codec: subsdec: fix variable shadowing
[vlc.git] / modules / codec / rtpvideo.c
blobf28c794121ff062c5960bac50a59e5d5b50ac31f
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$
7 * Authors: Tristan Matthews <tmatth@videolan.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_codec.h>
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 );
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 ()
53 static int OpenEncoder( vlc_object_t *p_this )
55 encoder_t *p_enc = (encoder_t *)p_this;
56 if( p_enc->fmt_out.i_codec != VLC_CODEC_R420 && !p_enc->obj.force )
57 return VLC_EGENERIC;
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;
63 return VLC_SUCCESS;
66 static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
68 VLC_UNUSED( p_enc );
69 if( !p_pict ) return NULL;
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;
75 block_t *p_block = block_Alloc( i_length );
76 if( !p_block ) return NULL;
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;
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;
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 )
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 )
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++;
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;
107 return p_block;