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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 #include <glib/gprintf.h>
31 /* don't want to add gio xdgmime typefinder if gio was disabled via configure */
43 #include <gst/pbutils/pbutils.h>
44 #include <gst/base/gstbytereader.h>
46 GST_DEBUG_CATEGORY_STATIC (type_find_debug);
47 #define GST_CAT_DEFAULT type_find_debug
49 /* so our code stays ready for 0.11 */
50 #define gst_type_find_peek(tf,off,len) \
51 ((const guint8 *)gst_type_find_peek((tf),(off),(len)))
53 /* DataScanCtx: helper for typefind functions that scan through data
54 * step-by-step, to avoid doing a peek at each and every offset */
56 #define DATA_SCAN_CTX_CHUNK_SIZE 4096
66 data_scan_ctx_advance (GstTypeFind * tf, DataScanCtx * c, guint bytes_to_skip)
68 c->offset += bytes_to_skip;
69 if (G_LIKELY (c->size > bytes_to_skip)) {
70 c->size -= bytes_to_skip;
71 c->data += bytes_to_skip;
78 static inline gboolean
79 data_scan_ctx_ensure_data (GstTypeFind * tf, DataScanCtx * c, gint min_len)
83 guint chunk_len = MAX (DATA_SCAN_CTX_CHUNK_SIZE, min_len);
85 if (G_LIKELY (c->size >= min_len))
88 data = gst_type_find_peek (tf, c->offset, chunk_len);
89 if (G_LIKELY (data != NULL)) {
95 /* if there's less than our chunk size, try to get as much as we can, but
96 * always at least min_len bytes (we might be typefinding the first buffer
97 * of the stream and not have as much data available as we'd like) */
98 len = gst_type_find_get_length (tf);
100 len = CLAMP (len - c->offset, min_len, chunk_len);
105 data = gst_type_find_peek (tf, c->offset, len);
115 static inline gboolean
116 data_scan_ctx_memcmp (GstTypeFind * tf, DataScanCtx * c, guint offset,
117 const gchar * data, guint len)
119 if (!data_scan_ctx_ensure_data (tf, c, offset + len))
122 return (memcmp (c->data + offset, data, len) == 0);
126 static gboolean xml_check_first_element (GstTypeFind * tf,
127 const gchar * element, guint elen, gboolean strict);
128 static gboolean sdp_check_header (GstTypeFind * tf);
130 static GstStaticCaps utf8_caps = GST_STATIC_CAPS ("text/plain");
132 #define UTF8_CAPS gst_static_caps_get(&utf8_caps)
135 utf8_type_find_have_valid_utf8_at_offset (GstTypeFind * tf, guint64 offset,
136 GstTypeFindProbability * prob)
140 /* randomly decided values */
141 guint min_size = 16; /* minimum size */
142 guint size = 32 * 1024; /* starting size */
143 guint probability = 95; /* starting probability */
144 guint step = 10; /* how much we reduce probability in each
147 while (probability > step && size > min_size) {
148 data = gst_type_find_peek (tf, offset, size);
151 gchar *start = (gchar *) data;
153 if (g_utf8_validate (start, size, (const gchar **) &end) || (end - start + 4 > size)) { /* allow last char to be cut off */
168 utf8_type_find (GstTypeFind * tf, gpointer unused)
170 GstTypeFindProbability start_prob, mid_prob;
173 /* leave xml to the xml typefinders */
174 if (xml_check_first_element (tf, "", 0, TRUE))
177 /* leave sdp to the sdp typefinders */
178 if (sdp_check_header (tf))
181 /* check beginning of stream */
182 if (!utf8_type_find_have_valid_utf8_at_offset (tf, 0, &start_prob))
185 GST_LOG ("start is plain text with probability of %u", start_prob);
187 /* POSSIBLE is the highest probability we ever return if we can't
188 * probe into the middle of the file and don't know its length */
190 length = gst_type_find_get_length (tf);
191 if (length == 0 || length == (guint64) - 1) {
192 gst_type_find_suggest (tf, MIN (start_prob, GST_TYPE_FIND_POSSIBLE),
197 if (length < 64 * 1024) {
198 gst_type_find_suggest (tf, start_prob, UTF8_CAPS);
202 /* check middle of stream */
203 if (!utf8_type_find_have_valid_utf8_at_offset (tf, length / 2, &mid_prob))
206 GST_LOG ("middle is plain text with probability of %u", mid_prob);
207 gst_type_find_suggest (tf, (start_prob + mid_prob) / 2, UTF8_CAPS);
210 /*** text/utf-16 and text/utf-32} ***/
211 /* While UTF-8 is unicode too, using text/plain for UTF-16 and UTF-32
212 is going to break stuff. */
217 const char *const bom;
218 gboolean (*checker) (const guint8 *, gint, gint);
224 check_utf16 (const guint8 * data, gint len, gint endianness)
234 gst_byte_reader_init (&br, data, len);
236 /* test first for a single 16 bit value in the BMP */
237 if (endianness == G_BIG_ENDIAN)
238 gst_byte_reader_get_uint16_be (&br, &high);
240 gst_byte_reader_get_uint16_le (&br, &high);
241 if (high >= 0xD800 && high <= 0xDBFF) {
242 /* start of a surrogate pair */
246 if (endianness == G_BIG_ENDIAN)
247 gst_byte_reader_get_uint16_be (&br, &low);
249 gst_byte_reader_get_uint16_le (&br, &low);
250 if (low >= 0xDC00 && low <= 0xDFFF) {
251 /* second half of the surrogate pair */
255 if (high >= 0xDC00 && high <= 0xDFFF)
264 check_utf32 (const guint8 * data, gint len, gint endianness)
270 if (endianness == G_BIG_ENDIAN)
271 v = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
273 v = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0];
283 unicode_type_find (GstTypeFind * tf, const GstUnicodeTester * tester,
284 guint n_tester, const char *media_type)
288 const guint8 *data = gst_type_find_peek (tf, 0, len);
290 const gint max_scan_size = 256 * 1024;
295 data = gst_type_find_peek (tf, 0, len);
300 /* find a large enough size that works */
301 while (len < max_scan_size) {
302 size_t newlen = len << 1;
303 const guint8 *newdata = gst_type_find_peek (tf, 0, newlen);
310 for (n = 0; n < n_tester; ++n) {
311 int bom_boost = 0, tmpprob;
312 if (len >= tester[n].bomlen) {
313 if (!memcmp (data, tester[n].bom, tester[n].bomlen))
314 bom_boost = tester[n].boost;
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),
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),
363 /*** text/uri-list ***/
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; \
381 uri_type_find (GstTypeFind * tf, gpointer unused)
383 const guint8 *data = gst_type_find_peek (tf, 0, BUFFER_SIZE);
388 /* Search for # comment lines */
389 while (*data == '#') {
390 /* Goto end of line */
391 while (*data != '\n') {
398 if (!g_ascii_isalpha (*data)) {
399 /* Had a non alpha char - can't be uri-list */
405 while (g_ascii_isalnum (*data)) {
410 /* First non alpha char is not a : */
414 /* Get the next 2 bytes as well */
415 data = gst_type_find_peek (tf, offset + pos, 3);
419 if (data[1] != '/' && data[2] != '/') {
423 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, URI_CAPS);
427 /*** application/x-hls ***/
429 static GstStaticCaps hls_caps = GST_STATIC_CAPS ("application/x-hls");
430 #define HLS_CAPS (gst_static_caps_get(&hls_caps))
432 /* See http://tools.ietf.org/html/draft-pantos-http-live-streaming-05 */
434 hls_type_find (GstTypeFind * tf, gpointer unused)
436 DataScanCtx c = { 0, NULL, 0 };
438 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 7)))
441 if (memcmp (c.data, "#EXTM3U", 7))
444 data_scan_ctx_advance (tf, &c, 7);
446 /* Check only the first 256 bytes */
447 while (c.offset < 256) {
448 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 21)))
451 /* Search for # comment lines */
452 if (c.data[0] == '#' && (memcmp (c.data, "#EXT-X-TARGETDURATION", 21) == 0
453 || memcmp (c.data, "#EXT-X-STREAM-INF", 17) == 0)) {
454 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HLS_CAPS);
458 data_scan_ctx_advance (tf, &c, 1);
463 /*** application/xml **********************************************************/
465 #define XML_BUFFER_SIZE 16
466 #define XML_INC_BUFFER { \
468 if (pos == XML_BUFFER_SIZE) { \
470 offset += XML_BUFFER_SIZE; \
471 data = gst_type_find_peek (tf, offset, XML_BUFFER_SIZE); \
472 if (data == NULL) return FALSE; \
479 xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen,
487 data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE);
491 /* look for the XMLDec
492 * see XML spec 2.8, Prolog and Document Type Declaration
493 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
494 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
496 if (strict && !got_xmldec)
499 /* skip XMLDec in any case if we've got one */
505 /* look for the first element, it has to be the requested element. Bail
506 * out if it is not within the first 4kB. */
507 while (data && (offset + pos) < 4096) {
508 while (*data != '<' && (offset + pos) < 4096) {
513 if (!g_ascii_isalpha (*data)) {
514 /* if not alphabetic, it's a PI or an element / attribute declaration
515 * like <?xxx or <!xxx */
520 /* the first normal element, check if it's the one asked for */
521 data = gst_type_find_peek (tf, offset + pos, elen + 1);
522 return (data && element && strncmp ((char *) data, element, elen) == 0);
528 static GstStaticCaps generic_xml_caps = GST_STATIC_CAPS ("application/xml");
530 #define GENERIC_XML_CAPS (gst_static_caps_get(&generic_xml_caps))
532 xml_type_find (GstTypeFind * tf, gpointer unused)
534 if (xml_check_first_element (tf, "", 0, TRUE)) {
535 gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, GENERIC_XML_CAPS);
539 /*** application/sdp *********************************************************/
541 static GstStaticCaps sdp_caps = GST_STATIC_CAPS ("application/sdp");
543 #define SDP_CAPS (gst_static_caps_get(&sdp_caps))
545 sdp_check_header (GstTypeFind * tf)
549 data = gst_type_find_peek (tf, 0, 5);
553 /* sdp must start with v=0[\r]\n */
554 if (memcmp (data, "v=0", 3))
557 if (data[3] == '\r' && data[4] == '\n')
566 sdp_type_find (GstTypeFind * tf, gpointer unused)
568 if (sdp_check_header (tf))
569 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDP_CAPS);
572 /*** application/smil *********************************************************/
574 static GstStaticCaps smil_caps = GST_STATIC_CAPS ("application/smil");
576 #define SMIL_CAPS (gst_static_caps_get(&smil_caps))
578 smil_type_find (GstTypeFind * tf, gpointer unused)
580 if (xml_check_first_element (tf, "smil", 4, FALSE)) {
581 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SMIL_CAPS);
587 static GstStaticCaps html_caps = GST_STATIC_CAPS ("text/html");
589 #define HTML_CAPS gst_static_caps_get (&html_caps)
592 html_type_find (GstTypeFind * tf, gpointer unused)
594 const gchar *d, *data;
596 data = (const gchar *) gst_type_find_peek (tf, 0, 16);
600 if (!g_ascii_strncasecmp (data, "<!DOCTYPE HTML", 14)) {
601 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
602 } else if (xml_check_first_element (tf, "html", 4, FALSE)) {
603 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
604 } else if ((d = memchr (data, '<', 16))) {
605 data = (const gchar *) gst_type_find_peek (tf, d - data, 6);
606 if (data && g_ascii_strncasecmp (data, "<html>", 6) == 0) {
607 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
614 static GstStaticCaps mid_caps = GST_STATIC_CAPS ("audio/midi");
616 #define MID_CAPS gst_static_caps_get(&mid_caps)
618 mid_type_find (GstTypeFind * tf, gpointer unused)
620 const guint8 *data = gst_type_find_peek (tf, 0, 4);
622 /* http://jedi.ks.uiuc.edu/~johns/links/music/midifile.html */
623 if (data && data[0] == 'M' && data[1] == 'T' && data[2] == 'h'
625 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MID_CAPS);
628 /*** audio/mobile-xmf ***/
630 static GstStaticCaps mxmf_caps = GST_STATIC_CAPS ("audio/mobile-xmf");
632 #define MXMF_CAPS gst_static_caps_get(&mxmf_caps)
634 mxmf_type_find (GstTypeFind * tf, gpointer unused)
636 const guint8 *data = NULL;
638 /* Search FileId "XMF_" 4 bytes */
639 data = gst_type_find_peek (tf, 0, 4);
640 if (data && data[0] == 'X' && data[1] == 'M' && data[2] == 'F'
642 /* Search Format version "2.00" 4 bytes */
643 data = gst_type_find_peek (tf, 4, 4);
644 if (data && data[0] == '2' && data[1] == '.' && data[2] == '0'
646 /* Search TypeId 2 1 byte */
647 data = gst_type_find_peek (tf, 11, 1);
648 if (data && data[0] == 2) {
649 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXMF_CAPS);
656 /*** video/x-fli ***/
658 static GstStaticCaps flx_caps = GST_STATIC_CAPS ("video/x-fli");
660 #define FLX_CAPS gst_static_caps_get(&flx_caps)
662 flx_type_find (GstTypeFind * tf, gpointer unused)
664 const guint8 *data = gst_type_find_peek (tf, 0, 134);
667 /* check magic and the frame type of the first frame */
668 if ((data[4] == 0x11 || data[4] == 0x12 ||
669 data[4] == 0x30 || data[4] == 0x44) &&
671 ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1)) {
672 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLX_CAPS);
676 data = gst_type_find_peek (tf, 0, 6);
678 /* check magic only */
679 if ((data[4] == 0x11 || data[4] == 0x12 ||
680 data[4] == 0x30 || data[4] == 0x44) && data[5] == 0xaf) {
681 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, FLX_CAPS);
687 /*** application/x-id3 ***/
689 static GstStaticCaps id3_caps = GST_STATIC_CAPS ("application/x-id3");
691 #define ID3_CAPS gst_static_caps_get(&id3_caps)
693 id3v2_type_find (GstTypeFind * tf, gpointer unused)
695 const guint8 *data = gst_type_find_peek (tf, 0, 10);
697 if (data && memcmp (data, "ID3", 3) == 0 &&
698 data[3] != 0xFF && data[4] != 0xFF &&
699 (data[6] & 0x80) == 0 && (data[7] & 0x80) == 0 &&
700 (data[8] & 0x80) == 0 && (data[9] & 0x80) == 0) {
701 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
706 id3v1_type_find (GstTypeFind * tf, gpointer unused)
708 const guint8 *data = gst_type_find_peek (tf, -128, 3);
710 if (data && memcmp (data, "TAG", 3) == 0) {
711 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
715 /*** application/x-ape ***/
717 static GstStaticCaps apetag_caps = GST_STATIC_CAPS ("application/x-apetag");
719 #define APETAG_CAPS gst_static_caps_get(&apetag_caps)
721 apetag_type_find (GstTypeFind * tf, gpointer unused)
725 /* APEv1/2 at start of file */
726 data = gst_type_find_peek (tf, 0, 8);
727 if (data && !memcmp (data, "APETAGEX", 8)) {
728 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
732 /* APEv1/2 at end of file */
733 data = gst_type_find_peek (tf, -32, 8);
734 if (data && !memcmp (data, "APETAGEX", 8)) {
735 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
740 /*** audio/x-ttafile ***/
742 static GstStaticCaps tta_caps = GST_STATIC_CAPS ("audio/x-ttafile");
744 #define TTA_CAPS gst_static_caps_get(&tta_caps)
746 tta_type_find (GstTypeFind * tf, gpointer unused)
748 const guint8 *data = gst_type_find_peek (tf, 0, 3);
751 if (memcmp (data, "TTA", 3) == 0) {
752 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTA_CAPS);
758 /*** audio/x-flac ***/
759 static GstStaticCaps flac_caps = GST_STATIC_CAPS ("audio/x-flac");
761 #define FLAC_CAPS (gst_static_caps_get(&flac_caps))
764 flac_type_find (GstTypeFind * tf, gpointer unused)
766 DataScanCtx c = { 0, NULL, 0 };
768 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
771 /* standard flac (also old/broken flac-in-ogg with an initial 4-byte marker
772 * packet and without the usual packet framing) */
773 if (memcmp (c.data, "fLaC", 4) == 0) {
774 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
778 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
781 /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */
782 if (memcmp (c.data, "\177FLAC\001", 6) == 0) {
783 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
787 /* disabled because it happily typefinds /dev/urandom as audio/x-flac, and
788 * because I yet have to see header-less flac in the wild */
790 /* flac without headers (subset format) */
791 /* 64K should be enough */
792 while (c.offset < (64 * 1024)) {
793 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
796 /* look for frame header,
797 * http://flac.sourceforge.net/format.html#frame_header
799 if (c.data[0] == 0xff && (c.data[1] >> 2) == 0x3e) {
800 /* bit 15 in the header must be 0 */
801 if (((c.data[1] >> 1) & 0x01) == 0x01)
804 /* blocksize must be != 0x00 */
805 if ((c.data[2] >> 4) == 0x00)
808 /* samplerate must be != 0x0f */
809 if ((c.data[2] & 0x0f) == 0x0f)
811 /* also 0 is invalid, as it means get the info from the header and we
812 * don't have headers if we are here */
813 if ((c.data[2] & 0x0f) == 0x00)
816 /* channel assignment must be < 11 */
817 if ((c.data[3] >> 4) >= 11)
820 /* sample size must be != 0x07 and != 0x05 */
821 if (((c.data[3] >> 1) & 0x07) == 0x07)
823 if (((c.data[3] >> 1) & 0x07) == 0x05)
825 /* also 0 is invalid, as it means get the info from the header and we
826 * don't have headers if we are here */
827 if (((c.data[3] >> 1) & 0x07) == 0x00)
830 /* next bit must be 0 */
831 if ((c.data[3] & 0x01) == 0x01)
834 /* FIXME: shouldn't we include the crc check ? */
836 GST_DEBUG ("Found flac without headers at %d", (gint) c.offset);
837 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, FLAC_CAPS);
841 data_scan_ctx_advance (tf, &c, 1);
846 /*** audio/mpeg version 2, 4 ***/
848 static GstStaticCaps aac_caps = GST_STATIC_CAPS ("audio/mpeg, "
849 "mpegversion = (int) { 2, 4 }, framed = (bool) false");
850 #define AAC_CAPS (gst_static_caps_get(&aac_caps))
851 #define AAC_AMOUNT (4096)
853 aac_type_find (GstTypeFind * tf, gpointer unused)
855 /* LUT to convert the AudioObjectType from the ADTS header to a string */
856 DataScanCtx c = { 0, NULL, 0 };
858 while (c.offset < AAC_AMOUNT) {
861 /* detect adts header or adif header.
862 * The ADIF header is 4 bytes, that should be OK. The ADTS header, on
863 * the other hand, is 14 bits only, so we require one valid frame with
864 * again a valid syncpoint on the next one (28 bits) for certainty. We
865 * require 4 kB, which is quite a lot, since frames are generally 200-400
867 * LOAS has 2 possible syncwords, which are 11 bits and 16 bits long.
868 * The following stream syntax depends on which one is found.
870 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
873 snc = GST_READ_UINT16_BE (c.data);
874 if (G_UNLIKELY ((snc & 0xfff6) == 0xfff0)) {
875 /* ADTS header - find frame length */
876 GST_DEBUG ("Found one ADTS syncpoint at offset 0x%" G_GINT64_MODIFIER
877 "x, tracing next...", c.offset);
878 len = ((c.data[3] & 0x03) << 11) |
879 (c.data[4] << 3) | ((c.data[5] & 0xe0) >> 5);
881 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
882 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
886 /* check if there's a second ADTS frame */
887 snc = GST_READ_UINT16_BE (c.data + len);
888 if ((snc & 0xfff6) == 0xfff0) {
890 guint mpegversion, sample_freq_idx, channel_config, profile_idx, rate;
891 guint8 audio_config[2];
893 mpegversion = (c.data[1] & 0x08) ? 2 : 4;
894 profile_idx = c.data[2] >> 6;
895 sample_freq_idx = ((c.data[2] & 0x3c) >> 2);
896 channel_config = ((c.data[2] & 0x01) << 2) + (c.data[3] >> 6);
898 GST_DEBUG ("Found second ADTS-%d syncpoint at offset 0x%"
899 G_GINT64_MODIFIER "x, framelen %u", mpegversion, c.offset, len);
901 /* 0xd and 0xe are reserved. 0xf means the sample frequency is directly
902 * specified in the header, but that's not allowed for ADTS */
903 if (sample_freq_idx > 0xc) {
904 GST_DEBUG ("Unexpected sample frequency index %d or wrong sync",
909 rate = gst_codec_utils_aac_get_sample_rate_from_index (sample_freq_idx);
910 GST_LOG ("ADTS: profile=%u, rate=%u", profile_idx, rate);
912 /* The ADTS frame header is slightly different from the
913 * AudioSpecificConfig defined for the MPEG-4 container, so we just
914 * construct enough of it for getting the level here. */
915 /* ADTS counts profiles from 0 instead of 1 to save bits */
916 audio_config[0] = (profile_idx + 1) << 3;
917 audio_config[0] |= (sample_freq_idx >> 1) & 0x7;
918 audio_config[1] = (sample_freq_idx & 0x1) << 7;
919 audio_config[1] |= (channel_config & 0xf) << 3;
921 caps = gst_caps_new_simple ("audio/mpeg",
922 "framed", G_TYPE_BOOLEAN, FALSE,
923 "mpegversion", G_TYPE_INT, mpegversion,
924 "stream-format", G_TYPE_STRING, "adts", NULL);
926 gst_codec_utils_aac_caps_set_level_and_profile (caps, audio_config, 2);
928 /* add rate and number of channels if we can */
929 if (channel_config != 0 && channel_config <= 7) {
930 const guint channels_map[] = { 0, 1, 2, 3, 4, 5, 6, 8 };
932 gst_caps_set_simple (caps, "channels", G_TYPE_INT,
933 channels_map[channel_config], "rate", G_TYPE_INT, rate, NULL);
936 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, caps);
937 gst_caps_unref (caps);
941 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
942 } else if (G_UNLIKELY (((snc & 0xffe0) == 0x56e0) || (snc == 0x4de1))) {
945 GST_DEBUG ("Found one LOAS syncword at offset 0x%" G_GINT64_MODIFIER
946 "x, tracing next...", c.offset);
948 /* check length of frame for each type of detectable LOAS streams */
950 /* EPAudioSyncStream */
951 len = ((c.data[2] & 0x0f) << 9) | (c.data[3] << 1) |
952 ((c.data[4] & 0x80) >> 7);
953 /* add size of EP sync stream header */
956 /* AudioSyncStream */
957 len = ((c.data[1] & 0x1f) << 8) | c.data[2];
958 /* add size of sync stream header */
962 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
963 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
967 /* check if there's a second LOAS frame */
968 snc = GST_READ_UINT16_BE (c.data + len);
969 if (((snc & 0xffe0) == 0x56e0) || (snc == 0x4de1)) {
970 GST_DEBUG ("Found second LOAS syncword at offset 0x%"
971 G_GINT64_MODIFIER "x, framelen %u", c.offset, len);
973 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
974 "framed", G_TYPE_BOOLEAN, FALSE,
975 "mpegversion", G_TYPE_INT, 4,
976 "stream-format", G_TYPE_STRING, "loas", NULL);
980 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
981 } else if (!memcmp (c.data, "ADIF", 4)) {
983 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
984 "framed", G_TYPE_BOOLEAN, FALSE, "mpegversion", G_TYPE_INT, 4,
985 "stream-format", G_TYPE_STRING, "adif", NULL);
991 data_scan_ctx_advance (tf, &c, 1);
995 /*** audio/mpeg version 1 ***/
998 * The chance that random data is identified as a valid mp3 header is 63 / 2^18
999 * (0.024%) per try. This makes the function for calculating false positives
1000 * 1 - (1 - ((63 / 2 ^18) ^ GST_MP3_TYPEFIND_MIN_HEADERS)) ^ buffersize)
1001 * This has the following probabilities of false positives:
1002 * datasize MIN_HEADERS
1004 * 4096 62.6% 0.02% 0% 0%
1005 * 16384 98% 0.09% 0% 0%
1006 * 1 MiB 100% 5.88% 0% 0%
1007 * 1 GiB 100% 100% 1.44% 0%
1008 * 1 TiB 100% 100% 100% 0.35%
1009 * This means that the current choice (3 headers by most of the time 4096 byte
1010 * buffers is pretty safe for now.
1012 * The max. size of each frame is 1440 bytes, which means that for N frames to
1013 * be detected, we need 1440 * GST_MP3_TYPEFIND_MIN_HEADERS + 3 bytes of data.
1014 * Assuming we step into the stream right after the frame header, this
1015 * means we need 1440 * (GST_MP3_TYPEFIND_MIN_HEADERS + 1) - 1 + 3 bytes
1016 * of data (5762) to always detect any mp3.
1019 static const guint mp3types_bitrates[2][3][16] =
1020 { {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
1021 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
1022 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
1023 {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
1024 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
1025 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}},
1028 static const guint mp3types_freqs[3][3] = { {11025, 12000, 8000},
1029 {22050, 24000, 16000},
1030 {44100, 48000, 32000}
1034 mp3_type_frame_length_from_header (guint32 header, guint * put_layer,
1035 guint * put_channels, guint * put_bitrate, guint * put_samplerate,
1036 gboolean * may_be_free_format, gint possible_free_framelen)
1038 guint bitrate, layer, length, mode, samplerate, version, channels;
1040 if ((header & 0xffe00000) != 0xffe00000)
1043 /* we don't need extension, copyright, original or
1044 * emphasis for the frame length */
1048 mode = header & 0x3;
1052 length = header & 0x1;
1055 /* sampling frequency */
1056 samplerate = header & 0x3;
1057 if (samplerate == 3)
1062 bitrate = header & 0xF;
1063 if (bitrate == 0 && possible_free_framelen == -1) {
1064 GST_LOG ("Possibly a free format mp3 - signalling");
1065 *may_be_free_format = TRUE;
1067 if (bitrate == 15 || (bitrate == 0 && possible_free_framelen == -1))
1070 /* ignore error correction, too */
1074 layer = 4 - (header & 0x3);
1079 /* version 0=MPEG2.5; 2=MPEG2; 3=MPEG1 */
1080 version = header & 0x3;
1085 channels = (mode == 3) ? 1 : 2;
1086 samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate];
1090 length += possible_free_framelen;
1091 bitrate = length * samplerate / 48000;
1093 length += possible_free_framelen;
1094 bitrate = length * samplerate /
1095 ((layer == 3 && version != 3) ? 72000 : 144000);
1099 bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate];
1101 length = ((12000 * bitrate / samplerate) + length) * 4;
1103 length += ((layer == 3
1104 && version != 3) ? 72000 : 144000) * bitrate / samplerate;
1108 GST_LOG ("mp3typefind: calculated mp3 frame length of %u bytes", length);
1110 ("mp3typefind: samplerate = %u - bitrate = %u - layer = %u - version = %u"
1111 " - channels = %u", samplerate, bitrate, layer, version, channels);
1116 *put_channels = channels;
1118 *put_bitrate = bitrate;
1120 *put_samplerate = samplerate;
1126 static GstStaticCaps mp3_caps = GST_STATIC_CAPS ("audio/mpeg, "
1127 "mpegversion = (int) 1, layer = (int) [ 1, 3 ]");
1128 #define MP3_CAPS (gst_static_caps_get(&mp3_caps))
1130 * random values for typefinding
1131 * if no more data is available, we will return a probability of
1132 * (found_headers/TRY_HEADERS) * (MAXIMUM * (TRY_SYNC - bytes_skipped)
1134 * if found_headers >= MIN_HEADERS
1136 #define GST_MP3_TYPEFIND_MIN_HEADERS (2)
1137 #define GST_MP3_TYPEFIND_TRY_HEADERS (5)
1138 #define GST_MP3_TYPEFIND_TRY_SYNC (GST_TYPE_FIND_MAXIMUM * 100) /* 10kB */
1139 #define GST_MP3_TYPEFIND_SYNC_SIZE (2048)
1140 #define GST_MP3_WRONG_HEADER (10)
1143 mp3_type_find_at_offset (GstTypeFind * tf, guint64 start_off,
1144 guint * found_layer, GstTypeFindProbability * found_prob)
1146 const guint8 *data = NULL;
1147 const guint8 *data_end = NULL;
1150 gint last_free_offset = -1;
1151 gint last_free_framelen = -1;
1152 gboolean headerstart = TRUE;
1159 while (skipped < GST_MP3_TYPEFIND_TRY_SYNC) {
1161 size = GST_MP3_TYPEFIND_SYNC_SIZE * 2;
1164 data = gst_type_find_peek (tf, skipped + start_off, size);
1165 } while (size > 10 && !data);
1168 data_end = data + size;
1170 if (*data == 0xFF) {
1171 const guint8 *head_data = NULL;
1172 guint layer = 0, bitrate, samplerate, channels;
1173 guint found = 0; /* number of valid headers found */
1174 guint64 offset = skipped;
1175 gboolean changed = FALSE;
1177 while (found < GST_MP3_TYPEFIND_TRY_HEADERS) {
1180 guint prev_layer = 0;
1181 guint prev_channels = 0, prev_samplerate = 0;
1182 gboolean free = FALSE;
1184 if ((gint64) (offset - skipped + 4) >= 0 &&
1185 data + offset - skipped + 4 < data_end) {
1186 head_data = data + offset - skipped;
1188 head_data = gst_type_find_peek (tf, offset + start_off, 4);
1192 head = GST_READ_UINT32_BE (head_data);
1193 if (!(length = mp3_type_frame_length_from_header (head, &layer,
1194 &channels, &bitrate, &samplerate, &free,
1195 last_free_framelen))) {
1197 if (last_free_offset == -1)
1198 last_free_offset = offset;
1200 last_free_framelen = offset - last_free_offset;
1201 offset = last_free_offset;
1205 last_free_framelen = -1;
1208 /* Mark the fact that we didn't find a valid header at the beginning */
1210 headerstart = FALSE;
1212 GST_LOG ("%d. header at offset %" G_GUINT64_FORMAT
1213 " (0x%" G_GINT64_MODIFIER "x) was not an mp3 header "
1214 "(possibly-free: %s)", found + 1, start_off + offset,
1215 start_off + offset, free ? "yes" : "no");
1218 if ((prev_layer && prev_layer != layer) ||
1219 /* (prev_bitrate && prev_bitrate != bitrate) || <-- VBR */
1220 (prev_samplerate && prev_samplerate != samplerate) ||
1221 (prev_channels && prev_channels != channels)) {
1222 /* this means an invalid property, or a change, which might mean
1223 * that this is not a mp3 but just a random bytestream. It could
1224 * be a freaking funky encoded mp3 though. We'll just not count
1229 prev_channels = channels;
1230 prev_samplerate = samplerate;
1233 GST_LOG ("found %d. header at offset %" G_GUINT64_FORMAT " (0x%"
1234 G_GINT64_MODIFIER "X)", found, start_off + offset,
1235 start_off + offset);
1239 g_assert (found <= GST_MP3_TYPEFIND_TRY_HEADERS);
1240 if (head_data == NULL &&
1241 gst_type_find_peek (tf, offset + start_off - 1, 1) == NULL)
1242 /* Incomplete last frame - don't count it. */
1244 if (found == GST_MP3_TYPEFIND_TRY_HEADERS ||
1245 (found >= GST_MP3_TYPEFIND_MIN_HEADERS && head_data == NULL)) {
1246 /* we can make a valid guess */
1247 guint probability = found * GST_TYPE_FIND_MAXIMUM *
1248 (GST_MP3_TYPEFIND_TRY_SYNC - skipped) /
1249 GST_MP3_TYPEFIND_TRY_HEADERS / GST_MP3_TYPEFIND_TRY_SYNC;
1252 && probability > (GST_TYPE_FIND_MINIMUM + GST_MP3_WRONG_HEADER))
1253 probability -= GST_MP3_WRONG_HEADER;
1254 if (probability < GST_TYPE_FIND_MINIMUM)
1255 probability = GST_TYPE_FIND_MINIMUM;
1259 probability = (probability + GST_TYPE_FIND_MAXIMUM) / 2;
1262 ("audio/mpeg calculated %u = %u * %u / %u * (%u - %"
1263 G_GUINT64_FORMAT ") / %u", probability, GST_TYPE_FIND_MAXIMUM,
1264 found, GST_MP3_TYPEFIND_TRY_HEADERS, GST_MP3_TYPEFIND_TRY_SYNC,
1265 (guint64) skipped, GST_MP3_TYPEFIND_TRY_SYNC);
1266 /* make sure we're not id3 tagged */
1267 head_data = gst_type_find_peek (tf, -128, 3);
1268 if (head_data && (memcmp (head_data, "TAG", 3) == 0)) {
1271 g_assert (probability <= GST_TYPE_FIND_MAXIMUM);
1273 *found_prob = probability;
1274 if (probability > 0)
1275 *found_layer = layer;
1286 mp3_type_find (GstTypeFind * tf, gpointer unused)
1288 GstTypeFindProbability prob, mid_prob;
1290 guint layer, mid_layer;
1293 mp3_type_find_at_offset (tf, 0, &layer, &prob);
1294 length = gst_type_find_get_length (tf);
1296 if (length == 0 || length == (guint64) - 1) {
1302 /* if we're pretty certain already, skip the additional check */
1303 if (prob >= GST_TYPE_FIND_LIKELY)
1306 mp3_type_find_at_offset (tf, length / 2, &mid_layer, &mid_prob);
1310 GST_LOG ("detected audio/mpeg only in the middle (p=%u)", mid_prob);
1316 if (layer != mid_layer) {
1317 GST_WARNING ("audio/mpeg layer discrepancy: %u vs. %u", layer, mid_layer);
1318 return; /* FIXME: or should we just go with the one in the middle? */
1321 /* detected mpeg audio both in middle of the file and at the start */
1322 prob = (prob + mid_prob) / 2;
1326 /* let's see if there's a valid header right at the start */
1327 data = gst_type_find_peek (tf, 0, 4); /* use min. frame size? */
1328 if (data && mp3_type_frame_length_from_header (GST_READ_UINT32_BE (data),
1329 &layer, NULL, NULL, NULL, NULL, 0) != 0) {
1331 prob = GST_TYPE_FIND_POSSIBLE - 10;
1333 prob = MAX (GST_TYPE_FIND_POSSIBLE - 10, prob + 10);
1343 g_return_if_fail (layer >= 1 && layer <= 3);
1345 gst_type_find_suggest_simple (tf, prob, "audio/mpeg",
1346 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, layer, NULL);
1350 /*** audio/x-musepack ***/
1352 static GstStaticCaps musepack_caps =
1353 GST_STATIC_CAPS ("audio/x-musepack, streamversion= (int) { 7, 8 }");
1355 #define MUSEPACK_CAPS (gst_static_caps_get(&musepack_caps))
1357 musepack_type_find (GstTypeFind * tf, gpointer unused)
1359 const guint8 *data = gst_type_find_peek (tf, 0, 4);
1360 GstTypeFindProbability prop = GST_TYPE_FIND_MINIMUM;
1361 gint streamversion = -1;
1363 if (data && memcmp (data, "MP+", 3) == 0) {
1365 if ((data[3] & 0x7f) == 7) {
1366 prop = GST_TYPE_FIND_MAXIMUM;
1368 prop = GST_TYPE_FIND_LIKELY + 10;
1370 } else if (data && memcmp (data, "MPCK", 4) == 0) {
1372 prop = GST_TYPE_FIND_MAXIMUM;
1375 if (streamversion != -1) {
1376 gst_type_find_suggest_simple (tf, prop, "audio/x-musepack",
1377 "streamversion", G_TYPE_INT, streamversion, NULL);
1381 /*** audio/x-ac3 ***/
1382 /* FIXME 0.11: should be audio/ac3, but isn't for backwards compatibility */
1383 static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
1385 #define AC3_CAPS (gst_static_caps_get(&ac3_caps))
1387 static GstStaticCaps eac3_caps = GST_STATIC_CAPS ("audio/x-eac3");
1389 #define EAC3_CAPS (gst_static_caps_get(&eac3_caps))
1393 unsigned short bit_rate;
1394 unsigned short frm_size[3];
1397 static const struct ac3_frmsize ac3_frmsizecod_tbl[] = {
1400 {40, {80, 87, 120}},
1401 {40, {80, 88, 120}},
1402 {48, {96, 104, 144}},
1403 {48, {96, 105, 144}},
1404 {56, {112, 121, 168}},
1405 {56, {112, 122, 168}},
1406 {64, {128, 139, 192}},
1407 {64, {128, 140, 192}},
1408 {80, {160, 174, 240}},
1409 {80, {160, 175, 240}},
1410 {96, {192, 208, 288}},
1411 {96, {192, 209, 288}},
1412 {112, {224, 243, 336}},
1413 {112, {224, 244, 336}},
1414 {128, {256, 278, 384}},
1415 {128, {256, 279, 384}},
1416 {160, {320, 348, 480}},
1417 {160, {320, 349, 480}},
1418 {192, {384, 417, 576}},
1419 {192, {384, 418, 576}},
1420 {224, {448, 487, 672}},
1421 {224, {448, 488, 672}},
1422 {256, {512, 557, 768}},
1423 {256, {512, 558, 768}},
1424 {320, {640, 696, 960}},
1425 {320, {640, 697, 960}},
1426 {384, {768, 835, 1152}},
1427 {384, {768, 836, 1152}},
1428 {448, {896, 975, 1344}},
1429 {448, {896, 976, 1344}},
1430 {512, {1024, 1114, 1536}},
1431 {512, {1024, 1115, 1536}},
1432 {576, {1152, 1253, 1728}},
1433 {576, {1152, 1254, 1728}},
1434 {640, {1280, 1393, 1920}},
1435 {640, {1280, 1394, 1920}}
1439 ac3_type_find (GstTypeFind * tf, gpointer unused)
1441 DataScanCtx c = { 0, NULL, 0 };
1443 /* Search for an ac3 frame; not neccesarily right at the start, but give it
1444 * a lower probability if not found right at the start. Check that the
1445 * frame is followed by a second frame at the expected offset.
1446 * We could also check the two ac3 CRCs, but we don't do that right now */
1447 while (c.offset < 1024) {
1448 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 5)))
1451 if (c.data[0] == 0x0b && c.data[1] == 0x77) {
1452 guint bsid = c.data[5] >> 3;
1456 guint fscod = c.data[4] >> 6;
1457 guint frmsizecod = c.data[4] & 0x3f;
1459 if (fscod < 3 && frmsizecod < 38) {
1460 DataScanCtx c_next = c;
1463 frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
1464 GST_LOG ("possible AC3 frame sync at offset %"
1465 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1466 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1467 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1469 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1470 fscod = c_next.data[4] >> 6;
1471 frmsizecod = c_next.data[4] & 0x3f;
1473 if (fscod < 3 && frmsizecod < 38) {
1474 GstTypeFindProbability prob;
1476 GST_LOG ("found second AC3 frame (size=%u), looks good",
1477 ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod]);
1479 prob = GST_TYPE_FIND_MAXIMUM;
1481 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1483 gst_type_find_suggest (tf, prob, AC3_CAPS);
1487 GST_LOG ("no second AC3 frame found, false sync");
1491 } else if (bsid <= 16 && bsid > 10) {
1493 DataScanCtx c_next = c;
1496 frame_size = (((c.data[2] & 0x07) << 8) + c.data[3]) + 1;
1497 GST_LOG ("possible E-AC3 frame sync at offset %"
1498 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1499 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1500 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1502 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1503 GstTypeFindProbability prob;
1505 GST_LOG ("found second E-AC3 frame, looks good");
1507 prob = GST_TYPE_FIND_MAXIMUM;
1509 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1511 gst_type_find_suggest (tf, prob, EAC3_CAPS);
1514 GST_LOG ("no second E-AC3 frame found, false sync");
1518 GST_LOG ("invalid AC3 BSID: %u", bsid);
1521 data_scan_ctx_advance (tf, &c, 1);
1525 /*** audio/x-dts ***/
1526 static GstStaticCaps dts_caps = GST_STATIC_CAPS ("audio/x-dts");
1527 #define DTS_CAPS (gst_static_caps_get (&dts_caps))
1528 #define DTS_MIN_FRAMESIZE 96
1529 #define DTS_MAX_FRAMESIZE 18725 /* 16384*16/14 */
1532 dts_parse_frame_header (DataScanCtx * c, guint * frame_size,
1533 guint * sample_rate, guint * channels, guint * depth, guint * endianness)
1535 static const int sample_rates[16] = { 0, 8000, 16000, 32000, 0, 0, 11025,
1536 22050, 44100, 0, 0, 12000, 24000, 48000, 96000, 192000
1538 static const guint8 channels_table[16] = { 1, 2, 2, 2, 2, 3, 3, 4, 4, 5,
1543 guint num_blocks, chans, lfe, i;
1545 marker = GST_READ_UINT32_BE (c->data);
1547 /* raw big endian or 14-bit big endian */
1548 if (marker == 0x7FFE8001 || marker == 0x1FFFE800) {
1549 *endianness = G_BIG_ENDIAN;
1550 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1551 hdr[i] = GST_READ_UINT16_BE (c->data + (i * sizeof (guint16)));
1553 /* raw little endian or 14-bit little endian */
1554 if (marker == 0xFE7F0180 || marker == 0xFF1F00E8) {
1555 *endianness = G_LITTLE_ENDIAN;
1556 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1557 hdr[i] = GST_READ_UINT16_LE (c->data + (i * sizeof (guint16)));
1562 GST_LOG ("dts sync marker 0x%08x at offset %u", marker, (guint) c->offset);
1565 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8) {
1566 if ((hdr[2] & 0xFFF0) != 0x07F0)
1568 /* discard top 2 bits (2 void), shift in 2 */
1569 hdr[0] = (hdr[0] << 2) | ((hdr[1] >> 12) & 0x0003);
1570 /* discard top 4 bits (2 void, 2 shifted into hdr[0]), shift in 4 etc. */
1571 hdr[1] = (hdr[1] << 4) | ((hdr[2] >> 10) & 0x000F);
1572 hdr[2] = (hdr[2] << 6) | ((hdr[3] >> 8) & 0x003F);
1573 hdr[3] = (hdr[3] << 8) | ((hdr[4] >> 6) & 0x00FF);
1574 hdr[4] = (hdr[4] << 10) | ((hdr[5] >> 4) & 0x03FF);
1575 hdr[5] = (hdr[5] << 12) | ((hdr[6] >> 2) & 0x0FFF);
1576 hdr[6] = (hdr[6] << 14) | ((hdr[7] >> 0) & 0x3FFF);
1577 g_assert (hdr[0] == 0x7FFE && hdr[1] == 0x8001);
1583 GST_LOG ("frame header: %04x%04x%04x%04x", hdr[2], hdr[3], hdr[4], hdr[5]);
1585 num_blocks = (hdr[2] >> 2) & 0x7F;
1586 *frame_size = (((hdr[2] & 0x03) << 12) | (hdr[3] >> 4)) + 1;
1587 chans = ((hdr[3] & 0x0F) << 2) | (hdr[4] >> 14);
1588 *sample_rate = sample_rates[(hdr[4] >> 10) & 0x0F];
1589 lfe = (hdr[5] >> 9) & 0x03;
1591 if (num_blocks < 5 || *frame_size < 96 || *sample_rate == 0)
1594 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8)
1595 *frame_size = (*frame_size * 16) / 14; /* FIXME: round up? */
1597 if (chans < G_N_ELEMENTS (channels_table))
1598 *channels = channels_table[chans] + ((lfe) ? 1 : 0);
1606 dts_type_find (GstTypeFind * tf, gpointer unused)
1608 DataScanCtx c = { 0, NULL, 0 };
1610 /* Search for an dts frame; not neccesarily right at the start, but give it
1611 * a lower probability if not found right at the start. Check that the
1612 * frame is followed by a second frame at the expected offset. */
1613 while (c.offset <= DTS_MAX_FRAMESIZE) {
1614 guint frame_size = 0, rate = 0, chans = 0, depth = 0, endianness = 0;
1616 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, DTS_MIN_FRAMESIZE)))
1619 if (G_UNLIKELY (dts_parse_frame_header (&c, &frame_size, &rate, &chans,
1620 &depth, &endianness))) {
1621 GstTypeFindProbability prob;
1624 prob = (c.offset == 0) ? GST_TYPE_FIND_LIKELY : GST_TYPE_FIND_POSSIBLE;
1626 /* check for second frame sync */
1628 data_scan_ctx_advance (tf, &next_c, frame_size);
1629 if (data_scan_ctx_ensure_data (tf, &next_c, 4)) {
1630 GST_LOG ("frame size: %u 0x%04x", frame_size, frame_size);
1631 GST_MEMDUMP ("second frame sync", next_c.data, 4);
1632 if (GST_READ_UINT32_BE (c.data) == GST_READ_UINT32_BE (next_c.data))
1633 prob = GST_TYPE_FIND_MAXIMUM;
1637 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
1638 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, chans,
1639 "depth", G_TYPE_INT, depth, "endianness", G_TYPE_INT, endianness,
1640 "framed", G_TYPE_BOOLEAN, FALSE, NULL);
1642 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
1643 "rate", G_TYPE_INT, rate, "depth", G_TYPE_INT, depth,
1644 "endianness", G_TYPE_INT, endianness,
1645 "framed", G_TYPE_BOOLEAN, FALSE, NULL);
1651 data_scan_ctx_advance (tf, &c, 1);
1657 /* can only be detected by using the extension, in which case we use the default
1659 static GstStaticCaps gsm_caps =
1660 GST_STATIC_CAPS ("audio/x-gsm, rate=8000, channels=1");
1662 #define GSM_CAPS (gst_static_caps_get(&gsm_caps))
1666 static GstStaticCaps wavpack_caps =
1667 GST_STATIC_CAPS ("audio/x-wavpack, framed = (boolean) false");
1669 #define WAVPACK_CAPS (gst_static_caps_get(&wavpack_caps))
1671 static GstStaticCaps wavpack_correction_caps =
1672 GST_STATIC_CAPS ("audio/x-wavpack-correction, framed = (boolean) false");
1674 #define WAVPACK_CORRECTION_CAPS (gst_static_caps_get(&wavpack_correction_caps))
1677 wavpack_type_find (GstTypeFind * tf, gpointer unused)
1683 data = gst_type_find_peek (tf, 0, 32);
1687 if (data[0] != 'w' || data[1] != 'v' || data[2] != 'p' || data[3] != 'k')
1690 /* Note: wavpack blocks can be fairly large (easily 60-110k), possibly
1691 * larger than the max. limits imposed by certain typefinding elements
1692 * like id3demux or apedemux, so typefinding is most likely only going to
1693 * work in pull-mode */
1694 blocksize = GST_READ_UINT32_LE (data + 4);
1695 GST_LOG ("wavpack header, blocksize=0x%04x", blocksize);
1697 while (offset < 32 + blocksize) {
1700 /* get chunk header */
1701 GST_LOG ("peeking at chunk at offset 0x%04x", (guint) offset);
1702 data = gst_type_find_peek (tf, offset, 4);
1705 sublen = ((guint32) data[1]) << 1;
1706 if (data[0] & 0x80) {
1707 sublen |= (((guint32) data[2]) << 9) | (((guint32) data[3]) << 17);
1708 sublen += 1 + 3; /* id + length */
1710 sublen += 1 + 1; /* id + length */
1712 if (sublen > blocksize - offset + 32) {
1713 GST_LOG ("chunk length too big (%u > %" G_GUINT64_FORMAT ")", sublen,
1714 blocksize - offset);
1717 if ((data[0] & 0x20) == 0) {
1718 switch (data[0] & 0x0f) {
1719 case 0xa: /* ID_WV_BITSTREAM */
1720 case 0xc: /* ID_WVX_BITSTREAM */
1721 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, WAVPACK_CAPS);
1723 case 0xb: /* ID_WVC_BITSTREAM */
1724 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY,
1725 WAVPACK_CORRECTION_CAPS);
1735 /*** application/postscrip ***/
1736 static GstStaticCaps postscript_caps =
1737 GST_STATIC_CAPS ("application/postscript");
1739 #define POSTSCRIPT_CAPS (gst_static_caps_get(&postscript_caps))
1742 postscript_type_find (GstTypeFind * tf, gpointer unused)
1744 const guint8 *data = gst_type_find_peek (tf, 0, 3);
1748 if (data[0] == 0x04)
1750 if (data[0] == '%' && data[1] == '!')
1751 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, POSTSCRIPT_CAPS);
1755 /*** image/svg+xml ***/
1756 static GstStaticCaps svg_caps = GST_STATIC_CAPS ("image/svg+xml");
1758 #define SVG_CAPS (gst_static_caps_get(&svg_caps))
1761 svg_type_find (GstTypeFind * tf, gpointer unused)
1763 static const gchar svg_doctype[] = "!DOCTYPE svg";
1764 static const gchar svg_tag[] = "<svg";
1765 DataScanCtx c = { 0, NULL, 0 };
1767 while (c.offset <= 1024) {
1768 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
1771 if (memcmp (svg_doctype, c.data, 12) == 0) {
1772 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVG_CAPS);
1774 } else if (memcmp (svg_tag, c.data, 4) == 0) {
1775 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, SVG_CAPS);
1778 data_scan_ctx_advance (tf, &c, 1);
1782 /*** multipart/x-mixed-replace mimestream ***/
1784 static GstStaticCaps multipart_caps =
1785 GST_STATIC_CAPS ("multipart/x-mixed-replace");
1786 #define MULTIPART_CAPS gst_static_caps_get(&multipart_caps)
1788 /* multipart/x-mixed replace is:
1789 * <maybe some whitespace>--<some ascii chars>[\r]\n
1790 * <more ascii chars>[\r]\nContent-type:<more ascii>[\r]\n */
1792 multipart_type_find (GstTypeFind * tf, gpointer unused)
1797 #define MULTIPART_MAX_BOUNDARY_OFFSET 16
1798 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_BOUNDARY_OFFSET);
1803 x - data < MULTIPART_MAX_BOUNDARY_OFFSET - 2 && g_ascii_isspace (*x);
1805 if (x[0] != '-' || x[1] != '-')
1808 /* Could be okay, peek what should be enough for a complete header */
1809 #define MULTIPART_MAX_HEADER_SIZE 256
1810 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_HEADER_SIZE);
1814 for (x = data; x - data < MULTIPART_MAX_HEADER_SIZE - 14; x++) {
1815 if (!isascii (*x)) {
1819 !g_ascii_strncasecmp ("content-type:", (gchar *) x + 1, 13)) {
1820 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MULTIPART_CAPS);
1826 /*** video/mpeg systemstream ***/
1827 static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, "
1828 "systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
1830 #define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
1831 #define IS_MPEG_HEADER(data) (G_UNLIKELY((((guint8 *)(data))[0] == 0x00) && \
1832 (((guint8 *)(data))[1] == 0x00) && \
1833 (((guint8 *)(data))[2] == 0x01)))
1835 #define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
1836 #define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
1837 #define IS_MPEG_PACK_HEADER(data) (IS_MPEG_HEADER (data) && \
1838 IS_MPEG_PACK_CODE (((guint8 *)(data))[3]))
1840 #define IS_MPEG_PES_CODE(b) (((b) & 0xF0) == 0xE0 || ((b) & 0xF0) == 0xC0 || \
1842 #define IS_MPEG_PES_HEADER(data) (IS_MPEG_HEADER (data) && \
1843 IS_MPEG_PES_CODE (((guint8 *)(data))[3]))
1845 #define MPEG2_MAX_PROBE_LENGTH (128 * 1024) /* 128kB should be 64 packs of the
1846 * most common 2kB pack size. */
1848 #define MPEG2_MIN_SYS_HEADERS 2
1849 #define MPEG2_MAX_SYS_HEADERS 5
1852 mpeg_sys_is_valid_pack (GstTypeFind * tf, const guint8 * data, guint len,
1855 /* Check the pack header @ offset for validity, assuming that the 4 byte header
1856 * itself has already been checked. */
1862 /* Check marker bits */
1863 if ((data[4] & 0xC4) == 0x44) {
1868 if ((data[6] & 0x04) != 0x04 ||
1869 (data[8] & 0x04) != 0x04 ||
1870 (data[9] & 0x01) != 0x01 || (data[12] & 0x03) != 0x03)
1873 stuff_len = data[13] & 0x07;
1875 /* Check the following header bytes, if we can */
1876 if ((14 + stuff_len + 4) <= len) {
1877 if (!IS_MPEG_HEADER (data + 14 + stuff_len))
1881 *pack_size = 14 + stuff_len;
1883 } else if ((data[4] & 0xF1) == 0x21) {
1885 if ((data[6] & 0x01) != 0x01 ||
1886 (data[8] & 0x01) != 0x01 ||
1887 (data[9] & 0x80) != 0x80 || (data[11] & 0x01) != 0x01)
1890 /* Check the following header bytes, if we can */
1891 if ((12 + 4) <= len) {
1892 if (!IS_MPEG_HEADER (data + 12))
1904 mpeg_sys_is_valid_pes (GstTypeFind * tf, const guint8 * data, guint len,
1907 guint pes_packet_len;
1909 /* Check the PES header at the given position, assuming the header code itself
1910 * was already checked */
1914 /* For MPEG Program streams, unbounded PES is not allowed, so we must have a
1915 * valid length present */
1916 pes_packet_len = GST_READ_UINT16_BE (data + 4);
1917 if (pes_packet_len == 0)
1920 /* Check the following header, if we can */
1921 if (6 + pes_packet_len + 4 <= len) {
1922 if (!IS_MPEG_HEADER (data + 6 + pes_packet_len))
1927 *pack_size = 6 + pes_packet_len;
1932 mpeg_sys_is_valid_sys (GstTypeFind * tf, const guint8 * data, guint len,
1937 /* Check the System header at the given position, assuming the header code itself
1938 * was already checked */
1941 sys_hdr_len = GST_READ_UINT16_BE (data + 4);
1942 if (sys_hdr_len < 6)
1945 /* Check the following header, if we can */
1946 if (6 + sys_hdr_len + 4 <= len) {
1947 if (!IS_MPEG_HEADER (data + 6 + sys_hdr_len))
1952 *pack_size = 6 + sys_hdr_len;
1957 /* calculation of possibility to identify random data as mpeg systemstream:
1958 * bits that must match in header detection: 32 (or more)
1959 * chance that random data is identifed: 1/2^32
1960 * chance that MPEG2_MIN_PACK_HEADERS headers are identified:
1961 * 1/2^(32*MPEG2_MIN_PACK_HEADERS)
1962 * chance that this happens in MPEG2_MAX_PROBE_LENGTH bytes:
1963 * 1-(1+1/2^(32*MPEG2_MIN_PACK_HEADERS)^MPEG2_MAX_PROBE_LENGTH)
1964 * for current values:
1965 * 1-(1+1/2^(32*4)^101024)
1967 * Since we also check marker bits and pes packet lengths, this probability is a
1968 * very coarse upper bound.
1971 mpeg_sys_type_find (GstTypeFind * tf, gpointer unused)
1973 const guint8 *data, *data0, *first_sync, *end;
1974 gint mpegversion = 0;
1975 guint pack_headers = 0;
1976 guint pes_headers = 0;
1978 guint since_last_sync = 0;
1979 guint32 sync_word = 0xffffffff;
1984 len = MPEG2_MAX_PROBE_LENGTH;
1987 data = gst_type_find_peek (tf, 0, 5 + len);
1988 } while (data == NULL && len >= 32);
2000 while (data < end) {
2002 if (sync_word == 0x00000100) {
2003 /* Found potential sync word */
2004 if (first_sync == NULL)
2005 first_sync = data - 3;
2007 if (since_last_sync > 4) {
2008 /* If more than 4 bytes since the last sync word, reset our counters,
2009 * as we're only interested in counting contiguous packets */
2010 pes_headers = pack_headers = 0;
2014 if (IS_MPEG_PACK_CODE (data[0])) {
2015 if ((data[1] & 0xC0) == 0x40) {
2018 } else if ((data[1] & 0xF0) == 0x20) {
2021 if (mpegversion != 0 &&
2022 mpeg_sys_is_valid_pack (tf, data - 3, end - data + 3, &pack_size)) {
2025 } else if (IS_MPEG_PES_CODE (data[0])) {
2027 if (mpeg_sys_is_valid_pes (tf, data - 3, end - data + 3, &pack_size)) {
2029 if (mpegversion == 0)
2032 } else if (IS_MPEG_SYS_CODE (data[0])) {
2033 if (mpeg_sys_is_valid_sys (tf, data - 3, end - data + 3, &pack_size)) {
2038 /* If we found a packet with a known size, skip the bytes in it and loop
2039 * around to check the next packet. */
2040 if (pack_size != 0) {
2041 data += pack_size - 3;
2042 sync_word = 0xffffffff;
2043 since_last_sync = 0;
2048 sync_word |= data[0];
2052 /* If we have found MAX headers, and *some* were pes headers (pack headers
2053 * are optional in an mpeg system stream) then return our high-probability
2055 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MAX_SYS_HEADERS)
2059 /* If we at least saw MIN headers, and *some* were pes headers (pack headers
2060 * are optional in an mpeg system stream) then return a lower-probability
2062 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MIN_SYS_HEADERS)
2070 prob = GST_TYPE_FIND_POSSIBLE + (10 * (pack_headers + pes_headers));
2071 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
2073 /* lower probability if the first packet wasn't right at the start */
2074 if (data0 != first_sync && prob >= 10)
2077 GST_LOG ("Suggesting MPEG %d system stream, %d packs, %d pes, prob %u%%\n",
2078 mpegversion, pack_headers, pes_headers, prob);
2080 gst_type_find_suggest_simple (tf, prob, "video/mpeg",
2081 "systemstream", G_TYPE_BOOLEAN, TRUE,
2082 "mpegversion", G_TYPE_INT, mpegversion, NULL);
2086 /*** video/mpegts Transport Stream ***/
2087 static GstStaticCaps mpegts_caps = GST_STATIC_CAPS ("video/mpegts, "
2088 "systemstream = (boolean) true, packetsize = (int) [ 188, 208 ]");
2089 #define MPEGTS_CAPS gst_static_caps_get(&mpegts_caps)
2091 #define GST_MPEGTS_TYPEFIND_MIN_HEADERS 4
2092 #define GST_MPEGTS_TYPEFIND_MAX_HEADERS 10
2093 #define GST_MPEGTS_MAX_PACKET_SIZE 208
2094 #define GST_MPEGTS_TYPEFIND_SYNC_SIZE \
2095 (GST_MPEGTS_TYPEFIND_MIN_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
2096 #define GST_MPEGTS_TYPEFIND_MAX_SYNC \
2097 (GST_MPEGTS_TYPEFIND_MAX_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
2098 #define GST_MPEGTS_TYPEFIND_SCAN_LENGTH \
2099 (GST_MPEGTS_TYPEFIND_MAX_SYNC * 4)
2101 #define MPEGTS_HDR_SIZE 4
2102 /* Check for sync byte, error_indicator == 0 and packet has payload */
2103 #define IS_MPEGTS_HEADER(data) (((data)[0] == 0x47) && \
2104 (((data)[1] & 0x80) == 0x00) && \
2105 (((data)[3] & 0x30) != 0x00))
2107 /* Helper function to search ahead at intervals of packet_size for mpegts
2110 mpeg_ts_probe_headers (GstTypeFind * tf, guint64 offset, gint packet_size)
2112 /* We always enter this function having found at least one header already */
2114 const guint8 *data = NULL;
2116 GST_LOG ("looking for mpeg-ts packets of size %u", packet_size);
2117 while (found < GST_MPEGTS_TYPEFIND_MAX_HEADERS) {
2118 offset += packet_size;
2120 data = gst_type_find_peek (tf, offset, MPEGTS_HDR_SIZE);
2121 if (data == NULL || !IS_MPEGTS_HEADER (data))
2125 GST_LOG ("mpeg-ts sync #%2d at offset %" G_GUINT64_FORMAT, found, offset);
2131 /* Try and detect at least 4 packets in at most 10 packets worth of
2132 * data. Need to try several possible packet sizes */
2134 mpeg_ts_type_find (GstTypeFind * tf, gpointer unused)
2136 /* TS packet sizes to test: normal, DVHS packet size and
2137 * FEC with 16 or 20 byte codes packet size. */
2138 const gint pack_sizes[] = { 188, 192, 204, 208 };
2139 const guint8 *data = NULL;
2141 guint64 skipped = 0;
2143 while (skipped < GST_MPEGTS_TYPEFIND_SCAN_LENGTH) {
2144 if (size < MPEGTS_HDR_SIZE) {
2145 data = gst_type_find_peek (tf, skipped, GST_MPEGTS_TYPEFIND_SYNC_SIZE);
2148 size = GST_MPEGTS_TYPEFIND_SYNC_SIZE;
2151 /* Have at least MPEGTS_HDR_SIZE bytes at this point */
2152 if (IS_MPEGTS_HEADER (data)) {
2155 GST_LOG ("possible mpeg-ts sync at offset %" G_GUINT64_FORMAT, skipped);
2157 for (p = 0; p < G_N_ELEMENTS (pack_sizes); p++) {
2160 /* Probe ahead at size pack_sizes[p] */
2161 found = mpeg_ts_probe_headers (tf, skipped, pack_sizes[p]);
2162 if (found >= GST_MPEGTS_TYPEFIND_MIN_HEADERS) {
2165 /* found at least 4 headers. 10 headers = MAXIMUM probability.
2166 * Arbitrarily, I assigned 10% probability for each header we
2167 * found, 40% -> 100% */
2168 probability = MIN (10 * found, GST_TYPE_FIND_MAXIMUM);
2170 gst_type_find_suggest_simple (tf, probability, "video/mpegts",
2171 "systemstream", G_TYPE_BOOLEAN, TRUE,
2172 "packetsize", G_TYPE_INT, pack_sizes[p], NULL);
2183 #define GST_MPEGVID_TYPEFIND_TRY_PICTURES 6
2184 #define GST_MPEGVID_TYPEFIND_TRY_SYNC (100 * 1024) /* 100 kB */
2186 /* Scan ahead a maximum of max_extra_offset bytes until the next IS_MPEG_HEADER
2187 * offset. After the call, offset will be after the 0x000001, i.e. at the 4th
2188 * byte of the MPEG header. Returns TRUE if a header was found, FALSE if not.
2191 mpeg_find_next_header (GstTypeFind * tf, DataScanCtx * c,
2192 guint64 max_extra_offset)
2194 guint64 extra_offset;
2196 for (extra_offset = 0; extra_offset <= max_extra_offset; ++extra_offset) {
2197 if (!data_scan_ctx_ensure_data (tf, c, 4))
2199 if (IS_MPEG_HEADER (c->data)) {
2200 data_scan_ctx_advance (tf, c, 3);
2203 data_scan_ctx_advance (tf, c, 1);
2208 /*** video/mpeg MPEG-4 elementary video stream ***/
2210 static GstStaticCaps mpeg4_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2211 "systemstream=(boolean)false, mpegversion=4, parsed=(boolean)false");
2212 #define MPEG4_VIDEO_CAPS gst_static_caps_get(&mpeg4_video_caps)
2215 * This typefind is based on the elementary video header defined in
2216 * http://xhelmboyx.tripod.com/formats/mpeg-layout.txt
2217 * In addition, it allows the visual object sequence header to be
2218 * absent, and even the VOS header to be absent. In the latter case,
2219 * a number of VOPs have to be present.
2222 mpeg4_video_type_find (GstTypeFind * tf, gpointer unused)
2224 DataScanCtx c = { 0, NULL, 0 };
2225 gboolean seen_vios_at_0 = FALSE;
2226 gboolean seen_vios = FALSE;
2227 gboolean seen_vos = FALSE;
2228 gboolean seen_vol = FALSE;
2229 guint num_vop_headers = 0;
2232 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2233 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2236 if (!mpeg_find_next_header (tf, &c,
2237 GST_MPEGVID_TYPEFIND_TRY_SYNC - c.offset))
2242 /* visual_object_sequence_start_code */
2245 break; /* Terminate at second vios */
2247 seen_vios_at_0 = TRUE;
2249 data_scan_ctx_advance (tf, &c, 2);
2250 if (!mpeg_find_next_header (tf, &c, 0))
2255 /* Optional metadata */
2257 if (!mpeg_find_next_header (tf, &c, 24))
2261 /* visual_object_start_code (consider it optional) */
2263 data_scan_ctx_advance (tf, &c, 2);
2264 /* may contain ID marker and YUV clamping */
2265 if (!mpeg_find_next_header (tf, &c, 7))
2271 /* video_object_start_code */
2274 break; /* Terminate at second vos */
2276 data_scan_ctx_advance (tf, &c, 2);
2280 /* video_object_layer_start_code */
2281 if (sc >= 0x20 && sc <= 0x2F) {
2283 data_scan_ctx_advance (tf, &c, 5);
2287 /* video_object_plane_start_code */
2290 data_scan_ctx_advance (tf, &c, 2);
2294 /* Unknown start code. */
2297 if (num_vop_headers > 0 || seen_vol) {
2298 GstTypeFindProbability probability = 0;
2300 GST_LOG ("Found %d pictures, vios: %d, vos:%d, vol:%d", num_vop_headers,
2301 seen_vios, seen_vos, seen_vol);
2303 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios_at_0
2304 && seen_vos && seen_vol)
2305 probability = GST_TYPE_FIND_MAXIMUM - 1;
2306 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios
2307 && seen_vos && seen_vol)
2308 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2309 else if (seen_vios_at_0 && seen_vos && seen_vol)
2310 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2311 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vos
2313 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2314 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vol)
2315 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2316 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2317 probability = GST_TYPE_FIND_LIKELY - 1;
2318 else if (num_vop_headers > 2 && seen_vios && seen_vos && seen_vol)
2319 probability = GST_TYPE_FIND_LIKELY - 9;
2320 else if (seen_vios && seen_vos && seen_vol)
2321 probability = GST_TYPE_FIND_LIKELY - 20;
2322 else if (num_vop_headers > 0 && seen_vos && seen_vol)
2323 probability = GST_TYPE_FIND_POSSIBLE;
2324 else if (num_vop_headers > 0)
2325 probability = GST_TYPE_FIND_POSSIBLE - 10;
2326 else if (seen_vos && seen_vol)
2327 probability = GST_TYPE_FIND_POSSIBLE - 20;
2329 gst_type_find_suggest (tf, probability, MPEG4_VIDEO_CAPS);
2333 /*** video/x-h263 H263 video stream ***/
2334 static GstStaticCaps h263_video_caps = GST_STATIC_CAPS ("video/x-h263");
2336 #define H263_VIDEO_CAPS gst_static_caps_get(&h263_video_caps)
2338 #define H263_MAX_PROBE_LENGTH (128 * 1024)
2341 h263_video_type_find (GstTypeFind * tf, gpointer unused)
2343 DataScanCtx c = { 0, NULL, 0 };
2351 while (c.offset < H263_MAX_PROBE_LENGTH) {
2352 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
2355 /* Find the picture start code */
2356 data = (data << 8) + c.data[0];
2357 psc = data & G_GUINT64_CONSTANT (0xfffffc0000);
2358 if (psc == 0x800000) {
2361 tr = (data & 0x3fc) >> 2;
2365 /* Now that we have a Valid PSC, check if we also have a valid PTYPE and
2366 the Source Format, which should range between 1 and 5 */
2367 if (((tr >> 6) == 0x2) && (format > 0 && format < 6))
2372 /* FIXME: maybe bail out early if we get mostly bad syncs ? */
2375 data_scan_ctx_advance (tf, &c, 1);
2378 if (good > 0 && bad == 0)
2379 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H263_VIDEO_CAPS);
2380 else if (good > 2 * bad)
2381 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H263_VIDEO_CAPS);
2386 /*** video/x-h264 H264 elementary video stream ***/
2388 static GstStaticCaps h264_video_caps =
2389 GST_STATIC_CAPS ("video/x-h264,stream-format=byte-stream");
2391 #define H264_VIDEO_CAPS gst_static_caps_get(&h264_video_caps)
2393 #define H264_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
2396 h264_video_type_find (GstTypeFind * tf, gpointer unused)
2398 DataScanCtx c = { 0, NULL, 0 };
2400 /* Stream consists of: a series of sync codes (00 00 00 01) followed
2407 while (c.offset < H264_MAX_PROBE_LENGTH) {
2408 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
2411 if (IS_MPEG_HEADER (c.data)) {
2412 nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
2413 ref = c.data[3] & 0x60; /* nal_ref_idc */
2415 /* if forbiden bit is different to 0 won't be h264 */
2421 /* collect statistics about the NAL types */
2422 if ((nut >= 1 && nut <= 13) || nut == 19) {
2423 if ((nut == 5 && ref == 0) ||
2424 ((nut == 6 || (nut >= 9 && nut <= 12)) && ref != 0)) {
2429 } else if (nut >= 14 && nut <= 33) {
2431 /* Theoretically these are good, since if they exist in the
2432 stream it merely means that a newer backwards-compatible
2433 h.264 stream. But we should be identifying that separately. */
2436 /* unspecified, application specific */
2437 /* don't consider these bad */
2440 GST_DEBUG ("good %d bad %d", good, bad);
2442 if (good >= 10 && bad < 4) {
2443 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H264_VIDEO_CAPS);
2447 data_scan_ctx_advance (tf, &c, 4);
2449 data_scan_ctx_advance (tf, &c, 1);
2452 if (good >= 2 && bad < 1) {
2453 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H264_VIDEO_CAPS);
2458 /*** video/mpeg video stream ***/
2460 static GstStaticCaps mpeg_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2461 "systemstream = (boolean) false");
2462 #define MPEG_VIDEO_CAPS gst_static_caps_get(&mpeg_video_caps)
2465 * Idea is the same as MPEG system stream typefinding: We check each
2466 * byte of the stream to see if - from that point on - the stream
2467 * matches a predefined set of marker bits as defined in the MPEG
2470 * I'm sure someone will do a chance calculation here too.
2474 mpeg_video_stream_type_find (GstTypeFind * tf, gpointer unused)
2476 DataScanCtx c = { 0, NULL, 0 };
2477 gboolean seen_seq_at_0 = FALSE;
2478 gboolean seen_seq = FALSE;
2479 gboolean seen_gop = FALSE;
2480 guint64 last_pic_offset = 0;
2481 guint num_pic_headers = 0;
2484 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2485 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2488 if (!data_scan_ctx_ensure_data (tf, &c, 5))
2491 if (!IS_MPEG_HEADER (c.data))
2494 /* a pack header indicates that this isn't an elementary stream */
2495 if (c.data[3] == 0xBA && mpeg_sys_is_valid_pack (tf, c.data, c.size, NULL))
2498 /* do we have a sequence header? */
2499 if (c.data[3] == 0xB3) {
2500 seen_seq_at_0 = seen_seq_at_0 || (c.offset == 0);
2502 data_scan_ctx_advance (tf, &c, 4 + 8);
2506 /* or a GOP header */
2507 if (c.data[3] == 0xB8) {
2509 data_scan_ctx_advance (tf, &c, 8);
2513 /* but what we'd really like to see is a picture header */
2514 if (c.data[3] == 0x00) {
2516 last_pic_offset = c.offset;
2517 data_scan_ctx_advance (tf, &c, 8);
2521 /* ... each followed by a slice header with slice_vertical_pos=1 that's
2522 * not too far away from the previously seen picture header. */
2523 if (c.data[3] == 0x01 && num_pic_headers > found &&
2524 (c.offset - last_pic_offset) >= 4 &&
2525 (c.offset - last_pic_offset) <= 64) {
2526 data_scan_ctx_advance (tf, &c, 4);
2533 data_scan_ctx_advance (tf, &c, 1);
2536 if (found > 0 || seen_seq) {
2537 GstTypeFindProbability probability = 0;
2539 GST_LOG ("Found %d pictures, seq:%d, gop:%d", found, seen_seq, seen_gop);
2541 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq && seen_gop)
2542 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2543 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq)
2544 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2545 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2546 probability = GST_TYPE_FIND_LIKELY;
2547 else if (seen_seq_at_0 && seen_gop && found > 2)
2548 probability = GST_TYPE_FIND_LIKELY - 10;
2549 else if (seen_seq && seen_gop && found > 2)
2550 probability = GST_TYPE_FIND_LIKELY - 20;
2551 else if (seen_seq_at_0 && found > 0)
2552 probability = GST_TYPE_FIND_POSSIBLE;
2553 else if (seen_seq && found > 0)
2554 probability = GST_TYPE_FIND_POSSIBLE - 5;
2556 probability = GST_TYPE_FIND_POSSIBLE - 10;
2558 probability = GST_TYPE_FIND_POSSIBLE - 20;
2560 gst_type_find_suggest_simple (tf, probability, "video/mpeg",
2561 "systemstream", G_TYPE_BOOLEAN, FALSE,
2562 "mpegversion", G_TYPE_INT, 1, NULL);
2566 /*** audio/x-aiff ***/
2568 static GstStaticCaps aiff_caps = GST_STATIC_CAPS ("audio/x-aiff");
2570 #define AIFF_CAPS gst_static_caps_get(&aiff_caps)
2572 aiff_type_find (GstTypeFind * tf, gpointer unused)
2574 const guint8 *data = gst_type_find_peek (tf, 0, 4);
2576 if (data && memcmp (data, "FORM", 4) == 0) {
2578 if (memcmp (data, "AIFF", 4) == 0 || memcmp (data, "AIFC", 4) == 0)
2579 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AIFF_CAPS);
2583 /*** audio/x-svx ***/
2585 static GstStaticCaps svx_caps = GST_STATIC_CAPS ("audio/x-svx");
2587 #define SVX_CAPS gst_static_caps_get(&svx_caps)
2589 svx_type_find (GstTypeFind * tf, gpointer unused)
2591 const guint8 *data = gst_type_find_peek (tf, 0, 4);
2593 if (data && memcmp (data, "FORM", 4) == 0) {
2595 if (memcmp (data, "8SVX", 4) == 0 || memcmp (data, "16SV", 4) == 0)
2596 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVX_CAPS);
2600 /*** audio/x-shorten ***/
2602 static GstStaticCaps shn_caps = GST_STATIC_CAPS ("audio/x-shorten");
2604 #define SHN_CAPS gst_static_caps_get(&shn_caps)
2606 shn_type_find (GstTypeFind * tf, gpointer unused)
2608 const guint8 *data = gst_type_find_peek (tf, 0, 4);
2610 if (data && memcmp (data, "ajkg", 4) == 0) {
2611 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2613 data = gst_type_find_peek (tf, -8, 8);
2614 if (data && memcmp (data, "SHNAMPSK", 8) == 0) {
2615 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2619 /*** application/x-ape ***/
2621 static GstStaticCaps ape_caps = GST_STATIC_CAPS ("application/x-ape");
2623 #define APE_CAPS gst_static_caps_get(&ape_caps)
2625 ape_type_find (GstTypeFind * tf, gpointer unused)
2627 const guint8 *data = gst_type_find_peek (tf, 0, 4);
2629 if (data && memcmp (data, "MAC ", 4) == 0) {
2630 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 10, APE_CAPS);
2634 /*** ISO FORMATS ***/
2636 /*** audio/x-m4a ***/
2638 static GstStaticCaps m4a_caps = GST_STATIC_CAPS ("audio/x-m4a");
2640 #define M4A_CAPS (gst_static_caps_get(&m4a_caps))
2642 m4a_type_find (GstTypeFind * tf, gpointer unused)
2644 const guint8 *data = gst_type_find_peek (tf, 4, 8);
2646 if (data && (memcmp (data, "ftypM4A ", 8) == 0)) {
2647 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
2651 /*** application/x-3gp ***/
2653 /* The Q is there because variables can't start with a number. */
2654 static GstStaticCaps q3gp_caps = GST_STATIC_CAPS ("application/x-3gp");
2655 #define Q3GP_CAPS (gst_static_caps_get(&q3gp_caps))
2657 static const gchar *
2658 q3gp_type_find_get_profile (const guint8 * data)
2660 switch (GST_MAKE_FOURCC (data[0], data[1], data[2], 0)) {
2661 case GST_MAKE_FOURCC ('3', 'g', 'g', 0):
2663 case GST_MAKE_FOURCC ('3', 'g', 'p', 0):
2665 case GST_MAKE_FOURCC ('3', 'g', 's', 0):
2666 return "streaming-server";
2667 case GST_MAKE_FOURCC ('3', 'g', 'r', 0):
2668 return "progressive-download";
2676 q3gp_type_find (GstTypeFind * tf, gpointer unused)
2678 const gchar *profile;
2679 guint32 ftyp_size = 0;
2681 const guint8 *data = NULL;
2683 if ((data = gst_type_find_peek (tf, 0, 12)) == NULL) {
2688 if (memcmp (data, "ftyp", 4) != 0) {
2692 /* check major brand */
2694 if ((profile = q3gp_type_find_get_profile (data))) {
2695 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
2696 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
2700 /* check compatible brands */
2701 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2702 ftyp_size = GST_READ_UINT32_BE (data);
2704 for (offset = 16; offset < ftyp_size; offset += 4) {
2705 if ((data = gst_type_find_peek (tf, offset, 3)) == NULL) {
2708 if ((profile = q3gp_type_find_get_profile (data))) {
2709 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
2710 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
2719 /*** video/mj2 and image/jp2 ***/
2720 static GstStaticCaps mj2_caps = GST_STATIC_CAPS ("video/mj2");
2722 #define MJ2_CAPS gst_static_caps_get(&mj2_caps)
2724 static GstStaticCaps jp2_caps = GST_STATIC_CAPS ("image/jp2");
2726 #define JP2_CAPS gst_static_caps_get(&jp2_caps)
2729 jp2_type_find (GstTypeFind * tf, gpointer unused)
2733 data = gst_type_find_peek (tf, 0, 24);
2738 if (memcmp (data, "\000\000\000\014jP \015\012\207\012", 12) != 0)
2741 /* check ftyp box */
2743 if (memcmp (data + 4, "ftyp", 4) == 0) {
2744 if (memcmp (data + 8, "jp2 ", 4) == 0)
2745 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JP2_CAPS);
2746 else if (memcmp (data + 8, "mjp2", 4) == 0)
2747 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MJ2_CAPS);
2751 /*** video/quicktime ***/
2753 static GstStaticCaps qt_caps = GST_STATIC_CAPS ("video/quicktime");
2755 #define QT_CAPS gst_static_caps_get(&qt_caps)
2756 #define STRNCMP(x,y,z) (strncmp ((char*)(x), (char*)(y), z))
2758 /* FIXME 0.11: go through http://www.ftyps.com/ */
2760 qt_type_find (GstTypeFind * tf, gpointer unused)
2766 const gchar *variant = NULL;
2768 while ((data = gst_type_find_peek (tf, offset, 12)) != NULL) {
2771 if (STRNCMP (&data[4], "ftypqt ", 8) == 0) {
2772 tip = GST_TYPE_FIND_MAXIMUM;
2776 if (STRNCMP (&data[4], "ftypisom", 8) == 0 ||
2777 STRNCMP (&data[4], "ftypavc1", 8) == 0 ||
2778 STRNCMP (&data[4], "ftypmp42", 8) == 0) {
2779 tip = GST_TYPE_FIND_MAXIMUM;
2784 /* box/atom types that are in common with ISO base media file format */
2785 if (STRNCMP (&data[4], "moov", 4) == 0 ||
2786 STRNCMP (&data[4], "mdat", 4) == 0 ||
2787 STRNCMP (&data[4], "ftyp", 4) == 0 ||
2788 STRNCMP (&data[4], "free", 4) == 0 ||
2789 STRNCMP (&data[4], "uuid", 4) == 0 ||
2790 STRNCMP (&data[4], "skip", 4) == 0) {
2792 tip = GST_TYPE_FIND_LIKELY;
2794 tip = GST_TYPE_FIND_NEARLY_CERTAIN;
2797 /* other box/atom types, apparently quicktime specific */
2798 else if (STRNCMP (&data[4], "pnot", 4) == 0 ||
2799 STRNCMP (&data[4], "PICT", 4) == 0 ||
2800 STRNCMP (&data[4], "wide", 4) == 0 ||
2801 STRNCMP (&data[4], "prfl", 4) == 0) {
2802 tip = GST_TYPE_FIND_MAXIMUM;
2809 size = GST_READ_UINT32_BE (data);
2810 /* check compatible brands rather than ever expaning major brands above */
2811 if ((STRNCMP (&data[4], "ftyp", 4) == 0) && (size >= 16)) {
2812 new_offset = offset + 12;
2813 while (new_offset + 4 <= offset + size) {
2814 data = gst_type_find_peek (tf, new_offset, 4);
2817 if (STRNCMP (&data[4], "isom", 4) == 0 ||
2818 STRNCMP (&data[4], "avc1", 4) == 0 ||
2819 STRNCMP (&data[4], "mp41", 4) == 0 ||
2820 STRNCMP (&data[4], "mp42", 4) == 0) {
2821 tip = GST_TYPE_FIND_MAXIMUM;
2829 const guint8 *sizedata;
2831 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2832 if (sizedata == NULL)
2835 size = GST_READ_UINT64_BE (sizedata);
2840 new_offset = offset + size;
2841 if (new_offset <= offset)
2843 offset = new_offset;
2849 GstCaps *caps = gst_caps_copy (QT_CAPS);
2851 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, variant, NULL);
2852 gst_type_find_suggest (tf, tip, caps);
2853 gst_caps_unref (caps);
2855 gst_type_find_suggest (tf, tip, QT_CAPS);
2861 /*** image/x-quicktime ***/
2863 static GstStaticCaps qtif_caps = GST_STATIC_CAPS ("image/x-quicktime");
2865 #define QTIF_CAPS gst_static_caps_get(&qtif_caps)
2867 /* how many atoms we check before we give up */
2868 #define QTIF_MAXROUNDS 25
2871 qtif_type_find (GstTypeFind * tf, gpointer unused)
2874 gboolean found_idsc = FALSE;
2875 gboolean found_idat = FALSE;
2879 while ((data = gst_type_find_peek (tf, offset, 8)) != NULL) {
2882 size = GST_READ_UINT32_BE (data);
2884 const guint8 *sizedata;
2886 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2887 if (sizedata == NULL)
2890 size = GST_READ_UINT64_BE (sizedata);
2895 if (STRNCMP (data + 4, "idsc", 4) == 0)
2897 if (STRNCMP (data + 4, "idat", 4) == 0)
2900 if (found_idsc && found_idat) {
2901 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, QTIF_CAPS);
2906 if (++rounds > QTIF_MAXROUNDS)
2910 if (found_idsc || found_idat) {
2911 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, QTIF_CAPS);
2916 /*** audio/x-mod ***/
2918 static GstStaticCaps mod_caps = GST_STATIC_CAPS ("audio/x-mod");
2920 #define MOD_CAPS gst_static_caps_get(&mod_caps)
2921 /* FIXME: M15 CheckType to do */
2923 mod_type_find (GstTypeFind * tf, gpointer unused)
2928 if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) {
2929 /* Protracker and variants */
2930 if ((memcmp (data, "M.K.", 4) == 0) || (memcmp (data, "M!K!", 4) == 0) ||
2932 (memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) ||
2933 (memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) ||
2934 /* Oktalyzer (Amiga) */
2935 (memcmp (data, "OKTA", 4) == 0) ||
2936 /* Oktalyser (Atari) */
2937 (memcmp (data, "CD81", 4) == 0) ||
2939 (memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) ||
2940 /* Fasttracker or Taketracker */
2941 (memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0])
2942 && isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0
2943 && isdigit (data[0]) && isdigit (data[1]))) {
2944 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2949 if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) {
2950 if (memcmp (data, "Extended Module: ", 17) == 0 && data[37] == 0x1A) {
2951 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2956 if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) {
2957 if (memcmp (data, "OKTASONG", 8) == 0) {
2958 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2962 if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2964 if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) {
2965 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2969 if ((memcmp (data, "AMF", 3) == 0 && data[3] > 10 && data[3] < 14) ||
2971 (memcmp (data, "IMPM", 4) == 0) ||
2973 (memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0) ||
2975 (memcmp (data, "MTM", 3) == 0)) {
2976 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2980 if (memcmp (data, "RIFF", 4) == 0) {
2981 const guint8 *data2 = gst_type_find_peek (tf, 8, 4);
2984 if (memcmp (data2, "DSMF", 4) == 0) {
2985 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2991 if (memcmp (data, "FAM\xFE", 4) == 0) {
2992 const guint8 *data2 = gst_type_find_peek (tf, 44, 3);
2995 if (memcmp (data2, "compare", 3) == 0) {
2996 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3000 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
3005 if (memcmp (data, "GDM\xFE", 4) == 0) {
3006 const guint8 *data2 = gst_type_find_peek (tf, 71, 4);
3009 if (memcmp (data2, "GMFS", 4) == 0) {
3010 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3014 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
3020 if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) {
3021 if (memcmp (data, "IM10", 4) == 0) {
3022 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3027 if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) {
3028 if (memcmp (data, "SCRM", 4) == 0) {
3029 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3034 if ((data = gst_type_find_peek (tf, 20, 8)) != NULL) {
3035 if (g_ascii_strncasecmp ((gchar *) data, "!Scream!", 8) == 0 ||
3036 g_ascii_strncasecmp ((gchar *) data, "BMOD2STM", 8) == 0) {
3037 const guint8 *id, *stmtype;
3039 if ((id = gst_type_find_peek (tf, 28, 1)) == NULL)
3041 if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL)
3043 if (*id == 0x1A && *stmtype == 2)
3044 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3049 if ((data = gst_type_find_peek (tf, 0, 19)) != NULL) {
3050 if (memcmp (data, "ASYLUM Music Format", 19) == 0) {
3051 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3057 /*** application/x-shockwave-flash ***/
3059 static GstStaticCaps swf_caps =
3060 GST_STATIC_CAPS ("application/x-shockwave-flash");
3061 #define SWF_CAPS (gst_static_caps_get(&swf_caps))
3063 swf_type_find (GstTypeFind * tf, gpointer unused)
3065 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3067 if (data && (data[0] == 'F' || data[0] == 'C') &&
3068 data[1] == 'W' && data[2] == 'S') {
3069 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SWF_CAPS);
3073 /*** image/jpeg ***/
3075 #define JPEG_MARKER_IS_START_OF_FRAME(x) \
3076 ((x)>=0xc0 && (x) <= 0xcf && (x)!=0xc4 && (x)!=0xc8 && (x)!=0xcc)
3078 static GstStaticCaps jpeg_caps = GST_STATIC_CAPS ("image/jpeg");
3080 #define JPEG_CAPS (gst_static_caps_get(&jpeg_caps))
3082 jpeg_type_find (GstTypeFind * tf, gpointer unused)
3084 GstTypeFindProbability prob = GST_TYPE_FIND_POSSIBLE;
3085 DataScanCtx c = { 0, NULL, 0 };
3089 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 2)))
3092 if (c.data[0] != 0xff || c.data[1] != 0xd8)
3096 data_scan_ctx_advance (tf, &c, 2);
3098 caps = gst_caps_copy (JPEG_CAPS);
3100 while (data_scan_ctx_ensure_data (tf, &c, 4) && c.offset < (200 * 1024)) {
3104 if (c.data[0] != 0xff)
3108 if (G_UNLIKELY (marker == 0xff)) {
3109 data_scan_ctx_advance (tf, &c, 1);
3113 data_scan_ctx_advance (tf, &c, 2);
3115 /* we assume all markers we'll see before SOF have a payload length; if
3116 * that's not the case we'll just detect a false sync and bail out, but
3117 * still report POSSIBLE probability */
3118 len = GST_READ_UINT16_BE (c.data);
3120 GST_LOG ("possible JPEG marker 0x%02x (@0x%04x), segment length %u",
3121 marker, (guint) c.offset, len);
3123 if (!data_scan_ctx_ensure_data (tf, &c, len))
3126 if (marker == 0xc4 || /* DEFINE_HUFFMAN_TABLES */
3127 marker == 0xcc || /* DEFINE_ARITHMETIC_CONDITIONING */
3128 marker == 0xdb || /* DEFINE_QUANTIZATION_TABLES */
3129 marker == 0xdd || /* DEFINE_RESTART_INTERVAL */
3130 marker == 0xfe) { /* COMMENT */
3131 data_scan_ctx_advance (tf, &c, len);
3133 } else if (marker == 0xe0 && len >= (2 + 4) && /* APP0 */
3134 data_scan_ctx_memcmp (tf, &c, 2, "JFIF", 4)) {
3135 GST_LOG ("found JFIF tag");
3136 prob = GST_TYPE_FIND_MAXIMUM;
3137 data_scan_ctx_advance (tf, &c, len);
3139 /* we continue until we find a start of frame marker */
3140 } else if (marker == 0xe1 && len >= (2 + 4) && /* APP1 */
3141 data_scan_ctx_memcmp (tf, &c, 2, "Exif", 4)) {
3142 GST_LOG ("found Exif tag");
3143 prob = GST_TYPE_FIND_MAXIMUM;
3144 data_scan_ctx_advance (tf, &c, len);
3146 /* we continue until we find a start of frame marker */
3147 } else if (marker >= 0xe0 && marker <= 0xef) { /* APPn */
3148 data_scan_ctx_advance (tf, &c, len);
3150 } else if (JPEG_MARKER_IS_START_OF_FRAME (marker) && len >= (2 + 8)) {
3153 h = GST_READ_UINT16_BE (c.data + 2 + 1);
3154 w = GST_READ_UINT16_BE (c.data + 2 + 1 + 2);
3155 if (h == 0 || w == 0) {
3156 GST_WARNING ("bad width %u and/or height %u in SOF header", w, h);
3160 GST_LOG ("SOF at offset %" G_GUINT64_FORMAT ", num_markers=%d, "
3161 "WxH=%dx%d", c.offset - 2, num_markers, w, h);
3163 if (num_markers >= 5 || prob == GST_TYPE_FIND_MAXIMUM)
3164 prob = GST_TYPE_FIND_MAXIMUM;
3166 prob = GST_TYPE_FIND_LIKELY;
3168 gst_caps_set_simple (caps, "width", G_TYPE_INT, w,
3169 "height", G_TYPE_INT, h, "sof-marker", G_TYPE_INT, marker & 0xf,
3174 GST_WARNING ("bad length or unexpected JPEG marker 0xff 0x%02x", marker);
3179 gst_type_find_suggest (tf, prob, caps);
3180 gst_caps_unref (caps);
3185 static GstStaticCaps bmp_caps = GST_STATIC_CAPS ("image/bmp");
3187 #define BMP_CAPS (gst_static_caps_get(&bmp_caps))
3189 bmp_type_find (GstTypeFind * tf, gpointer unused)
3191 DataScanCtx c = { 0, NULL, 0 };
3192 guint32 struct_size, w, h, planes, bpp;
3194 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 54)))
3197 if (c.data[0] != 'B' || c.data[1] != 'M')
3200 /* skip marker + size */
3201 data_scan_ctx_advance (tf, &c, 2 + 4);
3203 /* reserved, must be 0 */
3204 if (c.data[0] != 0 || c.data[1] != 0 || c.data[2] != 0 || c.data[3] != 0)
3207 data_scan_ctx_advance (tf, &c, 2 + 2);
3209 /* offset to start of image data in bytes (check for sanity) */
3210 GST_LOG ("offset=%u", GST_READ_UINT32_LE (c.data));
3211 if (GST_READ_UINT32_LE (c.data) > (10 * 1024 * 1024))
3214 struct_size = GST_READ_UINT32_LE (c.data + 4);
3215 GST_LOG ("struct_size=%u", struct_size);
3217 data_scan_ctx_advance (tf, &c, 4 + 4);
3219 if (struct_size == 0x0C) {
3220 w = GST_READ_UINT16_LE (c.data);
3221 h = GST_READ_UINT16_LE (c.data + 2);
3222 planes = GST_READ_UINT16_LE (c.data + 2 + 2);
3223 bpp = GST_READ_UINT16_LE (c.data + 2 + 2 + 2);
3224 } else if (struct_size == 40 || struct_size == 64 || struct_size == 108
3225 || struct_size == 124 || struct_size == 0xF0) {
3226 w = GST_READ_UINT32_LE (c.data);
3227 h = GST_READ_UINT32_LE (c.data + 4);
3228 planes = GST_READ_UINT16_LE (c.data + 4 + 4);
3229 bpp = GST_READ_UINT16_LE (c.data + 4 + 4 + 2);
3234 /* image sizes sanity check */
3235 GST_LOG ("w=%u, h=%u, planes=%u, bpp=%u", w, h, planes, bpp);
3236 if (w == 0 || w > 0xfffff || h == 0 || h > 0xfffff || planes != 1 ||
3237 (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32))
3240 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "image/bmp",
3241 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, "bpp", G_TYPE_INT, bpp,
3245 /*** image/tiff ***/
3246 static GstStaticCaps tiff_caps = GST_STATIC_CAPS ("image/tiff, "
3247 "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }");
3248 #define TIFF_CAPS (gst_static_caps_get(&tiff_caps))
3249 static GstStaticCaps tiff_be_caps = GST_STATIC_CAPS ("image/tiff, "
3250 "endianness = (int) BIG_ENDIAN");
3251 #define TIFF_BE_CAPS (gst_static_caps_get(&tiff_be_caps))
3252 static GstStaticCaps tiff_le_caps = GST_STATIC_CAPS ("image/tiff, "
3253 "endianness = (int) LITTLE_ENDIAN");
3254 #define TIFF_LE_CAPS (gst_static_caps_get(&tiff_le_caps))
3256 tiff_type_find (GstTypeFind * tf, gpointer ununsed)
3258 const guint8 *data = gst_type_find_peek (tf, 0, 8);
3259 guint8 le_header[4] = { 0x49, 0x49, 0x2A, 0x00 };
3260 guint8 be_header[4] = { 0x4D, 0x4D, 0x00, 0x2A };
3263 if (memcmp (data, le_header, 4) == 0) {
3264 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_LE_CAPS);
3265 } else if (memcmp (data, be_header, 4) == 0) {
3266 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_BE_CAPS);
3273 static GstStaticCaps pnm_caps = GST_STATIC_CAPS ("image/x-portable-bitmap; "
3274 "image/x-portable-graymap; image/x-portable-pixmap; "
3275 "image/x-portable-anymap");
3277 #define PNM_CAPS (gst_static_caps_get(&pnm_caps))
3279 #define IS_PNM_WHITESPACE(c) \
3280 ((c) == ' ' || (c) == '\r' || (c) == '\n' || (c) == 't')
3283 pnm_type_find (GstTypeFind * tf, gpointer ununsed)
3285 const gchar *media_type = NULL;
3286 DataScanCtx c = { 0, NULL, 0 };
3289 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
3292 /* see http://en.wikipedia.org/wiki/Netpbm_format */
3293 if (c.data[0] != 'P' || c.data[1] < '1' || c.data[1] > '7' ||
3294 !IS_PNM_WHITESPACE (c.data[2]) ||
3295 (c.data[3] != '#' && c.data[3] < '0' && c.data[3] > '9'))
3298 switch (c.data[1]) {
3300 media_type = "image/x-portable-bitmap"; /* ASCII */
3303 media_type = "image/x-portable-graymap"; /* ASCII */
3306 media_type = "image/x-portable-pixmap"; /* ASCII */
3309 media_type = "image/x-portable-bitmap"; /* Raw */
3312 media_type = "image/x-portable-graymap"; /* Raw */
3315 media_type = "image/x-portable-pixmap"; /* Raw */
3318 media_type = "image/x-portable-anymap";
3321 g_return_if_reached ();
3324 /* try to extract width and height as well */
3325 if (c.data[1] != '7') {
3326 gchar s[64] = { 0, }
3329 /* need to skip any comment lines first */
3330 data_scan_ctx_advance (tf, &c, 3);
3331 while (c.data[0] == '#') { /* we know there's still data left */
3332 data_scan_ctx_advance (tf, &c, 1);
3333 while (c.data[0] != '\n' && c.data[0] != '\r') {
3334 if (!data_scan_ctx_ensure_data (tf, &c, 4))
3336 data_scan_ctx_advance (tf, &c, 1);
3338 data_scan_ctx_advance (tf, &c, 1);
3339 GST_LOG ("skipped comment line in PNM header");
3342 if (!data_scan_ctx_ensure_data (tf, &c, 32) &&
3343 !data_scan_ctx_ensure_data (tf, &c, 4)) {
3347 /* need to NUL-terminate data for sscanf */
3348 memcpy (s, c.data, MIN (sizeof (s) - 1, c.size));
3349 if (sscanf (s, "%u%c%u%c", &w, &sep1, &h, &sep2) == 4 &&
3350 IS_PNM_WHITESPACE (sep1) && IS_PNM_WHITESPACE (sep2) &&
3351 w > 0 && w < G_MAXINT && h > 0 && h < G_MAXINT) {
3352 GST_LOG ("extracted PNM width and height: %dx%d", w, h);
3358 /* FIXME: extract width + height for anymaps too */
3361 if (w > 0 && h > 0) {
3362 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type,
3363 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, NULL);
3365 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, media_type, NULL);
3369 static GstStaticCaps sds_caps = GST_STATIC_CAPS ("audio/x-sds");
3371 #define SDS_CAPS (gst_static_caps_get(&sds_caps))
3373 sds_type_find (GstTypeFind * tf, gpointer ununsed)
3375 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3376 guint8 mask[4] = { 0xFF, 0xFF, 0x80, 0xFF };
3377 guint8 match[4] = { 0xF0, 0x7E, 0, 0x01 };
3381 for (x = 0; x < 4; x++) {
3382 if ((data[x] & mask[x]) != match[x]) {
3386 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDS_CAPS);
3390 static GstStaticCaps ircam_caps = GST_STATIC_CAPS ("audio/x-ircam");
3392 #define IRCAM_CAPS (gst_static_caps_get(&ircam_caps))
3394 ircam_type_find (GstTypeFind * tf, gpointer ununsed)
3396 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3397 guint8 mask[4] = { 0xFF, 0xFF, 0xF8, 0xFF };
3398 guint8 match[4] = { 0x64, 0xA3, 0x00, 0x00 };
3400 gboolean matched = TRUE;
3405 for (x = 0; x < 4; x++) {
3406 if ((data[x] & mask[x]) != match[x]) {
3411 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, IRCAM_CAPS);
3414 /* now try the reverse version */
3416 for (x = 0; x < 4; x++) {
3417 if ((data[x] & mask[3 - x]) != match[3 - x]) {
3423 /* EBML typefind helper */
3425 ebml_check_header (GstTypeFind * tf, const gchar * doctype, int doctype_len)
3427 /* 4 bytes for EBML ID, 1 byte for header length identifier */
3428 const guint8 *data = gst_type_find_peek (tf, 0, 4 + 1);
3429 gint len_mask = 0x80, size = 1, n = 1, total;
3435 if (data[0] != 0x1A || data[1] != 0x45 || data[2] != 0xDF || data[3] != 0xA3)
3438 /* length of header */
3440 while (size <= 8 && !(total & len_mask)) {
3446 total &= (len_mask - 1);
3448 total = (total << 8) | data[4 + n++];
3450 /* get new data for full header, 4 bytes for EBML ID,
3451 * EBML length tag and the actual header */
3452 data = gst_type_find_peek (tf, 0, 4 + size + total);
3456 /* only check doctype if asked to do so */
3457 if (doctype == NULL || doctype_len == 0)
3460 /* the header must contain the doctype. For now, we don't parse the
3461 * whole header but simply check for the availability of that array
3462 * of characters inside the header. Not fully fool-proof, but good
3464 for (n = 4 + size; n <= 4 + size + total - doctype_len; n++)
3465 if (!memcmp (&data[n], doctype, doctype_len))
3471 /*** video/x-matroska ***/
3472 static GstStaticCaps matroska_caps = GST_STATIC_CAPS ("video/x-matroska");
3474 #define MATROSKA_CAPS (gst_static_caps_get(&matroska_caps))
3476 matroska_type_find (GstTypeFind * tf, gpointer ununsed)
3478 if (ebml_check_header (tf, "matroska", 8))
3479 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MATROSKA_CAPS);
3480 else if (ebml_check_header (tf, NULL, 0))
3481 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MATROSKA_CAPS);
3484 /*** video/webm ***/
3485 static GstStaticCaps webm_caps = GST_STATIC_CAPS ("video/webm");
3487 #define WEBM_CAPS (gst_static_caps_get(&webm_caps))
3489 webm_type_find (GstTypeFind * tf, gpointer ununsed)
3491 if (ebml_check_header (tf, "webm", 4))
3492 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, WEBM_CAPS);
3495 /*** application/mxf ***/
3496 static GstStaticCaps mxf_caps = GST_STATIC_CAPS ("application/mxf");
3498 #define MXF_MAX_PROBE_LENGTH (1024 * 64)
3499 #define MXF_CAPS (gst_static_caps_get(&mxf_caps))
3502 * MXF files start with a header partition pack key of 16 bytes which is defined
3503 * at SMPTE-377M 6.1. Before this there can be up to 64K of run-in which _must_
3504 * not contain the partition pack key.
3507 mxf_type_find (GstTypeFind * tf, gpointer ununsed)
3509 static const guint8 partition_pack_key[] =
3510 { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
3513 DataScanCtx c = { 0, NULL, 0 };
3515 while (c.offset <= MXF_MAX_PROBE_LENGTH) {
3517 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 1024)))
3520 /* look over in chunks of 1kbytes to avoid too much overhead */
3522 for (i = 0; i < 1024 - 16; i++) {
3523 /* Check first byte before calling more expensive memcmp function */
3524 if (G_UNLIKELY (c.data[i] == 0x06
3525 && memcmp (c.data + i, partition_pack_key, 13) == 0)) {
3526 /* Header partition pack? */
3527 if (c.data[i + 13] != 0x02)
3530 /* Partition status */
3531 if (c.data[i + 14] >= 0x05)
3534 /* Reserved, must be 0x00 */
3535 if (c.data[i + 15] != 0x00)
3538 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
3544 data_scan_ctx_advance (tf, &c, 1024 - 16);
3548 /*** video/x-dv ***/
3550 static GstStaticCaps dv_caps = GST_STATIC_CAPS ("video/x-dv, "
3551 "systemstream = (boolean) true");
3552 #define DV_CAPS (gst_static_caps_get(&dv_caps))
3554 dv_type_find (GstTypeFind * tf, gpointer private)
3558 data = gst_type_find_peek (tf, 0, 5);
3560 /* check for DIF and DV flag */
3561 if (data && (data[0] == 0x1f) && (data[1] == 0x07) && (data[2] == 0x00)) {
3562 const gchar *format;
3564 if (data[3] & 0x80) {
3570 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "video/x-dv",
3571 "systemstream", G_TYPE_BOOLEAN, TRUE,
3572 "format", G_TYPE_STRING, format, NULL);
3577 /*** application/ogg and application/x-annodex ***/
3578 static GstStaticCaps ogg_caps = GST_STATIC_CAPS ("application/ogg");
3579 static GstStaticCaps annodex_caps = GST_STATIC_CAPS ("application/x-annodex");
3580 static GstStaticCaps ogg_annodex_caps =
3581 GST_STATIC_CAPS ("application/ogg;application/x-annodex");
3583 #define OGGANX_CAPS (gst_static_caps_get(&ogg_annodex_caps))
3586 ogganx_type_find (GstTypeFind * tf, gpointer private)
3588 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3590 if ((data != NULL) && (memcmp (data, "OggS", 4) == 0)) {
3592 /* Check for an annodex fishbone header */
3593 data = gst_type_find_peek (tf, 28, 8);
3594 if (data && memcmp (data, "fishead\0", 8) == 0)
3595 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
3596 gst_static_caps_get (&annodex_caps));
3598 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
3599 gst_static_caps_get (&ogg_caps));
3603 /*** audio/x-vorbis ***/
3604 static GstStaticCaps vorbis_caps = GST_STATIC_CAPS ("audio/x-vorbis");
3606 #define VORBIS_CAPS (gst_static_caps_get(&vorbis_caps))
3608 vorbis_type_find (GstTypeFind * tf, gpointer private)
3610 const guint8 *data = gst_type_find_peek (tf, 0, 30);
3616 /* 1 byte packet type (identification=0x01)
3617 6 byte string "vorbis"
3618 4 byte vorbis version */
3619 if (memcmp (data, "\001vorbis\000\000\000\000", 11) != 0)
3622 /* 1 byte channels must be != 0 */
3626 /* 4 byte samplerate must be != 0 */
3627 if (GST_READ_UINT32_LE (data) == 0)
3630 /* blocksize checks */
3631 blocksize_0 = data[0] & 0x0F;
3632 blocksize_1 = (data[0] & 0xF0) >> 4;
3633 if (blocksize_0 > blocksize_1)
3635 if (blocksize_0 < 6 || blocksize_0 > 13)
3637 if (blocksize_1 < 6 || blocksize_1 > 13)
3641 if ((data[0] & 0x01) != 1)
3643 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VORBIS_CAPS);
3647 /*** video/x-theora ***/
3649 static GstStaticCaps theora_caps = GST_STATIC_CAPS ("video/x-theora");
3651 #define THEORA_CAPS (gst_static_caps_get(&theora_caps))
3653 theora_type_find (GstTypeFind * tf, gpointer private)
3655 const guint8 *data = gst_type_find_peek (tf, 0, 7); //42);
3658 if (data[0] != 0x80)
3660 if (memcmp (&data[1], "theora", 6) != 0)
3662 /* FIXME: make this more reliable when specs are out */
3664 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, THEORA_CAPS);
3670 kate_type_find (GstTypeFind * tf, gpointer private)
3672 const guint8 *data = gst_type_find_peek (tf, 0, 64);
3673 gchar category[16] = { 0, };
3675 if (G_UNLIKELY (data == NULL))
3678 /* see: http://wiki.xiph.org/index.php/OggKate#Format_specification */
3679 if (G_LIKELY (memcmp (data, "\200kate\0\0\0", 8) != 0))
3682 /* make sure we always have a NUL-terminated string */
3683 memcpy (category, data + 48, 15);
3684 GST_LOG ("kate category: %s", category);
3685 /* canonical categories for subtitles: subtitles, spu-subtitles, SUB, K-SPU */
3686 if (strcmp (category, "subtitles") == 0 || strcmp (category, "SUB") == 0 ||
3687 strcmp (category, "spu-subtitles") == 0 ||
3688 strcmp (category, "K-SPU") == 0) {
3689 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3690 "subtitle/x-kate", NULL);
3692 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3693 "application/x-kate", NULL);
3697 /*** application/x-ogm-video or audio***/
3699 static GstStaticCaps ogmvideo_caps =
3700 GST_STATIC_CAPS ("application/x-ogm-video");
3701 #define OGMVIDEO_CAPS (gst_static_caps_get(&ogmvideo_caps))
3703 ogmvideo_type_find (GstTypeFind * tf, gpointer private)
3705 const guint8 *data = gst_type_find_peek (tf, 0, 9);
3708 if (memcmp (data, "\001video\000\000\000", 9) != 0)
3710 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMVIDEO_CAPS);
3714 static GstStaticCaps ogmaudio_caps =
3715 GST_STATIC_CAPS ("application/x-ogm-audio");
3716 #define OGMAUDIO_CAPS (gst_static_caps_get(&ogmaudio_caps))
3718 ogmaudio_type_find (GstTypeFind * tf, gpointer private)
3720 const guint8 *data = gst_type_find_peek (tf, 0, 9);
3723 if (memcmp (data, "\001audio\000\000\000", 9) != 0)
3725 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMAUDIO_CAPS);
3729 static GstStaticCaps ogmtext_caps = GST_STATIC_CAPS ("application/x-ogm-text");
3731 #define OGMTEXT_CAPS (gst_static_caps_get(&ogmtext_caps))
3733 ogmtext_type_find (GstTypeFind * tf, gpointer private)
3735 const guint8 *data = gst_type_find_peek (tf, 0, 9);
3738 if (memcmp (data, "\001text\000\000\000\000", 9) != 0)
3740 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMTEXT_CAPS);
3744 /*** audio/x-speex ***/
3746 static GstStaticCaps speex_caps = GST_STATIC_CAPS ("audio/x-speex");
3748 #define SPEEX_CAPS (gst_static_caps_get(&speex_caps))
3750 speex_type_find (GstTypeFind * tf, gpointer private)
3752 const guint8 *data = gst_type_find_peek (tf, 0, 80);
3755 /* 8 byte string "Speex "
3756 24 byte speex version string + int */
3757 if (memcmp (data, "Speex ", 8) != 0)
3761 /* 4 byte header size >= 80 */
3762 if (GST_READ_UINT32_LE (data) < 80)
3766 /* 4 byte sample rate <= 48000 */
3767 if (GST_READ_UINT32_LE (data) > 48000)
3771 /* currently there are only 3 speex modes. */
3772 if (GST_READ_UINT32_LE (data) > 3)
3776 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SPEEX_CAPS);
3780 /*** audio/x-celt ***/
3782 static GstStaticCaps celt_caps = GST_STATIC_CAPS ("audio/x-celt");
3784 #define CELT_CAPS (gst_static_caps_get(&celt_caps))
3786 celt_type_find (GstTypeFind * tf, gpointer private)
3788 const guint8 *data = gst_type_find_peek (tf, 0, 8);
3791 /* 8 byte string "CELT " */
3792 if (memcmp (data, "CELT ", 8) != 0)
3795 /* TODO: Check other values of the CELT header */
3796 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CELT_CAPS);
3800 /*** application/x-ogg-skeleton ***/
3801 static GstStaticCaps ogg_skeleton_caps =
3802 GST_STATIC_CAPS ("application/x-ogg-skeleton, parsed=(boolean)FALSE");
3803 #define OGG_SKELETON_CAPS (gst_static_caps_get(&ogg_skeleton_caps))
3805 oggskel_type_find (GstTypeFind * tf, gpointer private)
3807 const guint8 *data = gst_type_find_peek (tf, 0, 12);
3810 /* 8 byte string "fishead\0" for the ogg skeleton stream */
3811 if (memcmp (data, "fishead\0", 8) != 0)
3815 /* Require that the header contains version 3.0 */
3816 if (GST_READ_UINT16_LE (data) != 3)
3819 if (GST_READ_UINT16_LE (data) != 0)
3822 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGG_SKELETON_CAPS);
3826 static GstStaticCaps cmml_caps = GST_STATIC_CAPS ("text/x-cmml");
3828 #define CMML_CAPS (gst_static_caps_get(&cmml_caps))
3830 cmml_type_find (GstTypeFind * tf, gpointer private)
3832 /* Header is 12 bytes minimum (though we don't check the minor version */
3833 const guint8 *data = gst_type_find_peek (tf, 0, 12);
3837 /* 8 byte string "CMML\0\0\0\0" for the magic number */
3838 if (memcmp (data, "CMML\0\0\0\0", 8) != 0)
3842 /* Require that the header contains at least version 2.0 */
3843 if (GST_READ_UINT16_LE (data) < 2)
3846 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CMML_CAPS);
3850 /*** application/x-tar ***/
3852 static GstStaticCaps tar_caps = GST_STATIC_CAPS ("application/x-tar");
3854 #define TAR_CAPS (gst_static_caps_get(&tar_caps))
3855 #define OLDGNU_MAGIC "ustar " /* 7 chars and a NUL */
3856 #define NEWGNU_MAGIC "ustar" /* 5 chars and a NUL */
3858 tar_type_find (GstTypeFind * tf, gpointer unused)
3860 const guint8 *data = gst_type_find_peek (tf, 257, 8);
3862 /* of course we are not certain, but we don't want other typefind funcs
3863 * to detect formats of files within the tar archive, e.g. mp3s */
3865 if (memcmp (data, OLDGNU_MAGIC, 8) == 0) { /* sic */
3866 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3867 } else if (memcmp (data, NEWGNU_MAGIC, 6) == 0 && /* sic */
3868 g_ascii_isdigit (data[6]) && g_ascii_isdigit (data[7])) {
3869 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3874 /*** application/x-ar ***/
3876 static GstStaticCaps ar_caps = GST_STATIC_CAPS ("application/x-ar");
3878 #define AR_CAPS (gst_static_caps_get(&ar_caps))
3880 ar_type_find (GstTypeFind * tf, gpointer unused)
3882 const guint8 *data = gst_type_find_peek (tf, 0, 24);
3884 if (data && memcmp (data, "!<arch>", 7) == 0) {
3887 for (i = 7; i < 24; ++i) {
3888 if (!g_ascii_isprint (data[i]) && data[i] != '\n') {
3889 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AR_CAPS);
3893 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AR_CAPS);
3897 /*** audio/x-au ***/
3899 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3900 * as it is only possible to register one typefind factory per 'name'
3901 * (which is in this case the caps), and the first one would be replaced by
3902 * the second one. */
3903 static GstStaticCaps au_caps = GST_STATIC_CAPS ("audio/x-au");
3905 #define AU_CAPS (gst_static_caps_get(&au_caps))
3907 au_type_find (GstTypeFind * tf, gpointer unused)
3909 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3912 if (memcmp (data, ".snd", 4) == 0 || memcmp (data, "dns.", 4) == 0) {
3913 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AU_CAPS);
3919 /*** video/x-nuv ***/
3921 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3922 * as it is only possible to register one typefind factory per 'name'
3923 * (which is in this case the caps), and the first one would be replaced by
3924 * the second one. */
3925 static GstStaticCaps nuv_caps = GST_STATIC_CAPS ("video/x-nuv");
3927 #define NUV_CAPS (gst_static_caps_get(&nuv_caps))
3929 nuv_type_find (GstTypeFind * tf, gpointer unused)
3931 const guint8 *data = gst_type_find_peek (tf, 0, 11);
3934 if (memcmp (data, "MythTVVideo", 11) == 0
3935 || memcmp (data, "NuppelVideo", 11) == 0) {
3936 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, NUV_CAPS);
3941 /*** audio/x-paris ***/
3942 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3943 static GstStaticCaps paris_caps = GST_STATIC_CAPS ("audio/x-paris");
3945 #define PARIS_CAPS (gst_static_caps_get(&paris_caps))
3947 paris_type_find (GstTypeFind * tf, gpointer unused)
3949 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3952 if (memcmp (data, " paf", 4) == 0 || memcmp (data, "fap ", 4) == 0) {
3953 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, PARIS_CAPS);
3958 /*** audio/iLBC-sh ***/
3959 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3960 static GstStaticCaps ilbc_caps = GST_STATIC_CAPS ("audio/iLBC-sh");
3962 #define ILBC_CAPS (gst_static_caps_get(&ilbc_caps))
3964 ilbc_type_find (GstTypeFind * tf, gpointer unused)
3966 const guint8 *data = gst_type_find_peek (tf, 0, 8);
3969 if (memcmp (data, "#!iLBC30", 8) == 0 || memcmp (data, "#!iLBC20", 8) == 0) {
3970 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, ILBC_CAPS);
3975 /*** application/x-ms-dos-executable ***/
3977 static GstStaticCaps msdos_caps =
3978 GST_STATIC_CAPS ("application/x-ms-dos-executable");
3979 #define MSDOS_CAPS (gst_static_caps_get(&msdos_caps))
3980 /* see http://www.madchat.org/vxdevl/papers/winsys/pefile/pefile.htm */
3982 msdos_type_find (GstTypeFind * tf, gpointer unused)
3984 const guint8 *data = gst_type_find_peek (tf, 0, 64);
3986 if (data && data[0] == 'M' && data[1] == 'Z' &&
3987 GST_READ_UINT16_LE (data + 8) == 4) {
3988 guint32 pe_offset = GST_READ_UINT32_LE (data + 60);
3990 data = gst_type_find_peek (tf, pe_offset, 2);
3991 if (data && data[0] == 'P' && data[1] == 'E') {
3992 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, MSDOS_CAPS);
3997 /*** application/x-mmsh ***/
3999 static GstStaticCaps mmsh_caps = GST_STATIC_CAPS ("application/x-mmsh");
4001 #define MMSH_CAPS gst_static_caps_get(&mmsh_caps)
4003 /* This is to recognise mssh-over-http */
4005 mmsh_type_find (GstTypeFind * tf, gpointer unused)
4007 static const guint8 asf_marker[16] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66,
4008 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
4013 data = gst_type_find_peek (tf, 0, 2 + 2 + 4 + 2 + 2 + 16);
4014 if (data && data[0] == 0x24 && data[1] == 0x48 &&
4015 GST_READ_UINT16_LE (data + 2) > 2 + 2 + 4 + 2 + 2 + 16 &&
4016 memcmp (data + 2 + 2 + 4 + 2 + 2, asf_marker, 16) == 0) {
4017 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MMSH_CAPS);
4021 /*** video/x-dirac ***/
4023 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
4024 * as it is only possible to register one typefind factory per 'name'
4025 * (which is in this case the caps), and the first one would be replaced by
4026 * the second one. */
4027 static GstStaticCaps dirac_caps = GST_STATIC_CAPS ("video/x-dirac");
4029 #define DIRAC_CAPS (gst_static_caps_get(&dirac_caps))
4031 dirac_type_find (GstTypeFind * tf, gpointer unused)
4033 const guint8 *data = gst_type_find_peek (tf, 0, 8);
4036 if (memcmp (data, "BBCD", 4) == 0 || memcmp (data, "KW-DIRAC", 8) == 0) {
4037 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DIRAC_CAPS);
4042 /*** video/vivo ***/
4044 static GstStaticCaps vivo_caps = GST_STATIC_CAPS ("video/vivo");
4046 #define VIVO_CAPS gst_static_caps_get(&vivo_caps)
4049 vivo_type_find (GstTypeFind * tf, gpointer unused)
4051 static const guint8 vivo_marker[] = { 'V', 'e', 'r', 's', 'i', 'o', 'n',
4052 ':', 'V', 'i', 'v', 'o', '/'
4057 data = gst_type_find_peek (tf, 0, 1024);
4058 if (data == NULL || data[0] != 0x00)
4061 if ((data[1] & 0x80)) {
4062 if ((data[2] & 0x80))
4064 hdr_len = ((guint) (data[1] & 0x7f)) << 7;
4074 /* 1008 = 1022 - strlen ("Version:Vivo/") - 1 */
4075 while (pos < 1008 && data[pos] == '\r' && data[pos + 1] == '\n')
4078 if (memcmp (data + pos, vivo_marker, sizeof (vivo_marker)) == 0) {
4079 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VIVO_CAPS);
4083 /*** XDG MIME typefinder (to avoid false positives mostly) ***/
4087 xdgmime_typefind (GstTypeFind * find, gpointer user_data)
4090 gsize length = 16384;
4095 if ((tf_length = gst_type_find_get_length (find)) > 0)
4096 length = MIN (length, tf_length);
4098 if ((data = gst_type_find_peek (find, 0, length)) == NULL)
4101 tmp = g_content_type_guess (NULL, data, length, NULL);
4102 if (tmp == NULL || g_content_type_is_unknown (tmp)) {
4107 mimetype = g_content_type_get_mime_type (tmp);
4110 if (mimetype == NULL)
4113 GST_DEBUG ("Got mimetype '%s'", mimetype);
4115 /* Ignore audio/video types:
4116 * - our own typefinders in -base are likely to be better at this
4117 * (and if they're not, we really want to fix them, that's why we don't
4118 * report xdg-detected audio/video types at all, not even with a low
4120 * - we want to detect GStreamer media types and not MIME types
4121 * - the purpose of this xdg mime finder is mainly to prevent false
4122 * positives of non-media formats, not to typefind audio/video formats */
4123 if (g_str_has_prefix (mimetype, "audio/") ||
4124 g_str_has_prefix (mimetype, "video/")) {
4125 GST_LOG ("Ignoring audio/video mime type");
4130 /* Again, we mainly want the xdg typefinding to prevent false-positives on
4131 * non-media formats, so suggest the type with a probability that trumps
4132 * uncertain results of our typefinders, but not more than that. */
4133 GST_LOG ("Suggesting '%s' with probability POSSIBLE", mimetype);
4134 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE, mimetype, NULL);
4137 #endif /* USE_GIO */
4139 /*** Windows icon typefinder (to avoid false positives mostly) ***/
4142 windows_icon_typefind (GstTypeFind * find, gpointer user_data)
4146 guint16 type, nimages;
4147 gint32 size, offset;
4149 datalen = gst_type_find_get_length (find);
4150 if ((data = gst_type_find_peek (find, 0, 6)) == NULL)
4153 /* header - simple and not enough to rely on it alone */
4154 if (GST_READ_UINT16_LE (data) != 0)
4156 type = GST_READ_UINT16_LE (data + 2);
4157 if (type != 1 && type != 2)
4159 nimages = GST_READ_UINT16_LE (data + 4);
4160 if (nimages == 0) /* we can assume we can't have an empty image file ? */
4164 if (data[6 + 3] != 0)
4167 guint16 planes = GST_READ_UINT16_LE (data + 6 + 4);
4171 size = GST_READ_UINT32_LE (data + 6 + 8);
4172 offset = GST_READ_UINT32_LE (data + 6 + 12);
4173 if (offset < 0 || size <= 0 || size >= datalen || offset >= datalen
4174 || size + offset > datalen)
4177 gst_type_find_suggest_simple (find, GST_TYPE_FIND_NEARLY_CERTAIN,
4178 "image/x-icon", NULL);
4181 /*** WAP WBMP typefinder ***/
4184 wbmp_typefind (GstTypeFind * find, gpointer user_data)
4190 /* http://en.wikipedia.org/wiki/Wireless_Application_Protocol_Bitmap_Format */
4191 datalen = gst_type_find_get_length (find);
4195 data = gst_type_find_peek (find, 0, 5);
4199 /* want 0x00 0x00 at start */
4200 if (*data++ != 0 || *data++ != 0)
4203 /* min header size */
4206 /* let's assume max width/height is 65536 */
4209 w = (w << 8) | *data++;
4213 data = gst_type_find_peek (find, 4, 2);
4219 h = (h << 8) | *data++;
4225 if (w == 0 || h == 0)
4228 /* now add bitmap size */
4229 size += h * (GST_ROUND_UP_8 (w) / 8);
4231 if (datalen == size) {
4232 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE - 10,
4233 "image/vnd.wap.wbmp", NULL);
4237 /*** DEGAS Atari images (also to avoid false positives, see #625129) ***/
4239 degas_type_find (GstTypeFind * tf, gpointer private)
4241 /* No magic, but it should have a fixed size and a few invalid values */
4242 /* http://www.fileformat.info/format/atari/spec/6ecf9f6eb5be494284a47feb8a214687/view.htm */
4248 len = gst_type_find_get_length (tf);
4249 if (len < 34) /* smallest header of the lot */
4251 data = gst_type_find_peek (tf, 0, 4);
4252 if (G_UNLIKELY (data == NULL))
4254 resolution = GST_READ_UINT16_BE (data);
4256 /* could be DEGAS */
4257 if (resolution <= 2)
4258 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
4259 "image/x-degas", NULL);
4260 } else if (len == 32066) {
4261 /* could be DEGAS Elite */
4262 if (resolution <= 2) {
4263 data = gst_type_find_peek (tf, len - 16, 8);
4264 if (G_UNLIKELY (data == NULL))
4266 for (n = 0; n < 4; n++) {
4267 if (GST_READ_UINT16_BE (data + n * 2) > 2)
4270 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
4271 "image/x-degas", NULL);
4273 } else if (len >= 66 && len < 32066) {
4274 /* could be compressed DEGAS Elite, but it's compressed and so we can't rely on size,
4275 it does have 4 16 bytes values near the end that are 0-2 though. */
4276 if ((resolution & 0x8000) && (resolution & 0x7fff) <= 2) {
4277 data = gst_type_find_peek (tf, len - 16, 8);
4278 if (G_UNLIKELY (data == NULL))
4280 for (n = 0; n < 4; n++) {
4281 if (GST_READ_UINT16_BE (data + n * 2) > 2)
4284 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
4285 "image/x-degas", NULL);
4290 /*** generic typefind for streams that have some data at a specific position***/
4301 start_with_type_find (GstTypeFind * tf, gpointer private)
4303 GstTypeFindData *start_with = (GstTypeFindData *) private;
4306 GST_LOG ("trying to find mime type %s with the first %u bytes of data",
4307 gst_structure_get_name (gst_caps_get_structure (start_with->caps, 0)),
4309 data = gst_type_find_peek (tf, 0, start_with->size);
4310 if (data && memcmp (data, start_with->data, start_with->size) == 0) {
4311 gst_type_find_suggest (tf, start_with->probability, start_with->caps);
4316 sw_data_destroy (GstTypeFindData * sw_data)
4318 if (G_LIKELY (sw_data->caps != NULL))
4319 gst_caps_unref (sw_data->caps);
4323 #define TYPE_FIND_REGISTER_START_WITH(plugin,name,rank,ext,_data,_size,_probability)\
4325 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
4326 sw_data->data = (const guint8 *)_data; \
4327 sw_data->size = _size; \
4328 sw_data->probability = _probability; \
4329 sw_data->caps = gst_caps_new_empty_simple (name); \
4330 if (!gst_type_find_register (plugin, name, rank, start_with_type_find,\
4331 (char **) ext, sw_data->caps, sw_data, \
4332 (GDestroyNotify) (sw_data_destroy))) { \
4333 gst_caps_unref (sw_data->caps); \
4338 /*** same for riff types ***/
4341 riff_type_find (GstTypeFind * tf, gpointer private)
4343 GstTypeFindData *riff_data = (GstTypeFindData *) private;
4344 const guint8 *data = gst_type_find_peek (tf, 0, 12);
4346 if (data && (memcmp (data, "RIFF", 4) == 0 || memcmp (data, "AVF0", 4) == 0)) {
4348 if (memcmp (data, riff_data->data, 4) == 0)
4349 gst_type_find_suggest (tf, riff_data->probability, riff_data->caps);
4353 #define TYPE_FIND_REGISTER_RIFF(plugin,name,rank,ext,_data) \
4355 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
4356 sw_data->data = (gpointer)_data; \
4357 sw_data->size = 4; \
4358 sw_data->probability = GST_TYPE_FIND_MAXIMUM; \
4359 sw_data->caps = gst_caps_new_empty_simple (name); \
4360 if (!gst_type_find_register (plugin, name, rank, riff_type_find, \
4361 (char **) ext, sw_data->caps, sw_data, \
4362 (GDestroyNotify) (sw_data_destroy))) { \
4363 gst_caps_unref (sw_data->caps); \
4369 /*** plugin initialization ***/
4371 #define TYPE_FIND_REGISTER(plugin,name,rank,func,ext,caps,priv,notify) \
4373 if (!gst_type_find_register (plugin, name, rank, func, (char **) ext, caps, priv, notify))\
4379 plugin_init (GstPlugin * plugin)
4381 /* can't initialize this via a struct as caps can't be statically initialized */
4383 /* note: asx/wax/wmx are XML files, asf doesn't handle them */
4384 /* FIXME-0.11: these should be const,
4385 this requires gstreamer/gst/gsttypefind::gst_type_find_register()
4386 to have define the parameter as const
4388 static const gchar *asf_exts[] = { "asf", "wm", "wma", "wmv", NULL };
4389 static const gchar *au_exts[] = { "au", "snd", NULL };
4390 static const gchar *avi_exts[] = { "avi", NULL };
4391 static const gchar *qcp_exts[] = { "qcp", NULL };
4392 static const gchar *cdxa_exts[] = { "dat", NULL };
4393 static const gchar *flac_exts[] = { "flac", NULL };
4394 static const gchar *flx_exts[] = { "flc", "fli", NULL };
4395 static const gchar *id3_exts[] =
4396 { "mp3", "mp2", "mp1", "mpga", "ogg", "flac", "tta", NULL };
4397 static const gchar *apetag_exts[] = { "mp3", "ape", "mpc", "wv", NULL };
4398 static const gchar *tta_exts[] = { "tta", NULL };
4399 static const gchar *mod_exts[] = { "669", "amf", "dsm", "gdm", "far", "imf",
4400 "it", "med", "mod", "mtm", "okt", "sam",
4401 "s3m", "stm", "stx", "ult", "xm", NULL
4403 static const gchar *mp3_exts[] = { "mp3", "mp2", "mp1", "mpga", NULL };
4404 static const gchar *ac3_exts[] = { "ac3", "eac3", NULL };
4405 static const gchar *dts_exts[] = { "dts", NULL };
4406 static const gchar *gsm_exts[] = { "gsm", NULL };
4407 static const gchar *musepack_exts[] = { "mpc", "mpp", "mp+", NULL };
4408 static const gchar *mpeg_sys_exts[] = { "mpe", "mpeg", "mpg", NULL };
4409 static const gchar *mpeg_video_exts[] = { "mpv", "mpeg", "mpg", NULL };
4410 static const gchar *mpeg_ts_exts[] = { "ts", "mts", NULL };
4411 static const gchar *ogg_exts[] = { "anx", "ogg", "ogm", NULL };
4412 static const gchar *qt_exts[] = { "mov", NULL };
4413 static const gchar *qtif_exts[] = { "qif", "qtif", "qti", NULL };
4414 static const gchar *mj2_exts[] = { "mj2", NULL };
4415 static const gchar *jp2_exts[] = { "jp2", NULL };
4416 static const gchar *rm_exts[] = { "ra", "ram", "rm", "rmvb", NULL };
4417 static const gchar *swf_exts[] = { "swf", "swfl", NULL };
4418 static const gchar *utf8_exts[] = { "txt", NULL };
4419 static const gchar *unicode_exts[] = { "txt", NULL };
4420 static const gchar *wav_exts[] = { "wav", NULL };
4421 static const gchar *aiff_exts[] = { "aiff", "aif", "aifc", NULL };
4422 static const gchar *svx_exts[] = { "iff", "svx", NULL };
4423 static const gchar *paris_exts[] = { "paf", NULL };
4424 static const gchar *nist_exts[] = { "nist", NULL };
4425 static const gchar *voc_exts[] = { "voc", NULL };
4426 static const gchar *sds_exts[] = { "sds", NULL };
4427 static const gchar *ircam_exts[] = { "sf", NULL };
4428 static const gchar *w64_exts[] = { "w64", NULL };
4429 static const gchar *shn_exts[] = { "shn", NULL };
4430 static const gchar *ape_exts[] = { "ape", NULL };
4431 static const gchar *uri_exts[] = { "ram", NULL };
4432 static const gchar *hls_exts[] = { "m3u8", NULL };
4433 static const gchar *sdp_exts[] = { "sdp", NULL };
4434 static const gchar *smil_exts[] = { "smil", NULL };
4435 static const gchar *html_exts[] = { "htm", "html", NULL };
4436 static const gchar *xml_exts[] = { "xml", NULL };
4437 static const gchar *jpeg_exts[] = { "jpg", "jpe", "jpeg", NULL };
4438 static const gchar *gif_exts[] = { "gif", NULL };
4439 static const gchar *png_exts[] = { "png", NULL };
4440 static const gchar *bmp_exts[] = { "bmp", NULL };
4441 static const gchar *tiff_exts[] = { "tif", "tiff", NULL };
4442 static const gchar *matroska_exts[] = { "mkv", "mka", NULL };
4443 static const gchar *webm_exts[] = { "webm", NULL };
4444 static const gchar *mve_exts[] = { "mve", NULL };
4445 static const gchar *dv_exts[] = { "dv", "dif", NULL };
4446 static const gchar *amr_exts[] = { "amr", NULL };
4447 static const gchar *ilbc_exts[] = { "ilbc", NULL };
4448 static const gchar *sid_exts[] = { "sid", NULL };
4449 static const gchar *xcf_exts[] = { "xcf", NULL };
4450 static const gchar *mng_exts[] = { "mng", NULL };
4451 static const gchar *jng_exts[] = { "jng", NULL };
4452 static const gchar *xpm_exts[] = { "xpm", NULL };
4453 static const gchar *pnm_exts[] = { "pnm", "ppm", "pgm", "pbm", NULL };
4454 static const gchar *ras_exts[] = { "ras", NULL };
4455 static const gchar *bz2_exts[] = { "bz2", NULL };
4456 static const gchar *gz_exts[] = { "gz", NULL };
4457 static const gchar *zip_exts[] = { "zip", NULL };
4458 static const gchar *compress_exts[] = { "Z", NULL };
4459 static const gchar *m4a_exts[] = { "m4a", NULL };
4460 static const gchar *q3gp_exts[] = { "3gp", NULL };
4461 static const gchar *aac_exts[] = { "aac", "adts", "adif", "loas", NULL };
4462 static const gchar *spc_exts[] = { "spc", NULL };
4463 static const gchar *wavpack_exts[] = { "wv", "wvp", NULL };
4464 static const gchar *wavpack_correction_exts[] = { "wvc", NULL };
4465 static const gchar *rar_exts[] = { "rar", NULL };
4466 static const gchar *tar_exts[] = { "tar", NULL };
4467 static const gchar *ar_exts[] = { "a", NULL };
4468 static const gchar *msdos_exts[] = { "dll", "exe", "ocx", "sys", "scr",
4469 "msstyles", "cpl", NULL
4471 static const gchar *flv_exts[] = { "flv", NULL };
4472 static const gchar *m4v_exts[] = { "m4v", NULL };
4473 static const gchar *h263_exts[] = { "h263", "263", NULL };
4474 static const gchar *h264_exts[] = { "h264", "x264", "264", NULL };
4475 static const gchar *nuv_exts[] = { "nuv", NULL };
4476 static const gchar *vivo_exts[] = { "viv", NULL };
4477 static const gchar *nsf_exts[] = { "nsf", NULL };
4478 static const gchar *gym_exts[] = { "gym", NULL };
4479 static const gchar *ay_exts[] = { "ay", NULL };
4480 static const gchar *gbs_exts[] = { "gbs", NULL };
4481 static const gchar *kss_exts[] = { "kss", NULL };
4482 static const gchar *sap_exts[] = { "sap", NULL };
4483 static const gchar *vgm_exts[] = { "vgm", NULL };
4484 static const gchar *mid_exts[] = { "mid", "midi", NULL };
4485 static const gchar *mxmf_exts[] = { "mxmf", NULL };
4486 static const gchar *imelody_exts[] = { "imy", "ime", "imelody", NULL };
4487 static const gchar *pdf_exts[] = { "pdf", NULL };
4488 static const gchar *ps_exts[] = { "ps", NULL };
4489 static const gchar *svg_exts[] = { "svg", NULL };
4490 static const gchar *mxf_exts[] = { "mxf", NULL };
4491 static const gchar *ivf_exts[] = { "ivf", NULL };
4492 static const gchar *msword_exts[] = { "doc", NULL };
4493 static const gchar *dsstore_exts[] = { "DS_Store", NULL };
4494 static const gchar *psd_exts[] = { "psd", NULL };
4495 static const gchar *y4m_exts[] = { "y4m", NULL };
4497 GST_DEBUG_CATEGORY_INIT (type_find_debug, "typefindfunctions",
4498 GST_DEBUG_FG_GREEN | GST_DEBUG_BG_RED, "generic type find functions");
4500 /* must use strings, macros don't accept initializers */
4501 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ms-asf", GST_RANK_SECONDARY,
4503 "\060\046\262\165\216\146\317\021\246\331\000\252\000\142\316\154", 16,
4504 GST_TYPE_FIND_MAXIMUM);
4505 TYPE_FIND_REGISTER (plugin, "audio/x-musepack", GST_RANK_PRIMARY,
4506 musepack_type_find, musepack_exts, MUSEPACK_CAPS, NULL, NULL);
4507 TYPE_FIND_REGISTER (plugin, "audio/x-au", GST_RANK_MARGINAL,
4508 au_type_find, au_exts, AU_CAPS, NULL, NULL);
4509 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-msvideo", GST_RANK_PRIMARY,
4511 TYPE_FIND_REGISTER_RIFF (plugin, "audio/qcelp", GST_RANK_PRIMARY,
4513 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-cdxa", GST_RANK_PRIMARY,
4515 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-vcd", GST_RANK_PRIMARY,
4516 cdxa_exts, "\000\377\377\377\377\377\377\377\377\377\377\000", 12,
4517 GST_TYPE_FIND_MAXIMUM);
4518 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-imelody", GST_RANK_PRIMARY,
4519 imelody_exts, "BEGIN:IMELODY", 13, GST_TYPE_FIND_MAXIMUM);
4521 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-smoke", GST_RANK_PRIMARY,
4522 NULL, "\x80smoke\x00\x01\x00", 6, GST_TYPE_FIND_MAXIMUM);
4524 TYPE_FIND_REGISTER (plugin, "audio/midi", GST_RANK_PRIMARY, mid_type_find,
4525 mid_exts, MID_CAPS, NULL, NULL);
4526 TYPE_FIND_REGISTER_RIFF (plugin, "audio/riff-midi", GST_RANK_PRIMARY,
4528 TYPE_FIND_REGISTER (plugin, "audio/mobile-xmf", GST_RANK_PRIMARY,
4529 mxmf_type_find, mxmf_exts, MXMF_CAPS, NULL, NULL);
4530 TYPE_FIND_REGISTER (plugin, "video/x-fli", GST_RANK_MARGINAL, flx_type_find,
4531 flx_exts, FLX_CAPS, NULL, NULL);
4532 TYPE_FIND_REGISTER (plugin, "application/x-id3v2", GST_RANK_PRIMARY + 103,
4533 id3v2_type_find, id3_exts, ID3_CAPS, NULL, NULL);
4534 TYPE_FIND_REGISTER (plugin, "application/x-id3v1", GST_RANK_PRIMARY + 101,
4535 id3v1_type_find, id3_exts, ID3_CAPS, NULL, NULL);
4536 TYPE_FIND_REGISTER (plugin, "application/x-apetag", GST_RANK_PRIMARY + 102,
4537 apetag_type_find, apetag_exts, APETAG_CAPS, NULL, NULL);
4538 TYPE_FIND_REGISTER (plugin, "audio/x-ttafile", GST_RANK_PRIMARY,
4539 tta_type_find, tta_exts, TTA_CAPS, NULL, NULL);
4540 TYPE_FIND_REGISTER (plugin, "audio/x-mod", GST_RANK_SECONDARY, mod_type_find,
4541 mod_exts, MOD_CAPS, NULL, NULL);
4542 TYPE_FIND_REGISTER (plugin, "audio/mpeg", GST_RANK_PRIMARY, mp3_type_find,
4543 mp3_exts, MP3_CAPS, NULL, NULL);
4544 TYPE_FIND_REGISTER (plugin, "audio/x-ac3", GST_RANK_PRIMARY, ac3_type_find,
4545 ac3_exts, AC3_CAPS, NULL, NULL);
4546 TYPE_FIND_REGISTER (plugin, "audio/x-dts", GST_RANK_SECONDARY, dts_type_find,
4547 dts_exts, DTS_CAPS, NULL, NULL);
4548 TYPE_FIND_REGISTER (plugin, "audio/x-gsm", GST_RANK_PRIMARY, NULL, gsm_exts,
4549 GSM_CAPS, NULL, NULL);
4550 TYPE_FIND_REGISTER (plugin, "video/mpeg-sys", GST_RANK_PRIMARY,
4551 mpeg_sys_type_find, mpeg_sys_exts, MPEG_SYS_CAPS, NULL, NULL);
4552 TYPE_FIND_REGISTER (plugin, "video/mpegts", GST_RANK_PRIMARY,
4553 mpeg_ts_type_find, mpeg_ts_exts, MPEGTS_CAPS, NULL, NULL);
4554 TYPE_FIND_REGISTER (plugin, "application/ogg", GST_RANK_PRIMARY,
4555 ogganx_type_find, ogg_exts, OGGANX_CAPS, NULL, NULL);
4556 TYPE_FIND_REGISTER (plugin, "video/mpeg-elementary", GST_RANK_MARGINAL,
4557 mpeg_video_stream_type_find, mpeg_video_exts, MPEG_VIDEO_CAPS, NULL,
4559 TYPE_FIND_REGISTER (plugin, "video/mpeg4", GST_RANK_PRIMARY,
4560 mpeg4_video_type_find, m4v_exts, MPEG_VIDEO_CAPS, NULL, NULL);
4561 TYPE_FIND_REGISTER (plugin, "video/x-h263", GST_RANK_SECONDARY,
4562 h263_video_type_find, h263_exts, H263_VIDEO_CAPS, NULL, NULL);
4563 TYPE_FIND_REGISTER (plugin, "video/x-h264", GST_RANK_PRIMARY,
4564 h264_video_type_find, h264_exts, H264_VIDEO_CAPS, NULL, NULL);
4565 TYPE_FIND_REGISTER (plugin, "video/x-nuv", GST_RANK_SECONDARY, nuv_type_find,
4566 nuv_exts, NUV_CAPS, NULL, NULL);
4569 TYPE_FIND_REGISTER (plugin, "audio/x-m4a", GST_RANK_PRIMARY, m4a_type_find,
4570 m4a_exts, M4A_CAPS, NULL, NULL);
4571 TYPE_FIND_REGISTER (plugin, "application/x-3gp", GST_RANK_PRIMARY,
4572 q3gp_type_find, q3gp_exts, Q3GP_CAPS, NULL, NULL);
4573 TYPE_FIND_REGISTER (plugin, "video/quicktime", GST_RANK_SECONDARY,
4574 qt_type_find, qt_exts, QT_CAPS, NULL, NULL);
4575 TYPE_FIND_REGISTER (plugin, "image/x-quicktime", GST_RANK_SECONDARY,
4576 qtif_type_find, qtif_exts, QTIF_CAPS, NULL, NULL);
4577 TYPE_FIND_REGISTER (plugin, "image/jp2", GST_RANK_PRIMARY,
4578 jp2_type_find, jp2_exts, JP2_CAPS, NULL, NULL);
4579 TYPE_FIND_REGISTER (plugin, "video/mj2", GST_RANK_PRIMARY,
4580 jp2_type_find, mj2_exts, MJ2_CAPS, NULL, NULL);
4582 TYPE_FIND_REGISTER (plugin, "text/html", GST_RANK_SECONDARY, html_type_find,
4583 html_exts, HTML_CAPS, NULL, NULL);
4584 TYPE_FIND_REGISTER_START_WITH (plugin, "application/vnd.rn-realmedia",
4585 GST_RANK_SECONDARY, rm_exts, ".RMF", 4, GST_TYPE_FIND_MAXIMUM);
4586 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-pn-realaudio",
4587 GST_RANK_SECONDARY, rm_exts, ".ra\375", 4, GST_TYPE_FIND_MAXIMUM);
4588 TYPE_FIND_REGISTER (plugin, "application/x-shockwave-flash",
4589 GST_RANK_SECONDARY, swf_type_find, swf_exts, SWF_CAPS, NULL, NULL);
4590 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-flv", GST_RANK_SECONDARY,
4591 flv_exts, "FLV", 3, GST_TYPE_FIND_MAXIMUM);
4592 TYPE_FIND_REGISTER (plugin, "text/plain", GST_RANK_MARGINAL, utf8_type_find,
4593 utf8_exts, UTF8_CAPS, NULL, NULL);
4594 TYPE_FIND_REGISTER (plugin, "text/utf-16", GST_RANK_MARGINAL, utf16_type_find,
4595 unicode_exts, UTF16_CAPS, NULL, NULL);
4596 TYPE_FIND_REGISTER (plugin, "text/utf-32", GST_RANK_MARGINAL, utf32_type_find,
4597 unicode_exts, UTF32_CAPS, NULL, NULL);
4598 TYPE_FIND_REGISTER (plugin, "text/uri-list", GST_RANK_MARGINAL, uri_type_find,
4599 uri_exts, URI_CAPS, NULL, NULL);
4600 TYPE_FIND_REGISTER (plugin, "application/x-hls", GST_RANK_MARGINAL,
4601 hls_type_find, hls_exts, HLS_CAPS, NULL, NULL);
4602 TYPE_FIND_REGISTER (plugin, "application/sdp", GST_RANK_SECONDARY,
4603 sdp_type_find, sdp_exts, SDP_CAPS, NULL, NULL);
4604 TYPE_FIND_REGISTER (plugin, "application/smil", GST_RANK_SECONDARY,
4605 smil_type_find, smil_exts, SMIL_CAPS, NULL, NULL);
4606 TYPE_FIND_REGISTER (plugin, "application/xml", GST_RANK_MARGINAL,
4607 xml_type_find, xml_exts, GENERIC_XML_CAPS, NULL, NULL);
4608 TYPE_FIND_REGISTER_RIFF (plugin, "audio/x-wav", GST_RANK_PRIMARY, wav_exts,
4610 TYPE_FIND_REGISTER (plugin, "audio/x-aiff", GST_RANK_SECONDARY,
4611 aiff_type_find, aiff_exts, AIFF_CAPS, NULL, NULL);
4612 TYPE_FIND_REGISTER (plugin, "audio/x-svx", GST_RANK_SECONDARY, svx_type_find,
4613 svx_exts, SVX_CAPS, NULL, NULL);
4614 TYPE_FIND_REGISTER (plugin, "audio/x-paris", GST_RANK_SECONDARY,
4615 paris_type_find, paris_exts, PARIS_CAPS, NULL, NULL);
4616 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nist", GST_RANK_SECONDARY,
4617 nist_exts, "NIST", 4, GST_TYPE_FIND_MAXIMUM);
4618 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-voc", GST_RANK_SECONDARY,
4619 voc_exts, "Creative", 8, GST_TYPE_FIND_MAXIMUM);
4620 TYPE_FIND_REGISTER (plugin, "audio/x-sds", GST_RANK_SECONDARY, sds_type_find,
4621 sds_exts, SDS_CAPS, NULL, NULL);
4622 TYPE_FIND_REGISTER (plugin, "audio/x-ircam", GST_RANK_SECONDARY,
4623 ircam_type_find, ircam_exts, IRCAM_CAPS, NULL, NULL);
4624 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-w64", GST_RANK_SECONDARY,
4625 w64_exts, "riff", 4, GST_TYPE_FIND_MAXIMUM);
4626 TYPE_FIND_REGISTER (plugin, "audio/x-shorten", GST_RANK_SECONDARY,
4627 shn_type_find, shn_exts, SHN_CAPS, NULL, NULL);
4628 TYPE_FIND_REGISTER (plugin, "application/x-ape", GST_RANK_SECONDARY,
4629 ape_type_find, ape_exts, APE_CAPS, NULL, NULL);
4630 TYPE_FIND_REGISTER (plugin, "image/jpeg", GST_RANK_PRIMARY + 15,
4631 jpeg_type_find, jpeg_exts, JPEG_CAPS, NULL, NULL);
4632 TYPE_FIND_REGISTER_START_WITH (plugin, "image/gif", GST_RANK_PRIMARY,
4633 gif_exts, "GIF8", 4, GST_TYPE_FIND_MAXIMUM);
4634 TYPE_FIND_REGISTER_START_WITH (plugin, "image/png", GST_RANK_PRIMARY + 14,
4635 png_exts, "\211PNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
4636 TYPE_FIND_REGISTER (plugin, "image/bmp", GST_RANK_PRIMARY, bmp_type_find,
4637 bmp_exts, BMP_CAPS, NULL, NULL);
4638 TYPE_FIND_REGISTER (plugin, "image/tiff", GST_RANK_PRIMARY, tiff_type_find,
4639 tiff_exts, TIFF_CAPS, NULL, NULL);
4640 TYPE_FIND_REGISTER (plugin, "image/x-portable-pixmap", GST_RANK_SECONDARY,
4641 pnm_type_find, pnm_exts, PNM_CAPS, NULL, NULL);
4642 TYPE_FIND_REGISTER (plugin, "video/x-matroska", GST_RANK_PRIMARY,
4643 matroska_type_find, matroska_exts, MATROSKA_CAPS, NULL, NULL);
4644 TYPE_FIND_REGISTER (plugin, "video/webm", GST_RANK_PRIMARY,
4645 webm_type_find, webm_exts, WEBM_CAPS, NULL, NULL);
4646 TYPE_FIND_REGISTER (plugin, "application/mxf", GST_RANK_PRIMARY,
4647 mxf_type_find, mxf_exts, MXF_CAPS, NULL, NULL);
4648 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mve", GST_RANK_SECONDARY,
4649 mve_exts, "Interplay MVE File\032\000\032\000\000\001\063\021", 26,
4650 GST_TYPE_FIND_MAXIMUM);
4651 TYPE_FIND_REGISTER (plugin, "video/x-dv", GST_RANK_SECONDARY, dv_type_find,
4652 dv_exts, DV_CAPS, NULL, NULL);
4653 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-nb-sh", GST_RANK_PRIMARY,
4654 amr_exts, "#!AMR", 5, GST_TYPE_FIND_LIKELY);
4655 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-wb-sh", GST_RANK_PRIMARY,
4656 amr_exts, "#!AMR-WB", 7, GST_TYPE_FIND_MAXIMUM);
4657 TYPE_FIND_REGISTER (plugin, "audio/iLBC-sh", GST_RANK_PRIMARY,
4658 ilbc_type_find, ilbc_exts, ILBC_CAPS, NULL, NULL);
4659 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sid", GST_RANK_MARGINAL,
4660 sid_exts, "PSID", 4, GST_TYPE_FIND_MAXIMUM);
4661 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xcf", GST_RANK_SECONDARY,
4662 xcf_exts, "gimp xcf", 8, GST_TYPE_FIND_MAXIMUM);
4663 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mng", GST_RANK_SECONDARY,
4664 mng_exts, "\212MNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
4665 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-jng", GST_RANK_SECONDARY,
4666 jng_exts, "\213JNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
4667 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xpixmap", GST_RANK_SECONDARY,
4668 xpm_exts, "/* XPM */", 9, GST_TYPE_FIND_MAXIMUM);
4669 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-sun-raster",
4670 GST_RANK_SECONDARY, ras_exts, "\131\246\152\225", 4,
4671 GST_TYPE_FIND_MAXIMUM);
4672 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-bzip",
4673 GST_RANK_SECONDARY, bz2_exts, "BZh", 3, GST_TYPE_FIND_LIKELY);
4674 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-gzip",
4675 GST_RANK_SECONDARY, gz_exts, "\037\213", 2, GST_TYPE_FIND_LIKELY);
4676 TYPE_FIND_REGISTER_START_WITH (plugin, "application/zip", GST_RANK_SECONDARY,
4677 zip_exts, "PK\003\004", 4, GST_TYPE_FIND_LIKELY);
4678 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-compress",
4679 GST_RANK_SECONDARY, compress_exts, "\037\235", 2, GST_TYPE_FIND_LIKELY);
4680 TYPE_FIND_REGISTER (plugin, "subtitle/x-kate", GST_RANK_MARGINAL,
4681 kate_type_find, NULL, NULL, NULL, NULL);
4682 TYPE_FIND_REGISTER (plugin, "audio/x-flac", GST_RANK_PRIMARY,
4683 flac_type_find, flac_exts, FLAC_CAPS, NULL, NULL);
4684 TYPE_FIND_REGISTER (plugin, "audio/x-vorbis", GST_RANK_PRIMARY,
4685 vorbis_type_find, NULL, VORBIS_CAPS, NULL, NULL);
4686 TYPE_FIND_REGISTER (plugin, "video/x-theora", GST_RANK_PRIMARY,
4687 theora_type_find, NULL, THEORA_CAPS, NULL, NULL);
4688 TYPE_FIND_REGISTER (plugin, "application/x-ogm-video", GST_RANK_PRIMARY,
4689 ogmvideo_type_find, NULL, OGMVIDEO_CAPS, NULL, NULL);
4690 TYPE_FIND_REGISTER (plugin, "application/x-ogm-audio", GST_RANK_PRIMARY,
4691 ogmaudio_type_find, NULL, OGMAUDIO_CAPS, NULL, NULL);
4692 TYPE_FIND_REGISTER (plugin, "application/x-ogm-text", GST_RANK_PRIMARY,
4693 ogmtext_type_find, NULL, OGMTEXT_CAPS, NULL, NULL);
4694 TYPE_FIND_REGISTER (plugin, "audio/x-speex", GST_RANK_PRIMARY,
4695 speex_type_find, NULL, SPEEX_CAPS, NULL, NULL);
4696 TYPE_FIND_REGISTER (plugin, "audio/x-celt", GST_RANK_PRIMARY,
4697 celt_type_find, NULL, CELT_CAPS, NULL, NULL);
4698 TYPE_FIND_REGISTER (plugin, "application/x-ogg-skeleton", GST_RANK_PRIMARY,
4699 oggskel_type_find, NULL, OGG_SKELETON_CAPS, NULL, NULL);
4700 TYPE_FIND_REGISTER (plugin, "text/x-cmml", GST_RANK_PRIMARY, cmml_type_find,
4701 NULL, CMML_CAPS, NULL, NULL);
4702 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-executable",
4703 GST_RANK_MARGINAL, NULL, "\177ELF", 4, GST_TYPE_FIND_MAXIMUM);
4704 TYPE_FIND_REGISTER (plugin, "audio/aac", GST_RANK_SECONDARY,
4705 aac_type_find, aac_exts, AAC_CAPS, NULL, NULL);
4706 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-spc", GST_RANK_SECONDARY,
4707 spc_exts, "SNES-SPC700 Sound File Data", 27, GST_TYPE_FIND_MAXIMUM);
4708 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack", GST_RANK_SECONDARY,
4709 wavpack_type_find, wavpack_exts, WAVPACK_CAPS, NULL, NULL);
4710 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack-correction", GST_RANK_SECONDARY,
4711 wavpack_type_find, wavpack_correction_exts, WAVPACK_CORRECTION_CAPS, NULL,
4713 TYPE_FIND_REGISTER (plugin, "application/postscript", GST_RANK_SECONDARY,
4714 postscript_type_find, ps_exts, POSTSCRIPT_CAPS, NULL, NULL);
4715 TYPE_FIND_REGISTER (plugin, "image/svg+xml", GST_RANK_SECONDARY,
4716 svg_type_find, svg_exts, SVG_CAPS, NULL, NULL);
4717 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-rar",
4718 GST_RANK_SECONDARY, rar_exts, "Rar!", 4, GST_TYPE_FIND_LIKELY);
4719 TYPE_FIND_REGISTER (plugin, "application/x-tar", GST_RANK_SECONDARY,
4720 tar_type_find, tar_exts, TAR_CAPS, NULL, NULL);
4721 TYPE_FIND_REGISTER (plugin, "application/x-ar", GST_RANK_SECONDARY,
4722 ar_type_find, ar_exts, AR_CAPS, NULL, NULL);
4723 TYPE_FIND_REGISTER (plugin, "application/x-ms-dos-executable",
4724 GST_RANK_SECONDARY, msdos_type_find, msdos_exts, MSDOS_CAPS, NULL, NULL);
4725 TYPE_FIND_REGISTER (plugin, "video/x-dirac", GST_RANK_PRIMARY,
4726 dirac_type_find, NULL, DIRAC_CAPS, NULL, NULL);
4727 TYPE_FIND_REGISTER (plugin, "multipart/x-mixed-replace", GST_RANK_SECONDARY,
4728 multipart_type_find, NULL, MULTIPART_CAPS, NULL, NULL);
4729 TYPE_FIND_REGISTER (plugin, "application/x-mmsh", GST_RANK_SECONDARY,
4730 mmsh_type_find, NULL, MMSH_CAPS, NULL, NULL);
4731 TYPE_FIND_REGISTER (plugin, "video/vivo", GST_RANK_SECONDARY,
4732 vivo_type_find, vivo_exts, VIVO_CAPS, NULL, NULL);
4733 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nsf",
4734 GST_RANK_SECONDARY, nsf_exts, "NESM\x1a", 5, GST_TYPE_FIND_MAXIMUM);
4735 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gym",
4736 GST_RANK_SECONDARY, gym_exts, "GYMX", 4, GST_TYPE_FIND_MAXIMUM);
4737 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-ay",
4738 GST_RANK_SECONDARY, ay_exts, "ZXAYEMUL", 8, GST_TYPE_FIND_MAXIMUM);
4739 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gbs",
4740 GST_RANK_SECONDARY, gbs_exts, "GBS\x01", 4, GST_TYPE_FIND_MAXIMUM);
4741 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-vgm",
4742 GST_RANK_SECONDARY, vgm_exts, "Vgm\x20", 4, GST_TYPE_FIND_MAXIMUM);
4743 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sap",
4744 GST_RANK_SECONDARY, sap_exts, "SAP\x0d\x0a" "AUTHOR\x20", 12,
4745 GST_TYPE_FIND_MAXIMUM);
4746 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ivf", GST_RANK_SECONDARY,
4747 ivf_exts, "DKIF", 4, GST_TYPE_FIND_NEARLY_CERTAIN);
4748 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-kss", GST_RANK_SECONDARY,
4749 kss_exts, "KSSX\0", 5, GST_TYPE_FIND_MAXIMUM);
4750 TYPE_FIND_REGISTER_START_WITH (plugin, "application/pdf", GST_RANK_SECONDARY,
4751 pdf_exts, "%PDF-", 5, GST_TYPE_FIND_LIKELY);
4752 TYPE_FIND_REGISTER_START_WITH (plugin, "application/msword",
4753 GST_RANK_SECONDARY, msword_exts, "\320\317\021\340\241\261\032\341", 8,
4754 GST_TYPE_FIND_LIKELY);
4755 /* Mac OS X .DS_Store files tend to be taken for video/mpeg */
4756 TYPE_FIND_REGISTER_START_WITH (plugin, "application/octet-stream",
4757 GST_RANK_SECONDARY, dsstore_exts, "\000\000\000\001Bud1", 8,
4758 GST_TYPE_FIND_LIKELY);
4759 TYPE_FIND_REGISTER_START_WITH (plugin, "image/vnd.adobe.photoshop",
4760 GST_RANK_SECONDARY, psd_exts, "8BPS\000\001\000\000\000\000", 10,
4761 GST_TYPE_FIND_LIKELY);
4762 TYPE_FIND_REGISTER (plugin, "image/vnd.wap.wbmp", GST_RANK_MARGINAL,
4763 wbmp_typefind, NULL, NULL, NULL, NULL);
4764 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-yuv4mpeg",
4765 GST_RANK_SECONDARY, y4m_exts, "YUV4MPEG2 ", 10, GST_TYPE_FIND_LIKELY);
4766 TYPE_FIND_REGISTER (plugin, "image/x-icon", GST_RANK_MARGINAL,
4767 windows_icon_typefind, NULL, NULL, NULL, NULL);
4770 TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,
4771 xdgmime_typefind, NULL, NULL, NULL, NULL);
4774 TYPE_FIND_REGISTER (plugin, "image/x-degas", GST_RANK_MARGINAL,
4775 degas_type_find, NULL, NULL, NULL, NULL);
4780 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
4782 "typefindfunctions",
4783 "default typefind functions",
4784 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)