mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-04 01:32:42 +00:00
adapter: improve the flush function
Remove a compare and branch from flush.
This commit is contained in:
parent
6784355d52
commit
72232cfef1
1 changed files with 38 additions and 22 deletions
|
@ -467,39 +467,55 @@ gst_adapter_flush (GstAdapter * adapter, guint flush)
|
||||||
{
|
{
|
||||||
GstBuffer *cur;
|
GstBuffer *cur;
|
||||||
guint size;
|
guint size;
|
||||||
|
GstAdapterPrivate *priv;
|
||||||
|
GSList *g;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
GST_LOG_OBJECT (adapter, "flushing %u bytes", flush);
|
GST_LOG_OBJECT (adapter, "flushing %u bytes", flush);
|
||||||
|
|
||||||
|
/* flushing out 0 bytes will do nothing */
|
||||||
|
if (G_UNLIKELY (flush == 0))
|
||||||
|
return;
|
||||||
|
|
||||||
|
priv = adapter->priv;
|
||||||
|
|
||||||
|
/* clear state */
|
||||||
adapter->size -= flush;
|
adapter->size -= flush;
|
||||||
adapter->assembled_len = 0;
|
adapter->assembled_len = 0;
|
||||||
while (flush > 0) {
|
|
||||||
cur = adapter->buflist->data;
|
/* take skip into account */
|
||||||
size = GST_BUFFER_SIZE (cur) - adapter->skip;
|
flush += adapter->skip;
|
||||||
if (size <= flush) {
|
/* distance is always at least the amount of skipped bytes */
|
||||||
|
priv->distance -= adapter->skip;
|
||||||
|
|
||||||
|
g = adapter->buflist;
|
||||||
|
cur = g->data;
|
||||||
|
size = GST_BUFFER_SIZE (cur);
|
||||||
|
while (flush >= size) {
|
||||||
/* can skip whole buffer */
|
/* can skip whole buffer */
|
||||||
GST_LOG_OBJECT (adapter, "flushing out head buffer");
|
GST_LOG_OBJECT (adapter, "flushing out head buffer");
|
||||||
|
priv->distance += size;
|
||||||
flush -= size;
|
flush -= size;
|
||||||
adapter->skip = 0;
|
|
||||||
adapter->priv->distance += size;
|
|
||||||
adapter->buflist =
|
|
||||||
g_slist_delete_link (adapter->buflist, adapter->buflist);
|
|
||||||
|
|
||||||
if (G_UNLIKELY (adapter->buflist == NULL)) {
|
gst_buffer_unref (cur);
|
||||||
|
g = g_slist_delete_link (g, g);
|
||||||
|
|
||||||
|
if (G_UNLIKELY (g == NULL)) {
|
||||||
GST_LOG_OBJECT (adapter, "adapter empty now");
|
GST_LOG_OBJECT (adapter, "adapter empty now");
|
||||||
adapter->buflist_end = NULL;
|
adapter->buflist_end = NULL;
|
||||||
} else {
|
|
||||||
/* there is a new head buffer, update the timestamp */
|
|
||||||
update_timestamp (adapter, GST_BUFFER_CAST (adapter->buflist->data));
|
|
||||||
}
|
|
||||||
gst_buffer_unref (cur);
|
|
||||||
} else {
|
|
||||||
adapter->skip += flush;
|
|
||||||
adapter->priv->distance += flush;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* there is a new head buffer, update the timestamp */
|
||||||
|
cur = g->data;
|
||||||
|
update_timestamp (adapter, cur);
|
||||||
|
size = GST_BUFFER_SIZE (cur);
|
||||||
}
|
}
|
||||||
|
adapter->buflist = g;
|
||||||
|
/* account for the remaining bytes */
|
||||||
|
adapter->skip = flush;
|
||||||
|
adapter->priv->distance += flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue