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 <stdint.h>
22 #include <stdbool.h>
23 #include <string.h>
24 
25 #include "config.h"
26 
27 #if CONFIG_ICONV
28 # include <iconv.h>
29 #endif
30 
31 #include "libavutil/avassert.h"
33 #include "libavutil/common.h"
34 #include "libavutil/emms.h"
35 #include "libavutil/frame.h"
36 #include "libavutil/hwcontext.h"
37 #include "libavutil/imgutils.h"
38 #include "libavutil/internal.h"
40 #include "libavutil/mem.h"
41 #include "libavutil/stereo3d.h"
42 
43 #include "avcodec.h"
44 #include "avcodec_internal.h"
45 #include "bytestream.h"
46 #include "bsf.h"
47 #include "codec_desc.h"
48 #include "codec_internal.h"
49 #include "decode.h"
50 #include "exif_internal.h"
51 #include "hwaccel_internal.h"
52 #include "hwconfig.h"
53 #include "internal.h"
54 #include "lcevcdec.h"
55 #include "packet_internal.h"
56 #include "progressframe.h"
57 #include "libavutil/refstruct.h"
58 #include "thread.h"
59 #include "threadprogress.h"
60 
61 typedef struct DecodeContext {
63 
64  /**
65  * This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats
66  * (those whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set)
67  * to set the flag generically.
68  */
70 
71  /**
72  * This is set to AV_PICTURE_TYPE_I for intra only video decoders
73  * and to AV_PICTURE_TYPE_NONE for other decoders. It is used to set
74  * the AVFrame's pict_type before the decoder receives it.
75  */
77 
78  /* to prevent infinite loop on errors when draining */
80 
81  /**
82  * The caller has submitted a NULL packet on input.
83  */
85 
86  int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
87  int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
88  int64_t pts_correction_last_pts; /// PTS of the last frame
89  int64_t pts_correction_last_dts; /// DTS of the last frame
90 
91  /**
92  * Bitmask indicating for which side data types we prefer user-supplied
93  * (global or attached to packets) side data over bytestream.
94  */
96 
99  int width;
100  int height;
101 } DecodeContext;
102 
104 {
105  return (DecodeContext *)avci;
106 }
107 
108 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
109 {
110  int ret;
111  size_t size;
112  const uint8_t *data;
113  uint32_t flags;
114  int64_t val;
115 
117  if (!data)
118  return 0;
119 
120  if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) {
121  av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
122  "changes, but PARAM_CHANGE side data was sent to it.\n");
123  ret = AVERROR(EINVAL);
124  goto fail2;
125  }
126 
127  if (size < 4)
128  goto fail;
129 
130  flags = bytestream_get_le32(&data);
131  size -= 4;
132 
134  if (size < 4)
135  goto fail;
136  val = bytestream_get_le32(&data);
137  if (val <= 0 || val > INT_MAX) {
138  av_log(avctx, AV_LOG_ERROR, "Invalid sample rate");
140  goto fail2;
141  }
142  avctx->sample_rate = val;
143  size -= 4;
144  }
146  if (size < 8)
147  goto fail;
148  avctx->width = bytestream_get_le32(&data);
149  avctx->height = bytestream_get_le32(&data);
150  size -= 8;
151  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
152  if (ret < 0)
153  goto fail2;
154  }
155 
156  return 0;
157 fail:
158  av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
160 fail2:
161  if (ret < 0) {
162  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
163  if (avctx->err_recognition & AV_EF_EXPLODE)
164  return ret;
165  }
166  return 0;
167 }
168 
170 {
171  int ret = 0;
172 
174  if (pkt) {
176  }
177  return ret;
178 }
179 
181 {
182  AVCodecInternal *avci = avctx->internal;
183  const FFCodec *const codec = ffcodec(avctx->codec);
184  int ret;
185 
186  if (avci->bsf)
187  return 0;
188 
189  ret = av_bsf_list_parse_str(codec->bsfs, &avci->bsf);
190  if (ret < 0) {
191  av_log(avctx, AV_LOG_ERROR, "Error parsing decoder bitstream filters '%s': %s\n", codec->bsfs, av_err2str(ret));
192  if (ret != AVERROR(ENOMEM))
193  ret = AVERROR_BUG;
194  goto fail;
195  }
196 
197  /* We do not currently have an API for passing the input timebase into decoders,
198  * but no filters used here should actually need it.
199  * So we make up some plausible-looking number (the MPEG 90kHz timebase) */
200  avci->bsf->time_base_in = (AVRational){ 1, 90000 };
202  if (ret < 0)
203  goto fail;
204 
205  ret = av_bsf_init(avci->bsf);
206  if (ret < 0)
207  goto fail;
208 
209  return 0;
210 fail:
211  av_bsf_free(&avci->bsf);
212  return ret;
213 }
214 
215 #if !HAVE_THREADS
216 #define ff_thread_get_packet(avctx, pkt) (AVERROR_BUG)
217 #define ff_thread_receive_frame(avctx, frame) (AVERROR_BUG)
218 #endif
219 
221 {
222  AVCodecInternal *avci = avctx->internal;
223  int ret;
224 
225  ret = av_bsf_receive_packet(avci->bsf, pkt);
226  if (ret < 0)
227  return ret;
228 
231  if (ret < 0)
232  goto finish;
233  }
234 
235  ret = apply_param_change(avctx, pkt);
236  if (ret < 0)
237  goto finish;
238 
239  return 0;
240 finish:
242  return ret;
243 }
244 
246 {
247  AVCodecInternal *avci = avctx->internal;
248  DecodeContext *dc = decode_ctx(avci);
249 
250  if (avci->draining)
251  return AVERROR_EOF;
252 
253  /* If we are a worker thread, get the next packet from the threading
254  * context. Otherwise we are the main (user-facing) context, so we get the
255  * next packet from the input filterchain.
256  */
257  if (avctx->internal->is_frame_mt)
258  return ff_thread_get_packet(avctx, pkt);
259 
260  while (1) {
261  int ret = decode_get_packet(avctx, pkt);
262  if (ret == AVERROR(EAGAIN) &&
263  (!AVPACKET_IS_EMPTY(avci->buffer_pkt) || dc->draining_started)) {
264  ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
265  if (ret >= 0)
266  continue;
267 
269  }
270 
271  if (ret == AVERROR_EOF)
272  avci->draining = 1;
273  return ret;
274  }
275 }
276 
277 /**
278  * Attempt to guess proper monotonic timestamps for decoded video frames
279  * which might have incorrect times. Input timestamps may wrap around, in
280  * which case the output will as well.
281  *
282  * @param pts the pts field of the decoded AVPacket, as passed through
283  * AVFrame.pts
284  * @param dts the dts field of the decoded AVPacket
285  * @return one of the input values, may be AV_NOPTS_VALUE
286  */
288  int64_t reordered_pts, int64_t dts)
289 {
291 
292  if (dts != AV_NOPTS_VALUE) {
293  dc->pts_correction_num_faulty_dts += dts <= dc->pts_correction_last_dts;
294  dc->pts_correction_last_dts = dts;
295  } else if (reordered_pts != AV_NOPTS_VALUE)
296  dc->pts_correction_last_dts = reordered_pts;
297 
298  if (reordered_pts != AV_NOPTS_VALUE) {
299  dc->pts_correction_num_faulty_pts += reordered_pts <= dc->pts_correction_last_pts;
300  dc->pts_correction_last_pts = reordered_pts;
301  } else if(dts != AV_NOPTS_VALUE)
302  dc->pts_correction_last_pts = dts;
303 
304  if ((dc->pts_correction_num_faulty_pts<=dc->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
305  && reordered_pts != AV_NOPTS_VALUE)
306  pts = reordered_pts;
307  else
308  pts = dts;
309 
310  return pts;
311 }
312 
313 static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
314 {
315  AVCodecInternal *avci = avctx->internal;
316  AVFrameSideData *side;
317  uint32_t discard_padding = 0;
318  uint8_t skip_reason = 0;
319  uint8_t discard_reason = 0;
320 
322  if (side && side->size >= 10) {
323  avci->skip_samples = AV_RL32(side->data);
324  avci->skip_samples = FFMAX(0, avci->skip_samples);
325  discard_padding = AV_RL32(side->data + 4);
326  av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
327  avci->skip_samples, (int)discard_padding);
328  skip_reason = AV_RL8(side->data + 8);
329  discard_reason = AV_RL8(side->data + 9);
330  }
331 
332  if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
333  if (!side && (avci->skip_samples || discard_padding))
335  if (side && (avci->skip_samples || discard_padding)) {
336  AV_WL32(side->data, avci->skip_samples);
337  AV_WL32(side->data + 4, discard_padding);
338  AV_WL8(side->data + 8, skip_reason);
339  AV_WL8(side->data + 9, discard_reason);
340  avci->skip_samples = 0;
341  }
342  return 0;
343  }
345 
346  if ((frame->flags & AV_FRAME_FLAG_DISCARD)) {
347  avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
348  *discarded_samples += frame->nb_samples;
349  return AVERROR(EAGAIN);
350  }
351 
352  if (avci->skip_samples > 0) {
353  if (frame->nb_samples <= avci->skip_samples){
354  *discarded_samples += frame->nb_samples;
355  avci->skip_samples -= frame->nb_samples;
356  av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
357  avci->skip_samples);
358  return AVERROR(EAGAIN);
359  } else {
360  av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
361  frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
362  if (avctx->pkt_timebase.num && avctx->sample_rate) {
363  int64_t diff_ts = av_rescale_q(avci->skip_samples,
364  (AVRational){1, avctx->sample_rate},
365  avctx->pkt_timebase);
366  if (frame->pts != AV_NOPTS_VALUE)
367  frame->pts += diff_ts;
368  if (frame->pkt_dts != AV_NOPTS_VALUE)
369  frame->pkt_dts += diff_ts;
370  if (frame->duration >= diff_ts)
371  frame->duration -= diff_ts;
372  } else
373  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
374 
375  av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
376  avci->skip_samples, frame->nb_samples);
377  *discarded_samples += avci->skip_samples;
378  frame->nb_samples -= avci->skip_samples;
379  avci->skip_samples = 0;
380  }
381  }
382 
383  if (discard_padding > 0 && discard_padding <= frame->nb_samples) {
384  if (discard_padding == frame->nb_samples) {
385  *discarded_samples += frame->nb_samples;
386  return AVERROR(EAGAIN);
387  } else {
388  if (avctx->pkt_timebase.num && avctx->sample_rate) {
389  int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
390  (AVRational){1, avctx->sample_rate},
391  avctx->pkt_timebase);
392  frame->duration = diff_ts;
393  } else
394  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
395 
396  av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
397  (int)discard_padding, frame->nb_samples);
398  frame->nb_samples -= discard_padding;
399  }
400  }
401 
402  return 0;
403 }
404 
405 /*
406  * The core of the receive_frame_wrapper for the decoders implementing
407  * the simple API. Certain decoders might consume partial packets without
408  * returning any output, so this function needs to be called in a loop until it
409  * returns EAGAIN.
410  **/
411 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
412 {
413  AVCodecInternal *avci = avctx->internal;
414  DecodeContext *dc = decode_ctx(avci);
415  AVPacket *const pkt = avci->in_pkt;
416  const FFCodec *const codec = ffcodec(avctx->codec);
417  int got_frame, consumed;
418  int ret;
419 
420  if (!pkt->data && !avci->draining) {
422  ret = ff_decode_get_packet(avctx, pkt);
423  if (ret < 0 && ret != AVERROR_EOF)
424  return ret;
425  }
426 
427  // Some codecs (at least wma lossless) will crash when feeding drain packets
428  // after EOF was signaled.
429  if (avci->draining_done)
430  return AVERROR_EOF;
431 
432  if (!pkt->data &&
434  return AVERROR_EOF;
435 
436  got_frame = 0;
437 
438  frame->pict_type = dc->initial_pict_type;
439  frame->flags |= dc->intra_only_flag;
440  consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
441 
443  frame->pkt_dts = pkt->dts;
444  emms_c();
445 
446  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
447  ret = (!got_frame || frame->flags & AV_FRAME_FLAG_DISCARD)
448  ? AVERROR(EAGAIN)
449  : 0;
450  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
451  ret = !got_frame ? AVERROR(EAGAIN)
452  : discard_samples(avctx, frame, discarded_samples);
453  } else
454  av_assert0(0);
455 
456  if (ret == AVERROR(EAGAIN))
458 
459  // FF_CODEC_CB_TYPE_DECODE decoders must not return AVERROR EAGAIN
460  // code later will add AVERROR(EAGAIN) to a pointer
461  av_assert0(consumed != AVERROR(EAGAIN));
462  if (consumed < 0)
463  ret = consumed;
464  if (consumed >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
465  consumed = pkt->size;
466 
467  if (!ret)
468  av_assert0(frame->buf[0]);
469  if (ret == AVERROR(EAGAIN))
470  ret = 0;
471 
472  /* do not stop draining when got_frame != 0 or ret < 0 */
473  if (avci->draining && !got_frame) {
474  if (ret < 0) {
475  /* prevent infinite loop if a decoder wrongly always return error on draining */
476  /* reasonable nb_errors_max = maximum b frames + thread count */
477  int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
478  avctx->thread_count : 1);
479 
480  if (decode_ctx(avci)->nb_draining_errors++ >= nb_errors_max) {
481  av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
482  "Stop draining and force EOF.\n");
483  avci->draining_done = 1;
484  ret = AVERROR_BUG;
485  }
486  } else {
487  avci->draining_done = 1;
488  }
489  }
490 
491  if (consumed >= pkt->size || ret < 0) {
493  } else {
494  pkt->data += consumed;
495  pkt->size -= consumed;
501  }
502  }
503 
504  return ret;
505 }
506 
507 #if CONFIG_LCMS2
508 static int detect_colorspace(AVCodecContext *avctx, AVFrame *frame)
509 {
510  AVCodecInternal *avci = avctx->internal;
512  AVColorPrimariesDesc coeffs;
513  enum AVColorPrimaries prim;
514  cmsHPROFILE profile;
515  AVFrameSideData *sd;
516  int ret;
517  if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
518  return 0;
519 
521  if (!sd || !sd->size)
522  return 0;
523 
524  if (!avci->icc.avctx) {
525  ret = ff_icc_context_init(&avci->icc, avctx);
526  if (ret < 0)
527  return ret;
528  }
529 
530  profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size);
531  if (!profile)
532  return AVERROR_INVALIDDATA;
533 
534  ret = ff_icc_profile_sanitize(&avci->icc, profile);
535  if (!ret)
536  ret = ff_icc_profile_read_primaries(&avci->icc, profile, &coeffs);
537  if (!ret)
538  ret = ff_icc_profile_detect_transfer(&avci->icc, profile, &trc);
539  cmsCloseProfile(profile);
540  if (ret < 0)
541  return ret;
542 
543  prim = av_csp_primaries_id_from_desc(&coeffs);
544  if (prim != AVCOL_PRI_UNSPECIFIED)
545  frame->color_primaries = prim;
546  if (trc != AVCOL_TRC_UNSPECIFIED)
547  frame->color_trc = trc;
548  return 0;
549 }
550 #else /* !CONFIG_LCMS2 */
552 {
553  return 0;
554 }
555 #endif
556 
557 static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
558 {
559  int ret;
560 
561  if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
562  frame->color_primaries = avctx->color_primaries;
563  if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
564  frame->color_trc = avctx->color_trc;
565  if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
566  frame->colorspace = avctx->colorspace;
567  if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
568  frame->color_range = avctx->color_range;
569  if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
570  frame->chroma_location = avctx->chroma_sample_location;
571 
572  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
573  if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
574  if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
575  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
576  if (frame->format == AV_SAMPLE_FMT_NONE)
577  frame->format = avctx->sample_fmt;
578  if (!frame->ch_layout.nb_channels) {
579  ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
580  if (ret < 0)
581  return ret;
582  }
583  if (!frame->sample_rate)
584  frame->sample_rate = avctx->sample_rate;
585  }
586 
587  return 0;
588 }
589 
591 {
592  int ret;
593  int64_t discarded_samples = 0;
594 
595  while (!frame->buf[0]) {
596  if (discarded_samples > avctx->max_samples)
597  return AVERROR(EAGAIN);
598  ret = decode_simple_internal(avctx, frame, &discarded_samples);
599  if (ret < 0)
600  return ret;
601  }
602 
603  return 0;
604 }
605 
607 {
608  AVCodecInternal *avci = avctx->internal;
609  DecodeContext *dc = decode_ctx(avci);
610  const FFCodec *const codec = ffcodec(avctx->codec);
611  int ret;
612 
613  av_assert0(!frame->buf[0]);
614 
615  if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
616  while (1) {
617  frame->pict_type = dc->initial_pict_type;
618  frame->flags |= dc->intra_only_flag;
619  ret = codec->cb.receive_frame(avctx, frame);
620  emms_c();
621  if (!ret) {
622  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
623  int64_t discarded_samples = 0;
624  ret = discard_samples(avctx, frame, &discarded_samples);
625  }
626  if (ret == AVERROR(EAGAIN) || (frame->flags & AV_FRAME_FLAG_DISCARD)) {
628  continue;
629  }
630  }
631  break;
632  }
633  } else
635 
636  if (ret == AVERROR_EOF)
637  avci->draining_done = 1;
638 
639  return ret;
640 }
641 
643 {
644  AVCodecInternal *avci = avctx->internal;
645  DecodeContext *dc = decode_ctx(avci);
646  int ret, ok;
647 
648  if (avctx->active_thread_type & FF_THREAD_FRAME)
650  else
652 
653  /* preserve ret */
654  ok = detect_colorspace(avctx, frame);
655  if (ok < 0) {
657  return ok;
658  }
659 
660  if (!ret) {
661  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
662  if (!frame->width)
663  frame->width = avctx->width;
664  if (!frame->height)
665  frame->height = avctx->height;
666  }
667 
668  ret = fill_frame_props(avctx, frame);
669  if (ret < 0) {
671  return ret;
672  }
673 
674  frame->best_effort_timestamp = guess_correct_pts(dc,
675  frame->pts,
676  frame->pkt_dts);
677 
678  /* the only case where decode data is not set should be decoders
679  * that do not call ff_get_buffer() */
680  av_assert0(frame->private_ref ||
681  !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
682 
683  if (frame->private_ref) {
684  FrameDecodeData *fdd = frame->private_ref;
685 
686  if (fdd->post_process) {
687  ret = fdd->post_process(avctx, frame);
688  if (ret < 0) {
690  return ret;
691  }
692  }
693  }
694  }
695 
696  /* free the per-frame decode data */
697  av_refstruct_unref(&frame->private_ref);
698 
699  return ret;
700 }
701 
703 {
704  AVCodecInternal *avci = avctx->internal;
705  DecodeContext *dc = decode_ctx(avci);
706  int ret;
707 
708  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
709  return AVERROR(EINVAL);
710 
711  if (dc->draining_started)
712  return AVERROR_EOF;
713 
714  if (avpkt && !avpkt->size && avpkt->data)
715  return AVERROR(EINVAL);
716 
717  if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
718  if (!AVPACKET_IS_EMPTY(avci->buffer_pkt))
719  return AVERROR(EAGAIN);
720  ret = av_packet_ref(avci->buffer_pkt, avpkt);
721  if (ret < 0)
722  return ret;
723  } else
724  dc->draining_started = 1;
725 
726  if (!avci->buffer_frame->buf[0] && !dc->draining_started) {
728  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
729  return ret;
730  }
731 
732  return 0;
733 }
734 
736 {
737  /* make sure we are noisy about decoders returning invalid cropping data */
738  if (frame->crop_left >= INT_MAX - frame->crop_right ||
739  frame->crop_top >= INT_MAX - frame->crop_bottom ||
740  (frame->crop_left + frame->crop_right) >= frame->width ||
741  (frame->crop_top + frame->crop_bottom) >= frame->height) {
742  av_log(avctx, AV_LOG_WARNING,
743  "Invalid cropping information set by a decoder: "
745  "(frame size %dx%d). This is a bug, please report it\n",
746  frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
747  frame->width, frame->height);
748  frame->crop_left = 0;
749  frame->crop_right = 0;
750  frame->crop_top = 0;
751  frame->crop_bottom = 0;
752  return 0;
753  }
754 
755  if (!avctx->apply_cropping)
756  return 0;
757 
760 }
761 
762 // make sure frames returned to the caller are valid
764 {
765  if (!frame->buf[0] || frame->format < 0)
766  goto fail;
767 
768  switch (avctx->codec_type) {
769  case AVMEDIA_TYPE_VIDEO:
770  if (frame->width <= 0 || frame->height <= 0)
771  goto fail;
772  break;
773  case AVMEDIA_TYPE_AUDIO:
774  if (!av_channel_layout_check(&frame->ch_layout) ||
775  frame->sample_rate <= 0)
776  goto fail;
777 
778  break;
779  default: av_assert0(0);
780  }
781 
782  return 0;
783 fail:
784  av_log(avctx, AV_LOG_ERROR, "An invalid frame was output by a decoder. "
785  "This is a bug, please report it.\n");
786  return AVERROR_BUG;
787 }
788 
790 {
791  AVCodecInternal *avci = avctx->internal;
792  int ret;
793 
794  if (avci->buffer_frame->buf[0]) {
796  } else {
798  if (ret < 0)
799  return ret;
800  }
801 
802  ret = frame_validate(avctx, frame);
803  if (ret < 0)
804  goto fail;
805 
806  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
807  ret = apply_cropping(avctx, frame);
808  if (ret < 0)
809  goto fail;
810  }
811 
812  avctx->frame_num++;
813 
814  return 0;
815 fail:
817  return ret;
818 }
819 
821 {
822  memset(sub, 0, sizeof(*sub));
823  sub->pts = AV_NOPTS_VALUE;
824 }
825 
826 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
827 static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt,
828  const AVPacket *inpkt, AVPacket *buf_pkt)
829 {
830 #if CONFIG_ICONV
831  iconv_t cd = (iconv_t)-1;
832  int ret = 0;
833  char *inb, *outb;
834  size_t inl, outl;
835 #endif
836 
837  if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) {
838  *outpkt = inpkt;
839  return 0;
840  }
841 
842 #if CONFIG_ICONV
843  inb = inpkt->data;
844  inl = inpkt->size;
845 
846  if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) {
847  av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
848  return AVERROR(ERANGE);
849  }
850 
851  cd = iconv_open("UTF-8", avctx->sub_charenc);
852  av_assert0(cd != (iconv_t)-1);
853 
854  ret = av_new_packet(buf_pkt, inl * UTF8_MAX_BYTES);
855  if (ret < 0)
856  goto end;
857  ret = av_packet_copy_props(buf_pkt, inpkt);
858  if (ret < 0)
859  goto end;
860  outb = buf_pkt->data;
861  outl = buf_pkt->size;
862 
863  if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
864  iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
865  outl >= buf_pkt->size || inl != 0) {
866  ret = FFMIN(AVERROR(errno), -1);
867  av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
868  "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
869  goto end;
870  }
871  buf_pkt->size -= outl;
872  memset(buf_pkt->data + buf_pkt->size, 0, outl);
873  *outpkt = buf_pkt;
874 
875  ret = 0;
876 end:
877  if (ret < 0)
878  av_packet_unref(buf_pkt);
879  if (cd != (iconv_t)-1)
880  iconv_close(cd);
881  return ret;
882 #else
883  av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
884  return AVERROR(EINVAL);
885 #endif
886 }
887 
888 static int utf8_check(const uint8_t *str)
889 {
890  const uint8_t *byte;
891  uint32_t codepoint, min;
892 
893  while (*str) {
894  byte = str;
895  GET_UTF8(codepoint, *(byte++), return 0;);
896  min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
897  1 << (5 * (byte - str) - 4);
898  if (codepoint < min || codepoint >= 0x110000 ||
899  codepoint == 0xFFFE /* BOM */ ||
900  codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
901  return 0;
902  str = byte;
903  }
904  return 1;
905 }
906 
908  int *got_sub_ptr, const AVPacket *avpkt)
909 {
910  int ret = 0;
911 
912  if (!avpkt->data && avpkt->size) {
913  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
914  return AVERROR(EINVAL);
915  }
916  if (!avctx->codec)
917  return AVERROR(EINVAL);
919  av_log(avctx, AV_LOG_ERROR, "Codec not subtitle decoder\n");
920  return AVERROR(EINVAL);
921  }
922 
923  *got_sub_ptr = 0;
925 
926  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
927  AVCodecInternal *avci = avctx->internal;
928  const AVPacket *pkt;
929 
930  ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
931  if (ret < 0)
932  return ret;
933 
934  if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
935  sub->pts = av_rescale_q(avpkt->pts,
936  avctx->pkt_timebase, AV_TIME_BASE_Q);
937  ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
938  if (pkt == avci->buffer_pkt) // did we recode?
940  if (ret < 0) {
941  *got_sub_ptr = 0;
942  avsubtitle_free(sub);
943  return ret;
944  }
945  av_assert1(!sub->num_rects || *got_sub_ptr);
946 
947  if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
948  avctx->pkt_timebase.num) {
949  AVRational ms = { 1, 1000 };
950  sub->end_display_time = av_rescale_q(avpkt->duration,
951  avctx->pkt_timebase, ms);
952  }
953 
955  sub->format = 0;
956  else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
957  sub->format = 1;
958 
959  for (unsigned i = 0; i < sub->num_rects; i++) {
961  sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
962  av_log(avctx, AV_LOG_ERROR,
963  "Invalid UTF-8 in decoded subtitles text; "
964  "maybe missing -sub_charenc option\n");
965  avsubtitle_free(sub);
966  *got_sub_ptr = 0;
967  return AVERROR_INVALIDDATA;
968  }
969  }
970 
971  if (*got_sub_ptr)
972  avctx->frame_num++;
973  }
974 
975  return ret;
976 }
977 
979  const enum AVPixelFormat *fmt)
980 {
981  const AVPixFmtDescriptor *desc;
982  const AVCodecHWConfig *config;
983  int i, n;
984 
985  // If a device was supplied when the codec was opened, assume that the
986  // user wants to use it.
987  if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
988  AVHWDeviceContext *device_ctx =
990  for (i = 0;; i++) {
991  config = &ffcodec(avctx->codec)->hw_configs[i]->public;
992  if (!config)
993  break;
994  if (!(config->methods &
996  continue;
997  if (device_ctx->type != config->device_type)
998  continue;
999  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1000  if (config->pix_fmt == fmt[n])
1001  return fmt[n];
1002  }
1003  }
1004  }
1005  // No device or other setup, so we have to choose from things which
1006  // don't any other external information.
1007 
1008  // If the last element of the list is a software format, choose it
1009  // (this should be best software format if any exist).
1010  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1011  desc = av_pix_fmt_desc_get(fmt[n - 1]);
1012  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1013  return fmt[n - 1];
1014 
1015  // Finally, traverse the list in order and choose the first entry
1016  // with no external dependencies (if there is no hardware configuration
1017  // information available then this just picks the first entry).
1018  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1019  for (i = 0;; i++) {
1020  config = avcodec_get_hw_config(avctx->codec, i);
1021  if (!config)
1022  break;
1023  if (config->pix_fmt == fmt[n])
1024  break;
1025  }
1026  if (!config) {
1027  // No specific config available, so the decoder must be able
1028  // to handle this format without any additional setup.
1029  return fmt[n];
1030  }
1031  if (config->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
1032  // Usable with only internal setup.
1033  return fmt[n];
1034  }
1035  }
1036 
1037  // Nothing is usable, give up.
1038  return AV_PIX_FMT_NONE;
1039 }
1040 
1042  enum AVHWDeviceType dev_type)
1043 {
1044  AVHWDeviceContext *device_ctx;
1045  AVHWFramesContext *frames_ctx;
1046  int ret;
1047 
1048  if (!avctx->hwaccel)
1049  return AVERROR(ENOSYS);
1050 
1051  if (avctx->hw_frames_ctx)
1052  return 0;
1053  if (!avctx->hw_device_ctx) {
1054  av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
1055  "required for hardware accelerated decoding.\n");
1056  return AVERROR(EINVAL);
1057  }
1058 
1059  device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data;
1060  if (device_ctx->type != dev_type) {
1061  av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware "
1062  "decoding, but got %s.\n", av_hwdevice_get_type_name(dev_type),
1063  av_hwdevice_get_type_name(device_ctx->type));
1064  return AVERROR(EINVAL);
1065  }
1066 
1068  avctx->hw_device_ctx,
1069  avctx->hwaccel->pix_fmt,
1070  &avctx->hw_frames_ctx);
1071  if (ret < 0)
1072  return ret;
1073 
1074  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1075 
1076 
1077  if (frames_ctx->initial_pool_size) {
1078  // We guarantee 4 base work surfaces. The function above guarantees 1
1079  // (the absolute minimum), so add the missing count.
1080  frames_ctx->initial_pool_size += 3;
1081  }
1082 
1084  if (ret < 0) {
1085  av_buffer_unref(&avctx->hw_frames_ctx);
1086  return ret;
1087  }
1088 
1089  return 0;
1090 }
1091 
1093  AVBufferRef *device_ref,
1095  AVBufferRef **out_frames_ref)
1096 {
1097  AVBufferRef *frames_ref = NULL;
1098  const AVCodecHWConfigInternal *hw_config;
1099  const FFHWAccel *hwa;
1100  int i, ret;
1101  bool clean_priv_data = false;
1102 
1103  for (i = 0;; i++) {
1104  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1105  if (!hw_config)
1106  return AVERROR(ENOENT);
1107  if (hw_config->public.pix_fmt == hw_pix_fmt)
1108  break;
1109  }
1110 
1111  hwa = hw_config->hwaccel;
1112  if (!hwa || !hwa->frame_params)
1113  return AVERROR(ENOENT);
1114 
1115  frames_ref = av_hwframe_ctx_alloc(device_ref);
1116  if (!frames_ref)
1117  return AVERROR(ENOMEM);
1118 
1119  if (!avctx->internal->hwaccel_priv_data) {
1120  avctx->internal->hwaccel_priv_data =
1121  av_mallocz(hwa->priv_data_size);
1122  if (!avctx->internal->hwaccel_priv_data) {
1123  av_buffer_unref(&frames_ref);
1124  return AVERROR(ENOMEM);
1125  }
1126  clean_priv_data = true;
1127  }
1128 
1129  ret = hwa->frame_params(avctx, frames_ref);
1130  if (ret >= 0) {
1131  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
1132 
1133  if (frames_ctx->initial_pool_size) {
1134  // If the user has requested that extra output surfaces be
1135  // available then add them here.
1136  if (avctx->extra_hw_frames > 0)
1137  frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1138 
1139  // If frame threading is enabled then an extra surface per thread
1140  // is also required.
1141  if (avctx->active_thread_type & FF_THREAD_FRAME)
1142  frames_ctx->initial_pool_size += avctx->thread_count;
1143  }
1144 
1145  *out_frames_ref = frames_ref;
1146  } else {
1147  if (clean_priv_data)
1149  av_buffer_unref(&frames_ref);
1150  }
1151  return ret;
1152 }
1153 
1154 static int hwaccel_init(AVCodecContext *avctx,
1155  const FFHWAccel *hwaccel)
1156 {
1157  int err;
1158 
1159  if (hwaccel->p.capabilities & AV_HWACCEL_CODEC_CAP_EXPERIMENTAL &&
1161  av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1162  hwaccel->p.name);
1163  return AVERROR_PATCHWELCOME;
1164  }
1165 
1166  if (!avctx->internal->hwaccel_priv_data && hwaccel->priv_data_size) {
1167  avctx->internal->hwaccel_priv_data =
1168  av_mallocz(hwaccel->priv_data_size);
1169  if (!avctx->internal->hwaccel_priv_data)
1170  return AVERROR(ENOMEM);
1171  }
1172 
1173  avctx->hwaccel = &hwaccel->p;
1174  if (hwaccel->init) {
1175  err = hwaccel->init(avctx);
1176  if (err < 0) {
1177  av_log(avctx, AV_LOG_ERROR, "Failed setup for format %s: "
1178  "hwaccel initialisation returned error.\n",
1179  av_get_pix_fmt_name(hwaccel->p.pix_fmt));
1181  avctx->hwaccel = NULL;
1182  return err;
1183  }
1184  }
1185 
1186  return 0;
1187 }
1188 
1190 {
1191  if (FF_HW_HAS_CB(avctx, uninit))
1192  FF_HW_SIMPLE_CALL(avctx, uninit);
1193 
1195 
1196  avctx->hwaccel = NULL;
1197 
1198  av_buffer_unref(&avctx->hw_frames_ctx);
1199 }
1200 
1201 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1202 {
1203  const AVPixFmtDescriptor *desc;
1204  enum AVPixelFormat *choices;
1205  enum AVPixelFormat ret, user_choice;
1206  const AVCodecHWConfigInternal *hw_config;
1207  const AVCodecHWConfig *config;
1208  int i, n, err;
1209 
1210  // Find end of list.
1211  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1212  // Must contain at least one entry.
1213  av_assert0(n >= 1);
1214  // If a software format is available, it must be the last entry.
1215  desc = av_pix_fmt_desc_get(fmt[n - 1]);
1216  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1217  // No software format is available.
1218  } else {
1219  avctx->sw_pix_fmt = fmt[n - 1];
1220  }
1221 
1222  choices = av_memdup(fmt, (n + 1) * sizeof(*choices));
1223  if (!choices)
1224  return AV_PIX_FMT_NONE;
1225 
1226  for (;;) {
1227  // Remove the previous hwaccel, if there was one.
1228  ff_hwaccel_uninit(avctx);
1229 
1230  user_choice = avctx->get_format(avctx, choices);
1231  if (user_choice == AV_PIX_FMT_NONE) {
1232  // Explicitly chose nothing, give up.
1233  ret = AV_PIX_FMT_NONE;
1234  break;
1235  }
1236 
1237  desc = av_pix_fmt_desc_get(user_choice);
1238  if (!desc) {
1239  av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
1240  "get_format() callback.\n");
1241  ret = AV_PIX_FMT_NONE;
1242  break;
1243  }
1244  av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
1245  desc->name);
1246 
1247  for (i = 0; i < n; i++) {
1248  if (choices[i] == user_choice)
1249  break;
1250  }
1251  if (i == n) {
1252  av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
1253  "%s not in possible list.\n", desc->name);
1254  ret = AV_PIX_FMT_NONE;
1255  break;
1256  }
1257 
1258  if (ffcodec(avctx->codec)->hw_configs) {
1259  for (i = 0;; i++) {
1260  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1261  if (!hw_config)
1262  break;
1263  if (hw_config->public.pix_fmt == user_choice)
1264  break;
1265  }
1266  } else {
1267  hw_config = NULL;
1268  }
1269 
1270  if (!hw_config) {
1271  // No config available, so no extra setup required.
1272  ret = user_choice;
1273  break;
1274  }
1275  config = &hw_config->public;
1276 
1277  if (config->methods &
1279  avctx->hw_frames_ctx) {
1280  const AVHWFramesContext *frames_ctx =
1282  if (frames_ctx->format != user_choice) {
1283  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1284  "does not match the format of the provided frames "
1285  "context.\n", desc->name);
1286  goto try_again;
1287  }
1288  } else if (config->methods &
1290  avctx->hw_device_ctx) {
1291  const AVHWDeviceContext *device_ctx =
1293  if (device_ctx->type != config->device_type) {
1294  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1295  "does not match the type of the provided device "
1296  "context.\n", desc->name);
1297  goto try_again;
1298  }
1299  } else if (config->methods &
1301  // Internal-only setup, no additional configuration.
1302  } else if (config->methods &
1304  // Some ad-hoc configuration we can't see and can't check.
1305  } else {
1306  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1307  "missing configuration.\n", desc->name);
1308  goto try_again;
1309  }
1310  if (hw_config->hwaccel) {
1311  av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel %s "
1312  "initialisation.\n", desc->name, hw_config->hwaccel->p.name);
1313  err = hwaccel_init(avctx, hw_config->hwaccel);
1314  if (err < 0)
1315  goto try_again;
1316  }
1317  ret = user_choice;
1318  break;
1319 
1320  try_again:
1321  av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
1322  "get_format() without it.\n", desc->name);
1323  for (i = 0; i < n; i++) {
1324  if (choices[i] == user_choice)
1325  break;
1326  }
1327  for (; i + 1 < n; i++)
1328  choices[i] = choices[i + 1];
1329  --n;
1330  }
1331 
1332  if (ret < 0)
1333  ff_hwaccel_uninit(avctx);
1334 
1335  av_freep(&choices);
1336  return ret;
1337 }
1338 
1339 static const AVPacketSideData*
1342 {
1343  for (int i = 0; i < nb_sd; i++)
1344  if (sd[i].type == type)
1345  return &sd[i];
1346 
1347  return NULL;
1348 }
1349 
1352 {
1354 }
1355 
1357  const AVPacketSideData *sd_pkt)
1358 {
1359  const AVStereo3D *src;
1360  AVStereo3D *dst;
1361  int ret;
1362 
1363  ret = av_buffer_make_writable(&sd_frame->buf);
1364  if (ret < 0)
1365  return ret;
1366  sd_frame->data = sd_frame->buf->data;
1367 
1368  dst = ( AVStereo3D*)sd_frame->data;
1369  src = (const AVStereo3D*)sd_pkt->data;
1370 
1371  if (dst->type == AV_STEREO3D_UNSPEC)
1372  dst->type = src->type;
1373 
1374  if (dst->view == AV_STEREO3D_VIEW_UNSPEC)
1375  dst->view = src->view;
1376 
1377  if (dst->primary_eye == AV_PRIMARY_EYE_NONE)
1378  dst->primary_eye = src->primary_eye;
1379 
1380  if (!dst->baseline)
1381  dst->baseline = src->baseline;
1382 
1383  if (!dst->horizontal_disparity_adjustment.num)
1384  dst->horizontal_disparity_adjustment = src->horizontal_disparity_adjustment;
1385 
1386  if (!dst->horizontal_field_of_view.num)
1387  dst->horizontal_field_of_view = src->horizontal_field_of_view;
1388 
1389  return 0;
1390 }
1391 
1393  const AVPacketSideData *sd_src, int nb_sd_src,
1394  const SideDataMap *map)
1395 
1396 {
1397  for (int i = 0; map[i].packet < AV_PKT_DATA_NB; i++) {
1398  const enum AVPacketSideDataType type_pkt = map[i].packet;
1399  const enum AVFrameSideDataType type_frame = map[i].frame;
1400  const AVPacketSideData *sd_pkt;
1401  AVFrameSideData *sd_frame;
1402 
1403  sd_pkt = packet_side_data_get(sd_src, nb_sd_src, type_pkt);
1404  if (!sd_pkt)
1405  continue;
1406 
1407  sd_frame = av_frame_get_side_data(dst, type_frame);
1408  if (sd_frame) {
1409  if (type_frame == AV_FRAME_DATA_STEREO3D) {
1410  int ret = side_data_stereo3d_merge(sd_frame, sd_pkt);
1411  if (ret < 0)
1412  return ret;
1413  }
1414 
1415  continue;
1416  }
1417 
1418  sd_frame = av_frame_new_side_data(dst, type_frame, sd_pkt->size);
1419  if (!sd_frame)
1420  return AVERROR(ENOMEM);
1421 
1422  memcpy(sd_frame->data, sd_pkt->data, sd_pkt->size);
1423  }
1424 
1425  return 0;
1426 }
1427 
1429 {
1430  size_t size;
1431  const uint8_t *side_metadata;
1432 
1433  AVDictionary **frame_md = &frame->metadata;
1434 
1435  side_metadata = av_packet_get_side_data(avpkt,
1437  return av_packet_unpack_dictionary(side_metadata, size, frame_md);
1438 }
1439 
1441  AVFrame *frame, const AVPacket *pkt)
1442 {
1443  static const SideDataMap sd[] = {
1450  { AV_PKT_DATA_NB }
1451  };
1452 
1453  int ret = 0;
1454 
1455  frame->pts = pkt->pts;
1456  frame->duration = pkt->duration;
1457 
1459  if (ret < 0)
1460  return ret;
1461 
1463  if (ret < 0)
1464  return ret;
1465 
1467 
1468  if (pkt->flags & AV_PKT_FLAG_DISCARD) {
1469  frame->flags |= AV_FRAME_FLAG_DISCARD;
1470  }
1471 
1472  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
1473  int ret = av_buffer_replace(&frame->opaque_ref, pkt->opaque_ref);
1474  if (ret < 0)
1475  return ret;
1476  frame->opaque = pkt->opaque;
1477  }
1478 
1479  return 0;
1480 }
1481 
1483 {
1484  int ret;
1485 
1488  if (ret < 0)
1489  return ret;
1490 
1491  for (int i = 0; i < avctx->nb_decoded_side_data; i++) {
1492  const AVFrameSideData *src = avctx->decoded_side_data[i];
1493  if (av_frame_get_side_data(frame, src->type))
1494  continue;
1495  ret = av_frame_side_data_clone(&frame->side_data, &frame->nb_side_data, src, 0);
1496  if (ret < 0)
1497  return ret;
1498  }
1499 
1501  const AVPacket *pkt = avctx->internal->last_pkt_props;
1502 
1504  if (ret < 0)
1505  return ret;
1506  }
1507 
1508  ret = fill_frame_props(avctx, frame);
1509  if (ret < 0)
1510  return ret;
1511 
1512  switch (avctx->codec->type) {
1513  case AVMEDIA_TYPE_VIDEO:
1514  if (frame->width && frame->height &&
1515  av_image_check_sar(frame->width, frame->height,
1516  frame->sample_aspect_ratio) < 0) {
1517  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1518  frame->sample_aspect_ratio.num,
1519  frame->sample_aspect_ratio.den);
1520  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
1521  }
1522  break;
1523  }
1524  return 0;
1525 }
1526 
1528 {
1529  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1530  int i;
1531  int num_planes = av_pix_fmt_count_planes(frame->format);
1533  int flags = desc ? desc->flags : 0;
1534  if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL))
1535  num_planes = 2;
1536  for (i = 0; i < num_planes; i++) {
1537  av_assert0(frame->data[i]);
1538  }
1539  // For formats without data like hwaccel allow unused pointers to be non-NULL.
1540  for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) {
1541  if (frame->data[i])
1542  av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
1543  frame->data[i] = NULL;
1544  }
1545  }
1546 }
1547 
1548 static void decode_data_free(AVRefStructOpaque unused, void *obj)
1549 {
1550  FrameDecodeData *fdd = obj;
1551 
1552  if (fdd->post_process_opaque_free)
1554 
1555  if (fdd->hwaccel_priv_free)
1556  fdd->hwaccel_priv_free(fdd->hwaccel_priv);
1557 }
1558 
1560 {
1561  FrameDecodeData *fdd;
1562 
1563  av_assert1(!frame->private_ref);
1564  av_refstruct_unref(&frame->private_ref);
1565 
1566  fdd = av_refstruct_alloc_ext(sizeof(*fdd), 0, NULL, decode_data_free);
1567  if (!fdd)
1568  return AVERROR(ENOMEM);
1569 
1570  frame->private_ref = fdd;
1571 
1572  return 0;
1573 }
1574 
1576 {
1577  AVCodecInternal *avci = avctx->internal;
1578  DecodeContext *dc = decode_ctx(avci);
1579 
1580  dc->lcevc_frame = dc->lcevc && avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
1582 
1583  if (dc->lcevc_frame) {
1584  dc->width = frame->width;
1585  dc->height = frame->height;
1586  frame->width = frame->width * 2 / FFMAX(frame->sample_aspect_ratio.den, 1);
1587  frame->height = frame->height * 2 / FFMAX(frame->sample_aspect_ratio.num, 1);
1588  }
1589 }
1590 
1592 {
1593  AVCodecInternal *avci = avctx->internal;
1594  DecodeContext *dc = decode_ctx(avci);
1595 
1596  if (dc->lcevc_frame) {
1597  FrameDecodeData *fdd = frame->private_ref;
1598  FFLCEVCFrame *frame_ctx;
1599  int ret;
1600 
1601  frame_ctx = av_mallocz(sizeof(*frame_ctx));
1602  if (!frame_ctx)
1603  return AVERROR(ENOMEM);
1604 
1605  frame_ctx->frame = av_frame_alloc();
1606  if (!frame_ctx->frame) {
1607  av_free(frame_ctx);
1608  return AVERROR(ENOMEM);
1609  }
1610 
1611  frame_ctx->lcevc = av_refstruct_ref(dc->lcevc);
1612  frame_ctx->frame->width = frame->width;
1613  frame_ctx->frame->height = frame->height;
1614  frame_ctx->frame->format = frame->format;
1615 
1616  frame->width = dc->width;
1617  frame->height = dc->height;
1618 
1619  ret = avctx->get_buffer2(avctx, frame_ctx->frame, 0);
1620  if (ret < 0) {
1621  ff_lcevc_unref(frame_ctx);
1622  return ret;
1623  }
1624 
1625  validate_avframe_allocation(avctx, frame_ctx->frame);
1626 
1627  fdd->post_process_opaque = frame_ctx;
1630  }
1631  dc->lcevc_frame = 0;
1632 
1633  return 0;
1634 }
1635 
1637 {
1638  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1639  int override_dimensions = 1;
1640  int ret;
1641 
1643 
1644  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1645  if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
1646  (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) {
1647  av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
1648  ret = AVERROR(EINVAL);
1649  goto fail;
1650  }
1651 
1652  if (frame->width <= 0 || frame->height <= 0) {
1653  frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
1654  frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
1655  override_dimensions = 0;
1656  }
1657 
1658  if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
1659  av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
1660  ret = AVERROR(EINVAL);
1661  goto fail;
1662  }
1663  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1664  if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
1665  av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
1666  ret = AVERROR(EINVAL);
1667  goto fail;
1668  }
1669  }
1670  ret = ff_decode_frame_props(avctx, frame);
1671  if (ret < 0)
1672  goto fail;
1673 
1674  if (hwaccel) {
1675  if (hwaccel->alloc_frame) {
1676  ret = hwaccel->alloc_frame(avctx, frame);
1677  goto end;
1678  }
1679  } else {
1680  avctx->sw_pix_fmt = avctx->pix_fmt;
1681  update_frame_props(avctx, frame);
1682  }
1683 
1684  ret = avctx->get_buffer2(avctx, frame, flags);
1685  if (ret < 0)
1686  goto fail;
1687 
1689 
1691  if (ret < 0)
1692  goto fail;
1693 
1695  if (ret < 0)
1696  goto fail;
1697 
1698 end:
1699  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
1701  frame->width = avctx->width;
1702  frame->height = avctx->height;
1703  }
1704 
1705 fail:
1706  if (ret < 0) {
1707  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1709  }
1710 
1711  return ret;
1712 }
1713 
1715 {
1716  AVFrame *tmp;
1717  int ret;
1718 
1720 
1721  // make sure the discard flag does not persist
1722  frame->flags &= ~AV_FRAME_FLAG_DISCARD;
1723 
1724  if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1725  av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1726  frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1728  }
1729 
1730  if (!frame->data[0])
1731  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1732 
1733  av_frame_side_data_free(&frame->side_data, &frame->nb_side_data);
1734 
1736  return ff_decode_frame_props(avctx, frame);
1737 
1738  tmp = av_frame_alloc();
1739  if (!tmp)
1740  return AVERROR(ENOMEM);
1741 
1743 
1745  if (ret < 0) {
1746  av_frame_free(&tmp);
1747  return ret;
1748  }
1749 
1751  av_frame_free(&tmp);
1752 
1753  return 0;
1754 }
1755 
1757 {
1758  int ret = reget_buffer_internal(avctx, frame, flags);
1759  if (ret < 0)
1760  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1761  return ret;
1762 }
1763 
1764 typedef struct ProgressInternal {
1766  struct AVFrame *f;
1768 
1770 {
1771  av_assert1(!!f->f == !!f->progress);
1772  av_assert1(!f->progress || f->progress->f == f->f);
1773 }
1774 
1776 {
1778 
1779  av_assert1(!f->f && !f->progress);
1780 
1781  f->progress = av_refstruct_pool_get(pool);
1782  if (!f->progress)
1783  return AVERROR(ENOMEM);
1784 
1785  f->f = f->progress->f;
1786  return 0;
1787 }
1788 
1790 {
1791  int ret = ff_progress_frame_alloc(avctx, f);
1792  if (ret < 0)
1793  return ret;
1794 
1795  ret = ff_thread_get_buffer(avctx, f->progress->f, flags);
1796  if (ret < 0) {
1797  f->f = NULL;
1798  av_refstruct_unref(&f->progress);
1799  return ret;
1800  }
1801  return 0;
1802 }
1803 
1805 {
1806  av_assert1(src->progress && src->f && src->f == src->progress->f);
1807  av_assert1(!dst->f && !dst->progress);
1808  dst->f = src->f;
1809  dst->progress = av_refstruct_ref(src->progress);
1810 }
1811 
1813 {
1815  f->f = NULL;
1816  av_refstruct_unref(&f->progress);
1817 }
1818 
1820 {
1821  if (dst == src)
1822  return;
1825  if (src->f)
1827 }
1828 
1830 {
1831  ff_thread_progress_report(&f->progress->progress, n);
1832 }
1833 
1835 {
1836  ff_thread_progress_await(&f->progress->progress, n);
1837 }
1838 
1839 #if !HAVE_THREADS
1841 {
1843 }
1844 #endif /* !HAVE_THREADS */
1845 
1847 {
1848  const AVCodecContext *avctx = opaque.nc;
1849  ProgressInternal *progress = obj;
1850  int ret;
1851 
1853  if (ret < 0)
1854  return ret;
1855 
1856  progress->f = av_frame_alloc();
1857  if (!progress->f)
1858  return AVERROR(ENOMEM);
1859 
1860  return 0;
1861 }
1862 
1863 static void progress_frame_pool_reset_cb(AVRefStructOpaque unused, void *obj)
1864 {
1865  ProgressInternal *progress = obj;
1866 
1867  ff_thread_progress_reset(&progress->progress);
1868  av_frame_unref(progress->f);
1869 }
1870 
1872 {
1873  ProgressInternal *progress = obj;
1874 
1876  av_frame_free(&progress->f);
1877 }
1878 
1880 {
1881  AVCodecInternal *avci = avctx->internal;
1882  DecodeContext *dc = decode_ctx(avci);
1883  int ret = 0;
1884 
1885  dc->initial_pict_type = AV_PICTURE_TYPE_NONE;
1887  dc->intra_only_flag = AV_FRAME_FLAG_KEY;
1888  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
1889  dc->initial_pict_type = AV_PICTURE_TYPE_I;
1890  }
1891 
1892  /* if the decoder init function was already called previously,
1893  * free the already allocated subtitle_header before overwriting it */
1894  av_freep(&avctx->subtitle_header);
1895 
1896  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1897  av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
1898  avctx->codec->max_lowres);
1899  avctx->lowres = avctx->codec->max_lowres;
1900  }
1901  if (avctx->sub_charenc) {
1902  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1903  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1904  "supported with subtitles codecs\n");
1905  return AVERROR(EINVAL);
1906  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1907  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1908  "subtitles character encoding will be ignored\n",
1909  avctx->codec_descriptor->name);
1911  } else {
1912  /* input character encoding is set for a text based subtitle
1913  * codec at this point */
1916 
1918 #if CONFIG_ICONV
1919  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1920  if (cd == (iconv_t)-1) {
1921  ret = AVERROR(errno);
1922  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1923  "with input character encoding \"%s\"\n", avctx->sub_charenc);
1924  return ret;
1925  }
1926  iconv_close(cd);
1927 #else
1928  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1929  "conversion needs a libavcodec built with iconv support "
1930  "for this codec\n");
1931  return AVERROR(ENOSYS);
1932 #endif
1933  }
1934  }
1935  }
1936 
1937  dc->pts_correction_num_faulty_pts =
1938  dc->pts_correction_num_faulty_dts = 0;
1939  dc->pts_correction_last_pts =
1940  dc->pts_correction_last_dts = INT64_MIN;
1941 
1942  if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
1944  av_log(avctx, AV_LOG_WARNING,
1945  "gray decoding requested but not enabled at configuration time\n");
1946  if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
1948  }
1949 
1950  if (avctx->nb_side_data_prefer_packet == 1 &&
1951  avctx->side_data_prefer_packet[0] == -1)
1952  dc->side_data_pref_mask = ~0ULL;
1953  else {
1954  for (unsigned i = 0; i < avctx->nb_side_data_prefer_packet; i++) {
1955  int val = avctx->side_data_prefer_packet[i];
1956 
1957  if (val < 0 || val >= AV_PKT_DATA_NB) {
1958  av_log(avctx, AV_LOG_ERROR, "Invalid side data type: %d\n", val);
1959  return AVERROR(EINVAL);
1960  }
1961 
1962  for (unsigned j = 0; ff_sd_global_map[j].packet < AV_PKT_DATA_NB; j++) {
1963  if (ff_sd_global_map[j].packet == val) {
1964  val = ff_sd_global_map[j].frame;
1965 
1966  // this code will need to be changed when we have more than
1967  // 64 frame side data types
1968  if (val >= 64) {
1969  av_log(avctx, AV_LOG_ERROR, "Side data type too big\n");
1970  return AVERROR_BUG;
1971  }
1972 
1973  dc->side_data_pref_mask |= 1ULL << val;
1974  }
1975  }
1976  }
1977  }
1978 
1979  avci->in_pkt = av_packet_alloc();
1980  avci->last_pkt_props = av_packet_alloc();
1981  if (!avci->in_pkt || !avci->last_pkt_props)
1982  return AVERROR(ENOMEM);
1983 
1985  avci->progress_frame_pool =
1991  if (!avci->progress_frame_pool)
1992  return AVERROR(ENOMEM);
1993  }
1994  ret = decode_bsfs_init(avctx);
1995  if (ret < 0)
1996  return ret;
1997 
1999  ret = ff_lcevc_alloc(&dc->lcevc);
2000  if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
2001  return ret;
2002  }
2003 
2004  return 0;
2005 }
2006 
2007 /**
2008  * Check side data preference and clear existing side data from frame
2009  * if needed.
2010  *
2011  * @retval 0 side data of this type can be added to frame
2012  * @retval 1 side data of this type should not be added to frame
2013  */
2014 static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd,
2015  int *nb_sd, enum AVFrameSideDataType type)
2016 {
2017  DecodeContext *dc = decode_ctx(avctx->internal);
2018 
2019  // Note: could be skipped for `type` without corresponding packet sd
2020  if (av_frame_side_data_get(*sd, *nb_sd, type)) {
2021  if (dc->side_data_pref_mask & (1ULL << type))
2022  return 1;
2023  av_frame_side_data_remove(sd, nb_sd, type);
2024  }
2025 
2026  return 0;
2027 }
2028 
2029 
2031  enum AVFrameSideDataType type, size_t size,
2032  AVFrameSideData **psd)
2033 {
2034  AVFrameSideData *sd;
2035 
2036  if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, type)) {
2037  if (psd)
2038  *psd = NULL;
2039  return 0;
2040  }
2041 
2043  if (psd)
2044  *psd = sd;
2045 
2046  return sd ? 0 : AVERROR(ENOMEM);
2047 }
2048 
2050  AVFrameSideData ***sd, int *nb_sd,
2052  AVBufferRef **buf)
2053 {
2054  int ret = 0;
2055 
2056  if (side_data_pref(avctx, sd, nb_sd, type))
2057  goto finish;
2058 
2059  if (!av_frame_side_data_add(sd, nb_sd, type, buf, 0))
2060  ret = AVERROR(ENOMEM);
2061 
2062 finish:
2064 
2065  return ret;
2066 }
2067 
2070  AVBufferRef **buf)
2071 {
2073  &frame->side_data, &frame->nb_side_data,
2074  type, buf);
2075 }
2076 
2078  AVFrameSideData ***sd, int *nb_sd,
2079  struct AVMasteringDisplayMetadata **mdm)
2080 {
2081  AVBufferRef *buf;
2082  size_t size;
2083 
2085  *mdm = NULL;
2086  return 0;
2087  }
2088 
2090  if (!*mdm)
2091  return AVERROR(ENOMEM);
2092 
2093  buf = av_buffer_create((uint8_t *)*mdm, size, NULL, NULL, 0);
2094  if (!buf) {
2095  av_freep(mdm);
2096  return AVERROR(ENOMEM);
2097  }
2098 
2100  &buf, 0)) {
2101  *mdm = NULL;
2102  av_buffer_unref(&buf);
2103  return AVERROR(ENOMEM);
2104  }
2105 
2106  return 0;
2107 }
2108 
2111 {
2112  if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2114  *mdm = NULL;
2115  return 0;
2116  }
2117 
2119  return *mdm ? 0 : AVERROR(ENOMEM);
2120 }
2121 
2123  AVFrameSideData ***sd, int *nb_sd,
2124  AVContentLightMetadata **clm)
2125 {
2126  AVBufferRef *buf;
2127  size_t size;
2128 
2129  if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) {
2130  *clm = NULL;
2131  return 0;
2132  }
2133 
2135  if (!*clm)
2136  return AVERROR(ENOMEM);
2137 
2138  buf = av_buffer_create((uint8_t *)*clm, size, NULL, NULL, 0);
2139  if (!buf) {
2140  av_freep(clm);
2141  return AVERROR(ENOMEM);
2142  }
2143 
2145  &buf, 0)) {
2146  *clm = NULL;
2147  av_buffer_unref(&buf);
2148  return AVERROR(ENOMEM);
2149  }
2150 
2151  return 0;
2152 }
2153 
2155  AVContentLightMetadata **clm)
2156 {
2157  if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2159  *clm = NULL;
2160  return 0;
2161  }
2162 
2164  return *clm ? 0 : AVERROR(ENOMEM);
2165 }
2166 
2167 int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
2168 {
2169  size_t size;
2170  const void *pal = av_packet_get_side_data(src, AV_PKT_DATA_PALETTE, &size);
2171 
2172  if (pal && size == AVPALETTE_SIZE) {
2173  memcpy(dst, pal, AVPALETTE_SIZE);
2174  return 1;
2175  } else if (pal) {
2176  av_log(logctx, AV_LOG_ERROR,
2177  "Palette size %"SIZE_SPECIFIER" is wrong\n", size);
2178  }
2179  return 0;
2180 }
2181 
2182 int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
2183 {
2184  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
2185 
2186  if (!hwaccel || !hwaccel->frame_priv_data_size)
2187  return 0;
2188 
2189  av_assert0(!*hwaccel_picture_private);
2190 
2191  if (hwaccel->free_frame_priv) {
2192  AVHWFramesContext *frames_ctx;
2193 
2194  if (!avctx->hw_frames_ctx)
2195  return AVERROR(EINVAL);
2196 
2197  frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data;
2198  *hwaccel_picture_private = av_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,
2199  frames_ctx->device_ctx,
2200  hwaccel->free_frame_priv);
2201  } else {
2202  *hwaccel_picture_private = av_refstruct_allocz(hwaccel->frame_priv_data_size);
2203  }
2204 
2205  if (!*hwaccel_picture_private)
2206  return AVERROR(ENOMEM);
2207 
2208  return 0;
2209 }
2210 
2212 {
2213  AVCodecInternal *avci = avctx->internal;
2214  DecodeContext *dc = decode_ctx(avci);
2215 
2217  av_packet_unref(avci->in_pkt);
2218 
2219  dc->pts_correction_last_pts =
2220  dc->pts_correction_last_dts = INT64_MIN;
2221 
2222  if (avci->bsf)
2223  av_bsf_flush(avci->bsf);
2224 
2225  dc->nb_draining_errors = 0;
2226  dc->draining_started = 0;
2227 }
2228 
2230 {
2231  return av_mallocz(sizeof(DecodeContext));
2232 }
2233 
2235 {
2236  const DecodeContext *src_dc = decode_ctx(src->internal);
2237  DecodeContext *dst_dc = decode_ctx(dst->internal);
2238 
2239  av_refstruct_replace(&dst_dc->lcevc, src_dc->lcevc);
2240 }
2241 
2243 {
2244  AVCodecInternal *avci = avctx->internal;
2245  DecodeContext *dc = decode_ctx(avci);
2246 
2247  av_refstruct_unref(&dc->lcevc);
2248 }
2249 
2250 static int attach_displaymatrix(AVCodecContext *avctx, AVFrame *frame, int orientation)
2251 {
2252  AVFrameSideData *sd = NULL;
2253  int32_t *matrix;
2254  int ret;
2255  /* invalid orientation */
2256  if (orientation < 2 || orientation > 8)
2257  return AVERROR_INVALIDDATA;
2259  if (ret < 0) {
2260  av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data: %s\n", av_err2str(ret));
2261  return ret;
2262  }
2263  if (sd) {
2264  matrix = (int32_t *) sd->data;
2265  ret = av_exif_orientation_to_matrix(matrix, orientation);
2266  }
2267 
2268  return ret;
2269 }
2270 
2272 {
2273  const AVExifEntry *orient = NULL;
2274  AVFrameSideData *sd;
2275  AVExifMetadata *cloned = NULL;
2276  AVBufferRef *written = NULL;
2277  int ret;
2278 
2279  for (size_t i = 0; i < ifd->count; i++) {
2280  const AVExifEntry *entry = &ifd->entries[i];
2281  if (entry->id == ORIENTATION_TAG && entry->count > 0 && entry->type == AV_TIFF_SHORT) {
2282  orient = entry;
2283  break;
2284  }
2285  }
2286 
2287  if (orient && orient->value.uint[0] > 1) {
2288  av_log(avctx, AV_LOG_DEBUG, "found nontrivial EXIF orientation: %" PRIu64 "\n", orient->value.uint[0]);
2289  ret = attach_displaymatrix(avctx, frame, orient->value.uint[0]);
2290  if (ret < 0) {
2291  av_log(avctx, AV_LOG_WARNING, "unable to attach displaymatrix from EXIF\n");
2292  } else {
2293  cloned = av_exif_clone_ifd(ifd);
2294  if (!cloned) {
2295  ret = AVERROR(ENOMEM);
2296  goto end;
2297  }
2298  av_exif_remove_entry(avctx, cloned, orient->id, 0);
2299  ifd = cloned;
2300  }
2301  }
2302 
2303  ret = av_exif_ifd_to_dict(avctx, ifd, &frame->metadata);
2304  if (ret < 0)
2305  goto end;
2306 
2307  if (cloned || !og) {
2308  ret = av_exif_write(avctx, ifd, &written, AV_EXIF_TIFF_HEADER);
2309  if (ret < 0)
2310  goto end;
2311  }
2312 
2313  sd = av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_EXIF, written ? written : og);
2314  if (!sd) {
2315  if (written)
2316  av_buffer_unref(&written);
2317  ret = AVERROR(ENOMEM);
2318  goto end;
2319  }
2320 
2321  ret = 0;
2322 
2323 end:
2324  if (og && written && ret >= 0)
2325  av_buffer_unref(&og); // as though we called new_side_data on og;
2326  av_exif_free(cloned);
2327  av_free(cloned);
2328  return ret;
2329 }
2330 
2332 {
2333  return exif_attach_ifd(avctx, frame, ifd, NULL);
2334 }
2335 
2337  enum AVExifHeaderMode header_mode)
2338 {
2339  int ret;
2340  AVExifMetadata ifd = { 0 };
2341 
2342  ret = av_exif_parse_buffer(avctx, data->data, data->size, &ifd, header_mode);
2343  if (ret < 0)
2344  goto end;
2345 
2346  ret = exif_attach_ifd(avctx, frame, &ifd, data);
2347 
2348 end:
2349  av_exif_free(&ifd);
2350  return ret;
2351 }
lcevcdec.h
flags
const SwsFlags flags[]
Definition: swscale.c:61
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:1350
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:69
AVSubtitle
Definition: avcodec.h:2075
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:1829
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:432
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1405
FFCodec::receive_frame
int(* receive_frame)(struct AVCodecContext *avctx, struct AVFrame *frame)
Decode API with decoupled packet/frame dataflow.
Definition: codec_internal.h:213
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:1154
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:245
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:159
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
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:2080
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:761
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:255
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:757
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:659
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:661
ff_decode_exif_attach_buffer
int ff_decode_exif_attach_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferRef *data, enum AVExifHeaderMode header_mode)
Attach the data buffer to the frame.
Definition: decode.c:2336
AVCodecContext::decoded_side_data
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition: avcodec.h:1924
attach_post_process_data
static int attach_post_process_data(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:1591
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1201
apply_cropping
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:735
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:1024
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:657
AVExifEntry
Definition: exif.h:85
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:645
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:696
AVExifMetadata
Definition: exif.h:76
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:76
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3441
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
ff_lcevc_alloc
int ff_lcevc_alloc(FFLCEVCContext **plcevc)
Definition: lcevcdec.c:312
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:1976
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:614
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:907
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:1398
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:1704
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:1763
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:1185
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2079
AVExifHeaderMode
AVExifHeaderMode
Definition: exif.h:58
av_unused
#define av_unused
Definition: attributes.h:131
decode_simple_receive_frame
static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:590
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:63
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:565
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:88
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
AVFrameSideData::buf
AVBufferRef * buf
Definition: frame.h:287
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:652
AVFrame::width
int width
Definition: frame.h:499
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:403
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:191
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:552
FFLCEVCContext
Definition: lcevcdec.h:31
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:664
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:1789
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:1739
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
Definition: packet.h:629
FrameDecodeData::hwaccel_priv_free
void(* hwaccel_priv_free)(void *priv)
Definition: decode.h:52
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:570
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:1722
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:636
avcodec_default_get_format
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Definition: decode.c:978
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:248
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
ff_thread_receive_frame
#define ff_thread_receive_frame(avctx, frame)
Definition: decode.c:217
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:604
AV_RL8
#define AV_RL8(x)
Definition: intreadwrite.h:394
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:91
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:995
decode_ctx
static DecodeContext * decode_ctx(AVCodecInternal *avci)
Definition: decode.c:103
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:52
FF_SUB_CHARENC_MODE_AUTOMATIC
#define FF_SUB_CHARENC_MODE_AUTOMATIC
libavcodec will select the mode itself
Definition: avcodec.h:1721
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
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:758
DecodeContext::pts_correction_num_faulty_dts
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition: decode.c:87
ff_hwaccel_uninit
void ff_hwaccel_uninit(AVCodecContext *avctx)
Definition: decode.c:1189
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
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:220
AVCodec::max_lowres
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: codec.h:192
AVPacketSideData::size
size_t size
Definition: packet.h:405
AV_TIFF_SHORT
@ AV_TIFF_SHORT
Definition: exif.h:45
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3481
DecodeContext::nb_draining_errors
int nb_draining_errors
Definition: decode.c:79
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:279
exif_attach_ifd
static int exif_attach_ifd(AVCodecContext *avctx, AVFrame *frame, const AVExifMetadata *ifd, AVBufferRef *og)
Definition: decode.c:2271
finish
static void finish(void)
Definition: movenc.c:374
FFHWAccel
Definition: hwaccel_internal.h:34
bsf.h
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:287
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:440
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:588
STRIDE_ALIGN
#define STRIDE_ALIGN
Definition: internal.h:46
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1039
fail
#define fail()
Definition: checkasm.h:199
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:1561
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
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:311
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:327
ff_lcevc_process
int ff_lcevc_process(void *logctx, AVFrame *frame)
Definition: lcevcdec.c:281
av_exif_free
void av_exif_free(AVExifMetadata *ifd)
Frees all resources associated with the given EXIF metadata struct.
Definition: exif.c:602
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:1720
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:488
val
static double val(void *priv, double ch)
Definition: aeval.c:77
FrameDecodeData::post_process_opaque_free
void(* post_process_opaque_free)(void *opaque)
Definition: decode.h:46
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:1440
pts
static int64_t pts
Definition: transcode_aac.c:644
add_metadata_from_side_data
static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
Definition: decode.c:1428
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:607
AVCodecContext::max_samples
int64_t max_samples
The number of samples per frame to maximally accept.
Definition: avcodec.h:1825
AVRational::num
int num
Numerator.
Definition: rational.h:59
progressframe.h
AVFrameSideDataType
AVFrameSideDataType
Definition: frame.h:49
refstruct.h
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2072
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_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:2068
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:411
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:51
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:1200
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:488
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:907
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:2122
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:68
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:645
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
pkt
AVPacket * pkt
Definition: movenc.c:60
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:285
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
ff_decode_receive_frame
int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
avcodec_receive_frame() implementation for decoders.
Definition: decode.c:789
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:642
emms_c
#define emms_c()
Definition: emms.h:63
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:1804
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition: packet.h:630
AVCodecContext::side_data_prefer_packet
int * side_data_prefer_packet
Decoding only.
Definition: avcodec.h:1908
stereo3d.h
ff_hwaccel_frame_priv_alloc
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
Definition: decode.c:2182
get_subtitle_defaults
static void get_subtitle_defaults(AVSubtitle *sub)
Definition: decode.c:820
FrameDecodeData::post_process_opaque
void * post_process_opaque
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:99
validate_avframe_allocation
static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:1527
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:190
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:1925
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:411
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:1048
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
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:1136
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:404
AVRefStructPool
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition: refstruct.c:183
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:1812
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_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:339
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2081
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:110
AVCodecContext::max_pixels
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:1782
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:1846
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:577
ProgressInternal
Definition: decode.c:1764
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:639
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:1769
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:72
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:196
discard_samples
static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:313
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:1041
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:2109
DecodeContext::draining_started
int draining_started
The caller has submitted a NULL packet on input.
Definition: decode.c:84
ff_thread_get_packet
#define ff_thread_get_packet(avctx, pkt)
Definition: decode.c:216
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
AVCodecContext::sub_charenc
char * sub_charenc
Character encoding of the input subtitles file.
Definition: avcodec.h:1711
ff_decode_internal_alloc
AVCodecInternal * ff_decode_internal_alloc(void)
Definition: decode.c:2229
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:368
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
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
ff_decode_exif_attach_ifd
int ff_decode_exif_attach_ifd(AVCodecContext *avctx, AVFrame *frame, const AVExifMetadata *ifd)
Definition: decode.c:2331
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:149
utf8_check
static int utf8_check(const uint8_t *str)
Definition: decode.c:888
update_frame_props
static void update_frame_props(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:1575
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
ff_decode_flush_buffers
void ff_decode_flush_buffers(AVCodecContext *avctx)
Definition: decode.c:2211
AVCodecContext::apply_cropping
int apply_cropping
Video decoding only.
Definition: avcodec.h:1809
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:669
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:63
hwaccel_internal.h
tmp
static uint8_t tmp[20]
Definition: aes_ctr.c:47
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:230
AVCodec::type
enum AVMediaType type
Definition: codec.h:185
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:1764
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:466
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:102
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
ff_lcevc_unref
void ff_lcevc_unref(void *opaque)
Definition: lcevcdec.c:324
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:103
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
av_frame_new_side_data_from_buf
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
Definition: frame.c:636
FFLCEVCFrame::lcevc
FFLCEVCContext * lcevc
Definition: lcevcdec.h:39
AV_CODEC_HW_CONFIG_METHOD_INTERNAL
@ AV_CODEC_HW_CONFIG_METHOD_INTERNAL
The codec supports this format by some internal method.
Definition: codec.h:318
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:89
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:378
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:302
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:440
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:826
AVPACKET_IS_EMPTY
#define AVPACKET_IS_EMPTY(pkt)
Definition: packet_internal.h:26
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:58
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:1131
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:733
AV_CODEC_EXPORT_DATA_ENHANCEMENTS
#define AV_CODEC_EXPORT_DATA_ENHANCEMENTS
Decoding only.
Definition: avcodec.h:406
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:373
progress_frame_pool_free_entry_cb
static av_cold void progress_frame_pool_free_entry_cb(AVRefStructOpaque opaque, void *obj)
Definition: decode.c:1871
AVExifEntry::value
union AVExifEntry::@120 value
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
AVCodecContext::lowres
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:1697
f
f
Definition: af_crystalizer.c:122
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:495
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1636
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:52
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:302
AVPacket::size
int size
Definition: packet.h:553
ff_progress_frame_alloc
int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f)
This function sets up the ProgressFrame, i.e.
Definition: decode.c:1775
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
AVCodecContext::extra_hw_frames
int extra_hw_frames
Video decoding only.
Definition: avcodec.h:1498
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:1548
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:709
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:202
AV_PKT_DATA_DYNAMIC_HDR10_PLUS
@ AV_PKT_DATA_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
Definition: packet.h:296
AVExifEntry::id
uint16_t id
Definition: exif.h:86
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:303
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:77
AVCodecInternal::bsf
struct AVBSFContext * bsf
Definition: internal.h:84
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1031
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:542
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:60
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:763
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:2030
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:2049
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:2014
AVFrameSideData::data
uint8_t * data
Definition: frame.h:284
DecodeContext::height
int height
Definition: decode.c:100
ffcodec
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
Definition: codec_internal.h:284
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:533
fill_frame_props
static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:557
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:787
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:514
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:2078
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:352
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:723
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:551
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:1765
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:82
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:558
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:64
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:1834
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:264
DecodeContext::side_data_pref_mask
uint64_t side_data_pref_mask
DTS of the last frame.
Definition: decode.c:95
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:1340
AVCodecContext::nb_side_data_prefer_packet
unsigned nb_side_data_prefer_packet
Number of entries in side_data_prefer_packet.
Definition: avcodec.h:1912
detect_colorspace
static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f)
Definition: decode.c:551
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1572
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:1942
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:702
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:169
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
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:395
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:2076
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:545
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:133
reget_buffer_internal
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition: decode.c:1714
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:253
decode_receive_frame_internal
static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:642
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:606
AVExifMetadata::entries
AVExifEntry * entries
Definition: exif.h:78
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:57
ff_decode_preinit
int ff_decode_preinit(AVCodecContext *avctx)
Perform decoder initialization and validation.
Definition: decode.c:1879
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:62
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:521
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:494
DecodeContext::lcevc
FFLCEVCContext * lcevc
Definition: decode.c:97
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVExifMetadata::count
unsigned int count
Definition: exif.h:80
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:1475
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:676
AVExifEntry::uint
uint64_t * uint
Definition: exif.h:109
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
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:49
profile
int profile
Definition: mxfenc.c:2278
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:693
AVCodecContext::height
int height
Definition: avcodec.h:592
decode_simple_internal
static int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:411
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:631
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:1453
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:204
FFCodec::cb
union FFCodec::@102 cb
AVCodecContext::sub_charenc_mode
int sub_charenc_mode
Subtitles character encoding mode.
Definition: avcodec.h:1719
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:1878
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:1092
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:1756
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
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:1357
AV_CODEC_PROP_TEXT_SUB
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: codec_desc.h:108
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:783
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:1840
hwaccel
static const char * hwaccel
Definition: ffplay.c:353
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:2154
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:563
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
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:1819
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:129
apply_param_change
static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
Definition: decode.c:108
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:1482
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:431
AVFrame::height
int height
Definition: frame.h:499
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1580
recode_subtitle
static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt, const AVPacket *inpkt, AVPacket *buf_pkt)
Definition: decode.c:827
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:58
avcodec_internal.h
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
attach_displaymatrix
static int attach_displaymatrix(AVCodecContext *avctx, AVFrame *frame, int orientation)
Definition: decode.c:2250
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
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:1356
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
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:1774
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:76
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:1766
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:154
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:837
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:103
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:449
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:255
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:607
progress_frame_pool_reset_cb
static void progress_frame_pool_reset_cb(AVRefStructOpaque unused, void *obj)
Definition: decode.c:1863
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:439
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:646
desc
const char * desc
Definition: libsvtav1.c:79
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:526
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:2077
side_data_map
static int side_data_map(AVFrame *dst, const AVPacketSideData *sd_src, int nb_sd_src, const SideDataMap *map)
Definition: decode.c:1392
AV_PKT_DATA_A53_CC
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: packet.h:239
ff_decode_internal_uninit
void ff_decode_internal_uninit(AVCodecContext *avctx)
Definition: decode.c:2242
DecodeContext::width
int width
Definition: decode.c:99
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
packet_internal.h
AV_CODEC_EXPORT_DATA_MVS
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:386
ORIENTATION_TAG
#define ORIENTATION_TAG
Definition: exif_internal.h:46
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:213
mastering_display_metadata.h
ff_attach_decode_data
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1559
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:298
ThreadingStatus
ThreadingStatus
Definition: thread.h:60
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:137
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:282
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
DecodeContext::lcevc_frame
int lcevc_frame
Definition: decode.c:98
AV_CODEC_FLAG2_EXPORT_MVS
#define AV_CODEC_FLAG2_EXPORT_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:364
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:529
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
DecodeContext::pts_correction_num_faulty_pts
int64_t pts_correction_num_faulty_pts
Definition: decode.c:86
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:1144
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:592
AV_FRAME_DATA_EXIF
@ AV_FRAME_DATA_EXIF
Extensible image file format metadata.
Definition: frame.h:262
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:51
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:330
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:638
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
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:2167
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:180
FFLCEVCFrame
Definition: lcevcdec.h:38
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
FFLCEVCFrame::frame
struct AVFrame * frame
Definition: lcevcdec.h:40
AVHWAccel::pix_fmt
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:1963
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:616
DecodeContext
Definition: decode.c:61
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:223
FF_REGET_BUFFER_FLAG_READONLY
#define FF_REGET_BUFFER_FLAG_READONLY
the returned buffer does not need to be writable
Definition: decode.h:128
src
#define src
Definition: vp8dsp.c:248
ff_decode_internal_sync
void ff_decode_internal_sync(AVCodecContext *dst, const AVCodecContext *src)
Definition: decode.c:2234
Frame::height
int height
Definition: ffplay.c:160
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:564
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:3361
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:1723
min
float min
Definition: vorbis_enc_data.h:429