summaryrefslogtreecommitdiff
path: root/libavcodec/aacenc.c
diff options
context:
space:
mode:
authorClaudio Freire <klaussfreire@gmail.com>2016-04-05 23:13:44 -0300
committerClaudio Freire <klaussfreire@gmail.com>2016-04-05 23:13:44 -0300
commit8005b6de4f88c9e3739a3a4ceda4288804788df9 (patch)
tree62d70a122a4def1bd351ef00a4e7336ee3ba5337 /libavcodec/aacenc.c
parent2c697c650ca7dec27df63984c128beee30aa13b4 (diff)
AAC encoder: fix valgrind errors
Move wi.clipping computation outside of psy_lame_window, LFE channels don't even call that, and make the LFE path also initialize window_type[1] which is needed by analyze_channel
Diffstat (limited to 'libavcodec/aacenc.c')
-rw-r--r--libavcodec/aacenc.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 023260a7ae..2653cefaaa 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -554,10 +554,11 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
if (!frame)
la = NULL;
if (tag == TYPE_LFE) {
- wi[ch].window_type[0] = ONLY_LONG_SEQUENCE;
+ wi[ch].window_type[0] = wi[ch].window_type[1] = ONLY_LONG_SEQUENCE;
wi[ch].window_shape = 0;
wi[ch].num_windows = 1;
wi[ch].grouping[0] = 1;
+ wi[ch].clipping[0] = 0;
/* Only the lowest 12 coefficients are used in a LFE channel.
* The expression below results in only the bottom 8 coefficients
@@ -582,9 +583,22 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
ics->tns_max_bands = wi[ch].window_type[0] == EIGHT_SHORT_SEQUENCE ?
ff_tns_max_bands_128 [s->samplerate_index]:
ff_tns_max_bands_1024[s->samplerate_index];
- clip_avoidance_factor = 0.0f;
+
for (w = 0; w < ics->num_windows; w++)
ics->group_len[w] = wi[ch].grouping[w];
+
+ /* Calculate input sample maximums and evaluate clipping risk */
+ clip_avoidance_factor = 0.0f;
+ for (w = 0; w < ics->num_windows; w++) {
+ const float *wbuf = overlap + w * 128;
+ const int wlen = 2048 / ics->num_windows;
+ float max = 0;
+ int j;
+ /* mdct input is 2 * output */
+ for (j = 0; j < wlen; j++)
+ max = FFMAX(max, fabsf(wbuf[j]));
+ wi[ch].clipping[w] = max;
+ }
for (w = 0; w < ics->num_windows; w++) {
if (wi[ch].clipping[w] > CLIP_AVOIDANCE_FACTOR) {
ics->window_clipping[w] = 1;