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 <string.h>
23 
24 #include "config.h"
25 
26 #if CONFIG_ICONV
27 # include <iconv.h>
28 #endif
29 
30 #include "libavutil/avassert.h"
32 #include "libavutil/common.h"
33 #include "libavutil/emms.h"
34 #include "libavutil/frame.h"
35 #include "libavutil/hwcontext.h"
36 #include "libavutil/imgutils.h"
37 #include "libavutil/internal.h"
39 #include "libavutil/mem.h"
40 
41 #include "avcodec.h"
42 #include "avcodec_internal.h"
43 #include "bytestream.h"
44 #include "bsf.h"
45 #include "codec_desc.h"
46 #include "codec_internal.h"
47 #include "decode.h"
48 #include "hwaccel_internal.h"
49 #include "hwconfig.h"
50 #include "internal.h"
51 #include "packet_internal.h"
52 #include "progressframe.h"
53 #include "refstruct.h"
54 #include "thread.h"
55 #include "threadprogress.h"
56 
57 typedef struct DecodeContext {
59 
60  /* to prevent infinite loop on errors when draining */
62 
63  /**
64  * The caller has submitted a NULL packet on input.
65  */
67 
68  int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
69  int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
70  int64_t pts_correction_last_pts; /// PTS of the last frame
71  int64_t pts_correction_last_dts; /// DTS of the last frame
72 
73  /**
74  * Bitmask indicating for which side data types we prefer user-supplied
75  * (global or attached to packets) side data over bytestream.
76  */
79 
81 {
82  return (DecodeContext *)avci;
83 }
84 
85 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
86 {
87  int ret;
88  size_t size;
89  const uint8_t *data;
90  uint32_t flags;
91  int64_t val;
92 
94  if (!data)
95  return 0;
96 
97  if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) {
98  av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
99  "changes, but PARAM_CHANGE side data was sent to it.\n");
100  ret = AVERROR(EINVAL);
101  goto fail2;
102  }
103 
104  if (size < 4)
105  goto fail;
106 
107  flags = bytestream_get_le32(&data);
108  size -= 4;
109 
111  if (size < 4)
112  goto fail;
113  val = bytestream_get_le32(&data);
114  if (val <= 0 || val > INT_MAX) {
115  av_log(avctx, AV_LOG_ERROR, "Invalid sample rate");
117  goto fail2;
118  }
119  avctx->sample_rate = val;
120  size -= 4;
121  }
123  if (size < 8)
124  goto fail;
125  avctx->width = bytestream_get_le32(&data);
126  avctx->height = bytestream_get_le32(&data);
127  size -= 8;
128  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
129  if (ret < 0)
130  goto fail2;
131  }
132 
133  return 0;
134 fail:
135  av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
137 fail2:
138  if (ret < 0) {
139  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
140  if (avctx->err_recognition & AV_EF_EXPLODE)
141  return ret;
142  }
143  return 0;
144 }
145 
147 {
148  int ret = 0;
149 
151  if (pkt) {
153 #if FF_API_FRAME_PKT
154  if (!ret)
155  avci->last_pkt_props->stream_index = pkt->size; // Needed for ff_decode_frame_props().
156 #endif
157  }
158  return ret;
159 }
160 
162 {
163  AVCodecInternal *avci = avctx->internal;
164  const FFCodec *const codec = ffcodec(avctx->codec);
165  int ret;
166 
167  if (avci->bsf)
168  return 0;
169 
170  ret = av_bsf_list_parse_str(codec->bsfs, &avci->bsf);
171  if (ret < 0) {
172  av_log(avctx, AV_LOG_ERROR, "Error parsing decoder bitstream filters '%s': %s\n", codec->bsfs, av_err2str(ret));
173  if (ret != AVERROR(ENOMEM))
174  ret = AVERROR_BUG;
175  goto fail;
176  }
177 
178  /* We do not currently have an API for passing the input timebase into decoders,
179  * but no filters used here should actually need it.
180  * So we make up some plausible-looking number (the MPEG 90kHz timebase) */
181  avci->bsf->time_base_in = (AVRational){ 1, 90000 };
183  if (ret < 0)
184  goto fail;
185 
186  ret = av_bsf_init(avci->bsf);
187  if (ret < 0)
188  goto fail;
189 
190  return 0;
191 fail:
192  av_bsf_free(&avci->bsf);
193  return ret;
194 }
195 
197 {
198  AVCodecInternal *avci = avctx->internal;
199  int ret;
200 
201  ret = av_bsf_receive_packet(avci->bsf, pkt);
202  if (ret == AVERROR_EOF)
203  avci->draining = 1;
204  if (ret < 0)
205  return ret;
206 
209  if (ret < 0)
210  goto finish;
211  }
212 
213  ret = apply_param_change(avctx, pkt);
214  if (ret < 0)
215  goto finish;
216 
217  return 0;
218 finish:
220  return ret;
221 }
222 
224 {
225  AVCodecInternal *avci = avctx->internal;
226  DecodeContext *dc = decode_ctx(avci);
227 
228  if (avci->draining)
229  return AVERROR_EOF;
230 
231  while (1) {
232  int ret = decode_get_packet(avctx, pkt);
233  if (ret == AVERROR(EAGAIN) &&
234  (!AVPACKET_IS_EMPTY(avci->buffer_pkt) || dc->draining_started)) {
235  ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
236  if (ret < 0) {
238  return ret;
239  }
240 
241  continue;
242  }
243 
244  return ret;
245  }
246 }
247 
248 /**
249  * Attempt to guess proper monotonic timestamps for decoded video frames
250  * which might have incorrect times. Input timestamps may wrap around, in
251  * which case the output will as well.
252  *
253  * @param pts the pts field of the decoded AVPacket, as passed through
254  * AVFrame.pts
255  * @param dts the dts field of the decoded AVPacket
256  * @return one of the input values, may be AV_NOPTS_VALUE
257  */
259  int64_t reordered_pts, int64_t dts)
260 {
261  int64_t pts = AV_NOPTS_VALUE;
262 
263  if (dts != AV_NOPTS_VALUE) {
264  dc->pts_correction_num_faulty_dts += dts <= dc->pts_correction_last_dts;
265  dc->pts_correction_last_dts = dts;
266  } else if (reordered_pts != AV_NOPTS_VALUE)
267  dc->pts_correction_last_dts = reordered_pts;
268 
269  if (reordered_pts != AV_NOPTS_VALUE) {
270  dc->pts_correction_num_faulty_pts += reordered_pts <= dc->pts_correction_last_pts;
271  dc->pts_correction_last_pts = reordered_pts;
272  } else if(dts != AV_NOPTS_VALUE)
273  dc->pts_correction_last_pts = dts;
274 
275  if ((dc->pts_correction_num_faulty_pts<=dc->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
276  && reordered_pts != AV_NOPTS_VALUE)
277  pts = reordered_pts;
278  else
279  pts = dts;
280 
281  return pts;
282 }
283 
284 static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
285 {
286  AVCodecInternal *avci = avctx->internal;
287  AVFrameSideData *side;
288  uint32_t discard_padding = 0;
289  uint8_t skip_reason = 0;
290  uint8_t discard_reason = 0;
291 
293  if (side && side->size >= 10) {
294  avci->skip_samples = AV_RL32(side->data);
295  avci->skip_samples = FFMAX(0, avci->skip_samples);
296  discard_padding = AV_RL32(side->data + 4);
297  av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
298  avci->skip_samples, (int)discard_padding);
299  skip_reason = AV_RL8(side->data + 8);
300  discard_reason = AV_RL8(side->data + 9);
301  }
302 
303  if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
304  if (!side && (avci->skip_samples || discard_padding))
306  if (side && (avci->skip_samples || discard_padding)) {
307  AV_WL32(side->data, avci->skip_samples);
308  AV_WL32(side->data + 4, discard_padding);
309  AV_WL8(side->data + 8, skip_reason);
310  AV_WL8(side->data + 9, discard_reason);
311  avci->skip_samples = 0;
312  }
313  return 0;
314  }
316 
317  if ((frame->flags & AV_FRAME_FLAG_DISCARD)) {
318  avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
319  *discarded_samples += frame->nb_samples;
320  return AVERROR(EAGAIN);
321  }
322 
323  if (avci->skip_samples > 0) {
324  if (frame->nb_samples <= avci->skip_samples){
325  *discarded_samples += frame->nb_samples;
326  avci->skip_samples -= frame->nb_samples;
327  av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
328  avci->skip_samples);
329  return AVERROR(EAGAIN);
330  } else {
331  av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
332  frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
333  if (avctx->pkt_timebase.num && avctx->sample_rate) {
334  int64_t diff_ts = av_rescale_q(avci->skip_samples,
335  (AVRational){1, avctx->sample_rate},
336  avctx->pkt_timebase);
337  if (frame->pts != AV_NOPTS_VALUE)
338  frame->pts += diff_ts;
339  if (frame->pkt_dts != AV_NOPTS_VALUE)
340  frame->pkt_dts += diff_ts;
341  if (frame->duration >= diff_ts)
342  frame->duration -= diff_ts;
343  } else
344  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
345 
346  av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
347  avci->skip_samples, frame->nb_samples);
348  *discarded_samples += avci->skip_samples;
349  frame->nb_samples -= avci->skip_samples;
350  avci->skip_samples = 0;
351  }
352  }
353 
354  if (discard_padding > 0 && discard_padding <= frame->nb_samples) {
355  if (discard_padding == frame->nb_samples) {
356  *discarded_samples += frame->nb_samples;
357  return AVERROR(EAGAIN);
358  } else {
359  if (avctx->pkt_timebase.num && avctx->sample_rate) {
360  int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
361  (AVRational){1, avctx->sample_rate},
362  avctx->pkt_timebase);
363  frame->duration = diff_ts;
364  } else
365  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
366 
367  av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
368  (int)discard_padding, frame->nb_samples);
369  frame->nb_samples -= discard_padding;
370  }
371  }
372 
373  return 0;
374 }
375 
376 /*
377  * The core of the receive_frame_wrapper for the decoders implementing
378  * the simple API. Certain decoders might consume partial packets without
379  * returning any output, so this function needs to be called in a loop until it
380  * returns EAGAIN.
381  **/
382 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
383 {
384  AVCodecInternal *avci = avctx->internal;
385  AVPacket *const pkt = avci->in_pkt;
386  const FFCodec *const codec = ffcodec(avctx->codec);
387  int got_frame, consumed;
388  int ret;
389 
390  if (!pkt->data && !avci->draining) {
392  ret = ff_decode_get_packet(avctx, pkt);
393  if (ret < 0 && ret != AVERROR_EOF)
394  return ret;
395  }
396 
397  // Some codecs (at least wma lossless) will crash when feeding drain packets
398  // after EOF was signaled.
399  if (avci->draining_done)
400  return AVERROR_EOF;
401 
402  if (!pkt->data &&
403  !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
405  return AVERROR_EOF;
406 
407  got_frame = 0;
408 
409  if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
410  consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
411  } else {
412  consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
413 
415  frame->pkt_dts = pkt->dts;
416  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
417 #if FF_API_FRAME_PKT
419  if(!avctx->has_b_frames)
420  frame->pkt_pos = pkt->pos;
422 #endif
423  }
424  }
425  emms_c();
426 
427  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
428  ret = (!got_frame || frame->flags & AV_FRAME_FLAG_DISCARD)
429  ? AVERROR(EAGAIN)
430  : 0;
431  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
432  ret = !got_frame ? AVERROR(EAGAIN)
433  : discard_samples(avctx, frame, discarded_samples);
434  }
435 
436  if (ret == AVERROR(EAGAIN))
438 
439  // FF_CODEC_CB_TYPE_DECODE decoders must not return AVERROR EAGAIN
440  // code later will add AVERROR(EAGAIN) to a pointer
441  av_assert0(consumed != AVERROR(EAGAIN));
442  if (consumed < 0)
443  ret = consumed;
444  if (consumed >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
445  consumed = pkt->size;
446 
447  if (!ret)
448  av_assert0(frame->buf[0]);
449  if (ret == AVERROR(EAGAIN))
450  ret = 0;
451 
452  /* do not stop draining when got_frame != 0 or ret < 0 */
453  if (avci->draining && !got_frame) {
454  if (ret < 0) {
455  /* prevent infinite loop if a decoder wrongly always return error on draining */
456  /* reasonable nb_errors_max = maximum b frames + thread count */
457  int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
458  avctx->thread_count : 1);
459 
460  if (decode_ctx(avci)->nb_draining_errors++ >= nb_errors_max) {
461  av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
462  "Stop draining and force EOF.\n");
463  avci->draining_done = 1;
464  ret = AVERROR_BUG;
465  }
466  } else {
467  avci->draining_done = 1;
468  }
469  }
470 
471  if (consumed >= pkt->size || ret < 0) {
473  } else {
474  pkt->data += consumed;
475  pkt->size -= consumed;
479 #if FF_API_FRAME_PKT
480  // See extract_packet_props() comment.
481  avci->last_pkt_props->stream_index = avci->last_pkt_props->stream_index - consumed;
482 #endif
485  }
486  }
487 
488  return ret;
489 }
490 
491 #if CONFIG_LCMS2
492 static int detect_colorspace(AVCodecContext *avctx, AVFrame *frame)
493 {
494  AVCodecInternal *avci = avctx->internal;
496  AVColorPrimariesDesc coeffs;
497  enum AVColorPrimaries prim;
498  cmsHPROFILE profile;
499  AVFrameSideData *sd;
500  int ret;
501  if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
502  return 0;
503 
505  if (!sd || !sd->size)
506  return 0;
507 
508  if (!avci->icc.avctx) {
509  ret = ff_icc_context_init(&avci->icc, avctx);
510  if (ret < 0)
511  return ret;
512  }
513 
514  profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size);
515  if (!profile)
516  return AVERROR_INVALIDDATA;
517 
518  ret = ff_icc_profile_sanitize(&avci->icc, profile);
519  if (!ret)
520  ret = ff_icc_profile_read_primaries(&avci->icc, profile, &coeffs);
521  if (!ret)
522  ret = ff_icc_profile_detect_transfer(&avci->icc, profile, &trc);
523  cmsCloseProfile(profile);
524  if (ret < 0)
525  return ret;
526 
527  prim = av_csp_primaries_id_from_desc(&coeffs);
528  if (prim != AVCOL_PRI_UNSPECIFIED)
529  frame->color_primaries = prim;
530  if (trc != AVCOL_TRC_UNSPECIFIED)
531  frame->color_trc = trc;
532  return 0;
533 }
534 #else /* !CONFIG_LCMS2 */
536 {
537  return 0;
538 }
539 #endif
540 
541 static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
542 {
543  int ret;
544 
545  if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
546  frame->color_primaries = avctx->color_primaries;
547  if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
548  frame->color_trc = avctx->color_trc;
549  if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
550  frame->colorspace = avctx->colorspace;
551  if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
552  frame->color_range = avctx->color_range;
553  if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
554  frame->chroma_location = avctx->chroma_sample_location;
555 
556  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
557  if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
558  if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
559  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
560  if (frame->format == AV_SAMPLE_FMT_NONE)
561  frame->format = avctx->sample_fmt;
562  if (!frame->ch_layout.nb_channels) {
563  ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
564  if (ret < 0)
565  return ret;
566  }
567  if (!frame->sample_rate)
568  frame->sample_rate = avctx->sample_rate;
569  }
570 
571  return 0;
572 }
573 
575 {
576  int ret;
577  int64_t discarded_samples = 0;
578 
579  while (!frame->buf[0]) {
580  if (discarded_samples > avctx->max_samples)
581  return AVERROR(EAGAIN);
582  ret = decode_simple_internal(avctx, frame, &discarded_samples);
583  if (ret < 0)
584  return ret;
585  }
586 
587  return 0;
588 }
589 
591 {
592  AVCodecInternal *avci = avctx->internal;
593  DecodeContext *dc = decode_ctx(avci);
594  const FFCodec *const codec = ffcodec(avctx->codec);
595  int ret, ok;
596 
597  av_assert0(!frame->buf[0]);
598 
599  if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
600  ret = codec->cb.receive_frame(avctx, frame);
601  emms_c();
602  if (!ret) {
603  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO)
604  ret = (frame->flags & AV_FRAME_FLAG_DISCARD) ? AVERROR(EAGAIN) : 0;
605  else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
606  int64_t discarded_samples = 0;
607  ret = discard_samples(avctx, frame, &discarded_samples);
608  }
609  }
610  } else
612 
613  if (ret == AVERROR_EOF)
614  avci->draining_done = 1;
615 
616  /* preserve ret */
617  ok = detect_colorspace(avctx, frame);
618  if (ok < 0) {
620  return ok;
621  }
622 
623  if (!ret) {
624  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
625  if (!frame->width)
626  frame->width = avctx->width;
627  if (!frame->height)
628  frame->height = avctx->height;
629  } else
630  frame->flags |= AV_FRAME_FLAG_KEY;
631 
632  ret = fill_frame_props(avctx, frame);
633  if (ret < 0) {
635  return ret;
636  }
637 
638 #if FF_API_FRAME_KEY
640  frame->key_frame = !!(frame->flags & AV_FRAME_FLAG_KEY);
642 #endif
643 #if FF_API_INTERLACED_FRAME
645  frame->interlaced_frame = !!(frame->flags & AV_FRAME_FLAG_INTERLACED);
646  frame->top_field_first = !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST);
648 #endif
649  frame->best_effort_timestamp = guess_correct_pts(dc,
650  frame->pts,
651  frame->pkt_dts);
652 
653  /* the only case where decode data is not set should be decoders
654  * that do not call ff_get_buffer() */
655  av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) ||
656  !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
657 
658  if (frame->private_ref) {
659  FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
660 
661  if (fdd->post_process) {
662  ret = fdd->post_process(avctx, frame);
663  if (ret < 0) {
665  return ret;
666  }
667  }
668  }
669  }
670 
671  /* free the per-frame decode data */
672  av_buffer_unref(&frame->private_ref);
673 
674  return ret;
675 }
676 
678 {
679  AVCodecInternal *avci = avctx->internal;
680  DecodeContext *dc = decode_ctx(avci);
681  int ret;
682 
683  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
684  return AVERROR(EINVAL);
685 
686  if (dc->draining_started)
687  return AVERROR_EOF;
688 
689  if (avpkt && !avpkt->size && avpkt->data)
690  return AVERROR(EINVAL);
691 
692  if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
693  if (!AVPACKET_IS_EMPTY(avci->buffer_pkt))
694  return AVERROR(EAGAIN);
695  ret = av_packet_ref(avci->buffer_pkt, avpkt);
696  if (ret < 0)
697  return ret;
698  } else
699  dc->draining_started = 1;
700 
701  if (!avci->buffer_frame->buf[0] && !dc->draining_started) {
703  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
704  return ret;
705  }
706 
707  return 0;
708 }
709 
711 {
712  /* make sure we are noisy about decoders returning invalid cropping data */
713  if (frame->crop_left >= INT_MAX - frame->crop_right ||
714  frame->crop_top >= INT_MAX - frame->crop_bottom ||
715  (frame->crop_left + frame->crop_right) >= frame->width ||
716  (frame->crop_top + frame->crop_bottom) >= frame->height) {
717  av_log(avctx, AV_LOG_WARNING,
718  "Invalid cropping information set by a decoder: "
720  "(frame size %dx%d). This is a bug, please report it\n",
721  frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
722  frame->width, frame->height);
723  frame->crop_left = 0;
724  frame->crop_right = 0;
725  frame->crop_top = 0;
726  frame->crop_bottom = 0;
727  return 0;
728  }
729 
730  if (!avctx->apply_cropping)
731  return 0;
732 
735 }
736 
737 // make sure frames returned to the caller are valid
739 {
740  if (!frame->buf[0] || frame->format < 0)
741  goto fail;
742 
743  switch (avctx->codec_type) {
744  case AVMEDIA_TYPE_VIDEO:
745  if (frame->width <= 0 || frame->height <= 0)
746  goto fail;
747  break;
748  case AVMEDIA_TYPE_AUDIO:
749  if (!av_channel_layout_check(&frame->ch_layout) ||
750  frame->sample_rate <= 0)
751  goto fail;
752 
753  break;
754  default: av_assert0(0);
755  }
756 
757  return 0;
758 fail:
759  av_log(avctx, AV_LOG_ERROR, "An invalid frame was output by a decoder. "
760  "This is a bug, please report it.\n");
761  return AVERROR_BUG;
762 }
763 
765 {
766  AVCodecInternal *avci = avctx->internal;
767  int ret;
768 
769  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
770  return AVERROR(EINVAL);
771 
772  if (avci->buffer_frame->buf[0]) {
774  } else {
776  if (ret < 0)
777  return ret;
778  }
779 
780  ret = frame_validate(avctx, frame);
781  if (ret < 0)
782  goto fail;
783 
784  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
785  ret = apply_cropping(avctx, frame);
786  if (ret < 0)
787  goto fail;
788  }
789 
790  avctx->frame_num++;
791 
792 #if FF_API_DROPCHANGED
793  if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) {
794 
795  if (avctx->frame_num == 1) {
796  avci->initial_format = frame->format;
797  switch(avctx->codec_type) {
798  case AVMEDIA_TYPE_VIDEO:
799  avci->initial_width = frame->width;
800  avci->initial_height = frame->height;
801  break;
802  case AVMEDIA_TYPE_AUDIO:
803  avci->initial_sample_rate = frame->sample_rate ? frame->sample_rate :
804  avctx->sample_rate;
805  ret = av_channel_layout_copy(&avci->initial_ch_layout, &frame->ch_layout);
806  if (ret < 0)
807  goto fail;
808  break;
809  }
810  }
811 
812  if (avctx->frame_num > 1) {
813  int changed = avci->initial_format != frame->format;
814 
815  switch(avctx->codec_type) {
816  case AVMEDIA_TYPE_VIDEO:
817  changed |= avci->initial_width != frame->width ||
818  avci->initial_height != frame->height;
819  break;
820  case AVMEDIA_TYPE_AUDIO:
821  changed |= avci->initial_sample_rate != frame->sample_rate ||
822  avci->initial_sample_rate != avctx->sample_rate ||
824  break;
825  }
826 
827  if (changed) {
828  avci->changed_frames_dropped++;
829  av_log(avctx, AV_LOG_INFO, "dropped changed frame #%"PRId64" pts %"PRId64
830  " drop count: %d \n",
831  avctx->frame_num, frame->pts,
832  avci->changed_frames_dropped);
834  goto fail;
835  }
836  }
837  }
838 #endif
839  return 0;
840 fail:
842  return ret;
843 }
844 
846 {
847  memset(sub, 0, sizeof(*sub));
848  sub->pts = AV_NOPTS_VALUE;
849 }
850 
851 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
852 static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt,
853  const AVPacket *inpkt, AVPacket *buf_pkt)
854 {
855 #if CONFIG_ICONV
856  iconv_t cd = (iconv_t)-1;
857  int ret = 0;
858  char *inb, *outb;
859  size_t inl, outl;
860 #endif
861 
862  if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) {
863  *outpkt = inpkt;
864  return 0;
865  }
866 
867 #if CONFIG_ICONV
868  inb = inpkt->data;
869  inl = inpkt->size;
870 
871  if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) {
872  av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
873  return AVERROR(ERANGE);
874  }
875 
876  cd = iconv_open("UTF-8", avctx->sub_charenc);
877  av_assert0(cd != (iconv_t)-1);
878 
879  ret = av_new_packet(buf_pkt, inl * UTF8_MAX_BYTES);
880  if (ret < 0)
881  goto end;
882  ret = av_packet_copy_props(buf_pkt, inpkt);
883  if (ret < 0)
884  goto end;
885  outb = buf_pkt->data;
886  outl = buf_pkt->size;
887 
888  if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
889  iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
890  outl >= buf_pkt->size || inl != 0) {
891  ret = FFMIN(AVERROR(errno), -1);
892  av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
893  "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
894  goto end;
895  }
896  buf_pkt->size -= outl;
897  memset(buf_pkt->data + buf_pkt->size, 0, outl);
898  *outpkt = buf_pkt;
899 
900  ret = 0;
901 end:
902  if (ret < 0)
903  av_packet_unref(buf_pkt);
904  if (cd != (iconv_t)-1)
905  iconv_close(cd);
906  return ret;
907 #else
908  av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
909  return AVERROR(EINVAL);
910 #endif
911 }
912 
913 static int utf8_check(const uint8_t *str)
914 {
915  const uint8_t *byte;
916  uint32_t codepoint, min;
917 
918  while (*str) {
919  byte = str;
920  GET_UTF8(codepoint, *(byte++), return 0;);
921  min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
922  1 << (5 * (byte - str) - 4);
923  if (codepoint < min || codepoint >= 0x110000 ||
924  codepoint == 0xFFFE /* BOM */ ||
925  codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
926  return 0;
927  str = byte;
928  }
929  return 1;
930 }
931 
933  int *got_sub_ptr, const AVPacket *avpkt)
934 {
935  int ret = 0;
936 
937  if (!avpkt->data && avpkt->size) {
938  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
939  return AVERROR(EINVAL);
940  }
941  if (!avctx->codec)
942  return AVERROR(EINVAL);
944  av_log(avctx, AV_LOG_ERROR, "Codec not subtitle decoder\n");
945  return AVERROR(EINVAL);
946  }
947 
948  *got_sub_ptr = 0;
950 
951  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
952  AVCodecInternal *avci = avctx->internal;
953  const AVPacket *pkt;
954 
955  ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
956  if (ret < 0)
957  return ret;
958 
959  if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
960  sub->pts = av_rescale_q(avpkt->pts,
961  avctx->pkt_timebase, AV_TIME_BASE_Q);
962  ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
963  if (pkt == avci->buffer_pkt) // did we recode?
965  if (ret < 0) {
966  *got_sub_ptr = 0;
967  avsubtitle_free(sub);
968  return ret;
969  }
970  av_assert1(!sub->num_rects || *got_sub_ptr);
971 
972  if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
973  avctx->pkt_timebase.num) {
974  AVRational ms = { 1, 1000 };
975  sub->end_display_time = av_rescale_q(avpkt->duration,
976  avctx->pkt_timebase, ms);
977  }
978 
980  sub->format = 0;
981  else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
982  sub->format = 1;
983 
984  for (unsigned i = 0; i < sub->num_rects; i++) {
986  sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
987  av_log(avctx, AV_LOG_ERROR,
988  "Invalid UTF-8 in decoded subtitles text; "
989  "maybe missing -sub_charenc option\n");
990  avsubtitle_free(sub);
991  *got_sub_ptr = 0;
992  return AVERROR_INVALIDDATA;
993  }
994  }
995 
996  if (*got_sub_ptr)
997  avctx->frame_num++;
998  }
999 
1000  return ret;
1001 }
1002 
1004  const enum AVPixelFormat *fmt)
1005 {
1006  const AVPixFmtDescriptor *desc;
1007  const AVCodecHWConfig *config;
1008  int i, n;
1009 
1010  // If a device was supplied when the codec was opened, assume that the
1011  // user wants to use it.
1012  if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
1013  AVHWDeviceContext *device_ctx =
1015  for (i = 0;; i++) {
1016  config = &ffcodec(avctx->codec)->hw_configs[i]->public;
1017  if (!config)
1018  break;
1019  if (!(config->methods &
1021  continue;
1022  if (device_ctx->type != config->device_type)
1023  continue;
1024  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1025  if (config->pix_fmt == fmt[n])
1026  return fmt[n];
1027  }
1028  }
1029  }
1030  // No device or other setup, so we have to choose from things which
1031  // don't any other external information.
1032 
1033  // If the last element of the list is a software format, choose it
1034  // (this should be best software format if any exist).
1035  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1036  desc = av_pix_fmt_desc_get(fmt[n - 1]);
1037  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1038  return fmt[n - 1];
1039 
1040  // Finally, traverse the list in order and choose the first entry
1041  // with no external dependencies (if there is no hardware configuration
1042  // information available then this just picks the first entry).
1043  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1044  for (i = 0;; i++) {
1045  config = avcodec_get_hw_config(avctx->codec, i);
1046  if (!config)
1047  break;
1048  if (config->pix_fmt == fmt[n])
1049  break;
1050  }
1051  if (!config) {
1052  // No specific config available, so the decoder must be able
1053  // to handle this format without any additional setup.
1054  return fmt[n];
1055  }
1056  if (config->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
1057  // Usable with only internal setup.
1058  return fmt[n];
1059  }
1060  }
1061 
1062  // Nothing is usable, give up.
1063  return AV_PIX_FMT_NONE;
1064 }
1065 
1067  enum AVHWDeviceType dev_type)
1068 {
1069  AVHWDeviceContext *device_ctx;
1070  AVHWFramesContext *frames_ctx;
1071  int ret;
1072 
1073  if (!avctx->hwaccel)
1074  return AVERROR(ENOSYS);
1075 
1076  if (avctx->hw_frames_ctx)
1077  return 0;
1078  if (!avctx->hw_device_ctx) {
1079  av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
1080  "required for hardware accelerated decoding.\n");
1081  return AVERROR(EINVAL);
1082  }
1083 
1084  device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data;
1085  if (device_ctx->type != dev_type) {
1086  av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware "
1087  "decoding, but got %s.\n", av_hwdevice_get_type_name(dev_type),
1088  av_hwdevice_get_type_name(device_ctx->type));
1089  return AVERROR(EINVAL);
1090  }
1091 
1093  avctx->hw_device_ctx,
1094  avctx->hwaccel->pix_fmt,
1095  &avctx->hw_frames_ctx);
1096  if (ret < 0)
1097  return ret;
1098 
1099  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1100 
1101 
1102  if (frames_ctx->initial_pool_size) {
1103  // We guarantee 4 base work surfaces. The function above guarantees 1
1104  // (the absolute minimum), so add the missing count.
1105  frames_ctx->initial_pool_size += 3;
1106  }
1107 
1109  if (ret < 0) {
1110  av_buffer_unref(&avctx->hw_frames_ctx);
1111  return ret;
1112  }
1113 
1114  return 0;
1115 }
1116 
1118  AVBufferRef *device_ref,
1120  AVBufferRef **out_frames_ref)
1121 {
1122  AVBufferRef *frames_ref = NULL;
1123  const AVCodecHWConfigInternal *hw_config;
1124  const FFHWAccel *hwa;
1125  int i, ret;
1126 
1127  for (i = 0;; i++) {
1128  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1129  if (!hw_config)
1130  return AVERROR(ENOENT);
1131  if (hw_config->public.pix_fmt == hw_pix_fmt)
1132  break;
1133  }
1134 
1135  hwa = hw_config->hwaccel;
1136  if (!hwa || !hwa->frame_params)
1137  return AVERROR(ENOENT);
1138 
1139  frames_ref = av_hwframe_ctx_alloc(device_ref);
1140  if (!frames_ref)
1141  return AVERROR(ENOMEM);
1142 
1143  if (!avctx->internal->hwaccel_priv_data) {
1144  avctx->internal->hwaccel_priv_data =
1145  av_mallocz(hwa->priv_data_size);
1146  if (!avctx->internal->hwaccel_priv_data) {
1147  av_buffer_unref(&frames_ref);
1148  return AVERROR(ENOMEM);
1149  }
1150  }
1151 
1152  ret = hwa->frame_params(avctx, frames_ref);
1153  if (ret >= 0) {
1154  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
1155 
1156  if (frames_ctx->initial_pool_size) {
1157  // If the user has requested that extra output surfaces be
1158  // available then add them here.
1159  if (avctx->extra_hw_frames > 0)
1160  frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1161 
1162  // If frame threading is enabled then an extra surface per thread
1163  // is also required.
1164  if (avctx->active_thread_type & FF_THREAD_FRAME)
1165  frames_ctx->initial_pool_size += avctx->thread_count;
1166  }
1167 
1168  *out_frames_ref = frames_ref;
1169  } else {
1170  av_buffer_unref(&frames_ref);
1171  }
1172  return ret;
1173 }
1174 
1175 static int hwaccel_init(AVCodecContext *avctx,
1176  const FFHWAccel *hwaccel)
1177 {
1178  int err;
1179 
1180  if (hwaccel->p.capabilities & AV_HWACCEL_CODEC_CAP_EXPERIMENTAL &&
1182  av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1183  hwaccel->p.name);
1184  return AVERROR_PATCHWELCOME;
1185  }
1186 
1187  if (!avctx->internal->hwaccel_priv_data && hwaccel->priv_data_size) {
1188  avctx->internal->hwaccel_priv_data =
1189  av_mallocz(hwaccel->priv_data_size);
1190  if (!avctx->internal->hwaccel_priv_data)
1191  return AVERROR(ENOMEM);
1192  }
1193 
1194  avctx->hwaccel = &hwaccel->p;
1195  if (hwaccel->init) {
1196  err = hwaccel->init(avctx);
1197  if (err < 0) {
1198  av_log(avctx, AV_LOG_ERROR, "Failed setup for format %s: "
1199  "hwaccel initialisation returned error.\n",
1200  av_get_pix_fmt_name(hwaccel->p.pix_fmt));
1202  avctx->hwaccel = NULL;
1203  return err;
1204  }
1205  }
1206 
1207  return 0;
1208 }
1209 
1211 {
1212  if (FF_HW_HAS_CB(avctx, uninit))
1213  FF_HW_SIMPLE_CALL(avctx, uninit);
1214 
1216 
1217  avctx->hwaccel = NULL;
1218 
1219  av_buffer_unref(&avctx->hw_frames_ctx);
1220 }
1221 
1222 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1223 {
1224  const AVPixFmtDescriptor *desc;
1225  enum AVPixelFormat *choices;
1226  enum AVPixelFormat ret, user_choice;
1227  const AVCodecHWConfigInternal *hw_config;
1228  const AVCodecHWConfig *config;
1229  int i, n, err;
1230 
1231  // Find end of list.
1232  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1233  // Must contain at least one entry.
1234  av_assert0(n >= 1);
1235  // If a software format is available, it must be the last entry.
1236  desc = av_pix_fmt_desc_get(fmt[n - 1]);
1237  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1238  // No software format is available.
1239  } else {
1240  avctx->sw_pix_fmt = fmt[n - 1];
1241  }
1242 
1243  choices = av_memdup(fmt, (n + 1) * sizeof(*choices));
1244  if (!choices)
1245  return AV_PIX_FMT_NONE;
1246 
1247  for (;;) {
1248  // Remove the previous hwaccel, if there was one.
1249  ff_hwaccel_uninit(avctx);
1250 
1251  user_choice = avctx->get_format(avctx, choices);
1252  if (user_choice == AV_PIX_FMT_NONE) {
1253  // Explicitly chose nothing, give up.
1254  ret = AV_PIX_FMT_NONE;
1255  break;
1256  }
1257 
1258  desc = av_pix_fmt_desc_get(user_choice);
1259  if (!desc) {
1260  av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
1261  "get_format() callback.\n");
1262  ret = AV_PIX_FMT_NONE;
1263  break;
1264  }
1265  av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
1266  desc->name);
1267 
1268  for (i = 0; i < n; i++) {
1269  if (choices[i] == user_choice)
1270  break;
1271  }
1272  if (i == n) {
1273  av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
1274  "%s not in possible list.\n", desc->name);
1275  ret = AV_PIX_FMT_NONE;
1276  break;
1277  }
1278 
1279  if (ffcodec(avctx->codec)->hw_configs) {
1280  for (i = 0;; i++) {
1281  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1282  if (!hw_config)
1283  break;
1284  if (hw_config->public.pix_fmt == user_choice)
1285  break;
1286  }
1287  } else {
1288  hw_config = NULL;
1289  }
1290 
1291  if (!hw_config) {
1292  // No config available, so no extra setup required.
1293  ret = user_choice;
1294  break;
1295  }
1296  config = &hw_config->public;
1297 
1298  if (config->methods &
1300  avctx->hw_frames_ctx) {
1301  const AVHWFramesContext *frames_ctx =
1303  if (frames_ctx->format != user_choice) {
1304  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1305  "does not match the format of the provided frames "
1306  "context.\n", desc->name);
1307  goto try_again;
1308  }
1309  } else if (config->methods &
1311  avctx->hw_device_ctx) {
1312  const AVHWDeviceContext *device_ctx =
1314  if (device_ctx->type != config->device_type) {
1315  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1316  "does not match the type of the provided device "
1317  "context.\n", desc->name);
1318  goto try_again;
1319  }
1320  } else if (config->methods &
1322  // Internal-only setup, no additional configuration.
1323  } else if (config->methods &
1325  // Some ad-hoc configuration we can't see and can't check.
1326  } else {
1327  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1328  "missing configuration.\n", desc->name);
1329  goto try_again;
1330  }
1331  if (hw_config->hwaccel) {
1332  av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel %s "
1333  "initialisation.\n", desc->name, hw_config->hwaccel->p.name);
1334  err = hwaccel_init(avctx, hw_config->hwaccel);
1335  if (err < 0)
1336  goto try_again;
1337  }
1338  ret = user_choice;
1339  break;
1340 
1341  try_again:
1342  av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
1343  "get_format() without it.\n", desc->name);
1344  for (i = 0; i < n; i++) {
1345  if (choices[i] == user_choice)
1346  break;
1347  }
1348  for (; i + 1 < n; i++)
1349  choices[i] = choices[i + 1];
1350  --n;
1351  }
1352 
1353  if (ret < 0)
1354  ff_hwaccel_uninit(avctx);
1355 
1356  av_freep(&choices);
1357  return ret;
1358 }
1359 
1362 {
1363  for (int i = 0; i < avctx->nb_coded_side_data; i++)
1364  if (avctx->coded_side_data[i].type == type)
1365  return &avctx->coded_side_data[i];
1366 
1367  return NULL;
1368 }
1369 
1371 {
1372  size_t size;
1373  const uint8_t *side_metadata;
1374 
1375  AVDictionary **frame_md = &frame->metadata;
1376 
1377  side_metadata = av_packet_get_side_data(avpkt,
1379  return av_packet_unpack_dictionary(side_metadata, size, frame_md);
1380 }
1381 
1383  AVFrame *frame, const AVPacket *pkt)
1384 {
1385  static const struct {
1386  enum AVPacketSideDataType packet;
1388  } sd[] = {
1394  };
1395 
1396  frame->pts = pkt->pts;
1397  frame->duration = pkt->duration;
1398 #if FF_API_FRAME_PKT
1400  frame->pkt_pos = pkt->pos;
1401  frame->pkt_size = pkt->size;
1403 #endif
1404 
1405  for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) {
1406  size_t size;
1407  const uint8_t *packet_sd = av_packet_get_side_data(pkt, ff_sd_global_map[i].packet, &size);
1408  if (packet_sd) {
1409  AVFrameSideData *frame_sd;
1410 
1412  if (!frame_sd)
1413  return AVERROR(ENOMEM);
1414  memcpy(frame_sd->data, packet_sd, size);
1415  }
1416  }
1417  for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
1418  size_t size;
1419  uint8_t *packet_sd = av_packet_get_side_data(pkt, sd[i].packet, &size);
1420  if (packet_sd) {
1422  sd[i].frame,
1423  size);
1424  if (!frame_sd)
1425  return AVERROR(ENOMEM);
1426 
1427  memcpy(frame_sd->data, packet_sd, size);
1428  }
1429  }
1431 
1432  if (pkt->flags & AV_PKT_FLAG_DISCARD) {
1433  frame->flags |= AV_FRAME_FLAG_DISCARD;
1434  } else {
1435  frame->flags = (frame->flags & ~AV_FRAME_FLAG_DISCARD);
1436  }
1437 
1438  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
1439  int ret = av_buffer_replace(&frame->opaque_ref, pkt->opaque_ref);
1440  if (ret < 0)
1441  return ret;
1442  frame->opaque = pkt->opaque;
1443  }
1444 
1445  return 0;
1446 }
1447 
1449 {
1450  int ret;
1451 
1452  for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) {
1453  const AVPacketSideData *packet_sd = ff_get_coded_side_data(avctx,
1454  ff_sd_global_map[i].packet);
1455  if (packet_sd) {
1458  packet_sd->size);
1459  if (!frame_sd)
1460  return AVERROR(ENOMEM);
1461 
1462  memcpy(frame_sd->data, packet_sd->data, packet_sd->size);
1463  }
1464  }
1465 
1467  const AVPacket *pkt = avctx->internal->last_pkt_props;
1468 
1470  if (ret < 0)
1471  return ret;
1472 #if FF_API_FRAME_PKT
1474  frame->pkt_size = pkt->stream_index;
1476 #endif
1477  }
1478 
1479  ret = fill_frame_props(avctx, frame);
1480  if (ret < 0)
1481  return ret;
1482 
1483  switch (avctx->codec->type) {
1484  case AVMEDIA_TYPE_VIDEO:
1485  if (frame->width && frame->height &&
1486  av_image_check_sar(frame->width, frame->height,
1487  frame->sample_aspect_ratio) < 0) {
1488  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1489  frame->sample_aspect_ratio.num,
1490  frame->sample_aspect_ratio.den);
1491  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
1492  }
1493  break;
1494  }
1495  return 0;
1496 }
1497 
1499 {
1500  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1501  int i;
1502  int num_planes = av_pix_fmt_count_planes(frame->format);
1504  int flags = desc ? desc->flags : 0;
1505  if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL))
1506  num_planes = 2;
1507  for (i = 0; i < num_planes; i++) {
1508  av_assert0(frame->data[i]);
1509  }
1510  // For formats without data like hwaccel allow unused pointers to be non-NULL.
1511  for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) {
1512  if (frame->data[i])
1513  av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
1514  frame->data[i] = NULL;
1515  }
1516  }
1517 }
1518 
1519 static void decode_data_free(void *opaque, uint8_t *data)
1520 {
1522 
1523  if (fdd->post_process_opaque_free)
1525 
1526  if (fdd->hwaccel_priv_free)
1527  fdd->hwaccel_priv_free(fdd->hwaccel_priv);
1528 
1529  av_freep(&fdd);
1530 }
1531 
1533 {
1534  AVBufferRef *fdd_buf;
1535  FrameDecodeData *fdd;
1536 
1537  av_assert1(!frame->private_ref);
1538  av_buffer_unref(&frame->private_ref);
1539 
1540  fdd = av_mallocz(sizeof(*fdd));
1541  if (!fdd)
1542  return AVERROR(ENOMEM);
1543 
1544  fdd_buf = av_buffer_create((uint8_t*)fdd, sizeof(*fdd), decode_data_free,
1546  if (!fdd_buf) {
1547  av_freep(&fdd);
1548  return AVERROR(ENOMEM);
1549  }
1550 
1551  frame->private_ref = fdd_buf;
1552 
1553  return 0;
1554 }
1555 
1557 {
1558  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1559  int override_dimensions = 1;
1560  int ret;
1561 
1563 
1564  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1565  if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
1566  (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) {
1567  av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
1568  ret = AVERROR(EINVAL);
1569  goto fail;
1570  }
1571 
1572  if (frame->width <= 0 || frame->height <= 0) {
1573  frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
1574  frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
1575  override_dimensions = 0;
1576  }
1577 
1578  if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
1579  av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
1580  ret = AVERROR(EINVAL);
1581  goto fail;
1582  }
1583  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1584  if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
1585  av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
1586  ret = AVERROR(EINVAL);
1587  goto fail;
1588  }
1589  }
1590  ret = ff_decode_frame_props(avctx, frame);
1591  if (ret < 0)
1592  goto fail;
1593 
1594  if (hwaccel) {
1595  if (hwaccel->alloc_frame) {
1596  ret = hwaccel->alloc_frame(avctx, frame);
1597  goto end;
1598  }
1599  } else
1600  avctx->sw_pix_fmt = avctx->pix_fmt;
1601 
1602  ret = avctx->get_buffer2(avctx, frame, flags);
1603  if (ret < 0)
1604  goto fail;
1605 
1607 
1609  if (ret < 0)
1610  goto fail;
1611 
1612 end:
1613  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
1615  frame->width = avctx->width;
1616  frame->height = avctx->height;
1617  }
1618 
1619 fail:
1620  if (ret < 0) {
1621  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1623  }
1624 
1625  return ret;
1626 }
1627 
1629 {
1630  AVFrame *tmp;
1631  int ret;
1632 
1634 
1635  if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1636  av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1637  frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1639  }
1640 
1641  if (!frame->data[0])
1642  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1643 
1645  return ff_decode_frame_props(avctx, frame);
1646 
1647  tmp = av_frame_alloc();
1648  if (!tmp)
1649  return AVERROR(ENOMEM);
1650 
1652 
1654  if (ret < 0) {
1655  av_frame_free(&tmp);
1656  return ret;
1657  }
1658 
1660  av_frame_free(&tmp);
1661 
1662  return 0;
1663 }
1664 
1666 {
1667  int ret = reget_buffer_internal(avctx, frame, flags);
1668  if (ret < 0)
1669  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1670  return ret;
1671 }
1672 
1673 typedef struct ProgressInternal {
1675  struct AVFrame *f;
1677 
1679 {
1680  av_assert1(!!f->f == !!f->progress);
1681  av_assert1(!f->progress || f->progress->f == f->f);
1682 }
1683 
1685 {
1687 
1688  av_assert1(!f->f && !f->progress);
1689 
1690  f->progress = ff_refstruct_pool_get(pool);
1691  if (!f->progress)
1692  return AVERROR(ENOMEM);
1693 
1694  f->f = f->progress->f;
1695  return 0;
1696 }
1697 
1699 {
1700  int ret;
1701 
1702  ret = progress_frame_get(avctx, f);
1703  if (ret < 0)
1704  return ret;
1705 
1706  ret = ff_thread_get_buffer(avctx, f->progress->f, flags);
1707  if (ret < 0) {
1708  f->f = NULL;
1709  ff_refstruct_unref(&f->progress);
1710  return ret;
1711  }
1712  return 0;
1713 }
1714 
1716 {
1717  av_assert1(src->progress && src->f && src->f == src->progress->f);
1718  av_assert1(!dst->f && !dst->progress);
1719  dst->f = src->f;
1720  dst->progress = ff_refstruct_ref(src->progress);
1721 }
1722 
1724 {
1726  f->f = NULL;
1727  ff_refstruct_unref(&f->progress);
1728 }
1729 
1731 {
1732  if (dst == src)
1733  return;
1736  if (src->f)
1737  ff_progress_frame_ref(dst, src);
1738 }
1739 
1741 {
1742  ff_thread_progress_report(&f->progress->progress, n);
1743 }
1744 
1746 {
1747  ff_thread_progress_await(&f->progress->progress, n);
1748 }
1749 
1750 #if !HAVE_THREADS
1752 {
1754 }
1755 #endif /* !HAVE_THREADS */
1756 
1758 {
1759  const AVCodecContext *avctx = opaque.nc;
1760  ProgressInternal *progress = obj;
1761  int ret;
1762 
1764  if (ret < 0)
1765  return ret;
1766 
1767  progress->f = av_frame_alloc();
1768  if (!progress->f)
1769  return AVERROR(ENOMEM);
1770 
1771  return 0;
1772 }
1773 
1774 static void progress_frame_pool_reset_cb(FFRefStructOpaque unused, void *obj)
1775 {
1776  ProgressInternal *progress = obj;
1777 
1778  ff_thread_progress_reset(&progress->progress);
1779  av_frame_unref(progress->f);
1780 }
1781 
1783 {
1784  ProgressInternal *progress = obj;
1785 
1787  av_frame_free(&progress->f);
1788 }
1789 
1791 {
1792  AVCodecInternal *avci = avctx->internal;
1793  DecodeContext *dc = decode_ctx(avci);
1794  int ret = 0;
1795 
1796  /* if the decoder init function was already called previously,
1797  * free the already allocated subtitle_header before overwriting it */
1798  av_freep(&avctx->subtitle_header);
1799 
1800  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1801  av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
1802  avctx->codec->max_lowres);
1803  avctx->lowres = avctx->codec->max_lowres;
1804  }
1805  if (avctx->sub_charenc) {
1806  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1807  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1808  "supported with subtitles codecs\n");
1809  return AVERROR(EINVAL);
1810  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1811  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1812  "subtitles character encoding will be ignored\n",
1813  avctx->codec_descriptor->name);
1815  } else {
1816  /* input character encoding is set for a text based subtitle
1817  * codec at this point */
1820 
1822 #if CONFIG_ICONV
1823  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1824  if (cd == (iconv_t)-1) {
1825  ret = AVERROR(errno);
1826  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1827  "with input character encoding \"%s\"\n", avctx->sub_charenc);
1828  return ret;
1829  }
1830  iconv_close(cd);
1831 #else
1832  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1833  "conversion needs a libavcodec built with iconv support "
1834  "for this codec\n");
1835  return AVERROR(ENOSYS);
1836 #endif
1837  }
1838  }
1839  }
1840 
1841  dc->pts_correction_num_faulty_pts =
1842  dc->pts_correction_num_faulty_dts = 0;
1843  dc->pts_correction_last_pts =
1844  dc->pts_correction_last_dts = INT64_MIN;
1845 
1846  if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
1848  av_log(avctx, AV_LOG_WARNING,
1849  "gray decoding requested but not enabled at configuration time\n");
1850  if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
1852  }
1853 
1854  if (avctx->nb_side_data_prefer_packet == 1 &&
1855  avctx->side_data_prefer_packet[0] == -1)
1856  dc->side_data_pref_mask = ~0ULL;
1857  else {
1858  for (unsigned i = 0; i < avctx->nb_side_data_prefer_packet; i++) {
1859  int val = avctx->side_data_prefer_packet[i];
1860 
1861  if (val < 0 || val >= AV_PKT_DATA_NB) {
1862  av_log(avctx, AV_LOG_ERROR, "Invalid side data type: %d\n", val);
1863  return AVERROR(EINVAL);
1864  }
1865 
1866  for (unsigned j = 0; ff_sd_global_map[j].packet < AV_PKT_DATA_NB; j++) {
1867  if (ff_sd_global_map[j].packet == val) {
1868  val = ff_sd_global_map[j].frame;
1869 
1870  // this code will need to be changed when we have more than
1871  // 64 frame side data types
1872  if (val >= 64) {
1873  av_log(avctx, AV_LOG_ERROR, "Side data type too big\n");
1874  return AVERROR_BUG;
1875  }
1876 
1877  dc->side_data_pref_mask |= 1ULL << val;
1878  }
1879  }
1880  }
1881  }
1882 
1883  avci->in_pkt = av_packet_alloc();
1884  avci->last_pkt_props = av_packet_alloc();
1885  if (!avci->in_pkt || !avci->last_pkt_props)
1886  return AVERROR(ENOMEM);
1887 
1889  avci->progress_frame_pool =
1895  if (!avci->progress_frame_pool)
1896  return AVERROR(ENOMEM);
1897  }
1898  ret = decode_bsfs_init(avctx);
1899  if (ret < 0)
1900  return ret;
1901 
1902 #if FF_API_DROPCHANGED
1903  if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED)
1904  av_log(avctx, AV_LOG_WARNING, "The dropchanged flag is deprecated.\n");
1905 #endif
1906 
1907  return 0;
1908 }
1909 
1910 /**
1911  * Check side data preference and clear existing side data from frame
1912  * if needed.
1913  *
1914  * @retval 0 side data of this type can be added to frame
1915  * @retval 1 side data of this type should not be added to frame
1916  */
1917 static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd,
1918  int *nb_sd, enum AVFrameSideDataType type)
1919 {
1920  DecodeContext *dc = decode_ctx(avctx->internal);
1921 
1922  // Note: could be skipped for `type` without corresponding packet sd
1923  if (av_frame_side_data_get(*sd, *nb_sd, type)) {
1924  if (dc->side_data_pref_mask & (1ULL << type))
1925  return 1;
1926  av_frame_side_data_remove(sd, nb_sd, type);
1927  }
1928 
1929  return 0;
1930 }
1931 
1932 
1934  enum AVFrameSideDataType type, size_t size,
1935  AVFrameSideData **psd)
1936 {
1937  AVFrameSideData *sd;
1938 
1939  if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, type)) {
1940  if (psd)
1941  *psd = NULL;
1942  return 0;
1943  }
1944 
1946  if (psd)
1947  *psd = sd;
1948 
1949  return sd ? 0 : AVERROR(ENOMEM);
1950 }
1951 
1953  AVFrameSideData ***sd, int *nb_sd,
1955  AVBufferRef **buf)
1956 {
1957  int ret = 0;
1958 
1959  if (side_data_pref(avctx, sd, nb_sd, type))
1960  goto finish;
1961 
1962  if (!av_frame_side_data_add(sd, nb_sd, type, buf, 0))
1963  ret = AVERROR(ENOMEM);
1964 
1965 finish:
1967 
1968  return ret;
1969 }
1970 
1973  AVBufferRef **buf, AVFrameSideData **psd)
1974 {
1976  &frame->side_data, &frame->nb_side_data,
1977  type, buf);
1978 }
1979 
1981  AVFrameSideData ***sd, int *nb_sd,
1982  struct AVMasteringDisplayMetadata **mdm)
1983 {
1984  AVBufferRef *buf;
1985  size_t size;
1986 
1988  *mdm = NULL;
1989  return 0;
1990  }
1991 
1993  if (!*mdm)
1994  return AVERROR(ENOMEM);
1995 
1996  buf = av_buffer_create((uint8_t *)*mdm, size, NULL, NULL, 0);
1997  if (!buf) {
1998  av_freep(mdm);
1999  return AVERROR(ENOMEM);
2000  }
2001 
2003  &buf, 0)) {
2004  *mdm = NULL;
2005  av_buffer_unref(&buf);
2006  return AVERROR(ENOMEM);
2007  }
2008 
2009  return 0;
2010 }
2011 
2014 {
2015  if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2017  *mdm = NULL;
2018  return 0;
2019  }
2020 
2022  return *mdm ? 0 : AVERROR(ENOMEM);
2023 }
2024 
2026  AVFrameSideData ***sd, int *nb_sd,
2027  AVContentLightMetadata **clm)
2028 {
2029  AVBufferRef *buf;
2030  size_t size;
2031 
2032  if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) {
2033  *clm = NULL;
2034  return 0;
2035  }
2036 
2038  if (!*clm)
2039  return AVERROR(ENOMEM);
2040 
2041  buf = av_buffer_create((uint8_t *)*clm, size, NULL, NULL, 0);
2042  if (!buf) {
2043  av_freep(clm);
2044  return AVERROR(ENOMEM);
2045  }
2046 
2048  &buf, 0)) {
2049  *clm = NULL;
2050  av_buffer_unref(&buf);
2051  return AVERROR(ENOMEM);
2052  }
2053 
2054  return 0;
2055 }
2056 
2058  AVContentLightMetadata **clm)
2059 {
2060  if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2062  *clm = NULL;
2063  return 0;
2064  }
2065 
2067  return *clm ? 0 : AVERROR(ENOMEM);
2068 }
2069 
2070 int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
2071 {
2072  size_t size;
2073  const void *pal = av_packet_get_side_data(src, AV_PKT_DATA_PALETTE, &size);
2074 
2075  if (pal && size == AVPALETTE_SIZE) {
2076  memcpy(dst, pal, AVPALETTE_SIZE);
2077  return 1;
2078  } else if (pal) {
2079  av_log(logctx, AV_LOG_ERROR,
2080  "Palette size %"SIZE_SPECIFIER" is wrong\n", size);
2081  }
2082  return 0;
2083 }
2084 
2085 int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
2086 {
2087  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
2088 
2089  if (!hwaccel || !hwaccel->frame_priv_data_size)
2090  return 0;
2091 
2092  av_assert0(!*hwaccel_picture_private);
2093 
2094  if (hwaccel->free_frame_priv) {
2095  AVHWFramesContext *frames_ctx;
2096 
2097  if (!avctx->hw_frames_ctx)
2098  return AVERROR(EINVAL);
2099 
2100  frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data;
2101  *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,
2102  frames_ctx->device_ctx,
2103  hwaccel->free_frame_priv);
2104  } else {
2105  *hwaccel_picture_private = ff_refstruct_allocz(hwaccel->frame_priv_data_size);
2106  }
2107 
2108  if (!*hwaccel_picture_private)
2109  return AVERROR(ENOMEM);
2110 
2111  return 0;
2112 }
2113 
2115 {
2116  AVCodecInternal *avci = avctx->internal;
2117  DecodeContext *dc = decode_ctx(avci);
2118 
2120  av_packet_unref(avci->in_pkt);
2121 
2122  dc->pts_correction_last_pts =
2123  dc->pts_correction_last_dts = INT64_MIN;
2124 
2125  av_bsf_flush(avci->bsf);
2126 
2127  dc->nb_draining_errors = 0;
2128  dc->draining_started = 0;
2129 }
2130 
2132 {
2133  return av_mallocz(sizeof(DecodeContext));
2134 }
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:1360
AVSubtitle
Definition: avcodec.h:2227
AVCodecInternal::initial_sample_rate
int initial_sample_rate
Definition: internal.h:142
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:1740
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:427
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1427
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
FFCodec::receive_frame
int(* receive_frame)(struct AVCodecContext *avctx, struct AVFrame *frame)
Decode API with decoupled packet/frame dataflow.
Definition: codec_internal.h:209
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
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:1175
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
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:223
hw_pix_fmt
static enum AVPixelFormat hw_pix_fmt
Definition: hw_decode.c:46
progress_frame_pool_reset_cb
static void progress_frame_pool_reset_cb(FFRefStructOpaque unused, void *obj)
Definition: decode.c:1774
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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
ff_refstruct_ref
void * ff_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition: refstruct.c:140
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:2232
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:787
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
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, AVFrameSideData **psd)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
Definition: decode.c:1971
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:424
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:685
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:580
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1222
apply_cropping
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:710
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:1050
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:947
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:795
AVColorPrimariesDesc
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition: csp.h:78
FFCodec::cb
union FFCodec::@69 cb
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2965
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AV_HWACCEL_CODEC_CAP_EXPERIMENTAL
#define AV_HWACCEL_CODEC_CAP_EXPERIMENTAL
HWAccel is experimental and is thus avoided in favor of non experimental codecs.
Definition: avcodec.h:2128
AV_FRAME_DATA_A53_CC
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:59
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:586
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:197
AVCodecInternal::skip_samples
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
Definition: internal.h:118
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1420
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:220
AVCodecContext::codec_descriptor
const struct AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:1861
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
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:397
AVCodecContext::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
Definition: avcodec.h:1915
ff_refstruct_alloc_ext
static void * ff_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
A wrapper around ff_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition: refstruct.h:94
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:999
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2231
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:574
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:160
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:522
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:322
DecodeContext::pts_correction_last_pts
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition: decode.c:70
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:678
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:375
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:206
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:144
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:248
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:524
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:583
ff_progress_frame_get_buffer
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
This function sets up the ProgressFrame, i.e.
Definition: decode.c:1698
data
const char data[16]
Definition: mxf.c:148
AV_PKT_DATA_S12M_TIMECODE
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
Definition: packet.h:292
FFCodec
Definition: codec_internal.h:126
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Definition: avcodec.h:1891
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
Definition: packet.h:601
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:174
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:542
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:1879
AVDictionary
Definition: dict.c:34
FFRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:555
avcodec_default_get_format
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Definition: decode.c:1003
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:691
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:587
AV_RL8
#define AV_RL8(x)
Definition: intreadwrite.h:396
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:94
decode_ctx
static DecodeContext * decode_ctx(AVCodecInternal *avci)
Definition: decode.c:80
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:1878
tf_sess_config.config
config
Definition: tf_sess_config.py:33
thread.h
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:1062
DecodeContext::pts_correction_num_faulty_dts
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition: decode.c:69
ff_hwaccel_uninit
void ff_hwaccel_uninit(AVCodecContext *avctx)
Definition: decode.c:1210
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:638
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:196
AVCodec::max_lowres
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: codec.h:207
AVPacketSideData::size
size_t size
Definition: packet.h:377
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3005
AVCodecInternal::progress_frame_pool
struct FFRefStructPool * progress_frame_pool
Definition: internal.h:64
DecodeContext::nb_draining_errors
int nb_draining_errors
Definition: decode.c:61
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:299
finish
static void finish(void)
Definition: movenc.c:373
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:258
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:454
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:560
STRIDE_ALIGN
#define STRIDE_ALIGN
Definition: internal.h:46
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1065
fail
#define fail()
Definition: checkasm.h:179
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:1582
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
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:1877
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:502
val
static double val(void *priv, double ch)
Definition: aeval.c:78
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:1382
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:1370
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:633
AV_CODEC_HW_CONFIG_METHOD_INTERNAL
@ AV_CODEC_HW_CONFIG_METHOD_INTERNAL
The codec supports this format by some internal method.
Definition: codec.h:322
AVCodecContext::max_samples
int64_t max_samples
The number of samples per frame to maximally accept.
Definition: avcodec.h:1977
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:2224
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
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:393
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:148
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:1222
FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR
#define FF_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
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:473
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:932
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:2025
AV_CODEC_FLAG_DROPCHANGED
#define AV_CODEC_FLAG_DROPCHANGED
Don't output frames whose parameters differ from first decoded frame in stream.
Definition: avcodec.h:244
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
progress_frame_get
static int progress_frame_get(AVCodecContext *avctx, ProgressFrame *f)
Definition: decode.c:1684
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:671
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:73
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:180
AVFrameSideData::size
size_t size
Definition: frame.h:253
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:764
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:625
emms_c
#define emms_c()
Definition: emms.h:63
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:723
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:1715
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition: packet.h:602
AVCodecContext::side_data_prefer_packet
int * side_data_prefer_packet
Decoding only.
Definition: avcodec.h:2060
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:2085
get_subtitle_defaults
static void get_subtitle_defaults(AVSubtitle *sub)
Definition: decode.c:845
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:98
validate_avframe_allocation
static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:1498
AVCodecInternal::buffer_pkt
AVPacket * buffer_pkt
Temporary buffers for newly received or not yet output packets/frames.
Definition: internal.h:133
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:59
FFHWAccel::priv_data_size
int priv_data_size
Size of the private data to allocate in AVCodecInternal.hwaccel_priv_data.
Definition: hwaccel_internal.h:112
AV_BUFFER_FLAG_READONLY
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
Definition: buffer.h:114
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:425
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
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:973
AVERROR_INPUT_CHANGED
#define AVERROR_INPUT_CHANGED
Input changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_OUTPUT_CHANGED)
Definition: error.h:75
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
AVCodecDescriptor::type
enum AVMediaType type
Definition: codec_desc.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AVPacketSideData::data
uint8_t * data
Definition: packet.h:376
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:1723
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:343
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2233
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:1934
ProgressFrame::progress
struct ProgressInternal * progress
Definition: progressframe.h:63
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:112
FFRefStructPool
FFRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition: refstruct.c:183
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:549
ProgressInternal
Definition: decode.c:1673
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:558
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:1678
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:58
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:192
discard_samples
static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:284
decode_data_free
static void decode_data_free(void *opaque, uint8_t *data)
Definition: decode.c:1519
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:1066
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:2012
DecodeContext::draining_started
int draining_started
The caller has submitted a NULL packet on input.
Definition: decode.c:66
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
AVCodecInternal::changed_frames_dropped
int changed_frames_dropped
Definition: internal.h:139
AVCodecContext::sub_charenc
char * sub_charenc
Character encoding of the input subtitles file.
Definition: avcodec.h:1868
ff_decode_internal_alloc
AVCodecInternal * ff_decode_internal_alloc(void)
Definition: decode.c:2131
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:331
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:388
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:65
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:913
NULL
#define NULL
Definition: coverity.c:32
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:2114
AVCodecContext::apply_cropping
int apply_cropping
Video decoding only.
Definition: avcodec.h:1961
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
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
hwaccel_internal.h
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:200
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:1916
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:480
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: frame.c:941
FF_CODEC_CB_TYPE_DECODE_SUB
@ FF_CODEC_CB_TYPE_DECODE_SUB
Definition: codec_internal.h:111
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:378
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
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
ff_refstruct_allocz
static void * ff_refstruct_allocz(size_t size)
Equivalent to ff_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition: refstruct.h:105
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition: frame.h:120
AVCodecInternal::initial_height
int initial_height
Definition: internal.h:141
DecodeContext::pts_correction_last_dts
int64_t pts_correction_last_dts
PTS of the last frame.
Definition: decode.c:71
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:398
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:435
AVCodecInternal::draining_done
int draining_done
Definition: internal.h:135
FF_HW_HAS_CB
#define FF_HW_HAS_CB(avctx, function)
Definition: hwaccel_internal.h:177
UTF8_MAX_BYTES
#define UTF8_MAX_BYTES
Definition: decode.c:851
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:57
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:652
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:83
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:341
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:86
AVCodecContext::lowres
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:1854
f
f
Definition: af_crystalizer.c:121
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:509
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1556
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:322
AVPacket::size
int size
Definition: packet.h:525
ff_thread_decode_frame
int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Submit a new frame to a decoding thread.
Definition: pthread_frame.c:488
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:1520
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:123
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:999
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:300
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:121
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
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::initial_format
int initial_format
Definition: internal.h:140
AVCodecInternal::bsf
struct AVBSFContext * bsf
Definition: internal.h:77
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1057
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:551
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:248
frame_validate
static int frame_validate(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:738
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:1933
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:1952
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:1917
AVFrameSideData::data
uint8_t * data
Definition: frame.h:252
ffcodec
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
Definition: codec_internal.h:305
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:645
fill_frame_props
static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:541
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:706
AVCodecHWConfigInternal
Definition: hwconfig.h:25
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2230
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:347
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:1013
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:523
ProgressInternal::progress
ThreadProgress progress
Definition: decode.c:1674
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:68
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:530
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
ff_progress_frame_await
void ff_progress_frame_await(const ProgressFrame *f, int n)
Wait for earlier decoding threads to finish reference frames.
Definition: decode.c:1745
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:260
DecodeContext::side_data_pref_mask
uint64_t side_data_pref_mask
DTS of the last frame.
Definition: decode.c:77
FF_THREAD_NO_FRAME_THREADING
@ FF_THREAD_NO_FRAME_THREADING
Definition: thread.h:90
AVCodecContext::nb_side_data_prefer_packet
unsigned nb_side_data_prefer_packet
Number of entries in side_data_prefer_packet.
Definition: avcodec.h:2064
detect_colorspace
static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f)
Definition: decode.c:535
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:801
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
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:302
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1593
AV_FRAME_DATA_SKIP_SAMPLES
@ AV_FRAME_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: frame.h:109
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:33
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2094
AV_PKT_DATA_STRINGS_METADATA
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
Definition: packet.h:173
emms.h
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:677
FFCodec::caps_internal
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
Definition: codec_internal.h:135
extract_packet_props
static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
Definition: decode.c:146
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:390
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:2228
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:517
AVCodecInternal::initial_width
int initial_width
Definition: internal.h:141
reget_buffer_internal
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition: decode.c:1628
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: packet.c:252
decode_receive_frame_internal
static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:590
internal.h
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:76
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
ff_decode_preinit
int ff_decode_preinit(AVCodecContext *avctx)
Perform decoder initialization and validation.
Definition: decode.c:1790
ff_thread_progress_init
av_cold int ff_thread_progress_init(ThreadProgress *pro, int init_mode)
Initialize a ThreadProgress.
Definition: threadprogress.c:33
DecodeContext::avci
AVCodecInternal avci
Definition: decode.c:58
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:633
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:606
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
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:1497
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:702
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:2227
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:612
AVCodecContext::height
int height
Definition: avcodec.h:618
decode_simple_internal
static int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:382
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:633
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:315
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:1475
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:200
AVCodecContext::sub_charenc_mode
int sub_charenc_mode
Subtitles character encoding mode.
Definition: avcodec.h:1876
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:2030
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:1117
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:1665
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:72
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:134
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1379
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:775
ProgressFrame::f
struct AVFrame * f
Definition: progressframe.h:62
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:1751
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:2057
ff_thread_progress_destroy
av_cold void ff_thread_progress_destroy(ThreadProgress *pro)
Destroy a ThreadProgress.
Definition: threadprogress.c:44
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:1730
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:85
progress_frame_pool_init_cb
static av_cold int progress_frame_pool_init_cb(FFRefStructOpaque opaque, void *obj)
Definition: decode.c:1757
progress_frame_pool_free_entry_cb
static av_cold void progress_frame_pool_free_entry_cb(FFRefStructOpaque opaque, void *obj)
Definition: decode.c:1782
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:1448
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:445
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1601
recode_subtitle
static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt, const AVPacket *inpkt, AVPacket *buf_pkt)
Definition: decode.c:852
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:45
avcodec_internal.h
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
ff_refstruct_pool_alloc_ext
static FFRefStructPool * ff_refstruct_pool_alloc_ext(size_t size, unsigned flags, void *opaque, int(*init_cb)(FFRefStructOpaque opaque, void *obj), void(*reset_cb)(FFRefStructOpaque opaque, void *obj), void(*free_entry_cb)(FFRefStructOpaque opaque, void *obj), void(*free_cb)(FFRefStructOpaque opaque))
A wrapper around ff_refstruct_pool_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition: refstruct.h:258
ffhwaccel
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
Definition: hwaccel_internal.h:166
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:262
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: packet.h:157
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:1926
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:114
ProgressInternal::f
struct AVFrame * f
Definition: decode.c:1675
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:142
AVPacket::stream_index
int stream_index
Definition: packet.h:526
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:838
AVCodecInternal::buffer_frame
AVFrame * buffer_frame
Definition: internal.h:134
AV_CODEC_CAP_PARAM_CHANGE
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition: codec.h:118
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:440
AVCodecInternal::draining
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:128
FFCodec::bsfs
const char * bsfs
Decoding only, a comma-separated list of bitstream filters to apply to packets before decoding.
Definition: codec_internal.h:251
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:633
AVHWFramesContext::initial_pool_size
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:187
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:453
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:629
desc
const char * desc
Definition: libsvtav1.c:75
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
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:1980
AV_PKT_DATA_A53_CC
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: packet.h:243
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:406
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:1532
AVCodecInternal::initial_ch_layout
AVChannelLayout initial_ch_layout
Definition: internal.h:143
ThreadingStatus
ThreadingStatus
Definition: thread.h:87
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:250
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AV_CODEC_FLAG2_EXPORT_MVS
#define AV_CODEC_FLAG2_EXPORT_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:384
ProgressFrame
Definition: progressframe.h:61
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:501
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:544
DecodeContext::pts_correction_num_faulty_pts
int64_t pts_correction_num_faulty_pts
Definition: decode.c:68
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:1143
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
bytestream.h
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:51
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
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:334
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:664
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:2070
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:161
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
AVHWAccel::pix_fmt
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:2115
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
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:642
DecodeContext
Definition: decode.c:57
av_frame_side_data_add
AVFrameSideData * av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **pbuf, unsigned int flags)
Add a new side data entry to an array from an existing AVBufferRef.
Definition: frame.c:846
FF_REGET_BUFFER_FLAG_READONLY
#define FF_REGET_BUFFER_FLAG_READONLY
the returned buffer does not need to be writable
Definition: decode.h:128
ff_refstruct_pool_get
void * ff_refstruct_pool_get(FFRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
Definition: refstruct.c:297
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:536
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:2885
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:1880
min
float min
Definition: vorbis_enc_data.h:429