FFmpeg
Files | Data Structures | Macros | Functions

Files

file  buffer.h
 

Data Structures

struct  AVBufferRef
 A reference to a data buffer. More...
 

Macros

#define AV_BUFFER_FLAG_READONLY   (1 << 0)
 Always treat the buffer as read-only, even when it has only one reference. More...
 

Functions

AVBufferRefav_buffer_alloc (size_t size)
 Allocate an AVBuffer of the given size using av_malloc(). More...
 
AVBufferRefav_buffer_allocz (size_t size)
 Same as av_buffer_alloc(), except the returned buffer will be initialized to zero. More...
 
AVBufferRefav_buffer_create (uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
 Create an AVBuffer from an existing array. More...
 
void av_buffer_default_free (void *opaque, uint8_t *data)
 Default free callback, which calls av_free() on the buffer data. More...
 
AVBufferRefav_buffer_ref (const AVBufferRef *buf)
 Create a new reference to an AVBuffer. More...
 
void av_buffer_unref (AVBufferRef **buf)
 Free a given reference and automatically free the buffer if there are no more references to it. More...
 
int av_buffer_is_writable (const AVBufferRef *buf)
 
void * av_buffer_get_opaque (const AVBufferRef *buf)
 
int av_buffer_get_ref_count (const AVBufferRef *buf)
 
int av_buffer_make_writable (AVBufferRef **buf)
 Create a writable reference from a given buffer reference, avoiding data copy if possible. More...
 
int av_buffer_realloc (AVBufferRef **buf, size_t size)
 Reallocate a given buffer. More...
 
int av_buffer_replace (AVBufferRef **dst, const AVBufferRef *src)
 Ensure dst refers to the same data as src. More...
 

Detailed Description

AVBuffer is an API for reference-counted data buffers.

There are two core objects in this API – AVBuffer and AVBufferRef. AVBuffer represents the data buffer itself; it is opaque and not meant to be accessed by the caller directly, but only through AVBufferRef. However, the caller may e.g. compare two AVBuffer pointers to check whether two different references are describing the same data buffer. AVBufferRef represents a single reference to an AVBuffer and it is the object that may be manipulated by the caller directly.

There are two functions provided for creating a new AVBuffer with a single reference – av_buffer_alloc() to just allocate a new buffer, and av_buffer_create() to wrap an existing array in an AVBuffer. From an existing reference, additional references may be created with av_buffer_ref(). Use av_buffer_unref() to free a reference (this will automatically free the data once all the references are freed).

The convention throughout this API and the rest of FFmpeg is such that the buffer is considered writable if there exists only one reference to it (and it has not been marked as read-only). The av_buffer_is_writable() function is provided to check whether this is true and av_buffer_make_writable() will automatically create a new writable buffer when necessary. Of course nothing prevents the calling code from violating this convention, however that is safe only when all the existing references are under its control.

Note
Referencing and unreferencing the buffers is thread-safe and thus may be done from multiple threads simultaneously without any need for additional locking.
Two different references to the same buffer can point to different parts of the buffer (i.e. their AVBufferRef.data will not be equal).

Macro Definition Documentation

◆ AV_BUFFER_FLAG_READONLY

#define AV_BUFFER_FLAG_READONLY   (1 << 0)

Always treat the buffer as read-only, even when it has only one reference.

Definition at line 114 of file buffer.h.

Function Documentation

◆ av_buffer_alloc()

AVBufferRef* av_buffer_alloc ( size_t  size)

◆ av_buffer_allocz()

AVBufferRef* av_buffer_allocz ( size_t  size)

◆ av_buffer_create()

AVBufferRef* av_buffer_create ( uint8_t *  data,
size_t  size,
void(*)(void *opaque, uint8_t *data free,
void *  opaque,
int  flags 
)

Create an AVBuffer from an existing array.

If this function is successful, data is owned by the AVBuffer. The caller may only access data through the returned AVBufferRef and references derived from it. If this function fails, data is left untouched.

Parameters
datadata array
sizesize of data in bytes
freea callback for freeing this buffer's data
opaqueparameter to be got for processing or passed to free
flagsa combination of AV_BUFFER_FLAG_*
Returns
an AVBufferRef referring to data on success, NULL on failure.

Definition at line 55 of file buffer.c.

Referenced by alloc_rbsp_buffer(), av_buffer_alloc(), av_buffer_realloc(), av_detection_bbox_create_side_data(), av_hwdevice_ctx_alloc(), av_hwframe_ctx_alloc(), av_packet_from_data(), av_video_enc_params_create_side_data(), bufref_wrap_interface(), cbs_clone_unit_content(), cbs_h2645_assemble_fragment(), cbs_insert_unit_data(), create_buf(), cuda_pool_alloc(), decode_registered_user_data_dynamic_hdr_plus(), decode_registered_user_data_dynamic_hdr_vivid(), dxva2_pool_alloc(), ff_attach_decode_data(), ff_cbs_alloc_unit_content(), ff_cbs_alloc_unit_content2(), ff_cbs_sei_alloc_message_payload(), ff_dovi_attach_side_data(), ff_flac_parse_picture(), ff_h264_decode_picture_parameter_set(), ff_hevc_decode_nal_pps(), ff_hwframe_map_create(), ff_v4l2_m2m_create_context(), ff_videotoolbox_alloc_frame(), ff_vk_create_imageview(), ffmmal_set_ref(), frame_pool_alloc(), kmsgrab_read_packet(), mediacodec_wrap_hw_buffer(), mmap_read_frame(), nvdec_alloc_dummy(), nvdec_decoder_create(), nvdec_retrieve_data(), opencl_pool_alloc(), qsv_create_mids(), qsv_pool_alloc(), read_header_vs(), read_packet_vs(), rkmpp_init_decoder(), rkmpp_retrieve_frame(), v4l2_buf_to_bufref(), vaapi_encode_alloc_output_buffer(), vaapi_pool_alloc(), vdpau_pool_alloc(), decklink_input_callback::VideoInputFrameArrived(), vt_pool_alloc_buffer(), vulkan_pool_alloc(), wrap_texture_buf(), wrapped_avframe_encode(), write_uncoded_frame_internal(), and xcbgrab_frame().

◆ av_buffer_default_free()

void av_buffer_default_free ( void *  opaque,
uint8_t *  data 
)

Default free callback, which calls av_free() on the buffer data.

This function is meant to be passed to av_buffer_create(), not called directly.

Definition at line 72 of file buffer.c.

Referenced by av_buffer_alloc(), av_buffer_realloc(), av_packet_from_data(), buffer_create(), and ff_flac_parse_picture().

◆ av_buffer_ref()

AVBufferRef* av_buffer_ref ( const AVBufferRef buf)

Create a new reference to an AVBuffer.

Returns
a new AVBufferRef referring to the same AVBuffer as buf or NULL on failure.

Definition at line 103 of file buffer.c.

Referenced by add_buf_dep_exec_ctx(), alloc_picture(), amf_init_context(), av1_decode_frame(), av1_frame_ref(), av_buffer_replace(), av_buffersrc_parameters_set(), av_frame_ref(), av_hwdevice_ctx_create_derived_opts(), av_hwframe_ctx_alloc(), av_hwframe_ctx_create_derived(), av_hwframe_get_buffer(), av_packet_ref(), av_write_frame(), avfilter_config_links(), bitpacked_decode_uyvy422(), cbs_av1_read_unit(), cbs_av1_ref_tile_data(), cbs_av1_write_obu(), cbs_clone_unit_content(), cbs_h2645_replace_ps(), cbs_h265_read_nal_unit(), cbs_insert_unit_data(), cbs_jpeg_read_unit(), cbs_mpeg2_read_unit(), cbs_read_data(), cbs_vp9_assemble_fragment(), cbs_vp9_read_unit(), config_input(), config_output(), config_props(), config_props_output(), config_props_ref(), cudaupload_config_output(), cuvid_decode_init(), cuvid_output_frame(), dec_enc(), ff_cbs_insert_unit_content(), ff_cbs_sei_add_message(), ff_cbs_write_packet(), ff_h264_decode_picture_parameter_set(), ff_h264_ref_picture(), ff_h264_update_thread_context(), ff_hwframe_map_create(), ff_mpeg_ref_picture(), ff_nvdec_decode_init(), ff_nvdec_start_frame(), ff_thread_ref_frame(), ff_vaapi_encode_init(), ff_vaapi_vpp_config_input(), ff_vaapi_vpp_config_output(), ff_vk_filter_config_output_inplace(), ffmmal_add_packet(), frame_add_buf(), frame_copy_props(), frame_header_obu(), get_current_frame(), h264_init_ps(), hevc_ref_frame(), hw_decoder_init(), hw_device_setup_for_decode(), hw_device_setup_for_encode(), hw_device_setup_for_filter(), hwdownload_config_input(), hwmap_config_output(), hwmap_filter_frame(), hwupload_config_output(), hwupload_query_formats(), ifilter_parameters_from_frame(), init_processing_chain(), kmsgrab_read_packet(), libdav1d_receive_frame(), LLVMFuzzerTestOneInput(), main(), mpeg4_unpack_bframes_filter(), nppsharpen_config(), npptranspose_config_props(), nvdec_decoder_create(), nvdec_retrieve_data(), open_input_file(), opencl_filter_set_device(), overlay_cuda_config_output(), parse_nal_units(), parse_packet(), qsv_create_mids(), qsv_frame_lock(), qsv_init_session(), qsv_map_from(), qsv_setup_mids(), qsvdeint_config_props(), qsvenc_init_session(), raw_decode(), read_packet_vs(), rkmpp_retrieve_frame(), set_hwframe_ctx(), set_side_data(), transpose_opencl_config_output(), transpose_vaapi_vpp_config_output(), try_push_frame(), update_context_from_thread(), v4l2_buf_increase_ref(), videotoolbox_postproc_frame(), vp9_frame_ref(), vpx_decode(), vpx_encode(), vulkan_filter_set_device(), and vulkan_filter_set_frames().

◆ av_buffer_unref()

void av_buffer_unref ( AVBufferRef **  buf)

Free a given reference and automatically free the buffer if there are no more references to it.

Parameters
bufthe reference to be freed. The pointer is set to NULL on return.

Definition at line 139 of file buffer.c.

Referenced by addroi_filter_frame(), alloc_rbsp_buffer(), asf_parse_packet(), av1_decode_frame(), av1_decode_free(), av1_frame_unref(), av_buffer_replace(), av_buffersrc_parameters_set(), av_detection_bbox_create_side_data(), av_frame_new_side_data(), av_frame_unref(), av_hwdevice_ctx_create(), av_hwdevice_ctx_create_derived_opts(), av_hwframe_ctx_alloc(), av_hwframe_ctx_create_derived(), av_hwframe_get_buffer(), av_packet_copy_props(), av_packet_make_writable(), av_packet_unref(), av_video_enc_params_create_side_data(), avcodec_close(), avcodec_get_hw_frames_parameters(), avfilter_free(), avi_read_close(), bitpacked_decode_uyvy422(), cbs_av1_close(), cbs_av1_flush(), cbs_av1_free_metadata(), cbs_av1_read_unit(), cbs_av1_write_obu(), cbs_clone_unit_content(), cbs_default_free_unit_content(), cbs_free_user_data_registered(), cbs_free_user_data_unregistered(), cbs_h264_close(), cbs_h264_flush(), cbs_h265_close(), cbs_h265_flush(), cbs_insert_unit_data(), cbs_jpeg_free_application_data(), cbs_jpeg_free_comment(), cbs_jpeg_free_scan(), cbs_read_fragment_content(), cbs_sei_delete_message(), cbs_unit_uninit(), cbs_vp9_assemble_fragment(), copy_hdr10_plus_to_pkt(), cudachromakey_uninit(), cudascale_uninit(), cudaupload_config_output(), cudaupload_uninit(), cuvid_decode_end(), decode_nal_units(), decode_receive_frame_internal(), decode_registered_user_data_dynamic_hdr_plus(), decode_registered_user_data_dynamic_hdr_vivid(), deint_cuda_uninit(), extract_extradata_av1(), extract_extradata_h2645(), ff_amf_encode_close(), ff_attach_decode_data(), ff_cbs_fragment_reset(), ff_cbs_insert_unit_content(), ff_cbs_make_unit_writable(), ff_cbs_sei_free_message_list(), ff_cbs_write_fragment_data(), ff_cbs_write_packet(), ff_decode_get_hw_frames_ctx(), ff_dovi_attach_side_data(), ff_dovi_ctx_flush(), ff_dovi_ctx_unref(), ff_dxva2_decode_uninit(), ff_er_frame_end(), ff_flac_parse_picture(), ff_frame_thread_free(), ff_h2645_packet_uninit(), ff_h264_decode_picture_parameter_set(), ff_h264_decode_seq_parameter_set(), ff_h264_ps_uninit(), ff_h264_sei_uninit(), ff_h264_unref_picture(), ff_h264_update_thread_context(), ff_hevc_decode_nal_pps(), ff_hevc_decode_nal_sps(), ff_hevc_decode_nal_vps(), ff_hevc_ps_uninit(), ff_hevc_reset_sei(), ff_hevc_unref_frame(), ff_hwframe_map_create(), ff_hwframe_unmap(), ff_icc_profile_attach(), ff_mpeg_unref_picture(), ff_nvdec_decode_init(), ff_nvdec_decode_uninit(), ff_nvdec_start_frame_sep_ref(), ff_opencl_filter_config_output(), ff_opencl_filter_uninit(), ff_qsv_close_internal_session(), ff_qsv_enc_close(), ff_qsv_init_session_frames(), ff_sp5x_process_packet(), ff_thread_get_ext_buffer(), ff_thread_release_ext_buffer(), ff_v4l2_m2m_codec_end(), ff_v4l2_m2m_create_context(), ff_vaapi_encode_close(), ff_vaapi_vpp_config_output(), ff_vaapi_vpp_ctx_uninit(), ff_vaapi_vpp_pipeline_uninit(), ff_vk_create_imageview(), ff_vk_discard_exec_deps(), ff_vk_filter_config_output(), ff_vk_filter_config_output_inplace(), ff_vk_uninit(), ffmmal_fill_input_port(), ffmmal_stop_decoder(), ffmpeg_cleanup(), frame_copy_props(), frame_header_obu(), free_apic(), free_exec_ctx(), free_hdr10_plus_fifo(), free_link(), free_picture_tables(), free_side_data(), free_vsframe_ref(), h264_export_frame_props(), h264_init_ps(), handle_packets(), hevc_decode_flush(), hevc_decode_free(), hw_device_free_all(), hw_device_init_from_string(), hw_device_init_from_type(), hwaccel_uninit(), hwdevice_ctx_free(), hwdownload_config_input(), hwdownload_uninit(), hwframe_ctx_free(), hwmap_config_output(), hwmap_uninit(), hwupload_config_output(), hwupload_query_formats(), hwupload_uninit(), iccdetect_uninit(), ifilter_parameters_from_frame(), init_hwframe_ctx(), init_stage(), init_vpp_session(), input_callback(), kmsgrab_read_close(), libdav1d_data_free(), libdav1d_picture_allocator(), libdav1d_picture_release(), libdav1d_receive_frame(), libjxl_decode_close(), libjxl_get_icc(), main(), mediacodec_wrap_hw_buffer(), mids_buf_free(), mpeg4_unpack_bframes_close_flush(), mpeg4_unpack_bframes_filter(), mpeg_decode_end(), mpeg_field_start(), mpegts_close_filter(), nppscale_uninit(), nppsharpen_config(), nppsharpen_uninit(), npptranspose_uninit(), nvdec_decoder_create(), nvdec_decoder_free(), nvdec_fdd_priv_free(), nvdec_init_hwframes(), nvdec_retrieve_data(), nvdec_unmap_mapped_frame(), opencl_filter_set_device(), overlay_cuda_uninit(), parse_nal_units(), pool_alloc_buffer(), pps_free(), prepare_input_packet(), qsv_create_mids(), qsv_decode_close_qsvcontext(), qsv_decode_preinit(), qsv_device_free(), qsv_frame_alloc(), qsv_frame_free(), qsv_frames_uninit(), qsv_init_child_ctx(), qsv_init_session(), qsv_setup_mids(), qsvdeint_config_props(), qsvdeint_uninit(), qsvenc_init_session(), raw_close_decoder(), raw_decode(), read_close_vs(), read_packet_vs(), release_frame_buffer(), remove_pps(), remove_sps(), remove_vps(), reset_pes_packet_state(), rkmpp_close_decoder(), rkmpp_release_decoder(), rkmpp_release_frame(), rkmpp_retrieve_frame(), set_hwframe_ctx(), set_side_data(), test_derivation(), test_device(), uninit(), unref_exec_ctx_deps(), update_context_from_thread(), update_frame_pool(), v4l2_buf_to_bufref(), v4l2_free_buffer(), vaapi_encode_discard(), vaapi_encode_issue(), vaapi_encode_output(), vaapi_frames_init(), videotoolbox_buffer_release(), videotoolbox_postproc_frame(), vp8_alloc_frame(), vp8_release_frame(), vp9_frame_unref(), vpx_encode(), vulkan_filter_set_device(), vulkan_filter_set_frames(), vulkan_free_internal(), wavpack_decode_end(), and wv_dsd_reset().

◆ av_buffer_is_writable()

int av_buffer_is_writable ( const AVBufferRef buf)
Returns
1 if the caller may write to the data referred to by buf (which is true if and only if buf is the only reference to the underlying AVBuffer). Return 0 otherwise. A positive answer is valid until av_buffer_ref() is called on buf.

Definition at line 147 of file buffer.c.

Referenced by alloc_rbsp_buffer(), av_buffer_make_writable(), av_buffer_realloc(), av_frame_is_writable(), av_grow_packet(), av_packet_make_writable(), and ff_cbs_make_unit_writable().

◆ av_buffer_get_opaque()

void* av_buffer_get_opaque ( const AVBufferRef buf)
Returns
the opaque parameter set by av_buffer_create.

Definition at line 155 of file buffer.c.

◆ av_buffer_get_ref_count()

int av_buffer_get_ref_count ( const AVBufferRef buf)

Definition at line 160 of file buffer.c.

Referenced by ff_h264_build_ref_list().

◆ av_buffer_make_writable()

int av_buffer_make_writable ( AVBufferRef **  buf)

Create a writable reference from a given buffer reference, avoiding data copy if possible.

Parameters
bufbuffer reference to make writable. On success, buf is either left untouched, or it is unreferenced and a new writable AVBufferRef is written in its place. On failure, buf is left untouched.
Returns
0 on success, a negative AVERROR on failure.

Definition at line 165 of file buffer.c.

Referenced by ff_cbs_make_unit_writable(), and raw_decode().

◆ av_buffer_realloc()

int av_buffer_realloc ( AVBufferRef **  buf,
size_t  size 
)

Reallocate a given buffer.

Parameters
bufa buffer reference to reallocate. On success, buf will be unreferenced and a new reference with the required size will be written in its place. On failure buf will be left untouched. *buf may be NULL, then a new buffer is allocated.
sizerequired new buffer size.
Returns
0 on success, a negative AVERROR on failure.
Note
the buffer is actually reallocated with av_realloc() only if it was initially allocated through av_buffer_realloc(NULL) and there is only one reference to it (i.e. the one passed to this function). In all other cases a new buffer is allocated and the data is copied.

Definition at line 183 of file buffer.c.

Referenced by av_buffer_realloc(), av_grow_packet(), avcodec_default_get_encode_buffer(), ff_parse_a53_cc(), mpeg_decode_a53_cc(), and packet_alloc().

◆ av_buffer_replace()

int av_buffer_replace ( AVBufferRef **  dst,
const AVBufferRef src 
)

Ensure dst refers to the same data as src.

When *dst is already equivalent to src, do nothing. Otherwise unreference dst and replace it with a new reference to src.

Parameters
dstPointer to either a valid buffer reference or NULL. On success, this will point to a buffer reference equivalent to src. On failure, dst will be left untouched.
srcA buffer reference to replace dst with. May be NULL, then this function is equivalent to av_buffer_unref(dst).
Returns
0 on success AVERROR(ENOMEM) on memory allocation failure.

Definition at line 233 of file buffer.c.

Referenced by av1_frame_ref(), av_packet_copy_props(), ff_dovi_ctx_replace(), ff_h264_replace_picture(), ff_h264_update_thread_context(), ff_update_picture_tables(), flashsv_decode_frame(), frame_copy_props(), iccdetect_filter_frame(), and update_context_from_thread().