2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3 * Copyright (C) 2005-2009 Tim-Philipp Müller <tim centricular net>
4 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * gsttypefindfunctions.c: collection of various typefind functions
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 #include <glib/gprintf.h>
31 /* don't want to add gio xdgmime typefinder if gio was disabled via configure */
37 #include <gst/gsttypefind.h>
38 #include <gst/gstelement.h>
39 #include <gst/gstversion.h>
40 #include <gst/gstinfo.h>
41 #include <gst/gstutils.h>
47 #include "gstaacutil.h"
49 GST_DEBUG_CATEGORY_STATIC (type_find_debug);
50 #define GST_CAT_DEFAULT type_find_debug
52 /* DataScanCtx: helper for typefind functions that scan through data
53 * step-by-step, to avoid doing a peek at each and every offset */
55 #define DATA_SCAN_CTX_CHUNK_SIZE 4096
65 data_scan_ctx_advance (GstTypeFind * tf, DataScanCtx * c, guint bytes_to_skip)
67 c->offset += bytes_to_skip;
68 if (G_LIKELY (c->size > bytes_to_skip)) {
69 c->size -= bytes_to_skip;
70 c->data += bytes_to_skip;
77 static inline gboolean
78 data_scan_ctx_ensure_data (GstTypeFind * tf, DataScanCtx * c, gint min_len)
82 guint chunk_len = MAX (DATA_SCAN_CTX_CHUNK_SIZE, min_len);
84 if (G_LIKELY (c->size >= min_len))
87 data = gst_type_find_peek (tf, c->offset, chunk_len);
88 if (G_LIKELY (data != NULL)) {
94 /* if there's less than our chunk size, try to get as much as we can, but
95 * always at least min_len bytes (we might be typefinding the first buffer
96 * of the stream and not have as much data available as we'd like) */
97 len = gst_type_find_get_length (tf);
99 len = CLAMP (len - c->offset, min_len, chunk_len);
104 data = gst_type_find_peek (tf, c->offset, len);
114 static inline gboolean
115 data_scan_ctx_memcmp (GstTypeFind * tf, DataScanCtx * c, guint offset,
116 const gchar * data, guint len)
118 if (!data_scan_ctx_ensure_data (tf, c, offset + len))
121 return (memcmp (c->data + offset, data, len) == 0);
125 static gboolean xml_check_first_element (GstTypeFind * tf,
126 const gchar * element, guint elen, gboolean strict);
127 static gboolean sdp_check_header (GstTypeFind * tf);
129 static GstStaticCaps utf8_caps = GST_STATIC_CAPS ("text/plain");
131 #define UTF8_CAPS gst_static_caps_get(&utf8_caps)
134 utf8_type_find_have_valid_utf8_at_offset (GstTypeFind * tf, guint64 offset,
135 GstTypeFindProbability * prob)
139 /* randomly decided values */
140 guint min_size = 16; /* minimum size */
141 guint size = 32 * 1024; /* starting size */
142 guint probability = 95; /* starting probability */
143 guint step = 10; /* how much we reduce probability in each
146 while (probability > step && size > min_size) {
147 data = gst_type_find_peek (tf, offset, size);
150 gchar *start = (gchar *) data;
152 if (g_utf8_validate (start, size, (const gchar **) &end) || (end - start + 4 > size)) { /* allow last char to be cut off */
167 utf8_type_find (GstTypeFind * tf, gpointer unused)
169 GstTypeFindProbability start_prob, mid_prob;
172 /* leave xml to the xml typefinders */
173 if (xml_check_first_element (tf, "", 0, TRUE))
176 /* leave sdp to the sdp typefinders */
177 if (sdp_check_header (tf))
180 /* check beginning of stream */
181 if (!utf8_type_find_have_valid_utf8_at_offset (tf, 0, &start_prob))
184 GST_LOG ("start is plain text with probability of %u", start_prob);
186 /* POSSIBLE is the highest probability we ever return if we can't
187 * probe into the middle of the file and don't know its length */
189 length = gst_type_find_get_length (tf);
190 if (length == 0 || length == (guint64) - 1) {
191 gst_type_find_suggest (tf, MIN (start_prob, GST_TYPE_FIND_POSSIBLE),
196 if (length < 64 * 1024) {
197 gst_type_find_suggest (tf, start_prob, UTF8_CAPS);
201 /* check middle of stream */
202 if (!utf8_type_find_have_valid_utf8_at_offset (tf, length / 2, &mid_prob))
205 GST_LOG ("middle is plain text with probability of %u", mid_prob);
206 gst_type_find_suggest (tf, (start_prob + mid_prob) / 2, UTF8_CAPS);
209 /*** text/uri-list ***/
211 static GstStaticCaps uri_caps = GST_STATIC_CAPS ("text/uri-list");
213 #define URI_CAPS (gst_static_caps_get(&uri_caps))
214 #define BUFFER_SIZE 16 /* If the string is < 16 bytes we're screwed */
215 #define INC_BUFFER { \
217 if (pos == BUFFER_SIZE) { \
219 offset += BUFFER_SIZE; \
220 data = gst_type_find_peek (tf, offset, BUFFER_SIZE); \
221 if (data == NULL) return; \
227 uri_type_find (GstTypeFind * tf, gpointer unused)
229 guint8 *data = gst_type_find_peek (tf, 0, BUFFER_SIZE);
234 /* Search for # comment lines */
235 while (*data == '#') {
236 /* Goto end of line */
237 while (*data != '\n') {
244 if (!g_ascii_isalpha (*data)) {
245 /* Had a non alpha char - can't be uri-list */
251 while (g_ascii_isalnum (*data)) {
256 /* First non alpha char is not a : */
260 /* Get the next 2 bytes as well */
261 data = gst_type_find_peek (tf, offset + pos, 3);
265 if (data[1] != '/' && data[2] != '/') {
269 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, URI_CAPS);
274 /*** application/xml **********************************************************/
276 #define XML_BUFFER_SIZE 16
277 #define XML_INC_BUFFER { \
279 if (pos == XML_BUFFER_SIZE) { \
281 offset += XML_BUFFER_SIZE; \
282 data = gst_type_find_peek (tf, offset, XML_BUFFER_SIZE); \
283 if (data == NULL) return FALSE; \
290 xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen,
298 data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE);
302 /* look for the XMLDec
303 * see XML spec 2.8, Prolog and Document Type Declaration
304 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
305 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
307 if (strict && !got_xmldec)
310 /* skip XMLDec in any case if we've got one */
316 /* look for the first element, it has to be the requested element. Bail
317 * out if it is not within the first 4kB. */
318 while (data && (offset + pos) < 4096) {
319 while (*data != '<' && (offset + pos) < 4096) {
324 if (!g_ascii_isalpha (*data)) {
325 /* if not alphabetic, it's a PI or an element / attribute declaration
326 * like <?xxx or <!xxx */
331 /* the first normal element, check if it's the one asked for */
332 data = gst_type_find_peek (tf, offset + pos, elen + 1);
333 return (data && element && strncmp ((char *) data, element, elen) == 0);
339 static GstStaticCaps generic_xml_caps = GST_STATIC_CAPS ("application/xml");
341 #define GENERIC_XML_CAPS (gst_static_caps_get(&generic_xml_caps))
343 xml_type_find (GstTypeFind * tf, gpointer unused)
345 if (xml_check_first_element (tf, "", 0, TRUE)) {
346 gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, GENERIC_XML_CAPS);
350 /*** application/sdp *********************************************************/
352 static GstStaticCaps sdp_caps = GST_STATIC_CAPS ("application/sdp");
354 #define SDP_CAPS (gst_static_caps_get(&sdp_caps))
356 sdp_check_header (GstTypeFind * tf)
360 data = gst_type_find_peek (tf, 0, 5);
364 /* sdp must start with v=0[\r]\n */
365 if (memcmp (data, "v=0", 3))
368 if (data[3] == '\r' && data[4] == '\n')
377 sdp_type_find (GstTypeFind * tf, gpointer unused)
379 if (sdp_check_header (tf))
380 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDP_CAPS);
383 /*** application/smil *********************************************************/
385 static GstStaticCaps smil_caps = GST_STATIC_CAPS ("application/smil");
387 #define SMIL_CAPS (gst_static_caps_get(&smil_caps))
389 smil_type_find (GstTypeFind * tf, gpointer unused)
391 if (xml_check_first_element (tf, "smil", 4, FALSE)) {
392 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SMIL_CAPS);
398 static GstStaticCaps html_caps = GST_STATIC_CAPS ("text/html");
400 #define HTML_CAPS gst_static_caps_get (&html_caps)
403 html_type_find (GstTypeFind * tf, gpointer unused)
407 data = (gchar *) gst_type_find_peek (tf, 0, 16);
411 if (!g_ascii_strncasecmp (data, "<!DOCTYPE HTML", 14)) {
412 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
413 } else if (xml_check_first_element (tf, "html", 4, FALSE)) {
414 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
415 } else if ((d = memchr (data, '<', 16))) {
416 data = (gchar *) gst_type_find_peek (tf, d - data, 6);
417 if (data && g_ascii_strncasecmp (data, "<html>", 6) == 0) {
418 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
425 static GstStaticCaps mid_caps = GST_STATIC_CAPS ("audio/midi");
427 #define MID_CAPS gst_static_caps_get(&mid_caps)
429 mid_type_find (GstTypeFind * tf, gpointer unused)
431 guint8 *data = gst_type_find_peek (tf, 0, 4);
433 /* http://jedi.ks.uiuc.edu/~johns/links/music/midifile.html */
434 if (data && data[0] == 'M' && data[1] == 'T' && data[2] == 'h'
436 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MID_CAPS);
439 /*** audio/mobile-xmf ***/
441 static GstStaticCaps mxmf_caps = GST_STATIC_CAPS ("audio/mobile-xmf");
443 #define MXMF_CAPS gst_static_caps_get(&mxmf_caps)
445 mxmf_type_find (GstTypeFind * tf, gpointer unused)
449 /* Search FileId "XMF_" 4 bytes */
450 data = gst_type_find_peek (tf, 0, 4);
451 if (data && data[0] == 'X' && data[1] == 'M' && data[2] == 'F'
453 /* Search Format version "2.00" 4 bytes */
454 data = gst_type_find_peek (tf, 4, 4);
455 if (data && data[0] == '2' && data[1] == '.' && data[2] == '0'
457 /* Search TypeId 2 1 byte */
458 data = gst_type_find_peek (tf, 11, 1);
459 if (data && data[0] == 2) {
460 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXMF_CAPS);
467 /*** video/x-fli ***/
469 static GstStaticCaps flx_caps = GST_STATIC_CAPS ("video/x-fli");
471 #define FLX_CAPS gst_static_caps_get(&flx_caps)
473 flx_type_find (GstTypeFind * tf, gpointer unused)
475 guint8 *data = gst_type_find_peek (tf, 0, 134);
478 /* check magic and the frame type of the first frame */
479 if ((data[4] == 0x11 || data[4] == 0x12 ||
480 data[4] == 0x30 || data[4] == 0x44) &&
482 ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1)) {
483 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLX_CAPS);
487 data = gst_type_find_peek (tf, 0, 6);
489 /* check magic only */
490 if ((data[4] == 0x11 || data[4] == 0x12 ||
491 data[4] == 0x30 || data[4] == 0x44) && data[5] == 0xaf) {
492 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, FLX_CAPS);
498 /*** application/x-id3 ***/
500 static GstStaticCaps id3_caps = GST_STATIC_CAPS ("application/x-id3");
502 #define ID3_CAPS gst_static_caps_get(&id3_caps)
504 id3v2_type_find (GstTypeFind * tf, gpointer unused)
506 guint8 *data = gst_type_find_peek (tf, 0, 10);
508 if (data && memcmp (data, "ID3", 3) == 0 &&
509 data[3] != 0xFF && data[4] != 0xFF &&
510 (data[6] & 0x80) == 0 && (data[7] & 0x80) == 0 &&
511 (data[8] & 0x80) == 0 && (data[9] & 0x80) == 0) {
512 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
517 id3v1_type_find (GstTypeFind * tf, gpointer unused)
519 guint8 *data = gst_type_find_peek (tf, -128, 3);
521 if (data && memcmp (data, "TAG", 3) == 0) {
522 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
526 /*** application/x-ape ***/
528 static GstStaticCaps apetag_caps = GST_STATIC_CAPS ("application/x-apetag");
530 #define APETAG_CAPS gst_static_caps_get(&apetag_caps)
532 apetag_type_find (GstTypeFind * tf, gpointer unused)
536 /* APEv1/2 at start of file */
537 data = gst_type_find_peek (tf, 0, 8);
538 if (data && !memcmp (data, "APETAGEX", 8)) {
539 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
543 /* APEv1/2 at end of file */
544 data = gst_type_find_peek (tf, -32, 8);
545 if (data && !memcmp (data, "APETAGEX", 8)) {
546 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
551 /*** audio/x-ttafile ***/
553 static GstStaticCaps tta_caps = GST_STATIC_CAPS ("audio/x-ttafile");
555 #define TTA_CAPS gst_static_caps_get(&tta_caps)
557 tta_type_find (GstTypeFind * tf, gpointer unused)
559 guint8 *data = gst_type_find_peek (tf, 0, 3);
562 if (memcmp (data, "TTA", 3) == 0) {
563 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTA_CAPS);
569 /*** audio/x-flac ***/
570 static GstStaticCaps flac_caps = GST_STATIC_CAPS ("audio/x-flac");
572 #define FLAC_CAPS (gst_static_caps_get(&flac_caps))
575 flac_type_find (GstTypeFind * tf, gpointer unused)
577 DataScanCtx c = { 0, NULL, 0 };
579 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
582 /* standard flac (also old/broken flac-in-ogg with an initial 4-byte marker
583 * packet and without the usual packet framing) */
584 if (memcmp (c.data, "fLaC", 4) == 0) {
585 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
589 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
592 /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */
593 if (memcmp (c.data, "\177FLAC\001", 6) == 0) {
594 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
598 /* disabled because it happily typefinds /dev/urandom as audio/x-flac, and
599 * because I yet have to see header-less flac in the wild */
601 /* flac without headers (subset format) */
602 /* 64K should be enough */
603 while (c.offset < (64 * 1024)) {
604 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
607 /* look for frame header,
608 * http://flac.sourceforge.net/format.html#frame_header
610 if (c.data[0] == 0xff && (c.data[1] >> 2) == 0x3e) {
611 /* bit 15 in the header must be 0 */
612 if (((c.data[1] >> 1) & 0x01) == 0x01)
615 /* blocksize must be != 0x00 */
616 if ((c.data[2] >> 4) == 0x00)
619 /* samplerate must be != 0x0f */
620 if ((c.data[2] & 0x0f) == 0x0f)
622 /* also 0 is invalid, as it means get the info from the header and we
623 * don't have headers if we are here */
624 if ((c.data[2] & 0x0f) == 0x00)
627 /* channel assignment must be < 11 */
628 if ((c.data[3] >> 4) >= 11)
631 /* sample size must be != 0x07 and != 0x05 */
632 if (((c.data[3] >> 1) & 0x07) == 0x07)
634 if (((c.data[3] >> 1) & 0x07) == 0x05)
636 /* also 0 is invalid, as it means get the info from the header and we
637 * don't have headers if we are here */
638 if (((c.data[3] >> 1) & 0x07) == 0x00)
641 /* next bit must be 0 */
642 if ((c.data[3] & 0x01) == 0x01)
645 /* FIXME: shouldn't we include the crc check ? */
647 GST_DEBUG ("Found flac without headers at %d", (gint) c.offset);
648 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, FLAC_CAPS);
652 data_scan_ctx_advance (tf, &c, 1);
657 /*** audio/mpeg version 2, 4 ***/
659 static GstStaticCaps aac_caps = GST_STATIC_CAPS ("audio/mpeg, "
660 "mpegversion = (int) { 2, 4 }, framed = (bool) false");
661 #define AAC_CAPS (gst_static_caps_get(&aac_caps))
662 #define AAC_AMOUNT (4096)
664 aac_type_find (GstTypeFind * tf, gpointer unused)
666 /* LUT to convert the AudioObjectType from the ADTS header to a string */
667 static const gchar profile_to_string[][5] = { "main", "lc", "ssr", "ltp" };
668 static const guint sample_freq[] = { 96000, 88200, 64000, 48000, 44100,
669 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350
671 DataScanCtx c = { 0, NULL, 0 };
673 while (c.offset < AAC_AMOUNT) {
676 /* detect adts header or adif header.
677 * The ADIF header is 4 bytes, that should be OK. The ADTS header, on
678 * the other hand, is 14 bits only, so we require one valid frame with
679 * again a valid syncpoint on the next one (28 bits) for certainty. We
680 * require 4 kB, which is quite a lot, since frames are generally 200-400
683 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
686 snc = GST_READ_UINT16_BE (c.data);
687 if (G_UNLIKELY ((snc & 0xfff6) == 0xfff0)) {
688 /* ADTS header - find frame length */
689 GST_DEBUG ("Found one ADTS syncpoint at offset 0x%" G_GINT64_MODIFIER
690 "x, tracing next...", c.offset);
691 len = ((c.data[3] & 0x03) << 11) |
692 (c.data[4] << 3) | ((c.data[5] & 0xe0) >> 5);
694 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
695 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
699 /* check if there's a second ADTS frame */
700 snc = GST_READ_UINT16_BE (c.data + len);
701 if ((snc & 0xfff6) == 0xfff0) {
703 guint mpegversion, sample_freq_idx, channel_config, profile, rate;
706 mpegversion = (c.data[1] & 0x08) ? 2 : 4;
707 profile = c.data[2] >> 6;
708 sample_freq_idx = ((c.data[2] & 0x3c) >> 2);
709 channel_config = ((c.data[2] & 0x01) << 2) + (c.data[3] >> 6);
711 GST_DEBUG ("Found second ADTS-%d syncpoint at offset 0x%"
712 G_GINT64_MODIFIER "x, framelen %u", mpegversion, c.offset, len);
714 /* 0xd and 0xe are reserved. 0xf means the sample frequency is directly
715 * specified in the header, but that's not allowed for ADTS */
716 if (sample_freq_idx > 0xc) {
717 GST_DEBUG ("Unexpected sample frequency index %d or wrong sync",
722 rate = sample_freq[sample_freq_idx];
723 GST_LOG ("ADTS: profile=%u, rate=%u", profile, rate);
725 /* ADTS counts profiles from 0 instead of 1 to save bits */
726 level = gst_aac_level_from_header (profile + 1, rate, channel_config);
728 caps = gst_caps_new_simple ("audio/mpeg",
729 "framed", G_TYPE_BOOLEAN, FALSE,
730 "mpegversion", G_TYPE_INT, mpegversion,
731 "stream-type", G_TYPE_STRING, "adts",
732 "base-profile", G_TYPE_STRING, profile_to_string[profile],
733 "profile", G_TYPE_STRING, profile_to_string[profile], NULL);
738 /* we use a string here because h.264 levels are also strings and
739 * there aren't a lot of levels, so it's not too awkward to not use
740 * and integer here and keep the field type consistent with h.264 */
741 g_snprintf (level_str, sizeof (level_str), "%d", level);
742 gst_caps_set_simple (caps, "level", G_TYPE_STRING, level_str, NULL);
745 /* add rate and number of channels if we can */
746 if (channel_config != 0 && channel_config <= 7) {
747 const guint channels_map[] = { 0, 1, 2, 3, 4, 5, 6, 8 };
749 gst_caps_set_simple (caps, "channels", G_TYPE_INT,
750 channels_map[channel_config], "rate", G_TYPE_INT, rate, NULL);
753 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, caps);
754 gst_caps_unref (caps);
758 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
759 } else if (!memcmp (c.data, "ADIF", 4)) {
761 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
762 "framed", G_TYPE_BOOLEAN, FALSE, "mpegversion", G_TYPE_INT, 4,
763 "stream-format", G_TYPE_STRING, "adif", NULL);
769 data_scan_ctx_advance (tf, &c, 1);
773 /*** audio/mpeg version 1 ***/
776 * The chance that random data is identified as a valid mp3 header is 63 / 2^18
777 * (0.024%) per try. This makes the function for calculating false positives
778 * 1 - (1 - ((63 / 2 ^18) ^ GST_MP3_TYPEFIND_MIN_HEADERS)) ^ buffersize)
779 * This has the following probabilities of false positives:
780 * datasize MIN_HEADERS
782 * 4096 62.6% 0.02% 0% 0%
783 * 16384 98% 0.09% 0% 0%
784 * 1 MiB 100% 5.88% 0% 0%
785 * 1 GiB 100% 100% 1.44% 0%
786 * 1 TiB 100% 100% 100% 0.35%
787 * This means that the current choice (3 headers by most of the time 4096 byte
788 * buffers is pretty safe for now.
790 * The max. size of each frame is 1440 bytes, which means that for N frames to
791 * be detected, we need 1440 * GST_MP3_TYPEFIND_MIN_HEADERS + 3 bytes of data.
792 * Assuming we step into the stream right after the frame header, this
793 * means we need 1440 * (GST_MP3_TYPEFIND_MIN_HEADERS + 1) - 1 + 3 bytes
794 * of data (5762) to always detect any mp3.
797 static const guint mp3types_bitrates[2][3][16] =
798 { {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
799 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
800 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
801 {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
802 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
803 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}},
806 static const guint mp3types_freqs[3][3] = { {11025, 12000, 8000},
807 {22050, 24000, 16000},
808 {44100, 48000, 32000}
812 mp3_type_frame_length_from_header (guint32 header, guint * put_layer,
813 guint * put_channels, guint * put_bitrate, guint * put_samplerate,
814 gboolean * may_be_free_format, gint possible_free_framelen)
816 guint bitrate, layer, length, mode, samplerate, version, channels;
818 if ((header & 0xffe00000) != 0xffe00000)
821 /* we don't need extension, copyright, original or
822 * emphasis for the frame length */
830 length = header & 0x1;
833 /* sampling frequency */
834 samplerate = header & 0x3;
840 bitrate = header & 0xF;
841 if (bitrate == 0 && possible_free_framelen == -1) {
842 GST_LOG ("Possibly a free format mp3 - signalling");
843 *may_be_free_format = TRUE;
845 if (bitrate == 15 || (bitrate == 0 && possible_free_framelen == -1))
848 /* ignore error correction, too */
852 layer = 4 - (header & 0x3);
857 /* version 0=MPEG2.5; 2=MPEG2; 3=MPEG1 */
858 version = header & 0x3;
863 channels = (mode == 3) ? 1 : 2;
864 samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate];
868 length += possible_free_framelen;
869 bitrate = length * samplerate / 48000;
871 length += possible_free_framelen;
872 bitrate = length * samplerate /
873 ((layer == 3 && version != 3) ? 72000 : 144000);
877 bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate];
879 length = ((12000 * bitrate / samplerate) + length) * 4;
881 length += ((layer == 3
882 && version != 3) ? 72000 : 144000) * bitrate / samplerate;
886 GST_LOG ("mp3typefind: calculated mp3 frame length of %u bytes", length);
888 ("mp3typefind: samplerate = %u - bitrate = %u - layer = %u - version = %u"
889 " - channels = %u", samplerate, bitrate, layer, version, channels);
894 *put_channels = channels;
896 *put_bitrate = bitrate;
898 *put_samplerate = samplerate;
904 static GstStaticCaps mp3_caps = GST_STATIC_CAPS ("audio/mpeg, "
905 "mpegversion = (int) 1, layer = (int) [ 1, 3 ]");
906 #define MP3_CAPS (gst_static_caps_get(&mp3_caps))
908 * random values for typefinding
909 * if no more data is available, we will return a probability of
910 * (found_headers/TRY_HEADERS) * (MAXIMUM * (TRY_SYNC - bytes_skipped)
912 * if found_headers >= MIN_HEADERS
914 #define GST_MP3_TYPEFIND_MIN_HEADERS (2)
915 #define GST_MP3_TYPEFIND_TRY_HEADERS (5)
916 #define GST_MP3_TYPEFIND_TRY_SYNC (GST_TYPE_FIND_MAXIMUM * 100) /* 10kB */
917 #define GST_MP3_TYPEFIND_SYNC_SIZE (2048)
918 #define GST_MP3_WRONG_HEADER (10)
921 mp3_type_find_at_offset (GstTypeFind * tf, guint64 start_off,
922 guint * found_layer, GstTypeFindProbability * found_prob)
925 guint8 *data_end = NULL;
928 gint last_free_offset = -1;
929 gint last_free_framelen = -1;
930 gboolean headerstart = TRUE;
937 while (skipped < GST_MP3_TYPEFIND_TRY_SYNC) {
939 size = GST_MP3_TYPEFIND_SYNC_SIZE * 2;
942 data = gst_type_find_peek (tf, skipped + start_off, size);
943 } while (size > 10 && !data);
946 data_end = data + size;
949 guint8 *head_data = NULL;
950 guint layer = 0, bitrate, samplerate, channels;
951 guint found = 0; /* number of valid headers found */
952 guint64 offset = skipped;
954 while (found < GST_MP3_TYPEFIND_TRY_HEADERS) {
957 guint prev_layer = 0, prev_bitrate = 0;
958 guint prev_channels = 0, prev_samplerate = 0;
959 gboolean free = FALSE;
961 if ((gint64) (offset - skipped + 4) >= 0 &&
962 data + offset - skipped + 4 < data_end) {
963 head_data = data + offset - skipped;
965 head_data = gst_type_find_peek (tf, offset + start_off, 4);
969 head = GST_READ_UINT32_BE (head_data);
970 if (!(length = mp3_type_frame_length_from_header (head, &layer,
971 &channels, &bitrate, &samplerate, &free,
972 last_free_framelen))) {
974 if (last_free_offset == -1)
975 last_free_offset = offset;
977 last_free_framelen = offset - last_free_offset;
978 offset = last_free_offset;
982 last_free_framelen = -1;
985 /* Mark the fact that we didn't find a valid header at the beginning */
989 GST_LOG ("%d. header at offset %" G_GUINT64_FORMAT
990 " (0x%" G_GINT64_MODIFIER "x) was not an mp3 header "
991 "(possibly-free: %s)", found + 1, start_off + offset,
992 start_off + offset, free ? "yes" : "no");
995 if ((prev_layer && prev_layer != layer) ||
996 /* (prev_bitrate && prev_bitrate != bitrate) || <-- VBR */
997 (prev_samplerate && prev_samplerate != samplerate) ||
998 (prev_channels && prev_channels != channels)) {
999 /* this means an invalid property, or a change, which might mean
1000 * that this is not a mp3 but just a random bytestream. It could
1001 * be a freaking funky encoded mp3 though. We'll just not count
1004 prev_bitrate = bitrate;
1005 prev_channels = channels;
1006 prev_samplerate = samplerate;
1009 GST_LOG ("found %d. header at offset %" G_GUINT64_FORMAT " (0x%"
1010 G_GINT64_MODIFIER "X)", found, start_off + offset,
1011 start_off + offset);
1015 g_assert (found <= GST_MP3_TYPEFIND_TRY_HEADERS);
1016 if (head_data == NULL &&
1017 gst_type_find_peek (tf, offset + start_off - 1, 1) == NULL)
1018 /* Incomplete last frame - don't count it. */
1020 if (found == GST_MP3_TYPEFIND_TRY_HEADERS ||
1021 (found >= GST_MP3_TYPEFIND_MIN_HEADERS && head_data == NULL)) {
1022 /* we can make a valid guess */
1023 guint probability = found * GST_TYPE_FIND_MAXIMUM *
1024 (GST_MP3_TYPEFIND_TRY_SYNC - skipped) /
1025 GST_MP3_TYPEFIND_TRY_HEADERS / GST_MP3_TYPEFIND_TRY_SYNC;
1028 && probability > (GST_TYPE_FIND_MINIMUM + GST_MP3_WRONG_HEADER))
1029 probability -= GST_MP3_WRONG_HEADER;
1030 if (probability < GST_TYPE_FIND_MINIMUM)
1031 probability = GST_TYPE_FIND_MINIMUM;
1036 ("audio/mpeg calculated %u = %u * %u / %u * (%u - %"
1037 G_GUINT64_FORMAT ") / %u", probability, GST_TYPE_FIND_MAXIMUM,
1038 found, GST_MP3_TYPEFIND_TRY_HEADERS, GST_MP3_TYPEFIND_TRY_SYNC,
1039 (guint64) skipped, GST_MP3_TYPEFIND_TRY_SYNC);
1040 /* make sure we're not id3 tagged */
1041 head_data = gst_type_find_peek (tf, -128, 3);
1042 if (head_data && (memcmp (head_data, "TAG", 3) == 0)) {
1045 g_assert (probability <= GST_TYPE_FIND_MAXIMUM);
1047 *found_prob = probability;
1048 if (probability > 0)
1049 *found_layer = layer;
1060 mp3_type_find (GstTypeFind * tf, gpointer unused)
1062 GstTypeFindProbability prob, mid_prob;
1064 guint layer, mid_layer;
1067 mp3_type_find_at_offset (tf, 0, &layer, &prob);
1068 length = gst_type_find_get_length (tf);
1070 if (length == 0 || length == (guint64) - 1) {
1076 /* if we're pretty certain already, skip the additional check */
1077 if (prob >= GST_TYPE_FIND_LIKELY)
1080 mp3_type_find_at_offset (tf, length / 2, &mid_layer, &mid_prob);
1084 GST_LOG ("detected audio/mpeg only in the middle (p=%u)", mid_prob);
1090 if (layer != mid_layer) {
1091 GST_WARNING ("audio/mpeg layer discrepancy: %u vs. %u", layer, mid_layer);
1092 return; /* FIXME: or should we just go with the one in the middle? */
1095 /* detected mpeg audio both in middle of the file and at the start */
1096 prob = (prob + mid_prob) / 2;
1100 /* let's see if there's a valid header right at the start */
1101 data = gst_type_find_peek (tf, 0, 4); /* use min. frame size? */
1102 if (data && mp3_type_frame_length_from_header (GST_READ_UINT32_BE (data),
1103 &layer, NULL, NULL, NULL, NULL, 0) != 0) {
1105 prob = GST_TYPE_FIND_POSSIBLE - 10;
1107 prob = MAX (GST_TYPE_FIND_POSSIBLE - 10, prob + 10);
1117 g_return_if_fail (layer >= 1 && layer <= 3);
1119 gst_type_find_suggest_simple (tf, prob, "audio/mpeg",
1120 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, layer, NULL);
1124 /*** audio/x-musepack ***/
1126 static GstStaticCaps musepack_caps =
1127 GST_STATIC_CAPS ("audio/x-musepack, streamversion= (int) { 7, 8 }");
1129 #define MUSEPACK_CAPS (gst_static_caps_get(&musepack_caps))
1131 musepack_type_find (GstTypeFind * tf, gpointer unused)
1133 guint8 *data = gst_type_find_peek (tf, 0, 4);
1134 GstTypeFindProbability prop = GST_TYPE_FIND_MINIMUM;
1135 gint streamversion = -1;
1137 if (data && memcmp (data, "MP+", 3) == 0) {
1139 if ((data[3] & 0x7f) == 7) {
1140 prop = GST_TYPE_FIND_MAXIMUM;
1142 prop = GST_TYPE_FIND_LIKELY + 10;
1144 } else if (data && memcmp (data, "MPCK", 4) == 0) {
1146 prop = GST_TYPE_FIND_MAXIMUM;
1149 if (streamversion != -1) {
1150 gst_type_find_suggest_simple (tf, prop, "audio/x-musepack",
1151 "streamversion", G_TYPE_INT, streamversion, NULL);
1155 /*** audio/x-ac3 ***/
1156 /* FIXME 0.11: should be audio/ac3, but isn't for backwards compatibility */
1157 static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
1159 #define AC3_CAPS (gst_static_caps_get(&ac3_caps))
1163 unsigned short bit_rate;
1164 unsigned short frm_size[3];
1167 static const struct ac3_frmsize ac3_frmsizecod_tbl[] = {
1170 {40, {80, 87, 120}},
1171 {40, {80, 88, 120}},
1172 {48, {96, 104, 144}},
1173 {48, {96, 105, 144}},
1174 {56, {112, 121, 168}},
1175 {56, {112, 122, 168}},
1176 {64, {128, 139, 192}},
1177 {64, {128, 140, 192}},
1178 {80, {160, 174, 240}},
1179 {80, {160, 175, 240}},
1180 {96, {192, 208, 288}},
1181 {96, {192, 209, 288}},
1182 {112, {224, 243, 336}},
1183 {112, {224, 244, 336}},
1184 {128, {256, 278, 384}},
1185 {128, {256, 279, 384}},
1186 {160, {320, 348, 480}},
1187 {160, {320, 349, 480}},
1188 {192, {384, 417, 576}},
1189 {192, {384, 418, 576}},
1190 {224, {448, 487, 672}},
1191 {224, {448, 488, 672}},
1192 {256, {512, 557, 768}},
1193 {256, {512, 558, 768}},
1194 {320, {640, 696, 960}},
1195 {320, {640, 697, 960}},
1196 {384, {768, 835, 1152}},
1197 {384, {768, 836, 1152}},
1198 {448, {896, 975, 1344}},
1199 {448, {896, 976, 1344}},
1200 {512, {1024, 1114, 1536}},
1201 {512, {1024, 1115, 1536}},
1202 {576, {1152, 1253, 1728}},
1203 {576, {1152, 1254, 1728}},
1204 {640, {1280, 1393, 1920}},
1205 {640, {1280, 1394, 1920}}
1209 ac3_type_find (GstTypeFind * tf, gpointer unused)
1211 DataScanCtx c = { 0, NULL, 0 };
1213 /* Search for an ac3 frame; not neccesarily right at the start, but give it
1214 * a lower probability if not found right at the start. Check that the
1215 * frame is followed by a second frame at the expected offset.
1216 * We could also check the two ac3 CRCs, but we don't do that right now */
1217 while (c.offset < 1024) {
1218 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 5)))
1221 if (c.data[0] == 0x0b && c.data[1] == 0x77) {
1222 guint fscod = (c.data[4] >> 6) & 0x03;
1223 guint frmsizecod = c.data[4] & 0x3f;
1225 if (fscod < 3 && frmsizecod < 38) {
1226 DataScanCtx c_next = c;
1229 frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
1230 GST_LOG ("possible frame sync at offset %" G_GUINT64_FORMAT ", size=%u",
1231 c.offset, frame_size);
1232 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1233 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1235 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1236 guint fscod2 = (c_next.data[4] >> 6) & 0x03;
1237 guint frmsizecod2 = c_next.data[4] & 0x3f;
1239 if (fscod == fscod2 && frmsizecod == frmsizecod2) {
1240 GstTypeFindProbability prob;
1242 GST_LOG ("found second frame, looks good");
1244 prob = GST_TYPE_FIND_MAXIMUM;
1246 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1248 gst_type_find_suggest (tf, prob, AC3_CAPS);
1252 GST_LOG ("no second frame found, false sync");
1257 data_scan_ctx_advance (tf, &c, 1);
1263 /* can only be detected by using the extension, in which case we use the default
1265 static GstStaticCaps gsm_caps =
1266 GST_STATIC_CAPS ("audio/x-gsm, rate=8000, channels=1");
1268 #define GSM_CAPS (gst_static_caps_get(&gsm_caps))
1272 static GstStaticCaps wavpack_caps =
1273 GST_STATIC_CAPS ("audio/x-wavpack, framed = (boolean) false");
1275 #define WAVPACK_CAPS (gst_static_caps_get(&wavpack_caps))
1277 static GstStaticCaps wavpack_correction_caps =
1278 GST_STATIC_CAPS ("audio/x-wavpack-correction, framed = (boolean) false");
1280 #define WAVPACK_CORRECTION_CAPS (gst_static_caps_get(&wavpack_correction_caps))
1283 wavpack_type_find (GstTypeFind * tf, gpointer unused)
1289 data = gst_type_find_peek (tf, 0, 32);
1293 if (data[0] != 'w' || data[1] != 'v' || data[2] != 'p' || data[3] != 'k')
1296 /* Note: wavpack blocks can be fairly large (easily 60-110k), possibly
1297 * larger than the max. limits imposed by certain typefinding elements
1298 * like id3demux or apedemux, so typefinding is most likely only going to
1299 * work in pull-mode */
1300 blocksize = GST_READ_UINT32_LE (data + 4);
1301 GST_LOG ("wavpack header, blocksize=0x%04x", blocksize);
1303 while (offset < 32 + blocksize) {
1306 /* get chunk header */
1307 GST_LOG ("peeking at chunk at offset 0x%04x", (guint) offset);
1308 data = gst_type_find_peek (tf, offset, 4);
1311 sublen = ((guint32) data[1]) << 1;
1312 if (data[0] & 0x80) {
1313 sublen |= (((guint32) data[2]) << 9) | (((guint32) data[3]) << 17);
1314 sublen += 1 + 3; /* id + length */
1316 sublen += 1 + 1; /* id + length */
1318 if (sublen > blocksize - offset + 32) {
1319 GST_LOG ("chunk length too big (%u > %" G_GUINT64_FORMAT ")", sublen,
1320 blocksize - offset);
1323 if ((data[0] & 0x20) == 0) {
1324 switch (data[0] & 0x0f) {
1325 case 0xa: /* ID_WV_BITSTREAM */
1326 case 0xc: /* ID_WVX_BITSTREAM */
1327 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, WAVPACK_CAPS);
1329 case 0xb: /* ID_WVC_BITSTREAM */
1330 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY,
1331 WAVPACK_CORRECTION_CAPS);
1341 /*** application/postscrip ***/
1342 static GstStaticCaps postscript_caps =
1343 GST_STATIC_CAPS ("application/postscript");
1345 #define POSTSCRIPT_CAPS (gst_static_caps_get(&postscript_caps))
1348 postscript_type_find (GstTypeFind * tf, gpointer unused)
1350 guint8 *data = gst_type_find_peek (tf, 0, 3);
1354 if (data[0] == 0x04)
1356 if (data[0] == '%' && data[1] == '!')
1357 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, POSTSCRIPT_CAPS);
1361 /*** image/svg+xml ***/
1362 static GstStaticCaps svg_caps = GST_STATIC_CAPS ("image/svg+xml");
1364 #define SVG_CAPS (gst_static_caps_get(&svg_caps))
1367 svg_type_find (GstTypeFind * tf, gpointer unused)
1369 static const gchar svg_doctype[] = "!DOCTYPE svg";
1370 static const gchar svg_tag[] = "<svg";
1371 DataScanCtx c = { 0, NULL, 0 };
1373 while (c.offset <= 1024) {
1374 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
1377 if (memcmp (svg_doctype, c.data, 12) == 0) {
1378 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVG_CAPS);
1380 } else if (memcmp (svg_tag, c.data, 4) == 0) {
1381 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, SVG_CAPS);
1384 data_scan_ctx_advance (tf, &c, 1);
1388 /*** multipart/x-mixed-replace mimestream ***/
1390 static GstStaticCaps multipart_caps =
1391 GST_STATIC_CAPS ("multipart/x-mixed-replace");
1392 #define MULTIPART_CAPS gst_static_caps_get(&multipart_caps)
1394 /* multipart/x-mixed replace is:
1395 * <maybe some whitespace>--<some ascii chars>[\r]\n
1396 * <more ascii chars>[\r]\nContent-type:<more ascii>[\r]\n */
1398 multipart_type_find (GstTypeFind * tf, gpointer unused)
1403 #define MULTIPART_MAX_BOUNDARY_OFFSET 16
1404 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_BOUNDARY_OFFSET);
1409 x - data < MULTIPART_MAX_BOUNDARY_OFFSET - 2 && g_ascii_isspace (*x);
1411 if (x[0] != '-' || x[1] != '-')
1414 /* Could be okay, peek what should be enough for a complete header */
1415 #define MULTIPART_MAX_HEADER_SIZE 256
1416 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_HEADER_SIZE);
1420 for (x = data; x - data < MULTIPART_MAX_HEADER_SIZE - 14; x++) {
1421 if (!isascii (*x)) {
1425 !g_ascii_strncasecmp ("content-type:", (gchar *) x + 1, 13)) {
1426 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MULTIPART_CAPS);
1432 /*** video/mpeg systemstream ***/
1433 static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, "
1434 "systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
1436 #define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
1437 #define IS_MPEG_HEADER(data) (G_UNLIKELY((((guint8 *)(data))[0] == 0x00) && \
1438 (((guint8 *)(data))[1] == 0x00) && \
1439 (((guint8 *)(data))[2] == 0x01)))
1441 #define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
1442 #define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
1443 #define IS_MPEG_PACK_HEADER(data) (IS_MPEG_HEADER (data) && \
1444 IS_MPEG_PACK_CODE (((guint8 *)(data))[3]))
1446 #define IS_MPEG_PES_CODE(b) (((b) & 0xF0) == 0xE0 || ((b) & 0xF0) == 0xC0 || \
1448 #define IS_MPEG_PES_HEADER(data) (IS_MPEG_HEADER (data) && \
1449 IS_MPEG_PES_CODE (((guint8 *)(data))[3]))
1451 #define MPEG2_MAX_PROBE_LENGTH (128 * 1024) /* 128kB should be 64 packs of the
1452 * most common 2kB pack size. */
1454 #define MPEG2_MIN_SYS_HEADERS 2
1455 #define MPEG2_MAX_SYS_HEADERS 5
1458 mpeg_sys_is_valid_pack (GstTypeFind * tf, const guint8 * data, guint len,
1461 /* Check the pack header @ offset for validity, assuming that the 4 byte header
1462 * itself has already been checked. */
1468 /* Check marker bits */
1469 if ((data[4] & 0xC4) == 0x44) {
1474 if ((data[6] & 0x04) != 0x04 ||
1475 (data[8] & 0x04) != 0x04 ||
1476 (data[9] & 0x01) != 0x01 || (data[12] & 0x03) != 0x03)
1479 stuff_len = data[13] & 0x07;
1481 /* Check the following header bytes, if we can */
1482 if ((14 + stuff_len + 4) <= len) {
1483 if (!IS_MPEG_HEADER (data + 14 + stuff_len))
1487 *pack_size = 14 + stuff_len;
1489 } else if ((data[4] & 0xF1) == 0x21) {
1491 if ((data[6] & 0x01) != 0x01 ||
1492 (data[8] & 0x01) != 0x01 ||
1493 (data[9] & 0x80) != 0x80 || (data[11] & 0x01) != 0x01)
1496 /* Check the following header bytes, if we can */
1497 if ((12 + 4) <= len) {
1498 if (!IS_MPEG_HEADER (data + 12))
1510 mpeg_sys_is_valid_pes (GstTypeFind * tf, guint8 * data, guint len,
1513 guint pes_packet_len;
1515 /* Check the PES header at the given position, assuming the header code itself
1516 * was already checked */
1520 /* For MPEG Program streams, unbounded PES is not allowed, so we must have a
1521 * valid length present */
1522 pes_packet_len = GST_READ_UINT16_BE (data + 4);
1523 if (pes_packet_len == 0)
1526 /* Check the following header, if we can */
1527 if (6 + pes_packet_len + 4 <= len) {
1528 if (!IS_MPEG_HEADER (data + 6 + pes_packet_len))
1533 *pack_size = 6 + pes_packet_len;
1538 mpeg_sys_is_valid_sys (GstTypeFind * tf, guint8 * data, guint len,
1543 /* Check the System header at the given position, assuming the header code itself
1544 * was already checked */
1547 sys_hdr_len = GST_READ_UINT16_BE (data + 4);
1548 if (sys_hdr_len < 6)
1551 /* Check the following header, if we can */
1552 if (6 + sys_hdr_len + 4 <= len) {
1553 if (!IS_MPEG_HEADER (data + 6 + sys_hdr_len))
1558 *pack_size = 6 + sys_hdr_len;
1563 /* calculation of possibility to identify random data as mpeg systemstream:
1564 * bits that must match in header detection: 32 (or more)
1565 * chance that random data is identifed: 1/2^32
1566 * chance that MPEG2_MIN_PACK_HEADERS headers are identified:
1567 * 1/2^(32*MPEG2_MIN_PACK_HEADERS)
1568 * chance that this happens in MPEG2_MAX_PROBE_LENGTH bytes:
1569 * 1-(1+1/2^(32*MPEG2_MIN_PACK_HEADERS)^MPEG2_MAX_PROBE_LENGTH)
1570 * for current values:
1571 * 1-(1+1/2^(32*4)^101024)
1573 * Since we also check marker bits and pes packet lengths, this probability is a
1574 * very coarse upper bound.
1577 mpeg_sys_type_find (GstTypeFind * tf, gpointer unused)
1579 guint8 *data, *data0, *first_sync, *end;
1580 gint mpegversion = 0;
1581 guint pack_headers = 0;
1582 guint pes_headers = 0;
1584 guint since_last_sync = 0;
1585 guint32 sync_word = 0xffffffff;
1590 len = MPEG2_MAX_PROBE_LENGTH;
1593 data = gst_type_find_peek (tf, 0, 5 + len);
1594 } while (data == NULL && len >= 32);
1606 while (data < end) {
1608 if (sync_word == 0x00000100) {
1609 /* Found potential sync word */
1610 if (first_sync == NULL)
1611 first_sync = data - 3;
1613 if (since_last_sync > 4) {
1614 /* If more than 4 bytes since the last sync word, reset our counters,
1615 * as we're only interested in counting contiguous packets */
1616 pes_headers = pack_headers = 0;
1620 if (IS_MPEG_PACK_CODE (data[0])) {
1621 if ((data[1] & 0xC0) == 0x40) {
1624 } else if ((data[1] & 0xF0) == 0x20) {
1627 if (mpegversion != 0 &&
1628 mpeg_sys_is_valid_pack (tf, data - 3, end - data + 3, &pack_size)) {
1631 } else if (IS_MPEG_PES_CODE (data[0])) {
1633 if (mpeg_sys_is_valid_pes (tf, data - 3, end - data + 3, &pack_size)) {
1635 if (mpegversion == 0)
1638 } else if (IS_MPEG_SYS_CODE (data[0])) {
1639 if (mpeg_sys_is_valid_sys (tf, data - 3, end - data + 3, &pack_size)) {
1644 /* If we found a packet with a known size, skip the bytes in it and loop
1645 * around to check the next packet. */
1646 if (pack_size != 0) {
1647 data += pack_size - 3;
1648 sync_word = 0xffffffff;
1649 since_last_sync = 0;
1654 sync_word |= data[0];
1658 /* If we have found MAX headers, and *some* were pes headers (pack headers
1659 * are optional in an mpeg system stream) then return our high-probability
1661 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MAX_SYS_HEADERS)
1665 /* If we at least saw MIN headers, and *some* were pes headers (pack headers
1666 * are optional in an mpeg system stream) then return a lower-probability
1668 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MIN_SYS_HEADERS)
1676 prob = GST_TYPE_FIND_POSSIBLE + (10 * (pack_headers + pes_headers));
1677 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
1679 /* lower probability if the first packet wasn't right at the start */
1680 if (data0 != first_sync && prob >= 10)
1683 GST_LOG ("Suggesting MPEG %d system stream, %d packs, %d pes, prob %u%%\n",
1684 mpegversion, pack_headers, pes_headers, prob);
1686 gst_type_find_suggest_simple (tf, prob, "video/mpeg",
1687 "systemstream", G_TYPE_BOOLEAN, TRUE,
1688 "mpegversion", G_TYPE_INT, mpegversion, NULL);
1692 /*** video/mpegts Transport Stream ***/
1693 static GstStaticCaps mpegts_caps = GST_STATIC_CAPS ("video/mpegts, "
1694 "systemstream = (boolean) true, packetsize = (int) [ 188, 208 ]");
1695 #define MPEGTS_CAPS gst_static_caps_get(&mpegts_caps)
1697 #define GST_MPEGTS_TYPEFIND_MIN_HEADERS 4
1698 #define GST_MPEGTS_TYPEFIND_MAX_HEADERS 10
1699 #define GST_MPEGTS_MAX_PACKET_SIZE 208
1700 #define GST_MPEGTS_TYPEFIND_SYNC_SIZE \
1701 (GST_MPEGTS_TYPEFIND_MIN_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
1702 #define GST_MPEGTS_TYPEFIND_MAX_SYNC \
1703 (GST_MPEGTS_TYPEFIND_MAX_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
1705 #define MPEGTS_HDR_SIZE 4
1706 /* Check for sync byte, error_indicator == 0 and packet has payload */
1707 #define IS_MPEGTS_HEADER(data) (((data)[0] == 0x47) && \
1708 (((data)[1] & 0x80) == 0x00) && \
1709 (((data)[3] & 0x10) == 0x10))
1711 /* Helper function to search ahead at intervals of packet_size for mpegts
1714 mpeg_ts_probe_headers (GstTypeFind * tf, guint64 offset, gint packet_size)
1716 /* We always enter this function having found at least one header already */
1718 guint8 *data = NULL;
1720 while (found < GST_MPEGTS_TYPEFIND_MAX_HEADERS) {
1721 offset += packet_size;
1723 data = gst_type_find_peek (tf, offset, MPEGTS_HDR_SIZE);
1724 if (data == NULL || !IS_MPEGTS_HEADER (data))
1733 /* Try and detect at least 4 packets in at most 10 packets worth of
1734 * data. Need to try several possible packet sizes */
1736 mpeg_ts_type_find (GstTypeFind * tf, gpointer unused)
1738 /* TS packet sizes to test: normal, DVHS packet size and
1739 * FEC with 16 or 20 byte codes packet size. */
1740 const gint pack_sizes[] = { 188, 192, 204, 208 };
1741 const gint n_pack_sizes = sizeof (pack_sizes) / sizeof (gint);
1743 guint8 *data = NULL;
1745 guint64 skipped = 0;
1747 while (skipped < GST_MPEGTS_TYPEFIND_MAX_SYNC) {
1748 if (size < MPEGTS_HDR_SIZE) {
1749 data = gst_type_find_peek (tf, skipped, GST_MPEGTS_TYPEFIND_SYNC_SIZE);
1752 size = GST_MPEGTS_TYPEFIND_SYNC_SIZE;
1755 /* Have at least MPEGTS_HDR_SIZE bytes at this point */
1756 if (IS_MPEGTS_HEADER (data)) {
1759 for (p = 0; p < n_pack_sizes; p++) {
1762 /* Probe ahead at size pack_sizes[p] */
1763 found = mpeg_ts_probe_headers (tf, skipped, pack_sizes[p]);
1764 if (found >= GST_MPEGTS_TYPEFIND_MIN_HEADERS) {
1767 /* found at least 4 headers. 10 headers = MAXIMUM probability.
1768 * Arbitrarily, I assigned 10% probability for each header we
1769 * found, 40% -> 100% */
1770 probability = MIN (10 * found, GST_TYPE_FIND_MAXIMUM);
1772 gst_type_find_suggest_simple (tf, probability, "video/mpegts",
1773 "systemstream", G_TYPE_BOOLEAN, TRUE,
1774 "packetsize", G_TYPE_INT, pack_sizes[p], NULL);
1785 #define GST_MPEGVID_TYPEFIND_TRY_PICTURES 6
1786 #define GST_MPEGVID_TYPEFIND_TRY_SYNC (100 * 1024) /* 100 kB */
1788 /* Scan ahead a maximum of max_extra_offset bytes until the next IS_MPEG_HEADER
1789 * offset. After the call, offset will be after the 0x000001, i.e. at the 4th
1790 * byte of the MPEG header. Returns TRUE if a header was found, FALSE if not.
1793 mpeg_find_next_header (GstTypeFind * tf, DataScanCtx * c,
1794 guint64 max_extra_offset)
1796 guint64 extra_offset;
1798 for (extra_offset = 0; extra_offset <= max_extra_offset; ++extra_offset) {
1799 if (!data_scan_ctx_ensure_data (tf, c, 4))
1801 if (IS_MPEG_HEADER (c->data)) {
1802 data_scan_ctx_advance (tf, c, 3);
1805 data_scan_ctx_advance (tf, c, 1);
1810 /*** video/mpeg MPEG-4 elementary video stream ***/
1812 static GstStaticCaps mpeg4_video_caps = GST_STATIC_CAPS ("video/mpeg, "
1813 "systemstream=(boolean)false, mpegversion=4, parsed=(boolean)false");
1814 #define MPEG4_VIDEO_CAPS gst_static_caps_get(&mpeg4_video_caps)
1817 * This typefind is based on the elementary video header defined in
1818 * http://xhelmboyx.tripod.com/formats/mpeg-layout.txt
1819 * In addition, it allows the visual object sequence header to be
1820 * absent, and even the VOS header to be absent. In the latter case,
1821 * a number of VOPs have to be present.
1824 mpeg4_video_type_find (GstTypeFind * tf, gpointer unused)
1826 DataScanCtx c = { 0, NULL, 0 };
1827 gboolean seen_vios_at_0 = FALSE;
1828 gboolean seen_vios = FALSE;
1829 gboolean seen_vos = FALSE;
1830 gboolean seen_vol = FALSE;
1831 guint num_vop_headers = 0;
1834 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
1835 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
1838 if (!mpeg_find_next_header (tf, &c,
1839 GST_MPEGVID_TYPEFIND_TRY_SYNC - c.offset))
1844 /* visual_object_sequence_start_code */
1847 break; /* Terminate at second vios */
1849 seen_vios_at_0 = TRUE;
1851 data_scan_ctx_advance (tf, &c, 2);
1852 if (!mpeg_find_next_header (tf, &c, 0))
1857 /* Optional metadata */
1859 if (!mpeg_find_next_header (tf, &c, 24))
1863 /* visual_object_start_code (consider it optional) */
1865 data_scan_ctx_advance (tf, &c, 2);
1866 /* may contain ID marker and YUV clamping */
1867 if (!mpeg_find_next_header (tf, &c, 7))
1873 /* video_object_start_code */
1876 break; /* Terminate at second vos */
1878 data_scan_ctx_advance (tf, &c, 2);
1882 /* video_object_layer_start_code */
1883 if (sc >= 0x20 && sc <= 0x2F) {
1885 data_scan_ctx_advance (tf, &c, 5);
1889 /* video_object_plane_start_code */
1892 data_scan_ctx_advance (tf, &c, 2);
1896 /* Unknown start code. */
1899 if (num_vop_headers > 0 || seen_vol) {
1900 GstTypeFindProbability probability = 0;
1902 GST_LOG ("Found %d pictures, vios: %d, vos:%d, vol:%d", num_vop_headers,
1903 seen_vios, seen_vos, seen_vol);
1905 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios_at_0
1906 && seen_vos && seen_vol)
1907 probability = GST_TYPE_FIND_MAXIMUM - 1;
1908 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios
1909 && seen_vos && seen_vol)
1910 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
1911 else if (seen_vios_at_0 && seen_vos && seen_vol)
1912 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
1913 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vos
1915 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
1916 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vol)
1917 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
1918 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
1919 probability = GST_TYPE_FIND_LIKELY - 1;
1920 else if (num_vop_headers > 2 && seen_vios && seen_vos && seen_vol)
1921 probability = GST_TYPE_FIND_LIKELY - 9;
1922 else if (seen_vios && seen_vos && seen_vol)
1923 probability = GST_TYPE_FIND_LIKELY - 20;
1924 else if (num_vop_headers > 0 && seen_vos && seen_vol)
1925 probability = GST_TYPE_FIND_POSSIBLE;
1926 else if (num_vop_headers > 0)
1927 probability = GST_TYPE_FIND_POSSIBLE - 10;
1928 else if (seen_vos && seen_vol)
1929 probability = GST_TYPE_FIND_POSSIBLE - 20;
1931 gst_type_find_suggest (tf, probability, MPEG4_VIDEO_CAPS);
1935 /*** video/x-h264 H264 elementary video stream ***/
1937 static GstStaticCaps h264_video_caps = GST_STATIC_CAPS ("video/x-h264");
1939 #define H264_VIDEO_CAPS gst_static_caps_get(&h264_video_caps)
1941 #define H264_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
1944 h264_video_type_find (GstTypeFind * tf, gpointer unused)
1946 DataScanCtx c = { 0, NULL, 0 };
1948 /* Stream consists of: a series of sync codes (00 00 00 01) followed
1955 while (c.offset < H264_MAX_PROBE_LENGTH) {
1956 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
1959 if (IS_MPEG_HEADER (c.data)) {
1960 nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
1961 ref = c.data[3] & 0x60; /* nal_ref_idc */
1963 /* if forbiden bit is different to 0 won't be h264 */
1969 /* collect statistics about the NAL types */
1970 if ((nut >= 1 && nut <= 13) || nut == 19) {
1971 if ((nut == 5 && ref == 0) ||
1972 ((nut == 6 || (nut >= 9 && nut <= 12)) && ref != 0)) {
1977 } else if (nut >= 14 && nut <= 33) {
1979 /* Theoretically these are good, since if they exist in the
1980 stream it merely means that a newer backwards-compatible
1981 h.264 stream. But we should be identifying that separately. */
1984 /* unspecified, application specific */
1985 /* don't consider these bad */
1988 GST_DEBUG ("good %d bad %d", good, bad);
1990 if (good >= 10 && bad < 4) {
1991 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H264_VIDEO_CAPS);
1995 data_scan_ctx_advance (tf, &c, 4);
1997 data_scan_ctx_advance (tf, &c, 1);
2000 if (good >= 2 && bad < 1) {
2001 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H264_VIDEO_CAPS);
2006 /*** video/mpeg video stream ***/
2008 static GstStaticCaps mpeg_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2009 "systemstream = (boolean) false");
2010 #define MPEG_VIDEO_CAPS gst_static_caps_get(&mpeg_video_caps)
2013 * Idea is the same as MPEG system stream typefinding: We check each
2014 * byte of the stream to see if - from that point on - the stream
2015 * matches a predefined set of marker bits as defined in the MPEG
2018 * I'm sure someone will do a chance calculation here too.
2022 mpeg_video_stream_type_find (GstTypeFind * tf, gpointer unused)
2024 DataScanCtx c = { 0, NULL, 0 };
2025 gboolean seen_seq_at_0 = FALSE;
2026 gboolean seen_seq = FALSE;
2027 gboolean seen_gop = FALSE;
2028 guint64 last_pic_offset = 0;
2029 guint num_pic_headers = 0;
2032 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2033 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2036 if (!data_scan_ctx_ensure_data (tf, &c, 5))
2039 if (!IS_MPEG_HEADER (c.data))
2042 /* a pack header indicates that this isn't an elementary stream */
2043 if (c.data[3] == 0xBA && mpeg_sys_is_valid_pack (tf, c.data, c.size, NULL))
2046 /* do we have a sequence header? */
2047 if (c.data[3] == 0xB3) {
2048 seen_seq_at_0 = seen_seq_at_0 || (c.offset == 0);
2050 data_scan_ctx_advance (tf, &c, 4 + 8);
2054 /* or a GOP header */
2055 if (c.data[3] == 0xB8) {
2057 data_scan_ctx_advance (tf, &c, 8);
2061 /* but what we'd really like to see is a picture header */
2062 if (c.data[3] == 0x00) {
2064 last_pic_offset = c.offset;
2065 data_scan_ctx_advance (tf, &c, 8);
2069 /* ... each followed by a slice header with slice_vertical_pos=1 that's
2070 * not too far away from the previously seen picture header. */
2071 if (c.data[3] == 0x01 && num_pic_headers > found &&
2072 (c.offset - last_pic_offset) >= 4 &&
2073 (c.offset - last_pic_offset) <= 64) {
2074 data_scan_ctx_advance (tf, &c, 4);
2081 data_scan_ctx_advance (tf, &c, 1);
2084 if (found > 0 || seen_seq) {
2085 GstTypeFindProbability probability = 0;
2087 GST_LOG ("Found %d pictures, seq:%d, gop:%d", found, seen_seq, seen_gop);
2089 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq && seen_gop)
2090 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2091 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq)
2092 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2093 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2094 probability = GST_TYPE_FIND_LIKELY;
2095 else if (seen_seq_at_0 && seen_gop && found > 2)
2096 probability = GST_TYPE_FIND_LIKELY - 10;
2097 else if (seen_seq && seen_gop && found > 2)
2098 probability = GST_TYPE_FIND_LIKELY - 20;
2099 else if (seen_seq_at_0 && found > 0)
2100 probability = GST_TYPE_FIND_POSSIBLE;
2101 else if (seen_seq && found > 0)
2102 probability = GST_TYPE_FIND_POSSIBLE - 5;
2104 probability = GST_TYPE_FIND_POSSIBLE - 10;
2106 probability = GST_TYPE_FIND_POSSIBLE - 20;
2108 gst_type_find_suggest_simple (tf, probability, "video/mpeg",
2109 "systemstream", G_TYPE_BOOLEAN, FALSE,
2110 "mpegversion", G_TYPE_INT, 1, NULL);
2114 /*** audio/x-aiff ***/
2116 static GstStaticCaps aiff_caps = GST_STATIC_CAPS ("audio/x-aiff");
2118 #define AIFF_CAPS gst_static_caps_get(&aiff_caps)
2120 aiff_type_find (GstTypeFind * tf, gpointer unused)
2122 guint8 *data = gst_type_find_peek (tf, 0, 4);
2124 if (data && memcmp (data, "FORM", 4) == 0) {
2126 if (memcmp (data, "AIFF", 4) == 0 || memcmp (data, "AIFC", 4) == 0)
2127 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AIFF_CAPS);
2131 /*** audio/x-svx ***/
2133 static GstStaticCaps svx_caps = GST_STATIC_CAPS ("audio/x-svx");
2135 #define SVX_CAPS gst_static_caps_get(&svx_caps)
2137 svx_type_find (GstTypeFind * tf, gpointer unused)
2139 guint8 *data = gst_type_find_peek (tf, 0, 4);
2141 if (data && memcmp (data, "FORM", 4) == 0) {
2143 if (memcmp (data, "8SVX", 4) == 0 || memcmp (data, "16SV", 4) == 0)
2144 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVX_CAPS);
2148 /*** audio/x-shorten ***/
2150 static GstStaticCaps shn_caps = GST_STATIC_CAPS ("audio/x-shorten");
2152 #define SHN_CAPS gst_static_caps_get(&shn_caps)
2154 shn_type_find (GstTypeFind * tf, gpointer unused)
2156 guint8 *data = gst_type_find_peek (tf, 0, 4);
2158 if (data && memcmp (data, "ajkg", 4) == 0) {
2159 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2161 data = gst_type_find_peek (tf, -8, 8);
2162 if (data && memcmp (data, "SHNAMPSK", 8) == 0) {
2163 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2167 /*** application/x-ape ***/
2169 static GstStaticCaps ape_caps = GST_STATIC_CAPS ("application/x-ape");
2171 #define APE_CAPS gst_static_caps_get(&ape_caps)
2173 ape_type_find (GstTypeFind * tf, gpointer unused)
2175 guint8 *data = gst_type_find_peek (tf, 0, 4);
2177 if (data && memcmp (data, "MAC ", 4) == 0) {
2178 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 10, APE_CAPS);
2182 /*** ISO FORMATS ***/
2184 /*** audio/x-m4a ***/
2186 static GstStaticCaps m4a_caps = GST_STATIC_CAPS ("audio/x-m4a");
2188 #define M4A_CAPS (gst_static_caps_get(&m4a_caps))
2190 m4a_type_find (GstTypeFind * tf, gpointer unused)
2192 guint8 *data = gst_type_find_peek (tf, 4, 8);
2195 (memcmp (data, "ftypM4A ", 8) == 0 ||
2196 memcmp (data, "ftypmp42", 8) == 0)) {
2197 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
2201 /*** application/x-3gp ***/
2203 /* The Q is there because variables can't start with a number. */
2206 static GstStaticCaps q3gp_caps = GST_STATIC_CAPS ("application/x-3gp");
2208 #define Q3GP_CAPS (gst_static_caps_get(&q3gp_caps))
2210 q3gp_type_find (GstTypeFind * tf, gpointer unused)
2213 guint32 ftyp_size = 0;
2215 guint8 *data = NULL;
2217 if ((data = gst_type_find_peek (tf, 0, 12)) == NULL) {
2222 if (memcmp (data, "ftyp", 4) != 0) {
2226 /* check major brand */
2228 if (memcmp (data, "3gp", 3) == 0 ||
2229 memcmp (data, "3gr", 3) == 0 ||
2230 memcmp (data, "3gs", 3) == 0 || memcmp (data, "3gg", 3) == 0) {
2231 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, Q3GP_CAPS);
2235 /* check compatible brands */
2236 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2237 ftyp_size = GST_READ_UINT32_BE (data);
2239 for (offset = 16; offset < ftyp_size; offset += 4) {
2240 if ((data = gst_type_find_peek (tf, offset, 3)) == NULL) {
2243 if (memcmp (data, "3gp", 3) == 0 ||
2244 memcmp (data, "3gr", 3) == 0 ||
2245 memcmp (data, "3gs", 3) == 0 || memcmp (data, "3gg", 3) == 0) {
2246 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, Q3GP_CAPS);
2255 /*** video/mj2 and image/jp2 ***/
2256 static GstStaticCaps mj2_caps = GST_STATIC_CAPS ("video/mj2");
2258 #define MJ2_CAPS gst_static_caps_get(&mj2_caps)
2260 static GstStaticCaps jp2_caps = GST_STATIC_CAPS ("image/jp2");
2262 #define JP2_CAPS gst_static_caps_get(&jp2_caps)
2265 jp2_type_find (GstTypeFind * tf, gpointer unused)
2269 data = gst_type_find_peek (tf, 0, 24);
2274 if (memcmp (data, "\000\000\000\014jP \015\012\207\012", 12) != 0)
2277 /* check ftyp box */
2279 if (memcmp (data + 4, "ftyp", 4) == 0) {
2280 if (memcmp (data + 8, "jp2 ", 4) == 0)
2281 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JP2_CAPS);
2282 else if (memcmp (data + 8, "mjp2", 4) == 0)
2283 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MJ2_CAPS);
2287 /*** video/quicktime ***/
2289 static GstStaticCaps qt_caps = GST_STATIC_CAPS ("video/quicktime");
2291 #define QT_CAPS gst_static_caps_get(&qt_caps)
2292 #define STRNCMP(x,y,z) (strncmp ((char*)(x), (char*)(y), z))
2295 qt_type_find (GstTypeFind * tf, gpointer unused)
2301 const gchar *variant = NULL;
2303 while ((data = gst_type_find_peek (tf, offset, 12)) != NULL) {
2306 if (STRNCMP (&data[4], "ftypqt ", 8) == 0) {
2307 tip = GST_TYPE_FIND_MAXIMUM;
2311 if (STRNCMP (&data[4], "ftypisom", 8) == 0) {
2312 tip = GST_TYPE_FIND_MAXIMUM;
2317 /* box/atom types that are in common with ISO base media file format */
2318 if (STRNCMP (&data[4], "moov", 4) == 0 ||
2319 STRNCMP (&data[4], "mdat", 4) == 0 ||
2320 STRNCMP (&data[4], "ftyp", 4) == 0 ||
2321 STRNCMP (&data[4], "free", 4) == 0 ||
2322 STRNCMP (&data[4], "uuid", 4) == 0 ||
2323 STRNCMP (&data[4], "skip", 4) == 0) {
2325 tip = GST_TYPE_FIND_LIKELY;
2327 tip = GST_TYPE_FIND_NEARLY_CERTAIN;
2330 /* other box/atom types, apparently quicktime specific */
2331 else if (STRNCMP (&data[4], "pnot", 4) == 0 ||
2332 STRNCMP (&data[4], "PICT", 4) == 0 ||
2333 STRNCMP (&data[4], "wide", 4) == 0 ||
2334 STRNCMP (&data[4], "prfl", 4) == 0) {
2335 tip = GST_TYPE_FIND_MAXIMUM;
2341 size = GST_READ_UINT32_BE (data);
2345 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2346 if (sizedata == NULL)
2349 size = GST_READ_UINT64_BE (sizedata);
2354 new_offset = offset + size;
2355 if (new_offset <= offset)
2357 offset = new_offset;
2362 GstCaps *caps = gst_caps_copy (QT_CAPS);
2364 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, variant, NULL);
2365 gst_type_find_suggest (tf, tip, caps);
2366 gst_caps_unref (caps);
2368 gst_type_find_suggest (tf, tip, QT_CAPS);
2374 /*** image/x-quicktime ***/
2376 static GstStaticCaps qtif_caps = GST_STATIC_CAPS ("image/x-quicktime");
2378 #define QTIF_CAPS gst_static_caps_get(&qtif_caps)
2380 /* how many atoms we check before we give up */
2381 #define QTIF_MAXROUNDS 25
2384 qtif_type_find (GstTypeFind * tf, gpointer unused)
2387 gboolean found_idsc = FALSE;
2388 gboolean found_idat = FALSE;
2392 while ((data = gst_type_find_peek (tf, offset, 8)) != NULL) {
2395 size = GST_READ_UINT32_BE (data);
2397 const guint8 *sizedata;
2399 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2400 if (sizedata == NULL)
2403 size = GST_READ_UINT64_BE (sizedata);
2408 if (STRNCMP (data + 4, "idsc", 4) == 0)
2410 if (STRNCMP (data + 4, "idat", 4) == 0)
2413 if (found_idsc && found_idat) {
2414 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, QTIF_CAPS);
2419 if (++rounds > QTIF_MAXROUNDS)
2423 if (found_idsc || found_idat) {
2424 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, QTIF_CAPS);
2429 /*** audio/x-mod ***/
2431 static GstStaticCaps mod_caps = GST_STATIC_CAPS ("audio/x-mod");
2433 #define MOD_CAPS gst_static_caps_get(&mod_caps)
2434 /* FIXME: M15 CheckType to do */
2436 mod_type_find (GstTypeFind * tf, gpointer unused)
2441 if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) {
2442 /* Protracker and variants */
2443 if ((memcmp (data, "M.K.", 4) == 0) || (memcmp (data, "M!K!", 4) == 0) ||
2445 (memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) ||
2446 (memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) ||
2447 /* Oktalyzer (Amiga) */
2448 (memcmp (data, "OKTA", 4) == 0) ||
2449 /* Oktalyser (Atari) */
2450 (memcmp (data, "CD81", 4) == 0) ||
2452 (memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) ||
2453 /* Fasttracker or Taketracker */
2454 (memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0])
2455 && isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0
2456 && isdigit (data[0]) && isdigit (data[1]))) {
2457 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2462 if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) {
2463 if (memcmp (data, "Extended Module: ", 17) == 0 && data[37] == 0x1A) {
2464 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2469 if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) {
2470 if (memcmp (data, "OKTASONG", 8) == 0) {
2471 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2475 if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2477 if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) {
2478 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2482 if ((memcmp (data, "AMF", 3) == 0 && data[3] > 10 && data[3] < 14) ||
2484 (memcmp (data, "IMPM", 4) == 0) ||
2486 (memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0) ||
2488 (memcmp (data, "MTM", 3) == 0)) {
2489 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2493 if (memcmp (data, "RIFF", 4) == 0) {
2494 guint8 *data2 = gst_type_find_peek (tf, 8, 4);
2497 if (memcmp (data2, "DSMF", 4) == 0) {
2498 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2504 if (memcmp (data, "FAM\xFE", 4) == 0) {
2505 guint8 *data2 = gst_type_find_peek (tf, 44, 3);
2508 if (memcmp (data2, "compare", 3) == 0) {
2509 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2513 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2518 if (memcmp (data, "GDM\xFE", 4) == 0) {
2519 guint8 *data2 = gst_type_find_peek (tf, 71, 4);
2522 if (memcmp (data2, "GMFS", 4) == 0) {
2523 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2527 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2533 if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) {
2534 if (memcmp (data, "IM10", 4) == 0) {
2535 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2540 if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) {
2541 if (memcmp (data, "SCRM", 4) == 0) {
2542 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2547 if ((data = gst_type_find_peek (tf, 20, 8)) != NULL) {
2548 if (g_ascii_strncasecmp ((gchar *) data, "!Scream!", 8) == 0 ||
2549 g_ascii_strncasecmp ((gchar *) data, "BMOD2STM", 8) == 0) {
2550 guint8 *id, *stmtype;
2552 if ((id = gst_type_find_peek (tf, 28, 1)) == NULL)
2554 if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL)
2556 if (*id == 0x1A && *stmtype == 2)
2557 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2563 /*** application/x-shockwave-flash ***/
2565 static GstStaticCaps swf_caps =
2566 GST_STATIC_CAPS ("application/x-shockwave-flash");
2567 #define SWF_CAPS (gst_static_caps_get(&swf_caps))
2569 swf_type_find (GstTypeFind * tf, gpointer unused)
2571 guint8 *data = gst_type_find_peek (tf, 0, 4);
2573 if (data && (data[0] == 'F' || data[0] == 'C') &&
2574 data[1] == 'W' && data[2] == 'S') {
2575 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SWF_CAPS);
2579 /*** image/jpeg ***/
2581 #define JPEG_MARKER_IS_START_OF_FRAME(x) \
2582 ((x)>=0xc0 && (x) <= 0xcf && (x)!=0xc4 && (x)!=0xc8 && (x)!=0xcc)
2584 static GstStaticCaps jpeg_caps = GST_STATIC_CAPS ("image/jpeg");
2586 #define JPEG_CAPS (gst_static_caps_get(&jpeg_caps))
2588 jpeg_type_find (GstTypeFind * tf, gpointer unused)
2590 GstTypeFindProbability prob = GST_TYPE_FIND_POSSIBLE;
2591 DataScanCtx c = { 0, NULL, 0 };
2595 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 2)))
2598 if (c.data[0] != 0xff || c.data[1] != 0xd8)
2602 data_scan_ctx_advance (tf, &c, 2);
2604 caps = gst_caps_copy (JPEG_CAPS);
2606 while (data_scan_ctx_ensure_data (tf, &c, 4) && c.offset < (200 * 1024)) {
2610 if (c.data[0] != 0xff)
2614 if (G_UNLIKELY (marker == 0xff)) {
2615 data_scan_ctx_advance (tf, &c, 1);
2619 data_scan_ctx_advance (tf, &c, 2);
2621 /* we assume all markers we'll see before SOF have a payload length; if
2622 * that's not the case we'll just detect a false sync and bail out, but
2623 * still report POSSIBLE probability */
2624 len = GST_READ_UINT16_BE (c.data);
2626 GST_LOG ("possible JPEG marker 0x%02x (@0x%04x), segment length %u",
2627 marker, c.offset, len);
2629 if (!data_scan_ctx_ensure_data (tf, &c, len))
2632 if (marker == 0xc4 || /* DEFINE_HUFFMAN_TABLES */
2633 marker == 0xcc || /* DEFINE_ARITHMETIC_CONDITIONING */
2634 marker == 0xdb || /* DEFINE_QUANTIZATION_TABLES */
2635 marker == 0xdd || /* DEFINE_RESTART_INTERVAL */
2636 marker == 0xfe) { /* COMMENT */
2637 data_scan_ctx_advance (tf, &c, len);
2639 } else if (marker == 0xe0 && len >= (2 + 4) && /* APP0 */
2640 data_scan_ctx_memcmp (tf, &c, 2, "JFIF", 4)) {
2641 GST_LOG ("found JFIF tag");
2642 prob = GST_TYPE_FIND_MAXIMUM;
2643 data_scan_ctx_advance (tf, &c, len);
2645 /* we continue until we find a start of frame marker */
2646 } else if (marker == 0xe1 && len >= (2 + 4) && /* APP1 */
2647 data_scan_ctx_memcmp (tf, &c, 2, "Exif", 4)) {
2648 GST_LOG ("found Exif tag");
2649 prob = GST_TYPE_FIND_MAXIMUM;
2650 data_scan_ctx_advance (tf, &c, len);
2652 /* we continue until we find a start of frame marker */
2653 } else if (marker >= 0xe0 && marker <= 0xef) { /* APPn */
2654 data_scan_ctx_advance (tf, &c, len);
2656 } else if (JPEG_MARKER_IS_START_OF_FRAME (marker) && len >= (2 + 8)) {
2659 h = GST_READ_UINT16_BE (c.data + 2 + 1);
2660 w = GST_READ_UINT16_BE (c.data + 2 + 1 + 2);
2661 if (h == 0 || w == 0) {
2662 GST_WARNING ("bad width %u and/or height %u in SOF header", w, h);
2666 GST_LOG ("SOF at offset %" G_GUINT64_FORMAT ", num_markers=%d, "
2667 "WxH=%dx%d", c.offset - 2, num_markers, w, h);
2669 if (num_markers >= 5 || prob == GST_TYPE_FIND_MAXIMUM)
2670 prob = GST_TYPE_FIND_MAXIMUM;
2672 prob = GST_TYPE_FIND_LIKELY;
2674 gst_caps_set_simple (caps, "width", G_TYPE_INT, w,
2675 "height", G_TYPE_INT, h, NULL);
2677 GST_WARNING ("bad length or unexpected JPEG marker 0xff 0x%02x", marker);
2682 gst_type_find_suggest (tf, prob, caps);
2683 gst_caps_unref (caps);
2688 static GstStaticCaps bmp_caps = GST_STATIC_CAPS ("image/bmp");
2690 #define BMP_CAPS (gst_static_caps_get(&bmp_caps))
2692 bmp_type_find (GstTypeFind * tf, gpointer unused)
2694 DataScanCtx c = { 0, NULL, 0 };
2695 guint32 struct_size, w, h, planes, bpp;
2697 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 54)))
2700 if (c.data[0] != 'B' || c.data[1] != 'M')
2703 /* skip marker + size */
2704 data_scan_ctx_advance (tf, &c, 2 + 4);
2706 /* reserved, must be 0 */
2707 if (c.data[0] != 0 || c.data[1] != 0 || c.data[2] != 0 || c.data[3] != 0)
2710 data_scan_ctx_advance (tf, &c, 2 + 2);
2712 /* offset to start of image data in bytes (check for sanity) */
2713 GST_LOG ("offset=%u", GST_READ_UINT32_LE (c.data));
2714 if (GST_READ_UINT32_LE (c.data) > (10 * 1024 * 1024))
2717 struct_size = GST_READ_UINT32_LE (c.data + 4);
2718 GST_LOG ("struct_size=%u", struct_size);
2720 data_scan_ctx_advance (tf, &c, 4 + 4);
2722 if (struct_size == 0x0C) {
2723 w = GST_READ_UINT16_LE (c.data);
2724 h = GST_READ_UINT16_LE (c.data + 2);
2725 planes = GST_READ_UINT16_LE (c.data + 2 + 2);
2726 bpp = GST_READ_UINT16_LE (c.data + 2 + 2 + 2);
2727 } else if (struct_size == 40 || struct_size == 64 || struct_size == 108
2728 || struct_size == 124 || struct_size == 0xF0) {
2729 w = GST_READ_UINT32_LE (c.data);
2730 h = GST_READ_UINT32_LE (c.data + 4);
2731 planes = GST_READ_UINT16_LE (c.data + 4 + 4);
2732 bpp = GST_READ_UINT16_LE (c.data + 4 + 4 + 2);
2737 /* image sizes sanity check */
2738 GST_LOG ("w=%u, h=%u, planes=%u, bpp=%u", w, h, planes, bpp);
2739 if (w == 0 || w > 0xfffff || h == 0 || h > 0xfffff || planes != 1 ||
2740 (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32))
2743 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "image/bmp",
2744 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, "bpp", G_TYPE_INT, bpp,
2748 /*** image/tiff ***/
2749 static GstStaticCaps tiff_caps = GST_STATIC_CAPS ("image/tiff, "
2750 "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }");
2751 #define TIFF_CAPS (gst_static_caps_get(&tiff_caps))
2752 static GstStaticCaps tiff_be_caps = GST_STATIC_CAPS ("image/tiff, "
2753 "endianness = (int) BIG_ENDIAN");
2754 #define TIFF_BE_CAPS (gst_static_caps_get(&tiff_be_caps))
2755 static GstStaticCaps tiff_le_caps = GST_STATIC_CAPS ("image/tiff, "
2756 "endianness = (int) LITTLE_ENDIAN");
2757 #define TIFF_LE_CAPS (gst_static_caps_get(&tiff_le_caps))
2759 tiff_type_find (GstTypeFind * tf, gpointer ununsed)
2761 guint8 *data = gst_type_find_peek (tf, 0, 8);
2762 guint8 le_header[4] = { 0x49, 0x49, 0x2A, 0x00 };
2763 guint8 be_header[4] = { 0x4D, 0x4D, 0x00, 0x2A };
2766 if (memcmp (data, le_header, 4) == 0) {
2767 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_LE_CAPS);
2768 } else if (memcmp (data, be_header, 4) == 0) {
2769 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_BE_CAPS);
2776 static GstStaticCaps pnm_caps = GST_STATIC_CAPS ("image/x-portable-bitmap; "
2777 "image/x-portable-graymap; image/x-portable-pixmap; "
2778 "image/x-portable-anymap");
2780 #define PNM_CAPS (gst_static_caps_get(&pnm_caps))
2782 #define IS_PNM_WHITESPACE(c) \
2783 ((c) == ' ' || (c) == '\r' || (c) == '\n' || (c) == 't')
2786 pnm_type_find (GstTypeFind * tf, gpointer ununsed)
2788 const gchar *media_type = NULL;
2789 DataScanCtx c = { 0, NULL, 0 };
2792 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
2795 /* see http://en.wikipedia.org/wiki/Netpbm_format */
2796 if (c.data[0] != 'P' || c.data[1] < '1' || c.data[1] > '7' ||
2797 !IS_PNM_WHITESPACE (c.data[2]) ||
2798 (c.data[3] != '#' && c.data[3] < '0' && c.data[3] > '9'))
2801 switch (c.data[1]) {
2803 media_type = "image/x-portable-bitmap"; /* ASCII */
2806 media_type = "image/x-portable-graymap"; /* ASCII */
2809 media_type = "image/x-portable-pixmap"; /* ASCII */
2812 media_type = "image/x-portable-bitmap"; /* Raw */
2815 media_type = "image/x-portable-graymap"; /* Raw */
2818 media_type = "image/x-portable-pixmap"; /* Raw */
2821 media_type = "image/x-portable-anymap";
2824 g_return_if_reached ();
2827 /* try to extract width and height as well */
2828 if (c.data[1] != '7') {
2829 gchar s[64] = { 0, }
2832 /* need to skip any comment lines first */
2833 data_scan_ctx_advance (tf, &c, 3);
2834 while (c.data[0] == '#') { /* we know there's still data left */
2835 data_scan_ctx_advance (tf, &c, 1);
2836 while (c.data[0] != '\n' && c.data[0] != '\r') {
2837 if (!data_scan_ctx_ensure_data (tf, &c, 4))
2839 data_scan_ctx_advance (tf, &c, 1);
2841 data_scan_ctx_advance (tf, &c, 1);
2842 GST_LOG ("skipped comment line in PNM header");
2845 if (!data_scan_ctx_ensure_data (tf, &c, 32) &&
2846 !data_scan_ctx_ensure_data (tf, &c, 4)) {
2850 /* need to NUL-terminate data for sscanf */
2851 memcpy (s, c.data, MIN (sizeof (s) - 1, c.size));
2852 if (sscanf (s, "%u%c%u%c", &w, &sep1, &h, &sep2) == 4 &&
2853 IS_PNM_WHITESPACE (sep1) && IS_PNM_WHITESPACE (sep2) &&
2854 w > 0 && w < G_MAXINT && h > 0 && h < G_MAXINT) {
2855 GST_LOG ("extracted PNM width and height: %dx%d", w, h);
2861 /* FIXME: extract width + height for anymaps too */
2864 if (w > 0 && h > 0) {
2865 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type,
2866 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, NULL);
2868 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, media_type, NULL);
2872 static GstStaticCaps sds_caps = GST_STATIC_CAPS ("audio/x-sds");
2874 #define SDS_CAPS (gst_static_caps_get(&sds_caps))
2876 sds_type_find (GstTypeFind * tf, gpointer ununsed)
2878 guint8 *data = gst_type_find_peek (tf, 0, 4);
2879 guint8 mask[4] = { 0xFF, 0xFF, 0x80, 0xFF };
2880 guint8 match[4] = { 0xF0, 0x7E, 0, 0x01 };
2884 for (x = 0; x < 4; x++) {
2885 if ((data[x] & mask[x]) != match[x]) {
2889 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDS_CAPS);
2893 static GstStaticCaps ircam_caps = GST_STATIC_CAPS ("audio/x-ircam");
2895 #define IRCAM_CAPS (gst_static_caps_get(&ircam_caps))
2897 ircam_type_find (GstTypeFind * tf, gpointer ununsed)
2899 guint8 *data = gst_type_find_peek (tf, 0, 4);
2900 guint8 mask[4] = { 0xFF, 0xFF, 0xF8, 0xFF };
2901 guint8 match[4] = { 0x64, 0xA3, 0x00, 0x00 };
2903 gboolean matched = TRUE;
2908 for (x = 0; x < 4; x++) {
2909 if ((data[x] & mask[x]) != match[x]) {
2914 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, IRCAM_CAPS);
2917 /* now try the reverse version */
2919 for (x = 0; x < 4; x++) {
2920 if ((data[x] & mask[3 - x]) != match[3 - x]) {
2926 /* EBML typefind helper */
2928 ebml_check_header (GstTypeFind * tf, const gchar * doctype, int doctype_len)
2930 /* 4 bytes for EBML ID, 1 byte for header length identifier */
2931 guint8 *data = gst_type_find_peek (tf, 0, 4 + 1);
2932 gint len_mask = 0x80, size = 1, n = 1, total;
2938 if (data[0] != 0x1A || data[1] != 0x45 || data[2] != 0xDF || data[3] != 0xA3)
2941 /* length of header */
2943 while (size <= 8 && !(total & len_mask)) {
2949 total &= (len_mask - 1);
2951 total = (total << 8) | data[4 + n++];
2953 /* get new data for full header, 4 bytes for EBML ID,
2954 * EBML length tag and the actual header */
2955 data = gst_type_find_peek (tf, 0, 4 + size + total);
2959 /* the header must contain the doctype. For now, we don't parse the
2960 * whole header but simply check for the availability of that array
2961 * of characters inside the header. Not fully fool-proof, but good
2963 for (n = 4 + size; n <= 4 + size + total - doctype_len; n++)
2964 if (!memcmp (&data[n], doctype, doctype_len))
2970 /*** video/x-matroska ***/
2971 static GstStaticCaps matroska_caps = GST_STATIC_CAPS ("video/x-matroska");
2973 #define MATROSKA_CAPS (gst_static_caps_get(&matroska_caps))
2975 matroska_type_find (GstTypeFind * tf, gpointer ununsed)
2977 if (ebml_check_header (tf, "matroska", 8))
2978 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MATROSKA_CAPS);
2981 /*** video/webm ***/
2982 static GstStaticCaps webm_caps = GST_STATIC_CAPS ("video/webm");
2984 #define WEBM_CAPS (gst_static_caps_get(&webm_caps))
2986 webm_type_find (GstTypeFind * tf, gpointer ununsed)
2988 if (ebml_check_header (tf, "webm", 4))
2989 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, WEBM_CAPS);
2992 /*** application/mxf ***/
2993 static GstStaticCaps mxf_caps = GST_STATIC_CAPS ("application/mxf");
2995 #define MXF_MAX_PROBE_LENGTH (1024 * 64)
2996 #define MXF_CAPS (gst_static_caps_get(&mxf_caps))
2999 * MXF files start with a header partition pack key of 16 bytes which is defined
3000 * at SMPTE-377M 6.1. Before this there can be up to 64K of run-in which _must_
3001 * not contain the partition pack key.
3004 mxf_type_find (GstTypeFind * tf, gpointer ununsed)
3006 static const guint8 partition_pack_key[] =
3007 { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
3010 DataScanCtx c = { 0, NULL, 0 };
3012 while (c.offset <= MXF_MAX_PROBE_LENGTH) {
3014 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 1024)))
3017 /* look over in chunks of 1kbytes to avoid too much overhead */
3019 for (i = 0; i < 1024 - 16; i++) {
3020 /* Check first byte before calling more expensive memcmp function */
3021 if (G_UNLIKELY (c.data[i] == 0x06
3022 && memcmp (c.data + i, partition_pack_key, 13) == 0)) {
3023 /* Header partition pack? */
3024 if (c.data[i + 13] != 0x02)
3027 /* Partition status */
3028 if (c.data[i + 14] >= 0x05)
3031 /* Reserved, must be 0x00 */
3032 if (c.data[i + 15] != 0x00)
3035 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
3041 data_scan_ctx_advance (tf, &c, 1024 - 16);
3045 /*** video/x-dv ***/
3047 static GstStaticCaps dv_caps = GST_STATIC_CAPS ("video/x-dv, "
3048 "systemstream = (boolean) true");
3049 #define DV_CAPS (gst_static_caps_get(&dv_caps))
3051 dv_type_find (GstTypeFind * tf, gpointer private)
3055 data = gst_type_find_peek (tf, 0, 5);
3057 /* check for DIF and DV flag */
3058 if (data && (data[0] == 0x1f) && (data[1] == 0x07) && (data[2] == 0x00)) {
3059 const gchar *format;
3061 if (data[3] & 0x80) {
3067 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "video/x-dv",
3068 "systemstream", G_TYPE_BOOLEAN, TRUE,
3069 "format", G_TYPE_STRING, format, NULL);
3074 /*** application/ogg and application/x-annodex ***/
3075 static GstStaticCaps ogg_caps = GST_STATIC_CAPS ("application/ogg");
3076 static GstStaticCaps annodex_caps = GST_STATIC_CAPS ("application/x-annodex");
3077 static GstStaticCaps ogg_annodex_caps =
3078 GST_STATIC_CAPS ("application/ogg;application/x-annodex");
3080 #define OGGANX_CAPS (gst_static_caps_get(&ogg_annodex_caps))
3083 ogganx_type_find (GstTypeFind * tf, gpointer private)
3085 guint8 *data = gst_type_find_peek (tf, 0, 4);
3087 if ((data != NULL) && (memcmp (data, "OggS", 4) == 0)) {
3089 /* Check for an annodex fishbone header */
3090 data = gst_type_find_peek (tf, 28, 8);
3091 if (data && memcmp (data, "fishead\0", 8) == 0)
3092 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
3093 gst_static_caps_get (&annodex_caps));
3095 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
3096 gst_static_caps_get (&ogg_caps));
3100 /*** audio/x-vorbis ***/
3101 static GstStaticCaps vorbis_caps = GST_STATIC_CAPS ("audio/x-vorbis");
3103 #define VORBIS_CAPS (gst_static_caps_get(&vorbis_caps))
3105 vorbis_type_find (GstTypeFind * tf, gpointer private)
3107 guint8 *data = gst_type_find_peek (tf, 0, 30);
3113 /* 1 byte packet type (identification=0x01)
3114 6 byte string "vorbis"
3115 4 byte vorbis version */
3116 if (memcmp (data, "\001vorbis\000\000\000\000", 11) != 0)
3119 /* 1 byte channels must be != 0 */
3123 /* 4 byte samplerate must be != 0 */
3124 if (GST_READ_UINT32_LE (data) == 0)
3127 /* blocksize checks */
3128 blocksize_0 = data[0] & 0x0F;
3129 blocksize_1 = (data[0] & 0xF0) >> 4;
3130 if (blocksize_0 > blocksize_1)
3132 if (blocksize_0 < 6 || blocksize_0 > 13)
3134 if (blocksize_1 < 6 || blocksize_1 > 13)
3138 if ((data[0] & 0x01) != 1)
3140 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VORBIS_CAPS);
3144 /*** video/x-theora ***/
3146 static GstStaticCaps theora_caps = GST_STATIC_CAPS ("video/x-theora");
3148 #define THEORA_CAPS (gst_static_caps_get(&theora_caps))
3150 theora_type_find (GstTypeFind * tf, gpointer private)
3152 guint8 *data = gst_type_find_peek (tf, 0, 7); //42);
3155 if (data[0] != 0x80)
3157 if (memcmp (&data[1], "theora", 6) != 0)
3159 /* FIXME: make this more reliable when specs are out */
3161 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, THEORA_CAPS);
3167 kate_type_find (GstTypeFind * tf, gpointer private)
3169 guint8 *data = gst_type_find_peek (tf, 0, 64);
3170 gchar category[16] = { 0, };
3172 if (G_UNLIKELY (data == NULL))
3175 /* see: http://wiki.xiph.org/index.php/OggKate#Format_specification */
3176 if (G_LIKELY (memcmp (data, "\200kate\0\0\0", 8) != 0))
3179 /* make sure we always have a NUL-terminated string */
3180 memcpy (category, data + 48, 15);
3181 GST_LOG ("kate category: %s", category);
3182 /* canonical categories for subtitles: subtitles, spu-subtitles, SUB, K-SPU */
3183 if (strcmp (category, "subtitles") == 0 || strcmp (category, "SUB") == 0 ||
3184 strcmp (category, "spu-subtitles") == 0 ||
3185 strcmp (category, "K-SPU") == 0) {
3186 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3187 "subtitle/x-kate", NULL);
3189 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3190 "application/x-kate", NULL);
3194 /*** application/x-ogm-video or audio***/
3196 static GstStaticCaps ogmvideo_caps =
3197 GST_STATIC_CAPS ("application/x-ogm-video");
3198 #define OGMVIDEO_CAPS (gst_static_caps_get(&ogmvideo_caps))
3200 ogmvideo_type_find (GstTypeFind * tf, gpointer private)
3202 guint8 *data = gst_type_find_peek (tf, 0, 9);
3205 if (memcmp (data, "\001video\000\000\000", 9) != 0)
3207 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMVIDEO_CAPS);
3211 static GstStaticCaps ogmaudio_caps =
3212 GST_STATIC_CAPS ("application/x-ogm-audio");
3213 #define OGMAUDIO_CAPS (gst_static_caps_get(&ogmaudio_caps))
3215 ogmaudio_type_find (GstTypeFind * tf, gpointer private)
3217 guint8 *data = gst_type_find_peek (tf, 0, 9);
3220 if (memcmp (data, "\001audio\000\000\000", 9) != 0)
3222 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMAUDIO_CAPS);
3226 static GstStaticCaps ogmtext_caps = GST_STATIC_CAPS ("application/x-ogm-text");
3228 #define OGMTEXT_CAPS (gst_static_caps_get(&ogmtext_caps))
3230 ogmtext_type_find (GstTypeFind * tf, gpointer private)
3232 guint8 *data = gst_type_find_peek (tf, 0, 9);
3235 if (memcmp (data, "\001text\000\000\000\000", 9) != 0)
3237 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMTEXT_CAPS);
3241 /*** audio/x-speex ***/
3243 static GstStaticCaps speex_caps = GST_STATIC_CAPS ("audio/x-speex");
3245 #define SPEEX_CAPS (gst_static_caps_get(&speex_caps))
3247 speex_type_find (GstTypeFind * tf, gpointer private)
3249 guint8 *data = gst_type_find_peek (tf, 0, 80);
3252 /* 8 byte string "Speex "
3253 24 byte speex version string + int */
3254 if (memcmp (data, "Speex ", 8) != 0)
3258 /* 4 byte header size >= 80 */
3259 if (GST_READ_UINT32_LE (data) < 80)
3263 /* 4 byte sample rate <= 48000 */
3264 if (GST_READ_UINT32_LE (data) > 48000)
3268 /* currently there are only 3 speex modes. */
3269 if (GST_READ_UINT32_LE (data) > 3)
3273 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SPEEX_CAPS);
3277 /*** audio/x-celt ***/
3279 static GstStaticCaps celt_caps = GST_STATIC_CAPS ("audio/x-celt");
3281 #define CELT_CAPS (gst_static_caps_get(&celt_caps))
3283 celt_type_find (GstTypeFind * tf, gpointer private)
3285 guint8 *data = gst_type_find_peek (tf, 0, 8);
3288 /* 8 byte string "CELT " */
3289 if (memcmp (data, "CELT ", 8) != 0)
3292 /* TODO: Check other values of the CELT header */
3293 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CELT_CAPS);
3297 /*** application/x-ogg-skeleton ***/
3298 static GstStaticCaps ogg_skeleton_caps =
3299 GST_STATIC_CAPS ("application/x-ogg-skeleton, parsed=(boolean)FALSE");
3300 #define OGG_SKELETON_CAPS (gst_static_caps_get(&ogg_skeleton_caps))
3302 oggskel_type_find (GstTypeFind * tf, gpointer private)
3304 guint8 *data = gst_type_find_peek (tf, 0, 12);
3307 /* 8 byte string "fishead\0" for the ogg skeleton stream */
3308 if (memcmp (data, "fishead\0", 8) != 0)
3312 /* Require that the header contains version 3.0 */
3313 if (GST_READ_UINT16_LE (data) != 3)
3316 if (GST_READ_UINT16_LE (data) != 0)
3319 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGG_SKELETON_CAPS);
3323 static GstStaticCaps cmml_caps = GST_STATIC_CAPS ("text/x-cmml");
3325 #define CMML_CAPS (gst_static_caps_get(&cmml_caps))
3327 cmml_type_find (GstTypeFind * tf, gpointer private)
3329 /* Header is 12 bytes minimum (though we don't check the minor version */
3330 guint8 *data = gst_type_find_peek (tf, 0, 12);
3334 /* 8 byte string "CMML\0\0\0\0" for the magic number */
3335 if (memcmp (data, "CMML\0\0\0\0", 8) != 0)
3339 /* Require that the header contains at least version 2.0 */
3340 if (GST_READ_UINT16_LE (data) < 2)
3343 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CMML_CAPS);
3347 /*** application/x-tar ***/
3349 static GstStaticCaps tar_caps = GST_STATIC_CAPS ("application/x-tar");
3351 #define TAR_CAPS (gst_static_caps_get(&tar_caps))
3352 #define OLDGNU_MAGIC "ustar " /* 7 chars and a NUL */
3353 #define NEWGNU_MAGIC "ustar" /* 5 chars and a NUL */
3355 tar_type_find (GstTypeFind * tf, gpointer unused)
3357 guint8 *data = gst_type_find_peek (tf, 257, 8);
3359 /* of course we are not certain, but we don't want other typefind funcs
3360 * to detect formats of files within the tar archive, e.g. mp3s */
3362 if (memcmp (data, OLDGNU_MAGIC, 8) == 0) { /* sic */
3363 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3364 } else if (memcmp (data, NEWGNU_MAGIC, 6) == 0 && /* sic */
3365 g_ascii_isdigit (data[6]) && g_ascii_isdigit (data[7])) {
3366 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3371 /*** application/x-ar ***/
3373 static GstStaticCaps ar_caps = GST_STATIC_CAPS ("application/x-ar");
3375 #define AR_CAPS (gst_static_caps_get(&ar_caps))
3377 ar_type_find (GstTypeFind * tf, gpointer unused)
3379 guint8 *data = gst_type_find_peek (tf, 0, 24);
3381 if (data && memcmp (data, "!<arch>", 7) == 0) {
3384 for (i = 7; i < 24; ++i) {
3385 if (!g_ascii_isprint (data[i]) && data[i] != '\n') {
3386 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AR_CAPS);
3390 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AR_CAPS);
3394 /*** audio/x-au ***/
3396 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3397 * as it is only possible to register one typefind factory per 'name'
3398 * (which is in this case the caps), and the first one would be replaced by
3399 * the second one. */
3400 static GstStaticCaps au_caps = GST_STATIC_CAPS ("audio/x-au");
3402 #define AU_CAPS (gst_static_caps_get(&au_caps))
3404 au_type_find (GstTypeFind * tf, gpointer unused)
3406 guint8 *data = gst_type_find_peek (tf, 0, 4);
3409 if (memcmp (data, ".snd", 4) == 0 || memcmp (data, "dns.", 4) == 0) {
3410 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AU_CAPS);
3416 /*** video/x-nuv ***/
3418 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3419 * as it is only possible to register one typefind factory per 'name'
3420 * (which is in this case the caps), and the first one would be replaced by
3421 * the second one. */
3422 static GstStaticCaps nuv_caps = GST_STATIC_CAPS ("video/x-nuv");
3424 #define NUV_CAPS (gst_static_caps_get(&nuv_caps))
3426 nuv_type_find (GstTypeFind * tf, gpointer unused)
3428 guint8 *data = gst_type_find_peek (tf, 0, 11);
3431 if (memcmp (data, "MythTVVideo", 11) == 0
3432 || memcmp (data, "NuppelVideo", 11) == 0) {
3433 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, NUV_CAPS);
3438 /*** audio/x-paris ***/
3439 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3440 static GstStaticCaps paris_caps = GST_STATIC_CAPS ("audio/x-paris");
3442 #define PARIS_CAPS (gst_static_caps_get(&paris_caps))
3444 paris_type_find (GstTypeFind * tf, gpointer unused)
3446 guint8 *data = gst_type_find_peek (tf, 0, 4);
3449 if (memcmp (data, " paf", 4) == 0 || memcmp (data, "fap ", 4) == 0) {
3450 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, PARIS_CAPS);
3455 /*** audio/iLBC-sh ***/
3456 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3457 static GstStaticCaps ilbc_caps = GST_STATIC_CAPS ("audio/iLBC-sh");
3459 #define ILBC_CAPS (gst_static_caps_get(&ilbc_caps))
3461 ilbc_type_find (GstTypeFind * tf, gpointer unused)
3463 guint8 *data = gst_type_find_peek (tf, 0, 8);
3466 if (memcmp (data, "#!iLBC30", 8) == 0 || memcmp (data, "#!iLBC20", 8) == 0) {
3467 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, ILBC_CAPS);
3472 /*** application/x-ms-dos-executable ***/
3474 static GstStaticCaps msdos_caps =
3475 GST_STATIC_CAPS ("application/x-ms-dos-executable");
3476 #define MSDOS_CAPS (gst_static_caps_get(&msdos_caps))
3477 /* see http://www.madchat.org/vxdevl/papers/winsys/pefile/pefile.htm */
3479 msdos_type_find (GstTypeFind * tf, gpointer unused)
3481 guint8 *data = gst_type_find_peek (tf, 0, 64);
3483 if (data && data[0] == 'M' && data[1] == 'Z' &&
3484 GST_READ_UINT16_LE (data + 8) == 4) {
3485 guint32 pe_offset = GST_READ_UINT32_LE (data + 60);
3487 data = gst_type_find_peek (tf, pe_offset, 2);
3488 if (data && data[0] == 'P' && data[1] == 'E') {
3489 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, MSDOS_CAPS);
3494 /*** application/x-mmsh ***/
3496 static GstStaticCaps mmsh_caps = GST_STATIC_CAPS ("application/x-mmsh");
3498 #define MMSH_CAPS gst_static_caps_get(&mmsh_caps)
3500 /* This is to recognise mssh-over-http */
3502 mmsh_type_find (GstTypeFind * tf, gpointer unused)
3504 static const guint8 asf_marker[16] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66,
3505 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
3510 data = gst_type_find_peek (tf, 0, 2 + 2 + 4 + 2 + 2 + 16);
3511 if (data && data[0] == 0x24 && data[1] == 0x48 &&
3512 GST_READ_UINT16_LE (data + 2) > 2 + 2 + 4 + 2 + 2 + 16 &&
3513 memcmp (data + 2 + 2 + 4 + 2 + 2, asf_marker, 16) == 0) {
3514 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MMSH_CAPS);
3518 /*** video/x-dirac ***/
3520 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3521 * as it is only possible to register one typefind factory per 'name'
3522 * (which is in this case the caps), and the first one would be replaced by
3523 * the second one. */
3524 static GstStaticCaps dirac_caps = GST_STATIC_CAPS ("video/x-dirac");
3526 #define DIRAC_CAPS (gst_static_caps_get(&dirac_caps))
3528 dirac_type_find (GstTypeFind * tf, gpointer unused)
3530 guint8 *data = gst_type_find_peek (tf, 0, 8);
3533 if (memcmp (data, "BBCD", 4) == 0 || memcmp (data, "KW-DIRAC", 8) == 0) {
3534 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DIRAC_CAPS);
3539 /*** video/vivo ***/
3541 static GstStaticCaps vivo_caps = GST_STATIC_CAPS ("video/vivo");
3543 #define VIVO_CAPS gst_static_caps_get(&vivo_caps)
3546 vivo_type_find (GstTypeFind * tf, gpointer unused)
3548 static const guint8 vivo_marker[] = { 'V', 'e', 'r', 's', 'i', 'o', 'n',
3549 ':', 'V', 'i', 'v', 'o', '/'
3554 data = gst_type_find_peek (tf, 0, 1024);
3555 if (data == NULL || data[0] != 0x00)
3558 if ((data[1] & 0x80)) {
3559 if ((data[2] & 0x80))
3561 hdr_len = ((guint) (data[1] & 0x7f)) << 7;
3571 /* 1008 = 1022 - strlen ("Version:Vivo/") - 1 */
3572 while (pos < 1008 && data[pos] == '\r' && data[pos + 1] == '\n')
3575 if (memcmp (data + pos, vivo_marker, sizeof (vivo_marker)) == 0) {
3576 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VIVO_CAPS);
3580 /*** XDG MIME typefinder (to avoid false positives mostly) ***/
3584 xdgmime_typefind (GstTypeFind * find, gpointer user_data)
3587 gsize length = 16384;
3592 if ((tf_length = gst_type_find_get_length (find)) > 0)
3593 length = MIN (length, tf_length);
3595 if ((data = gst_type_find_peek (find, 0, length)) == NULL)
3598 tmp = g_content_type_guess (NULL, data, length, NULL);
3599 if (tmp == NULL || g_content_type_is_unknown (tmp)) {
3604 mimetype = g_content_type_get_mime_type (tmp);
3607 if (mimetype == NULL)
3610 GST_DEBUG ("Got mimetype '%s'", mimetype);
3612 /* Ignore audio/video types:
3613 * - our own typefinders in -base are likely to be better at this
3614 * (and if they're not, we really want to fix them, that's why we don't
3615 * report xdg-detected audio/video types at all, not even with a low
3617 * - we want to detect GStreamer media types and not MIME types
3618 * - the purpose of this xdg mime finder is mainly to prevent false
3619 * positives of non-media formats, not to typefind audio/video formats */
3620 if (g_str_has_prefix (mimetype, "audio/") ||
3621 g_str_has_prefix (mimetype, "video/")) {
3622 GST_LOG ("Ignoring audio/video mime type");
3627 /* Again, we mainly want the xdg typefinding to prevent false-positives on
3628 * non-media formats, so suggest the type with a probability that trumps
3629 * uncertain results of our typefinders, but not more than that. */
3630 GST_LOG ("Suggesting '%s' with probability POSSIBLE", mimetype);
3631 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE, mimetype, NULL);
3634 #endif /* USE_GIO */
3636 /*** generic typefind for streams that have some data at a specific position***/
3647 start_with_type_find (GstTypeFind * tf, gpointer private)
3649 GstTypeFindData *start_with = (GstTypeFindData *) private;
3652 GST_LOG ("trying to find mime type %s with the first %u bytes of data",
3653 gst_structure_get_name (gst_caps_get_structure (start_with->caps, 0)),
3655 data = gst_type_find_peek (tf, 0, start_with->size);
3656 if (data && memcmp (data, start_with->data, start_with->size) == 0) {
3657 gst_type_find_suggest (tf, start_with->probability, start_with->caps);
3662 sw_data_destroy (GstTypeFindData * sw_data)
3664 if (G_LIKELY (sw_data->caps != NULL))
3665 gst_caps_unref (sw_data->caps);
3669 #define TYPE_FIND_REGISTER_START_WITH(plugin,name,rank,ext,_data,_size,_probability)\
3671 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
3672 sw_data->data = (const guint8 *)_data; \
3673 sw_data->size = _size; \
3674 sw_data->probability = _probability; \
3675 sw_data->caps = gst_caps_new_simple (name, NULL); \
3676 if (!gst_type_find_register (plugin, name, rank, start_with_type_find,\
3677 (char **) ext, sw_data->caps, sw_data, \
3678 (GDestroyNotify) (sw_data_destroy))) { \
3679 gst_caps_unref (sw_data->caps); \
3684 /*** same for riff types ***/
3687 riff_type_find (GstTypeFind * tf, gpointer private)
3689 GstTypeFindData *riff_data = (GstTypeFindData *) private;
3690 guint8 *data = gst_type_find_peek (tf, 0, 12);
3692 if (data && (memcmp (data, "RIFF", 4) == 0 || memcmp (data, "AVF0", 4) == 0)) {
3694 if (memcmp (data, riff_data->data, 4) == 0)
3695 gst_type_find_suggest (tf, riff_data->probability, riff_data->caps);
3699 #define TYPE_FIND_REGISTER_RIFF(plugin,name,rank,ext,_data) \
3701 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
3702 sw_data->data = (gpointer)_data; \
3703 sw_data->size = 4; \
3704 sw_data->probability = GST_TYPE_FIND_MAXIMUM; \
3705 sw_data->caps = gst_caps_new_simple (name, NULL); \
3706 if (!gst_type_find_register (plugin, name, rank, riff_type_find, \
3707 (char **) ext, sw_data->caps, sw_data, \
3708 (GDestroyNotify) (sw_data_destroy))) { \
3709 gst_caps_unref (sw_data->caps); \
3715 /*** plugin initialization ***/
3717 #define TYPE_FIND_REGISTER(plugin,name,rank,func,ext,caps,priv,notify) \
3719 if (!gst_type_find_register (plugin, name, rank, func, (char **) ext, caps, priv, notify))\
3725 plugin_init (GstPlugin * plugin)
3727 /* can't initialize this via a struct as caps can't be statically initialized */
3729 /* note: asx/wax/wmx are XML files, asf doesn't handle them */
3730 /* FIXME-0.11: these should be const,
3731 this requires gstreamer/gst/gsttypefind::gst_type_find_register()
3732 to have define the parameter as const
3734 static const gchar *asf_exts[] = { "asf", "wm", "wma", "wmv", NULL };
3735 static const gchar *au_exts[] = { "au", "snd", NULL };
3736 static const gchar *avi_exts[] = { "avi", NULL };
3737 static const gchar *qcp_exts[] = { "qcp", NULL };
3738 static const gchar *cdxa_exts[] = { "dat", NULL };
3739 static const gchar *flac_exts[] = { "flac", NULL };
3740 static const gchar *flx_exts[] = { "flc", "fli", NULL };
3741 static const gchar *id3_exts[] =
3742 { "mp3", "mp2", "mp1", "mpga", "ogg", "flac", "tta", NULL };
3743 static const gchar *apetag_exts[] = { "ape", "mpc", "wv", NULL }; /* and mp3 and wav? */
3744 static const gchar *tta_exts[] = { "tta", NULL };
3745 static const gchar *mod_exts[] = { "669", "amf", "dsm", "gdm", "far", "imf",
3746 "it", "med", "mod", "mtm", "okt", "sam",
3747 "s3m", "stm", "stx", "ult", "xm", NULL
3749 static const gchar *mp3_exts[] = { "mp3", "mp2", "mp1", "mpga", NULL };
3750 static const gchar *ac3_exts[] = { "ac3", NULL };
3751 static const gchar *gsm_exts[] = { "gsm", NULL };
3752 static const gchar *musepack_exts[] = { "mpc", "mpp", "mp+", NULL };
3753 static const gchar *mpeg_sys_exts[] = { "mpe", "mpeg", "mpg", NULL };
3754 static const gchar *mpeg_video_exts[] = { "mpv", "mpeg", "mpg", NULL };
3755 static const gchar *mpeg_ts_exts[] = { "ts", NULL };
3756 static const gchar *ogg_exts[] = { "anx", "ogg", "ogm", NULL };
3757 static const gchar *qt_exts[] = { "mov", NULL };
3758 static const gchar *qtif_exts[] = { "qif", "qtif", "qti", NULL };
3759 static const gchar *mj2_exts[] = { "mj2", NULL };
3760 static const gchar *jp2_exts[] = { "jp2", NULL };
3761 static const gchar *rm_exts[] = { "ra", "ram", "rm", "rmvb", NULL };
3762 static const gchar *swf_exts[] = { "swf", "swfl", NULL };
3763 static const gchar *utf8_exts[] = { "txt", NULL };
3764 static const gchar *wav_exts[] = { "wav", NULL };
3765 static const gchar *aiff_exts[] = { "aiff", "aif", "aifc", NULL };
3766 static const gchar *svx_exts[] = { "iff", "svx", NULL };
3767 static const gchar *paris_exts[] = { "paf", NULL };
3768 static const gchar *nist_exts[] = { "nist", NULL };
3769 static const gchar *voc_exts[] = { "voc", NULL };
3770 static const gchar *sds_exts[] = { "sds", NULL };
3771 static const gchar *ircam_exts[] = { "sf", NULL };
3772 static const gchar *w64_exts[] = { "w64", NULL };
3773 static const gchar *shn_exts[] = { "shn", NULL };
3774 static const gchar *ape_exts[] = { "ape", NULL };
3775 static const gchar *uri_exts[] = { "ram", NULL };
3776 static const gchar *sdp_exts[] = { "sdp", NULL };
3777 static const gchar *smil_exts[] = { "smil", NULL };
3778 static const gchar *html_exts[] = { "htm", "html", NULL };
3779 static const gchar *xml_exts[] = { "xml", NULL };
3780 static const gchar *jpeg_exts[] = { "jpg", "jpe", "jpeg", NULL };
3781 static const gchar *gif_exts[] = { "gif", NULL };
3782 static const gchar *png_exts[] = { "png", NULL };
3783 static const gchar *bmp_exts[] = { "bmp", NULL };
3784 static const gchar *tiff_exts[] = { "tif", "tiff", NULL };
3785 static const gchar *matroska_exts[] = { "mkv", "mka", NULL };
3786 static const gchar *webm_exts[] = { "webm", "weba", "webv", NULL };
3787 static const gchar *mve_exts[] = { "mve", NULL };
3788 static const gchar *dv_exts[] = { "dv", "dif", NULL };
3789 static const gchar *amr_exts[] = { "amr", NULL };
3790 static const gchar *ilbc_exts[] = { "ilbc", NULL };
3791 static const gchar *sid_exts[] = { "sid", NULL };
3792 static const gchar *xcf_exts[] = { "xcf", NULL };
3793 static const gchar *mng_exts[] = { "mng", NULL };
3794 static const gchar *jng_exts[] = { "jng", NULL };
3795 static const gchar *xpm_exts[] = { "xpm", NULL };
3796 static const gchar *pnm_exts[] = { "pnm", "ppm", "pgm", "pbm", NULL };
3797 static const gchar *ras_exts[] = { "ras", NULL };
3798 static const gchar *bz2_exts[] = { "bz2", NULL };
3799 static const gchar *gz_exts[] = { "gz", NULL };
3800 static const gchar *zip_exts[] = { "zip", NULL };
3801 static const gchar *compress_exts[] = { "Z", NULL };
3802 static const gchar *m4a_exts[] = { "m4a", NULL };
3803 static const gchar *q3gp_exts[] = { "3gp", NULL };
3804 static const gchar *aac_exts[] = { "aac", NULL };
3805 static const gchar *spc_exts[] = { "spc", NULL };
3806 static const gchar *wavpack_exts[] = { "wv", "wvp", NULL };
3807 static const gchar *wavpack_correction_exts[] = { "wvc", NULL };
3808 static const gchar *rar_exts[] = { "rar", NULL };
3809 static const gchar *tar_exts[] = { "tar", NULL };
3810 static const gchar *ar_exts[] = { "a", NULL };
3811 static const gchar *msdos_exts[] = { "dll", "exe", "ocx", "sys", "scr",
3812 "msstyles", "cpl", NULL
3814 static const gchar *flv_exts[] = { "flv", NULL };
3815 static const gchar *m4v_exts[] = { "m4v", NULL };
3816 static const gchar *h264_exts[] = { "h264", "x264", "264", NULL };
3817 static const gchar *nuv_exts[] = { "nuv", NULL };
3818 static const gchar *vivo_exts[] = { "viv", NULL };
3819 static const gchar *nsf_exts[] = { "nsf", NULL };
3820 static const gchar *gym_exts[] = { "gym", NULL };
3821 static const gchar *ay_exts[] = { "ay", NULL };
3822 static const gchar *gbs_exts[] = { "gbs", NULL };
3823 static const gchar *kss_exts[] = { "kss", NULL };
3824 static const gchar *sap_exts[] = { "sap", NULL };
3825 static const gchar *vgm_exts[] = { "vgm", NULL };
3826 static const gchar *mid_exts[] = { "mid", "midi", NULL };
3827 static const gchar *mxmf_exts[] = { "mxmf", NULL };
3828 static const gchar *imelody_exts[] = { "imy", "ime", "imelody", NULL };
3829 static const gchar *pdf_exts[] = { "pdf", NULL };
3830 static const gchar *ps_exts[] = { "ps", NULL };
3831 static const gchar *svg_exts[] = { "svg", NULL };
3832 static const gchar *mxf_exts[] = { "mxf", NULL };
3833 static const gchar *ivf_exts[] = { "ivf", NULL };
3834 static const gchar *msword_exts[] = { "doc", NULL };
3835 static const gchar *dsstore_exts[] = { "DS_Store", NULL };
3836 static const gchar *psd_exts[] = { "psd", NULL };
3838 GST_DEBUG_CATEGORY_INIT (type_find_debug, "typefindfunctions",
3839 GST_DEBUG_FG_GREEN | GST_DEBUG_BG_RED, "generic type find functions");
3841 /* must use strings, macros don't accept initializers */
3842 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ms-asf", GST_RANK_SECONDARY,
3844 "\060\046\262\165\216\146\317\021\246\331\000\252\000\142\316\154", 16,
3845 GST_TYPE_FIND_MAXIMUM);
3846 TYPE_FIND_REGISTER (plugin, "audio/x-musepack", GST_RANK_PRIMARY,
3847 musepack_type_find, musepack_exts, MUSEPACK_CAPS, NULL, NULL);
3848 TYPE_FIND_REGISTER (plugin, "audio/x-au", GST_RANK_MARGINAL,
3849 au_type_find, au_exts, AU_CAPS, NULL, NULL);
3850 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-msvideo", GST_RANK_PRIMARY,
3852 TYPE_FIND_REGISTER_RIFF (plugin, "audio/qcelp", GST_RANK_PRIMARY,
3854 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-cdxa", GST_RANK_PRIMARY,
3856 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-vcd", GST_RANK_PRIMARY,
3857 cdxa_exts, "\000\377\377\377\377\377\377\377\377\377\377\000", 12,
3858 GST_TYPE_FIND_MAXIMUM);
3859 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-imelody", GST_RANK_PRIMARY,
3860 imelody_exts, "BEGIN:IMELODY", 13, GST_TYPE_FIND_MAXIMUM);
3862 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-smoke", GST_RANK_PRIMARY,
3863 NULL, "\x80smoke\x00\x01\x00", 6, GST_TYPE_FIND_MAXIMUM);
3865 TYPE_FIND_REGISTER (plugin, "audio/midi", GST_RANK_PRIMARY, mid_type_find,
3866 mid_exts, MID_CAPS, NULL, NULL);
3867 TYPE_FIND_REGISTER_RIFF (plugin, "audio/riff-midi", GST_RANK_PRIMARY,
3869 TYPE_FIND_REGISTER (plugin, "audio/mobile-xmf", GST_RANK_PRIMARY,
3870 mxmf_type_find, mxmf_exts, MXMF_CAPS, NULL, NULL);
3871 TYPE_FIND_REGISTER (plugin, "video/x-fli", GST_RANK_MARGINAL, flx_type_find,
3872 flx_exts, FLX_CAPS, NULL, NULL);
3873 TYPE_FIND_REGISTER (plugin, "application/x-id3v2", GST_RANK_PRIMARY + 103,
3874 id3v2_type_find, id3_exts, ID3_CAPS, NULL, NULL);
3875 TYPE_FIND_REGISTER (plugin, "application/x-id3v1", GST_RANK_PRIMARY + 101,
3876 id3v1_type_find, id3_exts, ID3_CAPS, NULL, NULL);
3877 TYPE_FIND_REGISTER (plugin, "application/x-apetag", GST_RANK_PRIMARY + 102,
3878 apetag_type_find, apetag_exts, APETAG_CAPS, NULL, NULL);
3879 TYPE_FIND_REGISTER (plugin, "audio/x-ttafile", GST_RANK_PRIMARY,
3880 tta_type_find, tta_exts, TTA_CAPS, NULL, NULL);
3881 TYPE_FIND_REGISTER (plugin, "audio/x-mod", GST_RANK_SECONDARY, mod_type_find,
3882 mod_exts, MOD_CAPS, NULL, NULL);
3883 TYPE_FIND_REGISTER (plugin, "audio/mpeg", GST_RANK_PRIMARY, mp3_type_find,
3884 mp3_exts, MP3_CAPS, NULL, NULL);
3885 TYPE_FIND_REGISTER (plugin, "audio/x-ac3", GST_RANK_PRIMARY, ac3_type_find,
3886 ac3_exts, AC3_CAPS, NULL, NULL);
3887 TYPE_FIND_REGISTER (plugin, "audio/x-gsm", GST_RANK_PRIMARY, NULL, gsm_exts,
3888 GSM_CAPS, NULL, NULL);
3889 TYPE_FIND_REGISTER (plugin, "video/mpeg-sys", GST_RANK_PRIMARY,
3890 mpeg_sys_type_find, mpeg_sys_exts, MPEG_SYS_CAPS, NULL, NULL);
3891 TYPE_FIND_REGISTER (plugin, "video/mpegts", GST_RANK_PRIMARY,
3892 mpeg_ts_type_find, mpeg_ts_exts, MPEGTS_CAPS, NULL, NULL);
3893 TYPE_FIND_REGISTER (plugin, "application/ogg", GST_RANK_PRIMARY,
3894 ogganx_type_find, ogg_exts, OGGANX_CAPS, NULL, NULL);
3895 TYPE_FIND_REGISTER (plugin, "video/mpeg-elementary", GST_RANK_MARGINAL,
3896 mpeg_video_stream_type_find, mpeg_video_exts, MPEG_VIDEO_CAPS, NULL,
3898 TYPE_FIND_REGISTER (plugin, "video/mpeg4", GST_RANK_PRIMARY,
3899 mpeg4_video_type_find, m4v_exts, MPEG_VIDEO_CAPS, NULL, NULL);
3900 TYPE_FIND_REGISTER (plugin, "video/x-h264", GST_RANK_PRIMARY,
3901 h264_video_type_find, h264_exts, MPEG_VIDEO_CAPS, NULL, NULL);
3902 TYPE_FIND_REGISTER (plugin, "video/x-nuv", GST_RANK_SECONDARY, nuv_type_find,
3903 nuv_exts, NUV_CAPS, NULL, NULL);
3906 TYPE_FIND_REGISTER (plugin, "audio/x-m4a", GST_RANK_PRIMARY, m4a_type_find,
3907 m4a_exts, M4A_CAPS, NULL, NULL);
3908 TYPE_FIND_REGISTER (plugin, "application/x-3gp", GST_RANK_PRIMARY,
3909 q3gp_type_find, q3gp_exts, Q3GP_CAPS, NULL, NULL);
3910 TYPE_FIND_REGISTER (plugin, "video/quicktime", GST_RANK_SECONDARY,
3911 qt_type_find, qt_exts, QT_CAPS, NULL, NULL);
3912 TYPE_FIND_REGISTER (plugin, "image/x-quicktime", GST_RANK_SECONDARY,
3913 qtif_type_find, qtif_exts, QTIF_CAPS, NULL, NULL);
3914 TYPE_FIND_REGISTER (plugin, "image/jp2", GST_RANK_PRIMARY,
3915 jp2_type_find, jp2_exts, JP2_CAPS, NULL, NULL);
3916 TYPE_FIND_REGISTER (plugin, "video/mj2", GST_RANK_PRIMARY,
3917 jp2_type_find, mj2_exts, MJ2_CAPS, NULL, NULL);
3919 TYPE_FIND_REGISTER (plugin, "text/html", GST_RANK_SECONDARY, html_type_find,
3920 html_exts, HTML_CAPS, NULL, NULL);
3921 TYPE_FIND_REGISTER_START_WITH (plugin, "application/vnd.rn-realmedia",
3922 GST_RANK_SECONDARY, rm_exts, ".RMF", 4, GST_TYPE_FIND_MAXIMUM);
3923 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-pn-realaudio",
3924 GST_RANK_SECONDARY, rm_exts, ".ra\375", 4, GST_TYPE_FIND_MAXIMUM);
3925 TYPE_FIND_REGISTER (plugin, "application/x-shockwave-flash",
3926 GST_RANK_SECONDARY, swf_type_find, swf_exts, SWF_CAPS, NULL, NULL);
3927 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-flv", GST_RANK_SECONDARY,
3928 flv_exts, "FLV", 3, GST_TYPE_FIND_MAXIMUM);
3929 TYPE_FIND_REGISTER (plugin, "text/plain", GST_RANK_MARGINAL, utf8_type_find,
3930 utf8_exts, UTF8_CAPS, NULL, NULL);
3931 TYPE_FIND_REGISTER (plugin, "text/uri-list", GST_RANK_MARGINAL, uri_type_find,
3932 uri_exts, URI_CAPS, NULL, NULL);
3933 TYPE_FIND_REGISTER (plugin, "application/sdp", GST_RANK_SECONDARY,
3934 sdp_type_find, sdp_exts, SDP_CAPS, NULL, NULL);
3935 TYPE_FIND_REGISTER (plugin, "application/smil", GST_RANK_SECONDARY,
3936 smil_type_find, smil_exts, SMIL_CAPS, NULL, NULL);
3937 TYPE_FIND_REGISTER (plugin, "application/xml", GST_RANK_MARGINAL,
3938 xml_type_find, xml_exts, GENERIC_XML_CAPS, NULL, NULL);
3939 TYPE_FIND_REGISTER_RIFF (plugin, "audio/x-wav", GST_RANK_PRIMARY, wav_exts,
3941 TYPE_FIND_REGISTER (plugin, "audio/x-aiff", GST_RANK_SECONDARY,
3942 aiff_type_find, aiff_exts, AIFF_CAPS, NULL, NULL);
3943 TYPE_FIND_REGISTER (plugin, "audio/x-svx", GST_RANK_SECONDARY, svx_type_find,
3944 svx_exts, SVX_CAPS, NULL, NULL);
3945 TYPE_FIND_REGISTER (plugin, "audio/x-paris", GST_RANK_SECONDARY,
3946 paris_type_find, paris_exts, PARIS_CAPS, NULL, NULL);
3947 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nist", GST_RANK_SECONDARY,
3948 nist_exts, "NIST", 4, GST_TYPE_FIND_MAXIMUM);
3949 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-voc", GST_RANK_SECONDARY,
3950 voc_exts, "Creative", 8, GST_TYPE_FIND_MAXIMUM);
3951 TYPE_FIND_REGISTER (plugin, "audio/x-sds", GST_RANK_SECONDARY, sds_type_find,
3952 sds_exts, SDS_CAPS, NULL, NULL);
3953 TYPE_FIND_REGISTER (plugin, "audio/x-ircam", GST_RANK_SECONDARY,
3954 ircam_type_find, ircam_exts, IRCAM_CAPS, NULL, NULL);
3955 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-w64", GST_RANK_SECONDARY,
3956 w64_exts, "riff", 4, GST_TYPE_FIND_MAXIMUM);
3957 TYPE_FIND_REGISTER (plugin, "audio/x-shorten", GST_RANK_SECONDARY,
3958 shn_type_find, shn_exts, SHN_CAPS, NULL, NULL);
3959 TYPE_FIND_REGISTER (plugin, "application/x-ape", GST_RANK_SECONDARY,
3960 ape_type_find, ape_exts, APE_CAPS, NULL, NULL);
3961 TYPE_FIND_REGISTER (plugin, "image/jpeg", GST_RANK_PRIMARY + 15,
3962 jpeg_type_find, jpeg_exts, JPEG_CAPS, NULL, NULL);
3963 TYPE_FIND_REGISTER_START_WITH (plugin, "image/gif", GST_RANK_PRIMARY,
3964 gif_exts, "GIF8", 4, GST_TYPE_FIND_MAXIMUM);
3965 TYPE_FIND_REGISTER_START_WITH (plugin, "image/png", GST_RANK_PRIMARY + 14,
3966 png_exts, "\211PNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
3967 TYPE_FIND_REGISTER (plugin, "image/bmp", GST_RANK_PRIMARY, bmp_type_find,
3968 bmp_exts, BMP_CAPS, NULL, NULL);
3969 TYPE_FIND_REGISTER (plugin, "image/tiff", GST_RANK_PRIMARY, tiff_type_find,
3970 tiff_exts, TIFF_CAPS, NULL, NULL);
3971 TYPE_FIND_REGISTER (plugin, "image/x-portable-pixmap", GST_RANK_SECONDARY,
3972 pnm_type_find, pnm_exts, PNM_CAPS, NULL, NULL);
3973 TYPE_FIND_REGISTER (plugin, "video/x-matroska", GST_RANK_PRIMARY,
3974 matroska_type_find, matroska_exts, MATROSKA_CAPS, NULL, NULL);
3975 TYPE_FIND_REGISTER (plugin, "video/webm", GST_RANK_PRIMARY,
3976 webm_type_find, webm_exts, WEBM_CAPS, NULL, NULL);
3977 TYPE_FIND_REGISTER (plugin, "application/mxf", GST_RANK_PRIMARY,
3978 mxf_type_find, mxf_exts, MXF_CAPS, NULL, NULL);
3979 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mve", GST_RANK_SECONDARY,
3980 mve_exts, "Interplay MVE File\032\000\032\000\000\001\063\021", 26,
3981 GST_TYPE_FIND_MAXIMUM);
3982 TYPE_FIND_REGISTER (plugin, "video/x-dv", GST_RANK_SECONDARY, dv_type_find,
3983 dv_exts, DV_CAPS, NULL, NULL);
3984 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-nb-sh", GST_RANK_PRIMARY,
3985 amr_exts, "#!AMR", 5, GST_TYPE_FIND_LIKELY);
3986 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-wb-sh", GST_RANK_PRIMARY,
3987 amr_exts, "#!AMR-WB", 7, GST_TYPE_FIND_MAXIMUM);
3988 TYPE_FIND_REGISTER (plugin, "audio/iLBC-sh", GST_RANK_PRIMARY,
3989 ilbc_type_find, ilbc_exts, ILBC_CAPS, NULL, NULL);
3990 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sid", GST_RANK_MARGINAL,
3991 sid_exts, "PSID", 4, GST_TYPE_FIND_MAXIMUM);
3992 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xcf", GST_RANK_SECONDARY,
3993 xcf_exts, "gimp xcf", 8, GST_TYPE_FIND_MAXIMUM);
3994 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mng", GST_RANK_SECONDARY,
3995 mng_exts, "\212MNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
3996 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-jng", GST_RANK_SECONDARY,
3997 jng_exts, "\213JNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
3998 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xpixmap", GST_RANK_SECONDARY,
3999 xpm_exts, "/* XPM */", 9, GST_TYPE_FIND_MAXIMUM);
4000 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-sun-raster",
4001 GST_RANK_SECONDARY, ras_exts, "\131\246\152\225", 4,
4002 GST_TYPE_FIND_MAXIMUM);
4003 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-bzip",
4004 GST_RANK_SECONDARY, bz2_exts, "BZh", 3, GST_TYPE_FIND_LIKELY);
4005 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-gzip",
4006 GST_RANK_SECONDARY, gz_exts, "\037\213", 2, GST_TYPE_FIND_LIKELY);
4007 TYPE_FIND_REGISTER_START_WITH (plugin, "application/zip", GST_RANK_SECONDARY,
4008 zip_exts, "PK\003\004", 4, GST_TYPE_FIND_LIKELY);
4009 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-compress",
4010 GST_RANK_SECONDARY, compress_exts, "\037\235", 2, GST_TYPE_FIND_LIKELY);
4011 TYPE_FIND_REGISTER (plugin, "subtitle/x-kate", GST_RANK_MARGINAL,
4012 kate_type_find, NULL, NULL, NULL, NULL);
4013 TYPE_FIND_REGISTER (plugin, "audio/x-flac", GST_RANK_PRIMARY,
4014 flac_type_find, flac_exts, FLAC_CAPS, NULL, NULL);
4015 TYPE_FIND_REGISTER (plugin, "audio/x-vorbis", GST_RANK_PRIMARY,
4016 vorbis_type_find, NULL, VORBIS_CAPS, NULL, NULL);
4017 TYPE_FIND_REGISTER (plugin, "video/x-theora", GST_RANK_PRIMARY,
4018 theora_type_find, NULL, THEORA_CAPS, NULL, NULL);
4019 TYPE_FIND_REGISTER (plugin, "application/x-ogm-video", GST_RANK_PRIMARY,
4020 ogmvideo_type_find, NULL, OGMVIDEO_CAPS, NULL, NULL);
4021 TYPE_FIND_REGISTER (plugin, "application/x-ogm-audio", GST_RANK_PRIMARY,
4022 ogmaudio_type_find, NULL, OGMAUDIO_CAPS, NULL, NULL);
4023 TYPE_FIND_REGISTER (plugin, "application/x-ogm-text", GST_RANK_PRIMARY,
4024 ogmtext_type_find, NULL, OGMTEXT_CAPS, NULL, NULL);
4025 TYPE_FIND_REGISTER (plugin, "audio/x-speex", GST_RANK_PRIMARY,
4026 speex_type_find, NULL, SPEEX_CAPS, NULL, NULL);
4027 TYPE_FIND_REGISTER (plugin, "audio/x-celt", GST_RANK_PRIMARY,
4028 celt_type_find, NULL, CELT_CAPS, NULL, NULL);
4029 TYPE_FIND_REGISTER (plugin, "application/x-ogg-skeleton", GST_RANK_PRIMARY,
4030 oggskel_type_find, NULL, OGG_SKELETON_CAPS, NULL, NULL);
4031 TYPE_FIND_REGISTER (plugin, "text/x-cmml", GST_RANK_PRIMARY, cmml_type_find,
4032 NULL, CMML_CAPS, NULL, NULL);
4033 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-executable",
4034 GST_RANK_MARGINAL, NULL, "\177ELF", 4, GST_TYPE_FIND_MAXIMUM);
4035 TYPE_FIND_REGISTER (plugin, "adts_mpeg_stream", GST_RANK_SECONDARY,
4036 aac_type_find, aac_exts, AAC_CAPS, NULL, NULL);
4037 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-spc", GST_RANK_SECONDARY,
4038 spc_exts, "SNES-SPC700 Sound File Data", 27, GST_TYPE_FIND_MAXIMUM);
4039 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack", GST_RANK_SECONDARY,
4040 wavpack_type_find, wavpack_exts, WAVPACK_CAPS, NULL, NULL);
4041 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack-correction", GST_RANK_SECONDARY,
4042 wavpack_type_find, wavpack_correction_exts, WAVPACK_CORRECTION_CAPS, NULL,
4044 TYPE_FIND_REGISTER (plugin, "application/postscript", GST_RANK_SECONDARY,
4045 postscript_type_find, ps_exts, POSTSCRIPT_CAPS, NULL, NULL);
4046 TYPE_FIND_REGISTER (plugin, "image/svg+xml", GST_RANK_SECONDARY,
4047 svg_type_find, svg_exts, SVG_CAPS, NULL, NULL);
4048 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-rar",
4049 GST_RANK_SECONDARY, rar_exts, "Rar!", 4, GST_TYPE_FIND_LIKELY);
4050 TYPE_FIND_REGISTER (plugin, "application/x-tar", GST_RANK_SECONDARY,
4051 tar_type_find, tar_exts, TAR_CAPS, NULL, NULL);
4052 TYPE_FIND_REGISTER (plugin, "application/x-ar", GST_RANK_SECONDARY,
4053 ar_type_find, ar_exts, AR_CAPS, NULL, NULL);
4054 TYPE_FIND_REGISTER (plugin, "application/x-ms-dos-executable",
4055 GST_RANK_SECONDARY, msdos_type_find, msdos_exts, MSDOS_CAPS, NULL, NULL);
4056 TYPE_FIND_REGISTER (plugin, "video/x-dirac", GST_RANK_PRIMARY,
4057 dirac_type_find, NULL, DIRAC_CAPS, NULL, NULL);
4058 TYPE_FIND_REGISTER (plugin, "multipart/x-mixed-replace", GST_RANK_SECONDARY,
4059 multipart_type_find, NULL, MULTIPART_CAPS, NULL, NULL);
4060 TYPE_FIND_REGISTER (plugin, "application/x-mmsh", GST_RANK_SECONDARY,
4061 mmsh_type_find, NULL, MMSH_CAPS, NULL, NULL);
4062 TYPE_FIND_REGISTER (plugin, "video/vivo", GST_RANK_SECONDARY,
4063 vivo_type_find, vivo_exts, VIVO_CAPS, NULL, NULL);
4064 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nsf",
4065 GST_RANK_SECONDARY, nsf_exts, "NESM\x1a", 5, GST_TYPE_FIND_MAXIMUM);
4066 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gym",
4067 GST_RANK_SECONDARY, gym_exts, "GYMX", 4, GST_TYPE_FIND_MAXIMUM);
4068 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-ay",
4069 GST_RANK_SECONDARY, ay_exts, "ZXAYEMUL", 8, GST_TYPE_FIND_MAXIMUM);
4070 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gbs",
4071 GST_RANK_SECONDARY, gbs_exts, "GBS\x01", 4, GST_TYPE_FIND_MAXIMUM);
4072 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-vgm",
4073 GST_RANK_SECONDARY, vgm_exts, "Vgm\x20", 4, GST_TYPE_FIND_MAXIMUM);
4074 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sap",
4075 GST_RANK_SECONDARY, sap_exts, "SAP\x0d\x0aAUTHOR\x20", 12,
4076 GST_TYPE_FIND_MAXIMUM);
4077 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ivf", GST_RANK_SECONDARY,
4078 ivf_exts, "DKIF", 4, GST_TYPE_FIND_NEARLY_CERTAIN);
4079 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-kss", GST_RANK_SECONDARY,
4080 kss_exts, "KSSX\0", 5, GST_TYPE_FIND_MAXIMUM);
4081 TYPE_FIND_REGISTER_START_WITH (plugin, "application/pdf", GST_RANK_SECONDARY,
4082 pdf_exts, "%PDF-", 5, GST_TYPE_FIND_LIKELY);
4083 TYPE_FIND_REGISTER_START_WITH (plugin, "application/msword",
4084 GST_RANK_SECONDARY, msword_exts, "\320\317\021\340\241\261\032\341", 8,
4085 GST_TYPE_FIND_LIKELY);
4086 /* Mac OS X .DS_Store files tend to be taken for video/mpeg */
4087 TYPE_FIND_REGISTER_START_WITH (plugin, "application/octet-stream",
4088 GST_RANK_SECONDARY, dsstore_exts, "\000\000\000\001Bud1", 8,
4089 GST_TYPE_FIND_LIKELY);
4090 TYPE_FIND_REGISTER_START_WITH (plugin, "image/vnd.adobe.photoshop",
4091 GST_RANK_SECONDARY, psd_exts, "8BPS\000\001\000\000\000\000", 10,
4092 GST_TYPE_FIND_LIKELY);
4095 TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,
4096 xdgmime_typefind, NULL, NULL, NULL, NULL);
4102 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
4104 "typefindfunctions",
4105 "default typefind functions",
4106 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)