FFmpeg
Loading...
Searching...
No Matches
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 <assert.h>
22#include <stdint.h>
23#include <stdbool.h>
24#include <string.h>
25
26#include "config.h"
27
28#if CONFIG_ICONV
29# include <iconv.h>
30#endif
31
32#include "libavutil/avassert.h"
34#include "libavutil/common.h"
35#include "libavutil/emms.h"
36#include "libavutil/frame.h"
37#include "libavutil/hwcontext.h"
38#include "libavutil/imgutils.h"
39#include "libavutil/internal.h"
41#include "libavutil/mem.h"
42#include "libavutil/stereo3d.h"
43
44#include "avcodec.h"
45#include "avcodec_internal.h"
46#include "bytestream.h"
47#include "bsf.h"
48#include "codec_desc.h"
49#include "codec_internal.h"
50#include "decode.h"
51#include "exif.h"
52#include "exif_internal.h"
53#include "hwaccel_internal.h"
54#include "hwconfig.h"
55#include "internal.h"
56#include "lcevcdec.h"
57#include "packet_internal.h"
58#include "progressframe.h"
59#include "libavutil/refstruct.h"
60#include "thread.h"
61#include "threadprogress.h"
62
63typedef struct DecodeContext {
65
66 /**
67 * This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats
68 * (those whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set)
69 * to set the flag generically.
70 */
72
73 /**
74 * This is set to AV_PICTURE_TYPE_I for intra only video decoders
75 * and to AV_PICTURE_TYPE_NONE for other decoders. It is used to set
76 * the AVFrame's pict_type before the decoder receives it.
77 */
79
80 /* to prevent infinite loop on errors when draining */
82
83 /**
84 * The caller has submitted a NULL packet on input.
85 */
87
88 int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
89 int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
90 int64_t pts_correction_last_pts; /// PTS of the last frame
91 int64_t pts_correction_last_dts; /// DTS of the last frame
92
93 /**
94 * Bitmask indicating for which side data types we prefer user-supplied
95 * (global or attached to packets) side data over bytestream.
96 */
98
99#if CONFIG_LIBLCEVC_DEC
100 struct {
102 int frame;
104 enum AVPixelFormat base_format;
105 int base_width;
106 int base_height;
107 int width;
108 int height;
109 } lcevc;
110#endif
112
114{
115 return (DecodeContext *)avci;
116}
117
118static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
119{
120 int ret;
121 size_t size;
122 const uint8_t *data;
123 uint32_t flags;
124 int64_t val;
125
127 if (!data)
128 return 0;
129
131 av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
132 "changes, but PARAM_CHANGE side data was sent to it.\n");
133 ret = AVERROR(EINVAL);
134 goto fail2;
135 }
136
137 if (size < 4)
138 goto fail;
139
140 flags = bytestream_get_le32(&data);
141 size -= 4;
142
144 if (size < 4)
145 goto fail;
146 val = bytestream_get_le32(&data);
147 if (val <= 0 || val > INT_MAX) {
148 av_log(avctx, AV_LOG_ERROR, "Invalid sample rate");
150 goto fail2;
151 }
152 avctx->sample_rate = val;
153 size -= 4;
154 }
156 if (size < 8)
157 goto fail;
158 avctx->width = bytestream_get_le32(&data);
159 avctx->height = bytestream_get_le32(&data);
160 size -= 8;
161 ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
162 if (ret < 0)
163 goto fail2;
164 }
165
166 return 0;
167fail:
168 av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
170fail2:
171 if (ret < 0) {
172 av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
173 if (avctx->err_recognition & AV_EF_EXPLODE)
174 return ret;
175 }
176 return 0;
177}
178
180{
181 int ret = 0;
182
184 if (pkt) {
186 }
187 return ret;
188}
189
191{
192 AVCodecInternal *avci = avctx->internal;
193 const FFCodec *const codec = ffcodec(avctx->codec);
194 int ret;
195
196 if (avci->bsf)
197 return 0;
198
199 ret = av_bsf_list_parse_str(codec->bsfs, &avci->bsf);
200 if (ret < 0) {
201 av_log(avctx, AV_LOG_ERROR, "Error parsing decoder bitstream filters '%s': %s\n", codec->bsfs, av_err2str(ret));
202 if (ret != AVERROR(ENOMEM))
204 goto fail;
205 }
206
207 /* We do not currently have an API for passing the input timebase into decoders,
208 * but no filters used here should actually need it.
209 * So we make up some plausible-looking number (the MPEG 90kHz timebase) */
210 avci->bsf->time_base_in = (AVRational){ 1, 90000 };
212 if (ret < 0)
213 goto fail;
214
215 ret = av_bsf_init(avci->bsf);
216 if (ret < 0)
217 goto fail;
218
219 return 0;
220fail:
221 av_bsf_free(&avci->bsf);
222 return ret;
223}
224
225#if !HAVE_THREADS
226#define ff_thread_get_packet(avctx, pkt) (AVERROR_BUG)
227#define ff_thread_receive_frame(avctx, frame, flags) (AVERROR_BUG)
228#endif
229
231{
232 AVCodecInternal *avci = avctx->internal;
233 int ret;
234
236 if (ret < 0)
237 return ret;
238
241 if (ret < 0)
242 goto finish;
243 }
244
245 ret = apply_param_change(avctx, pkt);
246 if (ret < 0)
247 goto finish;
248
249 return 0;
250finish:
252 return ret;
253}
254
256{
257 AVCodecInternal *avci = avctx->internal;
258 DecodeContext *dc = decode_ctx(avci);
259
260 if (avci->draining)
261 return AVERROR_EOF;
262
263 /* If we are a worker thread, get the next packet from the threading
264 * context. Otherwise we are the main (user-facing) context, so we get the
265 * next packet from the input filterchain.
266 */
267 if (avctx->internal->is_frame_mt)
268 return ff_thread_get_packet(avctx, pkt);
269
270 while (1) {
271 int ret = decode_get_packet(avctx, pkt);
272 if (ret == AVERROR(EAGAIN) &&
274 ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
275 if (ret >= 0)
276 continue;
277
279 }
280
281 if (ret == AVERROR_EOF)
282 avci->draining = 1;
283 return ret;
284 }
285}
286
287/**
288 * Attempt to guess proper monotonic timestamps for decoded video frames
289 * which might have incorrect times. Input timestamps may wrap around, in
290 * which case the output will as well.
291 *
292 * @param pts the pts field of the decoded AVPacket, as passed through
293 * AVFrame.pts
294 * @param dts the dts field of the decoded AVPacket
295 * @return one of the input values, may be AV_NOPTS_VALUE
296 */
298 int64_t reordered_pts, int64_t dts)
299{
301
302 if (dts != AV_NOPTS_VALUE) {
304 dc->pts_correction_last_dts = dts;
305 } else if (reordered_pts != AV_NOPTS_VALUE)
306 dc->pts_correction_last_dts = reordered_pts;
307
308 if (reordered_pts != AV_NOPTS_VALUE) {
309 dc->pts_correction_num_faulty_pts += reordered_pts <= dc->pts_correction_last_pts;
310 dc->pts_correction_last_pts = reordered_pts;
311 } else if(dts != AV_NOPTS_VALUE)
312 dc->pts_correction_last_pts = dts;
313
315 && reordered_pts != AV_NOPTS_VALUE)
316 pts = reordered_pts;
317 else
318 pts = dts;
319
320 return pts;
321}
322
323static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
324{
325 AVCodecInternal *avci = avctx->internal;
326 AVFrameSideData *side;
327 uint32_t discard_padding = 0;
328 int nb_samples = frame->nb_samples;
329 uint8_t skip_reason = 0;
330 uint8_t discard_reason = 0;
331
333 if (side && side->size >= 10) {
334 int skip_samples = AV_RL32(side->data);
335 if (skip_samples)
336 avci->skip_samples = av_rescale(skip_samples, frame->sample_rate, avctx->sample_rate);
337 avci->skip_samples = FFMAX(0, avci->skip_samples);
338 discard_padding = av_rescale(AV_RL32(side->data + 4), frame->sample_rate, avctx->sample_rate);
339 av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
340 avci->skip_samples, (int)discard_padding);
341 skip_reason = AV_RL8(side->data + 8);
342 discard_reason = AV_RL8(side->data + 9);
343 }
344
345 if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
346 if (!side && (avci->skip_samples || discard_padding))
348 if (side && (avci->skip_samples || discard_padding)) {
349 AV_WL32(side->data, avci->skip_samples);
350 AV_WL32(side->data + 4, discard_padding);
351 AV_WL8(side->data + 8, skip_reason);
352 AV_WL8(side->data + 9, discard_reason);
353 avci->skip_samples = 0;
354 }
355 return 0;
356 }
358
359 if ((frame->flags & AV_FRAME_FLAG_DISCARD)) {
360 avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
361 av_log(avctx, AV_LOG_DEBUG, "discard whole frame due to discard frame flag, skip left: %d\n",
362 avci->skip_samples);
363 *discarded_samples += frame->nb_samples;
364 return AVERROR(EAGAIN);
365 }
366
367 if (avci->skip_samples > 0) {
368 if (frame->nb_samples <= avci->skip_samples){
369 *discarded_samples += frame->nb_samples;
370 avci->skip_samples -= frame->nb_samples;
371 av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
372 avci->skip_samples);
373 return AVERROR(EAGAIN);
374 } else {
375 av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
376 frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
377 if (avctx->pkt_timebase.num && frame->sample_rate) {
378 int64_t diff_ts = av_rescale_q(avci->skip_samples,
379 (AVRational){1, frame->sample_rate},
380 avctx->pkt_timebase);
381 if (diff_ts != AV_NOPTS_VALUE) {
382 if (frame->pts != AV_NOPTS_VALUE)
383 frame->pts = av_sat_add64(frame->pts, diff_ts);
384 if (frame->pkt_dts != AV_NOPTS_VALUE)
385 frame->pkt_dts = av_sat_add64(frame->pkt_dts, diff_ts);
386 if (frame->duration >= diff_ts)
387 frame->duration = av_sat_sub64(frame->duration, diff_ts);
388 } else {
389 frame->pts = AV_NOPTS_VALUE;
390 frame->pkt_dts = AV_NOPTS_VALUE;
391 frame->duration = 0;
392 }
393 } else
394 av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
395
396 av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
397 avci->skip_samples, frame->nb_samples);
398 *discarded_samples += avci->skip_samples;
399 frame->nb_samples -= avci->skip_samples;
400 avci->skip_samples = 0;
401 }
402 }
403
404 if (discard_padding > 0 && discard_padding <= nb_samples) {
405 // The padding may overlap the samples skipped at the start.
406 discard_padding = FFMIN(discard_padding, frame->nb_samples);
407 if (discard_padding == frame->nb_samples) {
408 av_log(avctx, AV_LOG_DEBUG, "discard whole frame\n");
409 *discarded_samples += frame->nb_samples;
410 return AVERROR(EAGAIN);
411 } else {
412 if (avctx->pkt_timebase.num && avctx->sample_rate) {
413 int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
414 (AVRational){1, frame->sample_rate},
415 avctx->pkt_timebase);
416 frame->duration = diff_ts == AV_NOPTS_VALUE ? 0 : diff_ts;
417 } else
418 av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
419
420 av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
421 (int)discard_padding, frame->nb_samples);
422 frame->nb_samples -= discard_padding;
423 }
424 }
425
426 return 0;
427}
428
429/*
430 * The core of the receive_frame_wrapper for the decoders implementing
431 * the simple API. Certain decoders might consume partial packets without
432 * returning any output, so this function needs to be called in a loop until it
433 * returns EAGAIN.
434 **/
435static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
436{
437 AVCodecInternal *avci = avctx->internal;
438 DecodeContext *dc = decode_ctx(avci);
439 AVPacket *const pkt = avci->in_pkt;
440 const FFCodec *const codec = ffcodec(avctx->codec);
441 int got_frame, consumed;
442 int ret;
443
444 if (!pkt->data && !avci->draining) {
446 ret = ff_decode_get_packet(avctx, pkt);
447 if (ret < 0 && ret != AVERROR_EOF)
448 return ret;
449 }
450
451 // Some codecs (at least wma lossless) will crash when feeding drain packets
452 // after EOF was signaled.
453 if (avci->draining_done)
454 return AVERROR_EOF;
455
456 if (!pkt->data &&
458 return AVERROR_EOF;
459
460 got_frame = 0;
461
462 frame->pict_type = dc->initial_pict_type;
463 frame->flags |= dc->intra_only_flag;
464 consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
465
467 frame->pkt_dts = pkt->dts;
468 emms_c();
469
470 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
471 ret = (!got_frame || frame->flags & AV_FRAME_FLAG_DISCARD)
472 ? AVERROR(EAGAIN)
473 : 0;
474 } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
475 ret = !got_frame ? AVERROR(EAGAIN)
476 : discard_samples(avctx, frame, discarded_samples);
477 } else
478 av_assert0(0);
479
480 if (ret == AVERROR(EAGAIN))
482
483 // FF_CODEC_CB_TYPE_DECODE decoders must not return AVERROR EAGAIN
484 // or AVERROR_EOF.
485 // code later will add AVERROR(EAGAIN) to a pointer
486 av_assert0(consumed != AVERROR(EAGAIN) && consumed != AVERROR_EOF);
487 if (consumed < 0)
488 ret = consumed;
489 if (consumed >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
490 consumed = pkt->size;
491
492 if (!ret)
493 av_assert0(frame->buf[0]);
494 if (ret == AVERROR(EAGAIN))
495 ret = 0;
496
497 /* do not stop draining when got_frame != 0 or ret < 0 */
498 if (avci->draining && !got_frame) {
499 if (ret < 0) {
500 /* prevent infinite loop if a decoder wrongly always return error on draining */
501 /* reasonable nb_errors_max = maximum b frames + thread count */
502 int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
503 avctx->thread_count : 1);
504
505 if (decode_ctx(avci)->nb_draining_errors++ >= nb_errors_max) {
506 av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
507 "Stop draining and force EOF.\n");
508 avci->draining_done = 1;
510 }
511 } else {
512 avci->draining_done = 1;
513 }
514 }
515
516 if (consumed >= pkt->size || ret < 0) {
518 } else {
519 pkt->data += consumed;
520 pkt->size -= consumed;
521 pkt->pts = AV_NOPTS_VALUE;
522 pkt->dts = AV_NOPTS_VALUE;
526 }
527 }
528
529 return ret;
530}
531
532#if CONFIG_LCMS2
534{
535 AVCodecInternal *avci = avctx->internal;
538 enum AVColorPrimaries prim;
539 cmsHPROFILE profile;
540 AVFrameSideData *sd;
541 int ret;
542 if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
543 return 0;
544
546 if (!sd || !sd->size)
547 return 0;
548
549 if (!avci->icc.avctx) {
550 ret = ff_icc_context_init(&avci->icc, avctx);
551 if (ret < 0)
552 return ret;
553 }
554
555 profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size);
556 if (!profile)
557 return AVERROR_INVALIDDATA;
558
559 ret = ff_icc_profile_sanitize(&avci->icc, profile);
560 if (!ret)
561 ret = ff_icc_profile_read_primaries(&avci->icc, profile, &coeffs);
562 if (!ret)
563 ret = ff_icc_profile_detect_transfer(&avci->icc, profile, &trc);
564 cmsCloseProfile(profile);
565 if (ret < 0)
566 return ret;
567
568 prim = av_csp_primaries_id_from_desc(&coeffs);
569 if (prim != AVCOL_PRI_UNSPECIFIED)
570 frame->color_primaries = prim;
571 if (trc != AVCOL_TRC_UNSPECIFIED)
572 frame->color_trc = trc;
573 return 0;
574}
575#else /* !CONFIG_LCMS2 */
577{
578 return 0;
579}
580#endif
581
583{
584 int ret;
585
586 if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
587 frame->color_primaries = avctx->color_primaries;
588 if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
589 frame->color_trc = avctx->color_trc;
590 if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
591 frame->colorspace = avctx->colorspace;
592 if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
593 frame->color_range = avctx->color_range;
594 if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
595 frame->chroma_location = avctx->chroma_sample_location;
596 if (frame->alpha_mode == AVALPHA_MODE_UNSPECIFIED)
597 frame->alpha_mode = avctx->alpha_mode;
598
599 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
600 if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
601 if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
602 } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
603 if (frame->format == AV_SAMPLE_FMT_NONE)
604 frame->format = avctx->sample_fmt;
605 if (!frame->ch_layout.nb_channels) {
606 ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
607 if (ret < 0)
608 return ret;
609 }
610 if (!frame->sample_rate)
611 frame->sample_rate = avctx->sample_rate;
612 }
613
614 return 0;
615}
616
618{
619 int ret;
620 int64_t discarded_samples = 0;
621
622 while (!frame->buf[0]) {
623 if (discarded_samples > avctx->max_samples)
624 return AVERROR(EAGAIN);
625 ret = decode_simple_internal(avctx, frame, &discarded_samples);
626 if (ret < 0)
627 return ret;
628 }
629
630 return 0;
631}
632
634{
635 AVCodecInternal *avci = avctx->internal;
636 DecodeContext *dc = decode_ctx(avci);
637 const FFCodec *const codec = ffcodec(avctx->codec);
638 int ret;
639
640 av_assert0(!frame->buf[0]);
641
643 while (1) {
644 frame->pict_type = dc->initial_pict_type;
645 frame->flags |= dc->intra_only_flag;
646 ret = codec->cb.receive_frame(avctx, frame);
647 emms_c();
648 if (!ret) {
649 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
650 int64_t discarded_samples = 0;
651 ret = discard_samples(avctx, frame, &discarded_samples);
652 }
653 if (ret == AVERROR(EAGAIN) || (frame->flags & AV_FRAME_FLAG_DISCARD)) {
655 continue;
656 }
657 }
658 break;
659 }
660 } else
662
663 if (ret == AVERROR_EOF)
664 avci->draining_done = 1;
665
666 return ret;
667}
668
670 unsigned flags)
671{
672 AVCodecInternal *avci = avctx->internal;
673 DecodeContext *dc = decode_ctx(avci);
674 int ret, ok;
675
678 else
680
681 /* preserve ret */
682 ok = detect_colorspace(avctx, frame);
683 if (ok < 0) {
685 return ok;
686 }
687
688 if (!ret) {
689 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
690 if (!frame->width)
691 frame->width = avctx->width;
692 if (!frame->height)
693 frame->height = avctx->height;
694 }
695
696 ret = fill_frame_props(avctx, frame);
697 if (ret < 0) {
699 return ret;
700 }
701
702 frame->best_effort_timestamp = guess_correct_pts(dc,
703 frame->pts,
704 frame->pkt_dts);
705
706 /* the only case where decode data is not set should be decoders
707 * that do not call ff_get_buffer() */
708 av_assert0(frame->private_ref ||
709 !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
710
711 if (frame->private_ref) {
712 FrameDecodeData *fdd = frame->private_ref;
713
714 if (fdd->hwaccel_priv_post_process) {
715 ret = fdd->hwaccel_priv_post_process(avctx, frame);
716 if (ret < 0) {
718 return ret;
719 }
720 }
721
722 if (fdd->post_process) {
723 ret = fdd->post_process(avctx, frame);
724 if (ret < 0) {
726 return ret;
727 }
728 }
729 }
730 }
731
732 /* free the per-frame decode data */
733 av_refstruct_unref(&frame->private_ref);
734
735 return ret;
736}
737
739{
740 AVCodecInternal *avci = avctx->internal;
741 DecodeContext *dc = decode_ctx(avci);
742 int ret;
743
744 if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
745 return AVERROR(EINVAL);
746
747 if (dc->draining_started)
748 return AVERROR_EOF;
749
750 if (avpkt && !avpkt->size && avpkt->data)
751 return AVERROR(EINVAL);
752
753 if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
754 if (!AVPACKET_IS_EMPTY(avci->buffer_pkt))
755 return AVERROR(EAGAIN);
756 ret = av_packet_ref(avci->buffer_pkt, avpkt);
757 if (ret < 0)
758 return ret;
759 } else
760 dc->draining_started = 1;
761
762 if (!avci->buffer_frame->buf[0] && !dc->draining_started) {
764 if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
765 return ret;
766 }
767
768 return 0;
769}
770
772{
773 /* make sure we are noisy about decoders returning invalid cropping data */
774 if (frame->crop_left >= INT_MAX - frame->crop_right ||
775 frame->crop_top >= INT_MAX - frame->crop_bottom ||
776 (frame->crop_left + frame->crop_right) >= frame->width ||
777 (frame->crop_top + frame->crop_bottom) >= frame->height) {
778 av_log(avctx, AV_LOG_WARNING,
779 "Invalid cropping information set by a decoder: "
780 "%zu/%zu/%zu/%zu (frame size %dx%d). "
781 "This is a bug, please report it\n",
782 frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
783 frame->width, frame->height);
784 frame->crop_left = 0;
785 frame->crop_right = 0;
786 frame->crop_top = 0;
787 frame->crop_bottom = 0;
788 return 0;
789 }
790
791 if (!avctx->apply_cropping)
792 return 0;
793
796}
797
798// make sure frames returned to the caller are valid
800{
801 if (!frame->buf[0] || frame->format < 0)
802 goto fail;
803
804 switch (avctx->codec_type) {
806 if (frame->width <= 0 || frame->height <= 0)
807 goto fail;
808 break;
810 if (!av_channel_layout_check(&frame->ch_layout) ||
811 frame->sample_rate <= 0)
812 goto fail;
813
814 break;
815 default: av_assert0(0);
816 }
817
818 return 0;
819fail:
820 av_log(avctx, AV_LOG_ERROR, "An invalid frame was output by a decoder. "
821 "This is a bug, please report it.\n");
822 return AVERROR_BUG;
823}
824
826{
827 AVCodecInternal *avci = avctx->internal;
828 int ret;
829
830 if (avci->buffer_frame->buf[0]) {
832 } else {
834 if (ret < 0)
835 return ret;
836 }
837
838 ret = frame_validate(avctx, frame);
839 if (ret < 0)
840 goto fail;
841
842 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
843 ret = apply_cropping(avctx, frame);
844 if (ret < 0)
845 goto fail;
846 }
847
848 avctx->frame_num++;
849
850 return 0;
851fail:
853 return ret;
854}
855
857{
858 memset(sub, 0, sizeof(*sub));
859 sub->pts = AV_NOPTS_VALUE;
860}
861
862#define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
863static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt,
864 const AVPacket *inpkt, AVPacket *buf_pkt)
865{
866#if CONFIG_ICONV
867 iconv_t cd = (iconv_t)-1;
868 int ret = 0;
869 char *inb, *outb;
870 size_t inl, outl;
871#endif
872
873 if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) {
874 *outpkt = inpkt;
875 return 0;
876 }
877
878#if CONFIG_ICONV
879 inb = inpkt->data;
880 inl = inpkt->size;
881
882 if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) {
883 av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
884 return AVERROR(ERANGE);
885 }
886
887 cd = iconv_open("UTF-8", avctx->sub_charenc);
888 av_assert0(cd != (iconv_t)-1);
889
890 ret = av_new_packet(buf_pkt, inl * UTF8_MAX_BYTES);
891 if (ret < 0)
892 goto end;
893 ret = av_packet_copy_props(buf_pkt, inpkt);
894 if (ret < 0)
895 goto end;
896 outb = buf_pkt->data;
897 outl = buf_pkt->size;
898
899 if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
900 iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
901 outl >= buf_pkt->size || inl != 0) {
902 ret = FFMIN(AVERROR(errno), -1);
903 av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%.*s\" "
904 "from %s to UTF-8\n", inpkt->size, inpkt->data, avctx->sub_charenc);
905 goto end;
906 }
907 buf_pkt->size -= outl;
908 memset(buf_pkt->data + buf_pkt->size, 0, outl);
909 *outpkt = buf_pkt;
910
911 ret = 0;
912end:
913 if (ret < 0)
914 av_packet_unref(buf_pkt);
915 if (cd != (iconv_t)-1)
916 iconv_close(cd);
917 return ret;
918#else
919 av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
920 return AVERROR(EINVAL);
921#endif
922}
923
924static int utf8_check(const uint8_t *str)
925{
926 const uint8_t *byte;
927 uint32_t codepoint, min;
928
929 while (*str) {
930 byte = str;
931 GET_UTF8(codepoint, *(byte++), return 0;);
932 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
933 1 << (5 * (byte - str) - 4);
934 if (codepoint < min || codepoint >= 0x110000 ||
935 codepoint == 0xFFFE /* BOM */ ||
936 codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
937 return 0;
938 str = byte;
939 }
940 return 1;
941}
942
943const char *ff_decode_subtitle_text(AVCodecContext *avctx, const AVPacket *avpkt)
944{
945 AVPacket *copy = avctx->internal->buffer_pkt;
946
947 if (avpkt->size <= 0 || !avpkt->data[avpkt->size])
948 return avpkt->data;
949 if (av_new_packet(copy, avpkt->size) < 0)
950 return NULL;
951 memcpy(copy->data, avpkt->data, avpkt->size);
952 return copy->data;
953}
954
956 int *got_sub_ptr, const AVPacket *avpkt)
957{
958 int ret = 0;
959
960 if (!avpkt->data && avpkt->size) {
961 av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
962 return AVERROR(EINVAL);
963 }
964 if (!avctx->codec)
965 return AVERROR(EINVAL);
967 av_log(avctx, AV_LOG_ERROR, "Codec not subtitle decoder\n");
968 return AVERROR(EINVAL);
969 }
970
971 *got_sub_ptr = 0;
973
974 if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
975 AVCodecInternal *avci = avctx->internal;
976 const AVPacket *pkt;
977
978 ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
979 if (ret < 0)
980 return ret;
981
982 if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
983 sub->pts = av_rescale_q(avpkt->pts,
985 ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
987 if (ret < 0) {
988 *got_sub_ptr = 0;
989 avsubtitle_free(sub);
990 return ret;
991 }
992 av_assert1(!sub->num_rects || *got_sub_ptr);
993
994 if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
995 avctx->pkt_timebase.num) {
996 AVRational ms = { 1, 1000 };
998 avctx->pkt_timebase, ms);
999 }
1000
1002 sub->format = 0;
1004 sub->format = 1;
1005
1006 for (unsigned i = 0; i < sub->num_rects; i++) {
1008 sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
1009 av_log(avctx, AV_LOG_ERROR,
1010 "Invalid UTF-8 in decoded subtitles text; "
1011 "maybe missing -sub_charenc option\n");
1012 avsubtitle_free(sub);
1013 *got_sub_ptr = 0;
1014 return AVERROR_INVALIDDATA;
1015 }
1016 }
1017
1018 if (*got_sub_ptr)
1019 avctx->frame_num++;
1020 }
1021
1022 return ret;
1023}
1024
1026 const enum AVPixelFormat *fmt)
1027{
1028 const AVCodecHWConfig *config;
1029 int i, n;
1030
1031 // If a device was supplied when the codec was opened, assume that the
1032 // user wants to use it.
1033 if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
1034 AVHWDeviceContext *device_ctx =
1036 for (i = 0;; i++) {
1037 config = avcodec_get_hw_config(avctx->codec, i);
1038 if (!config)
1039 break;
1040 if (!(config->methods &
1042 continue;
1043 if (device_ctx->type != config->device_type)
1044 continue;
1045 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1046 if (config->pix_fmt == fmt[n])
1047 return fmt[n];
1048 }
1049 }
1050 }
1051 // No device or other setup, so we have to choose from things which
1052 // don't any other external information.
1053
1054 // Choose the first software format
1055 // (this should be best software format if any exist).
1056 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1058 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1059 return fmt[n];
1060 }
1061
1062 // Finally, traverse the list in order and choose the first entry
1063 // with no external dependencies (if there is no hardware configuration
1064 // information available then this just picks the first entry).
1065 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1066 for (i = 0;; i++) {
1067 config = avcodec_get_hw_config(avctx->codec, i);
1068 if (!config)
1069 break;
1070 if (config->pix_fmt == fmt[n])
1071 break;
1072 }
1073 if (!config) {
1074 // No specific config available, so the decoder must be able
1075 // to handle this format without any additional setup.
1076 return fmt[n];
1077 }
1078 if (config->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
1079 // Usable with only internal setup.
1080 return fmt[n];
1081 }
1082 }
1083
1084 // Nothing is usable, give up.
1085 return AV_PIX_FMT_NONE;
1086}
1087
1089 enum AVHWDeviceType dev_type)
1090{
1091 AVHWDeviceContext *device_ctx;
1092 AVHWFramesContext *frames_ctx;
1093 int ret;
1094
1095 if (!avctx->hwaccel)
1096 return AVERROR(ENOSYS);
1097
1098 if (avctx->hw_frames_ctx)
1099 return 0;
1100 if (!avctx->hw_device_ctx) {
1101 av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
1102 "required for hardware accelerated decoding.\n");
1103 return AVERROR(EINVAL);
1104 }
1105
1106 device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data;
1107 if (device_ctx->type != dev_type) {
1108 av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware "
1109 "decoding, but got %s.\n", av_hwdevice_get_type_name(dev_type),
1110 av_hwdevice_get_type_name(device_ctx->type));
1111 return AVERROR(EINVAL);
1112 }
1113
1115 avctx->hw_device_ctx,
1116 avctx->hwaccel->pix_fmt,
1117 &avctx->hw_frames_ctx);
1118 if (ret < 0)
1119 return ret;
1120
1121 frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1122
1123
1124 if (frames_ctx->initial_pool_size) {
1125 // We guarantee 4 base work surfaces. The function above guarantees 1
1126 // (the absolute minimum), so add the missing count.
1127 frames_ctx->initial_pool_size += 3;
1128 }
1129
1131 if (ret < 0) {
1133 return ret;
1134 }
1135
1136 return 0;
1137}
1138
1140 AVBufferRef *device_ref,
1142 AVBufferRef **out_frames_ref)
1143{
1144 AVBufferRef *frames_ref = NULL;
1145 const AVCodecHWConfigInternal *hw_config;
1146 const FFHWAccel *hwa;
1147 int i, ret;
1148 bool clean_priv_data = false;
1149
1150 for (i = 0;; i++) {
1151 hw_config = ffcodec(avctx->codec)->hw_configs[i];
1152 if (!hw_config)
1153 return AVERROR(ENOENT);
1154 if (hw_config->public.pix_fmt == hw_pix_fmt)
1155 break;
1156 }
1157
1158 hwa = hw_config->hwaccel;
1159 if (!hwa || !hwa->frame_params)
1160 return AVERROR(ENOENT);
1161
1162 frames_ref = av_hwframe_ctx_alloc(device_ref);
1163 if (!frames_ref)
1164 return AVERROR(ENOMEM);
1165
1166 if (!avctx->internal->hwaccel_priv_data) {
1167 avctx->internal->hwaccel_priv_data =
1169 if (!avctx->internal->hwaccel_priv_data) {
1170 av_buffer_unref(&frames_ref);
1171 return AVERROR(ENOMEM);
1172 }
1173 clean_priv_data = true;
1174 }
1175
1176 ret = hwa->frame_params(avctx, frames_ref);
1177 if (ret >= 0) {
1178 AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
1179
1180 if (frames_ctx->initial_pool_size) {
1181 // If the user has requested that extra output surfaces be
1182 // available then add them here.
1183 if (avctx->extra_hw_frames > 0)
1184 frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1185
1186 // If frame threading is enabled then an extra surface per thread
1187 // is also required.
1189 frames_ctx->initial_pool_size += avctx->thread_count;
1190 }
1191
1192 *out_frames_ref = frames_ref;
1193 } else {
1194 if (clean_priv_data)
1196 av_buffer_unref(&frames_ref);
1197 }
1198 return ret;
1199}
1200
1202 const FFHWAccel *hwaccel)
1203{
1204 int err;
1205
1206 if (hwaccel->p.capabilities & AV_HWACCEL_CODEC_CAP_EXPERIMENTAL &&
1208 av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1209 hwaccel->p.name);
1210 return AVERROR_PATCHWELCOME;
1211 }
1212
1213 if (!avctx->internal->hwaccel_priv_data && hwaccel->priv_data_size) {
1214 avctx->internal->hwaccel_priv_data =
1215 av_mallocz(hwaccel->priv_data_size);
1216 if (!avctx->internal->hwaccel_priv_data)
1217 return AVERROR(ENOMEM);
1218 }
1219
1220 avctx->hwaccel = &hwaccel->p;
1221 if (hwaccel->init) {
1222 err = hwaccel->init(avctx);
1223 if (err < 0) {
1224 av_log(avctx, AV_LOG_ERROR, "Failed setup for format %s: "
1225 "hwaccel initialisation returned error.\n",
1226 av_get_pix_fmt_name(hwaccel->p.pix_fmt));
1228 avctx->hwaccel = NULL;
1229 return err;
1230 }
1231 }
1232
1233 return 0;
1234}
1235
1237{
1238 if (FF_HW_HAS_CB(avctx, uninit))
1239 FF_HW_SIMPLE_CALL(avctx, uninit);
1240
1242
1243 avctx->hwaccel = NULL;
1244
1246}
1247
1248int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1249{
1250 const AVPixFmtDescriptor *desc;
1251 enum AVPixelFormat *choices;
1252 enum AVPixelFormat ret, user_choice;
1253 const AVCodecHWConfigInternal *hw_config;
1254 const AVCodecHWConfig *config;
1255 int i, n, err;
1256
1257 // Find end of list.
1258 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1259 // Must contain at least one entry.
1260 av_assert0(n >= 1);
1261 // If a software format is available, it must be the last entry.
1262 desc = av_pix_fmt_desc_get(fmt[n - 1]);
1263 if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1264 // No software format is available.
1265 } else {
1266 avctx->sw_pix_fmt = fmt[n - 1];
1267 }
1268
1269 choices = av_memdup(fmt, (n + 1) * sizeof(*choices));
1270 if (!choices)
1271 return AV_PIX_FMT_NONE;
1272
1273 for (;;) {
1274 // Remove the previous hwaccel, if there was one.
1275 ff_hwaccel_uninit(avctx);
1276
1277 user_choice = avctx->get_format(avctx, choices);
1278 if (user_choice == AV_PIX_FMT_NONE) {
1279 // Explicitly chose nothing, give up.
1281 break;
1282 }
1283
1284 desc = av_pix_fmt_desc_get(user_choice);
1285 if (!desc) {
1286 av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
1287 "get_format() callback.\n");
1289 break;
1290 }
1291 av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
1292 desc->name);
1293
1294 for (i = 0; i < n; i++) {
1295 if (choices[i] == user_choice)
1296 break;
1297 }
1298 if (i == n) {
1299 av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
1300 "%s not in possible list.\n", desc->name);
1302 break;
1303 }
1304
1305 if (ffcodec(avctx->codec)->hw_configs) {
1306 for (i = 0;; i++) {
1307 hw_config = ffcodec(avctx->codec)->hw_configs[i];
1308 if (!hw_config)
1309 break;
1310 if (hw_config->public.pix_fmt == user_choice)
1311 break;
1312 }
1313 } else {
1314 hw_config = NULL;
1315 }
1316
1317 if (!hw_config) {
1318 // No config available, so no extra setup required.
1319 ret = user_choice;
1320 break;
1321 }
1322 config = &hw_config->public;
1323
1324 if (config->methods &
1326 avctx->hw_frames_ctx) {
1327 const AVHWFramesContext *frames_ctx =
1329 if (frames_ctx->format != user_choice) {
1330 av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1331 "does not match the format of the provided frames "
1332 "context.\n", desc->name);
1333 goto try_again;
1334 }
1335 } else if (config->methods &
1337 avctx->hw_device_ctx) {
1338 const AVHWDeviceContext *device_ctx =
1340 if (device_ctx->type != config->device_type) {
1341 av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1342 "does not match the type of the provided device "
1343 "context.\n", desc->name);
1344 goto try_again;
1345 }
1346 } else if (config->methods &
1348 // Internal-only setup, no additional configuration.
1349 } else if (config->methods &
1351 // Some ad-hoc configuration we can't see and can't check.
1352 } else {
1353 av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1354 "missing configuration.\n", desc->name);
1355 goto try_again;
1356 }
1357 if (hw_config->hwaccel) {
1358 av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel %s "
1359 "initialisation.\n", desc->name, hw_config->hwaccel->p.name);
1360 err = hwaccel_init(avctx, hw_config->hwaccel);
1361 if (err < 0)
1362 goto try_again;
1363 }
1364 ret = user_choice;
1365 break;
1366
1367 try_again:
1368 av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
1369 "get_format() without it.\n", desc->name);
1370 for (i = 0; i < n; i++) {
1371 if (choices[i] == user_choice)
1372 break;
1373 }
1374 for (; i + 1 < n; i++)
1375 choices[i] = choices[i + 1];
1376 --n;
1377 }
1378
1379 if (ret < 0)
1380 ff_hwaccel_uninit(avctx);
1381
1382 av_freep(&choices);
1383 return ret;
1384}
1385
1386static const AVPacketSideData*
1389{
1390 for (int i = 0; i < nb_sd; i++)
1391 if (sd[i].type == type)
1392 return &sd[i];
1393
1394 return NULL;
1395}
1396
1402
1404 const AVPacketSideData *sd_pkt)
1405{
1406 const AVStereo3D *src;
1407 AVStereo3D *dst;
1408 int ret;
1409
1410 ret = av_buffer_make_writable(&sd_frame->buf);
1411 if (ret < 0)
1412 return ret;
1413 sd_frame->data = sd_frame->buf->data;
1414
1415 dst = ( AVStereo3D*)sd_frame->data;
1416 src = (const AVStereo3D*)sd_pkt->data;
1417
1418 if (dst->type == AV_STEREO3D_UNSPEC)
1419 dst->type = src->type;
1420
1421 if (dst->view == AV_STEREO3D_VIEW_UNSPEC)
1422 dst->view = src->view;
1423
1424 if (dst->primary_eye == AV_PRIMARY_EYE_NONE)
1425 dst->primary_eye = src->primary_eye;
1426
1427 if (!dst->baseline)
1428 dst->baseline = src->baseline;
1429
1430 if (!dst->horizontal_disparity_adjustment.num)
1431 dst->horizontal_disparity_adjustment = src->horizontal_disparity_adjustment;
1432
1433 if (!dst->horizontal_field_of_view.num)
1434 dst->horizontal_field_of_view = src->horizontal_field_of_view;
1435
1436 return 0;
1437}
1438
1440{
1441 AVExifMetadata ifd = { 0 };
1443 AVBufferRef *buf = NULL;
1444 AVFrameSideData *sd_frame;
1445 int ret;
1446
1447 ret = av_exif_parse_buffer(NULL, sd_pkt->data, sd_pkt->size, &ifd,
1449 if (ret < 0)
1450 return ret;
1451
1452 ret = av_exif_get_entry(NULL, &ifd, av_exif_get_tag_id("Orientation"), 0, &entry);
1453 if (ret < 0)
1454 goto end;
1455
1456 if (!entry) {
1457 ret = av_exif_ifd_to_dict(NULL, &ifd, &dst->metadata);
1458 if (ret < 0)
1459 goto end;
1460
1461 sd_frame = av_frame_side_data_new(&dst->side_data, &dst->nb_side_data, AV_FRAME_DATA_EXIF,
1462 sd_pkt->size, 0);
1463 if (sd_frame)
1464 memcpy(sd_frame->data, sd_pkt->data, sd_pkt->size);
1465 ret = sd_frame ? 0 : AVERROR(ENOMEM);
1466
1467 goto end;
1468 } else if (entry->count <= 0 || entry->type != AV_TIFF_SHORT) {
1470 goto end;
1471 }
1472
1473 // If a display matrix already exists in the frame, give it priority
1474 if (av_frame_side_data_get(dst->side_data, dst->nb_side_data, AV_FRAME_DATA_DISPLAYMATRIX))
1475 goto finish;
1476
1477 sd_frame = av_frame_side_data_new(&dst->side_data, &dst->nb_side_data, AV_FRAME_DATA_DISPLAYMATRIX,
1478 sizeof(int32_t) * 9, 0);
1479 if (!sd_frame) {
1480 ret = AVERROR(ENOMEM);
1481 goto end;
1482 }
1483
1484 ret = av_exif_orientation_to_matrix((int32_t *)sd_frame->data, entry->value.uint[0]);
1485 if (ret < 0)
1486 goto end;
1487
1488finish:
1489 av_exif_remove_entry(NULL, &ifd, entry->id, 0);
1490
1491 ret = av_exif_ifd_to_dict(NULL, &ifd, &dst->metadata);
1492 if (ret < 0)
1493 goto end;
1494
1495 ret = av_exif_write(NULL, &ifd, &buf, AV_EXIF_TIFF_HEADER);
1496 if (ret < 0)
1497 goto end;
1498
1499 if (!av_frame_side_data_add(&dst->side_data, &dst->nb_side_data, AV_FRAME_DATA_EXIF, &buf, 0)) {
1500 ret = AVERROR(ENOMEM);
1501 goto end;
1502 }
1503
1504 ret = 0;
1505end:
1506 av_buffer_unref(&buf);
1507 av_exif_free(&ifd);
1508 return ret;
1509}
1510
1512 const AVPacketSideData *sd_src, int nb_sd_src,
1513 const SideDataMap *map)
1514
1515{
1516 for (int i = 0; map[i].packet < AV_PKT_DATA_NB; i++) {
1517 const enum AVPacketSideDataType type_pkt = map[i].packet;
1518 const enum AVFrameSideDataType type_frame = map[i].frame;
1519 const AVPacketSideData *sd_pkt;
1520 AVFrameSideData *sd_frame;
1521
1522 sd_pkt = packet_side_data_get(sd_src, nb_sd_src, type_pkt);
1523 if (!sd_pkt)
1524 continue;
1525
1526 sd_frame = av_frame_get_side_data(dst, type_frame);
1527 if (sd_frame) {
1528 if (type_frame == AV_FRAME_DATA_STEREO3D) {
1529 int ret = side_data_stereo3d_merge(sd_frame, sd_pkt);
1530 if (ret < 0)
1531 return ret;
1532 }
1533
1534 continue;
1535 }
1536
1537 switch (type_pkt) {
1538 case AV_PKT_DATA_EXIF: {
1539 int ret = side_data_exif_parse(dst, sd_pkt);
1540 if (ret < 0)
1541 return ret;
1542 break;
1543 }
1544 default:
1545 sd_frame = av_frame_new_side_data(dst, type_frame, sd_pkt->size);
1546 if (!sd_frame)
1547 return AVERROR(ENOMEM);
1548
1549 memcpy(sd_frame->data, sd_pkt->data, sd_pkt->size);
1550 break;
1551 }
1552 }
1553
1554 return 0;
1555}
1556
1558{
1559 size_t size;
1560 const uint8_t *side_metadata;
1561
1562 AVDictionary **frame_md = &frame->metadata;
1563
1564 side_metadata = av_packet_get_side_data(avpkt,
1566 return av_packet_unpack_dictionary(side_metadata, size, frame_md);
1567}
1568
1570 AVFrame *frame, const AVPacket *pkt)
1571{
1572 static const SideDataMap sd[] = {
1583 { AV_PKT_DATA_NB }
1584 };
1585
1586 int ret = 0;
1587
1588 frame->pts = pkt->pts;
1589 frame->duration = pkt->duration;
1590
1591 if (pkt->side_data_elems) {
1592 ret = side_data_map(frame, pkt->side_data, pkt->side_data_elems, ff_sd_global_map);
1593 if (ret < 0)
1594 return ret;
1595
1596 ret = side_data_map(frame, pkt->side_data, pkt->side_data_elems, sd);
1597 if (ret < 0)
1598 return ret;
1599
1601 }
1602
1603 if (pkt->flags & AV_PKT_FLAG_DISCARD) {
1604 frame->flags |= AV_FRAME_FLAG_DISCARD;
1605 }
1606
1607 if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
1608 ret = av_buffer_replace(&frame->opaque_ref, pkt->opaque_ref);
1609 if (ret < 0)
1610 return ret;
1611 frame->opaque = pkt->opaque;
1612 }
1613
1614 return 0;
1615}
1616
1617#if CONFIG_LIBLCEVC_DEC
1618static int lcevc_parse_frame(AVCodecContext *avctx, DecodeContext *dc, AVFrame *frame)
1619{
1620 int ret;
1621
1622 dc->lcevc.frame = dc->lcevc.ctx &&
1624 if (!dc->lcevc.frame)
1625 return 0;
1626
1627 ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame, &dc->lcevc.format,
1628 &dc->lcevc.base_format,
1629 &dc->lcevc.width, &dc->lcevc.height);
1630 int enhance = !ret && dc->lcevc.width && dc->lcevc.height &&
1631 frame->format == dc->lcevc.base_format;
1632 if (enhance) {
1633 ret = av_image_check_size2(FFMAX(frame->width, dc->lcevc.width),
1634 FFMAX(frame->height, dc->lcevc.height),
1635 avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx);
1636 if (ret < 0) {
1637 dc->lcevc.width = dc->lcevc.height = 0;
1638 enhance = 0;
1639 }
1640 }
1641 if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
1642 return ret;
1643
1644 if (!enhance) {
1645 dc->lcevc.frame = 0;
1646 return 0;
1647 }
1648
1649 dc->lcevc.base_width = frame->width;
1650 dc->lcevc.base_height = frame->height;
1651
1652 return 0;
1653}
1654#endif
1655
1657{
1658 int ret;
1659
1662 if (ret < 0)
1663 return ret;
1664
1665 for (int i = 0; i < avctx->nb_decoded_side_data; i++) {
1666 const AVFrameSideData *src = avctx->decoded_side_data[i];
1667 if (av_frame_get_side_data(frame, src->type))
1668 continue;
1669 ret = av_frame_side_data_clone(&frame->side_data, &frame->nb_side_data, src, 0);
1670 if (ret < 0)
1671 return ret;
1672 }
1673
1675 const AVPacket *pkt = avctx->internal->last_pkt_props;
1676
1678 if (ret < 0)
1679 return ret;
1680 }
1681
1682 ret = fill_frame_props(avctx, frame);
1683 if (ret < 0)
1684 return ret;
1685
1686 switch (avctx->codec->type) {
1687 case AVMEDIA_TYPE_VIDEO:
1688 if (frame->width && frame->height &&
1689 av_image_check_sar(frame->width, frame->height,
1690 frame->sample_aspect_ratio) < 0) {
1691 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1692 frame->sample_aspect_ratio.num,
1693 frame->sample_aspect_ratio.den);
1694 frame->sample_aspect_ratio = (AVRational){ 0, 1 };
1695 }
1696 break;
1697 }
1698
1699#if CONFIG_LIBLCEVC_DEC
1700 AVCodecInternal *avci = avctx->internal;
1701 DecodeContext *dc = decode_ctx(avci);
1702
1703 ret = lcevc_parse_frame(avctx, dc, frame);
1704 if (ret < 0)
1705 return ret;
1706
1707 // force get_buffer2() to allocate the base frame with at least the dimensions
1708 // of the final enhanced frame, in order to prevent reinitializing the buffer
1709 // pools unnecessarely
1710 if (dc->lcevc.frame) {
1711 frame->width = FFMAX(frame->width, dc->lcevc.width);
1712 frame->height = FFMAX(frame->height, dc->lcevc.height);
1713 }
1714#endif
1715
1716 return 0;
1717}
1718
1720{
1721 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1722 int i;
1723 int num_planes = av_pix_fmt_count_planes(frame->format);
1725 int flags = desc ? desc->flags : 0;
1726 if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL))
1727 num_planes = 2;
1728 for (i = 0; i < num_planes; i++) {
1729 av_assert0(frame->data[i]);
1730 }
1731 // For formats without data like hwaccel allow unused pointers to be non-NULL.
1732 for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) {
1733 if (frame->data[i])
1734 av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
1735 frame->data[i] = NULL;
1736 }
1737 }
1738}
1739
1740static void decode_data_free(AVRefStructOpaque unused, void *obj)
1741{
1742 FrameDecodeData *fdd = obj;
1743
1744 if (CONFIG_LIBLCEVC_DEC)
1746 else
1748
1749 if (fdd->hwaccel_priv_free)
1751}
1752
1754{
1755 FrameDecodeData *fdd;
1756
1757 av_assert1(!frame->private_ref);
1758 av_refstruct_unref(&frame->private_ref);
1759
1760 fdd = av_refstruct_alloc_ext(sizeof(*fdd), 0, NULL, decode_data_free);
1761 if (!fdd)
1762 return AVERROR(ENOMEM);
1763
1764 frame->private_ref = fdd;
1765
1766#if CONFIG_LIBLCEVC_DEC
1767 AVCodecInternal *avci = avctx->internal;
1768 DecodeContext *dc = decode_ctx(avci);
1769
1770 if (!dc->lcevc.frame) {
1771 int ret = lcevc_parse_frame(avctx, dc, frame);
1772 if (ret < 0)
1773 return ret;
1774 }
1775 if (dc->lcevc.frame) {
1776 FFLCEVCFrame *frame_ctx;
1777 int ret;
1778
1779 if (fdd->post_process || !dc->lcevc.width || !dc->lcevc.height) {
1780 dc->lcevc.frame = 0;
1781 return 0;
1782 }
1783
1784 frame_ctx = av_refstruct_pool_get(dc->lcevc.ctx->frame_pool);
1785 if (!frame_ctx)
1786 return AVERROR(ENOMEM);
1787
1788 frame_ctx->lcevc = av_refstruct_ref(dc->lcevc.ctx);
1789 frame_ctx->frame->width = dc->lcevc.width;
1790 frame_ctx->frame->height = dc->lcevc.height;
1791 frame_ctx->frame->format = dc->lcevc.format;
1792 avctx->bits_per_raw_sample = av_pix_fmt_desc_get(dc->lcevc.format)->comp[0].depth;
1793
1794 frame->width = dc->lcevc.base_width;
1795 frame->height = dc->lcevc.base_height;
1796
1797 ret = avctx->get_buffer2(avctx, frame_ctx->frame, 0);
1798 if (ret < 0) {
1799 av_refstruct_unref(&frame_ctx);
1800 return ret;
1801 }
1802
1803 validate_avframe_allocation(avctx, frame_ctx->frame);
1804
1805 fdd->post_process_opaque = frame_ctx;
1807 }
1808 dc->lcevc.frame = 0;
1809#endif
1810
1811 return 0;
1812}
1813
1815{
1816 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1817 int override_dimensions = 1;
1818 int ret;
1819
1821
1822 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1823 if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
1824 (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) {
1825 av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
1826 ret = AVERROR(EINVAL);
1827 goto fail;
1828 }
1829
1830 if (frame->width <= 0 || frame->height <= 0) {
1831 frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
1832 frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
1833 override_dimensions = 0;
1834 }
1835
1836 if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
1837 av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
1838 ret = AVERROR(EINVAL);
1839 goto fail;
1840 }
1841 } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1842 if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
1843 av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
1844 ret = AVERROR(EINVAL);
1845 goto fail;
1846 }
1847 }
1849 if (ret < 0)
1850 goto fail;
1851
1852 if (hwaccel) {
1853 if (hwaccel->alloc_frame) {
1854 ret = hwaccel->alloc_frame(avctx, frame);
1855 goto end;
1856 }
1857 } else {
1858 avctx->sw_pix_fmt = avctx->pix_fmt;
1859 }
1860
1861 ret = avctx->get_buffer2(avctx, frame, flags);
1862 if (ret < 0)
1863 goto fail;
1864
1866
1868 if (ret < 0)
1869 goto fail;
1870
1871end:
1872 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
1873 !(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_EXPORTS_CROPPING)) {
1874 frame->width = avctx->width;
1875 frame->height = avctx->height;
1876 }
1877
1878fail:
1879 if (ret < 0) {
1880 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1882 }
1883
1884 return ret;
1885}
1886
1888{
1889 int ret;
1890
1892
1893 // make sure the discard flag does not persist
1894 frame->flags &= ~AV_FRAME_FLAG_DISCARD;
1895
1896 if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1897 av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1898 frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1900 }
1901
1902 if (!frame->data[0])
1904
1905 av_frame_side_data_free(&frame->side_data, &frame->nb_side_data);
1906
1908 return ff_decode_frame_props(avctx, frame);
1909
1910 uint8_t *data[AV_VIDEO_MAX_PLANES];
1912 int linesize[AV_VIDEO_MAX_PLANES];
1913
1914 static_assert(AV_VIDEO_MAX_PLANES <= FF_ARRAY_ELEMS(frame->data) &&
1917 "Copying code needs to be adjusted");
1918 static_assert(sizeof(frame->linesize[0]) == sizeof(linesize[0]),
1919 "linesize needs to be switched to ptrdiff_t");
1920
1921 for (int i = 0; i < AV_VIDEO_MAX_PLANES; ++i) {
1922 data[i] = frame->data[i];
1923 linesize[i] = frame->linesize[i];
1924 buf[i] = frame->buf[i];
1925 frame->buf[i] = NULL;
1926 }
1927 av_assert1(!frame->buf[AV_VIDEO_MAX_PLANES] && !frame->extended_buf);
1928
1930
1932 if (ret >= 0) {
1933 av_image_copy2(frame->data, frame->linesize,
1934 data, linesize,
1935 frame->format, frame->width, frame->height);
1936 }
1937 for (int i = 0; i < AV_VIDEO_MAX_PLANES; ++i)
1938 av_buffer_unref(&buf[i]);
1939
1940 return ret;
1941}
1942
1944{
1945 int ret = reget_buffer_internal(avctx, frame, flags);
1946 if (ret < 0)
1947 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1948 return ret;
1949}
1950
1955
1957{
1958 av_assert1(!!f->f == !!f->progress);
1959 av_assert1(!f->progress || f->progress->f == f->f);
1960}
1961
1963{
1965
1966 av_assert1(!f->f && !f->progress);
1967
1968 f->progress = av_refstruct_pool_get(pool);
1969 if (!f->progress)
1970 return AVERROR(ENOMEM);
1971
1972 f->f = f->progress->f;
1973 return 0;
1974}
1975
1977{
1978 int ret = ff_progress_frame_alloc(avctx, f);
1979 if (ret < 0)
1980 return ret;
1981
1982 ret = ff_thread_get_buffer(avctx, f->progress->f, flags);
1983 if (ret < 0) {
1984 f->f = NULL;
1985 av_refstruct_unref(&f->progress);
1986 return ret;
1987 }
1988 return 0;
1989}
1990
1992{
1993 av_assert1(src->progress && src->f && src->f == src->progress->f);
1994 av_assert1(!dst->f && !dst->progress);
1995 dst->f = src->f;
1996 dst->progress = av_refstruct_ref(src->progress);
1997}
1998
2000{
2002 f->f = NULL;
2003 av_refstruct_unref(&f->progress);
2004}
2005
2007{
2008 if (dst == src)
2009 return;
2012 if (src->f)
2014}
2015
2017{
2018 ff_thread_progress_report(&f->progress->progress, n);
2019}
2020
2022{
2023 ff_thread_progress_await(&f->progress->progress, n);
2024}
2025
2026#if !HAVE_THREADS
2031#endif /* !HAVE_THREADS */
2032
2034{
2035 const AVCodecContext *avctx = opaque.nc;
2036 ProgressInternal *progress = obj;
2037 int ret;
2038
2040 if (ret < 0)
2041 return ret;
2042
2043 progress->f = av_frame_alloc();
2044 if (!progress->f)
2045 return AVERROR(ENOMEM);
2046
2047 return 0;
2048}
2049
2051{
2052 ProgressInternal *progress = obj;
2053
2055 av_frame_unref(progress->f);
2056}
2057
2059{
2060 ProgressInternal *progress = obj;
2061
2063 av_frame_free(&progress->f);
2064}
2065
2067{
2068 AVCodecInternal *avci = avctx->internal;
2069 DecodeContext *dc = decode_ctx(avci);
2070 int ret = 0;
2071
2075 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
2077 }
2078
2079 /* if the decoder init function was already called previously,
2080 * free the already allocated subtitle_header before overwriting it */
2081 av_freep(&avctx->subtitle_header);
2082
2083 if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
2084 av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
2085 avctx->codec->max_lowres);
2086 avctx->lowres = avctx->codec->max_lowres;
2087 }
2088 if (avctx->sub_charenc) {
2089 if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
2090 av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
2091 "supported with subtitles codecs\n");
2092 return AVERROR(EINVAL);
2093 } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
2094 av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
2095 "subtitles character encoding will be ignored\n",
2096 avctx->codec_descriptor->name);
2098 } else {
2099 /* input character encoding is set for a text based subtitle
2100 * codec at this point */
2103
2105#if CONFIG_ICONV
2106 iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
2107 if (cd == (iconv_t)-1) {
2108 ret = AVERROR(errno);
2109 av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
2110 "with input character encoding \"%s\"\n", avctx->sub_charenc);
2111 return ret;
2112 }
2113 iconv_close(cd);
2114#else
2115 av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
2116 "conversion needs a libavcodec built with iconv support "
2117 "for this codec\n");
2118 return AVERROR(ENOSYS);
2119#endif
2120 }
2121 }
2122 }
2123
2127 dc->pts_correction_last_dts = INT64_MIN;
2128
2129 if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
2131 av_log(avctx, AV_LOG_WARNING,
2132 "gray decoding requested but not enabled at configuration time\n");
2133 if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
2135 }
2136
2137 if (avctx->nb_side_data_prefer_packet == 1 &&
2138 avctx->side_data_prefer_packet[0] == -1)
2139 dc->side_data_pref_mask = ~0ULL;
2140 else {
2141 for (unsigned i = 0; i < avctx->nb_side_data_prefer_packet; i++) {
2142 int val = avctx->side_data_prefer_packet[i];
2143 int mapped = 0;
2144
2146 av_log(avctx, AV_LOG_ERROR, "Invalid side data type: %d\n", val);
2147 return AVERROR(EINVAL);
2148 }
2149
2150 for (unsigned j = 0; ff_sd_global_map[j].packet < AV_PKT_DATA_NB; j++) {
2151 if (ff_sd_global_map[j].packet == val) {
2152 mapped = 1;
2153 val = ff_sd_global_map[j].frame;
2154
2155 // this code will need to be changed when we have more than
2156 // 64 frame side data types
2157 if (val >= 64) {
2158 av_log(avctx, AV_LOG_ERROR, "Side data type too big\n");
2159 return AVERROR_BUG;
2160 }
2161
2162 dc->side_data_pref_mask |= 1ULL << val;
2163 }
2164 }
2165
2166 if (!mapped)
2167 av_log(avctx, AV_LOG_WARNING,
2168 "Side data type %s has no frame side data counterpart, "
2169 "ignoring it in side_data_prefer_packet\n",
2171 }
2172 }
2173
2174 avci->in_pkt = av_packet_alloc();
2176 if (!avci->in_pkt || !avci->last_pkt_props)
2177 return AVERROR(ENOMEM);
2178
2180 avci->progress_frame_pool =
2186 if (!avci->progress_frame_pool)
2187 return AVERROR(ENOMEM);
2188 }
2189 ret = decode_bsfs_init(avctx);
2190 if (ret < 0)
2191 return ret;
2192
2194 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
2195#if CONFIG_LIBLCEVC_DEC
2196 FFCodecContext *ffavc = ffcodeccontext(avctx);
2197 ret = ff_lcevc_alloc(&dc->lcevc.ctx, &ffavc->lcevc_params,
2199 if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
2200 return ret;
2201#endif
2202 }
2203 }
2204
2205 return 0;
2206}
2207
2208/**
2209 * Check side data preference and clear existing side data from frame
2210 * if needed.
2211 *
2212 * @retval 0 side data of this type can be added to frame
2213 * @retval 1 side data of this type should not be added to frame
2214 */
2215static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd,
2216 int *nb_sd, enum AVFrameSideDataType type)
2217{
2218 DecodeContext *dc = decode_ctx(avctx->internal);
2219
2220 // Note: could be skipped for `type` without corresponding packet sd
2221 if (av_frame_side_data_get(*sd, *nb_sd, type)) {
2222 if (dc->side_data_pref_mask & (1ULL << type))
2223 return 1;
2224 av_frame_side_data_remove(sd, nb_sd, type);
2225 }
2226
2227 return 0;
2228}
2229
2230
2232 enum AVFrameSideDataType type, size_t size,
2233 AVFrameSideData **psd)
2234{
2235 AVFrameSideData *sd;
2236
2237 if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, type)) {
2238 if (psd)
2239 *psd = NULL;
2240 return 0;
2241 }
2242
2244 if (psd)
2245 *psd = sd;
2246
2247 return sd ? 0 : AVERROR(ENOMEM);
2248}
2249
2251 AVFrameSideData ***sd, int *nb_sd,
2253 AVBufferRef **buf)
2254{
2255 int ret = 0;
2256
2257 if (side_data_pref(avctx, sd, nb_sd, type))
2258 goto finish;
2259
2260 if (!av_frame_side_data_add(sd, nb_sd, type, buf, 0))
2261 ret = AVERROR(ENOMEM);
2262
2263finish:
2265
2266 return ret;
2267}
2268
2271 AVBufferRef **buf)
2272{
2274 &frame->side_data, &frame->nb_side_data,
2275 type, buf);
2276}
2277
2279 AVFrameSideData ***sd, int *nb_sd,
2280 struct AVMasteringDisplayMetadata **mdm)
2281{
2283 size_t size;
2284
2286 *mdm = NULL;
2287 return 0;
2288 }
2289
2291 if (!*mdm)
2292 return AVERROR(ENOMEM);
2293
2294 buf = av_buffer_create((uint8_t *)*mdm, size, NULL, NULL, 0);
2295 if (!buf) {
2296 av_freep(mdm);
2297 return AVERROR(ENOMEM);
2298 }
2299
2301 &buf, 0)) {
2302 *mdm = NULL;
2304 return AVERROR(ENOMEM);
2305 }
2306
2307 return 0;
2308}
2309
2312{
2313 if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2315 *mdm = NULL;
2316 return 0;
2317 }
2318
2320 return *mdm ? 0 : AVERROR(ENOMEM);
2321}
2322
2324 AVFrameSideData ***sd, int *nb_sd,
2326{
2328 size_t size;
2329
2330 if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) {
2331 *clm = NULL;
2332 return 0;
2333 }
2334
2336 if (!*clm)
2337 return AVERROR(ENOMEM);
2338
2339 buf = av_buffer_create((uint8_t *)*clm, size, NULL, NULL, 0);
2340 if (!buf) {
2341 av_freep(clm);
2342 return AVERROR(ENOMEM);
2343 }
2344
2346 &buf, 0)) {
2347 *clm = NULL;
2349 return AVERROR(ENOMEM);
2350 }
2351
2352 return 0;
2353}
2354
2357{
2358 if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2360 *clm = NULL;
2361 return 0;
2362 }
2363
2365 return *clm ? 0 : AVERROR(ENOMEM);
2366}
2367
2368int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
2369{
2370 size_t size;
2372
2373 if (pal && size == AVPALETTE_SIZE) {
2374 memcpy(dst, pal, AVPALETTE_SIZE);
2375 return 1;
2376 } else if (pal) {
2377 av_log(logctx, AV_LOG_ERROR,
2378 "Palette size %zu is wrong\n", size);
2379 }
2380 return 0;
2381}
2382
2383int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
2384{
2385 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
2386
2387 if (!hwaccel || !hwaccel->frame_priv_data_size)
2388 return 0;
2389
2390 av_assert0(!*hwaccel_picture_private);
2391
2392 if (hwaccel->free_frame_priv) {
2393 AVHWDeviceContext *device_ctx = NULL;
2394
2395 if (avctx->hw_frames_ctx)
2396 device_ctx = ((AVHWFramesContext *)avctx->hw_frames_ctx->data)->device_ctx;
2397
2398 *hwaccel_picture_private = av_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,
2399 device_ctx,
2400 hwaccel->free_frame_priv);
2401 } else {
2402 *hwaccel_picture_private = av_refstruct_allocz(hwaccel->frame_priv_data_size);
2403 }
2404
2405 if (!*hwaccel_picture_private)
2406 return AVERROR(ENOMEM);
2407
2408 return 0;
2409}
2410
2412{
2413 AVCodecInternal *avci = avctx->internal;
2414 DecodeContext *dc = decode_ctx(avci);
2415
2417 av_packet_unref(avci->in_pkt);
2418
2422 dc->pts_correction_last_dts = INT64_MIN;
2423
2424 if (avci->bsf)
2425 av_bsf_flush(avci->bsf);
2426
2427 dc->nb_draining_errors = 0;
2428 dc->draining_started = 0;
2429}
2430
2435
2437{
2438 const DecodeContext *src_dc = decode_ctx(src->internal);
2439 DecodeContext *dst_dc = decode_ctx(dst->internal);
2440
2441 dst_dc->initial_pict_type = src_dc->initial_pict_type;
2442 dst_dc->intra_only_flag = src_dc->intra_only_flag;
2443 dst_dc->side_data_pref_mask = src_dc->side_data_pref_mask;
2444#if CONFIG_LIBLCEVC_DEC
2445 av_refstruct_replace(&dst_dc->lcevc.ctx, src_dc->lcevc.ctx);
2446 dst_dc->lcevc.width = src_dc->lcevc.width;
2447 dst_dc->lcevc.height = src_dc->lcevc.height;
2448 dst_dc->lcevc.format = src_dc->lcevc.format;
2449 dst_dc->lcevc.base_format = src_dc->lcevc.base_format;
2450#endif
2451}
2452
2454{
2455#if CONFIG_LIBLCEVC_DEC
2456 AVCodecInternal *avci = avctx->internal;
2457 DecodeContext *dc = decode_ctx(avci);
2458
2459 av_refstruct_unref(&dc->lcevc.ctx);
2460#endif
2461}
2462
2463static int attach_displaymatrix(AVCodecContext *avctx, AVFrame *frame, int orientation)
2464{
2465 AVFrameSideData *sd = NULL;
2466 int32_t *matrix;
2467 int ret;
2468 /* invalid orientation */
2469 if (orientation < 1 || orientation > 8)
2470 return AVERROR_INVALIDDATA;
2472 if (ret < 0) {
2473 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data: %s\n", av_err2str(ret));
2474 return ret;
2475 }
2476 if (sd) {
2477 matrix = (int32_t *) sd->data;
2479 }
2480
2481 return ret;
2482}
2483
2485{
2486 const AVExifEntry *orient = NULL;
2487 AVExifMetadata *cloned = NULL;
2488 int ret;
2489
2490 for (size_t i = 0; i < ifd->count; i++) {
2491 const AVExifEntry *entry = &ifd->entries[i];
2492 if (entry->id == av_exif_get_tag_id("Orientation") &&
2493 entry->count > 0 && entry->type == AV_TIFF_SHORT) {
2494 orient = entry;
2495 break;
2496 }
2497 }
2498
2499 if (orient) {
2500 av_log(avctx, AV_LOG_DEBUG, "found EXIF orientation: %" PRIu64 "\n", orient->value.uint[0]);
2501 ret = attach_displaymatrix(avctx, frame, orient->value.uint[0]);
2502 if (ret < 0) {
2503 av_log(avctx, AV_LOG_WARNING, "unable to attach displaymatrix from EXIF\n");
2504 } else {
2505 cloned = av_exif_clone_ifd(ifd);
2506 if (!cloned) {
2507 ret = AVERROR(ENOMEM);
2508 goto end;
2509 }
2510 av_exif_remove_entry(avctx, cloned, orient->id, 0);
2511 ifd = cloned;
2512 }
2513 }
2514
2515 ret = av_exif_ifd_to_dict(avctx, ifd, &frame->metadata);
2516 if (ret < 0)
2517 goto end;
2518
2519 if (cloned || !*pbuf) {
2520 av_buffer_unref(pbuf);
2521 ret = av_exif_write(avctx, ifd, pbuf, AV_EXIF_TIFF_HEADER);
2522 if (ret < 0)
2523 goto end;
2524 }
2525
2527 if (ret < 0)
2528 goto end;
2529
2530 ret = 0;
2531
2532end:
2533 av_buffer_unref(pbuf);
2534 av_exif_free(cloned);
2535 av_free(cloned);
2536 return ret;
2537}
2538
2540{
2542 return exif_attach_ifd(avctx, frame, ifd, &dummy);
2543}
2544
2546 enum AVExifHeaderMode header_mode)
2547{
2548 int ret;
2549 AVBufferRef *data = *pbuf;
2550 AVExifMetadata ifd = { 0 };
2551
2552 ret = av_exif_parse_buffer(avctx, data->data, data->size, &ifd, header_mode);
2553 if (ret < 0)
2554 goto end;
2555
2556 ret = exif_attach_ifd(avctx, frame, &ifd, pbuf);
2557
2558end:
2559 av_buffer_unref(pbuf);
2560 av_exif_free(&ifd);
2561 return ret;
2562}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static double val(void *priv, double ch)
Definition aeval.c:77
static const char *const format[]
Definition af_aiir.c:445
#define entry
static AVFormatContext * ctx
static void finish(void)
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
const SideDataMap ff_sd_global_map[]
A map between packet and frame side data types.
Definition avcodec.c:56
Libavcodec external API header.
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition avcodec.h:1600
#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:1735
#define FF_SUB_CHARENC_MODE_IGNORE
neither convert the subtitles, nor check them for valid UTF-8
Definition avcodec.h:1738
#define FF_SUB_CHARENC_MODE_AUTOMATIC
libavcodec will select the mode itself
Definition avcodec.h:1736
#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:1737
static av_always_inline FFCodecContext * ffcodeccontext(AVCodecContext *avctx)
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
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
Public libavutil channel layout APIs header.
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
@ FF_CODEC_CB_TYPE_DECODE_SUB
@ FF_CODEC_CB_TYPE_RECEIVE_FRAME
static av_always_inline const FFCodec * ffcodec(const AVCodec *codec)
#define FF_CODEC_CAP_SETS_FRAME_PROPS
Codec handles output frame properties internally instead of letting the internal logic derive them fr...
static int ff_codec_is_decoder(const AVCodec *avcodec)
Internal version of av_codec_is_decoder().
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Definition codec_par.c:138
common internal and external API header
#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:477
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define av_sat_sub64
Definition common.h:142
#define av_sat_add64
Definition common.h:139
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define min(a, b)
void ff_progress_frame_ref(ProgressFrame *dst, const ProgressFrame *src)
Set dst->f to src->f and make dst a co-owner of src->f.
Definition decode.c:1991
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is ...
Definition decode.c:2006
static int64_t guess_correct_pts(DecodeContext *dc, int64_t reordered_pts, int64_t dts)
Attempt to guess proper monotonic timestamps for decoded video frames which might have incorrect time...
Definition decode.c:297
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1814
static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type)
Check side data preference and clear existing side data from frame if needed.
Definition decode.c:2215
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
Definition decode.c:2269
void ff_progress_frame_await(const ProgressFrame *f, int n)
Wait for earlier decoding threads to finish reference frames.
Definition decode.c:2021
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
Definition decode.c:2016
static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f)
Definition decode.c:576
static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt, const AVPacket *inpkt, AVPacket *buf_pkt)
Definition decode.c:863
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition decode.c:1656
static int attach_displaymatrix(AVCodecContext *avctx, AVFrame *frame, int orientation)
Definition decode.c:2463
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:1943
enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset)
Allows to synchronize objects whose lifetime is the whole decoding process among all frame threads.
Definition decode.c:2027
static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
Definition decode.c:1557
int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame)
Definition decode.c:1753
const char * ff_decode_subtitle_text(AVCodecContext *avctx, const AVPacket *avpkt)
Get the data of a subtitle packet followed by a 0 byte.
Definition decode.c:943
static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
Definition decode.c:582
int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf)
Same as ff_frame_new_side_data_from_buf, but taking a AVFrameSideData array directly instead of an AV...
Definition decode.c:2250
int ff_decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
Do the actual decoding and obtain a decoded frame from the decoder, if available.
Definition decode.c:633
#define UTF8_MAX_BYTES
Definition decode.c:862
int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, AVContentLightMetadata **clm)
Wrapper around av_content_light_metadata_create_side_data(), which rejects side data overridden by th...
Definition decode.c:2355
const AVPacketSideData * ff_get_coded_side_data(const AVCodecContext *avctx, enum AVPacketSideDataType type)
Get side data of the given type from a decoding context.
Definition decode.c:1397
static int side_data_stereo3d_merge(AVFrameSideData *sd_frame, const AVPacketSideData *sd_pkt)
Definition decode.c:1403
static const AVPacketSideData * packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Definition decode.c:1387
static av_cold void progress_frame_pool_free_entry_cb(AVRefStructOpaque opaque, void *obj)
Definition decode.c:2058
static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame, unsigned flags)
Definition decode.c:669
int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, AVMasteringDisplayMetadata **mdm)
Wrapper around av_mastering_display_metadata_create_side_data(), which rejects side data overridden b...
Definition decode.c:2310
static int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition decode.c:435
int ff_decode_exif_attach_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferRef **pbuf, enum AVExifHeaderMode header_mode)
Attach the data buffer to the frame.
Definition decode.c:2545
int ff_decode_exif_attach_ifd(AVCodecContext *avctx, AVFrame *frame, const AVExifMetadata *ifd)
Definition decode.c:2539
static int side_data_exif_parse(AVFrame *dst, const AVPacketSideData *sd_pkt)
Definition decode.c:1439
static void decode_data_free(AVRefStructOpaque unused, void *obj)
Definition decode.c:1740
static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition decode.c:617
static int decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition decode.c:230
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition decode.c:255
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition decode.c:1248
static void check_progress_consistency(const ProgressFrame *f)
Definition decode.c:1956
int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, struct AVMasteringDisplayMetadata **mdm)
Same as ff_decode_mastering_display_new, but taking a AVFrameSideData array directly instead of an AV...
Definition decode.c:2278
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:2368
static void get_subtitle_defaults(AVSubtitle *sub)
Definition decode.c:856
static int side_data_map(AVFrame *dst, const AVPacketSideData *sd_src, int nb_sd_src, const SideDataMap *map)
Definition decode.c:1511
int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt)
Set various frame properties from the provided packet.
Definition decode.c:1569
av_cold void ff_decode_flush_buffers(AVCodecContext *avctx)
Definition decode.c:2411
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
Definition decode.c:2383
static int decode_bsfs_init(AVCodecContext *avctx)
Definition decode.c:190
int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame, unsigned flags)
avcodec_receive_frame() implementation for decoders.
Definition decode.c:825
static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
Definition decode.c:323
static void progress_frame_pool_reset_cb(AVRefStructOpaque unused, void *obj)
Definition decode.c:2050
static int hwaccel_init(AVCodecContext *avctx, const FFHWAccel *hwaccel)
Definition decode.c:1201
av_cold void ff_decode_internal_uninit(AVCodecContext *avctx)
Definition decode.c:2453
av_cold int ff_decode_preinit(AVCodecContext *avctx)
Perform decoder initialization and validation.
Definition decode.c:2066
static DecodeContext * decode_ctx(AVCodecInternal *avci)
Definition decode.c:113
static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
Definition decode.c:118
static int frame_validate(AVCodecContext *avctx, AVFrame *frame)
Definition decode.c:799
static int exif_attach_ifd(AVCodecContext *avctx, AVFrame *frame, const AVExifMetadata *ifd, AVBufferRef **pbuf)
Definition decode.c:2484
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition decode.c:1887
static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
Definition decode.c:771
av_cold AVCodecInternal * ff_decode_internal_alloc(void)
Definition decode.c:2431
int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f)
This function sets up the ProgressFrame, i.e.
Definition decode.c:1962
void ff_hwaccel_uninit(AVCodecContext *avctx)
Definition decode.c:1236
static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
Definition decode.c:1719
static av_cold int progress_frame_pool_init_cb(AVRefStructOpaque opaque, void *obj)
Definition decode.c:2033
av_cold void ff_decode_internal_sync(AVCodecContext *dst, const AVCodecContext *src)
Definition decode.c:2436
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
Wrapper around ff_progress_frame_alloc() and ff_thread_get_buffer().
Definition decode.c:1976
int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, size_t size, AVFrameSideData **psd)
Wrapper around av_frame_new_side_data, which rejects side data overridden by the demuxer.
Definition decode.c:2231
int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx, enum AVHWDeviceType dev_type)
Make sure avctx.hw_frames_ctx is set.
Definition decode.c:1088
static int utf8_check(const uint8_t *str)
Definition decode.c:924
#define ff_thread_get_packet(avctx, pkt)
Definition decode.c:226
static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
Definition decode.c:179
void ff_progress_frame_unref(ProgressFrame *f)
Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame,...
Definition decode.c:1999
#define ff_thread_receive_frame(avctx, frame, flags)
Definition decode.c:227
int ff_decode_content_light_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, AVContentLightMetadata **clm)
Same as ff_decode_content_light_new, but taking a AVFrameSideData array directly instead of an AVFram...
Definition decode.c:2323
#define FF_REGET_BUFFER_FLAG_READONLY
the returned buffer does not need to be writable
Definition decode.h:148
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition defs.h:62
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition defs.h:51
static AVPacket * pkt
static AVFrame * frame
#define emms_c()
Definition emms.h:88
int av_exif_get_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int flags, AVExifEntry **value)
Get an entry with the tagged ID from the EXIF metadata struct.
Definition exif.c:1203
int av_exif_parse_buffer(void *logctx, const uint8_t *buf, size_t size, AVExifMetadata *ifd, enum AVExifHeaderMode header_mode)
Decodes the EXIF data provided in the buffer and writes it into the struct *ifd.
Definition exif.c:901
int av_exif_ifd_to_dict(void *logctx, const AVExifMetadata *ifd, AVDictionary **metadata)
Recursively reads all tags from the IFD and stores them in the provided metadata dictionary.
Definition exif.c:1083
void av_exif_free(AVExifMetadata *ifd)
Frees all resources associated with the given EXIF metadata struct.
Definition exif.c:678
int av_exif_orientation_to_matrix(int32_t *matrix, int orientation)
Convert an orientation constant used by EXIF's orientation tag into a display matrix used by AV_FRAME...
Definition exif.c:1356
AVExifMetadata * av_exif_clone_ifd(const AVExifMetadata *ifd)
Allocates a duplicate of the provided EXIF metadata struct.
Definition exif.c:1307
int av_exif_write(void *logctx, const AVExifMetadata *ifd, AVBufferRef **buffer, enum AVExifHeaderMode header_mode)
Allocates a buffer using av_malloc of an appropriate size and writes the EXIF data represented by ifd...
Definition exif.c:772
int32_t av_exif_get_tag_id(const char *name)
Retrieves the tag ID associated with the provided tag string name.
Definition exif.c:245
int av_exif_remove_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int flags)
Remove an entry from the provided EXIF metadata struct.
Definition exif.c:1302
EXIF metadata parser.
@ AV_TIFF_SHORT
Definition exif.h:44
AVExifHeaderMode
Definition exif.h:57
@ AV_EXIF_TIFF_HEADER
The TIFF header starts with 0x49492a00, or 0x4d4d002a.
Definition exif.h:62
EXIF metadata parser - internal functions.
static const char * hwaccel
Definition ffplay.c:406
int ret
Definition ffplay.c:391
static int dummy
Definition ffplay.c:4428
reference-counted frame API
#define fail
Definition test.h:479
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:47
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition bsf.c:147
void av_bsf_flush(AVBSFContext *ctx)
Reset the internal bitstream filter state.
Definition bsf.c:188
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition bsf.c:228
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition bsf.c:200
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:524
#define AV_CODEC_FLAG2_ICC_PROFILES
Generate/parse ICC profiles on encode/decode, as appropriate for the type of file.
Definition avcodec.h:382
#define AV_CODEC_FLAG2_EXPORT_MVS
Export motion vectors through frame side data.
Definition avcodec.h:368
#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:79
#define AV_CODEC_EXPORT_DATA_ENHANCEMENTS
Decoding only.
Definition avcodec.h:410
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition avcodec.h:415
int av_codec_is_decoder(const AVCodec *codec)
Definition utils.c:85
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
Definition codec_desc.h:72
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition avcodec.h:302
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition avcodec.c:419
#define AV_CODEC_FLAG_UNALIGNED
Allow decoders to produce frames with data planes that are not aligned to CPU requirements (e....
Definition avcodec.h:209
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
Definition utils.c:868
#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:111
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
Definition avcodec.h:390
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition codec.h:106
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition codec_desc.h:116
#define AV_CODEC_FLAG2_SKIP_MANUAL
Do not skip samples and export skip information as frame side data.
Definition avcodec.h:372
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition avcodec.h:279
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition codec.h:311
@ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
Definition codec.h:295
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition codec.h:282
@ AV_CODEC_HW_CONFIG_METHOD_INTERNAL
The codec supports this format by some internal method.
Definition codec.h:302
int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition decode.c:738
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
Definition decode.c:955
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:1139
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
#define AV_HWACCEL_CODEC_CAP_EXPERIMENTAL
HWAccel is experimental and is thus avoided in favor of non experimental codecs.
Definition avcodec.h:2008
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Definition decode.c:1025
int avcodec_is_open(AVCodecContext *s)
Definition avcodec.c:700
const char * av_packet_side_data_name(enum AVPacketSideDataType type)
Definition packet.c:269
AVPacketSideDataType
Definition packet.h:41
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
Definition packet.h:169
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
Definition packet.h:288
@ AV_PKT_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
Definition packet.h:153
@ AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM
IAMF Recon Gain Info Parameter Data associated with the audio frame.
Definition packet.h:320
@ AV_PKT_DATA_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
Definition packet.h:296
@ AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
IAMF Demixing Info Parameter Data associated with the audio frame.
Definition packet.h:312
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition packet.h:239
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition packet.h:47
@ AV_PKT_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
HDR dynamic metadata associated with a video frame.
Definition packet.h:376
@ AV_PKT_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition packet.h:258
@ AV_PKT_DATA_EXIF
Extensible image file format metadata.
Definition packet.h:369
@ AV_PKT_DATA_NB
The number of side data types.
Definition packet.h:401
@ AV_PKT_DATA_PARAM_CHANGE
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition packet.h:69
@ AV_PKT_DATA_LCEVC
Raw LCEVC payload data, as a uint8_t array, with NAL emulation bytes intact.
Definition packet.h:346
@ AV_PKT_DATA_IAMF_MIX_GAIN_PARAM
IAMF Mix Gain Parameter Data associated with the audio frame.
Definition packet.h:304
#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:664
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:435
int av_packet_unpack_dictionary(const uint8_t *data, size_t size, AVDictionary **dict)
Unpack a dictionary from side_data.
Definition packet.c:355
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition packet.c:252
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition packet.c:63
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition packet.c:443
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
Definition packet.c:398
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
Definition packet.h:688
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition packet.h:689
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
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:140
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition buffer.c:234
int av_buffer_make_writable(AVBufferRef **pbuf)
Create a writable reference from a given buffer reference, avoiding data copy if possible.
Definition buffer.c:166
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:56
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_DISCARD
A flag to mark the frames which need to be decoded, but shouldn't be output.
Definition frame.h:698
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition frame.h:694
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:499
AVFrameSideData * av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, size_t size, unsigned int flags)
Add new side data entry to an array.
Definition side_data.c:205
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:662
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition frame.c:728
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
Definition side_data.c:140
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition frame.c:538
AVFrameSideData * av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf, unsigned int flags)
Add a new side data entry to an array from an existing AVBufferRef.
Definition side_data.c:230
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition frame.c:526
void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type from an array.
Definition side_data.c:109
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
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:650
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:53
int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags)
Add a new side data entry to an array based on existing side data, taking a reference towards the con...
Definition side_data.c:255
AVFrameSideDataType
Definition frame.h:49
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:763
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
Definition frame.h:1206
@ AV_FRAME_CROP_UNALIGNED
Apply the maximum possible cropping, even if it requires setting the AVFrame.data[] entries to unalig...
Definition frame.h:1057
@ AV_FRAME_DATA_EXIF
Exchangeable image file format metadata.
Definition frame.h:263
@ AV_FRAME_DATA_LCEVC
Raw LCEVC payload data, as a uint8_t array, with NAL emulation bytes intact.
Definition frame.h:236
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition frame.h:137
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition frame.h:85
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition frame.h:59
@ AV_FRAME_DATA_DYNAMIC_HDR_PLUS
HDR dynamic metadata associated with a video frame.
Definition frame.h:159
@ AV_FRAME_DATA_IAMF_RECON_GAIN_INFO_PARAM
IAMF Recon Gain Info Parameter Data associated with the audio frame.
Definition frame.h:294
@ AV_FRAME_DATA_IAMF_MIX_GAIN_PARAM
IAMF Mix Gain Parameter Data associated with the audio frame.
Definition frame.h:278
@ AV_FRAME_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
Definition frame.h:109
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition frame.h:120
@ AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
HDR dynamic metadata associated with a video frame.
Definition frame.h:270
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition frame.h:144
@ AV_FRAME_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition frame.h:90
@ AV_FRAME_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1.
Definition frame.h:152
@ AV_FRAME_DATA_IAMF_DEMIXING_INFO_PARAM
IAMF Demixing Info Parameter Data associated with the audio frame.
Definition frame.h:286
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
Definition frame.h:64
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_log_get_level(void)
Get the current log level.
Definition log.c:477
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:115
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition mem.c:408
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition imgutils.h:184
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
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
AVPictureType
Definition avutil.h:276
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_NONE
Undefined.
Definition avutil.h:277
@ AV_SAMPLE_FMT_NONE
Definition samplefmt.h:56
int av_samples_copy(uint8_t *const *dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Definition samplefmt.c:223
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
@ AV_STEREO3D_UNSPEC
Video is stereoscopic but the packing is unspecified.
Definition stereo3d.h:143
@ AV_PRIMARY_EYE_NONE
Neither eye.
Definition stereo3d.h:178
@ AV_STEREO3D_VIEW_UNSPEC
Content is unspecified.
Definition stereo3d.h:168
static enum AVPixelFormat hw_pix_fmt
Definition hw_decode.c:46
#define FF_HW_HAS_CB(avctx, function)
#define FF_HW_SIMPLE_CALL(avctx, function)
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition hwcontext.c:121
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition hwcontext.c:347
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition hwcontext.c:267
AVHWDeviceType
Definition hwcontext.h:27
const VDPAUPixFmtMap * map
misc image utilities
#define AV_WL8(p, d)
#define AV_RL8(x)
#define AV_WL32(p, v)
#define AV_RL32(p)
enum MPFType type
Definition jpegmpfenc.c:55
static av_cold void uninit(AVBitStreamFilterContext *ctx)
unsigned offset
Definition libaomenc.c:763
int ff_icc_profile_sanitize(FFIccContext *s, cmsHPROFILE profile)
Sanitize an ICC profile to try and fix badly broken values.
Definition fflcms2.c:212
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:254
int ff_icc_context_init(FFIccContext *s, void *avctx)
Initializes an FFIccContext.
Definition fflcms2.c:30
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:301
common internal api header.
#define STRIDE_ALIGN
Definition internal.h:46
int ff_lcevc_parse_frame(FFLCEVCContext *lcevc, const AVFrame *frame, enum AVPixelFormat *format, enum AVPixelFormat *base_format, int *width, int *height)
Definition lcevcdec.c:516
int ff_lcevc_process(void *logctx, AVFrame *frame)
Definition lcevcdec.c:486
int ff_lcevc_alloc(FFLCEVCContext **plcevc, AVDictionary **options, int loglevel)
Definition lcevcdec.c:592
#define AVPACKET_IS_EMPTY(pkt)
Multithreading API for decoders.
ThreadingStatus
Definition thread.h:60
@ FF_THREAD_NO_FRAME_THREADING
Definition thread.h:63
#define av_unused
Definition attributes.h:164
#define av_cold
Definition attributes.h:117
common internal API header
#define attribute_align_arg
Definition internal.h:51
Stereoscopic video.
const char * desc
Definition libsvtav1.c:83
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
AVContentLightMetadata * av_content_light_metadata_alloc(size_t *size)
Allocate an AVContentLightMetadata structure and set its fields to default values.
AVContentLightMetadata * av_content_light_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVContentLightMetadata and add it to the frame.
AVMasteringDisplayMetadata * av_mastering_display_metadata_alloc_size(size_t *size)
Allocate an AVMasteringDisplayMetadata structure and set its fields to default values.
AVMasteringDisplayMetadata * av_mastering_display_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVMasteringDisplayMetadata and add it to the frame.
Memory handling functions.
static const char * obj
Definition mscl.c:57
const char data[16]
Definition mxf.c:149
int profile
Definition mxfenc.c:2300
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3524
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:3404
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition pixdesc.h:128
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition pixdesc.h:120
@ AVCHROMA_LOC_UNSPECIFIED
Definition pixfmt.h:812
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:758
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
Definition pixfmt.h:826
#define AV_VIDEO_MAX_PLANES
Maximum number of planes in any pixel format.
Definition pixfmt.h:40
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
#define AVPALETTE_SIZE
Definition pixfmt.h:32
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition pixfmt.h:647
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:650
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition pixfmt.h:677
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:680
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:714
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:121
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition refstruct.c:161
void * av_refstruct_pool_get(AVRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
Definition refstruct.c:315
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition refstruct.c:141
#define AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR
If this flag is set and both init_cb and free_entry_cb callbacks are provided, then free_cb will be c...
Definition refstruct.h:213
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition refstruct.h:105
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition refstruct.h:94
static AVRefStructPool * av_refstruct_pool_alloc_ext(size_t size, unsigned flags, void *opaque, int(*init_cb)(AVRefStructOpaque opaque, void *obj), void(*reset_cb)(AVRefStructOpaque opaque, void *obj), void(*free_entry_cb)(AVRefStructOpaque opaque, void *obj), void(*free_cb)(AVRefStructOpaque opaque))
A wrapper around av_refstruct_pool_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition refstruct.h:258
#define FF_ARRAY_ELEMS(a)
AVCodecParameters * par_in
Parameters of the input stream.
Definition bsf.h:90
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition bsf.h:102
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
int nb_channels
Number of channels in this layout.
main external API structure.
Definition avcodec.h:443
int * side_data_prefer_packet
Decoding only.
Definition avcodec.h:1923
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:644
int width
picture width / height.
Definition avcodec.h:605
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
Definition avcodec.h:1778
const struct AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition avcodec.h:1719
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1059
int flags2
AV_CODEC_FLAG2_*.
Definition avcodec.h:507
enum AVSampleFormat sample_fmt
audio sample format
Definition avcodec.h:1051
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:651
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition avcodec.h:1797
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:685
char * sub_charenc
Character encoding of the input subtitles file.
Definition avcodec.h:1726
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition avcodec.h:1381
int nb_coded_side_data
Definition avcodec.h:1779
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition avcodec.h:554
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Callback to negotiate the pixel format.
Definition avcodec.h:777
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:658
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition avcodec.h:1477
enum AVMediaType codec_type
Definition avcodec.h:451
int64_t frame_num
Frame counter, set by libavcodec.
Definition avcodec.h:1893
int apply_cropping
Video decoding only.
Definition avcodec.h:1824
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:629
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition avcodec.h:1429
int active_thread_type
Which multithreading methods are in use by the codec.
Definition avcodec.h:1608
int sub_charenc_mode
Subtitles character encoding mode.
Definition avcodec.h:1734
const struct AVCodec * codec
Definition avcodec.h:452
int log_level_offset
Definition avcodec.h:449
int nb_decoded_side_data
Definition avcodec.h:1940
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1581
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition avcodec.h:1789
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:672
int sample_rate
samples per second
Definition avcodec.h:1044
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition avcodec.h:1589
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:665
uint8_t * subtitle_header
Definition avcodec.h:1754
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition avcodec.h:1939
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition avcodec.h:692
enum AVAlphaMode alpha_mode
Indicates how the alpha channel of the video is represented.
Definition avcodec.h:1947
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition avcodec.h:1499
int extra_hw_frames
Video decoding only.
Definition avcodec.h:1522
unsigned nb_side_data_prefer_packet
Number of entries in side_data_prefer_packet.
Definition avcodec.h:1927
int64_t max_samples
The number of samples per frame to maximally accept.
Definition avcodec.h:1840
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition avcodec.h:620
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:1223
struct AVCodecInternal * internal
Private context used for internal data.
Definition avcodec.h:478
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition avcodec.h:1712
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition avcodec.h:1422
const char * name
Name of the codec described by this descriptor.
Definition codec_desc.h:46
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition codec_desc.h:54
enum AVMediaType type
Definition codec_desc.h:40
const struct FFHWAccel * hwaccel
If this configuration uses a hwaccel, a pointer to it.
Definition hwconfig.h:35
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition hwconfig.h:30
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:323
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
Definition internal.h:83
AVPacket * last_pkt_props
Properties (timestamps+side data) extracted from the last packet passed for decoding.
Definition internal.h:90
int is_frame_mt
This field is set to 1 when frame threading is being used and the parent AVCodecContext of this AVCod...
Definition internal.h:61
void * hwaccel_priv_data
hwaccel-specific private data
Definition internal.h:130
AVFrame * buffer_frame
Definition internal.h:145
AVPacket * buffer_pkt
Temporary buffers for newly received or not yet output packets/frames.
Definition internal.h:144
int draining
decoding: AVERROR_EOF has been returned from ff_decode_get_packet(); must not be used by decoders tha...
Definition internal.h:139
struct AVRefStructPool * progress_frame_pool
Definition internal.h:71
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
Definition internal.h:125
struct AVBSFContext * bsf
Definition internal.h:84
enum AVMediaType type
Definition codec.h:188
int capabilities
Codec capabilities.
Definition codec.h:194
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition codec.h:195
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition csp.h:78
int depth
Number of bits in the component.
Definition pixdesc.h:57
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
uint16_t id
Definition exif.h:85
union AVExifEntry::@325220332140161067313112036135003363017341144014 value
uint64_t * uint
Definition exif.h:108
unsigned int count
Definition exif.h:79
AVExifEntry * entries
Definition exif.h:77
Structure to hold side data for an AVFrame.
Definition frame.h:334
size_t size
Definition frame.h:337
uint8_t * data
Definition frame.h:336
AVBufferRef * buf
Definition frame.h:339
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
int width
Definition frame.h:551
void * opaque
Frame owner's private data.
Definition frame.h:617
int height
Definition frame.h:551
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition frame.h:656
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:566
const char * name
Name of the hardware accelerated codec.
Definition avcodec.h:1974
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition avcodec.h:1995
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition hwcontext.h:75
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition hwcontext.h:200
int initial_pool_size
Initial size of the frame pool.
Definition hwcontext.h:190
Mastering display metadata capable of representing the color volume of the display used to master the...
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition packet.h:431
uint8_t * data
Definition packet.h:432
This structure stores compressed data.
Definition packet.h:587
int size
Definition packet.h:611
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition packet.h:628
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition packet.h:603
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition packet.h:609
uint8_t * data
Definition packet.h:610
int side_data_elems
Definition packet.h:622
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition refstruct.c:184
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition stereo3d.h:203
char * ass
0 terminated ASS/SSA compatible event line.
Definition avcodec.h:2104
uint16_t format
Definition avcodec.h:2108
uint32_t end_display_time
Definition avcodec.h:2110
unsigned num_rects
Definition avcodec.h:2111
AVSubtitleRect ** rects
Definition avcodec.h:2112
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition avcodec.h:2113
enum AVPictureType initial_pict_type
This is set to AV_PICTURE_TYPE_I for intra only video decoders and to AV_PICTURE_TYPE_NONE for other ...
Definition decode.c:78
uint64_t side_data_pref_mask
DTS of the last frame.
Definition decode.c:97
int64_t pts_correction_last_dts
PTS of the last frame.
Definition decode.c:91
int nb_draining_errors
Definition decode.c:81
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition decode.c:89
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition decode.c:90
int draining_started
The caller has submitted a NULL packet on input.
Definition decode.c:86
int intra_only_flag
This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats (those whose codec descriptor has...
Definition decode.c:71
AVCodecInternal avci
Definition decode.c:64
int64_t pts_correction_num_faulty_pts
Definition decode.c:88
AVFrame * frame
struct AVDictionary * lcevc_params
int(* receive_frame)(struct AVCodecContext *avctx, struct AVFrame *frame)
Decode API with decoupled packet/frame dataflow.
const struct AVCodecHWConfigInternal *const * hw_configs
Array of pointers to hardware configurations supported by the codec, or NULL if no hardware supported...
unsigned cb_type
This field determines the type of the codec (decoder/encoder) and also the exact callback cb implemen...
const char * bsfs
Decoding only, a comma-separated list of bitstream filters to apply to packets before decoding.
int(* decode_sub)(struct AVCodecContext *avctx, struct AVSubtitle *sub, int *got_frame_ptr, const struct AVPacket *avpkt)
Decode subtitle data to an AVSubtitle.
int(* decode)(struct AVCodecContext *avctx, struct AVFrame *frame, int *got_frame_ptr, struct AVPacket *avpkt)
Decode to an AVFrame.
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
union FFCodec::@344166142000117327246261075357045351044045072174 cb
int priv_data_size
Size of the private data to allocate in AVCodecInternal.hwaccel_priv_data.
AVHWAccel p
The public AVHWAccel.
int(* frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Fill the given hw_frames context with current codec parameters.
FFLCEVCContext * lcevc
Definition lcevcdec.h:62
struct AVFrame * frame
Definition lcevcdec.h:63
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition decode.h:33
void(* hwaccel_priv_free)(void *priv)
Definition decode.h:55
int(* hwaccel_priv_post_process)(void *logctx, AVFrame *frame)
Per-frame private data for hwaccels.
Definition decode.h:53
void * post_process_opaque
RefStruct reference.
Definition decode.h:45
void * hwaccel_priv
Definition decode.h:54
int(* post_process)(void *logctx, AVFrame *frame)
The callback to perform some delayed processing on the frame right before it is returned to the calle...
Definition decode.h:44
The ProgressFrame structure.
ThreadProgress progress
Definition decode.c:1952
struct AVFrame * f
Definition decode.c:1953
ThreadProgress is an API to easily notify other threads about progress of any kind as long as it can ...
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99
av_cold void ff_thread_progress_destroy(ThreadProgress *pro)
Destroy a ThreadProgress.
av_cold int ff_thread_progress_init(ThreadProgress *pro, int init_mode)
Initialize a ThreadProgress.
void ff_thread_progress_report(ThreadProgress *pro, int n)
This function is a no-op in no-op mode; otherwise it notifies other threads that a certain level of p...
void ff_thread_progress_await(const ThreadProgress *pro_c, int n)
This function is a no-op in no-op mode; otherwise it waits until other threads have reached a certain...
static void ff_thread_progress_reset(ThreadProgress *pro)
Reset the ThreadProgress.progress counter; must only be called if the ThreadProgress is not in use in...
static int64_t pts
int size
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition refstruct.h:58
static void copy(const float *p1, float *p2, const int length)
static double c[64]