[MPlayer-cvslog] r25864 - in trunk/libfaad2: decoder.c syntax.c

nicodvb subversion at mplayerhq.hu
Sat Jan 26 19:45:11 CET 2008


Author: nicodvb
Date: Sat Jan 26 19:45:11 2008
New Revision: 25864

Log:
added code to check and handle the presence of LATM streams in the init() and decode() functions 

Modified:
   trunk/libfaad2/decoder.c
   trunk/libfaad2/syntax.c

Modified: trunk/libfaad2/decoder.c
==============================================================================
--- trunk/libfaad2/decoder.c	(original)
+++ trunk/libfaad2/decoder.c	Sat Jan 26 19:45:11 2008
@@ -195,6 +195,31 @@ uint8_t NEAACDECAPI NeAACDecSetConfigura
     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(NeAACDe
 
     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(NeAACDecHa
     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(NeAACDecHa
     }
 #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(NeAACDecHa
     }
 #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(NeAACDecHa
     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(NeAACDecHa
         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

Modified: trunk/libfaad2/syntax.c
==============================================================================
--- trunk/libfaad2/syntax.c	(original)
+++ trunk/libfaad2/syntax.c	Sat Jan 26 19:45:11 2008
@@ -548,7 +548,7 @@ void raw_data_block(NeAACDecHandle hDeco
 
     /* 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);



More information about the MPlayer-cvslog mailing list