/**
* SECTION:gstbufferlist
+ * @title: GstBufferList
* @short_description: Lists of buffers for data-passing
* @see_also: #GstPad, #GstMiniObject
*
*
* Get the buffer at @idx.
*
+ * You must make sure that @idx does not exceed the number of
+ * buffers available.
+ *
* Returns: (transfer none) (nullable): the buffer at @idx in @group
* or %NULL when there is no buffer. The buffer remains valid as
- * long as @list is valid.
+ * long as @list is valid and buffer is not removed from the list.
*/
GstBuffer *
gst_buffer_list_get (GstBufferList * list, guint idx)
}
/**
+ * gst_buffer_list_get_writable:
+ * @list: a (writable) #GstBufferList
+ * @idx: the index
+ *
+ * Gets the buffer at @idx, ensuring it is a writable buffer.
+ *
+ * You must make sure that @idx does not exceed the number of
+ * buffers available.
+ *
+ * Returns: (transfer none) (nullable): the buffer at @idx in @group.
+ * The returned buffer remains valid as long as @list is valid and
+ * the buffer is not removed from the list.
+ *
+ * Since: 1.14
+ */
+GstBuffer *
+gst_buffer_list_get_writable (GstBufferList * list, guint idx)
+{
+ GstBuffer **p_buf;
+
+ g_return_val_if_fail (GST_IS_BUFFER_LIST (list), NULL);
+ g_return_val_if_fail (gst_buffer_list_is_writable (list), NULL);
+ g_return_val_if_fail (idx < list->n_buffers, NULL);
+
+ p_buf = &list->buffers[idx];
+ return (*p_buf = gst_buffer_make_writable (*p_buf));
+}
+
+/**
* gst_buffer_list_add:
* @l: a #GstBufferList
* @b: a #GstBuffer
g_return_if_fail (GST_IS_BUFFER_LIST (list));
g_return_if_fail (buffer != NULL);
+ g_return_if_fail (gst_buffer_list_is_writable (list));
if (idx == -1 && list->n_buffers < list->n_allocated) {
list->buffers[list->n_buffers++] = buffer;
g_return_if_fail (GST_IS_BUFFER_LIST (list));
g_return_if_fail (idx < list->n_buffers);
g_return_if_fail (idx + length <= list->n_buffers);
+ g_return_if_fail (gst_buffer_list_is_writable (list));
gst_buffer_list_remove_range_internal (list, idx, length, TRUE);
}
+
+/**
+ * gst_buffer_list_copy_deep:
+ * @list: a #GstBufferList
+ *
+ * Create a copy of the given buffer list. This will make a newly allocated
+ * copy of the buffer that the source buffer list contains.
+ *
+ * Returns: (transfer full): a new copy of @list.
+ *
+ * Since: 1.6
+ */
+GstBufferList *
+gst_buffer_list_copy_deep (const GstBufferList * list)
+{
+ guint i, len;
+ GstBufferList *result = NULL;
+
+ g_return_val_if_fail (GST_IS_BUFFER_LIST (list), NULL);
+
+ result = gst_buffer_list_new ();
+
+ len = list->n_buffers;
+ for (i = 0; i < len; i++) {
+ GstBuffer *old = list->buffers[i];
+ GstBuffer *new = gst_buffer_copy_deep (old);
+
+ if (G_LIKELY (new)) {
+ gst_buffer_list_insert (result, i, new);
+ } else {
+ g_warning
+ ("Failed to deep copy buffer %p while deep "
+ "copying buffer list %p. Buffer list copy "
+ "will be incomplete", old, list);
+ }
+ }
+
+ return result;
+}
+
+/**
+ * gst_buffer_list_calculate_size:
+ * @list: a #GstBufferList
+ *
+ * Calculates the size of the data contained in buffer list by adding the
+ * size of all buffers.
+ *
+ * Returns: the size of the data contained in buffer list in bytes.
+ *
+ * Since: 1.14
+ */
+gsize
+gst_buffer_list_calculate_size (GstBufferList * list)
+{
+ GstBuffer **buffers;
+ gsize size = 0;
+ guint i, n;
+
+ g_return_val_if_fail (GST_IS_BUFFER_LIST (list), 0);
+
+ n = list->n_buffers;
+ buffers = list->buffers;
+
+ for (i = 0; i < n; ++i)
+ size += gst_buffer_get_size (buffers[i]);
+
+ return size;
+}