avauddec: fix garbled audio decoding in some cases
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Fri, 25 Jan 2013 19:40:15 +0000 (14:40 -0500)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Sat, 26 Jan 2013 12:23:14 +0000 (12:23 +0000)
Calculate output buffer size based on the number of
samples, channels and bytes per sample. The buffer
size was calculated based on linesize, which may
be larger than what's required.

https://bugzilla.gnome.org/show_bug.cgi?id=690940

ext/libav/gstavauddec.c

index f47c953..0f120c4 100644 (file)
@@ -453,18 +453,20 @@ gst_ffmpegauddec_audio_frame (GstFFMpegAudDec * ffmpegdec,
     } else if (av_sample_fmt_is_planar (ffmpegdec->context->sample_fmt)
         && ffmpegdec->info.channels > 1) {
       gint i, j;
-      gint nsamples, channels;
+      gint nsamples, channels, byte_per_sample;
       GstMapInfo minfo;
 
       channels = ffmpegdec->info.channels;
+      nsamples = frame.nb_samples;
+      byte_per_sample = ffmpegdec->info.finfo->width / 8;
 
+      /* note: linesize[0] might contain padding, allocate only what's needed */
       *outbuf =
           gst_audio_decoder_allocate_output_buffer (GST_AUDIO_DECODER
-          (ffmpegdec), frame.linesize[0] * channels);
+          (ffmpegdec), nsamples * byte_per_sample * channels);
 
       gst_buffer_map (*outbuf, &minfo, GST_MAP_WRITE);
 
-      nsamples = frame.nb_samples;
       switch (ffmpegdec->info.finfo->width) {
         case 8:{
           guint8 *odata = minfo.data;