[FFmpeg-cvslog] r25827 - in trunk: doc/APIchanges libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/defaults.c

stefano subversion
Thu Nov 25 21:50:28 CET 2010


Author: stefano
Date: Thu Nov 25 21:50:28 2010
New Revision: 25827

Log:
Implement avfilter_get_video_buffer_ref_from_arrays().

Modified:
   trunk/doc/APIchanges
   trunk/libavfilter/avfilter.c
   trunk/libavfilter/avfilter.h
   trunk/libavfilter/defaults.c

Modified: trunk/doc/APIchanges
==============================================================================
--- trunk/doc/APIchanges	Thu Nov 25 21:50:23 2010	(r25826)
+++ trunk/doc/APIchanges	Thu Nov 25 21:50:28 2010	(r25827)
@@ -12,6 +12,9 @@ libavutil:   2009-03-08
 
 
 API changes, most recent first:
+2010-11-22 - r25826 - lavfi 1.65.0 - avfilter_get_video_buffer_ref_from_arrays()
+  Add function avfilter_get_video_buffer_ref_from_arrays() in
+  avfilter.h.
 
 2010-11-21 - r25787 - lavcore 0.14.0 - audioconvert.h
   Add a public audio channel API in audioconvert.h, and deprecate the

Modified: trunk/libavfilter/avfilter.c
==============================================================================
--- trunk/libavfilter/avfilter.c	Thu Nov 25 21:50:23 2010	(r25826)
+++ trunk/libavfilter/avfilter.c	Thu Nov 25 21:50:28 2010	(r25827)
@@ -267,6 +267,46 @@ AVFilterBufferRef *avfilter_get_video_bu
     return ret;
 }
 
+AVFilterBufferRef *
+avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
+                                          int w, int h, enum PixelFormat format)
+{
+    AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer));
+    AVFilterBufferRef *picref = av_mallocz(sizeof(AVFilterBufferRef));
+
+    if (!pic || !picref)
+        goto fail;
+
+    picref->buf = pic;
+    picref->buf->free = ff_avfilter_default_free_buffer;
+    if (!(picref->video = av_mallocz(sizeof(AVFilterBufferRefVideoProps))))
+        goto fail;
+
+    picref->video->w = w;
+    picref->video->h = h;
+
+    /* make sure the buffer gets read permission or it's useless for output */
+    picref->perms = perms | AV_PERM_READ;
+
+    pic->refcount = 1;
+    picref->type = AVMEDIA_TYPE_VIDEO;
+    picref->format = format;
+
+    memcpy(pic->data,        data,          sizeof(pic->data));
+    memcpy(pic->linesize,    linesize,      sizeof(pic->linesize));
+    memcpy(picref->data,     pic->data,     sizeof(picref->data));
+    memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize));
+
+    return picref;
+
+fail:
+    if (picref && picref->video)
+        av_free(picref->video);
+    av_free(picref);
+    av_free(pic);
+    return NULL;
+}
+
 AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
                                              enum AVSampleFormat sample_fmt, int size,
                                              int64_t channel_layout, int planar)

Modified: trunk/libavfilter/avfilter.h
==============================================================================
--- trunk/libavfilter/avfilter.h	Thu Nov 25 21:50:23 2010	(r25826)
+++ trunk/libavfilter/avfilter.h	Thu Nov 25 21:50:28 2010	(r25827)
@@ -25,7 +25,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  1
-#define LIBAVFILTER_VERSION_MINOR 64
+#define LIBAVFILTER_VERSION_MINOR 65
 #define LIBAVFILTER_VERSION_MICRO  0
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
@@ -649,6 +649,21 @@ AVFilterBufferRef *avfilter_get_video_bu
                                           int w, int h);
 
 /**
+ * Create a buffer reference wrapped around an already allocated image
+ * buffer.
+ *
+ * @param data pointers to the planes of the image to reference
+ * @param linesize linesizes for the planes of the image to reference
+ * @param perms the required access permissions
+ * @param w the width of the image specified by the data and linesize arrays
+ * @param h the height of the image specified by the data and linesize arrays
+ * @param format the pixel format of the image specified by the data and linesize arrays
+ */
+AVFilterBufferRef *
+avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
+                                          int w, int h, enum PixelFormat format);
+
+/**
  * Request an audio samples buffer with a specific set of permissions.
  *
  * @param link           the output link to the filter from which the buffer will

Modified: trunk/libavfilter/defaults.c
==============================================================================
--- trunk/libavfilter/defaults.c	Thu Nov 25 21:50:23 2010	(r25826)
+++ trunk/libavfilter/defaults.c	Thu Nov 25 21:50:28 2010	(r25827)
@@ -37,49 +37,30 @@ void ff_avfilter_default_free_buffer(AVF
  * alloc & free cycle currently implemented. */
 AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
 {
-    AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer));
-    AVFilterBufferRef *ref = NULL;
-    int i, tempsize;
     char *buf = NULL;
+    int linesize[4], i, tempsize;
+    uint8_t *data[4];
+    AVFilterBufferRef *picref = NULL;
 
-    if (!pic || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))
-        goto fail;
-
-    ref->buf         = pic;
-    ref->video       = av_mallocz(sizeof(AVFilterBufferRefVideoProps));
-    ref->video->w    = w;
-    ref->video->h    = h;
-
-    /* make sure the buffer gets read permission or it's useless for output */
-    ref->perms = perms | AV_PERM_READ;
-
-    pic->refcount = 1;
-    ref->format   = link->format;
-    pic->free     = ff_avfilter_default_free_buffer;
-    av_image_fill_linesizes(pic->linesize, ref->format, ref->video->w);
-
+    av_image_fill_linesizes(linesize, link->format, w);
     for (i = 0; i < 4; i++)
-        pic->linesize[i] = FFALIGN(pic->linesize[i], 16);
-
-    tempsize = av_image_fill_pointers(pic->data, ref->format, ref->video->h, NULL, pic->linesize);
+        linesize[i] = FFALIGN(linesize[i], 16);
+    tempsize = av_image_fill_pointers(data, link->format, h, NULL, linesize);
     buf = av_malloc(tempsize + 16); // +2 is needed for swscaler, +16 to be
                                     // SIMD-friendly
     if (!buf)
-        goto fail;
-    av_image_fill_pointers(pic->data, ref->format, ref->video->h, buf, pic->linesize);
+        return NULL;
 
-    memcpy(ref->data,     pic->data,     sizeof(ref->data));
-    memcpy(ref->linesize, pic->linesize, sizeof(ref->linesize));
+    av_image_fill_pointers(data, link->format, h, buf, linesize);
 
-    return ref;
+    picref = avfilter_get_video_buffer_ref_from_arrays(data, linesize,
+                                                       perms, w, h, link->format);
+    if (!picref) {
+        av_free(buf);
+        return NULL;
+    }
 
-fail:
-    av_free(buf);
-    if (ref && ref->video)
-        av_free(ref->video);
-    av_free(ref);
-    av_free(pic);
-    return NULL;
+    return picref;
 }
 
 AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,



More information about the ffmpeg-cvslog mailing list