[FFmpeg-cvslog] avcodec/sonic: Don't allocate a temporary buffer for every frame
Andreas Rheinhardt
git at videolan.org
Sat Nov 7 03:05:18 EET 2020
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Sun Sep 27 11:34:34 2020 +0200| [992adc8aaff5ac4b146c4f6bd633870c9ba96ea0] | committer: Andreas Rheinhardt
avcodec/sonic: Don't allocate a temporary buffer for every frame
Instead allocate it together with the buffer that it mirrors.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=992adc8aaff5ac4b146c4f6bd633870c9ba96ea0
---
libavcodec/sonic.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
index 88d7672bf2..a285228bbc 100644
--- a/libavcodec/sonic.c
+++ b/libavcodec/sonic.c
@@ -500,14 +500,11 @@ static int predictor_calc_error(int *k, int *state, int order, int error)
// copes better with quantization, and calculates the
// actual whitened result as it goes.
-static int modified_levinson_durbin(int *window, int window_entries,
+static void modified_levinson_durbin(int *window, int window_entries,
int *out, int out_entries, int channels, int *tap_quant)
{
int i;
- int *state = av_calloc(window_entries, sizeof(*state));
-
- if (!state)
- return AVERROR(ENOMEM);
+ int *state = window + window_entries;
memcpy(state, window, window_entries * sizeof(*state));
@@ -571,9 +568,6 @@ static int modified_levinson_durbin(int *window, int window_entries,
}
#endif
}
-
- av_free(state);
- return 0;
}
static inline int code_samplerate(int samplerate)
@@ -665,7 +659,7 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx)
s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples));
s->window_size = ((2*s->tail_size)+s->frame_size);
- s->window = av_calloc(s->window_size, sizeof(*s->window));
+ s->window = av_calloc(s->window_size, 2 * sizeof(*s->window));
if (!s->window || !s->int_samples)
return AVERROR(ENOMEM);
@@ -776,10 +770,8 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
s->tail[i] = s->int_samples[s->frame_size - s->tail_size + i];
// generate taps
- ret = modified_levinson_durbin(s->window, s->window_size,
+ modified_levinson_durbin(s->window, s->window_size,
s->predictor_k, s->num_taps, s->channels, s->tap_quant);
- if (ret < 0)
- return ret;
if ((ret = intlist_write(&c, state, s->predictor_k, s->num_taps, 0)) < 0)
return ret;
More information about the ffmpeg-cvslog
mailing list