]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/avfilter.c
get_buffers: Check that pix_fmt is not NONE.
[ffmpeg] / libavfilter / avfilter.c
index 5327cf9b69c2f14fbe782c73e6b8ed24d246df98..706f7e26944d6d912c7d21f0881fbab54085531a 100644 (file)
@@ -31,6 +31,7 @@
 #include "internal.h"
 
 unsigned avfilter_version(void) {
+    av_assert0(LIBAVFILTER_VERSION_MICRO >= 100);
     return LIBAVFILTER_VERSION_INT;
 }
 
@@ -80,12 +81,42 @@ AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
     return ret;
 }
 
+static void free_pool(AVFilterPool *pool)
+{
+    int i;
+
+    av_assert0(pool->refcount > 0);
+
+    for (i = 0; i < POOL_SIZE; i++) {
+        if (pool->pic[i]) {
+            AVFilterBufferRef *picref = pool->pic[i];
+            /* free buffer: picrefs stored in the pool are not
+             * supposed to contain a free callback */
+            av_assert0(!picref->buf->refcount);
+            av_freep(&picref->buf->data[0]);
+            av_freep(&picref->buf);
+
+            av_freep(&picref->audio);
+            av_freep(&picref->video);
+            av_freep(&pool->pic[i]);
+            pool->count--;
+        }
+    }
+    pool->draining = 1;
+
+    if (!--pool->refcount) {
+        av_assert0(!pool->count);
+        av_free(pool);
+    }
+}
+
 static void store_in_pool(AVFilterBufferRef *ref)
 {
     int i;
     AVFilterPool *pool= ref->buf->priv;
 
     av_assert0(ref->buf->data[0]);
+    av_assert0(pool->refcount>0);
 
     if (pool->count == POOL_SIZE) {
         AVFilterBufferRef *ref1 = pool->pic[0];
@@ -106,12 +137,17 @@ static void store_in_pool(AVFilterBufferRef *ref)
             break;
         }
     }
+    if (pool->draining) {
+        free_pool(pool);
+    } else
+        --pool->refcount;
 }
 
 void avfilter_unref_buffer(AVFilterBufferRef *ref)
 {
     if (!ref)
         return;
+    av_assert0(ref->buf->refcount > 0);
     if (!(--ref->buf->refcount)) {
         if (!ref->buf->free) {
             store_in_pool(ref);
@@ -180,24 +216,9 @@ void avfilter_link_free(AVFilterLink **link)
     if (!*link)
         return;
 
-    if ((*link)->pool) {
-        int i;
-        for (i = 0; i < POOL_SIZE; i++) {
-            if ((*link)->pool->pic[i]) {
-                AVFilterBufferRef *picref = (*link)->pool->pic[i];
-                /* free buffer: picrefs stored in the pool are not
-                 * supposed to contain a free callback */
-                av_freep(&picref->buf->data[0]);
-                av_freep(&picref->buf);
-
-                av_freep(&picref->audio);
-                av_freep(&picref->video);
-                av_freep(&(*link)->pool->pic[i]);
-            }
-        }
-        (*link)->pool->count = 0;
-//        av_freep(&(*link)->pool);
-    }
+    if ((*link)->pool)
+        free_pool((*link)->pool);
+
     av_freep(link);
 }
 
@@ -369,7 +390,7 @@ static void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
 {
     if (link->type == AVMEDIA_TYPE_VIDEO) {
         av_dlog(ctx,
-                "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",
+                "link[%p s:%dx%d fmt:%s %s->%s]%s",
                 link, link->w, link->h,
                 av_pix_fmt_descriptors[link->format].name,
                 link->src ? link->src->filter->name : "",
@@ -380,7 +401,7 @@ static void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
         av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
 
         av_dlog(ctx,
-                "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s",
+                "link[%p r:%d cl:%s fmt:%s %s->%s]%s",
                 link, (int)link->sample_rate, buf,
                 av_get_sample_fmt_name(link->format),
                 link->src ? link->src->filter->name : "",
@@ -677,7 +698,7 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
         link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
 
         /* Copy actual data into new samples buffer */
-        for (i = 0; samplesref->data[i]; i++)
+        for (i = 0; samplesref->data[i] && i < 8; i++)
             memcpy(link->cur_buf->data[i], samplesref->data[i], samplesref->linesize[0]);
 
         avfilter_unref_buffer(samplesref);