]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mss2.c
libx264: add support for nal-hrd, required for Blu-ray streams.
[ffmpeg] / libavcodec / mss2.c
index c0c47dc8d320c7272339014f6bf443903dbcdc8b..fbdc72c5c7f1646bd11f347b9ac28d90531fc537 100644 (file)
@@ -106,7 +106,7 @@ static int arith2_get_number(ArithCoder *c, int n)
     return val;
 }
 
-static int arith2_get_prob(ArithCoder *c, int *probs)
+static int arith2_get_prob(ArithCoder *c, int16_t *probs)
 {
     int range = c->high - c->low + 1, n = *probs;
     int scale = av_log2(range) - av_log2(n);
@@ -161,7 +161,7 @@ static int decode_pal_v2(MSS12Context *ctx, const uint8_t *buf, int buf_size)
         return 0;
 
     ncol = *buf++;
-    if (buf_size < 2 + ncol * 3)
+    if (ncol > ctx->free_colours || buf_size < 2 + ncol * 3)
         return -1;
     for (i = 0; i < ncol; i++)
         *pal++ = AV_RB24(buf + 3 * i);
@@ -335,8 +335,7 @@ static int decode_rle(GetBitContext *gb, uint8_t *pal_dst, int pal_stride,
                     else
                         repeat = get_bits(gb, b);
 
-                    while (b--)
-                        repeat += 1 << b;
+                    repeat += (1 << b) - 1;
 
                     if (last_symbol == -2) {
                         int skip = FFMIN(repeat, pal_dst + w - pp);
@@ -671,14 +670,18 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         buf      += get_bits_count(&gb) >> 3;
         buf_size -= get_bits_count(&gb) >> 3;
     } else {
-        if (keyframe)
-            ff_mss12_codec_reset(c);
+        if (keyframe) {
+            c->corrupted = 0;
+            ff_mss12_slicecontext_reset(&ctx->sc[0]);
+            if (c->slice_split)
+                ff_mss12_slicecontext_reset(&ctx->sc[1]);
+        }
         else if (c->corrupted)
             return AVERROR_INVALIDDATA;
         bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
         arith2_init(&acoder, &gB);
         c->keyframe = keyframe;
-        if (c->corrupted = ff_mss12_decode_rect(&c->sc[0], &acoder, 0, 0,
+        if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[0], &acoder, 0, 0,
                                                 avctx->width,
                                                 ctx->split_position))
             return AVERROR_INVALIDDATA;
@@ -690,7 +693,7 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
                 return AVERROR_INVALIDDATA;
             bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
             arith2_init(&acoder, &gB);
-            if (c->corrupted = ff_mss12_decode_rect(&c->sc[1], &acoder, 0,
+            if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[1], &acoder, 0,
                                                     ctx->split_position,
                                                     avctx->width,
                                                     avctx->height - ctx->split_position))
@@ -830,7 +833,7 @@ static av_cold int mss2_decode_init(AVCodecContext *avctx)
     int ret;
     c->avctx = avctx;
     avctx->coded_frame = &ctx->pic;
-    if (ret = ff_mss12_decode_init(c, 1))
+    if (ret = ff_mss12_decode_init(c, 1, &ctx->sc[0], &ctx->sc[1]))
         return ret;
     c->pal_stride   = c->mask_stride;
     c->pal_pic      = av_malloc(c->pal_stride * avctx->height);
@@ -844,6 +847,10 @@ static av_cold int mss2_decode_init(AVCodecContext *avctx)
         return ret;
     }
     ff_mss2dsp_init(&ctx->dsp);
+
+    avctx->pix_fmt = c->free_colours == 127 ? PIX_FMT_RGB555
+                                            : PIX_FMT_RGB24;
+
     return 0;
 }