From 70148cdf9746f013f7c1fc0cde60da365747e410 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 30 Mar 2011 09:12:25 +0200 Subject: [PATCH] typefind: Use the DataScanCtx for the m3u8 typefinder --- gst/typefind/gsttypefindfunctions.c | 42 ++++++++++++++----------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index c58e3f2..1c4e559 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -269,44 +269,34 @@ uri_type_find (GstTypeFind * tf, gpointer unused) /*** plaulist/m3u8 ***/ static GstStaticCaps m3u8_caps = GST_STATIC_CAPS ("playlist/m3u8"); - #define M3U8_CAPS (gst_static_caps_get(&m3u8_caps)) -#define M3U8_BUFFER_SIZE 24 -#define M3U8_INC_BUFFER { \ - pos++; \ - if (pos == M3U8_BUFFER_SIZE) { \ - pos = 0; \ - offset += M3U8_BUFFER_SIZE; \ - data = gst_type_find_peek (tf, offset, M3U8_BUFFER_SIZE); \ - if (data == NULL) return; \ - } else { \ - data++; \ - } \ -} static void m3u8_type_find (GstTypeFind * tf, gpointer unused) { - guint pos = 0; - guint offset = 0; - guint8 *data = gst_type_find_peek (tf, 0, 7); + DataScanCtx c = { 0, NULL, 0 }; - if (memcmp (data, "#EXTM3U", 7)) + if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 7))) return; - M3U8_INC_BUFFER; - while (data) { - /* Search for # comment lines */ - while (*data != '#') { - M3U8_INC_BUFFER; - } + if (memcmp (c.data, "#EXTM3U", 7)) + return; + + data_scan_ctx_advance (tf, &c, 7); - if (memcmp (data, "#EXT-X-TARGETDURATION", 21) == 0 || - memcmp (data, "#EXT-X-STREAM-INF", 17) == 0) { + /* Check only the first 256 bytes */ + while (c.offset < 256) { + if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 21))) + return; + + /* Search for # comment lines */ + if (c.data[0] == '#' && (memcmp (c.data, "#EXT-X-TARGETDURATION", 21) == 0 + || memcmp (c.data, "#EXT-X-STREAM-INF", 17) == 0)) { gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M3U8_CAPS); return; } - M3U8_INC_BUFFER; + + data_scan_ctx_advance (tf, &c, 1); } } -- 2.7.4