summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DOCS/man/vf.rst6
-rw-r--r--old-makefile1
-rw-r--r--video/filter/vf.c2
-rw-r--r--video/filter/vf_buffer.c93
-rw-r--r--wscript_build.py1
5 files changed, 103 insertions, 0 deletions
diff --git a/DOCS/man/vf.rst b/DOCS/man/vf.rst
index d25686f137..8adf396068 100644
--- a/DOCS/man/vf.rst
+++ b/DOCS/man/vf.rst
@@ -969,3 +969,9 @@ Available filters are:
Use default VDPAU scaling (default).
1-9
Apply high quality VDPAU scaling (needs capable hardware).
+
+``buffer=<num>``
+ Buffer ``<num>`` frames in the filter chain. This filter is probably pretty
+ useless, except for debugging. (Note that this won't help smoothing out
+ latencies with decoding, because the filter will never output a frame if
+ the buffer isn't full, except on EOF.)
diff --git a/old-makefile b/old-makefile
index a1d98e60ec..aac2379a3d 100644
--- a/old-makefile
+++ b/old-makefile
@@ -247,6 +247,7 @@ SOURCES = audio/audio.c \
video/decode/vd_lavc.c \
video/filter/vf.c \
video/filter/pullup.c \
+ video/filter/vf_buffer.c \
video/filter/vf_crop.c \
video/filter/vf_delogo.c \
video/filter/vf_divtc.c \
diff --git a/video/filter/vf.c b/video/filter/vf.c
index 785fb9b908..e76d30ea23 100644
--- a/video/filter/vf.c
+++ b/video/filter/vf.c
@@ -72,6 +72,7 @@ extern const vf_info_t vf_info_lavfi;
extern const vf_info_t vf_info_vaapi;
extern const vf_info_t vf_info_vapoursynth;
extern const vf_info_t vf_info_vdpaupp;
+extern const vf_info_t vf_info_buffer;
// list of available filters:
static const vf_info_t *const filter_list[] = {
@@ -109,6 +110,7 @@ static const vf_info_t *const filter_list[] = {
&vf_info_sub,
&vf_info_yadif,
&vf_info_stereo3d,
+ &vf_info_buffer,
#if HAVE_DLOPEN
&vf_info_dlopen,
#endif
diff --git a/video/filter/vf_buffer.c b/video/filter/vf_buffer.c
new file mode 100644
index 0000000000..2a7e458637
--- /dev/null
+++ b/video/filter/vf_buffer.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "talloc.h"
+
+#include "options/m_option.h"
+
+#include "video/img_format.h"
+#include "video/mp_image.h"
+
+#include "vf.h"
+
+#define MAX_Q 100
+
+struct vf_priv_s {
+ struct mp_image *queued[MAX_Q];
+ int num_queued;
+ int cfg_num;
+};
+
+static void flush(struct vf_instance *vf)
+{
+ for (int n = 0; n < vf->priv->num_queued; n++)
+ mp_image_unrefp(&vf->priv->queued[n]);
+ vf->priv->num_queued = 0;
+}
+
+static int config(struct vf_instance *vf,
+ int width, int height, int d_width, int d_height,
+ unsigned int flags, unsigned int outfmt)
+{
+ flush(vf);
+ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static int filter_ext(struct vf_instance *vf, struct mp_image *mpi)
+{
+ struct vf_priv_s *p = vf->priv;
+ if (mpi) {
+ if (p->num_queued == p->cfg_num) {
+ vf_add_output_frame(vf, p->queued[p->num_queued - 1]);
+ p->num_queued--;
+ }
+ p->num_queued++;
+ for (int n = p->num_queued - 1; n > 0; n--)
+ p->queued[n] = p->queued[n - 1];
+ p->queued[0] = mpi;
+ } else {
+ // EOF
+ while (p->num_queued) {
+ vf_add_output_frame(vf, p->queued[p->num_queued - 1]);
+ p->num_queued--;
+ }
+ }
+ return 0;
+}
+
+static int control(vf_instance_t *vf, int request, void *data)
+{
+ if (request == VFCTRL_SEEK_RESET) {
+ flush(vf);
+ return CONTROL_OK;
+ }
+ return CONTROL_UNKNOWN;
+}
+
+static void uninit(vf_instance_t *vf)
+{
+ flush(vf);
+}
+
+static int vf_open(vf_instance_t *vf)
+{
+ vf->config = config;
+ vf->filter_ext = filter_ext;
+ vf->control = control;
+ vf->uninit = uninit;
+ return 1;
+}
+
+#define OPT_BASE_STRUCT struct vf_priv_s
+const vf_info_t vf_info_buffer = {
+ .description = "buffer a number of frames",
+ .name = "buffer",
+ .open = vf_open,
+ .priv_size = sizeof(struct vf_priv_s),
+ .options = (const struct m_option[]){
+ OPT_INTRANGE("num", cfg_num, 0, 1, MAX_Q, OPTDEF_INT(2)),
+ {0}
+ },
+};
diff --git a/wscript_build.py b/wscript_build.py
index 463c3c1084..9496977340 100644
--- a/wscript_build.py
+++ b/wscript_build.py
@@ -302,6 +302,7 @@ def build(ctx):
( "video/decode/vdpau.c", "vdpau-hwaccel" ),
( "video/filter/pullup.c" ),
( "video/filter/vf.c" ),
+ ( "video/filter/vf_buffer.c" ),
( "video/filter/vf_crop.c" ),
( "video/filter/vf_delogo.c" ),
( "video/filter/vf_divtc.c" ),