From 573b793f08164c91ee826e88cd953a81103582f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 14 Feb 2006 20:57:31 +0000 Subject: [PATCH] plugins/elements/gsttypefindelement.c: When typefinding is unsuccessful in the chain function, don't error out immedi... Original commit message from CVS: * plugins/elements/gsttypefindelement.c: (gst_type_find_element_chain): When typefinding is unsuccessful in the chain function, don't error out immediately. Only error out with NO_CAPS_FOUND if the amount of data is at least MAX_TYPEFIND_SIZE bytes, otherwise simply wait for more data so we can try typefinding again with more data later. Also, don't attempt to typefind if we have less than MIN_TYPEFIND_SIZE data available. Overall, this should improve typefinding from network sources where the size of the first buffer can be somewhat random. --- ChangeLog | 13 +++++++++++++ plugins/elements/gsttypefindelement.c | 22 +++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 53d4ae7d2a..df5705f804 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-02-14 Tim-Philipp Müller + + * plugins/elements/gsttypefindelement.c: + (gst_type_find_element_chain): + When typefinding is unsuccessful in the chain function, don't + error out immediately. Only error out with NO_CAPS_FOUND if + the amount of data is at least MAX_TYPEFIND_SIZE bytes, + otherwise simply wait for more data so we can try typefinding + again with more data later. Also, don't attempt to typefind + if we have less than MIN_TYPEFIND_SIZE data available. Overall, + this should improve typefinding from network sources where the + size of the first buffer can be somewhat random. + 2006-02-14 Wim Taymans * docs/gst/gstreamer-sections.txt: diff --git a/plugins/elements/gsttypefindelement.c b/plugins/elements/gsttypefindelement.c index 81e7dce78d..180509c3c5 100644 --- a/plugins/elements/gsttypefindelement.c +++ b/plugins/elements/gsttypefindelement.c @@ -82,6 +82,11 @@ GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY); +/* Require at least 2kB of data before we attempt typefinding in chain-mode. + * 128kB is massive overkill for the maximum, but doesn't do any harm */ +#define TYPE_FIND_MIN_SIZE (2*1024) +#define TYPE_FIND_MAX_SIZE (128*1024) + /* TypeFind signals and args */ enum { @@ -678,6 +683,11 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer) else typefind->store = buffer; + if (GST_BUFFER_SIZE (typefind->store) < TYPE_FIND_MIN_SIZE) { + GST_DEBUG_OBJECT (typefind, "not enough data for typefinding yet"); + return GST_FLOW_OK; + } + if (typefind->possibilities == NULL) { /* not yet started, get all typefinding functions into our "queue" */ GList *all_factories = gst_type_find_factory_get_list (); @@ -753,9 +763,15 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer) if (typefind->caps) { stop_typefinding (typefind); } else if (typefind->possibilities == NULL) { - GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, (NULL), (NULL)); - stop_typefinding (typefind); - return GST_FLOW_ERROR; + if (GST_BUFFER_SIZE (typefind->store) > TYPE_FIND_MAX_SIZE) { + GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, (NULL), (NULL)); + stop_typefinding (typefind); + return GST_FLOW_ERROR; + } else { + GST_DEBUG_OBJECT (typefind, "no type found with %u bytes - waiting " + "for more data", GST_BUFFER_SIZE (typefind->store)); + return GST_FLOW_OK; + } } else if (done) { TypeFindEntry *best;