]> git.sesse.net Git - vlc/blob - modules/codec/rtpvideo.c
upnp: change item b_net and i_type
[vlc] / modules / codec / rtpvideo.c
1 /*****************************************************************************
2  * rtpvideo.c: video encoder for raw video for RTP (see RFC 4175)
3  *****************************************************************************
4  * Copyright (C) 2015 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Tristan Matthews <tmatth@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_codec.h>
34
35 /****************************************************************************
36  * Local prototypes
37  ****************************************************************************/
38 static int  OpenEncoder( vlc_object_t * );
39 static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );
40
41 /*****************************************************************************
42  * Module descriptor
43  *****************************************************************************/
44 vlc_module_begin ()
45     set_description( N_("Raw video encoder for RTP") )
46     set_capability( "encoder", 50 )
47     set_category( CAT_INPUT )
48     set_subcategory( SUBCAT_INPUT_VCODEC )
49     set_callbacks( OpenEncoder, NULL )
50     add_shortcut( "rtpvideo" )
51 vlc_module_end ()
52
53 static int OpenEncoder( vlc_object_t *p_this )
54 {
55     encoder_t *p_enc = (encoder_t *)p_this;
56     if( p_enc->fmt_out.i_codec != VLC_CODEC_R420 && !p_enc->b_force )
57         return VLC_EGENERIC;
58
59     p_enc->pf_encode_video = Encode;
60     p_enc->fmt_in.i_codec = VLC_CODEC_I420;
61     p_enc->fmt_out.i_codec = VLC_CODEC_R420;
62
63     return VLC_SUCCESS;
64 }
65
66 static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
67 {
68     VLC_UNUSED( p_enc );
69     if( !p_pict ) return NULL;
70
71     const int i_length = p_pict->p[0].i_visible_lines * p_pict->p[0].i_visible_pitch +
72         p_pict->p[1].i_visible_lines * p_pict->p[1].i_visible_pitch +
73         p_pict->p[2].i_visible_lines * p_pict->p[2].i_visible_pitch;
74
75     block_t *p_block = block_Alloc( i_length );
76     if( !p_block ) return NULL;
77
78     p_block->i_dts = p_block->i_pts = p_pict->date;
79     uint8_t *p_outdata = p_block->p_buffer;
80     const int i_xdec = 2;
81     const int i_ydec = 2;
82
83     const uint8_t *p_yd1 = p_pict->p[0].p_pixels;
84     const uint8_t *p_u = p_pict->p[1].p_pixels;
85     const uint8_t *p_v = p_pict->p[2].p_pixels;
86
87     /* Y00-Y01-Y10-Y11-U00-V00...luma from adjacent lines */
88     for( int i_lin = 0; i_lin < p_pict->p[0].i_visible_lines; i_lin += i_ydec )
89     {
90         const uint8_t *p_yd2 = p_yd1 + p_pict->p[0].i_pitch;
91         for ( int i_pix = 0; i_pix < p_pict->p[0].i_visible_pitch; i_pix += i_xdec )
92         {
93             *p_outdata++ = *p_yd1++;
94             *p_outdata++ = *p_yd1++;
95             *p_outdata++ = *p_yd2++;
96             *p_outdata++ = *p_yd2++;
97             *p_outdata++ = *p_u++;
98             *p_outdata++ = *p_v++;
99         }
100         /* Skip a line + padding */
101         p_yd1 += p_pict->p[0].i_pitch +
102                  (p_pict->p[0].i_pitch - p_pict->p[0].i_visible_pitch);
103         p_u += p_pict->p[1].i_pitch - p_pict->p[1].i_visible_pitch;
104         p_v += p_pict->p[2].i_pitch - p_pict->p[2].i_visible_pitch;
105     }
106
107     return p_block;
108 }