diff options
author | Paul B Mahol <onemda@gmail.com> | 2018-11-02 10:11:24 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2018-11-02 12:32:34 +0100 |
commit | ef1aadffc785b48ed62c45d954289e754f43ef46 (patch) | |
tree | 2ac5129606a60dd87bfc47e1dcc78e089ece27c5 | |
parent | 4620e4c7ad2fd19d0bbe17c25c3466c40cc97279 (diff) | |
download | ffmpeg-ef1aadffc785b48ed62c45d954289e754f43ef46.tar.gz |
avfilter/f_loop: switch to activate
-rw-r--r-- | libavfilter/f_loop.c | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/libavfilter/f_loop.c b/libavfilter/f_loop.c index 1f857abf8d..d9d55f9837 100644 --- a/libavfilter/f_loop.c +++ b/libavfilter/f_loop.c @@ -25,6 +25,7 @@ #include "libavutil/opt.h" #include "avfilter.h" #include "audio.h" +#include "filters.h" #include "formats.h" #include "internal.h" #include "video.h" @@ -44,6 +45,7 @@ typedef struct LoopContext { int64_t ignored_samples; int loop; + int eof; int64_t size; int64_t start; int64_t pts; @@ -330,25 +332,44 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) return ret; } -static int request_frame(AVFilterLink *outlink) +static int activate(AVFilterContext *ctx) { - AVFilterContext *ctx = outlink->src; + AVFilterLink *inlink = ctx->inputs[0]; + AVFilterLink *outlink = ctx->outputs[0]; LoopContext *s = ctx->priv; - int ret = 0; + AVFrame *frame = NULL; + int ret, status; + int64_t pts; - if ((!s->size) || - (s->nb_frames < s->size) || - (s->nb_frames >= s->size && s->loop == 0)) { - ret = ff_request_frame(ctx->inputs[0]); - } else { - ret = push_frame(ctx); + FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); + + if (!s->eof && (s->nb_frames < s->size || !s->loop)) { + ret = ff_inlink_consume_frame(inlink, &frame); + if (ret < 0) + return ret; + if (ret > 0) + return filter_frame(inlink, frame); } - if (ret == AVERROR_EOF && s->nb_frames > 0 && s->loop != 0) { - ret = push_frame(ctx); + if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) { + if (status == AVERROR_EOF) + s->eof = 1; } - return ret; + if (s->eof && (s->loop == 0 || s->nb_frames < s->size)) { + ff_outlink_set_status(outlink, AVERROR_EOF, s->duration); + return 0; + } + + if (!s->eof && (!s->size || + (s->nb_frames < s->size) || + (s->nb_frames >= s->size && s->loop == 0))) { + FF_FILTER_FORWARD_WANTED(outlink, inlink); + } else if (s->loop && s->nb_frames == s->size) { + return push_frame(ctx); + } + + return FFERROR_NOT_READY; } static const AVOption loop_options[] = { @@ -362,18 +383,16 @@ AVFILTER_DEFINE_CLASS(loop); static const AVFilterPad inputs[] = { { - .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .filter_frame = filter_frame, + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, { NULL } }; static const AVFilterPad outputs[] = { { - .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .request_frame = request_frame, + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, { NULL } }; @@ -385,6 +404,7 @@ AVFilter ff_vf_loop = { .priv_class = &loop_class, .init = init, .uninit = uninit, + .activate = activate, .inputs = inputs, .outputs = outputs, }; |