From ba8a8319fd409b54efdb52faa583217b9757d919 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Wed, 10 Aug 2005 15:08:03 +0000 Subject: [PATCH] gst/base/gsttypefindhelper.c: The memory returned by gst_type_find_peek() needs to stay valid until the end of a type... Original commit message from CVS: * gst/base/gsttypefindhelper.c: (helper_find_peek), (gst_type_find_helper): The memory returned by gst_type_find_peek() needs to stay valid until the end of a typefind function, and typefind functions may keep results from different offsets around, so we can't just unref the buffer from the previous _peek(), but have to save all buffers returned by _peek() until typefinding is done and only free them then. --- ChangeLog | 12 ++++++++++++ gst/base/gsttypefindhelper.c | 18 ++++++++---------- libs/gst/base/gsttypefindhelper.c | 18 ++++++++---------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19a75b8..3f6b081 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-08-10 Tim-Philipp Müller + + * gst/base/gsttypefindhelper.c: (helper_find_peek), + (gst_type_find_helper): + The memory returned by gst_type_find_peek() needs to + stay valid until the end of a typefind function, and + typefind functions may keep results from different + offsets around, so we can't just unref the buffer from + the previous _peek(), but have to save all buffers + returned by _peek() until typefinding is done and only + free them then. + 2005-08-09 Tim-Philipp Müller * docs/gst/gstreamer-sections.txt: diff --git a/gst/base/gsttypefindhelper.c b/gst/base/gsttypefindhelper.c index 884d7f9..11a2bc6 100644 --- a/gst/base/gsttypefindhelper.c +++ b/gst/base/gsttypefindhelper.c @@ -38,7 +38,7 @@ typedef struct guint best_probability; GstCaps *caps; guint64 size; - GstBuffer *buffer; + GList *buffers; } GstTypeFindHelper; @@ -63,18 +63,15 @@ helper_find_peek (gpointer data, gint64 offset, guint size) offset += find->size; } + /* TODO: is it worth checking our list of buffers for + * a match before pulling a new buffer via _getrange()? */ buffer = NULL; ret = GST_PAD_GETRANGEFUNC (src) (src, offset, size, &buffer); - if (find->buffer) { - gst_buffer_unref (find->buffer); - find->buffer = NULL; - } - if (ret != GST_FLOW_OK) goto error; - find->buffer = buffer; + find->buffers = g_list_prepend (find->buffers, buffer); return GST_BUFFER_DATA (buffer); @@ -112,7 +109,7 @@ gst_type_find_helper (GstPad * src, guint64 size) find.best_probability = 0; find.caps = NULL; find.size = size; - find.buffer = NULL; + find.buffers = NULL; gst_find.data = &find; gst_find.peek = helper_find_peek; gst_find.suggest = helper_find_suggest; @@ -130,8 +127,9 @@ gst_type_find_helper (GstPad * src, guint64 size) if (find.best_probability > 0) result = find.caps; - if (find.buffer) - gst_buffer_unref (find.buffer); + for (walk = find.buffers; walk; walk = walk->next) + gst_buffer_unref (GST_BUFFER (walk->data)); + g_list_free (find.buffers); return result; } diff --git a/libs/gst/base/gsttypefindhelper.c b/libs/gst/base/gsttypefindhelper.c index 884d7f9..11a2bc6 100644 --- a/libs/gst/base/gsttypefindhelper.c +++ b/libs/gst/base/gsttypefindhelper.c @@ -38,7 +38,7 @@ typedef struct guint best_probability; GstCaps *caps; guint64 size; - GstBuffer *buffer; + GList *buffers; } GstTypeFindHelper; @@ -63,18 +63,15 @@ helper_find_peek (gpointer data, gint64 offset, guint size) offset += find->size; } + /* TODO: is it worth checking our list of buffers for + * a match before pulling a new buffer via _getrange()? */ buffer = NULL; ret = GST_PAD_GETRANGEFUNC (src) (src, offset, size, &buffer); - if (find->buffer) { - gst_buffer_unref (find->buffer); - find->buffer = NULL; - } - if (ret != GST_FLOW_OK) goto error; - find->buffer = buffer; + find->buffers = g_list_prepend (find->buffers, buffer); return GST_BUFFER_DATA (buffer); @@ -112,7 +109,7 @@ gst_type_find_helper (GstPad * src, guint64 size) find.best_probability = 0; find.caps = NULL; find.size = size; - find.buffer = NULL; + find.buffers = NULL; gst_find.data = &find; gst_find.peek = helper_find_peek; gst_find.suggest = helper_find_suggest; @@ -130,8 +127,9 @@ gst_type_find_helper (GstPad * src, guint64 size) if (find.best_probability > 0) result = find.caps; - if (find.buffer) - gst_buffer_unref (find.buffer); + for (walk = find.buffers; walk; walk = walk->next) + gst_buffer_unref (GST_BUFFER (walk->data)); + g_list_free (find.buffers); return result; } -- 2.7.4