[FFmpeg-devel] [PATCH 3/6] src_buffer: introduce av_src_buffer_add_ref().

Nicolas George nicolas.george at normalesup.org
Fri Apr 27 21:48:07 CEST 2012


This function merges the features of
av_vsrc_buffer_add_video_buffer_ref() and
av_buffersrc_buffer().

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/Makefile     |    2 +-
 libavfilter/src_buffer.c |   43 ++++++++++++++++---------------------
 libavfilter/src_buffer.h |   52 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 25 deletions(-)
 create mode 100644 libavfilter/src_buffer.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 95bcc5d..b21ea16 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -12,7 +12,7 @@ FFLIBS-$(CONFIG_REMOVELOGO_FILTER)           += swscale avformat avcodec
 FFLIBS-$(CONFIG_SCALE_FILTER)                += swscale
 FFLIBS-$(CONFIG_MP_FILTER)                   += avcodec postproc
 
-HEADERS = asrc_abuffer.h avcodec.h avfilter.h avfiltergraph.h buffersink.h version.h vsrc_buffer.h
+HEADERS = asrc_abuffer.h avcodec.h avfilter.h avfiltergraph.h buffersink.h src_buffer.h version.h vsrc_buffer.h
 
 OBJS = allfilters.o                                                     \
        avfilter.o                                                       \
diff --git a/libavfilter/src_buffer.c b/libavfilter/src_buffer.c
index e306034..d578a77 100644
--- a/libavfilter/src_buffer.c
+++ b/libavfilter/src_buffer.c
@@ -29,6 +29,7 @@
 #include "internal.h"
 #include "avcodec.h"
 #include "buffersrc.h"
+#include "src_buffer.h"
 #include "vsrc_buffer.h"
 #include "asrc_abuffer.h"
 #include "libavutil/audioconvert.h"
@@ -69,8 +70,8 @@ typedef struct {
         return AVERROR(EINVAL);\
     }
 
-int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
-                                        AVFilterBufferRef *picref, int flags)
+int av_src_buffer_add_ref(AVFilterContext *buffer_filter,
+                          AVFilterBufferRef *picref, int flags)
 {
     BufferSourceContext *c = buffer_filter->priv;
     AVFilterLink *outlink = buffer_filter->outputs[0];
@@ -88,6 +89,11 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
                                          sizeof(buf))) < 0)
         return ret;
 
+    if (flags & AV_SRC_BUFFER_FLAG_DIRECT) {
+        buf = picref;
+    } else {
+
+        /* TODO reindent */
     if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) {
         AVFilterContext *scale = buffer_filter->outputs[0]->dst;
         AVFilterLink *link;
@@ -140,8 +146,11 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
                   picref->format, picref->video->w, picref->video->h);
     avfilter_copy_buffer_ref_props(buf, picref);
 
+    }
+
     if ((ret = av_fifo_generic_write(c->fifo, &buf, sizeof(buf), NULL)) < 0) {
-        avfilter_unref_buffer(buf);
+        if (buf != picref)
+            avfilter_unref_buffer(buf);
         return ret;
     }
     c->nb_failed_requests = 0;
@@ -149,29 +158,15 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
     return 0;
 }
 
-int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
+int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
+                                        AVFilterBufferRef *picref, int flags)
 {
-    BufferSourceContext *c = s->priv;
-    int ret;
-
-    if (!buf) {
-        c->eof = 1;
-        return 0;
-    } else if (c->eof)
-        return AVERROR(EINVAL);
-
-    if (!av_fifo_space(c->fifo) &&
-        (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
-                                         sizeof(buf))) < 0)
-        return ret;
-
-//     CHECK_PARAM_CHANGE(s, c, buf->video->w, buf->video->h, buf->format);
-
-    if ((ret = av_fifo_generic_write(c->fifo, &buf, sizeof(buf), NULL)) < 0)
-        return ret;
-    c->nb_failed_requests = 0;
+    return av_src_buffer_add_ref(buffer_filter, picref, 0);
+}
 
-    return 0;
+int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
+{
+    return av_src_buffer_add_ref(s, buf, AV_SRC_BUFFER_FLAG_DIRECT);
 }
 
 #if CONFIG_AVCODEC
diff --git a/libavfilter/src_buffer.h b/libavfilter/src_buffer.h
new file mode 100644
index 0000000..252afab
--- /dev/null
+++ b/libavfilter/src_buffer.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2012 Mina Nagy Zaki
+ *
+ * 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
+ */
+
+#ifndef AVFILTER_SRC_BUFFER_H
+#define AVFILTER_SRC_BUFFER_H
+
+/**
+ * @file
+ * memory buffer source API for video and audio
+ */
+
+#include "avfilter.h"
+
+enum {
+
+    /**
+     * Do not copy the buffer reference and do not check for format changes.
+     */
+    AV_SRC_BUFFER_FLAG_DIRECT = 1,
+
+};
+
+/**
+ * Add video buffer data in picref to buffer_src.
+ *
+ * @param buffer_src  pointer to a buffer source context
+ * @param picref      a buffer reference, or NULL to mark EOF
+ * @param flags       a combination of AV_SRC_BUFFER_FLAG_*
+ * @return            >= 0 in case of success, a negative AVERROR code
+ *                    in case of failure
+ */
+int av_src_buffer_add_ref(AVFilterContext *buffer_src,
+                          AVFilterBufferRef *picref, int flags);
+
+#endif /* AVFILTER_SRC_BUFFER_H */
-- 
1.7.2.5



More information about the ffmpeg-devel mailing list