X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fpacketizer%2Fmpegvideo.c;h=f9b12f0f76d211f25bacf42b6765ca63e4851597;hb=63be579eeafa2a1fddb3df95974b8d4bba4013dd;hp=fa3c0e218ca1ab8f475535a907bfd4efcd55e136;hpb=52c18c4dec68158eedd655e0502820b7d7b6128f;p=vlc diff --git a/modules/packetizer/mpegvideo.c b/modules/packetizer/mpegvideo.c index fa3c0e218c..f9b12f0f76 100644 --- a/modules/packetizer/mpegvideo.c +++ b/modules/packetizer/mpegvideo.c @@ -1,7 +1,7 @@ /***************************************************************************** * mpegvideo.c: parse and packetize an MPEG1/2 video stream ***************************************************************************** - * Copyright (C) 2001-2006 the VideoLAN team + * Copyright (C) 2001-2006 VLC authors and VideoLAN * $Id$ * * Authors: Laurent Aimar @@ -9,19 +9,19 @@ * Gildas Bazin * Jean-Paul Saman * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -73,7 +73,7 @@ vlc_module_begin () set_capability( "packetizer", 50 ) set_callbacks( Open, Close ) - add_bool( "packetizer-mpegvideo-sync-iframe", 0, NULL, SYNC_INTRAFRAME_TEXT, + add_bool( "packetizer-mpegvideo-sync-iframe", false, SYNC_INTRAFRAME_TEXT, SYNC_INTRAFRAME_LONGTEXT, true ) vlc_module_end () @@ -159,8 +159,6 @@ static int Open( vlc_object_t *p_this ) es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_CODEC_MPGV ); p_dec->fmt_out.i_original_fourcc = p_dec->fmt_in.i_original_fourcc; - p_dec->pf_packetize = Packetize; - p_dec->pf_get_cc = GetCc; p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) ); if( !p_dec->p_sys ) @@ -170,7 +168,7 @@ static int Open( vlc_object_t *p_this ) /* Misc init */ packetizer_Init( &p_sys->packetizer, p_mp2v_startcode, sizeof(p_mp2v_startcode), - NULL, 0, + NULL, 0, 4, PacketizeReset, PacketizeParse, PacketizeValidate, p_dec ); p_sys->p_seq = NULL; @@ -179,7 +177,7 @@ static int Open( vlc_object_t *p_this ) p_sys->pp_last = &p_sys->p_frame; p_sys->b_frame_slice = false; - p_sys->i_dts = p_sys->i_pts = 0; + p_sys->i_dts = p_sys->i_pts = VLC_TS_INVALID; p_sys->i_frame_rate = 1; p_sys->i_frame_rate_base = 1; @@ -195,8 +193,8 @@ static int Open( vlc_object_t *p_this ) p_sys->i_progressive_frame = 0; p_sys->b_inited = 0; - p_sys->i_interpolated_dts = 0; - p_sys->i_last_ref_pts = 0; + p_sys->i_interpolated_dts = VLC_TS_INVALID; + p_sys->i_last_ref_pts = VLC_TS_INVALID; p_sys->b_second_field = 0; p_sys->b_discontinuity = false; @@ -210,6 +208,9 @@ static int Open( vlc_object_t *p_this ) p_sys->i_cc_flags = 0; cc_Init( &p_sys->cc ); + p_dec->pf_packetize = Packetize; + p_dec->pf_get_cc = GetCc; + return VLC_SUCCESS; } @@ -265,7 +266,7 @@ static block_t *GetCc( decoder_t *p_dec, bool pb_present[4] ) if( p_sys->cc.i_data <= 0 ) return NULL; - p_cc = block_New( p_dec, p_sys->cc.i_data); + p_cc = block_Alloc( p_sys->cc.i_data ); if( p_cc ) { memcpy( p_cc->p_buffer, p_sys->cc.p_data, p_sys->cc.i_data ); @@ -294,10 +295,10 @@ static void PacketizeReset( void *p_private, bool b_broken ) p_sys->pp_last = &p_sys->p_frame; p_sys->b_frame_slice = false; } - p_sys->i_dts = 0; - p_sys->i_pts = 0; - p_sys->i_interpolated_dts = 0; - p_sys->i_last_ref_pts = 0; + p_sys->i_dts = + p_sys->i_pts = + p_sys->i_interpolated_dts = + p_sys->i_last_ref_pts = VLC_TS_INVALID; } static block_t *PacketizeParse( void *p_private, bool *pb_ts_used, block_t *p_block ) @@ -305,7 +306,7 @@ static block_t *PacketizeParse( void *p_private, bool *pb_ts_used, block_t *p_bl decoder_t *p_dec = p_private; /* Check if we have a picture start code */ - *pb_ts_used = p_block->i_buffer >= 4 && p_block->p_buffer[3] == 0x00; + *pb_ts_used = p_block->p_buffer[3] == 0x00; return ParseMPEGBlock( p_dec, p_block ); } @@ -318,8 +319,8 @@ static int PacketizeValidate( void *p_private, block_t *p_au ) /* If a discontinuity has been encountered, then wait till * the next Intra frame before continuing with packetizing */ - if( p_sys->b_discontinuity && - p_sys->b_sync_on_intra_frame ) + if( unlikely( p_sys->b_discontinuity && + p_sys->b_sync_on_intra_frame ) ) { if( (p_au->i_flags & BLOCK_FLAG_TYPE_I) == 0 ) { @@ -333,16 +334,16 @@ static int PacketizeValidate( void *p_private, block_t *p_au ) /* We've just started the stream, wait for the first PTS. * We discard here so we can still get the sequence header. */ - if( p_sys->i_dts <= 0 && p_sys->i_pts <= 0 && - p_sys->i_interpolated_dts <= 0 ) + if( unlikely( p_sys->i_dts <= VLC_TS_INVALID && p_sys->i_pts <= VLC_TS_INVALID && + p_sys->i_interpolated_dts <= VLC_TS_INVALID )) { msg_Dbg( p_dec, "need a starting pts/dts" ); return VLC_EGENERIC; } /* When starting the stream we can have the first frame with - * a null DTS (i_interpolated_pts is initialized to 0) */ - if( !p_au->i_dts ) + * an invalid DTS (i_interpolated_pts is initialized to VLC_TS_INVALID) */ + if( unlikely( p_au->i_dts <= VLC_TS_INVALID ) ) p_au->i_dts = p_au->i_pts; return VLC_SUCCESS; @@ -389,7 +390,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) if( b_eos ) p_pic->i_flags |= BLOCK_FLAG_END_OF_SEQUENCE; - i_duration = (mtime_t)( 1000000 * p_sys->i_frame_rate_base / + i_duration = (mtime_t)( CLOCK_FREQ * p_sys->i_frame_rate_base / p_sys->i_frame_rate ); if( !p_sys->b_seq_progressive && p_sys->i_picture_structure != 0x03 ) @@ -425,15 +426,18 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) { /* Trivial case (DTS == PTS) */ /* Correct interpolated dts when we receive a new pts/dts */ - if( p_sys->i_pts > 0 ) p_sys->i_interpolated_dts = p_sys->i_pts; - if( p_sys->i_dts > 0 ) p_sys->i_interpolated_dts = p_sys->i_dts; + if( p_sys->i_pts > VLC_TS_INVALID ) + p_sys->i_interpolated_dts = p_sys->i_pts; + if( p_sys->i_dts > VLC_TS_INVALID ) + p_sys->i_interpolated_dts = p_sys->i_dts; } else { /* Correct interpolated dts when we receive a new pts/dts */ - if( p_sys->i_last_ref_pts > 0 && !p_sys->b_second_field ) + if(p_sys->i_last_ref_pts > VLC_TS_INVALID && !p_sys->b_second_field) p_sys->i_interpolated_dts = p_sys->i_last_ref_pts; - if( p_sys->i_dts > 0 ) p_sys->i_interpolated_dts = p_sys->i_dts; + if( p_sys->i_dts > VLC_TS_INVALID ) + p_sys->i_interpolated_dts = p_sys->i_dts; if( !p_sys->b_second_field ) p_sys->i_last_ref_pts = p_sys->i_pts; @@ -443,7 +447,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) p_sys->i_interpolated_dts += i_duration; /* Set PTS only if we have a B frame or if it comes from the stream */ - if( p_sys->i_pts > 0 ) + if( p_sys->i_pts > VLC_TS_INVALID ) { p_pic->i_pts = p_sys->i_pts; } @@ -453,7 +457,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) } else { - p_pic->i_pts = 0; + p_pic->i_pts = VLC_TS_INVALID; } switch ( p_sys->i_picture_type ) @@ -514,7 +518,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) if( p_sys->p_seq && p_sys->i_seq_old > p_sys->i_frame_rate/p_sys->i_frame_rate_base ) { - /* Usefull for mpeg1: repeat sequence header every second */ + /* Useful for mpeg1: repeat sequence header every second */ block_ChainLastAppend( &p_sys->pp_last, block_Duplicate( p_sys->p_seq ) ); if( p_sys->p_ext ) { @@ -535,7 +539,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) /* Unofficial 15fps from Xing*/ { 15, 1001 }, /* Unofficial economy rates from libmpeg3 */ - { 5, 1001 }, { 10, 1001 }, { 12, 1001 }, { 15, 1001 }, + { 5000, 1001 }, { 1000, 1001 }, { 12000, 1001 }, { 15000, 1001 }, { 1, 1 }, { 1, 1 } /* invalid */ }; @@ -607,10 +611,12 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) * of aspect ratio change, we're screwed. --Meuuh */ #if 0 - p_dec->fmt_out.video.i_aspect = + p_dec->fmt_out.video.i_sar_num = mpeg2_aspect[p_sys->i_aspect_ratio_info][0] * - VOUT_ASPECT_FACTOR / - mpeg2_aspect[p_sys->i_aspect_ratio_info][1]; + p_dec->fmt_out.video.i_height; + p_dec->fmt_out.video.i_sar_den = + mpeg2_aspect[p_sys->i_aspect_ratio_info][1] * + p_dec->fmt_out.video.i_width; #endif } @@ -625,7 +631,8 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) } else if( p_frag->p_buffer[3] == 0xb2 && p_frag->i_buffer > 4 ) { - cc_Extract( &p_sys->cc, &p_frag->p_buffer[4], p_frag->i_buffer - 4 ); + cc_Extract( &p_sys->cc, p_sys->i_top_field_first, + &p_frag->p_buffer[4], p_frag->i_buffer - 4 ); } else if( p_frag->p_buffer[3] == 0x00 ) {