Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type
@ 2023-07-02 23:26 James Almer
  2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 2/4] avcodec/cbs_h266: add support for Decoding capability " James Almer
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: James Almer @ 2023-07-02 23:26 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_h2645.c                | 18 ++++++++++++++++++
 libavcodec/cbs_h266.h                 | 11 +++++++++++
 libavcodec/cbs_h266_syntax_template.c | 27 +++++++++++++++++++++++++++
 3 files changed, 56 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 68ccf6a7eb..8dc9ae471d 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1059,6 +1059,14 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
         return err;
 
     switch (unit->type) {
+    case VVC_OPI_NUT:
+        {
+            err = cbs_h266_read_opi(ctx, &gbc, unit->content);
+
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_VPS_NUT:
         {
             H266RawVPS *vps = unit->content;
@@ -1593,6 +1601,15 @@ static int cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
     int err;
 
     switch (unit->type) {
+    case VVC_OPI_NUT:
+        {
+            H266RawOPI *opi = unit->content;
+
+            err = cbs_h266_write_opi(ctx, pbc, opi);
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_VPS_NUT:
         {
             H266RawVPS *vps = unit->content;
@@ -1965,6 +1982,7 @@ static void cbs_h266_free_sei(void *opaque, uint8_t *content)
 }
 
 static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = {
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_OPI_NUT, H266RawOPI, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS, extension_data.data),
diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index e33d08a0f5..693d1ca1fd 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -230,6 +230,17 @@ typedef struct H266RawVUI {
     H266RawExtensionData extension_data;
 } H266RawVUI;
 
+typedef struct H266RawOPI {
+    H266RawNALUnitHeader nal_unit_header;
+
+    uint8_t opi_ols_info_present_flag;
+    uint8_t opi_htid_info_present_flag;
+    uint16_t opi_ols_idx;
+    uint8_t opi_htid_plus1;
+    uint8_t opi_extension_flag;
+    H266RawExtensionData extension_data;
+} H266RawOPI;
+
 typedef struct H266RawVPS {
     H266RawNALUnitHeader nal_unit_header;
 
diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c
index 957735056f..d9c8e0afbe 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -623,6 +623,33 @@ static int FUNC(ols_timing_hrd_parameters) (CodedBitstreamContext *ctx,
     return 0;
 }
 
+static int FUNC(opi)(CodedBitstreamContext *ctx, RWContext *rw,
+                     H266RawOPI *current)
+{
+    int err;
+
+    HEADER("Operating point information");
+
+    CHECK(FUNC(nal_unit_header)(ctx, rw,
+                                &current->nal_unit_header, VVC_OPI_NUT));
+
+    flag(opi_ols_info_present_flag);
+    flag(opi_htid_info_present_flag);
+
+    if(current->opi_ols_info_present_flag)
+        ue(opi_ols_idx, 0, VVC_MAX_TOTAL_NUM_OLSS - 1);
+
+    if(current->opi_htid_info_present_flag)
+        ub(3, opi_htid_plus1);
+
+    flag(opi_extension_flag);
+    if (current->opi_extension_flag)
+        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
+    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
+
+    return 0;
+}
+
 static int FUNC(vps) (CodedBitstreamContext *ctx, RWContext *rw,
                      H266RawVPS *current)
 {
-- 
2.41.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 2/4] avcodec/cbs_h266: add support for Decoding capability information NALU type
  2023-07-02 23:26 [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type James Almer
@ 2023-07-02 23:26 ` James Almer
  2023-07-03 15:11   ` Nuo Mi
  2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 3/4] avcodec/cbs_h266: add support for Adaptation parameter set " James Almer
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: James Almer @ 2023-07-02 23:26 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_h2645.c                | 18 ++++++++++++++++++
 libavcodec/cbs_h266.h                 | 10 ++++++++++
 libavcodec/cbs_h266_syntax_template.c | 24 ++++++++++++++++++++++++
 libavcodec/vvc.h                      |  3 +++
 4 files changed, 55 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 8dc9ae471d..95da597427 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1059,6 +1059,14 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
         return err;
 
     switch (unit->type) {
+    case VVC_DCI_NUT:
+        {
+            err = cbs_h266_read_dci(ctx, &gbc, unit->content);
+
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_OPI_NUT:
         {
             err = cbs_h266_read_opi(ctx, &gbc, unit->content);
@@ -1601,6 +1609,15 @@ static int cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
     int err;
 
     switch (unit->type) {
+    case VVC_DCI_NUT:
+        {
+            H266RawDCI *dci = unit->content;
+
+            err = cbs_h266_write_dci(ctx, pbc, dci);
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_OPI_NUT:
         {
             H266RawOPI *opi = unit->content;
@@ -1982,6 +1999,7 @@ static void cbs_h266_free_sei(void *opaque, uint8_t *content)
 }
 
 static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = {
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_DCI_NUT, H266RawDCI, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_OPI_NUT, H266RawOPI, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS, extension_data.data),
diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index 693d1ca1fd..87aa2d849d 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -241,6 +241,16 @@ typedef struct H266RawOPI {
     H266RawExtensionData extension_data;
 } H266RawOPI;
 
+typedef struct H266RawDCI {
+    H266RawNALUnitHeader nal_unit_header;
+
+    uint8_t dci_reserved_zero_4bits;
+    uint8_t dci_num_ptls_minus1;
+    H266RawProfileTierLevel dci_profile_tier_level[VVC_MAX_DCI_PTLS];
+    uint8_t dci_extension_flag;
+    H266RawExtensionData extension_data;
+} H266RawDCI;
+
 typedef struct H266RawVPS {
     H266RawNALUnitHeader nal_unit_header;
 
diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c
index d9c8e0afbe..4ea29ec789 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -650,6 +650,30 @@ static int FUNC(opi)(CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+static int FUNC(dci)(CodedBitstreamContext *ctx, RWContext *rw,
+                     H266RawDCI *current)
+{
+    int err, i;
+
+    HEADER("Decoding capability information");
+
+    CHECK(FUNC(nal_unit_header)(ctx, rw,
+                                &current->nal_unit_header, VVC_DCI_NUT));
+
+    ub(4, dci_reserved_zero_4bits);
+    ub(4, dci_num_ptls_minus1);
+    for (i = 0; i <= current->dci_num_ptls_minus1; i++)
+        CHECK(FUNC(profile_tier_level)(ctx, rw,
+                                       current->dci_profile_tier_level + i, 1, 0));
+
+    flag(dci_extension_flag);
+    if (current->dci_extension_flag)
+        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
+    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
+
+    return 0;
+}
+
 static int FUNC(vps) (CodedBitstreamContext *ctx, RWContext *rw,
                      H266RawVPS *current)
 {
diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
index 099d2fc2ad..eda1b40eef 100644
--- a/libavcodec/vvc.h
+++ b/libavcodec/vvc.h
@@ -76,6 +76,9 @@ enum {
     //7.4.3.3 The value of vps_max_sublayers_minus1 shall be in the range of 0 to 6, inclusive
     VVC_MAX_SUBLAYERS = 7,
 
+    //7.3.2.1 dci_num_ptls_minus1 is u(4)
+    VVC_MAX_DCI_PTLS = 16,
+
     //7.4.3.3 vps_num_ptls_minus1 is u(8)
     VVC_MAX_PTLS = 256,
 
-- 
2.41.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 3/4] avcodec/cbs_h266: add support for Adaptation parameter set NALU type
  2023-07-02 23:26 [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type James Almer
  2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 2/4] avcodec/cbs_h266: add support for Decoding capability " James Almer
@ 2023-07-02 23:26 ` James Almer
  2023-07-05 14:29   ` Nuo Mi
  2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 4/4] fate/cbs: add more VVC tests James Almer
  2023-07-05 14:32 ` [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type Nuo Mi
  3 siblings, 1 reply; 13+ messages in thread
From: James Almer @ 2023-07-02 23:26 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_h2645.c                |  21 +++
 libavcodec/cbs_h266.h                 |  46 ++++++
 libavcodec/cbs_h266_syntax_template.c | 201 ++++++++++++++++++++++++++
 libavcodec/vvc.h                      |  10 ++
 4 files changed, 278 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 95da597427..34c5d1d372 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1116,6 +1116,16 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
         }
         break;
 
+    case VVC_PREFIX_APS_NUT:
+    case VVC_SUFFIX_APS_NUT:
+        {
+            err = cbs_h266_read_aps(ctx, &gbc, unit->content,
+                                    unit->type == VVC_PREFIX_APS_NUT);
+
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_PH_NUT:
         {
             H266RawPH *ph = unit->content;
@@ -1668,6 +1678,15 @@ static int cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
         }
         break;
 
+    case VVC_PREFIX_APS_NUT:
+    case VVC_SUFFIX_APS_NUT:
+        {
+            err = cbs_h266_write_aps(ctx, pbc, unit->content,
+                                     unit->type == VVC_PREFIX_APS_NUT);
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_PH_NUT:
         {
             H266RawPH *ph = unit->content;
@@ -2004,6 +2023,8 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = {
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_PREFIX_APS_NUT, H266RawAPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_SUFFIX_APS_NUT, H266RawAPS, extension_data.data),
 
     CBS_UNIT_TYPE_POD(VVC_PH_NUT , H266RawPH),
     CBS_UNIT_TYPE_POD(VVC_AUD_NUT, H266RawAUD),
diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index 87aa2d849d..d068ffa87a 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -576,6 +576,52 @@ typedef struct H266RawPPS {
     uint16_t sub_pic_id_val[VVC_MAX_SLICES];
 } H266RawPPS;
 
+typedef struct H266RawAPS {
+    H266RawNALUnitHeader nal_unit_header;
+    uint8_t aps_params_type;
+    uint8_t aps_adaptation_parameter_set_id;
+    uint8_t aps_chroma_present_flag;
+
+    uint8_t alf_luma_filter_signal_flag;
+    uint8_t alf_chroma_filter_signal_flag;
+    uint8_t alf_cc_cb_filter_signal_flag;
+    uint8_t alf_cc_cr_filter_signal_flag;
+    uint8_t alf_luma_clip_flag;
+    uint8_t alf_luma_num_filters_signalled_minus1;
+    uint8_t alf_luma_coeff_delta_idx[VVC_NUM_ALF_FILTERS];
+    uint8_t alf_luma_coeff_abs[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_luma_coeff_sign[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_luma_clip_idx[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_chroma_clip_flag;
+    uint8_t alf_chroma_num_alt_filters_minus1;
+    uint8_t alf_chroma_coeff_abs[8][6];
+    uint8_t alf_chroma_coeff_sign[8][6];
+    uint8_t alf_chroma_clip_idx[8][6];
+    uint8_t alf_cc_cb_filters_signalled_minus1;
+    uint8_t alf_cc_cb_mapped_coeff_abs[4][7];
+    uint8_t alf_cc_cb_coeff_sign[4][7];
+    uint8_t alf_cc_cr_filters_signalled_minus1;
+    uint8_t alf_cc_cr_mapped_coeff_abs[4][7];
+    uint8_t alf_cc_cr_coeff_sign[4][7];
+
+    uint8_t scaling_list_copy_mode_flag[28];
+    uint8_t scaling_list_pred_mode_flag[28];
+    uint8_t scaling_list_pred_id_delta[28];
+    int8_t  scaling_list_dc_coef[28];
+    int8_t  scaling_list_delta_coef[28][64];
+
+    uint8_t lmcs_min_bin_idx;
+    uint8_t lmcs_delta_max_bin_idx;
+    uint8_t lmcs_delta_cw_prec_minus1;
+    uint16_t lmcs_delta_abs_cw[16];
+    uint8_t lmcs_delta_sign_cw_flag[16];
+    uint8_t lmcs_delta_abs_crs;
+    uint8_t lmcs_delta_sign_crs_flag;
+
+    uint8_t aps_extension_flag;
+    H266RawExtensionData extension_data;
+} H266RawAPS;
+
 typedef struct H266RawAUD {
     H266RawNALUnitHeader nal_unit_header;
     uint8_t aud_irap_or_gdr_flag;
diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c
index 4ea29ec789..61a7237978 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -2183,6 +2183,207 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+static int FUNC(alf_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                          H266RawAPS *current)
+{
+    int err, j, k;
+
+    flag(alf_luma_filter_signal_flag);
+
+    if (current->aps_chroma_present_flag) {
+        flag(alf_chroma_filter_signal_flag);
+        flag(alf_cc_cb_filter_signal_flag);
+        flag(alf_cc_cr_filter_signal_flag);
+    } else {
+        infer(alf_chroma_filter_signal_flag, 0);
+        infer(alf_cc_cb_filter_signal_flag, 0);
+        infer(alf_cc_cr_filter_signal_flag, 0);
+    }
+
+    if (current->alf_luma_filter_signal_flag) {
+        flag(alf_luma_clip_flag);
+        ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS - 1);
+        if (current->alf_luma_num_filters_signalled_minus1 > 0) {
+            unsigned int bits = av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
+            for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS; filt_idx++)
+                us(bits, alf_luma_coeff_delta_idx[filt_idx],
+                   0, current->alf_luma_num_filters_signalled_minus1,
+                   1, filt_idx);
+        }
+        for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
+            for (j = 0; j < 12; j++) {
+                ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
+                if (current->alf_luma_coeff_abs[sf_idx][j])
+                    ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
+                else
+                    infer(alf_luma_coeff_sign[sf_idx][j], 0);
+            }
+        if (current->alf_luma_clip_flag)
+            for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
+                for (j = 0; j < 12; j++)
+                    ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
+    }
+
+    if (current->alf_chroma_filter_signal_flag) {
+        flag(alf_chroma_clip_flag);
+        ue(alf_chroma_num_alt_filters_minus1, 0, 7);
+        for (int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
+            for (j = 0; j < 6; j++) {
+                ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
+                if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
+                    ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
+                else
+                    infer(alf_chroma_coeff_sign[alt_idx][j], 0);
+            }
+            if (current->alf_chroma_clip_flag)
+                for(j = 0; j < 6; j++)
+                    ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
+        }
+    }
+
+    if (current->alf_cc_cb_filter_signal_flag) {
+        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
+        for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
+            for (j = 0; j < 7; j++) {
+                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
+                if (current->alf_cc_cb_mapped_coeff_abs[k][j])
+                    ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
+                else
+                    infer(alf_cc_cb_coeff_sign[k][j], 0);
+            }
+        }
+    }
+
+    if (current->alf_cc_cr_filter_signal_flag) {
+        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
+        for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
+            for (j = 0; j < 7; j++) {
+                ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
+                if (current->alf_cc_cr_mapped_coeff_abs[k][j])
+                    ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
+                else
+                    infer(alf_cc_cr_coeff_sign[k][j], 0);
+            }
+        }
+    }
+
+    return 0;
+}
+
+static int FUNC(lmcs_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                           H266RawAPS *current)
+{
+    int err, i, lmcs_max_bin_idx;
+
+    ue(lmcs_min_bin_idx, 0, 15);
+    ue(lmcs_delta_max_bin_idx, 0, 15);
+    ue(lmcs_delta_cw_prec_minus1, 0, 14);
+
+    lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
+
+    if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
+        return AVERROR_INVALIDDATA;
+
+    for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
+        ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i], 1, i);
+        if (current->lmcs_delta_abs_cw[i] > 0)
+            flags(lmcs_delta_sign_cw_flag[i], 1, i);
+        else
+            infer(lmcs_delta_sign_cw_flag[i], 0);
+    }
+
+    if (current->aps_chroma_present_flag) {
+        ub(3, lmcs_delta_abs_crs);
+        if (current->lmcs_delta_abs_crs > 0)
+            flag(lmcs_delta_sign_crs_flag);
+        else
+            infer(lmcs_delta_sign_crs_flag, 0);
+    } else {
+        infer(lmcs_delta_abs_crs, 0);
+        infer(lmcs_delta_sign_crs_flag, 0);
+    }
+
+    return 0;
+}
+
+static int FUNC(scaling_list_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                                   H266RawAPS *current)
+{
+    // 7.4.3.4, deriving DiagScanOrder
+    static const uint8_t diag_scan_order[64][2] = {
+        { 0,  0, }, { 0,  1, }, { 1,  0, }, { 0,  2, }, { 1,  1, }, { 2,  0, }, { 0,  3, }, { 1,  2, },
+        { 2,  1, }, { 3,  0, }, { 0,  4, }, { 1,  3, }, { 2,  2, }, { 3,  1, }, { 4,  0, }, { 0,  5, },
+        { 1,  4, }, { 2,  3, }, { 3,  2, }, { 4,  1, }, { 5,  0, }, { 0,  6, }, { 1,  5, }, { 2,  4, },
+        { 3,  3, }, { 4,  2, }, { 5,  1, }, { 6,  0, }, { 0,  7, }, { 1,  6, }, { 2,  5, }, { 3,  4, },
+        { 4,  3, }, { 5,  2, }, { 6,  1, }, { 7,  0, }, { 1,  7, }, { 2,  6, }, { 3,  5, }, { 4,  4, },
+        { 5,  3, }, { 6,  2, }, { 7,  1, }, { 2,  7, }, { 3,  6, }, { 4,  5, }, { 5,  4, }, { 6,  3, },
+        { 7,  2, }, { 3,  7, }, { 4,  6, }, { 5,  5, }, { 6,  4, }, { 7,  3, }, { 4,  7, }, { 5,  6, },
+        { 6,  5, }, { 7,  4, }, { 5,  7, }, { 6,  6, }, { 7,  5, }, { 6,  7, }, { 7,  6, }, { 7,  7, }, };
+    int err;
+
+    for (int id = 0; id < 28; id ++) {
+        if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
+            flags(scaling_list_copy_mode_flag[id], 1, id);
+            if (!current->scaling_list_copy_mode_flag[id])
+                flags(scaling_list_pred_mode_flag[id], 1, id);
+            if ((current->scaling_list_copy_mode_flag[id] ||
+                 current->scaling_list_pred_mode_flag[id]) &&
+                 id != 0 && id != 2 && id != 8) {
+                int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) : (id - 8));
+                ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1, id);
+            }
+            if (!current->scaling_list_copy_mode_flag[id]) {
+                int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
+                if (id > 13) {
+                    int idx = id - 14;
+                    ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
+                } else
+                    infer(scaling_list_dc_coef[id], 0);
+                for (int i = 0; i < matrix_size * matrix_size; i++) {
+                    int x = diag_scan_order[i][0];
+                    int y = diag_scan_order[i][1];
+                    if (!(id > 25 && x >= 4 && y >= 4))
+                        ses(scaling_list_delta_coef[id][i], -128, 127, 2, id, i);
+                }
+            } else
+                infer(scaling_list_dc_coef[id], 0);
+        }
+    }
+
+    return 0;
+}
+
+static int FUNC(aps)(CodedBitstreamContext *ctx, RWContext *rw,
+                     H266RawAPS *current, int prefix)
+{
+    int err;
+
+    if (prefix)
+        HEADER("Prefix Adaptation parameter set");
+    else
+        HEADER("Suffix Adaptation parameter set");
+
+    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
+                                prefix ? VVC_PREFIX_APS_NUT
+                                       : VVC_SUFFIX_APS_NUT));
+
+    ub(3, aps_params_type);
+    ub(5, aps_adaptation_parameter_set_id);
+    flag(aps_chroma_present_flag);
+    if (current->aps_params_type == VVC_ASP_TYPE_ALF)
+        CHECK(FUNC(alf_data)(ctx, rw, current));
+    else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
+        CHECK(FUNC(lmcs_data)(ctx, rw, current));
+    else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
+        CHECK(FUNC(scaling_list_data)(ctx, rw, current));
+    flag(aps_extension_flag);
+    if (current->aps_extension_flag)
+        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
+    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
+
+    return 0;
+}
+
 static int FUNC(aud) (CodedBitstreamContext *ctx, RWContext *rw,
                      H266RawAUD *current)
 {
diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
index eda1b40eef..49822ecc84 100644
--- a/libavcodec/vvc.h
+++ b/libavcodec/vvc.h
@@ -66,6 +66,12 @@ enum VVCSliceType {
     VVC_SLICE_TYPE_I = 2,
 };
 
+enum VVCAPSType {
+    VVC_ASP_TYPE_ALF     = 0,
+    VVC_ASP_TYPE_LMCS    = 1,
+    VVC_ASP_TYPE_SCALING = 2,
+};
+
 enum {
     //6.2 we can have 3 sample arrays
     VVC_MAX_SAMPLE_ARRAYS = 3,
@@ -95,6 +101,10 @@ enum {
     // 7.4.4.1: ptl_num_sub_profiles is u(8)
     VVC_MAX_SUB_PROFILES = 256,
 
+    // 7.4.3.18: The variable NumAlfFilters specifying the number of different adaptive loop
+    // filters is set equal to 25.
+    VVC_NUM_ALF_FILTERS = 25,
+
     // A.4.2: according to (1577), MaxDpbSize is bounded above by 2 * maxDpbPicBuf(8)
     VVC_MAX_DPB_SIZE = 16,
 
-- 
2.41.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH 4/4] fate/cbs: add more VVC tests
  2023-07-02 23:26 [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type James Almer
  2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 2/4] avcodec/cbs_h266: add support for Decoding capability " James Almer
  2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 3/4] avcodec/cbs_h266: add support for Adaptation parameter set " James Almer
@ 2023-07-02 23:26 ` James Almer
  2023-07-05 14:32 ` [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type Nuo Mi
  3 siblings, 0 replies; 13+ messages in thread
From: James Almer @ 2023-07-02 23:26 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 tests/fate/cbs.mak                 | 5 +++++
 tests/ref/fate/cbs-vvc-APSALF_A_2  | 1 +
 tests/ref/fate/cbs-vvc-APSLMCS_D_1 | 1 +
 tests/ref/fate/cbs-vvc-APSMULT_A_4 | 1 +
 tests/ref/fate/cbs-vvc-DCI_A_3     | 1 +
 tests/ref/fate/cbs-vvc-OPI_B_3     | 1 +
 6 files changed, 10 insertions(+)
 create mode 100644 tests/ref/fate/cbs-vvc-APSALF_A_2
 create mode 100644 tests/ref/fate/cbs-vvc-APSLMCS_D_1
 create mode 100644 tests/ref/fate/cbs-vvc-APSMULT_A_4
 create mode 100644 tests/ref/fate/cbs-vvc-DCI_A_3
 create mode 100644 tests/ref/fate/cbs-vvc-OPI_B_3

diff --git a/tests/fate/cbs.mak b/tests/fate/cbs.mak
index 4d8742d99c..802b0351a3 100644
--- a/tests/fate/cbs.mak
+++ b/tests/fate/cbs.mak
@@ -167,12 +167,17 @@ fate-cbs-hevc: $(FATE_CBS_HEVC-yes)
 # H.266 read/write
 
 FATE_CBS_VVC_SAMPLES =        \
+    APSALF_A_2.bit            \
+    APSLMCS_D_1.bit           \
+    APSMULT_A_4.bit           \
     AUD_A_3.bit               \
     BOUNDARY_A_3.bit          \
     BUMP_A_2.bit              \
     CodingToolsSets_A_2.bit   \
     CROP_B_4.bit              \
+    DCI_A_3.bit               \
     HRD_A_3.bit               \
+    OPI_B_3.bit               \
     PHSH_B_1.bit              \
     POC_A_1.bit               \
     PPS_B_1.bit               \
diff --git a/tests/ref/fate/cbs-vvc-APSALF_A_2 b/tests/ref/fate/cbs-vvc-APSALF_A_2
new file mode 100644
index 0000000000..eb2fc02a5e
--- /dev/null
+++ b/tests/ref/fate/cbs-vvc-APSALF_A_2
@@ -0,0 +1 @@
+c981a00e28e51adde1654850935a889d
diff --git a/tests/ref/fate/cbs-vvc-APSLMCS_D_1 b/tests/ref/fate/cbs-vvc-APSLMCS_D_1
new file mode 100644
index 0000000000..430dc934b7
--- /dev/null
+++ b/tests/ref/fate/cbs-vvc-APSLMCS_D_1
@@ -0,0 +1 @@
+e2e3407885d84e0dee5ec5d51dd4a3a6
diff --git a/tests/ref/fate/cbs-vvc-APSMULT_A_4 b/tests/ref/fate/cbs-vvc-APSMULT_A_4
new file mode 100644
index 0000000000..79f29373b9
--- /dev/null
+++ b/tests/ref/fate/cbs-vvc-APSMULT_A_4
@@ -0,0 +1 @@
+66dc3dba5c25bcaab231007bc059c331
diff --git a/tests/ref/fate/cbs-vvc-DCI_A_3 b/tests/ref/fate/cbs-vvc-DCI_A_3
new file mode 100644
index 0000000000..fec635afa5
--- /dev/null
+++ b/tests/ref/fate/cbs-vvc-DCI_A_3
@@ -0,0 +1 @@
+2b0eb33eb66078a3454619c5612e7bc2
diff --git a/tests/ref/fate/cbs-vvc-OPI_B_3 b/tests/ref/fate/cbs-vvc-OPI_B_3
new file mode 100644
index 0000000000..99c85165aa
--- /dev/null
+++ b/tests/ref/fate/cbs-vvc-OPI_B_3
@@ -0,0 +1 @@
+c35066104c7cf9be0e7b9aad5b576256
-- 
2.41.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/4] avcodec/cbs_h266: add support for Decoding capability information NALU type
  2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 2/4] avcodec/cbs_h266: add support for Decoding capability " James Almer
@ 2023-07-03 15:11   ` Nuo Mi
  0 siblings, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2023-07-03 15:11 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Mon, Jul 3, 2023 at 7:28 AM James Almer <jamrial@gmail.com> wrote:

> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/cbs_h2645.c                | 18 ++++++++++++++++++
>  libavcodec/cbs_h266.h                 | 10 ++++++++++
>  libavcodec/cbs_h266_syntax_template.c | 24 ++++++++++++++++++++++++
>  libavcodec/vvc.h                      |  3 +++
>  4 files changed, 55 insertions(+)
>
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 8dc9ae471d..95da597427 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1059,6 +1059,14 @@ static int
> cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
>          return err;
>
>      switch (unit->type) {
> +    case VVC_DCI_NUT:
> +        {
> +            err = cbs_h266_read_dci(ctx, &gbc, unit->content);
> +
> +            if (err < 0)
> +                return err;
> +        }
> +        break;
>      case VVC_OPI_NUT:
>          {
>              err = cbs_h266_read_opi(ctx, &gbc, unit->content);
> @@ -1601,6 +1609,15 @@ static int
> cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
>      int err;
>
>      switch (unit->type) {
> +    case VVC_DCI_NUT:
> +        {
> +            H266RawDCI *dci = unit->content;
> +
> +            err = cbs_h266_write_dci(ctx, pbc, dci);
> +            if (err < 0)
> +                return err;
> +        }
> +        break;
>      case VVC_OPI_NUT:
>          {
>              H266RawOPI *opi = unit->content;
> @@ -1982,6 +1999,7 @@ static void cbs_h266_free_sei(void *opaque, uint8_t
> *content)
>  }
>
>  static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = {
> +    CBS_UNIT_TYPE_INTERNAL_REF(VVC_DCI_NUT, H266RawDCI,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_OPI_NUT, H266RawOPI,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS,
> extension_data.data),
> diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
> index 693d1ca1fd..87aa2d849d 100644
> --- a/libavcodec/cbs_h266.h
> +++ b/libavcodec/cbs_h266.h
> @@ -241,6 +241,16 @@ typedef struct H266RawOPI {
>      H266RawExtensionData extension_data;
>  } H266RawOPI;
>
> +typedef struct H266RawDCI {
> +    H266RawNALUnitHeader nal_unit_header;
> +
> +    uint8_t dci_reserved_zero_4bits;
> +    uint8_t dci_num_ptls_minus1;
> +    H266RawProfileTierLevel dci_profile_tier_level[VVC_MAX_DCI_PTLS];
> +    uint8_t dci_extension_flag;
> +    H266RawExtensionData extension_data;
> +} H266RawDCI;
> +
>  typedef struct H266RawVPS {
>      H266RawNALUnitHeader nal_unit_header;
>
> diff --git a/libavcodec/cbs_h266_syntax_template.c
> b/libavcodec/cbs_h266_syntax_template.c
> index d9c8e0afbe..4ea29ec789 100644
> --- a/libavcodec/cbs_h266_syntax_template.c
> +++ b/libavcodec/cbs_h266_syntax_template.c
> @@ -650,6 +650,30 @@ static int FUNC(opi)(CodedBitstreamContext *ctx,
> RWContext *rw,
>      return 0;
>  }
>
> +static int FUNC(dci)(CodedBitstreamContext *ctx, RWContext *rw,
> +                     H266RawDCI *current)
> +{
> +    int err, i;
> +
> +    HEADER("Decoding capability information");
> +
> +    CHECK(FUNC(nal_unit_header)(ctx, rw,
> +                                &current->nal_unit_header, VVC_DCI_NUT));
> +
> +    ub(4, dci_reserved_zero_4bits);
> +    ub(4, dci_num_ptls_minus1);
> +    for (i = 0; i <= current->dci_num_ptls_minus1; i++)
> +        CHECK(FUNC(profile_tier_level)(ctx, rw,
> +                                       current->dci_profile_tier_level +
> i, 1, 0));
> +
> +    flag(dci_extension_flag);
> +    if (current->dci_extension_flag)
> +        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
> +    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
> +
> +    return 0;
> +}
> +
>  static int FUNC(vps) (CodedBitstreamContext *ctx, RWContext *rw,
>                       H266RawVPS *current)
>  {
> diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
> index 099d2fc2ad..eda1b40eef 100644
> --- a/libavcodec/vvc.h
> +++ b/libavcodec/vvc.h
> @@ -76,6 +76,9 @@ enum {
>      //7.4.3.3 The value of vps_max_sublayers_minus1 shall be in the
> range of 0 to 6, inclusive
>      VVC_MAX_SUBLAYERS = 7,
>
> +    //7.3.2.1 dci_num_ptls_minus1 is u(4)
> +    VVC_MAX_DCI_PTLS = 16,
> +
>      //7.4.3.3 vps_num_ptls_minus1 is u(8)
>      VVC_MAX_PTLS = 256,
>
> --
> 2.41.0
>
> _______________________________________________
> 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".
>
LGTM.
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 3/4] avcodec/cbs_h266: add support for Adaptation parameter set NALU type
  2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 3/4] avcodec/cbs_h266: add support for Adaptation parameter set " James Almer
@ 2023-07-05 14:29   ` Nuo Mi
  2023-07-05 18:11     ` [FFmpeg-devel] [PATCH v2 " James Almer
                       ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Nuo Mi @ 2023-07-05 14:29 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Mon, Jul 3, 2023 at 7:28 AM James Almer <jamrial@gmail.com> wrote:

> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/cbs_h2645.c                |  21 +++
>  libavcodec/cbs_h266.h                 |  46 ++++++
>  libavcodec/cbs_h266_syntax_template.c | 201 ++++++++++++++++++++++++++
>  libavcodec/vvc.h                      |  10 ++
>  4 files changed, 278 insertions(+)
>
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 95da597427..34c5d1d372 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1116,6 +1116,16 @@ static int
> cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
>          }
>          break;
>
> +    case VVC_PREFIX_APS_NUT:
> +    case VVC_SUFFIX_APS_NUT:
> +        {
> +            err = cbs_h266_read_aps(ctx, &gbc, unit->content,
> +                                    unit->type == VVC_PREFIX_APS_NUT);
> +
> +            if (err < 0)
> +                return err;
> +        }
> +        break;
>      case VVC_PH_NUT:
>          {
>              H266RawPH *ph = unit->content;
> @@ -1668,6 +1678,15 @@ static int
> cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
>          }
>          break;
>
> +    case VVC_PREFIX_APS_NUT:
> +    case VVC_SUFFIX_APS_NUT:
> +        {
> +            err = cbs_h266_write_aps(ctx, pbc, unit->content,
> +                                     unit->type == VVC_PREFIX_APS_NUT);
> +            if (err < 0)
> +                return err;
> +        }
> +        break;
>      case VVC_PH_NUT:
>          {
>              H266RawPH *ph = unit->content;
> @@ -2004,6 +2023,8 @@ static const CodedBitstreamUnitTypeDescriptor
> cbs_h266_unit_types[] = {
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS,
> extension_data.data),
> +    CBS_UNIT_TYPE_INTERNAL_REF(VVC_PREFIX_APS_NUT, H266RawAPS,
> extension_data.data),
> +    CBS_UNIT_TYPE_INTERNAL_REF(VVC_SUFFIX_APS_NUT, H266RawAPS,
> extension_data.data),
>
>      CBS_UNIT_TYPE_POD(VVC_PH_NUT , H266RawPH),
>      CBS_UNIT_TYPE_POD(VVC_AUD_NUT, H266RawAUD),
> diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
> index 87aa2d849d..d068ffa87a 100644
> --- a/libavcodec/cbs_h266.h
> +++ b/libavcodec/cbs_h266.h
> @@ -576,6 +576,52 @@ typedef struct H266RawPPS {
>      uint16_t sub_pic_id_val[VVC_MAX_SLICES];
>  } H266RawPPS;
>
> +typedef struct H266RawAPS {
> +    H266RawNALUnitHeader nal_unit_header;
> +    uint8_t aps_params_type;
> +    uint8_t aps_adaptation_parameter_set_id;
> +    uint8_t aps_chroma_present_flag;
> +
> +    uint8_t alf_luma_filter_signal_flag;
> +    uint8_t alf_chroma_filter_signal_flag;
> +    uint8_t alf_cc_cb_filter_signal_flag;
> +    uint8_t alf_cc_cr_filter_signal_flag;
> +    uint8_t alf_luma_clip_flag;
> +    uint8_t alf_luma_num_filters_signalled_minus1;
> +    uint8_t alf_luma_coeff_delta_idx[VVC_NUM_ALF_FILTERS];
> +    uint8_t alf_luma_coeff_abs[VVC_NUM_ALF_FILTERS][12];
> +    uint8_t alf_luma_coeff_sign[VVC_NUM_ALF_FILTERS][12];
> +    uint8_t alf_luma_clip_idx[VVC_NUM_ALF_FILTERS][12];
> +    uint8_t alf_chroma_clip_flag;
> +    uint8_t alf_chroma_num_alt_filters_minus1;
> +    uint8_t alf_chroma_coeff_abs[8][6];
> +    uint8_t alf_chroma_coeff_sign[8][6];
> +    uint8_t alf_chroma_clip_idx[8][6];
> +    uint8_t alf_cc_cb_filters_signalled_minus1;
> +    uint8_t alf_cc_cb_mapped_coeff_abs[4][7];
> +    uint8_t alf_cc_cb_coeff_sign[4][7];
> +    uint8_t alf_cc_cr_filters_signalled_minus1;
> +    uint8_t alf_cc_cr_mapped_coeff_abs[4][7];
> +    uint8_t alf_cc_cr_coeff_sign[4][7];
> +
> +    uint8_t scaling_list_copy_mode_flag[28];
> +    uint8_t scaling_list_pred_mode_flag[28];
> +    uint8_t scaling_list_pred_id_delta[28];
> +    int8_t  scaling_list_dc_coef[28];
> +    int8_t  scaling_list_delta_coef[28][64];
> +
> +    uint8_t lmcs_min_bin_idx;
> +    uint8_t lmcs_delta_max_bin_idx;
> +    uint8_t lmcs_delta_cw_prec_minus1;
> +    uint16_t lmcs_delta_abs_cw[16];
> +    uint8_t lmcs_delta_sign_cw_flag[16];
> +    uint8_t lmcs_delta_abs_crs;
> +    uint8_t lmcs_delta_sign_crs_flag;
> +
> +    uint8_t aps_extension_flag;
> +    H266RawExtensionData extension_data;
> +} H266RawAPS;
> +
>  typedef struct H266RawAUD {
>      H266RawNALUnitHeader nal_unit_header;
>      uint8_t aud_irap_or_gdr_flag;
> diff --git a/libavcodec/cbs_h266_syntax_template.c
> b/libavcodec/cbs_h266_syntax_template.c
> index 4ea29ec789..61a7237978 100644
> --- a/libavcodec/cbs_h266_syntax_template.c
> +++ b/libavcodec/cbs_h266_syntax_template.c
> @@ -2183,6 +2183,207 @@ static int FUNC(pps) (CodedBitstreamContext *ctx,
> RWContext *rw,
>      return 0;
>  }
>
> +static int FUNC(alf_data)(CodedBitstreamContext *ctx, RWContext *rw,
> +                          H266RawAPS *current)
> +{
> +    int err, j, k;
> +
> +    flag(alf_luma_filter_signal_flag);
> +
> +    if (current->aps_chroma_present_flag) {
> +        flag(alf_chroma_filter_signal_flag);
> +        flag(alf_cc_cb_filter_signal_flag);
> +        flag(alf_cc_cr_filter_signal_flag);
> +    } else {
> +        infer(alf_chroma_filter_signal_flag, 0);
> +        infer(alf_cc_cb_filter_signal_flag, 0);
> +        infer(alf_cc_cr_filter_signal_flag, 0);
> +    }
> +
> +    if (current->alf_luma_filter_signal_flag) {
> +        flag(alf_luma_clip_flag);
> +        ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS
> - 1);
> +        if (current->alf_luma_num_filters_signalled_minus1 > 0) {
> +            unsigned int bits =
> av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
> +            for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS;
> filt_idx++)
> +                us(bits, alf_luma_coeff_delta_idx[filt_idx],
> +                   0, current->alf_luma_num_filters_signalled_minus1,
> +                   1, filt_idx);
> +        }
> +        for (int sf_idx = 0; sf_idx <=
> current->alf_luma_num_filters_signalled_minus1; sf_idx++)
> +            for (j = 0; j < 12; j++) {
> +                ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
> +                if (current->alf_luma_coeff_abs[sf_idx][j])
> +                    ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
> +                else
> +                    infer(alf_luma_coeff_sign[sf_idx][j], 0);
> +            }
> +        if (current->alf_luma_clip_flag)
> +            for (int sf_idx = 0; sf_idx <=
> current->alf_luma_num_filters_signalled_minus1; sf_idx++)
> +                for (j = 0; j < 12; j++)
> +                    ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
>
need to infer alf_luma_clip_idx

> +    }
> +
> +    if (current->alf_chroma_filter_signal_flag) {
> +        flag(alf_chroma_clip_flag);
> +        ue(alf_chroma_num_alt_filters_minus1, 0, 7);
> +        for (int alt_idx = 0; alt_idx <=
> current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
> +            for (j = 0; j < 6; j++) {
> +                ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx,
> j);
> +                if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
> +                    ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx,
> j);
> +                else
> +                    infer(alf_chroma_coeff_sign[alt_idx][j], 0);
> +            }
> +            if (current->alf_chroma_clip_flag)
> +                for(j = 0; j < 6; j++)
> +                    ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx,
> j);
>
need to infer alf_chroma_clip_idx

> +        }
> +    }
>
need to infer alf_luma_clip_idx

> +
> +    if (current->alf_cc_cb_filter_signal_flag) {
> +        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
> +        for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1;
> k++) {
> +            for (j = 0; j < 7; j++) {
> +                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
> +                if (current->alf_cc_cb_mapped_coeff_abs[k][j])
> +                    ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
> +                else
> +                    infer(alf_cc_cb_coeff_sign[k][j], 0);
> +            }
> +        }
> +    }
>
need to infer  alf_cc_cb_mapped_coeff_abs and alf_cc_cb_coeff_sign

> +
> +    if (current->alf_cc_cr_filter_signal_flag) {
> +        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
> +        for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1;
> k++) {
> +            for (j = 0; j < 7; j++) {
> +                ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
> +                if (current->alf_cc_cr_mapped_coeff_abs[k][j])
> +                    ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
> +                else
> +                    infer(alf_cc_cr_coeff_sign[k][j], 0);
> +            }
> +        }
> +    }
>
need to infer alf_cc_cr_mapped coeff_abs and alf_cc_cr_coeff_sign


> +
> +    return 0;
> +}
> +
> +static int FUNC(lmcs_data)(CodedBitstreamContext *ctx, RWContext *rw,
> +                           H266RawAPS *current)
> +{
> +    int err, i, lmcs_max_bin_idx;
> +
> +    ue(lmcs_min_bin_idx, 0, 15);
> +    ue(lmcs_delta_max_bin_idx, 0, 15);
> +    ue(lmcs_delta_cw_prec_minus1, 0, 14);
> +
> +    lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
> +
> +    if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
> +        return AVERROR_INVALIDDATA;
> +
> +    for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
> +        ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i],
> 1, i);
> +        if (current->lmcs_delta_abs_cw[i] > 0)
> +            flags(lmcs_delta_sign_cw_flag[i], 1, i);
> +        else
> +            infer(lmcs_delta_sign_cw_flag[i], 0);
> +    }
> +
> +    if (current->aps_chroma_present_flag) {
> +        ub(3, lmcs_delta_abs_crs);
> +        if (current->lmcs_delta_abs_crs > 0)
> +            flag(lmcs_delta_sign_crs_flag);
> +        else
> +            infer(lmcs_delta_sign_crs_flag, 0);
> +    } else {
> +        infer(lmcs_delta_abs_crs, 0);
> +        infer(lmcs_delta_sign_crs_flag, 0);
> +    }
> +
> +    return 0;
> +}
> +
> +static int FUNC(scaling_list_data)(CodedBitstreamContext *ctx, RWContext
> *rw,
> +                                   H266RawAPS *current)
> +{
> +    // 7.4.3.4, deriving DiagScanOrder
> +    static const uint8_t diag_scan_order[64][2] = {
> +        { 0,  0, }, { 0,  1, }, { 1,  0, }, { 0,  2, }, { 1,  1, }, { 2,
> 0, }, { 0,  3, }, { 1,  2, },
> +        { 2,  1, }, { 3,  0, }, { 0,  4, }, { 1,  3, }, { 2,  2, }, { 3,
> 1, }, { 4,  0, }, { 0,  5, },
> +        { 1,  4, }, { 2,  3, }, { 3,  2, }, { 4,  1, }, { 5,  0, }, { 0,
> 6, }, { 1,  5, }, { 2,  4, },
> +        { 3,  3, }, { 4,  2, }, { 5,  1, }, { 6,  0, }, { 0,  7, }, { 1,
> 6, }, { 2,  5, }, { 3,  4, },
> +        { 4,  3, }, { 5,  2, }, { 6,  1, }, { 7,  0, }, { 1,  7, }, { 2,
> 6, }, { 3,  5, }, { 4,  4, },
> +        { 5,  3, }, { 6,  2, }, { 7,  1, }, { 2,  7, }, { 3,  6, }, { 4,
> 5, }, { 5,  4, }, { 6,  3, },
> +        { 7,  2, }, { 3,  7, }, { 4,  6, }, { 5,  5, }, { 6,  4, }, { 7,
> 3, }, { 4,  7, }, { 5,  6, },
> +        { 6,  5, }, { 7,  4, }, { 5,  7, }, { 6,  6, }, { 7,  5, }, { 6,
> 7, }, { 7,  6, }, { 7,  7, }, };
> +    int err;
> +
> +    for (int id = 0; id < 28; id ++) {
> +        if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
> +            flags(scaling_list_copy_mode_flag[id], 1, id);
> +            if (!current->scaling_list_copy_mode_flag[id])
> +                flags(scaling_list_pred_mode_flag[id], 1, id);
>
need to infer scaling_list_pred_mode_flag
 +            if ((current->scaling_list_copy_mode_flag[id] ||

> +                 current->scaling_list_pred_mode_flag[id]) &&
> +                 id != 0 && id != 2 && id != 8) {
> +                int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) :
> (id - 8));
> +                ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1,
> id);
> +            }
> +            if (!current->scaling_list_copy_mode_flag[id]) {
> +                int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
> +                if (id > 13) {
> +                    int idx = id - 14;
> +                    ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
> +                } else
> +                    infer(scaling_list_dc_coef[id], 0);
> +                for (int i = 0; i < matrix_size * matrix_size; i++) {
> +                    int x = diag_scan_order[i][0];
> +                    int y = diag_scan_order[i][1];
> +                    if (!(id > 25 && x >= 4 && y >= 4))
> +                        ses(scaling_list_delta_coef[id][i], -128, 127, 2,
> id, i);
> +                }
> +            } else
> +                infer(scaling_list_dc_coef[id], 0);
> +        }
>
need to infer scaling_list_copy_mode_flag


> +    }
> +
> +    return 0;
> +}
> +
> +static int FUNC(aps)(CodedBitstreamContext *ctx, RWContext *rw,
> +                     H266RawAPS *current, int prefix)
> +{
> +    int err;
> +
> +    if (prefix)
> +        HEADER("Prefix Adaptation parameter set");
> +    else
> +        HEADER("Suffix Adaptation parameter set");
> +
> +    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
> +                                prefix ? VVC_PREFIX_APS_NUT
> +                                       : VVC_SUFFIX_APS_NUT));
> +
> +    ub(3, aps_params_type);
> +    ub(5, aps_adaptation_parameter_set_id);
> +    flag(aps_chroma_present_flag);
> +    if (current->aps_params_type == VVC_ASP_TYPE_ALF)
> +        CHECK(FUNC(alf_data)(ctx, rw, current));
> +    else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
> +        CHECK(FUNC(lmcs_data)(ctx, rw, current));
> +    else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
> +        CHECK(FUNC(scaling_list_data)(ctx, rw, current));
> +    flag(aps_extension_flag);
> +    if (current->aps_extension_flag)
> +        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
> +    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
> +
> +    return 0;
> +}
> +
>  static int FUNC(aud) (CodedBitstreamContext *ctx, RWContext *rw,
>                       H266RawAUD *current)
>  {
> diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
> index eda1b40eef..49822ecc84 100644
> --- a/libavcodec/vvc.h
> +++ b/libavcodec/vvc.h
> @@ -66,6 +66,12 @@ enum VVCSliceType {
>      VVC_SLICE_TYPE_I = 2,
>  };
>
> +enum VVCAPSType {
> +    VVC_ASP_TYPE_ALF     = 0,
> +    VVC_ASP_TYPE_LMCS    = 1,
> +    VVC_ASP_TYPE_SCALING = 2,
> +};
> +
>  enum {
>      //6.2 we can have 3 sample arrays
>      VVC_MAX_SAMPLE_ARRAYS = 3,
> @@ -95,6 +101,10 @@ enum {
>      // 7.4.4.1: ptl_num_sub_profiles is u(8)
>      VVC_MAX_SUB_PROFILES = 256,
>
> +    // 7.4.3.18: The variable NumAlfFilters specifying the number of
> different adaptive loop
> +    // filters is set equal to 25.
> +    VVC_NUM_ALF_FILTERS = 25,
> +
>      // A.4.2: according to (1577), MaxDpbSize is bounded above by 2 *
> maxDpbPicBuf(8)
>      VVC_MAX_DPB_SIZE = 16,
>
> --
> 2.41.0
>
> _______________________________________________
> 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".
>
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type
  2023-07-02 23:26 [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type James Almer
                   ` (2 preceding siblings ...)
  2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 4/4] fate/cbs: add more VVC tests James Almer
@ 2023-07-05 14:32 ` Nuo Mi
  3 siblings, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2023-07-05 14:32 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Mon, Jul 3, 2023 at 7:28 AM James Almer <jamrial@gmail.com> wrote:

> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/cbs_h2645.c                | 18 ++++++++++++++++++
>  libavcodec/cbs_h266.h                 | 11 +++++++++++
>  libavcodec/cbs_h266_syntax_template.c | 27 +++++++++++++++++++++++++++
>  3 files changed, 56 insertions(+)
>
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 68ccf6a7eb..8dc9ae471d 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1059,6 +1059,14 @@ static int
> cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
>          return err;
>
>      switch (unit->type) {
> +    case VVC_OPI_NUT:
> +        {
> +            err = cbs_h266_read_opi(ctx, &gbc, unit->content);
> +
> +            if (err < 0)
> +                return err;
> +        }
> +        break;
>      case VVC_VPS_NUT:
>          {
>              H266RawVPS *vps = unit->content;
> @@ -1593,6 +1601,15 @@ static int
> cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
>      int err;
>
>      switch (unit->type) {
> +    case VVC_OPI_NUT:
> +        {
> +            H266RawOPI *opi = unit->content;
> +
> +            err = cbs_h266_write_opi(ctx, pbc, opi);
> +            if (err < 0)
> +                return err;
> +        }
> +        break;
>      case VVC_VPS_NUT:
>          {
>              H266RawVPS *vps = unit->content;
> @@ -1965,6 +1982,7 @@ static void cbs_h266_free_sei(void *opaque, uint8_t
> *content)
>  }
>
>  static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = {
> +    CBS_UNIT_TYPE_INTERNAL_REF(VVC_OPI_NUT, H266RawOPI,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS,
> extension_data.data),
> diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
> index e33d08a0f5..693d1ca1fd 100644
> --- a/libavcodec/cbs_h266.h
> +++ b/libavcodec/cbs_h266.h
> @@ -230,6 +230,17 @@ typedef struct H266RawVUI {
>      H266RawExtensionData extension_data;
>  } H266RawVUI;
>
> +typedef struct H266RawOPI {
> +    H266RawNALUnitHeader nal_unit_header;
> +
> +    uint8_t opi_ols_info_present_flag;
> +    uint8_t opi_htid_info_present_flag;
> +    uint16_t opi_ols_idx;
> +    uint8_t opi_htid_plus1;
> +    uint8_t opi_extension_flag;
> +    H266RawExtensionData extension_data;
> +} H266RawOPI;
> +
>  typedef struct H266RawVPS {
>      H266RawNALUnitHeader nal_unit_header;
>
> diff --git a/libavcodec/cbs_h266_syntax_template.c
> b/libavcodec/cbs_h266_syntax_template.c
> index 957735056f..d9c8e0afbe 100644
> --- a/libavcodec/cbs_h266_syntax_template.c
> +++ b/libavcodec/cbs_h266_syntax_template.c
> @@ -623,6 +623,33 @@ static int FUNC(ols_timing_hrd_parameters)
> (CodedBitstreamContext *ctx,
>      return 0;
>  }
>
> +static int FUNC(opi)(CodedBitstreamContext *ctx, RWContext *rw,
> +                     H266RawOPI *current)
> +{
> +    int err;
> +
> +    HEADER("Operating point information");
> +
> +    CHECK(FUNC(nal_unit_header)(ctx, rw,
> +                                &current->nal_unit_header, VVC_OPI_NUT));
> +
> +    flag(opi_ols_info_present_flag);
> +    flag(opi_htid_info_present_flag);
> +
> +    if(current->opi_ols_info_present_flag)
> +        ue(opi_ols_idx, 0, VVC_MAX_TOTAL_NUM_OLSS - 1);
> +
> +    if(current->opi_htid_info_present_flag)
> +        ub(3, opi_htid_plus1);
> +
> +    flag(opi_extension_flag);
> +    if (current->opi_extension_flag)
> +        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
> +    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
> +
> +    return 0;
> +}
> +
>  static int FUNC(vps) (CodedBitstreamContext *ctx, RWContext *rw,
>                       H266RawVPS *current)
>  {
> --
> 2.41.0
>
> LGTM

> _______________________________________________
> 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".
>
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH v2 3/4] avcodec/cbs_h266: add support for Adaptation parameter set NALU type
  2023-07-05 14:29   ` Nuo Mi
@ 2023-07-05 18:11     ` James Almer
  2023-07-05 18:33     ` [FFmpeg-devel] [PATCH v3] " James Almer
  2023-07-05 18:36     ` [FFmpeg-devel] [PATCH v4] " James Almer
  2 siblings, 0 replies; 13+ messages in thread
From: James Almer @ 2023-07-05 18:11 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_h2645.c                |  21 +++
 libavcodec/cbs_h266.h                 |  46 ++++++
 libavcodec/cbs_h266_syntax_template.c | 230 ++++++++++++++++++++++++++
 libavcodec/vvc.h                      |  10 ++
 4 files changed, 307 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 95da597427..34c5d1d372 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1116,6 +1116,16 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
         }
         break;
 
+    case VVC_PREFIX_APS_NUT:
+    case VVC_SUFFIX_APS_NUT:
+        {
+            err = cbs_h266_read_aps(ctx, &gbc, unit->content,
+                                    unit->type == VVC_PREFIX_APS_NUT);
+
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_PH_NUT:
         {
             H266RawPH *ph = unit->content;
@@ -1668,6 +1678,15 @@ static int cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
         }
         break;
 
+    case VVC_PREFIX_APS_NUT:
+    case VVC_SUFFIX_APS_NUT:
+        {
+            err = cbs_h266_write_aps(ctx, pbc, unit->content,
+                                     unit->type == VVC_PREFIX_APS_NUT);
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_PH_NUT:
         {
             H266RawPH *ph = unit->content;
@@ -2004,6 +2023,8 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = {
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_PREFIX_APS_NUT, H266RawAPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_SUFFIX_APS_NUT, H266RawAPS, extension_data.data),
 
     CBS_UNIT_TYPE_POD(VVC_PH_NUT , H266RawPH),
     CBS_UNIT_TYPE_POD(VVC_AUD_NUT, H266RawAUD),
diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index 63af3bacf0..2a7c81ba54 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -578,6 +578,52 @@ typedef struct H266RawPPS {
     uint16_t row_height_val[VVC_MAX_TILE_ROWS];
 } H266RawPPS;
 
+typedef struct H266RawAPS {
+    H266RawNALUnitHeader nal_unit_header;
+    uint8_t aps_params_type;
+    uint8_t aps_adaptation_parameter_set_id;
+    uint8_t aps_chroma_present_flag;
+
+    uint8_t alf_luma_filter_signal_flag;
+    uint8_t alf_chroma_filter_signal_flag;
+    uint8_t alf_cc_cb_filter_signal_flag;
+    uint8_t alf_cc_cr_filter_signal_flag;
+    uint8_t alf_luma_clip_flag;
+    uint8_t alf_luma_num_filters_signalled_minus1;
+    uint8_t alf_luma_coeff_delta_idx[VVC_NUM_ALF_FILTERS];
+    uint8_t alf_luma_coeff_abs[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_luma_coeff_sign[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_luma_clip_idx[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_chroma_clip_flag;
+    uint8_t alf_chroma_num_alt_filters_minus1;
+    uint8_t alf_chroma_coeff_abs[8][6];
+    uint8_t alf_chroma_coeff_sign[8][6];
+    uint8_t alf_chroma_clip_idx[8][6];
+    uint8_t alf_cc_cb_filters_signalled_minus1;
+    uint8_t alf_cc_cb_mapped_coeff_abs[4][7];
+    uint8_t alf_cc_cb_coeff_sign[4][7];
+    uint8_t alf_cc_cr_filters_signalled_minus1;
+    uint8_t alf_cc_cr_mapped_coeff_abs[4][7];
+    uint8_t alf_cc_cr_coeff_sign[4][7];
+
+    uint8_t scaling_list_copy_mode_flag[28];
+    uint8_t scaling_list_pred_mode_flag[28];
+    uint8_t scaling_list_pred_id_delta[28];
+    int8_t  scaling_list_dc_coef[28];
+    int8_t  scaling_list_delta_coef[28][64];
+
+    uint8_t lmcs_min_bin_idx;
+    uint8_t lmcs_delta_max_bin_idx;
+    uint8_t lmcs_delta_cw_prec_minus1;
+    uint16_t lmcs_delta_abs_cw[16];
+    uint8_t lmcs_delta_sign_cw_flag[16];
+    uint8_t lmcs_delta_abs_crs;
+    uint8_t lmcs_delta_sign_crs_flag;
+
+    uint8_t aps_extension_flag;
+    H266RawExtensionData extension_data;
+} H266RawAPS;
+
 typedef struct H266RawAUD {
     H266RawNALUnitHeader nal_unit_header;
     uint8_t aud_irap_or_gdr_flag;
diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c
index e2246cfc1b..d30460e87c 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -2185,6 +2185,236 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+static int FUNC(alf_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                          H266RawAPS *current)
+{
+    int err, j, k;
+
+    flag(alf_luma_filter_signal_flag);
+
+    if (current->aps_chroma_present_flag) {
+        flag(alf_chroma_filter_signal_flag);
+        flag(alf_cc_cb_filter_signal_flag);
+        flag(alf_cc_cr_filter_signal_flag);
+    } else {
+        infer(alf_chroma_filter_signal_flag, 0);
+        infer(alf_cc_cb_filter_signal_flag, 0);
+        infer(alf_cc_cr_filter_signal_flag, 0);
+    }
+
+    if (current->alf_luma_filter_signal_flag) {
+        flag(alf_luma_clip_flag);
+        ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS - 1);
+        if (current->alf_luma_num_filters_signalled_minus1 > 0) {
+            unsigned int bits = av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
+            for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS; filt_idx++)
+                us(bits, alf_luma_coeff_delta_idx[filt_idx],
+                   0, current->alf_luma_num_filters_signalled_minus1,
+                   1, filt_idx);
+        }
+        for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
+            for (j = 0; j < 12; j++) {
+                ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
+                if (current->alf_luma_coeff_abs[sf_idx][j])
+                    ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
+                else
+                    infer(alf_luma_coeff_sign[sf_idx][j], 0);
+            }
+    } else {
+        infer(alf_luma_clip_flag, 0);
+        infer(alf_luma_num_filters_signalled_minus1, 0);
+    }
+    for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
+        for (j = 0; j < 12; j++) {
+            if (current->alf_luma_clip_flag)
+                ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
+            else
+                infer(alf_luma_clip_idx[sf_idx][j], 0);
+        }
+    }
+
+    if (current->alf_chroma_filter_signal_flag) {
+        flag(alf_chroma_clip_flag);
+        ue(alf_chroma_num_alt_filters_minus1, 0, 7);
+    } else {
+        infer(alf_chroma_clip_flag, 0);
+        infer(alf_chroma_num_alt_filters_minus1, 0);
+    }
+    for (int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
+        for (j = 0; j < 6; j++) {
+            if (current->alf_chroma_filter_signal_flag)
+                ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
+            else
+                infer(alf_chroma_coeff_abs[alt_idx][j], 0);
+            if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
+                ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
+            else
+                infer(alf_chroma_coeff_sign[alt_idx][j], 0);
+        }
+        for (j = 0; j < 6; j++) {
+            if (current->alf_chroma_clip_flag)
+                ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
+            else
+                infer(alf_chroma_clip_idx[alt_idx][j], 0);
+        }
+    }
+
+    if (current->alf_cc_cb_filter_signal_flag)
+        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
+    else
+        infer(alf_cc_cb_filters_signalled_minus1, 0);
+    for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
+        for (j = 0; j < 7; j++) {
+            if (current->alf_cc_cb_filter_signal_flag)
+                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
+            else
+                infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
+            if (current->alf_cc_cb_mapped_coeff_abs[k][j])
+                ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
+            else
+                infer(alf_cc_cb_coeff_sign[k][j], 0);
+        }
+    }
+
+    if (current->alf_cc_cr_filter_signal_flag)
+        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
+    else
+        infer(alf_cc_cr_filters_signalled_minus1, 0);
+    for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
+        for (j = 0; j < 7; j++) {
+            if (current->alf_cc_cr_filter_signal_flag)
+                ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
+            else
+                infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
+            if (current->alf_cc_cr_mapped_coeff_abs[k][j])
+                ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
+            else
+                infer(alf_cc_cr_coeff_sign[k][j], 0);
+        }
+    }
+
+    return 0;
+}
+
+static int FUNC(lmcs_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                           H266RawAPS *current)
+{
+    int err, i, lmcs_max_bin_idx;
+
+    ue(lmcs_min_bin_idx, 0, 15);
+    ue(lmcs_delta_max_bin_idx, 0, 15);
+    ue(lmcs_delta_cw_prec_minus1, 0, 14);
+
+    lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
+
+    if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
+        return AVERROR_INVALIDDATA;
+
+    for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
+        ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i], 1, i);
+        if (current->lmcs_delta_abs_cw[i] > 0)
+            flags(lmcs_delta_sign_cw_flag[i], 1, i);
+        else
+            infer(lmcs_delta_sign_cw_flag[i], 0);
+    }
+
+    if (current->aps_chroma_present_flag) {
+        ub(3, lmcs_delta_abs_crs);
+        if (current->lmcs_delta_abs_crs > 0)
+            flag(lmcs_delta_sign_crs_flag);
+        else
+            infer(lmcs_delta_sign_crs_flag, 0);
+    } else {
+        infer(lmcs_delta_abs_crs, 0);
+        infer(lmcs_delta_sign_crs_flag, 0);
+    }
+
+    return 0;
+}
+
+static int FUNC(scaling_list_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                                   H266RawAPS *current)
+{
+    // 7.4.3.4, deriving DiagScanOrder
+    static const uint8_t diag_scan_order[64][2] = {
+        { 0,  0, }, { 0,  1, }, { 1,  0, }, { 0,  2, }, { 1,  1, }, { 2,  0, }, { 0,  3, }, { 1,  2, },
+        { 2,  1, }, { 3,  0, }, { 0,  4, }, { 1,  3, }, { 2,  2, }, { 3,  1, }, { 4,  0, }, { 0,  5, },
+        { 1,  4, }, { 2,  3, }, { 3,  2, }, { 4,  1, }, { 5,  0, }, { 0,  6, }, { 1,  5, }, { 2,  4, },
+        { 3,  3, }, { 4,  2, }, { 5,  1, }, { 6,  0, }, { 0,  7, }, { 1,  6, }, { 2,  5, }, { 3,  4, },
+        { 4,  3, }, { 5,  2, }, { 6,  1, }, { 7,  0, }, { 1,  7, }, { 2,  6, }, { 3,  5, }, { 4,  4, },
+        { 5,  3, }, { 6,  2, }, { 7,  1, }, { 2,  7, }, { 3,  6, }, { 4,  5, }, { 5,  4, }, { 6,  3, },
+        { 7,  2, }, { 3,  7, }, { 4,  6, }, { 5,  5, }, { 6,  4, }, { 7,  3, }, { 4,  7, }, { 5,  6, },
+        { 6,  5, }, { 7,  4, }, { 5,  7, }, { 6,  6, }, { 7,  5, }, { 6,  7, }, { 7,  6, }, { 7,  7, }, };
+    int err;
+
+    for (int id = 0; id < 28; id ++) {
+        if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
+            flags(scaling_list_copy_mode_flag[id], 1, id);
+            if (!current->scaling_list_copy_mode_flag[id])
+                flags(scaling_list_pred_mode_flag[id], 1, id);
+            else
+                infer(scaling_list_pred_mode_flag[id], 0);
+            if ((current->scaling_list_copy_mode_flag[id] ||
+                 current->scaling_list_pred_mode_flag[id]) &&
+                 id != 0 && id != 2 && id != 8) {
+                int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) : (id - 8));
+                ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1, id);
+            }
+            if (!current->scaling_list_copy_mode_flag[id]) {
+                int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
+                if (id > 13) {
+                    int idx = id - 14;
+                    ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
+                } else
+                    infer(scaling_list_dc_coef[id], 0);
+                for (int i = 0; i < matrix_size * matrix_size; i++) {
+                    int x = diag_scan_order[i][0];
+                    int y = diag_scan_order[i][1];
+                    if (!(id > 25 && x >= 4 && y >= 4))
+                        ses(scaling_list_delta_coef[id][i], -128, 127, 2, id, i);
+                }
+            } else
+                infer(scaling_list_dc_coef[id], 0);
+        } else {
+            infer(scaling_list_copy_mode_flag[id], 1);
+            infer(scaling_list_pred_mode_flag[id], 0);
+        }
+    }
+
+    return 0;
+}
+
+static int FUNC(aps)(CodedBitstreamContext *ctx, RWContext *rw,
+                     H266RawAPS *current, int prefix)
+{
+    int err;
+
+    if (prefix)
+        HEADER("Prefix Adaptation parameter set");
+    else
+        HEADER("Suffix Adaptation parameter set");
+
+    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
+                                prefix ? VVC_PREFIX_APS_NUT
+                                       : VVC_SUFFIX_APS_NUT));
+
+    ub(3, aps_params_type);
+    ub(5, aps_adaptation_parameter_set_id);
+    flag(aps_chroma_present_flag);
+    if (current->aps_params_type == VVC_ASP_TYPE_ALF)
+        CHECK(FUNC(alf_data)(ctx, rw, current));
+    else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
+        CHECK(FUNC(lmcs_data)(ctx, rw, current));
+    else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
+        CHECK(FUNC(scaling_list_data)(ctx, rw, current));
+    flag(aps_extension_flag);
+    if (current->aps_extension_flag)
+        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
+    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
+
+    return 0;
+}
+
 static int FUNC(aud) (CodedBitstreamContext *ctx, RWContext *rw,
                      H266RawAUD *current)
 {
diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
index 9fbb4a953c..7d165cdb86 100644
--- a/libavcodec/vvc.h
+++ b/libavcodec/vvc.h
@@ -66,6 +66,12 @@ enum VVCSliceType {
     VVC_SLICE_TYPE_I = 2,
 };
 
+enum VVCAPSType {
+    VVC_ASP_TYPE_ALF     = 0,
+    VVC_ASP_TYPE_LMCS    = 1,
+    VVC_ASP_TYPE_SCALING = 2,
+};
+
 enum {
     //6.2 we can have 3 sample arrays
     VVC_MAX_SAMPLE_ARRAYS = 3,
@@ -95,6 +101,10 @@ enum {
     // 7.4.4.1: ptl_num_sub_profiles is u(8)
     VVC_MAX_SUB_PROFILES = 256,
 
+    // 7.4.3.18: The variable NumAlfFilters specifying the number of different adaptive loop
+    // filters is set equal to 25.
+    VVC_NUM_ALF_FILTERS = 25,
+
     // A.4.2: according to (1577), MaxDpbSize is bounded above by 2 * maxDpbPicBuf(8)
     VVC_MAX_DPB_SIZE = 16,
 
-- 
2.41.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH v3] avcodec/cbs_h266: add support for Adaptation parameter set NALU type
  2023-07-05 14:29   ` Nuo Mi
  2023-07-05 18:11     ` [FFmpeg-devel] [PATCH v2 " James Almer
@ 2023-07-05 18:33     ` James Almer
  2023-07-05 18:36     ` [FFmpeg-devel] [PATCH v4] " James Almer
  2 siblings, 0 replies; 13+ messages in thread
From: James Almer @ 2023-07-05 18:33 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_h2645.c                |  21 +++
 libavcodec/cbs_h266.h                 |  46 ++++++
 libavcodec/cbs_h266_syntax_template.c | 230 ++++++++++++++++++++++++++
 libavcodec/vvc.h                      |  10 ++
 4 files changed, 307 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 95da597427..34c5d1d372 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1116,6 +1116,16 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
         }
         break;
 
+    case VVC_PREFIX_APS_NUT:
+    case VVC_SUFFIX_APS_NUT:
+        {
+            err = cbs_h266_read_aps(ctx, &gbc, unit->content,
+                                    unit->type == VVC_PREFIX_APS_NUT);
+
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_PH_NUT:
         {
             H266RawPH *ph = unit->content;
@@ -1668,6 +1678,15 @@ static int cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
         }
         break;
 
+    case VVC_PREFIX_APS_NUT:
+    case VVC_SUFFIX_APS_NUT:
+        {
+            err = cbs_h266_write_aps(ctx, pbc, unit->content,
+                                     unit->type == VVC_PREFIX_APS_NUT);
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_PH_NUT:
         {
             H266RawPH *ph = unit->content;
@@ -2004,6 +2023,8 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = {
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_PREFIX_APS_NUT, H266RawAPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_SUFFIX_APS_NUT, H266RawAPS, extension_data.data),
 
     CBS_UNIT_TYPE_POD(VVC_PH_NUT , H266RawPH),
     CBS_UNIT_TYPE_POD(VVC_AUD_NUT, H266RawAUD),
diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index 63af3bacf0..2a7c81ba54 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -578,6 +578,52 @@ typedef struct H266RawPPS {
     uint16_t row_height_val[VVC_MAX_TILE_ROWS];
 } H266RawPPS;
 
+typedef struct H266RawAPS {
+    H266RawNALUnitHeader nal_unit_header;
+    uint8_t aps_params_type;
+    uint8_t aps_adaptation_parameter_set_id;
+    uint8_t aps_chroma_present_flag;
+
+    uint8_t alf_luma_filter_signal_flag;
+    uint8_t alf_chroma_filter_signal_flag;
+    uint8_t alf_cc_cb_filter_signal_flag;
+    uint8_t alf_cc_cr_filter_signal_flag;
+    uint8_t alf_luma_clip_flag;
+    uint8_t alf_luma_num_filters_signalled_minus1;
+    uint8_t alf_luma_coeff_delta_idx[VVC_NUM_ALF_FILTERS];
+    uint8_t alf_luma_coeff_abs[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_luma_coeff_sign[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_luma_clip_idx[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_chroma_clip_flag;
+    uint8_t alf_chroma_num_alt_filters_minus1;
+    uint8_t alf_chroma_coeff_abs[8][6];
+    uint8_t alf_chroma_coeff_sign[8][6];
+    uint8_t alf_chroma_clip_idx[8][6];
+    uint8_t alf_cc_cb_filters_signalled_minus1;
+    uint8_t alf_cc_cb_mapped_coeff_abs[4][7];
+    uint8_t alf_cc_cb_coeff_sign[4][7];
+    uint8_t alf_cc_cr_filters_signalled_minus1;
+    uint8_t alf_cc_cr_mapped_coeff_abs[4][7];
+    uint8_t alf_cc_cr_coeff_sign[4][7];
+
+    uint8_t scaling_list_copy_mode_flag[28];
+    uint8_t scaling_list_pred_mode_flag[28];
+    uint8_t scaling_list_pred_id_delta[28];
+    int8_t  scaling_list_dc_coef[28];
+    int8_t  scaling_list_delta_coef[28][64];
+
+    uint8_t lmcs_min_bin_idx;
+    uint8_t lmcs_delta_max_bin_idx;
+    uint8_t lmcs_delta_cw_prec_minus1;
+    uint16_t lmcs_delta_abs_cw[16];
+    uint8_t lmcs_delta_sign_cw_flag[16];
+    uint8_t lmcs_delta_abs_crs;
+    uint8_t lmcs_delta_sign_crs_flag;
+
+    uint8_t aps_extension_flag;
+    H266RawExtensionData extension_data;
+} H266RawAPS;
+
 typedef struct H266RawAUD {
     H266RawNALUnitHeader nal_unit_header;
     uint8_t aud_irap_or_gdr_flag;
diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c
index e2246cfc1b..d30460e87c 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -2185,6 +2185,236 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+static int FUNC(alf_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                          H266RawAPS *current)
+{
+    int err, j, k;
+
+    flag(alf_luma_filter_signal_flag);
+
+    if (current->aps_chroma_present_flag) {
+        flag(alf_chroma_filter_signal_flag);
+        flag(alf_cc_cb_filter_signal_flag);
+        flag(alf_cc_cr_filter_signal_flag);
+    } else {
+        infer(alf_chroma_filter_signal_flag, 0);
+        infer(alf_cc_cb_filter_signal_flag, 0);
+        infer(alf_cc_cr_filter_signal_flag, 0);
+    }
+
+    if (current->alf_luma_filter_signal_flag) {
+        flag(alf_luma_clip_flag);
+        ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS - 1);
+        if (current->alf_luma_num_filters_signalled_minus1 > 0) {
+            unsigned int bits = av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
+            for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS; filt_idx++)
+                us(bits, alf_luma_coeff_delta_idx[filt_idx],
+                   0, current->alf_luma_num_filters_signalled_minus1,
+                   1, filt_idx);
+        }
+        for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
+            for (j = 0; j < 12; j++) {
+                ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
+                if (current->alf_luma_coeff_abs[sf_idx][j])
+                    ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
+                else
+                    infer(alf_luma_coeff_sign[sf_idx][j], 0);
+            }
+    } else {
+        infer(alf_luma_clip_flag, 0);
+        infer(alf_luma_num_filters_signalled_minus1, 0);
+    }
+    for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
+        for (j = 0; j < 12; j++) {
+            if (current->alf_luma_clip_flag)
+                ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
+            else
+                infer(alf_luma_clip_idx[sf_idx][j], 0);
+        }
+    }
+
+    if (current->alf_chroma_filter_signal_flag) {
+        flag(alf_chroma_clip_flag);
+        ue(alf_chroma_num_alt_filters_minus1, 0, 7);
+    } else {
+        infer(alf_chroma_clip_flag, 0);
+        infer(alf_chroma_num_alt_filters_minus1, 0);
+    }
+    for (int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
+        for (j = 0; j < 6; j++) {
+            if (current->alf_chroma_filter_signal_flag)
+                ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
+            else
+                infer(alf_chroma_coeff_abs[alt_idx][j], 0);
+            if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
+                ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
+            else
+                infer(alf_chroma_coeff_sign[alt_idx][j], 0);
+        }
+        for (j = 0; j < 6; j++) {
+            if (current->alf_chroma_clip_flag)
+                ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
+            else
+                infer(alf_chroma_clip_idx[alt_idx][j], 0);
+        }
+    }
+
+    if (current->alf_cc_cb_filter_signal_flag)
+        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
+    else
+        infer(alf_cc_cb_filters_signalled_minus1, 0);
+    for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
+        for (j = 0; j < 7; j++) {
+            if (current->alf_cc_cb_filter_signal_flag)
+                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
+            else
+                infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
+            if (current->alf_cc_cb_mapped_coeff_abs[k][j])
+                ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
+            else
+                infer(alf_cc_cb_coeff_sign[k][j], 0);
+        }
+    }
+
+    if (current->alf_cc_cr_filter_signal_flag)
+        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
+    else
+        infer(alf_cc_cr_filters_signalled_minus1, 0);
+    for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
+        for (j = 0; j < 7; j++) {
+            if (current->alf_cc_cr_filter_signal_flag)
+                ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
+            else
+                infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
+            if (current->alf_cc_cr_mapped_coeff_abs[k][j])
+                ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
+            else
+                infer(alf_cc_cr_coeff_sign[k][j], 0);
+        }
+    }
+
+    return 0;
+}
+
+static int FUNC(lmcs_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                           H266RawAPS *current)
+{
+    int err, i, lmcs_max_bin_idx;
+
+    ue(lmcs_min_bin_idx, 0, 15);
+    ue(lmcs_delta_max_bin_idx, 0, 15);
+    ue(lmcs_delta_cw_prec_minus1, 0, 14);
+
+    lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
+
+    if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
+        return AVERROR_INVALIDDATA;
+
+    for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
+        ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i], 1, i);
+        if (current->lmcs_delta_abs_cw[i] > 0)
+            flags(lmcs_delta_sign_cw_flag[i], 1, i);
+        else
+            infer(lmcs_delta_sign_cw_flag[i], 0);
+    }
+
+    if (current->aps_chroma_present_flag) {
+        ub(3, lmcs_delta_abs_crs);
+        if (current->lmcs_delta_abs_crs > 0)
+            flag(lmcs_delta_sign_crs_flag);
+        else
+            infer(lmcs_delta_sign_crs_flag, 0);
+    } else {
+        infer(lmcs_delta_abs_crs, 0);
+        infer(lmcs_delta_sign_crs_flag, 0);
+    }
+
+    return 0;
+}
+
+static int FUNC(scaling_list_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                                   H266RawAPS *current)
+{
+    // 7.4.3.4, deriving DiagScanOrder
+    static const uint8_t diag_scan_order[64][2] = {
+        { 0,  0, }, { 0,  1, }, { 1,  0, }, { 0,  2, }, { 1,  1, }, { 2,  0, }, { 0,  3, }, { 1,  2, },
+        { 2,  1, }, { 3,  0, }, { 0,  4, }, { 1,  3, }, { 2,  2, }, { 3,  1, }, { 4,  0, }, { 0,  5, },
+        { 1,  4, }, { 2,  3, }, { 3,  2, }, { 4,  1, }, { 5,  0, }, { 0,  6, }, { 1,  5, }, { 2,  4, },
+        { 3,  3, }, { 4,  2, }, { 5,  1, }, { 6,  0, }, { 0,  7, }, { 1,  6, }, { 2,  5, }, { 3,  4, },
+        { 4,  3, }, { 5,  2, }, { 6,  1, }, { 7,  0, }, { 1,  7, }, { 2,  6, }, { 3,  5, }, { 4,  4, },
+        { 5,  3, }, { 6,  2, }, { 7,  1, }, { 2,  7, }, { 3,  6, }, { 4,  5, }, { 5,  4, }, { 6,  3, },
+        { 7,  2, }, { 3,  7, }, { 4,  6, }, { 5,  5, }, { 6,  4, }, { 7,  3, }, { 4,  7, }, { 5,  6, },
+        { 6,  5, }, { 7,  4, }, { 5,  7, }, { 6,  6, }, { 7,  5, }, { 6,  7, }, { 7,  6, }, { 7,  7, }, };
+    int err;
+
+    for (int id = 0; id < 28; id ++) {
+        if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
+            flags(scaling_list_copy_mode_flag[id], 1, id);
+            if (!current->scaling_list_copy_mode_flag[id])
+                flags(scaling_list_pred_mode_flag[id], 1, id);
+            else
+                infer(scaling_list_pred_mode_flag[id], 0);
+            if ((current->scaling_list_copy_mode_flag[id] ||
+                 current->scaling_list_pred_mode_flag[id]) &&
+                 id != 0 && id != 2 && id != 8) {
+                int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) : (id - 8));
+                ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1, id);
+            }
+            if (!current->scaling_list_copy_mode_flag[id]) {
+                int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
+                if (id > 13) {
+                    int idx = id - 14;
+                    ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
+                } else
+                    infer(scaling_list_dc_coef[id], 0);
+                for (int i = 0; i < matrix_size * matrix_size; i++) {
+                    int x = diag_scan_order[i][0];
+                    int y = diag_scan_order[i][1];
+                    if (!(id > 25 && x >= 4 && y >= 4))
+                        ses(scaling_list_delta_coef[id][i], -128, 127, 2, id, i);
+                }
+            } else
+                infer(scaling_list_dc_coef[id], 0);
+        } else {
+            infer(scaling_list_copy_mode_flag[id], 1);
+            infer(scaling_list_pred_mode_flag[id], 0);
+        }
+    }
+
+    return 0;
+}
+
+static int FUNC(aps)(CodedBitstreamContext *ctx, RWContext *rw,
+                     H266RawAPS *current, int prefix)
+{
+    int err;
+
+    if (prefix)
+        HEADER("Prefix Adaptation parameter set");
+    else
+        HEADER("Suffix Adaptation parameter set");
+
+    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
+                                prefix ? VVC_PREFIX_APS_NUT
+                                       : VVC_SUFFIX_APS_NUT));
+
+    ub(3, aps_params_type);
+    ub(5, aps_adaptation_parameter_set_id);
+    flag(aps_chroma_present_flag);
+    if (current->aps_params_type == VVC_ASP_TYPE_ALF)
+        CHECK(FUNC(alf_data)(ctx, rw, current));
+    else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
+        CHECK(FUNC(lmcs_data)(ctx, rw, current));
+    else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
+        CHECK(FUNC(scaling_list_data)(ctx, rw, current));
+    flag(aps_extension_flag);
+    if (current->aps_extension_flag)
+        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
+    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
+
+    return 0;
+}
+
 static int FUNC(aud) (CodedBitstreamContext *ctx, RWContext *rw,
                      H266RawAUD *current)
 {
diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
index 9fbb4a953c..7d165cdb86 100644
--- a/libavcodec/vvc.h
+++ b/libavcodec/vvc.h
@@ -66,6 +66,12 @@ enum VVCSliceType {
     VVC_SLICE_TYPE_I = 2,
 };
 
+enum VVCAPSType {
+    VVC_ASP_TYPE_ALF     = 0,
+    VVC_ASP_TYPE_LMCS    = 1,
+    VVC_ASP_TYPE_SCALING = 2,
+};
+
 enum {
     //6.2 we can have 3 sample arrays
     VVC_MAX_SAMPLE_ARRAYS = 3,
@@ -95,6 +101,10 @@ enum {
     // 7.4.4.1: ptl_num_sub_profiles is u(8)
     VVC_MAX_SUB_PROFILES = 256,
 
+    // 7.4.3.18: The variable NumAlfFilters specifying the number of different adaptive loop
+    // filters is set equal to 25.
+    VVC_NUM_ALF_FILTERS = 25,
+
     // A.4.2: according to (1577), MaxDpbSize is bounded above by 2 * maxDpbPicBuf(8)
     VVC_MAX_DPB_SIZE = 16,
 
-- 
2.41.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [FFmpeg-devel] [PATCH v4] avcodec/cbs_h266: add support for Adaptation parameter set NALU type
  2023-07-05 14:29   ` Nuo Mi
  2023-07-05 18:11     ` [FFmpeg-devel] [PATCH v2 " James Almer
  2023-07-05 18:33     ` [FFmpeg-devel] [PATCH v3] " James Almer
@ 2023-07-05 18:36     ` James Almer
  2023-07-06  0:41       ` Nuo Mi
  2 siblings, 1 reply; 13+ messages in thread
From: James Almer @ 2023-07-05 18:36 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
v3 was mistakenly sent without the amended changes, so it's the
same as v2.

 libavcodec/cbs_h2645.c                |  21 +++
 libavcodec/cbs_h266.h                 |  46 +++++
 libavcodec/cbs_h266_syntax_template.c | 231 ++++++++++++++++++++++++++
 libavcodec/vvc.h                      |  10 ++
 4 files changed, 308 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 95da597427..34c5d1d372 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1116,6 +1116,16 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
         }
         break;
 
+    case VVC_PREFIX_APS_NUT:
+    case VVC_SUFFIX_APS_NUT:
+        {
+            err = cbs_h266_read_aps(ctx, &gbc, unit->content,
+                                    unit->type == VVC_PREFIX_APS_NUT);
+
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_PH_NUT:
         {
             H266RawPH *ph = unit->content;
@@ -1668,6 +1678,15 @@ static int cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
         }
         break;
 
+    case VVC_PREFIX_APS_NUT:
+    case VVC_SUFFIX_APS_NUT:
+        {
+            err = cbs_h266_write_aps(ctx, pbc, unit->content,
+                                     unit->type == VVC_PREFIX_APS_NUT);
+            if (err < 0)
+                return err;
+        }
+        break;
     case VVC_PH_NUT:
         {
             H266RawPH *ph = unit->content;
@@ -2004,6 +2023,8 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = {
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS, extension_data.data),
     CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_PREFIX_APS_NUT, H266RawAPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(VVC_SUFFIX_APS_NUT, H266RawAPS, extension_data.data),
 
     CBS_UNIT_TYPE_POD(VVC_PH_NUT , H266RawPH),
     CBS_UNIT_TYPE_POD(VVC_AUD_NUT, H266RawAUD),
diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index 63af3bacf0..08cae68036 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -578,6 +578,52 @@ typedef struct H266RawPPS {
     uint16_t row_height_val[VVC_MAX_TILE_ROWS];
 } H266RawPPS;
 
+typedef struct H266RawAPS {
+    H266RawNALUnitHeader nal_unit_header;
+    uint8_t aps_params_type;
+    uint8_t aps_adaptation_parameter_set_id;
+    uint8_t aps_chroma_present_flag;
+
+    uint8_t alf_luma_filter_signal_flag;
+    uint8_t alf_chroma_filter_signal_flag;
+    uint8_t alf_cc_cb_filter_signal_flag;
+    uint8_t alf_cc_cr_filter_signal_flag;
+    uint8_t alf_luma_clip_flag;
+    uint8_t alf_luma_num_filters_signalled_minus1;
+    uint8_t alf_luma_coeff_delta_idx[VVC_NUM_ALF_FILTERS];
+    uint8_t alf_luma_coeff_abs[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_luma_coeff_sign[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_luma_clip_idx[VVC_NUM_ALF_FILTERS][12];
+    uint8_t alf_chroma_clip_flag;
+    uint8_t alf_chroma_num_alt_filters_minus1;
+    uint8_t alf_chroma_coeff_abs[8][6];
+    uint8_t alf_chroma_coeff_sign[8][6];
+    uint8_t alf_chroma_clip_idx[8][6];
+    uint8_t alf_cc_cb_filters_signalled_minus1;
+    uint8_t alf_cc_cb_mapped_coeff_abs[4][7];
+    uint8_t alf_cc_cb_coeff_sign[4][7];
+    uint8_t alf_cc_cr_filters_signalled_minus1;
+    uint8_t alf_cc_cr_mapped_coeff_abs[4][7];
+    uint8_t alf_cc_cr_coeff_sign[4][7];
+
+    uint8_t scaling_list_copy_mode_flag[28];
+    uint8_t scaling_list_pred_mode_flag[28];
+    uint8_t scaling_list_pred_id_delta[28];
+    int8_t  scaling_list_dc_coef[14];
+    int8_t  scaling_list_delta_coef[28][64];
+
+    uint8_t lmcs_min_bin_idx;
+    uint8_t lmcs_delta_max_bin_idx;
+    uint8_t lmcs_delta_cw_prec_minus1;
+    uint16_t lmcs_delta_abs_cw[16];
+    uint8_t lmcs_delta_sign_cw_flag[16];
+    uint8_t lmcs_delta_abs_crs;
+    uint8_t lmcs_delta_sign_crs_flag;
+
+    uint8_t aps_extension_flag;
+    H266RawExtensionData extension_data;
+} H266RawAPS;
+
 typedef struct H266RawAUD {
     H266RawNALUnitHeader nal_unit_header;
     uint8_t aud_irap_or_gdr_flag;
diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c
index e2246cfc1b..d8ac493edc 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -2185,6 +2185,237 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+static int FUNC(alf_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                          H266RawAPS *current)
+{
+    int err, j, k;
+
+    flag(alf_luma_filter_signal_flag);
+
+    if (current->aps_chroma_present_flag) {
+        flag(alf_chroma_filter_signal_flag);
+        flag(alf_cc_cb_filter_signal_flag);
+        flag(alf_cc_cr_filter_signal_flag);
+    } else {
+        infer(alf_chroma_filter_signal_flag, 0);
+        infer(alf_cc_cb_filter_signal_flag, 0);
+        infer(alf_cc_cr_filter_signal_flag, 0);
+    }
+
+    if (current->alf_luma_filter_signal_flag) {
+        flag(alf_luma_clip_flag);
+        ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS - 1);
+        if (current->alf_luma_num_filters_signalled_minus1 > 0) {
+            unsigned int bits = av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
+            for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS; filt_idx++)
+                us(bits, alf_luma_coeff_delta_idx[filt_idx],
+                   0, current->alf_luma_num_filters_signalled_minus1,
+                   1, filt_idx);
+        }
+        for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
+            for (j = 0; j < 12; j++) {
+                ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
+                if (current->alf_luma_coeff_abs[sf_idx][j])
+                    ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
+                else
+                    infer(alf_luma_coeff_sign[sf_idx][j], 0);
+            }
+    } else {
+        infer(alf_luma_clip_flag, 0);
+        infer(alf_luma_num_filters_signalled_minus1, 0);
+    }
+    for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
+        for (j = 0; j < 12; j++) {
+            if (current->alf_luma_clip_flag)
+                ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
+            else
+                infer(alf_luma_clip_idx[sf_idx][j], 0);
+        }
+    }
+
+    if (current->alf_chroma_filter_signal_flag) {
+        flag(alf_chroma_clip_flag);
+        ue(alf_chroma_num_alt_filters_minus1, 0, 7);
+    } else {
+        infer(alf_chroma_clip_flag, 0);
+        infer(alf_chroma_num_alt_filters_minus1, 0);
+    }
+    for (int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
+        for (j = 0; j < 6; j++) {
+            if (current->alf_chroma_filter_signal_flag)
+                ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
+            else
+                infer(alf_chroma_coeff_abs[alt_idx][j], 0);
+            if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
+                ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
+            else
+                infer(alf_chroma_coeff_sign[alt_idx][j], 0);
+        }
+        for (j = 0; j < 6; j++) {
+            if (current->alf_chroma_clip_flag)
+                ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
+            else
+                infer(alf_chroma_clip_idx[alt_idx][j], 0);
+        }
+    }
+
+    if (current->alf_cc_cb_filter_signal_flag)
+        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
+    else
+        infer(alf_cc_cb_filters_signalled_minus1, 0);
+    for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
+        for (j = 0; j < 7; j++) {
+            if (current->alf_cc_cb_filter_signal_flag)
+                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
+            else
+                infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
+            if (current->alf_cc_cb_mapped_coeff_abs[k][j])
+                ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
+            else
+                infer(alf_cc_cb_coeff_sign[k][j], 0);
+        }
+    }
+
+    if (current->alf_cc_cr_filter_signal_flag)
+        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
+    else
+        infer(alf_cc_cr_filters_signalled_minus1, 0);
+    for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
+        for (j = 0; j < 7; j++) {
+            if (current->alf_cc_cr_filter_signal_flag)
+                ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
+            else
+                infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
+            if (current->alf_cc_cr_mapped_coeff_abs[k][j])
+                ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
+            else
+                infer(alf_cc_cr_coeff_sign[k][j], 0);
+        }
+    }
+
+    return 0;
+}
+
+static int FUNC(lmcs_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                           H266RawAPS *current)
+{
+    int err, i, lmcs_max_bin_idx;
+
+    ue(lmcs_min_bin_idx, 0, 15);
+    ue(lmcs_delta_max_bin_idx, 0, 15);
+    ue(lmcs_delta_cw_prec_minus1, 0, 14);
+
+    lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
+
+    if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
+        return AVERROR_INVALIDDATA;
+
+    for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
+        ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i], 1, i);
+        if (current->lmcs_delta_abs_cw[i] > 0)
+            flags(lmcs_delta_sign_cw_flag[i], 1, i);
+        else
+            infer(lmcs_delta_sign_cw_flag[i], 0);
+    }
+
+    if (current->aps_chroma_present_flag) {
+        ub(3, lmcs_delta_abs_crs);
+        if (current->lmcs_delta_abs_crs > 0)
+            flag(lmcs_delta_sign_crs_flag);
+        else
+            infer(lmcs_delta_sign_crs_flag, 0);
+    } else {
+        infer(lmcs_delta_abs_crs, 0);
+        infer(lmcs_delta_sign_crs_flag, 0);
+    }
+
+    return 0;
+}
+
+static int FUNC(scaling_list_data)(CodedBitstreamContext *ctx, RWContext *rw,
+                                   H266RawAPS *current)
+{
+    // 7.4.3.4, deriving DiagScanOrder
+    static const uint8_t diag_scan_order[64][2] = {
+        { 0,  0, }, { 0,  1, }, { 1,  0, }, { 0,  2, }, { 1,  1, }, { 2,  0, }, { 0,  3, }, { 1,  2, },
+        { 2,  1, }, { 3,  0, }, { 0,  4, }, { 1,  3, }, { 2,  2, }, { 3,  1, }, { 4,  0, }, { 0,  5, },
+        { 1,  4, }, { 2,  3, }, { 3,  2, }, { 4,  1, }, { 5,  0, }, { 0,  6, }, { 1,  5, }, { 2,  4, },
+        { 3,  3, }, { 4,  2, }, { 5,  1, }, { 6,  0, }, { 0,  7, }, { 1,  6, }, { 2,  5, }, { 3,  4, },
+        { 4,  3, }, { 5,  2, }, { 6,  1, }, { 7,  0, }, { 1,  7, }, { 2,  6, }, { 3,  5, }, { 4,  4, },
+        { 5,  3, }, { 6,  2, }, { 7,  1, }, { 2,  7, }, { 3,  6, }, { 4,  5, }, { 5,  4, }, { 6,  3, },
+        { 7,  2, }, { 3,  7, }, { 4,  6, }, { 5,  5, }, { 6,  4, }, { 7,  3, }, { 4,  7, }, { 5,  6, },
+        { 6,  5, }, { 7,  4, }, { 5,  7, }, { 6,  6, }, { 7,  5, }, { 6,  7, }, { 7,  6, }, { 7,  7, }, };
+    int err;
+
+    for (int id = 0; id < 28; id ++) {
+        if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
+            flags(scaling_list_copy_mode_flag[id], 1, id);
+            if (!current->scaling_list_copy_mode_flag[id])
+                flags(scaling_list_pred_mode_flag[id], 1, id);
+            else
+                infer(scaling_list_pred_mode_flag[id], 0);
+            if ((current->scaling_list_copy_mode_flag[id] ||
+                 current->scaling_list_pred_mode_flag[id]) &&
+                 id != 0 && id != 2 && id != 8) {
+                int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) : (id - 8));
+                ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1, id);
+            }
+            if (!current->scaling_list_copy_mode_flag[id]) {
+                int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
+                if (id > 13) {
+                    int idx = id - 14;
+                    ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
+                }
+                for (int i = 0; i < matrix_size * matrix_size; i++) {
+                    int x = diag_scan_order[i][0];
+                    int y = diag_scan_order[i][1];
+                    if (!(id > 25 && x >= 4 && y >= 4))
+                        ses(scaling_list_delta_coef[id][i], -128, 127, 2, id, i);
+                }
+            } else if (id > 13) {
+                int idx = id - 14;
+                infer(scaling_list_dc_coef[idx], 0);
+            }
+        } else {
+            infer(scaling_list_copy_mode_flag[id], 1);
+            infer(scaling_list_pred_mode_flag[id], 0);
+        }
+    }
+
+    return 0;
+}
+
+static int FUNC(aps)(CodedBitstreamContext *ctx, RWContext *rw,
+                     H266RawAPS *current, int prefix)
+{
+    int err;
+
+    if (prefix)
+        HEADER("Prefix Adaptation parameter set");
+    else
+        HEADER("Suffix Adaptation parameter set");
+
+    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
+                                prefix ? VVC_PREFIX_APS_NUT
+                                       : VVC_SUFFIX_APS_NUT));
+
+    ub(3, aps_params_type);
+    ub(5, aps_adaptation_parameter_set_id);
+    flag(aps_chroma_present_flag);
+    if (current->aps_params_type == VVC_ASP_TYPE_ALF)
+        CHECK(FUNC(alf_data)(ctx, rw, current));
+    else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
+        CHECK(FUNC(lmcs_data)(ctx, rw, current));
+    else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
+        CHECK(FUNC(scaling_list_data)(ctx, rw, current));
+    flag(aps_extension_flag);
+    if (current->aps_extension_flag)
+        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
+    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
+
+    return 0;
+}
+
 static int FUNC(aud) (CodedBitstreamContext *ctx, RWContext *rw,
                      H266RawAUD *current)
 {
diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
index 9fbb4a953c..7d165cdb86 100644
--- a/libavcodec/vvc.h
+++ b/libavcodec/vvc.h
@@ -66,6 +66,12 @@ enum VVCSliceType {
     VVC_SLICE_TYPE_I = 2,
 };
 
+enum VVCAPSType {
+    VVC_ASP_TYPE_ALF     = 0,
+    VVC_ASP_TYPE_LMCS    = 1,
+    VVC_ASP_TYPE_SCALING = 2,
+};
+
 enum {
     //6.2 we can have 3 sample arrays
     VVC_MAX_SAMPLE_ARRAYS = 3,
@@ -95,6 +101,10 @@ enum {
     // 7.4.4.1: ptl_num_sub_profiles is u(8)
     VVC_MAX_SUB_PROFILES = 256,
 
+    // 7.4.3.18: The variable NumAlfFilters specifying the number of different adaptive loop
+    // filters is set equal to 25.
+    VVC_NUM_ALF_FILTERS = 25,
+
     // A.4.2: according to (1577), MaxDpbSize is bounded above by 2 * maxDpbPicBuf(8)
     VVC_MAX_DPB_SIZE = 16,
 
-- 
2.41.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH v4] avcodec/cbs_h266: add support for Adaptation parameter set NALU type
  2023-07-05 18:36     ` [FFmpeg-devel] [PATCH v4] " James Almer
@ 2023-07-06  0:41       ` Nuo Mi
  2023-07-06  1:03         ` James Almer
  0 siblings, 1 reply; 13+ messages in thread
From: Nuo Mi @ 2023-07-06  0:41 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Thu, Jul 6, 2023 at 2:36 AM James Almer <jamrial@gmail.com> wrote:

> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> v3 was mistakenly sent without the amended changes, so it's the
> same as v2.
>
>  libavcodec/cbs_h2645.c                |  21 +++
>  libavcodec/cbs_h266.h                 |  46 +++++
>  libavcodec/cbs_h266_syntax_template.c | 231 ++++++++++++++++++++++++++
>  libavcodec/vvc.h                      |  10 ++
>  4 files changed, 308 insertions(+)
>
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 95da597427..34c5d1d372 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1116,6 +1116,16 @@ static int
> cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
>          }
>          break;
>
> +    case VVC_PREFIX_APS_NUT:
> +    case VVC_SUFFIX_APS_NUT:
> +        {
> +            err = cbs_h266_read_aps(ctx, &gbc, unit->content,
> +                                    unit->type == VVC_PREFIX_APS_NUT);
> +
> +            if (err < 0)
> +                return err;
> +        }
> +        break;
>      case VVC_PH_NUT:
>          {
>              H266RawPH *ph = unit->content;
> @@ -1668,6 +1678,15 @@ static int
> cbs_h266_write_nal_unit(CodedBitstreamContext *ctx,
>          }
>          break;
>
> +    case VVC_PREFIX_APS_NUT:
> +    case VVC_SUFFIX_APS_NUT:
> +        {
> +            err = cbs_h266_write_aps(ctx, pbc, unit->content,
> +                                     unit->type == VVC_PREFIX_APS_NUT);
> +            if (err < 0)
> +                return err;
> +        }
> +        break;
>      case VVC_PH_NUT:
>          {
>              H266RawPH *ph = unit->content;
> @@ -2004,6 +2023,8 @@ static const CodedBitstreamUnitTypeDescriptor
> cbs_h266_unit_types[] = {
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS,
> extension_data.data),
>      CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS,
> extension_data.data),
> +    CBS_UNIT_TYPE_INTERNAL_REF(VVC_PREFIX_APS_NUT, H266RawAPS,
> extension_data.data),
> +    CBS_UNIT_TYPE_INTERNAL_REF(VVC_SUFFIX_APS_NUT, H266RawAPS,
> extension_data.data),
>
>      CBS_UNIT_TYPE_POD(VVC_PH_NUT , H266RawPH),
>      CBS_UNIT_TYPE_POD(VVC_AUD_NUT, H266RawAUD),
> diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
> index 63af3bacf0..08cae68036 100644
> --- a/libavcodec/cbs_h266.h
> +++ b/libavcodec/cbs_h266.h
> @@ -578,6 +578,52 @@ typedef struct H266RawPPS {
>      uint16_t row_height_val[VVC_MAX_TILE_ROWS];
>  } H266RawPPS;
>
> +typedef struct H266RawAPS {
> +    H266RawNALUnitHeader nal_unit_header;
> +    uint8_t aps_params_type;
> +    uint8_t aps_adaptation_parameter_set_id;
> +    uint8_t aps_chroma_present_flag;
> +
> +    uint8_t alf_luma_filter_signal_flag;
> +    uint8_t alf_chroma_filter_signal_flag;
> +    uint8_t alf_cc_cb_filter_signal_flag;
> +    uint8_t alf_cc_cr_filter_signal_flag;
> +    uint8_t alf_luma_clip_flag;
> +    uint8_t alf_luma_num_filters_signalled_minus1;
> +    uint8_t alf_luma_coeff_delta_idx[VVC_NUM_ALF_FILTERS];
> +    uint8_t alf_luma_coeff_abs[VVC_NUM_ALF_FILTERS][12];
> +    uint8_t alf_luma_coeff_sign[VVC_NUM_ALF_FILTERS][12];
> +    uint8_t alf_luma_clip_idx[VVC_NUM_ALF_FILTERS][12];
> +    uint8_t alf_chroma_clip_flag;
> +    uint8_t alf_chroma_num_alt_filters_minus1;
> +    uint8_t alf_chroma_coeff_abs[8][6];
> +    uint8_t alf_chroma_coeff_sign[8][6];
> +    uint8_t alf_chroma_clip_idx[8][6];
> +    uint8_t alf_cc_cb_filters_signalled_minus1;
> +    uint8_t alf_cc_cb_mapped_coeff_abs[4][7];
> +    uint8_t alf_cc_cb_coeff_sign[4][7];
> +    uint8_t alf_cc_cr_filters_signalled_minus1;
> +    uint8_t alf_cc_cr_mapped_coeff_abs[4][7];
> +    uint8_t alf_cc_cr_coeff_sign[4][7];
> +
> +    uint8_t scaling_list_copy_mode_flag[28];
> +    uint8_t scaling_list_pred_mode_flag[28];
> +    uint8_t scaling_list_pred_id_delta[28];
> +    int8_t  scaling_list_dc_coef[14];
> +    int8_t  scaling_list_delta_coef[28][64];
> +
> +    uint8_t lmcs_min_bin_idx;
> +    uint8_t lmcs_delta_max_bin_idx;
> +    uint8_t lmcs_delta_cw_prec_minus1;
> +    uint16_t lmcs_delta_abs_cw[16];
> +    uint8_t lmcs_delta_sign_cw_flag[16];
> +    uint8_t lmcs_delta_abs_crs;
> +    uint8_t lmcs_delta_sign_crs_flag;
> +
> +    uint8_t aps_extension_flag;
> +    H266RawExtensionData extension_data;
> +} H266RawAPS;
> +
>  typedef struct H266RawAUD {
>      H266RawNALUnitHeader nal_unit_header;
>      uint8_t aud_irap_or_gdr_flag;
> diff --git a/libavcodec/cbs_h266_syntax_template.c
> b/libavcodec/cbs_h266_syntax_template.c
> index e2246cfc1b..d8ac493edc 100644
> --- a/libavcodec/cbs_h266_syntax_template.c
> +++ b/libavcodec/cbs_h266_syntax_template.c
> @@ -2185,6 +2185,237 @@ static int FUNC(pps) (CodedBitstreamContext *ctx,
> RWContext *rw,
>      return 0;
>  }
>
> +static int FUNC(alf_data)(CodedBitstreamContext *ctx, RWContext *rw,
> +                          H266RawAPS *current)
> +{
> +    int err, j, k;
> +
> +    flag(alf_luma_filter_signal_flag);
> +
> +    if (current->aps_chroma_present_flag) {
> +        flag(alf_chroma_filter_signal_flag);
> +        flag(alf_cc_cb_filter_signal_flag);
> +        flag(alf_cc_cr_filter_signal_flag);
> +    } else {
> +        infer(alf_chroma_filter_signal_flag, 0);
> +        infer(alf_cc_cb_filter_signal_flag, 0);
> +        infer(alf_cc_cr_filter_signal_flag, 0);
> +    }
> +
> +    if (current->alf_luma_filter_signal_flag) {
> +        flag(alf_luma_clip_flag);
> +        ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS
> - 1);
> +        if (current->alf_luma_num_filters_signalled_minus1 > 0) {
> +            unsigned int bits =
> av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
> +            for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS;
> filt_idx++)
> +                us(bits, alf_luma_coeff_delta_idx[filt_idx],
> +                   0, current->alf_luma_num_filters_signalled_minus1,
> +                   1, filt_idx);
> +        }
> +        for (int sf_idx = 0; sf_idx <=
> current->alf_luma_num_filters_signalled_minus1; sf_idx++)
> +            for (j = 0; j < 12; j++) {
> +                ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
> +                if (current->alf_luma_coeff_abs[sf_idx][j])
> +                    ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
> +                else
> +                    infer(alf_luma_coeff_sign[sf_idx][j], 0);
> +            }
> +    } else {
> +        infer(alf_luma_clip_flag, 0);
> +        infer(alf_luma_num_filters_signalled_minus1, 0);
> +    }
> +    for (int sf_idx = 0; sf_idx <=
> current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
> +        for (j = 0; j < 12; j++) {
> +            if (current->alf_luma_clip_flag)
> +                ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
> +            else
> +                infer(alf_luma_clip_idx[sf_idx][j], 0);
> +        }
> +    }
> +
> +    if (current->alf_chroma_filter_signal_flag) {
> +        flag(alf_chroma_clip_flag);
> +        ue(alf_chroma_num_alt_filters_minus1, 0, 7);
> +    } else {
> +        infer(alf_chroma_clip_flag, 0);
> +        infer(alf_chroma_num_alt_filters_minus1, 0);
> +    }
> +    for (int alt_idx = 0; alt_idx <=
> current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
> +        for (j = 0; j < 6; j++) {
> +            if (current->alf_chroma_filter_signal_flag)
> +                ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx,
> j);
> +            else
> +                infer(alf_chroma_coeff_abs[alt_idx][j], 0);
> +            if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
> +                ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
> +            else
> +                infer(alf_chroma_coeff_sign[alt_idx][j], 0);
> +        }
> +        for (j = 0; j < 6; j++) {
> +            if (current->alf_chroma_clip_flag)
> +                ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
> +            else
> +                infer(alf_chroma_clip_idx[alt_idx][j], 0);
> +        }
> +    }
> +
> +    if (current->alf_cc_cb_filter_signal_flag)
> +        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
> +    else
> +        infer(alf_cc_cb_filters_signalled_minus1, 0);
>
Not right, it will overread one filter set even
alf_cc_cb_filter_signal_flag is false.

> +    for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
> +        for (j = 0; j < 7; j++) {
> +            if (current->alf_cc_cb_filter_signal_flag)
> +                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
> +            else
> +                infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
> +            if (current->alf_cc_cb_mapped_coeff_abs[k][j])
> +                ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
> +            else
> +                infer(alf_cc_cb_coeff_sign[k][j], 0);
> +        }
> +    }
> +
> +    if (current->alf_cc_cr_filter_signal_flag)
> +        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
> +    else
> +        infer(alf_cc_cr_filters_signalled_minus1, 0);
>
Not right,

> +    for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++)
> {
> +        for (j = 0; j < 7; j++) {
> +            if (current->alf_cc_cr_filter_signal_flag)
> +                ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
> +            else
> +                infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
> +            if (current->alf_cc_cr_mapped_coeff_abs[k][j])
> +                ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
> +            else
> +                infer(alf_cc_cr_coeff_sign[k][j], 0);
> +        }
> +    }
> +
> +    return 0;
> +}
> +
> +static int FUNC(lmcs_data)(CodedBitstreamContext *ctx, RWContext *rw,
> +                           H266RawAPS *current)
> +{
> +    int err, i, lmcs_max_bin_idx;
> +
> +    ue(lmcs_min_bin_idx, 0, 15);
> +    ue(lmcs_delta_max_bin_idx, 0, 15);
> +    ue(lmcs_delta_cw_prec_minus1, 0, 14);
> +
> +    lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
> +
> +    if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
> +        return AVERROR_INVALIDDATA;
> +
> +    for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
> +        ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i],
> 1, i);
> +        if (current->lmcs_delta_abs_cw[i] > 0)
> +            flags(lmcs_delta_sign_cw_flag[i], 1, i);
> +        else
> +            infer(lmcs_delta_sign_cw_flag[i], 0);
> +    }
> +
> +    if (current->aps_chroma_present_flag) {
> +        ub(3, lmcs_delta_abs_crs);
> +        if (current->lmcs_delta_abs_crs > 0)
> +            flag(lmcs_delta_sign_crs_flag);
> +        else
> +            infer(lmcs_delta_sign_crs_flag, 0);
> +    } else {
> +        infer(lmcs_delta_abs_crs, 0);
> +        infer(lmcs_delta_sign_crs_flag, 0);
> +    }
> +
> +    return 0;
> +}
> +
> +static int FUNC(scaling_list_data)(CodedBitstreamContext *ctx, RWContext
> *rw,
> +                                   H266RawAPS *current)
> +{
> +    // 7.4.3.4, deriving DiagScanOrder
> +    static const uint8_t diag_scan_order[64][2] = {
> +        { 0,  0, }, { 0,  1, }, { 1,  0, }, { 0,  2, }, { 1,  1, }, { 2,
> 0, }, { 0,  3, }, { 1,  2, },
> +        { 2,  1, }, { 3,  0, }, { 0,  4, }, { 1,  3, }, { 2,  2, }, { 3,
> 1, }, { 4,  0, }, { 0,  5, },
> +        { 1,  4, }, { 2,  3, }, { 3,  2, }, { 4,  1, }, { 5,  0, }, { 0,
> 6, }, { 1,  5, }, { 2,  4, },
> +        { 3,  3, }, { 4,  2, }, { 5,  1, }, { 6,  0, }, { 0,  7, }, { 1,
> 6, }, { 2,  5, }, { 3,  4, },
> +        { 4,  3, }, { 5,  2, }, { 6,  1, }, { 7,  0, }, { 1,  7, }, { 2,
> 6, }, { 3,  5, }, { 4,  4, },
> +        { 5,  3, }, { 6,  2, }, { 7,  1, }, { 2,  7, }, { 3,  6, }, { 4,
> 5, }, { 5,  4, }, { 6,  3, },
> +        { 7,  2, }, { 3,  7, }, { 4,  6, }, { 5,  5, }, { 6,  4, }, { 7,
> 3, }, { 4,  7, }, { 5,  6, },
> +        { 6,  5, }, { 7,  4, }, { 5,  7, }, { 6,  6, }, { 7,  5, }, { 6,
> 7, }, { 7,  6, }, { 7,  7, }, };
> +    int err;
> +
> +    for (int id = 0; id < 28; id ++) {
> +        if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
> +            flags(scaling_list_copy_mode_flag[id], 1, id);
> +            if (!current->scaling_list_copy_mode_flag[id])
> +                flags(scaling_list_pred_mode_flag[id], 1, id);
> +            else
> +                infer(scaling_list_pred_mode_flag[id], 0);
> +            if ((current->scaling_list_copy_mode_flag[id] ||
> +                 current->scaling_list_pred_mode_flag[id]) &&
> +                 id != 0 && id != 2 && id != 8) {
> +                int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) :
> (id - 8));
> +                ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1,
> id);
> +            }
> +            if (!current->scaling_list_copy_mode_flag[id]) {
> +                int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
> +                if (id > 13) {
> +                    int idx = id - 14;
> +                    ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
> +                }
> +                for (int i = 0; i < matrix_size * matrix_size; i++) {
> +                    int x = diag_scan_order[i][0];
> +                    int y = diag_scan_order[i][1];
> +                    if (!(id > 25 && x >= 4 && y >= 4))
> +                        ses(scaling_list_delta_coef[id][i], -128, 127, 2,
> id, i);
> +                }
> +            } else if (id > 13) {
> +                int idx = id - 14;
> +                infer(scaling_list_dc_coef[idx], 0);
> +            }
> +        } else {
> +            infer(scaling_list_copy_mode_flag[id], 1);
> +            infer(scaling_list_pred_mode_flag[id], 0);
> +        }
> +    }
> +
> +    return 0;
> +}
> +
> +static int FUNC(aps)(CodedBitstreamContext *ctx, RWContext *rw,
> +                     H266RawAPS *current, int prefix)
> +{
> +    int err;
> +
> +    if (prefix)
> +        HEADER("Prefix Adaptation parameter set");
> +    else
> +        HEADER("Suffix Adaptation parameter set");
> +
> +    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
> +                                prefix ? VVC_PREFIX_APS_NUT
> +                                       : VVC_SUFFIX_APS_NUT));
> +
> +    ub(3, aps_params_type);
> +    ub(5, aps_adaptation_parameter_set_id);
> +    flag(aps_chroma_present_flag);
> +    if (current->aps_params_type == VVC_ASP_TYPE_ALF)
> +        CHECK(FUNC(alf_data)(ctx, rw, current));
> +    else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
> +        CHECK(FUNC(lmcs_data)(ctx, rw, current));
> +    else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
> +        CHECK(FUNC(scaling_list_data)(ctx, rw, current));
> +    flag(aps_extension_flag);
> +    if (current->aps_extension_flag)
> +        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
> +    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
> +
> +    return 0;
> +}
> +
>  static int FUNC(aud) (CodedBitstreamContext *ctx, RWContext *rw,
>                       H266RawAUD *current)
>  {
> diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
> index 9fbb4a953c..7d165cdb86 100644
> --- a/libavcodec/vvc.h
> +++ b/libavcodec/vvc.h
> @@ -66,6 +66,12 @@ enum VVCSliceType {
>      VVC_SLICE_TYPE_I = 2,
>  };
>
> +enum VVCAPSType {
> +    VVC_ASP_TYPE_ALF     = 0,
> +    VVC_ASP_TYPE_LMCS    = 1,
> +    VVC_ASP_TYPE_SCALING = 2,
> +};
> +
>  enum {
>      //6.2 we can have 3 sample arrays
>      VVC_MAX_SAMPLE_ARRAYS = 3,
> @@ -95,6 +101,10 @@ enum {
>      // 7.4.4.1: ptl_num_sub_profiles is u(8)
>      VVC_MAX_SUB_PROFILES = 256,
>
> +    // 7.4.3.18: The variable NumAlfFilters specifying the number of
> different adaptive loop
> +    // filters is set equal to 25.
> +    VVC_NUM_ALF_FILTERS = 25,
> +
>      // A.4.2: according to (1577), MaxDpbSize is bounded above by 2 *
> maxDpbPicBuf(8)
>      VVC_MAX_DPB_SIZE = 16,
>
> --
> 2.41.0
>
> _______________________________________________
> 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".
>
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH v4] avcodec/cbs_h266: add support for Adaptation parameter set NALU type
  2023-07-06  0:41       ` Nuo Mi
@ 2023-07-06  1:03         ` James Almer
  2023-07-06 14:00           ` Nuo Mi
  0 siblings, 1 reply; 13+ messages in thread
From: James Almer @ 2023-07-06  1:03 UTC (permalink / raw)
  To: ffmpeg-devel

On 7/5/2023 9:41 PM, Nuo Mi wrote:
>> +    if (current->alf_cc_cb_filter_signal_flag)
>> +        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
>> +    else
>> +        infer(alf_cc_cb_filters_signalled_minus1, 0);
>>
> Not right, it will overread one filter set even
> alf_cc_cb_filter_signal_flag is false.

It will infer all values in alf_cc_cb_mapped_coeff_abs[0][0..7] and 
alf_cc_cb_coeff_sign[0][0..7] to be 0, as they are not present.

> 
>> +    for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
>> +        for (j = 0; j < 7; j++) {
>> +            if (current->alf_cc_cb_filter_signal_flag)
>> +                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
>> +            else
>> +                infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
>> +            if (current->alf_cc_cb_mapped_coeff_abs[k][j])
>> +                ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
>> +            else
>> +                infer(alf_cc_cb_coeff_sign[k][j], 0);
>> +        }
>> +    }
>> +
>> +    if (current->alf_cc_cr_filter_signal_flag)
>> +        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
>> +    else
>> +        infer(alf_cc_cr_filters_signalled_minus1, 0);
>>
> Not right,

Same as the above.
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH v4] avcodec/cbs_h266: add support for Adaptation parameter set NALU type
  2023-07-06  1:03         ` James Almer
@ 2023-07-06 14:00           ` Nuo Mi
  0 siblings, 0 replies; 13+ messages in thread
From: Nuo Mi @ 2023-07-06 14:00 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

On Thu, Jul 6, 2023 at 9:04 AM James Almer <jamrial@gmail.com> wrote:

> On 7/5/2023 9:41 PM, Nuo Mi wrote:
> >> +    if (current->alf_cc_cb_filter_signal_flag)
> >> +        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
> >> +    else
> >> +        infer(alf_cc_cb_filters_signalled_minus1, 0);
> >>
> > Not right, it will overread one filter set even
> > alf_cc_cb_filter_signal_flag is false.
>
> It will infer all values in alf_cc_cb_mapped_coeff_abs[0][0..7] and
> alf_cc_cb_coeff_sign[0][0..7] to be 0, as they are not present.
>
> Oh, my bad. thank you for the explanation.
LGTM now.

> >
> >> +    for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++)
> {
> >> +        for (j = 0; j < 7; j++) {
> >> +            if (current->alf_cc_cb_filter_signal_flag)
> >> +                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
> >> +            else
> >> +                infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
> >> +            if (current->alf_cc_cb_mapped_coeff_abs[k][j])
> >> +                ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
> >> +            else
> >> +                infer(alf_cc_cb_coeff_sign[k][j], 0);
> >> +        }
> >> +    }
> >> +
> >> +    if (current->alf_cc_cr_filter_signal_flag)
> >> +        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
> >> +    else
> >> +        infer(alf_cc_cr_filters_signalled_minus1, 0);
> >>
> > Not right,
>
> Same as the above.
> _______________________________________________
> 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".
>
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-07-06 14:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-02 23:26 [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type James Almer
2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 2/4] avcodec/cbs_h266: add support for Decoding capability " James Almer
2023-07-03 15:11   ` Nuo Mi
2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 3/4] avcodec/cbs_h266: add support for Adaptation parameter set " James Almer
2023-07-05 14:29   ` Nuo Mi
2023-07-05 18:11     ` [FFmpeg-devel] [PATCH v2 " James Almer
2023-07-05 18:33     ` [FFmpeg-devel] [PATCH v3] " James Almer
2023-07-05 18:36     ` [FFmpeg-devel] [PATCH v4] " James Almer
2023-07-06  0:41       ` Nuo Mi
2023-07-06  1:03         ` James Almer
2023-07-06 14:00           ` Nuo Mi
2023-07-02 23:26 ` [FFmpeg-devel] [PATCH 4/4] fate/cbs: add more VVC tests James Almer
2023-07-05 14:32 ` [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h266: add support for Operating point information NALU type Nuo Mi

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git