]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mss4.c
error_resilience: initialize prev_* variables
[ffmpeg] / libavcodec / mss4.c
index 1c850bc1c36a9d1a911d2cd9c1b1f71825de5502..9198acc6a7405a6a75f0049f783904979c917305 100644 (file)
@@ -27,8 +27,8 @@
 
 #include "avcodec.h"
 #include "bytestream.h"
-#include "dsputil.h"
 #include "get_bits.h"
+#include "internal.h"
 #include "mss34dsp.h"
 #include "unary.h"
 
@@ -125,8 +125,7 @@ static const uint8_t mss4_vec_entry_vlc_syms[2][9] = {
 #define MAX_ENTRIES  162
 
 typedef struct MSS4Context {
-    AVFrame    pic;
-    DSPContext dsp;
+    AVFrame   *pic;
 
     VLC        dc_vlc[2], ac_vlc[2];
     VLC        vec_entry_vlc[2];
@@ -297,10 +296,10 @@ static int mss4_decode_dct_block(MSS4Context *c, GetBitContext *gb,
                 return ret;
             c->prev_dc[0][mb_x * 2 + i] = c->dc_cache[j][LEFT];
 
-            ff_mss34_dct_put(out + xpos * 8, c->pic.linesize[0],
+            ff_mss34_dct_put(out + xpos * 8, c->pic->linesize[0],
                              c->block);
         }
-        out += 8 * c->pic.linesize[0];
+        out += 8 * c->pic->linesize[0];
     }
 
     for (i = 1; i < 3; i++) {
@@ -320,7 +319,7 @@ static int mss4_decode_dct_block(MSS4Context *c, GetBitContext *gb,
         for (j = 0; j < 16; j++) {
             for (k = 0; k < 8; k++)
                 AV_WN16A(out + k * 2, c->imgbuf[i][k + (j & ~1) * 4] * 0x101);
-            out += c->pic.linesize[i];
+            out += c->pic->linesize[i];
         }
     }
 
@@ -481,7 +480,7 @@ static int mss4_decode_image_block(MSS4Context *ctx, GetBitContext *gb,
 
     for (i = 0; i < 3; i++)
         for (j = 0; j < 16; j++)
-            memcpy(picdst[i] + mb_x * 16 + j * ctx->pic.linesize[i],
+            memcpy(picdst[i] + mb_x * 16 + j * ctx->pic->linesize[i],
                    ctx->imgbuf[i] + j * 16, 16);
 
     return 0;
@@ -506,7 +505,7 @@ static inline void mss4_update_dc_cache(MSS4Context *c, int mb_x)
     }
 }
 
-static int mss4_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+static int mss4_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
                              AVPacket *avpkt)
 {
     const uint8_t *buf = avpkt->data;
@@ -554,20 +553,17 @@ static int mss4_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         return AVERROR_INVALIDDATA;
     }
 
-    c->pic.reference    = 3;
-    c->pic.buffer_hints = FF_BUFFER_HINTS_VALID    |
-                          FF_BUFFER_HINTS_PRESERVE |
-                          FF_BUFFER_HINTS_REUSABLE;
-    if ((ret = avctx->reget_buffer(avctx, &c->pic)) < 0) {
+    if ((ret = ff_reget_buffer(avctx, c->pic)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
         return ret;
     }
-    c->pic.key_frame = (frame_type == INTRA_FRAME);
-    c->pic.pict_type = (frame_type == INTRA_FRAME) ? AV_PICTURE_TYPE_I
+    c->pic->key_frame = (frame_type == INTRA_FRAME);
+    c->pic->pict_type = (frame_type == INTRA_FRAME) ? AV_PICTURE_TYPE_I
                                                    : AV_PICTURE_TYPE_P;
     if (frame_type == SKIP_FRAME) {
-        *data_size = sizeof(AVFrame);
-        *(AVFrame*)data = c->pic;
+        *got_frame      = 1;
+        if ((ret = av_frame_ref(data, c->pic)) < 0)
+            return ret;
 
         return buf_size;
     }
@@ -582,9 +578,9 @@ static int mss4_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 
     mb_width  = FFALIGN(width,  16) >> 4;
     mb_height = FFALIGN(height, 16) >> 4;
-    dst[0] = c->pic.data[0];
-    dst[1] = c->pic.data[1];
-    dst[2] = c->pic.data[2];
+    dst[0] = c->pic->data[0];
+    dst[1] = c->pic->data[1];
+    dst[2] = c->pic->data[2];
 
     memset(c->prev_vec, 0, sizeof(c->prev_vec));
     for (y = 0; y < mb_height; y++) {
@@ -618,17 +614,32 @@ static int mss4_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
             if (blk_type != DCT_BLOCK)
                 mss4_update_dc_cache(c, x);
         }
-        dst[0] += c->pic.linesize[0] * 16;
-        dst[1] += c->pic.linesize[1] * 16;
-        dst[2] += c->pic.linesize[2] * 16;
+        dst[0] += c->pic->linesize[0] * 16;
+        dst[1] += c->pic->linesize[1] * 16;
+        dst[2] += c->pic->linesize[2] * 16;
     }
 
-    *data_size = sizeof(AVFrame);
-    *(AVFrame*)data = c->pic;
+    if ((ret = av_frame_ref(data, c->pic)) < 0)
+        return ret;
+
+    *got_frame      = 1;
 
     return buf_size;
 }
 
+static av_cold int mss4_decode_end(AVCodecContext *avctx)
+{
+    MSS4Context * const c = avctx->priv_data;
+    int i;
+
+    av_frame_free(&c->pic);
+    for (i = 0; i < 3; i++)
+        av_freep(&c->prev_dc[i]);
+    mss4_free_vlcs(c);
+
+    return 0;
+}
+
 static av_cold int mss4_decode_init(AVCodecContext *avctx)
 {
     MSS4Context * const c = avctx->priv_data;
@@ -649,28 +660,20 @@ static av_cold int mss4_decode_init(AVCodecContext *avctx)
         }
     }
 
-    avctx->pix_fmt     = AV_PIX_FMT_YUV444P;
-    avctx->coded_frame = &c->pic;
-
-    return 0;
-}
-
-static av_cold int mss4_decode_end(AVCodecContext *avctx)
-{
-    MSS4Context * const c = avctx->priv_data;
-    int i;
+    c->pic = av_frame_alloc();
+    if (!c->pic) {
+        mss4_decode_end(avctx);
+        return AVERROR(ENOMEM);
+    }
 
-    if (c->pic.data[0])
-        avctx->release_buffer(avctx, &c->pic);
-    for (i = 0; i < 3; i++)
-        av_freep(&c->prev_dc[i]);
-    mss4_free_vlcs(c);
+    avctx->pix_fmt     = AV_PIX_FMT_YUV444P;
 
     return 0;
 }
 
 AVCodec ff_mts2_decoder = {
     .name           = "mts2",
+    .long_name      = NULL_IF_CONFIG_SMALL("MS Expression Encoder Screen"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_MTS2,
     .priv_data_size = sizeof(MSS4Context),
@@ -678,5 +681,4 @@ AVCodec ff_mts2_decoder = {
     .close          = mss4_decode_end,
     .decode         = mss4_decode_frame,
     .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("MS Expression Encoder Screen"),
 };