Coverage Report

Created: 2026-04-01 07:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/cbs_h266_syntax_template.c
Line
Count
Source
1
/*
2
 * This file is part of FFmpeg.
3
 *
4
 * FFmpeg is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * FFmpeg is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with FFmpeg; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
 */
18
19
static int FUNC(rbsp_trailing_bits) (CodedBitstreamContext *ctx,
20
                                     RWContext *rw)
21
835k
{
22
835k
    int err;
23
24
835k
    fixed(1, rbsp_stop_one_bit, 1);
25
1.76M
    while (byte_alignment(rw) != 0)
26
1.02M
        fixed(1, rbsp_alignment_zero_bit, 0);
27
739k
    return 0;
28
763k
}
cbs_h266.c:cbs_h266_read_rbsp_trailing_bits
Line
Count
Source
21
776k
{
22
776k
    int err;
23
24
776k
    fixed(1, rbsp_stop_one_bit, 1);
25
1.59M
    while (byte_alignment(rw) != 0)
26
912k
        fixed(1, rbsp_alignment_zero_bit, 0);
27
680k
    return 0;
28
704k
}
cbs_h266.c:cbs_h266_write_rbsp_trailing_bits
Line
Count
Source
21
58.8k
{
22
58.8k
    int err;
23
24
58.8k
    fixed(1, rbsp_stop_one_bit, 1);
25
171k
    while (byte_alignment(rw) != 0)
26
112k
        fixed(1, rbsp_alignment_zero_bit, 0);
27
58.8k
    return 0;
28
58.8k
}
29
30
static int FUNC(nal_unit_header) (CodedBitstreamContext *ctx, RWContext *rw,
31
                                  H266RawNALUnitHeader *current,
32
                                  int expected_nal_unit_type)
33
9.72M
{
34
9.72M
    int err;
35
36
9.72M
    fixed(1, forbidden_zero_bit, 0);
37
9.72M
    flag(nuh_reserved_zero_bit);
38
39
9.72M
    u(6, nuh_layer_id, 0, 55);
40
41
9.71M
    if (expected_nal_unit_type >= 0)
42
9.71M
        u(5, nal_unit_type, expected_nal_unit_type, expected_nal_unit_type);
43
7.73M
    else
44
7.73M
        ub(5, nal_unit_type);
45
46
9.70M
    u(3, nuh_temporal_id_plus1, 1, 7);
47
9.70M
    return 0;
48
9.70M
}
cbs_h266.c:cbs_h266_read_nal_unit_header
Line
Count
Source
33
9.61M
{
34
9.61M
    int err;
35
36
9.61M
    fixed(1, forbidden_zero_bit, 0);
37
9.61M
    flag(nuh_reserved_zero_bit);
38
39
9.61M
    u(6, nuh_layer_id, 0, 55);
40
41
9.59M
    if (expected_nal_unit_type >= 0)
42
9.59M
        u(5, nal_unit_type, expected_nal_unit_type, expected_nal_unit_type);
43
7.69M
    else
44
7.69M
        ub(5, nal_unit_type);
45
46
9.59M
    u(3, nuh_temporal_id_plus1, 1, 7);
47
9.59M
    return 0;
48
9.59M
}
cbs_h266.c:cbs_h266_write_nal_unit_header
Line
Count
Source
33
116k
{
34
116k
    int err;
35
36
116k
    fixed(1, forbidden_zero_bit, 0);
37
116k
    flag(nuh_reserved_zero_bit);
38
39
116k
    u(6, nuh_layer_id, 0, 55);
40
41
116k
    if (expected_nal_unit_type >= 0)
42
116k
        u(5, nal_unit_type, expected_nal_unit_type, expected_nal_unit_type);
43
46.8k
    else
44
46.8k
        ub(5, nal_unit_type);
45
46
116k
    u(3, nuh_temporal_id_plus1, 1, 7);
47
116k
    return 0;
48
116k
}
49
50
static int FUNC(byte_alignment) (CodedBitstreamContext *ctx, RWContext *rw)
51
5.58M
{
52
5.58M
    int err;
53
54
5.58M
    fixed(1, byte_alignment_bit_equal_to_one, 1);
55
5.84M
    while (byte_alignment(rw) != 0)
56
886k
        fixed(1, byte_alignment_bit_equal_to_zero, 0);
57
4.96M
    return 0;
58
5.42M
}
cbs_h266.c:cbs_h266_read_byte_alignment
Line
Count
Source
51
5.56M
{
52
5.56M
    int err;
53
54
5.56M
    fixed(1, byte_alignment_bit_equal_to_one, 1);
55
5.79M
    while (byte_alignment(rw) != 0)
56
849k
        fixed(1, byte_alignment_bit_equal_to_zero, 0);
57
4.94M
    return 0;
58
5.40M
}
cbs_h266.c:cbs_h266_write_byte_alignment
Line
Count
Source
51
19.2k
{
52
19.2k
    int err;
53
54
19.2k
    fixed(1, byte_alignment_bit_equal_to_one, 1);
55
56.2k
    while (byte_alignment(rw) != 0)
56
37.0k
        fixed(1, byte_alignment_bit_equal_to_zero, 0);
57
19.2k
    return 0;
58
19.2k
}
59
60
static int FUNC(general_constraints_info) (CodedBitstreamContext *ctx,
61
                                           RWContext *rw,
62
                                           H266GeneralConstraintsInfo *current)
63
308k
{
64
308k
    int err, i, num_additional_bits_used;
65
66
308k
    flag(gci_present_flag);
67
308k
    if (current->gci_present_flag) {
68
        /* general */
69
52.8k
        flag(gci_intra_only_constraint_flag);
70
52.8k
        flag(gci_all_layers_independent_constraint_flag);
71
52.8k
        flag(gci_one_au_only_constraint_flag);
72
73
        /* picture format */
74
52.8k
        u(4, gci_sixteen_minus_max_bitdepth_constraint_idc, 0, 8);
75
47.0k
        ub(2, gci_three_minus_max_chroma_format_constraint_idc);
76
77
        /* NAL unit type related */
78
47.0k
        flag(gci_no_mixed_nalu_types_in_pic_constraint_flag);
79
47.0k
        flag(gci_no_trail_constraint_flag);
80
47.0k
        flag(gci_no_stsa_constraint_flag);
81
47.0k
        flag(gci_no_rasl_constraint_flag);
82
47.0k
        flag(gci_no_radl_constraint_flag);
83
45.7k
        flag(gci_no_idr_constraint_flag);
84
45.7k
        flag(gci_no_cra_constraint_flag);
85
45.7k
        flag(gci_no_gdr_constraint_flag);
86
45.7k
        flag(gci_no_aps_constraint_flag);
87
45.7k
        flag(gci_no_idr_rpl_constraint_flag);
88
89
        /* tile, slice, subpicture partitioning */
90
45.7k
        flag(gci_one_tile_per_pic_constraint_flag);
91
45.7k
        flag(gci_pic_header_in_slice_header_constraint_flag);
92
45.7k
        flag(gci_one_slice_per_pic_constraint_flag);
93
42.9k
        flag(gci_no_rectangular_slice_constraint_flag);
94
42.9k
        flag(gci_one_slice_per_subpic_constraint_flag);
95
42.9k
        flag(gci_no_subpic_info_constraint_flag);
96
97
        /* CTU and block partitioning */
98
42.9k
        ub(2, gci_three_minus_max_log2_ctu_size_constraint_idc);
99
42.9k
        flag(gci_no_partition_constraints_override_constraint_flag);
100
42.9k
        flag(gci_no_mtt_constraint_flag);
101
42.9k
        flag(gci_no_qtbtt_dual_tree_intra_constraint_flag);
102
103
        /* intra */
104
41.9k
        flag(gci_no_palette_constraint_flag);
105
41.9k
        flag(gci_no_ibc_constraint_flag);
106
41.9k
        flag(gci_no_isp_constraint_flag);
107
41.9k
        flag(gci_no_mrl_constraint_flag);
108
41.9k
        flag(gci_no_mip_constraint_flag);
109
41.9k
        flag(gci_no_cclm_constraint_flag);
110
111
        /* inter */
112
41.9k
        flag(gci_no_ref_pic_resampling_constraint_flag);
113
41.9k
        flag(gci_no_res_change_in_clvs_constraint_flag);
114
40.7k
        flag(gci_no_weighted_prediction_constraint_flag);
115
40.7k
        flag(gci_no_ref_wraparound_constraint_flag);
116
40.7k
        flag(gci_no_temporal_mvp_constraint_flag);
117
40.7k
        flag(gci_no_sbtmvp_constraint_flag);
118
40.7k
        flag(gci_no_amvr_constraint_flag);
119
40.7k
        flag(gci_no_bdof_constraint_flag);
120
40.7k
        flag(gci_no_smvd_constraint_flag);
121
40.7k
        flag(gci_no_dmvr_constraint_flag);
122
39.8k
        flag(gci_no_mmvd_constraint_flag);
123
39.8k
        flag(gci_no_affine_motion_constraint_flag);
124
39.8k
        flag(gci_no_prof_constraint_flag);
125
39.8k
        flag(gci_no_bcw_constraint_flag);
126
39.8k
        flag(gci_no_ciip_constraint_flag);
127
39.8k
        flag(gci_no_gpm_constraint_flag);
128
129
        /* transform, quantization, residual */
130
39.8k
        flag(gci_no_luma_transform_size_64_constraint_flag);
131
39.8k
        flag(gci_no_transform_skip_constraint_flag);
132
38.7k
        flag(gci_no_bdpcm_constraint_flag);
133
38.7k
        flag(gci_no_mts_constraint_flag);
134
38.7k
        flag(gci_no_lfnst_constraint_flag);
135
38.7k
        flag(gci_no_joint_cbcr_constraint_flag);
136
38.7k
        flag(gci_no_sbt_constraint_flag);
137
38.7k
        flag(gci_no_act_constraint_flag);
138
38.7k
        flag(gci_no_explicit_scaling_list_constraint_flag);
139
38.7k
        flag(gci_no_dep_quant_constraint_flag);
140
37.9k
        flag(gci_no_sign_data_hiding_constraint_flag);
141
37.9k
        flag(gci_no_cu_qp_delta_constraint_flag);
142
37.9k
        flag(gci_no_chroma_qp_offset_constraint_flag);
143
144
        /* loop filter */
145
37.9k
        flag(gci_no_sao_constraint_flag);
146
37.9k
        flag(gci_no_alf_constraint_flag);
147
37.9k
        flag(gci_no_ccalf_constraint_flag);
148
37.9k
        flag(gci_no_lmcs_constraint_flag);
149
37.9k
        flag(gci_no_ladf_constraint_flag);
150
36.5k
        flag(gci_no_virtual_boundaries_constraint_flag);
151
36.5k
        ub(8, gci_num_additional_bits);
152
35.8k
        if (current->gci_num_additional_bits > 5) {
153
21.8k
            flag(gci_all_rap_pictures_constraint_flag);
154
21.8k
            flag(gci_no_extended_precision_processing_constraint_flag);
155
21.8k
            flag(gci_no_ts_residual_coding_rice_constraint_flag);
156
21.8k
            flag(gci_no_rrc_rice_extension_constraint_flag);
157
21.8k
            flag(gci_no_persistent_rice_adaptation_constraint_flag);
158
21.8k
            flag(gci_no_reverse_last_sig_coeff_constraint_flag);
159
21.8k
            num_additional_bits_used = 6;
160
21.8k
        } else {
161
13.9k
            infer(gci_all_rap_pictures_constraint_flag, 0);
162
13.9k
            infer(gci_no_extended_precision_processing_constraint_flag, 0);
163
13.9k
            infer(gci_no_ts_residual_coding_rice_constraint_flag, 0);
164
13.9k
            infer(gci_no_rrc_rice_extension_constraint_flag, 0);
165
13.9k
            infer(gci_no_persistent_rice_adaptation_constraint_flag, 0);
166
13.9k
            infer(gci_no_reverse_last_sig_coeff_constraint_flag, 0);
167
655
            num_additional_bits_used = 0;
168
655
        }
169
170
2.70M
        for (i = 0; i < current->gci_num_additional_bits - num_additional_bits_used; i++)
171
2.67M
            flags(gci_reserved_bit[i], 1, i);
172
35.8k
    }
173
1.59M
    while (byte_alignment(rw) != 0)
174
1.33M
        fixed(1, gci_alignment_zero_bit, 0);
175
262k
    return 0;
176
287k
}
cbs_h266.c:cbs_h266_read_general_constraints_info
Line
Count
Source
63
293k
{
64
293k
    int err, i, num_additional_bits_used;
65
66
293k
    flag(gci_present_flag);
67
293k
    if (current->gci_present_flag) {
68
        /* general */
69
51.3k
        flag(gci_intra_only_constraint_flag);
70
51.3k
        flag(gci_all_layers_independent_constraint_flag);
71
51.3k
        flag(gci_one_au_only_constraint_flag);
72
73
        /* picture format */
74
51.3k
        u(4, gci_sixteen_minus_max_bitdepth_constraint_idc, 0, 8);
75
45.5k
        ub(2, gci_three_minus_max_chroma_format_constraint_idc);
76
77
        /* NAL unit type related */
78
45.5k
        flag(gci_no_mixed_nalu_types_in_pic_constraint_flag);
79
45.5k
        flag(gci_no_trail_constraint_flag);
80
45.5k
        flag(gci_no_stsa_constraint_flag);
81
45.5k
        flag(gci_no_rasl_constraint_flag);
82
45.5k
        flag(gci_no_radl_constraint_flag);
83
44.2k
        flag(gci_no_idr_constraint_flag);
84
44.2k
        flag(gci_no_cra_constraint_flag);
85
44.2k
        flag(gci_no_gdr_constraint_flag);
86
44.2k
        flag(gci_no_aps_constraint_flag);
87
44.2k
        flag(gci_no_idr_rpl_constraint_flag);
88
89
        /* tile, slice, subpicture partitioning */
90
44.2k
        flag(gci_one_tile_per_pic_constraint_flag);
91
44.2k
        flag(gci_pic_header_in_slice_header_constraint_flag);
92
44.2k
        flag(gci_one_slice_per_pic_constraint_flag);
93
41.4k
        flag(gci_no_rectangular_slice_constraint_flag);
94
41.4k
        flag(gci_one_slice_per_subpic_constraint_flag);
95
41.4k
        flag(gci_no_subpic_info_constraint_flag);
96
97
        /* CTU and block partitioning */
98
41.4k
        ub(2, gci_three_minus_max_log2_ctu_size_constraint_idc);
99
41.4k
        flag(gci_no_partition_constraints_override_constraint_flag);
100
41.4k
        flag(gci_no_mtt_constraint_flag);
101
41.4k
        flag(gci_no_qtbtt_dual_tree_intra_constraint_flag);
102
103
        /* intra */
104
40.4k
        flag(gci_no_palette_constraint_flag);
105
40.4k
        flag(gci_no_ibc_constraint_flag);
106
40.4k
        flag(gci_no_isp_constraint_flag);
107
40.4k
        flag(gci_no_mrl_constraint_flag);
108
40.4k
        flag(gci_no_mip_constraint_flag);
109
40.4k
        flag(gci_no_cclm_constraint_flag);
110
111
        /* inter */
112
40.4k
        flag(gci_no_ref_pic_resampling_constraint_flag);
113
40.4k
        flag(gci_no_res_change_in_clvs_constraint_flag);
114
39.2k
        flag(gci_no_weighted_prediction_constraint_flag);
115
39.2k
        flag(gci_no_ref_wraparound_constraint_flag);
116
39.2k
        flag(gci_no_temporal_mvp_constraint_flag);
117
39.2k
        flag(gci_no_sbtmvp_constraint_flag);
118
39.2k
        flag(gci_no_amvr_constraint_flag);
119
39.2k
        flag(gci_no_bdof_constraint_flag);
120
39.2k
        flag(gci_no_smvd_constraint_flag);
121
39.2k
        flag(gci_no_dmvr_constraint_flag);
122
38.3k
        flag(gci_no_mmvd_constraint_flag);
123
38.3k
        flag(gci_no_affine_motion_constraint_flag);
124
38.3k
        flag(gci_no_prof_constraint_flag);
125
38.3k
        flag(gci_no_bcw_constraint_flag);
126
38.3k
        flag(gci_no_ciip_constraint_flag);
127
38.3k
        flag(gci_no_gpm_constraint_flag);
128
129
        /* transform, quantization, residual */
130
38.3k
        flag(gci_no_luma_transform_size_64_constraint_flag);
131
38.3k
        flag(gci_no_transform_skip_constraint_flag);
132
37.2k
        flag(gci_no_bdpcm_constraint_flag);
133
37.2k
        flag(gci_no_mts_constraint_flag);
134
37.2k
        flag(gci_no_lfnst_constraint_flag);
135
37.2k
        flag(gci_no_joint_cbcr_constraint_flag);
136
37.2k
        flag(gci_no_sbt_constraint_flag);
137
37.2k
        flag(gci_no_act_constraint_flag);
138
37.2k
        flag(gci_no_explicit_scaling_list_constraint_flag);
139
37.2k
        flag(gci_no_dep_quant_constraint_flag);
140
36.4k
        flag(gci_no_sign_data_hiding_constraint_flag);
141
36.4k
        flag(gci_no_cu_qp_delta_constraint_flag);
142
36.4k
        flag(gci_no_chroma_qp_offset_constraint_flag);
143
144
        /* loop filter */
145
36.4k
        flag(gci_no_sao_constraint_flag);
146
36.4k
        flag(gci_no_alf_constraint_flag);
147
36.4k
        flag(gci_no_ccalf_constraint_flag);
148
36.4k
        flag(gci_no_lmcs_constraint_flag);
149
36.4k
        flag(gci_no_ladf_constraint_flag);
150
35.0k
        flag(gci_no_virtual_boundaries_constraint_flag);
151
35.0k
        ub(8, gci_num_additional_bits);
152
34.3k
        if (current->gci_num_additional_bits > 5) {
153
21.0k
            flag(gci_all_rap_pictures_constraint_flag);
154
21.0k
            flag(gci_no_extended_precision_processing_constraint_flag);
155
21.0k
            flag(gci_no_ts_residual_coding_rice_constraint_flag);
156
21.0k
            flag(gci_no_rrc_rice_extension_constraint_flag);
157
21.0k
            flag(gci_no_persistent_rice_adaptation_constraint_flag);
158
21.0k
            flag(gci_no_reverse_last_sig_coeff_constraint_flag);
159
21.0k
            num_additional_bits_used = 6;
160
21.0k
        } else {
161
13.3k
            infer(gci_all_rap_pictures_constraint_flag, 0);
162
13.3k
            infer(gci_no_extended_precision_processing_constraint_flag, 0);
163
13.3k
            infer(gci_no_ts_residual_coding_rice_constraint_flag, 0);
164
13.3k
            infer(gci_no_rrc_rice_extension_constraint_flag, 0);
165
13.3k
            infer(gci_no_persistent_rice_adaptation_constraint_flag, 0);
166
13.3k
            infer(gci_no_reverse_last_sig_coeff_constraint_flag, 0);
167
13.3k
            num_additional_bits_used = 0;
168
13.3k
        }
169
170
2.56M
        for (i = 0; i < current->gci_num_additional_bits - num_additional_bits_used; i++)
171
2.53M
            flags(gci_reserved_bit[i], 1, i);
172
34.3k
    }
173
1.50M
    while (byte_alignment(rw) != 0)
174
1.25M
        fixed(1, gci_alignment_zero_bit, 0);
175
247k
    return 0;
176
271k
}
cbs_h266.c:cbs_h266_write_general_constraints_info
Line
Count
Source
63
15.4k
{
64
15.4k
    int err, i, num_additional_bits_used;
65
66
15.4k
    flag(gci_present_flag);
67
15.4k
    if (current->gci_present_flag) {
68
        /* general */
69
1.49k
        flag(gci_intra_only_constraint_flag);
70
1.49k
        flag(gci_all_layers_independent_constraint_flag);
71
1.49k
        flag(gci_one_au_only_constraint_flag);
72
73
        /* picture format */
74
1.49k
        u(4, gci_sixteen_minus_max_bitdepth_constraint_idc, 0, 8);
75
1.49k
        ub(2, gci_three_minus_max_chroma_format_constraint_idc);
76
77
        /* NAL unit type related */
78
1.49k
        flag(gci_no_mixed_nalu_types_in_pic_constraint_flag);
79
1.49k
        flag(gci_no_trail_constraint_flag);
80
1.49k
        flag(gci_no_stsa_constraint_flag);
81
1.49k
        flag(gci_no_rasl_constraint_flag);
82
1.49k
        flag(gci_no_radl_constraint_flag);
83
1.49k
        flag(gci_no_idr_constraint_flag);
84
1.49k
        flag(gci_no_cra_constraint_flag);
85
1.49k
        flag(gci_no_gdr_constraint_flag);
86
1.49k
        flag(gci_no_aps_constraint_flag);
87
1.49k
        flag(gci_no_idr_rpl_constraint_flag);
88
89
        /* tile, slice, subpicture partitioning */
90
1.49k
        flag(gci_one_tile_per_pic_constraint_flag);
91
1.49k
        flag(gci_pic_header_in_slice_header_constraint_flag);
92
1.49k
        flag(gci_one_slice_per_pic_constraint_flag);
93
1.49k
        flag(gci_no_rectangular_slice_constraint_flag);
94
1.49k
        flag(gci_one_slice_per_subpic_constraint_flag);
95
1.49k
        flag(gci_no_subpic_info_constraint_flag);
96
97
        /* CTU and block partitioning */
98
1.49k
        ub(2, gci_three_minus_max_log2_ctu_size_constraint_idc);
99
1.49k
        flag(gci_no_partition_constraints_override_constraint_flag);
100
1.49k
        flag(gci_no_mtt_constraint_flag);
101
1.49k
        flag(gci_no_qtbtt_dual_tree_intra_constraint_flag);
102
103
        /* intra */
104
1.49k
        flag(gci_no_palette_constraint_flag);
105
1.49k
        flag(gci_no_ibc_constraint_flag);
106
1.49k
        flag(gci_no_isp_constraint_flag);
107
1.49k
        flag(gci_no_mrl_constraint_flag);
108
1.49k
        flag(gci_no_mip_constraint_flag);
109
1.49k
        flag(gci_no_cclm_constraint_flag);
110
111
        /* inter */
112
1.49k
        flag(gci_no_ref_pic_resampling_constraint_flag);
113
1.49k
        flag(gci_no_res_change_in_clvs_constraint_flag);
114
1.49k
        flag(gci_no_weighted_prediction_constraint_flag);
115
1.49k
        flag(gci_no_ref_wraparound_constraint_flag);
116
1.49k
        flag(gci_no_temporal_mvp_constraint_flag);
117
1.49k
        flag(gci_no_sbtmvp_constraint_flag);
118
1.49k
        flag(gci_no_amvr_constraint_flag);
119
1.49k
        flag(gci_no_bdof_constraint_flag);
120
1.49k
        flag(gci_no_smvd_constraint_flag);
121
1.49k
        flag(gci_no_dmvr_constraint_flag);
122
1.49k
        flag(gci_no_mmvd_constraint_flag);
123
1.49k
        flag(gci_no_affine_motion_constraint_flag);
124
1.49k
        flag(gci_no_prof_constraint_flag);
125
1.49k
        flag(gci_no_bcw_constraint_flag);
126
1.49k
        flag(gci_no_ciip_constraint_flag);
127
1.49k
        flag(gci_no_gpm_constraint_flag);
128
129
        /* transform, quantization, residual */
130
1.49k
        flag(gci_no_luma_transform_size_64_constraint_flag);
131
1.49k
        flag(gci_no_transform_skip_constraint_flag);
132
1.49k
        flag(gci_no_bdpcm_constraint_flag);
133
1.49k
        flag(gci_no_mts_constraint_flag);
134
1.49k
        flag(gci_no_lfnst_constraint_flag);
135
1.49k
        flag(gci_no_joint_cbcr_constraint_flag);
136
1.49k
        flag(gci_no_sbt_constraint_flag);
137
1.49k
        flag(gci_no_act_constraint_flag);
138
1.49k
        flag(gci_no_explicit_scaling_list_constraint_flag);
139
1.49k
        flag(gci_no_dep_quant_constraint_flag);
140
1.49k
        flag(gci_no_sign_data_hiding_constraint_flag);
141
1.49k
        flag(gci_no_cu_qp_delta_constraint_flag);
142
1.49k
        flag(gci_no_chroma_qp_offset_constraint_flag);
143
144
        /* loop filter */
145
1.49k
        flag(gci_no_sao_constraint_flag);
146
1.49k
        flag(gci_no_alf_constraint_flag);
147
1.49k
        flag(gci_no_ccalf_constraint_flag);
148
1.49k
        flag(gci_no_lmcs_constraint_flag);
149
1.49k
        flag(gci_no_ladf_constraint_flag);
150
1.49k
        flag(gci_no_virtual_boundaries_constraint_flag);
151
1.49k
        ub(8, gci_num_additional_bits);
152
1.49k
        if (current->gci_num_additional_bits > 5) {
153
843
            flag(gci_all_rap_pictures_constraint_flag);
154
843
            flag(gci_no_extended_precision_processing_constraint_flag);
155
843
            flag(gci_no_ts_residual_coding_rice_constraint_flag);
156
843
            flag(gci_no_rrc_rice_extension_constraint_flag);
157
843
            flag(gci_no_persistent_rice_adaptation_constraint_flag);
158
843
            flag(gci_no_reverse_last_sig_coeff_constraint_flag);
159
843
            num_additional_bits_used = 6;
160
843
        } else {
161
655
            infer(gci_all_rap_pictures_constraint_flag, 0);
162
655
            infer(gci_no_extended_precision_processing_constraint_flag, 0);
163
655
            infer(gci_no_ts_residual_coding_rice_constraint_flag, 0);
164
655
            infer(gci_no_rrc_rice_extension_constraint_flag, 0);
165
655
            infer(gci_no_persistent_rice_adaptation_constraint_flag, 0);
166
655
            infer(gci_no_reverse_last_sig_coeff_constraint_flag, 0);
167
655
            num_additional_bits_used = 0;
168
655
        }
169
170
140k
        for (i = 0; i < current->gci_num_additional_bits - num_additional_bits_used; i++)
171
138k
            flags(gci_reserved_bit[i], 1, i);
172
1.49k
    }
173
90.1k
    while (byte_alignment(rw) != 0)
174
74.6k
        fixed(1, gci_alignment_zero_bit, 0);
175
15.4k
    return 0;
176
15.4k
}
177
178
static int FUNC(profile_tier_level) (CodedBitstreamContext *ctx,
179
                                     RWContext *rw,
180
                                     H266RawProfileTierLevel *current,
181
                                     int profile_tier_present_flag,
182
                                     int max_num_sub_layers_minus1)
183
365k
{
184
365k
    int err, i;
185
186
365k
    if (profile_tier_present_flag) {
187
335k
        ub(7, general_profile_idc);
188
315k
        flag(general_tier_flag);
189
315k
    }
190
345k
    ub(8, general_level_idc);
191
340k
    flag(ptl_frame_only_constraint_flag);
192
339k
    flag(ptl_multilayer_enabled_flag);
193
339k
    if (profile_tier_present_flag) {
194
308k
        CHECK(FUNC(general_constraints_info) (ctx, rw,
195
308k
                                              &current->
196
308k
                                              general_constraints_info));
197
308k
    }
198
746k
    for (i = max_num_sub_layers_minus1 - 1; i >= 0; i--)
199
454k
        flags(ptl_sublayer_level_present_flag[i], 1, i);
200
873k
    while (byte_alignment(rw) != 0)
201
580k
        flag(ptl_reserved_zero_bit);
202
743k
    for (i = max_num_sub_layers_minus1 - 1; i >= 0; i--)
203
452k
        if (current->ptl_sublayer_level_present_flag[i])
204
292k
            ubs(8, sublayer_level_idc[i], 1, i);
205
291k
    if (profile_tier_present_flag) {
206
260k
        ub(8, ptl_num_sub_profiles);
207
970k
        for (i = 0; i < current->ptl_num_sub_profiles; i++)
208
730k
            ubs(32, general_sub_profile_idc[i], 1, i);
209
260k
    }
210
271k
    return 0;
211
291k
}
cbs_h266.c:cbs_h266_read_profile_tier_level
Line
Count
Source
183
348k
{
184
348k
    int err, i;
185
186
348k
    if (profile_tier_present_flag) {
187
319k
        ub(7, general_profile_idc);
188
299k
        flag(general_tier_flag);
189
299k
    }
190
328k
    ub(8, general_level_idc);
191
323k
    flag(ptl_frame_only_constraint_flag);
192
322k
    flag(ptl_multilayer_enabled_flag);
193
322k
    if (profile_tier_present_flag) {
194
293k
        CHECK(FUNC(general_constraints_info) (ctx, rw,
195
293k
                                              &current->
196
293k
                                              general_constraints_info));
197
293k
    }
198
707k
    for (i = max_num_sub_layers_minus1 - 1; i >= 0; i--)
199
431k
        flags(ptl_sublayer_level_present_flag[i], 1, i);
200
832k
    while (byte_alignment(rw) != 0)
201
557k
        flag(ptl_reserved_zero_bit);
202
704k
    for (i = max_num_sub_layers_minus1 - 1; i >= 0; i--)
203
430k
        if (current->ptl_sublayer_level_present_flag[i])
204
275k
            ubs(8, sublayer_level_idc[i], 1, i);
205
274k
    if (profile_tier_present_flag) {
206
245k
        ub(8, ptl_num_sub_profiles);
207
909k
        for (i = 0; i < current->ptl_num_sub_profiles; i++)
208
684k
            ubs(32, general_sub_profile_idc[i], 1, i);
209
244k
    }
210
254k
    return 0;
211
274k
}
cbs_h266.c:cbs_h266_write_profile_tier_level
Line
Count
Source
183
16.8k
{
184
16.8k
    int err, i;
185
186
16.8k
    if (profile_tier_present_flag) {
187
15.4k
        ub(7, general_profile_idc);
188
15.4k
        flag(general_tier_flag);
189
15.4k
    }
190
16.8k
    ub(8, general_level_idc);
191
16.8k
    flag(ptl_frame_only_constraint_flag);
192
16.8k
    flag(ptl_multilayer_enabled_flag);
193
16.8k
    if (profile_tier_present_flag) {
194
15.4k
        CHECK(FUNC(general_constraints_info) (ctx, rw,
195
15.4k
                                              &current->
196
15.4k
                                              general_constraints_info));
197
15.4k
    }
198
39.3k
    for (i = max_num_sub_layers_minus1 - 1; i >= 0; i--)
199
22.4k
        flags(ptl_sublayer_level_present_flag[i], 1, i);
200
40.4k
    while (byte_alignment(rw) != 0)
201
23.5k
        flag(ptl_reserved_zero_bit);
202
39.3k
    for (i = max_num_sub_layers_minus1 - 1; i >= 0; i--)
203
22.4k
        if (current->ptl_sublayer_level_present_flag[i])
204
16.8k
            ubs(8, sublayer_level_idc[i], 1, i);
205
16.8k
    if (profile_tier_present_flag) {
206
15.4k
        ub(8, ptl_num_sub_profiles);
207
60.9k
        for (i = 0; i < current->ptl_num_sub_profiles; i++)
208
45.4k
            ubs(32, general_sub_profile_idc[i], 1, i);
209
15.4k
    }
210
16.8k
    return 0;
211
16.8k
}
212
213
static int FUNC(vui_parameters_default) (CodedBitstreamContext *ctx,
214
                                         RWContext *rw, H266RawVUI *current)
215
174k
{
216
    //defined in D.8
217
174k
    infer(vui_progressive_source_flag, 0);
218
174k
    infer(vui_interlaced_source_flag, 0);
219
220
174k
    infer(vui_non_packed_constraint_flag, 0);
221
174k
    infer(vui_non_projected_constraint_flag, 0);
222
223
174k
    infer(vui_aspect_ratio_constant_flag, 0);
224
174k
    infer(vui_aspect_ratio_idc, 0);
225
226
174k
    infer(vui_overscan_info_present_flag, 0);
227
228
174k
    infer(vui_colour_primaries, 2);
229
174k
    infer(vui_transfer_characteristics, 2);
230
174k
    infer(vui_matrix_coeffs, 2);
231
174k
    infer(vui_full_range_flag, 0);
232
233
174k
    infer(vui_chroma_sample_loc_type_frame, 6);
234
174k
    infer(vui_chroma_sample_loc_type_top_field, 6);
235
174k
    infer(vui_chroma_sample_loc_type_bottom_field, 6);
236
10.6k
    return 0;
237
10.6k
}
cbs_h266.c:cbs_h266_read_vui_parameters_default
Line
Count
Source
215
163k
{
216
    //defined in D.8
217
163k
    infer(vui_progressive_source_flag, 0);
218
163k
    infer(vui_interlaced_source_flag, 0);
219
220
163k
    infer(vui_non_packed_constraint_flag, 0);
221
163k
    infer(vui_non_projected_constraint_flag, 0);
222
223
163k
    infer(vui_aspect_ratio_constant_flag, 0);
224
163k
    infer(vui_aspect_ratio_idc, 0);
225
226
163k
    infer(vui_overscan_info_present_flag, 0);
227
228
163k
    infer(vui_colour_primaries, 2);
229
163k
    infer(vui_transfer_characteristics, 2);
230
163k
    infer(vui_matrix_coeffs, 2);
231
163k
    infer(vui_full_range_flag, 0);
232
233
163k
    infer(vui_chroma_sample_loc_type_frame, 6);
234
163k
    infer(vui_chroma_sample_loc_type_top_field, 6);
235
163k
    infer(vui_chroma_sample_loc_type_bottom_field, 6);
236
163k
    return 0;
237
163k
}
cbs_h266.c:cbs_h266_write_vui_parameters_default
Line
Count
Source
215
10.6k
{
216
    //defined in D.8
217
10.6k
    infer(vui_progressive_source_flag, 0);
218
10.6k
    infer(vui_interlaced_source_flag, 0);
219
220
10.6k
    infer(vui_non_packed_constraint_flag, 0);
221
10.6k
    infer(vui_non_projected_constraint_flag, 0);
222
223
10.6k
    infer(vui_aspect_ratio_constant_flag, 0);
224
10.6k
    infer(vui_aspect_ratio_idc, 0);
225
226
10.6k
    infer(vui_overscan_info_present_flag, 0);
227
228
10.6k
    infer(vui_colour_primaries, 2);
229
10.6k
    infer(vui_transfer_characteristics, 2);
230
10.6k
    infer(vui_matrix_coeffs, 2);
231
10.6k
    infer(vui_full_range_flag, 0);
232
233
10.6k
    infer(vui_chroma_sample_loc_type_frame, 6);
234
10.6k
    infer(vui_chroma_sample_loc_type_top_field, 6);
235
10.6k
    infer(vui_chroma_sample_loc_type_bottom_field, 6);
236
10.6k
    return 0;
237
10.6k
}
238
239
static int FUNC(vui_parameters) (CodedBitstreamContext *ctx, RWContext *rw,
240
                                 H266RawVUI *current,
241
                                 uint8_t chroma_format_idc)
242
70.0k
{
243
70.0k
    int err;
244
245
70.0k
    flag(vui_progressive_source_flag);
246
69.4k
    flag(vui_interlaced_source_flag);
247
69.4k
    flag(vui_non_packed_constraint_flag);
248
69.4k
    flag(vui_non_projected_constraint_flag);
249
69.4k
    flag(vui_aspect_ratio_info_present_flag);
250
69.4k
    if (current->vui_aspect_ratio_info_present_flag) {
251
48.2k
        flag(vui_aspect_ratio_constant_flag);
252
48.2k
        ub(8, vui_aspect_ratio_idc);
253
47.0k
        if (current->vui_aspect_ratio_idc == 255) {
254
22.5k
            ub(16, vui_sar_width);
255
21.4k
            ub(16, vui_sar_height);
256
21.4k
        }
257
47.0k
    } else {
258
21.1k
        infer(vui_aspect_ratio_constant_flag, 0);
259
21.1k
        infer(vui_aspect_ratio_idc, 0);
260
1.32k
    }
261
66.4k
    flag(vui_overscan_info_present_flag);
262
66.4k
    if (current->vui_overscan_info_present_flag)
263
66.4k
        flag(vui_overscan_appropriate_flag);
264
66.4k
    flag(vui_colour_description_present_flag);
265
65.9k
    if (current->vui_colour_description_present_flag) {
266
25.2k
        ub(8, vui_colour_primaries);
267
24.6k
        av_log(ctx->log_ctx, AV_LOG_DEBUG, "vui_colour_primaries == %d \n",
268
24.6k
               current->vui_colour_primaries);
269
24.6k
        ub(8, vui_transfer_characteristics);
270
23.8k
        av_log(ctx->log_ctx, AV_LOG_DEBUG,
271
23.8k
               "vui_transfer_characteristics == %d \n",
272
23.8k
               current->vui_transfer_characteristics);
273
23.8k
        ub(8, vui_matrix_coeffs);
274
23.2k
        av_log(ctx->log_ctx, AV_LOG_DEBUG, "vui_matrix_coeffs == %d \n",
275
23.2k
               current->vui_matrix_coeffs);
276
23.2k
        flag(vui_full_range_flag);
277
40.7k
    } else {
278
40.7k
        infer(vui_colour_primaries, 2);
279
40.7k
        infer(vui_transfer_characteristics, 2);
280
40.7k
        infer(vui_matrix_coeffs, 2);
281
40.7k
        infer(vui_full_range_flag, 0);
282
2.57k
    }
283
63.0k
    flag(vui_chroma_loc_info_present_flag);
284
62.7k
    if (chroma_format_idc != 1 && current->vui_chroma_loc_info_present_flag) {
285
1.85k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "chroma_format_idc == %d,"
286
1.85k
               "vui_chroma_loc_info_present_flag can't not be true",
287
1.85k
               chroma_format_idc);
288
1.85k
        return AVERROR_INVALIDDATA;
289
1.85k
    }
290
60.8k
    if (current->vui_chroma_loc_info_present_flag) {
291
21.3k
        if (current->vui_progressive_source_flag &&
292
13.5k
            !current->vui_interlaced_source_flag) {
293
4.02k
            ue(vui_chroma_sample_loc_type_frame, 0, 6);
294
17.3k
        } else {
295
17.3k
            ue(vui_chroma_sample_loc_type_top_field, 0, 6);
296
14.8k
            ue(vui_chroma_sample_loc_type_bottom_field, 0, 6);
297
14.8k
        }
298
39.4k
    } else {
299
39.4k
        if (chroma_format_idc == 1) {
300
27.0k
            infer(vui_chroma_sample_loc_type_frame, 6);
301
27.0k
            infer(vui_chroma_sample_loc_type_top_field,
302
1.35k
                  current->vui_chroma_sample_loc_type_frame);
303
27.0k
            infer(vui_chroma_sample_loc_type_bottom_field,
304
1.35k
                  current->vui_chroma_sample_loc_type_frame);
305
1.35k
        }
306
39.4k
    }
307
56.6k
    return 0;
308
60.8k
}
cbs_h266.c:cbs_h266_read_vui_parameters
Line
Count
Source
242
66.6k
{
243
66.6k
    int err;
244
245
66.6k
    flag(vui_progressive_source_flag);
246
65.9k
    flag(vui_interlaced_source_flag);
247
65.9k
    flag(vui_non_packed_constraint_flag);
248
65.9k
    flag(vui_non_projected_constraint_flag);
249
65.9k
    flag(vui_aspect_ratio_info_present_flag);
250
65.9k
    if (current->vui_aspect_ratio_info_present_flag) {
251
46.2k
        flag(vui_aspect_ratio_constant_flag);
252
46.2k
        ub(8, vui_aspect_ratio_idc);
253
44.9k
        if (current->vui_aspect_ratio_idc == 255) {
254
21.6k
            ub(16, vui_sar_width);
255
20.4k
            ub(16, vui_sar_height);
256
20.4k
        }
257
44.9k
    } else {
258
19.7k
        infer(vui_aspect_ratio_constant_flag, 0);
259
19.7k
        infer(vui_aspect_ratio_idc, 0);
260
19.7k
    }
261
63.0k
    flag(vui_overscan_info_present_flag);
262
63.0k
    if (current->vui_overscan_info_present_flag)
263
63.0k
        flag(vui_overscan_appropriate_flag);
264
63.0k
    flag(vui_colour_description_present_flag);
265
62.5k
    if (current->vui_colour_description_present_flag) {
266
24.4k
        ub(8, vui_colour_primaries);
267
23.7k
        av_log(ctx->log_ctx, AV_LOG_DEBUG, "vui_colour_primaries == %d \n",
268
23.7k
               current->vui_colour_primaries);
269
23.7k
        ub(8, vui_transfer_characteristics);
270
23.0k
        av_log(ctx->log_ctx, AV_LOG_DEBUG,
271
23.0k
               "vui_transfer_characteristics == %d \n",
272
23.0k
               current->vui_transfer_characteristics);
273
23.0k
        ub(8, vui_matrix_coeffs);
274
22.4k
        av_log(ctx->log_ctx, AV_LOG_DEBUG, "vui_matrix_coeffs == %d \n",
275
22.4k
               current->vui_matrix_coeffs);
276
22.4k
        flag(vui_full_range_flag);
277
38.1k
    } else {
278
38.1k
        infer(vui_colour_primaries, 2);
279
38.1k
        infer(vui_transfer_characteristics, 2);
280
38.1k
        infer(vui_matrix_coeffs, 2);
281
38.1k
        infer(vui_full_range_flag, 0);
282
38.1k
    }
283
59.5k
    flag(vui_chroma_loc_info_present_flag);
284
59.2k
    if (chroma_format_idc != 1 && current->vui_chroma_loc_info_present_flag) {
285
1.85k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "chroma_format_idc == %d,"
286
1.85k
               "vui_chroma_loc_info_present_flag can't not be true",
287
1.85k
               chroma_format_idc);
288
1.85k
        return AVERROR_INVALIDDATA;
289
1.85k
    }
290
57.4k
    if (current->vui_chroma_loc_info_present_flag) {
291
19.7k
        if (current->vui_progressive_source_flag &&
292
12.6k
            !current->vui_interlaced_source_flag) {
293
3.48k
            ue(vui_chroma_sample_loc_type_frame, 0, 6);
294
16.2k
        } else {
295
16.2k
            ue(vui_chroma_sample_loc_type_top_field, 0, 6);
296
13.7k
            ue(vui_chroma_sample_loc_type_bottom_field, 0, 6);
297
13.7k
        }
298
37.7k
    } else {
299
37.7k
        if (chroma_format_idc == 1) {
300
25.6k
            infer(vui_chroma_sample_loc_type_frame, 6);
301
25.6k
            infer(vui_chroma_sample_loc_type_top_field,
302
25.6k
                  current->vui_chroma_sample_loc_type_frame);
303
25.6k
            infer(vui_chroma_sample_loc_type_bottom_field,
304
25.6k
                  current->vui_chroma_sample_loc_type_frame);
305
25.6k
        }
306
37.7k
    }
307
53.2k
    return 0;
308
57.4k
}
cbs_h266.c:cbs_h266_write_vui_parameters
Line
Count
Source
242
3.41k
{
243
3.41k
    int err;
244
245
3.41k
    flag(vui_progressive_source_flag);
246
3.41k
    flag(vui_interlaced_source_flag);
247
3.41k
    flag(vui_non_packed_constraint_flag);
248
3.41k
    flag(vui_non_projected_constraint_flag);
249
3.41k
    flag(vui_aspect_ratio_info_present_flag);
250
3.41k
    if (current->vui_aspect_ratio_info_present_flag) {
251
2.08k
        flag(vui_aspect_ratio_constant_flag);
252
2.08k
        ub(8, vui_aspect_ratio_idc);
253
2.08k
        if (current->vui_aspect_ratio_idc == 255) {
254
977
            ub(16, vui_sar_width);
255
977
            ub(16, vui_sar_height);
256
977
        }
257
2.08k
    } else {
258
1.32k
        infer(vui_aspect_ratio_constant_flag, 0);
259
1.32k
        infer(vui_aspect_ratio_idc, 0);
260
1.32k
    }
261
3.41k
    flag(vui_overscan_info_present_flag);
262
3.41k
    if (current->vui_overscan_info_present_flag)
263
3.41k
        flag(vui_overscan_appropriate_flag);
264
3.41k
    flag(vui_colour_description_present_flag);
265
3.41k
    if (current->vui_colour_description_present_flag) {
266
841
        ub(8, vui_colour_primaries);
267
841
        av_log(ctx->log_ctx, AV_LOG_DEBUG, "vui_colour_primaries == %d \n",
268
841
               current->vui_colour_primaries);
269
841
        ub(8, vui_transfer_characteristics);
270
841
        av_log(ctx->log_ctx, AV_LOG_DEBUG,
271
841
               "vui_transfer_characteristics == %d \n",
272
841
               current->vui_transfer_characteristics);
273
841
        ub(8, vui_matrix_coeffs);
274
841
        av_log(ctx->log_ctx, AV_LOG_DEBUG, "vui_matrix_coeffs == %d \n",
275
841
               current->vui_matrix_coeffs);
276
841
        flag(vui_full_range_flag);
277
2.57k
    } else {
278
2.57k
        infer(vui_colour_primaries, 2);
279
2.57k
        infer(vui_transfer_characteristics, 2);
280
2.57k
        infer(vui_matrix_coeffs, 2);
281
2.57k
        infer(vui_full_range_flag, 0);
282
2.57k
    }
283
3.41k
    flag(vui_chroma_loc_info_present_flag);
284
3.41k
    if (chroma_format_idc != 1 && current->vui_chroma_loc_info_present_flag) {
285
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "chroma_format_idc == %d,"
286
0
               "vui_chroma_loc_info_present_flag can't not be true",
287
0
               chroma_format_idc);
288
0
        return AVERROR_INVALIDDATA;
289
0
    }
290
3.41k
    if (current->vui_chroma_loc_info_present_flag) {
291
1.65k
        if (current->vui_progressive_source_flag &&
292
892
            !current->vui_interlaced_source_flag) {
293
542
            ue(vui_chroma_sample_loc_type_frame, 0, 6);
294
1.11k
        } else {
295
1.11k
            ue(vui_chroma_sample_loc_type_top_field, 0, 6);
296
1.11k
            ue(vui_chroma_sample_loc_type_bottom_field, 0, 6);
297
1.11k
        }
298
1.76k
    } else {
299
1.76k
        if (chroma_format_idc == 1) {
300
1.35k
            infer(vui_chroma_sample_loc_type_frame, 6);
301
1.35k
            infer(vui_chroma_sample_loc_type_top_field,
302
1.35k
                  current->vui_chroma_sample_loc_type_frame);
303
1.35k
            infer(vui_chroma_sample_loc_type_bottom_field,
304
1.35k
                  current->vui_chroma_sample_loc_type_frame);
305
1.35k
        }
306
1.76k
    }
307
3.41k
    return 0;
308
3.41k
}
309
310
static int FUNC(payload_extension) (CodedBitstreamContext *ctx, RWContext *rw,
311
                                    H266RawExtensionData *current,
312
                                    uint32_t payload_size, int cur_pos)
313
24.8k
{
314
24.8k
    int err;
315
24.8k
    size_t byte_length, k;
316
317
#ifdef READ
318
    GetBitContext tmp;
319
    int bits_left, payload_zero_bits;
320
321
23.6k
    if (!ff_cbs_h2645_payload_extension_present(rw, payload_size, cur_pos))
322
1.65k
        return 0;
323
324
22.0k
    bits_left = 8 * payload_size - cur_pos;
325
22.0k
    tmp = *rw;
326
22.0k
    if (bits_left > 8)
327
16.9k
        skip_bits_long(&tmp, bits_left - 8);
328
22.0k
    payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
329
22.0k
    if (!payload_zero_bits)
330
1.74k
        return AVERROR_INVALIDDATA;
331
20.2k
    payload_zero_bits = ff_ctz(payload_zero_bits);
332
20.2k
    current->bit_length = bits_left - payload_zero_bits - 1;
333
20.2k
    allocate(current->data, (current->bit_length + 7) / 8);
334
20.2k
#endif
335
336
20.2k
    byte_length = (current->bit_length + 7) / 8;
337
125k
    for (k = 0; k < byte_length; k++) {
338
104k
        int length = FFMIN(current->bit_length - k * 8, 8);
339
104k
        xu(length, reserved_payload_extension_data, current->data[k],
340
104k
           0, MAX_UINT_BITS(length), 0);
341
104k
    }
342
343
20.8k
    return 0;
344
20.2k
}
cbs_h266.c:cbs_h266_read_payload_extension
Line
Count
Source
313
23.6k
{
314
23.6k
    int err;
315
23.6k
    size_t byte_length, k;
316
317
23.6k
#ifdef READ
318
23.6k
    GetBitContext tmp;
319
23.6k
    int bits_left, payload_zero_bits;
320
321
23.6k
    if (!ff_cbs_h2645_payload_extension_present(rw, payload_size, cur_pos))
322
1.65k
        return 0;
323
324
22.0k
    bits_left = 8 * payload_size - cur_pos;
325
22.0k
    tmp = *rw;
326
22.0k
    if (bits_left > 8)
327
16.9k
        skip_bits_long(&tmp, bits_left - 8);
328
22.0k
    payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
329
22.0k
    if (!payload_zero_bits)
330
1.74k
        return AVERROR_INVALIDDATA;
331
20.2k
    payload_zero_bits = ff_ctz(payload_zero_bits);
332
20.2k
    current->bit_length = bits_left - payload_zero_bits - 1;
333
20.2k
    allocate(current->data, (current->bit_length + 7) / 8);
334
20.2k
#endif
335
336
20.2k
    byte_length = (current->bit_length + 7) / 8;
337
116k
    for (k = 0; k < byte_length; k++) {
338
97.3k
        int length = FFMIN(current->bit_length - k * 8, 8);
339
97.3k
        xu(length, reserved_payload_extension_data, current->data[k],
340
97.3k
           0, MAX_UINT_BITS(length), 0);
341
97.3k
    }
342
343
19.6k
    return 0;
344
20.2k
}
cbs_h266.c:cbs_h266_write_payload_extension
Line
Count
Source
313
1.14k
{
314
1.14k
    int err;
315
1.14k
    size_t byte_length, k;
316
317
#ifdef READ
318
    GetBitContext tmp;
319
    int bits_left, payload_zero_bits;
320
321
    if (!ff_cbs_h2645_payload_extension_present(rw, payload_size, cur_pos))
322
        return 0;
323
324
    bits_left = 8 * payload_size - cur_pos;
325
    tmp = *rw;
326
    if (bits_left > 8)
327
        skip_bits_long(&tmp, bits_left - 8);
328
    payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
329
    if (!payload_zero_bits)
330
        return AVERROR_INVALIDDATA;
331
    payload_zero_bits = ff_ctz(payload_zero_bits);
332
    current->bit_length = bits_left - payload_zero_bits - 1;
333
    allocate(current->data, (current->bit_length + 7) / 8);
334
#endif
335
336
1.14k
    byte_length = (current->bit_length + 7) / 8;
337
8.44k
    for (k = 0; k < byte_length; k++) {
338
7.29k
        int length = FFMIN(current->bit_length - k * 8, 8);
339
7.29k
        xu(length, reserved_payload_extension_data, current->data[k],
340
7.29k
           0, MAX_UINT_BITS(length), 0);
341
7.29k
    }
342
343
1.14k
    return 0;
344
1.14k
}
345
346
static int FUNC(vui_payload) (CodedBitstreamContext *ctx, RWContext *rw,
347
                              H266RawVUI *current, uint16_t vui_payload_size,
348
                              uint8_t chroma_format_idc)
349
70.0k
{
350
70.0k
    int err;
351
70.0k
    int start_position, current_position;
352
353
70.0k
    start_position = bit_position(rw);
354
70.0k
    CHECK(FUNC(vui_parameters) (ctx, rw, current, chroma_format_idc));
355
56.6k
    current_position = bit_position(rw) - start_position;
356
357
56.6k
    if (current_position < 8 * vui_payload_size) {
358
24.8k
        CHECK(FUNC(payload_extension) (ctx, rw, &current->extension_data,
359
24.8k
                                       vui_payload_size, current_position));
360
22.4k
        fixed(1, vui_payload_bit_equal_to_one, 1);
361
57.8k
        while (byte_alignment(rw) != 0)
362
36.0k
            fixed(1, vui_payload_bit_equal_to_zero, 0);
363
21.8k
    }
364
53.6k
    return 0;
365
56.6k
}
cbs_h266.c:cbs_h266_read_vui_payload
Line
Count
Source
349
66.6k
{
350
66.6k
    int err;
351
66.6k
    int start_position, current_position;
352
353
66.6k
    start_position = bit_position(rw);
354
66.6k
    CHECK(FUNC(vui_parameters) (ctx, rw, current, chroma_format_idc));
355
53.2k
    current_position = bit_position(rw) - start_position;
356
357
53.2k
    if (current_position < 8 * vui_payload_size) {
358
23.6k
        CHECK(FUNC(payload_extension) (ctx, rw, &current->extension_data,
359
23.6k
                                       vui_payload_size, current_position));
360
21.3k
        fixed(1, vui_payload_bit_equal_to_one, 1);
361
55.8k
        while (byte_alignment(rw) != 0)
362
35.1k
            fixed(1, vui_payload_bit_equal_to_zero, 0);
363
20.6k
    }
364
50.2k
    return 0;
365
53.2k
}
cbs_h266.c:cbs_h266_write_vui_payload
Line
Count
Source
349
3.41k
{
350
3.41k
    int err;
351
3.41k
    int start_position, current_position;
352
353
3.41k
    start_position = bit_position(rw);
354
3.41k
    CHECK(FUNC(vui_parameters) (ctx, rw, current, chroma_format_idc));
355
3.41k
    current_position = bit_position(rw) - start_position;
356
357
3.41k
    if (current_position < 8 * vui_payload_size) {
358
1.14k
        CHECK(FUNC(payload_extension) (ctx, rw, &current->extension_data,
359
1.14k
                                       vui_payload_size, current_position));
360
1.14k
        fixed(1, vui_payload_bit_equal_to_one, 1);
361
2.04k
        while (byte_alignment(rw) != 0)
362
896
            fixed(1, vui_payload_bit_equal_to_zero, 0);
363
1.14k
    }
364
3.41k
    return 0;
365
3.41k
}
366
367
static int FUNC(extension_data) (CodedBitstreamContext *ctx, RWContext *rw,
368
                                 H266RawExtensionData *current)
369
576k
{
370
576k
    int err;
371
576k
    size_t k;
372
#ifdef READ
373
    GetBitContext start;
374
    uint8_t bit;
375
    start = *rw;
376
336M
    for (k = 0; ff_cbs_h2645_read_more_rbsp_data(rw); k++)
377
335M
        skip_bits(rw, 1);
378
    current->bit_length = k;
379
540k
    if (k > 0) {
380
491k
        *rw = start;
381
491k
        allocate(current->data, (current->bit_length + 7) / 8);
382
335M
        for (k = 0; k < current->bit_length; k++) {
383
335M
            xu(1, extension_data, bit, 0, 1, 0);
384
335M
            current->data[k / 8] |= bit << (7 - k % 8);
385
335M
        }
386
491k
    }
387
#else
388
144M
    for (k = 0; k < current->bit_length; k++)
389
144M
        xu(1, extension_data, current->data[k / 8] >> (7 - k % 8) & 1, 0, 1, 0);
390
36.0k
#endif
391
576k
    return 0;
392
576k
}
cbs_h266.c:cbs_h266_read_extension_data
Line
Count
Source
369
540k
{
370
540k
    int err;
371
540k
    size_t k;
372
540k
#ifdef READ
373
540k
    GetBitContext start;
374
540k
    uint8_t bit;
375
540k
    start = *rw;
376
336M
    for (k = 0; ff_cbs_h2645_read_more_rbsp_data(rw); k++)
377
335M
        skip_bits(rw, 1);
378
540k
    current->bit_length = k;
379
540k
    if (k > 0) {
380
491k
        *rw = start;
381
491k
        allocate(current->data, (current->bit_length + 7) / 8);
382
335M
        for (k = 0; k < current->bit_length; k++) {
383
335M
            xu(1, extension_data, bit, 0, 1, 0);
384
335M
            current->data[k / 8] |= bit << (7 - k % 8);
385
335M
        }
386
491k
    }
387
#else
388
    for (k = 0; k < current->bit_length; k++)
389
        xu(1, extension_data, current->data[k / 8] >> (7 - k % 8) & 1, 0, 1, 0);
390
#endif
391
540k
    return 0;
392
540k
}
cbs_h266.c:cbs_h266_write_extension_data
Line
Count
Source
369
36.0k
{
370
36.0k
    int err;
371
36.0k
    size_t k;
372
#ifdef READ
373
    GetBitContext start;
374
    uint8_t bit;
375
    start = *rw;
376
    for (k = 0; ff_cbs_h2645_read_more_rbsp_data(rw); k++)
377
        skip_bits(rw, 1);
378
    current->bit_length = k;
379
    if (k > 0) {
380
        *rw = start;
381
        allocate(current->data, (current->bit_length + 7) / 8);
382
        for (k = 0; k < current->bit_length; k++) {
383
            xu(1, extension_data, bit, 0, 1, 0);
384
            current->data[k / 8] |= bit << (7 - k % 8);
385
        }
386
    }
387
#else
388
144M
    for (k = 0; k < current->bit_length; k++)
389
144M
        xu(1, extension_data, current->data[k / 8] >> (7 - k % 8) & 1, 0, 1, 0);
390
36.0k
#endif
391
36.0k
    return 0;
392
36.0k
}
393
394
static int FUNC(dpb_parameters) (CodedBitstreamContext *ctx, RWContext *rw,
395
                                 H266DpbParameters *current,
396
                                 uint8_t max_sublayers_minus1,
397
                                 uint8_t sublayer_info_flag)
398
201k
{
399
201k
    int err, i;
400
201k
    for (i = (sublayer_info_flag ? 0 : max_sublayers_minus1);
401
484k
         i <= max_sublayers_minus1; i++) {
402
290k
        ues(dpb_max_dec_pic_buffering_minus1[i], 0, VVC_MAX_DPB_SIZE - 1, 1, i);
403
286k
        ues(dpb_max_num_reorder_pics[i],
404
283k
            0, current->dpb_max_dec_pic_buffering_minus1[i], 1, i);
405
283k
        ues(dpb_max_latency_increase_plus1[i], 0, UINT32_MAX - 1, 1, i);
406
283k
    }
407
194k
    return 0;
408
201k
}
cbs_h266.c:cbs_h266_read_dpb_parameters
Line
Count
Source
398
188k
{
399
188k
    int err, i;
400
188k
    for (i = (sublayer_info_flag ? 0 : max_sublayers_minus1);
401
456k
         i <= max_sublayers_minus1; i++) {
402
275k
        ues(dpb_max_dec_pic_buffering_minus1[i], 0, VVC_MAX_DPB_SIZE - 1, 1, i);
403
272k
        ues(dpb_max_num_reorder_pics[i],
404
269k
            0, current->dpb_max_dec_pic_buffering_minus1[i], 1, i);
405
269k
        ues(dpb_max_latency_increase_plus1[i], 0, UINT32_MAX - 1, 1, i);
406
269k
    }
407
181k
    return 0;
408
188k
}
cbs_h266.c:cbs_h266_write_dpb_parameters
Line
Count
Source
398
12.8k
{
399
12.8k
    int err, i;
400
12.8k
    for (i = (sublayer_info_flag ? 0 : max_sublayers_minus1);
401
27.5k
         i <= max_sublayers_minus1; i++) {
402
14.6k
        ues(dpb_max_dec_pic_buffering_minus1[i], 0, VVC_MAX_DPB_SIZE - 1, 1, i);
403
14.6k
        ues(dpb_max_num_reorder_pics[i],
404
14.6k
            0, current->dpb_max_dec_pic_buffering_minus1[i], 1, i);
405
14.6k
        ues(dpb_max_latency_increase_plus1[i], 0, UINT32_MAX - 1, 1, i);
406
14.6k
    }
407
12.8k
    return 0;
408
12.8k
}
409
410
static int FUNC(ref_pic_list_struct) (CodedBitstreamContext *ctx,
411
                                      RWContext *rw,
412
                                      H266RefPicListStruct *current,
413
                                      uint8_t list_idx, uint8_t rpls_idx,
414
                                      const H266RawSPS *sps)
415
11.9M
{
416
11.9M
    CodedBitstreamH266Context *h266 = ctx->priv_data;
417
11.9M
    int err, i, j, general_layer_idx = -1, num_direct_ref_layers = 0;
418
11.9M
    const H266RawVPS *vps = h266->vps[sps->sps_video_parameter_set_id];
419
420
11.9M
    if (!vps) {
421
8.76k
        av_log(ctx->log_ctx, AV_LOG_ERROR,
422
8.76k
               "VPS id %d not available.\n", sps->sps_video_parameter_set_id);
423
8.76k
        return AVERROR_INVALIDDATA;
424
8.76k
    }
425
    //7.4.3.3 (29)
426
12.0M
    for (i = 0; i <= vps->vps_max_layers_minus1; i++) {
427
12.0M
        if (sps->nal_unit_header.nuh_layer_id == vps->vps_layer_id[i]) {
428
11.9M
            general_layer_idx = i;
429
11.9M
            break;
430
11.9M
        }
431
12.0M
    }
432
11.9M
    if (general_layer_idx < 0) {
433
43.5k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "vps_layer_id %d not available.\n",
434
43.5k
               sps->nal_unit_header.nuh_layer_id);
435
43.5k
        return AVERROR_INVALIDDATA;
436
43.5k
    }
437
    //7.4.3.3 (28)
438
24.0M
    for (j = 0; j <= vps->vps_max_layers_minus1; j++) {
439
12.1M
        if (vps->vps_direct_ref_layer_flag[general_layer_idx][j])
440
58.9k
            num_direct_ref_layers++;
441
12.1M
    }
442
443
11.9M
    ue(num_ref_entries, 0, VVC_MAX_REF_ENTRIES);
444
11.7M
    if (sps->sps_long_term_ref_pics_flag &&
445
2.34M
        rpls_idx < sps->sps_num_ref_pic_lists[list_idx] &&
446
312k
        current->num_ref_entries > 0)
447
11.7M
        flag(ltrp_in_header_flag);
448
11.7M
    if (sps->sps_long_term_ref_pics_flag &&
449
2.34M
        rpls_idx == sps->sps_num_ref_pic_lists[list_idx])
450
2.03M
        infer(ltrp_in_header_flag, 1);
451
21.2M
    for (i = 0, j = 0; i < current->num_ref_entries; i++) {
452
9.55M
        if (sps->sps_inter_layer_prediction_enabled_flag)
453
9.55M
            flags(inter_layer_ref_pic_flag[i], 1, i);
454
9.40M
        else
455
9.40M
            infer(inter_layer_ref_pic_flag[i], 0);
456
457
9.55M
        if (!current->inter_layer_ref_pic_flag[i]) {
458
9.54M
            if (sps->sps_long_term_ref_pics_flag)
459
9.54M
                flags(st_ref_pic_flag[i], 1, i);
460
6.66M
            else
461
6.66M
                infer(st_ref_pic_flag[i], 1);
462
9.54M
            if (current->st_ref_pic_flag[i]) {
463
8.54M
                int abs_delta_poc_st;
464
8.54M
                ues(abs_delta_poc_st[i], 0, MAX_UINT_BITS(15), 1, i);
465
8.49M
                if ((sps->sps_weighted_pred_flag ||
466
7.24M
                     sps->sps_weighted_bipred_flag) && i != 0)
467
2.75M
                    abs_delta_poc_st = current->abs_delta_poc_st[i];
468
5.74M
                else
469
5.74M
                    abs_delta_poc_st = current->abs_delta_poc_st[i] + 1;
470
8.49M
                if (abs_delta_poc_st > 0)
471
8.49M
                    flags(strp_entry_sign_flag[i], 1, i);
472
8.49M
            } else {
473
998k
                if (!current->ltrp_in_header_flag) {
474
140k
                    uint8_t bits = sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4;
475
140k
                    ubs(bits, rpls_poc_lsb_lt[j], 1, j);
476
138k
                    j++;
477
138k
                }
478
998k
            }
479
9.54M
        } else {
480
10.0k
            if (num_direct_ref_layers == 0) {
481
844
                av_log(ctx->log_ctx, AV_LOG_ERROR,
482
844
                       "num_direct_ref_layers needs > 0.\n");
483
844
                return AVERROR_INVALIDDATA;
484
844
            }
485
9.24k
            ues(ilrp_idx[i], 0, num_direct_ref_layers - 1, 1, i);
486
9.24k
        }
487
9.55M
    }
488
11.6M
    return 0;
489
152k
}
cbs_h266.c:cbs_h266_read_ref_pic_list_struct
Line
Count
Source
415
11.8M
{
416
11.8M
    CodedBitstreamH266Context *h266 = ctx->priv_data;
417
11.8M
    int err, i, j, general_layer_idx = -1, num_direct_ref_layers = 0;
418
11.8M
    const H266RawVPS *vps = h266->vps[sps->sps_video_parameter_set_id];
419
420
11.8M
    if (!vps) {
421
8.56k
        av_log(ctx->log_ctx, AV_LOG_ERROR,
422
8.56k
               "VPS id %d not available.\n", sps->sps_video_parameter_set_id);
423
8.56k
        return AVERROR_INVALIDDATA;
424
8.56k
    }
425
    //7.4.3.3 (29)
426
11.9M
    for (i = 0; i <= vps->vps_max_layers_minus1; i++) {
427
11.8M
        if (sps->nal_unit_header.nuh_layer_id == vps->vps_layer_id[i]) {
428
11.7M
            general_layer_idx = i;
429
11.7M
            break;
430
11.7M
        }
431
11.8M
    }
432
11.7M
    if (general_layer_idx < 0) {
433
43.3k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "vps_layer_id %d not available.\n",
434
43.3k
               sps->nal_unit_header.nuh_layer_id);
435
43.3k
        return AVERROR_INVALIDDATA;
436
43.3k
    }
437
    //7.4.3.3 (28)
438
23.7M
    for (j = 0; j <= vps->vps_max_layers_minus1; j++) {
439
11.9M
        if (vps->vps_direct_ref_layer_flag[general_layer_idx][j])
440
57.2k
            num_direct_ref_layers++;
441
11.9M
    }
442
443
11.7M
    ue(num_ref_entries, 0, VVC_MAX_REF_ENTRIES);
444
11.6M
    if (sps->sps_long_term_ref_pics_flag &&
445
2.33M
        rpls_idx < sps->sps_num_ref_pic_lists[list_idx] &&
446
307k
        current->num_ref_entries > 0)
447
11.6M
        flag(ltrp_in_header_flag);
448
11.6M
    if (sps->sps_long_term_ref_pics_flag &&
449
2.33M
        rpls_idx == sps->sps_num_ref_pic_lists[list_idx])
450
2.02M
        infer(ltrp_in_header_flag, 1);
451
20.7M
    for (i = 0, j = 0; i < current->num_ref_entries; i++) {
452
9.21M
        if (sps->sps_inter_layer_prediction_enabled_flag)
453
9.21M
            flags(inter_layer_ref_pic_flag[i], 1, i);
454
9.06M
        else
455
9.06M
            infer(inter_layer_ref_pic_flag[i], 0);
456
457
9.21M
        if (!current->inter_layer_ref_pic_flag[i]) {
458
9.20M
            if (sps->sps_long_term_ref_pics_flag)
459
9.20M
                flags(st_ref_pic_flag[i], 1, i);
460
6.33M
            else
461
6.33M
                infer(st_ref_pic_flag[i], 1);
462
9.19M
            if (current->st_ref_pic_flag[i]) {
463
8.20M
                int abs_delta_poc_st;
464
8.20M
                ues(abs_delta_poc_st[i], 0, MAX_UINT_BITS(15), 1, i);
465
8.15M
                if ((sps->sps_weighted_pred_flag ||
466
6.93M
                     sps->sps_weighted_bipred_flag) && i != 0)
467
2.72M
                    abs_delta_poc_st = current->abs_delta_poc_st[i];
468
5.43M
                else
469
5.43M
                    abs_delta_poc_st = current->abs_delta_poc_st[i] + 1;
470
8.15M
                if (abs_delta_poc_st > 0)
471
8.15M
                    flags(strp_entry_sign_flag[i], 1, i);
472
8.15M
            } else {
473
990k
                if (!current->ltrp_in_header_flag) {
474
136k
                    uint8_t bits = sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4;
475
136k
                    ubs(bits, rpls_poc_lsb_lt[j], 1, j);
476
134k
                    j++;
477
134k
                }
478
990k
            }
479
9.19M
        } else {
480
9.81k
            if (num_direct_ref_layers == 0) {
481
844
                av_log(ctx->log_ctx, AV_LOG_ERROR,
482
844
                       "num_direct_ref_layers needs > 0.\n");
483
844
                return AVERROR_INVALIDDATA;
484
844
            }
485
8.97k
            ues(ilrp_idx[i], 0, num_direct_ref_layers - 1, 1, i);
486
8.97k
        }
487
9.21M
    }
488
11.5M
    return 0;
489
11.6M
}
cbs_h266.c:cbs_h266_write_ref_pic_list_struct
Line
Count
Source
415
153k
{
416
153k
    CodedBitstreamH266Context *h266 = ctx->priv_data;
417
153k
    int err, i, j, general_layer_idx = -1, num_direct_ref_layers = 0;
418
153k
    const H266RawVPS *vps = h266->vps[sps->sps_video_parameter_set_id];
419
420
153k
    if (!vps) {
421
199
        av_log(ctx->log_ctx, AV_LOG_ERROR,
422
199
               "VPS id %d not available.\n", sps->sps_video_parameter_set_id);
423
199
        return AVERROR_INVALIDDATA;
424
199
    }
425
    //7.4.3.3 (29)
426
154k
    for (i = 0; i <= vps->vps_max_layers_minus1; i++) {
427
154k
        if (sps->nal_unit_header.nuh_layer_id == vps->vps_layer_id[i]) {
428
152k
            general_layer_idx = i;
429
152k
            break;
430
152k
        }
431
154k
    }
432
152k
    if (general_layer_idx < 0) {
433
204
        av_log(ctx->log_ctx, AV_LOG_ERROR, "vps_layer_id %d not available.\n",
434
204
               sps->nal_unit_header.nuh_layer_id);
435
204
        return AVERROR_INVALIDDATA;
436
204
    }
437
    //7.4.3.3 (28)
438
312k
    for (j = 0; j <= vps->vps_max_layers_minus1; j++) {
439
160k
        if (vps->vps_direct_ref_layer_flag[general_layer_idx][j])
440
1.66k
            num_direct_ref_layers++;
441
160k
    }
442
443
152k
    ue(num_ref_entries, 0, VVC_MAX_REF_ENTRIES);
444
152k
    if (sps->sps_long_term_ref_pics_flag &&
445
11.6k
        rpls_idx < sps->sps_num_ref_pic_lists[list_idx] &&
446
5.27k
        current->num_ref_entries > 0)
447
152k
        flag(ltrp_in_header_flag);
448
152k
    if (sps->sps_long_term_ref_pics_flag &&
449
11.6k
        rpls_idx == sps->sps_num_ref_pic_lists[list_idx])
450
6.35k
        infer(ltrp_in_header_flag, 1);
451
494k
    for (i = 0, j = 0; i < current->num_ref_entries; i++) {
452
342k
        if (sps->sps_inter_layer_prediction_enabled_flag)
453
342k
            flags(inter_layer_ref_pic_flag[i], 1, i);
454
338k
        else
455
338k
            infer(inter_layer_ref_pic_flag[i], 0);
456
457
342k
        if (!current->inter_layer_ref_pic_flag[i]) {
458
342k
            if (sps->sps_long_term_ref_pics_flag)
459
342k
                flags(st_ref_pic_flag[i], 1, i);
460
324k
            else
461
324k
                infer(st_ref_pic_flag[i], 1);
462
341k
            if (current->st_ref_pic_flag[i]) {
463
333k
                int abs_delta_poc_st;
464
333k
                ues(abs_delta_poc_st[i], 0, MAX_UINT_BITS(15), 1, i);
465
333k
                if ((sps->sps_weighted_pred_flag ||
466
301k
                     sps->sps_weighted_bipred_flag) && i != 0)
467
28.4k
                    abs_delta_poc_st = current->abs_delta_poc_st[i];
468
305k
                else
469
305k
                    abs_delta_poc_st = current->abs_delta_poc_st[i] + 1;
470
333k
                if (abs_delta_poc_st > 0)
471
333k
                    flags(strp_entry_sign_flag[i], 1, i);
472
333k
            } else {
473
7.87k
                if (!current->ltrp_in_header_flag) {
474
4.02k
                    uint8_t bits = sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4;
475
4.02k
                    ubs(bits, rpls_poc_lsb_lt[j], 1, j);
476
4.02k
                    j++;
477
4.02k
                }
478
7.87k
            }
479
341k
        } else {
480
274
            if (num_direct_ref_layers == 0) {
481
0
                av_log(ctx->log_ctx, AV_LOG_ERROR,
482
0
                       "num_direct_ref_layers needs > 0.\n");
483
0
                return AVERROR_INVALIDDATA;
484
0
            }
485
274
            ues(ilrp_idx[i], 0, num_direct_ref_layers - 1, 1, i);
486
274
        }
487
342k
    }
488
151k
    return 0;
489
152k
}
490
491
static int FUNC(ref_pic_lists) (CodedBitstreamContext *ctx, RWContext *rw,
492
                                const H266RawSPS *sps, const H266RawPPS *pps,
493
6.28M
                                H266RefPicLists *current) {
494
6.28M
    const H266RefPicListStruct * ref_list;
495
6.28M
    int err, i, j, num_ltrp_entries;
496
18.4M
    for (i = 0; i < 2; i++) {
497
12.4M
        if (sps->sps_num_ref_pic_lists[i] > 0 &&
498
3.55M
            (i == 0 || (i == 1 && pps->pps_rpl1_idx_present_flag))) {
499
3.28M
            flags(rpl_sps_flag[i], 1, i);
500
9.12M
        } else {
501
9.12M
            if (sps->sps_num_ref_pic_lists[i] == 0) {
502
8.85M
                infer(rpl_sps_flag[i], 0);
503
8.85M
            } else {
504
271k
                if (!pps->pps_rpl1_idx_present_flag && i == 1)
505
271k
                    infer(rpl_sps_flag[1], current->rpl_sps_flag[0]);
506
271k
            }
507
9.12M
        }
508
12.4M
        if (current->rpl_sps_flag[i]) {
509
2.56M
            if (sps->sps_num_ref_pic_lists[i] > 1 &&
510
241k
                (i == 0 || (i == 1 && pps->pps_rpl1_idx_present_flag))) {
511
187k
                uint8_t bits = av_ceil_log2(sps->sps_num_ref_pic_lists[i]);
512
187k
                us(bits, rpl_idx[i], 0, sps->sps_num_ref_pic_lists[i] - 1, 1, i);
513
2.37M
            } else if (sps->sps_num_ref_pic_lists[i] == 1) {
514
2.32M
                infer(rpl_idx[i], 0);
515
2.32M
            } else if (i == 1 && !pps->pps_rpl1_idx_present_flag) {
516
53.9k
                infer(rpl_idx[1], current->rpl_idx[0]);
517
53.9k
            } else {
518
                //how to handle this? or never happpend?
519
0
                av_log(ctx->log_ctx, AV_LOG_ERROR,
520
0
                       "can't infer the rpl_idx[i]\n");
521
0
                return AVERROR_PATCHWELCOME;
522
0
            }
523
2.53M
            memcpy(&current->rpl_ref_list[i],
524
2.53M
                   &sps->sps_ref_pic_list_struct[i][current->rpl_idx[i]],
525
2.53M
                   sizeof(current->rpl_ref_list[i]));
526
9.83M
        } else {
527
9.83M
            CHECK(FUNC(ref_pic_list_struct) (ctx, rw, &current->rpl_ref_list[i],
528
9.83M
                                             i, sps->sps_num_ref_pic_lists[i],
529
9.83M
                                             sps));
530
9.83M
        }
531
12.1M
        ref_list = &current->rpl_ref_list[i];
532
533
12.1M
        num_ltrp_entries = 0;
534
17.2M
        for (int k = 0; k < ref_list->num_ref_entries; k++) {
535
5.05M
            if (!ref_list->inter_layer_ref_pic_flag[k]) {
536
5.04M
                if (!ref_list->st_ref_pic_flag[k]) {
537
829k
                    num_ltrp_entries++;
538
829k
                }
539
5.04M
            }
540
5.05M
        }
541
542
12.9M
        for (j = 0; j < num_ltrp_entries; j++) {
543
772k
            if (ref_list->ltrp_in_header_flag) {
544
656k
                ubs(sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4,
545
656k
                    poc_lsb_lt[i][j], 2, i, j);
546
656k
            }
547
763k
            flags(delta_poc_msb_cycle_present_flag[i][j], 2, i, j);
548
749k
            if (current->delta_poc_msb_cycle_present_flag[i][j]) {
549
352k
                uint32_t max =
550
352k
                    1 << (32 - sps->sps_log2_max_pic_order_cnt_lsb_minus4 - 4);
551
352k
                ues(delta_poc_msb_cycle_lt[i][j], 0, max, 2, i, j);
552
352k
            }
553
749k
        }
554
12.1M
    }
555
6.02M
    return 0;
556
6.28M
}
cbs_h266.c:cbs_h266_read_ref_pic_lists
Line
Count
Source
493
6.26M
                                H266RefPicLists *current) {
494
6.26M
    const H266RefPicListStruct * ref_list;
495
6.26M
    int err, i, j, num_ltrp_entries;
496
18.3M
    for (i = 0; i < 2; i++) {
497
12.3M
        if (sps->sps_num_ref_pic_lists[i] > 0 &&
498
3.50M
            (i == 0 || (i == 1 && pps->pps_rpl1_idx_present_flag))) {
499
3.25M
            flags(rpl_sps_flag[i], 1, i);
500
9.10M
        } else {
501
9.10M
            if (sps->sps_num_ref_pic_lists[i] == 0) {
502
8.84M
                infer(rpl_sps_flag[i], 0);
503
8.84M
            } else {
504
254k
                if (!pps->pps_rpl1_idx_present_flag && i == 1)
505
254k
                    infer(rpl_sps_flag[1], current->rpl_sps_flag[0]);
506
254k
            }
507
9.10M
        }
508
12.3M
        if (current->rpl_sps_flag[i]) {
509
2.54M
            if (sps->sps_num_ref_pic_lists[i] > 1 &&
510
228k
                (i == 0 || (i == 1 && pps->pps_rpl1_idx_present_flag))) {
511
178k
                uint8_t bits = av_ceil_log2(sps->sps_num_ref_pic_lists[i]);
512
178k
                us(bits, rpl_idx[i], 0, sps->sps_num_ref_pic_lists[i] - 1, 1, i);
513
2.36M
            } else if (sps->sps_num_ref_pic_lists[i] == 1) {
514
2.31M
                infer(rpl_idx[i], 0);
515
2.31M
            } else if (i == 1 && !pps->pps_rpl1_idx_present_flag) {
516
50.1k
                infer(rpl_idx[1], current->rpl_idx[0]);
517
50.1k
            } else {
518
                //how to handle this? or never happpend?
519
0
                av_log(ctx->log_ctx, AV_LOG_ERROR,
520
0
                       "can't infer the rpl_idx[i]\n");
521
0
                return AVERROR_PATCHWELCOME;
522
0
            }
523
2.52M
            memcpy(&current->rpl_ref_list[i],
524
2.52M
                   &sps->sps_ref_pic_list_struct[i][current->rpl_idx[i]],
525
2.52M
                   sizeof(current->rpl_ref_list[i]));
526
9.80M
        } else {
527
9.80M
            CHECK(FUNC(ref_pic_list_struct) (ctx, rw, &current->rpl_ref_list[i],
528
9.80M
                                             i, sps->sps_num_ref_pic_lists[i],
529
9.80M
                                             sps));
530
9.80M
        }
531
12.1M
        ref_list = &current->rpl_ref_list[i];
532
533
12.1M
        num_ltrp_entries = 0;
534
17.0M
        for (int k = 0; k < ref_list->num_ref_entries; k++) {
535
4.96M
            if (!ref_list->inter_layer_ref_pic_flag[k]) {
536
4.96M
                if (!ref_list->st_ref_pic_flag[k]) {
537
825k
                    num_ltrp_entries++;
538
825k
                }
539
4.96M
            }
540
4.96M
        }
541
542
12.8M
        for (j = 0; j < num_ltrp_entries; j++) {
543
768k
            if (ref_list->ltrp_in_header_flag) {
544
655k
                ubs(sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4,
545
655k
                    poc_lsb_lt[i][j], 2, i, j);
546
655k
            }
547
759k
            flags(delta_poc_msb_cycle_present_flag[i][j], 2, i, j);
548
744k
            if (current->delta_poc_msb_cycle_present_flag[i][j]) {
549
350k
                uint32_t max =
550
350k
                    1 << (32 - sps->sps_log2_max_pic_order_cnt_lsb_minus4 - 4);
551
350k
                ues(delta_poc_msb_cycle_lt[i][j], 0, max, 2, i, j);
552
350k
            }
553
744k
        }
554
12.1M
    }
555
5.99M
    return 0;
556
6.26M
}
cbs_h266.c:cbs_h266_write_ref_pic_lists
Line
Count
Source
493
25.9k
                                H266RefPicLists *current) {
494
25.9k
    const H266RefPicListStruct * ref_list;
495
25.9k
    int err, i, j, num_ltrp_entries;
496
74.3k
    for (i = 0; i < 2; i++) {
497
50.5k
        if (sps->sps_num_ref_pic_lists[i] > 0 &&
498
43.5k
            (i == 0 || (i == 1 && pps->pps_rpl1_idx_present_flag))) {
499
27.1k
            flags(rpl_sps_flag[i], 1, i);
500
27.1k
        } else {
501
23.4k
            if (sps->sps_num_ref_pic_lists[i] == 0) {
502
6.92k
                infer(rpl_sps_flag[i], 0);
503
16.4k
            } else {
504
16.4k
                if (!pps->pps_rpl1_idx_present_flag && i == 1)
505
16.4k
                    infer(rpl_sps_flag[1], current->rpl_sps_flag[0]);
506
16.4k
            }
507
23.4k
        }
508
50.1k
        if (current->rpl_sps_flag[i]) {
509
16.4k
            if (sps->sps_num_ref_pic_lists[i] > 1 &&
510
13.1k
                (i == 0 || (i == 1 && pps->pps_rpl1_idx_present_flag))) {
511
9.25k
                uint8_t bits = av_ceil_log2(sps->sps_num_ref_pic_lists[i]);
512
9.25k
                us(bits, rpl_idx[i], 0, sps->sps_num_ref_pic_lists[i] - 1, 1, i);
513
9.25k
            } else if (sps->sps_num_ref_pic_lists[i] == 1) {
514
3.33k
                infer(rpl_idx[i], 0);
515
3.85k
            } else if (i == 1 && !pps->pps_rpl1_idx_present_flag) {
516
3.85k
                infer(rpl_idx[1], current->rpl_idx[0]);
517
3.85k
            } else {
518
                //how to handle this? or never happpend?
519
0
                av_log(ctx->log_ctx, AV_LOG_ERROR,
520
0
                       "can't infer the rpl_idx[i]\n");
521
0
                return AVERROR_PATCHWELCOME;
522
0
            }
523
15.8k
            memcpy(&current->rpl_ref_list[i],
524
15.8k
                   &sps->sps_ref_pic_list_struct[i][current->rpl_idx[i]],
525
15.8k
                   sizeof(current->rpl_ref_list[i]));
526
33.6k
        } else {
527
33.6k
            CHECK(FUNC(ref_pic_list_struct) (ctx, rw, &current->rpl_ref_list[i],
528
33.6k
                                             i, sps->sps_num_ref_pic_lists[i],
529
33.6k
                                             sps));
530
33.6k
        }
531
48.6k
        ref_list = &current->rpl_ref_list[i];
532
533
48.6k
        num_ltrp_entries = 0;
534
133k
        for (int k = 0; k < ref_list->num_ref_entries; k++) {
535
84.7k
            if (!ref_list->inter_layer_ref_pic_flag[k]) {
536
84.4k
                if (!ref_list->st_ref_pic_flag[k]) {
537
4.45k
                    num_ltrp_entries++;
538
4.45k
                }
539
84.4k
            }
540
84.7k
        }
541
542
52.9k
        for (j = 0; j < num_ltrp_entries; j++) {
543
4.45k
            if (ref_list->ltrp_in_header_flag) {
544
1.79k
                ubs(sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4,
545
1.79k
                    poc_lsb_lt[i][j], 2, i, j);
546
1.79k
            }
547
4.26k
            flags(delta_poc_msb_cycle_present_flag[i][j], 2, i, j);
548
4.26k
            if (current->delta_poc_msb_cycle_present_flag[i][j]) {
549
2.14k
                uint32_t max =
550
2.14k
                    1 << (32 - sps->sps_log2_max_pic_order_cnt_lsb_minus4 - 4);
551
2.14k
                ues(delta_poc_msb_cycle_lt[i][j], 0, max, 2, i, j);
552
2.14k
            }
553
4.26k
        }
554
48.6k
    }
555
23.8k
    return 0;
556
25.9k
}
557
558
static int FUNC(general_timing_hrd_parameters)(CodedBitstreamContext *ctx,
559
                                    RWContext *rw,
560
                                    H266RawGeneralTimingHrdParameters *current)
561
79.2k
{
562
79.2k
    int err;
563
79.2k
    ub(32, num_units_in_tick);
564
78.3k
    u(32, time_scale, 1, MAX_UINT_BITS(32));
565
72.3k
    flag(general_nal_hrd_params_present_flag);
566
71.6k
    flag(general_vcl_hrd_params_present_flag);
567
568
70.8k
    if (current->general_nal_hrd_params_present_flag ||
569
61.6k
        current->general_vcl_hrd_params_present_flag) {
570
61.6k
        flag(general_same_pic_timing_in_all_ols_flag);
571
60.9k
        flag(general_du_hrd_params_present_flag);
572
59.8k
        if (current->general_du_hrd_params_present_flag)
573
35.9k
            ub(8, tick_divisor_minus2);
574
53.2k
        ub(4, bit_rate_scale);
575
52.6k
        ub(4, cpb_size_scale);
576
51.4k
        if (current->general_du_hrd_params_present_flag)
577
29.1k
            ub(4, cpb_size_du_scale);
578
50.9k
        ue(hrd_cpb_cnt_minus1, 0, 31);
579
50.9k
    } else {
580
        //infer general_same_pic_timing_in_all_ols_flag?
581
9.24k
        infer(general_du_hrd_params_present_flag, 0);
582
9.24k
    }
583
58.3k
    return 0;
584
70.8k
}
cbs_h266.c:cbs_h266_read_general_timing_hrd_parameters
Line
Count
Source
561
73.2k
{
562
73.2k
    int err;
563
73.2k
    ub(32, num_units_in_tick);
564
72.3k
    u(32, time_scale, 1, MAX_UINT_BITS(32));
565
66.3k
    flag(general_nal_hrd_params_present_flag);
566
65.6k
    flag(general_vcl_hrd_params_present_flag);
567
568
64.8k
    if (current->general_nal_hrd_params_present_flag ||
569
56.8k
        current->general_vcl_hrd_params_present_flag) {
570
56.8k
        flag(general_same_pic_timing_in_all_ols_flag);
571
56.2k
        flag(general_du_hrd_params_present_flag);
572
55.1k
        if (current->general_du_hrd_params_present_flag)
573
33.4k
            ub(8, tick_divisor_minus2);
574
48.5k
        ub(4, bit_rate_scale);
575
47.9k
        ub(4, cpb_size_scale);
576
46.7k
        if (current->general_du_hrd_params_present_flag)
577
26.5k
            ub(4, cpb_size_du_scale);
578
46.1k
        ue(hrd_cpb_cnt_minus1, 0, 31);
579
46.1k
    } else {
580
        //infer general_same_pic_timing_in_all_ols_flag?
581
7.92k
        infer(general_du_hrd_params_present_flag, 0);
582
7.92k
    }
583
52.3k
    return 0;
584
64.8k
}
cbs_h266.c:cbs_h266_write_general_timing_hrd_parameters
Line
Count
Source
561
6.02k
{
562
6.02k
    int err;
563
6.02k
    ub(32, num_units_in_tick);
564
6.02k
    u(32, time_scale, 1, MAX_UINT_BITS(32));
565
6.02k
    flag(general_nal_hrd_params_present_flag);
566
6.02k
    flag(general_vcl_hrd_params_present_flag);
567
568
6.02k
    if (current->general_nal_hrd_params_present_flag ||
569
4.70k
        current->general_vcl_hrd_params_present_flag) {
570
4.70k
        flag(general_same_pic_timing_in_all_ols_flag);
571
4.70k
        flag(general_du_hrd_params_present_flag);
572
4.70k
        if (current->general_du_hrd_params_present_flag)
573
2.54k
            ub(8, tick_divisor_minus2);
574
4.70k
        ub(4, bit_rate_scale);
575
4.70k
        ub(4, cpb_size_scale);
576
4.70k
        if (current->general_du_hrd_params_present_flag)
577
2.54k
            ub(4, cpb_size_du_scale);
578
4.70k
        ue(hrd_cpb_cnt_minus1, 0, 31);
579
4.70k
    } else {
580
        //infer general_same_pic_timing_in_all_ols_flag?
581
1.32k
        infer(general_du_hrd_params_present_flag, 0);
582
1.32k
    }
583
6.02k
    return 0;
584
6.02k
}
585
586
static int FUNC(sublayer_hrd_parameters) (CodedBitstreamContext *ctx,
587
                              RWContext *rw,
588
                              H266RawSubLayerHRDParameters *current,
589
                              int sublayer_id,
590
                              const H266RawGeneralTimingHrdParameters *general)
591
213k
{
592
213k
    int err, i;
593
572k
    for (i = 0; i <= general->hrd_cpb_cnt_minus1; i++) {
594
366k
        ues(bit_rate_value_minus1[sublayer_id][i], 0, UINT32_MAX - 1, 2,
595
365k
            sublayer_id, i);
596
365k
        ues(cpb_size_value_minus1[sublayer_id][i], 0, UINT32_MAX - 1, 2,
597
362k
            sublayer_id, i);
598
362k
        if (general->general_du_hrd_params_present_flag) {
599
169k
            ues(cpb_size_du_value_minus1[sublayer_id][i],
600
168k
                0, UINT32_MAX - 1, 2, sublayer_id, i);
601
168k
            ues(bit_rate_du_value_minus1[sublayer_id][i],
602
168k
                0, UINT32_MAX - 1, 2, sublayer_id, i);
603
168k
        }
604
360k
        flags(cbr_flag[sublayer_id][i], 2, sublayer_id, i);
605
360k
    }
606
206k
    return 0;
607
213k
}
cbs_h266.c:cbs_h266_read_sublayer_hrd_parameters
Line
Count
Source
591
194k
{
592
194k
    int err, i;
593
528k
    for (i = 0; i <= general->hrd_cpb_cnt_minus1; i++) {
594
341k
        ues(bit_rate_value_minus1[sublayer_id][i], 0, UINT32_MAX - 1, 2,
595
339k
            sublayer_id, i);
596
339k
        ues(cpb_size_value_minus1[sublayer_id][i], 0, UINT32_MAX - 1, 2,
597
337k
            sublayer_id, i);
598
337k
        if (general->general_du_hrd_params_present_flag) {
599
162k
            ues(cpb_size_du_value_minus1[sublayer_id][i],
600
160k
                0, UINT32_MAX - 1, 2, sublayer_id, i);
601
160k
            ues(bit_rate_du_value_minus1[sublayer_id][i],
602
160k
                0, UINT32_MAX - 1, 2, sublayer_id, i);
603
160k
        }
604
334k
        flags(cbr_flag[sublayer_id][i], 2, sublayer_id, i);
605
334k
    }
606
186k
    return 0;
607
194k
}
cbs_h266.c:cbs_h266_write_sublayer_hrd_parameters
Line
Count
Source
591
19.0k
{
592
19.0k
    int err, i;
593
44.5k
    for (i = 0; i <= general->hrd_cpb_cnt_minus1; i++) {
594
25.5k
        ues(bit_rate_value_minus1[sublayer_id][i], 0, UINT32_MAX - 1, 2,
595
25.5k
            sublayer_id, i);
596
25.5k
        ues(cpb_size_value_minus1[sublayer_id][i], 0, UINT32_MAX - 1, 2,
597
25.5k
            sublayer_id, i);
598
25.5k
        if (general->general_du_hrd_params_present_flag) {
599
7.33k
            ues(cpb_size_du_value_minus1[sublayer_id][i],
600
7.33k
                0, UINT32_MAX - 1, 2, sublayer_id, i);
601
7.33k
            ues(bit_rate_du_value_minus1[sublayer_id][i],
602
7.33k
                0, UINT32_MAX - 1, 2, sublayer_id, i);
603
7.33k
        }
604
25.5k
        flags(cbr_flag[sublayer_id][i], 2, sublayer_id, i);
605
25.5k
    }
606
19.0k
    return 0;
607
19.0k
}
608
609
static int FUNC(ols_timing_hrd_parameters) (CodedBitstreamContext *ctx,
610
                RWContext *rw, H266RawOlsTimingHrdParameters *current,
611
                uint8_t first_sublayer, uint8_t max_sublayers_minus1,
612
                const H266RawGeneralTimingHrdParameters *general)
613
102k
{
614
102k
    int err, i;
615
253k
    for (i = first_sublayer; i <= max_sublayers_minus1; i++) {
616
161k
        flags(fixed_pic_rate_general_flag[i], 1, i);
617
160k
        if (!current->fixed_pic_rate_general_flag[i])
618
160k
            flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
619
86.8k
        else
620
86.8k
            infer(fixed_pic_rate_within_cvs_flag[i], 1);
621
160k
        if (current->fixed_pic_rate_within_cvs_flag[i]) {
622
118k
            ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
623
117k
            infer(low_delay_hrd_flag[i], 0);
624
117k
        } else if ((general->general_nal_hrd_params_present_flag ||
625
21.6k
                    general->general_vcl_hrd_params_present_flag) &&
626
29.4k
                   general->hrd_cpb_cnt_minus1 == 0) {
627
23.8k
            flags(low_delay_hrd_flag[i], 1, i);
628
23.8k
        } else {
629
17.7k
            infer(low_delay_hrd_flag[i], 0);
630
17.7k
        }
631
158k
        if (general->general_nal_hrd_params_present_flag)
632
103k
            CHECK(FUNC(sublayer_hrd_parameters) (ctx, rw,
633
158k
                                        &current->nal_sub_layer_hrd_parameters,
634
158k
                                        i, general));
635
155k
        if (general->general_vcl_hrd_params_present_flag)
636
110k
            CHECK(FUNC(sublayer_hrd_parameters) (ctx, rw,
637
155k
                                        &current->nal_sub_layer_hrd_parameters,
638
155k
                                        i, general));
639
155k
    }
640
92.3k
    return 0;
641
102k
}
cbs_h266.c:cbs_h266_read_ols_timing_hrd_parameters
Line
Count
Source
613
89.3k
{
614
89.3k
    int err, i;
615
221k
    for (i = first_sublayer; i <= max_sublayers_minus1; i++) {
616
141k
        flags(fixed_pic_rate_general_flag[i], 1, i);
617
141k
        if (!current->fixed_pic_rate_general_flag[i])
618
141k
            flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
619
75.9k
        else
620
75.9k
            infer(fixed_pic_rate_within_cvs_flag[i], 1);
621
140k
        if (current->fixed_pic_rate_within_cvs_flag[i]) {
622
105k
            ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
623
104k
            infer(low_delay_hrd_flag[i], 0);
624
104k
        } else if ((general->general_nal_hrd_params_present_flag ||
625
17.1k
                    general->general_vcl_hrd_params_present_flag) &&
626
26.6k
                   general->hrd_cpb_cnt_minus1 == 0) {
627
21.6k
            flags(low_delay_hrd_flag[i], 1, i);
628
21.6k
        } else {
629
14.1k
            infer(low_delay_hrd_flag[i], 0);
630
14.1k
        }
631
139k
        if (general->general_nal_hrd_params_present_flag)
632
93.2k
            CHECK(FUNC(sublayer_hrd_parameters) (ctx, rw,
633
139k
                                        &current->nal_sub_layer_hrd_parameters,
634
139k
                                        i, general));
635
135k
        if (general->general_vcl_hrd_params_present_flag)
636
101k
            CHECK(FUNC(sublayer_hrd_parameters) (ctx, rw,
637
135k
                                        &current->nal_sub_layer_hrd_parameters,
638
135k
                                        i, general));
639
135k
    }
640
79.2k
    return 0;
641
89.3k
}
cbs_h266.c:cbs_h266_write_ols_timing_hrd_parameters
Line
Count
Source
613
13.0k
{
614
13.0k
    int err, i;
615
32.3k
    for (i = first_sublayer; i <= max_sublayers_minus1; i++) {
616
19.2k
        flags(fixed_pic_rate_general_flag[i], 1, i);
617
19.2k
        if (!current->fixed_pic_rate_general_flag[i])
618
19.2k
            flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
619
10.8k
        else
620
10.8k
            infer(fixed_pic_rate_within_cvs_flag[i], 1);
621
19.2k
        if (current->fixed_pic_rate_within_cvs_flag[i]) {
622
13.4k
            ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
623
13.4k
            infer(low_delay_hrd_flag[i], 0);
624
13.4k
        } else if ((general->general_nal_hrd_params_present_flag ||
625
4.51k
                    general->general_vcl_hrd_params_present_flag) &&
626
2.81k
                   general->hrd_cpb_cnt_minus1 == 0) {
627
2.25k
            flags(low_delay_hrd_flag[i], 1, i);
628
3.60k
        } else {
629
3.60k
            infer(low_delay_hrd_flag[i], 0);
630
3.60k
        }
631
19.2k
        if (general->general_nal_hrd_params_present_flag)
632
9.77k
            CHECK(FUNC(sublayer_hrd_parameters) (ctx, rw,
633
19.2k
                                        &current->nal_sub_layer_hrd_parameters,
634
19.2k
                                        i, general));
635
19.2k
        if (general->general_vcl_hrd_params_present_flag)
636
9.23k
            CHECK(FUNC(sublayer_hrd_parameters) (ctx, rw,
637
19.2k
                                        &current->nal_sub_layer_hrd_parameters,
638
19.2k
                                        i, general));
639
19.2k
    }
640
13.0k
    return 0;
641
13.0k
}
642
643
static int FUNC(opi)(CodedBitstreamContext *ctx, RWContext *rw,
644
                     H266RawOPI *current)
645
98.9k
{
646
98.9k
    int err;
647
648
98.9k
    HEADER("Operating point information");
649
650
98.9k
    CHECK(FUNC(nal_unit_header)(ctx, rw,
651
98.9k
                                &current->nal_unit_header, VVC_OPI_NUT));
652
653
98.2k
    flag(opi_ols_info_present_flag);
654
96.5k
    flag(opi_htid_info_present_flag);
655
656
96.5k
    if(current->opi_ols_info_present_flag)
657
96.5k
        ue(opi_ols_idx, 0, VVC_MAX_TOTAL_NUM_OLSS - 1);
658
659
95.6k
    if(current->opi_htid_info_present_flag)
660
37.0k
        ub(3, opi_htid_plus1);
661
662
95.1k
    flag(opi_extension_flag);
663
94.6k
    if (current->opi_extension_flag)
664
63.5k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
665
94.6k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
666
667
62.0k
    return 0;
668
94.6k
}
cbs_h266.c:cbs_h266_read_opi
Line
Count
Source
645
92.7k
{
646
92.7k
    int err;
647
648
92.7k
    HEADER("Operating point information");
649
650
92.7k
    CHECK(FUNC(nal_unit_header)(ctx, rw,
651
92.7k
                                &current->nal_unit_header, VVC_OPI_NUT));
652
653
92.1k
    flag(opi_ols_info_present_flag);
654
90.3k
    flag(opi_htid_info_present_flag);
655
656
90.3k
    if(current->opi_ols_info_present_flag)
657
90.3k
        ue(opi_ols_idx, 0, VVC_MAX_TOTAL_NUM_OLSS - 1);
658
659
89.4k
    if(current->opi_htid_info_present_flag)
660
33.9k
        ub(3, opi_htid_plus1);
661
662
88.9k
    flag(opi_extension_flag);
663
88.5k
    if (current->opi_extension_flag)
664
57.6k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
665
88.5k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
666
667
55.8k
    return 0;
668
88.5k
}
cbs_h266.c:cbs_h266_write_opi
Line
Count
Source
645
6.18k
{
646
6.18k
    int err;
647
648
6.18k
    HEADER("Operating point information");
649
650
6.18k
    CHECK(FUNC(nal_unit_header)(ctx, rw,
651
6.18k
                                &current->nal_unit_header, VVC_OPI_NUT));
652
653
6.18k
    flag(opi_ols_info_present_flag);
654
6.18k
    flag(opi_htid_info_present_flag);
655
656
6.18k
    if(current->opi_ols_info_present_flag)
657
6.18k
        ue(opi_ols_idx, 0, VVC_MAX_TOTAL_NUM_OLSS - 1);
658
659
6.18k
    if(current->opi_htid_info_present_flag)
660
3.12k
        ub(3, opi_htid_plus1);
661
662
6.18k
    flag(opi_extension_flag);
663
6.18k
    if (current->opi_extension_flag)
664
5.89k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
665
6.18k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
666
667
6.18k
    return 0;
668
6.18k
}
669
670
static int FUNC(dci)(CodedBitstreamContext *ctx, RWContext *rw,
671
                     H266RawDCI *current)
672
22.2k
{
673
22.2k
    int err, i;
674
675
22.2k
    HEADER("Decoding capability information");
676
677
22.2k
    CHECK(FUNC(nal_unit_header)(ctx, rw,
678
22.2k
                                &current->nal_unit_header, VVC_DCI_NUT));
679
680
21.3k
    ub(4, dci_reserved_zero_4bits);
681
18.7k
    ub(4, dci_num_ptls_minus1);
682
48.0k
    for (i = 0; i <= current->dci_num_ptls_minus1; i++)
683
41.1k
        CHECK(FUNC(profile_tier_level)(ctx, rw,
684
18.7k
                                       current->dci_profile_tier_level + i, 1, 0));
685
686
6.87k
    flag(dci_extension_flag);
687
6.33k
    if (current->dci_extension_flag)
688
2.34k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
689
6.33k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
690
691
3.11k
    return 0;
692
6.33k
}
cbs_h266.c:cbs_h266_read_dci
Line
Count
Source
672
21.1k
{
673
21.1k
    int err, i;
674
675
21.1k
    HEADER("Decoding capability information");
676
677
21.1k
    CHECK(FUNC(nal_unit_header)(ctx, rw,
678
21.1k
                                &current->nal_unit_header, VVC_DCI_NUT));
679
680
20.2k
    ub(4, dci_reserved_zero_4bits);
681
17.7k
    ub(4, dci_num_ptls_minus1);
682
43.9k
    for (i = 0; i <= current->dci_num_ptls_minus1; i++)
683
38.0k
        CHECK(FUNC(profile_tier_level)(ctx, rw,
684
17.7k
                                       current->dci_profile_tier_level + i, 1, 0));
685
686
5.85k
    flag(dci_extension_flag);
687
5.31k
    if (current->dci_extension_flag)
688
1.68k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
689
5.31k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
690
691
2.08k
    return 0;
692
5.31k
}
cbs_h266.c:cbs_h266_write_dci
Line
Count
Source
672
1.02k
{
673
1.02k
    int err, i;
674
675
1.02k
    HEADER("Decoding capability information");
676
677
1.02k
    CHECK(FUNC(nal_unit_header)(ctx, rw,
678
1.02k
                                &current->nal_unit_header, VVC_DCI_NUT));
679
680
1.02k
    ub(4, dci_reserved_zero_4bits);
681
1.02k
    ub(4, dci_num_ptls_minus1);
682
4.14k
    for (i = 0; i <= current->dci_num_ptls_minus1; i++)
683
3.11k
        CHECK(FUNC(profile_tier_level)(ctx, rw,
684
1.02k
                                       current->dci_profile_tier_level + i, 1, 0));
685
686
1.02k
    flag(dci_extension_flag);
687
1.02k
    if (current->dci_extension_flag)
688
666
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
689
1.02k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
690
691
1.02k
    return 0;
692
1.02k
}
693
694
static int FUNC(vps) (CodedBitstreamContext *ctx, RWContext *rw,
695
                     H266RawVPS *current)
696
180k
{
697
180k
    int err, i, j, k;
698
180k
    uint16_t total_num_olss = 0;
699
180k
    uint8_t ols_mode_idc = 0;
700
180k
    uint16_t num_multi_layer_olss = 0;
701
180k
    uint8_t layer_included_in_ols_flag[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_LAYERS];
702
180k
    uint8_t num_ref_layers[VVC_MAX_LAYERS];
703
180k
    uint8_t reference_layer_idx[VVC_MAX_LAYERS][VVC_MAX_LAYERS];
704
705
180k
    HEADER("Video Parameter Set");
706
707
180k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
708
180k
                                 &current->nal_unit_header, VVC_VPS_NUT));
709
710
177k
    u(4, vps_video_parameter_set_id, 1, VVC_MAX_VPS_COUNT - 1);
711
173k
    ub(6, vps_max_layers_minus1);
712
172k
    u(3, vps_max_sublayers_minus1, 0, 6);
713
169k
    if (current->vps_max_layers_minus1 > 0
714
166k
        && current->vps_max_sublayers_minus1 > 0)
715
169k
        flag(vps_default_ptl_dpb_hrd_max_tid_flag);
716
94.2k
    else
717
94.2k
        infer(vps_default_ptl_dpb_hrd_max_tid_flag, 1);
718
719
169k
    if (current->vps_max_layers_minus1 > 0)
720
169k
        flag(vps_all_independent_layers_flag);
721
3.25k
    else
722
3.25k
        infer(vps_all_independent_layers_flag, 1);
723
724
757k
    for (i = 0; i <= current->vps_max_layers_minus1; i++) {
725
613k
        ubs(6, vps_layer_id[i], 1, i);
726
610k
        if (i > 0 && current->vps_layer_id[i] <= current->vps_layer_id[i - 1]) {
727
17.4k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
728
17.4k
                   "vps_layer_id[%d](%d) should > vps_layer_id[%d](%d).\n",
729
17.4k
                   i, current->vps_layer_id[i], i - 1,
730
17.4k
                   current->vps_layer_id[i - 1]);
731
17.4k
            return AVERROR_INVALIDDATA;
732
17.4k
        }
733
592k
        if (i > 0 && !current->vps_all_independent_layers_flag) {
734
366k
            flags(vps_independent_layer_flag[i], 1, i);
735
364k
            if (!current->vps_independent_layer_flag[i]) {
736
240k
                flags(vps_max_tid_ref_present_flag[i], 1, i);
737
847k
                for (j = 0; j < i; j++) {
738
609k
                    flags(vps_direct_ref_layer_flag[i][j], 2, i, j);
739
608k
                    if (current->vps_max_tid_ref_present_flag[i] &&
740
317k
                        current->vps_direct_ref_layer_flag[i][j]) {
741
208k
                        ubs(3, vps_max_tid_il_ref_pics_plus1[i][j], 2, i, j);
742
400k
                    } else {
743
400k
                        infer(vps_max_tid_il_ref_pics_plus1[i][j],
744
400k
                              current->vps_max_sublayers_minus1 + 1);
745
400k
                    }
746
608k
                }
747
239k
            } else {
748
316k
                for (j = 0; j < i; j++) {
749
192k
                    infer(vps_direct_ref_layer_flag[i][j], 0);
750
192k
                }
751
124k
            }
752
364k
        } else {
753
226k
            infer(vps_independent_layer_flag[i], 1);
754
315k
            for (j = 0; j < i; j++) {
755
89.2k
                infer(vps_direct_ref_layer_flag[i][j], 0);
756
89.2k
            }
757
6.40k
        }
758
592k
    }
759
760
144k
    if (current->vps_max_layers_minus1 > 0) {
761
141k
        if (current->vps_all_independent_layers_flag)
762
141k
            flag(vps_each_layer_is_an_ols_flag);
763
114k
        else
764
114k
            infer(vps_each_layer_is_an_ols_flag, 0);
765
140k
        if (!current->vps_each_layer_is_an_ols_flag) {
766
137k
            if (!current->vps_all_independent_layers_flag)
767
114k
                ub(2, vps_ols_mode_idc);
768
23.1k
            else
769
23.1k
                infer(vps_ols_mode_idc, 2);
770
136k
            if (current->vps_ols_mode_idc == 2) {
771
36.7k
                ub(8, vps_num_output_layer_sets_minus2);
772
688k
                for (i = 1; i <= current->vps_num_output_layer_sets_minus2 + 1;
773
652k
                     i++)
774
3.14M
                    for (j = 0; j <= current->vps_max_layers_minus1; j++)
775
2.49M
                        flags(vps_ols_output_layer_flag[i][j], 2, i, j);
776
35.5k
            }
777
130k
            ols_mode_idc = current->vps_ols_mode_idc;
778
130k
        } else {
779
3.77k
            ols_mode_idc = 4;
780
3.77k
        }
781
134k
        if (ols_mode_idc == 4 || ols_mode_idc == 0 || ols_mode_idc == 1)
782
98.9k
            total_num_olss = current->vps_max_layers_minus1 + 1;
783
35.6k
        else if (ols_mode_idc == 2)
784
31.3k
            total_num_olss = current->vps_num_output_layer_sets_minus2 + 2;
785
4.26k
        else
786
4.26k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
787
4.26k
                   "ols_mode_idc == 3, patch welcome");
788
134k
        u(8, vps_num_ptls_minus1, 0, total_num_olss - 1);
789
134k
    } else {
790
3.25k
        infer(vps_each_layer_is_an_ols_flag, 1);
791
3.25k
        infer(vps_num_ptls_minus1, 0);
792
199
    }
793
794
745k
    for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
795
617k
        if (i > 0)
796
617k
            flags(vps_pt_present_flag[i], 1, i);
797
129k
        else
798
129k
            infer(vps_pt_present_flag[i], 1);
799
800
616k
        if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
801
616k
            us(3, vps_ptl_max_tid[i], 0, current->vps_max_sublayers_minus1, 1, i);
802
580k
        else
803
580k
            infer(vps_ptl_max_tid[i], current->vps_max_sublayers_minus1);
804
616k
    }
805
479k
    while (byte_alignment(rw) != 0)
806
358k
        fixed(1, vps_ptl_alignment_zero_bit, 0);
807
808
121k
    {
809
        //calc NumMultiLayerOlss
810
121k
        int m;
811
121k
        uint8_t dependency_flag[VVC_MAX_LAYERS][VVC_MAX_LAYERS];
812
121k
        uint16_t num_output_layers_in_ols[VVC_MAX_TOTAL_NUM_OLSS];
813
121k
        uint8_t num_sub_layers_in_layer_in_ols[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_TOTAL_NUM_OLSS];
814
121k
        uint8_t output_layer_idx[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_LAYERS];
815
816
        //7.4.3.3 vps_direct_ref_layer_flag section
817
578k
        for (i = 0; i <= current->vps_max_layers_minus1; i++) {
818
2.36M
            for (j = 0; j <= current->vps_max_layers_minus1; j++) {
819
1.90M
                dependency_flag[i][j] = current->vps_direct_ref_layer_flag[i][j];
820
5.18M
                for (k = 0; k < i; k++) {
821
3.27M
                    if (current->vps_direct_ref_layer_flag[i][k] &&
822
1.27M
                        dependency_flag[k][j])
823
71.3k
                        dependency_flag[i][j] = 1;
824
3.27M
                }
825
1.90M
            }
826
457k
        }
827
578k
        for (i = 0; i <= current->vps_max_layers_minus1; i++) {
828
457k
            int r;
829
2.36M
            for (j = 0, r = 0; j <= current->vps_max_layers_minus1; j++) {
830
1.90M
                if (dependency_flag[i][j])
831
281k
                    reference_layer_idx[i][r++] = j;
832
1.90M
            }
833
457k
            num_ref_layers[i] = r;
834
457k
        }
835
836
        //7.4.3.3 vps_ols_output_layer_flag section
837
121k
        num_output_layers_in_ols[0] = 1;
838
121k
        num_sub_layers_in_layer_in_ols[0][0] =
839
121k
            current->vps_ptl_max_tid[current->vps_ols_ptl_idx[0]] + 1;
840
572k
        for (i = 1; i < total_num_olss; i++) {
841
453k
            if (ols_mode_idc == 4 || ols_mode_idc == 0) {
842
149k
                num_output_layers_in_ols[i] = 1;
843
149k
                if (current->vps_each_layer_is_an_ols_flag) {
844
2.12k
                    num_sub_layers_in_layer_in_ols[i][0] =
845
2.12k
                        current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
846
147k
                } else {
847
147k
                    num_sub_layers_in_layer_in_ols[i][i] =
848
147k
                        current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
849
461k
                    for (k = i - 1; k >= 0; k--) {
850
314k
                        num_sub_layers_in_layer_in_ols[i][k] = 0;
851
889k
                        for (m = k + 1; m <= i; m++) {
852
574k
                            uint8_t max_sublayer_needed =
853
574k
                                FFMIN(num_sub_layers_in_layer_in_ols[i][m],
854
574k
                                      current->vps_max_tid_il_ref_pics_plus1[m][k]);
855
574k
                            if (current->vps_direct_ref_layer_flag[m][k] &&
856
179k
                                num_sub_layers_in_layer_in_ols[i][k] < max_sublayer_needed)
857
52.6k
                                num_sub_layers_in_layer_in_ols[i][k] = max_sublayer_needed;
858
574k
                        }
859
314k
                    }
860
147k
                }
861
303k
            } else if (current->vps_ols_mode_idc == 1) {
862
121k
                num_output_layers_in_ols[i] = i + 1;
863
539k
                for (j = 0; j < num_output_layers_in_ols[i]; j++) {
864
417k
                    num_sub_layers_in_layer_in_ols[i][j] =
865
417k
                        current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
866
417k
                }
867
182k
            } else if (current->vps_ols_mode_idc == 2) {
868
182k
                uint8_t highest_included_layer = 0;
869
821k
                for (j = 0; j <= current->vps_max_layers_minus1; j++) {
870
639k
                    layer_included_in_ols_flag[i][j] = 0;
871
639k
                    num_sub_layers_in_layer_in_ols[i][j] = 0;
872
639k
                }
873
821k
                for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++) {
874
639k
                    if (current->vps_ols_output_layer_flag[i][k]) {
875
412k
                        layer_included_in_ols_flag[i][k] = 1;
876
412k
                        highest_included_layer = k;
877
412k
                        output_layer_idx[i][j] = k;
878
412k
                        num_sub_layers_in_layer_in_ols[i][k] =
879
412k
                            current->vps_ptl_max_tid[current->
880
412k
                                                     vps_ols_ptl_idx[i]] + 1;
881
412k
                        j++;
882
412k
                    }
883
639k
                }
884
182k
                num_output_layers_in_ols[i] = j;
885
594k
                for (j = 0; j < num_output_layers_in_ols[i]; j++) {
886
412k
                    int idx = output_layer_idx[i][j];
887
540k
                    for (k = 0; k < num_ref_layers[idx]; k++) {
888
127k
                        if (!layer_included_in_ols_flag[i][reference_layer_idx[idx][k]])
889
33.9k
                            layer_included_in_ols_flag[i][reference_layer_idx[idx][k]] = 1;
890
127k
                    }
891
412k
                }
892
510k
                for (k = highest_included_layer - 1; k >= 0; k--) {
893
328k
                    if (layer_included_in_ols_flag[i][k] &&
894
267k
                        !current->vps_ols_output_layer_flag[i][k]) {
895
108k
                        for (m = k + 1; m <= highest_included_layer; m++) {
896
74.4k
                            uint8_t max_sublayer_needed =
897
74.4k
                                FFMIN(num_sub_layers_in_layer_in_ols[i][m],
898
74.4k
                                      current->vps_max_tid_il_ref_pics_plus1[m][k]);
899
74.4k
                            if (current->vps_direct_ref_layer_flag[m][k] &&
900
49.6k
                                layer_included_in_ols_flag[i][m] &&
901
41.3k
                                num_sub_layers_in_layer_in_ols[i][k] <
902
41.3k
                                max_sublayer_needed)
903
32.1k
                                num_sub_layers_in_layer_in_ols[i][k] =
904
32.1k
                                    max_sublayer_needed;
905
74.4k
                        }
906
33.9k
                    }
907
328k
                }
908
182k
            }
909
453k
            if (!num_output_layers_in_ols[i])
910
2.88k
                return AVERROR_INVALIDDATA;
911
453k
        }
912
554k
        for (i = 1; i < total_num_olss; i++) {
913
436k
            int num_layers_in_ols = 0;
914
436k
            if (current->vps_each_layer_is_an_ols_flag) {
915
2.12k
                num_layers_in_ols = 1;
916
434k
            } else if (current->vps_ols_mode_idc == 0 ||
917
286k
                       current->vps_ols_mode_idc == 1) {
918
269k
                num_layers_in_ols = i + 1;
919
269k
            } else if (current->vps_ols_mode_idc == 2) {
920
729k
                for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++)
921
564k
                    if (layer_included_in_ols_flag[i][k])
922
399k
                        j++;
923
164k
                num_layers_in_ols = j;
924
164k
            }
925
436k
            if (num_layers_in_ols > 1) {
926
408k
                num_multi_layer_olss++;
927
408k
            }
928
436k
        }
929
118k
        if (!current->vps_each_layer_is_an_ols_flag && num_multi_layer_olss == 0)
930
1.94k
            return AVERROR_INVALIDDATA;
931
118k
    }
932
933
230k
    for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
934
148k
        CHECK(FUNC(profile_tier_level) (ctx, rw,
935
148k
                                        current->vps_profile_tier_level + i,
936
148k
                                        current->vps_pt_present_flag[i],
937
148k
                                        current->vps_ptl_max_tid[i]));
938
148k
    }
939
481k
    for (i = 0; i < total_num_olss; i++) {
940
401k
        if (current->vps_num_ptls_minus1 > 0 &&
941
50.8k
            current->vps_num_ptls_minus1 + 1 != total_num_olss) {
942
24.4k
            us(8, vps_ols_ptl_idx[i], 0, current->vps_num_ptls_minus1, 1, i);
943
377k
        } else if (current->vps_num_ptls_minus1 == 0) {
944
350k
            infer(vps_ols_ptl_idx[i], 0);
945
350k
        } else {
946
26.4k
            infer(vps_ols_ptl_idx[i], i);
947
26.4k
        }
948
401k
    }
949
950
79.9k
    if (!current->vps_each_layer_is_an_ols_flag) {
951
77.5k
        uint16_t vps_num_dpb_params;
952
77.5k
        ue(vps_num_dpb_params_minus1, 0, num_multi_layer_olss - 1);
953
73.5k
        if (current->vps_each_layer_is_an_ols_flag)
954
0
            vps_num_dpb_params = 0;
955
73.5k
        else
956
73.5k
            vps_num_dpb_params = current->vps_num_dpb_params_minus1 + 1;
957
958
73.5k
        if (current->vps_max_sublayers_minus1 > 0)
959
73.5k
            flag(vps_sublayer_dpb_params_present_flag);
960
51.6k
        else
961
51.6k
            infer(vps_sublayer_dpb_params_present_flag, 0);
962
963
156k
        for (i = 0; i < vps_num_dpb_params; i++) {
964
86.5k
            if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
965
86.5k
                us(3, vps_dpb_max_tid[i], 0, current->vps_max_sublayers_minus1,
966
79.4k
                   1, i);
967
79.4k
            else
968
79.4k
                infer(vps_dpb_max_tid[i], current->vps_max_sublayers_minus1);
969
85.8k
            CHECK(FUNC(dpb_parameters) (ctx, rw, current->vps_dpb_params + i,
970
85.8k
                                        current->vps_dpb_max_tid[i],
971
85.8k
                                        current->
972
85.8k
                                        vps_sublayer_dpb_params_present_flag));
973
85.8k
        }
974
315k
        for (i = 0; i < num_multi_layer_olss; i++) {
975
254k
            ues(vps_ols_dpb_pic_width[i], 0, UINT16_MAX, 1, i);
976
252k
            ues(vps_ols_dpb_pic_height[i], 0, UINT16_MAX, 1, i);
977
251k
            ubs(2, vps_ols_dpb_chroma_format[i], 1, i);
978
248k
            ues(vps_ols_dpb_bitdepth_minus8[i], 0, 8, 1, i);
979
247k
            if (vps_num_dpb_params > 1
980
36.9k
                && vps_num_dpb_params != num_multi_layer_olss)
981
247k
                ues(vps_ols_dpb_params_idx[i], 0, vps_num_dpb_params - 1, 1, i);
982
216k
            else if (vps_num_dpb_params == 1)
983
210k
                infer(vps_ols_dpb_params_idx[i], 0);
984
6.01k
            else
985
6.01k
                infer(vps_ols_dpb_params_idx[i], i);
986
247k
        }
987
61.3k
        flag(vps_timing_hrd_params_present_flag);
988
60.8k
        if (current->vps_timing_hrd_params_present_flag) {
989
51.4k
            CHECK(FUNC(general_timing_hrd_parameters) (ctx, rw,
990
51.4k
                                                       &current->
991
51.4k
                                                       vps_general_timing_hrd_parameters));
992
37.7k
            if (current->vps_max_sublayers_minus1 > 0)
993
37.7k
                flag(vps_sublayer_cpb_params_present_flag);
994
27.2k
            else
995
27.2k
                infer(vps_sublayer_cpb_params_present_flag, 0);
996
37.1k
            ue(vps_num_ols_timing_hrd_params_minus1, 0,
997
34.4k
               num_multi_layer_olss - 1);
998
109k
            for (i = 0; i <= current->vps_num_ols_timing_hrd_params_minus1; i++) {
999
83.0k
                uint8_t first_sublayer;
1000
83.0k
                if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
1001
83.0k
                    us(3, vps_hrd_max_tid[i], 0,
1002
78.5k
                       current->vps_max_sublayers_minus1, 1, i);
1003
78.5k
                else
1004
78.5k
                    infer(vps_hrd_max_tid[i],
1005
83.0k
                          current->vps_max_sublayers_minus1);
1006
82.2k
                first_sublayer = current->vps_sublayer_cpb_params_present_flag ?
1007
71.6k
                                 0 : current->vps_hrd_max_tid[i];
1008
82.2k
                CHECK(FUNC(ols_timing_hrd_parameters)
1009
82.2k
                      (ctx, rw, &current->vps_ols_timing_hrd_parameters,
1010
82.2k
                       first_sublayer, current->vps_max_sublayers_minus1,
1011
82.2k
                       &current->vps_general_timing_hrd_parameters));
1012
1013
82.2k
            }
1014
26.5k
            if (current->vps_num_ols_timing_hrd_params_minus1 > 0 &&
1015
16.3k
                current->vps_num_ols_timing_hrd_params_minus1 + 1 !=
1016
16.3k
                num_multi_layer_olss) {
1017
31.2k
                for (i = 0; i < num_multi_layer_olss; i++) {
1018
27.2k
                    ues(vps_ols_timing_hrd_idx[i], 0,
1019
27.2k
                        current->vps_num_ols_timing_hrd_params_minus1, 1, i);
1020
27.2k
                }
1021
21.8k
            } else if (current->vps_num_ols_timing_hrd_params_minus1 == 0) {
1022
62.2k
                for (i = 0; i < num_multi_layer_olss; i++)
1023
52.0k
                    infer(vps_ols_timing_hrd_idx[i], 0);
1024
11.7k
            } else {
1025
55.8k
                for (i = 0; i < num_multi_layer_olss; i++)
1026
44.1k
                    infer(vps_ols_timing_hrd_idx[i], i);
1027
11.7k
            }
1028
26.5k
        }
1029
60.8k
    }
1030
1031
37.6k
    flag(vps_extension_flag);
1032
36.3k
    if (current->vps_extension_flag)
1033
29.3k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
1034
36.3k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
1035
1036
34.8k
    return 0;
1037
36.3k
}
cbs_h266.c:cbs_h266_read_vps
Line
Count
Source
696
174k
{
697
174k
    int err, i, j, k;
698
174k
    uint16_t total_num_olss = 0;
699
174k
    uint8_t ols_mode_idc = 0;
700
174k
    uint16_t num_multi_layer_olss = 0;
701
174k
    uint8_t layer_included_in_ols_flag[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_LAYERS];
702
174k
    uint8_t num_ref_layers[VVC_MAX_LAYERS];
703
174k
    uint8_t reference_layer_idx[VVC_MAX_LAYERS][VVC_MAX_LAYERS];
704
705
174k
    HEADER("Video Parameter Set");
706
707
174k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
708
174k
                                 &current->nal_unit_header, VVC_VPS_NUT));
709
710
171k
    u(4, vps_video_parameter_set_id, 1, VVC_MAX_VPS_COUNT - 1);
711
167k
    ub(6, vps_max_layers_minus1);
712
166k
    u(3, vps_max_sublayers_minus1, 0, 6);
713
163k
    if (current->vps_max_layers_minus1 > 0
714
160k
        && current->vps_max_sublayers_minus1 > 0)
715
163k
        flag(vps_default_ptl_dpb_hrd_max_tid_flag);
716
89.4k
    else
717
89.4k
        infer(vps_default_ptl_dpb_hrd_max_tid_flag, 1);
718
719
163k
    if (current->vps_max_layers_minus1 > 0)
720
163k
        flag(vps_all_independent_layers_flag);
721
3.05k
    else
722
3.05k
        infer(vps_all_independent_layers_flag, 1);
723
724
728k
    for (i = 0; i <= current->vps_max_layers_minus1; i++) {
725
590k
        ubs(6, vps_layer_id[i], 1, i);
726
587k
        if (i > 0 && current->vps_layer_id[i] <= current->vps_layer_id[i - 1]) {
727
17.4k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
728
17.4k
                   "vps_layer_id[%d](%d) should > vps_layer_id[%d](%d).\n",
729
17.4k
                   i, current->vps_layer_id[i], i - 1,
730
17.4k
                   current->vps_layer_id[i - 1]);
731
17.4k
            return AVERROR_INVALIDDATA;
732
17.4k
        }
733
569k
        if (i > 0 && !current->vps_all_independent_layers_flag) {
734
350k
            flags(vps_independent_layer_flag[i], 1, i);
735
347k
            if (!current->vps_independent_layer_flag[i]) {
736
228k
                flags(vps_max_tid_ref_present_flag[i], 1, i);
737
805k
                for (j = 0; j < i; j++) {
738
578k
                    flags(vps_direct_ref_layer_flag[i][j], 2, i, j);
739
577k
                    if (current->vps_max_tid_ref_present_flag[i] &&
740
297k
                        current->vps_direct_ref_layer_flag[i][j]) {
741
196k
                        ubs(3, vps_max_tid_il_ref_pics_plus1[i][j], 2, i, j);
742
381k
                    } else {
743
381k
                        infer(vps_max_tid_il_ref_pics_plus1[i][j],
744
381k
                              current->vps_max_sublayers_minus1 + 1);
745
381k
                    }
746
577k
                }
747
227k
            } else {
748
306k
                for (j = 0; j < i; j++) {
749
187k
                    infer(vps_direct_ref_layer_flag[i][j], 0);
750
187k
                }
751
119k
            }
752
347k
        } else {
753
219k
            infer(vps_independent_layer_flag[i], 1);
754
308k
            for (j = 0; j < i; j++) {
755
88.7k
                infer(vps_direct_ref_layer_flag[i][j], 0);
756
88.7k
            }
757
219k
        }
758
569k
    }
759
760
138k
    if (current->vps_max_layers_minus1 > 0) {
761
135k
        if (current->vps_all_independent_layers_flag)
762
135k
            flag(vps_each_layer_is_an_ols_flag);
763
108k
        else
764
108k
            infer(vps_each_layer_is_an_ols_flag, 0);
765
135k
        if (!current->vps_each_layer_is_an_ols_flag) {
766
131k
            if (!current->vps_all_independent_layers_flag)
767
108k
                ub(2, vps_ols_mode_idc);
768
23.0k
            else
769
23.0k
                infer(vps_ols_mode_idc, 2);
770
130k
            if (current->vps_ols_mode_idc == 2) {
771
35.7k
                ub(8, vps_num_output_layer_sets_minus2);
772
661k
                for (i = 1; i <= current->vps_num_output_layer_sets_minus2 + 1;
773
627k
                     i++)
774
3.02M
                    for (j = 0; j <= current->vps_max_layers_minus1; j++)
775
2.39M
                        flags(vps_ols_output_layer_flag[i][j], 2, i, j);
776
34.5k
            }
777
125k
            ols_mode_idc = current->vps_ols_mode_idc;
778
125k
        } else {
779
3.50k
            ols_mode_idc = 4;
780
3.50k
        }
781
128k
        if (ols_mode_idc == 4 || ols_mode_idc == 0 || ols_mode_idc == 1)
782
94.2k
            total_num_olss = current->vps_max_layers_minus1 + 1;
783
34.5k
        else if (ols_mode_idc == 2)
784
30.3k
            total_num_olss = current->vps_num_output_layer_sets_minus2 + 2;
785
4.26k
        else
786
4.26k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
787
4.26k
                   "ols_mode_idc == 3, patch welcome");
788
128k
        u(8, vps_num_ptls_minus1, 0, total_num_olss - 1);
789
128k
    } else {
790
3.05k
        infer(vps_each_layer_is_an_ols_flag, 1);
791
3.05k
        infer(vps_num_ptls_minus1, 0);
792
3.05k
    }
793
794
731k
    for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
795
609k
        if (i > 0)
796
609k
            flags(vps_pt_present_flag[i], 1, i);
797
123k
        else
798
123k
            infer(vps_pt_present_flag[i], 1);
799
800
609k
        if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
801
609k
            us(3, vps_ptl_max_tid[i], 0, current->vps_max_sublayers_minus1, 1, i);
802
574k
        else
803
574k
            infer(vps_ptl_max_tid[i], current->vps_max_sublayers_minus1);
804
609k
    }
805
456k
    while (byte_alignment(rw) != 0)
806
341k
        fixed(1, vps_ptl_alignment_zero_bit, 0);
807
808
115k
    {
809
        //calc NumMultiLayerOlss
810
115k
        int m;
811
115k
        uint8_t dependency_flag[VVC_MAX_LAYERS][VVC_MAX_LAYERS];
812
115k
        uint16_t num_output_layers_in_ols[VVC_MAX_TOTAL_NUM_OLSS];
813
115k
        uint8_t num_sub_layers_in_layer_in_ols[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_TOTAL_NUM_OLSS];
814
115k
        uint8_t output_layer_idx[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_LAYERS];
815
816
        //7.4.3.3 vps_direct_ref_layer_flag section
817
549k
        for (i = 0; i <= current->vps_max_layers_minus1; i++) {
818
2.24M
            for (j = 0; j <= current->vps_max_layers_minus1; j++) {
819
1.80M
                dependency_flag[i][j] = current->vps_direct_ref_layer_flag[i][j];
820
4.92M
                for (k = 0; k < i; k++) {
821
3.11M
                    if (current->vps_direct_ref_layer_flag[i][k] &&
822
1.18M
                        dependency_flag[k][j])
823
67.2k
                        dependency_flag[i][j] = 1;
824
3.11M
                }
825
1.80M
            }
826
434k
        }
827
549k
        for (i = 0; i <= current->vps_max_layers_minus1; i++) {
828
434k
            int r;
829
2.24M
            for (j = 0, r = 0; j <= current->vps_max_layers_minus1; j++) {
830
1.80M
                if (dependency_flag[i][j])
831
262k
                    reference_layer_idx[i][r++] = j;
832
1.80M
            }
833
434k
            num_ref_layers[i] = r;
834
434k
        }
835
836
        //7.4.3.3 vps_ols_output_layer_flag section
837
115k
        num_output_layers_in_ols[0] = 1;
838
115k
        num_sub_layers_in_layer_in_ols[0][0] =
839
115k
            current->vps_ptl_max_tid[current->vps_ols_ptl_idx[0]] + 1;
840
526k
        for (i = 1; i < total_num_olss; i++) {
841
414k
            if (ols_mode_idc == 4 || ols_mode_idc == 0) {
842
143k
                num_output_layers_in_ols[i] = 1;
843
143k
                if (current->vps_each_layer_is_an_ols_flag) {
844
1.79k
                    num_sub_layers_in_layer_in_ols[i][0] =
845
1.79k
                        current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
846
141k
                } else {
847
141k
                    num_sub_layers_in_layer_in_ols[i][i] =
848
141k
                        current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
849
445k
                    for (k = i - 1; k >= 0; k--) {
850
303k
                        num_sub_layers_in_layer_in_ols[i][k] = 0;
851
861k
                        for (m = k + 1; m <= i; m++) {
852
557k
                            uint8_t max_sublayer_needed =
853
557k
                                FFMIN(num_sub_layers_in_layer_in_ols[i][m],
854
557k
                                      current->vps_max_tid_il_ref_pics_plus1[m][k]);
855
557k
                            if (current->vps_direct_ref_layer_flag[m][k] &&
856
172k
                                num_sub_layers_in_layer_in_ols[i][k] < max_sublayer_needed)
857
48.8k
                                num_sub_layers_in_layer_in_ols[i][k] = max_sublayer_needed;
858
557k
                        }
859
303k
                    }
860
141k
                }
861
270k
            } else if (current->vps_ols_mode_idc == 1) {
862
113k
                num_output_layers_in_ols[i] = i + 1;
863
502k
                for (j = 0; j < num_output_layers_in_ols[i]; j++) {
864
389k
                    num_sub_layers_in_layer_in_ols[i][j] =
865
389k
                        current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
866
389k
                }
867
156k
            } else if (current->vps_ols_mode_idc == 2) {
868
156k
                uint8_t highest_included_layer = 0;
869
698k
                for (j = 0; j <= current->vps_max_layers_minus1; j++) {
870
541k
                    layer_included_in_ols_flag[i][j] = 0;
871
541k
                    num_sub_layers_in_layer_in_ols[i][j] = 0;
872
541k
                }
873
698k
                for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++) {
874
541k
                    if (current->vps_ols_output_layer_flag[i][k]) {
875
356k
                        layer_included_in_ols_flag[i][k] = 1;
876
356k
                        highest_included_layer = k;
877
356k
                        output_layer_idx[i][j] = k;
878
356k
                        num_sub_layers_in_layer_in_ols[i][k] =
879
356k
                            current->vps_ptl_max_tid[current->
880
356k
                                                     vps_ols_ptl_idx[i]] + 1;
881
356k
                        j++;
882
356k
                    }
883
541k
                }
884
156k
                num_output_layers_in_ols[i] = j;
885
513k
                for (j = 0; j < num_output_layers_in_ols[i]; j++) {
886
356k
                    int idx = output_layer_idx[i][j];
887
452k
                    for (k = 0; k < num_ref_layers[idx]; k++) {
888
95.7k
                        if (!layer_included_in_ols_flag[i][reference_layer_idx[idx][k]])
889
23.5k
                            layer_included_in_ols_flag[i][reference_layer_idx[idx][k]] = 1;
890
95.7k
                    }
891
356k
                }
892
431k
                for (k = highest_included_layer - 1; k >= 0; k--) {
893
274k
                    if (layer_included_in_ols_flag[i][k] &&
894
225k
                        !current->vps_ols_output_layer_flag[i][k]) {
895
75.5k
                        for (m = k + 1; m <= highest_included_layer; m++) {
896
52.0k
                            uint8_t max_sublayer_needed =
897
52.0k
                                FFMIN(num_sub_layers_in_layer_in_ols[i][m],
898
52.0k
                                      current->vps_max_tid_il_ref_pics_plus1[m][k]);
899
52.0k
                            if (current->vps_direct_ref_layer_flag[m][k] &&
900
33.5k
                                layer_included_in_ols_flag[i][m] &&
901
28.5k
                                num_sub_layers_in_layer_in_ols[i][k] <
902
28.5k
                                max_sublayer_needed)
903
22.0k
                                num_sub_layers_in_layer_in_ols[i][k] =
904
22.0k
                                    max_sublayer_needed;
905
52.0k
                        }
906
23.5k
                    }
907
274k
                }
908
156k
            }
909
414k
            if (!num_output_layers_in_ols[i])
910
2.88k
                return AVERROR_INVALIDDATA;
911
414k
        }
912
509k
        for (i = 1; i < total_num_olss; i++) {
913
396k
            int num_layers_in_ols = 0;
914
396k
            if (current->vps_each_layer_is_an_ols_flag) {
915
1.79k
                num_layers_in_ols = 1;
916
394k
            } else if (current->vps_ols_mode_idc == 0 ||
917
255k
                       current->vps_ols_mode_idc == 1) {
918
255k
                num_layers_in_ols = i + 1;
919
255k
            } else if (current->vps_ols_mode_idc == 2) {
920
606k
                for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++)
921
466k
                    if (layer_included_in_ols_flag[i][k])
922
332k
                        j++;
923
139k
                num_layers_in_ols = j;
924
139k
            }
925
396k
            if (num_layers_in_ols > 1) {
926
374k
                num_multi_layer_olss++;
927
374k
            }
928
396k
        }
929
112k
        if (!current->vps_each_layer_is_an_ols_flag && num_multi_layer_olss == 0)
930
1.94k
            return AVERROR_INVALIDDATA;
931
112k
    }
932
933
216k
    for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
934
140k
        CHECK(FUNC(profile_tier_level) (ctx, rw,
935
140k
                                        current->vps_profile_tier_level + i,
936
140k
                                        current->vps_pt_present_flag[i],
937
140k
                                        current->vps_ptl_max_tid[i]));
938
140k
    }
939
430k
    for (i = 0; i < total_num_olss; i++) {
940
356k
        if (current->vps_num_ptls_minus1 > 0 &&
941
48.0k
            current->vps_num_ptls_minus1 + 1 != total_num_olss) {
942
22.9k
            us(8, vps_ols_ptl_idx[i], 0, current->vps_num_ptls_minus1, 1, i);
943
333k
        } else if (current->vps_num_ptls_minus1 == 0) {
944
308k
            infer(vps_ols_ptl_idx[i], 0);
945
308k
        } else {
946
25.1k
            infer(vps_ols_ptl_idx[i], i);
947
25.1k
        }
948
356k
    }
949
950
73.9k
    if (!current->vps_each_layer_is_an_ols_flag) {
951
71.9k
        uint16_t vps_num_dpb_params;
952
71.9k
        ue(vps_num_dpb_params_minus1, 0, num_multi_layer_olss - 1);
953
68.0k
        if (current->vps_each_layer_is_an_ols_flag)
954
0
            vps_num_dpb_params = 0;
955
68.0k
        else
956
68.0k
            vps_num_dpb_params = current->vps_num_dpb_params_minus1 + 1;
957
958
68.0k
        if (current->vps_max_sublayers_minus1 > 0)
959
68.0k
            flag(vps_sublayer_dpb_params_present_flag);
960
46.9k
        else
961
46.9k
            infer(vps_sublayer_dpb_params_present_flag, 0);
962
963
144k
        for (i = 0; i < vps_num_dpb_params; i++) {
964
79.7k
            if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
965
79.7k
                us(3, vps_dpb_max_tid[i], 0, current->vps_max_sublayers_minus1,
966
73.3k
                   1, i);
967
73.3k
            else
968
73.3k
                infer(vps_dpb_max_tid[i], current->vps_max_sublayers_minus1);
969
79.0k
            CHECK(FUNC(dpb_parameters) (ctx, rw, current->vps_dpb_params + i,
970
79.0k
                                        current->vps_dpb_max_tid[i],
971
79.0k
                                        current->
972
79.0k
                                        vps_sublayer_dpb_params_present_flag));
973
79.0k
        }
974
276k
        for (i = 0; i < num_multi_layer_olss; i++) {
975
220k
            ues(vps_ols_dpb_pic_width[i], 0, UINT16_MAX, 1, i);
976
218k
            ues(vps_ols_dpb_pic_height[i], 0, UINT16_MAX, 1, i);
977
217k
            ubs(2, vps_ols_dpb_chroma_format[i], 1, i);
978
214k
            ues(vps_ols_dpb_bitdepth_minus8[i], 0, 8, 1, i);
979
213k
            if (vps_num_dpb_params > 1
980
25.3k
                && vps_num_dpb_params != num_multi_layer_olss)
981
213k
                ues(vps_ols_dpb_params_idx[i], 0, vps_num_dpb_params - 1, 1, i);
982
193k
            else if (vps_num_dpb_params == 1)
983
187k
                infer(vps_ols_dpb_params_idx[i], 0);
984
5.31k
            else
985
5.31k
                infer(vps_ols_dpb_params_idx[i], i);
986
213k
        }
987
55.7k
        flag(vps_timing_hrd_params_present_flag);
988
55.3k
        if (current->vps_timing_hrd_params_present_flag) {
989
47.0k
            CHECK(FUNC(general_timing_hrd_parameters) (ctx, rw,
990
47.0k
                                                       &current->
991
47.0k
                                                       vps_general_timing_hrd_parameters));
992
33.2k
            if (current->vps_max_sublayers_minus1 > 0)
993
33.2k
                flag(vps_sublayer_cpb_params_present_flag);
994
23.4k
            else
995
23.4k
                infer(vps_sublayer_cpb_params_present_flag, 0);
996
32.6k
            ue(vps_num_ols_timing_hrd_params_minus1, 0,
997
30.0k
               num_multi_layer_olss - 1);
998
93.6k
            for (i = 0; i <= current->vps_num_ols_timing_hrd_params_minus1; i++) {
999
71.5k
                uint8_t first_sublayer;
1000
71.5k
                if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
1001
71.5k
                    us(3, vps_hrd_max_tid[i], 0,
1002
68.2k
                       current->vps_max_sublayers_minus1, 1, i);
1003
68.2k
                else
1004
68.2k
                    infer(vps_hrd_max_tid[i],
1005
71.5k
                          current->vps_max_sublayers_minus1);
1006
70.7k
                first_sublayer = current->vps_sublayer_cpb_params_present_flag ?
1007
61.5k
                                 0 : current->vps_hrd_max_tid[i];
1008
70.7k
                CHECK(FUNC(ols_timing_hrd_parameters)
1009
70.7k
                      (ctx, rw, &current->vps_ols_timing_hrd_parameters,
1010
70.7k
                       first_sublayer, current->vps_max_sublayers_minus1,
1011
70.7k
                       &current->vps_general_timing_hrd_parameters));
1012
1013
70.7k
            }
1014
22.0k
            if (current->vps_num_ols_timing_hrd_params_minus1 > 0 &&
1015
13.8k
                current->vps_num_ols_timing_hrd_params_minus1 + 1 !=
1016
13.8k
                num_multi_layer_olss) {
1017
25.1k
                for (i = 0; i < num_multi_layer_olss; i++) {
1018
21.8k
                    ues(vps_ols_timing_hrd_idx[i], 0,
1019
21.8k
                        current->vps_num_ols_timing_hrd_params_minus1, 1, i);
1020
21.8k
                }
1021
18.1k
            } else if (current->vps_num_ols_timing_hrd_params_minus1 == 0) {
1022
40.5k
                for (i = 0; i < num_multi_layer_olss; i++)
1023
32.3k
                    infer(vps_ols_timing_hrd_idx[i], 0);
1024
9.94k
            } else {
1025
48.0k
                for (i = 0; i < num_multi_layer_olss; i++)
1026
38.1k
                    infer(vps_ols_timing_hrd_idx[i], i);
1027
9.94k
            }
1028
22.0k
        }
1029
55.3k
    }
1030
1031
31.6k
    flag(vps_extension_flag);
1032
30.3k
    if (current->vps_extension_flag)
1033
23.6k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
1034
30.3k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
1035
1036
28.8k
    return 0;
1037
30.3k
}
cbs_h266.c:cbs_h266_write_vps
Line
Count
Source
696
5.99k
{
697
5.99k
    int err, i, j, k;
698
5.99k
    uint16_t total_num_olss = 0;
699
5.99k
    uint8_t ols_mode_idc = 0;
700
5.99k
    uint16_t num_multi_layer_olss = 0;
701
5.99k
    uint8_t layer_included_in_ols_flag[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_LAYERS];
702
5.99k
    uint8_t num_ref_layers[VVC_MAX_LAYERS];
703
5.99k
    uint8_t reference_layer_idx[VVC_MAX_LAYERS][VVC_MAX_LAYERS];
704
705
5.99k
    HEADER("Video Parameter Set");
706
707
5.99k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
708
5.99k
                                 &current->nal_unit_header, VVC_VPS_NUT));
709
710
5.99k
    u(4, vps_video_parameter_set_id, 1, VVC_MAX_VPS_COUNT - 1);
711
5.99k
    ub(6, vps_max_layers_minus1);
712
5.99k
    u(3, vps_max_sublayers_minus1, 0, 6);
713
5.99k
    if (current->vps_max_layers_minus1 > 0
714
5.79k
        && current->vps_max_sublayers_minus1 > 0)
715
5.99k
        flag(vps_default_ptl_dpb_hrd_max_tid_flag);
716
4.87k
    else
717
4.87k
        infer(vps_default_ptl_dpb_hrd_max_tid_flag, 1);
718
719
5.99k
    if (current->vps_max_layers_minus1 > 0)
720
5.99k
        flag(vps_all_independent_layers_flag);
721
199
    else
722
199
        infer(vps_all_independent_layers_flag, 1);
723
724
28.9k
    for (i = 0; i <= current->vps_max_layers_minus1; i++) {
725
22.9k
        ubs(6, vps_layer_id[i], 1, i);
726
22.9k
        if (i > 0 && current->vps_layer_id[i] <= current->vps_layer_id[i - 1]) {
727
0
            av_log(ctx->log_ctx, AV_LOG_ERROR,
728
0
                   "vps_layer_id[%d](%d) should > vps_layer_id[%d](%d).\n",
729
0
                   i, current->vps_layer_id[i], i - 1,
730
0
                   current->vps_layer_id[i - 1]);
731
0
            return AVERROR_INVALIDDATA;
732
0
        }
733
22.9k
        if (i > 0 && !current->vps_all_independent_layers_flag) {
734
16.5k
            flags(vps_independent_layer_flag[i], 1, i);
735
16.5k
            if (!current->vps_independent_layer_flag[i]) {
736
11.8k
                flags(vps_max_tid_ref_present_flag[i], 1, i);
737
42.6k
                for (j = 0; j < i; j++) {
738
30.8k
                    flags(vps_direct_ref_layer_flag[i][j], 2, i, j);
739
30.8k
                    if (current->vps_max_tid_ref_present_flag[i] &&
740
20.1k
                        current->vps_direct_ref_layer_flag[i][j]) {
741
12.0k
                        ubs(3, vps_max_tid_il_ref_pics_plus1[i][j], 2, i, j);
742
18.7k
                    } else {
743
18.7k
                        infer(vps_max_tid_il_ref_pics_plus1[i][j],
744
18.7k
                              current->vps_max_sublayers_minus1 + 1);
745
18.7k
                    }
746
30.8k
                }
747
11.8k
            } else {
748
9.85k
                for (j = 0; j < i; j++) {
749
5.14k
                    infer(vps_direct_ref_layer_flag[i][j], 0);
750
5.14k
                }
751
4.70k
            }
752
16.5k
        } else {
753
6.40k
            infer(vps_independent_layer_flag[i], 1);
754
6.87k
            for (j = 0; j < i; j++) {
755
471
                infer(vps_direct_ref_layer_flag[i][j], 0);
756
471
            }
757
6.40k
        }
758
22.9k
    }
759
760
5.99k
    if (current->vps_max_layers_minus1 > 0) {
761
5.79k
        if (current->vps_all_independent_layers_flag)
762
5.79k
            flag(vps_each_layer_is_an_ols_flag);
763
5.45k
        else
764
5.45k
            infer(vps_each_layer_is_an_ols_flag, 0);
765
5.79k
        if (!current->vps_each_layer_is_an_ols_flag) {
766
5.52k
            if (!current->vps_all_independent_layers_flag)
767
5.45k
                ub(2, vps_ols_mode_idc);
768
68
            else
769
68
                infer(vps_ols_mode_idc, 2);
770
5.52k
            if (current->vps_ols_mode_idc == 2) {
771
1.06k
                ub(8, vps_num_output_layer_sets_minus2);
772
26.4k
                for (i = 1; i <= current->vps_num_output_layer_sets_minus2 + 1;
773
25.3k
                     i++)
774
123k
                    for (j = 0; j <= current->vps_max_layers_minus1; j++)
775
97.6k
                        flags(vps_ols_output_layer_flag[i][j], 2, i, j);
776
1.06k
            }
777
5.52k
            ols_mode_idc = current->vps_ols_mode_idc;
778
5.52k
        } else {
779
271
            ols_mode_idc = 4;
780
271
        }
781
5.79k
        if (ols_mode_idc == 4 || ols_mode_idc == 0 || ols_mode_idc == 1)
782
4.73k
            total_num_olss = current->vps_max_layers_minus1 + 1;
783
1.06k
        else if (ols_mode_idc == 2)
784
1.06k
            total_num_olss = current->vps_num_output_layer_sets_minus2 + 2;
785
0
        else
786
0
            av_log(ctx->log_ctx, AV_LOG_ERROR,
787
0
                   "ols_mode_idc == 3, patch welcome");
788
5.79k
        u(8, vps_num_ptls_minus1, 0, total_num_olss - 1);
789
5.79k
    } else {
790
199
        infer(vps_each_layer_is_an_ols_flag, 1);
791
199
        infer(vps_num_ptls_minus1, 0);
792
199
    }
793
794
13.6k
    for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
795
7.70k
        if (i > 0)
796
7.70k
            flags(vps_pt_present_flag[i], 1, i);
797
5.99k
        else
798
5.99k
            infer(vps_pt_present_flag[i], 1);
799
800
7.70k
        if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
801
7.70k
            us(3, vps_ptl_max_tid[i], 0, current->vps_max_sublayers_minus1, 1, i);
802
6.66k
        else
803
6.66k
            infer(vps_ptl_max_tid[i], current->vps_max_sublayers_minus1);
804
7.70k
    }
805
23.3k
    while (byte_alignment(rw) != 0)
806
17.3k
        fixed(1, vps_ptl_alignment_zero_bit, 0);
807
808
5.99k
    {
809
        //calc NumMultiLayerOlss
810
5.99k
        int m;
811
5.99k
        uint8_t dependency_flag[VVC_MAX_LAYERS][VVC_MAX_LAYERS];
812
5.99k
        uint16_t num_output_layers_in_ols[VVC_MAX_TOTAL_NUM_OLSS];
813
5.99k
        uint8_t num_sub_layers_in_layer_in_ols[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_TOTAL_NUM_OLSS];
814
5.99k
        uint8_t output_layer_idx[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_LAYERS];
815
816
        //7.4.3.3 vps_direct_ref_layer_flag section
817
28.9k
        for (i = 0; i <= current->vps_max_layers_minus1; i++) {
818
118k
            for (j = 0; j <= current->vps_max_layers_minus1; j++) {
819
95.7k
                dependency_flag[i][j] = current->vps_direct_ref_layer_flag[i][j];
820
259k
                for (k = 0; k < i; k++) {
821
163k
                    if (current->vps_direct_ref_layer_flag[i][k] &&
822
85.6k
                        dependency_flag[k][j])
823
4.11k
                        dependency_flag[i][j] = 1;
824
163k
                }
825
95.7k
            }
826
22.9k
        }
827
28.9k
        for (i = 0; i <= current->vps_max_layers_minus1; i++) {
828
22.9k
            int r;
829
118k
            for (j = 0, r = 0; j <= current->vps_max_layers_minus1; j++) {
830
95.7k
                if (dependency_flag[i][j])
831
18.8k
                    reference_layer_idx[i][r++] = j;
832
95.7k
            }
833
22.9k
            num_ref_layers[i] = r;
834
22.9k
        }
835
836
        //7.4.3.3 vps_ols_output_layer_flag section
837
5.99k
        num_output_layers_in_ols[0] = 1;
838
5.99k
        num_sub_layers_in_layer_in_ols[0][0] =
839
5.99k
            current->vps_ptl_max_tid[current->vps_ols_ptl_idx[0]] + 1;
840
45.4k
        for (i = 1; i < total_num_olss; i++) {
841
39.4k
            if (ols_mode_idc == 4 || ols_mode_idc == 0) {
842
5.96k
                num_output_layers_in_ols[i] = 1;
843
5.96k
                if (current->vps_each_layer_is_an_ols_flag) {
844
337
                    num_sub_layers_in_layer_in_ols[i][0] =
845
337
                        current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
846
5.62k
                } else {
847
5.62k
                    num_sub_layers_in_layer_in_ols[i][i] =
848
5.62k
                        current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
849
16.0k
                    for (k = i - 1; k >= 0; k--) {
850
10.4k
                        num_sub_layers_in_layer_in_ols[i][k] = 0;
851
27.6k
                        for (m = k + 1; m <= i; m++) {
852
17.1k
                            uint8_t max_sublayer_needed =
853
17.1k
                                FFMIN(num_sub_layers_in_layer_in_ols[i][m],
854
17.1k
                                      current->vps_max_tid_il_ref_pics_plus1[m][k]);
855
17.1k
                            if (current->vps_direct_ref_layer_flag[m][k] &&
856
7.23k
                                num_sub_layers_in_layer_in_ols[i][k] < max_sublayer_needed)
857
3.81k
                                num_sub_layers_in_layer_in_ols[i][k] = max_sublayer_needed;
858
17.1k
                        }
859
10.4k
                    }
860
5.62k
                }
861
33.5k
            } else if (current->vps_ols_mode_idc == 1) {
862
8.16k
                num_output_layers_in_ols[i] = i + 1;
863
36.5k
                for (j = 0; j < num_output_layers_in_ols[i]; j++) {
864
28.3k
                    num_sub_layers_in_layer_in_ols[i][j] =
865
28.3k
                        current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
866
28.3k
                }
867
25.3k
            } else if (current->vps_ols_mode_idc == 2) {
868
25.3k
                uint8_t highest_included_layer = 0;
869
123k
                for (j = 0; j <= current->vps_max_layers_minus1; j++) {
870
97.6k
                    layer_included_in_ols_flag[i][j] = 0;
871
97.6k
                    num_sub_layers_in_layer_in_ols[i][j] = 0;
872
97.6k
                }
873
123k
                for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++) {
874
97.6k
                    if (current->vps_ols_output_layer_flag[i][k]) {
875
56.0k
                        layer_included_in_ols_flag[i][k] = 1;
876
56.0k
                        highest_included_layer = k;
877
56.0k
                        output_layer_idx[i][j] = k;
878
56.0k
                        num_sub_layers_in_layer_in_ols[i][k] =
879
56.0k
                            current->vps_ptl_max_tid[current->
880
56.0k
                                                     vps_ols_ptl_idx[i]] + 1;
881
56.0k
                        j++;
882
56.0k
                    }
883
97.6k
                }
884
25.3k
                num_output_layers_in_ols[i] = j;
885
81.3k
                for (j = 0; j < num_output_layers_in_ols[i]; j++) {
886
56.0k
                    int idx = output_layer_idx[i][j];
887
88.0k
                    for (k = 0; k < num_ref_layers[idx]; k++) {
888
32.0k
                        if (!layer_included_in_ols_flag[i][reference_layer_idx[idx][k]])
889
10.3k
                            layer_included_in_ols_flag[i][reference_layer_idx[idx][k]] = 1;
890
32.0k
                    }
891
56.0k
                }
892
78.5k
                for (k = highest_included_layer - 1; k >= 0; k--) {
893
53.1k
                    if (layer_included_in_ols_flag[i][k] &&
894
41.0k
                        !current->vps_ols_output_layer_flag[i][k]) {
895
32.7k
                        for (m = k + 1; m <= highest_included_layer; m++) {
896
22.3k
                            uint8_t max_sublayer_needed =
897
22.3k
                                FFMIN(num_sub_layers_in_layer_in_ols[i][m],
898
22.3k
                                      current->vps_max_tid_il_ref_pics_plus1[m][k]);
899
22.3k
                            if (current->vps_direct_ref_layer_flag[m][k] &&
900
16.0k
                                layer_included_in_ols_flag[i][m] &&
901
12.7k
                                num_sub_layers_in_layer_in_ols[i][k] <
902
12.7k
                                max_sublayer_needed)
903
10.1k
                                num_sub_layers_in_layer_in_ols[i][k] =
904
10.1k
                                    max_sublayer_needed;
905
22.3k
                        }
906
10.3k
                    }
907
53.1k
                }
908
25.3k
            }
909
39.4k
            if (!num_output_layers_in_ols[i])
910
0
                return AVERROR_INVALIDDATA;
911
39.4k
        }
912
45.4k
        for (i = 1; i < total_num_olss; i++) {
913
39.4k
            int num_layers_in_ols = 0;
914
39.4k
            if (current->vps_each_layer_is_an_ols_flag) {
915
337
                num_layers_in_ols = 1;
916
39.1k
            } else if (current->vps_ols_mode_idc == 0 ||
917
33.5k
                       current->vps_ols_mode_idc == 1) {
918
13.7k
                num_layers_in_ols = i + 1;
919
25.3k
            } else if (current->vps_ols_mode_idc == 2) {
920
123k
                for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++)
921
97.6k
                    if (layer_included_in_ols_flag[i][k])
922
66.4k
                        j++;
923
25.3k
                num_layers_in_ols = j;
924
25.3k
            }
925
39.4k
            if (num_layers_in_ols > 1) {
926
34.1k
                num_multi_layer_olss++;
927
34.1k
            }
928
39.4k
        }
929
5.99k
        if (!current->vps_each_layer_is_an_ols_flag && num_multi_layer_olss == 0)
930
0
            return AVERROR_INVALIDDATA;
931
5.99k
    }
932
933
13.6k
    for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
934
7.70k
        CHECK(FUNC(profile_tier_level) (ctx, rw,
935
7.70k
                                        current->vps_profile_tier_level + i,
936
7.70k
                                        current->vps_pt_present_flag[i],
937
7.70k
                                        current->vps_ptl_max_tid[i]));
938
7.70k
    }
939
51.2k
    for (i = 0; i < total_num_olss; i++) {
940
45.2k
        if (current->vps_num_ptls_minus1 > 0 &&
941
2.76k
            current->vps_num_ptls_minus1 + 1 != total_num_olss) {
942
1.50k
            us(8, vps_ols_ptl_idx[i], 0, current->vps_num_ptls_minus1, 1, i);
943
43.7k
        } else if (current->vps_num_ptls_minus1 == 0) {
944
42.5k
            infer(vps_ols_ptl_idx[i], 0);
945
42.5k
        } else {
946
1.25k
            infer(vps_ols_ptl_idx[i], i);
947
1.25k
        }
948
45.2k
    }
949
950
5.99k
    if (!current->vps_each_layer_is_an_ols_flag) {
951
5.52k
        uint16_t vps_num_dpb_params;
952
5.52k
        ue(vps_num_dpb_params_minus1, 0, num_multi_layer_olss - 1);
953
5.52k
        if (current->vps_each_layer_is_an_ols_flag)
954
0
            vps_num_dpb_params = 0;
955
5.52k
        else
956
5.52k
            vps_num_dpb_params = current->vps_num_dpb_params_minus1 + 1;
957
958
5.52k
        if (current->vps_max_sublayers_minus1 > 0)
959
5.52k
            flag(vps_sublayer_dpb_params_present_flag);
960
4.67k
        else
961
4.67k
            infer(vps_sublayer_dpb_params_present_flag, 0);
962
963
12.3k
        for (i = 0; i < vps_num_dpb_params; i++) {
964
6.79k
            if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
965
6.79k
                us(3, vps_dpb_max_tid[i], 0, current->vps_max_sublayers_minus1,
966
6.09k
                   1, i);
967
6.09k
            else
968
6.09k
                infer(vps_dpb_max_tid[i], current->vps_max_sublayers_minus1);
969
6.79k
            CHECK(FUNC(dpb_parameters) (ctx, rw, current->vps_dpb_params + i,
970
6.79k
                                        current->vps_dpb_max_tid[i],
971
6.79k
                                        current->
972
6.79k
                                        vps_sublayer_dpb_params_present_flag));
973
6.79k
        }
974
39.6k
        for (i = 0; i < num_multi_layer_olss; i++) {
975
34.1k
            ues(vps_ols_dpb_pic_width[i], 0, UINT16_MAX, 1, i);
976
34.1k
            ues(vps_ols_dpb_pic_height[i], 0, UINT16_MAX, 1, i);
977
34.1k
            ubs(2, vps_ols_dpb_chroma_format[i], 1, i);
978
34.1k
            ues(vps_ols_dpb_bitdepth_minus8[i], 0, 8, 1, i);
979
34.1k
            if (vps_num_dpb_params > 1
980
11.5k
                && vps_num_dpb_params != num_multi_layer_olss)
981
34.1k
                ues(vps_ols_dpb_params_idx[i], 0, vps_num_dpb_params - 1, 1, i);
982
23.2k
            else if (vps_num_dpb_params == 1)
983
22.5k
                infer(vps_ols_dpb_params_idx[i], 0);
984
699
            else
985
699
                infer(vps_ols_dpb_params_idx[i], i);
986
34.1k
        }
987
5.52k
        flag(vps_timing_hrd_params_present_flag);
988
5.52k
        if (current->vps_timing_hrd_params_present_flag) {
989
4.46k
            CHECK(FUNC(general_timing_hrd_parameters) (ctx, rw,
990
4.46k
                                                       &current->
991
4.46k
                                                       vps_general_timing_hrd_parameters));
992
4.46k
            if (current->vps_max_sublayers_minus1 > 0)
993
4.46k
                flag(vps_sublayer_cpb_params_present_flag);
994
3.80k
            else
995
3.80k
                infer(vps_sublayer_cpb_params_present_flag, 0);
996
4.46k
            ue(vps_num_ols_timing_hrd_params_minus1, 0,
997
4.46k
               num_multi_layer_olss - 1);
998
15.9k
            for (i = 0; i <= current->vps_num_ols_timing_hrd_params_minus1; i++) {
999
11.4k
                uint8_t first_sublayer;
1000
11.4k
                if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
1001
11.4k
                    us(3, vps_hrd_max_tid[i], 0,
1002
10.3k
                       current->vps_max_sublayers_minus1, 1, i);
1003
10.3k
                else
1004
10.3k
                    infer(vps_hrd_max_tid[i],
1005
11.4k
                          current->vps_max_sublayers_minus1);
1006
11.4k
                first_sublayer = current->vps_sublayer_cpb_params_present_flag ?
1007
10.0k
                                 0 : current->vps_hrd_max_tid[i];
1008
11.4k
                CHECK(FUNC(ols_timing_hrd_parameters)
1009
11.4k
                      (ctx, rw, &current->vps_ols_timing_hrd_parameters,
1010
11.4k
                       first_sublayer, current->vps_max_sublayers_minus1,
1011
11.4k
                       &current->vps_general_timing_hrd_parameters));
1012
1013
11.4k
            }
1014
4.46k
            if (current->vps_num_ols_timing_hrd_params_minus1 > 0 &&
1015
2.48k
                current->vps_num_ols_timing_hrd_params_minus1 + 1 !=
1016
2.48k
                num_multi_layer_olss) {
1017
6.11k
                for (i = 0; i < num_multi_layer_olss; i++) {
1018
5.39k
                    ues(vps_ols_timing_hrd_idx[i], 0,
1019
5.39k
                        current->vps_num_ols_timing_hrd_params_minus1, 1, i);
1020
5.39k
                }
1021
3.73k
            } else if (current->vps_num_ols_timing_hrd_params_minus1 == 0) {
1022
21.7k
                for (i = 0; i < num_multi_layer_olss; i++)
1023
19.7k
                    infer(vps_ols_timing_hrd_idx[i], 0);
1024
1.97k
            } else {
1025
7.73k
                for (i = 0; i < num_multi_layer_olss; i++)
1026
5.96k
                    infer(vps_ols_timing_hrd_idx[i], i);
1027
1.76k
            }
1028
4.46k
        }
1029
5.52k
    }
1030
1031
5.99k
    flag(vps_extension_flag);
1032
5.99k
    if (current->vps_extension_flag)
1033
5.64k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
1034
5.99k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
1035
1036
5.99k
    return 0;
1037
5.99k
}
1038
1039
static int FUNC(sps_range_extension)(CodedBitstreamContext *ctx, RWContext *rw,
1040
                                     H266RawSPS *current)
1041
12.4k
{
1042
12.4k
    int err;
1043
1044
12.4k
    flag(sps_extended_precision_flag);
1045
12.2k
    if (current->sps_transform_skip_enabled_flag)
1046
12.2k
        flag(sps_ts_residual_coding_rice_present_in_sh_flag);
1047
5.13k
    else
1048
5.13k
        infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1049
11.9k
    flag(sps_rrc_rice_extension_flag);
1050
11.5k
    flag(sps_persistent_rice_adaptation_enabled_flag);
1051
11.2k
    flag(sps_reverse_last_sig_coeff_enabled_flag);
1052
1053
10.9k
    return 0;
1054
11.2k
}
cbs_h266.c:cbs_h266_read_sps_range_extension
Line
Count
Source
1041
11.7k
{
1042
11.7k
    int err;
1043
1044
11.7k
    flag(sps_extended_precision_flag);
1045
11.4k
    if (current->sps_transform_skip_enabled_flag)
1046
11.4k
        flag(sps_ts_residual_coding_rice_present_in_sh_flag);
1047
4.75k
    else
1048
4.75k
        infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1049
11.1k
    flag(sps_rrc_rice_extension_flag);
1050
10.7k
    flag(sps_persistent_rice_adaptation_enabled_flag);
1051
10.4k
    flag(sps_reverse_last_sig_coeff_enabled_flag);
1052
1053
10.1k
    return 0;
1054
10.4k
}
cbs_h266.c:cbs_h266_write_sps_range_extension
Line
Count
Source
1041
789
{
1042
789
    int err;
1043
1044
789
    flag(sps_extended_precision_flag);
1045
789
    if (current->sps_transform_skip_enabled_flag)
1046
789
        flag(sps_ts_residual_coding_rice_present_in_sh_flag);
1047
383
    else
1048
383
        infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1049
789
    flag(sps_rrc_rice_extension_flag);
1050
789
    flag(sps_persistent_rice_adaptation_enabled_flag);
1051
789
    flag(sps_reverse_last_sig_coeff_enabled_flag);
1052
1053
789
    return 0;
1054
789
}
1055
1056
static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
1057
                     H266RawSPS *current)
1058
774k
{
1059
774k
    CodedBitstreamH266Context *h266 = ctx->priv_data;
1060
774k
    int err, i, j, max_width_minus1, max_height_minus1;
1061
774k
    unsigned int ctb_log2_size_y, min_cb_log2_size_y,
1062
774k
                 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y,
1063
774k
                 ctb_size_y, max_num_merge_cand, tmp_width_val, tmp_height_val;
1064
774k
    uint8_t qp_bd_offset, sub_width_c, sub_height_c;
1065
1066
774k
    static const uint8_t h266_sub_width_c[] = {
1067
774k
        1, 2, 2, 1
1068
774k
    };
1069
774k
    static const uint8_t h266_sub_height_c[] = {
1070
774k
        1, 2, 1, 1
1071
774k
    };
1072
1073
774k
    HEADER("Sequence Parameter Set");
1074
1075
774k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
1076
774k
                                 &current->nal_unit_header, VVC_SPS_NUT));
1077
1078
771k
    ub(4, sps_seq_parameter_set_id);
1079
766k
    ub(4, sps_video_parameter_set_id);
1080
766k
    if (current->sps_video_parameter_set_id == 0 && !h266->vps[0]) {
1081
28.1k
        H266RawVPS *vps = av_refstruct_allocz(sizeof(*vps));
1082
28.1k
        if (!vps)
1083
0
            return AVERROR(ENOMEM);
1084
28.1k
        vps->vps_max_layers_minus1 = 0;
1085
28.1k
        vps->vps_independent_layer_flag[0] = 1;
1086
28.1k
        vps->vps_layer_id[0] = current->nal_unit_header.nuh_layer_id;
1087
28.1k
        h266->vps[0] = vps;
1088
28.1k
    }
1089
1090
766k
    u(3, sps_max_sublayers_minus1, 0, VVC_MAX_SUBLAYERS - 1);
1091
754k
    u(2, sps_chroma_format_idc, 0, 3);
1092
754k
    sub_width_c = h266_sub_width_c[current->sps_chroma_format_idc];
1093
754k
    sub_height_c = h266_sub_height_c[current->sps_chroma_format_idc];
1094
1095
754k
    u(2, sps_log2_ctu_size_minus5, 0, 3);
1096
754k
    ctb_log2_size_y = current->sps_log2_ctu_size_minus5 + 5;
1097
754k
    ctb_size_y = 1 << ctb_log2_size_y;
1098
1099
754k
    flag(sps_ptl_dpb_hrd_params_present_flag);
1100
754k
    if (current->sps_ptl_dpb_hrd_params_present_flag) {
1101
176k
        CHECK(FUNC(profile_tier_level) (ctx, rw, &current->profile_tier_level,
1102
176k
                                        1, current->sps_max_sublayers_minus1));
1103
176k
    }
1104
706k
    flag(sps_gdr_enabled_flag);
1105
700k
    flag(sps_ref_pic_resampling_enabled_flag);
1106
700k
    if (current->sps_ref_pic_resampling_enabled_flag)
1107
700k
        flag(sps_res_change_in_clvs_allowed_flag);
1108
254k
    else
1109
254k
        infer(sps_res_change_in_clvs_allowed_flag, 0);
1110
1111
700k
    ue(sps_pic_width_max_in_luma_samples, 1, VVC_MAX_WIDTH);
1112
684k
    ue(sps_pic_height_max_in_luma_samples, 1, VVC_MAX_HEIGHT);
1113
1114
675k
    flag(sps_conformance_window_flag);
1115
673k
    if (current->sps_conformance_window_flag) {
1116
77.1k
        uint16_t width = current->sps_pic_width_max_in_luma_samples / sub_width_c;
1117
77.1k
        uint16_t height = current->sps_pic_height_max_in_luma_samples / sub_height_c;
1118
77.1k
        ue(sps_conf_win_left_offset, 0, width);
1119
75.1k
        ue(sps_conf_win_right_offset, 0, width - current->sps_conf_win_left_offset);
1120
74.3k
        ue(sps_conf_win_top_offset, 0, height);
1121
72.5k
        ue(sps_conf_win_bottom_offset, 0, height - current->sps_conf_win_top_offset);
1122
596k
    } else {
1123
596k
        infer(sps_conf_win_left_offset, 0);
1124
596k
        infer(sps_conf_win_right_offset, 0);
1125
596k
        infer(sps_conf_win_top_offset, 0);
1126
596k
        infer(sps_conf_win_bottom_offset, 0);
1127
12.7k
    }
1128
1129
667k
    tmp_width_val = AV_CEIL_RSHIFT(current->sps_pic_width_max_in_luma_samples,
1130
667k
                    ctb_log2_size_y);
1131
667k
    tmp_height_val = AV_CEIL_RSHIFT(current->sps_pic_height_max_in_luma_samples,
1132
667k
                    ctb_log2_size_y);
1133
667k
    max_width_minus1  = tmp_width_val - 1;
1134
667k
    max_height_minus1 = tmp_height_val - 1;
1135
1136
667k
    flag(sps_subpic_info_present_flag);
1137
666k
    if (current->sps_subpic_info_present_flag) {
1138
131k
        ue(sps_num_subpics_minus1, 0, VVC_MAX_SLICES - 1);
1139
129k
        if (current->sps_num_subpics_minus1 > 0) {
1140
96.7k
            flag(sps_independent_subpics_flag);
1141
96.1k
            flag(sps_subpic_same_size_flag);
1142
96.1k
        }
1143
1144
128k
        if (current->sps_num_subpics_minus1 > 0) {
1145
95.6k
            int wlen = av_ceil_log2(tmp_width_val);
1146
95.6k
            int hlen = av_ceil_log2(tmp_height_val);
1147
95.6k
            infer(sps_subpic_ctu_top_left_x[0], 0);
1148
95.6k
            infer(sps_subpic_ctu_top_left_y[0], 0);
1149
95.6k
            if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1150
95.6k
                us(wlen, sps_subpic_width_minus1[0], 0, max_width_minus1, 1, 0);
1151
49.0k
            else
1152
49.0k
                infer(sps_subpic_width_minus1[0], max_width_minus1);
1153
92.7k
            if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1154
92.7k
                us(hlen, sps_subpic_height_minus1[0], 0, max_height_minus1, 1, 0);
1155
70.2k
            else
1156
70.2k
                infer(sps_subpic_height_minus1[0], max_height_minus1);
1157
91.5k
            if (!current->sps_independent_subpics_flag) {
1158
54.3k
                flags(sps_subpic_treated_as_pic_flag[0], 1, 0);
1159
53.8k
                flags(sps_loop_filter_across_subpic_enabled_flag[0], 1, 0);
1160
53.8k
            } else {
1161
37.2k
                infer(sps_subpic_treated_as_pic_flag[0], 1);
1162
37.2k
                infer(sps_loop_filter_across_subpic_enabled_flag[0], 1);
1163
1.00k
            }
1164
1.20M
            for (i = 1; i <= current->sps_num_subpics_minus1; i++) {
1165
1.13M
                if (!current->sps_subpic_same_size_flag) {
1166
1.11M
                    const int win_right_edge =
1167
1.11M
                        current->sps_pic_width_max_in_luma_samples -
1168
1.11M
                        current->sps_conf_win_right_offset * sub_width_c;
1169
1.11M
                    const int win_bottom_edge =
1170
1.11M
                        current->sps_pic_height_max_in_luma_samples -
1171
1.11M
                        current->sps_conf_win_bottom_offset * sub_height_c;
1172
1.11M
                    const int win_left_edge =
1173
1.11M
                        current->sps_conf_win_left_offset * sub_width_c;
1174
1.11M
                    const int win_top_edge =
1175
1.11M
                        current->sps_conf_win_top_offset * sub_height_c;
1176
1.11M
                    const int win_left_edge_ctus   =
1177
1.11M
                        AV_CEIL_RSHIFT(win_left_edge,   ctb_log2_size_y);
1178
1.11M
                    const int win_right_edge_ctus  =
1179
1.11M
                        AV_CEIL_RSHIFT(win_right_edge,  ctb_log2_size_y);
1180
1.11M
                    const int win_top_edge_ctus    =
1181
1.11M
                        AV_CEIL_RSHIFT(win_top_edge,    ctb_log2_size_y);
1182
1.11M
                    const int win_bottom_edge_ctus =
1183
1.11M
                        AV_CEIL_RSHIFT(win_bottom_edge, ctb_log2_size_y);
1184
1.11M
                    const int min_width  =
1185
1.11M
                        FFMAX(win_left_edge_ctus - current->sps_subpic_ctu_top_left_x[i], 0);
1186
1.11M
                    const int min_height =
1187
1.11M
                        FFMAX(win_top_edge_ctus  - current->sps_subpic_ctu_top_left_y[i], 0);
1188
1189
1.11M
                    if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1190
1.11M
                        us(wlen, sps_subpic_ctu_top_left_x[i], 0, win_right_edge_ctus - 1, 1, i);
1191
1.04M
                    else
1192
1.04M
                        infer(sps_subpic_ctu_top_left_x[i], 0);
1193
1194
1.10M
                    if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1195
1.10M
                        us(hlen, sps_subpic_ctu_top_left_y[i], 0, win_bottom_edge_ctus - 1, 1, i);
1196
1.07M
                    else
1197
1.07M
                        infer(sps_subpic_ctu_top_left_y[i], 0);
1198
1199
1.10M
                    max_width_minus1  = tmp_width_val  - current->sps_subpic_ctu_top_left_x[i] - 1;
1200
1.10M
                    max_height_minus1 = tmp_height_val - current->sps_subpic_ctu_top_left_y[i] - 1;
1201
1202
1.10M
                    if (i < current->sps_num_subpics_minus1 &&
1203
1.04M
                        current->sps_pic_width_max_in_luma_samples > ctb_size_y) {
1204
26.8k
                        us(wlen, sps_subpic_width_minus1[i], min_width, max_width_minus1, 1, i);
1205
1.08M
                    } else {
1206
1.08M
                        infer(sps_subpic_width_minus1[i], max_width_minus1);
1207
1.08M
                    }
1208
1209
1.10M
                    if (i < current->sps_num_subpics_minus1 &&
1210
1.03M
                        current->sps_pic_height_max_in_luma_samples > ctb_size_y) {
1211
17.3k
                        us(hlen, sps_subpic_height_minus1[i], min_height, max_height_minus1, 1, i);
1212
1.08M
                    } else {
1213
1.08M
                        infer(sps_subpic_height_minus1[i], max_height_minus1);
1214
1.08M
                    }
1215
1.10M
                } else {
1216
24.8k
                    int num_subpic_cols = tmp_width_val /
1217
24.8k
                                     (current->sps_subpic_width_minus1[0] + 1);
1218
24.8k
                    if (tmp_width_val % (current->sps_subpic_width_minus1[0] + 1) ||
1219
23.6k
                        tmp_height_val % (current->sps_subpic_height_minus1[0] + 1) ||
1220
22.9k
                        current->sps_num_subpics_minus1 !=
1221
22.9k
                        (num_subpic_cols * tmp_height_val /
1222
22.9k
                         (current->sps_subpic_height_minus1[0] + 1) - 1))
1223
5.15k
                        return AVERROR_INVALIDDATA;
1224
19.7k
                    infer(sps_subpic_ctu_top_left_x[i],
1225
19.7k
                          (i % num_subpic_cols) *
1226
19.7k
                          (current->sps_subpic_width_minus1[0] + 1));
1227
19.7k
                    infer(sps_subpic_ctu_top_left_y[i],
1228
2.58k
                          (i / num_subpic_cols) *
1229
2.58k
                          (current->sps_subpic_height_minus1[0] + 1));
1230
19.7k
                    infer(sps_subpic_width_minus1[i],
1231
2.58k
                          current->sps_subpic_width_minus1[0]);
1232
19.7k
                    infer(sps_subpic_height_minus1[i],
1233
2.58k
                          current->sps_subpic_height_minus1[0]);
1234
2.58k
                }
1235
1.12M
                if (!current->sps_independent_subpics_flag) {
1236
147k
                    flags(sps_subpic_treated_as_pic_flag[i], 1, i);
1237
147k
                    flags(sps_loop_filter_across_subpic_enabled_flag[i], 1, i);
1238
974k
                } else {
1239
974k
                    infer(sps_subpic_treated_as_pic_flag[i], 1);
1240
974k
                    infer(sps_loop_filter_across_subpic_enabled_flag[i], 0);
1241
1.25k
                }
1242
1.12M
            }
1243
83.5k
        } else {
1244
32.7k
            infer(sps_subpic_ctu_top_left_x[0], 0);
1245
32.7k
            infer(sps_subpic_ctu_top_left_y[0], 0);
1246
32.7k
            infer(sps_subpic_width_minus1[0], max_width_minus1);
1247
32.7k
            infer(sps_subpic_height_minus1[0], max_height_minus1);
1248
323
        }
1249
102k
        ue(sps_subpic_id_len_minus1, 0, 15);
1250
99.6k
        if ((1 << (current->sps_subpic_id_len_minus1 + 1)) <
1251
99.6k
            current->sps_num_subpics_minus1 + 1) {
1252
4.35k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1253
4.35k
                   "sps_subpic_id_len_minus1(%d) is too small\n",
1254
4.35k
                   current->sps_subpic_id_len_minus1);
1255
4.35k
            return AVERROR_INVALIDDATA;
1256
4.35k
        }
1257
95.2k
        flag(sps_subpic_id_mapping_explicitly_signalled_flag);
1258
93.8k
        if (current->sps_subpic_id_mapping_explicitly_signalled_flag) {
1259
51.0k
            flag(sps_subpic_id_mapping_present_flag);
1260
47.1k
            if (current->sps_subpic_id_mapping_present_flag) {
1261
123k
                for (i = 0; i <= current->sps_num_subpics_minus1; i++) {
1262
96.8k
                    ubs(current->sps_subpic_id_len_minus1 + 1,
1263
96.8k
                        sps_subpic_id[i], 1, i);
1264
96.8k
                }
1265
30.3k
            }
1266
47.1k
        }
1267
535k
    } else {
1268
535k
        infer(sps_num_subpics_minus1, 0);
1269
535k
        infer(sps_independent_subpics_flag, 1);
1270
535k
        infer(sps_subpic_same_size_flag, 0);
1271
535k
        infer(sps_subpic_id_mapping_explicitly_signalled_flag, 0);
1272
535k
        infer(sps_subpic_ctu_top_left_x[0], 0);
1273
535k
        infer(sps_subpic_ctu_top_left_y[0], 0);
1274
535k
        infer(sps_subpic_width_minus1[0], max_width_minus1);
1275
535k
        infer(sps_subpic_height_minus1[0], max_height_minus1);
1276
10.9k
    }
1277
1278
1279
621k
    ue(sps_bitdepth_minus8, 0, 8);
1280
613k
    qp_bd_offset = 6 * current->sps_bitdepth_minus8;
1281
1282
613k
    flag(sps_entropy_coding_sync_enabled_flag);
1283
612k
    flag(sps_entry_point_offsets_present_flag);
1284
1285
611k
    u(4, sps_log2_max_pic_order_cnt_lsb_minus4, 0, 12);
1286
605k
    flag(sps_poc_msb_cycle_flag);
1287
604k
    if (current->sps_poc_msb_cycle_flag)
1288
604k
        ue(sps_poc_msb_cycle_len_minus1,
1289
600k
           0, 32 - current->sps_log2_max_pic_order_cnt_lsb_minus4 - 5);
1290
1291
600k
    u(2, sps_num_extra_ph_bytes, 0, 2);
1292
4.93M
    for (i = 0; i < (current->sps_num_extra_ph_bytes * 8); i++) {
1293
4.34M
        flags(sps_extra_ph_bit_present_flag[i], 1, i);
1294
4.34M
    }
1295
1296
596k
    u(2, sps_num_extra_sh_bytes, 0, 2);
1297
4.98M
    for (i = 0; i < (current->sps_num_extra_sh_bytes * 8); i++) {
1298
4.40M
        flags(sps_extra_sh_bit_present_flag[i], 1, i);
1299
4.40M
    }
1300
1301
577k
    if (current->sps_ptl_dpb_hrd_params_present_flag) {
1302
116k
        if (current->sps_max_sublayers_minus1 > 0)
1303
116k
            flag(sps_sublayer_dpb_params_flag);
1304
49.4k
        else
1305
49.4k
            infer(sps_sublayer_dpb_params_flag, 0);
1306
115k
        CHECK(FUNC(dpb_parameters) (ctx, rw, &current->sps_dpb_params,
1307
115k
                                    current->sps_max_sublayers_minus1,
1308
115k
                                    current->sps_sublayer_dpb_params_flag));
1309
115k
    }
1310
1311
571k
    ue(sps_log2_min_luma_coding_block_size_minus2,
1312
560k
       0, FFMIN(4, current->sps_log2_ctu_size_minus5 + 3));
1313
560k
    min_cb_log2_size_y =
1314
560k
        current->sps_log2_min_luma_coding_block_size_minus2 + 2;
1315
1316
560k
    flag(sps_partition_constraints_override_enabled_flag);
1317
1318
559k
    ue(sps_log2_diff_min_qt_min_cb_intra_slice_luma,
1319
543k
       0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1320
543k
    min_qt_log2_size_intra_y =
1321
543k
        current->sps_log2_diff_min_qt_min_cb_intra_slice_luma +
1322
543k
        min_cb_log2_size_y;
1323
1324
543k
    ue(sps_max_mtt_hierarchy_depth_intra_slice_luma,
1325
519k
       0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1326
1327
519k
    if (current->sps_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
1328
200k
        ue(sps_log2_diff_max_bt_min_qt_intra_slice_luma,
1329
195k
           0, ctb_log2_size_y - min_qt_log2_size_intra_y);
1330
195k
        ue(sps_log2_diff_max_tt_min_qt_intra_slice_luma,
1331
195k
           0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
1332
319k
    } else {
1333
319k
        infer(sps_log2_diff_max_bt_min_qt_intra_slice_luma, 0);
1334
319k
        infer(sps_log2_diff_max_tt_min_qt_intra_slice_luma, 0);
1335
7.01k
    }
1336
1337
507k
    if (current->sps_chroma_format_idc != 0) {
1338
339k
        flag(sps_qtbtt_dual_tree_intra_flag);
1339
339k
    } else {
1340
167k
        infer(sps_qtbtt_dual_tree_intra_flag, 0);
1341
167k
    }
1342
1343
506k
    if (current->sps_qtbtt_dual_tree_intra_flag) {
1344
196k
        ue(sps_log2_diff_min_qt_min_cb_intra_slice_chroma,
1345
194k
           0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1346
194k
        ue(sps_max_mtt_hierarchy_depth_intra_slice_chroma,
1347
193k
           0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1348
193k
        if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
1349
83.0k
            unsigned int min_qt_log2_size_intra_c =
1350
83.0k
                current->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
1351
83.0k
                min_cb_log2_size_y;
1352
83.0k
            ue(sps_log2_diff_max_bt_min_qt_intra_slice_chroma,
1353
81.5k
               0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1354
81.5k
            ue(sps_log2_diff_max_tt_min_qt_intra_slice_chroma,
1355
81.5k
               0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1356
81.5k
        }
1357
310k
    } else {
1358
310k
        infer(sps_log2_diff_min_qt_min_cb_intra_slice_chroma, 0);
1359
310k
        infer(sps_max_mtt_hierarchy_depth_intra_slice_chroma, 0);
1360
7.03k
    }
1361
499k
    if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma == 0) {
1362
420k
        infer(sps_log2_diff_max_bt_min_qt_intra_slice_chroma, 0);
1363
420k
        infer(sps_log2_diff_max_tt_min_qt_intra_slice_chroma, 0);
1364
10.3k
    }
1365
1366
499k
    ue(sps_log2_diff_min_qt_min_cb_inter_slice,
1367
495k
       0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1368
495k
    min_qt_log2_size_inter_y =
1369
495k
        current->sps_log2_diff_min_qt_min_cb_inter_slice + min_cb_log2_size_y;
1370
1371
495k
    ue(sps_max_mtt_hierarchy_depth_inter_slice,
1372
492k
       0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1373
492k
    if (current->sps_max_mtt_hierarchy_depth_inter_slice != 0) {
1374
281k
        ue(sps_log2_diff_max_bt_min_qt_inter_slice,
1375
277k
           0, ctb_log2_size_y - min_qt_log2_size_inter_y);
1376
277k
        ue(sps_log2_diff_max_tt_min_qt_inter_slice,
1377
277k
           0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
1378
277k
    } else {
1379
211k
        infer(sps_log2_diff_max_bt_min_qt_inter_slice, 0);
1380
211k
        infer(sps_log2_diff_max_tt_min_qt_inter_slice, 0);
1381
6.15k
    }
1382
1383
487k
    if (ctb_size_y > 32)
1384
487k
        flag(sps_max_luma_transform_size_64_flag);
1385
102k
    else
1386
102k
        infer(sps_max_luma_transform_size_64_flag, 0);
1387
1388
486k
    flag(sps_transform_skip_enabled_flag);
1389
485k
    if (current->sps_transform_skip_enabled_flag) {
1390
327k
        ue(sps_log2_transform_skip_max_size_minus2, 0, 3);
1391
324k
        flag(sps_bdpcm_enabled_flag);
1392
324k
    }
1393
1394
480k
    flag(sps_mts_enabled_flag);
1395
480k
    if (current->sps_mts_enabled_flag) {
1396
240k
        flag(sps_explicit_mts_intra_enabled_flag);
1397
239k
        flag(sps_explicit_mts_inter_enabled_flag);
1398
239k
    } else {
1399
239k
        infer(sps_explicit_mts_intra_enabled_flag, 0);
1400
239k
        infer(sps_explicit_mts_inter_enabled_flag, 0);
1401
4.90k
    }
1402
1403
476k
    flag(sps_lfnst_enabled_flag);
1404
1405
475k
    if (current->sps_chroma_format_idc != 0) {
1406
319k
        uint8_t num_qp_tables;
1407
319k
        flag(sps_joint_cbcr_enabled_flag);
1408
318k
        flag(sps_same_qp_table_for_chroma_flag);
1409
316k
        num_qp_tables = current->sps_same_qp_table_for_chroma_flag ?
1410
164k
            1 : (current->sps_joint_cbcr_enabled_flag ? 3 : 2);
1411
891k
        for (i = 0; i < num_qp_tables; i++) {
1412
592k
            ses(sps_qp_table_start_minus26[i], -26 - qp_bd_offset, 36, 1, i);
1413
589k
            ues(sps_num_points_in_qp_table_minus1[i],
1414
583k
                0, 36 - current->sps_qp_table_start_minus26[i], 1, i);
1415
2.09M
            for (j = 0; j <= current->sps_num_points_in_qp_table_minus1[i]; j++) {
1416
1.52M
                uint8_t max = MAX_UINT_BITS(8);
1417
1.52M
                ues(sps_delta_qp_in_val_minus1[i][j], 0, max, 2, i, j);
1418
1.51M
                ues(sps_delta_qp_diff_val[i][j], 0, max, 2, i, j);
1419
1.51M
            }
1420
583k
        }
1421
316k
    } else {
1422
156k
        infer(sps_joint_cbcr_enabled_flag, 0);
1423
156k
        infer(sps_same_qp_table_for_chroma_flag, 0);
1424
4.29k
    }
1425
1426
454k
    flag(sps_sao_enabled_flag);
1427
452k
    flag(sps_alf_enabled_flag);
1428
450k
    if (current->sps_alf_enabled_flag && current->sps_chroma_format_idc)
1429
450k
        flag(sps_ccalf_enabled_flag);
1430
258k
    else
1431
258k
        infer(sps_ccalf_enabled_flag, 0);
1432
448k
    flag(sps_lmcs_enabled_flag);
1433
447k
    flag(sps_weighted_pred_flag);
1434
446k
    flag(sps_weighted_bipred_flag);
1435
444k
    flag(sps_long_term_ref_pics_flag);
1436
444k
    if (current->sps_video_parameter_set_id > 0)
1437
444k
        flag(sps_inter_layer_prediction_enabled_flag);
1438
343k
    else
1439
343k
        infer(sps_inter_layer_prediction_enabled_flag, 0);
1440
443k
    flag(sps_idr_rpl_present_flag);
1441
442k
    flag(sps_rpl1_same_as_rpl0_flag);
1442
1443
1.03M
    for (i = 0; i < (current->sps_rpl1_same_as_rpl0_flag ? 1 : 2); i++) {
1444
645k
        ues(sps_num_ref_pic_lists[i], 0, VVC_MAX_REF_PIC_LISTS, 1, i);
1445
2.71M
        for (j = 0; j < current->sps_num_ref_pic_lists[i]; j++)
1446
2.12M
            CHECK(FUNC(ref_pic_list_struct) (ctx, rw,
1447
643k
                                             &current->
1448
643k
                                             sps_ref_pic_list_struct[i][j], i,
1449
643k
                                             j, current));
1450
643k
    }
1451
1452
386k
    if (current->sps_rpl1_same_as_rpl0_flag) {
1453
197k
        current->sps_num_ref_pic_lists[1] = current->sps_num_ref_pic_lists[0];
1454
474k
        for (j = 0; j < current->sps_num_ref_pic_lists[0]; j++)
1455
277k
            memcpy(&current->sps_ref_pic_list_struct[1][j],
1456
277k
                   &current->sps_ref_pic_list_struct[0][j],
1457
277k
                   sizeof(current->sps_ref_pic_list_struct[0][j]));
1458
197k
    }
1459
1460
386k
    flag(sps_ref_wraparound_enabled_flag);
1461
1462
383k
    flag(sps_temporal_mvp_enabled_flag);
1463
382k
    if (current->sps_temporal_mvp_enabled_flag)
1464
382k
        flag(sps_sbtmvp_enabled_flag);
1465
110k
    else
1466
110k
        infer(sps_sbtmvp_enabled_flag, 0);
1467
1468
375k
    flag(sps_amvr_enabled_flag);
1469
373k
    flag(sps_bdof_enabled_flag);
1470
372k
    if (current->sps_bdof_enabled_flag)
1471
372k
        flag(sps_bdof_control_present_in_ph_flag);
1472
182k
    else
1473
182k
        infer(sps_bdof_control_present_in_ph_flag, 0);
1474
1475
371k
    flag(sps_smvd_enabled_flag);
1476
368k
    flag(sps_dmvr_enabled_flag);
1477
367k
    if (current->sps_dmvr_enabled_flag)
1478
367k
        flag(sps_dmvr_control_present_in_ph_flag);
1479
119k
    else
1480
119k
        infer(sps_dmvr_control_present_in_ph_flag, 0);
1481
1482
366k
    flag(sps_mmvd_enabled_flag);
1483
365k
    if (current->sps_mmvd_enabled_flag)
1484
365k
        flag(sps_mmvd_fullpel_only_enabled_flag);
1485
150k
    else
1486
150k
        infer(sps_mmvd_fullpel_only_enabled_flag, 0);
1487
1488
364k
    ue(sps_six_minus_max_num_merge_cand, 0, 5);
1489
347k
    max_num_merge_cand = 6 - current->sps_six_minus_max_num_merge_cand;
1490
1491
347k
    flag(sps_sbt_enabled_flag);
1492
1493
346k
    flag(sps_affine_enabled_flag);
1494
343k
    if (current->sps_affine_enabled_flag) {
1495
198k
        ue(sps_five_minus_max_num_subblock_merge_cand,
1496
194k
           0, 5 - current->sps_sbtmvp_enabled_flag);
1497
194k
        flag(sps_6param_affine_enabled_flag);
1498
193k
        if (current->sps_amvr_enabled_flag)
1499
193k
            flag(sps_affine_amvr_enabled_flag);
1500
42.6k
        else
1501
42.6k
            infer(sps_affine_amvr_enabled_flag, 0);
1502
192k
        flag(sps_affine_prof_enabled_flag);
1503
191k
        if (current->sps_affine_prof_enabled_flag)
1504
191k
            flag(sps_prof_control_present_in_ph_flag);
1505
51.4k
        else
1506
51.4k
            infer(sps_prof_control_present_in_ph_flag, 0);
1507
191k
    } else {
1508
145k
        infer(sps_6param_affine_enabled_flag, 0);
1509
145k
        infer(sps_affine_amvr_enabled_flag, 0);
1510
145k
        infer(sps_affine_prof_enabled_flag, 0);
1511
145k
        infer(sps_prof_control_present_in_ph_flag, 0);
1512
3.62k
    }
1513
1514
336k
    flag(sps_bcw_enabled_flag);
1515
335k
    flag(sps_ciip_enabled_flag);
1516
1517
334k
    if (max_num_merge_cand >= 2) {
1518
327k
        flag(sps_gpm_enabled_flag);
1519
326k
        if (current->sps_gpm_enabled_flag && max_num_merge_cand >= 3)
1520
326k
            ue(sps_max_num_merge_cand_minus_max_num_gpm_cand,
1521
326k
               0, max_num_merge_cand - 2);
1522
326k
    } else {
1523
7.26k
        infer(sps_gpm_enabled_flag, 0);
1524
7.26k
    }
1525
1526
331k
    ue(sps_log2_parallel_merge_level_minus2, 0, ctb_log2_size_y - 2);
1527
1528
326k
    flag(sps_isp_enabled_flag);
1529
325k
    flag(sps_mrl_enabled_flag);
1530
323k
    flag(sps_mip_enabled_flag);
1531
1532
319k
    if (current->sps_chroma_format_idc != 0)
1533
319k
        flag(sps_cclm_enabled_flag);
1534
62.4k
    else
1535
62.4k
        infer(sps_cclm_enabled_flag, 0);
1536
318k
    if (current->sps_chroma_format_idc == 1) {
1537
198k
        flag(sps_chroma_horizontal_collocated_flag);
1538
197k
        flag(sps_chroma_vertical_collocated_flag);
1539
197k
    } else {
1540
120k
        infer(sps_chroma_horizontal_collocated_flag, 1);
1541
120k
        infer(sps_chroma_vertical_collocated_flag, 1);
1542
6.17k
    }
1543
1544
317k
    flag(sps_palette_enabled_flag);
1545
314k
    if (current->sps_chroma_format_idc == 3 &&
1546
43.9k
        !current->sps_max_luma_transform_size_64_flag)
1547
314k
        flag(sps_act_enabled_flag);
1548
294k
    else
1549
294k
        infer(sps_act_enabled_flag, 0);
1550
314k
    if (current->sps_transform_skip_enabled_flag ||
1551
98.2k
        current->sps_palette_enabled_flag)
1552
314k
        ue(sps_min_qp_prime_ts, 0, 8);
1553
1554
311k
    flag(sps_ibc_enabled_flag);
1555
308k
    if (current->sps_ibc_enabled_flag)
1556
308k
        ue(sps_six_minus_max_num_ibc_merge_cand, 0, 5);
1557
1558
306k
    flag(sps_ladf_enabled_flag);
1559
306k
    if (current->sps_ladf_enabled_flag) {
1560
146k
        ub(2, sps_num_ladf_intervals_minus2);
1561
145k
        se(sps_ladf_lowest_interval_qp_offset, -63, 63);
1562
563k
        for (i = 0; i < current->sps_num_ladf_intervals_minus2 + 1; i++) {
1563
424k
            ses(sps_ladf_qp_offset[i], -63, 63, 1, i);
1564
421k
            ues(sps_ladf_delta_threshold_minus1[i],
1565
421k
                0, (2 << (8 + current->sps_bitdepth_minus8)) - 3, 1, i);
1566
421k
        }
1567
143k
    }
1568
1569
298k
    flag(sps_explicit_scaling_list_enabled_flag);
1570
294k
    if (current->sps_lfnst_enabled_flag &&
1571
129k
        current->sps_explicit_scaling_list_enabled_flag)
1572
294k
        flag(sps_scaling_matrix_for_lfnst_disabled_flag);
1573
1574
293k
    if (current->sps_act_enabled_flag &&
1575
15.1k
        current->sps_explicit_scaling_list_enabled_flag)
1576
293k
        flag(sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
1577
284k
    else
1578
284k
        infer(sps_scaling_matrix_for_alternative_colour_space_disabled_flag, 0);
1579
293k
    if (current->sps_scaling_matrix_for_alternative_colour_space_disabled_flag)
1580
293k
        flag(sps_scaling_matrix_designated_colour_space_flag);
1581
1582
292k
    flag(sps_dep_quant_enabled_flag);
1583
291k
    flag(sps_sign_data_hiding_enabled_flag);
1584
1585
291k
    flag(sps_virtual_boundaries_enabled_flag);
1586
288k
    if (current->sps_virtual_boundaries_enabled_flag) {
1587
135k
        flag(sps_virtual_boundaries_present_flag);
1588
134k
        if (current->sps_virtual_boundaries_present_flag) {
1589
71.3k
            ue(sps_num_ver_virtual_boundaries,
1590
69.8k
               0, current->sps_pic_width_max_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
1591
84.7k
            for (i = 0; i < current->sps_num_ver_virtual_boundaries; i++)
1592
69.8k
                ues(sps_virtual_boundary_pos_x_minus1[i],
1593
69.1k
                    0, (current->sps_pic_width_max_in_luma_samples + 7) / 8 - 2,
1594
69.1k
                    1, i);
1595
69.1k
            ue(sps_num_hor_virtual_boundaries,
1596
66.0k
               0, current->sps_pic_height_max_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
1597
89.9k
            for (i = 0; i < current->sps_num_hor_virtual_boundaries; i++)
1598
66.0k
                ues(sps_virtual_boundary_pos_y_minus1[i],
1599
66.0k
                    0, (current->sps_pic_height_max_in_luma_samples + 7) /
1600
66.0k
                    8 - 2, 1, i);
1601
66.0k
        }
1602
152k
    } else {
1603
152k
        infer(sps_virtual_boundaries_present_flag, 0);
1604
152k
        infer(sps_num_ver_virtual_boundaries, 0);
1605
152k
        infer(sps_num_hor_virtual_boundaries, 0);
1606
7.90k
    }
1607
1608
281k
    if (current->sps_ptl_dpb_hrd_params_present_flag) {
1609
78.0k
        flag(sps_timing_hrd_params_present_flag);
1610
77.5k
        if (current->sps_timing_hrd_params_present_flag) {
1611
27.7k
            uint8_t first_sublayer;
1612
27.7k
            CHECK(FUNC(general_timing_hrd_parameters) (ctx, rw,
1613
27.7k
                &current->sps_general_timing_hrd_parameters));
1614
20.6k
            if (current->sps_max_sublayers_minus1 > 0)
1615
20.6k
                flag(sps_sublayer_cpb_params_present_flag);
1616
8.94k
            else
1617
8.94k
                infer(sps_sublayer_cpb_params_present_flag, 0);
1618
20.2k
            first_sublayer = current->sps_sublayer_cpb_params_present_flag ?
1619
13.5k
                0 : current->sps_max_sublayers_minus1;
1620
20.2k
            CHECK(FUNC(ols_timing_hrd_parameters) (ctx, rw,
1621
20.2k
                &current->sps_ols_timing_hrd_parameters, first_sublayer,
1622
20.2k
                current->sps_max_sublayers_minus1,
1623
20.2k
                &current->sps_general_timing_hrd_parameters));
1624
20.2k
        }
1625
77.5k
    }
1626
1627
270k
    flag(sps_field_seq_flag);
1628
269k
    flag(sps_vui_parameters_present_flag);
1629
267k
    if (current->sps_vui_parameters_present_flag) {
1630
93.3k
        ue(sps_vui_payload_size_minus1, 0, 1023);
1631
159k
        while (byte_alignment(rw) != 0)
1632
89.5k
            fixed(1, sps_vui_alignment_zero_bit, 0);
1633
70.0k
        CHECK(FUNC(vui_payload) (ctx, rw, &current->vui,
1634
70.0k
                                 current->sps_vui_payload_size_minus1 + 1,
1635
70.0k
                                 current->sps_chroma_format_idc));
1636
174k
    } else {
1637
174k
        CHECK(FUNC(vui_parameters_default) (ctx, rw, &current->vui));
1638
174k
    }
1639
1640
228k
    flag(sps_extension_flag);
1641
226k
    if (current->sps_extension_flag) {
1642
167k
        flag(sps_range_extension_flag);
1643
166k
        ub(7, sps_extension_7bits);
1644
1645
163k
        if (current->sps_range_extension_flag) {
1646
30.6k
            if (current->sps_bitdepth_minus8 <= 10 - 8)
1647
18.1k
                return AVERROR_INVALIDDATA;
1648
12.4k
            CHECK(FUNC(sps_range_extension)(ctx, rw, current));
1649
132k
        } else {
1650
132k
            infer(sps_extended_precision_flag, 0);
1651
132k
            infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1652
132k
            infer(sps_rrc_rice_extension_flag, 0);
1653
132k
            infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1654
132k
            infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1655
8.88k
        }
1656
163k
    } else {
1657
58.9k
        infer(sps_range_extension_flag, 0);
1658
58.9k
        infer(sps_extension_7bits, 0);
1659
58.9k
        infer(sps_extended_precision_flag, 0);
1660
58.9k
        infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1661
58.9k
        infer(sps_rrc_rice_extension_flag, 0);
1662
58.9k
        infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1663
58.9k
        infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1664
4.42k
    }
1665
1666
202k
    if (current->sps_extension_7bits)
1667
143k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1668
1669
202k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
1670
1671
186k
    return 0;
1672
202k
}
cbs_h266.c:cbs_h266_read_sps
Line
Count
Source
1058
760k
{
1059
760k
    CodedBitstreamH266Context *h266 = ctx->priv_data;
1060
760k
    int err, i, j, max_width_minus1, max_height_minus1;
1061
760k
    unsigned int ctb_log2_size_y, min_cb_log2_size_y,
1062
760k
                 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y,
1063
760k
                 ctb_size_y, max_num_merge_cand, tmp_width_val, tmp_height_val;
1064
760k
    uint8_t qp_bd_offset, sub_width_c, sub_height_c;
1065
1066
760k
    static const uint8_t h266_sub_width_c[] = {
1067
760k
        1, 2, 2, 1
1068
760k
    };
1069
760k
    static const uint8_t h266_sub_height_c[] = {
1070
760k
        1, 2, 1, 1
1071
760k
    };
1072
1073
760k
    HEADER("Sequence Parameter Set");
1074
1075
760k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
1076
760k
                                 &current->nal_unit_header, VVC_SPS_NUT));
1077
1078
757k
    ub(4, sps_seq_parameter_set_id);
1079
752k
    ub(4, sps_video_parameter_set_id);
1080
752k
    if (current->sps_video_parameter_set_id == 0 && !h266->vps[0]) {
1081
25.1k
        H266RawVPS *vps = av_refstruct_allocz(sizeof(*vps));
1082
25.1k
        if (!vps)
1083
0
            return AVERROR(ENOMEM);
1084
25.1k
        vps->vps_max_layers_minus1 = 0;
1085
25.1k
        vps->vps_independent_layer_flag[0] = 1;
1086
25.1k
        vps->vps_layer_id[0] = current->nal_unit_header.nuh_layer_id;
1087
25.1k
        h266->vps[0] = vps;
1088
25.1k
    }
1089
1090
752k
    u(3, sps_max_sublayers_minus1, 0, VVC_MAX_SUBLAYERS - 1);
1091
740k
    u(2, sps_chroma_format_idc, 0, 3);
1092
740k
    sub_width_c = h266_sub_width_c[current->sps_chroma_format_idc];
1093
740k
    sub_height_c = h266_sub_height_c[current->sps_chroma_format_idc];
1094
1095
740k
    u(2, sps_log2_ctu_size_minus5, 0, 3);
1096
740k
    ctb_log2_size_y = current->sps_log2_ctu_size_minus5 + 5;
1097
740k
    ctb_size_y = 1 << ctb_log2_size_y;
1098
1099
740k
    flag(sps_ptl_dpb_hrd_params_present_flag);
1100
740k
    if (current->sps_ptl_dpb_hrd_params_present_flag) {
1101
170k
        CHECK(FUNC(profile_tier_level) (ctx, rw, &current->profile_tier_level,
1102
170k
                                        1, current->sps_max_sublayers_minus1));
1103
170k
    }
1104
691k
    flag(sps_gdr_enabled_flag);
1105
685k
    flag(sps_ref_pic_resampling_enabled_flag);
1106
685k
    if (current->sps_ref_pic_resampling_enabled_flag)
1107
685k
        flag(sps_res_change_in_clvs_allowed_flag);
1108
250k
    else
1109
250k
        infer(sps_res_change_in_clvs_allowed_flag, 0);
1110
1111
685k
    ue(sps_pic_width_max_in_luma_samples, 1, VVC_MAX_WIDTH);
1112
670k
    ue(sps_pic_height_max_in_luma_samples, 1, VVC_MAX_HEIGHT);
1113
1114
660k
    flag(sps_conformance_window_flag);
1115
659k
    if (current->sps_conformance_window_flag) {
1116
75.5k
        uint16_t width = current->sps_pic_width_max_in_luma_samples / sub_width_c;
1117
75.5k
        uint16_t height = current->sps_pic_height_max_in_luma_samples / sub_height_c;
1118
75.5k
        ue(sps_conf_win_left_offset, 0, width);
1119
73.6k
        ue(sps_conf_win_right_offset, 0, width - current->sps_conf_win_left_offset);
1120
72.7k
        ue(sps_conf_win_top_offset, 0, height);
1121
70.9k
        ue(sps_conf_win_bottom_offset, 0, height - current->sps_conf_win_top_offset);
1122
583k
    } else {
1123
583k
        infer(sps_conf_win_left_offset, 0);
1124
583k
        infer(sps_conf_win_right_offset, 0);
1125
583k
        infer(sps_conf_win_top_offset, 0);
1126
583k
        infer(sps_conf_win_bottom_offset, 0);
1127
583k
    }
1128
1129
653k
    tmp_width_val = AV_CEIL_RSHIFT(current->sps_pic_width_max_in_luma_samples,
1130
653k
                    ctb_log2_size_y);
1131
653k
    tmp_height_val = AV_CEIL_RSHIFT(current->sps_pic_height_max_in_luma_samples,
1132
653k
                    ctb_log2_size_y);
1133
653k
    max_width_minus1  = tmp_width_val - 1;
1134
653k
    max_height_minus1 = tmp_height_val - 1;
1135
1136
653k
    flag(sps_subpic_info_present_flag);
1137
652k
    if (current->sps_subpic_info_present_flag) {
1138
128k
        ue(sps_num_subpics_minus1, 0, VVC_MAX_SLICES - 1);
1139
126k
        if (current->sps_num_subpics_minus1 > 0) {
1140
93.7k
            flag(sps_independent_subpics_flag);
1141
93.1k
            flag(sps_subpic_same_size_flag);
1142
93.1k
        }
1143
1144
125k
        if (current->sps_num_subpics_minus1 > 0) {
1145
92.6k
            int wlen = av_ceil_log2(tmp_width_val);
1146
92.6k
            int hlen = av_ceil_log2(tmp_height_val);
1147
92.6k
            infer(sps_subpic_ctu_top_left_x[0], 0);
1148
92.6k
            infer(sps_subpic_ctu_top_left_y[0], 0);
1149
92.6k
            if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1150
92.6k
                us(wlen, sps_subpic_width_minus1[0], 0, max_width_minus1, 1, 0);
1151
47.8k
            else
1152
47.8k
                infer(sps_subpic_width_minus1[0], max_width_minus1);
1153
89.7k
            if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1154
89.7k
                us(hlen, sps_subpic_height_minus1[0], 0, max_height_minus1, 1, 0);
1155
68.7k
            else
1156
68.7k
                infer(sps_subpic_height_minus1[0], max_height_minus1);
1157
88.5k
            if (!current->sps_independent_subpics_flag) {
1158
52.3k
                flags(sps_subpic_treated_as_pic_flag[0], 1, 0);
1159
51.8k
                flags(sps_loop_filter_across_subpic_enabled_flag[0], 1, 0);
1160
51.8k
            } else {
1161
36.2k
                infer(sps_subpic_treated_as_pic_flag[0], 1);
1162
36.2k
                infer(sps_loop_filter_across_subpic_enabled_flag[0], 1);
1163
36.2k
            }
1164
1.19M
            for (i = 1; i <= current->sps_num_subpics_minus1; i++) {
1165
1.12M
                if (!current->sps_subpic_same_size_flag) {
1166
1.10M
                    const int win_right_edge =
1167
1.10M
                        current->sps_pic_width_max_in_luma_samples -
1168
1.10M
                        current->sps_conf_win_right_offset * sub_width_c;
1169
1.10M
                    const int win_bottom_edge =
1170
1.10M
                        current->sps_pic_height_max_in_luma_samples -
1171
1.10M
                        current->sps_conf_win_bottom_offset * sub_height_c;
1172
1.10M
                    const int win_left_edge =
1173
1.10M
                        current->sps_conf_win_left_offset * sub_width_c;
1174
1.10M
                    const int win_top_edge =
1175
1.10M
                        current->sps_conf_win_top_offset * sub_height_c;
1176
1.10M
                    const int win_left_edge_ctus   =
1177
1.10M
                        AV_CEIL_RSHIFT(win_left_edge,   ctb_log2_size_y);
1178
1.10M
                    const int win_right_edge_ctus  =
1179
1.10M
                        AV_CEIL_RSHIFT(win_right_edge,  ctb_log2_size_y);
1180
1.10M
                    const int win_top_edge_ctus    =
1181
1.10M
                        AV_CEIL_RSHIFT(win_top_edge,    ctb_log2_size_y);
1182
1.10M
                    const int win_bottom_edge_ctus =
1183
1.10M
                        AV_CEIL_RSHIFT(win_bottom_edge, ctb_log2_size_y);
1184
1.10M
                    const int min_width  =
1185
1.10M
                        FFMAX(win_left_edge_ctus - current->sps_subpic_ctu_top_left_x[i], 0);
1186
1.10M
                    const int min_height =
1187
1.10M
                        FFMAX(win_top_edge_ctus  - current->sps_subpic_ctu_top_left_y[i], 0);
1188
1189
1.10M
                    if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1190
1.10M
                        us(wlen, sps_subpic_ctu_top_left_x[i], 0, win_right_edge_ctus - 1, 1, i);
1191
1.04M
                    else
1192
1.04M
                        infer(sps_subpic_ctu_top_left_x[i], 0);
1193
1194
1.10M
                    if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1195
1.10M
                        us(hlen, sps_subpic_ctu_top_left_y[i], 0, win_bottom_edge_ctus - 1, 1, i);
1196
1.07M
                    else
1197
1.07M
                        infer(sps_subpic_ctu_top_left_y[i], 0);
1198
1199
1.10M
                    max_width_minus1  = tmp_width_val  - current->sps_subpic_ctu_top_left_x[i] - 1;
1200
1.10M
                    max_height_minus1 = tmp_height_val - current->sps_subpic_ctu_top_left_y[i] - 1;
1201
1202
1.10M
                    if (i < current->sps_num_subpics_minus1 &&
1203
1.03M
                        current->sps_pic_width_max_in_luma_samples > ctb_size_y) {
1204
25.5k
                        us(wlen, sps_subpic_width_minus1[i], min_width, max_width_minus1, 1, i);
1205
1.07M
                    } else {
1206
1.07M
                        infer(sps_subpic_width_minus1[i], max_width_minus1);
1207
1.07M
                    }
1208
1209
1.10M
                    if (i < current->sps_num_subpics_minus1 &&
1210
1.03M
                        current->sps_pic_height_max_in_luma_samples > ctb_size_y) {
1211
15.9k
                        us(hlen, sps_subpic_height_minus1[i], min_height, max_height_minus1, 1, i);
1212
1.08M
                    } else {
1213
1.08M
                        infer(sps_subpic_height_minus1[i], max_height_minus1);
1214
1.08M
                    }
1215
1.10M
                } else {
1216
22.3k
                    int num_subpic_cols = tmp_width_val /
1217
22.3k
                                     (current->sps_subpic_width_minus1[0] + 1);
1218
22.3k
                    if (tmp_width_val % (current->sps_subpic_width_minus1[0] + 1) ||
1219
21.1k
                        tmp_height_val % (current->sps_subpic_height_minus1[0] + 1) ||
1220
20.3k
                        current->sps_num_subpics_minus1 !=
1221
20.3k
                        (num_subpic_cols * tmp_height_val /
1222
20.3k
                         (current->sps_subpic_height_minus1[0] + 1) - 1))
1223
5.15k
                        return AVERROR_INVALIDDATA;
1224
17.1k
                    infer(sps_subpic_ctu_top_left_x[i],
1225
17.1k
                          (i % num_subpic_cols) *
1226
17.1k
                          (current->sps_subpic_width_minus1[0] + 1));
1227
17.1k
                    infer(sps_subpic_ctu_top_left_y[i],
1228
17.1k
                          (i / num_subpic_cols) *
1229
17.1k
                          (current->sps_subpic_height_minus1[0] + 1));
1230
17.1k
                    infer(sps_subpic_width_minus1[i],
1231
17.1k
                          current->sps_subpic_width_minus1[0]);
1232
17.1k
                    infer(sps_subpic_height_minus1[i],
1233
17.1k
                          current->sps_subpic_height_minus1[0]);
1234
17.1k
                }
1235
1.11M
                if (!current->sps_independent_subpics_flag) {
1236
141k
                    flags(sps_subpic_treated_as_pic_flag[i], 1, i);
1237
141k
                    flags(sps_loop_filter_across_subpic_enabled_flag[i], 1, i);
1238
973k
                } else {
1239
973k
                    infer(sps_subpic_treated_as_pic_flag[i], 1);
1240
973k
                    infer(sps_loop_filter_across_subpic_enabled_flag[i], 0);
1241
973k
                }
1242
1.11M
            }
1243
80.5k
        } else {
1244
32.3k
            infer(sps_subpic_ctu_top_left_x[0], 0);
1245
32.3k
            infer(sps_subpic_ctu_top_left_y[0], 0);
1246
32.3k
            infer(sps_subpic_width_minus1[0], max_width_minus1);
1247
32.3k
            infer(sps_subpic_height_minus1[0], max_height_minus1);
1248
32.3k
        }
1249
99.3k
        ue(sps_subpic_id_len_minus1, 0, 15);
1250
96.3k
        if ((1 << (current->sps_subpic_id_len_minus1 + 1)) <
1251
96.3k
            current->sps_num_subpics_minus1 + 1) {
1252
4.35k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1253
4.35k
                   "sps_subpic_id_len_minus1(%d) is too small\n",
1254
4.35k
                   current->sps_subpic_id_len_minus1);
1255
4.35k
            return AVERROR_INVALIDDATA;
1256
4.35k
        }
1257
91.9k
        flag(sps_subpic_id_mapping_explicitly_signalled_flag);
1258
90.5k
        if (current->sps_subpic_id_mapping_explicitly_signalled_flag) {
1259
49.3k
            flag(sps_subpic_id_mapping_present_flag);
1260
45.4k
            if (current->sps_subpic_id_mapping_present_flag) {
1261
119k
                for (i = 0; i <= current->sps_num_subpics_minus1; i++) {
1262
93.8k
                    ubs(current->sps_subpic_id_len_minus1 + 1,
1263
93.8k
                        sps_subpic_id[i], 1, i);
1264
93.8k
                }
1265
29.5k
            }
1266
45.4k
        }
1267
524k
    } else {
1268
524k
        infer(sps_num_subpics_minus1, 0);
1269
524k
        infer(sps_independent_subpics_flag, 1);
1270
524k
        infer(sps_subpic_same_size_flag, 0);
1271
524k
        infer(sps_subpic_id_mapping_explicitly_signalled_flag, 0);
1272
524k
        infer(sps_subpic_ctu_top_left_x[0], 0);
1273
524k
        infer(sps_subpic_ctu_top_left_y[0], 0);
1274
524k
        infer(sps_subpic_width_minus1[0], max_width_minus1);
1275
524k
        infer(sps_subpic_height_minus1[0], max_height_minus1);
1276
524k
    }
1277
1278
1279
607k
    ue(sps_bitdepth_minus8, 0, 8);
1280
599k
    qp_bd_offset = 6 * current->sps_bitdepth_minus8;
1281
1282
599k
    flag(sps_entropy_coding_sync_enabled_flag);
1283
598k
    flag(sps_entry_point_offsets_present_flag);
1284
1285
597k
    u(4, sps_log2_max_pic_order_cnt_lsb_minus4, 0, 12);
1286
591k
    flag(sps_poc_msb_cycle_flag);
1287
590k
    if (current->sps_poc_msb_cycle_flag)
1288
590k
        ue(sps_poc_msb_cycle_len_minus1,
1289
586k
           0, 32 - current->sps_log2_max_pic_order_cnt_lsb_minus4 - 5);
1290
1291
586k
    u(2, sps_num_extra_ph_bytes, 0, 2);
1292
4.83M
    for (i = 0; i < (current->sps_num_extra_ph_bytes * 8); i++) {
1293
4.24M
        flags(sps_extra_ph_bit_present_flag[i], 1, i);
1294
4.24M
    }
1295
1296
581k
    u(2, sps_num_extra_sh_bytes, 0, 2);
1297
4.85M
    for (i = 0; i < (current->sps_num_extra_sh_bytes * 8); i++) {
1298
4.29M
        flags(sps_extra_sh_bit_present_flag[i], 1, i);
1299
4.29M
    }
1300
1301
562k
    if (current->sps_ptl_dpb_hrd_params_present_flag) {
1302
110k
        if (current->sps_max_sublayers_minus1 > 0)
1303
110k
            flag(sps_sublayer_dpb_params_flag);
1304
47.3k
        else
1305
47.3k
            infer(sps_sublayer_dpb_params_flag, 0);
1306
109k
        CHECK(FUNC(dpb_parameters) (ctx, rw, &current->sps_dpb_params,
1307
109k
                                    current->sps_max_sublayers_minus1,
1308
109k
                                    current->sps_sublayer_dpb_params_flag));
1309
109k
    }
1310
1311
557k
    ue(sps_log2_min_luma_coding_block_size_minus2,
1312
546k
       0, FFMIN(4, current->sps_log2_ctu_size_minus5 + 3));
1313
546k
    min_cb_log2_size_y =
1314
546k
        current->sps_log2_min_luma_coding_block_size_minus2 + 2;
1315
1316
546k
    flag(sps_partition_constraints_override_enabled_flag);
1317
1318
545k
    ue(sps_log2_diff_min_qt_min_cb_intra_slice_luma,
1319
529k
       0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1320
529k
    min_qt_log2_size_intra_y =
1321
529k
        current->sps_log2_diff_min_qt_min_cb_intra_slice_luma +
1322
529k
        min_cb_log2_size_y;
1323
1324
529k
    ue(sps_max_mtt_hierarchy_depth_intra_slice_luma,
1325
505k
       0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1326
1327
505k
    if (current->sps_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
1328
193k
        ue(sps_log2_diff_max_bt_min_qt_intra_slice_luma,
1329
188k
           0, ctb_log2_size_y - min_qt_log2_size_intra_y);
1330
188k
        ue(sps_log2_diff_max_tt_min_qt_intra_slice_luma,
1331
188k
           0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
1332
312k
    } else {
1333
312k
        infer(sps_log2_diff_max_bt_min_qt_intra_slice_luma, 0);
1334
312k
        infer(sps_log2_diff_max_tt_min_qt_intra_slice_luma, 0);
1335
312k
    }
1336
1337
493k
    if (current->sps_chroma_format_idc != 0) {
1338
329k
        flag(sps_qtbtt_dual_tree_intra_flag);
1339
329k
    } else {
1340
163k
        infer(sps_qtbtt_dual_tree_intra_flag, 0);
1341
163k
    }
1342
1343
492k
    if (current->sps_qtbtt_dual_tree_intra_flag) {
1344
189k
        ue(sps_log2_diff_min_qt_min_cb_intra_slice_chroma,
1345
187k
           0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1346
187k
        ue(sps_max_mtt_hierarchy_depth_intra_slice_chroma,
1347
186k
           0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1348
186k
        if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
1349
79.0k
            unsigned int min_qt_log2_size_intra_c =
1350
79.0k
                current->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
1351
79.0k
                min_cb_log2_size_y;
1352
79.0k
            ue(sps_log2_diff_max_bt_min_qt_intra_slice_chroma,
1353
77.6k
               0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1354
77.6k
            ue(sps_log2_diff_max_tt_min_qt_intra_slice_chroma,
1355
77.6k
               0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1356
77.6k
        }
1357
303k
    } else {
1358
303k
        infer(sps_log2_diff_min_qt_min_cb_intra_slice_chroma, 0);
1359
303k
        infer(sps_max_mtt_hierarchy_depth_intra_slice_chroma, 0);
1360
303k
    }
1361
485k
    if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma == 0) {
1362
410k
        infer(sps_log2_diff_max_bt_min_qt_intra_slice_chroma, 0);
1363
410k
        infer(sps_log2_diff_max_tt_min_qt_intra_slice_chroma, 0);
1364
410k
    }
1365
1366
485k
    ue(sps_log2_diff_min_qt_min_cb_inter_slice,
1367
481k
       0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1368
481k
    min_qt_log2_size_inter_y =
1369
481k
        current->sps_log2_diff_min_qt_min_cb_inter_slice + min_cb_log2_size_y;
1370
1371
481k
    ue(sps_max_mtt_hierarchy_depth_inter_slice,
1372
478k
       0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1373
478k
    if (current->sps_max_mtt_hierarchy_depth_inter_slice != 0) {
1374
273k
        ue(sps_log2_diff_max_bt_min_qt_inter_slice,
1375
269k
           0, ctb_log2_size_y - min_qt_log2_size_inter_y);
1376
269k
        ue(sps_log2_diff_max_tt_min_qt_inter_slice,
1377
269k
           0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
1378
269k
    } else {
1379
205k
        infer(sps_log2_diff_max_bt_min_qt_inter_slice, 0);
1380
205k
        infer(sps_log2_diff_max_tt_min_qt_inter_slice, 0);
1381
205k
    }
1382
1383
473k
    if (ctb_size_y > 32)
1384
473k
        flag(sps_max_luma_transform_size_64_flag);
1385
97.9k
    else
1386
97.9k
        infer(sps_max_luma_transform_size_64_flag, 0);
1387
1388
472k
    flag(sps_transform_skip_enabled_flag);
1389
471k
    if (current->sps_transform_skip_enabled_flag) {
1390
317k
        ue(sps_log2_transform_skip_max_size_minus2, 0, 3);
1391
313k
        flag(sps_bdpcm_enabled_flag);
1392
313k
    }
1393
1394
466k
    flag(sps_mts_enabled_flag);
1395
465k
    if (current->sps_mts_enabled_flag) {
1396
230k
        flag(sps_explicit_mts_intra_enabled_flag);
1397
230k
        flag(sps_explicit_mts_inter_enabled_flag);
1398
235k
    } else {
1399
235k
        infer(sps_explicit_mts_intra_enabled_flag, 0);
1400
235k
        infer(sps_explicit_mts_inter_enabled_flag, 0);
1401
235k
    }
1402
1403
462k
    flag(sps_lfnst_enabled_flag);
1404
1405
460k
    if (current->sps_chroma_format_idc != 0) {
1406
309k
        uint8_t num_qp_tables;
1407
309k
        flag(sps_joint_cbcr_enabled_flag);
1408
308k
        flag(sps_same_qp_table_for_chroma_flag);
1409
306k
        num_qp_tables = current->sps_same_qp_table_for_chroma_flag ?
1410
162k
            1 : (current->sps_joint_cbcr_enabled_flag ? 3 : 2);
1411
868k
        for (i = 0; i < num_qp_tables; i++) {
1412
579k
            ses(sps_qp_table_start_minus26[i], -26 - qp_bd_offset, 36, 1, i);
1413
576k
            ues(sps_num_points_in_qp_table_minus1[i],
1414
570k
                0, 36 - current->sps_qp_table_start_minus26[i], 1, i);
1415
2.05M
            for (j = 0; j <= current->sps_num_points_in_qp_table_minus1[i]; j++) {
1416
1.49M
                uint8_t max = MAX_UINT_BITS(8);
1417
1.49M
                ues(sps_delta_qp_in_val_minus1[i][j], 0, max, 2, i, j);
1418
1.48M
                ues(sps_delta_qp_diff_val[i][j], 0, max, 2, i, j);
1419
1.48M
            }
1420
570k
        }
1421
306k
    } else {
1422
151k
        infer(sps_joint_cbcr_enabled_flag, 0);
1423
151k
        infer(sps_same_qp_table_for_chroma_flag, 0);
1424
151k
    }
1425
1426
440k
    flag(sps_sao_enabled_flag);
1427
437k
    flag(sps_alf_enabled_flag);
1428
436k
    if (current->sps_alf_enabled_flag && current->sps_chroma_format_idc)
1429
436k
        flag(sps_ccalf_enabled_flag);
1430
251k
    else
1431
251k
        infer(sps_ccalf_enabled_flag, 0);
1432
434k
    flag(sps_lmcs_enabled_flag);
1433
432k
    flag(sps_weighted_pred_flag);
1434
431k
    flag(sps_weighted_bipred_flag);
1435
430k
    flag(sps_long_term_ref_pics_flag);
1436
430k
    if (current->sps_video_parameter_set_id > 0)
1437
430k
        flag(sps_inter_layer_prediction_enabled_flag);
1438
336k
    else
1439
336k
        infer(sps_inter_layer_prediction_enabled_flag, 0);
1440
429k
    flag(sps_idr_rpl_present_flag);
1441
428k
    flag(sps_rpl1_same_as_rpl0_flag);
1442
1443
998k
    for (i = 0; i < (current->sps_rpl1_same_as_rpl0_flag ? 1 : 2); i++) {
1444
626k
        ues(sps_num_ref_pic_lists[i], 0, VVC_MAX_REF_PIC_LISTS, 1, i);
1445
2.57M
        for (j = 0; j < current->sps_num_ref_pic_lists[i]; j++)
1446
2.00M
            CHECK(FUNC(ref_pic_list_struct) (ctx, rw,
1447
623k
                                             &current->
1448
623k
                                             sps_ref_pic_list_struct[i][j], i,
1449
623k
                                             j, current));
1450
623k
    }
1451
1452
372k
    if (current->sps_rpl1_same_as_rpl0_flag) {
1453
188k
        current->sps_num_ref_pic_lists[1] = current->sps_num_ref_pic_lists[0];
1454
460k
        for (j = 0; j < current->sps_num_ref_pic_lists[0]; j++)
1455
272k
            memcpy(&current->sps_ref_pic_list_struct[1][j],
1456
272k
                   &current->sps_ref_pic_list_struct[0][j],
1457
272k
                   sizeof(current->sps_ref_pic_list_struct[0][j]));
1458
188k
    }
1459
1460
372k
    flag(sps_ref_wraparound_enabled_flag);
1461
1462
369k
    flag(sps_temporal_mvp_enabled_flag);
1463
368k
    if (current->sps_temporal_mvp_enabled_flag)
1464
368k
        flag(sps_sbtmvp_enabled_flag);
1465
106k
    else
1466
106k
        infer(sps_sbtmvp_enabled_flag, 0);
1467
1468
361k
    flag(sps_amvr_enabled_flag);
1469
359k
    flag(sps_bdof_enabled_flag);
1470
358k
    if (current->sps_bdof_enabled_flag)
1471
358k
        flag(sps_bdof_control_present_in_ph_flag);
1472
175k
    else
1473
175k
        infer(sps_bdof_control_present_in_ph_flag, 0);
1474
1475
357k
    flag(sps_smvd_enabled_flag);
1476
354k
    flag(sps_dmvr_enabled_flag);
1477
353k
    if (current->sps_dmvr_enabled_flag)
1478
353k
        flag(sps_dmvr_control_present_in_ph_flag);
1479
115k
    else
1480
115k
        infer(sps_dmvr_control_present_in_ph_flag, 0);
1481
1482
352k
    flag(sps_mmvd_enabled_flag);
1483
351k
    if (current->sps_mmvd_enabled_flag)
1484
351k
        flag(sps_mmvd_fullpel_only_enabled_flag);
1485
145k
    else
1486
145k
        infer(sps_mmvd_fullpel_only_enabled_flag, 0);
1487
1488
350k
    ue(sps_six_minus_max_num_merge_cand, 0, 5);
1489
333k
    max_num_merge_cand = 6 - current->sps_six_minus_max_num_merge_cand;
1490
1491
333k
    flag(sps_sbt_enabled_flag);
1492
1493
332k
    flag(sps_affine_enabled_flag);
1494
329k
    if (current->sps_affine_enabled_flag) {
1495
187k
        ue(sps_five_minus_max_num_subblock_merge_cand,
1496
183k
           0, 5 - current->sps_sbtmvp_enabled_flag);
1497
183k
        flag(sps_6param_affine_enabled_flag);
1498
182k
        if (current->sps_amvr_enabled_flag)
1499
182k
            flag(sps_affine_amvr_enabled_flag);
1500
41.6k
        else
1501
41.6k
            infer(sps_affine_amvr_enabled_flag, 0);
1502
181k
        flag(sps_affine_prof_enabled_flag);
1503
180k
        if (current->sps_affine_prof_enabled_flag)
1504
180k
            flag(sps_prof_control_present_in_ph_flag);
1505
49.2k
        else
1506
49.2k
            infer(sps_prof_control_present_in_ph_flag, 0);
1507
180k
    } else {
1508
141k
        infer(sps_6param_affine_enabled_flag, 0);
1509
141k
        infer(sps_affine_amvr_enabled_flag, 0);
1510
141k
        infer(sps_affine_prof_enabled_flag, 0);
1511
141k
        infer(sps_prof_control_present_in_ph_flag, 0);
1512
141k
    }
1513
1514
321k
    flag(sps_bcw_enabled_flag);
1515
321k
    flag(sps_ciip_enabled_flag);
1516
1517
320k
    if (max_num_merge_cand >= 2) {
1518
313k
        flag(sps_gpm_enabled_flag);
1519
313k
        if (current->sps_gpm_enabled_flag && max_num_merge_cand >= 3)
1520
313k
            ue(sps_max_num_merge_cand_minus_max_num_gpm_cand,
1521
313k
               0, max_num_merge_cand - 2);
1522
313k
    } else {
1523
6.95k
        infer(sps_gpm_enabled_flag, 0);
1524
6.95k
    }
1525
1526
317k
    ue(sps_log2_parallel_merge_level_minus2, 0, ctb_log2_size_y - 2);
1527
1528
312k
    flag(sps_isp_enabled_flag);
1529
311k
    flag(sps_mrl_enabled_flag);
1530
309k
    flag(sps_mip_enabled_flag);
1531
1532
305k
    if (current->sps_chroma_format_idc != 0)
1533
305k
        flag(sps_cclm_enabled_flag);
1534
58.3k
    else
1535
58.3k
        infer(sps_cclm_enabled_flag, 0);
1536
304k
    if (current->sps_chroma_format_idc == 1) {
1537
190k
        flag(sps_chroma_horizontal_collocated_flag);
1538
189k
        flag(sps_chroma_vertical_collocated_flag);
1539
189k
    } else {
1540
114k
        infer(sps_chroma_horizontal_collocated_flag, 1);
1541
114k
        infer(sps_chroma_vertical_collocated_flag, 1);
1542
114k
    }
1543
1544
303k
    flag(sps_palette_enabled_flag);
1545
300k
    if (current->sps_chroma_format_idc == 3 &&
1546
41.9k
        !current->sps_max_luma_transform_size_64_flag)
1547
300k
        flag(sps_act_enabled_flag);
1548
282k
    else
1549
282k
        infer(sps_act_enabled_flag, 0);
1550
300k
    if (current->sps_transform_skip_enabled_flag ||
1551
94.4k
        current->sps_palette_enabled_flag)
1552
300k
        ue(sps_min_qp_prime_ts, 0, 8);
1553
1554
297k
    flag(sps_ibc_enabled_flag);
1555
294k
    if (current->sps_ibc_enabled_flag)
1556
294k
        ue(sps_six_minus_max_num_ibc_merge_cand, 0, 5);
1557
1558
292k
    flag(sps_ladf_enabled_flag);
1559
291k
    if (current->sps_ladf_enabled_flag) {
1560
139k
        ub(2, sps_num_ladf_intervals_minus2);
1561
138k
        se(sps_ladf_lowest_interval_qp_offset, -63, 63);
1562
535k
        for (i = 0; i < current->sps_num_ladf_intervals_minus2 + 1; i++) {
1563
403k
            ses(sps_ladf_qp_offset[i], -63, 63, 1, i);
1564
401k
            ues(sps_ladf_delta_threshold_minus1[i],
1565
401k
                0, (2 << (8 + current->sps_bitdepth_minus8)) - 3, 1, i);
1566
401k
        }
1567
135k
    }
1568
1569
284k
    flag(sps_explicit_scaling_list_enabled_flag);
1570
280k
    if (current->sps_lfnst_enabled_flag &&
1571
118k
        current->sps_explicit_scaling_list_enabled_flag)
1572
280k
        flag(sps_scaling_matrix_for_lfnst_disabled_flag);
1573
1574
279k
    if (current->sps_act_enabled_flag &&
1575
14.3k
        current->sps_explicit_scaling_list_enabled_flag)
1576
279k
        flag(sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
1577
270k
    else
1578
270k
        infer(sps_scaling_matrix_for_alternative_colour_space_disabled_flag, 0);
1579
279k
    if (current->sps_scaling_matrix_for_alternative_colour_space_disabled_flag)
1580
279k
        flag(sps_scaling_matrix_designated_colour_space_flag);
1581
1582
278k
    flag(sps_dep_quant_enabled_flag);
1583
277k
    flag(sps_sign_data_hiding_enabled_flag);
1584
1585
277k
    flag(sps_virtual_boundaries_enabled_flag);
1586
274k
    if (current->sps_virtual_boundaries_enabled_flag) {
1587
129k
        flag(sps_virtual_boundaries_present_flag);
1588
128k
        if (current->sps_virtual_boundaries_present_flag) {
1589
67.0k
            ue(sps_num_ver_virtual_boundaries,
1590
65.5k
               0, current->sps_pic_width_max_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
1591
76.8k
            for (i = 0; i < current->sps_num_ver_virtual_boundaries; i++)
1592
65.5k
                ues(sps_virtual_boundary_pos_x_minus1[i],
1593
64.8k
                    0, (current->sps_pic_width_max_in_luma_samples + 7) / 8 - 2,
1594
64.8k
                    1, i);
1595
64.8k
            ue(sps_num_hor_virtual_boundaries,
1596
61.7k
               0, current->sps_pic_height_max_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
1597
81.2k
            for (i = 0; i < current->sps_num_hor_virtual_boundaries; i++)
1598
61.7k
                ues(sps_virtual_boundary_pos_y_minus1[i],
1599
61.7k
                    0, (current->sps_pic_height_max_in_luma_samples + 7) /
1600
61.7k
                    8 - 2, 1, i);
1601
61.7k
        }
1602
144k
    } else {
1603
144k
        infer(sps_virtual_boundaries_present_flag, 0);
1604
144k
        infer(sps_num_ver_virtual_boundaries, 0);
1605
144k
        infer(sps_num_hor_virtual_boundaries, 0);
1606
144k
    }
1607
1608
267k
    if (current->sps_ptl_dpb_hrd_params_present_flag) {
1609
71.9k
        flag(sps_timing_hrd_params_present_flag);
1610
71.4k
        if (current->sps_timing_hrd_params_present_flag) {
1611
26.2k
            uint8_t first_sublayer;
1612
26.2k
            CHECK(FUNC(general_timing_hrd_parameters) (ctx, rw,
1613
26.2k
                &current->sps_general_timing_hrd_parameters));
1614
19.0k
            if (current->sps_max_sublayers_minus1 > 0)
1615
19.0k
                flag(sps_sublayer_cpb_params_present_flag);
1616
8.39k
            else
1617
8.39k
                infer(sps_sublayer_cpb_params_present_flag, 0);
1618
18.6k
            first_sublayer = current->sps_sublayer_cpb_params_present_flag ?
1619
12.4k
                0 : current->sps_max_sublayers_minus1;
1620
18.6k
            CHECK(FUNC(ols_timing_hrd_parameters) (ctx, rw,
1621
18.6k
                &current->sps_ols_timing_hrd_parameters, first_sublayer,
1622
18.6k
                current->sps_max_sublayers_minus1,
1623
18.6k
                &current->sps_general_timing_hrd_parameters));
1624
18.6k
        }
1625
71.4k
    }
1626
1627
255k
    flag(sps_field_seq_flag);
1628
255k
    flag(sps_vui_parameters_present_flag);
1629
253k
    if (current->sps_vui_parameters_present_flag) {
1630
89.9k
        ue(sps_vui_payload_size_minus1, 0, 1023);
1631
151k
        while (byte_alignment(rw) != 0)
1632
85.1k
            fixed(1, sps_vui_alignment_zero_bit, 0);
1633
66.6k
        CHECK(FUNC(vui_payload) (ctx, rw, &current->vui,
1634
66.6k
                                 current->sps_vui_payload_size_minus1 + 1,
1635
66.6k
                                 current->sps_chroma_format_idc));
1636
163k
    } else {
1637
163k
        CHECK(FUNC(vui_parameters_default) (ctx, rw, &current->vui));
1638
163k
    }
1639
1640
214k
    flag(sps_extension_flag);
1641
212k
    if (current->sps_extension_flag) {
1642
158k
        flag(sps_range_extension_flag);
1643
157k
        ub(7, sps_extension_7bits);
1644
1645
153k
        if (current->sps_range_extension_flag) {
1646
29.8k
            if (current->sps_bitdepth_minus8 <= 10 - 8)
1647
18.1k
                return AVERROR_INVALIDDATA;
1648
11.7k
            CHECK(FUNC(sps_range_extension)(ctx, rw, current));
1649
123k
        } else {
1650
123k
            infer(sps_extended_precision_flag, 0);
1651
123k
            infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1652
123k
            infer(sps_rrc_rice_extension_flag, 0);
1653
123k
            infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1654
123k
            infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1655
123k
        }
1656
153k
    } else {
1657
54.5k
        infer(sps_range_extension_flag, 0);
1658
54.5k
        infer(sps_extension_7bits, 0);
1659
54.5k
        infer(sps_extended_precision_flag, 0);
1660
54.5k
        infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1661
54.5k
        infer(sps_rrc_rice_extension_flag, 0);
1662
54.5k
        infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1663
54.5k
        infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1664
54.5k
    }
1665
1666
188k
    if (current->sps_extension_7bits)
1667
133k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1668
1669
188k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
1670
1671
172k
    return 0;
1672
188k
}
cbs_h266.c:cbs_h266_write_sps
Line
Count
Source
1058
14.3k
{
1059
14.3k
    CodedBitstreamH266Context *h266 = ctx->priv_data;
1060
14.3k
    int err, i, j, max_width_minus1, max_height_minus1;
1061
14.3k
    unsigned int ctb_log2_size_y, min_cb_log2_size_y,
1062
14.3k
                 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y,
1063
14.3k
                 ctb_size_y, max_num_merge_cand, tmp_width_val, tmp_height_val;
1064
14.3k
    uint8_t qp_bd_offset, sub_width_c, sub_height_c;
1065
1066
14.3k
    static const uint8_t h266_sub_width_c[] = {
1067
14.3k
        1, 2, 2, 1
1068
14.3k
    };
1069
14.3k
    static const uint8_t h266_sub_height_c[] = {
1070
14.3k
        1, 2, 1, 1
1071
14.3k
    };
1072
1073
14.3k
    HEADER("Sequence Parameter Set");
1074
1075
14.3k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
1076
14.3k
                                 &current->nal_unit_header, VVC_SPS_NUT));
1077
1078
14.3k
    ub(4, sps_seq_parameter_set_id);
1079
14.3k
    ub(4, sps_video_parameter_set_id);
1080
14.3k
    if (current->sps_video_parameter_set_id == 0 && !h266->vps[0]) {
1081
2.93k
        H266RawVPS *vps = av_refstruct_allocz(sizeof(*vps));
1082
2.93k
        if (!vps)
1083
0
            return AVERROR(ENOMEM);
1084
2.93k
        vps->vps_max_layers_minus1 = 0;
1085
2.93k
        vps->vps_independent_layer_flag[0] = 1;
1086
2.93k
        vps->vps_layer_id[0] = current->nal_unit_header.nuh_layer_id;
1087
2.93k
        h266->vps[0] = vps;
1088
2.93k
    }
1089
1090
14.3k
    u(3, sps_max_sublayers_minus1, 0, VVC_MAX_SUBLAYERS - 1);
1091
14.3k
    u(2, sps_chroma_format_idc, 0, 3);
1092
14.3k
    sub_width_c = h266_sub_width_c[current->sps_chroma_format_idc];
1093
14.3k
    sub_height_c = h266_sub_height_c[current->sps_chroma_format_idc];
1094
1095
14.3k
    u(2, sps_log2_ctu_size_minus5, 0, 3);
1096
14.3k
    ctb_log2_size_y = current->sps_log2_ctu_size_minus5 + 5;
1097
14.3k
    ctb_size_y = 1 << ctb_log2_size_y;
1098
1099
14.3k
    flag(sps_ptl_dpb_hrd_params_present_flag);
1100
14.3k
    if (current->sps_ptl_dpb_hrd_params_present_flag) {
1101
6.07k
        CHECK(FUNC(profile_tier_level) (ctx, rw, &current->profile_tier_level,
1102
6.07k
                                        1, current->sps_max_sublayers_minus1));
1103
6.07k
    }
1104
14.3k
    flag(sps_gdr_enabled_flag);
1105
14.3k
    flag(sps_ref_pic_resampling_enabled_flag);
1106
14.3k
    if (current->sps_ref_pic_resampling_enabled_flag)
1107
14.3k
        flag(sps_res_change_in_clvs_allowed_flag);
1108
4.59k
    else
1109
4.59k
        infer(sps_res_change_in_clvs_allowed_flag, 0);
1110
1111
14.3k
    ue(sps_pic_width_max_in_luma_samples, 1, VVC_MAX_WIDTH);
1112
14.3k
    ue(sps_pic_height_max_in_luma_samples, 1, VVC_MAX_HEIGHT);
1113
1114
14.3k
    flag(sps_conformance_window_flag);
1115
14.3k
    if (current->sps_conformance_window_flag) {
1116
1.54k
        uint16_t width = current->sps_pic_width_max_in_luma_samples / sub_width_c;
1117
1.54k
        uint16_t height = current->sps_pic_height_max_in_luma_samples / sub_height_c;
1118
1.54k
        ue(sps_conf_win_left_offset, 0, width);
1119
1.54k
        ue(sps_conf_win_right_offset, 0, width - current->sps_conf_win_left_offset);
1120
1.54k
        ue(sps_conf_win_top_offset, 0, height);
1121
1.54k
        ue(sps_conf_win_bottom_offset, 0, height - current->sps_conf_win_top_offset);
1122
12.7k
    } else {
1123
12.7k
        infer(sps_conf_win_left_offset, 0);
1124
12.7k
        infer(sps_conf_win_right_offset, 0);
1125
12.7k
        infer(sps_conf_win_top_offset, 0);
1126
12.7k
        infer(sps_conf_win_bottom_offset, 0);
1127
12.7k
    }
1128
1129
14.3k
    tmp_width_val = AV_CEIL_RSHIFT(current->sps_pic_width_max_in_luma_samples,
1130
14.3k
                    ctb_log2_size_y);
1131
14.3k
    tmp_height_val = AV_CEIL_RSHIFT(current->sps_pic_height_max_in_luma_samples,
1132
14.3k
                    ctb_log2_size_y);
1133
14.3k
    max_width_minus1  = tmp_width_val - 1;
1134
14.3k
    max_height_minus1 = tmp_height_val - 1;
1135
1136
14.3k
    flag(sps_subpic_info_present_flag);
1137
14.3k
    if (current->sps_subpic_info_present_flag) {
1138
3.32k
        ue(sps_num_subpics_minus1, 0, VVC_MAX_SLICES - 1);
1139
3.32k
        if (current->sps_num_subpics_minus1 > 0) {
1140
3.00k
            flag(sps_independent_subpics_flag);
1141
3.00k
            flag(sps_subpic_same_size_flag);
1142
3.00k
        }
1143
1144
3.32k
        if (current->sps_num_subpics_minus1 > 0) {
1145
3.00k
            int wlen = av_ceil_log2(tmp_width_val);
1146
3.00k
            int hlen = av_ceil_log2(tmp_height_val);
1147
3.00k
            infer(sps_subpic_ctu_top_left_x[0], 0);
1148
3.00k
            infer(sps_subpic_ctu_top_left_y[0], 0);
1149
3.00k
            if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1150
3.00k
                us(wlen, sps_subpic_width_minus1[0], 0, max_width_minus1, 1, 0);
1151
1.19k
            else
1152
1.19k
                infer(sps_subpic_width_minus1[0], max_width_minus1);
1153
3.00k
            if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1154
3.00k
                us(hlen, sps_subpic_height_minus1[0], 0, max_height_minus1, 1, 0);
1155
1.51k
            else
1156
1.51k
                infer(sps_subpic_height_minus1[0], max_height_minus1);
1157
3.00k
            if (!current->sps_independent_subpics_flag) {
1158
1.99k
                flags(sps_subpic_treated_as_pic_flag[0], 1, 0);
1159
1.99k
                flags(sps_loop_filter_across_subpic_enabled_flag[0], 1, 0);
1160
1.99k
            } else {
1161
1.00k
                infer(sps_subpic_treated_as_pic_flag[0], 1);
1162
1.00k
                infer(sps_loop_filter_across_subpic_enabled_flag[0], 1);
1163
1.00k
            }
1164
10.6k
            for (i = 1; i <= current->sps_num_subpics_minus1; i++) {
1165
7.64k
                if (!current->sps_subpic_same_size_flag) {
1166
5.06k
                    const int win_right_edge =
1167
5.06k
                        current->sps_pic_width_max_in_luma_samples -
1168
5.06k
                        current->sps_conf_win_right_offset * sub_width_c;
1169
5.06k
                    const int win_bottom_edge =
1170
5.06k
                        current->sps_pic_height_max_in_luma_samples -
1171
5.06k
                        current->sps_conf_win_bottom_offset * sub_height_c;
1172
5.06k
                    const int win_left_edge =
1173
5.06k
                        current->sps_conf_win_left_offset * sub_width_c;
1174
5.06k
                    const int win_top_edge =
1175
5.06k
                        current->sps_conf_win_top_offset * sub_height_c;
1176
5.06k
                    const int win_left_edge_ctus   =
1177
5.06k
                        AV_CEIL_RSHIFT(win_left_edge,   ctb_log2_size_y);
1178
5.06k
                    const int win_right_edge_ctus  =
1179
5.06k
                        AV_CEIL_RSHIFT(win_right_edge,  ctb_log2_size_y);
1180
5.06k
                    const int win_top_edge_ctus    =
1181
5.06k
                        AV_CEIL_RSHIFT(win_top_edge,    ctb_log2_size_y);
1182
5.06k
                    const int win_bottom_edge_ctus =
1183
5.06k
                        AV_CEIL_RSHIFT(win_bottom_edge, ctb_log2_size_y);
1184
5.06k
                    const int min_width  =
1185
5.06k
                        FFMAX(win_left_edge_ctus - current->sps_subpic_ctu_top_left_x[i], 0);
1186
5.06k
                    const int min_height =
1187
5.06k
                        FFMAX(win_top_edge_ctus  - current->sps_subpic_ctu_top_left_y[i], 0);
1188
1189
5.06k
                    if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1190
5.06k
                        us(wlen, sps_subpic_ctu_top_left_x[i], 0, win_right_edge_ctus - 1, 1, i);
1191
2.27k
                    else
1192
2.27k
                        infer(sps_subpic_ctu_top_left_x[i], 0);
1193
1194
5.06k
                    if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1195
5.06k
                        us(hlen, sps_subpic_ctu_top_left_y[i], 0, win_bottom_edge_ctus - 1, 1, i);
1196
2.59k
                    else
1197
2.59k
                        infer(sps_subpic_ctu_top_left_y[i], 0);
1198
1199
5.06k
                    max_width_minus1  = tmp_width_val  - current->sps_subpic_ctu_top_left_x[i] - 1;
1200
5.06k
                    max_height_minus1 = tmp_height_val - current->sps_subpic_ctu_top_left_y[i] - 1;
1201
1202
5.06k
                    if (i < current->sps_num_subpics_minus1 &&
1203
2.43k
                        current->sps_pic_width_max_in_luma_samples > ctb_size_y) {
1204
1.35k
                        us(wlen, sps_subpic_width_minus1[i], min_width, max_width_minus1, 1, i);
1205
3.71k
                    } else {
1206
3.71k
                        infer(sps_subpic_width_minus1[i], max_width_minus1);
1207
3.71k
                    }
1208
1209
5.06k
                    if (i < current->sps_num_subpics_minus1 &&
1210
2.43k
                        current->sps_pic_height_max_in_luma_samples > ctb_size_y) {
1211
1.34k
                        us(hlen, sps_subpic_height_minus1[i], min_height, max_height_minus1, 1, i);
1212
3.71k
                    } else {
1213
3.71k
                        infer(sps_subpic_height_minus1[i], max_height_minus1);
1214
3.71k
                    }
1215
5.06k
                } else {
1216
2.58k
                    int num_subpic_cols = tmp_width_val /
1217
2.58k
                                     (current->sps_subpic_width_minus1[0] + 1);
1218
2.58k
                    if (tmp_width_val % (current->sps_subpic_width_minus1[0] + 1) ||
1219
2.58k
                        tmp_height_val % (current->sps_subpic_height_minus1[0] + 1) ||
1220
2.58k
                        current->sps_num_subpics_minus1 !=
1221
2.58k
                        (num_subpic_cols * tmp_height_val /
1222
2.58k
                         (current->sps_subpic_height_minus1[0] + 1) - 1))
1223
0
                        return AVERROR_INVALIDDATA;
1224
2.58k
                    infer(sps_subpic_ctu_top_left_x[i],
1225
2.58k
                          (i % num_subpic_cols) *
1226
2.58k
                          (current->sps_subpic_width_minus1[0] + 1));
1227
2.58k
                    infer(sps_subpic_ctu_top_left_y[i],
1228
2.58k
                          (i / num_subpic_cols) *
1229
2.58k
                          (current->sps_subpic_height_minus1[0] + 1));
1230
2.58k
                    infer(sps_subpic_width_minus1[i],
1231
2.58k
                          current->sps_subpic_width_minus1[0]);
1232
2.58k
                    infer(sps_subpic_height_minus1[i],
1233
2.58k
                          current->sps_subpic_height_minus1[0]);
1234
2.58k
                }
1235
7.64k
                if (!current->sps_independent_subpics_flag) {
1236
6.39k
                    flags(sps_subpic_treated_as_pic_flag[i], 1, i);
1237
6.39k
                    flags(sps_loop_filter_across_subpic_enabled_flag[i], 1, i);
1238
6.39k
                } else {
1239
1.25k
                    infer(sps_subpic_treated_as_pic_flag[i], 1);
1240
1.25k
                    infer(sps_loop_filter_across_subpic_enabled_flag[i], 0);
1241
1.25k
                }
1242
7.64k
            }
1243
3.00k
        } else {
1244
323
            infer(sps_subpic_ctu_top_left_x[0], 0);
1245
323
            infer(sps_subpic_ctu_top_left_y[0], 0);
1246
323
            infer(sps_subpic_width_minus1[0], max_width_minus1);
1247
323
            infer(sps_subpic_height_minus1[0], max_height_minus1);
1248
323
        }
1249
3.32k
        ue(sps_subpic_id_len_minus1, 0, 15);
1250
3.32k
        if ((1 << (current->sps_subpic_id_len_minus1 + 1)) <
1251
3.32k
            current->sps_num_subpics_minus1 + 1) {
1252
0
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1253
0
                   "sps_subpic_id_len_minus1(%d) is too small\n",
1254
0
                   current->sps_subpic_id_len_minus1);
1255
0
            return AVERROR_INVALIDDATA;
1256
0
        }
1257
3.32k
        flag(sps_subpic_id_mapping_explicitly_signalled_flag);
1258
3.32k
        if (current->sps_subpic_id_mapping_explicitly_signalled_flag) {
1259
1.66k
            flag(sps_subpic_id_mapping_present_flag);
1260
1.66k
            if (current->sps_subpic_id_mapping_present_flag) {
1261
3.78k
                for (i = 0; i <= current->sps_num_subpics_minus1; i++) {
1262
3.01k
                    ubs(current->sps_subpic_id_len_minus1 + 1,
1263
3.01k
                        sps_subpic_id[i], 1, i);
1264
3.01k
                }
1265
773
            }
1266
1.66k
        }
1267
10.9k
    } else {
1268
10.9k
        infer(sps_num_subpics_minus1, 0);
1269
10.9k
        infer(sps_independent_subpics_flag, 1);
1270
10.9k
        infer(sps_subpic_same_size_flag, 0);
1271
10.9k
        infer(sps_subpic_id_mapping_explicitly_signalled_flag, 0);
1272
10.9k
        infer(sps_subpic_ctu_top_left_x[0], 0);
1273
10.9k
        infer(sps_subpic_ctu_top_left_y[0], 0);
1274
10.9k
        infer(sps_subpic_width_minus1[0], max_width_minus1);
1275
10.9k
        infer(sps_subpic_height_minus1[0], max_height_minus1);
1276
10.9k
    }
1277
1278
1279
14.3k
    ue(sps_bitdepth_minus8, 0, 8);
1280
14.3k
    qp_bd_offset = 6 * current->sps_bitdepth_minus8;
1281
1282
14.3k
    flag(sps_entropy_coding_sync_enabled_flag);
1283
14.3k
    flag(sps_entry_point_offsets_present_flag);
1284
1285
14.3k
    u(4, sps_log2_max_pic_order_cnt_lsb_minus4, 0, 12);
1286
14.3k
    flag(sps_poc_msb_cycle_flag);
1287
14.3k
    if (current->sps_poc_msb_cycle_flag)
1288
14.3k
        ue(sps_poc_msb_cycle_len_minus1,
1289
14.3k
           0, 32 - current->sps_log2_max_pic_order_cnt_lsb_minus4 - 5);
1290
1291
14.3k
    u(2, sps_num_extra_ph_bytes, 0, 2);
1292
105k
    for (i = 0; i < (current->sps_num_extra_ph_bytes * 8); i++) {
1293
91.1k
        flags(sps_extra_ph_bit_present_flag[i], 1, i);
1294
91.1k
    }
1295
1296
14.3k
    u(2, sps_num_extra_sh_bytes, 0, 2);
1297
123k
    for (i = 0; i < (current->sps_num_extra_sh_bytes * 8); i++) {
1298
109k
        flags(sps_extra_sh_bit_present_flag[i], 1, i);
1299
109k
    }
1300
1301
14.3k
    if (current->sps_ptl_dpb_hrd_params_present_flag) {
1302
6.07k
        if (current->sps_max_sublayers_minus1 > 0)
1303
6.07k
            flag(sps_sublayer_dpb_params_flag);
1304
2.07k
        else
1305
2.07k
            infer(sps_sublayer_dpb_params_flag, 0);
1306
6.07k
        CHECK(FUNC(dpb_parameters) (ctx, rw, &current->sps_dpb_params,
1307
6.07k
                                    current->sps_max_sublayers_minus1,
1308
6.07k
                                    current->sps_sublayer_dpb_params_flag));
1309
6.07k
    }
1310
1311
14.3k
    ue(sps_log2_min_luma_coding_block_size_minus2,
1312
14.3k
       0, FFMIN(4, current->sps_log2_ctu_size_minus5 + 3));
1313
14.3k
    min_cb_log2_size_y =
1314
14.3k
        current->sps_log2_min_luma_coding_block_size_minus2 + 2;
1315
1316
14.3k
    flag(sps_partition_constraints_override_enabled_flag);
1317
1318
14.3k
    ue(sps_log2_diff_min_qt_min_cb_intra_slice_luma,
1319
14.3k
       0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1320
14.3k
    min_qt_log2_size_intra_y =
1321
14.3k
        current->sps_log2_diff_min_qt_min_cb_intra_slice_luma +
1322
14.3k
        min_cb_log2_size_y;
1323
1324
14.3k
    ue(sps_max_mtt_hierarchy_depth_intra_slice_luma,
1325
14.3k
       0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1326
1327
14.3k
    if (current->sps_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
1328
7.29k
        ue(sps_log2_diff_max_bt_min_qt_intra_slice_luma,
1329
7.29k
           0, ctb_log2_size_y - min_qt_log2_size_intra_y);
1330
7.29k
        ue(sps_log2_diff_max_tt_min_qt_intra_slice_luma,
1331
7.29k
           0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
1332
7.29k
    } else {
1333
7.01k
        infer(sps_log2_diff_max_bt_min_qt_intra_slice_luma, 0);
1334
7.01k
        infer(sps_log2_diff_max_tt_min_qt_intra_slice_luma, 0);
1335
7.01k
    }
1336
1337
14.3k
    if (current->sps_chroma_format_idc != 0) {
1338
10.0k
        flag(sps_qtbtt_dual_tree_intra_flag);
1339
10.0k
    } else {
1340
4.29k
        infer(sps_qtbtt_dual_tree_intra_flag, 0);
1341
4.29k
    }
1342
1343
14.3k
    if (current->sps_qtbtt_dual_tree_intra_flag) {
1344
7.27k
        ue(sps_log2_diff_min_qt_min_cb_intra_slice_chroma,
1345
7.27k
           0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1346
7.27k
        ue(sps_max_mtt_hierarchy_depth_intra_slice_chroma,
1347
7.27k
           0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1348
7.27k
        if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
1349
3.93k
            unsigned int min_qt_log2_size_intra_c =
1350
3.93k
                current->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
1351
3.93k
                min_cb_log2_size_y;
1352
3.93k
            ue(sps_log2_diff_max_bt_min_qt_intra_slice_chroma,
1353
3.93k
               0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1354
3.93k
            ue(sps_log2_diff_max_tt_min_qt_intra_slice_chroma,
1355
3.93k
               0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1356
3.93k
        }
1357
7.27k
    } else {
1358
7.03k
        infer(sps_log2_diff_min_qt_min_cb_intra_slice_chroma, 0);
1359
7.03k
        infer(sps_max_mtt_hierarchy_depth_intra_slice_chroma, 0);
1360
7.03k
    }
1361
14.3k
    if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma == 0) {
1362
10.3k
        infer(sps_log2_diff_max_bt_min_qt_intra_slice_chroma, 0);
1363
10.3k
        infer(sps_log2_diff_max_tt_min_qt_intra_slice_chroma, 0);
1364
10.3k
    }
1365
1366
14.3k
    ue(sps_log2_diff_min_qt_min_cb_inter_slice,
1367
14.3k
       0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1368
14.3k
    min_qt_log2_size_inter_y =
1369
14.3k
        current->sps_log2_diff_min_qt_min_cb_inter_slice + min_cb_log2_size_y;
1370
1371
14.3k
    ue(sps_max_mtt_hierarchy_depth_inter_slice,
1372
14.3k
       0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1373
14.3k
    if (current->sps_max_mtt_hierarchy_depth_inter_slice != 0) {
1374
8.15k
        ue(sps_log2_diff_max_bt_min_qt_inter_slice,
1375
8.15k
           0, ctb_log2_size_y - min_qt_log2_size_inter_y);
1376
8.15k
        ue(sps_log2_diff_max_tt_min_qt_inter_slice,
1377
8.15k
           0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
1378
8.15k
    } else {
1379
6.15k
        infer(sps_log2_diff_max_bt_min_qt_inter_slice, 0);
1380
6.15k
        infer(sps_log2_diff_max_tt_min_qt_inter_slice, 0);
1381
6.15k
    }
1382
1383
14.3k
    if (ctb_size_y > 32)
1384
14.3k
        flag(sps_max_luma_transform_size_64_flag);
1385
4.41k
    else
1386
4.41k
        infer(sps_max_luma_transform_size_64_flag, 0);
1387
1388
14.3k
    flag(sps_transform_skip_enabled_flag);
1389
14.3k
    if (current->sps_transform_skip_enabled_flag) {
1390
10.3k
        ue(sps_log2_transform_skip_max_size_minus2, 0, 3);
1391
10.3k
        flag(sps_bdpcm_enabled_flag);
1392
10.3k
    }
1393
1394
14.3k
    flag(sps_mts_enabled_flag);
1395
14.3k
    if (current->sps_mts_enabled_flag) {
1396
9.40k
        flag(sps_explicit_mts_intra_enabled_flag);
1397
9.40k
        flag(sps_explicit_mts_inter_enabled_flag);
1398
9.40k
    } else {
1399
4.90k
        infer(sps_explicit_mts_intra_enabled_flag, 0);
1400
4.90k
        infer(sps_explicit_mts_inter_enabled_flag, 0);
1401
4.90k
    }
1402
1403
14.3k
    flag(sps_lfnst_enabled_flag);
1404
1405
14.3k
    if (current->sps_chroma_format_idc != 0) {
1406
10.0k
        uint8_t num_qp_tables;
1407
10.0k
        flag(sps_joint_cbcr_enabled_flag);
1408
10.0k
        flag(sps_same_qp_table_for_chroma_flag);
1409
10.0k
        num_qp_tables = current->sps_same_qp_table_for_chroma_flag ?
1410
8.00k
            1 : (current->sps_joint_cbcr_enabled_flag ? 3 : 2);
1411
22.8k
        for (i = 0; i < num_qp_tables; i++) {
1412
12.8k
            ses(sps_qp_table_start_minus26[i], -26 - qp_bd_offset, 36, 1, i);
1413
12.8k
            ues(sps_num_points_in_qp_table_minus1[i],
1414
12.8k
                0, 36 - current->sps_qp_table_start_minus26[i], 1, i);
1415
44.6k
            for (j = 0; j <= current->sps_num_points_in_qp_table_minus1[i]; j++) {
1416
31.8k
                uint8_t max = MAX_UINT_BITS(8);
1417
31.8k
                ues(sps_delta_qp_in_val_minus1[i][j], 0, max, 2, i, j);
1418
31.8k
                ues(sps_delta_qp_diff_val[i][j], 0, max, 2, i, j);
1419
31.8k
            }
1420
12.8k
        }
1421
10.0k
    } else {
1422
4.29k
        infer(sps_joint_cbcr_enabled_flag, 0);
1423
4.29k
        infer(sps_same_qp_table_for_chroma_flag, 0);
1424
4.29k
    }
1425
1426
14.3k
    flag(sps_sao_enabled_flag);
1427
14.3k
    flag(sps_alf_enabled_flag);
1428
14.3k
    if (current->sps_alf_enabled_flag && current->sps_chroma_format_idc)
1429
14.3k
        flag(sps_ccalf_enabled_flag);
1430
6.63k
    else
1431
6.63k
        infer(sps_ccalf_enabled_flag, 0);
1432
14.3k
    flag(sps_lmcs_enabled_flag);
1433
14.3k
    flag(sps_weighted_pred_flag);
1434
14.3k
    flag(sps_weighted_bipred_flag);
1435
14.3k
    flag(sps_long_term_ref_pics_flag);
1436
14.3k
    if (current->sps_video_parameter_set_id > 0)
1437
14.3k
        flag(sps_inter_layer_prediction_enabled_flag);
1438
7.21k
    else
1439
7.21k
        infer(sps_inter_layer_prediction_enabled_flag, 0);
1440
14.3k
    flag(sps_idr_rpl_present_flag);
1441
14.3k
    flag(sps_rpl1_same_as_rpl0_flag);
1442
1443
33.3k
    for (i = 0; i < (current->sps_rpl1_same_as_rpl0_flag ? 1 : 2); i++) {
1444
19.2k
        ues(sps_num_ref_pic_lists[i], 0, VVC_MAX_REF_PIC_LISTS, 1, i);
1445
138k
        for (j = 0; j < current->sps_num_ref_pic_lists[i]; j++)
1446
119k
            CHECK(FUNC(ref_pic_list_struct) (ctx, rw,
1447
19.2k
                                             &current->
1448
19.2k
                                             sps_ref_pic_list_struct[i][j], i,
1449
19.2k
                                             j, current));
1450
19.2k
    }
1451
1452
14.0k
    if (current->sps_rpl1_same_as_rpl0_flag) {
1453
9.16k
        current->sps_num_ref_pic_lists[1] = current->sps_num_ref_pic_lists[0];
1454
14.1k
        for (j = 0; j < current->sps_num_ref_pic_lists[0]; j++)
1455
4.96k
            memcpy(&current->sps_ref_pic_list_struct[1][j],
1456
4.96k
                   &current->sps_ref_pic_list_struct[0][j],
1457
4.96k
                   sizeof(current->sps_ref_pic_list_struct[0][j]));
1458
9.16k
    }
1459
1460
14.0k
    flag(sps_ref_wraparound_enabled_flag);
1461
1462
14.0k
    flag(sps_temporal_mvp_enabled_flag);
1463
14.0k
    if (current->sps_temporal_mvp_enabled_flag)
1464
14.0k
        flag(sps_sbtmvp_enabled_flag);
1465
4.28k
    else
1466
4.28k
        infer(sps_sbtmvp_enabled_flag, 0);
1467
1468
14.0k
    flag(sps_amvr_enabled_flag);
1469
14.0k
    flag(sps_bdof_enabled_flag);
1470
14.0k
    if (current->sps_bdof_enabled_flag)
1471
14.0k
        flag(sps_bdof_control_present_in_ph_flag);
1472
6.81k
    else
1473
6.81k
        infer(sps_bdof_control_present_in_ph_flag, 0);
1474
1475
14.0k
    flag(sps_smvd_enabled_flag);
1476
14.0k
    flag(sps_dmvr_enabled_flag);
1477
14.0k
    if (current->sps_dmvr_enabled_flag)
1478
14.0k
        flag(sps_dmvr_control_present_in_ph_flag);
1479
4.51k
    else
1480
4.51k
        infer(sps_dmvr_control_present_in_ph_flag, 0);
1481
1482
14.0k
    flag(sps_mmvd_enabled_flag);
1483
14.0k
    if (current->sps_mmvd_enabled_flag)
1484
14.0k
        flag(sps_mmvd_fullpel_only_enabled_flag);
1485
4.59k
    else
1486
4.59k
        infer(sps_mmvd_fullpel_only_enabled_flag, 0);
1487
1488
14.0k
    ue(sps_six_minus_max_num_merge_cand, 0, 5);
1489
14.0k
    max_num_merge_cand = 6 - current->sps_six_minus_max_num_merge_cand;
1490
1491
14.0k
    flag(sps_sbt_enabled_flag);
1492
1493
14.0k
    flag(sps_affine_enabled_flag);
1494
14.0k
    if (current->sps_affine_enabled_flag) {
1495
10.4k
        ue(sps_five_minus_max_num_subblock_merge_cand,
1496
10.4k
           0, 5 - current->sps_sbtmvp_enabled_flag);
1497
10.4k
        flag(sps_6param_affine_enabled_flag);
1498
10.4k
        if (current->sps_amvr_enabled_flag)
1499
10.4k
            flag(sps_affine_amvr_enabled_flag);
1500
935
        else
1501
935
            infer(sps_affine_amvr_enabled_flag, 0);
1502
10.4k
        flag(sps_affine_prof_enabled_flag);
1503
10.4k
        if (current->sps_affine_prof_enabled_flag)
1504
10.4k
            flag(sps_prof_control_present_in_ph_flag);
1505
2.17k
        else
1506
2.17k
            infer(sps_prof_control_present_in_ph_flag, 0);
1507
10.4k
    } else {
1508
3.62k
        infer(sps_6param_affine_enabled_flag, 0);
1509
3.62k
        infer(sps_affine_amvr_enabled_flag, 0);
1510
3.62k
        infer(sps_affine_prof_enabled_flag, 0);
1511
3.62k
        infer(sps_prof_control_present_in_ph_flag, 0);
1512
3.62k
    }
1513
1514
14.0k
    flag(sps_bcw_enabled_flag);
1515
14.0k
    flag(sps_ciip_enabled_flag);
1516
1517
14.0k
    if (max_num_merge_cand >= 2) {
1518
13.7k
        flag(sps_gpm_enabled_flag);
1519
13.7k
        if (current->sps_gpm_enabled_flag && max_num_merge_cand >= 3)
1520
13.7k
            ue(sps_max_num_merge_cand_minus_max_num_gpm_cand,
1521
13.7k
               0, max_num_merge_cand - 2);
1522
13.7k
    } else {
1523
310
        infer(sps_gpm_enabled_flag, 0);
1524
310
    }
1525
1526
14.0k
    ue(sps_log2_parallel_merge_level_minus2, 0, ctb_log2_size_y - 2);
1527
1528
14.0k
    flag(sps_isp_enabled_flag);
1529
14.0k
    flag(sps_mrl_enabled_flag);
1530
14.0k
    flag(sps_mip_enabled_flag);
1531
1532
14.0k
    if (current->sps_chroma_format_idc != 0)
1533
14.0k
        flag(sps_cclm_enabled_flag);
1534
4.10k
    else
1535
4.10k
        infer(sps_cclm_enabled_flag, 0);
1536
14.0k
    if (current->sps_chroma_format_idc == 1) {
1537
7.91k
        flag(sps_chroma_horizontal_collocated_flag);
1538
7.91k
        flag(sps_chroma_vertical_collocated_flag);
1539
7.91k
    } else {
1540
6.17k
        infer(sps_chroma_horizontal_collocated_flag, 1);
1541
6.17k
        infer(sps_chroma_vertical_collocated_flag, 1);
1542
6.17k
    }
1543
1544
14.0k
    flag(sps_palette_enabled_flag);
1545
14.0k
    if (current->sps_chroma_format_idc == 3 &&
1546
1.98k
        !current->sps_max_luma_transform_size_64_flag)
1547
14.0k
        flag(sps_act_enabled_flag);
1548
12.3k
    else
1549
12.3k
        infer(sps_act_enabled_flag, 0);
1550
14.0k
    if (current->sps_transform_skip_enabled_flag ||
1551
3.78k
        current->sps_palette_enabled_flag)
1552
14.0k
        ue(sps_min_qp_prime_ts, 0, 8);
1553
1554
14.0k
    flag(sps_ibc_enabled_flag);
1555
14.0k
    if (current->sps_ibc_enabled_flag)
1556
14.0k
        ue(sps_six_minus_max_num_ibc_merge_cand, 0, 5);
1557
1558
14.0k
    flag(sps_ladf_enabled_flag);
1559
14.0k
    if (current->sps_ladf_enabled_flag) {
1560
7.14k
        ub(2, sps_num_ladf_intervals_minus2);
1561
7.14k
        se(sps_ladf_lowest_interval_qp_offset, -63, 63);
1562
27.6k
        for (i = 0; i < current->sps_num_ladf_intervals_minus2 + 1; i++) {
1563
20.4k
            ses(sps_ladf_qp_offset[i], -63, 63, 1, i);
1564
20.4k
            ues(sps_ladf_delta_threshold_minus1[i],
1565
20.4k
                0, (2 << (8 + current->sps_bitdepth_minus8)) - 3, 1, i);
1566
20.4k
        }
1567
7.14k
    }
1568
1569
14.0k
    flag(sps_explicit_scaling_list_enabled_flag);
1570
14.0k
    if (current->sps_lfnst_enabled_flag &&
1571
10.3k
        current->sps_explicit_scaling_list_enabled_flag)
1572
14.0k
        flag(sps_scaling_matrix_for_lfnst_disabled_flag);
1573
1574
14.0k
    if (current->sps_act_enabled_flag &&
1575
823
        current->sps_explicit_scaling_list_enabled_flag)
1576
14.0k
        flag(sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
1577
13.6k
    else
1578
13.6k
        infer(sps_scaling_matrix_for_alternative_colour_space_disabled_flag, 0);
1579
14.0k
    if (current->sps_scaling_matrix_for_alternative_colour_space_disabled_flag)
1580
14.0k
        flag(sps_scaling_matrix_designated_colour_space_flag);
1581
1582
14.0k
    flag(sps_dep_quant_enabled_flag);
1583
14.0k
    flag(sps_sign_data_hiding_enabled_flag);
1584
1585
14.0k
    flag(sps_virtual_boundaries_enabled_flag);
1586
14.0k
    if (current->sps_virtual_boundaries_enabled_flag) {
1587
6.18k
        flag(sps_virtual_boundaries_present_flag);
1588
6.18k
        if (current->sps_virtual_boundaries_present_flag) {
1589
4.30k
            ue(sps_num_ver_virtual_boundaries,
1590
4.30k
               0, current->sps_pic_width_max_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
1591
7.86k
            for (i = 0; i < current->sps_num_ver_virtual_boundaries; i++)
1592
4.30k
                ues(sps_virtual_boundary_pos_x_minus1[i],
1593
4.30k
                    0, (current->sps_pic_width_max_in_luma_samples + 7) / 8 - 2,
1594
4.30k
                    1, i);
1595
4.30k
            ue(sps_num_hor_virtual_boundaries,
1596
4.30k
               0, current->sps_pic_height_max_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
1597
8.73k
            for (i = 0; i < current->sps_num_hor_virtual_boundaries; i++)
1598
4.42k
                ues(sps_virtual_boundary_pos_y_minus1[i],
1599
4.30k
                    0, (current->sps_pic_height_max_in_luma_samples + 7) /
1600
4.30k
                    8 - 2, 1, i);
1601
4.30k
        }
1602
7.90k
    } else {
1603
7.90k
        infer(sps_virtual_boundaries_present_flag, 0);
1604
7.90k
        infer(sps_num_ver_virtual_boundaries, 0);
1605
7.90k
        infer(sps_num_hor_virtual_boundaries, 0);
1606
7.90k
    }
1607
1608
14.0k
    if (current->sps_ptl_dpb_hrd_params_present_flag) {
1609
6.05k
        flag(sps_timing_hrd_params_present_flag);
1610
6.05k
        if (current->sps_timing_hrd_params_present_flag) {
1611
1.56k
            uint8_t first_sublayer;
1612
1.56k
            CHECK(FUNC(general_timing_hrd_parameters) (ctx, rw,
1613
1.56k
                &current->sps_general_timing_hrd_parameters));
1614
1.56k
            if (current->sps_max_sublayers_minus1 > 0)
1615
1.56k
                flag(sps_sublayer_cpb_params_present_flag);
1616
553
            else
1617
553
                infer(sps_sublayer_cpb_params_present_flag, 0);
1618
1.56k
            first_sublayer = current->sps_sublayer_cpb_params_present_flag ?
1619
1.04k
                0 : current->sps_max_sublayers_minus1;
1620
1.56k
            CHECK(FUNC(ols_timing_hrd_parameters) (ctx, rw,
1621
1.56k
                &current->sps_ols_timing_hrd_parameters, first_sublayer,
1622
1.56k
                current->sps_max_sublayers_minus1,
1623
1.56k
                &current->sps_general_timing_hrd_parameters));
1624
1.56k
        }
1625
6.05k
    }
1626
1627
14.0k
    flag(sps_field_seq_flag);
1628
14.0k
    flag(sps_vui_parameters_present_flag);
1629
14.0k
    if (current->sps_vui_parameters_present_flag) {
1630
3.41k
        ue(sps_vui_payload_size_minus1, 0, 1023);
1631
7.81k
        while (byte_alignment(rw) != 0)
1632
4.39k
            fixed(1, sps_vui_alignment_zero_bit, 0);
1633
3.41k
        CHECK(FUNC(vui_payload) (ctx, rw, &current->vui,
1634
3.41k
                                 current->sps_vui_payload_size_minus1 + 1,
1635
3.41k
                                 current->sps_chroma_format_idc));
1636
10.6k
    } else {
1637
10.6k
        CHECK(FUNC(vui_parameters_default) (ctx, rw, &current->vui));
1638
10.6k
    }
1639
1640
14.0k
    flag(sps_extension_flag);
1641
14.0k
    if (current->sps_extension_flag) {
1642
9.67k
        flag(sps_range_extension_flag);
1643
9.67k
        ub(7, sps_extension_7bits);
1644
1645
9.67k
        if (current->sps_range_extension_flag) {
1646
789
            if (current->sps_bitdepth_minus8 <= 10 - 8)
1647
0
                return AVERROR_INVALIDDATA;
1648
789
            CHECK(FUNC(sps_range_extension)(ctx, rw, current));
1649
8.88k
        } else {
1650
8.88k
            infer(sps_extended_precision_flag, 0);
1651
8.88k
            infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1652
8.88k
            infer(sps_rrc_rice_extension_flag, 0);
1653
8.88k
            infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1654
8.88k
            infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1655
8.88k
        }
1656
9.67k
    } else {
1657
4.42k
        infer(sps_range_extension_flag, 0);
1658
4.42k
        infer(sps_extension_7bits, 0);
1659
4.42k
        infer(sps_extended_precision_flag, 0);
1660
4.42k
        infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1661
4.42k
        infer(sps_rrc_rice_extension_flag, 0);
1662
4.42k
        infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1663
4.42k
        infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1664
4.42k
    }
1665
1666
14.0k
    if (current->sps_extension_7bits)
1667
9.66k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1668
1669
14.0k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
1670
1671
14.0k
    return 0;
1672
14.0k
}
1673
1674
static int FUNC(pps) (CodedBitstreamContext *ctx, RWContext *rw,
1675
                      H266RawPPS *current)
1676
414k
{
1677
414k
    CodedBitstreamH266Context *h266 = ctx->priv_data;
1678
414k
    const H266RawSPS *sps;
1679
414k
    int err, i;
1680
414k
    unsigned int min_cb_size_y, divisor, ctb_size_y,
1681
414k
        pic_width_in_ctbs_y, pic_height_in_ctbs_y;
1682
414k
    uint8_t sub_width_c, sub_height_c, qp_bd_offset;
1683
1684
414k
    static const uint8_t h266_sub_width_c[] = {
1685
414k
        1, 2, 2, 1
1686
414k
    };
1687
414k
    static const uint8_t h266_sub_height_c[] = {
1688
414k
        1, 2, 1, 1
1689
414k
    };
1690
1691
414k
    HEADER("Picture Parameter Set");
1692
1693
414k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
1694
414k
                                 &current->nal_unit_header, VVC_PPS_NUT));
1695
1696
410k
    ub(6, pps_pic_parameter_set_id);
1697
408k
    ub(4, pps_seq_parameter_set_id);
1698
407k
    sps = h266->sps[current->pps_seq_parameter_set_id];
1699
407k
    if (!sps) {
1700
19.4k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1701
19.4k
               current->pps_seq_parameter_set_id);
1702
19.4k
        return AVERROR_INVALIDDATA;
1703
19.4k
    }
1704
1705
387k
    flag(pps_mixed_nalu_types_in_pic_flag);
1706
387k
    ue(pps_pic_width_in_luma_samples,
1707
379k
       1, sps->sps_pic_width_max_in_luma_samples);
1708
379k
    ue(pps_pic_height_in_luma_samples,
1709
374k
       1, sps->sps_pic_height_max_in_luma_samples);
1710
1711
374k
    min_cb_size_y = 1 << (sps->sps_log2_min_luma_coding_block_size_minus2 + 2);
1712
374k
    divisor = FFMAX(min_cb_size_y, 8);
1713
374k
    if (current->pps_pic_width_in_luma_samples % divisor ||
1714
372k
        current->pps_pic_height_in_luma_samples % divisor) {
1715
2.97k
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1716
2.97k
               "Invalid dimensions: %ux%u not divisible "
1717
2.97k
               "by %u, MinCbSizeY = %u.\n",
1718
2.97k
               current->pps_pic_width_in_luma_samples,
1719
2.97k
               current->pps_pic_height_in_luma_samples, divisor, min_cb_size_y);
1720
2.97k
        return AVERROR_INVALIDDATA;
1721
2.97k
    }
1722
371k
    if (!sps->sps_res_change_in_clvs_allowed_flag &&
1723
90.2k
        (current->pps_pic_width_in_luma_samples !=
1724
90.2k
         sps->sps_pic_width_max_in_luma_samples ||
1725
87.0k
         current->pps_pic_height_in_luma_samples !=
1726
87.0k
         sps->sps_pic_height_max_in_luma_samples)) {
1727
4.30k
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1728
4.30k
               "Resolution change is not allowed, "
1729
4.30k
               "in max resolution (%ux%u) mismatched with pps(%ux%u).\n",
1730
4.30k
               sps->sps_pic_width_max_in_luma_samples,
1731
4.30k
               sps->sps_pic_height_max_in_luma_samples,
1732
4.30k
               current->pps_pic_width_in_luma_samples,
1733
4.30k
               current->pps_pic_height_in_luma_samples);
1734
4.30k
        return AVERROR_INVALIDDATA;
1735
4.30k
    }
1736
1737
366k
    ctb_size_y = 1 << (sps->sps_log2_ctu_size_minus5 + 5);
1738
366k
    if (sps->sps_ref_wraparound_enabled_flag) {
1739
39.6k
        if ((ctb_size_y / min_cb_size_y + 1) >
1740
39.6k
            (current->pps_pic_width_in_luma_samples / min_cb_size_y - 1)) {
1741
1.02k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1742
1.02k
                   "Invalid width(%u), ctb_size_y = %u, min_cb_size_y = %u.\n",
1743
1.02k
                   current->pps_pic_width_in_luma_samples,
1744
1.02k
                   ctb_size_y, min_cb_size_y);
1745
1.02k
            return AVERROR_INVALIDDATA;
1746
1.02k
        }
1747
39.6k
    }
1748
1749
365k
    flag(pps_conformance_window_flag);
1750
365k
    if (current->pps_pic_width_in_luma_samples ==
1751
365k
        sps->sps_pic_width_max_in_luma_samples &&
1752
90.3k
        current->pps_pic_height_in_luma_samples ==
1753
90.3k
        sps->sps_pic_height_max_in_luma_samples &&
1754
86.1k
        current->pps_conformance_window_flag) {
1755
434
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1756
434
               "Conformance window flag should not true.\n");
1757
434
        return AVERROR_INVALIDDATA;
1758
434
    }
1759
1760
365k
    sub_width_c = h266_sub_width_c[sps->sps_chroma_format_idc];
1761
365k
    sub_height_c = h266_sub_height_c[sps->sps_chroma_format_idc];
1762
365k
    if (current->pps_conformance_window_flag) {
1763
274k
        ue(pps_conf_win_left_offset, 0, current->pps_pic_width_in_luma_samples);
1764
274k
        ue(pps_conf_win_right_offset,
1765
273k
           0, current->pps_pic_width_in_luma_samples);
1766
273k
        ue(pps_conf_win_top_offset, 0, current->pps_pic_height_in_luma_samples);
1767
273k
        ue(pps_conf_win_bottom_offset,
1768
272k
           0, current->pps_pic_height_in_luma_samples);
1769
272k
        if (sub_width_c *
1770
272k
            (current->pps_conf_win_left_offset +
1771
272k
             current->pps_conf_win_right_offset) >=
1772
272k
            current->pps_pic_width_in_luma_samples ||
1773
272k
            sub_height_c *
1774
272k
            (current->pps_conf_win_top_offset +
1775
272k
             current->pps_conf_win_bottom_offset) >=
1776
272k
            current->pps_pic_height_in_luma_samples) {
1777
823
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1778
823
                   "Invalid pps conformance window: (%u, %u, %u, %u), "
1779
823
                   "resolution is %ux%u, sub wxh is %ux%u.\n",
1780
823
                   current->pps_conf_win_left_offset,
1781
823
                   current->pps_conf_win_right_offset,
1782
823
                   current->pps_conf_win_top_offset,
1783
823
                   current->pps_conf_win_bottom_offset,
1784
823
                   current->pps_pic_width_in_luma_samples,
1785
823
                   current->pps_pic_height_in_luma_samples,
1786
823
                   sub_width_c, sub_height_c);
1787
823
            return AVERROR_INVALIDDATA;
1788
823
        }
1789
272k
    } else {
1790
90.8k
        if (current->pps_pic_width_in_luma_samples ==
1791
90.8k
            sps->sps_pic_width_max_in_luma_samples &&
1792
87.5k
            current->pps_pic_height_in_luma_samples ==
1793
87.5k
            sps->sps_pic_height_max_in_luma_samples) {
1794
85.7k
            infer(pps_conf_win_left_offset, sps->sps_conf_win_left_offset);
1795
85.5k
            infer(pps_conf_win_right_offset, sps->sps_conf_win_right_offset);
1796
85.3k
            infer(pps_conf_win_top_offset, sps->sps_conf_win_top_offset);
1797
85.1k
            infer(pps_conf_win_bottom_offset, sps->sps_conf_win_bottom_offset);
1798
10.7k
        } else {
1799
5.14k
            infer(pps_conf_win_left_offset, 0);
1800
5.14k
            infer(pps_conf_win_right_offset, 0);
1801
5.14k
            infer(pps_conf_win_top_offset, 0);
1802
5.14k
            infer(pps_conf_win_bottom_offset, 0);
1803
523
        }
1804
1805
90.8k
    }
1806
1807
361k
    flag(pps_scaling_window_explicit_signalling_flag);
1808
361k
    if (!sps->sps_ref_pic_resampling_enabled_flag &&
1809
3.21k
        current->pps_scaling_window_explicit_signalling_flag) {
1810
2
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1811
2
               "Invalid data: sps_ref_pic_resampling_enabled_flag is false, "
1812
2
               "but pps_scaling_window_explicit_signalling_flag is true.\n");
1813
2
        return AVERROR_INVALIDDATA;
1814
2
    }
1815
361k
    if (current->pps_scaling_window_explicit_signalling_flag) {
1816
282k
        se(pps_scaling_win_left_offset,
1817
281k
           -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1818
281k
           current->pps_pic_width_in_luma_samples / sub_width_c);
1819
281k
        se(pps_scaling_win_right_offset,
1820
273k
           -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1821
273k
           current->pps_pic_width_in_luma_samples / sub_width_c);
1822
273k
        se(pps_scaling_win_top_offset,
1823
272k
           -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1824
272k
           current->pps_pic_height_in_luma_samples / sub_height_c);
1825
272k
        se(pps_scaling_win_bottom_offset,
1826
272k
           -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1827
272k
           current->pps_pic_height_in_luma_samples / sub_height_c);
1828
272k
    } else {
1829
79.6k
        infer(pps_scaling_win_left_offset, current->pps_conf_win_left_offset);
1830
79.6k
        infer(pps_scaling_win_right_offset, current->pps_conf_win_right_offset);
1831
79.6k
        infer(pps_scaling_win_top_offset, current->pps_conf_win_top_offset);
1832
79.6k
        infer(pps_scaling_win_bottom_offset, current->pps_conf_win_bottom_offset);
1833
9.82k
    }
1834
1835
351k
    flag(pps_output_flag_present_flag);
1836
351k
    flag(pps_no_pic_partition_flag);
1837
351k
    flag(pps_subpic_id_mapping_present_flag);
1838
1839
351k
    if (current->pps_subpic_id_mapping_present_flag) {
1840
161k
        if (!current->pps_no_pic_partition_flag) {
1841
22.7k
            ue(pps_num_subpics_minus1,
1842
22.7k
               sps->sps_num_subpics_minus1, sps->sps_num_subpics_minus1);
1843
138k
        } else {
1844
138k
            infer(pps_num_subpics_minus1, 0);
1845
138k
        }
1846
160k
        ue(pps_subpic_id_len_minus1, sps->sps_subpic_id_len_minus1,
1847
158k
           sps->sps_subpic_id_len_minus1);
1848
334k
        for (i = 0; i <= current->pps_num_subpics_minus1; i++) {
1849
176k
            ubs(sps->sps_subpic_id_len_minus1 + 1, pps_subpic_id[i], 1, i);
1850
176k
        }
1851
158k
    }
1852
1853
768k
    for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
1854
420k
        if (sps->sps_subpic_id_mapping_explicitly_signalled_flag)
1855
56.9k
            current->sub_pic_id_val[i] = current->pps_subpic_id_mapping_present_flag
1856
56.9k
                                       ? current->pps_subpic_id[i]
1857
56.9k
                                       : sps->sps_subpic_id[i];
1858
364k
        else
1859
364k
            current->sub_pic_id_val[i] = i;
1860
420k
    }
1861
1862
347k
    pic_width_in_ctbs_y = AV_CEIL_RSHIFT
1863
347k
        (current->pps_pic_width_in_luma_samples, (sps->sps_log2_ctu_size_minus5 + 5));
1864
347k
    pic_height_in_ctbs_y = AV_CEIL_RSHIFT(
1865
347k
        current->pps_pic_height_in_luma_samples,(sps->sps_log2_ctu_size_minus5 + 5));
1866
347k
    if (!current->pps_no_pic_partition_flag) {
1867
172k
        unsigned int exp_tile_width = 0, exp_tile_height = 0;
1868
172k
        unsigned int unified_size, remaining_size;
1869
1870
172k
        u(2, pps_log2_ctu_size_minus5,
1871
169k
          sps->sps_log2_ctu_size_minus5, sps->sps_log2_ctu_size_minus5);
1872
169k
        ue(pps_num_exp_tile_columns_minus1,
1873
168k
           0, FFMIN(pic_width_in_ctbs_y - 1, VVC_MAX_TILE_COLUMNS - 1));
1874
168k
        ue(pps_num_exp_tile_rows_minus1,
1875
168k
           0, FFMIN(pic_height_in_ctbs_y - 1, VVC_MAX_TILE_ROWS - 1));
1876
1877
404k
        for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1878
238k
            ues(pps_tile_column_width_minus1[i],
1879
236k
                0, pic_width_in_ctbs_y - exp_tile_width - 1, 1, i);
1880
236k
            exp_tile_width += current->pps_tile_column_width_minus1[i] + 1;
1881
236k
        }
1882
350k
        for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1883
184k
            ues(pps_tile_row_height_minus1[i],
1884
184k
                0, pic_height_in_ctbs_y - exp_tile_height - 1, 1, i);
1885
184k
            exp_tile_height += current->pps_tile_row_height_minus1[i] + 1;
1886
184k
        }
1887
1888
166k
        remaining_size = pic_width_in_ctbs_y;
1889
396k
        for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1890
230k
          if (current->pps_tile_column_width_minus1[i] >= remaining_size) {
1891
208
              av_log(ctx->log_ctx, AV_LOG_ERROR,
1892
208
                     "Tile column width(%d) exceeds picture width\n",i);
1893
208
              return AVERROR_INVALIDDATA;
1894
208
          }
1895
230k
          current->col_width_val[i] = current->pps_tile_column_width_minus1[i] + 1;
1896
230k
          remaining_size -= (current->pps_tile_column_width_minus1[i] + 1);
1897
230k
        }
1898
166k
        unified_size = current->pps_tile_column_width_minus1[i - 1] + 1;
1899
330k
        while (remaining_size > 0) {
1900
164k
            if (i == VVC_MAX_TILE_COLUMNS) {
1901
238
                av_log(ctx->log_ctx, AV_LOG_ERROR,
1902
238
                       "Exceeded maximum tile columns (%d) (remaining size: %u)\n",
1903
238
                       VVC_MAX_TILE_COLUMNS, remaining_size);
1904
238
                return AVERROR_INVALIDDATA;
1905
238
            }
1906
164k
            unified_size = FFMIN(remaining_size, unified_size);
1907
164k
            current->col_width_val[i] = unified_size;
1908
164k
            remaining_size -= unified_size;
1909
164k
            i++;
1910
164k
        }
1911
165k
        current->num_tile_columns = i;
1912
1913
165k
        remaining_size = pic_height_in_ctbs_y;
1914
348k
        for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1915
182k
          if (current->pps_tile_row_height_minus1[i] >= remaining_size) {
1916
205
              av_log(ctx->log_ctx, AV_LOG_ERROR,
1917
205
                     "Tile row height(%d) exceeds picture height\n",i);
1918
205
              return AVERROR_INVALIDDATA;
1919
205
          }
1920
182k
          current->row_height_val[i] = current->pps_tile_row_height_minus1[i] + 1;
1921
182k
          remaining_size -= (current->pps_tile_row_height_minus1[i] + 1);
1922
182k
        }
1923
165k
        unified_size = current->pps_tile_row_height_minus1[i - 1] + 1;
1924
1925
317k
        while (remaining_size > 0) {
1926
151k
            if (i == VVC_MAX_TILE_ROWS) {
1927
0
                av_log(ctx->log_ctx, AV_LOG_ERROR,
1928
0
                       "Exceeded maximum tile rows (%d) (remaining size: %u)\n",
1929
0
                       VVC_MAX_TILE_ROWS, remaining_size);
1930
0
                return AVERROR_INVALIDDATA;
1931
0
            }
1932
151k
            unified_size = FFMIN(remaining_size, unified_size);
1933
151k
            current->row_height_val[i] = unified_size;
1934
151k
            remaining_size -= unified_size;
1935
151k
            i++;
1936
151k
        }
1937
165k
        current->num_tile_rows=i;
1938
1939
165k
        current->num_tiles_in_pic = current->num_tile_columns *
1940
165k
                                    current->num_tile_rows;
1941
165k
        if (current->num_tiles_in_pic > VVC_MAX_TILES_PER_AU) {
1942
213
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1943
213
                   "NumTilesInPic(%d) > than VVC_MAX_TILES_PER_AU(%d)\n",
1944
213
                   current->num_tiles_in_pic, VVC_MAX_TILES_PER_AU);
1945
213
            return AVERROR_INVALIDDATA;
1946
213
        }
1947
1948
165k
        if (current->num_tiles_in_pic > 1) {
1949
37.8k
            flag(pps_loop_filter_across_tiles_enabled_flag);
1950
37.6k
            flag(pps_rect_slice_flag);
1951
127k
        } else {
1952
127k
            infer(pps_loop_filter_across_tiles_enabled_flag, 0);
1953
127k
            infer(pps_rect_slice_flag, 1);
1954
206
        }
1955
165k
        if (current->pps_rect_slice_flag)
1956
165k
            flag(pps_single_slice_per_subpic_flag);
1957
5.67k
        else
1958
5.67k
            infer(pps_single_slice_per_subpic_flag, 1);
1959
164k
        if (current->pps_rect_slice_flag &&
1960
159k
            !current->pps_single_slice_per_subpic_flag) {
1961
30.9k
            int j, num_slices = 0;
1962
30.9k
            uint16_t tile_idx = 0, tile_x, tile_y, ctu_x, ctu_y;
1963
30.9k
            uint16_t slice_top_left_ctu_x[VVC_MAX_SLICES];
1964
30.9k
            uint16_t slice_top_left_ctu_y[VVC_MAX_SLICES];
1965
30.9k
            ue(pps_num_slices_in_pic_minus1, 0, VVC_MAX_SLICES - 1);
1966
30.7k
            if (current->pps_num_slices_in_pic_minus1 > 1)
1967
30.7k
                flag(pps_tile_idx_delta_present_flag);
1968
13.3k
            else
1969
13.3k
                infer(pps_tile_idx_delta_present_flag, 0);
1970
136k
            for (i = 0; i < current->pps_num_slices_in_pic_minus1; i++) {
1971
111k
                current->slice_top_left_tile_idx[i] = tile_idx;
1972
111k
                tile_x = tile_idx % current->num_tile_columns;
1973
111k
                tile_y = tile_idx / current->num_tile_columns;
1974
111k
                if (tile_y >= current->num_tile_rows)
1975
590
                    return AVERROR_INVALIDDATA;
1976
110k
                if (tile_x != current->num_tile_columns - 1) {
1977
64.7k
                    ues(pps_slice_width_in_tiles_minus1[i],
1978
64.7k
                        0, current->num_tile_columns - 1 - tile_x, 1, i);
1979
64.7k
                } else {
1980
46.1k
                    infer(pps_slice_width_in_tiles_minus1[i], 0);
1981
46.1k
                }
1982
108k
                if (tile_y != current->num_tile_rows - 1 &&
1983
62.5k
                    (current->pps_tile_idx_delta_present_flag || tile_x == 0)) {
1984
49.4k
                    ues(pps_slice_height_in_tiles_minus1[i],
1985
49.4k
                        0, current->num_tile_rows - 1 - tile_y, 1, i);
1986
59.2k
                } else {
1987
59.2k
                    if (tile_y == current->num_tile_rows - 1)
1988
46.2k
                        infer(pps_slice_height_in_tiles_minus1[i], 0);
1989
13.0k
                    else
1990
13.0k
                        infer(pps_slice_height_in_tiles_minus1[i],
1991
59.2k
                              current->pps_slice_height_in_tiles_minus1[i - 1]);
1992
59.2k
                }
1993
1994
108k
                ctu_x = ctu_y = 0;
1995
188k
                for (j = 0; j < tile_x; j++) {
1996
79.6k
                    ctu_x += current->col_width_val[j];
1997
79.6k
                }
1998
175k
                for (j = 0; j < tile_y; j++) {
1999
67.3k
                    ctu_y += current->row_height_val[j];
2000
67.3k
                }
2001
108k
                if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
2002
90.5k
                    current->pps_slice_height_in_tiles_minus1[i] == 0 &&
2003
84.5k
                    current->row_height_val[tile_y] > 1) {
2004
58.2k
                    int uniform_slice_height, remaining_height_in_ctbs_y;
2005
58.2k
                    remaining_height_in_ctbs_y =
2006
58.2k
                        current->row_height_val[tile_y];
2007
58.2k
                    ues(pps_num_exp_slices_in_tile[i],
2008
57.9k
                        0, current->row_height_val[tile_y] - 1, 1, i);
2009
57.9k
                    if (current->pps_num_exp_slices_in_tile[i] == 0) {
2010
30.4k
                        current->num_slices_in_tile[i] = 1;
2011
30.4k
                        current->slice_height_in_ctus[i] = current->row_height_val[tile_y];
2012
30.4k
                        slice_top_left_ctu_x[i] = ctu_x;
2013
30.4k
                        slice_top_left_ctu_y[i] = ctu_y;
2014
30.4k
                    } else {
2015
27.5k
                        uint16_t slice_height_in_ctus;
2016
27.5k
                        int num_uniform_slices;
2017
2018
27.5k
                        if (i + current->pps_num_exp_slices_in_tile[i] >
2019
27.5k
                            current->pps_num_slices_in_pic_minus1 + 1)
2020
194
                            return AVERROR_INVALIDDATA;
2021
2022
65.7k
                        for (j = 0; j < current->pps_num_exp_slices_in_tile[i];
2023
38.6k
                             j++) {
2024
38.6k
                            ues(pps_exp_slice_height_in_ctus_minus1[i][j], 0,
2025
38.3k
                                remaining_height_in_ctbs_y - 1, 2,
2026
38.3k
                                i, j);
2027
38.3k
                            slice_height_in_ctus =
2028
38.3k
                                current->
2029
38.3k
                                pps_exp_slice_height_in_ctus_minus1[i][j] + 1;
2030
2031
38.3k
                            current->slice_height_in_ctus[i + j] =
2032
38.3k
                                slice_height_in_ctus;
2033
38.3k
                            slice_top_left_ctu_x[i + j] = ctu_x;
2034
38.3k
                            slice_top_left_ctu_y[i + j] = ctu_y;
2035
38.3k
                            ctu_y += slice_height_in_ctus;
2036
2037
38.3k
                            remaining_height_in_ctbs_y -= slice_height_in_ctus;
2038
38.3k
                        }
2039
27.0k
                        uniform_slice_height = 1 +
2040
27.0k
                            (j == 0 ? current->row_height_val[tile_y] - 1:
2041
27.0k
                            current->pps_exp_slice_height_in_ctus_minus1[i][j-1]);
2042
2043
27.0k
                        num_uniform_slices = (remaining_height_in_ctbs_y + uniform_slice_height - 1)
2044
27.0k
                                           / uniform_slice_height;
2045
27.0k
                        if (i + current->pps_num_exp_slices_in_tile[i] + num_uniform_slices >
2046
27.0k
                            current->pps_num_slices_in_pic_minus1 + 1)
2047
199
                            return AVERROR_INVALIDDATA;
2048
2049
30.9k
                        while (remaining_height_in_ctbs_y > uniform_slice_height) {
2050
4.13k
                            current->slice_height_in_ctus[i + j] =
2051
4.13k
                                                          uniform_slice_height;
2052
4.13k
                            slice_top_left_ctu_x[i + j] = ctu_x;
2053
4.13k
                            slice_top_left_ctu_y[i + j] = ctu_y;
2054
4.13k
                            ctu_y += uniform_slice_height;
2055
2056
4.13k
                            remaining_height_in_ctbs_y -= uniform_slice_height;
2057
4.13k
                            j++;
2058
4.13k
                        }
2059
26.8k
                        if (remaining_height_in_ctbs_y > 0) {
2060
16.4k
                            current->slice_height_in_ctus[i + j] =
2061
16.4k
                                remaining_height_in_ctbs_y;
2062
16.4k
                            slice_top_left_ctu_x[i + j] = ctu_x;
2063
16.4k
                            slice_top_left_ctu_y[i + j] = ctu_y;
2064
16.4k
                            j++;
2065
16.4k
                        }
2066
26.8k
                        current->num_slices_in_tile[i] = j;
2067
26.8k
                    }
2068
146k
                    for (int k = 0; k < current->num_slices_in_tile[i]; k++)
2069
89.1k
                        current->slice_top_left_tile_idx[i + k] = tile_idx;
2070
57.2k
                    i += current->num_slices_in_tile[i] - 1;
2071
57.2k
                } else {
2072
50.2k
                    uint16_t height = 0;
2073
50.2k
                    infer(pps_num_exp_slices_in_tile[i], 0);
2074
50.2k
                    if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
2075
32.3k
                        current->pps_slice_height_in_tiles_minus1[i] == 0)
2076
26.3k
                        current->num_slices_in_tile[i] = 1;
2077
2078
7.17k
                    for (j = 0;
2079
113k
                         j <= current->pps_slice_height_in_tiles_minus1[i];
2080
63.5k
                         j++) {
2081
63.5k
                        height +=
2082
63.5k
                           current->row_height_val[tile_y + j];
2083
63.5k
                    }
2084
7.17k
                    current->slice_height_in_ctus[i] = height;
2085
2086
7.17k
                    slice_top_left_ctu_x[i] = ctu_x;
2087
7.17k
                    slice_top_left_ctu_y[i] = ctu_y;
2088
7.17k
                }
2089
107k
                if (i < current->pps_num_slices_in_pic_minus1) {
2090
106k
                    if (current->pps_tile_idx_delta_present_flag) {
2091
                        // Two conditions must be met:
2092
                        // 1. −NumTilesInPic + 1 <= pps_tile_idx_delta_val[i] <= NumTilesInPic − 1
2093
                        // 2. 0 <= tile_idx + pps_tile_idx_delta_val[i] <= NumTilesInPic − 1
2094
                        // Combining these conditions yields: -tile_idx <= pps_tile_idx_delta_val[i] <= NumTilesInPic - 1 - tile_idx
2095
80.9k
                        ses(pps_tile_idx_delta_val[i],
2096
79.6k
                            -tile_idx, current->num_tiles_in_pic - 1 - tile_idx, 1, i);
2097
79.6k
                        if (current->pps_tile_idx_delta_val[i] == 0) {
2098
38.1k
                            av_log(ctx->log_ctx, AV_LOG_ERROR,
2099
38.1k
                                   "pps_tile_idx_delta_val[i] shall not be equal to 0.\n");
2100
38.1k
                        }
2101
79.6k
                        tile_idx += current->pps_tile_idx_delta_val[i];
2102
79.6k
                    } else {
2103
25.8k
                        infer(pps_tile_idx_delta_val[i], 0);
2104
4.62k
                        tile_idx +=
2105
4.62k
                            current->pps_slice_width_in_tiles_minus1[i] + 1;
2106
25.8k
                        if (tile_idx % current->num_tile_columns == 0) {
2107
8.23k
                            tile_idx +=
2108
8.23k
                                current->pps_slice_height_in_tiles_minus1[i] *
2109
8.23k
                                current->num_tile_columns;
2110
8.23k
                        }
2111
4.62k
                    }
2112
106k
                }
2113
107k
            }
2114
25.2k
            if (i == current->pps_num_slices_in_pic_minus1) {
2115
24.4k
                uint16_t height = 0;
2116
2117
24.4k
                current->slice_top_left_tile_idx[i] = tile_idx;
2118
24.4k
                current->num_slices_in_tile[i] = 1;
2119
24.4k
                tile_x = tile_idx % current->num_tile_columns;
2120
24.4k
                tile_y = tile_idx / current->num_tile_columns;
2121
24.4k
                if (tile_y >= current->num_tile_rows)
2122
115
                    return AVERROR_INVALIDDATA;
2123
2124
24.3k
                ctu_x = 0, ctu_y = 0;
2125
41.9k
                for (j = 0; j < tile_x; j++) {
2126
17.6k
                    ctu_x += current->col_width_val[j];
2127
17.6k
                }
2128
41.9k
                for (j = 0; j < tile_y; j++) {
2129
17.6k
                    ctu_y += current->row_height_val[j];
2130
17.6k
                }
2131
24.3k
                slice_top_left_ctu_x[i] = ctu_x;
2132
24.3k
                slice_top_left_ctu_y[i] = ctu_y;
2133
2134
24.3k
                current->pps_slice_width_in_tiles_minus1[i] =
2135
24.3k
                    current->num_tile_columns - tile_x - 1;
2136
24.3k
                current->pps_slice_height_in_tiles_minus1[i] =
2137
24.3k
                    current->num_tile_rows - tile_y - 1;
2138
2139
132k
                for (j = 0; j <= current->pps_slice_height_in_tiles_minus1[i];
2140
107k
                     j++) {
2141
107k
                    height +=
2142
107k
                        current->row_height_val[tile_y + j];
2143
107k
                }
2144
24.3k
                current->slice_height_in_ctus[i] = height;
2145
2146
24.3k
                infer(pps_num_exp_slices_in_tile[i], 0);
2147
24.3k
            }
2148
            //now, we got all slice information, let's resolve NumSlicesInSubpic
2149
80.8k
            for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
2150
55.7k
                current->num_slices_in_subpic[i] = 0;
2151
374k
                for (j = 0; j <= current->pps_num_slices_in_pic_minus1; j++) {
2152
318k
                    uint16_t pos_x = 0, pos_y = 0;
2153
318k
                    pos_x = slice_top_left_ctu_x[j];
2154
318k
                    pos_y = slice_top_left_ctu_y[j];
2155
318k
                    if ((pos_x >= sps->sps_subpic_ctu_top_left_x[i]) &&
2156
216k
                        (pos_x <
2157
216k
                         sps->sps_subpic_ctu_top_left_x[i] +
2158
216k
                         sps->sps_subpic_width_minus1[i] + 1) &&
2159
190k
                         (pos_y >= sps->sps_subpic_ctu_top_left_y[i]) &&
2160
154k
                         (pos_y < sps->sps_subpic_ctu_top_left_y[i] +
2161
154k
                            sps->sps_subpic_height_minus1[i] + 1)) {
2162
142k
                        current->num_slices_in_subpic[i]++;
2163
142k
                    }
2164
318k
                }
2165
55.7k
                num_slices += current->num_slices_in_subpic[i];
2166
55.7k
            }
2167
25.0k
            if (current->pps_num_slices_in_pic_minus1 + 1 != num_slices)
2168
572
                return AVERROR_INVALIDDATA;
2169
133k
        } else {
2170
133k
            if (current->pps_no_pic_partition_flag)
2171
0
                infer(pps_num_slices_in_pic_minus1, 0);
2172
133k
            else if (current->pps_single_slice_per_subpic_flag) {
2173
288k
                for (i = 0; i <= sps->sps_num_subpics_minus1; i++)
2174
154k
                    current->num_slices_in_subpic[i] = 1;
2175
133k
                infer(pps_num_slices_in_pic_minus1,
2176
133k
                      sps->sps_num_subpics_minus1);
2177
133k
            }
2178
            // else?
2179
133k
        }
2180
158k
        if (!current->pps_rect_slice_flag ||
2181
152k
            current->pps_single_slice_per_subpic_flag ||
2182
24.5k
            current->pps_num_slices_in_pic_minus1 > 0)
2183
158k
            flag(pps_loop_filter_across_slices_enabled_flag);
2184
12.3k
        else
2185
12.3k
            infer(pps_loop_filter_across_slices_enabled_flag, 0);
2186
174k
    } else {
2187
174k
        infer(pps_num_exp_tile_columns_minus1, 0);
2188
174k
        infer(pps_tile_column_width_minus1[0], pic_width_in_ctbs_y - 1);
2189
174k
        infer(pps_num_exp_tile_rows_minus1, 0);
2190
174k
        infer(pps_tile_row_height_minus1[0], pic_height_in_ctbs_y - 1);
2191
4.44k
        current->col_width_val[0] = pic_width_in_ctbs_y;
2192
4.44k
        current->row_height_val[0] = pic_height_in_ctbs_y;
2193
4.44k
        current->num_tile_columns = 1;
2194
4.44k
        current->num_tile_rows = 1;
2195
4.44k
        current->num_tiles_in_pic = 1;
2196
4.44k
    }
2197
2198
332k
    flag(pps_cabac_init_present_flag);
2199
994k
    for (i = 0; i < 2; i++)
2200
663k
        ues(pps_num_ref_idx_default_active_minus1[i], 0, 14, 1, i);
2201
330k
    flag(pps_rpl1_idx_present_flag);
2202
330k
    flag(pps_weighted_pred_flag);
2203
330k
    flag(pps_weighted_bipred_flag);
2204
329k
    flag(pps_ref_wraparound_enabled_flag);
2205
329k
    if (current->pps_ref_wraparound_enabled_flag) {
2206
256k
        ue(pps_pic_width_minus_wraparound_offset,
2207
256k
           0, (current->pps_pic_width_in_luma_samples / min_cb_size_y)
2208
256k
           - (ctb_size_y / min_cb_size_y) - 2);
2209
256k
    }
2210
2211
327k
    qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2212
327k
    se(pps_init_qp_minus26, -(26 + qp_bd_offset), 37);
2213
325k
    flag(pps_cu_qp_delta_enabled_flag);
2214
323k
    flag(pps_chroma_tool_offsets_present_flag);
2215
323k
    if (current->pps_chroma_tool_offsets_present_flag) {
2216
188k
        se(pps_cb_qp_offset, -12, 12);
2217
187k
        se(pps_cr_qp_offset, -12, 12);
2218
187k
        flag(pps_joint_cbcr_qp_offset_present_flag);
2219
184k
        if (current->pps_joint_cbcr_qp_offset_present_flag)
2220
184k
            se(pps_joint_cbcr_qp_offset_value, -12, 12);
2221
111k
        else
2222
111k
            infer(pps_joint_cbcr_qp_offset_value, 0);
2223
184k
        flag(pps_slice_chroma_qp_offsets_present_flag);
2224
183k
        flag(pps_cu_chroma_qp_offset_list_enabled_flag);
2225
183k
        if (current->pps_cu_chroma_qp_offset_list_enabled_flag) {
2226
60.5k
            ue(pps_chroma_qp_offset_list_len_minus1, 0, 5);
2227
163k
            for (i = 0; i <= current->pps_chroma_qp_offset_list_len_minus1; i++) {
2228
111k
                ses(pps_cb_qp_offset_list[i], -12, 12, 1, i);
2229
105k
                ses(pps_cr_qp_offset_list[i], -12, 12, 1, i);
2230
104k
                if (current->pps_joint_cbcr_qp_offset_present_flag)
2231
104k
                    ses(pps_joint_cbcr_qp_offset_list[i], -12, 12, 1, i);
2232
36.2k
                else
2233
36.2k
                    infer(pps_joint_cbcr_qp_offset_list[i], 0);
2234
104k
            }
2235
59.1k
        }
2236
183k
    } else {
2237
134k
        infer(pps_cb_qp_offset, 0);
2238
134k
        infer(pps_cr_qp_offset, 0);
2239
134k
        infer(pps_joint_cbcr_qp_offset_present_flag, 0);
2240
134k
        infer(pps_joint_cbcr_qp_offset_value, 0);
2241
134k
        infer(pps_slice_chroma_qp_offsets_present_flag, 0);
2242
134k
        infer(pps_cu_chroma_qp_offset_list_enabled_flag, 0);
2243
2.71k
    }
2244
309k
    flag(pps_deblocking_filter_control_present_flag);
2245
309k
    if (current->pps_deblocking_filter_control_present_flag) {
2246
204k
        flag(pps_deblocking_filter_override_enabled_flag);
2247
204k
        flag(pps_deblocking_filter_disabled_flag);
2248
203k
        if (!current->pps_no_pic_partition_flag &&
2249
125k
            current->pps_deblocking_filter_override_enabled_flag)
2250
203k
            flag(pps_dbf_info_in_ph_flag);
2251
86.0k
        else
2252
86.0k
            infer(pps_dbf_info_in_ph_flag, 0);
2253
203k
        if (!current->pps_deblocking_filter_disabled_flag) {
2254
25.1k
            se(pps_luma_beta_offset_div2, -12, 12);
2255
24.5k
            se(pps_luma_tc_offset_div2, -12, 12);
2256
24.0k
            if (current->pps_chroma_tool_offsets_present_flag) {
2257
18.3k
                se(pps_cb_beta_offset_div2, -12, 12);
2258
16.2k
                se(pps_cb_tc_offset_div2, -12, 12);
2259
15.7k
                se(pps_cr_beta_offset_div2, -12, 12);
2260
15.0k
                se(pps_cr_tc_offset_div2, -12, 12);
2261
15.0k
            } else {
2262
5.61k
                infer(pps_cb_beta_offset_div2,
2263
5.61k
                      current->pps_luma_beta_offset_div2);
2264
5.61k
                infer(pps_cb_tc_offset_div2, current->pps_luma_tc_offset_div2);
2265
5.61k
                infer(pps_cr_beta_offset_div2,
2266
1.07k
                      current->pps_luma_beta_offset_div2);
2267
5.61k
                infer(pps_cr_tc_offset_div2, current->pps_luma_tc_offset_div2);
2268
1.07k
            }
2269
177k
        } else {
2270
177k
            infer(pps_luma_beta_offset_div2, 0);
2271
177k
            infer(pps_luma_tc_offset_div2, 0);
2272
177k
            infer(pps_cb_beta_offset_div2, 0);
2273
177k
            infer(pps_cb_tc_offset_div2, 0);
2274
177k
            infer(pps_cr_beta_offset_div2, 0);
2275
177k
            infer(pps_cr_tc_offset_div2, 0);
2276
2.06k
        }
2277
203k
    } else {
2278
104k
        infer(pps_deblocking_filter_override_enabled_flag, 0);
2279
104k
        infer(pps_deblocking_filter_disabled_flag, 0);
2280
104k
        infer(pps_dbf_info_in_ph_flag, 0);
2281
104k
        infer(pps_luma_beta_offset_div2, 0);
2282
104k
        infer(pps_luma_tc_offset_div2, 0);
2283
104k
        infer(pps_cb_beta_offset_div2, 0);
2284
104k
        infer(pps_cb_tc_offset_div2, 0);
2285
104k
        infer(pps_cr_beta_offset_div2, 0);
2286
104k
        infer(pps_cr_tc_offset_div2, 0);
2287
4.98k
    }
2288
2289
302k
    if (!current->pps_no_pic_partition_flag) {
2290
152k
        flag(pps_rpl_info_in_ph_flag);
2291
151k
        flag(pps_sao_info_in_ph_flag);
2292
151k
        flag(pps_alf_info_in_ph_flag);
2293
150k
        if ((current->pps_weighted_pred_flag ||
2294
28.4k
             current->pps_weighted_bipred_flag) &&
2295
130k
            current->pps_rpl_info_in_ph_flag)
2296
150k
            flag(pps_wp_info_in_ph_flag);
2297
150k
        flag(pps_qp_delta_info_in_ph_flag);
2298
150k
    }
2299
300k
    flag(pps_picture_header_extension_present_flag);
2300
299k
    flag(pps_slice_header_extension_present_flag);
2301
2302
299k
    flag(pps_extension_flag);
2303
299k
    if (current->pps_extension_flag)
2304
262k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2305
2306
299k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2307
294k
    return 0;
2308
299k
}
cbs_h266.c:cbs_h266_read_pps
Line
Count
Source
1676
399k
{
1677
399k
    CodedBitstreamH266Context *h266 = ctx->priv_data;
1678
399k
    const H266RawSPS *sps;
1679
399k
    int err, i;
1680
399k
    unsigned int min_cb_size_y, divisor, ctb_size_y,
1681
399k
        pic_width_in_ctbs_y, pic_height_in_ctbs_y;
1682
399k
    uint8_t sub_width_c, sub_height_c, qp_bd_offset;
1683
1684
399k
    static const uint8_t h266_sub_width_c[] = {
1685
399k
        1, 2, 2, 1
1686
399k
    };
1687
399k
    static const uint8_t h266_sub_height_c[] = {
1688
399k
        1, 2, 1, 1
1689
399k
    };
1690
1691
399k
    HEADER("Picture Parameter Set");
1692
1693
399k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
1694
399k
                                 &current->nal_unit_header, VVC_PPS_NUT));
1695
1696
395k
    ub(6, pps_pic_parameter_set_id);
1697
394k
    ub(4, pps_seq_parameter_set_id);
1698
392k
    sps = h266->sps[current->pps_seq_parameter_set_id];
1699
392k
    if (!sps) {
1700
19.0k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1701
19.0k
               current->pps_seq_parameter_set_id);
1702
19.0k
        return AVERROR_INVALIDDATA;
1703
19.0k
    }
1704
1705
373k
    flag(pps_mixed_nalu_types_in_pic_flag);
1706
373k
    ue(pps_pic_width_in_luma_samples,
1707
365k
       1, sps->sps_pic_width_max_in_luma_samples);
1708
365k
    ue(pps_pic_height_in_luma_samples,
1709
360k
       1, sps->sps_pic_height_max_in_luma_samples);
1710
1711
360k
    min_cb_size_y = 1 << (sps->sps_log2_min_luma_coding_block_size_minus2 + 2);
1712
360k
    divisor = FFMAX(min_cb_size_y, 8);
1713
360k
    if (current->pps_pic_width_in_luma_samples % divisor ||
1714
359k
        current->pps_pic_height_in_luma_samples % divisor) {
1715
2.78k
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1716
2.78k
               "Invalid dimensions: %ux%u not divisible "
1717
2.78k
               "by %u, MinCbSizeY = %u.\n",
1718
2.78k
               current->pps_pic_width_in_luma_samples,
1719
2.78k
               current->pps_pic_height_in_luma_samples, divisor, min_cb_size_y);
1720
2.78k
        return AVERROR_INVALIDDATA;
1721
2.78k
    }
1722
357k
    if (!sps->sps_res_change_in_clvs_allowed_flag &&
1723
77.8k
        (current->pps_pic_width_in_luma_samples !=
1724
77.8k
         sps->sps_pic_width_max_in_luma_samples ||
1725
75.2k
         current->pps_pic_height_in_luma_samples !=
1726
75.2k
         sps->sps_pic_height_max_in_luma_samples)) {
1727
3.51k
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1728
3.51k
               "Resolution change is not allowed, "
1729
3.51k
               "in max resolution (%ux%u) mismatched with pps(%ux%u).\n",
1730
3.51k
               sps->sps_pic_width_max_in_luma_samples,
1731
3.51k
               sps->sps_pic_height_max_in_luma_samples,
1732
3.51k
               current->pps_pic_width_in_luma_samples,
1733
3.51k
               current->pps_pic_height_in_luma_samples);
1734
3.51k
        return AVERROR_INVALIDDATA;
1735
3.51k
    }
1736
1737
354k
    ctb_size_y = 1 << (sps->sps_log2_ctu_size_minus5 + 5);
1738
354k
    if (sps->sps_ref_wraparound_enabled_flag) {
1739
35.0k
        if ((ctb_size_y / min_cb_size_y + 1) >
1740
35.0k
            (current->pps_pic_width_in_luma_samples / min_cb_size_y - 1)) {
1741
830
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1742
830
                   "Invalid width(%u), ctb_size_y = %u, min_cb_size_y = %u.\n",
1743
830
                   current->pps_pic_width_in_luma_samples,
1744
830
                   ctb_size_y, min_cb_size_y);
1745
830
            return AVERROR_INVALIDDATA;
1746
830
        }
1747
35.0k
    }
1748
1749
353k
    flag(pps_conformance_window_flag);
1750
353k
    if (current->pps_pic_width_in_luma_samples ==
1751
353k
        sps->sps_pic_width_max_in_luma_samples &&
1752
78.1k
        current->pps_pic_height_in_luma_samples ==
1753
78.1k
        sps->sps_pic_height_max_in_luma_samples &&
1754
74.5k
        current->pps_conformance_window_flag) {
1755
231
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1756
231
               "Conformance window flag should not true.\n");
1757
231
        return AVERROR_INVALIDDATA;
1758
231
    }
1759
1760
353k
    sub_width_c = h266_sub_width_c[sps->sps_chroma_format_idc];
1761
353k
    sub_height_c = h266_sub_height_c[sps->sps_chroma_format_idc];
1762
353k
    if (current->pps_conformance_window_flag) {
1763
274k
        ue(pps_conf_win_left_offset, 0, current->pps_pic_width_in_luma_samples);
1764
273k
        ue(pps_conf_win_right_offset,
1765
273k
           0, current->pps_pic_width_in_luma_samples);
1766
273k
        ue(pps_conf_win_top_offset, 0, current->pps_pic_height_in_luma_samples);
1767
273k
        ue(pps_conf_win_bottom_offset,
1768
272k
           0, current->pps_pic_height_in_luma_samples);
1769
272k
        if (sub_width_c *
1770
272k
            (current->pps_conf_win_left_offset +
1771
272k
             current->pps_conf_win_right_offset) >=
1772
272k
            current->pps_pic_width_in_luma_samples ||
1773
271k
            sub_height_c *
1774
271k
            (current->pps_conf_win_top_offset +
1775
271k
             current->pps_conf_win_bottom_offset) >=
1776
271k
            current->pps_pic_height_in_luma_samples) {
1777
823
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1778
823
                   "Invalid pps conformance window: (%u, %u, %u, %u), "
1779
823
                   "resolution is %ux%u, sub wxh is %ux%u.\n",
1780
823
                   current->pps_conf_win_left_offset,
1781
823
                   current->pps_conf_win_right_offset,
1782
823
                   current->pps_conf_win_top_offset,
1783
823
                   current->pps_conf_win_bottom_offset,
1784
823
                   current->pps_pic_width_in_luma_samples,
1785
823
                   current->pps_pic_height_in_luma_samples,
1786
823
                   sub_width_c, sub_height_c);
1787
823
            return AVERROR_INVALIDDATA;
1788
823
        }
1789
272k
    } else {
1790
78.9k
        if (current->pps_pic_width_in_luma_samples ==
1791
78.9k
            sps->sps_pic_width_max_in_luma_samples &&
1792
75.8k
            current->pps_pic_height_in_luma_samples ==
1793
75.8k
            sps->sps_pic_height_max_in_luma_samples) {
1794
74.3k
            infer(pps_conf_win_left_offset, sps->sps_conf_win_left_offset);
1795
74.3k
            infer(pps_conf_win_right_offset, sps->sps_conf_win_right_offset);
1796
74.3k
            infer(pps_conf_win_top_offset, sps->sps_conf_win_top_offset);
1797
74.3k
            infer(pps_conf_win_bottom_offset, sps->sps_conf_win_bottom_offset);
1798
74.3k
        } else {
1799
4.61k
            infer(pps_conf_win_left_offset, 0);
1800
4.61k
            infer(pps_conf_win_right_offset, 0);
1801
4.61k
            infer(pps_conf_win_top_offset, 0);
1802
4.61k
            infer(pps_conf_win_bottom_offset, 0);
1803
4.61k
        }
1804
1805
78.9k
    }
1806
1807
350k
    flag(pps_scaling_window_explicit_signalling_flag);
1808
350k
    if (!sps->sps_ref_pic_resampling_enabled_flag &&
1809
3.04k
        current->pps_scaling_window_explicit_signalling_flag) {
1810
2
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1811
2
               "Invalid data: sps_ref_pic_resampling_enabled_flag is false, "
1812
2
               "but pps_scaling_window_explicit_signalling_flag is true.\n");
1813
2
        return AVERROR_INVALIDDATA;
1814
2
    }
1815
350k
    if (current->pps_scaling_window_explicit_signalling_flag) {
1816
280k
        se(pps_scaling_win_left_offset,
1817
280k
           -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1818
280k
           current->pps_pic_width_in_luma_samples / sub_width_c);
1819
280k
        se(pps_scaling_win_right_offset,
1820
271k
           -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1821
271k
           current->pps_pic_width_in_luma_samples / sub_width_c);
1822
271k
        se(pps_scaling_win_top_offset,
1823
271k
           -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1824
271k
           current->pps_pic_height_in_luma_samples / sub_height_c);
1825
271k
        se(pps_scaling_win_bottom_offset,
1826
271k
           -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1827
271k
           current->pps_pic_height_in_luma_samples / sub_height_c);
1828
271k
    } else {
1829
69.8k
        infer(pps_scaling_win_left_offset, current->pps_conf_win_left_offset);
1830
69.8k
        infer(pps_scaling_win_right_offset, current->pps_conf_win_right_offset);
1831
69.8k
        infer(pps_scaling_win_top_offset, current->pps_conf_win_top_offset);
1832
69.8k
        infer(pps_scaling_win_bottom_offset, current->pps_conf_win_bottom_offset);
1833
69.8k
    }
1834
1835
340k
    flag(pps_output_flag_present_flag);
1836
340k
    flag(pps_no_pic_partition_flag);
1837
339k
    flag(pps_subpic_id_mapping_present_flag);
1838
1839
339k
    if (current->pps_subpic_id_mapping_present_flag) {
1840
159k
        if (!current->pps_no_pic_partition_flag) {
1841
21.9k
            ue(pps_num_subpics_minus1,
1842
21.9k
               sps->sps_num_subpics_minus1, sps->sps_num_subpics_minus1);
1843
137k
        } else {
1844
137k
            infer(pps_num_subpics_minus1, 0);
1845
137k
        }
1846
158k
        ue(pps_subpic_id_len_minus1, sps->sps_subpic_id_len_minus1,
1847
156k
           sps->sps_subpic_id_len_minus1);
1848
329k
        for (i = 0; i <= current->pps_num_subpics_minus1; i++) {
1849
173k
            ubs(sps->sps_subpic_id_len_minus1 + 1, pps_subpic_id[i], 1, i);
1850
173k
        }
1851
156k
    }
1852
1853
734k
    for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
1854
397k
        if (sps->sps_subpic_id_mapping_explicitly_signalled_flag)
1855
46.7k
            current->sub_pic_id_val[i] = current->pps_subpic_id_mapping_present_flag
1856
46.7k
                                       ? current->pps_subpic_id[i]
1857
46.7k
                                       : sps->sps_subpic_id[i];
1858
350k
        else
1859
350k
            current->sub_pic_id_val[i] = i;
1860
397k
    }
1861
1862
336k
    pic_width_in_ctbs_y = AV_CEIL_RSHIFT
1863
336k
        (current->pps_pic_width_in_luma_samples, (sps->sps_log2_ctu_size_minus5 + 5));
1864
336k
    pic_height_in_ctbs_y = AV_CEIL_RSHIFT(
1865
336k
        current->pps_pic_height_in_luma_samples,(sps->sps_log2_ctu_size_minus5 + 5));
1866
336k
    if (!current->pps_no_pic_partition_flag) {
1867
166k
        unsigned int exp_tile_width = 0, exp_tile_height = 0;
1868
166k
        unsigned int unified_size, remaining_size;
1869
1870
166k
        u(2, pps_log2_ctu_size_minus5,
1871
163k
          sps->sps_log2_ctu_size_minus5, sps->sps_log2_ctu_size_minus5);
1872
163k
        ue(pps_num_exp_tile_columns_minus1,
1873
162k
           0, FFMIN(pic_width_in_ctbs_y - 1, VVC_MAX_TILE_COLUMNS - 1));
1874
162k
        ue(pps_num_exp_tile_rows_minus1,
1875
162k
           0, FFMIN(pic_height_in_ctbs_y - 1, VVC_MAX_TILE_ROWS - 1));
1876
1877
382k
        for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1878
221k
            ues(pps_tile_column_width_minus1[i],
1879
219k
                0, pic_width_in_ctbs_y - exp_tile_width - 1, 1, i);
1880
219k
            exp_tile_width += current->pps_tile_column_width_minus1[i] + 1;
1881
219k
        }
1882
335k
        for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1883
175k
            ues(pps_tile_row_height_minus1[i],
1884
174k
                0, pic_height_in_ctbs_y - exp_tile_height - 1, 1, i);
1885
174k
            exp_tile_height += current->pps_tile_row_height_minus1[i] + 1;
1886
174k
        }
1887
1888
160k
        remaining_size = pic_width_in_ctbs_y;
1889
374k
        for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1890
214k
          if (current->pps_tile_column_width_minus1[i] >= remaining_size) {
1891
208
              av_log(ctx->log_ctx, AV_LOG_ERROR,
1892
208
                     "Tile column width(%d) exceeds picture width\n",i);
1893
208
              return AVERROR_INVALIDDATA;
1894
208
          }
1895
214k
          current->col_width_val[i] = current->pps_tile_column_width_minus1[i] + 1;
1896
214k
          remaining_size -= (current->pps_tile_column_width_minus1[i] + 1);
1897
214k
        }
1898
159k
        unified_size = current->pps_tile_column_width_minus1[i - 1] + 1;
1899
297k
        while (remaining_size > 0) {
1900
137k
            if (i == VVC_MAX_TILE_COLUMNS) {
1901
238
                av_log(ctx->log_ctx, AV_LOG_ERROR,
1902
238
                       "Exceeded maximum tile columns (%d) (remaining size: %u)\n",
1903
238
                       VVC_MAX_TILE_COLUMNS, remaining_size);
1904
238
                return AVERROR_INVALIDDATA;
1905
238
            }
1906
137k
            unified_size = FFMIN(remaining_size, unified_size);
1907
137k
            current->col_width_val[i] = unified_size;
1908
137k
            remaining_size -= unified_size;
1909
137k
            i++;
1910
137k
        }
1911
159k
        current->num_tile_columns = i;
1912
1913
159k
        remaining_size = pic_height_in_ctbs_y;
1914
333k
        for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1915
173k
          if (current->pps_tile_row_height_minus1[i] >= remaining_size) {
1916
205
              av_log(ctx->log_ctx, AV_LOG_ERROR,
1917
205
                     "Tile row height(%d) exceeds picture height\n",i);
1918
205
              return AVERROR_INVALIDDATA;
1919
205
          }
1920
173k
          current->row_height_val[i] = current->pps_tile_row_height_minus1[i] + 1;
1921
173k
          remaining_size -= (current->pps_tile_row_height_minus1[i] + 1);
1922
173k
        }
1923
159k
        unified_size = current->pps_tile_row_height_minus1[i - 1] + 1;
1924
1925
289k
        while (remaining_size > 0) {
1926
129k
            if (i == VVC_MAX_TILE_ROWS) {
1927
0
                av_log(ctx->log_ctx, AV_LOG_ERROR,
1928
0
                       "Exceeded maximum tile rows (%d) (remaining size: %u)\n",
1929
0
                       VVC_MAX_TILE_ROWS, remaining_size);
1930
0
                return AVERROR_INVALIDDATA;
1931
0
            }
1932
129k
            unified_size = FFMIN(remaining_size, unified_size);
1933
129k
            current->row_height_val[i] = unified_size;
1934
129k
            remaining_size -= unified_size;
1935
129k
            i++;
1936
129k
        }
1937
159k
        current->num_tile_rows=i;
1938
1939
159k
        current->num_tiles_in_pic = current->num_tile_columns *
1940
159k
                                    current->num_tile_rows;
1941
159k
        if (current->num_tiles_in_pic > VVC_MAX_TILES_PER_AU) {
1942
213
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1943
213
                   "NumTilesInPic(%d) > than VVC_MAX_TILES_PER_AU(%d)\n",
1944
213
                   current->num_tiles_in_pic, VVC_MAX_TILES_PER_AU);
1945
213
            return AVERROR_INVALIDDATA;
1946
213
        }
1947
1948
159k
        if (current->num_tiles_in_pic > 1) {
1949
31.9k
            flag(pps_loop_filter_across_tiles_enabled_flag);
1950
31.7k
            flag(pps_rect_slice_flag);
1951
127k
        } else {
1952
127k
            infer(pps_loop_filter_across_tiles_enabled_flag, 0);
1953
127k
            infer(pps_rect_slice_flag, 1);
1954
127k
        }
1955
158k
        if (current->pps_rect_slice_flag)
1956
158k
            flag(pps_single_slice_per_subpic_flag);
1957
4.19k
        else
1958
4.19k
            infer(pps_single_slice_per_subpic_flag, 1);
1959
158k
        if (current->pps_rect_slice_flag &&
1960
154k
            !current->pps_single_slice_per_subpic_flag) {
1961
27.2k
            int j, num_slices = 0;
1962
27.2k
            uint16_t tile_idx = 0, tile_x, tile_y, ctu_x, ctu_y;
1963
27.2k
            uint16_t slice_top_left_ctu_x[VVC_MAX_SLICES];
1964
27.2k
            uint16_t slice_top_left_ctu_y[VVC_MAX_SLICES];
1965
27.2k
            ue(pps_num_slices_in_pic_minus1, 0, VVC_MAX_SLICES - 1);
1966
26.9k
            if (current->pps_num_slices_in_pic_minus1 > 1)
1967
26.9k
                flag(pps_tile_idx_delta_present_flag);
1968
12.0k
            else
1969
12.0k
                infer(pps_tile_idx_delta_present_flag, 0);
1970
109k
            for (i = 0; i < current->pps_num_slices_in_pic_minus1; i++) {
1971
88.3k
                current->slice_top_left_tile_idx[i] = tile_idx;
1972
88.3k
                tile_x = tile_idx % current->num_tile_columns;
1973
88.3k
                tile_y = tile_idx / current->num_tile_columns;
1974
88.3k
                if (tile_y >= current->num_tile_rows)
1975
590
                    return AVERROR_INVALIDDATA;
1976
87.7k
                if (tile_x != current->num_tile_columns - 1) {
1977
54.4k
                    ues(pps_slice_width_in_tiles_minus1[i],
1978
54.4k
                        0, current->num_tile_columns - 1 - tile_x, 1, i);
1979
54.4k
                } else {
1980
33.2k
                    infer(pps_slice_width_in_tiles_minus1[i], 0);
1981
33.2k
                }
1982
85.6k
                if (tile_y != current->num_tile_rows - 1 &&
1983
52.1k
                    (current->pps_tile_idx_delta_present_flag || tile_x == 0)) {
1984
42.0k
                    ues(pps_slice_height_in_tiles_minus1[i],
1985
42.0k
                        0, current->num_tile_rows - 1 - tile_y, 1, i);
1986
43.5k
                } else {
1987
43.5k
                    if (tile_y == current->num_tile_rows - 1)
1988
33.5k
                        infer(pps_slice_height_in_tiles_minus1[i], 0);
1989
10.0k
                    else
1990
10.0k
                        infer(pps_slice_height_in_tiles_minus1[i],
1991
43.5k
                              current->pps_slice_height_in_tiles_minus1[i - 1]);
1992
43.5k
                }
1993
1994
85.3k
                ctu_x = ctu_y = 0;
1995
152k
                for (j = 0; j < tile_x; j++) {
1996
66.8k
                    ctu_x += current->col_width_val[j];
1997
66.8k
                }
1998
143k
                for (j = 0; j < tile_y; j++) {
1999
58.0k
                    ctu_y += current->row_height_val[j];
2000
58.0k
                }
2001
85.3k
                if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
2002
70.0k
                    current->pps_slice_height_in_tiles_minus1[i] == 0 &&
2003
65.5k
                    current->row_height_val[tile_y] > 1) {
2004
42.2k
                    int uniform_slice_height, remaining_height_in_ctbs_y;
2005
42.2k
                    remaining_height_in_ctbs_y =
2006
42.2k
                        current->row_height_val[tile_y];
2007
42.2k
                    ues(pps_num_exp_slices_in_tile[i],
2008
42.0k
                        0, current->row_height_val[tile_y] - 1, 1, i);
2009
42.0k
                    if (current->pps_num_exp_slices_in_tile[i] == 0) {
2010
18.1k
                        current->num_slices_in_tile[i] = 1;
2011
18.1k
                        current->slice_height_in_ctus[i] = current->row_height_val[tile_y];
2012
18.1k
                        slice_top_left_ctu_x[i] = ctu_x;
2013
18.1k
                        slice_top_left_ctu_y[i] = ctu_y;
2014
23.9k
                    } else {
2015
23.9k
                        uint16_t slice_height_in_ctus;
2016
23.9k
                        int num_uniform_slices;
2017
2018
23.9k
                        if (i + current->pps_num_exp_slices_in_tile[i] >
2019
23.9k
                            current->pps_num_slices_in_pic_minus1 + 1)
2020
194
                            return AVERROR_INVALIDDATA;
2021
2022
55.8k
                        for (j = 0; j < current->pps_num_exp_slices_in_tile[i];
2023
32.3k
                             j++) {
2024
32.3k
                            ues(pps_exp_slice_height_in_ctus_minus1[i][j], 0,
2025
32.1k
                                remaining_height_in_ctbs_y - 1, 2,
2026
32.1k
                                i, j);
2027
32.1k
                            slice_height_in_ctus =
2028
32.1k
                                current->
2029
32.1k
                                pps_exp_slice_height_in_ctus_minus1[i][j] + 1;
2030
2031
32.1k
                            current->slice_height_in_ctus[i + j] =
2032
32.1k
                                slice_height_in_ctus;
2033
32.1k
                            slice_top_left_ctu_x[i + j] = ctu_x;
2034
32.1k
                            slice_top_left_ctu_y[i + j] = ctu_y;
2035
32.1k
                            ctu_y += slice_height_in_ctus;
2036
2037
32.1k
                            remaining_height_in_ctbs_y -= slice_height_in_ctus;
2038
32.1k
                        }
2039
23.4k
                        uniform_slice_height = 1 +
2040
23.4k
                            (j == 0 ? current->row_height_val[tile_y] - 1:
2041
23.4k
                            current->pps_exp_slice_height_in_ctus_minus1[i][j-1]);
2042
2043
23.4k
                        num_uniform_slices = (remaining_height_in_ctbs_y + uniform_slice_height - 1)
2044
23.4k
                                           / uniform_slice_height;
2045
23.4k
                        if (i + current->pps_num_exp_slices_in_tile[i] + num_uniform_slices >
2046
23.4k
                            current->pps_num_slices_in_pic_minus1 + 1)
2047
199
                            return AVERROR_INVALIDDATA;
2048
2049
26.0k
                        while (remaining_height_in_ctbs_y > uniform_slice_height) {
2050
2.78k
                            current->slice_height_in_ctus[i + j] =
2051
2.78k
                                                          uniform_slice_height;
2052
2.78k
                            slice_top_left_ctu_x[i + j] = ctu_x;
2053
2.78k
                            slice_top_left_ctu_y[i + j] = ctu_y;
2054
2.78k
                            ctu_y += uniform_slice_height;
2055
2056
2.78k
                            remaining_height_in_ctbs_y -= uniform_slice_height;
2057
2.78k
                            j++;
2058
2.78k
                        }
2059
23.2k
                        if (remaining_height_in_ctbs_y > 0) {
2060
15.1k
                            current->slice_height_in_ctus[i + j] =
2061
15.1k
                                remaining_height_in_ctbs_y;
2062
15.1k
                            slice_top_left_ctu_x[i + j] = ctu_x;
2063
15.1k
                            slice_top_left_ctu_y[i + j] = ctu_y;
2064
15.1k
                            j++;
2065
15.1k
                        }
2066
23.2k
                        current->num_slices_in_tile[i] = j;
2067
23.2k
                    }
2068
109k
                    for (int k = 0; k < current->num_slices_in_tile[i]; k++)
2069
67.9k
                        current->slice_top_left_tile_idx[i + k] = tile_idx;
2070
41.3k
                    i += current->num_slices_in_tile[i] - 1;
2071
43.0k
                } else {
2072
43.0k
                    uint16_t height = 0;
2073
43.0k
                    infer(pps_num_exp_slices_in_tile[i], 0);
2074
43.0k
                    if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
2075
27.7k
                        current->pps_slice_height_in_tiles_minus1[i] == 0)
2076
23.2k
                        current->num_slices_in_tile[i] = 1;
2077
2078
43.0k
                    for (j = 0;
2079
96.2k
                         j <= current->pps_slice_height_in_tiles_minus1[i];
2080
53.1k
                         j++) {
2081
53.1k
                        height +=
2082
53.1k
                           current->row_height_val[tile_y + j];
2083
53.1k
                    }
2084
43.0k
                    current->slice_height_in_ctus[i] = height;
2085
2086
43.0k
                    slice_top_left_ctu_x[i] = ctu_x;
2087
43.0k
                    slice_top_left_ctu_y[i] = ctu_y;
2088
43.0k
                }
2089
84.4k
                if (i < current->pps_num_slices_in_pic_minus1) {
2090
84.0k
                    if (current->pps_tile_idx_delta_present_flag) {
2091
                        // Two conditions must be met:
2092
                        // 1. −NumTilesInPic + 1 <= pps_tile_idx_delta_val[i] <= NumTilesInPic − 1
2093
                        // 2. 0 <= tile_idx + pps_tile_idx_delta_val[i] <= NumTilesInPic − 1
2094
                        // Combining these conditions yields: -tile_idx <= pps_tile_idx_delta_val[i] <= NumTilesInPic - 1 - tile_idx
2095
62.7k
                        ses(pps_tile_idx_delta_val[i],
2096
61.4k
                            -tile_idx, current->num_tiles_in_pic - 1 - tile_idx, 1, i);
2097
61.4k
                        if (current->pps_tile_idx_delta_val[i] == 0) {
2098
25.9k
                            av_log(ctx->log_ctx, AV_LOG_ERROR,
2099
25.9k
                                   "pps_tile_idx_delta_val[i] shall not be equal to 0.\n");
2100
25.9k
                        }
2101
61.4k
                        tile_idx += current->pps_tile_idx_delta_val[i];
2102
61.4k
                    } else {
2103
21.2k
                        infer(pps_tile_idx_delta_val[i], 0);
2104
21.2k
                        tile_idx +=
2105
21.2k
                            current->pps_slice_width_in_tiles_minus1[i] + 1;
2106
21.2k
                        if (tile_idx % current->num_tile_columns == 0) {
2107
7.21k
                            tile_idx +=
2108
7.21k
                                current->pps_slice_height_in_tiles_minus1[i] *
2109
7.21k
                                current->num_tile_columns;
2110
7.21k
                        }
2111
21.2k
                    }
2112
84.0k
                }
2113
84.4k
            }
2114
21.4k
            if (i == current->pps_num_slices_in_pic_minus1) {
2115
21.0k
                uint16_t height = 0;
2116
2117
21.0k
                current->slice_top_left_tile_idx[i] = tile_idx;
2118
21.0k
                current->num_slices_in_tile[i] = 1;
2119
21.0k
                tile_x = tile_idx % current->num_tile_columns;
2120
21.0k
                tile_y = tile_idx / current->num_tile_columns;
2121
21.0k
                if (tile_y >= current->num_tile_rows)
2122
115
                    return AVERROR_INVALIDDATA;
2123
2124
20.9k
                ctu_x = 0, ctu_y = 0;
2125
34.8k
                for (j = 0; j < tile_x; j++) {
2126
13.9k
                    ctu_x += current->col_width_val[j];
2127
13.9k
                }
2128
35.2k
                for (j = 0; j < tile_y; j++) {
2129
14.3k
                    ctu_y += current->row_height_val[j];
2130
14.3k
                }
2131
20.9k
                slice_top_left_ctu_x[i] = ctu_x;
2132
20.9k
                slice_top_left_ctu_y[i] = ctu_y;
2133
2134
20.9k
                current->pps_slice_width_in_tiles_minus1[i] =
2135
20.9k
                    current->num_tile_columns - tile_x - 1;
2136
20.9k
                current->pps_slice_height_in_tiles_minus1[i] =
2137
20.9k
                    current->num_tile_rows - tile_y - 1;
2138
2139
112k
                for (j = 0; j <= current->pps_slice_height_in_tiles_minus1[i];
2140
91.3k
                     j++) {
2141
91.3k
                    height +=
2142
91.3k
                        current->row_height_val[tile_y + j];
2143
91.3k
                }
2144
20.9k
                current->slice_height_in_ctus[i] = height;
2145
2146
20.9k
                infer(pps_num_exp_slices_in_tile[i], 0);
2147
20.9k
            }
2148
            //now, we got all slice information, let's resolve NumSlicesInSubpic
2149
66.4k
            for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
2150
45.0k
                current->num_slices_in_subpic[i] = 0;
2151
287k
                for (j = 0; j <= current->pps_num_slices_in_pic_minus1; j++) {
2152
242k
                    uint16_t pos_x = 0, pos_y = 0;
2153
242k
                    pos_x = slice_top_left_ctu_x[j];
2154
242k
                    pos_y = slice_top_left_ctu_y[j];
2155
242k
                    if ((pos_x >= sps->sps_subpic_ctu_top_left_x[i]) &&
2156
167k
                        (pos_x <
2157
167k
                         sps->sps_subpic_ctu_top_left_x[i] +
2158
167k
                         sps->sps_subpic_width_minus1[i] + 1) &&
2159
147k
                         (pos_y >= sps->sps_subpic_ctu_top_left_y[i]) &&
2160
119k
                         (pos_y < sps->sps_subpic_ctu_top_left_y[i] +
2161
119k
                            sps->sps_subpic_height_minus1[i] + 1)) {
2162
109k
                        current->num_slices_in_subpic[i]++;
2163
109k
                    }
2164
242k
                }
2165
45.0k
                num_slices += current->num_slices_in_subpic[i];
2166
45.0k
            }
2167
21.3k
            if (current->pps_num_slices_in_pic_minus1 + 1 != num_slices)
2168
370
                return AVERROR_INVALIDDATA;
2169
131k
        } else {
2170
131k
            if (current->pps_no_pic_partition_flag)
2171
0
                infer(pps_num_slices_in_pic_minus1, 0);
2172
131k
            else if (current->pps_single_slice_per_subpic_flag) {
2173
280k
                for (i = 0; i <= sps->sps_num_subpics_minus1; i++)
2174
149k
                    current->num_slices_in_subpic[i] = 1;
2175
131k
                infer(pps_num_slices_in_pic_minus1,
2176
131k
                      sps->sps_num_subpics_minus1);
2177
131k
            }
2178
            // else?
2179
131k
        }
2180
152k
        if (!current->pps_rect_slice_flag ||
2181
148k
            current->pps_single_slice_per_subpic_flag ||
2182
20.9k
            current->pps_num_slices_in_pic_minus1 > 0)
2183
152k
            flag(pps_loop_filter_across_slices_enabled_flag);
2184
11.2k
        else
2185
11.2k
            infer(pps_loop_filter_across_slices_enabled_flag, 0);
2186
170k
    } else {
2187
170k
        infer(pps_num_exp_tile_columns_minus1, 0);
2188
170k
        infer(pps_tile_column_width_minus1[0], pic_width_in_ctbs_y - 1);
2189
170k
        infer(pps_num_exp_tile_rows_minus1, 0);
2190
170k
        infer(pps_tile_row_height_minus1[0], pic_height_in_ctbs_y - 1);
2191
170k
        current->col_width_val[0] = pic_width_in_ctbs_y;
2192
170k
        current->row_height_val[0] = pic_height_in_ctbs_y;
2193
170k
        current->num_tile_columns = 1;
2194
170k
        current->num_tile_rows = 1;
2195
170k
        current->num_tiles_in_pic = 1;
2196
170k
    }
2197
2198
322k
    flag(pps_cabac_init_present_flag);
2199
963k
    for (i = 0; i < 2; i++)
2200
643k
        ues(pps_num_ref_idx_default_active_minus1[i], 0, 14, 1, i);
2201
320k
    flag(pps_rpl1_idx_present_flag);
2202
320k
    flag(pps_weighted_pred_flag);
2203
319k
    flag(pps_weighted_bipred_flag);
2204
319k
    flag(pps_ref_wraparound_enabled_flag);
2205
319k
    if (current->pps_ref_wraparound_enabled_flag) {
2206
253k
        ue(pps_pic_width_minus_wraparound_offset,
2207
253k
           0, (current->pps_pic_width_in_luma_samples / min_cb_size_y)
2208
253k
           - (ctb_size_y / min_cb_size_y) - 2);
2209
253k
    }
2210
2211
317k
    qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2212
317k
    se(pps_init_qp_minus26, -(26 + qp_bd_offset), 37);
2213
316k
    flag(pps_cu_qp_delta_enabled_flag);
2214
313k
    flag(pps_chroma_tool_offsets_present_flag);
2215
313k
    if (current->pps_chroma_tool_offsets_present_flag) {
2216
181k
        se(pps_cb_qp_offset, -12, 12);
2217
180k
        se(pps_cr_qp_offset, -12, 12);
2218
180k
        flag(pps_joint_cbcr_qp_offset_present_flag);
2219
177k
        if (current->pps_joint_cbcr_qp_offset_present_flag)
2220
177k
            se(pps_joint_cbcr_qp_offset_value, -12, 12);
2221
108k
        else
2222
108k
            infer(pps_joint_cbcr_qp_offset_value, 0);
2223
177k
        flag(pps_slice_chroma_qp_offsets_present_flag);
2224
176k
        flag(pps_cu_chroma_qp_offset_list_enabled_flag);
2225
176k
        if (current->pps_cu_chroma_qp_offset_list_enabled_flag) {
2226
58.3k
            ue(pps_chroma_qp_offset_list_len_minus1, 0, 5);
2227
156k
            for (i = 0; i <= current->pps_chroma_qp_offset_list_len_minus1; i++) {
2228
106k
                ses(pps_cb_qp_offset_list[i], -12, 12, 1, i);
2229
100k
                ses(pps_cr_qp_offset_list[i], -12, 12, 1, i);
2230
99.7k
                if (current->pps_joint_cbcr_qp_offset_present_flag)
2231
99.7k
                    ses(pps_joint_cbcr_qp_offset_list[i], -12, 12, 1, i);
2232
34.9k
                else
2233
34.9k
                    infer(pps_joint_cbcr_qp_offset_list[i], 0);
2234
99.7k
            }
2235
56.9k
        }
2236
176k
    } else {
2237
131k
        infer(pps_cb_qp_offset, 0);
2238
131k
        infer(pps_cr_qp_offset, 0);
2239
131k
        infer(pps_joint_cbcr_qp_offset_present_flag, 0);
2240
131k
        infer(pps_joint_cbcr_qp_offset_value, 0);
2241
131k
        infer(pps_slice_chroma_qp_offsets_present_flag, 0);
2242
131k
        infer(pps_cu_chroma_qp_offset_list_enabled_flag, 0);
2243
131k
    }
2244
300k
    flag(pps_deblocking_filter_control_present_flag);
2245
299k
    if (current->pps_deblocking_filter_control_present_flag) {
2246
199k
        flag(pps_deblocking_filter_override_enabled_flag);
2247
199k
        flag(pps_deblocking_filter_disabled_flag);
2248
198k
        if (!current->pps_no_pic_partition_flag &&
2249
122k
            current->pps_deblocking_filter_override_enabled_flag)
2250
198k
            flag(pps_dbf_info_in_ph_flag);
2251
83.6k
        else
2252
83.6k
            infer(pps_dbf_info_in_ph_flag, 0);
2253
198k
        if (!current->pps_deblocking_filter_disabled_flag) {
2254
22.4k
            se(pps_luma_beta_offset_div2, -12, 12);
2255
21.8k
            se(pps_luma_tc_offset_div2, -12, 12);
2256
21.3k
            if (current->pps_chroma_tool_offsets_present_flag) {
2257
16.7k
                se(pps_cb_beta_offset_div2, -12, 12);
2258
14.5k
                se(pps_cb_tc_offset_div2, -12, 12);
2259
14.0k
                se(pps_cr_beta_offset_div2, -12, 12);
2260
13.4k
                se(pps_cr_tc_offset_div2, -12, 12);
2261
13.4k
            } else {
2262
4.54k
                infer(pps_cb_beta_offset_div2,
2263
4.54k
                      current->pps_luma_beta_offset_div2);
2264
4.54k
                infer(pps_cb_tc_offset_div2, current->pps_luma_tc_offset_div2);
2265
4.54k
                infer(pps_cr_beta_offset_div2,
2266
4.54k
                      current->pps_luma_beta_offset_div2);
2267
4.54k
                infer(pps_cr_tc_offset_div2, current->pps_luma_tc_offset_div2);
2268
4.54k
            }
2269
175k
        } else {
2270
175k
            infer(pps_luma_beta_offset_div2, 0);
2271
175k
            infer(pps_luma_tc_offset_div2, 0);
2272
175k
            infer(pps_cb_beta_offset_div2, 0);
2273
175k
            infer(pps_cb_tc_offset_div2, 0);
2274
175k
            infer(pps_cr_beta_offset_div2, 0);
2275
175k
            infer(pps_cr_tc_offset_div2, 0);
2276
175k
        }
2277
198k
    } else {
2278
99.9k
        infer(pps_deblocking_filter_override_enabled_flag, 0);
2279
99.9k
        infer(pps_deblocking_filter_disabled_flag, 0);
2280
99.9k
        infer(pps_dbf_info_in_ph_flag, 0);
2281
99.9k
        infer(pps_luma_beta_offset_div2, 0);
2282
99.9k
        infer(pps_luma_tc_offset_div2, 0);
2283
99.9k
        infer(pps_cb_beta_offset_div2, 0);
2284
99.9k
        infer(pps_cb_tc_offset_div2, 0);
2285
99.9k
        infer(pps_cr_beta_offset_div2, 0);
2286
99.9k
        infer(pps_cr_tc_offset_div2, 0);
2287
99.9k
    }
2288
2289
292k
    if (!current->pps_no_pic_partition_flag) {
2290
146k
        flag(pps_rpl_info_in_ph_flag);
2291
146k
        flag(pps_sao_info_in_ph_flag);
2292
145k
        flag(pps_alf_info_in_ph_flag);
2293
144k
        if ((current->pps_weighted_pred_flag ||
2294
24.6k
             current->pps_weighted_bipred_flag) &&
2295
127k
            current->pps_rpl_info_in_ph_flag)
2296
144k
            flag(pps_wp_info_in_ph_flag);
2297
144k
        flag(pps_qp_delta_info_in_ph_flag);
2298
144k
    }
2299
290k
    flag(pps_picture_header_extension_present_flag);
2300
290k
    flag(pps_slice_header_extension_present_flag);
2301
2302
289k
    flag(pps_extension_flag);
2303
289k
    if (current->pps_extension_flag)
2304
256k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2305
2306
289k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2307
285k
    return 0;
2308
289k
}
cbs_h266.c:cbs_h266_write_pps
Line
Count
Source
1676
14.4k
{
1677
14.4k
    CodedBitstreamH266Context *h266 = ctx->priv_data;
1678
14.4k
    const H266RawSPS *sps;
1679
14.4k
    int err, i;
1680
14.4k
    unsigned int min_cb_size_y, divisor, ctb_size_y,
1681
14.4k
        pic_width_in_ctbs_y, pic_height_in_ctbs_y;
1682
14.4k
    uint8_t sub_width_c, sub_height_c, qp_bd_offset;
1683
1684
14.4k
    static const uint8_t h266_sub_width_c[] = {
1685
14.4k
        1, 2, 2, 1
1686
14.4k
    };
1687
14.4k
    static const uint8_t h266_sub_height_c[] = {
1688
14.4k
        1, 2, 1, 1
1689
14.4k
    };
1690
1691
14.4k
    HEADER("Picture Parameter Set");
1692
1693
14.4k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
1694
14.4k
                                 &current->nal_unit_header, VVC_PPS_NUT));
1695
1696
14.4k
    ub(6, pps_pic_parameter_set_id);
1697
14.4k
    ub(4, pps_seq_parameter_set_id);
1698
14.4k
    sps = h266->sps[current->pps_seq_parameter_set_id];
1699
14.4k
    if (!sps) {
1700
412
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1701
412
               current->pps_seq_parameter_set_id);
1702
412
        return AVERROR_INVALIDDATA;
1703
412
    }
1704
1705
14.0k
    flag(pps_mixed_nalu_types_in_pic_flag);
1706
14.0k
    ue(pps_pic_width_in_luma_samples,
1707
13.8k
       1, sps->sps_pic_width_max_in_luma_samples);
1708
13.8k
    ue(pps_pic_height_in_luma_samples,
1709
13.5k
       1, sps->sps_pic_height_max_in_luma_samples);
1710
1711
13.5k
    min_cb_size_y = 1 << (sps->sps_log2_min_luma_coding_block_size_minus2 + 2);
1712
13.5k
    divisor = FFMAX(min_cb_size_y, 8);
1713
13.5k
    if (current->pps_pic_width_in_luma_samples % divisor ||
1714
13.5k
        current->pps_pic_height_in_luma_samples % divisor) {
1715
196
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1716
196
               "Invalid dimensions: %ux%u not divisible "
1717
196
               "by %u, MinCbSizeY = %u.\n",
1718
196
               current->pps_pic_width_in_luma_samples,
1719
196
               current->pps_pic_height_in_luma_samples, divisor, min_cb_size_y);
1720
196
        return AVERROR_INVALIDDATA;
1721
196
    }
1722
13.3k
    if (!sps->sps_res_change_in_clvs_allowed_flag &&
1723
12.3k
        (current->pps_pic_width_in_luma_samples !=
1724
12.3k
         sps->sps_pic_width_max_in_luma_samples ||
1725
11.8k
         current->pps_pic_height_in_luma_samples !=
1726
11.8k
         sps->sps_pic_height_max_in_luma_samples)) {
1727
781
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1728
781
               "Resolution change is not allowed, "
1729
781
               "in max resolution (%ux%u) mismatched with pps(%ux%u).\n",
1730
781
               sps->sps_pic_width_max_in_luma_samples,
1731
781
               sps->sps_pic_height_max_in_luma_samples,
1732
781
               current->pps_pic_width_in_luma_samples,
1733
781
               current->pps_pic_height_in_luma_samples);
1734
781
        return AVERROR_INVALIDDATA;
1735
781
    }
1736
1737
12.6k
    ctb_size_y = 1 << (sps->sps_log2_ctu_size_minus5 + 5);
1738
12.6k
    if (sps->sps_ref_wraparound_enabled_flag) {
1739
4.58k
        if ((ctb_size_y / min_cb_size_y + 1) >
1740
4.58k
            (current->pps_pic_width_in_luma_samples / min_cb_size_y - 1)) {
1741
196
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1742
196
                   "Invalid width(%u), ctb_size_y = %u, min_cb_size_y = %u.\n",
1743
196
                   current->pps_pic_width_in_luma_samples,
1744
196
                   ctb_size_y, min_cb_size_y);
1745
196
            return AVERROR_INVALIDDATA;
1746
196
        }
1747
4.58k
    }
1748
1749
12.4k
    flag(pps_conformance_window_flag);
1750
12.4k
    if (current->pps_pic_width_in_luma_samples ==
1751
12.4k
        sps->sps_pic_width_max_in_luma_samples &&
1752
12.2k
        current->pps_pic_height_in_luma_samples ==
1753
12.2k
        sps->sps_pic_height_max_in_luma_samples &&
1754
11.5k
        current->pps_conformance_window_flag) {
1755
203
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1756
203
               "Conformance window flag should not true.\n");
1757
203
        return AVERROR_INVALIDDATA;
1758
203
    }
1759
1760
12.2k
    sub_width_c = h266_sub_width_c[sps->sps_chroma_format_idc];
1761
12.2k
    sub_height_c = h266_sub_height_c[sps->sps_chroma_format_idc];
1762
12.2k
    if (current->pps_conformance_window_flag) {
1763
326
        ue(pps_conf_win_left_offset, 0, current->pps_pic_width_in_luma_samples);
1764
326
        ue(pps_conf_win_right_offset,
1765
326
           0, current->pps_pic_width_in_luma_samples);
1766
326
        ue(pps_conf_win_top_offset, 0, current->pps_pic_height_in_luma_samples);
1767
326
        ue(pps_conf_win_bottom_offset,
1768
326
           0, current->pps_pic_height_in_luma_samples);
1769
326
        if (sub_width_c *
1770
326
            (current->pps_conf_win_left_offset +
1771
326
             current->pps_conf_win_right_offset) >=
1772
326
            current->pps_pic_width_in_luma_samples ||
1773
326
            sub_height_c *
1774
326
            (current->pps_conf_win_top_offset +
1775
326
             current->pps_conf_win_bottom_offset) >=
1776
326
            current->pps_pic_height_in_luma_samples) {
1777
0
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1778
0
                   "Invalid pps conformance window: (%u, %u, %u, %u), "
1779
0
                   "resolution is %ux%u, sub wxh is %ux%u.\n",
1780
0
                   current->pps_conf_win_left_offset,
1781
0
                   current->pps_conf_win_right_offset,
1782
0
                   current->pps_conf_win_top_offset,
1783
0
                   current->pps_conf_win_bottom_offset,
1784
0
                   current->pps_pic_width_in_luma_samples,
1785
0
                   current->pps_pic_height_in_luma_samples,
1786
0
                   sub_width_c, sub_height_c);
1787
0
            return AVERROR_INVALIDDATA;
1788
0
        }
1789
11.8k
    } else {
1790
11.8k
        if (current->pps_pic_width_in_luma_samples ==
1791
11.8k
            sps->sps_pic_width_max_in_luma_samples &&
1792
11.6k
            current->pps_pic_height_in_luma_samples ==
1793
11.6k
            sps->sps_pic_height_max_in_luma_samples) {
1794
11.3k
            infer(pps_conf_win_left_offset, sps->sps_conf_win_left_offset);
1795
11.1k
            infer(pps_conf_win_right_offset, sps->sps_conf_win_right_offset);
1796
10.9k
            infer(pps_conf_win_top_offset, sps->sps_conf_win_top_offset);
1797
10.7k
            infer(pps_conf_win_bottom_offset, sps->sps_conf_win_bottom_offset);
1798
10.7k
        } else {
1799
524
            infer(pps_conf_win_left_offset, 0);
1800
523
            infer(pps_conf_win_right_offset, 0);
1801
523
            infer(pps_conf_win_top_offset, 0);
1802
523
            infer(pps_conf_win_bottom_offset, 0);
1803
523
        }
1804
1805
11.8k
    }
1806
1807
11.4k
    flag(pps_scaling_window_explicit_signalling_flag);
1808
11.4k
    if (!sps->sps_ref_pic_resampling_enabled_flag &&
1809
175
        current->pps_scaling_window_explicit_signalling_flag) {
1810
0
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1811
0
               "Invalid data: sps_ref_pic_resampling_enabled_flag is false, "
1812
0
               "but pps_scaling_window_explicit_signalling_flag is true.\n");
1813
0
        return AVERROR_INVALIDDATA;
1814
0
    }
1815
11.4k
    if (current->pps_scaling_window_explicit_signalling_flag) {
1816
1.57k
        se(pps_scaling_win_left_offset,
1817
1.57k
           -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1818
1.57k
           current->pps_pic_width_in_luma_samples / sub_width_c);
1819
1.57k
        se(pps_scaling_win_right_offset,
1820
1.57k
           -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1821
1.57k
           current->pps_pic_width_in_luma_samples / sub_width_c);
1822
1.57k
        se(pps_scaling_win_top_offset,
1823
1.57k
           -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1824
1.57k
           current->pps_pic_height_in_luma_samples / sub_height_c);
1825
1.57k
        se(pps_scaling_win_bottom_offset,
1826
1.57k
           -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1827
1.57k
           current->pps_pic_height_in_luma_samples / sub_height_c);
1828
9.82k
    } else {
1829
9.82k
        infer(pps_scaling_win_left_offset, current->pps_conf_win_left_offset);
1830
9.82k
        infer(pps_scaling_win_right_offset, current->pps_conf_win_right_offset);
1831
9.82k
        infer(pps_scaling_win_top_offset, current->pps_conf_win_top_offset);
1832
9.82k
        infer(pps_scaling_win_bottom_offset, current->pps_conf_win_bottom_offset);
1833
9.82k
    }
1834
1835
11.4k
    flag(pps_output_flag_present_flag);
1836
11.4k
    flag(pps_no_pic_partition_flag);
1837
11.4k
    flag(pps_subpic_id_mapping_present_flag);
1838
1839
11.4k
    if (current->pps_subpic_id_mapping_present_flag) {
1840
1.69k
        if (!current->pps_no_pic_partition_flag) {
1841
732
            ue(pps_num_subpics_minus1,
1842
732
               sps->sps_num_subpics_minus1, sps->sps_num_subpics_minus1);
1843
966
        } else {
1844
966
            infer(pps_num_subpics_minus1, 0);
1845
966
        }
1846
1.49k
        ue(pps_subpic_id_len_minus1, sps->sps_subpic_id_len_minus1,
1847
1.30k
           sps->sps_subpic_id_len_minus1);
1848
4.68k
        for (i = 0; i <= current->pps_num_subpics_minus1; i++) {
1849
3.38k
            ubs(sps->sps_subpic_id_len_minus1 + 1, pps_subpic_id[i], 1, i);
1850
3.38k
        }
1851
1.30k
    }
1852
1853
34.3k
    for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
1854
23.3k
        if (sps->sps_subpic_id_mapping_explicitly_signalled_flag)
1855
10.1k
            current->sub_pic_id_val[i] = current->pps_subpic_id_mapping_present_flag
1856
10.1k
                                       ? current->pps_subpic_id[i]
1857
10.1k
                                       : sps->sps_subpic_id[i];
1858
13.1k
        else
1859
13.1k
            current->sub_pic_id_val[i] = i;
1860
23.3k
    }
1861
1862
11.0k
    pic_width_in_ctbs_y = AV_CEIL_RSHIFT
1863
11.0k
        (current->pps_pic_width_in_luma_samples, (sps->sps_log2_ctu_size_minus5 + 5));
1864
11.0k
    pic_height_in_ctbs_y = AV_CEIL_RSHIFT(
1865
11.0k
        current->pps_pic_height_in_luma_samples,(sps->sps_log2_ctu_size_minus5 + 5));
1866
11.0k
    if (!current->pps_no_pic_partition_flag) {
1867
6.35k
        unsigned int exp_tile_width = 0, exp_tile_height = 0;
1868
6.35k
        unsigned int unified_size, remaining_size;
1869
1870
6.35k
        u(2, pps_log2_ctu_size_minus5,
1871
6.10k
          sps->sps_log2_ctu_size_minus5, sps->sps_log2_ctu_size_minus5);
1872
6.10k
        ue(pps_num_exp_tile_columns_minus1,
1873
6.10k
           0, FFMIN(pic_width_in_ctbs_y - 1, VVC_MAX_TILE_COLUMNS - 1));
1874
6.10k
        ue(pps_num_exp_tile_rows_minus1,
1875
6.10k
           0, FFMIN(pic_height_in_ctbs_y - 1, VVC_MAX_TILE_ROWS - 1));
1876
1877
22.3k
        for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1878
16.2k
            ues(pps_tile_column_width_minus1[i],
1879
16.2k
                0, pic_width_in_ctbs_y - exp_tile_width - 1, 1, i);
1880
16.2k
            exp_tile_width += current->pps_tile_column_width_minus1[i] + 1;
1881
16.2k
        }
1882
15.1k
        for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1883
9.08k
            ues(pps_tile_row_height_minus1[i],
1884
9.08k
                0, pic_height_in_ctbs_y - exp_tile_height - 1, 1, i);
1885
9.08k
            exp_tile_height += current->pps_tile_row_height_minus1[i] + 1;
1886
9.08k
        }
1887
1888
6.10k
        remaining_size = pic_width_in_ctbs_y;
1889
22.3k
        for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1890
16.2k
          if (current->pps_tile_column_width_minus1[i] >= remaining_size) {
1891
0
              av_log(ctx->log_ctx, AV_LOG_ERROR,
1892
0
                     "Tile column width(%d) exceeds picture width\n",i);
1893
0
              return AVERROR_INVALIDDATA;
1894
0
          }
1895
16.2k
          current->col_width_val[i] = current->pps_tile_column_width_minus1[i] + 1;
1896
16.2k
          remaining_size -= (current->pps_tile_column_width_minus1[i] + 1);
1897
16.2k
        }
1898
6.10k
        unified_size = current->pps_tile_column_width_minus1[i - 1] + 1;
1899
33.5k
        while (remaining_size > 0) {
1900
27.4k
            if (i == VVC_MAX_TILE_COLUMNS) {
1901
0
                av_log(ctx->log_ctx, AV_LOG_ERROR,
1902
0
                       "Exceeded maximum tile columns (%d) (remaining size: %u)\n",
1903
0
                       VVC_MAX_TILE_COLUMNS, remaining_size);
1904
0
                return AVERROR_INVALIDDATA;
1905
0
            }
1906
27.4k
            unified_size = FFMIN(remaining_size, unified_size);
1907
27.4k
            current->col_width_val[i] = unified_size;
1908
27.4k
            remaining_size -= unified_size;
1909
27.4k
            i++;
1910
27.4k
        }
1911
6.10k
        current->num_tile_columns = i;
1912
1913
6.10k
        remaining_size = pic_height_in_ctbs_y;
1914
15.1k
        for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1915
9.08k
          if (current->pps_tile_row_height_minus1[i] >= remaining_size) {
1916
0
              av_log(ctx->log_ctx, AV_LOG_ERROR,
1917
0
                     "Tile row height(%d) exceeds picture height\n",i);
1918
0
              return AVERROR_INVALIDDATA;
1919
0
          }
1920
9.08k
          current->row_height_val[i] = current->pps_tile_row_height_minus1[i] + 1;
1921
9.08k
          remaining_size -= (current->pps_tile_row_height_minus1[i] + 1);
1922
9.08k
        }
1923
6.10k
        unified_size = current->pps_tile_row_height_minus1[i - 1] + 1;
1924
1925
27.9k
        while (remaining_size > 0) {
1926
21.8k
            if (i == VVC_MAX_TILE_ROWS) {
1927
0
                av_log(ctx->log_ctx, AV_LOG_ERROR,
1928
0
                       "Exceeded maximum tile rows (%d) (remaining size: %u)\n",
1929
0
                       VVC_MAX_TILE_ROWS, remaining_size);
1930
0
                return AVERROR_INVALIDDATA;
1931
0
            }
1932
21.8k
            unified_size = FFMIN(remaining_size, unified_size);
1933
21.8k
            current->row_height_val[i] = unified_size;
1934
21.8k
            remaining_size -= unified_size;
1935
21.8k
            i++;
1936
21.8k
        }
1937
6.10k
        current->num_tile_rows=i;
1938
1939
6.10k
        current->num_tiles_in_pic = current->num_tile_columns *
1940
6.10k
                                    current->num_tile_rows;
1941
6.10k
        if (current->num_tiles_in_pic > VVC_MAX_TILES_PER_AU) {
1942
0
            av_log(ctx->log_ctx, AV_LOG_ERROR,
1943
0
                   "NumTilesInPic(%d) > than VVC_MAX_TILES_PER_AU(%d)\n",
1944
0
                   current->num_tiles_in_pic, VVC_MAX_TILES_PER_AU);
1945
0
            return AVERROR_INVALIDDATA;
1946
0
        }
1947
1948
6.10k
        if (current->num_tiles_in_pic > 1) {
1949
5.89k
            flag(pps_loop_filter_across_tiles_enabled_flag);
1950
5.89k
            flag(pps_rect_slice_flag);
1951
5.89k
        } else {
1952
206
            infer(pps_loop_filter_across_tiles_enabled_flag, 0);
1953
206
            infer(pps_rect_slice_flag, 1);
1954
206
        }
1955
6.10k
        if (current->pps_rect_slice_flag)
1956
6.10k
            flag(pps_single_slice_per_subpic_flag);
1957
1.47k
        else
1958
1.47k
            infer(pps_single_slice_per_subpic_flag, 1);
1959
6.10k
        if (current->pps_rect_slice_flag &&
1960
4.62k
            !current->pps_single_slice_per_subpic_flag) {
1961
3.73k
            int j, num_slices = 0;
1962
3.73k
            uint16_t tile_idx = 0, tile_x, tile_y, ctu_x, ctu_y;
1963
3.73k
            uint16_t slice_top_left_ctu_x[VVC_MAX_SLICES];
1964
3.73k
            uint16_t slice_top_left_ctu_y[VVC_MAX_SLICES];
1965
3.73k
            ue(pps_num_slices_in_pic_minus1, 0, VVC_MAX_SLICES - 1);
1966
3.73k
            if (current->pps_num_slices_in_pic_minus1 > 1)
1967
3.73k
                flag(pps_tile_idx_delta_present_flag);
1968
1.35k
            else
1969
1.35k
                infer(pps_tile_idx_delta_present_flag, 0);
1970
26.8k
            for (i = 0; i < current->pps_num_slices_in_pic_minus1; i++) {
1971
23.1k
                current->slice_top_left_tile_idx[i] = tile_idx;
1972
23.1k
                tile_x = tile_idx % current->num_tile_columns;
1973
23.1k
                tile_y = tile_idx / current->num_tile_columns;
1974
23.1k
                if (tile_y >= current->num_tile_rows)
1975
0
                    return AVERROR_INVALIDDATA;
1976
23.1k
                if (tile_x != current->num_tile_columns - 1) {
1977
10.2k
                    ues(pps_slice_width_in_tiles_minus1[i],
1978
10.2k
                        0, current->num_tile_columns - 1 - tile_x, 1, i);
1979
12.8k
                } else {
1980
12.8k
                    infer(pps_slice_width_in_tiles_minus1[i], 0);
1981
12.8k
                }
1982
23.1k
                if (tile_y != current->num_tile_rows - 1 &&
1983
10.3k
                    (current->pps_tile_idx_delta_present_flag || tile_x == 0)) {
1984
7.41k
                    ues(pps_slice_height_in_tiles_minus1[i],
1985
7.41k
                        0, current->num_tile_rows - 1 - tile_y, 1, i);
1986
15.7k
                } else {
1987
15.7k
                    if (tile_y == current->num_tile_rows - 1)
1988
12.7k
                        infer(pps_slice_height_in_tiles_minus1[i], 0);
1989
2.97k
                    else
1990
2.97k
                        infer(pps_slice_height_in_tiles_minus1[i],
1991
15.7k
                              current->pps_slice_height_in_tiles_minus1[i - 1]);
1992
15.7k
                }
1993
1994
23.1k
                ctu_x = ctu_y = 0;
1995
35.8k
                for (j = 0; j < tile_x; j++) {
1996
12.7k
                    ctu_x += current->col_width_val[j];
1997
12.7k
                }
1998
32.3k
                for (j = 0; j < tile_y; j++) {
1999
9.25k
                    ctu_y += current->row_height_val[j];
2000
9.25k
                }
2001
23.1k
                if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
2002
20.4k
                    current->pps_slice_height_in_tiles_minus1[i] == 0 &&
2003
18.9k
                    current->row_height_val[tile_y] > 1) {
2004
15.9k
                    int uniform_slice_height, remaining_height_in_ctbs_y;
2005
15.9k
                    remaining_height_in_ctbs_y =
2006
15.9k
                        current->row_height_val[tile_y];
2007
15.9k
                    ues(pps_num_exp_slices_in_tile[i],
2008
15.9k
                        0, current->row_height_val[tile_y] - 1, 1, i);
2009
15.9k
                    if (current->pps_num_exp_slices_in_tile[i] == 0) {
2010
12.3k
                        current->num_slices_in_tile[i] = 1;
2011
12.3k
                        current->slice_height_in_ctus[i] = current->row_height_val[tile_y];
2012
12.3k
                        slice_top_left_ctu_x[i] = ctu_x;
2013
12.3k
                        slice_top_left_ctu_y[i] = ctu_y;
2014
12.3k
                    } else {
2015
3.61k
                        uint16_t slice_height_in_ctus;
2016
3.61k
                        int num_uniform_slices;
2017
2018
3.61k
                        if (i + current->pps_num_exp_slices_in_tile[i] >
2019
3.61k
                            current->pps_num_slices_in_pic_minus1 + 1)
2020
0
                            return AVERROR_INVALIDDATA;
2021
2022
9.87k
                        for (j = 0; j < current->pps_num_exp_slices_in_tile[i];
2023
6.26k
                             j++) {
2024
6.26k
                            ues(pps_exp_slice_height_in_ctus_minus1[i][j], 0,
2025
6.26k
                                remaining_height_in_ctbs_y - 1, 2,
2026
6.26k
                                i, j);
2027
6.26k
                            slice_height_in_ctus =
2028
6.26k
                                current->
2029
6.26k
                                pps_exp_slice_height_in_ctus_minus1[i][j] + 1;
2030
2031
6.26k
                            current->slice_height_in_ctus[i + j] =
2032
6.26k
                                slice_height_in_ctus;
2033
6.26k
                            slice_top_left_ctu_x[i + j] = ctu_x;
2034
6.26k
                            slice_top_left_ctu_y[i + j] = ctu_y;
2035
6.26k
                            ctu_y += slice_height_in_ctus;
2036
2037
6.26k
                            remaining_height_in_ctbs_y -= slice_height_in_ctus;
2038
6.26k
                        }
2039
3.61k
                        uniform_slice_height = 1 +
2040
3.61k
                            (j == 0 ? current->row_height_val[tile_y] - 1:
2041
3.61k
                            current->pps_exp_slice_height_in_ctus_minus1[i][j-1]);
2042
2043
3.61k
                        num_uniform_slices = (remaining_height_in_ctbs_y + uniform_slice_height - 1)
2044
3.61k
                                           / uniform_slice_height;
2045
3.61k
                        if (i + current->pps_num_exp_slices_in_tile[i] + num_uniform_slices >
2046
3.61k
                            current->pps_num_slices_in_pic_minus1 + 1)
2047
0
                            return AVERROR_INVALIDDATA;
2048
2049
4.96k
                        while (remaining_height_in_ctbs_y > uniform_slice_height) {
2050
1.35k
                            current->slice_height_in_ctus[i + j] =
2051
1.35k
                                                          uniform_slice_height;
2052
1.35k
                            slice_top_left_ctu_x[i + j] = ctu_x;
2053
1.35k
                            slice_top_left_ctu_y[i + j] = ctu_y;
2054
1.35k
                            ctu_y += uniform_slice_height;
2055
2056
1.35k
                            remaining_height_in_ctbs_y -= uniform_slice_height;
2057
1.35k
                            j++;
2058
1.35k
                        }
2059
3.61k
                        if (remaining_height_in_ctbs_y > 0) {
2060
1.23k
                            current->slice_height_in_ctus[i + j] =
2061
1.23k
                                remaining_height_in_ctbs_y;
2062
1.23k
                            slice_top_left_ctu_x[i + j] = ctu_x;
2063
1.23k
                            slice_top_left_ctu_y[i + j] = ctu_y;
2064
1.23k
                            j++;
2065
1.23k
                        }
2066
3.61k
                        current->num_slices_in_tile[i] = j;
2067
3.61k
                    }
2068
37.1k
                    for (int k = 0; k < current->num_slices_in_tile[i]; k++)
2069
21.1k
                        current->slice_top_left_tile_idx[i + k] = tile_idx;
2070
15.9k
                    i += current->num_slices_in_tile[i] - 1;
2071
15.9k
                } else {
2072
7.17k
                    uint16_t height = 0;
2073
7.17k
                    infer(pps_num_exp_slices_in_tile[i], 0);
2074
7.17k
                    if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
2075
4.53k
                        current->pps_slice_height_in_tiles_minus1[i] == 0)
2076
3.02k
                        current->num_slices_in_tile[i] = 1;
2077
2078
7.17k
                    for (j = 0;
2079
17.5k
                         j <= current->pps_slice_height_in_tiles_minus1[i];
2080
10.3k
                         j++) {
2081
10.3k
                        height +=
2082
10.3k
                           current->row_height_val[tile_y + j];
2083
10.3k
                    }
2084
7.17k
                    current->slice_height_in_ctus[i] = height;
2085
2086
7.17k
                    slice_top_left_ctu_x[i] = ctu_x;
2087
7.17k
                    slice_top_left_ctu_y[i] = ctu_y;
2088
7.17k
                }
2089
23.1k
                if (i < current->pps_num_slices_in_pic_minus1) {
2090
22.7k
                    if (current->pps_tile_idx_delta_present_flag) {
2091
                        // Two conditions must be met:
2092
                        // 1. −NumTilesInPic + 1 <= pps_tile_idx_delta_val[i] <= NumTilesInPic − 1
2093
                        // 2. 0 <= tile_idx + pps_tile_idx_delta_val[i] <= NumTilesInPic − 1
2094
                        // Combining these conditions yields: -tile_idx <= pps_tile_idx_delta_val[i] <= NumTilesInPic - 1 - tile_idx
2095
18.1k
                        ses(pps_tile_idx_delta_val[i],
2096
18.1k
                            -tile_idx, current->num_tiles_in_pic - 1 - tile_idx, 1, i);
2097
18.1k
                        if (current->pps_tile_idx_delta_val[i] == 0) {
2098
12.2k
                            av_log(ctx->log_ctx, AV_LOG_ERROR,
2099
12.2k
                                   "pps_tile_idx_delta_val[i] shall not be equal to 0.\n");
2100
12.2k
                        }
2101
18.1k
                        tile_idx += current->pps_tile_idx_delta_val[i];
2102
18.1k
                    } else {
2103
4.62k
                        infer(pps_tile_idx_delta_val[i], 0);
2104
4.62k
                        tile_idx +=
2105
4.62k
                            current->pps_slice_width_in_tiles_minus1[i] + 1;
2106
4.62k
                        if (tile_idx % current->num_tile_columns == 0) {
2107
1.02k
                            tile_idx +=
2108
1.02k
                                current->pps_slice_height_in_tiles_minus1[i] *
2109
1.02k
                                current->num_tile_columns;
2110
1.02k
                        }
2111
4.62k
                    }
2112
22.7k
                }
2113
23.1k
            }
2114
3.73k
            if (i == current->pps_num_slices_in_pic_minus1) {
2115
3.38k
                uint16_t height = 0;
2116
2117
3.38k
                current->slice_top_left_tile_idx[i] = tile_idx;
2118
3.38k
                current->num_slices_in_tile[i] = 1;
2119
3.38k
                tile_x = tile_idx % current->num_tile_columns;
2120
3.38k
                tile_y = tile_idx / current->num_tile_columns;
2121
3.38k
                if (tile_y >= current->num_tile_rows)
2122
0
                    return AVERROR_INVALIDDATA;
2123
2124
3.38k
                ctu_x = 0, ctu_y = 0;
2125
7.10k
                for (j = 0; j < tile_x; j++) {
2126
3.71k
                    ctu_x += current->col_width_val[j];
2127
3.71k
                }
2128
6.67k
                for (j = 0; j < tile_y; j++) {
2129
3.28k
                    ctu_y += current->row_height_val[j];
2130
3.28k
                }
2131
3.38k
                slice_top_left_ctu_x[i] = ctu_x;
2132
3.38k
                slice_top_left_ctu_y[i] = ctu_y;
2133
2134
3.38k
                current->pps_slice_width_in_tiles_minus1[i] =
2135
3.38k
                    current->num_tile_columns - tile_x - 1;
2136
3.38k
                current->pps_slice_height_in_tiles_minus1[i] =
2137
3.38k
                    current->num_tile_rows - tile_y - 1;
2138
2139
19.8k
                for (j = 0; j <= current->pps_slice_height_in_tiles_minus1[i];
2140
16.4k
                     j++) {
2141
16.4k
                    height +=
2142
16.4k
                        current->row_height_val[tile_y + j];
2143
16.4k
                }
2144
3.38k
                current->slice_height_in_ctus[i] = height;
2145
2146
3.38k
                infer(pps_num_exp_slices_in_tile[i], 0);
2147
3.38k
            }
2148
            //now, we got all slice information, let's resolve NumSlicesInSubpic
2149
14.3k
            for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
2150
10.6k
                current->num_slices_in_subpic[i] = 0;
2151
87.0k
                for (j = 0; j <= current->pps_num_slices_in_pic_minus1; j++) {
2152
76.3k
                    uint16_t pos_x = 0, pos_y = 0;
2153
76.3k
                    pos_x = slice_top_left_ctu_x[j];
2154
76.3k
                    pos_y = slice_top_left_ctu_y[j];
2155
76.3k
                    if ((pos_x >= sps->sps_subpic_ctu_top_left_x[i]) &&
2156
48.6k
                        (pos_x <
2157
48.6k
                         sps->sps_subpic_ctu_top_left_x[i] +
2158
48.6k
                         sps->sps_subpic_width_minus1[i] + 1) &&
2159
43.5k
                         (pos_y >= sps->sps_subpic_ctu_top_left_y[i]) &&
2160
35.1k
                         (pos_y < sps->sps_subpic_ctu_top_left_y[i] +
2161
35.1k
                            sps->sps_subpic_height_minus1[i] + 1)) {
2162
32.3k
                        current->num_slices_in_subpic[i]++;
2163
32.3k
                    }
2164
76.3k
                }
2165
10.6k
                num_slices += current->num_slices_in_subpic[i];
2166
10.6k
            }
2167
3.73k
            if (current->pps_num_slices_in_pic_minus1 + 1 != num_slices)
2168
202
                return AVERROR_INVALIDDATA;
2169
3.73k
        } else {
2170
2.36k
            if (current->pps_no_pic_partition_flag)
2171
0
                infer(pps_num_slices_in_pic_minus1, 0);
2172
2.36k
            else if (current->pps_single_slice_per_subpic_flag) {
2173
8.31k
                for (i = 0; i <= sps->sps_num_subpics_minus1; i++)
2174
5.94k
                    current->num_slices_in_subpic[i] = 1;
2175
2.36k
                infer(pps_num_slices_in_pic_minus1,
2176
2.36k
                      sps->sps_num_subpics_minus1);
2177
2.36k
            }
2178
            // else?
2179
2.36k
        }
2180
5.70k
        if (!current->pps_rect_slice_flag ||
2181
4.42k
            current->pps_single_slice_per_subpic_flag ||
2182
3.53k
            current->pps_num_slices_in_pic_minus1 > 0)
2183
5.70k
            flag(pps_loop_filter_across_slices_enabled_flag);
2184
1.11k
        else
2185
1.11k
            infer(pps_loop_filter_across_slices_enabled_flag, 0);
2186
5.70k
    } else {
2187
4.65k
        infer(pps_num_exp_tile_columns_minus1, 0);
2188
4.65k
        infer(pps_tile_column_width_minus1[0], pic_width_in_ctbs_y - 1);
2189
4.44k
        infer(pps_num_exp_tile_rows_minus1, 0);
2190
4.44k
        infer(pps_tile_row_height_minus1[0], pic_height_in_ctbs_y - 1);
2191
4.44k
        current->col_width_val[0] = pic_width_in_ctbs_y;
2192
4.44k
        current->row_height_val[0] = pic_height_in_ctbs_y;
2193
4.44k
        current->num_tile_columns = 1;
2194
4.44k
        current->num_tile_rows = 1;
2195
4.44k
        current->num_tiles_in_pic = 1;
2196
4.44k
    }
2197
2198
10.1k
    flag(pps_cabac_init_present_flag);
2199
30.4k
    for (i = 0; i < 2; i++)
2200
20.2k
        ues(pps_num_ref_idx_default_active_minus1[i], 0, 14, 1, i);
2201
10.1k
    flag(pps_rpl1_idx_present_flag);
2202
10.1k
    flag(pps_weighted_pred_flag);
2203
10.1k
    flag(pps_weighted_bipred_flag);
2204
10.1k
    flag(pps_ref_wraparound_enabled_flag);
2205
10.1k
    if (current->pps_ref_wraparound_enabled_flag) {
2206
3.07k
        ue(pps_pic_width_minus_wraparound_offset,
2207
3.07k
           0, (current->pps_pic_width_in_luma_samples / min_cb_size_y)
2208
3.07k
           - (ctb_size_y / min_cb_size_y) - 2);
2209
3.07k
    }
2210
2211
9.95k
    qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2212
9.95k
    se(pps_init_qp_minus26, -(26 + qp_bd_offset), 37);
2213
9.75k
    flag(pps_cu_qp_delta_enabled_flag);
2214
9.75k
    flag(pps_chroma_tool_offsets_present_flag);
2215
9.75k
    if (current->pps_chroma_tool_offsets_present_flag) {
2216
7.04k
        se(pps_cb_qp_offset, -12, 12);
2217
7.04k
        se(pps_cr_qp_offset, -12, 12);
2218
7.04k
        flag(pps_joint_cbcr_qp_offset_present_flag);
2219
7.04k
        if (current->pps_joint_cbcr_qp_offset_present_flag)
2220
7.04k
            se(pps_joint_cbcr_qp_offset_value, -12, 12);
2221
2.26k
        else
2222
2.26k
            infer(pps_joint_cbcr_qp_offset_value, 0);
2223
7.04k
        flag(pps_slice_chroma_qp_offsets_present_flag);
2224
7.04k
        flag(pps_cu_chroma_qp_offset_list_enabled_flag);
2225
7.04k
        if (current->pps_cu_chroma_qp_offset_list_enabled_flag) {
2226
2.22k
            ue(pps_chroma_qp_offset_list_len_minus1, 0, 5);
2227
7.03k
            for (i = 0; i <= current->pps_chroma_qp_offset_list_len_minus1; i++) {
2228
4.81k
                ses(pps_cb_qp_offset_list[i], -12, 12, 1, i);
2229
4.81k
                ses(pps_cr_qp_offset_list[i], -12, 12, 1, i);
2230
4.81k
                if (current->pps_joint_cbcr_qp_offset_present_flag)
2231
4.81k
                    ses(pps_joint_cbcr_qp_offset_list[i], -12, 12, 1, i);
2232
1.22k
                else
2233
1.22k
                    infer(pps_joint_cbcr_qp_offset_list[i], 0);
2234
4.81k
            }
2235
2.22k
        }
2236
7.04k
    } else {
2237
2.71k
        infer(pps_cb_qp_offset, 0);
2238
2.71k
        infer(pps_cr_qp_offset, 0);
2239
2.71k
        infer(pps_joint_cbcr_qp_offset_present_flag, 0);
2240
2.71k
        infer(pps_joint_cbcr_qp_offset_value, 0);
2241
2.71k
        infer(pps_slice_chroma_qp_offsets_present_flag, 0);
2242
2.71k
        infer(pps_cu_chroma_qp_offset_list_enabled_flag, 0);
2243
2.71k
    }
2244
9.75k
    flag(pps_deblocking_filter_control_present_flag);
2245
9.75k
    if (current->pps_deblocking_filter_control_present_flag) {
2246
4.77k
        flag(pps_deblocking_filter_override_enabled_flag);
2247
4.77k
        flag(pps_deblocking_filter_disabled_flag);
2248
4.77k
        if (!current->pps_no_pic_partition_flag &&
2249
3.32k
            current->pps_deblocking_filter_override_enabled_flag)
2250
4.77k
            flag(pps_dbf_info_in_ph_flag);
2251
2.40k
        else
2252
2.40k
            infer(pps_dbf_info_in_ph_flag, 0);
2253
4.77k
        if (!current->pps_deblocking_filter_disabled_flag) {
2254
2.71k
            se(pps_luma_beta_offset_div2, -12, 12);
2255
2.71k
            se(pps_luma_tc_offset_div2, -12, 12);
2256
2.71k
            if (current->pps_chroma_tool_offsets_present_flag) {
2257
1.64k
                se(pps_cb_beta_offset_div2, -12, 12);
2258
1.64k
                se(pps_cb_tc_offset_div2, -12, 12);
2259
1.64k
                se(pps_cr_beta_offset_div2, -12, 12);
2260
1.64k
                se(pps_cr_tc_offset_div2, -12, 12);
2261
1.64k
            } else {
2262
1.07k
                infer(pps_cb_beta_offset_div2,
2263
1.07k
                      current->pps_luma_beta_offset_div2);
2264
1.07k
                infer(pps_cb_tc_offset_div2, current->pps_luma_tc_offset_div2);
2265
1.07k
                infer(pps_cr_beta_offset_div2,
2266
1.07k
                      current->pps_luma_beta_offset_div2);
2267
1.07k
                infer(pps_cr_tc_offset_div2, current->pps_luma_tc_offset_div2);
2268
1.07k
            }
2269
2.71k
        } else {
2270
2.06k
            infer(pps_luma_beta_offset_div2, 0);
2271
2.06k
            infer(pps_luma_tc_offset_div2, 0);
2272
2.06k
            infer(pps_cb_beta_offset_div2, 0);
2273
2.06k
            infer(pps_cb_tc_offset_div2, 0);
2274
2.06k
            infer(pps_cr_beta_offset_div2, 0);
2275
2.06k
            infer(pps_cr_tc_offset_div2, 0);
2276
2.06k
        }
2277
4.98k
    } else {
2278
4.98k
        infer(pps_deblocking_filter_override_enabled_flag, 0);
2279
4.98k
        infer(pps_deblocking_filter_disabled_flag, 0);
2280
4.98k
        infer(pps_dbf_info_in_ph_flag, 0);
2281
4.98k
        infer(pps_luma_beta_offset_div2, 0);
2282
4.98k
        infer(pps_luma_tc_offset_div2, 0);
2283
4.98k
        infer(pps_cb_beta_offset_div2, 0);
2284
4.98k
        infer(pps_cb_tc_offset_div2, 0);
2285
4.98k
        infer(pps_cr_beta_offset_div2, 0);
2286
4.98k
        infer(pps_cr_tc_offset_div2, 0);
2287
4.98k
    }
2288
2289
9.75k
    if (!current->pps_no_pic_partition_flag) {
2290
5.50k
        flag(pps_rpl_info_in_ph_flag);
2291
5.50k
        flag(pps_sao_info_in_ph_flag);
2292
5.50k
        flag(pps_alf_info_in_ph_flag);
2293
5.50k
        if ((current->pps_weighted_pred_flag ||
2294
3.79k
             current->pps_weighted_bipred_flag) &&
2295
2.86k
            current->pps_rpl_info_in_ph_flag)
2296
5.50k
            flag(pps_wp_info_in_ph_flag);
2297
5.50k
        flag(pps_qp_delta_info_in_ph_flag);
2298
5.50k
    }
2299
9.75k
    flag(pps_picture_header_extension_present_flag);
2300
9.75k
    flag(pps_slice_header_extension_present_flag);
2301
2302
9.75k
    flag(pps_extension_flag);
2303
9.75k
    if (current->pps_extension_flag)
2304
6.39k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2305
2306
9.75k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2307
9.75k
    return 0;
2308
9.75k
}
2309
2310
static int FUNC(alf_data)(CodedBitstreamContext *ctx, RWContext *rw,
2311
                          H266RawAPS *current)
2312
91.7k
{
2313
91.7k
    int err, j, k;
2314
2315
91.7k
    flag(alf_luma_filter_signal_flag);
2316
2317
91.7k
    if (current->aps_chroma_present_flag) {
2318
46.1k
        flag(alf_chroma_filter_signal_flag);
2319
46.1k
        flag(alf_cc_cb_filter_signal_flag);
2320
46.1k
        flag(alf_cc_cr_filter_signal_flag);
2321
46.1k
    } else {
2322
45.6k
        infer(alf_chroma_filter_signal_flag, 0);
2323
45.6k
        infer(alf_cc_cb_filter_signal_flag, 0);
2324
45.6k
        infer(alf_cc_cr_filter_signal_flag, 0);
2325
1.43k
    }
2326
2327
91.7k
    if (current->alf_luma_filter_signal_flag) {
2328
67.8k
        flag(alf_luma_clip_flag);
2329
67.8k
        ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS - 1);
2330
66.8k
        if (current->alf_luma_num_filters_signalled_minus1 > 0) {
2331
24.7k
            unsigned int bits = av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
2332
461k
            for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS; filt_idx++)
2333
444k
                us(bits, alf_luma_coeff_delta_idx[filt_idx],
2334
24.7k
                   0, current->alf_luma_num_filters_signalled_minus1,
2335
24.7k
                   1, filt_idx);
2336
24.7k
        }
2337
154k
        for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
2338
1.26M
            for (j = 0; j < 12; j++) {
2339
1.17M
                ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
2340
1.16M
                if (current->alf_luma_coeff_abs[sf_idx][j])
2341
1.16M
                    ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
2342
515k
                else
2343
515k
                    infer(alf_luma_coeff_sign[sf_idx][j], 0);
2344
1.16M
            }
2345
59.2k
    } else {
2346
23.9k
        infer(alf_luma_clip_flag, 0);
2347
23.9k
        infer(alf_luma_num_filters_signalled_minus1, 0);
2348
1.35k
    }
2349
190k
    for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
2350
1.48M
        for (j = 0; j < 12; j++) {
2351
1.36M
            if (current->alf_luma_clip_flag)
2352
1.36M
                ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
2353
336k
            else
2354
336k
                infer(alf_luma_clip_idx[sf_idx][j], 0);
2355
1.36M
        }
2356
114k
    }
2357
2358
75.7k
    if (current->alf_chroma_filter_signal_flag) {
2359
30.2k
        flag(alf_chroma_clip_flag);
2360
29.6k
        ue(alf_chroma_num_alt_filters_minus1, 0, 7);
2361
45.4k
    } else {
2362
45.4k
        infer(alf_chroma_clip_flag, 0);
2363
45.4k
        infer(alf_chroma_num_alt_filters_minus1, 0);
2364
2.70k
    }
2365
170k
    for (int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
2366
683k
        for (j = 0; j < 6; j++) {
2367
586k
            if (current->alf_chroma_filter_signal_flag)
2368
586k
                ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
2369
272k
            else
2370
272k
                infer(alf_chroma_coeff_abs[alt_idx][j], 0);
2371
585k
            if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
2372
585k
                ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
2373
401k
            else
2374
401k
                infer(alf_chroma_coeff_sign[alt_idx][j], 0);
2375
585k
        }
2376
672k
        for (j = 0; j < 6; j++) {
2377
576k
            if (current->alf_chroma_clip_flag)
2378
576k
                ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
2379
452k
            else
2380
452k
                infer(alf_chroma_clip_idx[alt_idx][j], 0);
2381
576k
        }
2382
96.6k
    }
2383
2384
71.3k
    if (current->alf_cc_cb_filter_signal_flag)
2385
71.3k
        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
2386
53.4k
    else
2387
53.4k
        infer(alf_cc_cb_filters_signalled_minus1, 0);
2388
146k
    for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
2389
616k
        for (j = 0; j < 7; j++) {
2390
540k
            if (current->alf_cc_cb_filter_signal_flag)
2391
540k
                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
2392
374k
            else
2393
374k
                infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
2394
537k
            if (current->alf_cc_cb_mapped_coeff_abs[k][j])
2395
537k
                ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
2396
408k
            else
2397
408k
                infer(alf_cc_cb_coeff_sign[k][j], 0);
2398
537k
        }
2399
79.4k
    }
2400
2401
66.5k
    if (current->alf_cc_cr_filter_signal_flag)
2402
66.5k
        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
2403
45.9k
    else
2404
45.9k
        infer(alf_cc_cr_filters_signalled_minus1, 0);
2405
145k
    for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
2406
671k
        for (j = 0; j < 7; j++) {
2407
590k
            if (current->alf_cc_cr_filter_signal_flag)
2408
590k
                ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
2409
321k
            else
2410
321k
                infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
2411
589k
            if (current->alf_cc_cr_mapped_coeff_abs[k][j])
2412
589k
                ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
2413
357k
            else
2414
357k
                infer(alf_cc_cr_coeff_sign[k][j], 0);
2415
589k
        }
2416
85.5k
    }
2417
2418
60.4k
    return 0;
2419
64.3k
}
cbs_h266.c:cbs_h266_read_alf_data
Line
Count
Source
2312
87.3k
{
2313
87.3k
    int err, j, k;
2314
2315
87.3k
    flag(alf_luma_filter_signal_flag);
2316
2317
87.3k
    if (current->aps_chroma_present_flag) {
2318
43.1k
        flag(alf_chroma_filter_signal_flag);
2319
43.1k
        flag(alf_cc_cb_filter_signal_flag);
2320
43.1k
        flag(alf_cc_cr_filter_signal_flag);
2321
44.2k
    } else {
2322
44.2k
        infer(alf_chroma_filter_signal_flag, 0);
2323
44.2k
        infer(alf_cc_cb_filter_signal_flag, 0);
2324
44.2k
        infer(alf_cc_cr_filter_signal_flag, 0);
2325
44.2k
    }
2326
2327
87.3k
    if (current->alf_luma_filter_signal_flag) {
2328
64.7k
        flag(alf_luma_clip_flag);
2329
64.7k
        ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS - 1);
2330
63.7k
        if (current->alf_luma_num_filters_signalled_minus1 > 0) {
2331
22.7k
            unsigned int bits = av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
2332
411k
            for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS; filt_idx++)
2333
396k
                us(bits, alf_luma_coeff_delta_idx[filt_idx],
2334
22.7k
                   0, current->alf_luma_num_filters_signalled_minus1,
2335
22.7k
                   1, filt_idx);
2336
22.7k
        }
2337
142k
        for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
2338
1.15M
            for (j = 0; j < 12; j++) {
2339
1.06M
                ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
2340
1.06M
                if (current->alf_luma_coeff_abs[sf_idx][j])
2341
1.06M
                    ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
2342
446k
                else
2343
446k
                    infer(alf_luma_coeff_sign[sf_idx][j], 0);
2344
1.06M
            }
2345
56.1k
    } else {
2346
22.6k
        infer(alf_luma_clip_flag, 0);
2347
22.6k
        infer(alf_luma_num_filters_signalled_minus1, 0);
2348
22.6k
    }
2349
176k
    for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
2350
1.35M
        for (j = 0; j < 12; j++) {
2351
1.24M
            if (current->alf_luma_clip_flag)
2352
1.24M
                ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
2353
318k
            else
2354
318k
                infer(alf_luma_clip_idx[sf_idx][j], 0);
2355
1.24M
        }
2356
104k
    }
2357
2358
71.2k
    if (current->alf_chroma_filter_signal_flag) {
2359
28.4k
        flag(alf_chroma_clip_flag);
2360
27.8k
        ue(alf_chroma_num_alt_filters_minus1, 0, 7);
2361
42.7k
    } else {
2362
42.7k
        infer(alf_chroma_clip_flag, 0);
2363
42.7k
        infer(alf_chroma_num_alt_filters_minus1, 0);
2364
42.7k
    }
2365
158k
    for (int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
2366
635k
        for (j = 0; j < 6; j++) {
2367
545k
            if (current->alf_chroma_filter_signal_flag)
2368
545k
                ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
2369
256k
            else
2370
256k
                infer(alf_chroma_coeff_abs[alt_idx][j], 0);
2371
544k
            if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
2372
544k
                ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
2373
374k
            else
2374
374k
                infer(alf_chroma_coeff_sign[alt_idx][j], 0);
2375
544k
        }
2376
624k
        for (j = 0; j < 6; j++) {
2377
535k
            if (current->alf_chroma_clip_flag)
2378
535k
                ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
2379
428k
            else
2380
428k
                infer(alf_chroma_clip_idx[alt_idx][j], 0);
2381
535k
        }
2382
89.8k
    }
2383
2384
66.9k
    if (current->alf_cc_cb_filter_signal_flag)
2385
66.9k
        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
2386
50.1k
    else
2387
50.1k
        infer(alf_cc_cb_filters_signalled_minus1, 0);
2388
136k
    for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
2389
571k
        for (j = 0; j < 7; j++) {
2390
501k
            if (current->alf_cc_cb_filter_signal_flag)
2391
501k
                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
2392
351k
            else
2393
351k
                infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
2394
499k
            if (current->alf_cc_cb_mapped_coeff_abs[k][j])
2395
499k
                ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
2396
384k
            else
2397
384k
                infer(alf_cc_cb_coeff_sign[k][j], 0);
2398
499k
        }
2399
73.9k
    }
2400
2401
62.0k
    if (current->alf_cc_cr_filter_signal_flag)
2402
62.0k
        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
2403
42.7k
    else
2404
42.7k
        infer(alf_cc_cr_filters_signalled_minus1, 0);
2405
135k
    for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
2406
625k
        for (j = 0; j < 7; j++) {
2407
549k
            if (current->alf_cc_cr_filter_signal_flag)
2408
549k
                ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
2409
299k
            else
2410
299k
                infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
2411
548k
            if (current->alf_cc_cr_mapped_coeff_abs[k][j])
2412
548k
                ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
2413
331k
            else
2414
331k
                infer(alf_cc_cr_coeff_sign[k][j], 0);
2415
548k
        }
2416
79.7k
    }
2417
2418
55.9k
    return 0;
2419
59.9k
}
cbs_h266.c:cbs_h266_write_alf_data
Line
Count
Source
2312
4.45k
{
2313
4.45k
    int err, j, k;
2314
2315
4.45k
    flag(alf_luma_filter_signal_flag);
2316
2317
4.45k
    if (current->aps_chroma_present_flag) {
2318
3.02k
        flag(alf_chroma_filter_signal_flag);
2319
3.02k
        flag(alf_cc_cb_filter_signal_flag);
2320
3.02k
        flag(alf_cc_cr_filter_signal_flag);
2321
3.02k
    } else {
2322
1.43k
        infer(alf_chroma_filter_signal_flag, 0);
2323
1.43k
        infer(alf_cc_cb_filter_signal_flag, 0);
2324
1.43k
        infer(alf_cc_cr_filter_signal_flag, 0);
2325
1.43k
    }
2326
2327
4.45k
    if (current->alf_luma_filter_signal_flag) {
2328
3.10k
        flag(alf_luma_clip_flag);
2329
3.10k
        ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS - 1);
2330
3.10k
        if (current->alf_luma_num_filters_signalled_minus1 > 0) {
2331
1.91k
            unsigned int bits = av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
2332
49.8k
            for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS; filt_idx++)
2333
47.9k
                us(bits, alf_luma_coeff_delta_idx[filt_idx],
2334
1.91k
                   0, current->alf_luma_num_filters_signalled_minus1,
2335
1.91k
                   1, filt_idx);
2336
1.91k
        }
2337
11.6k
        for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
2338
110k
            for (j = 0; j < 12; j++) {
2339
102k
                ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
2340
102k
                if (current->alf_luma_coeff_abs[sf_idx][j])
2341
102k
                    ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
2342
69.1k
                else
2343
69.1k
                    infer(alf_luma_coeff_sign[sf_idx][j], 0);
2344
102k
            }
2345
3.10k
    } else {
2346
1.35k
        infer(alf_luma_clip_flag, 0);
2347
1.35k
        infer(alf_luma_num_filters_signalled_minus1, 0);
2348
1.35k
    }
2349
14.3k
    for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
2350
128k
        for (j = 0; j < 12; j++) {
2351
118k
            if (current->alf_luma_clip_flag)
2352
118k
                ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
2353
17.5k
            else
2354
17.5k
                infer(alf_luma_clip_idx[sf_idx][j], 0);
2355
118k
        }
2356
9.88k
    }
2357
2358
4.45k
    if (current->alf_chroma_filter_signal_flag) {
2359
1.75k
        flag(alf_chroma_clip_flag);
2360
1.75k
        ue(alf_chroma_num_alt_filters_minus1, 0, 7);
2361
2.70k
    } else {
2362
2.70k
        infer(alf_chroma_clip_flag, 0);
2363
2.70k
        infer(alf_chroma_num_alt_filters_minus1, 0);
2364
2.70k
    }
2365
11.3k
    for (int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
2366
47.9k
        for (j = 0; j < 6; j++) {
2367
41.0k
            if (current->alf_chroma_filter_signal_flag)
2368
41.0k
                ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
2369
16.2k
            else
2370
16.2k
                infer(alf_chroma_coeff_abs[alt_idx][j], 0);
2371
41.0k
            if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
2372
41.0k
                ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
2373
27.0k
            else
2374
27.0k
                infer(alf_chroma_coeff_sign[alt_idx][j], 0);
2375
41.0k
        }
2376
47.9k
        for (j = 0; j < 6; j++) {
2377
41.0k
            if (current->alf_chroma_clip_flag)
2378
41.0k
                ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
2379
24.5k
            else
2380
24.5k
                infer(alf_chroma_clip_idx[alt_idx][j], 0);
2381
41.0k
        }
2382
6.84k
    }
2383
2384
4.45k
    if (current->alf_cc_cb_filter_signal_flag)
2385
4.45k
        ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
2386
3.24k
    else
2387
3.24k
        infer(alf_cc_cb_filters_signalled_minus1, 0);
2388
9.99k
    for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
2389
44.3k
        for (j = 0; j < 7; j++) {
2390
38.7k
            if (current->alf_cc_cb_filter_signal_flag)
2391
38.7k
                ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
2392
22.7k
            else
2393
22.7k
                infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
2394
38.7k
            if (current->alf_cc_cb_mapped_coeff_abs[k][j])
2395
38.7k
                ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
2396
24.1k
            else
2397
24.1k
                infer(alf_cc_cb_coeff_sign[k][j], 0);
2398
38.7k
        }
2399
5.54k
    }
2400
2401
4.45k
    if (current->alf_cc_cr_filter_signal_flag)
2402
4.45k
        ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
2403
3.18k
    else
2404
3.18k
        infer(alf_cc_cr_filters_signalled_minus1, 0);
2405
10.2k
    for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
2406
46.4k
        for (j = 0; j < 7; j++) {
2407
40.6k
            if (current->alf_cc_cr_filter_signal_flag)
2408
40.6k
                ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
2409
22.2k
            else
2410
22.2k
                infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
2411
40.6k
            if (current->alf_cc_cr_mapped_coeff_abs[k][j])
2412
40.6k
                ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
2413
25.7k
            else
2414
25.7k
                infer(alf_cc_cr_coeff_sign[k][j], 0);
2415
40.6k
        }
2416
5.80k
    }
2417
2418
4.45k
    return 0;
2419
4.45k
}
2420
2421
static int FUNC(lmcs_data)(CodedBitstreamContext *ctx, RWContext *rw,
2422
                           H266RawAPS *current)
2423
60.2k
{
2424
60.2k
    int err, i, lmcs_max_bin_idx;
2425
2426
60.2k
    ue(lmcs_min_bin_idx, 0, 15);
2427
59.5k
    ue(lmcs_delta_max_bin_idx, 0, 15);
2428
45.4k
    ue(lmcs_delta_cw_prec_minus1, 0, 14);
2429
2430
44.5k
    lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
2431
2432
44.5k
    if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
2433
1.54k
        return AVERROR_INVALIDDATA;
2434
2435
583k
    for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
2436
543k
        ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i], 1, i);
2437
541k
        if (current->lmcs_delta_abs_cw[i] > 0)
2438
541k
            flags(lmcs_delta_sign_cw_flag[i], 1, i);
2439
123k
        else
2440
123k
            infer(lmcs_delta_sign_cw_flag[i], 0);
2441
541k
    }
2442
2443
39.8k
    if (current->aps_chroma_present_flag) {
2444
35.2k
        ub(3, lmcs_delta_abs_crs);
2445
34.7k
        if (current->lmcs_delta_abs_crs > 0)
2446
34.7k
            flag(lmcs_delta_sign_crs_flag);
2447
5.05k
        else
2448
5.05k
            infer(lmcs_delta_sign_crs_flag, 0);
2449
34.7k
    } else {
2450
4.68k
        infer(lmcs_delta_abs_crs, 0);
2451
4.68k
        infer(lmcs_delta_sign_crs_flag, 0);
2452
232
    }
2453
2454
37.9k
    return 0;
2455
39.8k
}
cbs_h266.c:cbs_h266_read_lmcs_data
Line
Count
Source
2423
55.4k
{
2424
55.4k
    int err, i, lmcs_max_bin_idx;
2425
2426
55.4k
    ue(lmcs_min_bin_idx, 0, 15);
2427
54.7k
    ue(lmcs_delta_max_bin_idx, 0, 15);
2428
40.6k
    ue(lmcs_delta_cw_prec_minus1, 0, 14);
2429
2430
39.7k
    lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
2431
2432
39.7k
    if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
2433
1.54k
        return AVERROR_INVALIDDATA;
2434
2435
513k
    for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
2436
478k
        ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i], 1, i);
2437
476k
        if (current->lmcs_delta_abs_cw[i] > 0)
2438
476k
            flags(lmcs_delta_sign_cw_flag[i], 1, i);
2439
114k
        else
2440
114k
            infer(lmcs_delta_sign_cw_flag[i], 0);
2441
476k
    }
2442
2443
35.1k
    if (current->aps_chroma_present_flag) {
2444
30.6k
        ub(3, lmcs_delta_abs_crs);
2445
30.2k
        if (current->lmcs_delta_abs_crs > 0)
2446
30.2k
            flag(lmcs_delta_sign_crs_flag);
2447
4.69k
        else
2448
4.69k
            infer(lmcs_delta_sign_crs_flag, 0);
2449
30.2k
    } else {
2450
4.45k
        infer(lmcs_delta_abs_crs, 0);
2451
4.45k
        infer(lmcs_delta_sign_crs_flag, 0);
2452
4.45k
    }
2453
2454
33.2k
    return 0;
2455
35.1k
}
cbs_h266.c:cbs_h266_write_lmcs_data
Line
Count
Source
2423
4.74k
{
2424
4.74k
    int err, i, lmcs_max_bin_idx;
2425
2426
4.74k
    ue(lmcs_min_bin_idx, 0, 15);
2427
4.74k
    ue(lmcs_delta_max_bin_idx, 0, 15);
2428
4.74k
    ue(lmcs_delta_cw_prec_minus1, 0, 14);
2429
2430
4.74k
    lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
2431
2432
4.74k
    if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
2433
0
        return AVERROR_INVALIDDATA;
2434
2435
70.0k
    for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
2436
65.3k
        ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i], 1, i);
2437
65.3k
        if (current->lmcs_delta_abs_cw[i] > 0)
2438
65.3k
            flags(lmcs_delta_sign_cw_flag[i], 1, i);
2439
8.30k
        else
2440
8.30k
            infer(lmcs_delta_sign_cw_flag[i], 0);
2441
65.3k
    }
2442
2443
4.74k
    if (current->aps_chroma_present_flag) {
2444
4.51k
        ub(3, lmcs_delta_abs_crs);
2445
4.51k
        if (current->lmcs_delta_abs_crs > 0)
2446
4.51k
            flag(lmcs_delta_sign_crs_flag);
2447
352
        else
2448
352
            infer(lmcs_delta_sign_crs_flag, 0);
2449
4.51k
    } else {
2450
232
        infer(lmcs_delta_abs_crs, 0);
2451
232
        infer(lmcs_delta_sign_crs_flag, 0);
2452
232
    }
2453
2454
4.74k
    return 0;
2455
4.74k
}
2456
2457
static int FUNC(scaling_list_data)(CodedBitstreamContext *ctx, RWContext *rw,
2458
                                   H266RawAPS *current)
2459
92.0k
{
2460
    // 7.4.3.4, deriving DiagScanOrder
2461
92.0k
    static const uint8_t diag_scan_order[64][2] = {
2462
92.0k
        { 0,  0, }, { 0,  1, }, { 1,  0, }, { 0,  2, }, { 1,  1, }, { 2,  0, }, { 0,  3, }, { 1,  2, },
2463
92.0k
        { 2,  1, }, { 3,  0, }, { 0,  4, }, { 1,  3, }, { 2,  2, }, { 3,  1, }, { 4,  0, }, { 0,  5, },
2464
92.0k
        { 1,  4, }, { 2,  3, }, { 3,  2, }, { 4,  1, }, { 5,  0, }, { 0,  6, }, { 1,  5, }, { 2,  4, },
2465
92.0k
        { 3,  3, }, { 4,  2, }, { 5,  1, }, { 6,  0, }, { 0,  7, }, { 1,  6, }, { 2,  5, }, { 3,  4, },
2466
92.0k
        { 4,  3, }, { 5,  2, }, { 6,  1, }, { 7,  0, }, { 1,  7, }, { 2,  6, }, { 3,  5, }, { 4,  4, },
2467
92.0k
        { 5,  3, }, { 6,  2, }, { 7,  1, }, { 2,  7, }, { 3,  6, }, { 4,  5, }, { 5,  4, }, { 6,  3, },
2468
92.0k
        { 7,  2, }, { 3,  7, }, { 4,  6, }, { 5,  5, }, { 6,  4, }, { 7,  3, }, { 4,  7, }, { 5,  6, },
2469
92.0k
        { 6,  5, }, { 7,  4, }, { 5,  7, }, { 6,  6, }, { 7,  5, }, { 6,  7, }, { 7,  6, }, { 7,  7, }, };
2470
92.0k
    int err;
2471
2472
1.31M
    for (int id = 0; id < 28; id ++) {
2473
1.29M
        if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
2474
994k
            flags(scaling_list_copy_mode_flag[id], 1, id);
2475
993k
            if (!current->scaling_list_copy_mode_flag[id])
2476
993k
                flags(scaling_list_pred_mode_flag[id], 1, id);
2477
806k
            else
2478
806k
                infer(scaling_list_pred_mode_flag[id], 0);
2479
992k
            if ((current->scaling_list_copy_mode_flag[id] ||
2480
186k
                 current->scaling_list_pred_mode_flag[id]) &&
2481
907k
                 id != 0 && id != 2 && id != 8) {
2482
724k
                int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) : (id - 8));
2483
724k
                ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1, id);
2484
724k
            }
2485
978k
            if (!current->scaling_list_copy_mode_flag[id]) {
2486
176k
                int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
2487
176k
                if (id > 13) {
2488
18.9k
                    int idx = id - 14;
2489
18.9k
                    ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
2490
18.9k
                }
2491
4.26M
                for (int i = 0; i < matrix_size * matrix_size; i++) {
2492
4.14M
                    int x = diag_scan_order[i][0];
2493
4.14M
                    int y = diag_scan_order[i][1];
2494
4.14M
                    if (!(id > 25 && x >= 4 && y >= 4))
2495
4.14M
                        ses(scaling_list_delta_coef[id][i], -128, 127, 2, id, i);
2496
4.14M
                }
2497
801k
            } else if (id > 13) {
2498
215k
                int idx = id - 14;
2499
215k
                infer(scaling_list_dc_coef[idx], 0);
2500
215k
            }
2501
978k
        } else {
2502
297k
            infer(scaling_list_copy_mode_flag[id], 1);
2503
297k
            infer(scaling_list_pred_mode_flag[id], 0);
2504
15.7k
        }
2505
1.29M
    }
2506
2507
20.7k
    return 0;
2508
92.0k
}
cbs_h266.c:cbs_h266_read_scaling_list_data
Line
Count
Source
2459
89.2k
{
2460
    // 7.4.3.4, deriving DiagScanOrder
2461
89.2k
    static const uint8_t diag_scan_order[64][2] = {
2462
89.2k
        { 0,  0, }, { 0,  1, }, { 1,  0, }, { 0,  2, }, { 1,  1, }, { 2,  0, }, { 0,  3, }, { 1,  2, },
2463
89.2k
        { 2,  1, }, { 3,  0, }, { 0,  4, }, { 1,  3, }, { 2,  2, }, { 3,  1, }, { 4,  0, }, { 0,  5, },
2464
89.2k
        { 1,  4, }, { 2,  3, }, { 3,  2, }, { 4,  1, }, { 5,  0, }, { 0,  6, }, { 1,  5, }, { 2,  4, },
2465
89.2k
        { 3,  3, }, { 4,  2, }, { 5,  1, }, { 6,  0, }, { 0,  7, }, { 1,  6, }, { 2,  5, }, { 3,  4, },
2466
89.2k
        { 4,  3, }, { 5,  2, }, { 6,  1, }, { 7,  0, }, { 1,  7, }, { 2,  6, }, { 3,  5, }, { 4,  4, },
2467
89.2k
        { 5,  3, }, { 6,  2, }, { 7,  1, }, { 2,  7, }, { 3,  6, }, { 4,  5, }, { 5,  4, }, { 6,  3, },
2468
89.2k
        { 7,  2, }, { 3,  7, }, { 4,  6, }, { 5,  5, }, { 6,  4, }, { 7,  3, }, { 4,  7, }, { 5,  6, },
2469
89.2k
        { 6,  5, }, { 7,  4, }, { 5,  7, }, { 6,  6, }, { 7,  5, }, { 6,  7, }, { 7,  6, }, { 7,  7, }, };
2470
89.2k
    int err;
2471
2472
1.23M
    for (int id = 0; id < 28; id ++) {
2473
1.21M
        if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
2474
933k
            flags(scaling_list_copy_mode_flag[id], 1, id);
2475
931k
            if (!current->scaling_list_copy_mode_flag[id])
2476
931k
                flags(scaling_list_pred_mode_flag[id], 1, id);
2477
748k
            else
2478
748k
                infer(scaling_list_pred_mode_flag[id], 0);
2479
931k
            if ((current->scaling_list_copy_mode_flag[id] ||
2480
182k
                 current->scaling_list_pred_mode_flag[id]) &&
2481
847k
                 id != 0 && id != 2 && id != 8) {
2482
672k
                int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) : (id - 8));
2483
672k
                ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1, id);
2484
672k
            }
2485
916k
            if (!current->scaling_list_copy_mode_flag[id]) {
2486
172k
                int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
2487
172k
                if (id > 13) {
2488
17.9k
                    int idx = id - 14;
2489
17.9k
                    ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
2490
17.9k
                }
2491
4.13M
                for (int i = 0; i < matrix_size * matrix_size; i++) {
2492
4.01M
                    int x = diag_scan_order[i][0];
2493
4.01M
                    int y = diag_scan_order[i][1];
2494
4.01M
                    if (!(id > 25 && x >= 4 && y >= 4))
2495
4.01M
                        ses(scaling_list_delta_coef[id][i], -128, 127, 2, id, i);
2496
4.01M
                }
2497
744k
            } else if (id > 13) {
2498
185k
                int idx = id - 14;
2499
185k
                infer(scaling_list_dc_coef[idx], 0);
2500
185k
            }
2501
916k
        } else {
2502
281k
            infer(scaling_list_copy_mode_flag[id], 1);
2503
281k
            infer(scaling_list_pred_mode_flag[id], 0);
2504
281k
        }
2505
1.21M
    }
2506
2507
18.0k
    return 0;
2508
89.2k
}
cbs_h266.c:cbs_h266_write_scaling_list_data
Line
Count
Source
2459
2.76k
{
2460
    // 7.4.3.4, deriving DiagScanOrder
2461
2.76k
    static const uint8_t diag_scan_order[64][2] = {
2462
2.76k
        { 0,  0, }, { 0,  1, }, { 1,  0, }, { 0,  2, }, { 1,  1, }, { 2,  0, }, { 0,  3, }, { 1,  2, },
2463
2.76k
        { 2,  1, }, { 3,  0, }, { 0,  4, }, { 1,  3, }, { 2,  2, }, { 3,  1, }, { 4,  0, }, { 0,  5, },
2464
2.76k
        { 1,  4, }, { 2,  3, }, { 3,  2, }, { 4,  1, }, { 5,  0, }, { 0,  6, }, { 1,  5, }, { 2,  4, },
2465
2.76k
        { 3,  3, }, { 4,  2, }, { 5,  1, }, { 6,  0, }, { 0,  7, }, { 1,  6, }, { 2,  5, }, { 3,  4, },
2466
2.76k
        { 4,  3, }, { 5,  2, }, { 6,  1, }, { 7,  0, }, { 1,  7, }, { 2,  6, }, { 3,  5, }, { 4,  4, },
2467
2.76k
        { 5,  3, }, { 6,  2, }, { 7,  1, }, { 2,  7, }, { 3,  6, }, { 4,  5, }, { 5,  4, }, { 6,  3, },
2468
2.76k
        { 7,  2, }, { 3,  7, }, { 4,  6, }, { 5,  5, }, { 6,  4, }, { 7,  3, }, { 4,  7, }, { 5,  6, },
2469
2.76k
        { 6,  5, }, { 7,  4, }, { 5,  7, }, { 6,  6, }, { 7,  5, }, { 6,  7, }, { 7,  6, }, { 7,  7, }, };
2470
2.76k
    int err;
2471
2472
80.0k
    for (int id = 0; id < 28; id ++) {
2473
77.3k
        if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
2474
61.5k
            flags(scaling_list_copy_mode_flag[id], 1, id);
2475
61.5k
            if (!current->scaling_list_copy_mode_flag[id])
2476
61.5k
                flags(scaling_list_pred_mode_flag[id], 1, id);
2477
57.5k
            else
2478
57.5k
                infer(scaling_list_pred_mode_flag[id], 0);
2479
61.5k
            if ((current->scaling_list_copy_mode_flag[id] ||
2480
3.98k
                 current->scaling_list_pred_mode_flag[id]) &&
2481
59.4k
                 id != 0 && id != 2 && id != 8) {
2482
52.3k
                int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) : (id - 8));
2483
52.3k
                ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1, id);
2484
52.3k
            }
2485
61.5k
            if (!current->scaling_list_copy_mode_flag[id]) {
2486
3.98k
                int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
2487
3.98k
                if (id > 13) {
2488
1.01k
                    int idx = id - 14;
2489
1.01k
                    ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
2490
1.01k
                }
2491
128k
                for (int i = 0; i < matrix_size * matrix_size; i++) {
2492
124k
                    int x = diag_scan_order[i][0];
2493
124k
                    int y = diag_scan_order[i][1];
2494
124k
                    if (!(id > 25 && x >= 4 && y >= 4))
2495
124k
                        ses(scaling_list_delta_coef[id][i], -128, 127, 2, id, i);
2496
124k
                }
2497
57.5k
            } else if (id > 13) {
2498
30.6k
                int idx = id - 14;
2499
30.6k
                infer(scaling_list_dc_coef[idx], 0);
2500
30.6k
            }
2501
61.5k
        } else {
2502
15.7k
            infer(scaling_list_copy_mode_flag[id], 1);
2503
15.7k
            infer(scaling_list_pred_mode_flag[id], 0);
2504
15.7k
        }
2505
77.3k
    }
2506
2507
2.76k
    return 0;
2508
2.76k
}
2509
2510
static int FUNC(aps)(CodedBitstreamContext *ctx, RWContext *rw,
2511
                     H266RawAPS *current, int prefix)
2512
297k
{
2513
297k
    int aps_id_max = MAX_UINT_BITS(5);
2514
297k
    int err;
2515
2516
297k
    if (prefix)
2517
287k
        HEADER("Prefix Adaptation parameter set");
2518
10.3k
    else
2519
10.3k
        HEADER("Suffix Adaptation parameter set");
2520
2521
297k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2522
297k
                                prefix ? VVC_PREFIX_APS_NUT
2523
297k
                                       : VVC_SUFFIX_APS_NUT));
2524
2525
296k
    ub(3, aps_params_type);
2526
277k
    if (current->aps_params_type == VVC_ASP_TYPE_ALF ||
2527
179k
        current->aps_params_type == VVC_ASP_TYPE_SCALING)
2528
205k
        aps_id_max = 7;
2529
71.9k
    else if (current->aps_params_type == VVC_ASP_TYPE_LMCS)
2530
62.7k
        aps_id_max = 3;
2531
277k
    u(5, aps_adaptation_parameter_set_id, 0, aps_id_max);
2532
253k
    flag(aps_chroma_present_flag);
2533
252k
    if (current->aps_params_type == VVC_ASP_TYPE_ALF)
2534
91.7k
        CHECK(FUNC(alf_data)(ctx, rw, current));
2535
160k
    else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
2536
60.2k
        CHECK(FUNC(lmcs_data)(ctx, rw, current));
2537
100k
    else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
2538
92.0k
        CHECK(FUNC(scaling_list_data)(ctx, rw, current));
2539
127k
    flag(aps_extension_flag);
2540
126k
    if (current->aps_extension_flag)
2541
75.4k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2542
126k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2543
2544
105k
    return 0;
2545
126k
}
cbs_h266.c:cbs_h266_read_aps
Line
Count
Source
2512
285k
{
2513
285k
    int aps_id_max = MAX_UINT_BITS(5);
2514
285k
    int err;
2515
2516
285k
    if (prefix)
2517
275k
        HEADER("Prefix Adaptation parameter set");
2518
9.96k
    else
2519
9.96k
        HEADER("Suffix Adaptation parameter set");
2520
2521
285k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2522
285k
                                prefix ? VVC_PREFIX_APS_NUT
2523
285k
                                       : VVC_SUFFIX_APS_NUT));
2524
2525
284k
    ub(3, aps_params_type);
2526
264k
    if (current->aps_params_type == VVC_ASP_TYPE_ALF ||
2527
171k
        current->aps_params_type == VVC_ASP_TYPE_SCALING)
2528
198k
        aps_id_max = 7;
2529
66.5k
    else if (current->aps_params_type == VVC_ASP_TYPE_LMCS)
2530
58.0k
        aps_id_max = 3;
2531
264k
    u(5, aps_adaptation_parameter_set_id, 0, aps_id_max);
2532
240k
    flag(aps_chroma_present_flag);
2533
239k
    if (current->aps_params_type == VVC_ASP_TYPE_ALF)
2534
87.3k
        CHECK(FUNC(alf_data)(ctx, rw, current));
2535
152k
    else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
2536
55.4k
        CHECK(FUNC(lmcs_data)(ctx, rw, current));
2537
96.7k
    else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
2538
89.2k
        CHECK(FUNC(scaling_list_data)(ctx, rw, current));
2539
114k
    flag(aps_extension_flag);
2540
113k
    if (current->aps_extension_flag)
2541
67.6k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2542
113k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2543
2544
92.4k
    return 0;
2545
113k
}
cbs_h266.c:cbs_h266_write_aps
Line
Count
Source
2512
12.6k
{
2513
12.6k
    int aps_id_max = MAX_UINT_BITS(5);
2514
12.6k
    int err;
2515
2516
12.6k
    if (prefix)
2517
12.2k
        HEADER("Prefix Adaptation parameter set");
2518
378
    else
2519
378
        HEADER("Suffix Adaptation parameter set");
2520
2521
12.6k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2522
12.6k
                                prefix ? VVC_PREFIX_APS_NUT
2523
12.6k
                                       : VVC_SUFFIX_APS_NUT));
2524
2525
12.6k
    ub(3, aps_params_type);
2526
12.6k
    if (current->aps_params_type == VVC_ASP_TYPE_ALF ||
2527
8.14k
        current->aps_params_type == VVC_ASP_TYPE_SCALING)
2528
7.22k
        aps_id_max = 7;
2529
5.38k
    else if (current->aps_params_type == VVC_ASP_TYPE_LMCS)
2530
4.74k
        aps_id_max = 3;
2531
12.6k
    u(5, aps_adaptation_parameter_set_id, 0, aps_id_max);
2532
12.6k
    flag(aps_chroma_present_flag);
2533
12.6k
    if (current->aps_params_type == VVC_ASP_TYPE_ALF)
2534
4.45k
        CHECK(FUNC(alf_data)(ctx, rw, current));
2535
8.14k
    else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
2536
4.74k
        CHECK(FUNC(lmcs_data)(ctx, rw, current));
2537
3.39k
    else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
2538
2.76k
        CHECK(FUNC(scaling_list_data)(ctx, rw, current));
2539
12.6k
    flag(aps_extension_flag);
2540
12.6k
    if (current->aps_extension_flag)
2541
7.77k
        CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2542
12.6k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2543
2544
12.6k
    return 0;
2545
12.6k
}
2546
2547
static int FUNC(aud) (CodedBitstreamContext *ctx, RWContext *rw,
2548
                     H266RawAUD *current)
2549
24.2k
{
2550
24.2k
    int err;
2551
2552
24.2k
    HEADER("Access Unit Delimiter");
2553
2554
24.2k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
2555
24.2k
                                 &current->nal_unit_header, VVC_AUD_NUT));
2556
2557
23.6k
    flag(aud_irap_or_gdr_flag);
2558
23.0k
    u(3, aud_pic_type, 0, 2);
2559
2560
20.0k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2561
17.1k
    return 0;
2562
20.0k
}
cbs_h266.c:cbs_h266_read_aud
Line
Count
Source
2549
21.6k
{
2550
21.6k
    int err;
2551
2552
21.6k
    HEADER("Access Unit Delimiter");
2553
2554
21.6k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
2555
21.6k
                                 &current->nal_unit_header, VVC_AUD_NUT));
2556
2557
21.0k
    flag(aud_irap_or_gdr_flag);
2558
20.4k
    u(3, aud_pic_type, 0, 2);
2559
2560
17.4k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2561
14.5k
    return 0;
2562
17.4k
}
cbs_h266.c:cbs_h266_write_aud
Line
Count
Source
2549
2.60k
{
2550
2.60k
    int err;
2551
2552
2.60k
    HEADER("Access Unit Delimiter");
2553
2554
2.60k
    CHECK(FUNC(nal_unit_header) (ctx, rw,
2555
2.60k
                                 &current->nal_unit_header, VVC_AUD_NUT));
2556
2557
2.60k
    flag(aud_irap_or_gdr_flag);
2558
2.60k
    u(3, aud_pic_type, 0, 2);
2559
2560
2.60k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2561
2.60k
    return 0;
2562
2.60k
}
2563
2564
static int FUNC(pred_weight_table) (CodedBitstreamContext *ctx, RWContext *rw,
2565
                                    const H266RawSPS *sps,
2566
                                    const H266RawPPS *pps,
2567
                                    const H266RefPicLists *ref_lists,
2568
                                    uint8_t num_ref_idx_active[2],
2569
                                    H266RawPredWeightTable *current)
2570
365k
{
2571
365k
    int err, i, j;
2572
365k
    ue(luma_log2_weight_denom, 0, 7);
2573
355k
    if (sps->sps_chroma_format_idc != 0) {
2574
349k
        se(delta_chroma_log2_weight_denom,
2575
349k
           -current->luma_log2_weight_denom,
2576
349k
           7 - current->luma_log2_weight_denom);
2577
349k
    } else {
2578
6.04k
        infer(delta_chroma_log2_weight_denom, 0);
2579
6.04k
    }
2580
344k
    if (pps->pps_wp_info_in_ph_flag) {
2581
233k
        ue(num_l0_weights, 0,
2582
223k
           FFMIN(15, ref_lists->rpl_ref_list[0].num_ref_entries));
2583
223k
        infer(num_weights_l0, current->num_l0_weights);
2584
223k
    } else {
2585
110k
        infer(num_weights_l0, num_ref_idx_active[0]);
2586
110k
    }
2587
488k
    for (i = 0; i < current->num_weights_l0; i++) {
2588
159k
        flags(luma_weight_l0_flag[i], 1, i);
2589
159k
    }
2590
328k
    if (sps->sps_chroma_format_idc != 0) {
2591
470k
        for (i = 0; i < current->num_weights_l0; i++)
2592
322k
            flags(chroma_weight_l0_flag[i], 1, i);
2593
322k
    }
2594
469k
    for (i = 0; i < current->num_weights_l0; i++) {
2595
148k
        if (current->luma_weight_l0_flag[i]) {
2596
105k
            ses(delta_luma_weight_l0[i], -128, 127, 1, i);
2597
103k
            ses(luma_offset_l0[i], -128, 127, 1, i);
2598
103k
        } else {
2599
43.3k
            infer(delta_luma_weight_l0[i], 0);
2600
43.3k
            infer(luma_offset_l0[i], 0);
2601
1.33k
        }
2602
146k
        if (current->chroma_weight_l0_flag[i]) {
2603
209k
            for (j = 0; j < 2; j++) {
2604
141k
                ses(delta_chroma_weight_l0[i][j], -128, 127, 2, i, j);
2605
139k
                ses(delta_chroma_offset_l0[i][j], -4 * 128, 4 * 127, 2, i, j);
2606
139k
            }
2607
72.1k
        }
2608
146k
    }
2609
2610
321k
    if (pps->pps_weighted_bipred_flag &&
2611
310k
        ref_lists->rpl_ref_list[1].num_ref_entries > 0) {
2612
83.9k
        if (pps->pps_wp_info_in_ph_flag) {
2613
63.1k
            ue(num_l1_weights, 0,
2614
61.9k
               FFMIN(15, ref_lists->rpl_ref_list[1].num_ref_entries));
2615
61.9k
            infer(num_weights_l1, current->num_l1_weights);
2616
61.9k
        } else {
2617
20.8k
            infer(num_weights_l1, num_ref_idx_active[1]);
2618
20.8k
        }
2619
237k
    } else {
2620
237k
        infer(num_weights_l1, 0);
2621
237k
    }
2622
2623
370k
    for (i = 0; i < current->num_weights_l1; i++)
2624
319k
        flags(luma_weight_l1_flag[i], 1, i);
2625
319k
    if (sps->sps_chroma_format_idc != 0) {
2626
363k
        for (i = 0; i < current->num_weights_l1; i++)
2627
313k
            flags(chroma_weight_l1_flag[i], 1, i);
2628
313k
    }
2629
358k
    for (i = 0; i < current->num_weights_l1; i++) {
2630
42.2k
        if (current->luma_weight_l1_flag[i]) {
2631
21.9k
            ses(delta_luma_weight_l1[i], -128, 127, 1, i);
2632
21.3k
            ses(luma_offset_l1[i], -128, 127, 1, i);
2633
21.3k
        } else {
2634
20.3k
            infer(delta_luma_weight_l1[i], 0);
2635
20.3k
            infer(luma_offset_l1[i], 0);
2636
1.15k
        }
2637
40.8k
        if (current->chroma_weight_l1_flag[i]) {
2638
67.5k
            for (j = 0; j < 2; j++) {
2639
45.9k
                ses(delta_chroma_weight_l1[i][j], -128, 127, 2, i, j);
2640
45.0k
                ses(delta_chroma_offset_l1[i][j], -4 * 128, 4 * 127, 2, i, j);
2641
45.0k
            }
2642
23.3k
        }
2643
40.8k
    }
2644
315k
    return 0;
2645
318k
}
cbs_h266.c:cbs_h266_read_pred_weight_table
Line
Count
Source
2570
361k
{
2571
361k
    int err, i, j;
2572
361k
    ue(luma_log2_weight_denom, 0, 7);
2573
350k
    if (sps->sps_chroma_format_idc != 0) {
2574
345k
        se(delta_chroma_log2_weight_denom,
2575
345k
           -current->luma_log2_weight_denom,
2576
345k
           7 - current->luma_log2_weight_denom);
2577
345k
    } else {
2578
5.64k
        infer(delta_chroma_log2_weight_denom, 0);
2579
5.64k
    }
2580
339k
    if (pps->pps_wp_info_in_ph_flag) {
2581
232k
        ue(num_l0_weights, 0,
2582
221k
           FFMIN(15, ref_lists->rpl_ref_list[0].num_ref_entries));
2583
221k
        infer(num_weights_l0, current->num_l0_weights);
2584
221k
    } else {
2585
107k
        infer(num_weights_l0, num_ref_idx_active[0]);
2586
107k
    }
2587
478k
    for (i = 0; i < current->num_weights_l0; i++) {
2588
153k
        flags(luma_weight_l0_flag[i], 1, i);
2589
153k
    }
2590
324k
    if (sps->sps_chroma_format_idc != 0) {
2591
460k
        for (i = 0; i < current->num_weights_l0; i++)
2592
318k
            flags(chroma_weight_l0_flag[i], 1, i);
2593
318k
    }
2594
459k
    for (i = 0; i < current->num_weights_l0; i++) {
2595
143k
        if (current->luma_weight_l0_flag[i]) {
2596
101k
            ses(delta_luma_weight_l0[i], -128, 127, 1, i);
2597
99.5k
            ses(luma_offset_l0[i], -128, 127, 1, i);
2598
99.5k
        } else {
2599
42.0k
            infer(delta_luma_weight_l0[i], 0);
2600
42.0k
            infer(luma_offset_l0[i], 0);
2601
42.0k
        }
2602
140k
        if (current->chroma_weight_l0_flag[i]) {
2603
204k
            for (j = 0; j < 2; j++) {
2604
138k
                ses(delta_chroma_weight_l0[i][j], -128, 127, 2, i, j);
2605
135k
                ses(delta_chroma_offset_l0[i][j], -4 * 128, 4 * 127, 2, i, j);
2606
135k
            }
2607
70.3k
        }
2608
140k
    }
2609
2610
316k
    if (pps->pps_weighted_bipred_flag &&
2611
306k
        ref_lists->rpl_ref_list[1].num_ref_entries > 0) {
2612
81.3k
        if (pps->pps_wp_info_in_ph_flag) {
2613
62.2k
            ue(num_l1_weights, 0,
2614
61.3k
               FFMIN(15, ref_lists->rpl_ref_list[1].num_ref_entries));
2615
61.3k
            infer(num_weights_l1, current->num_l1_weights);
2616
61.3k
        } else {
2617
19.1k
            infer(num_weights_l1, num_ref_idx_active[1]);
2618
19.1k
        }
2619
235k
    } else {
2620
235k
        infer(num_weights_l1, 0);
2621
235k
    }
2622
2623
363k
    for (i = 0; i < current->num_weights_l1; i++)
2624
315k
        flags(luma_weight_l1_flag[i], 1, i);
2625
315k
    if (sps->sps_chroma_format_idc != 0) {
2626
357k
        for (i = 0; i < current->num_weights_l1; i++)
2627
310k
            flags(chroma_weight_l1_flag[i], 1, i);
2628
310k
    }
2629
351k
    for (i = 0; i < current->num_weights_l1; i++) {
2630
39.3k
        if (current->luma_weight_l1_flag[i]) {
2631
20.1k
            ses(delta_luma_weight_l1[i], -128, 127, 1, i);
2632
19.6k
            ses(luma_offset_l1[i], -128, 127, 1, i);
2633
19.6k
        } else {
2634
19.2k
            infer(delta_luma_weight_l1[i], 0);
2635
19.2k
            infer(luma_offset_l1[i], 0);
2636
19.2k
        }
2637
37.9k
        if (current->chroma_weight_l1_flag[i]) {
2638
62.7k
            for (j = 0; j < 2; j++) {
2639
42.7k
                ses(delta_chroma_weight_l1[i][j], -128, 127, 2, i, j);
2640
41.8k
                ses(delta_chroma_offset_l1[i][j], -4 * 128, 4 * 127, 2, i, j);
2641
41.8k
            }
2642
21.7k
        }
2643
37.9k
    }
2644
312k
    return 0;
2645
315k
}
cbs_h266.c:cbs_h266_write_pred_weight_table
Line
Count
Source
2570
4.68k
{
2571
4.68k
    int err, i, j;
2572
4.68k
    ue(luma_log2_weight_denom, 0, 7);
2573
4.68k
    if (sps->sps_chroma_format_idc != 0) {
2574
4.27k
        se(delta_chroma_log2_weight_denom,
2575
4.27k
           -current->luma_log2_weight_denom,
2576
4.27k
           7 - current->luma_log2_weight_denom);
2577
4.27k
    } else {
2578
402
        infer(delta_chroma_log2_weight_denom, 0);
2579
402
    }
2580
4.48k
    if (pps->pps_wp_info_in_ph_flag) {
2581
1.38k
        ue(num_l0_weights, 0,
2582
1.38k
           FFMIN(15, ref_lists->rpl_ref_list[0].num_ref_entries));
2583
1.38k
        infer(num_weights_l0, current->num_l0_weights);
2584
3.10k
    } else {
2585
3.10k
        infer(num_weights_l0, num_ref_idx_active[0]);
2586
3.10k
    }
2587
9.91k
    for (i = 0; i < current->num_weights_l0; i++) {
2588
5.62k
        flags(luma_weight_l0_flag[i], 1, i);
2589
5.62k
    }
2590
4.28k
    if (sps->sps_chroma_format_idc != 0) {
2591
9.46k
        for (i = 0; i < current->num_weights_l0; i++)
2592
5.38k
            flags(chroma_weight_l0_flag[i], 1, i);
2593
4.07k
    }
2594
9.91k
    for (i = 0; i < current->num_weights_l0; i++) {
2595
5.62k
        if (current->luma_weight_l0_flag[i]) {
2596
4.29k
            ses(delta_luma_weight_l0[i], -128, 127, 1, i);
2597
4.29k
            ses(luma_offset_l0[i], -128, 127, 1, i);
2598
4.29k
        } else {
2599
1.33k
            infer(delta_luma_weight_l0[i], 0);
2600
1.33k
            infer(luma_offset_l0[i], 0);
2601
1.33k
        }
2602
5.62k
        if (current->chroma_weight_l0_flag[i]) {
2603
5.27k
            for (j = 0; j < 2; j++) {
2604
3.51k
                ses(delta_chroma_weight_l0[i][j], -128, 127, 2, i, j);
2605
3.51k
                ses(delta_chroma_offset_l0[i][j], -4 * 128, 4 * 127, 2, i, j);
2606
3.51k
            }
2607
1.75k
        }
2608
5.62k
    }
2609
2610
4.28k
    if (pps->pps_weighted_bipred_flag &&
2611
3.81k
        ref_lists->rpl_ref_list[1].num_ref_entries > 0) {
2612
2.52k
        if (pps->pps_wp_info_in_ph_flag) {
2613
855
            ue(num_l1_weights, 0,
2614
657
               FFMIN(15, ref_lists->rpl_ref_list[1].num_ref_entries));
2615
657
            infer(num_weights_l1, current->num_l1_weights);
2616
1.67k
        } else {
2617
1.67k
            infer(num_weights_l1, num_ref_idx_active[1]);
2618
1.67k
        }
2619
2.52k
    } else {
2620
1.75k
        infer(num_weights_l1, 0);
2621
1.75k
    }
2622
2623
6.58k
    for (i = 0; i < current->num_weights_l1; i++)
2624
3.69k
        flags(luma_weight_l1_flag[i], 1, i);
2625
3.69k
    if (sps->sps_chroma_format_idc != 0) {
2626
6.38k
        for (i = 0; i < current->num_weights_l1; i++)
2627
3.49k
            flags(chroma_weight_l1_flag[i], 1, i);
2628
3.49k
    }
2629
6.58k
    for (i = 0; i < current->num_weights_l1; i++) {
2630
2.89k
        if (current->luma_weight_l1_flag[i]) {
2631
1.73k
            ses(delta_luma_weight_l1[i], -128, 127, 1, i);
2632
1.73k
            ses(luma_offset_l1[i], -128, 127, 1, i);
2633
1.73k
        } else {
2634
1.15k
            infer(delta_luma_weight_l1[i], 0);
2635
1.15k
            infer(luma_offset_l1[i], 0);
2636
1.15k
        }
2637
2.89k
        if (current->chroma_weight_l1_flag[i]) {
2638
4.73k
            for (j = 0; j < 2; j++) {
2639
3.15k
                ses(delta_chroma_weight_l1[i][j], -128, 127, 2, i, j);
2640
3.15k
                ses(delta_chroma_offset_l1[i][j], -4 * 128, 4 * 127, 2, i, j);
2641
3.15k
            }
2642
1.57k
        }
2643
2.89k
    }
2644
3.69k
    return 0;
2645
3.69k
}
2646
2647
static int FUNC(picture_header) (CodedBitstreamContext *ctx, RWContext *rw,
2648
7.14M
                                 H266RawPictureHeader *current) {
2649
7.14M
    CodedBitstreamH266Context *h266 = ctx->priv_data;
2650
7.14M
    const H266RawVPS *vps;
2651
7.14M
    const H266RawSPS *sps;
2652
7.14M
    const H266RawPPS *pps;
2653
7.14M
    int err, i;
2654
7.14M
    unsigned int ctb_log2_size_y, min_cb_log2_size_y,
2655
7.14M
        min_qt_log2_size_intra_y, min_qt_log2_size_inter_y;
2656
7.14M
    uint8_t qp_bd_offset;
2657
2658
7.14M
    flag(ph_gdr_or_irap_pic_flag);
2659
7.13M
    flag(ph_non_ref_pic_flag);
2660
7.13M
    if (current->ph_gdr_or_irap_pic_flag)
2661
7.13M
        flag(ph_gdr_pic_flag);
2662
6.05M
    else
2663
6.05M
        infer(ph_gdr_pic_flag, 0);
2664
7.13M
    flag(ph_inter_slice_allowed_flag);
2665
7.13M
    if (current->ph_inter_slice_allowed_flag)
2666
7.13M
        flag(ph_intra_slice_allowed_flag);
2667
6.24M
    else
2668
6.24M
        infer(ph_intra_slice_allowed_flag, 1);
2669
7.13M
    ue(ph_pic_parameter_set_id, 0, VVC_MAX_PPS_COUNT - 1);
2670
7.09M
    pps = h266->pps[current->ph_pic_parameter_set_id];
2671
7.09M
    if (!pps) {
2672
573k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
2673
573k
               current->ph_pic_parameter_set_id);
2674
573k
        return AVERROR_INVALIDDATA;
2675
573k
    }
2676
6.51M
    sps = h266->sps[pps->pps_seq_parameter_set_id];
2677
6.51M
    if (!sps) {
2678
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
2679
0
               pps->pps_seq_parameter_set_id);
2680
0
        return AVERROR_INVALIDDATA;
2681
0
    }
2682
6.51M
    vps = h266->vps[sps->sps_video_parameter_set_id];
2683
6.51M
    if (!vps) {
2684
1.36k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n",
2685
1.36k
               sps->sps_video_parameter_set_id);
2686
1.36k
        return AVERROR_INVALIDDATA;
2687
1.36k
    }
2688
2689
6.51M
    ub(sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4, ph_pic_order_cnt_lsb);
2690
6.49M
    if (current->ph_gdr_pic_flag)
2691
6.49M
        ue(ph_recovery_poc_cnt, 0,
2692
6.48M
           1 << (sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4));
2693
2694
42.8M
    for (i = 0; i < sps->sps_num_extra_ph_bytes * 8; i++) {
2695
36.3M
        if (sps->sps_extra_ph_bit_present_flag[i])
2696
36.3M
            flags(ph_extra_bit[i], 1, i);
2697
36.3M
    }
2698
6.47M
    if (sps->sps_poc_msb_cycle_flag) {
2699
74.8k
        flag(ph_poc_msb_cycle_present_flag);
2700
74.4k
        if (current->ph_poc_msb_cycle_present_flag)
2701
17.5k
            ub(sps->sps_poc_msb_cycle_len_minus1 + 1, ph_poc_msb_cycle_val);
2702
74.4k
    }
2703
6.47M
    if (sps->sps_alf_enabled_flag && pps->pps_alf_info_in_ph_flag) {
2704
383k
        flag(ph_alf_enabled_flag);
2705
382k
        if (current->ph_alf_enabled_flag) {
2706
2707
138k
            ub(3, ph_num_alf_aps_ids_luma);
2708
681k
            for (i = 0; i < current->ph_num_alf_aps_ids_luma; i++)
2709
547k
                ubs(3, ph_alf_aps_id_luma[i], 1, i);
2710
2711
133k
            if (sps->sps_chroma_format_idc != 0) {
2712
127k
                flag(ph_alf_cb_enabled_flag);
2713
127k
                flag(ph_alf_cr_enabled_flag);
2714
127k
            } else {
2715
6.25k
                infer(ph_alf_cb_enabled_flag, 0);
2716
6.06k
                infer(ph_alf_cr_enabled_flag, 0);
2717
586
            }
2718
2719
132k
            if (current->ph_alf_cb_enabled_flag
2720
96.6k
                || current->ph_alf_cr_enabled_flag) {
2721
96.6k
                ub(3, ph_alf_aps_id_chroma);
2722
96.6k
            }
2723
2724
131k
            if (sps->sps_ccalf_enabled_flag) {
2725
102k
                flag(ph_alf_cc_cb_enabled_flag);
2726
102k
                if (current->ph_alf_cc_cb_enabled_flag)
2727
62.2k
                    ub(3, ph_alf_cc_cb_aps_id);
2728
102k
                flag(ph_alf_cc_cr_enabled_flag);
2729
100k
                if (current->ph_alf_cc_cr_enabled_flag)
2730
60.6k
                    ub(3, ph_alf_cc_cr_aps_id);
2731
100k
            }
2732
131k
        }
2733
6.09M
    } else {
2734
6.09M
        infer(ph_alf_enabled_flag, 0);
2735
6.09M
    }
2736
6.46M
    if (sps->sps_lmcs_enabled_flag) {
2737
5.83M
        flag(ph_lmcs_enabled_flag);
2738
5.82M
        if (current->ph_lmcs_enabled_flag) {
2739
335k
            ub(2, ph_lmcs_aps_id);
2740
334k
            if (sps->sps_chroma_format_idc != 0)
2741
334k
                flag(ph_chroma_residual_scale_flag);
2742
15.7k
            else
2743
15.7k
                infer(ph_chroma_residual_scale_flag, 0);
2744
334k
        }
2745
5.82M
    } else {
2746
634k
        infer(ph_lmcs_enabled_flag, 0);
2747
634k
        infer(ph_chroma_residual_scale_flag, 0);
2748
9.80k
    }
2749
2750
6.45M
    if (sps->sps_explicit_scaling_list_enabled_flag) {
2751
4.96M
        flag(ph_explicit_scaling_list_enabled_flag);
2752
4.96M
        if (current->ph_explicit_scaling_list_enabled_flag) {
2753
            //todo: check the ph_scaling_list_aps_id range, when aps ready
2754
324k
            ub(3, ph_scaling_list_aps_id);
2755
324k
        }
2756
4.96M
    } else {
2757
1.49M
        infer(ph_explicit_scaling_list_enabled_flag, 0);
2758
1.49M
    }
2759
6.45M
    if (sps->sps_virtual_boundaries_enabled_flag &&
2760
1.97M
        !sps->sps_virtual_boundaries_present_flag) {
2761
1.30M
        flag(ph_virtual_boundaries_present_flag);
2762
1.30M
        if (current->ph_virtual_boundaries_present_flag) {
2763
107k
            ue(ph_num_ver_virtual_boundaries,
2764
91.3k
               0, pps->pps_pic_width_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
2765
111k
            for (i = 0; i < current->ph_num_ver_virtual_boundaries; i++) {
2766
20.3k
                ues(ph_virtual_boundary_pos_x_minus1[i],
2767
20.3k
                    0, (pps->pps_pic_width_in_luma_samples + 7) / 8 - 2, 1, i);
2768
20.3k
            }
2769
90.7k
            ue(ph_num_hor_virtual_boundaries,
2770
83.0k
               0, pps->pps_pic_height_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
2771
103k
            for (i = 0; i < current->ph_num_hor_virtual_boundaries; i++) {
2772
21.2k
                ues(ph_virtual_boundary_pos_y_minus1[i],
2773
21.2k
                    0, (pps->pps_pic_height_in_luma_samples + 7) / 8 - 2, 1, i);
2774
21.2k
            }
2775
1.19M
        } else {
2776
1.19M
            infer(ph_num_ver_virtual_boundaries, 0);
2777
1.19M
            infer(ph_num_hor_virtual_boundaries, 0);
2778
1.67k
        }
2779
1.30M
    }
2780
6.42M
    if (pps->pps_output_flag_present_flag && !current->ph_non_ref_pic_flag)
2781
6.42M
        flag(ph_pic_output_flag);
2782
1.41M
    else
2783
1.41M
        infer(ph_pic_output_flag, 1);
2784
6.42M
    if (pps->pps_rpl_info_in_ph_flag) {
2785
905k
        CHECK(FUNC(ref_pic_lists)
2786
905k
              (ctx, rw, sps, pps, &current->ph_ref_pic_lists));
2787
905k
    }
2788
6.35M
    if (sps->sps_partition_constraints_override_enabled_flag)
2789
6.35M
        flag(ph_partition_constraints_override_flag);
2790
3.07M
    else
2791
3.07M
        infer(ph_partition_constraints_override_flag, 0);
2792
2793
6.35M
    ctb_log2_size_y = sps->sps_log2_ctu_size_minus5 + 5;
2794
6.35M
    min_cb_log2_size_y = sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
2795
6.35M
    if (current->ph_intra_slice_allowed_flag) {
2796
6.19M
        if (current->ph_partition_constraints_override_flag) {
2797
1.15M
            ue(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2798
1.12M
               0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2799
1.12M
            ue(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2800
953k
               0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2801
953k
            if (current->ph_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
2802
42.5k
                min_qt_log2_size_intra_y =
2803
42.5k
                    current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2804
42.5k
                    min_cb_log2_size_y;
2805
42.5k
                ue(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2806
34.4k
                   0, (sps->sps_qtbtt_dual_tree_intra_flag ?
2807
34.4k
                       FFMIN(6, ctb_log2_size_y) :
2808
34.4k
                       ctb_log2_size_y) - min_qt_log2_size_intra_y);
2809
34.4k
                ue(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2810
34.4k
                   0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
2811
910k
            } else {
2812
910k
                infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2813
910k
                      sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2814
910k
                infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2815
5.66k
                      sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2816
5.66k
            }
2817
940k
            if (sps->sps_qtbtt_dual_tree_intra_flag) {
2818
96.1k
                ue(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2819
89.5k
                   0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2820
89.5k
                ue(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2821
53.5k
                   0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2822
53.5k
                if (sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
2823
46.1k
                    unsigned int min_qt_log2_size_intra_c =
2824
46.1k
                        current->ph_log2_diff_min_qt_min_cb_intra_slice_chroma +
2825
46.1k
                        min_cb_log2_size_y;
2826
46.1k
                    ue(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2827
38.9k
                       0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2828
38.9k
                    ue(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2829
38.9k
                       0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2830
38.9k
                } else {
2831
7.40k
                    infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2832
7.40k
                          sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2833
7.20k
                    infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2834
492
                          sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2835
492
                }
2836
53.5k
            }
2837
5.04M
        } else {
2838
5.04M
            infer(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2839
5.04M
                  sps->sps_log2_diff_min_qt_min_cb_intra_slice_luma);
2840
5.04M
            infer(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2841
8.05k
                  sps->sps_max_mtt_hierarchy_depth_intra_slice_luma);
2842
5.04M
            infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2843
7.84k
                  sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2844
5.04M
            infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2845
7.65k
                  sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2846
5.04M
            infer(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2847
7.45k
                  sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma);
2848
5.04M
            infer(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2849
6.09k
                  sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma);
2850
5.04M
            infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2851
5.89k
                  sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2852
5.04M
            infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2853
5.67k
                  sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2854
5.67k
        }
2855
2856
5.92M
        min_qt_log2_size_intra_y =
2857
5.92M
            current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2858
5.92M
            min_cb_log2_size_y;
2859
5.92M
        if (pps->pps_cu_qp_delta_enabled_flag)
2860
5.92M
            ue(ph_cu_qp_delta_subdiv_intra_slice, 0,
2861
3.31M
               2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2862
3.31M
                    current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2863
3.31M
        else
2864
3.31M
            infer(ph_cu_qp_delta_subdiv_intra_slice, 0);
2865
2866
5.87M
        if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2867
5.87M
            ue(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0,
2868
5.33M
               2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2869
5.33M
                    current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2870
5.33M
        else
2871
5.33M
            infer(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0);
2872
5.87M
    }
2873
6.01M
    if (current->ph_inter_slice_allowed_flag) {
2874
621k
        if (current->ph_partition_constraints_override_flag) {
2875
305k
            ue(ph_log2_diff_min_qt_min_cb_inter_slice,
2876
295k
               0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2877
295k
            min_qt_log2_size_inter_y =
2878
295k
                current->ph_log2_diff_min_qt_min_cb_inter_slice +
2879
295k
                min_cb_log2_size_y;
2880
295k
            ue(ph_max_mtt_hierarchy_depth_inter_slice, 0,
2881
291k
               2 * (ctb_log2_size_y - min_cb_log2_size_y));
2882
291k
            if (current->ph_max_mtt_hierarchy_depth_inter_slice != 0) {
2883
47.4k
                ue(ph_log2_diff_max_bt_min_qt_inter_slice,
2884
43.8k
                   0, ctb_log2_size_y - min_qt_log2_size_inter_y);
2885
43.8k
                ue(ph_log2_diff_max_tt_min_qt_inter_slice,
2886
43.8k
                   0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
2887
43.8k
            }
2888
316k
        } else {
2889
316k
            infer(ph_log2_diff_min_qt_min_cb_inter_slice,
2890
316k
                  sps->sps_log2_diff_min_qt_min_cb_inter_slice);
2891
9.56k
            min_qt_log2_size_inter_y =
2892
9.56k
                current->ph_log2_diff_min_qt_min_cb_inter_slice +
2893
9.56k
                min_cb_log2_size_y;
2894
315k
            infer(ph_max_mtt_hierarchy_depth_inter_slice,
2895
9.56k
                  sps->sps_max_mtt_hierarchy_depth_inter_slice);
2896
315k
            infer(ph_log2_diff_max_bt_min_qt_inter_slice,
2897
9.36k
                  sps->sps_log2_diff_max_bt_min_qt_inter_slice);
2898
315k
            infer(ph_log2_diff_max_tt_min_qt_inter_slice,
2899
9.13k
                  sps->sps_log2_diff_max_tt_min_qt_inter_slice);
2900
9.13k
        }
2901
2902
600k
        if (pps->pps_cu_qp_delta_enabled_flag)
2903
600k
            ue(ph_cu_qp_delta_subdiv_inter_slice, 0,
2904
258k
               2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2905
258k
                    current->ph_max_mtt_hierarchy_depth_inter_slice));
2906
258k
        else
2907
258k
            infer(ph_cu_qp_delta_subdiv_inter_slice, 0);
2908
2909
586k
        if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2910
586k
            ue(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0,
2911
424k
               2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2912
424k
                    current->ph_max_mtt_hierarchy_depth_inter_slice));
2913
424k
        else
2914
424k
            infer(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0);
2915
578k
        if (sps->sps_temporal_mvp_enabled_flag) {
2916
453k
            flag(ph_temporal_mvp_enabled_flag);
2917
452k
            if (current->ph_temporal_mvp_enabled_flag &&
2918
319k
                pps->pps_rpl_info_in_ph_flag) {
2919
188k
                if (current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0)
2920
188k
                    flag(ph_collocated_from_l0_flag);
2921
111k
                else
2922
111k
                    infer(ph_collocated_from_l0_flag, 1);
2923
187k
                if ((current->ph_collocated_from_l0_flag &&
2924
156k
                     current->ph_ref_pic_lists.rpl_ref_list[0].num_ref_entries > 1)
2925
93.0k
                     || (!current->ph_collocated_from_l0_flag &&
2926
101k
                         current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 1)) {
2927
101k
                    unsigned int idx =
2928
101k
                        current->ph_collocated_from_l0_flag ? 0 : 1;
2929
101k
                    ue(ph_collocated_ref_idx, 0,
2930
101k
                       current->ph_ref_pic_lists.rpl_ref_list[idx].
2931
101k
                       num_ref_entries - 1);
2932
101k
                } else {
2933
86.3k
                    infer(ph_collocated_ref_idx, 0);
2934
86.3k
                }
2935
187k
            }
2936
452k
        }
2937
574k
        if (sps->sps_mmvd_fullpel_only_enabled_flag)
2938
574k
            flag(ph_mmvd_fullpel_only_flag);
2939
208k
        else
2940
208k
            infer(ph_mmvd_fullpel_only_flag, 0);
2941
573k
        if (!pps->pps_rpl_info_in_ph_flag ||
2942
388k
            current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0) {
2943
388k
            flag(ph_mvd_l1_zero_flag);
2944
388k
            if (sps->sps_bdof_control_present_in_ph_flag) {
2945
122k
                flag(ph_bdof_disabled_flag);
2946
265k
            } else {
2947
265k
                if (!sps->sps_bdof_control_present_in_ph_flag)
2948
265k
                    infer(ph_bdof_disabled_flag,
2949
265k
                          1 - sps->sps_bdof_enabled_flag);
2950
0
                else
2951
0
                    infer(ph_bdof_disabled_flag, 1);
2952
265k
            }
2953
387k
            if (sps->sps_dmvr_control_present_in_ph_flag) {
2954
213k
                flag(ph_dmvr_disabled_flag);
2955
213k
            } else {
2956
173k
                if (!sps->sps_dmvr_control_present_in_ph_flag)
2957
173k
                    infer(ph_dmvr_disabled_flag,
2958
173k
                          1 - sps->sps_dmvr_enabled_flag);
2959
0
                else
2960
0
                    infer(ph_dmvr_disabled_flag, 1);
2961
173k
            }
2962
387k
        } else {
2963
184k
            infer(ph_mvd_l1_zero_flag, 1);
2964
184k
        }
2965
570k
        if (sps->sps_prof_control_present_in_ph_flag)
2966
570k
            flag(ph_prof_disabled_flag);
2967
480k
        else
2968
480k
            infer(ph_prof_disabled_flag, !sps->sps_affine_prof_enabled_flag);
2969
569k
        if ((pps->pps_weighted_pred_flag ||
2970
473k
             pps->pps_weighted_bipred_flag) && pps->pps_wp_info_in_ph_flag) {
2971
2972
            // if pps->pps_wp_info_in_ph_fla == 1
2973
            // pred_weight_table will not use num_ref_idx_active
2974
239k
            uint8_t num_ref_idx_active[2] = { 0, 0 };
2975
239k
            CHECK(FUNC(pred_weight_table)
2976
239k
                  (ctx, rw, sps, pps, &current->ph_ref_pic_lists,
2977
239k
                   num_ref_idx_active, &current->ph_pred_weight_table));
2978
239k
        }
2979
569k
    }
2980
2981
5.94M
    qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2982
5.94M
    if (pps->pps_qp_delta_info_in_ph_flag)
2983
5.94M
        se(ph_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
2984
5.93M
           63 - (26 + pps->pps_init_qp_minus26));
2985
2986
5.93M
    if (sps->sps_joint_cbcr_enabled_flag)
2987
5.93M
        flag(ph_joint_cbcr_sign_flag);
2988
376k
    else
2989
376k
        infer(ph_joint_cbcr_sign_flag, 0);
2990
5.92M
    if (sps->sps_sao_enabled_flag && pps->pps_sao_info_in_ph_flag) {
2991
305k
        flag(ph_sao_luma_enabled_flag);
2992
305k
        if (sps->sps_chroma_format_idc != 0)
2993
305k
            flag(ph_sao_chroma_enabled_flag);
2994
6.85k
        else
2995
6.85k
            infer(ph_sao_chroma_enabled_flag, 0);
2996
5.62M
    } else {
2997
5.62M
        infer(ph_sao_luma_enabled_flag, 0);
2998
5.62M
        infer(ph_sao_chroma_enabled_flag, 0);
2999
14.8k
    }
3000
3001
5.92M
    if (pps->pps_dbf_info_in_ph_flag)
3002
5.92M
        flag(ph_deblocking_params_present_flag);
3003
5.35M
    else
3004
5.35M
        infer(ph_deblocking_params_present_flag, 0);
3005
3006
5.92M
    if (current->ph_deblocking_params_present_flag) {
3007
421k
        if (!pps->pps_deblocking_filter_disabled_flag) {
3008
30.3k
            flag(ph_deblocking_filter_disabled_flag);
3009
29.8k
            if (!current->ph_deblocking_filter_disabled_flag) {
3010
13.4k
                se(ph_luma_beta_offset_div2, -12, 12);
3011
12.4k
                se(ph_luma_tc_offset_div2, -12, 12);
3012
11.3k
                if (pps->pps_chroma_tool_offsets_present_flag) {
3013
8.18k
                    se(ph_cb_beta_offset_div2, -12, 12);
3014
7.88k
                    se(ph_cb_tc_offset_div2, -12, 12);
3015
7.46k
                    se(ph_cr_beta_offset_div2, -12, 12);
3016
6.96k
                    se(ph_cr_tc_offset_div2, -12, 12);
3017
6.96k
                } else {
3018
3.16k
                    infer(ph_cb_beta_offset_div2,
3019
3.16k
                          current->ph_luma_beta_offset_div2);
3020
2.07k
                    infer(ph_cb_tc_offset_div2,
3021
792
                          current->ph_luma_tc_offset_div2);
3022
1.80k
                    infer(ph_cr_beta_offset_div2,
3023
525
                          current->ph_luma_beta_offset_div2);
3024
1.58k
                    infer(ph_cr_tc_offset_div2,
3025
303
                          current->ph_luma_tc_offset_div2);
3026
303
                }
3027
11.3k
            }
3028
390k
        } else {
3029
390k
            infer(ph_deblocking_filter_disabled_flag, 0);
3030
390k
        }
3031
5.50M
    } else {
3032
5.50M
        infer(ph_deblocking_filter_disabled_flag, pps->pps_deblocking_filter_disabled_flag);
3033
5.50M
        if (!current->ph_deblocking_filter_disabled_flag) {
3034
2.89M
            infer(ph_luma_beta_offset_div2, pps->pps_luma_beta_offset_div2);
3035
2.89M
            infer(ph_luma_tc_offset_div2, pps->pps_luma_tc_offset_div2);
3036
2.89M
            infer(ph_cb_beta_offset_div2, pps->pps_cb_beta_offset_div2);
3037
2.89M
            infer(ph_cb_tc_offset_div2, pps->pps_cb_tc_offset_div2);
3038
2.89M
            infer(ph_cr_beta_offset_div2, pps->pps_cr_beta_offset_div2);
3039
2.89M
            infer(ph_cr_tc_offset_div2, pps->pps_cr_tc_offset_div2);
3040
12.3k
        }
3041
14.7k
    }
3042
3043
5.91M
    if (pps->pps_picture_header_extension_present_flag) {
3044
3.06M
        ue(ph_extension_length, 0, 256);
3045
6.40M
        for (i = 0; i < current->ph_extension_length; i++)
3046
3.46M
            us(8, ph_extension_data_byte[i], 0x00, 0xff, 1, i);
3047
3.04M
    }
3048
3049
5.79M
    return 0;
3050
5.91M
}
cbs_h266.c:cbs_h266_read_picture_header
Line
Count
Source
2648
7.10M
                                 H266RawPictureHeader *current) {
2649
7.10M
    CodedBitstreamH266Context *h266 = ctx->priv_data;
2650
7.10M
    const H266RawVPS *vps;
2651
7.10M
    const H266RawSPS *sps;
2652
7.10M
    const H266RawPPS *pps;
2653
7.10M
    int err, i;
2654
7.10M
    unsigned int ctb_log2_size_y, min_cb_log2_size_y,
2655
7.10M
        min_qt_log2_size_intra_y, min_qt_log2_size_inter_y;
2656
7.10M
    uint8_t qp_bd_offset;
2657
2658
7.10M
    flag(ph_gdr_or_irap_pic_flag);
2659
7.09M
    flag(ph_non_ref_pic_flag);
2660
7.09M
    if (current->ph_gdr_or_irap_pic_flag)
2661
7.09M
        flag(ph_gdr_pic_flag);
2662
6.04M
    else
2663
6.04M
        infer(ph_gdr_pic_flag, 0);
2664
7.09M
    flag(ph_inter_slice_allowed_flag);
2665
7.09M
    if (current->ph_inter_slice_allowed_flag)
2666
7.09M
        flag(ph_intra_slice_allowed_flag);
2667
6.23M
    else
2668
6.23M
        infer(ph_intra_slice_allowed_flag, 1);
2669
7.09M
    ue(ph_pic_parameter_set_id, 0, VVC_MAX_PPS_COUNT - 1);
2670
7.05M
    pps = h266->pps[current->ph_pic_parameter_set_id];
2671
7.05M
    if (!pps) {
2672
572k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
2673
572k
               current->ph_pic_parameter_set_id);
2674
572k
        return AVERROR_INVALIDDATA;
2675
572k
    }
2676
6.48M
    sps = h266->sps[pps->pps_seq_parameter_set_id];
2677
6.48M
    if (!sps) {
2678
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
2679
0
               pps->pps_seq_parameter_set_id);
2680
0
        return AVERROR_INVALIDDATA;
2681
0
    }
2682
6.48M
    vps = h266->vps[sps->sps_video_parameter_set_id];
2683
6.48M
    if (!vps) {
2684
1.16k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n",
2685
1.16k
               sps->sps_video_parameter_set_id);
2686
1.16k
        return AVERROR_INVALIDDATA;
2687
1.16k
    }
2688
2689
6.48M
    ub(sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4, ph_pic_order_cnt_lsb);
2690
6.46M
    if (current->ph_gdr_pic_flag)
2691
6.46M
        ue(ph_recovery_poc_cnt, 0,
2692
6.45M
           1 << (sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4));
2693
2694
42.7M
    for (i = 0; i < sps->sps_num_extra_ph_bytes * 8; i++) {
2695
36.3M
        if (sps->sps_extra_ph_bit_present_flag[i])
2696
36.3M
            flags(ph_extra_bit[i], 1, i);
2697
36.3M
    }
2698
6.44M
    if (sps->sps_poc_msb_cycle_flag) {
2699
72.3k
        flag(ph_poc_msb_cycle_present_flag);
2700
71.8k
        if (current->ph_poc_msb_cycle_present_flag)
2701
16.6k
            ub(sps->sps_poc_msb_cycle_len_minus1 + 1, ph_poc_msb_cycle_val);
2702
71.8k
    }
2703
6.44M
    if (sps->sps_alf_enabled_flag && pps->pps_alf_info_in_ph_flag) {
2704
374k
        flag(ph_alf_enabled_flag);
2705
373k
        if (current->ph_alf_enabled_flag) {
2706
2707
131k
            ub(3, ph_num_alf_aps_ids_luma);
2708
664k
            for (i = 0; i < current->ph_num_alf_aps_ids_luma; i++)
2709
537k
                ubs(3, ph_alf_aps_id_luma[i], 1, i);
2710
2711
127k
            if (sps->sps_chroma_format_idc != 0) {
2712
121k
                flag(ph_alf_cb_enabled_flag);
2713
121k
                flag(ph_alf_cr_enabled_flag);
2714
121k
            } else {
2715
5.47k
                infer(ph_alf_cb_enabled_flag, 0);
2716
5.47k
                infer(ph_alf_cr_enabled_flag, 0);
2717
5.47k
            }
2718
2719
126k
            if (current->ph_alf_cb_enabled_flag
2720
91.8k
                || current->ph_alf_cr_enabled_flag) {
2721
91.8k
                ub(3, ph_alf_aps_id_chroma);
2722
91.8k
            }
2723
2724
125k
            if (sps->sps_ccalf_enabled_flag) {
2725
97.9k
                flag(ph_alf_cc_cb_enabled_flag);
2726
97.4k
                if (current->ph_alf_cc_cb_enabled_flag)
2727
58.7k
                    ub(3, ph_alf_cc_cb_aps_id);
2728
96.9k
                flag(ph_alf_cc_cr_enabled_flag);
2729
95.8k
                if (current->ph_alf_cc_cr_enabled_flag)
2730
59.6k
                    ub(3, ph_alf_cc_cr_aps_id);
2731
95.8k
            }
2732
125k
        }
2733
6.07M
    } else {
2734
6.07M
        infer(ph_alf_enabled_flag, 0);
2735
6.07M
    }
2736
6.43M
    if (sps->sps_lmcs_enabled_flag) {
2737
5.80M
        flag(ph_lmcs_enabled_flag);
2738
5.80M
        if (current->ph_lmcs_enabled_flag) {
2739
323k
            ub(2, ph_lmcs_aps_id);
2740
322k
            if (sps->sps_chroma_format_idc != 0)
2741
322k
                flag(ph_chroma_residual_scale_flag);
2742
14.4k
            else
2743
14.4k
                infer(ph_chroma_residual_scale_flag, 0);
2744
322k
        }
2745
5.80M
    } else {
2746
624k
        infer(ph_lmcs_enabled_flag, 0);
2747
624k
        infer(ph_chroma_residual_scale_flag, 0);
2748
624k
    }
2749
2750
6.42M
    if (sps->sps_explicit_scaling_list_enabled_flag) {
2751
4.95M
        flag(ph_explicit_scaling_list_enabled_flag);
2752
4.95M
        if (current->ph_explicit_scaling_list_enabled_flag) {
2753
            //todo: check the ph_scaling_list_aps_id range, when aps ready
2754
319k
            ub(3, ph_scaling_list_aps_id);
2755
319k
        }
2756
4.95M
    } else {
2757
1.47M
        infer(ph_explicit_scaling_list_enabled_flag, 0);
2758
1.47M
    }
2759
6.42M
    if (sps->sps_virtual_boundaries_enabled_flag &&
2760
1.96M
        !sps->sps_virtual_boundaries_present_flag) {
2761
1.30M
        flag(ph_virtual_boundaries_present_flag);
2762
1.30M
        if (current->ph_virtual_boundaries_present_flag) {
2763
105k
            ue(ph_num_ver_virtual_boundaries,
2764
89.2k
               0, pps->pps_pic_width_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
2765
107k
            for (i = 0; i < current->ph_num_ver_virtual_boundaries; i++) {
2766
18.4k
                ues(ph_virtual_boundary_pos_x_minus1[i],
2767
18.4k
                    0, (pps->pps_pic_width_in_luma_samples + 7) / 8 - 2, 1, i);
2768
18.4k
            }
2769
88.7k
            ue(ph_num_hor_virtual_boundaries,
2770
80.9k
               0, pps->pps_pic_height_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
2771
99.6k
            for (i = 0; i < current->ph_num_hor_virtual_boundaries; i++) {
2772
19.0k
                ues(ph_virtual_boundary_pos_y_minus1[i],
2773
19.0k
                    0, (pps->pps_pic_height_in_luma_samples + 7) / 8 - 2, 1, i);
2774
19.0k
            }
2775
1.19M
        } else {
2776
1.19M
            infer(ph_num_ver_virtual_boundaries, 0);
2777
1.19M
            infer(ph_num_hor_virtual_boundaries, 0);
2778
1.19M
        }
2779
1.30M
    }
2780
6.39M
    if (pps->pps_output_flag_present_flag && !current->ph_non_ref_pic_flag)
2781
6.39M
        flag(ph_pic_output_flag);
2782
1.38M
    else
2783
1.38M
        infer(ph_pic_output_flag, 1);
2784
6.39M
    if (pps->pps_rpl_info_in_ph_flag) {
2785
898k
        CHECK(FUNC(ref_pic_lists)
2786
898k
              (ctx, rw, sps, pps, &current->ph_ref_pic_lists));
2787
898k
    }
2788
6.32M
    if (sps->sps_partition_constraints_override_enabled_flag)
2789
6.32M
        flag(ph_partition_constraints_override_flag);
2790
3.06M
    else
2791
3.06M
        infer(ph_partition_constraints_override_flag, 0);
2792
2793
6.32M
    ctb_log2_size_y = sps->sps_log2_ctu_size_minus5 + 5;
2794
6.32M
    min_cb_log2_size_y = sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
2795
6.32M
    if (current->ph_intra_slice_allowed_flag) {
2796
6.18M
        if (current->ph_partition_constraints_override_flag) {
2797
1.14M
            ue(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2798
1.11M
               0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2799
1.11M
            ue(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2800
946k
               0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2801
946k
            if (current->ph_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
2802
41.4k
                min_qt_log2_size_intra_y =
2803
41.4k
                    current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2804
41.4k
                    min_cb_log2_size_y;
2805
41.4k
                ue(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2806
33.5k
                   0, (sps->sps_qtbtt_dual_tree_intra_flag ?
2807
33.5k
                       FFMIN(6, ctb_log2_size_y) :
2808
33.5k
                       ctb_log2_size_y) - min_qt_log2_size_intra_y);
2809
33.5k
                ue(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2810
33.5k
                   0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
2811
904k
            } else {
2812
904k
                infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2813
904k
                      sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2814
904k
                infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2815
904k
                      sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2816
904k
            }
2817
934k
            if (sps->sps_qtbtt_dual_tree_intra_flag) {
2818
91.4k
                ue(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2819
84.9k
                   0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2820
84.9k
                ue(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2821
49.2k
                   0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2822
49.2k
                if (sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
2823
42.5k
                    unsigned int min_qt_log2_size_intra_c =
2824
42.5k
                        current->ph_log2_diff_min_qt_min_cb_intra_slice_chroma +
2825
42.5k
                        min_cb_log2_size_y;
2826
42.5k
                    ue(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2827
35.5k
                       0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2828
35.5k
                    ue(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2829
35.5k
                       0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2830
35.5k
                } else {
2831
6.71k
                    infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2832
6.71k
                          sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2833
6.71k
                    infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2834
6.71k
                          sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2835
6.71k
                }
2836
49.2k
            }
2837
5.03M
        } else {
2838
5.03M
            infer(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2839
5.03M
                  sps->sps_log2_diff_min_qt_min_cb_intra_slice_luma);
2840
5.03M
            infer(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2841
5.03M
                  sps->sps_max_mtt_hierarchy_depth_intra_slice_luma);
2842
5.03M
            infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2843
5.03M
                  sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2844
5.03M
            infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2845
5.03M
                  sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2846
5.03M
            infer(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2847
5.03M
                  sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma);
2848
5.03M
            infer(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2849
5.03M
                  sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma);
2850
5.03M
            infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2851
5.03M
                  sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2852
5.03M
            infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2853
5.03M
                  sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2854
5.03M
        }
2855
2856
5.91M
        min_qt_log2_size_intra_y =
2857
5.91M
            current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2858
5.91M
            min_cb_log2_size_y;
2859
5.91M
        if (pps->pps_cu_qp_delta_enabled_flag)
2860
5.91M
            ue(ph_cu_qp_delta_subdiv_intra_slice, 0,
2861
3.30M
               2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2862
3.30M
                    current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2863
3.30M
        else
2864
3.30M
            infer(ph_cu_qp_delta_subdiv_intra_slice, 0);
2865
2866
5.86M
        if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2867
5.86M
            ue(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0,
2868
5.32M
               2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2869
5.32M
                    current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2870
5.32M
        else
2871
5.32M
            infer(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0);
2872
5.86M
    }
2873
5.98M
    if (current->ph_inter_slice_allowed_flag) {
2874
601k
        if (current->ph_partition_constraints_override_flag) {
2875
295k
            ue(ph_log2_diff_min_qt_min_cb_inter_slice,
2876
285k
               0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2877
285k
            min_qt_log2_size_inter_y =
2878
285k
                current->ph_log2_diff_min_qt_min_cb_inter_slice +
2879
285k
                min_cb_log2_size_y;
2880
285k
            ue(ph_max_mtt_hierarchy_depth_inter_slice, 0,
2881
281k
               2 * (ctb_log2_size_y - min_cb_log2_size_y));
2882
281k
            if (current->ph_max_mtt_hierarchy_depth_inter_slice != 0) {
2883
44.5k
                ue(ph_log2_diff_max_bt_min_qt_inter_slice,
2884
41.1k
                   0, ctb_log2_size_y - min_qt_log2_size_inter_y);
2885
41.1k
                ue(ph_log2_diff_max_tt_min_qt_inter_slice,
2886
41.1k
                   0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
2887
41.1k
            }
2888
306k
        } else {
2889
306k
            infer(ph_log2_diff_min_qt_min_cb_inter_slice,
2890
306k
                  sps->sps_log2_diff_min_qt_min_cb_inter_slice);
2891
306k
            min_qt_log2_size_inter_y =
2892
306k
                current->ph_log2_diff_min_qt_min_cb_inter_slice +
2893
306k
                min_cb_log2_size_y;
2894
306k
            infer(ph_max_mtt_hierarchy_depth_inter_slice,
2895
306k
                  sps->sps_max_mtt_hierarchy_depth_inter_slice);
2896
306k
            infer(ph_log2_diff_max_bt_min_qt_inter_slice,
2897
306k
                  sps->sps_log2_diff_max_bt_min_qt_inter_slice);
2898
306k
            infer(ph_log2_diff_max_tt_min_qt_inter_slice,
2899
306k
                  sps->sps_log2_diff_max_tt_min_qt_inter_slice);
2900
306k
        }
2901
2902
582k
        if (pps->pps_cu_qp_delta_enabled_flag)
2903
582k
            ue(ph_cu_qp_delta_subdiv_inter_slice, 0,
2904
246k
               2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2905
246k
                    current->ph_max_mtt_hierarchy_depth_inter_slice));
2906
246k
        else
2907
246k
            infer(ph_cu_qp_delta_subdiv_inter_slice, 0);
2908
2909
568k
        if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2910
568k
            ue(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0,
2911
408k
               2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2912
408k
                    current->ph_max_mtt_hierarchy_depth_inter_slice));
2913
408k
        else
2914
408k
            infer(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0);
2915
561k
        if (sps->sps_temporal_mvp_enabled_flag) {
2916
440k
            flag(ph_temporal_mvp_enabled_flag);
2917
439k
            if (current->ph_temporal_mvp_enabled_flag &&
2918
311k
                pps->pps_rpl_info_in_ph_flag) {
2919
185k
                if (current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0)
2920
185k
                    flag(ph_collocated_from_l0_flag);
2921
110k
                else
2922
110k
                    infer(ph_collocated_from_l0_flag, 1);
2923
185k
                if ((current->ph_collocated_from_l0_flag &&
2924
154k
                     current->ph_ref_pic_lists.rpl_ref_list[0].num_ref_entries > 1)
2925
91.8k
                     || (!current->ph_collocated_from_l0_flag &&
2926
99.4k
                         current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 1)) {
2927
99.4k
                    unsigned int idx =
2928
99.4k
                        current->ph_collocated_from_l0_flag ? 0 : 1;
2929
99.4k
                    ue(ph_collocated_ref_idx, 0,
2930
99.4k
                       current->ph_ref_pic_lists.rpl_ref_list[idx].
2931
99.4k
                       num_ref_entries - 1);
2932
99.4k
                } else {
2933
85.6k
                    infer(ph_collocated_ref_idx, 0);
2934
85.6k
                }
2935
185k
            }
2936
439k
        }
2937
557k
        if (sps->sps_mmvd_fullpel_only_enabled_flag)
2938
557k
            flag(ph_mmvd_fullpel_only_flag);
2939
200k
        else
2940
200k
            infer(ph_mmvd_fullpel_only_flag, 0);
2941
556k
        if (!pps->pps_rpl_info_in_ph_flag ||
2942
373k
            current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0) {
2943
373k
            flag(ph_mvd_l1_zero_flag);
2944
373k
            if (sps->sps_bdof_control_present_in_ph_flag) {
2945
114k
                flag(ph_bdof_disabled_flag);
2946
258k
            } else {
2947
258k
                if (!sps->sps_bdof_control_present_in_ph_flag)
2948
258k
                    infer(ph_bdof_disabled_flag,
2949
258k
                          1 - sps->sps_bdof_enabled_flag);
2950
0
                else
2951
0
                    infer(ph_bdof_disabled_flag, 1);
2952
258k
            }
2953
372k
            if (sps->sps_dmvr_control_present_in_ph_flag) {
2954
204k
                flag(ph_dmvr_disabled_flag);
2955
204k
            } else {
2956
168k
                if (!sps->sps_dmvr_control_present_in_ph_flag)
2957
168k
                    infer(ph_dmvr_disabled_flag,
2958
168k
                          1 - sps->sps_dmvr_enabled_flag);
2959
0
                else
2960
0
                    infer(ph_dmvr_disabled_flag, 1);
2961
168k
            }
2962
372k
        } else {
2963
182k
            infer(ph_mvd_l1_zero_flag, 1);
2964
182k
        }
2965
554k
        if (sps->sps_prof_control_present_in_ph_flag)
2966
554k
            flag(ph_prof_disabled_flag);
2967
472k
        else
2968
472k
            infer(ph_prof_disabled_flag, !sps->sps_affine_prof_enabled_flag);
2969
553k
        if ((pps->pps_weighted_pred_flag ||
2970
463k
             pps->pps_weighted_bipred_flag) && pps->pps_wp_info_in_ph_flag) {
2971
2972
            // if pps->pps_wp_info_in_ph_fla == 1
2973
            // pred_weight_table will not use num_ref_idx_active
2974
238k
            uint8_t num_ref_idx_active[2] = { 0, 0 };
2975
238k
            CHECK(FUNC(pred_weight_table)
2976
238k
                  (ctx, rw, sps, pps, &current->ph_ref_pic_lists,
2977
238k
                   num_ref_idx_active, &current->ph_pred_weight_table));
2978
238k
        }
2979
553k
    }
2980
2981
5.92M
    qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2982
5.92M
    if (pps->pps_qp_delta_info_in_ph_flag)
2983
5.92M
        se(ph_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
2984
5.91M
           63 - (26 + pps->pps_init_qp_minus26));
2985
2986
5.91M
    if (sps->sps_joint_cbcr_enabled_flag)
2987
5.91M
        flag(ph_joint_cbcr_sign_flag);
2988
368k
    else
2989
368k
        infer(ph_joint_cbcr_sign_flag, 0);
2990
5.90M
    if (sps->sps_sao_enabled_flag && pps->pps_sao_info_in_ph_flag) {
2991
301k
        flag(ph_sao_luma_enabled_flag);
2992
300k
        if (sps->sps_chroma_format_idc != 0)
2993
300k
            flag(ph_sao_chroma_enabled_flag);
2994
6.13k
        else
2995
6.13k
            infer(ph_sao_chroma_enabled_flag, 0);
2996
5.60M
    } else {
2997
5.60M
        infer(ph_sao_luma_enabled_flag, 0);
2998
5.60M
        infer(ph_sao_chroma_enabled_flag, 0);
2999
5.60M
    }
3000
3001
5.90M
    if (pps->pps_dbf_info_in_ph_flag)
3002
5.90M
        flag(ph_deblocking_params_present_flag);
3003
5.34M
    else
3004
5.34M
        infer(ph_deblocking_params_present_flag, 0);
3005
3006
5.90M
    if (current->ph_deblocking_params_present_flag) {
3007
417k
        if (!pps->pps_deblocking_filter_disabled_flag) {
3008
27.6k
            flag(ph_deblocking_filter_disabled_flag);
3009
27.2k
            if (!current->ph_deblocking_filter_disabled_flag) {
3010
11.1k
                se(ph_luma_beta_offset_div2, -12, 12);
3011
10.1k
                se(ph_luma_tc_offset_div2, -12, 12);
3012
8.96k
                if (pps->pps_chroma_tool_offsets_present_flag) {
3013
7.68k
                    se(ph_cb_beta_offset_div2, -12, 12);
3014
7.38k
                    se(ph_cb_tc_offset_div2, -12, 12);
3015
6.96k
                    se(ph_cr_beta_offset_div2, -12, 12);
3016
6.45k
                    se(ph_cr_tc_offset_div2, -12, 12);
3017
6.45k
                } else {
3018
1.28k
                    infer(ph_cb_beta_offset_div2,
3019
1.28k
                          current->ph_luma_beta_offset_div2);
3020
1.28k
                    infer(ph_cb_tc_offset_div2,
3021
1.28k
                          current->ph_luma_tc_offset_div2);
3022
1.28k
                    infer(ph_cr_beta_offset_div2,
3023
1.28k
                          current->ph_luma_beta_offset_div2);
3024
1.28k
                    infer(ph_cr_tc_offset_div2,
3025
1.28k
                          current->ph_luma_tc_offset_div2);
3026
1.28k
                }
3027
8.96k
            }
3028
389k
        } else {
3029
389k
            infer(ph_deblocking_filter_disabled_flag, 0);
3030
389k
        }
3031
5.49M
    } else {
3032
5.49M
        infer(ph_deblocking_filter_disabled_flag, pps->pps_deblocking_filter_disabled_flag);
3033
5.49M
        if (!current->ph_deblocking_filter_disabled_flag) {
3034
2.88M
            infer(ph_luma_beta_offset_div2, pps->pps_luma_beta_offset_div2);
3035
2.88M
            infer(ph_luma_tc_offset_div2, pps->pps_luma_tc_offset_div2);
3036
2.88M
            infer(ph_cb_beta_offset_div2, pps->pps_cb_beta_offset_div2);
3037
2.88M
            infer(ph_cb_tc_offset_div2, pps->pps_cb_tc_offset_div2);
3038
2.88M
            infer(ph_cr_beta_offset_div2, pps->pps_cr_beta_offset_div2);
3039
2.88M
            infer(ph_cr_tc_offset_div2, pps->pps_cr_tc_offset_div2);
3040
2.88M
        }
3041
5.49M
    }
3042
3043
5.90M
    if (pps->pps_picture_header_extension_present_flag) {
3044
3.06M
        ue(ph_extension_length, 0, 256);
3045
6.39M
        for (i = 0; i < current->ph_extension_length; i++)
3046
3.45M
            us(8, ph_extension_data_byte[i], 0x00, 0xff, 1, i);
3047
3.03M
    }
3048
3049
5.78M
    return 0;
3050
5.90M
}
cbs_h266.c:cbs_h266_write_picture_header
Line
Count
Source
2648
33.0k
                                 H266RawPictureHeader *current) {
2649
33.0k
    CodedBitstreamH266Context *h266 = ctx->priv_data;
2650
33.0k
    const H266RawVPS *vps;
2651
33.0k
    const H266RawSPS *sps;
2652
33.0k
    const H266RawPPS *pps;
2653
33.0k
    int err, i;
2654
33.0k
    unsigned int ctb_log2_size_y, min_cb_log2_size_y,
2655
33.0k
        min_qt_log2_size_intra_y, min_qt_log2_size_inter_y;
2656
33.0k
    uint8_t qp_bd_offset;
2657
2658
33.0k
    flag(ph_gdr_or_irap_pic_flag);
2659
33.0k
    flag(ph_non_ref_pic_flag);
2660
33.0k
    if (current->ph_gdr_or_irap_pic_flag)
2661
33.0k
        flag(ph_gdr_pic_flag);
2662
17.3k
    else
2663
17.3k
        infer(ph_gdr_pic_flag, 0);
2664
33.0k
    flag(ph_inter_slice_allowed_flag);
2665
33.0k
    if (current->ph_inter_slice_allowed_flag)
2666
33.0k
        flag(ph_intra_slice_allowed_flag);
2667
5.59k
    else
2668
5.59k
        infer(ph_intra_slice_allowed_flag, 1);
2669
33.0k
    ue(ph_pic_parameter_set_id, 0, VVC_MAX_PPS_COUNT - 1);
2670
33.0k
    pps = h266->pps[current->ph_pic_parameter_set_id];
2671
33.0k
    if (!pps) {
2672
843
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
2673
843
               current->ph_pic_parameter_set_id);
2674
843
        return AVERROR_INVALIDDATA;
2675
843
    }
2676
32.2k
    sps = h266->sps[pps->pps_seq_parameter_set_id];
2677
32.2k
    if (!sps) {
2678
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
2679
0
               pps->pps_seq_parameter_set_id);
2680
0
        return AVERROR_INVALIDDATA;
2681
0
    }
2682
32.2k
    vps = h266->vps[sps->sps_video_parameter_set_id];
2683
32.2k
    if (!vps) {
2684
199
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n",
2685
199
               sps->sps_video_parameter_set_id);
2686
199
        return AVERROR_INVALIDDATA;
2687
199
    }
2688
2689
32.0k
    ub(sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4, ph_pic_order_cnt_lsb);
2690
31.8k
    if (current->ph_gdr_pic_flag)
2691
31.8k
        ue(ph_recovery_poc_cnt, 0,
2692
31.8k
           1 << (sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4));
2693
2694
53.4k
    for (i = 0; i < sps->sps_num_extra_ph_bytes * 8; i++) {
2695
21.6k
        if (sps->sps_extra_ph_bit_present_flag[i])
2696
21.6k
            flags(ph_extra_bit[i], 1, i);
2697
21.6k
    }
2698
31.8k
    if (sps->sps_poc_msb_cycle_flag) {
2699
2.58k
        flag(ph_poc_msb_cycle_present_flag);
2700
2.58k
        if (current->ph_poc_msb_cycle_present_flag)
2701
911
            ub(sps->sps_poc_msb_cycle_len_minus1 + 1, ph_poc_msb_cycle_val);
2702
2.58k
    }
2703
31.6k
    if (sps->sps_alf_enabled_flag && pps->pps_alf_info_in_ph_flag) {
2704
9.40k
        flag(ph_alf_enabled_flag);
2705
9.40k
        if (current->ph_alf_enabled_flag) {
2706
2707
6.55k
            ub(3, ph_num_alf_aps_ids_luma);
2708
17.3k
            for (i = 0; i < current->ph_num_alf_aps_ids_luma; i++)
2709
10.7k
                ubs(3, ph_alf_aps_id_luma[i], 1, i);
2710
2711
6.55k
            if (sps->sps_chroma_format_idc != 0) {
2712
5.77k
                flag(ph_alf_cb_enabled_flag);
2713
5.77k
                flag(ph_alf_cr_enabled_flag);
2714
5.77k
            } else {
2715
780
                infer(ph_alf_cb_enabled_flag, 0);
2716
586
                infer(ph_alf_cr_enabled_flag, 0);
2717
586
            }
2718
2719
6.16k
            if (current->ph_alf_cb_enabled_flag
2720
4.86k
                || current->ph_alf_cr_enabled_flag) {
2721
4.86k
                ub(3, ph_alf_aps_id_chroma);
2722
4.86k
            }
2723
2724
6.16k
            if (sps->sps_ccalf_enabled_flag) {
2725
5.05k
                flag(ph_alf_cc_cb_enabled_flag);
2726
5.05k
                if (current->ph_alf_cc_cb_enabled_flag)
2727
3.45k
                    ub(3, ph_alf_cc_cb_aps_id);
2728
5.05k
                flag(ph_alf_cc_cr_enabled_flag);
2729
5.05k
                if (current->ph_alf_cc_cr_enabled_flag)
2730
1.02k
                    ub(3, ph_alf_cc_cr_aps_id);
2731
5.05k
            }
2732
6.16k
        }
2733
22.2k
    } else {
2734
22.2k
        infer(ph_alf_enabled_flag, 0);
2735
22.2k
    }
2736
31.0k
    if (sps->sps_lmcs_enabled_flag) {
2737
20.9k
        flag(ph_lmcs_enabled_flag);
2738
20.9k
        if (current->ph_lmcs_enabled_flag) {
2739
11.4k
            ub(2, ph_lmcs_aps_id);
2740
11.4k
            if (sps->sps_chroma_format_idc != 0)
2741
11.4k
                flag(ph_chroma_residual_scale_flag);
2742
1.23k
            else
2743
1.23k
                infer(ph_chroma_residual_scale_flag, 0);
2744
11.4k
        }
2745
20.9k
    } else {
2746
10.0k
        infer(ph_lmcs_enabled_flag, 0);
2747
9.80k
        infer(ph_chroma_residual_scale_flag, 0);
2748
9.80k
    }
2749
2750
30.6k
    if (sps->sps_explicit_scaling_list_enabled_flag) {
2751
10.3k
        flag(ph_explicit_scaling_list_enabled_flag);
2752
10.3k
        if (current->ph_explicit_scaling_list_enabled_flag) {
2753
            //todo: check the ph_scaling_list_aps_id range, when aps ready
2754
4.78k
            ub(3, ph_scaling_list_aps_id);
2755
4.78k
        }
2756
20.2k
    } else {
2757
20.2k
        infer(ph_explicit_scaling_list_enabled_flag, 0);
2758
20.2k
    }
2759
30.3k
    if (sps->sps_virtual_boundaries_enabled_flag &&
2760
9.95k
        !sps->sps_virtual_boundaries_present_flag) {
2761
3.73k
        flag(ph_virtual_boundaries_present_flag);
2762
3.73k
        if (current->ph_virtual_boundaries_present_flag) {
2763
2.06k
            ue(ph_num_ver_virtual_boundaries,
2764
2.06k
               0, pps->pps_pic_width_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
2765
3.90k
            for (i = 0; i < current->ph_num_ver_virtual_boundaries; i++) {
2766
1.84k
                ues(ph_virtual_boundary_pos_x_minus1[i],
2767
1.84k
                    0, (pps->pps_pic_width_in_luma_samples + 7) / 8 - 2, 1, i);
2768
1.84k
            }
2769
2.06k
            ue(ph_num_hor_virtual_boundaries,
2770
2.06k
               0, pps->pps_pic_height_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
2771
4.06k
            for (i = 0; i < current->ph_num_hor_virtual_boundaries; i++) {
2772
2.19k
                ues(ph_virtual_boundary_pos_y_minus1[i],
2773
2.19k
                    0, (pps->pps_pic_height_in_luma_samples + 7) / 8 - 2, 1, i);
2774
2.19k
            }
2775
2.06k
        } else {
2776
1.67k
            infer(ph_num_ver_virtual_boundaries, 0);
2777
1.67k
            infer(ph_num_hor_virtual_boundaries, 0);
2778
1.67k
        }
2779
3.73k
    }
2780
30.1k
    if (pps->pps_output_flag_present_flag && !current->ph_non_ref_pic_flag)
2781
30.1k
        flag(ph_pic_output_flag);
2782
27.9k
    else
2783
27.9k
        infer(ph_pic_output_flag, 1);
2784
29.9k
    if (pps->pps_rpl_info_in_ph_flag) {
2785
7.77k
        CHECK(FUNC(ref_pic_lists)
2786
7.77k
              (ctx, rw, sps, pps, &current->ph_ref_pic_lists));
2787
7.77k
    }
2788
29.4k
    if (sps->sps_partition_constraints_override_enabled_flag)
2789
29.4k
        flag(ph_partition_constraints_override_flag);
2790
4.10k
    else
2791
4.10k
        infer(ph_partition_constraints_override_flag, 0);
2792
2793
29.3k
    ctb_log2_size_y = sps->sps_log2_ctu_size_minus5 + 5;
2794
29.3k
    min_cb_log2_size_y = sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
2795
29.3k
    if (current->ph_intra_slice_allowed_flag) {
2796
15.6k
        if (current->ph_partition_constraints_override_flag) {
2797
7.35k
            ue(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2798
7.14k
               0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2799
7.14k
            ue(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2800
6.95k
               0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2801
6.95k
            if (current->ph_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
2802
1.08k
                min_qt_log2_size_intra_y =
2803
1.08k
                    current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2804
1.08k
                    min_cb_log2_size_y;
2805
1.08k
                ue(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2806
895
                   0, (sps->sps_qtbtt_dual_tree_intra_flag ?
2807
895
                       FFMIN(6, ctb_log2_size_y) :
2808
895
                       ctb_log2_size_y) - min_qt_log2_size_intra_y);
2809
895
                ue(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2810
895
                   0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
2811
5.86k
            } else {
2812
5.86k
                infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2813
5.86k
                      sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2814
5.66k
                infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2815
5.66k
                      sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2816
5.66k
            }
2817
6.17k
            if (sps->sps_qtbtt_dual_tree_intra_flag) {
2818
4.72k
                ue(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2819
4.53k
                   0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2820
4.53k
                ue(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2821
4.31k
                   0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2822
4.31k
                if (sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
2823
3.62k
                    unsigned int min_qt_log2_size_intra_c =
2824
3.62k
                        current->ph_log2_diff_min_qt_min_cb_intra_slice_chroma +
2825
3.62k
                        min_cb_log2_size_y;
2826
3.62k
                    ue(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2827
3.42k
                       0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2828
3.42k
                    ue(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2829
3.42k
                       0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2830
3.42k
                } else {
2831
688
                    infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2832
688
                          sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2833
492
                    infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2834
492
                          sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2835
492
                }
2836
4.31k
            }
2837
8.25k
        } else {
2838
8.25k
            infer(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2839
8.25k
                  sps->sps_log2_diff_min_qt_min_cb_intra_slice_luma);
2840
8.05k
            infer(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2841
8.05k
                  sps->sps_max_mtt_hierarchy_depth_intra_slice_luma);
2842
7.84k
            infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2843
7.84k
                  sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2844
7.65k
            infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2845
7.65k
                  sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2846
7.45k
            infer(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2847
7.45k
                  sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma);
2848
6.09k
            infer(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2849
6.09k
                  sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma);
2850
5.89k
            infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2851
5.89k
                  sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2852
5.67k
            infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2853
5.67k
                  sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2854
5.67k
        }
2855
2856
10.3k
        min_qt_log2_size_intra_y =
2857
10.3k
            current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2858
10.3k
            min_cb_log2_size_y;
2859
10.3k
        if (pps->pps_cu_qp_delta_enabled_flag)
2860
10.3k
            ue(ph_cu_qp_delta_subdiv_intra_slice, 0,
2861
7.13k
               2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2862
7.13k
                    current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2863
7.13k
        else
2864
7.13k
            infer(ph_cu_qp_delta_subdiv_intra_slice, 0);
2865
2866
10.1k
        if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2867
10.1k
            ue(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0,
2868
8.32k
               2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2869
8.32k
                    current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2870
8.32k
        else
2871
8.32k
            infer(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0);
2872
10.1k
    }
2873
23.6k
    if (current->ph_inter_slice_allowed_flag) {
2874
19.6k
        if (current->ph_partition_constraints_override_flag) {
2875
9.80k
            ue(ph_log2_diff_min_qt_min_cb_inter_slice,
2876
9.61k
               0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2877
9.61k
            min_qt_log2_size_inter_y =
2878
9.61k
                current->ph_log2_diff_min_qt_min_cb_inter_slice +
2879
9.61k
                min_cb_log2_size_y;
2880
9.61k
            ue(ph_max_mtt_hierarchy_depth_inter_slice, 0,
2881
9.41k
               2 * (ctb_log2_size_y - min_cb_log2_size_y));
2882
9.41k
            if (current->ph_max_mtt_hierarchy_depth_inter_slice != 0) {
2883
2.85k
                ue(ph_log2_diff_max_bt_min_qt_inter_slice,
2884
2.66k
                   0, ctb_log2_size_y - min_qt_log2_size_inter_y);
2885
2.66k
                ue(ph_log2_diff_max_tt_min_qt_inter_slice,
2886
2.66k
                   0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
2887
2.66k
            }
2888
9.86k
        } else {
2889
9.86k
            infer(ph_log2_diff_min_qt_min_cb_inter_slice,
2890
9.86k
                  sps->sps_log2_diff_min_qt_min_cb_inter_slice);
2891
9.56k
            min_qt_log2_size_inter_y =
2892
9.56k
                current->ph_log2_diff_min_qt_min_cb_inter_slice +
2893
9.56k
                min_cb_log2_size_y;
2894
9.56k
            infer(ph_max_mtt_hierarchy_depth_inter_slice,
2895
9.56k
                  sps->sps_max_mtt_hierarchy_depth_inter_slice);
2896
9.36k
            infer(ph_log2_diff_max_bt_min_qt_inter_slice,
2897
9.36k
                  sps->sps_log2_diff_max_bt_min_qt_inter_slice);
2898
9.13k
            infer(ph_log2_diff_max_tt_min_qt_inter_slice,
2899
9.13k
                  sps->sps_log2_diff_max_tt_min_qt_inter_slice);
2900
9.13k
        }
2901
2902
17.8k
        if (pps->pps_cu_qp_delta_enabled_flag)
2903
17.8k
            ue(ph_cu_qp_delta_subdiv_inter_slice, 0,
2904
11.6k
               2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2905
11.6k
                    current->ph_max_mtt_hierarchy_depth_inter_slice));
2906
11.6k
        else
2907
11.6k
            infer(ph_cu_qp_delta_subdiv_inter_slice, 0);
2908
2909
17.6k
        if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2910
17.6k
            ue(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0,
2911
15.9k
               2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2912
15.9k
                    current->ph_max_mtt_hierarchy_depth_inter_slice));
2913
15.9k
        else
2914
15.9k
            infer(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0);
2915
17.4k
        if (sps->sps_temporal_mvp_enabled_flag) {
2916
13.7k
            flag(ph_temporal_mvp_enabled_flag);
2917
13.7k
            if (current->ph_temporal_mvp_enabled_flag &&
2918
7.73k
                pps->pps_rpl_info_in_ph_flag) {
2919
2.55k
                if (current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0)
2920
2.55k
                    flag(ph_collocated_from_l0_flag);
2921
748
                else
2922
748
                    infer(ph_collocated_from_l0_flag, 1);
2923
2.25k
                if ((current->ph_collocated_from_l0_flag &&
2924
1.48k
                     current->ph_ref_pic_lists.rpl_ref_list[0].num_ref_entries > 1)
2925
1.22k
                     || (!current->ph_collocated_from_l0_flag &&
2926
1.53k
                         current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 1)) {
2927
1.53k
                    unsigned int idx =
2928
1.53k
                        current->ph_collocated_from_l0_flag ? 0 : 1;
2929
1.53k
                    ue(ph_collocated_ref_idx, 0,
2930
1.53k
                       current->ph_ref_pic_lists.rpl_ref_list[idx].
2931
1.53k
                       num_ref_entries - 1);
2932
1.53k
                } else {
2933
718
                    infer(ph_collocated_ref_idx, 0);
2934
718
                }
2935
2.25k
            }
2936
13.7k
        }
2937
17.1k
        if (sps->sps_mmvd_fullpel_only_enabled_flag)
2938
17.1k
            flag(ph_mmvd_fullpel_only_flag);
2939
7.36k
        else
2940
7.36k
            infer(ph_mmvd_fullpel_only_flag, 0);
2941
16.9k
        if (!pps->pps_rpl_info_in_ph_flag ||
2942
14.9k
            current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0) {
2943
14.9k
            flag(ph_mvd_l1_zero_flag);
2944
14.9k
            if (sps->sps_bdof_control_present_in_ph_flag) {
2945
8.06k
                flag(ph_bdof_disabled_flag);
2946
8.06k
            } else {
2947
6.87k
                if (!sps->sps_bdof_control_present_in_ph_flag)
2948
6.87k
                    infer(ph_bdof_disabled_flag,
2949
6.87k
                          1 - sps->sps_bdof_enabled_flag);
2950
0
                else
2951
0
                    infer(ph_bdof_disabled_flag, 1);
2952
6.87k
            }
2953
14.6k
            if (sps->sps_dmvr_control_present_in_ph_flag) {
2954
8.99k
                flag(ph_dmvr_disabled_flag);
2955
8.99k
            } else {
2956
5.64k
                if (!sps->sps_dmvr_control_present_in_ph_flag)
2957
5.64k
                    infer(ph_dmvr_disabled_flag,
2958
5.64k
                          1 - sps->sps_dmvr_enabled_flag);
2959
0
                else
2960
0
                    infer(ph_dmvr_disabled_flag, 1);
2961
5.64k
            }
2962
14.6k
        } else {
2963
2.02k
            infer(ph_mvd_l1_zero_flag, 1);
2964
2.02k
        }
2965
16.2k
        if (sps->sps_prof_control_present_in_ph_flag)
2966
16.2k
            flag(ph_prof_disabled_flag);
2967
8.23k
        else
2968
8.23k
            infer(ph_prof_disabled_flag, !sps->sps_affine_prof_enabled_flag);
2969
16.0k
        if ((pps->pps_weighted_pred_flag ||
2970
11.2k
             pps->pps_weighted_bipred_flag) && pps->pps_wp_info_in_ph_flag) {
2971
2972
            // if pps->pps_wp_info_in_ph_fla == 1
2973
            // pred_weight_table will not use num_ref_idx_active
2974
1.38k
            uint8_t num_ref_idx_active[2] = { 0, 0 };
2975
1.38k
            CHECK(FUNC(pred_weight_table)
2976
1.38k
                  (ctx, rw, sps, pps, &current->ph_ref_pic_lists,
2977
1.38k
                   num_ref_idx_active, &current->ph_pred_weight_table));
2978
1.38k
        }
2979
16.0k
    }
2980
2981
19.6k
    qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2982
19.6k
    if (pps->pps_qp_delta_info_in_ph_flag)
2983
19.6k
        se(ph_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
2984
19.4k
           63 - (26 + pps->pps_init_qp_minus26));
2985
2986
19.4k
    if (sps->sps_joint_cbcr_enabled_flag)
2987
19.4k
        flag(ph_joint_cbcr_sign_flag);
2988
8.16k
    else
2989
8.16k
        infer(ph_joint_cbcr_sign_flag, 0);
2990
19.2k
    if (sps->sps_sao_enabled_flag && pps->pps_sao_info_in_ph_flag) {
2991
4.18k
        flag(ph_sao_luma_enabled_flag);
2992
4.18k
        if (sps->sps_chroma_format_idc != 0)
2993
4.18k
            flag(ph_sao_chroma_enabled_flag);
2994
721
        else
2995
721
            infer(ph_sao_chroma_enabled_flag, 0);
2996
15.0k
    } else {
2997
15.0k
        infer(ph_sao_luma_enabled_flag, 0);
2998
14.8k
        infer(ph_sao_chroma_enabled_flag, 0);
2999
14.8k
    }
3000
3001
18.6k
    if (pps->pps_dbf_info_in_ph_flag)
3002
18.6k
        flag(ph_deblocking_params_present_flag);
3003
13.8k
    else
3004
13.8k
        infer(ph_deblocking_params_present_flag, 0);
3005
3006
18.4k
    if (current->ph_deblocking_params_present_flag) {
3007
3.48k
        if (!pps->pps_deblocking_filter_disabled_flag) {
3008
2.67k
            flag(ph_deblocking_filter_disabled_flag);
3009
2.67k
            if (!current->ph_deblocking_filter_disabled_flag) {
3010
2.38k
                se(ph_luma_beta_offset_div2, -12, 12);
3011
2.38k
                se(ph_luma_tc_offset_div2, -12, 12);
3012
2.38k
                if (pps->pps_chroma_tool_offsets_present_flag) {
3013
504
                    se(ph_cb_beta_offset_div2, -12, 12);
3014
504
                    se(ph_cb_tc_offset_div2, -12, 12);
3015
504
                    se(ph_cr_beta_offset_div2, -12, 12);
3016
504
                    se(ph_cr_tc_offset_div2, -12, 12);
3017
1.87k
                } else {
3018
1.87k
                    infer(ph_cb_beta_offset_div2,
3019
1.87k
                          current->ph_luma_beta_offset_div2);
3020
792
                    infer(ph_cb_tc_offset_div2,
3021
792
                          current->ph_luma_tc_offset_div2);
3022
525
                    infer(ph_cr_beta_offset_div2,
3023
525
                          current->ph_luma_beta_offset_div2);
3024
303
                    infer(ph_cr_tc_offset_div2,
3025
303
                          current->ph_luma_tc_offset_div2);
3026
303
                }
3027
2.38k
            }
3028
2.67k
        } else {
3029
818
            infer(ph_deblocking_filter_disabled_flag, 0);
3030
818
        }
3031
14.9k
    } else {
3032
14.9k
        infer(ph_deblocking_filter_disabled_flag, pps->pps_deblocking_filter_disabled_flag);
3033
14.7k
        if (!current->ph_deblocking_filter_disabled_flag) {
3034
13.3k
            infer(ph_luma_beta_offset_div2, pps->pps_luma_beta_offset_div2);
3035
13.1k
            infer(ph_luma_tc_offset_div2, pps->pps_luma_tc_offset_div2);
3036
12.9k
            infer(ph_cb_beta_offset_div2, pps->pps_cb_beta_offset_div2);
3037
12.7k
            infer(ph_cb_tc_offset_div2, pps->pps_cb_tc_offset_div2);
3038
12.5k
            infer(ph_cr_beta_offset_div2, pps->pps_cr_beta_offset_div2);
3039
12.3k
            infer(ph_cr_tc_offset_div2, pps->pps_cr_tc_offset_div2);
3040
12.3k
        }
3041
14.7k
    }
3042
3043
15.1k
    if (pps->pps_picture_header_extension_present_flag) {
3044
6.00k
        ue(ph_extension_length, 0, 256);
3045
15.0k
        for (i = 0; i < current->ph_extension_length; i++)
3046
9.07k
            us(8, ph_extension_data_byte[i], 0x00, 0xff, 1, i);
3047
6.00k
    }
3048
3049
15.1k
    return 0;
3050
15.1k
}
3051
3052
static int FUNC(ph) (CodedBitstreamContext *ctx, RWContext *rw,
3053
                     H266RawPH *current)
3054
106k
{
3055
106k
    int err;
3056
3057
106k
    HEADER("Picture Header");
3058
3059
106k
    CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, VVC_PH_NUT));
3060
103k
    CHECK(FUNC(picture_header) (ctx, rw, &current->ph_picture_header));
3061
33.2k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
3062
19.7k
    return 0;
3063
33.2k
}
cbs_h266.c:cbs_h266_read_ph
Line
Count
Source
3054
97.2k
{
3055
97.2k
    int err;
3056
3057
97.2k
    HEADER("Picture Header");
3058
3059
97.2k
    CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, VVC_PH_NUT));
3060
94.7k
    CHECK(FUNC(picture_header) (ctx, rw, &current->ph_picture_header));
3061
30.3k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
3062
16.8k
    return 0;
3063
30.3k
}
cbs_h266.c:cbs_h266_write_ph
Line
Count
Source
3054
9.12k
{
3055
9.12k
    int err;
3056
3057
9.12k
    HEADER("Picture Header");
3058
3059
9.12k
    CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, VVC_PH_NUT));
3060
9.12k
    CHECK(FUNC(picture_header) (ctx, rw, &current->ph_picture_header));
3061
2.88k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
3062
2.88k
    return 0;
3063
2.88k
}
3064
3065
static int FUNC(slice_header) (CodedBitstreamContext *ctx, RWContext *rw,
3066
                               H266RawSliceHeader *current)
3067
7.74M
{
3068
7.74M
    CodedBitstreamH266Context *h266 = ctx->priv_data;
3069
7.74M
    const H266RawSPS *sps;
3070
7.74M
    const H266RawPPS *pps;
3071
7.74M
    const H266RawPictureHeader *ph;
3072
7.74M
    const H266RefPicLists *ref_pic_lists;
3073
7.74M
    int err, i;
3074
7.74M
    uint8_t nal_unit_type, qp_bd_offset;
3075
7.74M
    uint16_t num_slices_in_subpic;
3076
3077
7.74M
    HEADER("Slice Header");
3078
3079
7.74M
    CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, -1));
3080
3081
7.73M
    flag(sh_picture_header_in_slice_header_flag);
3082
7.71M
    if (current->sh_picture_header_in_slice_header_flag) {
3083
        // 7.4.8 if sh_picture_header_in_slice_header_flag is true, we do not have a PH NAL unit
3084
7.03M
        CHECK(FUNC(picture_header) (ctx, rw, &current->sh_picture_header));
3085
5.76M
        ph = &current->sh_picture_header;
3086
5.76M
    } else {
3087
681k
        ph = h266->ph;
3088
681k
        if (!ph) {
3089
241k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
3090
241k
                   "Picture header not available.\n");
3091
241k
            return AVERROR_INVALIDDATA;
3092
241k
        }
3093
681k
    }
3094
3095
6.20M
    pps = h266->pps[ph->ph_pic_parameter_set_id];
3096
6.20M
    if (!pps) {
3097
13.1k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
3098
13.1k
               ph->ph_pic_parameter_set_id);
3099
13.1k
        return AVERROR_INVALIDDATA;
3100
13.1k
    }
3101
6.19M
    sps = h266->sps[pps->pps_seq_parameter_set_id];
3102
6.19M
    if (!sps) {
3103
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
3104
0
               pps->pps_seq_parameter_set_id);
3105
0
        return AVERROR_INVALIDDATA;
3106
0
    }
3107
3108
6.19M
    if (sps->sps_subpic_info_present_flag) {
3109
136k
        ub(sps->sps_subpic_id_len_minus1 + 1, sh_subpic_id);
3110
416k
        for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
3111
407k
            if (pps->sub_pic_id_val[i] == current->sh_subpic_id) {
3112
125k
                current->curr_subpic_idx = i;
3113
125k
                break;
3114
125k
            }
3115
407k
        }
3116
134k
        if (i > sps->sps_num_subpics_minus1) {
3117
9.38k
            av_log(ctx->log_ctx, AV_LOG_ERROR, "invalid CurrSubpicIdx %d\n", i);
3118
9.38k
            return AVERROR_INVALIDDATA;
3119
9.38k
        }
3120
6.05M
    } else {
3121
6.05M
        current->curr_subpic_idx = 0;
3122
6.05M
    }
3123
3124
6.17M
    num_slices_in_subpic = pps->num_slices_in_subpic[current->curr_subpic_idx];
3125
3126
6.17M
    if ((pps->pps_rect_slice_flag && num_slices_in_subpic > 1) ||
3127
6.13M
        (!pps->pps_rect_slice_flag && pps->num_tiles_in_pic > 1)) {
3128
94.0k
        unsigned int bits, max;
3129
94.0k
        if (!pps->pps_rect_slice_flag) {
3130
53.9k
            bits = av_ceil_log2(pps->num_tiles_in_pic);
3131
53.9k
            max = pps->num_tiles_in_pic - 1;
3132
53.9k
        } else {
3133
40.0k
            bits = av_ceil_log2(num_slices_in_subpic);
3134
40.0k
            max = num_slices_in_subpic - 1;
3135
40.0k
        }
3136
94.0k
        u(bits, sh_slice_address, 0, max);
3137
6.08M
    } else {
3138
6.08M
        infer(sh_slice_address, 0);
3139
6.08M
    }
3140
3141
34.2M
    for (i = 0; i < sps->sps_num_extra_sh_bytes * 8; i++) {
3142
28.0M
        if (sps->sps_extra_sh_bit_present_flag[i])
3143
28.0M
            flags(sh_extra_bit[i], 1, i);
3144
28.0M
    }
3145
3146
6.17M
    if (!pps->pps_rect_slice_flag &&
3147
5.03M
        pps->num_tiles_in_pic - current->sh_slice_address > 1)
3148
6.17M
        ue(sh_num_tiles_in_slice_minus1, 0, pps->num_tiles_in_pic - 1);
3149
6.12M
    else
3150
6.12M
        infer(sh_num_tiles_in_slice_minus1, 0);
3151
3152
6.16M
    if (ph->ph_inter_slice_allowed_flag)
3153
6.16M
        ue(sh_slice_type, 0, 2);
3154
5.51M
    else
3155
5.51M
        infer(sh_slice_type, 2);
3156
3157
6.06M
    nal_unit_type = current->nal_unit_header.nal_unit_type;
3158
6.06M
    if (nal_unit_type == VVC_IDR_W_RADL || nal_unit_type == VVC_IDR_N_LP ||
3159
5.97M
        nal_unit_type == VVC_CRA_NUT || nal_unit_type == VVC_GDR_NUT)
3160
6.06M
        flag(sh_no_output_of_prior_pics_flag);
3161
3162
6.06M
    if (sps->sps_alf_enabled_flag) {
3163
3.44M
        if (!pps->pps_alf_info_in_ph_flag) {
3164
3.13M
            flag(sh_alf_enabled_flag);
3165
3.13M
            if (current->sh_alf_enabled_flag) {
3166
305k
                ub(3, sh_num_alf_aps_ids_luma);
3167
1.55M
                for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3168
1.26M
                    ubs(3, sh_alf_aps_id_luma[i], 1, i);
3169
3170
290k
                if (sps->sps_chroma_format_idc != 0) {
3171
251k
                    flag(sh_alf_cb_enabled_flag);
3172
250k
                    flag(sh_alf_cr_enabled_flag);
3173
250k
                }
3174
288k
                if (current->sh_alf_cb_enabled_flag ||
3175
186k
                    current->sh_alf_cr_enabled_flag) {
3176
186k
                    ub(3, sh_alf_aps_id_chroma);
3177
186k
                }
3178
3179
287k
                if (sps->sps_ccalf_enabled_flag) {
3180
189k
                    flag(sh_alf_cc_cb_enabled_flag);
3181
189k
                    if (current->sh_alf_cc_cb_enabled_flag)
3182
88.4k
                        ub(3, sh_alf_cc_cb_aps_id);
3183
3184
187k
                    flag(sh_alf_cc_cr_enabled_flag);
3185
187k
                    if (current->sh_alf_cc_cr_enabled_flag)
3186
102k
                        ub(3, sh_alf_cc_cr_aps_id);
3187
187k
                }
3188
287k
            }
3189
3.13M
        } else {
3190
305k
            infer(sh_alf_enabled_flag, ph->ph_alf_enabled_flag);
3191
305k
            if (current->sh_alf_enabled_flag) {
3192
122k
                infer(sh_num_alf_aps_ids_luma, ph->ph_num_alf_aps_ids_luma);
3193
451k
                for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3194
330k
                    infer(sh_alf_aps_id_luma[i], ph->ph_alf_aps_id_luma[i]);
3195
3196
121k
                infer(sh_alf_cb_enabled_flag, ph->ph_alf_cb_enabled_flag);
3197
121k
                infer(sh_alf_cr_enabled_flag, ph->ph_alf_cr_enabled_flag);
3198
121k
                if (current->sh_alf_cb_enabled_flag ||current->sh_alf_cr_enabled_flag)
3199
97.5k
                    infer(sh_alf_aps_id_chroma, ph->ph_alf_aps_id_chroma);
3200
3201
121k
                if (sps->sps_ccalf_enabled_flag) {
3202
98.6k
                    infer(sh_alf_cc_cb_enabled_flag, ph->ph_alf_cc_cb_enabled_flag);
3203
98.4k
                    if (current->sh_alf_cc_cb_enabled_flag)
3204
47.5k
                        infer(sh_alf_cc_cb_aps_id, ph->ph_alf_cc_cb_aps_id);
3205
3206
98.2k
                    infer(sh_alf_cc_cr_enabled_flag, ph->ph_alf_cc_cr_enabled_flag);
3207
98.0k
                    if (current->sh_alf_cc_cr_enabled_flag)
3208
44.5k
                        infer(sh_alf_cc_cr_aps_id, ph->ph_alf_cc_cr_aps_id);
3209
6.36k
                }
3210
8.26k
            }
3211
11.3k
        }
3212
3.44M
    }
3213
3214
6.04M
    if (current->sh_picture_header_in_slice_header_flag) {
3215
5.69M
        infer(sh_lmcs_used_flag, ph->ph_lmcs_enabled_flag);
3216
5.69M
        infer(sh_explicit_scaling_list_used_flag,
3217
12.2k
            ph->ph_explicit_scaling_list_enabled_flag);
3218
350k
    } else {
3219
350k
        if (ph->ph_lmcs_enabled_flag)
3220
350k
            flag(sh_lmcs_used_flag);
3221
187k
        else
3222
187k
            infer(sh_lmcs_used_flag, 0);
3223
3224
349k
        if (ph->ph_explicit_scaling_list_enabled_flag)
3225
349k
            flag(sh_explicit_scaling_list_used_flag);
3226
310k
        else
3227
310k
            infer(sh_explicit_scaling_list_used_flag, 0);
3228
349k
    }
3229
3230
6.03M
    if (!pps->pps_rpl_info_in_ph_flag &&
3231
5.43M
        ((nal_unit_type != VVC_IDR_W_RADL &&
3232
5.40M
          nal_unit_type != VVC_IDR_N_LP) || sps->sps_idr_rpl_present_flag)) {
3233
5.37M
        CHECK(FUNC(ref_pic_lists)
3234
5.37M
              (ctx, rw, sps, pps, &current->sh_ref_pic_lists));
3235
5.18M
        ref_pic_lists = &current->sh_ref_pic_lists;
3236
5.18M
    } else {
3237
659k
        ref_pic_lists = &ph->ph_ref_pic_lists;
3238
659k
    }
3239
5.84M
    if ((current->sh_slice_type != VVC_SLICE_TYPE_I &&
3240
480k
         ref_pic_lists->rpl_ref_list[0].num_ref_entries > 1) ||
3241
5.64M
        (current->sh_slice_type == VVC_SLICE_TYPE_B &&
3242
252k
         ref_pic_lists->rpl_ref_list[1].num_ref_entries > 1)) {
3243
226k
        flag(sh_num_ref_idx_active_override_flag);
3244
224k
        if (current->sh_num_ref_idx_active_override_flag) {
3245
137k
            for (i = 0;
3246
394k
                 i < (current->sh_slice_type == VVC_SLICE_TYPE_B ? 2 : 1); i++)
3247
261k
                if (ref_pic_lists->rpl_ref_list[i].num_ref_entries > 1)
3248
261k
                    ues(sh_num_ref_idx_active_minus1[i], 0, 14, 1, i);
3249
109k
                else
3250
109k
                    infer(sh_num_ref_idx_active_minus1[i], 0);
3251
137k
        }
3252
5.62M
    } else {
3253
5.62M
        infer(sh_num_ref_idx_active_override_flag, 1);
3254
5.62M
    }
3255
3256
17.4M
    for (i = 0; i < 2; i++) {
3257
11.6M
        if (current->sh_slice_type == VVC_SLICE_TYPE_B ||
3258
10.8M
            (current->sh_slice_type == VVC_SLICE_TYPE_P && i == 0)) {
3259
886k
            if (current->sh_num_ref_idx_active_override_flag) {
3260
740k
                current->num_ref_idx_active[i] = current->sh_num_ref_idx_active_minus1[i] + 1;
3261
740k
            } else {
3262
146k
                current->num_ref_idx_active[i] =
3263
146k
                    FFMIN(ref_pic_lists->rpl_ref_list[i].num_ref_entries,
3264
146k
                        pps->pps_num_ref_idx_default_active_minus1[i] + 1);
3265
146k
            }
3266
3267
886k
            if (current->num_ref_idx_active[i] <= 0) {
3268
16.6k
                av_log(ctx->log_ctx, AV_LOG_ERROR,
3269
16.6k
                       "Inter slice but no reference pictures available for RPL%d.\n", i);
3270
16.6k
                return AVERROR_INVALIDDATA;
3271
16.6k
            }
3272
10.7M
        } else {
3273
10.7M
            current->num_ref_idx_active[i] = 0;
3274
10.7M
        }
3275
11.6M
    }
3276
3277
5.82M
    if (current->sh_slice_type != VVC_SLICE_TYPE_I) {
3278
457k
        if (pps->pps_cabac_init_present_flag)
3279
457k
            flag(sh_cabac_init_flag);
3280
16.3k
        else
3281
16.3k
            infer(sh_cabac_init_flag, 0);
3282
456k
        if (ph->ph_temporal_mvp_enabled_flag) {
3283
306k
            if (!pps->pps_rpl_info_in_ph_flag) {
3284
111k
                if (current->sh_slice_type == VVC_SLICE_TYPE_B)
3285
111k
                    flag(sh_collocated_from_l0_flag);
3286
14.0k
                else
3287
14.0k
                    infer(sh_collocated_from_l0_flag, 1);
3288
110k
                if ((current->sh_collocated_from_l0_flag &&
3289
75.1k
                    current->num_ref_idx_active[0] > 1) ||
3290
97.2k
                    (!current->sh_collocated_from_l0_flag &&
3291
35.6k
                    current->num_ref_idx_active[1] > 1)) {
3292
27.1k
                    unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1;
3293
27.1k
                    ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] - 1);
3294
83.6k
                } else {
3295
83.6k
                    infer(sh_collocated_ref_idx, 0);
3296
83.6k
                }
3297
194k
            } else {
3298
194k
                if (current->sh_slice_type == VVC_SLICE_TYPE_B)
3299
173k
                    infer(sh_collocated_from_l0_flag, ph->ph_collocated_from_l0_flag);
3300
21.6k
                else
3301
21.6k
                    infer(sh_collocated_from_l0_flag, 1);
3302
194k
                infer(sh_collocated_ref_idx, ph->ph_collocated_ref_idx);
3303
3.83k
            }
3304
306k
        }
3305
453k
        if (!pps->pps_wp_info_in_ph_flag &&
3306
235k
            ((pps->pps_weighted_pred_flag &&
3307
114k
            current->sh_slice_type == VVC_SLICE_TYPE_P) ||
3308
223k
            (pps->pps_weighted_bipred_flag &&
3309
126k
            current->sh_slice_type == VVC_SLICE_TYPE_B))) {
3310
126k
            CHECK(FUNC(pred_weight_table) (ctx, rw, sps, pps, ref_pic_lists,
3311
126k
                                           current->num_ref_idx_active,
3312
126k
                                           &current->sh_pred_weight_table));
3313
126k
        }
3314
453k
    }
3315
5.78M
    qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
3316
5.78M
    if (!pps->pps_qp_delta_info_in_ph_flag)
3317
5.78M
        se(sh_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
3318
5.76M
           63 - (26 + pps->pps_init_qp_minus26));
3319
5.76M
    if (pps->pps_slice_chroma_qp_offsets_present_flag) {
3320
1.00M
        int8_t off;
3321
3322
1.00M
        se(sh_cb_qp_offset, -12, 12);
3323
982k
        off = pps->pps_cb_qp_offset + current->sh_cb_qp_offset;
3324
982k
        if (off < -12 || off > 12) {
3325
935
            av_log(ctx->log_ctx, AV_LOG_ERROR,
3326
935
                   "pps_cb_qp_offset + sh_cb_qp_offset (%d) not in range [-12, 12].\n",
3327
935
                   off);
3328
935
            return AVERROR_INVALIDDATA;
3329
935
        }
3330
3331
981k
        se(sh_cr_qp_offset, -12, 12);
3332
965k
        off = pps->pps_cr_qp_offset + current->sh_cr_qp_offset;
3333
965k
        if (off < -12 || off > 12) {
3334
1.59k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
3335
1.59k
                   "pps_cr_qp_offset + sh_cr_qp_offset (%d) not in range [-12, 12].\n",
3336
1.59k
                   off);
3337
1.59k
            return AVERROR_INVALIDDATA;
3338
1.59k
        }
3339
3340
963k
        if (sps->sps_joint_cbcr_enabled_flag) {
3341
915k
            se(sh_joint_cbcr_qp_offset, -12, 12);
3342
909k
            off =
3343
909k
                pps->pps_joint_cbcr_qp_offset_value +
3344
909k
                current->sh_joint_cbcr_qp_offset;
3345
909k
            if (off < -12 || off > 12) {
3346
1.13k
                av_log(ctx->log_ctx, AV_LOG_ERROR,
3347
1.13k
                       "pps_joint_cbcr_qp_offset_value + sh_joint_cbcr_qp_offset (%d)"
3348
1.13k
                       "not in range [-12, 12]. \n", off);
3349
1.13k
                return AVERROR_INVALIDDATA;
3350
1.13k
            }
3351
909k
        } else {
3352
47.9k
            infer(sh_joint_cbcr_qp_offset, 0);
3353
47.9k
        }
3354
4.75M
    } else {
3355
4.75M
        infer(sh_cb_qp_offset, 0);
3356
4.75M
        infer(sh_cr_qp_offset, 0);
3357
4.75M
        infer(sh_joint_cbcr_qp_offset, 0);
3358
18.7k
    }
3359
5.70M
    if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
3360
5.70M
        flag(sh_cu_chroma_qp_offset_enabled_flag);
3361
5.24M
    else
3362
5.24M
        infer(sh_cu_chroma_qp_offset_enabled_flag, 0);
3363
5.70M
    if (sps->sps_sao_enabled_flag && !pps->pps_sao_info_in_ph_flag) {
3364
2.22M
        flag(sh_sao_luma_used_flag);
3365
2.22M
        if (sps->sps_chroma_format_idc != 0)
3366
2.22M
            flag(sh_sao_chroma_used_flag);
3367
54.3k
        else
3368
54.3k
            infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3369
3.47M
    } else {
3370
3.47M
        infer(sh_sao_luma_used_flag, ph->ph_sao_luma_enabled_flag);
3371
3.47M
        infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3372
15.6k
    }
3373
3374
5.70M
    if (pps->pps_deblocking_filter_override_enabled_flag &&
3375
2.83M
        !pps->pps_dbf_info_in_ph_flag)
3376
5.70M
        flag(sh_deblocking_params_present_flag);
3377
3.34M
    else
3378
3.34M
        infer(sh_deblocking_params_present_flag, 0);
3379
5.70M
    if (current->sh_deblocking_params_present_flag) {
3380
2.26M
        if (!pps->pps_deblocking_filter_disabled_flag)
3381
2.26M
            flag(sh_deblocking_filter_disabled_flag);
3382
2.24M
        else
3383
2.24M
            infer(sh_deblocking_filter_disabled_flag, 0);
3384
2.26M
        if (!current->sh_deblocking_filter_disabled_flag) {
3385
2.25M
            se(sh_luma_beta_offset_div2, -12, 12);
3386
2.24M
            se(sh_luma_tc_offset_div2, -12, 12);
3387
2.22M
            if (pps->pps_chroma_tool_offsets_present_flag) {
3388
96.3k
                se(sh_cb_beta_offset_div2, -12, 12);
3389
87.5k
                se(sh_cb_tc_offset_div2, -12, 12);
3390
85.0k
                se(sh_cr_beta_offset_div2, -12, 12);
3391
84.1k
                se(sh_cr_tc_offset_div2, -12, 12);
3392
2.13M
            } else {
3393
2.13M
                infer(sh_cb_beta_offset_div2,
3394
2.13M
                      current->sh_luma_beta_offset_div2);
3395
2.13M
                infer(sh_cb_tc_offset_div2, current->sh_luma_tc_offset_div2);
3396
2.13M
                infer(sh_cr_beta_offset_div2,
3397
762
                      current->sh_luma_beta_offset_div2);
3398
2.13M
                infer(sh_cr_tc_offset_div2, current->sh_luma_tc_offset_div2);
3399
538
            }
3400
2.22M
        }
3401
3.43M
    } else {
3402
3.43M
        infer(sh_deblocking_filter_disabled_flag, ph->ph_deblocking_filter_disabled_flag);
3403
3.43M
        if (!current->sh_deblocking_filter_disabled_flag) {
3404
3.24M
            infer(sh_luma_beta_offset_div2, ph->ph_luma_beta_offset_div2);
3405
3.24M
            infer(sh_luma_tc_offset_div2, ph->ph_luma_tc_offset_div2);
3406
3.24M
            infer(sh_cb_beta_offset_div2, ph->ph_cb_beta_offset_div2);
3407
3.24M
            infer(sh_cb_tc_offset_div2, ph->ph_cb_tc_offset_div2);
3408
3.24M
            infer(sh_cr_beta_offset_div2, ph->ph_cr_beta_offset_div2);
3409
3.24M
            infer(sh_cr_tc_offset_div2, ph->ph_cr_tc_offset_div2);
3410
17.3k
        }
3411
20.3k
    }
3412
3413
5.65M
    if (sps->sps_dep_quant_enabled_flag)
3414
5.65M
        flag(sh_dep_quant_used_flag);
3415
3.83M
    else
3416
3.83M
        infer(sh_dep_quant_used_flag, 0);
3417
3418
5.64M
    if (sps->sps_sign_data_hiding_enabled_flag &&
3419
4.21M
        !current->sh_dep_quant_used_flag)
3420
5.64M
        flag(sh_sign_data_hiding_used_flag);
3421
1.97M
    else
3422
1.97M
        infer(sh_sign_data_hiding_used_flag, 0);
3423
3424
5.64M
    if (sps->sps_transform_skip_enabled_flag &&
3425
3.97M
        !current->sh_dep_quant_used_flag &&
3426
2.61M
        !current->sh_sign_data_hiding_used_flag)
3427
5.64M
        flag(sh_ts_residual_coding_disabled_flag);
3428
5.21M
    else
3429
5.21M
        infer(sh_ts_residual_coding_disabled_flag, 0);
3430
3431
5.64M
    if (!current->sh_ts_residual_coding_disabled_flag &&
3432
5.36M
        sps->sps_ts_residual_coding_rice_present_in_sh_flag)
3433
28.0k
        ub(3, sh_ts_residual_coding_rice_idx_minus1);
3434
5.61M
    else
3435
5.61M
        infer(sh_ts_residual_coding_rice_idx_minus1, 0);
3436
3437
5.64M
    if (sps->sps_reverse_last_sig_coeff_enabled_flag)
3438
5.64M
        flag(sh_reverse_last_sig_coeff_flag);
3439
5.61M
    else
3440
5.61M
        infer(sh_reverse_last_sig_coeff_flag, 0);
3441
3442
5.64M
    if (pps->pps_slice_header_extension_present_flag) {
3443
4.57M
        ue(sh_slice_header_extension_length, 0, 256);
3444
5.66M
        for (i = 0; i < current->sh_slice_header_extension_length; i++)
3445
4.56M
            us(8, sh_slice_header_extension_data_byte[i], 0x00, 0xff, 1, i);
3446
4.56M
    }
3447
3448
5.59M
    current->num_entry_points = 0;
3449
5.59M
    if (sps->sps_entry_point_offsets_present_flag) {
3450
4.00M
        uint8_t entropy_sync = sps->sps_entropy_coding_sync_enabled_flag;
3451
4.00M
        int height;
3452
4.00M
        if (pps->pps_rect_slice_flag) {
3453
891k
            int width_in_tiles;
3454
891k
            int slice_idx = current->sh_slice_address;
3455
1.06M
            for (i = 0; i < current->curr_subpic_idx; i++) {
3456
175k
                slice_idx += pps->num_slices_in_subpic[i];
3457
175k
            }
3458
3459
891k
            if (pps->pps_single_slice_per_subpic_flag) {
3460
832k
                const int width_in_ctus = sps->sps_subpic_width_minus1[slice_idx] + 1;
3461
832k
                const int subpic_l = sps->sps_subpic_ctu_top_left_x[slice_idx];
3462
832k
                const int subpic_r = subpic_l + width_in_ctus;
3463
3464
832k
                int ctb_x = 0, tile_x = 0;
3465
884k
                for (; ctb_x < subpic_l && tile_x < pps->num_tile_columns; tile_x++)
3466
52.5k
                    ctb_x += pps->col_width_val[tile_x];
3467
3468
832k
                width_in_tiles = 0;
3469
1.71M
                for (; ctb_x < subpic_r && tile_x < pps->num_tile_columns; tile_x++) {
3470
882k
                    ctb_x += pps->col_width_val[tile_x];
3471
882k
                    width_in_tiles++;
3472
882k
                }
3473
3474
832k
                if (entropy_sync) {
3475
13.7k
                    height = sps->sps_subpic_height_minus1[slice_idx] + 1;
3476
818k
                } else {
3477
818k
                    const int height_in_ctus = sps->sps_subpic_height_minus1[slice_idx] + 1;
3478
818k
                    const int subpic_t = sps->sps_subpic_ctu_top_left_y[slice_idx];
3479
818k
                    const int subpic_b = subpic_t + height_in_ctus;
3480
3481
818k
                    int ctb_y = 0, tile_y = 0, height_in_tiles;
3482
848k
                    for (; ctb_y < subpic_t && tile_y < pps->num_tile_rows; tile_y++)
3483
30.3k
                        ctb_y += pps->row_height_val[tile_y];
3484
3485
818k
                    height_in_tiles = 0;
3486
1.66M
                    for (; ctb_y < subpic_b && tile_y < pps->num_tile_rows; tile_y++) {
3487
850k
                        ctb_y += pps->row_height_val[tile_y];
3488
850k
                        height_in_tiles++;
3489
850k
                    }
3490
3491
818k
                    height = height_in_tiles;
3492
818k
                }
3493
832k
            } else {
3494
58.8k
                width_in_tiles =
3495
58.8k
                    pps->pps_slice_width_in_tiles_minus1[slice_idx] + 1;
3496
3497
58.8k
                if (entropy_sync)
3498
3.95k
                    height = pps->slice_height_in_ctus[slice_idx];
3499
54.9k
                else
3500
54.9k
                    height = pps->pps_slice_height_in_tiles_minus1[slice_idx] + 1;
3501
58.8k
            }
3502
3503
891k
            current->num_entry_points = width_in_tiles * height;
3504
3.10M
        } else {
3505
3.10M
            int tile_idx;
3506
3.10M
            int tile_y;
3507
3.10M
            for (tile_idx = current->sh_slice_address;
3508
6.25M
                 tile_idx <=
3509
6.25M
                 current->sh_slice_address +
3510
6.25M
                 current->sh_num_tiles_in_slice_minus1; tile_idx++) {
3511
3.14M
                tile_y = tile_idx / pps->num_tile_columns;
3512
3.14M
                height = pps->row_height_val[tile_y];
3513
3.14M
                current->num_entry_points += (entropy_sync ? height : 1);
3514
3.14M
            }
3515
3.10M
        }
3516
4.00M
        current->num_entry_points--;
3517
4.00M
        if (current->num_entry_points > VVC_MAX_ENTRY_POINTS) {
3518
632
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
3519
632
                   "%" PRIu32 ".\n", current->num_entry_points);
3520
632
            return AVERROR_PATCHWELCOME;
3521
632
        }
3522
4.00M
        if (current->num_entry_points > 0) {
3523
54.4k
            ue(sh_entry_offset_len_minus1, 0, 31);
3524
1.64M
            for (i = 0; i < current->num_entry_points; i++) {
3525
1.60M
                ubs(current->sh_entry_offset_len_minus1 + 1,
3526
1.60M
                    sh_entry_point_offset_minus1[i], 1, i);
3527
1.60M
            }
3528
48.3k
        }
3529
4.00M
    }
3530
5.58M
    CHECK(FUNC(byte_alignment) (ctx, rw));
3531
3532
4.96M
    return 0;
3533
5.58M
}
cbs_h266.c:cbs_h266_read_slice_header
Line
Count
Source
3067
7.69M
{
3068
7.69M
    CodedBitstreamH266Context *h266 = ctx->priv_data;
3069
7.69M
    const H266RawSPS *sps;
3070
7.69M
    const H266RawPPS *pps;
3071
7.69M
    const H266RawPictureHeader *ph;
3072
7.69M
    const H266RefPicLists *ref_pic_lists;
3073
7.69M
    int err, i;
3074
7.69M
    uint8_t nal_unit_type, qp_bd_offset;
3075
7.69M
    uint16_t num_slices_in_subpic;
3076
3077
7.69M
    HEADER("Slice Header");
3078
3079
7.69M
    CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, -1));
3080
3081
7.69M
    flag(sh_picture_header_in_slice_header_flag);
3082
7.67M
    if (current->sh_picture_header_in_slice_header_flag) {
3083
        // 7.4.8 if sh_picture_header_in_slice_header_flag is true, we do not have a PH NAL unit
3084
7.01M
        CHECK(FUNC(picture_header) (ctx, rw, &current->sh_picture_header));
3085
5.75M
        ph = &current->sh_picture_header;
3086
5.75M
    } else {
3087
658k
        ph = h266->ph;
3088
658k
        if (!ph) {
3089
241k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
3090
241k
                   "Picture header not available.\n");
3091
241k
            return AVERROR_INVALIDDATA;
3092
241k
        }
3093
658k
    }
3094
3095
6.16M
    pps = h266->pps[ph->ph_pic_parameter_set_id];
3096
6.16M
    if (!pps) {
3097
12.9k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
3098
12.9k
               ph->ph_pic_parameter_set_id);
3099
12.9k
        return AVERROR_INVALIDDATA;
3100
12.9k
    }
3101
6.15M
    sps = h266->sps[pps->pps_seq_parameter_set_id];
3102
6.15M
    if (!sps) {
3103
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
3104
0
               pps->pps_seq_parameter_set_id);
3105
0
        return AVERROR_INVALIDDATA;
3106
0
    }
3107
3108
6.15M
    if (sps->sps_subpic_info_present_flag) {
3109
128k
        ub(sps->sps_subpic_id_len_minus1 + 1, sh_subpic_id);
3110
388k
        for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
3111
379k
            if (pps->sub_pic_id_val[i] == current->sh_subpic_id) {
3112
118k
                current->curr_subpic_idx = i;
3113
118k
                break;
3114
118k
            }
3115
379k
        }
3116
127k
        if (i > sps->sps_num_subpics_minus1) {
3117
8.99k
            av_log(ctx->log_ctx, AV_LOG_ERROR, "invalid CurrSubpicIdx %d\n", i);
3118
8.99k
            return AVERROR_INVALIDDATA;
3119
8.99k
        }
3120
6.02M
    } else {
3121
6.02M
        current->curr_subpic_idx = 0;
3122
6.02M
    }
3123
3124
6.14M
    num_slices_in_subpic = pps->num_slices_in_subpic[current->curr_subpic_idx];
3125
3126
6.14M
    if ((pps->pps_rect_slice_flag && num_slices_in_subpic > 1) ||
3127
6.10M
        (!pps->pps_rect_slice_flag && pps->num_tiles_in_pic > 1)) {
3128
88.0k
        unsigned int bits, max;
3129
88.0k
        if (!pps->pps_rect_slice_flag) {
3130
50.1k
            bits = av_ceil_log2(pps->num_tiles_in_pic);
3131
50.1k
            max = pps->num_tiles_in_pic - 1;
3132
50.1k
        } else {
3133
37.9k
            bits = av_ceil_log2(num_slices_in_subpic);
3134
37.9k
            max = num_slices_in_subpic - 1;
3135
37.9k
        }
3136
88.0k
        u(bits, sh_slice_address, 0, max);
3137
6.05M
    } else {
3138
6.05M
        infer(sh_slice_address, 0);
3139
6.05M
    }
3140
3141
34.1M
    for (i = 0; i < sps->sps_num_extra_sh_bytes * 8; i++) {
3142
28.0M
        if (sps->sps_extra_sh_bit_present_flag[i])
3143
28.0M
            flags(sh_extra_bit[i], 1, i);
3144
28.0M
    }
3145
3146
6.13M
    if (!pps->pps_rect_slice_flag &&
3147
5.01M
        pps->num_tiles_in_pic - current->sh_slice_address > 1)
3148
6.13M
        ue(sh_num_tiles_in_slice_minus1, 0, pps->num_tiles_in_pic - 1);
3149
6.09M
    else
3150
6.09M
        infer(sh_num_tiles_in_slice_minus1, 0);
3151
3152
6.13M
    if (ph->ph_inter_slice_allowed_flag)
3153
6.13M
        ue(sh_slice_type, 0, 2);
3154
5.50M
    else
3155
5.50M
        infer(sh_slice_type, 2);
3156
3157
6.03M
    nal_unit_type = current->nal_unit_header.nal_unit_type;
3158
6.03M
    if (nal_unit_type == VVC_IDR_W_RADL || nal_unit_type == VVC_IDR_N_LP ||
3159
5.94M
        nal_unit_type == VVC_CRA_NUT || nal_unit_type == VVC_GDR_NUT)
3160
6.03M
        flag(sh_no_output_of_prior_pics_flag);
3161
3162
6.03M
    if (sps->sps_alf_enabled_flag) {
3163
3.41M
        if (!pps->pps_alf_info_in_ph_flag) {
3164
3.12M
            flag(sh_alf_enabled_flag);
3165
3.12M
            if (current->sh_alf_enabled_flag) {
3166
299k
                ub(3, sh_num_alf_aps_ids_luma);
3167
1.53M
                for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3168
1.25M
                    ubs(3, sh_alf_aps_id_luma[i], 1, i);
3169
3170
284k
                if (sps->sps_chroma_format_idc != 0) {
3171
245k
                    flag(sh_alf_cb_enabled_flag);
3172
244k
                    flag(sh_alf_cr_enabled_flag);
3173
244k
                }
3174
282k
                if (current->sh_alf_cb_enabled_flag ||
3175
182k
                    current->sh_alf_cr_enabled_flag) {
3176
182k
                    ub(3, sh_alf_aps_id_chroma);
3177
182k
                }
3178
3179
281k
                if (sps->sps_ccalf_enabled_flag) {
3180
185k
                    flag(sh_alf_cc_cb_enabled_flag);
3181
184k
                    if (current->sh_alf_cc_cb_enabled_flag)
3182
87.6k
                        ub(3, sh_alf_cc_cb_aps_id);
3183
3184
183k
                    flag(sh_alf_cc_cr_enabled_flag);
3185
183k
                    if (current->sh_alf_cc_cr_enabled_flag)
3186
101k
                        ub(3, sh_alf_cc_cr_aps_id);
3187
183k
                }
3188
281k
            }
3189
3.12M
        } else {
3190
293k
            infer(sh_alf_enabled_flag, ph->ph_alf_enabled_flag);
3191
293k
            if (current->sh_alf_enabled_flag) {
3192
112k
                infer(sh_num_alf_aps_ids_luma, ph->ph_num_alf_aps_ids_luma);
3193
427k
                for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3194
314k
                    infer(sh_alf_aps_id_luma[i], ph->ph_alf_aps_id_luma[i]);
3195
3196
112k
                infer(sh_alf_cb_enabled_flag, ph->ph_alf_cb_enabled_flag);
3197
112k
                infer(sh_alf_cr_enabled_flag, ph->ph_alf_cr_enabled_flag);
3198
112k
                if (current->sh_alf_cb_enabled_flag ||current->sh_alf_cr_enabled_flag)
3199
91.1k
                    infer(sh_alf_aps_id_chroma, ph->ph_alf_aps_id_chroma);
3200
3201
112k
                if (sps->sps_ccalf_enabled_flag) {
3202
91.6k
                    infer(sh_alf_cc_cb_enabled_flag, ph->ph_alf_cc_cb_enabled_flag);
3203
91.6k
                    if (current->sh_alf_cc_cb_enabled_flag)
3204
45.0k
                        infer(sh_alf_cc_cb_aps_id, ph->ph_alf_cc_cb_aps_id);
3205
3206
91.6k
                    infer(sh_alf_cc_cr_enabled_flag, ph->ph_alf_cc_cr_enabled_flag);
3207
91.6k
                    if (current->sh_alf_cc_cr_enabled_flag)
3208
42.8k
                        infer(sh_alf_cc_cr_aps_id, ph->ph_alf_cc_cr_aps_id);
3209
91.6k
                }
3210
112k
            }
3211
293k
        }
3212
3.41M
    }
3213
3214
6.01M
    if (current->sh_picture_header_in_slice_header_flag) {
3215
5.67M
        infer(sh_lmcs_used_flag, ph->ph_lmcs_enabled_flag);
3216
5.67M
        infer(sh_explicit_scaling_list_used_flag,
3217
5.67M
            ph->ph_explicit_scaling_list_enabled_flag);
3218
5.67M
    } else {
3219
331k
        if (ph->ph_lmcs_enabled_flag)
3220
331k
            flag(sh_lmcs_used_flag);
3221
175k
        else
3222
175k
            infer(sh_lmcs_used_flag, 0);
3223
3224
331k
        if (ph->ph_explicit_scaling_list_enabled_flag)
3225
331k
            flag(sh_explicit_scaling_list_used_flag);
3226
295k
        else
3227
295k
            infer(sh_explicit_scaling_list_used_flag, 0);
3228
331k
    }
3229
3230
6.00M
    if (!pps->pps_rpl_info_in_ph_flag &&
3231
5.41M
        ((nal_unit_type != VVC_IDR_W_RADL &&
3232
5.38M
          nal_unit_type != VVC_IDR_N_LP) || sps->sps_idr_rpl_present_flag)) {
3233
5.36M
        CHECK(FUNC(ref_pic_lists)
3234
5.36M
              (ctx, rw, sps, pps, &current->sh_ref_pic_lists));
3235
5.16M
        ref_pic_lists = &current->sh_ref_pic_lists;
3236
5.16M
    } else {
3237
647k
        ref_pic_lists = &ph->ph_ref_pic_lists;
3238
647k
    }
3239
5.81M
    if ((current->sh_slice_type != VVC_SLICE_TYPE_I &&
3240
464k
         ref_pic_lists->rpl_ref_list[0].num_ref_entries > 1) ||
3241
5.62M
        (current->sh_slice_type == VVC_SLICE_TYPE_B &&
3242
247k
         ref_pic_lists->rpl_ref_list[1].num_ref_entries > 1)) {
3243
217k
        flag(sh_num_ref_idx_active_override_flag);
3244
216k
        if (current->sh_num_ref_idx_active_override_flag) {
3245
132k
            for (i = 0;
3246
382k
                 i < (current->sh_slice_type == VVC_SLICE_TYPE_B ? 2 : 1); i++)
3247
254k
                if (ref_pic_lists->rpl_ref_list[i].num_ref_entries > 1)
3248
254k
                    ues(sh_num_ref_idx_active_minus1[i], 0, 14, 1, i);
3249
108k
                else
3250
108k
                    infer(sh_num_ref_idx_active_minus1[i], 0);
3251
132k
        }
3252
5.60M
    } else {
3253
5.60M
        infer(sh_num_ref_idx_active_override_flag, 1);
3254
5.60M
    }
3255
3256
17.4M
    for (i = 0; i < 2; i++) {
3257
11.6M
        if (current->sh_slice_type == VVC_SLICE_TYPE_B ||
3258
10.8M
            (current->sh_slice_type == VVC_SLICE_TYPE_P && i == 0)) {
3259
861k
            if (current->sh_num_ref_idx_active_override_flag) {
3260
723k
                current->num_ref_idx_active[i] = current->sh_num_ref_idx_active_minus1[i] + 1;
3261
723k
            } else {
3262
138k
                current->num_ref_idx_active[i] =
3263
138k
                    FFMIN(ref_pic_lists->rpl_ref_list[i].num_ref_entries,
3264
138k
                        pps->pps_num_ref_idx_default_active_minus1[i] + 1);
3265
138k
            }
3266
3267
861k
            if (current->num_ref_idx_active[i] <= 0) {
3268
16.4k
                av_log(ctx->log_ctx, AV_LOG_ERROR,
3269
16.4k
                       "Inter slice but no reference pictures available for RPL%d.\n", i);
3270
16.4k
                return AVERROR_INVALIDDATA;
3271
16.4k
            }
3272
10.7M
        } else {
3273
10.7M
            current->num_ref_idx_active[i] = 0;
3274
10.7M
        }
3275
11.6M
    }
3276
3277
5.79M
    if (current->sh_slice_type != VVC_SLICE_TYPE_I) {
3278
443k
        if (pps->pps_cabac_init_present_flag)
3279
443k
            flag(sh_cabac_init_flag);
3280
13.8k
        else
3281
13.8k
            infer(sh_cabac_init_flag, 0);
3282
441k
        if (ph->ph_temporal_mvp_enabled_flag) {
3283
297k
            if (!pps->pps_rpl_info_in_ph_flag) {
3284
107k
                if (current->sh_slice_type == VVC_SLICE_TYPE_B)
3285
107k
                    flag(sh_collocated_from_l0_flag);
3286
12.1k
                else
3287
12.1k
                    infer(sh_collocated_from_l0_flag, 1);
3288
106k
                if ((current->sh_collocated_from_l0_flag &&
3289
71.9k
                    current->num_ref_idx_active[0] > 1) ||
3290
94.1k
                    (!current->sh_collocated_from_l0_flag &&
3291
34.5k
                    current->num_ref_idx_active[1] > 1)) {
3292
25.3k
                    unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1;
3293
25.3k
                    ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] - 1);
3294
81.2k
                } else {
3295
81.2k
                    infer(sh_collocated_ref_idx, 0);
3296
81.2k
                }
3297
190k
            } else {
3298
190k
                if (current->sh_slice_type == VVC_SLICE_TYPE_B)
3299
169k
                    infer(sh_collocated_from_l0_flag, ph->ph_collocated_from_l0_flag);
3300
21.0k
                else
3301
21.0k
                    infer(sh_collocated_from_l0_flag, 1);
3302
190k
                infer(sh_collocated_ref_idx, ph->ph_collocated_ref_idx);
3303
190k
            }
3304
297k
        }
3305
439k
        if (!pps->pps_wp_info_in_ph_flag &&
3306
223k
            ((pps->pps_weighted_pred_flag &&
3307
111k
            current->sh_slice_type == VVC_SLICE_TYPE_P) ||
3308
211k
            (pps->pps_weighted_bipred_flag &&
3309
123k
            current->sh_slice_type == VVC_SLICE_TYPE_B))) {
3310
123k
            CHECK(FUNC(pred_weight_table) (ctx, rw, sps, pps, ref_pic_lists,
3311
123k
                                           current->num_ref_idx_active,
3312
123k
                                           &current->sh_pred_weight_table));
3313
123k
        }
3314
439k
    }
3315
5.76M
    qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
3316
5.76M
    if (!pps->pps_qp_delta_info_in_ph_flag)
3317
5.76M
        se(sh_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
3318
5.73M
           63 - (26 + pps->pps_init_qp_minus26));
3319
5.73M
    if (pps->pps_slice_chroma_qp_offsets_present_flag) {
3320
1.00M
        int8_t off;
3321
3322
1.00M
        se(sh_cb_qp_offset, -12, 12);
3323
975k
        off = pps->pps_cb_qp_offset + current->sh_cb_qp_offset;
3324
975k
        if (off < -12 || off > 12) {
3325
739
            av_log(ctx->log_ctx, AV_LOG_ERROR,
3326
739
                   "pps_cb_qp_offset + sh_cb_qp_offset (%d) not in range [-12, 12].\n",
3327
739
                   off);
3328
739
            return AVERROR_INVALIDDATA;
3329
739
        }
3330
3331
974k
        se(sh_cr_qp_offset, -12, 12);
3332
958k
        off = pps->pps_cr_qp_offset + current->sh_cr_qp_offset;
3333
958k
        if (off < -12 || off > 12) {
3334
1.17k
            av_log(ctx->log_ctx, AV_LOG_ERROR,
3335
1.17k
                   "pps_cr_qp_offset + sh_cr_qp_offset (%d) not in range [-12, 12].\n",
3336
1.17k
                   off);
3337
1.17k
            return AVERROR_INVALIDDATA;
3338
1.17k
        }
3339
3340
957k
        if (sps->sps_joint_cbcr_enabled_flag) {
3341
909k
            se(sh_joint_cbcr_qp_offset, -12, 12);
3342
903k
            off =
3343
903k
                pps->pps_joint_cbcr_qp_offset_value +
3344
903k
                current->sh_joint_cbcr_qp_offset;
3345
903k
            if (off < -12 || off > 12) {
3346
713
                av_log(ctx->log_ctx, AV_LOG_ERROR,
3347
713
                       "pps_joint_cbcr_qp_offset_value + sh_joint_cbcr_qp_offset (%d)"
3348
713
                       "not in range [-12, 12]. \n", off);
3349
713
                return AVERROR_INVALIDDATA;
3350
713
            }
3351
903k
        } else {
3352
47.2k
            infer(sh_joint_cbcr_qp_offset, 0);
3353
47.2k
        }
3354
4.73M
    } else {
3355
4.73M
        infer(sh_cb_qp_offset, 0);
3356
4.73M
        infer(sh_cr_qp_offset, 0);
3357
4.73M
        infer(sh_joint_cbcr_qp_offset, 0);
3358
4.73M
    }
3359
5.68M
    if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
3360
5.68M
        flag(sh_cu_chroma_qp_offset_enabled_flag);
3361
5.22M
    else
3362
5.22M
        infer(sh_cu_chroma_qp_offset_enabled_flag, 0);
3363
5.68M
    if (sps->sps_sao_enabled_flag && !pps->pps_sao_info_in_ph_flag) {
3364
2.22M
        flag(sh_sao_luma_used_flag);
3365
2.21M
        if (sps->sps_chroma_format_idc != 0)
3366
2.21M
            flag(sh_sao_chroma_used_flag);
3367
53.4k
        else
3368
53.4k
            infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3369
3.46M
    } else {
3370
3.46M
        infer(sh_sao_luma_used_flag, ph->ph_sao_luma_enabled_flag);
3371
3.46M
        infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3372
3.46M
    }
3373
3374
5.67M
    if (pps->pps_deblocking_filter_override_enabled_flag &&
3375
2.82M
        !pps->pps_dbf_info_in_ph_flag)
3376
5.67M
        flag(sh_deblocking_params_present_flag);
3377
3.32M
    else
3378
3.32M
        infer(sh_deblocking_params_present_flag, 0);
3379
5.67M
    if (current->sh_deblocking_params_present_flag) {
3380
2.26M
        if (!pps->pps_deblocking_filter_disabled_flag)
3381
2.26M
            flag(sh_deblocking_filter_disabled_flag);
3382
2.24M
        else
3383
2.24M
            infer(sh_deblocking_filter_disabled_flag, 0);
3384
2.26M
        if (!current->sh_deblocking_filter_disabled_flag) {
3385
2.25M
            se(sh_luma_beta_offset_div2, -12, 12);
3386
2.24M
            se(sh_luma_tc_offset_div2, -12, 12);
3387
2.22M
            if (pps->pps_chroma_tool_offsets_present_flag) {
3388
96.1k
                se(sh_cb_beta_offset_div2, -12, 12);
3389
87.3k
                se(sh_cb_tc_offset_div2, -12, 12);
3390
84.7k
                se(sh_cr_beta_offset_div2, -12, 12);
3391
83.8k
                se(sh_cr_tc_offset_div2, -12, 12);
3392
2.13M
            } else {
3393
2.13M
                infer(sh_cb_beta_offset_div2,
3394
2.13M
                      current->sh_luma_beta_offset_div2);
3395
2.13M
                infer(sh_cb_tc_offset_div2, current->sh_luma_tc_offset_div2);
3396
2.13M
                infer(sh_cr_beta_offset_div2,
3397
2.13M
                      current->sh_luma_beta_offset_div2);
3398
2.13M
                infer(sh_cr_tc_offset_div2, current->sh_luma_tc_offset_div2);
3399
2.13M
            }
3400
2.22M
        }
3401
3.41M
    } else {
3402
3.41M
        infer(sh_deblocking_filter_disabled_flag, ph->ph_deblocking_filter_disabled_flag);
3403
3.41M
        if (!current->sh_deblocking_filter_disabled_flag) {
3404
3.22M
            infer(sh_luma_beta_offset_div2, ph->ph_luma_beta_offset_div2);
3405
3.22M
            infer(sh_luma_tc_offset_div2, ph->ph_luma_tc_offset_div2);
3406
3.22M
            infer(sh_cb_beta_offset_div2, ph->ph_cb_beta_offset_div2);
3407
3.22M
            infer(sh_cb_tc_offset_div2, ph->ph_cb_tc_offset_div2);
3408
3.22M
            infer(sh_cr_beta_offset_div2, ph->ph_cr_beta_offset_div2);
3409
3.22M
            infer(sh_cr_tc_offset_div2, ph->ph_cr_tc_offset_div2);
3410
3.22M
        }
3411
3.41M
    }
3412
3413
5.63M
    if (sps->sps_dep_quant_enabled_flag)
3414
5.63M
        flag(sh_dep_quant_used_flag);
3415
3.82M
    else
3416
3.82M
        infer(sh_dep_quant_used_flag, 0);
3417
3418
5.62M
    if (sps->sps_sign_data_hiding_enabled_flag &&
3419
4.20M
        !current->sh_dep_quant_used_flag)
3420
5.62M
        flag(sh_sign_data_hiding_used_flag);
3421
1.95M
    else
3422
1.95M
        infer(sh_sign_data_hiding_used_flag, 0);
3423
3424
5.62M
    if (sps->sps_transform_skip_enabled_flag &&
3425
3.95M
        !current->sh_dep_quant_used_flag &&
3426
2.60M
        !current->sh_sign_data_hiding_used_flag)
3427
5.62M
        flag(sh_ts_residual_coding_disabled_flag);
3428
5.20M
    else
3429
5.20M
        infer(sh_ts_residual_coding_disabled_flag, 0);
3430
3431
5.62M
    if (!current->sh_ts_residual_coding_disabled_flag &&
3432
5.35M
        sps->sps_ts_residual_coding_rice_present_in_sh_flag)
3433
27.8k
        ub(3, sh_ts_residual_coding_rice_idx_minus1);
3434
5.59M
    else
3435
5.59M
        infer(sh_ts_residual_coding_rice_idx_minus1, 0);
3436
3437
5.62M
    if (sps->sps_reverse_last_sig_coeff_enabled_flag)
3438
5.62M
        flag(sh_reverse_last_sig_coeff_flag);
3439
5.59M
    else
3440
5.59M
        infer(sh_reverse_last_sig_coeff_flag, 0);
3441
3442
5.62M
    if (pps->pps_slice_header_extension_present_flag) {
3443
4.57M
        ue(sh_slice_header_extension_length, 0, 256);
3444
5.65M
        for (i = 0; i < current->sh_slice_header_extension_length; i++)
3445
4.56M
            us(8, sh_slice_header_extension_data_byte[i], 0x00, 0xff, 1, i);
3446
4.56M
    }
3447
3448
5.57M
    current->num_entry_points = 0;
3449
5.57M
    if (sps->sps_entry_point_offsets_present_flag) {
3450
3.98M
        uint8_t entropy_sync = sps->sps_entropy_coding_sync_enabled_flag;
3451
3.98M
        int height;
3452
3.98M
        if (pps->pps_rect_slice_flag) {
3453
883k
            int width_in_tiles;
3454
883k
            int slice_idx = current->sh_slice_address;
3455
1.04M
            for (i = 0; i < current->curr_subpic_idx; i++) {
3456
165k
                slice_idx += pps->num_slices_in_subpic[i];
3457
165k
            }
3458
3459
883k
            if (pps->pps_single_slice_per_subpic_flag) {
3460
826k
                const int width_in_ctus = sps->sps_subpic_width_minus1[slice_idx] + 1;
3461
826k
                const int subpic_l = sps->sps_subpic_ctu_top_left_x[slice_idx];
3462
826k
                const int subpic_r = subpic_l + width_in_ctus;
3463
3464
826k
                int ctb_x = 0, tile_x = 0;
3465
875k
                for (; ctb_x < subpic_l && tile_x < pps->num_tile_columns; tile_x++)
3466
48.9k
                    ctb_x += pps->col_width_val[tile_x];
3467
3468
826k
                width_in_tiles = 0;
3469
1.69M
                for (; ctb_x < subpic_r && tile_x < pps->num_tile_columns; tile_x++) {
3470
868k
                    ctb_x += pps->col_width_val[tile_x];
3471
868k
                    width_in_tiles++;
3472
868k
                }
3473
3474
826k
                if (entropy_sync) {
3475
13.4k
                    height = sps->sps_subpic_height_minus1[slice_idx] + 1;
3476
812k
                } else {
3477
812k
                    const int height_in_ctus = sps->sps_subpic_height_minus1[slice_idx] + 1;
3478
812k
                    const int subpic_t = sps->sps_subpic_ctu_top_left_y[slice_idx];
3479
812k
                    const int subpic_b = subpic_t + height_in_ctus;
3480
3481
812k
                    int ctb_y = 0, tile_y = 0, height_in_tiles;
3482
841k
                    for (; ctb_y < subpic_t && tile_y < pps->num_tile_rows; tile_y++)
3483
28.7k
                        ctb_y += pps->row_height_val[tile_y];
3484
3485
812k
                    height_in_tiles = 0;
3486
1.65M
                    for (; ctb_y < subpic_b && tile_y < pps->num_tile_rows; tile_y++) {
3487
839k
                        ctb_y += pps->row_height_val[tile_y];
3488
839k
                        height_in_tiles++;
3489
839k
                    }
3490
3491
812k
                    height = height_in_tiles;
3492
812k
                }
3493
826k
            } else {
3494
56.8k
                width_in_tiles =
3495
56.8k
                    pps->pps_slice_width_in_tiles_minus1[slice_idx] + 1;
3496
3497
56.8k
                if (entropy_sync)
3498
3.75k
                    height = pps->slice_height_in_ctus[slice_idx];
3499
53.0k
                else
3500
53.0k
                    height = pps->pps_slice_height_in_tiles_minus1[slice_idx] + 1;
3501
56.8k
            }
3502
3503
883k
            current->num_entry_points = width_in_tiles * height;
3504
3.09M
        } else {
3505
3.09M
            int tile_idx;
3506
3.09M
            int tile_y;
3507
3.09M
            for (tile_idx = current->sh_slice_address;
3508
6.23M
                 tile_idx <=
3509
6.23M
                 current->sh_slice_address +
3510
6.23M
                 current->sh_num_tiles_in_slice_minus1; tile_idx++) {
3511
3.13M
                tile_y = tile_idx / pps->num_tile_columns;
3512
3.13M
                height = pps->row_height_val[tile_y];
3513
3.13M
                current->num_entry_points += (entropy_sync ? height : 1);
3514
3.13M
            }
3515
3.09M
        }
3516
3.98M
        current->num_entry_points--;
3517
3.98M
        if (current->num_entry_points > VVC_MAX_ENTRY_POINTS) {
3518
632
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
3519
632
                   "%" PRIu32 ".\n", current->num_entry_points);
3520
632
            return AVERROR_PATCHWELCOME;
3521
632
        }
3522
3.98M
        if (current->num_entry_points > 0) {
3523
50.2k
            ue(sh_entry_offset_len_minus1, 0, 31);
3524
1.48M
            for (i = 0; i < current->num_entry_points; i++) {
3525
1.44M
                ubs(current->sh_entry_offset_len_minus1 + 1,
3526
1.44M
                    sh_entry_point_offset_minus1[i], 1, i);
3527
1.44M
            }
3528
44.1k
        }
3529
3.98M
    }
3530
5.56M
    CHECK(FUNC(byte_alignment) (ctx, rw));
3531
3532
4.94M
    return 0;
3533
5.56M
}
cbs_h266.c:cbs_h266_write_slice_header
Line
Count
Source
3067
46.8k
{
3068
46.8k
    CodedBitstreamH266Context *h266 = ctx->priv_data;
3069
46.8k
    const H266RawSPS *sps;
3070
46.8k
    const H266RawPPS *pps;
3071
46.8k
    const H266RawPictureHeader *ph;
3072
46.8k
    const H266RefPicLists *ref_pic_lists;
3073
46.8k
    int err, i;
3074
46.8k
    uint8_t nal_unit_type, qp_bd_offset;
3075
46.8k
    uint16_t num_slices_in_subpic;
3076
3077
46.8k
    HEADER("Slice Header");
3078
3079
46.8k
    CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, -1));
3080
3081
46.8k
    flag(sh_picture_header_in_slice_header_flag);
3082
46.8k
    if (current->sh_picture_header_in_slice_header_flag) {
3083
        // 7.4.8 if sh_picture_header_in_slice_header_flag is true, we do not have a PH NAL unit
3084
23.9k
        CHECK(FUNC(picture_header) (ctx, rw, &current->sh_picture_header));
3085
12.2k
        ph = &current->sh_picture_header;
3086
22.9k
    } else {
3087
22.9k
        ph = h266->ph;
3088
22.9k
        if (!ph) {
3089
502
            av_log(ctx->log_ctx, AV_LOG_ERROR,
3090
502
                   "Picture header not available.\n");
3091
502
            return AVERROR_INVALIDDATA;
3092
502
        }
3093
22.9k
    }
3094
3095
34.7k
    pps = h266->pps[ph->ph_pic_parameter_set_id];
3096
34.7k
    if (!pps) {
3097
208
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
3098
208
               ph->ph_pic_parameter_set_id);
3099
208
        return AVERROR_INVALIDDATA;
3100
208
    }
3101
34.5k
    sps = h266->sps[pps->pps_seq_parameter_set_id];
3102
34.5k
    if (!sps) {
3103
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
3104
0
               pps->pps_seq_parameter_set_id);
3105
0
        return AVERROR_INVALIDDATA;
3106
0
    }
3107
3108
34.5k
    if (sps->sps_subpic_info_present_flag) {
3109
7.64k
        ub(sps->sps_subpic_id_len_minus1 + 1, sh_subpic_id);
3110
27.5k
        for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
3111
27.1k
            if (pps->sub_pic_id_val[i] == current->sh_subpic_id) {
3112
7.05k
                current->curr_subpic_idx = i;
3113
7.05k
                break;
3114
7.05k
            }
3115
27.1k
        }
3116
7.44k
        if (i > sps->sps_num_subpics_minus1) {
3117
382
            av_log(ctx->log_ctx, AV_LOG_ERROR, "invalid CurrSubpicIdx %d\n", i);
3118
382
            return AVERROR_INVALIDDATA;
3119
382
        }
3120
26.8k
    } else {
3121
26.8k
        current->curr_subpic_idx = 0;
3122
26.8k
    }
3123
3124
33.9k
    num_slices_in_subpic = pps->num_slices_in_subpic[current->curr_subpic_idx];
3125
3126
33.9k
    if ((pps->pps_rect_slice_flag && num_slices_in_subpic > 1) ||
3127
31.7k
        (!pps->pps_rect_slice_flag && pps->num_tiles_in_pic > 1)) {
3128
6.01k
        unsigned int bits, max;
3129
6.01k
        if (!pps->pps_rect_slice_flag) {
3130
3.85k
            bits = av_ceil_log2(pps->num_tiles_in_pic);
3131
3.85k
            max = pps->num_tiles_in_pic - 1;
3132
3.85k
        } else {
3133
2.15k
            bits = av_ceil_log2(num_slices_in_subpic);
3134
2.15k
            max = num_slices_in_subpic - 1;
3135
2.15k
        }
3136
6.01k
        u(bits, sh_slice_address, 0, max);
3137
27.9k
    } else {
3138
27.9k
        infer(sh_slice_address, 0);
3139
27.9k
    }
3140
3141
58.2k
    for (i = 0; i < sps->sps_num_extra_sh_bytes * 8; i++) {
3142
24.6k
        if (sps->sps_extra_sh_bit_present_flag[i])
3143
24.6k
            flags(sh_extra_bit[i], 1, i);
3144
24.6k
    }
3145
3146
33.5k
    if (!pps->pps_rect_slice_flag &&
3147
19.7k
        pps->num_tiles_in_pic - current->sh_slice_address > 1)
3148
33.5k
        ue(sh_num_tiles_in_slice_minus1, 0, pps->num_tiles_in_pic - 1);
3149
29.8k
    else
3150
29.8k
        infer(sh_num_tiles_in_slice_minus1, 0);
3151
3152
33.1k
    if (ph->ph_inter_slice_allowed_flag)
3153
33.1k
        ue(sh_slice_type, 0, 2);
3154
14.7k
    else
3155
14.7k
        infer(sh_slice_type, 2);
3156
3157
32.9k
    nal_unit_type = current->nal_unit_header.nal_unit_type;
3158
32.9k
    if (nal_unit_type == VVC_IDR_W_RADL || nal_unit_type == VVC_IDR_N_LP ||
3159
29.4k
        nal_unit_type == VVC_CRA_NUT || nal_unit_type == VVC_GDR_NUT)
3160
32.9k
        flag(sh_no_output_of_prior_pics_flag);
3161
3162
32.9k
    if (sps->sps_alf_enabled_flag) {
3163
22.6k
        if (!pps->pps_alf_info_in_ph_flag) {
3164
11.0k
            flag(sh_alf_enabled_flag);
3165
11.0k
            if (current->sh_alf_enabled_flag) {
3166
6.06k
                ub(3, sh_num_alf_aps_ids_luma);
3167
21.6k
                for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3168
15.5k
                    ubs(3, sh_alf_aps_id_luma[i], 1, i);
3169
3170
6.06k
                if (sps->sps_chroma_format_idc != 0) {
3171
5.65k
                    flag(sh_alf_cb_enabled_flag);
3172
5.65k
                    flag(sh_alf_cr_enabled_flag);
3173
5.65k
                }
3174
6.06k
                if (current->sh_alf_cb_enabled_flag ||
3175
3.85k
                    current->sh_alf_cr_enabled_flag) {
3176
3.85k
                    ub(3, sh_alf_aps_id_chroma);
3177
3.85k
                }
3178
3179
6.06k
                if (sps->sps_ccalf_enabled_flag) {
3180
4.24k
                    flag(sh_alf_cc_cb_enabled_flag);
3181
4.24k
                    if (current->sh_alf_cc_cb_enabled_flag)
3182
737
                        ub(3, sh_alf_cc_cb_aps_id);
3183
3184
4.24k
                    flag(sh_alf_cc_cr_enabled_flag);
3185
4.24k
                    if (current->sh_alf_cc_cr_enabled_flag)
3186
1.46k
                        ub(3, sh_alf_cc_cr_aps_id);
3187
4.24k
                }
3188
6.06k
            }
3189
11.5k
        } else {
3190
11.5k
            infer(sh_alf_enabled_flag, ph->ph_alf_enabled_flag);
3191
11.3k
            if (current->sh_alf_enabled_flag) {
3192
9.40k
                infer(sh_num_alf_aps_ids_luma, ph->ph_num_alf_aps_ids_luma);
3193
24.1k
                for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3194
15.2k
                    infer(sh_alf_aps_id_luma[i], ph->ph_alf_aps_id_luma[i]);
3195
3196
8.85k
                infer(sh_alf_cb_enabled_flag, ph->ph_alf_cb_enabled_flag);
3197
8.66k
                infer(sh_alf_cr_enabled_flag, ph->ph_alf_cr_enabled_flag);
3198
8.46k
                if (current->sh_alf_cb_enabled_flag ||current->sh_alf_cr_enabled_flag)
3199
6.37k
                    infer(sh_alf_aps_id_chroma, ph->ph_alf_aps_id_chroma);
3200
3201
8.26k
                if (sps->sps_ccalf_enabled_flag) {
3202
6.97k
                    infer(sh_alf_cc_cb_enabled_flag, ph->ph_alf_cc_cb_enabled_flag);
3203
6.76k
                    if (current->sh_alf_cc_cb_enabled_flag)
3204
2.52k
                        infer(sh_alf_cc_cb_aps_id, ph->ph_alf_cc_cb_aps_id);
3205
3206
6.55k
                    infer(sh_alf_cc_cr_enabled_flag, ph->ph_alf_cc_cr_enabled_flag);
3207
6.36k
                    if (current->sh_alf_cc_cr_enabled_flag)
3208
1.68k
                        infer(sh_alf_cc_cr_aps_id, ph->ph_alf_cc_cr_aps_id);
3209
6.36k
                }
3210
8.26k
            }
3211
11.3k
        }
3212
22.6k
    }
3213
3214
30.7k
    if (current->sh_picture_header_in_slice_header_flag) {
3215
12.2k
        infer(sh_lmcs_used_flag, ph->ph_lmcs_enabled_flag);
3216
12.2k
        infer(sh_explicit_scaling_list_used_flag,
3217
12.2k
            ph->ph_explicit_scaling_list_enabled_flag);
3218
18.5k
    } else {
3219
18.5k
        if (ph->ph_lmcs_enabled_flag)
3220
18.5k
            flag(sh_lmcs_used_flag);
3221
11.2k
        else
3222
11.2k
            infer(sh_lmcs_used_flag, 0);
3223
3224
18.3k
        if (ph->ph_explicit_scaling_list_enabled_flag)
3225
18.3k
            flag(sh_explicit_scaling_list_used_flag);
3226
15.2k
        else
3227
15.2k
            infer(sh_explicit_scaling_list_used_flag, 0);
3228
18.3k
    }
3229
3230
30.3k
    if (!pps->pps_rpl_info_in_ph_flag &&
3231
20.5k
        ((nal_unit_type != VVC_IDR_W_RADL &&
3232
20.3k
          nal_unit_type != VVC_IDR_N_LP) || sps->sps_idr_rpl_present_flag)) {
3233
18.1k
        CHECK(FUNC(ref_pic_lists)
3234
18.1k
              (ctx, rw, sps, pps, &current->sh_ref_pic_lists));
3235
16.5k
        ref_pic_lists = &current->sh_ref_pic_lists;
3236
16.5k
    } else {
3237
12.2k
        ref_pic_lists = &ph->ph_ref_pic_lists;
3238
12.2k
    }
3239
28.7k
    if ((current->sh_slice_type != VVC_SLICE_TYPE_I &&
3240
15.1k
         ref_pic_lists->rpl_ref_list[0].num_ref_entries > 1) ||
3241
20.7k
        (current->sh_slice_type == VVC_SLICE_TYPE_B &&
3242
8.81k
         ref_pic_lists->rpl_ref_list[1].num_ref_entries > 1)) {
3243
8.81k
        flag(sh_num_ref_idx_active_override_flag);
3244
8.81k
        if (current->sh_num_ref_idx_active_override_flag) {
3245
4.38k
            for (i = 0;
3246
11.4k
                 i < (current->sh_slice_type == VVC_SLICE_TYPE_B ? 2 : 1); i++)
3247
7.19k
                if (ref_pic_lists->rpl_ref_list[i].num_ref_entries > 1)
3248
7.19k
                    ues(sh_num_ref_idx_active_minus1[i], 0, 14, 1, i);
3249
1.28k
                else
3250
1.28k
                    infer(sh_num_ref_idx_active_minus1[i], 0);
3251
4.38k
        }
3252
19.9k
    } else {
3253
19.9k
        infer(sh_num_ref_idx_active_override_flag, 1);
3254
19.9k
    }
3255
3256
85.2k
    for (i = 0; i < 2; i++) {
3257
56.9k
        if (current->sh_slice_type == VVC_SLICE_TYPE_B ||
3258
35.2k
            (current->sh_slice_type == VVC_SLICE_TYPE_P && i == 0)) {
3259
25.7k
            if (current->sh_num_ref_idx_active_override_flag) {
3260
17.2k
                current->num_ref_idx_active[i] = current->sh_num_ref_idx_active_minus1[i] + 1;
3261
17.2k
            } else {
3262
8.44k
                current->num_ref_idx_active[i] =
3263
8.44k
                    FFMIN(ref_pic_lists->rpl_ref_list[i].num_ref_entries,
3264
8.44k
                        pps->pps_num_ref_idx_default_active_minus1[i] + 1);
3265
8.44k
            }
3266
3267
25.7k
            if (current->num_ref_idx_active[i] <= 0) {
3268
199
                av_log(ctx->log_ctx, AV_LOG_ERROR,
3269
199
                       "Inter slice but no reference pictures available for RPL%d.\n", i);
3270
199
                return AVERROR_INVALIDDATA;
3271
199
            }
3272
31.2k
        } else {
3273
31.2k
            current->num_ref_idx_active[i] = 0;
3274
31.2k
        }
3275
56.9k
    }
3276
3277
28.2k
    if (current->sh_slice_type != VVC_SLICE_TYPE_I) {
3278
14.6k
        if (pps->pps_cabac_init_present_flag)
3279
14.6k
            flag(sh_cabac_init_flag);
3280
2.46k
        else
3281
2.46k
            infer(sh_cabac_init_flag, 0);
3282
14.4k
        if (ph->ph_temporal_mvp_enabled_flag) {
3283
8.63k
            if (!pps->pps_rpl_info_in_ph_flag) {
3284
4.40k
                if (current->sh_slice_type == VVC_SLICE_TYPE_B)
3285
4.40k
                    flag(sh_collocated_from_l0_flag);
3286
1.93k
                else
3287
1.93k
                    infer(sh_collocated_from_l0_flag, 1);
3288
4.21k
                if ((current->sh_collocated_from_l0_flag &&
3289
3.17k
                    current->num_ref_idx_active[0] > 1) ||
3290
3.11k
                    (!current->sh_collocated_from_l0_flag &&
3291
1.81k
                    current->num_ref_idx_active[1] > 1)) {
3292
1.81k
                    unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1;
3293
1.81k
                    ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] - 1);
3294
2.40k
                } else {
3295
2.40k
                    infer(sh_collocated_ref_idx, 0);
3296
2.40k
                }
3297
4.22k
            } else {
3298
4.22k
                if (current->sh_slice_type == VVC_SLICE_TYPE_B)
3299
3.65k
                    infer(sh_collocated_from_l0_flag, ph->ph_collocated_from_l0_flag);
3300
576
                else
3301
576
                    infer(sh_collocated_from_l0_flag, 1);
3302
3.83k
                infer(sh_collocated_ref_idx, ph->ph_collocated_ref_idx);
3303
3.83k
            }
3304
8.63k
        }
3305
13.1k
        if (!pps->pps_wp_info_in_ph_flag &&
3306
12.5k
            ((pps->pps_weighted_pred_flag &&
3307
2.91k
            current->sh_slice_type == VVC_SLICE_TYPE_P) ||
3308
11.4k
            (pps->pps_weighted_bipred_flag &&
3309
3.29k
            current->sh_slice_type == VVC_SLICE_TYPE_B))) {
3310
3.29k
            CHECK(FUNC(pred_weight_table) (ctx, rw, sps, pps, ref_pic_lists,
3311
3.29k
                                           current->num_ref_idx_active,
3312
3.29k
                                           &current->sh_pred_weight_table));
3313
3.29k
        }
3314
13.1k
    }
3315
26.2k
    qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
3316
26.2k
    if (!pps->pps_qp_delta_info_in_ph_flag)
3317
26.2k
        se(sh_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
3318
26.0k
           63 - (26 + pps->pps_init_qp_minus26));
3319
26.0k
    if (pps->pps_slice_chroma_qp_offsets_present_flag) {
3320
6.91k
        int8_t off;
3321
3322
6.91k
        se(sh_cb_qp_offset, -12, 12);
3323
6.91k
        off = pps->pps_cb_qp_offset + current->sh_cb_qp_offset;
3324
6.91k
        if (off < -12 || off > 12) {
3325
196
            av_log(ctx->log_ctx, AV_LOG_ERROR,
3326
196
                   "pps_cb_qp_offset + sh_cb_qp_offset (%d) not in range [-12, 12].\n",
3327
196
                   off);
3328
196
            return AVERROR_INVALIDDATA;
3329
196
        }
3330
3331
6.71k
        se(sh_cr_qp_offset, -12, 12);
3332
6.71k
        off = pps->pps_cr_qp_offset + current->sh_cr_qp_offset;
3333
6.71k
        if (off < -12 || off > 12) {
3334
418
            av_log(ctx->log_ctx, AV_LOG_ERROR,
3335
418
                   "pps_cr_qp_offset + sh_cr_qp_offset (%d) not in range [-12, 12].\n",
3336
418
                   off);
3337
418
            return AVERROR_INVALIDDATA;
3338
418
        }
3339
3340
6.29k
        if (sps->sps_joint_cbcr_enabled_flag) {
3341
5.62k
            se(sh_joint_cbcr_qp_offset, -12, 12);
3342
5.62k
            off =
3343
5.62k
                pps->pps_joint_cbcr_qp_offset_value +
3344
5.62k
                current->sh_joint_cbcr_qp_offset;
3345
5.62k
            if (off < -12 || off > 12) {
3346
418
                av_log(ctx->log_ctx, AV_LOG_ERROR,
3347
418
                       "pps_joint_cbcr_qp_offset_value + sh_joint_cbcr_qp_offset (%d)"
3348
418
                       "not in range [-12, 12]. \n", off);
3349
418
                return AVERROR_INVALIDDATA;
3350
418
            }
3351
5.62k
        } else {
3352
670
            infer(sh_joint_cbcr_qp_offset, 0);
3353
670
        }
3354
19.1k
    } else {
3355
19.1k
        infer(sh_cb_qp_offset, 0);
3356
18.9k
        infer(sh_cr_qp_offset, 0);
3357
18.7k
        infer(sh_joint_cbcr_qp_offset, 0);
3358
18.7k
    }
3359
24.2k
    if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
3360
24.2k
        flag(sh_cu_chroma_qp_offset_enabled_flag);
3361
21.5k
    else
3362
21.5k
        infer(sh_cu_chroma_qp_offset_enabled_flag, 0);
3363
24.0k
    if (sps->sps_sao_enabled_flag && !pps->pps_sao_info_in_ph_flag) {
3364
8.15k
        flag(sh_sao_luma_used_flag);
3365
8.15k
        if (sps->sps_chroma_format_idc != 0)
3366
8.15k
            flag(sh_sao_chroma_used_flag);
3367
838
        else
3368
838
            infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3369
15.8k
    } else {
3370
15.8k
        infer(sh_sao_luma_used_flag, ph->ph_sao_luma_enabled_flag);
3371
15.6k
        infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3372
15.6k
    }
3373
3374
23.3k
    if (pps->pps_deblocking_filter_override_enabled_flag &&
3375
6.34k
        !pps->pps_dbf_info_in_ph_flag)
3376
23.3k
        flag(sh_deblocking_params_present_flag);
3377
19.1k
    else
3378
19.1k
        infer(sh_deblocking_params_present_flag, 0);
3379
23.1k
    if (current->sh_deblocking_params_present_flag) {
3380
2.53k
        if (!pps->pps_deblocking_filter_disabled_flag)
3381
2.53k
            flag(sh_deblocking_filter_disabled_flag);
3382
439
        else
3383
439
            infer(sh_deblocking_filter_disabled_flag, 0);
3384
2.33k
        if (!current->sh_deblocking_filter_disabled_flag) {
3385
1.58k
            se(sh_luma_beta_offset_div2, -12, 12);
3386
1.58k
            se(sh_luma_tc_offset_div2, -12, 12);
3387
1.58k
            if (pps->pps_chroma_tool_offsets_present_flag) {
3388
242
                se(sh_cb_beta_offset_div2, -12, 12);
3389
242
                se(sh_cb_tc_offset_div2, -12, 12);
3390
242
                se(sh_cr_beta_offset_div2, -12, 12);
3391
242
                se(sh_cr_tc_offset_div2, -12, 12);
3392
1.34k
            } else {
3393
1.34k
                infer(sh_cb_beta_offset_div2,
3394
1.34k
                      current->sh_luma_beta_offset_div2);
3395
970
                infer(sh_cb_tc_offset_div2, current->sh_luma_tc_offset_div2);
3396
762
                infer(sh_cr_beta_offset_div2,
3397
762
                      current->sh_luma_beta_offset_div2);
3398
538
                infer(sh_cr_tc_offset_div2, current->sh_luma_tc_offset_div2);
3399
538
            }
3400
1.58k
        }
3401
20.6k
    } else {
3402
20.6k
        infer(sh_deblocking_filter_disabled_flag, ph->ph_deblocking_filter_disabled_flag);
3403
20.3k
        if (!current->sh_deblocking_filter_disabled_flag) {
3404
18.4k
            infer(sh_luma_beta_offset_div2, ph->ph_luma_beta_offset_div2);
3405
18.2k
            infer(sh_luma_tc_offset_div2, ph->ph_luma_tc_offset_div2);
3406
17.9k
            infer(sh_cb_beta_offset_div2, ph->ph_cb_beta_offset_div2);
3407
17.7k
            infer(sh_cb_tc_offset_div2, ph->ph_cb_tc_offset_div2);
3408
17.5k
            infer(sh_cr_beta_offset_div2, ph->ph_cr_beta_offset_div2);
3409
17.3k
            infer(sh_cr_tc_offset_div2, ph->ph_cr_tc_offset_div2);
3410
17.3k
        }
3411
20.3k
    }
3412
3413
20.4k
    if (sps->sps_dep_quant_enabled_flag)
3414
20.4k
        flag(sh_dep_quant_used_flag);
3415
7.03k
    else
3416
7.03k
        infer(sh_dep_quant_used_flag, 0);
3417
3418
20.2k
    if (sps->sps_sign_data_hiding_enabled_flag &&
3419
5.17k
        !current->sh_dep_quant_used_flag)
3420
20.2k
        flag(sh_sign_data_hiding_used_flag);
3421
16.4k
    else
3422
16.4k
        infer(sh_sign_data_hiding_used_flag, 0);
3423
3424
20.0k
    if (sps->sps_transform_skip_enabled_flag &&
3425
15.4k
        !current->sh_dep_quant_used_flag &&
3426
9.01k
        !current->sh_sign_data_hiding_used_flag)
3427
20.0k
        flag(sh_ts_residual_coding_disabled_flag);
3428
12.6k
    else
3429
12.6k
        infer(sh_ts_residual_coding_disabled_flag, 0);
3430
3431
19.7k
    if (!current->sh_ts_residual_coding_disabled_flag &&
3432
15.2k
        sps->sps_ts_residual_coding_rice_present_in_sh_flag)
3433
206
        ub(3, sh_ts_residual_coding_rice_idx_minus1);
3434
19.5k
    else
3435
19.5k
        infer(sh_ts_residual_coding_rice_idx_minus1, 0);
3436
3437
19.5k
    if (sps->sps_reverse_last_sig_coeff_enabled_flag)
3438
19.5k
        flag(sh_reverse_last_sig_coeff_flag);
3439
19.1k
    else
3440
19.1k
        infer(sh_reverse_last_sig_coeff_flag, 0);
3441
3442
19.2k
    if (pps->pps_slice_header_extension_present_flag) {
3443
3.33k
        ue(sh_slice_header_extension_length, 0, 256);
3444
8.45k
        for (i = 0; i < current->sh_slice_header_extension_length; i++)
3445
5.11k
            us(8, sh_slice_header_extension_data_byte[i], 0x00, 0xff, 1, i);
3446
3.33k
    }
3447
3448
19.2k
    current->num_entry_points = 0;
3449
19.2k
    if (sps->sps_entry_point_offsets_present_flag) {
3450
17.8k
        uint8_t entropy_sync = sps->sps_entropy_coding_sync_enabled_flag;
3451
17.8k
        int height;
3452
17.8k
        if (pps->pps_rect_slice_flag) {
3453
7.88k
            int width_in_tiles;
3454
7.88k
            int slice_idx = current->sh_slice_address;
3455
17.7k
            for (i = 0; i < current->curr_subpic_idx; i++) {
3456
9.85k
                slice_idx += pps->num_slices_in_subpic[i];
3457
9.85k
            }
3458
3459
7.88k
            if (pps->pps_single_slice_per_subpic_flag) {
3460
5.83k
                const int width_in_ctus = sps->sps_subpic_width_minus1[slice_idx] + 1;
3461
5.83k
                const int subpic_l = sps->sps_subpic_ctu_top_left_x[slice_idx];
3462
5.83k
                const int subpic_r = subpic_l + width_in_ctus;
3463
3464
5.83k
                int ctb_x = 0, tile_x = 0;
3465
9.43k
                for (; ctb_x < subpic_l && tile_x < pps->num_tile_columns; tile_x++)
3466
3.59k
                    ctb_x += pps->col_width_val[tile_x];
3467
3468
5.83k
                width_in_tiles = 0;
3469
20.4k
                for (; ctb_x < subpic_r && tile_x < pps->num_tile_columns; tile_x++) {
3470
14.5k
                    ctb_x += pps->col_width_val[tile_x];
3471
14.5k
                    width_in_tiles++;
3472
14.5k
                }
3473
3474
5.83k
                if (entropy_sync) {
3475
379
                    height = sps->sps_subpic_height_minus1[slice_idx] + 1;
3476
5.46k
                } else {
3477
5.46k
                    const int height_in_ctus = sps->sps_subpic_height_minus1[slice_idx] + 1;
3478
5.46k
                    const int subpic_t = sps->sps_subpic_ctu_top_left_y[slice_idx];
3479
5.46k
                    const int subpic_b = subpic_t + height_in_ctus;
3480
3481
5.46k
                    int ctb_y = 0, tile_y = 0, height_in_tiles;
3482
7.07k
                    for (; ctb_y < subpic_t && tile_y < pps->num_tile_rows; tile_y++)
3483
1.61k
                        ctb_y += pps->row_height_val[tile_y];
3484
3485
5.46k
                    height_in_tiles = 0;
3486
16.3k
                    for (; ctb_y < subpic_b && tile_y < pps->num_tile_rows; tile_y++) {
3487
10.9k
                        ctb_y += pps->row_height_val[tile_y];
3488
10.9k
                        height_in_tiles++;
3489
10.9k
                    }
3490
3491
5.46k
                    height = height_in_tiles;
3492
5.46k
                }
3493
5.83k
            } else {
3494
2.04k
                width_in_tiles =
3495
2.04k
                    pps->pps_slice_width_in_tiles_minus1[slice_idx] + 1;
3496
3497
2.04k
                if (entropy_sync)
3498
198
                    height = pps->slice_height_in_ctus[slice_idx];
3499
1.84k
                else
3500
1.84k
                    height = pps->pps_slice_height_in_tiles_minus1[slice_idx] + 1;
3501
2.04k
            }
3502
3503
7.88k
            current->num_entry_points = width_in_tiles * height;
3504
9.97k
        } else {
3505
9.97k
            int tile_idx;
3506
9.97k
            int tile_y;
3507
9.97k
            for (tile_idx = current->sh_slice_address;
3508
22.2k
                 tile_idx <=
3509
22.2k
                 current->sh_slice_address +
3510
22.2k
                 current->sh_num_tiles_in_slice_minus1; tile_idx++) {
3511
12.2k
                tile_y = tile_idx / pps->num_tile_columns;
3512
12.2k
                height = pps->row_height_val[tile_y];
3513
12.2k
                current->num_entry_points += (entropy_sync ? height : 1);
3514
12.2k
            }
3515
9.97k
        }
3516
17.8k
        current->num_entry_points--;
3517
17.8k
        if (current->num_entry_points > VVC_MAX_ENTRY_POINTS) {
3518
0
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
3519
0
                   "%" PRIu32 ".\n", current->num_entry_points);
3520
0
            return AVERROR_PATCHWELCOME;
3521
0
        }
3522
17.8k
        if (current->num_entry_points > 0) {
3523
4.19k
            ue(sh_entry_offset_len_minus1, 0, 31);
3524
162k
            for (i = 0; i < current->num_entry_points; i++) {
3525
158k
                ubs(current->sh_entry_offset_len_minus1 + 1,
3526
158k
                    sh_entry_point_offset_minus1[i], 1, i);
3527
158k
            }
3528
4.19k
        }
3529
17.8k
    }
3530
19.2k
    CHECK(FUNC(byte_alignment) (ctx, rw));
3531
3532
19.2k
    return 0;
3533
19.2k
}
3534
3535
static int FUNC(sei) (CodedBitstreamContext *ctx, RWContext *rw,
3536
                      H266RawSEI *current, int prefix)
3537
69.2k
{
3538
69.2k
    int err;
3539
3540
69.2k
    if (prefix)
3541
32.9k
        HEADER("Prefix Supplemental Enhancement Information");
3542
36.2k
    else
3543
36.2k
        HEADER("Suffix Supplemental Enhancement Information");
3544
3545
69.2k
    CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header,
3546
69.2k
                                 prefix ? VVC_PREFIX_SEI_NUT
3547
69.2k
                                 : VVC_SUFFIX_SEI_NUT));
3548
3549
68.5k
    CHECK(FUNC_SEI(message_list) (ctx, rw, &current->message_list, prefix));
3550
3551
16.4k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
3552
3553
16.4k
    return 0;
3554
16.4k
}
cbs_h266.c:cbs_h266_read_sei
Line
Count
Source
3537
65.5k
{
3538
65.5k
    int err;
3539
3540
65.5k
    if (prefix)
3541
31.1k
        HEADER("Prefix Supplemental Enhancement Information");
3542
34.3k
    else
3543
34.3k
        HEADER("Suffix Supplemental Enhancement Information");
3544
3545
65.5k
    CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header,
3546
65.5k
                                 prefix ? VVC_PREFIX_SEI_NUT
3547
65.5k
                                 : VVC_SUFFIX_SEI_NUT));
3548
3549
64.8k
    CHECK(FUNC_SEI(message_list) (ctx, rw, &current->message_list, prefix));
3550
3551
12.7k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
3552
3553
12.7k
    return 0;
3554
12.7k
}
cbs_h266.c:cbs_h266_write_sei
Line
Count
Source
3537
3.70k
{
3538
3.70k
    int err;
3539
3540
3.70k
    if (prefix)
3541
1.82k
        HEADER("Prefix Supplemental Enhancement Information");
3542
1.88k
    else
3543
1.88k
        HEADER("Suffix Supplemental Enhancement Information");
3544
3545
3.70k
    CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header,
3546
3.70k
                                 prefix ? VVC_PREFIX_SEI_NUT
3547
3.70k
                                 : VVC_SUFFIX_SEI_NUT));
3548
3549
3.70k
    CHECK(FUNC_SEI(message_list) (ctx, rw, &current->message_list, prefix));
3550
3551
3.70k
    CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
3552
3553
3.70k
    return 0;
3554
3.70k
}