[FFmpeg-cvslog] lavfi: fix avfilter_default_get_audio_buffer() after changes in av_samples_alloc()

Stefano Sabatini git at videolan.org
Tue Dec 27 15:28:38 CET 2011


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sun Dec 25 23:35:06 2011 +0100| [e9af732a1a4c28f81959f19d434c9be609cff22a] | committer: Stefano Sabatini

lavfi: fix avfilter_default_get_audio_buffer() after changes in av_samples_alloc()

av_samples_alloc() behavior changed in bbb46f3ec, resulting in random
data filling the data[] and linesize[] arrays of the returned
AVFilterBufferRef, which was resulting in wrong behavior in case of code
checking on data[i] nullity.

In particular fixes crash in avfilter_filter_samples():
        for (i = 0; samplesref->data[i]; i++)
            memcpy(link->cur_buf->data[i], samplesref->data[i], samplesref->linesize[0]);

and correctly fills the linesize[] array for planar data.

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

 libavfilter/defaults.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
index 1b756a4..5f18168 100644
--- a/libavfilter/defaults.c
+++ b/libavfilter/defaults.c
@@ -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"
@@ -84,16 +85,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,
+                         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,



More information about the ffmpeg-cvslog mailing list