FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 "decode.h"
29 #include "hevc.h"
30 #include "hevcdec.h"
31 #include "progressframe.h"
32 #include "libavutil/refstruct.h"
33 
35 {
36  frame->flags &= ~flags;
37  if (!(frame->flags & ~HEVC_FRAME_FLAG_CORRUPT))
38  frame->flags = 0;
39  if (!frame->flags) {
41  av_frame_unref(frame->frame_grain);
42  frame->needs_fg = 0;
43 
45  av_refstruct_unref(&frame->tab_mvf);
46 
48  frame->nb_rpl_elems = 0;
49  av_refstruct_unref(&frame->rpl_tab);
50  frame->refPicList = NULL;
51 
52  av_refstruct_unref(&frame->hwaccel_picture_private);
53  }
54 }
55 
56 const RefPicList *ff_hevc_get_ref_list(const HEVCFrame *ref, int x0, int y0)
57 {
58  const HEVCSPS *sps = ref->pps->sps;
59  int x_cb = x0 >> sps->log2_ctb_size;
60  int y_cb = y0 >> sps->log2_ctb_size;
61  int pic_width_cb = sps->ctb_width;
62  int ctb_addr_ts = ref->pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb];
63  return &ref->rpl_tab[ctb_addr_ts]->refPicList[0];
64 }
65 
67 {
68  int i;
69  for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++)
73 }
74 
76 {
77  for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
78  HEVCLayerContext *l = &s->layers[layer];
79  for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++)
80  ff_hevc_unref_frame(&l->DPB[i], ~0);
81  }
82 }
83 
85 {
87  uintptr_t data = (uintptr_t)alpha->data[0];
88  int ret;
89 
90  for (int i = 0; i < FF_ARRAY_ELEMS(alpha->buf) && alpha->buf[i]; i++) {
91  AVBufferRef *buf = alpha->buf[i];
92  uintptr_t buf_begin = (uintptr_t)buf->data;
93 
94  if (data >= buf_begin && data < buf_begin + buf->size) {
95  ret = av_buffer_replace(&alpha->buf[i], base_a);
96  if (ret < 0)
97  return ret;
98 
99  alpha->linesize[0] = base->linesize[3];
100  alpha->data[0] = base->data[3];
101 
102  return 0;
103  }
104  }
105 
106  return AVERROR_BUG;
107 }
108 
110 {
111  const HEVCVPS *vps = l->sps->vps;
112  const int view_id = vps->view_id[s->cur_layer];
113  int i, j, ret;
114  for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
115  HEVCFrame *frame = &l->DPB[i];
116  if (frame->f)
117  continue;
118 
119  ret = ff_progress_frame_alloc(s->avctx, &frame->tf);
120  if (ret < 0)
121  return NULL;
122 
123  // Add LCEVC SEI metadata here, as it's needed in get_buffer()
124  if (s->sei.common.lcevc.info) {
125  HEVCSEILCEVC *lcevc = &s->sei.common.lcevc;
126  ret = ff_frame_new_side_data_from_buf(s->avctx, frame->tf.f,
127  AV_FRAME_DATA_LCEVC, &lcevc->info);
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 
160  ret = ff_progress_frame_get_buffer(s->avctx, &frame->tf,
162  if (ret < 0)
163  return NULL;
164 
165  frame->rpl = av_refstruct_allocz(s->pkt.nb_nals * sizeof(*frame->rpl));
166  if (!frame->rpl)
167  goto fail;
168  frame->nb_rpl_elems = s->pkt.nb_nals;
169 
171  if (!frame->tab_mvf)
172  goto fail;
173 
175  if (!frame->rpl_tab)
176  goto fail;
177  frame->ctb_count = l->sps->ctb_width * l->sps->ctb_height;
178  for (j = 0; j < frame->ctb_count; j++)
179  frame->rpl_tab[j] = frame->rpl;
180 
181  if (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD)
183  if ((s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_TOP_FIELD) ||
184  (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_BOTTOM_FIELD))
185  frame->f->flags |= AV_FRAME_FLAG_INTERLACED;
186 
187  ret = ff_hwaccel_frame_priv_alloc(s->avctx, &frame->hwaccel_picture_private);
188  if (ret < 0)
189  goto fail;
190 
191  frame->pps = av_refstruct_ref_c(s->pps);
192  if (l != &s->layers[0] && ff_hevc_is_alpha_video(s)) {
193  AVFrame *alpha = frame->f;
194  AVFrame *base = s->layers[0].cur_frame->f;
196  if (ret < 0)
197  goto fail;
198  }
199 
200  return frame;
201 fail:
203  return NULL;
204  }
205  av_log(s->avctx, AV_LOG_ERROR, "Error allocating frame, DPB full.\n");
206  return NULL;
207 }
208 
210 {
211  HEVCFrame *ref;
212  int i;
213  int no_output;
214 
215  /* check that this POC doesn't already exist */
216  for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
217  HEVCFrame *frame = &l->DPB[i];
218 
219  if (frame->f && frame->poc == poc) {
220  av_log(s->avctx, AV_LOG_ERROR, "Duplicate POC in a sequence: %d.\n",
221  poc);
222  return AVERROR_INVALIDDATA;
223  }
224  }
225 
226  ref = alloc_frame(s, l);
227  if (!ref)
228  return AVERROR(ENOMEM);
229 
230  s->cur_frame = ref;
231  l->cur_frame = ref;
232  s->collocated_ref = NULL;
233 
234  ref->base_layer_frame = (l != &s->layers[0] && s->layers[0].cur_frame) ?
235  s->layers[0].cur_frame - s->layers[0].DPB : -1;
236 
237  no_output = !IS_IRAP(s) && (s->poc < s->recovery_poc) &&
238  !(s->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) &&
239  !(s->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL);
240  if (s->sh.pic_output_flag && !no_output)
242  else
244 
245  ref->poc = poc;
246  ref->f->crop_left = l->sps->output_window.left_offset;
247  ref->f->crop_right = l->sps->output_window.right_offset;
248  ref->f->crop_top = l->sps->output_window.top_offset;
249  ref->f->crop_bottom = l->sps->output_window.bottom_offset;
250 
251  return 0;
252 }
253 
255 {
256  for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
257  HEVCFrame *frame = &l->DPB[i];
258  if (frame->flags & HEVC_FRAME_FLAG_UNAVAILABLE) {
260  }
261  }
262 }
263 
265  unsigned layers_active_decode, unsigned layers_active_output,
266  unsigned max_output, unsigned max_dpb, int discard)
267 {
268  while (1) {
269  int nb_dpb[HEVC_VPS_MAX_LAYERS] = { 0 };
270  int nb_output = 0;
271  int min_poc = INT_MAX;
272  int min_layer = -1;
273  int min_idx, ret = 0;
274 
275  for (int layer = 0; layer < FF_ARRAY_ELEMS(s->layers); layer++) {
276  HEVCLayerContext *l = &s->layers[layer];
277 
278  if (!(layers_active_decode & (1 << layer)))
279  continue;
280 
281  for (int i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
282  HEVCFrame *frame = &l->DPB[i];
283  if (frame->flags & HEVC_FRAME_FLAG_OUTPUT) {
284  // nb_output counts AUs with an output-pending frame
285  // in at least one layer
286  if (!(frame->base_layer_frame >= 0 &&
287  (s->layers[0].DPB[frame->base_layer_frame].flags & HEVC_FRAME_FLAG_OUTPUT)))
288  nb_output++;
289  if (min_layer < 0 || frame->poc < min_poc) {
290  min_poc = frame->poc;
291  min_idx = i;
292  min_layer = layer;
293  }
294  }
295  nb_dpb[layer] += !!frame->flags;
296  }
297  }
298 
299  if (nb_output > max_output ||
300  (nb_output &&
301  (nb_dpb[0] > max_dpb || nb_dpb[1] > max_dpb))) {
302  HEVCFrame *frame = &s->layers[min_layer].DPB[min_idx];
303  AVFrame *f = frame->needs_fg ? frame->frame_grain : frame->f;
304  int output = !discard && (layers_active_output & (1 << min_layer));
305 
306  if (output) {
307  if (frame->flags & HEVC_FRAME_FLAG_CORRUPT)
308  f->flags |= AV_FRAME_FLAG_CORRUPT;
309  f->pkt_dts = s->pkt_dts;
311  }
313  if (ret < 0)
314  return ret;
315 
316  av_log(s->avctx, AV_LOG_DEBUG, "%s frame with POC %d/%d.\n",
317  output ? "Output" : "Discarded", min_layer, frame->poc);
318  continue;
319  }
320  return 0;
321  }
322 }
323 
325 {
326  HEVCFrame *frame = s->cur_frame;
327  int ctb_count = frame->ctb_count;
328  int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
329  int i;
330 
331  if (s->slice_idx >= frame->nb_rpl_elems)
332  return AVERROR_INVALIDDATA;
333 
334  for (i = ctb_addr_ts; i < ctb_count; i++)
335  frame->rpl_tab[i] = frame->rpl + s->slice_idx;
336 
337  frame->refPicList = (RefPicList *)frame->rpl_tab[ctb_addr_ts];
338 
339  return 0;
340 }
341 
343 {
344  SliceHeader *sh = &s->sh;
345 
346  uint8_t nb_list = sh->slice_type == HEVC_SLICE_B ? 2 : 1;
347  uint8_t list_idx;
348  int i, j, ret;
349 
350  ret = init_slice_rpl(s);
351  if (ret < 0)
352  return ret;
353 
354  if (!(s->rps[ST_CURR_BEF].nb_refs + s->rps[ST_CURR_AFT].nb_refs +
355  s->rps[LT_CURR].nb_refs +
356  s->rps[INTER_LAYER0].nb_refs + s->rps[INTER_LAYER1].nb_refs) &&
357  !s->pps->pps_curr_pic_ref_enabled_flag) {
358  av_log(s->avctx, AV_LOG_ERROR, "Zero refs in the frame RPS.\n");
359  return AVERROR_INVALIDDATA;
360  }
361 
362  for (list_idx = 0; list_idx < nb_list; list_idx++) {
363  RefPicList rpl_tmp = { { 0 } };
364  RefPicList *rpl = &s->cur_frame->refPicList[list_idx];
365 
366  /* The order of the elements is
367  * ST_CURR_BEF - INTER_LAYER0 - ST_CURR_AFT - LT_CURR - INTER_LAYER1 for the L0 and
368  * ST_CURR_AFT - INTER_LAYER1 - ST_CURR_BEF - LT_CURR - INTER_LAYER0 for the L1 */
369  int cand_lists[] = { list_idx ? ST_CURR_AFT : ST_CURR_BEF,
370  list_idx ? INTER_LAYER1 : INTER_LAYER0,
371  list_idx ? ST_CURR_BEF : ST_CURR_AFT,
372  LT_CURR,
373  list_idx ? INTER_LAYER0 : INTER_LAYER1
374  };
375 
376  /* concatenate the candidate lists for the current frame */
377  while (rpl_tmp.nb_refs < sh->nb_refs[list_idx]) {
378  for (i = 0; i < FF_ARRAY_ELEMS(cand_lists); i++) {
379  RefPicList *rps = &s->rps[cand_lists[i]];
380  for (j = 0; j < rps->nb_refs && rpl_tmp.nb_refs < HEVC_MAX_REFS; j++) {
381  rpl_tmp.list[rpl_tmp.nb_refs] = rps->list[j];
382  rpl_tmp.ref[rpl_tmp.nb_refs] = rps->ref[j];
383  // multiview inter-layer refs are treated as long-term here,
384  // cf. G.8.1.3
385  rpl_tmp.isLongTerm[rpl_tmp.nb_refs] = cand_lists[i] == LT_CURR ||
386  cand_lists[i] == INTER_LAYER0 ||
387  cand_lists[i] == INTER_LAYER1;
388  rpl_tmp.nb_refs++;
389  }
390  }
391  // Construct RefPicList0, RefPicList1 (8-8, 8-10)
392  if (s->pps->pps_curr_pic_ref_enabled_flag && rpl_tmp.nb_refs < HEVC_MAX_REFS) {
393  rpl_tmp.list[rpl_tmp.nb_refs] = s->cur_frame->poc;
394  rpl_tmp.ref[rpl_tmp.nb_refs] = s->cur_frame;
395  rpl_tmp.isLongTerm[rpl_tmp.nb_refs] = 1;
396  rpl_tmp.nb_refs++;
397  }
398  }
399 
400  /* reorder the references if necessary */
401  if (sh->rpl_modification_flag[list_idx]) {
402  for (i = 0; i < sh->nb_refs[list_idx]; i++) {
403  int idx = sh->list_entry_lx[list_idx][i];
404 
405  if (idx >= rpl_tmp.nb_refs) {
406  av_log(s->avctx, AV_LOG_ERROR, "Invalid reference index.\n");
407  return AVERROR_INVALIDDATA;
408  }
409 
410  rpl->list[i] = rpl_tmp.list[idx];
411  rpl->ref[i] = rpl_tmp.ref[idx];
412  rpl->isLongTerm[i] = rpl_tmp.isLongTerm[idx];
413  rpl->nb_refs++;
414  }
415  } else {
416  memcpy(rpl, &rpl_tmp, sizeof(*rpl));
417  rpl->nb_refs = FFMIN(rpl->nb_refs, sh->nb_refs[list_idx]);
418  }
419 
420  // 8-9
421  if (s->pps->pps_curr_pic_ref_enabled_flag &&
422  !sh->rpl_modification_flag[list_idx] &&
423  rpl_tmp.nb_refs > sh->nb_refs[L0]) {
424  rpl->list[sh->nb_refs[L0] - 1] = s->cur_frame->poc;
425  rpl->ref[sh->nb_refs[L0] - 1] = s->cur_frame;
426  }
427 
428  if (sh->collocated_list == list_idx &&
429  sh->collocated_ref_idx < rpl->nb_refs)
430  s->collocated_ref = rpl->ref[sh->collocated_ref_idx];
431  }
432 
433  return 0;
434 }
435 
437  int poc, uint8_t use_msb)
438 {
439  int mask = use_msb ? ~0 : (1 << l->sps->log2_max_poc_lsb) - 1;
440  int i;
441 
442  for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
443  HEVCFrame *ref = &l->DPB[i];
444  if (ref->f) {
445  if ((ref->poc & mask) == poc && (use_msb || ref->poc != s->poc))
446  return ref;
447  }
448  }
449 
450  if (s->nal_unit_type != HEVC_NAL_CRA_NUT && !IS_BLA(s))
451  av_log(s->avctx, AV_LOG_ERROR,
452  "Could not find ref with POC %d\n", poc);
453  return NULL;
454 }
455 
456 static void mark_ref(HEVCFrame *frame, int flag)
457 {
459  frame->flags |= flag;
460 }
461 
463 {
464  HEVCFrame *frame;
465  int i, y;
466 
467  frame = alloc_frame(s, l);
468  if (!frame)
469  return NULL;
470 
471  if (!s->avctx->hwaccel) {
472  if (!l->sps->pixel_shift) {
473  for (i = 0; frame->f->data[i]; i++)
474  memset(frame->f->data[i], 1 << (l->sps->bit_depth - 1),
475  frame->f->linesize[i] * AV_CEIL_RSHIFT(l->sps->height, l->sps->vshift[i]));
476  } else {
477  for (i = 0; frame->f->data[i]; i++)
478  for (y = 0; y < (l->sps->height >> l->sps->vshift[i]); y++) {
479  uint8_t *dst = frame->f->data[i] + y * frame->f->linesize[i];
480  AV_WN16(dst, 1 << (l->sps->bit_depth - 1));
481  av_memcpy_backptr(dst + 2, 2, 2*(l->sps->width >> l->sps->hshift[i]) - 2);
482  }
483  }
484  }
485 
486  frame->poc = poc;
488 
489  if (s->avctx->active_thread_type == FF_THREAD_FRAME)
490  ff_progress_frame_report(&frame->tf, INT_MAX);
491 
492  return frame;
493 }
494 
495 /* add a reference with the given poc to the list and mark it as used in DPB */
497  RefPicList *list,
498  int poc, int ref_flag, uint8_t use_msb)
499 {
500  HEVCFrame *ref = find_ref_idx(s, l, poc, use_msb);
501 
502  if (ref == s->cur_frame || list->nb_refs >= HEVC_MAX_REFS)
503  return AVERROR_INVALIDDATA;
504 
505  if (!IS_IRAP(s)) {
506  int ref_corrupt = !ref || ref->flags & (HEVC_FRAME_FLAG_CORRUPT |
508  int recovering = HEVC_IS_RECOVERING(s);
509 
510  if (ref_corrupt && !recovering) {
511  if (!(s->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) &&
512  !(s->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL))
513  return AVERROR_INVALIDDATA;
514 
515  s->cur_frame->flags |= HEVC_FRAME_FLAG_CORRUPT;
516  }
517  }
518 
519  if (!ref) {
520  ref = generate_missing_ref(s, l, poc);
521  if (!ref)
522  return AVERROR(ENOMEM);
523  }
524 
525  list->list[list->nb_refs] = ref->poc;
526  list->ref[list->nb_refs] = ref;
527  list->nb_refs++;
528 
529  mark_ref(ref, ref_flag);
530  return 0;
531 }
532 
534 {
535  const ShortTermRPS *short_rps = s->sh.short_term_rps;
536  const LongTermRPS *long_rps = &s->sh.long_term_rps;
537  RefPicList *rps = s->rps;
538  int i, ret = 0;
539 
541 
542  /* clear the reference flags on all frames except the current one */
543  for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
544  HEVCFrame *frame = &l->DPB[i];
545 
546  if (frame == s->cur_frame)
547  continue;
548 
549  mark_ref(frame, 0);
550  }
551 
552  for (i = 0; i < NB_RPS_TYPE; i++)
553  rps[i].nb_refs = 0;
554 
555  if (!short_rps)
556  goto inter_layer;
557 
558  /* add the short refs */
559  for (i = 0; i < short_rps->num_delta_pocs; i++) {
560  int poc = s->poc + short_rps->delta_poc[i];
561  int list;
562 
563  if (!(short_rps->used & (1 << i)))
564  list = ST_FOLL;
565  else if (i < short_rps->num_negative_pics)
566  list = ST_CURR_BEF;
567  else
568  list = ST_CURR_AFT;
569 
570  ret = add_candidate_ref(s, l, &rps[list], poc,
572  if (ret < 0)
573  goto fail;
574  }
575 
576  /* add the long refs */
577  for (i = 0; i < long_rps->nb_refs; i++) {
578  int poc = long_rps->poc[i];
579  int list = long_rps->used[i] ? LT_CURR : LT_FOLL;
580 
581  ret = add_candidate_ref(s, l, &rps[list], poc,
583  if (ret < 0)
584  goto fail;
585  }
586 
587 inter_layer:
588  /* add inter-layer refs */
589  if (s->sh.inter_layer_pred) {
590  HEVCLayerContext *l0 = &s->layers[0];
591 
592  av_assert0(l != l0);
593 
594  /* Given the assumption of at most two layers, refPicSet0Flag is
595  * always 1, so only RefPicSetInterLayer0 can ever contain a frame. */
596  if (l0->cur_frame) {
597  // inter-layer refs are treated as short-term here, cf. F.8.1.6
598  ret = add_candidate_ref(s, l0, &rps[INTER_LAYER0], l0->cur_frame->poc,
600  if (ret < 0)
601  goto fail;
602  }
603  }
604 
605 fail:
606  /* release any frames that are now unused */
607  for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++)
608  ff_hevc_unref_frame(&l->DPB[i], 0);
609 
610  return ret;
611 }
612 
614  unsigned layer_idx)
615 {
616  int ret = 0;
617  int i;
618  const ShortTermRPS *rps = sh->short_term_rps;
619  const LongTermRPS *long_rps = &sh->long_term_rps;
620 
621  if (rps) {
622  for (i = 0; i < rps->num_negative_pics; i++)
623  ret += !!(rps->used & (1 << i));
624  for (; i < rps->num_delta_pocs; i++)
625  ret += !!(rps->used & (1 << i));
626  }
627 
628  if (long_rps) {
629  for (i = 0; i < long_rps->nb_refs; i++)
630  ret += !!long_rps->used[i];
631  }
632 
633  if (sh->inter_layer_pred) {
634  av_assert0(pps->sps->vps->num_direct_ref_layers[layer_idx] < 2);
635  ret++;
636  }
637 
638  if (pps->pps_curr_pic_ref_enabled_flag)
639  ret++;
640 
641  return ret;
642 }
ff_progress_frame_report
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
Definition: decode.c:1893
ff_hevc_flush_dpb
void ff_hevc_flush_dpb(HEVCContext *s)
Drop all frames currently in DPB.
Definition: refs.c:75
AV_CONTAINER_FIFO_FLAG_REF
@ 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...
Definition: container_fifo.h:39
AV_STEREO3D_VIEW_LEFT
@ AV_STEREO3D_VIEW_LEFT
Frame contains only the left view.
Definition: stereo3d.h:158
LT_FOLL
@ LT_FOLL
Definition: hevcdec.h:90
av_container_fifo_write
int av_container_fifo_write(AVContainerFifo *cf, void *obj, unsigned flags)
Write the contents of obj to the FIFO.
Definition: container_fifo.c:162
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
HEVCWindow::bottom_offset
unsigned int bottom_offset
Definition: ps.h:95
ShortTermRPS::num_negative_pics
uint8_t num_negative_pics
Definition: ps.h:80
HEVC_VPS_MAX_LAYERS
#define HEVC_VPS_MAX_LAYERS
Definition: ps.h:35
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
HEVCSPS::bit_depth
int bit_depth
Definition: ps.h:265
HEVC_IS_RECOVERING
#define HEVC_IS_RECOVERING(s)
Definition: hevcdec.h:83
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
HEVCSEILCEVC::info
AVBufferRef * info
Definition: h2645_sei.h:54
mask
int mask
Definition: mediacodecdec_common.c:154
container_fifo.h
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
ff_progress_frame_get_buffer
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
This function sets up the ProgressFrame, i.e.
Definition: decode.c:1848
data
const char data[16]
Definition: mxf.c:149
base
uint8_t base
Definition: vp3data.h:128
ff_hevc_frame_rps
int ff_hevc_frame_rps(HEVCContext *s, HEVCLayerContext *l)
Construct the reference picture sets for the current frame.
Definition: refs.c:533
RefPicList
Definition: hevcdec.h:196
AV_STEREO3D_VIEW_RIGHT
@ AV_STEREO3D_VIEW_RIGHT
Frame contains only the right view.
Definition: stereo3d.h:163
HEVCSEILCEVC
Definition: h2645_sei.h:53
AV_STEREO3D_VIEW_UNSPEC
@ AV_STEREO3D_VIEW_UNSPEC
Content is unspecified.
Definition: stereo3d.h:168
HEVCSPS::output_window
HEVCWindow output_window
Definition: ps.h:259
AV_FRAME_FLAG_TOP_FIELD_FIRST
#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:674
find_ref_idx
static HEVCFrame * find_ref_idx(HEVCContext *s, HEVCLayerContext *l, int poc, uint8_t use_msb)
Definition: refs.c:436
AV_CODEC_FLAG_OUTPUT_CORRUPT
#define AV_CODEC_FLAG_OUTPUT_CORRUPT
Output even those frames that might be corrupted.
Definition: avcodec.h:232
HEVC_FRAME_FLAG_LONG_REF
#define HEVC_FRAME_FLAG_LONG_REF
Definition: hevcdec.h:358
fail
#define fail()
Definition: checkasm.h:193
HEVCWindow::left_offset
unsigned int left_offset
Definition: ps.h:92
mark_ref
static void mark_ref(HEVCFrame *frame, int flag)
Definition: refs.c:456
RefPicList::nb_refs
int nb_refs
Definition: hevcdec.h:200
HEVCSPS::log2_max_poc_lsb
unsigned int log2_max_poc_lsb
Definition: ps.h:270
progressframe.h
refstruct.h
ff_frame_new_side_data_from_buf
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:2137
av_refstruct_allocz
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition: refstruct.h:105
AV_STEREO3D_FRAMESEQUENCE
@ AV_STEREO3D_FRAMESEQUENCE
Views are alternated temporally.
Definition: stereo3d.h:89
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
HEVC_SLICE_B
@ HEVC_SLICE_B
Definition: hevc.h:96
unref_missing_refs
static void unref_missing_refs(HEVCLayerContext *l)
Definition: refs.c:254
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
ff_hevc_is_alpha_video
int ff_hevc_is_alpha_video(const HEVCContext *s)
Definition: hevcdec.c:469
av_memcpy_backptr
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
Definition: mem.c:447
stereo3d.h
ff_hwaccel_frame_priv_alloc
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:2251
HEVCLayerContext::cur_frame
HEVCFrame * cur_frame
Definition: hevcdec.h:456
s
#define s(width, name)
Definition: cbs_vp9.c:198
HEVCSPS::height
int height
Definition: ps.h:351
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:431
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
ff_progress_frame_unref
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:1876
decode.h
hevc.h
HEVC_FRAME_FLAG_SHORT_REF
#define HEVC_FRAME_FLAG_SHORT_REF
Definition: hevcdec.h:357
ff_hevc_slice_rpl
int ff_hevc_slice_rpl(HEVCContext *s)
Construct the reference picture list(s) for the current slice.
Definition: refs.c:342
RefPicList::ref
struct HEVCFrame * ref[HEVC_MAX_REFS]
Definition: hevcdec.h:197
HEVCWindow::top_offset
unsigned int top_offset
Definition: ps.h:94
SliceHeader::collocated_list
uint8_t collocated_list
Definition: hevcdec.h:247
ShortTermRPS::num_delta_pocs
uint8_t num_delta_pocs
Definition: ps.h:81
HEVCLayerContext::tab_mvf_pool
struct AVRefStructPool * tab_mvf_pool
Definition: hevcdec.h:488
if
if(ret)
Definition: filter_design.txt:179
AV_PICTURE_STRUCTURE_BOTTOM_FIELD
@ AV_PICTURE_STRUCTURE_BOTTOM_FIELD
coded as bottom field
Definition: avcodec.h:2763
IS_BLA
#define IS_BLA(s)
Definition: hevcdec.h:77
NULL
#define NULL
Definition: coverity.c:32
LongTermRPS::poc
int poc[32]
Definition: hevcdec.h:190
AV_PICTURE_STRUCTURE_TOP_FIELD
@ AV_PICTURE_STRUCTURE_TOP_FIELD
coded as top field
Definition: avcodec.h:2762
generate_missing_ref
static HEVCFrame * generate_missing_ref(HEVCContext *s, HEVCLayerContext *l, int poc)
Definition: refs.c:462
L0
#define L0
Definition: hevcdec.h:58
list
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
Definition: filter_design.txt:25
LongTermRPS::poc_msb_present
uint8_t poc_msb_present[32]
Definition: hevcdec.h:191
av_refstruct_pool_get
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
INTER_LAYER0
@ INTER_LAYER0
Definition: hevcdec.h:91
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
SliceHeader::nb_refs
unsigned int nb_refs[2]
Definition: hevcdec.h:239
av_frame_get_plane_buffer
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:731
ff_hevc_set_new_ref
int ff_hevc_set_new_ref(HEVCContext *s, HEVCLayerContext *l, int poc)
Definition: refs.c:209
ShortTermRPS::used
uint32_t used
Definition: ps.h:77
ff_hevc_output_frames
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:264
IS_IRAP
#define IS_IRAP(s)
Definition: hevcdec.h:79
LongTermRPS::used
uint8_t used[32]
Definition: hevcdec.h:192
ff_hevc_unref_frame
void ff_hevc_unref_frame(HEVCFrame *frame, int flags)
Definition: refs.c:34
HEVCSEITDRDI
Definition: sei.h:82
ST_FOLL
@ ST_FOLL
Definition: hevcdec.h:88
add_candidate_ref
static int add_candidate_ref(HEVCContext *s, HEVCLayerContext *l, RefPicList *list, int poc, int ref_flag, uint8_t use_msb)
Definition: refs.c:496
f
f
Definition: af_crystalizer.c:122
HEVCSPS::vps
const HEVCVPS * vps
RefStruct reference.
Definition: ps.h:371
ff_progress_frame_alloc
int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f)
This function allocates ProgressFrame.f May be called before ff_progress_frame_get_buffer() in the ca...
Definition: decode.c:1834
hevcdec.h
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
HEVCSEITDRDI::right_view_id
uint16_t right_view_id[32]
Definition: sei.h:88
HEVCSEITDRDI::left_view_id
uint16_t left_view_id[32]
Definition: sei.h:87
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
AV_FRAME_DATA_LCEVC
@ AV_FRAME_DATA_LCEVC
Raw LCEVC payload data, as a uint8_t array, with NAL emulation bytes intact.
Definition: frame.h:236
replace_alpha_plane
static int replace_alpha_plane(AVFrame *alpha, AVFrame *base)
Definition: refs.c:84
size
int size
Definition: twinvq_data.h:10344
ff_hevc_clear_refs
void ff_hevc_clear_refs(HEVCLayerContext *l)
Mark all frames in DPB as unused for reference.
Definition: refs.c:66
SliceHeader::collocated_ref_idx
unsigned int collocated_ref_idx
Definition: hevcdec.h:249
AVFrameSideData::data
uint8_t * data
Definition: frame.h:267
HEVC_FRAME_FLAG_OUTPUT
#define HEVC_FRAME_FLAG_OUTPUT
Definition: hevcdec.h:356
HEVC_FRAME_FLAG_CORRUPT
#define HEVC_FRAME_FLAG_CORRUPT
Definition: hevcdec.h:360
HEVC_FRAME_FLAG_UNAVAILABLE
#define HEVC_FRAME_FLAG_UNAVAILABLE
Definition: hevcdec.h:359
HEVCSPS::hshift
int hshift[3]
Definition: ps.h:363
AV_FRAME_DATA_VIEW_ID
@ AV_FRAME_DATA_VIEW_ID
This side data must be associated with a video frame.
Definition: frame.h:245
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1612
av_refstruct_unref
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
flag
#define flag(name)
Definition: cbs_av1.c:474
SliceHeader
Definition: hevcdec.h:207
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AV_CODEC_FLAG2_SHOW_ALL
#define AV_CODEC_FLAG2_SHOW_ALL
Show all frames before the first keyframe.
Definition: avcodec.h:380
AV_FRAME_FLAG_CORRUPT
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition: frame.h:657
HEVCFrame
Definition: hevcdec.h:362
HEVC_MAX_REFS
@ HEVC_MAX_REFS
Definition: hevc.h:122
init_slice_rpl
static int init_slice_rpl(HEVCContext *s)
Definition: refs.c:324
HEVCLayerContext
Definition: hevcdec.h:454
RefPicList::list
int list[HEVC_MAX_REFS]
Definition: hevcdec.h:198
HEVCSEITDRDI::num_ref_displays
uint8_t num_ref_displays
Definition: sei.h:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:623
HEVCSPS::width
int width
Definition: ps.h:350
av_buffer_replace
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:233
SliceHeader::list_entry_lx
unsigned int list_entry_lx[2][32]
Definition: hevcdec.h:233
HEVCFrame::poc
int poc
Definition: hevcdec.h:375
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:669
SliceHeader::short_term_rps
const ShortTermRPS * short_term_rps
Definition: hevcdec.h:230
HEVCLayerContext::sps
const HEVCSPS * sps
Definition: hevcdec.h:458
ret
ret
Definition: filter_design.txt:187
ff_hevc_get_ref_list
const RefPicList * ff_hevc_get_ref_list(const HEVCFrame *ref, int x0, int y0)
Definition: refs.c:56
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
ST_CURR_BEF
@ ST_CURR_BEF
Definition: hevcdec.h:86
AVStereo3D::type
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:207
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
LongTermRPS
Definition: hevcdec.h:189
SliceHeader::slice_type
enum HEVCSliceType slice_type
Definition: hevcdec.h:215
LT_CURR
@ LT_CURR
Definition: hevcdec.h:89
HEVC_NAL_CRA_NUT
@ HEVC_NAL_CRA_NUT
Definition: hevc.h:50
av_refstruct_ref_c
const void * av_refstruct_ref_c(const void *obj)
Analog of av_refstruct_ref(), but for constant objects.
Definition: refstruct.c:149
av_frame_side_data_new
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: frame.c:842
NB_RPS_TYPE
@ NB_RPS_TYPE
Definition: hevcdec.h:93
HEVCContext
Definition: hevcdec.h:492
HEVCLayerContext::DPB
HEVCFrame DPB[32]
Definition: hevcdec.h:455
HEVCSPS::ctb_height
int ctb_height
Definition: ps.h:353
SliceHeader::rpl_modification_flag
uint8_t rpl_modification_flag[2]
Definition: hevcdec.h:235
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
HEVCWindow::right_offset
unsigned int right_offset
Definition: ps.h:93
alloc_frame
static HEVCFrame * alloc_frame(HEVCContext *s, HEVCLayerContext *l)
Definition: refs.c:109
ShortTermRPS
Definition: ps.h:75
SliceHeader::inter_layer_pred
uint8_t inter_layer_pred
RPS coded in the slice header itself is stored here.
Definition: hevcdec.h:224
HEVCSPS::ctb_width
int ctb_width
Definition: ps.h:352
mem.h
HEVCSPS::vshift
int vshift[3]
Definition: ps.h:364
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
HEVCVPS
Definition: ps.h:171
av_stereo3d_create_side_data
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition: stereo3d.c:54
HEVCSPS
Definition: ps.h:255
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:265
HEVCSPS::pixel_shift
int pixel_shift
Definition: ps.h:267
HEVCPPS
Definition: ps.h:374
ST_CURR_AFT
@ ST_CURR_AFT
Definition: hevcdec.h:87
AVStereo3D::view
enum AVStereo3DView view
Determines which views are packed.
Definition: stereo3d.h:217
LongTermRPS::nb_refs
uint8_t nb_refs
Definition: hevcdec.h:193
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ShortTermRPS::delta_poc
int32_t delta_poc[32]
Definition: ps.h:76
AVStereo3D
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition: stereo3d.h:203
HEVCLayerContext::rpl_tab_pool
struct AVRefStructPool * rpl_tab_pool
Definition: hevcdec.h:489
RefPicList::isLongTerm
int isLongTerm[HEVC_MAX_REFS]
Definition: hevcdec.h:199
ff_hevc_frame_nb_refs
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:613
SliceHeader::long_term_rps
LongTermRPS long_term_rps
Definition: hevcdec.h:232
INTER_LAYER1
@ INTER_LAYER1
Definition: hevcdec.h:92
AV_WN16
#define AV_WN16(p, v)
Definition: intreadwrite.h:368