aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Freire <klaussfreire@gmail.com>2016-01-21 03:32:49 -0300
committerClaudio Freire <klaussfreire@gmail.com>2016-01-21 03:47:28 -0300
commitadc7d2a4ce8ff09431d22441b1a41f1cc9dff0e4 (patch)
tree1a75e4295909cf99946c6263218115f165cd456e
parent8bbb9723508b0fdee7f25dc4007f90b79928a8bc (diff)
downloadffmpeg-adc7d2a4ce8ff09431d22441b1a41f1cc9dff0e4.tar.gz
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
-rw-r--r--libavcodec/aacenc_tns.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/libavcodec/aacenc_tns.c b/libavcodec/aacenc_tns.c
index 43fa974581..2ffe1f8de8 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;