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 #include "gsttypefindfunctionsplugin.h"
48 /* DataScanCtx: helper for typefind functions that scan through data
49 * step-by-step, to avoid doing a peek at each and every offset */
51 #define DATA_SCAN_CTX_CHUNK_SIZE 4096
61 data_scan_ctx_advance (GstTypeFind * tf, DataScanCtx * c, guint bytes_to_skip)
63 c->offset += bytes_to_skip;
64 if (G_LIKELY (c->size > bytes_to_skip)) {
65 c->size -= bytes_to_skip;
66 c->data += bytes_to_skip;
73 static inline gboolean
74 data_scan_ctx_ensure_data (GstTypeFind * tf, DataScanCtx * c, guint min_len)
78 guint chunk_len = MAX (DATA_SCAN_CTX_CHUNK_SIZE, min_len);
80 if (G_LIKELY (c->size >= min_len))
83 data = gst_type_find_peek (tf, c->offset, chunk_len);
84 if (G_LIKELY (data != NULL)) {
90 /* if there's less than our chunk size, try to get as much as we can, but
91 * always at least min_len bytes (we might be typefinding the first buffer
92 * of the stream and not have as much data available as we'd like) */
93 len = gst_type_find_get_length (tf);
95 len = CLAMP (len - c->offset, min_len, chunk_len);
100 data = gst_type_find_peek (tf, c->offset, len);
110 static inline gboolean
111 data_scan_ctx_memcmp (GstTypeFind * tf, DataScanCtx * c, guint offset,
112 const gchar * data, guint len)
114 if (G_UNLIKELY (offset + len >= G_MAXUINT32))
117 if (!data_scan_ctx_ensure_data (tf, c, offset + len))
120 return (memcmp (c->data + offset, data, len) == 0);
124 static gboolean xml_check_first_element (GstTypeFind * tf,
125 const gchar * element, guint elen, gboolean strict);
126 static gboolean sdp_check_header (GstTypeFind * tf);
128 static GstStaticCaps utf8_caps = GST_STATIC_CAPS ("text/plain");
130 #define UTF8_CAPS gst_static_caps_get(&utf8_caps)
133 utf8_type_find_have_valid_utf8_at_offset (GstTypeFind * tf, guint64 offset,
134 GstTypeFindProbability * prob)
138 /* randomly decided values */
139 guint min_size = 16; /* minimum size */
140 guint size = 32 * 1024; /* starting size */
141 guint probability = 95; /* starting probability */
142 guint step = 10; /* how much we reduce probability in each
145 while (probability > step && size > min_size) {
146 data = gst_type_find_peek (tf, offset, size);
149 gchar *start = (gchar *) data;
151 if (g_utf8_validate (start, size, (const gchar **) &end) || (end - start + 4 > size)) { /* allow last char to be cut off */
166 utf8_type_find (GstTypeFind * tf, gpointer unused)
168 GstTypeFindProbability start_prob, mid_prob;
171 /* leave xml to the xml typefinders */
172 if (xml_check_first_element (tf, "", 0, TRUE))
175 /* leave sdp to the sdp typefinders */
176 if (sdp_check_header (tf))
179 /* check beginning of stream */
180 if (!utf8_type_find_have_valid_utf8_at_offset (tf, 0, &start_prob))
183 GST_LOG ("start is plain text with probability of %u", start_prob);
185 /* POSSIBLE is the highest probability we ever return if we can't
186 * probe into the middle of the file and don't know its length */
188 length = gst_type_find_get_length (tf);
189 if (length == 0 || length == (guint64) - 1) {
190 gst_type_find_suggest (tf, MIN (start_prob, GST_TYPE_FIND_POSSIBLE),
195 if (length < 64 * 1024) {
196 gst_type_find_suggest (tf, start_prob, UTF8_CAPS);
200 /* check middle of stream */
201 if (!utf8_type_find_have_valid_utf8_at_offset (tf, length / 2, &mid_prob))
204 GST_LOG ("middle is plain text with probability of %u", mid_prob);
205 gst_type_find_suggest (tf, (start_prob + mid_prob) / 2, UTF8_CAPS);
208 /*** text/utf-16 and text/utf-32} ***/
209 /* While UTF-8 is unicode too, using text/plain for UTF-16 and UTF-32
210 is going to break stuff. */
215 const char *const bom;
216 gboolean (*checker) (const guint8 *, gint, gint);
222 check_utf16 (const guint8 * data, gint len, gint endianness)
232 gst_byte_reader_init (&br, data, len);
234 /* test first for a single 16 bit value in the BMP */
235 if (endianness == G_BIG_ENDIAN)
236 high = gst_byte_reader_get_uint16_be_unchecked (&br);
238 high = gst_byte_reader_get_uint16_le_unchecked (&br);
239 if (high >= 0xD800 && high <= 0xDBFF) {
240 /* start of a surrogate pair */
244 if (endianness == G_BIG_ENDIAN)
245 low = gst_byte_reader_get_uint16_be_unchecked (&br);
247 low = gst_byte_reader_get_uint16_le_unchecked (&br);
248 if (low >= 0xDC00 && low <= 0xDFFF) {
249 /* second half of the surrogate pair */
253 if (high >= 0xDC00 && high <= 0xDFFF)
262 check_utf32 (const guint8 * data, gint len, gint endianness)
268 if (endianness == G_BIG_ENDIAN)
269 v = GST_READ_UINT32_BE (data);
271 v = GST_READ_UINT32_LE (data);
281 unicode_type_find (GstTypeFind * tf, const GstUnicodeTester * tester,
282 guint n_tester, const char *media_type, gboolean require_bom)
286 const guint8 *data = gst_type_find_peek (tf, 0, len);
288 const gint max_scan_size = 256 * 1024;
293 data = gst_type_find_peek (tf, 0, len);
298 /* find a large enough size that works */
299 while (len < max_scan_size) {
300 size_t newlen = len << 1;
301 const guint8 *newdata = gst_type_find_peek (tf, 0, newlen);
308 for (n = 0; n < n_tester; ++n) {
309 int bom_boost = 0, tmpprob;
310 if (len >= tester[n].bomlen) {
311 if (!memcmp (data, tester[n].bom, tester[n].bomlen))
312 bom_boost = tester[n].boost;
314 if (require_bom && bom_boost == 0)
316 if (!(*tester[n].checker) (data, len, tester[n].endianness))
318 tmpprob = GST_TYPE_FIND_POSSIBLE - 20 + bom_boost;
319 if (tmpprob > prob) {
321 endianness = tester[n].endianness;
326 GST_DEBUG ("This is valid %s %s", media_type,
327 endianness == G_BIG_ENDIAN ? "be" : "le");
328 gst_type_find_suggest_simple (tf, prob, media_type,
329 "endianness", G_TYPE_INT, endianness, NULL);
333 static GstStaticCaps utf16_caps = GST_STATIC_CAPS ("text/utf-16");
335 #define UTF16_CAPS gst_static_caps_get(&utf16_caps)
338 utf16_type_find (GstTypeFind * tf, gpointer unused)
340 static const GstUnicodeTester utf16tester[2] = {
341 {2, "\xff\xfe", check_utf16, 10, G_LITTLE_ENDIAN},
342 {2, "\xfe\xff", check_utf16, 20, G_BIG_ENDIAN},
344 unicode_type_find (tf, utf16tester, G_N_ELEMENTS (utf16tester),
345 "text/utf-16", TRUE);
348 static GstStaticCaps utf32_caps = GST_STATIC_CAPS ("text/utf-32");
350 #define UTF32_CAPS gst_static_caps_get(&utf32_caps)
353 utf32_type_find (GstTypeFind * tf, gpointer unused)
355 static const GstUnicodeTester utf32tester[2] = {
356 {4, "\xff\xfe\x00\x00", check_utf32, 10, G_LITTLE_ENDIAN},
357 {4, "\x00\x00\xfe\xff", check_utf32, 20, G_BIG_ENDIAN}
359 unicode_type_find (tf, utf32tester, G_N_ELEMENTS (utf32tester),
360 "text/utf-32", TRUE);
363 /*** text/uri-list ***/
364 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
365 static GstStaticCaps uri_caps = GST_STATIC_CAPS ("text/uri-list");
367 #define URI_CAPS (gst_static_caps_get(&uri_caps))
368 #define BUFFER_SIZE 16 /* If the string is < 16 bytes we're screwed */
369 #define INC_BUFFER { \
371 if (pos == BUFFER_SIZE) { \
373 offset += BUFFER_SIZE; \
374 data = gst_type_find_peek (tf, offset, BUFFER_SIZE); \
375 if (data == NULL) return; \
382 uri_type_find (GstTypeFind * tf, gpointer unused)
384 const guint8 *data = gst_type_find_peek (tf, 0, BUFFER_SIZE);
389 /* Search for # comment lines */
390 while (*data == '#') {
391 /* Goto end of line */
392 while (*data != '\n') {
399 if (!g_ascii_isalpha (*data)) {
400 /* Had a non alpha char - can't be uri-list */
406 while (g_ascii_isalnum (*data)) {
411 /* First non alpha char is not a : */
415 /* Get the next 2 bytes as well */
416 data = gst_type_find_peek (tf, offset + pos, 3);
420 if (data[1] != '/' && data[2] != '/') {
424 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, URI_CAPS);
429 /*** application/itc ***/
430 static GstStaticCaps itc_caps = GST_STATIC_CAPS ("application/itc");
431 #define ITC_CAPS (gst_static_caps_get(&itc_caps))
434 itc_type_find (GstTypeFind * tf, gpointer unused)
436 DataScanCtx c = { 0, NULL, 0 };
437 guint8 magic[8] = { 0x00, 0x00, 0x01, 0x1C, 0x69, 0x74, 0x63, 0x68 };
438 guint8 preamble[4] = { 0x00, 0x00, 0x00, 0x02 };
439 guint8 artwork_marker[8] = { 0x00, 0x00, 0x00, 0x00, 0x61, 0x72, 0x74, 0x77 };
440 guint8 item_marker[4] = { 0x69, 0x74, 0x65, 0x6D };
441 GstTypeFindProbability itc_prob = GST_TYPE_FIND_NONE;
444 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 8)))
447 if (memcmp (c.data, magic, 8))
450 /* At least we found the right magic */
451 itc_prob = GST_TYPE_FIND_MINIMUM;
452 data_scan_ctx_advance (tf, &c, 8);
454 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
457 /* Check preamble 3 consecutive times */
458 for (i = 0; i < 3; i++) {
459 if (memcmp (c.data, preamble, 4))
461 data_scan_ctx_advance (tf, &c, 4);
464 itc_prob = GST_TYPE_FIND_POSSIBLE;
466 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 8)))
469 if (memcmp (c.data, artwork_marker, 8))
472 itc_prob = GST_TYPE_FIND_LIKELY;
473 data_scan_ctx_advance (tf, &c, 8);
475 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 256)))
478 /* ...and 256 0x00 padding bytes on what looks like the header's end */
479 for (i = 0; i < 256; i++) {
484 itc_prob = GST_TYPE_FIND_NEARLY_CERTAIN;
485 data_scan_ctx_advance (tf, &c, 256);
487 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 8)))
490 if (memcmp (c.data + 4, item_marker, 4))
493 itc_prob = GST_TYPE_FIND_MAXIMUM;
496 gst_type_find_suggest (tf, itc_prob, ITC_CAPS);
499 /*** application/x-hls ***/
501 static GstStaticCaps hls_caps = GST_STATIC_CAPS ("application/x-hls");
502 #define HLS_CAPS (gst_static_caps_get(&hls_caps))
504 /* See http://tools.ietf.org/html/draft-pantos-http-live-streaming-05 */
506 hls_type_find (GstTypeFind * tf, gpointer unused)
508 DataScanCtx c = { 0, NULL, 0 };
510 /* Minimum useful size is #EXTM3U\n + 1 tag + ':' = 30 bytes */
511 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 30)))
514 if (memcmp (c.data, "#EXTM3U", 7))
517 data_scan_ctx_advance (tf, &c, 7);
519 /* Check only the first 4KB */
520 while (c.offset < 4096) {
521 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 21)))
524 /* Search for # comment lines */
525 if (c.data[0] == '#' && (memcmp (c.data, "#EXT-X-TARGETDURATION", 21) == 0
526 || memcmp (c.data, "#EXT-X-STREAM-INF", 17) == 0
527 || memcmp (c.data, "#EXT-X-MEDIA", 12) == 0)) {
528 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HLS_CAPS);
532 data_scan_ctx_advance (tf, &c, 1);
537 /*** application/xml **********************************************************/
539 #define XML_BUFFER_SIZE 16
540 #define XML_INC_BUFFER { \
542 if (pos == XML_BUFFER_SIZE) { \
544 offset += XML_BUFFER_SIZE; \
545 data = gst_type_find_peek (tf, offset, XML_BUFFER_SIZE); \
546 if (data == NULL) return FALSE; \
552 #define XML_INC_BUFFER_DATA { \
554 if (pos >= length) { \
562 xml_check_first_element_from_data (const guint8 * data, guint length,
563 const gchar * element, guint elen, gboolean strict)
568 g_return_val_if_fail (data != NULL, FALSE);
573 /* look for the XMLDec
574 * see XML spec 2.8, Prolog and Document Type Declaration
575 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
576 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
578 if (strict && !got_xmldec)
581 /* skip XMLDec in any case if we've got one */
587 /* look for the first element, it has to be the requested element. Bail
588 * out if it is not within the first 4kB. */
589 while (pos < MIN (4096, length)) {
590 while (*data != '<' && pos < MIN (4096, length)) {
595 if (!g_ascii_isalpha (*data)) {
596 /* if not alphabetic, it's a PI or an element / attribute declaration
597 * like <?xxx or <!xxx */
602 /* the first normal element, check if it's the one asked for */
603 if (pos + elen + 1 >= length)
605 return (element && strncmp ((const char *) data, element, elen) == 0);
612 xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen,
620 data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE);
624 /* look for the XMLDec
625 * see XML spec 2.8, Prolog and Document Type Declaration
626 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
627 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
629 if (strict && !got_xmldec)
632 /* skip XMLDec in any case if we've got one */
638 /* look for the first element, it has to be the requested element. Bail
639 * out if it is not within the first 4kB. */
640 while (data && (offset + pos) < 4096) {
641 while (*data != '<' && (offset + pos) < 4096) {
646 if (!g_ascii_isalpha (*data)) {
647 /* if not alphabetic, it's a PI or an element / attribute declaration
648 * like <?xxx or <!xxx */
653 /* the first normal element, check if it's the one asked for */
654 data = gst_type_find_peek (tf, offset + pos, elen + 1);
655 return (data && element && strncmp ((char *) data, element, elen) == 0);
661 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
662 static GstStaticCaps generic_xml_caps = GST_STATIC_CAPS ("application/xml");
664 #define GENERIC_XML_CAPS (gst_static_caps_get(&generic_xml_caps))
666 xml_type_find (GstTypeFind * tf, gpointer unused)
668 if (xml_check_first_element (tf, "", 0, TRUE)) {
669 gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, GENERIC_XML_CAPS);
673 /*** application/dash+xml ****************************************************/
675 static GstStaticCaps dash_caps = GST_STATIC_CAPS ("application/dash+xml");
677 #define DASH_CAPS gst_static_caps_get (&dash_caps)
680 dash_mpd_type_find (GstTypeFind * tf, gpointer unused)
682 if (xml_check_first_element (tf, "MPD", 3, FALSE) ||
683 xml_check_first_element (tf, "mpd", 3, FALSE)) {
684 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DASH_CAPS);
688 /*** application/xges ****************************************************/
690 static GstStaticCaps xges_caps = GST_STATIC_CAPS ("application/xges");
692 #define XGES_CAPS gst_static_caps_get (&xges_caps)
695 xges_type_find (GstTypeFind * tf, gpointer unused)
697 if (xml_check_first_element (tf, "ges", 3, FALSE)) {
698 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, XGES_CAPS);
702 /***application/vnd.apple-fcp+xml ****************************************************/
704 static GstStaticCaps fcpxml_caps =
705 GST_STATIC_CAPS ("application/vnd.apple-fcp+xml");
707 #define FCPXML_CAPS gst_static_caps_get (&fcpxml_caps)
710 fcpxml_type_find (GstTypeFind * tf, gpointer unused)
712 if (xml_check_first_element (tf, "fcpxml", 3, FALSE)) {
713 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FCPXML_CAPS);
717 /*** application/vnd.apple-xmeml+xml ****************************************************/
719 static GstStaticCaps xmeml_caps =
720 GST_STATIC_CAPS ("application/vnd.apple-xmeml+xml");
722 #define XMEML_CAPS gst_static_caps_get (&xmeml_caps)
725 xmeml_type_find (GstTypeFind * tf, gpointer unused)
727 if (xml_check_first_element (tf, "xmeml", 3, FALSE)) {
728 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, XMEML_CAPS);
732 /*** application/otio ****************************************************/
734 static GstStaticCaps otio_caps =
735 GST_STATIC_CAPS ("application/vnd.pixar.opentimelineio+json");
737 #define OTIO_CAPS gst_static_caps_get (&otio_caps)
740 otio_type_find (GstTypeFind * tf, gpointer unused)
742 const gchar *data, *tmp;
744 data = (const gchar *) gst_type_find_peek (tf, 0, 30);
748 tmp = (const gchar *) memchr (data, '{', 30);
752 data = (const gchar *) gst_type_find_peek (tf, tmp - data, 30);
756 tmp = (const gchar *) memchr (data, '"', 30);
760 data = (const gchar *) gst_type_find_peek (tf, tmp - data, 14);
764 if (memcmp (data, "\"OTIO_SCHEMA\":", 14) == 0) {
765 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OTIO_CAPS);
770 /*** application/sdp *********************************************************/
772 static GstStaticCaps sdp_caps = GST_STATIC_CAPS ("application/sdp");
774 #define SDP_CAPS (gst_static_caps_get(&sdp_caps))
776 sdp_check_header (GstTypeFind * tf)
780 data = gst_type_find_peek (tf, 0, 5);
784 /* sdp must start with v=0[\r]\n */
785 if (memcmp (data, "v=0", 3))
788 if (data[3] == '\r' && data[4] == '\n')
797 sdp_type_find (GstTypeFind * tf, gpointer unused)
799 if (sdp_check_header (tf))
800 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDP_CAPS);
803 /*** application/smil *********************************************************/
804 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
805 static GstStaticCaps smil_caps = GST_STATIC_CAPS ("application/smil");
807 #define SMIL_CAPS (gst_static_caps_get(&smil_caps))
809 smil_type_find (GstTypeFind * tf, gpointer unused)
811 if (xml_check_first_element (tf, "smil", 4, FALSE)) {
812 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SMIL_CAPS);
816 /*** application/ttml+xml *****************************************************/
818 static GstStaticCaps ttml_xml_caps = GST_STATIC_CAPS ("application/ttml+xml");
820 #define TTML_XML_CAPS (gst_static_caps_get(&ttml_xml_caps))
822 ttml_xml_type_find (GstTypeFind * tf, gpointer unused)
824 if (xml_check_first_element (tf, "tt", 2, FALSE)) {
825 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTML_XML_CAPS);
831 static GstStaticCaps html_caps = GST_STATIC_CAPS ("text/html");
833 #define HTML_CAPS gst_static_caps_get (&html_caps)
836 html_type_find (GstTypeFind * tf, gpointer unused)
838 const gchar *d, *data;
840 data = (const gchar *) gst_type_find_peek (tf, 0, 16);
844 if (!g_ascii_strncasecmp (data, "<!DOCTYPE HTML", 14)) {
845 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
846 } else if (xml_check_first_element (tf, "html", 4, FALSE)) {
847 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
848 } else if ((d = memchr (data, '<', 16))) {
849 data = (const gchar *) gst_type_find_peek (tf, d - data, 6);
850 if (data && g_ascii_strncasecmp (data, "<html>", 6) == 0) {
851 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
858 static GstStaticCaps mid_caps = GST_STATIC_CAPS ("audio/midi");
860 #define MID_CAPS gst_static_caps_get(&mid_caps)
862 mid_type_find (GstTypeFind * tf, gpointer unused)
864 const guint8 *data = gst_type_find_peek (tf, 0, 4);
866 /* http://jedi.ks.uiuc.edu/~johns/links/music/midifile.html */
867 if (data && data[0] == 'M' && data[1] == 'T' && data[2] == 'h'
869 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MID_CAPS);
872 /*** audio/mobile-xmf ***/
874 static GstStaticCaps mxmf_caps = GST_STATIC_CAPS ("audio/mobile-xmf");
876 #define MXMF_CAPS gst_static_caps_get(&mxmf_caps)
878 mxmf_type_find (GstTypeFind * tf, gpointer unused)
880 const guint8 *data = NULL;
882 /* Search FileId "XMF_" 4 bytes */
883 data = gst_type_find_peek (tf, 0, 4);
884 if (data && data[0] == 'X' && data[1] == 'M' && data[2] == 'F'
886 /* Search Format version "2.00" 4 bytes */
887 data = gst_type_find_peek (tf, 4, 4);
888 if (data && data[0] == '2' && data[1] == '.' && data[2] == '0'
890 /* Search TypeId 2 1 byte */
891 data = gst_type_find_peek (tf, 11, 1);
892 if (data && data[0] == 2) {
893 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXMF_CAPS);
900 /*** video/x-fli ***/
901 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
902 static GstStaticCaps flx_caps = GST_STATIC_CAPS ("video/x-fli");
904 #define FLX_CAPS gst_static_caps_get(&flx_caps)
906 flx_type_find (GstTypeFind * tf, gpointer unused)
908 const guint8 *data = gst_type_find_peek (tf, 0, 134);
911 /* check magic and the frame type of the first frame */
912 if ((data[4] == 0x11 || data[4] == 0x12 ||
913 data[4] == 0x30 || data[4] == 0x44) &&
915 ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1)) {
916 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLX_CAPS);
920 data = gst_type_find_peek (tf, 0, 6);
922 /* check magic only */
923 if ((data[4] == 0x11 || data[4] == 0x12 ||
924 data[4] == 0x30 || data[4] == 0x44) && data[5] == 0xaf) {
925 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, FLX_CAPS);
931 /*** application/x-id3 ***/
933 static GstStaticCaps id3_caps = GST_STATIC_CAPS ("application/x-id3");
935 #define ID3_CAPS gst_static_caps_get(&id3_caps)
937 id3v2_type_find (GstTypeFind * tf, gpointer unused)
939 const guint8 *data = gst_type_find_peek (tf, 0, 10);
941 if (data && memcmp (data, "ID3", 3) == 0 &&
942 data[3] != 0xFF && data[4] != 0xFF &&
943 (data[6] & 0x80) == 0 && (data[7] & 0x80) == 0 &&
944 (data[8] & 0x80) == 0 && (data[9] & 0x80) == 0) {
945 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
950 id3v1_type_find (GstTypeFind * tf, gpointer unused)
952 const guint8 *data = gst_type_find_peek (tf, -128, 3);
954 if (data && memcmp (data, "TAG", 3) == 0) {
955 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
959 /*** application/x-ape ***/
961 static GstStaticCaps apetag_caps = GST_STATIC_CAPS ("application/x-apetag");
963 #define APETAG_CAPS gst_static_caps_get(&apetag_caps)
965 apetag_type_find (GstTypeFind * tf, gpointer unused)
969 /* APEv1/2 at start of file */
970 data = gst_type_find_peek (tf, 0, 8);
971 if (data && !memcmp (data, "APETAGEX", 8)) {
972 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
976 /* APEv1/2 at end of file */
977 data = gst_type_find_peek (tf, -32, 8);
978 if (data && !memcmp (data, "APETAGEX", 8)) {
979 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
984 /*** audio/x-ttafile ***/
985 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
986 static GstStaticCaps tta_caps = GST_STATIC_CAPS ("audio/x-ttafile");
988 #define TTA_CAPS gst_static_caps_get(&tta_caps)
990 tta_type_find (GstTypeFind * tf, gpointer unused)
992 const guint8 *data = gst_type_find_peek (tf, 0, 3);
995 if (memcmp (data, "TTA", 3) == 0) {
996 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTA_CAPS);
1002 /*** audio/x-flac ***/
1003 static GstStaticCaps flac_caps = GST_STATIC_CAPS ("audio/x-flac");
1005 #define FLAC_CAPS (gst_static_caps_get(&flac_caps))
1008 flac_type_find (GstTypeFind * tf, gpointer unused)
1010 DataScanCtx c = { 0, NULL, 0 };
1012 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
1015 /* standard flac (also old/broken flac-in-ogg with an initial 4-byte marker
1016 * packet and without the usual packet framing) */
1017 if (memcmp (c.data, "fLaC", 4) == 0) {
1018 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
1022 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
1025 /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */
1026 if (memcmp (c.data, "\177FLAC\001", 6) == 0) {
1027 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
1031 /* disabled because it happily typefinds /dev/urandom as audio/x-flac, and
1032 * because I yet have to see header-less flac in the wild */
1034 /* flac without headers (subset format) */
1035 /* 64K should be enough */
1036 while (c.offset < (64 * 1024)) {
1037 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
1040 /* look for frame header,
1041 * http://flac.sourceforge.net/format.html#frame_header
1043 if (c.data[0] == 0xff && (c.data[1] >> 2) == 0x3e) {
1044 /* bit 15 in the header must be 0 */
1045 if (((c.data[1] >> 1) & 0x01) == 0x01)
1048 /* blocksize must be != 0x00 */
1049 if ((c.data[2] >> 4) == 0x00)
1052 /* samplerate must be != 0x0f */
1053 if ((c.data[2] & 0x0f) == 0x0f)
1055 /* also 0 is invalid, as it means get the info from the header and we
1056 * don't have headers if we are here */
1057 if ((c.data[2] & 0x0f) == 0x00)
1060 /* channel assignment must be < 11 */
1061 if ((c.data[3] >> 4) >= 11)
1064 /* sample size must be != 0x07 and != 0x05 */
1065 if (((c.data[3] >> 1) & 0x07) == 0x07)
1067 if (((c.data[3] >> 1) & 0x07) == 0x05)
1069 /* also 0 is invalid, as it means get the info from the header and we
1070 * don't have headers if we are here */
1071 if (((c.data[3] >> 1) & 0x07) == 0x00)
1074 /* next bit must be 0 */
1075 if ((c.data[3] & 0x01) == 0x01)
1078 /* FIXME: shouldn't we include the crc check ? */
1080 GST_DEBUG ("Found flac without headers at %d", (gint) c.offset);
1081 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, FLAC_CAPS);
1085 data_scan_ctx_advance (tf, &c, 1);
1090 /* TODO: we could probably make a generic function for this.. */
1092 aac_type_find_scan_loas_frames_ep (GstTypeFind * tf, DataScanCtx * scan_ctx,
1095 DataScanCtx c = *scan_ctx;
1101 if (!data_scan_ctx_ensure_data (tf, &c, 5))
1104 /* EPAudioSyncStream */
1105 len = ((c.data[2] & 0x0f) << 9) | (c.data[3] << 1) |
1106 ((c.data[4] & 0x80) >> 7);
1108 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
1109 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
1113 /* check length of frame */
1114 snc = GST_READ_UINT16_BE (c.data + len);
1115 if (snc != 0x4de1) {
1116 GST_DEBUG ("No sync found at 0x%" G_GINT64_MODIFIER "x", c.offset + len);
1122 GST_DEBUG ("Found LOAS syncword #%d at offset 0x%" G_GINT64_MODIFIER "x, "
1123 "framelen %u", count, c.offset, len);
1125 data_scan_ctx_advance (tf, &c, len);
1126 } while (count < max_frames && (c.offset - scan_ctx->offset) < 64 * 1024);
1128 GST_DEBUG ("found %d consecutive frames", count);
1133 aac_type_find_scan_loas_frames (GstTypeFind * tf, DataScanCtx * scan_ctx,
1136 DataScanCtx c = *scan_ctx;
1142 if (!data_scan_ctx_ensure_data (tf, &c, 3))
1145 /* AudioSyncStream */
1146 len = ((c.data[1] & 0x1f) << 8) | c.data[2];
1147 /* add size of sync stream header */
1150 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
1151 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
1155 /* check length of frame */
1156 snc = GST_READ_UINT16_BE (c.data + len);
1157 if ((snc & 0xffe0) != 0x56e0) {
1158 GST_DEBUG ("No sync found at 0x%" G_GINT64_MODIFIER "x", c.offset + len);
1164 GST_DEBUG ("Found LOAS syncword #%d at offset 0x%" G_GINT64_MODIFIER "x, "
1165 "framelen %u", count, c.offset, len);
1167 data_scan_ctx_advance (tf, &c, len);
1168 } while (count < max_frames && (c.offset - scan_ctx->offset) < 64 * 1024);
1170 GST_DEBUG ("found %d consecutive frames", count);
1174 /*** audio/mpeg version 2, 4 ***/
1176 static GstStaticCaps aac_caps = GST_STATIC_CAPS ("audio/mpeg, "
1177 "mpegversion = (int) { 2, 4 }, framed = (bool) false");
1178 #define AAC_CAPS (gst_static_caps_get(&aac_caps))
1179 #define AAC_AMOUNT (4096)
1181 aac_type_find (GstTypeFind * tf, gpointer unused)
1183 DataScanCtx c = { 0, NULL, 0 };
1184 GstTypeFindProbability best_probability = GST_TYPE_FIND_NONE;
1185 GstCaps *best_caps = NULL;
1186 gint best_count = 0;
1188 while (c.offset < AAC_AMOUNT) {
1189 guint snc, len, offset, i;
1191 /* detect adts header or adif header.
1192 * The ADIF header is 4 bytes, that should be OK. The ADTS header, on
1193 * the other hand, is 14 bits only, so we require one valid frame with
1194 * again a valid syncpoint on the next one (28 bits) for certainty. We
1195 * require 4 kB, which is quite a lot, since frames are generally 200-400
1197 * LOAS has 2 possible syncwords, which are 11 bits and 16 bits long.
1198 * The following stream syntax depends on which one is found.
1200 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
1203 snc = GST_READ_UINT16_BE (c.data);
1204 if (G_UNLIKELY ((snc & 0xfff6) == 0xfff0)) {
1205 /* ADTS header - find frame length */
1206 GST_DEBUG ("Found one ADTS syncpoint at offset 0x%" G_GINT64_MODIFIER
1207 "x, tracing next...", c.offset);
1208 len = ((c.data[3] & 0x03) << 11) |
1209 (c.data[4] << 3) | ((c.data[5] & 0xe0) >> 5);
1211 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 6)) {
1212 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
1217 /* check if there's a second ADTS frame */
1218 snc = GST_READ_UINT16_BE (c.data + offset);
1219 if ((snc & 0xfff6) == 0xfff0) {
1221 guint mpegversion, sample_freq_idx, channel_config, profile_idx, rate;
1222 guint8 audio_config[2];
1224 mpegversion = (c.data[1] & 0x08) ? 2 : 4;
1225 profile_idx = c.data[2] >> 6;
1226 sample_freq_idx = ((c.data[2] & 0x3c) >> 2);
1227 channel_config = ((c.data[2] & 0x01) << 2) + (c.data[3] >> 6);
1229 GST_DEBUG ("Found second ADTS-%d syncpoint at offset 0x%"
1230 G_GINT64_MODIFIER "x, framelen %u", mpegversion, c.offset, len);
1232 /* 0xd and 0xe are reserved. 0xf means the sample frequency is directly
1233 * specified in the header, but that's not allowed for ADTS */
1234 if (sample_freq_idx > 0xc) {
1235 GST_DEBUG ("Unexpected sample frequency index %d or wrong sync",
1240 rate = gst_codec_utils_aac_get_sample_rate_from_index (sample_freq_idx);
1241 GST_LOG ("ADTS: profile=%u, rate=%u", profile_idx, rate);
1243 /* The ADTS frame header is slightly different from the
1244 * AudioSpecificConfig defined for the MPEG-4 container, so we just
1245 * construct enough of it for getting the level here. */
1246 /* ADTS counts profiles from 0 instead of 1 to save bits */
1247 audio_config[0] = (profile_idx + 1) << 3;
1248 audio_config[0] |= (sample_freq_idx >> 1) & 0x7;
1249 audio_config[1] = (sample_freq_idx & 0x1) << 7;
1250 audio_config[1] |= (channel_config & 0xf) << 3;
1252 caps = gst_caps_new_simple ("audio/mpeg",
1253 "framed", G_TYPE_BOOLEAN, FALSE,
1254 "mpegversion", G_TYPE_INT, mpegversion,
1255 "stream-format", G_TYPE_STRING, "adts", NULL);
1257 gst_codec_utils_aac_caps_set_level_and_profile (caps, audio_config, 2);
1259 /* add rate and number of channels if we can */
1260 if (channel_config != 0 && channel_config <= 7) {
1261 const guint channels_map[] = { 0, 1, 2, 3, 4, 5, 6, 8 };
1263 gst_caps_set_simple (caps, "channels", G_TYPE_INT,
1264 channels_map[channel_config], "rate", G_TYPE_INT, rate, NULL);
1267 /* length of the second ADTS frame */
1268 len = ((c.data[offset + 3] & 0x03) << 11) |
1269 (c.data[offset + 4] << 3) | ((c.data[offset + 5] & 0xe0) >> 5);
1271 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, offset + len + 6)) {
1272 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
1273 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, caps);
1276 /* find more aac sync to select correctly */
1277 /* check if there's a third/fourth/fifth/sixth ADTS frame, if there is a sixth frame, set probability to maximum:100% */
1278 for (i = 3; i <= 6; i++) {
1279 len = ((c.data[offset + 3] & 0x03) << 11) |
1280 (c.data[offset + 4] << 3) | ((c.data[offset + 5] & 0xe0) >> 5);
1282 || !data_scan_ctx_ensure_data (tf, &c, offset + len + 6)) {
1283 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u",
1287 snc = GST_READ_UINT16_BE (c.data + offset);
1288 if ((snc & 0xfff6) == 0xfff0) {
1289 GST_DEBUG ("Find %und Sync..probability is %u ", i,
1290 GST_TYPE_FIND_LIKELY + 5 * (i - 2));
1296 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 5 * (i - 3), caps);
1299 gst_caps_unref (caps);
1303 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
1304 } else if (G_UNLIKELY ((snc & 0xffe0) == 0x56e0 || snc == 0x4de1)) {
1308 GST_INFO ("Possible LOAS syncword at offset 0x%" G_GINT64_MODIFIER
1309 "x, scanning for more frames...", c.offset);
1312 count = aac_type_find_scan_loas_frames_ep (tf, &c, 20);
1314 count = aac_type_find_scan_loas_frames (tf, &c, 20);
1316 if (count >= 3 && count > best_count) {
1317 gst_caps_replace (&best_caps, NULL);
1318 best_caps = gst_caps_new_simple ("audio/mpeg",
1319 "framed", G_TYPE_BOOLEAN, FALSE,
1320 "mpegversion", G_TYPE_INT, 4,
1321 "stream-format", G_TYPE_STRING, "loas", NULL);
1323 best_probability = GST_TYPE_FIND_POSSIBLE - 10 + count * 3;
1324 if (best_probability >= GST_TYPE_FIND_LIKELY)
1327 } else if (!memcmp (c.data, "ADIF", 4)) {
1329 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
1330 "framed", G_TYPE_BOOLEAN, FALSE, "mpegversion", G_TYPE_INT, 4,
1331 "stream-format", G_TYPE_STRING, "adif", NULL);
1337 data_scan_ctx_advance (tf, &c, 1);
1340 if (best_probability > GST_TYPE_FIND_NONE) {
1341 gst_type_find_suggest (tf, best_probability, best_caps);
1342 gst_caps_unref (best_caps);
1346 /*** audio/mpeg version 1 ***/
1349 * The chance that random data is identified as a valid mp3 header is 63 / 2^18
1350 * (0.024%) per try. This makes the function for calculating false positives
1351 * 1 - (1 - ((63 / 2 ^18) ^ GST_MP3_TYPEFIND_MIN_HEADERS)) ^ buffersize)
1352 * This has the following probabilities of false positives:
1353 * datasize MIN_HEADERS
1355 * 4096 62.6% 0.02% 0% 0%
1356 * 16384 98% 0.09% 0% 0%
1357 * 1 MiB 100% 5.88% 0% 0%
1358 * 1 GiB 100% 100% 1.44% 0%
1359 * 1 TiB 100% 100% 100% 0.35%
1360 * This means that the current choice (3 headers by most of the time 4096 byte
1361 * buffers is pretty safe for now.
1363 * The max. size of each frame is 1440 bytes, which means that for N frames to
1364 * be detected, we need 1440 * GST_MP3_TYPEFIND_MIN_HEADERS + 3 bytes of data.
1365 * Assuming we step into the stream right after the frame header, this
1366 * means we need 1440 * (GST_MP3_TYPEFIND_MIN_HEADERS + 1) - 1 + 3 bytes
1367 * of data (5762) to always detect any mp3.
1370 static const guint mp3types_bitrates[2][3][16] =
1371 { {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
1372 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
1373 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
1374 {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
1375 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
1376 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}},
1379 static const guint mp3types_freqs[3][3] = { {11025, 12000, 8000},
1380 {22050, 24000, 16000},
1381 {44100, 48000, 32000}
1385 mp3_type_frame_length_from_header (guint32 header, guint * put_layer,
1386 guint * put_channels, guint * put_bitrate, guint * put_samplerate,
1387 gboolean * may_be_free_format, gint possible_free_framelen)
1389 guint bitrate, layer, length, mode, samplerate, version, channels;
1391 if ((header & 0xffe00000) != 0xffe00000)
1394 /* we don't need extension, copyright, original or
1395 * emphasis for the frame length */
1399 mode = header & 0x3;
1403 length = header & 0x1;
1406 /* sampling frequency */
1407 samplerate = header & 0x3;
1408 if (samplerate == 3)
1413 bitrate = header & 0xF;
1414 if (bitrate == 0 && possible_free_framelen == -1) {
1415 GST_LOG ("Possibly a free format mp3 - signaling");
1416 *may_be_free_format = TRUE;
1418 if (bitrate == 15 || (bitrate == 0 && possible_free_framelen == -1))
1421 /* ignore error correction, too */
1425 layer = 4 - (header & 0x3);
1430 /* version 0=MPEG2.5; 2=MPEG2; 3=MPEG1 */
1431 version = header & 0x3;
1436 channels = (mode == 3) ? 1 : 2;
1437 samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate];
1439 /* possible freeform mp3 */
1442 length += possible_free_framelen;
1443 bitrate = length * samplerate / 48000;
1445 length += possible_free_framelen;
1446 bitrate = length * samplerate /
1447 ((layer == 3 && version != 3) ? 72000 : 144000);
1449 /* freeform mp3 should have a higher-than-usually-allowed bitrate */
1450 GST_LOG ("calculated bitrate: %u, max usually: %u", bitrate,
1451 mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][14]);
1452 if (bitrate < mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][14])
1456 bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate];
1458 length = ((12000 * bitrate / samplerate) + length) * 4;
1460 length += ((layer == 3
1461 && version != 3) ? 72000 : 144000) * bitrate / samplerate;
1465 GST_LOG ("mp3typefind: calculated mp3 frame length of %u bytes", length);
1467 ("mp3typefind: samplerate = %u - bitrate = %u - layer = %u - version = %u"
1468 " - channels = %u", samplerate, bitrate, layer, version, channels);
1473 *put_channels = channels;
1475 *put_bitrate = bitrate;
1477 *put_samplerate = samplerate;
1483 static GstStaticCaps mp3_caps = GST_STATIC_CAPS ("audio/mpeg, "
1484 "mpegversion = (int) 1, layer = (int) [ 1, 3 ]");
1485 #define MP3_CAPS (gst_static_caps_get(&mp3_caps))
1487 * random values for typefinding
1488 * if no more data is available, we will return a probability of
1489 * (found_headers/TRY_HEADERS) * (MAXIMUM * (TRY_SYNC - bytes_skipped)
1491 * if found_headers >= MIN_HEADERS
1493 #define GST_MP3_TYPEFIND_MIN_HEADERS (2)
1494 #define GST_MP3_TYPEFIND_TRY_HEADERS (5)
1495 #define GST_MP3_TYPEFIND_TRY_SYNC (GST_TYPE_FIND_MAXIMUM * 100) /* 10kB */
1496 #define GST_MP3_TYPEFIND_SYNC_SIZE (2048)
1497 #define GST_MP3_WRONG_HEADER (10)
1500 mp3_type_find_at_offset (GstTypeFind * tf, guint64 start_off,
1501 guint * found_layer, GstTypeFindProbability * found_prob)
1503 const guint8 *data = NULL;
1504 const guint8 *data_end = NULL;
1507 gint last_free_offset = -1;
1508 gint last_free_framelen = -1;
1509 gboolean headerstart = TRUE;
1516 while (skipped < GST_MP3_TYPEFIND_TRY_SYNC) {
1518 size = GST_MP3_TYPEFIND_SYNC_SIZE * 2;
1521 data = gst_type_find_peek (tf, skipped + start_off, size);
1522 } while (size > 10 && !data);
1525 data_end = data + size;
1527 if (*data == 0xFF) {
1528 const guint8 *head_data = NULL;
1529 guint layer = 0, bitrate, samplerate, channels;
1530 guint found = 0; /* number of valid headers found */
1531 guint64 offset = skipped;
1532 gboolean changed = FALSE;
1533 guint prev_layer = 0;
1534 guint prev_channels = 0, prev_samplerate = 0;
1536 while (found < GST_MP3_TYPEFIND_TRY_HEADERS) {
1539 gboolean free = FALSE;
1541 if ((gint64) (offset - skipped + 4) >= 0 &&
1542 data + offset - skipped + 4 < data_end) {
1543 head_data = data + offset - skipped;
1545 head_data = gst_type_find_peek (tf, offset + start_off, 4);
1549 head = GST_READ_UINT32_BE (head_data);
1550 if (!(length = mp3_type_frame_length_from_header (head, &layer,
1551 &channels, &bitrate, &samplerate, &free,
1552 last_free_framelen))) {
1554 if (last_free_offset == -1)
1555 last_free_offset = offset;
1557 last_free_framelen = offset - last_free_offset;
1558 offset = last_free_offset;
1562 last_free_framelen = -1;
1565 /* Mark the fact that we didn't find a valid header at the beginning */
1567 headerstart = FALSE;
1569 GST_LOG ("%d. header at offset %" G_GUINT64_FORMAT
1570 " (0x%" G_GINT64_MODIFIER "x) was not an mp3 header "
1571 "(possibly-free: %s)", found + 1, start_off + offset,
1572 start_off + offset, free ? "yes" : "no");
1575 if ((prev_layer && prev_layer != layer) ||
1576 /* (prev_bitrate && prev_bitrate != bitrate) || <-- VBR */
1577 (prev_samplerate && prev_samplerate != samplerate) ||
1578 (prev_channels && prev_channels != channels)) {
1579 /* this means an invalid property, or a change, which might mean
1580 * that this is not a mp3 but just a random bytestream. It could
1581 * be a freaking funky encoded mp3 though. We'll just not count
1587 GST_LOG ("found %d. header at offset %" G_GUINT64_FORMAT " (0x%"
1588 G_GINT64_MODIFIER "X)", found, start_off + offset,
1589 start_off + offset);
1592 prev_channels = channels;
1593 prev_samplerate = samplerate;
1597 g_assert (found <= GST_MP3_TYPEFIND_TRY_HEADERS);
1598 if (found != 0 && head_data == NULL &&
1599 gst_type_find_peek (tf, offset + start_off - 1, 1) == NULL)
1600 /* Incomplete last frame - don't count it. */
1602 if (found == GST_MP3_TYPEFIND_TRY_HEADERS ||
1603 (found >= GST_MP3_TYPEFIND_MIN_HEADERS && head_data == NULL)) {
1604 /* we can make a valid guess */
1605 guint probability = found * GST_TYPE_FIND_MAXIMUM *
1606 (GST_MP3_TYPEFIND_TRY_SYNC - skipped) /
1607 GST_MP3_TYPEFIND_TRY_HEADERS / GST_MP3_TYPEFIND_TRY_SYNC;
1610 && probability > (GST_TYPE_FIND_MINIMUM + GST_MP3_WRONG_HEADER))
1611 probability -= GST_MP3_WRONG_HEADER;
1612 if (probability < GST_TYPE_FIND_MINIMUM)
1613 probability = GST_TYPE_FIND_MINIMUM;
1617 probability = (probability + GST_TYPE_FIND_MAXIMUM) / 2;
1620 ("audio/mpeg calculated %u = %u * %u / %u * (%u - %"
1621 G_GUINT64_FORMAT ") / %u", probability, GST_TYPE_FIND_MAXIMUM,
1622 found, GST_MP3_TYPEFIND_TRY_HEADERS, GST_MP3_TYPEFIND_TRY_SYNC,
1623 (guint64) skipped, GST_MP3_TYPEFIND_TRY_SYNC);
1624 /* make sure we're not id3 tagged */
1625 head_data = gst_type_find_peek (tf, -128, 3);
1626 if (head_data && (memcmp (head_data, "TAG", 3) == 0)) {
1629 g_assert (probability <= GST_TYPE_FIND_MAXIMUM);
1631 *found_prob = probability;
1632 if (probability > 0)
1633 *found_layer = layer;
1644 mp3_type_find (GstTypeFind * tf, gpointer unused)
1646 GstTypeFindProbability prob, mid_prob;
1648 guint layer, mid_layer;
1651 mp3_type_find_at_offset (tf, 0, &layer, &prob);
1652 length = gst_type_find_get_length (tf);
1654 if (length == 0 || length == (guint64) - 1) {
1660 /* if we're pretty certain already, skip the additional check */
1661 if (prob >= GST_TYPE_FIND_LIKELY)
1664 mp3_type_find_at_offset (tf, length / 2, &mid_layer, &mid_prob);
1668 GST_LOG ("detected audio/mpeg only in the middle (p=%u)", mid_prob);
1674 if (layer != mid_layer) {
1675 GST_WARNING ("audio/mpeg layer discrepancy: %u vs. %u", layer, mid_layer);
1676 return; /* FIXME: or should we just go with the one in the middle? */
1679 /* detected mpeg audio both in middle of the file and at the start */
1680 prob = (prob + mid_prob) / 2;
1684 /* a valid header right at the start makes it more likely
1685 * that this is actually plain mpeg-1 audio */
1687 data = gst_type_find_peek (tf, 0, 4); /* use min. frame size? */
1688 if (data && mp3_type_frame_length_from_header (GST_READ_UINT32_BE (data),
1689 &layer, NULL, NULL, NULL, NULL, 0) != 0) {
1690 prob = MIN (prob + 10, GST_TYPE_FIND_MAXIMUM);
1701 g_return_if_fail (layer >= 1 && layer <= 3);
1703 gst_type_find_suggest_simple (tf, prob, "audio/mpeg",
1704 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, layer,
1705 "parsed", G_TYPE_BOOLEAN, FALSE, NULL);
1709 /*** audio/x-musepack ***/
1711 static GstStaticCaps musepack_caps =
1712 GST_STATIC_CAPS ("audio/x-musepack, streamversion= (int) { 7, 8 }");
1714 #define MUSEPACK_CAPS (gst_static_caps_get(&musepack_caps))
1716 musepack_type_find (GstTypeFind * tf, gpointer unused)
1718 const guint8 *data = gst_type_find_peek (tf, 0, 4);
1719 GstTypeFindProbability prop = GST_TYPE_FIND_MINIMUM;
1720 gint streamversion = -1;
1722 if (data && memcmp (data, "MP+", 3) == 0) {
1724 if ((data[3] & 0x7f) == 7) {
1725 prop = GST_TYPE_FIND_MAXIMUM;
1727 prop = GST_TYPE_FIND_LIKELY + 10;
1729 } else if (data && memcmp (data, "MPCK", 4) == 0) {
1731 prop = GST_TYPE_FIND_MAXIMUM;
1734 if (streamversion != -1) {
1735 gst_type_find_suggest_simple (tf, prop, "audio/x-musepack",
1736 "streamversion", G_TYPE_INT, streamversion, NULL);
1740 /*** audio/x-ac3 ***/
1741 /* FIXME 0.11: should be audio/ac3, but isn't for backwards compatibility */
1742 static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
1744 #define AC3_CAPS (gst_static_caps_get(&ac3_caps))
1746 static GstStaticCaps eac3_caps = GST_STATIC_CAPS ("audio/x-eac3");
1748 #define EAC3_CAPS (gst_static_caps_get(&eac3_caps))
1752 unsigned short bit_rate;
1753 unsigned short frm_size[3];
1756 static const struct ac3_frmsize ac3_frmsizecod_tbl[] = {
1759 {40, {80, 87, 120}},
1760 {40, {80, 88, 120}},
1761 {48, {96, 104, 144}},
1762 {48, {96, 105, 144}},
1763 {56, {112, 121, 168}},
1764 {56, {112, 122, 168}},
1765 {64, {128, 139, 192}},
1766 {64, {128, 140, 192}},
1767 {80, {160, 174, 240}},
1768 {80, {160, 175, 240}},
1769 {96, {192, 208, 288}},
1770 {96, {192, 209, 288}},
1771 {112, {224, 243, 336}},
1772 {112, {224, 244, 336}},
1773 {128, {256, 278, 384}},
1774 {128, {256, 279, 384}},
1775 {160, {320, 348, 480}},
1776 {160, {320, 349, 480}},
1777 {192, {384, 417, 576}},
1778 {192, {384, 418, 576}},
1779 {224, {448, 487, 672}},
1780 {224, {448, 488, 672}},
1781 {256, {512, 557, 768}},
1782 {256, {512, 558, 768}},
1783 {320, {640, 696, 960}},
1784 {320, {640, 697, 960}},
1785 {384, {768, 835, 1152}},
1786 {384, {768, 836, 1152}},
1787 {448, {896, 975, 1344}},
1788 {448, {896, 976, 1344}},
1789 {512, {1024, 1114, 1536}},
1790 {512, {1024, 1115, 1536}},
1791 {576, {1152, 1253, 1728}},
1792 {576, {1152, 1254, 1728}},
1793 {640, {1280, 1393, 1920}},
1794 {640, {1280, 1394, 1920}}
1798 ac3_type_find (GstTypeFind * tf, gpointer unused)
1800 DataScanCtx c = { 0, NULL, 0 };
1802 /* Search for an ac3 frame; not necessarily right at the start, but give it
1803 * a lower probability if not found right at the start. Check that the
1804 * frame is followed by a second frame at the expected offset.
1805 * We could also check the two ac3 CRCs, but we don't do that right now */
1806 while (c.offset < 1024) {
1807 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
1810 if (c.data[0] == 0x0b && c.data[1] == 0x77) {
1811 guint bsid = c.data[5] >> 3;
1815 guint fscod = c.data[4] >> 6;
1816 guint frmsizecod = c.data[4] & 0x3f;
1818 if (fscod < 3 && frmsizecod < 38) {
1819 DataScanCtx c_next = c;
1822 frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
1823 GST_LOG ("possible AC3 frame sync at offset %"
1824 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1825 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1826 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1828 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1829 fscod = c_next.data[4] >> 6;
1830 frmsizecod = c_next.data[4] & 0x3f;
1832 if (fscod < 3 && frmsizecod < 38) {
1833 GstTypeFindProbability prob;
1835 GST_LOG ("found second AC3 frame (size=%u), looks good",
1836 ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod]);
1838 prob = GST_TYPE_FIND_MAXIMUM;
1840 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1842 gst_type_find_suggest (tf, prob, AC3_CAPS);
1846 GST_LOG ("no second AC3 frame found, false sync");
1850 } else if (bsid <= 16 && bsid > 10) {
1852 DataScanCtx c_next = c;
1855 frame_size = (((c.data[2] & 0x07) << 8) + c.data[3]) + 1;
1856 GST_LOG ("possible E-AC3 frame sync at offset %"
1857 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1858 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1859 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1861 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1862 GstTypeFindProbability prob;
1864 GST_LOG ("found second E-AC3 frame, looks good");
1866 prob = GST_TYPE_FIND_MAXIMUM;
1868 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1870 gst_type_find_suggest (tf, prob, EAC3_CAPS);
1873 GST_LOG ("no second E-AC3 frame found, false sync");
1877 GST_LOG ("invalid AC3 BSID: %u", bsid);
1880 data_scan_ctx_advance (tf, &c, 1);
1884 /*** audio/x-dts ***/
1885 static GstStaticCaps dts_caps = GST_STATIC_CAPS ("audio/x-dts");
1886 #define DTS_CAPS (gst_static_caps_get (&dts_caps))
1887 #define DTS_MIN_FRAMESIZE 96
1888 #define DTS_MAX_FRAMESIZE 18725 /* 16384*16/14 */
1891 dts_parse_frame_header (DataScanCtx * c, guint * frame_size,
1892 guint * sample_rate, guint * channels, guint * depth, guint * endianness)
1894 static const int sample_rates[16] = { 0, 8000, 16000, 32000, 0, 0, 11025,
1895 22050, 44100, 0, 0, 12000, 24000, 48000, 96000, 192000
1897 static const guint8 channels_table[16] = { 1, 2, 2, 2, 2, 3, 3, 4, 4, 5,
1902 guint num_blocks, chans, lfe, i;
1904 marker = GST_READ_UINT32_BE (c->data);
1906 /* raw big endian or 14-bit big endian */
1907 if (marker == 0x7FFE8001 || marker == 0x1FFFE800) {
1908 *endianness = G_BIG_ENDIAN;
1909 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1910 hdr[i] = GST_READ_UINT16_BE (c->data + (i * sizeof (guint16)));
1912 /* raw little endian or 14-bit little endian */
1913 if (marker == 0xFE7F0180 || marker == 0xFF1F00E8) {
1914 *endianness = G_LITTLE_ENDIAN;
1915 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1916 hdr[i] = GST_READ_UINT16_LE (c->data + (i * sizeof (guint16)));
1921 GST_LOG ("dts sync marker 0x%08x at offset %u", marker, (guint) c->offset);
1924 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8) {
1925 if ((hdr[2] & 0xFFF0) != 0x07F0)
1927 /* discard top 2 bits (2 void), shift in 2 */
1928 hdr[0] = (hdr[0] << 2) | ((hdr[1] >> 12) & 0x0003);
1929 /* discard top 4 bits (2 void, 2 shifted into hdr[0]), shift in 4 etc. */
1930 hdr[1] = (hdr[1] << 4) | ((hdr[2] >> 10) & 0x000F);
1931 hdr[2] = (hdr[2] << 6) | ((hdr[3] >> 8) & 0x003F);
1932 hdr[3] = (hdr[3] << 8) | ((hdr[4] >> 6) & 0x00FF);
1933 hdr[4] = (hdr[4] << 10) | ((hdr[5] >> 4) & 0x03FF);
1934 hdr[5] = (hdr[5] << 12) | ((hdr[6] >> 2) & 0x0FFF);
1935 hdr[6] = (hdr[6] << 14) | ((hdr[7] >> 0) & 0x3FFF);
1936 g_assert (hdr[0] == 0x7FFE && hdr[1] == 0x8001);
1942 GST_LOG ("frame header: %04x%04x%04x%04x", hdr[2], hdr[3], hdr[4], hdr[5]);
1944 num_blocks = (hdr[2] >> 2) & 0x7F;
1945 *frame_size = (((hdr[2] & 0x03) << 12) | (hdr[3] >> 4)) + 1;
1946 chans = ((hdr[3] & 0x0F) << 2) | (hdr[4] >> 14);
1947 *sample_rate = sample_rates[(hdr[4] >> 10) & 0x0F];
1948 lfe = (hdr[5] >> 9) & 0x03;
1950 if (num_blocks < 5 || *frame_size < 96 || *sample_rate == 0)
1953 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8)
1954 *frame_size = (*frame_size * 16) / 14; /* FIXME: round up? */
1956 if (chans < G_N_ELEMENTS (channels_table))
1957 *channels = channels_table[chans] + ((lfe) ? 1 : 0);
1965 dts_type_find (GstTypeFind * tf, gpointer unused)
1967 DataScanCtx c = { 0, NULL, 0 };
1969 /* Search for an dts frame; not necessarily right at the start, but give it
1970 * a lower probability if not found right at the start. Check that the
1971 * frame is followed by a second frame at the expected offset. */
1972 while (c.offset <= DTS_MAX_FRAMESIZE) {
1973 guint frame_size = 0, rate = 0, chans = 0, depth = 0, endianness = 0;
1975 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, DTS_MIN_FRAMESIZE)))
1978 if (G_UNLIKELY (dts_parse_frame_header (&c, &frame_size, &rate, &chans,
1979 &depth, &endianness))) {
1980 GstTypeFindProbability prob;
1983 prob = (c.offset == 0) ? GST_TYPE_FIND_LIKELY : GST_TYPE_FIND_POSSIBLE;
1985 /* check for second frame sync */
1987 data_scan_ctx_advance (tf, &next_c, frame_size);
1988 if (data_scan_ctx_ensure_data (tf, &next_c, 4)) {
1989 GST_LOG ("frame size: %u 0x%04x", frame_size, frame_size);
1990 GST_MEMDUMP ("second frame sync", next_c.data, 4);
1991 if (GST_READ_UINT32_BE (c.data) == GST_READ_UINT32_BE (next_c.data))
1992 prob = GST_TYPE_FIND_MAXIMUM;
1996 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
1997 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, chans,
1998 "depth", G_TYPE_INT, depth, "endianness", G_TYPE_INT, endianness,
1999 "framed", G_TYPE_BOOLEAN, FALSE, NULL);
2001 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
2002 "rate", G_TYPE_INT, rate, "depth", G_TYPE_INT, depth,
2003 "endianness", G_TYPE_INT, endianness,
2004 "framed", G_TYPE_BOOLEAN, FALSE, NULL);
2010 data_scan_ctx_advance (tf, &c, 1);
2015 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
2016 /* can only be detected by using the extension, in which case we use the default
2018 static GstStaticCaps gsm_caps =
2019 GST_STATIC_CAPS ("audio/x-gsm, rate=8000, channels=1");
2021 #define GSM_CAPS (gst_static_caps_get(&gsm_caps))
2025 static GstStaticCaps wavpack_caps =
2026 GST_STATIC_CAPS ("audio/x-wavpack, framed = (boolean) false");
2028 #define WAVPACK_CAPS (gst_static_caps_get(&wavpack_caps))
2030 static GstStaticCaps wavpack_correction_caps =
2031 GST_STATIC_CAPS ("audio/x-wavpack-correction, framed = (boolean) false");
2033 #define WAVPACK_CORRECTION_CAPS (gst_static_caps_get(&wavpack_correction_caps))
2036 wavpack_type_find (GstTypeFind * tf, gpointer unused)
2038 GstTypeFindProbability base_prob = GST_TYPE_FIND_POSSIBLE;
2042 guint count_wv, count_wvc;
2044 data = gst_type_find_peek (tf, 0, 32);
2048 if (data[0] != 'w' || data[1] != 'v' || data[2] != 'p' || data[3] != 'k')
2051 /* Note: wavpack blocks can be fairly large (easily 60-110k), possibly
2052 * larger than the max. limits imposed by certain typefinding elements
2053 * like id3demux or apedemux, so typefinding is most likely only going to
2054 * work in pull-mode */
2055 blocksize = GST_READ_UINT32_LE (data + 4);
2056 GST_LOG ("wavpack header, blocksize=0x%04x", blocksize);
2057 /* If bigger than maximum allowed blocksize, refuse */
2058 if (blocksize > 131072)
2063 while (offset < 8 + blocksize) {
2066 /* get chunk header */
2067 GST_LOG ("peeking at chunk at offset 0x%04x", (guint) offset);
2068 data = gst_type_find_peek (tf, offset, 4);
2071 sublen = ((guint32) data[1]) << 1;
2072 if (data[0] & 0x80) {
2073 sublen |= (((guint32) data[2]) << 9) | (((guint32) data[3]) << 17);
2074 sublen += 1 + 3; /* id + length */
2076 sublen += 1 + 1; /* id + length */
2078 if (offset + sublen > 8 + blocksize) {
2079 GST_LOG ("chunk length too big (%u > %" G_GUINT64_FORMAT ")", sublen,
2080 blocksize - offset);
2083 if ((data[0] & 0x20) == 0) {
2084 switch (data[0] & 0x0f) {
2085 case 0xa: /* ID_WV_BITSTREAM */
2086 case 0xc: /* ID_WVX_BITSTREAM */
2089 case 0xb: /* ID_WVC_BITSTREAM */
2095 if (count_wv >= 5 || count_wvc >= 5)
2101 /* check for second block header */
2102 data = gst_type_find_peek (tf, 8 + blocksize, 4);
2103 if (data != NULL && memcmp (data, "wvpk", 4) == 0) {
2104 GST_DEBUG ("found second block sync");
2105 base_prob = GST_TYPE_FIND_LIKELY;
2108 GST_DEBUG ("wvc=%d, wv=%d", count_wvc, count_wv);
2110 if (count_wvc > 0 && count_wvc > count_wv) {
2111 gst_type_find_suggest (tf,
2112 MIN (base_prob + 5 * count_wvc, GST_TYPE_FIND_NEARLY_CERTAIN),
2113 WAVPACK_CORRECTION_CAPS);
2114 } else if (count_wv > 0) {
2115 gst_type_find_suggest (tf,
2116 MIN (base_prob + 5 * count_wv, GST_TYPE_FIND_NEARLY_CERTAIN),
2121 /*** application/postscrip ***/
2122 static GstStaticCaps postscript_caps =
2123 GST_STATIC_CAPS ("application/postscript");
2125 #define POSTSCRIPT_CAPS (gst_static_caps_get(&postscript_caps))
2128 postscript_type_find (GstTypeFind * tf, gpointer unused)
2130 const guint8 *data = gst_type_find_peek (tf, 0, 3);
2134 if (data[0] == 0x04)
2136 if (data[0] == '%' && data[1] == '!')
2137 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, POSTSCRIPT_CAPS);
2141 /*** image/svg+xml ***/
2142 static GstStaticCaps svg_caps = GST_STATIC_CAPS ("image/svg+xml");
2144 #define SVG_CAPS (gst_static_caps_get(&svg_caps))
2147 svg_type_find (GstTypeFind * tf, gpointer unused)
2149 static const gchar svg_doctype[] = "!DOCTYPE svg";
2150 static const gchar svg_tag[] = "<svg";
2151 DataScanCtx c = { 0, NULL, 0 };
2153 while (c.offset <= 1024) {
2154 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
2157 if (memcmp (svg_doctype, c.data, 12) == 0) {
2158 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVG_CAPS);
2160 } else if (memcmp (svg_tag, c.data, 4) == 0) {
2161 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, SVG_CAPS);
2164 data_scan_ctx_advance (tf, &c, 1);
2168 /*** multipart/x-mixed-replace mimestream ***/
2170 static GstStaticCaps multipart_caps =
2171 GST_STATIC_CAPS ("multipart/x-mixed-replace");
2172 #define MULTIPART_CAPS gst_static_caps_get(&multipart_caps)
2174 /* multipart/x-mixed replace is:
2175 * <maybe some whitespace>--<some ascii chars>[\r]\n
2176 * <more ascii chars>[\r]\nContent-type:<more ascii>[\r]\n */
2178 multipart_type_find (GstTypeFind * tf, gpointer unused)
2183 #define MULTIPART_MAX_BOUNDARY_OFFSET 16
2184 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_BOUNDARY_OFFSET);
2189 x - data < MULTIPART_MAX_BOUNDARY_OFFSET - 2 && g_ascii_isspace (*x);
2191 if (x[0] != '-' || x[1] != '-')
2194 /* Could be okay, peek what should be enough for a complete header */
2195 #define MULTIPART_MAX_HEADER_SIZE 256
2196 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_HEADER_SIZE);
2200 for (x = data; x - data < MULTIPART_MAX_HEADER_SIZE - 14; x++) {
2201 if (!isascii (*x)) {
2205 !g_ascii_strncasecmp ("content-type:", (gchar *) x + 1, 13)) {
2206 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MULTIPART_CAPS);
2213 /*** video/mpeg systemstream ***/
2214 #if defined(TIZEN_PROFILE_TV) || !defined(TIZEN_FEATURE_DISABLE_MIME_TYPES)
2215 static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, "
2216 "systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
2218 #define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
2220 #define IS_MPEG_HEADER(data) (G_UNLIKELY((((guint8 *)(data))[0] == 0x00) && \
2221 (((guint8 *)(data))[1] == 0x00) && \
2222 (((guint8 *)(data))[2] == 0x01)))
2223 #if defined(TIZEN_PROFILE_TV) || !defined(TIZEN_FEATURE_DISABLE_MIME_TYPES)
2224 #define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
2225 #define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
2226 #define IS_MPEG_PACK_HEADER(data) (IS_MPEG_HEADER (data) && \
2227 IS_MPEG_PACK_CODE (((guint8 *)(data))[3]))
2229 #define IS_MPEG_PES_CODE(b) (((b) & 0xF0) == 0xE0 || ((b) & 0xF0) == 0xC0 || \
2231 #define IS_MPEG_PES_HEADER(data) (IS_MPEG_HEADER (data) && \
2232 IS_MPEG_PES_CODE (((guint8 *)(data))[3]))
2234 #define MPEG2_MAX_PROBE_LENGTH (128 * 1024) /* 128kB should be 64 packs of the
2235 * most common 2kB pack size. */
2237 #define MPEG2_MIN_SYS_HEADERS 2
2238 #define MPEG2_MAX_SYS_HEADERS 5
2242 mpeg_sys_is_valid_pack (GstTypeFind * tf, const guint8 * data, guint len,
2245 /* Check the pack header @ offset for validity, assuming that the 4 byte header
2246 * itself has already been checked. */
2252 /* Check marker bits */
2253 if ((data[4] & 0xC4) == 0x44) {
2258 if ((data[6] & 0x04) != 0x04 ||
2259 (data[8] & 0x04) != 0x04 ||
2260 (data[9] & 0x01) != 0x01 || (data[12] & 0x03) != 0x03)
2263 stuff_len = data[13] & 0x07;
2265 /* Check the following header bytes, if we can */
2266 if ((14 + stuff_len + 4) <= len) {
2267 if (!IS_MPEG_HEADER (data + 14 + stuff_len))
2271 *pack_size = 14 + stuff_len;
2273 } else if ((data[4] & 0xF1) == 0x21) {
2275 if ((data[6] & 0x01) != 0x01 ||
2276 (data[8] & 0x01) != 0x01 ||
2277 (data[9] & 0x80) != 0x80 || (data[11] & 0x01) != 0x01)
2280 /* Check the following header bytes, if we can */
2281 if ((12 + 4) <= len) {
2282 if (!IS_MPEG_HEADER (data + 12))
2293 #if defined(TIZEN_PROFILE_TV) || !defined(TIZEN_FEATURE_DISABLE_MIME_TYPES)
2295 mpeg_sys_is_valid_pes (GstTypeFind * tf, const guint8 * data, guint len,
2298 guint pes_packet_len;
2300 /* Check the PES header at the given position, assuming the header code itself
2301 * was already checked */
2305 /* For MPEG Program streams, unbounded PES is not allowed, so we must have a
2306 * valid length present */
2307 pes_packet_len = GST_READ_UINT16_BE (data + 4);
2308 if (pes_packet_len == 0)
2311 /* Check the following header, if we can */
2312 if (6 + pes_packet_len + 4 <= len) {
2313 if (!IS_MPEG_HEADER (data + 6 + pes_packet_len))
2318 *pack_size = 6 + pes_packet_len;
2323 mpeg_sys_is_valid_sys (GstTypeFind * tf, const guint8 * data, guint len,
2328 /* Check the System header at the given position, assuming the header code itself
2329 * was already checked */
2332 sys_hdr_len = GST_READ_UINT16_BE (data + 4);
2333 if (sys_hdr_len < 6)
2336 /* Check the following header, if we can */
2337 if (6 + sys_hdr_len + 4 <= len) {
2338 if (!IS_MPEG_HEADER (data + 6 + sys_hdr_len))
2343 *pack_size = 6 + sys_hdr_len;
2348 /* calculation of possibility to identify random data as mpeg systemstream:
2349 * bits that must match in header detection: 32 (or more)
2350 * chance that random data is identifed: 1/2^32
2351 * chance that MPEG2_MIN_PACK_HEADERS headers are identified:
2352 * 1/2^(32*MPEG2_MIN_PACK_HEADERS)
2353 * chance that this happens in MPEG2_MAX_PROBE_LENGTH bytes:
2354 * 1-(1+1/2^(32*MPEG2_MIN_PACK_HEADERS)^MPEG2_MAX_PROBE_LENGTH)
2355 * for current values:
2356 * 1-(1+1/2^(32*4)^101024)
2358 * Since we also check marker bits and pes packet lengths, this probability is a
2359 * very coarse upper bound.
2362 mpeg_sys_type_find (GstTypeFind * tf, gpointer unused)
2364 const guint8 *data, *data0, *first_sync, *end;
2365 gint mpegversion = 0;
2366 guint pack_headers = 0;
2367 guint pes_headers = 0;
2369 guint since_last_sync = 0;
2370 guint32 sync_word = 0xffffffff;
2371 guint potential_headers = 0;
2376 len = MPEG2_MAX_PROBE_LENGTH;
2379 data = gst_type_find_peek (tf, 0, 5 + len);
2395 while (data < end) {
2397 if (sync_word == 0x00000100) {
2398 /* Found potential sync word */
2399 if (first_sync == NULL)
2400 first_sync = data - 3;
2402 if (since_last_sync > 4) {
2403 /* If more than 4 bytes since the last sync word, reset our counters,
2404 * as we're only interested in counting contiguous packets */
2405 pes_headers = pack_headers = 0;
2409 potential_headers++;
2410 if (IS_MPEG_PACK_CODE (data[0])) {
2411 if ((data[1] & 0xC0) == 0x40) {
2414 } else if ((data[1] & 0xF0) == 0x20) {
2417 if (mpegversion != 0 &&
2418 mpeg_sys_is_valid_pack (tf, data - 3, end - data + 3, &pack_size)) {
2421 } else if (IS_MPEG_PES_CODE (data[0])) {
2423 if (mpeg_sys_is_valid_pes (tf, data - 3, end - data + 3, &pack_size)) {
2425 if (mpegversion == 0)
2428 } else if (IS_MPEG_SYS_CODE (data[0])) {
2429 if (mpeg_sys_is_valid_sys (tf, data - 3, end - data + 3, &pack_size)) {
2434 /* If we found a packet with a known size, skip the bytes in it and loop
2435 * around to check the next packet. */
2436 if (pack_size != 0) {
2437 data += pack_size - 3;
2438 sync_word = 0xffffffff;
2439 since_last_sync = 0;
2444 sync_word |= data[0];
2448 /* If we have found MAX headers, and *some* were pes headers (pack headers
2449 * are optional in an mpeg system stream) then return our high-probability
2451 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MAX_SYS_HEADERS)
2455 /* If we at least saw MIN headers, and *some* were pes headers (pack headers
2456 * are optional in an mpeg system stream) then return a lower-probability
2458 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MIN_SYS_HEADERS)
2466 prob = GST_TYPE_FIND_POSSIBLE + (10 * (pack_headers + pes_headers));
2467 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
2469 /* With the above test, we get into problems when we try to typefind
2470 a MPEG stream from a small amount of data, which can happen when
2471 we get data pushed from a HTTP source. We thus make a second test
2472 to give higher probability if all the potential headers were either
2473 pack or pes headers (ie, no potential header was unrecognized). */
2474 if (potential_headers == pack_headers + pes_headers) {
2475 GST_LOG ("Only %u headers, but all were recognized", potential_headers);
2477 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
2480 /* lower probability if the first packet wasn't right at the start */
2481 if (data0 != first_sync && prob >= 10)
2484 GST_LOG ("Suggesting MPEG %d system stream, %d packs, %d pes, prob %u%%",
2485 mpegversion, pack_headers, pes_headers, prob);
2487 gst_type_find_suggest_simple (tf, prob, "video/mpeg",
2488 "systemstream", G_TYPE_BOOLEAN, TRUE,
2489 "mpegversion", G_TYPE_INT, mpegversion, NULL);
2494 /*** video/mpegts Transport Stream ***/
2495 static GstStaticCaps mpegts_caps = GST_STATIC_CAPS ("video/mpegts, "
2496 "systemstream = (boolean) true, packetsize = (int) [ 188, 208 ]");
2497 #define MPEGTS_CAPS gst_static_caps_get(&mpegts_caps)
2499 #define GST_MPEGTS_TYPEFIND_MIN_HEADERS 4
2500 #define GST_MPEGTS_TYPEFIND_MAX_HEADERS 10
2501 #define GST_MPEGTS_MAX_PACKET_SIZE 208
2502 #define GST_MPEGTS_TYPEFIND_SYNC_SIZE \
2503 (GST_MPEGTS_TYPEFIND_MIN_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
2504 #define GST_MPEGTS_TYPEFIND_MAX_SYNC \
2505 (GST_MPEGTS_TYPEFIND_MAX_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
2506 #define GST_MPEGTS_TYPEFIND_SCAN_LENGTH \
2507 (GST_MPEGTS_TYPEFIND_MAX_SYNC * 4)
2509 #define MPEGTS_HDR_SIZE 4
2510 /* Check for sync byte, error_indicator == 0 and packet has payload.
2511 * Adaptation control field (data[3] & 0x30) may be zero for TS packets with
2512 * null PIDs. Still, these streams are valid TS streams (for null packets,
2513 * AFC is supposed to be 0x1, but the spec also says decoders should just
2514 * discard any packets with AFC = 0x00) */
2515 #define IS_MPEGTS_HEADER(data) (data[0] == 0x47 && \
2516 (data[1] & 0x80) == 0x00 && \
2517 ((data[3] & 0x30) != 0x00 || \
2518 ((data[3] & 0x30) == 0x00 && (data[1] & 0x1f) == 0x1f && (data[2] & 0xff) == 0xff)))
2520 /* Helper function to search ahead at intervals of packet_size for mpegts
2523 mpeg_ts_probe_headers (GstTypeFind * tf, guint64 offset, gint packet_size)
2525 /* We always enter this function having found at least one header already */
2527 const guint8 *data = NULL;
2529 GST_LOG ("looking for mpeg-ts packets of size %u", packet_size);
2530 while (found < GST_MPEGTS_TYPEFIND_MAX_HEADERS) {
2531 offset += packet_size;
2533 data = gst_type_find_peek (tf, offset, MPEGTS_HDR_SIZE);
2534 if (data == NULL || !IS_MPEGTS_HEADER (data))
2538 GST_LOG ("mpeg-ts sync #%2d at offset %" G_GUINT64_FORMAT, found, offset);
2544 /* Try and detect at least 4 packets in at most 10 packets worth of
2545 * data. Need to try several possible packet sizes */
2547 mpeg_ts_type_find (GstTypeFind * tf, gpointer unused)
2549 /* TS packet sizes to test: normal, DVHS packet size and
2550 * FEC with 16 or 20 byte codes packet size. */
2551 const gint pack_sizes[] = { 188, 192, 204, 208 };
2552 const guint8 *data = NULL;
2554 guint64 skipped = 0;
2556 while (skipped < GST_MPEGTS_TYPEFIND_SCAN_LENGTH) {
2557 if (size < MPEGTS_HDR_SIZE) {
2558 data = gst_type_find_peek (tf, skipped, GST_MPEGTS_TYPEFIND_SYNC_SIZE);
2561 size = GST_MPEGTS_TYPEFIND_SYNC_SIZE;
2564 /* Have at least MPEGTS_HDR_SIZE bytes at this point */
2565 if (IS_MPEGTS_HEADER (data)) {
2568 GST_LOG ("possible mpeg-ts sync at offset %" G_GUINT64_FORMAT, skipped);
2570 for (p = 0; p < G_N_ELEMENTS (pack_sizes); p++) {
2573 /* Probe ahead at size pack_sizes[p] */
2574 found = mpeg_ts_probe_headers (tf, skipped, pack_sizes[p]);
2575 if (found >= GST_MPEGTS_TYPEFIND_MIN_HEADERS) {
2578 /* found at least 4 headers. 10 headers = MAXIMUM probability.
2579 * Arbitrarily, I assigned 10% probability for each header we
2580 * found, 40% -> 100% */
2581 probability = MIN (10 * found, GST_TYPE_FIND_MAXIMUM);
2583 gst_type_find_suggest_simple (tf, probability, "video/mpegts",
2584 "systemstream", G_TYPE_BOOLEAN, TRUE,
2585 "packetsize", G_TYPE_INT, pack_sizes[p], NULL);
2596 #define GST_MPEGVID_TYPEFIND_TRY_PICTURES 6
2597 #define GST_MPEGVID_TYPEFIND_TRY_SYNC (100 * 1024) /* 100 kB */
2599 /* Scan ahead a maximum of max_extra_offset bytes until the next IS_MPEG_HEADER
2600 * offset. After the call, offset will be after the 0x000001, i.e. at the 4th
2601 * byte of the MPEG header. Returns TRUE if a header was found, FALSE if not.
2604 mpeg_find_next_header (GstTypeFind * tf, DataScanCtx * c,
2605 guint64 max_extra_offset)
2607 guint64 extra_offset;
2609 for (extra_offset = 0; extra_offset <= max_extra_offset; ++extra_offset) {
2610 if (!data_scan_ctx_ensure_data (tf, c, 4))
2612 if (IS_MPEG_HEADER (c->data)) {
2613 data_scan_ctx_advance (tf, c, 3);
2616 data_scan_ctx_advance (tf, c, 1);
2621 /*** video/mpeg MPEG-4 elementary video stream ***/
2623 static GstStaticCaps mpeg4_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2624 "systemstream=(boolean)false, mpegversion=4, parsed=(boolean)false");
2625 #define MPEG4_VIDEO_CAPS gst_static_caps_get(&mpeg4_video_caps)
2628 * This typefind is based on the elementary video header defined in
2629 * http://xhelmboyx.tripod.com/formats/mpeg-layout.txt
2630 * In addition, it allows the visual object sequence header to be
2631 * absent, and even the VOS header to be absent. In the latter case,
2632 * a number of VOPs have to be present.
2635 mpeg4_video_type_find (GstTypeFind * tf, gpointer unused)
2637 DataScanCtx c = { 0, NULL, 0 };
2638 gboolean seen_vios_at_0 = FALSE;
2639 gboolean seen_vios = FALSE;
2640 gboolean seen_vos = FALSE;
2641 gboolean seen_vol = FALSE;
2642 guint num_vop_headers = 0;
2645 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2646 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2649 if (!mpeg_find_next_header (tf, &c,
2650 GST_MPEGVID_TYPEFIND_TRY_SYNC - c.offset))
2655 /* visual_object_sequence_start_code */
2658 break; /* Terminate at second vios */
2660 seen_vios_at_0 = TRUE;
2662 data_scan_ctx_advance (tf, &c, 2);
2663 if (!mpeg_find_next_header (tf, &c, 0))
2668 /* Optional metadata */
2670 if (!mpeg_find_next_header (tf, &c, 24))
2674 /* visual_object_start_code (consider it optional) */
2676 data_scan_ctx_advance (tf, &c, 2);
2677 /* may contain ID marker and YUV clamping */
2678 if (!mpeg_find_next_header (tf, &c, 7))
2684 /* video_object_start_code */
2687 break; /* Terminate at second vos */
2689 data_scan_ctx_advance (tf, &c, 2);
2693 /* video_object_layer_start_code */
2694 if (sc >= 0x20 && sc <= 0x2F) {
2696 data_scan_ctx_advance (tf, &c, 5);
2700 /* video_object_plane_start_code */
2703 data_scan_ctx_advance (tf, &c, 2);
2707 /* Unknown start code. */
2710 if (num_vop_headers > 0 || seen_vol) {
2711 GstTypeFindProbability probability = 0;
2713 GST_LOG ("Found %d pictures, vios: %d, vos:%d, vol:%d", num_vop_headers,
2714 seen_vios, seen_vos, seen_vol);
2716 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios_at_0
2717 && seen_vos && seen_vol)
2718 probability = GST_TYPE_FIND_MAXIMUM - 1;
2719 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios
2720 && seen_vos && seen_vol)
2721 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2722 else if (seen_vios_at_0 && seen_vos && seen_vol)
2723 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2724 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vos
2726 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2727 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vol)
2728 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2729 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2730 probability = GST_TYPE_FIND_LIKELY - 1;
2731 else if (num_vop_headers > 2 && seen_vios && seen_vos && seen_vol)
2732 probability = GST_TYPE_FIND_LIKELY - 9;
2733 else if (seen_vios && seen_vos && seen_vol)
2734 probability = GST_TYPE_FIND_LIKELY - 20;
2735 else if (num_vop_headers > 0 && seen_vos && seen_vol)
2736 probability = GST_TYPE_FIND_POSSIBLE;
2737 else if (num_vop_headers > 0)
2738 probability = GST_TYPE_FIND_POSSIBLE - 10;
2739 else if (seen_vos && seen_vol)
2740 probability = GST_TYPE_FIND_POSSIBLE - 20;
2742 gst_type_find_suggest (tf, probability, MPEG4_VIDEO_CAPS);
2746 /*** video/x-h263 H263 video stream ***/
2747 static GstStaticCaps h263_video_caps =
2748 GST_STATIC_CAPS ("video/x-h263, variant=(string)itu");
2750 #define H263_VIDEO_CAPS gst_static_caps_get(&h263_video_caps)
2752 #define H263_MAX_PROBE_LENGTH (128 * 1024)
2755 h263_video_type_find (GstTypeFind * tf, gpointer unused)
2757 DataScanCtx c = { 0, NULL, 0 };
2758 guint64 data = 0xffff; /* prevents false positive for first 2 bytes */
2764 guint pc_type, pb_mode;
2766 while (c.offset < H263_MAX_PROBE_LENGTH) {
2767 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
2770 /* Find the picture start code */
2771 data = (data << 8) + c.data[0];
2772 psc = data & G_GUINT64_CONSTANT (0xfffffc0000);
2773 if (psc == 0x800000) {
2776 ptype = (data & 0x3fc) >> 2;
2778 format = ptype & 0x07;
2780 /* Now that we have a Valid PSC, check if we also have a valid PTYPE and
2781 the Source Format, which should range between 1 and 5 */
2782 if (((ptype >> 6) == 0x2) && (format > 0 && format < 6)) {
2783 pc_type = data & 0x02;
2784 pb_mode = c.data[1] & 0x20 >> 4;
2785 if (!pc_type && pb_mode)
2792 /* FIXME: maybe bail out early if we get mostly bad syncs ? */
2795 data_scan_ctx_advance (tf, &c, 1);
2798 GST_LOG ("good: %d, bad: %d", good, bad);
2801 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H263_VIDEO_CAPS);
2806 /*** video/x-h264 H264 elementary video stream ***/
2808 static GstStaticCaps h264_video_caps =
2809 GST_STATIC_CAPS ("video/x-h264,stream-format=byte-stream");
2811 #define H264_VIDEO_CAPS gst_static_caps_get(&h264_video_caps)
2813 #define H264_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
2816 h264_video_type_find (GstTypeFind * tf, gpointer unused)
2818 DataScanCtx c = { 0, NULL, 0 };
2820 /* Stream consists of: a series of sync codes (00 00 00 01) followed
2823 gboolean seen_idr = FALSE;
2824 gboolean seen_sps = FALSE;
2825 gboolean seen_pps = FALSE;
2826 gboolean seen_ssps = FALSE;
2831 while (c.offset < H264_MAX_PROBE_LENGTH) {
2832 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
2835 if (IS_MPEG_HEADER (c.data)) {
2836 nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
2837 ref = c.data[3] & 0x60; /* nal_ref_idc */
2839 /* if forbidden bit is different to 0 won't be h264 */
2845 /* collect statistics about the NAL types */
2846 if ((nut >= 1 && nut <= 13) || nut == 19) {
2847 if ((nut == 5 && ref == 0) ||
2848 ((nut == 6 || (nut >= 9 && nut <= 12)) && ref != 0)) {
2860 } else if (nut >= 14 && nut <= 33) {
2864 } else if (nut == 14 || nut == 20) {
2865 /* Sometimes we see NAL 14 or 20 without SSPS
2866 * if dropped into the middle of a stream -
2867 * just ignore those (don't add to bad count) */
2872 /* Theoretically these are good, since if they exist in the
2873 stream it merely means that a newer backwards-compatible
2874 h.264 stream. But we should be identifying that separately. */
2878 /* unspecified, application specific */
2879 /* don't consider these bad */
2882 GST_LOG ("good:%d, bad:%d, pps:%d, sps:%d, idr:%d ssps:%d", good, bad,
2883 seen_pps, seen_sps, seen_idr, seen_ssps);
2885 if (seen_sps && seen_pps && seen_idr && good >= 10 && bad < 4) {
2886 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H264_VIDEO_CAPS);
2890 data_scan_ctx_advance (tf, &c, 4);
2892 data_scan_ctx_advance (tf, &c, 1);
2895 GST_LOG ("good:%d, bad:%d, pps:%d, sps:%d, idr:%d ssps=%d", good, bad,
2896 seen_pps, seen_sps, seen_idr, seen_ssps);
2898 if (good >= 2 && bad == 0) {
2899 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H264_VIDEO_CAPS);
2903 /*** video/x-h265 H265 elementary video stream ***/
2905 static GstStaticCaps h265_video_caps =
2906 GST_STATIC_CAPS ("video/x-h265,stream-format=byte-stream");
2908 #define H265_VIDEO_CAPS gst_static_caps_get(&h265_video_caps)
2910 #define H265_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
2913 h265_video_type_find (GstTypeFind * tf, gpointer unused)
2915 DataScanCtx c = { 0, NULL, 0 };
2917 /* Stream consists of: a series of sync codes (00 00 00 01) followed
2920 gboolean seen_irap = FALSE;
2921 gboolean seen_vps = FALSE;
2922 gboolean seen_sps = FALSE;
2923 gboolean seen_pps = FALSE;
2928 while (c.offset < H265_MAX_PROBE_LENGTH) {
2929 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 5)))
2932 if (IS_MPEG_HEADER (c.data)) {
2933 /* forbiden_zero_bit | nal_unit_type */
2934 nut = c.data[3] & 0xfe;
2936 /* if forbidden bit is different to 0 won't be h265 */
2943 /* if nuh_layer_id is not zero or nuh_temporal_id_plus1 is zero then
2944 * it won't be h265 */
2945 if ((c.data[3] & 0x01) || (c.data[4] & 0xf8) || !(c.data[4] & 0x07)) {
2950 /* collect statistics about the NAL types */
2951 if ((nut >= 0 && nut <= 9) || (nut >= 16 && nut <= 21) || (nut >= 32
2959 else if (nut >= 16 && nut <= 21) {
2960 /* BLA, IDR and CRA pictures are belongs to be IRAP picture */
2961 /* we are not counting the reserved IRAP pictures (22 and 23) to good */
2966 } else if ((nut >= 10 && nut <= 15) || (nut >= 22 && nut <= 31)
2967 || (nut >= 41 && nut <= 47)) {
2968 /* reserved values are counting as bad */
2971 /* unspecified (48..63), application specific */
2972 /* don't consider these as bad */
2975 GST_LOG ("good:%d, bad:%d, pps:%d, sps:%d, vps:%d, irap:%d", good, bad,
2976 seen_pps, seen_sps, seen_vps, seen_irap);
2978 if (seen_sps && seen_pps && seen_irap && good >= 10 && bad < 4) {
2979 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H265_VIDEO_CAPS);
2983 data_scan_ctx_advance (tf, &c, 5);
2985 data_scan_ctx_advance (tf, &c, 1);
2988 GST_LOG ("good:%d, bad:%d, pps:%d, sps:%d, vps:%d, irap:%d", good, bad,
2989 seen_pps, seen_sps, seen_vps, seen_irap);
2991 if (good >= 2 && bad == 0) {
2992 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H265_VIDEO_CAPS);
2996 /*** video/mpeg video stream ***/
2998 static GstStaticCaps mpeg_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2999 "systemstream = (boolean) false");
3000 #define MPEG_VIDEO_CAPS gst_static_caps_get(&mpeg_video_caps)
3003 * Idea is the same as MPEG system stream typefinding: We check each
3004 * byte of the stream to see if - from that point on - the stream
3005 * matches a predefined set of marker bits as defined in the MPEG
3008 * I'm sure someone will do a chance calculation here too.
3012 mpeg_video_stream_type_find (GstTypeFind * tf, gpointer unused)
3014 DataScanCtx c = { 0, NULL, 0 };
3015 gboolean seen_seq_at_0 = FALSE;
3016 gboolean seen_seq = FALSE;
3017 gboolean seen_gop = FALSE;
3018 guint64 last_pic_offset = 0;
3019 gint num_pic_headers = 0;
3022 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
3023 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
3026 if (!data_scan_ctx_ensure_data (tf, &c, 5))
3029 if (!IS_MPEG_HEADER (c.data))
3032 /* a pack header indicates that this isn't an elementary stream */
3033 if (c.data[3] == 0xBA && mpeg_sys_is_valid_pack (tf, c.data, c.size, NULL))
3036 /* do we have a sequence header? */
3037 if (c.data[3] == 0xB3) {
3038 seen_seq_at_0 = seen_seq_at_0 || (c.offset == 0);
3040 data_scan_ctx_advance (tf, &c, 4 + 8);
3044 /* or a GOP header */
3045 if (c.data[3] == 0xB8) {
3047 data_scan_ctx_advance (tf, &c, 8);
3051 /* but what we'd really like to see is a picture header */
3052 if (c.data[3] == 0x00) {
3054 last_pic_offset = c.offset;
3055 data_scan_ctx_advance (tf, &c, 8);
3059 /* ... each followed by a slice header with slice_vertical_pos=1 that's
3060 * not too far away from the previously seen picture header. */
3061 if (c.data[3] == 0x01 && num_pic_headers > found &&
3062 (c.offset - last_pic_offset) >= 4 &&
3063 (c.offset - last_pic_offset) <= 64) {
3064 data_scan_ctx_advance (tf, &c, 4);
3071 data_scan_ctx_advance (tf, &c, 1);
3074 if (found > 0 || seen_seq) {
3075 GstTypeFindProbability probability = 0;
3077 GST_LOG ("Found %d pictures, seq:%d, gop:%d", found, seen_seq, seen_gop);
3079 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq && seen_gop)
3080 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
3081 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq)
3082 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
3083 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
3084 probability = GST_TYPE_FIND_LIKELY;
3085 else if (seen_seq_at_0 && seen_gop && found > 2)
3086 probability = GST_TYPE_FIND_LIKELY - 10;
3087 else if (seen_seq && seen_gop && found > 2)
3088 probability = GST_TYPE_FIND_LIKELY - 20;
3089 else if (seen_seq_at_0 && found > 0)
3090 probability = GST_TYPE_FIND_POSSIBLE;
3091 else if (seen_seq && found > 0)
3092 probability = GST_TYPE_FIND_POSSIBLE - 5;
3094 probability = GST_TYPE_FIND_POSSIBLE - 10;
3096 probability = GST_TYPE_FIND_POSSIBLE - 20;
3098 gst_type_find_suggest_simple (tf, probability, "video/mpeg",
3099 "systemstream", G_TYPE_BOOLEAN, FALSE,
3100 "mpegversion", G_TYPE_INT, 1, "parsed", G_TYPE_BOOLEAN, FALSE, NULL);
3104 /*** audio/x-aiff ***/
3106 static GstStaticCaps aiff_caps = GST_STATIC_CAPS ("audio/x-aiff");
3108 #define AIFF_CAPS gst_static_caps_get(&aiff_caps)
3110 aiff_type_find (GstTypeFind * tf, gpointer unused)
3112 const guint8 *data = gst_type_find_peek (tf, 0, 16);
3114 if (data && memcmp (data, "FORM", 4) == 0) {
3116 if (memcmp (data, "AIFF", 4) == 0 || memcmp (data, "AIFC", 4) == 0)
3117 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AIFF_CAPS);
3121 /*** audio/x-svx ***/
3122 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
3123 static GstStaticCaps svx_caps = GST_STATIC_CAPS ("audio/x-svx");
3125 #define SVX_CAPS gst_static_caps_get(&svx_caps)
3127 svx_type_find (GstTypeFind * tf, gpointer unused)
3129 const guint8 *data = gst_type_find_peek (tf, 0, 16);
3131 if (data && memcmp (data, "FORM", 4) == 0) {
3133 if (memcmp (data, "8SVX", 4) == 0 || memcmp (data, "16SV", 4) == 0)
3134 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVX_CAPS);
3138 /*** audio/x-shorten ***/
3140 static GstStaticCaps shn_caps = GST_STATIC_CAPS ("audio/x-shorten");
3142 #define SHN_CAPS gst_static_caps_get(&shn_caps)
3144 shn_type_find (GstTypeFind * tf, gpointer unused)
3146 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3148 if (data && memcmp (data, "ajkg", 4) == 0) {
3149 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
3151 data = gst_type_find_peek (tf, -8, 8);
3152 if (data && memcmp (data, "SHNAMPSK", 8) == 0) {
3153 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
3157 /*** application/x-ape ***/
3159 static GstStaticCaps ape_caps = GST_STATIC_CAPS ("application/x-ape");
3161 #define APE_CAPS gst_static_caps_get(&ape_caps)
3163 ape_type_find (GstTypeFind * tf, gpointer unused)
3165 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3167 if (data && memcmp (data, "MAC ", 4) == 0) {
3168 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 10, APE_CAPS);
3172 /*** ISO FORMATS ***/
3174 /*** audio/x-m4a ***/
3176 static GstStaticCaps m4a_caps = GST_STATIC_CAPS ("audio/x-m4a");
3178 #define M4A_CAPS (gst_static_caps_get(&m4a_caps))
3180 m4a_type_find (GstTypeFind * tf, gpointer unused)
3182 const guint8 *data = gst_type_find_peek (tf, 4, 8);
3184 if (data && (memcmp (data, "ftypM4A ", 8) == 0)) {
3185 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
3189 /*** application/x-3gp ***/
3191 /* The Q is there because variables can't start with a number. */
3192 static GstStaticCaps q3gp_caps = GST_STATIC_CAPS ("application/x-3gp");
3193 #define Q3GP_CAPS (gst_static_caps_get(&q3gp_caps))
3195 static const gchar *
3196 q3gp_type_find_get_profile (const guint8 * data)
3198 switch (GST_MAKE_FOURCC (data[0], data[1], data[2], 0)) {
3199 case GST_MAKE_FOURCC ('3', 'g', 'g', 0):
3201 case GST_MAKE_FOURCC ('3', 'g', 'p', 0):
3203 case GST_MAKE_FOURCC ('3', 'g', 's', 0):
3204 return "streaming-server";
3205 case GST_MAKE_FOURCC ('3', 'g', 'r', 0):
3206 return "progressive-download";
3214 q3gp_type_find (GstTypeFind * tf, gpointer unused)
3216 const gchar *profile;
3217 guint32 ftyp_size = 0;
3219 const guint8 *data = NULL;
3221 if ((data = gst_type_find_peek (tf, 0, 12)) == NULL) {
3226 if (memcmp (data, "ftyp", 4) != 0) {
3230 /* check major brand */
3232 if ((profile = q3gp_type_find_get_profile (data))) {
3233 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3234 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
3238 /* check compatible brands */
3239 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
3240 ftyp_size = GST_READ_UINT32_BE (data);
3242 if ((data = gst_type_find_peek (tf, 0, ftyp_size)) != NULL) {
3243 for (offset = 16; offset + 4 < ftyp_size; offset += 4) {
3244 if ((profile = q3gp_type_find_get_profile (data + offset))) {
3245 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3246 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
3256 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
3257 /*** video/mj2 and image/jp2 ***/
3258 static GstStaticCaps mj2_caps = GST_STATIC_CAPS ("video/mj2");
3260 #define MJ2_CAPS gst_static_caps_get(&mj2_caps)
3262 static GstStaticCaps jp2_caps = GST_STATIC_CAPS ("image/jp2");
3264 #define JP2_CAPS gst_static_caps_get(&jp2_caps)
3267 jp2_type_find (GstTypeFind * tf, gpointer unused)
3271 data = gst_type_find_peek (tf, 0, 24);
3276 if (memcmp (data, "\000\000\000\014jP \015\012\207\012", 12) != 0)
3279 /* check ftyp box */
3281 if (memcmp (data + 4, "ftyp", 4) == 0) {
3282 if (memcmp (data + 8, "jp2 ", 4) == 0)
3283 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JP2_CAPS);
3284 else if (memcmp (data + 8, "mjp2", 4) == 0)
3285 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MJ2_CAPS);
3290 static GstStaticCaps jpc_caps = GST_STATIC_CAPS ("image/x-jpc");
3292 #define JPC_CAPS gst_static_caps_get(&jpc_caps)
3295 jpc_type_find (GstTypeFind * tf, gpointer unused)
3297 gboolean found_cod = FALSE;
3298 gboolean found_qcd = FALSE;
3299 gboolean found_sot = FALSE;
3302 const guint8 soc_siz[] = { 0xff, 0x4f, 0xff, 0x51 };
3304 #define GST_TYPE_FIND_JPC_MARKER_SOT 0xFF90
3305 #define GST_TYPE_FIND_JPC_MARKER_COD 0xFF52
3306 #define GST_TYPE_FIND_JPC_MARKER_QCD 0xFF5C
3307 #define GST_TYPE_FIND_JPC_MARKER_COC 0xFF53
3308 #define GST_TYPE_FIND_JPC_MARKER_RGN 0xFF5E
3309 #define GST_TYPE_FIND_JPC_MARKER_QCC 0xFF5D
3310 #define GST_TYPE_FIND_JPC_MARKER_POC 0xFF5F
3311 #define GST_TYPE_FIND_JPC_MARKER_PLM 0xFF57
3312 #define GST_TYPE_FIND_JPC_MARKER_PPM 0xFF60
3313 #define GST_TYPE_FIND_JPC_MARKER_TLM 0xFF55
3314 #define GST_TYPE_FIND_JPC_MARKER_CRG 0xFF63
3315 #define GST_TYPE_FIND_JPC_MARKER_COM 0xFF64
3316 #define GST_TYPE_FIND_JPC_MARKER_CBD 0xFF78
3317 #define GST_TYPE_FIND_JPC_MARKER_MCC 0xFF75
3318 #define GST_TYPE_FIND_JPC_MARKER_MCT 0xFF74
3319 #define GST_TYPE_FIND_JPC_MARKER_MCO 0xFF77
3322 /* SOC marker + SIZ marker */
3323 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
3324 if (memcmp (data, soc_siz, 4) != 0)
3331 while (!found_sot) {
3333 /* skip actual marker data */
3334 if ((data = gst_type_find_peek (tf, offset, 2)) != NULL) {
3335 offset += GST_READ_UINT16_BE (data);
3341 if ((data = gst_type_find_peek (tf, offset, 2)) != NULL) {
3342 guint16 marker = GST_READ_UINT16_BE (data);
3344 case GST_TYPE_FIND_JPC_MARKER_SOT:
3347 case GST_TYPE_FIND_JPC_MARKER_COD:
3350 case GST_TYPE_FIND_JPC_MARKER_QCD:
3353 /* optional header markers */
3354 case GST_TYPE_FIND_JPC_MARKER_COC:
3355 case GST_TYPE_FIND_JPC_MARKER_RGN:
3356 case GST_TYPE_FIND_JPC_MARKER_QCC:
3357 case GST_TYPE_FIND_JPC_MARKER_POC:
3358 case GST_TYPE_FIND_JPC_MARKER_PLM:
3359 case GST_TYPE_FIND_JPC_MARKER_PPM:
3360 case GST_TYPE_FIND_JPC_MARKER_TLM:
3361 case GST_TYPE_FIND_JPC_MARKER_CRG:
3362 case GST_TYPE_FIND_JPC_MARKER_COM:
3363 case GST_TYPE_FIND_JPC_MARKER_CBD:
3364 case GST_TYPE_FIND_JPC_MARKER_MCC:
3365 case GST_TYPE_FIND_JPC_MARKER_MCT:
3366 case GST_TYPE_FIND_JPC_MARKER_MCO:
3368 /* unrecognized marker */
3378 if (found_cod && found_qcd && found_sot)
3379 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JPC_CAPS);
3383 /*** video/quicktime ***/
3385 static GstStaticCaps qt_caps = GST_STATIC_CAPS ("video/quicktime");
3387 #define QT_CAPS gst_static_caps_get(&qt_caps)
3388 #define STRNCMP(x,y,z) (strncmp ((char*)(x), (char*)(y), z))
3390 /* FIXME 0.11: go through http://www.ftyps.com/ */
3392 qt_type_find (GstTypeFind * tf, gpointer unused)
3396 guint atoms_in_a_row = 0;
3397 gboolean have_moov = FALSE, have_mdat = FALSE;
3400 const gchar *variant = NULL;
3402 while ((data = gst_type_find_peek (tf, offset, 12)) != NULL) {
3405 if (STRNCMP (&data[4], "ftypqt ", 8) == 0) {
3406 tip = GST_TYPE_FIND_MAXIMUM;
3410 if (STRNCMP (&data[4], "ftypisom", 8) == 0 ||
3411 STRNCMP (&data[4], "ftypavc1", 8) == 0 ||
3412 #ifdef TIZEN_FEATURE_TYPEFIND_ENHANCEMENT
3413 STRNCMP (&data[4], "ftypwmf ", 8) == 0 ||
3415 STRNCMP (&data[4], "ftypmp42", 8) == 0) {
3416 tip = GST_TYPE_FIND_MAXIMUM;
3421 if (STRNCMP (&data[4], "ftypisml", 8) == 0 ||
3422 STRNCMP (&data[4], "ftypavc3", 8) == 0) {
3423 tip = GST_TYPE_FIND_MAXIMUM;
3424 variant = "iso-fragmented";
3428 if (STRNCMP (&data[4], "ftypccff", 8) == 0) {
3429 tip = GST_TYPE_FIND_MAXIMUM;
3434 if (STRNCMP (&data[4], "ftypmif1", 8) == 0) {
3435 tip = GST_TYPE_FIND_MAXIMUM;
3440 /* box/atom types that are in common with ISO base media file format */
3441 if (STRNCMP (&data[4], "moov", 4) == 0 ||
3442 STRNCMP (&data[4], "mdat", 4) == 0 ||
3443 STRNCMP (&data[4], "ftyp", 4) == 0 ||
3444 STRNCMP (&data[4], "free", 4) == 0 ||
3445 STRNCMP (&data[4], "uuid", 4) == 0 ||
3446 STRNCMP (&data[4], "moof", 4) == 0 ||
3447 STRNCMP (&data[4], "skip", 4) == 0) {
3449 tip = GST_TYPE_FIND_LIKELY;
3451 tip = GST_TYPE_FIND_NEARLY_CERTAIN;
3454 if (STRNCMP (&data[4], "moov", 4) == 0)
3456 if (STRNCMP (&data[4], "mdat", 4) == 0)
3459 atoms_in_a_row += 1;
3460 if ((have_moov && have_mdat) || atoms_in_a_row >= 5) {
3461 tip = GST_TYPE_FIND_MAXIMUM;
3465 /* other box/atom types, apparently quicktime specific */
3466 else if (STRNCMP (&data[4], "pnot", 4) == 0 ||
3467 STRNCMP (&data[4], "PICT", 4) == 0 ||
3468 STRNCMP (&data[4], "wide", 4) == 0 ||
3469 STRNCMP (&data[4], "prfl", 4) == 0) {
3470 tip = GST_TYPE_FIND_MAXIMUM;
3473 if (atoms_in_a_row >= 3)
3474 tip = GST_TYPE_FIND_LIKELY;
3480 size = GST_READ_UINT32_BE (data);
3481 if (size + offset >= G_MAXINT64)
3483 /* check compatible brands rather than ever expanding major brands above */
3484 if ((STRNCMP (&data[4], "ftyp", 4) == 0) && (size >= 16)) {
3485 data = gst_type_find_peek (tf, offset, size);
3489 while (new_offset + 4 <= size) {
3490 if (STRNCMP (&data[new_offset], "isom", 4) == 0 ||
3491 STRNCMP (&data[new_offset], "dash", 4) == 0 ||
3492 STRNCMP (&data[new_offset], "avc1", 4) == 0 ||
3493 STRNCMP (&data[new_offset], "avc3", 4) == 0 ||
3494 STRNCMP (&data[new_offset], "mp41", 4) == 0 ||
3495 STRNCMP (&data[new_offset], "mp42", 4) == 0) {
3496 tip = GST_TYPE_FIND_MAXIMUM;
3499 } else if (STRNCMP (&data[new_offset], "mif1", 4) == 0) {
3500 tip = GST_TYPE_FIND_MAXIMUM;
3508 const guint8 *sizedata;
3510 sizedata = gst_type_find_peek (tf, offset + 8, 8);
3511 if (sizedata == NULL)
3514 size = GST_READ_UINT64_BE (sizedata);
3519 new_offset = offset + size;
3520 if (new_offset <= offset)
3522 if (new_offset + 16 >= G_MAXINT64)
3524 offset = new_offset;
3530 GstCaps *caps = gst_caps_copy (QT_CAPS);
3532 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, variant, NULL);
3533 gst_type_find_suggest (tf, tip, caps);
3534 gst_caps_unref (caps);
3536 gst_type_find_suggest (tf, tip, QT_CAPS);
3542 /*** image/x-quicktime ***/
3543 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
3544 static GstStaticCaps qtif_caps = GST_STATIC_CAPS ("image/x-quicktime");
3546 #define QTIF_CAPS gst_static_caps_get(&qtif_caps)
3548 /* how many atoms we check before we give up */
3549 #define QTIF_MAXROUNDS 25
3552 qtif_type_find (GstTypeFind * tf, gpointer unused)
3555 gboolean found_idsc = FALSE;
3556 gboolean found_idat = FALSE;
3560 while ((data = gst_type_find_peek (tf, offset, 8)) != NULL) {
3563 size = GST_READ_UINT32_BE (data);
3565 const guint8 *sizedata;
3567 sizedata = gst_type_find_peek (tf, offset + 8, 8);
3568 if (sizedata == NULL)
3571 size = GST_READ_UINT64_BE (sizedata);
3576 if (STRNCMP (data + 4, "idsc", 4) == 0)
3578 if (STRNCMP (data + 4, "idat", 4) == 0)
3581 if (found_idsc && found_idat) {
3582 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, QTIF_CAPS);
3587 if (offset + 8 >= G_MAXINT64)
3589 if (++rounds > QTIF_MAXROUNDS)
3593 if (found_idsc || found_idat) {
3594 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, QTIF_CAPS);
3599 /*** audio/x-mod ***/
3601 static GstStaticCaps mod_caps = GST_STATIC_CAPS ("audio/x-mod");
3603 #define MOD_CAPS gst_static_caps_get(&mod_caps)
3604 /* FIXME: M15 CheckType to do */
3606 mod_type_find (GstTypeFind * tf, gpointer unused)
3609 GstTypeFindProbability probability;
3610 const char *mod_type = NULL;
3613 if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) {
3614 /* Protracker and variants */
3615 if ((memcmp (data, "M.K.", 4) == 0) ||
3616 (memcmp (data, "M!K!", 4) == 0) ||
3617 (memcmp (data, "M&K!", 4) == 0) || (memcmp (data, "N.T.", 4) == 0) ||
3619 (memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) ||
3620 (memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) ||
3621 /* Oktalyzer (Amiga) */
3622 (memcmp (data, "OKTA", 4) == 0) || (memcmp (data, "OCTA", 4) == 0) ||
3623 /* Oktalyser (Atari) */
3624 (memcmp (data, "CD81", 4) == 0) ||
3626 (memcmp (data, "TDZ", 3) == 0 && isdigit (data[3])) ||
3628 (memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) ||
3629 /* Fasttracker or Taketracker */
3630 (memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0])
3631 && isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0
3632 && isdigit (data[0]) && isdigit (data[1]))) {
3634 probability = GST_TYPE_FIND_MAXIMUM;
3635 goto suggest_audio_mod_caps;
3638 /* J2B (Jazz Jackrabbit 2) */
3639 if ((data = gst_type_find_peek (tf, 0, 8)) != NULL) {
3640 if ((memcmp (data, "MUSE\xDE\xAD", 4) == 0) &&
3641 ((memcmp (data + 6, "\xBE\xEF", 2) == 0) ||
3642 (memcmp (data + 6, "\xBA\xBE", 2) == 0))) {
3644 probability = GST_TYPE_FIND_MAXIMUM;
3645 goto suggest_audio_mod_caps;
3648 /* AMS (Velvet Studio) */
3649 if ((data = gst_type_find_peek (tf, 0, 7)) != NULL) {
3650 if (memcmp (data, "AMShdr\x1A", 7) == 0) {
3651 mod_type = "velvet-ams";
3652 probability = GST_TYPE_FIND_MAXIMUM;
3653 goto suggest_audio_mod_caps;
3656 /* AMS (Extreme Tracker) */
3657 if ((data = gst_type_find_peek (tf, 0, 9)) != NULL) {
3658 if ((memcmp (data, "Extreme", 7) == 0) && (data[8] == 1)) {
3659 mod_type = "extreme-ams";
3660 probability = GST_TYPE_FIND_LIKELY;
3661 goto suggest_audio_mod_caps;
3664 /* ULT (Ultratracker) */
3665 if ((data = gst_type_find_peek (tf, 0, 14)) != NULL) {
3666 if (memcmp (data, "MAS_UTrack_V00", 14) == 0) {
3668 probability = GST_TYPE_FIND_MAXIMUM;
3669 goto suggest_audio_mod_caps;
3672 /* DIGI (DigiBooster) */
3673 if ((data = gst_type_find_peek (tf, 0, 20)) != NULL) {
3674 if (memcmp (data, "DIGI Booster module\0", 20) == 0) {
3676 probability = GST_TYPE_FIND_MAXIMUM;
3677 goto suggest_audio_mod_caps;
3680 /* PTM (PolyTracker) */
3681 if ((data = gst_type_find_peek (tf, 0x2C, 4)) != NULL) {
3682 if (memcmp (data, "PTMF", 4) == 0) {
3684 probability = GST_TYPE_FIND_LIKELY;
3685 goto suggest_audio_mod_caps;
3689 if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) {
3690 if ((memcmp (data, "Extended Module: ", 17) == 0) && (data[37] == 0x1A)) {
3692 probability = GST_TYPE_FIND_MAXIMUM;
3693 goto suggest_audio_mod_caps;
3697 if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) {
3698 if (memcmp (data, "OKTASONG", 8) == 0) {
3700 probability = GST_TYPE_FIND_MAXIMUM;
3701 goto suggest_audio_mod_caps;
3704 /* Various formats with a 4-byte magic ID at the beginning of the file */
3705 if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) {
3706 /* PSM (Protracker Studio PSM) */
3707 if (memcmp (data, "PSM", 3) == 0) {
3708 unsigned char fbyte = data[3];
3709 if ((fbyte == ' ') || (fbyte == 254)) {
3711 probability = GST_TYPE_FIND_MAXIMUM;
3712 goto suggest_audio_mod_caps;
3716 if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) {
3718 probability = GST_TYPE_FIND_LIKELY;
3719 goto suggest_audio_mod_caps;
3722 if ((memcmp (data, "AMF", 3) == 0) && (data[3] > 10) && (data[3] < 14)) {
3723 mod_type = "dsmi-amf";
3724 probability = GST_TYPE_FIND_MAXIMUM;
3725 goto suggest_audio_mod_caps;
3728 if (memcmp (data, "IMPM", 4) == 0) {
3730 probability = GST_TYPE_FIND_MAXIMUM;
3731 goto suggest_audio_mod_caps;
3733 /* DBM (DigiBooster Pro) */
3734 if (memcmp (data, "DBM0", 4) == 0) {
3736 probability = GST_TYPE_FIND_MAXIMUM;
3737 goto suggest_audio_mod_caps;
3739 /* MDL (DigiTrakker) */
3740 if (memcmp (data, "DMDL", 4) == 0) {
3742 probability = GST_TYPE_FIND_MAXIMUM;
3743 goto suggest_audio_mod_caps;
3745 /* MT2 (MadTracker 2.0) */
3746 if (memcmp (data, "MT20", 4) == 0) {
3748 probability = GST_TYPE_FIND_MAXIMUM;
3749 goto suggest_audio_mod_caps;
3751 /* DMF (X-Tracker) */
3752 if (memcmp (data, "DDMF", 4) == 0) {
3754 probability = GST_TYPE_FIND_MAXIMUM;
3755 goto suggest_audio_mod_caps;
3758 if ((memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0)) {
3760 probability = GST_TYPE_FIND_MAXIMUM;
3761 goto suggest_audio_mod_caps;
3764 if (memcmp (data, "MTM", 3) == 0) {
3766 probability = GST_TYPE_FIND_MAXIMUM;
3767 goto suggest_audio_mod_caps;
3770 if (memcmp (data, "RIFF", 4) == 0) {
3771 const guint8 *data2 = gst_type_find_peek (tf, 8, 4);
3774 if (memcmp (data2, "DSMF", 4) == 0) {
3776 probability = GST_TYPE_FIND_MAXIMUM;
3777 goto suggest_audio_mod_caps;
3781 /* FAR (Farandole) */
3782 if (memcmp (data, "FAR\xFE", 4) == 0) {
3784 probability = GST_TYPE_FIND_MAXIMUM;
3785 goto suggest_audio_mod_caps;
3788 if (memcmp (data, "FAM\xFE", 4) == 0) {
3789 const guint8 *data2 = gst_type_find_peek (tf, 44, 3);
3792 if (memcmp (data2, "compare", 3) == 0) {
3794 probability = GST_TYPE_FIND_MAXIMUM;
3795 goto suggest_audio_mod_caps;
3797 /* otherwise do not suggest anything */
3800 probability = GST_TYPE_FIND_LIKELY;
3801 goto suggest_audio_mod_caps;
3805 if (memcmp (data, "GDM\xFE", 4) == 0) {
3806 const guint8 *data2 = gst_type_find_peek (tf, 71, 4);
3809 if (memcmp (data2, "GMFS", 4) == 0) {
3811 probability = GST_TYPE_FIND_MAXIMUM;
3812 goto suggest_audio_mod_caps;
3814 /* otherwise do not suggest anything */
3817 probability = GST_TYPE_FIND_LIKELY;
3818 goto suggest_audio_mod_caps;
3822 if (memcmp (data, "\xC1\x83\x2A\x9E", 4) == 0) {
3824 probability = GST_TYPE_FIND_POSSIBLE;
3825 goto suggest_audio_mod_caps;
3828 /* FAR (Farandole) (secondary detection) */
3829 if ((data = gst_type_find_peek (tf, 44, 3)) != NULL) {
3830 if (memcmp (data, "\x0D\x0A\x1A", 3) == 0) {
3832 probability = GST_TYPE_FIND_POSSIBLE;
3833 goto suggest_audio_mod_caps;
3837 if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) {
3838 if (memcmp (data, "IM10", 4) == 0) {
3840 probability = GST_TYPE_FIND_MAXIMUM;
3841 goto suggest_audio_mod_caps;
3845 if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) {
3846 if (memcmp (data, "SCRM", 4) == 0) {
3848 probability = GST_TYPE_FIND_MAXIMUM;
3849 goto suggest_audio_mod_caps;
3853 if ((data = gst_type_find_peek (tf, 20, 8)) != NULL) {
3854 if (g_ascii_strncasecmp ((gchar *) data, "!Scream!", 8) == 0 ||
3855 g_ascii_strncasecmp ((gchar *) data, "BMOD2STM", 8) == 0) {
3856 const guint8 *id, *stmtype;
3858 if ((id = gst_type_find_peek (tf, 28, 1)) == NULL)
3860 if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL)
3862 if (*id == 0x1A && *stmtype == 2) {
3864 probability = GST_TYPE_FIND_MAXIMUM;
3865 goto suggest_audio_mod_caps;
3870 if ((data = gst_type_find_peek (tf, 0, 19)) != NULL) {
3871 if (memcmp (data, "ASYLUM Music Format", 19) == 0) {
3872 mod_type = "asylum-amf";
3873 probability = GST_TYPE_FIND_MAXIMUM;
3874 goto suggest_audio_mod_caps;
3878 suggest_audio_mod_caps:
3879 if (mod_type != NULL) {
3880 GstCaps *caps = gst_caps_new_simple ("audio/x-mod",
3881 "type", G_TYPE_STRING, mod_type, NULL);
3883 gst_type_find_suggest (tf, probability, caps);
3884 gst_caps_unref (caps);
3888 /*** application/x-shockwave-flash ***/
3890 static GstStaticCaps swf_caps =
3891 GST_STATIC_CAPS ("application/x-shockwave-flash");
3892 #define SWF_CAPS (gst_static_caps_get(&swf_caps))
3894 swf_type_find (GstTypeFind * tf, gpointer unused)
3896 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3898 if (data && (data[0] == 'F' || data[0] == 'C') &&
3899 data[1] == 'W' && data[2] == 'S') {
3900 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SWF_CAPS);
3904 /*** application/vnd.ms-sstr+xml ***/
3907 mss_manifest_load_utf16 (gunichar2 * utf16_ne, const guint8 * utf16_data,
3908 gsize data_size, guint data_endianness)
3910 memcpy (utf16_ne, utf16_data, data_size);
3911 if (data_endianness != G_BYTE_ORDER) {
3914 for (i = 0; i < data_size / 2; ++i)
3915 utf16_ne[i] = GUINT16_SWAP_LE_BE (utf16_ne[i]);
3919 static GstStaticCaps mss_manifest_caps =
3920 GST_STATIC_CAPS ("application/vnd.ms-sstr+xml");
3921 #define MSS_MANIFEST_CAPS (gst_static_caps_get(&mss_manifest_caps))
3923 mss_manifest_type_find (GstTypeFind * tf, gpointer unused)
3925 gunichar2 utf16_ne[512];
3927 guint data_endianness = 0;
3928 glong n_read = 0, size = 0;
3931 gboolean utf8_bom_detected = FALSE;
3933 if (xml_check_first_element (tf, "SmoothStreamingMedia", 20, TRUE)) {
3934 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MSS_MANIFEST_CAPS);
3938 length = gst_type_find_get_length (tf);
3940 /* try detecting the charset */
3941 data = gst_type_find_peek (tf, 0, 3);
3946 /* look for a possible BOM */
3947 if (data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF)
3948 utf8_bom_detected = TRUE;
3949 else if (data[0] == 0xFF && data[1] == 0xFE)
3950 data_endianness = G_LITTLE_ENDIAN;
3951 else if (data[0] == 0xFE && data[1] == 0xFF)
3952 data_endianness = G_BIG_ENDIAN;
3956 /* try a default that should be enough */
3959 else if (length < 64)
3961 else /* the first few bytes should be enough */
3962 length = MIN (1024, length);
3964 data = gst_type_find_peek (tf, 0, length);
3973 if (utf8_bom_detected) {
3974 /* skip last byte of the BOM */
3978 if (xml_check_first_element_from_data (data, length,
3979 "SmoothStreamingMedia", 20, TRUE))
3980 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MSS_MANIFEST_CAPS);
3982 length = GST_ROUND_DOWN_2 (length);
3984 /* convert to native endian UTF-16 */
3985 mss_manifest_load_utf16 (utf16_ne, data, length, data_endianness);
3987 /* and now convert to UTF-8 */
3988 utf8 = g_utf16_to_utf8 (utf16_ne, length / 2, &n_read, &size, NULL);
3989 if (utf8 != NULL && n_read > 0) {
3990 if (xml_check_first_element_from_data ((const guint8 *) utf8, size,
3991 "SmoothStreamingMedia", 20, TRUE))
3992 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MSS_MANIFEST_CAPS);
3998 /*** image/jpeg ***/
4000 #define JPEG_MARKER_IS_START_OF_FRAME(x) \
4001 ((x)>=0xc0 && (x) <= 0xcf && (x)!=0xc4 && (x)!=0xc8 && (x)!=0xcc)
4003 static GstStaticCaps jpeg_caps = GST_STATIC_CAPS ("image/jpeg");
4005 #define JPEG_CAPS (gst_static_caps_get(&jpeg_caps))
4007 jpeg_type_find (GstTypeFind * tf, gpointer unused)
4009 GstTypeFindProbability prob = GST_TYPE_FIND_POSSIBLE;
4010 DataScanCtx c = { 0, NULL, 0 };
4014 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 2)))
4017 if (c.data[0] != 0xff || c.data[1] != 0xd8)
4021 data_scan_ctx_advance (tf, &c, 2);
4023 caps = gst_caps_copy (JPEG_CAPS);
4025 while (data_scan_ctx_ensure_data (tf, &c, 4) && c.offset < (200 * 1024)) {
4029 if (c.data[0] != 0xff)
4033 if (G_UNLIKELY (marker == 0xff)) {
4034 data_scan_ctx_advance (tf, &c, 1);
4038 data_scan_ctx_advance (tf, &c, 2);
4040 /* we assume all markers we'll see before SOF have a payload length; if
4041 * that's not the case we'll just detect a false sync and bail out, but
4042 * still report POSSIBLE probability */
4043 len = GST_READ_UINT16_BE (c.data);
4045 GST_LOG ("possible JPEG marker 0x%02x (@0x%04x), segment length %u",
4046 marker, (guint) c.offset, len);
4048 if (!data_scan_ctx_ensure_data (tf, &c, len))
4051 if (marker == 0xc4 || /* DEFINE_HUFFMAN_TABLES */
4052 marker == 0xcc || /* DEFINE_ARITHMETIC_CONDITIONING */
4053 marker == 0xdb || /* DEFINE_QUANTIZATION_TABLES */
4054 marker == 0xdd || /* DEFINE_RESTART_INTERVAL */
4055 marker == 0xfe) { /* COMMENT */
4056 data_scan_ctx_advance (tf, &c, len);
4058 } else if (marker == 0xe0 && len >= (2 + 4) && /* APP0 */
4059 data_scan_ctx_memcmp (tf, &c, 2, "JFIF", 4)) {
4060 GST_LOG ("found JFIF tag");
4061 prob = GST_TYPE_FIND_MAXIMUM;
4062 data_scan_ctx_advance (tf, &c, len);
4064 /* we continue until we find a start of frame marker */
4065 } else if (marker == 0xe1 && len >= (2 + 4) && /* APP1 */
4066 data_scan_ctx_memcmp (tf, &c, 2, "Exif", 4)) {
4067 GST_LOG ("found Exif tag");
4068 prob = GST_TYPE_FIND_MAXIMUM;
4069 data_scan_ctx_advance (tf, &c, len);
4071 /* we continue until we find a start of frame marker */
4072 } else if (marker >= 0xe0 && marker <= 0xef) { /* APPn */
4073 data_scan_ctx_advance (tf, &c, len);
4075 } else if (JPEG_MARKER_IS_START_OF_FRAME (marker) && len >= (2 + 8)) {
4078 h = GST_READ_UINT16_BE (c.data + 2 + 1);
4079 w = GST_READ_UINT16_BE (c.data + 2 + 1 + 2);
4080 if (h == 0 || w == 0) {
4081 GST_WARNING ("bad width %u and/or height %u in SOF header", w, h);
4085 GST_LOG ("SOF at offset %" G_GUINT64_FORMAT ", num_markers=%d, "
4086 "WxH=%dx%d", c.offset - 2, num_markers, w, h);
4088 if (num_markers >= 5 || prob == GST_TYPE_FIND_MAXIMUM)
4089 prob = GST_TYPE_FIND_MAXIMUM;
4091 prob = GST_TYPE_FIND_LIKELY;
4093 gst_caps_set_simple (caps, "width", G_TYPE_INT, w,
4094 "height", G_TYPE_INT, h, "sof-marker", G_TYPE_INT, marker & 0xf,
4099 GST_WARNING ("bad length or unexpected JPEG marker 0xff 0x%02x", marker);
4104 gst_type_find_suggest (tf, prob, caps);
4105 gst_caps_unref (caps);
4110 static GstStaticCaps bmp_caps = GST_STATIC_CAPS ("image/bmp");
4112 #define BMP_CAPS (gst_static_caps_get(&bmp_caps))
4114 bmp_type_find (GstTypeFind * tf, gpointer unused)
4116 DataScanCtx c = { 0, NULL, 0 };
4117 guint32 struct_size, w, h, planes, bpp;
4119 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 54)))
4122 if (c.data[0] != 'B' || c.data[1] != 'M')
4125 /* skip marker + size */
4126 data_scan_ctx_advance (tf, &c, 2 + 4);
4128 /* reserved, must be 0 */
4129 if (c.data[0] != 0 || c.data[1] != 0 || c.data[2] != 0 || c.data[3] != 0)
4132 data_scan_ctx_advance (tf, &c, 2 + 2);
4134 /* offset to start of image data in bytes (check for sanity) */
4135 GST_LOG ("offset=%u", GST_READ_UINT32_LE (c.data));
4136 if (GST_READ_UINT32_LE (c.data) > (10 * 1024 * 1024))
4139 struct_size = GST_READ_UINT32_LE (c.data + 4);
4140 GST_LOG ("struct_size=%u", struct_size);
4142 data_scan_ctx_advance (tf, &c, 4 + 4);
4144 if (struct_size == 0x0C) {
4145 w = GST_READ_UINT16_LE (c.data);
4146 h = GST_READ_UINT16_LE (c.data + 2);
4147 planes = GST_READ_UINT16_LE (c.data + 2 + 2);
4148 bpp = GST_READ_UINT16_LE (c.data + 2 + 2 + 2);
4149 } else if (struct_size == 40 || struct_size == 64 || struct_size == 108
4150 || struct_size == 124 || struct_size == 0xF0) {
4151 w = GST_READ_UINT32_LE (c.data);
4152 h = GST_READ_UINT32_LE (c.data + 4);
4153 planes = GST_READ_UINT16_LE (c.data + 4 + 4);
4154 bpp = GST_READ_UINT16_LE (c.data + 4 + 4 + 2);
4159 /* image sizes sanity check */
4160 GST_LOG ("w=%u, h=%u, planes=%u, bpp=%u", w, h, planes, bpp);
4161 if (w == 0 || w > 0xfffff || h == 0 || h > 0xfffff || planes != 1 ||
4162 (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32))
4165 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "image/bmp",
4166 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, "bpp", G_TYPE_INT, bpp,
4170 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4171 /*** image/tiff ***/
4172 static GstStaticCaps tiff_caps = GST_STATIC_CAPS ("image/tiff, "
4173 "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }");
4174 #define TIFF_CAPS (gst_static_caps_get(&tiff_caps))
4175 static GstStaticCaps tiff_be_caps = GST_STATIC_CAPS ("image/tiff, "
4176 "endianness = (int) BIG_ENDIAN");
4177 #define TIFF_BE_CAPS (gst_static_caps_get(&tiff_be_caps))
4178 static GstStaticCaps tiff_le_caps = GST_STATIC_CAPS ("image/tiff, "
4179 "endianness = (int) LITTLE_ENDIAN");
4180 #define TIFF_LE_CAPS (gst_static_caps_get(&tiff_le_caps))
4182 tiff_type_find (GstTypeFind * tf, gpointer unused)
4184 const guint8 *data = gst_type_find_peek (tf, 0, 8);
4185 guint8 le_header[4] = { 0x49, 0x49, 0x2A, 0x00 };
4186 guint8 be_header[4] = { 0x4D, 0x4D, 0x00, 0x2A };
4189 if (memcmp (data, le_header, 4) == 0) {
4190 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_LE_CAPS);
4191 } else if (memcmp (data, be_header, 4) == 0) {
4192 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_BE_CAPS);
4198 /*** image/x-exr ***/
4199 static GstStaticCaps exr_caps = GST_STATIC_CAPS ("image/x-exr");
4200 #define EXR_CAPS (gst_static_caps_get(&exr_caps))
4202 exr_type_find (GstTypeFind * tf, gpointer unused)
4204 const guint8 *data = gst_type_find_peek (tf, 0, 8);
4209 if (GST_READ_UINT32_LE (data) != 0x01312f76)
4212 flags = GST_READ_UINT32_LE (data + 4);
4213 if ((flags & 0xff) != 1 && (flags & 0xff) != 2)
4216 /* If bit 9 is set, bit 11 and 12 must be 0 */
4217 if ((flags & 0x200) && (flags & 0x1800))
4220 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, EXR_CAPS);
4227 static GstStaticCaps pnm_caps = GST_STATIC_CAPS ("image/x-portable-bitmap; "
4228 "image/x-portable-graymap; image/x-portable-pixmap; "
4229 "image/x-portable-anymap");
4231 #define PNM_CAPS (gst_static_caps_get(&pnm_caps))
4233 #define IS_PNM_WHITESPACE(c) \
4234 ((c) == ' ' || (c) == '\r' || (c) == '\n' || (c) == 't')
4237 pnm_type_find (GstTypeFind * tf, gpointer unused)
4239 const gchar *media_type = NULL;
4240 DataScanCtx c = { 0, NULL, 0 };
4243 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
4246 /* see http://en.wikipedia.org/wiki/Netpbm_format */
4247 if (c.data[0] != 'P' || c.data[1] < '1' || c.data[1] > '7' ||
4248 !IS_PNM_WHITESPACE (c.data[2]) ||
4249 (c.data[3] != '#' && c.data[3] < '0' && c.data[3] > '9'))
4252 switch (c.data[1]) {
4254 media_type = "image/x-portable-bitmap"; /* ASCII */
4257 media_type = "image/x-portable-graymap"; /* ASCII */
4260 media_type = "image/x-portable-pixmap"; /* ASCII */
4263 media_type = "image/x-portable-bitmap"; /* Raw */
4266 media_type = "image/x-portable-graymap"; /* Raw */
4269 media_type = "image/x-portable-pixmap"; /* Raw */
4272 media_type = "image/x-portable-anymap";
4275 g_return_if_reached ();
4278 /* try to extract width and height as well */
4279 if (c.data[1] != '7') {
4280 gchar s[64] = { 0, }
4283 /* need to skip any comment lines first */
4284 data_scan_ctx_advance (tf, &c, 3);
4286 if (!data_scan_ctx_ensure_data (tf, &c, 1))
4289 while (c.data[0] == '#') { /* we know there's still data left */
4290 data_scan_ctx_advance (tf, &c, 1);
4291 if (!data_scan_ctx_ensure_data (tf, &c, 1))
4294 while (c.data[0] != '\n' && c.data[0] != '\r') {
4295 data_scan_ctx_advance (tf, &c, 1);
4296 if (!data_scan_ctx_ensure_data (tf, &c, 1))
4299 data_scan_ctx_advance (tf, &c, 1);
4300 GST_LOG ("skipped comment line in PNM header");
4301 if (!data_scan_ctx_ensure_data (tf, &c, 1))
4305 if (!data_scan_ctx_ensure_data (tf, &c, 32) &&
4306 !data_scan_ctx_ensure_data (tf, &c, 4)) {
4310 /* need to NUL-terminate data for sscanf */
4311 memcpy (s, c.data, MIN (sizeof (s) - 1, c.size));
4312 if (sscanf (s, "%u%c%u%c", &w, &sep1, &h, &sep2) == 4 &&
4313 IS_PNM_WHITESPACE (sep1) && IS_PNM_WHITESPACE (sep2) &&
4314 w > 0 && w < G_MAXINT && h > 0 && h < G_MAXINT) {
4315 GST_LOG ("extracted PNM width and height: %dx%d", w, h);
4321 /* FIXME: extract width + height for anymaps too */
4324 if (w > 0 && h > 0) {
4325 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type,
4326 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, NULL);
4328 gst_type_find_suggest_empty_simple (tf, GST_TYPE_FIND_LIKELY, media_type);
4332 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4333 static GstStaticCaps sds_caps = GST_STATIC_CAPS ("audio/x-sds");
4335 #define SDS_CAPS (gst_static_caps_get(&sds_caps))
4337 sds_type_find (GstTypeFind * tf, gpointer unused)
4339 const guint8 *data = gst_type_find_peek (tf, 0, 4);
4340 guint8 mask[4] = { 0xFF, 0xFF, 0x80, 0xFF };
4341 guint8 match[4] = { 0xF0, 0x7E, 0, 0x01 };
4345 for (x = 0; x < 4; x++) {
4346 if ((data[x] & mask[x]) != match[x]) {
4350 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDS_CAPS);
4354 static GstStaticCaps ircam_caps = GST_STATIC_CAPS ("audio/x-ircam");
4356 #define IRCAM_CAPS (gst_static_caps_get(&ircam_caps))
4358 ircam_type_find (GstTypeFind * tf, gpointer unused)
4360 const guint8 *data = gst_type_find_peek (tf, 0, 4);
4361 guint8 mask[4] = { 0xFF, 0xFF, 0xF8, 0xFF };
4362 guint8 match[4] = { 0x64, 0xA3, 0x00, 0x00 };
4364 gboolean matched = TRUE;
4369 for (x = 0; x < 4; x++) {
4370 if ((data[x] & mask[x]) != match[x]) {
4375 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, IRCAM_CAPS);
4378 /* now try the reverse version */
4380 for (x = 0; x < 4; x++) {
4381 if ((data[x] & mask[3 - x]) != match[3 - x]) {
4387 /*** Matroska/WebM ***/
4389 #define EBML_HEADER 0x1A45DFA3
4390 #define EBML_VERSION 0x4286
4391 #define EBML_DOCTYPE 0x4282
4392 #define EBML_DOCTYPE_VERSION 0x4287
4393 #define MATROSKA_SEGMENT 0x18538067
4394 #define MATROSKA_CLUSTER 0x1F43B675
4395 #define MATROSKA_TRACKS 0x1654AE6B
4396 #define MATROSKA_TRACK_ENTRY 0xAE
4397 #define MATROSKA_TRACK_TYPE 0x83
4398 #define MATROSKA_STEREO_MODE 0x53B8
4400 #define EBML_MAX_LEN (2 * 1024 * 1024)
4404 EBML_DOCTYPE_UNKNOWN = 0,
4405 EBML_DOCTYPE_MATROSKA,
4411 GstEbmlDocType doctype;
4417 guint tracks_ok; /* if we've seen and fully parsed the TRACKS element */
4421 ebml_read_chunk_header (GstTypeFind * tf, DataScanCtx * c, guint max_size,
4422 guint32 * id, guint64 * size)
4425 guint msbit_set, i, len, id_len;
4427 if (c->size < 12 || max_size < 1)
4432 if ((c->data[0] & 0x80) == 0x80) {
4434 } else if ((c->data[0] & 0xC0) == 0x40) {
4436 } else if ((c->data[0] & 0xE0) == 0x20) {
4438 } else if ((c->data[0] & 0xF0) == 0x10) {
4444 if (max_size < id_len)
4447 for (i = 1; i < id_len; ++i) {
4448 *id = (*id << 8) | c->data[i];
4451 data_scan_ctx_advance (tf, c, id_len);
4455 if (max_size < 1 || c->data[0] == 0)
4458 msbit_set = g_bit_nth_msf (c->data[0], 8);
4459 mask = ((1 << msbit_set) - 1);
4460 *size = c->data[0] & mask;
4461 len = 7 - msbit_set;
4463 if (max_size < 1 + len)
4465 for (i = 0; i < len; ++i) {
4466 mask = (mask << 8) | 0xff;
4467 *size = (*size << 8) | c->data[1 + i];
4470 data_scan_ctx_advance (tf, c, 1 + len);
4472 /* undefined/unknown size? (all bits 1) */
4473 if (*size == mask) {
4474 /* allow unknown size for SEGMENT chunk, bail out otherwise */
4475 if (*id == MATROSKA_SEGMENT)
4476 *size = G_MAXUINT64;
4481 return id_len + (1 + len);
4485 ebml_parse_chunk (GstTypeFind * tf, DataScanCtx * ctx, guint32 chunk_id,
4486 guint chunk_size, GstMatroskaInfo * info, guint depth)
4487 { /* FIXME: make sure input size is clipped to 32 bit */
4488 static const gchar SPACES[] = " ";
4489 DataScanCtx c = *ctx;
4490 guint64 element_size = 0;
4491 guint32 id, hdr_len;
4493 if (depth >= 8) /* keep SPACES large enough for depth */
4496 while (chunk_size > 0) {
4497 if (c.offset > EBML_MAX_LEN || !data_scan_ctx_ensure_data (tf, &c, 64))
4500 hdr_len = ebml_read_chunk_header (tf, &c, chunk_size, &id, &element_size);
4504 g_assert (hdr_len <= chunk_size);
4505 chunk_size -= hdr_len;
4507 if (element_size > chunk_size)
4510 GST_DEBUG ("%s %08x, size %" G_GUINT64_FORMAT " / %" G_GUINT64_FORMAT,
4511 SPACES + sizeof (SPACES) - 1 - (2 * depth), id, element_size,
4512 hdr_len + element_size);
4514 if (element_size >= G_MAXUINT32) {
4515 GST_DEBUG ("Chunk too big for typefinding");
4519 if (!data_scan_ctx_ensure_data (tf, &c, element_size)) {
4520 GST_DEBUG ("not enough data");
4526 if (element_size >= 8 && memcmp (c.data, "matroska", 8) == 0)
4527 info->doctype = EBML_DOCTYPE_MATROSKA;
4528 else if (element_size >= 4 && memcmp (c.data, "webm", 4) == 0)
4529 info->doctype = EBML_DOCTYPE_WEBM;
4531 case MATROSKA_SEGMENT:
4532 GST_LOG ("parsing segment");
4533 ebml_parse_chunk (tf, &c, id, element_size, info, depth + 1);
4534 GST_LOG ("parsed segment, done");
4536 case MATROSKA_TRACKS:
4537 GST_LOG ("parsing tracks");
4539 ebml_parse_chunk (tf, &c, id, element_size, info, depth + 1);
4540 GST_LOG ("parsed tracks: %s, done (after %" G_GUINT64_FORMAT " bytes)",
4541 info->tracks_ok ? "ok" : "FAIL", c.offset + element_size);
4543 case MATROSKA_TRACK_ENTRY:
4544 GST_LOG ("parsing track entry");
4545 if (!ebml_parse_chunk (tf, &c, id, element_size, info, depth + 1))
4548 case MATROSKA_TRACK_TYPE:{
4551 /* is supposed to always be 1-byte, but not everyone's following that */
4552 for (i = 0; i < element_size; ++i)
4553 type = (type << 8) | c.data[i];
4555 GST_DEBUG ("%s track type %u",
4556 SPACES + sizeof (SPACES) - 1 - (2 * depth), type);
4560 else if (c.data[0] == 2)
4566 case MATROSKA_STEREO_MODE:
4567 ++info->video_stereo;
4569 case MATROSKA_CLUSTER:
4570 GST_WARNING ("cluster, bailing out (should've found tracks by now)");
4575 data_scan_ctx_advance (tf, &c, element_size);
4576 chunk_size -= element_size;
4583 static GstStaticCaps matroska_caps = GST_STATIC_CAPS ("video/x-matroska");
4585 #define MATROSKA_CAPS (gst_static_caps_get(&matroska_caps))
4587 matroska_type_find (GstTypeFind * tf, gpointer unused)
4589 GstTypeFindProbability prob;
4590 GstMatroskaInfo info = { 0, };
4591 const gchar *type_name;
4592 DataScanCtx c = { 0, NULL, 0 };
4595 guint32 id, hdr_len;
4597 if (!data_scan_ctx_ensure_data (tf, &c, 64))
4600 if (GST_READ_UINT32_BE (c.data) != EBML_HEADER)
4603 while (c.offset < EBML_MAX_LEN && data_scan_ctx_ensure_data (tf, &c, 64)) {
4604 hdr_len = ebml_read_chunk_header (tf, &c, c.size, &id, &size);
4608 GST_INFO ("=== top-level chunk %08x, size %" G_GUINT64_FORMAT
4609 " / %" G_GUINT64_FORMAT, id, size, size + hdr_len);
4611 if (!ebml_parse_chunk (tf, &c, id, size, &info, 0))
4613 data_scan_ctx_advance (tf, &c, size);
4614 GST_INFO ("=== done with chunk %08x", id);
4615 if (id == MATROSKA_SEGMENT)
4619 GST_INFO ("audio=%u video=%u other=%u chunks=%u doctype=%d all_tracks=%d",
4620 info.audio, info.video, info.other, info.chunks, info.doctype,
4623 /* perhaps we should bail out if tracks_ok is FALSE and wait for more data?
4624 * (we would need new API to signal this properly and prevent other
4625 * typefinders from taking over the decision then) */
4626 is_audio = (info.audio > 0 && info.video == 0 && info.other == 0);
4628 if (info.doctype == EBML_DOCTYPE_WEBM) {
4629 type_name = (is_audio) ? "audio/webm" : "video/webm";
4630 } else if (info.video > 0 && info.video_stereo) {
4631 type_name = "video/x-matroska-3d";
4633 type_name = (is_audio) ? "audio/x-matroska" : "video/x-matroska";
4636 if (info.doctype == EBML_DOCTYPE_UNKNOWN)
4637 prob = GST_TYPE_FIND_LIKELY;
4639 prob = GST_TYPE_FIND_MAXIMUM;
4641 gst_type_find_suggest_empty_simple (tf, prob, type_name);
4644 /*** application/mxf ***/
4645 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4646 static GstStaticCaps mxf_caps = GST_STATIC_CAPS ("application/mxf");
4648 #define MXF_MAX_PROBE_LENGTH (1024 * 64)
4649 #define MXF_CAPS (gst_static_caps_get(&mxf_caps))
4652 * MXF files start with a header partition pack key of 16 bytes which is defined
4653 * at SMPTE-377M 6.1. Before this there can be up to 64K of run-in which _must_
4654 * not contain the partition pack key.
4657 mxf_type_find (GstTypeFind * tf, gpointer unused)
4659 static const guint8 partition_pack_key[] =
4660 { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
4663 DataScanCtx c = { 0, NULL, 0 };
4665 while (c.offset <= MXF_MAX_PROBE_LENGTH) {
4667 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 1024)))
4670 /* look over in chunks of 1kbytes to avoid too much overhead */
4672 for (i = 0; i < 1024 - 16; i++) {
4673 /* Check first byte before calling more expensive memcmp function */
4674 if (G_UNLIKELY (c.data[i] == 0x06
4675 && memcmp (c.data + i, partition_pack_key, 13) == 0)) {
4676 /* Header partition pack? */
4677 if (c.data[i + 13] != 0x02)
4680 /* Partition status */
4681 if (c.data[i + 14] >= 0x05)
4684 /* Reserved, must be 0x00 */
4685 if (c.data[i + 15] != 0x00)
4688 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
4694 data_scan_ctx_advance (tf, &c, 1024 - 16);
4698 /*** video/x-dv ***/
4700 static GstStaticCaps dv_caps = GST_STATIC_CAPS ("video/x-dv, "
4701 "systemstream = (boolean) true");
4702 #define DV_CAPS (gst_static_caps_get(&dv_caps))
4704 dv_type_find (GstTypeFind * tf, gpointer private)
4708 data = gst_type_find_peek (tf, 0, 5);
4710 /* check for DIF and DV flag */
4711 if (data && (data[0] == 0x1f) && (data[1] == 0x07) && (data[2] == 0x00)) {
4712 const gchar *format;
4714 if (data[3] & 0x80) {
4720 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "video/x-dv",
4721 "systemstream", G_TYPE_BOOLEAN, TRUE,
4722 "format", G_TYPE_STRING, format, NULL);
4727 /*** Ogg variants ***/
4728 static GstStaticCaps ogg_caps =
4729 GST_STATIC_CAPS ("application/ogg;video/ogg;audio/ogg;application/kate");
4731 #define OGG_CAPS (gst_static_caps_get(&ogg_caps))
4745 ogganx_type_find (GstTypeFind * tf, gpointer private)
4747 const gchar *media_type;
4748 DataScanCtx c = { 0, NULL, 0 };
4749 guint ogg_syncs = 0;
4750 guint hdr_count[OGG_NUM] = { 0, };
4753 const gchar marker[10];
4755 GstOggStreamType stream_type;
4758 "\001vorbis", 7, OGG_AUDIO}, {
4759 "\200theora", 7, OGG_VIDEO}, {
4760 "fLaC", 4, OGG_AUDIO}, {
4761 "\177FLAC", 5, OGG_AUDIO}, {
4762 "Speex", 5, OGG_AUDIO}, {
4763 "CMML\0\0\0\0", 8, OGG_OTHER}, {
4764 "PCM ", 8, OGG_AUDIO}, {
4765 "Annodex", 7, OGG_ANNODEX}, {
4766 "fishead", 7, OGG_SKELETON}, {
4767 "AnxData", 7, OGG_ANNODEX}, {
4768 "CELT ", 8, OGG_AUDIO}, {
4769 "\200kate\0\0\0", 8, OGG_KATE}, {
4770 "BBCD\0", 5, OGG_VIDEO}, {
4771 "OVP80\1\1", 7, OGG_VIDEO}, {
4772 "OpusHead", 8, OGG_AUDIO}, {
4773 "\001audio\0\0\0", 9, OGG_AUDIO}, {
4774 "\001video\0\0\0", 9, OGG_VIDEO}, {
4775 "\001text\0\0\0", 9, OGG_OTHER}
4778 while (c.offset < 4096 && data_scan_ctx_ensure_data (tf, &c, 64)) {
4781 if (memcmp (c.data, "OggS", 5) != 0)
4787 if (c.data[5] != 0x02)
4790 /* headers should only have one segment */
4791 if (c.data[26] != 1)
4798 data_scan_ctx_advance (tf, &c, 28);
4800 if (!data_scan_ctx_ensure_data (tf, &c, MAX (size, 8)))
4803 for (i = 0; i < G_N_ELEMENTS (markers); ++i) {
4804 if (memcmp (c.data, markers[i].marker, markers[i].marker_size) == 0) {
4805 ++hdr_count[markers[i].stream_type];
4810 if (i == G_N_ELEMENTS (markers)) {
4811 GST_MEMDUMP ("unknown Ogg stream marker", c.data, size);
4812 ++hdr_count[OGG_OTHER];
4815 data_scan_ctx_advance (tf, &c, size);
4821 /* We don't bother with annodex types. FIXME: what about XSPF? */
4822 if (hdr_count[OGG_VIDEO] > 0) {
4823 media_type = "video/ogg";
4824 } else if (hdr_count[OGG_AUDIO] > 0) {
4825 media_type = "audio/ogg";
4826 } else if (hdr_count[OGG_KATE] > 0 && hdr_count[OGG_OTHER] == 0) {
4827 media_type = "application/kate";
4829 media_type = "application/ogg";
4832 GST_INFO ("found %s (audio:%u, video:%u, annodex:%u, skeleton:%u, other:%u)",
4833 media_type, hdr_count[OGG_AUDIO], hdr_count[OGG_VIDEO],
4834 hdr_count[OGG_ANNODEX], hdr_count[OGG_SKELETON], hdr_count[OGG_OTHER]);
4836 gst_type_find_suggest_empty_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type);
4839 /*** audio/x-vorbis ***/
4840 static GstStaticCaps vorbis_caps = GST_STATIC_CAPS ("audio/x-vorbis");
4842 #define VORBIS_CAPS (gst_static_caps_get(&vorbis_caps))
4844 vorbis_type_find (GstTypeFind * tf, gpointer private)
4846 const guint8 *data = gst_type_find_peek (tf, 0, 30);
4852 /* 1 byte packet type (identification=0x01)
4853 6 byte string "vorbis"
4854 4 byte vorbis version */
4855 if (memcmp (data, "\001vorbis\000\000\000\000", 11) != 0)
4858 /* 1 byte channels must be != 0 */
4862 /* 4 byte samplerate must be != 0 */
4863 if (GST_READ_UINT32_LE (data) == 0)
4866 /* blocksize checks */
4867 blocksize_0 = data[0] & 0x0F;
4868 blocksize_1 = (data[0] & 0xF0) >> 4;
4869 if (blocksize_0 > blocksize_1)
4871 if (blocksize_0 < 6 || blocksize_0 > 13)
4873 if (blocksize_1 < 6 || blocksize_1 > 13)
4877 if ((data[0] & 0x01) != 1)
4879 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VORBIS_CAPS);
4883 /*** video/x-theora ***/
4885 static GstStaticCaps theora_caps = GST_STATIC_CAPS ("video/x-theora");
4887 #define THEORA_CAPS (gst_static_caps_get(&theora_caps))
4889 theora_type_find (GstTypeFind * tf, gpointer private)
4891 const guint8 *data = gst_type_find_peek (tf, 0, 7); //42);
4894 if (data[0] != 0x80)
4896 if (memcmp (&data[1], "theora", 6) != 0)
4898 /* FIXME: make this more reliable when specs are out */
4900 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, THEORA_CAPS);
4904 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4907 kate_type_find (GstTypeFind * tf, gpointer private)
4909 const guint8 *data = gst_type_find_peek (tf, 0, 64);
4910 gchar category[16] = { 0, };
4912 if (G_UNLIKELY (data == NULL))
4915 /* see: http://wiki.xiph.org/index.php/OggKate#Format_specification */
4916 if (G_LIKELY (memcmp (data, "\200kate\0\0\0", 8) != 0))
4919 /* make sure we always have a NUL-terminated string */
4920 memcpy (category, data + 48, 15);
4921 GST_LOG ("kate category: %s", category);
4922 /* canonical categories for subtitles: subtitles, spu-subtitles, SUB, K-SPU */
4923 if (strcmp (category, "subtitles") == 0 || strcmp (category, "SUB") == 0 ||
4924 strcmp (category, "spu-subtitles") == 0 ||
4925 strcmp (category, "K-SPU") == 0) {
4926 gst_type_find_suggest_empty_simple (tf, GST_TYPE_FIND_MAXIMUM,
4929 gst_type_find_suggest_empty_simple (tf, GST_TYPE_FIND_MAXIMUM,
4930 "application/x-kate");
4935 /*** WEBVTTT subtitles ***/
4936 static GstStaticCaps webvtt_caps =
4937 GST_STATIC_CAPS ("application/x-subtitle-vtt, parsed=(boolean)false");
4938 #define WEBVTT_CAPS (gst_static_caps_get(&webvtt_caps))
4941 webvtt_type_find (GstTypeFind * tf, gpointer private)
4945 data = gst_type_find_peek (tf, 0, 10);
4950 /* there might be a UTF-8 BOM at the beginning */
4951 if (memcmp (data, "WEBVTT", 6) != 0 && memcmp (data + 3, "WEBVTT", 6) != 0) {
4955 if (data[0] != 'W') {
4956 if (data[0] != 0xef || data[1] != 0xbb || data[2] != 0xbf)
4957 return; /* Not a UTF-8 BOM */
4961 /* After the WEBVTT magic must be one of these chars:
4962 * 0x20 (space), 0x9 (tab), 0xa (LF) or 0xd (CR) */
4963 if (data[6] != 0x20 && data[6] != 0x9 && data[6] != 0xa && data[6] != 0xd) {
4967 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, WEBVTT_CAPS);
4970 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
4971 /*** application/x-ogm-video or audio***/
4973 static GstStaticCaps ogmvideo_caps =
4974 GST_STATIC_CAPS ("application/x-ogm-video");
4975 #define OGMVIDEO_CAPS (gst_static_caps_get(&ogmvideo_caps))
4977 ogmvideo_type_find (GstTypeFind * tf, gpointer private)
4979 const guint8 *data = gst_type_find_peek (tf, 0, 9);
4982 if (memcmp (data, "\001video\000\000\000", 9) != 0)
4984 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMVIDEO_CAPS);
4988 static GstStaticCaps ogmaudio_caps =
4989 GST_STATIC_CAPS ("application/x-ogm-audio");
4990 #define OGMAUDIO_CAPS (gst_static_caps_get(&ogmaudio_caps))
4992 ogmaudio_type_find (GstTypeFind * tf, gpointer private)
4994 const guint8 *data = gst_type_find_peek (tf, 0, 9);
4997 if (memcmp (data, "\001audio\000\000\000", 9) != 0)
4999 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMAUDIO_CAPS);
5003 static GstStaticCaps ogmtext_caps = GST_STATIC_CAPS ("application/x-ogm-text");
5005 #define OGMTEXT_CAPS (gst_static_caps_get(&ogmtext_caps))
5007 ogmtext_type_find (GstTypeFind * tf, gpointer private)
5009 const guint8 *data = gst_type_find_peek (tf, 0, 9);
5012 if (memcmp (data, "\001text\000\000\000\000", 9) != 0)
5014 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMTEXT_CAPS);
5018 /*** audio/x-speex ***/
5020 static GstStaticCaps speex_caps = GST_STATIC_CAPS ("audio/x-speex");
5022 #define SPEEX_CAPS (gst_static_caps_get(&speex_caps))
5024 speex_type_find (GstTypeFind * tf, gpointer private)
5026 const guint8 *data = gst_type_find_peek (tf, 0, 80);
5029 /* 8 byte string "Speex "
5030 24 byte speex version string + int */
5031 if (memcmp (data, "Speex ", 8) != 0)
5035 /* 4 byte header size >= 80 */
5036 if (GST_READ_UINT32_LE (data) < 80)
5040 /* 4 byte sample rate <= 48000 */
5041 if (GST_READ_UINT32_LE (data) > 48000)
5045 /* currently there are only 3 speex modes. */
5046 if (GST_READ_UINT32_LE (data) > 3)
5050 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SPEEX_CAPS);
5054 /*** audio/x-celt ***/
5056 static GstStaticCaps celt_caps = GST_STATIC_CAPS ("audio/x-celt");
5058 #define CELT_CAPS (gst_static_caps_get(&celt_caps))
5060 celt_type_find (GstTypeFind * tf, gpointer private)
5062 const guint8 *data = gst_type_find_peek (tf, 0, 8);
5065 /* 8 byte string "CELT " */
5066 if (memcmp (data, "CELT ", 8) != 0)
5069 /* TODO: Check other values of the CELT header */
5070 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CELT_CAPS);
5074 /*** application/x-ogg-skeleton ***/
5075 static GstStaticCaps ogg_skeleton_caps =
5076 GST_STATIC_CAPS ("application/x-ogg-skeleton, parsed=(boolean)FALSE");
5077 #define OGG_SKELETON_CAPS (gst_static_caps_get(&ogg_skeleton_caps))
5079 oggskel_type_find (GstTypeFind * tf, gpointer private)
5081 const guint8 *data = gst_type_find_peek (tf, 0, 12);
5084 /* 8 byte string "fishead\0" for the ogg skeleton stream */
5085 if (memcmp (data, "fishead\0", 8) != 0)
5089 /* Require that the header contains version 3.0 */
5090 if (GST_READ_UINT16_LE (data) != 3)
5093 if (GST_READ_UINT16_LE (data) != 0)
5096 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGG_SKELETON_CAPS);
5100 static GstStaticCaps cmml_caps = GST_STATIC_CAPS ("text/x-cmml");
5102 #define CMML_CAPS (gst_static_caps_get(&cmml_caps))
5104 cmml_type_find (GstTypeFind * tf, gpointer private)
5106 /* Header is 12 bytes minimum (though we don't check the minor version */
5107 const guint8 *data = gst_type_find_peek (tf, 0, 12);
5111 /* 8 byte string "CMML\0\0\0\0" for the magic number */
5112 if (memcmp (data, "CMML\0\0\0\0", 8) != 0)
5116 /* Require that the header contains at least version 2.0 */
5117 if (GST_READ_UINT16_LE (data) < 2)
5120 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CMML_CAPS);
5124 /*** application/x-tar ***/
5126 static GstStaticCaps tar_caps = GST_STATIC_CAPS ("application/x-tar");
5128 #define TAR_CAPS (gst_static_caps_get(&tar_caps))
5129 #define OLDGNU_MAGIC "ustar " /* 7 chars and a NUL */
5130 #define NEWGNU_MAGIC "ustar" /* 5 chars and a NUL */
5132 tar_type_find (GstTypeFind * tf, gpointer unused)
5134 const guint8 *data = gst_type_find_peek (tf, 257, 8);
5136 /* of course we are not certain, but we don't want other typefind funcs
5137 * to detect formats of files within the tar archive, e.g. mp3s */
5139 if (memcmp (data, OLDGNU_MAGIC, 8) == 0) { /* sic */
5140 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
5141 } else if (memcmp (data, NEWGNU_MAGIC, 6) == 0 && /* sic */
5142 g_ascii_isdigit (data[6]) && g_ascii_isdigit (data[7])) {
5143 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
5148 /*** application/x-ar ***/
5150 static GstStaticCaps ar_caps = GST_STATIC_CAPS ("application/x-ar");
5152 #define AR_CAPS (gst_static_caps_get(&ar_caps))
5154 ar_type_find (GstTypeFind * tf, gpointer unused)
5156 const guint8 *data = gst_type_find_peek (tf, 0, 24);
5158 if (data && memcmp (data, "!<arch>", 7) == 0) {
5161 for (i = 7; i < 24; ++i) {
5162 if (!g_ascii_isprint (data[i]) && data[i] != '\n') {
5163 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AR_CAPS);
5167 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AR_CAPS);
5172 /*** audio/x-au ***/
5174 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
5175 * as it is only possible to register one typefind factory per 'name'
5176 * (which is in this case the caps), and the first one would be replaced by
5177 * the second one. */
5178 static GstStaticCaps au_caps = GST_STATIC_CAPS ("audio/x-au");
5180 #define AU_CAPS (gst_static_caps_get(&au_caps))
5182 au_type_find (GstTypeFind * tf, gpointer unused)
5184 const guint8 *data = gst_type_find_peek (tf, 0, 4);
5187 if (memcmp (data, ".snd", 4) == 0 || memcmp (data, "dns.", 4) == 0) {
5188 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AU_CAPS);
5194 /*** video/x-nuv ***/
5196 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
5197 * as it is only possible to register one typefind factory per 'name'
5198 * (which is in this case the caps), and the first one would be replaced by
5199 * the second one. */
5200 static GstStaticCaps nuv_caps = GST_STATIC_CAPS ("video/x-nuv");
5202 #define NUV_CAPS (gst_static_caps_get(&nuv_caps))
5204 nuv_type_find (GstTypeFind * tf, gpointer unused)
5206 const guint8 *data = gst_type_find_peek (tf, 0, 11);
5209 if (memcmp (data, "MythTVVideo", 11) == 0
5210 || memcmp (data, "NuppelVideo", 11) == 0) {
5211 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, NUV_CAPS);
5216 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5217 /*** audio/x-paris ***/
5218 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
5219 static GstStaticCaps paris_caps = GST_STATIC_CAPS ("audio/x-paris");
5221 #define PARIS_CAPS (gst_static_caps_get(&paris_caps))
5223 paris_type_find (GstTypeFind * tf, gpointer unused)
5225 const guint8 *data = gst_type_find_peek (tf, 0, 4);
5228 if (memcmp (data, " paf", 4) == 0 || memcmp (data, "fap ", 4) == 0) {
5229 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, PARIS_CAPS);
5234 /*** audio/x-sbc ***/
5235 static GstStaticCaps sbc_caps = GST_STATIC_CAPS ("audio/x-sbc");
5236 #define SBC_CAPS (gst_static_caps_get(&sbc_caps))
5239 sbc_check_header (const guint8 * data, gsize len, guint * rate,
5242 static const guint16 sbc_rates[4] = { 16000, 32000, 44100, 48000 };
5243 static const guint8 sbc_blocks[4] = { 4, 8, 12, 16 };
5244 guint n_blocks, ch_mode, n_subbands, bitpool;
5246 if (data[0] != 0x9C || len < 4)
5249 n_blocks = sbc_blocks[(data[1] >> 4) & 0x03];
5250 ch_mode = (data[1] >> 2) & 0x03;
5251 n_subbands = (data[1] & 0x01) ? 8 : 4;
5256 *rate = sbc_rates[(data[1] >> 6) & 0x03];
5257 *channels = (ch_mode == 0) ? 1 : 2;
5260 return 4 + (n_subbands * 1) / 2 + (n_blocks * 1 * bitpool) / 8;
5261 else if (ch_mode == 1)
5262 return 4 + (n_subbands * 2) / 2 + (n_blocks * 2 * bitpool) / 8;
5263 else if (ch_mode == 2)
5264 return 4 + (n_subbands * 2) / 2 + (n_blocks * bitpool) / 8;
5265 else if (ch_mode == 3)
5266 return 4 + (n_subbands * 2) / 2 + (n_subbands + n_blocks * bitpool) / 8;
5272 sbc_type_find (GstTypeFind * tf, gpointer unused)
5276 guint i, rate, channels, offset = 0;
5278 for (i = 0; i < 10; ++i) {
5279 data = gst_type_find_peek (tf, offset, 8);
5283 frame_len = sbc_check_header (data, 8, &rate, &channels);
5287 offset += frame_len;
5289 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE, "audio/x-sbc",
5290 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels,
5291 "parsed", G_TYPE_BOOLEAN, FALSE, NULL);
5294 /*** audio/iLBC-sh ***/
5295 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
5296 static GstStaticCaps ilbc_caps = GST_STATIC_CAPS ("audio/iLBC-sh");
5298 #define ILBC_CAPS (gst_static_caps_get(&ilbc_caps))
5300 ilbc_type_find (GstTypeFind * tf, gpointer unused)
5302 const guint8 *data = gst_type_find_peek (tf, 0, 8);
5305 if (memcmp (data, "#!iLBC30", 8) == 0 || memcmp (data, "#!iLBC20", 8) == 0) {
5306 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, ILBC_CAPS);
5311 /*** application/x-ms-dos-executable ***/
5313 static GstStaticCaps msdos_caps =
5314 GST_STATIC_CAPS ("application/x-ms-dos-executable");
5315 #define MSDOS_CAPS (gst_static_caps_get(&msdos_caps))
5316 /* see http://www.madchat.org/vxdevl/papers/winsys/pefile/pefile.htm */
5318 msdos_type_find (GstTypeFind * tf, gpointer unused)
5320 const guint8 *data = gst_type_find_peek (tf, 0, 64);
5322 if (data && data[0] == 'M' && data[1] == 'Z' &&
5323 GST_READ_UINT16_LE (data + 8) == 4) {
5324 guint32 pe_offset = GST_READ_UINT32_LE (data + 60);
5326 data = gst_type_find_peek (tf, pe_offset, 2);
5327 if (data && data[0] == 'P' && data[1] == 'E') {
5328 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, MSDOS_CAPS);
5333 /*** application/x-mmsh ***/
5335 static GstStaticCaps mmsh_caps = GST_STATIC_CAPS ("application/x-mmsh");
5337 #define MMSH_CAPS gst_static_caps_get(&mmsh_caps)
5339 /* This is to recognise mssh-over-http */
5341 mmsh_type_find (GstTypeFind * tf, gpointer unused)
5343 static const guint8 asf_marker[16] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66,
5344 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
5349 data = gst_type_find_peek (tf, 0, 2 + 2 + 4 + 2 + 2 + 16);
5350 if (data && data[0] == 0x24 && data[1] == 0x48 &&
5351 GST_READ_UINT16_LE (data + 2) > 2 + 2 + 4 + 2 + 2 + 16 &&
5352 memcmp (data + 2 + 2 + 4 + 2 + 2, asf_marker, 16) == 0) {
5353 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MMSH_CAPS);
5357 /*** video/x-dirac ***/
5359 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
5360 * as it is only possible to register one typefind factory per 'name'
5361 * (which is in this case the caps), and the first one would be replaced by
5362 * the second one. */
5363 static GstStaticCaps dirac_caps = GST_STATIC_CAPS ("video/x-dirac");
5365 #define DIRAC_CAPS (gst_static_caps_get(&dirac_caps))
5367 dirac_type_find (GstTypeFind * tf, gpointer unused)
5369 const guint8 *data = gst_type_find_peek (tf, 0, 8);
5372 if (memcmp (data, "BBCD", 4) == 0 || memcmp (data, "KW-DIRAC", 8) == 0) {
5373 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DIRAC_CAPS);
5378 /*** audio/x-tap-tap ***/
5380 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
5381 * as it is only possible to register one typefind factory per 'name'
5382 * (which is in this case the caps), and the first one would be replaced by
5383 * the second one. */
5384 static GstStaticCaps tap_caps = GST_STATIC_CAPS ("audio/x-tap-tap");
5386 #define TAP_CAPS (gst_static_caps_get(&tap_caps))
5388 tap_type_find (GstTypeFind * tf, gpointer unused)
5390 const guint8 *data = gst_type_find_peek (tf, 0, 16);
5393 if (memcmp (data, "C64-TAPE-RAW", 12) == 0
5394 || memcmp (data, "C16-TAPE-RAW", 12) == 0) {
5395 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TAP_CAPS);
5400 /*** video/vivo ***/
5402 static GstStaticCaps vivo_caps = GST_STATIC_CAPS ("video/vivo");
5404 #define VIVO_CAPS gst_static_caps_get(&vivo_caps)
5407 vivo_type_find (GstTypeFind * tf, gpointer unused)
5409 static const guint8 vivo_marker[] = { 'V', 'e', 'r', 's', 'i', 'o', 'n',
5410 ':', 'V', 'i', 'v', 'o', '/'
5415 data = gst_type_find_peek (tf, 0, 1024);
5416 if (data == NULL || data[0] != 0x00)
5419 if ((data[1] & 0x80)) {
5420 if ((data[2] & 0x80))
5422 hdr_len = ((guint) (data[1] & 0x7f)) << 7;
5432 /* 1008 = 1022 - strlen ("Version:Vivo/") - 1 */
5433 while (pos < 1008 && data[pos] == '\r' && data[pos + 1] == '\n')
5436 if (memcmp (data + pos, vivo_marker, sizeof (vivo_marker)) == 0) {
5437 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VIVO_CAPS);
5441 /*** XDG MIME typefinder (to avoid false positives mostly) ***/
5445 xdgmime_validate_name (const gchar * name)
5449 if (G_UNLIKELY (!g_ascii_isalpha (*name))) {
5453 /* FIXME: test name string more */
5455 while (*s && (g_ascii_isalnum (*s) || strchr ("/-_.:+", *s) != NULL))
5457 if (G_UNLIKELY (*s != '\0')) {
5465 xdgmime_typefind (GstTypeFind * find, gpointer user_data)
5468 gsize length = 16384;
5473 if ((tf_length = gst_type_find_get_length (find)) > 0)
5474 length = MIN (length, tf_length);
5476 if ((data = gst_type_find_peek (find, 0, length)) == NULL)
5479 tmp = g_content_type_guess (NULL, data, length, NULL);
5480 if (tmp == NULL || g_content_type_is_unknown (tmp)) {
5485 mimetype = g_content_type_get_mime_type (tmp);
5488 if (mimetype == NULL)
5491 GST_DEBUG ("Got mimetype '%s'", mimetype);
5493 /* Ignore audio/video types:
5494 * - our own typefinders in -base are likely to be better at this
5495 * (and if they're not, we really want to fix them, that's why we don't
5496 * report xdg-detected audio/video types at all, not even with a low
5498 * - we want to detect GStreamer media types and not MIME types
5499 * - the purpose of this xdg mime finder is mainly to prevent false
5500 * positives of non-media formats, not to typefind audio/video formats */
5501 if (g_str_has_prefix (mimetype, "audio/") ||
5502 g_str_has_prefix (mimetype, "video/")) {
5503 GST_LOG ("Ignoring audio/video mime type");
5508 if (!xdgmime_validate_name (mimetype)) {
5509 GST_LOG ("Ignoring mimetype with invalid structure name");
5514 /* Again, we mainly want the xdg typefinding to prevent false-positives on
5515 * non-media formats, so suggest the type with a probability that trumps
5516 * uncertain results of our typefinders, but not more than that. */
5517 GST_LOG ("Suggesting '%s' with probability POSSIBLE", mimetype);
5518 gst_type_find_suggest_empty_simple (find, GST_TYPE_FIND_POSSIBLE, mimetype);
5521 #endif /* USE_GIO */
5523 /*** Windows icon typefinder (to avoid false positives mostly) ***/
5524 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5526 windows_icon_typefind (GstTypeFind * find, gpointer user_data)
5530 guint16 type, nimages;
5531 gint32 size, offset;
5533 datalen = gst_type_find_get_length (find);
5536 if ((data = gst_type_find_peek (find, 0, 6)) == NULL)
5539 /* header - simple and not enough to rely on it alone */
5540 if (GST_READ_UINT16_LE (data) != 0)
5542 type = GST_READ_UINT16_LE (data + 2);
5543 if (type != 1 && type != 2)
5545 nimages = GST_READ_UINT16_LE (data + 4);
5546 if (nimages == 0) /* we can assume we can't have an empty image file ? */
5550 if (data[6 + 3] != 0)
5553 guint16 planes = GST_READ_UINT16_LE (data + 6 + 4);
5557 size = GST_READ_UINT32_LE (data + 6 + 8);
5558 offset = GST_READ_UINT32_LE (data + 6 + 12);
5559 if (offset < 0 || size <= 0 || size >= datalen || offset >= datalen
5560 || size + offset > datalen)
5563 gst_type_find_suggest_empty_simple (find, GST_TYPE_FIND_NEARLY_CERTAIN,
5567 /*** WAP WBMP typefinder ***/
5570 wbmp_typefind (GstTypeFind * find, gpointer user_data)
5576 /* http://en.wikipedia.org/wiki/Wireless_Application_Protocol_Bitmap_Format */
5577 datalen = gst_type_find_get_length (find);
5581 data = gst_type_find_peek (find, 0, 5);
5585 /* want 0x00 0x00 at start */
5586 if (*data++ != 0 || *data++ != 0)
5589 /* min header size */
5592 /* let's assume max width/height is 65536 */
5595 w = (w << 8) | *data++;
5599 data = gst_type_find_peek (find, 4, 2);
5605 h = (h << 8) | *data++;
5611 if (w == 0 || h == 0)
5614 /* now add bitmap size */
5615 size += h * (GST_ROUND_UP_8 (w) / 8);
5617 if (datalen == size) {
5618 gst_type_find_suggest_empty_simple (find, GST_TYPE_FIND_POSSIBLE - 10,
5619 "image/vnd.wap.wbmp");
5623 /*** DEGAS Atari images (also to avoid false positives, see #625129) ***/
5625 degas_type_find (GstTypeFind * tf, gpointer private)
5627 /* No magic, but it should have a fixed size and a few invalid values */
5628 /* http://www.fileformat.info/format/atari/spec/6ecf9f6eb5be494284a47feb8a214687/view.htm */
5634 len = gst_type_find_get_length (tf);
5635 if (len < 34) /* smallest header of the lot */
5637 data = gst_type_find_peek (tf, 0, 4);
5638 if (G_UNLIKELY (data == NULL))
5640 resolution = GST_READ_UINT16_BE (data);
5642 /* could be DEGAS */
5643 if (resolution <= 2)
5644 gst_type_find_suggest_empty_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
5646 } else if (len == 32066) {
5647 /* could be DEGAS Elite */
5648 if (resolution <= 2) {
5649 data = gst_type_find_peek (tf, len - 16, 8);
5650 if (G_UNLIKELY (data == NULL))
5652 for (n = 0; n < 4; n++) {
5653 if (GST_READ_UINT16_BE (data + n * 2) > 2)
5656 gst_type_find_suggest_empty_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
5659 } else if (len >= 66 && len < 32066) {
5660 /* could be compressed DEGAS Elite, but it's compressed and so we can't rely on size,
5661 it does have 4 16 bytes values near the end that are 0-2 though. */
5662 if ((resolution & 0x8000) && (resolution & 0x7fff) <= 2) {
5663 data = gst_type_find_peek (tf, len - 16, 8);
5664 if (G_UNLIKELY (data == NULL))
5666 for (n = 0; n < 4; n++) {
5667 if (GST_READ_UINT16_BE (data + n * 2) > 2)
5670 gst_type_find_suggest_empty_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
5679 y4m_typefind (GstTypeFind * tf, gpointer private)
5683 data = gst_type_find_peek (tf, 0, 10);
5684 if (data != NULL && memcmp (data, "YUV4MPEG2 ", 10) == 0) {
5685 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY,
5686 "application/x-yuv4mpeg", "y4mversion", G_TYPE_INT, 2, NULL);
5691 /*** DVD ISO images (looks like H.264, see #674069) ***/
5693 dvdiso_type_find (GstTypeFind * tf, gpointer private)
5695 /* 0x8000 bytes of zeros, then "\001CD001" */
5699 len = gst_type_find_get_length (tf);
5702 data = gst_type_find_peek (tf, 0, 0x8006);
5703 if (G_UNLIKELY (data == NULL))
5705 for (len = 0; len < 0x8000; len++)
5708 /* Can the '1' be anything else ? My three samples all have '1'. */
5709 if (memcmp (data + 0x8000, "\001CD001", 6))
5712 /* May need more inspection, we may be able to demux some of them */
5713 gst_type_find_suggest_empty_simple (tf, GST_TYPE_FIND_LIKELY,
5714 "application/octet-stream");
5717 /* SSA/ASS subtitles
5719 * http://en.wikipedia.org/wiki/SubStation_Alpha
5720 * http://matroska.org/technical/specs/subtitles/ssa.html
5723 ssa_type_find (GstTypeFind * tf, gpointer private)
5725 const gchar *start, *end, *ver_str, *media_type = NULL;
5727 gchar *str, *script_type, *p = NULL;
5730 data = gst_type_find_peek (tf, 0, 32);
5735 /* FIXME: detect utf-16/32 BOM and convert before typefinding the rest */
5737 /* there might be a UTF-8 BOM at the beginning */
5738 if (memcmp (data, "[Script Info]", 13) != 0 &&
5739 memcmp (data + 3, "[Script Info]", 13) != 0) {
5743 /* now check if we have SSA or ASS */
5744 len = gst_type_find_get_length (tf);
5748 data = gst_type_find_peek (tf, 0, len);
5753 start = (gchar *) memchr (data, '[', 5);
5755 len -= (start - (gchar *) data);
5757 /* ignore anything non-UTF8 for now, in future we might at least allow
5758 * other UTF variants that are clearly prefixed with the appropriate BOM */
5759 if (!g_utf8_validate (start, len, &end) && (len - (end - start)) > 6) {
5760 GST_FIXME ("non-UTF8 SSA/ASS file");
5764 /* something at start, but not a UTF-8 BOM? */
5765 if (data[0] != '[' && (data[0] != 0xEF || data[1] != 0xBB || data[2] != 0xBF))
5768 /* ignore any partial UTF-8 characters at the end */
5771 /* create a NUL-terminated string so it's easier to process it safely */
5772 str = g_strndup (start, len - 1);
5773 script_type = strstr (str, "ScriptType:");
5774 if (script_type != NULL) {
5777 ver_str = script_type + 11;
5778 while (*ver_str == ' ' || *ver_str == 'v' || *ver_str == 'V')
5780 version = g_ascii_strtod (ver_str, &p);
5781 if (version == 4.0 && p != NULL && *p == '+')
5782 media_type = "application/x-ass";
5783 else if (version >= 1.0 && version <= 4.0)
5784 media_type = "application/x-ssa";
5787 if (media_type == NULL) {
5788 if (strstr (str, "[v4+ Styles]") || strstr (str, "[V4+ Styles]"))
5789 media_type = "application/x-ass";
5790 else if (strstr (str, "[v4 Styles]") || strstr (str, "[V4 Styles]"))
5791 media_type = "application/x-ssa";
5794 if (media_type != NULL) {
5795 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
5796 media_type, "parsed", G_TYPE_BOOLEAN, FALSE, NULL);
5798 GST_WARNING ("could not detect SSA/ASS variant");
5804 /*** application/x-mcc ***/
5805 static GstStaticCaps mcc_caps = GST_STATIC_CAPS ("application/x-mcc");
5807 #define MCC_CAPS gst_static_caps_get(&mcc_caps)
5810 mcc_type_find (GstTypeFind * tf, gpointer private)
5814 data = gst_type_find_peek (tf, 0, 31);
5819 /* MCC files always start with this followed by the version */
5820 if (memcmp (data, "File Format=MacCaption_MCC V", 28) != 0 ||
5821 !g_ascii_isdigit (data[28]) || data[29] != '.' ||
5822 !g_ascii_isdigit (data[30])) {
5826 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
5827 "application/x-mcc", "version", G_TYPE_INT, data[28] - '0', NULL);
5830 /*** video/x-pva ***/
5832 static GstStaticCaps pva_caps = GST_STATIC_CAPS ("video/x-pva");
5834 #define PVA_CAPS gst_static_caps_get(&pva_caps)
5837 pva_type_find (GstTypeFind * tf, gpointer private)
5841 data = gst_type_find_peek (tf, 0, 5);
5846 if (data[0] == 'A' && data[1] == 'V' && data[2] < 3 && data[4] == 0x55)
5847 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, PVA_CAPS);
5850 /*** audio/audible ***/
5852 /* derived from pyaudibletags
5853 * http://code.google.com/p/pyaudibletags/source/browse/trunk/pyaudibletags.py
5855 static GstStaticCaps aa_caps = GST_STATIC_CAPS ("audio/x-audible");
5857 #define AA_CAPS gst_static_caps_get(&aa_caps)
5860 aa_type_find (GstTypeFind * tf, gpointer private)
5864 data = gst_type_find_peek (tf, 0, 12);
5868 if (GST_READ_UINT32_BE (data + 4) == 0x57907536) {
5871 media_len = gst_type_find_get_length (tf);
5872 if (media_len > 0 && GST_READ_UINT32_BE (data) == media_len)
5873 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AA_CAPS);
5875 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AA_CAPS);
5879 /*Type find definition by functions */
5880 GST_TYPE_FIND_REGISTER_DEFINE (musepack, "audio/x-musepack", GST_RANK_PRIMARY,
5881 musepack_type_find, "mpc,mpp,mp+", MUSEPACK_CAPS, NULL, NULL);
5882 GST_TYPE_FIND_REGISTER_DEFINE (au, "audio/x-au", GST_RANK_MARGINAL,
5883 au_type_find, "au,snd", AU_CAPS, NULL, NULL);
5885 GST_TYPE_FIND_REGISTER_DEFINE (mcc, "application/x-mcc", GST_RANK_PRIMARY,
5886 mcc_type_find, "mcc", MCC_CAPS, NULL, NULL);
5888 GST_TYPE_FIND_REGISTER_START_WITH_DEFINE (smoke, "video/x-smoke",
5889 GST_RANK_PRIMARY, NULL, "\x80smoke\x00\x01\x00", 6, GST_TYPE_FIND_MAXIMUM);
5891 GST_TYPE_FIND_REGISTER_DEFINE (mid, "audio/midi", GST_RANK_PRIMARY,
5892 mid_type_find, "mid,midi", MID_CAPS, NULL, NULL);
5893 GST_TYPE_FIND_REGISTER_DEFINE (mxmf, "audio/mobile-xmf", GST_RANK_PRIMARY,
5894 mxmf_type_find, "mxmf", MXMF_CAPS, NULL, NULL);
5895 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5896 GST_TYPE_FIND_REGISTER_DEFINE (flx, "video/x-fli", GST_RANK_MARGINAL,
5897 flx_type_find, "flc,fli", FLX_CAPS, NULL, NULL);
5899 GST_TYPE_FIND_REGISTER_DEFINE (id3v2, "application/x-id3v2",
5900 GST_RANK_PRIMARY + 103, id3v2_type_find, "mp3,mp2,mp1,mpga,ogg,flac,tta",
5901 ID3_CAPS, NULL, NULL);
5902 GST_TYPE_FIND_REGISTER_DEFINE (id3v1, "application/x-id3v1",
5903 GST_RANK_PRIMARY + 101, id3v1_type_find, "mp3,mp2,mp1,mpga,ogg,flac,tta",
5904 ID3_CAPS, NULL, NULL);
5905 GST_TYPE_FIND_REGISTER_DEFINE (apetag, "application/x-apetag",
5906 GST_RANK_PRIMARY + 102, apetag_type_find, "mp3,ape,mpc,wv", APETAG_CAPS,
5908 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5909 GST_TYPE_FIND_REGISTER_DEFINE (tta, "audio/x-ttafile", GST_RANK_PRIMARY,
5910 tta_type_find, "tta", TTA_CAPS, NULL, NULL);
5911 GST_TYPE_FIND_REGISTER_DEFINE (mod, "audio/x-mod", GST_RANK_SECONDARY,
5913 "669,amf,ams,dbm,digi,dmf,dsm,gdm,far,imf,it,j2b,mdl,med,mod,mt2,mtm,"
5914 "okt,psm,ptm,sam,s3m,stm,stx,ult,umx,xm", MOD_CAPS, NULL, NULL);
5916 GST_TYPE_FIND_REGISTER_DEFINE (mp3, "audio/mpeg", GST_RANK_PRIMARY,
5917 mp3_type_find, "mp3,mp2,mp1,mpga", MP3_CAPS, NULL, NULL);
5918 GST_TYPE_FIND_REGISTER_DEFINE (ac3, "audio/x-ac3", GST_RANK_PRIMARY,
5919 ac3_type_find, "ac3,eac3", AC3_CAPS, NULL, NULL);
5920 GST_TYPE_FIND_REGISTER_DEFINE (dts, "audio/x-dts", GST_RANK_SECONDARY,
5921 dts_type_find, "dts", DTS_CAPS, NULL, NULL);
5922 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5923 GST_TYPE_FIND_REGISTER_DEFINE (gsm, "audio/x-gsm", GST_RANK_PRIMARY, NULL,
5924 "gsm", GSM_CAPS, NULL, NULL);
5926 #ifdef TIZEN_PROFILE_TV
5927 GST_TYPE_FIND_REGISTER_DEFINE (mpeg_sys, "video/mpeg-sys", GST_RANK_PRIMARY,
5928 mpeg_sys_type_find, "mpe,mpeg,mpg", MPEG_SYS_CAPS, NULL, NULL);
5930 GST_TYPE_FIND_REGISTER_DEFINE (mpeg_ts, "video/mpegts", GST_RANK_PRIMARY,
5931 mpeg_ts_type_find, "ts,mts", MPEGTS_CAPS, NULL, NULL);
5932 GST_TYPE_FIND_REGISTER_DEFINE (ogganx, "application/ogg", GST_RANK_PRIMARY,
5933 ogganx_type_find, "ogg,oga,ogv,ogm,ogx,spx,anx,axa,axv", OGG_CAPS, NULL,
5935 GST_TYPE_FIND_REGISTER_DEFINE (mpeg_video_stream, "video/mpeg-elementary",
5936 GST_RANK_MARGINAL, mpeg_video_stream_type_find, "mpv,mpeg,mpg",
5937 MPEG_VIDEO_CAPS, NULL, NULL);
5938 GST_TYPE_FIND_REGISTER_DEFINE (mpeg4_video, "video/mpeg4", GST_RANK_PRIMARY,
5939 mpeg4_video_type_find, "m4v", MPEG_VIDEO_CAPS, NULL, NULL);
5940 GST_TYPE_FIND_REGISTER_DEFINE (h263_video, "video/x-h263", GST_RANK_SECONDARY,
5941 h263_video_type_find, "h263,263", H263_VIDEO_CAPS, NULL, NULL);
5942 GST_TYPE_FIND_REGISTER_DEFINE (h264_video, "video/x-h264", GST_RANK_PRIMARY,
5943 h264_video_type_find, "h264,x264,264", H264_VIDEO_CAPS, NULL, NULL);
5944 GST_TYPE_FIND_REGISTER_DEFINE (h265_video, "video/x-h265", GST_RANK_PRIMARY,
5945 h265_video_type_find, "h265,x265,265", H265_VIDEO_CAPS, NULL, NULL);
5946 GST_TYPE_FIND_REGISTER_DEFINE (nuv, "video/x-nuv", GST_RANK_SECONDARY,
5947 nuv_type_find, "nuv", NUV_CAPS, NULL, NULL);
5949 GST_TYPE_FIND_REGISTER_DEFINE (m4a, "audio/x-m4a", GST_RANK_PRIMARY,
5950 m4a_type_find, "m4a", M4A_CAPS, NULL, NULL);
5951 GST_TYPE_FIND_REGISTER_DEFINE (q3gp, "application/x-3gp", GST_RANK_PRIMARY,
5952 q3gp_type_find, "3gp", Q3GP_CAPS, NULL, NULL);
5953 GST_TYPE_FIND_REGISTER_DEFINE (qt, "video/quicktime", GST_RANK_PRIMARY,
5954 qt_type_find, "mov,mp4", QT_CAPS, NULL, NULL);
5955 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5956 GST_TYPE_FIND_REGISTER_DEFINE (qtif, "image/x-quicktime", GST_RANK_SECONDARY,
5957 qtif_type_find, "qif,qtif,qti", QTIF_CAPS, NULL, NULL);
5958 GST_TYPE_FIND_REGISTER_DEFINE (jp2, "image/jp2", GST_RANK_PRIMARY,
5959 jp2_type_find, "jp2", JP2_CAPS, NULL, NULL);
5960 GST_TYPE_FIND_REGISTER_DEFINE (jpc, "image/x-jpc", GST_RANK_PRIMARY,
5961 jpc_type_find, "jpc,j2k", JPC_CAPS, NULL, NULL);
5962 GST_TYPE_FIND_REGISTER_DEFINE (mj2, "video/mj2", GST_RANK_PRIMARY,
5963 jp2_type_find, "mj2", MJ2_CAPS, NULL, NULL);
5964 GST_TYPE_FIND_REGISTER_DEFINE (html, "text/html", GST_RANK_SECONDARY,
5965 html_type_find, "htm,html", HTML_CAPS, NULL, NULL);
5966 GST_TYPE_FIND_REGISTER_DEFINE (swf, "application/x-shockwave-flash",
5967 GST_RANK_SECONDARY, swf_type_find, "swf,swfl", SWF_CAPS, NULL, NULL);
5969 GST_TYPE_FIND_REGISTER_DEFINE (xges, "application/xges",
5970 GST_RANK_PRIMARY, xges_type_find, "xges", XGES_CAPS, NULL, NULL);
5971 GST_TYPE_FIND_REGISTER_DEFINE (xmeml, "application/vnd.apple-xmeml+xml",
5972 GST_RANK_SECONDARY, xmeml_type_find, "xmeml", XMEML_CAPS, NULL, NULL);
5973 GST_TYPE_FIND_REGISTER_DEFINE (fcpxml, "application/vnd.apple-fcp+xml",
5974 GST_RANK_SECONDARY, fcpxml_type_find, "fcpxml", FCPXML_CAPS, NULL, NULL);
5975 GST_TYPE_FIND_REGISTER_DEFINE (otio,
5976 "application/vnd.pixar.opentimelineio+json", GST_RANK_SECONDARY,
5977 otio_type_find, "otio", OTIO_CAPS, NULL, NULL);
5978 GST_TYPE_FIND_REGISTER_DEFINE (dash_mpd, "application/dash+xml",
5979 GST_RANK_PRIMARY, dash_mpd_type_find, "mpd,MPD", DASH_CAPS, NULL, NULL);
5980 GST_TYPE_FIND_REGISTER_DEFINE (mss_manifest, "application/vnd.ms-sstr+xml",
5981 GST_RANK_PRIMARY, mss_manifest_type_find, NULL, MSS_MANIFEST_CAPS, NULL,
5983 GST_TYPE_FIND_REGISTER_DEFINE (utf8, "text/plain", GST_RANK_MARGINAL,
5984 utf8_type_find, "txt", UTF8_CAPS, NULL, NULL);
5985 GST_TYPE_FIND_REGISTER_DEFINE (utf16, "text/utf-16", GST_RANK_MARGINAL,
5986 utf16_type_find, "txt", UTF16_CAPS, NULL, NULL);
5987 GST_TYPE_FIND_REGISTER_DEFINE (utf32, "text/utf-32", GST_RANK_MARGINAL,
5988 utf32_type_find, "txt", UTF32_CAPS, NULL, NULL);
5989 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
5990 GST_TYPE_FIND_REGISTER_DEFINE (uri, "text/uri-list", GST_RANK_MARGINAL,
5991 uri_type_find, "ram", URI_CAPS, NULL, NULL);
5993 GST_TYPE_FIND_REGISTER_DEFINE (itc, "application/itc", GST_RANK_SECONDARY,
5994 itc_type_find, "itc", ITC_CAPS, NULL, NULL);
5995 GST_TYPE_FIND_REGISTER_DEFINE (hls, "application/x-hls", GST_RANK_MARGINAL,
5996 hls_type_find, "m3u8", HLS_CAPS, NULL, NULL);
5997 GST_TYPE_FIND_REGISTER_DEFINE (sdp, "application/sdp", GST_RANK_SECONDARY,
5998 sdp_type_find, "sdp", SDP_CAPS, NULL, NULL);
5999 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6000 GST_TYPE_FIND_REGISTER_DEFINE (smil, "application/smil", GST_RANK_SECONDARY,
6001 smil_type_find, "smil", SMIL_CAPS, NULL, NULL);
6002 GST_TYPE_FIND_REGISTER_DEFINE (ttml_xml, "application/ttml+xml",
6003 GST_RANK_SECONDARY, ttml_xml_type_find, "ttml+xml", TTML_XML_CAPS, NULL,
6005 GST_TYPE_FIND_REGISTER_DEFINE (xml, "application/xml", GST_RANK_MARGINAL,
6006 xml_type_find, "xml", GENERIC_XML_CAPS, NULL, NULL);
6008 GST_TYPE_FIND_REGISTER_DEFINE (aiff, "audio/x-aiff", GST_RANK_SECONDARY,
6009 aiff_type_find, "aiff,aif,aifc", AIFF_CAPS, NULL, NULL);
6010 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6011 GST_TYPE_FIND_REGISTER_DEFINE (svx, "audio/x-svx", GST_RANK_SECONDARY,
6012 svx_type_find, "iff,svx", SVX_CAPS, NULL, NULL);
6013 GST_TYPE_FIND_REGISTER_DEFINE (paris, "audio/x-paris", GST_RANK_SECONDARY,
6014 paris_type_find, "paf", PARIS_CAPS, NULL, NULL);
6015 GST_TYPE_FIND_REGISTER_DEFINE (sds, "audio/x-sds", GST_RANK_SECONDARY,
6016 sds_type_find, "sds", SDS_CAPS, NULL, NULL);
6017 GST_TYPE_FIND_REGISTER_DEFINE (ircam, "audio/x-ircam", GST_RANK_SECONDARY,
6018 ircam_type_find, "sf", IRCAM_CAPS, NULL, NULL);
6019 GST_TYPE_FIND_REGISTER_DEFINE (shn, "audio/x-shorten", GST_RANK_SECONDARY,
6020 shn_type_find, "shn", SHN_CAPS, NULL, NULL);
6021 GST_TYPE_FIND_REGISTER_DEFINE (ape, "application/x-ape", GST_RANK_SECONDARY,
6022 ape_type_find, "ape", APE_CAPS, NULL, NULL);
6024 GST_TYPE_FIND_REGISTER_DEFINE (jpeg, "image/jpeg", GST_RANK_PRIMARY + 15,
6025 jpeg_type_find, "jpg,jpe,jpeg", JPEG_CAPS, NULL, NULL);
6026 GST_TYPE_FIND_REGISTER_DEFINE (bmp, "image/bmp", GST_RANK_PRIMARY,
6027 bmp_type_find, "bmp", BMP_CAPS, NULL, NULL);
6028 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6029 GST_TYPE_FIND_REGISTER_DEFINE (tiff, "image/tiff", GST_RANK_PRIMARY,
6030 tiff_type_find, "tif,tiff", TIFF_CAPS, NULL, NULL);
6032 GST_TYPE_FIND_REGISTER_DEFINE (exr, "image/x-exr", GST_RANK_PRIMARY,
6033 exr_type_find, "exr", EXR_CAPS, NULL, NULL);
6034 GST_TYPE_FIND_REGISTER_DEFINE (pnm, "image/x-portable-pixmap",
6035 GST_RANK_SECONDARY, pnm_type_find, "pnm,ppm,pgm,pbm", PNM_CAPS, NULL, NULL);
6036 GST_TYPE_FIND_REGISTER_DEFINE (matroska, "video/x-matroska", GST_RANK_PRIMARY,
6037 matroska_type_find, "mkv,mka,mk3d,webm", MATROSKA_CAPS, NULL, NULL);
6038 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6039 GST_TYPE_FIND_REGISTER_DEFINE (mxf, "application/mxf", GST_RANK_PRIMARY,
6040 mxf_type_find, "mxf", MXF_CAPS, NULL, NULL);
6041 GST_TYPE_FIND_REGISTER_DEFINE (dv, "video/x-dv", GST_RANK_SECONDARY,
6042 dv_type_find, "dv,dif", DV_CAPS, NULL, NULL);
6043 GST_TYPE_FIND_REGISTER_DEFINE (ilbc, "audio/iLBC-sh", GST_RANK_PRIMARY,
6044 ilbc_type_find, "ilbc", ILBC_CAPS, NULL, NULL);
6045 GST_TYPE_FIND_REGISTER_DEFINE (sbc, "audio/x-sbc", GST_RANK_MARGINAL,
6046 sbc_type_find, "sbc", SBC_CAPS, NULL, NULL);
6047 GST_TYPE_FIND_REGISTER_DEFINE (kate, "subtitle/x-kate", GST_RANK_MARGINAL,
6048 kate_type_find, NULL, NULL, NULL, NULL);
6050 GST_TYPE_FIND_REGISTER_DEFINE (webvtt, "application/x-subtitle-vtt",
6051 GST_RANK_MARGINAL, webvtt_type_find, "vtt", WEBVTT_CAPS, NULL, NULL);
6052 GST_TYPE_FIND_REGISTER_DEFINE (flac, "audio/x-flac", GST_RANK_PRIMARY,
6053 flac_type_find, "flac", FLAC_CAPS, NULL, NULL);
6054 GST_TYPE_FIND_REGISTER_DEFINE (vorbis, "audio/x-vorbis", GST_RANK_PRIMARY,
6055 vorbis_type_find, NULL, VORBIS_CAPS, NULL, NULL);
6056 GST_TYPE_FIND_REGISTER_DEFINE (theora, "video/x-theora", GST_RANK_PRIMARY,
6057 theora_type_find, NULL, THEORA_CAPS, NULL, NULL);
6058 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6059 GST_TYPE_FIND_REGISTER_DEFINE (ogmvideo, "application/x-ogm-video",
6060 GST_RANK_PRIMARY, ogmvideo_type_find, NULL, OGMVIDEO_CAPS, NULL, NULL);
6061 GST_TYPE_FIND_REGISTER_DEFINE (ogmaudio, "application/x-ogm-audio",
6062 GST_RANK_PRIMARY, ogmaudio_type_find, NULL, OGMAUDIO_CAPS, NULL, NULL);
6063 GST_TYPE_FIND_REGISTER_DEFINE (ogmtext, "application/x-ogm-text",
6064 GST_RANK_PRIMARY, ogmtext_type_find, NULL, OGMTEXT_CAPS, NULL, NULL);
6065 GST_TYPE_FIND_REGISTER_DEFINE (speex, "audio/x-speex", GST_RANK_PRIMARY,
6066 speex_type_find, NULL, SPEEX_CAPS, NULL, NULL);
6067 GST_TYPE_FIND_REGISTER_DEFINE (celt, "audio/x-celt", GST_RANK_PRIMARY,
6068 celt_type_find, NULL, CELT_CAPS, NULL, NULL);
6069 GST_TYPE_FIND_REGISTER_DEFINE (oggskel, "application/x-ogg-skeleton",
6070 GST_RANK_PRIMARY, oggskel_type_find, NULL, OGG_SKELETON_CAPS, NULL, NULL);
6071 GST_TYPE_FIND_REGISTER_DEFINE (cmml, "text/x-cmml", GST_RANK_PRIMARY,
6072 cmml_type_find, NULL, CMML_CAPS, NULL, NULL);
6074 GST_TYPE_FIND_REGISTER_DEFINE (aac, "audio/aac", GST_RANK_SECONDARY,
6075 aac_type_find, "aac,adts,adif,loas", AAC_CAPS, NULL, NULL);
6076 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6077 GST_TYPE_FIND_REGISTER_DEFINE (wavpack_wvp, "audio/x-wavpack",
6078 GST_RANK_SECONDARY, wavpack_type_find, "wv,wvp", WAVPACK_CAPS, NULL, NULL);
6079 GST_TYPE_FIND_REGISTER_DEFINE (wavpack_wvc, "audio/x-wavpack-correction",
6080 GST_RANK_SECONDARY, wavpack_type_find, "wvc", WAVPACK_CORRECTION_CAPS, NULL,
6082 GST_TYPE_FIND_REGISTER_DEFINE (postscript, "application/postscript",
6083 GST_RANK_SECONDARY, postscript_type_find, "ps", POSTSCRIPT_CAPS, NULL,
6085 GST_TYPE_FIND_REGISTER_DEFINE (svg, "image/svg+xml", GST_RANK_SECONDARY,
6086 svg_type_find, "svg", SVG_CAPS, NULL, NULL);
6087 GST_TYPE_FIND_REGISTER_DEFINE (tar, "application/x-tar", GST_RANK_SECONDARY,
6088 tar_type_find, "tar", TAR_CAPS, NULL, NULL);
6089 GST_TYPE_FIND_REGISTER_DEFINE (ar, "application/x-ar", GST_RANK_SECONDARY,
6090 ar_type_find, "a", AR_CAPS, NULL, NULL);
6091 GST_TYPE_FIND_REGISTER_DEFINE (msdos, "application/x-ms-dos-executable",
6092 GST_RANK_SECONDARY, msdos_type_find, "dll,exe,ocx,sys,scr,msstyles,cpl",
6093 MSDOS_CAPS, NULL, NULL);
6094 GST_TYPE_FIND_REGISTER_DEFINE (dirac, "video/x-dirac", GST_RANK_PRIMARY,
6095 dirac_type_find, NULL, DIRAC_CAPS, NULL, NULL);
6096 GST_TYPE_FIND_REGISTER_DEFINE (multipart, "multipart/x-mixed-replace",
6097 GST_RANK_SECONDARY, multipart_type_find, NULL, MULTIPART_CAPS, NULL, NULL);
6098 GST_TYPE_FIND_REGISTER_DEFINE (mmsh, "application/x-mmsh", GST_RANK_SECONDARY,
6099 mmsh_type_find, NULL, MMSH_CAPS, NULL, NULL);
6100 GST_TYPE_FIND_REGISTER_DEFINE (vivo, "video/vivo", GST_RANK_SECONDARY,
6101 vivo_type_find, "viv", VIVO_CAPS, NULL, NULL);
6102 GST_TYPE_FIND_REGISTER_DEFINE (wbmp, "image/vnd.wap.wbmp", GST_RANK_MARGINAL,
6103 wbmp_typefind, NULL, NULL, NULL, NULL);
6104 GST_TYPE_FIND_REGISTER_DEFINE (y4m, "application/x-yuv4mpeg",
6105 GST_RANK_SECONDARY, y4m_typefind, NULL, NULL, NULL, NULL);
6106 GST_TYPE_FIND_REGISTER_DEFINE (windows_icon, "image/x-icon", GST_RANK_MARGINAL,
6107 windows_icon_typefind, NULL, NULL, NULL, NULL);
6110 GST_TYPE_FIND_REGISTER_DEFINE (xdgmime, "xdgmime-base", GST_RANK_MARGINAL,
6111 xdgmime_typefind, NULL, NULL, NULL, NULL);
6113 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6114 GST_TYPE_FIND_REGISTER_DEFINE (degas, "image/x-degas", GST_RANK_MARGINAL,
6115 degas_type_find, NULL, NULL, NULL, NULL);
6117 GST_TYPE_FIND_REGISTER_DEFINE (dvdiso, "application/octet-stream",
6118 GST_RANK_MARGINAL, dvdiso_type_find, NULL, NULL, NULL, NULL);
6119 GST_TYPE_FIND_REGISTER_DEFINE (ssa, "application/x-ssa", GST_RANK_SECONDARY,
6120 ssa_type_find, "ssa,ass", NULL, NULL, NULL);
6121 GST_TYPE_FIND_REGISTER_DEFINE (pva, "video/x-pva", GST_RANK_SECONDARY,
6122 pva_type_find, "pva", PVA_CAPS, NULL, NULL);
6123 GST_TYPE_FIND_REGISTER_DEFINE (aa, "audio/audible", GST_RANK_MARGINAL,
6124 aa_type_find, "aa,aax", AA_CAPS, NULL, NULL);
6125 #ifndef TIZEN_FEATURE_DISABLE_MIME_TYPES
6126 GST_TYPE_FIND_REGISTER_DEFINE (tap, "audio/x-tap-tap", GST_RANK_PRIMARY,
6127 tap_type_find, "tap", TAP_CAPS, NULL, NULL);