avfilter/framesync: allocate FFFrameSyncIn internally

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2013-10-05 20:19:23 +00:00
parent a16251a6d0
commit 0190c372ef
5 changed files with 22 additions and 10 deletions

View File

@ -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;

View File

@ -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

View File

@ -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)

View File

@ -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.

View File

@ -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;