]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/truemotion2.c
mpeg4videodec: move mpeg4-specific bug workaround variables from MpegEncContext to...
[ffmpeg] / libavcodec / truemotion2.c
index a4d01cb0c5159ff9905d3009fdc730aa6101d296..e41d7a39e3cf0953e99ecfd42c52eab01145de24 100644 (file)
@@ -58,7 +58,7 @@ enum TM2_BLOCKS {
 
 typedef struct TM2Context {
     AVCodecContext *avctx;
-    AVFrame pic;
+    AVFrame *pic;
 
     GetBitContext gb;
     DSPContext dsp;
@@ -838,7 +838,7 @@ static int decode_frame(AVCodecContext *avctx,
     TM2Context * const l = avctx->priv_data;
     const uint8_t *buf   = avpkt->data;
     int buf_size         = avpkt->size & ~3;
-    AVFrame * const p    = &l->pic;
+    AVFrame * const p    = l->pic;
     int offset           = TM2_HEADER_SIZE;
     int i, t, ret;
     uint8_t *swbuf;
@@ -883,7 +883,7 @@ static int decode_frame(AVCodecContext *avctx,
 
     l->cur = !l->cur;
     *got_frame      = 1;
-    ret = av_frame_ref(data, &l->pic);
+    ret = av_frame_ref(data, l->pic);
     av_free(swbuf);
 
     return (ret < 0) ? ret : buf_size;
@@ -900,9 +900,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
     }
 
     l->avctx       = avctx;
-    avcodec_get_frame_defaults(&l->pic);
     avctx->pix_fmt = AV_PIX_FMT_BGR24;
 
+    l->pic = av_frame_alloc();
+    if (!l->pic)
+        return AVERROR(ENOMEM);
+
     ff_dsputil_init(&l->dsp, avctx);
 
     l->last  = av_malloc(4 * sizeof(*l->last)  * (w >> 2));
@@ -929,14 +932,14 @@ static av_cold int decode_init(AVCodecContext *avctx)
     if (!l->Y1_base || !l->Y2_base || !l->U1_base ||
         !l->V1_base || !l->U2_base || !l->V2_base ||
         !l->last    || !l->clast) {
-        av_freep(l->Y1_base);
-        av_freep(l->Y2_base);
-        av_freep(l->U1_base);
-        av_freep(l->U2_base);
-        av_freep(l->V1_base);
-        av_freep(l->V2_base);
-        av_freep(l->last);
-        av_freep(l->clast);
+        av_freep(&l->Y1_base);
+        av_freep(&l->Y2_base);
+        av_freep(&l->U1_base);
+        av_freep(&l->U2_base);
+        av_freep(&l->V1_base);
+        av_freep(&l->V2_base);
+        av_freep(&l->last);
+        av_freep(&l->clast);
         return AVERROR(ENOMEM);
     }
     l->Y1 = l->Y1_base + l->y_stride  * 4 + 4;
@@ -952,7 +955,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
 static av_cold int decode_end(AVCodecContext *avctx)
 {
     TM2Context * const l = avctx->priv_data;
-    AVFrame *pic = &l->pic;
     int i;
 
     av_free(l->last);
@@ -968,13 +970,14 @@ static av_cold int decode_end(AVCodecContext *avctx)
         av_free(l->V2_base);
     }
 
-    av_frame_unref(pic);
+    av_frame_free(&l->pic);
 
     return 0;
 }
 
 AVCodec ff_truemotion2_decoder = {
     .name           = "truemotion2",
+    .long_name      = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_TRUEMOTION2,
     .priv_data_size = sizeof(TM2Context),
@@ -982,5 +985,4 @@ AVCodec ff_truemotion2_decoder = {
     .close          = decode_end,
     .decode         = decode_frame,
     .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"),
 };