FFmpeg
Functions
utils.c File Reference
#include "config.h"
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/pixfmt.h"
#include "avcodec.h"
#include "codec.h"
#include "codec_desc.h"
#include "codec_internal.h"
#include "codec_par.h"
#include "decode.h"
#include "hwconfig.h"
#include "refstruct.h"
#include "thread.h"
#include "threadframe.h"
#include "internal.h"
#include "put_bits.h"
#include "startcode.h"
#include <stdlib.h>
#include <limits.h>

Go to the source code of this file.

Functions

void av_fast_padded_malloc (void *ptr, unsigned int *size, size_t min_size)
 Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0. More...
 
void av_fast_padded_mallocz (void *ptr, unsigned int *size, size_t min_size)
 Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call. More...
 
int av_codec_is_encoder (const AVCodec *avcodec)
 
int av_codec_is_decoder (const AVCodec *avcodec)
 
int ff_set_dimensions (AVCodecContext *s, int width, int height)
 Check that the provided frame dimensions are valid and set them on the codec context. More...
 
int ff_set_sar (AVCodecContext *avctx, AVRational sar)
 Check that the provided sample aspect ratio is valid and set it on the codec context. More...
 
int ff_side_data_update_matrix_encoding (AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
 Add or update AV_FRAME_DATA_MATRIXENCODING side data. More...
 
void avcodec_align_dimensions2 (AVCodecContext *s, int *width, int *height, int linesize_align[AV_NUM_DATA_POINTERS])
 Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you also ensure that all line sizes are a multiple of the respective linesize_align[i]. More...
 
void avcodec_align_dimensions (AVCodecContext *s, int *width, int *height)
 Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you do not use any horizontal padding. More...
 
int avcodec_fill_audio_frame (AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
 Fill AVFrame audio data and linesize pointers. More...
 
int avpriv_codec_get_cap_skip_frame_fill_param (const AVCodec *codec)
 
const char * avcodec_get_name (enum AVCodecID id)
 Get the name of a codec. More...
 
const char * av_get_profile_name (const AVCodec *codec, int profile)
 Return a name for the specified profile, if available. More...
 
const char * avcodec_profile_name (enum AVCodecID codec_id, int profile)
 Return a name for the specified profile, if available. More...
 
int av_get_exact_bits_per_sample (enum AVCodecID codec_id)
 Return codec bits per sample. More...
 
enum AVCodecID av_get_pcm_codec (enum AVSampleFormat fmt, int be)
 Return the PCM codec associated with a sample format. More...
 
int av_get_bits_per_sample (enum AVCodecID codec_id)
 Return codec bits per sample. More...
 
static int get_audio_frame_duration (enum AVCodecID id, int sr, int ch, int ba, uint32_t tag, int bits_per_coded_sample, int64_t bitrate, uint8_t *extradata, int frame_size, int frame_bytes)
 
int av_get_audio_frame_duration (AVCodecContext *avctx, int frame_bytes)
 Return audio frame duration. More...
 
int av_get_audio_frame_duration2 (AVCodecParameters *par, int frame_bytes)
 This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters instead of an AVCodecContext. More...
 
int ff_thread_init (AVCodecContext *s)
 
unsigned int av_xiphlacing (unsigned char *s, unsigned int v)
 Encode extradata length to a buffer. More...
 
int ff_match_2uint16 (const uint16_t(*tab)[2], int size, int a, int b)
 Return the index into tab at which {a,b} match elements {[0],[1]} of tab. More...
 
const AVCodecHWConfigavcodec_get_hw_config (const AVCodec *avcodec, int index)
 Retrieve supported hardware configurations for a codec. More...
 
int ff_thread_ref_frame (ThreadFrame *dst, const ThreadFrame *src)
 
int ff_thread_replace_frame (ThreadFrame *dst, const ThreadFrame *src)
 
int ff_thread_get_buffer (AVCodecContext *avctx, AVFrame *f, int flags)
 Wrapper around get_buffer() for frame-multithreaded codecs. More...
 
int ff_thread_get_ext_buffer (AVCodecContext *avctx, ThreadFrame *f, int flags)
 Wrapper around ff_get_buffer() for frame-multithreaded codecs. More...
 
void ff_thread_release_ext_buffer (ThreadFrame *f)
 Unref a ThreadFrame. More...
 
void ff_thread_finish_setup (AVCodecContext *avctx)
 If the codec defines update_thread_context(), call this when they are ready for the next thread to start decoding the next frame. More...
 
void ff_thread_report_progress (ThreadFrame *f, int progress, int field)
 Notify later decoding threads when part of their reference picture is ready. More...
 
void ff_thread_await_progress (const ThreadFrame *f, int progress, int field)
 Wait for earlier decoding threads to finish reference pictures. More...
 
int ff_thread_can_start_frame (AVCodecContext *avctx)
 
int ff_slice_thread_init_progress (AVCodecContext *avctx)
 
int ff_slice_thread_allocz_entries (AVCodecContext *avctx, int count)
 
void ff_thread_await_progress2 (AVCodecContext *avctx, int field, int thread, int shift)
 
void ff_thread_report_progress2 (AVCodecContext *avctx, int field, int thread, int n)
 
const uint8_t * avpriv_find_start_code (const uint8_t *restrict p, const uint8_t *end, uint32_t *restrict state)
 
AVCPBPropertiesav_cpb_properties_alloc (size_t *size)
 Allocate a CPB properties structure and initialize its fields to default values. More...
 
static unsigned bcd2uint (uint8_t bcd)
 
int ff_alloc_timecode_sei (const AVFrame *frame, AVRational rate, size_t prefix_len, void **data, size_t *sei_size)
 Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info. More...
 
int64_t ff_guess_coded_bitrate (AVCodecContext *avctx)
 Get an estimated video bitrate based on frame size, frame rate and coded bits per pixel. More...
 

Detailed Description

utils.

Definition in file utils.c.

Function Documentation

◆ ff_set_dimensions()

int ff_set_dimensions ( AVCodecContext s,
int  width,
int  height 
)

Check that the provided frame dimensions are valid and set them on the codec context.

Definition at line 94 of file utils.c.

Referenced by alloc_buffers(), aom_decode(), apply_param_change(), avcodec_open2(), avs_decode_init(), bmp_decode_frame(), cdg_decode_init(), cdxl_decode_frame(), cfhd_decode(), clv_decode_init(), cmv_process_header(), codec_reinit(), cri_decode_frame(), dds_decode(), decode_blocks(), decode_fint(), decode_frame(), decode_frame_header(), decode_frame_headers(), decode_header(), decode_idat_chunk(), decode_init(), decode_seq_header(), dirac_decode_data_unit(), dnxhd_decode_frame(), dvbsub_parse_display_definition_segment(), dvdsub_parse_extradata(), dvvideo_decode_frame(), execute_code(), ff_h263_decode_frame(), ff_ivi_decode_frame(), ff_mjpeg_decode_sof(), ff_pnm_decode_header(), ff_rv34_decode_frame(), ff_vc1_decode_entry_point(), ff_vc1_decode_sequence_header(), ff_vp56_decode_frame(), ffmal_update_format(), fits_decode_frame(), flashsv_decode_frame(), g2m_decode_frame(), gem_decode_frame(), get_siz(), gif_decode_frame(), h261_decode_frame(), hdr_decode_frame(), hqa_decode_frame(), init_image(), libdav1d_parse_extradata(), libdav1d_receive_frame(), libjxl_receive_frame(), librsvg_decode_frame(), libuavs3d_decode_frame(), libxevd_image_copy(), magy_decode_frame(), mediacodec_dec_parse_format(), mimic_decode_frame(), mpeg4_decode_header(), mpeg_decode_postinit(), mpegvideo_extract_headers(), mvc_decode_init(), parse_presentation_segment(), pcx_decode_frame(), pgx_decode_frame(), photocd_decode_frame(), pix_decode_frame(), pixlet_decode_frame(), process_frame_obj(), ptx_decode_frame(), qoi_decode_frame(), rl2_decode_init(), rv20_decode_picture_header(), seqvideo_decode_init(), set_context_with_sequence(), set_output_format(), sga_decode_frame(), sunrast_decode_frame(), svc_decode_frame(), svq1_decode_frame(), svq3_decode_init(), tdsc_parse_tdsf(), tgq_decode_frame(), tgv_decode_frame(), tqi_decode_frame(), truemotion1_decode_header(), truemotion2rt_decode_header(), txd_decode_frame(), update_context_with_frame_header(), update_dimensions(), update_size(), v4l2_handle_event(), vbn_decode_frame(), vp56_size_changed(), vp5_parse_header(), vp6_parse_header(), vp8_lossless_decode_frame(), vpx_decode(), vqa_decode_init(), wbmp_decode_frame(), xbm_decode_frame(), xpm_decode_frame(), and xwd_decode_frame().

◆ ff_set_sar()

int ff_set_sar ( AVCodecContext avctx,
AVRational  sar 
)

◆ ff_side_data_update_matrix_encoding()

int ff_side_data_update_matrix_encoding ( AVFrame frame,
enum AVMatrixEncoding  matrix_encoding 
)

Add or update AV_FRAME_DATA_MATRIXENCODING side data.

Definition at line 124 of file utils.c.

Referenced by ac3_decode_frame(), ff_dca_core_filter_frame(), ff_dca_lbr_filter_frame(), ff_dca_xll_filter_frame(), and output_data().

◆ avpriv_codec_get_cap_skip_frame_fill_param()

int avpriv_codec_get_cap_skip_frame_fill_param ( const AVCodec codec)

Definition at line 405 of file utils.c.

Referenced by try_decode_frame().

◆ get_audio_frame_duration()

static int get_audio_frame_duration ( enum AVCodecID  id,
int  sr,
int  ch,
int  ba,
uint32_t  tag,
int  bits_per_coded_sample,
int64_t  bitrate,
uint8_t *  extradata,
int  frame_size,
int  frame_bytes 
)
static

Definition at line 570 of file utils.c.

Referenced by av_get_audio_frame_duration(), and av_get_audio_frame_duration2().

◆ ff_thread_init()

int ff_thread_init ( AVCodecContext s)

Definition at line 813 of file utils.c.

◆ av_xiphlacing()

unsigned int av_xiphlacing ( unsigned char *  s,
unsigned int  v 
)

Encode extradata length to a buffer.

Used by xiph codecs.

Parameters
sbuffer to write to; must be at least (v/255+1) bytes long
vsize of extradata in bytes
Returns
number of bytes written to the buffer.

Definition at line 820 of file utils.c.

Referenced by fixup_vorbis_headers(), libvorbis_encode_init(), parse_packed_headers(), put_main_header(), and track_header().

◆ ff_match_2uint16()

int ff_match_2uint16 ( const uint16_t(*)  tab[2],
int  size,
int  a,
int  b 
)

Return the index into tab at which {a,b} match elements {[0],[1]} of tab.

If there is no such matching pair then size is returned.

Definition at line 834 of file utils.c.

Referenced by ff_h263_encode_picture_header(), ff_mpv_encode_init(), and svq1_write_header().

◆ ff_thread_ref_frame()

int ff_thread_ref_frame ( ThreadFrame dst,
const ThreadFrame src 
)

◆ ff_thread_replace_frame()

int ff_thread_replace_frame ( ThreadFrame dst,
const ThreadFrame src 
)

Definition at line 872 of file utils.c.

Referenced by ff_h264_replace_picture().

◆ ff_thread_get_buffer()

int ff_thread_get_buffer ( AVCodecContext avctx,
AVFrame f,
int  flags 
)

Wrapper around get_buffer() for frame-multithreaded codecs.

Call this function instead of ff_get_buffer(f). Cannot be called after the codec has called ff_thread_finish_setup().

Parameters
avctxThe current context.
fThe frame to write into.

Definition at line 890 of file utils.c.

◆ ff_thread_get_ext_buffer()

int ff_thread_get_ext_buffer ( AVCodecContext avctx,
ThreadFrame f,
int  flags 
)

Wrapper around ff_get_buffer() for frame-multithreaded codecs.

Call this function instead of ff_get_buffer() if you might need to wait for progress on this frame. Cannot be called after the codec has called ff_thread_finish_setup().

Parameters
avctxThe current context.
fThe frame to write into.
Note
: It is fine to call this with codecs that do not support frame threading.

Definition at line 895 of file utils.c.

◆ ff_thread_release_ext_buffer()

void ff_thread_release_ext_buffer ( ThreadFrame f)

Unref a ThreadFrame.

This is basically a wrapper around av_frame_unref() and should be called instead of it.

Parameters
avctxThe current context.
fThe picture being released.

Definition at line 901 of file utils.c.

◆ ff_thread_finish_setup()

void ff_thread_finish_setup ( AVCodecContext avctx)

If the codec defines update_thread_context(), call this when they are ready for the next thread to start decoding the next frame.

After calling it, do not change any variables read by the update_thread_context() method, or call ff_thread_get_buffer().

Parameters
avctxThe context.

Definition at line 908 of file utils.c.

◆ ff_thread_report_progress()

void ff_thread_report_progress ( ThreadFrame f,
int  progress,
int  field 
)

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

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

Parameters
fThe picture being decoded.
progressValue, in arbitrary units, of how much of the picture has decoded.
fieldThe field being decoded, for field-picture codecs. 0 for top field or frame pictures, 1 for bottom field.

Definition at line 912 of file utils.c.

◆ ff_thread_await_progress()

void ff_thread_await_progress ( const ThreadFrame f,
int  progress,
int  field 
)

Wait for earlier decoding threads to finish reference pictures.

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

Parameters
fThe picture being referenced.
progressValue, in arbitrary units, to wait for.
fieldThe field being referenced, for field-picture codecs. 0 for top field or frame pictures, 1 for bottom field.

Definition at line 916 of file utils.c.

◆ ff_thread_can_start_frame()

int ff_thread_can_start_frame ( AVCodecContext avctx)

Definition at line 920 of file utils.c.

◆ ff_slice_thread_init_progress()

int ff_slice_thread_init_progress ( AVCodecContext avctx)

Definition at line 925 of file utils.c.

◆ ff_slice_thread_allocz_entries()

int ff_slice_thread_allocz_entries ( AVCodecContext avctx,
int  count 
)

Definition at line 930 of file utils.c.

◆ ff_thread_await_progress2()

void ff_thread_await_progress2 ( AVCodecContext avctx,
int  field,
int  thread,
int  shift 
)

Definition at line 935 of file utils.c.

◆ ff_thread_report_progress2()

void ff_thread_report_progress2 ( AVCodecContext avctx,
int  field,
int  thread,
int  n 
)

Definition at line 939 of file utils.c.

◆ avpriv_find_start_code()

const uint8_t* avpriv_find_start_code ( const uint8_t *restrict  p,
const uint8_t *  end,
uint32_t *restrict  state 
)

Definition at line 945 of file utils.c.

◆ av_cpb_properties_alloc()

AVCPBProperties* av_cpb_properties_alloc ( size_t *  size)

Allocate a CPB properties structure and initialize its fields to default values.

Parameters
sizeif non-NULL, the size of the allocated struct will be written here. This is useful for embedding it in side data.
Returns
the newly allocated struct or NULL on failure

Definition at line 978 of file utils.c.

Referenced by avformat_find_stream_info(), ff_encode_add_cpb_side_data(), and ff_mpv_encode_picture().

◆ bcd2uint()

static unsigned bcd2uint ( uint8_t  bcd)
static

Definition at line 992 of file utils.c.

Referenced by ff_alloc_timecode_sei().

◆ ff_alloc_timecode_sei()

int ff_alloc_timecode_sei ( const AVFrame frame,
AVRational  rate,
size_t  prefix_len,
void **  data,
size_t *  sei_size 
)

Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info.

Parameters
frameRaw frame to get S12M timecode side data from
rateThe frame rate
prefix_lenNumber of bytes to allocate before SEI message
dataPointer to a variable to store allocated memory Upon return the variable will hold NULL on error or if frame has no S12M timecode info. Otherwise it will point to prefix_len uninitialized bytes followed by *sei_size SEI message
sei_sizePointer to a variable to store generated SEI message length
Returns
Zero on success, negative error code on failure

Definition at line 1001 of file utils.c.

Referenced by prepare_sei_data_array().

◆ ff_guess_coded_bitrate()

int64_t ff_guess_coded_bitrate ( AVCodecContext avctx)

Get an estimated video bitrate based on frame size, frame rate and coded bits per pixel.

Definition at line 1065 of file utils.c.

Referenced by encode_init(), raw_encode_init(), v308_encode_init(), v408_encode_init(), v410_encode_init(), and y41p_encode_init().