FFmpeg  4.0
Macros | Functions
decode.c File Reference
#include <stdint.h>
#include <string.h>
#include "config.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/common.h"
#include "libavutil/frame.h"
#include "libavutil/hwcontext.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/intmath.h"
#include "avcodec.h"
#include "bytestream.h"
#include "decode.h"
#include "hwaccel.h"
#include "internal.h"
#include "thread.h"

Go to the source code of this file.

Macros

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

Functions

static int apply_param_change (AVCodecContext *avctx, const AVPacket *avpkt)
 
static int extract_packet_props (AVCodecInternal *avci, const AVPacket *pkt)
 
static int unrefcount_frame (AVCodecInternal *avci, AVFrame *frame)
 
static int bsfs_init (AVCodecContext *avctx)
 
static int bsfs_poll (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 (AVCodecContext *ctx, 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 decode_simple_internal (AVCodecContext *avctx, AVFrame *frame)
 
static int decode_simple_receive_frame (AVCodecContext *avctx, AVFrame *frame)
 
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)
 
int attribute_align_arg avcodec_receive_frame (AVCodecContext *avctx, AVFrame *frame)
 Return decoded output data from a decoder. More...
 
static int compat_decode (AVCodecContext *avctx, AVFrame *frame, int *got_frame, const AVPacket *pkt)
 
int attribute_align_arg avcodec_decode_video2 (AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
 Decode the video frame of size avpkt->size from avpkt->data into picture. More...
 
int attribute_align_arg avcodec_decode_audio4 (AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
 Decode the audio frame of size avpkt->size from avpkt->data into frame. More...
 
static void get_subtitle_defaults (AVSubtitle *sub)
 
static int recode_subtitle (AVCodecContext *avctx, AVPacket *outpkt, const AVPacket *inpkt)
 
static int utf8_check (const uint8_t *str)
 
static void insert_ts (AVBPrint *buf, int ts)
 
static int convert_sub_to_old_ass_form (AVSubtitle *sub, const AVPacket *pkt, AVRational tb)
 
int avcodec_decode_subtitle2 (AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, 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 AVCodecHWConfigInternal *hw_config)
 
static void hwaccel_uninit (AVCodecContext *avctx)
 
int ff_get_format (AVCodecContext *avctx, const enum AVPixelFormat *fmt)
 Select the (possibly hardware accelerated) pixel format. More...
 
static int update_frame_pool (AVCodecContext *avctx, AVFrame *frame)
 
static int audio_get_buffer (AVCodecContext *avctx, AVFrame *frame)
 
static int video_get_buffer (AVCodecContext *s, AVFrame *pic)
 
int avcodec_default_get_buffer2 (AVCodecContext *avctx, AVFrame *frame, int flags)
 The default callback for AVCodecContext.get_buffer2(). More...
 
static int add_metadata_from_side_data (const AVPacket *avpkt, AVFrame *frame)
 
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 int get_buffer_internal (AVCodecContext *avctx, AVFrame *frame, int flags)
 
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 ff_reget_buffer (AVCodecContext *avctx, AVFrame *frame)
 Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buffer when needed. More...
 
void avcodec_flush_buffers (AVCodecContext *avctx)
 Reset the internal decoder state / flush internal buffers. More...
 
void ff_decode_bsfs_uninit (AVCodecContext *avctx)
 

Macro Definition Documentation

◆ UTF8_MAX_BYTES

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

Definition at line 847 of file decode.c.

Referenced by recode_subtitle().

Function Documentation

◆ apply_param_change()

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

Definition at line 47 of file decode.c.

Referenced by ff_decode_get_packet().

◆ extract_packet_props()

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

Definition at line 125 of file decode.c.

Referenced by avcodec_decode_subtitle2(), and ff_decode_get_packet().

◆ unrefcount_frame()

static int unrefcount_frame ( AVCodecInternal avci,
AVFrame frame 
)
static

Definition at line 138 of file decode.c.

Referenced by compat_decode().

◆ bsfs_init()

static int bsfs_init ( AVCodecContext avctx)
static

Definition at line 184 of file decode.c.

Referenced by avcodec_receive_frame(), and avcodec_send_packet().

◆ bsfs_poll()

static int bsfs_poll ( AVCodecContext avctx,
AVPacket pkt 
)
static

Definition at line 256 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 294 of file decode.c.

Referenced by binkaudio_receive_frame(), crystalhd_receive_frame(), cuvid_output_frame(), decode_simple_internal(), mediacodec_receive_frame(), and v4l2_receive_frame().

◆ guess_correct_pts()

static int64_t guess_correct_pts ( AVCodecContext ctx,
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 335 of file decode.c.

Referenced by decode_simple_internal().

◆ decode_simple_internal()

static int decode_simple_internal ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 367 of file decode.c.

Referenced by decode_simple_receive_frame().

◆ decode_simple_receive_frame()

static int decode_simple_receive_frame ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 589 of file decode.c.

Referenced by decode_receive_frame_internal().

◆ decode_receive_frame_internal()

static int decode_receive_frame_internal ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 602 of file decode.c.

Referenced by avcodec_receive_frame(), and avcodec_send_packet().

◆ apply_cropping()

static int apply_cropping ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 682 of file decode.c.

Referenced by avcodec_receive_frame().

◆ compat_decode()

static int compat_decode ( AVCodecContext avctx,
AVFrame frame,
int got_frame,
const AVPacket pkt 
)
static

Definition at line 744 of file decode.c.

Referenced by avcodec_decode_audio4(), and avcodec_decode_video2().

◆ get_subtitle_defaults()

static void get_subtitle_defaults ( AVSubtitle sub)
static

Definition at line 841 of file decode.c.

Referenced by avcodec_decode_subtitle2().

◆ recode_subtitle()

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

Definition at line 848 of file decode.c.

Referenced by avcodec_decode_subtitle2().

◆ utf8_check()

static int utf8_check ( const uint8_t str)
static

Definition at line 906 of file decode.c.

Referenced by avcodec_decode_subtitle2().

◆ insert_ts()

static void insert_ts ( AVBPrint *  buf,
int  ts 
)
static

Definition at line 926 of file decode.c.

Referenced by convert_sub_to_old_ass_form().

◆ convert_sub_to_old_ass_form()

static int convert_sub_to_old_ass_form ( AVSubtitle sub,
const AVPacket pkt,
AVRational  tb 
)
static

Definition at line 940 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 1150 of file decode.c.

Referenced by ff_dxva2_decode_init(), ff_nvdec_decode_init(), ff_vaapi_decode_init(), and ff_vdpau_common_init().

◆ hwaccel_init()

static int hwaccel_init ( AVCodecContext avctx,
const AVCodecHWConfigInternal hw_config 
)
static

Definition at line 1250 of file decode.c.

Referenced by ff_get_format().

◆ hwaccel_uninit()

static void hwaccel_uninit ( AVCodecContext avctx)
static

Definition at line 1287 of file decode.c.

Referenced by ff_get_format().

◆ 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 1299 of file decode.c.

Referenced by cuvid_decode_init(), decode_init(), ff_exp2fi(), ff_mediacodec_dec_init(), ff_mjpeg_decode_sof(), ff_qsv_process_data(), ff_thread_get_format(), ffmmal_init_decoder(), get_pixel_format(), h263_get_format(), submit_packet(), and vc1_decode_init().

◆ update_frame_pool()

static int update_frame_pool ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 1435 of file decode.c.

Referenced by avcodec_default_get_buffer2().

◆ audio_get_buffer()

static int audio_get_buffer ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 1537 of file decode.c.

Referenced by avcodec_default_get_buffer2().

◆ video_get_buffer()

static int video_get_buffer ( AVCodecContext s,
AVFrame pic 
)
static

Definition at line 1582 of file decode.c.

Referenced by avcodec_default_get_buffer2().

◆ add_metadata_from_side_data()

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

Definition at line 1653 of file decode.c.

Referenced by ff_decode_frame_props().

◆ ff_decode_frame_props()

int ff_decode_frame_props ( AVCodecContext avctx,
AVFrame frame 
)

Set various frame properties from the codec context / packet data.

Definition at line 1665 of file decode.c.

Referenced by cuvid_output_frame(), ff_exp2fi(), ffmal_copy_frame(), get_buffer_internal(), raw_decode(), reget_buffer_internal(), and wrapped_avframe_decode().

◆ validate_avframe_allocation()

static void validate_avframe_allocation ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 1773 of file decode.c.

Referenced by get_buffer_internal().

◆ decode_data_free()

static void decode_data_free ( void opaque,
uint8_t data 
)
static

Definition at line 1796 of file decode.c.

Referenced by ff_attach_decode_data().

◆ ff_attach_decode_data()

int ff_attach_decode_data ( AVFrame frame)

◆ get_buffer_internal()

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

Definition at line 1833 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 1891 of file decode.c.

Referenced by ac3_decode_frame(), adpcm_decode_frame(), adx_decode_frame(), alloc_frame(), amr_decode_fix_avctx(), amrnb_decode_frame(), amrwb_decode_frame(), aom_decode(), ape_decode_frame(), aptx_decode_frame(), atrac1_decode_frame(), atrac3_decode_frame(), atrac3al_decode_frame(), atrac3p_decode_frame(), aura_decode_frame(), avui_decode_frame(), bfi_decode_frame(), binkaudio_receive_frame(), bitpacked_decode_yuv422p10(), bmp_decode_frame(), bmv_aud_decode_frame(), cdg_decode_frame(), cdxl_decode_frame(), cinaudio_decode_frame(), cmv_decode_frame(), cng_decode_frame(), cook_decode_frame(), copy_frame(), copy_output(), cuvid_output_frame(), cyuv_decode_frame(), dds_decode(), decode_frame(), decode_pic(), decode_tag(), dfa_decode_frame(), dpcm_decode_frame(), dss_sp_decode_frame(), dvvideo_decode_frame(), dxtory_decode_v1_410(), dxtory_decode_v1_420(), dxtory_decode_v1_444(), dxtory_decode_v1_rgb(), dxtory_decode_v2(), eightsvx_decode_frame(), escape124_decode_frame(), escape130_decode_frame(), evrc_decode_frame(), execute_code(), fdk_aac_decode_frame(), ff_dca_lbr_filter_frame(), ff_dca_xll_filter_frame(), ff_exp2fi(), ff_ivi_decode_frame(), ff_mjpeg_decode_sof(), ff_snow_common_init_after_header(), ff_snow_get_buffer(), ff_thread_get_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(), flush(), frame_configure_elements(), g2m_decode_frame(), g722_decode_frame(), g723_1_decode_frame(), g726_reset(), gdv_decode_frame(), get_buffer(), get_buffer_with_edge(), gif_decode_frame(), gsm_decode_frame(), hnm_decode_frame(), hq_decode_frame(), hqa_decode_frame(), idcin_decode_frame(), ilbc_decode_frame(), imc_decode_frame(), ipvideo_decode_frame(), ipvideo_decode_init(), libcelt_dec_decode(), libcodec2_decode(), libgsm_decode_frame(), libopus_decode(), librsvg_decode_frame(), libspeex_decode_frame(), m101_decode_frame(), mace_decode_frame(), mediacodec_wrap_sw_buffer(), mp_decode_frame(), mpc7_decode_frame(), mpc8_decode_frame(), mss2_decode_frame(), mvc_decode_frame(), mxpeg_decode_frame(), oggvorbis_decode_frame(), on2avc_decode_frame(), opus_decode_packet(), output_data(), paf_audio_decode(), pcm_bluray_decode_frame(), pcm_decode_frame(), pcm_dvd_decode_frame(), pcx_decode_frame(), pix_decode_frame(), pnm_decode_frame(), predictor_calc_error(), ptx_decode_frame(), qcelp_decode_frame(), qdm2_decode_frame(), qdmc_decode_frame(), ra144_decode_frame(), ra288_decode_frame(), reget_buffer_internal(), rl2_decode_frame(), roq_encode_frame(), s302m_decode_frame(), sbc_decode_frame(), sgirle_decode_frame(), shorten_decode_frame(), sipr_decode_frame(), smka_decode_frame(), speedhq_decode_frame(), submit_frame(), submit_packet(), sunrast_decode_frame(), svc_decode_frame(), svq1_decode_frame(), svq1_encode_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(), v410_decode_frame(), vcr1_decode_frame(), vmdaudio_decode_frame(), vmdvideo_decode_frame(), vorbis_decode_frame(), vpx_decode(), vqa_decode_frame(), wavesynth_decode(), wma_decode_superframe(), wmapro_decode_packet(), ws_snd_decode_frame(), xan_decode_frame(), xbm_decode_frame(), xface_decode_frame(), xma_decode_init(), 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 
)
static

Definition at line 1901 of file decode.c.

Referenced by ff_reget_buffer().

◆ ff_reget_buffer()

int ff_reget_buffer ( AVCodecContext avctx,
AVFrame frame 
)

◆ ff_decode_bsfs_uninit()

void ff_decode_bsfs_uninit ( AVCodecContext avctx)

Definition at line 1972 of file decode.c.

Referenced by avcodec_close(), avcodec_flush_buffers(), and bsfs_init().