FFmpeg
Macros | Functions | Variables
utils.c File Reference
#include <stdint.h>
#include "config.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/internal.h"
#include "libavutil/thread.h"
#include "libavutil/time.h"
#include "libavcodec/internal.h"
#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
#include "os_support.h"

Go to the source code of this file.

Macros

#define SANE_CHUNK_SIZE   (50000000)
 

Functions

int ff_lock_avformat (void)
 
int ff_unlock_avformat (void)
 
static int append_packet_chunked (AVIOContext *s, AVPacket *pkt, int size)
 
int av_get_packet (AVIOContext *s, AVPacket *pkt, int size)
 Allocate and read the payload of a packet and initialize its fields with default values. More...
 
int av_append_packet (AVIOContext *s, AVPacket *pkt, int size)
 Read data and append it to the current content of the AVPacket. More...
 
int av_filename_number_test (const char *filename)
 Check whether filename actually is a numbered sequence generator. More...
 
unsigned int ff_codec_get_tag (const AVCodecTag *tags, enum AVCodecID id)
 
enum AVCodecID ff_codec_get_id (const AVCodecTag *tags, unsigned int tag)
 
enum AVCodecID ff_get_pcm_codec_id (int bps, int flt, int be, int sflags)
 Select a PCM codec based on the given parameters. More...
 
unsigned int av_codec_get_tag (const AVCodecTag *const *tags, enum AVCodecID id)
 
int av_codec_get_tag2 (const AVCodecTag *const *tags, enum AVCodecID id, unsigned int *tag)
 
enum AVCodecID av_codec_get_id (const AVCodecTag *const *tags, unsigned int tag)
 
int ff_alloc_extradata (AVCodecParameters *par, int size)
 Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0. More...
 
uint64_t ff_ntp_time (void)
 Get the current time since NTP epoch in microseconds. More...
 
uint64_t ff_get_formatted_ntp_time (uint64_t ntp_time_us)
 Get the NTP time stamp formatted as per the RFC-5905. More...
 
uint64_t ff_parse_ntp_time (uint64_t ntp_ts)
 Parse the NTP time in micro seconds (since NTP epoch). More...
 
int av_get_frame_filename2 (char *buf, int buf_size, const char *path, int number, int flags)
 Return in 'buf' the path with 'd' replaced by a number. More...
 
int av_get_frame_filename (char *buf, int buf_size, const char *path, int number)
 
void av_url_split (char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
 Split a URL string into components. More...
 
int ff_mkdir_p (const char *path)
 Automatically create sub-directories. More...
 
char * ff_data_to_hex (char *buff, const uint8_t *src, int s, int lowercase)
 Write hexadecimal string corresponding to given binary data. More...
 
int ff_hex_to_data (uint8_t *data, const char *p)
 Parse a string of hexadecimal strings. More...
 
void ff_parse_key_value (const char *str, ff_parse_key_val_cb callback_get_buf, void *context)
 Parse a string with comma-separated key=value pairs. More...
 
int avformat_network_init (void)
 Do global initialization of network libraries. More...
 
int avformat_network_deinit (void)
 Undo the initialization done by avformat_network_init. More...
 
int ff_is_http_proto (const char *filename)
 Utility function to check if the file uses http or https protocol. More...
 
int ff_bprint_to_codecpar_extradata (AVCodecParameters *par, struct AVBPrint *buf)
 Finalize buf into extradata and set its size appropriately. More...
 

Variables

static AVMutex avformat_mutex = AV_MUTEX_INITIALIZER
 

Detailed Description

various utility functions for use within FFmpeg

Definition in file utils.c.

Macro Definition Documentation

◆ SANE_CHUNK_SIZE

#define SANE_CHUNK_SIZE   (50000000)

Definition at line 60 of file utils.c.

Function Documentation

◆ ff_lock_avformat()

int ff_lock_avformat ( void  )

◆ ff_unlock_avformat()

int ff_unlock_avformat ( void  )

◆ append_packet_chunked()

static int append_packet_chunked ( AVIOContext s,
AVPacket pkt,
int  size 
)
static

Definition at line 64 of file utils.c.

Referenced by av_append_packet(), and av_get_packet().

◆ av_get_packet()

int av_get_packet ( AVIOContext s,
AVPacket pkt,
int  size 
)

Allocate and read the payload of a packet and initialize its fields with default values.

Parameters
sassociated IO context
pktpacket
sizedesired payload size
Returns
>0 (read size) if OK, AVERROR_xxx otherwise

Definition at line 103 of file utils.c.

Referenced by aa_read_packet(), aal_read_packet(), aax_read_packet(), ac4_read_packet(), ace_read_packet(), adp_read_packet(), ads_read_packet(), adts_aac_read_packet(), adx_read_packet(), aea_read_packet(), afc_read_packet(), aiff_read_packet(), aix_read_packet(), apc_read_packet(), aptx_hd_read_packet(), aptx_read_packet(), argo_brp_read_packet(), asf_read_header(), asf_read_subpayload(), ast_read_packet(), audio_frame_obu(), av_append_packet(), avi_read_packet(), bfi_read_packet(), cdata_read_packet(), cdxl_read_packet(), cin_read_packet(), cine_read_packet(), codec2_read_packet(), dat_read_packet(), daud_packet(), dcstr_read_packet(), dfa_read_packet(), dhav_read_packet(), dsf_read_packet(), dxa_read_packet(), ea_read_packet(), evc_read_packet(), ff_add_attached_pic(), ff_pcm_read_packet(), ff_rm_parse_packet(), ff_rm_retrieve_cache(), ff_voc_get_packet(), film_read_packet(), flv_data_packet(), flv_read_packet(), fourxm_read_packet(), frm_read_packet(), fsb_read_packet(), g726_read_packet(), g729_read_packet(), gdv_read_packet(), genh_read_packet(), gsm_read_packet(), gxf_packet(), hca_read_packet(), hnm_read_packet(), idcin_read_packet(), iff_read_packet(), ifv_read_packet(), ilbc_read_packet(), ingenient_read_packet(), iss_read_packet(), lmlm4_read_packet(), load_ipmovie_packet(), lvf_read_packet(), mmf_read_packet(), mods_read_packet(), mov_read_packet(), mp3_read_packet(), mpc8_read_packet(), mpegps_read_packet(), mpjpeg_read_packet(), msf_read_packet(), msnwc_tcp_read_packet(), msp_read_packet(), mtaf_read_packet(), mtv_read_packet(), musx_read_packet(), mv_read_packet(), mxf_decrypt_triplet(), mxf_get_d10_aes3_packet(), mxf_get_eia608_packet(), mxf_read_packet(), nc_read_packet(), nsv_read_chunk(), nuv_packet(), parse_chunk(), pdv_read_packet(), pmp_packet(), pp_bnk_read_packet(), pva_read_packet(), qcp_read_packet(), r3d_read_reda(), r3d_read_redv(), raw_read_packet(), rawvideo_read_packet(), read_dst_frame(), read_packet(), redspark_read_packet(), rka_read_packet(), rl2_read_packet(), roq_read_packet(), rpl_read_packet(), rsd_read_packet(), s337m_read_packet(), scd_read_packet(), sdns_read_packet(), sdr2_read_packet(), seq_read_packet(), ser_read_packet(), siff_read_packet(), simbiosis_imx_read_packet(), smacker_read_packet(), smjpeg_read_packet(), smush_read_packet(), sol_read_packet(), sup_read_packet(), svag_read_packet(), svs_read_packet(), swf_read_packet(), thp_read_packet(), threedostr_read_packet(), tmv_read_packet(), tta_read_packet(), txd_read_packet(), vag_read_packet(), vc1t_read_packet(), vid_read_packet(), viv_read_packet(), vivo_read_packet(), vpk_read_packet(), wavarc_read_packet(), wc3_read_packet(), wsaud_read_packet(), wsvqa_read_packet(), xa_read_packet(), xmv_fetch_audio_packet(), xmv_fetch_video_packet(), xvag_read_packet(), xwma_read_packet(), yop_read_packet(), and yuv4_read_packet().

◆ av_append_packet()

int av_append_packet ( AVIOContext s,
AVPacket pkt,
int  size 
)

Read data and append it to the current content of the AVPacket.

If pkt->size is 0 this is identical to av_get_packet. Note that this uses av_grow_packet and thus involves a realloc which is inefficient. Thus this function should only be used when there is no reasonable way to know (an upper bound of) the final size.

Parameters
sassociated IO context
pktpacket
sizeamount of data to read
Returns
>0 (read size) if OK, AVERROR_xxx otherwise, previous data will not be lost even if an error occurs.

Definition at line 119 of file utils.c.

Referenced by adts_aac_read_packet(), apng_read_packet(), dfa_read_packet(), ea_read_packet(), fits_read_packet(), handle_id3(), is_image(), moflex_read_packet(), mpjpeg_read_packet(), msp_read_packet(), read_packet(), sup_read_packet(), vivo_read_packet(), wc3_read_header(), wc3_read_packet(), and wsvqa_read_packet().

◆ ff_codec_get_tag()

unsigned int ff_codec_get_tag ( const AVCodecTag tags,
enum AVCodecID  id 
)

◆ ff_codec_get_id()

enum AVCodecID ff_codec_get_id ( const AVCodecTag tags,
unsigned int  tag 
)

◆ ff_get_pcm_codec_id()

enum AVCodecID ff_get_pcm_codec_id ( int  bps,
int  flt,
int  be,
int  sflags 
)

Select a PCM codec based on the given parameters.

Parameters
bpsbits-per-sample
fltfloating-point
bebig-endian
sflagssigned flags. each bit corresponds to one byte of bit depth. e.g. the 1st bit indicates if 8-bit should be signed or unsigned, the 2nd bit indicates if 16-bit should be signed or unsigned, etc... This is useful for formats such as WAVE where only 8-bit is unsigned and all other bit depths are signed.
Returns
a PCM codec id or AV_CODEC_ID_NONE

Definition at line 156 of file utils.c.

Referenced by avr_read_header(), ff_mov_get_lpcm_codec_id(), ff_wav_codec_get_id(), get_codec_data(), nist_read_header(), and pvf_read_header().

◆ av_codec_get_tag()

unsigned int av_codec_get_tag ( const AVCodecTag *const *  tags,
enum AVCodecID  id 
)

Definition at line 205 of file utils.c.

◆ av_codec_get_tag2()

int av_codec_get_tag2 ( const AVCodecTag *const *  tags,
enum AVCodecID  id,
unsigned int tag 
)

Definition at line 213 of file utils.c.

Referenced by av_codec_get_tag().

◆ av_codec_get_id()

enum AVCodecID av_codec_get_id ( const AVCodecTag *const *  tags,
unsigned int  tag 
)

Definition at line 229 of file utils.c.

◆ ff_alloc_extradata()

int ff_alloc_extradata ( AVCodecParameters par,
int  size 
)

Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0.

Previously allocated extradata in par will be freed.

Parameters
sizesize of extradata
Returns
0 if OK, AVERROR_xxx on error

Definition at line 239 of file utils.c.

Referenced by ace_read_header(), adts_write_packet(), afc_read_header(), ape_read_header(), apng_read_header(), celt_header(), codec2_read_header(), codec2raw_read_header(), concat_parse_script(), copy_stream_props(), dfa_read_header(), encode_intervals(), ff_generate_avci_extradata(), ff_get_extradata(), ff_parse_mpeg2_descriptor(), flac_header(), flv_set_video_codec(), flv_write_packet(), fsb_read_header(), genh_read_header(), hca_read_header(), hcom_read_header(), hevc_parse_sdp_line(), hnm_read_header(), iff_read_header(), latm_write_packet(), microdvd_read_header(), mkv_update_codecprivate(), mov_create_chapter_track(), mov_read_dops(), mov_rewrite_dvd_sub_extradata(), msf_read_header(), mxf_parse_structural_metadata(), nist_read_header(), nsv_parse_NSVs_header(), ogm_header(), oma_read_header(), opus_header(), opus_write_extradata(), parse_fmtp_config(), parse_packed_headers(), qdm2_parse_config(), read_header(), read_kuki_chunk(), redspark_read_header(), rsd_read_header(), sdns_read_header(), seg_write_packet(), smacker_read_header(), smush_read_header(), speex_header(), svq3_parse_packet(), track_header(), tta_read_header(), update_stream_extradata(), vmd_read_header(), vqf_read_header(), wavarc_read_header(), wsvqa_read_packet(), wv_read_header(), xmv_process_packet_header(), and xwma_read_header().

◆ ff_ntp_time()

uint64_t ff_ntp_time ( void  )

Get the current time since NTP epoch in microseconds.

Definition at line 259 of file utils.c.

Referenced by mov_write_prft_tag(), rtp_write_header(), rtp_write_packet(), and rtp_write_trailer().

◆ ff_get_formatted_ntp_time()

uint64_t ff_get_formatted_ntp_time ( uint64_t  ntp_time_us)

Get the NTP time stamp formatted as per the RFC-5905.

Parameters
ntp_timeNTP time in micro seconds (since NTP epoch)
Returns
the formatted NTP time stamp

Definition at line 264 of file utils.c.

Referenced by mov_write_prft_tag().

◆ ff_parse_ntp_time()

uint64_t ff_parse_ntp_time ( uint64_t  ntp_ts)

Parse the NTP time in micro seconds (since NTP epoch).

Parameters
ntp_tsNTP time stamp formatted as per the RFC-5905.
Returns
the time in micro seconds (since NTP epoch)

Definition at line 286 of file utils.c.

Referenced by rtp_set_prft().

◆ ff_mkdir_p()

int ff_mkdir_p ( const char *  path)

Automatically create sub-directories.

Parameters
pathwill create sub-directories by path
Returns
0, or < 0 on error

Definition at line 421 of file utils.c.

Referenced by format_name(), and hls_start().

◆ ff_data_to_hex()

char* ff_data_to_hex ( char *  buf,
const uint8_t *  src,
int  size,
int  lowercase 
)

Write hexadecimal string corresponding to given binary data.

The string is zero-terminated.

Parameters
bufthe output string is written here; needs to be at least 2 * size + 1 bytes long.
srcthe input data to be transformed.
sizethe size (in byte) of src.
lowercasedetermines whether to use the range [0-9a-f] or [0-9A-F].
Returns
buf.

Definition at line 455 of file utils.c.

Referenced by aa_read_header(), do_encrypt(), do_llnw_auth(), ff_rdt_calc_response_and_checksum(), hex_log(), hls_encryption_start(), hls_read_header(), make_digest_auth(), md5_close(), mov_read_adrm(), mxf_umid_to_str(), open_input(), param_write_hex(), and tak_read_header().

◆ ff_hex_to_data()

int ff_hex_to_data ( uint8_t *  data,
const char *  p 
)

Parse a string of hexadecimal strings.

Any space between the hexadecimal digits is ignored.

Parameters
dataif non-null, the parsed data is written to this pointer
pthe string to parse
Returns
the number of bytes written (or to be written, if data is null)

Definition at line 476 of file utils.c.

Referenced by concat_parse_script(), parse_fmtp_config(), and parse_playlist().

◆ ff_parse_key_value()

void ff_parse_key_value ( const char *  str,
ff_parse_key_val_cb  callback_get_buf,
void *  context 
)

Parse a string with comma-separated key=value pairs.

The value strings may be quoted and may contain escaped characters within quoted strings.

Parameters
strthe string to parse
callback_get_buffunction that returns where to store the unescaped value string.
contextthe opaque context pointer to pass to callback_get_buf

Definition at line 504 of file utils.c.

Referenced by ff_http_auth_handle_header(), and parse_playlist().

◆ ff_is_http_proto()

int ff_is_http_proto ( const char *  filename)

Utility function to check if the file uses http or https protocol.

Parameters
sAVFormatContext
filenameURL or file name to open for writing

Definition at line 579 of file utils.c.

Referenced by dashenc_delete_file(), dashenc_io_close(), dashenc_io_open(), hls_init(), hlsenc_io_close(), hlsenc_io_open(), and set_http_options().

◆ ff_bprint_to_codecpar_extradata()

int ff_bprint_to_codecpar_extradata ( AVCodecParameters par,
struct AVBPrint *  buf 
)

Finalize buf into extradata and set its size appropriately.

Definition at line 584 of file utils.c.

Referenced by ass_read_header(), ff_dvdclut_palette_extradata_cat(), jacosub_read_header(), sami_read_header(), and subviewer_read_header().

Variable Documentation

◆ avformat_mutex

AVMutex avformat_mutex = AV_MUTEX_INITIALIZER
static

Definition at line 42 of file utils.c.

Referenced by ff_lock_avformat(), and ff_unlock_avformat().