[01/15] vc1dec: Fix mv_f shuffling

Message ID 1369729571-75967-1-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö May 28, 2013, 8:25 a.m.
From: Michael Niedermayer <michaelni@gmx.at>

Avoid a (confusing) memcpy(), making the code simpler code.
Fixes a small number of artifacts in black_screen_VC-1.mkv
and several more artifacts in other videos.
---
 libavcodec/vc1dec.c |   24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

Comments

Kostya Shishkov May 28, 2013, 8:48 a.m. | #1
On Tue, May 28, 2013 at 11:25:57AM +0300, Martin Storsjö wrote:
> From: Michael Niedermayer <michaelni@gmx.at>
> 
> Avoid a (confusing) memcpy(), making the code simpler code.
> Fixes a small number of artifacts in black_screen_VC-1.mkv
> and several more artifacts in other videos.

The message should be improved into better message. Partly because it's poorly
formulated, partly because it doesn't really say what has been done.
My suggestion is:
Shuffle field MVs after decoding, not before.

This simplifies the code since copying MVs to the reference is not needed
anymore (and maybe something about fixing artifacts).

Patch

diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index a1c9890..d42573d 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -5889,20 +5889,11 @@  static int vc1_decode_frame(AVCodecContext *avctx, void *data,
         v->bits = buf_size * 8;
         v->end_mb_x = s->mb_width;
         if (v->field_mode) {
-            uint8_t *tmp[2];
             s->current_picture.f.linesize[0] <<= 1;
             s->current_picture.f.linesize[1] <<= 1;
             s->current_picture.f.linesize[2] <<= 1;
             s->linesize                      <<= 1;
             s->uvlinesize                    <<= 1;
-            tmp[0]          = v->mv_f_last[0];
-            tmp[1]          = v->mv_f_last[1];
-            v->mv_f_last[0] = v->mv_f_next[0];
-            v->mv_f_last[1] = v->mv_f_next[1];
-            v->mv_f_next[0] = v->mv_f[0];
-            v->mv_f_next[1] = v->mv_f[1];
-            v->mv_f[0] = tmp[0];
-            v->mv_f[1] = tmp[1];
         }
         mb_height = s->mb_height >> v->field_mode;
         for (i = 0; i <= n_slices; i++) {
@@ -5947,15 +5938,22 @@  static int vc1_decode_frame(AVCodecContext *avctx, void *data,
         }
         if (v->field_mode) {
             v->second_field = 0;
-            if (s->pict_type == AV_PICTURE_TYPE_B) {
-                memcpy(v->mv_f_base, v->mv_f_next_base,
-                       2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2));
-            }
             s->current_picture.f.linesize[0] >>= 1;
             s->current_picture.f.linesize[1] >>= 1;
             s->current_picture.f.linesize[2] >>= 1;
             s->linesize                      >>= 1;
             s->uvlinesize                    >>= 1;
+            if (v->s.pict_type != AV_PICTURE_TYPE_BI && v->s.pict_type != AV_PICTURE_TYPE_B) {
+                uint8_t *tmp[2];
+                tmp[0]          = v->mv_f_last[0];
+                tmp[1]          = v->mv_f_last[1];
+                v->mv_f_last[0] = v->mv_f_next[0];
+                v->mv_f_last[1] = v->mv_f_next[1];
+                v->mv_f_next[0] = v->mv_f[0];
+                v->mv_f_next[1] = v->mv_f[1];
+                v->mv_f[0] = tmp[0];
+                v->mv_f[1] = tmp[1];
+            }
         }
         av_dlog(s->avctx, "Consumed %i/%i bits\n",
                 get_bits_count(&s->gb), s->gb.size_in_bits);