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