2013-05-25 17:25:46 +03:00
|
|
|
/*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dualinput.h"
|
|
|
|
#include "libavutil/timestamp.h"
|
|
|
|
|
2013-08-28 01:07:22 +03:00
|
|
|
static int process_frame(FFFrameSync *fs)
|
2013-05-25 17:25:46 +03:00
|
|
|
{
|
2013-08-28 01:07:22 +03:00
|
|
|
AVFilterContext *ctx = fs->parent;
|
|
|
|
FFDualInputContext *s = fs->opaque;
|
|
|
|
AVFrame *mainpic = NULL, *secondpic = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if ((ret = ff_framesync_get_frame(&s->fs, 0, &mainpic, 1)) < 0 ||
|
|
|
|
(ret = ff_framesync_get_frame(&s->fs, 1, &secondpic, 0)) < 0) {
|
|
|
|
av_frame_free(&mainpic);
|
|
|
|
return ret;
|
2013-05-25 17:25:46 +03:00
|
|
|
}
|
2013-08-28 01:07:22 +03:00
|
|
|
av_assert0(mainpic);
|
2016-02-09 19:32:54 +02:00
|
|
|
mainpic->pts = av_rescale_q(s->fs.pts, s->fs.time_base, ctx->outputs[0]->time_base);
|
2013-08-28 01:07:22 +03:00
|
|
|
if (secondpic && !ctx->is_disabled)
|
|
|
|
mainpic = s->process(ctx, mainpic, secondpic);
|
2013-05-25 17:25:46 +03:00
|
|
|
ret = ff_filter_frame(ctx->outputs[0], mainpic);
|
|
|
|
av_assert1(ret != AVERROR(EAGAIN));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-28 01:07:22 +03:00
|
|
|
int ff_dualinput_init(AVFilterContext *ctx, FFDualInputContext *s)
|
2013-05-25 17:25:46 +03:00
|
|
|
{
|
2013-10-05 23:19:23 +03:00
|
|
|
FFFrameSyncIn *in;
|
|
|
|
int ret;
|
2013-08-28 01:07:22 +03:00
|
|
|
|
2013-10-05 23:19:23 +03:00
|
|
|
if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
in = s->fs.in;
|
2013-08-28 01:07:22 +03:00
|
|
|
s->fs.opaque = s;
|
|
|
|
s->fs.on_event = process_frame;
|
|
|
|
in[0].time_base = ctx->inputs[0]->time_base;
|
|
|
|
in[1].time_base = ctx->inputs[1]->time_base;
|
|
|
|
in[0].sync = 2;
|
|
|
|
in[0].before = EXT_STOP;
|
|
|
|
in[0].after = EXT_INFINITY;
|
|
|
|
in[1].sync = 1;
|
|
|
|
in[1].before = EXT_NULL;
|
|
|
|
in[1].after = EXT_INFINITY;
|
|
|
|
|
|
|
|
if (s->shortest)
|
2014-01-18 02:34:17 +03:00
|
|
|
in[0].after = in[1].after = EXT_STOP;
|
2013-08-28 01:07:22 +03:00
|
|
|
if (!s->repeatlast) {
|
2014-02-04 16:54:14 +03:00
|
|
|
in[1].after = EXT_NULL;
|
2013-08-28 01:07:22 +03:00
|
|
|
in[1].sync = 0;
|
|
|
|
}
|
2016-06-25 00:22:47 +02:00
|
|
|
if (s->skip_initial_unpaired) {
|
|
|
|
in[1].before = EXT_STOP;
|
|
|
|
}
|
2013-05-25 17:25:46 +03:00
|
|
|
|
2013-08-28 01:07:22 +03:00
|
|
|
return ff_framesync_configure(&s->fs);
|
2013-05-25 17:25:46 +03:00
|
|
|
}
|
|
|
|
|
2013-09-28 19:06:08 +03:00
|
|
|
int ff_dualinput_filter_frame(FFDualInputContext *s,
|
2013-05-25 17:25:46 +03:00
|
|
|
AVFilterLink *inlink, AVFrame *in)
|
|
|
|
{
|
2013-08-28 01:07:22 +03:00
|
|
|
return ff_framesync_filter_frame(&s->fs, inlink, in);
|
2013-05-25 17:25:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int ff_dualinput_request_frame(FFDualInputContext *s, AVFilterLink *outlink)
|
|
|
|
{
|
2013-08-28 01:07:22 +03:00
|
|
|
return ff_framesync_request_frame(&s->fs, outlink);
|
2013-05-25 17:25:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ff_dualinput_uninit(FFDualInputContext *s)
|
|
|
|
{
|
2013-08-28 01:07:22 +03:00
|
|
|
ff_framesync_uninit(&s->fs);
|
2013-05-25 17:25:46 +03:00
|
|
|
}
|