]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vp56.c
Merge commit '25bacd0a0c32ae682e6f411b1ac9020aeaabca72'
[ffmpeg] / libavcodec / vp56.c
index b36c99fd33c5dde5f28c43992b71e08499c698a1..9d4162bb963dbcb594ef6b748c5db48aa06ce577 100644 (file)
@@ -400,30 +400,18 @@ static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src,
     }
 }
 
-static int vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
+static av_always_inline void vp56_render_mb(VP56Context *s, int row, int col, int is_alpha, VP56mb mb_type)
 {
-    AVFrame *frame_current, *frame_ref;
-    VP56mb mb_type;
-    VP56Frame ref_frame;
     int b, ab, b_max, plane, off;
-    int ret;
-
-    if (s->frames[VP56_FRAME_CURRENT]->key_frame)
-        mb_type = VP56_MB_INTRA;
-    else
-        mb_type = vp56_decode_mv(s, row, col);
-    ref_frame = ff_vp56_reference_frame[mb_type];
-
-    ret = s->parse_coeff(s);
-    if (ret < 0)
-        return ret;
+    AVFrame *frame_current, *frame_ref;
+    VP56Frame ref_frame = ff_vp56_reference_frame[mb_type];
 
     vp56_add_predictors_dc(s, ref_frame);
 
     frame_current = s->frames[VP56_FRAME_CURRENT];
     frame_ref = s->frames[ref_frame];
     if (mb_type != VP56_MB_INTRA && !frame_ref->data[0])
-        return 0;
+        return;
 
     ab = 6*is_alpha;
     b_max = 6 - 2*is_alpha;
@@ -473,57 +461,38 @@ static int vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
         s->block_coeff[4][0] = 0;
         s->block_coeff[5][0] = 0;
     }
-    return 0;
 }
 
-static int vp56_conceal_mb(VP56Context *s, int row, int col, int is_alpha)
+static int vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
 {
-    AVFrame *frame_current, *frame_ref;
     VP56mb mb_type;
-    VP56Frame ref_frame;
-    int b, ab, b_max, plane, off;
+    int ret;
 
     if (s->frames[VP56_FRAME_CURRENT]->key_frame)
         mb_type = VP56_MB_INTRA;
     else
-        mb_type = vp56_conceal_mv(s, row, col);
-    ref_frame = ff_vp56_reference_frame[mb_type];
+        mb_type = vp56_decode_mv(s, row, col);
 
-    frame_current = s->frames[VP56_FRAME_CURRENT];
-    frame_ref = s->frames[ref_frame];
-    if (mb_type != VP56_MB_INTRA && !frame_ref->data[0])
-        return 0;
+    ret = s->parse_coeff(s);
+    if (ret < 0)
+        return ret;
 
-    ab = 6*is_alpha;
-    b_max = 6 - 2*is_alpha;
+    vp56_render_mb(s, row, col, is_alpha, mb_type);
 
-    switch (mb_type) {
-        case VP56_MB_INTRA:
-            for (b=0; b<b_max; b++) {
-                plane = ff_vp56_b2p[b+ab];
-                s->vp3dsp.idct_put(frame_current->data[plane] + s->block_offset[b],
-                                s->stride[plane], s->block_coeff[b]);
-            }
-            break;
+    return 0;
+}
 
-        case VP56_MB_INTER_NOVEC_PF:
-        case VP56_MB_INTER_NOVEC_GF:
-            for (b=0; b<b_max; b++) {
-                plane = ff_vp56_b2p[b+ab];
-                off = s->block_offset[b];
-                s->hdsp.put_pixels_tab[1][0](frame_current->data[plane] + off,
-                                             frame_ref->data[plane] + off,
-                                             s->stride[plane], 8);
-                s->vp3dsp.idct_add(frame_current->data[plane] + off,
-                                s->stride[plane], s->block_coeff[b]);
-            }
-            break;
-    }
+static int vp56_conceal_mb(VP56Context *s, int row, int col, int is_alpha)
+{
+    VP56mb mb_type;
+
+    if (s->frames[VP56_FRAME_CURRENT]->key_frame)
+        mb_type = VP56_MB_INTRA;
+    else
+        mb_type = vp56_conceal_mv(s, row, col);
+
+    vp56_render_mb(s, row, col, is_alpha, mb_type);
 
-    if (is_alpha) {
-        s->block_coeff[4][0] = 0;
-        s->block_coeff[5][0] = 0;
-    }
     return 0;
 }
 
@@ -538,6 +507,8 @@ static int vp56_size_changed(VP56Context *s)
     s->plane_height[0] = s->plane_height[3] = avctx->coded_height;
     s->plane_height[1] = s->plane_height[2] = avctx->coded_height/2;
 
+    s->have_undamaged_frame = 0;
+
     for (i=0; i<4; i++)
         s->stride[i] = s->flip * s->frames[VP56_FRAME_CURRENT]->linesize[i];
 
@@ -603,13 +574,18 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     }
 
     ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF);
-    if (ret < 0)
+    if (ret < 0) {
+        if (res == VP56_SIZE_CHANGE)
+            ff_set_dimensions(avctx, 0, 0);
         return ret;
+    }
 
     if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) {
         av_frame_unref(s->alpha_context->frames[VP56_FRAME_CURRENT]);
         if ((ret = av_frame_ref(s->alpha_context->frames[VP56_FRAME_CURRENT], p)) < 0) {
             av_frame_unref(p);
+            if (res == VP56_SIZE_CHANGE)
+                ff_set_dimensions(avctx, 0, 0);
             return ret;
         }
     }
@@ -643,8 +619,12 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         }
     }
 
+    s->discard_frame = 0;
     avctx->execute2(avctx, ff_vp56_decode_mbs, 0, 0, (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) + 1);
 
+    if (s->discard_frame)
+        return AVERROR_INVALIDDATA;
+
     if ((res = av_frame_ref(data, p)) < 0)
         return res;
     *got_frame = 1;
@@ -730,8 +710,13 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
         for (mb_col=0; mb_col<s->mb_width; mb_col++) {
             if (!damaged) {
                 int ret = vp56_decode_mb(s, mb_row, mb_col, is_alpha);
-                if (ret < 0)
+                if (ret < 0) {
                     damaged = 1;
+                    if (!s->have_undamaged_frame) {
+                        s->discard_frame = 1;
+                        return AVERROR_INVALIDDATA;
+                    }
+                }
             }
             if (damaged)
                 vp56_conceal_mb(s, mb_row, mb_col, is_alpha);
@@ -748,6 +733,9 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
         }
     }
 
+    if (!damaged)
+        s->have_undamaged_frame = 1;
+
 next:
     if (p->key_frame || s->golden_frame) {
         av_frame_unref(s->frames[VP56_FRAME_GOLDEN]);