From 654ba215dffd2dac92540575d67096b99dafcbfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 16 May 2008 21:09:45 +0000 Subject: [PATCH] libs/gst/base/gsttypefindhelper.c: Sort buffer cache list by end offsets. This makes sure that we don't stop to searc... Original commit message from CVS: * libs/gst/base/gsttypefindhelper.c: (helper_find_peek): Sort buffer cache list by end offsets. This makes sure that we don't stop to search for a cached buffer that contains the requested data too early. Also read a minimum of 4k bytes instead of 512 bytes as this is a bit more efficient. Fixes bug #459862. --- ChangeLog | 9 +++++++++ common | 2 +- libs/gst/base/gsttypefindhelper.c | 15 ++++++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6cdf3e4de3..f2c029438f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-05-16 Sebastian Dröge + + * libs/gst/base/gsttypefindhelper.c: (helper_find_peek): + Sort buffer cache list by end offsets. This makes sure that we don't + stop to search for a cached buffer that contains the requested data + too early. + Also read a minimum of 4k bytes instead of 512 bytes as this is a bit + more efficient. Fixes bug #459862. + 2008-05-14 Stefan Kost * gst/gstinfo.c: diff --git a/common b/common index d78efae300..3b3631082d 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit d78efae300d4dff0291717ccf7a2b82c713a81ef +Subproject commit 3b3631082d04b426f450810e8836de94e9c5d60a diff --git a/libs/gst/base/gsttypefindhelper.c b/libs/gst/base/gsttypefindhelper.c index f65035c604..ce5dece2fb 100644 --- a/libs/gst/base/gsttypefindhelper.c +++ b/libs/gst/base/gsttypefindhelper.c @@ -111,16 +111,14 @@ helper_find_peek (gpointer data, gint64 offset, guint size) guint64 buf_offset = GST_BUFFER_OFFSET (buf); guint buf_size = GST_BUFFER_SIZE (buf); + /* buffers are kept sorted by end offset (highest first) in the list, so + * at this point we save the current position and stop searching if + * we're after the searched end offset */ if (buf_offset <= offset) { if ((offset + size) < (buf_offset + buf_size)) { return GST_BUFFER_DATA (buf) + (offset - buf_offset); } - /* buffers are kept sorted by offset (highest first) in the list, so - * at this point we know we don't need to check the remaining buffers - * (is that correct or just a guess that we're unlikely to find a - * match further down and it's most of the time not worth going through - * the entire list? How do we know the next buffer isn't offset-N with - * a big enough size to cover the requested offset+size?) */ + } else if (offset + size >= buf_offset + buf_size) { insert_pos = walk; break; } @@ -134,7 +132,7 @@ helper_find_peek (gpointer data, gint64 offset, guint size) * of the file is also not a problem here, we'll just get a truncated buffer * in that case (and we'll have to double-check the size we actually get * anyway, see below) */ - ret = helper->func (helper->obj, offset, MAX (size, 512), &buffer); + ret = helper->func (helper->obj, offset, MAX (size, 4096), &buffer); if (ret != GST_FLOW_OK) goto error; @@ -157,8 +155,7 @@ helper_find_peek (gpointer data, gint64 offset, guint size) /* if insert_pos is not set, our offset is bigger than the largest offset * we have so far; since we keep the list sorted with highest offsets * first, we need to prepend the buffer to the list */ - /* FIXME: why not last_offset = buffer_offset + buffer_size here? */ - helper->last_offset = GST_BUFFER_OFFSET (buffer); + helper->last_offset = GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer); helper->buffers = g_slist_prepend (helper->buffers, buffer); } return GST_BUFFER_DATA (buffer);