shithub: aacdec

Download patch

ref: 336d6cabd617079710432094c53e075b6e67f53d
parent: b288de8383dbf2f6ed278ceb1bfe80bff8b92129
author: gcp <gcp>
date: Thu Sep 2 10:02:02 EDT 2004

Bugfixes for PS AAC streaming

--- a/libfaad/sbr_syntax.c
+++ b/libfaad/sbr_syntax.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: sbr_syntax.c,v 1.32 2004/07/31 15:48:57 menno Exp $
+** $Id: sbr_syntax.c,v 1.34 2004/09/04 14:56:28 menno Exp $
 **/
 
 #include "common.h"
@@ -391,6 +391,9 @@
     if (sbr->bs_extended_data)
     {
         uint16_t nr_bits_left;
+#if (defined(PS_DEC) || defined(DRM_PS))
+        uint8_t ps_ext_read = 0;
+#endif
         uint16_t cnt = (uint16_t)faad_getbits(ld, 4
             DEBUGVAR(1,225,"sbr_single_channel_element(): bs_extension_size"));
         if (cnt == 15)
@@ -407,6 +410,32 @@
             sbr->bs_extension_id = (uint8_t)faad_getbits(ld, 2
                 DEBUGVAR(1,227,"sbr_single_channel_element(): bs_extension_id"));
             tmp_nr_bits += 2;
+
+            /* allow only 1 PS extension element per extension data */
+#if (defined(PS_DEC) || defined(DRM_PS))
+#if (defined(PS_DEC) && defined(DRM_PS))
+            if (sbr->bs_extension_id == EXTENSION_ID_PS || sbr->bs_extension_id == DRM_PARAMETRIC_STEREO)
+#else
+#ifdef PS_DEC
+            if (sbr->bs_extension_id == EXTENSION_ID_PS)
+#else
+#ifdef DRM_PS
+            if (sbr->bs_extension_id == DRM_PARAMETRIC_STEREO)
+#endif
+#endif
+#endif
+            {
+                if (ps_ext_read == 0)
+                {
+                    ps_ext_read = 1;
+                } else {
+                    /* to be safe make it 3, will switch to "default"
+                     * in sbr_extension() */
+                    sbr->bs_extension_id = 3;
+                }
+            }
+#endif
+
             tmp_nr_bits += sbr_extension(ld, sbr, sbr->bs_extension_id, nr_bits_left);
 
             /* check if the data read is bigger than the number of available bits */
@@ -787,16 +816,28 @@
 static uint16_t sbr_extension(bitfile *ld, sbr_info *sbr,
                               uint8_t bs_extension_id, uint16_t num_bits_left)
 {
+#ifdef PS_DEC
+    uint8_t header;
+    uint16_t ret;
+#endif
+
     switch (bs_extension_id)
     {
 #ifdef PS_DEC
     case EXTENSION_ID_PS:
-        sbr->ps_used = 1;
         if (!sbr->ps)
         {
             sbr->ps = ps_init(get_sr_index(sbr->sample_rate));
         }
-        return ps_data(sbr->ps, ld);
+        ret = ps_data(sbr->ps, ld, &header);
+
+        /* enable PS if and only if: a header has been decoded */
+        if (sbr->ps_used == 0 && header == 1)
+        {
+            sbr->ps_used = 1;
+        }
+
+        return ret;
 #endif
 #ifdef DRM_PS
     case DRM_PARAMETRIC_STEREO:
--- a/libfaad/specrec.c
+++ b/libfaad/specrec.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: specrec.c,v 1.52 2004/07/31 15:48:57 menno Exp $
+** $Id: specrec.c,v 1.54 2004/09/04 14:56:28 menno Exp $
 **/
 
 /*
@@ -849,18 +849,9 @@
 #endif
 
 
-    /* determine whether some mono->stereo tool is used */
-#if (defined(PS_DEC) || defined(DRM_PS))
-    output_channels = hDecoder->ps_used[hDecoder->fr_ch_ele] ? 2 : 1;
-#else
-    output_channels = 1;
-#endif
-#ifdef DRM_PS
-    /* for DRM error recovery is crucial */
-    /* simply always allocate 2 channels, you never know when PS will pop up */
-    if (hDecoder->object_type == DRM_ER_LC)
-        output_channels = 2;
-#endif
+    /* always allocate 2 channels, PS can always "suddenly" turn up */
+    output_channels = 2;
+
     if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0)
     {
         /* element_output_channels not set yet */
@@ -1025,10 +1016,8 @@
     }
 #endif
 
-#ifdef DRM_PS
-    /* copy L to R for DRM when no PS is used */
-    if ((hDecoder->object_type == DRM_ER_LC) &&
-        (hDecoder->ps_used[hDecoder->fr_ch_ele] == 0))
+    /* copy L to R when no PS is used */
+    if ((hDecoder->ps_used[hDecoder->fr_ch_ele] == 0))
     {
         uint8_t ele = hDecoder->fr_ch_ele;
         uint8_t ch = sce->channel;
@@ -1037,7 +1026,6 @@
 
         memcpy(hDecoder->time_out[ch+1], hDecoder->time_out[ch], frame_size);
     }
-#endif
 
     return 0;
 }