FFmpeg
Loading...
Searching...
No Matches
refs.c
Go to the documentation of this file.
1/*
2 * HEVC video decoder
3 *
4 * Copyright (C) 2012 - 2013 Guillaume Martres
5 * Copyright (C) 2012 - 2013 Gildas Cocherel
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
25#include "libavutil/mem.h"
26#include "libavutil/stereo3d.h"
27
28#include "libavcodec/decode.h"
29#include "hevc.h"
30#include "hevcdec.h"
32#include "libavcodec/thread.h"
33#include "libavutil/refstruct.h"
34
36{
37 frame->flags &= ~flags;
38 if (!(frame->flags & ~HEVC_FRAME_FLAG_CORRUPT))
39 frame->flags = 0;
40 if (!frame->flags) {
41 av_refstruct_unref(&frame->hwaccel_picture_private);
42
44 av_frame_unref(frame->frame_grain);
45 frame->needs_fg = 0;
46
48 av_refstruct_unref(&frame->tab_mvf);
49
51 frame->nb_rpl_elems = 0;
52 av_refstruct_unref(&frame->rpl_tab);
53 frame->refPicList = NULL;
54 }
55}
56
57const RefPicList *ff_hevc_get_ref_list(const HEVCFrame *ref, int x0, int y0)
58{
59 const HEVCSPS *sps = ref->pps->sps;
60 int x_cb = x0 >> sps->log2_ctb_size;
61 int y_cb = y0 >> sps->log2_ctb_size;
62 int pic_width_cb = sps->ctb_width;
63 int ctb_addr_ts = ref->pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb];
64 return &ref->rpl_tab[ctb_addr_ts]->refPicList[0];
65}
66
75
77{
78 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
79 HEVCLayerContext *l = &s->layers[layer];
80 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++)
81 ff_hevc_unref_frame(&l->DPB[i], ~0);
82 }
83}
84
86{
88 uintptr_t data = (uintptr_t)alpha->data[0];
89 int ret;
90
91 for (int i = 0; i < FF_ARRAY_ELEMS(alpha->buf) && alpha->buf[i]; i++) {
92 AVBufferRef *buf = alpha->buf[i];
93 uintptr_t buf_begin = (uintptr_t)buf->data;
94
95 if (data >= buf_begin && data < buf_begin + buf->size) {
96 ret = av_buffer_replace(&alpha->buf[i], base_a);
97 if (ret < 0)
98 return ret;
99
100 alpha->linesize[0] = base->linesize[3];
101 alpha->data[0] = base->data[3];
102
103 return 0;
104 }
105 }
106
107 return AVERROR_BUG;
108}
109
111{
112 const HEVCVPS *vps = l->sps->vps;
113 const int view_id = vps->view_id[s->cur_layer];
114 int i, j, ret;
115 for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
116 HEVCFrame *frame = &l->DPB[i];
117 if (frame->f)
118 continue;
119
120 ret = ff_progress_frame_alloc(s->avctx, &frame->tf);
121 if (ret < 0)
122 return NULL;
123
124 // Add LCEVC SEI metadata here, as it's needed in get_buffer()
125 if (s->sei.common.itut_t35.lcevc) {
126 ret = ff_frame_new_side_data_from_buf(s->avctx, frame->tf.f,
127 AV_FRAME_DATA_LCEVC, &s->sei.common.itut_t35.lcevc);
128 if (ret < 0)
129 goto fail;
130 }
131
132 // add view ID side data if it's nontrivial
133 if (!ff_hevc_is_alpha_video(s) && (vps->nb_layers > 1 || view_id)) {
134 HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
135 AVFrameSideData *sd = av_frame_side_data_new(&frame->f->side_data,
136 &frame->f->nb_side_data,
138 sizeof(int), 0);
139 if (!sd)
140 goto fail;
141 *(int*)sd->data = view_id;
142
143 if (tdrdi->num_ref_displays) {
144 AVStereo3D *stereo_3d;
145
146 stereo_3d = av_stereo3d_create_side_data(frame->f);
147 if (!stereo_3d)
148 goto fail;
149
150 stereo_3d->type = AV_STEREO3D_FRAMESEQUENCE;
151 if (tdrdi->left_view_id[0] == view_id)
152 stereo_3d->view = AV_STEREO3D_VIEW_LEFT;
153 else if (tdrdi->right_view_id[0] == view_id)
154 stereo_3d->view = AV_STEREO3D_VIEW_RIGHT;
155 else
156 stereo_3d->view = AV_STEREO3D_VIEW_UNSPEC;
157 }
158 }
159
161 if (ret < 0)
162 goto fail;
163
164 size_t rpl_bytes;
165 if (av_size_mult(s->pkt.nb_nals, sizeof(*frame->rpl), &rpl_bytes) < 0)
166 goto fail;
167 frame->rpl = av_refstruct_allocz(rpl_bytes);
168 if (!frame->rpl)
169 goto fail;
170 frame->nb_rpl_elems = s->pkt.nb_nals;
171
173 if (!frame->tab_mvf)
174 goto fail;
175
177 if (!frame->rpl_tab)
178 goto fail;
179 frame->ctb_count = l->sps->ctb_width * l->sps->ctb_height;
180 for (j = 0; j < frame->ctb_count; j++)
181 frame->rpl_tab[j] = frame->rpl;
182
183 if (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD)
185 if ((s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD) ||
186 (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_BOTTOM_FIELD))
187 frame->f->flags |= AV_FRAME_FLAG_INTERLACED;
188
189 ret = ff_hwaccel_frame_priv_alloc(s->avctx, &frame->hwaccel_picture_private);
190 if (ret < 0)
191 goto fail;
192
193 frame->pps = av_refstruct_ref_c(s->pps);
194 if (l != &s->layers[0] && ff_hevc_is_alpha_video(s)) {
195 AVFrame *alpha = frame->f;
196 AVFrame *base = s->layers[0].cur_frame->f;
198 if (ret < 0)
199 goto fail;
200 }
201
202 return frame;
203fail:
205 return NULL;
206 }
207 av_log(s->avctx, AV_LOG_ERROR, "Error allocating frame, DPB full.\n");
208 return NULL;
209}
210
212{
213 HEVCFrame *ref;
214 int i;
215 int no_output;
216
217 /* check that this POC doesn't already exist */
218 for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
219 HEVCFrame *frame = &l->DPB[i];
220
221 if (frame->f && frame->poc == poc) {
222 av_log(s->avctx, AV_LOG_ERROR, "Duplicate POC in a sequence: %d.\n",
223 poc);
224 return AVERROR_INVALIDDATA;
225 }
226 }
227
228 ref = alloc_frame(s, l);
229 if (!ref)
230 return AVERROR(ENOMEM);
231
232 s->cur_frame = ref;
233 l->cur_frame = ref;
234 s->collocated_ref = NULL;
235
236 ref->base_layer_frame = (l != &s->layers[0] && s->layers[0].cur_frame) ?
237 s->layers[0].cur_frame - s->layers[0].DPB : -1;
238
239 no_output = !IS_IRAP(s) && (s->poc < s->recovery_poc) &&
241 !(s->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) &&
242 !(s->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL);
243 if (s->sh.pic_output_flag && !no_output)
245 else
247
248 ref->poc = poc;
249 ref->f->crop_left = l->sps->output_window.left_offset;
250 ref->f->crop_right = l->sps->output_window.right_offset;
251 ref->f->crop_top = l->sps->output_window.top_offset;
252 ref->f->crop_bottom = l->sps->output_window.bottom_offset;
253
254 return 0;
255}
256
258{
259 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
260 HEVCFrame *frame = &l->DPB[i];
261 if (frame->flags & HEVC_FRAME_FLAG_UNAVAILABLE) {
263 }
264 }
265}
266
268 unsigned layers_active_decode, unsigned layers_active_output,
269 unsigned max_output, unsigned max_dpb, int discard)
270{
271 while (1) {
272 int nb_dpb[HEVC_VPS_MAX_LAYERS] = { 0 };
273 int nb_output = 0;
274 int min_poc = INT_MAX;
275 int min_layer = -1;
276 int min_idx, ret = 0;
277
278 for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
279 HEVCLayerContext *l = &s->layers[layer];
280
281 if (!(layers_active_decode & (1 << layer)))
282 continue;
283
284 for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
285 HEVCFrame *frame = &l->DPB[i];
286 if (frame->flags & HEVC_FRAME_FLAG_OUTPUT) {
287 // nb_output counts AUs with an output-pending frame
288 // in at least one layer
289 if (!(frame->base_layer_frame >= 0 &&
290 (s->layers[0].DPB[frame->base_layer_frame].flags & HEVC_FRAME_FLAG_OUTPUT)))
291 nb_output++;
292 if (min_layer < 0 || frame->poc < min_poc) {
293 min_poc = frame->poc;
294 min_idx = i;
295 min_layer = layer;
296 }
297 }
298 nb_dpb[layer] += !!frame->flags;
299 }
300 }
301
302 if (nb_output > max_output ||
303 (nb_output &&
304 (nb_dpb[0] > max_dpb || nb_dpb[1] > max_dpb))) {
305 HEVCFrame *frame = &s->layers[min_layer].DPB[min_idx];
306 AVFrame *f = frame->needs_fg ? frame->frame_grain : frame->f;
307 int output = !discard && (layers_active_output & (1 << min_layer));
308
309 if (output) {
310 if (frame->flags & HEVC_FRAME_FLAG_CORRUPT)
311 f->flags |= AV_FRAME_FLAG_CORRUPT;
312 f->pkt_dts = s->pkt_dts;
314 }
316 if (ret < 0)
317 return ret;
318
319 av_log(s->avctx, AV_LOG_DEBUG, "%s frame with POC %d/%d.\n",
320 output ? "Output" : "Discarded", min_layer, frame->poc);
321 continue;
322 }
323 return 0;
324 }
325}
326
328{
329 HEVCFrame *frame = s->cur_frame;
330 int ctb_count = frame->ctb_count;
331 int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
332 int i;
333
334 if (s->slice_idx >= frame->nb_rpl_elems)
335 return AVERROR_INVALIDDATA;
336
337 for (i = ctb_addr_ts; i < ctb_count; i++)
338 frame->rpl_tab[i] = frame->rpl + s->slice_idx;
339
340 frame->refPicList = (RefPicList *)frame->rpl_tab[ctb_addr_ts];
341
342 return 0;
343}
344
346{
347 SliceHeader *sh = &s->sh;
348
349 uint8_t nb_list = sh->slice_type == HEVC_SLICE_B ? 2 : 1;
350 uint8_t list_idx;
351 int i, j, ret;
352
353 ret = init_slice_rpl(s);
354 if (ret < 0)
355 return ret;
356
357 if (!(s->rps[ST_CURR_BEF].nb_refs + s->rps[ST_CURR_AFT].nb_refs +
358 s->rps[LT_CURR].nb_refs +
359 s->rps[INTER_LAYER0].nb_refs + s->rps[INTER_LAYER1].nb_refs) &&
360 !s->pps->pps_curr_pic_ref_enabled_flag) {
361 av_log(s->avctx, AV_LOG_ERROR, "Zero refs in the frame RPS.\n");
362 return AVERROR_INVALIDDATA;
363 }
364
365 for (list_idx = 0; list_idx < nb_list; list_idx++) {
366 RefPicList rpl_tmp = { { 0 } };
367 RefPicList *rpl = &s->cur_frame->refPicList[list_idx];
368
369 /* The order of the elements is
370 * ST_CURR_BEF - INTER_LAYER0 - ST_CURR_AFT - LT_CURR - INTER_LAYER1 for the L0 and
371 * ST_CURR_AFT - INTER_LAYER1 - ST_CURR_BEF - LT_CURR - INTER_LAYER0 for the L1 */
372 int cand_lists[] = { list_idx ? ST_CURR_AFT : ST_CURR_BEF,
373 list_idx ? INTER_LAYER1 : INTER_LAYER0,
374 list_idx ? ST_CURR_BEF : ST_CURR_AFT,
375 LT_CURR,
376 list_idx ? INTER_LAYER0 : INTER_LAYER1
377 };
378
379 /* concatenate the candidate lists for the current frame */
380 while (rpl_tmp.nb_refs < sh->nb_refs[list_idx]) {
381 for (i = 0; i < FF_ARRAY_ELEMS(cand_lists); i++) {
382 RefPicList *rps = &s->rps[cand_lists[i]];
383 for (j = 0; j < rps->nb_refs && rpl_tmp.nb_refs < HEVC_MAX_REFS; j++) {
384 rpl_tmp.list[rpl_tmp.nb_refs] = rps->list[j];
385 rpl_tmp.ref[rpl_tmp.nb_refs] = rps->ref[j];
386 // multiview inter-layer refs are treated as long-term here,
387 // cf. G.8.1.3
388 rpl_tmp.isLongTerm[rpl_tmp.nb_refs] = cand_lists[i] == LT_CURR ||
389 cand_lists[i] == INTER_LAYER0 ||
390 cand_lists[i] == INTER_LAYER1;
391 rpl_tmp.nb_refs++;
392 }
393 }
394 // Construct RefPicList0, RefPicList1 (8-8, 8-10)
395 if (s->pps->pps_curr_pic_ref_enabled_flag && rpl_tmp.nb_refs < HEVC_MAX_REFS) {
396 rpl_tmp.list[rpl_tmp.nb_refs] = s->cur_frame->poc;
397 rpl_tmp.ref[rpl_tmp.nb_refs] = s->cur_frame;
398 rpl_tmp.isLongTerm[rpl_tmp.nb_refs] = 1;
399 rpl_tmp.nb_refs++;
400 }
401 }
402
403 /* reorder the references if necessary */
404 if (sh->rpl_modification_flag[list_idx]) {
405 for (i = 0; i < sh->nb_refs[list_idx]; i++) {
406 int idx = sh->list_entry_lx[list_idx][i];
407
408 if (idx >= rpl_tmp.nb_refs) {
409 av_log(s->avctx, AV_LOG_ERROR, "Invalid reference index.\n");
410 return AVERROR_INVALIDDATA;
411 }
412
413 rpl->list[i] = rpl_tmp.list[idx];
414 rpl->ref[i] = rpl_tmp.ref[idx];
415 rpl->isLongTerm[i] = rpl_tmp.isLongTerm[idx];
416 rpl->nb_refs++;
417 }
418 } else {
419 memcpy(rpl, &rpl_tmp, sizeof(*rpl));
420 rpl->nb_refs = FFMIN(rpl->nb_refs, sh->nb_refs[list_idx]);
421 }
422
423 // 8-9
424 if (s->pps->pps_curr_pic_ref_enabled_flag &&
425 !sh->rpl_modification_flag[list_idx] &&
426 rpl_tmp.nb_refs > sh->nb_refs[L0]) {
427 rpl->list[sh->nb_refs[L0] - 1] = s->cur_frame->poc;
428 rpl->ref[sh->nb_refs[L0] - 1] = s->cur_frame;
429 }
430
431 if (sh->collocated_list == list_idx &&
432 sh->collocated_ref_idx < rpl->nb_refs)
433 s->collocated_ref = rpl->ref[sh->collocated_ref_idx];
434 }
435
436 return 0;
437}
438
440 int poc, uint8_t use_msb)
441{
442 int mask = use_msb ? ~0 : (1 << l->sps->log2_max_poc_lsb) - 1;
443 int i;
444
445 for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
446 HEVCFrame *ref = &l->DPB[i];
447 if (ref->f) {
448 if ((ref->poc & mask) == poc && (use_msb || ref->poc != s->poc))
449 return ref;
450 }
451 }
452
453 if (s->nal_unit_type != HEVC_NAL_CRA_NUT && !IS_BLA(s))
454 av_log(s->avctx, AV_LOG_ERROR,
455 "Could not find ref with POC %d\n", poc);
456 return NULL;
457}
458
459static void mark_ref(HEVCFrame *frame, int flag)
460{
462 frame->flags |= flag;
463}
464
466{
468
469 frame = alloc_frame(s, l);
470 if (!frame)
471 return NULL;
472
473 if (!s->avctx->hwaccel) {
474 int nb_planes = l->sps->chroma_format_idc ? 3 : 1;
475 if (!l->sps->pixel_shift) {
476 for (int i = 0; i < nb_planes; i++)
477 memset(frame->f->data[i], 1 << (l->sps->bit_depth - 1),
478 frame->f->linesize[i] * AV_CEIL_RSHIFT(l->sps->height, l->sps->vshift[i]));
479 } else {
480 for (int i = 0; i < nb_planes; i++)
481 for (int y = 0; y < (l->sps->height >> l->sps->vshift[i]); y++) {
482 uint8_t *dst = frame->f->data[i] + y * frame->f->linesize[i];
483 AV_WN16(dst, 1 << (l->sps->bit_depth - 1));
484 av_memcpy_backptr(dst + 2, 2, 2*(l->sps->width >> l->sps->hshift[i]) - 2);
485 }
486 }
487 }
488
489 frame->poc = poc;
491
492 if (s->avctx->active_thread_type == FF_THREAD_FRAME)
493 ff_progress_frame_report(&frame->tf, INT_MAX);
494
495 return frame;
496}
497
498/* add a reference with the given poc to the list and mark it as used in DPB */
500 RefPicList *rps, int list_idx,
501 int poc, int ref_flag, uint8_t use_msb)
502{
503 RefPicList *list = &rps[list_idx];
504 HEVCFrame *ref = find_ref_idx(s, l, poc, use_msb);
505
506 if (ref == s->cur_frame || list->nb_refs >= HEVC_MAX_REFS)
507 return AVERROR_INVALIDDATA;
508
509 if (!IS_IRAP(s) && list_idx != ST_FOLL && list_idx != LT_FOLL) {
510 int ref_corrupt = !ref || ref->flags & (HEVC_FRAME_FLAG_CORRUPT |
512 int recovering = HEVC_IS_RECOVERING(s);
513
514 if (ref_corrupt && !recovering) {
515 if (!(s->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) &&
516 !(s->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL))
517 return AVERROR_INVALIDDATA;
518
519 s->cur_frame->flags |= HEVC_FRAME_FLAG_CORRUPT;
520 }
521 }
522
523 if (!ref) {
524 ref = generate_missing_ref(s, l, poc);
525 if (!ref)
526 return AVERROR(ENOMEM);
527 }
528
529 list->list[list->nb_refs] = ref->poc;
530 list->ref[list->nb_refs] = ref;
531 list->nb_refs++;
532
533 mark_ref(ref, ref_flag);
534 return 0;
535}
536
538{
539 const ShortTermRPS *short_rps = s->sh.short_term_rps;
540 const LongTermRPS *long_rps = &s->sh.long_term_rps;
541 RefPicList *rps = s->rps;
542 int i, ret = 0;
543
545
546 /* clear the reference flags on all frames except the current one */
547 for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
548 HEVCFrame *frame = &l->DPB[i];
549
550 if (frame == s->cur_frame)
551 continue;
552
553 mark_ref(frame, 0);
554 }
555
556 for (i = 0; i < NB_RPS_TYPE; i++)
557 rps[i].nb_refs = 0;
558
559 if (!short_rps)
560 goto inter_layer;
561
562 /* add the short refs */
563 for (i = 0; i < short_rps->num_delta_pocs; i++) {
564 int poc = s->poc + short_rps->delta_poc[i];
565 int list;
566
567 if (!(short_rps->used & (1 << i)))
568 list = ST_FOLL;
569 else if (i < short_rps->num_negative_pics)
570 list = ST_CURR_BEF;
571 else
572 list = ST_CURR_AFT;
573
574 ret = add_candidate_ref(s, l, rps, list, poc,
576 if (ret < 0)
577 goto fail;
578 }
579
580 /* add the long refs */
581 for (i = 0; i < long_rps->nb_refs; i++) {
582 int poc = long_rps->poc[i];
583 int list = long_rps->used[i] ? LT_CURR : LT_FOLL;
584
585 ret = add_candidate_ref(s, l, rps, list, poc,
587 if (ret < 0)
588 goto fail;
589 }
590
591inter_layer:
592 /* add inter-layer refs */
593 if (s->sh.inter_layer_pred) {
594 HEVCLayerContext *l0 = &s->layers[0];
595
596 av_assert0(l != l0);
597
598 /* Given the assumption of at most two layers, refPicSet0Flag is
599 * always 1, so only RefPicSetInterLayer0 can ever contain a frame. */
600 if (l0->cur_frame) {
601 // inter-layer refs are treated as short-term here, cf. F.8.1.6
602 ret = add_candidate_ref(s, l0, rps, INTER_LAYER0, l0->cur_frame->poc,
604 if (ret < 0)
605 goto fail;
606 }
607 }
608
609fail:
610 /* release any frames that are now unused */
611 for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++)
612 ff_hevc_unref_frame(&l->DPB[i], 0);
613
614 return ret;
615}
616
618 unsigned layer_idx)
619{
620 int ret = 0;
621 int i;
622 const ShortTermRPS *rps = sh->short_term_rps;
623 const LongTermRPS *long_rps = &sh->long_term_rps;
624
625 if (rps) {
626 for (i = 0; i < rps->num_negative_pics; i++)
627 ret += !!(rps->used & (1 << i));
628 for (; i < rps->num_delta_pocs; i++)
629 ret += !!(rps->used & (1 << i));
630 }
631
632 for (i = 0; i < long_rps->nb_refs; i++)
633 ret += !!long_rps->used[i];
634
635 if (sh->inter_layer_pred) {
636 av_assert0(pps->sps->vps->num_direct_ref_layers[layer_idx] < 2);
637 ret++;
638 }
639
640 if (pps->pps_curr_pic_ref_enabled_flag)
641 ret++;
642
643 return ret;
644}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition avcodec.h:1590
#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 vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
#define f(width, name)
Definition cbs_vp8.c:236
#define s(width, name)
Definition cbs_vp9.c:198
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
int av_container_fifo_write(AVContainerFifo *cf, void *obj, unsigned flags)
Write the contents of obj to the FIFO.
@ AV_CONTAINER_FIFO_FLAG_REF
Signal to av_container_fifo_write() that it should make a new reference to data in src rather than co...
#define NULL
Definition coverity.c:32
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:2222
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
Definition decode.c:1979
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:2336
int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f)
This function sets up the ProgressFrame, i.e.
Definition decode.c:1925
void ff_progress_frame_unref(ProgressFrame *f)
Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame,...
Definition decode.c:1962
static AVFrame * frame
uint64_t pps
Definition dovi_rpuenc.c:36
#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_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:2613
@ AV_PICTURE_STRUCTURE_TOP_FIELD
coded as top field
Definition avcodec.h:2612
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition buffer.c:233
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#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:695
#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:700
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition frame.h:683
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:496
AVFrameSideData * av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, size_t size, unsigned int flags)
Add new side data entry to an array.
Definition side_data.c:204
AVBufferRef * av_frame_get_plane_buffer(const AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition frame.c:604
@ AV_FRAME_DATA_VIEW_ID
This side data must be associated with a video frame.
Definition frame.h:245
@ AV_FRAME_DATA_LCEVC
Raw LCEVC payload data, as a uint8_t array, with NAL emulation bytes intact.
Definition frame.h:236
#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:445
int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
Definition mem.c:565
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition stereo3d.c:54
@ AV_STEREO3D_FRAMESEQUENCE
Views are alternated temporally.
Definition stereo3d.h:89
@ AV_STEREO3D_VIEW_RIGHT
Frame contains only the right view.
Definition stereo3d.h:163
@ AV_STEREO3D_VIEW_LEFT
Frame contains only the left view.
Definition stereo3d.h:158
@ AV_STEREO3D_VIEW_UNSPEC
Content is unspecified.
Definition stereo3d.h:168
#define HEVC_VPS_MAX_LAYERS
Definition ps.h:35
int ff_hevc_output_frames(HEVCContext *s, unsigned layers_active_decode, unsigned layers_active_output, unsigned max_output, unsigned max_dpb, int discard)
Find frames in the DPB that are ready for output and either write them to the output FIFO or drop the...
Definition refs.c:267
static HEVCFrame * find_ref_idx(HEVCContext *s, HEVCLayerContext *l, int poc, uint8_t use_msb)
Definition refs.c:439
void ff_hevc_flush_dpb(HEVCContext *s)
Drop all frames currently in DPB.
Definition refs.c:76
int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps, unsigned layer_idx)
Get the number of candidate references for the current frame.
Definition refs.c:617
const RefPicList * ff_hevc_get_ref_list(const HEVCFrame *ref, int x0, int y0)
Definition refs.c:57
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
void ff_hevc_clear_refs(HEVCLayerContext *l)
Mark all frames in DPB as unused for reference.
Definition refs.c:67
static void unref_missing_refs(HEVCLayerContext *l)
Definition refs.c:257
static void mark_ref(HEVCFrame *frame, int flag)
Definition refs.c:459
int ff_hevc_set_new_ref(HEVCContext *s, HEVCLayerContext *l, int poc)
Definition refs.c:211
int ff_hevc_frame_rps(HEVCContext *s, HEVCLayerContext *l)
Construct the reference picture sets for the current frame.
Definition refs.c:537
static int replace_alpha_plane(AVFrame *alpha, AVFrame *base)
Definition refs.c:85
static HEVCFrame * alloc_frame(HEVCContext *s, HEVCLayerContext *l)
Definition refs.c:110
static int init_slice_rpl(HEVCContext *s)
Definition refs.c:327
void ff_hevc_unref_frame(HEVCFrame *frame, int flags)
Definition refs.c:35
int ff_hevc_slice_rpl(HEVCContext *s)
Construct the reference picture list(s) for the current slice.
Definition refs.c:345
static HEVCFrame * generate_missing_ref(HEVCContext *s, HEVCLayerContext *l, int poc)
Definition refs.c:465
#define HEVC_FRAME_FLAG_SHORT_REF
Definition hevcdec.h:355
#define HEVC_IS_RECOVERING(s)
Definition hevcdec.h:81
#define HEVC_FRAME_FLAG_UNAVAILABLE
Definition hevcdec.h:357
#define HEVC_FRAME_FLAG_LONG_REF
Definition hevcdec.h:356
#define L0
Definition hevcdec.h:56
#define HEVC_FRAME_FLAG_OUTPUT
Definition hevcdec.h:354
#define IS_IRAP(s)
Definition hevcdec.h:77
@ ST_CURR_AFT
Definition hevcdec.h:85
@ INTER_LAYER1
Definition hevcdec.h:90
@ NB_RPS_TYPE
Definition hevcdec.h:91
@ LT_FOLL
Definition hevcdec.h:88
@ ST_CURR_BEF
Definition hevcdec.h:84
@ LT_CURR
Definition hevcdec.h:87
@ INTER_LAYER0
Definition hevcdec.h:89
@ ST_FOLL
Definition hevcdec.h:86
#define IS_BLA(s)
Definition hevcdec.h:75
#define HEVC_FRAME_FLAG_CORRUPT
Definition hevcdec.h:358
static const int16_t alpha[]
Definition ilbcdata.h:55
#define AV_WN16(p, v)
@ HEVC_NAL_CRA_NUT
Definition hevc.h:50
@ HEVC_SLICE_B
Definition hevc.h:96
@ HEVC_MAX_REFS
Definition hevc.h:122
int ff_hevc_is_alpha_video(const HEVCContext *s)
Definition hevcdec.c:440
Multithreading API for decoders.
Stereoscopic video.
static const uint16_t mask[17]
Definition lzw.c:38
#define FFMIN(a, b)
Definition macros.h:49
Memory handling functions.
const char data[16]
Definition mxf.c:149
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
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:120
const void * av_refstruct_ref_c(const void *obj)
Analog of av_refstruct_ref(), but for constant objects.
Definition refstruct.c:149
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:297
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition refstruct.h:105
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition stereo3d.h:203
enum AVStereo3DType type
How views are packed within the video.
Definition stereo3d.h:207
enum AVStereo3DView view
Determines which views are packed.
Definition stereo3d.h:217
int poc
Definition hevcdec.h:373
HEVCFrame DPB[32]
Definition hevcdec.h:453
HEVCFrame * cur_frame
Definition hevcdec.h:454
const HEVCSPS * sps
Definition hevcdec.h:456
struct AVRefStructPool * rpl_tab_pool
Definition hevcdec.h:487
struct AVRefStructPool * tab_mvf_pool
Definition hevcdec.h:486
Definition ps.h:371
uint8_t num_ref_displays
Definition sei.h:86
uint16_t left_view_id[32]
Definition sei.h:87
uint16_t right_view_id[32]
Definition sei.h:88
Definition ps.h:252
int bit_depth
Definition ps.h:262
int chroma_format_idc
Definition ps.h:254
int ctb_width
Definition ps.h:349
int height
Definition ps.h:348
HEVCWindow output_window
Definition ps.h:256
unsigned int log2_max_poc_lsb
Definition ps.h:267
int ctb_height
Definition ps.h:350
int width
coded frame dimension in various units
Definition ps.h:347
const HEVCVPS * vps
RefStruct reference.
Definition ps.h:368
int hshift[3]
Definition ps.h:360
int pixel_shift
Definition ps.h:264
int vshift[3]
Definition ps.h:361
Definition ps.h:168
unsigned int top_offset
Definition ps.h:94
unsigned int right_offset
Definition ps.h:93
unsigned int bottom_offset
Definition ps.h:95
unsigned int left_offset
Definition ps.h:92
uint8_t used[32]
Definition hevcdec.h:190
uint8_t nb_refs
Definition hevcdec.h:191
int poc[32]
Definition hevcdec.h:188
uint8_t poc_msb_present[32]
Definition hevcdec.h:189
int isLongTerm[HEVC_MAX_REFS]
Definition hevcdec.h:197
struct HEVCFrame * ref[HEVC_MAX_REFS]
Definition hevcdec.h:195
int nb_refs
Definition hevcdec.h:198
int list[HEVC_MAX_REFS]
Definition hevcdec.h:196
uint32_t used
Definition ps.h:77
uint8_t num_delta_pocs
Definition ps.h:81
int32_t delta_poc[32]
Definition ps.h:76
uint8_t num_negative_pics
Definition ps.h:80
const ShortTermRPS * short_term_rps
Definition hevcdec.h:228
enum HEVCSliceType slice_type
Definition hevcdec.h:213
unsigned int list_entry_lx[2][32]
Definition hevcdec.h:231
uint8_t inter_layer_pred
Definition hevcdec.h:222
unsigned int nb_refs[2]
Definition hevcdec.h:237
uint8_t rpl_modification_flag[2]
Definition hevcdec.h:233
LongTermRPS long_term_rps
Definition hevcdec.h:230
unsigned int collocated_ref_idx
Definition hevcdec.h:247
uint8_t collocated_list
Definition hevcdec.h:245
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
int size
uint8_t base
Definition vp3data.h:128