adapter: small cleanups

This commit is contained in:
Wim Taymans 2009-05-13 16:20:26 +02:00
parent 39d21970b0
commit 8ceff30ca9
2 changed files with 11 additions and 5 deletions

View file

@ -210,7 +210,6 @@ gst_adapter_push (GstAdapter * adapter, GstBuffer * buf)
GST_LOG_OBJECT (adapter, "discarding empty buffer"); GST_LOG_OBJECT (adapter, "discarding empty buffer");
gst_buffer_unref (buf); gst_buffer_unref (buf);
} else { } else {
adapter->size += size; adapter->size += size;
/* Note: merging buffers at this point is premature. */ /* Note: merging buffers at this point is premature. */
@ -433,6 +432,7 @@ void
gst_adapter_flush (GstAdapter * adapter, guint flush) gst_adapter_flush (GstAdapter * adapter, guint flush)
{ {
GstBuffer *cur; GstBuffer *cur;
guint size;
g_return_if_fail (GST_IS_ADAPTER (adapter)); g_return_if_fail (GST_IS_ADAPTER (adapter));
g_return_if_fail (flush <= adapter->size); g_return_if_fail (flush <= adapter->size);
@ -442,14 +442,19 @@ gst_adapter_flush (GstAdapter * adapter, guint flush)
adapter->assembled_len = 0; adapter->assembled_len = 0;
while (flush > 0) { while (flush > 0) {
cur = adapter->buflist->data; cur = adapter->buflist->data;
if (GST_BUFFER_SIZE (cur) <= flush + adapter->skip) { size = GST_BUFFER_SIZE (cur) - adapter->skip;
if (size <= flush) {
/* can skip whole buffer */ /* can skip whole buffer */
flush -= GST_BUFFER_SIZE (cur) - adapter->skip; GST_LOG_OBJECT (adapter, "flushing out head buffer");
flush -= size;
adapter->skip = 0; adapter->skip = 0;
adapter->buflist = adapter->buflist =
g_slist_delete_link (adapter->buflist, adapter->buflist); g_slist_delete_link (adapter->buflist, adapter->buflist);
if (G_UNLIKELY (adapter->buflist == NULL))
if (G_UNLIKELY (adapter->buflist == NULL)) {
GST_LOG_OBJECT (adapter, "adapter empty now");
adapter->buflist_end = NULL; adapter->buflist_end = NULL;
}
gst_buffer_unref (cur); gst_buffer_unref (cur);
} else { } else {
adapter->skip += flush; adapter->skip += flush;

View file

@ -73,6 +73,8 @@ struct _GstAdapterClass {
gpointer _gst_reserved[GST_PADDING]; gpointer _gst_reserved[GST_PADDING];
}; };
GType gst_adapter_get_type (void);
GstAdapter * gst_adapter_new (void); GstAdapter * gst_adapter_new (void);
void gst_adapter_clear (GstAdapter *adapter); void gst_adapter_clear (GstAdapter *adapter);
@ -85,7 +87,6 @@ guint8* gst_adapter_take (GstAdapter *adapter, guint nbytes);
GstBuffer* gst_adapter_take_buffer (GstAdapter *adapter, guint nbytes); GstBuffer* gst_adapter_take_buffer (GstAdapter *adapter, guint nbytes);
guint gst_adapter_available (GstAdapter *adapter); guint gst_adapter_available (GstAdapter *adapter);
guint gst_adapter_available_fast (GstAdapter *adapter); guint gst_adapter_available_fast (GstAdapter *adapter);
GType gst_adapter_get_type (void);
G_END_DECLS G_END_DECLS