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 
135 #define IS_EMPTY(pkt) (!(pkt)->data)
136 
137 static int copy_packet_props(AVPacket *dst, const AVPacket *src)
138 {
139  int ret = av_packet_copy_props(dst, src);
140  if (ret < 0)
141  return ret;
142 
143  dst->size = src->size; // HACK: Needed for ff_decode_frame_props().
144  dst->data = (void*)1; // HACK: Needed for IS_EMPTY().
145 
146  return 0;
147 }
148 
150 {
151  AVPacket tmp = { 0 };
152  int ret = 0;
153 
154  if (IS_EMPTY(avci->last_pkt_props)) {
155  if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0)
156  return copy_packet_props(avci->last_pkt_props, pkt);
157  }
158 
160  if (ret < 0)
161  return ret;
162 
163  ret = av_fifo_write(avci->pkt_props, &tmp, 1);
164  if (ret < 0)
166 
167  return ret;
168 }
169 
171 {
172  AVCodecInternal *avci = avctx->internal;
173  const FFCodec *const codec = ffcodec(avctx->codec);
174  int ret;
175 
176  if (avci->bsf)
177  return 0;
178 
179  ret = av_bsf_list_parse_str(codec->bsfs, &avci->bsf);
180  if (ret < 0) {
181  av_log(avctx, AV_LOG_ERROR, "Error parsing decoder bitstream filters '%s': %s\n", codec->bsfs, av_err2str(ret));
182  if (ret != AVERROR(ENOMEM))
183  ret = AVERROR_BUG;
184  goto fail;
185  }
186 
187  /* We do not currently have an API for passing the input timebase into decoders,
188  * but no filters used here should actually need it.
189  * So we make up some plausible-looking number (the MPEG 90kHz timebase) */
190  avci->bsf->time_base_in = (AVRational){ 1, 90000 };
192  if (ret < 0)
193  goto fail;
194 
195  ret = av_bsf_init(avci->bsf);
196  if (ret < 0)
197  goto fail;
198 
199  return 0;
200 fail:
201  av_bsf_free(&avci->bsf);
202  return ret;
203 }
204 
206 {
207  AVCodecInternal *avci = avctx->internal;
208  int ret;
209 
210  if (avci->draining)
211  return AVERROR_EOF;
212 
213  ret = av_bsf_receive_packet(avci->bsf, pkt);
214  if (ret == AVERROR_EOF)
215  avci->draining = 1;
216  if (ret < 0)
217  return ret;
218 
221  if (ret < 0)
222  goto finish;
223  }
224 
225  ret = apply_param_change(avctx, pkt);
226  if (ret < 0)
227  goto finish;
228 
229  return 0;
230 finish:
232  return ret;
233 }
234 
235 /**
236  * Attempt to guess proper monotonic timestamps for decoded video frames
237  * which might have incorrect times. Input timestamps may wrap around, in
238  * which case the output will as well.
239  *
240  * @param pts the pts field of the decoded AVPacket, as passed through
241  * AVFrame.pts
242  * @param dts the dts field of the decoded AVPacket
243  * @return one of the input values, may be AV_NOPTS_VALUE
244  */
246  int64_t reordered_pts, int64_t dts)
247 {
248  int64_t pts = AV_NOPTS_VALUE;
249 
250  if (dts != AV_NOPTS_VALUE) {
251  ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts;
252  ctx->pts_correction_last_dts = dts;
253  } else if (reordered_pts != AV_NOPTS_VALUE)
254  ctx->pts_correction_last_dts = reordered_pts;
255 
256  if (reordered_pts != AV_NOPTS_VALUE) {
257  ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
258  ctx->pts_correction_last_pts = reordered_pts;
259  } else if(dts != AV_NOPTS_VALUE)
260  ctx->pts_correction_last_pts = dts;
261 
262  if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
263  && reordered_pts != AV_NOPTS_VALUE)
264  pts = reordered_pts;
265  else
266  pts = dts;
267 
268  return pts;
269 }
270 
271 /*
272  * The core of the receive_frame_wrapper for the decoders implementing
273  * the simple API. Certain decoders might consume partial packets without
274  * returning any output, so this function needs to be called in a loop until it
275  * returns EAGAIN.
276  **/
277 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
278 {
279  AVCodecInternal *avci = avctx->internal;
280  AVPacket *const pkt = avci->in_pkt;
281  const FFCodec *const codec = ffcodec(avctx->codec);
282  int got_frame, actual_got_frame;
283  int ret;
284 
285  if (!pkt->data && !avci->draining) {
287  ret = ff_decode_get_packet(avctx, pkt);
288  if (ret < 0 && ret != AVERROR_EOF)
289  return ret;
290  }
291 
292  // Some codecs (at least wma lossless) will crash when feeding drain packets
293  // after EOF was signaled.
294  if (avci->draining_done)
295  return AVERROR_EOF;
296 
297  if (!pkt->data &&
298  !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
300  return AVERROR_EOF;
301 
302  got_frame = 0;
303 
304  if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
305  ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
306  } else {
307  ret = codec->cb.decode(avctx, frame, &got_frame, pkt);
308 
310  frame->pkt_dts = pkt->dts;
311  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
312  if(!avctx->has_b_frames)
313  frame->pkt_pos = pkt->pos;
314  //FIXME these should be under if(!avctx->has_b_frames)
315  /* get_buffer is supposed to set frame parameters */
316  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
317  if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
318  if (!frame->width) frame->width = avctx->width;
319  if (!frame->height) frame->height = avctx->height;
320  if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
321  }
322  }
323  }
324  emms_c();
325  actual_got_frame = got_frame;
326 
327  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
328  if (frame->flags & AV_FRAME_FLAG_DISCARD)
329  got_frame = 0;
330  } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
331  uint8_t *side;
332  size_t side_size;
333  uint32_t discard_padding = 0;
334  uint8_t skip_reason = 0;
335  uint8_t discard_reason = 0;
336 
337  if (ret >= 0 && got_frame) {
338  if (frame->format == AV_SAMPLE_FMT_NONE)
339  frame->format = avctx->sample_fmt;
340  if (!frame->ch_layout.nb_channels) {
341  int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
342  if (ret2 < 0) {
343  ret = ret2;
344  got_frame = 0;
345  }
346  }
347 #if FF_API_OLD_CHANNEL_LAYOUT
349  if (!frame->channel_layout)
350  frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
351  avctx->ch_layout.u.mask : 0;
352  if (!frame->channels)
353  frame->channels = avctx->ch_layout.nb_channels;
355 #endif
356  if (!frame->sample_rate)
357  frame->sample_rate = avctx->sample_rate;
358  }
359 
361  if(side && side_size>=10) {
362  avci->skip_samples = AV_RL32(side);
363  avci->skip_samples = FFMAX(0, avci->skip_samples);
364  discard_padding = AV_RL32(side + 4);
365  av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
366  avci->skip_samples, (int)discard_padding);
367  skip_reason = AV_RL8(side + 8);
368  discard_reason = AV_RL8(side + 9);
369  }
370 
371  if ((frame->flags & AV_FRAME_FLAG_DISCARD) && got_frame &&
372  !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
373  avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
374  got_frame = 0;
375  *discarded_samples += frame->nb_samples;
376  }
377 
378  if (avci->skip_samples > 0 && got_frame &&
379  !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
380  if(frame->nb_samples <= avci->skip_samples){
381  got_frame = 0;
382  *discarded_samples += frame->nb_samples;
383  avci->skip_samples -= frame->nb_samples;
384  av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
385  avci->skip_samples);
386  } else {
387  av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
388  frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
389  if(avctx->pkt_timebase.num && avctx->sample_rate) {
390  int64_t diff_ts = av_rescale_q(avci->skip_samples,
391  (AVRational){1, avctx->sample_rate},
392  avctx->pkt_timebase);
393  if(frame->pts!=AV_NOPTS_VALUE)
394  frame->pts += diff_ts;
395  if(frame->pkt_dts!=AV_NOPTS_VALUE)
396  frame->pkt_dts += diff_ts;
397  if (frame->duration >= diff_ts)
398  frame->duration -= diff_ts;
399  } else {
400  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
401  }
402  av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
403  avci->skip_samples, frame->nb_samples);
404  *discarded_samples += avci->skip_samples;
405  frame->nb_samples -= avci->skip_samples;
406  avci->skip_samples = 0;
407  }
408  }
409 
410  if (discard_padding > 0 && discard_padding <= frame->nb_samples && got_frame &&
411  !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
412  if (discard_padding == frame->nb_samples) {
413  *discarded_samples += frame->nb_samples;
414  got_frame = 0;
415  } else {
416  if(avctx->pkt_timebase.num && avctx->sample_rate) {
417  int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
418  (AVRational){1, avctx->sample_rate},
419  avctx->pkt_timebase);
420  frame->duration = diff_ts;
421  } else {
422  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
423  }
424  av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
425  (int)discard_padding, frame->nb_samples);
426  frame->nb_samples -= discard_padding;
427  }
428  }
429 
430  if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL) && got_frame) {
432  if (fside) {
433  AV_WL32(fside->data, avci->skip_samples);
434  AV_WL32(fside->data + 4, discard_padding);
435  AV_WL8(fside->data + 8, skip_reason);
436  AV_WL8(fside->data + 9, discard_reason);
437  avci->skip_samples = 0;
438  }
439  }
440  }
441 
442  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO &&
444  ret >= 0 && ret != pkt->size && !(avctx->codec->capabilities & AV_CODEC_CAP_SUBFRAMES)) {
445  av_log(avctx, AV_LOG_WARNING, "Multiple frames in a packet.\n");
446  avci->showed_multi_packet_warning = 1;
447  }
448 
449  if (!got_frame)
451 
452 #if FF_API_FLAG_TRUNCATED
453  if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
454 #else
455  if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
456 #endif
457  ret = pkt->size;
458 
459 #if FF_API_AVCTX_TIMEBASE
460  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
461  avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
462 #endif
463 
464  /* do not stop draining when actual_got_frame != 0 or ret < 0 */
465  /* got_frame == 0 but actual_got_frame != 0 when frame is discarded */
466  if (avci->draining && !actual_got_frame) {
467  if (ret < 0) {
468  /* prevent infinite loop if a decoder wrongly always return error on draining */
469  /* reasonable nb_errors_max = maximum b frames + thread count */
470  int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
471  avctx->thread_count : 1);
472 
473  if (avci->nb_draining_errors++ >= nb_errors_max) {
474  av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
475  "Stop draining and force EOF.\n");
476  avci->draining_done = 1;
477  ret = AVERROR_BUG;
478  }
479  } else {
480  avci->draining_done = 1;
481  }
482  }
483 
484  if (ret >= pkt->size || ret < 0) {
487  } else {
488  int consumed = ret;
489 
490  pkt->data += consumed;
491  pkt->size -= consumed;
495  avci->last_pkt_props->size -= consumed; // See extract_packet_props() comment.
498  }
499  }
500 
501  if (got_frame)
502  av_assert0(frame->buf[0]);
503 
504  return ret < 0 ? ret : 0;
505 }
506 
507 #if CONFIG_LCMS2
508 static int detect_colorspace(AVCodecContext *avctx, AVFrame *frame)
509 {
510  AVCodecInternal *avci = avctx->internal;
512  AVColorPrimariesDesc coeffs;
513  enum AVColorPrimaries prim;
514  cmsHPROFILE profile;
515  AVFrameSideData *sd;
516  int ret;
517  if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
518  return 0;
519 
521  if (!sd || !sd->size)
522  return 0;
523 
524  if (!avci->icc.avctx) {
525  ret = ff_icc_context_init(&avci->icc, avctx);
526  if (ret < 0)
527  return ret;
528  }
529 
530  profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size);
531  if (!profile)
532  return AVERROR_INVALIDDATA;
533 
534  ret = ff_icc_profile_read_primaries(&avci->icc, profile, &coeffs);
535  if (!ret)
536  ret = ff_icc_profile_detect_transfer(&avci->icc, profile, &trc);
537  cmsCloseProfile(profile);
538  if (ret < 0)
539  return ret;
540 
541  prim = av_csp_primaries_id_from_desc(&coeffs);
542  if (prim != AVCOL_PRI_UNSPECIFIED)
543  frame->color_primaries = prim;
544  if (trc != AVCOL_TRC_UNSPECIFIED)
545  frame->color_trc = trc;
546  return 0;
547 }
548 #else /* !CONFIG_LCMS2 */
550 {
551  return 0;
552 }
553 #endif
554 
556 {
557  int ret;
558  int64_t discarded_samples = 0;
559 
560  while (!frame->buf[0]) {
561  if (discarded_samples > avctx->max_samples)
562  return AVERROR(EAGAIN);
563  ret = decode_simple_internal(avctx, frame, &discarded_samples);
564  if (ret < 0)
565  return ret;
566  }
567 
568  return 0;
569 }
570 
572 {
573  AVCodecInternal *avci = avctx->internal;
574  const FFCodec *const codec = ffcodec(avctx->codec);
575  int ret, ok;
576 
577  av_assert0(!frame->buf[0]);
578 
579  if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
580  ret = codec->cb.receive_frame(avctx, frame);
581  if (ret != AVERROR(EAGAIN))
583  } else
585 
586  if (ret == AVERROR_EOF)
587  avci->draining_done = 1;
588 
589  /* preserve ret */
590  ok = detect_colorspace(avctx, frame);
591  if (ok < 0) {
593  return ok;
594  }
595 
597  IS_EMPTY(avci->last_pkt_props)) {
598  // May fail if the FIFO is empty.
599  av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
600  }
601 
602  if (!ret) {
603  frame->best_effort_timestamp = guess_correct_pts(avctx,
604  frame->pts,
605  frame->pkt_dts);
606 
607 #if FF_API_PKT_DURATION
609  frame->pkt_duration = frame->duration;
611 #endif
612 
613  /* the only case where decode data is not set should be decoders
614  * that do not call ff_get_buffer() */
615  av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) ||
616  !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
617 
618  if (frame->private_ref) {
619  FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
620 
621  if (fdd->post_process) {
622  ret = fdd->post_process(avctx, frame);
623  if (ret < 0) {
625  return ret;
626  }
627  }
628  }
629  }
630 
631  /* free the per-frame decode data */
632  av_buffer_unref(&frame->private_ref);
633 
634  return ret;
635 }
636 
637 int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
638 {
639  AVCodecInternal *avci = avctx->internal;
640  int ret;
641 
642  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
643  return AVERROR(EINVAL);
644 
645  if (avctx->internal->draining)
646  return AVERROR_EOF;
647 
648  if (avpkt && !avpkt->size && avpkt->data)
649  return AVERROR(EINVAL);
650 
652  if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
653  ret = av_packet_ref(avci->buffer_pkt, avpkt);
654  if (ret < 0)
655  return ret;
656  }
657 
658  ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
659  if (ret < 0) {
661  return ret;
662  }
663 
664  if (!avci->buffer_frame->buf[0]) {
666  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
667  return ret;
668  }
669 
670  return 0;
671 }
672 
674 {
675  /* make sure we are noisy about decoders returning invalid cropping data */
676  if (frame->crop_left >= INT_MAX - frame->crop_right ||
677  frame->crop_top >= INT_MAX - frame->crop_bottom ||
678  (frame->crop_left + frame->crop_right) >= frame->width ||
679  (frame->crop_top + frame->crop_bottom) >= frame->height) {
680  av_log(avctx, AV_LOG_WARNING,
681  "Invalid cropping information set by a decoder: "
683  "(frame size %dx%d). This is a bug, please report it\n",
684  frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
685  frame->width, frame->height);
686  frame->crop_left = 0;
687  frame->crop_right = 0;
688  frame->crop_top = 0;
689  frame->crop_bottom = 0;
690  return 0;
691  }
692 
693  if (!avctx->apply_cropping)
694  return 0;
695 
698 }
699 
701 {
702  AVCodecInternal *avci = avctx->internal;
703  int ret, changed;
704 
705  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
706  return AVERROR(EINVAL);
707 
708  if (avci->buffer_frame->buf[0]) {
710  } else {
712  if (ret < 0)
713  return ret;
714  }
715 
716  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
717  ret = apply_cropping(avctx, frame);
718  if (ret < 0) {
720  return ret;
721  }
722  }
723 
724  avctx->frame_number++;
725 
726  if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) {
727 
728  if (avctx->frame_number == 1) {
729  avci->initial_format = frame->format;
730  switch(avctx->codec_type) {
731  case AVMEDIA_TYPE_VIDEO:
732  avci->initial_width = frame->width;
733  avci->initial_height = frame->height;
734  break;
735  case AVMEDIA_TYPE_AUDIO:
736  avci->initial_sample_rate = frame->sample_rate ? frame->sample_rate :
737  avctx->sample_rate;
738 #if FF_API_OLD_CHANNEL_LAYOUT
740  avci->initial_channels = frame->ch_layout.nb_channels;
741  avci->initial_channel_layout = frame->channel_layout;
743 #endif
744  ret = av_channel_layout_copy(&avci->initial_ch_layout, &frame->ch_layout);
745  if (ret < 0) {
747  return ret;
748  }
749  break;
750  }
751  }
752 
753  if (avctx->frame_number > 1) {
754  changed = avci->initial_format != frame->format;
755 
756  switch(avctx->codec_type) {
757  case AVMEDIA_TYPE_VIDEO:
758  changed |= avci->initial_width != frame->width ||
759  avci->initial_height != frame->height;
760  break;
761  case AVMEDIA_TYPE_AUDIO:
763  changed |= avci->initial_sample_rate != frame->sample_rate ||
764  avci->initial_sample_rate != avctx->sample_rate ||
765 #if FF_API_OLD_CHANNEL_LAYOUT
766  avci->initial_channels != frame->channels ||
767  avci->initial_channel_layout != frame->channel_layout ||
768 #endif
771  break;
772  }
773 
774  if (changed) {
775  avci->changed_frames_dropped++;
776  av_log(avctx, AV_LOG_INFO, "dropped changed frame #%d pts %"PRId64
777  " drop count: %d \n",
778  avctx->frame_number, frame->pts,
779  avci->changed_frames_dropped);
781  return AVERROR_INPUT_CHANGED;
782  }
783  }
784  }
785  return 0;
786 }
787 
789 {
790  memset(sub, 0, sizeof(*sub));
791  sub->pts = AV_NOPTS_VALUE;
792 }
793 
794 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
795 static int recode_subtitle(AVCodecContext *avctx, AVPacket **outpkt,
796  AVPacket *inpkt, AVPacket *buf_pkt)
797 {
798 #if CONFIG_ICONV
799  iconv_t cd = (iconv_t)-1;
800  int ret = 0;
801  char *inb, *outb;
802  size_t inl, outl;
803 #endif
804 
805  if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) {
806  *outpkt = inpkt;
807  return 0;
808  }
809 
810 #if CONFIG_ICONV
811  inb = inpkt->data;
812  inl = inpkt->size;
813 
814  if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) {
815  av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
816  return AVERROR(ERANGE);
817  }
818 
819  cd = iconv_open("UTF-8", avctx->sub_charenc);
820  av_assert0(cd != (iconv_t)-1);
821 
822  ret = av_new_packet(buf_pkt, inl * UTF8_MAX_BYTES);
823  if (ret < 0)
824  goto end;
825  ret = av_packet_copy_props(buf_pkt, inpkt);
826  if (ret < 0)
827  goto end;
828  outb = buf_pkt->data;
829  outl = buf_pkt->size;
830 
831  if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
832  iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
833  outl >= buf_pkt->size || inl != 0) {
834  ret = FFMIN(AVERROR(errno), -1);
835  av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
836  "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
837  goto end;
838  }
839  buf_pkt->size -= outl;
840  memset(buf_pkt->data + buf_pkt->size, 0, outl);
841  *outpkt = buf_pkt;
842 
843  ret = 0;
844 end:
845  if (ret < 0)
846  av_packet_unref(buf_pkt);
847  if (cd != (iconv_t)-1)
848  iconv_close(cd);
849  return ret;
850 #else
851  av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
852  return AVERROR(EINVAL);
853 #endif
854 }
855 
856 static int utf8_check(const uint8_t *str)
857 {
858  const uint8_t *byte;
859  uint32_t codepoint, min;
860 
861  while (*str) {
862  byte = str;
863  GET_UTF8(codepoint, *(byte++), return 0;);
864  min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
865  1 << (5 * (byte - str) - 4);
866  if (codepoint < min || codepoint >= 0x110000 ||
867  codepoint == 0xFFFE /* BOM */ ||
868  codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
869  return 0;
870  str = byte;
871  }
872  return 1;
873 }
874 
876  int *got_sub_ptr,
877  AVPacket *avpkt)
878 {
879  int ret = 0;
880 
881  if (!avpkt->data && avpkt->size) {
882  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
883  return AVERROR(EINVAL);
884  }
885  if (!avctx->codec)
886  return AVERROR(EINVAL);
887  if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) {
888  av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n");
889  return AVERROR(EINVAL);
890  }
891 
892  *got_sub_ptr = 0;
894 
895  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
896  AVCodecInternal *avci = avctx->internal;
897  AVPacket *pkt;
898 
899  ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
900  if (ret < 0)
901  return ret;
902 
903  if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
904  sub->pts = av_rescale_q(avpkt->pts,
905  avctx->pkt_timebase, AV_TIME_BASE_Q);
906  ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
907  if (pkt == avci->buffer_pkt) // did we recode?
909  if (ret < 0) {
910  *got_sub_ptr = 0;
912  return ret;
913  }
914  av_assert1(!sub->num_rects || *got_sub_ptr);
915 
916  if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
917  avctx->pkt_timebase.num) {
918  AVRational ms = { 1, 1000 };
919  sub->end_display_time = av_rescale_q(avpkt->duration,
920  avctx->pkt_timebase, ms);
921  }
922 
924  sub->format = 0;
925  else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
926  sub->format = 1;
927 
928  for (unsigned i = 0; i < sub->num_rects; i++) {
930  sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
931  av_log(avctx, AV_LOG_ERROR,
932  "Invalid UTF-8 in decoded subtitles text; "
933  "maybe missing -sub_charenc option\n");
935  *got_sub_ptr = 0;
936  return AVERROR_INVALIDDATA;
937  }
938  }
939 
940  if (*got_sub_ptr)
941  avctx->frame_number++;
942  }
943 
944  return ret;
945 }
946 
948  const enum AVPixelFormat *fmt)
949 {
950  const AVPixFmtDescriptor *desc;
951  const AVCodecHWConfig *config;
952  int i, n;
953 
954  // If a device was supplied when the codec was opened, assume that the
955  // user wants to use it.
956  if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
957  AVHWDeviceContext *device_ctx =
959  for (i = 0;; i++) {
960  config = &ffcodec(avctx->codec)->hw_configs[i]->public;
961  if (!config)
962  break;
963  if (!(config->methods &
965  continue;
966  if (device_ctx->type != config->device_type)
967  continue;
968  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
969  if (config->pix_fmt == fmt[n])
970  return fmt[n];
971  }
972  }
973  }
974  // No device or other setup, so we have to choose from things which
975  // don't any other external information.
976 
977  // If the last element of the list is a software format, choose it
978  // (this should be best software format if any exist).
979  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
980  desc = av_pix_fmt_desc_get(fmt[n - 1]);
981  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
982  return fmt[n - 1];
983 
984  // Finally, traverse the list in order and choose the first entry
985  // with no external dependencies (if there is no hardware configuration
986  // information available then this just picks the first entry).
987  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
988  for (i = 0;; i++) {
989  config = avcodec_get_hw_config(avctx->codec, i);
990  if (!config)
991  break;
992  if (config->pix_fmt == fmt[n])
993  break;
994  }
995  if (!config) {
996  // No specific config available, so the decoder must be able
997  // to handle this format without any additional setup.
998  return fmt[n];
999  }
1000  if (config->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
1001  // Usable with only internal setup.
1002  return fmt[n];
1003  }
1004  }
1005 
1006  // Nothing is usable, give up.
1007  return AV_PIX_FMT_NONE;
1008 }
1009 
1011  enum AVHWDeviceType dev_type)
1012 {
1013  AVHWDeviceContext *device_ctx;
1014  AVHWFramesContext *frames_ctx;
1015  int ret;
1016 
1017  if (!avctx->hwaccel)
1018  return AVERROR(ENOSYS);
1019 
1020  if (avctx->hw_frames_ctx)
1021  return 0;
1022  if (!avctx->hw_device_ctx) {
1023  av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
1024  "required for hardware accelerated decoding.\n");
1025  return AVERROR(EINVAL);
1026  }
1027 
1028  device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data;
1029  if (device_ctx->type != dev_type) {
1030  av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware "
1031  "decoding, but got %s.\n", av_hwdevice_get_type_name(dev_type),
1032  av_hwdevice_get_type_name(device_ctx->type));
1033  return AVERROR(EINVAL);
1034  }
1035 
1037  avctx->hw_device_ctx,
1038  avctx->hwaccel->pix_fmt,
1039  &avctx->hw_frames_ctx);
1040  if (ret < 0)
1041  return ret;
1042 
1043  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1044 
1045 
1046  if (frames_ctx->initial_pool_size) {
1047  // We guarantee 4 base work surfaces. The function above guarantees 1
1048  // (the absolute minimum), so add the missing count.
1049  frames_ctx->initial_pool_size += 3;
1050  }
1051 
1053  if (ret < 0) {
1054  av_buffer_unref(&avctx->hw_frames_ctx);
1055  return ret;
1056  }
1057 
1058  return 0;
1059 }
1060 
1062  AVBufferRef *device_ref,
1064  AVBufferRef **out_frames_ref)
1065 {
1066  AVBufferRef *frames_ref = NULL;
1067  const AVCodecHWConfigInternal *hw_config;
1068  const AVHWAccel *hwa;
1069  int i, ret;
1070 
1071  for (i = 0;; i++) {
1072  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1073  if (!hw_config)
1074  return AVERROR(ENOENT);
1075  if (hw_config->public.pix_fmt == hw_pix_fmt)
1076  break;
1077  }
1078 
1079  hwa = hw_config->hwaccel;
1080  if (!hwa || !hwa->frame_params)
1081  return AVERROR(ENOENT);
1082 
1083  frames_ref = av_hwframe_ctx_alloc(device_ref);
1084  if (!frames_ref)
1085  return AVERROR(ENOMEM);
1086 
1087  ret = hwa->frame_params(avctx, frames_ref);
1088  if (ret >= 0) {
1089  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
1090 
1091  if (frames_ctx->initial_pool_size) {
1092  // If the user has requested that extra output surfaces be
1093  // available then add them here.
1094  if (avctx->extra_hw_frames > 0)
1095  frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1096 
1097  // If frame threading is enabled then an extra surface per thread
1098  // is also required.
1099  if (avctx->active_thread_type & FF_THREAD_FRAME)
1100  frames_ctx->initial_pool_size += avctx->thread_count;
1101  }
1102 
1103  *out_frames_ref = frames_ref;
1104  } else {
1105  av_buffer_unref(&frames_ref);
1106  }
1107  return ret;
1108 }
1109 
1110 static int hwaccel_init(AVCodecContext *avctx,
1111  const AVCodecHWConfigInternal *hw_config)
1112 {
1113  const AVHWAccel *hwaccel;
1114  int err;
1115 
1116  hwaccel = hw_config->hwaccel;
1119  av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1120  hwaccel->name);
1121  return AVERROR_PATCHWELCOME;
1122  }
1123 
1124  if (hwaccel->priv_data_size) {
1125  avctx->internal->hwaccel_priv_data =
1126  av_mallocz(hwaccel->priv_data_size);
1127  if (!avctx->internal->hwaccel_priv_data)
1128  return AVERROR(ENOMEM);
1129  }
1130 
1131  avctx->hwaccel = hwaccel;
1132  if (hwaccel->init) {
1133  err = hwaccel->init(avctx);
1134  if (err < 0) {
1135  av_log(avctx, AV_LOG_ERROR, "Failed setup for format %s: "
1136  "hwaccel initialisation returned error.\n",
1137  av_get_pix_fmt_name(hw_config->public.pix_fmt));
1139  avctx->hwaccel = NULL;
1140  return err;
1141  }
1142  }
1143 
1144  return 0;
1145 }
1146 
1147 static void hwaccel_uninit(AVCodecContext *avctx)
1148 {
1149  if (avctx->hwaccel && avctx->hwaccel->uninit)
1150  avctx->hwaccel->uninit(avctx);
1151 
1153 
1154  avctx->hwaccel = NULL;
1155 
1156  av_buffer_unref(&avctx->hw_frames_ctx);
1157 }
1158 
1159 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1160 {
1161  const AVPixFmtDescriptor *desc;
1162  enum AVPixelFormat *choices;
1163  enum AVPixelFormat ret, user_choice;
1164  const AVCodecHWConfigInternal *hw_config;
1165  const AVCodecHWConfig *config;
1166  int i, n, err;
1167 
1168  // Find end of list.
1169  for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1170  // Must contain at least one entry.
1171  av_assert0(n >= 1);
1172  // If a software format is available, it must be the last entry.
1173  desc = av_pix_fmt_desc_get(fmt[n - 1]);
1174  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1175  // No software format is available.
1176  } else {
1177  avctx->sw_pix_fmt = fmt[n - 1];
1178  }
1179 
1180  choices = av_memdup(fmt, (n + 1) * sizeof(*choices));
1181  if (!choices)
1182  return AV_PIX_FMT_NONE;
1183 
1184  for (;;) {
1185  // Remove the previous hwaccel, if there was one.
1186  hwaccel_uninit(avctx);
1187 
1188  user_choice = avctx->get_format(avctx, choices);
1189  if (user_choice == AV_PIX_FMT_NONE) {
1190  // Explicitly chose nothing, give up.
1191  ret = AV_PIX_FMT_NONE;
1192  break;
1193  }
1194 
1195  desc = av_pix_fmt_desc_get(user_choice);
1196  if (!desc) {
1197  av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
1198  "get_format() callback.\n");
1199  ret = AV_PIX_FMT_NONE;
1200  break;
1201  }
1202  av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
1203  desc->name);
1204 
1205  for (i = 0; i < n; i++) {
1206  if (choices[i] == user_choice)
1207  break;
1208  }
1209  if (i == n) {
1210  av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
1211  "%s not in possible list.\n", desc->name);
1212  ret = AV_PIX_FMT_NONE;
1213  break;
1214  }
1215 
1216  if (ffcodec(avctx->codec)->hw_configs) {
1217  for (i = 0;; i++) {
1218  hw_config = ffcodec(avctx->codec)->hw_configs[i];
1219  if (!hw_config)
1220  break;
1221  if (hw_config->public.pix_fmt == user_choice)
1222  break;
1223  }
1224  } else {
1225  hw_config = NULL;
1226  }
1227 
1228  if (!hw_config) {
1229  // No config available, so no extra setup required.
1230  ret = user_choice;
1231  break;
1232  }
1233  config = &hw_config->public;
1234 
1235  if (config->methods &
1237  avctx->hw_frames_ctx) {
1238  const AVHWFramesContext *frames_ctx =
1240  if (frames_ctx->format != user_choice) {
1241  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1242  "does not match the format of the provided frames "
1243  "context.\n", desc->name);
1244  goto try_again;
1245  }
1246  } else if (config->methods &
1248  avctx->hw_device_ctx) {
1249  const AVHWDeviceContext *device_ctx =
1251  if (device_ctx->type != config->device_type) {
1252  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1253  "does not match the type of the provided device "
1254  "context.\n", desc->name);
1255  goto try_again;
1256  }
1257  } else if (config->methods &
1259  // Internal-only setup, no additional configuration.
1260  } else if (config->methods &
1262  // Some ad-hoc configuration we can't see and can't check.
1263  } else {
1264  av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1265  "missing configuration.\n", desc->name);
1266  goto try_again;
1267  }
1268  if (hw_config->hwaccel) {
1269  av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel "
1270  "initialisation.\n", desc->name);
1271  err = hwaccel_init(avctx, hw_config);
1272  if (err < 0)
1273  goto try_again;
1274  }
1275  ret = user_choice;
1276  break;
1277 
1278  try_again:
1279  av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
1280  "get_format() without it.\n", desc->name);
1281  for (i = 0; i < n; i++) {
1282  if (choices[i] == user_choice)
1283  break;
1284  }
1285  for (; i + 1 < n; i++)
1286  choices[i] = choices[i + 1];
1287  --n;
1288  }
1289 
1290  av_freep(&choices);
1291  return ret;
1292 }
1293 
1295 {
1296  size_t size;
1297  const uint8_t *side_metadata;
1298 
1299  AVDictionary **frame_md = &frame->metadata;
1300 
1301  side_metadata = av_packet_get_side_data(avpkt,
1303  return av_packet_unpack_dictionary(side_metadata, size, frame_md);
1304 }
1305 
1307 {
1308  AVPacket *pkt = avctx->internal->last_pkt_props;
1309  static const struct {
1310  enum AVPacketSideDataType packet;
1312  } sd[] = {
1324  };
1325 
1327  frame->pts = pkt->pts;
1328  frame->pkt_pos = pkt->pos;
1329  frame->duration = pkt->duration;
1330  frame->pkt_size = pkt->size;
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  frame->reordered_opaque = avctx->reordered_opaque;
1354 
1355  if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
1356  frame->color_primaries = avctx->color_primaries;
1357  if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
1358  frame->color_trc = avctx->color_trc;
1359  if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
1360  frame->colorspace = avctx->colorspace;
1361  if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
1362  frame->color_range = avctx->color_range;
1363  if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
1364  frame->chroma_location = avctx->chroma_sample_location;
1365 
1366  switch (avctx->codec->type) {
1367  case AVMEDIA_TYPE_VIDEO:
1368  frame->format = avctx->pix_fmt;
1369  if (!frame->sample_aspect_ratio.num)
1370  frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
1371 
1372  if (frame->width && frame->height &&
1373  av_image_check_sar(frame->width, frame->height,
1374  frame->sample_aspect_ratio) < 0) {
1375  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1376  frame->sample_aspect_ratio.num,
1377  frame->sample_aspect_ratio.den);
1378  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
1379  }
1380 
1381  break;
1382  case AVMEDIA_TYPE_AUDIO:
1383  if (!frame->sample_rate)
1384  frame->sample_rate = avctx->sample_rate;
1385  if (frame->format < 0)
1386  frame->format = avctx->sample_fmt;
1387  if (!frame->ch_layout.nb_channels) {
1388  int ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
1389  if (ret < 0)
1390  return ret;
1391  }
1392 #if FF_API_OLD_CHANNEL_LAYOUT
1394  frame->channels = frame->ch_layout.nb_channels;
1395  frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
1396  frame->ch_layout.u.mask : 0;
1398 #endif
1399  break;
1400  }
1401  return 0;
1402 }
1403 
1405 {
1406  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1407  int i;
1408  int num_planes = av_pix_fmt_count_planes(frame->format);
1410  int flags = desc ? desc->flags : 0;
1411  if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL))
1412  num_planes = 2;
1413  for (i = 0; i < num_planes; i++) {
1414  av_assert0(frame->data[i]);
1415  }
1416  // For formats without data like hwaccel allow unused pointers to be non-NULL.
1417  for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) {
1418  if (frame->data[i])
1419  av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
1420  frame->data[i] = NULL;
1421  }
1422  }
1423 }
1424 
1425 static void decode_data_free(void *opaque, uint8_t *data)
1426 {
1428 
1429  if (fdd->post_process_opaque_free)
1431 
1432  if (fdd->hwaccel_priv_free)
1433  fdd->hwaccel_priv_free(fdd->hwaccel_priv);
1434 
1435  av_freep(&fdd);
1436 }
1437 
1439 {
1440  AVBufferRef *fdd_buf;
1441  FrameDecodeData *fdd;
1442 
1443  av_assert1(!frame->private_ref);
1444  av_buffer_unref(&frame->private_ref);
1445 
1446  fdd = av_mallocz(sizeof(*fdd));
1447  if (!fdd)
1448  return AVERROR(ENOMEM);
1449 
1450  fdd_buf = av_buffer_create((uint8_t*)fdd, sizeof(*fdd), decode_data_free,
1452  if (!fdd_buf) {
1453  av_freep(&fdd);
1454  return AVERROR(ENOMEM);
1455  }
1456 
1457  frame->private_ref = fdd_buf;
1458 
1459  return 0;
1460 }
1461 
1463 {
1464  const AVHWAccel *hwaccel = avctx->hwaccel;
1465  int override_dimensions = 1;
1466  int ret;
1467 
1469 
1470  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1471  if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
1472  (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) {
1473  av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
1474  ret = AVERROR(EINVAL);
1475  goto fail;
1476  }
1477 
1478  if (frame->width <= 0 || frame->height <= 0) {
1479  frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
1480  frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
1481  override_dimensions = 0;
1482  }
1483 
1484  if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
1485  av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
1486  ret = AVERROR(EINVAL);
1487  goto fail;
1488  }
1489  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1490 #if FF_API_OLD_CHANNEL_LAYOUT
1492  /* compat layer for old-style get_buffer() implementations */
1493  avctx->channels = avctx->ch_layout.nb_channels;
1494  avctx->channel_layout = (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) ?
1495  avctx->ch_layout.u.mask : 0;
1497 #endif
1498 
1499  if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
1500  av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
1501  ret = AVERROR(EINVAL);
1502  goto fail;
1503  }
1504  }
1505  ret = ff_decode_frame_props(avctx, frame);
1506  if (ret < 0)
1507  goto fail;
1508 
1509  if (hwaccel) {
1510  if (hwaccel->alloc_frame) {
1511  ret = hwaccel->alloc_frame(avctx, frame);
1512  goto end;
1513  }
1514  } else
1515  avctx->sw_pix_fmt = avctx->pix_fmt;
1516 
1517  ret = avctx->get_buffer2(avctx, frame, flags);
1518  if (ret < 0)
1519  goto fail;
1520 
1522 
1524  if (ret < 0)
1525  goto fail;
1526 
1527 end:
1528  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
1530  frame->width = avctx->width;
1531  frame->height = avctx->height;
1532  }
1533 
1534 fail:
1535  if (ret < 0) {
1536  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1538  }
1539 
1540  return ret;
1541 }
1542 
1544 {
1545  AVFrame *tmp;
1546  int ret;
1547 
1549 
1550  if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1551  av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1552  frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1554  }
1555 
1556  if (!frame->data[0])
1557  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1558 
1560  return ff_decode_frame_props(avctx, frame);
1561 
1562  tmp = av_frame_alloc();
1563  if (!tmp)
1564  return AVERROR(ENOMEM);
1565 
1567 
1569  if (ret < 0) {
1570  av_frame_free(&tmp);
1571  return ret;
1572  }
1573 
1575  av_frame_free(&tmp);
1576 
1577  return 0;
1578 }
1579 
1581 {
1582  int ret = reget_buffer_internal(avctx, frame, flags);
1583  if (ret < 0)
1584  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1585  return ret;
1586 }
1587 
1589 {
1590  AVCodecInternal *avci = avctx->internal;
1591  int ret = 0;
1592 
1593  /* if the decoder init function was already called previously,
1594  * free the already allocated subtitle_header before overwriting it */
1595  av_freep(&avctx->subtitle_header);
1596 
1597 #if FF_API_THREAD_SAFE_CALLBACKS
1599  if ((avctx->thread_type & FF_THREAD_FRAME) &&
1601  !avctx->thread_safe_callbacks) {
1602  av_log(avctx, AV_LOG_WARNING, "Requested frame threading with a "
1603  "custom get_buffer2() implementation which is not marked as "
1604  "thread safe. This is not supported anymore, make your "
1605  "callback thread-safe.\n");
1606  }
1608 #endif
1609 
1610  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && avctx->ch_layout.nb_channels == 0 &&
1612  av_log(avctx, AV_LOG_ERROR, "Decoder requires channel count but channels not set\n");
1613  return AVERROR(EINVAL);
1614  }
1615  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1616  av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
1617  avctx->codec->max_lowres);
1618  avctx->lowres = avctx->codec->max_lowres;
1619  }
1620  if (avctx->sub_charenc) {
1621  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1622  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1623  "supported with subtitles codecs\n");
1624  return AVERROR(EINVAL);
1625  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1626  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1627  "subtitles character encoding will be ignored\n",
1628  avctx->codec_descriptor->name);
1630  } else {
1631  /* input character encoding is set for a text based subtitle
1632  * codec at this point */
1635 
1637 #if CONFIG_ICONV
1638  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1639  if (cd == (iconv_t)-1) {
1640  ret = AVERROR(errno);
1641  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1642  "with input character encoding \"%s\"\n", avctx->sub_charenc);
1643  return ret;
1644  }
1645  iconv_close(cd);
1646 #else
1647  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1648  "conversion needs a libavcodec built with iconv support "
1649  "for this codec\n");
1650  return AVERROR(ENOSYS);
1651 #endif
1652  }
1653  }
1654  }
1655 
1657  avctx->pts_correction_num_faulty_dts = 0;
1658  avctx->pts_correction_last_pts =
1659  avctx->pts_correction_last_dts = INT64_MIN;
1660 
1661  if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
1663  av_log(avctx, AV_LOG_WARNING,
1664  "gray decoding requested but not enabled at configuration time\n");
1665  if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
1667  }
1668 
1669  avci->in_pkt = av_packet_alloc();
1670  avci->last_pkt_props = av_packet_alloc();
1671  avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
1673  if (!avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props)
1674  return AVERROR(ENOMEM);
1675 
1676  ret = decode_bsfs_init(avctx);
1677  if (ret < 0)
1678  return ret;
1679 
1680  return 0;
1681 }
1682 
1683 int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
1684 {
1685  size_t size;
1686  const void *pal = av_packet_get_side_data(src, AV_PKT_DATA_PALETTE, &size);
1687 
1688  if (pal && size == AVPALETTE_SIZE) {
1689  memcpy(dst, pal, AVPALETTE_SIZE);
1690  return 1;
1691  } else if (pal) {
1692  av_log(logctx, AV_LOG_ERROR,
1693  "Palette size %"SIZE_SPECIFIER" is wrong\n", size);
1694  }
1695  return 0;
1696 }
AVSubtitle
Definition: avcodec.h:2314
AVCodecInternal::initial_sample_rate
int initial_sample_rate
Definition: internal.h:155
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:1388
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
FFCodec::receive_frame
int(* receive_frame)(struct AVCodecContext *avctx, struct AVFrame *frame)
Decode API with decoupled packet/frame dataflow.
Definition: codec_internal.h:201
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:205
hw_pix_fmt
static enum AVPixelFormat hw_pix_fmt
Definition: hw_decode.c:46
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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:662
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:205
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:975
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:503
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1159
apply_cropping
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition: decode.c:673
FF_COMPLIANCE_EXPERIMENTAL
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:1314
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1007
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:691
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:679
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:69
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:2703
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:2230
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:346
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:127
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1353
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:555
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:116
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:325
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:968
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:223
avcodec_decode_subtitle2
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: decode.c:875
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
AV_FIFO_FLAG_AUTO_GROW
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition: fifo.h:58
AVHWAccel::capabilities
int capabilities
Hardware accelerated codec capabilities.
Definition: avcodec.h:2109
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:506
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:2194
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:928
FFCodec
Definition: codec_internal.h:118
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:1714
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
av_fifo_read
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition: fifo.c:240
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:1790
AVDictionary
Definition: dict.c:30
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:295
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:478
avcodec_default_get_format
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Definition: decode.c:947
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:720
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:322
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:300
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:525
AV_RL8
#define AV_RL8(x)
Definition: intreadwrite.h:398
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:1789
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:870
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:637
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:312
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1741
AVCodec::max_lowres
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: codec.h:224
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2743
AVHWAccel
Definition: avcodec.h:2076
fifo.h
finish
static void finish(void)
Definition: movenc.c:342
bsf.h
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:407
STRIDE_ALIGN
#define STRIDE_ALIGN
Definition: internal.h:49
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2065
fail
#define fail()
Definition: checkasm.h:131
AVCodecInternal::showed_multi_packet_warning
int showed_multi_packet_warning
Definition: internal.h:146
ff_icc_context_init
int ff_icc_context_init(FFIccContext *s, void *avctx)
Initializes an FFIccContext.
Definition: fflcms2.c:31
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1472
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:1788
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:478
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
pts
static int64_t pts
Definition: transcode_aac.c:654
add_metadata_from_side_data
static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
Definition: decode.c:1294
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:586
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:245
AVCodecContext::max_samples
int64_t max_samples
The number of samples per frame to maximally accept.
Definition: avcodec.h:2005
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:2208
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:418
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:104
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:1176
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
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:961
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:234
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:1769
ff_decode_receive_frame
int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
avcodec_receive_frame() implementation for decoders.
Definition: decode.c:700
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:112
hwaccel_uninit
static void hwaccel_uninit(AVCodecContext *avctx)
Definition: decode.c:1147
AVHWAccel::alloc_frame
int(* alloc_frame)(AVCodecContext *avctx, AVFrame *frame)
Allocate a custom buffer.
Definition: avcodec.h:2122
copy_packet_props
static int copy_packet_props(AVPacket *dst, const AVPacket *src)
Definition: decode.c:137
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:694
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:339
get_subtitle_defaults
static void get_subtitle_defaults(AVSubtitle *sub)
Definition: decode.c:788
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:1404
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
buffers for using new encode/decode API through legacy API
Definition: internal.h:142
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:2202
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:376
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
AVCodecContext::thread_type
int thread_type
Which multithreading methods to use.
Definition: avcodec.h:1482
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:367
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:105
AVCodecContext::max_pixels
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:1917
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
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:481
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:184
decode_data_free
static void decode_data_free(void *opaque, uint8_t *data)
Definition: decode.c:1425
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:1010
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:152
AVCodecContext::sub_charenc
char * sub_charenc
DTS of the last frame.
Definition: avcodec.h:1779
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:339
AVChannelLayout::u
union AVChannelLayout::@303 u
Details about which channels are present in this layout.
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:856
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:1975
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:982
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:217
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:433
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_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:930
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_CODEC_FLAG_TRUNCATED
#define AV_CODEC_FLAG_TRUNCATED
Input bitstream might be truncated at a random location instead of only at frame boundaries.
Definition: avcodec.h:271
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:154
AVCodecContext::thread_safe_callbacks
attribute_deprecated int thread_safe_callbacks
Set by the client if its custom get_buffer() callback can be called synchronously from another thread...
Definition: avcodec.h:1511
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:349
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:252
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
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1364
AVCodecInternal::draining_done
int draining_done
Definition: internal.h:144
UTF8_MAX_BYTES
#define UTF8_MAX_BYTES
Definition: decode.c:794
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:572
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:84
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:109
FFCodec::cb
union FFCodec::@50 cb
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:521
av_codec_is_decoder
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:82
AVCodecContext::lowres
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:1464
f
f
Definition: af_crystalizer.c:122
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:485
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1462
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:259
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:510
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:1989
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:132
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:771
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:77
AVCodecInternal::initial_format
int initial_format
Definition: internal.h:153
AVCodecInternal::bsf
struct AVBSFContext * bsf
Definition: internal.h:78
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1023
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:1755
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:59
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVFrameSideData::data
uint8_t * data
Definition: frame.h:233
ffcodec
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
Definition: codec_internal.h:279
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:533
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:626
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:1770
AVCodecContext::pts_correction_last_pts
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition: avcodec.h:1771
hwaccel_init
static int hwaccel_init(AVCodecContext *avctx, const AVCodecHWConfigInternal *hw_config)
Definition: decode.c:1110
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:41
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:236
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:252
detect_colorspace
static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f)
Definition: decode.c:549
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
AVCodecInternal::pkt_props
struct AVFifo * pkt_props
Definition: internal.h:85
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1483
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:2082
avcodec_default_get_buffer2
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: get_buffer.c:290
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:637
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:127
extract_packet_props
static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
Definition: decode.c:149
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:154
reget_buffer_internal
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition: decode.c:1543
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:571
internal.h
av_fifo_alloc2
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition: fifo.c:47
common.h
AVCodecInternal::in_pkt
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
Definition: internal.h:77
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h: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:1772
ff_decode_preinit
int ff_decode_preinit(AVCodecContext *avctx)
Perform decoder initialization and validation.
Definition: decode.c:1588
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:516
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:487
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:264
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
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:1939
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:989
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:48
profile
int profile
Definition: mxfenc.c:2005
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:535
AVCodecContext::height
int height
Definition: avcodec.h:571
decode_simple_internal
static int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition: decode.c:277
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:608
AVCodecInternal::nb_draining_errors
int nb_draining_errors
Definition: internal.h:149
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:1889
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:192
AVCodecContext::sub_charenc_mode
int sub_charenc_mode
Subtitles character encoding mode.
Definition: avcodec.h:1787
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
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:1061
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:1580
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:355
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1309
FF_REGET_BUFFER_FLAG_READONLY
#define FF_REGET_BUFFER_FLAG_READONLY
the returned buffer does not need to be writable
Definition: internal.h:222
AV_CODEC_PROP_TEXT_SUB
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: codec_desc.h:102
av_fifo_write
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition: fifo.c:188
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:195
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:1306
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:398
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1491
AVCodecContext::codec_descriptor
const AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:1762
channel_layout.h
AVRational::den
int den
Denominator.
Definition: rational.h:60
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:2015
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:82
FF_CODEC_CB_TYPE_RECEIVE_FRAME
@ FF_CODEC_CB_TYPE_RECEIVE_FRAME
Definition: codec_internal.h:106
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
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:134
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:879
AVCodecInternal::buffer_frame
AVFrame * buffer_frame
Definition: internal.h:143
AV_CODEC_CAP_PARAM_CHANGE
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition: codec.h:121
AVCodecInternal::draining
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:137
FFCodec::bsfs
const char * bsfs
Decoding only, a comma-separated list of bitstream filters to apply to packets before decoding.
Definition: codec_internal.h:243
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:82
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:586
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:406
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:563
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
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:90
AV_CODEC_EXPORT_DATA_MVS
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:357
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:100
ff_attach_decode_data
int ff_attach_decode_data(AVFrame *frame)
Definition: decode.c:1438
AVCodecInternal::initial_ch_layout
AVChannelLayout initial_ch_layout
Definition: internal.h:160
AVCodecContext::frame_number
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1046
recode_subtitle
static int recode_subtitle(AVCodecContext *avctx, AVPacket **outpkt, AVPacket *inpkt, AVPacket *buf_pkt)
Definition: decode.c:795
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:231
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:335
IS_EMPTY
#define IS_EMPTY(pkt)
Definition: decode.c:135
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:351
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:2223
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:394
AVCodecContext::reordered_opaque
int64_t reordered_opaque
opaque 64-bit number (generally a PTS) that will be reordered and output in AVFrame....
Definition: avcodec.h:1381
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:571
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
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:326
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:358
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1748
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:1683
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:170
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:2103
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:768
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:2623
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:1791
min
float min
Definition: vorbis_enc_data.h:429
intmath.h