[FFmpeg-devel] [PATCH 1/2] avfilter/framesync: allocate FFFrameSyncIn internally

Paul B Mahol onemda at gmail.com
Tue Aug 25 16:34:26 CEST 2015


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
Already OKed years ago.
---
 libavfilter/dualinput.c      | 8 ++++++--
 libavfilter/dualinput.h      | 1 -
 libavfilter/framesync.c      | 9 ++++++++-
 libavfilter/framesync.h      | 7 ++++---
 libavfilter/vf_mergeplanes.c | 7 ++++---
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/libavfilter/dualinput.c b/libavfilter/dualinput.c
index 45f6810..ea2007f 100644
--- a/libavfilter/dualinput.c
+++ b/libavfilter/dualinput.c
@@ -42,9 +42,13 @@ static int process_frame(FFFrameSync *fs)
 
 int ff_dualinput_init(AVFilterContext *ctx, FFDualInputContext *s)
 {
-    FFFrameSyncIn *in = s->fs.in;
+    FFFrameSyncIn *in;
+    int ret;
 
-    ff_framesync_init(&s->fs, ctx, 2);
+    if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
+        return ret;
+
+    in = s->fs.in;
     s->fs.opaque = s;
     s->fs.on_event = process_frame;
     in[0].time_base = ctx->inputs[0]->time_base;
diff --git a/libavfilter/dualinput.h b/libavfilter/dualinput.h
index 0ec0ea7..5ff23e6 100644
--- a/libavfilter/dualinput.h
+++ b/libavfilter/dualinput.h
@@ -31,7 +31,6 @@
 
 typedef struct {
     FFFrameSync fs;
-    FFFrameSyncIn second_input; /* must be immediately after fs */
 
     AVFrame *(*process)(AVFilterContext *ctx, AVFrame *main, const AVFrame *second);
     int shortest;               ///< terminate stream when the second input terminates
diff --git a/libavfilter/framesync.c b/libavfilter/framesync.c
index 12db50c..bdac40b 100644
--- a/libavfilter/framesync.c
+++ b/libavfilter/framesync.c
@@ -46,11 +46,16 @@ enum {
     STATE_EOF,
 };
 
-void ff_framesync_init(FFFrameSync *fs, void *parent, unsigned nb_in)
+int ff_framesync_init(FFFrameSync *fs, void *parent, unsigned nb_in)
 {
     fs->class  = &framesync_class;
     fs->parent = parent;
     fs->nb_in  = nb_in;
+
+    fs->in = av_calloc(nb_in, sizeof(*fs->in));
+    if (!fs->in)
+        return AVERROR(ENOMEM);
+    return 0;
 }
 
 static void framesync_sync_level_update(FFFrameSync *fs)
@@ -267,6 +272,8 @@ void ff_framesync_uninit(FFFrameSync *fs)
         av_frame_free(&fs->in[i].frame_next);
         ff_bufqueue_discard_all(&fs->in[i].queue);
     }
+
+    av_freep(&fs->in);
 }
 
 int ff_framesync_process_frame(FFFrameSync *fs, unsigned all)
diff --git a/libavfilter/framesync.h b/libavfilter/framesync.h
index 2072781..7ba99d5 100644
--- a/libavfilter/framesync.h
+++ b/libavfilter/framesync.h
@@ -201,9 +201,9 @@ typedef struct FFFrameSync {
     uint8_t eof;
 
     /**
-     * Array of inputs; all inputs must be in consecutive memory
+     * Pointer to array of inputs.
      */
-    FFFrameSyncIn in[1]; /* must be the last field */
+    FFFrameSyncIn *in;
 
 } FFFrameSync;
 
@@ -215,8 +215,9 @@ typedef struct FFFrameSync {
  * @param  fs      frame sync structure to initialize
  * @param  parent  parent object, used for logging
  * @param  nb_in   number of inputs
+ * @return  >= 0 for success or a negative error code
  */
-void ff_framesync_init(FFFrameSync *fs, void *parent, unsigned nb_in);
+int ff_framesync_init(FFFrameSync *fs, void *parent, unsigned nb_in);
 
 /**
  * Configure a frame sync structure.
diff --git a/libavfilter/vf_mergeplanes.c b/libavfilter/vf_mergeplanes.c
index c76e82a..734327e 100644
--- a/libavfilter/vf_mergeplanes.c
+++ b/libavfilter/vf_mergeplanes.c
@@ -46,7 +46,6 @@ typedef struct MergePlanesContext {
     const AVPixFmtDescriptor *outdesc;
 
     FFFrameSync fs;
-    FFFrameSyncIn fsin[3]; /* must be immediately after fs */
 } MergePlanesContext;
 
 #define OFFSET(x) offsetof(MergePlanesContext, x)
@@ -174,9 +173,11 @@ static int config_output(AVFilterLink *outlink)
     MergePlanesContext *s = ctx->priv;
     InputParam inputsp[4];
     FFFrameSyncIn *in;
-    int i;
+    int i, ret;
+
+    if ((ret = ff_framesync_init(&s->fs, ctx, s->nb_inputs)) < 0)
+        return ret;
 
-    ff_framesync_init(&s->fs, ctx, s->nb_inputs);
     in = s->fs.in;
     s->fs.opaque = s;
     s->fs.on_event = process_frame;
-- 
1.7.11.2



More information about the ffmpeg-devel mailing list