FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
Memory Management

Macros

#define DECLARE_ALIGNED(n, t, v)   t __attribute__ ((aligned (n))) v
 
#define DECLARE_ASM_CONST(n, t, v)   static const t av_used __attribute__ ((aligned (n))) v
 
#define av_malloc_attrib   __attribute__((__malloc__))
 
#define av_alloc_size(...)   __attribute__((alloc_size(__VA_ARGS__)))
 

Functions

voidav_malloc (size_t size) av_malloc_attrib 1(1)
 Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU). More...
 
static voidav_malloc_array (size_t nmemb, size_t size)
 
voidav_realloc (void *ptr, size_t size) 1(2)
 Allocate or reallocate a block of memory. More...
 
voidav_realloc_f (void *ptr, size_t nelem, size_t elsize)
 Allocate or reallocate a block of memory. More...
 
av_warn_unused_result int av_reallocp (void *ptr, size_t size)
 Allocate or reallocate a block of memory. More...
 
voidav_realloc_array (void *ptr, size_t nmemb, size_t size)
 
int av_reallocp_array (void *ptr, size_t nmemb, size_t size)
 
void av_free (void *ptr)
 Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). More...
 
voidav_mallocz (size_t size) av_malloc_attrib 1(1)
 Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block. More...
 
voidav_calloc (size_t nmemb, size_t size) av_malloc_attrib
 Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block. More...
 
static voidav_mallocz_array (size_t nmemb, size_t size)
 
char * av_strdup (const char *s) av_malloc_attrib
 Duplicate the string s. More...
 
char * av_strndup (const char *s, size_t len) av_malloc_attrib
 Duplicate a substring of the string s. More...
 
voidav_memdup (const void *p, size_t size)
 Duplicate the buffer p. More...
 
void av_freep (void *ptr)
 Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer pointing to it to NULL. More...
 
void av_dynarray_add (void *tab_ptr, int *nb_ptr, void *elem)
 Add an element to a dynamic array. More...
 
av_warn_unused_result int av_dynarray_add_nofree (void *tab_ptr, int *nb_ptr, void *elem)
 Add an element to a dynamic array. More...
 
voidav_dynarray2_add (void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
 Add an element of size elem_size to a dynamic array. More...
 
static int av_size_mult (size_t a, size_t b, size_t *r)
 Multiply two size_t values checking for overflow. More...
 
void av_max_alloc (size_t max)
 Set the maximum size that may me allocated in one block. More...
 
void av_memcpy_backptr (uint8_t *dst, int back, int cnt)
 deliberately overlapping memcpy implementation More...
 
voidav_fast_realloc (void *ptr, unsigned int *size, size_t min_size)
 Reallocate the given block if it is not large enough, otherwise do nothing. More...
 
void av_fast_malloc (void *ptr, unsigned int *size, size_t min_size)
 Allocate a buffer, reusing the given one if large enough. More...
 
void av_fast_mallocz (void *ptr, unsigned int *size, size_t min_size)
 Allocate a buffer, reusing the given one if large enough. More...
 

Detailed Description

Macro Definition Documentation

#define DECLARE_ALIGNED (   n,
  t,
 
)    t __attribute__ ((aligned (n))) v
#define DECLARE_ASM_CONST (   n,
  t,
 
)    static const t av_used __attribute__ ((aligned (n))) v

Definition at line 54 of file mem.h.

#define av_malloc_attrib   __attribute__((__malloc__))

Definition at line 64 of file mem.h.

#define av_alloc_size (   ...)    __attribute__((alloc_size(__VA_ARGS__)))

Definition at line 70 of file mem.h.

Function Documentation

void* av_malloc ( size_t  size)

Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU).

Parameters
sizeSize in bytes for the memory block to be allocated.
Returns
Pointer to the allocated block, NULL if the block cannot be allocated.
See Also
av_mallocz()

Definition at line 77 of file mem.c.

Referenced by av_malloc(), av_malloc_array(), av_mallocz(), av_memdup(), and av_realloc().

static void* av_malloc_array ( size_t  nmemb,
size_t  size 
)
inlinestatic

Definition at line 93 of file mem.h.

void* av_realloc ( void ptr,
size_t  size 
)

Allocate or reallocate a block of memory.

If ptr is NULL and size > 0, allocate a new block. If size is zero, free the memory block pointed to by ptr.

Parameters
ptrPointer to a memory block already allocated with av_realloc() or NULL.
sizeSize in bytes of the memory block to be allocated or reallocated.
Returns
Pointer to a newly-reallocated block or NULL if the block cannot be reallocated or the function is used to free the memory block.
Warning
Pointers originating from the av_malloc() family of functions must not be passed to av_realloc(). The former can be implemented using memalign() (or other functions), and there is no guarantee that pointers from such functions can be passed to realloc() at all. The situation is undefined according to POSIX and may crash with some libc implementations.
See Also
av_fast_realloc()

Definition at line 145 of file mem.c.

Referenced by add_crc_to_array(), add_file(), append_extradata(), av_bprint_alloc(), av_bprint_finalize(), av_buffer_realloc(), av_dict_set(), av_fast_realloc(), av_frame_new_side_data(), av_packet_add_side_data(), av_packet_pack_dictionary(), av_realloc_array(), av_realloc_f(), av_reallocp(), av_strdup(), av_strndup(), avfilter_graph_alloc_filter(), concat_open(), decode_frame(), decode_header(), draw_text(), epic_hash_add(), ff_els_decode_unsigned(), ff_h264_parse_sprop_parameter_sets(), ff_img_read_header(), ff_rtmp_packet_create(), ff_vs_init(), fixup_vorbis_headers(), get_qt_codec(), huf_build_dec_table(), load_textfile(), main(), match_streams(), matroska_decode_buffer(), matroska_deliver_packet(), matroska_parse_wavpack(), mov_read_ctts(), mov_read_trun(), nut_read_header(), ogg_new_stream(), parse_adaptation_sets(), probe_codec(), qt_rtp_parse_packet(), and xmlescape().

void* av_realloc_f ( void ptr,
size_t  nelem,
size_t  elsize 
)

Allocate or reallocate a block of memory.

This function does the same thing as av_realloc, except:

  • It takes two arguments and checks the result of the multiplication for integer overflow.
  • It frees the input block in case of failure, thus avoiding the memory leak with the classic "buf = realloc(buf); if (!buf) return -1;".

Definition at line 172 of file mem.c.

Referenced by av_reallocp_array().

av_warn_unused_result int av_reallocp ( void ptr,
size_t  size 
)

Allocate or reallocate a block of memory.

If *ptr is NULL and size > 0, allocate a new block. If size is zero, free the memory block pointed to by ptr.

Parameters
ptrPointer to a pointer to a memory block already allocated with av_realloc(), or pointer to a pointer to NULL. The pointer is updated on success, or freed on failure.
sizeSize in bytes for the memory block to be allocated or reallocated
Returns
Zero on success, an AVERROR error code on failure.
Warning
Pointers originating from the av_malloc() family of functions must not be passed to av_reallocp(). The former can be implemented using memalign() (or other functions), and there is no guarantee that pointers from such functions can be passed to realloc() at all. The situation is undefined according to POSIX and may crash with some libc implementations.

Definition at line 187 of file mem.c.

Referenced by add_fragment(), add_segment(), add_tracked_method(), alloc_and_copy(), append_flv_data(), asfrtp_parse_packet(), auxiliary_info_alloc_size(), av_probe_input_buffer2(), av_vdpau_bind_context(), avi_read_header(), bmv_read_packet(), concat_open(), concatenate_packet(), daala_header(), decode_frame(), decode_registered_user_data_closed_caption(), dxv_decode(), dyn_buf_write(), ff_lzf_uncompress(), ffm_append_recommended_configuration(), fixup_vorbis_headers(), flashsv_decode_frame(), g2m_load_cursor(), get_tcp_server_response(), h264_extradata_to_annexb(), handle_metadata(), hap_decode(), hevc_extradata_to_annexb(), hevc_mp4toannexb_filter(), http_open(), jpg_decode_data(), libschroedinger_encode_frame(), mov_cenc_end_packet(), mov_realloc_extradata(), parse_icy(), qt_rtp_parse_packet(), queue_frames(), rdt_parse_sdp_line(), realloc_buffer(), rtmp_http_write(), rtmp_open(), rtmp_write(), set_segment_filename(), smacker_read_packet(), tdsc_decode_frame(), tdsc_decode_tiles(), tdsc_init(), tdsc_load_cursor(), tgv_decode_inter(), theora_header(), tls_client_handshake_loop(), tls_read(), and vpx_init().

void* av_realloc_array ( void ptr,
size_t  nmemb,
size_t  size 
)
int av_reallocp_array ( void ptr,
size_t  nmemb,
size_t  size 
)
void av_free ( void ptr)

Free a memory block which has been allocated with av_malloc(z)() or av_realloc().

Parameters
ptrPointer to the memory block which should be freed.
Note
ptr = NULL is explicitly allowed.
It is recommended that you use av_freep() instead.
See Also
av_freep()

Definition at line 228 of file mem.c.

Referenced by av_freep(), and av_realloc_f().

void* av_mallocz ( size_t  size)

Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block.

Parameters
sizeSize in bytes for the memory block to be allocated.
Returns
Pointer to the allocated block, NULL if it cannot be allocated.
See Also
av_malloc()

Definition at line 252 of file mem.c.

Referenced by a64multi_encode_init(), aac_adtstoasc_filter(), aac_decode_frame(), aac_encode_init(), add_av_stream1(), add_codec(), add_fragment(), add_input_streams(), add_pes_stream(), add_segment(), add_to_pktbuf(), add_to_queue(), aiff_write_packet(), alac_encode_init(), allocate_buffers(), allocate_tables(), ape_read_header(), asf_read_picture(), asf_read_stream_properties(), atrac3_decode_init(), av_abuffersink_params_alloc(), av_aes_alloc(), av_aes_ctr_alloc(), av_audio_fifo_alloc(), av_audio_resample_init(), av_bitstream_filter_init(), av_blowfish_alloc(), av_buffer_create(), av_buffer_pool_init(), av_buffer_ref(), av_calloc(), av_camellia_alloc(), av_cast5_alloc(), av_cpb_properties_alloc(), av_des_alloc(), av_dict_set(), av_dump_format(), av_expr_parse(), av_fft_init(), av_frame_alloc(), av_frame_new_side_data(), av_hash_alloc(), av_hmac_alloc(), av_mallocz_array(), av_mastering_display_metadata_alloc(), av_md5_alloc(), av_murmur3_alloc(), av_new_program(), av_opencl_alloc_external_env(), av_opencl_get_device_list(), av_opt_query_ranges_default(), av_packet_alloc(), av_packet_new_side_data(), av_packet_split_side_data(), av_parser_init(), av_rc4_alloc(), av_resample_init(), av_ripemd_alloc(), av_sha512_alloc(), av_sha_alloc(), av_stereo3d_alloc(), av_tea_alloc(), av_thread_message_queue_alloc(), av_tree_node_alloc(), av_twofish_alloc(), av_vdpau_alloc_context(), av_vorbis_parse_init(), av_xtea_alloc(), avcodec_dct_alloc(), avcodec_get_context_defaults3(), avcodec_open2(), avdevice_capabilities_create(), avdevice_list_devices(), avfilter_graph_alloc(), avfilter_graph_queue_command(), avfilter_inout_alloc(), avfilter_link(), avformat_alloc_context(), avformat_alloc_output_context2(), avformat_new_stream(), avformat_open_input(), avi_read_header(), avi_write_header(), avio_alloc_context(), avio_open_dir(), avpriv_ac3_parse_header(), avpriv_dv_init_demux(), avpriv_float_dsp_alloc(), avpriv_mpegts_parse_open(), avpriv_new_chapter(), avresample_alloc_context(), avui_encode_init(), bfi_decode_init(), callback(), che_configure(), check_field_queue(), compute_mask(), config_output(), cook_decode_init(), copy_chapters(), D(), daala_header(), dash_write_header(), decode_dvd_subtitles(), decode_frame(), decode_init(), decode_pic(), DEF_CHOOSE_FORMAT(), dfa_decode_init(), display_end_segment(), doTest(), dss_read_metadata_string(), dv_read_timecode(), dvbsub_parse_display_definition_segment(), dvbsub_parse_page_segment(), dvbsub_parse_region_segment(), dxva2_alloc(), dxva2_create_decoder(), dxva2_get_buffer(), encode_frame(), encode_init(), encode_picture_ls(), enqueue_packet(), epic_add_pixel_to_cache(), extract_mpeg4_header(), ff_all_channel_counts(), ff_all_channel_layouts(), ff_all_samplerates(), ff_alloc_dir_entry(), ff_alloc_input_device_context(), ff_alsa_get_device_list(), ff_ass_add_rect(), ff_ass_split(), ff_audio_data_alloc(), ff_audio_mix_alloc(), ff_audio_resample_init(), ff_avc_write_annexb_extradata(), ff_cavs_init_top_lines(), ff_celt_init(), ff_decklink_read_header(), ff_decklink_write_header(), ff_dither_alloc(), ff_fast_malloc(), ff_fbdev_get_device_list(), ff_ffv1_init_slice_contexts(), ff_filter_alloc(), ff_frame_thread_encoder_init(), ff_frame_thread_init(), ff_graph_thread_init(), ff_h264_decode_picture_parameter_set(), ff_h264_decode_seq_parameter_set(), ff_hevc_decode_nal_pps(), ff_iir_filter_init_state(), ff_imdct15_init(), ff_init_vscale(), ff_interleave_add_packet(), ff_intrax8_common_init(), ff_ivi_init_planes(), ff_jpegls_decode_picture(), ff_lpc_init(), ff_lzw_decode_open(), ff_merge_channel_layouts(), ff_mpeg_er_init(), ff_nut_add_sp(), ff_parse_mpeg2_descriptor(), ff_pca_init(), ff_psy_preprocess_init(), ff_rate_control_init(), ff_rdt_parse_open(), ff_read_riff_info(), ff_rfps_add_frame(), ff_rm_alloc_rmstream(), ff_rtp_parse_open(), ff_rtsp_setup_output_streams(), ff_schro_queue_push_back(), ff_silk_init(), ff_slice_thread_init(), ff_timefilter_new(), ff_vc1_decode_init_alloc_tables(), ff_video_frame_pool_init(), ff_vs_init(), ff_wms_parse_sdp_a_line(), ffmal_update_format(), ffmmal_add_packet(), ffmmal_set_ref(), ffserver_parse_acl_row(), ffserver_parse_config_feed(), ffserver_parse_config_redirect(), ffserver_parse_config_stream(), fifo_alloc_common(), find_headers_search_validate(), flac_read_header(), flashsv2_encode_init(), flashsv_decode_frame(), flashsv_encode_frame(), flashsv_encode_init(), flv_queue_extradata(), flv_write_header(), g2m_init_buffers(), gen_sub_bitmap(), generate_fake_vps(), generate_joint_tables(), get_buffer(), get_buffer2(), get_device_list(), get_free_frame(), get_http_header_data(), get_private_data(), get_siz(), get_surface(), gif_encode_init(), gxf_write_header(), handle_file(), handler(), hevc_init_context(), hls_slice_data_wpp(), hnm_decode_init(), hnm_read_header(), htmlencode(), http_prepare_data(), iec61883_callback(), init(), init_bundles(), init_complex_filtergraph(), init_fps(), init_input_filter(), init_muxer(), init_output_stream(), init_pts(), lavfi_read_header(), libkvazaar_init(), libschroedinger_encode_frame(), link_filter_inouts(), load_glyph(), main(), make_eval_expr(), make_field_queue(), make_point(), matroska_parse_frame(), matroska_parse_laces(), matroska_parse_rm_audio(), matroska_parse_tracks(), matroska_parse_webvtt(), mkv_start_cues(), mkv_start_seekhead(), mkv_write_header(), mmsh_open_internal(), mmsh_read_seek(), mov_read_chapters(), mov_read_covr(), mov_read_dref(), mov_read_keys(), mov_read_sidx(), mov_read_trak(), mov_read_udta_string(), mov_read_uuid(), mov_read_wave(), mov_rewrite_dvd_sub_extradata(), mov_text_encode_init(), mov_text_tx3g(), mov_write_dvc1_structs(), mpeg_mux_init(), mpeg_mux_write_packet(), mpegts_add_service(), mpegts_init(), mpegts_open_filter(), mss2_decode_init(), mxf_handle_missing_index_segment(), mxf_parse_package_comments(), mxf_read_local_tags(), mxf_timestamp_to_str(), mxf_uid_to_str(), mxf_umid_to_str(), mxf_write_header(), mxpeg_decode_mxm(), new_connection(), new_init_section(), new_output_stream(), new_playlist(), new_rendition(), new_stream(), new_variant(), new_video_stream(), nsv_parse_NSVf_header(), nsv_parse_NSVs_header(), nvenc_encode_init(), ogg_buffer_page(), ogg_build_flac_headers(), ogg_build_opus_headers(), ogg_build_speex_headers(), ogg_save(), ogg_write_header(), ogg_write_vorbiscomment(), opaque_list_push(), open_input_file(), open_output_file(), opt_channel_layout(), opt_filter_complex(), opt_filter_complex_script(), opus_header(), paf_video_init(), parse_dynamic_acl(), parse_fmtp_config(), parse_inputs(), parse_keyframes_index(), parse_primary(), parse_sws_flags(), parse_vtrk(), pic_arrays_init(), pool_alloc_buffer(), pp_get_context(), prepare_sdp_description(), process_output_surface(), psy_3gpp_init(), pthread_cond_init(), pulse_add_detected_device(), put_main_header(), qsv_h264_set_encode_ctrl(), qsv_transcode_init(), qt_rtp_parse_packet(), qtrle_encode_init(), rdt_parse_b64buf(), read_apic(), read_gab2_sub(), read_geobtag(), read_header(), read_packet(), read_priv(), read_tfra(), reallocAlign(), resample_init(), rl2_decode_init(), rtp_new_connection(), rtp_parse_addr_list(), rv34_decoder_alloc(), sap_write_header(), segment_end(), set_encoder_id(), setup_hwaccel(), smacker_decode_header_tree(), smka_decode_frame(), sp5x_decode_frame(), speex_header(), stream_open(), subtitle_thread(), svc_encode_init(), svq1_encode_init(), svq1_encode_plane(), svq3_decode_init(), swr_alloc(), swri_rematrix_init(), sws_alloc_context(), tgv_decode_frame(), theora_header(), transcode_init(), update_block_buffers(), update_dimensions(), url_alloc_for_protocol(), url_open_dyn_buf_internal(), utvideo_encode_init(), v4l2_get_device_list(), vc1_decode_frame(), vc1_decode_init(), vda_old_h264_end_frame(), vdpau_alloc(), videostream_cb(), videotoolbox_init(), vorbis_header(), vorbis_parse_setup_hdr_codebooks(), vorbis_parse_setup_hdr_floors(), vorbis_parse_setup_hdr_mappings(), vorbis_parse_setup_hdr_modes(), vorbis_parse_setup_hdr_residues(), vp6_decode_init(), vqa_decode_init(), wmv2_encode_init(), worker(), write_frame(), write_packet(), writer_open(), wtvfile_open_sector(), wv_alloc_frame_context(), X264_frame(), and X264_init().

void* av_calloc ( size_t  nmemb,
size_t  size 
)
static void* av_mallocz_array ( size_t  nmemb,
size_t  size 
)
inlinestatic
Examples:
qsvdec.c.

Definition at line 229 of file mem.h.

Referenced by a64multi_encode_init(), alloc_sequence_buffers(), alloc_slice(), allocate_buffers(), allocate_tables(), atrac3_decode_init(), atrac3p_decode_init(), audio_get_buffer(), av_audio_fifo_alloc(), av_frame_ref(), av_resample_init(), avcodec_fill_audio_frame(), channelmap_filter_frame(), check_stream_max_drift(), cng_decode_init(), compute_mask(), config_output(), copy_separable_masks(), D(), decode_entropy_coded_image(), decode_init(), decode_lowdelay(), decode_picture_header(), dejudder_init(), display_end_segment(), dnxhd_decode_init(), dnxhd_decode_init_thread_copy(), encode_init(), ff_alloc_entries(), ff_cavs_init_top_lines(), ff_ffv1_init_slice_state(), ff_filter_alloc(), ff_frame_thread_init(), ff_init_filters(), ff_init_vscale(), ff_ivi_init_planes(), ff_ivi_init_tiles(), ff_jpeg2000_init_component(), ff_jpeg2000_tag_tree_init(), ff_mjpeg_decode_sof(), ff_opus_parse_extradata(), ff_png_zalloc(), ff_psy_init(), ff_qsv_enc_init(), ff_slice_buffer_init(), ff_slice_thread_init(), ff_snow_alloc_blocks(), ff_snow_common_init_after_header(), ffserver_parse_config_feed(), frame_alloc(), g2m_init_buffers(), g722_encode_init(), get_audio_buffer(), get_buffer(), get_device_list(), get_siz(), h264_init_context(), hds_write_header(), http_prepare_data(), http_server(), huf_uncompress(), ico_write_header(), init(), init_band(), init_opaque_surf(), init_parse_context(), init_pattern_from_string(), init_prec(), init_tiles(), ism_write_header(), ivi_init_tiles(), join_config_output(), join_init(), libopus_encode_init(), main(), mkv_write_header(), mov_read_sidx(), mov_write_header(), mp_decode_init(), mxf_compute_index_tables(), opus_decode_init(), pic_arrays_init(), psy_3gpp_init(), qtrle_encode_init(), read_huffman_code_normal(), read_shape_from_file(), read_tfra(), ready_codebook(), ready_residue(), roq_encode_init(), rtsp_read_header(), sap_write_header(), setup_find_stream_info_opts(), smacker_decode_header_tree(), subtitle_thread(), swri_realloc_audio(), thread_init_internal(), tiff_decode_tag(), try_push_frame(), vorbis_parse_id_hdr(), vorbis_parse_setup_hdr_codebooks(), vorbis_parse_setup_hdr_floors(), vorbis_parse_setup_hdr_mappings(), and XAVS_init().

char* av_strdup ( const char *  s)

Duplicate the string s.

Parameters
sstring to be duplicated
Returns
Pointer to a newly-allocated string containing a copy of s or NULL if the string cannot be allocated.

Definition at line 267 of file mem.c.

Referenced by add_av_stream(), add_codec(), add_input_streams(), add_tracked_method(), av_append_path_component(), av_dict_get_string(), av_dict_set(), av_opt_copy(), av_opt_get(), av_tempfile(), avfilter_graph_parse(), avfilter_graph_queue_command(), avfilter_init_str(), avformat_match_stream_specifier(), avformat_open_input(), caca_write_header(), choose_pix_fmts(), cine_read_header(), config_input(), config_output(), configure_filtergraph(), decimate_init(), draw_curves(), dump_stream_format(), ebml_parse_nest(), ff_alsa_get_device_list(), ff_copy_whitelists(), ff_fbdev_get_device_list(), ff_filter_alloc(), ff_http_do_new_request(), ff_http_match_no_proxy(), ff_img_read_header(), ff_mpv_encode_init(), ff_stream_add_bitstream_filter(), ff_tls_open_underlying(), ffio_fdopen(), ffm2_read_header(), ffm_read_header(), ffserver_parse_config_feed(), ffserver_parse_config_stream(), ffurl_connect(), fieldmatch_init(), frei0r_init(), ftp_connect(), ftp_current_dir(), ftp_parse_entry_mlsd(), ftp_parse_entry_nlst(), geq_init(), get_cookies(), get_geokey_val(), get_opt_flags_string(), get_ost_filters(), grab_read_header(), hls_delete_old_segments(), hls_write_header(), http_open(), icecast_open(), init(), init_filter(), init_filters(), initialize(), join_init(), lavfi_read_header(), libsmbc_read_dir(), libssh_read_dir(), main(), microdvd_read_header(), mkv_write_simpletag(), movie_common_init(), mpegts_add_service(), mpjpeg_read_packet(), mtv_read_header(), new_audio_stream(), new_init_section(), new_output_stream(), new_video_stream(), open_output_file(), open_slave(), opengl_write_header(), opt_filter_complex(), opt_map(), opt_sdp_file(), opt_vstats_file(), parse_bsfs(), parse_channel_expressions(), parse_device_name(), parse_filename(), parse_fmtp(), parse_frames(), parse_location(), parse_playlist(), parse_psfile(), parse_read_interval(), parse_read_intervals(), parse_source_list(), parse_times(), parse_video_var(), plot_freqs(), process_line(), pulse_add_detected_device(), pulse_server_info_cb(), qsv_decode_init(), qsv_enc_init(), read_header(), read_ttag(), realtext_read_header(), sami_paragraph_to_ass(), sap_read_header(), sdl_write_header(), seg_write_header(), segment_end(), set_enable_expr(), set_expr(), set_options(), set_string(), show_help(), split_init(), start_children(), stream_open(), url_connect(), v4l2_get_device_list(), write_option(), x11grab_read_header(), X264_init(), xcbgrab_read_header(), and xv_write_header().

char* av_strndup ( const char *  s,
size_t  len 
)

Duplicate a substring of the string s.

Parameters
sstring to be duplicated
lenthe maximum length of the resulting string (not counting the terminating byte).
Returns
Pointer to a newly-allocated string containing a copy of s or NULL if the string cannot be allocated.

Definition at line 279 of file mem.c.

Referenced by avformat_match_stream_specifier(), mpjpeg_get_boundary(), and parse_cookie().

void* av_memdup ( const void p,
size_t  size 
)

Duplicate the buffer p.

Parameters
pbuffer to be duplicated
Returns
Pointer to a newly allocated buffer containing a copy of p or NULL if the buffer cannot be allocated.

Definition at line 299 of file mem.c.

Referenced by av_opt_copy(), clone_filter_formats(), ff_mpv_common_frame_size_change(), ff_mpv_common_init(), and set_aes_arg().

void av_freep ( void ptr)

Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer pointing to it to NULL.

Parameters
ptrPointer to the pointer to the memory block which should be freed.
Note
passing a pointer to a NULL pointer is safe and leads to no action.
See Also
av_free()

Definition at line 243 of file mem.c.

Referenced by av_dynarray2_add(), av_dynarray_add(), and av_reallocp().

void av_dynarray_add ( void tab_ptr,
int *  nb_ptr,
void elem 
)

Add an element to a dynamic array.

The array to grow is supposed to be an array of pointers to structures, and the element to add must be a pointer to an already allocated structure.

The array is reallocated when its size reaches powers of 2. Therefore, the amortized cost of adding an element is constant.

In case of success, the pointer to the array is updated in order to point to the new grown array, and the number pointed to by nb_ptr is incremented. In case of failure, the array is freed, *tab_ptr is set to NULL and *nb_ptr is set to 0.

Parameters
tab_ptrpointer to the array to grow
nb_ptrpointer to the number of elements in the array
elemelement to add
See Also
av_dynarray_add_nofree(), av_dynarray2_add()

Definition at line 324 of file mem.c.

Referenced by decode_styl(), mov_text_style_cb(), and mov_text_tx3g().

av_warn_unused_result int av_dynarray_add_nofree ( void tab_ptr,
int *  nb_ptr,
void elem 
)

Add an element to a dynamic array.

Function has the same functionality as av_dynarray_add(), but it doesn't free memory on fails. It returns error code instead and leave current buffer untouched.

Parameters
tab_ptrpointer to the array to grow
nb_ptrpointer to the number of elements in the array
elemelement to add
Returns
>=0 on success, negative otherwise.
See Also
av_dynarray_add(), av_dynarray2_add()

Definition at line 310 of file mem.c.

Referenced by ff_alsa_get_device_list(), ff_fbdev_get_device_list(), mpegts_add_service(), pulse_add_detected_device(), and v4l2_get_device_list().

void* av_dynarray2_add ( void **  tab_ptr,
int *  nb_ptr,
size_t  elem_size,
const uint8_t elem_data 
)

Add an element of size elem_size to a dynamic array.

The array is reallocated when its number of elements reaches powers of 2. Therefore, the amortized cost of adding an element is constant.

In case of success, the pointer to the array is updated in order to point to the new grown array, and the number pointed to by nb_ptr is incremented. In case of failure, the array is freed, *tab_ptr is set to NULL and *nb_ptr is set to 0.

Parameters
tab_ptrpointer to the array to grow
nb_ptrpointer to the number of elements in the array
elem_sizesize in bytes of the elements in the array
elem_datapointer to the data of the element to add. If NULL, the space of the new added element is not filled.
Returns
pointer to the data of the element to copy in the new allocated space. If NULL, the new allocated space is left uninitialized."
See Also
av_dynarray_add(), av_dynarray_add_nofree()

Definition at line 338 of file mem.c.

Referenced by color_get(), and color_inc().

static int av_size_mult ( size_t  a,
size_t  b,
size_t *  r 
)
inlinestatic

Multiply two size_t values checking for overflow.

Returns
0 if success, AVERROR(EINVAL) if overflow.

Definition at line 339 of file mem.h.

Referenced by av_realloc_f(), and ogg_new_stream().

void av_max_alloc ( size_t  max)

Set the maximum size that may me allocated in one block.

Definition at line 73 of file mem.c.

Referenced by opt_max_alloc().

void av_memcpy_backptr ( uint8_t dst,
int  back,
int  cnt 
)

deliberately overlapping memcpy implementation

Parameters
dstdestination buffer
backhow many bytes back we start (the initial size of the overlapping window), must be > 0
cntnumber of bytes to copy, must be >= 0

cnt > back is valid, this will copy the bytes we just copied, thus creating a repeating pattern with a period length of back.

Definition at line 430 of file mem.c.

Referenced by copy_backptr(), decode_dsw1(), decode_frame(), decode_tsw1(), ff_lzf_uncompress(), mszh_decomp(), residual_interp(), synth_block_fcb_acb(), unpack(), and xan_unpack().

void* av_fast_realloc ( void ptr,
unsigned int *  size,
size_t  min_size 
)
void av_fast_malloc ( void ptr,
unsigned int *  size,
size_t  min_size 
)

Allocate a buffer, reusing the given one if large enough.

Contrary to av_fast_realloc the current buffer contents might not be preserved and on error the old buffer is freed, thus no special handling to avoid memleaks is necessary.

Parameters
ptrpointer to pointer to already allocated buffer, overwritten with pointer to new buffer
sizesize of the buffer *ptr points to
min_sizeminimum size of *ptr buffer after returning, *ptr will be NULL and *size 0 if an error occurred.

Definition at line 499 of file mem.c.

Referenced by alloc_scratch_buffers(), allocate_buffers(), ape_decode_frame(), audio_decode_frame(), chs_alloc_lsb_band_data(), chs_alloc_msb_band_data(), chs_assemble_freq_bands(), codec_reinit(), dcadec_decode_frame(), decode_8(), decode_frame(), ff_dca_core_filter_fixed(), ff_hevc_extract_rbsp(), ff_mpeg_update_thread_context(), fic_decode_frame(), filter_frame_float(), find_motion(), gif_decode_frame(), gif_read_image(), id3v2_parse(), lag_decode_frame(), ljpeg_decode_rgb_scan(), opus_decode_subpacket(), parse_navi_table(), pmp_packet(), reconfigure_at_keyframe(), rscc_decode_frame(), spdif_header_dts4(), spdif_write_packet(), tak_decode_frame(), truemotion1_decode_header(), truemotion1_decode_init(), update_init_section(), update_md5_sum(), and verify_md5().

void av_fast_mallocz ( void ptr,
unsigned int *  size,
size_t  min_size 
)

Allocate a buffer, reusing the given one if large enough.

All newly allocated space is initially cleared Contrary to av_fast_realloc the current buffer contents might not be preserved and on error the old buffer is freed, thus no special handling to avoid memleaks is necessary.

Parameters
ptrpointer to pointer to already allocated buffer, overwritten with pointer to new buffer
sizesize of the buffer *ptr points to
min_sizeminimum size of *ptr buffer after returning, *ptr will be NULL and *size 0 if an error occurred.

Definition at line 504 of file mem.c.

Referenced by alloc_sample_buffer(), alloc_scratch_buffers(), and alloc_x96_sample_buffer().