From 4cbe4d2c725314f78eda017dbc6d65605db8626a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Wed, 11 Mar 2009 13:33:33 +0000 Subject: [PATCH] typefinding: flac typefinder fixes Use scan context for initial peek as well. Peek 6 bytes in the initial peek rather than 5 bytes, to match the length of the memcmp we're doing on that data later. Return immediately when we found caps from looking at the beginning of the data - no point in continuing to scan the next 64kB for something matching a frame header. --- gst/typefind/gsttypefindfunctions.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index d199a56ae8..ead4a37eac 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -552,19 +552,21 @@ static GstStaticCaps flac_caps = GST_STATIC_CAPS ("audio/x-flac"); static void flac_type_find (GstTypeFind * tf, gpointer unused) { - guint8 *data; DataScanCtx c = { 0, NULL, 0 }; - data = gst_type_find_peek (tf, 0, 5); - if (G_LIKELY (data)) { - /* standard flac */ - if (memcmp (data, "fLaC", 4) == 0) { - gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS); - } - /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */ - else if (memcmp (data, "\177FLAC\001", 6) == 0) { - gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS); - } + if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6))) + return; + + /* standard flac */ + if (memcmp (c.data, "fLaC", 4) == 0) { + gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS); + return; + } + + /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */ + if (memcmp (c.data, "\177FLAC\001", 6) == 0) { + gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS); + return; } /* flac without headers (subset format) */