[FFmpeg-cvslog] src_buffer: introduce av_buffersrc_add_ref().

Nicolas George git at videolan.org
Thu May 3 19:57:52 CEST 2012


ffmpeg | branch: master | Nicolas George <nicolas.george at normalesup.org> | Fri Apr 27 20:02:52 2012 +0200| [3985ec0ee68564c213cb0862c8854899690f4321] | committer: Nicolas George

src_buffer: introduce av_buffersrc_add_ref().

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

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3985ec0ee68564c213cb0862c8854899690f4321
---

 libavfilter/buffersrc.h  |   26 ++++++++++++++++++++++++++
 libavfilter/src_buffer.c |   44 ++++++++++++++++++++------------------------
 2 files changed, 46 insertions(+), 24 deletions(-)

diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
index 918a54f..32ef29b 100644
--- a/libavfilter/buffersrc.h
+++ b/libavfilter/buffersrc.h
@@ -27,6 +27,32 @@
 
 #include "avfilter.h"
 
+enum {
+
+    /**
+     * Do not check for format changes.
+     */
+    AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT = 1,
+
+    /**
+     * Do not copy buffer data.
+     */
+    AV_BUFFERSRC_FLAG_NO_COPY = 2,
+
+};
+
+/**
+ * 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_BUFFERSRC_FLAG_*
+ * @return            >= 0 in case of success, a negative AVERROR code
+ *                    in case of failure
+ */
+int av_buffersrc_add_ref(AVFilterContext *buffer_src,
+                         AVFilterBufferRef *picref, int flags);
+
 /**
  * Add a buffer to the filtergraph s.
  *
diff --git a/libavfilter/src_buffer.c b/libavfilter/src_buffer.c
index 7873c0a..85d03b0 100644
--- a/libavfilter/src_buffer.c
+++ b/libavfilter/src_buffer.c
@@ -69,8 +69,8 @@ typedef struct {
         return AVERROR(EINVAL);\
     }
 
-int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
-                                        AVFilterBufferRef *picref, int flags)
+int av_buffersrc_add_ref(AVFilterContext *buffer_filter,
+                         AVFilterBufferRef *picref, int flags)
 {
     BufferSourceContext *c = buffer_filter->priv;
     AVFilterLink *outlink = buffer_filter->outputs[0];
@@ -88,6 +88,8 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
                                          sizeof(buf))) < 0)
         return ret;
 
+    if (!(flags & AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT)) {
+        /* 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;
@@ -132,7 +134,11 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
         if ((ret =  link->srcpad->config_props(link)) < 0)
             return ret;
     }
+    }
 
+    if (flags & AV_BUFFERSRC_FLAG_NO_COPY) {
+        buf = picref;
+    } else {
     buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
                                     picref->video->w, picref->video->h);
     av_image_copy(buf->data, buf->linesize,
@@ -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,16 @@ 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_buffersrc_add_ref(buffer_filter, picref, 0);
+}
 
-    return 0;
+int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
+{
+    return av_buffersrc_add_ref(s, buf, AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT |
+                                        AV_BUFFERSRC_FLAG_NO_COPY);
 }
 
 #if CONFIG_AVCODEC



More information about the ffmpeg-cvslog mailing list