Re: [FFmpeg-devel] [PATCH 11/11] avcodec/vvcdec: add Intra Block Copy decoder

2024-02-24 Thread Nuo Mi
On Sat, Feb 24, 2024 at 9:20 PM Ronald S. Bultje  wrote:

> Hi,
>
> On Thu, Feb 22, 2024 at 2:15 AM Nuo Mi  wrote:
>
>> +static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit
>> *cu)
>> [..]
>>
> +av_image_copy_plane(ibc_buf, ibc_stride, src, src_stride,
>> cu->cb_width >> hs << ps , cu->cb_height >> vs);
>>
>
> I'm admittedly not super-familiar with VVC, but I wonder why we need the
> double buffering here (from ref_pos in pic to ibc_buf, and then back from
> ibc_buf back to cur block in pic)? In AV1, this is done with just a single
> copy. Why is this done this way?
>
Hi Ronald,
Two major differences between AV1 and VVC are:
1. AV1 disables all in-loop filters for IBC, while VVC does not.
2. AV1 can refer to any reconstructed super blocks, except the delayed
super block, whereas VVC can only refer to the left and current CTU.
Therefore, in VVC, we need to allocate memory for each line to save pixels
before applying filters. VVC refers to this memory as IbcVirBuf, which is a
2D cyclic buffer.
Every new reconstructed Coding Block will be copied to this buffer, and we
can only copy pixels from this buffer.

Best Regards.

>
> Ronald
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 11/11] avcodec/vvcdec: add Intra Block Copy decoder

2024-02-24 Thread Ronald S. Bultje
Hi,

On Thu, Feb 22, 2024 at 2:15 AM Nuo Mi  wrote:

> +static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit
> *cu)
> [..]
>
+av_image_copy_plane(ibc_buf, ibc_stride, src, src_stride,
> cu->cb_width >> hs << ps , cu->cb_height >> vs);
>

I'm admittedly not super-familiar with VVC, but I wonder why we need the
double buffering here (from ref_pos in pic to ibc_buf, and then back from
ibc_buf back to cur block in pic)? In AV1, this is done with just a single
copy. Why is this done this way?

Ronald
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 11/11] avcodec/vvcdec: add Intra Block Copy decoder

2024-02-24 Thread Nuo Mi
On Fri, Feb 23, 2024 at 9:03 PM Nuo Mi  wrote:

>
>
> On Thu, Feb 22, 2024 at 3:15 PM Nuo Mi  wrote:
>
>> From: Wu Jianhua 
>>
>> Introduction at https://ieeexplore.ieee.org/document/9408666
>>
>> passed files:
>> 10b444_A_Kwai_3.bit
>> 10b444_B_Kwai_3.bit
>> CodingToolsSets_D_Tencent_2.bit
>> IBC_A_Tencent_2.bit
>> IBC_B_Tencent_2.bit
>> IBC_C_Tencent_2.bit
>> IBC_D_Tencent_2.bit
>> IBC_E_Tencent_1.bit
>> LOSSLESS_B_HHI_3.bit
>>
> Will push tomorrow if there are no objections.
>
pushed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 11/11] avcodec/vvcdec: add Intra Block Copy decoder

2024-02-23 Thread Nuo Mi
On Thu, Feb 22, 2024 at 3:15 PM Nuo Mi  wrote:

> From: Wu Jianhua 
>
> Introduction at https://ieeexplore.ieee.org/document/9408666
>
> passed files:
> 10b444_A_Kwai_3.bit
> 10b444_B_Kwai_3.bit
> CodingToolsSets_D_Tencent_2.bit
> IBC_A_Tencent_2.bit
> IBC_B_Tencent_2.bit
> IBC_C_Tencent_2.bit
> IBC_D_Tencent_2.bit
> IBC_E_Tencent_1.bit
> LOSSLESS_B_HHI_3.bit
>
Will push tomorrow if there are no objections.

>
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 11/11] avcodec/vvcdec: add Intra Block Copy decoder

2024-02-21 Thread Nuo Mi
From: Wu Jianhua 

Introduction at https://ieeexplore.ieee.org/document/9408666

passed files:
10b444_A_Kwai_3.bit
10b444_B_Kwai_3.bit
CodingToolsSets_D_Tencent_2.bit
IBC_A_Tencent_2.bit
IBC_B_Tencent_2.bit
IBC_C_Tencent_2.bit
IBC_D_Tencent_2.bit
IBC_E_Tencent_1.bit
LOSSLESS_B_HHI_3.bit

Signed-off-by: Wu Jianhua 
Signed-off-by: Nuo Mi 
---
 libavcodec/vvc/vvc_intra.c | 81 ++
 libavcodec/vvc/vvcdec.c| 25 
 libavcodec/vvc/vvcdec.h|  3 ++
 3 files changed, 109 insertions(+)

diff --git a/libavcodec/vvc/vvc_intra.c b/libavcodec/vvc/vvc_intra.c
index fb001d6713..58dd492478 100644
--- a/libavcodec/vvc/vvc_intra.c
+++ b/libavcodec/vvc/vvc_intra.c
@@ -20,11 +20,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "libavutil/frame.h"
+#include "libavutil/imgutils.h"
 
 #include "vvc_data.h"
 #include "vvc_inter.h"
 #include "vvc_intra.h"
 #include "vvc_itx_1d.h"
+#include "vvc_mvs.h"
 
 static int is_cclm(enum IntraPredMode mode)
 {
@@ -580,6 +582,81 @@ static int reconstruct(VVCLocalContext *lc)
 return 0;
 }
 
+#define POS(c_idx, x, y)\
+>frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * 
fc->frame->linesize[c_idx] +   \
+(((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
+
+#define IBC_POS(c_idx, x, y) \
+(fc->tab.ibc_vir_buf[c_idx] + \
+(x << ps) + (y + ((cu->y0 & ~(sps->ctb_size_y - 1)) >> vs)) * 
ibc_stride)
+#define IBC_X(x)  ((x) & ((fc->tab.sz.ibc_buffer_width >> hs) - 1))
+#define IBC_Y(y)  ((y) & ((1 << sps->ctb_log2_size_y >> vs) - 1))
+
+static void intra_block_copy(const VVCLocalContext *lc, const int c_idx)
+{
+const CodingUnit *cu  = lc->cu;
+const PredictionUnit *pu  = >pu;
+const VVCFrameContext *fc = lc->fc;
+const VVCSPS *sps = fc->ps.sps;
+const Mv *bv  = >mi.mv[L0][0];
+const int hs  = sps->hshift[c_idx];
+const int vs  = sps->vshift[c_idx];
+const int ps  = sps->pixel_shift;
+const int ref_x   = IBC_X((cu->x0 >> hs) + (bv->x >> (4 + hs)));
+const int ref_y   = IBC_Y((cu->y0 >> vs) + (bv->y >> (4 + vs)));
+const int w   = cu->cb_width >> hs;
+const int h   = cu->cb_height >> vs;
+const int ibc_buf_width   = fc->tab.sz.ibc_buffer_width >> hs;///< 
IbcBufWidthY and IbcBufWidthC
+const int rw  = FFMIN(w, ibc_buf_width - ref_x);
+const int ibc_stride  = ibc_buf_width << ps;
+const int dst_stride  = fc->frame->linesize[c_idx];
+const uint8_t *ibc_buf= IBC_POS(c_idx, ref_x, ref_y);
+uint8_t *dst  = POS(c_idx, cu->x0, cu->y0);
+
+av_image_copy_plane(dst, dst_stride, ibc_buf, ibc_stride, rw << ps, h);
+
+if (w > rw) {
+//wrap around, left part
+ibc_buf = IBC_POS(c_idx, 0, ref_y);
+dst  += rw << ps;
+av_image_copy_plane(dst, dst_stride, ibc_buf, ibc_stride, (w - rw) << 
ps, h);
+}
+}
+
+static void vvc_predict_ibc(const VVCLocalContext *lc)
+{
+const H266RawSPS *rsps = lc->fc->ps.sps->r;
+
+intra_block_copy(lc, LUMA);
+if (lc->cu->tree_type == SINGLE_TREE && rsps->sps_chroma_format_idc) {
+intra_block_copy(lc, CB);
+intra_block_copy(lc, CR);
+}
+}
+
+static void ibc_fill_vir_buf(const VVCLocalContext *lc, const CodingUnit *cu)
+{
+const VVCFrameContext *fc = lc->fc;
+const VVCSPS *sps = fc->ps.sps;
+const int has_chroma  = sps->r->sps_chroma_format_idc && cu->tree_type 
!= DUAL_TREE_LUMA;
+const int start   = cu->tree_type == DUAL_TREE_CHROMA;
+const int end = has_chroma ? CR : LUMA;
+
+for (int c_idx = start; c_idx <= end; c_idx++) {
+const int hs = sps->hshift[c_idx];
+const int vs = sps->vshift[c_idx];
+const int ps = sps->pixel_shift;
+const int x  = IBC_X(cu->x0 >> hs);
+const int y  = IBC_Y(cu->y0 >> vs);
+const int src_stride = fc->frame->linesize[c_idx];
+const int ibc_stride = fc->tab.sz.ibc_buffer_width >> hs << ps;
+const uint8_t *src   = POS(c_idx, cu->x0, cu->y0);
+uint8_t *ibc_buf = IBC_POS(c_idx, x, y);
+
+av_image_copy_plane(ibc_buf, ibc_stride, src, src_stride, cu->cb_width 
>> hs << ps , cu->cb_height >> vs);
+}
+}
+
 int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, const int rx, const 
int ry)
 {
 const VVCFrameContext *fc   = lc->fc;
@@ -599,6 +676,8 @@ int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, 
const int rx, const in
 
 if (cu->ciip_flag)
 ff_vvc_predict_ciip(lc);
+else if (cu->pred_mode == MODE_IBC)
+vvc_predict_ibc(lc);
 if (cu->coded_flag) {
 ret = reconstruct(lc);
 } else {
@@ -607,6 +686,8 @@ int ff_vvc_reconstruct(VVCLocalContext *lc, const int rs, 
const int rx,