FFmpeg
|
AVBuffer is an API for reference-counted data buffers. More...
Files | |
file | buffer.h |
refcounted data buffer API | |
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... | |
Typedefs | |
typedef struct AVBuffer | AVBuffer |
A reference counted buffer type. More... | |
typedef struct AVBufferRef | AVBufferRef |
A reference to a data buffer. More... | |
Functions | |
AVBufferRef * | av_buffer_alloc (int size) |
Allocate an AVBuffer of the given size using av_malloc(). More... | |
AVBufferRef * | av_buffer_allocz (int size) |
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero. More... | |
AVBufferRef * | av_buffer_create (uint8_t *data, int 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... | |
AVBufferRef * | av_buffer_ref (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, int size) |
Reallocate a given buffer. 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
#define AV_BUFFER_FLAG_READONLY (1 << 0) |
Always treat the buffer as read-only, even when it has only one reference.
Definition at line 113 of file buffer.h.
Referenced by av_buffer_create(), av_buffer_is_writable(), and av_buffersrc_add_frame_internal().
Typedef Documentation
A reference counted buffer type.
It is opaque and is meant to be used through references (AVBufferRef).
typedef struct AVBufferRef AVBufferRef |
A reference to a data buffer.
The size of this struct is not a part of the public ABI and it is not meant to be allocated directly.
Function Documentation
AVBufferRef* av_buffer_alloc | ( | int | size | ) |
Allocate an AVBuffer of the given size using av_malloc().
- Returns
- an AVBufferRef of given size or NULL when out of memory
Definition at line 65 of file libavutil/buffer.c.
Referenced by av_buffer_allocz(), av_buffer_make_writable(), av_buffer_pool_init(), av_grow_packet(), av_packet_merge_side_data(), ff_asf_parse_packet(), ff_default_get_audio_buffer(), ff_mjpeg_decode_frame(), get_audio_buffer(), get_video_buffer(), matroska_decode_buffer(), mpegts_push_data(), parse_picture(), raw_decode(), raw_init_decoder(), read_apic(), and thread_get_buffer_internal().
AVBufferRef* av_buffer_allocz | ( | int | size | ) |
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition at line 81 of file libavutil/buffer.c.
Referenced by alloc_frame_buffer(), alloc_picture(), alloc_picture_tables(), ff_er_frame_end(), get_buffer(), init_table_pools(), update_frame_pool(), and vp8_alloc_frame().
AVBufferRef* av_buffer_create | ( | uint8_t * | data, |
int | 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
-
data data array size size of data in bytes free a callback for freeing data opaque parameter to be got for processing or passed to free flags a combination of AV_BUFFER_FLAG_*
- Returns
- an AVBufferRef referring to data on success, NULL on failure.
Definition at line 27 of file libavutil/buffer.c.
Referenced by av_buffer_alloc(), av_buffer_pool_get(), av_buffer_realloc(), av_buffersrc_add_frame_internal(), av_packet_from_data(), do_streamcopy(), get_buffer2(), get_buffer_internal(), mmap_read_frame(), and write_frame().
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 60 of file libavutil/buffer.c.
Referenced by av_buffer_alloc(), av_buffer_create(), av_buffer_realloc(), av_packet_from_data(), do_streamcopy(), and write_frame().
void* av_buffer_get_opaque | ( | const AVBufferRef * | buf | ) |
- Returns
- the opaque parameter set by av_buffer_create.
Definition at line 128 of file libavutil/buffer.c.
Referenced by vdadec_decode().
int av_buffer_get_ref_count | ( | const AVBufferRef * | buf | ) |
Definition at line 133 of file libavutil/buffer.c.
Referenced by ff_h264_decode_ref_pic_list_reordering().
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 120 of file libavutil/buffer.c.
Referenced by av_buffer_make_writable(), av_buffer_realloc(), and av_frame_is_writable().
int av_buffer_make_writable | ( | AVBufferRef ** | buf | ) |
Create a writable reference from a given buffer reference, avoiding data copy if possible.
- Parameters
-
buf buffer 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 138 of file libavutil/buffer.c.
int av_buffer_realloc | ( | AVBufferRef ** | buf, |
int | size | ||
) |
Reallocate a given buffer.
- Parameters
-
buf a 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. size required 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 156 of file libavutil/buffer.c.
Referenced by av_buffer_realloc(), av_grow_packet(), av_new_packet(), avcodec_encode_audio2(), and avcodec_encode_video2().
AVBufferRef* av_buffer_ref | ( | 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 91 of file libavutil/buffer.c.
Referenced by av_buffersrc_add_frame_internal(), av_frame_copy_props(), av_frame_ref(), avformat_queue_attached_pictures(), copy_packet_data(), ff_mpeg_ref_picture(), ff_mpv_export_qp_table(), ff_thread_ref_frame(), join_request_frame(), mkv_write_packet(), query_codec(), raw_decode(), ref_picture(), submit_packet(), and vp8_ref_frame().
void av_buffer_unref | ( | AVBufferRef ** | buf | ) |
Free a given reference and automatically free the buffer if there are no more references to it.
- Parameters
-
buf the reference to be freed. The pointer is set to NULL on return.
Definition at line 105 of file libavutil/buffer.c.
Referenced by av_buffer_make_writable(), av_buffer_realloc(), av_buffersrc_add_frame_internal(), av_frame_set_qp_table(), av_frame_unref(), av_free_packet(), compat_release_buffer(), ff_asf_parse_packet(), ff_default_get_audio_buffer(), ff_er_frame_end(), ff_mpeg_unref_picture(), ff_thread_release_buffer(), frame_thread_free(), free_apic(), free_picture(), free_picture_tables(), get_buffer_internal(), get_video_buffer(), handle_packets(), matroska_decode_buffer(), mpegts_close_filter(), parse_picture(), pool_alloc_buffer(), raw_close_decoder(), raw_decode(), submit_packet(), thread_get_buffer_internal(), unref_picture(), and vp8_release_frame().
Generated on Mon Nov 18 2024 06:52:10 for FFmpeg by 1.8.11