]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/qpeg.c
Merge commit '2d2a92f72199823a92e4e226c32e42a27ec801c0'
[ffmpeg] / libavcodec / qpeg.c
index edde937b15ac44cdb79231c5c9dd706330968416..da2d3b9d16eec703bb099bfe2fbde69756694899 100644 (file)
@@ -30,7 +30,7 @@
 
 typedef struct QpegContext{
     AVCodecContext *avctx;
-    AVFrame pic, ref;
+    AVFrame *pic, *ref;
     uint32_t pal[256];
     GetByteContext buffer;
 } QpegContext;
@@ -255,8 +255,8 @@ static int decode_frame(AVCodecContext *avctx,
 {
     uint8_t ctable[128];
     QpegContext * const a = avctx->priv_data;
-    AVFrame *  p = &a->pic;
-    AVFrame * ref= &a->ref;
+    AVFrame * const p = a->pic;
+    AVFrame * const ref = a->ref;
     uint8_t* outdata;
     int delta, ret;
     const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
@@ -273,26 +273,26 @@ static int decode_frame(AVCodecContext *avctx,
 
     if ((ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF)) < 0)
         return ret;
-    outdata = a->pic.data[0];
+    outdata = p->data[0];
     bytestream2_skip(&a->buffer, 4);
     bytestream2_get_buffer(&a->buffer, ctable, 128);
     bytestream2_skip(&a->buffer, 1);
 
     delta = bytestream2_get_byte(&a->buffer);
     if(delta == 0x10) {
-        qpeg_decode_intra(a, outdata, a->pic.linesize[0], avctx->width, avctx->height);
+        qpeg_decode_intra(a, outdata, p->linesize[0], avctx->width, avctx->height);
     } else {
-        qpeg_decode_inter(a, outdata, a->pic.linesize[0], avctx->width, avctx->height, delta, ctable, a->ref.data[0]);
+        qpeg_decode_inter(a, outdata, p->linesize[0], avctx->width, avctx->height, delta, ctable, ref->data[0]);
     }
 
     /* make the palette available on the way out */
     if (pal) {
-        a->pic.palette_has_changed = 1;
+        p->palette_has_changed = 1;
         memcpy(a->pal, pal, AVPALETTE_SIZE);
     }
-    memcpy(a->pic.data[1], a->pal, AVPALETTE_SIZE);
+    memcpy(p->data[1], a->pal, AVPALETTE_SIZE);
 
-    if ((ret = av_frame_ref(data, &a->pic)) < 0)
+    if ((ret = av_frame_ref(data, p)) < 0)
         return ret;
 
     *got_frame      = 1;
@@ -312,6 +312,16 @@ static void decode_flush(AVCodecContext *avctx){
         a->pal[i] = 0xFFU<<24 | AV_RL32(pal_src+4*i);
 }
 
+static av_cold int decode_end(AVCodecContext *avctx)
+{
+    QpegContext * const a = avctx->priv_data;
+
+    av_frame_free(&a->pic);
+    av_frame_free(&a->ref);
+
+    return 0;
+}
+
 static av_cold int decode_init(AVCodecContext *avctx){
     QpegContext * const a = avctx->priv_data;
 
@@ -322,18 +332,12 @@ static av_cold int decode_init(AVCodecContext *avctx){
 
     decode_flush(avctx);
 
-    avcodec_get_frame_defaults(&a->pic);
-
-    return 0;
-}
-
-static av_cold int decode_end(AVCodecContext *avctx){
-    QpegContext * const a = avctx->priv_data;
-    AVFrame * const p = &a->pic;
-    AVFrame * const ref= &a->ref;
-
-    av_frame_unref(p);
-    av_frame_unref(ref);
+    a->pic = av_frame_alloc();
+    a->ref = av_frame_alloc();
+    if (!a->pic || !a->ref) {
+        decode_end(avctx);
+        return AVERROR(ENOMEM);
+    }
 
     return 0;
 }