mirror of
https://github.com/mpv-player/mpv
synced 2025-04-23 23:56:20 +00:00
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
This commit is contained in:
parent
54cc9247e0
commit
a8e8627367
@ -195,6 +195,31 @@ uint8_t NEAACDECAPI NeAACDecSetConfiguration(NeAACDecHandle hDecoder,
|
|||||||
return 0;
|
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,
|
int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer,
|
||||||
uint32_t buffer_size,
|
uint32_t buffer_size,
|
||||||
uint32_t *samplerate, uint8_t *channels)
|
uint32_t *samplerate, uint8_t *channels)
|
||||||
@ -214,8 +239,25 @@ int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer,
|
|||||||
|
|
||||||
if (buffer != NULL)
|
if (buffer != NULL)
|
||||||
{
|
{
|
||||||
|
int is_latm;
|
||||||
|
latm_header *l = &hDecoder->latm_config;
|
||||||
faad_initbits(&ld, buffer, buffer_size);
|
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 */
|
/* Check if an ADIF header is present */
|
||||||
if ((buffer[0] == 'A') && (buffer[1] == 'D') &&
|
if ((buffer[0] == 'A') && (buffer[1] == 'D') &&
|
||||||
(buffer[2] == 'I') && (buffer[3] == 'F'))
|
(buffer[2] == 'I') && (buffer[3] == 'F'))
|
||||||
@ -733,6 +775,7 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
|
|||||||
uint32_t bitsconsumed;
|
uint32_t bitsconsumed;
|
||||||
uint16_t frame_len;
|
uint16_t frame_len;
|
||||||
void *sample_buffer;
|
void *sample_buffer;
|
||||||
|
uint32_t startbit=0, endbit=0, payload_bits=0;
|
||||||
|
|
||||||
#ifdef PROFILE
|
#ifdef PROFILE
|
||||||
int64_t count = faad_get_ts();
|
int64_t count = faad_get_ts();
|
||||||
@ -775,6 +818,17 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
#ifdef DRM
|
||||||
if (hDecoder->object_type == DRM_ER_LC)
|
if (hDecoder->object_type == DRM_ER_LC)
|
||||||
{
|
{
|
||||||
@ -820,6 +874,17 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
|
|||||||
}
|
}
|
||||||
#endif
|
#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;
|
channels = hDecoder->fr_channels;
|
||||||
|
|
||||||
if (hInfo->error > 0)
|
if (hInfo->error > 0)
|
||||||
@ -844,7 +909,7 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
|
|||||||
faad_endbits(&ld);
|
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)
|
if (hDecoder->channelConfiguration == 0)
|
||||||
hDecoder->channelConfiguration = channels;
|
hDecoder->channelConfiguration = channels;
|
||||||
@ -893,6 +958,8 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
|
|||||||
hInfo->header_type = ADIF;
|
hInfo->header_type = ADIF;
|
||||||
if (hDecoder->adts_header_present)
|
if (hDecoder->adts_header_present)
|
||||||
hInfo->header_type = ADTS;
|
hInfo->header_type = ADTS;
|
||||||
|
if (hDecoder->latm_header_present)
|
||||||
|
hInfo->header_type = LATM;
|
||||||
#if (defined(PS_DEC) || defined(DRM_PS))
|
#if (defined(PS_DEC) || defined(DRM_PS))
|
||||||
hInfo->ps = hDecoder->ps_used_global;
|
hInfo->ps = hDecoder->ps_used_global;
|
||||||
#endif
|
#endif
|
||||||
|
@ -548,7 +548,7 @@ void raw_data_block(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
|
|||||||
|
|
||||||
/* new in corrigendum 14496-3:2002 */
|
/* new in corrigendum 14496-3:2002 */
|
||||||
#ifdef DRM
|
#ifdef DRM
|
||||||
if (hDecoder->object_type != DRM_ER_LC)
|
if (hDecoder->object_type != DRM_ER_LC && !hDecoder->latm_header_present)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
faad_byte_align(ld);
|
faad_byte_align(ld);
|
||||||
|
Loading…
Reference in New Issue
Block a user