FFmpeg
Loading...
Searching...
No Matches
refs.c
Go to the documentation of this file.
1/*
2 * VVC reference management
3 *
4 * Copyright (C) 2023 Nuo Mi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <stdatomic.h>
24#include <stdbool.h>
25
26#include "libavutil/mem.h"
27#include "libavutil/thread.h"
28#include "libavutil/refstruct.h"
29#include "libavcodec/thread.h"
30#include "libavcodec/decode.h"
31
32#include "refs.h"
33
34
43
45{
46 /* frame->frame can be NULL if context init failed */
47 if (!frame->frame || !frame->frame->buf[0])
48 return;
49
50 frame->flags &= ~flags;
51 if (!(frame->flags & ~VVC_FRAME_FLAG_CORRUPT))
52 frame->flags = 0;
53 if (!frame->flags) {
54 av_refstruct_unref(&frame->hwaccel_picture_private);
55 av_frame_unref(frame->frame);
56
57 if (frame->needs_fg) {
58 av_frame_unref(frame->frame_grain);
59 frame->needs_fg = 0;
60 }
61
64 av_refstruct_unref(&frame->progress);
65
66 av_refstruct_unref(&frame->tab_dmvr_mvf);
67
69 frame->nb_rpl_elems = 0;
70 av_refstruct_unref(&frame->rpl_tab);
71
72 frame->collocated_ref = NULL;
73 }
74}
75
76const RefPicList *ff_vvc_get_ref_list(const VVCFrameContext *fc, const VVCFrame *ref, int x0, int y0)
77{
78 const int x_cb = x0 >> fc->ps.sps->ctb_log2_size_y;
79 const int y_cb = y0 >> fc->ps.sps->ctb_log2_size_y;
80 const int pic_width_cb = fc->ps.pps->ctb_width;
81 const int ctb_addr_rs = y_cb * pic_width_cb + x_cb;
82
83 return (const RefPicList *)ref->rpl_tab[ctb_addr_rs];
84}
85
92
94{
95 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++)
96 ff_vvc_unref_frame(fc, &fc->DPB[i], ~0);
97}
98
99static void free_progress(AVRefStructOpaque unused, void *obj)
100{
102
103 if (p->has_cond)
104 ff_cond_destroy(&p->cond);
105 if (p->has_lock)
106 ff_mutex_destroy(&p->lock);
107}
108
110{
112
113 if (p) {
114 p->has_lock = !ff_mutex_init(&p->lock, NULL);
115 p->has_cond = !ff_cond_init(&p->cond, NULL);
116 if (!p->has_lock || !p->has_cond)
118 }
119 return p;
120}
121
123{
124 const VVCSPS *sps = fc->ps.sps;
125 const VVCPPS *pps = fc->ps.pps;
126 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
127 int ret;
128 VVCFrame *frame = &fc->DPB[i];
129 VVCWindow *win = &frame->scaling_win;
130 if (frame->frame->buf[0])
131 continue;
132
133 // Add LCEVC SEI metadata here, as it's needed in get_buffer()
134 if (fc->sei.common.itut_t35.lcevc) {
136 AV_FRAME_DATA_LCEVC, &fc->sei.common.itut_t35.lcevc);
137 if (ret < 0)
138 goto fail;
139 }
140
142 if (ret < 0)
143 return NULL;
144
145 frame->sps = av_refstruct_ref_c(fc->ps.sps);
146 frame->pps = av_refstruct_ref_c(fc->ps.pps);
147
148 size_t rpl_size;
149 if (av_size_mult(s->current_frame.nb_units, sizeof(RefPicListTab), &rpl_size) < 0)
150 goto fail;
151 frame->rpl = av_refstruct_allocz(rpl_size);
152 if (!frame->rpl)
153 goto fail;
154 frame->nb_rpl_elems = s->current_frame.nb_units;
155
156 frame->tab_dmvr_mvf = av_refstruct_pool_get(fc->tab_dmvr_mvf_pool);
157 if (!frame->tab_dmvr_mvf)
158 goto fail;
159
160 frame->rpl_tab = av_refstruct_pool_get(fc->rpl_tab_pool);
161 if (!frame->rpl_tab)
162 goto fail;
163 frame->ctb_count = pps->ctb_width * pps->ctb_height;
164 for (int j = 0; j < frame->ctb_count; j++)
165 frame->rpl_tab[j] = frame->rpl;
166
167 win->left_offset = pps->r->pps_scaling_win_left_offset * (1 << sps->hshift[CHROMA]);
168 win->right_offset = pps->r->pps_scaling_win_right_offset * (1 << sps->hshift[CHROMA]);
169 win->top_offset = pps->r->pps_scaling_win_top_offset * (1 << sps->vshift[CHROMA]);
170 win->bottom_offset = pps->r->pps_scaling_win_bottom_offset * (1 << sps->vshift[CHROMA]);
171 frame->ref_width = pps->r->pps_pic_width_in_luma_samples - win->left_offset - win->right_offset;
172 frame->ref_height = pps->r->pps_pic_height_in_luma_samples - win->bottom_offset - win->top_offset;
173
174 if (fc->sei.frame_field_info.present) {
175 if (fc->sei.frame_field_info.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD)
176 frame->frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
177 if (fc->sei.frame_field_info.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD ||
178 fc->sei.frame_field_info.picture_struct == AV_PICTURE_STRUCTURE_BOTTOM_FIELD)
179 frame->frame->flags |= AV_FRAME_FLAG_INTERLACED;
180 }
181
182 frame->progress = alloc_progress();
183 if (!frame->progress)
184 goto fail;
185
186 ret = ff_hwaccel_frame_priv_alloc(s->avctx, &frame->hwaccel_picture_private);
187 if (ret < 0)
188 goto fail;
189
190 return frame;
191fail:
193 return NULL;
194 }
195 av_log(s->avctx, AV_LOG_ERROR, "Error allocating frame, DPB full.\n");
196 return NULL;
197}
198
200{
201 bool has_b = false, has_inter = false;
202
203 if (IS_IRAP(s)) {
204 frame->pict_type = AV_PICTURE_TYPE_I;
205 frame->flags |= AV_FRAME_FLAG_KEY;
206 return;
207 }
208
209 if (fc->ps.ph.r->ph_inter_slice_allowed_flag) {
210 // At this point, fc->slices is not fully initialized; we need to inspect the CBS directly.
211 const CodedBitstreamFragment *current = &s->current_frame;
212 for (int i = 0; i < current->nb_units && !has_b; i++) {
213 const CodedBitstreamUnit *unit = current->units + i;
214 if (unit->content_ref && unit->type <= VVC_RSV_IRAP_11) {
215 const H266RawSliceHeader *rsh = unit->content_ref;
216 has_inter |= !IS_I(rsh);
217 has_b |= IS_B(rsh);
218 }
219 }
220 }
221 if (!has_inter)
222 frame->pict_type = AV_PICTURE_TYPE_I;
223 else if (has_b)
224 frame->pict_type = AV_PICTURE_TYPE_B;
225 else
226 frame->pict_type = AV_PICTURE_TYPE_P;
227}
228
230{
231 const VVCPH *ph= &fc->ps.ph;
232 const int poc = ph->poc;
233 VVCFrame *ref;
234
235 /* check that this POC doesn't already exist */
236 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
237 VVCFrame *frame = &fc->DPB[i];
238
239 if (frame->frame->buf[0] && frame->sequence == s->seq_decode &&
240 frame->poc == poc) {
241 av_log(s->avctx, AV_LOG_ERROR, "Duplicate POC in a sequence: %d.\n", poc);
242 return AVERROR_INVALIDDATA;
243 }
244 }
245
246 ref = alloc_frame(s, fc);
247 if (!ref)
248 return AVERROR(ENOMEM);
249
250 set_pict_type(ref->frame, s, fc);
251 *frame = ref->frame;
252 fc->ref = ref;
253
254 if (s->no_output_before_recovery_flag && (IS_RASL(s) || !GDR_IS_RECOVERED(s)))
256 else if (ph->r->ph_pic_output_flag)
258
259 if (!ph->r->ph_non_ref_pic_flag)
261
262 ref->poc = poc;
263 ref->sequence = s->seq_decode;
264 ref->frame->crop_left = fc->ps.pps->r->pps_conf_win_left_offset << fc->ps.sps->hshift[CHROMA];
265 ref->frame->crop_right = fc->ps.pps->r->pps_conf_win_right_offset << fc->ps.sps->hshift[CHROMA];
266 ref->frame->crop_top = fc->ps.pps->r->pps_conf_win_top_offset << fc->ps.sps->vshift[CHROMA];
267 ref->frame->crop_bottom = fc->ps.pps->r->pps_conf_win_bottom_offset << fc->ps.sps->vshift[CHROMA];
268
269 return 0;
270}
271
272int ff_vvc_output_frame(VVCContext *s, VVCFrameContext *fc, AVFrame *out, const int no_output_of_prior_pics_flag, int flush)
273{
274 const VVCSPS *sps = fc->ps.sps;
275 do {
276 int nb_output = 0;
277 int min_poc = INT_MAX;
278 int min_idx, ret;
279
280 if (no_output_of_prior_pics_flag) {
281 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
282 VVCFrame *frame = &fc->DPB[i];
283 if (!(frame->flags & VVC_FRAME_FLAG_BUMPING) && frame->poc != fc->ps.ph.poc &&
284 frame->sequence == s->seq_output) {
286 }
287 }
288 }
289
290 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
291 VVCFrame *frame = &fc->DPB[i];
292 if ((frame->flags & VVC_FRAME_FLAG_OUTPUT) &&
293 frame->sequence == s->seq_output) {
294 nb_output++;
295 if (frame->poc < min_poc || nb_output == 1) {
296 min_poc = frame->poc;
297 min_idx = i;
298 }
299 }
300 }
301
302 /* wait for more frames before output */
303 if (!flush && s->seq_output == s->seq_decode && sps &&
304 nb_output <= sps->r->sps_dpb_params.dpb_max_num_reorder_pics[sps->r->sps_max_sublayers_minus1])
305 return 0;
306
307 if (nb_output) {
308 VVCFrame *frame = &fc->DPB[min_idx];
309
310 if (frame->flags & VVC_FRAME_FLAG_CORRUPT)
311 frame->frame->flags |= AV_FRAME_FLAG_CORRUPT;
312
313 ret = av_frame_ref(out, frame->needs_fg ? frame->frame_grain : frame->frame);
314
315 if (!ret && !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))
317
318 if (frame->flags & VVC_FRAME_FLAG_BUMPING)
320 else
322
323 if (ret < 0)
324 return ret;
325
326 av_log(s->avctx, AV_LOG_DEBUG,
327 "Output frame with POC %d.\n", frame->poc);
328 return 1;
329 }
330
331 if (s->seq_output != s->seq_decode)
332 s->seq_output = (s->seq_output + 1) & 0xff;
333 else
334 break;
335 } while (1);
336 return 0;
337}
338
340{
341 const VVCSPS *sps = fc->ps.sps;
342 const int poc = fc->ps.ph.poc;
343 int dpb = 0;
344 int min_poc = INT_MAX;
345
346 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
347 VVCFrame *frame = &fc->DPB[i];
348 if ((frame->flags) &&
349 frame->sequence == s->seq_output &&
350 frame->poc != poc) {
351 dpb++;
352 }
353 }
354
355 if (sps && dpb >= sps->r->sps_dpb_params.dpb_max_dec_pic_buffering_minus1[sps->r->sps_max_sublayers_minus1] + 1) {
356 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
357 VVCFrame *frame = &fc->DPB[i];
358 if ((frame->flags) &&
359 frame->sequence == s->seq_output &&
360 frame->poc != poc) {
361 if (frame->flags == VVC_FRAME_FLAG_OUTPUT && frame->poc < min_poc) {
362 min_poc = frame->poc;
363 }
364 }
365 }
366
367 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
368 VVCFrame *frame = &fc->DPB[i];
369 if (frame->flags & VVC_FRAME_FLAG_OUTPUT &&
370 frame->sequence == s->seq_output &&
371 frame->poc <= min_poc) {
373 }
374 }
375
376 dpb--;
377 }
378}
379
380static VVCFrame *find_ref_idx(VVCContext *s, VVCFrameContext *fc, int poc, uint8_t use_msb)
381{
382 const unsigned mask = use_msb ? ~0 : fc->ps.sps->max_pic_order_cnt_lsb - 1;
383
384 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
385 VVCFrame *ref = &fc->DPB[i];
386
387 // In the specification, the current frame is not considered part of
388 // the DPB at this stage, therefore we treat it as if it's not there.
389 if (ref == fc->ref)
390 continue;
391
392 if (ref->frame->buf[0] && ref->sequence == s->seq_decode) {
393 if ((ref->poc & mask) == poc)
394 return ref;
395 }
396 }
397 return NULL;
398}
399
400static void mark_ref(VVCFrame *frame, int flag)
401{
403 frame->flags |= flag;
404}
405
407{
408 const VVCSPS *sps = fc->ps.sps;
409 const VVCPPS *pps = fc->ps.pps;
411
412 frame = alloc_frame(s, fc);
413 if (!frame)
414 return NULL;
415
416 if (!s->avctx->hwaccel) {
417 if (!sps->pixel_shift) {
418 for (int i = 0; frame->frame->buf[i]; i++)
419 memset(frame->frame->buf[i]->data, 1 << (sps->bit_depth - 1),
420 frame->frame->buf[i]->size);
421 } else {
422 for (int i = 0; frame->frame->data[i]; i++)
423 for (int y = 0; y < (pps->height >> sps->vshift[i]); y++) {
424 uint8_t *dst = frame->frame->data[i] + y * frame->frame->linesize[i];
425 AV_WN16(dst, 1 << (sps->bit_depth - 1));
426 av_memcpy_backptr(dst + 2, 2, 2*(pps->width >> sps->hshift[i]) - 2);
427 }
428 }
429 }
430
431 frame->poc = poc;
432 frame->sequence = s->seq_decode;
434
436
437 return frame;
438}
439
440#define CHECK_MAX(d) (frame->ref_##d * frame->sps->r->sps_pic_##d##_max_in_luma_samples >= ref->ref_##d * (frame->pps->r->pps_pic_##d##_in_luma_samples - max))
441#define CHECK_SAMPLES(d) (frame->pps->r->pps_pic_##d##_in_luma_samples == ref->pps->r->pps_pic_##d##_in_luma_samples)
442static int check_candidate_ref(const VVCFrame *frame, const VVCRefPic *refp)
443{
444 const VVCFrame *ref = refp->ref;
445
446 if (refp->is_scaled) {
447 const int max = FFMAX(8, frame->sps->min_cb_size_y);
448 return frame->ref_width * 2 >= ref->ref_width &&
449 frame->ref_height * 2 >= ref->ref_height &&
450 frame->ref_width <= ref->ref_width * 8 &&
451 frame->ref_height <= ref->ref_height * 8 &&
453 }
455}
456
457#define RPR_SCALE(f) (((ref->f << 14) + (fc->ref->f >> 1)) / fc->ref->f)
458/* add a reference with the given poc to the list and mark it as used in DPB */
460 int poc, int ref_flag, uint8_t use_msb)
461{
462 VVCRefPic *refp = &list->refs[list->nb_refs];
463 VVCFrame *ref;
464
465 if (use_msb && poc == fc->ref->poc || list->nb_refs >= VVC_MAX_REF_ENTRIES)
466 return AVERROR_INVALIDDATA;
467
468 ref = find_ref_idx(s, fc, poc, use_msb);
469
470 if (!IS_CVSS(s)) {
471 const bool ref_corrupt = !ref || (ref->flags & VVC_FRAME_FLAG_CORRUPT);
472 const bool recovering = s->no_output_before_recovery_flag &&
473 (IS_RASL(s) || !GDR_IS_RECOVERED(s));
474
475 if (ref_corrupt && !recovering) {
476 if (!(s->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) &&
477 !(s->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL))
478 return AVERROR_INVALIDDATA;
479
480 fc->ref->flags |= VVC_FRAME_FLAG_CORRUPT;
481 }
482 }
483
484 if (!ref) {
485 ref = generate_missing_ref(s, fc, poc);
486 if (!ref)
487 return AVERROR(ENOMEM);
488 }
489
490 refp->poc = poc;
491 refp->ref = ref;
492 refp->is_lt = ref_flag & VVC_FRAME_FLAG_LONG_REF;
493 refp->is_scaled = ref->sps->r->sps_num_subpics_minus1 != fc->ref->sps->r->sps_num_subpics_minus1||
494 memcmp(&ref->scaling_win, &fc->ref->scaling_win, sizeof(ref->scaling_win)) ||
495 ref->pps->r->pps_pic_width_in_luma_samples != fc->ref->pps->r->pps_pic_width_in_luma_samples ||
496 ref->pps->r->pps_pic_height_in_luma_samples != fc->ref->pps->r->pps_pic_height_in_luma_samples;
497
498 if (!check_candidate_ref(fc->ref, refp))
499 return AVERROR_INVALIDDATA;
500
501 if (refp->is_scaled) {
502 refp->scale[0] = RPR_SCALE(ref_width);
503 refp->scale[1] = RPR_SCALE(ref_height);
504 }
505 list->nb_refs++;
506
507 mark_ref(ref, ref_flag);
508 return 0;
509}
510
512{
513 VVCFrame *frame = fc->ref;
514 const VVCSH *sh = &sc->sh;
515
516 if (sc->slice_idx >= frame->nb_rpl_elems)
517 return AVERROR_INVALIDDATA;
518
519 for (int i = 0; i < sh->num_ctus_in_curr_slice; i++) {
520 const int rs = sh->ctb_addr_in_curr_slice[i];
521 frame->rpl_tab[rs] = frame->rpl + sc->slice_idx;
522 }
523
524 sc->rpl = frame->rpl_tab[sh->ctb_addr_in_curr_slice[0]]->refPicList;
525
526 return 0;
527}
528
529static int delta_poc_st(const H266RefPicListStruct *rpls,
530 const int lx, const int i, const VVCSPS *sps)
531{
532 int abs_delta_poc_st = rpls->abs_delta_poc_st[i];
533 if (!((sps->r->sps_weighted_pred_flag ||
534 sps->r->sps_weighted_bipred_flag) && i != 0))
535 abs_delta_poc_st++;
536 return (1 - 2 * rpls->strp_entry_sign_flag[i]) * abs_delta_poc_st;
537}
538
539static int poc_lt(int *prev_delta_poc_msb, const int poc, const H266RefPicLists *ref_lists,
540 const int lx, const int j, const int max_poc_lsb)
541{
542 const H266RefPicListStruct *rpls = ref_lists->rpl_ref_list + lx;
543 int lt_poc = rpls->ltrp_in_header_flag ? ref_lists->poc_lsb_lt[lx][j] : rpls->rpls_poc_lsb_lt[j];
544
545 if (ref_lists->delta_poc_msb_cycle_present_flag[lx][j]) {
546 const uint32_t delta = ref_lists->delta_poc_msb_cycle_lt[lx][j] + *prev_delta_poc_msb;
547 lt_poc += poc - delta * max_poc_lsb - (poc & (max_poc_lsb - 1));
548 *prev_delta_poc_msb = delta;
549 }
550 return lt_poc;
551}
552
554{
555 const VVCSPS *sps = fc->ps.sps;
556 const H266RawPPS *pps = fc->ps.pps->r;
557 const VVCPH *ph = &fc->ps.ph;
558 const H266RawSliceHeader *rsh = sc->sh.r;
559 const int max_poc_lsb = sps->max_pic_order_cnt_lsb;
560 const H266RefPicLists *ref_lists =
561 pps->pps_rpl_info_in_ph_flag ? &ph->r->ph_ref_pic_lists : &rsh->sh_ref_pic_lists;
562 int ret = 0;
563
564 ret = init_slice_rpl(fc, sc);
565 if (ret < 0)
566 return ret;
567
568 for (int lx = L0; lx <= L1; lx++) {
569 const H266RefPicListStruct *rpls = ref_lists->rpl_ref_list + lx;
570 RefPicList *rpl = sc->rpl + lx;
571 int poc_base = ph->poc;
572 int prev_delta_poc_msb = 0;
573
574 rpl->nb_refs = 0;
575 for (int i = 0, j = 0; i < rpls->num_ref_entries; i++) {
576 int poc;
577 if (!rpls->inter_layer_ref_pic_flag[i]) {
578 int use_msb = 1;
579 int ref_flag;
580 if (rpls->st_ref_pic_flag[i]) {
581 poc = poc_base + delta_poc_st(rpls, lx, i, sps);
582 poc_base = poc;
583 ref_flag = VVC_FRAME_FLAG_SHORT_REF;
584 } else {
585 use_msb = ref_lists->delta_poc_msb_cycle_present_flag[lx][j];
586 poc = poc_lt(&prev_delta_poc_msb, ph->poc, ref_lists, lx, j, max_poc_lsb);
587 ref_flag = VVC_FRAME_FLAG_LONG_REF;
588 j++;
589 }
590 ret = add_candidate_ref(s, fc, rpl, poc, ref_flag, use_msb);
591 if (ret < 0)
592 return ret;
593 } else {
594 // OPI_B_3.bit and VPS_A_3.bit should cover this
595 avpriv_report_missing_feature(fc->log_ctx, "Inter layer ref");
597 return ret;
598 }
599 }
600 if (rsh->num_ref_idx_active[lx] > rpl->nb_refs)
601 return AVERROR_INVALIDDATA;
602 if (ph->r->ph_temporal_mvp_enabled_flag &&
603 (!rsh->sh_collocated_from_l0_flag) == lx &&
604 rsh->sh_collocated_ref_idx < rpl->nb_refs) {
605 const VVCRefPic *refp = rpl->refs + rsh->sh_collocated_ref_idx;
606 if (refp->is_scaled || refp->ref->sps->ctb_log2_size_y != sps->ctb_log2_size_y)
607 return AVERROR_INVALIDDATA;
608 fc->ref->collocated_ref = refp->ref;
609 }
610 }
611 return 0;
612}
613
615{
616 int ret = 0;
617
618 /* clear the reference flags on all frames except the current one */
619 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
620 VVCFrame *frame = &fc->DPB[i];
621
622 if (frame == fc->ref)
623 continue;
624
625 mark_ref(frame, 0);
626 }
627
628 if ((ret = ff_vvc_slice_rpl(s, fc, sc)) < 0)
629 goto fail;
630
631fail:
632 /* release any frames that are now unused */
633 for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++)
634 ff_vvc_unref_frame(fc, &fc->DPB[i], 0);
635 return ret;
636}
637
643
645{
646 return p->progress[l->vp] > l->y;
647}
648
650{
651 l->next = *prev;
652 *prev = l;
653}
654
656{
657 *prev = l->next;
658 l->next = NULL;
659 return l;
660}
661
663{
665 VVCProgressListener **prev = &p->listener[vp];
666
667 while (*prev) {
668 if (is_progress_done(p, *prev)) {
669 VVCProgressListener *l = remove_listener(prev, *prev);
670 add_listener(&list, l);
671 } else {
672 prev = &(*prev)->next;
673 }
674 }
675 return list;
676}
677
679{
680 FrameProgress *p = frame->progress;
682
683 ff_mutex_lock(&p->lock);
684 if (p->progress[vp] < y) {
685 // Due to the nature of thread scheduling, later progress may reach this point before earlier progress.
686 // Therefore, we only update the progress when p->progress[vp] < y.
687 p->progress[vp] = y;
688 l = get_done_listener(p, vp);
689 ff_cond_signal(&p->cond);
690 }
691 ff_mutex_unlock(&p->lock);
692
693 while (l) {
694 l->progress_done(l);
695 l = l->next;
696 }
697}
698
700{
701 FrameProgress *p = frame->progress;
702
703 ff_mutex_lock(&p->lock);
704
705 if (is_progress_done(p, l)) {
706 ff_mutex_unlock(&p->lock);
707 l->progress_done(l);
708 } else {
709 add_listener(p->listener + l->vp, l);
710 ff_mutex_unlock(&p->lock);
711 }
712}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static float win(SuperEqualizerContext *s, float n, int N)
static FILE * out
#define flag(name)
Definition cbs_h264.c:60
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
#define max(a, b)
static const uint16_t fc[]
Definition dcaenc.h:43
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
Definition decode.c:2269
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
Definition decode.c:2383
static AVFrame * frame
uint64_t pps
Definition dovi_rpuenc.c:36
void(* flush)(AVBSFContext *ctx)
Definition dts2pts.c:615
static struct @111144215057303131116103221376075045141373005341 current
int ret
Definition ffplay.c:391
static ListView * list
Definition ffplay.c:377
#define fail
Definition test.h:479
#define AV_CODEC_FLAG2_SHOW_ALL
Show all frames before the first keyframe.
Definition avcodec.h:364
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition avcodec.h:415
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
Definition avcodec.h:404
#define AV_CODEC_FLAG_OUTPUT_CORRUPT
Output even those frames that might be corrupted.
Definition avcodec.h:221
@ AV_PICTURE_STRUCTURE_BOTTOM_FIELD
coded as bottom field
Definition avcodec.h:2634
@ AV_PICTURE_STRUCTURE_TOP_FIELD
coded as top field
Definition avcodec.h:2633
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition frame.h:702
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition frame.h:707
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition frame.h:690
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition frame.h:694
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:499
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition frame.c:728
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition frame.c:281
@ AV_FRAME_DATA_LCEVC
Raw LCEVC payload data, as a uint8_t array, with NAL emulation bytes intact.
Definition frame.h:236
@ AV_FRAME_DATA_FILM_GRAIN_PARAMS
Film grain parameters for a frame, described by AVFilmGrainParams.
Definition frame.h:188
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
Definition mem.c:551
int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
Definition mem.c:671
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition avutil.h:280
#define CHROMA(h)
Definition h264dec.h:88
static HEVCFrame * find_ref_idx(HEVCContext *s, HEVCLayerContext *l, int poc, uint8_t use_msb)
Definition refs.c:439
static int add_candidate_ref(HEVCContext *s, HEVCLayerContext *l, RefPicList *rps, int list_idx, int poc, int ref_flag, uint8_t use_msb)
Definition refs.c:499
static void mark_ref(HEVCFrame *frame, int flag)
Definition refs.c:459
static HEVCFrame * alloc_frame(HEVCContext *s, HEVCLayerContext *l)
Definition refs.c:110
static int init_slice_rpl(HEVCContext *s)
Definition refs.c:327
static HEVCFrame * generate_missing_ref(HEVCContext *s, HEVCLayerContext *l, int poc)
Definition refs.c:465
#define L1
Definition hevcdec.h:57
#define L0
Definition hevcdec.h:56
#define IS_IRAP(s)
Definition hevcdec.h:78
#define r
Definition input.c:42
#define AV_WN16(p, v)
Multithreading API for decoders.
@ VVC_MAX_REF_ENTRIES
Definition vvc.h:115
@ VVC_RSV_IRAP_11
Definition vvc.h:40
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int ff_mutex_unlock(AVMutex *mutex)
Definition thread.h:189
static int ff_cond_destroy(AVCond *cond)
Definition thread.h:195
static int ff_mutex_lock(AVMutex *mutex)
Definition thread.h:188
static int ff_mutex_destroy(AVMutex *mutex)
Definition thread.h:190
static int ff_cond_init(AVCond *cond, const void *attr)
Definition thread.h:194
#define AVCond
Definition thread.h:192
static int ff_cond_signal(AVCond *cond)
Definition thread.h:196
#define AVMutex
Definition thread.h:184
static int ff_mutex_init(AVMutex *mutex, const void *attr)
Definition thread.h:187
static const uint16_t mask[17]
Definition lzw.c:38
#define FFMAX(a, b)
Definition macros.h:47
Memory handling functions.
static const char * obj
Definition mscl.c:57
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
#define VVC_FRAME_FLAG_OUTPUT
Definition refs.h:28
#define VVC_FRAME_FLAG_BUMPING
Definition refs.h:31
#define VVC_FRAME_FLAG_SHORT_REF
Definition refs.h:29
VVCProgress
Definition refs.h:44
@ VVC_PROGRESS_PIXEL
Definition refs.h:46
@ VVC_PROGRESS_MV
Definition refs.h:45
@ VVC_PROGRESS_LAST
Definition refs.h:47
#define VVC_FRAME_FLAG_CORRUPT
Definition refs.h:32
#define VVC_FRAME_FLAG_LONG_REF
Definition refs.h:30
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:121
const void * av_refstruct_ref_c(const void *obj)
Analog of av_refstruct_ref(), but for constant objects.
Definition refstruct.c:150
void * av_refstruct_pool_get(AVRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
Definition refstruct.c:315
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition refstruct.h:105
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition refstruct.h:94
#define FF_ARRAY_ELEMS(a)
int atomic_int
Definition stdatomic.h:63
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
Coded bitstream unit structure.
Definition cbs.h:77
void * content_ref
If content is reference counted, a RefStruct reference backing content.
Definition cbs.h:119
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition cbs.h:81
AVCond cond
Definition refs.c:39
atomic_int progress[VVC_PROGRESS_LAST]
Definition refs.c:36
uint8_t has_cond
Definition refs.c:41
AVMutex lock
Definition refs.c:38
VVCProgressListener * listener[VVC_PROGRESS_LAST]
Definition refs.c:37
uint8_t has_lock
Definition refs.c:40
uint8_t num_ref_idx_active[2]
NumRefIdxActive[].
Definition cbs_h266.h:840
uint8_t sh_collocated_ref_idx
Definition cbs_h266.h:804
uint8_t sh_collocated_from_l0_flag
Definition cbs_h266.h:803
H266RefPicLists sh_ref_pic_lists
Definition cbs_h266.h:798
uint8_t abs_delta_poc_st[VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:165
uint8_t strp_entry_sign_flag[VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:166
uint8_t num_ref_entries
Definition cbs_h266.h:161
uint8_t inter_layer_ref_pic_flag[VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:163
uint8_t rpls_poc_lsb_lt[VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:167
uint8_t st_ref_pic_flag[VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:164
uint8_t ltrp_in_header_flag
Definition cbs_h266.h:162
uint8_t delta_poc_msb_cycle_present_flag[2][VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:176
uint16_t delta_poc_msb_cycle_lt[2][VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:177
H266RefPicListStruct rpl_ref_list[2]
Definition cbs_h266.h:174
uint16_t poc_lsb_lt[2][VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:175
VVCRefPic refs[VVC_MAX_REF_ENTRIES]
Definition dec.h:58
int nb_refs
Definition hevcdec.h:199
VVCSH sh
Definition dec.h:115
int slice_idx
Definition dec.h:114
RefPicList * rpl
Definition dec.h:118
Definition dec.h:73
const VVCSPS * sps
RefStruct reference.
Definition dec.h:76
Definition ps.h:147
Definition ps.h:92
VVCProgressListener * next
Definition refs.h:57
progress_done_fn progress_done
Definition refs.h:56
VVCProgress vp
Definition refs.h:54
int scale[2]
RefPicScale[].
Definition dec.h:54
int is_lt
Definition dec.h:50
int poc
Definition dec.h:49
int is_scaled
RprConstraintsActiveFlag.
Definition dec.h:53
struct VVCFrame * ref
Definition dec.h:48
Definition ps.h:238
const H266RawSliceHeader * r
RefStruct reference.
Definition ps.h:239
const uint32_t * ctb_addr_in_curr_slice
CtbAddrInCurrSlice.
Definition ps.h:244
uint32_t num_ctus_in_curr_slice
NumCtusInCurrSlice.
Definition ps.h:243
Definition ps.h:58
uint8_t ctb_log2_size_y
CtbLog2SizeY.
Definition ps.h:71
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition refstruct.h:58
float delta
#define IS_CVSS(s)
Definition ps.h:33
#define GDR_IS_RECOVERED(s)
Definition ps.h:43
#define IS_RASL(s)
Definition ps.h:35
#define IS_I(rsh)
Definition ps.h:38
#define IS_B(rsh)
Definition ps.h:40
#define CHECK_MAX(d)
Definition refs.c:440
#define RPR_SCALE(f)
Definition refs.c:457
void ff_vvc_add_progress_listener(VVCFrame *frame, VVCProgressListener *l)
Definition refs.c:699
void ff_vvc_clear_refs(VVCFrameContext *fc)
Definition refs.c:86
static FrameProgress * alloc_progress(void)
Definition refs.c:109
const RefPicList * ff_vvc_get_ref_list(const VVCFrameContext *fc, const VVCFrame *ref, int x0, int y0)
Definition refs.c:76
int ff_vvc_frame_rpl(VVCContext *s, VVCFrameContext *fc, SliceContext *sc)
Definition refs.c:614
void ff_vvc_unref_frame(VVCFrameContext *fc, VVCFrame *frame, int flags)
Definition refs.c:44
void ff_vvc_bump_frame(VVCContext *s, VVCFrameContext *fc)
Definition refs.c:339
void ff_vvc_report_frame_finished(VVCFrame *frame)
Definition refs.c:638
void ff_vvc_report_progress(VVCFrame *frame, const VVCProgress vp, const int y)
Definition refs.c:678
static void free_progress(AVRefStructOpaque unused, void *obj)
Definition refs.c:99
int ff_vvc_output_frame(VVCContext *s, VVCFrameContext *fc, AVFrame *out, const int no_output_of_prior_pics_flag, int flush)
Definition refs.c:272
int ff_vvc_slice_rpl(VVCContext *s, VVCFrameContext *fc, SliceContext *sc)
Definition refs.c:553
static VVCProgressListener * get_done_listener(FrameProgress *p, const VVCProgress vp)
Definition refs.c:662
int ff_vvc_set_new_ref(VVCContext *s, VVCFrameContext *fc, AVFrame **frame)
Definition refs.c:229
static int check_candidate_ref(const VVCFrame *frame, const VVCRefPic *refp)
Definition refs.c:442
static void add_listener(VVCProgressListener **prev, VVCProgressListener *l)
Definition refs.c:649
void ff_vvc_flush_dpb(VVCFrameContext *fc)
Definition refs.c:93
static void set_pict_type(AVFrame *frame, const VVCContext *s, const VVCFrameContext *fc)
Definition refs.c:199
#define CHECK_SAMPLES(d)
Definition refs.c:441
static int delta_poc_st(const H266RefPicListStruct *rpls, const int lx, const int i, const VVCSPS *sps)
Definition refs.c:529
static VVCProgressListener * remove_listener(VVCProgressListener **prev, VVCProgressListener *l)
Definition refs.c:655
static int poc_lt(int *prev_delta_poc_msb, const int poc, const H266RefPicLists *ref_lists, const int lx, const int j, const int max_poc_lsb)
Definition refs.c:539
static int is_progress_done(const FrameProgress *p, const VVCProgressListener *l)
Definition refs.c:644