mmal: Fix AVBufferRef usage
authorwm4 <nfxjfg at googlemail.com>
Thu, 24 Sep 2015 06:49:41 +0000 (08:49 +0200)
committerLuca Barbato <lu_zero@gentoo.org>
Thu, 24 Sep 2015 08:34:46 +0000 (10:34 +0200)
AVBufferRef.data and AVPacket.data don't need to have the same value.
AVPacket could point anywhere into the buffer. Likewise, the sizes
don't need to be the same.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
libavcodec/mmaldec.c

index fea3fc4..ae9d749 100644 (file)
@@ -433,17 +433,20 @@ static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt,
     if (avpkt->size) {
         if (avpkt->buf) {
             buf = av_buffer_ref(avpkt->buf);
+            size = avpkt->size;
+            data = avpkt->data;
         } else {
             buf = av_buffer_alloc(avpkt->size);
-            if (buf)
+            if (buf) {
                 memcpy(buf->data, avpkt->data, avpkt->size);
+                size = buf->size;
+                data = buf->data;
+            }
         }
         if (!buf) {
             ret = AVERROR(ENOMEM);
             goto done;
         }
-        size = buf->size;
-        data = buf->data;
         if (!is_extradata)
             ctx->packets_sent++;
     } else {