From 3de939cb5b7c4fdf40a4f2b780a0ce620cd7b6ee Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 1 Mar 2014 23:18:44 +0100 Subject: [PATCH] adapter: Adapt gst_adapter_copy() for bindings This is done by introducing a new gst_adapter_copy_bytes() call that returns a GBytes structure. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=725476 --- docs/libs/gstreamer-libs-sections.txt | 1 + libs/gst/base/gstadapter.c | 28 +++++++++++++++++++++++++++- libs/gst/base/gstadapter.h | 2 ++ win32/common/libgstbase.def | 1 + 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index 99dfb1c..2cc3c1a 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -159,6 +159,7 @@ gst_adapter_push gst_adapter_map gst_adapter_unmap gst_adapter_copy +gst_adapter_copy_bytes gst_adapter_flush gst_adapter_available gst_adapter_available_fast diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c index 4c3e730..e590f45 100644 --- a/libs/gst/base/gstadapter.c +++ b/libs/gst/base/gstadapter.c @@ -526,7 +526,7 @@ gst_adapter_unmap (GstAdapter * adapter) } /** - * gst_adapter_copy: + * gst_adapter_copy: (skip) * @adapter: a #GstAdapter * @dest: (out caller-allocates) (array length=size) (element-type guint8): * the memory to copy into @@ -550,6 +550,32 @@ gst_adapter_copy (GstAdapter * adapter, gpointer dest, gsize offset, gsize size) copy_into_unchecked (adapter, dest, offset + adapter->skip, size); } +/** + * gst_adapter_copy_bytes: + * @adapter: a #GstAdapter + * @offset: the bytes offset in the adapter to start from + * @size: the number of bytes to copy + * + * Similar to gst_adapter_copy, but more suitable for language bindings. @size + * bytes of data starting at @offset will be copied out of the buffers contained + * in @adapter and into a new #GBytes structure which is returned. Depending on + * the value of the @size argument an empty #GBytes structure may be returned. + * + * Returns: (transfer full): A new #GBytes structure containing the copied data. + * + * Rename to: gst_adapter_copy + * + * Since: 1.4 + */ +GBytes * +gst_adapter_copy_bytes (GstAdapter * adapter, gsize offset, gsize size) +{ + gpointer data; + data = g_malloc (size); + gst_adapter_copy (adapter, data, offset, size); + return g_bytes_new_take (data, size); +} + /*Flushes the first @flush bytes in the @adapter*/ static void gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush) diff --git a/libs/gst/base/gstadapter.h b/libs/gst/base/gstadapter.h index 9683f3b..f82fbfb 100644 --- a/libs/gst/base/gstadapter.h +++ b/libs/gst/base/gstadapter.h @@ -56,6 +56,8 @@ gconstpointer gst_adapter_map (GstAdapter *adapter, gs void gst_adapter_unmap (GstAdapter *adapter); void gst_adapter_copy (GstAdapter *adapter, gpointer dest, gsize offset, gsize size); +GBytes * gst_adapter_copy_bytes (GstAdapter *adapter, + gsize offset, gsize size); void gst_adapter_flush (GstAdapter *adapter, gsize flush); gpointer gst_adapter_take (GstAdapter *adapter, gsize nbytes); GstBuffer* gst_adapter_take_buffer (GstAdapter *adapter, gsize nbytes); diff --git a/win32/common/libgstbase.def b/win32/common/libgstbase.def index fac5702..8049a96 100644 --- a/win32/common/libgstbase.def +++ b/win32/common/libgstbase.def @@ -3,6 +3,7 @@ EXPORTS gst_adapter_available_fast gst_adapter_clear gst_adapter_copy + gst_adapter_copy_bytes gst_adapter_flush gst_adapter_get_type gst_adapter_map -- 2.7.4