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"
38 
39 #include "avcodec.h"
40 #include "avcodec_internal.h"
41 #include "bytestream.h"
42 #include "bsf.h"
43 #include "codec_desc.h"
44 #include "codec_internal.h"
45 #include "decode.h"
46 #include "hwaccel_internal.h"
47 #include "hwconfig.h"
48 #include "internal.h"
49 #include "packet_internal.h"
50 #include "refstruct.h"
51 #include "thread.h"
52 
53 typedef struct DecodeContext {
55 
56  /* to prevent infinite loop on errors when draining */
58 
59  /**
60  * The caller has submitted a NULL packet on input.
61  */
64 
66 {
67  return (DecodeContext *)avci;
68 }
69 
70 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
71 {
72  int ret;
73  size_t size;
74  const uint8_t *data;
75  uint32_t flags;
76  int64_t val;
77 
79  if (!data)
80  return 0;
81 
82  if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) {
83  av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
84  "changes, but PARAM_CHANGE side data was sent to it.\n");
85  ret = AVERROR(EINVAL);
86  goto fail2;
87  }
88 
89  if (size < 4)
90  goto fail;
91 
92  flags = bytestream_get_le32(&data);
93  size -= 4;
94 
95 #if FF_API_OLD_CHANNEL_LAYOUT
97  if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
98  if (size < 4)
99  goto fail;
100  val = bytestream_get_le32(&data);
101  if (val <= 0 || val > INT_MAX) {
102  av_log(avctx, AV_LOG_ERROR, "Invalid channel count");
104  goto fail2;
105  }
107  avctx->ch_layout.nb_channels = val;
109  size -= 4;
110  }
111  if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
112  if (size < 8)
113  goto fail;
115  ret = av_channel_layout_from_mask(&avctx->ch_layout, bytestream_get_le64(&data));
116  if (ret < 0)
117  goto fail2;
118  size -= 8;
119  }
120  if (flags & (AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT |
121  AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)) {
122  avctx->channels = avctx->ch_layout.nb_channels;
123  avctx->channel_layout = (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) ?
124  avctx->ch_layout.u.mask : 0;
125  }
127 #endif
129  if (size < 4)
130  goto fail;
131  val = bytestream_get_le32(&data);
132  if (val <= 0 || val > INT_MAX) {
133  av_log(avctx, AV_LOG_ERROR, "Invalid sample rate");
135  goto fail2;
136  }
137  avctx->sample_rate = val;
138  size -= 4;
139  }
141  if (size < 8)
142  goto fail;
143  avctx->width = bytestream_get_le32(&data);
144  avctx->height = bytestream_get_le32(&data);
145  size -= 8;
146  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
147  if (ret < 0)
148  goto fail2;
149  }
150 
151  return 0;
152 fail:
153  av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
155 fail2:
156  if (ret < 0) {
157  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
158  if (avctx->err_recognition & AV_EF_EXPLODE)
159  return ret;
160  }
161  return 0;
162 }
163 
165 {
166  int ret = 0;
167 
169  if (pkt) {
171 #if FF_API_FRAME_PKT
172  if (!ret)
173  avci->last_pkt_props->stream_index = pkt->size; // Needed for ff_decode_frame_props().
174 #endif
175  }
176  return ret;
177 }
178 
180 {
181  AVCodecInternal *avci = avctx->internal;
182  const FFCodec *const codec = ffcodec(avctx->codec);
183  int ret;
184 
185  if (avci->bsf)
186  return 0;
187 
188  ret = av_bsf_list_parse_str(codec->bsfs, &avci->bsf);
189  if (ret < 0) {
190  av_log(avctx, AV_LOG_ERROR, "Error parsing decoder bitstream filters '%s': %s\n", codec->bsfs, av_err2str(ret));
191  if (ret != AVERROR(ENOMEM))
192  ret = AVERROR_BUG;
193  goto fail;
194  }
195 
196  /* We do not currently have an API for passing the input timebase into decoders,
197  * but no filters used here should actually need it.
198  * So we make up some plausible-looking number (the MPEG 90kHz timebase) */
199  avci->bsf->time_base_in = (AVRational){ 1, 90000 };
201  if (ret < 0)
202  goto fail;
203 
204  ret = av_bsf_init(avci->bsf);
205  if (ret < 0)
206  goto fail;
207 
208  return 0;
209 fail:
210  av_bsf_free(&avci->bsf);
211  return ret;
212 }
213 
215 {
216  AVCodecInternal *avci = avctx->internal;
217  int ret;
218 
219  ret = av_bsf_receive_packet(avci->bsf, pkt);
220  if (ret == AVERROR_EOF)
221  avci->draining = 1;
222  if (ret < 0)
223  return ret;
224 
227  if (ret < 0)
228  goto finish;
229  }
230 
231  ret = apply_param_change(avctx, pkt);
232  if (ret < 0)
233  goto finish;
234 
235  return 0;
236 finish:
238  return ret;
239 }
240 
242 {
243  AVCodecInternal *avci = avctx->internal;
244  DecodeContext *dc = decode_ctx(avci);
245 
246  if (avci->draining)
247  return AVERROR_EOF;
248 
249  while (1) {
250  int ret = decode_get_packet(avctx, pkt);
251  if (ret == AVERROR(EAGAIN) &&
252  (!AVPACKET_IS_EMPTY(avci->buffer_pkt) || dc->draining_started)) {
253  ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
254  if (ret < 0) {
256  return ret;
257  }
258 
259  continue;
260  }
261 
262  return ret;
263  }
264 }
265 
266 /**
267  * Attempt to guess proper monotonic timestamps for decoded video frames
268  * which might have incorrect times. Input timestamps may wrap around, in
269  * which case the output will as well.
270  *
271  * @param pts the pts field of the decoded AVPacket, as passed through
272  * AVFrame.pts
273  * @param dts the dts field of the decoded AVPacket
274  * @return one of the input values, may be AV_NOPTS_VALUE
275  */
277  int64_t reordered_pts, int64_t dts)
278 {
279  int64_t pts = AV_NOPTS_VALUE;
280 
281  if (dts != AV_NOPTS_VALUE) {
282  ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts;
283  ctx->pts_correction_last_dts = dts;
284  } else if (reordered_pts != AV_NOPTS_VALUE)
285  ctx->pts_correction_last_dts = reordered_pts;
286 
287  if (reordered_pts != AV_NOPTS_VALUE) {
288  ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
289  ctx->pts_correction_last_pts = reordered_pts;
290  } else if(dts != AV_NOPTS_VALUE)
291  ctx->pts_correction_last_pts = dts;
292 
293  if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
294  && reordered_pts != AV_NOPTS_VALUE)
295  pts = reordered_pts;
296  else
297  pts = dts;
298 
299  return pts;
300 }
301 
302 static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
303 {
304  AVCodecInternal *avci = avctx->internal;
305  AVFrameSideData *side;
306  uint32_t discard_padding = 0;
307  uint8_t skip_reason = 0;
308  uint8_t discard_reason = 0;
309 
311  if (side && side->size >= 10) {
312  avci->skip_samples = AV_RL32(side->data);
313  avci->skip_samples = FFMAX(0, avci->skip_samples);
314  discard_padding = AV_RL32(side->data + 4);
315  av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
316  avci->skip_samples, (int)discard_padding);
317  skip_reason = AV_RL8(side->data + 8);
318  discard_reason = AV_RL8(side->data + 9);
319  }
320 
321  if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
322  if (!side && (avci->skip_samples || discard_padding))
324  if (side && (avci->skip_samples || discard_padding)) {
325  AV_WL32(side->data, avci->skip_samples);
326  AV_WL32(side->data + 4, discard_padding);
327  AV_WL8(side->data + 8, skip_reason);
328  AV_WL8(side->data + 9, discard_reason);
329  avci->skip_samples = 0;
330  }
331  return 0;
332  }
334 
335  if ((frame->flags & AV_FRAME_FLAG_DISCARD)) {
336  avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
337  *discarded_samples += frame->nb_samples;
338  return AVERROR(EAGAIN);
339  }
340 
341  if (avci->skip_samples > 0) {
342  if (frame->nb_samples <= avci->skip_samples){
343  *discarded_samples += frame->nb_samples;
344  avci->skip_samples -= frame->nb_samples;
345  av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
346  avci->skip_samples);
347  return AVERROR(EAGAIN);
348  } else {
349  av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
350  frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
351  if (avctx->pkt_timebase.num && avctx->sample_rate) {
352  int64_t diff_ts = av_rescale_q(avci->skip_samples,
353  (AVRational){1, avctx->sample_rate},
354  avctx->pkt_timebase);
355  if (frame->pts != AV_NOPTS_VALUE)
356  frame->pts += diff_ts;
357  if (frame->pkt_dts != AV_NOPTS_VALUE)
358  frame->pkt_dts += diff_ts;
359  if (frame->duration >= diff_ts)
360  frame->duration -= diff_ts;
361  } else
362  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
363 
364  av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
365  avci->skip_samples, frame->nb_samples);
366  *discarded_samples += avci->skip_samples;
367  frame->nb_samples -= avci->skip_samples;
368  avci->skip_samples = 0;
369  }
370  }
371 
372  if (discard_padding > 0 && discard_padding <= frame->nb_samples) {
373  if (discard_padding == frame->nb_samples) {
374  *discarded_samples += frame->nb_samples;
375  return AVERROR(EAGAIN);
376  } else {
377  if (avctx->pkt_timebase.num && avctx->sample_rate) {
378  int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
379  (AVRational){1, avctx->sample_rate},
380  avctx->pkt_timebase);
381  frame->duration = diff_ts;
382  } else
383  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
384 
385  av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
386  (int)discard_padding, frame->nb_samples);
387  frame->nb_samples -= discard_padding;
388  }
389  }
390 
391  return 0;
392 }
393 
394 /*
395  * The core of the receive_frame_wrapper for the decoders implementing
396  * the simple API. Certain decoders might consume partial packets without
397  * returning any output, so this function needs to be called in a loop until it
398  * returns EAGAIN.
399  **/
400 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
401 {
402  AVCodecInternal *avci = avctx->internal;
403  AVPacket *const pkt = avci->in_pkt;
404  const FFCodec *const codec = ffcodec(avctx->codec);
405  int got_frame, consumed;
406  int ret;
407 
408  if (!pkt->data && !avci->draining) {
410  ret = ff_decode_get_packet(avctx, pkt);
411  if (ret < 0 && ret != AVERROR_EOF)
412  return ret;
413  }
414 
415  // Some codecs (at least wma lossless) will crash when feeding drain packets
416  // after EOF was signaled.
417  if (avci->draining_done)
418  return AVERROR_EOF;
419 
420  if (!pkt->data &&
421  !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
423  return AVERROR_EOF;
424 
425  got_frame = 0;
426 
427  if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
428  consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
429  } else {
430  consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
431 
433  frame->pkt_dts = pkt->dts;
434  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
435 #if FF_API_FRAME_PKT
437  if(!avctx->has_b_frames)
438  frame->pkt_pos = pkt->pos;
440 #endif
441  }
442  }
443  emms_c();
444 
445  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
446  ret = (!got_frame || frame->flags & AV_FRAME_FLAG_DISCARD)
447  ? AVERROR(EAGAIN)
448  : 0;
449  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
450  ret = !got_frame ? AVERROR(EAGAIN)
451  : discard_samples(avctx, frame, discarded_samples);
452  }
453 
454  if (ret == AVERROR(EAGAIN))
456 
457  // FF_CODEC_CB_TYPE_DECODE decoders must not return AVERROR EAGAIN
458  // code later will add AVERROR(EAGAIN) to a pointer
459  av_assert0(consumed != AVERROR(EAGAIN));
460  if (consumed < 0)
461  ret = consumed;
462  if (consumed >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
463  consumed = pkt->size;
464 
465  if (!ret)
466  av_assert0(frame->buf[0]);
467  if (ret == AVERROR(EAGAIN))
468  ret = 0;
469 
470  /* do not stop draining when got_frame != 0 or ret < 0 */
471  if (avci->draining && !got_frame) {
472  if (ret < 0) {
473  /* prevent infinite loop if a decoder wrongly always return error on draining */
474  /* reasonable nb_errors_max = maximum b frames + thread count */
475  int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
476  avctx->thread_count : 1);
477 
478  if (decode_ctx(avci)->nb_draining_errors++ >= nb_errors_max) {
479  av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
480  "Stop draining and force EOF.\n");
481  avci->draining_done = 1;
482  ret = AVERROR_BUG;
483  }
484  } else {
485  avci->draining_done = 1;
486  }
487  }
488 
489  if (consumed >= pkt->size || ret < 0) {
491  } else {
492  pkt->data += consumed;
493  pkt->size -= consumed;
497 #if FF_API_FRAME_PKT
498  // See extract_packet_props() comment.
499  avci->last_pkt_props->stream_index = avci->last_pkt_props->stream_index - consumed;
500 #endif
503  }
504  }
505 
506  return ret;
507 }
508 
509 #if CONFIG_LCMS2
510 static int detect_colorspace(AVCodecContext *avctx, AVFrame *frame)
511 {
512  AVCodecInternal *avci = avctx->internal;
514  AVColorPrimariesDesc coeffs;
515  enum AVColorPrimaries prim;
516  cmsHPROFILE profile;
517  AVFrameSideData *sd;
518  int ret;
519  if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
520  return 0;
521 
523  if (!sd || !sd->size)
524  return 0;
525 
526  if (!avci->icc.avctx) {
527  ret = ff_icc_context_init(&avci->icc, avctx);
528  if (ret < 0)
529  return ret;
530  }
531 
532  profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size);
533  if (!profile)
534  return AVERROR_INVALIDDATA;
535 
536  ret = ff_icc_profile_sanitize(&avci->icc, profile);
537  if (!ret)
538  ret = ff_icc_profile_read_primaries(&avci->icc, profile, &coeffs);
539  if (!ret)
540  ret = ff_icc_profile_detect_transfer(&avci->icc, profile, &trc);
541  cmsCloseProfile(profile);
542  if (ret < 0)
543  return ret;
544 
545  prim = av_csp_primaries_id_from_desc(&coeffs);
546  if (prim != AVCOL_PRI_UNSPECIFIED)
547  frame->color_primaries = prim;
548  if (trc != AVCOL_TRC_UNSPECIFIED)
549  frame->color_trc = trc;
550  return 0;
551 }
552 #else /* !CONFIG_LCMS2 */
554 {
555  return 0;
556 }
557 #endif
558 
559 static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
560 {
561  int ret;
562 
563  if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
564  frame->color_primaries = avctx->color_primaries;
565  if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
566  frame->color_trc = avctx->color_trc;
567  if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
568  frame->colorspace = avctx->colorspace;
569  if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
570  frame->color_range = avctx->color_range;
571  if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
572  frame->chroma_location = avctx->chroma_sample_location;
573 
574  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
575  if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
576  if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
577  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
578  if (frame->format == AV_SAMPLE_FMT_NONE)
579  frame->format = avctx->sample_fmt;
580  if (!frame->ch_layout.nb_channels) {
581  ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
582  if (ret < 0)
583  return ret;
584  }
585 #if FF_API_OLD_CHANNEL_LAYOUT
587  if (!frame->channel_layout)
588  frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
589  avctx->ch_layout.u.mask : 0;
590  if (!frame->channels)
591  frame->channels = avctx->ch_layout.nb_channels;
593 #endif
594  if (!frame->sample_rate)
595  frame->sample_rate = avctx->sample_rate;
596  }
597 
598  return 0;
599 }
600 
602 {
603  int ret;
604  int64_t discarded_samples = 0;
605 
606  while (!frame->buf[0]) {
607  if (discarded_samples > avctx->max_samples)
608  return AVERROR(EAGAIN);
609  ret = decode_simple_internal(avctx, frame, &discarded_samples);
610  if (ret < 0)
611  return ret;
612  }
613 
614  return 0;
615 }
616 
618 {
619  AVCodecInternal *avci = avctx->internal;
620  const FFCodec *const codec = ffcodec(avctx->codec);
621  int ret, ok;
622 
623  av_assert0(!frame->buf[0]);
624 
625  if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
626  ret = codec->cb.receive_frame(avctx, frame);
627  emms_c();
628  if (!ret) {
629  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO)
630  ret = (frame->flags & AV_FRAME_FLAG_DISCARD) ? AVERROR(EAGAIN) : 0;
631  else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
632  int64_t discarded_samples = 0;
633  ret = discard_samples(avctx, frame, &discarded_samples);
634  }
635  }
636  } else
638 
639  if (ret == AVERROR_EOF)
640  avci->draining_done = 1;
641 
642  /* preserve ret */
643  ok = detect_colorspace(avctx, frame);
644  if (ok < 0) {
646  return ok;
647  }
648 
649  if (!ret) {
650  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
651  if (!frame->width)
652  frame->width = avctx->width;
653  if (!frame->height)
654  frame->height = avctx->height;
655  } else
656  frame->flags |= AV_FRAME_FLAG_KEY;
657 
658  ret = fill_frame_props(avctx, frame);
659  if (ret < 0) {
661  return ret;
662  }
663 
664 #if FF_API_FRAME_KEY
666  frame->key_frame = !!(frame->flags & AV_FRAME_FLAG_KEY);
668 #endif
669 #if FF_API_INTERLACED_FRAME
671  frame->interlaced_frame = !!(frame->flags & AV_FRAME_FLAG_INTERLACED);
672  frame->top_field_first = !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST);
674 #endif
675  frame->best_effort_timestamp = guess_correct_pts(avctx,
676  frame->pts,
677  frame->pkt_dts);
678 
679 #if FF_API_PKT_DURATION
681  frame->pkt_duration = frame->duration;
683 #endif
684 
685  /* the only case where decode data is not set should be decoders
686  * that do not call ff_get_buffer() */
687  av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) ||
688  !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
689 
690  if (frame->private_ref) {
691  FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
692 
693  if (fdd->post_process) {
694  ret = fdd->post_process(avctx, frame);
695  if (ret < 0) {
697  return ret;
698  }
699  }
700  }
701  }
702 
703  /* free the per-frame decode data */
704  av_buffer_unref(&frame->private_ref);
705 
706  return ret;
707 }
708 
710 {
711  AVCodecInternal *avci = avctx->internal;
712  DecodeContext *dc = decode_ctx(avci);
713  int ret;
714 
715  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
716  return AVERROR(EINVAL);
717 
718  if (dc->draining_started)
719  return AVERROR_EOF;
720 
721  if (avpkt && !avpkt->size && avpkt->data)
722  return AVERROR(EINVAL);
723 
724  if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
725  if (!AVPACKET_IS_EMPTY(avci->buffer_pkt))
726  return AVERROR(EAGAIN);
727  ret = av_packet_ref(avci->buffer_pkt, avpkt);
728  if (ret < 0)
729  return ret;
730  } else
731  dc->draining_started = 1;
732 
733  if (!avci->buffer_frame->buf[0] && !dc->draining_started) {
735  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
736  return ret;
737  }
738 
739  return 0;
740 }
741 
743 {
744  /* make sure we are noisy about decoders returning invalid cropping data */
745  if (frame->crop_left >= INT_MAX - frame->crop_right ||
746  frame->crop_top >= INT_MAX - frame->crop_bottom ||
747  (frame->crop_left + frame->crop_right) >= frame->width ||
748  (frame->crop_top + frame->crop_bottom) >= frame->height) {
749  av_log(avctx, AV_LOG_WARNING,
750  "Invalid cropping information set by a decoder: "
752  "(frame size %dx%d). This is a bug, please report it\n",
753  frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
754  frame->width, frame->height);
755  frame->crop_left = 0;
756  frame->crop_right = 0;
757  frame->crop_top = 0;
758  frame->crop_bottom = 0;
759  return 0;
760  }
761 
762  if (!avctx->apply_cropping)
763  return 0;
764 
767 }
768 
769 // make sure frames returned to the caller are valid
771 {
772  if (!frame->buf[0] || frame->format < 0)
773  goto fail;
774 
775  switch (avctx->codec_type) {
776  case AVMEDIA_TYPE_VIDEO:
777  if (frame->width <= 0 || frame->height <= 0)
778  goto fail;
779  break;
780  case AVMEDIA_TYPE_AUDIO:
781  if (!av_channel_layout_check(&frame->ch_layout) ||
782  frame->sample_rate <= 0)
783  goto fail;
784 
785  break;
786  default: av_assert0(0);
787  }
788 
789  return 0;
790 fail:
791  av_log(avctx, AV_LOG_ERROR, "An invalid frame was output by a decoder. "
792  "This is a bug, please report it.\n");
793  return AVERROR_BUG;
794 }
795 
797 {
798  AVCodecInternal *avci = avctx->internal;
799  int ret;
800 
801  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
802  return AVERROR(EINVAL);
803 
804  if (avci->buffer_frame->buf[0]) {
806  } else {
808  if (ret < 0)
809  return ret;
810  }
811 
812  ret = frame_validate(avctx, frame);
813  if (ret < 0)
814  goto fail;
815 
816  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
817  ret = apply_cropping(avctx, frame);
818  if (ret < 0)
819  goto fail;
820  }
821 
822  avctx->frame_num++;
823 #if FF_API_AVCTX_FRAME_NUMBER
825  avctx->frame_number = avctx->frame_num;
827 #endif
828 
829 #if FF_API_DROPCHANGED
830  if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) {
831 
832  if (avctx->frame_num == 1) {
833  avci->initial_format = frame->format;
834  switch(avctx->codec_type) {
835  case AVMEDIA_TYPE_VIDEO:
836  avci->initial_width = frame->width;
837  avci->initial_height = frame->height;
838  break;
839  case AVMEDIA_TYPE_AUDIO:
840  avci->initial_sample_rate = frame->sample_rate ? frame->sample_rate :
841  avctx->sample_rate;
842  ret = av_channel_layout_copy(&avci->initial_ch_layout, &frame->ch_layout);
843  if (ret < 0)
844  goto fail;
845  break;
846  }
847  }
848 
849  if (avctx->frame_num > 1) {
850  int changed = avci->initial_format != frame->format;
851 
852  switch(avctx->codec_type) {
853  case AVMEDIA_TYPE_VIDEO:
854  changed |= avci->initial_width != frame->width ||
855  avci->initial_height != frame->height;
856  break;
857  case AVMEDIA_TYPE_AUDIO:
858  changed |= avci->initial_sample_rate != frame->sample_rate ||
859  avci->initial_sample_rate != avctx->sample_rate ||
861  break;
862  }
863 
864  if (changed) {
865  avci->changed_frames_dropped++;
866  av_log(avctx, AV_LOG_INFO, "dropped changed frame #%"PRId64" pts %"PRId64
867  " drop count: %d \n",
868  avctx->frame_num, frame->pts,
869  avci->changed_frames_dropped);
871  goto fail;
872  }
873  }
874  }
875 #endif
876  return 0;
877 fail:
879  return ret;
880 }
881 
883 {
884  memset(sub, 0, sizeof(*sub));
885  sub->pts = AV_NOPTS_VALUE;
886 }
887 
888 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
889 static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt,
890  const AVPacket *inpkt, AVPacket *buf_pkt)
891 {
892 #if CONFIG_ICONV
893  iconv_t cd = (iconv_t)-1;
894  int ret = 0;
895  char *inb, *outb;
896  size_t inl, outl;
897 #endif
898 
899  if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) {
900  *outpkt = inpkt;
901  return 0;
902  }
903 
904 #if CONFIG_ICONV
905  inb = inpkt->data;
906  inl = inpkt->size;
907 
908  if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) {
909  av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
910  return AVERROR(ERANGE);
911  }
912 
913  cd = iconv_open("UTF-8", avctx->sub_charenc);
914  av_assert0(cd != (iconv_t)-1);
915 
916  ret = av_new_packet(buf_pkt, inl * UTF8_MAX_BYTES);
917  if (ret < 0)
918  goto end;
919  ret = av_packet_copy_props(buf_pkt, inpkt);
920  if (ret < 0)
921  goto end;
922  outb = buf_pkt->data;
923  outl = buf_pkt->size;
924 
925  if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
926  iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
927  outl >= buf_pkt->size || inl != 0) {
928  ret = FFMIN(AVERROR(errno), -1);
929  av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
930  "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
931  goto end;
932  }
933  buf_pkt->size -= outl;
934  memset(buf_pkt->data + buf_pkt->size, 0, outl);
935  *outpkt = buf_pkt;
936 
937  ret = 0;
938 end:
939  if (ret < 0)
940  av_packet_unref(buf_pkt);
941  if (cd != (iconv_t)-1)
942  iconv_close(cd);
943  return ret;
944 #else
945  av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
946  return AVERROR(EINVAL);
947 #endif
948 }
949 
950 static int utf8_check(const uint8_t *str)
951 {
952  const uint8_t *byte;
953  uint32_t codepoint, min;
954 
955  while (*str) {
956  byte = str;
957  GET_UTF8(codepoint, *(byte++), return 0;);
958  min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
959  1 << (5 * (byte - str) - 4);
960  if (codepoint < min || codepoint >= 0x110000 ||
961  codepoint == 0xFFFE /* BOM */ ||
962  codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
963  return 0;
964  str = byte;
965  }
966  return 1;
967 }
968 
970  int *got_sub_ptr, const AVPacket *avpkt)
971 {
972  int ret = 0;
973 
974  if (!avpkt->data && avpkt->size) {
975  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
976  return AVERROR(EINVAL);
977  }
978  if (!avctx->codec)
979  return AVERROR(EINVAL);
980  if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) {
981  av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n");
982  return AVERROR(EINVAL);
983  }
984 
985  *got_sub_ptr = 0;
987 
988  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
989  AVCodecInternal *avci = avctx->internal;
990  const AVPacket *pkt;
991 
992  ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
993  if (ret < 0)
994  return ret;
995 
996  if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
997  sub->pts = av_rescale_q(avpkt->pts,
998  avctx->pkt_timebase, AV_TIME_BASE_Q);
999  ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
1000  if (pkt == avci->buffer_pkt) // did we recode?
1001  av_packet_unref(avci->buffer_pkt);
1002  if (ret < 0) {
1003  *got_sub_ptr = 0;
1004  avsubtitle_free(sub);
1005  return ret;
1006  }
1007  av_assert1(!sub->num_rects || *got_sub_ptr);
1008 
1009  if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
1010  avctx->pkt_timebase.num) {
1011  AVRational ms = { 1, 1000 };
1012  sub->end_display_time = av_rescale_q(avpkt->duration,
1013  avctx->pkt_timebase, ms);
1014  }
1015 
1017  sub->format = 0;
1018  else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
1019  sub->format = 1;
1020 
1021  for (unsigned i = 0; i < sub->num_rects; i++) {
1023  sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
1024  av_log(avctx, AV_LOG_ERROR,
1025  "Invalid UTF-8 in decoded subtitles text; "
1026  "maybe missing -sub_charenc option\n");
1027  avsubtitle_free(sub);
1028  *got_sub_ptr = 0;
1029  return AVERROR_INVALIDDATA;
1030  }
1031  }
1032 
1033  if (*got_sub_ptr)
1034  avctx->frame_num++;
1035 #if FF_API_AVCTX_FRAME_NUMBER
1037  avctx->frame_number = avctx->frame_num;
1039 #endif
1040  }
1041 
1042  return ret;
1043 }
1044 
1046  const enum AVPixelFormat *fmt)
1047 {
1048  const AVPixFmtDescriptor *desc;
1049  const AVCodecHWConfig *config;
1050  int i, n;
1051 
1052  // If a device was supplied when the codec was opened, assume that the
1053  // user wants to use it.
1054  if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
1055  AVHWDeviceContext *device_ctx =
1057  for (i = 0;; i++) {
1058  config = &ffcodec(avctx->codec)->hw_configs[i]->public;
1059  if (!config)
1060  break;
1061  if (!(config->methods &
1063  continue;
1064  if (device_ctx->type != config->device_type)
1065  continue;
1066  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1067  if (config->pix_fmt == fmt[n])
1068  return fmt[n];
1069  }
1070  }
1071  }
1072  // No device or other setup, so we have to choose from things which
1073  // don't any other external information.
1074 
1075  // If the last element of the list is a software format, choose it
1076  // (this should be best software format if any exist).
1077  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1078  desc = av_pix_fmt_desc_get(fmt[n - 1]);
1079  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1080  return fmt[n - 1];
1081 
1082  // Finally, traverse the list in order and choose the first entry
1083  // with no external dependencies (if there is no hardware configuration
1084  // information available then this just picks the first entry).
1085  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1086  for (i = 0;; i++) {
1087  config = avcodec_get_hw_config(avctx->codec, i);
1088  if (!config)
1089  break;
1090  if (config->pix_fmt == fmt[n])
1091  break;
1092  }
1093  if (!config) {
1094  // No specific config available, so the decoder must be able
1095  // to handle this format without any additional setup.
1096  return fmt[n];
1097  }
1098  if (config->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
1099  // Usable with only internal setup.
1100  return fmt[n];
1101  }
1102  }
1103 
1104  // Nothing is usable, give up.
1105  return AV_PIX_FMT_NONE;
1106 }
1107 
1109  enum AVHWDeviceType dev_type)
1110 {
1111  AVHWDeviceContext *device_ctx;
1112  AVHWFramesContext *frames_ctx;
1113  int ret;
1114 
1115  if (!avctx->hwaccel)
1116  return AVERROR(ENOSYS);
1117 
1118  if (avctx->hw_frames_ctx)
1119  return 0;
1120  if (!avctx->hw_device_ctx) {
1121  av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
1122  "required for hardware accelerated decoding.\n");
1123  return AVERROR(EINVAL);
1124  }
1125 
1126  device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data;
1127  if (device_ctx->type != dev_type) {
1128  av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware "
1129  "decoding, but got %s.\n", av_hwdevice_get_type_name(dev_type),
1130  av_hwdevice_get_type_name(device_ctx->type));
1131  return AVERROR(EINVAL);
1132  }
1133 
1135  avctx->hw_device_ctx,
1136  avctx->hwaccel->pix_fmt,
1137  &avctx->hw_frames_ctx);
1138  if (ret < 0)
1139  return ret;
1140 
1141  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1142 
1143 
1144  if (frames_ctx->initial_pool_size) {
1145  // We guarantee 4 base work surfaces. The function above guarantees 1
1146  // (the absolute minimum), so add the missing count.
1147  frames_ctx->initial_pool_size += 3;
1148  }
1149 
1151  if (ret < 0) {
1152  av_buffer_unref(&avctx->hw_frames_ctx);
1153  return ret;
1154  }
1155 
1156  return 0;
1157 }
1158 
1160  AVBufferRef *device_ref,
1162  AVBufferRef **out_frames_ref)
1163 {
1164  AVBufferRef *frames_ref = NULL;
1165  const AVCodecHWConfigInternal *hw_config;
1166  const FFHWAccel *hwa;
1167  int i, ret;
1168 
1169  for (i = 0;; i++) {
1170  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1171  if (!hw_config)
1172  return AVERROR(ENOENT);
1173  if (hw_config->public.pix_fmt == hw_pix_fmt)
1174  break;
1175  }
1176 
1177  hwa = hw_config->hwaccel;
1178  if (!hwa || !hwa->frame_params)
1179  return AVERROR(ENOENT);
1180 
1181  frames_ref = av_hwframe_ctx_alloc(device_ref);
1182  if (!frames_ref)
1183  return AVERROR(ENOMEM);
1184 
1185  if (!avctx->internal->hwaccel_priv_data) {
1186  avctx->internal->hwaccel_priv_data =
1187  av_mallocz(hwa->priv_data_size);
1188  if (!avctx->internal->hwaccel_priv_data) {
1189  av_buffer_unref(&frames_ref);
1190  return AVERROR(ENOMEM);
1191  }
1192  }
1193 
1194  ret = hwa->frame_params(avctx, frames_ref);
1195  if (ret >= 0) {
1196  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
1197 
1198  if (frames_ctx->initial_pool_size) {
1199  // If the user has requested that extra output surfaces be
1200  // available then add them here.
1201  if (avctx->extra_hw_frames > 0)
1202  frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1203 
1204  // If frame threading is enabled then an extra surface per thread
1205  // is also required.
1206  if (avctx->active_thread_type & FF_THREAD_FRAME)
1207  frames_ctx->initial_pool_size += avctx->thread_count;
1208  }
1209 
1210  *out_frames_ref = frames_ref;
1211  } else {
1212  av_buffer_unref(&frames_ref);
1213  }
1214  return ret;
1215 }
1216 
1217 static int hwaccel_init(AVCodecContext *avctx,
1218  const FFHWAccel *hwaccel)
1219 {
1220  int err;
1221 
1224  av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1225  hwaccel->p.name);
1226  return AVERROR_PATCHWELCOME;
1227  }
1228 
1229  if (!avctx->internal->hwaccel_priv_data && hwaccel->priv_data_size) {
1230  avctx->internal->hwaccel_priv_data =
1231  av_mallocz(hwaccel->priv_data_size);
1232  if (!avctx->internal->hwaccel_priv_data)
1233  return AVERROR(ENOMEM);
1234  }
1235 
1236  avctx->hwaccel = &hwaccel->p;
1237  if (hwaccel->init) {
1238  err = hwaccel->init(avctx);
1239  if (err < 0) {
1240  av_log(avctx, AV_LOG_ERROR, "Failed setup for format %s: "
1241  "hwaccel initialisation returned error.\n",
1242  av_get_pix_fmt_name(hwaccel->p.pix_fmt));
1244  avctx->hwaccel = NULL;
1245  return err;
1246  }
1247  }
1248 
1249  return 0;
1250 }
1251 
1253 {
1254  if (FF_HW_HAS_CB(avctx, uninit))
1255  FF_HW_SIMPLE_CALL(avctx, uninit);
1256 
1258 
1259  avctx->hwaccel = NULL;
1260 
1261  av_buffer_unref(&avctx->hw_frames_ctx);
1262 }
1263 
1264 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1265 {
1266  const AVPixFmtDescriptor *desc;
1267  enum AVPixelFormat *choices;
1268  enum AVPixelFormat ret, user_choice;
1269  const AVCodecHWConfigInternal *hw_config;
1270  const AVCodecHWConfig *config;
1271  int i, n, err;
1272 
1273  // Find end of list.
1274  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1275  // Must contain at least one entry.
1276  av_assert0(n >= 1);
1277  // If a software format is available, it must be the last entry.
1278  desc = av_pix_fmt_desc_get(fmt[n - 1]);
1279  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1280  // No software format is available.
1281  } else {
1282  avctx->sw_pix_fmt = fmt[n - 1];
1283  }
1284 
1285  choices = av_memdup(fmt, (n + 1) * sizeof(*choices));
1286  if (!choices)
1287  return AV_PIX_FMT_NONE;
1288 
1289  for (;;) {
1290  // Remove the previous hwaccel, if there was one.
1291  ff_hwaccel_uninit(avctx);
1292 
1293  user_choice = avctx->get_format(avctx, choices);
1294  if (user_choice == AV_PIX_FMT_NONE) {
1295  // Explicitly chose nothing, give up.
1296  ret = AV_PIX_FMT_NONE;
1297  break;
1298  }
1299 
1300  desc = av_pix_fmt_desc_get(user_choice);
1301  if (!desc) {
1302  av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
1303  "get_format() callback.\n");
1304  ret = AV_PIX_FMT_NONE;
1305  break;
1306  }
1307  av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
1308  desc->name);
1309 
1310  for (i = 0; i < n; i++) {
1311  if (choices[i] == user_choice)
1312  break;
1313  }
1314  if (i == n) {
1315  av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
1316  "%s not in possible list.\n", desc->name);
1317  ret = AV_PIX_FMT_NONE;
1318  break;
1319  }
1320 
1321  if (ffcodec(avctx->codec)->hw_configs) {
1322  for (i = 0;; i++) {
1323  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1324  if (!hw_config)
1325  break;
1326  if (hw_config->public.pix_fmt == user_choice)
1327  break;
1328  }
1329  } else {
1330  hw_config = NULL;
1331  }
1332 
1333  if (!hw_config) {
1334  // No config available, so no extra setup required.
1335  ret = user_choice;
1336  break;
1337  }
1338  config = &hw_config->public;
1339 
1340  if (config->methods &
1342  avctx->hw_frames_ctx) {
1343  const AVHWFramesContext *frames_ctx =
1345  if (frames_ctx->format != user_choice) {
1346  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1347  "does not match the format of the provided frames "
1348  "context.\n", desc->name);
1349  goto try_again;
1350  }
1351  } else if (config->methods &
1353  avctx->hw_device_ctx) {
1354  const AVHWDeviceContext *device_ctx =
1356  if (device_ctx->type != config->device_type) {
1357  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1358  "does not match the type of the provided device "
1359  "context.\n", desc->name);
1360  goto try_again;
1361  }
1362  } else if (config->methods &
1364  // Internal-only setup, no additional configuration.
1365  } else if (config->methods &
1367  // Some ad-hoc configuration we can't see and can't check.
1368  } else {
1369  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1370  "missing configuration.\n", desc->name);
1371  goto try_again;
1372  }
1373  if (hw_config->hwaccel) {
1374  av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
1375  "initialisation.\n", desc->name);
1376  err = hwaccel_init(avctx, hw_config->hwaccel);
1377  if (err < 0)
1378  goto try_again;
1379  }
1380  ret = user_choice;
1381  break;
1382 
1383  try_again:
1384  av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
1385  "get_format() without it.\n", desc->name);
1386  for (i = 0; i < n; i++) {
1387  if (choices[i] == user_choice)
1388  break;
1389  }
1390  for (; i + 1 < n; i++)
1391  choices[i] = choices[i + 1];
1392  --n;
1393  }
1394 
1395  if (ret < 0)
1396  ff_hwaccel_uninit(avctx);
1397 
1398  av_freep(&choices);
1399  return ret;
1400 }
1401 
1404 {
1405  for (int i = 0; i < avctx->nb_coded_side_data; i++)
1406  if (avctx->coded_side_data[i].type == type)
1407  return &avctx->coded_side_data[i];
1408 
1409  return NULL;
1410 }
1411 
1413 {
1414  size_t size;
1415  const uint8_t *side_metadata;
1416 
1417  AVDictionary **frame_md = &frame->metadata;
1418 
1419  side_metadata = av_packet_get_side_data(avpkt,
1421  return av_packet_unpack_dictionary(side_metadata, size, frame_md);
1422 }
1423 
1424 static const struct {
1427 } sd_global_map[] = {
1437 };
1438 
1440  AVFrame *frame, const AVPacket *pkt)
1441 {
1442  static const struct {
1445  } sd[] = {
1450  };
1451 
1452  frame->pts = pkt->pts;
1453  frame->duration = pkt->duration;
1454 #if FF_API_FRAME_PKT
1456  frame->pkt_pos = pkt->pos;
1457  frame->pkt_size = pkt->size;
1459 #endif
1460 
1461  for (int i = 0; i < FF_ARRAY_ELEMS(sd_global_map); i++) {
1462  size_t size;
1463  const uint8_t *packet_sd = av_packet_get_side_data(pkt, sd_global_map[i].packet, &size);
1464  if (packet_sd) {
1465  AVFrameSideData *frame_sd;
1466 
1468  if (!frame_sd)
1469  return AVERROR(ENOMEM);
1470  memcpy(frame_sd->data, packet_sd, size);
1471  }
1472  }
1473  for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
1474  size_t size;
1475  uint8_t *packet_sd = av_packet_get_side_data(pkt, sd[i].packet, &size);
1476  if (packet_sd) {
1478  sd[i].frame,
1479  size);
1480  if (!frame_sd)
1481  return AVERROR(ENOMEM);
1482 
1483  memcpy(frame_sd->data, packet_sd, size);
1484  }
1485  }
1487 
1488  if (pkt->flags & AV_PKT_FLAG_DISCARD) {
1489  frame->flags |= AV_FRAME_FLAG_DISCARD;
1490  } else {
1491  frame->flags = (frame->flags & ~AV_FRAME_FLAG_DISCARD);
1492  }
1493 
1494  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
1495  int ret = av_buffer_replace(&frame->opaque_ref, pkt->opaque_ref);
1496  if (ret < 0)
1497  return ret;
1498  frame->opaque = pkt->opaque;
1499  }
1500 
1501  return 0;
1502 }
1503 
1505 {
1506  int ret;
1507 
1508  for (int i = 0; i < FF_ARRAY_ELEMS(sd_global_map); i++) {
1509  const AVPacketSideData *packet_sd = ff_get_coded_side_data(avctx,
1511  if (packet_sd) {
1514  packet_sd->size);
1515  if (!frame_sd)
1516  return AVERROR(ENOMEM);
1517 
1518  memcpy(frame_sd->data, packet_sd->data, packet_sd->size);
1519  }
1520  }
1521 
1523  const AVPacket *pkt = avctx->internal->last_pkt_props;
1524 
1526  if (ret < 0)
1527  return ret;
1528 #if FF_API_FRAME_PKT
1530  frame->pkt_size = pkt->stream_index;
1532 #endif
1533  }
1534 #if FF_API_REORDERED_OPAQUE
1536  frame->reordered_opaque = avctx->reordered_opaque;
1538 #endif
1539 
1540  ret = fill_frame_props(avctx, frame);
1541  if (ret < 0)
1542  return ret;
1543 
1544  switch (avctx->codec->type) {
1545  case AVMEDIA_TYPE_VIDEO:
1546  if (frame->width && frame->height &&
1547  av_image_check_sar(frame->width, frame->height,
1548  frame->sample_aspect_ratio) < 0) {
1549  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1550  frame->sample_aspect_ratio.num,
1551  frame->sample_aspect_ratio.den);
1552  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
1553  }
1554  break;
1555  }
1556  return 0;
1557 }
1558 
1560 {
1561  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1562  int i;
1563  int num_planes = av_pix_fmt_count_planes(frame->format);
1565  int flags = desc ? desc->flags : 0;
1566  if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL))
1567  num_planes = 2;
1568  for (i = 0; i < num_planes; i++) {
1569  av_assert0(frame->data[i]);
1570  }
1571  // For formats without data like hwaccel allow unused pointers to be non-NULL.
1572  for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) {
1573  if (frame->data[i])
1574  av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
1575  frame->data[i] = NULL;
1576  }
1577  }
1578 }
1579 
1580 static void decode_data_free(void *opaque, uint8_t *data)
1581 {
1583 
1584  if (fdd->post_process_opaque_free)
1586 
1587  if (fdd->hwaccel_priv_free)
1588  fdd->hwaccel_priv_free(fdd->hwaccel_priv);
1589 
1590  av_freep(&fdd);
1591 }
1592 
1594 {
1595  AVBufferRef *fdd_buf;
1596  FrameDecodeData *fdd;
1597 
1598  av_assert1(!frame->private_ref);
1599  av_buffer_unref(&frame->private_ref);
1600 
1601  fdd = av_mallocz(sizeof(*fdd));
1602  if (!fdd)
1603  return AVERROR(ENOMEM);
1604 
1605  fdd_buf = av_buffer_create((uint8_t*)fdd, sizeof(*fdd), decode_data_free,
1607  if (!fdd_buf) {
1608  av_freep(&fdd);
1609  return AVERROR(ENOMEM);
1610  }
1611 
1612  frame->private_ref = fdd_buf;
1613 
1614  return 0;
1615 }
1616 
1618 {
1619  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1620  int override_dimensions = 1;
1621  int ret;
1622 
1624 
1625  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1626  if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
1627  (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) {
1628  av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
1629  ret = AVERROR(EINVAL);
1630  goto fail;
1631  }
1632 
1633  if (frame->width <= 0 || frame->height <= 0) {
1634  frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
1635  frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
1636  override_dimensions = 0;
1637  }
1638 
1639  if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
1640  av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
1641  ret = AVERROR(EINVAL);
1642  goto fail;
1643  }
1644  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1645 #if FF_API_OLD_CHANNEL_LAYOUT
1647  /* compat layer for old-style get_buffer() implementations */
1648  avctx->channels = avctx->ch_layout.nb_channels;
1649  avctx->channel_layout = (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) ?
1650  avctx->ch_layout.u.mask : 0;
1652 #endif
1653 
1654  if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
1655  av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
1656  ret = AVERROR(EINVAL);
1657  goto fail;
1658  }
1659  }
1660  ret = ff_decode_frame_props(avctx, frame);
1661  if (ret < 0)
1662  goto fail;
1663 
1664  if (hwaccel) {
1665  if (hwaccel->alloc_frame) {
1666  ret = hwaccel->alloc_frame(avctx, frame);
1667  goto end;
1668  }
1669  } else
1670  avctx->sw_pix_fmt = avctx->pix_fmt;
1671 
1672  ret = avctx->get_buffer2(avctx, frame, flags);
1673  if (ret < 0)
1674  goto fail;
1675 
1677 
1679  if (ret < 0)
1680  goto fail;
1681 
1682 end:
1683  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
1685  frame->width = avctx->width;
1686  frame->height = avctx->height;
1687  }
1688 
1689 fail:
1690  if (ret < 0) {
1691  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1693  }
1694 
1695  return ret;
1696 }
1697 
1699 {
1700  AVFrame *tmp;
1701  int ret;
1702 
1704 
1705  if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1706  av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1707  frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1709  }
1710 
1711  if (!frame->data[0])
1712  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1713 
1715  return ff_decode_frame_props(avctx, frame);
1716 
1717  tmp = av_frame_alloc();
1718  if (!tmp)
1719  return AVERROR(ENOMEM);
1720 
1722 
1724  if (ret < 0) {
1725  av_frame_free(&tmp);
1726  return ret;
1727  }
1728 
1730  av_frame_free(&tmp);
1731 
1732  return 0;
1733 }
1734 
1736 {
1737  int ret = reget_buffer_internal(avctx, frame, flags);
1738  if (ret < 0)
1739  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1740  return ret;
1741 }
1742 
1744 {
1745  AVCodecInternal *avci = avctx->internal;
1746  int ret = 0;
1747 
1748  /* if the decoder init function was already called previously,
1749  * free the already allocated subtitle_header before overwriting it */
1750  av_freep(&avctx->subtitle_header);
1751 
1752  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1753  av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
1754  avctx->codec->max_lowres);
1755  avctx->lowres = avctx->codec->max_lowres;
1756  }
1757  if (avctx->sub_charenc) {
1758  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1759  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1760  "supported with subtitles codecs\n");
1761  return AVERROR(EINVAL);
1762  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1763  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1764  "subtitles character encoding will be ignored\n",
1765  avctx->codec_descriptor->name);
1767  } else {
1768  /* input character encoding is set for a text based subtitle
1769  * codec at this point */
1772 
1774 #if CONFIG_ICONV
1775  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1776  if (cd == (iconv_t)-1) {
1777  ret = AVERROR(errno);
1778  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1779  "with input character encoding \"%s\"\n", avctx->sub_charenc);
1780  return ret;
1781  }
1782  iconv_close(cd);
1783 #else
1784  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1785  "conversion needs a libavcodec built with iconv support "
1786  "for this codec\n");
1787  return AVERROR(ENOSYS);
1788 #endif
1789  }
1790  }
1791  }
1792 
1794  avctx->pts_correction_num_faulty_dts = 0;
1795  avctx->pts_correction_last_pts =
1796  avctx->pts_correction_last_dts = INT64_MIN;
1797 
1798  if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
1800  av_log(avctx, AV_LOG_WARNING,
1801  "gray decoding requested but not enabled at configuration time\n");
1802  if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
1804  }
1805 
1806  avci->in_pkt = av_packet_alloc();
1807  avci->last_pkt_props = av_packet_alloc();
1808  if (!avci->in_pkt || !avci->last_pkt_props)
1809  return AVERROR(ENOMEM);
1810 
1811  ret = decode_bsfs_init(avctx);
1812  if (ret < 0)
1813  return ret;
1814 
1815 #if FF_API_DROPCHANGED
1816  if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED)
1817  av_log(avctx, AV_LOG_WARNING, "The dropchanged flag is deprecated.\n");
1818 #endif
1819 
1820  return 0;
1821 }
1822 
1823 int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
1824 {
1825  size_t size;
1826  const void *pal = av_packet_get_side_data(src, AV_PKT_DATA_PALETTE, &size);
1827 
1828  if (pal && size == AVPALETTE_SIZE) {
1829  memcpy(dst, pal, AVPALETTE_SIZE);
1830  return 1;
1831  } else if (pal) {
1832  av_log(logctx, AV_LOG_ERROR,
1833  "Palette size %"SIZE_SPECIFIER" is wrong\n", size);
1834  }
1835  return 0;
1836 }
1837 
1838 int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
1839 {
1840  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1841 
1842  if (!hwaccel || !hwaccel->frame_priv_data_size)
1843  return 0;
1844 
1845  av_assert0(!*hwaccel_picture_private);
1846 
1847  if (hwaccel->free_frame_priv) {
1848  AVHWFramesContext *frames_ctx;
1849 
1850  if (!avctx->hw_frames_ctx)
1851  return AVERROR(EINVAL);
1852 
1853  frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data;
1854  *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,
1855  frames_ctx->device_ctx,
1856  hwaccel->free_frame_priv);
1857  } else {
1858  *hwaccel_picture_private = ff_refstruct_allocz(hwaccel->frame_priv_data_size);
1859  }
1860 
1861  if (!*hwaccel_picture_private)
1862  return AVERROR(ENOMEM);
1863 
1864  return 0;
1865 }
1866 
1868 {
1869  AVCodecInternal *avci = avctx->internal;
1870  DecodeContext *dc = decode_ctx(avci);
1871 
1873  av_packet_unref(avci->in_pkt);
1874 
1875  avctx->pts_correction_last_pts =
1876  avctx->pts_correction_last_dts = INT64_MIN;
1877 
1878  av_bsf_flush(avci->bsf);
1879 
1880  dc->nb_draining_errors = 0;
1881  dc->draining_started = 0;
1882 }
1883 
1885 {
1886  return av_mallocz(sizeof(DecodeContext));
1887 }
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:1402
AVSubtitle
Definition: avcodec.h:2269
AVCodecInternal::initial_sample_rate
int initial_sample_rate
Definition: internal.h:143
hwconfig.h
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_PKT_DATA_DISPLAYMATRIX
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:109
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:423
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1435
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:210
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:1217
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:241
hw_pix_fmt
static enum AVPixelFormat hw_pix_fmt
Definition: hw_decode.c:45
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
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:2274
AVCodecContext::get_format
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Callback to negotiate the pixel format.
Definition: avcodec.h:712
ff_icc_profile_read_primaries
int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile, AVColorPrimariesDesc *out_primaries)
Read the color primaries and white point coefficients encoded by an ICC profile, and return the raw v...
Definition: fflcms2.c:255
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:424
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1029
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:570
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1264
apply_cropping
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:742
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1064
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:824
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:812
AVColorPrimariesDesc
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition: csp.h:78
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:322
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2964
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:2169
AV_FRAME_DATA_A53_CC
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:59
AV_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:223
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:553
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:209
AVCodecInternal::skip_samples
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
Definition: internal.h:119
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1412
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:216
AVCodecContext::codec_descriptor
const struct AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:1824
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
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2273
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:601
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:100
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:334
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1022
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:342
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:491
AVHWAccel::capabilities
int capabilities
Hardware accelerated codec capabilities.
Definition: avcodec.h:2162
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:573
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:127
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:1776
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
Definition: packet.h:575
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
AV_FRAME_DATA_DISPLAYMATRIX
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:85
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:509
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:1852
AVDictionary
Definition: dict.c:34
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:312
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:545
avcodec_default_get_format
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Definition: decode.c:1045
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:708
AVChannelLayout::mask
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
Definition: channel_layout.h:339
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:317
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:590
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:65
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:1851
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:995
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:309
ff_hwaccel_uninit
void ff_hwaccel_uninit(AVCodecContext *avctx)
Definition: decode.c:1252
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:641
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
decode_get_packet
static int decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: decode.c:214
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:344
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3004
AV_PKT_DATA_REPLAYGAIN
@ AV_PKT_DATA_REPLAYGAIN
This side data should be associated with an audio stream and contains ReplayGain information in form ...
Definition: packet.h:100
DecodeContext::nb_draining_errors
int nb_draining_errors
Definition: decode.c:57
FFHWAccel::alloc_frame
int(* alloc_frame)(AVCodecContext *avctx, AVFrame *frame)
Allocate a custom buffer.
Definition: hwaccel_internal.h:43
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:295
finish
static void finish(void)
Definition: movenc.c:342
FFHWAccel
Definition: hwaccel_internal.h:34
bsf.h
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:450
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:527
STRIDE_ALIGN
#define STRIDE_ALIGN
Definition: internal.h:49
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2107
fail
#define fail()
Definition: checkasm.h:138
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:1532
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:1850
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:521
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:1439
AVChannelLayout::u
union AVChannelLayout::@332 u
Details about which channels are present in this layout.
pts
static int64_t pts
Definition: transcode_aac.c:643
add_metadata_from_side_data
static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
Definition: decode.c:1412
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:636
guess_correct_pts
static int64_t guess_correct_pts(AVCodecContext *ctx, 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:276
AVCodecContext::max_samples
int64_t max_samples
The number of samples per frame to maximally accept.
Definition: avcodec.h:2047
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFrameSideDataType
AVFrameSideDataType
Definition: frame.h:49
refstruct.h
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2264
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:413
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:61
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:88
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:1237
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:470
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:969
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:240
avassert.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1015
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:59
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:249
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVCodecContext::pts_correction_num_faulty_pts
int64_t pts_correction_num_faulty_pts
Current statistics for PTS correction.
Definition: avcodec.h:1831
ff_decode_receive_frame
int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
avcodec_receive_frame() implementation for decoders.
Definition: decode.c:796
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:628
FFHWAccel::frame_priv_data_size
int frame_priv_data_size
Size of per-frame hardware accelerator private data.
Definition: hwaccel_internal.h:106
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:744
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition: packet.h:576
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:1838
get_subtitle_defaults
static void get_subtitle_defaults(AVSubtitle *sub)
Definition: decode.c:882
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: avpacket.c:98
validate_avframe_allocation
static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:1559
AVCodecInternal::buffer_pkt
AVPacket * buffer_pkt
Temporary buffers for newly received or not yet output packets/frames.
Definition: internal.h:134
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:51
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:421
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
av_channel_layout_from_mask
FF_ENABLE_DEPRECATION_WARNINGS int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
Definition: channel_layout.c:399
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_FRAME_DATA_AUDIO_SERVICE_TYPE
@ AV_FRAME_DATA_AUDIO_SERVICE_TYPE
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
Definition: frame.h:114
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:343
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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_PKT_DATA_STEREO3D
@ AV_PKT_DATA_STEREO3D
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: packet.h:115
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:350
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2275
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:1959
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:93
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:516
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:548
AVCodecHWConfigInternal::hwaccel
const struct FFHWAccel * hwaccel
If this configuration uses a hwaccel, a pointer to it.
Definition: hwconfig.h:35
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:193
discard_samples
static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:302
decode_data_free
static void decode_data_free(void *opaque, uint8_t *data)
Definition: decode.c:1580
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:1108
DecodeContext::draining_started
int draining_started
The caller has submitted a NULL packet on input.
Definition: decode.c:62
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:140
AVCodecContext::sub_charenc
char * sub_charenc
DTS of the last frame.
Definition: avcodec.h:1841
ff_decode_internal_alloc
AVCodecInternal * ff_decode_internal_alloc(void)
Definition: decode.c:1884
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:384
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:950
AV_FRAME_DATA_SPHERICAL
@ AV_FRAME_DATA_SPHERICAL
The data represents the AVSphericalMapping structure defined in libavutil/spherical....
Definition: frame.h:131
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:1867
AVCodecContext::apply_cropping
int apply_cropping
Video decoding only.
Definition: avcodec.h:2017
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1039
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:476
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:345
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:142
FFCodec::cb
union FFCodec::@53 cb
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:394
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: avpacket.c:431
AVCodecInternal::draining_done
int draining_done
Definition: internal.h:136
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:888
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
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:236
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:639
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
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:1026
AVCodecInternal::last_pkt_props
AVPacket * last_pkt_props
Properties (timestamps+side data) extracted from the last packet passed for decoding.
Definition: internal.h:84
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_SPHERICAL
@ AV_PKT_DATA_SPHERICAL
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition: packet.h:229
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:1524
FFHWAccel::init
int(* init)(AVCodecContext *avctx)
Initialize the hwaccel private data.
Definition: hwaccel_internal.h:126
f
f
Definition: af_crystalizer.c:121
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:528
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1617
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_FRAME_DATA_REPLAYGAIN
@ AV_FRAME_DATA_REPLAYGAIN
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:77
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:318
AVPacket::size
int size
Definition: packet.h:492
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:504
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
Definition: avcodec.h:2031
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:124
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:899
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:78
AVCodecInternal::initial_format
int initial_format
Definition: internal.h:141
AVCodecInternal::bsf
struct AVBSFContext * bsf
Definition: internal.h:78
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1080
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:1817
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:770
AVFrameSideData::data
uint8_t * data
Definition: frame.h:248
ffcodec
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
Definition: codec_internal.h:325
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:666
fill_frame_props
static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:559
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:693
AVCodecHWConfigInternal
Definition: hwconfig.h:25
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2272
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: avpacket.c:343
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:919
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:490
AVCodecContext::pts_correction_num_faulty_dts
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition: avcodec.h:1832
AVCodecContext::pts_correction_last_pts
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition: avcodec.h:1833
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:118
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:497
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:63
AVCodecInternal
Definition: internal.h:52
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:261
detect_colorspace
static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f)
Definition: decode.c:553
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:942
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1543
AV_FRAME_DATA_SKIP_SAMPLES
@ AV_FRAME_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: frame.h:109
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2135
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:709
FFCodec::caps_internal
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
Definition: codec_internal.h:136
extract_packet_props
static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
Definition: decode.c:164
av_packet_copy_props
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
Definition: avpacket.c:386
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:2270
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:484
AVCodecInternal::initial_width
int initial_width
Definition: internal.h:142
reget_buffer_internal
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition: decode.c:1698
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: avpacket.c:252
decode_receive_frame_internal
static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:617
internal.h
sd_global_map
static const struct @59 sd_global_map[]
AV_PKT_DATA_ICC_PROFILE
@ AV_PKT_DATA_ICC_PROFILE
ICC profile data consisting of an opaque octet buffer following the format described by ISO 15076-1.
Definition: packet.h:275
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:77
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
packet
enum AVPacketSideDataType packet
Definition: decode.c:1425
AVCodecContext::pts_correction_last_dts
int64_t pts_correction_last_dts
PTS of the last frame.
Definition: avcodec.h:1834
ff_decode_preinit
int ff_decode_preinit(AVCodecContext *avctx)
Perform decoder initialization and validation.
Definition: decode.c:1743
AV_FRAME_DATA_STEREO3D
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
Definition: frame.h:64
DecodeContext::avci
AVCodecInternal avci
Definition: decode.c:54
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:649
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:622
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:254
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:1981
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:1046
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:2115
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:602
AVCodecContext::height
int height
Definition: avcodec.h:621
decode_simple_internal
static int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:400
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:658
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:636
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:1940
FFHWAccel::free_frame_priv
void(* free_frame_priv)(FFRefStructOpaque hwctx, void *data)
Callback to free the hwaccel-specific frame data.
Definition: hwaccel_internal.h:158
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:201
AVCodecContext::sub_charenc_mode
int sub_charenc_mode
Subtitles character encoding mode.
Definition: avcodec.h:1849
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:2118
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:1159
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:1735
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:79
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:149
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1371
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:916
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
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:141
apply_param_change
static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
Definition: decode.c:70
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:1504
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:441
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1551
recode_subtitle
static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt, const AVPacket *inpkt, AVPacket *buf_pkt)
Definition: decode.c:889
channel_layout.h
avcodec_internal.h
AV_CODEC_HW_CONFIG_METHOD_INTERNAL
@ AV_CODEC_HW_CONFIG_METHOD_INTERNAL
The codec supports this format by some internal method.
Definition: codec.h:329
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
ffhwaccel
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
Definition: hwaccel_internal.h:166
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:640
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:2057
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:41
FF_CODEC_CB_TYPE_RECEIVE_FRAME
@ FF_CODEC_CB_TYPE_RECEIVE_FRAME
Definition: codec_internal.h:115
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:143
AVPacket::stream_index
int stream_index
Definition: packet.h:493
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:859
AVCodecInternal::buffer_frame
AVFrame * buffer_frame
Definition: internal.h:135
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:647
AVCodecInternal::draining
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:129
frame
enum AVFrameSideDataType frame
Definition: decode.c:1426
FFCodec::bsfs
const char * bsfs
Decoding only, a comma-separated list of bitstream filters to apply to packets before decoding.
Definition: codec_internal.h:252
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:636
AV_PKT_DATA_AUDIO_SERVICE_TYPE
@ AV_PKT_DATA_AUDIO_SERVICE_TYPE
This side data should be associated with an audio stream and corresponds to enum AVAudioServiceType.
Definition: packet.h:121
AVHWFramesContext::initial_pool_size
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:199
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:449
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:632
desc
const char * desc
Definition: libsvtav1.c:83
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
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:338
AV_PKT_DATA_A53_CC
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: packet.h:243
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:402
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
ff_attach_decode_data
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1593
AVCodecInternal::initial_ch_layout
AVChannelLayout initial_ch_layout
Definition: internal.h:144
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:246
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:380
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:468
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:511
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
bytestream.h
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:51
imgutils.h
AVCodecContext::frame_number
attribute_deprecated int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1106
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:341
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:285
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1810
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:1823
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:179
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:2156
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:822
DecodeContext
Definition: decode.c:53
FF_REGET_BUFFER_FLAG_READONLY
#define FF_REGET_BUFFER_FLAG_READONLY
the returned buffer does not need to be writable
Definition: decode.h:128
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:503
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:2884
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:1853
min
float min
Definition: vorbis_enc_data.h:429