]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/defaults.c
tools: add ffeval tool
[ffmpeg] / libavfilter / defaults.c
index 79fb38d70fc3ee9421a4489f5db4987b83ce4abf..c083195b4ffb7a345d486c4dc262c52a85ef9774 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/audioconvert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/samplefmt.h"
@@ -56,14 +57,17 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
                 pic->refcount = 1;
                 memcpy(picref->data,     pic->data,     sizeof(picref->data));
                 memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize));
+                pool->refcount++;
                 return picref;
             }
         }
-    } else
+    } else {
         pool = link->pool = av_mallocz(sizeof(AVFilterPool));
+        pool->refcount = 1;
+    }
 
     // align: +2 is needed for swscaler, +16 to be SIMD-friendly
-    if ((i = av_image_alloc(data, linesize, w, h, link->format, 16)) < 0)
+    if ((i = av_image_alloc(data, linesize, w, h, link->format, 32)) < 0)
         return NULL;
 
     picref = avfilter_get_video_buffer_ref_from_arrays(data, linesize,
@@ -76,6 +80,7 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
 
     picref->buf->priv = pool;
     picref->buf->free = NULL;
+    pool->refcount++;
 
     return picref;
 }
@@ -84,16 +89,22 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
                                                      int nb_samples)
 {
     AVFilterBufferRef *samplesref = NULL;
-    int linesize[8];
-    uint8_t *data[8];
-    int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
+    int linesize[8] = {0};
+    uint8_t *data[8] = {0};
+    int ch, nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
+
+    /* right now we don't support more than 8 channels */
+    av_assert0(nb_channels <= 8);
 
     /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */
     if (av_samples_alloc(data, linesize,
-                         nb_channels, nb_samples, link->format,
-                         link->planar, 16) < 0)
+                         nb_channels, nb_samples,
+                         av_get_alt_sample_fmt(link->format, link->planar),
+                         16) < 0)
         return NULL;
 
+    for (ch = 1; link->planar && ch < nb_channels; ch++)
+        linesize[ch] = linesize[0];
     samplesref =
         avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms,
                                                   nb_samples, link->format,