0. 概述
缓冲区是 GStreamer 中数据传输的基本单元。它们包含定时和偏移量以及与缓冲区包含的 GstMemory 块关联的其他任意元数据。
缓冲区通常是用 gst_buffer_new 创建的。创建缓冲区后,通常会为其分配内存并将其添加到缓冲区中。下面的示例创建一个缓冲区,该缓冲区可以容纳每个平面具有给定宽度、高度和位的给定视频帧。
GstBuffer *buffer;
GstMemory *memory;
gint size, width, height, bpp;
...
size = width * height * bpp;
buffer = gst_buffer_new ();
memory = gst_allocator_alloc (NULL, size, NULL);
gst_buffer_insert_memory (buffer, -1, memory);
...
或者,使用 gst_buffer_new_allocate 创建具有给定大小的预分配数据的缓冲区。
缓冲区可以包含 GstMemory 对象的列表。您可以使用 gst_buffer_n_memory 内存检索多少个内存对象,并且可以使用 gst_buffer_peek_memory 内存获取指向内存的指针。
缓冲区通常会有时间戳和持续时间,但也可能都未设置(可以设置为 GST_CLOCK_TIME_NONE )。无论何时,只要能给这些值一个有意义的值,就应该设置它们。时间戳和持续时间以纳秒为单位(它们是 GstClockTime 值)。
buffer DTS 是指缓冲区解码的时间戳,通常是单调递增的。 buffer PTS 指的是当缓冲区内容应该呈现给用户时的时间戳,并不总是单调递增的。
缓冲区也可以有一个或两个开始偏移和结束偏移。这些是特定于媒体类型的。对于视频缓冲区,开始偏移量通常是帧数。对于音频缓冲区,它将是迄今为止生成的样本数。对于压缩数据,它可以是源文件或目标文件中的字节偏移量。同样,结束偏移量将是缓冲区结束的偏移量。只有知道缓冲区的介质类型(前面的CAPS事件)时,才能对这些进行有意义的解释。其中一个或两个都可以设置为 GST_BUFFER_OFFSET_NONE。
gst_buffer_ref 用于增加缓冲区的 refcount。如果要在将缓冲区推到下一个元素后保留其句柄,则必须执行此操作。buffer refcount 决定了缓冲区的可写性,只有当 refcount 正好为 1 时,即调用方只有对缓冲区的引用时,缓冲区才是可写的。
要在现有缓冲区的基础上高效地创建较小的缓冲区,可以使用 gst_buffer_copy_region。此方法尝试在两个缓冲区之间共享内存对象。
If a plug-in wants to modify the buffer data or metadata in-place, it should first obtain a buffer that is safe to modify by using gst_buffer_make_writable. This function is optimized so that a copy will only be made when it is necessary.
如果插件想要修改缓冲区数据或元数据,它应该首先使用 gst_buffer_make_writable 获得一个可以安全修改的缓冲区。此功能经过优化,因此只有在必要时才进行复制。
Several flags of the buffer can be set and unset with the GST_BUFFER_FLAG_SET and GST_BUFFER_FLAG_UNSET macros. Use GST_BUFFER_FLAG_IS_SET to test if a certain GstBufferFlags flag is set.
可以使用 GST_BUFFER_FLAG_SET 和 GST_BUFFER_FLAG_UNSET 宏设置和取消设置缓冲区的几个标志。使用 GST_BUFFER_FLAG_IS_SET 测试是否设置了某个 GstBufferFlags 标志。
使用 gst_buffer_append 可以有效地将缓冲区合并到更大的缓冲区中。只有在绝对需要的时候才会复制内存。
可以使用 gst_buffer_add_meta 在缓冲区上设置任意额外的元数据。可以使用 gst_buffer_get_meta 检索元数据。另请参见 GstMeta。
元素应该释放缓冲区,或者使用 gst_pad_push 将其推出 src pad(请参见 GstPad)。
缓冲区通常通过 gst_buffer_unref 释放。当 refcount 降到 0 时,缓冲区指向的所有内存和元数据也将不被恢复。当 refcount 降到 0 时,从 GstBufferPool 分配的缓冲区将返回到池。
GstParentBufferMeta 是一个可以附加到 GstBuffer 的 meta,用于保存对另一个缓冲区的引用,该缓冲区仅在释放子 GstBuffer 时才被释放。
通常,当子缓冲区直接使用父缓冲区的 GstMemory 时,会使用 GstParentBufferMeta,并希望在 GstMemory 可供重用之前防止父缓冲区返回缓冲池(自:1.6)
1. GstBuffer
GstBuffer的结构。使用关联的宏访问公共变量。
1.1 成员
- mini_object (GstMiniObject) –父结构
- pool (GstBufferPool *) – 指向缓冲区的池所有者的指针
- pts (GstClockTime) – 缓冲区的表示时间戳,当pts未知或不相关时,可以是 GST_CLOCK_TIME_NONE。pts包含媒体应该呈现给用户的时间戳。
- dts (GstClockTime) – 缓冲区的解码时间戳,当dts未知或不相关时,可以是 GST_CLOCK_TIME_NONE。dts包含处理媒体的时间戳。
- duration (GstClockTime) – 缓冲区数据的持续时间,当持续时间未知或不相关时,可以是 GST_CLOCK_TIME_NONE。
- offset (guint64) – 缓冲区数据的媒体特定偏移量。对于视频帧,这是该缓冲区的帧数。对于音频采样,这是缓冲区中第一个采样的偏移量。对于文件数据或压缩数据,这是缓冲区中第一个字节的字节偏移量。
- offset_end (guint64) – 此缓冲区中包含的最后一个偏移量。它的格式与offset相同。
1.2 构造函数
gst_buffer_new
GstBuffer *
gst_buffer_new ()
创建没有任何数据的新分配的缓冲区。
参数
返回:
- return ( [transfer: full]) – 新的 GstBuffer。
gst_buffer_new_allocate
GstBuffer *
gst_buffer_new_allocate (GstAllocator * allocator,
gsize size,
GstAllocationParams * params)
尝试使用给定大小的数据和分配器中的额外参数创建新分配的缓冲区。如果无法分配请求的内存量,将返回 NULL。分配的缓冲区内存未被清除。
当分配器为空(NULL)时,将使用默认的内存分配器。
请注意,当 size==0 时,缓冲区将没有与其关联的内存。
参数:
- allocator ( [transfer: none][allow-none]) – 要使用的 GstAllocator,或 NULL 使用默认分配器
- size – 新缓冲区数据的字节大小。
- params ( [transfer: none][allow-none]) – 可选参数
返回:
- Returns ( [transfer: full][nullable]) – 一个新的 GstBuffer。
gst_buffer_new_wrapped
GstBuffer *
gst_buffer_new_wrapped (gpointer data,
gsize size)
创建包装给定数据的新缓冲区。内存将被 g_free 释放,并被标记为可写。
gst_buffer_new_wrapped_bytes
GstBuffer *
gst_buffer_new_wrapped_bytes (GBytes * bytes)
创建包装给定字节的新 GstBuffer。字节内的数据不能为空(NULL),产生的缓冲区将被标记为只读。
参数:
- bytes ( [transfer: none]) – 要包装的GB字节
返回:
- Returns ( [transfer: full]) – 新的GstBuffer包装字节
Since : 1.16
gst_buffer_new_wrapped_full
GstBuffer *
gst_buffer_new_wrapped_full (GstMemoryFlags flags,
gpointer data,
gsize maxsize,
gsize offset,
gsize size,
gpointer user_data,
GDestroyNotify notify)
Allocates a new buffer that wraps the given memory. data must point to maxsize of memory, the wrapped buffer will have the region from offset and size visible.
分配一个新缓冲区包装了给定的内存。数据必须指向最大尺寸的内存,包装的缓冲区包括从偏移位置到数据尺寸的可见区域。
当缓冲区被销毁时,将使用 user_data 调用 notify。
如果标志分别包含 GST_MEMORY_FLAG_ZERO_PREFIXED 前缀和 GST_MEMORY_FLAG_ZERO_PADDED ,则前缀/填充必须用 0 填充。
参数:
- flags – GstMemoryFlags
- data ( [arraylength=size][element-typeguint8][transfer: none]) – 要包装的数据
- maxsize – 分配的数据大小
- offset – 数据中的偏移
- size – 有效数据的大小
- user_data ( [allow-none]) – 用户数据
- notify ( [allow-none][scope async][closure]) – 在释放内存时用用户\数据调用
返回:
- Returns ( [transfer: full]) – 一个新的GstBuffer
1.3 方法
gst_buffer_add_custom_meta
GstCustomMeta *
gst_buffer_add_custom_meta (GstBuffer * buffer,
const gchar * name)
Creates and adds a GstCustomMeta for the desired name. name must have been successfully registered with gst_meta_register_custom.
Parameters:
- buffer ( [transfer: none]) – a GstBuffer
- name – the registered name of the desired custom meta
Returns ( [transfer: none][nullable]) – The GstCustomMeta that was added to the buffer
Since : 1.20
gst_buffer_add_meta
GstMeta *
gst_buffer_add_meta (GstBuffer * buffer,
const GstMetaInfo * info,
gpointer params)
Adds metadata for info to buffer using the parameters in params.
Parameters:
- buffer – a GstBuffer
- info – a GstMetaInfo
- params – params for info
Returns ( [transfer: none][nullable]) – the metadata for the api in info on buffer.
gst_buffer_add_parent_buffer_meta
GstParentBufferMeta *
gst_buffer_add_parent_buffer_meta (GstBuffer * buffer,
GstBuffer * ref)
Adds a GstParentBufferMeta to buffer that holds a reference on ref until the buffer is freed.
Parameters:
- buffer ( [transfer: none]) – a GstBuffer
- ref ( [transfer: none]) – a GstBuffer to ref
Returns ( [transfer: none][nullable]) – The GstParentBufferMeta that was added to the buffer
Since : 1.6
gst_buffer_add_protection_meta
GstProtectionMeta *
gst_buffer_add_protection_meta (GstBuffer * buffer,
GstStructure * info)
Attaches protection metadata to a GstBuffer.
Parameters:
buffer – GstBuffer holding an encrypted sample, to which protection metadata should be added.
info ( [transfer: full]) – a GstStructure holding cryptographic information relating to the sample contained in buffer. This function takes ownership of info.
Returns ( [transfer: none]) – a pointer to the added GstProtectionMeta if successful
Since : 1.6
gst_buffer_add_reference_timestamp_meta
GstReferenceTimestampMeta *
gst_buffer_add_reference_timestamp_meta (GstBuffer * buffer,
GstCaps * reference,
GstClockTime timestamp,
GstClockTime duration)
Adds a GstReferenceTimestampMeta to buffer that holds a timestamp and optionally duration based on a specific timestamp reference. See the documentation of GstReferenceTimestampMeta for details.
Parameters:
buffer ( [transfer: none]) – a GstBuffer
reference ( [transfer: none]) – identifier for the timestamp reference.
timestamp – timestamp
duration – duration, or GST_CLOCK_TIME_NONE
Returns ( [transfer: none][nullable]) – The GstReferenceTimestampMeta that was added to the buffer
Since : 1.14
gst_buffer_append
GstBuffer *
gst_buffer_append (GstBuffer * buf1,
GstBuffer * buf2)
Appends all the memory from buf2 to buf1. The result buffer will contain a concatenation of the memory of buf1 and buf2.
Parameters:
buf1 ( [transfer: full]) – the first source GstBuffer to append.
buf2 ( [transfer: full]) – the second source GstBuffer to append.
Returns ( [transfer: full]) – the new GstBuffer that contains the memory of the two source buffers.
gst_buffer_append_memory
gst_buffer_append_memory (GstBuffer * buffer,
GstMemory * mem)
Appends the memory block mem to buffer. This function takes ownership of mem and thus doesn’t increase its refcount.
This function is identical to gst_buffer_insert_memory with an index of -1. See gst_buffer_insert_memory for more details.
Parameters:
buffer – a GstBuffer.
mem ( [transfer: full]) – a GstMemory.
gst_buffer_append_region
GstBuffer *
gst_buffer_append_region (GstBuffer * buf1,
GstBuffer * buf2,
gssize offset,
gssize size)
Appends size bytes at offset from buf2 to buf1. The result buffer will contain a concatenation of the memory of buf1 and the requested region of buf2.
Parameters:
buf1 ( [transfer: full]) – the first source GstBuffer to append.
buf2 ( [transfer: full]) – the second source GstBuffer to append.
offset – the offset in buf2
size – the size or -1 of buf2
Returns ( [transfer: full]) – the new GstBuffer that contains the memory of the two source buffers.
gst_buffer_copy
GstBuffer *
gst_buffer_copy (const GstBuffer * buf)
Creates a copy of the given buffer. This will only copy the buffer’s data to a newly allocated memory if needed (if the type of memory requires it), otherwise the underlying data is just referenced. Check gst_buffer_copy_deep if you want to force the data to be copied to newly allocated memory.
Parameters:
buf – a GstBuffer.
Returns ( [transfer: full]) – a new copy of buf.
gst_buffer_copy_deep
GstBuffer *
gst_buffer_copy_deep (const GstBuffer * buf)
Creates a copy of the given buffer. This will make a newly allocated copy of the data the source buffer contains.
Parameters:
buf – a GstBuffer.
Returns ( [transfer: full]) – a new copy of buf.
Since : 1.6
gst_buffer_copy_into
gboolean
gst_buffer_copy_into (GstBuffer * dest,
GstBuffer * src,
GstBufferCopyFlags flags,
gsize offset,
gsize size)
Copies the information from src into dest.
If dest already contains memory and flags contains GST_BUFFER_COPY_MEMORY, the memory from src will be appended to dest.
flags indicate which fields will be copied.
Parameters:
dest – a destination GstBuffer
src – a source GstBuffer
flags – flags indicating what metadata fields should be copied.
offset – offset to copy from
size – total size to copy. If -1, all data is copied.
Returns – TRUE if the copying succeeded, FALSE otherwise.
gst_buffer_copy_region
GstBuffer *
gst_buffer_copy_region (GstBuffer * parent,
GstBufferCopyFlags flags,
gsize offset,
gsize size)
Creates a sub-buffer from parent at offset and size. This sub-buffer uses the actual memory space of the parent buffer. This function will copy the offset and timestamp fields when the offset is 0. If not, they will be set to GST_CLOCK_TIME_NONE and GST_BUFFER_OFFSET_NONE. If offset equals 0 and size equals the total size of buffer, the duration and offset end fields are also copied. If not they will be set to GST_CLOCK_TIME_NONE and GST_BUFFER_OFFSET_NONE.
Parameters:
parent – a GstBuffer.
flags – the GstBufferCopyFlags
offset – the offset into parent GstBuffer at which the new sub-buffer begins.
size – the size of the new GstBuffer sub-buffer, in bytes. If -1, all data is copied.
Returns ( [transfer: full]) – the new GstBuffer or NULL if the arguments were invalid.
gst_buffer_extract
gsize
gst_buffer_extract (GstBuffer * buffer,
gsize offset,
gpointer dest,
gsize size)
Copies size bytes starting from offset in buffer to dest.
Parameters:
buffer – a GstBuffer.
offset – the offset to extract
dest – (out caller-allocates) (array length=size) (element-type guint8): the destination address
size – the size to extract
Returns – The amount of bytes extracted. This value can be lower than size when buffer did not contain enough data.
gst_buffer_extract_dup
gst_buffer_extract_dup (GstBuffer * buffer,
gsize offset,
gsize size,
gpointer * dest,
gsize * dest_size)
Extracts a copy of at most size bytes the data at offset into newly-allocated memory. dest must be freed using g_free when done.
Parameters:
buffer – a GstBuffer
offset – the offset to extract
size – the size to extract
dest ( [arraylength=dest_size][element-typeguint8][out]) – A pointer where the destination array will be written. Might be NULL if the size is 0.
dest_size ( [out]) – A location where the size of dest can be written
Since : 1.0.10
gst_buffer_fill
gsize
gst_buffer_fill (GstBuffer * buffer,
gsize offset,
gconstpointer src,
gsize size)
Copies size bytes from src to buffer at offset.
Parameters:
buffer – a GstBuffer.
offset – the offset to fill
src ( [arraylength=size][element-typeguint8]) – the source address
size – the size to fill
Returns – The amount of bytes copied. This value can be lower than size when buffer did not contain enough data.
gst_buffer_find_memory
gboolean
gst_buffer_find_memory (GstBuffer * buffer,
gsize offset,
gsize size,
guint * idx,
guint * length,
gsize * skip)
Finds the memory blocks that span size bytes starting from offset in buffer.
When this function returns TRUE, idx will contain the index of the first memory block where the byte for offset can be found and length contains the number of memory blocks containing the size remaining bytes. skip contains the number of bytes to skip in the memory block at idx to get to the byte for offset.
size can be -1 to get all the memory blocks after idx.
Parameters:
buffer – a GstBuffer.
offset – an offset
size – a size
idx ( [out]) – pointer to index
length ( [out]) – pointer to length
skip ( [out]) – pointer to skip
Returns – TRUE when size bytes starting from offset could be found in buffer and idx, length and skip will be filled.
gst_buffer_foreach_meta
gboolean
gst_buffer_foreach_meta (GstBuffer * buffer,
GstBufferForeachMetaFunc func,
gpointer user_data)
Calls func with user_data for each meta in buffer.
func can modify the passed meta pointer or its contents. The return value of func defines if this function returns or if the remaining metadata items in the buffer should be skipped.
Parameters:
buffer – a GstBuffer
func ( [scope call]) – a GstBufferForeachMetaFunc to call
user_data ( [closure]) – user data passed to func
Returns – FALSE when func returned FALSE for one of the metadata.
gst_buffer_get_all_memory
GstMemory *
gst_buffer_get_all_memory (GstBuffer * buffer)
Gets all the memory blocks in buffer. The memory blocks will be merged into one large GstMemory.
Parameters:
buffer – a GstBuffer.
Returns ( [transfer: full][nullable]) – a GstMemory that contains the merged memory.
gst_buffer_get_custom_meta
GstCustomMeta *
gst_buffer_get_custom_meta (GstBuffer * buffer,
const gchar * name)
Finds the first GstCustomMeta on buffer for the desired name.
Parameters:
buffer – a GstBuffer
name – the registered name of the custom meta to retrieve.
Returns ( [transfer: none][nullable]) – the GstCustomMeta
Since : 1.20
gst_buffer_get_flags
GstBufferFlags
gst_buffer_get_flags (GstBuffer * buffer)
Gets the GstBufferFlags flags set on this buffer.
Parameters:
buffer – a GstBuffer
Returns – the flags set on this buffer.
Since : 1.10
gst_buffer_get_memory
GstMemory *
gst_buffer_get_memory (GstBuffer * buffer,
guint idx)
Gets the memory block at index idx in buffer.
Parameters:
buffer – a GstBuffer.
idx – an index
Returns ( [transfer: full][nullable]) – a GstMemory that contains the data of the memory block at idx.
gst_buffer_get_memory_range
GstMemory *
gst_buffer_get_memory_range (GstBuffer * buffer,
guint idx,
gint length)
Gets length memory blocks in buffer starting at idx. The memory blocks will be merged into one large GstMemory.
If length is -1, all memory starting from idx is merged.
Parameters:
buffer – a GstBuffer.
idx – an index
length – a length
Returns ( [transfer: full][nullable]) – a GstMemory that contains the merged data of length blocks starting at idx.
gst_buffer_get_meta
GstMeta *
gst_buffer_get_meta (GstBuffer * buffer,
GType api)
Gets the metadata for api on buffer. When there is no such metadata, NULL is returned. If multiple metadata with the given api are attached to this buffer only the first one is returned. To handle multiple metadata with a given API use gst_buffer_iterate_meta or gst_buffer_foreach_meta instead and check the meta->info.api member for the API type.
Parameters:
buffer – a GstBuffer
api – the GType of an API
Returns ( [transfer: none][nullable]) – the metadata for api on buffer.
gst_buffer_get_n_meta
guint
gst_buffer_get_n_meta (GstBuffer * buffer,
GType api_type)
Parameters:
buffer – a GstBuffer
api_type – the GType of an API
Returns – number of metas of type api_type on buffer.
Since : 1.14
gst_buffer_get_reference_timestamp_meta
GstReferenceTimestampMeta *
gst_buffer_get_reference_timestamp_meta (GstBuffer * buffer,
GstCaps * reference)
Finds the first GstReferenceTimestampMeta on buffer that conforms to reference. Conformance is tested by checking if the meta’s reference is a subset of reference.
Buffers can contain multiple GstReferenceTimestampMeta metadata items.
Parameters:
buffer – a GstBuffer
reference ( [allow-none]) – a reference GstCaps
Returns ( [transfer: none][nullable]) – the GstReferenceTimestampMeta or NULL when there is no such metadata on buffer.
Since : 1.14
gst_buffer_get_size
gsize
gst_buffer_get_size (GstBuffer * buffer)
Gets the total size of the memory blocks in buffer.
Parameters:
buffer – a GstBuffer.
Returns – total size of the memory blocks in buffer.
gst_buffer_get_sizes
gsize
gst_buffer_get_sizes (GstBuffer * buffer,
gsize * offset,
gsize * maxsize)
Gets the total size of the memory blocks in buffer.
When not NULL, offset will contain the offset of the data in the first memory block in buffer and maxsize will contain the sum of the size and offset and the amount of extra padding on the last memory block. offset and maxsize can be used to resize the buffer memory blocks with gst_buffer_resize.
Parameters:
buffer – a GstBuffer.
offset ( [out][allow-none]) – a pointer to the offset
maxsize ( [out][allow-none]) – a pointer to the maxsize
Returns – total size of the memory blocks in buffer.
gst_buffer_get_sizes_range
gsize
gst_buffer_get_sizes_range (GstBuffer * buffer,
guint idx,
gint length,
gsize * offset,
gsize * maxsize)
Gets the total size of length memory blocks stating from idx in buffer.
When not NULL, offset will contain the offset of the data in the memory block in buffer at idx and maxsize will contain the sum of the size and offset and the amount of extra padding on the memory block at idx + length -1. offset and maxsize can be used to resize the buffer memory blocks with gst_buffer_resize_range.
Parameters:
buffer – a GstBuffer.
idx – an index
length – a length
offset ( [out][allow-none]) – a pointer to the offset
maxsize ( [out][allow-none]) – a pointer to the maxsize
Returns – total size of length memory blocks starting at idx in buffer.
gst_buffer_has_flags
gboolean
gst_buffer_has_flags (GstBuffer * buffer,
GstBufferFlags flags)
Gives the status of a specific flag on a buffer.
Parameters:
buffer – a GstBuffer
flags – the GstBufferFlags flag to check.
Returns – TRUE if all flags in flags are found on buffer.
Since : 1.10
gst_buffer_insert_memory
gst_buffer_insert_memory (GstBuffer * buffer,
gint idx,
GstMemory * mem)
Inserts the memory block mem into buffer at idx. This function takes ownership of mem and thus doesn’t increase its refcount.
Only gst_buffer_get_max_memory can be added to a buffer. If more memory is added, existing memory blocks will automatically be merged to make room for the new memory.
Parameters:
buffer – a GstBuffer.
idx – the index to add the memory at, or -1 to append it to the end
mem ( [transfer: full]) – a GstMemory.
gst_buffer_is_all_memory_writable
gboolean
gst_buffer_is_all_memory_writable (GstBuffer * buffer)
Checks if all memory blocks in buffer are writable.
Note that this function does not check if buffer is writable, use gst_buffer_is_writable to check that if needed.
Parameters:
buffer – a GstBuffer.
Returns – TRUE if all memory blocks in buffer are writable
Since : 1.4
gst_buffer_is_memory_range_writable
gboolean
gst_buffer_is_memory_range_writable (GstBuffer * buffer,
guint idx,
gint length)
Checks if length memory blocks in buffer starting from idx are writable.
length can be -1 to check all the memory blocks after idx.
Note that this function does not check if buffer is writable, use gst_buffer_is_writable to check that if needed.
Parameters:
buffer – a GstBuffer.
idx – an index
length – a length, should not be 0
Returns – TRUE if the memory range is writable
Since : 1.4
gst_buffer_iterate_meta
GstMeta *
gst_buffer_iterate_meta (GstBuffer * buffer,
gpointer * state)
Retrieves the next GstMeta after current. If state points to NULL, the first metadata is returned.
state will be updated with an opaque state pointer
Parameters:
buffer – a GstBuffer
state ( [out]) – an opaque state pointer
Returns ( [transfer: none][nullable]) – The next GstMeta or NULL when there are no more items.
gst_buffer_iterate_meta_filtered
GstMeta *
gst_buffer_iterate_meta_filtered (GstBuffer * buffer,
gpointer * state,
GType meta_api_type)
Retrieves the next GstMeta of type meta_api_type after the current one according to state. If state points to NULL, the first metadata of type meta_api_type is returned.
state will be updated with an opaque state pointer
Parameters:
buffer – a GstBuffer
state ( [out]) – an opaque state pointer
meta_api_type – only return GstMeta of this type
Returns ( [transfer: none][nullable]) – The next GstMeta of type meta_api_type or NULL when there are no more items.
Since : 1.12
gst_buffer_map
gboolean
gst_buffer_map (GstBuffer * buffer,
GstMapInfo * info,
GstMapFlags flags)
Fills info with the GstMapInfo of all merged memory blocks in buffer.
flags describe the desired access of the memory. When flags is GST_MAP_WRITE, buffer should be writable (as returned from gst_buffer_is_writable).
When buffer is writable but the memory isn’t, a writable copy will automatically be created and returned. The readonly copy of the buffer memory will then also be replaced with this writable copy.
The memory in info should be unmapped with gst_buffer_unmap after usage.
Parameters:
buffer – a GstBuffer.
info ( [out]) – info about the mapping
flags – flags for the mapping
Returns – TRUE if the map succeeded and info contains valid data.
gst_buffer_map_range
gboolean
gst_buffer_map_range (GstBuffer * buffer,
guint idx,
gint length,
GstMapInfo * info,
GstMapFlags flags)
Fills info with the GstMapInfo of length merged memory blocks starting at idx in buffer. When length is -1, all memory blocks starting from idx are merged and mapped.
flags describe the desired access of the memory. When flags is GST_MAP_WRITE, buffer should be writable (as returned from gst_buffer_is_writable).
When buffer is writable but the memory isn’t, a writable copy will automatically be created and returned. The readonly copy of the buffer memory will then also be replaced with this writable copy.
The memory in info should be unmapped with gst_buffer_unmap after usage.
Parameters:
buffer – a GstBuffer.
idx – an index
length – a length
info ( [out]) – info about the mapping
flags – flags for the mapping
Returns – TRUE if the map succeeded and info contains valid data.
gst_buffer_memcmp
gint
gst_buffer_memcmp (GstBuffer * buffer,
gsize offset,
gconstpointer mem,
gsize size)
Compares size bytes starting from offset in buffer with the memory in mem.
Parameters:
buffer – a GstBuffer.
offset – the offset in buffer
mem ( [arraylength=size][element-typeguint8]) – the memory to compare
size – the size to compare
Returns – 0 if the memory is equal.
gst_buffer_memset
gsize
gst_buffer_memset (GstBuffer * buffer,
gsize offset,
guint8 val,
gsize size)
Fills buf with size bytes with val starting from offset.
Parameters:
buffer – a GstBuffer.
offset – the offset in buffer
val – the value to set
size – the size to set
Returns – The amount of bytes filled. This value can be lower than size when buffer did not contain enough data.
gst_buffer_n_memory
guint
gst_buffer_n_memory (GstBuffer * buffer)
Gets the amount of memory blocks that this buffer has. This amount is never larger than what gst_buffer_get_max_memory returns.
Parameters:
buffer – a GstBuffer.
Returns – the number of memory blocks this buffer is made of.
gst_buffer_peek_memory
GstMemory *
gst_buffer_peek_memory (GstBuffer * buffer,
guint idx)
Gets the memory block at idx in buffer. The memory block stays valid until the memory block in buffer is removed, replaced or merged, typically with any call that modifies the memory in buffer.
Parameters:
buffer – a GstBuffer.
idx – an index
Returns ( [transfer: none][nullable]) – the GstMemory at idx.
gst_buffer_prepend_memory
gst_buffer_prepend_memory (GstBuffer * buffer,
GstMemory * mem)
Prepends the memory block mem to buffer. This function takes ownership of mem and thus doesn’t increase its refcount.
This function is identical to gst_buffer_insert_memory with an index of 0. See gst_buffer_insert_memory for more details.
Parameters:
buffer – a GstBuffer.
mem ( [transfer: full]) – a GstMemory.
gst_buffer_ref
GstBuffer *
gst_buffer_ref (GstBuffer * buf)
Increases the refcount of the given buffer by one.
Note that the refcount affects the writability of buf and its metadata, see gst_buffer_is_writable. It is important to note that keeping additional references to GstBuffer instances can potentially increase the number of memcpy operations in a pipeline.
Parameters:
buf – a GstBuffer.
Returns ( [transfer: full]) – buf
gst_buffer_remove_all_memory
gst_buffer_remove_all_memory (GstBuffer * buffer)
Removes all the memory blocks in buffer.
Parameters:
buffer – a GstBuffer.
gst_buffer_remove_memory
gst_buffer_remove_memory (GstBuffer * buffer,
guint idx)
Removes the memory block in b at index i.
Parameters:
buffer – a GstBuffer.
idx – an index
gst_buffer_remove_memory_range
gst_buffer_remove_memory_range (GstBuffer * buffer,
guint idx,
gint length)
Removes length memory blocks in buffer starting from idx.
length can be -1, in which case all memory starting from idx is removed.
Parameters:
buffer – a GstBuffer.
idx – an index
length – a length
gst_buffer_remove_meta
gboolean
gst_buffer_remove_meta (GstBuffer * buffer,
GstMeta * meta)
Removes the metadata for meta on buffer.
Parameters:
buffer – a GstBuffer
meta – a GstMeta
Returns – TRUE if the metadata existed and was removed, FALSE if no such metadata was on buffer.
gst_buffer_replace_all_memory
gst_buffer_replace_all_memory (GstBuffer * buffer,
GstMemory * mem)
Replaces all memory in buffer with mem.
Parameters:
buffer – a GstBuffer.
mem ( [transfer: full]) – a GstMemory
gst_buffer_replace_memory
gst_buffer_replace_memory (GstBuffer * buffer,
guint idx,
GstMemory * mem)
Replaces the memory block at index idx in buffer with mem.
Parameters:
buffer – a GstBuffer.
idx – an index
mem ( [transfer: full]) – a GstMemory
gst_buffer_replace_memory_range
gst_buffer_replace_memory_range (GstBuffer * buffer,
guint idx,
gint length,
GstMemory * mem)
Replaces length memory blocks in buffer starting at idx with mem.
If length is -1, all memory starting from idx will be removed and replaced with mem.
buffer should be writable.
Parameters:
buffer – a GstBuffer.
idx – an index
length – a length, should not be 0
mem ( [transfer: full]) – a GstMemory
gst_buffer_resize
gst_buffer_resize (GstBuffer * buffer,
gssize offset,
gssize size)
Sets the offset and total size of the memory blocks in buffer.
Parameters:
buffer – a GstBuffer.
offset – the offset adjustment
size – the new size or -1 to just adjust the offset
gst_buffer_resize_range
gboolean
gst_buffer_resize_range (GstBuffer * buffer,
guint idx,
gint length,
gssize offset,
gssize size)
Sets the total size of the length memory blocks starting at idx in buffer
Parameters:
buffer – a GstBuffer.
idx – an index
length – a length
offset – the offset adjustment
size – the new size or -1 to just adjust the offset
Returns – TRUE if resizing succeeded, FALSE otherwise.
gst_buffer_set_flags
gboolean
gst_buffer_set_flags (GstBuffer * buffer,
GstBufferFlags flags)
Sets one or more buffer flags on a buffer.
Parameters:
buffer – a GstBuffer
flags – the GstBufferFlags to set.
Returns – TRUE if flags were successfully set on buffer.
Since : 1.10
gst_buffer_set_size
gst_buffer_set_size (GstBuffer * buffer,
gssize size)
Sets the total size of the memory blocks in buffer.
Parameters:
buffer – a GstBuffer.
size – the new size
gst_buffer_unmap
gst_buffer_unmap (GstBuffer * buffer,
GstMapInfo * info)
Releases the memory previously mapped with gst_buffer_map.
Parameters:
buffer – a GstBuffer.
info – a GstMapInfo
gst_buffer_unref
gst_buffer_unref (GstBuffer * buf)
Decreases the refcount of the buffer. If the refcount reaches 0, the buffer with the associated metadata and memory will be freed.
Parameters:
buf ( [transfer: full]) – a GstBuffer.
gst_buffer_unset_flags
gboolean
gst_buffer_unset_flags (GstBuffer * buffer,
GstBufferFlags flags)
Clears one or more buffer flags.
Parameters:
buffer – a GstBuffer
flags – the GstBufferFlags to clear
Returns – true if flags is successfully cleared from buffer.
Since : 1.10
1.4 函数
gst_buffer_get_max_memory
guint
gst_buffer_get_max_memory ()
Gets the maximum amount of memory blocks that a buffer can hold. This is a compile time constant that can be queried with the function.
When more memory blocks are added, existing memory blocks will be merged together to make room for the new block.
Returns – the maximum amount of memory blocks that a buffer can hold.
Since : 1.2
gst_buffer_replace
gboolean
gst_buffer_replace (GstBuffer ** obuf,
GstBuffer * nbuf)
Modifies a pointer to a GstBuffer to point to a different GstBuffer. The modification is done atomically (so this is useful for ensuring thread safety in some cases), and the reference counts are updated appropriately (the old buffer is unreffed, the new is reffed).
Either nbuf or the GstBuffer pointed to by obuf may be NULL.
Parameters:
obuf ( [inout][transfer: full][nullable]) – pointer to a pointer to a GstBuffer to be replaced.
nbuf ( [transfer: none][allow-none]) – pointer to a GstBuffer that will replace the buffer pointed to by obuf.
Returns – TRUE when obuf was different from nbuf.
参考资料