]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/truemotion2.c
avcodec/motionpixels: Don't check for errors for complete VLC
[ffmpeg] / libavcodec / truemotion2.c
index d90a8baff37b1a91eba89d30f6e90e21a57bc6d1..0f4f345a6c7c5894ddb389802be6b75c1d529f57 100644 (file)
@@ -81,7 +81,7 @@ typedef struct TM2Context {
     int *clast;
 
     /* data for current and previous frame */
-    int *Y1_base, *U1_base, *V1_base, *Y2_base, *U2_base, *V2_base;
+    int *Y_base, *UV_base;
     int *Y1, *U1, *V1, *Y2, *U2, *V2;
     int y_stride, uv_stride;
     int cur;
@@ -200,8 +200,6 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
 
     /* convert codes to vlc_table */
     if (res >= 0) {
-        int i;
-
         res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,
                        huff.lens, sizeof(int), sizeof(int),
                        huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
@@ -210,13 +208,8 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
         else {
             code->bits = huff.max_bits;
             code->length = huff.max_num;
-            code->recode = av_malloc_array(code->length, sizeof(int));
-            if (!code->recode) {
-                res = AVERROR(ENOMEM);
-                goto out;
-            }
-            for (i = 0; i < code->length; i++)
-                code->recode[i] = huff.nums[i];
+            code->recode = huff.nums;
+            huff.nums = NULL;
         }
     }
 
@@ -957,7 +950,7 @@ static int decode_frame(AVCodecContext *avctx,
 static av_cold int decode_init(AVCodecContext *avctx)
 {
     TM2Context * const l = avctx->priv_data;
-    int i, w = avctx->width, h = avctx->height;
+    int w = avctx->width, h = avctx->height;
 
     if ((avctx->width & 3) || (avctx->height & 3)) {
         av_log(avctx, AV_LOG_ERROR, "Width and height must be multiple of 4\n");
@@ -973,47 +966,29 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     ff_bswapdsp_init(&l->bdsp);
 
-    l->last  = av_malloc_array(w >> 2, 4 * sizeof(*l->last) );
-    l->clast = av_malloc_array(w >> 2, 4 * sizeof(*l->clast));
-
-    for (i = 0; i < TM2_NUM_STREAMS; i++) {
-        l->tokens[i] = NULL;
-        l->tok_lens[i] = 0;
-    }
+    l->last  = av_malloc_array(w, 2 * sizeof(*l->last));
+    if (!l->last)
+        return AVERROR(ENOMEM);
+    l->clast = l->last + w;
 
     w += 8;
     h += 8;
-    l->Y1_base = av_calloc(w * h, sizeof(*l->Y1_base));
-    l->Y2_base = av_calloc(w * h, sizeof(*l->Y2_base));
+    l->Y_base = av_calloc(w * h, 2 * sizeof(*l->Y_base));
+    if (!l->Y_base)
+        return AVERROR(ENOMEM);
     l->y_stride = w;
+    l->Y1 = l->Y_base + l->y_stride * 4 + 4;
+    l->Y2 = l->Y1 + w * h;
     w = (w + 1) >> 1;
     h = (h + 1) >> 1;
-    l->U1_base = av_calloc(w * h, sizeof(*l->U1_base));
-    l->V1_base = av_calloc(w * h, sizeof(*l->V1_base));
-    l->U2_base = av_calloc(w * h, sizeof(*l->U2_base));
-    l->V2_base = av_calloc(w * h, sizeof(*l->V1_base));
-    l->uv_stride = w;
-    l->cur = 0;
-    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_frame_free(&l->pic);
+    l->UV_base = av_calloc(w * h, 4 * sizeof(*l->UV_base));
+    if (!l->UV_base)
         return AVERROR(ENOMEM);
-    }
-    l->Y1 = l->Y1_base + l->y_stride  * 4 + 4;
-    l->Y2 = l->Y2_base + l->y_stride  * 4 + 4;
-    l->U1 = l->U1_base + l->uv_stride * 2 + 2;
-    l->U2 = l->U2_base + l->uv_stride * 2 + 2;
-    l->V1 = l->V1_base + l->uv_stride * 2 + 2;
-    l->V2 = l->V2_base + l->uv_stride * 2 + 2;
+    l->uv_stride = w;
+    l->U1 = l->UV_base + l->uv_stride * 2 + 2;
+    l->U2 = l->U1 + w * h;
+    l->V1 = l->U2 + w * h;
+    l->V2 = l->V1 + w * h;
 
     return 0;
 }
@@ -1023,18 +998,12 @@ static av_cold int decode_end(AVCodecContext *avctx)
     TM2Context * const l = avctx->priv_data;
     int i;
 
-    av_free(l->last);
-    av_free(l->clast);
+    av_freep(&l->last);
     for (i = 0; i < TM2_NUM_STREAMS; i++)
         av_freep(&l->tokens[i]);
-    if (l->Y1) {
-        av_freep(&l->Y1_base);
-        av_freep(&l->U1_base);
-        av_freep(&l->V1_base);
-        av_freep(&l->Y2_base);
-        av_freep(&l->U2_base);
-        av_freep(&l->V2_base);
-    }
+
+    av_freep(&l->Y_base);
+    av_freep(&l->UV_base);
     av_freep(&l->buffer);
     l->buffer_size = 0;
 
@@ -1053,4 +1022,5 @@ AVCodec ff_truemotion2_decoder = {
     .close          = decode_end,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };