[FFmpeg-cvslog] avfilter/vf_waveform: simplify memory allocations

Paul B Mahol git at videolan.org
Tue Sep 1 10:44:08 CEST 2015


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Aug 31 16:45:55 2015 +0000| [97c7c39d2539127094a3c30a1d13653e25b85d02] | committer: Paul B Mahol

avfilter/vf_waveform: simplify memory allocations

Signed-off-by: Paul B Mahol <onemda at gmail.com>

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

 libavfilter/vf_waveform.c |   26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/libavfilter/vf_waveform.c b/libavfilter/vf_waveform.c
index eb49ef3..a856ccb 100644
--- a/libavfilter/vf_waveform.c
+++ b/libavfilter/vf_waveform.c
@@ -52,6 +52,7 @@ typedef struct WaveformContext {
     int            eend[4];
     int            *emax[4];
     int            *emin[4];
+    int            *peak;
     int            filter;
     int            size;
     void (*waveform)(struct WaveformContext *s, AVFrame *in, AVFrame *out,
@@ -908,19 +909,20 @@ static int config_output(AVFilterLink *outlink)
             comp++;
     }
 
-    for (p = 0; p < 4; p++) {
-        av_freep(&s->emax[p]);
-        av_freep(&s->emin[p]);
-    }
+    av_freep(&s->peak);
 
     if (s->mode) {
         outlink->h = s->size * FFMAX(comp * s->display, 1);
-        size = inlink->w * sizeof(int);
+        size = inlink->w;
     } else {
         outlink->w = s->size * FFMAX(comp * s->display, 1);
-        size = inlink->h * sizeof(int);
+        size = inlink->h;
     }
 
+    s->peak = av_malloc_array(size, 8 * sizeof(*s->peak));
+    if (!s->peak)
+        return AVERROR(ENOMEM);
+
     for (p = 0; p < 4; p++) {
         const int is_chroma = (p == 1 || p == 2);
         const int shift_w = (is_chroma ? s->desc->log2_chroma_w : 0);
@@ -933,8 +935,8 @@ static int config_output(AVFilterLink *outlink)
 
         shift = s->mode ? shift_h : shift_w;
 
-        s->emax[plane] = av_malloc(size);
-        s->emin[plane] = av_malloc(size);
+        s->emax[plane] = s->peak + size * (p + 0);
+        s->emin[plane] = s->peak + size * (p + 4);
 
         if (!s->emin[plane] || !s->emax[plane])
             return AVERROR(ENOMEM);
@@ -942,7 +944,7 @@ static int config_output(AVFilterLink *outlink)
         offset = j++ * s->size * s->display;
         s->estart[plane] = offset >> shift;
         s->eend[plane]   = (offset + s->size - 1) >> shift;
-        for (i = 0; i < size / sizeof(int); i++) {
+        for (i = 0; i < size; i++) {
             s->emax[plane][i] = s->estart[plane];
             s->emin[plane][i] = s->eend[plane];
         }
@@ -992,12 +994,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 static av_cold void uninit(AVFilterContext *ctx)
 {
     WaveformContext *s = ctx->priv;
-    int p;
 
-    for (p = 0; p < 4; p++) {
-        av_freep(&s->emax[p]);
-        av_freep(&s->emin[p]);
-    }
+    av_freep(&s->peak);
 }
 
 static const AVFilterPad inputs[] = {



More information about the ffmpeg-cvslog mailing list