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"
31 #include "libavutil/avstring.h"
32 #include "libavutil/bprint.h"
34 #include "libavutil/common.h"
35 #include "libavutil/fifo.h"
36 #include "libavutil/frame.h"
37 #include "libavutil/hwcontext.h"
38 #include "libavutil/imgutils.h"
39 #include "libavutil/internal.h"
40 #include "libavutil/intmath.h"
41 #include "libavutil/opt.h"
42 
43 #include "avcodec.h"
44 #include "bytestream.h"
45 #include "bsf.h"
46 #include "codec_internal.h"
47 #include "decode.h"
48 #include "hwconfig.h"
49 #include "internal.h"
50 #include "thread.h"
51 
52 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
53 {
54  int ret;
55  size_t size;
56  const uint8_t *data;
57  uint32_t flags;
58  int64_t val;
59 
61  if (!data)
62  return 0;
63 
64  if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) {
65  av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
66  "changes, but PARAM_CHANGE side data was sent to it.\n");
67  ret = AVERROR(EINVAL);
68  goto fail2;
69  }
70 
71  if (size < 4)
72  goto fail;
73 
74  flags = bytestream_get_le32(&data);
75  size -= 4;
76 
77 #if FF_API_OLD_CHANNEL_LAYOUT
79  if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
80  if (size < 4)
81  goto fail;
82  val = bytestream_get_le32(&data);
83  if (val <= 0 || val > INT_MAX) {
84  av_log(avctx, AV_LOG_ERROR, "Invalid channel count");
86  goto fail2;
87  }
88  avctx->channels = val;
89  size -= 4;
90  }
91  if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
92  if (size < 8)
93  goto fail;
94  avctx->channel_layout = bytestream_get_le64(&data);
95  size -= 8;
96  }
98 #endif
100  if (size < 4)
101  goto fail;
102  val = bytestream_get_le32(&data);
103  if (val <= 0 || val > INT_MAX) {
104  av_log(avctx, AV_LOG_ERROR, "Invalid sample rate");
106  goto fail2;
107  }
108  avctx->sample_rate = val;
109  size -= 4;
110  }
112  if (size < 8)
113  goto fail;
114  avctx->width = bytestream_get_le32(&data);
115  avctx->height = bytestream_get_le32(&data);
116  size -= 8;
117  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
118  if (ret < 0)
119  goto fail2;
120  }
121 
122  return 0;
123 fail:
124  av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
126 fail2:
127  if (ret < 0) {
128  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
129  if (avctx->err_recognition & AV_EF_EXPLODE)
130  return ret;
131  }
132  return 0;
133 }
134 
136 {
137  int ret = 0;
138 
140  if (pkt) {
142 #if FF_API_FRAME_PKT
143  if (!ret)
144  avci->last_pkt_props->stream_index = pkt->size; // Needed for ff_decode_frame_props().
145 #endif
146  }
147  return ret;
148 }
149 
151 {
152  AVCodecInternal *avci = avctx->internal;
153  const FFCodec *const codec = ffcodec(avctx->codec);
154  int ret;
155 
156  if (avci->bsf)
157  return 0;
158 
159  ret = av_bsf_list_parse_str(codec->bsfs, &avci->bsf);
160  if (ret < 0) {
161  av_log(avctx, AV_LOG_ERROR, "Error parsing decoder bitstream filters '%s': %s\n", codec->bsfs, av_err2str(ret));
162  if (ret != AVERROR(ENOMEM))
163  ret = AVERROR_BUG;
164  goto fail;
165  }
166 
167  /* We do not currently have an API for passing the input timebase into decoders,
168  * but no filters used here should actually need it.
169  * So we make up some plausible-looking number (the MPEG 90kHz timebase) */
170  avci->bsf->time_base_in = (AVRational){ 1, 90000 };
172  if (ret < 0)
173  goto fail;
174 
175  ret = av_bsf_init(avci->bsf);
176  if (ret < 0)
177  goto fail;
178 
179  return 0;
180 fail:
181  av_bsf_free(&avci->bsf);
182  return ret;
183 }
184 
186 {
187  AVCodecInternal *avci = avctx->internal;
188  int ret;
189 
190  if (avci->draining)
191  return AVERROR_EOF;
192 
193  ret = av_bsf_receive_packet(avci->bsf, pkt);
194  if (ret == AVERROR_EOF)
195  avci->draining = 1;
196  if (ret < 0)
197  return ret;
198 
201  if (ret < 0)
202  goto finish;
203  }
204 
205  ret = apply_param_change(avctx, pkt);
206  if (ret < 0)
207  goto finish;
208 
209  return 0;
210 finish:
212  return ret;
213 }
214 
215 /**
216  * Attempt to guess proper monotonic timestamps for decoded video frames
217  * which might have incorrect times. Input timestamps may wrap around, in
218  * which case the output will as well.
219  *
220  * @param pts the pts field of the decoded AVPacket, as passed through
221  * AVFrame.pts
222  * @param dts the dts field of the decoded AVPacket
223  * @return one of the input values, may be AV_NOPTS_VALUE
224  */
226  int64_t reordered_pts, int64_t dts)
227 {
228  int64_t pts = AV_NOPTS_VALUE;
229 
230  if (dts != AV_NOPTS_VALUE) {
231  ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts;
232  ctx->pts_correction_last_dts = dts;
233  } else if (reordered_pts != AV_NOPTS_VALUE)
234  ctx->pts_correction_last_dts = reordered_pts;
235 
236  if (reordered_pts != AV_NOPTS_VALUE) {
237  ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
238  ctx->pts_correction_last_pts = reordered_pts;
239  } else if(dts != AV_NOPTS_VALUE)
240  ctx->pts_correction_last_pts = dts;
241 
242  if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
243  && reordered_pts != AV_NOPTS_VALUE)
244  pts = reordered_pts;
245  else
246  pts = dts;
247 
248  return pts;
249 }
250 
251 /*
252  * The core of the receive_frame_wrapper for the decoders implementing
253  * the simple API. Certain decoders might consume partial packets without
254  * returning any output, so this function needs to be called in a loop until it
255  * returns EAGAIN.
256  **/
257 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
258 {
259  AVCodecInternal *avci = avctx->internal;
260  AVPacket *const pkt = avci->in_pkt;
261  const FFCodec *const codec = ffcodec(avctx->codec);
262  int got_frame, actual_got_frame;
263  int ret;
264 
265  if (!pkt->data && !avci->draining) {
267  ret = ff_decode_get_packet(avctx, pkt);
268  if (ret < 0 && ret != AVERROR_EOF)
269  return ret;
270  }
271 
272  // Some codecs (at least wma lossless) will crash when feeding drain packets
273  // after EOF was signaled.
274  if (avci->draining_done)
275  return AVERROR_EOF;
276 
277  if (!pkt->data &&
278  !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
280  return AVERROR_EOF;
281 
282  got_frame = 0;
283 
284  if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
285  ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
286  } else {
287  ret = codec->cb.decode(avctx, frame, &got_frame, pkt);
288 
290  frame->pkt_dts = pkt->dts;
291  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
292 #if FF_API_FRAME_PKT
294  if(!avctx->has_b_frames)
295  frame->pkt_pos = pkt->pos;
297 #endif
298  //FIXME these should be under if(!avctx->has_b_frames)
299  /* get_buffer is supposed to set frame parameters */
300  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
301  if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
302  if (!frame->width) frame->width = avctx->width;
303  if (!frame->height) frame->height = avctx->height;
304  if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
305  }
306  }
307  }
308  emms_c();
309  actual_got_frame = got_frame;
310 
311  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
312  if (frame->flags & AV_FRAME_FLAG_DISCARD)
313  got_frame = 0;
314  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
315  uint8_t *side;
316  size_t side_size;
317  uint32_t discard_padding = 0;
318  uint8_t skip_reason = 0;
319  uint8_t discard_reason = 0;
320 
321  if (ret >= 0 && got_frame) {
322  if (frame->format == AV_SAMPLE_FMT_NONE)
323  frame->format = avctx->sample_fmt;
324  if (!frame->ch_layout.nb_channels) {
325  int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
326  if (ret2 < 0) {
327  ret = ret2;
328  got_frame = 0;
329  }
330  }
331 #if FF_API_OLD_CHANNEL_LAYOUT
333  if (!frame->channel_layout)
334  frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
335  avctx->ch_layout.u.mask : 0;
336  if (!frame->channels)
337  frame->channels = avctx->ch_layout.nb_channels;
339 #endif
340  if (!frame->sample_rate)
341  frame->sample_rate = avctx->sample_rate;
342  }
343 
345  if(side && side_size>=10) {
346  avci->skip_samples = AV_RL32(side);
347  avci->skip_samples = FFMAX(0, avci->skip_samples);
348  discard_padding = AV_RL32(side + 4);
349  av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
350  avci->skip_samples, (int)discard_padding);
351  skip_reason = AV_RL8(side + 8);
352  discard_reason = AV_RL8(side + 9);
353  }
354 
355  if ((frame->flags & AV_FRAME_FLAG_DISCARD) && got_frame &&
356  !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
357  avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
358  got_frame = 0;
359  *discarded_samples += frame->nb_samples;
360  }
361 
362  if (avci->skip_samples > 0 && got_frame &&
363  !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
364  if(frame->nb_samples <= avci->skip_samples){
365  got_frame = 0;
366  *discarded_samples += frame->nb_samples;
367  avci->skip_samples -= frame->nb_samples;
368  av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
369  avci->skip_samples);
370  } else {
371  av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
372  frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
373  if(avctx->pkt_timebase.num && avctx->sample_rate) {
374  int64_t diff_ts = av_rescale_q(avci->skip_samples,
375  (AVRational){1, avctx->sample_rate},
376  avctx->pkt_timebase);
377  if(frame->pts!=AV_NOPTS_VALUE)
378  frame->pts += diff_ts;
379  if(frame->pkt_dts!=AV_NOPTS_VALUE)
380  frame->pkt_dts += diff_ts;
381  if (frame->duration >= diff_ts)
382  frame->duration -= diff_ts;
383  } else {
384  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
385  }
386  av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
387  avci->skip_samples, frame->nb_samples);
388  *discarded_samples += avci->skip_samples;
389  frame->nb_samples -= avci->skip_samples;
390  avci->skip_samples = 0;
391  }
392  }
393 
394  if (discard_padding > 0 && discard_padding <= frame->nb_samples && got_frame &&
395  !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
396  if (discard_padding == frame->nb_samples) {
397  *discarded_samples += frame->nb_samples;
398  got_frame = 0;
399  } else {
400  if(avctx->pkt_timebase.num && avctx->sample_rate) {
401  int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
402  (AVRational){1, avctx->sample_rate},
403  avctx->pkt_timebase);
404  frame->duration = diff_ts;
405  } else {
406  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
407  }
408  av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
409  (int)discard_padding, frame->nb_samples);
410  frame->nb_samples -= discard_padding;
411  }
412  }
413 
414  if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL) && got_frame) {
416  if (fside) {
417  AV_WL32(fside->data, avci->skip_samples);
418  AV_WL32(fside->data + 4, discard_padding);
419  AV_WL8(fside->data + 8, skip_reason);
420  AV_WL8(fside->data + 9, discard_reason);
421  avci->skip_samples = 0;
422  }
423  }
424  }
425 
426  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO &&
428  ret >= 0 && ret != pkt->size && !(avctx->codec->capabilities & AV_CODEC_CAP_SUBFRAMES)) {
429  av_log(avctx, AV_LOG_WARNING, "Multiple frames in a packet.\n");
430  avci->showed_multi_packet_warning = 1;
431  }
432 
433  if (!got_frame)
435 
436  if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
437  ret = pkt->size;
438 
439  /* do not stop draining when actual_got_frame != 0 or ret < 0 */
440  /* got_frame == 0 but actual_got_frame != 0 when frame is discarded */
441  if (avci->draining && !actual_got_frame) {
442  if (ret < 0) {
443  /* prevent infinite loop if a decoder wrongly always return error on draining */
444  /* reasonable nb_errors_max = maximum b frames + thread count */
445  int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
446  avctx->thread_count : 1);
447 
448  if (avci->nb_draining_errors++ >= nb_errors_max) {
449  av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
450  "Stop draining and force EOF.\n");
451  avci->draining_done = 1;
452  ret = AVERROR_BUG;
453  }
454  } else {
455  avci->draining_done = 1;
456  }
457  }
458 
459  if (ret >= pkt->size || ret < 0) {
461  } else {
462  int consumed = ret;
463 
464  pkt->data += consumed;
465  pkt->size -= consumed;
469 #if FF_API_FRAME_PKT
470  // See extract_packet_props() comment.
471  avci->last_pkt_props->stream_index = avci->last_pkt_props->stream_index - consumed;
472 #endif
475  }
476  }
477 
478  if (got_frame)
479  av_assert0(frame->buf[0]);
480 
481  return ret < 0 ? ret : 0;
482 }
483 
484 #if CONFIG_LCMS2
485 static int detect_colorspace(AVCodecContext *avctx, AVFrame *frame)
486 {
487  AVCodecInternal *avci = avctx->internal;
489  AVColorPrimariesDesc coeffs;
490  enum AVColorPrimaries prim;
491  cmsHPROFILE profile;
492  AVFrameSideData *sd;
493  int ret;
494  if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
495  return 0;
496 
498  if (!sd || !sd->size)
499  return 0;
500 
501  if (!avci->icc.avctx) {
502  ret = ff_icc_context_init(&avci->icc, avctx);
503  if (ret < 0)
504  return ret;
505  }
506 
507  profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size);
508  if (!profile)
509  return AVERROR_INVALIDDATA;
510 
511  ret = ff_icc_profile_read_primaries(&avci->icc, profile, &coeffs);
512  if (!ret)
513  ret = ff_icc_profile_detect_transfer(&avci->icc, profile, &trc);
514  cmsCloseProfile(profile);
515  if (ret < 0)
516  return ret;
517 
518  prim = av_csp_primaries_id_from_desc(&coeffs);
519  if (prim != AVCOL_PRI_UNSPECIFIED)
520  frame->color_primaries = prim;
521  if (trc != AVCOL_TRC_UNSPECIFIED)
522  frame->color_trc = trc;
523  return 0;
524 }
525 #else /* !CONFIG_LCMS2 */
527 {
528  return 0;
529 }
530 #endif
531 
533 {
534  int ret;
535  int64_t discarded_samples = 0;
536 
537  while (!frame->buf[0]) {
538  if (discarded_samples > avctx->max_samples)
539  return AVERROR(EAGAIN);
540  ret = decode_simple_internal(avctx, frame, &discarded_samples);
541  if (ret < 0)
542  return ret;
543  }
544 
545  return 0;
546 }
547 
549 {
550  AVCodecInternal *avci = avctx->internal;
551  const FFCodec *const codec = ffcodec(avctx->codec);
552  int ret, ok;
553 
554  av_assert0(!frame->buf[0]);
555 
556  if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
557  ret = codec->cb.receive_frame(avctx, frame);
558  emms_c();
559  } else
561 
562  if (ret == AVERROR_EOF)
563  avci->draining_done = 1;
564 
565  /* preserve ret */
566  ok = detect_colorspace(avctx, frame);
567  if (ok < 0) {
569  return ok;
570  }
571 
572  if (!ret) {
573  frame->best_effort_timestamp = guess_correct_pts(avctx,
574  frame->pts,
575  frame->pkt_dts);
576 
577 #if FF_API_PKT_DURATION
579  frame->pkt_duration = frame->duration;
581 #endif
582 
583  /* the only case where decode data is not set should be decoders
584  * that do not call ff_get_buffer() */
585  av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) ||
586  !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
587 
588  if (frame->private_ref) {
589  FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
590 
591  if (fdd->post_process) {
592  ret = fdd->post_process(avctx, frame);
593  if (ret < 0) {
595  return ret;
596  }
597  }
598  }
599  }
600 
601  /* free the per-frame decode data */
602  av_buffer_unref(&frame->private_ref);
603 
604  return ret;
605 }
606 
607 int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
608 {
609  AVCodecInternal *avci = avctx->internal;
610  int ret;
611 
612  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
613  return AVERROR(EINVAL);
614 
615  if (avctx->internal->draining)
616  return AVERROR_EOF;
617 
618  if (avpkt && !avpkt->size && avpkt->data)
619  return AVERROR(EINVAL);
620 
622  if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
623  ret = av_packet_ref(avci->buffer_pkt, avpkt);
624  if (ret < 0)
625  return ret;
626  }
627 
628  ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
629  if (ret < 0) {
631  return ret;
632  }
633 
634  if (!avci->buffer_frame->buf[0]) {
636  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
637  return ret;
638  }
639 
640  return 0;
641 }
642 
644 {
645  /* make sure we are noisy about decoders returning invalid cropping data */
646  if (frame->crop_left >= INT_MAX - frame->crop_right ||
647  frame->crop_top >= INT_MAX - frame->crop_bottom ||
648  (frame->crop_left + frame->crop_right) >= frame->width ||
649  (frame->crop_top + frame->crop_bottom) >= frame->height) {
650  av_log(avctx, AV_LOG_WARNING,
651  "Invalid cropping information set by a decoder: "
653  "(frame size %dx%d). This is a bug, please report it\n",
654  frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
655  frame->width, frame->height);
656  frame->crop_left = 0;
657  frame->crop_right = 0;
658  frame->crop_top = 0;
659  frame->crop_bottom = 0;
660  return 0;
661  }
662 
663  if (!avctx->apply_cropping)
664  return 0;
665 
668 }
669 
670 // make sure frames returned to the caller are valid
672 {
673  if (!frame->buf[0] || frame->format < 0)
674  goto fail;
675 
676  switch (avctx->codec_type) {
677  case AVMEDIA_TYPE_VIDEO:
678  if (frame->width <= 0 || frame->height <= 0)
679  goto fail;
680  break;
681  case AVMEDIA_TYPE_AUDIO:
682  if (!av_channel_layout_check(&frame->ch_layout) ||
683  frame->sample_rate <= 0)
684  goto fail;
685 
686  break;
687  default: av_assert0(0);
688  }
689 
690  return 0;
691 fail:
692  av_log(avctx, AV_LOG_ERROR, "An invalid frame was output by a decoder. "
693  "This is a bug, please report it.\n");
694  return AVERROR_BUG;
695 }
696 
698 {
699  AVCodecInternal *avci = avctx->internal;
700  int ret, changed;
701 
702  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
703  return AVERROR(EINVAL);
704 
705  if (avci->buffer_frame->buf[0]) {
707  } else {
709  if (ret < 0)
710  return ret;
711  }
712 
713  ret = frame_validate(avctx, frame);
714  if (ret < 0)
715  goto fail;
716 
717  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
718  ret = apply_cropping(avctx, frame);
719  if (ret < 0)
720  goto fail;
721  }
722 
723  avctx->frame_num++;
724 #if FF_API_AVCTX_FRAME_NUMBER
726  avctx->frame_number = avctx->frame_num;
728 #endif
729 
730  if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) {
731 
732  if (avctx->frame_num == 1) {
733  avci->initial_format = frame->format;
734  switch(avctx->codec_type) {
735  case AVMEDIA_TYPE_VIDEO:
736  avci->initial_width = frame->width;
737  avci->initial_height = frame->height;
738  break;
739  case AVMEDIA_TYPE_AUDIO:
740  avci->initial_sample_rate = frame->sample_rate ? frame->sample_rate :
741  avctx->sample_rate;
742  ret = av_channel_layout_copy(&avci->initial_ch_layout, &frame->ch_layout);
743  if (ret < 0)
744  goto fail;
745  break;
746  }
747  }
748 
749  if (avctx->frame_num > 1) {
750  changed = avci->initial_format != frame->format;
751 
752  switch(avctx->codec_type) {
753  case AVMEDIA_TYPE_VIDEO:
754  changed |= avci->initial_width != frame->width ||
755  avci->initial_height != frame->height;
756  break;
757  case AVMEDIA_TYPE_AUDIO:
758  changed |= avci->initial_sample_rate != frame->sample_rate ||
759  avci->initial_sample_rate != avctx->sample_rate ||
761  break;
762  }
763 
764  if (changed) {
765  avci->changed_frames_dropped++;
766  av_log(avctx, AV_LOG_INFO, "dropped changed frame #%"PRId64" pts %"PRId64
767  " drop count: %d \n",
768  avctx->frame_num, frame->pts,
769  avci->changed_frames_dropped);
771  goto fail;
772  }
773  }
774  }
775  return 0;
776 fail:
778  return ret;
779 }
780 
782 {
783  memset(sub, 0, sizeof(*sub));
784  sub->pts = AV_NOPTS_VALUE;
785 }
786 
787 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
788 static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt,
789  const AVPacket *inpkt, AVPacket *buf_pkt)
790 {
791 #if CONFIG_ICONV
792  iconv_t cd = (iconv_t)-1;
793  int ret = 0;
794  char *inb, *outb;
795  size_t inl, outl;
796 #endif
797 
798  if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) {
799  *outpkt = inpkt;
800  return 0;
801  }
802 
803 #if CONFIG_ICONV
804  inb = inpkt->data;
805  inl = inpkt->size;
806 
807  if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) {
808  av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
809  return AVERROR(ERANGE);
810  }
811 
812  cd = iconv_open("UTF-8", avctx->sub_charenc);
813  av_assert0(cd != (iconv_t)-1);
814 
815  ret = av_new_packet(buf_pkt, inl * UTF8_MAX_BYTES);
816  if (ret < 0)
817  goto end;
818  ret = av_packet_copy_props(buf_pkt, inpkt);
819  if (ret < 0)
820  goto end;
821  outb = buf_pkt->data;
822  outl = buf_pkt->size;
823 
824  if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
825  iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
826  outl >= buf_pkt->size || inl != 0) {
827  ret = FFMIN(AVERROR(errno), -1);
828  av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
829  "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
830  goto end;
831  }
832  buf_pkt->size -= outl;
833  memset(buf_pkt->data + buf_pkt->size, 0, outl);
834  *outpkt = buf_pkt;
835 
836  ret = 0;
837 end:
838  if (ret < 0)
839  av_packet_unref(buf_pkt);
840  if (cd != (iconv_t)-1)
841  iconv_close(cd);
842  return ret;
843 #else
844  av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
845  return AVERROR(EINVAL);
846 #endif
847 }
848 
849 static int utf8_check(const uint8_t *str)
850 {
851  const uint8_t *byte;
852  uint32_t codepoint, min;
853 
854  while (*str) {
855  byte = str;
856  GET_UTF8(codepoint, *(byte++), return 0;);
857  min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
858  1 << (5 * (byte - str) - 4);
859  if (codepoint < min || codepoint >= 0x110000 ||
860  codepoint == 0xFFFE /* BOM */ ||
861  codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
862  return 0;
863  str = byte;
864  }
865  return 1;
866 }
867 
869  int *got_sub_ptr, const AVPacket *avpkt)
870 {
871  int ret = 0;
872 
873  if (!avpkt->data && avpkt->size) {
874  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
875  return AVERROR(EINVAL);
876  }
877  if (!avctx->codec)
878  return AVERROR(EINVAL);
879  if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) {
880  av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n");
881  return AVERROR(EINVAL);
882  }
883 
884  *got_sub_ptr = 0;
886 
887  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
888  AVCodecInternal *avci = avctx->internal;
889  const AVPacket *pkt;
890 
891  ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
892  if (ret < 0)
893  return ret;
894 
895  if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
896  sub->pts = av_rescale_q(avpkt->pts,
897  avctx->pkt_timebase, AV_TIME_BASE_Q);
898  ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
899  if (pkt == avci->buffer_pkt) // did we recode?
901  if (ret < 0) {
902  *got_sub_ptr = 0;
904  return ret;
905  }
906  av_assert1(!sub->num_rects || *got_sub_ptr);
907 
908  if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
909  avctx->pkt_timebase.num) {
910  AVRational ms = { 1, 1000 };
911  sub->end_display_time = av_rescale_q(avpkt->duration,
912  avctx->pkt_timebase, ms);
913  }
914 
916  sub->format = 0;
917  else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
918  sub->format = 1;
919 
920  for (unsigned i = 0; i < sub->num_rects; i++) {
922  sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
923  av_log(avctx, AV_LOG_ERROR,
924  "Invalid UTF-8 in decoded subtitles text; "
925  "maybe missing -sub_charenc option\n");
927  *got_sub_ptr = 0;
928  return AVERROR_INVALIDDATA;
929  }
930  }
931 
932  if (*got_sub_ptr)
933  avctx->frame_num++;
934 #if FF_API_AVCTX_FRAME_NUMBER
936  avctx->frame_number = avctx->frame_num;
938 #endif
939  }
940 
941  return ret;
942 }
943 
945  const enum AVPixelFormat *fmt)
946 {
947  const AVPixFmtDescriptor *desc;
948  const AVCodecHWConfig *config;
949  int i, n;
950 
951  // If a device was supplied when the codec was opened, assume that the
952  // user wants to use it.
953  if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
954  AVHWDeviceContext *device_ctx =
956  for (i = 0;; i++) {
957  config = &ffcodec(avctx->codec)->hw_configs[i]->public;
958  if (!config)
959  break;
960  if (!(config->methods &
962  continue;
963  if (device_ctx->type != config->device_type)
964  continue;
965  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
966  if (config->pix_fmt == fmt[n])
967  return fmt[n];
968  }
969  }
970  }
971  // No device or other setup, so we have to choose from things which
972  // don't any other external information.
973 
974  // If the last element of the list is a software format, choose it
975  // (this should be best software format if any exist).
976  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
977  desc = av_pix_fmt_desc_get(fmt[n - 1]);
978  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
979  return fmt[n - 1];
980 
981  // Finally, traverse the list in order and choose the first entry
982  // with no external dependencies (if there is no hardware configuration
983  // information available then this just picks the first entry).
984  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
985  for (i = 0;; i++) {
986  config = avcodec_get_hw_config(avctx->codec, i);
987  if (!config)
988  break;
989  if (config->pix_fmt == fmt[n])
990  break;
991  }
992  if (!config) {
993  // No specific config available, so the decoder must be able
994  // to handle this format without any additional setup.
995  return fmt[n];
996  }
998  // Usable with only internal setup.
999  return fmt[n];
1000  }
1001  }
1002 
1003  // Nothing is usable, give up.
1004  return AV_PIX_FMT_NONE;
1005 }
1006 
1008  enum AVHWDeviceType dev_type)
1009 {
1010  AVHWDeviceContext *device_ctx;
1011  AVHWFramesContext *frames_ctx;
1012  int ret;
1013 
1014  if (!avctx->hwaccel)
1015  return AVERROR(ENOSYS);
1016 
1017  if (avctx->hw_frames_ctx)
1018  return 0;
1019  if (!avctx->hw_device_ctx) {
1020  av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
1021  "required for hardware accelerated decoding.\n");
1022  return AVERROR(EINVAL);
1023  }
1024 
1025  device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data;
1026  if (device_ctx->type != dev_type) {
1027  av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware "
1028  "decoding, but got %s.\n", av_hwdevice_get_type_name(dev_type),
1029  av_hwdevice_get_type_name(device_ctx->type));
1030  return AVERROR(EINVAL);
1031  }
1032 
1034  avctx->hw_device_ctx,
1035  avctx->hwaccel->pix_fmt,
1036  &avctx->hw_frames_ctx);
1037  if (ret < 0)
1038  return ret;
1039 
1040  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1041 
1042 
1043  if (frames_ctx->initial_pool_size) {
1044  // We guarantee 4 base work surfaces. The function above guarantees 1
1045  // (the absolute minimum), so add the missing count.
1046  frames_ctx->initial_pool_size += 3;
1047  }
1048 
1050  if (ret < 0) {
1051  av_buffer_unref(&avctx->hw_frames_ctx);
1052  return ret;
1053  }
1054 
1055  return 0;
1056 }
1057 
1059  AVBufferRef *device_ref,
1061  AVBufferRef **out_frames_ref)
1062 {
1063  AVBufferRef *frames_ref = NULL;
1064  const AVCodecHWConfigInternal *hw_config;
1065  const AVHWAccel *hwa;
1066  int i, ret;
1067 
1068  for (i = 0;; i++) {
1069  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1070  if (!hw_config)
1071  return AVERROR(ENOENT);
1072  if (hw_config->public.pix_fmt == hw_pix_fmt)
1073  break;
1074  }
1075 
1076  hwa = hw_config->hwaccel;
1077  if (!hwa || !hwa->frame_params)
1078  return AVERROR(ENOENT);
1079 
1080  frames_ref = av_hwframe_ctx_alloc(device_ref);
1081  if (!frames_ref)
1082  return AVERROR(ENOMEM);
1083 
1084  ret = hwa->frame_params(avctx, frames_ref);
1085  if (ret >= 0) {
1086  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
1087 
1088  if (frames_ctx->initial_pool_size) {
1089  // If the user has requested that extra output surfaces be
1090  // available then add them here.
1091  if (avctx->extra_hw_frames > 0)
1092  frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1093 
1094  // If frame threading is enabled then an extra surface per thread
1095  // is also required.
1096  if (avctx->active_thread_type & FF_THREAD_FRAME)
1097  frames_ctx->initial_pool_size += avctx->thread_count;
1098  }
1099 
1100  *out_frames_ref = frames_ref;
1101  } else {
1102  av_buffer_unref(&frames_ref);
1103  }
1104  return ret;
1105 }
1106 
1107 static int hwaccel_init(AVCodecContext *avctx,
1108  const AVCodecHWConfigInternal *hw_config)
1109 {
1110  const AVHWAccel *hwaccel;
1111  int err;
1112 
1113  hwaccel = hw_config->hwaccel;
1116  av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1117  hwaccel->name);
1118  return AVERROR_PATCHWELCOME;
1119  }
1120 
1121  if (hwaccel->priv_data_size) {
1122  avctx->internal->hwaccel_priv_data =
1123  av_mallocz(hwaccel->priv_data_size);
1124  if (!avctx->internal->hwaccel_priv_data)
1125  return AVERROR(ENOMEM);
1126  }
1127 
1128  avctx->hwaccel = hwaccel;
1129  if (hwaccel->init) {
1130  err = hwaccel->init(avctx);
1131  if (err < 0) {
1132  av_log(avctx, AV_LOG_ERROR, "Failed setup for format %s: "
1133  "hwaccel initialisation returned error.\n",
1134  av_get_pix_fmt_name(hw_config->public.pix_fmt));
1136  avctx->hwaccel = NULL;
1137  return err;
1138  }
1139  }
1140 
1141  return 0;
1142 }
1143 
1144 static void hwaccel_uninit(AVCodecContext *avctx)
1145 {
1146  if (avctx->hwaccel && avctx->hwaccel->uninit)
1147  avctx->hwaccel->uninit(avctx);
1148 
1150 
1151  avctx->hwaccel = NULL;
1152 
1153  av_buffer_unref(&avctx->hw_frames_ctx);
1154 }
1155 
1156 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1157 {
1158  const AVPixFmtDescriptor *desc;
1159  enum AVPixelFormat *choices;
1160  enum AVPixelFormat ret, user_choice;
1161  const AVCodecHWConfigInternal *hw_config;
1162  const AVCodecHWConfig *config;
1163  int i, n, err;
1164 
1165  // Find end of list.
1166  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1167  // Must contain at least one entry.
1168  av_assert0(n >= 1);
1169  // If a software format is available, it must be the last entry.
1170  desc = av_pix_fmt_desc_get(fmt[n - 1]);
1171  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1172  // No software format is available.
1173  } else {
1174  avctx->sw_pix_fmt = fmt[n - 1];
1175  }
1176 
1177  choices = av_memdup(fmt, (n + 1) * sizeof(*choices));
1178  if (!choices)
1179  return AV_PIX_FMT_NONE;
1180 
1181  for (;;) {
1182  // Remove the previous hwaccel, if there was one.
1183  hwaccel_uninit(avctx);
1184 
1185  user_choice = avctx->get_format(avctx, choices);
1186  if (user_choice == AV_PIX_FMT_NONE) {
1187  // Explicitly chose nothing, give up.
1188  ret = AV_PIX_FMT_NONE;
1189  break;
1190  }
1191 
1192  desc = av_pix_fmt_desc_get(user_choice);
1193  if (!desc) {
1194  av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
1195  "get_format() callback.\n");
1196  ret = AV_PIX_FMT_NONE;
1197  break;
1198  }
1199  av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
1200  desc->name);
1201 
1202  for (i = 0; i < n; i++) {
1203  if (choices[i] == user_choice)
1204  break;
1205  }
1206  if (i == n) {
1207  av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
1208  "%s not in possible list.\n", desc->name);
1209  ret = AV_PIX_FMT_NONE;
1210  break;
1211  }
1212 
1213  if (ffcodec(avctx->codec)->hw_configs) {
1214  for (i = 0;; i++) {
1215  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1216  if (!hw_config)
1217  break;
1218  if (hw_config->public.pix_fmt == user_choice)
1219  break;
1220  }
1221  } else {
1222  hw_config = NULL;
1223  }
1224 
1225  if (!hw_config) {
1226  // No config available, so no extra setup required.
1227  ret = user_choice;
1228  break;
1229  }
1230  config = &hw_config->public;
1231 
1232  if (config->methods &
1234  avctx->hw_frames_ctx) {
1235  const AVHWFramesContext *frames_ctx =
1237  if (frames_ctx->format != user_choice) {
1238  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1239  "does not match the format of the provided frames "
1240  "context.\n", desc->name);
1241  goto try_again;
1242  }
1243  } else if (config->methods &
1245  avctx->hw_device_ctx) {
1246  const AVHWDeviceContext *device_ctx =
1248  if (device_ctx->type != config->device_type) {
1249  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1250  "does not match the type of the provided device "
1251  "context.\n", desc->name);
1252  goto try_again;
1253  }
1254  } else if (config->methods &
1256  // Internal-only setup, no additional configuration.
1257  } else if (config->methods &
1259  // Some ad-hoc configuration we can't see and can't check.
1260  } else {
1261  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1262  "missing configuration.\n", desc->name);
1263  goto try_again;
1264  }
1265  if (hw_config->hwaccel) {
1266  av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
1267  "initialisation.\n", desc->name);
1268  err = hwaccel_init(avctx, hw_config);
1269  if (err < 0)
1270  goto try_again;
1271  }
1272  ret = user_choice;
1273  break;
1274 
1275  try_again:
1276  av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
1277  "get_format() without it.\n", desc->name);
1278  for (i = 0; i < n; i++) {
1279  if (choices[i] == user_choice)
1280  break;
1281  }
1282  for (; i + 1 < n; i++)
1283  choices[i] = choices[i + 1];
1284  --n;
1285  }
1286 
1287  av_freep(&choices);
1288  return ret;
1289 }
1290 
1292 {
1293  size_t size;
1294  const uint8_t *side_metadata;
1295 
1296  AVDictionary **frame_md = &frame->metadata;
1297 
1298  side_metadata = av_packet_get_side_data(avpkt,
1300  return av_packet_unpack_dictionary(side_metadata, size, frame_md);
1301 }
1302 
1304  AVFrame *frame, const AVPacket *pkt)
1305 {
1306  static const struct {
1307  enum AVPacketSideDataType packet;
1309  } sd[] = {
1321  };
1322 
1323  frame->pts = pkt->pts;
1324  frame->duration = pkt->duration;
1325 #if FF_API_FRAME_PKT
1327  frame->pkt_pos = pkt->pos;
1328  frame->pkt_size = pkt->size;
1330 #endif
1331 
1332  for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
1333  size_t size;
1334  uint8_t *packet_sd = av_packet_get_side_data(pkt, sd[i].packet, &size);
1335  if (packet_sd) {
1337  sd[i].frame,
1338  size);
1339  if (!frame_sd)
1340  return AVERROR(ENOMEM);
1341 
1342  memcpy(frame_sd->data, packet_sd, size);
1343  }
1344  }
1346 
1347  if (pkt->flags & AV_PKT_FLAG_DISCARD) {
1348  frame->flags |= AV_FRAME_FLAG_DISCARD;
1349  } else {
1350  frame->flags = (frame->flags & ~AV_FRAME_FLAG_DISCARD);
1351  }
1352 
1353  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
1354  int ret = av_buffer_replace(&frame->opaque_ref, pkt->opaque_ref);
1355  if (ret < 0)
1356  return ret;
1357  frame->opaque = pkt->opaque;
1358  }
1359 
1360  return 0;
1361 }
1362 
1364 {
1365  const AVPacket *pkt = avctx->internal->last_pkt_props;
1366 
1369  if (ret < 0)
1370  return ret;
1371 #if FF_API_FRAME_PKT
1373  frame->pkt_size = pkt->stream_index;
1375 #endif
1376  }
1377 #if FF_API_REORDERED_OPAQUE
1379  frame->reordered_opaque = avctx->reordered_opaque;
1381 #endif
1382 
1383  if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
1384  frame->color_primaries = avctx->color_primaries;
1385  if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
1386  frame->color_trc = avctx->color_trc;
1387  if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
1388  frame->colorspace = avctx->colorspace;
1389  if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
1390  frame->color_range = avctx->color_range;
1391  if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
1392  frame->chroma_location = avctx->chroma_sample_location;
1393 
1394  switch (avctx->codec->type) {
1395  case AVMEDIA_TYPE_VIDEO:
1396  frame->format = avctx->pix_fmt;
1397  if (!frame->sample_aspect_ratio.num)
1398  frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
1399 
1400  if (frame->width && frame->height &&
1401  av_image_check_sar(frame->width, frame->height,
1402  frame->sample_aspect_ratio) < 0) {
1403  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1404  frame->sample_aspect_ratio.num,
1405  frame->sample_aspect_ratio.den);
1406  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
1407  }
1408 
1409  break;
1410  case AVMEDIA_TYPE_AUDIO:
1411  if (!frame->sample_rate)
1412  frame->sample_rate = avctx->sample_rate;
1413  if (frame->format < 0)
1414  frame->format = avctx->sample_fmt;
1415  if (!frame->ch_layout.nb_channels) {
1416  int ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
1417  if (ret < 0)
1418  return ret;
1419  }
1420 #if FF_API_OLD_CHANNEL_LAYOUT
1422  frame->channels = frame->ch_layout.nb_channels;
1423  frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
1424  frame->ch_layout.u.mask : 0;
1426 #endif
1427  break;
1428  }
1429  return 0;
1430 }
1431 
1433 {
1434  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1435  int i;
1436  int num_planes = av_pix_fmt_count_planes(frame->format);
1438  int flags = desc ? desc->flags : 0;
1439  if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL))
1440  num_planes = 2;
1441  for (i = 0; i < num_planes; i++) {
1442  av_assert0(frame->data[i]);
1443  }
1444  // For formats without data like hwaccel allow unused pointers to be non-NULL.
1445  for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) {
1446  if (frame->data[i])
1447  av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
1448  frame->data[i] = NULL;
1449  }
1450  }
1451 }
1452 
1453 static void decode_data_free(void *opaque, uint8_t *data)
1454 {
1456 
1457  if (fdd->post_process_opaque_free)
1459 
1460  if (fdd->hwaccel_priv_free)
1461  fdd->hwaccel_priv_free(fdd->hwaccel_priv);
1462 
1463  av_freep(&fdd);
1464 }
1465 
1467 {
1468  AVBufferRef *fdd_buf;
1469  FrameDecodeData *fdd;
1470 
1471  av_assert1(!frame->private_ref);
1472  av_buffer_unref(&frame->private_ref);
1473 
1474  fdd = av_mallocz(sizeof(*fdd));
1475  if (!fdd)
1476  return AVERROR(ENOMEM);
1477 
1478  fdd_buf = av_buffer_create((uint8_t*)fdd, sizeof(*fdd), decode_data_free,
1480  if (!fdd_buf) {
1481  av_freep(&fdd);
1482  return AVERROR(ENOMEM);
1483  }
1484 
1485  frame->private_ref = fdd_buf;
1486 
1487  return 0;
1488 }
1489 
1491 {
1492  const AVHWAccel *hwaccel = avctx->hwaccel;
1493  int override_dimensions = 1;
1494  int ret;
1495 
1497 
1498  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1499  if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
1500  (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) {
1501  av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
1502  ret = AVERROR(EINVAL);
1503  goto fail;
1504  }
1505 
1506  if (frame->width <= 0 || frame->height <= 0) {
1507  frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
1508  frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
1509  override_dimensions = 0;
1510  }
1511 
1512  if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
1513  av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
1514  ret = AVERROR(EINVAL);
1515  goto fail;
1516  }
1517  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1518 #if FF_API_OLD_CHANNEL_LAYOUT
1520  /* compat layer for old-style get_buffer() implementations */
1521  avctx->channels = avctx->ch_layout.nb_channels;
1522  avctx->channel_layout = (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) ?
1523  avctx->ch_layout.u.mask : 0;
1525 #endif
1526 
1527  if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
1528  av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
1529  ret = AVERROR(EINVAL);
1530  goto fail;
1531  }
1532  }
1533  ret = ff_decode_frame_props(avctx, frame);
1534  if (ret < 0)
1535  goto fail;
1536 
1537  if (hwaccel) {
1538  if (hwaccel->alloc_frame) {
1539  ret = hwaccel->alloc_frame(avctx, frame);
1540  goto end;
1541  }
1542  } else
1543  avctx->sw_pix_fmt = avctx->pix_fmt;
1544 
1545  ret = avctx->get_buffer2(avctx, frame, flags);
1546  if (ret < 0)
1547  goto fail;
1548 
1550 
1552  if (ret < 0)
1553  goto fail;
1554 
1555 end:
1556  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
1558  frame->width = avctx->width;
1559  frame->height = avctx->height;
1560  }
1561 
1562 fail:
1563  if (ret < 0) {
1564  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1566  }
1567 
1568  return ret;
1569 }
1570 
1572 {
1573  AVFrame *tmp;
1574  int ret;
1575 
1577 
1578  if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1579  av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1580  frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1582  }
1583 
1584  if (!frame->data[0])
1585  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1586 
1588  return ff_decode_frame_props(avctx, frame);
1589 
1590  tmp = av_frame_alloc();
1591  if (!tmp)
1592  return AVERROR(ENOMEM);
1593 
1595 
1597  if (ret < 0) {
1598  av_frame_free(&tmp);
1599  return ret;
1600  }
1601 
1603  av_frame_free(&tmp);
1604 
1605  return 0;
1606 }
1607 
1609 {
1610  int ret = reget_buffer_internal(avctx, frame, flags);
1611  if (ret < 0)
1612  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1613  return ret;
1614 }
1615 
1617 {
1618  AVCodecInternal *avci = avctx->internal;
1619  int ret = 0;
1620 
1621  /* if the decoder init function was already called previously,
1622  * free the already allocated subtitle_header before overwriting it */
1623  av_freep(&avctx->subtitle_header);
1624 
1625  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1626  av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
1627  avctx->codec->max_lowres);
1628  avctx->lowres = avctx->codec->max_lowres;
1629  }
1630  if (avctx->sub_charenc) {
1631  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1632  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1633  "supported with subtitles codecs\n");
1634  return AVERROR(EINVAL);
1635  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1636  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1637  "subtitles character encoding will be ignored\n",
1638  avctx->codec_descriptor->name);
1640  } else {
1641  /* input character encoding is set for a text based subtitle
1642  * codec at this point */
1645 
1647 #if CONFIG_ICONV
1648  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1649  if (cd == (iconv_t)-1) {
1650  ret = AVERROR(errno);
1651  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1652  "with input character encoding \"%s\"\n", avctx->sub_charenc);
1653  return ret;
1654  }
1655  iconv_close(cd);
1656 #else
1657  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1658  "conversion needs a libavcodec built with iconv support "
1659  "for this codec\n");
1660  return AVERROR(ENOSYS);
1661 #endif
1662  }
1663  }
1664  }
1665 
1667  avctx->pts_correction_num_faulty_dts = 0;
1668  avctx->pts_correction_last_pts =
1669  avctx->pts_correction_last_dts = INT64_MIN;
1670 
1671  if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
1673  av_log(avctx, AV_LOG_WARNING,
1674  "gray decoding requested but not enabled at configuration time\n");
1675  if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
1677  }
1678 
1679  avci->in_pkt = av_packet_alloc();
1680  avci->last_pkt_props = av_packet_alloc();
1681  if (!avci->in_pkt || !avci->last_pkt_props)
1682  return AVERROR(ENOMEM);
1683 
1684  ret = decode_bsfs_init(avctx);
1685  if (ret < 0)
1686  return ret;
1687 
1688  return 0;
1689 }
1690 
1691 int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
1692 {
1693  size_t size;
1694  const void *pal = av_packet_get_side_data(src, AV_PKT_DATA_PALETTE, &size);
1695 
1696  if (pal && size == AVPALETTE_SIZE) {
1697  memcpy(dst, pal, AVPALETTE_SIZE);
1698  return 1;
1699  } else if (pal) {
1700  av_log(logctx, AV_LOG_ERROR,
1701  "Palette size %"SIZE_SPECIFIER" is wrong\n", size);
1702  }
1703  return 0;
1704 }
AVSubtitle
Definition: avcodec.h:2351
AVCodecInternal::initial_sample_rate
int initial_sample_rate
Definition: internal.h:160
hwconfig.h
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:422
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1418
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:82
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
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:185
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
opt.h
AVCodecContext::get_format
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Callback to negotiate the pixel format.
Definition: avcodec.h:698
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:204
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1015
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:558
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1156
apply_cropping
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:643
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1047
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:686
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:674
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
AVColorPrimariesDesc
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition: csp.h:78
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2888
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:2251
AV_FRAME_DATA_A53_CC
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:59
AV_CODEC_HW_CONFIG_METHOD_INTERNAL
@ AV_CODEC_HW_CONFIG_METHOD_INTERNAL
The codec supports this format by some internal method.
Definition: codec.h:326
avcodec_parameters_from_context
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:99
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:436
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:132
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1395
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:212
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
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:399
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:532
AV_FRAME_DATA_S12M_TIMECODE
@ AV_FRAME_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1.
Definition: frame.h:152
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:101
FrameDecodeData
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition: decode.h:34
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:330
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1008
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:203
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:374
AVHWAccel::capabilities
int capabilities
Hardware accelerated codec capabilities.
Definition: avcodec.h:2130
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:561
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
data
const char data[16]
Definition: mxf.c:146
AVHWAccel::init
int(* init)(AVCodecContext *avctx)
Initialize the hwaccel private data.
Definition: avcodec.h:2215
FFCodec
Definition: codec_internal.h:127
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:1744
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
Definition: packet.h:458
FrameDecodeData::hwaccel_priv_free
void(* hwaccel_priv_free)(void *priv)
Definition: decode.h:53
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:392
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:1820
AVDictionary
Definition: dict.c:32
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:306
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:533
avcodec_default_get_format
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Definition: decode.c:944
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:704
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:333
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
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:550
AV_RL8
#define AV_RL8(x)
Definition: intreadwrite.h:398
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:91
av_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:53
FF_SUB_CHARENC_MODE_AUTOMATIC
#define FF_SUB_CHARENC_MODE_AUTOMATIC
libavcodec will select the mode itself
Definition: avcodec.h:1819
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:859
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
AVCodec::max_lowres
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: codec.h:204
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2928
AVHWAccel
Definition: avcodec.h:2097
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:287
fifo.h
finish
static void finish(void)
Definition: movenc.c:342
bsf.h
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:444
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:410
STRIDE_ALIGN
#define STRIDE_ALIGN
Definition: internal.h:49
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2075
fail
#define fail()
Definition: checkasm.h:135
AVCodecInternal::showed_multi_packet_warning
int showed_multi_packet_warning
Definition: internal.h:151
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:1515
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:1818
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:515
val
static double val(void *priv, double ch)
Definition: aeval.c:77
FrameDecodeData::post_process_opaque_free
void(* post_process_opaque_free)(void *opaque)
Definition: decode.h:47
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:1303
pts
static int64_t pts
Definition: transcode_aac.c:653
add_metadata_from_side_data
static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
Definition: decode.c:1291
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:622
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
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:225
AVCodecContext::max_samples
int64_t max_samples
The number of samples per frame to maximally accept.
Definition: avcodec.h:2015
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFrameSideDataType
AVFrameSideDataType
Definition: frame.h:49
AVHWAccel::priv_data_size
int priv_data_size
Size of the private data to allocate in AVCodecInternal.hwaccel_priv_data.
Definition: avcodec.h:2229
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:409
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:89
AV_PKT_DATA_STRINGS_METADATA
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
Definition: packet.h:173
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
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:1220
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:469
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:868
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:233
avassert.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1001
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:239
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:1799
ff_decode_receive_frame
int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
avcodec_receive_frame() implementation for decoders.
Definition: decode.c:697
hwaccel_uninit
static void hwaccel_uninit(AVCodecContext *avctx)
Definition: decode.c:1144
AVHWAccel::alloc_frame
int(* alloc_frame)(AVCodecContext *avctx, AVFrame *frame)
Allocate a custom buffer.
Definition: avcodec.h:2143
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
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:730
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition: packet.h:459
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:319
get_subtitle_defaults
static void get_subtitle_defaults(AVSubtitle *sub)
Definition: decode.c:781
FrameDecodeData::post_process_opaque
void * post_process_opaque
Definition: decode.h:46
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:97
validate_avframe_allocation
static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:1432
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
AVCodecInternal::buffer_pkt
AVPacket * buffer_pkt
Temporary buffers for newly received or not yet output packets/frames.
Definition: internal.h:147
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:50
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_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:223
AVHWAccel::uninit
int(* uninit)(AVCodecContext *avctx)
Uninitialize the hwaccel private data.
Definition: avcodec.h:2223
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:413
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
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:37
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
AVCodecDescriptor::type
enum AVMediaType type
Definition: codec_desc.h:40
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
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
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_DYNAMIC_HDR10_PLUS
@ AV_PKT_DATA_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
Definition: packet.h:300
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:347
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:1927
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:399
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:536
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
decode_data_free
static void decode_data_free(void *opaque, uint8_t *data)
Definition: decode.c:1453
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:1007
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:157
AVCodecContext::sub_charenc
char * sub_charenc
DTS of the last frame.
Definition: avcodec.h:1809
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:376
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:150
utf8_check
static int utf8_check(const uint8_t *str)
Definition: decode.c:849
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
AVCodecContext::apply_cropping
int apply_cropping
Video decoding only.
Definition: avcodec.h:1985
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1022
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:231
AVCodec::type
enum AVMediaType type
Definition: codec.h:197
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:470
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:97
AV_FRAME_DATA_ICC_PROFILE
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition: frame.h:144
AV_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:159
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:386
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:251
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:430
AVCodecInternal::draining_done
int draining_done
Definition: internal.h:149
UTF8_MAX_BYTES
#define UTF8_MAX_BYTES
Definition: decode.c:787
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:627
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVCodecInternal::last_pkt_props
AVPacket * last_pkt_props
Properties (timestamps+side data) extracted from the last packet passed for decoding.
Definition: internal.h:90
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
FFCodec::cb
union FFCodec::@50 cb
av_codec_is_decoder
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:83
AVCodecContext::lowres
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:1507
f
f
Definition: af_crystalizer.c:122
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:522
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1490
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:310
AVPacket::size
int size
Definition: packet.h:375
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:463
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:1999
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:45
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:137
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:763
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:203
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:158
AVCodecInternal::bsf
struct AVBSFContext * bsf
Definition: internal.h:84
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1063
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:1785
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:671
AVFrameSideData::data
uint8_t * data
Definition: frame.h:238
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:528
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:681
AVCodecHWConfigInternal
Definition: hwconfig.h:29
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:342
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:373
AVCodecContext::pts_correction_num_faulty_dts
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition: avcodec.h:1800
AVCodecContext::pts_correction_last_pts
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition: avcodec.h:1801
hwaccel_init
static int hwaccel_init(AVCodecContext *avctx, const AVCodecHWConfigInternal *hw_config)
Definition: decode.c:1107
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:41
AVChannelLayout::u
union AVChannelLayout::@315 u
Details about which channels are present in this layout.
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:236
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:380
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:62
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:526
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:932
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:1526
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:2103
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:607
av_samples_copy
int av_samples_copy(uint8_t **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
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:135
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:385
bprint.h
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: frame.h:137
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
AVCodecInternal::initial_width
int initial_width
Definition: internal.h:159
reget_buffer_internal
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition: decode.c:1571
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:251
decode_receive_frame_internal
static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:548
internal.h
common.h
AVCodecInternal::in_pkt
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
Definition: internal.h:83
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
AV_PKT_DATA_A53_CC
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: packet.h:243
AVCodecContext::pts_correction_last_dts
int64_t pts_correction_last_dts
PTS of the last frame.
Definition: avcodec.h:1802
ff_decode_preinit
int ff_decode_preinit(AVCodecContext *avctx)
Perform decoder initialization and validation.
Definition: decode.c:1616
AV_FRAME_DATA_STEREO3D
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
Definition: frame.h:64
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:511
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:484
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:1949
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
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: packet.h:157
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:1029
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:2111
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:590
AVCodecContext::height
int height
Definition: avcodec.h:607
decode_simple_internal
static int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:257
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:644
AVCodecInternal::nb_draining_errors
int nb_draining_errors
Definition: internal.h:154
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:1908
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:1817
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:2086
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:1058
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:1608
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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
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:335
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1354
AV_CODEC_PROP_TEXT_SUB
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: codec_desc.h:102
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:906
AV_PKT_DATA_S12M_TIMECODE
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
Definition: packet.h:292
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:150
apply_param_change
static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
Definition: decode.c:52
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:1363
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:435
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1534
AVCodecContext::codec_descriptor
const AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:1792
recode_subtitle
static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt, const AVPacket *inpkt, AVPacket *buf_pkt)
Definition: decode.c:788
channel_layout.h
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
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:2025
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
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:376
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:884
AVCodecInternal::buffer_frame
AVFrame * buffer_frame
Definition: internal.h:148
AV_CODEC_CAP_PARAM_CHANGE
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition: codec.h:115
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:639
AVCodecInternal::draining
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:142
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:81
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:622
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:443
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:588
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:527
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AV_CODEC_EXPORT_DATA_MVS
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:394
AV_CODEC_CAP_SUBFRAMES
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time,...
Definition: codec.h:94
ff_attach_decode_data
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1466
AVCodecInternal::initial_ch_layout
AVChannelLayout initial_ch_layout
Definition: internal.h:161
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:236
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:372
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:351
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:960
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVHWAccel::frame_params
int(* frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Fill the given hw_frames context with current codec parameters.
Definition: avcodec.h:2244
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:394
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:607
bytestream.h
convert_header.str
string str
Definition: convert_header.py:20
FrameDecodeData::hwaccel_priv
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:52
imgutils.h
AVCodecContext::frame_number
attribute_deprecated int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1089
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
hwcontext.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
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:306
AVCodecHWConfigInternal::hwaccel
const AVHWAccel * hwaccel
If this configuration uses a hwaccel, a pointer to it.
Definition: hwconfig.h:39
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:338
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1778
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
avstring.h
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:1691
AVCodecHWConfigInternal::public
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:34
decode_bsfs_init
static int decode_bsfs_init(AVCodecContext *avctx)
Definition: decode.c:150
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:2124
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:808
FF_REGET_BUFFER_FLAG_READONLY
#define FF_REGET_BUFFER_FLAG_READONLY
the returned buffer does not need to be writable
Definition: decode.h:140
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:386
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:2808
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:1821
min
float min
Definition: vorbis_enc_data.h:429
intmath.h