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_mallocz_array (size_t nmemb, size_t size)
 
void * av_calloc (size_t nmemb, size_t size) av_malloc_attrib
 Non-inlined equivalent of av_mallocz_array(). More...
 
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, or free 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 77 of file mem.c.

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

◆ 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 237 of file mem.c.

Referenced by a64multi_encode_init(), aac_encode_init(), add_fragment(), add_input_streams(), add_pes_stream(), add_segment(), add_to_queue(), alac_encode_init(), alloc_rbsp_buffer(), allocate_buffers(), allocate_tables(), amf_encode_init_h264(), amf_encode_init_hevc(), ape_read_header(), apng_write_header(), asf_read_stream_properties(), ass_decode_frame(), atrac3_decode_init(), av_abuffersink_params_alloc(), av_aes_alloc(), av_aes_ctr_alloc(), av_audio_fifo_alloc(), av_bitstream_filter_filter(), av_bitstream_filter_init(), 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_des_alloc(), av_dict_set(), av_dovi_alloc(), av_dump_format(), av_dynamic_hdr_plus_alloc(), av_encryption_info_alloc(), av_encryption_init_info_alloc(), av_expr_parse(), av_fft_init(), av_frame_alloc(), av_frame_new_side_data_from_buf(), av_hash_alloc(), av_hmac_alloc(), av_hwdevice_ctx_alloc(), av_hwdevice_get_hwframe_constraints(), av_hwdevice_hwconfig_alloc(), av_hwframe_ctx_alloc(), av_mallocz_array(), av_mastering_display_metadata_alloc(), av_md5_alloc(), av_murmur3_alloc(), av_new_program(), 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_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_tx_init(), av_vdpau_alloc_context(), av_video_enc_params_alloc(), av_vk_frame_alloc(), av_vorbis_parse_init(), av_xtea_alloc(), avcodec_dct_alloc(), avcodec_open2(), avcodec_parameters_alloc(), avcodec_parameters_copy(), avcodec_parameters_from_context(), avcodec_parameters_to_context(), 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_open_dir(), 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_add_bytes(), check_add_gradient_pred(), check_add_int16(), check_add_left_pred(), check_add_median_pred(), check_field_queue(), codec_create(), command(), config_output(), cook_decode_init(), copy_chapters(), copy_init_section(), create_buf(), create_exec_ctx(), cuda_device_init(), cuvid_decode_init(), D(), dash_init(), decklink_autodetect(), decode_dvd_subtitles(), decode_extradata_ps_mp4(), decode_frame(), decode_init(), decode_pic(), decoder_init(), DEF_CHOOSE_FORMAT(), dfa_decode_init(), dhav_read_packet(), display_end_segment(), do_encrypt(), doTest(), drm_map_frame(), dss_read_metadata_string(), dv_read_timecode(), dvbsub_parse_display_definition_segment(), dvbsub_parse_page_segment(), dvbsub_parse_region_segment(), dxva2_device_create(), dxva2_map_frame(), encode_frame(), encode_init(), encode_picture_ls(), encode_sample_description(), enqueue_packet(), epic_add_pixel_to_cache(), extract_extradata(), 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_alsa_get_device_list(), ff_AMediaFormat_new(), ff_AMediaFormat_newFromObject(), ff_ass_add_rect(), ff_ass_split(), ff_ass_split_dialog2(), ff_attach_decode_data(), ff_audio_data_alloc(), ff_audio_mix_alloc(), ff_audio_resample_init(), ff_avc_write_annexb_extradata(), ff_cavs_init_top_lines(), ff_cbs_alloc_unit_content(), ff_cbs_h264_add_sei_message(), ff_cbs_init(), ff_celt_init(), ff_decklink_list_devices(), ff_decklink_list_devices_legacy(), ff_decklink_read_header(), ff_decklink_write_header(), ff_dither_alloc(), ff_dnn_load_model_native(), ff_dnn_load_model_tf(), ff_ebur128_init(), ff_fast_malloc(), 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_h264_decode_picture_parameter_set(), ff_hevc_decode_nal_pps(), ff_hwframe_map_create(), ff_iir_filter_init_state(), ff_init_vscale(), ff_intrax8_common_init(), ff_jpegls_decode_picture(), ff_lpc_init(), ff_lzw_decode_open(), ff_mdct15_init(), ff_merge_channel_layouts(), ff_mjpeg_decode_sof(), ff_mjpeg_encode_init(), ff_mpeg_er_init(), ff_nut_add_sp(), ff_nvdec_decode_init(), ff_nvdec_start_frame(), ff_opus_psy_init(), ff_packet_list_put(), ff_parse_mpeg2_descriptor(), ff_pca_init(), ff_psy_preprocess_init(), ff_qsvvpp_create(), 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_v4l2_context_init(), ff_v4l2_m2m_create_context(), ff_vaapi_encode_init(), ff_vc1_decode_init_alloc_tables(), ff_videotoolbox_alloc_frame(), ff_vk_add_descriptor_set(), ff_vk_create_exec_ctx(), ff_vk_create_imageview(), 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(), fifo_alloc_common(), film_write_packet(), filter_frame(), find_component(), find_headers_search_validate(), flac_read_header(), flashsv2_encode_init(), flashsv_decode_frame(), flashsv_encode_frame(), flashsv_encode_init(), flush_packet(), flv_init(), flv_queue_extradata(), frame_alloc(), frame_pool_alloc(), 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_private_data(), get_siz(), get_surface(), gif_encode_init(), glslang_compile(), gxf_write_header(), handle_file(), handler(), hevc_init_context(), hls_slice_data_wpp(), hls_start(), hnm_decode_init(), hw_device_add(), hwaccel_init(), iec61883_callback(), init(), init_bundles(), init_complex_filtergraph(), init_context_defaults(), init_fps(), init_input_filter(), init_muxer(), init_output_stream(), init_pts(), kmsgrab_read_packet(), lavfi_read_header(), libaribb24_decode(), libcodec2_init_encoder(), libkvazaar_init(), link_filter_inouts(), LLVMFuzzerTestOneInput(), load_glyph(), magy_encode_init(), main(), make_eval_expr(), make_field_queue(), make_point(), mediacodec_decode_init(), mediacodec_wrap_hw_buffer(), mf_enca_output_type_get(), mf_encv_output_type_get(), mjpeg_decode_app(), mmsh_open_internal(), mmsh_read_seek(), mov_read_chapters(), mov_read_covr(), mov_read_dref(), 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_decode_a53_cc(), mpeg_mux_init(), mpeg_mux_write_packet(), mpegts_add_service(), mpegts_init(), mpegts_open_filter(), mpegts_open_section_filter(), mss2_decode_init(), mxf_handle_missing_index_segment(), mxf_read_local_tags(), mxf_uid_to_str(), mxf_umid_to_str(), mxf_write_header(), mxpeg_decode_mxm(), 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(), nvdec_decoder_create(), nvdec_retrieve_data(), nvenc_setup_extradata(), 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(), opaque_list_push(), open_input(), open_input_file(), open_output_file(), opencl_map_frame(), opencl_pool_alloc(), opt_channel_layout(), opt_filter_complex(), opt_filter_complex_script(), opus_header(), overlay_qsv_init(), paf_video_init(), parse_cc_stream_mapstring(), parse_fmtp_config(), parse_inputs(), 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(), process_output_surface(), psy_3gpp_init(), pulse_add_detected_device(), put_audio_specific_config(), put_main_header(), qsv_decode(), qsv_device_create(), 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_packet(), read_packet_vs(), read_priv(), reallocAlign(), resample_init(), resolve_content_path(), rkmpp_init_decoder(), rkmpp_retrieve_frame(), rl2_decode_init(), rv34_decoder_alloc(), sap_write_header(), save_subtitle_set(), segment_end(), set_encoder_id(), set_extradata(), smacker_decode_header_tree(), smka_decode_frame(), sp5x_decode_frame(), speex_header(), stream_open(), 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(), update_block_buffers(), 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(), vc1_decode_frame(), vc1_decode_init(), vc2_encode_init(), 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(), vorbis_update_metadata(), vp6_decode_init(), vp9_raw_reorder_filter(), vqa_decode_init(), vtenc_send_frame(), vulkan_map_frame_to_mem(), wmv2_encode_init(), wrap_texture_buf(), wrapped_avframe_encode(), write_packet(), write_uncoded_frame_internal(), writer_open(), wtvfile_open_sector(), wv_alloc_frame_context(), X264_frame(), and X264_init().

◆ av_malloc_array()

void* av_malloc_array ( size_t  nmemb,
size_t  size 
)

Definition at line 182 of file mem.c.

◆ av_mallocz_array()

void* av_mallocz_array ( size_t  nmemb,
size_t  size 
)

Definition at line 190 of file mem.c.

Referenced by a64multi_encode_init(), alloc_buffers(), alloc_sequence_buffers(), alloc_slice(), allocate_buffers(), allocate_tables(), atrac3_decode_init(), atrac3p_decode_init(), audio_get_buffer(), av_audio_fifo_alloc(), av_encryption_info_alloc(), av_encryption_init_info_alloc(), av_frame_ref(), avcodec_fill_audio_frame(), channelmap_filter_frame(), check_add_bytes(), check_add_left_pred(), check_add_left_pred_16(), check_add_median_pred(), check_stream_max_drift(), checkasm_check_nlmeans(), cng_decode_init(), config_input(), config_input_ref(), config_output(), D(), decode_entropy_coded_image(), decode_frame_header(), decode_init(), decode_picture_header(), dejudder_init(), display_end_segment(), dnxhd_decode_init(), dxva2_init_pool(), encode_init(), ff_alloc_entries(), ff_cavs_init_top_lines(), ff_ebur128_init(), ff_ffv1_init_slice_state(), ff_filter_alloc(), ff_frame_pool_get(), 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_mlz_init_dict(), ff_opus_parse_extradata(), ff_png_zalloc(), ff_psy_init(), ff_psy_preprocess_init(), ff_qsv_enc_init(), ff_qsvvpp_create(), ff_slice_buffer_init(), ff_snow_alloc_blocks(), ff_snow_common_init_after_header(), ff_stream_encode_params_copy(), ffurl_get_protocols(), find_component(), find_device(), g2m_init_buffers(), get_audio_buffer(), get_buffer(), get_siz(), h264_init_context(), hds_write_header(), huf_uncompress(), hwframe_pool_prealloc(), ico_write_header(), init(), init_band(), init_filter_param(), init_out_session(), init_parse_context(), init_pattern_from_string(), init_prec(), init_tiles(), init_vpp_session(), ism_write_header(), ivi_init_tiles(), join_config_output(), join_init(), jpeg2000_decode_packet(), libopus_encode_init(), libx265_encode_set_roi(), main(), mkv_init(), mov_init(), mov_read_sample_encryption_info(), mov_read_stsd(), mp_decode_init(), mxf_compute_index_tables(), nvenc_setup_surfaces(), open_input_file(), open_output_file(), opus_decode_init(), overlay_qsv_init(), pic_arrays_init(), program_opencl_init(), psy_3gpp_init(), qsv_create_mids(), qsv_frames_derive_from(), qsv_frames_derive_to(), qsv_frames_init(), qsv_init_pool(), qsv_setup_mids(), 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(), save_subtitle_set(), set_gauss(), set_input_output_native(), set_input_output_tf(), set_roi_map(), setup_derivative_buffers(), setup_find_stream_info_opts(), smacker_decode_header_tree(), swri_realloc_audio(), tee_write_header(), tiff_decode_tag(), try_push_frame(), vaapi_encode_issue(), var_size_bme(), vorbis_parse_id_hdr(), vorbis_parse_setup_hdr_codebooks(), vorbis_parse_setup_hdr_floors(), vorbis_parse_setup_hdr_mappings(), X264_frame(), XAVS_init(), and xmv_read_header().

◆ av_calloc()

void* av_calloc ( size_t  nmemb,
size_t  size 
)

◆ av_realloc()

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. If size is zero, free the memory block pointed to by ptr. 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 or the function is used to free the memory block
Warning
Unlike av_malloc(), the returned pointer is not guaranteed to be correctly aligned.
See also
av_fast_realloc()
av_reallocp()

Definition at line 134 of file mem.c.

Referenced by add_adaptation_set(), add_file(), append_extradata(), av_bprint_alloc(), av_bprint_finalize(), av_buffer_realloc(), av_fast_realloc(), av_frame_new_side_data_from_buf(), av_packet_add_side_data(), av_packet_pack_dictionary(), av_realloc_array(), av_realloc_f(), av_reallocp(), av_strdup(), av_stream_add_side_data(), av_strndup(), avfilter_graph_alloc_filter(), buf_realloc(), cbs_h2645_assemble_fragment(), concat_open(), decode_header(), dnn_execute_layer_conv2d(), dnn_execute_layer_depth2space(), dnn_execute_layer_math_binary(), dnn_execute_layer_math_unary(), dnn_execute_layer_maximum(), dnn_execute_layer_pad(), 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_ppt(), huf_build_dec_table(), jpeg2000_decode_packet(), load_textfile(), main(), match_streams(), mov_fix_index(), ogg_new_stream(), 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 161 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(), concat_open(), 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(), mov_cenc_end_packet(), mov_realloc_extradata(), omx_encode_frame(), omx_encode_init(), 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().

◆ 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 146 of file mem.c.

Referenced by av_reallocp_array().

◆ av_realloc_array()

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

◆ av_reallocp_array()

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

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

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

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.

Definition at line 206 of file mem.c.

Referenced by add_fragment(), add_pat_entry(), add_segment(), add_tracked_method(), allocate_buffers(), ass_split_section(), ff_h2645_extract_rbsp(), ff_hap_set_chunk_count(), filter_frame(), gxf_write_map_packet(), gxf_write_packet(), hvcc_array_add_nal_unit(), hw_device_add(), mov_add_tfra_entries(), mov_build_index(), mov_read_trex(), mxf_write_packet(), mxf_write_partition(), new_audio_stream(), nut_write_packet(), ogg_restore(), opencl_frames_get_constraints(), parse_adaptation_sets(), parse_strk(), tgv_decode_inter(), tm2_read_stream(), update_context_from_user(), update_index(), and vp56_size_changed().

◆ 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 478 of file mem.c.

Referenced by add_buf_dep_exec_ctx(), add_ctts_entry(), add_index_entry(), caf_write_packet(), decode_frame(), dirac_combine_frame(), 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_subtitles_queue_insert(), ff_vdpau_add_buffer(), ff_vk_add_dep_exec_ctx(), ff_vk_add_exec_dep(), ff_vk_map_buffers(), ff_vk_unmap_buffers(), filter_frame(), flac_fifo_read_wrap(), get_stats(), init(), intercept_id3(), 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(), mov_try_read_block(), mxg_update_cache(), nvdec_h264_decode_slice(), nvdec_hevc_decode_slice(), parse_string(), read_frame(), shorten_decode_frame(), spdif_header_eac3(), update_frag_index(), and videotoolbox_buffer_copy().

◆ 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 502 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(), crypto_write(), decode_8(), decode_frame(), detect_clips(), do_interpolation(), ff_dca_core_filter_fixed(), ff_mpeg_update_thread_context(), 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(), pmp_packet(), reconfigure_at_keyframe(), rscc_decode_frame(), spdif_header_dts4(), spdif_write_packet(), svq3_decode_slice_header(), tak_decode_frame(), truemotion1_decode_header(), truemotion1_decode_init(), 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 507 of file mem.c.

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

◆ 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 219 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 228 of file mem.c.

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

◆ 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 253 of file mem.c.

Referenced by add_input_streams(), add_tracked_method(), ass_decode_frame(), av_append_path_component(), av_bsf_list_parse_str(), av_dict_get_string(), av_dict_set(), av_opt_copy(), av_opt_get(), avfilter_graph_parse(), avfilter_graph_queue_command(), avfilter_init_str(), avformat_alloc_output_context2(), avformat_open_input(), avpriv_tempfile(), caca_write_header(), check_extensions(), choose_pix_fmts(), cine_read_header(), config_input(), config_output(), configure_filtergraph(), convert_sub_to_old_ass_form(), curves_init(), dash_init(), decimate_init(), draw_curves(), 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_mkdir_p(), ff_stream_encode_params_copy(), ff_tls_open_underlying(), ffio_fdopen(), ffurl_connect(), fieldmatch_init(), format_name(), frei0r_init(), ftp_connect(), ftp_current_dir(), ftp_parse_entry_mlsd(), ftp_parse_entry_nlst(), geq_init(), get_cookies(), get_current_fragment(), get_geokey_val(), get_opt_flags_string(), get_ost_filters(), glslang_compile(), 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_connect(), http_open(), icecast_open(), init(), init_filter(), init_filters(), init_muxer(), initialize(), lavfi_read_header(), libsmbc_read_dir(), libsrt_open(), libssh_read_dir(), log_callback(), main(), match_stream_specifier(), mkv_write_simpletag(), mmsh_open_internal(), movie_common_init(), mpjpeg_read_packet(), mtv_read_header(), new_audio_stream(), new_init_section(), new_output_stream(), new_video_stream(), open_camera(), open_input_file(), open_output_file(), open_slave(), opengl_write_header(), opt_filter_complex(), opt_map(), opt_map_channel(), opt_sdp_file(), opt_vstats_file(), parse_cc_stream_mapstring(), parse_channel_expressions(), parse_device_name(), parse_fmtp(), parse_frames(), parse_location(), parse_manifest(), parse_manifest_representation(), parse_map(), 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_custom_noise(), read_gains(), read_header(), read_tf_coefficients(), read_ttag(), read_zp_coefficients(), realtext_read_header(), rfc4175_parse_fmtp(), rtmp_http_open(), sami_paragraph_to_ass(), sap_read_header(), sap_write_header(), scale_parse_expr(), sdl2_write_header(), segment_end(), set_enable_expr(), set_expr(), set_options(), set_segment_filename(), set_string(), show_help(), sls_flags_filename_process(), stream_open(), update_master_pl_info(), v4l2_get_device_list(), validate_name(), write_option(), X264_init(), 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 265 of file mem.c.

Referenced by hw_device_init_from_string(), libsrt_open(), 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 
)

Duplicate a buffer with av_malloc().

Parameters
pBuffer to be duplicated
sizeSize in bytes of the buffer copied
Returns
Pointer to a newly allocated buffer containing a copy of p or NULL if the buffer cannot be allocated

Definition at line 285 of file mem.c.

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

◆ 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 428 of file mem.c.

Referenced by copy_backptr(), decode_dsw1(), decode_frame(), decode_tsw1(), ff_color_frame(), ff_lzf_uncompress(), fill_frame(), generate_missing_ref(), memset_bytes(), mszh_decomp(), picmemset(), 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:31
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:478
uint8_t
uint8_t
Definition: audio_convert.c:194
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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:502