From 7e14875458c6f2dc68b071251a0d372bcd87f693 Mon Sep 17 00:00:00 2001 From: "Reynaldo H. Verdejo Pinochet" Date: Tue, 18 Oct 2016 16:18:19 -0700 Subject: [PATCH] typefind: add typefinder for Apple/iTunes itc artwork files Avoids audio/mpeg false-positive described at: https://bugzilla.gnome.org/show_bug.cgi?id=773172 --- gst/typefind/gsttypefindfunctions.c | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index 353525a..7cac6bd 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -422,6 +422,67 @@ uri_type_find (GstTypeFind * tf, gpointer unused) } } +/*** application/itc ***/ +static GstStaticCaps itc_caps = GST_STATIC_CAPS ("application/itc"); +#define ITC_CAPS (gst_static_caps_get(&itc_caps)) + +static void +itc_type_find (GstTypeFind * tf, gpointer unused) +{ + DataScanCtx c = { 0, NULL, 0 }; + guint8 magic[8] = { 0x00, 0x00, 0x01, 0x1C, 0x69, 0x74, 0x63, 0x68 }; + guint8 preamble[4] = { 0x00, 0x00, 0x00, 0x02 }; + guint8 artwork_marker[8] = { 0x00, 0x00, 0x00, 0x00, 0x61, 0x72, 0x74, 0x77 }; + GstTypeFindProbability itc_prob = GST_TYPE_FIND_NONE; + int i; + + if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 8))) + return; + + if (memcmp (c.data, magic, 8)) + return; + + /* At least we found the right magic */ + itc_prob = GST_TYPE_FIND_MINIMUM; + data_scan_ctx_advance (tf, &c, 8); + + if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12))) + goto done; + + /* Check preamble 3 consecutive times */ + for (i = 0; i < 3; i++) { + if (memcmp (c.data, preamble, 4)) + goto done; + data_scan_ctx_advance (tf, &c, 4); + } + + itc_prob = GST_TYPE_FIND_POSSIBLE; + + if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 8))) + goto done; + + /* Look for "artw" marker */ + if (memcmp (c.data, artwork_marker, 8)) + goto done; + + itc_prob = GST_TYPE_FIND_LIKELY; + data_scan_ctx_advance (tf, &c, 8); + + if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 256))) + goto done; + + /* ...and 256 0x00 padding bytes on what looks like the header's end */ + for (i = 0; i < 256; i++) { + if (c.data[i]) + goto done; + } + + itc_prob = GST_TYPE_FIND_NEARLY_CERTAIN; + +done: + gst_type_find_suggest (tf, itc_prob, ITC_CAPS); +} + /*** application/x-hls ***/ static GstStaticCaps hls_caps = GST_STATIC_CAPS ("application/x-hls"); @@ -5683,6 +5744,8 @@ plugin_init (GstPlugin * plugin) "txt", UTF32_CAPS, NULL, NULL); TYPE_FIND_REGISTER (plugin, "text/uri-list", GST_RANK_MARGINAL, uri_type_find, "ram", URI_CAPS, NULL, NULL); + TYPE_FIND_REGISTER (plugin, "application/itc", GST_RANK_SECONDARY, + itc_type_find, "itc", ITC_CAPS, NULL, NULL); TYPE_FIND_REGISTER (plugin, "application/x-hls", GST_RANK_MARGINAL, hls_type_find, "m3u8", HLS_CAPS, NULL, NULL); TYPE_FIND_REGISTER (plugin, "application/sdp", GST_RANK_SECONDARY, -- 2.7.4