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

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.
This commit is contained in:
Andy Wingo 2005-08-16 17:23:55 +00:00
parent 3b0897e827
commit ecbae942c5
5 changed files with 76 additions and 0 deletions

View file

@ -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),

View file

@ -257,6 +257,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

View 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);

View file

@ -257,6 +257,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

View 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);