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);
115 static gboolean xml_check_first_element (GstTypeFind * tf,
116 const gchar * element, guint elen, gboolean strict);
117 static gboolean sdp_check_header (GstTypeFind * tf);
119 static GstStaticCaps utf8_caps = GST_STATIC_CAPS ("text/plain");
121 #define UTF8_CAPS gst_static_caps_get(&utf8_caps)
124 utf8_type_find_have_valid_utf8_at_offset (GstTypeFind * tf, guint64 offset,
125 GstTypeFindProbability * prob)
129 /* randomly decided values */
130 guint min_size = 16; /* minimum size */
131 guint size = 32 * 1024; /* starting size */
132 guint probability = 95; /* starting probability */
133 guint step = 10; /* how much we reduce probability in each
136 while (probability > step && size > min_size) {
137 data = gst_type_find_peek (tf, offset, size);
140 gchar *start = (gchar *) data;
142 if (g_utf8_validate (start, size, (const gchar **) &end) || (end - start + 4 > size)) { /* allow last char to be cut off */
157 utf8_type_find (GstTypeFind * tf, gpointer unused)
159 GstTypeFindProbability start_prob, mid_prob;
162 /* leave xml to the xml typefinders */
163 if (xml_check_first_element (tf, "", 0, TRUE))
166 /* leave sdp to the sdp typefinders */
167 if (sdp_check_header (tf))
170 /* check beginning of stream */
171 if (!utf8_type_find_have_valid_utf8_at_offset (tf, 0, &start_prob))
174 GST_LOG ("start is plain text with probability of %u", start_prob);
176 /* POSSIBLE is the highest probability we ever return if we can't
177 * probe into the middle of the file and don't know its length */
179 length = gst_type_find_get_length (tf);
180 if (length == 0 || length == (guint64) - 1) {
181 gst_type_find_suggest (tf, MIN (start_prob, GST_TYPE_FIND_POSSIBLE),
186 if (length < 64 * 1024) {
187 gst_type_find_suggest (tf, start_prob, UTF8_CAPS);
191 /* check middle of stream */
192 if (!utf8_type_find_have_valid_utf8_at_offset (tf, length / 2, &mid_prob))
195 GST_LOG ("middle is plain text with probability of %u", mid_prob);
196 gst_type_find_suggest (tf, (start_prob + mid_prob) / 2, UTF8_CAPS);
199 /*** text/uri-list ***/
201 static GstStaticCaps uri_caps = GST_STATIC_CAPS ("text/uri-list");
203 #define URI_CAPS (gst_static_caps_get(&uri_caps))
204 #define BUFFER_SIZE 16 /* If the string is < 16 bytes we're screwed */
205 #define INC_BUFFER { \
207 if (pos == BUFFER_SIZE) { \
209 offset += BUFFER_SIZE; \
210 data = gst_type_find_peek (tf, offset, BUFFER_SIZE); \
211 if (data == NULL) return; \
217 uri_type_find (GstTypeFind * tf, gpointer unused)
219 guint8 *data = gst_type_find_peek (tf, 0, BUFFER_SIZE);
224 /* Search for # comment lines */
225 while (*data == '#') {
226 /* Goto end of line */
227 while (*data != '\n') {
234 if (!g_ascii_isalpha (*data)) {
235 /* Had a non alpha char - can't be uri-list */
241 while (g_ascii_isalnum (*data)) {
246 /* First non alpha char is not a : */
250 /* Get the next 2 bytes as well */
251 data = gst_type_find_peek (tf, offset + pos, 3);
255 if (data[1] != '/' && data[2] != '/') {
259 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, URI_CAPS);
264 /*** application/xml **********************************************************/
266 #define XML_BUFFER_SIZE 16
267 #define XML_INC_BUFFER { \
269 if (pos == XML_BUFFER_SIZE) { \
271 offset += XML_BUFFER_SIZE; \
272 data = gst_type_find_peek (tf, offset, XML_BUFFER_SIZE); \
273 if (data == NULL) return FALSE; \
280 xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen,
288 data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE);
292 /* look for the XMLDec
293 * see XML spec 2.8, Prolog and Document Type Declaration
294 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
295 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
297 if (strict && !got_xmldec)
300 /* skip XMLDec in any case if we've got one */
306 /* look for the first element, it has to be the requested element. Bail
307 * out if it is not within the first 4kB. */
308 while (data && (offset + pos) < 4096) {
309 while (*data != '<' && (offset + pos) < 4096) {
314 if (!g_ascii_isalpha (*data)) {
315 /* if not alphabetic, it's a PI or an element / attribute declaration
316 * like <?xxx or <!xxx */
321 /* the first normal element, check if it's the one asked for */
322 data = gst_type_find_peek (tf, offset + pos, elen + 1);
323 return (data && element && strncmp ((char *) data, element, elen) == 0);
329 static GstStaticCaps generic_xml_caps = GST_STATIC_CAPS ("application/xml");
331 #define GENERIC_XML_CAPS (gst_static_caps_get(&generic_xml_caps))
333 xml_type_find (GstTypeFind * tf, gpointer unused)
335 if (xml_check_first_element (tf, "", 0, TRUE)) {
336 gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, GENERIC_XML_CAPS);
340 /*** application/sdp *********************************************************/
342 static GstStaticCaps sdp_caps = GST_STATIC_CAPS ("application/sdp");
344 #define SDP_CAPS (gst_static_caps_get(&sdp_caps))
346 sdp_check_header (GstTypeFind * tf)
350 data = gst_type_find_peek (tf, 0, 5);
354 /* sdp must start with v=0[\r]\n */
355 if (memcmp (data, "v=0", 3))
358 if (data[3] == '\r' && data[4] == '\n')
367 sdp_type_find (GstTypeFind * tf, gpointer unused)
369 if (sdp_check_header (tf))
370 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDP_CAPS);
373 /*** application/smil *********************************************************/
375 static GstStaticCaps smil_caps = GST_STATIC_CAPS ("application/smil");
377 #define SMIL_CAPS (gst_static_caps_get(&smil_caps))
379 smil_type_find (GstTypeFind * tf, gpointer unused)
381 if (xml_check_first_element (tf, "smil", 4, FALSE)) {
382 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SMIL_CAPS);
388 static GstStaticCaps html_caps = GST_STATIC_CAPS ("text/html");
390 #define HTML_CAPS gst_static_caps_get (&html_caps)
393 html_type_find (GstTypeFind * tf, gpointer unused)
397 data = (gchar *) gst_type_find_peek (tf, 0, 16);
401 if (!g_ascii_strncasecmp (data, "<!DOCTYPE HTML", 14)) {
402 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
403 } else if (xml_check_first_element (tf, "html", 4, FALSE)) {
404 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
405 } else if ((d = memchr (data, '<', 16))) {
406 data = (gchar *) gst_type_find_peek (tf, d - data, 6);
407 if (data && g_ascii_strncasecmp (data, "<html>", 6) == 0) {
408 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
415 static GstStaticCaps mid_caps = GST_STATIC_CAPS ("audio/midi");
417 #define MID_CAPS gst_static_caps_get(&mid_caps)
419 mid_type_find (GstTypeFind * tf, gpointer unused)
421 guint8 *data = gst_type_find_peek (tf, 0, 4);
423 /* http://jedi.ks.uiuc.edu/~johns/links/music/midifile.html */
424 if (data && data[0] == 'M' && data[1] == 'T' && data[2] == 'h'
426 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MID_CAPS);
429 /*** audio/mobile-xmf ***/
431 static GstStaticCaps mxmf_caps = GST_STATIC_CAPS ("audio/mobile-xmf");
433 #define MXMF_CAPS gst_static_caps_get(&mxmf_caps)
435 mxmf_type_find (GstTypeFind * tf, gpointer unused)
439 /* Search FileId "XMF_" 4 bytes */
440 data = gst_type_find_peek (tf, 0, 4);
441 if (data && data[0] == 'X' && data[1] == 'M' && data[2] == 'F'
443 /* Search Format version "2.00" 4 bytes */
444 data = gst_type_find_peek (tf, 4, 4);
445 if (data && data[0] == '2' && data[1] == '.' && data[2] == '0'
447 /* Search TypeId 2 1 byte */
448 data = gst_type_find_peek (tf, 11, 1);
449 if (data && data[0] == 2) {
450 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXMF_CAPS);
457 /*** video/x-fli ***/
459 static GstStaticCaps flx_caps = GST_STATIC_CAPS ("video/x-fli");
461 #define FLX_CAPS gst_static_caps_get(&flx_caps)
463 flx_type_find (GstTypeFind * tf, gpointer unused)
465 guint8 *data = gst_type_find_peek (tf, 0, 134);
468 /* check magic and the frame type of the first frame */
469 if ((data[4] == 0x11 || data[4] == 0x12 ||
470 data[4] == 0x30 || data[4] == 0x44) &&
472 ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1)) {
473 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLX_CAPS);
477 data = gst_type_find_peek (tf, 0, 6);
479 /* check magic only */
480 if ((data[4] == 0x11 || data[4] == 0x12 ||
481 data[4] == 0x30 || data[4] == 0x44) && data[5] == 0xaf) {
482 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, FLX_CAPS);
488 /*** application/x-id3 ***/
490 static GstStaticCaps id3_caps = GST_STATIC_CAPS ("application/x-id3");
492 #define ID3_CAPS gst_static_caps_get(&id3_caps)
494 id3v2_type_find (GstTypeFind * tf, gpointer unused)
496 guint8 *data = gst_type_find_peek (tf, 0, 10);
498 if (data && memcmp (data, "ID3", 3) == 0 &&
499 data[3] != 0xFF && data[4] != 0xFF &&
500 (data[6] & 0x80) == 0 && (data[7] & 0x80) == 0 &&
501 (data[8] & 0x80) == 0 && (data[9] & 0x80) == 0) {
502 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
507 id3v1_type_find (GstTypeFind * tf, gpointer unused)
509 guint8 *data = gst_type_find_peek (tf, -128, 3);
511 if (data && memcmp (data, "TAG", 3) == 0) {
512 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
516 /*** application/x-ape ***/
518 static GstStaticCaps apetag_caps = GST_STATIC_CAPS ("application/x-apetag");
520 #define APETAG_CAPS gst_static_caps_get(&apetag_caps)
522 apetag_type_find (GstTypeFind * tf, gpointer unused)
526 /* APEv1/2 at start of file */
527 data = gst_type_find_peek (tf, 0, 8);
528 if (data && !memcmp (data, "APETAGEX", 8)) {
529 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
533 /* APEv1/2 at end of file */
534 data = gst_type_find_peek (tf, -32, 8);
535 if (data && !memcmp (data, "APETAGEX", 8)) {
536 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
541 /*** audio/x-ttafile ***/
543 static GstStaticCaps tta_caps = GST_STATIC_CAPS ("audio/x-ttafile");
545 #define TTA_CAPS gst_static_caps_get(&tta_caps)
547 tta_type_find (GstTypeFind * tf, gpointer unused)
549 guint8 *data = gst_type_find_peek (tf, 0, 3);
552 if (memcmp (data, "TTA", 3) == 0) {
553 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTA_CAPS);
559 /*** audio/x-flac ***/
560 static GstStaticCaps flac_caps = GST_STATIC_CAPS ("audio/x-flac");
562 #define FLAC_CAPS (gst_static_caps_get(&flac_caps))
565 flac_type_find (GstTypeFind * tf, gpointer unused)
567 DataScanCtx c = { 0, NULL, 0 };
569 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
572 /* standard flac (also old/broken flac-in-ogg with an initial 4-byte marker
573 * packet and without the usual packet framing) */
574 if (memcmp (c.data, "fLaC", 4) == 0) {
575 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
579 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
582 /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */
583 if (memcmp (c.data, "\177FLAC\001", 6) == 0) {
584 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
588 /* disabled because it happily typefinds /dev/urandom as audio/x-flac, and
589 * because I yet have to see header-less flac in the wild */
591 /* flac without headers (subset format) */
592 /* 64K should be enough */
593 while (c.offset < (64 * 1024)) {
594 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
597 /* look for frame header,
598 * http://flac.sourceforge.net/format.html#frame_header
600 if (c.data[0] == 0xff && (c.data[1] >> 2) == 0x3e) {
601 /* bit 15 in the header must be 0 */
602 if (((c.data[1] >> 1) & 0x01) == 0x01)
605 /* blocksize must be != 0x00 */
606 if ((c.data[2] >> 4) == 0x00)
609 /* samplerate must be != 0x0f */
610 if ((c.data[2] & 0x0f) == 0x0f)
612 /* also 0 is invalid, as it means get the info from the header and we
613 * don't have headers if we are here */
614 if ((c.data[2] & 0x0f) == 0x00)
617 /* channel assignment must be < 11 */
618 if ((c.data[3] >> 4) >= 11)
621 /* sample size must be != 0x07 and != 0x05 */
622 if (((c.data[3] >> 1) & 0x07) == 0x07)
624 if (((c.data[3] >> 1) & 0x07) == 0x05)
626 /* also 0 is invalid, as it means get the info from the header and we
627 * don't have headers if we are here */
628 if (((c.data[3] >> 1) & 0x07) == 0x00)
631 /* next bit must be 0 */
632 if ((c.data[3] & 0x01) == 0x01)
635 /* FIXME: shouldn't we include the crc check ? */
637 GST_DEBUG ("Found flac without headers at %d", (gint) c.offset);
638 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, FLAC_CAPS);
642 data_scan_ctx_advance (tf, &c, 1);
647 /*** audio/mpeg version 2, 4 ***/
649 static GstStaticCaps aac_caps = GST_STATIC_CAPS ("audio/mpeg, "
650 "mpegversion = (int) { 2, 4 }, framed = (bool) false");
651 #define AAC_CAPS (gst_static_caps_get(&aac_caps))
652 #define AAC_AMOUNT (4096)
654 aac_type_find (GstTypeFind * tf, gpointer unused)
656 /* LUT to convert the AudioObjectType from the ADTS header to a string */
657 static const gchar profile_to_string[][5] = { "main", "lc", "ssr", "ltp" };
658 static const guint sample_freq[] = { 96000, 88200, 64000, 48000, 44100,
659 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350
661 DataScanCtx c = { 0, NULL, 0 };
663 while (c.offset < AAC_AMOUNT) {
666 /* detect adts header or adif header.
667 * The ADIF header is 4 bytes, that should be OK. The ADTS header, on
668 * the other hand, is 14 bits only, so we require one valid frame with
669 * again a valid syncpoint on the next one (28 bits) for certainty. We
670 * require 4 kB, which is quite a lot, since frames are generally 200-400
673 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
676 snc = GST_READ_UINT16_BE (c.data);
677 if (G_UNLIKELY ((snc & 0xfff6) == 0xfff0)) {
678 /* ADTS header - find frame length */
679 GST_DEBUG ("Found one ADTS syncpoint at offset 0x%" G_GINT64_MODIFIER
680 "x, tracing next...", c.offset);
681 len = ((c.data[3] & 0x03) << 11) |
682 (c.data[4] << 3) | ((c.data[5] & 0xe0) >> 5);
684 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
685 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
689 /* check if there's a second ADTS frame */
690 snc = GST_READ_UINT16_BE (c.data + len);
691 if ((snc & 0xfff6) == 0xfff0) {
693 guint mpegversion, sample_freq_idx, channel_config, profile, rate;
696 mpegversion = (c.data[1] & 0x08) ? 2 : 4;
697 profile = c.data[2] >> 6;
698 sample_freq_idx = ((c.data[2] & 0x3c) >> 2);
699 channel_config = ((c.data[2] & 0x01) << 2) + (c.data[3] >> 6);
701 GST_DEBUG ("Found second ADTS-%d syncpoint at offset 0x%"
702 G_GINT64_MODIFIER "x, framelen %u", mpegversion, c.offset, len);
704 /* 0xd and 0xe are reserved. 0xf means the sample frequency is directly
705 * specified in the header, but that's not allowed for ADTS */
706 if (sample_freq_idx > 0xc) {
707 GST_DEBUG ("Unexpected sample frequency index %d or wrong sync",
712 rate = sample_freq[sample_freq_idx];
713 GST_LOG ("ADTS: profile=%u, rate=%u", profile, rate);
715 /* ADTS counts profiles from 0 instead of 1 to save bits */
716 level = gst_aac_level_from_header (profile + 1, rate, channel_config);
718 caps = gst_caps_new_simple ("audio/mpeg",
719 "framed", G_TYPE_BOOLEAN, FALSE,
720 "mpegversion", G_TYPE_INT, mpegversion,
721 "stream-type", G_TYPE_STRING, "adts",
722 "base-profile", G_TYPE_STRING, profile_to_string[profile],
723 "profile", G_TYPE_STRING, profile_to_string[profile], NULL);
728 /* we use a string here because h.264 levels are also strings and
729 * there aren't a lot of levels, so it's not too awkward to not use
730 * and integer here and keep the field type consistent with h.264 */
731 g_snprintf (level_str, sizeof (level_str), "%d", level);
732 gst_caps_set_simple (caps, "level", G_TYPE_STRING, level_str, NULL);
735 /* add rate and number of channels if we can */
736 if (channel_config != 0 && channel_config <= 7) {
737 const guint channels_map[] = { 0, 1, 2, 3, 4, 5, 6, 8 };
739 gst_caps_set_simple (caps, "channels", G_TYPE_INT,
740 channels_map[channel_config], "rate", G_TYPE_INT, rate, NULL);
743 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, caps);
744 gst_caps_unref (caps);
748 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
749 } else if (!memcmp (c.data, "ADIF", 4)) {
751 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
752 "framed", G_TYPE_BOOLEAN, FALSE, "mpegversion", G_TYPE_INT, 4,
753 "stream-format", G_TYPE_STRING, "adif", NULL);
759 data_scan_ctx_advance (tf, &c, 1);
763 /*** audio/mpeg version 1 ***/
766 * The chance that random data is identified as a valid mp3 header is 63 / 2^18
767 * (0.024%) per try. This makes the function for calculating false positives
768 * 1 - (1 - ((63 / 2 ^18) ^ GST_MP3_TYPEFIND_MIN_HEADERS)) ^ buffersize)
769 * This has the following probabilities of false positives:
770 * datasize MIN_HEADERS
772 * 4096 62.6% 0.02% 0% 0%
773 * 16384 98% 0.09% 0% 0%
774 * 1 MiB 100% 5.88% 0% 0%
775 * 1 GiB 100% 100% 1.44% 0%
776 * 1 TiB 100% 100% 100% 0.35%
777 * This means that the current choice (3 headers by most of the time 4096 byte
778 * buffers is pretty safe for now.
780 * The max. size of each frame is 1440 bytes, which means that for N frames to
781 * be detected, we need 1440 * GST_MP3_TYPEFIND_MIN_HEADERS + 3 bytes of data.
782 * Assuming we step into the stream right after the frame header, this
783 * means we need 1440 * (GST_MP3_TYPEFIND_MIN_HEADERS + 1) - 1 + 3 bytes
784 * of data (5762) to always detect any mp3.
787 static const guint mp3types_bitrates[2][3][16] =
788 { {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
789 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
790 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
791 {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
792 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
793 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}},
796 static const guint mp3types_freqs[3][3] = { {11025, 12000, 8000},
797 {22050, 24000, 16000},
798 {44100, 48000, 32000}
802 mp3_type_frame_length_from_header (guint32 header, guint * put_layer,
803 guint * put_channels, guint * put_bitrate, guint * put_samplerate,
804 gboolean * may_be_free_format, gint possible_free_framelen)
806 guint bitrate, layer, length, mode, samplerate, version, channels;
808 if ((header & 0xffe00000) != 0xffe00000)
811 /* we don't need extension, copyright, original or
812 * emphasis for the frame length */
820 length = header & 0x1;
823 /* sampling frequency */
824 samplerate = header & 0x3;
830 bitrate = header & 0xF;
831 if (bitrate == 0 && possible_free_framelen == -1) {
832 GST_LOG ("Possibly a free format mp3 - signalling");
833 *may_be_free_format = TRUE;
835 if (bitrate == 15 || (bitrate == 0 && possible_free_framelen == -1))
838 /* ignore error correction, too */
842 layer = 4 - (header & 0x3);
847 /* version 0=MPEG2.5; 2=MPEG2; 3=MPEG1 */
848 version = header & 0x3;
853 channels = (mode == 3) ? 1 : 2;
854 samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate];
858 length += possible_free_framelen;
859 bitrate = length * samplerate / 48000;
861 length += possible_free_framelen;
862 bitrate = length * samplerate /
863 ((layer == 3 && version != 3) ? 72000 : 144000);
867 bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate];
869 length = ((12000 * bitrate / samplerate) + length) * 4;
871 length += ((layer == 3
872 && version != 3) ? 72000 : 144000) * bitrate / samplerate;
876 GST_LOG ("mp3typefind: calculated mp3 frame length of %u bytes", length);
878 ("mp3typefind: samplerate = %u - bitrate = %u - layer = %u - version = %u"
879 " - channels = %u", samplerate, bitrate, layer, version, channels);
884 *put_channels = channels;
886 *put_bitrate = bitrate;
888 *put_samplerate = samplerate;
894 static GstStaticCaps mp3_caps = GST_STATIC_CAPS ("audio/mpeg, "
895 "mpegversion = (int) 1, layer = (int) [ 1, 3 ]");
896 #define MP3_CAPS (gst_static_caps_get(&mp3_caps))
898 * random values for typefinding
899 * if no more data is available, we will return a probability of
900 * (found_headers/TRY_HEADERS) * (MAXIMUM * (TRY_SYNC - bytes_skipped)
902 * if found_headers >= MIN_HEADERS
904 #define GST_MP3_TYPEFIND_MIN_HEADERS (2)
905 #define GST_MP3_TYPEFIND_TRY_HEADERS (5)
906 #define GST_MP3_TYPEFIND_TRY_SYNC (GST_TYPE_FIND_MAXIMUM * 100) /* 10kB */
907 #define GST_MP3_TYPEFIND_SYNC_SIZE (2048)
908 #define GST_MP3_WRONG_HEADER (10)
911 mp3_type_find_at_offset (GstTypeFind * tf, guint64 start_off,
912 guint * found_layer, GstTypeFindProbability * found_prob)
915 guint8 *data_end = NULL;
918 gint last_free_offset = -1;
919 gint last_free_framelen = -1;
920 gboolean headerstart = TRUE;
927 while (skipped < GST_MP3_TYPEFIND_TRY_SYNC) {
929 size = GST_MP3_TYPEFIND_SYNC_SIZE * 2;
932 data = gst_type_find_peek (tf, skipped + start_off, size);
933 } while (size > 10 && !data);
936 data_end = data + size;
939 guint8 *head_data = NULL;
940 guint layer = 0, bitrate, samplerate, channels;
941 guint found = 0; /* number of valid headers found */
942 guint64 offset = skipped;
944 while (found < GST_MP3_TYPEFIND_TRY_HEADERS) {
947 guint prev_layer = 0, prev_bitrate = 0;
948 guint prev_channels = 0, prev_samplerate = 0;
949 gboolean free = FALSE;
951 if ((gint64) (offset - skipped + 4) >= 0 &&
952 data + offset - skipped + 4 < data_end) {
953 head_data = data + offset - skipped;
955 head_data = gst_type_find_peek (tf, offset + start_off, 4);
959 head = GST_READ_UINT32_BE (head_data);
960 if (!(length = mp3_type_frame_length_from_header (head, &layer,
961 &channels, &bitrate, &samplerate, &free,
962 last_free_framelen))) {
964 if (last_free_offset == -1)
965 last_free_offset = offset;
967 last_free_framelen = offset - last_free_offset;
968 offset = last_free_offset;
972 last_free_framelen = -1;
975 /* Mark the fact that we didn't find a valid header at the beginning */
979 GST_LOG ("%d. header at offset %" G_GUINT64_FORMAT
980 " (0x%" G_GINT64_MODIFIER "x) was not an mp3 header "
981 "(possibly-free: %s)", found + 1, start_off + offset,
982 start_off + offset, free ? "yes" : "no");
985 if ((prev_layer && prev_layer != layer) ||
986 /* (prev_bitrate && prev_bitrate != bitrate) || <-- VBR */
987 (prev_samplerate && prev_samplerate != samplerate) ||
988 (prev_channels && prev_channels != channels)) {
989 /* this means an invalid property, or a change, which might mean
990 * that this is not a mp3 but just a random bytestream. It could
991 * be a freaking funky encoded mp3 though. We'll just not count
994 prev_bitrate = bitrate;
995 prev_channels = channels;
996 prev_samplerate = samplerate;
999 GST_LOG ("found %d. header at offset %" G_GUINT64_FORMAT " (0x%"
1000 G_GINT64_MODIFIER "X)", found, start_off + offset,
1001 start_off + offset);
1005 g_assert (found <= GST_MP3_TYPEFIND_TRY_HEADERS);
1006 if (head_data == NULL &&
1007 gst_type_find_peek (tf, offset + start_off - 1, 1) == NULL)
1008 /* Incomplete last frame - don't count it. */
1010 if (found == GST_MP3_TYPEFIND_TRY_HEADERS ||
1011 (found >= GST_MP3_TYPEFIND_MIN_HEADERS && head_data == NULL)) {
1012 /* we can make a valid guess */
1013 guint probability = found * GST_TYPE_FIND_MAXIMUM *
1014 (GST_MP3_TYPEFIND_TRY_SYNC - skipped) /
1015 GST_MP3_TYPEFIND_TRY_HEADERS / GST_MP3_TYPEFIND_TRY_SYNC;
1018 && probability > (GST_TYPE_FIND_MINIMUM + GST_MP3_WRONG_HEADER))
1019 probability -= GST_MP3_WRONG_HEADER;
1020 if (probability < GST_TYPE_FIND_MINIMUM)
1021 probability = GST_TYPE_FIND_MINIMUM;
1026 ("audio/mpeg calculated %u = %u * %u / %u * (%u - %"
1027 G_GUINT64_FORMAT ") / %u", probability, GST_TYPE_FIND_MAXIMUM,
1028 found, GST_MP3_TYPEFIND_TRY_HEADERS, GST_MP3_TYPEFIND_TRY_SYNC,
1029 (guint64) skipped, GST_MP3_TYPEFIND_TRY_SYNC);
1030 /* make sure we're not id3 tagged */
1031 head_data = gst_type_find_peek (tf, -128, 3);
1032 if (head_data && (memcmp (head_data, "TAG", 3) == 0)) {
1035 g_assert (probability <= GST_TYPE_FIND_MAXIMUM);
1037 *found_prob = probability;
1038 if (probability > 0)
1039 *found_layer = layer;
1050 mp3_type_find (GstTypeFind * tf, gpointer unused)
1052 GstTypeFindProbability prob, mid_prob;
1054 guint layer, mid_layer;
1057 mp3_type_find_at_offset (tf, 0, &layer, &prob);
1058 length = gst_type_find_get_length (tf);
1060 if (length == 0 || length == (guint64) - 1) {
1066 /* if we're pretty certain already, skip the additional check */
1067 if (prob >= GST_TYPE_FIND_LIKELY)
1070 mp3_type_find_at_offset (tf, length / 2, &mid_layer, &mid_prob);
1074 GST_LOG ("detected audio/mpeg only in the middle (p=%u)", mid_prob);
1080 if (layer != mid_layer) {
1081 GST_WARNING ("audio/mpeg layer discrepancy: %u vs. %u", layer, mid_layer);
1082 return; /* FIXME: or should we just go with the one in the middle? */
1085 /* detected mpeg audio both in middle of the file and at the start */
1086 prob = (prob + mid_prob) / 2;
1090 /* let's see if there's a valid header right at the start */
1091 data = gst_type_find_peek (tf, 0, 4); /* use min. frame size? */
1092 if (data && mp3_type_frame_length_from_header (GST_READ_UINT32_BE (data),
1093 &layer, NULL, NULL, NULL, NULL, 0) != 0) {
1095 prob = GST_TYPE_FIND_POSSIBLE - 10;
1097 prob = MAX (GST_TYPE_FIND_POSSIBLE - 10, prob + 10);
1107 g_return_if_fail (layer >= 1 && layer <= 3);
1109 gst_type_find_suggest_simple (tf, prob, "audio/mpeg",
1110 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, layer, NULL);
1114 /*** audio/x-musepack ***/
1116 static GstStaticCaps musepack_caps =
1117 GST_STATIC_CAPS ("audio/x-musepack, streamversion= (int) { 7, 8 }");
1119 #define MUSEPACK_CAPS (gst_static_caps_get(&musepack_caps))
1121 musepack_type_find (GstTypeFind * tf, gpointer unused)
1123 guint8 *data = gst_type_find_peek (tf, 0, 4);
1124 GstTypeFindProbability prop = GST_TYPE_FIND_MINIMUM;
1125 gint streamversion = -1;
1127 if (data && memcmp (data, "MP+", 3) == 0) {
1129 if ((data[3] & 0x7f) == 7) {
1130 prop = GST_TYPE_FIND_MAXIMUM;
1132 prop = GST_TYPE_FIND_LIKELY + 10;
1134 } else if (data && memcmp (data, "MPCK", 4) == 0) {
1136 prop = GST_TYPE_FIND_MAXIMUM;
1139 if (streamversion != -1) {
1140 gst_type_find_suggest_simple (tf, prop, "audio/x-musepack",
1141 "streamversion", G_TYPE_INT, streamversion, NULL);
1145 /*** audio/x-ac3 ***/
1146 /* FIXME 0.11: should be audio/ac3, but isn't for backwards compatibility */
1147 static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
1149 #define AC3_CAPS (gst_static_caps_get(&ac3_caps))
1153 unsigned short bit_rate;
1154 unsigned short frm_size[3];
1157 static const struct ac3_frmsize ac3_frmsizecod_tbl[] = {
1160 {40, {80, 87, 120}},
1161 {40, {80, 88, 120}},
1162 {48, {96, 104, 144}},
1163 {48, {96, 105, 144}},
1164 {56, {112, 121, 168}},
1165 {56, {112, 122, 168}},
1166 {64, {128, 139, 192}},
1167 {64, {128, 140, 192}},
1168 {80, {160, 174, 240}},
1169 {80, {160, 175, 240}},
1170 {96, {192, 208, 288}},
1171 {96, {192, 209, 288}},
1172 {112, {224, 243, 336}},
1173 {112, {224, 244, 336}},
1174 {128, {256, 278, 384}},
1175 {128, {256, 279, 384}},
1176 {160, {320, 348, 480}},
1177 {160, {320, 349, 480}},
1178 {192, {384, 417, 576}},
1179 {192, {384, 418, 576}},
1180 {224, {448, 487, 672}},
1181 {224, {448, 488, 672}},
1182 {256, {512, 557, 768}},
1183 {256, {512, 558, 768}},
1184 {320, {640, 696, 960}},
1185 {320, {640, 697, 960}},
1186 {384, {768, 835, 1152}},
1187 {384, {768, 836, 1152}},
1188 {448, {896, 975, 1344}},
1189 {448, {896, 976, 1344}},
1190 {512, {1024, 1114, 1536}},
1191 {512, {1024, 1115, 1536}},
1192 {576, {1152, 1253, 1728}},
1193 {576, {1152, 1254, 1728}},
1194 {640, {1280, 1393, 1920}},
1195 {640, {1280, 1394, 1920}}
1199 ac3_type_find (GstTypeFind * tf, gpointer unused)
1201 DataScanCtx c = { 0, NULL, 0 };
1203 /* Search for an ac3 frame; not neccesarily right at the start, but give it
1204 * a lower probability if not found right at the start. Check that the
1205 * frame is followed by a second frame at the expected offset.
1206 * We could also check the two ac3 CRCs, but we don't do that right now */
1207 while (c.offset < 1024) {
1208 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 5)))
1211 if (c.data[0] == 0x0b && c.data[1] == 0x77) {
1212 guint fscod = (c.data[4] >> 6) & 0x03;
1213 guint frmsizecod = c.data[4] & 0x3f;
1215 if (fscod < 3 && frmsizecod < 38) {
1216 DataScanCtx c_next = c;
1219 frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
1220 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1221 data_scan_ctx_advance (tf, &c, frame_size * 2);
1223 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1224 guint fscod2 = (c_next.data[4] >> 6) & 0x03;
1225 guint frmsizecod2 = c_next.data[4] & 0x3f;
1227 if (fscod == fscod2 && frmsizecod == frmsizecod2) {
1228 GstTypeFindProbability prob;
1231 prob = GST_TYPE_FIND_MAXIMUM;
1233 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1235 gst_type_find_suggest (tf, prob, AC3_CAPS);
1242 data_scan_ctx_advance (tf, &c, 1);
1248 /* can only be detected by using the extension, in which case we use the default
1250 static GstStaticCaps gsm_caps =
1251 GST_STATIC_CAPS ("audio/x-gsm, rate=8000, channels=1");
1253 #define GSM_CAPS (gst_static_caps_get(&gsm_caps))
1257 static GstStaticCaps wavpack_caps =
1258 GST_STATIC_CAPS ("audio/x-wavpack, framed = (boolean) false");
1260 #define WAVPACK_CAPS (gst_static_caps_get(&wavpack_caps))
1262 static GstStaticCaps wavpack_correction_caps =
1263 GST_STATIC_CAPS ("audio/x-wavpack-correction, framed = (boolean) false");
1265 #define WAVPACK_CORRECTION_CAPS (gst_static_caps_get(&wavpack_correction_caps))
1268 wavpack_type_find (GstTypeFind * tf, gpointer unused)
1274 data = gst_type_find_peek (tf, 0, 32);
1278 if (data[0] != 'w' || data[1] != 'v' || data[2] != 'p' || data[3] != 'k')
1281 /* Note: wavpack blocks can be fairly large (easily 60-110k), possibly
1282 * larger than the max. limits imposed by certain typefinding elements
1283 * like id3demux or apedemux, so typefinding is most likely only going to
1284 * work in pull-mode */
1285 blocksize = GST_READ_UINT32_LE (data + 4);
1286 GST_LOG ("wavpack header, blocksize=0x%04x", blocksize);
1288 while (offset < 32 + blocksize) {
1291 /* get chunk header */
1292 GST_LOG ("peeking at chunk at offset 0x%04x", (guint) offset);
1293 data = gst_type_find_peek (tf, offset, 4);
1296 sublen = ((guint32) data[1]) << 1;
1297 if (data[0] & 0x80) {
1298 sublen |= (((guint32) data[2]) << 9) | (((guint32) data[3]) << 17);
1299 sublen += 1 + 3; /* id + length */
1301 sublen += 1 + 1; /* id + length */
1303 if (sublen > blocksize - offset + 32) {
1304 GST_LOG ("chunk length too big (%u > %" G_GUINT64_FORMAT ")", sublen,
1305 blocksize - offset);
1308 if ((data[0] & 0x20) == 0) {
1309 switch (data[0] & 0x0f) {
1310 case 0xa: /* ID_WV_BITSTREAM */
1311 case 0xc: /* ID_WVX_BITSTREAM */
1312 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, WAVPACK_CAPS);
1314 case 0xb: /* ID_WVC_BITSTREAM */
1315 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY,
1316 WAVPACK_CORRECTION_CAPS);
1326 /*** application/postscrip ***/
1327 static GstStaticCaps postscript_caps =
1328 GST_STATIC_CAPS ("application/postscript");
1330 #define POSTSCRIPT_CAPS (gst_static_caps_get(&postscript_caps))
1333 postscript_type_find (GstTypeFind * tf, gpointer unused)
1335 guint8 *data = gst_type_find_peek (tf, 0, 3);
1339 if (data[0] == 0x04)
1341 if (data[0] == '%' && data[1] == '!')
1342 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, POSTSCRIPT_CAPS);
1346 /*** image/svg+xml ***/
1347 static GstStaticCaps svg_caps = GST_STATIC_CAPS ("image/svg+xml");
1349 #define SVG_CAPS (gst_static_caps_get(&svg_caps))
1352 svg_type_find (GstTypeFind * tf, gpointer unused)
1354 static const gchar svg_doctype[] = "!DOCTYPE svg";
1355 static const gchar svg_tag[] = "<svg";
1356 DataScanCtx c = { 0, NULL, 0 };
1358 while (c.offset <= 1024) {
1359 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
1362 if (memcmp (svg_doctype, c.data, 12) == 0) {
1363 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVG_CAPS);
1365 } else if (memcmp (svg_tag, c.data, 4) == 0) {
1366 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, SVG_CAPS);
1369 data_scan_ctx_advance (tf, &c, 1);
1373 /*** multipart/x-mixed-replace mimestream ***/
1375 static GstStaticCaps multipart_caps =
1376 GST_STATIC_CAPS ("multipart/x-mixed-replace");
1377 #define MULTIPART_CAPS gst_static_caps_get(&multipart_caps)
1379 /* multipart/x-mixed replace is:
1380 * <maybe some whitespace>--<some ascii chars>[\r]\n
1381 * <more ascii chars>[\r]\nContent-type:<more ascii>[\r]\n */
1383 multipart_type_find (GstTypeFind * tf, gpointer unused)
1388 #define MULTIPART_MAX_BOUNDARY_OFFSET 16
1389 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_BOUNDARY_OFFSET);
1394 x - data < MULTIPART_MAX_BOUNDARY_OFFSET - 2 && g_ascii_isspace (*x);
1396 if (x[0] != '-' || x[1] != '-')
1399 /* Could be okay, peek what should be enough for a complete header */
1400 #define MULTIPART_MAX_HEADER_SIZE 256
1401 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_HEADER_SIZE);
1405 for (x = data; x - data < MULTIPART_MAX_HEADER_SIZE - 14; x++) {
1406 if (!isascii (*x)) {
1410 !g_ascii_strncasecmp ("content-type:", (gchar *) x + 1, 13)) {
1411 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MULTIPART_CAPS);
1417 /*** video/mpeg systemstream ***/
1418 static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, "
1419 "systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
1421 #define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
1422 #define IS_MPEG_HEADER(data) (G_UNLIKELY((((guint8 *)(data))[0] == 0x00) && \
1423 (((guint8 *)(data))[1] == 0x00) && \
1424 (((guint8 *)(data))[2] == 0x01)))
1426 #define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
1427 #define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
1428 #define IS_MPEG_PACK_HEADER(data) (IS_MPEG_HEADER (data) && \
1429 IS_MPEG_PACK_CODE (((guint8 *)(data))[3]))
1431 #define IS_MPEG_PES_CODE(b) (((b) & 0xF0) == 0xE0 || ((b) & 0xF0) == 0xC0 || \
1433 #define IS_MPEG_PES_HEADER(data) (IS_MPEG_HEADER (data) && \
1434 IS_MPEG_PES_CODE (((guint8 *)(data))[3]))
1436 #define MPEG2_MAX_PROBE_LENGTH (128 * 1024) /* 128kB should be 64 packs of the
1437 * most common 2kB pack size. */
1439 #define MPEG2_MIN_SYS_HEADERS 2
1440 #define MPEG2_MAX_SYS_HEADERS 5
1443 mpeg_sys_is_valid_pack (GstTypeFind * tf, const guint8 * data, guint len,
1446 /* Check the pack header @ offset for validity, assuming that the 4 byte header
1447 * itself has already been checked. */
1453 /* Check marker bits */
1454 if ((data[4] & 0xC4) == 0x44) {
1459 if ((data[6] & 0x04) != 0x04 ||
1460 (data[8] & 0x04) != 0x04 ||
1461 (data[9] & 0x01) != 0x01 || (data[12] & 0x03) != 0x03)
1464 stuff_len = data[13] & 0x07;
1466 /* Check the following header bytes, if we can */
1467 if ((14 + stuff_len + 4) <= len) {
1468 if (!IS_MPEG_HEADER (data + 14 + stuff_len))
1472 *pack_size = 14 + stuff_len;
1474 } else if ((data[4] & 0xF1) == 0x21) {
1476 if ((data[6] & 0x01) != 0x01 ||
1477 (data[8] & 0x01) != 0x01 ||
1478 (data[9] & 0x80) != 0x80 || (data[11] & 0x01) != 0x01)
1481 /* Check the following header bytes, if we can */
1482 if ((12 + 4) <= len) {
1483 if (!IS_MPEG_HEADER (data + 12))
1495 mpeg_sys_is_valid_pes (GstTypeFind * tf, guint8 * data, guint len,
1498 guint pes_packet_len;
1500 /* Check the PES header at the given position, assuming the header code itself
1501 * was already checked */
1505 /* For MPEG Program streams, unbounded PES is not allowed, so we must have a
1506 * valid length present */
1507 pes_packet_len = GST_READ_UINT16_BE (data + 4);
1508 if (pes_packet_len == 0)
1511 /* Check the following header, if we can */
1512 if (6 + pes_packet_len + 4 <= len) {
1513 if (!IS_MPEG_HEADER (data + 6 + pes_packet_len))
1518 *pack_size = 6 + pes_packet_len;
1523 mpeg_sys_is_valid_sys (GstTypeFind * tf, guint8 * data, guint len,
1528 /* Check the System header at the given position, assuming the header code itself
1529 * was already checked */
1532 sys_hdr_len = GST_READ_UINT16_BE (data + 4);
1533 if (sys_hdr_len < 6)
1536 /* Check the following header, if we can */
1537 if (6 + sys_hdr_len + 4 <= len) {
1538 if (!IS_MPEG_HEADER (data + 6 + sys_hdr_len))
1543 *pack_size = 6 + sys_hdr_len;
1548 /* calculation of possibility to identify random data as mpeg systemstream:
1549 * bits that must match in header detection: 32 (or more)
1550 * chance that random data is identifed: 1/2^32
1551 * chance that MPEG2_MIN_PACK_HEADERS headers are identified:
1552 * 1/2^(32*MPEG2_MIN_PACK_HEADERS)
1553 * chance that this happens in MPEG2_MAX_PROBE_LENGTH bytes:
1554 * 1-(1+1/2^(32*MPEG2_MIN_PACK_HEADERS)^MPEG2_MAX_PROBE_LENGTH)
1555 * for current values:
1556 * 1-(1+1/2^(32*4)^101024)
1558 * Since we also check marker bits and pes packet lengths, this probability is a
1559 * very coarse upper bound.
1562 mpeg_sys_type_find (GstTypeFind * tf, gpointer unused)
1564 guint8 *data, *data0, *first_sync, *end;
1565 gint mpegversion = 0;
1566 guint pack_headers = 0;
1567 guint pes_headers = 0;
1569 guint since_last_sync = 0;
1570 guint32 sync_word = 0xffffffff;
1575 len = MPEG2_MAX_PROBE_LENGTH;
1578 data = gst_type_find_peek (tf, 0, 5 + len);
1579 } while (data == NULL && len >= 32);
1591 while (data < end) {
1593 if (sync_word == 0x00000100) {
1594 /* Found potential sync word */
1595 if (first_sync == NULL)
1596 first_sync = data - 3;
1598 if (since_last_sync > 4) {
1599 /* If more than 4 bytes since the last sync word, reset our counters,
1600 * as we're only interested in counting contiguous packets */
1601 pes_headers = pack_headers = 0;
1605 if (IS_MPEG_PACK_CODE (data[0])) {
1606 if ((data[1] & 0xC0) == 0x40) {
1609 } else if ((data[1] & 0xF0) == 0x20) {
1612 if (mpegversion != 0 &&
1613 mpeg_sys_is_valid_pack (tf, data - 3, end - data + 3, &pack_size)) {
1616 } else if (IS_MPEG_PES_CODE (data[0])) {
1618 if (mpeg_sys_is_valid_pes (tf, data - 3, end - data + 3, &pack_size)) {
1620 if (mpegversion == 0)
1623 } else if (IS_MPEG_SYS_CODE (data[0])) {
1624 if (mpeg_sys_is_valid_sys (tf, data - 3, end - data + 3, &pack_size)) {
1629 /* If we found a packet with a known size, skip the bytes in it and loop
1630 * around to check the next packet. */
1631 if (pack_size != 0) {
1632 data += pack_size - 3;
1633 sync_word = 0xffffffff;
1634 since_last_sync = 0;
1639 sync_word |= data[0];
1643 /* If we have found MAX headers, and *some* were pes headers (pack headers
1644 * are optional in an mpeg system stream) then return our high-probability
1646 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MAX_SYS_HEADERS)
1650 /* If we at least saw MIN headers, and *some* were pes headers (pack headers
1651 * are optional in an mpeg system stream) then return a lower-probability
1653 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MIN_SYS_HEADERS)
1661 prob = GST_TYPE_FIND_POSSIBLE + (10 * (pack_headers + pes_headers));
1662 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
1664 /* lower probability if the first packet wasn't right at the start */
1665 if (data0 != first_sync && prob >= 10)
1668 GST_LOG ("Suggesting MPEG %d system stream, %d packs, %d pes, prob %u%%\n",
1669 mpegversion, pack_headers, pes_headers, prob);
1671 gst_type_find_suggest_simple (tf, prob, "video/mpeg",
1672 "systemstream", G_TYPE_BOOLEAN, TRUE,
1673 "mpegversion", G_TYPE_INT, mpegversion, NULL);
1677 /*** video/mpegts Transport Stream ***/
1678 static GstStaticCaps mpegts_caps = GST_STATIC_CAPS ("video/mpegts, "
1679 "systemstream = (boolean) true, packetsize = (int) [ 188, 208 ]");
1680 #define MPEGTS_CAPS gst_static_caps_get(&mpegts_caps)
1682 #define GST_MPEGTS_TYPEFIND_MIN_HEADERS 4
1683 #define GST_MPEGTS_TYPEFIND_MAX_HEADERS 10
1684 #define GST_MPEGTS_MAX_PACKET_SIZE 208
1685 #define GST_MPEGTS_TYPEFIND_SYNC_SIZE \
1686 (GST_MPEGTS_TYPEFIND_MIN_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
1687 #define GST_MPEGTS_TYPEFIND_MAX_SYNC \
1688 (GST_MPEGTS_TYPEFIND_MAX_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
1690 #define MPEGTS_HDR_SIZE 4
1691 /* Check for sync byte, error_indicator == 0 and packet has payload */
1692 #define IS_MPEGTS_HEADER(data) (((data)[0] == 0x47) && \
1693 (((data)[1] & 0x80) == 0x00) && \
1694 (((data)[3] & 0x10) == 0x10))
1696 /* Helper function to search ahead at intervals of packet_size for mpegts
1699 mpeg_ts_probe_headers (GstTypeFind * tf, guint64 offset, gint packet_size)
1701 /* We always enter this function having found at least one header already */
1703 guint8 *data = NULL;
1705 while (found < GST_MPEGTS_TYPEFIND_MAX_HEADERS) {
1706 offset += packet_size;
1708 data = gst_type_find_peek (tf, offset, MPEGTS_HDR_SIZE);
1709 if (data == NULL || !IS_MPEGTS_HEADER (data))
1718 /* Try and detect at least 4 packets in at most 10 packets worth of
1719 * data. Need to try several possible packet sizes */
1721 mpeg_ts_type_find (GstTypeFind * tf, gpointer unused)
1723 /* TS packet sizes to test: normal, DVHS packet size and
1724 * FEC with 16 or 20 byte codes packet size. */
1725 const gint pack_sizes[] = { 188, 192, 204, 208 };
1726 const gint n_pack_sizes = sizeof (pack_sizes) / sizeof (gint);
1728 guint8 *data = NULL;
1730 guint64 skipped = 0;
1732 while (skipped < GST_MPEGTS_TYPEFIND_MAX_SYNC) {
1733 if (size < MPEGTS_HDR_SIZE) {
1734 data = gst_type_find_peek (tf, skipped, GST_MPEGTS_TYPEFIND_SYNC_SIZE);
1737 size = GST_MPEGTS_TYPEFIND_SYNC_SIZE;
1740 /* Have at least MPEGTS_HDR_SIZE bytes at this point */
1741 if (IS_MPEGTS_HEADER (data)) {
1744 for (p = 0; p < n_pack_sizes; p++) {
1747 /* Probe ahead at size pack_sizes[p] */
1748 found = mpeg_ts_probe_headers (tf, skipped, pack_sizes[p]);
1749 if (found >= GST_MPEGTS_TYPEFIND_MIN_HEADERS) {
1752 /* found at least 4 headers. 10 headers = MAXIMUM probability.
1753 * Arbitrarily, I assigned 10% probability for each header we
1754 * found, 40% -> 100% */
1755 probability = MIN (10 * found, GST_TYPE_FIND_MAXIMUM);
1757 gst_type_find_suggest_simple (tf, probability, "video/mpegts",
1758 "systemstream", G_TYPE_BOOLEAN, TRUE,
1759 "packetsize", G_TYPE_INT, pack_sizes[p], NULL);
1770 #define GST_MPEGVID_TYPEFIND_TRY_PICTURES 6
1771 #define GST_MPEGVID_TYPEFIND_TRY_SYNC (100 * 1024) /* 100 kB */
1773 /* Scan ahead a maximum of max_extra_offset bytes until the next IS_MPEG_HEADER
1774 * offset. After the call, offset will be after the 0x000001, i.e. at the 4th
1775 * byte of the MPEG header. Returns TRUE if a header was found, FALSE if not.
1778 mpeg_find_next_header (GstTypeFind * tf, DataScanCtx * c,
1779 guint64 max_extra_offset)
1781 guint64 extra_offset;
1783 for (extra_offset = 0; extra_offset <= max_extra_offset; ++extra_offset) {
1784 if (!data_scan_ctx_ensure_data (tf, c, 4))
1786 if (IS_MPEG_HEADER (c->data)) {
1787 data_scan_ctx_advance (tf, c, 3);
1790 data_scan_ctx_advance (tf, c, 1);
1795 /*** video/mpeg MPEG-4 elementary video stream ***/
1797 static GstStaticCaps mpeg4_video_caps = GST_STATIC_CAPS ("video/mpeg, "
1798 "systemstream=(boolean)false, mpegversion=4, parsed=(boolean)false");
1799 #define MPEG4_VIDEO_CAPS gst_static_caps_get(&mpeg4_video_caps)
1802 * This typefind is based on the elementary video header defined in
1803 * http://xhelmboyx.tripod.com/formats/mpeg-layout.txt
1804 * In addition, it allows the visual object sequence header to be
1805 * absent, and even the VOS header to be absent. In the latter case,
1806 * a number of VOPs have to be present.
1809 mpeg4_video_type_find (GstTypeFind * tf, gpointer unused)
1811 DataScanCtx c = { 0, NULL, 0 };
1812 gboolean seen_vios_at_0 = FALSE;
1813 gboolean seen_vios = FALSE;
1814 gboolean seen_vos = FALSE;
1815 gboolean seen_vol = FALSE;
1816 guint num_vop_headers = 0;
1819 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
1820 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
1823 if (!mpeg_find_next_header (tf, &c,
1824 GST_MPEGVID_TYPEFIND_TRY_SYNC - c.offset))
1829 /* visual_object_sequence_start_code */
1832 break; /* Terminate at second vios */
1834 seen_vios_at_0 = TRUE;
1836 data_scan_ctx_advance (tf, &c, 2);
1837 if (!mpeg_find_next_header (tf, &c, 0))
1842 /* Optional metadata */
1844 if (!mpeg_find_next_header (tf, &c, 24))
1848 /* visual_object_start_code (consider it optional) */
1850 data_scan_ctx_advance (tf, &c, 2);
1851 /* may contain ID marker and YUV clamping */
1852 if (!mpeg_find_next_header (tf, &c, 7))
1858 /* video_object_start_code */
1861 break; /* Terminate at second vos */
1863 data_scan_ctx_advance (tf, &c, 2);
1867 /* video_object_layer_start_code */
1868 if (sc >= 0x20 && sc <= 0x2F) {
1870 data_scan_ctx_advance (tf, &c, 5);
1874 /* video_object_plane_start_code */
1877 data_scan_ctx_advance (tf, &c, 2);
1881 /* Unknown start code. */
1884 if (num_vop_headers > 0 || seen_vol) {
1885 GstTypeFindProbability probability = 0;
1887 GST_LOG ("Found %d pictures, vios: %d, vos:%d, vol:%d", num_vop_headers,
1888 seen_vios, seen_vos, seen_vol);
1890 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios_at_0
1891 && seen_vos && seen_vol)
1892 probability = GST_TYPE_FIND_MAXIMUM - 1;
1893 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios
1894 && seen_vos && seen_vol)
1895 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
1896 else if (seen_vios_at_0 && seen_vos && seen_vol)
1897 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
1898 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vos
1900 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
1901 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vol)
1902 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
1903 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
1904 probability = GST_TYPE_FIND_LIKELY - 1;
1905 else if (num_vop_headers > 2 && seen_vios && seen_vos && seen_vol)
1906 probability = GST_TYPE_FIND_LIKELY - 9;
1907 else if (seen_vios && seen_vos && seen_vol)
1908 probability = GST_TYPE_FIND_LIKELY - 20;
1909 else if (num_vop_headers > 0 && seen_vos && seen_vol)
1910 probability = GST_TYPE_FIND_POSSIBLE;
1911 else if (num_vop_headers > 0)
1912 probability = GST_TYPE_FIND_POSSIBLE - 10;
1913 else if (seen_vos && seen_vol)
1914 probability = GST_TYPE_FIND_POSSIBLE - 20;
1916 gst_type_find_suggest (tf, probability, MPEG4_VIDEO_CAPS);
1920 /*** video/x-h264 H264 elementary video stream ***/
1922 static GstStaticCaps h264_video_caps = GST_STATIC_CAPS ("video/x-h264");
1924 #define H264_VIDEO_CAPS gst_static_caps_get(&h264_video_caps)
1926 #define H264_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
1929 h264_video_type_find (GstTypeFind * tf, gpointer unused)
1931 DataScanCtx c = { 0, NULL, 0 };
1933 /* Stream consists of: a series of sync codes (00 00 00 01) followed
1940 while (c.offset < H264_MAX_PROBE_LENGTH) {
1941 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
1944 if (IS_MPEG_HEADER (c.data)) {
1945 nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
1946 ref = c.data[3] & 0x60; /* nal_ref_idc */
1948 /* if forbiden bit is different to 0 won't be h264 */
1954 /* collect statistics about the NAL types */
1955 if ((nut >= 1 && nut <= 13) || nut == 19) {
1956 if ((nut == 5 && ref == 0) ||
1957 ((nut == 6 || (nut >= 9 && nut <= 12)) && ref != 0)) {
1962 } else if (nut >= 14 && nut <= 33) {
1964 /* Theoretically these are good, since if they exist in the
1965 stream it merely means that a newer backwards-compatible
1966 h.264 stream. But we should be identifying that separately. */
1969 /* unspecified, application specific */
1970 /* don't consider these bad */
1973 GST_DEBUG ("good %d bad %d", good, bad);
1975 if (good >= 10 && bad < 4) {
1976 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H264_VIDEO_CAPS);
1980 data_scan_ctx_advance (tf, &c, 4);
1982 data_scan_ctx_advance (tf, &c, 1);
1985 if (good >= 2 && bad < 1) {
1986 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H264_VIDEO_CAPS);
1991 /*** video/mpeg video stream ***/
1993 static GstStaticCaps mpeg_video_caps = GST_STATIC_CAPS ("video/mpeg, "
1994 "systemstream = (boolean) false");
1995 #define MPEG_VIDEO_CAPS gst_static_caps_get(&mpeg_video_caps)
1998 * Idea is the same as MPEG system stream typefinding: We check each
1999 * byte of the stream to see if - from that point on - the stream
2000 * matches a predefined set of marker bits as defined in the MPEG
2003 * I'm sure someone will do a chance calculation here too.
2007 mpeg_video_stream_type_find (GstTypeFind * tf, gpointer unused)
2009 DataScanCtx c = { 0, NULL, 0 };
2010 gboolean seen_seq_at_0 = FALSE;
2011 gboolean seen_seq = FALSE;
2012 gboolean seen_gop = FALSE;
2013 guint64 last_pic_offset = 0;
2014 guint num_pic_headers = 0;
2017 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2018 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2021 if (!data_scan_ctx_ensure_data (tf, &c, 5))
2024 if (!IS_MPEG_HEADER (c.data))
2027 /* a pack header indicates that this isn't an elementary stream */
2028 if (c.data[3] == 0xBA && mpeg_sys_is_valid_pack (tf, c.data, c.size, NULL))
2031 /* do we have a sequence header? */
2032 if (c.data[3] == 0xB3) {
2033 seen_seq_at_0 = seen_seq_at_0 || (c.offset == 0);
2035 data_scan_ctx_advance (tf, &c, 4 + 8);
2039 /* or a GOP header */
2040 if (c.data[3] == 0xB8) {
2042 data_scan_ctx_advance (tf, &c, 8);
2046 /* but what we'd really like to see is a picture header */
2047 if (c.data[3] == 0x00) {
2049 last_pic_offset = c.offset;
2050 data_scan_ctx_advance (tf, &c, 8);
2054 /* ... each followed by a slice header with slice_vertical_pos=1 that's
2055 * not too far away from the previously seen picture header. */
2056 if (c.data[3] == 0x01 && num_pic_headers > found &&
2057 (c.offset - last_pic_offset) >= 4 &&
2058 (c.offset - last_pic_offset) <= 64) {
2059 data_scan_ctx_advance (tf, &c, 4);
2066 data_scan_ctx_advance (tf, &c, 1);
2069 if (found > 0 || seen_seq) {
2070 GstTypeFindProbability probability = 0;
2072 GST_LOG ("Found %d pictures, seq:%d, gop:%d", found, seen_seq, seen_gop);
2074 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq && seen_gop)
2075 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2076 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq)
2077 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2078 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2079 probability = GST_TYPE_FIND_LIKELY;
2080 else if (seen_seq_at_0 && seen_gop && found > 2)
2081 probability = GST_TYPE_FIND_LIKELY - 10;
2082 else if (seen_seq && seen_gop && found > 2)
2083 probability = GST_TYPE_FIND_LIKELY - 20;
2084 else if (seen_seq_at_0 && found > 0)
2085 probability = GST_TYPE_FIND_POSSIBLE;
2086 else if (seen_seq && found > 0)
2087 probability = GST_TYPE_FIND_POSSIBLE - 5;
2089 probability = GST_TYPE_FIND_POSSIBLE - 10;
2091 probability = GST_TYPE_FIND_POSSIBLE - 20;
2093 gst_type_find_suggest_simple (tf, probability, "video/mpeg",
2094 "systemstream", G_TYPE_BOOLEAN, FALSE,
2095 "mpegversion", G_TYPE_INT, 1, NULL);
2099 /*** audio/x-aiff ***/
2101 static GstStaticCaps aiff_caps = GST_STATIC_CAPS ("audio/x-aiff");
2103 #define AIFF_CAPS gst_static_caps_get(&aiff_caps)
2105 aiff_type_find (GstTypeFind * tf, gpointer unused)
2107 guint8 *data = gst_type_find_peek (tf, 0, 4);
2109 if (data && memcmp (data, "FORM", 4) == 0) {
2111 if (memcmp (data, "AIFF", 4) == 0 || memcmp (data, "AIFC", 4) == 0)
2112 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AIFF_CAPS);
2116 /*** audio/x-svx ***/
2118 static GstStaticCaps svx_caps = GST_STATIC_CAPS ("audio/x-svx");
2120 #define SVX_CAPS gst_static_caps_get(&svx_caps)
2122 svx_type_find (GstTypeFind * tf, gpointer unused)
2124 guint8 *data = gst_type_find_peek (tf, 0, 4);
2126 if (data && memcmp (data, "FORM", 4) == 0) {
2128 if (memcmp (data, "8SVX", 4) == 0 || memcmp (data, "16SV", 4) == 0)
2129 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVX_CAPS);
2133 /*** audio/x-shorten ***/
2135 static GstStaticCaps shn_caps = GST_STATIC_CAPS ("audio/x-shorten");
2137 #define SHN_CAPS gst_static_caps_get(&shn_caps)
2139 shn_type_find (GstTypeFind * tf, gpointer unused)
2141 guint8 *data = gst_type_find_peek (tf, 0, 4);
2143 if (data && memcmp (data, "ajkg", 4) == 0) {
2144 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2146 data = gst_type_find_peek (tf, -8, 8);
2147 if (data && memcmp (data, "SHNAMPSK", 8) == 0) {
2148 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2152 /*** application/x-ape ***/
2154 static GstStaticCaps ape_caps = GST_STATIC_CAPS ("application/x-ape");
2156 #define APE_CAPS gst_static_caps_get(&ape_caps)
2158 ape_type_find (GstTypeFind * tf, gpointer unused)
2160 guint8 *data = gst_type_find_peek (tf, 0, 4);
2162 if (data && memcmp (data, "MAC ", 4) == 0) {
2163 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 10, APE_CAPS);
2167 /*** ISO FORMATS ***/
2169 /*** audio/x-m4a ***/
2171 static GstStaticCaps m4a_caps = GST_STATIC_CAPS ("audio/x-m4a");
2173 #define M4A_CAPS (gst_static_caps_get(&m4a_caps))
2175 m4a_type_find (GstTypeFind * tf, gpointer unused)
2177 guint8 *data = gst_type_find_peek (tf, 4, 8);
2180 (memcmp (data, "ftypM4A ", 8) == 0 ||
2181 memcmp (data, "ftypmp42", 8) == 0)) {
2182 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
2186 /*** application/x-3gp ***/
2188 /* The Q is there because variables can't start with a number. */
2191 static GstStaticCaps q3gp_caps = GST_STATIC_CAPS ("application/x-3gp");
2193 #define Q3GP_CAPS (gst_static_caps_get(&q3gp_caps))
2195 q3gp_type_find (GstTypeFind * tf, gpointer unused)
2198 guint32 ftyp_size = 0;
2200 guint8 *data = NULL;
2202 if ((data = gst_type_find_peek (tf, 0, 12)) == NULL) {
2207 if (memcmp (data, "ftyp", 4) != 0) {
2211 /* check major brand */
2213 if (memcmp (data, "3gp", 3) == 0 ||
2214 memcmp (data, "3gr", 3) == 0 ||
2215 memcmp (data, "3gs", 3) == 0 || memcmp (data, "3gg", 3) == 0) {
2216 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, Q3GP_CAPS);
2220 /* check compatible brands */
2221 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2222 ftyp_size = GST_READ_UINT32_BE (data);
2224 for (offset = 16; offset < ftyp_size; offset += 4) {
2225 if ((data = gst_type_find_peek (tf, offset, 3)) == NULL) {
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_LIKELY, Q3GP_CAPS);
2240 /*** video/mj2 and image/jp2 ***/
2241 static GstStaticCaps mj2_caps = GST_STATIC_CAPS ("video/mj2");
2243 #define MJ2_CAPS gst_static_caps_get(&mj2_caps)
2245 static GstStaticCaps jp2_caps = GST_STATIC_CAPS ("image/jp2");
2247 #define JP2_CAPS gst_static_caps_get(&jp2_caps)
2250 jp2_type_find (GstTypeFind * tf, gpointer unused)
2254 data = gst_type_find_peek (tf, 0, 24);
2259 if (memcmp (data, "\000\000\000\014jP \015\012\207\012", 12) != 0)
2262 /* check ftyp box */
2264 if (memcmp (data + 4, "ftyp", 4) == 0) {
2265 if (memcmp (data + 8, "jp2 ", 4) == 0)
2266 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JP2_CAPS);
2267 else if (memcmp (data + 8, "mjp2", 4) == 0)
2268 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MJ2_CAPS);
2272 /*** video/quicktime ***/
2274 static GstStaticCaps qt_caps = GST_STATIC_CAPS ("video/quicktime");
2276 #define QT_CAPS gst_static_caps_get(&qt_caps)
2277 #define STRNCMP(x,y,z) (strncmp ((char*)(x), (char*)(y), z))
2280 qt_type_find (GstTypeFind * tf, gpointer unused)
2286 const gchar *variant = NULL;
2288 while ((data = gst_type_find_peek (tf, offset, 12)) != NULL) {
2291 if (STRNCMP (&data[4], "ftypqt ", 8) == 0) {
2292 tip = GST_TYPE_FIND_MAXIMUM;
2296 if (STRNCMP (&data[4], "ftypisom", 8) == 0) {
2297 tip = GST_TYPE_FIND_MAXIMUM;
2302 /* box/atom types that are in common with ISO base media file format */
2303 if (STRNCMP (&data[4], "moov", 4) == 0 ||
2304 STRNCMP (&data[4], "mdat", 4) == 0 ||
2305 STRNCMP (&data[4], "ftyp", 4) == 0 ||
2306 STRNCMP (&data[4], "free", 4) == 0 ||
2307 STRNCMP (&data[4], "uuid", 4) == 0 ||
2308 STRNCMP (&data[4], "skip", 4) == 0) {
2310 tip = GST_TYPE_FIND_LIKELY;
2312 tip = GST_TYPE_FIND_NEARLY_CERTAIN;
2315 /* other box/atom types, apparently quicktime specific */
2316 else if (STRNCMP (&data[4], "pnot", 4) == 0 ||
2317 STRNCMP (&data[4], "PICT", 4) == 0 ||
2318 STRNCMP (&data[4], "wide", 4) == 0 ||
2319 STRNCMP (&data[4], "prfl", 4) == 0) {
2320 tip = GST_TYPE_FIND_MAXIMUM;
2326 size = GST_READ_UINT32_BE (data);
2330 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2331 if (sizedata == NULL)
2334 size = GST_READ_UINT64_BE (sizedata);
2339 new_offset = offset + size;
2340 if (new_offset <= offset)
2342 offset = new_offset;
2347 GstCaps *caps = gst_caps_copy (QT_CAPS);
2349 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, variant, NULL);
2350 gst_type_find_suggest (tf, tip, caps);
2351 gst_caps_unref (caps);
2353 gst_type_find_suggest (tf, tip, QT_CAPS);
2359 /*** image/x-quicktime ***/
2361 static GstStaticCaps qtif_caps = GST_STATIC_CAPS ("image/x-quicktime");
2363 #define QTIF_CAPS gst_static_caps_get(&qtif_caps)
2365 /* how many atoms we check before we give up */
2366 #define QTIF_MAXROUNDS 25
2369 qtif_type_find (GstTypeFind * tf, gpointer unused)
2372 gboolean found_idsc = FALSE;
2373 gboolean found_idat = FALSE;
2377 while ((data = gst_type_find_peek (tf, offset, 8)) != NULL) {
2380 size = GST_READ_UINT32_BE (data);
2382 const guint8 *sizedata;
2384 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2385 if (sizedata == NULL)
2388 size = GST_READ_UINT64_BE (sizedata);
2393 if (STRNCMP (data + 4, "idsc", 4) == 0)
2395 if (STRNCMP (data + 4, "idat", 4) == 0)
2398 if (found_idsc && found_idat) {
2399 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, QTIF_CAPS);
2404 if (++rounds > QTIF_MAXROUNDS)
2408 if (found_idsc || found_idat) {
2409 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, QTIF_CAPS);
2414 /*** audio/x-mod ***/
2416 static GstStaticCaps mod_caps = GST_STATIC_CAPS ("audio/x-mod");
2418 #define MOD_CAPS gst_static_caps_get(&mod_caps)
2419 /* FIXME: M15 CheckType to do */
2421 mod_type_find (GstTypeFind * tf, gpointer unused)
2426 if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) {
2427 /* Protracker and variants */
2428 if ((memcmp (data, "M.K.", 4) == 0) || (memcmp (data, "M!K!", 4) == 0) ||
2430 (memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) ||
2431 (memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) ||
2432 /* Oktalyzer (Amiga) */
2433 (memcmp (data, "OKTA", 4) == 0) ||
2434 /* Oktalyser (Atari) */
2435 (memcmp (data, "CD81", 4) == 0) ||
2437 (memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) ||
2438 /* Fasttracker or Taketracker */
2439 (memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0])
2440 && isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0
2441 && isdigit (data[0]) && isdigit (data[1]))) {
2442 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2447 if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) {
2448 if (memcmp (data, "Extended Module: ", 17) == 0 && data[37] == 0x1A) {
2449 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2454 if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) {
2455 if (memcmp (data, "OKTASONG", 8) == 0) {
2456 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2460 if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2462 if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) {
2463 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2467 if ((memcmp (data, "AMF", 3) == 0 && data[3] > 10 && data[3] < 14) ||
2469 (memcmp (data, "IMPM", 4) == 0) ||
2471 (memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0) ||
2473 (memcmp (data, "MTM", 3) == 0)) {
2474 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2478 if (memcmp (data, "RIFF", 4) == 0) {
2479 guint8 *data2 = gst_type_find_peek (tf, 8, 4);
2482 if (memcmp (data2, "DSMF", 4) == 0) {
2483 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2489 if (memcmp (data, "FAM\xFE", 4) == 0) {
2490 guint8 *data2 = gst_type_find_peek (tf, 44, 3);
2493 if (memcmp (data2, "compare", 3) == 0) {
2494 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2498 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2503 if (memcmp (data, "GDM\xFE", 4) == 0) {
2504 guint8 *data2 = gst_type_find_peek (tf, 71, 4);
2507 if (memcmp (data2, "GMFS", 4) == 0) {
2508 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2512 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2518 if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) {
2519 if (memcmp (data, "IM10", 4) == 0) {
2520 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2525 if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) {
2526 if (memcmp (data, "SCRM", 4) == 0) {
2527 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2532 if ((data = gst_type_find_peek (tf, 20, 8)) != NULL) {
2533 if (g_ascii_strncasecmp ((gchar *) data, "!Scream!", 8) == 0 ||
2534 g_ascii_strncasecmp ((gchar *) data, "BMOD2STM", 8) == 0) {
2535 guint8 *id, *stmtype;
2537 if ((id = gst_type_find_peek (tf, 28, 1)) == NULL)
2539 if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL)
2541 if (*id == 0x1A && *stmtype == 2)
2542 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2548 /*** application/x-shockwave-flash ***/
2550 static GstStaticCaps swf_caps =
2551 GST_STATIC_CAPS ("application/x-shockwave-flash");
2552 #define SWF_CAPS (gst_static_caps_get(&swf_caps))
2554 swf_type_find (GstTypeFind * tf, gpointer unused)
2556 guint8 *data = gst_type_find_peek (tf, 0, 4);
2558 if (data && (data[0] == 'F' || data[0] == 'C') &&
2559 data[1] == 'W' && data[2] == 'S') {
2560 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SWF_CAPS);
2564 /*** image/jpeg ***/
2566 static GstStaticCaps jpeg_caps = GST_STATIC_CAPS ("image/jpeg");
2568 #define JPEG_CAPS (gst_static_caps_get(&jpeg_caps))
2570 jpeg_type_find (GstTypeFind * tf, gpointer unused)
2572 guint8 *data = gst_type_find_peek (tf, 0, 10);
2573 guint8 header[2] = { 0xFF, 0xD8 };
2575 if (data && memcmp (data, header, 2) == 0) {
2576 if (memcmp (data + 6, "JFIF", 4) == 0) {
2577 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JPEG_CAPS);
2578 } else if (memcmp (data + 6, "Exif", 4) == 0) {
2579 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JPEG_CAPS);
2581 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, JPEG_CAPS);
2588 static GstStaticCaps bmp_caps = GST_STATIC_CAPS ("image/bmp");
2590 #define BMP_CAPS (gst_static_caps_get(&bmp_caps))
2592 bmp_type_find (GstTypeFind * tf, gpointer unused)
2594 DataScanCtx c = { 0, NULL, 0 };
2595 guint32 struct_size, w, h, planes, bpp;
2597 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 54)))
2600 if (c.data[0] != 'B' || c.data[1] != 'M')
2603 /* skip marker + size */
2604 data_scan_ctx_advance (tf, &c, 2 + 4);
2606 /* reserved, must be 0 */
2607 if (c.data[0] != 0 || c.data[1] != 0 || c.data[2] != 0 || c.data[3] != 0)
2610 data_scan_ctx_advance (tf, &c, 2 + 2);
2612 /* offset to start of image data in bytes (check for sanity) */
2613 GST_LOG ("offset=%u", GST_READ_UINT32_LE (c.data));
2614 if (GST_READ_UINT32_LE (c.data) > (10 * 1024 * 1024))
2617 struct_size = GST_READ_UINT32_LE (c.data + 4);
2618 GST_LOG ("struct_size=%u", struct_size);
2620 data_scan_ctx_advance (tf, &c, 4 + 4);
2622 if (struct_size == 0x0C) {
2623 w = GST_READ_UINT16_LE (c.data);
2624 h = GST_READ_UINT16_LE (c.data + 2);
2625 planes = GST_READ_UINT16_LE (c.data + 2 + 2);
2626 bpp = GST_READ_UINT16_LE (c.data + 2 + 2 + 2);
2627 } else if (struct_size == 40 || struct_size == 64 || struct_size == 108
2628 || struct_size == 124 || struct_size == 0xF0) {
2629 w = GST_READ_UINT32_LE (c.data);
2630 h = GST_READ_UINT32_LE (c.data + 4);
2631 planes = GST_READ_UINT16_LE (c.data + 4 + 4);
2632 bpp = GST_READ_UINT16_LE (c.data + 4 + 4 + 2);
2637 /* image sizes sanity check */
2638 GST_LOG ("w=%u, h=%u, planes=%u, bpp=%u", w, h, planes, bpp);
2639 if (w == 0 || w > 0xfffff || h == 0 || h > 0xfffff || planes != 1 ||
2640 (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32))
2643 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "image/bmp",
2644 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, "bpp", G_TYPE_INT, bpp,
2648 /*** image/tiff ***/
2649 static GstStaticCaps tiff_caps = GST_STATIC_CAPS ("image/tiff, "
2650 "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }");
2651 #define TIFF_CAPS (gst_static_caps_get(&tiff_caps))
2652 static GstStaticCaps tiff_be_caps = GST_STATIC_CAPS ("image/tiff, "
2653 "endianness = (int) BIG_ENDIAN");
2654 #define TIFF_BE_CAPS (gst_static_caps_get(&tiff_be_caps))
2655 static GstStaticCaps tiff_le_caps = GST_STATIC_CAPS ("image/tiff, "
2656 "endianness = (int) LITTLE_ENDIAN");
2657 #define TIFF_LE_CAPS (gst_static_caps_get(&tiff_le_caps))
2659 tiff_type_find (GstTypeFind * tf, gpointer ununsed)
2661 guint8 *data = gst_type_find_peek (tf, 0, 8);
2662 guint8 le_header[4] = { 0x49, 0x49, 0x2A, 0x00 };
2663 guint8 be_header[4] = { 0x4D, 0x4D, 0x00, 0x2A };
2666 if (memcmp (data, le_header, 4) == 0) {
2667 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_LE_CAPS);
2668 } else if (memcmp (data, be_header, 4) == 0) {
2669 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_BE_CAPS);
2676 static GstStaticCaps pnm_caps = GST_STATIC_CAPS ("image/x-portable-bitmap; "
2677 "image/x-portable-graymap; image/x-portable-pixmap; "
2678 "image/x-portable-anymap");
2680 #define PNM_CAPS (gst_static_caps_get(&pnm_caps))
2682 #define IS_PNM_WHITESPACE(c) \
2683 ((c) == ' ' || (c) == '\r' || (c) == '\n' || (c) == 't')
2686 pnm_type_find (GstTypeFind * tf, gpointer ununsed)
2688 const gchar *media_type = NULL;
2689 DataScanCtx c = { 0, NULL, 0 };
2692 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
2695 /* see http://en.wikipedia.org/wiki/Netpbm_format */
2696 if (c.data[0] != 'P' || c.data[1] < '1' || c.data[1] > '7' ||
2697 !IS_PNM_WHITESPACE (c.data[2]) ||
2698 (c.data[3] != '#' && c.data[3] < '0' && c.data[3] > '9'))
2701 switch (c.data[1]) {
2703 media_type = "image/x-portable-bitmap"; /* ASCII */
2706 media_type = "image/x-portable-graymap"; /* ASCII */
2709 media_type = "image/x-portable-pixmap"; /* ASCII */
2712 media_type = "image/x-portable-bitmap"; /* Raw */
2715 media_type = "image/x-portable-graymap"; /* Raw */
2718 media_type = "image/x-portable-pixmap"; /* Raw */
2721 media_type = "image/x-portable-anymap";
2724 g_return_if_reached ();
2727 /* try to extract width and height as well */
2728 if (c.data[1] != '7') {
2729 gchar s[64] = { 0, }
2732 /* need to skip any comment lines first */
2733 data_scan_ctx_advance (tf, &c, 3);
2734 while (c.data[0] == '#') { /* we know there's still data left */
2735 data_scan_ctx_advance (tf, &c, 1);
2736 while (c.data[0] != '\n' && c.data[0] != '\r') {
2737 if (!data_scan_ctx_ensure_data (tf, &c, 4))
2739 data_scan_ctx_advance (tf, &c, 1);
2741 data_scan_ctx_advance (tf, &c, 1);
2742 GST_LOG ("skipped comment line in PNM header");
2745 if (!data_scan_ctx_ensure_data (tf, &c, 32) &&
2746 !data_scan_ctx_ensure_data (tf, &c, 4)) {
2750 /* need to NUL-terminate data for sscanf */
2751 memcpy (s, c.data, MIN (sizeof (s) - 1, c.size));
2752 if (sscanf (s, "%u%c%u%c", &w, &sep1, &h, &sep2) == 4 &&
2753 IS_PNM_WHITESPACE (sep1) && IS_PNM_WHITESPACE (sep2) &&
2754 w > 0 && w < G_MAXINT && h > 0 && h < G_MAXINT) {
2755 GST_LOG ("extracted PNM width and height: %dx%d", w, h);
2761 /* FIXME: extract width + height for anymaps too */
2764 if (w > 0 && h > 0) {
2765 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type,
2766 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, NULL);
2768 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, media_type, NULL);
2772 static GstStaticCaps sds_caps = GST_STATIC_CAPS ("audio/x-sds");
2774 #define SDS_CAPS (gst_static_caps_get(&sds_caps))
2776 sds_type_find (GstTypeFind * tf, gpointer ununsed)
2778 guint8 *data = gst_type_find_peek (tf, 0, 4);
2779 guint8 mask[4] = { 0xFF, 0xFF, 0x80, 0xFF };
2780 guint8 match[4] = { 0xF0, 0x7E, 0, 0x01 };
2784 for (x = 0; x < 4; x++) {
2785 if ((data[x] & mask[x]) != match[x]) {
2789 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDS_CAPS);
2793 static GstStaticCaps ircam_caps = GST_STATIC_CAPS ("audio/x-ircam");
2795 #define IRCAM_CAPS (gst_static_caps_get(&ircam_caps))
2797 ircam_type_find (GstTypeFind * tf, gpointer ununsed)
2799 guint8 *data = gst_type_find_peek (tf, 0, 4);
2800 guint8 mask[4] = { 0xFF, 0xFF, 0xF8, 0xFF };
2801 guint8 match[4] = { 0x64, 0xA3, 0x00, 0x00 };
2803 gboolean matched = TRUE;
2808 for (x = 0; x < 4; x++) {
2809 if ((data[x] & mask[x]) != match[x]) {
2814 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, IRCAM_CAPS);
2817 /* now try the reverse version */
2819 for (x = 0; x < 4; x++) {
2820 if ((data[x] & mask[3 - x]) != match[3 - x]) {
2826 /* EBML typefind helper */
2828 ebml_check_header (GstTypeFind * tf, const gchar * doctype, int doctype_len)
2830 /* 4 bytes for EBML ID, 1 byte for header length identifier */
2831 guint8 *data = gst_type_find_peek (tf, 0, 4 + 1);
2832 gint len_mask = 0x80, size = 1, n = 1, total;
2838 if (data[0] != 0x1A || data[1] != 0x45 || data[2] != 0xDF || data[3] != 0xA3)
2841 /* length of header */
2843 while (size <= 8 && !(total & len_mask)) {
2849 total &= (len_mask - 1);
2851 total = (total << 8) | data[4 + n++];
2853 /* get new data for full header, 4 bytes for EBML ID,
2854 * EBML length tag and the actual header */
2855 data = gst_type_find_peek (tf, 0, 4 + size + total);
2859 /* the header must contain the doctype. For now, we don't parse the
2860 * whole header but simply check for the availability of that array
2861 * of characters inside the header. Not fully fool-proof, but good
2863 for (n = 4 + size; n <= 4 + size + total - doctype_len; n++)
2864 if (!memcmp (&data[n], doctype, doctype_len))
2870 /*** video/x-matroska ***/
2871 static GstStaticCaps matroska_caps = GST_STATIC_CAPS ("video/x-matroska");
2873 #define MATROSKA_CAPS (gst_static_caps_get(&matroska_caps))
2875 matroska_type_find (GstTypeFind * tf, gpointer ununsed)
2877 if (ebml_check_header (tf, "matroska", 8))
2878 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MATROSKA_CAPS);
2881 /*** video/webm ***/
2882 static GstStaticCaps webm_caps = GST_STATIC_CAPS ("video/webm");
2884 #define WEBM_CAPS (gst_static_caps_get(&webm_caps))
2886 webm_type_find (GstTypeFind * tf, gpointer ununsed)
2888 if (ebml_check_header (tf, "webm", 4))
2889 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, WEBM_CAPS);
2892 /*** application/mxf ***/
2893 static GstStaticCaps mxf_caps = GST_STATIC_CAPS ("application/mxf");
2895 #define MXF_MAX_PROBE_LENGTH (1024 * 64)
2896 #define MXF_CAPS (gst_static_caps_get(&mxf_caps))
2899 * MXF files start with a header partition pack key of 16 bytes which is defined
2900 * at SMPTE-377M 6.1. Before this there can be up to 64K of run-in which _must_
2901 * not contain the partition pack key.
2904 mxf_type_find (GstTypeFind * tf, gpointer ununsed)
2906 static const guint8 partition_pack_key[] =
2907 { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
2910 DataScanCtx c = { 0, NULL, 0 };
2912 while (c.offset <= MXF_MAX_PROBE_LENGTH) {
2914 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 1024)))
2917 /* look over in chunks of 1kbytes to avoid too much overhead */
2919 for (i = 0; i < 1024 - 16; i++) {
2920 /* Check first byte before calling more expensive memcmp function */
2921 if (G_UNLIKELY (c.data[i] == 0x06
2922 && memcmp (c.data + i, partition_pack_key, 13) == 0)) {
2923 /* Header partition pack? */
2924 if (c.data[i + 13] != 0x02)
2927 /* Partition status */
2928 if (c.data[i + 14] >= 0x05)
2931 /* Reserved, must be 0x00 */
2932 if (c.data[i + 15] != 0x00)
2935 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
2941 data_scan_ctx_advance (tf, &c, 1024 - 16);
2945 /*** video/x-dv ***/
2947 static GstStaticCaps dv_caps = GST_STATIC_CAPS ("video/x-dv, "
2948 "systemstream = (boolean) true");
2949 #define DV_CAPS (gst_static_caps_get(&dv_caps))
2951 dv_type_find (GstTypeFind * tf, gpointer private)
2955 data = gst_type_find_peek (tf, 0, 5);
2957 /* check for DIF and DV flag */
2958 if (data && (data[0] == 0x1f) && (data[1] == 0x07) && (data[2] == 0x00)) {
2959 const gchar *format;
2961 if (data[3] & 0x80) {
2967 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "video/x-dv",
2968 "systemstream", G_TYPE_BOOLEAN, TRUE,
2969 "format", G_TYPE_STRING, format, NULL);
2974 /*** application/ogg and application/x-annodex ***/
2975 static GstStaticCaps ogg_caps = GST_STATIC_CAPS ("application/ogg");
2976 static GstStaticCaps annodex_caps = GST_STATIC_CAPS ("application/x-annodex");
2977 static GstStaticCaps ogg_annodex_caps =
2978 GST_STATIC_CAPS ("application/ogg;application/x-annodex");
2980 #define OGGANX_CAPS (gst_static_caps_get(&ogg_annodex_caps))
2983 ogganx_type_find (GstTypeFind * tf, gpointer private)
2985 guint8 *data = gst_type_find_peek (tf, 0, 4);
2987 if ((data != NULL) && (memcmp (data, "OggS", 4) == 0)) {
2989 /* Check for an annodex fishbone header */
2990 data = gst_type_find_peek (tf, 28, 8);
2991 if (data && memcmp (data, "fishead\0", 8) == 0)
2992 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
2993 gst_static_caps_get (&annodex_caps));
2995 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
2996 gst_static_caps_get (&ogg_caps));
3000 /*** audio/x-vorbis ***/
3001 static GstStaticCaps vorbis_caps = GST_STATIC_CAPS ("audio/x-vorbis");
3003 #define VORBIS_CAPS (gst_static_caps_get(&vorbis_caps))
3005 vorbis_type_find (GstTypeFind * tf, gpointer private)
3007 guint8 *data = gst_type_find_peek (tf, 0, 30);
3013 /* 1 byte packet type (identification=0x01)
3014 6 byte string "vorbis"
3015 4 byte vorbis version */
3016 if (memcmp (data, "\001vorbis\000\000\000\000", 11) != 0)
3019 /* 1 byte channels must be != 0 */
3023 /* 4 byte samplerate must be != 0 */
3024 if (GST_READ_UINT32_LE (data) == 0)
3027 /* blocksize checks */
3028 blocksize_0 = data[0] & 0x0F;
3029 blocksize_1 = (data[0] & 0xF0) >> 4;
3030 if (blocksize_0 > blocksize_1)
3032 if (blocksize_0 < 6 || blocksize_0 > 13)
3034 if (blocksize_1 < 6 || blocksize_1 > 13)
3038 if ((data[0] & 0x01) != 1)
3040 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VORBIS_CAPS);
3044 /*** video/x-theora ***/
3046 static GstStaticCaps theora_caps = GST_STATIC_CAPS ("video/x-theora");
3048 #define THEORA_CAPS (gst_static_caps_get(&theora_caps))
3050 theora_type_find (GstTypeFind * tf, gpointer private)
3052 guint8 *data = gst_type_find_peek (tf, 0, 7); //42);
3055 if (data[0] != 0x80)
3057 if (memcmp (&data[1], "theora", 6) != 0)
3059 /* FIXME: make this more reliable when specs are out */
3061 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, THEORA_CAPS);
3067 kate_type_find (GstTypeFind * tf, gpointer private)
3069 guint8 *data = gst_type_find_peek (tf, 0, 64);
3070 gchar category[16] = { 0, };
3072 if (G_UNLIKELY (data == NULL))
3075 /* see: http://wiki.xiph.org/index.php/OggKate#Format_specification */
3076 if (G_LIKELY (memcmp (data, "\200kate\0\0\0", 8) != 0))
3079 /* make sure we always have a NUL-terminated string */
3080 memcpy (category, data + 48, 15);
3081 GST_LOG ("kate category: %s", category);
3082 /* canonical categories for subtitles: subtitles, spu-subtitles, SUB, K-SPU */
3083 if (strcmp (category, "subtitles") == 0 || strcmp (category, "SUB") == 0 ||
3084 strcmp (category, "spu-subtitles") == 0 ||
3085 strcmp (category, "K-SPU") == 0) {
3086 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3087 "subtitle/x-kate", NULL);
3089 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3090 "application/x-kate", NULL);
3094 /*** application/x-ogm-video or audio***/
3096 static GstStaticCaps ogmvideo_caps =
3097 GST_STATIC_CAPS ("application/x-ogm-video");
3098 #define OGMVIDEO_CAPS (gst_static_caps_get(&ogmvideo_caps))
3100 ogmvideo_type_find (GstTypeFind * tf, gpointer private)
3102 guint8 *data = gst_type_find_peek (tf, 0, 9);
3105 if (memcmp (data, "\001video\000\000\000", 9) != 0)
3107 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMVIDEO_CAPS);
3111 static GstStaticCaps ogmaudio_caps =
3112 GST_STATIC_CAPS ("application/x-ogm-audio");
3113 #define OGMAUDIO_CAPS (gst_static_caps_get(&ogmaudio_caps))
3115 ogmaudio_type_find (GstTypeFind * tf, gpointer private)
3117 guint8 *data = gst_type_find_peek (tf, 0, 9);
3120 if (memcmp (data, "\001audio\000\000\000", 9) != 0)
3122 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMAUDIO_CAPS);
3126 static GstStaticCaps ogmtext_caps = GST_STATIC_CAPS ("application/x-ogm-text");
3128 #define OGMTEXT_CAPS (gst_static_caps_get(&ogmtext_caps))
3130 ogmtext_type_find (GstTypeFind * tf, gpointer private)
3132 guint8 *data = gst_type_find_peek (tf, 0, 9);
3135 if (memcmp (data, "\001text\000\000\000\000", 9) != 0)
3137 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMTEXT_CAPS);
3141 /*** audio/x-speex ***/
3143 static GstStaticCaps speex_caps = GST_STATIC_CAPS ("audio/x-speex");
3145 #define SPEEX_CAPS (gst_static_caps_get(&speex_caps))
3147 speex_type_find (GstTypeFind * tf, gpointer private)
3149 guint8 *data = gst_type_find_peek (tf, 0, 80);
3152 /* 8 byte string "Speex "
3153 24 byte speex version string + int */
3154 if (memcmp (data, "Speex ", 8) != 0)
3158 /* 4 byte header size >= 80 */
3159 if (GST_READ_UINT32_LE (data) < 80)
3163 /* 4 byte sample rate <= 48000 */
3164 if (GST_READ_UINT32_LE (data) > 48000)
3168 /* currently there are only 3 speex modes. */
3169 if (GST_READ_UINT32_LE (data) > 3)
3173 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SPEEX_CAPS);
3177 /*** audio/x-celt ***/
3179 static GstStaticCaps celt_caps = GST_STATIC_CAPS ("audio/x-celt");
3181 #define CELT_CAPS (gst_static_caps_get(&celt_caps))
3183 celt_type_find (GstTypeFind * tf, gpointer private)
3185 guint8 *data = gst_type_find_peek (tf, 0, 8);
3188 /* 8 byte string "CELT " */
3189 if (memcmp (data, "CELT ", 8) != 0)
3192 /* TODO: Check other values of the CELT header */
3193 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CELT_CAPS);
3197 /*** application/x-ogg-skeleton ***/
3198 static GstStaticCaps ogg_skeleton_caps =
3199 GST_STATIC_CAPS ("application/x-ogg-skeleton, parsed=(boolean)FALSE");
3200 #define OGG_SKELETON_CAPS (gst_static_caps_get(&ogg_skeleton_caps))
3202 oggskel_type_find (GstTypeFind * tf, gpointer private)
3204 guint8 *data = gst_type_find_peek (tf, 0, 12);
3207 /* 8 byte string "fishead\0" for the ogg skeleton stream */
3208 if (memcmp (data, "fishead\0", 8) != 0)
3212 /* Require that the header contains version 3.0 */
3213 if (GST_READ_UINT16_LE (data) != 3)
3216 if (GST_READ_UINT16_LE (data) != 0)
3219 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGG_SKELETON_CAPS);
3223 static GstStaticCaps cmml_caps = GST_STATIC_CAPS ("text/x-cmml");
3225 #define CMML_CAPS (gst_static_caps_get(&cmml_caps))
3227 cmml_type_find (GstTypeFind * tf, gpointer private)
3229 /* Header is 12 bytes minimum (though we don't check the minor version */
3230 guint8 *data = gst_type_find_peek (tf, 0, 12);
3234 /* 8 byte string "CMML\0\0\0\0" for the magic number */
3235 if (memcmp (data, "CMML\0\0\0\0", 8) != 0)
3239 /* Require that the header contains at least version 2.0 */
3240 if (GST_READ_UINT16_LE (data) < 2)
3243 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CMML_CAPS);
3247 /*** application/x-tar ***/
3249 static GstStaticCaps tar_caps = GST_STATIC_CAPS ("application/x-tar");
3251 #define TAR_CAPS (gst_static_caps_get(&tar_caps))
3252 #define OLDGNU_MAGIC "ustar " /* 7 chars and a NUL */
3253 #define NEWGNU_MAGIC "ustar" /* 5 chars and a NUL */
3255 tar_type_find (GstTypeFind * tf, gpointer unused)
3257 guint8 *data = gst_type_find_peek (tf, 257, 8);
3259 /* of course we are not certain, but we don't want other typefind funcs
3260 * to detect formats of files within the tar archive, e.g. mp3s */
3262 if (memcmp (data, OLDGNU_MAGIC, 8) == 0) { /* sic */
3263 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3264 } else if (memcmp (data, NEWGNU_MAGIC, 6) == 0 && /* sic */
3265 g_ascii_isdigit (data[6]) && g_ascii_isdigit (data[7])) {
3266 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3271 /*** application/x-ar ***/
3273 static GstStaticCaps ar_caps = GST_STATIC_CAPS ("application/x-ar");
3275 #define AR_CAPS (gst_static_caps_get(&ar_caps))
3277 ar_type_find (GstTypeFind * tf, gpointer unused)
3279 guint8 *data = gst_type_find_peek (tf, 0, 24);
3281 if (data && memcmp (data, "!<arch>", 7) == 0) {
3284 for (i = 7; i < 24; ++i) {
3285 if (!g_ascii_isprint (data[i]) && data[i] != '\n') {
3286 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AR_CAPS);
3290 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AR_CAPS);
3294 /*** audio/x-au ***/
3296 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3297 * as it is only possible to register one typefind factory per 'name'
3298 * (which is in this case the caps), and the first one would be replaced by
3299 * the second one. */
3300 static GstStaticCaps au_caps = GST_STATIC_CAPS ("audio/x-au");
3302 #define AU_CAPS (gst_static_caps_get(&au_caps))
3304 au_type_find (GstTypeFind * tf, gpointer unused)
3306 guint8 *data = gst_type_find_peek (tf, 0, 4);
3309 if (memcmp (data, ".snd", 4) == 0 || memcmp (data, "dns.", 4) == 0) {
3310 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AU_CAPS);
3316 /*** video/x-nuv ***/
3318 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3319 * as it is only possible to register one typefind factory per 'name'
3320 * (which is in this case the caps), and the first one would be replaced by
3321 * the second one. */
3322 static GstStaticCaps nuv_caps = GST_STATIC_CAPS ("video/x-nuv");
3324 #define NUV_CAPS (gst_static_caps_get(&nuv_caps))
3326 nuv_type_find (GstTypeFind * tf, gpointer unused)
3328 guint8 *data = gst_type_find_peek (tf, 0, 11);
3331 if (memcmp (data, "MythTVVideo", 11) == 0
3332 || memcmp (data, "NuppelVideo", 11) == 0) {
3333 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, NUV_CAPS);
3338 /*** audio/x-paris ***/
3339 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3340 static GstStaticCaps paris_caps = GST_STATIC_CAPS ("audio/x-paris");
3342 #define PARIS_CAPS (gst_static_caps_get(&paris_caps))
3344 paris_type_find (GstTypeFind * tf, gpointer unused)
3346 guint8 *data = gst_type_find_peek (tf, 0, 4);
3349 if (memcmp (data, " paf", 4) == 0 || memcmp (data, "fap ", 4) == 0) {
3350 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, PARIS_CAPS);
3355 /*** audio/iLBC-sh ***/
3356 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3357 static GstStaticCaps ilbc_caps = GST_STATIC_CAPS ("audio/iLBC-sh");
3359 #define ILBC_CAPS (gst_static_caps_get(&ilbc_caps))
3361 ilbc_type_find (GstTypeFind * tf, gpointer unused)
3363 guint8 *data = gst_type_find_peek (tf, 0, 8);
3366 if (memcmp (data, "#!iLBC30", 8) == 0 || memcmp (data, "#!iLBC20", 8) == 0) {
3367 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, ILBC_CAPS);
3372 /*** application/x-ms-dos-executable ***/
3374 static GstStaticCaps msdos_caps =
3375 GST_STATIC_CAPS ("application/x-ms-dos-executable");
3376 #define MSDOS_CAPS (gst_static_caps_get(&msdos_caps))
3377 /* see http://www.madchat.org/vxdevl/papers/winsys/pefile/pefile.htm */
3379 msdos_type_find (GstTypeFind * tf, gpointer unused)
3381 guint8 *data = gst_type_find_peek (tf, 0, 64);
3383 if (data && data[0] == 'M' && data[1] == 'Z' &&
3384 GST_READ_UINT16_LE (data + 8) == 4) {
3385 guint32 pe_offset = GST_READ_UINT32_LE (data + 60);
3387 data = gst_type_find_peek (tf, pe_offset, 2);
3388 if (data && data[0] == 'P' && data[1] == 'E') {
3389 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, MSDOS_CAPS);
3394 /*** application/x-mmsh ***/
3396 static GstStaticCaps mmsh_caps = GST_STATIC_CAPS ("application/x-mmsh");
3398 #define MMSH_CAPS gst_static_caps_get(&mmsh_caps)
3400 /* This is to recognise mssh-over-http */
3402 mmsh_type_find (GstTypeFind * tf, gpointer unused)
3404 static const guint8 asf_marker[16] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66,
3405 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
3410 data = gst_type_find_peek (tf, 0, 2 + 2 + 4 + 2 + 2 + 16);
3411 if (data && data[0] == 0x24 && data[1] == 0x48 &&
3412 GST_READ_UINT16_LE (data + 2) > 2 + 2 + 4 + 2 + 2 + 16 &&
3413 memcmp (data + 2 + 2 + 4 + 2 + 2, asf_marker, 16) == 0) {
3414 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MMSH_CAPS);
3418 /*** video/x-dirac ***/
3420 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3421 * as it is only possible to register one typefind factory per 'name'
3422 * (which is in this case the caps), and the first one would be replaced by
3423 * the second one. */
3424 static GstStaticCaps dirac_caps = GST_STATIC_CAPS ("video/x-dirac");
3426 #define DIRAC_CAPS (gst_static_caps_get(&dirac_caps))
3428 dirac_type_find (GstTypeFind * tf, gpointer unused)
3430 guint8 *data = gst_type_find_peek (tf, 0, 8);
3433 if (memcmp (data, "BBCD", 4) == 0 || memcmp (data, "KW-DIRAC", 8) == 0) {
3434 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DIRAC_CAPS);
3439 /*** video/vivo ***/
3441 static GstStaticCaps vivo_caps = GST_STATIC_CAPS ("video/vivo");
3443 #define VIVO_CAPS gst_static_caps_get(&vivo_caps)
3446 vivo_type_find (GstTypeFind * tf, gpointer unused)
3448 static const guint8 vivo_marker[] = { 'V', 'e', 'r', 's', 'i', 'o', 'n',
3449 ':', 'V', 'i', 'v', 'o', '/'
3454 data = gst_type_find_peek (tf, 0, 1024);
3455 if (data == NULL || data[0] != 0x00)
3458 if ((data[1] & 0x80)) {
3459 if ((data[2] & 0x80))
3461 hdr_len = ((guint) (data[1] & 0x7f)) << 7;
3471 /* 1008 = 1022 - strlen ("Version:Vivo/") - 1 */
3472 while (pos < 1008 && data[pos] == '\r' && data[pos + 1] == '\n')
3475 if (memcmp (data + pos, vivo_marker, sizeof (vivo_marker)) == 0) {
3476 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VIVO_CAPS);
3480 /*** XDG MIME typefinder (to avoid false positives mostly) ***/
3484 xdgmime_typefind (GstTypeFind * find, gpointer user_data)
3487 gsize length = 16384;
3492 if ((tf_length = gst_type_find_get_length (find)) > 0)
3493 length = MIN (length, tf_length);
3495 if ((data = gst_type_find_peek (find, 0, length)) == NULL)
3498 tmp = g_content_type_guess (NULL, data, length, NULL);
3499 if (tmp == NULL || g_content_type_is_unknown (tmp)) {
3504 mimetype = g_content_type_get_mime_type (tmp);
3507 if (mimetype == NULL)
3510 GST_DEBUG ("Got mimetype '%s'", mimetype);
3512 /* Ignore audio/video types:
3513 * - our own typefinders in -base are likely to be better at this
3514 * (and if they're not, we really want to fix them, that's why we don't
3515 * report xdg-detected audio/video types at all, not even with a low
3517 * - we want to detect GStreamer media types and not MIME types
3518 * - the purpose of this xdg mime finder is mainly to prevent false
3519 * positives of non-media formats, not to typefind audio/video formats */
3520 if (g_str_has_prefix (mimetype, "audio/") ||
3521 g_str_has_prefix (mimetype, "video/")) {
3522 GST_LOG ("Ignoring audio/video mime type");
3527 /* Again, we mainly want the xdg typefinding to prevent false-positives on
3528 * non-media formats, so suggest the type with a probability that trumps
3529 * uncertain results of our typefinders, but not more than that. */
3530 GST_LOG ("Suggesting '%s' with probability POSSIBLE", mimetype);
3531 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE, mimetype, NULL);
3534 #endif /* USE_GIO */
3536 /*** generic typefind for streams that have some data at a specific position***/
3547 start_with_type_find (GstTypeFind * tf, gpointer private)
3549 GstTypeFindData *start_with = (GstTypeFindData *) private;
3552 GST_LOG ("trying to find mime type %s with the first %u bytes of data",
3553 gst_structure_get_name (gst_caps_get_structure (start_with->caps, 0)),
3555 data = gst_type_find_peek (tf, 0, start_with->size);
3556 if (data && memcmp (data, start_with->data, start_with->size) == 0) {
3557 gst_type_find_suggest (tf, start_with->probability, start_with->caps);
3562 sw_data_destroy (GstTypeFindData * sw_data)
3564 if (G_LIKELY (sw_data->caps != NULL))
3565 gst_caps_unref (sw_data->caps);
3569 #define TYPE_FIND_REGISTER_START_WITH(plugin,name,rank,ext,_data,_size,_probability)\
3571 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
3572 sw_data->data = (const guint8 *)_data; \
3573 sw_data->size = _size; \
3574 sw_data->probability = _probability; \
3575 sw_data->caps = gst_caps_new_simple (name, NULL); \
3576 if (!gst_type_find_register (plugin, name, rank, start_with_type_find,\
3577 (char **) ext, sw_data->caps, sw_data, \
3578 (GDestroyNotify) (sw_data_destroy))) { \
3579 gst_caps_unref (sw_data->caps); \
3584 /*** same for riff types ***/
3587 riff_type_find (GstTypeFind * tf, gpointer private)
3589 GstTypeFindData *riff_data = (GstTypeFindData *) private;
3590 guint8 *data = gst_type_find_peek (tf, 0, 12);
3592 if (data && (memcmp (data, "RIFF", 4) == 0 || memcmp (data, "AVF0", 4) == 0)) {
3594 if (memcmp (data, riff_data->data, 4) == 0)
3595 gst_type_find_suggest (tf, riff_data->probability, riff_data->caps);
3599 #define TYPE_FIND_REGISTER_RIFF(plugin,name,rank,ext,_data) \
3601 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
3602 sw_data->data = (gpointer)_data; \
3603 sw_data->size = 4; \
3604 sw_data->probability = GST_TYPE_FIND_MAXIMUM; \
3605 sw_data->caps = gst_caps_new_simple (name, NULL); \
3606 if (!gst_type_find_register (plugin, name, rank, riff_type_find, \
3607 (char **) ext, sw_data->caps, sw_data, \
3608 (GDestroyNotify) (sw_data_destroy))) { \
3609 gst_caps_unref (sw_data->caps); \
3615 /*** plugin initialization ***/
3617 #define TYPE_FIND_REGISTER(plugin,name,rank,func,ext,caps,priv,notify) \
3619 if (!gst_type_find_register (plugin, name, rank, func, (char **) ext, caps, priv, notify))\
3625 plugin_init (GstPlugin * plugin)
3627 /* can't initialize this via a struct as caps can't be statically initialized */
3629 /* note: asx/wax/wmx are XML files, asf doesn't handle them */
3630 /* FIXME-0.11: these should be const,
3631 this requires gstreamer/gst/gsttypefind::gst_type_find_register()
3632 to have define the parameter as const
3634 static const gchar *asf_exts[] = { "asf", "wm", "wma", "wmv", NULL };
3635 static const gchar *au_exts[] = { "au", "snd", NULL };
3636 static const gchar *avi_exts[] = { "avi", NULL };
3637 static const gchar *qcp_exts[] = { "qcp", NULL };
3638 static const gchar *cdxa_exts[] = { "dat", NULL };
3639 static const gchar *flac_exts[] = { "flac", NULL };
3640 static const gchar *flx_exts[] = { "flc", "fli", NULL };
3641 static const gchar *id3_exts[] =
3642 { "mp3", "mp2", "mp1", "mpga", "ogg", "flac", "tta", NULL };
3643 static const gchar *apetag_exts[] = { "ape", "mpc", "wv", NULL }; /* and mp3 and wav? */
3644 static const gchar *tta_exts[] = { "tta", NULL };
3645 static const gchar *mod_exts[] = { "669", "amf", "dsm", "gdm", "far", "imf",
3646 "it", "med", "mod", "mtm", "okt", "sam",
3647 "s3m", "stm", "stx", "ult", "xm", NULL
3649 static const gchar *mp3_exts[] = { "mp3", "mp2", "mp1", "mpga", NULL };
3650 static const gchar *ac3_exts[] = { "ac3", NULL };
3651 static const gchar *gsm_exts[] = { "gsm", NULL };
3652 static const gchar *musepack_exts[] = { "mpc", "mpp", "mp+", NULL };
3653 static const gchar *mpeg_sys_exts[] = { "mpe", "mpeg", "mpg", NULL };
3654 static const gchar *mpeg_video_exts[] = { "mpv", "mpeg", "mpg", NULL };
3655 static const gchar *mpeg_ts_exts[] = { "ts", NULL };
3656 static const gchar *ogg_exts[] = { "anx", "ogg", "ogm", NULL };
3657 static const gchar *qt_exts[] = { "mov", NULL };
3658 static const gchar *qtif_exts[] = { "qif", "qtif", "qti", NULL };
3659 static const gchar *mj2_exts[] = { "mj2", NULL };
3660 static const gchar *jp2_exts[] = { "jp2", NULL };
3661 static const gchar *rm_exts[] = { "ra", "ram", "rm", "rmvb", NULL };
3662 static const gchar *swf_exts[] = { "swf", "swfl", NULL };
3663 static const gchar *utf8_exts[] = { "txt", NULL };
3664 static const gchar *wav_exts[] = { "wav", NULL };
3665 static const gchar *aiff_exts[] = { "aiff", "aif", "aifc", NULL };
3666 static const gchar *svx_exts[] = { "iff", "svx", NULL };
3667 static const gchar *paris_exts[] = { "paf", NULL };
3668 static const gchar *nist_exts[] = { "nist", NULL };
3669 static const gchar *voc_exts[] = { "voc", NULL };
3670 static const gchar *sds_exts[] = { "sds", NULL };
3671 static const gchar *ircam_exts[] = { "sf", NULL };
3672 static const gchar *w64_exts[] = { "w64", NULL };
3673 static const gchar *shn_exts[] = { "shn", NULL };
3674 static const gchar *ape_exts[] = { "ape", NULL };
3675 static const gchar *uri_exts[] = { "ram", NULL };
3676 static const gchar *sdp_exts[] = { "sdp", NULL };
3677 static const gchar *smil_exts[] = { "smil", NULL };
3678 static const gchar *html_exts[] = { "htm", "html", NULL };
3679 static const gchar *xml_exts[] = { "xml", NULL };
3680 static const gchar *jpeg_exts[] = { "jpg", "jpe", "jpeg", NULL };
3681 static const gchar *gif_exts[] = { "gif", NULL };
3682 static const gchar *png_exts[] = { "png", NULL };
3683 static const gchar *bmp_exts[] = { "bmp", NULL };
3684 static const gchar *tiff_exts[] = { "tif", "tiff", NULL };
3685 static const gchar *matroska_exts[] = { "mkv", "mka", NULL };
3686 static const gchar *webm_exts[] = { "webm", "weba", "webv", NULL };
3687 static const gchar *mve_exts[] = { "mve", NULL };
3688 static const gchar *dv_exts[] = { "dv", "dif", NULL };
3689 static const gchar *amr_exts[] = { "amr", NULL };
3690 static const gchar *ilbc_exts[] = { "ilbc", NULL };
3691 static const gchar *sid_exts[] = { "sid", NULL };
3692 static const gchar *xcf_exts[] = { "xcf", NULL };
3693 static const gchar *mng_exts[] = { "mng", NULL };
3694 static const gchar *jng_exts[] = { "jng", NULL };
3695 static const gchar *xpm_exts[] = { "xpm", NULL };
3696 static const gchar *pnm_exts[] = { "pnm", "ppm", "pgm", "pbm", NULL };
3697 static const gchar *ras_exts[] = { "ras", NULL };
3698 static const gchar *bz2_exts[] = { "bz2", NULL };
3699 static const gchar *gz_exts[] = { "gz", NULL };
3700 static const gchar *zip_exts[] = { "zip", NULL };
3701 static const gchar *compress_exts[] = { "Z", NULL };
3702 static const gchar *m4a_exts[] = { "m4a", NULL };
3703 static const gchar *q3gp_exts[] = { "3gp", NULL };
3704 static const gchar *aac_exts[] = { "aac", NULL };
3705 static const gchar *spc_exts[] = { "spc", NULL };
3706 static const gchar *wavpack_exts[] = { "wv", "wvp", NULL };
3707 static const gchar *wavpack_correction_exts[] = { "wvc", NULL };
3708 static const gchar *rar_exts[] = { "rar", NULL };
3709 static const gchar *tar_exts[] = { "tar", NULL };
3710 static const gchar *ar_exts[] = { "a", NULL };
3711 static const gchar *msdos_exts[] = { "dll", "exe", "ocx", "sys", "scr",
3712 "msstyles", "cpl", NULL
3714 static const gchar *flv_exts[] = { "flv", NULL };
3715 static const gchar *m4v_exts[] = { "m4v", NULL };
3716 static const gchar *h264_exts[] = { "h264", "x264", "264", NULL };
3717 static const gchar *nuv_exts[] = { "nuv", NULL };
3718 static const gchar *vivo_exts[] = { "viv", NULL };
3719 static const gchar *nsf_exts[] = { "nsf", NULL };
3720 static const gchar *gym_exts[] = { "gym", NULL };
3721 static const gchar *ay_exts[] = { "ay", NULL };
3722 static const gchar *gbs_exts[] = { "gbs", NULL };
3723 static const gchar *kss_exts[] = { "kss", NULL };
3724 static const gchar *sap_exts[] = { "sap", NULL };
3725 static const gchar *vgm_exts[] = { "vgm", NULL };
3726 static const gchar *mid_exts[] = { "mid", "midi", NULL };
3727 static const gchar *mxmf_exts[] = { "mxmf", NULL };
3728 static const gchar *imelody_exts[] = { "imy", "ime", "imelody", NULL };
3729 static const gchar *pdf_exts[] = { "pdf", NULL };
3730 static const gchar *ps_exts[] = { "ps", NULL };
3731 static const gchar *svg_exts[] = { "svg", NULL };
3732 static const gchar *mxf_exts[] = { "mxf", NULL };
3733 static const gchar *ivf_exts[] = { "ivf", NULL };
3734 static const gchar *msword_exts[] = { "doc", NULL };
3735 static const gchar *dsstore_exts[] = { "DS_Store", NULL };
3736 static const gchar *psd_exts[] = { "psd", NULL };
3738 GST_DEBUG_CATEGORY_INIT (type_find_debug, "typefindfunctions",
3739 GST_DEBUG_FG_GREEN | GST_DEBUG_BG_RED, "generic type find functions");
3741 /* must use strings, macros don't accept initializers */
3742 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ms-asf", GST_RANK_SECONDARY,
3744 "\060\046\262\165\216\146\317\021\246\331\000\252\000\142\316\154", 16,
3745 GST_TYPE_FIND_MAXIMUM);
3746 TYPE_FIND_REGISTER (plugin, "audio/x-musepack", GST_RANK_PRIMARY,
3747 musepack_type_find, musepack_exts, MUSEPACK_CAPS, NULL, NULL);
3748 TYPE_FIND_REGISTER (plugin, "audio/x-au", GST_RANK_MARGINAL,
3749 au_type_find, au_exts, AU_CAPS, NULL, NULL);
3750 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-msvideo", GST_RANK_PRIMARY,
3752 TYPE_FIND_REGISTER_RIFF (plugin, "audio/qcelp", GST_RANK_PRIMARY,
3754 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-cdxa", GST_RANK_PRIMARY,
3756 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-vcd", GST_RANK_PRIMARY,
3757 cdxa_exts, "\000\377\377\377\377\377\377\377\377\377\377\000", 12,
3758 GST_TYPE_FIND_MAXIMUM);
3759 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-imelody", GST_RANK_PRIMARY,
3760 imelody_exts, "BEGIN:IMELODY", 13, GST_TYPE_FIND_MAXIMUM);
3762 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-smoke", GST_RANK_PRIMARY,
3763 NULL, "\x80smoke\x00\x01\x00", 6, GST_TYPE_FIND_MAXIMUM);
3765 TYPE_FIND_REGISTER (plugin, "audio/midi", GST_RANK_PRIMARY, mid_type_find,
3766 mid_exts, MID_CAPS, NULL, NULL);
3767 TYPE_FIND_REGISTER_RIFF (plugin, "audio/riff-midi", GST_RANK_PRIMARY,
3769 TYPE_FIND_REGISTER (plugin, "audio/mobile-xmf", GST_RANK_PRIMARY,
3770 mxmf_type_find, mxmf_exts, MXMF_CAPS, NULL, NULL);
3771 TYPE_FIND_REGISTER (plugin, "video/x-fli", GST_RANK_MARGINAL, flx_type_find,
3772 flx_exts, FLX_CAPS, NULL, NULL);
3773 TYPE_FIND_REGISTER (plugin, "application/x-id3v2", GST_RANK_PRIMARY + 103,
3774 id3v2_type_find, id3_exts, ID3_CAPS, NULL, NULL);
3775 TYPE_FIND_REGISTER (plugin, "application/x-id3v1", GST_RANK_PRIMARY + 101,
3776 id3v1_type_find, id3_exts, ID3_CAPS, NULL, NULL);
3777 TYPE_FIND_REGISTER (plugin, "application/x-apetag", GST_RANK_PRIMARY + 102,
3778 apetag_type_find, apetag_exts, APETAG_CAPS, NULL, NULL);
3779 TYPE_FIND_REGISTER (plugin, "audio/x-ttafile", GST_RANK_PRIMARY,
3780 tta_type_find, tta_exts, TTA_CAPS, NULL, NULL);
3781 TYPE_FIND_REGISTER (plugin, "audio/x-mod", GST_RANK_SECONDARY, mod_type_find,
3782 mod_exts, MOD_CAPS, NULL, NULL);
3783 TYPE_FIND_REGISTER (plugin, "audio/mpeg", GST_RANK_PRIMARY, mp3_type_find,
3784 mp3_exts, MP3_CAPS, NULL, NULL);
3785 TYPE_FIND_REGISTER (plugin, "audio/x-ac3", GST_RANK_PRIMARY, ac3_type_find,
3786 ac3_exts, AC3_CAPS, NULL, NULL);
3787 TYPE_FIND_REGISTER (plugin, "audio/x-gsm", GST_RANK_PRIMARY, NULL, gsm_exts,
3788 GSM_CAPS, NULL, NULL);
3789 TYPE_FIND_REGISTER (plugin, "video/mpeg-sys", GST_RANK_PRIMARY,
3790 mpeg_sys_type_find, mpeg_sys_exts, MPEG_SYS_CAPS, NULL, NULL);
3791 TYPE_FIND_REGISTER (plugin, "video/mpegts", GST_RANK_PRIMARY,
3792 mpeg_ts_type_find, mpeg_ts_exts, MPEGTS_CAPS, NULL, NULL);
3793 TYPE_FIND_REGISTER (plugin, "application/ogg", GST_RANK_PRIMARY,
3794 ogganx_type_find, ogg_exts, OGGANX_CAPS, NULL, NULL);
3795 TYPE_FIND_REGISTER (plugin, "video/mpeg-elementary", GST_RANK_MARGINAL,
3796 mpeg_video_stream_type_find, mpeg_video_exts, MPEG_VIDEO_CAPS, NULL,
3798 TYPE_FIND_REGISTER (plugin, "video/mpeg4", GST_RANK_PRIMARY,
3799 mpeg4_video_type_find, m4v_exts, MPEG_VIDEO_CAPS, NULL, NULL);
3800 TYPE_FIND_REGISTER (plugin, "video/x-h264", GST_RANK_PRIMARY,
3801 h264_video_type_find, h264_exts, MPEG_VIDEO_CAPS, NULL, NULL);
3802 TYPE_FIND_REGISTER (plugin, "video/x-nuv", GST_RANK_SECONDARY, nuv_type_find,
3803 nuv_exts, NUV_CAPS, NULL, NULL);
3806 TYPE_FIND_REGISTER (plugin, "audio/x-m4a", GST_RANK_PRIMARY, m4a_type_find,
3807 m4a_exts, M4A_CAPS, NULL, NULL);
3808 TYPE_FIND_REGISTER (plugin, "application/x-3gp", GST_RANK_PRIMARY,
3809 q3gp_type_find, q3gp_exts, Q3GP_CAPS, NULL, NULL);
3810 TYPE_FIND_REGISTER (plugin, "video/quicktime", GST_RANK_SECONDARY,
3811 qt_type_find, qt_exts, QT_CAPS, NULL, NULL);
3812 TYPE_FIND_REGISTER (plugin, "image/x-quicktime", GST_RANK_SECONDARY,
3813 qtif_type_find, qtif_exts, QTIF_CAPS, NULL, NULL);
3814 TYPE_FIND_REGISTER (plugin, "image/jp2", GST_RANK_PRIMARY,
3815 jp2_type_find, jp2_exts, JP2_CAPS, NULL, NULL);
3816 TYPE_FIND_REGISTER (plugin, "video/mj2", GST_RANK_PRIMARY,
3817 jp2_type_find, mj2_exts, MJ2_CAPS, NULL, NULL);
3819 TYPE_FIND_REGISTER (plugin, "text/html", GST_RANK_SECONDARY, html_type_find,
3820 html_exts, HTML_CAPS, NULL, NULL);
3821 TYPE_FIND_REGISTER_START_WITH (plugin, "application/vnd.rn-realmedia",
3822 GST_RANK_SECONDARY, rm_exts, ".RMF", 4, GST_TYPE_FIND_MAXIMUM);
3823 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-pn-realaudio",
3824 GST_RANK_SECONDARY, rm_exts, ".ra\375", 4, GST_TYPE_FIND_MAXIMUM);
3825 TYPE_FIND_REGISTER (plugin, "application/x-shockwave-flash",
3826 GST_RANK_SECONDARY, swf_type_find, swf_exts, SWF_CAPS, NULL, NULL);
3827 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-flv", GST_RANK_SECONDARY,
3828 flv_exts, "FLV", 3, GST_TYPE_FIND_MAXIMUM);
3829 TYPE_FIND_REGISTER (plugin, "text/plain", GST_RANK_MARGINAL, utf8_type_find,
3830 utf8_exts, UTF8_CAPS, NULL, NULL);
3831 TYPE_FIND_REGISTER (plugin, "text/uri-list", GST_RANK_MARGINAL, uri_type_find,
3832 uri_exts, URI_CAPS, NULL, NULL);
3833 TYPE_FIND_REGISTER (plugin, "application/sdp", GST_RANK_SECONDARY,
3834 sdp_type_find, sdp_exts, SDP_CAPS, NULL, NULL);
3835 TYPE_FIND_REGISTER (plugin, "application/smil", GST_RANK_SECONDARY,
3836 smil_type_find, smil_exts, SMIL_CAPS, NULL, NULL);
3837 TYPE_FIND_REGISTER (plugin, "application/xml", GST_RANK_MARGINAL,
3838 xml_type_find, xml_exts, GENERIC_XML_CAPS, NULL, NULL);
3839 TYPE_FIND_REGISTER_RIFF (plugin, "audio/x-wav", GST_RANK_PRIMARY, wav_exts,
3841 TYPE_FIND_REGISTER (plugin, "audio/x-aiff", GST_RANK_SECONDARY,
3842 aiff_type_find, aiff_exts, AIFF_CAPS, NULL, NULL);
3843 TYPE_FIND_REGISTER (plugin, "audio/x-svx", GST_RANK_SECONDARY, svx_type_find,
3844 svx_exts, SVX_CAPS, NULL, NULL);
3845 TYPE_FIND_REGISTER (plugin, "audio/x-paris", GST_RANK_SECONDARY,
3846 paris_type_find, paris_exts, PARIS_CAPS, NULL, NULL);
3847 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nist", GST_RANK_SECONDARY,
3848 nist_exts, "NIST", 4, GST_TYPE_FIND_MAXIMUM);
3849 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-voc", GST_RANK_SECONDARY,
3850 voc_exts, "Creative", 8, GST_TYPE_FIND_MAXIMUM);
3851 TYPE_FIND_REGISTER (plugin, "audio/x-sds", GST_RANK_SECONDARY, sds_type_find,
3852 sds_exts, SDS_CAPS, NULL, NULL);
3853 TYPE_FIND_REGISTER (plugin, "audio/x-ircam", GST_RANK_SECONDARY,
3854 ircam_type_find, ircam_exts, IRCAM_CAPS, NULL, NULL);
3855 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-w64", GST_RANK_SECONDARY,
3856 w64_exts, "riff", 4, GST_TYPE_FIND_MAXIMUM);
3857 TYPE_FIND_REGISTER (plugin, "audio/x-shorten", GST_RANK_SECONDARY,
3858 shn_type_find, shn_exts, SHN_CAPS, NULL, NULL);
3859 TYPE_FIND_REGISTER (plugin, "application/x-ape", GST_RANK_SECONDARY,
3860 ape_type_find, ape_exts, APE_CAPS, NULL, NULL);
3861 TYPE_FIND_REGISTER (plugin, "image/jpeg", GST_RANK_PRIMARY + 15,
3862 jpeg_type_find, jpeg_exts, JPEG_CAPS, NULL, NULL);
3863 TYPE_FIND_REGISTER_START_WITH (plugin, "image/gif", GST_RANK_PRIMARY,
3864 gif_exts, "GIF8", 4, GST_TYPE_FIND_MAXIMUM);
3865 TYPE_FIND_REGISTER_START_WITH (plugin, "image/png", GST_RANK_PRIMARY + 14,
3866 png_exts, "\211PNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
3867 TYPE_FIND_REGISTER (plugin, "image/bmp", GST_RANK_PRIMARY, bmp_type_find,
3868 bmp_exts, BMP_CAPS, NULL, NULL);
3869 TYPE_FIND_REGISTER (plugin, "image/tiff", GST_RANK_PRIMARY, tiff_type_find,
3870 tiff_exts, TIFF_CAPS, NULL, NULL);
3871 TYPE_FIND_REGISTER (plugin, "image/x-portable-pixmap", GST_RANK_SECONDARY,
3872 pnm_type_find, pnm_exts, PNM_CAPS, NULL, NULL);
3873 TYPE_FIND_REGISTER (plugin, "video/x-matroska", GST_RANK_PRIMARY,
3874 matroska_type_find, matroska_exts, MATROSKA_CAPS, NULL, NULL);
3875 TYPE_FIND_REGISTER (plugin, "video/webm", GST_RANK_PRIMARY,
3876 webm_type_find, webm_exts, WEBM_CAPS, NULL, NULL);
3877 TYPE_FIND_REGISTER (plugin, "application/mxf", GST_RANK_PRIMARY,
3878 mxf_type_find, mxf_exts, MXF_CAPS, NULL, NULL);
3879 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mve", GST_RANK_SECONDARY,
3880 mve_exts, "Interplay MVE File\032\000\032\000\000\001\063\021", 26,
3881 GST_TYPE_FIND_MAXIMUM);
3882 TYPE_FIND_REGISTER (plugin, "video/x-dv", GST_RANK_SECONDARY, dv_type_find,
3883 dv_exts, DV_CAPS, NULL, NULL);
3884 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-nb-sh", GST_RANK_PRIMARY,
3885 amr_exts, "#!AMR", 5, GST_TYPE_FIND_LIKELY);
3886 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-wb-sh", GST_RANK_PRIMARY,
3887 amr_exts, "#!AMR-WB", 7, GST_TYPE_FIND_MAXIMUM);
3888 TYPE_FIND_REGISTER (plugin, "audio/iLBC-sh", GST_RANK_PRIMARY,
3889 ilbc_type_find, ilbc_exts, ILBC_CAPS, NULL, NULL);
3890 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sid", GST_RANK_MARGINAL,
3891 sid_exts, "PSID", 4, GST_TYPE_FIND_MAXIMUM);
3892 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xcf", GST_RANK_SECONDARY,
3893 xcf_exts, "gimp xcf", 8, GST_TYPE_FIND_MAXIMUM);
3894 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mng", GST_RANK_SECONDARY,
3895 mng_exts, "\212MNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
3896 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-jng", GST_RANK_SECONDARY,
3897 jng_exts, "\213JNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
3898 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xpixmap", GST_RANK_SECONDARY,
3899 xpm_exts, "/* XPM */", 9, GST_TYPE_FIND_MAXIMUM);
3900 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-sun-raster",
3901 GST_RANK_SECONDARY, ras_exts, "\131\246\152\225", 4,
3902 GST_TYPE_FIND_MAXIMUM);
3903 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-bzip",
3904 GST_RANK_SECONDARY, bz2_exts, "BZh", 3, GST_TYPE_FIND_LIKELY);
3905 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-gzip",
3906 GST_RANK_SECONDARY, gz_exts, "\037\213", 2, GST_TYPE_FIND_LIKELY);
3907 TYPE_FIND_REGISTER_START_WITH (plugin, "application/zip", GST_RANK_SECONDARY,
3908 zip_exts, "PK\003\004", 4, GST_TYPE_FIND_LIKELY);
3909 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-compress",
3910 GST_RANK_SECONDARY, compress_exts, "\037\235", 2, GST_TYPE_FIND_LIKELY);
3911 TYPE_FIND_REGISTER (plugin, "subtitle/x-kate", GST_RANK_MARGINAL,
3912 kate_type_find, NULL, NULL, NULL, NULL);
3913 TYPE_FIND_REGISTER (plugin, "audio/x-flac", GST_RANK_PRIMARY,
3914 flac_type_find, flac_exts, FLAC_CAPS, NULL, NULL);
3915 TYPE_FIND_REGISTER (plugin, "audio/x-vorbis", GST_RANK_PRIMARY,
3916 vorbis_type_find, NULL, VORBIS_CAPS, NULL, NULL);
3917 TYPE_FIND_REGISTER (plugin, "video/x-theora", GST_RANK_PRIMARY,
3918 theora_type_find, NULL, THEORA_CAPS, NULL, NULL);
3919 TYPE_FIND_REGISTER (plugin, "application/x-ogm-video", GST_RANK_PRIMARY,
3920 ogmvideo_type_find, NULL, OGMVIDEO_CAPS, NULL, NULL);
3921 TYPE_FIND_REGISTER (plugin, "application/x-ogm-audio", GST_RANK_PRIMARY,
3922 ogmaudio_type_find, NULL, OGMAUDIO_CAPS, NULL, NULL);
3923 TYPE_FIND_REGISTER (plugin, "application/x-ogm-text", GST_RANK_PRIMARY,
3924 ogmtext_type_find, NULL, OGMTEXT_CAPS, NULL, NULL);
3925 TYPE_FIND_REGISTER (plugin, "audio/x-speex", GST_RANK_PRIMARY,
3926 speex_type_find, NULL, SPEEX_CAPS, NULL, NULL);
3927 TYPE_FIND_REGISTER (plugin, "audio/x-celt", GST_RANK_PRIMARY,
3928 celt_type_find, NULL, CELT_CAPS, NULL, NULL);
3929 TYPE_FIND_REGISTER (plugin, "application/x-ogg-skeleton", GST_RANK_PRIMARY,
3930 oggskel_type_find, NULL, OGG_SKELETON_CAPS, NULL, NULL);
3931 TYPE_FIND_REGISTER (plugin, "text/x-cmml", GST_RANK_PRIMARY, cmml_type_find,
3932 NULL, CMML_CAPS, NULL, NULL);
3933 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-executable",
3934 GST_RANK_MARGINAL, NULL, "\177ELF", 4, GST_TYPE_FIND_MAXIMUM);
3935 TYPE_FIND_REGISTER (plugin, "adts_mpeg_stream", GST_RANK_SECONDARY,
3936 aac_type_find, aac_exts, AAC_CAPS, NULL, NULL);
3937 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-spc", GST_RANK_SECONDARY,
3938 spc_exts, "SNES-SPC700 Sound File Data", 27, GST_TYPE_FIND_MAXIMUM);
3939 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack", GST_RANK_SECONDARY,
3940 wavpack_type_find, wavpack_exts, WAVPACK_CAPS, NULL, NULL);
3941 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack-correction", GST_RANK_SECONDARY,
3942 wavpack_type_find, wavpack_correction_exts, WAVPACK_CORRECTION_CAPS, NULL,
3944 TYPE_FIND_REGISTER (plugin, "application/postscript", GST_RANK_SECONDARY,
3945 postscript_type_find, ps_exts, POSTSCRIPT_CAPS, NULL, NULL);
3946 TYPE_FIND_REGISTER (plugin, "image/svg+xml", GST_RANK_SECONDARY,
3947 svg_type_find, svg_exts, SVG_CAPS, NULL, NULL);
3948 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-rar",
3949 GST_RANK_SECONDARY, rar_exts, "Rar!", 4, GST_TYPE_FIND_LIKELY);
3950 TYPE_FIND_REGISTER (plugin, "application/x-tar", GST_RANK_SECONDARY,
3951 tar_type_find, tar_exts, TAR_CAPS, NULL, NULL);
3952 TYPE_FIND_REGISTER (plugin, "application/x-ar", GST_RANK_SECONDARY,
3953 ar_type_find, ar_exts, AR_CAPS, NULL, NULL);
3954 TYPE_FIND_REGISTER (plugin, "application/x-ms-dos-executable",
3955 GST_RANK_SECONDARY, msdos_type_find, msdos_exts, MSDOS_CAPS, NULL, NULL);
3956 TYPE_FIND_REGISTER (plugin, "video/x-dirac", GST_RANK_PRIMARY,
3957 dirac_type_find, NULL, DIRAC_CAPS, NULL, NULL);
3958 TYPE_FIND_REGISTER (plugin, "multipart/x-mixed-replace", GST_RANK_SECONDARY,
3959 multipart_type_find, NULL, MULTIPART_CAPS, NULL, NULL);
3960 TYPE_FIND_REGISTER (plugin, "application/x-mmsh", GST_RANK_SECONDARY,
3961 mmsh_type_find, NULL, MMSH_CAPS, NULL, NULL);
3962 TYPE_FIND_REGISTER (plugin, "video/vivo", GST_RANK_SECONDARY,
3963 vivo_type_find, vivo_exts, VIVO_CAPS, NULL, NULL);
3964 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nsf",
3965 GST_RANK_SECONDARY, nsf_exts, "NESM\x1a", 5, GST_TYPE_FIND_MAXIMUM);
3966 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gym",
3967 GST_RANK_SECONDARY, gym_exts, "GYMX", 4, GST_TYPE_FIND_MAXIMUM);
3968 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-ay",
3969 GST_RANK_SECONDARY, ay_exts, "ZXAYEMUL", 8, GST_TYPE_FIND_MAXIMUM);
3970 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gbs",
3971 GST_RANK_SECONDARY, gbs_exts, "GBS\x01", 4, GST_TYPE_FIND_MAXIMUM);
3972 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-vgm",
3973 GST_RANK_SECONDARY, vgm_exts, "Vgm\x20", 4, GST_TYPE_FIND_MAXIMUM);
3974 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sap",
3975 GST_RANK_SECONDARY, sap_exts, "SAP\x0d\x0aAUTHOR\x20", 12,
3976 GST_TYPE_FIND_MAXIMUM);
3977 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ivf", GST_RANK_SECONDARY,
3978 ivf_exts, "DKIF", 4, GST_TYPE_FIND_NEARLY_CERTAIN);
3979 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-kss", GST_RANK_SECONDARY,
3980 kss_exts, "KSSX\0", 5, GST_TYPE_FIND_MAXIMUM);
3981 TYPE_FIND_REGISTER_START_WITH (plugin, "application/pdf", GST_RANK_SECONDARY,
3982 pdf_exts, "%PDF-", 5, GST_TYPE_FIND_LIKELY);
3983 TYPE_FIND_REGISTER_START_WITH (plugin, "application/msword",
3984 GST_RANK_SECONDARY, msword_exts, "\320\317\021\340\241\261\032\341", 8,
3985 GST_TYPE_FIND_LIKELY);
3986 /* Mac OS X .DS_Store files tend to be taken for video/mpeg */
3987 TYPE_FIND_REGISTER_START_WITH (plugin, "application/octet-stream",
3988 GST_RANK_SECONDARY, dsstore_exts, "\000\000\000\001Bud1", 8,
3989 GST_TYPE_FIND_LIKELY);
3990 TYPE_FIND_REGISTER_START_WITH (plugin, "image/vnd.adobe.photoshop",
3991 GST_RANK_SECONDARY, psd_exts, "8BPS\000\001\000\000\000\000", 10,
3992 GST_TYPE_FIND_LIKELY);
3995 TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,
3996 xdgmime_typefind, NULL, NULL, NULL, NULL);
4002 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
4004 "typefindfunctions",
4005 "default typefind functions",
4006 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)