GstMetaItem *next;
GstMeta meta;
};
-#define ITEM_SIZE(info) ((info)->size + sizeof (GstMetaItem))
+
+/* info->size will be sizeof(FooMeta) which contains a GstMeta at the beginning
+ * too, and then there is again a GstMeta in GstMetaItem, so subtract one. */
+#define ITEM_SIZE(info) ((info)->size + sizeof (GstMetaItem) - sizeof (GstMeta))
#define GST_BUFFER_MEM_MAX 16
GstMemory *old = GST_BUFFER_MEM_PTR (buffer, i);
gst_memory_unlock (old, GST_LOCK_FLAG_EXCLUSIVE);
+ gst_mini_object_remove_parent (GST_MINI_OBJECT_CAST (old),
+ GST_MINI_OBJECT_CAST (buffer));
gst_memory_unref (old);
}
if (mem != NULL) {
/* replace with single memory */
+ gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (mem),
+ GST_MINI_OBJECT_CAST (buffer));
gst_memory_lock (mem, GST_LOCK_FLAG_EXCLUSIVE);
GST_BUFFER_MEM_PTR (buffer, idx) = mem;
idx++;
/* and insert the new buffer */
GST_BUFFER_MEM_PTR (buffer, idx) = mem;
GST_BUFFER_MEM_LEN (buffer) = len + 1;
+ gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (mem),
+ GST_MINI_OBJECT_CAST (buffer));
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
}
len = GST_BUFFER_MEM_LEN (buffer);
for (i = 0; i < len; i++) {
gst_memory_unlock (GST_BUFFER_MEM_PTR (buffer, i), GST_LOCK_FLAG_EXCLUSIVE);
+ gst_mini_object_remove_parent (GST_MINI_OBJECT_CAST (GST_BUFFER_MEM_PTR
+ (buffer, i)), GST_MINI_OBJECT_CAST (buffer));
gst_memory_unref (GST_BUFFER_MEM_PTR (buffer, i));
}
if (mapped != mem) {
/* memory changed, lock new memory */
+ gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (mapped),
+ GST_MINI_OBJECT_CAST (buffer));
gst_memory_lock (mapped, GST_LOCK_FLAG_EXCLUSIVE);
GST_BUFFER_MEM_PTR (buffer, idx) = mapped;
/* unlock old memory */
gst_memory_unlock (mem, GST_LOCK_FLAG_EXCLUSIVE);
+ gst_mini_object_remove_parent (GST_MINI_OBJECT_CAST (mem),
+ GST_MINI_OBJECT_CAST (buffer));
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
}
gst_memory_unref (mem);
* the memory block in @buffer is removed, replaced or merged, typically with
* any call that modifies the memory in @buffer.
*
- * Returns: (transfer none): the #GstMemory at @idx.
+ * Returns: (transfer none) (nullable): the #GstMemory at @idx.
*/
GstMemory *
gst_buffer_peek_memory (GstBuffer * buffer, guint idx)
*
* Get the memory block at index @idx in @buffer.
*
- * Returns: (transfer full): a #GstMemory that contains the data of the
+ * Returns: (transfer full) (nullable): a #GstMemory that contains the data of the
* memory block at @idx. Use gst_memory_unref () after usage.
*/
GstMemory *
* Get all the memory block in @buffer. The memory blocks will be merged
* into one large #GstMemory.
*
- * Returns: (transfer full): a #GstMemory that contains the merged memory.
+ * Returns: (transfer full) (nullable): a #GstMemory that contains the merged memory.
* Use gst_memory_unref () after usage.
*/
GstMemory *
*
* If @length is -1, all memory starting from @idx is merged.
*
- * Returns: (transfer full): a #GstMemory that contains the merged data of @length
+ * Returns: (transfer full) (nullable): a #GstMemory that contains the merged data of @length
* blocks starting at @idx. Use gst_memory_unref () after usage.
*/
GstMemory *
if (newmem == NULL)
return FALSE;
+ gst_mini_object_add_parent (GST_MINI_OBJECT_CAST (newmem),
+ GST_MINI_OBJECT_CAST (buffer));
gst_memory_lock (newmem, GST_LOCK_FLAG_EXCLUSIVE);
GST_BUFFER_MEM_PTR (buffer, i) = newmem;
gst_memory_unlock (mem, GST_LOCK_FLAG_EXCLUSIVE);
+ gst_mini_object_remove_parent (GST_MINI_OBJECT_CAST (mem),
+ GST_MINI_OBJECT_CAST (buffer));
gst_memory_unref (mem);
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
* gst_buffer_extract:
* @buffer: a #GstBuffer.
* @offset: the offset to extract
- * @dest: the destination address
+ * @dest: (out caller-allocates) (array length=size) (element-type guint8):
+ * the destination address
* @size: the size to extract
*
* Copy @size bytes starting from @offset in @buffer to @dest.
GstMemory *mem;
mem = GST_BUFFER_MEM_PTR (buf2, i);
+ gst_mini_object_remove_parent (GST_MINI_OBJECT_CAST (mem),
+ GST_MINI_OBJECT_CAST (buf2));
GST_BUFFER_MEM_PTR (buf2, i) = NULL;
_memory_add (buf1, -1, mem);
}
}
/**
+ * gst_buffer_get_n_meta:
+ * @buffer: a #GstBuffer
+ * @api_type: the #GType of an API
+ *
+ * Returns: number of metas of type @api_type on @buffer.
+ *
+ * Since: 1.14
+ */
+guint
+gst_buffer_get_n_meta (GstBuffer * buffer, GType api_type)
+{
+ gpointer state = NULL;
+ GstMeta *meta;
+ guint n = 0;
+
+ while ((meta = gst_buffer_iterate_meta_filtered (buffer, &state, api_type)))
+ ++n;
+
+ return n;
+}
+
+/**
* gst_buffer_add_meta:
* @buffer: a #GstBuffer
* @info: a #GstMetaInfo
*
* Add metadata for @info to @buffer using the parameters in @params.
*
- * Returns: (transfer none): the metadata for the api in @info on @buffer.
+ * Returns: (transfer none) (nullable): the metadata for the api in @info on @buffer.
*/
GstMeta *
gst_buffer_add_meta (GstBuffer * buffer, const GstMetaInfo * info,
/**
* gst_buffer_iterate_meta: (skip)
* @buffer: a #GstBuffer
- * @state: an opaque state pointer
+ * @state: (out caller-allocates): an opaque state pointer
*
* Retrieve the next #GstMeta after @current. If @state points
* to %NULL, the first metadata is returned.
/**
* gst_buffer_iterate_meta_filtered: (skip)
* @buffer: a #GstBuffer
- * @state: an opaque state pointer
+ * @state: (out caller-allocates): an opaque state pointer
* @meta_api_type: only return #GstMeta of this type
*
* Retrieve the next #GstMeta of type @meta_api_type after the current one
* Add a #GstParentBufferMeta to @buffer that holds a reference on
* @ref until the buffer is freed.
*
- * Returns: (transfer none): The #GstParentBufferMeta that was added to the buffer
+ * Returns: (transfer none) (nullable): The #GstParentBufferMeta that was added to the buffer
*
* Since: 1.6
*/
* optionally @duration based on a specific timestamp @reference. See the
* documentation of #GstReferenceTimestampMeta for details.
*
- * Returns: (transfer none): The #GstReferenceTimestampMeta that was added to the buffer
+ * Returns: (transfer none) (nullable): The #GstReferenceTimestampMeta that was added to the buffer
*
* Since: 1.14
*/
*
* Buffers can contain multiple #GstReferenceTimestampMeta metadata items.
*
- * Returns: (transfer none): the #GstReferenceTimestampMeta or %NULL when there
+ * Returns: (transfer none) (nullable): the #GstReferenceTimestampMeta or %NULL when there
* is no such metadata on @buffer.
*
* Since: 1.14