PR #24996 opened by frankplow
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24996
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24996.patch

The spec defines pps_exp_slice_height_in_ctus_minus1 as a 2D array but
it is sparse, with at most VVC_MAX_SLICES present elements. This commit
replaces it with a 1D array, similar to what was already done in
libavcodec/vaapi_vvc.c. This reduces the size of H266RawPPS from ~1.9MiB
to ~26KiB.

Signed-off-by: Frank Plowman <[email protected]>


>From 29babcd775c38a6581edc38e835ae5091f9dfd1b Mon Sep 17 00:00:00 2001
From: Frank Plowman <[email protected]>
Date: Sat, 10 Oct 2026 10:08:06 +0100
Subject: [PATCH] lavc/vvc: Use 1D array for explicit slice heights in PPS

The spec defines pps_exp_slice_height_in_ctus_minus1 as a 2D array but
it is sparse, with at most VVC_MAX_SLICES present elements. This commit
replaces it with a 1D array, similar to what was already done in
libavcodec/vaapi_vvc.c. This reduces the size of H266RawPPS from ~1.9MiB
to ~26KiB.

Signed-off-by: Frank Plowman <[email protected]>
---
 libavcodec/cbs_h266.h                 | 2 +-
 libavcodec/cbs_h266_syntax_template.c | 7 ++++---
 libavcodec/vaapi_vvc.c                | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
index d315f6b64a..2751ef5dd0 100644
--- a/libavcodec/cbs_h266.h
+++ b/libavcodec/cbs_h266.h
@@ -537,7 +537,7 @@ typedef struct H266RawPPS {
     uint16_t pps_slice_width_in_tiles_minus1[VVC_MAX_SLICES];
     uint16_t pps_slice_height_in_tiles_minus1[VVC_MAX_SLICES];
     uint16_t pps_num_exp_slices_in_tile[VVC_MAX_SLICES];
-    uint16_t 
pps_exp_slice_height_in_ctus_minus1[VVC_MAX_SLICES][VVC_MAX_TILE_ROWS];
+    uint16_t pps_exp_slice_height_in_ctus_minus1[VVC_MAX_SLICES];
     int16_t  pps_tile_idx_delta_val[VVC_MAX_SLICES];
 
     uint8_t  pps_loop_filter_across_slices_enabled_flag;
diff --git a/libavcodec/cbs_h266_syntax_template.c 
b/libavcodec/cbs_h266_syntax_template.c
index 55178db1ea..16862314f6 100644
--- a/libavcodec/cbs_h266_syntax_template.c
+++ b/libavcodec/cbs_h266_syntax_template.c
@@ -2021,12 +2021,13 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, 
RWContext *rw,
 
                         for (j = 0; j < current->pps_num_exp_slices_in_tile[i];
                              j++) {
-                            ues(pps_exp_slice_height_in_ctus_minus1[i][j], 0,
+                            xue(pps_exp_slice_height_in_ctus_minus1[i][j],
+                                current->pps_exp_slice_height_in_ctus_minus1[i 
+ j], 0,
                                 remaining_height_in_ctbs_y - 
(current->pps_num_exp_slices_in_tile[i] - j), 2,
                                 i, j);
                             slice_height_in_ctus =
                                 current->
-                                pps_exp_slice_height_in_ctus_minus1[i][j] + 1;
+                                pps_exp_slice_height_in_ctus_minus1[i + j] + 1;
 
                             current->slice_height_in_ctus[i + j] =
                                 slice_height_in_ctus;
@@ -2038,7 +2039,7 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, 
RWContext *rw,
                         }
                         uniform_slice_height = 1 +
                             (j == 0 ? current->row_height_val[tile_y] - 1:
-                            
current->pps_exp_slice_height_in_ctus_minus1[i][j-1]);
+                            current->pps_exp_slice_height_in_ctus_minus1[i + j 
- 1]);
 
                         num_uniform_slices = (remaining_height_in_ctbs_y + 
uniform_slice_height - 1)
                                            / uniform_slice_height;
diff --git a/libavcodec/vaapi_vvc.c b/libavcodec/vaapi_vvc.c
index 908db7bfab..f5ee07ee87 100644
--- a/libavcodec/vaapi_vvc.c
+++ b/libavcodec/vaapi_vvc.c
@@ -425,7 +425,7 @@ static int vaapi_vvc_start_frame(AVCodecContext          
*avctx,
     if (!pps->pps_no_pic_partition_flag && pps->pps_rect_slice_flag && 
!pps->pps_single_slice_per_subpic_flag) {
         for (i = 0; i <= pps->pps_num_slices_in_pic_minus1; i++) {
             for (j = 0; j < pps->pps_num_exp_slices_in_tile[i]; j++) {
-                exp_slice_height_in_ctus[i + j] = 
pps->pps_exp_slice_height_in_ctus_minus1[i][j] + 1;
+                exp_slice_height_in_ctus[i + j] = 
pps->pps_exp_slice_height_in_ctus_minus1[i + j] + 1;
             }
         }
         for (i = 0; i <= pps->pps_num_slices_in_pic_minus1; i++) {
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to