X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fpacketizer%2Fmpeg4audio.c;h=0312c05b1a9dce672580a1a147d9ef55b4d53822;hb=70a8bb9649c3e44350d0fd579c24b8a9ddd7af34;hp=c01785cde9a9db6a8b45d4c484d382630e3a4b38;hpb=3f74a523459df2be022bce48de1ecc8b0eb08277;p=vlc diff --git a/modules/packetizer/mpeg4audio.c b/modules/packetizer/mpeg4audio.c index c01785cde9..0312c05b1a 100644 --- a/modules/packetizer/mpeg4audio.c +++ b/modules/packetizer/mpeg4audio.c @@ -1,8 +1,8 @@ /***************************************************************************** * mpeg4audio.c: parse and packetize an MPEG 4 audio stream ***************************************************************************** - * Copyright (C) 2001, 2002 VideoLAN - * $Id: mpeg4audio.c,v 1.15 2004/01/25 17:41:30 murray Exp $ + * Copyright (C) 2001, 2002, 2006 the VideoLAN team + * $Id$ * * Authors: Laurent Aimar * Gildas Bazin @@ -19,7 +19,7 @@ * * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -29,11 +29,12 @@ #include /* strdup() */ #include -#include -#include -#include -#include -#include "codecs.h" +#include +#include +#include +#include +#include +#include #include "vlc_block_helper.h" @@ -68,9 +69,12 @@ struct decoder_sys_t audio_date_t end_date; mtime_t i_pts; - int i_frame_size, i_raw_blocks; + int i_frame_size; + unsigned int i_raw_blocks; unsigned int i_channels; unsigned int i_rate, i_frame_length, i_header_size; + + int i_input_rate; }; enum { @@ -113,7 +117,9 @@ static int ADTSSyncInfo( decoder_t *, const byte_t * p_buf, * Module descriptor *****************************************************************************/ vlc_module_begin(); - set_description( _("MPEG4 Audio Packetizer") ); + set_category( CAT_SOUT ); + set_subcategory( SUBCAT_SOUT_PACKETIZER ); + set_description( _("MPEG4 audio packetizer") ); set_capability( "packetizer", 50 ); set_callbacks( OpenPacketizer, ClosePacketizer ); vlc_module_end(); @@ -143,6 +149,7 @@ static int OpenPacketizer( vlc_object_t *p_this ) p_sys->i_state = STATE_NOSYNC; aout_DateSet( &p_sys->end_date, 0 ); p_sys->bytestream = block_BytestreamInit( p_dec ); + p_sys->i_input_rate = INPUT_RATE_DEFAULT; /* Set output properties */ p_dec->fmt_out.i_cat = AUDIO_ES; @@ -151,7 +158,7 @@ static int OpenPacketizer( vlc_object_t *p_this ) /* Set callback */ p_dec->pf_packetize = PacketizeBlock; - msg_Info( p_dec, "running MPEG4 audio packetizer" ); + msg_Dbg( p_dec, "running MPEG4 audio packetizer" ); if( p_dec->fmt_in.i_extra > 0 ) { @@ -190,6 +197,8 @@ static int OpenPacketizer( vlc_object_t *p_this ) { msg_Dbg( p_dec, "no decoder specific info, must be an ADTS stream" ); + aout_DateInit( &p_sys->end_date, p_dec->fmt_in.audio.i_rate ); + /* We will try to create a AAC Config from adts */ p_dec->fmt_out.i_extra = 0; p_dec->fmt_out.p_extra = NULL; @@ -211,6 +220,13 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block ) if( !pp_block || !*pp_block ) return NULL; + if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) + { + //aout_DateSet( &p_sys->end_date, 0 ); + block_Release( *pp_block ); + return NULL; + } + p_block = *pp_block; *pp_block = NULL; /* Don't reuse this block */ @@ -229,7 +245,7 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block ) p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date ); p_block->i_length = aout_DateIncrement( &p_sys->end_date, - p_dec->fmt_out.audio.i_frame_length ) - p_block->i_pts; + p_dec->fmt_out.audio.i_frame_length * p_sys->i_input_rate / INPUT_RATE_DEFAULT ) - p_block->i_pts; return p_block; } @@ -246,18 +262,28 @@ static block_t *ADTSPacketizeBlock( decoder_t *p_dec, block_t **pp_block ) if( !pp_block || !*pp_block ) return NULL; - if( !aout_DateGet( &p_sys->end_date ) && !(*pp_block)->i_pts ) + if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) { - /* We've just started the stream, wait for the first PTS. */ + if( (*pp_block)->i_flags&BLOCK_FLAG_CORRUPTED ) + { + p_sys->i_state = STATE_NOSYNC; + block_BytestreamFlush( &p_sys->bytestream ); + } + //aout_DateSet( &p_sys->end_date, 0 ); block_Release( *pp_block ); return NULL; } - if( (*pp_block)->b_discontinuity ) + if( !aout_DateGet( &p_sys->end_date ) && !(*pp_block)->i_pts ) { - p_sys->i_state = STATE_NOSYNC; + /* We've just started the stream, wait for the first PTS. */ + block_Release( *pp_block ); + return NULL; } + if( (*pp_block)->i_rate > 0 ) + p_sys->i_input_rate = (*pp_block)->i_rate; + block_BytestreamPush( &p_sys->bytestream, *pp_block ); while( 1 ) @@ -424,7 +450,8 @@ static uint8_t *GetOutBuffer( decoder_t *p_dec, void **pp_out_buffer ) p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date ); p_block->i_length = aout_DateIncrement( &p_sys->end_date, - p_sys->i_frame_length ) - p_block->i_pts; + p_sys->i_frame_length * p_sys->i_input_rate / INPUT_RATE_DEFAULT ) - + p_block->i_pts; *pp_out_buffer = p_block; return p_block->p_buffer;