Line | Branch | Exec | 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 | 112 | static int FUNC(pbu_header)(CodedBitstreamContext *ctx, RWContext *rw, | |
20 | APVRawPBUHeader *current) | ||
21 | { | ||
22 | int err; | ||
23 | |||
24 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
|
112 | ub(8, pbu_type); |
25 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
|
112 | ub(16, group_id); |
26 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
|
112 | u(8, reserved_zero_8bits, 0, 0); |
27 | |||
28 | 112 | return 0; | |
29 | } | ||
30 | |||
31 | 34 | static int FUNC(byte_alignment)(CodedBitstreamContext *ctx, RWContext *rw) | |
32 | { | ||
33 | int err; | ||
34 | |||
35 |
2/2✓ Branch 1 taken 68 times.
✓ Branch 2 taken 17 times.
|
170 | while (byte_alignment(rw) != 0) |
36 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 68 times.
|
136 | fixed(1, alignment_bit_equal_to_zero, 0); |
37 | |||
38 | 34 | return 0; | |
39 | } | ||
40 | |||
41 | 56 | static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw, | |
42 | APVRawFiller *current) | ||
43 | { | ||
44 | int err; | ||
45 | |||
46 | #ifdef READ | ||
47 | 44 | current->filler_size = 0; | |
48 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
|
44 | while (show_bits(rw, 8) == 0xff) { |
49 | ✗ | fixed(8, ff_byte, 0xff); | |
50 | ✗ | ++current->filler_size; | |
51 | } | ||
52 | #else | ||
53 | { | ||
54 | uint32_t i; | ||
55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
12 | for (i = 0; i < current->filler_size; i++) |
56 | ✗ | fixed(8, ff_byte, 0xff); | |
57 | } | ||
58 | #endif | ||
59 | |||
60 | 56 | return 0; | |
61 | } | ||
62 | |||
63 | 34 | static int FUNC(frame_info)(CodedBitstreamContext *ctx, RWContext *rw, | |
64 | APVRawFrameInfo *current) | ||
65 | { | ||
66 | int err; | ||
67 | |||
68 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(8, profile_idc); |
69 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(8, level_idc); |
70 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(3, band_idc); |
71 | |||
72 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | u(5, reserved_zero_5bits, 0, 0); |
73 | |||
74 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(24, frame_width); |
75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(24, frame_height); |
76 | |||
77 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | u(4, chroma_format_idc, 0, 4); |
78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
34 | if (current->chroma_format_idc == 1) { |
79 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, | |
80 | "chroma_format_idc 1 for 4:2:0 is not allowed in APV.\n"); | ||
81 | ✗ | return AVERROR_INVALIDDATA; | |
82 | } | ||
83 | |||
84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | u(4, bit_depth_minus8, 2, 8); |
85 | |||
86 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(8, capture_time_distance); |
87 | |||
88 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | u(8, reserved_zero_8bits, 0, 0); |
89 | |||
90 | 34 | return 0; | |
91 | } | ||
92 | |||
93 | ✗ | static int FUNC(quantization_matrix)(CodedBitstreamContext *ctx, | |
94 | RWContext *rw, | ||
95 | APVRawQuantizationMatrix *current) | ||
96 | { | ||
97 | ✗ | const CodedBitstreamAPVContext *priv = ctx->priv_data; | |
98 | int err; | ||
99 | |||
100 | ✗ | for (int c = 0; c < priv->num_comp; c++) { | |
101 | ✗ | for (int y = 0; y < 8; y++) { | |
102 | ✗ | for (int x = 0; x < 8 ; x++) { | |
103 | ✗ | us(8, q_matrix[c][x][y], 1, 255, 3, c, x, y); | |
104 | } | ||
105 | } | ||
106 | } | ||
107 | |||
108 | ✗ | return 0; | |
109 | } | ||
110 | |||
111 | 34 | static int FUNC(tile_info)(CodedBitstreamContext *ctx, RWContext *rw, | |
112 | APVRawTileInfo *current, | ||
113 | const APVRawFrameHeader *fh) | ||
114 | { | ||
115 | 34 | CodedBitstreamAPVContext *priv = ctx->priv_data; | |
116 | 34 | int frame_width_in_mbs = (fh->frame_info.frame_width + 15) / 16; | |
117 | 34 | int frame_height_in_mbs = (fh->frame_info.frame_height + 15) / 16; | |
118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
34 | uint32_t min_tile_width = FFMAX(APV_MIN_TILE_WIDTH_IN_MBS, |
119 | (frame_width_in_mbs + APV_MAX_TILE_COLS - 1) / | ||
120 | APV_MAX_TILE_COLS); | ||
121 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
34 | uint32_t min_tile_height = FFMAX(APV_MIN_TILE_HEIGHT_IN_MBS, |
122 | (frame_height_in_mbs + APV_MAX_TILE_ROWS - 1) / | ||
123 | APV_MAX_TILE_ROWS); | ||
124 | int err; | ||
125 | |||
126 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | u(20, tile_width_in_mbs, min_tile_width, MAX_UINT_BITS(20)); |
127 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | u(20, tile_height_in_mbs, min_tile_height, MAX_UINT_BITS(20)); |
128 | |||
129 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(1, tile_size_present_in_fh_flag); |
130 | |||
131 | 34 | cbs_apv_derive_tile_info(&priv->tile_info, fh); | |
132 | |||
133 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
34 | if (current->tile_size_present_in_fh_flag) { |
134 | ✗ | for (int t = 0; t < priv->tile_info.num_tiles; t++) { | |
135 | ✗ | us(32, tile_size_in_fh[t], 10, MAX_UINT_BITS(32), 1, t); | |
136 | } | ||
137 | } | ||
138 | |||
139 | 34 | return 0; | |
140 | } | ||
141 | |||
142 | 34 | static int FUNC(frame_header)(CodedBitstreamContext *ctx, RWContext *rw, | |
143 | APVRawFrameHeader *current) | ||
144 | { | ||
145 | 34 | CodedBitstreamAPVContext *priv = ctx->priv_data; | |
146 | int err; | ||
147 | |||
148 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | CHECK(FUNC(frame_info)(ctx, rw, ¤t->frame_info)); |
149 | |||
150 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | u(8, reserved_zero_8bits, 0, 0); |
151 | |||
152 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(1, color_description_present_flag); |
153 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
34 | if (current->color_description_present_flag) { |
154 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(8, color_primaries); |
155 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(8, transfer_characteristics); |
156 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(8, matrix_coefficients); |
157 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(1, full_range_flag); |
158 | } else { | ||
159 | ✗ | infer(color_primaries, 2); | |
160 | ✗ | infer(transfer_characteristics, 2); | |
161 | ✗ | infer(matrix_coefficients, 2); | |
162 | ✗ | infer(full_range_flag, 0); | |
163 | } | ||
164 | |||
165 | 34 | priv->bit_depth = current->frame_info.bit_depth_minus8 + 8; | |
166 | 34 | priv->num_comp = cbs_apv_get_num_comp(current); | |
167 | |||
168 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | ub(1, use_q_matrix); |
169 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
34 | if (current->use_q_matrix) { |
170 | ✗ | CHECK(FUNC(quantization_matrix)(ctx, rw, | |
171 | ¤t->quantization_matrix)); | ||
172 | } else { | ||
173 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 17 times.
|
136 | for (int c = 0; c < priv->num_comp; c++) { |
174 |
2/2✓ Branch 0 taken 408 times.
✓ Branch 1 taken 51 times.
|
918 | for (int y = 0; y < 8; y++) { |
175 |
2/2✓ Branch 0 taken 3264 times.
✓ Branch 1 taken 408 times.
|
7344 | for (int x = 0; x < 8 ; x++) { |
176 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 576 times.
|
6528 | infer(quantization_matrix.q_matrix[c][y][x], 16); |
177 | } | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | CHECK(FUNC(tile_info)(ctx, rw, ¤t->tile_info, current)); |
183 | |||
184 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | u(8, reserved_zero_8bits_2, 0, 0); |
185 | |||
186 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | CHECK(FUNC(byte_alignment)(ctx, rw)); |
187 | |||
188 | 34 | return 0; | |
189 | } | ||
190 | |||
191 | 68 | static int FUNC(tile_header)(CodedBitstreamContext *ctx, RWContext *rw, | |
192 | APVRawTileHeader *current, | ||
193 | int tile_idx, uint32_t tile_size) | ||
194 | { | ||
195 | 68 | const CodedBitstreamAPVContext *priv = ctx->priv_data; | |
196 | uint16_t expected_tile_header_size; | ||
197 | uint32_t tile_size_remaining; | ||
198 | uint8_t max_qp; | ||
199 | int err; | ||
200 | |||
201 | 68 | expected_tile_header_size = 4 + priv->num_comp * (4 + 1) + 1; | |
202 | |||
203 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
|
68 | u(16, tile_header_size, |
204 | expected_tile_header_size, expected_tile_header_size); | ||
205 | |||
206 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
|
68 | u(16, tile_index, tile_idx, tile_idx); |
207 | |||
208 | 68 | tile_size_remaining = tile_size - current->tile_header_size; | |
209 |
2/2✓ Branch 0 taken 102 times.
✓ Branch 1 taken 34 times.
|
272 | for (int c = 0; c < priv->num_comp; c++) { |
210 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 102 times.
|
204 | us(32, tile_data_size[c], 1, tile_size_remaining, 1, c); |
211 | 204 | tile_size_remaining -= current->tile_data_size[c]; | |
212 | } | ||
213 | |||
214 | 68 | max_qp = 3 + priv->bit_depth * 6; | |
215 |
2/2✓ Branch 0 taken 102 times.
✓ Branch 1 taken 34 times.
|
272 | for (int c = 0; c < priv->num_comp; c++) { |
216 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 102 times.
|
204 | us(8, tile_qp[c], 0, max_qp, 1, c); |
217 | } | ||
218 | |||
219 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
|
68 | u(8, reserved_zero_8bits, 0, 0); |
220 | |||
221 | 68 | return 0; | |
222 | } | ||
223 | |||
224 | 68 | static int FUNC(tile)(CodedBitstreamContext *ctx, RWContext *rw, | |
225 | APVRawTile *current, | ||
226 | int tile_idx, uint32_t tile_size) | ||
227 | { | ||
228 | 68 | const CodedBitstreamAPVContext *priv = ctx->priv_data; | |
229 | int err; | ||
230 | |||
231 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
|
68 | CHECK(FUNC(tile_header)(ctx, rw, ¤t->tile_header, |
232 | tile_idx, tile_size)); | ||
233 | |||
234 |
2/2✓ Branch 0 taken 102 times.
✓ Branch 1 taken 34 times.
|
272 | for (int c = 0; c < priv->num_comp; c++) { |
235 | 204 | uint32_t comp_size = current->tile_header.tile_data_size[c]; | |
236 | #ifdef READ | ||
237 | 168 | int pos = get_bits_count(rw); | |
238 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
|
168 | av_assert0(pos % 8 == 0); |
239 | 168 | current->tile_data[c] = (uint8_t*)align_get_bits(rw); | |
240 | 168 | skip_bits_long(rw, 8 * comp_size); | |
241 | #else | ||
242 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
|
36 | if (put_bytes_left(rw, 0) < comp_size) |
243 | ✗ | return AVERROR(ENOSPC); | |
244 | 36 | ff_copy_bits(rw, current->tile_data[c], comp_size * 8); | |
245 | #endif | ||
246 | } | ||
247 | |||
248 | 68 | return 0; | |
249 | } | ||
250 | |||
251 | 34 | static int FUNC(frame)(CodedBitstreamContext *ctx, RWContext *rw, | |
252 | APVRawFrame *current) | ||
253 | { | ||
254 | 34 | const CodedBitstreamAPVContext *priv = ctx->priv_data; | |
255 | int err; | ||
256 | |||
257 | 34 | HEADER("Frame"); | |
258 | |||
259 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | CHECK(FUNC(pbu_header)(ctx, rw, ¤t->pbu_header)); |
260 | |||
261 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | CHECK(FUNC(frame_header)(ctx, rw, ¤t->frame_header)); |
262 | |||
263 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 17 times.
|
102 | for (int t = 0; t < priv->tile_info.num_tiles; t++) { |
264 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
|
68 | us(32, tile_size[t], 10, MAX_UINT_BITS(32), 1, t); |
265 | |||
266 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
|
68 | CHECK(FUNC(tile)(ctx, rw, ¤t->tile[t], |
267 | t, current->tile_size[t])); | ||
268 | } | ||
269 | |||
270 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
34 | CHECK(FUNC(filler)(ctx, rw, ¤t->filler)); |
271 | |||
272 | 34 | return 0; | |
273 | } | ||
274 | |||
275 | ✗ | static int FUNC(au_info)(CodedBitstreamContext *ctx, RWContext *rw, | |
276 | APVRawAUInfo *current) | ||
277 | { | ||
278 | int err; | ||
279 | |||
280 | ✗ | HEADER("Access Unit Information"); | |
281 | |||
282 | ✗ | u(16, num_frames, 1, CBS_APV_MAX_AU_FRAMES); | |
283 | |||
284 | ✗ | for (int i = 0; i < current->num_frames; i++) { | |
285 | ✗ | ubs(8, pbu_type[i], 1, i); | |
286 | ✗ | ubs(8, group_id[i], 1, i); | |
287 | |||
288 | ✗ | us(8, reserved_zero_8bits[i], 0, 0, 1, i); | |
289 | |||
290 | ✗ | CHECK(FUNC(frame_info)(ctx, rw, ¤t->frame_info[i])); | |
291 | } | ||
292 | |||
293 | ✗ | u(8, reserved_zero_8bits_2, 0, 0); | |
294 | |||
295 | ✗ | return 0; | |
296 | } | ||
297 | |||
298 | ✗ | static int FUNC(metadata_itu_t_t35)(CodedBitstreamContext *ctx, | |
299 | RWContext *rw, | ||
300 | APVRawMetadataITUTT35 *current, | ||
301 | size_t payload_size) | ||
302 | { | ||
303 | int err; | ||
304 | ✗ | size_t read_size = payload_size - 1; | |
305 | |||
306 | ✗ | HEADER("ITU-T T.35 Metadata"); | |
307 | |||
308 | ✗ | ub(8, itu_t_t35_country_code); | |
309 | |||
310 | ✗ | if (current->itu_t_t35_country_code == 0xff) { | |
311 | ✗ | ub(8, itu_t_t35_country_code_extension); | |
312 | ✗ | --read_size; | |
313 | } | ||
314 | |||
315 | #ifdef READ | ||
316 | ✗ | current->data_size = read_size; | |
317 | ✗ | current->data_ref = av_buffer_alloc(current->data_size); | |
318 | ✗ | if (!current->data_ref) | |
319 | ✗ | return AVERROR(ENOMEM); | |
320 | ✗ | current->data = current->data_ref->data; | |
321 | #else | ||
322 | ✗ | if (current->data_size != read_size) { | |
323 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Write size mismatch: " | |
324 | "payload %zu but expecting %zu\n", | ||
325 | current->data_size, read_size); | ||
326 | ✗ | return AVERROR(EINVAL); | |
327 | } | ||
328 | #endif | ||
329 | |||
330 | ✗ | for (size_t i = 0; i < current->data_size; i++) { | |
331 | ✗ | xu(8, itu_t_t35_payload[i], | |
332 | current->data[i], 0x00, 0xff, 1, i); | ||
333 | } | ||
334 | |||
335 | ✗ | return 0; | |
336 | } | ||
337 | |||
338 | ✗ | static int FUNC(metadata_mdcv)(CodedBitstreamContext *ctx, | |
339 | RWContext *rw, | ||
340 | APVRawMetadataMDCV *current) | ||
341 | { | ||
342 | int err, i; | ||
343 | |||
344 | ✗ | HEADER("MDCV Metadata"); | |
345 | |||
346 | ✗ | for (i = 0; i < 3; i++) { | |
347 | ✗ | ubs(16, primary_chromaticity_x[i], 1, i); | |
348 | ✗ | ubs(16, primary_chromaticity_y[i], 1, i); | |
349 | } | ||
350 | |||
351 | ✗ | ub(16, white_point_chromaticity_x); | |
352 | ✗ | ub(16, white_point_chromaticity_y); | |
353 | |||
354 | ✗ | ub(32, max_mastering_luminance); | |
355 | ✗ | ub(32, min_mastering_luminance); | |
356 | |||
357 | ✗ | return 0; | |
358 | } | ||
359 | |||
360 | ✗ | static int FUNC(metadata_cll)(CodedBitstreamContext *ctx, | |
361 | RWContext *rw, | ||
362 | APVRawMetadataCLL *current) | ||
363 | { | ||
364 | int err; | ||
365 | |||
366 | ✗ | HEADER("CLL Metadata"); | |
367 | |||
368 | ✗ | ub(16, max_cll); | |
369 | ✗ | ub(16, max_fall); | |
370 | |||
371 | ✗ | return 0; | |
372 | } | ||
373 | |||
374 | ✗ | static int FUNC(metadata_filler)(CodedBitstreamContext *ctx, | |
375 | RWContext *rw, | ||
376 | APVRawMetadataFiller *current, | ||
377 | size_t payload_size) | ||
378 | { | ||
379 | int err; | ||
380 | |||
381 | ✗ | HEADER("Filler Metadata"); | |
382 | |||
383 | ✗ | for (size_t i = 0; i < payload_size; i++) | |
384 | ✗ | fixed(8, ff_byte, 0xff); | |
385 | |||
386 | ✗ | return 0; | |
387 | } | ||
388 | |||
389 | 56 | static int FUNC(metadata_user_defined)(CodedBitstreamContext *ctx, | |
390 | RWContext *rw, | ||
391 | APVRawMetadataUserDefined *current, | ||
392 | size_t payload_size) | ||
393 | { | ||
394 | int err; | ||
395 | |||
396 | 56 | HEADER("User-Defined Metadata"); | |
397 | |||
398 |
2/2✓ Branch 0 taken 448 times.
✓ Branch 1 taken 28 times.
|
952 | for (int i = 0; i < 16; i++) |
399 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 448 times.
|
896 | ubs(8, uuid[i], 1, i); |
400 | |||
401 | #ifdef READ | ||
402 | 32 | current->data_size = payload_size - 16; | |
403 | 32 | current->data_ref = av_buffer_alloc(current->data_size); | |
404 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
32 | if (!current->data_ref) |
405 | ✗ | return AVERROR(ENOMEM); | |
406 | 32 | current->data = current->data_ref->data; | |
407 | #else | ||
408 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
24 | if (current->data_size != payload_size - 16) { |
409 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Write size mismatch: " | |
410 | "payload %zu but expecting %zu\n", | ||
411 | current->data_size, payload_size - 16); | ||
412 | ✗ | return AVERROR(EINVAL); | |
413 | } | ||
414 | #endif | ||
415 | |||
416 |
2/2✓ Branch 0 taken 1106 times.
✓ Branch 1 taken 28 times.
|
2268 | for (size_t i = 0; i < current->data_size; i++) { |
417 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1106 times.
|
2212 | xu(8, user_defined_data_payload[i], |
418 | current->data[i], 0x00, 0xff, 1, i); | ||
419 | } | ||
420 | |||
421 | 56 | return 0; | |
422 | } | ||
423 | |||
424 | ✗ | static int FUNC(metadata_undefined)(CodedBitstreamContext *ctx, | |
425 | RWContext *rw, | ||
426 | APVRawMetadataUndefined *current, | ||
427 | size_t payload_size) | ||
428 | { | ||
429 | int err; | ||
430 | |||
431 | ✗ | HEADER("Undefined Metadata"); | |
432 | |||
433 | #ifdef READ | ||
434 | ✗ | current->data_size = payload_size; | |
435 | ✗ | current->data_ref = av_buffer_alloc(current->data_size); | |
436 | ✗ | if (!current->data_ref) | |
437 | ✗ | return AVERROR(ENOMEM); | |
438 | ✗ | current->data = current->data_ref->data; | |
439 | #else | ||
440 | ✗ | if (current->data_size != payload_size) { | |
441 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Write size mismatch: " | |
442 | "payload %zu but expecting %zu\n", | ||
443 | current->data_size, payload_size - 16); | ||
444 | ✗ | return AVERROR(EINVAL); | |
445 | } | ||
446 | #endif | ||
447 | |||
448 | ✗ | for (size_t i = 0; i < current->data_size; i++) { | |
449 | ✗ | xu(8, undefined_metadata_payload_byte[i], | |
450 | current->data[i], 0x00, 0xff, 1, i); | ||
451 | } | ||
452 | |||
453 | ✗ | return 0; | |
454 | } | ||
455 | |||
456 | 56 | static int FUNC(metadata_payload)(CodedBitstreamContext *ctx, | |
457 | RWContext *rw, | ||
458 | APVRawMetadataPayload *current) | ||
459 | { | ||
460 | int err; | ||
461 | |||
462 |
1/6✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
|
56 | switch (current->payload_type) { |
463 | ✗ | case APV_METADATA_ITU_T_T35: | |
464 | ✗ | CHECK(FUNC(metadata_itu_t_t35)(ctx, rw, | |
465 | ¤t->itu_t_t35, | ||
466 | current->payload_size)); | ||
467 | ✗ | break; | |
468 | ✗ | case APV_METADATA_MDCV: | |
469 | ✗ | CHECK(FUNC(metadata_mdcv)(ctx, rw, ¤t->mdcv)); | |
470 | ✗ | break; | |
471 | ✗ | case APV_METADATA_CLL: | |
472 | ✗ | CHECK(FUNC(metadata_cll)(ctx, rw, ¤t->cll)); | |
473 | ✗ | break; | |
474 | ✗ | case APV_METADATA_FILLER: | |
475 | ✗ | CHECK(FUNC(metadata_filler)(ctx, rw, | |
476 | ¤t->filler, | ||
477 | current->payload_size)); | ||
478 | ✗ | break; | |
479 | 56 | case APV_METADATA_USER_DEFINED: | |
480 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
|
56 | CHECK(FUNC(metadata_user_defined)(ctx, rw, |
481 | ¤t->user_defined, | ||
482 | current->payload_size)); | ||
483 | 56 | break; | |
484 | ✗ | default: | |
485 | ✗ | CHECK(FUNC(metadata_undefined)(ctx, rw, | |
486 | ¤t->undefined, | ||
487 | current->payload_size)); | ||
488 | } | ||
489 | |||
490 | 56 | return 0; | |
491 | } | ||
492 | |||
493 | 11 | static int FUNC(metadata)(CodedBitstreamContext *ctx, RWContext *rw, | |
494 | APVRawMetadata *current) | ||
495 | { | ||
496 | int err; | ||
497 | |||
498 | #ifdef READ | ||
499 | uint32_t metadata_bytes_left; | ||
500 | #else | ||
501 | PutBitContext metadata_start_state; | ||
502 | uint32_t metadata_start_position; | ||
503 | int trace; | ||
504 | #endif | ||
505 | |||
506 | 11 | HEADER("Metadata"); | |
507 | |||
508 | 11 | CHECK(FUNC(pbu_header)(ctx, rw, ¤t->pbu_header)); | |
509 | |||
510 | #ifdef READ | ||
511 | 8 | ub(32, metadata_size); | |
512 | |||
513 | 8 | metadata_bytes_left = current->metadata_size; | |
514 | |||
515 | 16 | for (int p = 0; p < CBS_APV_MAX_METADATA_PAYLOADS; p++) { | |
516 | 16 | APVRawMetadataPayload *pl = ¤t->payloads[p]; | |
517 | uint32_t tmp; | ||
518 | |||
519 | 16 | pl->payload_type = 0; | |
520 | 16 | while (show_bits(rw, 8) == 0xff) { | |
521 | ✗ | fixed(8, ff_byte, 0xff); | |
522 | ✗ | pl->payload_type += 255; | |
523 | ✗ | --metadata_bytes_left; | |
524 | } | ||
525 | 16 | xu(8, metadata_payload_type, tmp, 0, 254, 0); | |
526 | 16 | pl->payload_type += tmp; | |
527 | 16 | --metadata_bytes_left; | |
528 | |||
529 | 16 | pl->payload_size = 0; | |
530 | 16 | while (show_bits(rw, 8) == 0xff) { | |
531 | ✗ | fixed(8, ff_byte, 0xff); | |
532 | ✗ | pl->payload_size += 255; | |
533 | ✗ | --metadata_bytes_left; | |
534 | } | ||
535 | 16 | xu(8, metadata_payload_size, tmp, 0, 254, 0); | |
536 | 16 | pl->payload_size += tmp; | |
537 | 16 | --metadata_bytes_left; | |
538 | |||
539 | 16 | if (pl->payload_size > metadata_bytes_left) { | |
540 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid metadata: " | |
541 | "payload_size larger than remaining metadata size " | ||
542 | "(%"PRIu32" bytes).\n", pl->payload_size); | ||
543 | ✗ | return AVERROR_INVALIDDATA; | |
544 | } | ||
545 | |||
546 | 16 | CHECK(FUNC(metadata_payload)(ctx, rw, pl)); | |
547 | |||
548 | 16 | metadata_bytes_left -= pl->payload_size; | |
549 | |||
550 | 16 | current->metadata_count = p + 1; | |
551 | 16 | if (metadata_bytes_left == 0) | |
552 | 8 | break; | |
553 | } | ||
554 | #else | ||
555 | // Two passes: the first write finds the size (with tracing | ||
556 | // disabled), the second write does the real write. | ||
557 | |||
558 | 3 | metadata_start_state = *rw; | |
559 | 3 | metadata_start_position = put_bits_count(rw); | |
560 | |||
561 | 3 | trace = ctx->trace_enable; | |
562 | 3 | ctx->trace_enable = 0; | |
563 | |||
564 | 9 | for (int pass = 1; pass <= 2; pass++) { | |
565 | 6 | *rw = metadata_start_state; | |
566 | |||
567 | 6 | ub(32, metadata_size); | |
568 | |||
569 | 18 | for (int p = 0; p < current->metadata_count; p++) { | |
570 | 12 | APVRawMetadataPayload *pl = ¤t->payloads[p]; | |
571 | uint32_t payload_start_position; | ||
572 | uint32_t tmp; | ||
573 | |||
574 | 12 | tmp = pl->payload_type; | |
575 | 12 | while (tmp >= 255) { | |
576 | ✗ | fixed(8, ff_byte, 0xff); | |
577 | ✗ | tmp -= 255; | |
578 | } | ||
579 | 12 | xu(8, metadata_payload_type, tmp, 0, 254, 0); | |
580 | |||
581 | 12 | tmp = pl->payload_size; | |
582 | 12 | while (tmp >= 255) { | |
583 | ✗ | fixed(8, ff_byte, 0xff); | |
584 | ✗ | tmp -= 255; | |
585 | } | ||
586 | 12 | xu(8, metadata_payload_size, tmp, 0, 254, 0); | |
587 | |||
588 | 12 | payload_start_position = put_bits_count(rw); | |
589 | |||
590 | 12 | err = FUNC(metadata_payload)(ctx, rw, pl); | |
591 | 12 | ctx->trace_enable = trace; | |
592 | 12 | if (err < 0) | |
593 | ✗ | return err; | |
594 | |||
595 | 12 | if (pass == 1) { | |
596 | 6 | pl->payload_size = (put_bits_count(rw) - | |
597 | 6 | payload_start_position) / 8; | |
598 | } | ||
599 | } | ||
600 | |||
601 | 6 | if (pass == 1) { | |
602 | 3 | current->metadata_size = (put_bits_count(rw) - | |
603 | 3 | metadata_start_position) / 8 - 4; | |
604 | 3 | ctx->trace_enable = trace; | |
605 | } | ||
606 | } | ||
607 | #endif | ||
608 | |||
609 | 11 | CHECK(FUNC(filler)(ctx, rw, ¤t->filler)); | |
610 | |||
611 | 11 | return 0; | |
612 | } | ||
613 |