]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mss1.c
dds: Fix enum declaration
[ffmpeg] / libavcodec / mss1.c
index ada479eee7810df9ba9c27e886dc1b70cf690f1e..a67a942ac26aff9889edb43c390b54007ad90758 100644 (file)
  */
 
 #include "avcodec.h"
+#include "internal.h"
 #include "mss12.h"
 
 typedef struct MSS1Context {
     MSS12Context   ctx;
-    AVFrame        pic;
-    SliceContext   sc[2];
+    AVFrame       *pic;
+    SliceContext   sc;
 } MSS1Context;
 
 static void arith_normalise(ArithCoder *c)
@@ -89,7 +90,7 @@ static int arith_get_number(ArithCoder *c, int mod_val)
     return val;
 }
 
-static int arith_get_prob(ArithCoder *c, int *probs)
+static int arith_get_prob(ArithCoder *c, int16_t *probs)
 {
     int range = c->high - c->low + 1;
     int val   = ((c->value - c->low + 1) * probs[0] - 1) / range;
@@ -135,7 +136,7 @@ static int decode_pal(MSS12Context *ctx, ArithCoder *acoder)
     return !!ncol;
 }
 
-static int mss1_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+static int mss1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
                              AVPacket *avpkt)
 {
     const uint8_t *buf = avpkt->data;
@@ -150,37 +151,37 @@ static int mss1_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     init_get_bits(&gb, buf, buf_size * 8);
     arith_init(&acoder, &gb);
 
-    ctx->pic.reference    = 3;
-    ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
-                            FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
-    if ((ret = avctx->reget_buffer(avctx, &ctx->pic)) < 0) {
+    if ((ret = ff_reget_buffer(avctx, ctx->pic)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
         return ret;
     }
 
-    c->pal_pic    =  ctx->pic.data[0] + ctx->pic.linesize[0] * (avctx->height - 1);
-    c->pal_stride = -ctx->pic.linesize[0];
+    c->pal_pic    =  ctx->pic->data[0] + ctx->pic->linesize[0] * (avctx->height - 1);
+    c->pal_stride = -ctx->pic->linesize[0];
     c->keyframe   = !arith_get_bit(&acoder);
     if (c->keyframe) {
-        ff_mss12_codec_reset(c);
+        c->corrupted = 0;
+        ff_mss12_slicecontext_reset(&ctx->sc);
         pal_changed        = decode_pal(c, &acoder);
-        ctx->pic.key_frame = 1;
-        ctx->pic.pict_type = AV_PICTURE_TYPE_I;
+        ctx->pic->key_frame = 1;
+        ctx->pic->pict_type = AV_PICTURE_TYPE_I;
     } else {
         if (c->corrupted)
             return AVERROR_INVALIDDATA;
-        ctx->pic.key_frame = 0;
-        ctx->pic.pict_type = AV_PICTURE_TYPE_P;
+        ctx->pic->key_frame = 0;
+        ctx->pic->pict_type = AV_PICTURE_TYPE_P;
     }
-    c->corrupted = ff_mss12_decode_rect(&c->sc[0], &acoder, 0, 0,
+    c->corrupted = ff_mss12_decode_rect(&ctx->sc, &acoder, 0, 0,
                                         avctx->width, avctx->height);
     if (c->corrupted)
         return AVERROR_INVALIDDATA;
-    memcpy(ctx->pic.data[1], c->pal, AVPALETTE_SIZE);
-    ctx->pic.palette_has_changed = pal_changed;
+    memcpy(ctx->pic->data[1], c->pal, AVPALETTE_SIZE);
+    ctx->pic->palette_has_changed = pal_changed;
 
-    *data_size = sizeof(AVFrame);
-    *(AVFrame*)data = ctx->pic;
+    if ((ret = av_frame_ref(data, ctx->pic)) < 0)
+        return ret;
+
+    *got_frame      = 1;
 
     /* always report that the buffer was completely consumed */
     return buf_size;
@@ -189,19 +190,26 @@ static int mss1_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 static av_cold int mss1_decode_init(AVCodecContext *avctx)
 {
     MSS1Context * const c = avctx->priv_data;
+    int ret;
 
     c->ctx.avctx       = avctx;
-    avctx->coded_frame = &c->pic;
 
-    return ff_mss12_decode_init(&c->ctx, 0);
+    c->pic = av_frame_alloc();
+    if (!c->pic)
+        return AVERROR(ENOMEM);
+
+    ret = ff_mss12_decode_init(&c->ctx, 0, &c->sc, NULL);
+
+    avctx->pix_fmt = AV_PIX_FMT_PAL8;
+
+    return ret;
 }
 
 static av_cold int mss1_decode_end(AVCodecContext *avctx)
 {
     MSS1Context * const ctx = avctx->priv_data;
 
-    if (ctx->pic.data[0])
-        avctx->release_buffer(avctx, &ctx->pic);
+    av_frame_free(&ctx->pic);
     ff_mss12_decode_end(&ctx->ctx);
 
     return 0;
@@ -209,6 +217,7 @@ static av_cold int mss1_decode_end(AVCodecContext *avctx)
 
 AVCodec ff_mss1_decoder = {
     .name           = "mss1",
+    .long_name      = NULL_IF_CONFIG_SMALL("MS Screen 1"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_MSS1,
     .priv_data_size = sizeof(MSS1Context),
@@ -216,5 +225,4 @@ AVCodec ff_mss1_decoder = {
     .close          = mss1_decode_end,
     .decode         = mss1_decode_frame,
     .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("MS Screen 1"),
 };