diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index b8132e7b7f..86355fb8f7 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -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 diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c index bf605732c6..ab70fce5f7 100644 --- a/libs/gst/base/gstadapter.c +++ b/libs/gst/base/gstadapter.c @@ -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 diff --git a/libs/gst/base/gstadapter.h b/libs/gst/base/gstadapter.h index f82fbfb5cd..3e93ca2667 100644 --- a/libs/gst/base/gstadapter.h +++ b/libs/gst/base/gstadapter.h @@ -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); diff --git a/win32/common/libgstbase.def b/win32/common/libgstbase.def index 8a596b8cc7..1767f6715f 100644 --- a/win32/common/libgstbase.def +++ b/win32/common/libgstbase.def @@ -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