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.
30 /* don't want to add gio xdgmime typefinder if gio was disabled via configure */
36 #include <gst/gsttypefind.h>
37 #include <gst/gstelement.h>
38 #include <gst/gstversion.h>
39 #include <gst/gstinfo.h>
40 #include <gst/gstutils.h>
46 GST_DEBUG_CATEGORY_STATIC (type_find_debug);
47 #define GST_CAT_DEFAULT type_find_debug
49 /* DataScanCtx: helper for typefind functions that scan through data
50 * step-by-step, to avoid doing a peek at each and every offset */
52 #define DATA_SCAN_CTX_CHUNK_SIZE 4096
62 data_scan_ctx_advance (GstTypeFind * tf, DataScanCtx * c, guint bytes_to_skip)
64 c->offset += bytes_to_skip;
65 if (G_LIKELY (c->size > bytes_to_skip)) {
66 c->size -= bytes_to_skip;
67 c->data += bytes_to_skip;
74 static inline gboolean
75 data_scan_ctx_ensure_data (GstTypeFind * tf, DataScanCtx * c, gint min_len)
79 guint chunk_len = MAX (DATA_SCAN_CTX_CHUNK_SIZE, min_len);
81 if (G_LIKELY (c->size >= min_len))
84 data = gst_type_find_peek (tf, c->offset, chunk_len);
85 if (G_LIKELY (data != NULL)) {
91 /* if there's less than our chunk size, try to get as much as we can, but
92 * always at least min_len bytes (we might be typefinding the first buffer
93 * of the stream and not have as much data available as we'd like) */
94 len = gst_type_find_get_length (tf);
96 len = CLAMP (len - c->offset, min_len, chunk_len);
101 data = gst_type_find_peek (tf, c->offset, len);
112 static gboolean xml_check_first_element (GstTypeFind * tf,
113 const gchar * element, guint elen, gboolean strict);
114 static gboolean sdp_check_header (GstTypeFind * tf);
116 static GstStaticCaps utf8_caps = GST_STATIC_CAPS ("text/plain");
118 #define UTF8_CAPS gst_static_caps_get(&utf8_caps)
121 utf8_type_find_have_valid_utf8_at_offset (GstTypeFind * tf, guint64 offset,
122 GstTypeFindProbability * prob)
126 /* randomly decided values */
127 guint min_size = 16; /* minimum size */
128 guint size = 32 * 1024; /* starting size */
129 guint probability = 95; /* starting probability */
130 guint step = 10; /* how much we reduce probability in each
133 while (probability > step && size > min_size) {
134 data = gst_type_find_peek (tf, offset, size);
137 gchar *start = (gchar *) data;
139 if (g_utf8_validate (start, size, (const gchar **) &end) || (end - start + 4 > size)) { /* allow last char to be cut off */
154 utf8_type_find (GstTypeFind * tf, gpointer unused)
156 GstTypeFindProbability start_prob, mid_prob;
159 /* leave xml to the xml typefinders */
160 if (xml_check_first_element (tf, "", 0, TRUE))
163 /* leave sdp to the sdp typefinders */
164 if (sdp_check_header (tf))
167 /* check beginning of stream */
168 if (!utf8_type_find_have_valid_utf8_at_offset (tf, 0, &start_prob))
171 GST_LOG ("start is plain text with probability of %u", start_prob);
173 /* POSSIBLE is the highest probability we ever return if we can't
174 * probe into the middle of the file and don't know its length */
176 length = gst_type_find_get_length (tf);
177 if (length == 0 || length == (guint64) - 1) {
178 gst_type_find_suggest (tf, MIN (start_prob, GST_TYPE_FIND_POSSIBLE),
183 if (length < 64 * 1024) {
184 gst_type_find_suggest (tf, start_prob, UTF8_CAPS);
188 /* check middle of stream */
189 if (!utf8_type_find_have_valid_utf8_at_offset (tf, length / 2, &mid_prob))
192 GST_LOG ("middle is plain text with probability of %u", mid_prob);
193 gst_type_find_suggest (tf, (start_prob + mid_prob) / 2, UTF8_CAPS);
196 /*** text/uri-list ***/
198 static GstStaticCaps uri_caps = GST_STATIC_CAPS ("text/uri-list");
200 #define URI_CAPS (gst_static_caps_get(&uri_caps))
201 #define BUFFER_SIZE 16 /* If the string is < 16 bytes we're screwed */
202 #define INC_BUFFER { \
204 if (pos == BUFFER_SIZE) { \
206 offset += BUFFER_SIZE; \
207 data = gst_type_find_peek (tf, offset, BUFFER_SIZE); \
208 if (data == NULL) return; \
214 uri_type_find (GstTypeFind * tf, gpointer unused)
216 guint8 *data = gst_type_find_peek (tf, 0, BUFFER_SIZE);
221 /* Search for # comment lines */
222 while (*data == '#') {
223 /* Goto end of line */
224 while (*data != '\n') {
231 if (!g_ascii_isalpha (*data)) {
232 /* Had a non alpha char - can't be uri-list */
238 while (g_ascii_isalnum (*data)) {
243 /* First non alpha char is not a : */
247 /* Get the next 2 bytes as well */
248 data = gst_type_find_peek (tf, offset + pos, 3);
252 if (data[1] != '/' && data[2] != '/') {
256 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, URI_CAPS);
261 /*** application/xml **********************************************************/
263 #define XML_BUFFER_SIZE 16
264 #define XML_INC_BUFFER { \
266 if (pos == XML_BUFFER_SIZE) { \
268 offset += XML_BUFFER_SIZE; \
269 data = gst_type_find_peek (tf, offset, XML_BUFFER_SIZE); \
270 if (data == NULL) return FALSE; \
277 xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen,
285 data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE);
289 /* look for the XMLDec
290 * see XML spec 2.8, Prolog and Document Type Declaration
291 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
292 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
294 if (strict && !got_xmldec)
297 /* skip XMLDec in any case if we've got one */
303 /* look for the first element, it has to be the requested element. Bail
304 * out if it is not within the first 4kB. */
305 while (data && (offset + pos) < 4096) {
306 while (*data != '<' && (offset + pos) < 4096) {
311 if (!g_ascii_isalpha (*data)) {
312 /* if not alphabetic, it's a PI or an element / attribute declaration
313 * like <?xxx or <!xxx */
318 /* the first normal element, check if it's the one asked for */
319 data = gst_type_find_peek (tf, offset + pos, elen + 1);
320 return (data && element && strncmp ((char *) data, element, elen) == 0);
326 static GstStaticCaps generic_xml_caps = GST_STATIC_CAPS ("application/xml");
328 #define GENERIC_XML_CAPS (gst_static_caps_get(&generic_xml_caps))
330 xml_type_find (GstTypeFind * tf, gpointer unused)
332 if (xml_check_first_element (tf, "", 0, TRUE)) {
333 gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, GENERIC_XML_CAPS);
337 /*** application/sdp *********************************************************/
339 static GstStaticCaps sdp_caps = GST_STATIC_CAPS ("application/sdp");
341 #define SDP_CAPS (gst_static_caps_get(&sdp_caps))
343 sdp_check_header (GstTypeFind * tf)
347 data = gst_type_find_peek (tf, 0, 5);
351 /* sdp must start with v=0[\r]\n */
352 if (memcmp (data, "v=0", 3))
355 if (data[3] == '\r' && data[4] == '\n')
364 sdp_type_find (GstTypeFind * tf, gpointer unused)
366 if (sdp_check_header (tf))
367 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDP_CAPS);
370 /*** application/smil *********************************************************/
372 static GstStaticCaps smil_caps = GST_STATIC_CAPS ("application/smil");
374 #define SMIL_CAPS (gst_static_caps_get(&smil_caps))
376 smil_type_find (GstTypeFind * tf, gpointer unused)
378 if (xml_check_first_element (tf, "smil", 4, FALSE)) {
379 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SMIL_CAPS);
385 static GstStaticCaps html_caps = GST_STATIC_CAPS ("text/html");
387 #define HTML_CAPS gst_static_caps_get (&html_caps)
390 html_type_find (GstTypeFind * tf, gpointer unused)
394 data = (gchar *) gst_type_find_peek (tf, 0, 16);
398 if (!g_ascii_strncasecmp (data, "<!DOCTYPE HTML", 14)) {
399 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
400 } else if (xml_check_first_element (tf, "html", 4, FALSE)) {
401 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
402 } else if ((d = memchr (data, '<', 16))) {
403 data = (gchar *) gst_type_find_peek (tf, d - data, 6);
404 if (data && g_ascii_strncasecmp (data, "<html>", 6) == 0) {
405 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
412 static GstStaticCaps mid_caps = GST_STATIC_CAPS ("audio/midi");
414 #define MID_CAPS gst_static_caps_get(&mid_caps)
416 mid_type_find (GstTypeFind * tf, gpointer unused)
418 guint8 *data = gst_type_find_peek (tf, 0, 4);
420 /* http://jedi.ks.uiuc.edu/~johns/links/music/midifile.html */
421 if (data && data[0] == 'M' && data[1] == 'T' && data[2] == 'h'
423 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MID_CAPS);
426 /*** audio/mobile-xmf ***/
428 static GstStaticCaps mxmf_caps = GST_STATIC_CAPS ("audio/mobile-xmf");
430 #define MXMF_CAPS gst_static_caps_get(&mxmf_caps)
432 mxmf_type_find (GstTypeFind * tf, gpointer unused)
436 /* Search FileId "XMF_" 4 bytes */
437 data = gst_type_find_peek (tf, 0, 4);
438 if (data && data[0] == 'X' && data[1] == 'M' && data[2] == 'F'
440 /* Search Format version "2.00" 4 bytes */
441 data = gst_type_find_peek (tf, 4, 4);
442 if (data && data[0] == '2' && data[1] == '.' && data[2] == '0'
444 /* Search TypeId 2 1 byte */
445 data = gst_type_find_peek (tf, 11, 1);
446 if (data && data[0] == 2) {
447 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXMF_CAPS);
454 /*** video/x-fli ***/
456 static GstStaticCaps flx_caps = GST_STATIC_CAPS ("video/x-fli");
458 #define FLX_CAPS gst_static_caps_get(&flx_caps)
460 flx_type_find (GstTypeFind * tf, gpointer unused)
462 guint8 *data = gst_type_find_peek (tf, 0, 134);
465 /* check magic and the frame type of the first frame */
466 if ((data[4] == 0x11 || data[4] == 0x12 ||
467 data[4] == 0x30 || data[4] == 0x44) &&
469 ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1)) {
470 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLX_CAPS);
474 data = gst_type_find_peek (tf, 0, 6);
476 /* check magic only */
477 if ((data[4] == 0x11 || data[4] == 0x12 ||
478 data[4] == 0x30 || data[4] == 0x44) && data[5] == 0xaf) {
479 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, FLX_CAPS);
485 /*** application/x-id3 ***/
487 static GstStaticCaps id3_caps = GST_STATIC_CAPS ("application/x-id3");
489 #define ID3_CAPS gst_static_caps_get(&id3_caps)
491 id3v2_type_find (GstTypeFind * tf, gpointer unused)
493 guint8 *data = gst_type_find_peek (tf, 0, 10);
495 if (data && memcmp (data, "ID3", 3) == 0 &&
496 data[3] != 0xFF && data[4] != 0xFF &&
497 (data[6] & 0x80) == 0 && (data[7] & 0x80) == 0 &&
498 (data[8] & 0x80) == 0 && (data[9] & 0x80) == 0) {
499 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
504 id3v1_type_find (GstTypeFind * tf, gpointer unused)
506 guint8 *data = gst_type_find_peek (tf, -128, 3);
508 if (data && memcmp (data, "TAG", 3) == 0) {
509 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
513 /*** application/x-ape ***/
515 static GstStaticCaps apetag_caps = GST_STATIC_CAPS ("application/x-apetag");
517 #define APETAG_CAPS gst_static_caps_get(&apetag_caps)
519 apetag_type_find (GstTypeFind * tf, gpointer unused)
523 /* APEv1/2 at start of file */
524 data = gst_type_find_peek (tf, 0, 8);
525 if (data && !memcmp (data, "APETAGEX", 8)) {
526 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
530 /* APEv1/2 at end of file */
531 data = gst_type_find_peek (tf, -32, 8);
532 if (data && !memcmp (data, "APETAGEX", 8)) {
533 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
538 /*** audio/x-ttafile ***/
540 static GstStaticCaps tta_caps = GST_STATIC_CAPS ("audio/x-ttafile");
542 #define TTA_CAPS gst_static_caps_get(&tta_caps)
544 tta_type_find (GstTypeFind * tf, gpointer unused)
546 guint8 *data = gst_type_find_peek (tf, 0, 3);
549 if (memcmp (data, "TTA", 3) == 0) {
550 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTA_CAPS);
556 /*** audio/x-flac ***/
557 static GstStaticCaps flac_caps = GST_STATIC_CAPS ("audio/x-flac");
559 #define FLAC_CAPS (gst_static_caps_get(&flac_caps))
562 flac_type_find (GstTypeFind * tf, gpointer unused)
564 DataScanCtx c = { 0, NULL, 0 };
566 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
569 /* standard flac (also old/broken flac-in-ogg with an initial 4-byte marker
570 * packet and without the usual packet framing) */
571 if (memcmp (c.data, "fLaC", 4) == 0) {
572 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
576 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
579 /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */
580 if (memcmp (c.data, "\177FLAC\001", 6) == 0) {
581 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
585 /* disabled because it happily typefinds /dev/urandom as audio/x-flac, and
586 * because I yet have to see header-less flac in the wild */
588 /* flac without headers (subset format) */
589 /* 64K should be enough */
590 while (c.offset < (64 * 1024)) {
591 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
594 /* look for frame header,
595 * http://flac.sourceforge.net/format.html#frame_header
597 if (c.data[0] == 0xff && (c.data[1] >> 2) == 0x3e) {
598 /* bit 15 in the header must be 0 */
599 if (((c.data[1] >> 1) & 0x01) == 0x01)
602 /* blocksize must be != 0x00 */
603 if ((c.data[2] >> 4) == 0x00)
606 /* samplerate must be != 0x0f */
607 if ((c.data[2] & 0x0f) == 0x0f)
609 /* also 0 is invalid, as it means get the info from the header and we
610 * don't have headers if we are here */
611 if ((c.data[2] & 0x0f) == 0x00)
614 /* channel assignment must be < 11 */
615 if ((c.data[3] >> 4) >= 11)
618 /* sample size must be != 0x07 and != 0x05 */
619 if (((c.data[3] >> 1) & 0x07) == 0x07)
621 if (((c.data[3] >> 1) & 0x07) == 0x05)
623 /* also 0 is invalid, as it means get the info from the header and we
624 * don't have headers if we are here */
625 if (((c.data[3] >> 1) & 0x07) == 0x00)
628 /* next bit must be 0 */
629 if ((c.data[3] & 0x01) == 0x01)
632 /* FIXME: shouldn't we include the crc check ? */
634 GST_DEBUG ("Found flac without headers at %d", (gint) c.offset);
635 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, FLAC_CAPS);
639 data_scan_ctx_advance (tf, &c, 1);
644 /*** audio/mpeg version 2, 4 ***/
646 static GstStaticCaps aac_caps = GST_STATIC_CAPS ("audio/mpeg, "
647 "mpegversion = (int) { 2, 4 }, framed = (bool) false");
648 #define AAC_CAPS (gst_static_caps_get(&aac_caps))
649 #define AAC_AMOUNT (4096)
651 aac_type_find (GstTypeFind * tf, gpointer unused)
653 DataScanCtx c = { 0, NULL, 0 };
655 while (c.offset < AAC_AMOUNT) {
658 /* detect adts header or adif header.
659 * The ADIF header is 4 bytes, that should be OK. The ADTS header, on
660 * the other hand, is 14 bits only, so we require one valid frame with
661 * again a valid syncpoint on the next one (28 bits) for certainty. We
662 * require 4 kB, which is quite a lot, since frames are generally 200-400
665 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
668 snc = GST_READ_UINT16_BE (c.data);
669 if (G_UNLIKELY ((snc & 0xfff6) == 0xfff0)) {
670 /* ADTS header - find frame length */
671 GST_DEBUG ("Found one ADTS syncpoint at offset 0x%" G_GINT64_MODIFIER
672 "x, tracing next...", c.offset);
673 len = ((c.data[3] & 0x03) << 11) |
674 (c.data[4] << 3) | ((c.data[5] & 0xe0) >> 5);
676 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
677 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
681 snc = GST_READ_UINT16_BE (c.data + len);
682 if ((snc & 0xfff6) == 0xfff0) {
685 mpegversion = (c.data[1] & 0x08) ? 2 : 4;
686 GST_DEBUG ("Found second ADTS-%d syncpoint at offset 0x%"
687 G_GINT64_MODIFIER "x, framelen %u", mpegversion, c.offset, len);
688 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
689 "framed", G_TYPE_BOOLEAN, FALSE,
690 "mpegversion", G_TYPE_INT, mpegversion,
691 "stream-type", G_TYPE_STRING, "adts", NULL);
695 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
696 } else if (!memcmp (c.data, "ADIF", 4)) {
698 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
699 "framed", G_TYPE_BOOLEAN, FALSE, "mpegversion", G_TYPE_INT, 4,
700 "stream-format", G_TYPE_STRING, "adif", NULL);
706 data_scan_ctx_advance (tf, &c, 1);
710 /*** audio/mpeg version 1 ***/
713 * The chance that random data is identified as a valid mp3 header is 63 / 2^18
714 * (0.024%) per try. This makes the function for calculating false positives
715 * 1 - (1 - ((63 / 2 ^18) ^ GST_MP3_TYPEFIND_MIN_HEADERS)) ^ buffersize)
716 * This has the following probabilities of false positives:
717 * datasize MIN_HEADERS
719 * 4096 62.6% 0.02% 0% 0%
720 * 16384 98% 0.09% 0% 0%
721 * 1 MiB 100% 5.88% 0% 0%
722 * 1 GiB 100% 100% 1.44% 0%
723 * 1 TiB 100% 100% 100% 0.35%
724 * This means that the current choice (3 headers by most of the time 4096 byte
725 * buffers is pretty safe for now.
727 * The max. size of each frame is 1440 bytes, which means that for N frames to
728 * be detected, we need 1440 * GST_MP3_TYPEFIND_MIN_HEADERS + 3 bytes of data.
729 * Assuming we step into the stream right after the frame header, this
730 * means we need 1440 * (GST_MP3_TYPEFIND_MIN_HEADERS + 1) - 1 + 3 bytes
731 * of data (5762) to always detect any mp3.
734 static const guint mp3types_bitrates[2][3][16] =
735 { {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
736 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
737 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
738 {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
739 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
740 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}},
743 static const guint mp3types_freqs[3][3] = { {11025, 12000, 8000},
744 {22050, 24000, 16000},
745 {44100, 48000, 32000}
749 mp3_type_frame_length_from_header (guint32 header, guint * put_layer,
750 guint * put_channels, guint * put_bitrate, guint * put_samplerate,
751 gboolean * may_be_free_format, gint possible_free_framelen)
753 guint bitrate, layer, length, mode, samplerate, version, channels;
755 if ((header & 0xffe00000) != 0xffe00000)
758 /* we don't need extension, copyright, original or
759 * emphasis for the frame length */
767 length = header & 0x1;
770 /* sampling frequency */
771 samplerate = header & 0x3;
777 bitrate = header & 0xF;
778 if (bitrate == 0 && possible_free_framelen == -1) {
779 GST_LOG ("Possibly a free format mp3 - signalling");
780 *may_be_free_format = TRUE;
782 if (bitrate == 15 || (bitrate == 0 && possible_free_framelen == -1))
785 /* ignore error correction, too */
789 layer = 4 - (header & 0x3);
794 /* version 0=MPEG2.5; 2=MPEG2; 3=MPEG1 */
795 version = header & 0x3;
800 channels = (mode == 3) ? 1 : 2;
801 samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate];
805 length += possible_free_framelen;
806 bitrate = length * samplerate / 48000;
808 length += possible_free_framelen;
809 bitrate = length * samplerate /
810 ((layer == 3 && version != 3) ? 72000 : 144000);
814 bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate];
816 length = ((12000 * bitrate / samplerate) + length) * 4;
818 length += ((layer == 3
819 && version != 3) ? 72000 : 144000) * bitrate / samplerate;
823 GST_LOG ("mp3typefind: calculated mp3 frame length of %u bytes", length);
825 ("mp3typefind: samplerate = %u - bitrate = %u - layer = %u - version = %u"
826 " - channels = %u", samplerate, bitrate, layer, version, channels);
831 *put_channels = channels;
833 *put_bitrate = bitrate;
835 *put_samplerate = samplerate;
841 static GstStaticCaps mp3_caps = GST_STATIC_CAPS ("audio/mpeg, "
842 "mpegversion = (int) 1, layer = (int) [ 1, 3 ]");
843 #define MP3_CAPS (gst_static_caps_get(&mp3_caps))
845 * random values for typefinding
846 * if no more data is available, we will return a probability of
847 * (found_headers/TRY_HEADERS) * (MAXIMUM * (TRY_SYNC - bytes_skipped)
849 * if found_headers >= MIN_HEADERS
851 #define GST_MP3_TYPEFIND_MIN_HEADERS (2)
852 #define GST_MP3_TYPEFIND_TRY_HEADERS (5)
853 #define GST_MP3_TYPEFIND_TRY_SYNC (GST_TYPE_FIND_MAXIMUM * 100) /* 10kB */
854 #define GST_MP3_TYPEFIND_SYNC_SIZE (2048)
855 #define GST_MP3_WRONG_HEADER (10)
858 mp3_type_find_at_offset (GstTypeFind * tf, guint64 start_off,
859 guint * found_layer, GstTypeFindProbability * found_prob)
862 guint8 *data_end = NULL;
865 gint last_free_offset = -1;
866 gint last_free_framelen = -1;
867 gboolean headerstart = TRUE;
874 while (skipped < GST_MP3_TYPEFIND_TRY_SYNC) {
876 size = GST_MP3_TYPEFIND_SYNC_SIZE * 2;
879 data = gst_type_find_peek (tf, skipped + start_off, size);
880 } while (size > 10 && !data);
883 data_end = data + size;
886 guint8 *head_data = NULL;
887 guint layer = 0, bitrate, samplerate, channels;
888 guint found = 0; /* number of valid headers found */
889 guint64 offset = skipped;
891 while (found < GST_MP3_TYPEFIND_TRY_HEADERS) {
894 guint prev_layer = 0, prev_bitrate = 0;
895 guint prev_channels = 0, prev_samplerate = 0;
896 gboolean free = FALSE;
898 if ((gint64) (offset - skipped + 4) >= 0 &&
899 data + offset - skipped + 4 < data_end) {
900 head_data = data + offset - skipped;
902 head_data = gst_type_find_peek (tf, offset + start_off, 4);
906 head = GST_READ_UINT32_BE (head_data);
907 if (!(length = mp3_type_frame_length_from_header (head, &layer,
908 &channels, &bitrate, &samplerate, &free,
909 last_free_framelen))) {
911 if (last_free_offset == -1)
912 last_free_offset = offset;
914 last_free_framelen = offset - last_free_offset;
915 offset = last_free_offset;
919 last_free_framelen = -1;
922 /* Mark the fact that we didn't find a valid header at the beginning */
926 GST_LOG ("%d. header at offset %" G_GUINT64_FORMAT
927 " (0x%" G_GINT64_MODIFIER "x) was not an mp3 header "
928 "(possibly-free: %s)", found + 1, start_off + offset,
929 start_off + offset, free ? "yes" : "no");
932 if ((prev_layer && prev_layer != layer) ||
933 /* (prev_bitrate && prev_bitrate != bitrate) || <-- VBR */
934 (prev_samplerate && prev_samplerate != samplerate) ||
935 (prev_channels && prev_channels != channels)) {
936 /* this means an invalid property, or a change, which might mean
937 * that this is not a mp3 but just a random bytestream. It could
938 * be a freaking funky encoded mp3 though. We'll just not count
941 prev_bitrate = bitrate;
942 prev_channels = channels;
943 prev_samplerate = samplerate;
946 GST_LOG ("found %d. header at offset %" G_GUINT64_FORMAT " (0x%"
947 G_GINT64_MODIFIER "X)", found, start_off + offset,
952 g_assert (found <= GST_MP3_TYPEFIND_TRY_HEADERS);
953 if (head_data == NULL &&
954 gst_type_find_peek (tf, offset + start_off - 1, 1) == NULL)
955 /* Incomplete last frame - don't count it. */
957 if (found == GST_MP3_TYPEFIND_TRY_HEADERS ||
958 (found >= GST_MP3_TYPEFIND_MIN_HEADERS && head_data == NULL)) {
959 /* we can make a valid guess */
960 guint probability = found * GST_TYPE_FIND_MAXIMUM *
961 (GST_MP3_TYPEFIND_TRY_SYNC - skipped) /
962 GST_MP3_TYPEFIND_TRY_HEADERS / GST_MP3_TYPEFIND_TRY_SYNC;
965 && probability > (GST_TYPE_FIND_MINIMUM + GST_MP3_WRONG_HEADER))
966 probability -= GST_MP3_WRONG_HEADER;
967 if (probability < GST_TYPE_FIND_MINIMUM)
968 probability = GST_TYPE_FIND_MINIMUM;
973 ("audio/mpeg calculated %u = %u * %u / %u * (%u - %"
974 G_GUINT64_FORMAT ") / %u", probability, GST_TYPE_FIND_MAXIMUM,
975 found, GST_MP3_TYPEFIND_TRY_HEADERS, GST_MP3_TYPEFIND_TRY_SYNC,
976 (guint64) skipped, GST_MP3_TYPEFIND_TRY_SYNC);
977 /* make sure we're not id3 tagged */
978 head_data = gst_type_find_peek (tf, -128, 3);
979 if (head_data && (memcmp (head_data, "TAG", 3) == 0)) {
982 g_assert (probability <= GST_TYPE_FIND_MAXIMUM);
984 *found_prob = probability;
986 *found_layer = layer;
997 mp3_type_find (GstTypeFind * tf, gpointer unused)
999 GstTypeFindProbability prob, mid_prob;
1001 guint layer, mid_layer;
1004 mp3_type_find_at_offset (tf, 0, &layer, &prob);
1005 length = gst_type_find_get_length (tf);
1007 if (length == 0 || length == (guint64) - 1) {
1013 /* if we're pretty certain already, skip the additional check */
1014 if (prob >= GST_TYPE_FIND_LIKELY)
1017 mp3_type_find_at_offset (tf, length / 2, &mid_layer, &mid_prob);
1021 GST_LOG ("detected audio/mpeg only in the middle (p=%u)", mid_prob);
1027 if (layer != mid_layer) {
1028 GST_WARNING ("audio/mpeg layer discrepancy: %u vs. %u", layer, mid_layer);
1029 return; /* FIXME: or should we just go with the one in the middle? */
1032 /* detected mpeg audio both in middle of the file and at the start */
1033 prob = (prob + mid_prob) / 2;
1037 /* let's see if there's a valid header right at the start */
1038 data = gst_type_find_peek (tf, 0, 4); /* use min. frame size? */
1039 if (data && mp3_type_frame_length_from_header (GST_READ_UINT32_BE (data),
1040 &layer, NULL, NULL, NULL, NULL, 0) != 0) {
1042 prob = GST_TYPE_FIND_POSSIBLE - 10;
1044 prob = MAX (GST_TYPE_FIND_POSSIBLE - 10, prob + 10);
1054 g_return_if_fail (layer >= 1 && layer <= 3);
1056 gst_type_find_suggest_simple (tf, prob, "audio/mpeg",
1057 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, layer, NULL);
1061 /*** audio/x-musepack ***/
1063 static GstStaticCaps musepack_caps =
1064 GST_STATIC_CAPS ("audio/x-musepack, streamversion= (int) { 7, 8 }");
1066 #define MUSEPACK_CAPS (gst_static_caps_get(&musepack_caps))
1068 musepack_type_find (GstTypeFind * tf, gpointer unused)
1070 guint8 *data = gst_type_find_peek (tf, 0, 4);
1071 GstTypeFindProbability prop = GST_TYPE_FIND_MINIMUM;
1072 gint streamversion = -1;
1074 if (data && memcmp (data, "MP+", 3) == 0) {
1076 if ((data[3] & 0x7f) == 7) {
1077 prop = GST_TYPE_FIND_MAXIMUM;
1079 prop = GST_TYPE_FIND_LIKELY + 10;
1081 } else if (data && memcmp (data, "MPCK", 4) == 0) {
1083 prop = GST_TYPE_FIND_MAXIMUM;
1086 if (streamversion != -1) {
1087 gst_type_find_suggest_simple (tf, prop, "audio/x-musepack",
1088 "streamversion", G_TYPE_INT, streamversion, NULL);
1092 /*** audio/x-ac3 ***/
1093 /* FIXME 0.11: should be audio/ac3, but isn't for backwards compatibility */
1094 static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
1096 #define AC3_CAPS (gst_static_caps_get(&ac3_caps))
1100 unsigned short bit_rate;
1101 unsigned short frm_size[3];
1104 static const struct ac3_frmsize ac3_frmsizecod_tbl[] = {
1107 {40, {80, 87, 120}},
1108 {40, {80, 88, 120}},
1109 {48, {96, 104, 144}},
1110 {48, {96, 105, 144}},
1111 {56, {112, 121, 168}},
1112 {56, {112, 122, 168}},
1113 {64, {128, 139, 192}},
1114 {64, {128, 140, 192}},
1115 {80, {160, 174, 240}},
1116 {80, {160, 175, 240}},
1117 {96, {192, 208, 288}},
1118 {96, {192, 209, 288}},
1119 {112, {224, 243, 336}},
1120 {112, {224, 244, 336}},
1121 {128, {256, 278, 384}},
1122 {128, {256, 279, 384}},
1123 {160, {320, 348, 480}},
1124 {160, {320, 349, 480}},
1125 {192, {384, 417, 576}},
1126 {192, {384, 418, 576}},
1127 {224, {448, 487, 672}},
1128 {224, {448, 488, 672}},
1129 {256, {512, 557, 768}},
1130 {256, {512, 558, 768}},
1131 {320, {640, 696, 960}},
1132 {320, {640, 697, 960}},
1133 {384, {768, 835, 1152}},
1134 {384, {768, 836, 1152}},
1135 {448, {896, 975, 1344}},
1136 {448, {896, 976, 1344}},
1137 {512, {1024, 1114, 1536}},
1138 {512, {1024, 1115, 1536}},
1139 {576, {1152, 1253, 1728}},
1140 {576, {1152, 1254, 1728}},
1141 {640, {1280, 1393, 1920}},
1142 {640, {1280, 1394, 1920}}
1146 ac3_type_find (GstTypeFind * tf, gpointer unused)
1148 DataScanCtx c = { 0, NULL, 0 };
1150 /* Search for an ac3 frame; not neccesarily right at the start, but give it
1151 * a lower probability if not found right at the start. Check that the
1152 * frame is followed by a second frame at the expected offset.
1153 * We could also check the two ac3 CRCs, but we don't do that right now */
1154 while (c.offset < 1024) {
1155 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 5)))
1158 if (c.data[0] == 0x0b && c.data[1] == 0x77) {
1159 guint fscod = (c.data[4] >> 6) & 0x03;
1160 guint frmsizecod = c.data[4] & 0x3f;
1162 if (fscod < 3 && frmsizecod < 38) {
1163 DataScanCtx c_next = c;
1166 frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
1167 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1168 data_scan_ctx_advance (tf, &c, frame_size * 2);
1170 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1171 guint fscod2 = (c_next.data[4] >> 6) & 0x03;
1172 guint frmsizecod2 = c_next.data[4] & 0x3f;
1174 if (fscod == fscod2 && frmsizecod == frmsizecod2) {
1175 GstTypeFindProbability prob;
1178 prob = GST_TYPE_FIND_MAXIMUM;
1180 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1182 gst_type_find_suggest (tf, prob, AC3_CAPS);
1189 data_scan_ctx_advance (tf, &c, 1);
1195 /* can only be detected by using the extension, in which case we use the default
1197 static GstStaticCaps gsm_caps =
1198 GST_STATIC_CAPS ("audio/x-gsm, rate=8000, channels=1");
1200 #define GSM_CAPS (gst_static_caps_get(&gsm_caps))
1204 static GstStaticCaps wavpack_caps =
1205 GST_STATIC_CAPS ("audio/x-wavpack, framed = (boolean) false");
1207 #define WAVPACK_CAPS (gst_static_caps_get(&wavpack_caps))
1209 static GstStaticCaps wavpack_correction_caps =
1210 GST_STATIC_CAPS ("audio/x-wavpack-correction, framed = (boolean) false");
1212 #define WAVPACK_CORRECTION_CAPS (gst_static_caps_get(&wavpack_correction_caps))
1215 wavpack_type_find (GstTypeFind * tf, gpointer unused)
1221 data = gst_type_find_peek (tf, 0, 32);
1225 if (data[0] != 'w' || data[1] != 'v' || data[2] != 'p' || data[3] != 'k')
1228 /* Note: wavpack blocks can be fairly large (easily 60-110k), possibly
1229 * larger than the max. limits imposed by certain typefinding elements
1230 * like id3demux or apedemux, so typefinding is most likely only going to
1231 * work in pull-mode */
1232 blocksize = GST_READ_UINT32_LE (data + 4);
1233 GST_LOG ("wavpack header, blocksize=0x%04x", blocksize);
1235 while (offset < 32 + blocksize) {
1238 /* get chunk header */
1239 GST_LOG ("peeking at chunk at offset 0x%04x", (guint) offset);
1240 data = gst_type_find_peek (tf, offset, 4);
1243 sublen = ((guint32) data[1]) << 1;
1244 if (data[0] & 0x80) {
1245 sublen |= (((guint32) data[2]) << 9) | (((guint32) data[3]) << 17);
1246 sublen += 1 + 3; /* id + length */
1248 sublen += 1 + 1; /* id + length */
1250 if (sublen > blocksize - offset + 32) {
1251 GST_LOG ("chunk length too big (%u > %" G_GUINT64_FORMAT ")", sublen,
1252 blocksize - offset);
1255 if ((data[0] & 0x20) == 0) {
1256 switch (data[0] & 0x0f) {
1257 case 0xa: /* ID_WV_BITSTREAM */
1258 case 0xc: /* ID_WVX_BITSTREAM */
1259 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, WAVPACK_CAPS);
1261 case 0xb: /* ID_WVC_BITSTREAM */
1262 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY,
1263 WAVPACK_CORRECTION_CAPS);
1273 /*** application/postscrip ***/
1274 static GstStaticCaps postscript_caps =
1275 GST_STATIC_CAPS ("application/postscript");
1277 #define POSTSCRIPT_CAPS (gst_static_caps_get(&postscript_caps))
1280 postscript_type_find (GstTypeFind * tf, gpointer unused)
1282 guint8 *data = gst_type_find_peek (tf, 0, 3);
1286 if (data[0] == 0x04)
1288 if (data[0] == '%' && data[1] == '!')
1289 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, POSTSCRIPT_CAPS);
1293 /*** image/svg+xml ***/
1294 static GstStaticCaps svg_caps = GST_STATIC_CAPS ("image/svg+xml");
1296 #define SVG_CAPS (gst_static_caps_get(&svg_caps))
1299 svg_type_find (GstTypeFind * tf, gpointer unused)
1301 static const gchar svg_doctype[] = "!DOCTYPE svg";
1302 static const gchar svg_tag[] = "<svg";
1303 DataScanCtx c = { 0, NULL, 0 };
1305 while (c.offset <= 1024) {
1306 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
1309 if (memcmp (svg_doctype, c.data, 12) == 0) {
1310 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVG_CAPS);
1312 } else if (memcmp (svg_tag, c.data, 4) == 0) {
1313 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, SVG_CAPS);
1316 data_scan_ctx_advance (tf, &c, 1);
1320 /*** multipart/x-mixed-replace mimestream ***/
1322 static GstStaticCaps multipart_caps =
1323 GST_STATIC_CAPS ("multipart/x-mixed-replace");
1324 #define MULTIPART_CAPS gst_static_caps_get(&multipart_caps)
1326 /* multipart/x-mixed replace is:
1327 * <maybe some whitespace>--<some ascii chars>[\r]\n
1328 * <more ascii chars>[\r]\nContent-type:<more ascii>[\r]\n */
1330 multipart_type_find (GstTypeFind * tf, gpointer unused)
1335 #define MULTIPART_MAX_BOUNDARY_OFFSET 16
1336 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_BOUNDARY_OFFSET);
1341 x - data < MULTIPART_MAX_BOUNDARY_OFFSET - 2 && g_ascii_isspace (*x);
1343 if (x[0] != '-' || x[1] != '-')
1346 /* Could be okay, peek what should be enough for a complete header */
1347 #define MULTIPART_MAX_HEADER_SIZE 256
1348 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_HEADER_SIZE);
1352 for (x = data; x - data < MULTIPART_MAX_HEADER_SIZE - 14; x++) {
1353 if (!isascii (*x)) {
1357 !g_ascii_strncasecmp ("content-type:", (gchar *) x + 1, 13)) {
1358 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MULTIPART_CAPS);
1364 /*** video/mpeg systemstream ***/
1365 static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, "
1366 "systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
1368 #define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
1369 #define IS_MPEG_HEADER(data) (G_UNLIKELY((((guint8 *)(data))[0] == 0x00) && \
1370 (((guint8 *)(data))[1] == 0x00) && \
1371 (((guint8 *)(data))[2] == 0x01)))
1373 #define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
1374 #define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
1375 #define IS_MPEG_PACK_HEADER(data) (IS_MPEG_HEADER (data) && \
1376 IS_MPEG_PACK_CODE (((guint8 *)(data))[3]))
1378 #define IS_MPEG_PES_CODE(b) (((b) & 0xF0) == 0xE0 || ((b) & 0xF0) == 0xC0 || \
1380 #define IS_MPEG_PES_HEADER(data) (IS_MPEG_HEADER (data) && \
1381 IS_MPEG_PES_CODE (((guint8 *)(data))[3]))
1383 #define MPEG2_MAX_PROBE_LENGTH (128 * 1024) /* 128kB should be 64 packs of the
1384 * most common 2kB pack size. */
1386 #define MPEG2_MIN_SYS_HEADERS 2
1387 #define MPEG2_MAX_SYS_HEADERS 5
1390 mpeg_sys_is_valid_pack (GstTypeFind * tf, const guint8 * data, guint len,
1393 /* Check the pack header @ offset for validity, assuming that the 4 byte header
1394 * itself has already been checked. */
1400 /* Check marker bits */
1401 if ((data[4] & 0xC4) == 0x44) {
1406 if ((data[6] & 0x04) != 0x04 ||
1407 (data[8] & 0x04) != 0x04 ||
1408 (data[9] & 0x01) != 0x01 || (data[12] & 0x03) != 0x03)
1411 stuff_len = data[13] & 0x07;
1413 /* Check the following header bytes, if we can */
1414 if ((14 + stuff_len + 4) <= len) {
1415 if (!IS_MPEG_HEADER (data + 14 + stuff_len))
1419 *pack_size = 14 + stuff_len;
1421 } else if ((data[4] & 0xF1) == 0x21) {
1423 if ((data[6] & 0x01) != 0x01 ||
1424 (data[8] & 0x01) != 0x01 ||
1425 (data[9] & 0x80) != 0x80 || (data[11] & 0x01) != 0x01)
1428 /* Check the following header bytes, if we can */
1429 if ((12 + 4) <= len) {
1430 if (!IS_MPEG_HEADER (data + 12))
1442 mpeg_sys_is_valid_pes (GstTypeFind * tf, guint8 * data, guint len,
1445 guint pes_packet_len;
1447 /* Check the PES header at the given position, assuming the header code itself
1448 * was already checked */
1452 /* For MPEG Program streams, unbounded PES is not allowed, so we must have a
1453 * valid length present */
1454 pes_packet_len = GST_READ_UINT16_BE (data + 4);
1455 if (pes_packet_len == 0)
1458 /* Check the following header, if we can */
1459 if (6 + pes_packet_len + 4 <= len) {
1460 if (!IS_MPEG_HEADER (data + 6 + pes_packet_len))
1465 *pack_size = 6 + pes_packet_len;
1470 mpeg_sys_is_valid_sys (GstTypeFind * tf, guint8 * data, guint len,
1475 /* Check the System header at the given position, assuming the header code itself
1476 * was already checked */
1479 sys_hdr_len = GST_READ_UINT16_BE (data + 4);
1480 if (sys_hdr_len < 6)
1483 /* Check the following header, if we can */
1484 if (6 + sys_hdr_len + 4 <= len) {
1485 if (!IS_MPEG_HEADER (data + 6 + sys_hdr_len))
1490 *pack_size = 6 + sys_hdr_len;
1495 /* calculation of possibility to identify random data as mpeg systemstream:
1496 * bits that must match in header detection: 32 (or more)
1497 * chance that random data is identifed: 1/2^32
1498 * chance that MPEG2_MIN_PACK_HEADERS headers are identified:
1499 * 1/2^(32*MPEG2_MIN_PACK_HEADERS)
1500 * chance that this happens in MPEG2_MAX_PROBE_LENGTH bytes:
1501 * 1-(1+1/2^(32*MPEG2_MIN_PACK_HEADERS)^MPEG2_MAX_PROBE_LENGTH)
1502 * for current values:
1503 * 1-(1+1/2^(32*4)^101024)
1505 * Since we also check marker bits and pes packet lengths, this probability is a
1506 * very coarse upper bound.
1509 mpeg_sys_type_find (GstTypeFind * tf, gpointer unused)
1511 guint8 *data, *data0, *first_sync, *end;
1512 gint mpegversion = 0;
1513 guint pack_headers = 0;
1514 guint pes_headers = 0;
1516 guint since_last_sync = 0;
1517 guint32 sync_word = 0xffffffff;
1522 len = MPEG2_MAX_PROBE_LENGTH;
1525 data = gst_type_find_peek (tf, 0, 5 + len);
1526 } while (data == NULL && len >= 32);
1538 while (data < end) {
1540 if (sync_word == 0x00000100) {
1541 /* Found potential sync word */
1542 if (first_sync == NULL)
1543 first_sync = data - 3;
1545 if (since_last_sync > 4) {
1546 /* If more than 4 bytes since the last sync word, reset our counters,
1547 * as we're only interested in counting contiguous packets */
1548 pes_headers = pack_headers = 0;
1552 if (IS_MPEG_PACK_CODE (data[0])) {
1553 if ((data[1] & 0xC0) == 0x40) {
1556 } else if ((data[1] & 0xF0) == 0x20) {
1559 if (mpegversion != 0 &&
1560 mpeg_sys_is_valid_pack (tf, data - 3, end - data + 3, &pack_size)) {
1563 } else if (IS_MPEG_PES_CODE (data[0])) {
1565 if (mpeg_sys_is_valid_pes (tf, data - 3, end - data + 3, &pack_size)) {
1567 if (mpegversion == 0)
1570 } else if (IS_MPEG_SYS_CODE (data[0])) {
1571 if (mpeg_sys_is_valid_sys (tf, data - 3, end - data + 3, &pack_size)) {
1576 /* If we found a packet with a known size, skip the bytes in it and loop
1577 * around to check the next packet. */
1578 if (pack_size != 0) {
1579 data += pack_size - 3;
1580 sync_word = 0xffffffff;
1581 since_last_sync = 0;
1586 sync_word |= data[0];
1590 /* If we have found MAX headers, and *some* were pes headers (pack headers
1591 * are optional in an mpeg system stream) then return our high-probability
1593 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MAX_SYS_HEADERS)
1597 /* If we at least saw MIN headers, and *some* were pes headers (pack headers
1598 * are optional in an mpeg system stream) then return a lower-probability
1600 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MIN_SYS_HEADERS)
1608 prob = GST_TYPE_FIND_POSSIBLE + (10 * (pack_headers + pes_headers));
1609 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
1611 /* lower probability if the first packet wasn't right at the start */
1612 if (data0 != first_sync && prob >= 10)
1615 GST_LOG ("Suggesting MPEG %d system stream, %d packs, %d pes, prob %u%%\n",
1616 mpegversion, pack_headers, pes_headers, prob);
1618 gst_type_find_suggest_simple (tf, prob, "video/mpeg",
1619 "systemstream", G_TYPE_BOOLEAN, TRUE,
1620 "mpegversion", G_TYPE_INT, mpegversion, NULL);
1624 /*** video/mpegts Transport Stream ***/
1625 static GstStaticCaps mpegts_caps = GST_STATIC_CAPS ("video/mpegts, "
1626 "systemstream = (boolean) true, packetsize = (int) [ 188, 208 ]");
1627 #define MPEGTS_CAPS gst_static_caps_get(&mpegts_caps)
1629 #define GST_MPEGTS_TYPEFIND_MIN_HEADERS 4
1630 #define GST_MPEGTS_TYPEFIND_MAX_HEADERS 10
1631 #define GST_MPEGTS_MAX_PACKET_SIZE 208
1632 #define GST_MPEGTS_TYPEFIND_SYNC_SIZE \
1633 (GST_MPEGTS_TYPEFIND_MIN_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
1634 #define GST_MPEGTS_TYPEFIND_MAX_SYNC \
1635 (GST_MPEGTS_TYPEFIND_MAX_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
1637 #define MPEGTS_HDR_SIZE 4
1638 /* Check for sync byte, error_indicator == 0 and packet has payload */
1639 #define IS_MPEGTS_HEADER(data) (((data)[0] == 0x47) && \
1640 (((data)[1] & 0x80) == 0x00) && \
1641 (((data)[3] & 0x10) == 0x10))
1643 /* Helper function to search ahead at intervals of packet_size for mpegts
1646 mpeg_ts_probe_headers (GstTypeFind * tf, guint64 offset, gint packet_size)
1648 /* We always enter this function having found at least one header already */
1650 guint8 *data = NULL;
1652 while (found < GST_MPEGTS_TYPEFIND_MAX_HEADERS) {
1653 offset += packet_size;
1655 data = gst_type_find_peek (tf, offset, MPEGTS_HDR_SIZE);
1656 if (data == NULL || !IS_MPEGTS_HEADER (data))
1665 /* Try and detect at least 4 packets in at most 10 packets worth of
1666 * data. Need to try several possible packet sizes */
1668 mpeg_ts_type_find (GstTypeFind * tf, gpointer unused)
1670 /* TS packet sizes to test: normal, DVHS packet size and
1671 * FEC with 16 or 20 byte codes packet size. */
1672 const gint pack_sizes[] = { 188, 192, 204, 208 };
1673 const gint n_pack_sizes = sizeof (pack_sizes) / sizeof (gint);
1675 guint8 *data = NULL;
1677 guint64 skipped = 0;
1679 while (skipped < GST_MPEGTS_TYPEFIND_MAX_SYNC) {
1680 if (size < MPEGTS_HDR_SIZE) {
1681 data = gst_type_find_peek (tf, skipped, GST_MPEGTS_TYPEFIND_SYNC_SIZE);
1684 size = GST_MPEGTS_TYPEFIND_SYNC_SIZE;
1687 /* Have at least MPEGTS_HDR_SIZE bytes at this point */
1688 if (IS_MPEGTS_HEADER (data)) {
1691 for (p = 0; p < n_pack_sizes; p++) {
1694 /* Probe ahead at size pack_sizes[p] */
1695 found = mpeg_ts_probe_headers (tf, skipped, pack_sizes[p]);
1696 if (found >= GST_MPEGTS_TYPEFIND_MIN_HEADERS) {
1699 /* found at least 4 headers. 10 headers = MAXIMUM probability.
1700 * Arbitrarily, I assigned 10% probability for each header we
1701 * found, 40% -> 100% */
1702 probability = MIN (10 * found, GST_TYPE_FIND_MAXIMUM);
1704 gst_type_find_suggest_simple (tf, probability, "video/mpegts",
1705 "systemstream", G_TYPE_BOOLEAN, TRUE,
1706 "packetsize", G_TYPE_INT, pack_sizes[p], NULL);
1717 #define GST_MPEGVID_TYPEFIND_TRY_PICTURES 6
1718 #define GST_MPEGVID_TYPEFIND_TRY_SYNC (100 * 1024) /* 100 kB */
1720 /* Scan ahead a maximum of max_extra_offset bytes until the next IS_MPEG_HEADER
1721 * offset. After the call, offset will be after the 0x000001, i.e. at the 4th
1722 * byte of the MPEG header. Returns TRUE if a header was found, FALSE if not.
1725 mpeg_find_next_header (GstTypeFind * tf, DataScanCtx * c,
1726 guint64 max_extra_offset)
1728 guint64 extra_offset;
1730 for (extra_offset = 0; extra_offset <= max_extra_offset; ++extra_offset) {
1731 if (!data_scan_ctx_ensure_data (tf, c, 4))
1733 if (IS_MPEG_HEADER (c->data)) {
1734 data_scan_ctx_advance (tf, c, 3);
1737 data_scan_ctx_advance (tf, c, 1);
1742 /*** video/mpeg MPEG-4 elementary video stream ***/
1744 static GstStaticCaps mpeg4_video_caps = GST_STATIC_CAPS ("video/mpeg, "
1745 "systemstream=(boolean)false, mpegversion=4, parsed=(boolean)false");
1746 #define MPEG4_VIDEO_CAPS gst_static_caps_get(&mpeg4_video_caps)
1749 * This typefind is based on the elementary video header defined in
1750 * http://xhelmboyx.tripod.com/formats/mpeg-layout.txt
1751 * In addition, it allows the visual object sequence header to be
1752 * absent, and even the VOS header to be absent. In the latter case,
1753 * a number of VOPs have to be present.
1756 mpeg4_video_type_find (GstTypeFind * tf, gpointer unused)
1758 DataScanCtx c = { 0, NULL, 0 };
1759 gboolean seen_vios_at_0 = FALSE;
1760 gboolean seen_vios = FALSE;
1761 gboolean seen_vos = FALSE;
1762 gboolean seen_vol = FALSE;
1763 guint num_vop_headers = 0;
1766 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
1767 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
1770 if (!mpeg_find_next_header (tf, &c,
1771 GST_MPEGVID_TYPEFIND_TRY_SYNC - c.offset))
1776 /* visual_object_sequence_start_code */
1779 break; /* Terminate at second vios */
1781 seen_vios_at_0 = TRUE;
1783 data_scan_ctx_advance (tf, &c, 2);
1784 if (!mpeg_find_next_header (tf, &c, 0))
1789 /* Optional metadata */
1791 if (!mpeg_find_next_header (tf, &c, 24))
1795 /* visual_object_start_code (consider it optional) */
1797 data_scan_ctx_advance (tf, &c, 2);
1798 /* may contain ID marker and YUV clamping */
1799 if (!mpeg_find_next_header (tf, &c, 7))
1805 /* video_object_start_code */
1808 break; /* Terminate at second vos */
1810 data_scan_ctx_advance (tf, &c, 2);
1814 /* video_object_layer_start_code */
1815 if (sc >= 0x20 && sc <= 0x2F) {
1817 data_scan_ctx_advance (tf, &c, 5);
1821 /* video_object_plane_start_code */
1824 data_scan_ctx_advance (tf, &c, 2);
1828 /* Unknown start code. */
1831 if (num_vop_headers > 0 || seen_vol) {
1832 GstTypeFindProbability probability = 0;
1834 GST_LOG ("Found %d pictures, vios: %d, vos:%d, vol:%d", num_vop_headers,
1835 seen_vios, seen_vos, seen_vol);
1837 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios_at_0
1838 && seen_vos && seen_vol)
1839 probability = GST_TYPE_FIND_MAXIMUM - 1;
1840 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios
1841 && seen_vos && seen_vol)
1842 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
1843 else if (seen_vios_at_0 && seen_vos && seen_vol)
1844 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
1845 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vos
1847 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
1848 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vol)
1849 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
1850 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
1851 probability = GST_TYPE_FIND_LIKELY - 1;
1852 else if (num_vop_headers > 2 && seen_vios && seen_vos && seen_vol)
1853 probability = GST_TYPE_FIND_LIKELY - 9;
1854 else if (seen_vios && seen_vos && seen_vol)
1855 probability = GST_TYPE_FIND_LIKELY - 20;
1856 else if (num_vop_headers > 0 && seen_vos && seen_vol)
1857 probability = GST_TYPE_FIND_POSSIBLE;
1858 else if (num_vop_headers > 0)
1859 probability = GST_TYPE_FIND_POSSIBLE - 10;
1860 else if (seen_vos && seen_vol)
1861 probability = GST_TYPE_FIND_POSSIBLE - 20;
1863 gst_type_find_suggest (tf, probability, MPEG4_VIDEO_CAPS);
1867 /*** video/x-h264 H264 elementary video stream ***/
1869 static GstStaticCaps h264_video_caps = GST_STATIC_CAPS ("video/x-h264");
1871 #define H264_VIDEO_CAPS gst_static_caps_get(&h264_video_caps)
1873 #define H264_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
1876 h264_video_type_find (GstTypeFind * tf, gpointer unused)
1878 DataScanCtx c = { 0, NULL, 0 };
1880 /* Stream consists of: a series of sync codes (00 00 00 01) followed
1887 while (c.offset < H264_MAX_PROBE_LENGTH) {
1888 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
1891 if (IS_MPEG_HEADER (c.data)) {
1892 nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
1893 ref = c.data[3] & 0x60; /* nal_ref_idc */
1895 /* if forbiden bit is different to 0 won't be h264 */
1901 /* collect statistics about the NAL types */
1902 if ((nut >= 1 && nut <= 13) || nut == 19) {
1903 if ((nut == 5 && ref == 0) ||
1904 ((nut == 6 || (nut >= 9 && nut <= 12)) && ref != 0)) {
1909 } else if (nut >= 14 && nut <= 33) {
1911 /* Theoretically these are good, since if they exist in the
1912 stream it merely means that a newer backwards-compatible
1913 h.264 stream. But we should be identifying that separately. */
1916 /* unspecified, application specific */
1917 /* don't consider these bad */
1920 GST_DEBUG ("good %d bad %d", good, bad);
1922 if (good >= 10 && bad < 4) {
1923 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H264_VIDEO_CAPS);
1927 data_scan_ctx_advance (tf, &c, 4);
1929 data_scan_ctx_advance (tf, &c, 1);
1932 if (good >= 2 && bad < 1) {
1933 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H264_VIDEO_CAPS);
1938 /*** video/mpeg video stream ***/
1940 static GstStaticCaps mpeg_video_caps = GST_STATIC_CAPS ("video/mpeg, "
1941 "systemstream = (boolean) false");
1942 #define MPEG_VIDEO_CAPS gst_static_caps_get(&mpeg_video_caps)
1945 * Idea is the same as MPEG system stream typefinding: We check each
1946 * byte of the stream to see if - from that point on - the stream
1947 * matches a predefined set of marker bits as defined in the MPEG
1950 * I'm sure someone will do a chance calculation here too.
1954 mpeg_video_stream_type_find (GstTypeFind * tf, gpointer unused)
1956 DataScanCtx c = { 0, NULL, 0 };
1957 gboolean seen_seq_at_0 = FALSE;
1958 gboolean seen_seq = FALSE;
1959 gboolean seen_gop = FALSE;
1960 guint64 last_pic_offset = 0;
1961 guint num_pic_headers = 0;
1964 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
1965 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
1968 if (!data_scan_ctx_ensure_data (tf, &c, 5))
1971 if (!IS_MPEG_HEADER (c.data))
1974 /* a pack header indicates that this isn't an elementary stream */
1975 if (c.data[3] == 0xBA && mpeg_sys_is_valid_pack (tf, c.data, c.size, NULL))
1978 /* do we have a sequence header? */
1979 if (c.data[3] == 0xB3) {
1980 seen_seq_at_0 = seen_seq_at_0 || (c.offset == 0);
1982 data_scan_ctx_advance (tf, &c, 4 + 8);
1986 /* or a GOP header */
1987 if (c.data[3] == 0xB8) {
1989 data_scan_ctx_advance (tf, &c, 8);
1993 /* but what we'd really like to see is a picture header */
1994 if (c.data[3] == 0x00) {
1996 last_pic_offset = c.offset;
1997 data_scan_ctx_advance (tf, &c, 8);
2001 /* ... each followed by a slice header with slice_vertical_pos=1 that's
2002 * not too far away from the previously seen picture header. */
2003 if (c.data[3] == 0x01 && num_pic_headers > found &&
2004 (c.offset - last_pic_offset) >= 4 &&
2005 (c.offset - last_pic_offset) <= 64) {
2006 data_scan_ctx_advance (tf, &c, 4);
2013 data_scan_ctx_advance (tf, &c, 1);
2016 if (found > 0 || seen_seq) {
2017 GstTypeFindProbability probability = 0;
2019 GST_LOG ("Found %d pictures, seq:%d, gop:%d", found, seen_seq, seen_gop);
2021 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq && seen_gop)
2022 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2023 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq)
2024 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2025 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2026 probability = GST_TYPE_FIND_LIKELY;
2027 else if (seen_seq_at_0 && seen_gop && found > 2)
2028 probability = GST_TYPE_FIND_LIKELY - 10;
2029 else if (seen_seq && seen_gop && found > 2)
2030 probability = GST_TYPE_FIND_LIKELY - 20;
2031 else if (seen_seq_at_0 && found > 0)
2032 probability = GST_TYPE_FIND_POSSIBLE;
2033 else if (seen_seq && found > 0)
2034 probability = GST_TYPE_FIND_POSSIBLE - 5;
2036 probability = GST_TYPE_FIND_POSSIBLE - 10;
2038 probability = GST_TYPE_FIND_POSSIBLE - 20;
2040 gst_type_find_suggest_simple (tf, probability, "video/mpeg",
2041 "systemstream", G_TYPE_BOOLEAN, FALSE,
2042 "mpegversion", G_TYPE_INT, 1, NULL);
2046 /*** audio/x-aiff ***/
2048 static GstStaticCaps aiff_caps = GST_STATIC_CAPS ("audio/x-aiff");
2050 #define AIFF_CAPS gst_static_caps_get(&aiff_caps)
2052 aiff_type_find (GstTypeFind * tf, gpointer unused)
2054 guint8 *data = gst_type_find_peek (tf, 0, 4);
2056 if (data && memcmp (data, "FORM", 4) == 0) {
2058 if (memcmp (data, "AIFF", 4) == 0 || memcmp (data, "AIFC", 4) == 0)
2059 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AIFF_CAPS);
2063 /*** audio/x-svx ***/
2065 static GstStaticCaps svx_caps = GST_STATIC_CAPS ("audio/x-svx");
2067 #define SVX_CAPS gst_static_caps_get(&svx_caps)
2069 svx_type_find (GstTypeFind * tf, gpointer unused)
2071 guint8 *data = gst_type_find_peek (tf, 0, 4);
2073 if (data && memcmp (data, "FORM", 4) == 0) {
2075 if (memcmp (data, "8SVX", 4) == 0 || memcmp (data, "16SV", 4) == 0)
2076 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVX_CAPS);
2080 /*** audio/x-shorten ***/
2082 static GstStaticCaps shn_caps = GST_STATIC_CAPS ("audio/x-shorten");
2084 #define SHN_CAPS gst_static_caps_get(&shn_caps)
2086 shn_type_find (GstTypeFind * tf, gpointer unused)
2088 guint8 *data = gst_type_find_peek (tf, 0, 4);
2090 if (data && memcmp (data, "ajkg", 4) == 0) {
2091 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2093 data = gst_type_find_peek (tf, -8, 8);
2094 if (data && memcmp (data, "SHNAMPSK", 8) == 0) {
2095 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2099 /*** application/x-ape ***/
2101 static GstStaticCaps ape_caps = GST_STATIC_CAPS ("application/x-ape");
2103 #define APE_CAPS gst_static_caps_get(&ape_caps)
2105 ape_type_find (GstTypeFind * tf, gpointer unused)
2107 guint8 *data = gst_type_find_peek (tf, 0, 4);
2109 if (data && memcmp (data, "MAC ", 4) == 0) {
2110 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 10, APE_CAPS);
2114 /*** ISO FORMATS ***/
2116 /*** audio/x-m4a ***/
2118 static GstStaticCaps m4a_caps = GST_STATIC_CAPS ("audio/x-m4a");
2120 #define M4A_CAPS (gst_static_caps_get(&m4a_caps))
2122 m4a_type_find (GstTypeFind * tf, gpointer unused)
2124 guint8 *data = gst_type_find_peek (tf, 4, 8);
2127 (memcmp (data, "ftypM4A ", 8) == 0 ||
2128 memcmp (data, "ftypmp42", 8) == 0)) {
2129 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
2133 /*** application/x-3gp ***/
2135 /* The Q is there because variables can't start with a number. */
2138 static GstStaticCaps q3gp_caps = GST_STATIC_CAPS ("application/x-3gp");
2140 #define Q3GP_CAPS (gst_static_caps_get(&q3gp_caps))
2142 q3gp_type_find (GstTypeFind * tf, gpointer unused)
2145 guint32 ftyp_size = 0;
2147 guint8 *data = NULL;
2149 if ((data = gst_type_find_peek (tf, 0, 12)) == NULL) {
2154 if (memcmp (data, "ftyp", 4) != 0) {
2158 /* check major brand */
2160 if (memcmp (data, "3gp", 3) == 0 ||
2161 memcmp (data, "3gr", 3) == 0 ||
2162 memcmp (data, "3gs", 3) == 0 || memcmp (data, "3gg", 3) == 0) {
2163 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, Q3GP_CAPS);
2167 /* check compatible brands */
2168 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2169 ftyp_size = GST_READ_UINT32_BE (data);
2171 for (offset = 16; offset < ftyp_size; offset += 4) {
2172 if ((data = gst_type_find_peek (tf, offset, 3)) == NULL) {
2175 if (memcmp (data, "3gp", 3) == 0 ||
2176 memcmp (data, "3gr", 3) == 0 ||
2177 memcmp (data, "3gs", 3) == 0 || memcmp (data, "3gg", 3) == 0) {
2178 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, Q3GP_CAPS);
2187 /*** video/mj2 and image/jp2 ***/
2188 static GstStaticCaps mj2_caps = GST_STATIC_CAPS ("video/mj2");
2190 #define MJ2_CAPS gst_static_caps_get(&mj2_caps)
2192 static GstStaticCaps jp2_caps = GST_STATIC_CAPS ("image/jp2");
2194 #define JP2_CAPS gst_static_caps_get(&jp2_caps)
2197 jp2_type_find (GstTypeFind * tf, gpointer unused)
2201 data = gst_type_find_peek (tf, 0, 24);
2206 if (memcmp (data, "\000\000\000\014jP \015\012\207\012", 12) != 0)
2209 /* check ftyp box */
2211 if (memcmp (data + 4, "ftyp", 4) == 0) {
2212 if (memcmp (data + 8, "jp2 ", 4) == 0)
2213 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JP2_CAPS);
2214 else if (memcmp (data + 8, "mjp2", 4) == 0)
2215 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MJ2_CAPS);
2219 /*** video/quicktime ***/
2221 static GstStaticCaps qt_caps = GST_STATIC_CAPS ("video/quicktime");
2223 #define QT_CAPS gst_static_caps_get(&qt_caps)
2224 #define STRNCMP(x,y,z) (strncmp ((char*)(x), (char*)(y), z))
2227 qt_type_find (GstTypeFind * tf, gpointer unused)
2233 const gchar *variant = NULL;
2235 while ((data = gst_type_find_peek (tf, offset, 12)) != NULL) {
2238 if (STRNCMP (&data[4], "ftypqt ", 8) == 0) {
2239 tip = GST_TYPE_FIND_MAXIMUM;
2243 if (STRNCMP (&data[4], "ftypisom", 8) == 0) {
2244 tip = GST_TYPE_FIND_MAXIMUM;
2249 /* box/atom types that are in common with ISO base media file format */
2250 if (STRNCMP (&data[4], "moov", 4) == 0 ||
2251 STRNCMP (&data[4], "mdat", 4) == 0 ||
2252 STRNCMP (&data[4], "ftyp", 4) == 0 ||
2253 STRNCMP (&data[4], "free", 4) == 0 ||
2254 STRNCMP (&data[4], "uuid", 4) == 0 ||
2255 STRNCMP (&data[4], "skip", 4) == 0) {
2257 tip = GST_TYPE_FIND_LIKELY;
2259 tip = GST_TYPE_FIND_NEARLY_CERTAIN;
2262 /* other box/atom types, apparently quicktime specific */
2263 else if (STRNCMP (&data[4], "pnot", 4) == 0 ||
2264 STRNCMP (&data[4], "PICT", 4) == 0 ||
2265 STRNCMP (&data[4], "wide", 4) == 0 ||
2266 STRNCMP (&data[4], "prfl", 4) == 0) {
2267 tip = GST_TYPE_FIND_MAXIMUM;
2273 size = GST_READ_UINT32_BE (data);
2277 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2278 if (sizedata == NULL)
2281 size = GST_READ_UINT64_BE (sizedata);
2286 new_offset = offset + size;
2287 if (new_offset <= offset)
2289 offset = new_offset;
2294 GstCaps *caps = gst_caps_copy (QT_CAPS);
2296 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, variant, NULL);
2297 gst_type_find_suggest (tf, tip, caps);
2298 gst_caps_unref (caps);
2300 gst_type_find_suggest (tf, tip, QT_CAPS);
2306 /*** image/x-quicktime ***/
2308 static GstStaticCaps qtif_caps = GST_STATIC_CAPS ("image/x-quicktime");
2310 #define QTIF_CAPS gst_static_caps_get(&qtif_caps)
2312 /* how many atoms we check before we give up */
2313 #define QTIF_MAXROUNDS 25
2316 qtif_type_find (GstTypeFind * tf, gpointer unused)
2319 gboolean found_idsc = FALSE;
2320 gboolean found_idat = FALSE;
2324 while ((data = gst_type_find_peek (tf, offset, 8)) != NULL) {
2327 size = GST_READ_UINT32_BE (data);
2329 const guint8 *sizedata;
2331 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2332 if (sizedata == NULL)
2335 size = GST_READ_UINT64_BE (sizedata);
2340 if (STRNCMP (data + 4, "idsc", 4) == 0)
2342 if (STRNCMP (data + 4, "idat", 4) == 0)
2345 if (found_idsc && found_idat) {
2346 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, QTIF_CAPS);
2351 if (++rounds > QTIF_MAXROUNDS)
2355 if (found_idsc || found_idat) {
2356 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, QTIF_CAPS);
2361 /*** audio/x-mod ***/
2363 static GstStaticCaps mod_caps = GST_STATIC_CAPS ("audio/x-mod");
2365 #define MOD_CAPS gst_static_caps_get(&mod_caps)
2366 /* FIXME: M15 CheckType to do */
2368 mod_type_find (GstTypeFind * tf, gpointer unused)
2373 if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) {
2374 /* Protracker and variants */
2375 if ((memcmp (data, "M.K.", 4) == 0) || (memcmp (data, "M!K!", 4) == 0) ||
2377 (memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) ||
2378 (memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) ||
2379 /* Oktalyzer (Amiga) */
2380 (memcmp (data, "OKTA", 4) == 0) ||
2381 /* Oktalyser (Atari) */
2382 (memcmp (data, "CD81", 4) == 0) ||
2384 (memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) ||
2385 /* Fasttracker or Taketracker */
2386 (memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0])
2387 && isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0
2388 && isdigit (data[0]) && isdigit (data[1]))) {
2389 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2394 if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) {
2395 if (memcmp (data, "Extended Module: ", 17) == 0 && data[37] == 0x1A) {
2396 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2401 if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) {
2402 if (memcmp (data, "OKTASONG", 8) == 0) {
2403 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2407 if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2409 if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) {
2410 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2414 if ((memcmp (data, "AMF", 3) == 0 && data[3] > 10 && data[3] < 14) ||
2416 (memcmp (data, "IMPM", 4) == 0) ||
2418 (memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0) ||
2420 (memcmp (data, "MTM", 3) == 0)) {
2421 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2425 if (memcmp (data, "RIFF", 4) == 0) {
2426 guint8 *data2 = gst_type_find_peek (tf, 8, 4);
2429 if (memcmp (data2, "DSMF", 4) == 0) {
2430 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2436 if (memcmp (data, "FAM\xFE", 4) == 0) {
2437 guint8 *data2 = gst_type_find_peek (tf, 44, 3);
2440 if (memcmp (data2, "compare", 3) == 0) {
2441 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2445 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2450 if (memcmp (data, "GDM\xFE", 4) == 0) {
2451 guint8 *data2 = gst_type_find_peek (tf, 71, 4);
2454 if (memcmp (data2, "GMFS", 4) == 0) {
2455 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2459 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2465 if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) {
2466 if (memcmp (data, "IM10", 4) == 0) {
2467 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2472 if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) {
2473 if (memcmp (data, "SCRM", 4) == 0) {
2474 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2479 if ((data = gst_type_find_peek (tf, 20, 8)) != NULL) {
2480 if (g_ascii_strncasecmp ((gchar *) data, "!Scream!", 8) == 0 ||
2481 g_ascii_strncasecmp ((gchar *) data, "BMOD2STM", 8) == 0) {
2482 guint8 *id, *stmtype;
2484 if ((id = gst_type_find_peek (tf, 28, 1)) == NULL)
2486 if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL)
2488 if (*id == 0x1A && *stmtype == 2)
2489 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2495 /*** application/x-shockwave-flash ***/
2497 static GstStaticCaps swf_caps =
2498 GST_STATIC_CAPS ("application/x-shockwave-flash");
2499 #define SWF_CAPS (gst_static_caps_get(&swf_caps))
2501 swf_type_find (GstTypeFind * tf, gpointer unused)
2503 guint8 *data = gst_type_find_peek (tf, 0, 4);
2505 if (data && (data[0] == 'F' || data[0] == 'C') &&
2506 data[1] == 'W' && data[2] == 'S') {
2507 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SWF_CAPS);
2511 /*** image/jpeg ***/
2513 static GstStaticCaps jpeg_caps = GST_STATIC_CAPS ("image/jpeg");
2515 #define JPEG_CAPS (gst_static_caps_get(&jpeg_caps))
2517 jpeg_type_find (GstTypeFind * tf, gpointer unused)
2519 guint8 *data = gst_type_find_peek (tf, 0, 10);
2520 guint8 header[2] = { 0xFF, 0xD8 };
2522 if (data && memcmp (data, header, 2) == 0) {
2523 if (memcmp (data + 6, "JFIF", 4) == 0) {
2524 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JPEG_CAPS);
2525 } else if (memcmp (data + 6, "Exif", 4) == 0) {
2526 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JPEG_CAPS);
2528 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, JPEG_CAPS);
2535 static GstStaticCaps bmp_caps = GST_STATIC_CAPS ("image/bmp");
2537 #define BMP_CAPS (gst_static_caps_get(&bmp_caps))
2539 bmp_type_find (GstTypeFind * tf, gpointer unused)
2541 DataScanCtx c = { 0, NULL, 0 };
2542 guint32 struct_size, w, h, planes, bpp;
2544 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 54)))
2547 if (c.data[0] != 'B' || c.data[1] != 'M')
2550 /* skip marker + size */
2551 data_scan_ctx_advance (tf, &c, 2 + 4);
2553 /* reserved, must be 0 */
2554 if (c.data[0] != 0 || c.data[1] != 0 || c.data[2] != 0 || c.data[3] != 0)
2557 data_scan_ctx_advance (tf, &c, 2 + 2);
2559 /* offset to start of image data in bytes (check for sanity) */
2560 GST_LOG ("offset=%u", GST_READ_UINT32_LE (c.data));
2561 if (GST_READ_UINT32_LE (c.data) > (10 * 1024 * 1024))
2564 struct_size = GST_READ_UINT32_LE (c.data + 4);
2565 GST_LOG ("struct_size=%u", struct_size);
2567 data_scan_ctx_advance (tf, &c, 4 + 4);
2569 if (struct_size == 0x0C) {
2570 w = GST_READ_UINT16_LE (c.data);
2571 h = GST_READ_UINT16_LE (c.data + 2);
2572 planes = GST_READ_UINT16_LE (c.data + 2 + 2);
2573 bpp = GST_READ_UINT16_LE (c.data + 2 + 2 + 2);
2574 } else if (struct_size == 40 || struct_size == 64 || struct_size == 108
2575 || struct_size == 124 || struct_size == 0xF0) {
2576 w = GST_READ_UINT32_LE (c.data);
2577 h = GST_READ_UINT32_LE (c.data + 4);
2578 planes = GST_READ_UINT16_LE (c.data + 4 + 4);
2579 bpp = GST_READ_UINT16_LE (c.data + 4 + 4 + 2);
2584 /* image sizes sanity check */
2585 GST_LOG ("w=%u, h=%u, planes=%u, bpp=%u", w, h, planes, bpp);
2586 if (w == 0 || w > 0xfffff || h == 0 || h > 0xfffff || planes != 1 ||
2587 (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32))
2590 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "image/bmp",
2591 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, "bpp", G_TYPE_INT, bpp,
2595 /*** image/tiff ***/
2596 static GstStaticCaps tiff_caps = GST_STATIC_CAPS ("image/tiff, "
2597 "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }");
2598 #define TIFF_CAPS (gst_static_caps_get(&tiff_caps))
2599 static GstStaticCaps tiff_be_caps = GST_STATIC_CAPS ("image/tiff, "
2600 "endianness = (int) BIG_ENDIAN");
2601 #define TIFF_BE_CAPS (gst_static_caps_get(&tiff_be_caps))
2602 static GstStaticCaps tiff_le_caps = GST_STATIC_CAPS ("image/tiff, "
2603 "endianness = (int) LITTLE_ENDIAN");
2604 #define TIFF_LE_CAPS (gst_static_caps_get(&tiff_le_caps))
2606 tiff_type_find (GstTypeFind * tf, gpointer ununsed)
2608 guint8 *data = gst_type_find_peek (tf, 0, 8);
2609 guint8 le_header[4] = { 0x49, 0x49, 0x2A, 0x00 };
2610 guint8 be_header[4] = { 0x4D, 0x4D, 0x00, 0x2A };
2613 if (memcmp (data, le_header, 4) == 0) {
2614 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_LE_CAPS);
2615 } else if (memcmp (data, be_header, 4) == 0) {
2616 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_BE_CAPS);
2623 static GstStaticCaps pnm_caps = GST_STATIC_CAPS ("image/x-portable-bitmap; "
2624 "image/x-portable-graymap; image/x-portable-pixmap; "
2625 "image/x-portable-anymap");
2627 #define PNM_CAPS (gst_static_caps_get(&pnm_caps))
2629 #define IS_PNM_WHITESPACE(c) \
2630 ((c) == ' ' || (c) == '\r' || (c) == '\n' || (c) == 't')
2633 pnm_type_find (GstTypeFind * tf, gpointer ununsed)
2635 const gchar *media_type = NULL;
2636 DataScanCtx c = { 0, NULL, 0 };
2639 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
2642 /* see http://en.wikipedia.org/wiki/Netpbm_format */
2643 if (c.data[0] != 'P' || c.data[1] < '1' || c.data[1] > '7' ||
2644 !IS_PNM_WHITESPACE (c.data[2]) ||
2645 (c.data[3] != '#' && c.data[3] < '0' && c.data[3] > '9'))
2648 switch (c.data[1]) {
2650 media_type = "image/x-portable-bitmap"; /* ASCII */
2653 media_type = "image/x-portable-graymap"; /* ASCII */
2656 media_type = "image/x-portable-pixmap"; /* ASCII */
2659 media_type = "image/x-portable-bitmap"; /* Raw */
2662 media_type = "image/x-portable-graymap"; /* Raw */
2665 media_type = "image/x-portable-pixmap"; /* Raw */
2668 media_type = "image/x-portable-anymap";
2671 g_return_if_reached ();
2674 /* try to extract width and height as well */
2675 if (c.data[1] != '7') {
2676 gchar s[64] = { 0, }
2679 /* need to skip any comment lines first */
2680 data_scan_ctx_advance (tf, &c, 3);
2681 while (c.data[0] == '#') { /* we know there's still data left */
2682 data_scan_ctx_advance (tf, &c, 1);
2683 while (c.data[0] != '\n' && c.data[0] != '\r') {
2684 if (!data_scan_ctx_ensure_data (tf, &c, 4))
2686 data_scan_ctx_advance (tf, &c, 1);
2688 data_scan_ctx_advance (tf, &c, 1);
2689 GST_LOG ("skipped comment line in PNM header");
2692 if (!data_scan_ctx_ensure_data (tf, &c, 32) &&
2693 !data_scan_ctx_ensure_data (tf, &c, 4)) {
2697 /* need to NUL-terminate data for sscanf */
2698 memcpy (s, c.data, MIN (sizeof (s) - 1, c.size));
2699 if (sscanf (s, "%u%c%u%c", &w, &sep1, &h, &sep2) == 4 &&
2700 IS_PNM_WHITESPACE (sep1) && IS_PNM_WHITESPACE (sep2) &&
2701 w > 0 && w < G_MAXINT && h > 0 && h < G_MAXINT) {
2702 GST_LOG ("extracted PNM width and height: %dx%d", w, h);
2708 /* FIXME: extract width + height for anymaps too */
2711 if (w > 0 && h > 0) {
2712 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type,
2713 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, NULL);
2715 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, media_type, NULL);
2719 static GstStaticCaps sds_caps = GST_STATIC_CAPS ("audio/x-sds");
2721 #define SDS_CAPS (gst_static_caps_get(&sds_caps))
2723 sds_type_find (GstTypeFind * tf, gpointer ununsed)
2725 guint8 *data = gst_type_find_peek (tf, 0, 4);
2726 guint8 mask[4] = { 0xFF, 0xFF, 0x80, 0xFF };
2727 guint8 match[4] = { 0xF0, 0x7E, 0, 0x01 };
2731 for (x = 0; x < 4; x++) {
2732 if ((data[x] & mask[x]) != match[x]) {
2736 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDS_CAPS);
2740 static GstStaticCaps ircam_caps = GST_STATIC_CAPS ("audio/x-ircam");
2742 #define IRCAM_CAPS (gst_static_caps_get(&ircam_caps))
2744 ircam_type_find (GstTypeFind * tf, gpointer ununsed)
2746 guint8 *data = gst_type_find_peek (tf, 0, 4);
2747 guint8 mask[4] = { 0xFF, 0xFF, 0xF8, 0xFF };
2748 guint8 match[4] = { 0x64, 0xA3, 0x00, 0x00 };
2750 gboolean matched = TRUE;
2755 for (x = 0; x < 4; x++) {
2756 if ((data[x] & mask[x]) != match[x]) {
2761 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, IRCAM_CAPS);
2764 /* now try the reverse version */
2766 for (x = 0; x < 4; x++) {
2767 if ((data[x] & mask[3 - x]) != match[3 - x]) {
2774 /*** video/x-matroska ***/
2775 static GstStaticCaps matroska_caps = GST_STATIC_CAPS ("video/x-matroska");
2777 #define MATROSKA_CAPS (gst_static_caps_get(&matroska_caps))
2779 matroska_type_find (GstTypeFind * tf, gpointer ununsed)
2781 /* 4 bytes for EBML ID, 1 byte for header length identifier */
2782 guint8 *data = gst_type_find_peek (tf, 0, 4 + 1);
2783 gint len_mask = 0x80, size = 1, n = 1, total;
2784 guint8 probe_data[] = { 'm', 'a', 't', 'r', 'o', 's', 'k', 'a' };
2790 if (data[0] != 0x1A || data[1] != 0x45 || data[2] != 0xDF || data[3] != 0xA3)
2793 /* length of header */
2795 while (size <= 8 && !(total & len_mask)) {
2801 total &= (len_mask - 1);
2803 total = (total << 8) | data[4 + n++];
2805 /* get new data for full header, 4 bytes for EBML ID,
2806 * EBML length tag and the actual header */
2807 data = gst_type_find_peek (tf, 0, 4 + size + total);
2811 /* the header must contain the document type 'matroska'. For now,
2812 * we don't parse the whole header but simply check for the
2813 * availability of that array of characters inside the header.
2814 * Not fully fool-proof, but good enough. */
2815 for (n = 4 + size; n <= 4 + size + total - sizeof (probe_data); n++)
2816 if (!memcmp (&data[n], probe_data, sizeof (probe_data))) {
2817 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MATROSKA_CAPS);
2822 /*** application/mxf ***/
2823 static GstStaticCaps mxf_caps = GST_STATIC_CAPS ("application/mxf");
2825 #define MXF_MAX_PROBE_LENGTH (1024 * 64)
2826 #define MXF_CAPS (gst_static_caps_get(&mxf_caps))
2829 * MXF files start with a header partition pack key of 16 bytes which is defined
2830 * at SMPTE-377M 6.1. Before this there can be up to 64K of run-in which _must_
2831 * not contain the partition pack key.
2834 mxf_type_find (GstTypeFind * tf, gpointer ununsed)
2836 static const guint8 partition_pack_key[] =
2837 { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
2840 DataScanCtx c = { 0, NULL, 0 };
2842 while (c.offset <= MXF_MAX_PROBE_LENGTH) {
2844 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 1024)))
2847 /* look over in chunks of 1kbytes to avoid too much overhead */
2849 for (i = 0; i < 1024 - 16; i++) {
2850 /* Check first byte before calling more expensive memcmp function */
2851 if (G_UNLIKELY (c.data[i] == 0x06
2852 && memcmp (c.data + i, partition_pack_key, 13) == 0)) {
2853 /* Header partition pack? */
2854 if (c.data[i + 13] != 0x02)
2857 /* Partition status */
2858 if (c.data[i + 14] >= 0x05)
2861 /* Reserved, must be 0x00 */
2862 if (c.data[i + 15] != 0x00)
2865 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
2871 data_scan_ctx_advance (tf, &c, 1024 - 16);
2875 /*** video/x-dv ***/
2877 static GstStaticCaps dv_caps = GST_STATIC_CAPS ("video/x-dv, "
2878 "systemstream = (boolean) true");
2879 #define DV_CAPS (gst_static_caps_get(&dv_caps))
2881 dv_type_find (GstTypeFind * tf, gpointer private)
2885 data = gst_type_find_peek (tf, 0, 5);
2887 /* check for DIF and DV flag */
2888 if (data && (data[0] == 0x1f) && (data[1] == 0x07) && (data[2] == 0x00)) {
2889 const gchar *format;
2891 if (data[3] & 0x80) {
2897 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "video/x-dv",
2898 "systemstream", G_TYPE_BOOLEAN, TRUE,
2899 "format", G_TYPE_STRING, format, NULL);
2904 /*** application/ogg and application/x-annodex ***/
2905 static GstStaticCaps ogg_caps = GST_STATIC_CAPS ("application/ogg");
2906 static GstStaticCaps annodex_caps = GST_STATIC_CAPS ("application/x-annodex");
2907 static GstStaticCaps ogg_annodex_caps =
2908 GST_STATIC_CAPS ("application/ogg;application/x-annodex");
2910 #define OGGANX_CAPS (gst_static_caps_get(&ogg_annodex_caps))
2913 ogganx_type_find (GstTypeFind * tf, gpointer private)
2915 guint8 *data = gst_type_find_peek (tf, 0, 4);
2917 if ((data != NULL) && (memcmp (data, "OggS", 4) == 0)) {
2919 /* Check for an annodex fishbone header */
2920 data = gst_type_find_peek (tf, 28, 8);
2921 if (data && memcmp (data, "fishead\0", 8) == 0)
2922 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
2923 gst_static_caps_get (&annodex_caps));
2925 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
2926 gst_static_caps_get (&ogg_caps));
2930 /*** audio/x-vorbis ***/
2931 static GstStaticCaps vorbis_caps = GST_STATIC_CAPS ("audio/x-vorbis");
2933 #define VORBIS_CAPS (gst_static_caps_get(&vorbis_caps))
2935 vorbis_type_find (GstTypeFind * tf, gpointer private)
2937 guint8 *data = gst_type_find_peek (tf, 0, 30);
2943 /* 1 byte packet type (identification=0x01)
2944 6 byte string "vorbis"
2945 4 byte vorbis version */
2946 if (memcmp (data, "\001vorbis\000\000\000\000", 11) != 0)
2949 /* 1 byte channels must be != 0 */
2953 /* 4 byte samplerate must be != 0 */
2954 if (GST_READ_UINT32_LE (data) == 0)
2957 /* blocksize checks */
2958 blocksize_0 = data[0] & 0x0F;
2959 blocksize_1 = (data[0] & 0xF0) >> 4;
2960 if (blocksize_0 > blocksize_1)
2962 if (blocksize_0 < 6 || blocksize_0 > 13)
2964 if (blocksize_1 < 6 || blocksize_1 > 13)
2968 if ((data[0] & 0x01) != 1)
2970 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VORBIS_CAPS);
2974 /*** video/x-theora ***/
2976 static GstStaticCaps theora_caps = GST_STATIC_CAPS ("video/x-theora");
2978 #define THEORA_CAPS (gst_static_caps_get(&theora_caps))
2980 theora_type_find (GstTypeFind * tf, gpointer private)
2982 guint8 *data = gst_type_find_peek (tf, 0, 7); //42);
2985 if (data[0] != 0x80)
2987 if (memcmp (&data[1], "theora", 6) != 0)
2989 /* FIXME: make this more reliable when specs are out */
2991 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, THEORA_CAPS);
2997 kate_type_find (GstTypeFind * tf, gpointer private)
2999 guint8 *data = gst_type_find_peek (tf, 0, 64);
3000 gchar category[16] = { 0, };
3002 if (G_UNLIKELY (data == NULL))
3005 /* see: http://wiki.xiph.org/index.php/OggKate#Format_specification */
3006 if (G_LIKELY (memcmp (data, "\200kate\0\0\0", 8) != 0))
3009 /* make sure we always have a NUL-terminated string */
3010 memcpy (category, data + 48, 15);
3011 GST_LOG ("kate category: %s", category);
3012 /* canonical categories for subtitles: subtitles, spu-subtitles, SUB, K-SPU */
3013 if (strcmp (category, "subtitles") == 0 || strcmp (category, "SUB") == 0 ||
3014 strcmp (category, "spu-subtitles") == 0 ||
3015 strcmp (category, "K-SPU") == 0) {
3016 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3017 "subtitle/x-kate", NULL);
3019 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3020 "application/x-kate", NULL);
3024 /*** application/x-ogm-video or audio***/
3026 static GstStaticCaps ogmvideo_caps =
3027 GST_STATIC_CAPS ("application/x-ogm-video");
3028 #define OGMVIDEO_CAPS (gst_static_caps_get(&ogmvideo_caps))
3030 ogmvideo_type_find (GstTypeFind * tf, gpointer private)
3032 guint8 *data = gst_type_find_peek (tf, 0, 9);
3035 if (memcmp (data, "\001video\000\000\000", 9) != 0)
3037 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMVIDEO_CAPS);
3041 static GstStaticCaps ogmaudio_caps =
3042 GST_STATIC_CAPS ("application/x-ogm-audio");
3043 #define OGMAUDIO_CAPS (gst_static_caps_get(&ogmaudio_caps))
3045 ogmaudio_type_find (GstTypeFind * tf, gpointer private)
3047 guint8 *data = gst_type_find_peek (tf, 0, 9);
3050 if (memcmp (data, "\001audio\000\000\000", 9) != 0)
3052 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMAUDIO_CAPS);
3056 static GstStaticCaps ogmtext_caps = GST_STATIC_CAPS ("application/x-ogm-text");
3058 #define OGMTEXT_CAPS (gst_static_caps_get(&ogmtext_caps))
3060 ogmtext_type_find (GstTypeFind * tf, gpointer private)
3062 guint8 *data = gst_type_find_peek (tf, 0, 9);
3065 if (memcmp (data, "\001text\000\000\000\000", 9) != 0)
3067 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMTEXT_CAPS);
3071 /*** audio/x-speex ***/
3073 static GstStaticCaps speex_caps = GST_STATIC_CAPS ("audio/x-speex");
3075 #define SPEEX_CAPS (gst_static_caps_get(&speex_caps))
3077 speex_type_find (GstTypeFind * tf, gpointer private)
3079 guint8 *data = gst_type_find_peek (tf, 0, 80);
3082 /* 8 byte string "Speex "
3083 24 byte speex version string + int */
3084 if (memcmp (data, "Speex ", 8) != 0)
3088 /* 4 byte header size >= 80 */
3089 if (GST_READ_UINT32_LE (data) < 80)
3093 /* 4 byte sample rate <= 48000 */
3094 if (GST_READ_UINT32_LE (data) > 48000)
3098 /* currently there are only 3 speex modes. */
3099 if (GST_READ_UINT32_LE (data) > 3)
3103 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SPEEX_CAPS);
3107 /*** audio/x-celt ***/
3109 static GstStaticCaps celt_caps = GST_STATIC_CAPS ("audio/x-celt");
3111 #define CELT_CAPS (gst_static_caps_get(&celt_caps))
3113 celt_type_find (GstTypeFind * tf, gpointer private)
3115 guint8 *data = gst_type_find_peek (tf, 0, 8);
3118 /* 8 byte string "CELT " */
3119 if (memcmp (data, "CELT ", 8) != 0)
3122 /* TODO: Check other values of the CELT header */
3123 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CELT_CAPS);
3127 /*** application/x-ogg-skeleton ***/
3128 static GstStaticCaps ogg_skeleton_caps =
3129 GST_STATIC_CAPS ("application/x-ogg-skeleton, parsed=(boolean)FALSE");
3130 #define OGG_SKELETON_CAPS (gst_static_caps_get(&ogg_skeleton_caps))
3132 oggskel_type_find (GstTypeFind * tf, gpointer private)
3134 guint8 *data = gst_type_find_peek (tf, 0, 12);
3137 /* 8 byte string "fishead\0" for the ogg skeleton stream */
3138 if (memcmp (data, "fishead\0", 8) != 0)
3142 /* Require that the header contains version 3.0 */
3143 if (GST_READ_UINT16_LE (data) != 3)
3146 if (GST_READ_UINT16_LE (data) != 0)
3149 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGG_SKELETON_CAPS);
3153 static GstStaticCaps cmml_caps = GST_STATIC_CAPS ("text/x-cmml");
3155 #define CMML_CAPS (gst_static_caps_get(&cmml_caps))
3157 cmml_type_find (GstTypeFind * tf, gpointer private)
3159 /* Header is 12 bytes minimum (though we don't check the minor version */
3160 guint8 *data = gst_type_find_peek (tf, 0, 12);
3164 /* 8 byte string "CMML\0\0\0\0" for the magic number */
3165 if (memcmp (data, "CMML\0\0\0\0", 8) != 0)
3169 /* Require that the header contains at least version 2.0 */
3170 if (GST_READ_UINT16_LE (data) < 2)
3173 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CMML_CAPS);
3177 /*** application/x-tar ***/
3179 static GstStaticCaps tar_caps = GST_STATIC_CAPS ("application/x-tar");
3181 #define TAR_CAPS (gst_static_caps_get(&tar_caps))
3182 #define OLDGNU_MAGIC "ustar " /* 7 chars and a NUL */
3183 #define NEWGNU_MAGIC "ustar" /* 5 chars and a NUL */
3185 tar_type_find (GstTypeFind * tf, gpointer unused)
3187 guint8 *data = gst_type_find_peek (tf, 257, 8);
3189 /* of course we are not certain, but we don't want other typefind funcs
3190 * to detect formats of files within the tar archive, e.g. mp3s */
3192 if (memcmp (data, OLDGNU_MAGIC, 8) == 0) { /* sic */
3193 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3194 } else if (memcmp (data, NEWGNU_MAGIC, 6) == 0 && /* sic */
3195 g_ascii_isdigit (data[6]) && g_ascii_isdigit (data[7])) {
3196 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3201 /*** application/x-ar ***/
3203 static GstStaticCaps ar_caps = GST_STATIC_CAPS ("application/x-ar");
3205 #define AR_CAPS (gst_static_caps_get(&ar_caps))
3207 ar_type_find (GstTypeFind * tf, gpointer unused)
3209 guint8 *data = gst_type_find_peek (tf, 0, 24);
3211 if (data && memcmp (data, "!<arch>", 7) == 0) {
3214 for (i = 7; i < 24; ++i) {
3215 if (!g_ascii_isprint (data[i]) && data[i] != '\n') {
3216 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AR_CAPS);
3220 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AR_CAPS);
3224 /*** audio/x-au ***/
3226 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3227 * as it is only possible to register one typefind factory per 'name'
3228 * (which is in this case the caps), and the first one would be replaced by
3229 * the second one. */
3230 static GstStaticCaps au_caps = GST_STATIC_CAPS ("audio/x-au");
3232 #define AU_CAPS (gst_static_caps_get(&au_caps))
3234 au_type_find (GstTypeFind * tf, gpointer unused)
3236 guint8 *data = gst_type_find_peek (tf, 0, 4);
3239 if (memcmp (data, ".snd", 4) == 0 || memcmp (data, "dns.", 4) == 0) {
3240 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AU_CAPS);
3246 /*** video/x-nuv ***/
3248 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3249 * as it is only possible to register one typefind factory per 'name'
3250 * (which is in this case the caps), and the first one would be replaced by
3251 * the second one. */
3252 static GstStaticCaps nuv_caps = GST_STATIC_CAPS ("video/x-nuv");
3254 #define NUV_CAPS (gst_static_caps_get(&nuv_caps))
3256 nuv_type_find (GstTypeFind * tf, gpointer unused)
3258 guint8 *data = gst_type_find_peek (tf, 0, 11);
3261 if (memcmp (data, "MythTVVideo", 11) == 0
3262 || memcmp (data, "NuppelVideo", 11) == 0) {
3263 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, NUV_CAPS);
3268 /*** audio/x-paris ***/
3269 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3270 static GstStaticCaps paris_caps = GST_STATIC_CAPS ("audio/x-paris");
3272 #define PARIS_CAPS (gst_static_caps_get(&paris_caps))
3274 paris_type_find (GstTypeFind * tf, gpointer unused)
3276 guint8 *data = gst_type_find_peek (tf, 0, 4);
3279 if (memcmp (data, " paf", 4) == 0 || memcmp (data, "fap ", 4) == 0) {
3280 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, PARIS_CAPS);
3285 /*** audio/iLBC-sh ***/
3286 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3287 static GstStaticCaps ilbc_caps = GST_STATIC_CAPS ("audio/iLBC-sh");
3289 #define ILBC_CAPS (gst_static_caps_get(&ilbc_caps))
3291 ilbc_type_find (GstTypeFind * tf, gpointer unused)
3293 guint8 *data = gst_type_find_peek (tf, 0, 8);
3296 if (memcmp (data, "#!iLBC30", 8) == 0 || memcmp (data, "#!iLBC20", 8) == 0) {
3297 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, ILBC_CAPS);
3302 /*** application/x-ms-dos-executable ***/
3304 static GstStaticCaps msdos_caps =
3305 GST_STATIC_CAPS ("application/x-ms-dos-executable");
3306 #define MSDOS_CAPS (gst_static_caps_get(&msdos_caps))
3307 /* see http://www.madchat.org/vxdevl/papers/winsys/pefile/pefile.htm */
3309 msdos_type_find (GstTypeFind * tf, gpointer unused)
3311 guint8 *data = gst_type_find_peek (tf, 0, 64);
3313 if (data && data[0] == 'M' && data[1] == 'Z' &&
3314 GST_READ_UINT16_LE (data + 8) == 4) {
3315 guint32 pe_offset = GST_READ_UINT32_LE (data + 60);
3317 data = gst_type_find_peek (tf, pe_offset, 2);
3318 if (data && data[0] == 'P' && data[1] == 'E') {
3319 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, MSDOS_CAPS);
3324 /*** application/x-mmsh ***/
3326 static GstStaticCaps mmsh_caps = GST_STATIC_CAPS ("application/x-mmsh");
3328 #define MMSH_CAPS gst_static_caps_get(&mmsh_caps)
3330 /* This is to recognise mssh-over-http */
3332 mmsh_type_find (GstTypeFind * tf, gpointer unused)
3334 static const guint8 asf_marker[16] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66,
3335 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
3340 data = gst_type_find_peek (tf, 0, 2 + 2 + 4 + 2 + 2 + 16);
3341 if (data && data[0] == 0x24 && data[1] == 0x48 &&
3342 GST_READ_UINT16_LE (data + 2) > 2 + 2 + 4 + 2 + 2 + 16 &&
3343 memcmp (data + 2 + 2 + 4 + 2 + 2, asf_marker, 16) == 0) {
3344 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MMSH_CAPS);
3348 /*** video/x-dirac ***/
3350 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3351 * as it is only possible to register one typefind factory per 'name'
3352 * (which is in this case the caps), and the first one would be replaced by
3353 * the second one. */
3354 static GstStaticCaps dirac_caps = GST_STATIC_CAPS ("video/x-dirac");
3356 #define DIRAC_CAPS (gst_static_caps_get(&dirac_caps))
3358 dirac_type_find (GstTypeFind * tf, gpointer unused)
3360 guint8 *data = gst_type_find_peek (tf, 0, 8);
3363 if (memcmp (data, "BBCD", 4) == 0 || memcmp (data, "KW-DIRAC", 8) == 0) {
3364 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DIRAC_CAPS);
3369 /*** video/vivo ***/
3371 static GstStaticCaps vivo_caps = GST_STATIC_CAPS ("video/vivo");
3373 #define VIVO_CAPS gst_static_caps_get(&vivo_caps)
3376 vivo_type_find (GstTypeFind * tf, gpointer unused)
3378 static const guint8 vivo_marker[] = { 'V', 'e', 'r', 's', 'i', 'o', 'n',
3379 ':', 'V', 'i', 'v', 'o', '/'
3384 data = gst_type_find_peek (tf, 0, 1024);
3385 if (data == NULL || data[0] != 0x00)
3388 if ((data[1] & 0x80)) {
3389 if ((data[2] & 0x80))
3391 hdr_len = ((guint) (data[1] & 0x7f)) << 7;
3401 /* 1008 = 1022 - strlen ("Version:Vivo/") - 1 */
3402 while (pos < 1008 && data[pos] == '\r' && data[pos + 1] == '\n')
3405 if (memcmp (data + pos, vivo_marker, sizeof (vivo_marker)) == 0) {
3406 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VIVO_CAPS);
3410 /*** XDG MIME typefinder (to avoid false positives mostly) ***/
3414 xdgmime_typefind (GstTypeFind * find, gpointer user_data)
3417 gsize length = 16384;
3422 if ((tf_length = gst_type_find_get_length (find)) > 0)
3423 length = MIN (length, tf_length);
3425 if ((data = gst_type_find_peek (find, 0, length)) == NULL)
3428 tmp = g_content_type_guess (NULL, data, length, NULL);
3429 if (tmp == NULL || g_content_type_is_unknown (tmp)) {
3434 mimetype = g_content_type_get_mime_type (tmp);
3437 if (mimetype == NULL)
3440 GST_DEBUG ("Got mimetype '%s'", mimetype);
3442 /* Ignore audio/video types:
3443 * - our own typefinders in -base are likely to be better at this
3444 * (and if they're not, we really want to fix them, that's why we don't
3445 * report xdg-detected audio/video types at all, not even with a low
3447 * - we want to detect GStreamer media types and not MIME types
3448 * - the purpose of this xdg mime finder is mainly to prevent false
3449 * positives of non-media formats, not to typefind audio/video formats */
3450 if (g_str_has_prefix (mimetype, "audio/") ||
3451 g_str_has_prefix (mimetype, "video/")) {
3452 GST_LOG ("Ignoring audio/video mime type");
3457 /* Again, we mainly want the xdg typefinding to prevent false-positives on
3458 * non-media formats, so suggest the type with a probability that trumps
3459 * uncertain results of our typefinders, but not more than that. */
3460 GST_LOG ("Suggesting '%s' with probability POSSIBLE", mimetype);
3461 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE, mimetype, NULL);
3464 #endif /* USE_GIO */
3466 /*** generic typefind for streams that have some data at a specific position***/
3477 start_with_type_find (GstTypeFind * tf, gpointer private)
3479 GstTypeFindData *start_with = (GstTypeFindData *) private;
3482 GST_LOG ("trying to find mime type %s with the first %u bytes of data",
3483 gst_structure_get_name (gst_caps_get_structure (start_with->caps, 0)),
3485 data = gst_type_find_peek (tf, 0, start_with->size);
3486 if (data && memcmp (data, start_with->data, start_with->size) == 0) {
3487 gst_type_find_suggest (tf, start_with->probability, start_with->caps);
3492 sw_data_destroy (GstTypeFindData * sw_data)
3494 if (G_LIKELY (sw_data->caps != NULL))
3495 gst_caps_unref (sw_data->caps);
3499 #define TYPE_FIND_REGISTER_START_WITH(plugin,name,rank,ext,_data,_size,_probability)\
3501 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
3502 sw_data->data = (const guint8 *)_data; \
3503 sw_data->size = _size; \
3504 sw_data->probability = _probability; \
3505 sw_data->caps = gst_caps_new_simple (name, NULL); \
3506 if (!gst_type_find_register (plugin, name, rank, start_with_type_find,\
3507 (char **) ext, sw_data->caps, sw_data, \
3508 (GDestroyNotify) (sw_data_destroy))) { \
3509 gst_caps_unref (sw_data->caps); \
3514 /*** same for riff types ***/
3517 riff_type_find (GstTypeFind * tf, gpointer private)
3519 GstTypeFindData *riff_data = (GstTypeFindData *) private;
3520 guint8 *data = gst_type_find_peek (tf, 0, 12);
3522 if (data && (memcmp (data, "RIFF", 4) == 0 || memcmp (data, "AVF0", 4) == 0)) {
3524 if (memcmp (data, riff_data->data, 4) == 0)
3525 gst_type_find_suggest (tf, riff_data->probability, riff_data->caps);
3529 #define TYPE_FIND_REGISTER_RIFF(plugin,name,rank,ext,_data) \
3531 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
3532 sw_data->data = (gpointer)_data; \
3533 sw_data->size = 4; \
3534 sw_data->probability = GST_TYPE_FIND_MAXIMUM; \
3535 sw_data->caps = gst_caps_new_simple (name, NULL); \
3536 if (!gst_type_find_register (plugin, name, rank, riff_type_find, \
3537 (char **) ext, sw_data->caps, sw_data, \
3538 (GDestroyNotify) (sw_data_destroy))) { \
3539 gst_caps_unref (sw_data->caps); \
3545 /*** plugin initialization ***/
3547 #define TYPE_FIND_REGISTER(plugin,name,rank,func,ext,caps,priv,notify) \
3549 if (!gst_type_find_register (plugin, name, rank, func, (char **) ext, caps, priv, notify))\
3555 plugin_init (GstPlugin * plugin)
3557 /* can't initialize this via a struct as caps can't be statically initialized */
3559 /* note: asx/wax/wmx are XML files, asf doesn't handle them */
3560 /* FIXME-0.11: these should be const,
3561 this requires gstreamer/gst/gsttypefind::gst_type_find_register()
3562 to have define the parameter as const
3564 static const gchar *asf_exts[] = { "asf", "wm", "wma", "wmv", NULL };
3565 static const gchar *au_exts[] = { "au", "snd", NULL };
3566 static const gchar *avi_exts[] = { "avi", NULL };
3567 static const gchar *qcp_exts[] = { "qcp", NULL };
3568 static const gchar *cdxa_exts[] = { "dat", NULL };
3569 static const gchar *flac_exts[] = { "flac", NULL };
3570 static const gchar *flx_exts[] = { "flc", "fli", NULL };
3571 static const gchar *id3_exts[] =
3572 { "mp3", "mp2", "mp1", "mpga", "ogg", "flac", "tta", NULL };
3573 static const gchar *apetag_exts[] = { "ape", "mpc", "wv", NULL }; /* and mp3 and wav? */
3574 static const gchar *tta_exts[] = { "tta", NULL };
3575 static const gchar *mod_exts[] = { "669", "amf", "dsm", "gdm", "far", "imf",
3576 "it", "med", "mod", "mtm", "okt", "sam",
3577 "s3m", "stm", "stx", "ult", "xm", NULL
3579 static const gchar *mp3_exts[] = { "mp3", "mp2", "mp1", "mpga", NULL };
3580 static const gchar *ac3_exts[] = { "ac3", NULL };
3581 static const gchar *gsm_exts[] = { "gsm", NULL };
3582 static const gchar *musepack_exts[] = { "mpc", "mpp", "mp+", NULL };
3583 static const gchar *mpeg_sys_exts[] = { "mpe", "mpeg", "mpg", NULL };
3584 static const gchar *mpeg_video_exts[] = { "mpv", "mpeg", "mpg", NULL };
3585 static const gchar *mpeg_ts_exts[] = { "ts", NULL };
3586 static const gchar *ogg_exts[] = { "anx", "ogg", "ogm", NULL };
3587 static const gchar *qt_exts[] = { "mov", NULL };
3588 static const gchar *qtif_exts[] = { "qif", "qtif", "qti", NULL };
3589 static const gchar *mj2_exts[] = { "mj2", NULL };
3590 static const gchar *jp2_exts[] = { "jp2", NULL };
3591 static const gchar *rm_exts[] = { "ra", "ram", "rm", "rmvb", NULL };
3592 static const gchar *swf_exts[] = { "swf", "swfl", NULL };
3593 static const gchar *utf8_exts[] = { "txt", NULL };
3594 static const gchar *wav_exts[] = { "wav", NULL };
3595 static const gchar *aiff_exts[] = { "aiff", "aif", "aifc", NULL };
3596 static const gchar *svx_exts[] = { "iff", "svx", NULL };
3597 static const gchar *paris_exts[] = { "paf", NULL };
3598 static const gchar *nist_exts[] = { "nist", NULL };
3599 static const gchar *voc_exts[] = { "voc", NULL };
3600 static const gchar *sds_exts[] = { "sds", NULL };
3601 static const gchar *ircam_exts[] = { "sf", NULL };
3602 static const gchar *w64_exts[] = { "w64", NULL };
3603 static const gchar *shn_exts[] = { "shn", NULL };
3604 static const gchar *ape_exts[] = { "ape", NULL };
3605 static const gchar *uri_exts[] = { "ram", NULL };
3606 static const gchar *sdp_exts[] = { "sdp", NULL };
3607 static const gchar *smil_exts[] = { "smil", NULL };
3608 static const gchar *html_exts[] = { "htm", "html", NULL };
3609 static const gchar *xml_exts[] = { "xml", NULL };
3610 static const gchar *jpeg_exts[] = { "jpg", "jpe", "jpeg", NULL };
3611 static const gchar *gif_exts[] = { "gif", NULL };
3612 static const gchar *png_exts[] = { "png", NULL };
3613 static const gchar *bmp_exts[] = { "bmp", NULL };
3614 static const gchar *tiff_exts[] = { "tif", "tiff", NULL };
3615 static const gchar *matroska_exts[] = { "mkv", "mka", NULL };
3616 static const gchar *mve_exts[] = { "mve", NULL };
3617 static const gchar *dv_exts[] = { "dv", "dif", NULL };
3618 static const gchar *amr_exts[] = { "amr", NULL };
3619 static const gchar *ilbc_exts[] = { "ilbc", NULL };
3620 static const gchar *sid_exts[] = { "sid", NULL };
3621 static const gchar *xcf_exts[] = { "xcf", NULL };
3622 static const gchar *mng_exts[] = { "mng", NULL };
3623 static const gchar *jng_exts[] = { "jng", NULL };
3624 static const gchar *xpm_exts[] = { "xpm", NULL };
3625 static const gchar *pnm_exts[] = { "pnm", "ppm", "pgm", "pbm", NULL };
3626 static const gchar *ras_exts[] = { "ras", NULL };
3627 static const gchar *bz2_exts[] = { "bz2", NULL };
3628 static const gchar *gz_exts[] = { "gz", NULL };
3629 static const gchar *zip_exts[] = { "zip", NULL };
3630 static const gchar *compress_exts[] = { "Z", NULL };
3631 static const gchar *m4a_exts[] = { "m4a", NULL };
3632 static const gchar *q3gp_exts[] = { "3gp", NULL };
3633 static const gchar *aac_exts[] = { "aac", NULL };
3634 static const gchar *spc_exts[] = { "spc", NULL };
3635 static const gchar *wavpack_exts[] = { "wv", "wvp", NULL };
3636 static const gchar *wavpack_correction_exts[] = { "wvc", NULL };
3637 static const gchar *rar_exts[] = { "rar", NULL };
3638 static const gchar *tar_exts[] = { "tar", NULL };
3639 static const gchar *ar_exts[] = { "a", NULL };
3640 static const gchar *msdos_exts[] = { "dll", "exe", "ocx", "sys", "scr",
3641 "msstyles", "cpl", NULL
3643 static const gchar *flv_exts[] = { "flv", NULL };
3644 static const gchar *m4v_exts[] = { "m4v", NULL };
3645 static const gchar *h264_exts[] = { "h264", "x264", "264", NULL };
3646 static const gchar *nuv_exts[] = { "nuv", NULL };
3647 static const gchar *vivo_exts[] = { "viv", NULL };
3648 static const gchar *nsf_exts[] = { "nsf", NULL };
3649 static const gchar *gym_exts[] = { "gym", NULL };
3650 static const gchar *ay_exts[] = { "ay", NULL };
3651 static const gchar *gbs_exts[] = { "gbs", NULL };
3652 static const gchar *kss_exts[] = { "kss", NULL };
3653 static const gchar *sap_exts[] = { "sap", NULL };
3654 static const gchar *vgm_exts[] = { "vgm", NULL };
3655 static const gchar *mid_exts[] = { "mid", "midi", NULL };
3656 static const gchar *mxmf_exts[] = { "mxmf", NULL };
3657 static const gchar *imelody_exts[] = { "imy", "ime", "imelody", NULL };
3658 static const gchar *pdf_exts[] = { "pdf", NULL };
3659 static const gchar *ps_exts[] = { "ps", NULL };
3660 static const gchar *svg_exts[] = { "svg", NULL };
3661 static const gchar *mxf_exts[] = { "mxf", NULL };
3662 static const gchar *msword_exts[] = { "doc", NULL };
3663 static const gchar *dsstore_exts[] = { "DS_Store", NULL };
3664 static const gchar *psd_exts[] = { "psd", NULL };
3666 GST_DEBUG_CATEGORY_INIT (type_find_debug, "typefindfunctions",
3667 GST_DEBUG_FG_GREEN | GST_DEBUG_BG_RED, "generic type find functions");
3669 /* must use strings, macros don't accept initializers */
3670 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ms-asf", GST_RANK_SECONDARY,
3672 "\060\046\262\165\216\146\317\021\246\331\000\252\000\142\316\154", 16,
3673 GST_TYPE_FIND_MAXIMUM);
3674 TYPE_FIND_REGISTER (plugin, "audio/x-musepack", GST_RANK_PRIMARY,
3675 musepack_type_find, musepack_exts, MUSEPACK_CAPS, NULL, NULL);
3676 TYPE_FIND_REGISTER (plugin, "audio/x-au", GST_RANK_MARGINAL,
3677 au_type_find, au_exts, AU_CAPS, NULL, NULL);
3678 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-msvideo", GST_RANK_PRIMARY,
3680 TYPE_FIND_REGISTER_RIFF (plugin, "audio/qcelp", GST_RANK_PRIMARY,
3682 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-cdxa", GST_RANK_PRIMARY,
3684 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-vcd", GST_RANK_PRIMARY,
3685 cdxa_exts, "\000\377\377\377\377\377\377\377\377\377\377\000", 12,
3686 GST_TYPE_FIND_MAXIMUM);
3687 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-imelody", GST_RANK_PRIMARY,
3688 imelody_exts, "BEGIN:IMELODY", 13, GST_TYPE_FIND_MAXIMUM);
3690 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-smoke", GST_RANK_PRIMARY,
3691 NULL, "\x80smoke\x00\x01\x00", 6, GST_TYPE_FIND_MAXIMUM);
3693 TYPE_FIND_REGISTER (plugin, "audio/midi", GST_RANK_PRIMARY, mid_type_find,
3694 mid_exts, MID_CAPS, NULL, NULL);
3695 TYPE_FIND_REGISTER_RIFF (plugin, "audio/riff-midi", GST_RANK_PRIMARY,
3697 TYPE_FIND_REGISTER (plugin, "audio/mobile-xmf", GST_RANK_PRIMARY,
3698 mxmf_type_find, mxmf_exts, MXMF_CAPS, NULL, NULL);
3699 TYPE_FIND_REGISTER (plugin, "video/x-fli", GST_RANK_MARGINAL, flx_type_find,
3700 flx_exts, FLX_CAPS, NULL, NULL);
3701 TYPE_FIND_REGISTER (plugin, "application/x-id3v2", GST_RANK_PRIMARY + 103,
3702 id3v2_type_find, id3_exts, ID3_CAPS, NULL, NULL);
3703 TYPE_FIND_REGISTER (plugin, "application/x-id3v1", GST_RANK_PRIMARY + 101,
3704 id3v1_type_find, id3_exts, ID3_CAPS, NULL, NULL);
3705 TYPE_FIND_REGISTER (plugin, "application/x-apetag", GST_RANK_PRIMARY + 102,
3706 apetag_type_find, apetag_exts, APETAG_CAPS, NULL, NULL);
3707 TYPE_FIND_REGISTER (plugin, "audio/x-ttafile", GST_RANK_PRIMARY,
3708 tta_type_find, tta_exts, TTA_CAPS, NULL, NULL);
3709 TYPE_FIND_REGISTER (plugin, "audio/x-mod", GST_RANK_SECONDARY, mod_type_find,
3710 mod_exts, MOD_CAPS, NULL, NULL);
3711 TYPE_FIND_REGISTER (plugin, "audio/mpeg", GST_RANK_PRIMARY, mp3_type_find,
3712 mp3_exts, MP3_CAPS, NULL, NULL);
3713 TYPE_FIND_REGISTER (plugin, "audio/x-ac3", GST_RANK_PRIMARY, ac3_type_find,
3714 ac3_exts, AC3_CAPS, NULL, NULL);
3715 TYPE_FIND_REGISTER (plugin, "audio/x-gsm", GST_RANK_PRIMARY, NULL, gsm_exts,
3716 GSM_CAPS, NULL, NULL);
3717 TYPE_FIND_REGISTER (plugin, "video/mpeg-sys", GST_RANK_PRIMARY,
3718 mpeg_sys_type_find, mpeg_sys_exts, MPEG_SYS_CAPS, NULL, NULL);
3719 TYPE_FIND_REGISTER (plugin, "video/mpegts", GST_RANK_PRIMARY,
3720 mpeg_ts_type_find, mpeg_ts_exts, MPEGTS_CAPS, NULL, NULL);
3721 TYPE_FIND_REGISTER (plugin, "application/ogg", GST_RANK_PRIMARY,
3722 ogganx_type_find, ogg_exts, OGGANX_CAPS, NULL, NULL);
3723 TYPE_FIND_REGISTER (plugin, "video/mpeg-elementary", GST_RANK_MARGINAL,
3724 mpeg_video_stream_type_find, mpeg_video_exts, MPEG_VIDEO_CAPS, NULL,
3726 TYPE_FIND_REGISTER (plugin, "video/mpeg4", GST_RANK_PRIMARY,
3727 mpeg4_video_type_find, m4v_exts, MPEG_VIDEO_CAPS, NULL, NULL);
3728 TYPE_FIND_REGISTER (plugin, "video/x-h264", GST_RANK_PRIMARY,
3729 h264_video_type_find, h264_exts, MPEG_VIDEO_CAPS, NULL, NULL);
3730 TYPE_FIND_REGISTER (plugin, "video/x-nuv", GST_RANK_SECONDARY, nuv_type_find,
3731 nuv_exts, NUV_CAPS, NULL, NULL);
3734 TYPE_FIND_REGISTER (plugin, "audio/x-m4a", GST_RANK_PRIMARY, m4a_type_find,
3735 m4a_exts, M4A_CAPS, NULL, NULL);
3736 TYPE_FIND_REGISTER (plugin, "application/x-3gp", GST_RANK_PRIMARY,
3737 q3gp_type_find, q3gp_exts, Q3GP_CAPS, NULL, NULL);
3738 TYPE_FIND_REGISTER (plugin, "video/quicktime", GST_RANK_SECONDARY,
3739 qt_type_find, qt_exts, QT_CAPS, NULL, NULL);
3740 TYPE_FIND_REGISTER (plugin, "image/x-quicktime", GST_RANK_SECONDARY,
3741 qtif_type_find, qtif_exts, QTIF_CAPS, NULL, NULL);
3742 TYPE_FIND_REGISTER (plugin, "image/jp2", GST_RANK_PRIMARY,
3743 jp2_type_find, jp2_exts, JP2_CAPS, NULL, NULL);
3744 TYPE_FIND_REGISTER (plugin, "video/mj2", GST_RANK_PRIMARY,
3745 jp2_type_find, mj2_exts, MJ2_CAPS, NULL, NULL);
3747 TYPE_FIND_REGISTER (plugin, "text/html", GST_RANK_SECONDARY, html_type_find,
3748 html_exts, HTML_CAPS, NULL, NULL);
3749 TYPE_FIND_REGISTER_START_WITH (plugin, "application/vnd.rn-realmedia",
3750 GST_RANK_SECONDARY, rm_exts, ".RMF", 4, GST_TYPE_FIND_MAXIMUM);
3751 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-pn-realaudio",
3752 GST_RANK_SECONDARY, rm_exts, ".ra\375", 4, GST_TYPE_FIND_MAXIMUM);
3753 TYPE_FIND_REGISTER (plugin, "application/x-shockwave-flash",
3754 GST_RANK_SECONDARY, swf_type_find, swf_exts, SWF_CAPS, NULL, NULL);
3755 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-flv", GST_RANK_SECONDARY,
3756 flv_exts, "FLV", 3, GST_TYPE_FIND_MAXIMUM);
3757 TYPE_FIND_REGISTER (plugin, "text/plain", GST_RANK_MARGINAL, utf8_type_find,
3758 utf8_exts, UTF8_CAPS, NULL, NULL);
3759 TYPE_FIND_REGISTER (plugin, "text/uri-list", GST_RANK_MARGINAL, uri_type_find,
3760 uri_exts, URI_CAPS, NULL, NULL);
3761 TYPE_FIND_REGISTER (plugin, "application/sdp", GST_RANK_SECONDARY,
3762 sdp_type_find, sdp_exts, SDP_CAPS, NULL, NULL);
3763 TYPE_FIND_REGISTER (plugin, "application/smil", GST_RANK_SECONDARY,
3764 smil_type_find, smil_exts, SMIL_CAPS, NULL, NULL);
3765 TYPE_FIND_REGISTER (plugin, "application/xml", GST_RANK_MARGINAL,
3766 xml_type_find, xml_exts, GENERIC_XML_CAPS, NULL, NULL);
3767 TYPE_FIND_REGISTER_RIFF (plugin, "audio/x-wav", GST_RANK_PRIMARY, wav_exts,
3769 TYPE_FIND_REGISTER (plugin, "audio/x-aiff", GST_RANK_SECONDARY,
3770 aiff_type_find, aiff_exts, AIFF_CAPS, NULL, NULL);
3771 TYPE_FIND_REGISTER (plugin, "audio/x-svx", GST_RANK_SECONDARY, svx_type_find,
3772 svx_exts, SVX_CAPS, NULL, NULL);
3773 TYPE_FIND_REGISTER (plugin, "audio/x-paris", GST_RANK_SECONDARY,
3774 paris_type_find, paris_exts, PARIS_CAPS, NULL, NULL);
3775 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nist", GST_RANK_SECONDARY,
3776 nist_exts, "NIST", 4, GST_TYPE_FIND_MAXIMUM);
3777 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-voc", GST_RANK_SECONDARY,
3778 voc_exts, "Creative", 8, GST_TYPE_FIND_MAXIMUM);
3779 TYPE_FIND_REGISTER (plugin, "audio/x-sds", GST_RANK_SECONDARY, sds_type_find,
3780 sds_exts, SDS_CAPS, NULL, NULL);
3781 TYPE_FIND_REGISTER (plugin, "audio/x-ircam", GST_RANK_SECONDARY,
3782 ircam_type_find, ircam_exts, IRCAM_CAPS, NULL, NULL);
3783 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-w64", GST_RANK_SECONDARY,
3784 w64_exts, "riff", 4, GST_TYPE_FIND_MAXIMUM);
3785 TYPE_FIND_REGISTER (plugin, "audio/x-shorten", GST_RANK_SECONDARY,
3786 shn_type_find, shn_exts, SHN_CAPS, NULL, NULL);
3787 TYPE_FIND_REGISTER (plugin, "application/x-ape", GST_RANK_SECONDARY,
3788 ape_type_find, ape_exts, APE_CAPS, NULL, NULL);
3789 TYPE_FIND_REGISTER (plugin, "image/jpeg", GST_RANK_PRIMARY + 15,
3790 jpeg_type_find, jpeg_exts, JPEG_CAPS, NULL, NULL);
3791 TYPE_FIND_REGISTER_START_WITH (plugin, "image/gif", GST_RANK_PRIMARY,
3792 gif_exts, "GIF8", 4, GST_TYPE_FIND_MAXIMUM);
3793 TYPE_FIND_REGISTER_START_WITH (plugin, "image/png", GST_RANK_PRIMARY + 14,
3794 png_exts, "\211PNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
3795 TYPE_FIND_REGISTER (plugin, "image/bmp", GST_RANK_PRIMARY, bmp_type_find,
3796 bmp_exts, BMP_CAPS, NULL, NULL);
3797 TYPE_FIND_REGISTER (plugin, "image/tiff", GST_RANK_PRIMARY, tiff_type_find,
3798 tiff_exts, TIFF_CAPS, NULL, NULL);
3799 TYPE_FIND_REGISTER (plugin, "image/x-portable-pixmap", GST_RANK_SECONDARY,
3800 pnm_type_find, pnm_exts, PNM_CAPS, NULL, NULL);
3801 TYPE_FIND_REGISTER (plugin, "video/x-matroska", GST_RANK_PRIMARY,
3802 matroska_type_find, matroska_exts, MATROSKA_CAPS, NULL, NULL);
3803 TYPE_FIND_REGISTER (plugin, "application/mxf", GST_RANK_PRIMARY,
3804 mxf_type_find, mxf_exts, MXF_CAPS, NULL, NULL);
3805 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mve", GST_RANK_SECONDARY,
3806 mve_exts, "Interplay MVE File\032\000\032\000\000\001\063\021", 26,
3807 GST_TYPE_FIND_MAXIMUM);
3808 TYPE_FIND_REGISTER (plugin, "video/x-dv", GST_RANK_SECONDARY, dv_type_find,
3809 dv_exts, DV_CAPS, NULL, NULL);
3810 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-nb-sh", GST_RANK_PRIMARY,
3811 amr_exts, "#!AMR", 5, GST_TYPE_FIND_LIKELY);
3812 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-wb-sh", GST_RANK_PRIMARY,
3813 amr_exts, "#!AMR-WB", 7, GST_TYPE_FIND_MAXIMUM);
3814 TYPE_FIND_REGISTER (plugin, "audio/iLBC-sh", GST_RANK_PRIMARY,
3815 ilbc_type_find, ilbc_exts, ILBC_CAPS, NULL, NULL);
3816 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sid", GST_RANK_MARGINAL,
3817 sid_exts, "PSID", 4, GST_TYPE_FIND_MAXIMUM);
3818 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xcf", GST_RANK_SECONDARY,
3819 xcf_exts, "gimp xcf", 8, GST_TYPE_FIND_MAXIMUM);
3820 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mng", GST_RANK_SECONDARY,
3821 mng_exts, "\212MNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
3822 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-jng", GST_RANK_SECONDARY,
3823 jng_exts, "\213JNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
3824 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xpixmap", GST_RANK_SECONDARY,
3825 xpm_exts, "/* XPM */", 9, GST_TYPE_FIND_MAXIMUM);
3826 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-sun-raster",
3827 GST_RANK_SECONDARY, ras_exts, "\131\246\152\225", 4,
3828 GST_TYPE_FIND_MAXIMUM);
3829 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-bzip",
3830 GST_RANK_SECONDARY, bz2_exts, "BZh", 3, GST_TYPE_FIND_LIKELY);
3831 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-gzip",
3832 GST_RANK_SECONDARY, gz_exts, "\037\213", 2, GST_TYPE_FIND_LIKELY);
3833 TYPE_FIND_REGISTER_START_WITH (plugin, "application/zip", GST_RANK_SECONDARY,
3834 zip_exts, "PK\003\004", 4, GST_TYPE_FIND_LIKELY);
3835 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-compress",
3836 GST_RANK_SECONDARY, compress_exts, "\037\235", 2, GST_TYPE_FIND_LIKELY);
3837 TYPE_FIND_REGISTER (plugin, "subtitle/x-kate", GST_RANK_MARGINAL,
3838 kate_type_find, NULL, NULL, NULL, NULL);
3839 TYPE_FIND_REGISTER (plugin, "audio/x-flac", GST_RANK_PRIMARY,
3840 flac_type_find, flac_exts, FLAC_CAPS, NULL, NULL);
3841 TYPE_FIND_REGISTER (plugin, "audio/x-vorbis", GST_RANK_PRIMARY,
3842 vorbis_type_find, NULL, VORBIS_CAPS, NULL, NULL);
3843 TYPE_FIND_REGISTER (plugin, "video/x-theora", GST_RANK_PRIMARY,
3844 theora_type_find, NULL, THEORA_CAPS, NULL, NULL);
3845 TYPE_FIND_REGISTER (plugin, "application/x-ogm-video", GST_RANK_PRIMARY,
3846 ogmvideo_type_find, NULL, OGMVIDEO_CAPS, NULL, NULL);
3847 TYPE_FIND_REGISTER (plugin, "application/x-ogm-audio", GST_RANK_PRIMARY,
3848 ogmaudio_type_find, NULL, OGMAUDIO_CAPS, NULL, NULL);
3849 TYPE_FIND_REGISTER (plugin, "application/x-ogm-text", GST_RANK_PRIMARY,
3850 ogmtext_type_find, NULL, OGMTEXT_CAPS, NULL, NULL);
3851 TYPE_FIND_REGISTER (plugin, "audio/x-speex", GST_RANK_PRIMARY,
3852 speex_type_find, NULL, SPEEX_CAPS, NULL, NULL);
3853 TYPE_FIND_REGISTER (plugin, "audio/x-celt", GST_RANK_PRIMARY,
3854 celt_type_find, NULL, CELT_CAPS, NULL, NULL);
3855 TYPE_FIND_REGISTER (plugin, "application/x-ogg-skeleton", GST_RANK_PRIMARY,
3856 oggskel_type_find, NULL, OGG_SKELETON_CAPS, NULL, NULL);
3857 TYPE_FIND_REGISTER (plugin, "text/x-cmml", GST_RANK_PRIMARY, cmml_type_find,
3858 NULL, CMML_CAPS, NULL, NULL);
3859 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-executable",
3860 GST_RANK_MARGINAL, NULL, "\177ELF", 4, GST_TYPE_FIND_MAXIMUM);
3861 TYPE_FIND_REGISTER (plugin, "adts_mpeg_stream", GST_RANK_SECONDARY,
3862 aac_type_find, aac_exts, AAC_CAPS, NULL, NULL);
3863 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-spc", GST_RANK_SECONDARY,
3864 spc_exts, "SNES-SPC700 Sound File Data", 27, GST_TYPE_FIND_MAXIMUM);
3865 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack", GST_RANK_SECONDARY,
3866 wavpack_type_find, wavpack_exts, WAVPACK_CAPS, NULL, NULL);
3867 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack-correction", GST_RANK_SECONDARY,
3868 wavpack_type_find, wavpack_correction_exts, WAVPACK_CORRECTION_CAPS, NULL,
3870 TYPE_FIND_REGISTER (plugin, "application/postscript", GST_RANK_SECONDARY,
3871 postscript_type_find, ps_exts, POSTSCRIPT_CAPS, NULL, NULL);
3872 TYPE_FIND_REGISTER (plugin, "image/svg+xml", GST_RANK_SECONDARY,
3873 svg_type_find, svg_exts, SVG_CAPS, NULL, NULL);
3874 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-rar",
3875 GST_RANK_SECONDARY, rar_exts, "Rar!", 4, GST_TYPE_FIND_LIKELY);
3876 TYPE_FIND_REGISTER (plugin, "application/x-tar", GST_RANK_SECONDARY,
3877 tar_type_find, tar_exts, TAR_CAPS, NULL, NULL);
3878 TYPE_FIND_REGISTER (plugin, "application/x-ar", GST_RANK_SECONDARY,
3879 ar_type_find, ar_exts, AR_CAPS, NULL, NULL);
3880 TYPE_FIND_REGISTER (plugin, "application/x-ms-dos-executable",
3881 GST_RANK_SECONDARY, msdos_type_find, msdos_exts, MSDOS_CAPS, NULL, NULL);
3882 TYPE_FIND_REGISTER (plugin, "video/x-dirac", GST_RANK_PRIMARY,
3883 dirac_type_find, NULL, DIRAC_CAPS, NULL, NULL);
3884 TYPE_FIND_REGISTER (plugin, "multipart/x-mixed-replace", GST_RANK_SECONDARY,
3885 multipart_type_find, NULL, MULTIPART_CAPS, NULL, NULL);
3886 TYPE_FIND_REGISTER (plugin, "application/x-mmsh", GST_RANK_SECONDARY,
3887 mmsh_type_find, NULL, MMSH_CAPS, NULL, NULL);
3888 TYPE_FIND_REGISTER (plugin, "video/vivo", GST_RANK_SECONDARY,
3889 vivo_type_find, vivo_exts, VIVO_CAPS, NULL, NULL);
3890 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nsf",
3891 GST_RANK_SECONDARY, nsf_exts, "NESM\x1a", 5, GST_TYPE_FIND_MAXIMUM);
3892 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gym",
3893 GST_RANK_SECONDARY, gym_exts, "GYMX", 4, GST_TYPE_FIND_MAXIMUM);
3894 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-ay",
3895 GST_RANK_SECONDARY, ay_exts, "ZXAYEMUL", 8, GST_TYPE_FIND_MAXIMUM);
3896 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gbs",
3897 GST_RANK_SECONDARY, gbs_exts, "GBS\x01", 4, GST_TYPE_FIND_MAXIMUM);
3898 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-vgm",
3899 GST_RANK_SECONDARY, vgm_exts, "Vgm\x20", 4, GST_TYPE_FIND_MAXIMUM);
3900 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sap",
3901 GST_RANK_SECONDARY, sap_exts, "SAP\x0d\x0aAUTHOR\x20", 12,
3902 GST_TYPE_FIND_MAXIMUM);
3903 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-kss", GST_RANK_SECONDARY,
3904 kss_exts, "KSSX\0", 5, GST_TYPE_FIND_MAXIMUM);
3905 TYPE_FIND_REGISTER_START_WITH (plugin, "application/pdf", GST_RANK_SECONDARY,
3906 pdf_exts, "%PDF-", 5, GST_TYPE_FIND_LIKELY);
3907 TYPE_FIND_REGISTER_START_WITH (plugin, "application/msword",
3908 GST_RANK_SECONDARY, msword_exts, "\320\317\021\340\241\261\032\341", 8,
3909 GST_TYPE_FIND_LIKELY);
3910 /* Mac OS X .DS_Store files tend to be taken for video/mpeg */
3911 TYPE_FIND_REGISTER_START_WITH (plugin, "application/octet-stream",
3912 GST_RANK_SECONDARY, dsstore_exts, "\000\000\000\001Bud1", 8,
3913 GST_TYPE_FIND_LIKELY);
3914 TYPE_FIND_REGISTER_START_WITH (plugin, "image/vnd.adobe.photoshop",
3915 GST_RANK_SECONDARY, psd_exts, "8BPS\000\001\000\000\000\000", 10,
3916 GST_TYPE_FIND_LIKELY);
3919 TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,
3920 xdgmime_typefind, NULL, NULL, NULL, NULL);
3926 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
3928 "typefindfunctions",
3929 "default typefind functions",
3930 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)