[FFmpeg-cvslog] avcodec/vvcdec: support rectangular single-slice subpics

Frank Plowman git at videolan.org
Tue Apr 2 15:59:25 EEST 2024


ffmpeg | branch: master | Frank Plowman <post at frankplowman.com> | Wed Mar 27 21:01:01 2024 +0800| [8078a0b0fa72b41c780953ed5fbbca132a2f9948] | committer: Nuo Mi

avcodec/vvcdec: support rectangular single-slice subpics

Co-authored-by: Nuo Mi <nuomi2021 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8078a0b0fa72b41c780953ed5fbbca132a2f9948
---

 libavcodec/cbs_h266_syntax_template.c |  5 +-
 libavcodec/vvc/vvc_ps.c               | 93 ++++++++++++++++++++++++++++++++---
 2 files changed, 91 insertions(+), 7 deletions(-)

diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c
index f56066d470..725cee5b03 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -2120,9 +2120,12 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, RWContext *rw,
         } else {
             if (current->pps_no_pic_partition_flag)
                 infer(pps_num_slices_in_pic_minus1, 0);
-            else if (current->pps_single_slice_per_subpic_flag)
+            else if (current->pps_single_slice_per_subpic_flag) {
+                for (i = 0; i <= sps->sps_num_subpics_minus1; i++)
+                    current->num_slices_in_subpic[i] = 1;
                 infer(pps_num_slices_in_pic_minus1,
                       sps->sps_num_subpics_minus1);
+            }
             // else?
         }
         if (!current->pps_rect_slice_flag ||
diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c
index d50822024f..634c2b05a7 100644
--- a/libavcodec/vvc/vvc_ps.c
+++ b/libavcodec/vvc/vvc_ps.c
@@ -348,6 +348,83 @@ static int pps_add_ctus(VVCPPS *pps, int *off, const int ctu_x, const int ctu_y,
     return *off - start;
 }
 
+static void pps_single_slice_picture(VVCPPS *pps, int *off)
+{
+    for (int j = 0; j < pps->r->num_tile_rows; j++) {
+        for (int i = 0; i < pps->r->num_tile_columns; i++) {
+            pps->num_ctus_in_slice[0] = pps_add_ctus(pps, off,
+                pps->col_bd[i], pps->row_bd[j],
+                pps->r->col_width_val[i], pps->r->row_height_val[j]);
+        }
+    }
+}
+
+static void subpic_tiles(int *tile_x, int *tile_y, int *tile_x_end, int *tile_y_end,
+    const VVCSPS *sps, const VVCPPS *pps,  const int i)
+{
+    const int rx = sps->r->sps_subpic_ctu_top_left_x[i];
+    const int ry = sps->r->sps_subpic_ctu_top_left_y[i];
+
+    *tile_x = *tile_y = 0;
+
+    while (pps->col_bd[*tile_x] != rx)
+        (*tile_x)++;
+
+    while (pps->row_bd[*tile_y] != ry)
+        (*tile_y)++;
+
+    *tile_x_end = (*tile_x);
+    *tile_y_end = (*tile_y);
+
+    while (pps->col_bd[*tile_x_end] < rx + sps->r->sps_subpic_width_minus1[i] + 1)
+        (*tile_x_end)++;
+
+    while (pps->row_bd[*tile_y_end] < ry + sps->r->sps_subpic_height_minus1[i] + 1)
+        (*tile_y_end)++;
+}
+
+static void pps_subpic_less_than_one_tile_slice(VVCPPS *pps, const VVCSPS *sps, const int i, const int tx, const int ty, int *off)
+{
+    pps->num_ctus_in_slice[i] = pps_add_ctus(pps, off,
+        pps->col_bd[tx], pps->row_bd[ty],
+        pps->r->col_width_val[tx], sps->r->sps_subpic_height_minus1[i] + 1);
+}
+
+static void pps_subpic_one_or_more_tiles_slice(VVCPPS *pps, const int tile_x, const int tile_y, const int x_end, const int y_end, const int i, int *off)
+{
+    for (int ty = tile_y; ty < y_end; ty++) {
+        for (int tx = tile_x; tx < x_end; tx++) {
+            pps->num_ctus_in_slice[i] += pps_add_ctus(pps, off,
+                pps->col_bd[tx], pps->row_bd[ty],
+                pps->r->col_width_val[tx], pps->r->row_height_val[ty]);
+        }
+    }
+}
+
+static void pps_subpic_slice(VVCPPS *pps, const VVCSPS *sps, const int i, int *off)
+{
+    int tx, ty, x_end, y_end;
+
+    pps->slice_start_offset[i] = *off;
+    pps->num_ctus_in_slice[i] = 0;
+
+    subpic_tiles(&tx, &ty, &x_end, &y_end, sps, pps, i);
+    if (ty + 1 == y_end && sps->r->sps_subpic_height_minus1[i] + 1 < pps->r->row_height_val[ty])
+        pps_subpic_less_than_one_tile_slice(pps, sps, i, tx, ty, off);
+    else
+        pps_subpic_one_or_more_tiles_slice(pps, tx, ty, x_end, y_end, i, off);
+}
+
+static void pps_single_slice_per_subpic(VVCPPS *pps, const VVCSPS *sps, int *off)
+{
+    if (!sps->r->sps_subpic_info_present_flag) {
+        pps_single_slice_picture(pps, off);
+    } else {
+        for (int i = 0; i < pps->r->pps_num_slices_in_pic_minus1 + 1; i++)
+            pps_subpic_slice(pps, sps, i, off);
+    }
+}
+
 static int pps_one_tile_slices(VVCPPS *pps, const int tile_idx, int i, int *off)
 {
     const H266RawPPS *r = pps->r;
@@ -383,18 +460,22 @@ static void pps_multi_tiles_slice(VVCPPS *pps, const int tile_idx, const int i,
     }
 }
 
-static void pps_rect_slice(VVCPPS* pps)
+static void pps_rect_slice(VVCPPS *pps, const VVCSPS *sps)
 {
-    const H266RawPPS* r = pps->r;
+    const H266RawPPS *r = pps->r;
     int tile_idx = 0, off = 0;
 
+    if (r->pps_single_slice_per_subpic_flag) {
+        pps_single_slice_per_subpic(pps, sps, &off);
+        return;
+    }
+
     for (int i = 0; i < r->pps_num_slices_in_pic_minus1 + 1; i++) {
         if (!r->pps_slice_width_in_tiles_minus1[i] &&
             !r->pps_slice_height_in_tiles_minus1[i]) {
             i = pps_one_tile_slices(pps, tile_idx, i, &off);
         } else {
             pps_multi_tiles_slice(pps, tile_idx, i, &off);
-
         }
         tile_idx = next_tile_idx(tile_idx, i, r);
     }
@@ -413,14 +494,14 @@ static void pps_no_rect_slice(VVCPPS* pps)
     }
 }
 
-static int pps_slice_map(VVCPPS *pps)
+static int pps_slice_map(VVCPPS *pps, const VVCSPS *sps)
 {
     pps->ctb_addr_in_slice = av_calloc(pps->ctb_count, sizeof(*pps->ctb_addr_in_slice));
     if (!pps->ctb_addr_in_slice)
         return AVERROR(ENOMEM);
 
     if (pps->r->pps_rect_slice_flag)
-        pps_rect_slice(pps);
+        pps_rect_slice(pps, sps);
     else
         pps_no_rect_slice(pps);
 
@@ -446,7 +527,7 @@ static int pps_derive(VVCPPS *pps, const VVCSPS *sps)
     if (ret < 0)
         return ret;
 
-    ret = pps_slice_map(pps);
+    ret = pps_slice_map(pps, sps);
     if (ret < 0)
         return ret;
 



More information about the ffmpeg-cvslog mailing list