/src/ffmpeg/libavcodec/cbs_h264_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, RWContext *rw) |
20 | 234k | { |
21 | 234k | int err; |
22 | | |
23 | 234k | fixed(1, rbsp_stop_one_bit, 1); |
24 | 632k | while (byte_alignment(rw) != 0) |
25 | 463k | fixed(1, rbsp_alignment_zero_bit, 0); |
26 | | |
27 | 168k | return 0; |
28 | 195k | } cbs_h264.c:cbs_h264_read_rbsp_trailing_bits Line | Count | Source | 20 | 189k | { | 21 | 189k | int err; | 22 | | | 23 | 189k | fixed(1, rbsp_stop_one_bit, 1); | 24 | 448k | while (byte_alignment(rw) != 0) | 25 | 325k | fixed(1, rbsp_alignment_zero_bit, 0); | 26 | | | 27 | 122k | return 0; | 28 | 149k | } |
cbs_h264.c:cbs_h264_write_rbsp_trailing_bits Line | Count | Source | 20 | 45.5k | { | 21 | 45.5k | int err; | 22 | | | 23 | 45.5k | fixed(1, rbsp_stop_one_bit, 1); | 24 | 183k | while (byte_alignment(rw) != 0) | 25 | 138k | fixed(1, rbsp_alignment_zero_bit, 0); | 26 | | | 27 | 45.5k | return 0; | 28 | 45.5k | } |
|
29 | | |
30 | | static int FUNC(nal_unit_header)(CodedBitstreamContext *ctx, RWContext *rw, |
31 | | H264RawNALUnitHeader *current, |
32 | | uint32_t valid_type_mask) |
33 | 4.14M | { |
34 | 4.14M | int err; |
35 | | |
36 | 4.14M | fixed(1, forbidden_zero_bit, 0); |
37 | 4.14M | ub(2, nal_ref_idc); |
38 | 4.14M | ub(5, nal_unit_type); |
39 | | |
40 | 4.14M | if (!(1 << current->nal_unit_type & valid_type_mask)) { |
41 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid NAL unit type %d.\n", |
42 | 0 | current->nal_unit_type); |
43 | 0 | return AVERROR_INVALIDDATA; |
44 | 0 | } |
45 | | |
46 | 4.14M | if (current->nal_unit_type == 14 || |
47 | 4.14M | current->nal_unit_type == 20 || |
48 | 4.14M | current->nal_unit_type == 21) { |
49 | 0 | if (current->nal_unit_type != 21) |
50 | 0 | flag(svc_extension_flag); |
51 | 0 | else |
52 | 0 | flag(avc_3d_extension_flag); |
53 | | |
54 | 0 | if (current->svc_extension_flag) { |
55 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "SVC not supported.\n"); |
56 | 0 | return AVERROR_PATCHWELCOME; |
57 | |
|
58 | 0 | } else if (current->avc_3d_extension_flag) { |
59 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "3DAVC not supported.\n"); |
60 | 0 | return AVERROR_PATCHWELCOME; |
61 | |
|
62 | 0 | } else { |
63 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC not supported.\n"); |
64 | 0 | return AVERROR_PATCHWELCOME; |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | 4.14M | return 0; |
69 | 4.14M | } cbs_h264.c:cbs_h264_read_nal_unit_header Line | Count | Source | 33 | 2.74M | { | 34 | 2.74M | int err; | 35 | | | 36 | 2.74M | fixed(1, forbidden_zero_bit, 0); | 37 | 2.74M | ub(2, nal_ref_idc); | 38 | 2.74M | ub(5, nal_unit_type); | 39 | | | 40 | 2.74M | if (!(1 << current->nal_unit_type & valid_type_mask)) { | 41 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid NAL unit type %d.\n", | 42 | 0 | current->nal_unit_type); | 43 | 0 | return AVERROR_INVALIDDATA; | 44 | 0 | } | 45 | | | 46 | 2.74M | if (current->nal_unit_type == 14 || | 47 | 2.74M | current->nal_unit_type == 20 || | 48 | 2.74M | current->nal_unit_type == 21) { | 49 | 0 | if (current->nal_unit_type != 21) | 50 | 0 | flag(svc_extension_flag); | 51 | 0 | else | 52 | 0 | flag(avc_3d_extension_flag); | 53 | | | 54 | 0 | if (current->svc_extension_flag) { | 55 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "SVC not supported.\n"); | 56 | 0 | return AVERROR_PATCHWELCOME; | 57 | |
| 58 | 0 | } else if (current->avc_3d_extension_flag) { | 59 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "3DAVC not supported.\n"); | 60 | 0 | return AVERROR_PATCHWELCOME; | 61 | |
| 62 | 0 | } else { | 63 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC not supported.\n"); | 64 | 0 | return AVERROR_PATCHWELCOME; | 65 | 0 | } | 66 | 0 | } | 67 | | | 68 | 2.74M | return 0; | 69 | 2.74M | } |
cbs_h264.c:cbs_h264_write_nal_unit_header Line | Count | Source | 33 | 1.39M | { | 34 | 1.39M | int err; | 35 | | | 36 | 1.39M | fixed(1, forbidden_zero_bit, 0); | 37 | 1.39M | ub(2, nal_ref_idc); | 38 | 1.39M | ub(5, nal_unit_type); | 39 | | | 40 | 1.39M | if (!(1 << current->nal_unit_type & valid_type_mask)) { | 41 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid NAL unit type %d.\n", | 42 | 0 | current->nal_unit_type); | 43 | 0 | return AVERROR_INVALIDDATA; | 44 | 0 | } | 45 | | | 46 | 1.39M | if (current->nal_unit_type == 14 || | 47 | 1.39M | current->nal_unit_type == 20 || | 48 | 1.39M | current->nal_unit_type == 21) { | 49 | 0 | if (current->nal_unit_type != 21) | 50 | 0 | flag(svc_extension_flag); | 51 | 0 | else | 52 | 0 | flag(avc_3d_extension_flag); | 53 | | | 54 | 0 | if (current->svc_extension_flag) { | 55 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "SVC not supported.\n"); | 56 | 0 | return AVERROR_PATCHWELCOME; | 57 | |
| 58 | 0 | } else if (current->avc_3d_extension_flag) { | 59 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "3DAVC not supported.\n"); | 60 | 0 | return AVERROR_PATCHWELCOME; | 61 | |
| 62 | 0 | } else { | 63 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC not supported.\n"); | 64 | 0 | return AVERROR_PATCHWELCOME; | 65 | 0 | } | 66 | 0 | } | 67 | | | 68 | 1.39M | return 0; | 69 | 1.39M | } |
|
70 | | |
71 | | static int FUNC(scaling_list)(CodedBitstreamContext *ctx, RWContext *rw, |
72 | | H264RawScalingList *current, |
73 | | int size_of_scaling_list) |
74 | 205k | { |
75 | 205k | int err, i, scale; |
76 | | |
77 | 205k | scale = 8; |
78 | 4.17M | for (i = 0; i < size_of_scaling_list; i++) { |
79 | 4.00M | ses(delta_scale[i], -128, +127, 1, i); |
80 | 3.98M | scale = (scale + current->delta_scale[i] + 256) % 256; |
81 | 3.98M | if (scale == 0) |
82 | 13.1k | break; |
83 | 3.98M | } |
84 | | |
85 | 184k | return 0; |
86 | 205k | } cbs_h264.c:cbs_h264_read_scaling_list Line | Count | Source | 74 | 183k | { | 75 | 183k | int err, i, scale; | 76 | | | 77 | 183k | scale = 8; | 78 | 3.68M | for (i = 0; i < size_of_scaling_list; i++) { | 79 | 3.52M | ses(delta_scale[i], -128, +127, 1, i); | 80 | 3.50M | scale = (scale + current->delta_scale[i] + 256) % 256; | 81 | 3.50M | if (scale == 0) | 82 | 11.3k | break; | 83 | 3.50M | } | 84 | | | 85 | 163k | return 0; | 86 | 183k | } |
cbs_h264.c:cbs_h264_write_scaling_list Line | Count | Source | 74 | 21.7k | { | 75 | 21.7k | int err, i, scale; | 76 | | | 77 | 21.7k | scale = 8; | 78 | 491k | for (i = 0; i < size_of_scaling_list; i++) { | 79 | 471k | ses(delta_scale[i], -128, +127, 1, i); | 80 | 471k | scale = (scale + current->delta_scale[i] + 256) % 256; | 81 | 471k | if (scale == 0) | 82 | 1.81k | break; | 83 | 471k | } | 84 | | | 85 | 21.7k | return 0; | 86 | 21.7k | } |
|
87 | | |
88 | | static int FUNC(hrd_parameters)(CodedBitstreamContext *ctx, RWContext *rw, |
89 | | H264RawHRD *current) |
90 | 93.9k | { |
91 | 93.9k | int err, i; |
92 | | |
93 | 93.9k | ue(cpb_cnt_minus1, 0, 31); |
94 | 89.8k | ub(4, bit_rate_scale); |
95 | 87.9k | ub(4, cpb_size_scale); |
96 | | |
97 | 362k | for (i = 0; i <= current->cpb_cnt_minus1; i++) { |
98 | 288k | ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i); |
99 | 284k | ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i); |
100 | 280k | flags(cbr_flag[i], 1, i); |
101 | 280k | } |
102 | | |
103 | 74.6k | ub(5, initial_cpb_removal_delay_length_minus1); |
104 | 72.2k | ub(5, cpb_removal_delay_length_minus1); |
105 | 69.9k | ub(5, dpb_output_delay_length_minus1); |
106 | 69.0k | ub(5, time_offset_length); |
107 | | |
108 | 67.5k | return 0; |
109 | 69.0k | } cbs_h264.c:cbs_h264_read_hrd_parameters Line | Count | Source | 90 | 86.2k | { | 91 | 86.2k | int err, i; | 92 | | | 93 | 86.2k | ue(cpb_cnt_minus1, 0, 31); | 94 | 82.1k | ub(4, bit_rate_scale); | 95 | 80.2k | ub(4, cpb_size_scale); | 96 | | | 97 | 335k | for (i = 0; i <= current->cpb_cnt_minus1; i++) { | 98 | 268k | ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i); | 99 | 264k | ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i); | 100 | 260k | flags(cbr_flag[i], 1, i); | 101 | 260k | } | 102 | | | 103 | 66.9k | ub(5, initial_cpb_removal_delay_length_minus1); | 104 | 64.5k | ub(5, cpb_removal_delay_length_minus1); | 105 | 62.2k | ub(5, dpb_output_delay_length_minus1); | 106 | 61.3k | ub(5, time_offset_length); | 107 | | | 108 | 59.8k | return 0; | 109 | 61.3k | } |
cbs_h264.c:cbs_h264_write_hrd_parameters Line | Count | Source | 90 | 7.70k | { | 91 | 7.70k | int err, i; | 92 | | | 93 | 7.70k | ue(cpb_cnt_minus1, 0, 31); | 94 | 7.70k | ub(4, bit_rate_scale); | 95 | 7.70k | ub(4, cpb_size_scale); | 96 | | | 97 | 27.5k | for (i = 0; i <= current->cpb_cnt_minus1; i++) { | 98 | 19.8k | ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i); | 99 | 19.8k | ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i); | 100 | 19.8k | flags(cbr_flag[i], 1, i); | 101 | 19.8k | } | 102 | | | 103 | 7.70k | ub(5, initial_cpb_removal_delay_length_minus1); | 104 | 7.70k | ub(5, cpb_removal_delay_length_minus1); | 105 | 7.70k | ub(5, dpb_output_delay_length_minus1); | 106 | 7.70k | ub(5, time_offset_length); | 107 | | | 108 | 7.70k | return 0; | 109 | 7.70k | } |
|
110 | | |
111 | | static int FUNC(vui_parameters)(CodedBitstreamContext *ctx, RWContext *rw, |
112 | | H264RawVUI *current, H264RawSPS *sps) |
113 | 151k | { |
114 | 151k | int err; |
115 | | |
116 | 151k | flag(aspect_ratio_info_present_flag); |
117 | 150k | if (current->aspect_ratio_info_present_flag) { |
118 | 93.4k | ub(8, aspect_ratio_idc); |
119 | 91.7k | if (current->aspect_ratio_idc == 255) { |
120 | 43.5k | ub(16, sar_width); |
121 | 42.2k | ub(16, sar_height); |
122 | 42.2k | } |
123 | 91.7k | } else { |
124 | 57.3k | infer(aspect_ratio_idc, 0); |
125 | 57.3k | } |
126 | | |
127 | 146k | flag(overscan_info_present_flag); |
128 | 145k | if (current->overscan_info_present_flag) |
129 | 145k | flag(overscan_appropriate_flag); |
130 | | |
131 | 143k | flag(video_signal_type_present_flag); |
132 | 141k | if (current->video_signal_type_present_flag) { |
133 | 84.9k | ub(3, video_format); |
134 | 81.8k | flag(video_full_range_flag); |
135 | 80.9k | flag(colour_description_present_flag); |
136 | 80.0k | if (current->colour_description_present_flag) { |
137 | 53.0k | ub(8, colour_primaries); |
138 | 51.7k | ub(8, transfer_characteristics); |
139 | 49.7k | ub(8, matrix_coefficients); |
140 | 49.7k | } else { |
141 | 26.9k | infer(colour_primaries, 2); |
142 | 26.9k | infer(transfer_characteristics, 2); |
143 | 26.9k | infer(matrix_coefficients, 2); |
144 | 2.11k | } |
145 | 80.0k | } else { |
146 | 56.4k | infer(video_format, 5); |
147 | 56.4k | infer(video_full_range_flag, 0); |
148 | 56.4k | infer(colour_primaries, 2); |
149 | 56.4k | infer(transfer_characteristics, 2); |
150 | 56.4k | infer(matrix_coefficients, 2); |
151 | 3.72k | } |
152 | | |
153 | 132k | flag(chroma_loc_info_present_flag); |
154 | 130k | if (current->chroma_loc_info_present_flag) { |
155 | 53.0k | ue(chroma_sample_loc_type_top_field, 0, 5); |
156 | 49.2k | ue(chroma_sample_loc_type_bottom_field, 0, 5); |
157 | 77.7k | } else { |
158 | 77.7k | infer(chroma_sample_loc_type_top_field, 0); |
159 | 77.7k | infer(chroma_sample_loc_type_bottom_field, 0); |
160 | 5.92k | } |
161 | | |
162 | 121k | flag(timing_info_present_flag); |
163 | 118k | if (current->timing_info_present_flag) { |
164 | 45.8k | u(32, num_units_in_tick, 1, UINT32_MAX); |
165 | 42.7k | u(32, time_scale, 1, UINT32_MAX); |
166 | 40.0k | flag(fixed_frame_rate_flag); |
167 | 72.4k | } else { |
168 | 72.4k | infer(fixed_frame_rate_flag, 0); |
169 | 72.4k | } |
170 | | |
171 | 110k | flag(nal_hrd_parameters_present_flag); |
172 | 108k | if (current->nal_hrd_parameters_present_flag) |
173 | 53.1k | CHECK(FUNC(hrd_parameters)(ctx, rw, ¤t->nal_hrd_parameters)); |
174 | | |
175 | 92.4k | flag(vcl_hrd_parameters_present_flag); |
176 | 91.7k | if (current->vcl_hrd_parameters_present_flag) |
177 | 40.7k | CHECK(FUNC(hrd_parameters)(ctx, rw, ¤t->vcl_hrd_parameters)); |
178 | | |
179 | 81.2k | if (current->nal_hrd_parameters_present_flag || |
180 | 49.8k | current->vcl_hrd_parameters_present_flag) |
181 | 81.2k | flag(low_delay_hrd_flag); |
182 | 33.8k | else |
183 | 33.8k | infer(low_delay_hrd_flag, 1 - current->fixed_frame_rate_flag); |
184 | | |
185 | 79.2k | flag(pic_struct_present_flag); |
186 | | |
187 | 77.4k | flag(bitstream_restriction_flag); |
188 | 75.9k | if (current->bitstream_restriction_flag) { |
189 | 36.9k | flag(motion_vectors_over_pic_boundaries_flag); |
190 | 36.1k | ue(max_bytes_per_pic_denom, 0, 16); |
191 | 34.1k | ue(max_bits_per_mb_denom, 0, 16); |
192 | | // The current version of the standard constrains this to be in |
193 | | // [0,15], but older versions allow 16. |
194 | 28.8k | ue(log2_max_mv_length_horizontal, 0, 16); |
195 | 26.7k | ue(log2_max_mv_length_vertical, 0, 16); |
196 | 23.5k | ue(max_num_reorder_frames, 0, H264_MAX_DPB_FRAMES); |
197 | 21.5k | ue(max_dec_frame_buffering, 0, H264_MAX_DPB_FRAMES); |
198 | 38.9k | } else { |
199 | 38.9k | infer(motion_vectors_over_pic_boundaries_flag, 1); |
200 | 38.9k | infer(max_bytes_per_pic_denom, 2); |
201 | 38.9k | infer(max_bits_per_mb_denom, 1); |
202 | 38.9k | infer(log2_max_mv_length_horizontal, 15); |
203 | 38.9k | infer(log2_max_mv_length_vertical, 15); |
204 | | |
205 | 38.9k | if ((sps->profile_idc == 44 || sps->profile_idc == 86 || |
206 | 34.2k | sps->profile_idc == 100 || sps->profile_idc == 110 || |
207 | 27.3k | sps->profile_idc == 122 || sps->profile_idc == 244) && |
208 | 16.1k | sps->constraint_set3_flag) { |
209 | 6.29k | infer(max_num_reorder_frames, 0); |
210 | 6.29k | infer(max_dec_frame_buffering, 0); |
211 | 32.6k | } else { |
212 | 32.6k | infer(max_num_reorder_frames, H264_MAX_DPB_FRAMES); |
213 | 32.6k | infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES); |
214 | 5.29k | } |
215 | 6.66k | } |
216 | | |
217 | 59.3k | return 0; |
218 | 75.9k | } cbs_h264.c:cbs_h264_read_vui_parameters Line | Count | Source | 113 | 142k | { | 114 | 142k | int err; | 115 | | | 116 | 142k | flag(aspect_ratio_info_present_flag); | 117 | 141k | if (current->aspect_ratio_info_present_flag) { | 118 | 88.3k | ub(8, aspect_ratio_idc); | 119 | 86.6k | if (current->aspect_ratio_idc == 255) { | 120 | 40.4k | ub(16, sar_width); | 121 | 39.1k | ub(16, sar_height); | 122 | 39.1k | } | 123 | 86.6k | } else { | 124 | 52.8k | infer(aspect_ratio_idc, 0); | 125 | 52.8k | } | 126 | | | 127 | 136k | flag(overscan_info_present_flag); | 128 | 135k | if (current->overscan_info_present_flag) | 129 | 135k | flag(overscan_appropriate_flag); | 130 | | | 131 | 133k | flag(video_signal_type_present_flag); | 132 | 131k | if (current->video_signal_type_present_flag) { | 133 | 79.0k | ub(3, video_format); | 134 | 75.9k | flag(video_full_range_flag); | 135 | 75.0k | flag(colour_description_present_flag); | 136 | 74.1k | if (current->colour_description_present_flag) { | 137 | 49.3k | ub(8, colour_primaries); | 138 | 48.0k | ub(8, transfer_characteristics); | 139 | 46.0k | ub(8, matrix_coefficients); | 140 | 46.0k | } else { | 141 | 24.8k | infer(colour_primaries, 2); | 142 | 24.8k | infer(transfer_characteristics, 2); | 143 | 24.8k | infer(matrix_coefficients, 2); | 144 | 24.8k | } | 145 | 74.1k | } else { | 146 | 52.7k | infer(video_format, 5); | 147 | 52.7k | infer(video_full_range_flag, 0); | 148 | 52.7k | infer(colour_primaries, 2); | 149 | 52.7k | infer(transfer_characteristics, 2); | 150 | 52.7k | infer(matrix_coefficients, 2); | 151 | 52.7k | } | 152 | | | 153 | 122k | flag(chroma_loc_info_present_flag); | 154 | 121k | if (current->chroma_loc_info_present_flag) { | 155 | 49.4k | ue(chroma_sample_loc_type_top_field, 0, 5); | 156 | 45.5k | ue(chroma_sample_loc_type_bottom_field, 0, 5); | 157 | 71.8k | } else { | 158 | 71.8k | infer(chroma_sample_loc_type_top_field, 0); | 159 | 71.8k | infer(chroma_sample_loc_type_bottom_field, 0); | 160 | 71.8k | } | 161 | | | 162 | 112k | flag(timing_info_present_flag); | 163 | 108k | if (current->timing_info_present_flag) { | 164 | 43.1k | u(32, num_units_in_tick, 1, UINT32_MAX); | 165 | 39.9k | u(32, time_scale, 1, UINT32_MAX); | 166 | 37.3k | flag(fixed_frame_rate_flag); | 167 | 65.6k | } else { | 168 | 65.6k | infer(fixed_frame_rate_flag, 0); | 169 | 65.6k | } | 170 | | | 171 | 100k | flag(nal_hrd_parameters_present_flag); | 172 | 98.8k | if (current->nal_hrd_parameters_present_flag) | 173 | 48.5k | CHECK(FUNC(hrd_parameters)(ctx, rw, ¤t->nal_hrd_parameters)); | 174 | | | 175 | 82.8k | flag(vcl_hrd_parameters_present_flag); | 176 | 82.1k | if (current->vcl_hrd_parameters_present_flag) | 177 | 37.6k | CHECK(FUNC(hrd_parameters)(ctx, rw, ¤t->vcl_hrd_parameters)); | 178 | | | 179 | 71.6k | if (current->nal_hrd_parameters_present_flag || | 180 | 44.8k | current->vcl_hrd_parameters_present_flag) | 181 | 71.6k | flag(low_delay_hrd_flag); | 182 | 30.0k | else | 183 | 30.0k | infer(low_delay_hrd_flag, 1 - current->fixed_frame_rate_flag); | 184 | | | 185 | 69.6k | flag(pic_struct_present_flag); | 186 | | | 187 | 67.8k | flag(bitstream_restriction_flag); | 188 | 66.3k | if (current->bitstream_restriction_flag) { | 189 | 34.0k | flag(motion_vectors_over_pic_boundaries_flag); | 190 | 33.1k | ue(max_bytes_per_pic_denom, 0, 16); | 191 | 31.2k | ue(max_bits_per_mb_denom, 0, 16); | 192 | | // The current version of the standard constrains this to be in | 193 | | // [0,15], but older versions allow 16. | 194 | 25.9k | ue(log2_max_mv_length_horizontal, 0, 16); | 195 | 23.8k | ue(log2_max_mv_length_vertical, 0, 16); | 196 | 20.6k | ue(max_num_reorder_frames, 0, H264_MAX_DPB_FRAMES); | 197 | 18.6k | ue(max_dec_frame_buffering, 0, H264_MAX_DPB_FRAMES); | 198 | 32.3k | } else { | 199 | 32.3k | infer(motion_vectors_over_pic_boundaries_flag, 1); | 200 | 32.3k | infer(max_bytes_per_pic_denom, 2); | 201 | 32.3k | infer(max_bits_per_mb_denom, 1); | 202 | 32.3k | infer(log2_max_mv_length_horizontal, 15); | 203 | 32.3k | infer(log2_max_mv_length_vertical, 15); | 204 | | | 205 | 32.3k | if ((sps->profile_idc == 44 || sps->profile_idc == 86 || | 206 | 28.6k | sps->profile_idc == 100 || sps->profile_idc == 110 || | 207 | 22.9k | sps->profile_idc == 122 || sps->profile_idc == 244) && | 208 | 12.6k | sps->constraint_set3_flag) { | 209 | 4.91k | infer(max_num_reorder_frames, 0); | 210 | 4.91k | infer(max_dec_frame_buffering, 0); | 211 | 27.3k | } else { | 212 | 27.3k | infer(max_num_reorder_frames, H264_MAX_DPB_FRAMES); | 213 | 27.3k | infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES); | 214 | 27.3k | } | 215 | 32.3k | } | 216 | | | 217 | 49.8k | return 0; | 218 | 66.3k | } |
cbs_h264.c:cbs_h264_write_vui_parameters Line | Count | Source | 113 | 9.58k | { | 114 | 9.58k | int err; | 115 | | | 116 | 9.58k | flag(aspect_ratio_info_present_flag); | 117 | 9.58k | if (current->aspect_ratio_info_present_flag) { | 118 | 5.05k | ub(8, aspect_ratio_idc); | 119 | 5.05k | if (current->aspect_ratio_idc == 255) { | 120 | 3.11k | ub(16, sar_width); | 121 | 3.11k | ub(16, sar_height); | 122 | 3.11k | } | 123 | 5.05k | } else { | 124 | 4.52k | infer(aspect_ratio_idc, 0); | 125 | 4.52k | } | 126 | | | 127 | 9.58k | flag(overscan_info_present_flag); | 128 | 9.58k | if (current->overscan_info_present_flag) | 129 | 9.58k | flag(overscan_appropriate_flag); | 130 | | | 131 | 9.58k | flag(video_signal_type_present_flag); | 132 | 9.58k | if (current->video_signal_type_present_flag) { | 133 | 5.85k | ub(3, video_format); | 134 | 5.85k | flag(video_full_range_flag); | 135 | 5.85k | flag(colour_description_present_flag); | 136 | 5.85k | if (current->colour_description_present_flag) { | 137 | 3.74k | ub(8, colour_primaries); | 138 | 3.74k | ub(8, transfer_characteristics); | 139 | 3.74k | ub(8, matrix_coefficients); | 140 | 3.74k | } else { | 141 | 2.11k | infer(colour_primaries, 2); | 142 | 2.11k | infer(transfer_characteristics, 2); | 143 | 2.11k | infer(matrix_coefficients, 2); | 144 | 2.11k | } | 145 | 5.85k | } else { | 146 | 3.72k | infer(video_format, 5); | 147 | 3.72k | infer(video_full_range_flag, 0); | 148 | 3.72k | infer(colour_primaries, 2); | 149 | 3.72k | infer(transfer_characteristics, 2); | 150 | 3.72k | infer(matrix_coefficients, 2); | 151 | 3.72k | } | 152 | | | 153 | 9.58k | flag(chroma_loc_info_present_flag); | 154 | 9.58k | if (current->chroma_loc_info_present_flag) { | 155 | 3.65k | ue(chroma_sample_loc_type_top_field, 0, 5); | 156 | 3.65k | ue(chroma_sample_loc_type_bottom_field, 0, 5); | 157 | 5.92k | } else { | 158 | 5.92k | infer(chroma_sample_loc_type_top_field, 0); | 159 | 5.92k | infer(chroma_sample_loc_type_bottom_field, 0); | 160 | 5.92k | } | 161 | | | 162 | 9.58k | flag(timing_info_present_flag); | 163 | 9.58k | if (current->timing_info_present_flag) { | 164 | 2.71k | u(32, num_units_in_tick, 1, UINT32_MAX); | 165 | 2.71k | u(32, time_scale, 1, UINT32_MAX); | 166 | 2.71k | flag(fixed_frame_rate_flag); | 167 | 6.86k | } else { | 168 | 6.86k | infer(fixed_frame_rate_flag, 0); | 169 | 6.86k | } | 170 | | | 171 | 9.58k | flag(nal_hrd_parameters_present_flag); | 172 | 9.58k | if (current->nal_hrd_parameters_present_flag) | 173 | 4.63k | CHECK(FUNC(hrd_parameters)(ctx, rw, ¤t->nal_hrd_parameters)); | 174 | | | 175 | 9.58k | flag(vcl_hrd_parameters_present_flag); | 176 | 9.58k | if (current->vcl_hrd_parameters_present_flag) | 177 | 3.07k | CHECK(FUNC(hrd_parameters)(ctx, rw, ¤t->vcl_hrd_parameters)); | 178 | | | 179 | 9.58k | if (current->nal_hrd_parameters_present_flag || | 180 | 4.94k | current->vcl_hrd_parameters_present_flag) | 181 | 9.58k | flag(low_delay_hrd_flag); | 182 | 3.78k | else | 183 | 3.78k | infer(low_delay_hrd_flag, 1 - current->fixed_frame_rate_flag); | 184 | | | 185 | 9.58k | flag(pic_struct_present_flag); | 186 | | | 187 | 9.58k | flag(bitstream_restriction_flag); | 188 | 9.58k | if (current->bitstream_restriction_flag) { | 189 | 2.91k | flag(motion_vectors_over_pic_boundaries_flag); | 190 | 2.91k | ue(max_bytes_per_pic_denom, 0, 16); | 191 | 2.91k | ue(max_bits_per_mb_denom, 0, 16); | 192 | | // The current version of the standard constrains this to be in | 193 | | // [0,15], but older versions allow 16. | 194 | 2.91k | ue(log2_max_mv_length_horizontal, 0, 16); | 195 | 2.91k | ue(log2_max_mv_length_vertical, 0, 16); | 196 | 2.91k | ue(max_num_reorder_frames, 0, H264_MAX_DPB_FRAMES); | 197 | 2.91k | ue(max_dec_frame_buffering, 0, H264_MAX_DPB_FRAMES); | 198 | 6.66k | } else { | 199 | 6.66k | infer(motion_vectors_over_pic_boundaries_flag, 1); | 200 | 6.66k | infer(max_bytes_per_pic_denom, 2); | 201 | 6.66k | infer(max_bits_per_mb_denom, 1); | 202 | 6.66k | infer(log2_max_mv_length_horizontal, 15); | 203 | 6.66k | infer(log2_max_mv_length_vertical, 15); | 204 | | | 205 | 6.66k | if ((sps->profile_idc == 44 || sps->profile_idc == 86 || | 206 | 5.67k | sps->profile_idc == 100 || sps->profile_idc == 110 || | 207 | 4.39k | sps->profile_idc == 122 || sps->profile_idc == 244) && | 208 | 3.46k | sps->constraint_set3_flag) { | 209 | 1.37k | infer(max_num_reorder_frames, 0); | 210 | 1.37k | infer(max_dec_frame_buffering, 0); | 211 | 5.29k | } else { | 212 | 5.29k | infer(max_num_reorder_frames, H264_MAX_DPB_FRAMES); | 213 | 5.29k | infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES); | 214 | 5.29k | } | 215 | 6.66k | } | 216 | | | 217 | 9.58k | return 0; | 218 | 9.58k | } |
|
219 | | |
220 | | static int FUNC(vui_parameters_default)(CodedBitstreamContext *ctx, |
221 | | RWContext *rw, H264RawVUI *current, |
222 | | H264RawSPS *sps) |
223 | 55.0k | { |
224 | 55.0k | infer(aspect_ratio_idc, 0); |
225 | | |
226 | 55.0k | infer(video_format, 5); |
227 | 55.0k | infer(video_full_range_flag, 0); |
228 | 55.0k | infer(colour_primaries, 2); |
229 | 55.0k | infer(transfer_characteristics, 2); |
230 | 55.0k | infer(matrix_coefficients, 2); |
231 | | |
232 | 55.0k | infer(chroma_sample_loc_type_top_field, 0); |
233 | 55.0k | infer(chroma_sample_loc_type_bottom_field, 0); |
234 | | |
235 | 55.0k | infer(fixed_frame_rate_flag, 0); |
236 | 55.0k | infer(low_delay_hrd_flag, 1); |
237 | | |
238 | 55.0k | infer(pic_struct_present_flag, 0); |
239 | | |
240 | 55.0k | infer(motion_vectors_over_pic_boundaries_flag, 1); |
241 | 55.0k | infer(max_bytes_per_pic_denom, 2); |
242 | 55.0k | infer(max_bits_per_mb_denom, 1); |
243 | 55.0k | infer(log2_max_mv_length_horizontal, 15); |
244 | 55.0k | infer(log2_max_mv_length_vertical, 15); |
245 | | |
246 | 55.0k | if ((sps->profile_idc == 44 || sps->profile_idc == 86 || |
247 | 51.2k | sps->profile_idc == 100 || sps->profile_idc == 110 || |
248 | 46.0k | sps->profile_idc == 122 || sps->profile_idc == 244) && |
249 | 13.8k | sps->constraint_set3_flag) { |
250 | 6.74k | infer(max_num_reorder_frames, 0); |
251 | 6.74k | infer(max_dec_frame_buffering, 0); |
252 | 48.2k | } else { |
253 | 48.2k | infer(max_num_reorder_frames, H264_MAX_DPB_FRAMES); |
254 | 48.2k | infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES); |
255 | 6.95k | } |
256 | | |
257 | 8.23k | return 0; |
258 | 8.23k | } cbs_h264.c:cbs_h264_read_vui_parameters_default Line | Count | Source | 223 | 46.8k | { | 224 | 46.8k | infer(aspect_ratio_idc, 0); | 225 | | | 226 | 46.8k | infer(video_format, 5); | 227 | 46.8k | infer(video_full_range_flag, 0); | 228 | 46.8k | infer(colour_primaries, 2); | 229 | 46.8k | infer(transfer_characteristics, 2); | 230 | 46.8k | infer(matrix_coefficients, 2); | 231 | | | 232 | 46.8k | infer(chroma_sample_loc_type_top_field, 0); | 233 | 46.8k | infer(chroma_sample_loc_type_bottom_field, 0); | 234 | | | 235 | 46.8k | infer(fixed_frame_rate_flag, 0); | 236 | 46.8k | infer(low_delay_hrd_flag, 1); | 237 | | | 238 | 46.8k | infer(pic_struct_present_flag, 0); | 239 | | | 240 | 46.8k | infer(motion_vectors_over_pic_boundaries_flag, 1); | 241 | 46.8k | infer(max_bytes_per_pic_denom, 2); | 242 | 46.8k | infer(max_bits_per_mb_denom, 1); | 243 | 46.8k | infer(log2_max_mv_length_horizontal, 15); | 244 | 46.8k | infer(log2_max_mv_length_vertical, 15); | 245 | | | 246 | 46.8k | if ((sps->profile_idc == 44 || sps->profile_idc == 86 || | 247 | 43.9k | sps->profile_idc == 100 || sps->profile_idc == 110 || | 248 | 39.7k | sps->profile_idc == 122 || sps->profile_idc == 244) && | 249 | 10.8k | sps->constraint_set3_flag) { | 250 | 5.46k | infer(max_num_reorder_frames, 0); | 251 | 5.46k | infer(max_dec_frame_buffering, 0); | 252 | 41.3k | } else { | 253 | 41.3k | infer(max_num_reorder_frames, H264_MAX_DPB_FRAMES); | 254 | 41.3k | infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES); | 255 | 41.3k | } | 256 | | | 257 | 46.8k | return 0; | 258 | 46.8k | } |
cbs_h264.c:cbs_h264_write_vui_parameters_default Line | Count | Source | 223 | 8.23k | { | 224 | 8.23k | infer(aspect_ratio_idc, 0); | 225 | | | 226 | 8.23k | infer(video_format, 5); | 227 | 8.23k | infer(video_full_range_flag, 0); | 228 | 8.23k | infer(colour_primaries, 2); | 229 | 8.23k | infer(transfer_characteristics, 2); | 230 | 8.23k | infer(matrix_coefficients, 2); | 231 | | | 232 | 8.23k | infer(chroma_sample_loc_type_top_field, 0); | 233 | 8.23k | infer(chroma_sample_loc_type_bottom_field, 0); | 234 | | | 235 | 8.23k | infer(fixed_frame_rate_flag, 0); | 236 | 8.23k | infer(low_delay_hrd_flag, 1); | 237 | | | 238 | 8.23k | infer(pic_struct_present_flag, 0); | 239 | | | 240 | 8.23k | infer(motion_vectors_over_pic_boundaries_flag, 1); | 241 | 8.23k | infer(max_bytes_per_pic_denom, 2); | 242 | 8.23k | infer(max_bits_per_mb_denom, 1); | 243 | 8.23k | infer(log2_max_mv_length_horizontal, 15); | 244 | 8.23k | infer(log2_max_mv_length_vertical, 15); | 245 | | | 246 | 8.23k | if ((sps->profile_idc == 44 || sps->profile_idc == 86 || | 247 | 7.30k | sps->profile_idc == 100 || sps->profile_idc == 110 || | 248 | 6.26k | sps->profile_idc == 122 || sps->profile_idc == 244) && | 249 | 3.01k | sps->constraint_set3_flag) { | 250 | 1.28k | infer(max_num_reorder_frames, 0); | 251 | 1.28k | infer(max_dec_frame_buffering, 0); | 252 | 6.95k | } else { | 253 | 6.95k | infer(max_num_reorder_frames, H264_MAX_DPB_FRAMES); | 254 | 6.95k | infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES); | 255 | 6.95k | } | 256 | | | 257 | 8.23k | return 0; | 258 | 8.23k | } |
|
259 | | |
260 | | static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, |
261 | | H264RawSPS *current) |
262 | 340k | { |
263 | 340k | int err, i; |
264 | | |
265 | 340k | HEADER("Sequence Parameter Set"); |
266 | | |
267 | 340k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, |
268 | 340k | 1 << H264_NAL_SPS)); |
269 | | |
270 | 340k | ub(8, profile_idc); |
271 | | |
272 | 335k | flag(constraint_set0_flag); |
273 | 331k | flag(constraint_set1_flag); |
274 | 331k | flag(constraint_set2_flag); |
275 | 331k | flag(constraint_set3_flag); |
276 | 331k | flag(constraint_set4_flag); |
277 | 331k | flag(constraint_set5_flag); |
278 | | |
279 | 331k | u(2, reserved_zero_2bits, 0, 0); |
280 | | |
281 | 317k | ub(8, level_idc); |
282 | | |
283 | 316k | ue(seq_parameter_set_id, 0, 31); |
284 | | |
285 | 309k | if (current->profile_idc == 100 || current->profile_idc == 110 || |
286 | 281k | current->profile_idc == 122 || current->profile_idc == 244 || |
287 | 248k | current->profile_idc == 44 || current->profile_idc == 83 || |
288 | 231k | current->profile_idc == 86 || current->profile_idc == 118 || |
289 | 222k | current->profile_idc == 128 || current->profile_idc == 138) { |
290 | 109k | ue(chroma_format_idc, 0, 3); |
291 | | |
292 | 89.0k | if (current->chroma_format_idc == 3) |
293 | 89.0k | flag(separate_colour_plane_flag); |
294 | 75.6k | else |
295 | 75.6k | infer(separate_colour_plane_flag, 0); |
296 | | |
297 | 85.7k | ue(bit_depth_luma_minus8, 0, 6); |
298 | 83.9k | ue(bit_depth_chroma_minus8, 0, 6); |
299 | | |
300 | 82.4k | flag(qpprime_y_zero_transform_bypass_flag); |
301 | | |
302 | 78.5k | flag(seq_scaling_matrix_present_flag); |
303 | 76.0k | if (current->seq_scaling_matrix_present_flag) { |
304 | 254k | for (i = 0; i < ((current->chroma_format_idc != 3) ? 8 : 12); i++) { |
305 | 234k | flags(seq_scaling_list_present_flag[i], 1, i); |
306 | 232k | if (current->seq_scaling_list_present_flag[i]) { |
307 | 130k | if (i < 6) |
308 | 109k | CHECK(FUNC(scaling_list)(ctx, rw, |
309 | 130k | ¤t->scaling_list_4x4[i], |
310 | 130k | 16)); |
311 | 21.2k | else |
312 | 21.2k | CHECK(FUNC(scaling_list)(ctx, rw, |
313 | 130k | ¤t->scaling_list_8x8[i - 6], |
314 | 130k | 64)); |
315 | 130k | } |
316 | 232k | } |
317 | 34.3k | } |
318 | 200k | } else { |
319 | 200k | infer(chroma_format_idc, current->profile_idc == 183 ? 0 : 1); |
320 | | |
321 | 200k | infer(separate_colour_plane_flag, 0); |
322 | 200k | infer(bit_depth_luma_minus8, 0); |
323 | 200k | infer(bit_depth_chroma_minus8, 0); |
324 | 8.34k | } |
325 | | |
326 | 262k | ue(log2_max_frame_num_minus4, 0, 12); |
327 | 254k | ue(pic_order_cnt_type, 0, 2); |
328 | | |
329 | 248k | if (current->pic_order_cnt_type == 0) { |
330 | 145k | ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12); |
331 | 145k | } else if (current->pic_order_cnt_type == 1) { |
332 | 78.4k | flag(delta_pic_order_always_zero_flag); |
333 | 77.1k | se(offset_for_non_ref_pic, INT32_MIN + 1, INT32_MAX); |
334 | 76.1k | se(offset_for_top_to_bottom_field, INT32_MIN + 1, INT32_MAX); |
335 | 72.8k | ue(num_ref_frames_in_pic_order_cnt_cycle, 0, 255); |
336 | | |
337 | 367k | for (i = 0; i < current->num_ref_frames_in_pic_order_cnt_cycle; i++) |
338 | 299k | ses(offset_for_ref_frame[i], INT32_MIN + 1, INT32_MAX, 1, i); |
339 | 71.0k | } |
340 | | |
341 | 235k | ue(max_num_ref_frames, 0, H264_MAX_DPB_FRAMES); |
342 | 232k | flag(gaps_in_frame_num_allowed_flag); |
343 | | |
344 | 231k | ue(pic_width_in_mbs_minus1, 0, H264_MAX_MB_WIDTH); |
345 | 227k | ue(pic_height_in_map_units_minus1, 0, H264_MAX_MB_HEIGHT); |
346 | | |
347 | 225k | flag(frame_mbs_only_flag); |
348 | 223k | if (!current->frame_mbs_only_flag) |
349 | 223k | flag(mb_adaptive_frame_field_flag); |
350 | | |
351 | 222k | flag(direct_8x8_inference_flag); |
352 | | |
353 | 220k | flag(frame_cropping_flag); |
354 | 217k | if (current->frame_cropping_flag) { |
355 | 131k | ue(frame_crop_left_offset, 0, H264_MAX_WIDTH); |
356 | 130k | ue(frame_crop_right_offset, 0, H264_MAX_WIDTH); |
357 | 129k | ue(frame_crop_top_offset, 0, H264_MAX_HEIGHT); |
358 | 127k | ue(frame_crop_bottom_offset, 0, H264_MAX_HEIGHT); |
359 | 127k | } |
360 | | |
361 | 211k | flag(vui_parameters_present_flag); |
362 | 206k | if (current->vui_parameters_present_flag) |
363 | 151k | CHECK(FUNC(vui_parameters)(ctx, rw, ¤t->vui, current)); |
364 | 55.0k | else |
365 | 55.0k | CHECK(FUNC(vui_parameters_default)(ctx, rw, ¤t->vui, current)); |
366 | | |
367 | 114k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); |
368 | | |
369 | 79.0k | return 0; |
370 | 114k | } cbs_h264.c:cbs_h264_read_sps Line | Count | Source | 262 | 322k | { | 263 | 322k | int err, i; | 264 | | | 265 | 322k | HEADER("Sequence Parameter Set"); | 266 | | | 267 | 322k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 268 | 322k | 1 << H264_NAL_SPS)); | 269 | | | 270 | 322k | ub(8, profile_idc); | 271 | | | 272 | 317k | flag(constraint_set0_flag); | 273 | 314k | flag(constraint_set1_flag); | 274 | 314k | flag(constraint_set2_flag); | 275 | 314k | flag(constraint_set3_flag); | 276 | 314k | flag(constraint_set4_flag); | 277 | 314k | flag(constraint_set5_flag); | 278 | | | 279 | 314k | u(2, reserved_zero_2bits, 0, 0); | 280 | | | 281 | 299k | ub(8, level_idc); | 282 | | | 283 | 298k | ue(seq_parameter_set_id, 0, 31); | 284 | | | 285 | 291k | if (current->profile_idc == 100 || current->profile_idc == 110 || | 286 | 266k | current->profile_idc == 122 || current->profile_idc == 244 || | 287 | 234k | current->profile_idc == 44 || current->profile_idc == 83 || | 288 | 219k | current->profile_idc == 86 || current->profile_idc == 118 || | 289 | 212k | current->profile_idc == 128 || current->profile_idc == 138) { | 290 | 99.5k | ue(chroma_format_idc, 0, 3); | 291 | | | 292 | 79.6k | if (current->chroma_format_idc == 3) | 293 | 79.6k | flag(separate_colour_plane_flag); | 294 | 68.5k | else | 295 | 68.5k | infer(separate_colour_plane_flag, 0); | 296 | | | 297 | 76.3k | ue(bit_depth_luma_minus8, 0, 6); | 298 | 74.4k | ue(bit_depth_chroma_minus8, 0, 6); | 299 | | | 300 | 72.9k | flag(qpprime_y_zero_transform_bypass_flag); | 301 | | | 302 | 69.1k | flag(seq_scaling_matrix_present_flag); | 303 | 66.5k | if (current->seq_scaling_matrix_present_flag) { | 304 | 226k | for (i = 0; i < ((current->chroma_format_idc != 3) ? 8 : 12); i++) { | 305 | 209k | flags(seq_scaling_list_present_flag[i], 1, i); | 306 | 208k | if (current->seq_scaling_list_present_flag[i]) { | 307 | 116k | if (i < 6) | 308 | 97.9k | CHECK(FUNC(scaling_list)(ctx, rw, | 309 | 116k | ¤t->scaling_list_4x4[i], | 310 | 116k | 16)); | 311 | 18.6k | else | 312 | 18.6k | CHECK(FUNC(scaling_list)(ctx, rw, | 313 | 116k | ¤t->scaling_list_8x8[i - 6], | 314 | 116k | 64)); | 315 | 116k | } | 316 | 208k | } | 317 | 31.3k | } | 318 | 192k | } else { | 319 | 192k | infer(chroma_format_idc, current->profile_idc == 183 ? 0 : 1); | 320 | | | 321 | 192k | infer(separate_colour_plane_flag, 0); | 322 | 192k | infer(bit_depth_luma_minus8, 0); | 323 | 192k | infer(bit_depth_chroma_minus8, 0); | 324 | 192k | } | 325 | | | 326 | 244k | ue(log2_max_frame_num_minus4, 0, 12); | 327 | 236k | ue(pic_order_cnt_type, 0, 2); | 328 | | | 329 | 230k | if (current->pic_order_cnt_type == 0) { | 330 | 134k | ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12); | 331 | 134k | } else if (current->pic_order_cnt_type == 1) { | 332 | 73.8k | flag(delta_pic_order_always_zero_flag); | 333 | 72.5k | se(offset_for_non_ref_pic, INT32_MIN + 1, INT32_MAX); | 334 | 71.4k | se(offset_for_top_to_bottom_field, INT32_MIN + 1, INT32_MAX); | 335 | 68.2k | ue(num_ref_frames_in_pic_order_cnt_cycle, 0, 255); | 336 | | | 337 | 333k | for (i = 0; i < current->num_ref_frames_in_pic_order_cnt_cycle; i++) | 338 | 270k | ses(offset_for_ref_frame[i], INT32_MIN + 1, INT32_MAX, 1, i); | 339 | 66.4k | } | 340 | | | 341 | 217k | ue(max_num_ref_frames, 0, H264_MAX_DPB_FRAMES); | 342 | 214k | flag(gaps_in_frame_num_allowed_flag); | 343 | | | 344 | 213k | ue(pic_width_in_mbs_minus1, 0, H264_MAX_MB_WIDTH); | 345 | 210k | ue(pic_height_in_map_units_minus1, 0, H264_MAX_MB_HEIGHT); | 346 | | | 347 | 207k | flag(frame_mbs_only_flag); | 348 | 205k | if (!current->frame_mbs_only_flag) | 349 | 205k | flag(mb_adaptive_frame_field_flag); | 350 | | | 351 | 204k | flag(direct_8x8_inference_flag); | 352 | | | 353 | 202k | flag(frame_cropping_flag); | 354 | 199k | if (current->frame_cropping_flag) { | 355 | 122k | ue(frame_crop_left_offset, 0, H264_MAX_WIDTH); | 356 | 120k | ue(frame_crop_right_offset, 0, H264_MAX_WIDTH); | 357 | 120k | ue(frame_crop_top_offset, 0, H264_MAX_HEIGHT); | 358 | 118k | ue(frame_crop_bottom_offset, 0, H264_MAX_HEIGHT); | 359 | 118k | } | 360 | | | 361 | 193k | flag(vui_parameters_present_flag); | 362 | 188k | if (current->vui_parameters_present_flag) | 363 | 142k | CHECK(FUNC(vui_parameters)(ctx, rw, ¤t->vui, current)); | 364 | 46.8k | else | 365 | 46.8k | CHECK(FUNC(vui_parameters_default)(ctx, rw, ¤t->vui, current)); | 366 | | | 367 | 96.6k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 368 | | | 369 | 61.2k | return 0; | 370 | 96.6k | } |
cbs_h264.c:cbs_h264_write_sps Line | Count | Source | 262 | 17.8k | { | 263 | 17.8k | int err, i; | 264 | | | 265 | 17.8k | HEADER("Sequence Parameter Set"); | 266 | | | 267 | 17.8k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 268 | 17.8k | 1 << H264_NAL_SPS)); | 269 | | | 270 | 17.8k | ub(8, profile_idc); | 271 | | | 272 | 17.8k | flag(constraint_set0_flag); | 273 | 17.8k | flag(constraint_set1_flag); | 274 | 17.8k | flag(constraint_set2_flag); | 275 | 17.8k | flag(constraint_set3_flag); | 276 | 17.8k | flag(constraint_set4_flag); | 277 | 17.8k | flag(constraint_set5_flag); | 278 | | | 279 | 17.8k | u(2, reserved_zero_2bits, 0, 0); | 280 | | | 281 | 17.8k | ub(8, level_idc); | 282 | | | 283 | 17.8k | ue(seq_parameter_set_id, 0, 31); | 284 | | | 285 | 17.8k | if (current->profile_idc == 100 || current->profile_idc == 110 || | 286 | 15.4k | current->profile_idc == 122 || current->profile_idc == 244 || | 287 | 13.1k | current->profile_idc == 44 || current->profile_idc == 83 || | 288 | 11.7k | current->profile_idc == 86 || current->profile_idc == 118 || | 289 | 9.75k | current->profile_idc == 128 || current->profile_idc == 138) { | 290 | 9.47k | ue(chroma_format_idc, 0, 3); | 291 | | | 292 | 9.47k | if (current->chroma_format_idc == 3) | 293 | 9.47k | flag(separate_colour_plane_flag); | 294 | 7.11k | else | 295 | 7.11k | infer(separate_colour_plane_flag, 0); | 296 | | | 297 | 9.47k | ue(bit_depth_luma_minus8, 0, 6); | 298 | 9.47k | ue(bit_depth_chroma_minus8, 0, 6); | 299 | | | 300 | 9.47k | flag(qpprime_y_zero_transform_bypass_flag); | 301 | | | 302 | 9.47k | flag(seq_scaling_matrix_present_flag); | 303 | 9.47k | if (current->seq_scaling_matrix_present_flag) { | 304 | 27.8k | for (i = 0; i < ((current->chroma_format_idc != 3) ? 8 : 12); i++) { | 305 | 24.7k | flags(seq_scaling_list_present_flag[i], 1, i); | 306 | 24.7k | if (current->seq_scaling_list_present_flag[i]) { | 307 | 13.8k | if (i < 6) | 308 | 11.2k | CHECK(FUNC(scaling_list)(ctx, rw, | 309 | 13.8k | ¤t->scaling_list_4x4[i], | 310 | 13.8k | 16)); | 311 | 2.59k | else | 312 | 2.59k | CHECK(FUNC(scaling_list)(ctx, rw, | 313 | 13.8k | ¤t->scaling_list_8x8[i - 6], | 314 | 13.8k | 64)); | 315 | 13.8k | } | 316 | 24.7k | } | 317 | 3.05k | } | 318 | 9.47k | } else { | 319 | 8.34k | infer(chroma_format_idc, current->profile_idc == 183 ? 0 : 1); | 320 | | | 321 | 8.34k | infer(separate_colour_plane_flag, 0); | 322 | 8.34k | infer(bit_depth_luma_minus8, 0); | 323 | 8.34k | infer(bit_depth_chroma_minus8, 0); | 324 | 8.34k | } | 325 | | | 326 | 17.8k | ue(log2_max_frame_num_minus4, 0, 12); | 327 | 17.8k | ue(pic_order_cnt_type, 0, 2); | 328 | | | 329 | 17.8k | if (current->pic_order_cnt_type == 0) { | 330 | 11.2k | ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12); | 331 | 11.2k | } else if (current->pic_order_cnt_type == 1) { | 332 | 4.64k | flag(delta_pic_order_always_zero_flag); | 333 | 4.64k | se(offset_for_non_ref_pic, INT32_MIN + 1, INT32_MAX); | 334 | 4.64k | se(offset_for_top_to_bottom_field, INT32_MIN + 1, INT32_MAX); | 335 | 4.64k | ue(num_ref_frames_in_pic_order_cnt_cycle, 0, 255); | 336 | | | 337 | 33.3k | for (i = 0; i < current->num_ref_frames_in_pic_order_cnt_cycle; i++) | 338 | 28.6k | ses(offset_for_ref_frame[i], INT32_MIN + 1, INT32_MAX, 1, i); | 339 | 4.64k | } | 340 | | | 341 | 17.8k | ue(max_num_ref_frames, 0, H264_MAX_DPB_FRAMES); | 342 | 17.8k | flag(gaps_in_frame_num_allowed_flag); | 343 | | | 344 | 17.8k | ue(pic_width_in_mbs_minus1, 0, H264_MAX_MB_WIDTH); | 345 | 17.8k | ue(pic_height_in_map_units_minus1, 0, H264_MAX_MB_HEIGHT); | 346 | | | 347 | 17.8k | flag(frame_mbs_only_flag); | 348 | 17.8k | if (!current->frame_mbs_only_flag) | 349 | 17.8k | flag(mb_adaptive_frame_field_flag); | 350 | | | 351 | 17.8k | flag(direct_8x8_inference_flag); | 352 | | | 353 | 17.8k | flag(frame_cropping_flag); | 354 | 17.8k | if (current->frame_cropping_flag) { | 355 | 9.14k | ue(frame_crop_left_offset, 0, H264_MAX_WIDTH); | 356 | 9.14k | ue(frame_crop_right_offset, 0, H264_MAX_WIDTH); | 357 | 9.14k | ue(frame_crop_top_offset, 0, H264_MAX_HEIGHT); | 358 | 9.14k | ue(frame_crop_bottom_offset, 0, H264_MAX_HEIGHT); | 359 | 9.14k | } | 360 | | | 361 | 17.8k | flag(vui_parameters_present_flag); | 362 | 17.8k | if (current->vui_parameters_present_flag) | 363 | 9.58k | CHECK(FUNC(vui_parameters)(ctx, rw, ¤t->vui, current)); | 364 | 8.23k | else | 365 | 8.23k | CHECK(FUNC(vui_parameters_default)(ctx, rw, ¤t->vui, current)); | 366 | | | 367 | 17.8k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 368 | | | 369 | 17.8k | return 0; | 370 | 17.8k | } |
|
371 | | |
372 | | static int FUNC(sps_extension)(CodedBitstreamContext *ctx, RWContext *rw, |
373 | | H264RawSPSExtension *current) |
374 | 15.9k | { |
375 | 15.9k | int err; |
376 | | |
377 | 15.9k | HEADER("Sequence Parameter Set Extension"); |
378 | | |
379 | 15.9k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, |
380 | 15.9k | 1 << H264_NAL_SPS_EXT)); |
381 | | |
382 | 15.9k | ue(seq_parameter_set_id, 0, 31); |
383 | | |
384 | 14.2k | ue(aux_format_idc, 0, 3); |
385 | | |
386 | 13.0k | if (current->aux_format_idc != 0) { |
387 | 6.59k | int bits; |
388 | | |
389 | 6.59k | ue(bit_depth_aux_minus8, 0, 4); |
390 | 5.73k | flag(alpha_incr_flag); |
391 | | |
392 | 5.73k | bits = current->bit_depth_aux_minus8 + 9; |
393 | 5.73k | ub(bits, alpha_opaque_value); |
394 | 5.01k | ub(bits, alpha_transparent_value); |
395 | 5.01k | } |
396 | | |
397 | 10.8k | flag(additional_extension_flag); |
398 | | |
399 | 9.24k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); |
400 | | |
401 | 4.82k | return 0; |
402 | 9.24k | } cbs_h264.c:cbs_h264_read_sps_extension Line | Count | Source | 374 | 14.4k | { | 375 | 14.4k | int err; | 376 | | | 377 | 14.4k | HEADER("Sequence Parameter Set Extension"); | 378 | | | 379 | 14.4k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 380 | 14.4k | 1 << H264_NAL_SPS_EXT)); | 381 | | | 382 | 14.4k | ue(seq_parameter_set_id, 0, 31); | 383 | | | 384 | 12.6k | ue(aux_format_idc, 0, 3); | 385 | | | 386 | 11.4k | if (current->aux_format_idc != 0) { | 387 | 6.17k | int bits; | 388 | | | 389 | 6.17k | ue(bit_depth_aux_minus8, 0, 4); | 390 | 5.30k | flag(alpha_incr_flag); | 391 | | | 392 | 5.30k | bits = current->bit_depth_aux_minus8 + 9; | 393 | 5.30k | ub(bits, alpha_opaque_value); | 394 | 4.58k | ub(bits, alpha_transparent_value); | 395 | 4.58k | } | 396 | | | 397 | 9.33k | flag(additional_extension_flag); | 398 | | | 399 | 7.69k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 400 | | | 401 | 3.27k | return 0; | 402 | 7.69k | } |
cbs_h264.c:cbs_h264_write_sps_extension Line | Count | Source | 374 | 1.54k | { | 375 | 1.54k | int err; | 376 | | | 377 | 1.54k | HEADER("Sequence Parameter Set Extension"); | 378 | | | 379 | 1.54k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 380 | 1.54k | 1 << H264_NAL_SPS_EXT)); | 381 | | | 382 | 1.54k | ue(seq_parameter_set_id, 0, 31); | 383 | | | 384 | 1.54k | ue(aux_format_idc, 0, 3); | 385 | | | 386 | 1.54k | if (current->aux_format_idc != 0) { | 387 | 424 | int bits; | 388 | | | 389 | 424 | ue(bit_depth_aux_minus8, 0, 4); | 390 | 424 | flag(alpha_incr_flag); | 391 | | | 392 | 424 | bits = current->bit_depth_aux_minus8 + 9; | 393 | 424 | ub(bits, alpha_opaque_value); | 394 | 424 | ub(bits, alpha_transparent_value); | 395 | 424 | } | 396 | | | 397 | 1.54k | flag(additional_extension_flag); | 398 | | | 399 | 1.54k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 400 | | | 401 | 1.54k | return 0; | 402 | 1.54k | } |
|
403 | | |
404 | | static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw, |
405 | | H264RawPPS *current) |
406 | 139k | { |
407 | 139k | CodedBitstreamH264Context *h264 = ctx->priv_data; |
408 | 139k | const H264RawSPS *sps; |
409 | 139k | int err, i; |
410 | | |
411 | 139k | HEADER("Picture Parameter Set"); |
412 | | |
413 | 139k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, |
414 | 139k | 1 << H264_NAL_PPS)); |
415 | | |
416 | 139k | ue(pic_parameter_set_id, 0, 255); |
417 | 124k | ue(seq_parameter_set_id, 0, 31); |
418 | | |
419 | 118k | sps = h264->sps[current->seq_parameter_set_id]; |
420 | 118k | if (!sps) { |
421 | 15.1k | av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n", |
422 | 15.1k | current->seq_parameter_set_id); |
423 | 15.1k | return AVERROR_INVALIDDATA; |
424 | 15.1k | } |
425 | | |
426 | 103k | flag(entropy_coding_mode_flag); |
427 | 101k | flag(bottom_field_pic_order_in_frame_present_flag); |
428 | | |
429 | 101k | ue(num_slice_groups_minus1, 0, 7); |
430 | 96.1k | if (current->num_slice_groups_minus1 > 0) { |
431 | 55.4k | unsigned int pic_size; |
432 | 55.4k | int iGroup; |
433 | | |
434 | 55.4k | pic_size = (sps->pic_width_in_mbs_minus1 + 1) * |
435 | 55.4k | (sps->pic_height_in_map_units_minus1 + 1); |
436 | | |
437 | 55.4k | ue(slice_group_map_type, 0, 6); |
438 | | |
439 | 54.2k | if (current->slice_group_map_type == 0) { |
440 | 38.5k | for (iGroup = 0; iGroup <= current->num_slice_groups_minus1; iGroup++) |
441 | 32.5k | ues(run_length_minus1[iGroup], 0, pic_size - 1, 1, iGroup); |
442 | | |
443 | 39.0k | } else if (current->slice_group_map_type == 2) { |
444 | 27.5k | for (iGroup = 0; iGroup < current->num_slice_groups_minus1; iGroup++) { |
445 | 23.6k | ues(top_left[iGroup], 0, pic_size - 1, 1, iGroup); |
446 | 22.4k | ues(bottom_right[iGroup], |
447 | 22.4k | current->top_left[iGroup], pic_size - 1, 1, iGroup); |
448 | 22.4k | } |
449 | 31.2k | } else if (current->slice_group_map_type == 3 || |
450 | 23.9k | current->slice_group_map_type == 4 || |
451 | 19.6k | current->slice_group_map_type == 5) { |
452 | 17.9k | flag(slice_group_change_direction_flag); |
453 | 14.2k | ue(slice_group_change_rate_minus1, 0, pic_size - 1); |
454 | 14.2k | } else if (current->slice_group_map_type == 6) { |
455 | 9.60k | ue(pic_size_in_map_units_minus1, pic_size - 1, pic_size - 1); |
456 | | |
457 | 6.66k | allocate(current->slice_group_id, |
458 | 6.66k | current->pic_size_in_map_units_minus1 + 1); |
459 | 20.5k | for (i = 0; i <= current->pic_size_in_map_units_minus1; i++) |
460 | 15.1k | us(av_log2(2 * current->num_slice_groups_minus1 + 1), |
461 | 6.66k | slice_group_id[i], 0, current->num_slice_groups_minus1, 1, i); |
462 | 6.66k | } |
463 | 54.2k | } |
464 | | |
465 | 68.8k | ue(num_ref_idx_l0_default_active_minus1, 0, 31); |
466 | 66.8k | ue(num_ref_idx_l1_default_active_minus1, 0, 31); |
467 | | |
468 | 65.7k | flag(weighted_pred_flag); |
469 | 64.8k | u(2, weighted_bipred_idc, 0, 2); |
470 | | |
471 | 62.0k | se(pic_init_qp_minus26, -26 - 6 * sps->bit_depth_luma_minus8, +25); |
472 | 60.6k | se(pic_init_qs_minus26, -26, +25); |
473 | 59.1k | se(chroma_qp_index_offset, -12, +12); |
474 | | |
475 | 57.8k | flag(deblocking_filter_control_present_flag); |
476 | 56.6k | flag(constrained_intra_pred_flag); |
477 | 54.6k | flag(redundant_pic_cnt_present_flag); |
478 | | |
479 | 53.2k | if (more_rbsp_data(current->more_rbsp_data)) |
480 | 49.3k | { |
481 | 49.3k | flag(transform_8x8_mode_flag); |
482 | | |
483 | 49.3k | flag(pic_scaling_matrix_present_flag); |
484 | 49.3k | if (current->pic_scaling_matrix_present_flag) { |
485 | 157k | for (i = 0; i < 6 + (((sps->chroma_format_idc != 3) ? 2 : 6) * |
486 | 157k | current->transform_8x8_mode_flag); i++) { |
487 | 141k | flags(pic_scaling_list_present_flag[i], 1, i); |
488 | 140k | if (current->pic_scaling_list_present_flag[i]) { |
489 | 75.0k | if (i < 6) |
490 | 67.9k | CHECK(FUNC(scaling_list)(ctx, rw, |
491 | 75.0k | ¤t->scaling_list_4x4[i], |
492 | 75.0k | 16)); |
493 | 7.00k | else |
494 | 7.00k | CHECK(FUNC(scaling_list)(ctx, rw, |
495 | 75.0k | ¤t->scaling_list_8x8[i - 6], |
496 | 75.0k | 64)); |
497 | 75.0k | } |
498 | 140k | } |
499 | 24.7k | } |
500 | | |
501 | 40.4k | se(second_chroma_qp_index_offset, -12, +12); |
502 | 40.4k | } else { |
503 | 3.92k | infer(transform_8x8_mode_flag, 0); |
504 | 3.92k | infer(pic_scaling_matrix_present_flag, 0); |
505 | 3.92k | infer(second_chroma_qp_index_offset, current->chroma_qp_index_offset); |
506 | 736 | } |
507 | | |
508 | 42.3k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); |
509 | | |
510 | 36.1k | return 0; |
511 | 42.3k | } cbs_h264.c:cbs_h264_read_pps Line | Count | Source | 406 | 127k | { | 407 | 127k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 408 | 127k | const H264RawSPS *sps; | 409 | 127k | int err, i; | 410 | | | 411 | 127k | HEADER("Picture Parameter Set"); | 412 | | | 413 | 127k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 414 | 127k | 1 << H264_NAL_PPS)); | 415 | | | 416 | 127k | ue(pic_parameter_set_id, 0, 255); | 417 | 112k | ue(seq_parameter_set_id, 0, 31); | 418 | | | 419 | 106k | sps = h264->sps[current->seq_parameter_set_id]; | 420 | 106k | if (!sps) { | 421 | 14.5k | av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n", | 422 | 14.5k | current->seq_parameter_set_id); | 423 | 14.5k | return AVERROR_INVALIDDATA; | 424 | 14.5k | } | 425 | | | 426 | 92.1k | flag(entropy_coding_mode_flag); | 427 | 90.6k | flag(bottom_field_pic_order_in_frame_present_flag); | 428 | | | 429 | 90.6k | ue(num_slice_groups_minus1, 0, 7); | 430 | 84.8k | if (current->num_slice_groups_minus1 > 0) { | 431 | 48.7k | unsigned int pic_size; | 432 | 48.7k | int iGroup; | 433 | | | 434 | 48.7k | pic_size = (sps->pic_width_in_mbs_minus1 + 1) * | 435 | 48.7k | (sps->pic_height_in_map_units_minus1 + 1); | 436 | | | 437 | 48.7k | ue(slice_group_map_type, 0, 6); | 438 | | | 439 | 47.5k | if (current->slice_group_map_type == 0) { | 440 | 33.7k | for (iGroup = 0; iGroup <= current->num_slice_groups_minus1; iGroup++) | 441 | 28.7k | ues(run_length_minus1[iGroup], 0, pic_size - 1, 1, iGroup); | 442 | | | 443 | 33.7k | } else if (current->slice_group_map_type == 2) { | 444 | 23.2k | for (iGroup = 0; iGroup < current->num_slice_groups_minus1; iGroup++) { | 445 | 19.8k | ues(top_left[iGroup], 0, pic_size - 1, 1, iGroup); | 446 | 19.0k | ues(bottom_right[iGroup], | 447 | 19.0k | current->top_left[iGroup], pic_size - 1, 1, iGroup); | 448 | 19.0k | } | 449 | 27.2k | } else if (current->slice_group_map_type == 3 || | 450 | 20.7k | current->slice_group_map_type == 4 || | 451 | 17.1k | current->slice_group_map_type == 5) { | 452 | 15.7k | flag(slice_group_change_direction_flag); | 453 | 12.1k | ue(slice_group_change_rate_minus1, 0, pic_size - 1); | 454 | 12.1k | } else if (current->slice_group_map_type == 6) { | 455 | 8.49k | ue(pic_size_in_map_units_minus1, pic_size - 1, pic_size - 1); | 456 | | | 457 | 5.99k | allocate(current->slice_group_id, | 458 | 5.99k | current->pic_size_in_map_units_minus1 + 1); | 459 | 17.1k | for (i = 0; i <= current->pic_size_in_map_units_minus1; i++) | 460 | 12.4k | us(av_log2(2 * current->num_slice_groups_minus1 + 1), | 461 | 5.99k | slice_group_id[i], 0, current->num_slice_groups_minus1, 1, i); | 462 | 5.99k | } | 463 | 47.5k | } | 464 | | | 465 | 59.6k | ue(num_ref_idx_l0_default_active_minus1, 0, 31); | 466 | 57.6k | ue(num_ref_idx_l1_default_active_minus1, 0, 31); | 467 | | | 468 | 56.5k | flag(weighted_pred_flag); | 469 | 55.6k | u(2, weighted_bipred_idc, 0, 2); | 470 | | | 471 | 52.8k | se(pic_init_qp_minus26, -26 - 6 * sps->bit_depth_luma_minus8, +25); | 472 | 51.6k | se(pic_init_qs_minus26, -26, +25); | 473 | 50.1k | se(chroma_qp_index_offset, -12, +12); | 474 | | | 475 | 48.8k | flag(deblocking_filter_control_present_flag); | 476 | 47.6k | flag(constrained_intra_pred_flag); | 477 | 45.6k | flag(redundant_pic_cnt_present_flag); | 478 | | | 479 | 44.2k | if (more_rbsp_data(current->more_rbsp_data)) | 480 | 41.0k | { | 481 | 41.0k | flag(transform_8x8_mode_flag); | 482 | | | 483 | 41.0k | flag(pic_scaling_matrix_present_flag); | 484 | 41.0k | if (current->pic_scaling_matrix_present_flag) { | 485 | 136k | for (i = 0; i < 6 + (((sps->chroma_format_idc != 3) ? 2 : 6) * | 486 | 136k | current->transform_8x8_mode_flag); i++) { | 487 | 122k | flags(pic_scaling_list_present_flag[i], 1, i); | 488 | 122k | if (current->pic_scaling_list_present_flag[i]) { | 489 | 67.0k | if (i < 6) | 490 | 60.8k | CHECK(FUNC(scaling_list)(ctx, rw, | 491 | 67.0k | ¤t->scaling_list_4x4[i], | 492 | 67.0k | 16)); | 493 | 6.22k | else | 494 | 6.22k | CHECK(FUNC(scaling_list)(ctx, rw, | 495 | 67.0k | ¤t->scaling_list_8x8[i - 6], | 496 | 67.0k | 64)); | 497 | 67.0k | } | 498 | 122k | } | 499 | 22.1k | } | 500 | | | 501 | 32.1k | se(second_chroma_qp_index_offset, -12, +12); | 502 | 32.1k | } else { | 503 | 3.19k | infer(transform_8x8_mode_flag, 0); | 504 | 3.19k | infer(pic_scaling_matrix_present_flag, 0); | 505 | 3.19k | infer(second_chroma_qp_index_offset, current->chroma_qp_index_offset); | 506 | 3.19k | } | 507 | | | 508 | 33.3k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 509 | | | 510 | 27.0k | return 0; | 511 | 33.3k | } |
cbs_h264.c:cbs_h264_write_pps Line | Count | Source | 406 | 11.9k | { | 407 | 11.9k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 408 | 11.9k | const H264RawSPS *sps; | 409 | 11.9k | int err, i; | 410 | | | 411 | 11.9k | HEADER("Picture Parameter Set"); | 412 | | | 413 | 11.9k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 414 | 11.9k | 1 << H264_NAL_PPS)); | 415 | | | 416 | 11.9k | ue(pic_parameter_set_id, 0, 255); | 417 | 11.9k | ue(seq_parameter_set_id, 0, 31); | 418 | | | 419 | 11.9k | sps = h264->sps[current->seq_parameter_set_id]; | 420 | 11.9k | if (!sps) { | 421 | 629 | av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n", | 422 | 629 | current->seq_parameter_set_id); | 423 | 629 | return AVERROR_INVALIDDATA; | 424 | 629 | } | 425 | | | 426 | 11.3k | flag(entropy_coding_mode_flag); | 427 | 11.3k | flag(bottom_field_pic_order_in_frame_present_flag); | 428 | | | 429 | 11.3k | ue(num_slice_groups_minus1, 0, 7); | 430 | 11.3k | if (current->num_slice_groups_minus1 > 0) { | 431 | 6.71k | unsigned int pic_size; | 432 | 6.71k | int iGroup; | 433 | | | 434 | 6.71k | pic_size = (sps->pic_width_in_mbs_minus1 + 1) * | 435 | 6.71k | (sps->pic_height_in_map_units_minus1 + 1); | 436 | | | 437 | 6.71k | ue(slice_group_map_type, 0, 6); | 438 | | | 439 | 6.71k | if (current->slice_group_map_type == 0) { | 440 | 4.81k | for (iGroup = 0; iGroup <= current->num_slice_groups_minus1; iGroup++) | 441 | 3.78k | ues(run_length_minus1[iGroup], 0, pic_size - 1, 1, iGroup); | 442 | | | 443 | 5.28k | } else if (current->slice_group_map_type == 2) { | 444 | 4.28k | for (iGroup = 0; iGroup < current->num_slice_groups_minus1; iGroup++) { | 445 | 3.79k | ues(top_left[iGroup], 0, pic_size - 1, 1, iGroup); | 446 | 3.39k | ues(bottom_right[iGroup], | 447 | 3.39k | current->top_left[iGroup], pic_size - 1, 1, iGroup); | 448 | 3.39k | } | 449 | 3.97k | } else if (current->slice_group_map_type == 3 || | 450 | 3.13k | current->slice_group_map_type == 4 || | 451 | 2.43k | current->slice_group_map_type == 5) { | 452 | 2.12k | flag(slice_group_change_direction_flag); | 453 | 2.12k | ue(slice_group_change_rate_minus1, 0, pic_size - 1); | 454 | 2.12k | } else if (current->slice_group_map_type == 6) { | 455 | 1.10k | ue(pic_size_in_map_units_minus1, pic_size - 1, pic_size - 1); | 456 | | | 457 | 672 | allocate(current->slice_group_id, | 458 | 672 | current->pic_size_in_map_units_minus1 + 1); | 459 | 3.37k | for (i = 0; i <= current->pic_size_in_map_units_minus1; i++) | 460 | 2.69k | us(av_log2(2 * current->num_slice_groups_minus1 + 1), | 461 | 672 | slice_group_id[i], 0, current->num_slice_groups_minus1, 1, i); | 462 | 672 | } | 463 | 6.71k | } | 464 | | | 465 | 9.22k | ue(num_ref_idx_l0_default_active_minus1, 0, 31); | 466 | 9.22k | ue(num_ref_idx_l1_default_active_minus1, 0, 31); | 467 | | | 468 | 9.22k | flag(weighted_pred_flag); | 469 | 9.22k | u(2, weighted_bipred_idc, 0, 2); | 470 | | | 471 | 9.22k | se(pic_init_qp_minus26, -26 - 6 * sps->bit_depth_luma_minus8, +25); | 472 | 9.02k | se(pic_init_qs_minus26, -26, +25); | 473 | 9.02k | se(chroma_qp_index_offset, -12, +12); | 474 | | | 475 | 9.02k | flag(deblocking_filter_control_present_flag); | 476 | 9.02k | flag(constrained_intra_pred_flag); | 477 | 9.02k | flag(redundant_pic_cnt_present_flag); | 478 | | | 479 | 9.02k | if (more_rbsp_data(current->more_rbsp_data)) | 480 | 8.28k | { | 481 | 8.28k | flag(transform_8x8_mode_flag); | 482 | | | 483 | 8.28k | flag(pic_scaling_matrix_present_flag); | 484 | 8.28k | if (current->pic_scaling_matrix_present_flag) { | 485 | 21.5k | for (i = 0; i < 6 + (((sps->chroma_format_idc != 3) ? 2 : 6) * | 486 | 21.5k | current->transform_8x8_mode_flag); i++) { | 487 | 18.8k | flags(pic_scaling_list_present_flag[i], 1, i); | 488 | 18.8k | if (current->pic_scaling_list_present_flag[i]) { | 489 | 7.91k | if (i < 6) | 490 | 7.13k | CHECK(FUNC(scaling_list)(ctx, rw, | 491 | 7.91k | ¤t->scaling_list_4x4[i], | 492 | 7.91k | 16)); | 493 | 781 | else | 494 | 781 | CHECK(FUNC(scaling_list)(ctx, rw, | 495 | 7.91k | ¤t->scaling_list_8x8[i - 6], | 496 | 7.91k | 64)); | 497 | 7.91k | } | 498 | 18.8k | } | 499 | 2.67k | } | 500 | | | 501 | 8.28k | se(second_chroma_qp_index_offset, -12, +12); | 502 | 8.28k | } else { | 503 | 736 | infer(transform_8x8_mode_flag, 0); | 504 | 736 | infer(pic_scaling_matrix_present_flag, 0); | 505 | 736 | infer(second_chroma_qp_index_offset, current->chroma_qp_index_offset); | 506 | 736 | } | 507 | | | 508 | 9.02k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 509 | | | 510 | 9.02k | return 0; | 511 | 9.02k | } |
|
512 | | |
513 | | SEI_FUNC(sei_buffering_period, (CodedBitstreamContext *ctx, RWContext *rw, |
514 | | H264RawSEIBufferingPeriod *current, |
515 | | SEIMessageState *sei)) |
516 | 30.4k | { |
517 | 30.4k | CodedBitstreamH264Context *h264 = ctx->priv_data; |
518 | 30.4k | const H264RawSPS *sps; |
519 | 30.4k | int err, i, length; |
520 | | |
521 | 30.4k | HEADER("Buffering Period"); |
522 | | |
523 | 30.4k | ue(seq_parameter_set_id, 0, 31); |
524 | | |
525 | 16.0k | sps = h264->sps[current->seq_parameter_set_id]; |
526 | 16.0k | if (!sps) { |
527 | 2.24k | av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n", |
528 | 2.24k | current->seq_parameter_set_id); |
529 | 2.24k | return AVERROR_INVALIDDATA; |
530 | 2.24k | } |
531 | 13.8k | h264->active_sps = sps; |
532 | | |
533 | 13.8k | if (sps->vui.nal_hrd_parameters_present_flag) { |
534 | 22.1k | for (i = 0; i <= sps->vui.nal_hrd_parameters.cpb_cnt_minus1; i++) { |
535 | 16.6k | length = sps->vui.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1; |
536 | 16.6k | xu(length, initial_cpb_removal_delay[SchedSelIdx], |
537 | 16.6k | current->nal.initial_cpb_removal_delay[i], |
538 | 16.6k | 1, MAX_UINT_BITS(length), 1, i); |
539 | 15.4k | xu(length, initial_cpb_removal_delay_offset[SchedSelIdx], |
540 | 15.4k | current->nal.initial_cpb_removal_delay_offset[i], |
541 | 15.4k | 0, MAX_UINT_BITS(length), 1, i); |
542 | 15.4k | } |
543 | 7.85k | } |
544 | | |
545 | 11.4k | if (sps->vui.vcl_hrd_parameters_present_flag) { |
546 | 18.0k | for (i = 0; i <= sps->vui.vcl_hrd_parameters.cpb_cnt_minus1; i++) { |
547 | 13.6k | length = sps->vui.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1; |
548 | 13.6k | xu(length, initial_cpb_removal_delay[SchedSelIdx], |
549 | 13.6k | current->vcl.initial_cpb_removal_delay[i], |
550 | 13.6k | 1, MAX_UINT_BITS(length), 1, i); |
551 | 12.1k | xu(length, initial_cpb_removal_delay_offset[SchedSelIdx], |
552 | 12.1k | current->vcl.initial_cpb_removal_delay_offset[i], |
553 | 12.1k | 0, MAX_UINT_BITS(length), 1, i); |
554 | 12.1k | } |
555 | 6.97k | } |
556 | | |
557 | 8.84k | return 0; |
558 | 11.4k | } cbs_h264.c:cbs_h264_read_sei_buffering_period Line | Count | Source | 516 | 26.1k | { | 517 | 26.1k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 518 | 26.1k | const H264RawSPS *sps; | 519 | 26.1k | int err, i, length; | 520 | | | 521 | 26.1k | HEADER("Buffering Period"); | 522 | | | 523 | 26.1k | ue(seq_parameter_set_id, 0, 31); | 524 | | | 525 | 11.7k | sps = h264->sps[current->seq_parameter_set_id]; | 526 | 11.7k | if (!sps) { | 527 | 1.82k | av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n", | 528 | 1.82k | current->seq_parameter_set_id); | 529 | 1.82k | return AVERROR_INVALIDDATA; | 530 | 1.82k | } | 531 | 9.90k | h264->active_sps = sps; | 532 | | | 533 | 9.90k | if (sps->vui.nal_hrd_parameters_present_flag) { | 534 | 16.1k | for (i = 0; i <= sps->vui.nal_hrd_parameters.cpb_cnt_minus1; i++) { | 535 | 12.1k | length = sps->vui.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1; | 536 | 12.1k | xu(length, initial_cpb_removal_delay[SchedSelIdx], | 537 | 12.1k | current->nal.initial_cpb_removal_delay[i], | 538 | 12.1k | 1, MAX_UINT_BITS(length), 1, i); | 539 | 11.3k | xu(length, initial_cpb_removal_delay_offset[SchedSelIdx], | 540 | 11.3k | current->nal.initial_cpb_removal_delay_offset[i], | 541 | 11.3k | 0, MAX_UINT_BITS(length), 1, i); | 542 | 11.3k | } | 543 | 5.56k | } | 544 | | | 545 | 8.33k | if (sps->vui.vcl_hrd_parameters_present_flag) { | 546 | 12.7k | for (i = 0; i <= sps->vui.vcl_hrd_parameters.cpb_cnt_minus1; i++) { | 547 | 9.76k | length = sps->vui.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1; | 548 | 9.76k | xu(length, initial_cpb_removal_delay[SchedSelIdx], | 549 | 9.76k | current->vcl.initial_cpb_removal_delay[i], | 550 | 9.76k | 1, MAX_UINT_BITS(length), 1, i); | 551 | 8.61k | xu(length, initial_cpb_removal_delay_offset[SchedSelIdx], | 552 | 8.61k | current->vcl.initial_cpb_removal_delay_offset[i], | 553 | 8.61k | 0, MAX_UINT_BITS(length), 1, i); | 554 | 8.61k | } | 555 | 4.74k | } | 556 | | | 557 | 6.55k | return 0; | 558 | 8.33k | } |
cbs_h264.c:cbs_h264_write_sei_buffering_period Line | Count | Source | 516 | 4.36k | { | 517 | 4.36k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 518 | 4.36k | const H264RawSPS *sps; | 519 | 4.36k | int err, i, length; | 520 | | | 521 | 4.36k | HEADER("Buffering Period"); | 522 | | | 523 | 4.36k | ue(seq_parameter_set_id, 0, 31); | 524 | | | 525 | 4.36k | sps = h264->sps[current->seq_parameter_set_id]; | 526 | 4.36k | if (!sps) { | 527 | 421 | av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n", | 528 | 421 | current->seq_parameter_set_id); | 529 | 421 | return AVERROR_INVALIDDATA; | 530 | 421 | } | 531 | 3.94k | h264->active_sps = sps; | 532 | | | 533 | 3.94k | if (sps->vui.nal_hrd_parameters_present_flag) { | 534 | 6.00k | for (i = 0; i <= sps->vui.nal_hrd_parameters.cpb_cnt_minus1; i++) { | 535 | 4.55k | length = sps->vui.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1; | 536 | 4.55k | xu(length, initial_cpb_removal_delay[SchedSelIdx], | 537 | 4.55k | current->nal.initial_cpb_removal_delay[i], | 538 | 4.55k | 1, MAX_UINT_BITS(length), 1, i); | 539 | 4.10k | xu(length, initial_cpb_removal_delay_offset[SchedSelIdx], | 540 | 4.10k | current->nal.initial_cpb_removal_delay_offset[i], | 541 | 4.10k | 0, MAX_UINT_BITS(length), 1, i); | 542 | 4.10k | } | 543 | 2.29k | } | 544 | | | 545 | 3.09k | if (sps->vui.vcl_hrd_parameters_present_flag) { | 546 | 5.33k | for (i = 0; i <= sps->vui.vcl_hrd_parameters.cpb_cnt_minus1; i++) { | 547 | 3.91k | length = sps->vui.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1; | 548 | 3.91k | xu(length, initial_cpb_removal_delay[SchedSelIdx], | 549 | 3.91k | current->vcl.initial_cpb_removal_delay[i], | 550 | 3.91k | 1, MAX_UINT_BITS(length), 1, i); | 551 | 3.50k | xu(length, initial_cpb_removal_delay_offset[SchedSelIdx], | 552 | 3.50k | current->vcl.initial_cpb_removal_delay_offset[i], | 553 | 3.50k | 0, MAX_UINT_BITS(length), 1, i); | 554 | 3.50k | } | 555 | 2.22k | } | 556 | | | 557 | 2.29k | return 0; | 558 | 3.09k | } |
|
559 | | |
560 | | static int FUNC(sei_pic_timestamp)(CodedBitstreamContext *ctx, RWContext *rw, |
561 | | H264RawSEIPicTimestamp *current, |
562 | | const H264RawSPS *sps) |
563 | 93.7k | { |
564 | 93.7k | uint8_t time_offset_length; |
565 | 93.7k | int err; |
566 | | |
567 | 93.7k | u(2, ct_type, 0, 2); |
568 | 93.0k | flag(nuit_field_based_flag); |
569 | 92.5k | u(5, counting_type, 0, 6); |
570 | 91.2k | flag(full_timestamp_flag); |
571 | 90.4k | flag(discontinuity_flag); |
572 | 90.0k | flag(cnt_dropped_flag); |
573 | 89.0k | ub(8, n_frames); |
574 | 88.0k | if (current->full_timestamp_flag) { |
575 | 5.43k | u(6, seconds_value, 0, 59); |
576 | 4.99k | u(6, minutes_value, 0, 59); |
577 | 4.45k | u(5, hours_value, 0, 23); |
578 | 82.6k | } else { |
579 | 82.6k | flag(seconds_flag); |
580 | 81.9k | if (current->seconds_flag) { |
581 | 9.78k | u(6, seconds_value, 0, 59); |
582 | 9.23k | flag(minutes_flag); |
583 | 8.72k | if (current->minutes_flag) { |
584 | 6.13k | u(6, minutes_value, 0, 59); |
585 | 5.62k | flag(hours_flag); |
586 | 5.19k | if (current->hours_flag) |
587 | 5.19k | u(5, hours_value, 0, 23); |
588 | 5.19k | } |
589 | 8.72k | } |
590 | 81.9k | } |
591 | | |
592 | 82.9k | if (sps->vui.nal_hrd_parameters_present_flag) |
593 | 71.1k | time_offset_length = sps->vui.nal_hrd_parameters.time_offset_length; |
594 | 11.8k | else if (sps->vui.vcl_hrd_parameters_present_flag) |
595 | 5.36k | time_offset_length = sps->vui.vcl_hrd_parameters.time_offset_length; |
596 | 6.45k | else |
597 | 6.45k | time_offset_length = 24; |
598 | | |
599 | 82.9k | if (time_offset_length > 0) |
600 | 82.9k | ib(time_offset_length, time_offset); |
601 | 2.44k | else |
602 | 2.44k | infer(time_offset, 0); |
603 | | |
604 | 79.1k | return 0; |
605 | 82.9k | } cbs_h264.c:cbs_h264_read_sei_pic_timestamp Line | Count | Source | 563 | 46.7k | { | 564 | 46.7k | uint8_t time_offset_length; | 565 | 46.7k | int err; | 566 | | | 567 | 46.7k | u(2, ct_type, 0, 2); | 568 | 46.0k | flag(nuit_field_based_flag); | 569 | 45.5k | u(5, counting_type, 0, 6); | 570 | 44.2k | flag(full_timestamp_flag); | 571 | 43.4k | flag(discontinuity_flag); | 572 | 42.9k | flag(cnt_dropped_flag); | 573 | 41.9k | ub(8, n_frames); | 574 | 41.0k | if (current->full_timestamp_flag) { | 575 | 4.38k | u(6, seconds_value, 0, 59); | 576 | 3.93k | u(6, minutes_value, 0, 59); | 577 | 3.39k | u(5, hours_value, 0, 23); | 578 | 36.6k | } else { | 579 | 36.6k | flag(seconds_flag); | 580 | 35.9k | if (current->seconds_flag) { | 581 | 6.96k | u(6, seconds_value, 0, 59); | 582 | 6.41k | flag(minutes_flag); | 583 | 5.90k | if (current->minutes_flag) { | 584 | 4.55k | u(6, minutes_value, 0, 59); | 585 | 4.05k | flag(hours_flag); | 586 | 3.62k | if (current->hours_flag) | 587 | 3.62k | u(5, hours_value, 0, 23); | 588 | 3.62k | } | 589 | 5.90k | } | 590 | 35.9k | } | 591 | | | 592 | 35.9k | if (sps->vui.nal_hrd_parameters_present_flag) | 593 | 27.0k | time_offset_length = sps->vui.nal_hrd_parameters.time_offset_length; | 594 | 8.90k | else if (sps->vui.vcl_hrd_parameters_present_flag) | 595 | 3.65k | time_offset_length = sps->vui.vcl_hrd_parameters.time_offset_length; | 596 | 5.24k | else | 597 | 5.24k | time_offset_length = 24; | 598 | | | 599 | 35.9k | if (time_offset_length > 0) | 600 | 35.9k | ib(time_offset_length, time_offset); | 601 | 1.59k | else | 602 | 1.59k | infer(time_offset, 0); | 603 | | | 604 | 33.5k | return 0; | 605 | 35.9k | } |
cbs_h264.c:cbs_h264_write_sei_pic_timestamp Line | Count | Source | 563 | 47.0k | { | 564 | 47.0k | uint8_t time_offset_length; | 565 | 47.0k | int err; | 566 | | | 567 | 47.0k | u(2, ct_type, 0, 2); | 568 | 47.0k | flag(nuit_field_based_flag); | 569 | 47.0k | u(5, counting_type, 0, 6); | 570 | 47.0k | flag(full_timestamp_flag); | 571 | 47.0k | flag(discontinuity_flag); | 572 | 47.0k | flag(cnt_dropped_flag); | 573 | 47.0k | ub(8, n_frames); | 574 | 47.0k | if (current->full_timestamp_flag) { | 575 | 1.05k | u(6, seconds_value, 0, 59); | 576 | 1.05k | u(6, minutes_value, 0, 59); | 577 | 1.05k | u(5, hours_value, 0, 23); | 578 | 45.9k | } else { | 579 | 45.9k | flag(seconds_flag); | 580 | 45.9k | if (current->seconds_flag) { | 581 | 2.82k | u(6, seconds_value, 0, 59); | 582 | 2.82k | flag(minutes_flag); | 583 | 2.82k | if (current->minutes_flag) { | 584 | 1.57k | u(6, minutes_value, 0, 59); | 585 | 1.57k | flag(hours_flag); | 586 | 1.57k | if (current->hours_flag) | 587 | 1.57k | u(5, hours_value, 0, 23); | 588 | 1.57k | } | 589 | 2.82k | } | 590 | 45.9k | } | 591 | | | 592 | 47.0k | if (sps->vui.nal_hrd_parameters_present_flag) | 593 | 44.1k | time_offset_length = sps->vui.nal_hrd_parameters.time_offset_length; | 594 | 2.90k | else if (sps->vui.vcl_hrd_parameters_present_flag) | 595 | 1.70k | time_offset_length = sps->vui.vcl_hrd_parameters.time_offset_length; | 596 | 1.20k | else | 597 | 1.20k | time_offset_length = 24; | 598 | | | 599 | 47.0k | if (time_offset_length > 0) | 600 | 47.0k | ib(time_offset_length, time_offset); | 601 | 849 | else | 602 | 849 | infer(time_offset, 0); | 603 | | | 604 | 45.6k | return 0; | 605 | 47.0k | } |
|
606 | | |
607 | | SEI_FUNC(sei_pic_timing, (CodedBitstreamContext *ctx, RWContext *rw, |
608 | | H264RawSEIPicTiming *current, SEIMessageState *sei)) |
609 | 204M | { |
610 | 204M | CodedBitstreamH264Context *h264 = ctx->priv_data; |
611 | 204M | const H264RawSPS *sps; |
612 | 204M | int err; |
613 | | |
614 | 204M | HEADER("Picture Timing"); |
615 | | |
616 | 204M | sps = h264->active_sps; |
617 | 204M | if (!sps) { |
618 | | // If there is exactly one possible SPS but it is not yet active |
619 | | // then just assume that it should be the active one. |
620 | 191M | int i, k = -1; |
621 | 6.30G | for (i = 0; i < H264_MAX_SPS_COUNT; i++) { |
622 | 6.11G | if (h264->sps[i]) { |
623 | 191M | if (k >= 0) { |
624 | 4.33k | k = -1; |
625 | 4.33k | break; |
626 | 4.33k | } |
627 | 191M | k = i; |
628 | 191M | } |
629 | 6.11G | } |
630 | 191M | if (k >= 0) |
631 | 191M | sps = h264->sps[k]; |
632 | 191M | } |
633 | 204M | if (!sps) { |
634 | 7.59k | av_log(ctx->log_ctx, AV_LOG_ERROR, |
635 | 7.59k | "No active SPS for pic_timing.\n"); |
636 | 7.59k | return AVERROR_INVALIDDATA; |
637 | 7.59k | } |
638 | | |
639 | 204M | if (sps->vui.nal_hrd_parameters_present_flag || |
640 | 165M | sps->vui.vcl_hrd_parameters_present_flag) { |
641 | 165M | const H264RawHRD *hrd; |
642 | | |
643 | 165M | if (sps->vui.nal_hrd_parameters_present_flag) |
644 | 165M | hrd = &sps->vui.nal_hrd_parameters; |
645 | 12.0k | else if (sps->vui.vcl_hrd_parameters_present_flag) |
646 | 12.0k | hrd = &sps->vui.vcl_hrd_parameters; |
647 | 0 | else { |
648 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, |
649 | 0 | "No HRD parameters for pic_timing.\n"); |
650 | 0 | return AVERROR_INVALIDDATA; |
651 | 0 | } |
652 | | |
653 | 165M | ub(hrd->cpb_removal_delay_length_minus1 + 1, cpb_removal_delay); |
654 | 165M | ub(hrd->dpb_output_delay_length_minus1 + 1, dpb_output_delay); |
655 | 165M | } |
656 | | |
657 | 204M | if (sps->vui.pic_struct_present_flag) { |
658 | 72.7M | static const uint8_t num_clock_ts[9] = { |
659 | 72.7M | 1, 1, 1, 2, 2, 3, 3, 2, 3 |
660 | 72.7M | }; |
661 | 72.7M | int i; |
662 | | |
663 | 72.7M | u(4, pic_struct, 0, 8); |
664 | 72.7M | if (current->pic_struct > 8) |
665 | 0 | return AVERROR_INVALIDDATA; |
666 | | |
667 | 145M | for (i = 0; i < num_clock_ts[current->pic_struct]; i++) { |
668 | 72.7M | flags(clock_timestamp_flag[i], 1, i); |
669 | 72.7M | if (current->clock_timestamp_flag[i]) |
670 | 93.7k | CHECK(FUNC(sei_pic_timestamp)(ctx, rw, |
671 | 72.7M | ¤t->timestamp[i], sps)); |
672 | 72.7M | } |
673 | 72.7M | } |
674 | | |
675 | 204M | return 0; |
676 | 204M | } cbs_h264.c:cbs_h264_read_sei_pic_timing Line | Count | Source | 609 | 43.7M | { | 610 | 43.7M | CodedBitstreamH264Context *h264 = ctx->priv_data; | 611 | 43.7M | const H264RawSPS *sps; | 612 | 43.7M | int err; | 613 | | | 614 | 43.7M | HEADER("Picture Timing"); | 615 | | | 616 | 43.7M | sps = h264->active_sps; | 617 | 43.7M | if (!sps) { | 618 | | // If there is exactly one possible SPS but it is not yet active | 619 | | // then just assume that it should be the active one. | 620 | 33.4M | int i, k = -1; | 621 | 1.10G | for (i = 0; i < H264_MAX_SPS_COUNT; i++) { | 622 | 1.07G | if (h264->sps[i]) { | 623 | 33.4M | if (k >= 0) { | 624 | 3.88k | k = -1; | 625 | 3.88k | break; | 626 | 3.88k | } | 627 | 33.4M | k = i; | 628 | 33.4M | } | 629 | 1.07G | } | 630 | 33.4M | if (k >= 0) | 631 | 33.4M | sps = h264->sps[k]; | 632 | 33.4M | } | 633 | 43.7M | if (!sps) { | 634 | 6.59k | av_log(ctx->log_ctx, AV_LOG_ERROR, | 635 | 6.59k | "No active SPS for pic_timing.\n"); | 636 | 6.59k | return AVERROR_INVALIDDATA; | 637 | 6.59k | } | 638 | | | 639 | 43.7M | if (sps->vui.nal_hrd_parameters_present_flag || | 640 | 39.1M | sps->vui.vcl_hrd_parameters_present_flag) { | 641 | 4.62M | const H264RawHRD *hrd; | 642 | | | 643 | 4.62M | if (sps->vui.nal_hrd_parameters_present_flag) | 644 | 4.61M | hrd = &sps->vui.nal_hrd_parameters; | 645 | 9.18k | else if (sps->vui.vcl_hrd_parameters_present_flag) | 646 | 9.18k | hrd = &sps->vui.vcl_hrd_parameters; | 647 | 0 | else { | 648 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, | 649 | 0 | "No HRD parameters for pic_timing.\n"); | 650 | 0 | return AVERROR_INVALIDDATA; | 651 | 0 | } | 652 | | | 653 | 4.62M | ub(hrd->cpb_removal_delay_length_minus1 + 1, cpb_removal_delay); | 654 | 4.62M | ub(hrd->dpb_output_delay_length_minus1 + 1, dpb_output_delay); | 655 | 4.62M | } | 656 | | | 657 | 43.7M | if (sps->vui.pic_struct_present_flag) { | 658 | 4.64M | static const uint8_t num_clock_ts[9] = { | 659 | 4.64M | 1, 1, 1, 2, 2, 3, 3, 2, 3 | 660 | 4.64M | }; | 661 | 4.64M | int i; | 662 | | | 663 | 4.64M | u(4, pic_struct, 0, 8); | 664 | 4.63M | if (current->pic_struct > 8) | 665 | 0 | return AVERROR_INVALIDDATA; | 666 | | | 667 | 9.27M | for (i = 0; i < num_clock_ts[current->pic_struct]; i++) { | 668 | 4.65M | flags(clock_timestamp_flag[i], 1, i); | 669 | 4.65M | if (current->clock_timestamp_flag[i]) | 670 | 46.7k | CHECK(FUNC(sei_pic_timestamp)(ctx, rw, | 671 | 4.65M | ¤t->timestamp[i], sps)); | 672 | 4.65M | } | 673 | 4.63M | } | 674 | | | 675 | 43.7M | return 0; | 676 | 43.7M | } |
cbs_h264.c:cbs_h264_write_sei_pic_timing Line | Count | Source | 609 | 161M | { | 610 | 161M | CodedBitstreamH264Context *h264 = ctx->priv_data; | 611 | 161M | const H264RawSPS *sps; | 612 | 161M | int err; | 613 | | | 614 | 161M | HEADER("Picture Timing"); | 615 | | | 616 | 161M | sps = h264->active_sps; | 617 | 161M | if (!sps) { | 618 | | // If there is exactly one possible SPS but it is not yet active | 619 | | // then just assume that it should be the active one. | 620 | 157M | int i, k = -1; | 621 | 5.20G | for (i = 0; i < H264_MAX_SPS_COUNT; i++) { | 622 | 5.04G | if (h264->sps[i]) { | 623 | 157M | if (k >= 0) { | 624 | 444 | k = -1; | 625 | 444 | break; | 626 | 444 | } | 627 | 157M | k = i; | 628 | 157M | } | 629 | 5.04G | } | 630 | 157M | if (k >= 0) | 631 | 157M | sps = h264->sps[k]; | 632 | 157M | } | 633 | 161M | if (!sps) { | 634 | 1.00k | av_log(ctx->log_ctx, AV_LOG_ERROR, | 635 | 1.00k | "No active SPS for pic_timing.\n"); | 636 | 1.00k | return AVERROR_INVALIDDATA; | 637 | 1.00k | } | 638 | | | 639 | 161M | if (sps->vui.nal_hrd_parameters_present_flag || | 640 | 161M | sps->vui.vcl_hrd_parameters_present_flag) { | 641 | 161M | const H264RawHRD *hrd; | 642 | | | 643 | 161M | if (sps->vui.nal_hrd_parameters_present_flag) | 644 | 160M | hrd = &sps->vui.nal_hrd_parameters; | 645 | 2.88k | else if (sps->vui.vcl_hrd_parameters_present_flag) | 646 | 2.88k | hrd = &sps->vui.vcl_hrd_parameters; | 647 | 0 | else { | 648 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, | 649 | 0 | "No HRD parameters for pic_timing.\n"); | 650 | 0 | return AVERROR_INVALIDDATA; | 651 | 0 | } | 652 | | | 653 | 161M | ub(hrd->cpb_removal_delay_length_minus1 + 1, cpb_removal_delay); | 654 | 161M | ub(hrd->dpb_output_delay_length_minus1 + 1, dpb_output_delay); | 655 | 161M | } | 656 | | | 657 | 161M | if (sps->vui.pic_struct_present_flag) { | 658 | 68.0M | static const uint8_t num_clock_ts[9] = { | 659 | 68.0M | 1, 1, 1, 2, 2, 3, 3, 2, 3 | 660 | 68.0M | }; | 661 | 68.0M | int i; | 662 | | | 663 | 68.0M | u(4, pic_struct, 0, 8); | 664 | 68.0M | if (current->pic_struct > 8) | 665 | 0 | return AVERROR_INVALIDDATA; | 666 | | | 667 | 136M | for (i = 0; i < num_clock_ts[current->pic_struct]; i++) { | 668 | 68.0M | flags(clock_timestamp_flag[i], 1, i); | 669 | 68.0M | if (current->clock_timestamp_flag[i]) | 670 | 47.0k | CHECK(FUNC(sei_pic_timestamp)(ctx, rw, | 671 | 68.0M | ¤t->timestamp[i], sps)); | 672 | 68.0M | } | 673 | 68.0M | } | 674 | | | 675 | 161M | return 0; | 676 | 161M | } |
|
677 | | |
678 | | SEI_FUNC(sei_pan_scan_rect, (CodedBitstreamContext *ctx, RWContext *rw, |
679 | | H264RawSEIPanScanRect *current, |
680 | | SEIMessageState *sei)) |
681 | 101k | { |
682 | 101k | int err, i; |
683 | | |
684 | 101k | HEADER("Pan-Scan Rectangle"); |
685 | | |
686 | 101k | ue(pan_scan_rect_id, 0, UINT32_MAX - 1); |
687 | 100k | flag(pan_scan_rect_cancel_flag); |
688 | | |
689 | 100k | if (!current->pan_scan_rect_cancel_flag) { |
690 | 85.1k | ue(pan_scan_cnt_minus1, 0, 2); |
691 | | |
692 | 281k | for (i = 0; i <= current->pan_scan_cnt_minus1; i++) { |
693 | 201k | ses(pan_scan_rect_left_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); |
694 | 201k | ses(pan_scan_rect_right_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); |
695 | 200k | ses(pan_scan_rect_top_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); |
696 | 199k | ses(pan_scan_rect_bottom_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); |
697 | 199k | } |
698 | | |
699 | 79.4k | ue(pan_scan_rect_repetition_period, 0, 16384); |
700 | 79.4k | } |
701 | | |
702 | 93.5k | return 0; |
703 | 100k | } cbs_h264.c:cbs_h264_read_sei_pan_scan_rect Line | Count | Source | 681 | 53.1k | { | 682 | 53.1k | int err, i; | 683 | | | 684 | 53.1k | HEADER("Pan-Scan Rectangle"); | 685 | | | 686 | 53.1k | ue(pan_scan_rect_id, 0, UINT32_MAX - 1); | 687 | 51.9k | flag(pan_scan_rect_cancel_flag); | 688 | | | 689 | 51.9k | if (!current->pan_scan_rect_cancel_flag) { | 690 | 43.3k | ue(pan_scan_cnt_minus1, 0, 2); | 691 | | | 692 | 142k | for (i = 0; i <= current->pan_scan_cnt_minus1; i++) { | 693 | 104k | ses(pan_scan_rect_left_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); | 694 | 103k | ses(pan_scan_rect_right_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); | 695 | 102k | ses(pan_scan_rect_top_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); | 696 | 101k | ses(pan_scan_rect_bottom_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); | 697 | 101k | } | 698 | | | 699 | 37.7k | ue(pan_scan_rect_repetition_period, 0, 16384); | 700 | 37.7k | } | 701 | | | 702 | 45.3k | return 0; | 703 | 51.9k | } |
cbs_h264.c:cbs_h264_write_sei_pan_scan_rect Line | Count | Source | 681 | 48.2k | { | 682 | 48.2k | int err, i; | 683 | | | 684 | 48.2k | HEADER("Pan-Scan Rectangle"); | 685 | | | 686 | 48.2k | ue(pan_scan_rect_id, 0, UINT32_MAX - 1); | 687 | 48.2k | flag(pan_scan_rect_cancel_flag); | 688 | | | 689 | 48.2k | if (!current->pan_scan_rect_cancel_flag) { | 690 | 41.7k | ue(pan_scan_cnt_minus1, 0, 2); | 691 | | | 692 | 139k | for (i = 0; i <= current->pan_scan_cnt_minus1; i++) { | 693 | 97.3k | ses(pan_scan_rect_left_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); | 694 | 97.3k | ses(pan_scan_rect_right_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); | 695 | 97.3k | ses(pan_scan_rect_top_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); | 696 | 97.3k | ses(pan_scan_rect_bottom_offset[i], INT32_MIN + 1, INT32_MAX, 1, i); | 697 | 97.3k | } | 698 | | | 699 | 41.7k | ue(pan_scan_rect_repetition_period, 0, 16384); | 700 | 41.7k | } | 701 | | | 702 | 48.2k | return 0; | 703 | 48.2k | } |
|
704 | | |
705 | | SEI_FUNC(sei_recovery_point, (CodedBitstreamContext *ctx, RWContext *rw, |
706 | | H264RawSEIRecoveryPoint *current, |
707 | | SEIMessageState *sei)) |
708 | 6.93k | { |
709 | 6.93k | int err; |
710 | | |
711 | 6.93k | HEADER("Recovery Point"); |
712 | | |
713 | 6.93k | ue(recovery_frame_cnt, 0, 65535); |
714 | 5.59k | flag(exact_match_flag); |
715 | 5.59k | flag(broken_link_flag); |
716 | 4.79k | u(2, changing_slice_group_idc, 0, 2); |
717 | | |
718 | 3.59k | return 0; |
719 | 4.79k | } cbs_h264.c:cbs_h264_read_sei_recovery_point Line | Count | Source | 708 | 6.03k | { | 709 | 6.03k | int err; | 710 | | | 711 | 6.03k | HEADER("Recovery Point"); | 712 | | | 713 | 6.03k | ue(recovery_frame_cnt, 0, 65535); | 714 | 4.69k | flag(exact_match_flag); | 715 | 4.69k | flag(broken_link_flag); | 716 | 3.88k | u(2, changing_slice_group_idc, 0, 2); | 717 | | | 718 | 2.68k | return 0; | 719 | 3.88k | } |
cbs_h264.c:cbs_h264_write_sei_recovery_point Line | Count | Source | 708 | 906 | { | 709 | 906 | int err; | 710 | | | 711 | 906 | HEADER("Recovery Point"); | 712 | | | 713 | 906 | ue(recovery_frame_cnt, 0, 65535); | 714 | 904 | flag(exact_match_flag); | 715 | 904 | flag(broken_link_flag); | 716 | 902 | u(2, changing_slice_group_idc, 0, 2); | 717 | | | 718 | 902 | return 0; | 719 | 902 | } |
|
720 | | |
721 | | SEI_FUNC(film_grain_characteristics, (CodedBitstreamContext *ctx, RWContext *rw, |
722 | | H264RawFilmGrainCharacteristics *current, |
723 | | SEIMessageState *state)) |
724 | 45.1k | { |
725 | 45.1k | CodedBitstreamH264Context *h264 = ctx->priv_data; |
726 | 45.1k | const H264RawSPS *sps; |
727 | 45.1k | int err, c, i, j; |
728 | | |
729 | 45.1k | HEADER("Film Grain Characteristics"); |
730 | | |
731 | 45.1k | sps = h264->active_sps; |
732 | 45.1k | if (!sps) { |
733 | | // If there is exactly one possible SPS but it is not yet active |
734 | | // then just assume that it should be the active one. |
735 | 33.9k | int i, k = -1; |
736 | 993k | for (i = 0; i < H264_MAX_SPS_COUNT; i++) { |
737 | 964k | if (h264->sps[i]) { |
738 | 32.2k | if (k >= 0) { |
739 | 4.84k | k = -1; |
740 | 4.84k | break; |
741 | 4.84k | } |
742 | 27.4k | k = i; |
743 | 27.4k | } |
744 | 964k | } |
745 | 33.9k | if (k >= 0) |
746 | 22.6k | sps = h264->sps[k]; |
747 | 33.9k | } |
748 | | |
749 | 45.1k | flag(film_grain_characteristics_cancel_flag); |
750 | 44.2k | if (!current->film_grain_characteristics_cancel_flag) { |
751 | 39.4k | int filmGrainBitDepth[3]; |
752 | | |
753 | 39.4k | u(2, film_grain_model_id, 0, 1); |
754 | 38.8k | flag(separate_colour_description_present_flag); |
755 | 38.8k | if (current->separate_colour_description_present_flag) { |
756 | 13.8k | ub(3, film_grain_bit_depth_luma_minus8); |
757 | 13.8k | ub(3, film_grain_bit_depth_chroma_minus8); |
758 | 12.1k | flag(film_grain_full_range_flag); |
759 | 12.1k | ub(8, film_grain_colour_primaries); |
760 | 11.3k | ub(8, film_grain_transfer_characteristics); |
761 | 10.4k | ub(8, film_grain_matrix_coefficients); |
762 | 24.9k | } else { |
763 | 24.9k | if (!sps) { |
764 | 3.65k | av_log(ctx->log_ctx, AV_LOG_ERROR, |
765 | 3.65k | "No active SPS for film_grain_characteristics.\n"); |
766 | 3.65k | return AVERROR_INVALIDDATA; |
767 | 3.65k | } |
768 | 21.2k | infer(film_grain_bit_depth_luma_minus8, sps->bit_depth_luma_minus8); |
769 | 20.8k | infer(film_grain_bit_depth_chroma_minus8, sps->bit_depth_chroma_minus8); |
770 | 20.4k | infer(film_grain_full_range_flag, sps->vui.video_full_range_flag); |
771 | 19.9k | infer(film_grain_colour_primaries, sps->vui.colour_primaries); |
772 | 19.4k | infer(film_grain_transfer_characteristics, sps->vui.transfer_characteristics); |
773 | 19.0k | infer(film_grain_matrix_coefficients, sps->vui.matrix_coefficients); |
774 | 3.51k | } |
775 | | |
776 | 28.5k | filmGrainBitDepth[0] = current->film_grain_bit_depth_luma_minus8 + 8; |
777 | 28.5k | filmGrainBitDepth[1] = |
778 | 28.5k | filmGrainBitDepth[2] = current->film_grain_bit_depth_chroma_minus8 + 8; |
779 | | |
780 | 28.5k | u(2, blending_mode_id, 0, 1); |
781 | 26.9k | ub(4, log2_scale_factor); |
782 | 104k | for (c = 0; c < 3; c++) |
783 | 78.1k | flags(comp_model_present_flag[c], 1, c); |
784 | 80.2k | for (c = 0; c < 3; c++) { |
785 | 64.2k | if (current->comp_model_present_flag[c]) { |
786 | 17.8k | ubs(8, num_intensity_intervals_minus1[c], 1, c); |
787 | 15.4k | us(3, num_model_values_minus1[c], 0, 5, 1, c); |
788 | 33.7k | for (i = 0; i <= current->num_intensity_intervals_minus1[c]; i++) { |
789 | 25.9k | ubs(8, intensity_interval_lower_bound[c][i], 2, c, i); |
790 | 25.3k | ubs(8, intensity_interval_upper_bound[c][i], 2, c, i); |
791 | 64.7k | for (j = 0; j <= current->num_model_values_minus1[c]; j++) |
792 | 44.4k | ses(comp_model_value[c][i][j], 0 - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)), |
793 | 23.6k | ((1 << filmGrainBitDepth[c]) - 1) - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)), |
794 | 23.6k | 3, c, i, j); |
795 | 23.6k | } |
796 | 13.4k | } |
797 | 64.2k | } |
798 | 16.0k | ue(film_grain_characteristics_repetition_period, 0, 16384); |
799 | 16.0k | } |
800 | | |
801 | 20.0k | return 0; |
802 | 44.2k | } cbs_h264.c:cbs_h264_read_film_grain_characteristics Line | Count | Source | 724 | 36.0k | { | 725 | 36.0k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 726 | 36.0k | const H264RawSPS *sps; | 727 | 36.0k | int err, c, i, j; | 728 | | | 729 | 36.0k | HEADER("Film Grain Characteristics"); | 730 | | | 731 | 36.0k | sps = h264->active_sps; | 732 | 36.0k | if (!sps) { | 733 | | // If there is exactly one possible SPS but it is not yet active | 734 | | // then just assume that it should be the active one. | 735 | 25.6k | int i, k = -1; | 736 | 735k | for (i = 0; i < H264_MAX_SPS_COUNT; i++) { | 737 | 714k | if (h264->sps[i]) { | 738 | 24.8k | if (k >= 0) { | 739 | 4.06k | k = -1; | 740 | 4.06k | break; | 741 | 4.06k | } | 742 | 20.8k | k = i; | 743 | 20.8k | } | 744 | 714k | } | 745 | 25.6k | if (k >= 0) | 746 | 16.7k | sps = h264->sps[k]; | 747 | 25.6k | } | 748 | | | 749 | 36.0k | flag(film_grain_characteristics_cancel_flag); | 750 | 35.2k | if (!current->film_grain_characteristics_cancel_flag) { | 751 | 31.8k | int filmGrainBitDepth[3]; | 752 | | | 753 | 31.8k | u(2, film_grain_model_id, 0, 1); | 754 | 31.1k | flag(separate_colour_description_present_flag); | 755 | 31.1k | if (current->separate_colour_description_present_flag) { | 756 | 12.4k | ub(3, film_grain_bit_depth_luma_minus8); | 757 | 12.4k | ub(3, film_grain_bit_depth_chroma_minus8); | 758 | 10.6k | flag(film_grain_full_range_flag); | 759 | 10.6k | ub(8, film_grain_colour_primaries); | 760 | 9.90k | ub(8, film_grain_transfer_characteristics); | 761 | 9.01k | ub(8, film_grain_matrix_coefficients); | 762 | 18.7k | } else { | 763 | 18.7k | if (!sps) { | 764 | 3.20k | av_log(ctx->log_ctx, AV_LOG_ERROR, | 765 | 3.20k | "No active SPS for film_grain_characteristics.\n"); | 766 | 3.20k | return AVERROR_INVALIDDATA; | 767 | 3.20k | } | 768 | 15.5k | infer(film_grain_bit_depth_luma_minus8, sps->bit_depth_luma_minus8); | 769 | 15.5k | infer(film_grain_bit_depth_chroma_minus8, sps->bit_depth_chroma_minus8); | 770 | 15.5k | infer(film_grain_full_range_flag, sps->vui.video_full_range_flag); | 771 | 15.5k | infer(film_grain_colour_primaries, sps->vui.colour_primaries); | 772 | 15.5k | infer(film_grain_transfer_characteristics, sps->vui.transfer_characteristics); | 773 | 15.5k | infer(film_grain_matrix_coefficients, sps->vui.matrix_coefficients); | 774 | 15.5k | } | 775 | | | 776 | 24.0k | filmGrainBitDepth[0] = current->film_grain_bit_depth_luma_minus8 + 8; | 777 | 24.0k | filmGrainBitDepth[1] = | 778 | 24.0k | filmGrainBitDepth[2] = current->film_grain_bit_depth_chroma_minus8 + 8; | 779 | | | 780 | 24.0k | u(2, blending_mode_id, 0, 1); | 781 | 22.3k | ub(4, log2_scale_factor); | 782 | 85.9k | for (c = 0; c < 3; c++) | 783 | 64.4k | flags(comp_model_present_flag[c], 1, c); | 784 | 62.0k | for (c = 0; c < 3; c++) { | 785 | 50.5k | if (current->comp_model_present_flag[c]) { | 786 | 15.1k | ubs(8, num_intensity_intervals_minus1[c], 1, c); | 787 | 12.7k | us(3, num_model_values_minus1[c], 0, 5, 1, c); | 788 | 25.7k | for (i = 0; i <= current->num_intensity_intervals_minus1[c]; i++) { | 789 | 20.5k | ubs(8, intensity_interval_lower_bound[c][i], 2, c, i); | 790 | 20.0k | ubs(8, intensity_interval_upper_bound[c][i], 2, c, i); | 791 | 46.0k | for (j = 0; j <= current->num_model_values_minus1[c]; j++) | 792 | 31.0k | ses(comp_model_value[c][i][j], 0 - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)), | 793 | 18.3k | ((1 << filmGrainBitDepth[c]) - 1) - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)), | 794 | 18.3k | 3, c, i, j); | 795 | 18.3k | } | 796 | 10.8k | } | 797 | 50.5k | } | 798 | 11.4k | ue(film_grain_characteristics_repetition_period, 0, 16384); | 799 | 11.4k | } | 800 | | | 801 | 14.1k | return 0; | 802 | 35.2k | } |
cbs_h264.c:cbs_h264_write_film_grain_characteristics Line | Count | Source | 724 | 9.03k | { | 725 | 9.03k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 726 | 9.03k | const H264RawSPS *sps; | 727 | 9.03k | int err, c, i, j; | 728 | | | 729 | 9.03k | HEADER("Film Grain Characteristics"); | 730 | | | 731 | 9.03k | sps = h264->active_sps; | 732 | 9.03k | if (!sps) { | 733 | | // If there is exactly one possible SPS but it is not yet active | 734 | | // then just assume that it should be the active one. | 735 | 8.34k | int i, k = -1; | 736 | 257k | for (i = 0; i < H264_MAX_SPS_COUNT; i++) { | 737 | 250k | if (h264->sps[i]) { | 738 | 7.40k | if (k >= 0) { | 739 | 776 | k = -1; | 740 | 776 | break; | 741 | 776 | } | 742 | 6.62k | k = i; | 743 | 6.62k | } | 744 | 250k | } | 745 | 8.34k | if (k >= 0) | 746 | 5.85k | sps = h264->sps[k]; | 747 | 8.34k | } | 748 | | | 749 | 9.03k | flag(film_grain_characteristics_cancel_flag); | 750 | 9.03k | if (!current->film_grain_characteristics_cancel_flag) { | 751 | 7.61k | int filmGrainBitDepth[3]; | 752 | | | 753 | 7.61k | u(2, film_grain_model_id, 0, 1); | 754 | 7.61k | flag(separate_colour_description_present_flag); | 755 | 7.61k | if (current->separate_colour_description_present_flag) { | 756 | 1.46k | ub(3, film_grain_bit_depth_luma_minus8); | 757 | 1.46k | ub(3, film_grain_bit_depth_chroma_minus8); | 758 | 1.45k | flag(film_grain_full_range_flag); | 759 | 1.45k | ub(8, film_grain_colour_primaries); | 760 | 1.45k | ub(8, film_grain_transfer_characteristics); | 761 | 1.45k | ub(8, film_grain_matrix_coefficients); | 762 | 6.14k | } else { | 763 | 6.14k | if (!sps) { | 764 | 452 | av_log(ctx->log_ctx, AV_LOG_ERROR, | 765 | 452 | "No active SPS for film_grain_characteristics.\n"); | 766 | 452 | return AVERROR_INVALIDDATA; | 767 | 452 | } | 768 | 5.69k | infer(film_grain_bit_depth_luma_minus8, sps->bit_depth_luma_minus8); | 769 | 5.23k | infer(film_grain_bit_depth_chroma_minus8, sps->bit_depth_chroma_minus8); | 770 | 4.83k | infer(film_grain_full_range_flag, sps->vui.video_full_range_flag); | 771 | 4.34k | infer(film_grain_colour_primaries, sps->vui.colour_primaries); | 772 | 3.91k | infer(film_grain_transfer_characteristics, sps->vui.transfer_characteristics); | 773 | 3.51k | infer(film_grain_matrix_coefficients, sps->vui.matrix_coefficients); | 774 | 3.51k | } | 775 | | | 776 | 4.55k | filmGrainBitDepth[0] = current->film_grain_bit_depth_luma_minus8 + 8; | 777 | 4.55k | filmGrainBitDepth[1] = | 778 | 4.55k | filmGrainBitDepth[2] = current->film_grain_bit_depth_chroma_minus8 + 8; | 779 | | | 780 | 4.55k | u(2, blending_mode_id, 0, 1); | 781 | 4.55k | ub(4, log2_scale_factor); | 782 | 18.2k | for (c = 0; c < 3; c++) | 783 | 13.6k | flags(comp_model_present_flag[c], 1, c); | 784 | 18.1k | for (c = 0; c < 3; c++) { | 785 | 13.6k | if (current->comp_model_present_flag[c]) { | 786 | 2.65k | ubs(8, num_intensity_intervals_minus1[c], 1, c); | 787 | 2.65k | us(3, num_model_values_minus1[c], 0, 5, 1, c); | 788 | 7.97k | for (i = 0; i <= current->num_intensity_intervals_minus1[c]; i++) { | 789 | 5.32k | ubs(8, intensity_interval_lower_bound[c][i], 2, c, i); | 790 | 5.32k | ubs(8, intensity_interval_upper_bound[c][i], 2, c, i); | 791 | 18.6k | for (j = 0; j <= current->num_model_values_minus1[c]; j++) | 792 | 13.3k | ses(comp_model_value[c][i][j], 0 - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)), | 793 | 5.32k | ((1 << filmGrainBitDepth[c]) - 1) - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)), | 794 | 5.32k | 3, c, i, j); | 795 | 5.32k | } | 796 | 2.65k | } | 797 | 13.6k | } | 798 | 4.54k | ue(film_grain_characteristics_repetition_period, 0, 16384); | 799 | 4.54k | } | 800 | | | 801 | 5.96k | return 0; | 802 | 9.03k | } |
|
803 | | |
804 | | SEI_FUNC(sei_frame_packing_arrangement, (CodedBitstreamContext *ctx, RWContext *rw, |
805 | | H264RawSEIFramePackingArrangement *current, |
806 | | SEIMessageState *sei)) |
807 | 13.8k | { |
808 | 13.8k | int err; |
809 | | |
810 | 13.8k | HEADER("Frame Packing Arrangement"); |
811 | | |
812 | 13.8k | ue(frame_packing_arrangement_id, 0, MAX_UINT_BITS(31)); |
813 | 13.4k | flag(frame_packing_arrangement_cancel_flag); |
814 | 13.4k | if (!current->frame_packing_arrangement_cancel_flag) { |
815 | 8.89k | u(7, frame_packing_arrangement_type, 0, 7); |
816 | 8.31k | flag(quincunx_sampling_flag); |
817 | 8.31k | u(6, content_interpretation_type, 0, 2); |
818 | 7.59k | flag(spatial_flipping_flag); |
819 | 7.20k | flag(frame0_flipped_flag); |
820 | 7.20k | flag(field_views_flag); |
821 | 6.80k | flag(current_frame_is_frame0_flag); |
822 | 6.80k | flag(frame0_self_contained_flag); |
823 | 6.40k | flag(frame1_self_contained_flag); |
824 | 6.40k | if (!current->quincunx_sampling_flag && current->frame_packing_arrangement_type != 5) { |
825 | 3.35k | ub(4, frame0_grid_position_x); |
826 | 2.88k | ub(4, frame0_grid_position_y); |
827 | 2.38k | ub(4, frame1_grid_position_x); |
828 | 1.99k | ub(4, frame1_grid_position_y); |
829 | 1.99k | } |
830 | 4.64k | fixed(8, frame_packing_arrangement_reserved_byte, 0); |
831 | 3.99k | ue(frame_packing_arrangement_repetition_period, 0, 16384); |
832 | 3.99k | } |
833 | 7.83k | flag(frame_packing_arrangement_extension_flag); |
834 | | |
835 | 7.37k | return 0; |
836 | 7.83k | } cbs_h264.c:cbs_h264_read_sei_frame_packing_arrangement Line | Count | Source | 807 | 11.0k | { | 808 | 11.0k | int err; | 809 | | | 810 | 11.0k | HEADER("Frame Packing Arrangement"); | 811 | | | 812 | 11.0k | ue(frame_packing_arrangement_id, 0, MAX_UINT_BITS(31)); | 813 | 10.6k | flag(frame_packing_arrangement_cancel_flag); | 814 | 10.6k | if (!current->frame_packing_arrangement_cancel_flag) { | 815 | 6.99k | u(7, frame_packing_arrangement_type, 0, 7); | 816 | 6.41k | flag(quincunx_sampling_flag); | 817 | 6.41k | u(6, content_interpretation_type, 0, 2); | 818 | 5.69k | flag(spatial_flipping_flag); | 819 | 5.30k | flag(frame0_flipped_flag); | 820 | 5.30k | flag(field_views_flag); | 821 | 4.90k | flag(current_frame_is_frame0_flag); | 822 | 4.90k | flag(frame0_self_contained_flag); | 823 | 4.50k | flag(frame1_self_contained_flag); | 824 | 4.50k | if (!current->quincunx_sampling_flag && current->frame_packing_arrangement_type != 5) { | 825 | 2.96k | ub(4, frame0_grid_position_x); | 826 | 2.49k | ub(4, frame0_grid_position_y); | 827 | 1.99k | ub(4, frame1_grid_position_x); | 828 | 1.60k | ub(4, frame1_grid_position_y); | 829 | 1.60k | } | 830 | 2.74k | fixed(8, frame_packing_arrangement_reserved_byte, 0); | 831 | 2.09k | ue(frame_packing_arrangement_repetition_period, 0, 16384); | 832 | 2.09k | } | 833 | 5.01k | flag(frame_packing_arrangement_extension_flag); | 834 | | | 835 | 4.55k | return 0; | 836 | 5.01k | } |
cbs_h264.c:cbs_h264_write_sei_frame_packing_arrangement Line | Count | Source | 807 | 2.81k | { | 808 | 2.81k | int err; | 809 | | | 810 | 2.81k | HEADER("Frame Packing Arrangement"); | 811 | | | 812 | 2.81k | ue(frame_packing_arrangement_id, 0, MAX_UINT_BITS(31)); | 813 | 2.81k | flag(frame_packing_arrangement_cancel_flag); | 814 | 2.81k | if (!current->frame_packing_arrangement_cancel_flag) { | 815 | 1.90k | u(7, frame_packing_arrangement_type, 0, 7); | 816 | 1.90k | flag(quincunx_sampling_flag); | 817 | 1.90k | u(6, content_interpretation_type, 0, 2); | 818 | 1.90k | flag(spatial_flipping_flag); | 819 | 1.90k | flag(frame0_flipped_flag); | 820 | 1.90k | flag(field_views_flag); | 821 | 1.90k | flag(current_frame_is_frame0_flag); | 822 | 1.90k | flag(frame0_self_contained_flag); | 823 | 1.90k | flag(frame1_self_contained_flag); | 824 | 1.90k | if (!current->quincunx_sampling_flag && current->frame_packing_arrangement_type != 5) { | 825 | 390 | ub(4, frame0_grid_position_x); | 826 | 390 | ub(4, frame0_grid_position_y); | 827 | 390 | ub(4, frame1_grid_position_x); | 828 | 390 | ub(4, frame1_grid_position_y); | 829 | 390 | } | 830 | 1.90k | fixed(8, frame_packing_arrangement_reserved_byte, 0); | 831 | 1.90k | ue(frame_packing_arrangement_repetition_period, 0, 16384); | 832 | 1.90k | } | 833 | 2.81k | flag(frame_packing_arrangement_extension_flag); | 834 | | | 835 | 2.81k | return 0; | 836 | 2.81k | } |
|
837 | | |
838 | | SEI_FUNC(sei_display_orientation, (CodedBitstreamContext *ctx, RWContext *rw, |
839 | | H264RawSEIDisplayOrientation *current, |
840 | | SEIMessageState *sei)) |
841 | 94.5k | { |
842 | 94.5k | int err; |
843 | | |
844 | 94.5k | HEADER("Display Orientation"); |
845 | | |
846 | 94.5k | flag(display_orientation_cancel_flag); |
847 | 93.7k | if (!current->display_orientation_cancel_flag) { |
848 | 89.3k | flag(hor_flip); |
849 | 89.3k | flag(ver_flip); |
850 | 89.3k | ub(16, anticlockwise_rotation); |
851 | 88.8k | ue(display_orientation_repetition_period, 0, 16384); |
852 | 87.1k | flag(display_orientation_extension_flag); |
853 | 87.1k | } |
854 | | |
855 | 90.8k | return 0; |
856 | 93.7k | } cbs_h264.c:cbs_h264_read_sei_display_orientation Line | Count | Source | 841 | 53.0k | { | 842 | 53.0k | int err; | 843 | | | 844 | 53.0k | HEADER("Display Orientation"); | 845 | | | 846 | 53.0k | flag(display_orientation_cancel_flag); | 847 | 52.1k | if (!current->display_orientation_cancel_flag) { | 848 | 50.2k | flag(hor_flip); | 849 | 50.2k | flag(ver_flip); | 850 | 50.2k | ub(16, anticlockwise_rotation); | 851 | 49.7k | ue(display_orientation_repetition_period, 0, 16384); | 852 | 48.0k | flag(display_orientation_extension_flag); | 853 | 48.0k | } | 854 | | | 855 | 49.2k | return 0; | 856 | 52.1k | } |
cbs_h264.c:cbs_h264_write_sei_display_orientation Line | Count | Source | 841 | 41.5k | { | 842 | 41.5k | int err; | 843 | | | 844 | 41.5k | HEADER("Display Orientation"); | 845 | | | 846 | 41.5k | flag(display_orientation_cancel_flag); | 847 | 41.5k | if (!current->display_orientation_cancel_flag) { | 848 | 39.0k | flag(hor_flip); | 849 | 39.0k | flag(ver_flip); | 850 | 39.0k | ub(16, anticlockwise_rotation); | 851 | 39.0k | ue(display_orientation_repetition_period, 0, 16384); | 852 | 39.0k | flag(display_orientation_extension_flag); | 853 | 39.0k | } | 854 | | | 855 | 41.5k | return 0; | 856 | 41.5k | } |
|
857 | | |
858 | | static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw, |
859 | | H264RawSEI *current) |
860 | 234k | { |
861 | 234k | int err; |
862 | | |
863 | 234k | HEADER("Supplemental Enhancement Information"); |
864 | | |
865 | 234k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, |
866 | 234k | 1 << H264_NAL_SEI)); |
867 | | |
868 | 234k | CHECK(FUNC_SEI(message_list)(ctx, rw, ¤t->message_list, 1)); |
869 | | |
870 | 35.9k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); |
871 | | |
872 | 35.9k | return 0; |
873 | 35.9k | } cbs_h264.c:cbs_h264_read_sei Line | Count | Source | 860 | 215k | { | 861 | 215k | int err; | 862 | | | 863 | 215k | HEADER("Supplemental Enhancement Information"); | 864 | | | 865 | 215k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 866 | 215k | 1 << H264_NAL_SEI)); | 867 | | | 868 | 215k | CHECK(FUNC_SEI(message_list)(ctx, rw, ¤t->message_list, 1)); | 869 | | | 870 | 25.2k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 871 | | | 872 | 25.2k | return 0; | 873 | 25.2k | } |
cbs_h264.c:cbs_h264_write_sei Line | Count | Source | 860 | 19.3k | { | 861 | 19.3k | int err; | 862 | | | 863 | 19.3k | HEADER("Supplemental Enhancement Information"); | 864 | | | 865 | 19.3k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 866 | 19.3k | 1 << H264_NAL_SEI)); | 867 | | | 868 | 19.3k | CHECK(FUNC_SEI(message_list)(ctx, rw, ¤t->message_list, 1)); | 869 | | | 870 | 10.7k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 871 | | | 872 | 10.7k | return 0; | 873 | 10.7k | } |
|
874 | | |
875 | | static int FUNC(aud)(CodedBitstreamContext *ctx, RWContext *rw, |
876 | | H264RawAUD *current) |
877 | 21.8k | { |
878 | 21.8k | int err; |
879 | | |
880 | 21.8k | HEADER("Access Unit Delimiter"); |
881 | | |
882 | 21.8k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, |
883 | 21.8k | 1 << H264_NAL_AUD)); |
884 | | |
885 | 21.8k | ub(3, primary_pic_type); |
886 | | |
887 | 16.1k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); |
888 | | |
889 | 8.71k | return 0; |
890 | 16.1k | } cbs_h264.c:cbs_h264_read_aud Line | Count | Source | 877 | 16.8k | { | 878 | 16.8k | int err; | 879 | | | 880 | 16.8k | HEADER("Access Unit Delimiter"); | 881 | | | 882 | 16.8k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 883 | 16.8k | 1 << H264_NAL_AUD)); | 884 | | | 885 | 16.8k | ub(3, primary_pic_type); | 886 | | | 887 | 11.1k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 888 | | | 889 | 3.71k | return 0; | 890 | 11.1k | } |
cbs_h264.c:cbs_h264_write_aud Line | Count | Source | 877 | 4.99k | { | 878 | 4.99k | int err; | 879 | | | 880 | 4.99k | HEADER("Access Unit Delimiter"); | 881 | | | 882 | 4.99k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 883 | 4.99k | 1 << H264_NAL_AUD)); | 884 | | | 885 | 4.99k | ub(3, primary_pic_type); | 886 | | | 887 | 4.99k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 888 | | | 889 | 4.99k | return 0; | 890 | 4.99k | } |
|
891 | | |
892 | | static int FUNC(ref_pic_list_modification)(CodedBitstreamContext *ctx, RWContext *rw, |
893 | | H264RawSliceHeader *current) |
894 | 614k | { |
895 | 614k | CodedBitstreamH264Context *h264 = ctx->priv_data; |
896 | 614k | const H264RawSPS *sps = h264->active_sps; |
897 | 614k | int err, i, mopn; |
898 | | |
899 | 614k | if (current->slice_type % 5 != 2 && |
900 | 546k | current->slice_type % 5 != 4) { |
901 | 538k | flag(ref_pic_list_modification_flag_l0); |
902 | 536k | if (current->ref_pic_list_modification_flag_l0) { |
903 | 710k | for (i = 0; i < H264_MAX_RPLM_COUNT; i++) { |
904 | 695k | xue(modification_of_pic_nums_idc, |
905 | 695k | current->rplm_l0[i].modification_of_pic_nums_idc, 0, 3, 0); |
906 | | |
907 | 673k | mopn = current->rplm_l0[i].modification_of_pic_nums_idc; |
908 | 673k | if (mopn == 3) |
909 | 6.38k | break; |
910 | | |
911 | 667k | if (mopn == 0 || mopn == 1) |
912 | 573k | xue(abs_diff_pic_num_minus1, |
913 | 667k | current->rplm_l0[i].abs_diff_pic_num_minus1, |
914 | 667k | 0, (1 + current->field_pic_flag) * |
915 | 667k | (1 << (sps->log2_max_frame_num_minus4 + 4)), 0); |
916 | 93.9k | else if (mopn == 2) |
917 | 93.9k | xue(long_term_pic_num, |
918 | 667k | current->rplm_l0[i].long_term_pic_num, |
919 | 667k | 0, sps->max_num_ref_frames - 1, 0); |
920 | 667k | } |
921 | 54.0k | } |
922 | 536k | } |
923 | | |
924 | 580k | if (current->slice_type % 5 == 1) { |
925 | 53.2k | flag(ref_pic_list_modification_flag_l1); |
926 | 52.0k | if (current->ref_pic_list_modification_flag_l1) { |
927 | 325k | for (i = 0; i < H264_MAX_RPLM_COUNT; i++) { |
928 | 318k | xue(modification_of_pic_nums_idc, |
929 | 318k | current->rplm_l1[i].modification_of_pic_nums_idc, 0, 3, 0); |
930 | | |
931 | 313k | mopn = current->rplm_l1[i].modification_of_pic_nums_idc; |
932 | 313k | if (mopn == 3) |
933 | 6.70k | break; |
934 | | |
935 | 306k | if (mopn == 0 || mopn == 1) |
936 | 229k | xue(abs_diff_pic_num_minus1, |
937 | 306k | current->rplm_l1[i].abs_diff_pic_num_minus1, |
938 | 306k | 0, (1 + current->field_pic_flag) * |
939 | 306k | (1 << (sps->log2_max_frame_num_minus4 + 4)), 0); |
940 | 77.0k | else if (mopn == 2) |
941 | 77.0k | xue(long_term_pic_num, |
942 | 306k | current->rplm_l1[i].long_term_pic_num, |
943 | 306k | 0, sps->max_num_ref_frames - 1, 0); |
944 | 306k | } |
945 | 21.8k | } |
946 | 52.0k | } |
947 | | |
948 | 571k | return 0; |
949 | 580k | } cbs_h264.c:cbs_h264_read_ref_pic_list_modification Line | Count | Source | 894 | 586k | { | 895 | 586k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 896 | 586k | const H264RawSPS *sps = h264->active_sps; | 897 | 586k | int err, i, mopn; | 898 | | | 899 | 586k | if (current->slice_type % 5 != 2 && | 900 | 523k | current->slice_type % 5 != 4) { | 901 | 516k | flag(ref_pic_list_modification_flag_l0); | 902 | 515k | if (current->ref_pic_list_modification_flag_l0) { | 903 | 620k | for (i = 0; i < H264_MAX_RPLM_COUNT; i++) { | 904 | 606k | xue(modification_of_pic_nums_idc, | 905 | 606k | current->rplm_l0[i].modification_of_pic_nums_idc, 0, 3, 0); | 906 | | | 907 | 585k | mopn = current->rplm_l0[i].modification_of_pic_nums_idc; | 908 | 585k | if (mopn == 3) | 909 | 4.60k | break; | 910 | | | 911 | 580k | if (mopn == 0 || mopn == 1) | 912 | 490k | xue(abs_diff_pic_num_minus1, | 913 | 580k | current->rplm_l0[i].abs_diff_pic_num_minus1, | 914 | 580k | 0, (1 + current->field_pic_flag) * | 915 | 580k | (1 << (sps->log2_max_frame_num_minus4 + 4)), 0); | 916 | 90.5k | else if (mopn == 2) | 917 | 90.5k | xue(long_term_pic_num, | 918 | 580k | current->rplm_l0[i].long_term_pic_num, | 919 | 580k | 0, sps->max_num_ref_frames - 1, 0); | 920 | 580k | } | 921 | 49.4k | } | 922 | 515k | } | 923 | | | 924 | 553k | if (current->slice_type % 5 == 1) { | 925 | 46.7k | flag(ref_pic_list_modification_flag_l1); | 926 | 45.5k | if (current->ref_pic_list_modification_flag_l1) { | 927 | 288k | for (i = 0; i < H264_MAX_RPLM_COUNT; i++) { | 928 | 282k | xue(modification_of_pic_nums_idc, | 929 | 282k | current->rplm_l1[i].modification_of_pic_nums_idc, 0, 3, 0); | 930 | | | 931 | 277k | mopn = current->rplm_l1[i].modification_of_pic_nums_idc; | 932 | 277k | if (mopn == 3) | 933 | 5.24k | break; | 934 | | | 935 | 272k | if (mopn == 0 || mopn == 1) | 936 | 199k | xue(abs_diff_pic_num_minus1, | 937 | 272k | current->rplm_l1[i].abs_diff_pic_num_minus1, | 938 | 272k | 0, (1 + current->field_pic_flag) * | 939 | 272k | (1 << (sps->log2_max_frame_num_minus4 + 4)), 0); | 940 | 72.7k | else if (mopn == 2) | 941 | 72.7k | xue(long_term_pic_num, | 942 | 272k | current->rplm_l1[i].long_term_pic_num, | 943 | 272k | 0, sps->max_num_ref_frames - 1, 0); | 944 | 272k | } | 945 | 18.8k | } | 946 | 45.5k | } | 947 | | | 948 | 544k | return 0; | 949 | 553k | } |
cbs_h264.c:cbs_h264_write_ref_pic_list_modification Line | Count | Source | 894 | 28.3k | { | 895 | 28.3k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 896 | 28.3k | const H264RawSPS *sps = h264->active_sps; | 897 | 28.3k | int err, i, mopn; | 898 | | | 899 | 28.3k | if (current->slice_type % 5 != 2 && | 900 | 23.6k | current->slice_type % 5 != 4) { | 901 | 21.6k | flag(ref_pic_list_modification_flag_l0); | 902 | 21.6k | if (current->ref_pic_list_modification_flag_l0) { | 903 | 90.3k | for (i = 0; i < H264_MAX_RPLM_COUNT; i++) { | 904 | 88.4k | xue(modification_of_pic_nums_idc, | 905 | 88.4k | current->rplm_l0[i].modification_of_pic_nums_idc, 0, 3, 0); | 906 | | | 907 | 88.4k | mopn = current->rplm_l0[i].modification_of_pic_nums_idc; | 908 | 88.4k | if (mopn == 3) | 909 | 1.78k | break; | 910 | | | 911 | 86.7k | if (mopn == 0 || mopn == 1) | 912 | 83.3k | xue(abs_diff_pic_num_minus1, | 913 | 86.7k | current->rplm_l0[i].abs_diff_pic_num_minus1, | 914 | 86.7k | 0, (1 + current->field_pic_flag) * | 915 | 86.7k | (1 << (sps->log2_max_frame_num_minus4 + 4)), 0); | 916 | 3.38k | else if (mopn == 2) | 917 | 3.38k | xue(long_term_pic_num, | 918 | 86.7k | current->rplm_l0[i].long_term_pic_num, | 919 | 86.7k | 0, sps->max_num_ref_frames - 1, 0); | 920 | 86.7k | } | 921 | 4.62k | } | 922 | 21.6k | } | 923 | | | 924 | 27.4k | if (current->slice_type % 5 == 1) { | 925 | 6.48k | flag(ref_pic_list_modification_flag_l1); | 926 | 6.48k | if (current->ref_pic_list_modification_flag_l1) { | 927 | 36.7k | for (i = 0; i < H264_MAX_RPLM_COUNT; i++) { | 928 | 36.0k | xue(modification_of_pic_nums_idc, | 929 | 36.0k | current->rplm_l1[i].modification_of_pic_nums_idc, 0, 3, 0); | 930 | | | 931 | 36.0k | mopn = current->rplm_l1[i].modification_of_pic_nums_idc; | 932 | 36.0k | if (mopn == 3) | 933 | 1.46k | break; | 934 | | | 935 | 34.6k | if (mopn == 0 || mopn == 1) | 936 | 30.2k | xue(abs_diff_pic_num_minus1, | 937 | 34.6k | current->rplm_l1[i].abs_diff_pic_num_minus1, | 938 | 34.6k | 0, (1 + current->field_pic_flag) * | 939 | 34.6k | (1 << (sps->log2_max_frame_num_minus4 + 4)), 0); | 940 | 4.33k | else if (mopn == 2) | 941 | 4.33k | xue(long_term_pic_num, | 942 | 34.6k | current->rplm_l1[i].long_term_pic_num, | 943 | 34.6k | 0, sps->max_num_ref_frames - 1, 0); | 944 | 34.6k | } | 945 | 3.00k | } | 946 | 6.48k | } | 947 | | | 948 | 26.5k | return 0; | 949 | 27.4k | } |
|
950 | | |
951 | | static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw, |
952 | | H264RawSliceHeader *current) |
953 | 84.4k | { |
954 | 84.4k | CodedBitstreamH264Context *h264 = ctx->priv_data; |
955 | 84.4k | const H264RawSPS *sps = h264->active_sps; |
956 | 84.4k | int chroma; |
957 | 84.4k | int err, i, j; |
958 | | |
959 | 84.4k | ue(luma_log2_weight_denom, 0, 7); |
960 | | |
961 | 73.2k | chroma = !sps->separate_colour_plane_flag && sps->chroma_format_idc != 0; |
962 | 73.2k | if (chroma) |
963 | 73.2k | ue(chroma_log2_weight_denom, 0, 7); |
964 | | |
965 | 221k | for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) { |
966 | 164k | flags(luma_weight_l0_flag[i], 1, i); |
967 | 163k | if (current->luma_weight_l0_flag[i]) { |
968 | 79.9k | ses(luma_weight_l0[i], -128, +127, 1, i); |
969 | 78.3k | ses(luma_offset_l0[i], -128, +127, 1, i); |
970 | 78.3k | } |
971 | 159k | if (chroma) { |
972 | 116k | flags(chroma_weight_l0_flag[i], 1, i); |
973 | 113k | if (current->chroma_weight_l0_flag[i]) { |
974 | 159k | for (j = 0; j < 2; j++) { |
975 | 108k | ses(chroma_weight_l0[i][j], -128, +127, 2, i, j); |
976 | 105k | ses(chroma_offset_l0[i][j], -128, +127, 2, i, j); |
977 | 105k | } |
978 | 55.0k | } |
979 | 113k | } |
980 | 159k | } |
981 | | |
982 | 56.6k | if (current->slice_type % 5 == 1) { |
983 | 66.1k | for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) { |
984 | 55.2k | flags(luma_weight_l1_flag[i], 1, i); |
985 | 53.4k | if (current->luma_weight_l1_flag[i]) { |
986 | 27.6k | ses(luma_weight_l1[i], -128, +127, 1, i); |
987 | 26.9k | ses(luma_offset_l1[i], -128, +127, 1, i); |
988 | 26.9k | } |
989 | 51.8k | if (chroma) { |
990 | 38.7k | flags(chroma_weight_l1_flag[i], 1, i); |
991 | 37.7k | if (current->chroma_weight_l1_flag[i]) { |
992 | 59.0k | for (j = 0; j < 2; j++) { |
993 | 40.8k | ses(chroma_weight_l1[i][j], -128, +127, 2, i, j); |
994 | 39.3k | ses(chroma_offset_l1[i][j], -128, +127, 2, i, j); |
995 | 39.3k | } |
996 | 20.9k | } |
997 | 37.7k | } |
998 | 51.8k | } |
999 | 17.8k | } |
1000 | | |
1001 | 49.6k | return 0; |
1002 | 56.6k | } cbs_h264.c:cbs_h264_read_pred_weight_table Line | Count | Source | 953 | 75.3k | { | 954 | 75.3k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 955 | 75.3k | const H264RawSPS *sps = h264->active_sps; | 956 | 75.3k | int chroma; | 957 | 75.3k | int err, i, j; | 958 | | | 959 | 75.3k | ue(luma_log2_weight_denom, 0, 7); | 960 | | | 961 | 64.1k | chroma = !sps->separate_colour_plane_flag && sps->chroma_format_idc != 0; | 962 | 64.1k | if (chroma) | 963 | 64.1k | ue(chroma_log2_weight_denom, 0, 7); | 964 | | | 965 | 185k | for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) { | 966 | 137k | flags(luma_weight_l0_flag[i], 1, i); | 967 | 136k | if (current->luma_weight_l0_flag[i]) { | 968 | 75.4k | ses(luma_weight_l0[i], -128, +127, 1, i); | 969 | 73.9k | ses(luma_offset_l0[i], -128, +127, 1, i); | 970 | 73.9k | } | 971 | 132k | if (chroma) { | 972 | 99.6k | flags(chroma_weight_l0_flag[i], 1, i); | 973 | 97.1k | if (current->chroma_weight_l0_flag[i]) { | 974 | 151k | for (j = 0; j < 2; j++) { | 975 | 102k | ses(chroma_weight_l0[i][j], -128, +127, 2, i, j); | 976 | 100k | ses(chroma_offset_l0[i][j], -128, +127, 2, i, j); | 977 | 100k | } | 978 | 52.3k | } | 979 | 97.1k | } | 980 | 132k | } | 981 | | | 982 | 47.6k | if (current->slice_type % 5 == 1) { | 983 | 60.6k | for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) { | 984 | 51.4k | flags(luma_weight_l1_flag[i], 1, i); | 985 | 49.7k | if (current->luma_weight_l1_flag[i]) { | 986 | 25.1k | ses(luma_weight_l1[i], -128, +127, 1, i); | 987 | 24.4k | ses(luma_offset_l1[i], -128, +127, 1, i); | 988 | 24.4k | } | 989 | 48.1k | if (chroma) { | 990 | 36.6k | flags(chroma_weight_l1_flag[i], 1, i); | 991 | 35.6k | if (current->chroma_weight_l1_flag[i]) { | 992 | 56.3k | for (j = 0; j < 2; j++) { | 993 | 39.0k | ses(chroma_weight_l1[i][j], -128, +127, 2, i, j); | 994 | 37.5k | ses(chroma_offset_l1[i][j], -128, +127, 2, i, j); | 995 | 37.5k | } | 996 | 20.0k | } | 997 | 35.6k | } | 998 | 48.1k | } | 999 | 16.1k | } | 1000 | | | 1001 | 40.5k | return 0; | 1002 | 47.6k | } |
cbs_h264.c:cbs_h264_write_pred_weight_table Line | Count | Source | 953 | 9.08k | { | 954 | 9.08k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 955 | 9.08k | const H264RawSPS *sps = h264->active_sps; | 956 | 9.08k | int chroma; | 957 | 9.08k | int err, i, j; | 958 | | | 959 | 9.08k | ue(luma_log2_weight_denom, 0, 7); | 960 | | | 961 | 9.08k | chroma = !sps->separate_colour_plane_flag && sps->chroma_format_idc != 0; | 962 | 9.08k | if (chroma) | 963 | 9.08k | ue(chroma_log2_weight_denom, 0, 7); | 964 | | | 965 | 36.1k | for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) { | 966 | 27.0k | flags(luma_weight_l0_flag[i], 1, i); | 967 | 27.0k | if (current->luma_weight_l0_flag[i]) { | 968 | 4.44k | ses(luma_weight_l0[i], -128, +127, 1, i); | 969 | 4.44k | ses(luma_offset_l0[i], -128, +127, 1, i); | 970 | 4.44k | } | 971 | 27.0k | if (chroma) { | 972 | 16.7k | flags(chroma_weight_l0_flag[i], 1, i); | 973 | 16.7k | if (current->chroma_weight_l0_flag[i]) { | 974 | 7.90k | for (j = 0; j < 2; j++) { | 975 | 5.27k | ses(chroma_weight_l0[i][j], -128, +127, 2, i, j); | 976 | 5.27k | ses(chroma_offset_l0[i][j], -128, +127, 2, i, j); | 977 | 5.27k | } | 978 | 2.63k | } | 979 | 16.7k | } | 980 | 27.0k | } | 981 | | | 982 | 9.08k | if (current->slice_type % 5 == 1) { | 983 | 5.51k | for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) { | 984 | 3.77k | flags(luma_weight_l1_flag[i], 1, i); | 985 | 3.77k | if (current->luma_weight_l1_flag[i]) { | 986 | 2.48k | ses(luma_weight_l1[i], -128, +127, 1, i); | 987 | 2.48k | ses(luma_offset_l1[i], -128, +127, 1, i); | 988 | 2.48k | } | 989 | 3.77k | if (chroma) { | 990 | 2.09k | flags(chroma_weight_l1_flag[i], 1, i); | 991 | 2.09k | if (current->chroma_weight_l1_flag[i]) { | 992 | 2.69k | for (j = 0; j < 2; j++) { | 993 | 1.79k | ses(chroma_weight_l1[i][j], -128, +127, 2, i, j); | 994 | 1.79k | ses(chroma_offset_l1[i][j], -128, +127, 2, i, j); | 995 | 1.79k | } | 996 | 899 | } | 997 | 2.09k | } | 998 | 3.77k | } | 999 | 1.73k | } | 1000 | | | 1001 | 9.08k | return 0; | 1002 | 9.08k | } |
|
1003 | | |
1004 | | static int FUNC(dec_ref_pic_marking)(CodedBitstreamContext *ctx, RWContext *rw, |
1005 | | H264RawSliceHeader *current, int idr_pic_flag) |
1006 | 442k | { |
1007 | 442k | CodedBitstreamH264Context *h264 = ctx->priv_data; |
1008 | 442k | const H264RawSPS *sps = h264->active_sps; |
1009 | 442k | int err, i; |
1010 | 442k | uint32_t mmco; |
1011 | | |
1012 | 442k | if (idr_pic_flag) { |
1013 | 29.6k | flag(no_output_of_prior_pics_flag); |
1014 | 28.5k | flag(long_term_reference_flag); |
1015 | 413k | } else { |
1016 | 413k | flag(adaptive_ref_pic_marking_mode_flag); |
1017 | 411k | if (current->adaptive_ref_pic_marking_mode_flag) { |
1018 | 539k | for (i = 0; i < H264_MAX_MMCO_COUNT; i++) { |
1019 | 537k | xue(memory_management_control_operation, |
1020 | 537k | current->mmco[i].memory_management_control_operation, |
1021 | 537k | 0, 6, 0); |
1022 | | |
1023 | 536k | mmco = current->mmco[i].memory_management_control_operation; |
1024 | 536k | if (mmco == 0) |
1025 | 177k | break; |
1026 | | |
1027 | 358k | if (mmco == 1 || mmco == 3) |
1028 | 152k | xue(difference_of_pic_nums_minus1, |
1029 | 358k | current->mmco[i].difference_of_pic_nums_minus1, |
1030 | 358k | 0, INT32_MAX, 0); |
1031 | 356k | if (mmco == 2) |
1032 | 181k | xue(long_term_pic_num, |
1033 | 356k | current->mmco[i].long_term_pic_num, |
1034 | 356k | 0, sps->max_num_ref_frames - 1, 0); |
1035 | 354k | if (mmco == 3 || mmco == 6) |
1036 | 16.6k | xue(long_term_frame_idx, |
1037 | 354k | current->mmco[i].long_term_frame_idx, |
1038 | 354k | 0, sps->max_num_ref_frames - 1, 0); |
1039 | 352k | if (mmco == 4) |
1040 | 7.90k | xue(max_long_term_frame_idx_plus1, |
1041 | 352k | current->mmco[i].max_long_term_frame_idx_plus1, |
1042 | 352k | 0, sps->max_num_ref_frames, 0); |
1043 | 352k | } |
1044 | 178k | if (i == H264_MAX_MMCO_COUNT) { |
1045 | 1.38k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many " |
1046 | 1.38k | "memory management control operations.\n"); |
1047 | 1.38k | return AVERROR_INVALIDDATA; |
1048 | 1.38k | } |
1049 | 178k | } |
1050 | 411k | } |
1051 | | |
1052 | 427k | return 0; |
1053 | 442k | } cbs_h264.c:cbs_h264_read_dec_ref_pic_marking Line | Count | Source | 1006 | 428k | { | 1007 | 428k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 1008 | 428k | const H264RawSPS *sps = h264->active_sps; | 1009 | 428k | int err, i; | 1010 | 428k | uint32_t mmco; | 1011 | | | 1012 | 428k | if (idr_pic_flag) { | 1013 | 28.2k | flag(no_output_of_prior_pics_flag); | 1014 | 27.1k | flag(long_term_reference_flag); | 1015 | 400k | } else { | 1016 | 400k | flag(adaptive_ref_pic_marking_mode_flag); | 1017 | 398k | if (current->adaptive_ref_pic_marking_mode_flag) { | 1018 | 520k | for (i = 0; i < H264_MAX_MMCO_COUNT; i++) { | 1019 | 518k | xue(memory_management_control_operation, | 1020 | 518k | current->mmco[i].memory_management_control_operation, | 1021 | 518k | 0, 6, 0); | 1022 | | | 1023 | 516k | mmco = current->mmco[i].memory_management_control_operation; | 1024 | 516k | if (mmco == 0) | 1025 | 171k | break; | 1026 | | | 1027 | 345k | if (mmco == 1 || mmco == 3) | 1028 | 145k | xue(difference_of_pic_nums_minus1, | 1029 | 345k | current->mmco[i].difference_of_pic_nums_minus1, | 1030 | 345k | 0, INT32_MAX, 0); | 1031 | 343k | if (mmco == 2) | 1032 | 178k | xue(long_term_pic_num, | 1033 | 343k | current->mmco[i].long_term_pic_num, | 1034 | 343k | 0, sps->max_num_ref_frames - 1, 0); | 1035 | 342k | if (mmco == 3 || mmco == 6) | 1036 | 14.7k | xue(long_term_frame_idx, | 1037 | 342k | current->mmco[i].long_term_frame_idx, | 1038 | 342k | 0, sps->max_num_ref_frames - 1, 0); | 1039 | 340k | if (mmco == 4) | 1040 | 6.48k | xue(max_long_term_frame_idx_plus1, | 1041 | 340k | current->mmco[i].max_long_term_frame_idx_plus1, | 1042 | 340k | 0, sps->max_num_ref_frames, 0); | 1043 | 340k | } | 1044 | 172k | if (i == H264_MAX_MMCO_COUNT) { | 1045 | 1.38k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many " | 1046 | 1.38k | "memory management control operations.\n"); | 1047 | 1.38k | return AVERROR_INVALIDDATA; | 1048 | 1.38k | } | 1049 | 172k | } | 1050 | 398k | } | 1051 | | | 1052 | 414k | return 0; | 1053 | 428k | } |
cbs_h264.c:cbs_h264_write_dec_ref_pic_marking Line | Count | Source | 1006 | 14.3k | { | 1007 | 14.3k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 1008 | 14.3k | const H264RawSPS *sps = h264->active_sps; | 1009 | 14.3k | int err, i; | 1010 | 14.3k | uint32_t mmco; | 1011 | | | 1012 | 14.3k | if (idr_pic_flag) { | 1013 | 1.39k | flag(no_output_of_prior_pics_flag); | 1014 | 1.39k | flag(long_term_reference_flag); | 1015 | 12.9k | } else { | 1016 | 12.9k | flag(adaptive_ref_pic_marking_mode_flag); | 1017 | 12.9k | if (current->adaptive_ref_pic_marking_mode_flag) { | 1018 | 19.1k | for (i = 0; i < H264_MAX_MMCO_COUNT; i++) { | 1019 | 19.1k | xue(memory_management_control_operation, | 1020 | 19.1k | current->mmco[i].memory_management_control_operation, | 1021 | 19.1k | 0, 6, 0); | 1022 | | | 1023 | 19.1k | mmco = current->mmco[i].memory_management_control_operation; | 1024 | 19.1k | if (mmco == 0) | 1025 | 5.94k | break; | 1026 | | | 1027 | 13.2k | if (mmco == 1 || mmco == 3) | 1028 | 7.35k | xue(difference_of_pic_nums_minus1, | 1029 | 13.2k | current->mmco[i].difference_of_pic_nums_minus1, | 1030 | 13.2k | 0, INT32_MAX, 0); | 1031 | 13.2k | if (mmco == 2) | 1032 | 2.49k | xue(long_term_pic_num, | 1033 | 13.2k | current->mmco[i].long_term_pic_num, | 1034 | 13.2k | 0, sps->max_num_ref_frames - 1, 0); | 1035 | 12.2k | if (mmco == 3 || mmco == 6) | 1036 | 1.90k | xue(long_term_frame_idx, | 1037 | 12.2k | current->mmco[i].long_term_frame_idx, | 1038 | 12.2k | 0, sps->max_num_ref_frames - 1, 0); | 1039 | 11.8k | if (mmco == 4) | 1040 | 1.41k | xue(max_long_term_frame_idx_plus1, | 1041 | 11.8k | current->mmco[i].max_long_term_frame_idx_plus1, | 1042 | 11.8k | 0, sps->max_num_ref_frames, 0); | 1043 | 11.8k | } | 1044 | 5.94k | if (i == H264_MAX_MMCO_COUNT) { | 1045 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many " | 1046 | 0 | "memory management control operations.\n"); | 1047 | 0 | return AVERROR_INVALIDDATA; | 1048 | 0 | } | 1049 | 5.94k | } | 1050 | 12.9k | } | 1051 | | | 1052 | 12.5k | return 0; | 1053 | 14.3k | } |
|
1054 | | |
1055 | | static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw, |
1056 | | H264RawSliceHeader *current) |
1057 | 740k | { |
1058 | 740k | CodedBitstreamH264Context *h264 = ctx->priv_data; |
1059 | 740k | const H264RawSPS *sps; |
1060 | 740k | const H264RawPPS *pps; |
1061 | 740k | int err; |
1062 | 740k | int idr_pic_flag; |
1063 | 740k | int slice_type_i, slice_type_p, slice_type_b; |
1064 | 740k | int slice_type_si, slice_type_sp; |
1065 | | |
1066 | 740k | HEADER("Slice Header"); |
1067 | | |
1068 | 740k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, |
1069 | 740k | 1 << H264_NAL_SLICE | |
1070 | 740k | 1 << H264_NAL_IDR_SLICE | |
1071 | 740k | 1 << H264_NAL_AUXILIARY_SLICE)); |
1072 | | |
1073 | 740k | if (current->nal_unit_header.nal_unit_type == H264_NAL_AUXILIARY_SLICE) { |
1074 | 9.59k | if (!h264->last_slice_nal_unit_type) { |
1075 | 2.24k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Auxiliary slice " |
1076 | 2.24k | "is not decodable without the main picture " |
1077 | 2.24k | "in the same access unit.\n"); |
1078 | 2.24k | return AVERROR_INVALIDDATA; |
1079 | 2.24k | } |
1080 | 7.34k | idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE; |
1081 | 731k | } else { |
1082 | 731k | idr_pic_flag = current->nal_unit_header.nal_unit_type == H264_NAL_IDR_SLICE; |
1083 | 731k | } |
1084 | | |
1085 | 738k | ue(first_mb_in_slice, 0, H264_MAX_MB_PIC_SIZE - 1); |
1086 | 730k | ue(slice_type, 0, 9); |
1087 | | |
1088 | 723k | slice_type_i = current->slice_type % 5 == 2; |
1089 | 723k | slice_type_p = current->slice_type % 5 == 0; |
1090 | 723k | slice_type_b = current->slice_type % 5 == 1; |
1091 | 723k | slice_type_si = current->slice_type % 5 == 4; |
1092 | 723k | slice_type_sp = current->slice_type % 5 == 3; |
1093 | | |
1094 | 723k | if (idr_pic_flag && !(slice_type_i || slice_type_si)) { |
1095 | 6.04k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid slice type %d " |
1096 | 6.04k | "for IDR picture.\n", current->slice_type); |
1097 | 6.04k | return AVERROR_INVALIDDATA; |
1098 | 6.04k | } |
1099 | | |
1100 | 717k | ue(pic_parameter_set_id, 0, 255); |
1101 | | |
1102 | 710k | pps = h264->pps[current->pic_parameter_set_id]; |
1103 | 710k | if (!pps) { |
1104 | 59.1k | av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n", |
1105 | 59.1k | current->pic_parameter_set_id); |
1106 | 59.1k | return AVERROR_INVALIDDATA; |
1107 | 59.1k | } |
1108 | 650k | h264->active_pps = pps; |
1109 | | |
1110 | 650k | sps = h264->sps[pps->seq_parameter_set_id]; |
1111 | 650k | if (!sps) { |
1112 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n", |
1113 | 0 | pps->seq_parameter_set_id); |
1114 | 0 | return AVERROR_INVALIDDATA; |
1115 | 0 | } |
1116 | 650k | h264->active_sps = sps; |
1117 | | |
1118 | 650k | if (sps->separate_colour_plane_flag) |
1119 | 650k | u(2, colour_plane_id, 0, 2); |
1120 | | |
1121 | 649k | ub(sps->log2_max_frame_num_minus4 + 4, frame_num); |
1122 | | |
1123 | 645k | if (!sps->frame_mbs_only_flag) { |
1124 | 176k | flag(field_pic_flag); |
1125 | 174k | if (current->field_pic_flag) |
1126 | 174k | flag(bottom_field_flag); |
1127 | 76.0k | else |
1128 | 76.0k | infer(bottom_field_flag, 0); |
1129 | 468k | } else { |
1130 | 468k | infer(field_pic_flag, 0); |
1131 | 468k | infer(bottom_field_flag, 0); |
1132 | 15.9k | } |
1133 | | |
1134 | 640k | if (idr_pic_flag) |
1135 | 640k | ue(idr_pic_id, 0, 65535); |
1136 | | |
1137 | 639k | if (sps->pic_order_cnt_type == 0) { |
1138 | 144k | ub(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, pic_order_cnt_lsb); |
1139 | 142k | if (pps->bottom_field_pic_order_in_frame_present_flag && |
1140 | 80.6k | !current->field_pic_flag) |
1141 | 142k | se(delta_pic_order_cnt_bottom, INT32_MIN + 1, INT32_MAX); |
1142 | | |
1143 | 494k | } else if (sps->pic_order_cnt_type == 1) { |
1144 | 106k | if (!sps->delta_pic_order_always_zero_flag) { |
1145 | 88.4k | se(delta_pic_order_cnt[0], INT32_MIN + 1, INT32_MAX); |
1146 | 84.5k | if (pps->bottom_field_pic_order_in_frame_present_flag && |
1147 | 45.9k | !current->field_pic_flag) |
1148 | 84.5k | se(delta_pic_order_cnt[1], INT32_MIN + 1, INT32_MAX); |
1149 | 50.2k | else |
1150 | 50.2k | infer(delta_pic_order_cnt[1], 0); |
1151 | 84.5k | } else { |
1152 | 17.8k | infer(delta_pic_order_cnt[0], 0); |
1153 | 17.3k | infer(delta_pic_order_cnt[1], 0); |
1154 | 4.94k | } |
1155 | 106k | } |
1156 | | |
1157 | 627k | if (pps->redundant_pic_cnt_present_flag) |
1158 | 627k | ue(redundant_pic_cnt, 0, 127); |
1159 | 491k | else |
1160 | 491k | infer(redundant_pic_cnt, 0); |
1161 | | |
1162 | 622k | if (current->nal_unit_header.nal_unit_type != H264_NAL_AUXILIARY_SLICE |
1163 | 616k | && !current->redundant_pic_cnt) |
1164 | 539k | h264->last_slice_nal_unit_type = |
1165 | 539k | current->nal_unit_header.nal_unit_type; |
1166 | | |
1167 | 622k | if (slice_type_b) |
1168 | 622k | flag(direct_spatial_mv_pred_flag); |
1169 | | |
1170 | 621k | if (slice_type_p || slice_type_sp || slice_type_b) { |
1171 | 545k | flag(num_ref_idx_active_override_flag); |
1172 | 543k | if (current->num_ref_idx_active_override_flag) { |
1173 | 428k | ue(num_ref_idx_l0_active_minus1, 0, 31); |
1174 | 425k | if (slice_type_b) |
1175 | 425k | ue(num_ref_idx_l1_active_minus1, 0, 31); |
1176 | 425k | } else { |
1177 | 114k | infer(num_ref_idx_l0_active_minus1, |
1178 | 114k | pps->num_ref_idx_l0_default_active_minus1); |
1179 | 114k | infer(num_ref_idx_l1_active_minus1, |
1180 | 11.3k | pps->num_ref_idx_l1_default_active_minus1); |
1181 | 11.3k | } |
1182 | 543k | } |
1183 | | |
1184 | 614k | if (current->nal_unit_header.nal_unit_type == 20 || |
1185 | 614k | current->nal_unit_header.nal_unit_type == 21) { |
1186 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC / 3DAVC not supported.\n"); |
1187 | 0 | return AVERROR_PATCHWELCOME; |
1188 | 614k | } else { |
1189 | 614k | CHECK(FUNC(ref_pic_list_modification)(ctx, rw, current)); |
1190 | 614k | } |
1191 | | |
1192 | 571k | if ((pps->weighted_pred_flag && (slice_type_p || slice_type_sp)) || |
1193 | 509k | (pps->weighted_bipred_idc == 1 && slice_type_b)) { |
1194 | 84.4k | CHECK(FUNC(pred_weight_table)(ctx, rw, current)); |
1195 | 84.4k | } |
1196 | | |
1197 | 536k | if (current->nal_unit_header.nal_ref_idc != 0) { |
1198 | 442k | CHECK(FUNC(dec_ref_pic_marking)(ctx, rw, current, idr_pic_flag)); |
1199 | 442k | } |
1200 | | |
1201 | 521k | if (pps->entropy_coding_mode_flag && |
1202 | 66.6k | !slice_type_i && !slice_type_si) { |
1203 | 36.4k | ue(cabac_init_idc, 0, 2); |
1204 | 36.4k | } |
1205 | | |
1206 | 517k | se(slice_qp_delta, - 51 - 6 * sps->bit_depth_luma_minus8, |
1207 | 509k | + 51 + 6 * sps->bit_depth_luma_minus8); |
1208 | 509k | if (slice_type_sp || slice_type_si) { |
1209 | 47.8k | if (slice_type_sp) |
1210 | 47.8k | flag(sp_for_switch_flag); |
1211 | 47.0k | se(slice_qs_delta, -51, +51); |
1212 | 47.0k | } |
1213 | | |
1214 | 506k | if (pps->deblocking_filter_control_present_flag) { |
1215 | 432k | ue(disable_deblocking_filter_idc, 0, 2); |
1216 | 427k | if (current->disable_deblocking_filter_idc != 1) { |
1217 | 138k | se(slice_alpha_c0_offset_div2, -6, +6); |
1218 | 135k | se(slice_beta_offset_div2, -6, +6); |
1219 | 288k | } else { |
1220 | 288k | infer(slice_alpha_c0_offset_div2, 0); |
1221 | 288k | infer(slice_beta_offset_div2, 0); |
1222 | 1.11k | } |
1223 | 427k | } else { |
1224 | 74.1k | infer(disable_deblocking_filter_idc, 0); |
1225 | 73.5k | infer(slice_alpha_c0_offset_div2, 0); |
1226 | 73.0k | infer(slice_beta_offset_div2, 0); |
1227 | 16.7k | } |
1228 | | |
1229 | 494k | if (pps->num_slice_groups_minus1 > 0 && |
1230 | 44.0k | pps->slice_group_map_type >= 3 && |
1231 | 29.2k | pps->slice_group_map_type <= 5) { |
1232 | 16.7k | unsigned int pic_size, max, bits; |
1233 | | |
1234 | 16.7k | pic_size = (sps->pic_width_in_mbs_minus1 + 1) * |
1235 | 16.7k | (sps->pic_height_in_map_units_minus1 + 1); |
1236 | 16.7k | max = (pic_size + pps->slice_group_change_rate_minus1) / |
1237 | 16.7k | (pps->slice_group_change_rate_minus1 + 1); |
1238 | 16.7k | bits = av_ceil_log2(max + 1); |
1239 | | |
1240 | 16.7k | u(bits, slice_group_change_cycle, 0, max); |
1241 | 16.7k | } |
1242 | | |
1243 | 492k | if (pps->entropy_coding_mode_flag) { |
1244 | 228k | while (byte_alignment(rw)) |
1245 | 176k | fixed(1, cabac_alignment_one_bit, 1); |
1246 | 56.3k | } |
1247 | | |
1248 | 487k | return 0; |
1249 | 492k | } cbs_h264.c:cbs_h264_read_slice_header Line | Count | Source | 1057 | 706k | { | 1058 | 706k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 1059 | 706k | const H264RawSPS *sps; | 1060 | 706k | const H264RawPPS *pps; | 1061 | 706k | int err; | 1062 | 706k | int idr_pic_flag; | 1063 | 706k | int slice_type_i, slice_type_p, slice_type_b; | 1064 | 706k | int slice_type_si, slice_type_sp; | 1065 | | | 1066 | 706k | HEADER("Slice Header"); | 1067 | | | 1068 | 706k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 1069 | 706k | 1 << H264_NAL_SLICE | | 1070 | 706k | 1 << H264_NAL_IDR_SLICE | | 1071 | 706k | 1 << H264_NAL_AUXILIARY_SLICE)); | 1072 | | | 1073 | 706k | if (current->nal_unit_header.nal_unit_type == H264_NAL_AUXILIARY_SLICE) { | 1074 | 7.75k | if (!h264->last_slice_nal_unit_type) { | 1075 | 1.81k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Auxiliary slice " | 1076 | 1.81k | "is not decodable without the main picture " | 1077 | 1.81k | "in the same access unit.\n"); | 1078 | 1.81k | return AVERROR_INVALIDDATA; | 1079 | 1.81k | } | 1080 | 5.94k | idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE; | 1081 | 698k | } else { | 1082 | 698k | idr_pic_flag = current->nal_unit_header.nal_unit_type == H264_NAL_IDR_SLICE; | 1083 | 698k | } | 1084 | | | 1085 | 704k | ue(first_mb_in_slice, 0, H264_MAX_MB_PIC_SIZE - 1); | 1086 | 696k | ue(slice_type, 0, 9); | 1087 | | | 1088 | 688k | slice_type_i = current->slice_type % 5 == 2; | 1089 | 688k | slice_type_p = current->slice_type % 5 == 0; | 1090 | 688k | slice_type_b = current->slice_type % 5 == 1; | 1091 | 688k | slice_type_si = current->slice_type % 5 == 4; | 1092 | 688k | slice_type_sp = current->slice_type % 5 == 3; | 1093 | | | 1094 | 688k | if (idr_pic_flag && !(slice_type_i || slice_type_si)) { | 1095 | 5.61k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid slice type %d " | 1096 | 5.61k | "for IDR picture.\n", current->slice_type); | 1097 | 5.61k | return AVERROR_INVALIDDATA; | 1098 | 5.61k | } | 1099 | | | 1100 | 683k | ue(pic_parameter_set_id, 0, 255); | 1101 | | | 1102 | 676k | pps = h264->pps[current->pic_parameter_set_id]; | 1103 | 676k | if (!pps) { | 1104 | 58.3k | av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n", | 1105 | 58.3k | current->pic_parameter_set_id); | 1106 | 58.3k | return AVERROR_INVALIDDATA; | 1107 | 58.3k | } | 1108 | 617k | h264->active_pps = pps; | 1109 | | | 1110 | 617k | sps = h264->sps[pps->seq_parameter_set_id]; | 1111 | 617k | if (!sps) { | 1112 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n", | 1113 | 0 | pps->seq_parameter_set_id); | 1114 | 0 | return AVERROR_INVALIDDATA; | 1115 | 0 | } | 1116 | 617k | h264->active_sps = sps; | 1117 | | | 1118 | 617k | if (sps->separate_colour_plane_flag) | 1119 | 617k | u(2, colour_plane_id, 0, 2); | 1120 | | | 1121 | 616k | ub(sps->log2_max_frame_num_minus4 + 4, frame_num); | 1122 | | | 1123 | 612k | if (!sps->frame_mbs_only_flag) { | 1124 | 160k | flag(field_pic_flag); | 1125 | 158k | if (current->field_pic_flag) | 1126 | 158k | flag(bottom_field_flag); | 1127 | 69.1k | else | 1128 | 69.1k | infer(bottom_field_flag, 0); | 1129 | 452k | } else { | 1130 | 452k | infer(field_pic_flag, 0); | 1131 | 452k | infer(bottom_field_flag, 0); | 1132 | 452k | } | 1133 | | | 1134 | 608k | if (idr_pic_flag) | 1135 | 608k | ue(idr_pic_id, 0, 65535); | 1136 | | | 1137 | 607k | if (sps->pic_order_cnt_type == 0) { | 1138 | 136k | ub(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, pic_order_cnt_lsb); | 1139 | 134k | if (pps->bottom_field_pic_order_in_frame_present_flag && | 1140 | 76.3k | !current->field_pic_flag) | 1141 | 134k | se(delta_pic_order_cnt_bottom, INT32_MIN + 1, INT32_MAX); | 1142 | | | 1143 | 470k | } else if (sps->pic_order_cnt_type == 1) { | 1144 | 90.4k | if (!sps->delta_pic_order_always_zero_flag) { | 1145 | 78.0k | se(delta_pic_order_cnt[0], INT32_MIN + 1, INT32_MAX); | 1146 | 74.1k | if (pps->bottom_field_pic_order_in_frame_present_flag && | 1147 | 41.1k | !current->field_pic_flag) | 1148 | 74.1k | se(delta_pic_order_cnt[1], INT32_MIN + 1, INT32_MAX); | 1149 | 42.8k | else | 1150 | 42.8k | infer(delta_pic_order_cnt[1], 0); | 1151 | 74.1k | } else { | 1152 | 12.3k | infer(delta_pic_order_cnt[0], 0); | 1153 | 12.3k | infer(delta_pic_order_cnt[1], 0); | 1154 | 12.3k | } | 1155 | 90.4k | } | 1156 | | | 1157 | 597k | if (pps->redundant_pic_cnt_present_flag) | 1158 | 597k | ue(redundant_pic_cnt, 0, 127); | 1159 | 472k | else | 1160 | 472k | infer(redundant_pic_cnt, 0); | 1161 | | | 1162 | 593k | if (current->nal_unit_header.nal_unit_type != H264_NAL_AUXILIARY_SLICE | 1163 | 588k | && !current->redundant_pic_cnt) | 1164 | 517k | h264->last_slice_nal_unit_type = | 1165 | 517k | current->nal_unit_header.nal_unit_type; | 1166 | | | 1167 | 593k | if (slice_type_b) | 1168 | 593k | flag(direct_spatial_mv_pred_flag); | 1169 | | | 1170 | 592k | if (slice_type_p || slice_type_sp || slice_type_b) { | 1171 | 522k | flag(num_ref_idx_active_override_flag); | 1172 | 520k | if (current->num_ref_idx_active_override_flag) { | 1173 | 417k | ue(num_ref_idx_l0_active_minus1, 0, 31); | 1174 | 415k | if (slice_type_b) | 1175 | 415k | ue(num_ref_idx_l1_active_minus1, 0, 31); | 1176 | 415k | } else { | 1177 | 102k | infer(num_ref_idx_l0_active_minus1, | 1178 | 102k | pps->num_ref_idx_l0_default_active_minus1); | 1179 | 102k | infer(num_ref_idx_l1_active_minus1, | 1180 | 102k | pps->num_ref_idx_l1_default_active_minus1); | 1181 | 102k | } | 1182 | 520k | } | 1183 | | | 1184 | 586k | if (current->nal_unit_header.nal_unit_type == 20 || | 1185 | 586k | current->nal_unit_header.nal_unit_type == 21) { | 1186 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC / 3DAVC not supported.\n"); | 1187 | 0 | return AVERROR_PATCHWELCOME; | 1188 | 586k | } else { | 1189 | 586k | CHECK(FUNC(ref_pic_list_modification)(ctx, rw, current)); | 1190 | 586k | } | 1191 | | | 1192 | 544k | if ((pps->weighted_pred_flag && (slice_type_p || slice_type_sp)) || | 1193 | 490k | (pps->weighted_bipred_idc == 1 && slice_type_b)) { | 1194 | 75.3k | CHECK(FUNC(pred_weight_table)(ctx, rw, current)); | 1195 | 75.3k | } | 1196 | | | 1197 | 509k | if (current->nal_unit_header.nal_ref_idc != 0) { | 1198 | 428k | CHECK(FUNC(dec_ref_pic_marking)(ctx, rw, current, idr_pic_flag)); | 1199 | 428k | } | 1200 | | | 1201 | 496k | if (pps->entropy_coding_mode_flag && | 1202 | 59.9k | !slice_type_i && !slice_type_si) { | 1203 | 31.5k | ue(cabac_init_idc, 0, 2); | 1204 | 31.5k | } | 1205 | | | 1206 | 492k | se(slice_qp_delta, - 51 - 6 * sps->bit_depth_luma_minus8, | 1207 | 485k | + 51 + 6 * sps->bit_depth_luma_minus8); | 1208 | 485k | if (slice_type_sp || slice_type_si) { | 1209 | 41.9k | if (slice_type_sp) | 1210 | 41.9k | flag(sp_for_switch_flag); | 1211 | 41.1k | se(slice_qs_delta, -51, +51); | 1212 | 41.1k | } | 1213 | | | 1214 | 482k | if (pps->deblocking_filter_control_present_flag) { | 1215 | 426k | ue(disable_deblocking_filter_idc, 0, 2); | 1216 | 420k | if (current->disable_deblocking_filter_idc != 1) { | 1217 | 133k | se(slice_alpha_c0_offset_div2, -6, +6); | 1218 | 130k | se(slice_beta_offset_div2, -6, +6); | 1219 | 287k | } else { | 1220 | 287k | infer(slice_alpha_c0_offset_div2, 0); | 1221 | 287k | infer(slice_beta_offset_div2, 0); | 1222 | 287k | } | 1223 | 420k | } else { | 1224 | 56.3k | infer(disable_deblocking_filter_idc, 0); | 1225 | 56.3k | infer(slice_alpha_c0_offset_div2, 0); | 1226 | 56.3k | infer(slice_beta_offset_div2, 0); | 1227 | 56.3k | } | 1228 | | | 1229 | 472k | if (pps->num_slice_groups_minus1 > 0 && | 1230 | 35.0k | pps->slice_group_map_type >= 3 && | 1231 | 22.8k | pps->slice_group_map_type <= 5) { | 1232 | 12.3k | unsigned int pic_size, max, bits; | 1233 | | | 1234 | 12.3k | pic_size = (sps->pic_width_in_mbs_minus1 + 1) * | 1235 | 12.3k | (sps->pic_height_in_map_units_minus1 + 1); | 1236 | 12.3k | max = (pic_size + pps->slice_group_change_rate_minus1) / | 1237 | 12.3k | (pps->slice_group_change_rate_minus1 + 1); | 1238 | 12.3k | bits = av_ceil_log2(max + 1); | 1239 | | | 1240 | 12.3k | u(bits, slice_group_change_cycle, 0, max); | 1241 | 12.3k | } | 1242 | | | 1243 | 470k | if (pps->entropy_coding_mode_flag) { | 1244 | 207k | while (byte_alignment(rw)) | 1245 | 161k | fixed(1, cabac_alignment_one_bit, 1); | 1246 | 50.6k | } | 1247 | | | 1248 | 465k | return 0; | 1249 | 470k | } |
cbs_h264.c:cbs_h264_write_slice_header Line | Count | Source | 1057 | 34.8k | { | 1058 | 34.8k | CodedBitstreamH264Context *h264 = ctx->priv_data; | 1059 | 34.8k | const H264RawSPS *sps; | 1060 | 34.8k | const H264RawPPS *pps; | 1061 | 34.8k | int err; | 1062 | 34.8k | int idr_pic_flag; | 1063 | 34.8k | int slice_type_i, slice_type_p, slice_type_b; | 1064 | 34.8k | int slice_type_si, slice_type_sp; | 1065 | | | 1066 | 34.8k | HEADER("Slice Header"); | 1067 | | | 1068 | 34.8k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 1069 | 34.8k | 1 << H264_NAL_SLICE | | 1070 | 34.8k | 1 << H264_NAL_IDR_SLICE | | 1071 | 34.8k | 1 << H264_NAL_AUXILIARY_SLICE)); | 1072 | | | 1073 | 34.8k | if (current->nal_unit_header.nal_unit_type == H264_NAL_AUXILIARY_SLICE) { | 1074 | 1.83k | if (!h264->last_slice_nal_unit_type) { | 1075 | 431 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Auxiliary slice " | 1076 | 431 | "is not decodable without the main picture " | 1077 | 431 | "in the same access unit.\n"); | 1078 | 431 | return AVERROR_INVALIDDATA; | 1079 | 431 | } | 1080 | 1.40k | idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE; | 1081 | 33.0k | } else { | 1082 | 33.0k | idr_pic_flag = current->nal_unit_header.nal_unit_type == H264_NAL_IDR_SLICE; | 1083 | 33.0k | } | 1084 | | | 1085 | 34.4k | ue(first_mb_in_slice, 0, H264_MAX_MB_PIC_SIZE - 1); | 1086 | 34.4k | ue(slice_type, 0, 9); | 1087 | | | 1088 | 34.4k | slice_type_i = current->slice_type % 5 == 2; | 1089 | 34.4k | slice_type_p = current->slice_type % 5 == 0; | 1090 | 34.4k | slice_type_b = current->slice_type % 5 == 1; | 1091 | 34.4k | slice_type_si = current->slice_type % 5 == 4; | 1092 | 34.4k | slice_type_sp = current->slice_type % 5 == 3; | 1093 | | | 1094 | 34.4k | if (idr_pic_flag && !(slice_type_i || slice_type_si)) { | 1095 | 425 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid slice type %d " | 1096 | 425 | "for IDR picture.\n", current->slice_type); | 1097 | 425 | return AVERROR_INVALIDDATA; | 1098 | 425 | } | 1099 | | | 1100 | 34.0k | ue(pic_parameter_set_id, 0, 255); | 1101 | | | 1102 | 34.0k | pps = h264->pps[current->pic_parameter_set_id]; | 1103 | 34.0k | if (!pps) { | 1104 | 783 | av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n", | 1105 | 783 | current->pic_parameter_set_id); | 1106 | 783 | return AVERROR_INVALIDDATA; | 1107 | 783 | } | 1108 | 33.2k | h264->active_pps = pps; | 1109 | | | 1110 | 33.2k | sps = h264->sps[pps->seq_parameter_set_id]; | 1111 | 33.2k | if (!sps) { | 1112 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n", | 1113 | 0 | pps->seq_parameter_set_id); | 1114 | 0 | return AVERROR_INVALIDDATA; | 1115 | 0 | } | 1116 | 33.2k | h264->active_sps = sps; | 1117 | | | 1118 | 33.2k | if (sps->separate_colour_plane_flag) | 1119 | 33.2k | u(2, colour_plane_id, 0, 2); | 1120 | | | 1121 | 33.2k | ub(sps->log2_max_frame_num_minus4 + 4, frame_num); | 1122 | | | 1123 | 32.6k | if (!sps->frame_mbs_only_flag) { | 1124 | 16.0k | flag(field_pic_flag); | 1125 | 16.0k | if (current->field_pic_flag) | 1126 | 16.0k | flag(bottom_field_flag); | 1127 | 6.95k | else | 1128 | 6.95k | infer(bottom_field_flag, 0); | 1129 | 16.5k | } else { | 1130 | 16.5k | infer(field_pic_flag, 0); | 1131 | 15.9k | infer(bottom_field_flag, 0); | 1132 | 15.9k | } | 1133 | | | 1134 | 32.0k | if (idr_pic_flag) | 1135 | 32.0k | ue(idr_pic_id, 0, 65535); | 1136 | | | 1137 | 32.0k | if (sps->pic_order_cnt_type == 0) { | 1138 | 8.13k | ub(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, pic_order_cnt_lsb); | 1139 | 7.71k | if (pps->bottom_field_pic_order_in_frame_present_flag && | 1140 | 4.31k | !current->field_pic_flag) | 1141 | 7.71k | se(delta_pic_order_cnt_bottom, INT32_MIN + 1, INT32_MAX); | 1142 | | | 1143 | 23.8k | } else if (sps->pic_order_cnt_type == 1) { | 1144 | 15.8k | if (!sps->delta_pic_order_always_zero_flag) { | 1145 | 10.4k | se(delta_pic_order_cnt[0], INT32_MIN + 1, INT32_MAX); | 1146 | 10.4k | if (pps->bottom_field_pic_order_in_frame_present_flag && | 1147 | 4.82k | !current->field_pic_flag) | 1148 | 10.4k | se(delta_pic_order_cnt[1], INT32_MIN + 1, INT32_MAX); | 1149 | 7.37k | else | 1150 | 7.37k | infer(delta_pic_order_cnt[1], 0); | 1151 | 10.4k | } else { | 1152 | 5.45k | infer(delta_pic_order_cnt[0], 0); | 1153 | 4.94k | infer(delta_pic_order_cnt[1], 0); | 1154 | 4.94k | } | 1155 | 15.8k | } | 1156 | | | 1157 | 29.9k | if (pps->redundant_pic_cnt_present_flag) | 1158 | 29.9k | ue(redundant_pic_cnt, 0, 127); | 1159 | 18.8k | else | 1160 | 18.8k | infer(redundant_pic_cnt, 0); | 1161 | | | 1162 | 29.3k | if (current->nal_unit_header.nal_unit_type != H264_NAL_AUXILIARY_SLICE | 1163 | 28.4k | && !current->redundant_pic_cnt) | 1164 | 22.2k | h264->last_slice_nal_unit_type = | 1165 | 22.2k | current->nal_unit_header.nal_unit_type; | 1166 | | | 1167 | 29.3k | if (slice_type_b) | 1168 | 29.3k | flag(direct_spatial_mv_pred_flag); | 1169 | | | 1170 | 29.3k | if (slice_type_p || slice_type_sp || slice_type_b) { | 1171 | 22.6k | flag(num_ref_idx_active_override_flag); | 1172 | 22.6k | if (current->num_ref_idx_active_override_flag) { | 1173 | 10.8k | ue(num_ref_idx_l0_active_minus1, 0, 31); | 1174 | 10.8k | if (slice_type_b) | 1175 | 10.8k | ue(num_ref_idx_l1_active_minus1, 0, 31); | 1176 | 11.8k | } else { | 1177 | 11.8k | infer(num_ref_idx_l0_active_minus1, | 1178 | 11.8k | pps->num_ref_idx_l0_default_active_minus1); | 1179 | 11.3k | infer(num_ref_idx_l1_active_minus1, | 1180 | 11.3k | pps->num_ref_idx_l1_default_active_minus1); | 1181 | 11.3k | } | 1182 | 22.6k | } | 1183 | | | 1184 | 28.3k | if (current->nal_unit_header.nal_unit_type == 20 || | 1185 | 28.3k | current->nal_unit_header.nal_unit_type == 21) { | 1186 | 0 | av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC / 3DAVC not supported.\n"); | 1187 | 0 | return AVERROR_PATCHWELCOME; | 1188 | 28.3k | } else { | 1189 | 28.3k | CHECK(FUNC(ref_pic_list_modification)(ctx, rw, current)); | 1190 | 28.3k | } | 1191 | | | 1192 | 26.5k | if ((pps->weighted_pred_flag && (slice_type_p || slice_type_sp)) || | 1193 | 19.2k | (pps->weighted_bipred_idc == 1 && slice_type_b)) { | 1194 | 9.08k | CHECK(FUNC(pred_weight_table)(ctx, rw, current)); | 1195 | 9.08k | } | 1196 | | | 1197 | 26.5k | if (current->nal_unit_header.nal_ref_idc != 0) { | 1198 | 14.3k | CHECK(FUNC(dec_ref_pic_marking)(ctx, rw, current, idr_pic_flag)); | 1199 | 14.3k | } | 1200 | | | 1201 | 24.7k | if (pps->entropy_coding_mode_flag && | 1202 | 6.75k | !slice_type_i && !slice_type_si) { | 1203 | 4.86k | ue(cabac_init_idc, 0, 2); | 1204 | 4.86k | } | 1205 | | | 1206 | 24.7k | se(slice_qp_delta, - 51 - 6 * sps->bit_depth_luma_minus8, | 1207 | 24.0k | + 51 + 6 * sps->bit_depth_luma_minus8); | 1208 | 24.0k | if (slice_type_sp || slice_type_si) { | 1209 | 5.85k | if (slice_type_sp) | 1210 | 5.85k | flag(sp_for_switch_flag); | 1211 | 5.85k | se(slice_qs_delta, -51, +51); | 1212 | 5.85k | } | 1213 | | | 1214 | 24.0k | if (pps->deblocking_filter_control_present_flag) { | 1215 | 6.31k | ue(disable_deblocking_filter_idc, 0, 2); | 1216 | 6.31k | if (current->disable_deblocking_filter_idc != 1) { | 1217 | 5.19k | se(slice_alpha_c0_offset_div2, -6, +6); | 1218 | 5.19k | se(slice_beta_offset_div2, -6, +6); | 1219 | 5.19k | } else { | 1220 | 1.11k | infer(slice_alpha_c0_offset_div2, 0); | 1221 | 1.11k | infer(slice_beta_offset_div2, 0); | 1222 | 1.11k | } | 1223 | 17.7k | } else { | 1224 | 17.7k | infer(disable_deblocking_filter_idc, 0); | 1225 | 17.2k | infer(slice_alpha_c0_offset_div2, 0); | 1226 | 16.7k | infer(slice_beta_offset_div2, 0); | 1227 | 16.7k | } | 1228 | | | 1229 | 22.5k | if (pps->num_slice_groups_minus1 > 0 && | 1230 | 8.98k | pps->slice_group_map_type >= 3 && | 1231 | 6.44k | pps->slice_group_map_type <= 5) { | 1232 | 4.43k | unsigned int pic_size, max, bits; | 1233 | | | 1234 | 4.43k | pic_size = (sps->pic_width_in_mbs_minus1 + 1) * | 1235 | 4.43k | (sps->pic_height_in_map_units_minus1 + 1); | 1236 | 4.43k | max = (pic_size + pps->slice_group_change_rate_minus1) / | 1237 | 4.43k | (pps->slice_group_change_rate_minus1 + 1); | 1238 | 4.43k | bits = av_ceil_log2(max + 1); | 1239 | | | 1240 | 4.43k | u(bits, slice_group_change_cycle, 0, max); | 1241 | 4.43k | } | 1242 | | | 1243 | 21.7k | if (pps->entropy_coding_mode_flag) { | 1244 | 20.4k | while (byte_alignment(rw)) | 1245 | 14.8k | fixed(1, cabac_alignment_one_bit, 1); | 1246 | 5.64k | } | 1247 | | | 1248 | 21.7k | return 0; | 1249 | 21.7k | } |
|
1250 | | |
1251 | | static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw, |
1252 | | H264RawFiller *current) |
1253 | 17.5k | { |
1254 | 17.5k | int err; |
1255 | | |
1256 | 17.5k | HEADER("Filler Data"); |
1257 | | |
1258 | 17.5k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, |
1259 | 17.5k | 1 << H264_NAL_FILLER_DATA)); |
1260 | | |
1261 | | #ifdef READ |
1262 | 132k | while (show_bits(rw, 8) == 0xff) { |
1263 | 117k | fixed(8, ff_byte, 0xff); |
1264 | 116k | ++current->filler_size; |
1265 | 116k | } |
1266 | | #else |
1267 | 1.49k | { |
1268 | 1.49k | uint32_t i; |
1269 | 57.7k | for (i = 0; i < current->filler_size; i++) |
1270 | 56.2k | fixed(8, ff_byte, 0xff); |
1271 | 1.49k | } |
1272 | 1.49k | #endif |
1273 | | |
1274 | 16.5k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); |
1275 | | |
1276 | 3.70k | return 0; |
1277 | 16.5k | } cbs_h264.c:cbs_h264_read_filler Line | Count | Source | 1253 | 16.0k | { | 1254 | 16.0k | int err; | 1255 | | | 1256 | 16.0k | HEADER("Filler Data"); | 1257 | | | 1258 | 16.0k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 1259 | 16.0k | 1 << H264_NAL_FILLER_DATA)); | 1260 | | | 1261 | 16.0k | #ifdef READ | 1262 | 132k | while (show_bits(rw, 8) == 0xff) { | 1263 | 117k | fixed(8, ff_byte, 0xff); | 1264 | 116k | ++current->filler_size; | 1265 | 116k | } | 1266 | | #else | 1267 | | { | 1268 | | uint32_t i; | 1269 | | for (i = 0; i < current->filler_size; i++) | 1270 | | fixed(8, ff_byte, 0xff); | 1271 | | } | 1272 | | #endif | 1273 | | | 1274 | 15.0k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 1275 | | | 1276 | 2.20k | return 0; | 1277 | 15.0k | } |
cbs_h264.c:cbs_h264_write_filler Line | Count | Source | 1253 | 1.49k | { | 1254 | 1.49k | int err; | 1255 | | | 1256 | 1.49k | HEADER("Filler Data"); | 1257 | | | 1258 | 1.49k | CHECK(FUNC(nal_unit_header)(ctx, rw, ¤t->nal_unit_header, | 1259 | 1.49k | 1 << H264_NAL_FILLER_DATA)); | 1260 | | | 1261 | | #ifdef READ | 1262 | | while (show_bits(rw, 8) == 0xff) { | 1263 | | fixed(8, ff_byte, 0xff); | 1264 | | ++current->filler_size; | 1265 | | } | 1266 | | #else | 1267 | 1.49k | { | 1268 | 1.49k | uint32_t i; | 1269 | 57.7k | for (i = 0; i < current->filler_size; i++) | 1270 | 56.2k | fixed(8, ff_byte, 0xff); | 1271 | 1.49k | } | 1272 | 1.49k | #endif | 1273 | | | 1274 | 1.49k | CHECK(FUNC(rbsp_trailing_bits)(ctx, rw)); | 1275 | | | 1276 | 1.49k | return 0; | 1277 | 1.49k | } |
|
1278 | | |
1279 | | static int FUNC(end_of_sequence)(CodedBitstreamContext *ctx, RWContext *rw, |
1280 | | H264RawNALUnitHeader *current) |
1281 | 2.34M | { |
1282 | 2.34M | HEADER("End of Sequence"); |
1283 | | |
1284 | 2.34M | return FUNC(nal_unit_header)(ctx, rw, current, |
1285 | 2.34M | 1 << H264_NAL_END_SEQUENCE); |
1286 | 2.34M | } cbs_h264.c:cbs_h264_read_end_of_sequence Line | Count | Source | 1281 | 1.18M | { | 1282 | 1.18M | HEADER("End of Sequence"); | 1283 | | | 1284 | 1.18M | return FUNC(nal_unit_header)(ctx, rw, current, | 1285 | 1.18M | 1 << H264_NAL_END_SEQUENCE); | 1286 | 1.18M | } |
cbs_h264.c:cbs_h264_write_end_of_sequence Line | Count | Source | 1281 | 1.15M | { | 1282 | 1.15M | HEADER("End of Sequence"); | 1283 | | | 1284 | 1.15M | return FUNC(nal_unit_header)(ctx, rw, current, | 1285 | 1.15M | 1 << H264_NAL_END_SEQUENCE); | 1286 | 1.15M | } |
|
1287 | | |
1288 | | static int FUNC(end_of_stream)(CodedBitstreamContext *ctx, RWContext *rw, |
1289 | | H264RawNALUnitHeader *current) |
1290 | 292k | { |
1291 | 292k | HEADER("End of Stream"); |
1292 | | |
1293 | 292k | return FUNC(nal_unit_header)(ctx, rw, current, |
1294 | 292k | 1 << H264_NAL_END_STREAM); |
1295 | 292k | } cbs_h264.c:cbs_h264_read_end_of_stream Line | Count | Source | 1290 | 147k | { | 1291 | 147k | HEADER("End of Stream"); | 1292 | | | 1293 | 147k | return FUNC(nal_unit_header)(ctx, rw, current, | 1294 | 147k | 1 << H264_NAL_END_STREAM); | 1295 | 147k | } |
cbs_h264.c:cbs_h264_write_end_of_stream Line | Count | Source | 1290 | 144k | { | 1291 | 144k | HEADER("End of Stream"); | 1292 | | | 1293 | 144k | return FUNC(nal_unit_header)(ctx, rw, current, | 1294 | 144k | 1 << H264_NAL_END_STREAM); | 1295 | 144k | } |
|