X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fpacketizer%2Fmpeg4audio.c;h=9a926acdd28123909cb58d7fdf12cb4f2ca4876e;hb=7b0dd84fff6c300cab5e0bdbf2a29fb1b3618e62;hp=bbdbb2e34f57aef33d6f46fb837850ac110ec947;hpb=a74d5452eb0c1b7846e14090c1063169ebd9681a;p=vlc diff --git a/modules/packetizer/mpeg4audio.c b/modules/packetizer/mpeg4audio.c index bbdbb2e34f..9a926acdd2 100644 --- a/modules/packetizer/mpeg4audio.c +++ b/modules/packetizer/mpeg4audio.c @@ -30,7 +30,8 @@ # include "config.h" #endif -#include +#include +#include #include #include #include @@ -41,6 +42,8 @@ #include "vlc_block_helper.h" +#include + /* AAC Config in ES: * * AudioObjectType 5 bits @@ -135,7 +138,7 @@ struct decoder_sys_t int i_input_rate; /* LOAS */ - vlc_bool_t b_latm_cfg; + bool b_latm_cfg; latm_mux_t latm; }; @@ -179,7 +182,7 @@ static block_t *PacketizeStreamBlock( decoder_t *, block_t ** ); vlc_module_begin(); set_category( CAT_SOUT ); set_subcategory( SUBCAT_SOUT_PACKETIZER ); - set_description( _("MPEG4 audio packetizer") ); + set_description( N_("MPEG4 audio packetizer") ); set_capability( "packetizer", 50 ); set_callbacks( OpenPacketizer, ClosePacketizer ); vlc_module_end(); @@ -200,17 +203,14 @@ static int OpenPacketizer( vlc_object_t *p_this ) /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) - { - msg_Err( p_dec, "out of memory" ); - return VLC_EGENERIC; - } + return VLC_ENOMEM; /* Misc init */ p_sys->i_state = STATE_NOSYNC; aout_DateSet( &p_sys->end_date, 0 ); p_sys->bytestream = block_BytestreamInit(); p_sys->i_input_rate = INPUT_RATE_DEFAULT; - p_sys->b_latm_cfg = VLC_FALSE; + p_sys->b_latm_cfg = false; /* Set output properties */ p_dec->fmt_out.i_cat = AUDIO_ES; @@ -239,13 +239,15 @@ static int OpenPacketizer( vlc_object_t *p_this ) (( p_config[4] >> 2 ) & 0x01) ? 960 : 1024; } + p_dec->fmt_out.audio.i_channels = + (p_config[i_index == 0x0f ? 4 : 1] >> 3) & 0x0f; + msg_Dbg( p_dec, "AAC %dHz %d samples/frame", 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 ); - p_dec->fmt_out.audio.i_channels = p_dec->fmt_in.audio.i_channels; 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 ); if( !p_dec->fmt_out.p_extra ) @@ -323,36 +325,83 @@ static block_t *PacketizeRawBlock( decoder_t *p_dec, block_t **pp_block ) /**************************************************************************** * ADTS helpers ****************************************************************************/ -static int ADTSSyncInfo( decoder_t * p_dec, const byte_t * p_buf, +static int ADTSSyncInfo( decoder_t * p_dec, const uint8_t * p_buf, unsigned int * pi_channels, unsigned int * pi_sample_rate, unsigned int * pi_frame_length, unsigned int * pi_header_size ) { - int i_id, i_profile, i_sample_rate_idx, i_frame_size; - vlc_bool_t b_crc; + int i_profile, i_sample_rate_idx, i_frame_size; + bool b_crc; /* Fixed header between frames */ - i_id = ( (p_buf[1] >> 3) & 0x01 ) ? 2 : 4; + //int i_id = ( (p_buf[1] >> 3) & 0x01) ? 2 : 4; /* MPEG-2 or 4 */ b_crc = !(p_buf[1] & 0x01); i_profile = p_buf[2] >> 6; i_sample_rate_idx = (p_buf[2] >> 2) & 0x0f; *pi_sample_rate = pi_sample_rates[i_sample_rate_idx]; + //private_bit = (p_buf[2] >> 1) & 0x01; *pi_channels = ((p_buf[2] & 0x01) << 2) | ((p_buf[3] >> 6) & 0x03); + //original_copy = (p_buf[3] >> 5) & 0x01; + //home = (p_buf[3] >> 4) & 0x01; /* Variable header */ + //copyright_id_bit = (p_buf[3] >> 3) & 0x01; + //copyright_id_start = (p_buf[3] >> 2) & 0x01; i_frame_size = ((p_buf[3] & 0x03) << 11) | (p_buf[4] << 3) | - ((p_buf[5] >> 5) & 0x7); - //i_raw_blocks_in_frame = (p_buf[6] & 0x02) + 1; + ((p_buf[5] >> 5) /*& 0x7*/); + //uint16_t buffer_fullness = ((p_buf[5] & 0x1f) << 6) | (p_buf[6] >> 2); + unsigned short i_raw_blocks_in_frame = p_buf[6] & 0x03; if( !*pi_sample_rate || !*pi_channels || !i_frame_size ) { + msg_Warn( p_dec, "Invalid ADTS header" ); return 0; } - /* Fixme */ *pi_frame_length = 1024; + if( i_raw_blocks_in_frame == 0 ) + { + if( b_crc ) + { + msg_Warn( p_dec, "ADTS CRC not supported" ); + //uint16_t crc = (p_buf[7] << 8) | p_buf[8]; + } + } + else + { + msg_Err( p_dec, "Multiple blocks per frame in ADTS not supported" ); + return 0; +#if 0 + int i; + const uint8_t *p_pos = p_buf + 7; + uint16_t crc_block; + uint16_t i_block_pos[3]; + if( b_crc ) + { + for( i = 0 ; i < i_raw_blocks_in_frame ; i++ ) + { /* the 1st block's position is known ... */ + i_block_pos[i] = (*p_pos << 8) | *(p_pos+1); + p_pos += 2; + } + crc_block = (*p_pos << 8) | *(p_pos+1); + p_pos += 2; + } + for( i = 0 ; i <= i_raw_blocks_in_frame ; i++ ) + { + //read 1 block + if( b_crc ) + { + msg_Err( p_dec, "ADTS CRC not supported" ); + //uint16_t crc = (*p_pos << 8) | *(p_pos+1); + //p_pos += 2; + } + } +#endif + } + + /* Build the decoder specific info header */ if( !p_dec->fmt_out.i_extra ) { @@ -655,13 +704,13 @@ static int LatmReadStreamMuxConfiguration( latm_mux_t *m, bs_t *s ) for( i_layer = 0; i_layer < m->pi_layers[i_program]; i_layer++ ) { latm_stream_t *st = &m->stream[m->i_streams]; - vlc_bool_t b_previous_cfg; + bool b_previous_cfg; m->pi_stream[i_program][i_layer] = m->i_streams; st->i_program = i_program; st->i_layer = i_layer; - b_previous_cfg = VLC_FALSE; + b_previous_cfg = false; if( i_program != 0 || i_layer != 0 ) b_previous_cfg = bs_read1( s ); @@ -771,14 +820,14 @@ static int LOASParse( decoder_t *p_dec, uint8_t *p_buffer, int i_buffer ) memcpy( p_dec->fmt_out.p_extra, st->extra, st->i_extra ); } - p_sys->b_latm_cfg = VLC_TRUE; + p_sys->b_latm_cfg = true; } } /* Wait for the configuration */ if( !p_sys->b_latm_cfg ) return 0; - /* FIXME do we need to split the subframe into independant packet ? */ + /* FIXME do we need to split the subframe into independent packet ? */ if( p_sys->latm.i_sub_frames > 1 ) msg_Err( p_dec, "latm sub frames not yet supported, please send a sample" ); @@ -1091,7 +1140,7 @@ static block_t *PacketizeStreamBlock( decoder_t *p_dec, block_t **pp_block ) p_out_buffer = block_New( p_dec, p_sys->i_frame_size ); if( !p_out_buffer ) { - //p_dec->b_error = VLC_TRUE; + //p_dec->b_error = true; return NULL; } p_buf = p_out_buffer->p_buffer;