/**
* SECTION:gstbuffer
+ * @title: GstBuffer
* @short_description: Data-passing buffer type
* @see_also: #GstPad, #GstMiniObject, #GstMemory, #GstMeta, #GstBufferPool
*
* created one will typically allocate memory for it and add it to the buffer.
* The following example creates a buffer that can hold a given video frame
* with a given width, height and bits per plane.
- * |[
+ * |[<!-- language="C" -->
* GstBuffer *buffer;
* GstMemory *memory;
* gint size, width, height, bpp;
guint8 *ptr;
result = gst_allocator_alloc (NULL, size, NULL);
- gst_memory_map (result, &dinfo, GST_MAP_WRITE);
+ if (result == NULL || !gst_memory_map (result, &dinfo, GST_MAP_WRITE)) {
+ GST_CAT_ERROR (GST_CAT_BUFFER, "Failed to map memory writable");
+ if (result)
+ gst_memory_unref (result);
+ return NULL;
+ }
ptr = dinfo.data;
left = size;
for (i = idx; i < (idx + length) && left > 0; i++) {
- gst_memory_map (mem[i], &sinfo, GST_MAP_READ);
+ if (!gst_memory_map (mem[i], &sinfo, GST_MAP_READ)) {
+ GST_CAT_ERROR (GST_CAT_BUFFER,
+ "buffer %p, idx %u, length %u failed to map readable", buffer,
+ idx, length);
+ gst_memory_unmap (result, &dinfo);
+ gst_memory_unref (result);
+ return NULL;
+ }
tocopy = MIN (sinfo.size, left);
GST_CAT_DEBUG (GST_CAT_PERFORMANCE,
"memcpy %" G_GSIZE_FORMAT " bytes for merge %p from memory %p",
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
}
+/**
+ * gst_buffer_get_flags:
+ * @buffer: a #GstBuffer
+ *
+ * Get the #GstBufferFlags flags set on this buffer.
+ *
+ * Returns: the flags set on this buffer.
+ *
+ * Since: 1.10
+ */
+GstBufferFlags
+gst_buffer_get_flags (GstBuffer * buffer)
+{
+ return (GstBufferFlags) GST_BUFFER_FLAGS (buffer);
+}
+
+/**
+ * gst_buffer_flag_is_set:
+ * @buffer: a #GstBuffer
+ * @flags: the #GstBufferFlags flag to check.
+ *
+ * Gives the status of a specific flag on a buffer.
+ *
+ * Returns: %TRUE if all flags in @flags are found on @buffer.
+ *
+ * Since: 1.10
+ */
+gboolean
+gst_buffer_has_flags (GstBuffer * buffer, GstBufferFlags flags)
+{
+ return GST_BUFFER_FLAG_IS_SET (buffer, flags);
+}
+
+/**
+ * gst_buffer_set_flags:
+ * @buffer: a #GstBuffer
+ * @flags: the #GstBufferFlags to set.
+ *
+ * Sets one or more buffer flags on a buffer.
+ *
+ * Returns: %TRUE if @flags were successfully set on buffer.
+ *
+ * Since: 1.10
+ */
+gboolean
+gst_buffer_set_flags (GstBuffer * buffer, GstBufferFlags flags)
+{
+ GST_BUFFER_FLAG_SET (buffer, flags);
+ return TRUE;
+}
+
+/**
+ * gst_buffer_unset_flags:
+ * @buffer: a #GstBuffer
+ * @flags: the #GstBufferFlags to clear
+ *
+ * Clears one or more buffer flags.
+ *
+ * Returns: true if @flags is successfully cleared from buffer.
+ *
+ * Since: 1.10
+ */
+gboolean
+gst_buffer_unset_flags (GstBuffer * buffer, GstBufferFlags flags)
+{
+ GST_BUFFER_FLAG_UNSET (buffer, flags);
+ return TRUE;
+}
+
+
+
/* transfer full for return and transfer none for @mem */
static inline GstMemory *
_memory_get_exclusive_reference (GstMemory * mem)
* Get the amount of memory blocks that this buffer has. This amount is never
* larger than what gst_buffer_get_max_memory() returns.
*
- * Returns: (transfer full): the amount of memory block in this buffer.
+ * Returns: the number of memory blocks this buffer is made of.
*/
guint
gst_buffer_n_memory (GstBuffer * buffer)
/* create a new slice */
size = ITEM_SIZE (info);
- item = g_slice_alloc (size);
+ /* We warn in gst_meta_register() about metas without
+ * init function but let's play safe here and prevent
+ * uninitialized memory
+ */
+ if (!info->init_func)
+ item = g_slice_alloc0 (size);
+ else
+ item = g_slice_alloc (size);
result = &item->meta;
result->info = info;
result->flags = GST_META_FLAG_NONE;
-
GST_CAT_DEBUG (GST_CAT_BUFFER,
"alloc metadata %p (%s) of size %" G_GSIZE_FORMAT, result,
g_type_name (info->type), info->size);
}
/**
- * gst_buffer_iterate_meta:
+ * gst_buffer_iterate_meta: (skip)
* @buffer: a #GstBuffer
* @state: an opaque state pointer
*
}
/**
+ * gst_buffer_iterate_meta_filtered: (skip)
+ * @buffer: a #GstBuffer
+ * @state: 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
+ * 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
+ *
+ * Returns: (transfer none) (nullable): The next #GstMeta of type
+ * @meta_api_type or %NULL when there are no more items.
+ *
+ * Since: 1.12
+ */
+GstMeta *
+gst_buffer_iterate_meta_filtered (GstBuffer * buffer, gpointer * state,
+ GType meta_api_type)
+{
+ GstMetaItem **meta;
+
+ g_return_val_if_fail (buffer != NULL, NULL);
+ g_return_val_if_fail (state != NULL, NULL);
+
+ meta = (GstMetaItem **) state;
+ if (*meta == NULL)
+ /* state NULL, move to first item */
+ *meta = GST_BUFFER_META (buffer);
+ else
+ /* state !NULL, move to next item in list */
+ *meta = (*meta)->next;
+
+ while (*meta != NULL && (*meta)->meta.info->api != meta_api_type)
+ *meta = (*meta)->next;
+
+ if (*meta)
+ return &(*meta)->meta;
+ else
+ return NULL;
+}
+
+/**
* gst_buffer_foreach_meta:
* @buffer: a #GstBuffer
* @func: (scope call): a #GstBufferForeachMetaFunc to call
static volatile gsize _init;
if (g_once_init_enter (&_init)) {
- GST_DEBUG_CATEGORY_INIT (gst_parent_buffer_meta_debug, "glbufferrefmeta", 0,
- "glbufferrefmeta");
+ GST_DEBUG_CATEGORY_INIT (gst_parent_buffer_meta_debug, "parentbuffermeta",
+ 0, "parentbuffermeta");
g_once_init_leave (&_init, 1);
}
{
static const GstMetaInfo *meta_info = NULL;
- if (g_once_init_enter (&meta_info)) {
+ if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
const GstMetaInfo *meta =
gst_meta_register (gst_parent_buffer_meta_api_get_type (),
"GstParentBufferMeta",
(GstMetaInitFunction) _gst_parent_buffer_meta_init,
(GstMetaFreeFunction) _gst_parent_buffer_meta_free,
_gst_parent_buffer_meta_transform);
- g_once_init_leave (&meta_info, meta);
+ g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) meta);
}
return meta_info;