adapter: add gst_adapter_take_buffer_list()

API: gst_adapter_take_buffer_list()
This commit is contained in:
Tim-Philipp Müller 2015-03-14 17:20:33 +00:00
parent f7eeed3447
commit e6a0f52e3c
4 changed files with 49 additions and 0 deletions

View file

@ -166,6 +166,7 @@ gst_adapter_take
gst_adapter_take_buffer
gst_adapter_take_buffer_fast
gst_adapter_take_list
gst_adapter_take_buffer_list
gst_adapter_prev_pts
gst_adapter_prev_dts
gst_adapter_prev_pts_at_offset

View file

@ -947,6 +947,52 @@ gst_adapter_take_list (GstAdapter * adapter, gsize nbytes)
return queue.head;
}
/**
* gst_adapter_take_buffer_list:
* @adapter: a #GstAdapter
* @nbytes: the number of bytes to take
*
* Returns a #GstBufferList of buffers containing the first @nbytes bytes of
* the @adapter. The returned bytes will be flushed from the adapter.
* When the caller can deal with individual buffers, this function is more
* performant because no memory should be copied.
*
* Caller owns the returned list. Call gst_buffer_list_unref() to free
* the list after usage.
*
* Returns: (transfer full) (nullable): a #GstBufferList of buffers containing
* the first @nbytes of the adapter, or %NULL if @nbytes bytes are not
* available
*
* Since: 1.6
*/
GstBufferList *
gst_adapter_take_buffer_list (GstAdapter * adapter, gsize nbytes)
{
GstBufferList *buffer_list;
GstBuffer *cur;
gsize hsize, skip, cur_size;
g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
if (nbytes > adapter->size)
return NULL;
GST_LOG_OBJECT (adapter, "taking %" G_GSIZE_FORMAT " bytes", nbytes);
buffer_list = gst_buffer_list_new ();
while (nbytes > 0) {
cur = adapter->buflist->data;
skip = adapter->skip;
cur_size = gst_buffer_get_size (cur);
hsize = MIN (nbytes, cur_size - skip);
gst_buffer_list_add (buffer_list, gst_adapter_take_buffer (adapter, hsize));
nbytes -= hsize;
}
return buffer_list;
}
/**
* gst_adapter_available:
* @adapter: a #GstAdapter

View file

@ -63,6 +63,7 @@ gpointer gst_adapter_take (GstAdapter *adapter, gs
GstBuffer* gst_adapter_take_buffer (GstAdapter *adapter, gsize nbytes);
GList* gst_adapter_take_list (GstAdapter *adapter, gsize nbytes);
GstBuffer * gst_adapter_take_buffer_fast (GstAdapter *adapter, gsize nbytes);
GstBufferList * gst_adapter_take_buffer_list (GstAdapter *adapter, gsize nbytes);
gsize gst_adapter_available (GstAdapter *adapter);
gsize gst_adapter_available_fast (GstAdapter *adapter);

View file

@ -18,6 +18,7 @@ EXPORTS
gst_adapter_take
gst_adapter_take_buffer
gst_adapter_take_buffer_fast
gst_adapter_take_buffer_list
gst_adapter_take_list
gst_adapter_unmap
gst_base_parse_add_index_entry