+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),
}
/**
+ * 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
*
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);
}
/**
+ * 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
*
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);