FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/vvc.c
Date: 2026-10-14 03:02:30
Exec Total Coverage
Lines: 327 433 75.5%
Functions: 14 14 100.0%
Branches: 125 238 52.5%

Line Branch Exec Source
1 /*
2 * H.266/VVC helper functions for muxers
3 *
4 * Copyright (C) 2022, Thomas Siedel
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavcodec/get_bits.h"
24 #include "libavcodec/put_bits.h"
25 #include "libavcodec/golomb.h"
26 #include "libavcodec/vvc.h"
27 #include "libavutil/avassert.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/mem.h"
30 #include "avc.h"
31 #include "avio.h"
32 #include "avio_internal.h"
33 #include "nal.h"
34 #include "vvc.h"
35
36 enum {
37 OPI_INDEX,
38 VPS_INDEX,
39 SPS_INDEX,
40 PPS_INDEX,
41 SEI_PREFIX_INDEX,
42 SEI_SUFFIX_INDEX,
43 NB_ARRAYS
44 };
45
46 typedef struct VVCCNALUnitArray {
47 uint8_t array_completeness;
48 uint8_t NAL_unit_type;
49 uint16_t num_nalus;
50 uint16_t *nal_unit_length;
51 uint8_t **nal_unit;
52 } VVCCNALUnitArray;
53
54 typedef struct VVCPTLRecord {
55 uint8_t num_bytes_constraint_info;
56 uint8_t general_profile_idc;
57 uint8_t general_tier_flag;
58 uint8_t general_level_idc;
59 uint8_t ptl_frame_only_constraint_flag;
60 uint8_t ptl_multilayer_enabled_flag;
61 uint8_t general_constraint_info[9];
62 uint8_t ptl_sublayer_level_present_flag[VVC_MAX_SUBLAYERS - 1];
63 uint8_t sublayer_level_idc[VVC_MAX_SUBLAYERS - 1];
64 uint8_t ptl_num_sub_profiles;
65 uint32_t general_sub_profile_idc[VVC_MAX_SUB_PROFILES];
66 } VVCPTLRecord;
67
68 typedef struct VVCDecoderConfigurationRecord {
69 uint8_t lengthSizeMinusOne;
70 uint8_t ptl_present_flag;
71 uint16_t ols_idx;
72 uint8_t num_sublayers;
73 uint8_t constant_frame_rate;
74 uint8_t chroma_format_idc;
75 uint8_t bit_depth_minus8;
76 VVCPTLRecord ptl;
77 uint16_t max_picture_width;
78 uint16_t max_picture_height;
79 uint16_t avg_frame_rate;
80 uint8_t num_of_arrays;
81 VVCCNALUnitArray arrays[NB_ARRAYS];
82 } VVCDecoderConfigurationRecord;
83
84 7 static void vvcc_update_ptl(VVCDecoderConfigurationRecord *vvcc,
85 VVCPTLRecord *ptl)
86 {
87 /*
88 * The level indication general_level_idc must indicate a level of
89 * capability equal to or greater than the highest level indicated for the
90 * highest tier in all the parameter sets.
91 */
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (vvcc->ptl.general_tier_flag < ptl->general_tier_flag)
93 ✗ vvcc->ptl.general_level_idc = ptl->general_level_idc;
94 else
95 7 vvcc->ptl.general_level_idc =
96 7 FFMAX(vvcc->ptl.general_level_idc, ptl->general_level_idc);
97
98 /*
99 * The tier indication general_tier_flag must indicate a tier equal to or
100 * greater than the highest tier indicated in all the parameter sets.
101 */
102 7 vvcc->ptl.general_tier_flag =
103 7 FFMAX(vvcc->ptl.general_tier_flag, ptl->general_tier_flag);
104
105 /*
106 * The profile indication general_profile_idc must indicate a profile to
107 * which the stream associated with this configuration record conforms.
108 *
109 * If the sequence parameter sets are marked with different profiles, then
110 * the stream may need examination to determine which profile, if any, the
111 * entire stream conforms to. If the entire stream is not examined, or the
112 * examination reveals that there is no profile to which the entire stream
113 * conforms, then the entire stream must be split into two or more
114 * sub-streams with separate configuration records in which these rules can
115 * be met.
116 *
117 * Note: set the profile to the highest value for the sake of simplicity.
118 */
119 7 vvcc->ptl.general_profile_idc =
120 7 FFMAX(vvcc->ptl.general_profile_idc, ptl->general_profile_idc);
121
122 /*
123 * Each bit in flags may only be set if all
124 * the parameter sets set that bit.
125 */
126 7 vvcc->ptl.ptl_frame_only_constraint_flag &=
127 7 ptl->ptl_frame_only_constraint_flag;
128 7 vvcc->ptl.ptl_multilayer_enabled_flag &= ptl->ptl_multilayer_enabled_flag;
129
130 /*
131 * Constraints Info
132 */
133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (ptl->num_bytes_constraint_info) {
134 ✗ vvcc->ptl.num_bytes_constraint_info = ptl->num_bytes_constraint_info;
135 ✗ memcpy(&vvcc->ptl.general_constraint_info[0],
136 ✗ &ptl->general_constraint_info[0], ptl->num_bytes_constraint_info);
137 } else {
138 7 vvcc->ptl.num_bytes_constraint_info = 1;
139 7 memset(&vvcc->ptl.general_constraint_info[0], 0, sizeof(vvcc->ptl.general_constraint_info));
140 }
141
142 /*
143 * Each bit in flags may only be set if one of
144 * the parameter sets set that bit.
145 */
146 7 memset(vvcc->ptl.ptl_sublayer_level_present_flag, 0,
147 7 sizeof(uint8_t) * vvcc->num_sublayers - 1);
148 7 memset(vvcc->ptl.sublayer_level_idc, 0,
149 7 sizeof(uint8_t) * vvcc->num_sublayers - 1);
150
151
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
11 for (int i = vvcc->num_sublayers - 2; i >= 0; i--) {
152 4 vvcc->ptl.ptl_sublayer_level_present_flag[i] |=
153 4 ptl->ptl_sublayer_level_present_flag[i];
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (vvcc->ptl.ptl_sublayer_level_present_flag[i]) {
155 ✗ vvcc->ptl.sublayer_level_idc[i] =
156 ✗ FFMAX(vvcc->ptl.sublayer_level_idc[i],
157 ptl->sublayer_level_idc[i]);
158 } else {
159
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (i == vvcc->num_sublayers - 2) {
160 1 vvcc->ptl.sublayer_level_idc[i] = vvcc->ptl.general_level_idc;
161 } else {
162 3 vvcc->ptl.sublayer_level_idc[i] =
163 3 vvcc->ptl.sublayer_level_idc[i + 1];
164 }
165 }
166 }
167
168 7 vvcc->ptl.ptl_num_sub_profiles =
169 7 FFMAX(vvcc->ptl.ptl_num_sub_profiles, ptl->ptl_num_sub_profiles);
170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (vvcc->ptl.ptl_num_sub_profiles) {
171 ✗ for (int i = 0; i < vvcc->ptl.ptl_num_sub_profiles; i++) {
172 ✗ vvcc->ptl.general_sub_profile_idc[i] =
173 ✗ ptl->general_sub_profile_idc[i];
174 }
175 }
176 7 }
177
178 7 static void vvcc_parse_ptl(GetBitContext *gb,
179 VVCDecoderConfigurationRecord *vvcc,
180 unsigned int profileTierPresentFlag,
181 unsigned int max_sub_layers_minus1)
182 {
183 7 VVCPTLRecord general_ptl = { 0 };
184
185
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
7 if (profileTierPresentFlag) {
186 5 general_ptl.general_profile_idc = get_bits(gb, 7);
187 5 general_ptl.general_tier_flag = get_bits1(gb);
188 }
189 7 general_ptl.general_level_idc = get_bits(gb, 8);
190
191 7 general_ptl.ptl_frame_only_constraint_flag = get_bits1(gb);
192 7 general_ptl.ptl_multilayer_enabled_flag = get_bits1(gb);
193
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
7 if (profileTierPresentFlag) { // parse constraint info
194 5 general_ptl.num_bytes_constraint_info = get_bits1(gb); // gci_present_flag
195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (general_ptl.num_bytes_constraint_info) {
196 int gci_num_reserved_bits, j;
197 ✗ for (j = 0; j < 8; j++)
198 ✗ general_ptl.general_constraint_info[j] = get_bits(gb, 8);
199 ✗ general_ptl.general_constraint_info[j++] = get_bits(gb, 7);
200
201 ✗ gci_num_reserved_bits = get_bits(gb, 8);
202 ✗ general_ptl.num_bytes_constraint_info = j;
203 ✗ skip_bits(gb, gci_num_reserved_bits);
204 }
205 5 align_get_bits(gb);
206 }
207
208
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
11 for (int i = max_sub_layers_minus1 - 1; i >= 0; i--)
209 4 general_ptl.ptl_sublayer_level_present_flag[i] = get_bits1(gb);
210
211 7 align_get_bits(gb);
212
213
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
11 for (int i = max_sub_layers_minus1 - 1; i >= 0; i--) {
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (general_ptl.ptl_sublayer_level_present_flag[i])
215 ✗ general_ptl.sublayer_level_idc[i] = get_bits(gb, 8);
216 }
217
218
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
7 if (profileTierPresentFlag) {
219 5 general_ptl.ptl_num_sub_profiles = get_bits(gb, 8);
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (general_ptl.ptl_num_sub_profiles) {
221 ✗ for (int i = 0; i < general_ptl.ptl_num_sub_profiles; i++)
222 ✗ general_ptl.general_sub_profile_idc[i] = get_bits_long(gb, 32);
223 }
224 }
225
226 7 vvcc_update_ptl(vvcc, &general_ptl);
227 7 }
228
229 2 static int vvcc_parse_vps(GetBitContext *gb,
230 VVCDecoderConfigurationRecord *vvcc)
231 {
232 unsigned int vps_max_layers_minus1;
233 unsigned int vps_max_sublayers_minus1;
234 unsigned int vps_default_ptl_dpb_hrd_max_tid_flag;
235 unsigned int vps_all_independent_layers_flag;
236
237 unsigned int vps_pt_present_flag[VVC_MAX_PTLS];
238 unsigned int vps_ptl_max_tid[VVC_MAX_PTLS];
239 2 unsigned int vps_num_ptls_minus1 = 0;
240
241 /*
242 * vps_video_parameter_set_id u(4)
243 */
244 2 skip_bits(gb, 4);
245
246 2 vps_max_layers_minus1 = get_bits(gb, 6);
247 2 vps_max_sublayers_minus1 = get_bits(gb, 3);
248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (vps_max_sublayers_minus1 >= VVC_MAX_SUBLAYERS)
249 ✗ return AVERROR_INVALIDDATA;
250
251 /*
252 * numTemporalLayers greater than 1 indicates that the stream to which this
253 * configuration record applies is temporally scalable and the contained
254 * number of temporal layers (also referred to as temporal sub-layer or
255 * sub-layer in ISO/IEC 23008-2) is equal to numTemporalLayers. Value 1
256 * indicates that the stream is not temporally scalable. Value 0 indicates
257 * that it is unknown whether the stream is temporally scalable.
258 */
259 2 vvcc->num_sublayers = FFMAX(vvcc->num_sublayers,
260 vps_max_sublayers_minus1 + 1);
261
262
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (vps_max_layers_minus1 > 0 && vps_max_sublayers_minus1 > 0)
263 ✗ vps_default_ptl_dpb_hrd_max_tid_flag = get_bits1(gb);
264 else
265 2 vps_default_ptl_dpb_hrd_max_tid_flag = 1;
266
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (vps_max_layers_minus1 > 0)
267 2 vps_all_independent_layers_flag = get_bits1(gb);
268 else
269 ✗ vps_all_independent_layers_flag = 1;
270
271
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (int i = 0; i <= vps_max_layers_minus1; i++) {
272 4 skip_bits(gb, 6); //vps_layer_id[i]
273
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 if (i > 0 && !vps_all_independent_layers_flag) {
274
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (!get_bits1(gb)) { // vps_independent_layer_flag[i]
275 2 unsigned int vps_max_tid_ref_present_flag = get_bits1(gb);
276
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (int j = 0; j < i; j++) {
277 2 unsigned int vps_direct_ref_layer_flag = get_bits1(gb);
278
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (vps_max_tid_ref_present_flag && vps_direct_ref_layer_flag)
279 ✗ skip_bits(gb, 3); // vps_max_tid_il_ref_pics_plus1
280 }
281 }
282 }
283 }
284
285
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (vps_max_layers_minus1 > 0) {
286 unsigned int vps_each_layer_is_an_ols_flag;
287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (vps_all_independent_layers_flag)
288 ✗ vps_each_layer_is_an_ols_flag = get_bits1(gb);
289 else
290 2 vps_each_layer_is_an_ols_flag = 0;
291
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!vps_each_layer_is_an_ols_flag) {
292 unsigned int vps_ols_mode_idc;
293
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!vps_all_independent_layers_flag)
294 2 vps_ols_mode_idc = get_bits(gb, 2);
295 else
296 ✗ vps_ols_mode_idc = 2;
297
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (vps_ols_mode_idc == 2) {
298 2 unsigned int vps_num_output_layer_sets_minus2 = get_bits(gb, 8);
299
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (int i = 1; i <= vps_num_output_layer_sets_minus2 + 1; i++) {
300
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (int j = 0; j <= vps_max_layers_minus1; j++) {
301 4 skip_bits1(gb); // vps_ols_output_layer_flag[i][j]
302 }
303 }
304 }
305 }
306 2 vps_num_ptls_minus1 = get_bits(gb, 8);
307 }
308
309
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (int i = 0; i <= vps_num_ptls_minus1; i++) {
310
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (i > 0)
311 2 vps_pt_present_flag[i] = get_bits1(gb);
312 else
313 2 vps_pt_present_flag[i] = 1;
314
315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!vps_default_ptl_dpb_hrd_max_tid_flag) {
316 ✗ vps_ptl_max_tid[i] = get_bits(gb, 3);
317 ✗ if (vps_ptl_max_tid[i] > vps_max_sublayers_minus1)
318 ✗ return AVERROR_INVALIDDATA;
319 } else
320 4 vps_ptl_max_tid[i] = vps_max_sublayers_minus1;
321 }
322
323 2 align_get_bits(gb);
324
325
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (int i = 0; i <= vps_num_ptls_minus1; i++)
326 4 vvcc_parse_ptl(gb, vvcc, vps_pt_present_flag[i], vps_ptl_max_tid[i]);
327 2 vvcc->ptl_present_flag = 1;
328
329 /* nothing useful for vvcc past this point */
330 2 return 0;
331 }
332
333 3 static int vvcc_parse_sps(GetBitContext *gb,
334 VVCDecoderConfigurationRecord *vvcc)
335 {
336 unsigned int sps_max_sublayers_minus1, sps_log2_ctu_size_minus5;
337 unsigned int sps_subpic_same_size_flag, sps_pic_height_max_in_luma_samples,
338 sps_pic_width_max_in_luma_samples;
339 unsigned int sps_independent_subpics_flag;
340
341 3 skip_bits(gb, 8); // sps_seq_parameter_set_id && sps_video_parameter_set_id
342 3 sps_max_sublayers_minus1 = get_bits(gb, 3);
343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (sps_max_sublayers_minus1 >= VVC_MAX_SUBLAYERS)
344 ✗ return AVERROR_INVALIDDATA;
345
346 /*
347 * numTemporalLayers greater than 1 indicates that the stream to which this
348 * configuration record applies is temporally scalable and the contained
349 * number of temporal layers (also referred to as temporal sub-layer or
350 * sub-layer in ISO/IEC 23008-2) is equal to numTemporalLayers. Value 1
351 * indicates that the stream is not temporally scalable. Value 0 indicates
352 * that it is unknown whether the stream is temporally scalable.
353 */
354 3 vvcc->num_sublayers = FFMAX(vvcc->num_sublayers,
355 sps_max_sublayers_minus1 + 1);
356
357 3 vvcc->chroma_format_idc = get_bits(gb, 2);
358 3 sps_log2_ctu_size_minus5 = get_bits(gb, 2);
359
360
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (get_bits1(gb)) { // sps_ptl_dpb_hrd_params_present_flag
361 3 vvcc->ptl_present_flag = 1;
362 3 vvcc_parse_ptl(gb, vvcc, 1, sps_max_sublayers_minus1);
363 }
364
365 3 skip_bits1(gb); // sps_gdr_enabled_flag
366
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (get_bits(gb, 1)) // sps_ref_pic_resampling_enabled_flag
367 3 skip_bits1(gb); // sps_res_change_in_clvs_allowed_flag
368
369 3 sps_pic_width_max_in_luma_samples = get_ue_golomb_long(gb);
370 3 vvcc->max_picture_width =
371 3 FFMAX(vvcc->max_picture_width, sps_pic_width_max_in_luma_samples);
372 3 sps_pic_height_max_in_luma_samples = get_ue_golomb_long(gb);
373 3 vvcc->max_picture_height =
374 3 FFMAX(vvcc->max_picture_height, sps_pic_height_max_in_luma_samples);
375
376
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (get_bits1(gb)) {
377 ✗ get_ue_golomb_long(gb); // sps_conf_win_left_offset
378 ✗ get_ue_golomb_long(gb); // sps_conf_win_right_offset
379 ✗ get_ue_golomb_long(gb); // sps_conf_win_top_offset
380 ✗ get_ue_golomb_long(gb); // sps_conf_win_bottom_offset
381 }
382
383
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (get_bits1(gb)) { // sps_subpic_info_present_flag
384 ✗ const unsigned int sps_num_subpics_minus1 = get_ue_golomb_long(gb);
385 ✗ const int ctb_log2_size_y = sps_log2_ctu_size_minus5 + 5;
386 ✗ const int ctb_size_y = 1 << ctb_log2_size_y;
387 ✗ const int tmp_width_val = AV_CEIL_RSHIFT(sps_pic_width_max_in_luma_samples, ctb_log2_size_y);
388 ✗ const int tmp_height_val = AV_CEIL_RSHIFT(sps_pic_height_max_in_luma_samples, ctb_log2_size_y);
389 ✗ const int wlen = av_ceil_log2(tmp_width_val);
390 ✗ const int hlen = av_ceil_log2(tmp_height_val);
391 unsigned int sps_subpic_id_len;
392 ✗ if (sps_num_subpics_minus1 > 0) { // sps_num_subpics_minus1
393 ✗ sps_independent_subpics_flag = get_bits1(gb);
394 ✗ sps_subpic_same_size_flag = get_bits1(gb);
395 }
396 ✗ for (int i = 0; sps_num_subpics_minus1 > 0 && i <= sps_num_subpics_minus1; i++) {
397 ✗ if (!sps_subpic_same_size_flag || i == 0) {
398 ✗ if (i > 0 && sps_pic_width_max_in_luma_samples > ctb_size_y)
399 ✗ skip_bits(gb, wlen);
400 ✗ if (i > 0 && sps_pic_height_max_in_luma_samples > ctb_size_y)
401 ✗ skip_bits(gb, hlen);
402 ✗ if (i < sps_num_subpics_minus1 && sps_pic_width_max_in_luma_samples > ctb_size_y)
403 ✗ skip_bits(gb, wlen);
404 ✗ if (i < sps_num_subpics_minus1 && sps_pic_height_max_in_luma_samples > ctb_size_y)
405 ✗ skip_bits(gb, hlen);
406 }
407 ✗ if (!sps_independent_subpics_flag) {
408 ✗ skip_bits(gb, 2); // sps_subpic_treated_as_pic_flag && sps_loop_filter_across_subpic_enabled_flag
409 }
410 }
411 ✗ sps_subpic_id_len = get_ue_golomb_long(gb) + 1;
412 ✗ if (get_bits1(gb)) { // sps_subpic_id_mapping_explicitly_signalled_flag
413 ✗ if (get_bits1(gb)) // sps_subpic_id_mapping_present_flag
414 ✗ for (int i = 0; i <= sps_num_subpics_minus1; i++) {
415 ✗ skip_bits_long(gb, sps_subpic_id_len); // sps_subpic_id[i]
416 }
417 }
418 }
419 3 vvcc->bit_depth_minus8 = get_ue_golomb_long(gb);
420
421 /* nothing useful for vvcc past this point */
422 3 return 0;
423 }
424
425 3 static int vvcc_parse_pps(GetBitContext *gb,
426 VVCDecoderConfigurationRecord *vvcc)
427 {
428
429 // Nothing of importance to parse in PPS
430 /* nothing useful for vvcc past this point */
431 3 return 0;
432 }
433
434 8 static void nal_unit_parse_header(GetBitContext *gb, uint8_t *nal_type)
435 {
436 /*
437 * forbidden_zero_bit u(1)
438 * nuh_reserved_zero_bit u(1)
439 * nuh_layer_id u(6)
440 */
441 8 skip_bits(gb, 8);
442 8 *nal_type = get_bits(gb, 5);
443
444 /*
445 * nuh_temporal_id_plus1 u(3)
446 */
447 8 skip_bits(gb, 3);
448 8 }
449
450 8 static int vvcc_array_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size,
451 uint8_t nal_type, int ps_array_completeness,
452 VVCCNALUnitArray *array)
453 {
454 int ret;
455 uint16_t num_nalus;
456
457 8 num_nalus = array->num_nalus;
458
459 8 ret = av_reallocp_array(&array->nal_unit, num_nalus + 1, sizeof(uint8_t *));
460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
461 ✗ return ret;
462
463 ret =
464 8 av_reallocp_array(&array->nal_unit_length, num_nalus + 1,
465 sizeof(uint16_t));
466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
467 ✗ return ret;
468
469 8 array->nal_unit[num_nalus] = nal_buf;
470 8 array->nal_unit_length[num_nalus] = nal_size;
471 8 array->NAL_unit_type = nal_type;
472 8 array->num_nalus++;
473
474 /*
475 * When the sample entry name is 'vvc1', the following applies:
476 * • The value of array_completeness shall be equal to 1 for arrays of SPS,
477 * and PPS NAL units.
478 * • If a VVC bitstream includes DCI NAL unit(s), the value of
479 * array_completeness shall be equal to 1 for the array of DCI units.
480 * Otherwise, NAL_unit_type shall not indicate DCI NAL units.
481 * • If a VVC bitstream includes VPS NAL unit(s), the value of
482 * array_completeness shall be equal to 1 for the array of VPS NAL units.
483 * Otherwise, NAL_unit_type shall not indicate VPS NAL units.
484 * When the value of array_completeness is equal to 1 for an array of a
485 * particular NAL_unit_type value, NAL units of that NAL_unit_type value
486 * cannot be updated without causing a different sample entry to be used.
487 * When the sample entry name is 'vvi1', the value of array_completeness
488 * of at least one of the following arrays shall be equal to 0:
489 • The array of DCI NAL units, if present.
490 • The array of VPS NAL units, if present.
491 • The array of SPS NAL units
492 • The array of PPS NAL units.
493 */
494
5/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
8 if (nal_type == VVC_VPS_NUT || nal_type == VVC_SPS_NUT ||
495 ✗ nal_type == VVC_PPS_NUT || nal_type == VVC_DCI_NUT )
496 8 array->array_completeness = ps_array_completeness;
497
498 8 return 0;
499 }
500
501 8 static int vvcc_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size,
502 int ps_array_completeness,
503 VVCDecoderConfigurationRecord *vvcc,
504 unsigned array_idx)
505 {
506 8 int ret = 0;
507 GetBitContext gbc;
508 uint8_t nal_type;
509 uint8_t *rbsp_buf;
510 uint32_t rbsp_size;
511
512 8 rbsp_buf = ff_nal_unit_extract_rbsp(nal_buf, nal_size, &rbsp_size, 2);
513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!rbsp_buf) {
514 ✗ ret = AVERROR(ENOMEM);
515 ✗ goto end;
516 }
517
518 8 ret = init_get_bits8(&gbc, rbsp_buf, rbsp_size);
519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
520 ✗ goto end;
521
522 8 nal_unit_parse_header(&gbc, &nal_type);
523
524 /*
525 * Note: only 'declarative' SEI messages are allowed in
526 * vvcc. Perhaps the SEI playload type should be checked
527 * and non-declarative SEI messages discarded?
528 */
529 8 ret = vvcc_array_add_nal_unit(nal_buf, nal_size, nal_type,
530 ps_array_completeness,
531 &vvcc->arrays[array_idx]);
532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
533 ✗ goto end;
534
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (vvcc->arrays[array_idx].num_nalus == 1)
535 8 vvcc->num_of_arrays++;
536
537
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (nal_type == VVC_VPS_NUT)
538 2 ret = vvcc_parse_vps(&gbc, vvcc);
539
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 else if (nal_type == VVC_SPS_NUT)
540 3 ret = vvcc_parse_sps(&gbc, vvcc);
541
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 else if (nal_type == VVC_PPS_NUT)
542 3 ret = vvcc_parse_pps(&gbc, vvcc);
543 ✗ else if (nal_type == VVC_OPI_NUT) {
544 // not yet supported
545 }
546
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (ret < 0)
547 ✗ goto end;
548
549 8 end:
550 8 av_free(rbsp_buf);
551 8 return ret;
552 }
553
554 3 static void vvcc_init(VVCDecoderConfigurationRecord *vvcc)
555 {
556 3 memset(vvcc, 0, sizeof(VVCDecoderConfigurationRecord));
557 3 vvcc->lengthSizeMinusOne = 3; // 4 bytes
558 3 vvcc->ptl.ptl_frame_only_constraint_flag =
559 3 vvcc->ptl.ptl_multilayer_enabled_flag = 1;
560 3 }
561
562 3 static void vvcc_close(VVCDecoderConfigurationRecord *vvcc)
563 {
564
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
21 for (unsigned i = 0; i < FF_ARRAY_ELEMS(vvcc->arrays); i++) {
565 18 VVCCNALUnitArray *const array = &vvcc->arrays[i];
566
567 18 array->num_nalus = 0;
568 18 av_freep(&array->nal_unit);
569 18 av_freep(&array->nal_unit_length);
570 }
571
572 3 vvcc->num_of_arrays = 0;
573 3 }
574
575 3 static int vvcc_write(AVIOContext *pb, VVCDecoderConfigurationRecord *vvcc)
576 {
577 3 uint16_t vps_count = 0, sps_count = 0, pps_count = 0;
578 /*
579 * It's unclear how to properly compute these fields, so
580 * let's always set them to values meaning 'unspecified'.
581 */
582 3 vvcc->avg_frame_rate = 0;
583 3 vvcc->constant_frame_rate = 1;
584
585 3 av_log(NULL, AV_LOG_TRACE,
586 "lengthSizeMinusOne: %" PRIu8 "\n",
587 3 vvcc->lengthSizeMinusOne);
588 3 av_log(NULL, AV_LOG_TRACE,
589 "ptl_present_flag: %" PRIu8 "\n",
590 3 vvcc->ptl_present_flag);
591 3 av_log(NULL, AV_LOG_TRACE,
592 3 "ols_idx: %" PRIu16 "\n", vvcc->ols_idx);
593 3 av_log(NULL, AV_LOG_TRACE,
594 "num_sublayers: %" PRIu8 "\n",
595 3 vvcc->num_sublayers);
596 3 av_log(NULL, AV_LOG_TRACE,
597 "constant_frame_rate: %" PRIu8 "\n",
598 3 vvcc->constant_frame_rate);
599 3 av_log(NULL, AV_LOG_TRACE,
600 "chroma_format_idc: %" PRIu8 "\n",
601 3 vvcc->chroma_format_idc);
602
603 3 av_log(NULL, AV_LOG_TRACE,
604 "bit_depth_minus8: %" PRIu8 "\n",
605 3 vvcc->bit_depth_minus8);
606 3 av_log(NULL, AV_LOG_TRACE,
607 "num_bytes_constraint_info: %" PRIu8 "\n",
608 3 vvcc->ptl.num_bytes_constraint_info);
609 3 av_log(NULL, AV_LOG_TRACE,
610 "general_profile_idc: %" PRIu8 "\n",
611 3 vvcc->ptl.general_profile_idc);
612 3 av_log(NULL, AV_LOG_TRACE,
613 "general_tier_flag: %" PRIu8 "\n",
614 3 vvcc->ptl.general_tier_flag);
615 3 av_log(NULL, AV_LOG_TRACE,
616 "general_level_idc: %" PRIu8 "\n",
617 3 vvcc->ptl.general_level_idc);
618 3 av_log(NULL, AV_LOG_TRACE,
619 "ptl_frame_only_constraint_flag: %" PRIu8 "\n",
620 3 vvcc->ptl.ptl_frame_only_constraint_flag);
621 3 av_log(NULL, AV_LOG_TRACE,
622 "ptl_multilayer_enabled_flag: %" PRIu8 "\n",
623 3 vvcc->ptl.ptl_multilayer_enabled_flag);
624
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 for (int i = 0; i < vvcc->ptl.num_bytes_constraint_info; i++) {
625 3 av_log(NULL, AV_LOG_TRACE,
626 "general_constraint_info[%d]: %" PRIu8 "\n", i,
627 3 vvcc->ptl.general_constraint_info[i]);
628 }
629
630
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
7 for (int i = 0; i < vvcc->num_sublayers - 1; i++) {
631 4 av_log(NULL, AV_LOG_TRACE,
632 "ptl_sublayer_level_present_flag[%d]: %" PRIu8 "\n", i,
633 4 vvcc->ptl.ptl_sublayer_level_present_flag[i]);
634 4 av_log(NULL, AV_LOG_TRACE,
635 "sublayer_level_idc[%d]: %" PRIu8 "\n", i,
636 4 vvcc->ptl.sublayer_level_idc[i]);
637 }
638
639 3 av_log(NULL, AV_LOG_TRACE,
640 "num_sub_profiles: %" PRIu8 "\n",
641 3 vvcc->ptl.ptl_num_sub_profiles);
642
643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 for (unsigned i = 0; i < vvcc->ptl.ptl_num_sub_profiles; i++) {
644 ✗ av_log(NULL, AV_LOG_TRACE,
645 "general_sub_profile_idc[%u]: %" PRIx32 "\n", i,
646 vvcc->ptl.general_sub_profile_idc[i]);
647 }
648
649 3 av_log(NULL, AV_LOG_TRACE,
650 "max_picture_width: %" PRIu16 "\n",
651 3 vvcc->max_picture_width);
652 3 av_log(NULL, AV_LOG_TRACE,
653 "max_picture_height: %" PRIu16 "\n",
654 3 vvcc->max_picture_height);
655 3 av_log(NULL, AV_LOG_TRACE,
656 "avg_frame_rate: %" PRIu16 "\n",
657 3 vvcc->avg_frame_rate);
658
659 3 av_log(NULL, AV_LOG_TRACE,
660 "num_of_arrays: %" PRIu8 "\n",
661 3 vvcc->num_of_arrays);
662
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
21 for (unsigned i = 0; i < FF_ARRAY_ELEMS(vvcc->arrays); i++) {
663 18 const VVCCNALUnitArray *const array = &vvcc->arrays[i];
664
665
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8 times.
18 if (array->num_nalus == 0)
666 10 continue;
667
668 8 av_log(NULL, AV_LOG_TRACE,
669 "array_completeness[%u]: %" PRIu8 "\n", i,
670 8 array->array_completeness);
671 8 av_log(NULL, AV_LOG_TRACE,
672 "NAL_unit_type[%u]: %" PRIu8 "\n", i,
673 8 array->NAL_unit_type);
674 8 av_log(NULL, AV_LOG_TRACE,
675 "num_nalus[%u]: %" PRIu16 "\n", i,
676 8 array->num_nalus);
677
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for (unsigned j = 0; j < array->num_nalus; j++)
678 8 av_log(NULL, AV_LOG_TRACE,
679 "nal_unit_length[%u][%u]: %"
680 8 PRIu16 "\n", i, j, array->nal_unit_length[j]);
681 }
682
683 /*
684 * We need at least one of each: SPS and PPS.
685 */
686 3 vps_count = vvcc->arrays[VPS_INDEX].num_nalus;
687 3 sps_count = vvcc->arrays[SPS_INDEX].num_nalus;
688 3 pps_count = vvcc->arrays[PPS_INDEX].num_nalus;
689
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (vps_count > VVC_MAX_VPS_COUNT)
690 ✗ return AVERROR_INVALIDDATA;
691
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (!sps_count || sps_count > VVC_MAX_SPS_COUNT)
692 ✗ return AVERROR_INVALIDDATA;
693
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (!pps_count || pps_count > VVC_MAX_PPS_COUNT)
694 ✗ return AVERROR_INVALIDDATA;
695
696 /* bit(5) reserved = ‘11111’b;
697 unsigned int (2) LengthSizeMinusOne
698 unsigned int (1) ptl_present_flag */
699 3 avio_w8(pb, vvcc->lengthSizeMinusOne << 1 | vvcc->ptl_present_flag | 0xf8);
700
701
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (vvcc->ptl_present_flag) {
702 uint8_t buf[64];
703 PutBitContext pbc;
704
705 3 init_put_bits(&pbc, buf, sizeof(buf));
706 /*
707 * unsigned int(9) ols_idx;
708 * unsigned int(3) num_sublayers;
709 * unsigned int(2) constant_frame_rate;
710 * unsigned int(2) chroma_format_idc; */
711 3 avio_wb16(pb,
712 3 vvcc->ols_idx << 7 | vvcc->num_sublayers << 4 | vvcc->
713 3 constant_frame_rate << 2 | vvcc->chroma_format_idc);
714
715 /* unsigned int(3) bit_depth_minus8;
716 bit(5) reserved = ‘11111’b; */
717 3 avio_w8(pb, vvcc->bit_depth_minus8 << 5 | 0x1f);
718
719 //VVCPTLRecord
720
721 /* bit(2) reserved = ‘00’b;
722 unsigned int (6) num_bytes_constraint_info */
723 3 avio_w8(pb, vvcc->ptl.num_bytes_constraint_info & 0x3f);
724
725 /* unsigned int (7) general_profile_idc
726 unsigned int (1) general_tier_flag */
727 3 avio_w8(pb,
728 3 vvcc->ptl.general_profile_idc << 1 | vvcc->ptl.general_tier_flag);
729
730 /* unsigned int (8) general_level_idc */
731 3 avio_w8(pb, vvcc->ptl.general_level_idc);
732
733 /*
734 * unsigned int (1) ptl_frame_only_constraint_flag
735 * unsigned int (1) ptl_multilayer_enabled_flag
736 * unsigned int (8*num_bytes_constraint_info -2) general_constraint_info */
737 3 put_bits(&pbc, 1, vvcc->ptl.ptl_frame_only_constraint_flag);
738 3 put_bits(&pbc, 1, vvcc->ptl.ptl_multilayer_enabled_flag);
739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 av_assert0(vvcc->ptl.num_bytes_constraint_info);
740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 for (int i = 0; i < vvcc->ptl.num_bytes_constraint_info - 1; i++)
741 ✗ put_bits(&pbc, 8, vvcc->ptl.general_constraint_info[i]);
742 3 put_bits(&pbc, 6, vvcc->ptl.general_constraint_info[vvcc->ptl.num_bytes_constraint_info - 1] & 0x3f);
743 3 flush_put_bits(&pbc);
744 3 avio_write(pb, buf, put_bytes_output(&pbc));
745
746
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (vvcc->num_sublayers > 1) {
747 1 uint8_t ptl_sublayer_level_present_flags = 0;
748
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (int i = vvcc->num_sublayers - 2; i >= 0; i--) {
749 4 ptl_sublayer_level_present_flags =
750 4 (ptl_sublayer_level_present_flags << 1 | vvcc->ptl.
751 4 ptl_sublayer_level_present_flag[i]);
752 }
753 1 avio_w8(pb, ptl_sublayer_level_present_flags);
754 }
755
756
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
7 for (int i = vvcc->num_sublayers - 2; i >= 0; i--) {
757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (vvcc->ptl.ptl_sublayer_level_present_flag[i])
758 ✗ avio_w8(pb, vvcc->ptl.sublayer_level_idc[i]);
759 }
760
761 /* unsigned int(8) num_sub_profiles; */
762 3 avio_w8(pb, vvcc->ptl.ptl_num_sub_profiles);
763
764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 for (int j = 0; j < vvcc->ptl.ptl_num_sub_profiles; j++) {
765 /* unsigned int(32) general_sub_profile_idc[j]; */
766 ✗ avio_wb32(pb, vvcc->ptl.general_sub_profile_idc[j]);
767 }
768
769 //End of VvcPTLRecord
770
771 /*
772 * unsigned int(16) max_picture_width;*/
773 3 avio_wb16(pb, vvcc->max_picture_width);
774
775 /*
776 * unsigned int(16) max_picture_height;*/
777 3 avio_wb16(pb, vvcc->max_picture_height);
778
779 /*
780 * unsigned int(16) avg_frame_rate; */
781 3 avio_wb16(pb, vvcc->avg_frame_rate);
782 }
783
784 /* unsigned int(8) num_of_arrays; */
785 3 avio_w8(pb, vvcc->num_of_arrays);
786
787
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
21 for (unsigned i = 0; i < FF_ARRAY_ELEMS(vvcc->arrays); i++) {
788 18 const VVCCNALUnitArray *const array = &vvcc->arrays[i];
789
790
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8 times.
18 if (!array->num_nalus)
791 10 continue;
792 /*
793 * bit(1) array_completeness;
794 * unsigned int(2) reserved = 0;
795 * unsigned int(5) NAL_unit_type;
796 */
797 8 avio_w8(pb, array->array_completeness << 7 |
798 8 array->NAL_unit_type & 0x1f);
799 /* unsigned int(16) num_nalus; */
800
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (array->NAL_unit_type != VVC_DCI_NUT &&
801
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 array->NAL_unit_type != VVC_OPI_NUT)
802 8 avio_wb16(pb, array->num_nalus);
803
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for (int j = 0; j < array->num_nalus; j++) {
804 /* unsigned int(16) nal_unit_length; */
805 8 avio_wb16(pb, array->nal_unit_length[j]);
806
807 /* bit(8*nal_unit_length) nal_unit; */
808 8 avio_write(pb, array->nal_unit[j],
809 8 array->nal_unit_length[j]);
810 }
811 }
812
813 3 return 0;
814 }
815
816 27 int ff_vvc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in,
817 int size, int filter_ps, int *ps_count)
818 {
819 27 int num_ps = 0, ret = 0;
820 27 uint8_t *buf, *end, *start = NULL;
821
822
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 if (!filter_ps) {
823 27 ret = ff_nal_parse_units(pb, buf_in, size);
824 27 goto end;
825 }
826
827 ✗ ret = ff_nal_parse_units_buf(buf_in, &start, &size);
828 ✗ if (ret < 0)
829 ✗ goto end;
830
831 ✗ ret = 0;
832 ✗ buf = start;
833 ✗ end = start + size;
834
835 ✗ while (end - buf > 4) {
836 ✗ uint32_t len = FFMIN(AV_RB32(buf), end - buf - 4);
837 ✗ uint8_t type = (buf[5] >> 3);
838
839 ✗ buf += 4;
840
841 ✗ switch (type) {
842 ✗ case VVC_VPS_NUT:
843 case VVC_SPS_NUT:
844 case VVC_PPS_NUT:
845 ✗ num_ps++;
846 ✗ break;
847 ✗ default:
848 ✗ ret += 4 + len;
849 ✗ avio_wb32(pb, len);
850 ✗ avio_write(pb, buf, len);
851 ✗ break;
852 }
853
854 ✗ buf += len;
855 }
856
857 ✗ end:
858 27 av_free(start);
859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (ps_count)
860 ✗ *ps_count = num_ps;
861 27 return ret;
862 }
863
864 17 int ff_vvc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out,
865 int *size, int filter_ps, int *ps_count)
866 {
867 AVIOContext *pb;
868 int ret;
869
870 17 ret = avio_open_dyn_buf(&pb);
871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (ret < 0)
872 ✗ return ret;
873
874 17 ret = ff_vvc_annexb2mp4(pb, buf_in, *size, filter_ps, ps_count);
875
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (ret < 0) {
876 ✗ ffio_free_dyn_buf(&pb);
877 ✗ return ret;
878 }
879
880 17 *size = avio_close_dyn_buf(pb, buf_out);
881
882 17 return 0;
883 }
884
885 3 int ff_isom_write_vvcc(AVIOContext *pb, const uint8_t *data,
886 int size, int ps_array_completeness)
887 {
888 VVCDecoderConfigurationRecord vvcc;
889 uint8_t *buf, *end, *start;
890 int ret;
891
892
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (size < 6) {
893 /* We can't write a valid vvcc from the provided data */
894 ✗ return AVERROR_INVALIDDATA;
895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 } else if ((*data & 0xf8) == 0xf8) {
896 /* Data is already vvcc-formatted */
897 ✗ avio_write(pb, data, size);
898 ✗ return 0;
899
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 } else if (!(AV_RB24(data) == 1 || AV_RB32(data) == 1)) {
900 /* Not a valid Annex B start code prefix */
901 ✗ return AVERROR_INVALIDDATA;
902 }
903
904 3 ret = ff_nal_parse_units_buf(data, &start, &size);
905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
906 ✗ return ret;
907
908 3 vvcc_init(&vvcc);
909
910 3 buf = start;
911 3 end = start + size;
912
913
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 while (end - buf > 4) {
914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 uint32_t len = FFMIN(AV_RB32(buf), end - buf - 4);
915 8 uint8_t type = (buf[5] >> 3);
916
917 8 buf += 4;
918
919
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (unsigned i = 0; i < FF_ARRAY_ELEMS(vvcc.arrays); i++) {
920 static const uint8_t array_idx_to_type[] =
921 { VVC_OPI_NUT, VVC_VPS_NUT, VVC_SPS_NUT,
922 VVC_PPS_NUT, VVC_PREFIX_SEI_NUT, VVC_SUFFIX_SEI_NUT };
923
924
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 17 times.
25 if (type == array_idx_to_type[i]) {
925 8 ret = vvcc_add_nal_unit(buf, len, ps_array_completeness,
926 &vvcc, i);
927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
928 ✗ goto end;
929 8 break;
930 }
931 }
932
933 8 buf += len;
934 }
935
936 3 ret = vvcc_write(pb, &vvcc);
937
938 3 end:
939 3 vvcc_close(&vvcc);
940 3 av_free(start);
941 3 return ret;
942 }
943