diff mbox series

[FFmpeg-devel,5/5] avcodec/vvcdec: support mv wraparound

Message ID TYSPR06MB6433A1570473A7C0A9E0B7BFAAFF2@TYSPR06MB6433.apcprd06.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,1/5] avcodec/vvcdec: refact, remove emulated_edge_dmvr and emulated_edge_bilinear to simplify code | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed

Commit Message

Nuo Mi June 3, 2024, 12:51 p.m. UTC
A 360 video specific tool
see https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9503377

passed files:
    DMVR_A_Huawei_3.bit
    WRAP_D_InterDigital_4.bit
    WRAP_A_InterDigital_4.bit
    WRAP_B_InterDigital_4.bit
    WRAP_C_InterDigital_4.bit
    ERP_A_MediaTek_3.bit
---
 libavcodec/vvc/inter.c | 81 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 79 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer June 4, 2024, 12:40 a.m. UTC | #1
On Mon, Jun 03, 2024 at 08:51:16PM +0800, Nuo Mi wrote:
> A 360 video specific tool
> see https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9503377
> 
> passed files:
>     DMVR_A_Huawei_3.bit
>     WRAP_D_InterDigital_4.bit
>     WRAP_A_InterDigital_4.bit
>     WRAP_B_InterDigital_4.bit
>     WRAP_C_InterDigital_4.bit
>     ERP_A_MediaTek_3.bit
> ---
>  libavcodec/vvc/inter.c | 81 ++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 79 insertions(+), 2 deletions(-)

seems to break fate-vvc-conformance-WRAP_A_4, maybe the fate checksums need to be updated ?

TEST    vvc-conformance-WRAP_A_4
--- ./tests/ref/fate/vvc-conformance-WRAP_A_4	2024-06-03 22:55:42.173081332 +0200
+++ tests/data/fate/vvc-conformance-WRAP_A_4	2024-06-04 02:39:44.835650168 +0200
@@ -4,11 +4,11 @@
 #dimensions 0: 1680x832
 #sar 0: 0/1
 0,          0,          0,        1,  4193280, 0xbd70f1b3
-0,          1,          1,        1,  4193280, 0x64e160d5
-0,          2,          2,        1,  4193280, 0xd20722ea
-0,          3,          3,        1,  4193280, 0xa1d00055
-0,          4,          4,        1,  4193280, 0xe3dcb9cd
-0,          5,          5,        1,  4193280, 0xcf97b6cf
-0,          6,          6,        1,  4193280, 0xd87b73d0
-0,          7,          7,        1,  4193280, 0x0f8ee2bc
-0,          8,          8,        1,  4193280, 0x76607ca4
+0,          1,          1,        1,  4193280, 0x491104c9
+0,          2,          2,        1,  4193280, 0xf600c2c1
+0,          3,          3,        1,  4193280, 0x1e3c8e2b
+0,          4,          4,        1,  4193280, 0xad275e45
+0,          5,          5,        1,  4193280, 0xcd6103d7
+0,          6,          6,        1,  4193280, 0x0ec8cfbd
+0,          7,          7,        1,  4193280, 0x2f664486
+0,          8,          8,        1,  4193280, 0x543eb3fc
Test vvc-conformance-WRAP_A_4 failed. Look at tests/data/fate/vvc-conformance-WRAP_A_4.err for details.
make: *** [tests/Makefile:311: fate-vvc-conformance-WRAP_A_4] Error 1

thx

[...]
Nuo Mi June 4, 2024, 12:11 p.m. UTC | #2
On Tue, Jun 4, 2024 at 8:41 AM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Mon, Jun 03, 2024 at 08:51:16PM +0800, Nuo Mi wrote:
> > A 360 video specific tool
> > see https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9503377
> >
> > passed files:
> >     DMVR_A_Huawei_3.bit
> >     WRAP_D_InterDigital_4.bit
> >     WRAP_A_InterDigital_4.bit
> >     WRAP_B_InterDigital_4.bit
> >     WRAP_C_InterDigital_4.bit
> >     ERP_A_MediaTek_3.bit
> > ---
> >  libavcodec/vvc/inter.c | 81 ++++++++++++++++++++++++++++++++++++++++--
> >  1 file changed, 79 insertions(+), 2 deletions(-)
>
> seems to break fate-vvc-conformance-WRAP_A_4, maybe the fate checksums
> need to be updated ?
>
Hi Michael,
Sorry for missing the fate test
Yes, we need to update the reference. v2 will fix it

thank you.

>
> TEST    vvc-conformance-WRAP_A_4
> --- ./tests/ref/fate/vvc-conformance-WRAP_A_4   2024-06-03
> 22:55:42.173081332 +0200
> +++ tests/data/fate/vvc-conformance-WRAP_A_4    2024-06-04
> 02:39:44.835650168 +0200
> @@ -4,11 +4,11 @@
>  #dimensions 0: 1680x832
>  #sar 0: 0/1
>  0,          0,          0,        1,  4193280, 0xbd70f1b3
> -0,          1,          1,        1,  4193280, 0x64e160d5
> -0,          2,          2,        1,  4193280, 0xd20722ea
> -0,          3,          3,        1,  4193280, 0xa1d00055
> -0,          4,          4,        1,  4193280, 0xe3dcb9cd
> -0,          5,          5,        1,  4193280, 0xcf97b6cf
> -0,          6,          6,        1,  4193280, 0xd87b73d0
> -0,          7,          7,        1,  4193280, 0x0f8ee2bc
> -0,          8,          8,        1,  4193280, 0x76607ca4
> +0,          1,          1,        1,  4193280, 0x491104c9
> +0,          2,          2,        1,  4193280, 0xf600c2c1
> +0,          3,          3,        1,  4193280, 0x1e3c8e2b
> +0,          4,          4,        1,  4193280, 0xad275e45
> +0,          5,          5,        1,  4193280, 0xcd6103d7
> +0,          6,          6,        1,  4193280, 0x0ec8cfbd
> +0,          7,          7,        1,  4193280, 0x2f664486
> +0,          8,          8,        1,  4193280, 0x543eb3fc
> Test vvc-conformance-WRAP_A_4 failed. Look at
> tests/data/fate/vvc-conformance-WRAP_A_4.err for details.
> make: *** [tests/Makefile:311: fate-vvc-conformance-WRAP_A_4] Error 1
>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Some people wanted to paint the bikeshed green, some blue and some pink.
> People argued and fought, when they finally agreed, only rust was left.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
diff mbox series

Patch

diff --git a/libavcodec/vvc/inter.c b/libavcodec/vvc/inter.c
index 09575eb2b4..98cb43322f 100644
--- a/libavcodec/vvc/inter.c
+++ b/libavcodec/vvc/inter.c
@@ -95,20 +95,97 @@  static void emulated_edge_no_wrap(const VVCLocalContext *lc, uint8_t *dst,
     }
 }
 
+static void emulated_half(const VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
+    const uint8_t *src, const ptrdiff_t src_stride, const int ps,
+    int x_off, int y_off, const int block_w, const int block_h,
+    const VVCRect *subpic,const VVCRect *half_sb, const int dmvr_clip)
+{
+    const VVCFrameContext *fc = lc->fc;
+    int pic_width, pic_height;
+
+    src += y_off * src_stride + x_off * (1 << ps);
+
+    clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, half_sb, dmvr_clip);
+
+    fc->vdsp.emulated_edge_mc(dst, src, dst_stride, src_stride,
+        block_w, block_h, x_off, y_off, pic_width, pic_height);
+}
+
+static void sb_set_lr(VVCRect *sb, const int l, const int r)
+{
+    sb->l = l;
+    sb->r = r;
+}
+
+static void sb_wrap(VVCRect *sb, const int wrap)
+{
+    sb_set_lr(sb, sb->l + wrap, sb->r + wrap);
+}
+
 static void emulated_edge(const VVCLocalContext *lc, uint8_t *dst,
     const uint8_t **src, ptrdiff_t *src_stride, const VVCFrame *src_frame,
     int x_sb, int y_sb, int x_off, int y_off, int block_w, int block_h, const int wrap_enabled,
     const int is_chroma, const int extra_before, const int extra_after)
 {
+    const VVCSPS *sps          = src_frame->sps;
+    const VVCPPS *pps          = src_frame->pps;
+    const int ps               = sps->pixel_shift;
     const int subpic_idx       = lc->sc->sh.r->curr_subpic_idx;
+    const int extra            = extra_before + extra_after;
     const int dmvr_clip        = x_sb != x_off || y_sb != y_off;
+    const int dmvr_left        = FFMAX(x_off, x_sb) - extra_before;
+    const int dmvr_right       = FFMIN(x_off, x_sb) + block_w + extra_after;
+    const int left             = x_off - extra_before;
+    const int top              = y_off - extra_before;
+    const int pic_width        = pps->width >> sps->hshift[is_chroma];
+    const int wrap             = pps->ref_wraparound_offset << (sps->min_cb_log2_size_y - sps->hshift[is_chroma]);
+    const ptrdiff_t dst_stride = EDGE_EMU_BUFFER_STRIDE << ps;
     VVCRect sb                 = { x_sb - extra_before, y_sb - extra_before, x_sb + block_w + extra_after, y_sb + block_h + extra_after };
     VVCRect subpic;
 
     subpic_get_rect(&subpic, src_frame, subpic_idx, is_chroma);
 
-    return emulated_edge_no_wrap(lc, dst, src, src_stride,
-        x_off, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip);
+    if (!wrap_enabled || (dmvr_left >= 0 && dmvr_right <= pic_width)) {
+        return emulated_edge_no_wrap(lc, dst, src, src_stride,
+            x_off, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip);
+    }
+    if (dmvr_right <= 0) {
+        sb_wrap(&sb, wrap);
+        return emulated_edge_no_wrap(lc, dst, src, src_stride,
+            x_off + wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip);
+    }
+    if (dmvr_left >= pic_width) {
+        sb_wrap(&sb, -wrap);
+        return emulated_edge_no_wrap(lc, dst, src, src_stride,
+            x_off - wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip);
+    }
+
+    block_w += extra;
+    block_h += extra;
+
+    // half block are wrapped
+    if (dmvr_left < 0 ) {
+        const int w     = -left;
+        VVCRect half_sb = { sb.l + wrap, sb.t, 0 + wrap, sb.b };
+        emulated_half(lc, dst, dst_stride, *src, *src_stride, ps,
+            left + wrap, top, w, block_h, &subpic, &half_sb, dmvr_clip);
+
+        sb_set_lr(&half_sb, 0, sb.r);
+        emulated_half(lc, dst +  (w << ps), dst_stride, *src, *src_stride, ps,
+            0, top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip);
+    } else {
+        const int w     = pic_width - left;
+        VVCRect half_sb = { sb.l, sb.t, pic_width, sb.b };
+        emulated_half(lc, dst, dst_stride, *src, *src_stride, ps,
+            left, top, w, block_h, &subpic, &half_sb, dmvr_clip);
+
+        sb_set_lr(&half_sb, pic_width - wrap, sb.r - wrap);
+        emulated_half(lc, dst +  (w << ps), dst_stride, *src, *src_stride, ps,
+            pic_width - wrap , top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip);
+    }
+
+    *src = dst + extra_before * dst_stride + (extra_before << ps);
+    *src_stride = dst_stride;
 }
 
 #define MC_EMULATED_EDGE(dst, src, src_stride, x_off, y_off)                                                                    \