gst/base/gstadapter.*: New function, like peek() but you own the data. Not terribly...
authorAndy Wingo <wingo@pobox.com>
Tue, 16 Aug 2005 17:23:55 +0000 (17:23 +0000)
committerAndy Wingo <wingo@pobox.com>
Tue, 16 Aug 2005 17:23:55 +0000 (17:23 +0000)
Original commit message from CVS:
2005-08-16  Andy Wingo  <wingo@pobox.com>

* gst/base/gstadapter.h:
* gst/base/gstadapter.c (gst_adapter_take): New function, like
peek() but you own the data. Not terribly efficient atm.

ChangeLog
gst/base/gstadapter.c
gst/base/gstadapter.h
libs/gst/base/gstadapter.c
libs/gst/base/gstadapter.h

index 2d9190d..70f6ed7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-08-16  Andy Wingo  <wingo@pobox.com>
+
+       * gst/base/gstadapter.h:
+       * gst/base/gstadapter.c (gst_adapter_take): New function, like
+       peek() but you own the data. Not terribly efficient atm.
+
 2005-08-16  Ronald S. Bultje  <rbultje@ronald.bitfreak.net>
 
        * gst/gstutils.c: (gst_element_found_tags_for_pad), (push_and_ref),
index 7c2b3ad..c9c8565 100644 (file)
@@ -258,6 +258,40 @@ gst_adapter_flush (GstAdapter * adapter, guint flush)
 }
 
 /**
+ * gst_adapter_take:
+ * @adapter: a #GstAdapter
+ * @nbytes: number of bytes to take
+ *
+ * Returns a freshly allocated buffer containing the first @nbytes bytes of the
+ * @adapter. g_free() the return value after use.
+ *
+ * Returns: oven-fresh hot data, or NULL if @nbytes bytes are not available
+ */
+guint8 *
+gst_adapter_take (GstAdapter * adapter, guint nbytes)
+{
+  const guint8 *cdata;
+  guint8 *data;
+
+  g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
+  g_return_val_if_fail (nbytes > 0, NULL);
+
+  GST_LOG_OBJECT (adapter, "taking %u bytes", nbytes);
+
+  cdata = gst_adapter_peek (adapter, nbytes);
+
+  if (!cdata)
+    return NULL;
+
+  data = g_malloc (nbytes);
+  memcpy (data, cdata, nbytes);
+
+  gst_adapter_flush (adapter, nbytes);
+
+  return data;
+}
+
+/**
  * gst_adapter_available:
  * @adapter: a #GstAdapter
  *
index f39a7b9..c12eec9 100644 (file)
@@ -68,6 +68,7 @@ void                  gst_adapter_clear               (GstAdapter *adapter);
 void                   gst_adapter_push                (GstAdapter *adapter, GstBuffer* buf);
 const guint8 *         gst_adapter_peek                (GstAdapter *adapter, guint size);
 void                   gst_adapter_flush               (GstAdapter *adapter, guint flush);
+guint8*                        gst_adapter_take                (GstAdapter * adapter, guint nbytes);
 guint                  gst_adapter_available           (GstAdapter *adapter);
 guint                  gst_adapter_available_fast      (GstAdapter *adapter);
 GType                  gst_adapter_get_type            (void);
index 7c2b3ad..c9c8565 100644 (file)
@@ -258,6 +258,40 @@ gst_adapter_flush (GstAdapter * adapter, guint flush)
 }
 
 /**
+ * gst_adapter_take:
+ * @adapter: a #GstAdapter
+ * @nbytes: number of bytes to take
+ *
+ * Returns a freshly allocated buffer containing the first @nbytes bytes of the
+ * @adapter. g_free() the return value after use.
+ *
+ * Returns: oven-fresh hot data, or NULL if @nbytes bytes are not available
+ */
+guint8 *
+gst_adapter_take (GstAdapter * adapter, guint nbytes)
+{
+  const guint8 *cdata;
+  guint8 *data;
+
+  g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
+  g_return_val_if_fail (nbytes > 0, NULL);
+
+  GST_LOG_OBJECT (adapter, "taking %u bytes", nbytes);
+
+  cdata = gst_adapter_peek (adapter, nbytes);
+
+  if (!cdata)
+    return NULL;
+
+  data = g_malloc (nbytes);
+  memcpy (data, cdata, nbytes);
+
+  gst_adapter_flush (adapter, nbytes);
+
+  return data;
+}
+
+/**
  * gst_adapter_available:
  * @adapter: a #GstAdapter
  *
index f39a7b9..c12eec9 100644 (file)
@@ -68,6 +68,7 @@ void                  gst_adapter_clear               (GstAdapter *adapter);
 void                   gst_adapter_push                (GstAdapter *adapter, GstBuffer* buf);
 const guint8 *         gst_adapter_peek                (GstAdapter *adapter, guint size);
 void                   gst_adapter_flush               (GstAdapter *adapter, guint flush);
+guint8*                        gst_adapter_take                (GstAdapter * adapter, guint nbytes);
 guint                  gst_adapter_available           (GstAdapter *adapter);
 guint                  gst_adapter_available_fast      (GstAdapter *adapter);
 GType                  gst_adapter_get_type            (void);