[FFmpeg-devel] [PATCH] lavfi/sink_buffer: implement libav compatibility API (video).

Nicolas George nicolas.george at normalesup.org
Sun Sep 23 20:51:01 CEST 2012


Implement av_buffersink_read() for ffmpeg's version of buffersink.

With this change, avconv linked against ffmpeg's libraries passes
the same number of tests whether it uses ffbuffersink or
buffersink_old.

Note: the framed audio API (av_buffersink_read_samples()) is still
missing for ffmpeg's version to be a drop-in replacement.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/buffersink.c  |    2 +-
 libavfilter/internal.h    |    2 ++
 libavfilter/sink_buffer.c |   30 ++++++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index 2e84fb4..103bffe 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -59,7 +59,7 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *buf)
     return 0;
 }
 
-int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
+int ff_buffersink_read_compat(AVFilterContext *ctx, AVFilterBufferRef **buf)
 {
     BufferSinkContext *s    = ctx->priv;
     AVFilterLink      *link = ctx->inputs[0];
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index c217883..4ccffe1 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -365,4 +365,6 @@ AVFilterBufferRef *ff_copy_buffer_ref(AVFilterLink *outlink,
 #define FF_INLINK_IDX(link)  ((int)((link)->dstpad - (link)->dst->input_pads))
 #define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads))
 
+int ff_buffersink_read_compat(AVFilterContext *ctx, AVFilterBufferRef **buf);
+
 #endif /* AVFILTER_INTERNAL_H */
diff --git a/libavfilter/sink_buffer.c b/libavfilter/sink_buffer.c
index e34e8e2..9c54d25 100644
--- a/libavfilter/sink_buffer.c
+++ b/libavfilter/sink_buffer.c
@@ -356,3 +356,33 @@ AVFilter avfilter_asink_abuffersink = {
 };
 
 #endif /* CONFIG_ABUFFERSINK_FILTER */
+
+/* Libav compatibility API */
+
+extern AVFilter avfilter_vsink_buffer;
+extern AVFilter avfilter_asink_abuffer;
+
+int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
+{
+    AVFilterBufferRef *tbuf;
+    int ret;
+
+    if (ctx->filter->          inputs[0].start_frame ==
+        avfilter_vsink_buffer. inputs[0].start_frame ||
+        ctx->filter->          inputs[0].filter_samples ==
+        avfilter_asink_abuffer.inputs[0].filter_samples)
+        return ff_buffersink_read_compat(ctx, buf);
+    av_assert0(ctx->filter->                inputs[0].end_frame ==
+               avfilter_vsink_ffbuffersink. inputs[0].end_frame ||
+               ctx->filter->                inputs[0].filter_samples ==
+               avfilter_asink_ffabuffersink.inputs[0].filter_samples);
+
+    ret = av_buffersink_get_buffer_ref(ctx, &tbuf,
+                                       buf ? 0 : AV_BUFFERSINK_FLAG_PEEK);
+    if (!buf)
+        return ret >= 0;
+    if (ret < 0)
+        return ret;
+    *buf = tbuf;
+    return 0;
+}
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list