../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
827 / 940
88.0%
Branches:
417 / 550
75.8%
Functions:
76 / 77
98.7%

libavcodec/vvc/ps.c
Line Branch Exec Source
1 /*
2 * VVC parameter set parser
3 *
4 * Copyright (C) 2023 Nuo Mi
5 * Copyright (C) 2022 Xu Mu
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 #include <limits.h>
24 #include <stdbool.h>
25
26 #include "libavcodec/cbs_h266.h"
27 #include "libavcodec/decode.h"
28 #include "libavcodec/h2645data.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/pixdesc.h"
31 #include "libavutil/refstruct.h"
32 #include "data.h"
33 #include "ps.h"
34 #include "dec.h"
35
36 370 static int sps_map_pixel_format(VVCSPS *sps, void *log_ctx)
37 {
38 370 const H266RawSPS *r = sps->r;
39 const AVPixFmtDescriptor *desc;
40
41
2/4
✓ Branch 2 → 3 taken 16 times.
✓ Branch 2 → 12 taken 354 times.
✗ Branch 2 → 21 not taken.
✗ Branch 2 → 30 not taken.
370 switch (sps->bit_depth) {
42 16 case 8:
43
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 16 times.
16 if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8;
44
1/2
✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 7 not taken.
16 if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
45
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 16 times.
16 if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
46
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 16 times.
16 if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
47 16 break;
48 354 case 10:
49
2/2
✓ Branch 12 → 13 taken 3 times.
✓ Branch 12 → 14 taken 351 times.
354 if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY10;
50
2/2
✓ Branch 14 → 15 taken 342 times.
✓ Branch 14 → 16 taken 12 times.
354 if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
51
2/2
✓ Branch 16 → 17 taken 4 times.
✓ Branch 16 → 18 taken 350 times.
354 if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
52
2/2
✓ Branch 18 → 19 taken 5 times.
✓ Branch 18 → 20 taken 349 times.
354 if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
53 354 break;
54 ✗ case 12:
55
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY12;
56
0/2
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
✗ if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
57
0/2
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
58
0/2
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
✗ if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
59 ✗ break;
60 ✗ default:
61 ✗ av_log(log_ctx, AV_LOG_ERROR,
62 "The following bit-depths are currently specified: 8, 10, 12 bits, "
63 "chroma_format_idc is %d, depth is %d\n",
64 ✗ r->sps_chroma_format_idc, sps->bit_depth);
65 ✗ return AVERROR_INVALIDDATA;
66 }
67
68 370 desc = av_pix_fmt_desc_get(sps->pix_fmt);
69
1/2
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 370 times.
370 if (!desc)
70 ✗ return AVERROR(EINVAL);
71
72 370 sps->hshift[0] = sps->vshift[0] = 0;
73 370 sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w;
74 370 sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h;
75
76 370 sps->pixel_shift = sps->bit_depth > 8;
77
78 370 return 0;
79 }
80
81 370 static int sps_bit_depth(VVCSPS *sps, void *log_ctx)
82 {
83 370 const H266RawSPS *r = sps->r;
84
85 370 sps->bit_depth = r->sps_bitdepth_minus8 + 8;
86 370 sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
87 370 sps->log2_transform_range =
88
1/6
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 8 taken 370 times.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
370 r->sps_extended_precision_flag ? FFMAX(15, FFMIN(20, sps->bit_depth + 6)) : 15;
89 370 return sps_map_pixel_format(sps, log_ctx);
90 }
91
92 367 static int sps_chroma_qp_table(VVCSPS *sps)
93 {
94 367 const H266RawSPS *r = sps->r;
95 367 const int num_qp_tables = r->sps_same_qp_table_for_chroma_flag ?
96
3/4
✓ Branch 2 → 3 taken 3 times.
✓ Branch 2 → 6 taken 364 times.
✓ Branch 3 → 4 taken 3 times.
✗ Branch 3 → 5 not taken.
367 1 : (r->sps_joint_cbcr_enabled_flag ? 3 : 2);
97
98
2/2
✓ Branch 27 → 8 taken 373 times.
✓ Branch 27 → 28 taken 367 times.
740 for (int i = 0; i < num_qp_tables; i++) {
99 int num_points_in_qp_table;
100 int8_t qp_in[VVC_MAX_POINTS_IN_QP_TABLE], qp_out[VVC_MAX_POINTS_IN_QP_TABLE];
101 unsigned int delta_qp_in[VVC_MAX_POINTS_IN_QP_TABLE];
102 373 int off = sps->qp_bd_offset;
103
104 373 num_points_in_qp_table = r->sps_num_points_in_qp_table_minus1[i] + 1;
105
106 373 qp_out[0] = qp_in[0] = r->sps_qp_table_start_minus26[i] + 26;
107
2/2
✓ Branch 13 → 9 taken 595 times.
✓ Branch 13 → 14 taken 373 times.
968 for (int j = 0; j < num_points_in_qp_table; j++ ) {
108 595 const uint8_t delta_qp_out = (r->sps_delta_qp_in_val_minus1[i][j] ^ r->sps_delta_qp_diff_val[i][j]);
109 595 delta_qp_in[j] = r->sps_delta_qp_in_val_minus1[i][j] + 1;
110 // Note: we cannot check qp_{in,out}[j+1] here as qp_*[j] + delta_qp_*
111 // may not fit in an 8-bit signed integer.
112
2/4
✓ Branch 9 → 10 taken 595 times.
✗ Branch 9 → 11 not taken.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 595 times.
595 if (qp_in[j] + delta_qp_in[j] > 63 || qp_out[j] + delta_qp_out > 63)
113 ✗ return AVERROR(EINVAL);
114 595 qp_in[j+1] = qp_in[j] + delta_qp_in[j];
115 595 qp_out[j+1] = qp_out[j] + delta_qp_out;
116 }
117 373 sps->chroma_qp_table[i][qp_in[0] + off] = qp_out[0];
118
2/2
✓ Branch 16 → 15 taken 14680 times.
✓ Branch 16 → 17 taken 373 times.
15053 for (int k = qp_in[0] - 1 + off; k >= 0; k--)
119 14680 sps->chroma_qp_table[i][k] = av_clip(sps->chroma_qp_table[i][k+1]-1, -off, 63);
120
121
2/2
✓ Branch 22 → 18 taken 595 times.
✓ Branch 22 → 23 taken 373 times.
968 for (int j = 0; j < num_points_in_qp_table; j++) {
122 595 int sh = delta_qp_in[j] >> 1;
123
2/2
✓ Branch 20 → 19 taken 5745 times.
✓ Branch 20 → 21 taken 595 times.
6340 for (int k = qp_in[j] + 1 + off, m = 1; k <= qp_in[j+1] + off; k++, m++) {
124 5745 sps->chroma_qp_table[i][k] = sps->chroma_qp_table[i][qp_in[j] + off] +
125 5745 ((qp_out[j+1] - qp_out[j]) * m + sh) / delta_qp_in[j];
126 }
127 }
128
2/2
✓ Branch 25 → 24 taken 7358 times.
✓ Branch 25 → 26 taken 373 times.
7731 for (int k = qp_in[num_points_in_qp_table] + 1 + off; k <= 63 + off; k++)
129 7358 sps->chroma_qp_table[i][k] = av_clip(sps->chroma_qp_table[i][k-1] + 1, -sps->qp_bd_offset, 63);
130 }
131
2/2
✓ Branch 28 → 29 taken 364 times.
✓ Branch 28 → 30 taken 3 times.
367 if (r->sps_same_qp_table_for_chroma_flag) {
132 364 memcpy(&sps->chroma_qp_table[1], &sps->chroma_qp_table[0], sizeof(sps->chroma_qp_table[0]));
133 364 memcpy(&sps->chroma_qp_table[2], &sps->chroma_qp_table[0], sizeof(sps->chroma_qp_table[0]));
134 }
135
136 367 return 0;
137 }
138
139 370 static void sps_poc(VVCSPS *sps)
140 {
141 370 sps->max_pic_order_cnt_lsb = 1 << (sps->r->sps_log2_max_pic_order_cnt_lsb_minus4 + 4);
142 370 }
143
144 370 static void sps_inter(VVCSPS *sps)
145 {
146 370 const H266RawSPS *r = sps->r;
147
148 370 sps->max_num_merge_cand = 6 - r->sps_six_minus_max_num_merge_cand;
149 370 sps->max_num_ibc_merge_cand = 6 - r->sps_six_minus_max_num_ibc_merge_cand;
150
151
2/2
✓ Branch 2 → 3 taken 88 times.
✓ Branch 2 → 5 taken 282 times.
370 if (sps->r->sps_gpm_enabled_flag) {
152 88 sps->max_num_gpm_merge_cand = 2;
153
1/2
✓ Branch 3 → 4 taken 88 times.
✗ Branch 3 → 5 not taken.
88 if (sps->max_num_merge_cand >= 3)
154 88 sps->max_num_gpm_merge_cand = sps->max_num_merge_cand - r->sps_max_num_merge_cand_minus_max_num_gpm_cand;
155 }
156
157 370 sps->log2_parallel_merge_level = r->sps_log2_parallel_merge_level_minus2 + 2;
158 370 }
159
160 370 static void sps_partition_constraints(VVCSPS* sps)
161 {
162 370 const H266RawSPS *r = sps->r;
163
164 370 sps->ctb_log2_size_y = r->sps_log2_ctu_size_minus5 + 5;
165 370 sps->ctb_size_y = 1 << sps->ctb_log2_size_y;
166 370 sps->min_cb_log2_size_y = r->sps_log2_min_luma_coding_block_size_minus2 + 2;
167 370 sps->min_cb_size_y = 1 << sps->min_cb_log2_size_y;
168
2/2
✓ Branch 2 → 3 taken 354 times.
✓ Branch 2 → 4 taken 16 times.
370 sps->max_tb_size_y = 1 << (r->sps_max_luma_transform_size_64_flag ? 6 : 5);
169 370 sps->max_ts_size = 1 << (r->sps_log2_transform_skip_max_size_minus2 + 2);
170 370 }
171
172 370 static void sps_ladf(VVCSPS* sps)
173 {
174 370 const H266RawSPS *r = sps->r;
175
176
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 368 times.
370 if (r->sps_ladf_enabled_flag) {
177 2 sps->num_ladf_intervals = r->sps_num_ladf_intervals_minus2 + 2;
178 2 sps->ladf_interval_lower_bound[0] = 0;
179
2/2
✓ Branch 5 → 4 taken 4 times.
✓ Branch 5 → 6 taken 2 times.
6 for (int i = 0; i < sps->num_ladf_intervals - 1; i++) {
180 4 sps->ladf_interval_lower_bound[i + 1] =
181 4 sps->ladf_interval_lower_bound[i] + r->sps_ladf_delta_threshold_minus1[i] + 1;
182 }
183 }
184 370 }
185
186 #define EXTENDED_SAR 255
187 9 static void sps_vui(AVCodecContext *c, const H266RawVUI *vui)
188 {
189 9 AVRational sar = (AVRational){ 0, 1 };
190
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 8 taken 7 times.
9 if (vui->vui_aspect_ratio_info_present_flag) {
191
1/2
✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 5 not taken.
2 if (vui->vui_aspect_ratio_idc < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect))
192 2 sar = ff_h2645_pixel_aspect[vui->vui_aspect_ratio_idc];
193
0/2
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ else if (vui->vui_aspect_ratio_idc == EXTENDED_SAR) {
194 ✗ sar = (AVRational){ vui->vui_sar_width, vui->vui_sar_height };
195 } else {
196 ✗ av_log(c, AV_LOG_WARNING, "Unknown SAR index: %u.\n", vui->vui_aspect_ratio_idc);
197 }
198 }
199 9 ff_set_sar(c, sar);
200
201
2/2
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 22 taken 7 times.
9 if (vui->vui_colour_description_present_flag) {
202 2 c->color_primaries = vui->vui_colour_primaries;
203 2 c->color_trc = vui->vui_transfer_characteristics;
204 2 c->colorspace = vui->vui_matrix_coeffs;
205
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 2 times.
2 c->color_range = vui->vui_full_range_flag ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
206
207 // Set invalid values to "unspecified"
208
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 2 times.
2 if (!av_color_primaries_name(c->color_primaries))
209 ✗ c->color_primaries = AVCOL_PRI_UNSPECIFIED;
210
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 2 times.
2 if (!av_color_transfer_name(c->color_trc))
211 ✗ c->color_trc = AVCOL_TRC_UNSPECIFIED;
212
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 23 taken 2 times.
2 if (!av_color_space_name(c->colorspace))
213 ✗ c->colorspace = AVCOL_SPC_UNSPECIFIED;
214 } else {
215 7 c->color_primaries = AVCOL_PRI_UNSPECIFIED;
216 7 c->color_trc = AVCOL_TRC_UNSPECIFIED;
217 7 c->colorspace = AVCOL_SPC_UNSPECIFIED;
218 7 c->color_range = AVCOL_RANGE_MPEG;
219 }
220 9 }
221
222
223 370 static void sps_export_stream_params(AVCodecContext *c, const VVCSPS *sps)
224 {
225 370 const H266RawSPS *r = sps->r;
226
227 370 c->has_b_frames = !!r->sps_dpb_params.dpb_max_num_reorder_pics[r->sps_max_sublayers_minus1];
228
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 361 times.
370 if (r->sps_vui_parameters_present_flag)
229 9 sps_vui(c, &r->vui);
230 370 }
231
232 370 static int sps_derive(VVCSPS *sps, AVCodecContext *c)
233 {
234 int ret;
235 370 const H266RawSPS *r = sps->r;
236
237 370 ret = sps_bit_depth(sps, c);
238
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 370 times.
370 if (ret < 0)
239 ✗ return ret;
240 370 sps_poc(sps);
241 370 sps_inter(sps);
242 370 sps_partition_constraints(sps);
243 370 sps_ladf(sps);
244
2/2
✓ Branch 9 → 10 taken 367 times.
✓ Branch 9 → 13 taken 3 times.
370 if (r->sps_chroma_format_idc != 0) {
245 367 ret = sps_chroma_qp_table(sps);
246
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 367 times.
367 if (ret < 0)
247 ✗ return ret;
248 }
249 370 sps_export_stream_params(c, sps);
250
251 370 return 0;
252 }
253
254 370 static void sps_free(AVRefStructOpaque opaque, void *obj)
255 {
256 370 VVCSPS *sps = obj;
257 370 av_refstruct_unref(&sps->r);
258 370 }
259
260 370 static const VVCSPS *sps_alloc(const H266RawSPS *rsps, AVCodecContext *c)
261 {
262 int ret;
263 370 VVCSPS *sps = av_refstruct_alloc_ext(sizeof(*sps), 0, NULL, sps_free);
264
265
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 370 times.
370 if (!sps)
266 ✗ return NULL;
267
268 370 av_refstruct_replace(&sps->r, rsps);
269
270 370 ret = sps_derive(sps, c);
271
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 370 times.
370 if (ret < 0)
272 ✗ goto fail;
273
274 370 return sps;
275
276 ✗ fail:
277 ✗ av_refstruct_unref(&sps);
278 ✗ return NULL;
279 }
280
281 2421 static int decode_sps(VVCParamSets *ps, AVCodecContext *c, const H266RawSPS *rsps, int is_clvss)
282 {
283 2421 VVCContext *s = c->priv_data;
284 2421 const int sps_id = rsps->sps_seq_parameter_set_id;
285 2421 const VVCSPS *old_sps = ps->sps_list[sps_id];
286 const VVCSPS *sps;
287
288
2/2
✓ Branch 2 → 3 taken 379 times.
✓ Branch 2 → 4 taken 2042 times.
2421 if (is_clvss) {
289 379 ps->sps_id_used = 0;
290 379 s->seq_decode = (s->seq_decode + 1) & 0xff;
291 }
292
293
2/2
✓ Branch 4 → 5 taken 2311 times.
✓ Branch 4 → 10 taken 110 times.
2421 if (old_sps) {
294
4/4
✓ Branch 5 → 6 taken 557 times.
✓ Branch 5 → 7 taken 1754 times.
✓ Branch 6 → 7 taken 297 times.
✓ Branch 6 → 8 taken 260 times.
2311 if (old_sps->r == rsps || !memcmp(old_sps->r, rsps, sizeof(*old_sps->r))) {
295 2051 ps->sps_id_used |= (1 << sps_id);
296 2051 return 0;
297
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 260 times.
260 } else if (ps->sps_id_used & (1 << sps_id))
298 ✗ return AVERROR_INVALIDDATA;
299 }
300
301 370 sps = sps_alloc(rsps, c);
302
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 370 times.
370 if (!sps)
303 ✗ return AVERROR(ENOMEM);
304
305 370 av_refstruct_unref(&ps->sps_list[sps_id]);
306 370 ps->sps_list[sps_id] = sps;
307 370 ps->sps_id_used |= (1 << sps_id);
308
309 370 return 0;
310 }
311
312 470 static void pps_chroma_qp_offset(VVCPPS *pps)
313 {
314 470 pps->chroma_qp_offset[CB - 1] = pps->r->pps_cb_qp_offset;
315 470 pps->chroma_qp_offset[CR - 1] = pps->r->pps_cr_qp_offset;
316 470 pps->chroma_qp_offset[JCBCR - 1]= pps->r->pps_joint_cbcr_qp_offset_value;
317
2/2
✓ Branch 4 → 3 taken 2820 times.
✓ Branch 4 → 5 taken 470 times.
3290 for (int i = 0; i < 6; i++) {
318 2820 pps->chroma_qp_offset_list[i][CB - 1] = pps->r->pps_cb_qp_offset_list[i];
319 2820 pps->chroma_qp_offset_list[i][CR - 1] = pps->r->pps_cr_qp_offset_list[i];
320 2820 pps->chroma_qp_offset_list[i][JCBCR - 1]= pps->r->pps_joint_cbcr_qp_offset_list[i];
321 }
322 470 }
323
324 470 static void pps_width_height(VVCPPS *pps, const VVCSPS *sps)
325 {
326 470 const H266RawPPS *r = pps->r;
327
328 470 pps->width = r->pps_pic_width_in_luma_samples;
329 470 pps->height = r->pps_pic_height_in_luma_samples;
330
331 470 pps->ctb_width = AV_CEIL_RSHIFT(pps->width, sps->ctb_log2_size_y);
332 470 pps->ctb_height = AV_CEIL_RSHIFT(pps->height, sps->ctb_log2_size_y);
333 470 pps->ctb_count = pps->ctb_width * pps->ctb_height;
334
335 470 pps->min_cb_width = pps->width >> sps->min_cb_log2_size_y;
336 470 pps->min_cb_height = pps->height >> sps->min_cb_log2_size_y;
337
338 470 pps->min_pu_width = pps->width >> MIN_PU_LOG2;
339 470 pps->min_pu_height = pps->height >> MIN_PU_LOG2;
340 470 pps->min_tu_width = pps->width >> MIN_TU_LOG2;
341 470 pps->min_tu_height = pps->height >> MIN_TU_LOG2;
342
343 470 pps->width32 = AV_CEIL_RSHIFT(pps->width, 5);
344 470 pps->height32 = AV_CEIL_RSHIFT(pps->height, 5);
345 470 pps->width64 = AV_CEIL_RSHIFT(pps->width, 6);
346 470 pps->height64 = AV_CEIL_RSHIFT(pps->height, 6);
347 470 }
348
349 470 static int pps_bd(VVCPPS *pps)
350 {
351 470 const H266RawPPS *r = pps->r;
352
353 470 pps->col_bd = av_calloc(r->num_tile_columns + 1, sizeof(*pps->col_bd));
354 470 pps->row_bd = av_calloc(r->num_tile_rows + 1, sizeof(*pps->row_bd));
355 470 pps->ctb_to_col_bd = av_calloc(pps->ctb_width + 1, sizeof(*pps->ctb_to_col_bd));
356 470 pps->ctb_to_row_bd = av_calloc(pps->ctb_height + 1, sizeof(*pps->ctb_to_col_bd));
357
4/8
✓ Branch 6 → 7 taken 470 times.
✗ Branch 6 → 10 not taken.
✓ Branch 7 → 8 taken 470 times.
✗ Branch 7 → 10 not taken.
✓ Branch 8 → 9 taken 470 times.
✗ Branch 8 → 10 not taken.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 470 times.
470 if (!pps->col_bd || !pps->row_bd || !pps->ctb_to_col_bd || !pps->ctb_to_row_bd)
358 ✗ return AVERROR(ENOMEM);
359
360
2/2
✓ Branch 16 → 12 taken 588 times.
✓ Branch 16 → 17 taken 470 times.
1058 for (int i = 0, j = 0; i < r->num_tile_columns; i++) {
361 588 pps->col_bd[i] = j;
362 588 j += r->col_width_val[i];
363
2/2
✓ Branch 14 → 13 taken 2202 times.
✓ Branch 14 → 15 taken 588 times.
2790 for (int k = pps->col_bd[i]; k < j; k++)
364 2202 pps->ctb_to_col_bd[k] = pps->col_bd[i];
365 }
366 470 pps->col_bd[r->num_tile_columns] = pps->ctb_to_col_bd[pps->ctb_width] = pps->ctb_width;
367
368
2/2
✓ Branch 22 → 18 taken 573 times.
✓ Branch 22 → 23 taken 470 times.
1043 for (int i = 0, j = 0; i < r->num_tile_rows; i++) {
369 573 pps->row_bd[i] = j;
370 573 j += r->row_height_val[i];
371
2/2
✓ Branch 20 → 19 taken 1638 times.
✓ Branch 20 → 21 taken 573 times.
2211 for (int k = pps->row_bd[i]; k < j; k++)
372 1638 pps->ctb_to_row_bd[k] = pps->row_bd[i];
373 }
374 470 pps->row_bd[r->num_tile_rows] = pps->ctb_to_row_bd[pps->ctb_height] = pps->ctb_height;
375
376 470 return 0;
377 }
378
379
380 163 static int next_tile_idx(int tile_idx, const int i, const H266RawPPS *r)
381 {
382
2/2
✓ Branch 2 → 3 taken 61 times.
✓ Branch 2 → 4 taken 102 times.
163 if (r->pps_tile_idx_delta_present_flag) {
383 61 tile_idx += r->pps_tile_idx_delta_val[i];
384 } else {
385 102 tile_idx += r->pps_slice_width_in_tiles_minus1[i] + 1;
386
2/2
✓ Branch 4 → 5 taken 57 times.
✓ Branch 4 → 6 taken 45 times.
102 if (tile_idx % r->num_tile_columns == 0)
387 57 tile_idx += (r->pps_slice_height_in_tiles_minus1[i]) * r->num_tile_columns;
388 }
389 163 return tile_idx;
390 }
391
392 163 static void tile_xy(int *tile_x, int *tile_y, const int tile_idx, const VVCPPS *pps)
393 {
394 163 *tile_x = tile_idx % pps->r->num_tile_columns;
395 163 *tile_y = tile_idx / pps->r->num_tile_columns;
396 163 }
397
398 996 static void ctu_xy(int *rx, int *ry, const int tile_x, const int tile_y, const VVCPPS *pps)
399 {
400 996 *rx = pps->col_bd[tile_x];
401 996 *ry = pps->row_bd[tile_y];
402 996 }
403
404 10693 static int ctu_rs(const int rx, const int ry, const VVCPPS *pps)
405 {
406 10693 return pps->ctb_width * ry + rx;
407 }
408
409 1052 static int pps_add_ctus(VVCPPS *pps, int *off, const int rx, const int ry,
410 const int w, const int h)
411 {
412 1052 int start = *off;
413
2/2
✓ Branch 10 → 3 taken 2503 times.
✓ Branch 10 → 11 taken 1052 times.
3555 for (int y = 0; y < h; y++) {
414
2/2
✓ Branch 8 → 4 taken 10693 times.
✓ Branch 8 → 9 taken 2503 times.
13196 for (int x = 0; x < w; x++) {
415
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 10693 times.
10693 if (*off >= pps->ctb_count)
416 ✗ return AVERROR_INVALIDDATA;
417 10693 pps->ctb_addr_in_slice[*off] = ctu_rs(rx + x, ry + y, pps);
418 10693 (*off)++;
419 }
420 }
421 1052 return *off - start;
422 }
423
424 2 static int pps_single_slice_picture(VVCPPS *pps, int *off)
425 {
426 2 pps->num_ctus_in_slice[0] = 0;
427
2/2
✓ Branch 10 → 3 taken 4 times.
✓ Branch 10 → 11 taken 2 times.
6 for (int j = 0; j < pps->r->num_tile_rows; j++) {
428
2/2
✓ Branch 8 → 4 taken 8 times.
✓ Branch 8 → 9 taken 4 times.
12 for (int i = 0; i < pps->r->num_tile_columns; i++) {
429 8 const int ret = pps_add_ctus(pps, off,
430 8 pps->col_bd[i], pps->row_bd[j],
431 8 pps->r->col_width_val[i], pps->r->row_height_val[j]);
432
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 8 times.
8 if (ret < 0)
433 ✗ return ret;
434 8 pps->num_ctus_in_slice[0] += ret;
435 }
436 }
437
438 2 return 0;
439 }
440
441 64 static int tile_at_or_after(const uint16_t *bd, const int num_tiles, const int ctb_pos)
442 {
443 64 int tile = 0;
444
445
4/4
✓ Branch 4 → 5 taken 148 times.
✓ Branch 4 → 6 taken 12 times.
✓ Branch 5 → 3 taken 96 times.
✓ Branch 5 → 6 taken 52 times.
160 while (tile < num_tiles && bd[tile] < ctb_pos)
446 96 tile++;
447
448 64 return tile;
449 }
450
451 16 static void subpic_tiles(int *tile_x, int *tile_y, int *tile_x_end, int *tile_y_end,
452 const VVCSPS *sps, const VVCPPS *pps, const int i)
453 {
454 16 const H266RawPPS *r = pps->r;
455 16 const int rx = sps->r->sps_subpic_ctu_top_left_x[i];
456 16 const int ry = sps->r->sps_subpic_ctu_top_left_y[i];
457
458 16 *tile_x = tile_at_or_after(pps->col_bd, r->num_tile_columns, rx);
459 16 *tile_y = tile_at_or_after(pps->row_bd, r->num_tile_rows, ry);
460 16 *tile_x_end = tile_at_or_after(pps->col_bd, r->num_tile_columns, rx + sps->r->sps_subpic_width_minus1[i] + 1);
461 16 *tile_y_end = tile_at_or_after(pps->row_bd, r->num_tile_rows, ry + sps->r->sps_subpic_height_minus1[i] + 1);
462 16 }
463
464 ✗ static int pps_subpic_less_than_one_tile_slice(VVCPPS *pps, const VVCSPS *sps, const int i, const int tx, const int ty, int *off)
465 {
466 ✗ const int ret = pps_add_ctus(pps, off,
467 ✗ sps->r->sps_subpic_ctu_top_left_x[i], sps->r->sps_subpic_ctu_top_left_y[i],
468 ✗ sps->r->sps_subpic_width_minus1[i] + 1, sps->r->sps_subpic_height_minus1[i] + 1);
469
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (ret < 0)
470 ✗ return ret;
471
472 ✗ pps->num_ctus_in_slice[i] = ret;
473 ✗ return 0;
474 }
475
476 16 static int 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,
477 const int i, int *off)
478 {
479
2/2
✓ Branch 10 → 3 taken 16 times.
✓ Branch 10 → 11 taken 16 times.
32 for (int ty = tile_y; ty < y_end; ty++) {
480
2/2
✓ Branch 8 → 4 taken 16 times.
✓ Branch 8 → 9 taken 16 times.
32 for (int tx = tile_x; tx < x_end; tx++) {
481 16 const int ret = pps_add_ctus(pps, off,
482 16 pps->col_bd[tx], pps->row_bd[ty],
483 16 pps->r->col_width_val[tx], pps->r->row_height_val[ty]);
484
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 16 times.
16 if (ret < 0)
485 ✗ return ret;
486
487 16 pps->num_ctus_in_slice[i] += ret;
488 }
489 }
490 16 return 0;
491 }
492
493 16 static int pps_subpic_slice(VVCPPS *pps, const VVCSPS *sps, const int i, int *off)
494 {
495 int tx, ty, x_end, y_end;
496
497 16 pps->slice_start_offset[i] = *off;
498 16 pps->num_ctus_in_slice[i] = 0;
499
500 16 subpic_tiles(&tx, &ty, &x_end, &y_end, sps, pps, i);
501
2/4
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 7 not taken.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 16 times.
16 if (ty + 1 == y_end && sps->r->sps_subpic_height_minus1[i] + 1 < pps->r->row_height_val[ty])
502 ✗ return pps_subpic_less_than_one_tile_slice(pps, sps, i, tx, ty, off);
503 else
504 16 return pps_subpic_one_or_more_tiles_slice(pps, tx, ty, x_end, y_end, i, off);
505 }
506
507 4 static int pps_single_slice_per_subpic(VVCPPS *pps, const VVCSPS *sps, int *off)
508 {
509 int ret;
510
511
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 6 taken 2 times.
4 if (!sps->r->sps_subpic_info_present_flag) {
512 2 ret = pps_single_slice_picture(pps, off);
513
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 12 taken 2 times.
2 if (ret < 0)
514 ✗ return ret;
515 } else {
516
2/2
✓ Branch 11 → 7 taken 16 times.
✓ Branch 11 → 12 taken 2 times.
18 for (int i = 0; i < pps->r->pps_num_slices_in_pic_minus1 + 1; i++) {
517 16 const int ret = pps_subpic_slice(pps, sps, i, off);
518
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 16 times.
16 if (ret < 0)
519 ✗ return ret;
520 }
521 }
522 4 return 0;
523 }
524
525 95 static int pps_one_tile_slices(VVCPPS *pps, const int tile_idx, int i, int *off)
526 {
527 95 const H266RawPPS *r = pps->r;
528 int rx, ry, ctu_y_end, tile_x, tile_y;
529
530 95 tile_xy(&tile_x, &tile_y, tile_idx, pps);
531 95 ctu_xy(&rx, &ry, tile_x, tile_y, pps);
532 95 ctu_y_end = ry + r->row_height_val[tile_y];
533
2/2
✓ Branch 9 → 5 taken 127 times.
✓ Branch 9 → 10 taken 95 times.
222 while (ry < ctu_y_end) {
534 int ret;
535 127 pps->slice_start_offset[i] = *off;
536 127 ret = pps_add_ctus(pps, off, rx, ry,
537 127 r->col_width_val[tile_x], r->slice_height_in_ctus[i]);
538
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 127 times.
127 if (ret < 0)
539 ✗ return ret;
540 127 pps->num_ctus_in_slice[i] = ret;
541 127 ry += r->slice_height_in_ctus[i++];
542 }
543 95 i--;
544 95 return i;
545 }
546
547 68 static int pps_multi_tiles_slice(VVCPPS *pps, const int tile_idx, const int i, int *off, bool *tile_in_slice)
548 {
549 68 const H266RawPPS *r = pps->r;
550 int rx, ry, tile_x, tile_y;
551
552 68 tile_xy(&tile_x, &tile_y, tile_idx, pps);
553 68 pps->slice_start_offset[i] = *off;
554 68 pps->num_ctus_in_slice[i] = 0;
555
2/2
✓ Branch 14 → 4 taken 128 times.
✓ Branch 14 → 15 taken 68 times.
196 for (int ty = tile_y; ty <= tile_y + r->pps_slice_height_in_tiles_minus1[i]; ty++) {
556
2/2
✓ Branch 12 → 5 taken 424 times.
✓ Branch 12 → 13 taken 128 times.
552 for (int tx = tile_x; tx <= tile_x + r->pps_slice_width_in_tiles_minus1[i]; tx++) {
557 int ret;
558 424 const int idx = ty * r->num_tile_columns + tx;
559
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 424 times.
424 if (tile_in_slice[idx])
560 ✗ return AVERROR_INVALIDDATA;
561 424 tile_in_slice[idx] = true;
562 424 ctu_xy(&rx, &ry, tx, ty, pps);
563 424 ret = pps_add_ctus(pps, off, rx, ry,
564 424 r->col_width_val[tx], r->row_height_val[ty]);
565
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 424 times.
424 if (ret < 0)
566 ✗ return ret;
567 424 pps->num_ctus_in_slice[i] += ret;
568 }
569 }
570
571 68 return 0;
572 }
573
574 41 static int pps_rect_slice(VVCPPS *pps, const VVCSPS *sps)
575 {
576 41 const H266RawPPS *r = pps->r;
577 41 bool tile_in_slice[VVC_MAX_TILES_PER_AU] = {false};
578 41 int tile_idx = 0, off = 0, ret;
579
580
2/2
✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 5 taken 37 times.
41 if (r->pps_single_slice_per_subpic_flag) {
581 4 return pps_single_slice_per_subpic(pps, sps, &off);
582 }
583
584
2/2
✓ Branch 19 → 6 taken 163 times.
✓ Branch 19 → 20 taken 37 times.
200 for (int i = 0; i < r->pps_num_slices_in_pic_minus1 + 1; i++) {
585
2/2
✓ Branch 6 → 7 taken 101 times.
✓ Branch 6 → 14 taken 62 times.
163 if (!r->pps_slice_width_in_tiles_minus1[i] &&
586
2/2
✓ Branch 7 → 8 taken 95 times.
✓ Branch 7 → 14 taken 6 times.
101 !r->pps_slice_height_in_tiles_minus1[i]) {
587
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 95 times.
95 if (tile_in_slice[tile_idx])
588 ✗ return AVERROR_INVALIDDATA;
589 95 tile_in_slice[tile_idx] = true;
590 95 ret = pps_one_tile_slices(pps, tile_idx, i, &off);
591
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 95 times.
95 if (ret < 0)
592 ✗ return ret;
593 95 i = ret;
594 } else {
595 68 ret = pps_multi_tiles_slice(pps, tile_idx, i, &off, tile_in_slice);
596
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 68 times.
68 if (ret < 0)
597 ✗ return ret;
598 }
599 163 tile_idx = next_tile_idx(tile_idx, i, r);
600 }
601
602
2/2
✓ Branch 24 → 21 taken 519 times.
✓ Branch 24 → 25 taken 37 times.
556 for (int i = 0; i < r->num_tiles_in_pic; i++) {
603
1/2
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 519 times.
519 if (!tile_in_slice[i])
604 ✗ return AVERROR_INVALIDDATA;
605 }
606
607 37 return 0;
608 }
609
610 429 static int pps_no_rect_slice(VVCPPS* pps)
611 {
612 429 const H266RawPPS* r = pps->r;
613 429 int rx, ry, off = 0;
614
615
2/2
✓ Branch 11 → 3 taken 437 times.
✓ Branch 11 → 12 taken 429 times.
866 for (int tile_y = 0; tile_y < r->num_tile_rows; tile_y++) {
616
2/2
✓ Branch 9 → 4 taken 477 times.
✓ Branch 9 → 10 taken 437 times.
914 for (int tile_x = 0; tile_x < r->num_tile_columns; tile_x++) {
617 int ret;
618 477 ctu_xy(&rx, &ry, tile_x, tile_y, pps);
619 477 ret = pps_add_ctus(pps, &off, rx, ry, r->col_width_val[tile_x], r->row_height_val[tile_y]);
620
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 477 times.
477 if (ret < 0)
621 ✗ return ret;
622 }
623 }
624
625 429 return 0;
626 }
627
628 470 static int pps_slice_map(VVCPPS *pps, const VVCSPS *sps)
629 {
630 int ret;
631
632 470 pps->ctb_addr_in_slice = av_calloc(pps->ctb_count, sizeof(*pps->ctb_addr_in_slice));
633
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 470 times.
470 if (!pps->ctb_addr_in_slice)
634 ✗ return AVERROR(ENOMEM);
635
636
2/2
✓ Branch 5 → 6 taken 41 times.
✓ Branch 5 → 8 taken 429 times.
470 if (pps->r->pps_rect_slice_flag)
637 41 return pps_rect_slice(pps, sps);
638
639 429 ret = pps_no_rect_slice(pps);
640
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 429 times.
429 if (ret < 0)
641 ✗ return ret;
642
643 429 return 0;
644 }
645
646 470 static void pps_ref_wraparound_offset(VVCPPS *pps, const VVCSPS *sps)
647 {
648 470 const H266RawPPS *r = pps->r;
649
650
2/2
✓ Branch 2 → 3 taken 3 times.
✓ Branch 2 → 4 taken 467 times.
470 if (r->pps_ref_wraparound_enabled_flag)
651 3 pps->ref_wraparound_offset = (pps->width / sps->min_cb_size_y) - r->pps_pic_width_minus_wraparound_offset;
652 470 }
653
654 470 static void pps_subpic(VVCPPS *pps, const VVCSPS *sps)
655 {
656 470 const H266RawSPS *rsps = sps->r;
657
2/2
✓ Branch 7 → 3 taken 550 times.
✓ Branch 7 → 8 taken 470 times.
1020 for (int i = 0; i < rsps->sps_num_subpics_minus1 + 1; i++) {
658
2/2
✓ Branch 3 → 4 taken 109 times.
✓ Branch 3 → 5 taken 441 times.
550 if (rsps->sps_subpic_treated_as_pic_flag[i]) {
659 109 pps->subpic_x[i] = rsps->sps_subpic_ctu_top_left_x[i] << sps->ctb_log2_size_y;
660 109 pps->subpic_y[i] = rsps->sps_subpic_ctu_top_left_y[i] << sps->ctb_log2_size_y;
661 109 pps->subpic_width[i] = FFMIN(pps->width - pps->subpic_x[i], (rsps->sps_subpic_width_minus1[i] + 1) << sps->ctb_log2_size_y);
662 109 pps->subpic_height[i] = FFMIN(pps->height - pps->subpic_y[i], (rsps->sps_subpic_height_minus1[i] + 1) << sps->ctb_log2_size_y);
663 } else {
664 441 pps->subpic_x[i] = 0;
665 441 pps->subpic_y[i] = 0;
666 441 pps->subpic_width[i] = pps->width;
667 441 pps->subpic_height[i] = pps->height;
668 }
669 }
670 470 }
671
672 470 static int pps_derive(VVCPPS *pps, const VVCSPS *sps)
673 {
674 int ret;
675
676 470 pps_chroma_qp_offset(pps);
677 470 pps_width_height(pps, sps);
678
679 470 ret = pps_bd(pps);
680
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 470 times.
470 if (ret < 0)
681 ✗ return ret;
682
683 470 ret = pps_slice_map(pps, sps);
684
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 470 times.
470 if (ret < 0)
685 ✗ return ret;
686
687 470 pps_ref_wraparound_offset(pps, sps);
688 470 pps_subpic(pps, sps);
689
690 470 return 0;
691 }
692
693 470 static void pps_free(AVRefStructOpaque opaque, void *obj)
694 {
695 470 VVCPPS *pps = obj;
696
697 470 av_refstruct_unref(&pps->r);
698
699 470 av_freep(&pps->col_bd);
700 470 av_freep(&pps->row_bd);
701 470 av_freep(&pps->ctb_to_col_bd);
702 470 av_freep(&pps->ctb_to_row_bd);
703 470 av_freep(&pps->ctb_addr_in_slice);
704 470 }
705
706 470 static const VVCPPS *pps_alloc(const H266RawPPS *rpps, const VVCSPS *sps)
707 {
708 int ret;
709 470 VVCPPS *pps = av_refstruct_alloc_ext(sizeof(*pps), 0, NULL, pps_free);
710
711
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 470 times.
470 if (!pps)
712 ✗ return NULL;
713
714 470 av_refstruct_replace(&pps->r, rpps);
715
716 470 ret = pps_derive(pps, sps);
717
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 470 times.
470 if (ret < 0)
718 ✗ goto fail;
719
720 470 return pps;
721
722 ✗ fail:
723 ✗ av_refstruct_unref(&pps);
724 ✗ return NULL;
725 }
726
727 2421 static int decode_pps(VVCParamSets *ps, const H266RawPPS *rpps)
728 {
729 2421 int ret = 0;
730 2421 const int pps_id = rpps->pps_pic_parameter_set_id;
731 2421 const int sps_id = rpps->pps_seq_parameter_set_id;
732 2421 const VVCPPS *old_pps = ps->pps_list[pps_id];
733 const VVCPPS *pps;
734
735
4/4
✓ Branch 2 → 3 taken 2288 times.
✓ Branch 2 → 5 taken 133 times.
✓ Branch 3 → 4 taken 1951 times.
✓ Branch 3 → 5 taken 337 times.
2421 if (old_pps && old_pps->r == rpps)
736 1951 return 0;
737
738 470 pps = pps_alloc(rpps, ps->sps_list[sps_id]);
739
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 470 times.
470 if (!pps)
740 ✗ return AVERROR(ENOMEM);
741
742 470 av_refstruct_unref(&ps->pps_list[pps_id]);
743 470 ps->pps_list[pps_id] = pps;
744
745 470 return ret;
746 }
747
748 2421 static int decode_ps(VVCParamSets *ps, AVCodecContext *c, const SliceContext *sc, int is_clvss)
749 {
750 2421 const H266RawSlice *sl = sc->ref;
751 2421 const H266RawPPS *rpps = sl->pps;
752 2421 const H266RawSPS *rsps = sl->sps;
753 int ret;
754
755
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2421 times.
2421 if (!rpps)
756 ✗ return AVERROR_INVALIDDATA;
757
758
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 2421 times.
2421 if (!rsps)
759 ✗ return AVERROR_INVALIDDATA;
760
761 2421 ret = decode_sps(ps, c, rsps, is_clvss);
762
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 2421 times.
2421 if (ret < 0)
763 ✗ return ret;
764
765
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 12 taken 2421 times.
2421 if (rsps->sps_log2_ctu_size_minus5 > 2) {
766 // CTU > 128 are reserved in vvc spec v3
767 ✗ av_log(c, AV_LOG_ERROR, "CTU size > 128. \n");
768 ✗ return AVERROR_PATCHWELCOME;
769 }
770
771 2421 ret = decode_pps(ps, rpps);
772
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 2421 times.
2421 if (ret < 0)
773 ✗ return ret;
774
775 2421 return 0;
776 }
777
778 #define WEIGHT_TABLE(x) \
779 w->nb_weights[L##x] = r->num_weights_l##x; \
780 for (int i = 0; i < w->nb_weights[L##x]; i++) { \
781 w->weight_flag[L##x][LUMA][i] = r->luma_weight_l##x##_flag[i]; \
782 w->weight_flag[L##x][CHROMA][i] = r->chroma_weight_l##x##_flag[i]; \
783 w->weight[L##x][LUMA][i] = denom[LUMA] + r->delta_luma_weight_l##x[i]; \
784 w->offset[L##x][LUMA][i] = r->luma_offset_l##x[i]; \
785 for (int j = CB; j <= CR; j++) { \
786 w->weight[L##x][j][i] = denom[CHROMA] + r->delta_chroma_weight_l##x[i][j - 1]; \
787 w->offset[L##x][j][i] = 128 + r->delta_chroma_offset_l##x[i][j - 1]; \
788 w->offset[L##x][j][i] -= (128 * w->weight[L##x][j][i]) >> w->log2_denom[CHROMA]; \
789 w->offset[L##x][j][i] = av_clip_intp2(w->offset[L##x][j][i], 7); \
790 } \
791 } \
792
793 75 static void pred_weight_table(PredWeightTable *w, const H266RawPredWeightTable *r)
794 {
795 int denom[2];
796
797 75 w->log2_denom[LUMA] = r->luma_log2_weight_denom;
798 75 w->log2_denom[CHROMA] = w->log2_denom[LUMA] + r->delta_chroma_log2_weight_denom;
799 75 denom[LUMA] = 1 << w->log2_denom[LUMA];
800 75 denom[CHROMA] = 1 << w->log2_denom[CHROMA];
801
4/4
✓ Branch 5 → 4 taken 834 times.
✓ Branch 5 → 6 taken 417 times.
✓ Branch 7 → 3 taken 417 times.
✓ Branch 7 → 8 taken 75 times.
1326 WEIGHT_TABLE(0)
802
4/4
✓ Branch 11 → 10 taken 712 times.
✓ Branch 11 → 12 taken 356 times.
✓ Branch 13 → 9 taken 356 times.
✓ Branch 13 → 14 taken 75 times.
1143 WEIGHT_TABLE(1)
803 75 }
804
805 // 8.3.1 Decoding process for picture order count
806 2421 static int ph_compute_poc(const H266RawPictureHeader *ph, const H266RawSPS *sps, const int poc_tid0, const int is_clvss)
807 {
808 2421 const int max_poc_lsb = 1 << (sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4);
809 2421 const int prev_poc_lsb = poc_tid0 % max_poc_lsb;
810 2421 const int prev_poc_msb = poc_tid0 - prev_poc_lsb;
811 2421 const int poc_lsb = ph->ph_pic_order_cnt_lsb;
812 int poc_msb;
813
814
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2421 times.
2421 if (ph->ph_poc_msb_cycle_present_flag) {
815 ✗ poc_msb = ph->ph_poc_msb_cycle_val * max_poc_lsb;
816
2/2
✓ Branch 4 → 5 taken 379 times.
✓ Branch 4 → 6 taken 2042 times.
2421 } else if (is_clvss) {
817 379 poc_msb = 0;
818 } else {
819
4/4
✓ Branch 6 → 7 taken 613 times.
✓ Branch 6 → 9 taken 1429 times.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 9 taken 612 times.
2042 if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2)
820 1 poc_msb = prev_poc_msb + max_poc_lsb;
821
3/4
✓ Branch 9 → 10 taken 1429 times.
✓ Branch 9 → 12 taken 612 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 1429 times.
2041 else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2)
822 ✗ poc_msb = prev_poc_msb - max_poc_lsb;
823 else
824 2041 poc_msb = prev_poc_msb;
825 }
826
827 2421 return poc_msb + poc_lsb;
828 }
829
830 778240 static av_always_inline uint16_t lmcs_derive_lut_sample(uint16_t sample,
831 uint16_t *pivot1, uint16_t *pivot2, uint16_t *scale_coeff, const int idx, const int max)
832 {
833 778240 const int lut_sample =
834 778240 pivot1[idx] + ((scale_coeff[idx] * (sample - pivot2[idx]) + (1<< 10)) >> 11);
835 778240 return av_clip(lut_sample, 0, max - 1);
836 }
837
838 //8.8.2.2 Inverse mapping process for a luma sample
839 380 static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266RawSPS *sps)
840 {
841 380 const int bit_depth = (sps->sps_bitdepth_minus8 + 8);
842 380 const int max = (1 << bit_depth);
843 380 const int org_cw = max / LMCS_MAX_BIN_SIZE;
844 380 const int shift = av_log2(org_cw);
845 380 const int off = 1 << (shift - 1);
846 int cw[LMCS_MAX_BIN_SIZE];
847 uint16_t input_pivot[LMCS_MAX_BIN_SIZE];
848 uint16_t scale_coeff[LMCS_MAX_BIN_SIZE];
849 uint16_t inv_scale_coeff[LMCS_MAX_BIN_SIZE];
850 380 int i, delta_crs, sum_cw = 0;
851
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 380 times.
380 if (bit_depth > LMCS_MAX_BIT_DEPTH)
852 ✗ return AVERROR_PATCHWELCOME;
853
854
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 380 times.
380 if (!rlmcs)
855 ✗ return AVERROR_INVALIDDATA;
856
857 380 lmcs->min_bin_idx = rlmcs->lmcs_min_bin_idx;
858 380 lmcs->max_bin_idx = LMCS_MAX_BIN_SIZE - 1 - rlmcs->lmcs_delta_max_bin_idx;
859
860 380 memset(cw, 0, sizeof(cw));
861
2/2
✓ Branch 8 → 7 taken 5069 times.
✓ Branch 8 → 9 taken 380 times.
5449 for (int i = lmcs->min_bin_idx; i <= lmcs->max_bin_idx; i++) {
862 5069 cw[i] = org_cw + (1 - 2 * rlmcs->lmcs_delta_sign_cw_flag[i]) * rlmcs->lmcs_delta_abs_cw[i];
863 5069 sum_cw += cw[i];
864 }
865
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 380 times.
380 if (sum_cw > (1 << bit_depth) - 1)
866 ✗ return AVERROR_INVALIDDATA;
867
868 380 delta_crs = (1 - 2 * rlmcs->lmcs_delta_sign_crs_flag) * rlmcs->lmcs_delta_abs_crs;
869
870 380 lmcs->pivot[0] = 0;
871
2/2
✓ Branch 24 → 12 taken 6080 times.
✓ Branch 24 → 25 taken 380 times.
6460 for (i = 0; i < LMCS_MAX_BIN_SIZE; i++) {
872 6080 input_pivot[i] = i * org_cw;
873 6080 lmcs->pivot[i + 1] = lmcs->pivot[i] + cw[i];
874
4/4
✓ Branch 12 → 13 taken 5676 times.
✓ Branch 12 → 17 taken 404 times.
✓ Branch 13 → 14 taken 5069 times.
✓ Branch 13 → 17 taken 607 times.
6080 if (i >= lmcs->min_bin_idx && i <= lmcs->max_bin_idx &&
875
2/2
✓ Branch 14 → 15 taken 4484 times.
✓ Branch 14 → 17 taken 585 times.
5069 lmcs->pivot[i] % (1 << (bit_depth - 5)) != 0 &&
876
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 4484 times.
4484 lmcs->pivot[i] >> (bit_depth - 5) == lmcs->pivot[i + 1] >> (bit_depth - 5))
877 ✗ return AVERROR_INVALIDDATA;
878 6080 scale_coeff[i] = (cw[i] * (1 << 11) + off) >> shift;
879
2/2
✓ Branch 17 → 18 taken 1011 times.
✓ Branch 17 → 19 taken 5069 times.
6080 if (cw[i] == 0) {
880 1011 inv_scale_coeff[i] = 0;
881 1011 lmcs->chroma_scale_coeff[i] = (1 << 11);
882 } else {
883 5069 const int cw_plus_d = cw[i] + delta_crs;
884
2/4
✓ Branch 19 → 20 taken 5069 times.
✗ Branch 19 → 21 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 5069 times.
5069 if (cw_plus_d < (org_cw >> 3) || cw_plus_d > ((org_cw << 3) - 1))
885 ✗ return AVERROR_INVALIDDATA;
886 5069 inv_scale_coeff[i] = org_cw * (1 << 11) / cw[i];
887 5069 lmcs->chroma_scale_coeff[i] = org_cw * (1 << 11) / cw_plus_d;
888 }
889 }
890
891 //derive lmcs_fwd_lut
892
2/2
✓ Branch 31 → 26 taken 389120 times.
✓ Branch 31 → 32 taken 380 times.
389500 for (uint16_t sample = 0; sample < max; sample++) {
893 389120 const int idx_y = sample >> shift;
894 389120 const uint16_t fwd_sample = lmcs_derive_lut_sample(sample, lmcs->pivot,
895 input_pivot, scale_coeff, idx_y, max);
896
1/2
✓ Branch 27 → 28 taken 389120 times.
✗ Branch 27 → 29 not taken.
389120 if (bit_depth > 8)
897 389120 lmcs->fwd_lut.u16[sample] = fwd_sample;
898 else
899 ✗ lmcs->fwd_lut.u8 [sample] = fwd_sample;
900
901 }
902
903 //derive lmcs_inv_lut
904 380 i = lmcs->min_bin_idx;
905
2/2
✓ Branch 42 → 33 taken 389120 times.
✓ Branch 42 → 43 taken 380 times.
389500 for (uint16_t sample = 0; sample < max; sample++) {
906 uint16_t inv_sample;
907
4/4
✓ Branch 35 → 36 taken 377976 times.
✓ Branch 35 → 37 taken 16213 times.
✓ Branch 36 → 34 taken 5069 times.
✓ Branch 36 → 37 taken 372907 times.
394189 while (i <= lmcs->max_bin_idx && sample >= lmcs->pivot[i + 1])
908 5069 i++;
909 389120 i = FFMIN(i, LMCS_MAX_BIN_SIZE - 1);
910
911 389120 inv_sample = lmcs_derive_lut_sample(sample, input_pivot, lmcs->pivot,
912 inv_scale_coeff, i, max);
913
914
1/2
✓ Branch 38 → 39 taken 389120 times.
✗ Branch 38 → 40 not taken.
389120 if (bit_depth > 8)
915 389120 lmcs->inv_lut.u16[sample] = inv_sample;
916 else
917 ✗ lmcs->inv_lut.u8 [sample] = inv_sample;
918 }
919
920 380 return 0;
921 }
922
923 2421 static int ph_max_num_subblock_merge_cand(const H266RawSPS *sps, const H266RawPictureHeader *ph)
924 {
925
2/2
✓ Branch 2 → 3 taken 1070 times.
✓ Branch 2 → 4 taken 1351 times.
2421 if (sps->sps_affine_enabled_flag)
926 1070 return 5 - sps->sps_five_minus_max_num_subblock_merge_cand;
927
1/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 1351 times.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
1351 return sps->sps_sbtmvp_enabled_flag && ph->ph_temporal_mvp_enabled_flag;
928 }
929
930 42 static int ph_vb_pos(uint16_t *vbs, uint8_t *num_vbs, const uint16_t *pos_minus_1, const uint8_t num_pos, int max, const int ctb_size_y)
931 {
932 42 max = FF_CEIL_RSHIFT(max, 3) - 2;
933
1/2
✗ Branch 9 → 3 not taken.
✓ Branch 9 → 10 taken 42 times.
42 for (int i = 0; i < num_pos; i++) {
934
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (pos_minus_1[i] > max)
935 ✗ return AVERROR_INVALIDDATA;
936
937 ✗ vbs[i] = (pos_minus_1[i] + 1) << 3;
938
939 // The distance between any two vertical virtual boundaries shall be greater than or equal to CtbSizeY luma samples
940
0/4
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 8 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ if (i && vbs[i] < vbs[i - 1] + ctb_size_y)
941 ✗ return AVERROR_INVALIDDATA;
942 }
943 42 *num_vbs = num_pos;
944
945 42 return 0;
946 }
947
948 #define VBF(f) (sps->sps_virtual_boundaries_present_flag ? sps->sps_##f : ph->r->ph_##f)
949 #define VBFS(c, d) VBF(virtual_boundary_pos_##c##_minus1), VBF(num_##d##_virtual_boundaries)
950
951 2421 static int ph_vb(VVCPH *ph, const H266RawSPS *sps, const H266RawPPS *pps)
952 {
953 2421 const int ctb_size_y = 1 << (sps->sps_log2_ctu_size_minus5 + 5);
954 int ret;
955
956
2/2
✓ Branch 2 → 3 taken 2400 times.
✓ Branch 2 → 4 taken 21 times.
2421 if (!sps->sps_virtual_boundaries_enabled_flag)
957 2400 return 0;
958
959
2/4
✓ Branch 4 → 5 taken 21 times.
✗ Branch 4 → 6 not taken.
✓ Branch 7 → 8 taken 21 times.
✗ Branch 7 → 9 not taken.
21 ret = ph_vb_pos(ph->vb_pos_x, &ph->num_ver_vbs, VBFS(x, ver), pps->pps_pic_width_in_luma_samples, ctb_size_y);
960
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 21 times.
21 if (ret < 0)
961 ✗ return ret;
962
963
2/4
✓ Branch 13 → 14 taken 21 times.
✗ Branch 13 → 15 not taken.
✓ Branch 16 → 17 taken 21 times.
✗ Branch 16 → 18 not taken.
21 ret = ph_vb_pos(ph->vb_pos_y, &ph->num_hor_vbs, VBFS(y, hor), pps->pps_pic_height_in_luma_samples, ctb_size_y);
964
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 21 times.
21 if (ret < 0)
965 ✗ return ret;
966
967 21 return 0;
968 }
969
970 2421 static int ph_derive(VVCPH *ph, const H266RawSPS *sps, const H266RawPPS *pps, const int poc_tid0, const int is_clvss)
971 {
972 int ret;
973 2421 ph->max_num_subblock_merge_cand = ph_max_num_subblock_merge_cand(sps, ph->r);
974
975 2421 ph->poc = ph_compute_poc(ph->r, sps, poc_tid0, is_clvss);
976
977
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 2421 times.
2421 if (pps->pps_wp_info_in_ph_flag)
978 ✗ pred_weight_table(&ph->pwt, &ph->r->ph_pred_weight_table);
979
980 2421 ret = ph_vb(ph, sps, pps);
981
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 2421 times.
2421 if (ret < 0)
982 ✗ return ret;
983
984 2421 return 0;
985 }
986
987 2421 static int decode_ph(VVCFrameParamSets *fps, const H266RawPictureHeader *rph, void *rph_ref,
988 const int poc_tid0, const int is_clvss)
989 {
990 int ret;
991 2421 VVCPH *ph = &fps->ph;
992 2421 const H266RawSPS *sps = fps->sps->r;
993 2421 const H266RawPPS *pps = fps->pps->r;
994
995 2421 ph->r = rph;
996 2421 av_refstruct_replace(&ph->rref, rph_ref);
997 2421 ret = ph_derive(ph, sps, pps, poc_tid0, is_clvss);
998
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 2421 times.
2421 if (ret < 0)
999 ✗ return ret;
1000
1001 2421 return 0;
1002 }
1003
1004 2421 static int decode_frame_ps(VVCFrameParamSets *fps, const VVCParamSets *ps,
1005 const SliceContext *sc, const int poc_tid0, const int is_clvss, const VVCContext *s)
1006 {
1007 2421 const H266RawSlice *sl = sc->ref;
1008 2421 const H266RawPictureHeader *ph = sl->ph;
1009 2421 const H266RawPPS *rpps = sl->pps;
1010 int ret;
1011
1012
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2421 times.
2421 if (!ph)
1013 ✗ return AVERROR_INVALIDDATA;
1014
1015
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 2421 times.
2421 if (!rpps)
1016 ✗ return AVERROR_INVALIDDATA;
1017
1018 2421 av_refstruct_replace(&fps->sps, ps->sps_list[rpps->pps_seq_parameter_set_id]);
1019 2421 av_refstruct_replace(&fps->pps, ps->pps_list[rpps->pps_pic_parameter_set_id]);
1020
1021 2421 ret = decode_ph(fps, ph, sl->ph_ref, poc_tid0, is_clvss);
1022
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 2421 times.
2421 if (ret < 0)
1023 ✗ return ret;
1024
1025
2/2
✓ Branch 11 → 12 taken 137 times.
✓ Branch 11 → 13 taken 2284 times.
2421 if (ph->ph_explicit_scaling_list_enabled_flag)
1026 137 av_refstruct_replace(&fps->sl, ps->scaling_list[ph->ph_scaling_list_aps_id]);
1027
1028
2/2
✓ Branch 13 → 14 taken 380 times.
✓ Branch 13 → 17 taken 2041 times.
2421 if (ph->ph_lmcs_enabled_flag) {
1029 380 ret = lmcs_derive_lut(&fps->lmcs, ps->lmcs_list[ph->ph_lmcs_aps_id], fps->sps->r);
1030
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 380 times.
380 if (ret < 0)
1031 ✗ return ret;
1032 }
1033
1034
2/2
✓ Branch 20 → 18 taken 19368 times.
✓ Branch 20 → 21 taken 2421 times.
21789 for (int i = 0; i < FF_ARRAY_ELEMS(fps->alf_list); i++)
1035 19368 av_refstruct_replace(&fps->alf_list[i], ps->alf_list[i]);
1036
1037 2421 return 0;
1038 }
1039
1040 2421 static void decode_recovery_flag(VVCContext *s)
1041 {
1042
4/4
✓ Branch 2 → 3 taken 2414 times.
✓ Branch 2 → 4 taken 7 times.
✓ Branch 3 → 4 taken 366 times.
✓ Branch 3 → 5 taken 2048 times.
2421 if (IS_IDR(s))
1043 373 s->no_output_before_recovery_flag = 1;
1044
4/4
✓ Branch 5 → 6 taken 2036 times.
✓ Branch 5 → 7 taken 12 times.
✓ Branch 6 → 7 taken 3 times.
✓ Branch 6 → 8 taken 2033 times.
2048 else if (IS_CRA(s) || IS_GDR(s))
1045 15 s->no_output_before_recovery_flag = s->last_eos;
1046 2421 }
1047
1048 2421 static int decode_recovery_poc(VVCContext *s, const VVCFrameParamSets *fps)
1049 {
1050 2421 const VVCPH *ph = &fps->ph;
1051
1052
2/2
✓ Branch 2 → 3 taken 3 times.
✓ Branch 2 → 16 taken 2418 times.
2421 if (IS_GDR(s)) {
1053 3 const uint32_t recovery_poc_cnt = ph->r->ph_recovery_poc_cnt;
1054 3 const uint32_t max_recovery_poc_cnt = fps->sps->max_pic_order_cnt_lsb - 1;
1055
1056 3 const int64_t recovery_poc = (int64_t)ph->poc + recovery_poc_cnt;
1057
2/4
✓ Branch 3 → 4 taken 3 times.
✗ Branch 3 → 5 not taken.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 3 times.
3 if (recovery_poc < INT_MIN || recovery_poc > INT_MAX) {
1058 ✗ av_log(s->avctx, AV_LOG_ERROR, "Recovery point POC out of range: %"PRId64".\n", recovery_poc);
1059 ✗ return AVERROR_INVALIDDATA;
1060 }
1061
1062
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 14 taken 3 times.
3 if (recovery_poc_cnt > max_recovery_poc_cnt) {
1063 ✗ const int strict = s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT;
1064
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ av_log(s->avctx, strict ? AV_LOG_ERROR : AV_LOG_WARNING,
1065 "ph_recovery_poc_cnt out of range: %"PRIu32
1066 ", expected [0, %"PRIu32"].\n", recovery_poc_cnt, max_recovery_poc_cnt);
1067
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ if (strict)
1068 ✗ return AVERROR_INVALIDDATA;
1069 }
1070
1071
1/2
✓ Branch 14 → 15 taken 3 times.
✗ Branch 14 → 16 not taken.
3 if (s->no_output_before_recovery_flag)
1072 3 s->gdr_recovery_point_poc = recovery_poc;
1073 }
1074
1075
2/2
✓ Branch 16 → 17 taken 2220 times.
✓ Branch 16 → 20 taken 201 times.
2421 if (s->no_output_before_recovery_flag) {
1076
3/4
✓ Branch 17 → 18 taken 3 times.
✓ Branch 17 → 20 taken 2217 times.
✓ Branch 18 → 19 taken 3 times.
✗ Branch 18 → 20 not taken.
2220 if (!GDR_IS_RECOVERED(s) && s->gdr_recovery_point_poc <= ph->poc)
1077 3 GDR_SET_RECOVERED(s);
1078 }
1079
1080 2421 return 0;
1081 }
1082
1083 2421 int ff_vvc_decode_frame_ps(struct VVCFrameContext *fc, struct VVCContext *s)
1084 {
1085 2421 int ret = 0;
1086 2421 VVCFrameParamSets *fps = &fc->ps;
1087 2421 VVCParamSets *ps = &s->ps;
1088 2421 const SliceContext *sc = fc->slices[0];
1089 int is_clvss;
1090
1091 2421 decode_recovery_flag(s);
1092
10/10
✓ Branch 3 → 4 taken 2414 times.
✓ Branch 3 → 7 taken 7 times.
✓ Branch 4 → 5 taken 2048 times.
✓ Branch 4 → 7 taken 366 times.
✓ Branch 5 → 6 taken 2036 times.
✓ Branch 5 → 7 taken 12 times.
✓ Branch 6 → 7 taken 3 times.
✓ Branch 6 → 9 taken 2033 times.
✓ Branch 7 → 8 taken 379 times.
✓ Branch 7 → 9 taken 9 times.
2421 is_clvss = IS_CLVSS(s);
1093
1094 2421 ret = decode_ps(ps, s->avctx, sc, is_clvss);
1095
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 2421 times.
2421 if (ret < 0)
1096 ✗ return ret;
1097
1098 2421 ret = decode_frame_ps(fps, ps, sc, s->poc_tid0, is_clvss, s);
1099
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 2421 times.
2421 if (ret < 0)
1100 ✗ return ret;
1101
1102 2421 return decode_recovery_poc(s, fps);
1103 }
1104
1105 880 void ff_vvc_frame_ps_free(VVCFrameParamSets *fps)
1106 {
1107 880 av_refstruct_unref(&fps->sps);
1108 880 av_refstruct_unref(&fps->pps);
1109 880 av_refstruct_unref(&fps->ph.rref);
1110 880 av_refstruct_unref(&fps->sl);
1111
2/2
✓ Branch 9 → 7 taken 7040 times.
✓ Branch 9 → 10 taken 880 times.
7920 for (int i = 0; i < FF_ARRAY_ELEMS(fps->alf_list); i++)
1112 7040 av_refstruct_unref(&fps->alf_list[i]);
1113 880 }
1114
1115 110 void ff_vvc_ps_uninit(VVCParamSets *ps)
1116 {
1117
2/2
✓ Branch 5 → 3 taken 880 times.
✓ Branch 5 → 6 taken 110 times.
990 for (int i = 0; i < FF_ARRAY_ELEMS(ps->scaling_list); i++)
1118 880 av_refstruct_unref(&ps->scaling_list[i]);
1119
2/2
✓ Branch 9 → 7 taken 440 times.
✓ Branch 9 → 10 taken 110 times.
550 for (int i = 0; i < FF_ARRAY_ELEMS(ps->lmcs_list); i++)
1120 440 av_refstruct_unref(&ps->lmcs_list[i]);
1121
2/2
✓ Branch 13 → 11 taken 880 times.
✓ Branch 13 → 14 taken 110 times.
990 for (int i = 0; i < FF_ARRAY_ELEMS(ps->alf_list); i++)
1122 880 av_refstruct_unref(&ps->alf_list[i]);
1123
2/2
✓ Branch 17 → 15 taken 1760 times.
✓ Branch 17 → 18 taken 110 times.
1870 for (int i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++)
1124 1760 av_refstruct_unref(&ps->sps_list[i]);
1125
2/2
✓ Branch 21 → 19 taken 7040 times.
✓ Branch 21 → 22 taken 110 times.
7150 for (int i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
1126 7040 av_refstruct_unref(&ps->pps_list[i]);
1127 110 }
1128
1129 7665 static void alf_coeff(int16_t *coeff,
1130 const uint8_t *abs, const uint8_t *sign, const int size)
1131 {
1132
2/2
✓ Branch 4 → 3 taken 87540 times.
✓ Branch 4 → 5 taken 7665 times.
95205 for (int i = 0; i < size; i++)
1133 87540 coeff[i] = (1 - 2 * sign[i]) * abs[i];
1134 7665 }
1135
1136 830 static void alf_coeff_cc(int16_t *coeff,
1137 const uint8_t *mapped_abs, const uint8_t *sign)
1138 {
1139
2/2
✓ Branch 6 → 3 taken 5810 times.
✓ Branch 6 → 7 taken 830 times.
6640 for (int i = 0; i < ALF_NUM_COEFF_CC; i++) {
1140 5810 int c = mapped_abs[i];
1141
2/2
✓ Branch 3 → 4 taken 4996 times.
✓ Branch 3 → 5 taken 814 times.
5810 if (c)
1142 4996 c = (1 - 2 * sign[i]) * (1 << (c - 1));
1143 5810 coeff[i] = c;
1144 }
1145 830 }
1146
1147 328 static void alf_luma(VVCALF *alf, const H266RawAPS *aps)
1148 {
1149
2/2
✓ Branch 2 → 3 taken 51 times.
✓ Branch 2 → 4 taken 277 times.
328 if (!aps->alf_luma_filter_signal_flag)
1150 51 return;
1151
1152
2/2
✓ Branch 7 → 5 taken 6925 times.
✓ Branch 7 → 8 taken 277 times.
7202 for (int i = 0; i < ALF_NUM_FILTERS_LUMA; i++) {
1153 6925 const int ref = aps->alf_luma_coeff_delta_idx[i];
1154 6925 const uint8_t *abs = aps->alf_luma_coeff_abs[ref];
1155 6925 const uint8_t *sign = aps->alf_luma_coeff_sign[ref];
1156
1157 6925 alf_coeff(alf->luma_coeff[i], abs, sign, ALF_NUM_COEFF_LUMA);
1158 6925 memcpy(alf->luma_clip_idx[i], aps->alf_luma_clip_idx[ref],
1159 sizeof(alf->luma_clip_idx[i]));
1160 }
1161 }
1162
1163 328 static void alf_chroma(VVCALF *alf, const H266RawAPS *aps)
1164 {
1165
2/2
✓ Branch 2 → 3 taken 90 times.
✓ Branch 2 → 4 taken 238 times.
328 if (!aps->alf_chroma_filter_signal_flag)
1166 90 return;
1167
1168 238 alf->num_chroma_filters = aps->alf_chroma_num_alt_filters_minus1 + 1;
1169
2/2
✓ Branch 7 → 5 taken 740 times.
✓ Branch 7 → 8 taken 238 times.
978 for (int i = 0; i < alf->num_chroma_filters; i++) {
1170 740 const uint8_t *abs = aps->alf_chroma_coeff_abs[i];
1171 740 const uint8_t *sign = aps->alf_chroma_coeff_sign[i];
1172
1173 740 alf_coeff(alf->chroma_coeff[i], abs, sign, ALF_NUM_COEFF_CHROMA);
1174 740 memcpy(alf->chroma_clip_idx[i], aps->alf_chroma_clip_idx[i],
1175 sizeof(alf->chroma_clip_idx[i]));
1176 }
1177 }
1178
1179 328 static void alf_cc(VVCALF *alf, const H266RawAPS *aps)
1180 {
1181 328 const uint8_t (*abs[])[ALF_NUM_COEFF_CC] =
1182 328 { aps->alf_cc_cb_mapped_coeff_abs, aps->alf_cc_cr_mapped_coeff_abs };
1183 328 const uint8_t (*sign[])[ALF_NUM_COEFF_CC] =
1184 328 {aps->alf_cc_cb_coeff_sign, aps->alf_cc_cr_coeff_sign };
1185 328 const int signaled[] = { aps->alf_cc_cb_filter_signal_flag, aps->alf_cc_cr_filter_signal_flag};
1186
1187 328 alf->num_cc_filters[0] = aps->alf_cc_cb_filters_signalled_minus1 + 1;
1188 328 alf->num_cc_filters[1] = aps->alf_cc_cr_filters_signalled_minus1 + 1;
1189
1190
2/2
✓ Branch 9 → 3 taken 656 times.
✓ Branch 9 → 10 taken 328 times.
984 for (int idx = 0; idx < 2; idx++) {
1191
2/2
✓ Branch 3 → 4 taken 276 times.
✓ Branch 3 → 8 taken 380 times.
656 if (signaled[idx]) {
1192
2/2
✓ Branch 7 → 5 taken 830 times.
✓ Branch 7 → 8 taken 276 times.
1106 for (int i = 0; i < alf->num_cc_filters[idx]; i++)
1193 830 alf_coeff_cc(alf->cc_coeff[idx][i], abs[idx][i], sign[idx][i]);
1194 }
1195 }
1196 328 }
1197
1198 328 static void alf_derive(VVCALF *alf, const H266RawAPS *aps)
1199 {
1200 328 alf_luma(alf, aps);
1201 328 alf_chroma(alf, aps);
1202 328 alf_cc(alf, aps);
1203 328 }
1204
1205 328 static void alf_free(AVRefStructOpaque unused, void *obj)
1206 {
1207 328 VVCALF *alf = obj;
1208
1209 328 av_refstruct_unref(&alf->r);
1210 328 }
1211
1212 328 static int aps_decode_alf(const VVCALF **alf, const H266RawAPS *aps)
1213 {
1214 328 VVCALF *a = av_refstruct_alloc_ext(sizeof(*a), 0, NULL, alf_free);
1215
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 328 times.
328 if (!a)
1216 ✗ return AVERROR(ENOMEM);
1217
1218 328 alf_derive(a, aps);
1219 328 av_refstruct_replace(&a->r, aps);
1220 328 av_refstruct_replace(alf, a);
1221 328 av_refstruct_unref(&a);
1222
1223 328 return 0;
1224 }
1225
1226 280 static int is_luma_list(const int id)
1227 {
1228
4/4
✓ Branch 2 → 3 taken 190 times.
✓ Branch 2 → 4 taken 90 times.
✓ Branch 3 → 4 taken 10 times.
✓ Branch 3 → 5 taken 180 times.
280 return id % VVC_MAX_SAMPLE_ARRAYS == SL_START_4x4 || id == SL_START_64x64 + 1;
1229 }
1230
1231 448 static int derive_matrix_size(const int id)
1232 {
1233
4/4
✓ Branch 2 → 3 taken 416 times.
✓ Branch 2 → 6 taken 32 times.
✓ Branch 3 → 4 taken 96 times.
✓ Branch 3 → 5 taken 320 times.
448 return id < SL_START_4x4 ? 2 : (id < SL_START_8x8 ? 4 : 8);
1234 }
1235
1236 // 7.4.3.20 Scaling list data semantics
1237 16 static void scaling_derive(VVCScalingList *sl, const H266RawAPS *aps)
1238 {
1239
2/2
✓ Branch 40 → 3 taken 448 times.
✓ Branch 40 → 41 taken 16 times.
464 for (int id = 0; id < SL_MAX_ID; id++) {
1240 448 const int matrix_size = derive_matrix_size(id);
1241 448 const int log2_size = av_log2(matrix_size);
1242 448 const int list_size = matrix_size * matrix_size;
1243 int coeff[SL_MAX_MATRIX_SIZE * SL_MAX_MATRIX_SIZE];
1244 const uint8_t *pred;
1245 const int *scaling_list;
1246 448 int dc = 0;
1247
1248
4/4
✓ Branch 4 → 5 taken 280 times.
✓ Branch 4 → 7 taken 168 times.
✓ Branch 6 → 7 taken 100 times.
✓ Branch 6 → 17 taken 180 times.
448 if (aps->aps_chroma_present_flag || is_luma_list(id)) {
1249
2/2
✓ Branch 7 → 8 taken 122 times.
✓ Branch 7 → 17 taken 146 times.
268 if (!aps->scaling_list_copy_mode_flag[id]) {
1250 122 int next_coef = 0;
1251
1252
2/2
✓ Branch 8 → 9 taken 36 times.
✓ Branch 8 → 10 taken 86 times.
122 if (id >= SL_START_16x16)
1253 36 dc = next_coef = aps->scaling_list_dc_coef[id - SL_START_16x16];
1254
1255
2/2
✓ Branch 16 → 11 taken 5504 times.
✓ Branch 16 → 17 taken 122 times.
5626 for (int i = 0; i < list_size; i++) {
1256 5504 const int x = ff_vvc_diag_scan_x[3][3][i];
1257 5504 const int y = ff_vvc_diag_scan_y[3][3][i];
1258
1259
6/6
✓ Branch 11 → 12 taken 384 times.
✓ Branch 11 → 14 taken 5120 times.
✓ Branch 12 → 13 taken 192 times.
✓ Branch 12 → 14 taken 192 times.
✓ Branch 13 → 14 taken 96 times.
✓ Branch 13 → 15 taken 96 times.
5504 if (!(id >= SL_START_64x64 && x >= 4 && y >= 4))
1260 5408 next_coef += aps->scaling_list_delta_coef[id][i];
1261 5504 coeff[i] = next_coef;
1262 }
1263 }
1264 }
1265
1266 //dc
1267
2/2
✓ Branch 17 → 18 taken 224 times.
✓ Branch 17 → 27 taken 224 times.
448 if (id >= SL_START_16x16) {
1268
4/4
✓ Branch 18 → 19 taken 36 times.
✓ Branch 18 → 21 taken 188 times.
✓ Branch 19 → 20 taken 4 times.
✓ Branch 19 → 21 taken 32 times.
224 if (!aps->scaling_list_copy_mode_flag[id] && !aps->scaling_list_pred_mode_flag[id]) {
1269 4 dc += 8;
1270
2/2
✓ Branch 21 → 22 taken 80 times.
✓ Branch 21 → 23 taken 140 times.
220 } else if (!aps->scaling_list_pred_id_delta[id]) {
1271 80 dc += 16;
1272 } else {
1273 140 const int ref_id = id - aps->scaling_list_pred_id_delta[id];
1274
2/2
✓ Branch 23 → 24 taken 94 times.
✓ Branch 23 → 25 taken 46 times.
140 if (ref_id >= SL_START_16x16)
1275 94 dc += sl->scaling_matrix_dc_rec[ref_id - SL_START_16x16];
1276 else
1277 46 dc += sl->scaling_matrix_rec[ref_id][0];
1278 }
1279 224 sl->scaling_matrix_dc_rec[id - SL_START_16x16] = dc & 255;
1280 }
1281
1282 //ac
1283
2/2
✓ Branch 27 → 28 taken 122 times.
✓ Branch 27 → 29 taken 326 times.
448 scaling_list = aps->scaling_list_copy_mode_flag[id] ? ff_vvc_scaling_list0 : coeff;
1284
4/4
✓ Branch 30 → 31 taken 122 times.
✓ Branch 30 → 33 taken 326 times.
✓ Branch 31 → 32 taken 46 times.
✓ Branch 31 → 33 taken 76 times.
448 if (!aps->scaling_list_copy_mode_flag[id] && !aps->scaling_list_pred_mode_flag[id])
1285 46 pred = ff_vvc_scaling_pred_8;
1286
2/2
✓ Branch 33 → 34 taken 194 times.
✓ Branch 33 → 35 taken 208 times.
402 else if (!aps->scaling_list_pred_id_delta[id])
1287 194 pred = ff_vvc_scaling_pred_16;
1288 else
1289 208 pred = sl->scaling_matrix_rec[id - aps->scaling_list_pred_id_delta[id]];
1290
2/2
✓ Branch 38 → 37 taken 22144 times.
✓ Branch 38 → 39 taken 448 times.
22592 for (int i = 0; i < list_size; i++) {
1291 22144 const int x = ff_vvc_diag_scan_x[log2_size][log2_size][i];
1292 22144 const int y = ff_vvc_diag_scan_y[log2_size][log2_size][i];
1293 22144 const int off = y * matrix_size + x;
1294 22144 sl->scaling_matrix_rec[id][off] = (pred[off] + scaling_list[i]) & 255;
1295 }
1296 }
1297 16 }
1298
1299 16 static int aps_decode_scaling(const VVCScalingList **scaling, const H266RawAPS *aps)
1300 {
1301 16 VVCScalingList *sl = av_refstruct_allocz(sizeof(*sl));
1302
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 16 times.
16 if (!sl)
1303 ✗ return AVERROR(ENOMEM);
1304
1305 16 scaling_derive(sl, aps);
1306 16 av_refstruct_replace(scaling, sl);
1307 16 av_refstruct_unref(&sl);
1308
1309 16 return 0;
1310 }
1311
1312 431 int ff_vvc_decode_aps(VVCParamSets *ps, const CodedBitstreamUnit *unit)
1313 {
1314 431 const H266RawAPS *aps = unit->content_ref;
1315 431 int ret = 0;
1316
1317
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 431 times.
431 if (!aps)
1318 ✗ return AVERROR_INVALIDDATA;
1319
1320
3/4
✓ Branch 4 → 5 taken 328 times.
✓ Branch 4 → 7 taken 87 times.
✓ Branch 4 → 9 taken 16 times.
✗ Branch 4 → 11 not taken.
431 switch (aps->aps_params_type) {
1321 328 case VVC_ASP_TYPE_ALF:
1322 328 ret = aps_decode_alf(&ps->alf_list[aps->aps_adaptation_parameter_set_id], aps);
1323 328 break;
1324 87 case VVC_ASP_TYPE_LMCS:
1325 87 av_refstruct_replace(&ps->lmcs_list[aps->aps_adaptation_parameter_set_id], aps);
1326 87 break;
1327 16 case VVC_ASP_TYPE_SCALING:
1328 16 ret = aps_decode_scaling(&ps->scaling_list[aps->aps_adaptation_parameter_set_id], aps);
1329 16 break;
1330 }
1331
1332 431 return ret;
1333 }
1334
1335 3186 static int sh_alf_aps(const VVCSH *sh, const VVCFrameParamSets *fps)
1336 {
1337
2/2
✓ Branch 2 → 3 taken 1775 times.
✓ Branch 2 → 4 taken 1411 times.
3186 if (!sh->r->sh_alf_enabled_flag)
1338 1775 return 0;
1339
1340
2/2
✓ Branch 8 → 5 taken 1737 times.
✓ Branch 8 → 9 taken 1411 times.
3148 for (int i = 0; i < sh->r->sh_num_alf_aps_ids_luma; i++) {
1341 1737 const VVCALF *alf_aps_luma = fps->alf_list[sh->r->sh_alf_aps_id_luma[i]];
1342
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 1737 times.
1737 if (!alf_aps_luma)
1343 ✗ return AVERROR_INVALIDDATA;
1344 }
1345
1346
4/4
✓ Branch 9 → 10 taken 753 times.
✓ Branch 9 → 11 taken 658 times.
✓ Branch 10 → 11 taken 152 times.
✓ Branch 10 → 13 taken 601 times.
1411 if (sh->r->sh_alf_cb_enabled_flag || sh->r->sh_alf_cr_enabled_flag) {
1347 810 const VVCALF *alf_aps_chroma = fps->alf_list[sh->r->sh_alf_aps_id_chroma];
1348
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 810 times.
810 if (!alf_aps_chroma)
1349 ✗ return AVERROR_INVALIDDATA;
1350 }
1351
1352
2/2
✓ Branch 13 → 14 taken 1352 times.
✓ Branch 13 → 20 taken 59 times.
1411 if (fps->sps->r->sps_ccalf_enabled_flag) {
1353
2/2
✓ Branch 14 → 15 taken 216 times.
✓ Branch 14 → 17 taken 1136 times.
1352 if (sh->r->sh_alf_cc_cb_enabled_flag) {
1354 216 const VVCALF *alf_aps_cc_cr = fps->alf_list[sh->r->sh_alf_cc_cb_aps_id];
1355
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 216 times.
216 if (!alf_aps_cc_cr)
1356 ✗ return AVERROR_INVALIDDATA;
1357 }
1358
2/2
✓ Branch 17 → 18 taken 188 times.
✓ Branch 17 → 20 taken 1164 times.
1352 if (sh->r->sh_alf_cc_cr_enabled_flag) {
1359 188 const VVCALF *alf_aps_cc_cr = fps->alf_list[sh->r->sh_alf_cc_cr_aps_id];
1360
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 188 times.
188 if (!alf_aps_cc_cr)
1361 ✗ return AVERROR_INVALIDDATA;
1362 }
1363 }
1364
1365 1411 return 0;
1366 }
1367
1368 3186 static int sh_slice_address(VVCSH *sh, const H266RawSPS *sps, const VVCPPS *pps)
1369 {
1370 3186 const int slice_address = sh->r->sh_slice_address;
1371
1372
2/2
✓ Branch 2 → 3 taken 718 times.
✓ Branch 2 → 9 taken 2468 times.
3186 if (pps->r->pps_rect_slice_flag) {
1373 718 int pic_level_slice_idx = slice_address;
1374
2/2
✓ Branch 5 → 4 taken 1047 times.
✓ Branch 5 → 6 taken 718 times.
1765 for (int j = 0; j < sh->r->curr_subpic_idx; j++)
1375 1047 pic_level_slice_idx += pps->r->num_slices_in_subpic[j];
1376
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 718 times.
718 if (pic_level_slice_idx > pps->r->pps_num_slices_in_pic_minus1)
1377 ✗ return AVERROR_INVALIDDATA;
1378 718 sh->ctb_addr_in_curr_slice = pps->ctb_addr_in_slice + pps->slice_start_offset[pic_level_slice_idx];
1379 718 sh->num_ctus_in_curr_slice = pps->num_ctus_in_slice[pic_level_slice_idx];
1380 } else {
1381 2468 int tile_x = slice_address % pps->r->num_tile_columns;
1382 2468 int tile_y = slice_address / pps->r->num_tile_columns;
1383 2468 const int slice_start_ctb = pps->row_bd[tile_y] * pps->ctb_width + pps->col_bd[tile_x] * pps->r->row_height_val[tile_y];
1384
1385 2468 sh->ctb_addr_in_curr_slice = pps->ctb_addr_in_slice + slice_start_ctb;
1386
1387 2468 sh->num_ctus_in_curr_slice = 0;
1388
2/2
✓ Branch 11 → 10 taken 2548 times.
✓ Branch 11 → 12 taken 2468 times.
5016 for (int tile_idx = slice_address; tile_idx <= slice_address + sh->r->sh_num_tiles_in_slice_minus1; tile_idx++) {
1389 2548 tile_x = tile_idx % pps->r->num_tile_columns;
1390 2548 tile_y = tile_idx / pps->r->num_tile_columns;
1391 2548 sh->num_ctus_in_curr_slice += pps->r->row_height_val[tile_y] * pps->r->col_width_val[tile_x];
1392 }
1393 }
1394
1395
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 3186 times.
3186 if (!sh->num_ctus_in_curr_slice)
1396 ✗ return AVERROR_INVALIDDATA;
1397
1398 3186 return 0;
1399 }
1400
1401 3186 static void sh_qp_y(VVCSH *sh, const H266RawPPS *pps, const H266RawPictureHeader *ph)
1402 {
1403 3186 const int init_qp = pps->pps_init_qp_minus26 + 26;
1404
1405
2/2
✓ Branch 2 → 3 taken 2916 times.
✓ Branch 2 → 4 taken 270 times.
3186 if (!pps->pps_qp_delta_info_in_ph_flag)
1406 2916 sh->slice_qp_y = init_qp + sh->r->sh_qp_delta;
1407 else
1408 270 sh->slice_qp_y = init_qp + ph->ph_qp_delta;
1409 3186 }
1410
1411 3186 static void sh_inter(VVCSH *sh, const H266RawSPS *sps, const H266RawPPS *pps)
1412 {
1413 3186 const H266RawSliceHeader *rsh = sh->r;
1414
1415
1/2
✓ Branch 2 → 3 taken 3186 times.
✗ Branch 2 → 8 not taken.
3186 if (!pps->pps_wp_info_in_ph_flag &&
1416
4/4
✓ Branch 3 → 4 taken 86 times.
✓ Branch 3 → 5 taken 3100 times.
✓ Branch 4 → 5 taken 73 times.
✓ Branch 4 → 7 taken 13 times.
3186 ((pps->pps_weighted_pred_flag && IS_P(rsh)) ||
1417
4/4
✓ Branch 5 → 6 taken 73 times.
✓ Branch 5 → 8 taken 3100 times.
✓ Branch 6 → 7 taken 62 times.
✓ Branch 6 → 8 taken 11 times.
3173 (pps->pps_weighted_bipred_flag && IS_B(rsh))))
1418 75 pred_weight_table(&sh->pwt, &rsh->sh_pred_weight_table);
1419 3186 }
1420
1421 3186 static void sh_deblock_offsets(VVCSH *sh)
1422 {
1423 3186 const H266RawSliceHeader *r = sh->r;
1424
1425
2/2
✓ Branch 2 → 3 taken 1889 times.
✓ Branch 2 → 4 taken 1297 times.
3186 if (!r->sh_deblocking_filter_disabled_flag) {
1426 1889 sh->deblock.beta_offset[LUMA] = r->sh_luma_beta_offset_div2 * 2;
1427 1889 sh->deblock.tc_offset[LUMA] = r->sh_luma_tc_offset_div2 * 2;
1428 1889 sh->deblock.beta_offset[CB] = r->sh_cb_beta_offset_div2 * 2;
1429 1889 sh->deblock.tc_offset[CB] = r->sh_cb_tc_offset_div2 * 2;
1430 1889 sh->deblock.beta_offset[CR] = r->sh_cr_beta_offset_div2 * 2;
1431 1889 sh->deblock.tc_offset[CR] = r->sh_cr_tc_offset_div2 * 2;
1432 }
1433 3186 }
1434
1435 3186 static void sh_partition_constraints(VVCSH *sh, const H266RawSPS *sps, const H266RawPictureHeader *ph)
1436 {
1437 3186 const int min_cb_log2_size_y = sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
1438 int min_qt_log2_size_y[2];
1439
1440
2/2
✓ Branch 2 → 3 taken 554 times.
✓ Branch 2 → 4 taken 2632 times.
3186 if (IS_I(sh->r)) {
1441 554 min_qt_log2_size_y[LUMA] = (min_cb_log2_size_y + ph->ph_log2_diff_min_qt_min_cb_intra_slice_luma);
1442 554 min_qt_log2_size_y[CHROMA] = (min_cb_log2_size_y + ph->ph_log2_diff_min_qt_min_cb_intra_slice_chroma);
1443
1444 554 sh->max_bt_size[LUMA] = 1 << (min_qt_log2_size_y[LUMA] + ph->ph_log2_diff_max_bt_min_qt_intra_slice_luma);
1445 554 sh->max_bt_size[CHROMA] = 1 << (min_qt_log2_size_y[CHROMA]+ ph->ph_log2_diff_max_bt_min_qt_intra_slice_chroma);
1446
1447 554 sh->max_tt_size[LUMA] = 1 << (min_qt_log2_size_y[LUMA] + ph->ph_log2_diff_max_tt_min_qt_intra_slice_luma);
1448 554 sh->max_tt_size[CHROMA] = 1 << (min_qt_log2_size_y[CHROMA]+ ph->ph_log2_diff_max_tt_min_qt_intra_slice_chroma);
1449
1450 554 sh->max_mtt_depth[LUMA] = ph->ph_max_mtt_hierarchy_depth_intra_slice_luma;
1451 554 sh->max_mtt_depth[CHROMA] = ph->ph_max_mtt_hierarchy_depth_intra_slice_chroma;
1452
1453 554 sh->cu_qp_delta_subdiv = ph->ph_cu_qp_delta_subdiv_intra_slice;
1454 554 sh->cu_chroma_qp_offset_subdiv = ph->ph_cu_chroma_qp_offset_subdiv_intra_slice;
1455 } else {
1456
2/2
✓ Branch 6 → 5 taken 5264 times.
✓ Branch 6 → 7 taken 2632 times.
7896 for (int i = LUMA; i <= CHROMA; i++) {
1457 5264 min_qt_log2_size_y[i] = (min_cb_log2_size_y + ph->ph_log2_diff_min_qt_min_cb_inter_slice);
1458 5264 sh->max_bt_size[i] = 1 << (min_qt_log2_size_y[i] + ph->ph_log2_diff_max_bt_min_qt_inter_slice);
1459 5264 sh->max_tt_size[i] = 1 << (min_qt_log2_size_y[i] + ph->ph_log2_diff_max_tt_min_qt_inter_slice);
1460 5264 sh->max_mtt_depth[i] = ph->ph_max_mtt_hierarchy_depth_inter_slice;
1461 }
1462
1463 2632 sh->cu_qp_delta_subdiv = ph->ph_cu_qp_delta_subdiv_inter_slice;
1464 2632 sh->cu_chroma_qp_offset_subdiv = ph->ph_cu_chroma_qp_offset_subdiv_inter_slice;
1465 }
1466
1467 3186 sh->min_qt_size[LUMA] = 1 << min_qt_log2_size_y[LUMA];
1468 3186 sh->min_qt_size[CHROMA] = 1 << min_qt_log2_size_y[CHROMA];
1469 3186 }
1470
1471 3186 static int sh_entry_points(VVCSH *sh, const H266RawSPS *sps, const VVCPPS *pps)
1472 {
1473
2/2
✓ Branch 2 → 3 taken 3092 times.
✓ Branch 2 → 15 taken 94 times.
3186 if (sps->sps_entry_point_offsets_present_flag) {
1474 3092 int j = 0;
1475
2/2
✓ Branch 12 → 4 taken 61526 times.
✓ Branch 12 → 13 taken 3092 times.
64618 for (int i = 1; i < sh->num_ctus_in_curr_slice; i++) {
1476 61526 const int pre_ctb_addr_x = sh->ctb_addr_in_curr_slice[i - 1] % pps->ctb_width;
1477 61526 const int pre_ctb_addr_y = sh->ctb_addr_in_curr_slice[i - 1] / pps->ctb_width;
1478 61526 const int ctb_addr_x = sh->ctb_addr_in_curr_slice[i] % pps->ctb_width;
1479 61526 const int ctb_addr_y = sh->ctb_addr_in_curr_slice[i] / pps->ctb_width;
1480
2/2
✓ Branch 4 → 5 taken 61483 times.
✓ Branch 4 → 8 taken 43 times.
61526 if (pps->ctb_to_row_bd[ctb_addr_y] != pps->ctb_to_row_bd[pre_ctb_addr_y] ||
1481
4/4
✓ Branch 5 → 6 taken 61272 times.
✓ Branch 5 → 8 taken 211 times.
✓ Branch 6 → 7 taken 6606 times.
✓ Branch 6 → 11 taken 54666 times.
61483 pps->ctb_to_col_bd[ctb_addr_x] != pps->ctb_to_col_bd[pre_ctb_addr_x] ||
1482
2/2
✓ Branch 7 → 8 taken 153 times.
✓ Branch 7 → 11 taken 6453 times.
6606 (ctb_addr_y != pre_ctb_addr_y && sps->sps_entropy_coding_sync_enabled_flag)) {
1483
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 407 times.
407 if (j >= VVC_MAX_ENTRY_POINTS)
1484 ✗ return AVERROR_INVALIDDATA;
1485 407 sh->entry_point_start_ctu[j++] = i;
1486 }
1487 }
1488
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 3092 times.
3092 if (j != sh->r->num_entry_points)
1489 ✗ return AVERROR_INVALIDDATA;
1490 }
1491
1492 3186 return 0;
1493 }
1494
1495 3186 static int sh_derive(VVCSH *sh, const VVCFrameParamSets *fps)
1496 {
1497 3186 const H266RawSPS *sps = fps->sps->r;
1498 3186 const H266RawPPS *pps = fps->pps->r;
1499 3186 const H266RawPictureHeader *ph = fps->ph.r;
1500 int ret;
1501
1502 3186 ret = sh_slice_address(sh, sps, fps->pps);
1503
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 3186 times.
3186 if (ret < 0)
1504 ✗ return ret;
1505 3186 ret = sh_alf_aps(sh, fps);
1506
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 3186 times.
3186 if (ret < 0)
1507 ✗ return ret;
1508 3186 sh_inter(sh, sps, pps);
1509 3186 sh_qp_y(sh, pps, ph);
1510 3186 sh_deblock_offsets(sh);
1511 3186 sh_partition_constraints(sh, sps, ph);
1512 3186 ret = sh_entry_points(sh, sps, fps->pps);
1513
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 3186 times.
3186 if (ret < 0)
1514 ✗ return ret;
1515
1516 3186 return 0;
1517 }
1518
1519 3186 int ff_vvc_decode_sh(VVCSH *sh, const VVCFrameParamSets *fps, const CodedBitstreamUnit *unit)
1520 {
1521 int ret;
1522
1523
2/4
✓ Branch 2 → 3 taken 3186 times.
✗ Branch 2 → 4 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 3186 times.
3186 if (!fps->sps || !fps->pps)
1524 ✗ return AVERROR_INVALIDDATA;
1525
1526 3186 av_refstruct_replace(&sh->r, unit->content_ref);
1527
1528 3186 ret = sh_derive(sh, fps);
1529
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 3186 times.
3186 if (ret < 0)
1530 ✗ return ret;
1531
1532 3186 return 0;
1533 }
1534