FFmpeg
Functions
Heap Management

Functions responsible for allocating, freeing, and copying memory. More...

Functions

void * av_malloc (size_t size) av_malloc_attrib 1(1)
 Allocate a memory block with alignment suitable for all memory accesses (including vectors if available on the CPU). More...
 
void * av_mallocz (size_t size) av_malloc_attrib 1(1)
 Allocate a memory block with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block. More...
 
void * av_malloc_array (size_t nmemb, size_t size)
 
void * av_calloc (size_t nmemb, size_t size) av_malloc_attrib 1(1
 Allocate a memory block for an array with av_mallocz(). More...
 
void void * av_realloc (void *ptr, size_t size) 1(2)
 Allocate, reallocate, or free a block of memory. More...
 
av_warn_unused_result int av_reallocp (void *ptr, size_t size)
 Allocate, reallocate, or free a block of memory through a pointer to a pointer. More...
 
void * av_realloc_f (void *ptr, size_t nelem, size_t elsize)
 Allocate, reallocate, or free a block of memory. More...
 
void * av_realloc_array (void *ptr, size_t nmemb, size_t size)
 
int av_reallocp_array (void *ptr, size_t nmemb, size_t size)
 Allocate, reallocate an array through a pointer to a pointer. More...
 
void * av_fast_realloc (void *ptr, unsigned int *size, size_t min_size)
 Reallocate the given buffer 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 and clear a buffer, reusing the given one if large enough. More...
 
void av_free (void *ptr)
 Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family. More...
 
void av_freep (void *ptr)
 Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family, and set the pointer pointing to it to NULL. More...
 
char * av_strdup (const char *s) av_malloc_attrib
 Duplicate a string. More...
 
char * av_strndup (const char *s, size_t len) av_malloc_attrib
 Duplicate a substring of a string. More...
 
void * av_memdup (const void *p, size_t size)
 Duplicate a buffer with av_malloc(). More...
 
void av_memcpy_backptr (uint8_t *dst, int back, int cnt)
 Overlapping memcpy() implementation. More...
 

Detailed Description

Functions responsible for allocating, freeing, and copying memory.

All memory allocation functions have a built-in upper limit of INT_MAX bytes. This may be changed with av_max_alloc(), although exercise extreme caution when doing so.

Function Documentation

◆ av_malloc()

void* av_malloc ( size_t  size)

Allocate a memory block 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, or NULL if the block cannot be allocated
See also
av_mallocz()

Definition at line 96 of file mem.c.

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

◆ av_mallocz()

void* av_mallocz ( size_t  size)

Allocate a memory block 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, or NULL if it cannot be allocated
See also
av_malloc()

Definition at line 254 of file mem.c.

Referenced by a64multi_encode_init(), aac_encode_init(), add_fragment(), add_param_definition(), add_pes_stream(), add_segment(), add_side_data_from_buf_ext(), adpcm_encode_init(), alac_encode_init(), alloc_buffer(), alloc_data_buf(), alloc_hevc_header_structs(), alloc_plane(), alloc_rbsp_buffer(), allocate_array_elem(), allocate_buffers(), allocate_sample_buffers(), allocate_tables(), ambisonics_config(), amf_encode_init_av1(), amf_encode_init_h264(), amf_encode_init_hevc(), apng_write_header(), aribcaption_init(), aribcaption_trans_bitmap_subtitle(), aribcaption_trans_text_subtitle(), asf_read_stream_properties(), ass_decode_frame(), atrac3_decode_init(), audio_element_obu(), av_aes_alloc(), av_aes_ctr_alloc(), av_ambient_viewing_environment_alloc(), av_audio_fifo_alloc(), av_blowfish_alloc(), av_bsf_alloc(), av_bsf_list_alloc(), av_buffer_create(), av_buffer_pool_init(), av_buffer_pool_init2(), av_buffer_ref(), av_buffersrc_parameters_alloc(), av_calloc(), av_camellia_alloc(), av_cast5_alloc(), av_content_light_metadata_alloc(), av_cpb_properties_alloc(), av_dct_init(), av_des_alloc(), av_detection_bbox_alloc(), av_dict_set(), av_dovi_alloc(), av_dovi_metadata_alloc(), av_dump_format(), av_dynamic_hdr_plus_alloc(), av_dynamic_hdr_vivid_alloc(), av_encryption_info_alloc(), av_encryption_init_info_alloc(), av_executor_alloc(), av_expr_parse(), av_fft_init(), av_fifo_alloc2(), av_film_grain_params_alloc(), av_hash_alloc(), av_hmac_alloc(), av_hwdevice_ctx_alloc(), av_hwdevice_get_hwframe_constraints(), av_hwdevice_hwconfig_alloc(), av_hwframe_ctx_alloc(), av_iamf_audio_element_alloc(), av_iamf_mix_presentation_alloc(), av_iamf_param_definition_alloc(), av_mastering_display_metadata_alloc(), av_md5_alloc(), av_mdct_init(), av_murmur3_alloc(), av_new_program(), av_opt_query_ranges_default(), av_packet_new_side_data(), av_parser_init(), av_rc4_alloc(), av_rdft_init(), av_ripemd_alloc(), av_sha512_alloc(), av_sha_alloc(), av_spherical_alloc(), av_stereo3d_alloc(), av_tea_alloc(), av_thread_message_queue_alloc(), av_tree_node_alloc(), av_twofish_alloc(), av_vdpau_alloc_context(), av_video_enc_params_alloc(), av_video_hint_alloc(), av_vk_frame_alloc(), av_vorbis_parse_init(), av_xtea_alloc(), avcodec_dct_alloc(), avcodec_get_hw_frames_parameters(), avcodec_open2(), avcodec_parameters_alloc(), avcodec_parameters_copy(), avcodec_parameters_from_context(), avcodec_parameters_to_context(), avdevice_list_devices(), avfilter_graph_alloc(), avfilter_graph_queue_command(), avfilter_graph_segment_parse(), avfilter_inout_alloc(), avfilter_link(), avformat_alloc_context(), avformat_alloc_output_context2(), avformat_new_stream(), avformat_open_input(), avformat_stream_group_create(), avi_read_header(), avi_write_header(), avio_open_dir(), avpriv_adts_header_parse(), avpriv_elbg_do(), avpriv_float_dsp_alloc(), avpriv_mpegts_parse_open(), avpriv_new_chapter(), avui_encode_init(), bfi_decode_init(), buffer_create(), callback(), chain_parse(), che_configure(), check_add_bytes(), check_add_gradient_pred(), check_add_int16(), check_add_left_pred(), check_add_median_pred(), check_field_queue(), codec_config_obu(), codec_create(), command(), config_output(), cook_decode_init(), copy_av_subtitle(), copy_chapters(), copy_init_section(), create_vorbis_context(), cuvid_decode_init(), D(), d3d12va_pool_alloc(), dash_init(), dec_alloc(), decklink_autodetect(), decode_dvd_subtitles(), decode_extradata_ps_mp4(), decode_frame(), decode_init(), decode_pic(), decoder_init(), dfa_decode_init(), dhav_read_packet(), display_end_segment(), dnn_detect_parse_anchors(), dnn_detect_parse_yolo_output(), dnn_load_model_tf(), dnn_load_model_th(), dnxhd_init_vlc(), do_encrypt(), doTest(), draw_text(), dshow_get_format_info(), dss_read_metadata_string(), dvbsub_parse_display_definition_segment(), dvbsub_parse_page_segment(), dvbsub_parse_region_segment(), dvdvideo_subdemux_open(), dxva2_device_create(), dxva2_map_frame(), eb_enc_init(), enc_alloc(), enc_open(), encode_frame(), encode_init(), encode_picture_ls(), encode_sample_description(), enqueue_packet(), epic_add_pixel_to_cache(), fast_malloc(), ff_all_channel_counts(), ff_all_channel_layouts(), ff_all_samplerates(), ff_alloc_a53_sei(), ff_alloc_dir_entry(), ff_alloc_input_device_context(), ff_alloc_timecode_sei(), ff_alsa_get_device_list(), ff_ass_add_rect2(), ff_ass_split(), ff_ass_split_dialog(), ff_attach_decode_data(), ff_avc_write_annexb_extradata(), ff_cavs_init_top_lines(), ff_cbs_init(), ff_celt_init(), ff_decklink_list_devices(), ff_decklink_list_devices_legacy(), ff_decklink_read_header(), ff_decklink_write_header(), ff_decode_internal_alloc(), ff_ebur128_init(), ff_encode_internal_alloc(), ff_evc_parse_pps(), ff_evc_parse_sps(), ff_fbdev_get_device_list(), ff_ffv1_init_slice_contexts(), ff_filter_alloc(), ff_formats_pixdesc_filter(), ff_frame_pool_audio_init(), ff_frame_pool_video_init(), ff_frame_thread_encoder_init(), ff_frame_thread_init(), ff_graph_thread_init(), ff_hwframe_map_create(), ff_iamf_add_audio_element(), ff_iamf_add_mix_presentation(), ff_iir_filter_init_coeffs(), ff_iir_filter_init_state(), ff_init_vscale(), ff_intrax8_common_init(), ff_jpegls_decode_picture(), ff_lpc_init(), ff_lzw_decode_open(), ff_make_channel_layout_list(), ff_mediacodec_surface_ref(), ff_mjpeg_decode_sof(), ff_mlz_init_dict(), ff_mpeg_er_init(), ff_mpv_encode_init(), ff_mpv_init_context_frame(), ff_nut_add_sp(), ff_nvdec_decode_init(), ff_nvdec_start_frame(), ff_opus_psy_init(), 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_silk_init(), ff_slice_thread_init(), ff_timefilter_new(), ff_tx_gen_inplace_map(), ff_tx_gen_split_radix_parity_revtab(), ff_tx_init_subtx(), ff_tx_rdft_init(), ff_v4l2_context_init(), ff_v4l2_m2m_create_context(), ff_vaapi_encode_init(), ff_videotoolbox_alloc_frame(), ff_vk_create_avbuf(), ff_vk_create_imageviews(), ff_vk_frame_params(), ff_vk_glslang_init(), ff_vk_shaderc_init(), ff_vk_video_common_init(), ff_vs_init(), ff_wms_parse_sdp_a_line(), ffat_decode(), ffat_init_decoder(), ffat_init_encoder(), ffmal_update_format(), ffmmal_add_packet(), ffmmal_set_ref(), fg_send_command(), filter_frame(), filter_parse(), find_component(), find_headers_search_validate(), flac_read_header(), flashsv2_encode_init(), flashsv_decode_frame(), flush_packet(), flv_parse_video_color_info(), flv_queue_extradata(), frame_alloc(), frame_data_ensure(), g2m_init_buffers(), gen_sub_bitmap(), generate_fake_vps(), generate_joint_tables(), get_content_url(), get_current_encryption_info(), get_current_fragment(), get_Fragment(), get_free_frame(), get_http_header_data(), get_output_ov(), get_private_data(), get_siz(), get_surface(), gif_encode_init(), gxf_write_header(), handle_eac3(), handle_file(), handler(), heif_add_stream(), hevc_init_context(), hls_slice_data_wpp(), hnm_decode_init(), hw_device_add(), hwaccel_init(), iec61883_callback(), init(), init_context_defaults(), init_duplicate_context(), init_fps(), init_model_ov(), init_muxer(), init_thread(), inout_add(), kmsgrab_read_packet(), lavfi_read_header(), libaribb24_decode(), libcodec2_init_encoder(), libkvazaar_init(), librav1e_encode_init(), librav1e_receive_packet(), linklabels_parse(), LLVMFuzzerTestOneInput(), load_tf_model(), magy_encode_init(), main(), make_eval_expr(), make_field_queue(), make_point(), map_alloc(), measure_text(), mediacodec_decode_init(), mediacodec_wrap_hw_buffer(), mediaformat_jni_new(), mediaformat_jni_newFromObject(), mediaformat_ndk_create(), mf_enca_output_type_get(), mf_encv_output_type_get(), mix_presentation_obu(), mmsh_open_internal(), mmsh_read_seek(), mov_init_iamf_track(), mov_read_chapters(), mov_read_covr(), mov_read_dref(), mov_read_iacb(), mov_read_keys(), mov_read_pssh(), mov_read_stsd(), mov_read_tenc(), mov_read_trak(), mov_read_udta_string(), mov_read_uuid(), mov_read_wave(), mov_write_dvc1_structs(), mov_write_single_packet(), mpeg_mux_init(), mpeg_mux_write_packet(), mpegts_add_service(), mpegts_init(), mpegts_open_filter(), mpegts_open_section_filter(), mpegts_write_packet_internal(), mss2_decode_init(), mxf_handle_missing_index_segment(), mxf_init(), mxf_read_ffv1_sub_descriptor(), mxf_read_local_tags(), mxpeg_decode_mxm(), ndk_codec_create(), new_init_section(), new_matrix(), new_playlist(), new_rendition(), new_stream(), new_stream_video(), new_variant(), nsv_parse_NSVf_header(), nsv_parse_NSVs_header(), nvenc_setup_extradata(), objpool_alloc(), ogg_buffer_page(), ogg_build_flac_headers(), ogg_build_opus_headers(), ogg_build_speex_headers(), ogg_build_vp8_headers(), ogg_init(), ogg_save(), ogg_write_vorbiscomment(), omx_component_init(), omx_init(), open_input(), open_virtual_track(), opencl_map_frame(), opencl_pool_alloc(), opus_header(), overlay_qsv_init(), paf_video_init(), param_parse(), parse_cc_stream_mapstring(), parse_fmtp_config(), parse_keyframes_index(), parse_manifest_representation(), parse_manifest_segmenttimeline(), parse_primary(), parse_sws_flags(), parse_variant_stream_mapstring(), parse_vtrk(), pic_arrays_init(), pool_alloc_buffer(), pp_get_context(), prepare_buf(), psy_3gpp_init(), pulse_add_detected_device(), put_audio_specific_config(), put_main_header(), qsv_decode(), qsv_device_create(), qsv_device_derive(), qsv_hevc_set_encode_ctrl(), qsv_stack_init(), qt_rtp_parse_packet(), qtrle_encode_init(), rdt_parse_b64buf(), read_apic(), read_chapter(), read_gab2_sub(), read_geobtag(), read_header(), read_header_vs(), read_huffman_code_normal(), read_packet_vs(), read_priv(), read_vlc_prefix(), reallocAlign(), resample_init(), resolve_content_path(), rkmpp_init_decoder(), rkmpp_retrieve_frame(), rl2_decode_init(), rv34_decoder_alloc(), sap_write_header(), save_subtitle_set(), sch_alloc(), segment_end(), set_encoder_id(), set_extradata(), set_roi_encode_ctrl(), setup_frame(), slices_realloc(), sp5x_decode_frame(), speex_header(), sq_alloc(), stream_open(), strftime_expand(), subtitle_wrap_frame(), 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(), tl_create(), tm2_build_huff_table(), tq_alloc(), ttml_write_header_content(), update_block_buffers(), update_context_from_thread(), update_dimensions(), update_variant_stream_info(), url_alloc_for_protocol(), url_open_dyn_buf_internal(), utvideo_encode_init(), v4l2_get_device_list(), vaapi_device_create(), vaapi_device_derive(), vaapi_encode_alloc(), vaapi_encode_issue(), var_size_bme(), vc1_decode_frame(), vc1_decode_init(), vc1_decode_init_alloc_tables(), vc2_encode_init(), videostream_cb(), 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(), vorbis_update_metadata(), vp9_raw_reorder_filter(), vqa_decode_init(), vtenc_send_frame(), vulkan_decode_get_profile(), wmv2_encode_init(), wrap_texture_buf(), wrapped_avframe_encode(), write_packet(), write_uncoded_frame_internal(), writer_open(), wtvfile_open_sector(), and wv_alloc_frame_context().

◆ av_malloc_array()

void* av_malloc_array ( size_t  nmemb,
size_t  size 
)

Definition at line 207 of file mem.c.

◆ av_calloc()

void* av_calloc ( size_t  nmemb,
size_t  size 
)

Allocate a memory block for an array with av_mallocz().

The allocated memory will have size size * nmemb bytes.

Parameters
nmembNumber of elements
sizeSize of the single element
Returns
Pointer to the allocated block, or NULL if the block cannot be allocated
See also
av_mallocz()
av_malloc_array()

◆ av_realloc()

void void* av_realloc ( void *  ptr,
size_t  size 
)

Allocate, reallocate, or free a block of memory.

If ptr is NULL and size > 0, allocate a new block. Otherwise, expand or shrink that block of memory according to size.

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
Warning
Unlike av_malloc(), the returned pointer is not guaranteed to be correctly aligned. The returned pointer must be freed after even if size is zero.
See also
av_fast_realloc()
av_reallocp()

Definition at line 153 of file mem.c.

Referenced by add_adaptation_set(), add_file(), append_extradata(), av_bprint_alloc(), av_bprint_finalize(), av_buffer_realloc(), av_dict_set(), av_fast_realloc(), av_packet_add_side_data(), av_realloc_array(), av_realloc_f(), av_reallocp(), av_strdup(), av_strndup(), buf_realloc(), cbs_h2645_assemble_fragment(), decode_header(), epic_hash_add(), ff_cuda_load_module(), ff_els_decode_unsigned(), ff_h264_parse_sprop_parameter_sets(), ff_img_read_header(), ff_load_textfile(), ff_rtmp_packet_create(), ff_vs_init(), fixup_vorbis_headers(), flac_fifo_alloc(), flac_fifo_grow(), get_ppm(), get_ppt(), jpeg2000_decode_packet(), libjxl_encode_frame(), libjxl_encode_init(), main(), match_streams(), mov_fix_index(), parse_adaptation_sets(), probe_codec(), qt_rtp_parse_packet(), and xmlescape().

◆ av_reallocp()

av_warn_unused_result int av_reallocp ( void *  ptr,
size_t  size 
)

Allocate, reallocate, or free a block of memory through a pointer to a pointer.

If *ptr is NULL and size > 0, allocate a new block. If size is zero, free the memory block pointed to by *ptr. Otherwise, expand or shrink that block of memory according to size.

Parameters
[in,out]ptrPointer to a pointer to a memory block already allocated with av_realloc(), or a pointer to NULL. The pointer is updated on success, or freed on failure.
[in]sizeSize in bytes for the memory block to be allocated or reallocated
Returns
Zero on success, an AVERROR error code on failure
Warning
Unlike av_malloc(), the allocated memory is not guaranteed to be correctly aligned.

Definition at line 186 of file mem.c.

Referenced by aom_init(), append_flv_data(), asfrtp_parse_packet(), auxiliary_info_alloc_size(), av_probe_input_buffer2(), av_vdpau_bind_context(), avi_read_header(), bmv_read_packet(), cbs_h2645_assemble_fragment(), cbs_write_unit_data(), concatenate_packet(), decode_frame(), dxv_decode(), dyn_buf_write(), ff_els_decode_unsigned(), ff_lzf_uncompress(), ff_opencl_filter_load_program_from_file(), 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(), http_open(), jpg_decode_data(), mediacodec_receive(), mov_cenc_end_packet(), mov_realloc_extradata(), omx_encode_frame(), omx_encode_init(), opt_get_array(), parse_icy(), qt_rtp_parse_packet(), rdt_parse_sdp_line(), realloc_buffer(), rtmp_http_write(), rtmp_open(), rtmp_write(), set_segment_filename(), tdsc_decode_frame(), tdsc_decode_tiles(), tdsc_init(), tdsc_load_cursor(), tgv_decode_inter(), theora_header(), tls_client_handshake_loop(), tls_read(), vpx_init(), and vvc_extradata_to_annexb().

◆ av_realloc_f()

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

Allocate, reallocate, or free a block of memory.

This function does the same thing as av_realloc(), except:

  • It takes two size arguments and allocates nelem * elsize bytes, after checking 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;
    pattern.

Definition at line 171 of file mem.c.

Referenced by av_reallocp_array().

◆ av_realloc_array()

void* av_realloc_array ( void *  ptr,
size_t  nmemb,
size_t  size 
)

Definition at line 215 of file mem.c.

Referenced by add_param_definition(), add_serial_pair(), add_side_data_from_buf_ext(), append_pad(), aribcaption_init(), audio_element_obu(), av_dict_set(), av_fifo_alloc2(), av_fifo_grow2(), av_frame_replace(), av_program_add_stream_index(), avfilter_graph_alloc_filter(), avformat_new_stream(), avformat_stream_group_create(), codec_config_obu(), decode_styl(), decode_unregistered_user_data(), ff_alsa_extend_reorder_buf(), ff_ass_add_rect2(), ff_cbs_sei_list_add(), ff_encode_add_cpb_side_data(), ff_framequeue_add(), ff_iamf_add_audio_element(), ff_iamf_add_mix_presentation(), ff_mov_write_packet(), ff_rtmp_check_alloc_array(), ff_vaapi_decode_make_slice_buffer(), ff_vk_add_push_constant(), ff_vk_pipeline_descriptor_set_add(), fill_codec_config(), fill_marker_resource(), filter_frame(), frame_hash(), get_preset_file(), grow_array(), handle_file(), handler(), jpeg2000_decode_packet(), log_callback(), mix_presentation_obu(), mkv_add_cuepoint(), mov_read_iinf(), mov_read_iloc(), mov_read_iref_dimg(), mxf_read_partition_pack(), new_stream_video(), ogg_new_stream(), open_virtual_track(), opt_set_array(), packet_side_data_add(), param_parse(), parse_imf_asset_map_from_xml_dom(), push_main_audio_sequence(), push_marker_sequence(), rd_get(), realloc_section_array(), sample_queue_push(), slices_realloc(), sq_add_stream(), stream_group_add_stream(), tee_open(), update_block_dimensions(), update_frag_index(), vaapi_av1_decode_slice(), vaapi_encode_make_packed_header(), vaapi_encode_make_param_buffer(), wv_alloc_frame_context(), and xan_decode_frame().

◆ av_reallocp_array()

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

Allocate, reallocate an array through a pointer to a pointer.

If *ptr is NULL and nmemb > 0, allocate a new block.

Parameters
[in,out]ptrPointer to a pointer to a memory block already allocated with av_realloc(), or a pointer to NULL. The pointer is updated on success, or freed on failure.
[in]nmembNumber of elements
[in]sizeSize of the single element
Returns
Zero on success, an AVERROR error code on failure
Warning
Unlike av_malloc(), the allocated memory is not guaranteed to be correctly aligned. *ptr must be freed after even if nmemb is zero.

Definition at line 223 of file mem.c.

Referenced by add_fragment(), add_program(), add_segment(), add_tracked_method(), allocate_buffers(), ass_split_section(), evcc_array_add_nal_unit(), ff_h2645_extract_rbsp(), ff_h2645_sei_ctx_replace(), ff_hap_set_chunk_count(), gem_decode_frame(), gxf_write_map_packet(), gxf_write_packet(), hvcc_array_add_nal_unit(), hw_device_add(), init_tile_data(), mov_add_tfra_entries(), mov_build_index(), mov_read_trex(), mxf_write_packet(), mxf_write_partition(), nut_write_packet(), ogg_restore(), opencl_frames_get_constraints(), parse_adaptation_sets(), parse_strk(), tgv_decode_inter(), tm2_read_stream(), update_index(), vp56_size_changed(), and vvcc_array_add_nal_unit().

◆ av_fast_realloc()

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

Reallocate the given buffer if it is not large enough, otherwise do nothing.

If the given buffer is NULL, then a new uninitialized buffer is allocated.

If the given buffer is not large enough, and reallocation fails, NULL is returned and *size is set to 0, but the original buffer is not changed or freed.

A typical use pattern follows:

uint8_t *buf = ...;
uint8_t *new_buf = av_fast_realloc(buf, &current_size, size_needed);
if (!new_buf) {
// Allocation failed; clean up original buffer
av_freep(&buf);
return AVERROR(ENOMEM);
}
Parameters
[in,out]ptrAlready allocated buffer, or NULL
[in,out]sizePointer to the size of buffer ptr. *size is updated to the new allocated size, in particular 0 in case of failure.
[in]min_sizeDesired minimal size of buffer ptr
Returns
ptr if the buffer is large enough, a pointer to newly reallocated buffer if the buffer was not large enough, or NULL in case of error
See also
av_realloc()
av_fast_malloc()

Definition at line 495 of file mem.c.

Referenced by add_ctts_entry(), add_index_entry(), avc_parse_nal_units(), caf_write_packet(), config_output(), decode_frame(), dirac_combine_frame(), draw_items(), dxva2_av1_decode_slice(), evc_frame_merge_filter(), ff_add_index_entry(), ff_af_queue_add(), ff_av1_packet_split(), ff_combine_frame(), ff_h2645_packet_split(), ff_mms_asf_header_parser(), ff_nvdec_simple_decode_slice(), ff_range_add(), ff_subtitles_queue_insert(), ff_tx_init_subtx(), ff_vdpau_add_buffer(), ff_videotoolbox_buffer_copy(), ff_vk_decode_add_slice(), ff_vk_exec_add_dep_buf(), filter_frame(), flac_fifo_read_wrap(), get_stats(), h264_extradata_to_annexb(), h264_mp4toannexb_save_ps(), init(), intercept_id3(), libx265_encode_frame(), mov_build_index(), mov_parse_auxiliary_info(), mov_read_ctts(), mov_read_pssh(), mov_read_saio(), mov_read_senc(), mov_read_stts(), mov_read_trun(), mov_text_style_start(), mxg_update_cache(), nvdec_av1_decode_slice(), nvdec_h264_decode_slice(), nvdec_hevc_decode_slice(), open_track_file_resource(), parse_string(), prepare_sei_data_array(), push_main_audio_sequence(), push_main_image_2d_sequence(), queue_frames(), read_frame(), setup_frame(), shorten_decode_frame(), spdif_header_eac3(), update_frag_index(), and vc1_decode_frame().

◆ av_fast_malloc()

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.

*ptr is allowed to be NULL, in which case allocation always happens if size_needed is greater than 0.

uint8_t *buf = ...;
av_fast_malloc(&buf, &current_size, size_needed);
if (!buf) {
// Allocation failed; buf already freed
return AVERROR(ENOMEM);
}
Parameters
[in,out]ptrPointer to pointer to an already allocated buffer. *ptr will be overwritten with pointer to new buffer on success or NULL on failure
[in,out]sizePointer to the size of buffer *ptr. *size is updated to the new allocated size, in particular 0 in case of failure.
[in]min_sizeDesired minimal size of buffer *ptr
See also
av_realloc()
av_fast_mallocz()

Definition at line 555 of file mem.c.

Referenced by alloc_scratch_buffers(), allocate_buffers(), ape_decode_frame(), audio_decode_frame(), av_fast_padded_mallocz(), chs_alloc_lsb_band_data(), chs_alloc_msb_band_data(), chs_assemble_freq_bands(), codec_reinit(), crypto_write(), decode_8(), decode_frame(), detect_clips(), do_interpolation(), ff_dca_core_filter_fixed(), fic_decode_frame(), filter_frame_float(), find_motion(), gif_decode_frame(), gif_read_image(), id3v2_parse(), interpolation(), ljpeg_decode_rgb_scan(), magy_decode_frame(), opus_decode_subpacket(), parse_navi_table(), parse_utf(), pmp_packet(), rscc_decode_frame(), scale_internal(), spdif_header_dts4(), spdif_write_packet(), tak_decode_frame(), truemotion1_decode_header(), truemotion1_decode_init(), update_block_dimensions(), update_init_section(), update_md5_sum(), and verify_md5().

◆ av_fast_mallocz()

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

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

Like av_fast_malloc(), but all newly allocated space is initially cleared. Reused buffer is not cleared.

*ptr is allowed to be NULL, in which case allocation always happens if size_needed is greater than 0.

Parameters
[in,out]ptrPointer to pointer to an already allocated buffer. *ptr will be overwritten with pointer to new buffer on success or NULL on failure
[in,out]sizePointer to the size of buffer *ptr. *size is updated to the new allocated size, in particular 0 in case of failure.
[in]min_sizeDesired minimal size of buffer *ptr
See also
av_fast_malloc()

Definition at line 560 of file mem.c.

Referenced by alloc_sample_buffer(), alloc_scratch_buffers(), alloc_x96_sample_buffer(), av_fast_padded_malloc(), decode_frame(), and g2m_init_buffers().

◆ av_free()

void av_free ( void *  ptr)

Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family.

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, to prevent leaving behind dangling pointers.
See also
av_freep()

Definition at line 236 of file mem.c.

Referenced by av_freep(), and av_realloc_f().

◆ av_freep()

void av_freep ( void *  ptr)

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

uint8_t *buf = av_malloc(16);
av_free(buf);
// buf now contains a dangling pointer to freed memory, and accidental
// dereference of buf will result in a use-after-free, which may be a
// security risk.
uint8_t *buf = av_malloc(16);
av_freep(&buf);
// buf is now NULL, and accidental dereference will only result in a
// NULL-pointer dereference.
Parameters
ptrPointer to the pointer to the memory block which should be freed
Note
*ptr = NULL is safe and leads to no action.
See also
av_free()

Definition at line 245 of file mem.c.

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

◆ av_strdup()

char* av_strdup ( const char *  s)

Duplicate a string.

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
See also
av_strndup()

Definition at line 270 of file mem.c.

Referenced by add_tracked_method(), aribcaption_trans_text_subtitle(), ass_decode_frame(), av_append_path_component(), av_channel_layout_from_string(), av_dict_get_string(), av_dict_set(), av_opt_get(), avfilter_graph_parse(), avfilter_graph_queue_command(), avfilter_graph_segment_create_filters(), avformat_alloc_output_context2(), avformat_open_input(), avpriv_tempfile(), caca_write_header(), check_extensions(), check_validation_layers(), cine_read_header(), config_eq_output(), config_input(), config_output(), config_params(), configure_filtergraph(), configure_video_filters(), copy_av_subtitle(), curves_init(), dash_init(), dec_filter_add(), dec_open(), delimited_dict_parse(), describe_filter_link(), draw_curves(), enc_stats_get_file(), ff_alsa_get_device_list(), ff_boxblur_eval_filter_params(), ff_copy_whiteblacklists(), ff_decklink_list_devices(), ff_fbdev_get_device_list(), ff_filter_alloc(), ff_http_do_new_request2(), ff_http_match_no_proxy(), ff_img_read_header(), ff_jni_jstring_to_utf_chars(), ff_mediacodec_dec_init(), ff_mkdir_p(), ff_tls_open_underlying(), ffio_fdopen(), ffurl_connect(), fg_send_command(), filter_parse(), format_name(), ftp_connect(), ftp_current_dir(), ftp_parse_entry_mlsd(), ftp_parse_entry_nlst(), geq_init(), get_cookies(), get_current_fragment(), get_opt_flags_string(), getenv_dup(), grab_read_header(), hls_delete_old_segments(), hls_init(), hls_mux_init(), hls_read_header(), hls_rename_temp_file(), hls_start(), hls_write_packet(), hls_write_trailer(), http_open(), http_open_cnx(), http_seek_internal(), icecast_open(), imf_read_header(), init(), init_filter(), init_filters(), init_muxer(), initialize(), inout_add(), ist_add(), ist_filter_add(), label_string(), lavfi_read_header(), libsmbc_read_dir(), libssh_read_dir(), log_callback(), main(), match_stream_specifier(), measure_text(), mediacodec_ndk_getName(), mediaformat_ndk_getString(), mediaformat_ndk_toString(), mkv_write_simpletag(), mmsh_open_internal(), mpjpeg_read_packet(), mtv_read_header(), new_init_section(), new_stream_audio(), new_stream_video(), noise_init(), nppscale_parse_expr(), of_add_attachments(), of_add_groups(), of_parse_iamf_submixes(), open_camera(), open_input_file(), open_output_file(), open_slave(), opengl_write_header(), opt_add_vfilter(), opt_attach(), opt_codec(), opt_copy_elem(), opt_filter_complex(), opt_filter_threads(), opt_get_elem(), opt_input_file(), opt_map(), opt_output_file_o(), opt_print_filename(), opt_vstats_file(), ost_get_filters(), param_init(), parse_assetmap(), parse_cc_stream_mapstring(), parse_channel_expressions(), parse_device_name(), parse_fmtp(), parse_imf_asset_map_from_xml_dom(), parse_location(), parse_manifest(), parse_manifest_representation(), parse_options(), parse_playlist(), parse_psfile(), parse_read_interval(), parse_read_intervals(), parse_set_cookie(), parse_speaker_pos(), parse_times(), parse_variant_stream_mapstring(), parse_video_var(), plot_freqs(), process_command(), process_line(), pulse_add_detected_device(), pulse_server_info_cb(), qsv_decode_init(), qsv_enc_init(), read_channels(), read_classify_label_file(), read_custom_noise(), read_detect_label_file(), read_gains(), read_header(), read_tf_coefficients(), read_ttag(), read_zp_coefficients(), realtext_read_header(), rfc4175_parse_fmtp(), rtmp_http_open(), rtp_open(), sami_paragraph_to_ass(), sap_read_header(), sap_write_header(), scale_parse_expr(), sch_sdp_filename(), sdl2_write_header(), segment_end(), set_ass_header(), set_enable_expr(), set_expr(), set_options(), set_segment_filename(), set_string(), show_help(), sls_flags_filename_process(), stream_open(), tcp_open(), tiff_decode_tag(), udp_open(), update_master_pl_info(), v4l2_get_device_list(), validate_name(), write_option(), xcbgrab_read_header(), and xv_write_header().

◆ av_strndup()

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

Duplicate a substring of a string.

Parameters
sString to be duplicated
lenMaximum length of the resulting string (not counting the terminating byte)
Returns
Pointer to a newly-allocated string containing a substring of s or NULL if the string cannot be allocated

Definition at line 282 of file mem.c.

Referenced by hw_device_init_from_string(), match_stream_specifier(), mpjpeg_get_boundary(), parse_adaptation_sets(), parse_cookie(), and process_line().

◆ av_memdup()

void* av_memdup ( const void *  p,
size_t  size 
)

◆ av_memcpy_backptr()

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

Overlapping memcpy() implementation.

Parameters
dstDestination buffer
backNumber of bytes back to start copying (i.e. the initial size of the overlapping window); must be > 0
cntNumber of bytes to copy; must be >= 0
Note
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 445 of file mem.c.

Referenced by color_frame(), copy_backptr(), decode_dsw1(), decode_frame(), decode_tsw1(), ff_lzf_uncompress(), fill_frame(), generate_missing_ref(), memset_bytes(), mszh_decomp(), picmemset(), qsv_fill_border(), qsvenc_fill_padding_area(), residual_interp(), synth_block_fcb_acb(), unpack(), and xan_unpack().

AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
av_fast_realloc
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition: mem.c:495
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_fast_malloc
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:555