2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3 * Copyright (C) 2005-2009 Tim-Philipp Müller <tim centricular net>
4 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * gsttypefindfunctions.c: collection of various typefind functions
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
29 #include <glib/gprintf.h>
31 /* don't want to add gio xdgmime typefinder if gio was disabled via configure */
43 #include <gst/pbutils/pbutils.h>
44 #include <gst/base/gstbytereader.h>
46 GST_DEBUG_CATEGORY_STATIC (type_find_debug);
47 #define GST_CAT_DEFAULT type_find_debug
49 /* DataScanCtx: helper for typefind functions that scan through data
50 * step-by-step, to avoid doing a peek at each and every offset */
52 #define DATA_SCAN_CTX_CHUNK_SIZE 4096
62 data_scan_ctx_advance (GstTypeFind * tf, DataScanCtx * c, guint bytes_to_skip)
64 c->offset += bytes_to_skip;
65 if (G_LIKELY (c->size > bytes_to_skip)) {
66 c->size -= bytes_to_skip;
67 c->data += bytes_to_skip;
74 static inline gboolean
75 data_scan_ctx_ensure_data (GstTypeFind * tf, DataScanCtx * c, guint min_len)
79 guint chunk_len = MAX (DATA_SCAN_CTX_CHUNK_SIZE, min_len);
81 if (G_LIKELY (c->size >= min_len))
84 data = gst_type_find_peek (tf, c->offset, chunk_len);
85 if (G_LIKELY (data != NULL)) {
91 /* if there's less than our chunk size, try to get as much as we can, but
92 * always at least min_len bytes (we might be typefinding the first buffer
93 * of the stream and not have as much data available as we'd like) */
94 len = gst_type_find_get_length (tf);
96 len = CLAMP (len - c->offset, min_len, chunk_len);
101 data = gst_type_find_peek (tf, c->offset, len);
111 static inline gboolean
112 data_scan_ctx_memcmp (GstTypeFind * tf, DataScanCtx * c, guint offset,
113 const gchar * data, guint len)
115 if (G_UNLIKELY (offset + len >= G_MAXUINT32))
118 if (!data_scan_ctx_ensure_data (tf, c, offset + len))
121 return (memcmp (c->data + offset, data, len) == 0);
125 static gboolean xml_check_first_element (GstTypeFind * tf,
126 const gchar * element, guint elen, gboolean strict);
127 static gboolean sdp_check_header (GstTypeFind * tf);
129 static GstStaticCaps utf8_caps = GST_STATIC_CAPS ("text/plain");
131 #define UTF8_CAPS gst_static_caps_get(&utf8_caps)
134 utf8_type_find_have_valid_utf8_at_offset (GstTypeFind * tf, guint64 offset,
135 GstTypeFindProbability * prob)
139 /* randomly decided values */
140 guint min_size = 16; /* minimum size */
141 guint size = 32 * 1024; /* starting size */
142 guint probability = 95; /* starting probability */
143 guint step = 10; /* how much we reduce probability in each
146 while (probability > step && size > min_size) {
147 data = gst_type_find_peek (tf, offset, size);
150 gchar *start = (gchar *) data;
152 if (g_utf8_validate (start, size, (const gchar **) &end) || (end - start + 4 > size)) { /* allow last char to be cut off */
167 utf8_type_find (GstTypeFind * tf, gpointer unused)
169 GstTypeFindProbability start_prob, mid_prob;
172 /* leave xml to the xml typefinders */
173 if (xml_check_first_element (tf, "", 0, TRUE))
176 /* leave sdp to the sdp typefinders */
177 if (sdp_check_header (tf))
180 /* check beginning of stream */
181 if (!utf8_type_find_have_valid_utf8_at_offset (tf, 0, &start_prob))
184 GST_LOG ("start is plain text with probability of %u", start_prob);
186 /* POSSIBLE is the highest probability we ever return if we can't
187 * probe into the middle of the file and don't know its length */
189 length = gst_type_find_get_length (tf);
190 if (length == 0 || length == (guint64) - 1) {
191 gst_type_find_suggest (tf, MIN (start_prob, GST_TYPE_FIND_POSSIBLE),
196 if (length < 64 * 1024) {
197 gst_type_find_suggest (tf, start_prob, UTF8_CAPS);
201 /* check middle of stream */
202 if (!utf8_type_find_have_valid_utf8_at_offset (tf, length / 2, &mid_prob))
205 GST_LOG ("middle is plain text with probability of %u", mid_prob);
206 gst_type_find_suggest (tf, (start_prob + mid_prob) / 2, UTF8_CAPS);
209 /*** text/utf-16 and text/utf-32} ***/
210 /* While UTF-8 is unicode too, using text/plain for UTF-16 and UTF-32
211 is going to break stuff. */
216 const char *const bom;
217 gboolean (*checker) (const guint8 *, gint, gint);
223 check_utf16 (const guint8 * data, gint len, gint endianness)
233 gst_byte_reader_init (&br, data, len);
235 /* test first for a single 16 bit value in the BMP */
236 if (endianness == G_BIG_ENDIAN)
237 high = gst_byte_reader_get_uint16_be_unchecked (&br);
239 high = gst_byte_reader_get_uint16_le_unchecked (&br);
240 if (high >= 0xD800 && high <= 0xDBFF) {
241 /* start of a surrogate pair */
245 if (endianness == G_BIG_ENDIAN)
246 low = gst_byte_reader_get_uint16_be_unchecked (&br);
248 low = gst_byte_reader_get_uint16_le_unchecked (&br);
249 if (low >= 0xDC00 && low <= 0xDFFF) {
250 /* second half of the surrogate pair */
254 if (high >= 0xDC00 && high <= 0xDFFF)
263 check_utf32 (const guint8 * data, gint len, gint endianness)
269 if (endianness == G_BIG_ENDIAN)
270 v = GST_READ_UINT32_BE (data);
272 v = GST_READ_UINT32_LE (data);
282 unicode_type_find (GstTypeFind * tf, const GstUnicodeTester * tester,
283 guint n_tester, const char *media_type, gboolean require_bom)
287 const guint8 *data = gst_type_find_peek (tf, 0, len);
289 const gint max_scan_size = 256 * 1024;
294 data = gst_type_find_peek (tf, 0, len);
299 /* find a large enough size that works */
300 while (len < max_scan_size) {
301 size_t newlen = len << 1;
302 const guint8 *newdata = gst_type_find_peek (tf, 0, newlen);
309 for (n = 0; n < n_tester; ++n) {
310 int bom_boost = 0, tmpprob;
311 if (len >= tester[n].bomlen) {
312 if (!memcmp (data, tester[n].bom, tester[n].bomlen))
313 bom_boost = tester[n].boost;
315 if (require_bom && bom_boost == 0)
317 if (!(*tester[n].checker) (data, len, tester[n].endianness))
319 tmpprob = GST_TYPE_FIND_POSSIBLE - 20 + bom_boost;
320 if (tmpprob > prob) {
322 endianness = tester[n].endianness;
327 GST_DEBUG ("This is valid %s %s", media_type,
328 endianness == G_BIG_ENDIAN ? "be" : "le");
329 gst_type_find_suggest_simple (tf, prob, media_type,
330 "endianness", G_TYPE_INT, endianness, NULL);
334 static GstStaticCaps utf16_caps = GST_STATIC_CAPS ("text/utf-16");
336 #define UTF16_CAPS gst_static_caps_get(&utf16_caps)
339 utf16_type_find (GstTypeFind * tf, gpointer unused)
341 static const GstUnicodeTester utf16tester[2] = {
342 {2, "\xff\xfe", check_utf16, 10, G_LITTLE_ENDIAN},
343 {2, "\xfe\xff", check_utf16, 20, G_BIG_ENDIAN},
345 unicode_type_find (tf, utf16tester, G_N_ELEMENTS (utf16tester),
346 "text/utf-16", TRUE);
349 static GstStaticCaps utf32_caps = GST_STATIC_CAPS ("text/utf-32");
351 #define UTF32_CAPS gst_static_caps_get(&utf32_caps)
354 utf32_type_find (GstTypeFind * tf, gpointer unused)
356 static const GstUnicodeTester utf32tester[2] = {
357 {4, "\xff\xfe\x00\x00", check_utf32, 10, G_LITTLE_ENDIAN},
358 {4, "\x00\x00\xfe\xff", check_utf32, 20, G_BIG_ENDIAN}
360 unicode_type_find (tf, utf32tester, G_N_ELEMENTS (utf32tester),
361 "text/utf-32", TRUE);
364 /*** text/uri-list ***/
365 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
366 static GstStaticCaps uri_caps = GST_STATIC_CAPS ("text/uri-list");
368 #define URI_CAPS (gst_static_caps_get(&uri_caps))
369 #define BUFFER_SIZE 16 /* If the string is < 16 bytes we're screwed */
370 #define INC_BUFFER { \
372 if (pos == BUFFER_SIZE) { \
374 offset += BUFFER_SIZE; \
375 data = gst_type_find_peek (tf, offset, BUFFER_SIZE); \
376 if (data == NULL) return; \
383 uri_type_find (GstTypeFind * tf, gpointer unused)
385 const guint8 *data = gst_type_find_peek (tf, 0, BUFFER_SIZE);
390 /* Search for # comment lines */
391 while (*data == '#') {
392 /* Goto end of line */
393 while (*data != '\n') {
400 if (!g_ascii_isalpha (*data)) {
401 /* Had a non alpha char - can't be uri-list */
407 while (g_ascii_isalnum (*data)) {
412 /* First non alpha char is not a : */
416 /* Get the next 2 bytes as well */
417 data = gst_type_find_peek (tf, offset + pos, 3);
421 if (data[1] != '/' && data[2] != '/') {
425 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, URI_CAPS);
430 /*** application/itc ***/
431 static GstStaticCaps itc_caps = GST_STATIC_CAPS ("application/itc");
432 #define ITC_CAPS (gst_static_caps_get(&itc_caps))
435 itc_type_find (GstTypeFind * tf, gpointer unused)
437 DataScanCtx c = { 0, NULL, 0 };
438 guint8 magic[8] = { 0x00, 0x00, 0x01, 0x1C, 0x69, 0x74, 0x63, 0x68 };
439 guint8 preamble[4] = { 0x00, 0x00, 0x00, 0x02 };
440 guint8 artwork_marker[8] = { 0x00, 0x00, 0x00, 0x00, 0x61, 0x72, 0x74, 0x77 };
441 guint8 item_marker[4] = { 0x69, 0x74, 0x65, 0x6D };
442 GstTypeFindProbability itc_prob = GST_TYPE_FIND_NONE;
445 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 8)))
448 if (memcmp (c.data, magic, 8))
451 /* At least we found the right magic */
452 itc_prob = GST_TYPE_FIND_MINIMUM;
453 data_scan_ctx_advance (tf, &c, 8);
455 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
458 /* Check preamble 3 consecutive times */
459 for (i = 0; i < 3; i++) {
460 if (memcmp (c.data, preamble, 4))
462 data_scan_ctx_advance (tf, &c, 4);
465 itc_prob = GST_TYPE_FIND_POSSIBLE;
467 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 8)))
470 if (memcmp (c.data, artwork_marker, 8))
473 itc_prob = GST_TYPE_FIND_LIKELY;
474 data_scan_ctx_advance (tf, &c, 8);
476 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 256)))
479 /* ...and 256 0x00 padding bytes on what looks like the header's end */
480 for (i = 0; i < 256; i++) {
485 itc_prob = GST_TYPE_FIND_NEARLY_CERTAIN;
486 data_scan_ctx_advance (tf, &c, 256);
488 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 8)))
491 if (memcmp (c.data + 4, item_marker, 4))
494 itc_prob = GST_TYPE_FIND_MAXIMUM;
497 gst_type_find_suggest (tf, itc_prob, ITC_CAPS);
500 /*** application/x-hls ***/
502 static GstStaticCaps hls_caps = GST_STATIC_CAPS ("application/x-hls");
503 #define HLS_CAPS (gst_static_caps_get(&hls_caps))
505 /* See http://tools.ietf.org/html/draft-pantos-http-live-streaming-05 */
507 hls_type_find (GstTypeFind * tf, gpointer unused)
509 DataScanCtx c = { 0, NULL, 0 };
511 /* Minimum useful size is #EXTM3U\n + 1 tag + ':' = 30 bytes */
512 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 30)))
515 if (memcmp (c.data, "#EXTM3U", 7))
518 data_scan_ctx_advance (tf, &c, 7);
520 /* Check only the first 4KB */
521 while (c.offset < 4096) {
522 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 21)))
525 /* Search for # comment lines */
526 if (c.data[0] == '#' && (memcmp (c.data, "#EXT-X-TARGETDURATION", 21) == 0
527 || memcmp (c.data, "#EXT-X-STREAM-INF", 17) == 0
528 || memcmp (c.data, "#EXT-X-MEDIA", 12) == 0)) {
529 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HLS_CAPS);
533 data_scan_ctx_advance (tf, &c, 1);
538 /*** application/xml **********************************************************/
540 #define XML_BUFFER_SIZE 16
541 #define XML_INC_BUFFER { \
543 if (pos == XML_BUFFER_SIZE) { \
545 offset += XML_BUFFER_SIZE; \
546 data = gst_type_find_peek (tf, offset, XML_BUFFER_SIZE); \
547 if (data == NULL) return FALSE; \
553 #define XML_INC_BUFFER_DATA { \
555 if (pos >= length) { \
563 xml_check_first_element_from_data (const guint8 * data, guint length,
564 const gchar * element, guint elen, gboolean strict)
569 g_return_val_if_fail (data != NULL, FALSE);
574 /* look for the XMLDec
575 * see XML spec 2.8, Prolog and Document Type Declaration
576 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
577 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
579 if (strict && !got_xmldec)
582 /* skip XMLDec in any case if we've got one */
588 /* look for the first element, it has to be the requested element. Bail
589 * out if it is not within the first 4kB. */
590 while (pos < MIN (4096, length)) {
591 while (*data != '<' && pos < MIN (4096, length)) {
596 if (!g_ascii_isalpha (*data)) {
597 /* if not alphabetic, it's a PI or an element / attribute declaration
598 * like <?xxx or <!xxx */
603 /* the first normal element, check if it's the one asked for */
604 if (pos + elen + 1 >= length)
606 return (element && strncmp ((const char *) data, element, elen) == 0);
613 xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen,
621 data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE);
625 /* look for the XMLDec
626 * see XML spec 2.8, Prolog and Document Type Declaration
627 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
628 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
630 if (strict && !got_xmldec)
633 /* skip XMLDec in any case if we've got one */
639 /* look for the first element, it has to be the requested element. Bail
640 * out if it is not within the first 4kB. */
641 while (data && (offset + pos) < 4096) {
642 while (*data != '<' && (offset + pos) < 4096) {
647 if (!g_ascii_isalpha (*data)) {
648 /* if not alphabetic, it's a PI or an element / attribute declaration
649 * like <?xxx or <!xxx */
654 /* the first normal element, check if it's the one asked for */
655 data = gst_type_find_peek (tf, offset + pos, elen + 1);
656 return (data && element && strncmp ((char *) data, element, elen) == 0);
662 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
663 static GstStaticCaps generic_xml_caps = GST_STATIC_CAPS ("application/xml");
665 #define GENERIC_XML_CAPS (gst_static_caps_get(&generic_xml_caps))
667 xml_type_find (GstTypeFind * tf, gpointer unused)
669 if (xml_check_first_element (tf, "", 0, TRUE)) {
670 gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, GENERIC_XML_CAPS);
674 /*** application/dash+xml ****************************************************/
676 static GstStaticCaps dash_caps = GST_STATIC_CAPS ("application/dash+xml");
678 #define DASH_CAPS gst_static_caps_get (&dash_caps)
681 dash_mpd_type_find (GstTypeFind * tf, gpointer unused)
683 if (xml_check_first_element (tf, "MPD", 3, FALSE) ||
684 xml_check_first_element (tf, "mpd", 3, FALSE)) {
685 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DASH_CAPS);
689 /*** application/xges ****************************************************/
691 static GstStaticCaps xges_caps = GST_STATIC_CAPS ("application/xges");
693 #define XGES_CAPS gst_static_caps_get (&xges_caps)
696 xges_type_find (GstTypeFind * tf, gpointer unused)
698 if (xml_check_first_element (tf, "ges", 3, FALSE)) {
699 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, XGES_CAPS);
704 /*** application/sdp *********************************************************/
706 static GstStaticCaps sdp_caps = GST_STATIC_CAPS ("application/sdp");
708 #define SDP_CAPS (gst_static_caps_get(&sdp_caps))
710 sdp_check_header (GstTypeFind * tf)
714 data = gst_type_find_peek (tf, 0, 5);
718 /* sdp must start with v=0[\r]\n */
719 if (memcmp (data, "v=0", 3))
722 if (data[3] == '\r' && data[4] == '\n')
731 sdp_type_find (GstTypeFind * tf, gpointer unused)
733 if (sdp_check_header (tf))
734 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDP_CAPS);
737 /*** application/smil *********************************************************/
738 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
739 static GstStaticCaps smil_caps = GST_STATIC_CAPS ("application/smil");
741 #define SMIL_CAPS (gst_static_caps_get(&smil_caps))
743 smil_type_find (GstTypeFind * tf, gpointer unused)
745 if (xml_check_first_element (tf, "smil", 4, FALSE)) {
746 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SMIL_CAPS);
750 /*** application/ttml+xml *****************************************************/
752 static GstStaticCaps ttml_xml_caps = GST_STATIC_CAPS ("application/ttml+xml");
754 #define TTML_XML_CAPS (gst_static_caps_get(&ttml_xml_caps))
756 ttml_xml_type_find (GstTypeFind * tf, gpointer unused)
758 if (xml_check_first_element (tf, "tt", 2, FALSE)) {
759 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTML_XML_CAPS);
765 static GstStaticCaps html_caps = GST_STATIC_CAPS ("text/html");
767 #define HTML_CAPS gst_static_caps_get (&html_caps)
770 html_type_find (GstTypeFind * tf, gpointer unused)
772 const gchar *d, *data;
774 data = (const gchar *) gst_type_find_peek (tf, 0, 16);
778 if (!g_ascii_strncasecmp (data, "<!DOCTYPE HTML", 14)) {
779 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
780 } else if (xml_check_first_element (tf, "html", 4, FALSE)) {
781 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
782 } else if ((d = memchr (data, '<', 16))) {
783 data = (const gchar *) gst_type_find_peek (tf, d - data, 6);
784 if (data && g_ascii_strncasecmp (data, "<html>", 6) == 0) {
785 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
792 static GstStaticCaps mid_caps = GST_STATIC_CAPS ("audio/midi");
794 #define MID_CAPS gst_static_caps_get(&mid_caps)
796 mid_type_find (GstTypeFind * tf, gpointer unused)
798 const guint8 *data = gst_type_find_peek (tf, 0, 4);
800 /* http://jedi.ks.uiuc.edu/~johns/links/music/midifile.html */
801 if (data && data[0] == 'M' && data[1] == 'T' && data[2] == 'h'
803 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MID_CAPS);
806 /*** audio/mobile-xmf ***/
808 static GstStaticCaps mxmf_caps = GST_STATIC_CAPS ("audio/mobile-xmf");
810 #define MXMF_CAPS gst_static_caps_get(&mxmf_caps)
812 mxmf_type_find (GstTypeFind * tf, gpointer unused)
814 const guint8 *data = NULL;
816 /* Search FileId "XMF_" 4 bytes */
817 data = gst_type_find_peek (tf, 0, 4);
818 if (data && data[0] == 'X' && data[1] == 'M' && data[2] == 'F'
820 /* Search Format version "2.00" 4 bytes */
821 data = gst_type_find_peek (tf, 4, 4);
822 if (data && data[0] == '2' && data[1] == '.' && data[2] == '0'
824 /* Search TypeId 2 1 byte */
825 data = gst_type_find_peek (tf, 11, 1);
826 if (data && data[0] == 2) {
827 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXMF_CAPS);
834 /*** video/x-fli ***/
835 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
836 static GstStaticCaps flx_caps = GST_STATIC_CAPS ("video/x-fli");
838 #define FLX_CAPS gst_static_caps_get(&flx_caps)
840 flx_type_find (GstTypeFind * tf, gpointer unused)
842 const guint8 *data = gst_type_find_peek (tf, 0, 134);
845 /* check magic and the frame type of the first frame */
846 if ((data[4] == 0x11 || data[4] == 0x12 ||
847 data[4] == 0x30 || data[4] == 0x44) &&
849 ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1)) {
850 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLX_CAPS);
854 data = gst_type_find_peek (tf, 0, 6);
856 /* check magic only */
857 if ((data[4] == 0x11 || data[4] == 0x12 ||
858 data[4] == 0x30 || data[4] == 0x44) && data[5] == 0xaf) {
859 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, FLX_CAPS);
865 /*** application/x-id3 ***/
867 static GstStaticCaps id3_caps = GST_STATIC_CAPS ("application/x-id3");
869 #define ID3_CAPS gst_static_caps_get(&id3_caps)
871 id3v2_type_find (GstTypeFind * tf, gpointer unused)
873 const guint8 *data = gst_type_find_peek (tf, 0, 10);
875 if (data && memcmp (data, "ID3", 3) == 0 &&
876 data[3] != 0xFF && data[4] != 0xFF &&
877 (data[6] & 0x80) == 0 && (data[7] & 0x80) == 0 &&
878 (data[8] & 0x80) == 0 && (data[9] & 0x80) == 0) {
879 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
884 id3v1_type_find (GstTypeFind * tf, gpointer unused)
886 const guint8 *data = gst_type_find_peek (tf, -128, 3);
888 if (data && memcmp (data, "TAG", 3) == 0) {
889 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
893 /*** application/x-ape ***/
895 static GstStaticCaps apetag_caps = GST_STATIC_CAPS ("application/x-apetag");
897 #define APETAG_CAPS gst_static_caps_get(&apetag_caps)
899 apetag_type_find (GstTypeFind * tf, gpointer unused)
903 /* APEv1/2 at start of file */
904 data = gst_type_find_peek (tf, 0, 8);
905 if (data && !memcmp (data, "APETAGEX", 8)) {
906 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
910 /* APEv1/2 at end of file */
911 data = gst_type_find_peek (tf, -32, 8);
912 if (data && !memcmp (data, "APETAGEX", 8)) {
913 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
918 /*** audio/x-ttafile ***/
919 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
920 static GstStaticCaps tta_caps = GST_STATIC_CAPS ("audio/x-ttafile");
922 #define TTA_CAPS gst_static_caps_get(&tta_caps)
924 tta_type_find (GstTypeFind * tf, gpointer unused)
926 const guint8 *data = gst_type_find_peek (tf, 0, 3);
929 if (memcmp (data, "TTA", 3) == 0) {
930 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTA_CAPS);
936 /*** audio/x-flac ***/
937 static GstStaticCaps flac_caps = GST_STATIC_CAPS ("audio/x-flac");
939 #define FLAC_CAPS (gst_static_caps_get(&flac_caps))
942 flac_type_find (GstTypeFind * tf, gpointer unused)
944 DataScanCtx c = { 0, NULL, 0 };
946 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
949 /* standard flac (also old/broken flac-in-ogg with an initial 4-byte marker
950 * packet and without the usual packet framing) */
951 if (memcmp (c.data, "fLaC", 4) == 0) {
952 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
956 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
959 /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */
960 if (memcmp (c.data, "\177FLAC\001", 6) == 0) {
961 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
965 /* disabled because it happily typefinds /dev/urandom as audio/x-flac, and
966 * because I yet have to see header-less flac in the wild */
968 /* flac without headers (subset format) */
969 /* 64K should be enough */
970 while (c.offset < (64 * 1024)) {
971 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
974 /* look for frame header,
975 * http://flac.sourceforge.net/format.html#frame_header
977 if (c.data[0] == 0xff && (c.data[1] >> 2) == 0x3e) {
978 /* bit 15 in the header must be 0 */
979 if (((c.data[1] >> 1) & 0x01) == 0x01)
982 /* blocksize must be != 0x00 */
983 if ((c.data[2] >> 4) == 0x00)
986 /* samplerate must be != 0x0f */
987 if ((c.data[2] & 0x0f) == 0x0f)
989 /* also 0 is invalid, as it means get the info from the header and we
990 * don't have headers if we are here */
991 if ((c.data[2] & 0x0f) == 0x00)
994 /* channel assignment must be < 11 */
995 if ((c.data[3] >> 4) >= 11)
998 /* sample size must be != 0x07 and != 0x05 */
999 if (((c.data[3] >> 1) & 0x07) == 0x07)
1001 if (((c.data[3] >> 1) & 0x07) == 0x05)
1003 /* also 0 is invalid, as it means get the info from the header and we
1004 * don't have headers if we are here */
1005 if (((c.data[3] >> 1) & 0x07) == 0x00)
1008 /* next bit must be 0 */
1009 if ((c.data[3] & 0x01) == 0x01)
1012 /* FIXME: shouldn't we include the crc check ? */
1014 GST_DEBUG ("Found flac without headers at %d", (gint) c.offset);
1015 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, FLAC_CAPS);
1019 data_scan_ctx_advance (tf, &c, 1);
1024 /* TODO: we could probably make a generic function for this.. */
1026 aac_type_find_scan_loas_frames_ep (GstTypeFind * tf, DataScanCtx * scan_ctx,
1029 DataScanCtx c = *scan_ctx;
1035 if (!data_scan_ctx_ensure_data (tf, &c, 5))
1038 /* EPAudioSyncStream */
1039 len = ((c.data[2] & 0x0f) << 9) | (c.data[3] << 1) |
1040 ((c.data[4] & 0x80) >> 7);
1042 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
1043 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
1047 /* check length of frame */
1048 snc = GST_READ_UINT16_BE (c.data + len);
1049 if (snc != 0x4de1) {
1050 GST_DEBUG ("No sync found at 0x%" G_GINT64_MODIFIER "x", c.offset + len);
1056 GST_DEBUG ("Found LOAS syncword #%d at offset 0x%" G_GINT64_MODIFIER "x, "
1057 "framelen %u", count, c.offset, len);
1059 data_scan_ctx_advance (tf, &c, len);
1060 } while (count < max_frames && (c.offset - scan_ctx->offset) < 64 * 1024);
1062 GST_DEBUG ("found %d consecutive frames", count);
1067 aac_type_find_scan_loas_frames (GstTypeFind * tf, DataScanCtx * scan_ctx,
1070 DataScanCtx c = *scan_ctx;
1076 if (!data_scan_ctx_ensure_data (tf, &c, 3))
1079 /* AudioSyncStream */
1080 len = ((c.data[1] & 0x1f) << 8) | c.data[2];
1081 /* add size of sync stream header */
1084 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
1085 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
1089 /* check length of frame */
1090 snc = GST_READ_UINT16_BE (c.data + len);
1091 if ((snc & 0xffe0) != 0x56e0) {
1092 GST_DEBUG ("No sync found at 0x%" G_GINT64_MODIFIER "x", c.offset + len);
1098 GST_DEBUG ("Found LOAS syncword #%d at offset 0x%" G_GINT64_MODIFIER "x, "
1099 "framelen %u", count, c.offset, len);
1101 data_scan_ctx_advance (tf, &c, len);
1102 } while (count < max_frames && (c.offset - scan_ctx->offset) < 64 * 1024);
1104 GST_DEBUG ("found %d consecutive frames", count);
1108 /*** audio/mpeg version 2, 4 ***/
1110 static GstStaticCaps aac_caps = GST_STATIC_CAPS ("audio/mpeg, "
1111 "mpegversion = (int) { 2, 4 }, framed = (bool) false");
1112 #define AAC_CAPS (gst_static_caps_get(&aac_caps))
1113 #define AAC_AMOUNT (4096)
1115 aac_type_find (GstTypeFind * tf, gpointer unused)
1117 DataScanCtx c = { 0, NULL, 0 };
1118 GstTypeFindProbability best_probability = GST_TYPE_FIND_NONE;
1119 GstCaps *best_caps = NULL;
1120 gint best_count = 0;
1122 while (c.offset < AAC_AMOUNT) {
1123 guint snc, len, offset, i;
1125 /* detect adts header or adif header.
1126 * The ADIF header is 4 bytes, that should be OK. The ADTS header, on
1127 * the other hand, is 14 bits only, so we require one valid frame with
1128 * again a valid syncpoint on the next one (28 bits) for certainty. We
1129 * require 4 kB, which is quite a lot, since frames are generally 200-400
1131 * LOAS has 2 possible syncwords, which are 11 bits and 16 bits long.
1132 * The following stream syntax depends on which one is found.
1134 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
1137 snc = GST_READ_UINT16_BE (c.data);
1138 if (G_UNLIKELY ((snc & 0xfff6) == 0xfff0)) {
1139 /* ADTS header - find frame length */
1140 GST_DEBUG ("Found one ADTS syncpoint at offset 0x%" G_GINT64_MODIFIER
1141 "x, tracing next...", c.offset);
1142 len = ((c.data[3] & 0x03) << 11) |
1143 (c.data[4] << 3) | ((c.data[5] & 0xe0) >> 5);
1145 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 6)) {
1146 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
1151 /* check if there's a second ADTS frame */
1152 snc = GST_READ_UINT16_BE (c.data + offset);
1153 if ((snc & 0xfff6) == 0xfff0) {
1155 guint mpegversion, sample_freq_idx, channel_config, profile_idx, rate;
1156 guint8 audio_config[2];
1158 mpegversion = (c.data[1] & 0x08) ? 2 : 4;
1159 profile_idx = c.data[2] >> 6;
1160 sample_freq_idx = ((c.data[2] & 0x3c) >> 2);
1161 channel_config = ((c.data[2] & 0x01) << 2) + (c.data[3] >> 6);
1163 GST_DEBUG ("Found second ADTS-%d syncpoint at offset 0x%"
1164 G_GINT64_MODIFIER "x, framelen %u", mpegversion, c.offset, len);
1166 /* 0xd and 0xe are reserved. 0xf means the sample frequency is directly
1167 * specified in the header, but that's not allowed for ADTS */
1168 if (sample_freq_idx > 0xc) {
1169 GST_DEBUG ("Unexpected sample frequency index %d or wrong sync",
1174 rate = gst_codec_utils_aac_get_sample_rate_from_index (sample_freq_idx);
1175 GST_LOG ("ADTS: profile=%u, rate=%u", profile_idx, rate);
1177 /* The ADTS frame header is slightly different from the
1178 * AudioSpecificConfig defined for the MPEG-4 container, so we just
1179 * construct enough of it for getting the level here. */
1180 /* ADTS counts profiles from 0 instead of 1 to save bits */
1181 audio_config[0] = (profile_idx + 1) << 3;
1182 audio_config[0] |= (sample_freq_idx >> 1) & 0x7;
1183 audio_config[1] = (sample_freq_idx & 0x1) << 7;
1184 audio_config[1] |= (channel_config & 0xf) << 3;
1186 caps = gst_caps_new_simple ("audio/mpeg",
1187 "framed", G_TYPE_BOOLEAN, FALSE,
1188 "mpegversion", G_TYPE_INT, mpegversion,
1189 "stream-format", G_TYPE_STRING, "adts", NULL);
1191 gst_codec_utils_aac_caps_set_level_and_profile (caps, audio_config, 2);
1193 /* add rate and number of channels if we can */
1194 if (channel_config != 0 && channel_config <= 7) {
1195 const guint channels_map[] = { 0, 1, 2, 3, 4, 5, 6, 8 };
1197 gst_caps_set_simple (caps, "channels", G_TYPE_INT,
1198 channels_map[channel_config], "rate", G_TYPE_INT, rate, NULL);
1201 /* length of the second ADTS frame */
1202 len = ((c.data[offset + 3] & 0x03) << 11) |
1203 (c.data[offset + 4] << 3) | ((c.data[offset + 5] & 0xe0) >> 5);
1205 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, offset + len + 6)) {
1206 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
1207 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, caps);
1210 /* find more aac sync to select correctly */
1211 /* check if there's a third/fourth/fifth/sixth ADTS frame, if there is a sixth frame, set probability to maximum:100% */
1212 for (i = 3; i <= 6; i++) {
1213 len = ((c.data[offset + 3] & 0x03) << 11) |
1214 (c.data[offset + 4] << 3) | ((c.data[offset + 5] & 0xe0) >> 5);
1216 || !data_scan_ctx_ensure_data (tf, &c, offset + len + 6)) {
1217 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u",
1221 snc = GST_READ_UINT16_BE (c.data + offset);
1222 if ((snc & 0xfff6) == 0xfff0) {
1223 GST_DEBUG ("Find %und Sync..probability is %u ", i,
1224 GST_TYPE_FIND_LIKELY + 5 * (i - 2));
1230 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 5 * (i - 3), caps);
1233 gst_caps_unref (caps);
1237 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
1238 } else if (G_UNLIKELY ((snc & 0xffe0) == 0x56e0 || snc == 0x4de1)) {
1242 GST_INFO ("Possible LOAS syncword at offset 0x%" G_GINT64_MODIFIER
1243 "x, scanning for more frames...", c.offset);
1246 count = aac_type_find_scan_loas_frames_ep (tf, &c, 20);
1248 count = aac_type_find_scan_loas_frames (tf, &c, 20);
1250 if (count >= 3 && count > best_count) {
1251 gst_caps_replace (&best_caps, NULL);
1252 best_caps = gst_caps_new_simple ("audio/mpeg",
1253 "framed", G_TYPE_BOOLEAN, FALSE,
1254 "mpegversion", G_TYPE_INT, 4,
1255 "stream-format", G_TYPE_STRING, "loas", NULL);
1257 best_probability = GST_TYPE_FIND_POSSIBLE - 10 + count * 3;
1258 if (best_probability >= GST_TYPE_FIND_LIKELY)
1261 } else if (!memcmp (c.data, "ADIF", 4)) {
1263 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
1264 "framed", G_TYPE_BOOLEAN, FALSE, "mpegversion", G_TYPE_INT, 4,
1265 "stream-format", G_TYPE_STRING, "adif", NULL);
1271 data_scan_ctx_advance (tf, &c, 1);
1274 if (best_probability > GST_TYPE_FIND_NONE) {
1275 gst_type_find_suggest (tf, best_probability, best_caps);
1276 gst_caps_unref (best_caps);
1280 /*** audio/mpeg version 1 ***/
1283 * The chance that random data is identified as a valid mp3 header is 63 / 2^18
1284 * (0.024%) per try. This makes the function for calculating false positives
1285 * 1 - (1 - ((63 / 2 ^18) ^ GST_MP3_TYPEFIND_MIN_HEADERS)) ^ buffersize)
1286 * This has the following probabilities of false positives:
1287 * datasize MIN_HEADERS
1289 * 4096 62.6% 0.02% 0% 0%
1290 * 16384 98% 0.09% 0% 0%
1291 * 1 MiB 100% 5.88% 0% 0%
1292 * 1 GiB 100% 100% 1.44% 0%
1293 * 1 TiB 100% 100% 100% 0.35%
1294 * This means that the current choice (3 headers by most of the time 4096 byte
1295 * buffers is pretty safe for now.
1297 * The max. size of each frame is 1440 bytes, which means that for N frames to
1298 * be detected, we need 1440 * GST_MP3_TYPEFIND_MIN_HEADERS + 3 bytes of data.
1299 * Assuming we step into the stream right after the frame header, this
1300 * means we need 1440 * (GST_MP3_TYPEFIND_MIN_HEADERS + 1) - 1 + 3 bytes
1301 * of data (5762) to always detect any mp3.
1304 static const guint mp3types_bitrates[2][3][16] =
1305 { {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
1306 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
1307 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
1308 {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
1309 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
1310 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}},
1313 static const guint mp3types_freqs[3][3] = { {11025, 12000, 8000},
1314 {22050, 24000, 16000},
1315 {44100, 48000, 32000}
1319 mp3_type_frame_length_from_header (guint32 header, guint * put_layer,
1320 guint * put_channels, guint * put_bitrate, guint * put_samplerate,
1321 gboolean * may_be_free_format, gint possible_free_framelen)
1323 guint bitrate, layer, length, mode, samplerate, version, channels;
1325 if ((header & 0xffe00000) != 0xffe00000)
1328 /* we don't need extension, copyright, original or
1329 * emphasis for the frame length */
1333 mode = header & 0x3;
1337 length = header & 0x1;
1340 /* sampling frequency */
1341 samplerate = header & 0x3;
1342 if (samplerate == 3)
1347 bitrate = header & 0xF;
1348 if (bitrate == 0 && possible_free_framelen == -1) {
1349 GST_LOG ("Possibly a free format mp3 - signaling");
1350 *may_be_free_format = TRUE;
1352 if (bitrate == 15 || (bitrate == 0 && possible_free_framelen == -1))
1355 /* ignore error correction, too */
1359 layer = 4 - (header & 0x3);
1364 /* version 0=MPEG2.5; 2=MPEG2; 3=MPEG1 */
1365 version = header & 0x3;
1370 channels = (mode == 3) ? 1 : 2;
1371 samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate];
1373 /* possible freeform mp3 */
1376 length += possible_free_framelen;
1377 bitrate = length * samplerate / 48000;
1379 length += possible_free_framelen;
1380 bitrate = length * samplerate /
1381 ((layer == 3 && version != 3) ? 72000 : 144000);
1383 /* freeform mp3 should have a higher-than-usually-allowed bitrate */
1384 GST_LOG ("calculated bitrate: %u, max usually: %u", bitrate,
1385 mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][14]);
1386 if (bitrate < mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][14])
1390 bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate];
1392 length = ((12000 * bitrate / samplerate) + length) * 4;
1394 length += ((layer == 3
1395 && version != 3) ? 72000 : 144000) * bitrate / samplerate;
1399 GST_LOG ("mp3typefind: calculated mp3 frame length of %u bytes", length);
1401 ("mp3typefind: samplerate = %u - bitrate = %u - layer = %u - version = %u"
1402 " - channels = %u", samplerate, bitrate, layer, version, channels);
1407 *put_channels = channels;
1409 *put_bitrate = bitrate;
1411 *put_samplerate = samplerate;
1417 static GstStaticCaps mp3_caps = GST_STATIC_CAPS ("audio/mpeg, "
1418 "mpegversion = (int) 1, layer = (int) [ 1, 3 ]");
1419 #define MP3_CAPS (gst_static_caps_get(&mp3_caps))
1421 * random values for typefinding
1422 * if no more data is available, we will return a probability of
1423 * (found_headers/TRY_HEADERS) * (MAXIMUM * (TRY_SYNC - bytes_skipped)
1425 * if found_headers >= MIN_HEADERS
1427 #define GST_MP3_TYPEFIND_MIN_HEADERS (2)
1428 #define GST_MP3_TYPEFIND_TRY_HEADERS (5)
1429 #define GST_MP3_TYPEFIND_TRY_SYNC (GST_TYPE_FIND_MAXIMUM * 100) /* 10kB */
1430 #define GST_MP3_TYPEFIND_SYNC_SIZE (2048)
1431 #define GST_MP3_WRONG_HEADER (10)
1434 mp3_type_find_at_offset (GstTypeFind * tf, guint64 start_off,
1435 guint * found_layer, GstTypeFindProbability * found_prob)
1437 const guint8 *data = NULL;
1438 const guint8 *data_end = NULL;
1441 gint last_free_offset = -1;
1442 gint last_free_framelen = -1;
1443 gboolean headerstart = TRUE;
1450 while (skipped < GST_MP3_TYPEFIND_TRY_SYNC) {
1452 size = GST_MP3_TYPEFIND_SYNC_SIZE * 2;
1455 data = gst_type_find_peek (tf, skipped + start_off, size);
1456 } while (size > 10 && !data);
1459 data_end = data + size;
1461 if (*data == 0xFF) {
1462 const guint8 *head_data = NULL;
1463 guint layer = 0, bitrate, samplerate, channels;
1464 guint found = 0; /* number of valid headers found */
1465 guint64 offset = skipped;
1466 gboolean changed = FALSE;
1467 guint prev_layer = 0;
1468 guint prev_channels = 0, prev_samplerate = 0;
1470 while (found < GST_MP3_TYPEFIND_TRY_HEADERS) {
1473 gboolean free = FALSE;
1475 if ((gint64) (offset - skipped + 4) >= 0 &&
1476 data + offset - skipped + 4 < data_end) {
1477 head_data = data + offset - skipped;
1479 head_data = gst_type_find_peek (tf, offset + start_off, 4);
1483 head = GST_READ_UINT32_BE (head_data);
1484 if (!(length = mp3_type_frame_length_from_header (head, &layer,
1485 &channels, &bitrate, &samplerate, &free,
1486 last_free_framelen))) {
1488 if (last_free_offset == -1)
1489 last_free_offset = offset;
1491 last_free_framelen = offset - last_free_offset;
1492 offset = last_free_offset;
1496 last_free_framelen = -1;
1499 /* Mark the fact that we didn't find a valid header at the beginning */
1501 headerstart = FALSE;
1503 GST_LOG ("%d. header at offset %" G_GUINT64_FORMAT
1504 " (0x%" G_GINT64_MODIFIER "x) was not an mp3 header "
1505 "(possibly-free: %s)", found + 1, start_off + offset,
1506 start_off + offset, free ? "yes" : "no");
1509 if ((prev_layer && prev_layer != layer) ||
1510 /* (prev_bitrate && prev_bitrate != bitrate) || <-- VBR */
1511 (prev_samplerate && prev_samplerate != samplerate) ||
1512 (prev_channels && prev_channels != channels)) {
1513 /* this means an invalid property, or a change, which might mean
1514 * that this is not a mp3 but just a random bytestream. It could
1515 * be a freaking funky encoded mp3 though. We'll just not count
1521 GST_LOG ("found %d. header at offset %" G_GUINT64_FORMAT " (0x%"
1522 G_GINT64_MODIFIER "X)", found, start_off + offset,
1523 start_off + offset);
1526 prev_channels = channels;
1527 prev_samplerate = samplerate;
1531 g_assert (found <= GST_MP3_TYPEFIND_TRY_HEADERS);
1532 if (found != 0 && head_data == NULL &&
1533 gst_type_find_peek (tf, offset + start_off - 1, 1) == NULL)
1534 /* Incomplete last frame - don't count it. */
1536 if (found == GST_MP3_TYPEFIND_TRY_HEADERS ||
1537 (found >= GST_MP3_TYPEFIND_MIN_HEADERS && head_data == NULL)) {
1538 /* we can make a valid guess */
1539 guint probability = found * GST_TYPE_FIND_MAXIMUM *
1540 (GST_MP3_TYPEFIND_TRY_SYNC - skipped) /
1541 GST_MP3_TYPEFIND_TRY_HEADERS / GST_MP3_TYPEFIND_TRY_SYNC;
1544 && probability > (GST_TYPE_FIND_MINIMUM + GST_MP3_WRONG_HEADER))
1545 probability -= GST_MP3_WRONG_HEADER;
1546 if (probability < GST_TYPE_FIND_MINIMUM)
1547 probability = GST_TYPE_FIND_MINIMUM;
1551 probability = (probability + GST_TYPE_FIND_MAXIMUM) / 2;
1554 ("audio/mpeg calculated %u = %u * %u / %u * (%u - %"
1555 G_GUINT64_FORMAT ") / %u", probability, GST_TYPE_FIND_MAXIMUM,
1556 found, GST_MP3_TYPEFIND_TRY_HEADERS, GST_MP3_TYPEFIND_TRY_SYNC,
1557 (guint64) skipped, GST_MP3_TYPEFIND_TRY_SYNC);
1558 /* make sure we're not id3 tagged */
1559 head_data = gst_type_find_peek (tf, -128, 3);
1560 if (head_data && (memcmp (head_data, "TAG", 3) == 0)) {
1563 g_assert (probability <= GST_TYPE_FIND_MAXIMUM);
1565 *found_prob = probability;
1566 if (probability > 0)
1567 *found_layer = layer;
1578 mp3_type_find (GstTypeFind * tf, gpointer unused)
1580 GstTypeFindProbability prob, mid_prob;
1582 guint layer, mid_layer;
1585 mp3_type_find_at_offset (tf, 0, &layer, &prob);
1586 length = gst_type_find_get_length (tf);
1588 if (length == 0 || length == (guint64) - 1) {
1594 /* if we're pretty certain already, skip the additional check */
1595 if (prob >= GST_TYPE_FIND_LIKELY)
1598 mp3_type_find_at_offset (tf, length / 2, &mid_layer, &mid_prob);
1602 GST_LOG ("detected audio/mpeg only in the middle (p=%u)", mid_prob);
1608 if (layer != mid_layer) {
1609 GST_WARNING ("audio/mpeg layer discrepancy: %u vs. %u", layer, mid_layer);
1610 return; /* FIXME: or should we just go with the one in the middle? */
1613 /* detected mpeg audio both in middle of the file and at the start */
1614 prob = (prob + mid_prob) / 2;
1618 /* a valid header right at the start makes it more likely
1619 * that this is actually plain mpeg-1 audio */
1621 data = gst_type_find_peek (tf, 0, 4); /* use min. frame size? */
1622 if (data && mp3_type_frame_length_from_header (GST_READ_UINT32_BE (data),
1623 &layer, NULL, NULL, NULL, NULL, 0) != 0) {
1624 prob = MIN (prob + 10, GST_TYPE_FIND_MAXIMUM);
1635 g_return_if_fail (layer >= 1 && layer <= 3);
1637 gst_type_find_suggest_simple (tf, prob, "audio/mpeg",
1638 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, layer,
1639 "parsed", G_TYPE_BOOLEAN, FALSE, NULL);
1643 /*** audio/x-musepack ***/
1645 static GstStaticCaps musepack_caps =
1646 GST_STATIC_CAPS ("audio/x-musepack, streamversion= (int) { 7, 8 }");
1648 #define MUSEPACK_CAPS (gst_static_caps_get(&musepack_caps))
1650 musepack_type_find (GstTypeFind * tf, gpointer unused)
1652 const guint8 *data = gst_type_find_peek (tf, 0, 4);
1653 GstTypeFindProbability prop = GST_TYPE_FIND_MINIMUM;
1654 gint streamversion = -1;
1656 if (data && memcmp (data, "MP+", 3) == 0) {
1658 if ((data[3] & 0x7f) == 7) {
1659 prop = GST_TYPE_FIND_MAXIMUM;
1661 prop = GST_TYPE_FIND_LIKELY + 10;
1663 } else if (data && memcmp (data, "MPCK", 4) == 0) {
1665 prop = GST_TYPE_FIND_MAXIMUM;
1668 if (streamversion != -1) {
1669 gst_type_find_suggest_simple (tf, prop, "audio/x-musepack",
1670 "streamversion", G_TYPE_INT, streamversion, NULL);
1674 /*** audio/x-ac3 ***/
1675 /* FIXME 0.11: should be audio/ac3, but isn't for backwards compatibility */
1676 static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
1678 #define AC3_CAPS (gst_static_caps_get(&ac3_caps))
1680 static GstStaticCaps eac3_caps = GST_STATIC_CAPS ("audio/x-eac3");
1682 #define EAC3_CAPS (gst_static_caps_get(&eac3_caps))
1686 unsigned short bit_rate;
1687 unsigned short frm_size[3];
1690 static const struct ac3_frmsize ac3_frmsizecod_tbl[] = {
1693 {40, {80, 87, 120}},
1694 {40, {80, 88, 120}},
1695 {48, {96, 104, 144}},
1696 {48, {96, 105, 144}},
1697 {56, {112, 121, 168}},
1698 {56, {112, 122, 168}},
1699 {64, {128, 139, 192}},
1700 {64, {128, 140, 192}},
1701 {80, {160, 174, 240}},
1702 {80, {160, 175, 240}},
1703 {96, {192, 208, 288}},
1704 {96, {192, 209, 288}},
1705 {112, {224, 243, 336}},
1706 {112, {224, 244, 336}},
1707 {128, {256, 278, 384}},
1708 {128, {256, 279, 384}},
1709 {160, {320, 348, 480}},
1710 {160, {320, 349, 480}},
1711 {192, {384, 417, 576}},
1712 {192, {384, 418, 576}},
1713 {224, {448, 487, 672}},
1714 {224, {448, 488, 672}},
1715 {256, {512, 557, 768}},
1716 {256, {512, 558, 768}},
1717 {320, {640, 696, 960}},
1718 {320, {640, 697, 960}},
1719 {384, {768, 835, 1152}},
1720 {384, {768, 836, 1152}},
1721 {448, {896, 975, 1344}},
1722 {448, {896, 976, 1344}},
1723 {512, {1024, 1114, 1536}},
1724 {512, {1024, 1115, 1536}},
1725 {576, {1152, 1253, 1728}},
1726 {576, {1152, 1254, 1728}},
1727 {640, {1280, 1393, 1920}},
1728 {640, {1280, 1394, 1920}}
1732 ac3_type_find (GstTypeFind * tf, gpointer unused)
1734 DataScanCtx c = { 0, NULL, 0 };
1736 /* Search for an ac3 frame; not necessarily right at the start, but give it
1737 * a lower probability if not found right at the start. Check that the
1738 * frame is followed by a second frame at the expected offset.
1739 * We could also check the two ac3 CRCs, but we don't do that right now */
1740 while (c.offset < 1024) {
1741 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
1744 if (c.data[0] == 0x0b && c.data[1] == 0x77) {
1745 guint bsid = c.data[5] >> 3;
1749 guint fscod = c.data[4] >> 6;
1750 guint frmsizecod = c.data[4] & 0x3f;
1752 if (fscod < 3 && frmsizecod < 38) {
1753 DataScanCtx c_next = c;
1756 frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
1757 GST_LOG ("possible AC3 frame sync at offset %"
1758 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1759 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1760 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1762 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1763 fscod = c_next.data[4] >> 6;
1764 frmsizecod = c_next.data[4] & 0x3f;
1766 if (fscod < 3 && frmsizecod < 38) {
1767 GstTypeFindProbability prob;
1769 GST_LOG ("found second AC3 frame (size=%u), looks good",
1770 ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod]);
1772 prob = GST_TYPE_FIND_MAXIMUM;
1774 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1776 gst_type_find_suggest (tf, prob, AC3_CAPS);
1780 GST_LOG ("no second AC3 frame found, false sync");
1784 } else if (bsid <= 16 && bsid > 10) {
1786 DataScanCtx c_next = c;
1789 frame_size = (((c.data[2] & 0x07) << 8) + c.data[3]) + 1;
1790 GST_LOG ("possible E-AC3 frame sync at offset %"
1791 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1792 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1793 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1795 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1796 GstTypeFindProbability prob;
1798 GST_LOG ("found second E-AC3 frame, looks good");
1800 prob = GST_TYPE_FIND_MAXIMUM;
1802 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1804 gst_type_find_suggest (tf, prob, EAC3_CAPS);
1807 GST_LOG ("no second E-AC3 frame found, false sync");
1811 GST_LOG ("invalid AC3 BSID: %u", bsid);
1814 data_scan_ctx_advance (tf, &c, 1);
1818 /*** audio/x-dts ***/
1819 static GstStaticCaps dts_caps = GST_STATIC_CAPS ("audio/x-dts");
1820 #define DTS_CAPS (gst_static_caps_get (&dts_caps))
1821 #define DTS_MIN_FRAMESIZE 96
1822 #define DTS_MAX_FRAMESIZE 18725 /* 16384*16/14 */
1825 dts_parse_frame_header (DataScanCtx * c, guint * frame_size,
1826 guint * sample_rate, guint * channels, guint * depth, guint * endianness)
1828 static const int sample_rates[16] = { 0, 8000, 16000, 32000, 0, 0, 11025,
1829 22050, 44100, 0, 0, 12000, 24000, 48000, 96000, 192000
1831 static const guint8 channels_table[16] = { 1, 2, 2, 2, 2, 3, 3, 4, 4, 5,
1836 guint num_blocks, chans, lfe, i;
1838 marker = GST_READ_UINT32_BE (c->data);
1840 /* raw big endian or 14-bit big endian */
1841 if (marker == 0x7FFE8001 || marker == 0x1FFFE800) {
1842 *endianness = G_BIG_ENDIAN;
1843 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1844 hdr[i] = GST_READ_UINT16_BE (c->data + (i * sizeof (guint16)));
1846 /* raw little endian or 14-bit little endian */
1847 if (marker == 0xFE7F0180 || marker == 0xFF1F00E8) {
1848 *endianness = G_LITTLE_ENDIAN;
1849 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1850 hdr[i] = GST_READ_UINT16_LE (c->data + (i * sizeof (guint16)));
1855 GST_LOG ("dts sync marker 0x%08x at offset %u", marker, (guint) c->offset);
1858 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8) {
1859 if ((hdr[2] & 0xFFF0) != 0x07F0)
1861 /* discard top 2 bits (2 void), shift in 2 */
1862 hdr[0] = (hdr[0] << 2) | ((hdr[1] >> 12) & 0x0003);
1863 /* discard top 4 bits (2 void, 2 shifted into hdr[0]), shift in 4 etc. */
1864 hdr[1] = (hdr[1] << 4) | ((hdr[2] >> 10) & 0x000F);
1865 hdr[2] = (hdr[2] << 6) | ((hdr[3] >> 8) & 0x003F);
1866 hdr[3] = (hdr[3] << 8) | ((hdr[4] >> 6) & 0x00FF);
1867 hdr[4] = (hdr[4] << 10) | ((hdr[5] >> 4) & 0x03FF);
1868 hdr[5] = (hdr[5] << 12) | ((hdr[6] >> 2) & 0x0FFF);
1869 hdr[6] = (hdr[6] << 14) | ((hdr[7] >> 0) & 0x3FFF);
1870 g_assert (hdr[0] == 0x7FFE && hdr[1] == 0x8001);
1876 GST_LOG ("frame header: %04x%04x%04x%04x", hdr[2], hdr[3], hdr[4], hdr[5]);
1878 num_blocks = (hdr[2] >> 2) & 0x7F;
1879 *frame_size = (((hdr[2] & 0x03) << 12) | (hdr[3] >> 4)) + 1;
1880 chans = ((hdr[3] & 0x0F) << 2) | (hdr[4] >> 14);
1881 *sample_rate = sample_rates[(hdr[4] >> 10) & 0x0F];
1882 lfe = (hdr[5] >> 9) & 0x03;
1884 if (num_blocks < 5 || *frame_size < 96 || *sample_rate == 0)
1887 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8)
1888 *frame_size = (*frame_size * 16) / 14; /* FIXME: round up? */
1890 if (chans < G_N_ELEMENTS (channels_table))
1891 *channels = channels_table[chans] + ((lfe) ? 1 : 0);
1899 dts_type_find (GstTypeFind * tf, gpointer unused)
1901 DataScanCtx c = { 0, NULL, 0 };
1903 /* Search for an dts frame; not necessarily right at the start, but give it
1904 * a lower probability if not found right at the start. Check that the
1905 * frame is followed by a second frame at the expected offset. */
1906 while (c.offset <= DTS_MAX_FRAMESIZE) {
1907 guint frame_size = 0, rate = 0, chans = 0, depth = 0, endianness = 0;
1909 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, DTS_MIN_FRAMESIZE)))
1912 if (G_UNLIKELY (dts_parse_frame_header (&c, &frame_size, &rate, &chans,
1913 &depth, &endianness))) {
1914 GstTypeFindProbability prob;
1917 prob = (c.offset == 0) ? GST_TYPE_FIND_LIKELY : GST_TYPE_FIND_POSSIBLE;
1919 /* check for second frame sync */
1921 data_scan_ctx_advance (tf, &next_c, frame_size);
1922 if (data_scan_ctx_ensure_data (tf, &next_c, 4)) {
1923 GST_LOG ("frame size: %u 0x%04x", frame_size, frame_size);
1924 GST_MEMDUMP ("second frame sync", next_c.data, 4);
1925 if (GST_READ_UINT32_BE (c.data) == GST_READ_UINT32_BE (next_c.data))
1926 prob = GST_TYPE_FIND_MAXIMUM;
1930 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
1931 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, chans,
1932 "depth", G_TYPE_INT, depth, "endianness", G_TYPE_INT, endianness,
1933 "framed", G_TYPE_BOOLEAN, FALSE, NULL);
1935 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
1936 "rate", G_TYPE_INT, rate, "depth", G_TYPE_INT, depth,
1937 "endianness", G_TYPE_INT, endianness,
1938 "framed", G_TYPE_BOOLEAN, FALSE, NULL);
1944 data_scan_ctx_advance (tf, &c, 1);
1949 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
1950 /* can only be detected by using the extension, in which case we use the default
1952 static GstStaticCaps gsm_caps =
1953 GST_STATIC_CAPS ("audio/x-gsm, rate=8000, channels=1");
1955 #define GSM_CAPS (gst_static_caps_get(&gsm_caps))
1959 static GstStaticCaps wavpack_caps =
1960 GST_STATIC_CAPS ("audio/x-wavpack, framed = (boolean) false");
1962 #define WAVPACK_CAPS (gst_static_caps_get(&wavpack_caps))
1964 static GstStaticCaps wavpack_correction_caps =
1965 GST_STATIC_CAPS ("audio/x-wavpack-correction, framed = (boolean) false");
1967 #define WAVPACK_CORRECTION_CAPS (gst_static_caps_get(&wavpack_correction_caps))
1970 wavpack_type_find (GstTypeFind * tf, gpointer unused)
1972 GstTypeFindProbability base_prob = GST_TYPE_FIND_POSSIBLE;
1976 guint count_wv, count_wvc;
1978 data = gst_type_find_peek (tf, 0, 32);
1982 if (data[0] != 'w' || data[1] != 'v' || data[2] != 'p' || data[3] != 'k')
1985 /* Note: wavpack blocks can be fairly large (easily 60-110k), possibly
1986 * larger than the max. limits imposed by certain typefinding elements
1987 * like id3demux or apedemux, so typefinding is most likely only going to
1988 * work in pull-mode */
1989 blocksize = GST_READ_UINT32_LE (data + 4);
1990 GST_LOG ("wavpack header, blocksize=0x%04x", blocksize);
1991 /* If bigger than maximum allowed blocksize, refuse */
1992 if (blocksize > 131072)
1997 while (offset < 8 + blocksize) {
2000 /* get chunk header */
2001 GST_LOG ("peeking at chunk at offset 0x%04x", (guint) offset);
2002 data = gst_type_find_peek (tf, offset, 4);
2005 sublen = ((guint32) data[1]) << 1;
2006 if (data[0] & 0x80) {
2007 sublen |= (((guint32) data[2]) << 9) | (((guint32) data[3]) << 17);
2008 sublen += 1 + 3; /* id + length */
2010 sublen += 1 + 1; /* id + length */
2012 if (offset + sublen > 8 + blocksize) {
2013 GST_LOG ("chunk length too big (%u > %" G_GUINT64_FORMAT ")", sublen,
2014 blocksize - offset);
2017 if ((data[0] & 0x20) == 0) {
2018 switch (data[0] & 0x0f) {
2019 case 0xa: /* ID_WV_BITSTREAM */
2020 case 0xc: /* ID_WVX_BITSTREAM */
2023 case 0xb: /* ID_WVC_BITSTREAM */
2029 if (count_wv >= 5 || count_wvc >= 5)
2035 /* check for second block header */
2036 data = gst_type_find_peek (tf, 8 + blocksize, 4);
2037 if (data != NULL && memcmp (data, "wvpk", 4) == 0) {
2038 GST_DEBUG ("found second block sync");
2039 base_prob = GST_TYPE_FIND_LIKELY;
2042 GST_DEBUG ("wvc=%d, wv=%d", count_wvc, count_wv);
2044 if (count_wvc > 0 && count_wvc > count_wv) {
2045 gst_type_find_suggest (tf,
2046 MIN (base_prob + 5 * count_wvc, GST_TYPE_FIND_NEARLY_CERTAIN),
2047 WAVPACK_CORRECTION_CAPS);
2048 } else if (count_wv > 0) {
2049 gst_type_find_suggest (tf,
2050 MIN (base_prob + 5 * count_wv, GST_TYPE_FIND_NEARLY_CERTAIN),
2055 /*** application/postscrip ***/
2056 static GstStaticCaps postscript_caps =
2057 GST_STATIC_CAPS ("application/postscript");
2059 #define POSTSCRIPT_CAPS (gst_static_caps_get(&postscript_caps))
2062 postscript_type_find (GstTypeFind * tf, gpointer unused)
2064 const guint8 *data = gst_type_find_peek (tf, 0, 3);
2068 if (data[0] == 0x04)
2070 if (data[0] == '%' && data[1] == '!')
2071 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, POSTSCRIPT_CAPS);
2075 /*** image/svg+xml ***/
2076 static GstStaticCaps svg_caps = GST_STATIC_CAPS ("image/svg+xml");
2078 #define SVG_CAPS (gst_static_caps_get(&svg_caps))
2081 svg_type_find (GstTypeFind * tf, gpointer unused)
2083 static const gchar svg_doctype[] = "!DOCTYPE svg";
2084 static const gchar svg_tag[] = "<svg";
2085 DataScanCtx c = { 0, NULL, 0 };
2087 while (c.offset <= 1024) {
2088 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
2091 if (memcmp (svg_doctype, c.data, 12) == 0) {
2092 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVG_CAPS);
2094 } else if (memcmp (svg_tag, c.data, 4) == 0) {
2095 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, SVG_CAPS);
2098 data_scan_ctx_advance (tf, &c, 1);
2102 /*** multipart/x-mixed-replace mimestream ***/
2104 static GstStaticCaps multipart_caps =
2105 GST_STATIC_CAPS ("multipart/x-mixed-replace");
2106 #define MULTIPART_CAPS gst_static_caps_get(&multipart_caps)
2108 /* multipart/x-mixed replace is:
2109 * <maybe some whitespace>--<some ascii chars>[\r]\n
2110 * <more ascii chars>[\r]\nContent-type:<more ascii>[\r]\n */
2112 multipart_type_find (GstTypeFind * tf, gpointer unused)
2117 #define MULTIPART_MAX_BOUNDARY_OFFSET 16
2118 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_BOUNDARY_OFFSET);
2123 x - data < MULTIPART_MAX_BOUNDARY_OFFSET - 2 && g_ascii_isspace (*x);
2125 if (x[0] != '-' || x[1] != '-')
2128 /* Could be okay, peek what should be enough for a complete header */
2129 #define MULTIPART_MAX_HEADER_SIZE 256
2130 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_HEADER_SIZE);
2134 for (x = data; x - data < MULTIPART_MAX_HEADER_SIZE - 14; x++) {
2135 if (!isascii (*x)) {
2139 !g_ascii_strncasecmp ("content-type:", (gchar *) x + 1, 13)) {
2140 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MULTIPART_CAPS);
2147 /*** video/mpeg systemstream ***/
2148 #if defined(TIZEN_PROFILE_TV) || !defined(TIZEN_FEATURE_DISABLE_MIME_TYPES)
2149 static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, "
2150 "systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
2152 #define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
2154 #define IS_MPEG_HEADER(data) (G_UNLIKELY((((guint8 *)(data))[0] == 0x00) && \
2155 (((guint8 *)(data))[1] == 0x00) && \
2156 (((guint8 *)(data))[2] == 0x01)))
2157 #if defined(TIZEN_PROFILE_TV) || !defined(TIZEN_FEATURE_DISABLE_MIME_TYPES)
2158 #define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
2159 #define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
2160 #define IS_MPEG_PACK_HEADER(data) (IS_MPEG_HEADER (data) && \
2161 IS_MPEG_PACK_CODE (((guint8 *)(data))[3]))
2163 #define IS_MPEG_PES_CODE(b) (((b) & 0xF0) == 0xE0 || ((b) & 0xF0) == 0xC0 || \
2165 #define IS_MPEG_PES_HEADER(data) (IS_MPEG_HEADER (data) && \
2166 IS_MPEG_PES_CODE (((guint8 *)(data))[3]))
2168 #define MPEG2_MAX_PROBE_LENGTH (128 * 1024) /* 128kB should be 64 packs of the
2169 * most common 2kB pack size. */
2171 #define MPEG2_MIN_SYS_HEADERS 2
2172 #define MPEG2_MAX_SYS_HEADERS 5
2176 mpeg_sys_is_valid_pack (GstTypeFind * tf, const guint8 * data, guint len,
2179 /* Check the pack header @ offset for validity, assuming that the 4 byte header
2180 * itself has already been checked. */
2186 /* Check marker bits */
2187 if ((data[4] & 0xC4) == 0x44) {
2192 if ((data[6] & 0x04) != 0x04 ||
2193 (data[8] & 0x04) != 0x04 ||
2194 (data[9] & 0x01) != 0x01 || (data[12] & 0x03) != 0x03)
2197 stuff_len = data[13] & 0x07;
2199 /* Check the following header bytes, if we can */
2200 if ((14 + stuff_len + 4) <= len) {
2201 if (!IS_MPEG_HEADER (data + 14 + stuff_len))
2205 *pack_size = 14 + stuff_len;
2207 } else if ((data[4] & 0xF1) == 0x21) {
2209 if ((data[6] & 0x01) != 0x01 ||
2210 (data[8] & 0x01) != 0x01 ||
2211 (data[9] & 0x80) != 0x80 || (data[11] & 0x01) != 0x01)
2214 /* Check the following header bytes, if we can */
2215 if ((12 + 4) <= len) {
2216 if (!IS_MPEG_HEADER (data + 12))
2227 #if defined(TIZEN_PROFILE_TV) || !defined(TIZEN_FEATURE_DISABLE_MIME_TYPES)
2229 mpeg_sys_is_valid_pes (GstTypeFind * tf, const guint8 * data, guint len,
2232 guint pes_packet_len;
2234 /* Check the PES header at the given position, assuming the header code itself
2235 * was already checked */
2239 /* For MPEG Program streams, unbounded PES is not allowed, so we must have a
2240 * valid length present */
2241 pes_packet_len = GST_READ_UINT16_BE (data + 4);
2242 if (pes_packet_len == 0)
2245 /* Check the following header, if we can */
2246 if (6 + pes_packet_len + 4 <= len) {
2247 if (!IS_MPEG_HEADER (data + 6 + pes_packet_len))
2252 *pack_size = 6 + pes_packet_len;
2257 mpeg_sys_is_valid_sys (GstTypeFind * tf, const guint8 * data, guint len,
2262 /* Check the System header at the given position, assuming the header code itself
2263 * was already checked */
2266 sys_hdr_len = GST_READ_UINT16_BE (data + 4);
2267 if (sys_hdr_len < 6)
2270 /* Check the following header, if we can */
2271 if (6 + sys_hdr_len + 4 <= len) {
2272 if (!IS_MPEG_HEADER (data + 6 + sys_hdr_len))
2277 *pack_size = 6 + sys_hdr_len;
2282 /* calculation of possibility to identify random data as mpeg systemstream:
2283 * bits that must match in header detection: 32 (or more)
2284 * chance that random data is identifed: 1/2^32
2285 * chance that MPEG2_MIN_PACK_HEADERS headers are identified:
2286 * 1/2^(32*MPEG2_MIN_PACK_HEADERS)
2287 * chance that this happens in MPEG2_MAX_PROBE_LENGTH bytes:
2288 * 1-(1+1/2^(32*MPEG2_MIN_PACK_HEADERS)^MPEG2_MAX_PROBE_LENGTH)
2289 * for current values:
2290 * 1-(1+1/2^(32*4)^101024)
2292 * Since we also check marker bits and pes packet lengths, this probability is a
2293 * very coarse upper bound.
2296 mpeg_sys_type_find (GstTypeFind * tf, gpointer unused)
2298 const guint8 *data, *data0, *first_sync, *end;
2299 gint mpegversion = 0;
2300 guint pack_headers = 0;
2301 guint pes_headers = 0;
2303 guint since_last_sync = 0;
2304 guint32 sync_word = 0xffffffff;
2305 guint potential_headers = 0;
2310 len = MPEG2_MAX_PROBE_LENGTH;
2313 data = gst_type_find_peek (tf, 0, 5 + len);
2329 while (data < end) {
2331 if (sync_word == 0x00000100) {
2332 /* Found potential sync word */
2333 if (first_sync == NULL)
2334 first_sync = data - 3;
2336 if (since_last_sync > 4) {
2337 /* If more than 4 bytes since the last sync word, reset our counters,
2338 * as we're only interested in counting contiguous packets */
2339 pes_headers = pack_headers = 0;
2343 potential_headers++;
2344 if (IS_MPEG_PACK_CODE (data[0])) {
2345 if ((data[1] & 0xC0) == 0x40) {
2348 } else if ((data[1] & 0xF0) == 0x20) {
2351 if (mpegversion != 0 &&
2352 mpeg_sys_is_valid_pack (tf, data - 3, end - data + 3, &pack_size)) {
2355 } else if (IS_MPEG_PES_CODE (data[0])) {
2357 if (mpeg_sys_is_valid_pes (tf, data - 3, end - data + 3, &pack_size)) {
2359 if (mpegversion == 0)
2362 } else if (IS_MPEG_SYS_CODE (data[0])) {
2363 if (mpeg_sys_is_valid_sys (tf, data - 3, end - data + 3, &pack_size)) {
2368 /* If we found a packet with a known size, skip the bytes in it and loop
2369 * around to check the next packet. */
2370 if (pack_size != 0) {
2371 data += pack_size - 3;
2372 sync_word = 0xffffffff;
2373 since_last_sync = 0;
2378 sync_word |= data[0];
2382 /* If we have found MAX headers, and *some* were pes headers (pack headers
2383 * are optional in an mpeg system stream) then return our high-probability
2385 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MAX_SYS_HEADERS)
2389 /* If we at least saw MIN headers, and *some* were pes headers (pack headers
2390 * are optional in an mpeg system stream) then return a lower-probability
2392 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MIN_SYS_HEADERS)
2400 prob = GST_TYPE_FIND_POSSIBLE + (10 * (pack_headers + pes_headers));
2401 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
2403 /* With the above test, we get into problems when we try to typefind
2404 a MPEG stream from a small amount of data, which can happen when
2405 we get data pushed from a HTTP source. We thus make a second test
2406 to give higher probability if all the potential headers were either
2407 pack or pes headers (ie, no potential header was unrecognized). */
2408 if (potential_headers == pack_headers + pes_headers) {
2409 GST_LOG ("Only %u headers, but all were recognized", potential_headers);
2411 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
2414 /* lower probability if the first packet wasn't right at the start */
2415 if (data0 != first_sync && prob >= 10)
2418 GST_LOG ("Suggesting MPEG %d system stream, %d packs, %d pes, prob %u%%",
2419 mpegversion, pack_headers, pes_headers, prob);
2421 gst_type_find_suggest_simple (tf, prob, "video/mpeg",
2422 "systemstream", G_TYPE_BOOLEAN, TRUE,
2423 "mpegversion", G_TYPE_INT, mpegversion, NULL);
2428 /*** video/mpegts Transport Stream ***/
2429 static GstStaticCaps mpegts_caps = GST_STATIC_CAPS ("video/mpegts, "
2430 "systemstream = (boolean) true, packetsize = (int) [ 188, 208 ]");
2431 #define MPEGTS_CAPS gst_static_caps_get(&mpegts_caps)
2433 #define GST_MPEGTS_TYPEFIND_MIN_HEADERS 4
2434 #define GST_MPEGTS_TYPEFIND_MAX_HEADERS 10
2435 #define GST_MPEGTS_MAX_PACKET_SIZE 208
2436 #define GST_MPEGTS_TYPEFIND_SYNC_SIZE \
2437 (GST_MPEGTS_TYPEFIND_MIN_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
2438 #define GST_MPEGTS_TYPEFIND_MAX_SYNC \
2439 (GST_MPEGTS_TYPEFIND_MAX_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
2440 #define GST_MPEGTS_TYPEFIND_SCAN_LENGTH \
2441 (GST_MPEGTS_TYPEFIND_MAX_SYNC * 4)
2443 #define MPEGTS_HDR_SIZE 4
2444 /* Check for sync byte, error_indicator == 0 and packet has payload.
2445 * Adaptation control field (data[3] & 0x30) may be zero for TS packets with
2446 * null PIDs. Still, these streams are valid TS streams (for null packets,
2447 * AFC is supposed to be 0x1, but the spec also says decoders should just
2448 * discard any packets with AFC = 0x00) */
2449 #define IS_MPEGTS_HEADER(data) (data[0] == 0x47 && \
2450 (data[1] & 0x80) == 0x00 && \
2451 ((data[3] & 0x30) != 0x00 || \
2452 ((data[3] & 0x30) == 0x00 && (data[1] & 0x1f) == 0x1f && (data[2] & 0xff) == 0xff)))
2454 /* Helper function to search ahead at intervals of packet_size for mpegts
2457 mpeg_ts_probe_headers (GstTypeFind * tf, guint64 offset, gint packet_size)
2459 /* We always enter this function having found at least one header already */
2461 const guint8 *data = NULL;
2463 GST_LOG ("looking for mpeg-ts packets of size %u", packet_size);
2464 while (found < GST_MPEGTS_TYPEFIND_MAX_HEADERS) {
2465 offset += packet_size;
2467 data = gst_type_find_peek (tf, offset, MPEGTS_HDR_SIZE);
2468 if (data == NULL || !IS_MPEGTS_HEADER (data))
2472 GST_LOG ("mpeg-ts sync #%2d at offset %" G_GUINT64_FORMAT, found, offset);
2478 /* Try and detect at least 4 packets in at most 10 packets worth of
2479 * data. Need to try several possible packet sizes */
2481 mpeg_ts_type_find (GstTypeFind * tf, gpointer unused)
2483 /* TS packet sizes to test: normal, DVHS packet size and
2484 * FEC with 16 or 20 byte codes packet size. */
2485 const gint pack_sizes[] = { 188, 192, 204, 208 };
2486 const guint8 *data = NULL;
2488 guint64 skipped = 0;
2490 while (skipped < GST_MPEGTS_TYPEFIND_SCAN_LENGTH) {
2491 if (size < MPEGTS_HDR_SIZE) {
2492 data = gst_type_find_peek (tf, skipped, GST_MPEGTS_TYPEFIND_SYNC_SIZE);
2495 size = GST_MPEGTS_TYPEFIND_SYNC_SIZE;
2498 /* Have at least MPEGTS_HDR_SIZE bytes at this point */
2499 if (IS_MPEGTS_HEADER (data)) {
2502 GST_LOG ("possible mpeg-ts sync at offset %" G_GUINT64_FORMAT, skipped);
2504 for (p = 0; p < G_N_ELEMENTS (pack_sizes); p++) {
2507 /* Probe ahead at size pack_sizes[p] */
2508 found = mpeg_ts_probe_headers (tf, skipped, pack_sizes[p]);
2509 if (found >= GST_MPEGTS_TYPEFIND_MIN_HEADERS) {
2512 /* found at least 4 headers. 10 headers = MAXIMUM probability.
2513 * Arbitrarily, I assigned 10% probability for each header we
2514 * found, 40% -> 100% */
2515 probability = MIN (10 * found, GST_TYPE_FIND_MAXIMUM);
2517 gst_type_find_suggest_simple (tf, probability, "video/mpegts",
2518 "systemstream", G_TYPE_BOOLEAN, TRUE,
2519 "packetsize", G_TYPE_INT, pack_sizes[p], NULL);
2530 #define GST_MPEGVID_TYPEFIND_TRY_PICTURES 6
2531 #define GST_MPEGVID_TYPEFIND_TRY_SYNC (100 * 1024) /* 100 kB */
2533 /* Scan ahead a maximum of max_extra_offset bytes until the next IS_MPEG_HEADER
2534 * offset. After the call, offset will be after the 0x000001, i.e. at the 4th
2535 * byte of the MPEG header. Returns TRUE if a header was found, FALSE if not.
2538 mpeg_find_next_header (GstTypeFind * tf, DataScanCtx * c,
2539 guint64 max_extra_offset)
2541 guint64 extra_offset;
2543 for (extra_offset = 0; extra_offset <= max_extra_offset; ++extra_offset) {
2544 if (!data_scan_ctx_ensure_data (tf, c, 4))
2546 if (IS_MPEG_HEADER (c->data)) {
2547 data_scan_ctx_advance (tf, c, 3);
2550 data_scan_ctx_advance (tf, c, 1);
2555 /*** video/mpeg MPEG-4 elementary video stream ***/
2557 static GstStaticCaps mpeg4_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2558 "systemstream=(boolean)false, mpegversion=4, parsed=(boolean)false");
2559 #define MPEG4_VIDEO_CAPS gst_static_caps_get(&mpeg4_video_caps)
2562 * This typefind is based on the elementary video header defined in
2563 * http://xhelmboyx.tripod.com/formats/mpeg-layout.txt
2564 * In addition, it allows the visual object sequence header to be
2565 * absent, and even the VOS header to be absent. In the latter case,
2566 * a number of VOPs have to be present.
2569 mpeg4_video_type_find (GstTypeFind * tf, gpointer unused)
2571 DataScanCtx c = { 0, NULL, 0 };
2572 gboolean seen_vios_at_0 = FALSE;
2573 gboolean seen_vios = FALSE;
2574 gboolean seen_vos = FALSE;
2575 gboolean seen_vol = FALSE;
2576 guint num_vop_headers = 0;
2579 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2580 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2583 if (!mpeg_find_next_header (tf, &c,
2584 GST_MPEGVID_TYPEFIND_TRY_SYNC - c.offset))
2589 /* visual_object_sequence_start_code */
2592 break; /* Terminate at second vios */
2594 seen_vios_at_0 = TRUE;
2596 data_scan_ctx_advance (tf, &c, 2);
2597 if (!mpeg_find_next_header (tf, &c, 0))
2602 /* Optional metadata */
2604 if (!mpeg_find_next_header (tf, &c, 24))
2608 /* visual_object_start_code (consider it optional) */
2610 data_scan_ctx_advance (tf, &c, 2);
2611 /* may contain ID marker and YUV clamping */
2612 if (!mpeg_find_next_header (tf, &c, 7))
2618 /* video_object_start_code */
2621 break; /* Terminate at second vos */
2623 data_scan_ctx_advance (tf, &c, 2);
2627 /* video_object_layer_start_code */
2628 if (sc >= 0x20 && sc <= 0x2F) {
2630 data_scan_ctx_advance (tf, &c, 5);
2634 /* video_object_plane_start_code */
2637 data_scan_ctx_advance (tf, &c, 2);
2641 /* Unknown start code. */
2644 if (num_vop_headers > 0 || seen_vol) {
2645 GstTypeFindProbability probability = 0;
2647 GST_LOG ("Found %d pictures, vios: %d, vos:%d, vol:%d", num_vop_headers,
2648 seen_vios, seen_vos, seen_vol);
2650 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios_at_0
2651 && seen_vos && seen_vol)
2652 probability = GST_TYPE_FIND_MAXIMUM - 1;
2653 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios
2654 && seen_vos && seen_vol)
2655 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2656 else if (seen_vios_at_0 && seen_vos && seen_vol)
2657 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2658 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vos
2660 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2661 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vol)
2662 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2663 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2664 probability = GST_TYPE_FIND_LIKELY - 1;
2665 else if (num_vop_headers > 2 && seen_vios && seen_vos && seen_vol)
2666 probability = GST_TYPE_FIND_LIKELY - 9;
2667 else if (seen_vios && seen_vos && seen_vol)
2668 probability = GST_TYPE_FIND_LIKELY - 20;
2669 else if (num_vop_headers > 0 && seen_vos && seen_vol)
2670 probability = GST_TYPE_FIND_POSSIBLE;
2671 else if (num_vop_headers > 0)
2672 probability = GST_TYPE_FIND_POSSIBLE - 10;
2673 else if (seen_vos && seen_vol)
2674 probability = GST_TYPE_FIND_POSSIBLE - 20;
2676 gst_type_find_suggest (tf, probability, MPEG4_VIDEO_CAPS);
2680 /*** video/x-h263 H263 video stream ***/
2681 static GstStaticCaps h263_video_caps =
2682 GST_STATIC_CAPS ("video/x-h263, variant=(string)itu");
2684 #define H263_VIDEO_CAPS gst_static_caps_get(&h263_video_caps)
2686 #define H263_MAX_PROBE_LENGTH (128 * 1024)
2689 h263_video_type_find (GstTypeFind * tf, gpointer unused)
2691 DataScanCtx c = { 0, NULL, 0 };
2692 guint64 data = 0xffff; /* prevents false positive for first 2 bytes */
2698 guint pc_type, pb_mode;
2700 while (c.offset < H263_MAX_PROBE_LENGTH) {
2701 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
2704 /* Find the picture start code */
2705 data = (data << 8) + c.data[0];
2706 psc = data & G_GUINT64_CONSTANT (0xfffffc0000);
2707 if (psc == 0x800000) {
2710 ptype = (data & 0x3fc) >> 2;
2712 format = ptype & 0x07;
2714 /* Now that we have a Valid PSC, check if we also have a valid PTYPE and
2715 the Source Format, which should range between 1 and 5 */
2716 if (((ptype >> 6) == 0x2) && (format > 0 && format < 6)) {
2717 pc_type = data & 0x02;
2718 pb_mode = c.data[1] & 0x20 >> 4;
2719 if (!pc_type && pb_mode)
2726 /* FIXME: maybe bail out early if we get mostly bad syncs ? */
2729 data_scan_ctx_advance (tf, &c, 1);
2732 GST_LOG ("good: %d, bad: %d", good, bad);
2735 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H263_VIDEO_CAPS);
2740 /*** video/x-h264 H264 elementary video stream ***/
2742 static GstStaticCaps h264_video_caps =
2743 GST_STATIC_CAPS ("video/x-h264,stream-format=byte-stream");
2745 #define H264_VIDEO_CAPS gst_static_caps_get(&h264_video_caps)
2747 #define H264_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
2750 h264_video_type_find (GstTypeFind * tf, gpointer unused)
2752 DataScanCtx c = { 0, NULL, 0 };
2754 /* Stream consists of: a series of sync codes (00 00 00 01) followed
2757 gboolean seen_idr = FALSE;
2758 gboolean seen_sps = FALSE;
2759 gboolean seen_pps = FALSE;
2760 gboolean seen_ssps = FALSE;
2765 while (c.offset < H264_MAX_PROBE_LENGTH) {
2766 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
2769 if (IS_MPEG_HEADER (c.data)) {
2770 nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
2771 ref = c.data[3] & 0x60; /* nal_ref_idc */
2773 /* if forbidden bit is different to 0 won't be h264 */
2779 /* collect statistics about the NAL types */
2780 if ((nut >= 1 && nut <= 13) || nut == 19) {
2781 if ((nut == 5 && ref == 0) ||
2782 ((nut == 6 || (nut >= 9 && nut <= 12)) && ref != 0)) {
2794 } else if (nut >= 14 && nut <= 33) {
2798 } else if (nut == 14 || nut == 20) {
2799 /* Sometimes we see NAL 14 or 20 without SSPS
2800 * if dropped into the middle of a stream -
2801 * just ignore those (don't add to bad count) */
2806 /* Theoretically these are good, since if they exist in the
2807 stream it merely means that a newer backwards-compatible
2808 h.264 stream. But we should be identifying that separately. */
2812 /* unspecified, application specific */
2813 /* don't consider these bad */
2816 GST_LOG ("good:%d, bad:%d, pps:%d, sps:%d, idr:%d ssps:%d", good, bad,
2817 seen_pps, seen_sps, seen_idr, seen_ssps);
2819 if (seen_sps && seen_pps && seen_idr && good >= 10 && bad < 4) {
2820 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H264_VIDEO_CAPS);
2824 data_scan_ctx_advance (tf, &c, 4);
2826 data_scan_ctx_advance (tf, &c, 1);
2829 GST_LOG ("good:%d, bad:%d, pps:%d, sps:%d, idr:%d ssps=%d", good, bad,
2830 seen_pps, seen_sps, seen_idr, seen_ssps);
2832 if (good >= 2 && bad == 0) {
2833 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H264_VIDEO_CAPS);
2837 /*** video/x-h265 H265 elementary video stream ***/
2839 static GstStaticCaps h265_video_caps =
2840 GST_STATIC_CAPS ("video/x-h265,stream-format=byte-stream");
2842 #define H265_VIDEO_CAPS gst_static_caps_get(&h265_video_caps)
2844 #define H265_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
2847 h265_video_type_find (GstTypeFind * tf, gpointer unused)
2849 DataScanCtx c = { 0, NULL, 0 };
2851 /* Stream consists of: a series of sync codes (00 00 00 01) followed
2854 gboolean seen_irap = FALSE;
2855 gboolean seen_vps = FALSE;
2856 gboolean seen_sps = FALSE;
2857 gboolean seen_pps = FALSE;
2862 while (c.offset < H265_MAX_PROBE_LENGTH) {
2863 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 5)))
2866 if (IS_MPEG_HEADER (c.data)) {
2867 /* forbiden_zero_bit | nal_unit_type */
2868 nut = c.data[3] & 0xfe;
2870 /* if forbidden bit is different to 0 won't be h265 */
2877 /* if nuh_layer_id is not zero or nuh_temporal_id_plus1 is zero then
2878 * it won't be h265 */
2879 if ((c.data[3] & 0x01) || (c.data[4] & 0xf8) || !(c.data[4] & 0x07)) {
2884 /* collect statistics about the NAL types */
2885 if ((nut >= 0 && nut <= 9) || (nut >= 16 && nut <= 21) || (nut >= 32
2893 else if (nut >= 16 && nut <= 21) {
2894 /* BLA, IDR and CRA pictures are belongs to be IRAP picture */
2895 /* we are not counting the reserved IRAP pictures (22 and 23) to good */
2900 } else if ((nut >= 10 && nut <= 15) || (nut >= 22 && nut <= 31)
2901 || (nut >= 41 && nut <= 47)) {
2902 /* reserved values are counting as bad */
2905 /* unspecified (48..63), application specific */
2906 /* don't consider these as bad */
2909 GST_LOG ("good:%d, bad:%d, pps:%d, sps:%d, vps:%d, irap:%d", good, bad,
2910 seen_pps, seen_sps, seen_vps, seen_irap);
2912 if (seen_sps && seen_pps && seen_irap && good >= 10 && bad < 4) {
2913 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H265_VIDEO_CAPS);
2917 data_scan_ctx_advance (tf, &c, 5);
2919 data_scan_ctx_advance (tf, &c, 1);
2922 GST_LOG ("good:%d, bad:%d, pps:%d, sps:%d, vps:%d, irap:%d", good, bad,
2923 seen_pps, seen_sps, seen_vps, seen_irap);
2925 if (good >= 2 && bad == 0) {
2926 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H265_VIDEO_CAPS);
2930 /*** video/mpeg video stream ***/
2932 static GstStaticCaps mpeg_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2933 "systemstream = (boolean) false");
2934 #define MPEG_VIDEO_CAPS gst_static_caps_get(&mpeg_video_caps)
2937 * Idea is the same as MPEG system stream typefinding: We check each
2938 * byte of the stream to see if - from that point on - the stream
2939 * matches a predefined set of marker bits as defined in the MPEG
2942 * I'm sure someone will do a chance calculation here too.
2946 mpeg_video_stream_type_find (GstTypeFind * tf, gpointer unused)
2948 DataScanCtx c = { 0, NULL, 0 };
2949 gboolean seen_seq_at_0 = FALSE;
2950 gboolean seen_seq = FALSE;
2951 gboolean seen_gop = FALSE;
2952 guint64 last_pic_offset = 0;
2953 gint num_pic_headers = 0;
2956 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2957 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2960 if (!data_scan_ctx_ensure_data (tf, &c, 5))
2963 if (!IS_MPEG_HEADER (c.data))
2966 /* a pack header indicates that this isn't an elementary stream */
2967 if (c.data[3] == 0xBA && mpeg_sys_is_valid_pack (tf, c.data, c.size, NULL))
2970 /* do we have a sequence header? */
2971 if (c.data[3] == 0xB3) {
2972 seen_seq_at_0 = seen_seq_at_0 || (c.offset == 0);
2974 data_scan_ctx_advance (tf, &c, 4 + 8);
2978 /* or a GOP header */
2979 if (c.data[3] == 0xB8) {
2981 data_scan_ctx_advance (tf, &c, 8);
2985 /* but what we'd really like to see is a picture header */
2986 if (c.data[3] == 0x00) {
2988 last_pic_offset = c.offset;
2989 data_scan_ctx_advance (tf, &c, 8);
2993 /* ... each followed by a slice header with slice_vertical_pos=1 that's
2994 * not too far away from the previously seen picture header. */
2995 if (c.data[3] == 0x01 && num_pic_headers > found &&
2996 (c.offset - last_pic_offset) >= 4 &&
2997 (c.offset - last_pic_offset) <= 64) {
2998 data_scan_ctx_advance (tf, &c, 4);
3005 data_scan_ctx_advance (tf, &c, 1);
3008 if (found > 0 || seen_seq) {
3009 GstTypeFindProbability probability = 0;
3011 GST_LOG ("Found %d pictures, seq:%d, gop:%d", found, seen_seq, seen_gop);
3013 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq && seen_gop)
3014 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
3015 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq)
3016 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
3017 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
3018 probability = GST_TYPE_FIND_LIKELY;
3019 else if (seen_seq_at_0 && seen_gop && found > 2)
3020 probability = GST_TYPE_FIND_LIKELY - 10;
3021 else if (seen_seq && seen_gop && found > 2)
3022 probability = GST_TYPE_FIND_LIKELY - 20;
3023 else if (seen_seq_at_0 && found > 0)
3024 probability = GST_TYPE_FIND_POSSIBLE;
3025 else if (seen_seq && found > 0)
3026 probability = GST_TYPE_FIND_POSSIBLE - 5;
3028 probability = GST_TYPE_FIND_POSSIBLE - 10;
3030 probability = GST_TYPE_FIND_POSSIBLE - 20;
3032 gst_type_find_suggest_simple (tf, probability, "video/mpeg",
3033 "systemstream", G_TYPE_BOOLEAN, FALSE,
3034 "mpegversion", G_TYPE_INT, 1, "parsed", G_TYPE_BOOLEAN, FALSE, NULL);
3038 /*** audio/x-aiff ***/
3040 static GstStaticCaps aiff_caps = GST_STATIC_CAPS ("audio/x-aiff");
3042 #define AIFF_CAPS gst_static_caps_get(&aiff_caps)
3044 aiff_type_find (GstTypeFind * tf, gpointer unused)
3046 const guint8 *data = gst_type_find_peek (tf, 0, 16);
3048 if (data && memcmp (data, "FORM", 4) == 0) {
3050 if (memcmp (data, "AIFF", 4) == 0 || memcmp (data, "AIFC", 4) == 0)
3051 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AIFF_CAPS);
3055 /*** audio/x-svx ***/
3056 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
3057 static GstStaticCaps svx_caps = GST_STATIC_CAPS ("audio/x-svx");
3059 #define SVX_CAPS gst_static_caps_get(&svx_caps)
3061 svx_type_find (GstTypeFind * tf, gpointer unused)
3063 const guint8 *data = gst_type_find_peek (tf, 0, 16);
3065 if (data && memcmp (data, "FORM", 4) == 0) {
3067 if (memcmp (data, "8SVX", 4) == 0 || memcmp (data, "16SV", 4) == 0)
3068 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVX_CAPS);
3072 /*** audio/x-shorten ***/
3074 static GstStaticCaps shn_caps = GST_STATIC_CAPS ("audio/x-shorten");
3076 #define SHN_CAPS gst_static_caps_get(&shn_caps)
3078 shn_type_find (GstTypeFind * tf, gpointer unused)
3080 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3082 if (data && memcmp (data, "ajkg", 4) == 0) {
3083 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
3085 data = gst_type_find_peek (tf, -8, 8);
3086 if (data && memcmp (data, "SHNAMPSK", 8) == 0) {
3087 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
3091 /*** application/x-ape ***/
3093 static GstStaticCaps ape_caps = GST_STATIC_CAPS ("application/x-ape");
3095 #define APE_CAPS gst_static_caps_get(&ape_caps)
3097 ape_type_find (GstTypeFind * tf, gpointer unused)
3099 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3101 if (data && memcmp (data, "MAC ", 4) == 0) {
3102 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 10, APE_CAPS);
3106 /*** ISO FORMATS ***/
3108 /*** audio/x-m4a ***/
3110 static GstStaticCaps m4a_caps = GST_STATIC_CAPS ("audio/x-m4a");
3112 #define M4A_CAPS (gst_static_caps_get(&m4a_caps))
3114 m4a_type_find (GstTypeFind * tf, gpointer unused)
3116 const guint8 *data = gst_type_find_peek (tf, 4, 8);
3118 if (data && (memcmp (data, "ftypM4A ", 8) == 0)) {
3119 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
3123 /*** application/x-3gp ***/
3125 /* The Q is there because variables can't start with a number. */
3126 static GstStaticCaps q3gp_caps = GST_STATIC_CAPS ("application/x-3gp");
3127 #define Q3GP_CAPS (gst_static_caps_get(&q3gp_caps))
3129 static const gchar *
3130 q3gp_type_find_get_profile (const guint8 * data)
3132 switch (GST_MAKE_FOURCC (data[0], data[1], data[2], 0)) {
3133 case GST_MAKE_FOURCC ('3', 'g', 'g', 0):
3135 case GST_MAKE_FOURCC ('3', 'g', 'p', 0):
3137 case GST_MAKE_FOURCC ('3', 'g', 's', 0):
3138 return "streaming-server";
3139 case GST_MAKE_FOURCC ('3', 'g', 'r', 0):
3140 return "progressive-download";
3148 q3gp_type_find (GstTypeFind * tf, gpointer unused)
3150 const gchar *profile;
3151 guint32 ftyp_size = 0;
3153 const guint8 *data = NULL;
3155 if ((data = gst_type_find_peek (tf, 0, 12)) == NULL) {
3160 if (memcmp (data, "ftyp", 4) != 0) {
3164 /* check major brand */
3166 if ((profile = q3gp_type_find_get_profile (data))) {
3167 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3168 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
3172 /* check compatible brands */
3173 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
3174 ftyp_size = GST_READ_UINT32_BE (data);
3176 if ((data = gst_type_find_peek (tf, 0, ftyp_size)) != NULL) {
3177 for (offset = 16; offset + 4 < ftyp_size; offset += 4) {
3178 if ((profile = q3gp_type_find_get_profile (data + offset))) {
3179 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3180 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
3190 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
3191 /*** video/mj2 and image/jp2 ***/
3192 static GstStaticCaps mj2_caps = GST_STATIC_CAPS ("video/mj2");
3194 #define MJ2_CAPS gst_static_caps_get(&mj2_caps)
3196 static GstStaticCaps jp2_caps = GST_STATIC_CAPS ("image/jp2");
3198 #define JP2_CAPS gst_static_caps_get(&jp2_caps)
3201 jp2_type_find (GstTypeFind * tf, gpointer unused)
3205 data = gst_type_find_peek (tf, 0, 24);
3210 if (memcmp (data, "\000\000\000\014jP \015\012\207\012", 12) != 0)
3213 /* check ftyp box */
3215 if (memcmp (data + 4, "ftyp", 4) == 0) {
3216 if (memcmp (data + 8, "jp2 ", 4) == 0)
3217 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JP2_CAPS);
3218 else if (memcmp (data + 8, "mjp2", 4) == 0)
3219 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MJ2_CAPS);
3224 static GstStaticCaps jpc_caps = GST_STATIC_CAPS ("image/x-jpc");
3226 #define JPC_CAPS gst_static_caps_get(&jpc_caps)
3229 jpc_type_find (GstTypeFind * tf, gpointer unused)
3231 gboolean found_cod = FALSE;
3232 gboolean found_qcd = FALSE;
3233 gboolean found_sot = FALSE;
3236 const guint8 soc_siz[] = { 0xff, 0x4f, 0xff, 0x51 };
3238 #define GST_TYPE_FIND_JPC_MARKER_SOT 0xFF90
3239 #define GST_TYPE_FIND_JPC_MARKER_COD 0xFF52
3240 #define GST_TYPE_FIND_JPC_MARKER_QCD 0xFF5C
3241 #define GST_TYPE_FIND_JPC_MARKER_COC 0xFF53
3242 #define GST_TYPE_FIND_JPC_MARKER_RGN 0xFF5E
3243 #define GST_TYPE_FIND_JPC_MARKER_QCC 0xFF5D
3244 #define GST_TYPE_FIND_JPC_MARKER_POC 0xFF5F
3245 #define GST_TYPE_FIND_JPC_MARKER_PLM 0xFF57
3246 #define GST_TYPE_FIND_JPC_MARKER_PPM 0xFF60
3247 #define GST_TYPE_FIND_JPC_MARKER_TLM 0xFF55
3248 #define GST_TYPE_FIND_JPC_MARKER_CRG 0xFF63
3249 #define GST_TYPE_FIND_JPC_MARKER_COM 0xFF64
3250 #define GST_TYPE_FIND_JPC_MARKER_CBD 0xFF78
3251 #define GST_TYPE_FIND_JPC_MARKER_MCC 0xFF75
3252 #define GST_TYPE_FIND_JPC_MARKER_MCT 0xFF74
3253 #define GST_TYPE_FIND_JPC_MARKER_MCO 0xFF77
3256 /* SOC marker + SIZ marker */
3257 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
3258 if (memcmp (data, soc_siz, 4) != 0)
3265 while (!found_sot) {
3267 /* skip actual marker data */
3268 if ((data = gst_type_find_peek (tf, offset, 2)) != NULL) {
3269 offset += GST_READ_UINT16_BE (data);
3275 if ((data = gst_type_find_peek (tf, offset, 2)) != NULL) {
3276 guint16 marker = GST_READ_UINT16_BE (data);
3278 case GST_TYPE_FIND_JPC_MARKER_SOT:
3281 case GST_TYPE_FIND_JPC_MARKER_COD:
3284 case GST_TYPE_FIND_JPC_MARKER_QCD:
3287 /* optional header markers */
3288 case GST_TYPE_FIND_JPC_MARKER_COC:
3289 case GST_TYPE_FIND_JPC_MARKER_RGN:
3290 case GST_TYPE_FIND_JPC_MARKER_QCC:
3291 case GST_TYPE_FIND_JPC_MARKER_POC:
3292 case GST_TYPE_FIND_JPC_MARKER_PLM:
3293 case GST_TYPE_FIND_JPC_MARKER_PPM:
3294 case GST_TYPE_FIND_JPC_MARKER_TLM:
3295 case GST_TYPE_FIND_JPC_MARKER_CRG:
3296 case GST_TYPE_FIND_JPC_MARKER_COM:
3297 case GST_TYPE_FIND_JPC_MARKER_CBD:
3298 case GST_TYPE_FIND_JPC_MARKER_MCC:
3299 case GST_TYPE_FIND_JPC_MARKER_MCT:
3300 case GST_TYPE_FIND_JPC_MARKER_MCO:
3302 /* unrecognized marker */
3312 if (found_cod && found_qcd && found_sot)
3313 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JPC_CAPS);
3317 /*** video/quicktime ***/
3319 static GstStaticCaps qt_caps = GST_STATIC_CAPS ("video/quicktime");
3321 #define QT_CAPS gst_static_caps_get(&qt_caps)
3322 #define STRNCMP(x,y,z) (strncmp ((char*)(x), (char*)(y), z))
3324 /* FIXME 0.11: go through http://www.ftyps.com/ */
3326 qt_type_find (GstTypeFind * tf, gpointer unused)
3332 const gchar *variant = NULL;
3334 while ((data = gst_type_find_peek (tf, offset, 12)) != NULL) {
3337 if (STRNCMP (&data[4], "ftypqt ", 8) == 0) {
3338 tip = GST_TYPE_FIND_MAXIMUM;
3342 if (STRNCMP (&data[4], "ftypisom", 8) == 0 ||
3343 STRNCMP (&data[4], "ftypavc1", 8) == 0 ||
3344 #ifdef TIZEN_FEATURE_TYPEFIND_ENHANCEMENT
3345 STRNCMP (&data[4], "ftypwmf ", 8) == 0 ||
3347 STRNCMP (&data[4], "ftypmp42", 8) == 0) {
3348 tip = GST_TYPE_FIND_MAXIMUM;
3353 if (STRNCMP (&data[4], "ftypisml", 8) == 0 ||
3354 STRNCMP (&data[4], "ftypavc3", 8) == 0) {
3355 tip = GST_TYPE_FIND_MAXIMUM;
3356 variant = "iso-fragmented";
3360 if (STRNCMP (&data[4], "ftypccff", 8) == 0) {
3361 tip = GST_TYPE_FIND_MAXIMUM;
3366 /* box/atom types that are in common with ISO base media file format */
3367 if (STRNCMP (&data[4], "moov", 4) == 0 ||
3368 STRNCMP (&data[4], "mdat", 4) == 0 ||
3369 STRNCMP (&data[4], "ftyp", 4) == 0 ||
3370 STRNCMP (&data[4], "free", 4) == 0 ||
3371 STRNCMP (&data[4], "uuid", 4) == 0 ||
3372 STRNCMP (&data[4], "moof", 4) == 0 ||
3373 STRNCMP (&data[4], "skip", 4) == 0) {
3375 tip = GST_TYPE_FIND_LIKELY;
3377 tip = GST_TYPE_FIND_NEARLY_CERTAIN;
3380 /* other box/atom types, apparently quicktime specific */
3381 else if (STRNCMP (&data[4], "pnot", 4) == 0 ||
3382 STRNCMP (&data[4], "PICT", 4) == 0 ||
3383 STRNCMP (&data[4], "wide", 4) == 0 ||
3384 STRNCMP (&data[4], "prfl", 4) == 0) {
3385 tip = GST_TYPE_FIND_MAXIMUM;
3392 size = GST_READ_UINT32_BE (data);
3393 if (size + offset >= G_MAXINT64)
3395 /* check compatible brands rather than ever expaning major brands above */
3396 if ((STRNCMP (&data[4], "ftyp", 4) == 0) && (size >= 16)) {
3397 data = gst_type_find_peek (tf, offset, size);
3401 while (new_offset + 4 <= size) {
3402 if (STRNCMP (&data[new_offset], "isom", 4) == 0 ||
3403 STRNCMP (&data[new_offset], "dash", 4) == 0 ||
3404 STRNCMP (&data[new_offset], "avc1", 4) == 0 ||
3405 STRNCMP (&data[new_offset], "avc3", 4) == 0 ||
3406 STRNCMP (&data[new_offset], "mp41", 4) == 0 ||
3407 STRNCMP (&data[new_offset], "mp42", 4) == 0) {
3408 tip = GST_TYPE_FIND_MAXIMUM;
3416 const guint8 *sizedata;
3418 sizedata = gst_type_find_peek (tf, offset + 8, 8);
3419 if (sizedata == NULL)
3422 size = GST_READ_UINT64_BE (sizedata);
3427 new_offset = offset + size;
3428 if (new_offset <= offset)
3430 if (new_offset + 16 >= G_MAXINT64)
3432 offset = new_offset;
3438 GstCaps *caps = gst_caps_copy (QT_CAPS);
3440 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, variant, NULL);
3441 gst_type_find_suggest (tf, tip, caps);
3442 gst_caps_unref (caps);
3444 gst_type_find_suggest (tf, tip, QT_CAPS);
3450 /*** image/x-quicktime ***/
3451 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
3452 static GstStaticCaps qtif_caps = GST_STATIC_CAPS ("image/x-quicktime");
3454 #define QTIF_CAPS gst_static_caps_get(&qtif_caps)
3456 /* how many atoms we check before we give up */
3457 #define QTIF_MAXROUNDS 25
3460 qtif_type_find (GstTypeFind * tf, gpointer unused)
3463 gboolean found_idsc = FALSE;
3464 gboolean found_idat = FALSE;
3468 while ((data = gst_type_find_peek (tf, offset, 8)) != NULL) {
3471 size = GST_READ_UINT32_BE (data);
3473 const guint8 *sizedata;
3475 sizedata = gst_type_find_peek (tf, offset + 8, 8);
3476 if (sizedata == NULL)
3479 size = GST_READ_UINT64_BE (sizedata);
3484 if (STRNCMP (data + 4, "idsc", 4) == 0)
3486 if (STRNCMP (data + 4, "idat", 4) == 0)
3489 if (found_idsc && found_idat) {
3490 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, QTIF_CAPS);
3495 if (offset + 8 >= G_MAXINT64)
3497 if (++rounds > QTIF_MAXROUNDS)
3501 if (found_idsc || found_idat) {
3502 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, QTIF_CAPS);
3507 /*** audio/x-mod ***/
3509 static GstStaticCaps mod_caps = GST_STATIC_CAPS ("audio/x-mod");
3511 #define MOD_CAPS gst_static_caps_get(&mod_caps)
3512 /* FIXME: M15 CheckType to do */
3514 mod_type_find (GstTypeFind * tf, gpointer unused)
3517 GstTypeFindProbability probability;
3518 const char *mod_type = NULL;
3521 if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) {
3522 /* Protracker and variants */
3523 if ((memcmp (data, "M.K.", 4) == 0) ||
3524 (memcmp (data, "M!K!", 4) == 0) ||
3525 (memcmp (data, "M&K!", 4) == 0) || (memcmp (data, "N.T.", 4) == 0) ||
3527 (memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) ||
3528 (memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) ||
3529 /* Oktalyzer (Amiga) */
3530 (memcmp (data, "OKTA", 4) == 0) || (memcmp (data, "OCTA", 4) == 0) ||
3531 /* Oktalyser (Atari) */
3532 (memcmp (data, "CD81", 4) == 0) ||
3534 (memcmp (data, "TDZ", 3) == 0 && isdigit (data[3])) ||
3536 (memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) ||
3537 /* Fasttracker or Taketracker */
3538 (memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0])
3539 && isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0
3540 && isdigit (data[0]) && isdigit (data[1]))) {
3542 probability = GST_TYPE_FIND_MAXIMUM;
3543 goto suggest_audio_mod_caps;
3546 /* J2B (Jazz Jackrabbit 2) */
3547 if ((data = gst_type_find_peek (tf, 0, 8)) != NULL) {
3548 if ((memcmp (data, "MUSE\xDE\xAD", 4) == 0) &&
3549 ((memcmp (data + 6, "\xBE\xEF", 2) == 0) ||
3550 (memcmp (data + 6, "\xBA\xBE", 2) == 0))) {
3552 probability = GST_TYPE_FIND_MAXIMUM;
3553 goto suggest_audio_mod_caps;
3556 /* AMS (Velvet Studio) */
3557 if ((data = gst_type_find_peek (tf, 0, 7)) != NULL) {
3558 if (memcmp (data, "AMShdr\x1A", 7) == 0) {
3559 mod_type = "velvet-ams";
3560 probability = GST_TYPE_FIND_MAXIMUM;
3561 goto suggest_audio_mod_caps;
3564 /* AMS (Extreme Tracker) */
3565 if ((data = gst_type_find_peek (tf, 0, 9)) != NULL) {
3566 if ((memcmp (data, "Extreme", 7) == 0) && (data[8] == 1)) {
3567 mod_type = "extreme-ams";
3568 probability = GST_TYPE_FIND_LIKELY;
3569 goto suggest_audio_mod_caps;
3572 /* ULT (Ultratracker) */
3573 if ((data = gst_type_find_peek (tf, 0, 14)) != NULL) {
3574 if (memcmp (data, "MAS_UTrack_V00", 14) == 0) {
3576 probability = GST_TYPE_FIND_MAXIMUM;
3577 goto suggest_audio_mod_caps;
3580 /* DIGI (DigiBooster) */
3581 if ((data = gst_type_find_peek (tf, 0, 20)) != NULL) {
3582 if (memcmp (data, "DIGI Booster module\0", 20) == 0) {
3584 probability = GST_TYPE_FIND_MAXIMUM;
3585 goto suggest_audio_mod_caps;
3588 /* PTM (PolyTracker) */
3589 if ((data = gst_type_find_peek (tf, 0x2C, 4)) != NULL) {
3590 if (memcmp (data, "PTMF", 4) == 0) {
3592 probability = GST_TYPE_FIND_LIKELY;
3593 goto suggest_audio_mod_caps;
3597 if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) {
3598 if ((memcmp (data, "Extended Module: ", 17) == 0) && (data[37] == 0x1A)) {
3600 probability = GST_TYPE_FIND_MAXIMUM;
3601 goto suggest_audio_mod_caps;
3605 if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) {
3606 if (memcmp (data, "OKTASONG", 8) == 0) {
3608 probability = GST_TYPE_FIND_MAXIMUM;
3609 goto suggest_audio_mod_caps;
3612 /* Various formats with a 4-byte magic ID at the beginning of the file */
3613 if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) {
3614 /* PSM (Protracker Studio PSM) */
3615 if (memcmp (data, "PSM", 3) == 0) {
3616 unsigned char fbyte = data[3];
3617 if ((fbyte == ' ') || (fbyte == 254)) {
3619 probability = GST_TYPE_FIND_MAXIMUM;
3620 goto suggest_audio_mod_caps;
3624 if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) {
3626 probability = GST_TYPE_FIND_LIKELY;
3627 goto suggest_audio_mod_caps;
3630 if ((memcmp (data, "AMF", 3) == 0) && (data[3] > 10) && (data[3] < 14)) {
3631 mod_type = "dsmi-amf";
3632 probability = GST_TYPE_FIND_MAXIMUM;
3633 goto suggest_audio_mod_caps;
3636 if (memcmp (data, "IMPM", 4) == 0) {
3638 probability = GST_TYPE_FIND_MAXIMUM;
3639 goto suggest_audio_mod_caps;
3641 /* DBM (DigiBooster Pro) */
3642 if (memcmp (data, "DBM0", 4) == 0) {
3644 probability = GST_TYPE_FIND_MAXIMUM;
3645 goto suggest_audio_mod_caps;
3647 /* MDL (DigiTrakker) */
3648 if (memcmp (data, "DMDL", 4) == 0) {
3650 probability = GST_TYPE_FIND_MAXIMUM;
3651 goto suggest_audio_mod_caps;
3653 /* MT2 (MadTracker 2.0) */
3654 if (memcmp (data, "MT20", 4) == 0) {
3656 probability = GST_TYPE_FIND_MAXIMUM;
3657 goto suggest_audio_mod_caps;
3659 /* DMF (X-Tracker) */
3660 if (memcmp (data, "DDMF", 4) == 0) {
3662 probability = GST_TYPE_FIND_MAXIMUM;
3663 goto suggest_audio_mod_caps;
3666 if ((memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0)) {
3668 probability = GST_TYPE_FIND_MAXIMUM;
3669 goto suggest_audio_mod_caps;
3672 if (memcmp (data, "MTM", 3) == 0) {
3674 probability = GST_TYPE_FIND_MAXIMUM;
3675 goto suggest_audio_mod_caps;
3678 if (memcmp (data, "RIFF", 4) == 0) {
3679 const guint8 *data2 = gst_type_find_peek (tf, 8, 4);
3682 if (memcmp (data2, "DSMF", 4) == 0) {
3684 probability = GST_TYPE_FIND_MAXIMUM;
3685 goto suggest_audio_mod_caps;
3689 /* FAR (Farandole) */
3690 if (memcmp (data, "FAR\xFE", 4) == 0) {
3692 probability = GST_TYPE_FIND_MAXIMUM;
3693 goto suggest_audio_mod_caps;
3696 if (memcmp (data, "FAM\xFE", 4) == 0) {
3697 const guint8 *data2 = gst_type_find_peek (tf, 44, 3);
3700 if (memcmp (data2, "compare", 3) == 0) {
3702 probability = GST_TYPE_FIND_MAXIMUM;
3703 goto suggest_audio_mod_caps;
3705 /* otherwise do not suggest anything */
3708 probability = GST_TYPE_FIND_LIKELY;
3709 goto suggest_audio_mod_caps;
3713 if (memcmp (data, "GDM\xFE", 4) == 0) {
3714 const guint8 *data2 = gst_type_find_peek (tf, 71, 4);
3717 if (memcmp (data2, "GMFS", 4) == 0) {
3719 probability = GST_TYPE_FIND_MAXIMUM;
3720 goto suggest_audio_mod_caps;
3722 /* otherwise do not suggest anything */
3725 probability = GST_TYPE_FIND_LIKELY;
3726 goto suggest_audio_mod_caps;
3730 if (memcmp (data, "\xC1\x83\x2A\x9E", 4) == 0) {
3732 probability = GST_TYPE_FIND_POSSIBLE;
3733 goto suggest_audio_mod_caps;
3736 /* FAR (Farandole) (secondary detection) */
3737 if ((data = gst_type_find_peek (tf, 44, 3)) != NULL) {
3738 if (memcmp (data, "\x0D\x0A\x1A", 3) == 0) {
3740 probability = GST_TYPE_FIND_POSSIBLE;
3741 goto suggest_audio_mod_caps;
3745 if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) {
3746 if (memcmp (data, "IM10", 4) == 0) {
3748 probability = GST_TYPE_FIND_MAXIMUM;
3749 goto suggest_audio_mod_caps;
3753 if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) {
3754 if (memcmp (data, "SCRM", 4) == 0) {
3756 probability = GST_TYPE_FIND_MAXIMUM;
3757 goto suggest_audio_mod_caps;
3761 if ((data = gst_type_find_peek (tf, 20, 8)) != NULL) {
3762 if (g_ascii_strncasecmp ((gchar *) data, "!Scream!", 8) == 0 ||
3763 g_ascii_strncasecmp ((gchar *) data, "BMOD2STM", 8) == 0) {
3764 const guint8 *id, *stmtype;
3766 if ((id = gst_type_find_peek (tf, 28, 1)) == NULL)
3768 if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL)
3770 if (*id == 0x1A && *stmtype == 2) {
3772 probability = GST_TYPE_FIND_MAXIMUM;
3773 goto suggest_audio_mod_caps;
3778 if ((data = gst_type_find_peek (tf, 0, 19)) != NULL) {
3779 if (memcmp (data, "ASYLUM Music Format", 19) == 0) {
3780 mod_type = "asylum-amf";
3781 probability = GST_TYPE_FIND_MAXIMUM;
3782 goto suggest_audio_mod_caps;
3786 suggest_audio_mod_caps:
3787 if (mod_type != NULL) {
3788 GstCaps *caps = gst_caps_new_simple ("audio/x-mod",
3789 "type", G_TYPE_STRING, mod_type, NULL);
3791 gst_type_find_suggest (tf, probability, caps);
3792 gst_caps_unref (caps);
3796 /*** application/x-shockwave-flash ***/
3798 static GstStaticCaps swf_caps =
3799 GST_STATIC_CAPS ("application/x-shockwave-flash");
3800 #define SWF_CAPS (gst_static_caps_get(&swf_caps))
3802 swf_type_find (GstTypeFind * tf, gpointer unused)
3804 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3806 if (data && (data[0] == 'F' || data[0] == 'C') &&
3807 data[1] == 'W' && data[2] == 'S') {
3808 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SWF_CAPS);
3812 /*** application/vnd.ms-sstr+xml ***/
3815 mss_manifest_load_utf16 (gunichar2 * utf16_ne, const guint8 * utf16_data,
3816 gsize data_size, guint data_endianness)
3818 memcpy (utf16_ne, utf16_data, data_size);
3819 if (data_endianness != G_BYTE_ORDER) {
3822 for (i = 0; i < data_size / 2; ++i)
3823 utf16_ne[i] = GUINT16_SWAP_LE_BE (utf16_ne[i]);
3827 static GstStaticCaps mss_manifest_caps =
3828 GST_STATIC_CAPS ("application/vnd.ms-sstr+xml");
3829 #define MSS_MANIFEST_CAPS (gst_static_caps_get(&mss_manifest_caps))
3831 mss_manifest_type_find (GstTypeFind * tf, gpointer unused)
3833 gunichar2 utf16_ne[512];
3835 guint data_endianness = 0;
3836 glong n_read = 0, size = 0;
3839 gboolean utf8_bom_detected = FALSE;
3841 if (xml_check_first_element (tf, "SmoothStreamingMedia", 20, TRUE)) {
3842 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MSS_MANIFEST_CAPS);
3846 length = gst_type_find_get_length (tf);
3848 /* try detecting the charset */
3849 data = gst_type_find_peek (tf, 0, 3);
3854 /* look for a possible BOM */
3855 if (data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF)
3856 utf8_bom_detected = TRUE;
3857 else if (data[0] == 0xFF && data[1] == 0xFE)
3858 data_endianness = G_LITTLE_ENDIAN;
3859 else if (data[0] == 0xFE && data[1] == 0xFF)
3860 data_endianness = G_BIG_ENDIAN;
3864 /* try a default that should be enough */
3867 else if (length < 64)
3869 else /* the first few bytes should be enough */
3870 length = MIN (1024, length);
3872 data = gst_type_find_peek (tf, 0, length);
3881 if (utf8_bom_detected) {
3882 /* skip last byte of the BOM */
3886 if (xml_check_first_element_from_data (data, length,
3887 "SmoothStreamingMedia", 20, TRUE))
3888 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MSS_MANIFEST_CAPS);
3890 length = GST_ROUND_DOWN_2 (length);
3892 /* convert to native endian UTF-16 */
3893 mss_manifest_load_utf16 (utf16_ne, data, length, data_endianness);
3895 /* and now convert to UTF-8 */
3896 utf8 = g_utf16_to_utf8 (utf16_ne, length / 2, &n_read, &size, NULL);
3897 if (utf8 != NULL && n_read > 0) {
3898 if (xml_check_first_element_from_data ((const guint8 *) utf8, size,
3899 "SmoothStreamingMedia", 20, TRUE))
3900 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MSS_MANIFEST_CAPS);
3906 /*** image/jpeg ***/
3908 #define JPEG_MARKER_IS_START_OF_FRAME(x) \
3909 ((x)>=0xc0 && (x) <= 0xcf && (x)!=0xc4 && (x)!=0xc8 && (x)!=0xcc)
3911 static GstStaticCaps jpeg_caps = GST_STATIC_CAPS ("image/jpeg");
3913 #define JPEG_CAPS (gst_static_caps_get(&jpeg_caps))
3915 jpeg_type_find (GstTypeFind * tf, gpointer unused)
3917 GstTypeFindProbability prob = GST_TYPE_FIND_POSSIBLE;
3918 DataScanCtx c = { 0, NULL, 0 };
3922 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 2)))
3925 if (c.data[0] != 0xff || c.data[1] != 0xd8)
3929 data_scan_ctx_advance (tf, &c, 2);
3931 caps = gst_caps_copy (JPEG_CAPS);
3933 while (data_scan_ctx_ensure_data (tf, &c, 4) && c.offset < (200 * 1024)) {
3937 if (c.data[0] != 0xff)
3941 if (G_UNLIKELY (marker == 0xff)) {
3942 data_scan_ctx_advance (tf, &c, 1);
3946 data_scan_ctx_advance (tf, &c, 2);
3948 /* we assume all markers we'll see before SOF have a payload length; if
3949 * that's not the case we'll just detect a false sync and bail out, but
3950 * still report POSSIBLE probability */
3951 len = GST_READ_UINT16_BE (c.data);
3953 GST_LOG ("possible JPEG marker 0x%02x (@0x%04x), segment length %u",
3954 marker, (guint) c.offset, len);
3956 if (!data_scan_ctx_ensure_data (tf, &c, len))
3959 if (marker == 0xc4 || /* DEFINE_HUFFMAN_TABLES */
3960 marker == 0xcc || /* DEFINE_ARITHMETIC_CONDITIONING */
3961 marker == 0xdb || /* DEFINE_QUANTIZATION_TABLES */
3962 marker == 0xdd || /* DEFINE_RESTART_INTERVAL */
3963 marker == 0xfe) { /* COMMENT */
3964 data_scan_ctx_advance (tf, &c, len);
3966 } else if (marker == 0xe0 && len >= (2 + 4) && /* APP0 */
3967 data_scan_ctx_memcmp (tf, &c, 2, "JFIF", 4)) {
3968 GST_LOG ("found JFIF tag");
3969 prob = GST_TYPE_FIND_MAXIMUM;
3970 data_scan_ctx_advance (tf, &c, len);
3972 /* we continue until we find a start of frame marker */
3973 } else if (marker == 0xe1 && len >= (2 + 4) && /* APP1 */
3974 data_scan_ctx_memcmp (tf, &c, 2, "Exif", 4)) {
3975 GST_LOG ("found Exif tag");
3976 prob = GST_TYPE_FIND_MAXIMUM;
3977 data_scan_ctx_advance (tf, &c, len);
3979 /* we continue until we find a start of frame marker */
3980 } else if (marker >= 0xe0 && marker <= 0xef) { /* APPn */
3981 data_scan_ctx_advance (tf, &c, len);
3983 } else if (JPEG_MARKER_IS_START_OF_FRAME (marker) && len >= (2 + 8)) {
3986 h = GST_READ_UINT16_BE (c.data + 2 + 1);
3987 w = GST_READ_UINT16_BE (c.data + 2 + 1 + 2);
3988 if (h == 0 || w == 0) {
3989 GST_WARNING ("bad width %u and/or height %u in SOF header", w, h);
3993 GST_LOG ("SOF at offset %" G_GUINT64_FORMAT ", num_markers=%d, "
3994 "WxH=%dx%d", c.offset - 2, num_markers, w, h);
3996 if (num_markers >= 5 || prob == GST_TYPE_FIND_MAXIMUM)
3997 prob = GST_TYPE_FIND_MAXIMUM;
3999 prob = GST_TYPE_FIND_LIKELY;
4001 gst_caps_set_simple (caps, "width", G_TYPE_INT, w,
4002 "height", G_TYPE_INT, h, "sof-marker", G_TYPE_INT, marker & 0xf,
4007 GST_WARNING ("bad length or unexpected JPEG marker 0xff 0x%02x", marker);
4012 gst_type_find_suggest (tf, prob, caps);
4013 gst_caps_unref (caps);
4018 static GstStaticCaps bmp_caps = GST_STATIC_CAPS ("image/bmp");
4020 #define BMP_CAPS (gst_static_caps_get(&bmp_caps))
4022 bmp_type_find (GstTypeFind * tf, gpointer unused)
4024 DataScanCtx c = { 0, NULL, 0 };
4025 guint32 struct_size, w, h, planes, bpp;
4027 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 54)))
4030 if (c.data[0] != 'B' || c.data[1] != 'M')
4033 /* skip marker + size */
4034 data_scan_ctx_advance (tf, &c, 2 + 4);
4036 /* reserved, must be 0 */
4037 if (c.data[0] != 0 || c.data[1] != 0 || c.data[2] != 0 || c.data[3] != 0)
4040 data_scan_ctx_advance (tf, &c, 2 + 2);
4042 /* offset to start of image data in bytes (check for sanity) */
4043 GST_LOG ("offset=%u", GST_READ_UINT32_LE (c.data));
4044 if (GST_READ_UINT32_LE (c.data) > (10 * 1024 * 1024))
4047 struct_size = GST_READ_UINT32_LE (c.data + 4);
4048 GST_LOG ("struct_size=%u", struct_size);
4050 data_scan_ctx_advance (tf, &c, 4 + 4);
4052 if (struct_size == 0x0C) {
4053 w = GST_READ_UINT16_LE (c.data);
4054 h = GST_READ_UINT16_LE (c.data + 2);
4055 planes = GST_READ_UINT16_LE (c.data + 2 + 2);
4056 bpp = GST_READ_UINT16_LE (c.data + 2 + 2 + 2);
4057 } else if (struct_size == 40 || struct_size == 64 || struct_size == 108
4058 || struct_size == 124 || struct_size == 0xF0) {
4059 w = GST_READ_UINT32_LE (c.data);
4060 h = GST_READ_UINT32_LE (c.data + 4);
4061 planes = GST_READ_UINT16_LE (c.data + 4 + 4);
4062 bpp = GST_READ_UINT16_LE (c.data + 4 + 4 + 2);
4067 /* image sizes sanity check */
4068 GST_LOG ("w=%u, h=%u, planes=%u, bpp=%u", w, h, planes, bpp);
4069 if (w == 0 || w > 0xfffff || h == 0 || h > 0xfffff || planes != 1 ||
4070 (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32))
4073 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "image/bmp",
4074 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, "bpp", G_TYPE_INT, bpp,
4078 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4079 /*** image/tiff ***/
4080 static GstStaticCaps tiff_caps = GST_STATIC_CAPS ("image/tiff, "
4081 "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }");
4082 #define TIFF_CAPS (gst_static_caps_get(&tiff_caps))
4083 static GstStaticCaps tiff_be_caps = GST_STATIC_CAPS ("image/tiff, "
4084 "endianness = (int) BIG_ENDIAN");
4085 #define TIFF_BE_CAPS (gst_static_caps_get(&tiff_be_caps))
4086 static GstStaticCaps tiff_le_caps = GST_STATIC_CAPS ("image/tiff, "
4087 "endianness = (int) LITTLE_ENDIAN");
4088 #define TIFF_LE_CAPS (gst_static_caps_get(&tiff_le_caps))
4090 tiff_type_find (GstTypeFind * tf, gpointer ununsed)
4092 const guint8 *data = gst_type_find_peek (tf, 0, 8);
4093 guint8 le_header[4] = { 0x49, 0x49, 0x2A, 0x00 };
4094 guint8 be_header[4] = { 0x4D, 0x4D, 0x00, 0x2A };
4097 if (memcmp (data, le_header, 4) == 0) {
4098 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_LE_CAPS);
4099 } else if (memcmp (data, be_header, 4) == 0) {
4100 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_BE_CAPS);
4106 /*** image/x-exr ***/
4107 static GstStaticCaps exr_caps = GST_STATIC_CAPS ("image/x-exr");
4108 #define EXR_CAPS (gst_static_caps_get(&exr_caps))
4110 exr_type_find (GstTypeFind * tf, gpointer ununsed)
4112 const guint8 *data = gst_type_find_peek (tf, 0, 8);
4117 if (GST_READ_UINT32_LE (data) != 0x01312f76)
4120 flags = GST_READ_UINT32_LE (data + 4);
4121 if ((flags & 0xff) != 1 && (flags & 0xff) != 2)
4124 /* If bit 9 is set, bit 11 and 12 must be 0 */
4125 if ((flags & 0x200) && (flags & 0x1800))
4128 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, EXR_CAPS);
4135 static GstStaticCaps pnm_caps = GST_STATIC_CAPS ("image/x-portable-bitmap; "
4136 "image/x-portable-graymap; image/x-portable-pixmap; "
4137 "image/x-portable-anymap");
4139 #define PNM_CAPS (gst_static_caps_get(&pnm_caps))
4141 #define IS_PNM_WHITESPACE(c) \
4142 ((c) == ' ' || (c) == '\r' || (c) == '\n' || (c) == 't')
4145 pnm_type_find (GstTypeFind * tf, gpointer ununsed)
4147 const gchar *media_type = NULL;
4148 DataScanCtx c = { 0, NULL, 0 };
4151 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
4154 /* see http://en.wikipedia.org/wiki/Netpbm_format */
4155 if (c.data[0] != 'P' || c.data[1] < '1' || c.data[1] > '7' ||
4156 !IS_PNM_WHITESPACE (c.data[2]) ||
4157 (c.data[3] != '#' && c.data[3] < '0' && c.data[3] > '9'))
4160 switch (c.data[1]) {
4162 media_type = "image/x-portable-bitmap"; /* ASCII */
4165 media_type = "image/x-portable-graymap"; /* ASCII */
4168 media_type = "image/x-portable-pixmap"; /* ASCII */
4171 media_type = "image/x-portable-bitmap"; /* Raw */
4174 media_type = "image/x-portable-graymap"; /* Raw */
4177 media_type = "image/x-portable-pixmap"; /* Raw */
4180 media_type = "image/x-portable-anymap";
4183 g_return_if_reached ();
4186 /* try to extract width and height as well */
4187 if (c.data[1] != '7') {
4188 gchar s[64] = { 0, }
4191 /* need to skip any comment lines first */
4192 data_scan_ctx_advance (tf, &c, 3);
4194 if (!data_scan_ctx_ensure_data (tf, &c, 1))
4197 while (c.data[0] == '#') { /* we know there's still data left */
4198 data_scan_ctx_advance (tf, &c, 1);
4199 if (!data_scan_ctx_ensure_data (tf, &c, 1))
4202 while (c.data[0] != '\n' && c.data[0] != '\r') {
4203 data_scan_ctx_advance (tf, &c, 1);
4204 if (!data_scan_ctx_ensure_data (tf, &c, 1))
4207 data_scan_ctx_advance (tf, &c, 1);
4208 GST_LOG ("skipped comment line in PNM header");
4209 if (!data_scan_ctx_ensure_data (tf, &c, 1))
4213 if (!data_scan_ctx_ensure_data (tf, &c, 32) &&
4214 !data_scan_ctx_ensure_data (tf, &c, 4)) {
4218 /* need to NUL-terminate data for sscanf */
4219 memcpy (s, c.data, MIN (sizeof (s) - 1, c.size));
4220 if (sscanf (s, "%u%c%u%c", &w, &sep1, &h, &sep2) == 4 &&
4221 IS_PNM_WHITESPACE (sep1) && IS_PNM_WHITESPACE (sep2) &&
4222 w > 0 && w < G_MAXINT && h > 0 && h < G_MAXINT) {
4223 GST_LOG ("extracted PNM width and height: %dx%d", w, h);
4229 /* FIXME: extract width + height for anymaps too */
4232 if (w > 0 && h > 0) {
4233 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type,
4234 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, NULL);
4236 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, media_type, NULL);
4240 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4241 static GstStaticCaps sds_caps = GST_STATIC_CAPS ("audio/x-sds");
4243 #define SDS_CAPS (gst_static_caps_get(&sds_caps))
4245 sds_type_find (GstTypeFind * tf, gpointer ununsed)
4247 const guint8 *data = gst_type_find_peek (tf, 0, 4);
4248 guint8 mask[4] = { 0xFF, 0xFF, 0x80, 0xFF };
4249 guint8 match[4] = { 0xF0, 0x7E, 0, 0x01 };
4253 for (x = 0; x < 4; x++) {
4254 if ((data[x] & mask[x]) != match[x]) {
4258 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDS_CAPS);
4262 static GstStaticCaps ircam_caps = GST_STATIC_CAPS ("audio/x-ircam");
4264 #define IRCAM_CAPS (gst_static_caps_get(&ircam_caps))
4266 ircam_type_find (GstTypeFind * tf, gpointer ununsed)
4268 const guint8 *data = gst_type_find_peek (tf, 0, 4);
4269 guint8 mask[4] = { 0xFF, 0xFF, 0xF8, 0xFF };
4270 guint8 match[4] = { 0x64, 0xA3, 0x00, 0x00 };
4272 gboolean matched = TRUE;
4277 for (x = 0; x < 4; x++) {
4278 if ((data[x] & mask[x]) != match[x]) {
4283 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, IRCAM_CAPS);
4286 /* now try the reverse version */
4288 for (x = 0; x < 4; x++) {
4289 if ((data[x] & mask[3 - x]) != match[3 - x]) {
4295 /*** Matroska/WebM ***/
4297 #define EBML_HEADER 0x1A45DFA3
4298 #define EBML_VERSION 0x4286
4299 #define EBML_DOCTYPE 0x4282
4300 #define EBML_DOCTYPE_VERSION 0x4287
4301 #define MATROSKA_SEGMENT 0x18538067
4302 #define MATROSKA_CLUSTER 0x1F43B675
4303 #define MATROSKA_TRACKS 0x1654AE6B
4304 #define MATROSKA_TRACK_ENTRY 0xAE
4305 #define MATROSKA_TRACK_TYPE 0x83
4306 #define MATROSKA_STEREO_MODE 0x53B8
4308 #define EBML_MAX_LEN (2 * 1024 * 1024)
4312 EBML_DOCTYPE_UNKNOWN = 0,
4313 EBML_DOCTYPE_MATROSKA,
4319 GstEbmlDocType doctype;
4325 guint tracks_ok; /* if we've seen and fully parsed the TRACKS element */
4329 ebml_read_chunk_header (GstTypeFind * tf, DataScanCtx * c, guint max_size,
4330 guint32 * id, guint64 * size)
4333 guint msbit_set, i, len, id_len;
4335 if (c->size < 12 || max_size < 1)
4340 if ((c->data[0] & 0x80) == 0x80) {
4342 } else if ((c->data[0] & 0xC0) == 0x40) {
4344 } else if ((c->data[0] & 0xE0) == 0x20) {
4346 } else if ((c->data[0] & 0xF0) == 0x10) {
4352 if (max_size < id_len)
4355 for (i = 1; i < id_len; ++i) {
4356 *id = (*id << 8) | c->data[i];
4359 data_scan_ctx_advance (tf, c, id_len);
4363 if (max_size < 1 || c->data[0] == 0)
4366 msbit_set = g_bit_nth_msf (c->data[0], 8);
4367 mask = ((1 << msbit_set) - 1);
4368 *size = c->data[0] & mask;
4369 len = 7 - msbit_set;
4371 if (max_size < 1 + len)
4373 for (i = 0; i < len; ++i) {
4374 mask = (mask << 8) | 0xff;
4375 *size = (*size << 8) | c->data[1 + i];
4378 data_scan_ctx_advance (tf, c, 1 + len);
4380 /* undefined/unknown size? (all bits 1) */
4381 if (*size == mask) {
4382 /* allow unknown size for SEGMENT chunk, bail out otherwise */
4383 if (*id == MATROSKA_SEGMENT)
4384 *size = G_MAXUINT64;
4389 return id_len + (1 + len);
4393 ebml_parse_chunk (GstTypeFind * tf, DataScanCtx * ctx, guint32 chunk_id,
4394 guint chunk_size, GstMatroskaInfo * info, guint depth)
4395 { /* FIXME: make sure input size is clipped to 32 bit */
4396 static const gchar SPACES[] = " ";
4397 DataScanCtx c = *ctx;
4398 guint64 element_size = 0;
4399 guint32 id, hdr_len;
4401 if (depth >= 8) /* keep SPACES large enough for depth */
4404 while (chunk_size > 0) {
4405 if (c.offset > EBML_MAX_LEN || !data_scan_ctx_ensure_data (tf, &c, 64))
4408 hdr_len = ebml_read_chunk_header (tf, &c, chunk_size, &id, &element_size);
4412 g_assert (hdr_len <= chunk_size);
4413 chunk_size -= hdr_len;
4415 if (element_size > chunk_size)
4418 GST_DEBUG ("%s %08x, size %" G_GUINT64_FORMAT " / %" G_GUINT64_FORMAT,
4419 SPACES + sizeof (SPACES) - 1 - (2 * depth), id, element_size,
4420 hdr_len + element_size);
4422 if (element_size >= G_MAXUINT32) {
4423 GST_DEBUG ("Chunk too big for typefinding");
4427 if (!data_scan_ctx_ensure_data (tf, &c, element_size)) {
4428 GST_DEBUG ("not enough data");
4434 if (element_size >= 8 && memcmp (c.data, "matroska", 8) == 0)
4435 info->doctype = EBML_DOCTYPE_MATROSKA;
4436 else if (element_size >= 4 && memcmp (c.data, "webm", 4) == 0)
4437 info->doctype = EBML_DOCTYPE_WEBM;
4439 case MATROSKA_SEGMENT:
4440 GST_LOG ("parsing segment");
4441 ebml_parse_chunk (tf, &c, id, element_size, info, depth + 1);
4442 GST_LOG ("parsed segment, done");
4444 case MATROSKA_TRACKS:
4445 GST_LOG ("parsing tracks");
4447 ebml_parse_chunk (tf, &c, id, element_size, info, depth + 1);
4448 GST_LOG ("parsed tracks: %s, done (after %" G_GUINT64_FORMAT " bytes)",
4449 info->tracks_ok ? "ok" : "FAIL", c.offset + element_size);
4451 case MATROSKA_TRACK_ENTRY:
4452 GST_LOG ("parsing track entry");
4453 if (!ebml_parse_chunk (tf, &c, id, element_size, info, depth + 1))
4456 case MATROSKA_TRACK_TYPE:{
4459 /* is supposed to always be 1-byte, but not everyone's following that */
4460 for (i = 0; i < element_size; ++i)
4461 type = (type << 8) | c.data[i];
4463 GST_DEBUG ("%s track type %u",
4464 SPACES + sizeof (SPACES) - 1 - (2 * depth), type);
4468 else if (c.data[0] == 2)
4474 case MATROSKA_STEREO_MODE:
4475 ++info->video_stereo;
4477 case MATROSKA_CLUSTER:
4478 GST_WARNING ("cluster, bailing out (should've found tracks by now)");
4483 data_scan_ctx_advance (tf, &c, element_size);
4484 chunk_size -= element_size;
4491 static GstStaticCaps matroska_caps = GST_STATIC_CAPS ("video/x-matroska");
4493 #define MATROSKA_CAPS (gst_static_caps_get(&matroska_caps))
4495 matroska_type_find (GstTypeFind * tf, gpointer ununsed)
4497 GstTypeFindProbability prob;
4498 GstMatroskaInfo info = { 0, };
4499 const gchar *type_name;
4500 DataScanCtx c = { 0, NULL, 0 };
4503 guint32 id, hdr_len;
4505 if (!data_scan_ctx_ensure_data (tf, &c, 64))
4508 if (GST_READ_UINT32_BE (c.data) != EBML_HEADER)
4511 while (c.offset < EBML_MAX_LEN && data_scan_ctx_ensure_data (tf, &c, 64)) {
4512 hdr_len = ebml_read_chunk_header (tf, &c, c.size, &id, &size);
4516 GST_INFO ("=== top-level chunk %08x, size %" G_GUINT64_FORMAT
4517 " / %" G_GUINT64_FORMAT, id, size, size + hdr_len);
4519 if (!ebml_parse_chunk (tf, &c, id, size, &info, 0))
4521 data_scan_ctx_advance (tf, &c, size);
4522 GST_INFO ("=== done with chunk %08x", id);
4523 if (id == MATROSKA_SEGMENT)
4527 GST_INFO ("audio=%u video=%u other=%u chunks=%u doctype=%d all_tracks=%d",
4528 info.audio, info.video, info.other, info.chunks, info.doctype,
4531 /* perhaps we should bail out if tracks_ok is FALSE and wait for more data?
4532 * (we would need new API to signal this properly and prevent other
4533 * typefinders from taking over the decision then) */
4534 is_audio = (info.audio > 0 && info.video == 0 && info.other == 0);
4536 if (info.doctype == EBML_DOCTYPE_WEBM) {
4537 type_name = (is_audio) ? "audio/webm" : "video/webm";
4538 } else if (info.video > 0 && info.video_stereo) {
4539 type_name = "video/x-matroska-3d";
4541 type_name = (is_audio) ? "audio/x-matroska" : "video/x-matroska";
4544 if (info.doctype == EBML_DOCTYPE_UNKNOWN)
4545 prob = GST_TYPE_FIND_LIKELY;
4547 prob = GST_TYPE_FIND_MAXIMUM;
4549 gst_type_find_suggest_simple (tf, prob, type_name, NULL);
4552 /*** application/mxf ***/
4553 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4554 static GstStaticCaps mxf_caps = GST_STATIC_CAPS ("application/mxf");
4556 #define MXF_MAX_PROBE_LENGTH (1024 * 64)
4557 #define MXF_CAPS (gst_static_caps_get(&mxf_caps))
4560 * MXF files start with a header partition pack key of 16 bytes which is defined
4561 * at SMPTE-377M 6.1. Before this there can be up to 64K of run-in which _must_
4562 * not contain the partition pack key.
4565 mxf_type_find (GstTypeFind * tf, gpointer ununsed)
4567 static const guint8 partition_pack_key[] =
4568 { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
4571 DataScanCtx c = { 0, NULL, 0 };
4573 while (c.offset <= MXF_MAX_PROBE_LENGTH) {
4575 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 1024)))
4578 /* look over in chunks of 1kbytes to avoid too much overhead */
4580 for (i = 0; i < 1024 - 16; i++) {
4581 /* Check first byte before calling more expensive memcmp function */
4582 if (G_UNLIKELY (c.data[i] == 0x06
4583 && memcmp (c.data + i, partition_pack_key, 13) == 0)) {
4584 /* Header partition pack? */
4585 if (c.data[i + 13] != 0x02)
4588 /* Partition status */
4589 if (c.data[i + 14] >= 0x05)
4592 /* Reserved, must be 0x00 */
4593 if (c.data[i + 15] != 0x00)
4596 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
4602 data_scan_ctx_advance (tf, &c, 1024 - 16);
4606 /*** video/x-dv ***/
4608 static GstStaticCaps dv_caps = GST_STATIC_CAPS ("video/x-dv, "
4609 "systemstream = (boolean) true");
4610 #define DV_CAPS (gst_static_caps_get(&dv_caps))
4612 dv_type_find (GstTypeFind * tf, gpointer private)
4616 data = gst_type_find_peek (tf, 0, 5);
4618 /* check for DIF and DV flag */
4619 if (data && (data[0] == 0x1f) && (data[1] == 0x07) && (data[2] == 0x00)) {
4620 const gchar *format;
4622 if (data[3] & 0x80) {
4628 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "video/x-dv",
4629 "systemstream", G_TYPE_BOOLEAN, TRUE,
4630 "format", G_TYPE_STRING, format, NULL);
4635 /*** Ogg variants ***/
4636 static GstStaticCaps ogg_caps =
4637 GST_STATIC_CAPS ("application/ogg;video/ogg;audio/ogg;application/kate");
4639 #define OGG_CAPS (gst_static_caps_get(&ogg_caps))
4653 ogganx_type_find (GstTypeFind * tf, gpointer private)
4655 const gchar *media_type;
4656 DataScanCtx c = { 0, NULL, 0 };
4657 guint ogg_syncs = 0;
4658 guint hdr_count[OGG_NUM] = { 0, };
4661 const gchar marker[10];
4663 GstOggStreamType stream_type;
4666 "\001vorbis", 7, OGG_AUDIO}, {
4667 "\200theora", 7, OGG_VIDEO}, {
4668 "fLaC", 4, OGG_AUDIO}, {
4669 "\177FLAC", 5, OGG_AUDIO}, {
4670 "Speex", 5, OGG_AUDIO}, {
4671 "CMML\0\0\0\0", 8, OGG_OTHER}, {
4672 "PCM ", 8, OGG_AUDIO}, {
4673 "Annodex", 7, OGG_ANNODEX}, {
4674 "fishead", 7, OGG_SKELETON}, {
4675 "AnxData", 7, OGG_ANNODEX}, {
4676 "CELT ", 8, OGG_AUDIO}, {
4677 "\200kate\0\0\0", 8, OGG_KATE}, {
4678 "BBCD\0", 5, OGG_VIDEO}, {
4679 "OVP80\1\1", 7, OGG_VIDEO}, {
4680 "OpusHead", 8, OGG_AUDIO}, {
4681 "\001audio\0\0\0", 9, OGG_AUDIO}, {
4682 "\001video\0\0\0", 9, OGG_VIDEO}, {
4683 "\001text\0\0\0", 9, OGG_OTHER}
4686 while (c.offset < 4096 && data_scan_ctx_ensure_data (tf, &c, 64)) {
4689 if (memcmp (c.data, "OggS", 5) != 0)
4695 if (c.data[5] != 0x02)
4698 /* headers should only have one segment */
4699 if (c.data[26] != 1)
4706 data_scan_ctx_advance (tf, &c, 28);
4708 if (!data_scan_ctx_ensure_data (tf, &c, MAX (size, 8)))
4711 for (i = 0; i < G_N_ELEMENTS (markers); ++i) {
4712 if (memcmp (c.data, markers[i].marker, markers[i].marker_size) == 0) {
4713 ++hdr_count[markers[i].stream_type];
4718 if (i == G_N_ELEMENTS (markers)) {
4719 GST_MEMDUMP ("unknown Ogg stream marker", c.data, size);
4720 ++hdr_count[OGG_OTHER];
4723 data_scan_ctx_advance (tf, &c, size);
4729 /* We don't bother with annodex types. FIXME: what about XSPF? */
4730 if (hdr_count[OGG_VIDEO] > 0) {
4731 media_type = "video/ogg";
4732 } else if (hdr_count[OGG_AUDIO] > 0) {
4733 media_type = "audio/ogg";
4734 } else if (hdr_count[OGG_KATE] > 0 && hdr_count[OGG_OTHER] == 0) {
4735 media_type = "application/kate";
4737 media_type = "application/ogg";
4740 GST_INFO ("found %s (audio:%u, video:%u, annodex:%u, skeleton:%u, other:%u)",
4741 media_type, hdr_count[OGG_AUDIO], hdr_count[OGG_VIDEO],
4742 hdr_count[OGG_ANNODEX], hdr_count[OGG_SKELETON], hdr_count[OGG_OTHER]);
4744 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type, NULL);
4747 /*** audio/x-vorbis ***/
4748 static GstStaticCaps vorbis_caps = GST_STATIC_CAPS ("audio/x-vorbis");
4750 #define VORBIS_CAPS (gst_static_caps_get(&vorbis_caps))
4752 vorbis_type_find (GstTypeFind * tf, gpointer private)
4754 const guint8 *data = gst_type_find_peek (tf, 0, 30);
4760 /* 1 byte packet type (identification=0x01)
4761 6 byte string "vorbis"
4762 4 byte vorbis version */
4763 if (memcmp (data, "\001vorbis\000\000\000\000", 11) != 0)
4766 /* 1 byte channels must be != 0 */
4770 /* 4 byte samplerate must be != 0 */
4771 if (GST_READ_UINT32_LE (data) == 0)
4774 /* blocksize checks */
4775 blocksize_0 = data[0] & 0x0F;
4776 blocksize_1 = (data[0] & 0xF0) >> 4;
4777 if (blocksize_0 > blocksize_1)
4779 if (blocksize_0 < 6 || blocksize_0 > 13)
4781 if (blocksize_1 < 6 || blocksize_1 > 13)
4785 if ((data[0] & 0x01) != 1)
4787 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VORBIS_CAPS);
4791 /*** video/x-theora ***/
4793 static GstStaticCaps theora_caps = GST_STATIC_CAPS ("video/x-theora");
4795 #define THEORA_CAPS (gst_static_caps_get(&theora_caps))
4797 theora_type_find (GstTypeFind * tf, gpointer private)
4799 const guint8 *data = gst_type_find_peek (tf, 0, 7); //42);
4802 if (data[0] != 0x80)
4804 if (memcmp (&data[1], "theora", 6) != 0)
4806 /* FIXME: make this more reliable when specs are out */
4808 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, THEORA_CAPS);
4812 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4815 kate_type_find (GstTypeFind * tf, gpointer private)
4817 const guint8 *data = gst_type_find_peek (tf, 0, 64);
4818 gchar category[16] = { 0, };
4820 if (G_UNLIKELY (data == NULL))
4823 /* see: http://wiki.xiph.org/index.php/OggKate#Format_specification */
4824 if (G_LIKELY (memcmp (data, "\200kate\0\0\0", 8) != 0))
4827 /* make sure we always have a NUL-terminated string */
4828 memcpy (category, data + 48, 15);
4829 GST_LOG ("kate category: %s", category);
4830 /* canonical categories for subtitles: subtitles, spu-subtitles, SUB, K-SPU */
4831 if (strcmp (category, "subtitles") == 0 || strcmp (category, "SUB") == 0 ||
4832 strcmp (category, "spu-subtitles") == 0 ||
4833 strcmp (category, "K-SPU") == 0) {
4834 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
4835 "subtitle/x-kate", NULL);
4837 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
4838 "application/x-kate", NULL);
4843 /*** WEBVTTT subtitles ***/
4844 static GstStaticCaps webvtt_caps =
4845 GST_STATIC_CAPS ("application/x-subtitle-vtt, parsed=(boolean)false");
4846 #define WEBVTT_CAPS (gst_static_caps_get(&webvtt_caps))
4849 webvtt_type_find (GstTypeFind * tf, gpointer private)
4853 data = gst_type_find_peek (tf, 0, 10);
4858 /* there might be a UTF-8 BOM at the beginning */
4859 if (memcmp (data, "WEBVTT", 6) != 0 && memcmp (data + 3, "WEBVTT", 6) != 0) {
4863 if (data[0] != 'W') {
4864 if (data[0] != 0xef || data[1] != 0xbb || data[2] != 0xbf)
4865 return; /* Not a UTF-8 BOM */
4869 /* After the WEBVTT magic must be one of these chars:
4870 * 0x20 (space), 0x9 (tab), 0xa (LF) or 0xd (CR) */
4871 if (data[6] != 0x20 && data[6] != 0x9 && data[6] != 0xa && data[6] != 0xd) {
4875 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, WEBVTT_CAPS);
4878 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4879 /*** application/x-ogm-video or audio***/
4881 static GstStaticCaps ogmvideo_caps =
4882 GST_STATIC_CAPS ("application/x-ogm-video");
4883 #define OGMVIDEO_CAPS (gst_static_caps_get(&ogmvideo_caps))
4885 ogmvideo_type_find (GstTypeFind * tf, gpointer private)
4887 const guint8 *data = gst_type_find_peek (tf, 0, 9);
4890 if (memcmp (data, "\001video\000\000\000", 9) != 0)
4892 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMVIDEO_CAPS);
4896 static GstStaticCaps ogmaudio_caps =
4897 GST_STATIC_CAPS ("application/x-ogm-audio");
4898 #define OGMAUDIO_CAPS (gst_static_caps_get(&ogmaudio_caps))
4900 ogmaudio_type_find (GstTypeFind * tf, gpointer private)
4902 const guint8 *data = gst_type_find_peek (tf, 0, 9);
4905 if (memcmp (data, "\001audio\000\000\000", 9) != 0)
4907 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMAUDIO_CAPS);
4911 static GstStaticCaps ogmtext_caps = GST_STATIC_CAPS ("application/x-ogm-text");
4913 #define OGMTEXT_CAPS (gst_static_caps_get(&ogmtext_caps))
4915 ogmtext_type_find (GstTypeFind * tf, gpointer private)
4917 const guint8 *data = gst_type_find_peek (tf, 0, 9);
4920 if (memcmp (data, "\001text\000\000\000\000", 9) != 0)
4922 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMTEXT_CAPS);
4926 /*** audio/x-speex ***/
4928 static GstStaticCaps speex_caps = GST_STATIC_CAPS ("audio/x-speex");
4930 #define SPEEX_CAPS (gst_static_caps_get(&speex_caps))
4932 speex_type_find (GstTypeFind * tf, gpointer private)
4934 const guint8 *data = gst_type_find_peek (tf, 0, 80);
4937 /* 8 byte string "Speex "
4938 24 byte speex version string + int */
4939 if (memcmp (data, "Speex ", 8) != 0)
4943 /* 4 byte header size >= 80 */
4944 if (GST_READ_UINT32_LE (data) < 80)
4948 /* 4 byte sample rate <= 48000 */
4949 if (GST_READ_UINT32_LE (data) > 48000)
4953 /* currently there are only 3 speex modes. */
4954 if (GST_READ_UINT32_LE (data) > 3)
4958 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SPEEX_CAPS);
4962 /*** audio/x-celt ***/
4964 static GstStaticCaps celt_caps = GST_STATIC_CAPS ("audio/x-celt");
4966 #define CELT_CAPS (gst_static_caps_get(&celt_caps))
4968 celt_type_find (GstTypeFind * tf, gpointer private)
4970 const guint8 *data = gst_type_find_peek (tf, 0, 8);
4973 /* 8 byte string "CELT " */
4974 if (memcmp (data, "CELT ", 8) != 0)
4977 /* TODO: Check other values of the CELT header */
4978 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CELT_CAPS);
4982 /*** application/x-ogg-skeleton ***/
4983 static GstStaticCaps ogg_skeleton_caps =
4984 GST_STATIC_CAPS ("application/x-ogg-skeleton, parsed=(boolean)FALSE");
4985 #define OGG_SKELETON_CAPS (gst_static_caps_get(&ogg_skeleton_caps))
4987 oggskel_type_find (GstTypeFind * tf, gpointer private)
4989 const guint8 *data = gst_type_find_peek (tf, 0, 12);
4992 /* 8 byte string "fishead\0" for the ogg skeleton stream */
4993 if (memcmp (data, "fishead\0", 8) != 0)
4997 /* Require that the header contains version 3.0 */
4998 if (GST_READ_UINT16_LE (data) != 3)
5001 if (GST_READ_UINT16_LE (data) != 0)
5004 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGG_SKELETON_CAPS);
5008 static GstStaticCaps cmml_caps = GST_STATIC_CAPS ("text/x-cmml");
5010 #define CMML_CAPS (gst_static_caps_get(&cmml_caps))
5012 cmml_type_find (GstTypeFind * tf, gpointer private)
5014 /* Header is 12 bytes minimum (though we don't check the minor version */
5015 const guint8 *data = gst_type_find_peek (tf, 0, 12);
5019 /* 8 byte string "CMML\0\0\0\0" for the magic number */
5020 if (memcmp (data, "CMML\0\0\0\0", 8) != 0)
5024 /* Require that the header contains at least version 2.0 */
5025 if (GST_READ_UINT16_LE (data) < 2)
5028 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CMML_CAPS);
5032 /*** application/x-tar ***/
5034 static GstStaticCaps tar_caps = GST_STATIC_CAPS ("application/x-tar");
5036 #define TAR_CAPS (gst_static_caps_get(&tar_caps))
5037 #define OLDGNU_MAGIC "ustar " /* 7 chars and a NUL */
5038 #define NEWGNU_MAGIC "ustar" /* 5 chars and a NUL */
5040 tar_type_find (GstTypeFind * tf, gpointer unused)
5042 const guint8 *data = gst_type_find_peek (tf, 257, 8);
5044 /* of course we are not certain, but we don't want other typefind funcs
5045 * to detect formats of files within the tar archive, e.g. mp3s */
5047 if (memcmp (data, OLDGNU_MAGIC, 8) == 0) { /* sic */
5048 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
5049 } else if (memcmp (data, NEWGNU_MAGIC, 6) == 0 && /* sic */
5050 g_ascii_isdigit (data[6]) && g_ascii_isdigit (data[7])) {
5051 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
5056 /*** application/x-ar ***/
5058 static GstStaticCaps ar_caps = GST_STATIC_CAPS ("application/x-ar");
5060 #define AR_CAPS (gst_static_caps_get(&ar_caps))
5062 ar_type_find (GstTypeFind * tf, gpointer unused)
5064 const guint8 *data = gst_type_find_peek (tf, 0, 24);
5066 if (data && memcmp (data, "!<arch>", 7) == 0) {
5069 for (i = 7; i < 24; ++i) {
5070 if (!g_ascii_isprint (data[i]) && data[i] != '\n') {
5071 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AR_CAPS);
5075 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AR_CAPS);
5080 /*** audio/x-au ***/
5082 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
5083 * as it is only possible to register one typefind factory per 'name'
5084 * (which is in this case the caps), and the first one would be replaced by
5085 * the second one. */
5086 static GstStaticCaps au_caps = GST_STATIC_CAPS ("audio/x-au");
5088 #define AU_CAPS (gst_static_caps_get(&au_caps))
5090 au_type_find (GstTypeFind * tf, gpointer unused)
5092 const guint8 *data = gst_type_find_peek (tf, 0, 4);
5095 if (memcmp (data, ".snd", 4) == 0 || memcmp (data, "dns.", 4) == 0) {
5096 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AU_CAPS);
5102 /*** video/x-nuv ***/
5104 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
5105 * as it is only possible to register one typefind factory per 'name'
5106 * (which is in this case the caps), and the first one would be replaced by
5107 * the second one. */
5108 static GstStaticCaps nuv_caps = GST_STATIC_CAPS ("video/x-nuv");
5110 #define NUV_CAPS (gst_static_caps_get(&nuv_caps))
5112 nuv_type_find (GstTypeFind * tf, gpointer unused)
5114 const guint8 *data = gst_type_find_peek (tf, 0, 11);
5117 if (memcmp (data, "MythTVVideo", 11) == 0
5118 || memcmp (data, "NuppelVideo", 11) == 0) {
5119 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, NUV_CAPS);
5124 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5125 /*** audio/x-paris ***/
5126 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
5127 static GstStaticCaps paris_caps = GST_STATIC_CAPS ("audio/x-paris");
5129 #define PARIS_CAPS (gst_static_caps_get(&paris_caps))
5131 paris_type_find (GstTypeFind * tf, gpointer unused)
5133 const guint8 *data = gst_type_find_peek (tf, 0, 4);
5136 if (memcmp (data, " paf", 4) == 0 || memcmp (data, "fap ", 4) == 0) {
5137 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, PARIS_CAPS);
5142 /*** audio/x-sbc ***/
5143 static GstStaticCaps sbc_caps = GST_STATIC_CAPS ("audio/x-sbc");
5144 #define SBC_CAPS (gst_static_caps_get(&sbc_caps))
5147 sbc_check_header (const guint8 * data, gsize len, guint * rate,
5150 static const guint16 sbc_rates[4] = { 16000, 32000, 44100, 48000 };
5151 static const guint8 sbc_blocks[4] = { 4, 8, 12, 16 };
5152 guint n_blocks, ch_mode, n_subbands, bitpool;
5154 if (data[0] != 0x9C || len < 4)
5157 n_blocks = sbc_blocks[(data[1] >> 4) & 0x03];
5158 ch_mode = (data[1] >> 2) & 0x03;
5159 n_subbands = (data[1] & 0x01) ? 8 : 4;
5164 *rate = sbc_rates[(data[1] >> 6) & 0x03];
5165 *channels = (ch_mode == 0) ? 1 : 2;
5168 return 4 + (n_subbands * 1) / 2 + (n_blocks * 1 * bitpool) / 8;
5169 else if (ch_mode == 1)
5170 return 4 + (n_subbands * 2) / 2 + (n_blocks * 2 * bitpool) / 8;
5171 else if (ch_mode == 2)
5172 return 4 + (n_subbands * 2) / 2 + (n_blocks * bitpool) / 8;
5173 else if (ch_mode == 3)
5174 return 4 + (n_subbands * 2) / 2 + (n_subbands + n_blocks * bitpool) / 8;
5180 sbc_type_find (GstTypeFind * tf, gpointer unused)
5184 guint i, rate, channels, offset = 0;
5186 for (i = 0; i < 10; ++i) {
5187 data = gst_type_find_peek (tf, offset, 8);
5191 frame_len = sbc_check_header (data, 8, &rate, &channels);
5195 offset += frame_len;
5197 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE, "audio/x-sbc",
5198 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels,
5199 "parsed", G_TYPE_BOOLEAN, FALSE, NULL);
5202 /*** audio/iLBC-sh ***/
5203 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
5204 static GstStaticCaps ilbc_caps = GST_STATIC_CAPS ("audio/iLBC-sh");
5206 #define ILBC_CAPS (gst_static_caps_get(&ilbc_caps))
5208 ilbc_type_find (GstTypeFind * tf, gpointer unused)
5210 const guint8 *data = gst_type_find_peek (tf, 0, 8);
5213 if (memcmp (data, "#!iLBC30", 8) == 0 || memcmp (data, "#!iLBC20", 8) == 0) {
5214 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, ILBC_CAPS);
5219 /*** application/x-ms-dos-executable ***/
5221 static GstStaticCaps msdos_caps =
5222 GST_STATIC_CAPS ("application/x-ms-dos-executable");
5223 #define MSDOS_CAPS (gst_static_caps_get(&msdos_caps))
5224 /* see http://www.madchat.org/vxdevl/papers/winsys/pefile/pefile.htm */
5226 msdos_type_find (GstTypeFind * tf, gpointer unused)
5228 const guint8 *data = gst_type_find_peek (tf, 0, 64);
5230 if (data && data[0] == 'M' && data[1] == 'Z' &&
5231 GST_READ_UINT16_LE (data + 8) == 4) {
5232 guint32 pe_offset = GST_READ_UINT32_LE (data + 60);
5234 data = gst_type_find_peek (tf, pe_offset, 2);
5235 if (data && data[0] == 'P' && data[1] == 'E') {
5236 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, MSDOS_CAPS);
5241 /*** application/x-mmsh ***/
5243 static GstStaticCaps mmsh_caps = GST_STATIC_CAPS ("application/x-mmsh");
5245 #define MMSH_CAPS gst_static_caps_get(&mmsh_caps)
5247 /* This is to recognise mssh-over-http */
5249 mmsh_type_find (GstTypeFind * tf, gpointer unused)
5251 static const guint8 asf_marker[16] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66,
5252 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
5257 data = gst_type_find_peek (tf, 0, 2 + 2 + 4 + 2 + 2 + 16);
5258 if (data && data[0] == 0x24 && data[1] == 0x48 &&
5259 GST_READ_UINT16_LE (data + 2) > 2 + 2 + 4 + 2 + 2 + 16 &&
5260 memcmp (data + 2 + 2 + 4 + 2 + 2, asf_marker, 16) == 0) {
5261 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MMSH_CAPS);
5265 /*** video/x-dirac ***/
5267 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
5268 * as it is only possible to register one typefind factory per 'name'
5269 * (which is in this case the caps), and the first one would be replaced by
5270 * the second one. */
5271 static GstStaticCaps dirac_caps = GST_STATIC_CAPS ("video/x-dirac");
5273 #define DIRAC_CAPS (gst_static_caps_get(&dirac_caps))
5275 dirac_type_find (GstTypeFind * tf, gpointer unused)
5277 const guint8 *data = gst_type_find_peek (tf, 0, 8);
5280 if (memcmp (data, "BBCD", 4) == 0 || memcmp (data, "KW-DIRAC", 8) == 0) {
5281 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DIRAC_CAPS);
5286 /*** audio/x-tap-tap ***/
5288 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
5289 * as it is only possible to register one typefind factory per 'name'
5290 * (which is in this case the caps), and the first one would be replaced by
5291 * the second one. */
5292 static GstStaticCaps tap_caps = GST_STATIC_CAPS ("audio/x-tap-tap");
5294 #define TAP_CAPS (gst_static_caps_get(&tap_caps))
5296 tap_type_find (GstTypeFind * tf, gpointer unused)
5298 const guint8 *data = gst_type_find_peek (tf, 0, 16);
5301 if (memcmp (data, "C64-TAPE-RAW", 12) == 0
5302 || memcmp (data, "C16-TAPE-RAW", 12) == 0) {
5303 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TAP_CAPS);
5308 /*** video/vivo ***/
5310 static GstStaticCaps vivo_caps = GST_STATIC_CAPS ("video/vivo");
5312 #define VIVO_CAPS gst_static_caps_get(&vivo_caps)
5315 vivo_type_find (GstTypeFind * tf, gpointer unused)
5317 static const guint8 vivo_marker[] = { 'V', 'e', 'r', 's', 'i', 'o', 'n',
5318 ':', 'V', 'i', 'v', 'o', '/'
5323 data = gst_type_find_peek (tf, 0, 1024);
5324 if (data == NULL || data[0] != 0x00)
5327 if ((data[1] & 0x80)) {
5328 if ((data[2] & 0x80))
5330 hdr_len = ((guint) (data[1] & 0x7f)) << 7;
5340 /* 1008 = 1022 - strlen ("Version:Vivo/") - 1 */
5341 while (pos < 1008 && data[pos] == '\r' && data[pos + 1] == '\n')
5344 if (memcmp (data + pos, vivo_marker, sizeof (vivo_marker)) == 0) {
5345 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VIVO_CAPS);
5349 /*** XDG MIME typefinder (to avoid false positives mostly) ***/
5353 xdgmime_typefind (GstTypeFind * find, gpointer user_data)
5356 gsize length = 16384;
5361 if ((tf_length = gst_type_find_get_length (find)) > 0)
5362 length = MIN (length, tf_length);
5364 if ((data = gst_type_find_peek (find, 0, length)) == NULL)
5367 tmp = g_content_type_guess (NULL, data, length, NULL);
5368 if (tmp == NULL || g_content_type_is_unknown (tmp)) {
5373 mimetype = g_content_type_get_mime_type (tmp);
5376 if (mimetype == NULL)
5379 GST_DEBUG ("Got mimetype '%s'", mimetype);
5381 /* Ignore audio/video types:
5382 * - our own typefinders in -base are likely to be better at this
5383 * (and if they're not, we really want to fix them, that's why we don't
5384 * report xdg-detected audio/video types at all, not even with a low
5386 * - we want to detect GStreamer media types and not MIME types
5387 * - the purpose of this xdg mime finder is mainly to prevent false
5388 * positives of non-media formats, not to typefind audio/video formats */
5389 if (g_str_has_prefix (mimetype, "audio/") ||
5390 g_str_has_prefix (mimetype, "video/")) {
5391 GST_LOG ("Ignoring audio/video mime type");
5396 /* Again, we mainly want the xdg typefinding to prevent false-positives on
5397 * non-media formats, so suggest the type with a probability that trumps
5398 * uncertain results of our typefinders, but not more than that. */
5399 GST_LOG ("Suggesting '%s' with probability POSSIBLE", mimetype);
5400 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE, mimetype, NULL);
5403 #endif /* USE_GIO */
5405 /*** Windows icon typefinder (to avoid false positives mostly) ***/
5406 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5408 windows_icon_typefind (GstTypeFind * find, gpointer user_data)
5412 guint16 type, nimages;
5413 gint32 size, offset;
5415 datalen = gst_type_find_get_length (find);
5418 if ((data = gst_type_find_peek (find, 0, 6)) == NULL)
5421 /* header - simple and not enough to rely on it alone */
5422 if (GST_READ_UINT16_LE (data) != 0)
5424 type = GST_READ_UINT16_LE (data + 2);
5425 if (type != 1 && type != 2)
5427 nimages = GST_READ_UINT16_LE (data + 4);
5428 if (nimages == 0) /* we can assume we can't have an empty image file ? */
5432 if (data[6 + 3] != 0)
5435 guint16 planes = GST_READ_UINT16_LE (data + 6 + 4);
5439 size = GST_READ_UINT32_LE (data + 6 + 8);
5440 offset = GST_READ_UINT32_LE (data + 6 + 12);
5441 if (offset < 0 || size <= 0 || size >= datalen || offset >= datalen
5442 || size + offset > datalen)
5445 gst_type_find_suggest_simple (find, GST_TYPE_FIND_NEARLY_CERTAIN,
5446 "image/x-icon", NULL);
5449 /*** WAP WBMP typefinder ***/
5452 wbmp_typefind (GstTypeFind * find, gpointer user_data)
5458 /* http://en.wikipedia.org/wiki/Wireless_Application_Protocol_Bitmap_Format */
5459 datalen = gst_type_find_get_length (find);
5463 data = gst_type_find_peek (find, 0, 5);
5467 /* want 0x00 0x00 at start */
5468 if (*data++ != 0 || *data++ != 0)
5471 /* min header size */
5474 /* let's assume max width/height is 65536 */
5477 w = (w << 8) | *data++;
5481 data = gst_type_find_peek (find, 4, 2);
5487 h = (h << 8) | *data++;
5493 if (w == 0 || h == 0)
5496 /* now add bitmap size */
5497 size += h * (GST_ROUND_UP_8 (w) / 8);
5499 if (datalen == size) {
5500 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE - 10,
5501 "image/vnd.wap.wbmp", NULL);
5505 /*** DEGAS Atari images (also to avoid false positives, see #625129) ***/
5507 degas_type_find (GstTypeFind * tf, gpointer private)
5509 /* No magic, but it should have a fixed size and a few invalid values */
5510 /* http://www.fileformat.info/format/atari/spec/6ecf9f6eb5be494284a47feb8a214687/view.htm */
5516 len = gst_type_find_get_length (tf);
5517 if (len < 34) /* smallest header of the lot */
5519 data = gst_type_find_peek (tf, 0, 4);
5520 if (G_UNLIKELY (data == NULL))
5522 resolution = GST_READ_UINT16_BE (data);
5524 /* could be DEGAS */
5525 if (resolution <= 2)
5526 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
5527 "image/x-degas", NULL);
5528 } else if (len == 32066) {
5529 /* could be DEGAS Elite */
5530 if (resolution <= 2) {
5531 data = gst_type_find_peek (tf, len - 16, 8);
5532 if (G_UNLIKELY (data == NULL))
5534 for (n = 0; n < 4; n++) {
5535 if (GST_READ_UINT16_BE (data + n * 2) > 2)
5538 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
5539 "image/x-degas", NULL);
5541 } else if (len >= 66 && len < 32066) {
5542 /* could be compressed DEGAS Elite, but it's compressed and so we can't rely on size,
5543 it does have 4 16 bytes values near the end that are 0-2 though. */
5544 if ((resolution & 0x8000) && (resolution & 0x7fff) <= 2) {
5545 data = gst_type_find_peek (tf, len - 16, 8);
5546 if (G_UNLIKELY (data == NULL))
5548 for (n = 0; n < 4; n++) {
5549 if (GST_READ_UINT16_BE (data + n * 2) > 2)
5552 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
5553 "image/x-degas", NULL);
5561 y4m_typefind (GstTypeFind * tf, gpointer private)
5565 data = gst_type_find_peek (tf, 0, 10);
5566 if (data != NULL && memcmp (data, "YUV4MPEG2 ", 10) == 0) {
5567 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY,
5568 "application/x-yuv4mpeg", "y4mversion", G_TYPE_INT, 2, NULL);
5573 /*** DVD ISO images (looks like H.264, see #674069) ***/
5575 dvdiso_type_find (GstTypeFind * tf, gpointer private)
5577 /* 0x8000 bytes of zeros, then "\001CD001" */
5581 len = gst_type_find_get_length (tf);
5584 data = gst_type_find_peek (tf, 0, 0x8006);
5585 if (G_UNLIKELY (data == NULL))
5587 for (len = 0; len < 0x8000; len++)
5590 /* Can the '1' be anything else ? My three samples all have '1'. */
5591 if (memcmp (data + 0x8000, "\001CD001", 6))
5594 /* May need more inspection, we may be able to demux some of them */
5595 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY,
5596 "application/octet-stream", NULL);
5599 /* SSA/ASS subtitles
5601 * http://en.wikipedia.org/wiki/SubStation_Alpha
5602 * http://matroska.org/technical/specs/subtitles/ssa.html
5605 ssa_type_find (GstTypeFind * tf, gpointer private)
5607 const gchar *start, *end, *ver_str, *media_type = NULL;
5609 gchar *str, *script_type, *p = NULL;
5612 data = gst_type_find_peek (tf, 0, 32);
5617 /* FIXME: detect utf-16/32 BOM and convert before typefinding the rest */
5619 /* there might be a UTF-8 BOM at the beginning */
5620 if (memcmp (data, "[Script Info]", 13) != 0 &&
5621 memcmp (data + 3, "[Script Info]", 13) != 0) {
5625 /* now check if we have SSA or ASS */
5626 len = gst_type_find_get_length (tf);
5630 data = gst_type_find_peek (tf, 0, len);
5635 start = (gchar *) memchr (data, '[', 5);
5637 len -= (start - (gchar *) data);
5639 /* ignore anything non-UTF8 for now, in future we might at least allow
5640 * other UTF variants that are clearly prefixed with the appropriate BOM */
5641 if (!g_utf8_validate (start, len, &end) && (len - (end - start)) > 6) {
5642 GST_FIXME ("non-UTF8 SSA/ASS file");
5646 /* something at start, but not a UTF-8 BOM? */
5647 if (data[0] != '[' && (data[0] != 0xEF || data[1] != 0xBB || data[2] != 0xBF))
5650 /* ignore any partial UTF-8 characters at the end */
5653 /* create a NUL-terminated string so it's easier to process it safely */
5654 str = g_strndup (start, len - 1);
5655 script_type = strstr (str, "ScriptType:");
5656 if (script_type != NULL) {
5659 ver_str = script_type + 11;
5660 while (*ver_str == ' ' || *ver_str == 'v' || *ver_str == 'V')
5662 version = g_ascii_strtod (ver_str, &p);
5663 if (version == 4.0 && p != NULL && *p == '+')
5664 media_type = "application/x-ass";
5665 else if (version >= 1.0 && version <= 4.0)
5666 media_type = "application/x-ssa";
5669 if (media_type == NULL) {
5670 if (strstr (str, "[v4+ Styles]") || strstr (str, "[V4+ Styles]"))
5671 media_type = "application/x-ass";
5672 else if (strstr (str, "[v4 Styles]") || strstr (str, "[V4 Styles]"))
5673 media_type = "application/x-ssa";
5676 if (media_type != NULL) {
5677 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
5678 media_type, "parsed", G_TYPE_BOOLEAN, FALSE, NULL);
5680 GST_WARNING ("could not detect SSA/ASS variant");
5686 /*** application/x-mcc ***/
5687 static GstStaticCaps mcc_caps = GST_STATIC_CAPS ("application/x-mcc");
5689 #define MCC_CAPS gst_static_caps_get(&mcc_caps)
5692 mcc_type_find (GstTypeFind * tf, gpointer private)
5696 data = gst_type_find_peek (tf, 0, 31);
5701 /* MCC files always start with this followed by the version */
5702 if (memcmp (data, "File Format=MacCaption_MCC V", 28) != 0 ||
5703 !g_ascii_isdigit (data[28]) || data[29] != '.' ||
5704 !g_ascii_isdigit (data[30])) {
5708 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
5709 "application/x-mcc", "version", G_TYPE_INT, data[28] - '0', NULL);
5712 /*** video/x-pva ***/
5714 static GstStaticCaps pva_caps = GST_STATIC_CAPS ("video/x-pva");
5716 #define PVA_CAPS gst_static_caps_get(&pva_caps)
5719 pva_type_find (GstTypeFind * tf, gpointer private)
5723 data = gst_type_find_peek (tf, 0, 5);
5728 if (data[0] == 'A' && data[1] == 'V' && data[2] < 3 && data[4] == 0x55)
5729 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, PVA_CAPS);
5732 /*** audio/audible ***/
5734 /* derived from pyaudibletags
5735 * http://code.google.com/p/pyaudibletags/source/browse/trunk/pyaudibletags.py
5737 static GstStaticCaps aa_caps = GST_STATIC_CAPS ("audio/x-audible");
5739 #define AA_CAPS gst_static_caps_get(&aa_caps)
5742 aa_type_find (GstTypeFind * tf, gpointer private)
5746 data = gst_type_find_peek (tf, 0, 12);
5750 if (GST_READ_UINT32_BE (data + 4) == 0x57907536) {
5753 media_len = gst_type_find_get_length (tf);
5754 if (media_len > 0 && GST_READ_UINT32_BE (data) == media_len)
5755 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AA_CAPS);
5757 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AA_CAPS);
5761 /*** generic typefind for streams that have some data at a specific position***/
5772 start_with_type_find (GstTypeFind * tf, gpointer private)
5774 GstTypeFindData *start_with = (GstTypeFindData *) private;
5777 GST_LOG ("trying to find mime type %s with the first %u bytes of data",
5778 gst_structure_get_name (gst_caps_get_structure (start_with->caps, 0)),
5780 data = gst_type_find_peek (tf, 0, start_with->size);
5781 if (data && memcmp (data, start_with->data, start_with->size) == 0) {
5782 gst_type_find_suggest (tf, start_with->probability, start_with->caps);
5787 sw_data_destroy (GstTypeFindData * sw_data)
5789 if (G_LIKELY (sw_data->caps != NULL))
5790 gst_caps_unref (sw_data->caps);
5791 g_slice_free (GstTypeFindData, sw_data);
5794 #define TYPE_FIND_REGISTER_START_WITH(plugin,name,rank,ext,_data,_size,_probability)\
5796 GstTypeFindData *sw_data = g_slice_new (GstTypeFindData); \
5797 sw_data->data = (const guint8 *)_data; \
5798 sw_data->size = _size; \
5799 sw_data->probability = _probability; \
5800 sw_data->caps = gst_caps_new_empty_simple (name); \
5801 if (!gst_type_find_register (plugin, name, rank, start_with_type_find,\
5802 ext, sw_data->caps, sw_data, \
5803 (GDestroyNotify) (sw_data_destroy))) { \
5804 sw_data_destroy (sw_data); \
5808 /*** same for riff types ***/
5811 riff_type_find (GstTypeFind * tf, gpointer private)
5813 GstTypeFindData *riff_data = (GstTypeFindData *) private;
5814 const guint8 *data = gst_type_find_peek (tf, 0, 12);
5816 if (data && (memcmp (data, "RIFF", 4) == 0 || memcmp (data, "AVF0", 4) == 0)) {
5818 if (memcmp (data, riff_data->data, 4) == 0)
5819 gst_type_find_suggest (tf, riff_data->probability, riff_data->caps);
5823 #define TYPE_FIND_REGISTER_RIFF(plugin,name,rank,ext,_data) \
5825 GstTypeFindData *sw_data = g_slice_new (GstTypeFindData); \
5826 sw_data->data = (gpointer)_data; \
5827 sw_data->size = 4; \
5828 sw_data->probability = GST_TYPE_FIND_MAXIMUM; \
5829 sw_data->caps = gst_caps_new_empty_simple (name); \
5830 if (!gst_type_find_register (plugin, name, rank, riff_type_find, \
5831 ext, sw_data->caps, sw_data, \
5832 (GDestroyNotify) (sw_data_destroy))) { \
5833 sw_data_destroy (sw_data); \
5838 /*** plugin initialization ***/
5840 #define TYPE_FIND_REGISTER(plugin,name,rank,func,ext,caps,priv,notify) \
5842 if (!gst_type_find_register (plugin, name, rank, func, ext, caps, priv, notify))\
5848 plugin_init (GstPlugin * plugin)
5850 /* can't initialize this via a struct as caps can't be statically initialized */
5852 GST_DEBUG_CATEGORY_INIT (type_find_debug, "typefindfunctions",
5853 GST_DEBUG_FG_GREEN | GST_DEBUG_BG_RED, "generic type find functions");
5855 /* note: asx/wax/wmx are XML files, asf doesn't handle them */
5856 /* must use strings, macros don't accept initializers */
5857 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ms-asf", GST_RANK_SECONDARY,
5859 "\060\046\262\165\216\146\317\021\246\331\000\252\000\142\316\154", 16,
5860 GST_TYPE_FIND_MAXIMUM);
5861 TYPE_FIND_REGISTER (plugin, "audio/x-musepack", GST_RANK_PRIMARY,
5862 musepack_type_find, "mpc,mpp,mp+", MUSEPACK_CAPS, NULL, NULL);
5863 TYPE_FIND_REGISTER (plugin, "audio/x-au", GST_RANK_MARGINAL,
5864 au_type_find, "au,snd", AU_CAPS, NULL, NULL);
5865 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-msvideo", GST_RANK_PRIMARY,
5867 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5868 TYPE_FIND_REGISTER_RIFF (plugin, "audio/qcelp", GST_RANK_PRIMARY,
5870 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-cdxa", GST_RANK_PRIMARY,
5872 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-vcd", GST_RANK_PRIMARY,
5873 "dat", "\000\377\377\377\377\377\377\377\377\377\377\000", 12,
5874 GST_TYPE_FIND_MAXIMUM);
5876 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-imelody", GST_RANK_PRIMARY,
5877 "imy,ime,imelody", "BEGIN:IMELODY", 13, GST_TYPE_FIND_MAXIMUM);
5878 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-scc", GST_RANK_PRIMARY,
5879 "scc", "Scenarist_SCC V1.0", 18, GST_TYPE_FIND_MAXIMUM);
5880 TYPE_FIND_REGISTER (plugin, "application/x-mcc", GST_RANK_PRIMARY,
5881 mcc_type_find, "mcc", MCC_CAPS, NULL, NULL);
5884 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-smoke", GST_RANK_PRIMARY,
5885 NULL, "\x80smoke\x00\x01\x00", 6, GST_TYPE_FIND_MAXIMUM);
5887 TYPE_FIND_REGISTER (plugin, "audio/midi", GST_RANK_PRIMARY, mid_type_find,
5888 "mid,midi", MID_CAPS, NULL, NULL);
5889 TYPE_FIND_REGISTER_RIFF (plugin, "audio/riff-midi", GST_RANK_PRIMARY,
5890 "mid,midi", "RMID");
5891 TYPE_FIND_REGISTER (plugin, "audio/mobile-xmf", GST_RANK_PRIMARY,
5892 mxmf_type_find, "mxmf", MXMF_CAPS, NULL, NULL);
5893 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5894 TYPE_FIND_REGISTER (plugin, "video/x-fli", GST_RANK_MARGINAL, flx_type_find,
5895 "flc,fli", FLX_CAPS, NULL, NULL);
5897 TYPE_FIND_REGISTER (plugin, "application/x-id3v2", GST_RANK_PRIMARY + 103,
5898 id3v2_type_find, "mp3,mp2,mp1,mpga,ogg,flac,tta", ID3_CAPS, NULL, NULL);
5899 TYPE_FIND_REGISTER (plugin, "application/x-id3v1", GST_RANK_PRIMARY + 101,
5900 id3v1_type_find, "mp3,mp2,mp1,mpga,ogg,flac,tta", ID3_CAPS, NULL, NULL);
5901 TYPE_FIND_REGISTER (plugin, "application/x-apetag", GST_RANK_PRIMARY + 102,
5902 apetag_type_find, "mp3,ape,mpc,wv", APETAG_CAPS, NULL, NULL);
5903 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5904 TYPE_FIND_REGISTER (plugin, "audio/x-ttafile", GST_RANK_PRIMARY,
5905 tta_type_find, "tta", TTA_CAPS, NULL, NULL);
5906 TYPE_FIND_REGISTER (plugin, "audio/x-mod", GST_RANK_SECONDARY, mod_type_find,
5907 "669,amf,ams,dbm,digi,dmf,dsm,gdm,far,imf,it,j2b,mdl,med,mod,mt2,mtm,"
5908 "okt,psm,ptm,sam,s3m,stm,stx,ult,umx,xm", MOD_CAPS, NULL, NULL);
5910 TYPE_FIND_REGISTER (plugin, "audio/mpeg", GST_RANK_PRIMARY, mp3_type_find,
5911 "mp3,mp2,mp1,mpga", MP3_CAPS, NULL, NULL);
5912 TYPE_FIND_REGISTER (plugin, "audio/x-ac3", GST_RANK_PRIMARY, ac3_type_find,
5913 "ac3,eac3", AC3_CAPS, NULL, NULL);
5914 TYPE_FIND_REGISTER (plugin, "audio/x-dts", GST_RANK_SECONDARY, dts_type_find,
5915 "dts", DTS_CAPS, NULL, NULL);
5916 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5917 TYPE_FIND_REGISTER (plugin, "audio/x-gsm", GST_RANK_PRIMARY, NULL, "gsm",
5918 GSM_CAPS, NULL, NULL);
5920 #ifdef TIZEN_PROFILE_TV
5921 TYPE_FIND_REGISTER (plugin, "video/mpeg-sys", GST_RANK_PRIMARY,
5922 mpeg_sys_type_find, "mpe,mpeg,mpg", MPEG_SYS_CAPS, NULL, NULL);
5924 TYPE_FIND_REGISTER (plugin, "video/mpegts", GST_RANK_PRIMARY,
5925 mpeg_ts_type_find, "ts,mts", MPEGTS_CAPS, NULL, NULL);
5926 TYPE_FIND_REGISTER (plugin, "application/ogg", GST_RANK_PRIMARY,
5927 ogganx_type_find, "ogg,oga,ogv,ogm,ogx,spx,anx,axa,axv", OGG_CAPS,
5929 TYPE_FIND_REGISTER (plugin, "video/mpeg-elementary", GST_RANK_MARGINAL,
5930 mpeg_video_stream_type_find, "mpv,mpeg,mpg", MPEG_VIDEO_CAPS, NULL, NULL);
5931 TYPE_FIND_REGISTER (plugin, "video/mpeg4", GST_RANK_PRIMARY,
5932 mpeg4_video_type_find, "m4v", MPEG_VIDEO_CAPS, NULL, NULL);
5933 TYPE_FIND_REGISTER (plugin, "video/x-h263", GST_RANK_SECONDARY,
5934 h263_video_type_find, "h263,263", H263_VIDEO_CAPS, NULL, NULL);
5935 TYPE_FIND_REGISTER (plugin, "video/x-h264", GST_RANK_PRIMARY,
5936 h264_video_type_find, "h264,x264,264", H264_VIDEO_CAPS, NULL, NULL);
5937 TYPE_FIND_REGISTER (plugin, "video/x-h265", GST_RANK_PRIMARY,
5938 h265_video_type_find, "h265,x265,265", H265_VIDEO_CAPS, NULL, NULL);
5939 TYPE_FIND_REGISTER (plugin, "video/x-nuv", GST_RANK_SECONDARY, nuv_type_find,
5940 "nuv", NUV_CAPS, NULL, NULL);
5943 TYPE_FIND_REGISTER (plugin, "audio/x-m4a", GST_RANK_PRIMARY, m4a_type_find,
5944 "m4a", M4A_CAPS, NULL, NULL);
5945 TYPE_FIND_REGISTER (plugin, "application/x-3gp", GST_RANK_PRIMARY,
5946 q3gp_type_find, "3gp", Q3GP_CAPS, NULL, NULL);
5947 TYPE_FIND_REGISTER (plugin, "video/quicktime", GST_RANK_PRIMARY,
5948 qt_type_find, "mov,mp4", QT_CAPS, NULL, NULL);
5949 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5950 TYPE_FIND_REGISTER (plugin, "image/x-quicktime", GST_RANK_SECONDARY,
5951 qtif_type_find, "qif,qtif,qti", QTIF_CAPS, NULL, NULL);
5952 TYPE_FIND_REGISTER (plugin, "image/jp2", GST_RANK_PRIMARY,
5953 jp2_type_find, "jp2", JP2_CAPS, NULL, NULL);
5954 TYPE_FIND_REGISTER (plugin, "image/x-jpc", GST_RANK_PRIMARY,
5955 jpc_type_find, "jpc,j2k", JPC_CAPS, NULL, NULL);
5956 TYPE_FIND_REGISTER (plugin, "video/mj2", GST_RANK_PRIMARY,
5957 jp2_type_find, "mj2", MJ2_CAPS, NULL, NULL);
5959 TYPE_FIND_REGISTER (plugin, "text/html", GST_RANK_SECONDARY, html_type_find,
5960 "htm,html", HTML_CAPS, NULL, NULL);
5962 TYPE_FIND_REGISTER_START_WITH (plugin, "application/vnd.rn-realmedia",
5963 GST_RANK_SECONDARY, "ra,ram,rm,rmvb", ".RMF", 4, GST_TYPE_FIND_MAXIMUM);
5964 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-pn-realaudio",
5965 GST_RANK_SECONDARY, "ra,ram,rm,rmvb", ".ra\375", 4,
5966 GST_TYPE_FIND_MAXIMUM);
5967 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5968 TYPE_FIND_REGISTER (plugin, "application/x-shockwave-flash",
5969 GST_RANK_SECONDARY, swf_type_find, "swf,swfl", SWF_CAPS, NULL, NULL);
5971 TYPE_FIND_REGISTER (plugin, "application/xges",
5972 GST_RANK_PRIMARY, xges_type_find, "xges", XGES_CAPS, NULL, NULL);
5973 TYPE_FIND_REGISTER (plugin, "application/dash+xml",
5974 GST_RANK_PRIMARY, dash_mpd_type_find, "mpd,MPD", DASH_CAPS, NULL, NULL);
5975 TYPE_FIND_REGISTER (plugin, "application/vnd.ms-sstr+xml",
5976 GST_RANK_PRIMARY, mss_manifest_type_find, NULL, MSS_MANIFEST_CAPS, NULL,
5978 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-flv", GST_RANK_SECONDARY,
5979 "flv", "FLV", 3, GST_TYPE_FIND_MAXIMUM);
5980 TYPE_FIND_REGISTER (plugin, "text/plain", GST_RANK_MARGINAL, utf8_type_find,
5981 "txt", UTF8_CAPS, NULL, NULL);
5982 TYPE_FIND_REGISTER (plugin, "text/utf-16", GST_RANK_MARGINAL, utf16_type_find,
5983 "txt", UTF16_CAPS, NULL, NULL);
5984 TYPE_FIND_REGISTER (plugin, "text/utf-32", GST_RANK_MARGINAL, utf32_type_find,
5985 "txt", UTF32_CAPS, NULL, NULL);
5986 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5987 TYPE_FIND_REGISTER (plugin, "text/uri-list", GST_RANK_MARGINAL, uri_type_find,
5988 "ram", URI_CAPS, NULL, NULL);
5990 TYPE_FIND_REGISTER (plugin, "application/itc", GST_RANK_SECONDARY,
5991 itc_type_find, "itc", ITC_CAPS, NULL, NULL);
5992 TYPE_FIND_REGISTER (plugin, "application/x-hls", GST_RANK_MARGINAL,
5993 hls_type_find, "m3u8", HLS_CAPS, NULL, NULL);
5994 TYPE_FIND_REGISTER (plugin, "application/sdp", GST_RANK_SECONDARY,
5995 sdp_type_find, "sdp", SDP_CAPS, NULL, NULL);
5996 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5997 TYPE_FIND_REGISTER (plugin, "application/smil", GST_RANK_SECONDARY,
5998 smil_type_find, "smil", SMIL_CAPS, NULL, NULL);
5999 TYPE_FIND_REGISTER (plugin, "application/ttml+xml", GST_RANK_SECONDARY,
6000 ttml_xml_type_find, "ttml+xml", TTML_XML_CAPS, NULL, NULL);
6001 TYPE_FIND_REGISTER (plugin, "application/xml", GST_RANK_MARGINAL,
6002 xml_type_find, "xml", GENERIC_XML_CAPS, NULL, NULL);
6004 TYPE_FIND_REGISTER_RIFF (plugin, "audio/x-wav", GST_RANK_PRIMARY, "wav",
6006 TYPE_FIND_REGISTER (plugin, "audio/x-aiff", GST_RANK_SECONDARY,
6007 aiff_type_find, "aiff,aif,aifc", AIFF_CAPS, NULL, NULL);
6008 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6009 TYPE_FIND_REGISTER (plugin, "audio/x-svx", GST_RANK_SECONDARY, svx_type_find,
6010 "iff,svx", SVX_CAPS, NULL, NULL);
6011 TYPE_FIND_REGISTER (plugin, "audio/x-paris", GST_RANK_SECONDARY,
6012 paris_type_find, "paf", PARIS_CAPS, NULL, NULL);
6013 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nist", GST_RANK_SECONDARY,
6014 "nist", "NIST", 4, GST_TYPE_FIND_MAXIMUM);
6015 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-voc", GST_RANK_SECONDARY,
6016 "voc", "Creative", 8, GST_TYPE_FIND_MAXIMUM);
6017 TYPE_FIND_REGISTER (plugin, "audio/x-sds", GST_RANK_SECONDARY, sds_type_find,
6018 "sds", SDS_CAPS, NULL, NULL);
6019 TYPE_FIND_REGISTER (plugin, "audio/x-ircam", GST_RANK_SECONDARY,
6020 ircam_type_find, "sf", IRCAM_CAPS, NULL, NULL);
6021 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-w64", GST_RANK_SECONDARY,
6022 "w64", "riff", 4, GST_TYPE_FIND_MAXIMUM);
6023 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-rf64", GST_RANK_PRIMARY,
6024 "rf64", "RF64", 4, GST_TYPE_FIND_MAXIMUM);
6025 TYPE_FIND_REGISTER (plugin, "audio/x-shorten", GST_RANK_SECONDARY,
6026 shn_type_find, "shn", SHN_CAPS, NULL, NULL);
6027 TYPE_FIND_REGISTER (plugin, "application/x-ape", GST_RANK_SECONDARY,
6028 ape_type_find, "ape", APE_CAPS, NULL, NULL);
6030 TYPE_FIND_REGISTER (plugin, "image/jpeg", GST_RANK_PRIMARY + 15,
6031 jpeg_type_find, "jpg,jpe,jpeg", JPEG_CAPS, NULL, NULL);
6032 TYPE_FIND_REGISTER_START_WITH (plugin, "image/gif", GST_RANK_PRIMARY, "gif",
6033 "GIF8", 4, GST_TYPE_FIND_MAXIMUM);
6034 TYPE_FIND_REGISTER_START_WITH (plugin, "image/png", GST_RANK_PRIMARY + 14,
6035 "png", "\211PNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
6036 TYPE_FIND_REGISTER (plugin, "image/bmp", GST_RANK_PRIMARY, bmp_type_find,
6037 "bmp", BMP_CAPS, NULL, NULL);
6038 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6039 TYPE_FIND_REGISTER (plugin, "image/tiff", GST_RANK_PRIMARY, tiff_type_find,
6040 "tif,tiff", TIFF_CAPS, NULL, NULL);
6041 TYPE_FIND_REGISTER_RIFF (plugin, "image/webp", GST_RANK_PRIMARY,
6044 TYPE_FIND_REGISTER (plugin, "image/x-exr", GST_RANK_PRIMARY, exr_type_find,
6045 "exr", EXR_CAPS, NULL, NULL);
6046 TYPE_FIND_REGISTER (plugin, "image/x-portable-pixmap", GST_RANK_SECONDARY,
6047 pnm_type_find, "pnm,ppm,pgm,pbm", PNM_CAPS, NULL, NULL);
6048 TYPE_FIND_REGISTER (plugin, "video/x-matroska", GST_RANK_PRIMARY,
6049 matroska_type_find, "mkv,mka,mk3d,webm", MATROSKA_CAPS, NULL, NULL);
6050 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6051 TYPE_FIND_REGISTER (plugin, "application/mxf", GST_RANK_PRIMARY,
6052 mxf_type_find, "mxf", MXF_CAPS, NULL, NULL);
6053 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mve", GST_RANK_SECONDARY,
6054 "mve", "Interplay MVE File\032\000\032\000\000\001\063\021", 26,
6055 GST_TYPE_FIND_MAXIMUM);
6056 TYPE_FIND_REGISTER (plugin, "video/x-dv", GST_RANK_SECONDARY, dv_type_find,
6057 "dv,dif", DV_CAPS, NULL, NULL);
6059 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-nb-sh", GST_RANK_PRIMARY,
6060 "amr", "#!AMR", 5, GST_TYPE_FIND_LIKELY);
6061 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-wb-sh", GST_RANK_PRIMARY,
6062 "amr", "#!AMR-WB", 7, GST_TYPE_FIND_MAXIMUM);
6063 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6064 TYPE_FIND_REGISTER (plugin, "audio/iLBC-sh", GST_RANK_PRIMARY, ilbc_type_find,
6065 "ilbc", ILBC_CAPS, NULL, NULL);
6066 TYPE_FIND_REGISTER (plugin, "audio/x-sbc", GST_RANK_MARGINAL, sbc_type_find,
6067 "sbc", SBC_CAPS, NULL, NULL);
6068 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sid", GST_RANK_MARGINAL,
6069 "sid", "PSID", 4, GST_TYPE_FIND_MAXIMUM);
6070 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xcf", GST_RANK_SECONDARY,
6071 "xcf", "gimp xcf", 8, GST_TYPE_FIND_MAXIMUM);
6072 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mng", GST_RANK_SECONDARY,
6073 "mng", "\212MNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
6074 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-jng", GST_RANK_SECONDARY,
6075 "jng", "\213JNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
6076 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xpixmap", GST_RANK_SECONDARY,
6077 "xpm", "/* XPM */", 9, GST_TYPE_FIND_MAXIMUM);
6078 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-sun-raster",
6079 GST_RANK_SECONDARY, "ras", "\131\246\152\225", 4, GST_TYPE_FIND_MAXIMUM);
6080 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-bzip",
6081 GST_RANK_SECONDARY, "bz2", "BZh", 3, GST_TYPE_FIND_LIKELY);
6082 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-gzip",
6083 GST_RANK_SECONDARY, "gz", "\037\213", 2, GST_TYPE_FIND_LIKELY);
6084 TYPE_FIND_REGISTER_START_WITH (plugin, "application/zip", GST_RANK_SECONDARY,
6085 "zip", "PK\003\004", 4, GST_TYPE_FIND_LIKELY);
6086 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-compress",
6087 GST_RANK_SECONDARY, "Z", "\037\235", 2, GST_TYPE_FIND_LIKELY);
6088 TYPE_FIND_REGISTER (plugin, "subtitle/x-kate", GST_RANK_MARGINAL,
6089 kate_type_find, NULL, NULL, NULL, NULL);
6091 TYPE_FIND_REGISTER (plugin, "application/x-subtitle-vtt", GST_RANK_MARGINAL,
6092 webvtt_type_find, "vtt", WEBVTT_CAPS, NULL, NULL);
6093 TYPE_FIND_REGISTER (plugin, "audio/x-flac", GST_RANK_PRIMARY, flac_type_find,
6094 "flac", FLAC_CAPS, NULL, NULL);
6095 TYPE_FIND_REGISTER (plugin, "audio/x-vorbis", GST_RANK_PRIMARY,
6096 vorbis_type_find, NULL, VORBIS_CAPS, NULL, NULL);
6097 TYPE_FIND_REGISTER (plugin, "video/x-theora", GST_RANK_PRIMARY,
6098 theora_type_find, NULL, THEORA_CAPS, NULL, NULL);
6099 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6100 TYPE_FIND_REGISTER (plugin, "application/x-ogm-video", GST_RANK_PRIMARY,
6101 ogmvideo_type_find, NULL, OGMVIDEO_CAPS, NULL, NULL);
6102 TYPE_FIND_REGISTER (plugin, "application/x-ogm-audio", GST_RANK_PRIMARY,
6103 ogmaudio_type_find, NULL, OGMAUDIO_CAPS, NULL, NULL);
6104 TYPE_FIND_REGISTER (plugin, "application/x-ogm-text", GST_RANK_PRIMARY,
6105 ogmtext_type_find, NULL, OGMTEXT_CAPS, NULL, NULL);
6106 TYPE_FIND_REGISTER (plugin, "audio/x-speex", GST_RANK_PRIMARY,
6107 speex_type_find, NULL, SPEEX_CAPS, NULL, NULL);
6108 TYPE_FIND_REGISTER (plugin, "audio/x-celt", GST_RANK_PRIMARY, celt_type_find,
6109 NULL, CELT_CAPS, NULL, NULL);
6110 TYPE_FIND_REGISTER (plugin, "application/x-ogg-skeleton", GST_RANK_PRIMARY,
6111 oggskel_type_find, NULL, OGG_SKELETON_CAPS, NULL, NULL);
6112 TYPE_FIND_REGISTER (plugin, "text/x-cmml", GST_RANK_PRIMARY, cmml_type_find,
6113 NULL, CMML_CAPS, NULL, NULL);
6114 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-executable",
6115 GST_RANK_MARGINAL, NULL, "\177ELF", 4, GST_TYPE_FIND_MAXIMUM);
6117 TYPE_FIND_REGISTER (plugin, "audio/aac", GST_RANK_SECONDARY, aac_type_find,
6118 "aac,adts,adif,loas", AAC_CAPS, NULL, NULL);
6119 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6120 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-spc", GST_RANK_SECONDARY,
6121 "spc", "SNES-SPC700 Sound File Data", 27, GST_TYPE_FIND_MAXIMUM);
6122 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack", GST_RANK_SECONDARY,
6123 wavpack_type_find, "wv,wvp", WAVPACK_CAPS, NULL, NULL);
6124 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack-correction", GST_RANK_SECONDARY,
6125 wavpack_type_find, "wvc", WAVPACK_CORRECTION_CAPS, NULL, NULL);
6126 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-caf", GST_RANK_SECONDARY,
6127 "caf", "caff\000\001", 6, GST_TYPE_FIND_MAXIMUM);
6128 TYPE_FIND_REGISTER (plugin, "application/postscript", GST_RANK_SECONDARY,
6129 postscript_type_find, "ps", POSTSCRIPT_CAPS, NULL, NULL);
6130 TYPE_FIND_REGISTER (plugin, "image/svg+xml", GST_RANK_SECONDARY,
6131 svg_type_find, "svg", SVG_CAPS, NULL, NULL);
6132 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-rar",
6133 GST_RANK_SECONDARY, "rar", "Rar!", 4, GST_TYPE_FIND_LIKELY);
6134 TYPE_FIND_REGISTER (plugin, "application/x-tar", GST_RANK_SECONDARY,
6135 tar_type_find, "tar", TAR_CAPS, NULL, NULL);
6136 TYPE_FIND_REGISTER (plugin, "application/x-ar", GST_RANK_SECONDARY,
6137 ar_type_find, "a", AR_CAPS, NULL, NULL);
6138 TYPE_FIND_REGISTER (plugin, "application/x-ms-dos-executable",
6139 GST_RANK_SECONDARY, msdos_type_find, "dll,exe,ocx,sys,scr,msstyles,cpl",
6140 MSDOS_CAPS, NULL, NULL);
6141 TYPE_FIND_REGISTER (plugin, "video/x-dirac", GST_RANK_PRIMARY,
6142 dirac_type_find, NULL, DIRAC_CAPS, NULL, NULL);
6143 TYPE_FIND_REGISTER (plugin, "multipart/x-mixed-replace", GST_RANK_SECONDARY,
6144 multipart_type_find, NULL, MULTIPART_CAPS, NULL, NULL);
6145 TYPE_FIND_REGISTER (plugin, "application/x-mmsh", GST_RANK_SECONDARY,
6146 mmsh_type_find, NULL, MMSH_CAPS, NULL, NULL);
6147 TYPE_FIND_REGISTER (plugin, "video/vivo", GST_RANK_SECONDARY, vivo_type_find,
6148 "viv", VIVO_CAPS, NULL, NULL);
6149 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nsf", GST_RANK_SECONDARY,
6150 "nsf", "NESM\x1a", 5, GST_TYPE_FIND_MAXIMUM);
6151 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gym", GST_RANK_SECONDARY,
6152 "gym", "GYMX", 4, GST_TYPE_FIND_MAXIMUM);
6153 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-ay", GST_RANK_SECONDARY, "ay",
6154 "ZXAYEMUL", 8, GST_TYPE_FIND_MAXIMUM);
6155 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gbs", GST_RANK_SECONDARY,
6156 "gbs", "GBS\x01", 4, GST_TYPE_FIND_MAXIMUM);
6157 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-vgm", GST_RANK_SECONDARY,
6158 "vgm", "Vgm\x20", 4, GST_TYPE_FIND_MAXIMUM);
6159 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sap", GST_RANK_SECONDARY,
6160 "sap", "SAP\x0d\x0a" "AUTHOR\x20", 12, GST_TYPE_FIND_MAXIMUM);
6161 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ivf", GST_RANK_SECONDARY,
6162 "ivf", "DKIF", 4, GST_TYPE_FIND_NEARLY_CERTAIN);
6163 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-kss", GST_RANK_SECONDARY,
6164 "kss", "KSSX\0", 5, GST_TYPE_FIND_MAXIMUM);
6165 TYPE_FIND_REGISTER_START_WITH (plugin, "application/pdf", GST_RANK_SECONDARY,
6166 "pdf", "%PDF-", 5, GST_TYPE_FIND_LIKELY);
6167 TYPE_FIND_REGISTER_START_WITH (plugin, "application/msword",
6168 GST_RANK_SECONDARY, "doc", "\320\317\021\340\241\261\032\341", 8,
6169 GST_TYPE_FIND_LIKELY);
6171 /* Mac OS X .DS_Store files tend to be taken for video/mpeg */
6172 TYPE_FIND_REGISTER_START_WITH (plugin, "application/octet-stream",
6173 GST_RANK_SECONDARY, "DS_Store", "\000\000\000\001Bud1", 8,
6174 GST_TYPE_FIND_LIKELY);
6175 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6176 TYPE_FIND_REGISTER_START_WITH (plugin, "image/vnd.adobe.photoshop",
6177 GST_RANK_SECONDARY, "psd", "8BPS\000\001\000\000\000\000", 10,
6178 GST_TYPE_FIND_LIKELY);
6179 TYPE_FIND_REGISTER (plugin, "image/vnd.wap.wbmp", GST_RANK_MARGINAL,
6180 wbmp_typefind, NULL, NULL, NULL, NULL);
6181 TYPE_FIND_REGISTER (plugin, "application/x-yuv4mpeg", GST_RANK_SECONDARY,
6182 y4m_typefind, NULL, NULL, NULL, NULL);
6183 TYPE_FIND_REGISTER (plugin, "image/x-icon", GST_RANK_MARGINAL,
6184 windows_icon_typefind, NULL, NULL, NULL, NULL);
6188 TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,
6189 xdgmime_typefind, NULL, NULL, NULL, NULL);
6192 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6193 TYPE_FIND_REGISTER (plugin, "image/x-degas", GST_RANK_MARGINAL,
6194 degas_type_find, NULL, NULL, NULL, NULL);
6196 TYPE_FIND_REGISTER (plugin, "application/octet-stream", GST_RANK_MARGINAL,
6197 dvdiso_type_find, NULL, NULL, NULL, NULL);
6199 TYPE_FIND_REGISTER (plugin, "application/x-ssa", GST_RANK_SECONDARY,
6200 ssa_type_find, "ssa,ass", NULL, NULL, NULL);
6202 TYPE_FIND_REGISTER (plugin, "video/x-pva", GST_RANK_SECONDARY,
6203 pva_type_find, "pva", PVA_CAPS, NULL, NULL);
6205 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-xi", GST_RANK_SECONDARY,
6206 "xi", "Extended Instrument: ", 21, GST_TYPE_FIND_MAXIMUM);
6208 TYPE_FIND_REGISTER (plugin, "audio/audible", GST_RANK_MARGINAL,
6209 aa_type_find, "aa,aax", AA_CAPS, NULL, NULL);
6210 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6211 TYPE_FIND_REGISTER (plugin, "audio/x-tap-tap", GST_RANK_PRIMARY,
6212 tap_type_find, "tap", TAP_CAPS, NULL, NULL);
6213 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-tap-dmp",
6214 GST_RANK_SECONDARY, "dmp", "DC2N-TAP-RAW", 12, GST_TYPE_FIND_LIKELY);
6220 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
6223 "default typefind functions",
6224 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)