[FFmpeg-cvslog] AAC encoder: check for NaNs/inf in TNS gain

Claudio Freire git at videolan.org
Thu Jan 21 08:01:15 CET 2016


ffmpeg | branch: master | Claudio Freire <klaussfreire at gmail.com> | Thu Jan 21 03:32:49 2016 -0300| [adc7d2a4ce8ff09431d22441b1a41f1cc9dff0e4] | committer: Claudio Freire

AAC encoder: check for NaNs/inf in TNS gain

Can happen in cases where's there's zero autocorrelation (pulses),
and it also implies NaN/inf coeffs

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=adc7d2a4ce8ff09431d22441b1a41f1cc9dff0e4
---

 libavcodec/aacenc_tns.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/libavcodec/aacenc_tns.c b/libavcodec/aacenc_tns.c
index 43fa974..2ffe1f8 100644
--- a/libavcodec/aacenc_tns.c
+++ b/libavcodec/aacenc_tns.c
@@ -25,6 +25,7 @@
  * @author Rostislav Pehlivanov ( atomnuker gmail com )
  */
 
+#include "libavutil/libm.h"
 #include "aacenc.h"
 #include "aacenc_tns.h"
 #include "aactab.h"
@@ -170,13 +171,18 @@ void ff_aac_search_for_tns(AACEncContext *s, SingleChannelElement *sce)
     const int order = is8 ? 7 : s->profile == FF_PROFILE_AAC_LOW ? 12 : TNS_MAX_ORDER;
     const int slant = sce->ics.window_sequence[0] == LONG_STOP_SEQUENCE  ? 1 :
                       sce->ics.window_sequence[0] == LONG_START_SEQUENCE ? 0 : 2;
+    const int sfb_len = sfb_end - sfb_start;
+    const int coef_len = sce->ics.swb_offset[sfb_end] - sce->ics.swb_offset[sfb_start];
+
+    if (coef_len <= 0 || sfb_len <= 0) {
+        sce->tns.present = 0;
+        return;
+    }
 
     for (w = 0; w < sce->ics.num_windows; w++) {
         float en[2] = {0.0f, 0.0f};
         int oc_start = 0, os_start = 0;
-        int coef_start = w*sce->ics.num_swb + sce->ics.swb_offset[sfb_start];
-        int coef_len = sce->ics.swb_offset[sfb_end] - sce->ics.swb_offset[sfb_start];
-        const int sfb_len = sfb_end - sfb_start;
+        int coef_start = sce->ics.swb_offset[sfb_start];
 
         for (g = sfb_start; g < sce->ics.num_swb && g <= sfb_end; g++) {
             FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[w*16+g];
@@ -186,14 +192,11 @@ void ff_aac_search_for_tns(AACEncContext *s, SingleChannelElement *sce)
                 en[0] += band->energy;
         }
 
-        if (coef_len <= 0 || sfb_len <= 0)
-            continue;
-
         /* LPC */
         gain = ff_lpc_calc_ref_coefs_f(&s->lpc, &sce->coeffs[w*128 + coef_start],
                                        coef_len, order, coefs);
 
-        if (!order || gain < TNS_GAIN_THRESHOLD_LOW || gain > TNS_GAIN_THRESHOLD_HIGH)
+        if (!order || !isfinite(gain) || gain < TNS_GAIN_THRESHOLD_LOW || gain > TNS_GAIN_THRESHOLD_HIGH)
             continue;
 
         tns->n_filt[w] = is8 ? 1 : order != TNS_MAX_ORDER ? 2 : 3;



More information about the ffmpeg-cvslog mailing list