FFmpeg
Data Structures | Macros | Functions
decode.c File Reference
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "config.h"
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/emms.h"
#include "libavutil/frame.h"
#include "libavutil/hwcontext.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/mastering_display_metadata.h"
#include "libavutil/mem.h"
#include "libavutil/stereo3d.h"
#include "avcodec.h"
#include "avcodec_internal.h"
#include "bytestream.h"
#include "bsf.h"
#include "codec_desc.h"
#include "codec_internal.h"
#include "decode.h"
#include "hwaccel_internal.h"
#include "hwconfig.h"
#include "internal.h"
#include "lcevcdec.h"
#include "packet_internal.h"
#include "progressframe.h"
#include "libavutil/refstruct.h"
#include "thread.h"
#include "threadprogress.h"

Go to the source code of this file.

Data Structures

struct  DecodeContext
 
struct  ProgressInternal
 

Macros

#define ff_thread_get_packet(avctx, pkt)   (AVERROR_BUG)
 
#define ff_thread_receive_frame(avctx, frame)   (AVERROR_BUG)
 
#define UTF8_MAX_BYTES   4 /* 5 and 6 bytes sequences should not be used */
 

Functions

static DecodeContextdecode_ctx (AVCodecInternal *avci)
 
static int apply_param_change (AVCodecContext *avctx, const AVPacket *avpkt)
 
static int extract_packet_props (AVCodecInternal *avci, const AVPacket *pkt)
 
static int decode_bsfs_init (AVCodecContext *avctx)
 
static int decode_get_packet (AVCodecContext *avctx, AVPacket *pkt)
 
int ff_decode_get_packet (AVCodecContext *avctx, AVPacket *pkt)
 Called by decoders to get the next packet for decoding. More...
 
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 times. More...
 
static int discard_samples (AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
 
static int decode_simple_internal (AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
 
static int detect_colorspace (av_unused AVCodecContext *c, av_unused AVFrame *f)
 
static int fill_frame_props (const AVCodecContext *avctx, AVFrame *frame)
 
static int decode_simple_receive_frame (AVCodecContext *avctx, AVFrame *frame)
 
int ff_decode_receive_frame_internal (AVCodecContext *avctx, AVFrame *frame)
 Do the actual decoding and obtain a decoded frame from the decoder, if available. More...
 
static int decode_receive_frame_internal (AVCodecContext *avctx, AVFrame *frame)
 
int attribute_align_arg avcodec_send_packet (AVCodecContext *avctx, const AVPacket *avpkt)
 Supply raw packet data as input to a decoder. More...
 
static int apply_cropping (AVCodecContext *avctx, AVFrame *frame)
 
static int frame_validate (AVCodecContext *avctx, AVFrame *frame)
 
int ff_decode_receive_frame (AVCodecContext *avctx, AVFrame *frame)
 avcodec_receive_frame() implementation for decoders. More...
 
static void get_subtitle_defaults (AVSubtitle *sub)
 
static int recode_subtitle (AVCodecContext *avctx, const AVPacket **outpkt, const AVPacket *inpkt, AVPacket *buf_pkt)
 
static int utf8_check (const uint8_t *str)
 
int avcodec_decode_subtitle2 (AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
 Decode a subtitle message. More...
 
enum AVPixelFormat avcodec_default_get_format (struct AVCodecContext *avctx, const enum AVPixelFormat *fmt)
 
int ff_decode_get_hw_frames_ctx (AVCodecContext *avctx, enum AVHWDeviceType dev_type)
 Make sure avctx.hw_frames_ctx is set. More...
 
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. More...
 
static int hwaccel_init (AVCodecContext *avctx, const FFHWAccel *hwaccel)
 
void ff_hwaccel_uninit (AVCodecContext *avctx)
 
int ff_get_format (AVCodecContext *avctx, const enum AVPixelFormat *fmt)
 Select the (possibly hardware accelerated) pixel format. More...
 
static const AVPacketSideDatapacket_side_data_get (const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
 
const AVPacketSideDataff_get_coded_side_data (const AVCodecContext *avctx, enum AVPacketSideDataType type)
 Get side data of the given type from a decoding context. More...
 
static int side_data_stereo3d_merge (AVFrameSideData *sd_frame, const AVPacketSideData *sd_pkt)
 
static int side_data_map (AVFrame *dst, const AVPacketSideData *sd_src, int nb_sd_src, const SideDataMap *map)
 
static int add_metadata_from_side_data (const AVPacket *avpkt, AVFrame *frame)
 
int ff_decode_frame_props_from_pkt (const AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt)
 Set various frame properties from the provided packet. More...
 
int ff_decode_frame_props (AVCodecContext *avctx, AVFrame *frame)
 Set various frame properties from the codec context / packet data. More...
 
static void validate_avframe_allocation (AVCodecContext *avctx, AVFrame *frame)
 
static void decode_data_free (void *opaque, uint8_t *data)
 
int ff_attach_decode_data (AVFrame *frame)
 
static void update_frame_props (AVCodecContext *avctx, AVFrame *frame)
 
static void attach_post_process_data (AVCodecContext *avctx, AVFrame *frame)
 
int ff_get_buffer (AVCodecContext *avctx, AVFrame *frame, int flags)
 Get a buffer for a frame. More...
 
static int reget_buffer_internal (AVCodecContext *avctx, AVFrame *frame, int flags)
 
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. More...
 
static void check_progress_consistency (const ProgressFrame *f)
 
int ff_progress_frame_alloc (AVCodecContext *avctx, ProgressFrame *f)
 This function allocates ProgressFrame.f May be called before ff_progress_frame_get_buffer() in the cases where the AVFrame needs to be accessed before the ff_thread_get_buffer() call in ff_progress_frame_alloc(). More...
 
int ff_progress_frame_get_buffer (AVCodecContext *avctx, ProgressFrame *f, int flags)
 This function sets up the ProgressFrame, i.e. More...
 
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. More...
 
void ff_progress_frame_unref (ProgressFrame *f)
 Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame, setting all pointers to NULL. More...
 
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 not blank, put a reference to src's AVFrame in its place (in case src is not blank). More...
 
void ff_progress_frame_report (ProgressFrame *f, int n)
 Notify later decoding threads when part of their reference frame is ready. More...
 
void ff_progress_frame_await (const ProgressFrame *f, int n)
 Wait for earlier decoding threads to finish reference frames. More...
 
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. More...
 
static av_cold int progress_frame_pool_init_cb (AVRefStructOpaque opaque, void *obj)
 
static void progress_frame_pool_reset_cb (AVRefStructOpaque unused, void *obj)
 
static av_cold void progress_frame_pool_free_entry_cb (AVRefStructOpaque opaque, void *obj)
 
int ff_decode_preinit (AVCodecContext *avctx)
 Perform decoder initialization and validation. More...
 
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. More...
 
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. More...
 
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 AVFrame. More...
 
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. More...
 
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 AVFrame. More...
 
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 by the demuxer. More...
 
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 AVFrame. More...
 
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 the demuxer. More...
 
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, copy it to dst and return 1; else return 0. More...
 
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. More...
 
void ff_decode_flush_buffers (AVCodecContext *avctx)
 
AVCodecInternalff_decode_internal_alloc (void)
 
void ff_decode_internal_sync (AVCodecContext *dst, const AVCodecContext *src)
 
void ff_decode_internal_uninit (AVCodecContext *avctx)
 

Macro Definition Documentation

◆ ff_thread_get_packet

#define ff_thread_get_packet (   avctx,
  pkt 
)    (AVERROR_BUG)

Definition at line 219 of file decode.c.

◆ ff_thread_receive_frame

#define ff_thread_receive_frame (   avctx,
  frame 
)    (AVERROR_BUG)

Definition at line 220 of file decode.c.

◆ UTF8_MAX_BYTES

#define UTF8_MAX_BYTES   4 /* 5 and 6 bytes sequences should not be used */

Definition at line 902 of file decode.c.

Function Documentation

◆ decode_ctx()

static DecodeContext* decode_ctx ( AVCodecInternal avci)
static

◆ apply_param_change()

static int apply_param_change ( AVCodecContext avctx,
const AVPacket avpkt 
)
static

Definition at line 107 of file decode.c.

Referenced by decode_get_packet().

◆ extract_packet_props()

static int extract_packet_props ( AVCodecInternal avci,
const AVPacket pkt 
)
static

Definition at line 168 of file decode.c.

Referenced by decode_get_packet().

◆ decode_bsfs_init()

static int decode_bsfs_init ( AVCodecContext avctx)
static

Definition at line 183 of file decode.c.

Referenced by ff_decode_preinit().

◆ decode_get_packet()

static int decode_get_packet ( AVCodecContext avctx,
AVPacket pkt 
)
static

Definition at line 223 of file decode.c.

Referenced by ff_decode_get_packet().

◆ ff_decode_get_packet()

int ff_decode_get_packet ( AVCodecContext avctx,
AVPacket pkt 
)

Called by decoders to get the next packet for decoding.

Parameters
pktAn empty packet to be filled with data.
Returns
0 if a new reference has been successfully written to pkt AVERROR(EAGAIN) if no data is currently available AVERROR_EOF if and end of stream has been reached, so no more data will be available

Definition at line 248 of file decode.c.

Referenced by av1_receive_frame(), binkaudio_receive_frame(), cuvid_output_frame(), decode_simple_internal(), ff_thread_receive_frame(), ffmmal_receive_frame(), hevc_receive_frame(), libdav1d_receive_frame_internal(), libjxl_receive_frame(), libxevd_receive_frame(), mediacodec_receive_frame(), osq_receive_frame(), rkmpp_receive_frame(), and v4l2_receive_frame().

◆ guess_correct_pts()

static int64_t guess_correct_pts ( DecodeContext dc,
int64_t  reordered_pts,
int64_t  dts 
)
static

Attempt to guess proper monotonic timestamps for decoded video frames which might have incorrect times.

Input timestamps may wrap around, in which case the output will as well.

Parameters
ptsthe pts field of the decoded AVPacket, as passed through AVFrame.pts
dtsthe dts field of the decoded AVPacket
Returns
one of the input values, may be AV_NOPTS_VALUE

Definition at line 290 of file decode.c.

Referenced by decode_receive_frame_internal().

◆ discard_samples()

static int discard_samples ( AVCodecContext avctx,
AVFrame frame,
int64_t discarded_samples 
)
static

Definition at line 316 of file decode.c.

Referenced by decode_simple_internal(), and ff_decode_receive_frame_internal().

◆ decode_simple_internal()

static int decode_simple_internal ( AVCodecContext avctx,
AVFrame frame,
int64_t discarded_samples 
)
inlinestatic

Definition at line 414 of file decode.c.

Referenced by decode_simple_receive_frame().

◆ detect_colorspace()

static int detect_colorspace ( av_unused AVCodecContext c,
av_unused AVFrame f 
)
static

Definition at line 566 of file decode.c.

Referenced by decode_receive_frame_internal().

◆ fill_frame_props()

static int fill_frame_props ( const AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 572 of file decode.c.

Referenced by decode_receive_frame_internal(), and ff_decode_frame_props().

◆ decode_simple_receive_frame()

static int decode_simple_receive_frame ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 605 of file decode.c.

Referenced by ff_decode_receive_frame_internal().

◆ ff_decode_receive_frame_internal()

int ff_decode_receive_frame_internal ( struct AVCodecContext avctx,
AVFrame frame 
)

Do the actual decoding and obtain a decoded frame from the decoder, if available.

When frame threading is used, this is invoked by the worker threads, otherwise by the top layer directly.

Definition at line 621 of file decode.c.

Referenced by decode_receive_frame_internal(), and frame_worker_thread().

◆ decode_receive_frame_internal()

static int decode_receive_frame_internal ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 657 of file decode.c.

Referenced by avcodec_send_packet(), and ff_decode_receive_frame().

◆ apply_cropping()

static int apply_cropping ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 761 of file decode.c.

Referenced by ff_decode_receive_frame(), and ist_add().

◆ frame_validate()

static int frame_validate ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 789 of file decode.c.

Referenced by ff_decode_receive_frame().

◆ ff_decode_receive_frame()

int ff_decode_receive_frame ( AVCodecContext avctx,
AVFrame frame 
)

avcodec_receive_frame() implementation for decoders.

Definition at line 815 of file decode.c.

Referenced by avcodec_receive_frame().

◆ get_subtitle_defaults()

static void get_subtitle_defaults ( AVSubtitle sub)
static

Definition at line 896 of file decode.c.

Referenced by avcodec_decode_subtitle2().

◆ recode_subtitle()

static int recode_subtitle ( AVCodecContext avctx,
const AVPacket **  outpkt,
const AVPacket inpkt,
AVPacket buf_pkt 
)
static

Definition at line 903 of file decode.c.

Referenced by avcodec_decode_subtitle2().

◆ utf8_check()

static int utf8_check ( const uint8_t *  str)
static

Definition at line 964 of file decode.c.

Referenced by avcodec_decode_subtitle2().

◆ ff_decode_get_hw_frames_ctx()

int ff_decode_get_hw_frames_ctx ( AVCodecContext avctx,
enum AVHWDeviceType  dev_type 
)

Make sure avctx.hw_frames_ctx is set.

If it's not set, the function will try to allocate it from hw_device_ctx. If that is not possible, an error message is printed, and an error code is returned.

Definition at line 1117 of file decode.c.

Referenced by ff_d3d12va_decode_init(), ff_dxva2_decode_init(), ff_vaapi_decode_init(), ff_vdpau_common_init(), and ff_vk_decode_init().

◆ hwaccel_init()

static int hwaccel_init ( AVCodecContext avctx,
const FFHWAccel hwaccel 
)
static

Definition at line 1230 of file decode.c.

Referenced by ff_get_format().

◆ ff_hwaccel_uninit()

void ff_hwaccel_uninit ( AVCodecContext avctx)

◆ ff_get_format()

int ff_get_format ( AVCodecContext avctx,
const enum AVPixelFormat fmt 
)

Select the (possibly hardware accelerated) pixel format.

This is a wrapper around AVCodecContext.get_format() and should be used instead of calling get_format() directly.

The list of pixel formats must contain at least one valid entry, and is terminated with AV_PIX_FMT_NONE. If it is possible to decode to software, the last entry in the list must be the most accurate software format. If it is not possible to decode to software, AVCodecContext.sw_pix_fmt must be set before calling this function.

Definition at line 1277 of file decode.c.

Referenced by cuvid_decode_init(), decode_frame_header(), ff_mjpeg_decode_sof(), ffmmal_init_decoder(), get_format(), get_pixel_format(), h263_get_format(), mediacodec_dec_get_video_codec(), mpeg_get_pixelformat(), qsv_decode_preinit(), update_size(), and vc1_get_format().

◆ packet_side_data_get()

static const AVPacketSideData* packet_side_data_get ( const AVPacketSideData sd,
int  nb_sd,
enum AVPacketSideDataType  type 
)
static

Definition at line 1416 of file decode.c.

Referenced by ff_get_coded_side_data(), and side_data_map().

◆ ff_get_coded_side_data()

const AVPacketSideData* ff_get_coded_side_data ( const AVCodecContext avctx,
enum AVPacketSideDataType  type 
)

Get side data of the given type from a decoding context.

Definition at line 1426 of file decode.c.

Referenced by av1_decode_init(), hevc_decode_init(), and libdav1d_init().

◆ side_data_stereo3d_merge()

static int side_data_stereo3d_merge ( AVFrameSideData sd_frame,
const AVPacketSideData sd_pkt 
)
static

Definition at line 1432 of file decode.c.

Referenced by side_data_map().

◆ side_data_map()

static int side_data_map ( AVFrame dst,
const AVPacketSideData sd_src,
int  nb_sd_src,
const SideDataMap map 
)
static

Definition at line 1468 of file decode.c.

Referenced by ff_decode_frame_props(), and ff_decode_frame_props_from_pkt().

◆ add_metadata_from_side_data()

static int add_metadata_from_side_data ( const AVPacket avpkt,
AVFrame frame 
)
static

Definition at line 1504 of file decode.c.

Referenced by ff_decode_frame_props_from_pkt().

◆ ff_decode_frame_props_from_pkt()

int ff_decode_frame_props_from_pkt ( const AVCodecContext avctx,
AVFrame frame,
const AVPacket pkt 
)

Set various frame properties from the provided packet.

Definition at line 1516 of file decode.c.

Referenced by ff_decode_frame_props(), libdav1d_receive_frame(), and libxevd_return_frame().

◆ ff_decode_frame_props()

int ff_decode_frame_props ( AVCodecContext avctx,
AVFrame frame 
)

◆ validate_avframe_allocation()

static void validate_avframe_allocation ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 1605 of file decode.c.

Referenced by ff_get_buffer().

◆ decode_data_free()

static void decode_data_free ( void *  opaque,
uint8_t *  data 
)
static

Definition at line 1626 of file decode.c.

Referenced by ff_attach_decode_data().

◆ ff_attach_decode_data()

int ff_attach_decode_data ( AVFrame frame)

◆ update_frame_props()

static void update_frame_props ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 1663 of file decode.c.

Referenced by ff_get_buffer().

◆ attach_post_process_data()

static void attach_post_process_data ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 1679 of file decode.c.

Referenced by ff_get_buffer().

◆ ff_get_buffer()

int ff_get_buffer ( AVCodecContext avctx,
AVFrame frame,
int  flags 
)

Get a buffer for a frame.

This is a wrapper around AVCodecContext.get_buffer() and should be used instead calling get_buffer() directly.

Definition at line 1697 of file decode.c.

Referenced by ac3_decode_frame(), adpcm_decode_frame(), adx_decode_frame(), alloc_frame(), amrnb_decode_frame(), amrwb_decode_frame(), aom_decode(), apac_decode(), ape_decode_frame(), aptx_decode_frame(), atrac1_decode_frame(), atrac3_decode_frame(), atrac3al_decode_frame(), atrac3p_decode_frame(), atrac9_decode_frame(), aura_decode_frame(), avui_decode_frame(), bfi_decode_frame(), binkaudio_receive_frame(), bmp_decode_frame(), bmv_aud_decode_frame(), bonk_decode(), cdg_decode_frame(), cdxl_decode_frame(), cinaudio_decode_frame(), cmv_decode_frame(), cng_decode_frame(), cook_decode_frame(), copy_output(), cuvid_output_frame(), cyuv_decode_frame(), dds_decode(), decode_frame(), decode_pic(), decode_tag(), dfa_decode_frame(), dfpwm_dec_frame(), dpcm_decode_frame(), dss_sp_decode_frame(), eightsvx_decode_frame(), escape124_decode_frame(), escape130_decode_frame(), evrc_decode_frame(), execute_code(), fastaudio_decode(), fdk_aac_decode_frame(), ff_dca_lbr_filter_frame(), ff_dca_xll_filter_frame(), ff_ivi_decode_frame(), ff_mjpeg_decode_sof(), ff_thread_get_buffer(), ff_thread_get_ext_buffer(), ff_twinvq_decode_frame(), ff_vp56_decode_frame(), ffat_decode(), ffmal_copy_frame(), filter_frame(), filter_frame_fixed(), filter_frame_float(), fits_decode_frame(), frame_configure_elements(), ftr_decode_frame(), g2m_decode_frame(), g722_decode_frame(), g723_1_decode_frame(), gdv_decode_frame(), gem_decode_frame(), get_buffer(), get_buffer_with_edge(), gsm_decode_frame(), hcom_decode(), hnm_decode_frame(), hq_decode_frame(), hqa_decode_frame(), idcin_decode_frame(), ilbc_decode_frame(), imc_decode_frame(), init_frames(), ipu_decode_frame(), ipvideo_decode_frame(), lead_decode_frame(), libcelt_dec_decode(), libcodec2_decode(), libgsm_decode_frame(), libjxl_receive_frame(), liblc3_decode(), libopus_decode(), librsvg_decode_frame(), libspeex_decode_frame(), libuavs3d_decode_frame(), libxevd_image_copy(), m101_decode_frame(), mace_decode_frame(), mediacodec_wrap_sw_audio_buffer(), mediacodec_wrap_sw_video_buffer(), misc4_decode(), mp_decode_frame(), mpc7_decode_frame(), mpc8_decode_frame(), msp2_decode_frame(), mss2_decode_frame(), mvc_decode_frame(), mxpeg_decode_frame(), oggvorbis_decode_frame(), on2avc_decode_frame(), opus_decode_packet(), osq_receive_frame(), output_data(), paf_audio_decode(), pcm_bluray_decode_frame(), pcm_decode_frame(), pcm_dvd_decode_frame(), pcx_decode_frame(), pgx_decode_frame(), pix_decode_frame(), pnm_decode_frame(), ptx_decode_frame(), qcelp_decode_frame(), qdm2_decode_frame(), qdmc_decode_frame(), qoa_decode_frame(), ra144_decode_frame(), ra288_decode_frame(), reget_buffer_internal(), rka_decode_frame(), rl2_decode_frame(), rv60_decode_frame(), s302m_decode_frame(), sbc_decode_frame(), sga_decode_frame(), sgirle_decode_frame(), shorten_decode_frame(), sipr_decode_frame(), siren_decode(), smka_decode_frame(), speex_decode_frame(), sunrast_decode_frame(), svc_decode_frame(), svq1_decode_frame(), synth_superframe(), tdsc_decode_frame(), tgq_decode_frame(), tgv_decode_frame(), thread_get_buffer_internal(), tmv_decode_frame(), tqi_decode_frame(), truemotion2rt_decode_frame(), truespeech_decode_frame(), txd_decode_frame(), v308_decode_frame(), v408_decode_frame(), vbn_decode_frame(), vcr1_decode_frame(), vmdaudio_decode_frame(), vmdvideo_decode_frame(), vorbis_decode_frame(), vpx_decode(), wavarc_decode(), wavesynth_decode(), wma_decode_superframe(), wmapro_decode_packet(), ws_snd_decode_frame(), xan_decode_frame(), xbm_decode_frame(), xface_decode_frame(), xma_decode_packet(), xpm_decode_frame(), xwd_decode_frame(), y216_decode_frame(), y41p_decode_frame(), yuv4_decode_frame(), zero12v_decode_frame(), and zerocodec_decode_frame().

◆ reget_buffer_internal()

static int reget_buffer_internal ( AVCodecContext avctx,
AVFrame frame,
int  flags 
)
static

Definition at line 1773 of file decode.c.

Referenced by ff_reget_buffer().

◆ ff_reget_buffer()

int ff_reget_buffer ( AVCodecContext avctx,
AVFrame frame,
int  flags 
)

◆ check_progress_consistency()

static void check_progress_consistency ( const ProgressFrame f)
static

◆ ff_progress_frame_alloc()

int ff_progress_frame_alloc ( struct AVCodecContext avctx,
ProgressFrame f 
)

This function allocates ProgressFrame.f May be called before ff_progress_frame_get_buffer() in the cases where the AVFrame needs to be accessed before the ff_thread_get_buffer() call in ff_progress_frame_alloc().

Note
: This must only be called by codecs with the FF_CODEC_CAP_USES_PROGRESSFRAMES internal cap.

Definition at line 1834 of file decode.c.

Referenced by alloc_frame(), and ff_progress_frame_get_buffer().

◆ ff_progress_frame_get_buffer()

int ff_progress_frame_get_buffer ( struct AVCodecContext avctx,
ProgressFrame f,
int  flags 
)

This function sets up the ProgressFrame, i.e.

allocates ProgressFrame.f if needed, and also calls ff_thread_get_buffer() on the frame.

Note
: This must only be called by codecs with the FF_CODEC_CAP_USES_PROGRESSFRAMES internal cap.
See also
ff_progress_frame_alloc

Definition at line 1848 of file decode.c.

Referenced by alloc_frame(), av1_frame_alloc(), decode_frame(), decode_idat_chunk(), mimic_decode_frame(), vp8_alloc_frame(), and vp9_frame_alloc().

◆ ff_progress_frame_ref()

void ff_progress_frame_ref ( ProgressFrame dst,
const ProgressFrame src 
)

Set dst->f to src->f and make dst a co-owner of src->f.

dst can then be used to wait on progress of the underlying frame.

Note
: There is no underlying av_frame_ref() here. dst->f and src->f really point to the same AVFrame. Typically this means that the decoding thread is allowed to set all the properties of the AVFrame until it has indicated to have finished decoding. Afterwards later threads may read all of these fields. Access to the frame's data is governed by ff_thread_progress_report/await().

Definition at line 1868 of file decode.c.

Referenced by ff_progress_frame_replace(), and hevc_ref_frame().

◆ ff_progress_frame_unref()

void ff_progress_frame_unref ( ProgressFrame f)

Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame, setting all pointers to NULL.

Note
: This implies that when using this API the check for whether a frame exists is by checking ProgressFrame.f and not ProgressFrame.f->data[0] or ProgressFrame.f->buf[0].

Definition at line 1876 of file decode.c.

Referenced by av1_frame_unref(), decode_frame(), decode_idat_chunk(), ff_hevc_unref_frame(), ff_progress_frame_replace(), ffv1_decode_close(), mimic_decode_end(), mimic_decode_frame(), png_dec_end(), update_frames(), vp3_decode_flush(), vp8_alloc_frame(), vp8_release_frame(), vp9_decode_flush(), vp9_decode_free(), and vp9_frame_unref().

◆ ff_progress_frame_replace()

void ff_progress_frame_replace ( ProgressFrame dst,
const ProgressFrame src 
)

Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is not blank, put a reference to src's AVFrame in its place (in case src is not blank).

Definition at line 1883 of file decode.c.

Referenced by av1_frame_replace(), update_frames(), vp9_decode_frame(), and vp9_frame_replace().

◆ ff_progress_frame_report()

void ff_progress_frame_report ( ProgressFrame f,
int  progress 
)

Notify later decoding threads when part of their reference frame is ready.

Call this when some part of the frame is finished decoding. Later calls with lower values of progress have no effect.

Parameters
fThe frame being decoded.
progressValue, in arbitrary units, of how much of the frame has decoded.
Warning
Calling this on a blank ProgressFrame causes undefined behaviour

Definition at line 1893 of file decode.c.

Referenced by decode(), decode_frame(), decode_frame_common(), decode_nal_units(), decode_slice(), decode_tiles(), ff_hevc_hls_filter(), generate_missing_ref(), mimic_decode_frame(), vp3_draw_horiz_band(), vp78_decode_frame(), vp78_decode_mb_row_sliced(), and vp9_decode_frame().

◆ ff_progress_frame_await()

void ff_progress_frame_await ( const ProgressFrame f,
int  progress 
)

Wait for earlier decoding threads to finish reference frames.

Call this before accessing some part of a frame, with a given value for progress, and it will return after the responsible decoding thread calls ff_thread_progress_report() with the same or higher value for progress.

Parameters
fThe frame being referenced.
progressValue, in arbitrary units, to wait for.
Warning
Calling this on a blank ProgressFrame causes undefined behaviour

Definition at line 1898 of file decode.c.

◆ ff_thread_sync_ref()

enum ThreadingStatus ff_thread_sync_ref ( AVCodecContext avctx,
size_t  offset 
)

Allows to synchronize objects whose lifetime is the whole decoding process among all frame threads.

When called from a non-copy thread, do nothing. When called from another thread, place a new RefStruct reference at the given offset in the calling thread's private data from the RefStruct reference in the private data of the first decoding thread. The first thread must have a valid RefStruct reference at the given offset in its private data; the calling thread must not have a reference at this offset in its private data (must be NULL).

Parameters
avctxan AVCodecContext
offsetoffset of the RefStruct reference in avctx's private data
Return values
FF_THREAD_IS_COPYif frame-threading is in use and the calling thread is a copy; in this case, the RefStruct reference will be set.
FF_THREAD_IS_MAIN_THREADif frame-threading is in use and the calling thread is the main thread.
FF_THREAD_NO_FRAME_THREADINGif frame-threading is not in use.

Definition at line 1904 of file decode.c.

Referenced by ff_mpv_decode_init(), and wavpack_decode_init().

◆ progress_frame_pool_init_cb()

static av_cold int progress_frame_pool_init_cb ( AVRefStructOpaque  opaque,
void *  obj 
)
static

Definition at line 1910 of file decode.c.

Referenced by ff_decode_preinit().

◆ progress_frame_pool_reset_cb()

static void progress_frame_pool_reset_cb ( AVRefStructOpaque  unused,
void *  obj 
)
static

Definition at line 1927 of file decode.c.

Referenced by ff_decode_preinit().

◆ progress_frame_pool_free_entry_cb()

static av_cold void progress_frame_pool_free_entry_cb ( AVRefStructOpaque  opaque,
void *  obj 
)
static

Definition at line 1935 of file decode.c.

Referenced by ff_decode_preinit().

◆ ff_decode_preinit()

int ff_decode_preinit ( struct AVCodecContext avctx)

Perform decoder initialization and validation.

Called when opening the decoder, before the FFCodec.init() call.

Definition at line 1943 of file decode.c.

Referenced by avcodec_open2().

◆ side_data_pref()

static int side_data_pref ( const AVCodecContext avctx,
AVFrameSideData ***  sd,
int *  nb_sd,
enum AVFrameSideDataType  type 
)
static

Check side data preference and clear existing side data from frame if needed.

Return values
0side data of this type can be added to frame
1side data of this type should not be added to frame

Definition at line 2083 of file decode.c.

Referenced by ff_decode_content_light_new(), ff_decode_content_light_new_ext(), ff_decode_mastering_display_new(), ff_decode_mastering_display_new_ext(), ff_frame_new_side_data(), and ff_frame_new_side_data_from_buf_ext().

◆ ff_frame_new_side_data()

int ff_frame_new_side_data ( const AVCodecContext avctx,
AVFrame frame,
enum AVFrameSideDataType  type,
size_t  size,
AVFrameSideData **  sd 
)

Wrapper around av_frame_new_side_data, which rejects side data overridden by the demuxer.

Returns 0 on success, and a negative error code otherwise. If successful and sd is not NULL, *sd may either contain a pointer to the new side data, or NULL in case the side data was already present.

Definition at line 2099 of file decode.c.

Referenced by cri_decode_frame(), decode_frame(), ff_mjpeg_decode_frame_from_buf(), h264_export_frame_props(), mpeg_field_start(), populate_avctx_color_fields(), set_side_data(), tiff_decode_tag(), and webp_decode_frame().

◆ ff_frame_new_side_data_from_buf_ext()

int ff_frame_new_side_data_from_buf_ext ( const AVCodecContext avctx,
AVFrameSideData ***  sd,
int *  nb_sd,
enum AVFrameSideDataType  type,
AVBufferRef **  buf 
)

Same as ff_frame_new_side_data_from_buf, but taking a AVFrameSideData array directly instead of an AVFrame.

Definition at line 2118 of file decode.c.

Referenced by ff_frame_new_side_data_from_buf(), and h2645_sei_to_side_data().

◆ ff_frame_new_side_data_from_buf()

int ff_frame_new_side_data_from_buf ( const AVCodecContext avctx,
AVFrame frame,
enum AVFrameSideDataType  type,
AVBufferRef **  buf 
)

Similar to ff_frame_new_side_data, but using an existing buffer ref.

*buf is ALWAYS consumed by this function and NULL written in its place, even on failure.

Definition at line 2137 of file decode.c.

Referenced by alloc_frame(), export_itut_t35(), ff_h2645_sei_to_frame(), libdav1d_receive_frame(), libjxl_receive_frame(), mpeg_field_start(), and set_side_data().

◆ ff_decode_mastering_display_new_ext()

int ff_decode_mastering_display_new_ext ( const AVCodecContext avctx,
AVFrameSideData ***  sd,
int *  nb_sd,
struct AVMasteringDisplayMetadata **  mdm 
)

Same as ff_decode_mastering_display_new, but taking a AVFrameSideData array directly instead of an AVFrame.

Definition at line 2146 of file decode.c.

Referenced by h2645_sei_to_side_data().

◆ ff_decode_mastering_display_new()

int ff_decode_mastering_display_new ( const AVCodecContext avctx,
AVFrame frame,
struct AVMasteringDisplayMetadata **  mdm 
)

Wrapper around av_mastering_display_metadata_create_side_data(), which rejects side data overridden by the demuxer.

Returns 0 on success, and a negative error code otherwise. If successful, *mdm may either be a pointer to the new side data, or NULL in case the side data was already present.

Definition at line 2178 of file decode.c.

Referenced by export_metadata(), libdav1d_receive_frame(), and populate_avctx_color_fields().

◆ ff_decode_content_light_new_ext()

int ff_decode_content_light_new_ext ( const AVCodecContext avctx,
AVFrameSideData ***  sd,
int *  nb_sd,
AVContentLightMetadata **  clm 
)

Same as ff_decode_content_light_new, but taking a AVFrameSideData array directly instead of an AVFrame.

Definition at line 2191 of file decode.c.

Referenced by h2645_sei_to_side_data().

◆ ff_decode_content_light_new()

int ff_decode_content_light_new ( const AVCodecContext avctx,
AVFrame frame,
struct AVContentLightMetadata **  clm 
)

Wrapper around av_content_light_metadata_create_side_data(), which rejects side data overridden by the demuxer.

Returns 0 on success, and a negative error code otherwise. If successful, *clm may either be a pointer to the new side data, or NULL in case the side data was already present.

Definition at line 2223 of file decode.c.

Referenced by export_metadata(), libdav1d_receive_frame(), and populate_avctx_color_fields().

◆ ff_copy_palette()

int ff_copy_palette ( void *  dst,
const AVPacket src,
void *  logctx 
)

Check whether the side-data of src contains a palette of size AVPALETTE_SIZE; if so, copy it to dst and return 1; else return 0.

Also emit an error message upon encountering a palette with invalid size.

Definition at line 2236 of file decode.c.

Referenced by cinepak_decode_frame(), decode_frame(), gdv_decode_frame(), idcin_decode_frame(), imx_decode_frame(), ipvideo_decode_frame(), msrle_decode_frame(), msvideo1_decode_frame(), qtrle_decode_frame(), raw_decode(), rscc_decode_frame(), and smc_decode_frame().

◆ ff_hwaccel_frame_priv_alloc()

int ff_hwaccel_frame_priv_alloc ( AVCodecContext avctx,
void **  hwaccel_picture_private 
)

Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.

The returned data is a RefStruct reference (if allocated).

Parameters
avctxThe codec context
hwaccel_picture_privatePointer to return hwaccel_picture_private
Returns
0 on success, < 0 on error

Definition at line 2251 of file decode.c.

Referenced by alloc_frame(), alloc_picture(), av1_frame_alloc(), vp8_alloc_frame(), and vp9_frame_alloc().

◆ ff_decode_flush_buffers()

void ff_decode_flush_buffers ( AVCodecContext avctx)

Definition at line 2280 of file decode.c.

Referenced by avcodec_flush_buffers().

◆ ff_decode_internal_alloc()

AVCodecInternal* ff_decode_internal_alloc ( void  )

Definition at line 2298 of file decode.c.

Referenced by avcodec_open2(), and init_thread().

◆ ff_decode_internal_sync()

void ff_decode_internal_sync ( AVCodecContext dst,
const AVCodecContext src 
)

Definition at line 2303 of file decode.c.

◆ ff_decode_internal_uninit()

void ff_decode_internal_uninit ( AVCodecContext avctx)

Definition at line 2311 of file decode.c.

Referenced by ff_codec_close(), and ff_frame_thread_free().