shithub: aacdec

Download patch

ref: 5857a18ba4498e9bd73e3893ea59d460c5abe8b5
parent: 5cef46a6c51d565622907fa49a38a16d0932a760
author: menno <menno>
date: Sat Jun 15 11:10:47 EDT 2002

Changes for DRM

--- a/include/faad.h
+++ b/include/faad.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: faad.h,v 1.7 2002/06/13 11:03:27 menno Exp $
+** $Id: faad.h,v 1.8 2002/06/15 15:10:47 menno Exp $
 **/
 
 #ifndef __AACDEC_H__
@@ -42,7 +42,9 @@
 #define LC   1
 #define SSR  2
 #define LTP  3
+#define ER_LC  17
 #define LD   23
+#define DRM_ER_LC   27 /* special object type for DRM */
 
 #define FAAD_FMT_16BIT 1
 #define FAAD_FMT_24BIT 2
--- a/libfaad/Makefile.am
+++ b/libfaad/Makefile.am
@@ -4,7 +4,7 @@
 
 libfaad_la_SOURCES = bits.c data.c decoder.c drc.c error.c filtbank.c \
 ic_predict.c is.c lt_predict.c mdct.c mp4.c ms.c output.c pns.c \
-pulse.c specrec.c syntax.c tns.c \
+pulse.c specrec.c syntax.c tns.c reordered_spectral_data.c \
 hcb_1.c hcb_2.c hcb_3.c hcb_4.c hcb_5.c hcb_6.c hcb_7.c hcb_8.c \
 hcb_9.c hcb_10.c hcb_11.c hcb_sf.c
 
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: decoder.c,v 1.16 2002/06/13 11:03:27 menno Exp $
+** $Id: decoder.c,v 1.17 2002/06/15 15:10:47 menno Exp $
 **/
 
 #include <stdlib.h>
@@ -105,6 +105,15 @@
                                     faacDecConfigurationPtr config)
 {
     hDecoder->config.defObjectType = config->defObjectType;
+#ifdef DRM
+    if (config->defObjectType == DRM_ER_LC)
+    {
+        hDecoder->aacSectionDataResilienceFlag = 1; /* VCB11 */
+        hDecoder->aacScalefactorDataResilienceFlag = 0; /* no RVLC */
+        hDecoder->aacSpectralDataResilienceFlag = 1; /* HCR */
+        hDecoder->frameLength = 960;
+    }
+#endif
     hDecoder->config.defSampleRate = config->defSampleRate;
     hDecoder->config.outputFormat  = config->outputFormat;
 
@@ -155,6 +164,9 @@
     /* ER object types */
 #ifdef ERROR_RESILIENCE
     case ER_LC:
+#ifdef DRM
+    case DRM_ER_LC:
+#endif
         return 0;
     case ER_LTP:
 #ifdef LTP_DEC
@@ -191,6 +203,9 @@
     {
         faad_initbits(&ld, buffer);
 
+#ifdef DRM
+        if (hDecoder->object_type != DRM_ER_LC)
+#endif        
         /* Check if an ADIF header is present */
         if ((buffer[0] == 'A') && (buffer[1] == 'D') &&
             (buffer[2] == 'I') && (buffer[3] == 'F'))
--- a/libfaad/huffman.h
+++ b/libfaad/huffman.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: huffman.h,v 1.7 2002/05/31 18:06:49 menno Exp $
+** $Id: huffman.h,v 1.8 2002/06/15 15:10:47 menno Exp $
 **/
 
 #ifndef __HUFFMAN_H__
@@ -40,9 +40,18 @@
 
     while (hcb_sf[offset][1])
     {
-        uint8_t b = faad_get1bit(ld);
+        uint8_t b = faad_get1bit(ld
+            DEBUGVAR(1,255,"huffman_scale_factor()"));
         offset += hcb_sf[offset][b];
     }
+#ifdef ANALYSIS
+    if (offset>240)
+    {
+        printf("ERROR: offset into hcb_sf = %d >240!\n", offset);
+        return 0;
+    }
+#endif
+
     return hcb_sf[offset][0];
 }
 
@@ -65,6 +74,11 @@
 
 static uint8_t hcbN[] = { 0, 5, 5, 0, 5, 0, 5, 0, 5, 0, 6, 5 };
 
+#ifdef ANALYSIS
+static int hcb_2_quad_table_size[] = { 0, 114, 86, 0, 185, 0, 0, 0, 0, 0, 0, 0 };
+static int hcb_2_pair_table_size[] = { 0, 0, 0, 0, 0, 0, 126, 0, 83, 0, 210, 373 };
+static int hcb_bin_table_size[] = { 0, 0, 0, 0, 0, 161, 0, 127, 0, 337, 0, 0 };
+#endif
 
 static INLINE void huffman_spectral_data(uint8_t cb, bitfile *ld, int16_t *sp)
 {
@@ -92,6 +106,15 @@
             faad_flushbits(ld, hcb_2_quad_table[cb][offset].bits);
         }
 
+#ifdef ANALYSIS
+        if (offset > hcb_2_quad_table_size[cb])
+        {
+            printf("ERROR: offset into hcb_2_quad_table = %d >%d!\n", offset,
+                hcb_2_quad_table_size[cb]);
+            return;
+        }
+#endif
+
         sp[0] = hcb_2_quad_table[cb][offset].x;
         sp[1] = hcb_2_quad_table[cb][offset].y;
         sp[2] = hcb_2_quad_table[cb][offset].v;
@@ -125,6 +148,15 @@
             faad_flushbits(ld, hcb_2_pair_table[cb][offset].bits);
         }
 
+#ifdef ANALYSIS
+        if (offset > hcb_2_pair_table_size[cb])
+        {
+            printf("ERROR: offset into hcb_2_pair_table = %d >%d!\n", offset,
+                hcb_2_pair_table_size[cb]);
+            return;
+        }
+#endif
+
         sp[0] = hcb_2_pair_table[cb][offset].x;
         sp[1] = hcb_2_pair_table[cb][offset].y;
         break;
@@ -133,7 +165,8 @@
 
         while (!hcb3[offset].is_leaf)
         {
-            uint8_t b = faad_get1bit(ld);
+            uint8_t b = faad_get1bit(ld
+                DEBUGVAR(1,255,"huffman_spectral_data():3"));
             offset += hcb3[offset].data[b];
         }
 
@@ -150,9 +183,19 @@
 
         while (!hcb_bin_table[cb][offset].is_leaf)
         {
-            uint8_t b = faad_get1bit(ld);
+            uint8_t b = faad_get1bit(ld
+                DEBUGVAR(1,255,"huffman_spectral_data():9"));
             offset += hcb_bin_table[cb][offset].data[b];
         }
+
+#ifdef ANALYSIS
+        if (offset > hcb_bin_table_size[cb])
+        {
+            printf("ERROR: offset into hcb_2_pair_table = %d >%d!\n", offset,
+                hcb_bin_table_size[cb]);
+            return;
+        }
+#endif
 
         sp[0] = hcb_bin_table[cb][offset].data[0];
         sp[1] = hcb_bin_table[cb][offset].data[1];
--- a/libfaad/reordered_spectral_data.c
+++ b/libfaad/reordered_spectral_data.c
@@ -368,6 +368,15 @@
 	if (ics->length_of_reordered_spectral_data == 0)
     		return 0; /* nothing to do */
 
+    /* if we have a corrupted bitstream this can happen... */
+    if ((ics->length_of_longest_codeword == 0) ||
+        (ics->length_of_reordered_spectral_data <
+        ics->length_of_longest_codeword))
+    {
+        return 0; /* this is not good... */
+    }
+
+
 	/* store the offset into the spectral data for all the window groups because we can't do it later */
     
     sp_offset[0] = 0;
@@ -565,6 +574,21 @@
         for (i=0; i < numberOfSegments; i++)
         	rewind_bits( &Segment[ i ] );
 	}
+
+#ifdef ANALYSIS
+    {
+        int i, r=0;
+        for (i=0; i< numberOfSegments; i++)
+            r += Segment[ i ].len;
+        if (r != 0)
+            printf("reordered_spectral_data: %d bits remaining!\n", r);
+        for (i=0; i< NrCodeWords - numberOfSegments; i++)
+        {
+            if (Codewords[ i ].decoded == 0)
+                printf("reordered_spectral_data: Undecoded Codebooks remaining!\n", r);
+        }
+    }
+#endif
 
     return 0;
 }
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.c,v 1.18 2002/06/13 11:03:28 menno Exp $
+** $Id: syntax.c,v 1.19 2002/06/15 15:10:47 menno Exp $
 **/
 
 /*
@@ -244,6 +244,9 @@
 {
     ic_stream *ics = &(sce->ics1);
 
+#ifdef DRM
+    if (object_type != DRM_ER_LC)
+#endif
     sce->element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
         DEBUGVAR(1,38,"single_lfe_channel_element(): element_instance_tag"));
 
@@ -272,6 +275,9 @@
     ic_stream *ics1 = &(cpe->ics1);
     ic_stream *ics2 = &(cpe->ics2);
 
+#ifdef DRM
+    if (object_type != DRM_ER_LC)
+#endif
     cpe->element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
         DEBUGVAR(1,39,"channel_pair_element(): element_instance_tag"));
 
@@ -652,8 +658,12 @@
         {
 #ifdef ERROR_RESILIENCE
             /* TODO I don't understand this, but the "rewrite" software moves tns_data away */
-            if ((object_type != ER_LC) && (object_type != ER_LTP))
+            if ((object_type != ER_LC) && (object_type != ER_LTP)
+#ifdef DRM
+                && (object_type != DRM_ER_LC)
 #endif
+                )
+#endif
                 tns_data(ics, &(ics->tns), ld);
         }
 
@@ -674,7 +684,12 @@
     {
         /* TODO I don't understand this, but the "rewrite" software
                 moves tns_data before spectral_data */
-        if ( (object_type == ER_LC) || (object_type == ER_LTP) ) {
+        if ( (object_type == ER_LC) || (object_type == ER_LTP) 
+#ifdef DRM
+            && (object_type != DRM_ER_LC)
+#endif
+            )
+        {
             if (ics->tns_data_present)
                 tns_data(ics, &(ics->tns), ld);
         }
--- a/libfaad/syntax.h
+++ b/libfaad/syntax.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.h,v 1.13 2002/06/13 11:03:28 menno Exp $
+** $Id: syntax.h,v 1.14 2002/06/15 15:10:47 menno Exp $
 **/
 
 #ifndef __SYNTAX_H__
@@ -35,6 +35,8 @@
 #define LD      23
 #define ER_LC   17
 #define ER_LTP  19
+#define DRM_ER_LC   27 /* special object type for DRM */
+
 
 /* First object type that has ER */
 #define ER_OBJECT_START 17