- if (it->last_returned->data != STOLEN) {
- gst_buffer_unref (it->last_returned->data);
- }
- g_queue_delete_link (it->list->buffers, it->last_returned);
- it->last_returned = NULL;
-}
-
-/**
- * gst_buffer_list_iterator_take:
- * @it: a #GstBufferListIterator
- * @buffer: (transfer full): a #GstBuffer
- *
- * Replaces the last buffer returned by gst_buffer_list_iterator_next() with
- * @buffer in the #GstBufferList iterated with @it and takes ownership of
- * @buffer. gst_buffer_list_iterator_next() must have been called on @it before
- * this function is called. gst_buffer_list_iterator_remove() must not have been
- * called since the last call to gst_buffer_list_iterator_next().
- *
- * This function unrefs the replaced buffer if it has not been stolen with
- * gst_buffer_list_iterator_steal() and takes ownership of @buffer (i.e. the
- * refcount of @buffer is not increased).
- *
- * FIXME 0.11: this conditional taking-ownership is not good for bindings
- *
- * Since: 0.10.24
- */
-void
-gst_buffer_list_iterator_take (GstBufferListIterator * it, GstBuffer * buffer)
-{
- g_return_if_fail (it != NULL);
- g_return_if_fail (it->last_returned != NULL);
- g_return_if_fail (buffer != NULL);
- g_assert (it->last_returned->data != GROUP_START);
-
- if (it->last_returned->data != STOLEN) {
- gst_buffer_unref (it->last_returned->data);
- }
- it->last_returned->data = buffer;
-}
-
-/**
- * gst_buffer_list_iterator_steal:
- * @it: a #GstBufferListIterator
- *
- * Returns the last buffer returned by gst_buffer_list_iterator_next() without
- * modifying the refcount of the buffer.
- *
- * Returns: (transfer none): the last buffer returned by
- * gst_buffer_list_iterator_next()
- *
- * Since: 0.10.24
- */
-GstBuffer *
-gst_buffer_list_iterator_steal (GstBufferListIterator * it)
-{
- GstBuffer *buffer;
-
- g_return_val_if_fail (it != NULL, NULL);
- g_return_val_if_fail (it->last_returned != NULL, NULL);
- g_return_val_if_fail (it->last_returned->data != STOLEN, NULL);
- g_assert (it->last_returned->data != GROUP_START);
-
- buffer = it->last_returned->data;
- it->last_returned->data = (gpointer) STOLEN;
-
- return buffer;
-}
-
-/**
- * gst_buffer_list_iterator_do:
- * @it: a #GstBufferListIterator
- * @do_func: the function to be called
- * @user_data: the gpointer to optional user data.
- *
- * Calls the given function for the last buffer returned by
- * gst_buffer_list_iterator_next(). gst_buffer_list_iterator_next() must have
- * been called on @it before this function is called.
- * gst_buffer_list_iterator_remove() and gst_buffer_list_iterator_steal() must
- * not have been called since the last call to gst_buffer_list_iterator_next().
- *
- * See #GstBufferListDoFunction for more details.
- *
- * Returns: (transfer none): the return value from @do_func
- *
- * Since: 0.10.24
- */
-GstBuffer *
-gst_buffer_list_iterator_do (GstBufferListIterator * it,
- GstBufferListDoFunction do_func, gpointer user_data)
-{
- GstBuffer *buffer;
-
- g_return_val_if_fail (it != NULL, NULL);
- g_return_val_if_fail (it->last_returned != NULL, NULL);
- g_return_val_if_fail (it->last_returned->data != STOLEN, NULL);
- g_return_val_if_fail (do_func != NULL, NULL);
- g_return_val_if_fail (gst_buffer_list_is_writable (it->list), NULL);
- g_assert (it->last_returned->data != GROUP_START);
-
- buffer = gst_buffer_list_iterator_steal (it);
- buffer = do_func (buffer, user_data);
- if (buffer == NULL) {
- gst_buffer_list_iterator_remove (it);
- } else {
- gst_buffer_list_iterator_take (it, buffer);
- }
-
- return buffer;
-}
-
-/**
- * gst_buffer_list_iterator_merge_group:
- * @it: a #GstBufferListIterator
- *
- * Merge a buffer list group into a normal #GstBuffer by copying its metadata
- * and memcpying its data into consecutive memory. All buffers in the current
- * group after the implicit cursor will be merged into one new buffer. The
- * metadata of the new buffer will be a copy of the metadata of the buffer that
- * would be returned by gst_buffer_list_iterator_next(). If there is no buffer
- * in the current group after the implicit cursor, NULL will be returned.
- *
- * This function will not move the implicit cursor or in any other way affect
- * the state of the iterator @it or the list.
- *
- * Returns: (transfer full): a new #GstBuffer, gst_buffer_unref() after usage,
- * or NULL
- *
- * Since: 0.10.24
- */
-GstBuffer *
-gst_buffer_list_iterator_merge_group (const GstBufferListIterator * it)
-{
- GList *tmp;
- gsize size;
- GstBuffer *buf;
- guint8 *dest, *ptr;
-
- g_return_val_if_fail (it != NULL, NULL);
-
- /* calculate size of merged buffer */
- size = 0;
- tmp = it->next;
- while (tmp && tmp->data != GROUP_START) {
- if (tmp->data != STOLEN) {
- size += gst_buffer_get_size (tmp->data);
- }
- tmp = g_list_next (tmp);
- }
-
- if (size == 0) {
- return NULL;
- }
-
- /* allocate a new buffer */
- buf = gst_buffer_new_and_alloc (size);
-
- /* copy metadata from the next buffer after the implicit cursor */
- gst_buffer_copy_into (buf, GST_BUFFER_CAST (it->next->data),
- GST_BUFFER_COPY_METADATA, 0, -1);
-
- /* copy data of all buffers before the next group start into the new buffer */
- dest = ptr = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
- tmp = it->next;
- do {
- if (tmp->data != STOLEN) {
- GstBuffer *tbuf = GST_BUFFER_CAST (tmp->data);
- gsize bsize;
-
- bsize = gst_buffer_get_size (tbuf);
- gst_buffer_extract (tbuf, 0, ptr, bsize);
- ptr += bsize;
- }
- tmp = g_list_next (tmp);
- } while (tmp && tmp->data != GROUP_START);
-
- gst_buffer_unmap (buf, dest, size);
-
- return buf;