FFmpeg
decode.c
Go to the documentation of this file.
1 /*
2  * generic decoding-related code
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <assert.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include <string.h>
25 
26 #include "config.h"
27 
28 #if CONFIG_ICONV
29 # include <iconv.h>
30 #endif
31 
32 #include "libavutil/avassert.h"
34 #include "libavutil/common.h"
35 #include "libavutil/emms.h"
36 #include "libavutil/frame.h"
37 #include "libavutil/hwcontext.h"
38 #include "libavutil/imgutils.h"
39 #include "libavutil/internal.h"
41 #include "libavutil/mem.h"
42 #include "libavutil/stereo3d.h"
43 
44 #include "avcodec.h"
45 #include "avcodec_internal.h"
46 #include "bytestream.h"
47 #include "bsf.h"
48 #include "codec_desc.h"
49 #include "codec_internal.h"
50 #include "decode.h"
51 #include "exif.h"
52 #include "exif_internal.h"
53 #include "hwaccel_internal.h"
54 #include "hwconfig.h"
55 #include "internal.h"
56 #include "lcevcdec.h"
57 #include "packet_internal.h"
58 #include "progressframe.h"
59 #include "libavutil/refstruct.h"
60 #include "thread.h"
61 #include "threadprogress.h"
62 
63 typedef struct DecodeContext {
65 
66  /**
67  * This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats
68  * (those whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set)
69  * to set the flag generically.
70  */
72 
73  /**
74  * This is set to AV_PICTURE_TYPE_I for intra only video decoders
75  * and to AV_PICTURE_TYPE_NONE for other decoders. It is used to set
76  * the AVFrame's pict_type before the decoder receives it.
77  */
79 
80  /* to prevent infinite loop on errors when draining */
82 
83  /**
84  * The caller has submitted a NULL packet on input.
85  */
87 
88  int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
89  int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
90  int64_t pts_correction_last_pts; /// PTS of the last frame
91  int64_t pts_correction_last_dts; /// DTS of the last frame
92 
93  /**
94  * Bitmask indicating for which side data types we prefer user-supplied
95  * (global or attached to packets) side data over bytestream.
96  */
98 
99 #if CONFIG_LIBLCEVC_DEC
100  struct {
102  int frame;
103  enum AVPixelFormat format;
104  int base_width;
105  int base_height;
106  int width;
107  int height;
108  } lcevc;
109 #endif
110 } DecodeContext;
111 
113 {
114  return (DecodeContext *)avci;
115 }
116 
117 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
118 {
119  int ret;
120  size_t size;
121  const uint8_t *data;
122  uint32_t flags;
123  int64_t val;
124 
126  if (!data)
127  return 0;
128 
129  if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) {
130  av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
131  "changes, but PARAM_CHANGE side data was sent to it.\n");
132  ret = AVERROR(EINVAL);
133  goto fail2;
134  }
135 
136  if (size < 4)
137  goto fail;
138 
139  flags = bytestream_get_le32(&data);
140  size -= 4;
141 
143  if (size < 4)
144  goto fail;
145  val = bytestream_get_le32(&data);
146  if (val <= 0 || val > INT_MAX) {
147  av_log(avctx, AV_LOG_ERROR, "Invalid sample rate");
149  goto fail2;
150  }
151  avctx->sample_rate = val;
152  size -= 4;
153  }
155  if (size < 8)
156  goto fail;
157  avctx->width = bytestream_get_le32(&data);
158  avctx->height = bytestream_get_le32(&data);
159  size -= 8;
160  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
161  if (ret < 0)
162  goto fail2;
163  }
164 
165  return 0;
166 fail:
167  av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
169 fail2:
170  if (ret < 0) {
171  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
172  if (avctx->err_recognition & AV_EF_EXPLODE)
173  return ret;
174  }
175  return 0;
176 }
177 
179 {
180  int ret = 0;
181 
183  if (pkt) {
185  }
186  return ret;
187 }
188 
190 {
191  AVCodecInternal *avci = avctx->internal;
192  const FFCodec *const codec = ffcodec(avctx->codec);
193  int ret;
194 
195  if (avci->bsf)
196  return 0;
197 
198  ret = av_bsf_list_parse_str(codec->bsfs, &avci->bsf);
199  if (ret < 0) {
200  av_log(avctx, AV_LOG_ERROR, "Error parsing decoder bitstream filters '%s': %s\n", codec->bsfs, av_err2str(ret));
201  if (ret != AVERROR(ENOMEM))
202  ret = AVERROR_BUG;
203  goto fail;
204  }
205 
206  /* We do not currently have an API for passing the input timebase into decoders,
207  * but no filters used here should actually need it.
208  * So we make up some plausible-looking number (the MPEG 90kHz timebase) */
209  avci->bsf->time_base_in = (AVRational){ 1, 90000 };
211  if (ret < 0)
212  goto fail;
213 
214  ret = av_bsf_init(avci->bsf);
215  if (ret < 0)
216  goto fail;
217 
218  return 0;
219 fail:
220  av_bsf_free(&avci->bsf);
221  return ret;
222 }
223 
224 #if !HAVE_THREADS
225 #define ff_thread_get_packet(avctx, pkt) (AVERROR_BUG)
226 #define ff_thread_receive_frame(avctx, frame, flags) (AVERROR_BUG)
227 #endif
228 
230 {
231  AVCodecInternal *avci = avctx->internal;
232  int ret;
233 
234  ret = av_bsf_receive_packet(avci->bsf, pkt);
235  if (ret < 0)
236  return ret;
237 
240  if (ret < 0)
241  goto finish;
242  }
243 
244  ret = apply_param_change(avctx, pkt);
245  if (ret < 0)
246  goto finish;
247 
248  return 0;
249 finish:
251  return ret;
252 }
253 
255 {
256  AVCodecInternal *avci = avctx->internal;
257  DecodeContext *dc = decode_ctx(avci);
258 
259  if (avci->draining)
260  return AVERROR_EOF;
261 
262  /* If we are a worker thread, get the next packet from the threading
263  * context. Otherwise we are the main (user-facing) context, so we get the
264  * next packet from the input filterchain.
265  */
266  if (avctx->internal->is_frame_mt)
267  return ff_thread_get_packet(avctx, pkt);
268 
269  while (1) {
270  int ret = decode_get_packet(avctx, pkt);
271  if (ret == AVERROR(EAGAIN) &&
272  (!AVPACKET_IS_EMPTY(avci->buffer_pkt) || dc->draining_started)) {
273  ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
274  if (ret >= 0)
275  continue;
276 
278  }
279 
280  if (ret == AVERROR_EOF)
281  avci->draining = 1;
282  return ret;
283  }
284 }
285 
286 /**
287  * Attempt to guess proper monotonic timestamps for decoded video frames
288  * which might have incorrect times. Input timestamps may wrap around, in
289  * which case the output will as well.
290  *
291  * @param pts the pts field of the decoded AVPacket, as passed through
292  * AVFrame.pts
293  * @param dts the dts field of the decoded AVPacket
294  * @return one of the input values, may be AV_NOPTS_VALUE
295  */
297  int64_t reordered_pts, int64_t dts)
298 {
300 
301  if (dts != AV_NOPTS_VALUE) {
302  dc->pts_correction_num_faulty_dts += dts <= dc->pts_correction_last_dts;
303  dc->pts_correction_last_dts = dts;
304  } else if (reordered_pts != AV_NOPTS_VALUE)
305  dc->pts_correction_last_dts = reordered_pts;
306 
307  if (reordered_pts != AV_NOPTS_VALUE) {
308  dc->pts_correction_num_faulty_pts += reordered_pts <= dc->pts_correction_last_pts;
309  dc->pts_correction_last_pts = reordered_pts;
310  } else if(dts != AV_NOPTS_VALUE)
311  dc->pts_correction_last_pts = dts;
312 
313  if ((dc->pts_correction_num_faulty_pts<=dc->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
314  && reordered_pts != AV_NOPTS_VALUE)
315  pts = reordered_pts;
316  else
317  pts = dts;
318 
319  return pts;
320 }
321 
322 static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
323 {
324  AVCodecInternal *avci = avctx->internal;
325  AVFrameSideData *side;
326  uint32_t discard_padding = 0;
327  uint8_t skip_reason = 0;
328  uint8_t discard_reason = 0;
329 
331  if (side && side->size >= 10) {
332  int skip_samples = AV_RL32(side->data);
333  if (skip_samples)
334  avci->skip_samples = skip_samples;
335  avci->skip_samples = FFMAX(0, avci->skip_samples);
336  discard_padding = AV_RL32(side->data + 4);
337  av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
338  avci->skip_samples, (int)discard_padding);
339  skip_reason = AV_RL8(side->data + 8);
340  discard_reason = AV_RL8(side->data + 9);
341  }
342 
343  if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
344  if (!side && (avci->skip_samples || discard_padding))
346  if (side && (avci->skip_samples || discard_padding)) {
347  AV_WL32(side->data, avci->skip_samples);
348  AV_WL32(side->data + 4, discard_padding);
349  AV_WL8(side->data + 8, skip_reason);
350  AV_WL8(side->data + 9, discard_reason);
351  avci->skip_samples = 0;
352  }
353  return 0;
354  }
356 
357  if ((frame->flags & AV_FRAME_FLAG_DISCARD)) {
358  avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
359  *discarded_samples += frame->nb_samples;
360  return AVERROR(EAGAIN);
361  }
362 
363  if (avci->skip_samples > 0) {
364  if (frame->nb_samples <= avci->skip_samples){
365  *discarded_samples += frame->nb_samples;
366  avci->skip_samples -= frame->nb_samples;
367  av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
368  avci->skip_samples);
369  return AVERROR(EAGAIN);
370  } else {
371  av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
372  frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
373  if (avctx->pkt_timebase.num && avctx->sample_rate) {
374  int64_t diff_ts = av_rescale_q(avci->skip_samples,
375  (AVRational){1, avctx->sample_rate},
376  avctx->pkt_timebase);
377  if (diff_ts != AV_NOPTS_VALUE) {
378  if (frame->pts != AV_NOPTS_VALUE)
379  frame->pts = av_sat_add64(frame->pts, diff_ts);
380  if (frame->pkt_dts != AV_NOPTS_VALUE)
381  frame->pkt_dts = av_sat_add64(frame->pkt_dts, diff_ts);
382  if (frame->duration >= diff_ts)
383  frame->duration = av_sat_sub64(frame->duration, diff_ts);
384  } else {
385  frame->pts = AV_NOPTS_VALUE;
386  frame->pkt_dts = AV_NOPTS_VALUE;
387  frame->duration = 0;
388  }
389  } else
390  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
391 
392  av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
393  avci->skip_samples, frame->nb_samples);
394  *discarded_samples += avci->skip_samples;
395  frame->nb_samples -= avci->skip_samples;
396  avci->skip_samples = 0;
397  }
398  }
399 
400  if (discard_padding > 0 && discard_padding <= frame->nb_samples) {
401  if (discard_padding == frame->nb_samples) {
402  *discarded_samples += frame->nb_samples;
403  return AVERROR(EAGAIN);
404  } else {
405  if (avctx->pkt_timebase.num && avctx->sample_rate) {
406  int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
407  (AVRational){1, avctx->sample_rate},
408  avctx->pkt_timebase);
409  frame->duration = diff_ts == AV_NOPTS_VALUE ? 0 : diff_ts;
410  } else
411  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
412 
413  av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
414  (int)discard_padding, frame->nb_samples);
415  frame->nb_samples -= discard_padding;
416  }
417  }
418 
419  return 0;
420 }
421 
422 /*
423  * The core of the receive_frame_wrapper for the decoders implementing
424  * the simple API. Certain decoders might consume partial packets without
425  * returning any output, so this function needs to be called in a loop until it
426  * returns EAGAIN.
427  **/
428 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
429 {
430  AVCodecInternal *avci = avctx->internal;
431  DecodeContext *dc = decode_ctx(avci);
432  AVPacket *const pkt = avci->in_pkt;
433  const FFCodec *const codec = ffcodec(avctx->codec);
434  int got_frame, consumed;
435  int ret;
436 
437  if (!pkt->data && !avci->draining) {
439  ret = ff_decode_get_packet(avctx, pkt);
440  if (ret < 0 && ret != AVERROR_EOF)
441  return ret;
442  }
443 
444  // Some codecs (at least wma lossless) will crash when feeding drain packets
445  // after EOF was signaled.
446  if (avci->draining_done)
447  return AVERROR_EOF;
448 
449  if (!pkt->data &&
451  return AVERROR_EOF;
452 
453  got_frame = 0;
454 
455  frame->pict_type = dc->initial_pict_type;
456  frame->flags |= dc->intra_only_flag;
457  consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
458 
460  frame->pkt_dts = pkt->dts;
461  emms_c();
462 
463  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
464  ret = (!got_frame || frame->flags & AV_FRAME_FLAG_DISCARD)
465  ? AVERROR(EAGAIN)
466  : 0;
467  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
468  ret = !got_frame ? AVERROR(EAGAIN)
469  : discard_samples(avctx, frame, discarded_samples);
470  } else
471  av_assert0(0);
472 
473  if (ret == AVERROR(EAGAIN))
475 
476  // FF_CODEC_CB_TYPE_DECODE decoders must not return AVERROR EAGAIN
477  // code later will add AVERROR(EAGAIN) to a pointer
478  av_assert0(consumed != AVERROR(EAGAIN));
479  if (consumed < 0)
480  ret = consumed;
481  if (consumed >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
482  consumed = pkt->size;
483 
484  if (!ret)
485  av_assert0(frame->buf[0]);
486  if (ret == AVERROR(EAGAIN))
487  ret = 0;
488 
489  /* do not stop draining when got_frame != 0 or ret < 0 */
490  if (avci->draining && !got_frame) {
491  if (ret < 0) {
492  /* prevent infinite loop if a decoder wrongly always return error on draining */
493  /* reasonable nb_errors_max = maximum b frames + thread count */
494  int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
495  avctx->thread_count : 1);
496 
497  if (decode_ctx(avci)->nb_draining_errors++ >= nb_errors_max) {
498  av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
499  "Stop draining and force EOF.\n");
500  avci->draining_done = 1;
501  ret = AVERROR_BUG;
502  }
503  } else {
504  avci->draining_done = 1;
505  }
506  }
507 
508  if (consumed >= pkt->size || ret < 0) {
510  } else {
511  pkt->data += consumed;
512  pkt->size -= consumed;
518  }
519  }
520 
521  return ret;
522 }
523 
524 #if CONFIG_LCMS2
525 static int detect_colorspace(AVCodecContext *avctx, AVFrame *frame)
526 {
527  AVCodecInternal *avci = avctx->internal;
529  AVColorPrimariesDesc coeffs;
530  enum AVColorPrimaries prim;
531  cmsHPROFILE profile;
532  AVFrameSideData *sd;
533  int ret;
534  if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
535  return 0;
536 
538  if (!sd || !sd->size)
539  return 0;
540 
541  if (!avci->icc.avctx) {
542  ret = ff_icc_context_init(&avci->icc, avctx);
543  if (ret < 0)
544  return ret;
545  }
546 
547  profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size);
548  if (!profile)
549  return AVERROR_INVALIDDATA;
550 
551  ret = ff_icc_profile_sanitize(&avci->icc, profile);
552  if (!ret)
553  ret = ff_icc_profile_read_primaries(&avci->icc, profile, &coeffs);
554  if (!ret)
555  ret = ff_icc_profile_detect_transfer(&avci->icc, profile, &trc);
556  cmsCloseProfile(profile);
557  if (ret < 0)
558  return ret;
559 
560  prim = av_csp_primaries_id_from_desc(&coeffs);
561  if (prim != AVCOL_PRI_UNSPECIFIED)
562  frame->color_primaries = prim;
563  if (trc != AVCOL_TRC_UNSPECIFIED)
564  frame->color_trc = trc;
565  return 0;
566 }
567 #else /* !CONFIG_LCMS2 */
569 {
570  return 0;
571 }
572 #endif
573 
574 static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
575 {
576  int ret;
577 
578  if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
579  frame->color_primaries = avctx->color_primaries;
580  if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
581  frame->color_trc = avctx->color_trc;
582  if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
583  frame->colorspace = avctx->colorspace;
584  if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
585  frame->color_range = avctx->color_range;
586  if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
587  frame->chroma_location = avctx->chroma_sample_location;
588  if (frame->alpha_mode == AVALPHA_MODE_UNSPECIFIED)
589  frame->alpha_mode = avctx->alpha_mode;
590 
591  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
592  if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
593  if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
594  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
595  if (frame->format == AV_SAMPLE_FMT_NONE)
596  frame->format = avctx->sample_fmt;
597  if (!frame->ch_layout.nb_channels) {
598  ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
599  if (ret < 0)
600  return ret;
601  }
602  if (!frame->sample_rate)
603  frame->sample_rate = avctx->sample_rate;
604  }
605 
606  return 0;
607 }
608 
610 {
611  int ret;
612  int64_t discarded_samples = 0;
613 
614  while (!frame->buf[0]) {
615  if (discarded_samples > avctx->max_samples)
616  return AVERROR(EAGAIN);
617  ret = decode_simple_internal(avctx, frame, &discarded_samples);
618  if (ret < 0)
619  return ret;
620  }
621 
622  return 0;
623 }
624 
626 {
627  AVCodecInternal *avci = avctx->internal;
628  DecodeContext *dc = decode_ctx(avci);
629  const FFCodec *const codec = ffcodec(avctx->codec);
630  int ret;
631 
632  av_assert0(!frame->buf[0]);
633 
634  if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
635  while (1) {
636  frame->pict_type = dc->initial_pict_type;
637  frame->flags |= dc->intra_only_flag;
638  ret = codec->cb.receive_frame(avctx, frame);
639  emms_c();
640  if (!ret) {
641  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
642  int64_t discarded_samples = 0;
643  ret = discard_samples(avctx, frame, &discarded_samples);
644  }
645  if (ret == AVERROR(EAGAIN) || (frame->flags & AV_FRAME_FLAG_DISCARD)) {
647  continue;
648  }
649  }
650  break;
651  }
652  } else
654 
655  if (ret == AVERROR_EOF)
656  avci->draining_done = 1;
657 
658  return ret;
659 }
660 
662  unsigned flags)
663 {
664  AVCodecInternal *avci = avctx->internal;
665  DecodeContext *dc = decode_ctx(avci);
666  int ret, ok;
667 
668  if (avctx->active_thread_type & FF_THREAD_FRAME)
670  else
672 
673  /* preserve ret */
674  ok = detect_colorspace(avctx, frame);
675  if (ok < 0) {
677  return ok;
678  }
679 
680  if (!ret) {
681  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
682  if (!frame->width)
683  frame->width = avctx->width;
684  if (!frame->height)
685  frame->height = avctx->height;
686  }
687 
688  ret = fill_frame_props(avctx, frame);
689  if (ret < 0) {
691  return ret;
692  }
693 
694  frame->best_effort_timestamp = guess_correct_pts(dc,
695  frame->pts,
696  frame->pkt_dts);
697 
698  /* the only case where decode data is not set should be decoders
699  * that do not call ff_get_buffer() */
700  av_assert0(frame->private_ref ||
701  !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
702 
703  if (frame->private_ref) {
704  FrameDecodeData *fdd = frame->private_ref;
705 
706  if (fdd->hwaccel_priv_post_process) {
707  ret = fdd->hwaccel_priv_post_process(avctx, frame);
708  if (ret < 0) {
710  return ret;
711  }
712  }
713 
714  if (fdd->post_process) {
715  ret = fdd->post_process(avctx, frame);
716  if (ret < 0) {
718  return ret;
719  }
720  }
721  }
722  }
723 
724  /* free the per-frame decode data */
725  av_refstruct_unref(&frame->private_ref);
726 
727  return ret;
728 }
729 
731 {
732  AVCodecInternal *avci = avctx->internal;
733  DecodeContext *dc = decode_ctx(avci);
734  int ret;
735 
736  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
737  return AVERROR(EINVAL);
738 
739  if (dc->draining_started)
740  return AVERROR_EOF;
741 
742  if (avpkt && !avpkt->size && avpkt->data)
743  return AVERROR(EINVAL);
744 
745  if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
746  if (!AVPACKET_IS_EMPTY(avci->buffer_pkt))
747  return AVERROR(EAGAIN);
748  ret = av_packet_ref(avci->buffer_pkt, avpkt);
749  if (ret < 0)
750  return ret;
751  } else
752  dc->draining_started = 1;
753 
754  if (!avci->buffer_frame->buf[0] && !dc->draining_started) {
756  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
757  return ret;
758  }
759 
760  return 0;
761 }
762 
764 {
765  /* make sure we are noisy about decoders returning invalid cropping data */
766  if (frame->crop_left >= INT_MAX - frame->crop_right ||
767  frame->crop_top >= INT_MAX - frame->crop_bottom ||
768  (frame->crop_left + frame->crop_right) >= frame->width ||
769  (frame->crop_top + frame->crop_bottom) >= frame->height) {
770  av_log(avctx, AV_LOG_WARNING,
771  "Invalid cropping information set by a decoder: "
772  "%zu/%zu/%zu/%zu (frame size %dx%d). "
773  "This is a bug, please report it\n",
774  frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
775  frame->width, frame->height);
776  frame->crop_left = 0;
777  frame->crop_right = 0;
778  frame->crop_top = 0;
779  frame->crop_bottom = 0;
780  return 0;
781  }
782 
783  if (!avctx->apply_cropping)
784  return 0;
785 
788 }
789 
790 // make sure frames returned to the caller are valid
792 {
793  if (!frame->buf[0] || frame->format < 0)
794  goto fail;
795 
796  switch (avctx->codec_type) {
797  case AVMEDIA_TYPE_VIDEO:
798  if (frame->width <= 0 || frame->height <= 0)
799  goto fail;
800  break;
801  case AVMEDIA_TYPE_AUDIO:
802  if (!av_channel_layout_check(&frame->ch_layout) ||
803  frame->sample_rate <= 0)
804  goto fail;
805 
806  break;
807  default: av_assert0(0);
808  }
809 
810  return 0;
811 fail:
812  av_log(avctx, AV_LOG_ERROR, "An invalid frame was output by a decoder. "
813  "This is a bug, please report it.\n");
814  return AVERROR_BUG;
815 }
816 
818 {
819  AVCodecInternal *avci = avctx->internal;
820  int ret;
821 
822  if (avci->buffer_frame->buf[0]) {
824  } else {
826  if (ret < 0)
827  return ret;
828  }
829 
830  ret = frame_validate(avctx, frame);
831  if (ret < 0)
832  goto fail;
833 
834  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
835  ret = apply_cropping(avctx, frame);
836  if (ret < 0)
837  goto fail;
838  }
839 
840  avctx->frame_num++;
841 
842  return 0;
843 fail:
845  return ret;
846 }
847 
849 {
850  memset(sub, 0, sizeof(*sub));
851  sub->pts = AV_NOPTS_VALUE;
852 }
853 
854 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
855 static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt,
856  const AVPacket *inpkt, AVPacket *buf_pkt)
857 {
858 #if CONFIG_ICONV
859  iconv_t cd = (iconv_t)-1;
860  int ret = 0;
861  char *inb, *outb;
862  size_t inl, outl;
863 #endif
864 
865  if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) {
866  *outpkt = inpkt;
867  return 0;
868  }
869 
870 #if CONFIG_ICONV
871  inb = inpkt->data;
872  inl = inpkt->size;
873 
874  if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) {
875  av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
876  return AVERROR(ERANGE);
877  }
878 
879  cd = iconv_open("UTF-8", avctx->sub_charenc);
880  av_assert0(cd != (iconv_t)-1);
881 
882  ret = av_new_packet(buf_pkt, inl * UTF8_MAX_BYTES);
883  if (ret < 0)
884  goto end;
885  ret = av_packet_copy_props(buf_pkt, inpkt);
886  if (ret < 0)
887  goto end;
888  outb = buf_pkt->data;
889  outl = buf_pkt->size;
890 
891  if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
892  iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
893  outl >= buf_pkt->size || inl != 0) {
894  ret = FFMIN(AVERROR(errno), -1);
895  av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
896  "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
897  goto end;
898  }
899  buf_pkt->size -= outl;
900  memset(buf_pkt->data + buf_pkt->size, 0, outl);
901  *outpkt = buf_pkt;
902 
903  ret = 0;
904 end:
905  if (ret < 0)
906  av_packet_unref(buf_pkt);
907  if (cd != (iconv_t)-1)
908  iconv_close(cd);
909  return ret;
910 #else
911  av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
912  return AVERROR(EINVAL);
913 #endif
914 }
915 
916 static int utf8_check(const uint8_t *str)
917 {
918  const uint8_t *byte;
919  uint32_t codepoint, min;
920 
921  while (*str) {
922  byte = str;
923  GET_UTF8(codepoint, *(byte++), return 0;);
924  min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
925  1 << (5 * (byte - str) - 4);
926  if (codepoint < min || codepoint >= 0x110000 ||
927  codepoint == 0xFFFE /* BOM */ ||
928  codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
929  return 0;
930  str = byte;
931  }
932  return 1;
933 }
934 
936  int *got_sub_ptr, const AVPacket *avpkt)
937 {
938  int ret = 0;
939 
940  if (!avpkt->data && avpkt->size) {
941  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
942  return AVERROR(EINVAL);
943  }
944  if (!avctx->codec)
945  return AVERROR(EINVAL);
947  av_log(avctx, AV_LOG_ERROR, "Codec not subtitle decoder\n");
948  return AVERROR(EINVAL);
949  }
950 
951  *got_sub_ptr = 0;
953 
954  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
955  AVCodecInternal *avci = avctx->internal;
956  const AVPacket *pkt;
957 
958  ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
959  if (ret < 0)
960  return ret;
961 
962  if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
963  sub->pts = av_rescale_q(avpkt->pts,
964  avctx->pkt_timebase, AV_TIME_BASE_Q);
965  ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
966  if (pkt == avci->buffer_pkt) // did we recode?
968  if (ret < 0) {
969  *got_sub_ptr = 0;
970  avsubtitle_free(sub);
971  return ret;
972  }
973  av_assert1(!sub->num_rects || *got_sub_ptr);
974 
975  if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
976  avctx->pkt_timebase.num) {
977  AVRational ms = { 1, 1000 };
978  sub->end_display_time = av_rescale_q(avpkt->duration,
979  avctx->pkt_timebase, ms);
980  }
981 
983  sub->format = 0;
984  else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
985  sub->format = 1;
986 
987  for (unsigned i = 0; i < sub->num_rects; i++) {
989  sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
990  av_log(avctx, AV_LOG_ERROR,
991  "Invalid UTF-8 in decoded subtitles text; "
992  "maybe missing -sub_charenc option\n");
993  avsubtitle_free(sub);
994  *got_sub_ptr = 0;
995  return AVERROR_INVALIDDATA;
996  }
997  }
998 
999  if (*got_sub_ptr)
1000  avctx->frame_num++;
1001  }
1002 
1003  return ret;
1004 }
1005 
1007  const enum AVPixelFormat *fmt)
1008 {
1009  const AVCodecHWConfig *config;
1010  int i, n;
1011 
1012  // If a device was supplied when the codec was opened, assume that the
1013  // user wants to use it.
1014  if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
1015  AVHWDeviceContext *device_ctx =
1017  for (i = 0;; i++) {
1018  config = &ffcodec(avctx->codec)->hw_configs[i]->public;
1019  if (!config)
1020  break;
1021  if (!(config->methods &
1023  continue;
1024  if (device_ctx->type != config->device_type)
1025  continue;
1026  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1027  if (config->pix_fmt == fmt[n])
1028  return fmt[n];
1029  }
1030  }
1031  }
1032  // No device or other setup, so we have to choose from things which
1033  // don't any other external information.
1034 
1035  // Choose the first software format
1036  // (this should be best software format if any exist).
1037  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1038  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt[n]);
1039  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1040  return fmt[n];
1041  }
1042 
1043  // Finally, traverse the list in order and choose the first entry
1044  // with no external dependencies (if there is no hardware configuration
1045  // information available then this just picks the first entry).
1046  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1047  for (i = 0;; i++) {
1048  config = avcodec_get_hw_config(avctx->codec, i);
1049  if (!config)
1050  break;
1051  if (config->pix_fmt == fmt[n])
1052  break;
1053  }
1054  if (!config) {
1055  // No specific config available, so the decoder must be able
1056  // to handle this format without any additional setup.
1057  return fmt[n];
1058  }
1059  if (config->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
1060  // Usable with only internal setup.
1061  return fmt[n];
1062  }
1063  }
1064 
1065  // Nothing is usable, give up.
1066  return AV_PIX_FMT_NONE;
1067 }
1068 
1070  enum AVHWDeviceType dev_type)
1071 {
1072  AVHWDeviceContext *device_ctx;
1073  AVHWFramesContext *frames_ctx;
1074  int ret;
1075 
1076  if (!avctx->hwaccel)
1077  return AVERROR(ENOSYS);
1078 
1079  if (avctx->hw_frames_ctx)
1080  return 0;
1081  if (!avctx->hw_device_ctx) {
1082  av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
1083  "required for hardware accelerated decoding.\n");
1084  return AVERROR(EINVAL);
1085  }
1086 
1087  device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data;
1088  if (device_ctx->type != dev_type) {
1089  av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware "
1090  "decoding, but got %s.\n", av_hwdevice_get_type_name(dev_type),
1091  av_hwdevice_get_type_name(device_ctx->type));
1092  return AVERROR(EINVAL);
1093  }
1094 
1096  avctx->hw_device_ctx,
1097  avctx->hwaccel->pix_fmt,
1098  &avctx->hw_frames_ctx);
1099  if (ret < 0)
1100  return ret;
1101 
1102  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1103 
1104 
1105  if (frames_ctx->initial_pool_size) {
1106  // We guarantee 4 base work surfaces. The function above guarantees 1
1107  // (the absolute minimum), so add the missing count.
1108  frames_ctx->initial_pool_size += 3;
1109  }
1110 
1112  if (ret < 0) {
1113  av_buffer_unref(&avctx->hw_frames_ctx);
1114  return ret;
1115  }
1116 
1117  return 0;
1118 }
1119 
1121  AVBufferRef *device_ref,
1123  AVBufferRef **out_frames_ref)
1124 {
1125  AVBufferRef *frames_ref = NULL;
1126  const AVCodecHWConfigInternal *hw_config;
1127  const FFHWAccel *hwa;
1128  int i, ret;
1129  bool clean_priv_data = false;
1130 
1131  for (i = 0;; i++) {
1132  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1133  if (!hw_config)
1134  return AVERROR(ENOENT);
1135  if (hw_config->public.pix_fmt == hw_pix_fmt)
1136  break;
1137  }
1138 
1139  hwa = hw_config->hwaccel;
1140  if (!hwa || !hwa->frame_params)
1141  return AVERROR(ENOENT);
1142 
1143  frames_ref = av_hwframe_ctx_alloc(device_ref);
1144  if (!frames_ref)
1145  return AVERROR(ENOMEM);
1146 
1147  if (!avctx->internal->hwaccel_priv_data) {
1148  avctx->internal->hwaccel_priv_data =
1149  av_mallocz(hwa->priv_data_size);
1150  if (!avctx->internal->hwaccel_priv_data) {
1151  av_buffer_unref(&frames_ref);
1152  return AVERROR(ENOMEM);
1153  }
1154  clean_priv_data = true;
1155  }
1156 
1157  ret = hwa->frame_params(avctx, frames_ref);
1158  if (ret >= 0) {
1159  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
1160 
1161  if (frames_ctx->initial_pool_size) {
1162  // If the user has requested that extra output surfaces be
1163  // available then add them here.
1164  if (avctx->extra_hw_frames > 0)
1165  frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1166 
1167  // If frame threading is enabled then an extra surface per thread
1168  // is also required.
1169  if (avctx->active_thread_type & FF_THREAD_FRAME)
1170  frames_ctx->initial_pool_size += avctx->thread_count;
1171  }
1172 
1173  *out_frames_ref = frames_ref;
1174  } else {
1175  if (clean_priv_data)
1177  av_buffer_unref(&frames_ref);
1178  }
1179  return ret;
1180 }
1181 
1182 static int hwaccel_init(AVCodecContext *avctx,
1183  const FFHWAccel *hwaccel)
1184 {
1185  int err;
1186 
1187  if (hwaccel->p.capabilities & AV_HWACCEL_CODEC_CAP_EXPERIMENTAL &&
1189  av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1190  hwaccel->p.name);
1191  return AVERROR_PATCHWELCOME;
1192  }
1193 
1194  if (!avctx->internal->hwaccel_priv_data && hwaccel->priv_data_size) {
1195  avctx->internal->hwaccel_priv_data =
1196  av_mallocz(hwaccel->priv_data_size);
1197  if (!avctx->internal->hwaccel_priv_data)
1198  return AVERROR(ENOMEM);
1199  }
1200 
1201  avctx->hwaccel = &hwaccel->p;
1202  if (hwaccel->init) {
1203  err = hwaccel->init(avctx);
1204  if (err < 0) {
1205  av_log(avctx, AV_LOG_ERROR, "Failed setup for format %s: "
1206  "hwaccel initialisation returned error.\n",
1207  av_get_pix_fmt_name(hwaccel->p.pix_fmt));
1209  avctx->hwaccel = NULL;
1210  return err;
1211  }
1212  }
1213 
1214  return 0;
1215 }
1216 
1218 {
1219  if (FF_HW_HAS_CB(avctx, uninit))
1220  FF_HW_SIMPLE_CALL(avctx, uninit);
1221 
1223 
1224  avctx->hwaccel = NULL;
1225 
1226  av_buffer_unref(&avctx->hw_frames_ctx);
1227 }
1228 
1229 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1230 {
1231  const AVPixFmtDescriptor *desc;
1232  enum AVPixelFormat *choices;
1233  enum AVPixelFormat ret, user_choice;
1234  const AVCodecHWConfigInternal *hw_config;
1235  const AVCodecHWConfig *config;
1236  int i, n, err;
1237 
1238  // Find end of list.
1239  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1240  // Must contain at least one entry.
1241  av_assert0(n >= 1);
1242  // If a software format is available, it must be the last entry.
1243  desc = av_pix_fmt_desc_get(fmt[n - 1]);
1244  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1245  // No software format is available.
1246  } else {
1247  avctx->sw_pix_fmt = fmt[n - 1];
1248  }
1249 
1250  choices = av_memdup(fmt, (n + 1) * sizeof(*choices));
1251  if (!choices)
1252  return AV_PIX_FMT_NONE;
1253 
1254  for (;;) {
1255  // Remove the previous hwaccel, if there was one.
1256  ff_hwaccel_uninit(avctx);
1257 
1258  user_choice = avctx->get_format(avctx, choices);
1259  if (user_choice == AV_PIX_FMT_NONE) {
1260  // Explicitly chose nothing, give up.
1261  ret = AV_PIX_FMT_NONE;
1262  break;
1263  }
1264 
1265  desc = av_pix_fmt_desc_get(user_choice);
1266  if (!desc) {
1267  av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
1268  "get_format() callback.\n");
1269  ret = AV_PIX_FMT_NONE;
1270  break;
1271  }
1272  av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
1273  desc->name);
1274 
1275  for (i = 0; i < n; i++) {
1276  if (choices[i] == user_choice)
1277  break;
1278  }
1279  if (i == n) {
1280  av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
1281  "%s not in possible list.\n", desc->name);
1282  ret = AV_PIX_FMT_NONE;
1283  break;
1284  }
1285 
1286  if (ffcodec(avctx->codec)->hw_configs) {
1287  for (i = 0;; i++) {
1288  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1289  if (!hw_config)
1290  break;
1291  if (hw_config->public.pix_fmt == user_choice)
1292  break;
1293  }
1294  } else {
1295  hw_config = NULL;
1296  }
1297 
1298  if (!hw_config) {
1299  // No config available, so no extra setup required.
1300  ret = user_choice;
1301  break;
1302  }
1303  config = &hw_config->public;
1304 
1305  if (config->methods &
1307  avctx->hw_frames_ctx) {
1308  const AVHWFramesContext *frames_ctx =
1310  if (frames_ctx->format != user_choice) {
1311  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1312  "does not match the format of the provided frames "
1313  "context.\n", desc->name);
1314  goto try_again;
1315  }
1316  } else if (config->methods &
1318  avctx->hw_device_ctx) {
1319  const AVHWDeviceContext *device_ctx =
1321  if (device_ctx->type != config->device_type) {
1322  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1323  "does not match the type of the provided device "
1324  "context.\n", desc->name);
1325  goto try_again;
1326  }
1327  } else if (config->methods &
1329  // Internal-only setup, no additional configuration.
1330  } else if (config->methods &
1332  // Some ad-hoc configuration we can't see and can't check.
1333  } else {
1334  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1335  "missing configuration.\n", desc->name);
1336  goto try_again;
1337  }
1338  if (hw_config->hwaccel) {
1339  av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel %s "
1340  "initialisation.\n", desc->name, hw_config->hwaccel->p.name);
1341  err = hwaccel_init(avctx, hw_config->hwaccel);
1342  if (err < 0)
1343  goto try_again;
1344  }
1345  ret = user_choice;
1346  break;
1347 
1348  try_again:
1349  av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
1350  "get_format() without it.\n", desc->name);
1351  for (i = 0; i < n; i++) {
1352  if (choices[i] == user_choice)
1353  break;
1354  }
1355  for (; i + 1 < n; i++)
1356  choices[i] = choices[i + 1];
1357  --n;
1358  }
1359 
1360  if (ret < 0)
1361  ff_hwaccel_uninit(avctx);
1362 
1363  av_freep(&choices);
1364  return ret;
1365 }
1366 
1367 static const AVPacketSideData*
1370 {
1371  for (int i = 0; i < nb_sd; i++)
1372  if (sd[i].type == type)
1373  return &sd[i];
1374 
1375  return NULL;
1376 }
1377 
1380 {
1382 }
1383 
1385  const AVPacketSideData *sd_pkt)
1386 {
1387  const AVStereo3D *src;
1388  AVStereo3D *dst;
1389  int ret;
1390 
1391  ret = av_buffer_make_writable(&sd_frame->buf);
1392  if (ret < 0)
1393  return ret;
1394  sd_frame->data = sd_frame->buf->data;
1395 
1396  dst = ( AVStereo3D*)sd_frame->data;
1397  src = (const AVStereo3D*)sd_pkt->data;
1398 
1399  if (dst->type == AV_STEREO3D_UNSPEC)
1400  dst->type = src->type;
1401 
1402  if (dst->view == AV_STEREO3D_VIEW_UNSPEC)
1403  dst->view = src->view;
1404 
1405  if (dst->primary_eye == AV_PRIMARY_EYE_NONE)
1406  dst->primary_eye = src->primary_eye;
1407 
1408  if (!dst->baseline)
1409  dst->baseline = src->baseline;
1410 
1411  if (!dst->horizontal_disparity_adjustment.num)
1412  dst->horizontal_disparity_adjustment = src->horizontal_disparity_adjustment;
1413 
1414  if (!dst->horizontal_field_of_view.num)
1415  dst->horizontal_field_of_view = src->horizontal_field_of_view;
1416 
1417  return 0;
1418 }
1419 
1421 {
1422  AVExifMetadata ifd = { 0 };
1423  AVExifEntry *entry = NULL;
1424  AVBufferRef *buf = NULL;
1425  AVFrameSideData *sd_frame;
1426  int ret;
1427 
1428  ret = av_exif_parse_buffer(NULL, sd_pkt->data, sd_pkt->size, &ifd,
1430  if (ret < 0)
1431  return ret;
1432 
1433  ret = av_exif_get_entry(NULL, &ifd, av_exif_get_tag_id("Orientation"), 0, &entry);
1434  if (ret < 0)
1435  goto end;
1436 
1437  if (!entry) {
1438  ret = av_exif_ifd_to_dict(NULL, &ifd, &dst->metadata);
1439  if (ret < 0)
1440  goto end;
1441 
1442  sd_frame = av_frame_side_data_new(&dst->side_data, &dst->nb_side_data, AV_FRAME_DATA_EXIF,
1443  sd_pkt->size, 0);
1444  if (sd_frame)
1445  memcpy(sd_frame->data, sd_pkt->data, sd_pkt->size);
1446  ret = sd_frame ? 0 : AVERROR(ENOMEM);
1447 
1448  goto end;
1449  } else if (entry->count <= 0 || entry->type != AV_TIFF_SHORT) {
1451  goto end;
1452  }
1453 
1454  // If a display matrix already exists in the frame, give it priority
1455  if (av_frame_side_data_get(dst->side_data, dst->nb_side_data, AV_FRAME_DATA_DISPLAYMATRIX))
1456  goto finish;
1457 
1458  sd_frame = av_frame_side_data_new(&dst->side_data, &dst->nb_side_data, AV_FRAME_DATA_DISPLAYMATRIX,
1459  sizeof(int32_t) * 9, 0);
1460  if (!sd_frame) {
1461  ret = AVERROR(ENOMEM);
1462  goto end;
1463  }
1464 
1465  ret = av_exif_orientation_to_matrix((int32_t *)sd_frame->data, entry->value.uint[0]);
1466  if (ret < 0)
1467  goto end;
1468 
1469 finish:
1470  av_exif_remove_entry(NULL, &ifd, entry->id, 0);
1471 
1472  ret = av_exif_ifd_to_dict(NULL, &ifd, &dst->metadata);
1473  if (ret < 0)
1474  goto end;
1475 
1476  ret = av_exif_write(NULL, &ifd, &buf, AV_EXIF_TIFF_HEADER);
1477  if (ret < 0)
1478  goto end;
1479 
1480  if (!av_frame_side_data_add(&dst->side_data, &dst->nb_side_data, AV_FRAME_DATA_EXIF, &buf, 0)) {
1481  ret = AVERROR(ENOMEM);
1482  goto end;
1483  }
1484 
1485  ret = 0;
1486 end:
1487  av_buffer_unref(&buf);
1488  av_exif_free(&ifd);
1489  return ret;
1490 }
1491 
1493  const AVPacketSideData *sd_src, int nb_sd_src,
1494  const SideDataMap *map)
1495 
1496 {
1497  for (int i = 0; map[i].packet < AV_PKT_DATA_NB; i++) {
1498  const enum AVPacketSideDataType type_pkt = map[i].packet;
1499  const enum AVFrameSideDataType type_frame = map[i].frame;
1500  const AVPacketSideData *sd_pkt;
1501  AVFrameSideData *sd_frame;
1502 
1503  sd_pkt = packet_side_data_get(sd_src, nb_sd_src, type_pkt);
1504  if (!sd_pkt)
1505  continue;
1506 
1507  sd_frame = av_frame_get_side_data(dst, type_frame);
1508  if (sd_frame) {
1509  if (type_frame == AV_FRAME_DATA_STEREO3D) {
1510  int ret = side_data_stereo3d_merge(sd_frame, sd_pkt);
1511  if (ret < 0)
1512  return ret;
1513  }
1514 
1515  continue;
1516  }
1517 
1518  switch (type_pkt) {
1519  case AV_PKT_DATA_EXIF: {
1520  int ret = side_data_exif_parse(dst, sd_pkt);
1521  if (ret < 0)
1522  return ret;
1523  break;
1524  }
1525  default:
1526  sd_frame = av_frame_new_side_data(dst, type_frame, sd_pkt->size);
1527  if (!sd_frame)
1528  return AVERROR(ENOMEM);
1529 
1530  memcpy(sd_frame->data, sd_pkt->data, sd_pkt->size);
1531  break;
1532  }
1533  }
1534 
1535  return 0;
1536 }
1537 
1539 {
1540  size_t size;
1541  const uint8_t *side_metadata;
1542 
1543  AVDictionary **frame_md = &frame->metadata;
1544 
1545  side_metadata = av_packet_get_side_data(avpkt,
1547  return av_packet_unpack_dictionary(side_metadata, size, frame_md);
1548 }
1549 
1551  AVFrame *frame, const AVPacket *pkt)
1552 {
1553  static const SideDataMap sd[] = {
1564  { AV_PKT_DATA_NB }
1565  };
1566 
1567  int ret = 0;
1568 
1569  frame->pts = pkt->pts;
1570  frame->duration = pkt->duration;
1571 
1572  if (pkt->side_data_elems) {
1574  if (ret < 0)
1575  return ret;
1576 
1578  if (ret < 0)
1579  return ret;
1580 
1582  }
1583 
1584  if (pkt->flags & AV_PKT_FLAG_DISCARD) {
1585  frame->flags |= AV_FRAME_FLAG_DISCARD;
1586  }
1587 
1588  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
1589  ret = av_buffer_replace(&frame->opaque_ref, pkt->opaque_ref);
1590  if (ret < 0)
1591  return ret;
1592  frame->opaque = pkt->opaque;
1593  }
1594 
1595  return 0;
1596 }
1597 
1599 {
1600  int ret;
1601 
1604  if (ret < 0)
1605  return ret;
1606 
1607  for (int i = 0; i < avctx->nb_decoded_side_data; i++) {
1608  const AVFrameSideData *src = avctx->decoded_side_data[i];
1609  if (av_frame_get_side_data(frame, src->type))
1610  continue;
1611  ret = av_frame_side_data_clone(&frame->side_data, &frame->nb_side_data, src, 0);
1612  if (ret < 0)
1613  return ret;
1614  }
1615 
1617  const AVPacket *pkt = avctx->internal->last_pkt_props;
1618 
1620  if (ret < 0)
1621  return ret;
1622  }
1623 
1624  ret = fill_frame_props(avctx, frame);
1625  if (ret < 0)
1626  return ret;
1627 
1628  switch (avctx->codec->type) {
1629  case AVMEDIA_TYPE_VIDEO:
1630  if (frame->width && frame->height &&
1631  av_image_check_sar(frame->width, frame->height,
1632  frame->sample_aspect_ratio) < 0) {
1633  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1634  frame->sample_aspect_ratio.num,
1635  frame->sample_aspect_ratio.den);
1636  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
1637  }
1638  break;
1639  }
1640 
1641 #if CONFIG_LIBLCEVC_DEC
1642  AVCodecInternal *avci = avctx->internal;
1643  DecodeContext *dc = decode_ctx(avci);
1644 
1645  dc->lcevc.frame = dc->lcevc.ctx &&
1647 
1648  if (dc->lcevc.frame) {
1649  ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame, &dc->lcevc.format,
1650  &dc->lcevc.width, &dc->lcevc.height);
1651  if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
1652  return ret;
1653 
1654  // force get_buffer2() to allocate the base frame using the same dimensions
1655  // as the final enhanced frame, in order to prevent reinitializing the buffer
1656  // pools unnecessarely
1657  if (!ret && dc->lcevc.width && dc->lcevc.height) {
1658  dc->lcevc.base_width = frame->width;
1659  dc->lcevc.base_height = frame->height;
1660  frame->width = dc->lcevc.width;
1661  frame->height = dc->lcevc.height;
1662  } else
1663  dc->lcevc.frame = 0;
1664  }
1665 #endif
1666 
1667  return 0;
1668 }
1669 
1671 {
1672  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1673  int i;
1674  int num_planes = av_pix_fmt_count_planes(frame->format);
1676  int flags = desc ? desc->flags : 0;
1677  if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL))
1678  num_planes = 2;
1679  for (i = 0; i < num_planes; i++) {
1680  av_assert0(frame->data[i]);
1681  }
1682  // For formats without data like hwaccel allow unused pointers to be non-NULL.
1683  for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) {
1684  if (frame->data[i])
1685  av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
1686  frame->data[i] = NULL;
1687  }
1688  }
1689 }
1690 
1691 static void decode_data_free(AVRefStructOpaque unused, void *obj)
1692 {
1693  FrameDecodeData *fdd = obj;
1694 
1695  if (CONFIG_LIBLCEVC_DEC)
1697  else
1699 
1700  if (fdd->hwaccel_priv_free)
1701  fdd->hwaccel_priv_free(fdd->hwaccel_priv);
1702 }
1703 
1705 {
1706  FrameDecodeData *fdd;
1707 
1708  av_assert1(!frame->private_ref);
1709  av_refstruct_unref(&frame->private_ref);
1710 
1711  fdd = av_refstruct_alloc_ext(sizeof(*fdd), 0, NULL, decode_data_free);
1712  if (!fdd)
1713  return AVERROR(ENOMEM);
1714 
1715  frame->private_ref = fdd;
1716 
1717 #if CONFIG_LIBLCEVC_DEC
1718  AVCodecInternal *avci = avctx->internal;
1719  DecodeContext *dc = decode_ctx(avci);
1720 
1721  if (!dc->lcevc.frame) {
1722  dc->lcevc.frame = dc->lcevc.ctx &&
1724 
1725  if (dc->lcevc.frame) {
1726  int ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame, &dc->lcevc.format,
1727  &dc->lcevc.width, &dc->lcevc.height);
1728  if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
1729  return ret;
1730 
1731  if (!ret && dc->lcevc.width && dc->lcevc.height) {
1732  dc->lcevc.base_width = frame->width;
1733  dc->lcevc.base_height = frame->height;
1734  } else
1735  dc->lcevc.frame = 0;
1736  }
1737  }
1738  if (dc->lcevc.frame) {
1739  FFLCEVCFrame *frame_ctx;
1740  int ret;
1741 
1742  if (fdd->post_process || !dc->lcevc.width || !dc->lcevc.height) {
1743  dc->lcevc.frame = 0;
1744  return 0;
1745  }
1746 
1747  frame_ctx = av_refstruct_pool_get(dc->lcevc.ctx->frame_pool);
1748  if (!frame_ctx)
1749  return AVERROR(ENOMEM);
1750 
1751  frame_ctx->lcevc = av_refstruct_ref(dc->lcevc.ctx);
1752  frame_ctx->frame->width = dc->lcevc.width;
1753  frame_ctx->frame->height = dc->lcevc.height;
1754  frame_ctx->frame->format = dc->lcevc.format;
1756 
1757  frame->width = dc->lcevc.base_width;
1758  frame->height = dc->lcevc.base_height;
1759 
1760  ret = avctx->get_buffer2(avctx, frame_ctx->frame, 0);
1761  if (ret < 0) {
1762  av_refstruct_unref(&frame_ctx);
1763  return ret;
1764  }
1765 
1766  validate_avframe_allocation(avctx, frame_ctx->frame);
1767 
1768  fdd->post_process_opaque = frame_ctx;
1770  }
1771  dc->lcevc.frame = 0;
1772 #endif
1773 
1774  return 0;
1775 }
1776 
1778 {
1779  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1780  int override_dimensions = 1;
1781  int ret;
1782 
1784 
1785  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1786  if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
1787  (ret = av_image_check_size2(FFALIGN(avctx->width, STRIDE_ALIGN), avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) {
1788  av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
1789  ret = AVERROR(EINVAL);
1790  goto fail;
1791  }
1792 
1793  if (frame->width <= 0 || frame->height <= 0) {
1794  frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
1795  frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
1796  override_dimensions = 0;
1797  }
1798 
1799  if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
1800  av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
1801  ret = AVERROR(EINVAL);
1802  goto fail;
1803  }
1804  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1805  if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
1806  av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
1807  ret = AVERROR(EINVAL);
1808  goto fail;
1809  }
1810  }
1811  ret = ff_decode_frame_props(avctx, frame);
1812  if (ret < 0)
1813  goto fail;
1814 
1815  if (hwaccel) {
1816  if (hwaccel->alloc_frame) {
1817  ret = hwaccel->alloc_frame(avctx, frame);
1818  goto end;
1819  }
1820  } else {
1821  avctx->sw_pix_fmt = avctx->pix_fmt;
1822  }
1823 
1824  ret = avctx->get_buffer2(avctx, frame, flags);
1825  if (ret < 0)
1826  goto fail;
1827 
1829 
1830  ret = ff_attach_decode_data(avctx, frame);
1831  if (ret < 0)
1832  goto fail;
1833 
1834 end:
1835  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
1837  frame->width = avctx->width;
1838  frame->height = avctx->height;
1839  }
1840 
1841 fail:
1842  if (ret < 0) {
1843  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1845  }
1846 
1847  return ret;
1848 }
1849 
1851 {
1852  int ret;
1853 
1855 
1856  // make sure the discard flag does not persist
1857  frame->flags &= ~AV_FRAME_FLAG_DISCARD;
1858 
1859  if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1860  av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1861  frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1863  }
1864 
1865  if (!frame->data[0])
1866  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1867 
1868  av_frame_side_data_free(&frame->side_data, &frame->nb_side_data);
1869 
1871  return ff_decode_frame_props(avctx, frame);
1872 
1873  uint8_t *data[AV_VIDEO_MAX_PLANES];
1875  int linesize[AV_VIDEO_MAX_PLANES];
1876 
1877  static_assert(AV_VIDEO_MAX_PLANES <= FF_ARRAY_ELEMS(frame->data) &&
1880  "Copying code needs to be adjusted");
1881  static_assert(sizeof(frame->linesize[0]) == sizeof(linesize[0]),
1882  "linesize needs to be switched to ptrdiff_t");
1883 
1884  for (int i = 0; i < AV_VIDEO_MAX_PLANES; ++i) {
1885  data[i] = frame->data[i];
1886  linesize[i] = frame->linesize[i];
1887  buf[i] = frame->buf[i];
1888  frame->buf[i] = NULL;
1889  }
1890  av_assert1(!frame->buf[AV_VIDEO_MAX_PLANES] && !frame->extended_buf);
1891 
1893 
1895  if (ret >= 0) {
1896  av_image_copy2(frame->data, frame->linesize,
1897  data, linesize,
1898  frame->format, frame->width, frame->height);
1899  }
1900  for (int i = 0; i < AV_VIDEO_MAX_PLANES; ++i)
1901  av_buffer_unref(&buf[i]);
1902 
1903  return ret;
1904 }
1905 
1907 {
1908  int ret = reget_buffer_internal(avctx, frame, flags);
1909  if (ret < 0)
1910  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1911  return ret;
1912 }
1913 
1914 typedef struct ProgressInternal {
1916  struct AVFrame *f;
1918 
1920 {
1921  av_assert1(!!f->f == !!f->progress);
1922  av_assert1(!f->progress || f->progress->f == f->f);
1923 }
1924 
1926 {
1928 
1929  av_assert1(!f->f && !f->progress);
1930 
1931  f->progress = av_refstruct_pool_get(pool);
1932  if (!f->progress)
1933  return AVERROR(ENOMEM);
1934 
1935  f->f = f->progress->f;
1936  return 0;
1937 }
1938 
1940 {
1941  int ret = ff_progress_frame_alloc(avctx, f);
1942  if (ret < 0)
1943  return ret;
1944 
1945  ret = ff_thread_get_buffer(avctx, f->progress->f, flags);
1946  if (ret < 0) {
1947  f->f = NULL;
1948  av_refstruct_unref(&f->progress);
1949  return ret;
1950  }
1951  return 0;
1952 }
1953 
1955 {
1956  av_assert1(src->progress && src->f && src->f == src->progress->f);
1957  av_assert1(!dst->f && !dst->progress);
1958  dst->f = src->f;
1959  dst->progress = av_refstruct_ref(src->progress);
1960 }
1961 
1963 {
1965  f->f = NULL;
1966  av_refstruct_unref(&f->progress);
1967 }
1968 
1970 {
1971  if (dst == src)
1972  return;
1975  if (src->f)
1977 }
1978 
1980 {
1981  ff_thread_progress_report(&f->progress->progress, n);
1982 }
1983 
1985 {
1986  ff_thread_progress_await(&f->progress->progress, n);
1987 }
1988 
1989 #if !HAVE_THREADS
1991 {
1993 }
1994 #endif /* !HAVE_THREADS */
1995 
1997 {
1998  const AVCodecContext *avctx = opaque.nc;
1999  ProgressInternal *progress = obj;
2000  int ret;
2001 
2003  if (ret < 0)
2004  return ret;
2005 
2006  progress->f = av_frame_alloc();
2007  if (!progress->f)
2008  return AVERROR(ENOMEM);
2009 
2010  return 0;
2011 }
2012 
2013 static void progress_frame_pool_reset_cb(AVRefStructOpaque unused, void *obj)
2014 {
2015  ProgressInternal *progress = obj;
2016 
2017  ff_thread_progress_reset(&progress->progress);
2018  av_frame_unref(progress->f);
2019 }
2020 
2022 {
2023  ProgressInternal *progress = obj;
2024 
2026  av_frame_free(&progress->f);
2027 }
2028 
2030 {
2031  AVCodecInternal *avci = avctx->internal;
2032  DecodeContext *dc = decode_ctx(avci);
2033  int ret = 0;
2034 
2035  dc->initial_pict_type = AV_PICTURE_TYPE_NONE;
2037  dc->intra_only_flag = AV_FRAME_FLAG_KEY;
2038  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
2039  dc->initial_pict_type = AV_PICTURE_TYPE_I;
2040  }
2041 
2042  /* if the decoder init function was already called previously,
2043  * free the already allocated subtitle_header before overwriting it */
2044  av_freep(&avctx->subtitle_header);
2045 
2046  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
2047  av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
2048  avctx->codec->max_lowres);
2049  avctx->lowres = avctx->codec->max_lowres;
2050  }
2051  if (avctx->sub_charenc) {
2052  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
2053  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
2054  "supported with subtitles codecs\n");
2055  return AVERROR(EINVAL);
2056  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
2057  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
2058  "subtitles character encoding will be ignored\n",
2059  avctx->codec_descriptor->name);
2061  } else {
2062  /* input character encoding is set for a text based subtitle
2063  * codec at this point */
2066 
2068 #if CONFIG_ICONV
2069  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
2070  if (cd == (iconv_t)-1) {
2071  ret = AVERROR(errno);
2072  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
2073  "with input character encoding \"%s\"\n", avctx->sub_charenc);
2074  return ret;
2075  }
2076  iconv_close(cd);
2077 #else
2078  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
2079  "conversion needs a libavcodec built with iconv support "
2080  "for this codec\n");
2081  return AVERROR(ENOSYS);
2082 #endif
2083  }
2084  }
2085  }
2086 
2087  dc->pts_correction_num_faulty_pts =
2088  dc->pts_correction_num_faulty_dts = 0;
2089  dc->pts_correction_last_pts =
2090  dc->pts_correction_last_dts = INT64_MIN;
2091 
2092  if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
2094  av_log(avctx, AV_LOG_WARNING,
2095  "gray decoding requested but not enabled at configuration time\n");
2096  if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
2098  }
2099 
2100  if (avctx->nb_side_data_prefer_packet == 1 &&
2101  avctx->side_data_prefer_packet[0] == -1)
2102  dc->side_data_pref_mask = ~0ULL;
2103  else {
2104  for (unsigned i = 0; i < avctx->nb_side_data_prefer_packet; i++) {
2105  int val = avctx->side_data_prefer_packet[i];
2106 
2107  if (val < 0 || val >= AV_PKT_DATA_NB) {
2108  av_log(avctx, AV_LOG_ERROR, "Invalid side data type: %d\n", val);
2109  return AVERROR(EINVAL);
2110  }
2111 
2112  for (unsigned j = 0; ff_sd_global_map[j].packet < AV_PKT_DATA_NB; j++) {
2113  if (ff_sd_global_map[j].packet == val) {
2114  val = ff_sd_global_map[j].frame;
2115 
2116  // this code will need to be changed when we have more than
2117  // 64 frame side data types
2118  if (val >= 64) {
2119  av_log(avctx, AV_LOG_ERROR, "Side data type too big\n");
2120  return AVERROR_BUG;
2121  }
2122 
2123  dc->side_data_pref_mask |= 1ULL << val;
2124  }
2125  }
2126  }
2127  }
2128 
2129  avci->in_pkt = av_packet_alloc();
2130  avci->last_pkt_props = av_packet_alloc();
2131  if (!avci->in_pkt || !avci->last_pkt_props)
2132  return AVERROR(ENOMEM);
2133 
2135  avci->progress_frame_pool =
2141  if (!avci->progress_frame_pool)
2142  return AVERROR(ENOMEM);
2143  }
2144  ret = decode_bsfs_init(avctx);
2145  if (ret < 0)
2146  return ret;
2147 
2149  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
2150 #if CONFIG_LIBLCEVC_DEC
2151  ret = ff_lcevc_alloc(&dc->lcevc.ctx, av_log_get_level() + avctx->log_level_offset);
2152  if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
2153  return ret;
2154 #endif
2155  }
2156  }
2157 
2158  return 0;
2159 }
2160 
2161 /**
2162  * Check side data preference and clear existing side data from frame
2163  * if needed.
2164  *
2165  * @retval 0 side data of this type can be added to frame
2166  * @retval 1 side data of this type should not be added to frame
2167  */
2168 static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd,
2169  int *nb_sd, enum AVFrameSideDataType type)
2170 {
2171  DecodeContext *dc = decode_ctx(avctx->internal);
2172 
2173  // Note: could be skipped for `type` without corresponding packet sd
2174  if (av_frame_side_data_get(*sd, *nb_sd, type)) {
2175  if (dc->side_data_pref_mask & (1ULL << type))
2176  return 1;
2177  av_frame_side_data_remove(sd, nb_sd, type);
2178  }
2179 
2180  return 0;
2181 }
2182 
2183 
2185  enum AVFrameSideDataType type, size_t size,
2186  AVFrameSideData **psd)
2187 {
2188  AVFrameSideData *sd;
2189 
2190  if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, type)) {
2191  if (psd)
2192  *psd = NULL;
2193  return 0;
2194  }
2195 
2197  if (psd)
2198  *psd = sd;
2199 
2200  return sd ? 0 : AVERROR(ENOMEM);
2201 }
2202 
2204  AVFrameSideData ***sd, int *nb_sd,
2206  AVBufferRef **buf)
2207 {
2208  int ret = 0;
2209 
2210  if (side_data_pref(avctx, sd, nb_sd, type))
2211  goto finish;
2212 
2213  if (!av_frame_side_data_add(sd, nb_sd, type, buf, 0))
2214  ret = AVERROR(ENOMEM);
2215 
2216 finish:
2218 
2219  return ret;
2220 }
2221 
2224  AVBufferRef **buf)
2225 {
2227  &frame->side_data, &frame->nb_side_data,
2228  type, buf);
2229 }
2230 
2232  AVFrameSideData ***sd, int *nb_sd,
2233  struct AVMasteringDisplayMetadata **mdm)
2234 {
2235  AVBufferRef *buf;
2236  size_t size;
2237 
2239  *mdm = NULL;
2240  return 0;
2241  }
2242 
2244  if (!*mdm)
2245  return AVERROR(ENOMEM);
2246 
2247  buf = av_buffer_create((uint8_t *)*mdm, size, NULL, NULL, 0);
2248  if (!buf) {
2249  av_freep(mdm);
2250  return AVERROR(ENOMEM);
2251  }
2252 
2254  &buf, 0)) {
2255  *mdm = NULL;
2256  av_buffer_unref(&buf);
2257  return AVERROR(ENOMEM);
2258  }
2259 
2260  return 0;
2261 }
2262 
2265 {
2266  if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2268  *mdm = NULL;
2269  return 0;
2270  }
2271 
2273  return *mdm ? 0 : AVERROR(ENOMEM);
2274 }
2275 
2277  AVFrameSideData ***sd, int *nb_sd,
2278  AVContentLightMetadata **clm)
2279 {
2280  AVBufferRef *buf;
2281  size_t size;
2282 
2283  if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) {
2284  *clm = NULL;
2285  return 0;
2286  }
2287 
2289  if (!*clm)
2290  return AVERROR(ENOMEM);
2291 
2292  buf = av_buffer_create((uint8_t *)*clm, size, NULL, NULL, 0);
2293  if (!buf) {
2294  av_freep(clm);
2295  return AVERROR(ENOMEM);
2296  }
2297 
2299  &buf, 0)) {
2300  *clm = NULL;
2301  av_buffer_unref(&buf);
2302  return AVERROR(ENOMEM);
2303  }
2304 
2305  return 0;
2306 }
2307 
2309  AVContentLightMetadata **clm)
2310 {
2311  if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2313  *clm = NULL;
2314  return 0;
2315  }
2316 
2318  return *clm ? 0 : AVERROR(ENOMEM);
2319 }
2320 
2321 int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
2322 {
2323  size_t size;
2324  const void *pal = av_packet_get_side_data(src, AV_PKT_DATA_PALETTE, &size);
2325 
2326  if (pal && size == AVPALETTE_SIZE) {
2327  memcpy(dst, pal, AVPALETTE_SIZE);
2328  return 1;
2329  } else if (pal) {
2330  av_log(logctx, AV_LOG_ERROR,
2331  "Palette size %zu is wrong\n", size);
2332  }
2333  return 0;
2334 }
2335 
2336 int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
2337 {
2338  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
2339 
2340  if (!hwaccel || !hwaccel->frame_priv_data_size)
2341  return 0;
2342 
2343  av_assert0(!*hwaccel_picture_private);
2344 
2345  if (hwaccel->free_frame_priv) {
2346  AVHWFramesContext *frames_ctx;
2347 
2348  if (!avctx->hw_frames_ctx)
2349  return AVERROR(EINVAL);
2350 
2351  frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data;
2352  *hwaccel_picture_private = av_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,
2353  frames_ctx->device_ctx,
2354  hwaccel->free_frame_priv);
2355  } else {
2356  *hwaccel_picture_private = av_refstruct_allocz(hwaccel->frame_priv_data_size);
2357  }
2358 
2359  if (!*hwaccel_picture_private)
2360  return AVERROR(ENOMEM);
2361 
2362  return 0;
2363 }
2364 
2366 {
2367  AVCodecInternal *avci = avctx->internal;
2368  DecodeContext *dc = decode_ctx(avci);
2369 
2371  av_packet_unref(avci->in_pkt);
2372 
2373  dc->pts_correction_num_faulty_pts =
2374  dc->pts_correction_num_faulty_dts = 0;
2375  dc->pts_correction_last_pts =
2376  dc->pts_correction_last_dts = INT64_MIN;
2377 
2378  if (avci->bsf)
2379  av_bsf_flush(avci->bsf);
2380 
2381  dc->nb_draining_errors = 0;
2382  dc->draining_started = 0;
2383 }
2384 
2386 {
2387  return av_mallocz(sizeof(DecodeContext));
2388 }
2389 
2391 {
2392  const DecodeContext *src_dc = decode_ctx(src->internal);
2393  DecodeContext *dst_dc = decode_ctx(dst->internal);
2394 
2395  dst_dc->initial_pict_type = src_dc->initial_pict_type;
2396  dst_dc->intra_only_flag = src_dc->intra_only_flag;
2397  dst_dc->side_data_pref_mask = src_dc->side_data_pref_mask;
2398 #if CONFIG_LIBLCEVC_DEC
2399  av_refstruct_replace(&dst_dc->lcevc.ctx, src_dc->lcevc.ctx);
2400  dst_dc->lcevc.width = src_dc->lcevc.width;
2401  dst_dc->lcevc.height = src_dc->lcevc.height;
2402  dst_dc->lcevc.format = src_dc->lcevc.format;
2403 #endif
2404 }
2405 
2407 {
2408 #if CONFIG_LIBLCEVC_DEC
2409  AVCodecInternal *avci = avctx->internal;
2410  DecodeContext *dc = decode_ctx(avci);
2411 
2412  av_refstruct_unref(&dc->lcevc.ctx);
2413 #endif
2414 }
2415 
2416 static int attach_displaymatrix(AVCodecContext *avctx, AVFrame *frame, int orientation)
2417 {
2418  AVFrameSideData *sd = NULL;
2419  int32_t *matrix;
2420  int ret;
2421  /* invalid orientation */
2422  if (orientation < 1 || orientation > 8)
2423  return AVERROR_INVALIDDATA;
2425  if (ret < 0) {
2426  av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data: %s\n", av_err2str(ret));
2427  return ret;
2428  }
2429  if (sd) {
2430  matrix = (int32_t *) sd->data;
2431  ret = av_exif_orientation_to_matrix(matrix, orientation);
2432  }
2433 
2434  return ret;
2435 }
2436 
2437 static int exif_attach_ifd(AVCodecContext *avctx, AVFrame *frame, const AVExifMetadata *ifd, AVBufferRef **pbuf)
2438 {
2439  const AVExifEntry *orient = NULL;
2440  AVExifMetadata *cloned = NULL;
2441  int ret;
2442 
2443  for (size_t i = 0; i < ifd->count; i++) {
2444  const AVExifEntry *entry = &ifd->entries[i];
2445  if (entry->id == av_exif_get_tag_id("Orientation") &&
2446  entry->count > 0 && entry->type == AV_TIFF_SHORT) {
2447  orient = entry;
2448  break;
2449  }
2450  }
2451 
2452  if (orient) {
2453  av_log(avctx, AV_LOG_DEBUG, "found EXIF orientation: %" PRIu64 "\n", orient->value.uint[0]);
2454  ret = attach_displaymatrix(avctx, frame, orient->value.uint[0]);
2455  if (ret < 0) {
2456  av_log(avctx, AV_LOG_WARNING, "unable to attach displaymatrix from EXIF\n");
2457  } else {
2458  cloned = av_exif_clone_ifd(ifd);
2459  if (!cloned) {
2460  ret = AVERROR(ENOMEM);
2461  goto end;
2462  }
2463  av_exif_remove_entry(avctx, cloned, orient->id, 0);
2464  ifd = cloned;
2465  }
2466  }
2467 
2468  ret = av_exif_ifd_to_dict(avctx, ifd, &frame->metadata);
2469  if (ret < 0)
2470  goto end;
2471 
2472  if (cloned || !*pbuf) {
2473  av_buffer_unref(pbuf);
2474  ret = av_exif_write(avctx, ifd, pbuf, AV_EXIF_TIFF_HEADER);
2475  if (ret < 0)
2476  goto end;
2477  }
2478 
2480  if (ret < 0)
2481  goto end;
2482 
2483  ret = 0;
2484 
2485 end:
2486  av_buffer_unref(pbuf);
2487  av_exif_free(cloned);
2488  av_free(cloned);
2489  return ret;
2490 }
2491 
2493 {
2494  AVBufferRef *dummy = NULL;
2495  return exif_attach_ifd(avctx, frame, ifd, &dummy);
2496 }
2497 
2499  enum AVExifHeaderMode header_mode)
2500 {
2501  int ret;
2502  AVBufferRef *data = *pbuf;
2503  AVExifMetadata ifd = { 0 };
2504 
2505  ret = av_exif_parse_buffer(avctx, data->data, data->size, &ifd, header_mode);
2506  if (ret < 0)
2507  goto end;
2508 
2509  ret = exif_attach_ifd(avctx, frame, &ifd, pbuf);
2510 
2511 end:
2512  av_buffer_unref(pbuf);
2513  av_exif_free(&ifd);
2514  return ret;
2515 }
lcevcdec.h
ff_get_coded_side_data
const AVPacketSideData * ff_get_coded_side_data(const AVCodecContext *avctx, enum AVPacketSideDataType type)
Get side data of the given type from a decoding context.
Definition: decode.c:1378
DecodeContext::intra_only_flag
int intra_only_flag
This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats (those whose codec descriptor has...
Definition: decode.c:71
AVSubtitle
Definition: avcodec.h:2087
hwconfig.h
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:1979
av_samples_copy
int av_samples_copy(uint8_t *const *dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Definition: samplefmt.c:222
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:434
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1423
exif_attach_ifd
static int exif_attach_ifd(AVCodecContext *avctx, AVFrame *frame, const AVExifMetadata *ifd, AVBufferRef **pbuf)
Definition: decode.c:2437
AV_FRAME_DATA_IAMF_MIX_GAIN_PARAM
@ AV_FRAME_DATA_IAMF_MIX_GAIN_PARAM
IAMF Mix Gain Parameter Data associated with the audio frame.
Definition: frame.h:278
FFCodec::receive_frame
int(* receive_frame)(struct AVCodecContext *avctx, struct AVFrame *frame)
Decode API with decoupled packet/frame dataflow.
Definition: codec_internal.h:219
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
AVBSFContext::par_in
AVCodecParameters * par_in
Parameters of the input stream.
Definition: bsf.h:90
hwaccel_init
static int hwaccel_init(AVCodecContext *avctx, const FFHWAccel *hwaccel)
Definition: decode.c:1182
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
ff_decode_get_packet
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition: decode.c:254
hw_pix_fmt
static enum AVPixelFormat hw_pix_fmt
Definition: hw_decode.c:46
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
Frame::width
int width
Definition: ffplay.c:160
entry
#define entry
Definition: aom_film_grain_template.c:66
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
ff_thread_progress_report
void ff_thread_progress_report(ThreadProgress *pro, int n)
This function is a no-op in no-op mode; otherwise it notifies other threads that a certain level of p...
Definition: threadprogress.c:53
AVCodecContext::alpha_mode
enum AVAlphaMode alpha_mode
Indicates how the alpha channel of the video is represented.
Definition: avcodec.h:1937
AVCodecContext::log_level_offset
int log_level_offset
Definition: avcodec.h:449
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
AVSubtitle::rects
AVSubtitleRect ** rects
Definition: avcodec.h:2092
threadprogress.h
AVCodecContext::get_format
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Callback to negotiate the pixel format.
Definition: avcodec.h:773
ff_icc_profile_read_primaries
int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile, AVColorPrimariesDesc *out_primaries)
Read the color primaries and white point coefficients encoded by an ICC profile, and return the raw v...
Definition: fflcms2.c:253
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
av_exif_parse_buffer
int av_exif_parse_buffer(void *logctx, const uint8_t *buf, size_t size, AVExifMetadata *ifd, enum AVExifHeaderMode header_mode)
Decodes the EXIF data provided in the buffer and writes it into the struct *ifd.
Definition: exif.c:882
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:671
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:672
AVCodecContext::decoded_side_data
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition: avcodec.h:1929
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1229
apply_cropping
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:763
ThreadProgress
ThreadProgress is an API to easily notify other threads about progress of any kind as long as it can ...
Definition: threadprogress.h:43
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1040
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:659
AVExifEntry
Definition: exif.h:84
av_frame_new_side_data
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
Definition: frame.c:647
av_exif_write
int av_exif_write(void *logctx, const AVExifMetadata *ifd, AVBufferRef **buffer, enum AVExifHeaderMode header_mode)
Allocates a buffer using av_malloc of an appropriate size and writes the EXIF data represented by ifd...
Definition: exif.c:753
AVExifMetadata
Definition: exif.h:75
AVColorPrimariesDesc
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition: csp.h:78
DecodeContext::initial_pict_type
enum AVPictureType initial_pict_type
This is set to AV_PICTURE_TYPE_I for intra only video decoders and to AV_PICTURE_TYPE_NONE for other ...
Definition: decode.c:78
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3460
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AV_HWACCEL_CODEC_CAP_EXPERIMENTAL
#define AV_HWACCEL_CODEC_CAP_EXPERIMENTAL
HWAccel is experimental and is thus avoided in favor of non experimental codecs.
Definition: avcodec.h:1988
AV_FRAME_DATA_IAMF_RECON_GAIN_INFO_PARAM
@ AV_FRAME_DATA_IAMF_RECON_GAIN_INFO_PARAM
IAMF Recon Gain Info Parameter Data associated with the audio frame.
Definition: frame.h:294
AV_FRAME_DATA_A53_CC
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:59
AVRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
matrix
Definition: vc1dsp.c:43
AV_PKT_FLAG_DISCARD
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
Definition: packet.h:657
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:200
AVPictureType
AVPictureType
Definition: avutil.h:276
av_exif_ifd_to_dict
int av_exif_ifd_to_dict(void *logctx, const AVExifMetadata *ifd, AVDictionary **metadata)
Recursively reads all tags from the IFD and stores them in the provided metadata dictionary.
Definition: exif.c:1053
AVCodecInternal::skip_samples
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
Definition: internal.h:125
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1416
AV_CODEC_FLAG_UNALIGNED
#define AV_CODEC_FLAG_UNALIGNED
Allow decoders to produce frames with data planes that are not aligned to CPU requirements (e....
Definition: avcodec.h:209
AVCodecContext::codec_descriptor
const struct AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:1709
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:263
AVCodecDescriptor::name
const char * name
Name of the codec described by this descriptor.
Definition: codec_desc.h:46
AV_WL8
#define AV_WL8(p, d)
Definition: intreadwrite.h:395
AVCodecContext::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
Definition: avcodec.h:1768
av_cold
#define av_cold
Definition: attributes.h:119
int64_t
long long int64_t
Definition: coverity.c:34
av_exif_orientation_to_matrix
int av_exif_orientation_to_matrix(int32_t *matrix, int orientation)
Convert an orientation constant used by EXIF's orientation tag into a display matrix used by AV_FRAME...
Definition: exif.c:1326
AV_VIDEO_MAX_PLANES
#define AV_VIDEO_MAX_PLANES
Maximum number of planes in any pixel format.
Definition: pixfmt.h:40
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2091
AVExifHeaderMode
AVExifHeaderMode
Definition: exif.h:57
decode_simple_receive_frame
static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:609
AV_FRAME_DATA_S12M_TIMECODE
@ AV_FRAME_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1.
Definition: frame.h:152
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:610
FrameDecodeData
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition: decode.h:33
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:337
DecodeContext::pts_correction_last_pts
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition: decode.c:90
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:472
AVFrameSideData::buf
AVBufferRef * buf
Definition: frame.h:332
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:664
AVFrame::width
int width
Definition: frame.h:544
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:424
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:188
FFHWAccel::frame_params
int(* frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Fill the given hw_frames context with current codec parameters.
Definition: hwaccel_internal.h:146
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:263
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:603
ff_lcevc_alloc
int ff_lcevc_alloc(FFLCEVCContext **plcevc, int loglevel)
Definition: lcevcdec.c:475
FFLCEVCContext
Definition: lcevcdec.h:36
AVComponentDescriptor::depth
int depth
Number of bits in the component.
Definition: pixdesc.h:57
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:675
ff_progress_frame_get_buffer
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
Wrapper around ff_progress_frame_alloc() and ff_thread_get_buffer().
Definition: decode.c:1939
data
const char data[16]
Definition: mxf.c:149
AV_PKT_DATA_S12M_TIMECODE
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
Definition: packet.h:288
FFCodec
Definition: codec_internal.h:127
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Definition: avcodec.h:1744
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
Definition: packet.h:672
FrameDecodeData::hwaccel_priv_free
void(* hwaccel_priv_free)(void *priv)
Definition: decode.h:55
FF_HW_SIMPLE_CALL
#define FF_HW_SIMPLE_CALL(avctx, function)
Definition: hwaccel_internal.h:176
AV_FRAME_DATA_DISPLAYMATRIX
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:85
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:621
FF_COMPLIANCE_EXPERIMENTAL
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: defs.h:62
FF_SUB_CHARENC_MODE_PRE_DECODER
#define FF_SUB_CHARENC_MODE_PRE_DECODER
the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv
Definition: avcodec.h:1727
AVDictionary
Definition: dict.c:32
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:642
avcodec_default_get_format
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Definition: decode.c:1006
av_frame_side_data_clone
int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags)
Add a new side data entry to an array based on existing side data, taking a reference towards the con...
Definition: side_data.c:254
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:702
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:649
AV_RL8
#define AV_RL8(x)
Definition: intreadwrite.h:394
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:91
decode_ctx
static DecodeContext * decode_ctx(AVCodecInternal *avci)
Definition: decode.c:112
av_bsf_free
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:47
FF_SUB_CHARENC_MODE_AUTOMATIC
#define FF_SUB_CHARENC_MODE_AUTOMATIC
libavcodec will select the mode itself
Definition: avcodec.h:1726
AV_STEREO3D_VIEW_UNSPEC
@ AV_STEREO3D_VIEW_UNSPEC
Content is unspecified.
Definition: stereo3d.h:168
tf_sess_config.config
config
Definition: tf_sess_config.py:33
thread.h
dummy
static int dummy
Definition: ffplay.c:3751
AV_STEREO3D_UNSPEC
@ AV_STEREO3D_UNSPEC
Video is stereoscopic but the packing is unspecified.
Definition: stereo3d.h:143
av_frame_apply_cropping
int av_frame_apply_cropping(AVFrame *frame, int flags)
Crop the given video AVFrame according to its crop_left/crop_top/crop_right/ crop_bottom fields.
Definition: frame.c:760
DecodeContext::pts_correction_num_faulty_dts
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition: decode.c:89
ff_hwaccel_uninit
void ff_hwaccel_uninit(AVCodecContext *avctx)
Definition: decode.c:1217
AV_CODEC_HW_CONFIG_METHOD_INTERNAL
@ AV_CODEC_HW_CONFIG_METHOD_INTERNAL
The codec supports this format by some internal method.
Definition: codec.h:296
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
decode_get_packet
static int decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: decode.c:229
AVCodec::max_lowres
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: codec.h:189
AVPacketSideData::size
size_t size
Definition: packet.h:426
AV_TIFF_SHORT
@ AV_TIFF_SHORT
Definition: exif.h:44
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3500
DecodeContext::frame
AVFrame * frame
Definition: decode_simple.h:39
DecodeContext::nb_draining_errors
int nb_draining_errors
Definition: decode.c:81
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:279
finish
static void finish(void)
Definition: movenc.c:374
FFHWAccel
Definition: hwaccel_internal.h:34
AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM
@ AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM
IAMF Recon Gain Info Parameter Data associated with the audio frame.
Definition: packet.h:320
bsf.h
AVExifEntry::value
union AVExifEntry::@139 value
guess_correct_pts
static int64_t guess_correct_pts(DecodeContext *dc, int64_t reordered_pts, int64_t dts)
Attempt to guess proper monotonic timestamps for decoded video frames which might have incorrect time...
Definition: decode.c:296
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:452
AV_PKT_DATA_PALETTE
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition: packet.h:47
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:639
STRIDE_ALIGN
#define STRIDE_ALIGN
Definition: internal.h:46
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1055
ff_icc_context_init
int ff_icc_context_init(FFIccContext *s, void *avctx)
Initializes an FFIccContext.
Definition: fflcms2.c:30
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1579
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
ff_lcevc_process
int ff_lcevc_process(void *logctx, AVFrame *frame)
Definition: lcevcdec.c:394
av_exif_free
void av_exif_free(AVExifMetadata *ifd)
Frees all resources associated with the given EXIF metadata struct.
Definition: exif.c:659
FF_SUB_CHARENC_MODE_DO_NOTHING
#define FF_SUB_CHARENC_MODE_DO_NOTHING
do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for inst...
Definition: avcodec.h:1725
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:500
val
static double val(void *priv, double ch)
Definition: aeval.c:77
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
ff_decode_frame_props_from_pkt
int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt)
Set various frame properties from the provided packet.
Definition: decode.c:1550
pts
static int64_t pts
Definition: transcode_aac.c:649
add_metadata_from_side_data
static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
Definition: decode.c:1538
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:619
AVCodecContext::max_samples
int64_t max_samples
The number of samples per frame to maximally accept.
Definition: avcodec.h:1830
AVRational::num
int num
Numerator.
Definition: rational.h:59
progressframe.h
AVFrameSideDataType
AVFrameSideDataType
Definition: frame.h:49
av_unused
#define av_unused
Definition: attributes.h:164
refstruct.h
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2084
av_image_check_size2
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:289
ff_decode_internal_sync
av_cold void ff_decode_internal_sync(AVCodecContext *dst, const AVCodecContext *src)
Definition: decode.c:2390
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:2222
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:421
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
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
AVCodecContext::get_buffer2
int(* get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags)
This callback is called at the beginning of each frame to get data buffer(s) for it.
Definition: avcodec.h:1218
GET_UTF8
#define GET_UTF8(val, GET_BYTE, ERROR)
Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
Definition: common.h:477
avcodec_decode_subtitle2
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
Definition: decode.c:935
ff_decode_content_light_new_ext
int ff_decode_content_light_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, AVContentLightMetadata **clm)
Same as ff_decode_content_light_new, but taking a AVFrameSideData array directly instead of an AVFram...
Definition: decode.c:2276
avassert.h
FF_CODEC_CAP_USES_PROGRESSFRAMES
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
Definition: codec_internal.h:69
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:657
AV_PKT_DATA_PARAM_CHANGE
@ AV_PKT_DATA_PARAM_CHANGE
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: packet.h:69
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
AVFrameSideData::size
size_t size
Definition: frame.h:330
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:687
emms_c
#define emms_c()
Definition: emms.h:88
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:504
ff_progress_frame_ref
void ff_progress_frame_ref(ProgressFrame *dst, const ProgressFrame *src)
Set dst->f to src->f and make dst a co-owner of src->f.
Definition: decode.c:1954
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition: packet.h:673
AVCodecContext::side_data_prefer_packet
int * side_data_prefer_packet
Decoding only.
Definition: avcodec.h:1913
stereo3d.h
FrameDecodeData::hwaccel_priv_post_process
int(* hwaccel_priv_post_process)(void *logctx, AVFrame *frame)
Per-frame private data for hwaccels.
Definition: decode.h:53
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:2336
AV_FRAME_DATA_IAMF_DEMIXING_INFO_PARAM
@ AV_FRAME_DATA_IAMF_DEMIXING_INFO_PARAM
IAMF Demixing Info Parameter Data associated with the audio frame.
Definition: frame.h:286
get_subtitle_defaults
static void get_subtitle_defaults(AVSubtitle *sub)
Definition: decode.c:848
FrameDecodeData::post_process_opaque
void * post_process_opaque
RefStruct reference.
Definition: decode.h:45
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: packet.c:98
ff_decode_internal_uninit
av_cold void ff_decode_internal_uninit(AVCodecContext *avctx)
Definition: decode.c:2406
validate_avframe_allocation
static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:1670
AVCodecInternal::buffer_pkt
AVPacket * buffer_pkt
Temporary buffers for newly received or not yet output packets/frames.
Definition: internal.h:144
av_bsf_flush
void av_bsf_flush(AVBSFContext *ctx)
Reset the internal bitstream filter state.
Definition: bsf.c:188
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
FFHWAccel::priv_data_size
int priv_data_size
Size of the private data to allocate in AVCodecInternal.hwaccel_priv_data.
Definition: hwaccel_internal.h:114
AVCodecContext::nb_decoded_side_data
int nb_decoded_side_data
Definition: avcodec.h:1930
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:415
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
ff_thread_get_buffer
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread_frame.c:1036
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
AVCodecDescriptor::type
enum AVMediaType type
Definition: codec_desc.h:40
av_refstruct_alloc_ext
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
av_exif_clone_ifd
AVExifMetadata * av_exif_clone_ifd(const AVExifMetadata *ifd)
Allocates a duplicate of the provided EXIF metadata struct.
Definition: exif.c:1277
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1571
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
AVPacketSideData::data
uint8_t * data
Definition: packet.h:425
AVRefStructPool
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition: refstruct.c:183
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
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:1962
decode.h
AVBSFContext::time_base_in
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition: bsf.h:102
AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
@ AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
HDR dynamic metadata associated with a video frame.
Definition: frame.h:270
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVCodecHWConfig::pix_fmt
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
Definition: codec.h:317
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2093
av_csp_primaries_id_from_desc
enum AVColorPrimaries av_csp_primaries_id_from_desc(const AVColorPrimariesDesc *prm)
Detects which enum AVColorPrimaries constant corresponds to the given complete gamut description.
Definition: csp.c:115
AVCodecContext::max_pixels
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:1787
AV_PKT_DATA_LCEVC
@ AV_PKT_DATA_LCEVC
Raw LCEVC payload data, as a uint8_t array, with NAL emulation bytes intact.
Definition: packet.h:346
av_hwdevice_get_type_name
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition: hwcontext.c:120
progress_frame_pool_init_cb
static av_cold int progress_frame_pool_init_cb(AVRefStructOpaque opaque, void *obj)
Definition: decode.c:1996
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:628
ProgressInternal
Definition: decode.c:1914
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:645
AVCodecHWConfigInternal::hwaccel
const struct FFHWAccel * hwaccel
If this configuration uses a hwaccel, a pointer to it.
Definition: hwconfig.h:35
check_progress_consistency
static void check_progress_consistency(const ProgressFrame *f)
Definition: decode.c:1919
av_content_light_metadata_alloc
AVContentLightMetadata * av_content_light_metadata_alloc(size_t *size)
Allocate an AVContentLightMetadata structure and set its fields to default values.
Definition: mastering_display_metadata.c:73
FFCodec::decode
int(* decode)(struct AVCodecContext *avctx, struct AVFrame *frame, int *got_frame_ptr, struct AVPacket *avpkt)
Decode to an AVFrame.
Definition: codec_internal.h:202
discard_samples
static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:322
ff_decode_get_hw_frames_ctx
int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx, enum AVHWDeviceType dev_type)
Make sure avctx.hw_frames_ctx is set.
Definition: decode.c:1069
ff_decode_mastering_display_new
int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, AVMasteringDisplayMetadata **mdm)
Wrapper around av_mastering_display_metadata_create_side_data(), which rejects side data overridden b...
Definition: decode.c:2263
DecodeContext::draining_started
int draining_started
The caller has submitted a NULL packet on input.
Definition: decode.c:86
ff_thread_get_packet
#define ff_thread_get_packet(avctx, pkt)
Definition: decode.c:225
ff_lcevc_parse_frame
int ff_lcevc_parse_frame(FFLCEVCContext *lcevc, const AVFrame *frame, enum AVPixelFormat *format, int *width, int *height)
Definition: lcevcdec.c:423
AVCodecDescriptor::props
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
if
if(ret)
Definition: filter_design.txt:179
ff_attach_decode_data
int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:1704
AVCodecContext::sub_charenc
char * sub_charenc
Character encoding of the input subtitles file.
Definition: avcodec.h:1716
av_log_get_level
int av_log_get_level(void)
Get the current log level.
Definition: log.c:472
AV_CODEC_FLAG2_SKIP_MANUAL
#define AV_CODEC_FLAG2_SKIP_MANUAL
Do not skip samples and export skip information as frame side data.
Definition: avcodec.h:372
fail
#define fail
Definition: test.h:478
AV_CODEC_PROP_INTRA_ONLY
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
Definition: codec_desc.h:72
AVCodecInternal::progress_frame_pool
struct AVRefStructPool * progress_frame_pool
Definition: internal.h:71
av_exif_get_tag_id
int32_t av_exif_get_tag_id(const char *name)
Retrieves the tag ID associated with the provided tag string name.
Definition: exif.c:244
ff_thread_progress_await
void ff_thread_progress_await(const ThreadProgress *pro_c, int n)
This function is a no-op in no-op mode; otherwise it waits until other threads have reached a certain...
Definition: threadprogress.c:64
AV_PKT_DATA_EXIF
@ AV_PKT_DATA_EXIF
Extensible image file format metadata.
Definition: packet.h:369
ff_decode_exif_attach_ifd
int ff_decode_exif_attach_ifd(AVCodecContext *avctx, AVFrame *frame, const AVExifMetadata *ifd)
Definition: decode.c:2492
av_bsf_init
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:147
utf8_check
static int utf8_check(const uint8_t *str)
Definition: decode.c:916
NULL
#define NULL
Definition: coverity.c:32
exif_internal.h
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
format
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
Definition: swscale-v2.txt:14
AVCodecContext::apply_cropping
int apply_cropping
Video decoding only.
Definition: avcodec.h:1814
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:681
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AV_EXIF_TIFF_HEADER
@ AV_EXIF_TIFF_HEADER
The TIFF header starts with 0x49492a00, or 0x4d4d002a.
Definition: exif.h:62
hwaccel_internal.h
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:228
AVPACKET_IS_EMPTY
#define AVPACKET_IS_EMPTY(pkt)
Definition: packet_internal.h:26
AVCodec::type
enum AVMediaType type
Definition: codec.h:182
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVCodecContext::nb_coded_side_data
int nb_coded_side_data
Definition: avcodec.h:1769
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:478
av_frame_side_data_remove
void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type from an array.
Definition: side_data.c:108
FF_CODEC_CB_TYPE_DECODE_SUB
@ FF_CODEC_CB_TYPE_DECODE_SUB
Definition: codec_internal.h:112
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
AV_CODEC_PROP_BITMAP_SUB
#define AV_CODEC_PROP_BITMAP_SUB
Subtitle codec is bitmap based Decoded AVSubtitle data can be read from the AVSubtitleRect->pict fiel...
Definition: codec_desc.h:111
AV_FRAME_DATA_ICC_PROFILE
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition: frame.h:144
av_refstruct_pool_alloc_ext
static AVRefStructPool * av_refstruct_pool_alloc_ext(size_t size, unsigned flags, void *opaque, int(*init_cb)(AVRefStructOpaque opaque, void *obj), void(*reset_cb)(AVRefStructOpaque opaque, void *obj), void(*free_entry_cb)(AVRefStructOpaque opaque, void *obj), void(*free_cb)(AVRefStructOpaque opaque))
A wrapper around av_refstruct_pool_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition: refstruct.h:258
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition: frame.h:120
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
FFLCEVCFrame::lcevc
FFLCEVCContext * lcevc
Definition: lcevcdec.h:49
AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR
#define AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR
If this flag is set and both init_cb and free_entry_cb callbacks are provided, then free_cb will be c...
Definition: refstruct.h:213
DecodeContext::pts_correction_last_dts
int64_t pts_correction_last_dts
PTS of the last frame.
Definition: decode.c:91
AV_CODEC_FLAG2_ICC_PROFILES
#define AV_CODEC_FLAG2_ICC_PROFILES
Generate/parse ICC profiles on encode/decode, as appropriate for the type of file.
Definition: avcodec.h:382
ff_icc_profile_detect_transfer
int ff_icc_profile_detect_transfer(FFIccContext *s, cmsHPROFILE profile, enum AVColorTransferCharacteristic *out_trc)
Attempt detecting the transfer characteristic that best approximates the transfer function encoded by...
Definition: fflcms2.c:300
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: packet.c:442
AVCodecInternal::draining_done
int draining_done
Definition: internal.h:146
FF_HW_HAS_CB
#define FF_HW_HAS_CB(avctx, function)
Definition: hwaccel_internal.h:179
UTF8_MAX_BYTES
#define UTF8_MAX_BYTES
Definition: decode.c:854
AV_FRAME_DATA_AFD
@ AV_FRAME_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: frame.h:90
ff_sd_global_map
const SideDataMap ff_sd_global_map[]
A map between packet and frame side data types.
Definition: avcodec.c:57
av_exif_remove_entry
int av_exif_remove_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int flags)
Remove an entry from the provided EXIF metadata struct.
Definition: exif.c:1272
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:749
AV_CODEC_EXPORT_DATA_ENHANCEMENTS
#define AV_CODEC_EXPORT_DATA_ENHANCEMENTS
Decoding only.
Definition: avcodec.h:410
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVCodecInternal::last_pkt_props
AVPacket * last_pkt_props
Properties (timestamps+side data) extracted from the last packet passed for decoding.
Definition: internal.h:90
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
AV_PKT_DATA_NB
@ AV_PKT_DATA_NB
The number of side data types.
Definition: packet.h:394
progress_frame_pool_free_entry_cb
static av_cold void progress_frame_pool_free_entry_cb(AVRefStructOpaque opaque, void *obj)
Definition: decode.c:2021
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition: codec.h:276
packet_internal.h
attribute_align_arg
#define attribute_align_arg
Definition: internal.h:50
av_codec_is_decoder
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:85
av_sat_sub64
#define av_sat_sub64
Definition: common.h:142
AVCodecContext::lowres
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:1702
Frame::format
int format
Definition: ffplay.c:162
f
f
Definition: af_crystalizer.c:122
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:507
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1777
SideDataMap::packet
enum AVPacketSideDataType packet
Definition: avcodec_internal.h:35
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:49
AV_CODEC_HW_CONFIG_METHOD_AD_HOC
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:305
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:302
AVPacket::size
int size
Definition: packet.h:604
ff_progress_frame_alloc
int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f)
This function sets up the ProgressFrame, i.e.
Definition: decode.c:1925
dc
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
Definition: snow.txt:400
byte
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
Definition: bytestream.h:99
ff_decode_exif_attach_buffer
int ff_decode_exif_attach_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferRef **pbuf, enum AVExifHeaderMode header_mode)
Attach the data buffer to the frame.
Definition: decode.c:2498
height
#define height
Definition: dsp.h:89
AVCodecContext::extra_hw_frames
int extra_hw_frames
Video decoding only.
Definition: avcodec.h:1516
codec_internal.h
FrameDecodeData::post_process
int(* post_process)(void *logctx, AVFrame *frame)
The callback to perform some delayed processing on the frame right before it is returned to the calle...
Definition: decode.h:44
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:130
decode_data_free
static void decode_data_free(AVRefStructOpaque unused, void *obj)
Definition: decode.c:1691
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:200
AV_PKT_DATA_DYNAMIC_HDR10_PLUS
@ AV_PKT_DATA_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
Definition: packet.h:296
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
AVExifEntry::id
uint16_t id
Definition: exif.h:85
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
ff_codec_is_decoder
static int ff_codec_is_decoder(const AVCodec *avcodec)
Internal version of av_codec_is_decoder().
Definition: codec_internal.h:326
FF_CODEC_CAP_SETS_FRAME_PROPS
#define FF_CODEC_CAP_SETS_FRAME_PROPS
Codec handles output frame properties internally instead of letting the internal logic derive them fr...
Definition: codec_internal.h:78
AVCodecInternal::bsf
struct AVBSFContext * bsf
Definition: internal.h:84
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1047
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
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:554
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
FF_CODEC_CAP_EXPORTS_CROPPING
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
Definition: codec_internal.h:61
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
frame_validate
static int frame_validate(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:791
ff_frame_new_side_data
int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, size_t size, AVFrameSideData **psd)
Wrapper around av_frame_new_side_data, which rejects side data overridden by the demuxer.
Definition: decode.c:2184
ff_frame_new_side_data_from_buf_ext
int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf)
Same as ff_frame_new_side_data_from_buf, but taking a AVFrameSideData array directly instead of an AV...
Definition: decode.c:2203
side_data_pref
static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type)
Check side data preference and clear existing side data from frame if needed.
Definition: decode.c:2168
AVFrameSideData::data
uint8_t * data
Definition: frame.h:329
ffcodec
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
Definition: codec_internal.h:307
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:535
fill_frame_props
static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:574
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:803
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:559
AVCodecHWConfigInternal
Definition: hwconfig.h:25
AV_PICTURE_TYPE_NONE
@ AV_PICTURE_TYPE_NONE
Undefined.
Definition: avutil.h:277
av_buffer_make_writable
int av_buffer_make_writable(AVBufferRef **pbuf)
Create a writable reference from a given buffer reference, avoiding data copy if possible.
Definition: buffer.c:165
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2090
frame.h
av_packet_unpack_dictionary
int av_packet_unpack_dictionary(const uint8_t *data, size_t size, AVDictionary **dict)
Unpack a dictionary from side_data.
Definition: packet.c:354
FFCodec::cb
union FFCodec::@115 cb
av_frame_remove_side_data
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:725
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:602
av_refstruct_ref
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition: refstruct.c:140
ProgressInternal::progress
ThreadProgress progress
Definition: decode.c:1915
AV_PRIMARY_EYE_NONE
@ AV_PRIMARY_EYE_NONE
Neither eye.
Definition: stereo3d.h:178
av_content_light_metadata_create_side_data
AVContentLightMetadata * av_content_light_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVContentLightMetadata and add it to the frame.
Definition: mastering_display_metadata.c:83
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
SideDataMap::frame
enum AVFrameSideDataType frame
Definition: avcodec_internal.h:36
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:609
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
ff_progress_frame_await
void ff_progress_frame_await(const ProgressFrame *f, int n)
Wait for earlier decoding threads to finish reference frames.
Definition: decode.c:1984
AVCodecInternal
Definition: internal.h:49
FFCodec::hw_configs
const struct AVCodecHWConfigInternal *const * hw_configs
Array of pointers to hardware configurations supported by the codec, or NULL if no hardware supported...
Definition: codec_internal.h:270
DecodeContext::side_data_pref_mask
uint64_t side_data_pref_mask
DTS of the last frame.
Definition: decode.c:97
FF_THREAD_NO_FRAME_THREADING
@ FF_THREAD_NO_FRAME_THREADING
Definition: thread.h:63
packet_side_data_get
static const AVPacketSideData * packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Definition: decode.c:1368
AVCodecContext::nb_side_data_prefer_packet
unsigned nb_side_data_prefer_packet
Number of entries in side_data_prefer_packet.
Definition: avcodec.h:1917
detect_colorspace
static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f)
Definition: decode.c:568
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1590
AV_FRAME_DATA_SKIP_SAMPLES
@ AV_FRAME_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
Definition: frame.h:109
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
av_mastering_display_metadata_alloc_size
AVMasteringDisplayMetadata * av_mastering_display_metadata_alloc_size(size_t *size)
Allocate an AVMasteringDisplayMetadata structure and set its fields to default values.
Definition: mastering_display_metadata.c:44
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:1954
AV_PKT_DATA_STRINGS_METADATA
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
Definition: packet.h:169
emms.h
AVCodecInternal::is_frame_mt
int is_frame_mt
This field is set to 1 when frame threading is being used and the parent AVCodecContext of this AVCod...
Definition: internal.h:61
avcodec_send_packet
int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:730
FFCodec::caps_internal
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
Definition: codec_internal.h:136
extract_packet_props
static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
Definition: decode.c:178
av_packet_copy_props
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
Definition: packet.c:397
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: frame.h:137
AVSubtitle::format
uint16_t format
Definition: avcodec.h:2088
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:596
av_frame_side_data_free
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
Definition: side_data.c:139
ff_decode_internal_alloc
av_cold AVCodecInternal * ff_decode_internal_alloc(void)
Definition: decode.c:2385
reget_buffer_internal
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition: decode.c:1850
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: packet.c:252
internal.h
ff_decode_receive_frame_internal
int ff_decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
Do the actual decoding and obtain a decoded frame from the decoder, if available.
Definition: decode.c:625
AVExifMetadata::entries
AVExifEntry * entries
Definition: exif.h:77
common.h
AVCodecInternal::in_pkt
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
Definition: internal.h:83
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:58
ff_thread_progress_init
av_cold int ff_thread_progress_init(ThreadProgress *pro, int init_mode)
Initialize a ThreadProgress.
Definition: threadprogress.c:33
AV_FRAME_DATA_STEREO3D
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
Definition: frame.h:64
DecodeContext::avci
AVCodecInternal avci
Definition: decode.c:64
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:523
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:496
AVExifMetadata::count
unsigned int count
Definition: exif.h:79
AVCodecContext::hw_device_ctx
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:1493
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
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:688
AVExifEntry::uint
uint64_t * uint
Definition: exif.h:108
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
Frame::frame
AVFrame * frame
Definition: ffplay.c:154
uninit
static av_cold void uninit(AVBitStreamFilterContext *ctx)
Definition: lcevc_merge.c:135
FF_CODEC_CAP_SETS_PKT_DTS
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
Definition: codec_internal.h:50
exif.h
profile
int profile
Definition: mxfenc.c:2299
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:709
AVCodecContext::height
int height
Definition: avcodec.h:604
decode_simple_internal
static int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:428
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:643
AVCodecContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition: avcodec.h:1471
avcodec.h
FFCodec::decode_sub
int(* decode_sub)(struct AVCodecContext *avctx, struct AVSubtitle *sub, int *got_frame_ptr, const struct AVPacket *avpkt)
Decode subtitle data to an AVSubtitle.
Definition: codec_internal.h:210
AVCodecContext::sub_charenc_mode
int sub_charenc_mode
Subtitles character encoding mode.
Definition: avcodec.h:1724
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:1883
avcodec_get_hw_frames_parameters
int avcodec_get_hw_frames_parameters(AVCodecContext *avctx, AVBufferRef *device_ref, enum AVPixelFormat hw_pix_fmt, AVBufferRef **out_frames_ref)
Create and return a AVHWFramesContext with values adequate for hardware decoding.
Definition: decode.c:1120
ff_reget_buffer
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
Definition: decode.c:1906
ret
ret
Definition: filter_design.txt:187
AVHWDeviceContext::type
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:75
AVALPHA_MODE_UNSPECIFIED
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
Definition: pixfmt.h:817
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:265
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:137
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1375
AV_CODEC_PROP_TEXT_SUB
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: codec_desc.h:116
av_channel_layout_check
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
Definition: channel_layout.c:785
ff_thread_sync_ref
enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset)
Allows to synchronize objects whose lifetime is the whole decoding process among all frame threads.
Definition: decode.c:1990
hwaccel
static const char * hwaccel
Definition: ffplay.c:356
ff_decode_content_light_new
int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, AVContentLightMetadata **clm)
Wrapper around av_content_light_metadata_create_side_data(), which rejects side data overridden by th...
Definition: decode.c:2308
ff_thread_progress_destroy
av_cold void ff_thread_progress_destroy(ThreadProgress *pro)
Destroy a ThreadProgress.
Definition: threadprogress.c:44
AVPacket::side_data
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:614
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
av_sat_add64
#define av_sat_add64
Definition: common.h:139
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
AV_FRAME_CROP_UNALIGNED
@ AV_FRAME_CROP_UNALIGNED
Apply the maximum possible cropping, even if it requires setting the AVFrame.data[] entries to unalig...
Definition: frame.h:1047
ff_progress_frame_replace
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is ...
Definition: decode.c:1969
apply_param_change
static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
Definition: decode.c:117
ff_decode_frame_props
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition: decode.c:1598
AV_FRAME_DATA_DYNAMIC_HDR_PLUS
@ AV_FRAME_DATA_DYNAMIC_HDR_PLUS
HDR dynamic metadata associated with a video frame.
Definition: frame.h:159
AVCodecContext
main external API structure.
Definition: avcodec.h:443
AVFrame::height
int height
Definition: frame.h:544
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1598
recode_subtitle
static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt, const AVPacket *inpkt, AVPacket *buf_pkt)
Definition: decode.c:855
channel_layout.h
av_mastering_display_metadata_create_side_data
AVMasteringDisplayMetadata * av_mastering_display_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVMasteringDisplayMetadata and add it to the frame.
Definition: mastering_display_metadata.c:59
avcodec_internal.h
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: side_data.c:204
ff_decode_flush_buffers
av_cold void ff_decode_flush_buffers(AVCodecContext *avctx)
Definition: decode.c:2365
av_refstruct_replace
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
av_image_copy2
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition: imgutils.h:184
attach_displaymatrix
static int attach_displaymatrix(AVCodecContext *avctx, AVFrame *frame, int orientation)
Definition: decode.c:2416
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
Definition: codec.h:289
ffhwaccel
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
Definition: hwaccel_internal.h:168
side_data_stereo3d_merge
static int side_data_stereo3d_merge(AVFrameSideData *sd_frame, const AVPacketSideData *sd_pkt)
Definition: decode.c:1384
decode_receive_frame_internal
static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame, unsigned flags)
Definition: decode.c:661
AV_PKT_DATA_AFD
@ AV_PKT_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: packet.h:258
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
ff_decode_preinit
av_cold int ff_decode_preinit(AVCodecContext *avctx)
Perform decoder initialization and validation.
Definition: decode.c:2029
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
Definition: packet.h:153
AVCodecContext::export_side_data
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition: avcodec.h:1779
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:73
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:41
FF_CODEC_CB_TYPE_RECEIVE_FRAME
@ FF_CODEC_CB_TYPE_RECEIVE_FRAME
Definition: codec_internal.h:115
ProgressInternal::f
struct AVFrame * f
Definition: decode.c:1916
ff_thread_progress_reset
static void ff_thread_progress_reset(ThreadProgress *pro)
Reset the ThreadProgress.progress counter; must only be called if the ThreadProgress is not in use in...
Definition: threadprogress.h:72
FFCodec::cb_type
unsigned cb_type
This field determines the type of the codec (decoder/encoder) and also the exact callback cb implemen...
Definition: codec_internal.h:160
ff_thread_receive_frame
#define ff_thread_receive_frame(avctx, frame, flags)
Definition: decode.c:226
avcodec_get_hw_config
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
Definition: utils.c:857
AVCodecInternal::buffer_frame
AVFrame * buffer_frame
Definition: internal.h:145
AV_CODEC_CAP_PARAM_CHANGE
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition: codec.h:100
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:450
ff_decode_receive_frame
int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame, unsigned flags)
avcodec_receive_frame() implementation for decoders.
Definition: decode.c:817
AVCodecInternal::draining
int draining
decoding: AVERROR_EOF has been returned from ff_decode_get_packet(); must not be used by decoders tha...
Definition: internal.h:139
FFCodec::bsfs
const char * bsfs
Decoding only, a comma-separated list of bitstream filters to apply to packets before decoding.
Definition: codec_internal.h:261
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:619
progress_frame_pool_reset_cb
static void progress_frame_pool_reset_cb(AVRefStructOpaque unused, void *obj)
Definition: decode.c:2013
AVHWFramesContext::initial_pool_size
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:190
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:451
AV_FRAME_FLAG_DISCARD
#define AV_FRAME_FLAG_DISCARD
A flag to mark the frames which need to be decoded, but shouldn't be output.
Definition: frame.h:691
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
av_bsf_list_parse_str
int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
Parse string describing list of bitstream filters and create single AVBSFContext describing the whole...
Definition: bsf.c:524
ff_decode_mastering_display_new_ext
int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, struct AVMasteringDisplayMetadata **mdm)
Same as ff_decode_mastering_display_new, but taking a AVFrameSideData array directly instead of an AV...
Definition: decode.c:2231
side_data_map
static int side_data_map(AVFrame *dst, const AVPacketSideData *sd_src, int nb_sd_src, const SideDataMap *map)
Definition: decode.c:1492
AV_PKT_DATA_A53_CC
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: packet.h:239
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AV_CODEC_EXPORT_DATA_MVS
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:390
ff_icc_profile_sanitize
int ff_icc_profile_sanitize(FFIccContext *s, cmsHPROFILE profile)
Sanitize an ICC profile to try and fix badly broken values.
Definition: fflcms2.c:211
mastering_display_metadata.h
ThreadingStatus
ThreadingStatus
Definition: thread.h:60
AVCodecParameters::avcodec_parameters_from_context
int avcodec_parameters_from_context(struct AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:138
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:327
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
AV_CODEC_FLAG2_EXPORT_MVS
#define AV_CODEC_FLAG2_EXPORT_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:368
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
ProgressFrame
The ProgressFrame structure.
Definition: progressframe.h:73
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
SideDataMap
Definition: avcodec_internal.h:34
AVPacket
This structure stores compressed data.
Definition: packet.h:580
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_PKT_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
@ AV_PKT_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
HDR dynamic metadata associated with a video frame.
Definition: packet.h:376
DecodeContext::pts_correction_num_faulty_pts
int64_t pts_correction_num_faulty_pts
Definition: decode.c:88
av_exif_get_entry
int av_exif_get_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int flags, AVExifEntry **value)
Get an entry with the tagged ID from the EXIF metadata struct.
Definition: exif.c:1173
av_frame_side_data_get
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
Definition: frame.h:1196
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:604
AV_FRAME_DATA_EXIF
@ AV_FRAME_DATA_EXIF
Exchangeable image file format metadata.
Definition: frame.h:263
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Definition: decode.h:54
imgutils.h
hwcontext.h
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
AVCodecHWConfig
Definition: codec.h:308
AVStereo3D
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition: stereo3d.h:203
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:650
av_image_check_sar
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar)
Check if the given sample aspect ratio of an image is valid.
Definition: imgutils.c:323
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
ff_copy_palette
int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
Check whether the side-data of src contains a palette of size AVPALETTE_SIZE; if so,...
Definition: decode.c:2321
width
#define width
Definition: dsp.h:89
AVCodecHWConfigInternal::public
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:30
decode_bsfs_init
static int decode_bsfs_init(AVCodecContext *avctx)
Definition: decode.c:189
FFLCEVCFrame
Definition: lcevcdec.h:48
codec_desc.h
AV_PIX_FMT_FLAG_PAL
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:120
side_data_exif_parse
static int side_data_exif_parse(AVFrame *dst, const AVPacketSideData *sd_pkt)
Definition: decode.c:1420
AV_PKT_DATA_IAMF_MIX_GAIN_PARAM
@ AV_PKT_DATA_IAMF_MIX_GAIN_PARAM
IAMF Mix Gain Parameter Data associated with the audio frame.
Definition: packet.h:304
FFLCEVCFrame::frame
struct AVFrame * frame
Definition: lcevcdec.h:50
AVHWAccel::pix_fmt
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:1975
AVCodecContext::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition: avcodec.h:628
DecodeContext
Definition: decode.c:63
av_frame_side_data_add
AVFrameSideData * av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf, unsigned int flags)
Add a new side data entry to an array from an existing AVBufferRef.
Definition: side_data.c:229
FF_REGET_BUFFER_FLAG_READONLY
#define FF_REGET_BUFFER_FLAG_READONLY
the returned buffer does not need to be writable
Definition: decode.h:137
src
#define src
Definition: vp8dsp.c:248
Frame::height
int height
Definition: ffplay.c:161
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:615
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3380
FF_SUB_CHARENC_MODE_IGNORE
#define FF_SUB_CHARENC_MODE_IGNORE
neither convert the subtitles, nor check them for valid UTF-8
Definition: avcodec.h:1728
min
float min
Definition: vorbis_enc_data.h:429
AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
@ AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
IAMF Demixing Info Parameter Data associated with the audio frame.
Definition: packet.h:312