shithub: aacdec

Download patch

ref: e48c2c82a5f9192622a29b052122ef594da891c5
parent: f71b5e81f563d94fa284977a326520d269d8353e
parent: 2783bdac5d524a0574b7eca273e8ca6b9a6b8014
author: Fabian Greffrath <fabian@greffrath.com>
date: Tue Oct 6 02:45:42 EDT 2020

Merge pull request #63 from awesie/awesie-fix-1

Fix various issues

--- a/frontend/main.c
+++ b/frontend/main.c
@@ -872,7 +872,7 @@
         if (NeAACDecAudioSpecificConfig(mp4config.asc.buf, mp4config.asc.size, &mp4ASC) >= 0)
         {
             if (mp4ASC.frameLengthFlag == 1) framesize = 960;
-            if (mp4ASC.sbr_present_flag == 1) framesize *= 2;
+            if (mp4ASC.sbr_present_flag == 1 || mp4ASC.forceUpSampling) framesize *= 2;
         }
     }
 
--- a/libfaad/mp4.c
+++ b/libfaad/mp4.c
@@ -107,7 +107,11 @@
     0, /* 27 ER Parametric */
 #endif
     0, /* 28 (Reserved) */
-    0, /* 29 (Reserved) */
+#ifdef PS_DEC
+    1, /* 29 AAC LC + SBR + PS */
+#else
+    0, /* 29 AAC LC + SBR + PS */
+#endif
     0, /* 30 (Reserved) */
     0  /* 31 (Reserved) */
 };
@@ -174,7 +178,7 @@
 
 #ifdef SBR_DEC
     mp4ASC->sbr_present_flag = -1;
-    if (mp4ASC->objectTypeIndex == 5)
+    if (mp4ASC->objectTypeIndex == 5 || mp4ASC->objectTypeIndex == 29)
     {
         uint8_t tmp;
 
@@ -231,7 +235,7 @@
     else
 		bits_to_decode = (int8_t)(buffer_size*8 - (startpos-faad_get_processed_bits(ld)));
 
-    if ((mp4ASC->objectTypeIndex != 5) && (bits_to_decode >= 16))
+    if ((mp4ASC->objectTypeIndex != 5 && mp4ASC->objectTypeIndex != 29) && (bits_to_decode >= 16))
     {
         int16_t syncExtensionType = (int16_t)faad_getbits(ld, 11
             DEBUGVAR(1,9,"parse_audio_decoder_specific_info(): syncExtensionType"));
--- a/libfaad/pns.c
+++ b/libfaad/pns.c
@@ -236,7 +236,17 @@
                 if ((ics_right != NULL)
                     && is_noise(ics_right, g, sfb))
                 {
-                    if (channel_pair &&
+#ifdef LTP_DEC
+                    /* See comment above. */
+                    ics_right->ltp.long_used[sfb] = 0;
+                    ics_right->ltp2.long_used[sfb] = 0;
+#endif
+#ifdef MAIN_DEC
+                    /* See comment above. */
+                    ics_right->pred.prediction_used[sfb] = 0;
+#endif
+
+                    if (channel_pair && is_noise(ics_left, g, sfb) &&
                         (((ics_left->ms_mask_present == 1) &&
                         (ics_left->ms_used[g][sfb])) ||
                         (ics_left->ms_mask_present == 2)))
@@ -251,14 +261,6 @@
                             ics_right->scale_factors[g][sfb], size, sub, &r1_dep, &r2_dep);
 
                     } else /*if (ics_left->ms_mask_present == 0)*/ {
-
-#ifdef LTP_DEC
-                        ics_right->ltp.long_used[sfb] = 0;
-                        ics_right->ltp2.long_used[sfb] = 0;
-#endif
-#ifdef MAIN_DEC
-                        ics_right->pred.prediction_used[sfb] = 0;
-#endif
 
                         offs = ics_right->swb_offset[sfb];
                         size = min(ics_right->swb_offset[sfb+1], ics_right->swb_offset_max) - offs;
--- a/libfaad/sbr_dec.c
+++ b/libfaad/sbr_dec.c
@@ -97,9 +97,16 @@
     {
         sbr->numTimeSlotsRate = RATE * NO_TIME_SLOTS_960;
         sbr->numTimeSlots = NO_TIME_SLOTS_960;
-    } else {
+    }
+    else if (framelength == 1024)
+    {
         sbr->numTimeSlotsRate = RATE * NO_TIME_SLOTS;
         sbr->numTimeSlots = NO_TIME_SLOTS;
+    }
+    else
+    {
+        faad_free(sbr);
+        return NULL;
     }
 
     sbr->GQ_ringbuf_index[0] = 0;
--- a/libfaad/specrec.c
+++ b/libfaad/specrec.c
@@ -1056,6 +1056,8 @@
 #endif
                 );
         }
+        if (!hDecoder->sbr[ele])
+            return 19;
 
         if (sce->ics1.window_sequence == EIGHT_SHORT_SEQUENCE)
             hDecoder->sbr[ele]->maxAACLine = 8*min(sce->ics1.swb_offset[max(sce->ics1.max_sfb-1, 0)], sce->ics1.swb_offset_max);
@@ -1312,6 +1314,8 @@
 #endif
                 );
         }
+        if (!hDecoder->sbr[ele])
+            return 19;
 
         if (cpe->ics1.window_sequence == EIGHT_SHORT_SEQUENCE)
             hDecoder->sbr[ele]->maxAACLine = 8*min(cpe->ics1.swb_offset[max(cpe->ics1.max_sfb-1, 0)], cpe->ics1.swb_offset_max);
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -884,7 +884,10 @@
                     if ((ics->ltp.data_present = faad_get1bit(ld
                         DEBUGVAR(1,50,"ics_info(): ltp.data_present"))) & 1)
                     {
-                        ltp_data(hDecoder, ics, &(ics->ltp), ld);
+                        if ((retval = ltp_data(hDecoder, ics, &(ics->ltp), ld)) > 0)
+                        {
+                            return retval;
+                        }
                     }
                 }
 #endif
@@ -1091,6 +1094,8 @@
 #endif
                     );
             }
+            if (!hDecoder->sbr[sbr_ele])
+                return 19;
 
             hDecoder->sbr_present_flag = 1;
 
@@ -1359,6 +1364,11 @@
         {
             hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, hDecoder->element_id[0],
                 2*get_sample_rate(hDecoder->sf_index), 0 /* ds SBR */, 1);
+        }
+        if (!hDecoder->sbr[0])
+        {
+            hInfo->error = 19;
+            return;
         }
 
         /* Reverse bit reading of SBR data in DRM audio frame */