X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fpacketizer%2Fmpeg4audio.c;h=f47aecb3969cf824b8578596701d734127addbce;hb=e71c332dc322a9584003c0b162ca05772cfdfcc9;hp=e08798073ed0525f9037adc47d7e24b9559902ca;hpb=3801da9dcde2f56498d49709250abc59502eea59;p=vlc diff --git a/modules/packetizer/mpeg4audio.c b/modules/packetizer/mpeg4audio.c index e08798073e..f47aecb396 100644 --- a/modules/packetizer/mpeg4audio.c +++ b/modules/packetizer/mpeg4audio.c @@ -37,7 +37,7 @@ #include #include -#include "vlc_block_helper.h" +#include #include @@ -63,6 +63,7 @@ typedef struct int i_samplerate; int i_channel; int i_sbr; // 0: no sbr, 1: sbr, -1: unknown + int i_ps; // 0: no ps, 1: ps, -1: unknown struct { @@ -125,7 +126,7 @@ struct decoder_sys_t /* * Common properties */ - audio_date_t end_date; + date_t end_date; mtime_t i_pts; int i_frame_size; @@ -192,7 +193,7 @@ static int OpenPacketizer( vlc_object_t *p_this ) decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; - if( p_dec->fmt_in.i_codec != VLC_FOURCC( 'm', 'p', '4', 'a' ) ) + if( p_dec->fmt_in.i_codec != VLC_CODEC_MP4A ) { return VLC_EGENERIC; } @@ -204,13 +205,13 @@ static int OpenPacketizer( vlc_object_t *p_this ) /* Misc init */ p_sys->i_state = STATE_NOSYNC; - aout_DateSet( &p_sys->end_date, 0 ); + date_Set( &p_sys->end_date, 0 ); p_sys->bytestream = block_BytestreamInit(); p_sys->b_latm_cfg = false; /* Set output properties */ p_dec->fmt_out.i_cat = AUDIO_ES; - p_dec->fmt_out.i_codec = VLC_FOURCC('m','p','4','a'); + p_dec->fmt_out.i_codec = VLC_CODEC_MP4A; msg_Dbg( p_dec, "running MPEG4 audio packetizer" ); @@ -242,7 +243,7 @@ static int OpenPacketizer( vlc_object_t *p_this ) p_dec->fmt_out.audio.i_rate, p_dec->fmt_out.audio.i_frame_length ); - aout_DateInit( &p_sys->end_date, p_dec->fmt_out.audio.i_rate ); + date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 ); p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; p_dec->fmt_out.p_extra = malloc( p_dec->fmt_in.i_extra ); @@ -262,7 +263,7 @@ static int OpenPacketizer( vlc_object_t *p_this ) { msg_Dbg( p_dec, "no decoder specific info, must be an ADTS or LOAS stream" ); - aout_DateInit( &p_sys->end_date, p_dec->fmt_in.audio.i_rate ); + date_Init( &p_sys->end_date, p_dec->fmt_in.audio.i_rate, 1 ); /* We will try to create a AAC Config from adts/loas */ p_dec->fmt_out.i_extra = 0; @@ -290,7 +291,7 @@ static block_t *PacketizeRawBlock( decoder_t *p_dec, block_t **pp_block ) if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) { - aout_DateSet( &p_sys->end_date, 0 ); + date_Set( &p_sys->end_date, 0 ); block_Release( *pp_block ); return NULL; } @@ -298,21 +299,21 @@ static block_t *PacketizeRawBlock( decoder_t *p_dec, block_t **pp_block ) p_block = *pp_block; *pp_block = NULL; /* Don't reuse this block */ - if( !aout_DateGet( &p_sys->end_date ) && !p_block->i_pts ) + if( !date_Get( &p_sys->end_date ) && p_block->i_pts <= VLC_TS_INVALID ) { /* We've just started the stream, wait for the first PTS. */ block_Release( p_block ); return NULL; } - else if( p_block->i_pts != 0 && - p_block->i_pts != aout_DateGet( &p_sys->end_date ) ) + else if( p_block->i_pts > VLC_TS_INVALID && + p_block->i_pts != date_Get( &p_sys->end_date ) ) { - aout_DateSet( &p_sys->end_date, p_block->i_pts ); + date_Set( &p_sys->end_date, p_block->i_pts ); } - p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date ); + p_block->i_pts = p_block->i_dts = date_Get( &p_sys->end_date ); - p_block->i_length = aout_DateIncrement( &p_sys->end_date, + p_block->i_length = date_Increment( &p_sys->end_date, p_dec->fmt_out.audio.i_frame_length ) - p_block->i_pts; return p_block; @@ -497,8 +498,8 @@ static int Mpeg4GASpecificConfig( mpeg4_cfg_t *p_cfg, bs_t *s ) static int Mpeg4ReadAudioObjectType( bs_t *s ) { int i_type = bs_read( s, 5 ); - if( i_type == 0x1f ) - i_type += bs_read( s, 6 ); + if( i_type == 31 ) + i_type = 32 + bs_read( s, 6 ); return i_type; } @@ -527,7 +528,7 @@ static int Mpeg4ReadAudioSpecificInfo( mpeg4_cfg_t *p_cfg, int *pi_extra, uint8_ "ER AAC LTP", "ER AAC Scalable", "ER TwinVQ", "ER BSAC", "ER AAC LD", "ER CELP", "ER HVXC", "ER HILN", "ER Parametric", "SSC", - "Reserved", "Reserved", "Escape", + "PS", "Reserved", "Escape", "Layer 1", "Layer 2", "Layer 3", "DST", }; @@ -550,12 +551,15 @@ static int Mpeg4ReadAudioSpecificInfo( mpeg4_cfg_t *p_cfg, int *pi_extra, uint8_ p_cfg->i_channel = -1; p_cfg->i_sbr = -1; + p_cfg->i_ps = -1; p_cfg->extension.i_object_type = 0; p_cfg->extension.i_samplerate = 0; - if( p_cfg->i_object_type == 5 ) + if( p_cfg->i_object_type == 5 || p_cfg->i_object_type == 29 ) { p_cfg->i_sbr = 1; - p_cfg->extension.i_object_type = p_cfg->i_object_type; + if( p_cfg->i_object_type == 29 ) + p_cfg->i_ps = 1; + p_cfg->extension.i_object_type = 5; p_cfg->extension.i_samplerate = Mpeg4ReadAudioSamplerate( s ); p_cfg->i_object_type = Mpeg4ReadAudioObjectType( s ); @@ -598,6 +602,9 @@ static int Mpeg4ReadAudioSpecificInfo( mpeg4_cfg_t *p_cfg, int *pi_extra, uint8_ case 35: // DSTSpecificConfig(); break; + case 36: + // ALSSpecificConfig(); + break; default: // error break; @@ -626,7 +633,7 @@ static int Mpeg4ReadAudioSpecificInfo( mpeg4_cfg_t *p_cfg, int *pi_extra, uint8_ break; } - if( p_cfg->extension.i_object_type != 5 && i_max_size > 0 && i_max_size - (bs_pos(s) - i_pos_start) >= 16 && + if( p_cfg->extension.i_object_type != 5 && i_max_size > 0 && i_max_size - (bs_pos(s) - i_pos_start) >= 16 && bs_read( s, 11 ) == 0x2b7 ) { p_cfg->extension.i_object_type = Mpeg4ReadAudioObjectType( s ); @@ -634,7 +641,13 @@ static int Mpeg4ReadAudioSpecificInfo( mpeg4_cfg_t *p_cfg, int *pi_extra, uint8_ { p_cfg->i_sbr = bs_read1( s ); if( p_cfg->i_sbr == 1 ) + { p_cfg->extension.i_samplerate = Mpeg4ReadAudioSamplerate( s ); + if( i_max_size > 0 && i_max_size - (bs_pos(s) - i_pos_start) >= 12 && bs_read( s, 11 ) == 0x548 ) + { + p_cfg->i_ps = bs_read1( s ); + } + } } } @@ -643,8 +656,8 @@ static int Mpeg4ReadAudioSpecificInfo( mpeg4_cfg_t *p_cfg, int *pi_extra, uint8_ i_bits = bs_pos(s) - i_pos_start; - *pi_extra = ( i_bits + 7 ) / 8; - for( i = 0; i < __MIN( LATM_MAX_EXTRA_SIZE, *pi_extra ); i++ ) + *pi_extra = __MIN( ( i_bits + 7 ) / 8, LATM_MAX_EXTRA_SIZE ); + for( i = 0; i < *pi_extra; i++ ) { const int i_read = __MIN( 8, i_bits - 8*i ); p_extra[i] = bs_read( &s_sav, i_read ) << (8-i_read); @@ -974,12 +987,12 @@ static block_t *PacketizeStreamBlock( decoder_t *p_dec, block_t **pp_block ) p_sys->i_state = STATE_NOSYNC; block_BytestreamEmpty( &p_sys->bytestream ); } - aout_DateSet( &p_sys->end_date, 0 ); + date_Set( &p_sys->end_date, 0 ); block_Release( *pp_block ); return NULL; } - if( !aout_DateGet( &p_sys->end_date ) && !(*pp_block)->i_pts ) + if( !date_Get( &p_sys->end_date ) && (*pp_block)->i_pts <= VLC_TS_INVALID ) { /* We've just started the stream, wait for the first PTS. */ block_Release( *pp_block ); @@ -1029,10 +1042,10 @@ static block_t *PacketizeStreamBlock( decoder_t *p_dec, block_t **pp_block ) case STATE_SYNC: /* New frame, set the Presentation Time Stamp */ p_sys->i_pts = p_sys->bytestream.p_block->i_pts; - if( p_sys->i_pts != 0 && - p_sys->i_pts != aout_DateGet( &p_sys->end_date ) ) + if( p_sys->i_pts > VLC_TS_INVALID && + p_sys->i_pts != date_Get( &p_sys->end_date ) ) { - aout_DateSet( &p_sys->end_date, p_sys->i_pts ); + date_Set( &p_sys->end_date, p_sys->i_pts ); } p_sys->i_state = STATE_HEADER; break; @@ -1166,7 +1179,7 @@ static block_t *PacketizeStreamBlock( decoder_t *p_dec, block_t **pp_block ) SetupOutput( p_dec, p_out_buffer ); /* Make sure we don't reuse the same pts twice */ if( p_sys->i_pts == p_sys->bytestream.p_block->i_pts ) - p_sys->i_pts = p_sys->bytestream.p_block->i_pts = 0; + p_sys->i_pts = p_sys->bytestream.p_block->i_pts = VLC_TS_INVALID; /* So p_block doesn't get re-added several times */ *pp_block = block_BytestreamPop( &p_sys->bytestream ); @@ -1192,8 +1205,8 @@ static void SetupOutput( decoder_t *p_dec, block_t *p_block ) msg_Info( p_dec, "AAC channels: %d samplerate: %d", p_sys->i_channels, p_sys->i_rate ); - aout_DateInit( &p_sys->end_date, p_sys->i_rate ); - aout_DateSet( &p_sys->end_date, p_sys->i_pts ); + date_Init( &p_sys->end_date, p_sys->i_rate, 1 ); + date_Set( &p_sys->end_date, p_sys->i_pts ); } p_dec->fmt_out.audio.i_rate = p_sys->i_rate; @@ -1207,10 +1220,10 @@ static void SetupOutput( decoder_t *p_dec, block_t *p_block ) p_sys->i_channels_conf & AOUT_CHAN_PHYSMASK; #endif - p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date ); + p_block->i_pts = p_block->i_dts = date_Get( &p_sys->end_date ); p_block->i_length = - aout_DateIncrement( &p_sys->end_date, p_sys->i_frame_length ) - p_block->i_pts; + date_Increment( &p_sys->end_date, p_sys->i_frame_length ) - p_block->i_pts; } /*****************************************************************************