From cdbb4ae9cab79e4495f44438137fd6a94a32ddad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Wed, 19 Oct 2005 09:21:46 +0000 Subject: [PATCH] gst/typefind/gsttypefindfunctions.c: Akos Maroy (#308663). Original commit message from CVS: * gst/typefind/gsttypefindfunctions.c: (utf8_type_find), (xml_check_first_element), (xml_type_find), (smil_type_find), (plugin_init): Add typefinding for SMIL and for generic XML. Based on patch by Akos Maroy (#308663). --- ChangeLog | 8 ++ gst/typefind/gsttypefindfunctions.c | 127 ++++++++++++++++++++++++---- 2 files changed, 117 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index ccd3853a76..b4a7f57c3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-10-19 Tim-Philipp Müller + + * gst/typefind/gsttypefindfunctions.c: (utf8_type_find), + (xml_check_first_element), (xml_type_find), (smil_type_find), + (plugin_init): + Add typefinding for SMIL and for generic XML. Based on patch by + Akos Maroy (#308663). + 2005-10-18 Wim Taymans * gst/playback/Makefile.am: diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index 8bf9c0da7d..a93abeca25 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -38,6 +38,9 @@ GST_DEBUG_CATEGORY_STATIC (type_find_debug); #define GST_CAT_DEFAULT type_find_debug /*** text/plain ***/ +static gboolean xml_check_first_element (GstTypeFind * tf, + const gchar * element, guint elen); + static GstStaticCaps utf8_caps = GST_STATIC_CAPS ("text/plain"); @@ -53,6 +56,10 @@ utf8_type_find (GstTypeFind * tf, gpointer unused) guint step = 10; /* how much we reduce probability in each * iteration */ + /* leave xml to the xml typefinders */ + if (xml_check_first_element (tf, "", 0)) + return; + while (probability > step) { data = gst_type_find_peek (tf, 0, size); if (data) { @@ -133,6 +140,84 @@ uri_type_find (GstTypeFind * tf, gpointer unused) } } + +/*** application/xml **********************************************************/ + +#define XML_BUFFER_SIZE 256 +#define XML_INC_BUFFER { \ + pos++; \ + if (pos == XML_BUFFER_SIZE) { \ + pos = 0; \ + offset += XML_BUFFER_SIZE; \ + data = gst_type_find_peek (tf, offset, XML_BUFFER_SIZE); \ + if (data == NULL) return FALSE; \ + } else { \ + data++; \ + } \ +} + +static gboolean +xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen) +{ + guint8 *data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE); + guint offset = 0; + guint pos = 0; + + /* look for the XMLDec, + * see XML spec 2.8, Prolog and Document Type Declaration + * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */ + if (!data || memcmp (data, " element */ + while (data) { + while (*data != '<') { + XML_INC_BUFFER; + } + + XML_INC_BUFFER; + if (!g_ascii_isalpha (*data)) { + /* if not alphabetic, it's a PI or an element / attribute declaration + * like