aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2013-10-05 20:19:23 +0000
committerPaul B Mahol <onemda@gmail.com>2015-08-26 11:12:23 +0000
commit0190c372ef79740ddc546e9ce1877a908475d3e1 (patch)
treee4cc964790855da1cc85dd0d540d1e7004b6284b
parenta16251a6d0401c772bd985f4c611caf97ca5e537 (diff)
downloadffmpeg-0190c372ef79740ddc546e9ce1877a908475d3e1.tar.gz
avfilter/framesync: allocate FFFrameSyncIn internally
Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r--libavfilter/dualinput.c8
-rw-r--r--libavfilter/dualinput.h1
-rw-r--r--libavfilter/framesync.c9
-rw-r--r--libavfilter/framesync.h7
-rw-r--r--libavfilter/vf_mergeplanes.c7
5 files changed, 22 insertions, 10 deletions
diff --git a/libavfilter/dualinput.c b/libavfilter/dualinput.c
index 45f681078d..ea2007f93c 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 0ec0ea7350..5ff23e6249 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 12db50cb77..bdac40b783 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 2072781054..7ba99d5d86 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 c76e82a419..734327eacc 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;