diff options
author | nicodvb <nicodvb@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2008-01-26 18:45:11 +0000 |
---|---|---|
committer | nicodvb <nicodvb@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2008-01-26 18:45:11 +0000 |
commit | a8e8627367e3c00113ff53ab197ecebd4920dbc9 (patch) | |
tree | 93d66a277940dddfd9352757ee2ad4ab7e0a7598 | |
parent | 54cc9247e0ff20068a6b937332ab88020bf6fbf2 (diff) |
added code to check and handle the presence of LATM streams in the init() and decode() functions
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25864 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | libfaad2/decoder.c | 69 | ||||
-rw-r--r-- | libfaad2/syntax.c | 2 |
2 files changed, 69 insertions, 2 deletions
diff --git a/libfaad2/decoder.c b/libfaad2/decoder.c index 7ff12b4982..c9842f7a89 100644 --- a/libfaad2/decoder.c +++ b/libfaad2/decoder.c @@ -195,6 +195,31 @@ uint8_t NEAACDECAPI NeAACDecSetConfiguration(NeAACDecHandle hDecoder, return 0; } +static int latmCheck(latm_header *latm, bitfile *ld) +{ + uint32_t good=0, bad=0, bits, m; + + while(!ld->error && !ld->no_more_reading) + { + bits = faad_latm_frame(latm, ld); + if(bits==-1U) + bad++; + else + { + good++; + while(bits>0) + { + m = min(bits, 8); + faad_getbits(ld, m); + bits -= m; + } + } + } + + return (good>0); +} + + int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer, uint32_t buffer_size, uint32_t *samplerate, uint8_t *channels) @@ -214,8 +239,25 @@ int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer, if (buffer != NULL) { + int is_latm; + latm_header *l = &hDecoder->latm_config; faad_initbits(&ld, buffer, buffer_size); + memset(l, 0, sizeof(latm_header)); + is_latm = latmCheck(l, &ld); + l->inited = 0; + l->frameLength = 0; + faad_rewindbits(&ld); + if(is_latm && l->ASCbits>0) + { + int32_t x; + hDecoder->latm_header_present = 1; + x = NeAACDecInit2(hDecoder, &l->ASC, (l->ASCbits+7)/8, samplerate, channels); + if(x!=0) + hDecoder->latm_header_present = 0; + return x; + } + else /* Check if an ADIF header is present */ if ((buffer[0] == 'A') && (buffer[1] == 'D') && (buffer[2] == 'I') && (buffer[3] == 'F')) @@ -733,6 +775,7 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, uint32_t bitsconsumed; uint16_t frame_len; void *sample_buffer; + uint32_t startbit=0, endbit=0, payload_bits=0; #ifdef PROFILE int64_t count = faad_get_ts(); @@ -775,6 +818,17 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, } #endif + if(hDecoder->latm_header_present) + { + payload_bits = faad_latm_frame(&hDecoder->latm_config, &ld); + startbit = faad_get_processed_bits(&ld); + if(payload_bits == -1U) + { + hInfo->error = 1; + goto error; + } + } + #ifdef DRM if (hDecoder->object_type == DRM_ER_LC) { @@ -820,6 +874,17 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, } #endif + if(hDecoder->latm_header_present) + { + endbit = faad_get_processed_bits(&ld); + if(endbit-startbit > payload_bits) + fprintf(stderr, "\r\nERROR, too many payload bits read: %u > %d. Please. report with a link to a sample\n", + endbit-startbit, payload_bits); + if(hDecoder->latm_config.otherDataLenBits > 0) + faad_getbits(&ld, hDecoder->latm_config.otherDataLenBits); + faad_byte_align(&ld); + } + channels = hDecoder->fr_channels; if (hInfo->error > 0) @@ -844,7 +909,7 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, faad_endbits(&ld); - if (!hDecoder->adts_header_present && !hDecoder->adif_header_present) + if (!hDecoder->adts_header_present && !hDecoder->adif_header_present && !hDecoder->latm_header_present) { if (hDecoder->channelConfiguration == 0) hDecoder->channelConfiguration = channels; @@ -893,6 +958,8 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, hInfo->header_type = ADIF; if (hDecoder->adts_header_present) hInfo->header_type = ADTS; + if (hDecoder->latm_header_present) + hInfo->header_type = LATM; #if (defined(PS_DEC) || defined(DRM_PS)) hInfo->ps = hDecoder->ps_used_global; #endif diff --git a/libfaad2/syntax.c b/libfaad2/syntax.c index 52a08f25b7..566c16b88b 100644 --- a/libfaad2/syntax.c +++ b/libfaad2/syntax.c @@ -548,7 +548,7 @@ void raw_data_block(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo, /* new in corrigendum 14496-3:2002 */ #ifdef DRM - if (hDecoder->object_type != DRM_ER_LC) + if (hDecoder->object_type != DRM_ER_LC && !hDecoder->latm_header_present) #endif { faad_byte_align(ld); |