FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/apv_decode.c
Date: 2026-06-06 18:10:07
Exec Total Coverage
Lines: 196 296 66.2%
Functions: 12 14 85.7%
Branches: 66 120 55.0%

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 #include <stdatomic.h>
20
21 #include "libavutil/attributes.h"
22 #include "libavutil/avassert.h"
23 #include "libavutil/mastering_display_metadata.h"
24 #include "libavutil/mem_internal.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/thread.h"
27
28 #include "apv.h"
29 #include "apv_decode.h"
30 #include "avcodec.h"
31 #include "cbs_apv.h"
32 #include "codec_internal.h"
33 #include "decode.h"
34 #include "internal.h"
35 #include "thread.h"
36 #include "hwconfig.h"
37 #include "hwaccel_internal.h"
38 #include "config_components.h"
39
40 static const enum AVPixelFormat apv_format_table[5][4] = {
41 { AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16 },
42 { AV_PIX_FMT_NONE, AV_PIX_FMT_NONE, AV_PIX_FMT_NONE, AV_PIX_FMT_NONE }, // 4:2:0 is not valid.
43 { AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV422P16 },
44 { AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV444P16 },
45 { AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_NONE, AV_PIX_FMT_YUVA444P16 },
46 };
47
48 APVVLCLUT ff_apv_decode_lut;
49
50 8 static enum AVPixelFormat get_pixel_format(AVCodecContext *avctx,
51 enum AVPixelFormat pix_fmt)
52 {
53 8 enum AVPixelFormat pix_fmts[] = {
54 #if CONFIG_APV_VULKAN_HWACCEL
55 AV_PIX_FMT_VULKAN,
56 #endif
57 pix_fmt,
58 AV_PIX_FMT_NONE,
59 };
60
61 8 return ff_get_format(avctx, pix_fmts);
62 }
63
64 12 static int apv_decode_check_format(AVCodecContext *avctx,
65 const APVRawFrameHeader *header)
66 {
67 int err, bit_depth;
68 enum AVPixelFormat pix_fmt;
69 12 int coded_width = FFALIGN(header->frame_info.frame_width, 16);
70 12 int coded_height = FFALIGN(header->frame_info.frame_height, 16);
71 12 APVDecodeContext *apv = avctx->priv_data;
72
73 12 avctx->profile = header->frame_info.profile_idc;
74 12 avctx->level = header->frame_info.level_idc;
75
76 12 bit_depth = header->frame_info.bit_depth_minus8 + 8;
77 av_assert1(bit_depth >= 10 && bit_depth <= 16); // checked by CBS
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (bit_depth % 2) {
79 avpriv_request_sample(avctx, "Bit depth %d", bit_depth);
80 return AVERROR_PATCHWELCOME;
81 }
82
83 12 pix_fmt = apv_format_table[header->frame_info.chroma_format_idc][(bit_depth - 10) >> 1];
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (pix_fmt == AV_PIX_FMT_NONE) {
85 avpriv_request_sample(avctx, "YUVA444P14");
86 return AVERROR_PATCHWELCOME;
87 }
88
89
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 5 times.
12 if (avctx->coded_width != coded_width ||
90
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
7 avctx->coded_height != coded_height) {
91 8 err = ff_set_dimensions(avctx, coded_width, coded_height);
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (err < 0) {
93 // Unsupported frame size.
94 return err;
95 }
96 }
97
98 12 avctx->width = header->frame_info.frame_width;
99 12 avctx->height = header->frame_info.frame_height;
100
101
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if (pix_fmt != apv->pix_fmt) {
102 8 apv->pix_fmt = pix_fmt;
103
104 8 err = get_pixel_format(avctx, pix_fmt);
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (err < 0)
106 return err;
107
108 8 avctx->pix_fmt = err;
109 }
110
111 12 avctx->sample_aspect_ratio = (AVRational){ 1, 1 };
112
113 12 avctx->color_primaries = header->color_primaries;
114 12 avctx->color_trc = header->transfer_characteristics;
115 12 avctx->colorspace = header->matrix_coefficients;
116 24 avctx->color_range = header->full_range_flag ? AVCOL_RANGE_JPEG
117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 : AVCOL_RANGE_MPEG;
118 12 avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
119
120 12 avctx->refs = 0;
121 12 avctx->has_b_frames = 0;
122
123 12 return 0;
124 }
125
126 static const CodedBitstreamUnitType apv_decompose_unit_types[] = {
127 APV_PBU_PRIMARY_FRAME,
128 APV_PBU_METADATA,
129 };
130
131 static AVOnce apv_entropy_once = AV_ONCE_INIT;
132
133 6 static av_cold void apv_entropy_build_decode_lut(void)
134 {
135 6 ff_apv_entropy_build_decode_lut(&ff_apv_decode_lut);
136 6 }
137
138 8 static av_cold int apv_decode_init(AVCodecContext *avctx)
139 {
140 8 APVDecodeContext *apv = avctx->priv_data;
141 int err;
142
143 8 apv->pix_fmt = AV_PIX_FMT_NONE;
144
145 8 ff_thread_once(&apv_entropy_once, apv_entropy_build_decode_lut);
146
147 8 err = ff_cbs_init(&apv->cbc, AV_CODEC_ID_APV, avctx);
148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (err < 0)
149 return err;
150
151 8 apv->cbc->decompose_unit_types =
152 apv_decompose_unit_types;
153 8 apv->cbc->nb_decompose_unit_types =
154 FF_ARRAY_ELEMS(apv_decompose_unit_types);
155
156 // Extradata could be set here, but is ignored by the decoder.
157
158 8 apv->pkt = avctx->internal->in_pkt;
159 8 ff_apv_dsp_init(&apv->dsp);
160
161 8 atomic_init(&apv->tile_errors, 0);
162
163 8 return 0;
164 }
165
166 static av_cold void apv_decode_flush(AVCodecContext *avctx)
167 {
168 APVDecodeContext *apv = avctx->priv_data;
169
170 apv->nb_unit = 0;
171 av_packet_unref(apv->pkt);
172 ff_cbs_fragment_reset(&apv->au);
173 ff_cbs_flush(apv->cbc);
174 }
175
176 8 static av_cold int apv_decode_close(AVCodecContext *avctx)
177 {
178 8 APVDecodeContext *apv = avctx->priv_data;
179
180 8 ff_cbs_fragment_free(&apv->au);
181 8 ff_cbs_close(&apv->cbc);
182
183 8 return 0;
184 }
185
186 8640 static int apv_decode_block(AVCodecContext *avctx,
187 void *output,
188 ptrdiff_t pitch,
189 GetBitContext *gbc,
190 APVEntropyState *entropy_state,
191 int bit_depth,
192 int qp_shift,
193 const uint16_t *qmatrix)
194 {
195 8640 APVDecodeContext *apv = avctx->priv_data;
196 int err;
197
198 8640 LOCAL_ALIGNED_32(int16_t, coeff, [64]);
199 8640 memset(coeff, 0, 64 * sizeof(int16_t));
200
201 8640 err = ff_apv_entropy_decode_block(coeff, gbc, entropy_state);
202
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8640 times.
8640 if (err < 0)
203 return err;
204
205 8640 apv->dsp.decode_transquant(output, pitch,
206 coeff, qmatrix,
207 bit_depth, qp_shift);
208
209 8640 return 0;
210 }
211
212 24 static int apv_decode_tile_component(AVCodecContext *avctx, void *data,
213 int job, int thread)
214 {
215 24 APVRawFrame *input = data;
216 24 APVDecodeContext *apv = avctx->priv_data;
217 24 const APVDerivedTileInfo *tile_info = &apv->tile_info;
218 const AVPixFmtDescriptor *pix_fmt_desc =
219 24 av_pix_fmt_desc_get(apv->pix_fmt);
220 24 int nb_components = pix_fmt_desc->nb_components;
221
222 24 int tile_index = job / nb_components;
223 24 int comp_index = job % nb_components;
224
225
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 int sub_w_shift = comp_index == 0 ? 0 : pix_fmt_desc->log2_chroma_w;
226
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 int sub_h_shift = comp_index == 0 ? 0 : pix_fmt_desc->log2_chroma_h;
227
228 24 APVRawTile *tile = &input->tile[tile_index];
229
230 24 int tile_y = tile_index / tile_info->tile_cols;
231 24 int tile_x = tile_index % tile_info->tile_cols;
232
233 24 int tile_start_x = tile_info->col_starts[tile_x];
234 24 int tile_start_y = tile_info->row_starts[tile_y];
235
236 24 int tile_width = tile_info->col_starts[tile_x + 1] - tile_start_x;
237 24 int tile_height = tile_info->row_starts[tile_y + 1] - tile_start_y;
238
239 24 int tile_mb_width = tile_width / APV_MB_WIDTH;
240 24 int tile_mb_height = tile_height / APV_MB_HEIGHT;
241
242 24 int blk_mb_width = 2 >> sub_w_shift;
243 24 int blk_mb_height = 2 >> sub_h_shift;
244
245 int bit_depth;
246 int qp_shift;
247 24 LOCAL_ALIGNED_32(uint16_t, qmatrix_scaled, [64]);
248
249 GetBitContext gbc;
250
251 24 APVEntropyState entropy_state = {
252 .log_ctx = avctx,
253 .decode_lut = &ff_apv_decode_lut,
254 .prev_dc = 0,
255 .prev_k_dc = 5,
256 .prev_k_level = 0,
257 };
258
259 int err;
260
261 24 err = init_get_bits8(&gbc, tile->tile_data[comp_index],
262 24 tile->tile_header.tile_data_size[comp_index]);
263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (err < 0)
264 goto fail;
265
266 // Combine the bitstream quantisation matrix with the qp scaling
267 // in advance. (Including qp_shift as well would overflow 16 bits.)
268 // Fix the row ordering at the same time.
269 {
270 static const uint8_t apv_level_scale[6] = { 40, 45, 51, 57, 64, 71 };
271 24 int qp = tile->tile_header.tile_qp[comp_index];
272 24 int level_scale = apv_level_scale[qp % 6];
273
274 24 bit_depth = input->frame_header.frame_info.bit_depth_minus8 + 8;
275 24 qp_shift = qp / 6;
276
277
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 24 times.
216 for (int y = 0; y < 8; y++) {
278
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 192 times.
1728 for (int x = 0; x < 8; x++)
279 1536 qmatrix_scaled[y * 8 + x] = level_scale *
280 1536 input->frame_header.quantization_matrix.q_matrix[comp_index][x][y];
281 }
282 }
283
284
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 24 times.
312 for (int mb_y = 0; mb_y < tile_mb_height; mb_y++) {
285
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 288 times.
3168 for (int mb_x = 0; mb_x < tile_mb_width; mb_x++) {
286
2/2
✓ Branch 0 taken 5760 times.
✓ Branch 1 taken 2880 times.
8640 for (int blk_y = 0; blk_y < blk_mb_height; blk_y++) {
287
2/2
✓ Branch 0 taken 8640 times.
✓ Branch 1 taken 5760 times.
14400 for (int blk_x = 0; blk_x < blk_mb_width; blk_x++) {
288 8640 int frame_y = (tile_start_y +
289 8640 APV_MB_HEIGHT * mb_y +
290 8640 APV_TR_SIZE * blk_y) >> sub_h_shift;
291 8640 int frame_x = (tile_start_x +
292 8640 APV_MB_WIDTH * mb_x +
293 8640 APV_TR_SIZE * blk_x) >> sub_w_shift;
294
295 8640 ptrdiff_t frame_pitch = apv->output_frame->linesize[comp_index];
296 8640 uint8_t *block_start = apv->output_frame->data[comp_index] +
297 8640 frame_y * frame_pitch + 2 * frame_x;
298
299 8640 err = apv_decode_block(avctx,
300 block_start, frame_pitch,
301 &gbc, &entropy_state,
302 bit_depth,
303 qp_shift,
304 qmatrix_scaled);
305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8640 times.
8640 if (err < 0) {
306 // Error in block decode means entropy desync,
307 // so this is not recoverable.
308 goto fail;
309 }
310 }
311 }
312 }
313 }
314
315 24 av_log(avctx, AV_LOG_TRACE,
316 "Decoded tile %d component %d: %dx%d MBs starting at (%d,%d)\n",
317 tile_index, comp_index, tile_mb_width, tile_mb_height,
318 tile_start_x, tile_start_y);
319
320 24 return 0;
321
322 fail:
323 av_log(avctx, AV_LOG_VERBOSE,
324 "Decode error in tile %d component %d.\n",
325 tile_index, comp_index);
326 atomic_fetch_add_explicit(&apv->tile_errors, 1, memory_order_relaxed);
327 return err;
328 }
329
330 6 static void apv_derive_tile_info(APVDerivedTileInfo *ti,
331 const APVRawFrameHeader *fh)
332 {
333 6 int frame_width_in_mbs = (fh->frame_info.frame_width + (APV_MB_WIDTH - 1)) >> 4;
334 6 int frame_height_in_mbs = (fh->frame_info.frame_height + (APV_MB_HEIGHT - 1)) >> 4;
335 int start_mb, i;
336
337 6 start_mb = 0;
338
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for (i = 0; start_mb < frame_width_in_mbs; i++) {
339 12 ti->col_starts[i] = start_mb * APV_MB_WIDTH;
340 12 start_mb += fh->tile_info.tile_width_in_mbs;
341 }
342 6 ti->col_starts[i] = frame_width_in_mbs * APV_MB_WIDTH;
343 6 ti->tile_cols = i;
344
345 6 start_mb = 0;
346
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (i = 0; start_mb < frame_height_in_mbs; i++) {
347 6 ti->row_starts[i] = start_mb * APV_MB_HEIGHT;
348 6 start_mb += fh->tile_info.tile_height_in_mbs;
349 }
350 6 ti->row_starts[i] = frame_height_in_mbs * APV_MB_HEIGHT;
351 6 ti->tile_rows = i;
352
353 6 ti->num_tiles = ti->tile_cols * ti->tile_rows;
354 6 }
355
356 12 static int apv_decode(AVCodecContext *avctx, AVFrame *output,
357 APVRawFrame *input)
358 {
359 12 APVDecodeContext *apv = avctx->priv_data;
360 12 const AVPixFmtDescriptor *desc = NULL;
361 12 APVDerivedTileInfo *tile_info = &apv->tile_info;
362 int err, job_count;
363
364 12 err = apv_decode_check_format(avctx, &input->frame_header);
365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (err < 0) {
366 av_log(avctx, AV_LOG_ERROR, "Unsupported format parameters.\n");
367 return err;
368 }
369
370
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (avctx->skip_frame == AVDISCARD_ALL)
371 6 return 0;
372
373 6 desc = av_pix_fmt_desc_get(apv->pix_fmt);
374
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 av_assert0(desc);
375
376 6 err = ff_thread_get_buffer(avctx, output, 0);
377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (err < 0)
378 return err;
379
380 6 apv->cur_raw_frame = input;
381 6 apv->output_frame = output;
382 6 atomic_store_explicit(&apv->tile_errors, 0, memory_order_relaxed);
383
384 6 apv_derive_tile_info(tile_info, &input->frame_header);
385
386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (avctx->hwaccel) {
387 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
388
389 err = ff_hwaccel_frame_priv_alloc(avctx, &apv->hwaccel_picture_private);
390 if (err < 0)
391 return err;
392
393 err = hwaccel->start_frame(avctx, apv->pkt->buf,
394 apv->pkt->data, apv->pkt->size);
395 if (err < 0)
396 return err;
397
398 for (int j = 0; j < desc->nb_components; j++) {
399 for (int i = 0; i < tile_info->num_tiles; i++) {
400 APVRawTile *tile = &input->tile[i];
401 err = hwaccel->decode_slice(avctx, tile->tile_data[j],
402 tile->tile_header.tile_data_size[j]);
403 if (err < 0)
404 return err;
405 }
406 }
407
408 err = hwaccel->end_frame(avctx);
409 if (err < 0)
410 return err;
411
412 av_refstruct_unref(&apv->hwaccel_picture_private);
413 } else {
414 // Each component within a tile is independent of every other,
415 // so we can decode all in parallel.
416 6 job_count = tile_info->num_tiles * desc->nb_components;
417
418 6 avctx->execute2(avctx, apv_decode_tile_component,
419 input, NULL, job_count);
420
421 6 err = atomic_load_explicit(&apv->tile_errors, memory_order_relaxed);
422
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (err > 0) {
423 av_log(avctx, AV_LOG_ERROR,
424 "Decode errors in %d tile components.\n", err);
425 if (avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) {
426 // Output the frame anyway.
427 output->flags |= AV_FRAME_FLAG_CORRUPT;
428 } else {
429 return AVERROR_INVALIDDATA;
430 }
431 }
432 }
433
434 6 return 0;
435 }
436
437 12 static int apv_decode_metadata(AVCodecContext *avctx, AVFrame *frame,
438 const APVRawMetadata *md)
439 {
440 int err;
441
442
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for (int i = 0; i < md->metadata_count; i++) {
443 24 const APVRawMetadataPayload *pl = &md->payloads[i];
444
445
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 switch (pl->payload_type) {
446 case APV_METADATA_MDCV:
447 {
448 const APVRawMetadataMDCV *mdcv = &pl->mdcv;
449 AVMasteringDisplayMetadata *mdm;
450
451 err = ff_decode_mastering_display_new(avctx, frame, &mdm);
452 if (err < 0)
453 return err;
454
455 if (mdm) {
456 for (int j = 0; j < 3; j++) {
457 mdm->display_primaries[j][0] =
458 av_make_q(mdcv->primary_chromaticity_x[j], 1 << 16);
459 mdm->display_primaries[j][1] =
460 av_make_q(mdcv->primary_chromaticity_y[j], 1 << 16);
461 }
462
463 mdm->white_point[0] =
464 av_make_q(mdcv->white_point_chromaticity_x, 1 << 16);
465 mdm->white_point[1] =
466 av_make_q(mdcv->white_point_chromaticity_y, 1 << 16);
467
468 mdm->max_luminance =
469 av_make_q(mdcv->max_mastering_luminance, 1 << 8);
470 mdm->min_luminance =
471 av_make_q(mdcv->min_mastering_luminance, 1 << 14);
472
473 mdm->has_primaries = 1;
474 mdm->has_luminance = 1;
475 }
476 }
477 break;
478 case APV_METADATA_CLL:
479 {
480 const APVRawMetadataCLL *cll = &pl->cll;
481 AVContentLightMetadata *clm;
482
483 err = ff_decode_content_light_new(avctx, frame, &clm);
484 if (err < 0)
485 return err;
486
487 if (clm) {
488 clm->MaxCLL = cll->max_cll;
489 clm->MaxFALL = cll->max_fall;
490 }
491 }
492 break;
493 24 default:
494 // Ignore other types of metadata.
495 24 break;
496 }
497 }
498
499 12 return 0;
500 }
501
502 24 static int apv_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
503 {
504 24 APVDecodeContext *apv = avctx->priv_data;
505 24 CodedBitstreamFragment *au = &apv->au;
506 int i, err;
507
508
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for (i = apv->nb_unit; i < au->nb_units; i++) {
509 24 CodedBitstreamUnit *pbu = &au->units[i];
510
511
2/5
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 switch (pbu->type) {
512 12 case APV_PBU_PRIMARY_FRAME:
513 12 err = apv_decode(avctx, frame, pbu->content);
514 12 i++;
515 12 goto end;
516 12 case APV_PBU_METADATA:
517 12 apv_decode_metadata(avctx, frame, pbu->content);
518 12 break;
519 case APV_PBU_NON_PRIMARY_FRAME:
520 case APV_PBU_PREVIEW_FRAME:
521 case APV_PBU_DEPTH_FRAME:
522 case APV_PBU_ALPHA_FRAME:
523 if (!avctx->internal->is_copy &&
524 !apv->warned_additional_frames) {
525 av_log(avctx, AV_LOG_WARNING,
526 "Stream contains additional non-primary frames "
527 "which will be ignored by the decoder.\n");
528 apv->warned_additional_frames = 1;
529 }
530 break;
531 case APV_PBU_ACCESS_UNIT_INFORMATION:
532 case APV_PBU_FILLER:
533 // Not relevant to the decoder.
534 break;
535 default:
536 if (!avctx->internal->is_copy &&
537 !apv->warned_unknown_pbu_types) {
538 av_log(avctx, AV_LOG_WARNING,
539 "Stream contains PBUs with unknown types "
540 "which will be ignored by the decoder.\n");
541 apv->warned_unknown_pbu_types = 1;
542 }
543 break;
544 }
545 }
546
547 12 err = AVERROR(EAGAIN);
548 24 end:
549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 av_assert0(i <= apv->au.nb_units);
550 24 apv->nb_unit = i;
551
552
5/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 12 times.
24 if ((err < 0 && err != AVERROR(EAGAIN)) || apv->au.nb_units == i) {
553 12 av_packet_unref(apv->pkt);
554 12 ff_cbs_fragment_reset(&apv->au);
555 12 apv->nb_unit = 0;
556 }
557
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
24 if (!err && !frame->buf[0])
558 6 err = AVERROR(EAGAIN);
559
560 24 return err;
561 }
562
563 26 static int apv_receive_frame(AVCodecContext *avctx, AVFrame *frame)
564 {
565 26 APVDecodeContext *apv = avctx->priv_data;
566 int err;
567
568 do {
569
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 12 times.
44 if (!apv->au.nb_units) {
570 32 err = ff_decode_get_packet(avctx, apv->pkt);
571
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 12 times.
32 if (err < 0)
572 20 return err;
573
574 12 err = ff_cbs_read_packet(apv->cbc, &apv->au, apv->pkt);
575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (err < 0) {
576 ff_cbs_fragment_reset(&apv->au);
577 av_packet_unref(apv->pkt);
578 av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n");
579 return err;
580 }
581
582 12 apv->nb_unit = 0;
583 12 av_log(avctx, AV_LOG_DEBUG, "Total PBUs on this packet: %d.\n",
584 apv->au.nb_units);
585 }
586
587 24 err = apv_receive_frame_internal(avctx, frame);
588
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
24 } while (err == AVERROR(EAGAIN));
589
590 6 return err;
591 }
592
593 #if HAVE_THREADS
594 static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
595 {
596 APVDecodeContext *asrc = src->priv_data;
597 APVDecodeContext *adst = dst->priv_data;
598
599 adst->pix_fmt = asrc->pix_fmt;
600
601 return 0;
602 }
603 #endif
604
605 const FFCodec ff_apv_decoder = {
606 .p.name = "apv",
607 CODEC_LONG_NAME("Advanced Professional Video"),
608 .p.type = AVMEDIA_TYPE_VIDEO,
609 .p.id = AV_CODEC_ID_APV,
610 .priv_data_size = sizeof(APVDecodeContext),
611 .init = apv_decode_init,
612 .flush = apv_decode_flush,
613 .close = apv_decode_close,
614 FF_CODEC_RECEIVE_FRAME_CB(apv_receive_frame),
615 UPDATE_THREAD_CONTEXT(update_thread_context),
616 .p.capabilities = AV_CODEC_CAP_DR1 |
617 AV_CODEC_CAP_SLICE_THREADS |
618 AV_CODEC_CAP_FRAME_THREADS,
619 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
620 .hw_configs = (const AVCodecHWConfigInternal *const []) {
621 #if CONFIG_APV_VULKAN_HWACCEL
622 HWACCEL_VULKAN(apv),
623 #endif
624 NULL
625 },
626 };
627