summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-18 19:26:13 +0200
committerwm4 <wm4@nowhere>2014-09-18 19:36:55 +0200
commit95bb0bb6711986fc2f999738fcb1158085346872 (patch)
treed1fa41e1b1d12dc877b169c589f11abec1289d24
parent580cf433bd3713f1c00a612be2d57d5b959e8496 (diff)
downloadmpv-95bb0bb6711986fc2f999738fcb1158085346872.tar.bz2
mpv-95bb0bb6711986fc2f999738fcb1158085346872.tar.xz
vf_lavfi: fetch output frames incrementally
Uses the new mechanism introduced in the previous commit. Depending on the actual filter, this distributes CPU load more evenly over time, although it probably doesn't matter.
-rw-r--r--video/filter/vf_lavfi.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/video/filter/vf_lavfi.c b/video/filter/vf_lavfi.c
index 8f1ee243a2..0a14f94bbb 100644
--- a/video/filter/vf_lavfi.c
+++ b/video/filter/vf_lavfi.c
@@ -315,33 +315,34 @@ static int filter_ext(struct vf_instance *vf, struct mp_image *mpi)
return -1;
AVFrame *frame = mp_to_av(vf, mpi);
- if (av_buffersrc_add_frame(p->in, frame) < 0) {
- av_frame_free(&frame);
- return -1;
- }
+ int r = av_buffersrc_add_frame(p->in, frame) < 0 ? -1 : 0;
av_frame_free(&frame);
- for (;;) {
- frame = av_frame_alloc();
- int err = av_buffersink_get_frame(p->out, frame);
- if (err == AVERROR(EAGAIN) || err == AVERROR_EOF) {
- // Not an error situation - no more output buffers in queue.
- // AVERROR_EOF means we shouldn't even give the filter more
- // input, but we don't handle that completely correctly.
- av_frame_free(&frame);
- p->eof |= err == AVERROR_EOF;
- break;
- }
- if (err < 0) {
- av_frame_free(&frame);
- MP_ERR(vf, "libavfilter error: %d\n", err);
- return -1;
- }
+ return r;
+}
+
+static int filter_out(struct vf_instance *vf)
+{
+ struct vf_priv_s *p = vf->priv;
- get_metadata_from_av_frame(vf, frame);
- vf_add_output_frame(vf, av_to_mp(vf, frame));
+ AVFrame *frame = av_frame_alloc();
+ int err = av_buffersink_get_frame(p->out, frame);
+ if (err == AVERROR(EAGAIN) || err == AVERROR_EOF) {
+ // Not an error situation - no more output buffers in queue.
+ // AVERROR_EOF means we shouldn't even give the filter more
+ // input, but we don't handle that completely correctly.
+ av_frame_free(&frame);
+ p->eof |= err == AVERROR_EOF;
+ return 0;
+ }
+ if (err < 0) {
+ av_frame_free(&frame);
+ MP_ERR(vf, "libavfilter error: %d\n", err);
+ return -1;
}
+ get_metadata_from_av_frame(vf, frame);
+ vf_add_output_frame(vf, av_to_mp(vf, frame));
return 0;
}
@@ -374,6 +375,7 @@ static int vf_open(vf_instance_t *vf)
vf->reconfig = NULL;
vf->config = config;
vf->filter_ext = filter_ext;
+ vf->filter_out = filter_out;
vf->filter = NULL;
vf->query_format = query_format;
vf->control = control;