2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3 * Copyright (C) 2005-2009 Tim-Philipp Müller <tim centricular net>
4 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * gsttypefindfunctions.c: collection of various typefind functions
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 #include <glib/gprintf.h>
31 /* don't want to add gio xdgmime typefinder if gio was disabled via configure */
43 #include "gstaacutil.h"
45 GST_DEBUG_CATEGORY_STATIC (type_find_debug);
46 #define GST_CAT_DEFAULT type_find_debug
48 /* DataScanCtx: helper for typefind functions that scan through data
49 * step-by-step, to avoid doing a peek at each and every offset */
51 #define DATA_SCAN_CTX_CHUNK_SIZE 4096
61 data_scan_ctx_advance (GstTypeFind * tf, DataScanCtx * c, guint bytes_to_skip)
63 c->offset += bytes_to_skip;
64 if (G_LIKELY (c->size > bytes_to_skip)) {
65 c->size -= bytes_to_skip;
66 c->data += bytes_to_skip;
73 static inline gboolean
74 data_scan_ctx_ensure_data (GstTypeFind * tf, DataScanCtx * c, gint min_len)
78 guint chunk_len = MAX (DATA_SCAN_CTX_CHUNK_SIZE, min_len);
80 if (G_LIKELY (c->size >= min_len))
83 data = gst_type_find_peek (tf, c->offset, chunk_len);
84 if (G_LIKELY (data != NULL)) {
90 /* if there's less than our chunk size, try to get as much as we can, but
91 * always at least min_len bytes (we might be typefinding the first buffer
92 * of the stream and not have as much data available as we'd like) */
93 len = gst_type_find_get_length (tf);
95 len = CLAMP (len - c->offset, min_len, chunk_len);
100 data = gst_type_find_peek (tf, c->offset, len);
110 static inline gboolean
111 data_scan_ctx_memcmp (GstTypeFind * tf, DataScanCtx * c, guint offset,
112 const gchar * data, guint len)
114 if (!data_scan_ctx_ensure_data (tf, c, offset + len))
117 return (memcmp (c->data + offset, data, len) == 0);
121 static gboolean xml_check_first_element (GstTypeFind * tf,
122 const gchar * element, guint elen, gboolean strict);
123 static gboolean sdp_check_header (GstTypeFind * tf);
125 static GstStaticCaps utf8_caps = GST_STATIC_CAPS ("text/plain");
127 #define UTF8_CAPS gst_static_caps_get(&utf8_caps)
130 utf8_type_find_have_valid_utf8_at_offset (GstTypeFind * tf, guint64 offset,
131 GstTypeFindProbability * prob)
135 /* randomly decided values */
136 guint min_size = 16; /* minimum size */
137 guint size = 32 * 1024; /* starting size */
138 guint probability = 95; /* starting probability */
139 guint step = 10; /* how much we reduce probability in each
142 while (probability > step && size > min_size) {
143 data = gst_type_find_peek (tf, offset, size);
146 gchar *start = (gchar *) data;
148 if (g_utf8_validate (start, size, (const gchar **) &end) || (end - start + 4 > size)) { /* allow last char to be cut off */
163 utf8_type_find (GstTypeFind * tf, gpointer unused)
165 GstTypeFindProbability start_prob, mid_prob;
168 /* leave xml to the xml typefinders */
169 if (xml_check_first_element (tf, "", 0, TRUE))
172 /* leave sdp to the sdp typefinders */
173 if (sdp_check_header (tf))
176 /* check beginning of stream */
177 if (!utf8_type_find_have_valid_utf8_at_offset (tf, 0, &start_prob))
180 GST_LOG ("start is plain text with probability of %u", start_prob);
182 /* POSSIBLE is the highest probability we ever return if we can't
183 * probe into the middle of the file and don't know its length */
185 length = gst_type_find_get_length (tf);
186 if (length == 0 || length == (guint64) - 1) {
187 gst_type_find_suggest (tf, MIN (start_prob, GST_TYPE_FIND_POSSIBLE),
192 if (length < 64 * 1024) {
193 gst_type_find_suggest (tf, start_prob, UTF8_CAPS);
197 /* check middle of stream */
198 if (!utf8_type_find_have_valid_utf8_at_offset (tf, length / 2, &mid_prob))
201 GST_LOG ("middle is plain text with probability of %u", mid_prob);
202 gst_type_find_suggest (tf, (start_prob + mid_prob) / 2, UTF8_CAPS);
205 /*** text/uri-list ***/
207 static GstStaticCaps uri_caps = GST_STATIC_CAPS ("text/uri-list");
209 #define URI_CAPS (gst_static_caps_get(&uri_caps))
210 #define BUFFER_SIZE 16 /* If the string is < 16 bytes we're screwed */
211 #define INC_BUFFER { \
213 if (pos == BUFFER_SIZE) { \
215 offset += BUFFER_SIZE; \
216 data = gst_type_find_peek (tf, offset, BUFFER_SIZE); \
217 if (data == NULL) return; \
223 uri_type_find (GstTypeFind * tf, gpointer unused)
225 guint8 *data = gst_type_find_peek (tf, 0, BUFFER_SIZE);
230 /* Search for # comment lines */
231 while (*data == '#') {
232 /* Goto end of line */
233 while (*data != '\n') {
240 if (!g_ascii_isalpha (*data)) {
241 /* Had a non alpha char - can't be uri-list */
247 while (g_ascii_isalnum (*data)) {
252 /* First non alpha char is not a : */
256 /* Get the next 2 bytes as well */
257 data = gst_type_find_peek (tf, offset + pos, 3);
261 if (data[1] != '/' && data[2] != '/') {
265 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, URI_CAPS);
270 /*** application/xml **********************************************************/
272 #define XML_BUFFER_SIZE 16
273 #define XML_INC_BUFFER { \
275 if (pos == XML_BUFFER_SIZE) { \
277 offset += XML_BUFFER_SIZE; \
278 data = gst_type_find_peek (tf, offset, XML_BUFFER_SIZE); \
279 if (data == NULL) return FALSE; \
286 xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen,
294 data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE);
298 /* look for the XMLDec
299 * see XML spec 2.8, Prolog and Document Type Declaration
300 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
301 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
303 if (strict && !got_xmldec)
306 /* skip XMLDec in any case if we've got one */
312 /* look for the first element, it has to be the requested element. Bail
313 * out if it is not within the first 4kB. */
314 while (data && (offset + pos) < 4096) {
315 while (*data != '<' && (offset + pos) < 4096) {
320 if (!g_ascii_isalpha (*data)) {
321 /* if not alphabetic, it's a PI or an element / attribute declaration
322 * like <?xxx or <!xxx */
327 /* the first normal element, check if it's the one asked for */
328 data = gst_type_find_peek (tf, offset + pos, elen + 1);
329 return (data && element && strncmp ((char *) data, element, elen) == 0);
335 static GstStaticCaps generic_xml_caps = GST_STATIC_CAPS ("application/xml");
337 #define GENERIC_XML_CAPS (gst_static_caps_get(&generic_xml_caps))
339 xml_type_find (GstTypeFind * tf, gpointer unused)
341 if (xml_check_first_element (tf, "", 0, TRUE)) {
342 gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, GENERIC_XML_CAPS);
346 /*** application/sdp *********************************************************/
348 static GstStaticCaps sdp_caps = GST_STATIC_CAPS ("application/sdp");
350 #define SDP_CAPS (gst_static_caps_get(&sdp_caps))
352 sdp_check_header (GstTypeFind * tf)
356 data = gst_type_find_peek (tf, 0, 5);
360 /* sdp must start with v=0[\r]\n */
361 if (memcmp (data, "v=0", 3))
364 if (data[3] == '\r' && data[4] == '\n')
373 sdp_type_find (GstTypeFind * tf, gpointer unused)
375 if (sdp_check_header (tf))
376 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDP_CAPS);
379 /*** application/smil *********************************************************/
381 static GstStaticCaps smil_caps = GST_STATIC_CAPS ("application/smil");
383 #define SMIL_CAPS (gst_static_caps_get(&smil_caps))
385 smil_type_find (GstTypeFind * tf, gpointer unused)
387 if (xml_check_first_element (tf, "smil", 4, FALSE)) {
388 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SMIL_CAPS);
394 static GstStaticCaps html_caps = GST_STATIC_CAPS ("text/html");
396 #define HTML_CAPS gst_static_caps_get (&html_caps)
399 html_type_find (GstTypeFind * tf, gpointer unused)
403 data = (gchar *) gst_type_find_peek (tf, 0, 16);
407 if (!g_ascii_strncasecmp (data, "<!DOCTYPE HTML", 14)) {
408 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
409 } else if (xml_check_first_element (tf, "html", 4, FALSE)) {
410 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
411 } else if ((d = memchr (data, '<', 16))) {
412 data = (gchar *) gst_type_find_peek (tf, d - data, 6);
413 if (data && g_ascii_strncasecmp (data, "<html>", 6) == 0) {
414 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
421 static GstStaticCaps mid_caps = GST_STATIC_CAPS ("audio/midi");
423 #define MID_CAPS gst_static_caps_get(&mid_caps)
425 mid_type_find (GstTypeFind * tf, gpointer unused)
427 guint8 *data = gst_type_find_peek (tf, 0, 4);
429 /* http://jedi.ks.uiuc.edu/~johns/links/music/midifile.html */
430 if (data && data[0] == 'M' && data[1] == 'T' && data[2] == 'h'
432 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MID_CAPS);
435 /*** audio/mobile-xmf ***/
437 static GstStaticCaps mxmf_caps = GST_STATIC_CAPS ("audio/mobile-xmf");
439 #define MXMF_CAPS gst_static_caps_get(&mxmf_caps)
441 mxmf_type_find (GstTypeFind * tf, gpointer unused)
445 /* Search FileId "XMF_" 4 bytes */
446 data = gst_type_find_peek (tf, 0, 4);
447 if (data && data[0] == 'X' && data[1] == 'M' && data[2] == 'F'
449 /* Search Format version "2.00" 4 bytes */
450 data = gst_type_find_peek (tf, 4, 4);
451 if (data && data[0] == '2' && data[1] == '.' && data[2] == '0'
453 /* Search TypeId 2 1 byte */
454 data = gst_type_find_peek (tf, 11, 1);
455 if (data && data[0] == 2) {
456 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXMF_CAPS);
463 /*** video/x-fli ***/
465 static GstStaticCaps flx_caps = GST_STATIC_CAPS ("video/x-fli");
467 #define FLX_CAPS gst_static_caps_get(&flx_caps)
469 flx_type_find (GstTypeFind * tf, gpointer unused)
471 guint8 *data = gst_type_find_peek (tf, 0, 134);
474 /* check magic and the frame type of the first frame */
475 if ((data[4] == 0x11 || data[4] == 0x12 ||
476 data[4] == 0x30 || data[4] == 0x44) &&
478 ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1)) {
479 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLX_CAPS);
483 data = gst_type_find_peek (tf, 0, 6);
485 /* check magic only */
486 if ((data[4] == 0x11 || data[4] == 0x12 ||
487 data[4] == 0x30 || data[4] == 0x44) && data[5] == 0xaf) {
488 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, FLX_CAPS);
494 /*** application/x-id3 ***/
496 static GstStaticCaps id3_caps = GST_STATIC_CAPS ("application/x-id3");
498 #define ID3_CAPS gst_static_caps_get(&id3_caps)
500 id3v2_type_find (GstTypeFind * tf, gpointer unused)
502 guint8 *data = gst_type_find_peek (tf, 0, 10);
504 if (data && memcmp (data, "ID3", 3) == 0 &&
505 data[3] != 0xFF && data[4] != 0xFF &&
506 (data[6] & 0x80) == 0 && (data[7] & 0x80) == 0 &&
507 (data[8] & 0x80) == 0 && (data[9] & 0x80) == 0) {
508 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
513 id3v1_type_find (GstTypeFind * tf, gpointer unused)
515 guint8 *data = gst_type_find_peek (tf, -128, 3);
517 if (data && memcmp (data, "TAG", 3) == 0) {
518 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
522 /*** application/x-ape ***/
524 static GstStaticCaps apetag_caps = GST_STATIC_CAPS ("application/x-apetag");
526 #define APETAG_CAPS gst_static_caps_get(&apetag_caps)
528 apetag_type_find (GstTypeFind * tf, gpointer unused)
532 /* APEv1/2 at start of file */
533 data = gst_type_find_peek (tf, 0, 8);
534 if (data && !memcmp (data, "APETAGEX", 8)) {
535 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
539 /* APEv1/2 at end of file */
540 data = gst_type_find_peek (tf, -32, 8);
541 if (data && !memcmp (data, "APETAGEX", 8)) {
542 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
547 /*** audio/x-ttafile ***/
549 static GstStaticCaps tta_caps = GST_STATIC_CAPS ("audio/x-ttafile");
551 #define TTA_CAPS gst_static_caps_get(&tta_caps)
553 tta_type_find (GstTypeFind * tf, gpointer unused)
555 guint8 *data = gst_type_find_peek (tf, 0, 3);
558 if (memcmp (data, "TTA", 3) == 0) {
559 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTA_CAPS);
565 /*** audio/x-flac ***/
566 static GstStaticCaps flac_caps = GST_STATIC_CAPS ("audio/x-flac");
568 #define FLAC_CAPS (gst_static_caps_get(&flac_caps))
571 flac_type_find (GstTypeFind * tf, gpointer unused)
573 DataScanCtx c = { 0, NULL, 0 };
575 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
578 /* standard flac (also old/broken flac-in-ogg with an initial 4-byte marker
579 * packet and without the usual packet framing) */
580 if (memcmp (c.data, "fLaC", 4) == 0) {
581 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
585 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
588 /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */
589 if (memcmp (c.data, "\177FLAC\001", 6) == 0) {
590 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
594 /* disabled because it happily typefinds /dev/urandom as audio/x-flac, and
595 * because I yet have to see header-less flac in the wild */
597 /* flac without headers (subset format) */
598 /* 64K should be enough */
599 while (c.offset < (64 * 1024)) {
600 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
603 /* look for frame header,
604 * http://flac.sourceforge.net/format.html#frame_header
606 if (c.data[0] == 0xff && (c.data[1] >> 2) == 0x3e) {
607 /* bit 15 in the header must be 0 */
608 if (((c.data[1] >> 1) & 0x01) == 0x01)
611 /* blocksize must be != 0x00 */
612 if ((c.data[2] >> 4) == 0x00)
615 /* samplerate must be != 0x0f */
616 if ((c.data[2] & 0x0f) == 0x0f)
618 /* also 0 is invalid, as it means get the info from the header and we
619 * don't have headers if we are here */
620 if ((c.data[2] & 0x0f) == 0x00)
623 /* channel assignment must be < 11 */
624 if ((c.data[3] >> 4) >= 11)
627 /* sample size must be != 0x07 and != 0x05 */
628 if (((c.data[3] >> 1) & 0x07) == 0x07)
630 if (((c.data[3] >> 1) & 0x07) == 0x05)
632 /* also 0 is invalid, as it means get the info from the header and we
633 * don't have headers if we are here */
634 if (((c.data[3] >> 1) & 0x07) == 0x00)
637 /* next bit must be 0 */
638 if ((c.data[3] & 0x01) == 0x01)
641 /* FIXME: shouldn't we include the crc check ? */
643 GST_DEBUG ("Found flac without headers at %d", (gint) c.offset);
644 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, FLAC_CAPS);
648 data_scan_ctx_advance (tf, &c, 1);
653 /*** audio/mpeg version 2, 4 ***/
655 static GstStaticCaps aac_caps = GST_STATIC_CAPS ("audio/mpeg, "
656 "mpegversion = (int) { 2, 4 }, framed = (bool) false");
657 #define AAC_CAPS (gst_static_caps_get(&aac_caps))
658 #define AAC_AMOUNT (4096)
660 aac_type_find (GstTypeFind * tf, gpointer unused)
662 /* LUT to convert the AudioObjectType from the ADTS header to a string */
663 static const gchar profile_to_string[][5] = { "main", "lc", "ssr", "ltp" };
664 static const guint sample_freq[] = { 96000, 88200, 64000, 48000, 44100,
665 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350
667 DataScanCtx c = { 0, NULL, 0 };
669 while (c.offset < AAC_AMOUNT) {
672 /* detect adts header or adif header.
673 * The ADIF header is 4 bytes, that should be OK. The ADTS header, on
674 * the other hand, is 14 bits only, so we require one valid frame with
675 * again a valid syncpoint on the next one (28 bits) for certainty. We
676 * require 4 kB, which is quite a lot, since frames are generally 200-400
679 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
682 snc = GST_READ_UINT16_BE (c.data);
683 if (G_UNLIKELY ((snc & 0xfff6) == 0xfff0)) {
684 /* ADTS header - find frame length */
685 GST_DEBUG ("Found one ADTS syncpoint at offset 0x%" G_GINT64_MODIFIER
686 "x, tracing next...", c.offset);
687 len = ((c.data[3] & 0x03) << 11) |
688 (c.data[4] << 3) | ((c.data[5] & 0xe0) >> 5);
690 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
691 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
695 /* check if there's a second ADTS frame */
696 snc = GST_READ_UINT16_BE (c.data + len);
697 if ((snc & 0xfff6) == 0xfff0) {
699 guint mpegversion, sample_freq_idx, channel_config, profile, rate;
702 mpegversion = (c.data[1] & 0x08) ? 2 : 4;
703 profile = c.data[2] >> 6;
704 sample_freq_idx = ((c.data[2] & 0x3c) >> 2);
705 channel_config = ((c.data[2] & 0x01) << 2) + (c.data[3] >> 6);
707 GST_DEBUG ("Found second ADTS-%d syncpoint at offset 0x%"
708 G_GINT64_MODIFIER "x, framelen %u", mpegversion, c.offset, len);
710 /* 0xd and 0xe are reserved. 0xf means the sample frequency is directly
711 * specified in the header, but that's not allowed for ADTS */
712 if (sample_freq_idx > 0xc) {
713 GST_DEBUG ("Unexpected sample frequency index %d or wrong sync",
718 rate = sample_freq[sample_freq_idx];
719 GST_LOG ("ADTS: profile=%u, rate=%u", profile, rate);
721 /* ADTS counts profiles from 0 instead of 1 to save bits */
722 level = gst_aac_level_from_header (profile + 1, rate, channel_config);
724 caps = gst_caps_new_simple ("audio/mpeg",
725 "framed", G_TYPE_BOOLEAN, FALSE,
726 "mpegversion", G_TYPE_INT, mpegversion,
727 "stream-type", G_TYPE_STRING, "adts",
728 "base-profile", G_TYPE_STRING, profile_to_string[profile],
729 "profile", G_TYPE_STRING, profile_to_string[profile], NULL);
734 /* we use a string here because h.264 levels are also strings and
735 * there aren't a lot of levels, so it's not too awkward to not use
736 * and integer here and keep the field type consistent with h.264 */
737 g_snprintf (level_str, sizeof (level_str), "%d", level);
738 gst_caps_set_simple (caps, "level", G_TYPE_STRING, level_str, NULL);
741 /* add rate and number of channels if we can */
742 if (channel_config != 0 && channel_config <= 7) {
743 const guint channels_map[] = { 0, 1, 2, 3, 4, 5, 6, 8 };
745 gst_caps_set_simple (caps, "channels", G_TYPE_INT,
746 channels_map[channel_config], "rate", G_TYPE_INT, rate, NULL);
749 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, caps);
750 gst_caps_unref (caps);
754 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
755 } else if (!memcmp (c.data, "ADIF", 4)) {
757 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
758 "framed", G_TYPE_BOOLEAN, FALSE, "mpegversion", G_TYPE_INT, 4,
759 "stream-format", G_TYPE_STRING, "adif", NULL);
765 data_scan_ctx_advance (tf, &c, 1);
769 /*** audio/mpeg version 1 ***/
772 * The chance that random data is identified as a valid mp3 header is 63 / 2^18
773 * (0.024%) per try. This makes the function for calculating false positives
774 * 1 - (1 - ((63 / 2 ^18) ^ GST_MP3_TYPEFIND_MIN_HEADERS)) ^ buffersize)
775 * This has the following probabilities of false positives:
776 * datasize MIN_HEADERS
778 * 4096 62.6% 0.02% 0% 0%
779 * 16384 98% 0.09% 0% 0%
780 * 1 MiB 100% 5.88% 0% 0%
781 * 1 GiB 100% 100% 1.44% 0%
782 * 1 TiB 100% 100% 100% 0.35%
783 * This means that the current choice (3 headers by most of the time 4096 byte
784 * buffers is pretty safe for now.
786 * The max. size of each frame is 1440 bytes, which means that for N frames to
787 * be detected, we need 1440 * GST_MP3_TYPEFIND_MIN_HEADERS + 3 bytes of data.
788 * Assuming we step into the stream right after the frame header, this
789 * means we need 1440 * (GST_MP3_TYPEFIND_MIN_HEADERS + 1) - 1 + 3 bytes
790 * of data (5762) to always detect any mp3.
793 static const guint mp3types_bitrates[2][3][16] =
794 { {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
795 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
796 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
797 {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
798 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
799 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}},
802 static const guint mp3types_freqs[3][3] = { {11025, 12000, 8000},
803 {22050, 24000, 16000},
804 {44100, 48000, 32000}
808 mp3_type_frame_length_from_header (guint32 header, guint * put_layer,
809 guint * put_channels, guint * put_bitrate, guint * put_samplerate,
810 gboolean * may_be_free_format, gint possible_free_framelen)
812 guint bitrate, layer, length, mode, samplerate, version, channels;
814 if ((header & 0xffe00000) != 0xffe00000)
817 /* we don't need extension, copyright, original or
818 * emphasis for the frame length */
826 length = header & 0x1;
829 /* sampling frequency */
830 samplerate = header & 0x3;
836 bitrate = header & 0xF;
837 if (bitrate == 0 && possible_free_framelen == -1) {
838 GST_LOG ("Possibly a free format mp3 - signalling");
839 *may_be_free_format = TRUE;
841 if (bitrate == 15 || (bitrate == 0 && possible_free_framelen == -1))
844 /* ignore error correction, too */
848 layer = 4 - (header & 0x3);
853 /* version 0=MPEG2.5; 2=MPEG2; 3=MPEG1 */
854 version = header & 0x3;
859 channels = (mode == 3) ? 1 : 2;
860 samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate];
864 length += possible_free_framelen;
865 bitrate = length * samplerate / 48000;
867 length += possible_free_framelen;
868 bitrate = length * samplerate /
869 ((layer == 3 && version != 3) ? 72000 : 144000);
873 bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate];
875 length = ((12000 * bitrate / samplerate) + length) * 4;
877 length += ((layer == 3
878 && version != 3) ? 72000 : 144000) * bitrate / samplerate;
882 GST_LOG ("mp3typefind: calculated mp3 frame length of %u bytes", length);
884 ("mp3typefind: samplerate = %u - bitrate = %u - layer = %u - version = %u"
885 " - channels = %u", samplerate, bitrate, layer, version, channels);
890 *put_channels = channels;
892 *put_bitrate = bitrate;
894 *put_samplerate = samplerate;
900 static GstStaticCaps mp3_caps = GST_STATIC_CAPS ("audio/mpeg, "
901 "mpegversion = (int) 1, layer = (int) [ 1, 3 ]");
902 #define MP3_CAPS (gst_static_caps_get(&mp3_caps))
904 * random values for typefinding
905 * if no more data is available, we will return a probability of
906 * (found_headers/TRY_HEADERS) * (MAXIMUM * (TRY_SYNC - bytes_skipped)
908 * if found_headers >= MIN_HEADERS
910 #define GST_MP3_TYPEFIND_MIN_HEADERS (2)
911 #define GST_MP3_TYPEFIND_TRY_HEADERS (5)
912 #define GST_MP3_TYPEFIND_TRY_SYNC (GST_TYPE_FIND_MAXIMUM * 100) /* 10kB */
913 #define GST_MP3_TYPEFIND_SYNC_SIZE (2048)
914 #define GST_MP3_WRONG_HEADER (10)
917 mp3_type_find_at_offset (GstTypeFind * tf, guint64 start_off,
918 guint * found_layer, GstTypeFindProbability * found_prob)
921 guint8 *data_end = NULL;
924 gint last_free_offset = -1;
925 gint last_free_framelen = -1;
926 gboolean headerstart = TRUE;
933 while (skipped < GST_MP3_TYPEFIND_TRY_SYNC) {
935 size = GST_MP3_TYPEFIND_SYNC_SIZE * 2;
938 data = gst_type_find_peek (tf, skipped + start_off, size);
939 } while (size > 10 && !data);
942 data_end = data + size;
945 guint8 *head_data = NULL;
946 guint layer = 0, bitrate, samplerate, channels;
947 guint found = 0; /* number of valid headers found */
948 guint64 offset = skipped;
950 while (found < GST_MP3_TYPEFIND_TRY_HEADERS) {
953 guint prev_layer = 0, prev_bitrate = 0;
954 guint prev_channels = 0, prev_samplerate = 0;
955 gboolean free = FALSE;
957 if ((gint64) (offset - skipped + 4) >= 0 &&
958 data + offset - skipped + 4 < data_end) {
959 head_data = data + offset - skipped;
961 head_data = gst_type_find_peek (tf, offset + start_off, 4);
965 head = GST_READ_UINT32_BE (head_data);
966 if (!(length = mp3_type_frame_length_from_header (head, &layer,
967 &channels, &bitrate, &samplerate, &free,
968 last_free_framelen))) {
970 if (last_free_offset == -1)
971 last_free_offset = offset;
973 last_free_framelen = offset - last_free_offset;
974 offset = last_free_offset;
978 last_free_framelen = -1;
981 /* Mark the fact that we didn't find a valid header at the beginning */
985 GST_LOG ("%d. header at offset %" G_GUINT64_FORMAT
986 " (0x%" G_GINT64_MODIFIER "x) was not an mp3 header "
987 "(possibly-free: %s)", found + 1, start_off + offset,
988 start_off + offset, free ? "yes" : "no");
991 if ((prev_layer && prev_layer != layer) ||
992 /* (prev_bitrate && prev_bitrate != bitrate) || <-- VBR */
993 (prev_samplerate && prev_samplerate != samplerate) ||
994 (prev_channels && prev_channels != channels)) {
995 /* this means an invalid property, or a change, which might mean
996 * that this is not a mp3 but just a random bytestream. It could
997 * be a freaking funky encoded mp3 though. We'll just not count
1000 prev_bitrate = bitrate;
1001 prev_channels = channels;
1002 prev_samplerate = samplerate;
1005 GST_LOG ("found %d. header at offset %" G_GUINT64_FORMAT " (0x%"
1006 G_GINT64_MODIFIER "X)", found, start_off + offset,
1007 start_off + offset);
1011 g_assert (found <= GST_MP3_TYPEFIND_TRY_HEADERS);
1012 if (head_data == NULL &&
1013 gst_type_find_peek (tf, offset + start_off - 1, 1) == NULL)
1014 /* Incomplete last frame - don't count it. */
1016 if (found == GST_MP3_TYPEFIND_TRY_HEADERS ||
1017 (found >= GST_MP3_TYPEFIND_MIN_HEADERS && head_data == NULL)) {
1018 /* we can make a valid guess */
1019 guint probability = found * GST_TYPE_FIND_MAXIMUM *
1020 (GST_MP3_TYPEFIND_TRY_SYNC - skipped) /
1021 GST_MP3_TYPEFIND_TRY_HEADERS / GST_MP3_TYPEFIND_TRY_SYNC;
1024 && probability > (GST_TYPE_FIND_MINIMUM + GST_MP3_WRONG_HEADER))
1025 probability -= GST_MP3_WRONG_HEADER;
1026 if (probability < GST_TYPE_FIND_MINIMUM)
1027 probability = GST_TYPE_FIND_MINIMUM;
1032 ("audio/mpeg calculated %u = %u * %u / %u * (%u - %"
1033 G_GUINT64_FORMAT ") / %u", probability, GST_TYPE_FIND_MAXIMUM,
1034 found, GST_MP3_TYPEFIND_TRY_HEADERS, GST_MP3_TYPEFIND_TRY_SYNC,
1035 (guint64) skipped, GST_MP3_TYPEFIND_TRY_SYNC);
1036 /* make sure we're not id3 tagged */
1037 head_data = gst_type_find_peek (tf, -128, 3);
1038 if (head_data && (memcmp (head_data, "TAG", 3) == 0)) {
1041 g_assert (probability <= GST_TYPE_FIND_MAXIMUM);
1043 *found_prob = probability;
1044 if (probability > 0)
1045 *found_layer = layer;
1056 mp3_type_find (GstTypeFind * tf, gpointer unused)
1058 GstTypeFindProbability prob, mid_prob;
1060 guint layer, mid_layer;
1063 mp3_type_find_at_offset (tf, 0, &layer, &prob);
1064 length = gst_type_find_get_length (tf);
1066 if (length == 0 || length == (guint64) - 1) {
1072 /* if we're pretty certain already, skip the additional check */
1073 if (prob >= GST_TYPE_FIND_LIKELY)
1076 mp3_type_find_at_offset (tf, length / 2, &mid_layer, &mid_prob);
1080 GST_LOG ("detected audio/mpeg only in the middle (p=%u)", mid_prob);
1086 if (layer != mid_layer) {
1087 GST_WARNING ("audio/mpeg layer discrepancy: %u vs. %u", layer, mid_layer);
1088 return; /* FIXME: or should we just go with the one in the middle? */
1091 /* detected mpeg audio both in middle of the file and at the start */
1092 prob = (prob + mid_prob) / 2;
1096 /* let's see if there's a valid header right at the start */
1097 data = gst_type_find_peek (tf, 0, 4); /* use min. frame size? */
1098 if (data && mp3_type_frame_length_from_header (GST_READ_UINT32_BE (data),
1099 &layer, NULL, NULL, NULL, NULL, 0) != 0) {
1101 prob = GST_TYPE_FIND_POSSIBLE - 10;
1103 prob = MAX (GST_TYPE_FIND_POSSIBLE - 10, prob + 10);
1113 g_return_if_fail (layer >= 1 && layer <= 3);
1115 gst_type_find_suggest_simple (tf, prob, "audio/mpeg",
1116 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, layer, NULL);
1120 /*** audio/x-musepack ***/
1122 static GstStaticCaps musepack_caps =
1123 GST_STATIC_CAPS ("audio/x-musepack, streamversion= (int) { 7, 8 }");
1125 #define MUSEPACK_CAPS (gst_static_caps_get(&musepack_caps))
1127 musepack_type_find (GstTypeFind * tf, gpointer unused)
1129 guint8 *data = gst_type_find_peek (tf, 0, 4);
1130 GstTypeFindProbability prop = GST_TYPE_FIND_MINIMUM;
1131 gint streamversion = -1;
1133 if (data && memcmp (data, "MP+", 3) == 0) {
1135 if ((data[3] & 0x7f) == 7) {
1136 prop = GST_TYPE_FIND_MAXIMUM;
1138 prop = GST_TYPE_FIND_LIKELY + 10;
1140 } else if (data && memcmp (data, "MPCK", 4) == 0) {
1142 prop = GST_TYPE_FIND_MAXIMUM;
1145 if (streamversion != -1) {
1146 gst_type_find_suggest_simple (tf, prop, "audio/x-musepack",
1147 "streamversion", G_TYPE_INT, streamversion, NULL);
1151 /*** audio/x-ac3 ***/
1152 /* FIXME 0.11: should be audio/ac3, but isn't for backwards compatibility */
1153 static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
1155 #define AC3_CAPS (gst_static_caps_get(&ac3_caps))
1157 static GstStaticCaps eac3_caps = GST_STATIC_CAPS ("audio/x-eac3");
1159 #define EAC3_CAPS (gst_static_caps_get(&eac3_caps))
1163 unsigned short bit_rate;
1164 unsigned short frm_size[3];
1167 static const struct ac3_frmsize ac3_frmsizecod_tbl[] = {
1170 {40, {80, 87, 120}},
1171 {40, {80, 88, 120}},
1172 {48, {96, 104, 144}},
1173 {48, {96, 105, 144}},
1174 {56, {112, 121, 168}},
1175 {56, {112, 122, 168}},
1176 {64, {128, 139, 192}},
1177 {64, {128, 140, 192}},
1178 {80, {160, 174, 240}},
1179 {80, {160, 175, 240}},
1180 {96, {192, 208, 288}},
1181 {96, {192, 209, 288}},
1182 {112, {224, 243, 336}},
1183 {112, {224, 244, 336}},
1184 {128, {256, 278, 384}},
1185 {128, {256, 279, 384}},
1186 {160, {320, 348, 480}},
1187 {160, {320, 349, 480}},
1188 {192, {384, 417, 576}},
1189 {192, {384, 418, 576}},
1190 {224, {448, 487, 672}},
1191 {224, {448, 488, 672}},
1192 {256, {512, 557, 768}},
1193 {256, {512, 558, 768}},
1194 {320, {640, 696, 960}},
1195 {320, {640, 697, 960}},
1196 {384, {768, 835, 1152}},
1197 {384, {768, 836, 1152}},
1198 {448, {896, 975, 1344}},
1199 {448, {896, 976, 1344}},
1200 {512, {1024, 1114, 1536}},
1201 {512, {1024, 1115, 1536}},
1202 {576, {1152, 1253, 1728}},
1203 {576, {1152, 1254, 1728}},
1204 {640, {1280, 1393, 1920}},
1205 {640, {1280, 1394, 1920}}
1209 ac3_type_find (GstTypeFind * tf, gpointer unused)
1211 DataScanCtx c = { 0, NULL, 0 };
1213 /* Search for an ac3 frame; not neccesarily right at the start, but give it
1214 * a lower probability if not found right at the start. Check that the
1215 * frame is followed by a second frame at the expected offset.
1216 * We could also check the two ac3 CRCs, but we don't do that right now */
1217 while (c.offset < 1024) {
1218 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 5)))
1221 if (c.data[0] == 0x0b && c.data[1] == 0x77) {
1222 guint bsid = (c.data[5] >> 3) & 0x1F;
1226 guint fscod = (c.data[4] >> 6) & 0x03;
1227 guint frmsizecod = c.data[4] & 0x3f;
1229 if (fscod < 3 && frmsizecod < 38) {
1230 DataScanCtx c_next = c;
1233 frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
1234 GST_LOG ("possible AC3 frame sync at offset %"
1235 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1236 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1237 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1239 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1240 guint fscod2 = (c_next.data[4] >> 6) & 0x03;
1241 guint frmsizecod2 = c_next.data[4] & 0x3f;
1243 if (fscod == fscod2 && frmsizecod == frmsizecod2) {
1244 GstTypeFindProbability prob;
1246 GST_LOG ("found second AC3 frame, looks good");
1248 prob = GST_TYPE_FIND_MAXIMUM;
1250 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1252 gst_type_find_suggest (tf, prob, AC3_CAPS);
1256 GST_LOG ("no second AC3 frame found, false sync");
1262 DataScanCtx c_next = c;
1265 frame_size = ((((c.data[2] & 0x07) << 8) +
1266 (c.data[3] & 0xff)) + 1) << 1;
1267 GST_LOG ("possible E-AC3 frame sync at offset %"
1268 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1269 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1270 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1272 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1273 GstTypeFindProbability prob;
1275 GST_LOG ("found second E-AC3 frame, looks good");
1277 prob = GST_TYPE_FIND_MAXIMUM;
1279 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1281 gst_type_find_suggest (tf, prob, EAC3_CAPS);
1283 GST_LOG ("no second E-AC3 frame found, false sync");
1288 data_scan_ctx_advance (tf, &c, 1);
1292 /*** audio/x-dts ***/
1293 static GstStaticCaps dts_caps = GST_STATIC_CAPS ("audio/x-dts");
1294 #define DTS_CAPS (gst_static_caps_get (&dts_caps))
1295 #define DTS_MIN_FRAMESIZE 96
1296 #define DTS_MAX_FRAMESIZE 18725 /* 16384*16/14 */
1299 dts_parse_frame_header (DataScanCtx * c, guint * frame_size,
1300 guint * sample_rate, guint * channels)
1302 static const int sample_rates[16] = { 0, 8000, 16000, 32000, 0, 0, 11025,
1303 22050, 44100, 0, 0, 12000, 24000, 48000, 96000, 192000
1305 static const guint8 channels_table[16] = { 1, 2, 2, 2, 2, 3, 3, 4, 4, 5,
1310 guint num_blocks, chans, lfe, i;
1312 marker = GST_READ_UINT32_BE (c->data);
1314 /* raw big endian or 14-bit big endian */
1315 if (marker == 0x7FFE8001 || marker == 0x1FFFE800) {
1316 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1317 hdr[i] = GST_READ_UINT16_BE (c->data + (i * sizeof (guint16)));
1319 /* raw little endian or 14-bit little endian */
1320 if (marker == 0xFE7F0180 || marker == 0xFF1F00E8) {
1321 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1322 hdr[i] = GST_READ_UINT16_LE (c->data + (i * sizeof (guint16)));
1327 GST_LOG ("dts sync marker 0x%08x at offset %u", marker, (guint) c->offset);
1330 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8) {
1331 if ((hdr[2] & 0xFFF0) != 0x07F0)
1333 /* discard top 2 bits (2 void), shift in 2 */
1334 hdr[0] = (hdr[0] << 2) | ((hdr[1] >> 12) & 0x0003);
1335 /* discard top 4 bits (2 void, 2 shifted into hdr[0]), shift in 4 etc. */
1336 hdr[1] = (hdr[1] << 4) | ((hdr[2] >> 10) & 0x000F);
1337 hdr[2] = (hdr[2] << 6) | ((hdr[3] >> 8) & 0x003F);
1338 hdr[3] = (hdr[3] << 8) | ((hdr[4] >> 6) & 0x00FF);
1339 hdr[4] = (hdr[4] << 10) | ((hdr[5] >> 4) & 0x03FF);
1340 hdr[5] = (hdr[5] << 12) | ((hdr[6] >> 2) & 0x0FFF);
1341 hdr[6] = (hdr[6] << 14) | ((hdr[7] >> 0) & 0x3FFF);
1342 g_assert (hdr[0] == 0x7FFE && hdr[1] == 0x8001);
1345 GST_LOG ("frame header: %04x%04x%04x%04x", hdr[2], hdr[3], hdr[4], hdr[5]);
1347 num_blocks = (hdr[2] >> 2) & 0x7F;
1348 *frame_size = (((hdr[2] & 0x03) << 12) | (hdr[3] >> 4)) + 1;
1349 chans = ((hdr[3] & 0x0F) << 2) | (hdr[4] >> 14);
1350 *sample_rate = sample_rates[(hdr[4] >> 10) & 0x0F];
1351 lfe = (hdr[5] >> 9) & 0x03;
1353 if (num_blocks < 5 || *frame_size < 96 || *sample_rate == 0)
1356 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8)
1357 *frame_size = (*frame_size * 16) / 14; /* FIXME: round up? */
1359 if (chans < G_N_ELEMENTS (channels_table))
1360 *channels = channels_table[chans] + ((lfe) ? 1 : 0);
1368 dts_type_find (GstTypeFind * tf, gpointer unused)
1370 DataScanCtx c = { 0, NULL, 0 };
1372 /* Search for an dts frame; not neccesarily right at the start, but give it
1373 * a lower probability if not found right at the start. Check that the
1374 * frame is followed by a second frame at the expected offset. */
1375 while (c.offset <= DTS_MAX_FRAMESIZE) {
1376 guint frame_size = 0, rate = 0, chans = 0;
1378 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, DTS_MIN_FRAMESIZE)))
1381 if (G_UNLIKELY (dts_parse_frame_header (&c, &frame_size, &rate, &chans))) {
1382 GstTypeFindProbability prob;
1385 prob = (c.offset == 0) ? GST_TYPE_FIND_LIKELY : GST_TYPE_FIND_POSSIBLE;
1387 /* check for second frame sync */
1389 data_scan_ctx_advance (tf, &next_c, frame_size);
1390 if (data_scan_ctx_ensure_data (tf, &next_c, 4)) {
1391 GST_LOG ("frame size: %u 0x%04x", frame_size, frame_size);
1392 GST_MEMDUMP ("second frame sync", next_c.data, 4);
1393 if (GST_READ_UINT32_BE (c.data) == GST_READ_UINT32_BE (next_c.data))
1394 prob = GST_TYPE_FIND_MAXIMUM;
1398 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
1399 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, chans, NULL);
1401 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
1402 "rate", G_TYPE_INT, rate, NULL);
1408 data_scan_ctx_advance (tf, &c, 1);
1414 /* can only be detected by using the extension, in which case we use the default
1416 static GstStaticCaps gsm_caps =
1417 GST_STATIC_CAPS ("audio/x-gsm, rate=8000, channels=1");
1419 #define GSM_CAPS (gst_static_caps_get(&gsm_caps))
1423 static GstStaticCaps wavpack_caps =
1424 GST_STATIC_CAPS ("audio/x-wavpack, framed = (boolean) false");
1426 #define WAVPACK_CAPS (gst_static_caps_get(&wavpack_caps))
1428 static GstStaticCaps wavpack_correction_caps =
1429 GST_STATIC_CAPS ("audio/x-wavpack-correction, framed = (boolean) false");
1431 #define WAVPACK_CORRECTION_CAPS (gst_static_caps_get(&wavpack_correction_caps))
1434 wavpack_type_find (GstTypeFind * tf, gpointer unused)
1440 data = gst_type_find_peek (tf, 0, 32);
1444 if (data[0] != 'w' || data[1] != 'v' || data[2] != 'p' || data[3] != 'k')
1447 /* Note: wavpack blocks can be fairly large (easily 60-110k), possibly
1448 * larger than the max. limits imposed by certain typefinding elements
1449 * like id3demux or apedemux, so typefinding is most likely only going to
1450 * work in pull-mode */
1451 blocksize = GST_READ_UINT32_LE (data + 4);
1452 GST_LOG ("wavpack header, blocksize=0x%04x", blocksize);
1454 while (offset < 32 + blocksize) {
1457 /* get chunk header */
1458 GST_LOG ("peeking at chunk at offset 0x%04x", (guint) offset);
1459 data = gst_type_find_peek (tf, offset, 4);
1462 sublen = ((guint32) data[1]) << 1;
1463 if (data[0] & 0x80) {
1464 sublen |= (((guint32) data[2]) << 9) | (((guint32) data[3]) << 17);
1465 sublen += 1 + 3; /* id + length */
1467 sublen += 1 + 1; /* id + length */
1469 if (sublen > blocksize - offset + 32) {
1470 GST_LOG ("chunk length too big (%u > %" G_GUINT64_FORMAT ")", sublen,
1471 blocksize - offset);
1474 if ((data[0] & 0x20) == 0) {
1475 switch (data[0] & 0x0f) {
1476 case 0xa: /* ID_WV_BITSTREAM */
1477 case 0xc: /* ID_WVX_BITSTREAM */
1478 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, WAVPACK_CAPS);
1480 case 0xb: /* ID_WVC_BITSTREAM */
1481 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY,
1482 WAVPACK_CORRECTION_CAPS);
1492 /*** application/postscrip ***/
1493 static GstStaticCaps postscript_caps =
1494 GST_STATIC_CAPS ("application/postscript");
1496 #define POSTSCRIPT_CAPS (gst_static_caps_get(&postscript_caps))
1499 postscript_type_find (GstTypeFind * tf, gpointer unused)
1501 guint8 *data = gst_type_find_peek (tf, 0, 3);
1505 if (data[0] == 0x04)
1507 if (data[0] == '%' && data[1] == '!')
1508 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, POSTSCRIPT_CAPS);
1512 /*** image/svg+xml ***/
1513 static GstStaticCaps svg_caps = GST_STATIC_CAPS ("image/svg+xml");
1515 #define SVG_CAPS (gst_static_caps_get(&svg_caps))
1518 svg_type_find (GstTypeFind * tf, gpointer unused)
1520 static const gchar svg_doctype[] = "!DOCTYPE svg";
1521 static const gchar svg_tag[] = "<svg";
1522 DataScanCtx c = { 0, NULL, 0 };
1524 while (c.offset <= 1024) {
1525 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
1528 if (memcmp (svg_doctype, c.data, 12) == 0) {
1529 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVG_CAPS);
1531 } else if (memcmp (svg_tag, c.data, 4) == 0) {
1532 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, SVG_CAPS);
1535 data_scan_ctx_advance (tf, &c, 1);
1539 /*** multipart/x-mixed-replace mimestream ***/
1541 static GstStaticCaps multipart_caps =
1542 GST_STATIC_CAPS ("multipart/x-mixed-replace");
1543 #define MULTIPART_CAPS gst_static_caps_get(&multipart_caps)
1545 /* multipart/x-mixed replace is:
1546 * <maybe some whitespace>--<some ascii chars>[\r]\n
1547 * <more ascii chars>[\r]\nContent-type:<more ascii>[\r]\n */
1549 multipart_type_find (GstTypeFind * tf, gpointer unused)
1554 #define MULTIPART_MAX_BOUNDARY_OFFSET 16
1555 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_BOUNDARY_OFFSET);
1560 x - data < MULTIPART_MAX_BOUNDARY_OFFSET - 2 && g_ascii_isspace (*x);
1562 if (x[0] != '-' || x[1] != '-')
1565 /* Could be okay, peek what should be enough for a complete header */
1566 #define MULTIPART_MAX_HEADER_SIZE 256
1567 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_HEADER_SIZE);
1571 for (x = data; x - data < MULTIPART_MAX_HEADER_SIZE - 14; x++) {
1572 if (!isascii (*x)) {
1576 !g_ascii_strncasecmp ("content-type:", (gchar *) x + 1, 13)) {
1577 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MULTIPART_CAPS);
1583 /*** video/mpeg systemstream ***/
1584 static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, "
1585 "systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
1587 #define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
1588 #define IS_MPEG_HEADER(data) (G_UNLIKELY((((guint8 *)(data))[0] == 0x00) && \
1589 (((guint8 *)(data))[1] == 0x00) && \
1590 (((guint8 *)(data))[2] == 0x01)))
1592 #define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
1593 #define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
1594 #define IS_MPEG_PACK_HEADER(data) (IS_MPEG_HEADER (data) && \
1595 IS_MPEG_PACK_CODE (((guint8 *)(data))[3]))
1597 #define IS_MPEG_PES_CODE(b) (((b) & 0xF0) == 0xE0 || ((b) & 0xF0) == 0xC0 || \
1599 #define IS_MPEG_PES_HEADER(data) (IS_MPEG_HEADER (data) && \
1600 IS_MPEG_PES_CODE (((guint8 *)(data))[3]))
1602 #define MPEG2_MAX_PROBE_LENGTH (128 * 1024) /* 128kB should be 64 packs of the
1603 * most common 2kB pack size. */
1605 #define MPEG2_MIN_SYS_HEADERS 2
1606 #define MPEG2_MAX_SYS_HEADERS 5
1609 mpeg_sys_is_valid_pack (GstTypeFind * tf, const guint8 * data, guint len,
1612 /* Check the pack header @ offset for validity, assuming that the 4 byte header
1613 * itself has already been checked. */
1619 /* Check marker bits */
1620 if ((data[4] & 0xC4) == 0x44) {
1625 if ((data[6] & 0x04) != 0x04 ||
1626 (data[8] & 0x04) != 0x04 ||
1627 (data[9] & 0x01) != 0x01 || (data[12] & 0x03) != 0x03)
1630 stuff_len = data[13] & 0x07;
1632 /* Check the following header bytes, if we can */
1633 if ((14 + stuff_len + 4) <= len) {
1634 if (!IS_MPEG_HEADER (data + 14 + stuff_len))
1638 *pack_size = 14 + stuff_len;
1640 } else if ((data[4] & 0xF1) == 0x21) {
1642 if ((data[6] & 0x01) != 0x01 ||
1643 (data[8] & 0x01) != 0x01 ||
1644 (data[9] & 0x80) != 0x80 || (data[11] & 0x01) != 0x01)
1647 /* Check the following header bytes, if we can */
1648 if ((12 + 4) <= len) {
1649 if (!IS_MPEG_HEADER (data + 12))
1661 mpeg_sys_is_valid_pes (GstTypeFind * tf, guint8 * data, guint len,
1664 guint pes_packet_len;
1666 /* Check the PES header at the given position, assuming the header code itself
1667 * was already checked */
1671 /* For MPEG Program streams, unbounded PES is not allowed, so we must have a
1672 * valid length present */
1673 pes_packet_len = GST_READ_UINT16_BE (data + 4);
1674 if (pes_packet_len == 0)
1677 /* Check the following header, if we can */
1678 if (6 + pes_packet_len + 4 <= len) {
1679 if (!IS_MPEG_HEADER (data + 6 + pes_packet_len))
1684 *pack_size = 6 + pes_packet_len;
1689 mpeg_sys_is_valid_sys (GstTypeFind * tf, guint8 * data, guint len,
1694 /* Check the System header at the given position, assuming the header code itself
1695 * was already checked */
1698 sys_hdr_len = GST_READ_UINT16_BE (data + 4);
1699 if (sys_hdr_len < 6)
1702 /* Check the following header, if we can */
1703 if (6 + sys_hdr_len + 4 <= len) {
1704 if (!IS_MPEG_HEADER (data + 6 + sys_hdr_len))
1709 *pack_size = 6 + sys_hdr_len;
1714 /* calculation of possibility to identify random data as mpeg systemstream:
1715 * bits that must match in header detection: 32 (or more)
1716 * chance that random data is identifed: 1/2^32
1717 * chance that MPEG2_MIN_PACK_HEADERS headers are identified:
1718 * 1/2^(32*MPEG2_MIN_PACK_HEADERS)
1719 * chance that this happens in MPEG2_MAX_PROBE_LENGTH bytes:
1720 * 1-(1+1/2^(32*MPEG2_MIN_PACK_HEADERS)^MPEG2_MAX_PROBE_LENGTH)
1721 * for current values:
1722 * 1-(1+1/2^(32*4)^101024)
1724 * Since we also check marker bits and pes packet lengths, this probability is a
1725 * very coarse upper bound.
1728 mpeg_sys_type_find (GstTypeFind * tf, gpointer unused)
1730 guint8 *data, *data0, *first_sync, *end;
1731 gint mpegversion = 0;
1732 guint pack_headers = 0;
1733 guint pes_headers = 0;
1735 guint since_last_sync = 0;
1736 guint32 sync_word = 0xffffffff;
1741 len = MPEG2_MAX_PROBE_LENGTH;
1744 data = gst_type_find_peek (tf, 0, 5 + len);
1745 } while (data == NULL && len >= 32);
1757 while (data < end) {
1759 if (sync_word == 0x00000100) {
1760 /* Found potential sync word */
1761 if (first_sync == NULL)
1762 first_sync = data - 3;
1764 if (since_last_sync > 4) {
1765 /* If more than 4 bytes since the last sync word, reset our counters,
1766 * as we're only interested in counting contiguous packets */
1767 pes_headers = pack_headers = 0;
1771 if (IS_MPEG_PACK_CODE (data[0])) {
1772 if ((data[1] & 0xC0) == 0x40) {
1775 } else if ((data[1] & 0xF0) == 0x20) {
1778 if (mpegversion != 0 &&
1779 mpeg_sys_is_valid_pack (tf, data - 3, end - data + 3, &pack_size)) {
1782 } else if (IS_MPEG_PES_CODE (data[0])) {
1784 if (mpeg_sys_is_valid_pes (tf, data - 3, end - data + 3, &pack_size)) {
1786 if (mpegversion == 0)
1789 } else if (IS_MPEG_SYS_CODE (data[0])) {
1790 if (mpeg_sys_is_valid_sys (tf, data - 3, end - data + 3, &pack_size)) {
1795 /* If we found a packet with a known size, skip the bytes in it and loop
1796 * around to check the next packet. */
1797 if (pack_size != 0) {
1798 data += pack_size - 3;
1799 sync_word = 0xffffffff;
1800 since_last_sync = 0;
1805 sync_word |= data[0];
1809 /* If we have found MAX headers, and *some* were pes headers (pack headers
1810 * are optional in an mpeg system stream) then return our high-probability
1812 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MAX_SYS_HEADERS)
1816 /* If we at least saw MIN headers, and *some* were pes headers (pack headers
1817 * are optional in an mpeg system stream) then return a lower-probability
1819 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MIN_SYS_HEADERS)
1827 prob = GST_TYPE_FIND_POSSIBLE + (10 * (pack_headers + pes_headers));
1828 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
1830 /* lower probability if the first packet wasn't right at the start */
1831 if (data0 != first_sync && prob >= 10)
1834 GST_LOG ("Suggesting MPEG %d system stream, %d packs, %d pes, prob %u%%\n",
1835 mpegversion, pack_headers, pes_headers, prob);
1837 gst_type_find_suggest_simple (tf, prob, "video/mpeg",
1838 "systemstream", G_TYPE_BOOLEAN, TRUE,
1839 "mpegversion", G_TYPE_INT, mpegversion, NULL);
1843 /*** video/mpegts Transport Stream ***/
1844 static GstStaticCaps mpegts_caps = GST_STATIC_CAPS ("video/mpegts, "
1845 "systemstream = (boolean) true, packetsize = (int) [ 188, 208 ]");
1846 #define MPEGTS_CAPS gst_static_caps_get(&mpegts_caps)
1848 #define GST_MPEGTS_TYPEFIND_MIN_HEADERS 4
1849 #define GST_MPEGTS_TYPEFIND_MAX_HEADERS 10
1850 #define GST_MPEGTS_MAX_PACKET_SIZE 208
1851 #define GST_MPEGTS_TYPEFIND_SYNC_SIZE \
1852 (GST_MPEGTS_TYPEFIND_MIN_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
1853 #define GST_MPEGTS_TYPEFIND_MAX_SYNC \
1854 (GST_MPEGTS_TYPEFIND_MAX_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
1855 #define GST_MPEGTS_TYPEFIND_SCAN_LENGTH \
1856 (GST_MPEGTS_TYPEFIND_MAX_SYNC * 4)
1858 #define MPEGTS_HDR_SIZE 4
1859 /* Check for sync byte, error_indicator == 0 and packet has payload */
1860 #define IS_MPEGTS_HEADER(data) (((data)[0] == 0x47) && \
1861 (((data)[1] & 0x80) == 0x00) && \
1862 (((data)[3] & 0x10) == 0x10))
1864 /* Helper function to search ahead at intervals of packet_size for mpegts
1867 mpeg_ts_probe_headers (GstTypeFind * tf, guint64 offset, gint packet_size)
1869 /* We always enter this function having found at least one header already */
1871 guint8 *data = NULL;
1873 GST_LOG ("looking for mpeg-ts packets of size %u", packet_size);
1874 while (found < GST_MPEGTS_TYPEFIND_MAX_HEADERS) {
1875 offset += packet_size;
1877 data = gst_type_find_peek (tf, offset, MPEGTS_HDR_SIZE);
1878 if (data == NULL || !IS_MPEGTS_HEADER (data))
1882 GST_LOG ("mpeg-ts sync #%2d at offset %" G_GUINT64_FORMAT, found, offset);
1888 /* Try and detect at least 4 packets in at most 10 packets worth of
1889 * data. Need to try several possible packet sizes */
1891 mpeg_ts_type_find (GstTypeFind * tf, gpointer unused)
1893 /* TS packet sizes to test: normal, DVHS packet size and
1894 * FEC with 16 or 20 byte codes packet size. */
1895 const gint pack_sizes[] = { 188, 192, 204, 208 };
1897 guint8 *data = NULL;
1899 guint64 skipped = 0;
1901 while (skipped < GST_MPEGTS_TYPEFIND_SCAN_LENGTH) {
1902 if (size < MPEGTS_HDR_SIZE) {
1903 data = gst_type_find_peek (tf, skipped, GST_MPEGTS_TYPEFIND_SYNC_SIZE);
1906 size = GST_MPEGTS_TYPEFIND_SYNC_SIZE;
1909 /* Have at least MPEGTS_HDR_SIZE bytes at this point */
1910 if (IS_MPEGTS_HEADER (data)) {
1913 GST_LOG ("possible mpeg-ts sync at offset %" G_GUINT64_FORMAT, skipped);
1915 for (p = 0; p < G_N_ELEMENTS (pack_sizes); p++) {
1918 /* Probe ahead at size pack_sizes[p] */
1919 found = mpeg_ts_probe_headers (tf, skipped, pack_sizes[p]);
1920 if (found >= GST_MPEGTS_TYPEFIND_MIN_HEADERS) {
1923 /* found at least 4 headers. 10 headers = MAXIMUM probability.
1924 * Arbitrarily, I assigned 10% probability for each header we
1925 * found, 40% -> 100% */
1926 probability = MIN (10 * found, GST_TYPE_FIND_MAXIMUM);
1928 gst_type_find_suggest_simple (tf, probability, "video/mpegts",
1929 "systemstream", G_TYPE_BOOLEAN, TRUE,
1930 "packetsize", G_TYPE_INT, pack_sizes[p], NULL);
1941 #define GST_MPEGVID_TYPEFIND_TRY_PICTURES 6
1942 #define GST_MPEGVID_TYPEFIND_TRY_SYNC (100 * 1024) /* 100 kB */
1944 /* Scan ahead a maximum of max_extra_offset bytes until the next IS_MPEG_HEADER
1945 * offset. After the call, offset will be after the 0x000001, i.e. at the 4th
1946 * byte of the MPEG header. Returns TRUE if a header was found, FALSE if not.
1949 mpeg_find_next_header (GstTypeFind * tf, DataScanCtx * c,
1950 guint64 max_extra_offset)
1952 guint64 extra_offset;
1954 for (extra_offset = 0; extra_offset <= max_extra_offset; ++extra_offset) {
1955 if (!data_scan_ctx_ensure_data (tf, c, 4))
1957 if (IS_MPEG_HEADER (c->data)) {
1958 data_scan_ctx_advance (tf, c, 3);
1961 data_scan_ctx_advance (tf, c, 1);
1966 /*** video/mpeg MPEG-4 elementary video stream ***/
1968 static GstStaticCaps mpeg4_video_caps = GST_STATIC_CAPS ("video/mpeg, "
1969 "systemstream=(boolean)false, mpegversion=4, parsed=(boolean)false");
1970 #define MPEG4_VIDEO_CAPS gst_static_caps_get(&mpeg4_video_caps)
1973 * This typefind is based on the elementary video header defined in
1974 * http://xhelmboyx.tripod.com/formats/mpeg-layout.txt
1975 * In addition, it allows the visual object sequence header to be
1976 * absent, and even the VOS header to be absent. In the latter case,
1977 * a number of VOPs have to be present.
1980 mpeg4_video_type_find (GstTypeFind * tf, gpointer unused)
1982 DataScanCtx c = { 0, NULL, 0 };
1983 gboolean seen_vios_at_0 = FALSE;
1984 gboolean seen_vios = FALSE;
1985 gboolean seen_vos = FALSE;
1986 gboolean seen_vol = FALSE;
1987 guint num_vop_headers = 0;
1990 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
1991 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
1994 if (!mpeg_find_next_header (tf, &c,
1995 GST_MPEGVID_TYPEFIND_TRY_SYNC - c.offset))
2000 /* visual_object_sequence_start_code */
2003 break; /* Terminate at second vios */
2005 seen_vios_at_0 = TRUE;
2007 data_scan_ctx_advance (tf, &c, 2);
2008 if (!mpeg_find_next_header (tf, &c, 0))
2013 /* Optional metadata */
2015 if (!mpeg_find_next_header (tf, &c, 24))
2019 /* visual_object_start_code (consider it optional) */
2021 data_scan_ctx_advance (tf, &c, 2);
2022 /* may contain ID marker and YUV clamping */
2023 if (!mpeg_find_next_header (tf, &c, 7))
2029 /* video_object_start_code */
2032 break; /* Terminate at second vos */
2034 data_scan_ctx_advance (tf, &c, 2);
2038 /* video_object_layer_start_code */
2039 if (sc >= 0x20 && sc <= 0x2F) {
2041 data_scan_ctx_advance (tf, &c, 5);
2045 /* video_object_plane_start_code */
2048 data_scan_ctx_advance (tf, &c, 2);
2052 /* Unknown start code. */
2055 if (num_vop_headers > 0 || seen_vol) {
2056 GstTypeFindProbability probability = 0;
2058 GST_LOG ("Found %d pictures, vios: %d, vos:%d, vol:%d", num_vop_headers,
2059 seen_vios, seen_vos, seen_vol);
2061 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios_at_0
2062 && seen_vos && seen_vol)
2063 probability = GST_TYPE_FIND_MAXIMUM - 1;
2064 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios
2065 && seen_vos && seen_vol)
2066 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2067 else if (seen_vios_at_0 && seen_vos && seen_vol)
2068 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2069 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vos
2071 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2072 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vol)
2073 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2074 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2075 probability = GST_TYPE_FIND_LIKELY - 1;
2076 else if (num_vop_headers > 2 && seen_vios && seen_vos && seen_vol)
2077 probability = GST_TYPE_FIND_LIKELY - 9;
2078 else if (seen_vios && seen_vos && seen_vol)
2079 probability = GST_TYPE_FIND_LIKELY - 20;
2080 else if (num_vop_headers > 0 && seen_vos && seen_vol)
2081 probability = GST_TYPE_FIND_POSSIBLE;
2082 else if (num_vop_headers > 0)
2083 probability = GST_TYPE_FIND_POSSIBLE - 10;
2084 else if (seen_vos && seen_vol)
2085 probability = GST_TYPE_FIND_POSSIBLE - 20;
2087 gst_type_find_suggest (tf, probability, MPEG4_VIDEO_CAPS);
2091 /*** video/x-h264 H264 elementary video stream ***/
2093 static GstStaticCaps h264_video_caps = GST_STATIC_CAPS ("video/x-h264");
2095 #define H264_VIDEO_CAPS gst_static_caps_get(&h264_video_caps)
2097 #define H264_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
2100 h264_video_type_find (GstTypeFind * tf, gpointer unused)
2102 DataScanCtx c = { 0, NULL, 0 };
2104 /* Stream consists of: a series of sync codes (00 00 00 01) followed
2111 while (c.offset < H264_MAX_PROBE_LENGTH) {
2112 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
2115 if (IS_MPEG_HEADER (c.data)) {
2116 nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
2117 ref = c.data[3] & 0x60; /* nal_ref_idc */
2119 /* if forbiden bit is different to 0 won't be h264 */
2125 /* collect statistics about the NAL types */
2126 if ((nut >= 1 && nut <= 13) || nut == 19) {
2127 if ((nut == 5 && ref == 0) ||
2128 ((nut == 6 || (nut >= 9 && nut <= 12)) && ref != 0)) {
2133 } else if (nut >= 14 && nut <= 33) {
2135 /* Theoretically these are good, since if they exist in the
2136 stream it merely means that a newer backwards-compatible
2137 h.264 stream. But we should be identifying that separately. */
2140 /* unspecified, application specific */
2141 /* don't consider these bad */
2144 GST_DEBUG ("good %d bad %d", good, bad);
2146 if (good >= 10 && bad < 4) {
2147 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H264_VIDEO_CAPS);
2151 data_scan_ctx_advance (tf, &c, 4);
2153 data_scan_ctx_advance (tf, &c, 1);
2156 if (good >= 2 && bad < 1) {
2157 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H264_VIDEO_CAPS);
2162 /*** video/mpeg video stream ***/
2164 static GstStaticCaps mpeg_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2165 "systemstream = (boolean) false");
2166 #define MPEG_VIDEO_CAPS gst_static_caps_get(&mpeg_video_caps)
2169 * Idea is the same as MPEG system stream typefinding: We check each
2170 * byte of the stream to see if - from that point on - the stream
2171 * matches a predefined set of marker bits as defined in the MPEG
2174 * I'm sure someone will do a chance calculation here too.
2178 mpeg_video_stream_type_find (GstTypeFind * tf, gpointer unused)
2180 DataScanCtx c = { 0, NULL, 0 };
2181 gboolean seen_seq_at_0 = FALSE;
2182 gboolean seen_seq = FALSE;
2183 gboolean seen_gop = FALSE;
2184 guint64 last_pic_offset = 0;
2185 guint num_pic_headers = 0;
2188 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2189 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2192 if (!data_scan_ctx_ensure_data (tf, &c, 5))
2195 if (!IS_MPEG_HEADER (c.data))
2198 /* a pack header indicates that this isn't an elementary stream */
2199 if (c.data[3] == 0xBA && mpeg_sys_is_valid_pack (tf, c.data, c.size, NULL))
2202 /* do we have a sequence header? */
2203 if (c.data[3] == 0xB3) {
2204 seen_seq_at_0 = seen_seq_at_0 || (c.offset == 0);
2206 data_scan_ctx_advance (tf, &c, 4 + 8);
2210 /* or a GOP header */
2211 if (c.data[3] == 0xB8) {
2213 data_scan_ctx_advance (tf, &c, 8);
2217 /* but what we'd really like to see is a picture header */
2218 if (c.data[3] == 0x00) {
2220 last_pic_offset = c.offset;
2221 data_scan_ctx_advance (tf, &c, 8);
2225 /* ... each followed by a slice header with slice_vertical_pos=1 that's
2226 * not too far away from the previously seen picture header. */
2227 if (c.data[3] == 0x01 && num_pic_headers > found &&
2228 (c.offset - last_pic_offset) >= 4 &&
2229 (c.offset - last_pic_offset) <= 64) {
2230 data_scan_ctx_advance (tf, &c, 4);
2237 data_scan_ctx_advance (tf, &c, 1);
2240 if (found > 0 || seen_seq) {
2241 GstTypeFindProbability probability = 0;
2243 GST_LOG ("Found %d pictures, seq:%d, gop:%d", found, seen_seq, seen_gop);
2245 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq && seen_gop)
2246 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2247 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq)
2248 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2249 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2250 probability = GST_TYPE_FIND_LIKELY;
2251 else if (seen_seq_at_0 && seen_gop && found > 2)
2252 probability = GST_TYPE_FIND_LIKELY - 10;
2253 else if (seen_seq && seen_gop && found > 2)
2254 probability = GST_TYPE_FIND_LIKELY - 20;
2255 else if (seen_seq_at_0 && found > 0)
2256 probability = GST_TYPE_FIND_POSSIBLE;
2257 else if (seen_seq && found > 0)
2258 probability = GST_TYPE_FIND_POSSIBLE - 5;
2260 probability = GST_TYPE_FIND_POSSIBLE - 10;
2262 probability = GST_TYPE_FIND_POSSIBLE - 20;
2264 gst_type_find_suggest_simple (tf, probability, "video/mpeg",
2265 "systemstream", G_TYPE_BOOLEAN, FALSE,
2266 "mpegversion", G_TYPE_INT, 1, NULL);
2270 /*** audio/x-aiff ***/
2272 static GstStaticCaps aiff_caps = GST_STATIC_CAPS ("audio/x-aiff");
2274 #define AIFF_CAPS gst_static_caps_get(&aiff_caps)
2276 aiff_type_find (GstTypeFind * tf, gpointer unused)
2278 guint8 *data = gst_type_find_peek (tf, 0, 4);
2280 if (data && memcmp (data, "FORM", 4) == 0) {
2282 if (memcmp (data, "AIFF", 4) == 0 || memcmp (data, "AIFC", 4) == 0)
2283 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AIFF_CAPS);
2287 /*** audio/x-svx ***/
2289 static GstStaticCaps svx_caps = GST_STATIC_CAPS ("audio/x-svx");
2291 #define SVX_CAPS gst_static_caps_get(&svx_caps)
2293 svx_type_find (GstTypeFind * tf, gpointer unused)
2295 guint8 *data = gst_type_find_peek (tf, 0, 4);
2297 if (data && memcmp (data, "FORM", 4) == 0) {
2299 if (memcmp (data, "8SVX", 4) == 0 || memcmp (data, "16SV", 4) == 0)
2300 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVX_CAPS);
2304 /*** audio/x-shorten ***/
2306 static GstStaticCaps shn_caps = GST_STATIC_CAPS ("audio/x-shorten");
2308 #define SHN_CAPS gst_static_caps_get(&shn_caps)
2310 shn_type_find (GstTypeFind * tf, gpointer unused)
2312 guint8 *data = gst_type_find_peek (tf, 0, 4);
2314 if (data && memcmp (data, "ajkg", 4) == 0) {
2315 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2317 data = gst_type_find_peek (tf, -8, 8);
2318 if (data && memcmp (data, "SHNAMPSK", 8) == 0) {
2319 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2323 /*** application/x-ape ***/
2325 static GstStaticCaps ape_caps = GST_STATIC_CAPS ("application/x-ape");
2327 #define APE_CAPS gst_static_caps_get(&ape_caps)
2329 ape_type_find (GstTypeFind * tf, gpointer unused)
2331 guint8 *data = gst_type_find_peek (tf, 0, 4);
2333 if (data && memcmp (data, "MAC ", 4) == 0) {
2334 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 10, APE_CAPS);
2338 /*** ISO FORMATS ***/
2340 /*** audio/x-m4a ***/
2342 static GstStaticCaps m4a_caps = GST_STATIC_CAPS ("audio/x-m4a");
2344 #define M4A_CAPS (gst_static_caps_get(&m4a_caps))
2346 m4a_type_find (GstTypeFind * tf, gpointer unused)
2348 guint8 *data = gst_type_find_peek (tf, 4, 8);
2350 if (data && (memcmp (data, "ftypM4A ", 8) == 0)) {
2351 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
2355 /*** application/x-3gp ***/
2357 /* The Q is there because variables can't start with a number. */
2358 static GstStaticCaps q3gp_caps = GST_STATIC_CAPS ("application/x-3gp");
2359 #define Q3GP_CAPS (gst_static_caps_get(&q3gp_caps))
2361 static const gchar *
2362 q3gp_type_find_get_profile (const guint8 * data)
2364 switch (GST_MAKE_FOURCC (data[0], data[1], data[2], 0)) {
2365 case GST_MAKE_FOURCC ('3', 'g', 'g', 0):
2367 case GST_MAKE_FOURCC ('3', 'g', 'p', 0):
2369 case GST_MAKE_FOURCC ('3', 'g', 's', 0):
2370 return "streaming-server";
2371 case GST_MAKE_FOURCC ('3', 'g', 'r', 0):
2372 return "progressive-download";
2380 q3gp_type_find (GstTypeFind * tf, gpointer unused)
2382 const gchar *profile;
2383 guint32 ftyp_size = 0;
2385 guint8 *data = NULL;
2387 if ((data = gst_type_find_peek (tf, 0, 12)) == NULL) {
2392 if (memcmp (data, "ftyp", 4) != 0) {
2396 /* check major brand */
2398 if ((profile = q3gp_type_find_get_profile (data))) {
2399 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
2400 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
2404 /* check compatible brands */
2405 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2406 ftyp_size = GST_READ_UINT32_BE (data);
2408 for (offset = 16; offset < ftyp_size; offset += 4) {
2409 if ((data = gst_type_find_peek (tf, offset, 3)) == NULL) {
2412 if ((profile = q3gp_type_find_get_profile (data))) {
2413 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
2414 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
2423 /*** video/mj2 and image/jp2 ***/
2424 static GstStaticCaps mj2_caps = GST_STATIC_CAPS ("video/mj2");
2426 #define MJ2_CAPS gst_static_caps_get(&mj2_caps)
2428 static GstStaticCaps jp2_caps = GST_STATIC_CAPS ("image/jp2");
2430 #define JP2_CAPS gst_static_caps_get(&jp2_caps)
2433 jp2_type_find (GstTypeFind * tf, gpointer unused)
2437 data = gst_type_find_peek (tf, 0, 24);
2442 if (memcmp (data, "\000\000\000\014jP \015\012\207\012", 12) != 0)
2445 /* check ftyp box */
2447 if (memcmp (data + 4, "ftyp", 4) == 0) {
2448 if (memcmp (data + 8, "jp2 ", 4) == 0)
2449 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JP2_CAPS);
2450 else if (memcmp (data + 8, "mjp2", 4) == 0)
2451 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MJ2_CAPS);
2455 /*** video/quicktime ***/
2457 static GstStaticCaps qt_caps = GST_STATIC_CAPS ("video/quicktime");
2459 #define QT_CAPS gst_static_caps_get(&qt_caps)
2460 #define STRNCMP(x,y,z) (strncmp ((char*)(x), (char*)(y), z))
2462 /* FIXME 0.11: go through http://www.ftyps.com/ */
2464 qt_type_find (GstTypeFind * tf, gpointer unused)
2470 const gchar *variant = NULL;
2472 while ((data = gst_type_find_peek (tf, offset, 12)) != NULL) {
2475 if (STRNCMP (&data[4], "ftypqt ", 8) == 0) {
2476 tip = GST_TYPE_FIND_MAXIMUM;
2480 if (STRNCMP (&data[4], "ftypisom", 8) == 0 ||
2481 STRNCMP (&data[4], "ftypmp42", 8) == 0) {
2482 tip = GST_TYPE_FIND_MAXIMUM;
2487 /* box/atom types that are in common with ISO base media file format */
2488 if (STRNCMP (&data[4], "moov", 4) == 0 ||
2489 STRNCMP (&data[4], "mdat", 4) == 0 ||
2490 STRNCMP (&data[4], "ftyp", 4) == 0 ||
2491 STRNCMP (&data[4], "free", 4) == 0 ||
2492 STRNCMP (&data[4], "uuid", 4) == 0 ||
2493 STRNCMP (&data[4], "skip", 4) == 0) {
2495 tip = GST_TYPE_FIND_LIKELY;
2497 tip = GST_TYPE_FIND_NEARLY_CERTAIN;
2500 /* other box/atom types, apparently quicktime specific */
2501 else if (STRNCMP (&data[4], "pnot", 4) == 0 ||
2502 STRNCMP (&data[4], "PICT", 4) == 0 ||
2503 STRNCMP (&data[4], "wide", 4) == 0 ||
2504 STRNCMP (&data[4], "prfl", 4) == 0) {
2505 tip = GST_TYPE_FIND_MAXIMUM;
2511 size = GST_READ_UINT32_BE (data);
2515 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2516 if (sizedata == NULL)
2519 size = GST_READ_UINT64_BE (sizedata);
2524 new_offset = offset + size;
2525 if (new_offset <= offset)
2527 offset = new_offset;
2532 GstCaps *caps = gst_caps_copy (QT_CAPS);
2534 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, variant, NULL);
2535 gst_type_find_suggest (tf, tip, caps);
2536 gst_caps_unref (caps);
2538 gst_type_find_suggest (tf, tip, QT_CAPS);
2544 /*** image/x-quicktime ***/
2546 static GstStaticCaps qtif_caps = GST_STATIC_CAPS ("image/x-quicktime");
2548 #define QTIF_CAPS gst_static_caps_get(&qtif_caps)
2550 /* how many atoms we check before we give up */
2551 #define QTIF_MAXROUNDS 25
2554 qtif_type_find (GstTypeFind * tf, gpointer unused)
2557 gboolean found_idsc = FALSE;
2558 gboolean found_idat = FALSE;
2562 while ((data = gst_type_find_peek (tf, offset, 8)) != NULL) {
2565 size = GST_READ_UINT32_BE (data);
2567 const guint8 *sizedata;
2569 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2570 if (sizedata == NULL)
2573 size = GST_READ_UINT64_BE (sizedata);
2578 if (STRNCMP (data + 4, "idsc", 4) == 0)
2580 if (STRNCMP (data + 4, "idat", 4) == 0)
2583 if (found_idsc && found_idat) {
2584 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, QTIF_CAPS);
2589 if (++rounds > QTIF_MAXROUNDS)
2593 if (found_idsc || found_idat) {
2594 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, QTIF_CAPS);
2599 /*** audio/x-mod ***/
2601 static GstStaticCaps mod_caps = GST_STATIC_CAPS ("audio/x-mod");
2603 #define MOD_CAPS gst_static_caps_get(&mod_caps)
2604 /* FIXME: M15 CheckType to do */
2606 mod_type_find (GstTypeFind * tf, gpointer unused)
2611 if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) {
2612 /* Protracker and variants */
2613 if ((memcmp (data, "M.K.", 4) == 0) || (memcmp (data, "M!K!", 4) == 0) ||
2615 (memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) ||
2616 (memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) ||
2617 /* Oktalyzer (Amiga) */
2618 (memcmp (data, "OKTA", 4) == 0) ||
2619 /* Oktalyser (Atari) */
2620 (memcmp (data, "CD81", 4) == 0) ||
2622 (memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) ||
2623 /* Fasttracker or Taketracker */
2624 (memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0])
2625 && isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0
2626 && isdigit (data[0]) && isdigit (data[1]))) {
2627 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2632 if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) {
2633 if (memcmp (data, "Extended Module: ", 17) == 0 && data[37] == 0x1A) {
2634 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2639 if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) {
2640 if (memcmp (data, "OKTASONG", 8) == 0) {
2641 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2645 if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2647 if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) {
2648 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2652 if ((memcmp (data, "AMF", 3) == 0 && data[3] > 10 && data[3] < 14) ||
2654 (memcmp (data, "IMPM", 4) == 0) ||
2656 (memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0) ||
2658 (memcmp (data, "MTM", 3) == 0)) {
2659 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2663 if (memcmp (data, "RIFF", 4) == 0) {
2664 guint8 *data2 = gst_type_find_peek (tf, 8, 4);
2667 if (memcmp (data2, "DSMF", 4) == 0) {
2668 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2674 if (memcmp (data, "FAM\xFE", 4) == 0) {
2675 guint8 *data2 = gst_type_find_peek (tf, 44, 3);
2678 if (memcmp (data2, "compare", 3) == 0) {
2679 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2683 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2688 if (memcmp (data, "GDM\xFE", 4) == 0) {
2689 guint8 *data2 = gst_type_find_peek (tf, 71, 4);
2692 if (memcmp (data2, "GMFS", 4) == 0) {
2693 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2697 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2703 if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) {
2704 if (memcmp (data, "IM10", 4) == 0) {
2705 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2710 if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) {
2711 if (memcmp (data, "SCRM", 4) == 0) {
2712 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2717 if ((data = gst_type_find_peek (tf, 20, 8)) != NULL) {
2718 if (g_ascii_strncasecmp ((gchar *) data, "!Scream!", 8) == 0 ||
2719 g_ascii_strncasecmp ((gchar *) data, "BMOD2STM", 8) == 0) {
2720 guint8 *id, *stmtype;
2722 if ((id = gst_type_find_peek (tf, 28, 1)) == NULL)
2724 if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL)
2726 if (*id == 0x1A && *stmtype == 2)
2727 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2733 /*** application/x-shockwave-flash ***/
2735 static GstStaticCaps swf_caps =
2736 GST_STATIC_CAPS ("application/x-shockwave-flash");
2737 #define SWF_CAPS (gst_static_caps_get(&swf_caps))
2739 swf_type_find (GstTypeFind * tf, gpointer unused)
2741 guint8 *data = gst_type_find_peek (tf, 0, 4);
2743 if (data && (data[0] == 'F' || data[0] == 'C') &&
2744 data[1] == 'W' && data[2] == 'S') {
2745 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SWF_CAPS);
2749 /*** image/jpeg ***/
2751 #define JPEG_MARKER_IS_START_OF_FRAME(x) \
2752 ((x)>=0xc0 && (x) <= 0xcf && (x)!=0xc4 && (x)!=0xc8 && (x)!=0xcc)
2754 static GstStaticCaps jpeg_caps = GST_STATIC_CAPS ("image/jpeg");
2756 #define JPEG_CAPS (gst_static_caps_get(&jpeg_caps))
2758 jpeg_type_find (GstTypeFind * tf, gpointer unused)
2760 GstTypeFindProbability prob = GST_TYPE_FIND_POSSIBLE;
2761 DataScanCtx c = { 0, NULL, 0 };
2765 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 2)))
2768 if (c.data[0] != 0xff || c.data[1] != 0xd8)
2772 data_scan_ctx_advance (tf, &c, 2);
2774 caps = gst_caps_copy (JPEG_CAPS);
2776 while (data_scan_ctx_ensure_data (tf, &c, 4) && c.offset < (200 * 1024)) {
2780 if (c.data[0] != 0xff)
2784 if (G_UNLIKELY (marker == 0xff)) {
2785 data_scan_ctx_advance (tf, &c, 1);
2789 data_scan_ctx_advance (tf, &c, 2);
2791 /* we assume all markers we'll see before SOF have a payload length; if
2792 * that's not the case we'll just detect a false sync and bail out, but
2793 * still report POSSIBLE probability */
2794 len = GST_READ_UINT16_BE (c.data);
2796 GST_LOG ("possible JPEG marker 0x%02x (@0x%04x), segment length %u",
2797 marker, (guint) c.offset, len);
2799 if (!data_scan_ctx_ensure_data (tf, &c, len))
2802 if (marker == 0xc4 || /* DEFINE_HUFFMAN_TABLES */
2803 marker == 0xcc || /* DEFINE_ARITHMETIC_CONDITIONING */
2804 marker == 0xdb || /* DEFINE_QUANTIZATION_TABLES */
2805 marker == 0xdd || /* DEFINE_RESTART_INTERVAL */
2806 marker == 0xfe) { /* COMMENT */
2807 data_scan_ctx_advance (tf, &c, len);
2809 } else if (marker == 0xe0 && len >= (2 + 4) && /* APP0 */
2810 data_scan_ctx_memcmp (tf, &c, 2, "JFIF", 4)) {
2811 GST_LOG ("found JFIF tag");
2812 prob = GST_TYPE_FIND_MAXIMUM;
2813 data_scan_ctx_advance (tf, &c, len);
2815 /* we continue until we find a start of frame marker */
2816 } else if (marker == 0xe1 && len >= (2 + 4) && /* APP1 */
2817 data_scan_ctx_memcmp (tf, &c, 2, "Exif", 4)) {
2818 GST_LOG ("found Exif tag");
2819 prob = GST_TYPE_FIND_MAXIMUM;
2820 data_scan_ctx_advance (tf, &c, len);
2822 /* we continue until we find a start of frame marker */
2823 } else if (marker >= 0xe0 && marker <= 0xef) { /* APPn */
2824 data_scan_ctx_advance (tf, &c, len);
2826 } else if (JPEG_MARKER_IS_START_OF_FRAME (marker) && len >= (2 + 8)) {
2829 h = GST_READ_UINT16_BE (c.data + 2 + 1);
2830 w = GST_READ_UINT16_BE (c.data + 2 + 1 + 2);
2831 if (h == 0 || w == 0) {
2832 GST_WARNING ("bad width %u and/or height %u in SOF header", w, h);
2836 GST_LOG ("SOF at offset %" G_GUINT64_FORMAT ", num_markers=%d, "
2837 "WxH=%dx%d", c.offset - 2, num_markers, w, h);
2839 if (num_markers >= 5 || prob == GST_TYPE_FIND_MAXIMUM)
2840 prob = GST_TYPE_FIND_MAXIMUM;
2842 prob = GST_TYPE_FIND_LIKELY;
2844 gst_caps_set_simple (caps, "width", G_TYPE_INT, w,
2845 "height", G_TYPE_INT, h, NULL);
2848 GST_WARNING ("bad length or unexpected JPEG marker 0xff 0x%02x", marker);
2853 gst_type_find_suggest (tf, prob, caps);
2854 gst_caps_unref (caps);
2859 static GstStaticCaps bmp_caps = GST_STATIC_CAPS ("image/bmp");
2861 #define BMP_CAPS (gst_static_caps_get(&bmp_caps))
2863 bmp_type_find (GstTypeFind * tf, gpointer unused)
2865 DataScanCtx c = { 0, NULL, 0 };
2866 guint32 struct_size, w, h, planes, bpp;
2868 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 54)))
2871 if (c.data[0] != 'B' || c.data[1] != 'M')
2874 /* skip marker + size */
2875 data_scan_ctx_advance (tf, &c, 2 + 4);
2877 /* reserved, must be 0 */
2878 if (c.data[0] != 0 || c.data[1] != 0 || c.data[2] != 0 || c.data[3] != 0)
2881 data_scan_ctx_advance (tf, &c, 2 + 2);
2883 /* offset to start of image data in bytes (check for sanity) */
2884 GST_LOG ("offset=%u", GST_READ_UINT32_LE (c.data));
2885 if (GST_READ_UINT32_LE (c.data) > (10 * 1024 * 1024))
2888 struct_size = GST_READ_UINT32_LE (c.data + 4);
2889 GST_LOG ("struct_size=%u", struct_size);
2891 data_scan_ctx_advance (tf, &c, 4 + 4);
2893 if (struct_size == 0x0C) {
2894 w = GST_READ_UINT16_LE (c.data);
2895 h = GST_READ_UINT16_LE (c.data + 2);
2896 planes = GST_READ_UINT16_LE (c.data + 2 + 2);
2897 bpp = GST_READ_UINT16_LE (c.data + 2 + 2 + 2);
2898 } else if (struct_size == 40 || struct_size == 64 || struct_size == 108
2899 || struct_size == 124 || struct_size == 0xF0) {
2900 w = GST_READ_UINT32_LE (c.data);
2901 h = GST_READ_UINT32_LE (c.data + 4);
2902 planes = GST_READ_UINT16_LE (c.data + 4 + 4);
2903 bpp = GST_READ_UINT16_LE (c.data + 4 + 4 + 2);
2908 /* image sizes sanity check */
2909 GST_LOG ("w=%u, h=%u, planes=%u, bpp=%u", w, h, planes, bpp);
2910 if (w == 0 || w > 0xfffff || h == 0 || h > 0xfffff || planes != 1 ||
2911 (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32))
2914 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "image/bmp",
2915 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, "bpp", G_TYPE_INT, bpp,
2919 /*** image/tiff ***/
2920 static GstStaticCaps tiff_caps = GST_STATIC_CAPS ("image/tiff, "
2921 "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }");
2922 #define TIFF_CAPS (gst_static_caps_get(&tiff_caps))
2923 static GstStaticCaps tiff_be_caps = GST_STATIC_CAPS ("image/tiff, "
2924 "endianness = (int) BIG_ENDIAN");
2925 #define TIFF_BE_CAPS (gst_static_caps_get(&tiff_be_caps))
2926 static GstStaticCaps tiff_le_caps = GST_STATIC_CAPS ("image/tiff, "
2927 "endianness = (int) LITTLE_ENDIAN");
2928 #define TIFF_LE_CAPS (gst_static_caps_get(&tiff_le_caps))
2930 tiff_type_find (GstTypeFind * tf, gpointer ununsed)
2932 guint8 *data = gst_type_find_peek (tf, 0, 8);
2933 guint8 le_header[4] = { 0x49, 0x49, 0x2A, 0x00 };
2934 guint8 be_header[4] = { 0x4D, 0x4D, 0x00, 0x2A };
2937 if (memcmp (data, le_header, 4) == 0) {
2938 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_LE_CAPS);
2939 } else if (memcmp (data, be_header, 4) == 0) {
2940 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_BE_CAPS);
2947 static GstStaticCaps pnm_caps = GST_STATIC_CAPS ("image/x-portable-bitmap; "
2948 "image/x-portable-graymap; image/x-portable-pixmap; "
2949 "image/x-portable-anymap");
2951 #define PNM_CAPS (gst_static_caps_get(&pnm_caps))
2953 #define IS_PNM_WHITESPACE(c) \
2954 ((c) == ' ' || (c) == '\r' || (c) == '\n' || (c) == 't')
2957 pnm_type_find (GstTypeFind * tf, gpointer ununsed)
2959 const gchar *media_type = NULL;
2960 DataScanCtx c = { 0, NULL, 0 };
2963 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
2966 /* see http://en.wikipedia.org/wiki/Netpbm_format */
2967 if (c.data[0] != 'P' || c.data[1] < '1' || c.data[1] > '7' ||
2968 !IS_PNM_WHITESPACE (c.data[2]) ||
2969 (c.data[3] != '#' && c.data[3] < '0' && c.data[3] > '9'))
2972 switch (c.data[1]) {
2974 media_type = "image/x-portable-bitmap"; /* ASCII */
2977 media_type = "image/x-portable-graymap"; /* ASCII */
2980 media_type = "image/x-portable-pixmap"; /* ASCII */
2983 media_type = "image/x-portable-bitmap"; /* Raw */
2986 media_type = "image/x-portable-graymap"; /* Raw */
2989 media_type = "image/x-portable-pixmap"; /* Raw */
2992 media_type = "image/x-portable-anymap";
2995 g_return_if_reached ();
2998 /* try to extract width and height as well */
2999 if (c.data[1] != '7') {
3000 gchar s[64] = { 0, }
3003 /* need to skip any comment lines first */
3004 data_scan_ctx_advance (tf, &c, 3);
3005 while (c.data[0] == '#') { /* we know there's still data left */
3006 data_scan_ctx_advance (tf, &c, 1);
3007 while (c.data[0] != '\n' && c.data[0] != '\r') {
3008 if (!data_scan_ctx_ensure_data (tf, &c, 4))
3010 data_scan_ctx_advance (tf, &c, 1);
3012 data_scan_ctx_advance (tf, &c, 1);
3013 GST_LOG ("skipped comment line in PNM header");
3016 if (!data_scan_ctx_ensure_data (tf, &c, 32) &&
3017 !data_scan_ctx_ensure_data (tf, &c, 4)) {
3021 /* need to NUL-terminate data for sscanf */
3022 memcpy (s, c.data, MIN (sizeof (s) - 1, c.size));
3023 if (sscanf (s, "%u%c%u%c", &w, &sep1, &h, &sep2) == 4 &&
3024 IS_PNM_WHITESPACE (sep1) && IS_PNM_WHITESPACE (sep2) &&
3025 w > 0 && w < G_MAXINT && h > 0 && h < G_MAXINT) {
3026 GST_LOG ("extracted PNM width and height: %dx%d", w, h);
3032 /* FIXME: extract width + height for anymaps too */
3035 if (w > 0 && h > 0) {
3036 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type,
3037 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, NULL);
3039 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, media_type, NULL);
3043 static GstStaticCaps sds_caps = GST_STATIC_CAPS ("audio/x-sds");
3045 #define SDS_CAPS (gst_static_caps_get(&sds_caps))
3047 sds_type_find (GstTypeFind * tf, gpointer ununsed)
3049 guint8 *data = gst_type_find_peek (tf, 0, 4);
3050 guint8 mask[4] = { 0xFF, 0xFF, 0x80, 0xFF };
3051 guint8 match[4] = { 0xF0, 0x7E, 0, 0x01 };
3055 for (x = 0; x < 4; x++) {
3056 if ((data[x] & mask[x]) != match[x]) {
3060 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDS_CAPS);
3064 static GstStaticCaps ircam_caps = GST_STATIC_CAPS ("audio/x-ircam");
3066 #define IRCAM_CAPS (gst_static_caps_get(&ircam_caps))
3068 ircam_type_find (GstTypeFind * tf, gpointer ununsed)
3070 guint8 *data = gst_type_find_peek (tf, 0, 4);
3071 guint8 mask[4] = { 0xFF, 0xFF, 0xF8, 0xFF };
3072 guint8 match[4] = { 0x64, 0xA3, 0x00, 0x00 };
3074 gboolean matched = TRUE;
3079 for (x = 0; x < 4; x++) {
3080 if ((data[x] & mask[x]) != match[x]) {
3085 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, IRCAM_CAPS);
3088 /* now try the reverse version */
3090 for (x = 0; x < 4; x++) {
3091 if ((data[x] & mask[3 - x]) != match[3 - x]) {
3097 /* EBML typefind helper */
3099 ebml_check_header (GstTypeFind * tf, const gchar * doctype, int doctype_len)
3101 /* 4 bytes for EBML ID, 1 byte for header length identifier */
3102 guint8 *data = gst_type_find_peek (tf, 0, 4 + 1);
3103 gint len_mask = 0x80, size = 1, n = 1, total;
3109 if (data[0] != 0x1A || data[1] != 0x45 || data[2] != 0xDF || data[3] != 0xA3)
3112 /* length of header */
3114 while (size <= 8 && !(total & len_mask)) {
3120 total &= (len_mask - 1);
3122 total = (total << 8) | data[4 + n++];
3124 /* get new data for full header, 4 bytes for EBML ID,
3125 * EBML length tag and the actual header */
3126 data = gst_type_find_peek (tf, 0, 4 + size + total);
3130 /* the header must contain the doctype. For now, we don't parse the
3131 * whole header but simply check for the availability of that array
3132 * of characters inside the header. Not fully fool-proof, but good
3134 for (n = 4 + size; n <= 4 + size + total - doctype_len; n++)
3135 if (!memcmp (&data[n], doctype, doctype_len))
3141 /*** video/x-matroska ***/
3142 static GstStaticCaps matroska_caps = GST_STATIC_CAPS ("video/x-matroska");
3144 #define MATROSKA_CAPS (gst_static_caps_get(&matroska_caps))
3146 matroska_type_find (GstTypeFind * tf, gpointer ununsed)
3148 if (ebml_check_header (tf, "matroska", 8))
3149 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MATROSKA_CAPS);
3152 /*** video/webm ***/
3153 static GstStaticCaps webm_caps = GST_STATIC_CAPS ("video/webm");
3155 #define WEBM_CAPS (gst_static_caps_get(&webm_caps))
3157 webm_type_find (GstTypeFind * tf, gpointer ununsed)
3159 if (ebml_check_header (tf, "webm", 4))
3160 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, WEBM_CAPS);
3163 /*** application/mxf ***/
3164 static GstStaticCaps mxf_caps = GST_STATIC_CAPS ("application/mxf");
3166 #define MXF_MAX_PROBE_LENGTH (1024 * 64)
3167 #define MXF_CAPS (gst_static_caps_get(&mxf_caps))
3170 * MXF files start with a header partition pack key of 16 bytes which is defined
3171 * at SMPTE-377M 6.1. Before this there can be up to 64K of run-in which _must_
3172 * not contain the partition pack key.
3175 mxf_type_find (GstTypeFind * tf, gpointer ununsed)
3177 static const guint8 partition_pack_key[] =
3178 { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
3181 DataScanCtx c = { 0, NULL, 0 };
3183 while (c.offset <= MXF_MAX_PROBE_LENGTH) {
3185 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 1024)))
3188 /* look over in chunks of 1kbytes to avoid too much overhead */
3190 for (i = 0; i < 1024 - 16; i++) {
3191 /* Check first byte before calling more expensive memcmp function */
3192 if (G_UNLIKELY (c.data[i] == 0x06
3193 && memcmp (c.data + i, partition_pack_key, 13) == 0)) {
3194 /* Header partition pack? */
3195 if (c.data[i + 13] != 0x02)
3198 /* Partition status */
3199 if (c.data[i + 14] >= 0x05)
3202 /* Reserved, must be 0x00 */
3203 if (c.data[i + 15] != 0x00)
3206 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
3212 data_scan_ctx_advance (tf, &c, 1024 - 16);
3216 /*** video/x-dv ***/
3218 static GstStaticCaps dv_caps = GST_STATIC_CAPS ("video/x-dv, "
3219 "systemstream = (boolean) true");
3220 #define DV_CAPS (gst_static_caps_get(&dv_caps))
3222 dv_type_find (GstTypeFind * tf, gpointer private)
3226 data = gst_type_find_peek (tf, 0, 5);
3228 /* check for DIF and DV flag */
3229 if (data && (data[0] == 0x1f) && (data[1] == 0x07) && (data[2] == 0x00)) {
3230 const gchar *format;
3232 if (data[3] & 0x80) {
3238 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "video/x-dv",
3239 "systemstream", G_TYPE_BOOLEAN, TRUE,
3240 "format", G_TYPE_STRING, format, NULL);
3245 /*** application/ogg and application/x-annodex ***/
3246 static GstStaticCaps ogg_caps = GST_STATIC_CAPS ("application/ogg");
3247 static GstStaticCaps annodex_caps = GST_STATIC_CAPS ("application/x-annodex");
3248 static GstStaticCaps ogg_annodex_caps =
3249 GST_STATIC_CAPS ("application/ogg;application/x-annodex");
3251 #define OGGANX_CAPS (gst_static_caps_get(&ogg_annodex_caps))
3254 ogganx_type_find (GstTypeFind * tf, gpointer private)
3256 guint8 *data = gst_type_find_peek (tf, 0, 4);
3258 if ((data != NULL) && (memcmp (data, "OggS", 4) == 0)) {
3260 /* Check for an annodex fishbone header */
3261 data = gst_type_find_peek (tf, 28, 8);
3262 if (data && memcmp (data, "fishead\0", 8) == 0)
3263 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
3264 gst_static_caps_get (&annodex_caps));
3266 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
3267 gst_static_caps_get (&ogg_caps));
3271 /*** audio/x-vorbis ***/
3272 static GstStaticCaps vorbis_caps = GST_STATIC_CAPS ("audio/x-vorbis");
3274 #define VORBIS_CAPS (gst_static_caps_get(&vorbis_caps))
3276 vorbis_type_find (GstTypeFind * tf, gpointer private)
3278 guint8 *data = gst_type_find_peek (tf, 0, 30);
3284 /* 1 byte packet type (identification=0x01)
3285 6 byte string "vorbis"
3286 4 byte vorbis version */
3287 if (memcmp (data, "\001vorbis\000\000\000\000", 11) != 0)
3290 /* 1 byte channels must be != 0 */
3294 /* 4 byte samplerate must be != 0 */
3295 if (GST_READ_UINT32_LE (data) == 0)
3298 /* blocksize checks */
3299 blocksize_0 = data[0] & 0x0F;
3300 blocksize_1 = (data[0] & 0xF0) >> 4;
3301 if (blocksize_0 > blocksize_1)
3303 if (blocksize_0 < 6 || blocksize_0 > 13)
3305 if (blocksize_1 < 6 || blocksize_1 > 13)
3309 if ((data[0] & 0x01) != 1)
3311 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VORBIS_CAPS);
3315 /*** video/x-theora ***/
3317 static GstStaticCaps theora_caps = GST_STATIC_CAPS ("video/x-theora");
3319 #define THEORA_CAPS (gst_static_caps_get(&theora_caps))
3321 theora_type_find (GstTypeFind * tf, gpointer private)
3323 guint8 *data = gst_type_find_peek (tf, 0, 7); //42);
3326 if (data[0] != 0x80)
3328 if (memcmp (&data[1], "theora", 6) != 0)
3330 /* FIXME: make this more reliable when specs are out */
3332 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, THEORA_CAPS);
3338 kate_type_find (GstTypeFind * tf, gpointer private)
3340 guint8 *data = gst_type_find_peek (tf, 0, 64);
3341 gchar category[16] = { 0, };
3343 if (G_UNLIKELY (data == NULL))
3346 /* see: http://wiki.xiph.org/index.php/OggKate#Format_specification */
3347 if (G_LIKELY (memcmp (data, "\200kate\0\0\0", 8) != 0))
3350 /* make sure we always have a NUL-terminated string */
3351 memcpy (category, data + 48, 15);
3352 GST_LOG ("kate category: %s", category);
3353 /* canonical categories for subtitles: subtitles, spu-subtitles, SUB, K-SPU */
3354 if (strcmp (category, "subtitles") == 0 || strcmp (category, "SUB") == 0 ||
3355 strcmp (category, "spu-subtitles") == 0 ||
3356 strcmp (category, "K-SPU") == 0) {
3357 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3358 "subtitle/x-kate", NULL);
3360 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3361 "application/x-kate", NULL);
3365 /*** application/x-ogm-video or audio***/
3367 static GstStaticCaps ogmvideo_caps =
3368 GST_STATIC_CAPS ("application/x-ogm-video");
3369 #define OGMVIDEO_CAPS (gst_static_caps_get(&ogmvideo_caps))
3371 ogmvideo_type_find (GstTypeFind * tf, gpointer private)
3373 guint8 *data = gst_type_find_peek (tf, 0, 9);
3376 if (memcmp (data, "\001video\000\000\000", 9) != 0)
3378 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMVIDEO_CAPS);
3382 static GstStaticCaps ogmaudio_caps =
3383 GST_STATIC_CAPS ("application/x-ogm-audio");
3384 #define OGMAUDIO_CAPS (gst_static_caps_get(&ogmaudio_caps))
3386 ogmaudio_type_find (GstTypeFind * tf, gpointer private)
3388 guint8 *data = gst_type_find_peek (tf, 0, 9);
3391 if (memcmp (data, "\001audio\000\000\000", 9) != 0)
3393 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMAUDIO_CAPS);
3397 static GstStaticCaps ogmtext_caps = GST_STATIC_CAPS ("application/x-ogm-text");
3399 #define OGMTEXT_CAPS (gst_static_caps_get(&ogmtext_caps))
3401 ogmtext_type_find (GstTypeFind * tf, gpointer private)
3403 guint8 *data = gst_type_find_peek (tf, 0, 9);
3406 if (memcmp (data, "\001text\000\000\000\000", 9) != 0)
3408 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMTEXT_CAPS);
3412 /*** audio/x-speex ***/
3414 static GstStaticCaps speex_caps = GST_STATIC_CAPS ("audio/x-speex");
3416 #define SPEEX_CAPS (gst_static_caps_get(&speex_caps))
3418 speex_type_find (GstTypeFind * tf, gpointer private)
3420 guint8 *data = gst_type_find_peek (tf, 0, 80);
3423 /* 8 byte string "Speex "
3424 24 byte speex version string + int */
3425 if (memcmp (data, "Speex ", 8) != 0)
3429 /* 4 byte header size >= 80 */
3430 if (GST_READ_UINT32_LE (data) < 80)
3434 /* 4 byte sample rate <= 48000 */
3435 if (GST_READ_UINT32_LE (data) > 48000)
3439 /* currently there are only 3 speex modes. */
3440 if (GST_READ_UINT32_LE (data) > 3)
3444 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SPEEX_CAPS);
3448 /*** audio/x-celt ***/
3450 static GstStaticCaps celt_caps = GST_STATIC_CAPS ("audio/x-celt");
3452 #define CELT_CAPS (gst_static_caps_get(&celt_caps))
3454 celt_type_find (GstTypeFind * tf, gpointer private)
3456 guint8 *data = gst_type_find_peek (tf, 0, 8);
3459 /* 8 byte string "CELT " */
3460 if (memcmp (data, "CELT ", 8) != 0)
3463 /* TODO: Check other values of the CELT header */
3464 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CELT_CAPS);
3468 /*** application/x-ogg-skeleton ***/
3469 static GstStaticCaps ogg_skeleton_caps =
3470 GST_STATIC_CAPS ("application/x-ogg-skeleton, parsed=(boolean)FALSE");
3471 #define OGG_SKELETON_CAPS (gst_static_caps_get(&ogg_skeleton_caps))
3473 oggskel_type_find (GstTypeFind * tf, gpointer private)
3475 guint8 *data = gst_type_find_peek (tf, 0, 12);
3478 /* 8 byte string "fishead\0" for the ogg skeleton stream */
3479 if (memcmp (data, "fishead\0", 8) != 0)
3483 /* Require that the header contains version 3.0 */
3484 if (GST_READ_UINT16_LE (data) != 3)
3487 if (GST_READ_UINT16_LE (data) != 0)
3490 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGG_SKELETON_CAPS);
3494 static GstStaticCaps cmml_caps = GST_STATIC_CAPS ("text/x-cmml");
3496 #define CMML_CAPS (gst_static_caps_get(&cmml_caps))
3498 cmml_type_find (GstTypeFind * tf, gpointer private)
3500 /* Header is 12 bytes minimum (though we don't check the minor version */
3501 guint8 *data = gst_type_find_peek (tf, 0, 12);
3505 /* 8 byte string "CMML\0\0\0\0" for the magic number */
3506 if (memcmp (data, "CMML\0\0\0\0", 8) != 0)
3510 /* Require that the header contains at least version 2.0 */
3511 if (GST_READ_UINT16_LE (data) < 2)
3514 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CMML_CAPS);
3518 /*** application/x-tar ***/
3520 static GstStaticCaps tar_caps = GST_STATIC_CAPS ("application/x-tar");
3522 #define TAR_CAPS (gst_static_caps_get(&tar_caps))
3523 #define OLDGNU_MAGIC "ustar " /* 7 chars and a NUL */
3524 #define NEWGNU_MAGIC "ustar" /* 5 chars and a NUL */
3526 tar_type_find (GstTypeFind * tf, gpointer unused)
3528 guint8 *data = gst_type_find_peek (tf, 257, 8);
3530 /* of course we are not certain, but we don't want other typefind funcs
3531 * to detect formats of files within the tar archive, e.g. mp3s */
3533 if (memcmp (data, OLDGNU_MAGIC, 8) == 0) { /* sic */
3534 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3535 } else if (memcmp (data, NEWGNU_MAGIC, 6) == 0 && /* sic */
3536 g_ascii_isdigit (data[6]) && g_ascii_isdigit (data[7])) {
3537 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3542 /*** application/x-ar ***/
3544 static GstStaticCaps ar_caps = GST_STATIC_CAPS ("application/x-ar");
3546 #define AR_CAPS (gst_static_caps_get(&ar_caps))
3548 ar_type_find (GstTypeFind * tf, gpointer unused)
3550 guint8 *data = gst_type_find_peek (tf, 0, 24);
3552 if (data && memcmp (data, "!<arch>", 7) == 0) {
3555 for (i = 7; i < 24; ++i) {
3556 if (!g_ascii_isprint (data[i]) && data[i] != '\n') {
3557 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AR_CAPS);
3561 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AR_CAPS);
3565 /*** audio/x-au ***/
3567 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3568 * as it is only possible to register one typefind factory per 'name'
3569 * (which is in this case the caps), and the first one would be replaced by
3570 * the second one. */
3571 static GstStaticCaps au_caps = GST_STATIC_CAPS ("audio/x-au");
3573 #define AU_CAPS (gst_static_caps_get(&au_caps))
3575 au_type_find (GstTypeFind * tf, gpointer unused)
3577 guint8 *data = gst_type_find_peek (tf, 0, 4);
3580 if (memcmp (data, ".snd", 4) == 0 || memcmp (data, "dns.", 4) == 0) {
3581 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AU_CAPS);
3587 /*** video/x-nuv ***/
3589 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3590 * as it is only possible to register one typefind factory per 'name'
3591 * (which is in this case the caps), and the first one would be replaced by
3592 * the second one. */
3593 static GstStaticCaps nuv_caps = GST_STATIC_CAPS ("video/x-nuv");
3595 #define NUV_CAPS (gst_static_caps_get(&nuv_caps))
3597 nuv_type_find (GstTypeFind * tf, gpointer unused)
3599 guint8 *data = gst_type_find_peek (tf, 0, 11);
3602 if (memcmp (data, "MythTVVideo", 11) == 0
3603 || memcmp (data, "NuppelVideo", 11) == 0) {
3604 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, NUV_CAPS);
3609 /*** audio/x-paris ***/
3610 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3611 static GstStaticCaps paris_caps = GST_STATIC_CAPS ("audio/x-paris");
3613 #define PARIS_CAPS (gst_static_caps_get(&paris_caps))
3615 paris_type_find (GstTypeFind * tf, gpointer unused)
3617 guint8 *data = gst_type_find_peek (tf, 0, 4);
3620 if (memcmp (data, " paf", 4) == 0 || memcmp (data, "fap ", 4) == 0) {
3621 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, PARIS_CAPS);
3626 /*** audio/iLBC-sh ***/
3627 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3628 static GstStaticCaps ilbc_caps = GST_STATIC_CAPS ("audio/iLBC-sh");
3630 #define ILBC_CAPS (gst_static_caps_get(&ilbc_caps))
3632 ilbc_type_find (GstTypeFind * tf, gpointer unused)
3634 guint8 *data = gst_type_find_peek (tf, 0, 8);
3637 if (memcmp (data, "#!iLBC30", 8) == 0 || memcmp (data, "#!iLBC20", 8) == 0) {
3638 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, ILBC_CAPS);
3643 /*** application/x-ms-dos-executable ***/
3645 static GstStaticCaps msdos_caps =
3646 GST_STATIC_CAPS ("application/x-ms-dos-executable");
3647 #define MSDOS_CAPS (gst_static_caps_get(&msdos_caps))
3648 /* see http://www.madchat.org/vxdevl/papers/winsys/pefile/pefile.htm */
3650 msdos_type_find (GstTypeFind * tf, gpointer unused)
3652 guint8 *data = gst_type_find_peek (tf, 0, 64);
3654 if (data && data[0] == 'M' && data[1] == 'Z' &&
3655 GST_READ_UINT16_LE (data + 8) == 4) {
3656 guint32 pe_offset = GST_READ_UINT32_LE (data + 60);
3658 data = gst_type_find_peek (tf, pe_offset, 2);
3659 if (data && data[0] == 'P' && data[1] == 'E') {
3660 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, MSDOS_CAPS);
3665 /*** application/x-mmsh ***/
3667 static GstStaticCaps mmsh_caps = GST_STATIC_CAPS ("application/x-mmsh");
3669 #define MMSH_CAPS gst_static_caps_get(&mmsh_caps)
3671 /* This is to recognise mssh-over-http */
3673 mmsh_type_find (GstTypeFind * tf, gpointer unused)
3675 static const guint8 asf_marker[16] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66,
3676 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
3681 data = gst_type_find_peek (tf, 0, 2 + 2 + 4 + 2 + 2 + 16);
3682 if (data && data[0] == 0x24 && data[1] == 0x48 &&
3683 GST_READ_UINT16_LE (data + 2) > 2 + 2 + 4 + 2 + 2 + 16 &&
3684 memcmp (data + 2 + 2 + 4 + 2 + 2, asf_marker, 16) == 0) {
3685 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MMSH_CAPS);
3689 /*** video/x-dirac ***/
3691 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3692 * as it is only possible to register one typefind factory per 'name'
3693 * (which is in this case the caps), and the first one would be replaced by
3694 * the second one. */
3695 static GstStaticCaps dirac_caps = GST_STATIC_CAPS ("video/x-dirac");
3697 #define DIRAC_CAPS (gst_static_caps_get(&dirac_caps))
3699 dirac_type_find (GstTypeFind * tf, gpointer unused)
3701 guint8 *data = gst_type_find_peek (tf, 0, 8);
3704 if (memcmp (data, "BBCD", 4) == 0 || memcmp (data, "KW-DIRAC", 8) == 0) {
3705 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DIRAC_CAPS);
3710 /*** video/vivo ***/
3712 static GstStaticCaps vivo_caps = GST_STATIC_CAPS ("video/vivo");
3714 #define VIVO_CAPS gst_static_caps_get(&vivo_caps)
3717 vivo_type_find (GstTypeFind * tf, gpointer unused)
3719 static const guint8 vivo_marker[] = { 'V', 'e', 'r', 's', 'i', 'o', 'n',
3720 ':', 'V', 'i', 'v', 'o', '/'
3725 data = gst_type_find_peek (tf, 0, 1024);
3726 if (data == NULL || data[0] != 0x00)
3729 if ((data[1] & 0x80)) {
3730 if ((data[2] & 0x80))
3732 hdr_len = ((guint) (data[1] & 0x7f)) << 7;
3742 /* 1008 = 1022 - strlen ("Version:Vivo/") - 1 */
3743 while (pos < 1008 && data[pos] == '\r' && data[pos + 1] == '\n')
3746 if (memcmp (data + pos, vivo_marker, sizeof (vivo_marker)) == 0) {
3747 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VIVO_CAPS);
3751 /*** XDG MIME typefinder (to avoid false positives mostly) ***/
3755 xdgmime_typefind (GstTypeFind * find, gpointer user_data)
3758 gsize length = 16384;
3763 if ((tf_length = gst_type_find_get_length (find)) > 0)
3764 length = MIN (length, tf_length);
3766 if ((data = gst_type_find_peek (find, 0, length)) == NULL)
3769 tmp = g_content_type_guess (NULL, data, length, NULL);
3770 if (tmp == NULL || g_content_type_is_unknown (tmp)) {
3775 mimetype = g_content_type_get_mime_type (tmp);
3778 if (mimetype == NULL)
3781 GST_DEBUG ("Got mimetype '%s'", mimetype);
3783 /* Ignore audio/video types:
3784 * - our own typefinders in -base are likely to be better at this
3785 * (and if they're not, we really want to fix them, that's why we don't
3786 * report xdg-detected audio/video types at all, not even with a low
3788 * - we want to detect GStreamer media types and not MIME types
3789 * - the purpose of this xdg mime finder is mainly to prevent false
3790 * positives of non-media formats, not to typefind audio/video formats */
3791 if (g_str_has_prefix (mimetype, "audio/") ||
3792 g_str_has_prefix (mimetype, "video/")) {
3793 GST_LOG ("Ignoring audio/video mime type");
3798 /* Again, we mainly want the xdg typefinding to prevent false-positives on
3799 * non-media formats, so suggest the type with a probability that trumps
3800 * uncertain results of our typefinders, but not more than that. */
3801 GST_LOG ("Suggesting '%s' with probability POSSIBLE", mimetype);
3802 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE, mimetype, NULL);
3805 #endif /* USE_GIO */
3807 /*** generic typefind for streams that have some data at a specific position***/
3818 start_with_type_find (GstTypeFind * tf, gpointer private)
3820 GstTypeFindData *start_with = (GstTypeFindData *) private;
3823 GST_LOG ("trying to find mime type %s with the first %u bytes of data",
3824 gst_structure_get_name (gst_caps_get_structure (start_with->caps, 0)),
3826 data = gst_type_find_peek (tf, 0, start_with->size);
3827 if (data && memcmp (data, start_with->data, start_with->size) == 0) {
3828 gst_type_find_suggest (tf, start_with->probability, start_with->caps);
3833 sw_data_destroy (GstTypeFindData * sw_data)
3835 if (G_LIKELY (sw_data->caps != NULL))
3836 gst_caps_unref (sw_data->caps);
3840 #define TYPE_FIND_REGISTER_START_WITH(plugin,name,rank,ext,_data,_size,_probability)\
3842 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
3843 sw_data->data = (const guint8 *)_data; \
3844 sw_data->size = _size; \
3845 sw_data->probability = _probability; \
3846 sw_data->caps = gst_caps_new_simple (name, NULL); \
3847 if (!gst_type_find_register (plugin, name, rank, start_with_type_find,\
3848 (char **) ext, sw_data->caps, sw_data, \
3849 (GDestroyNotify) (sw_data_destroy))) { \
3850 gst_caps_unref (sw_data->caps); \
3855 /*** same for riff types ***/
3858 riff_type_find (GstTypeFind * tf, gpointer private)
3860 GstTypeFindData *riff_data = (GstTypeFindData *) private;
3861 guint8 *data = gst_type_find_peek (tf, 0, 12);
3863 if (data && (memcmp (data, "RIFF", 4) == 0 || memcmp (data, "AVF0", 4) == 0)) {
3865 if (memcmp (data, riff_data->data, 4) == 0)
3866 gst_type_find_suggest (tf, riff_data->probability, riff_data->caps);
3870 #define TYPE_FIND_REGISTER_RIFF(plugin,name,rank,ext,_data) \
3872 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
3873 sw_data->data = (gpointer)_data; \
3874 sw_data->size = 4; \
3875 sw_data->probability = GST_TYPE_FIND_MAXIMUM; \
3876 sw_data->caps = gst_caps_new_simple (name, NULL); \
3877 if (!gst_type_find_register (plugin, name, rank, riff_type_find, \
3878 (char **) ext, sw_data->caps, sw_data, \
3879 (GDestroyNotify) (sw_data_destroy))) { \
3880 gst_caps_unref (sw_data->caps); \
3886 /*** plugin initialization ***/
3888 #define TYPE_FIND_REGISTER(plugin,name,rank,func,ext,caps,priv,notify) \
3890 if (!gst_type_find_register (plugin, name, rank, func, (char **) ext, caps, priv, notify))\
3896 plugin_init (GstPlugin * plugin)
3898 /* can't initialize this via a struct as caps can't be statically initialized */
3900 /* note: asx/wax/wmx are XML files, asf doesn't handle them */
3901 /* FIXME-0.11: these should be const,
3902 this requires gstreamer/gst/gsttypefind::gst_type_find_register()
3903 to have define the parameter as const
3905 static const gchar *asf_exts[] = { "asf", "wm", "wma", "wmv", NULL };
3906 static const gchar *au_exts[] = { "au", "snd", NULL };
3907 static const gchar *avi_exts[] = { "avi", NULL };
3908 static const gchar *qcp_exts[] = { "qcp", NULL };
3909 static const gchar *cdxa_exts[] = { "dat", NULL };
3910 static const gchar *flac_exts[] = { "flac", NULL };
3911 static const gchar *flx_exts[] = { "flc", "fli", NULL };
3912 static const gchar *id3_exts[] =
3913 { "mp3", "mp2", "mp1", "mpga", "ogg", "flac", "tta", NULL };
3914 static const gchar *apetag_exts[] = { "ape", "mpc", "wv", NULL }; /* and mp3 and wav? */
3915 static const gchar *tta_exts[] = { "tta", NULL };
3916 static const gchar *mod_exts[] = { "669", "amf", "dsm", "gdm", "far", "imf",
3917 "it", "med", "mod", "mtm", "okt", "sam",
3918 "s3m", "stm", "stx", "ult", "xm", NULL
3920 static const gchar *mp3_exts[] = { "mp3", "mp2", "mp1", "mpga", NULL };
3921 static const gchar *ac3_exts[] = { "ac3", "eac3", NULL };
3922 static const gchar *dts_exts[] = { "dts", NULL };
3923 static const gchar *gsm_exts[] = { "gsm", NULL };
3924 static const gchar *musepack_exts[] = { "mpc", "mpp", "mp+", NULL };
3925 static const gchar *mpeg_sys_exts[] = { "mpe", "mpeg", "mpg", NULL };
3926 static const gchar *mpeg_video_exts[] = { "mpv", "mpeg", "mpg", NULL };
3927 static const gchar *mpeg_ts_exts[] = { "ts", "mts", NULL };
3928 static const gchar *ogg_exts[] = { "anx", "ogg", "ogm", NULL };
3929 static const gchar *qt_exts[] = { "mov", NULL };
3930 static const gchar *qtif_exts[] = { "qif", "qtif", "qti", NULL };
3931 static const gchar *mj2_exts[] = { "mj2", NULL };
3932 static const gchar *jp2_exts[] = { "jp2", NULL };
3933 static const gchar *rm_exts[] = { "ra", "ram", "rm", "rmvb", NULL };
3934 static const gchar *swf_exts[] = { "swf", "swfl", NULL };
3935 static const gchar *utf8_exts[] = { "txt", NULL };
3936 static const gchar *wav_exts[] = { "wav", NULL };
3937 static const gchar *aiff_exts[] = { "aiff", "aif", "aifc", NULL };
3938 static const gchar *svx_exts[] = { "iff", "svx", NULL };
3939 static const gchar *paris_exts[] = { "paf", NULL };
3940 static const gchar *nist_exts[] = { "nist", NULL };
3941 static const gchar *voc_exts[] = { "voc", NULL };
3942 static const gchar *sds_exts[] = { "sds", NULL };
3943 static const gchar *ircam_exts[] = { "sf", NULL };
3944 static const gchar *w64_exts[] = { "w64", NULL };
3945 static const gchar *shn_exts[] = { "shn", NULL };
3946 static const gchar *ape_exts[] = { "ape", NULL };
3947 static const gchar *uri_exts[] = { "ram", NULL };
3948 static const gchar *sdp_exts[] = { "sdp", NULL };
3949 static const gchar *smil_exts[] = { "smil", NULL };
3950 static const gchar *html_exts[] = { "htm", "html", NULL };
3951 static const gchar *xml_exts[] = { "xml", NULL };
3952 static const gchar *jpeg_exts[] = { "jpg", "jpe", "jpeg", NULL };
3953 static const gchar *gif_exts[] = { "gif", NULL };
3954 static const gchar *png_exts[] = { "png", NULL };
3955 static const gchar *bmp_exts[] = { "bmp", NULL };
3956 static const gchar *tiff_exts[] = { "tif", "tiff", NULL };
3957 static const gchar *matroska_exts[] = { "mkv", "mka", NULL };
3958 static const gchar *webm_exts[] = { "webm", NULL };
3959 static const gchar *mve_exts[] = { "mve", NULL };
3960 static const gchar *dv_exts[] = { "dv", "dif", NULL };
3961 static const gchar *amr_exts[] = { "amr", NULL };
3962 static const gchar *ilbc_exts[] = { "ilbc", NULL };
3963 static const gchar *sid_exts[] = { "sid", NULL };
3964 static const gchar *xcf_exts[] = { "xcf", NULL };
3965 static const gchar *mng_exts[] = { "mng", NULL };
3966 static const gchar *jng_exts[] = { "jng", NULL };
3967 static const gchar *xpm_exts[] = { "xpm", NULL };
3968 static const gchar *pnm_exts[] = { "pnm", "ppm", "pgm", "pbm", NULL };
3969 static const gchar *ras_exts[] = { "ras", NULL };
3970 static const gchar *bz2_exts[] = { "bz2", NULL };
3971 static const gchar *gz_exts[] = { "gz", NULL };
3972 static const gchar *zip_exts[] = { "zip", NULL };
3973 static const gchar *compress_exts[] = { "Z", NULL };
3974 static const gchar *m4a_exts[] = { "m4a", NULL };
3975 static const gchar *q3gp_exts[] = { "3gp", NULL };
3976 static const gchar *aac_exts[] = { "aac", NULL };
3977 static const gchar *spc_exts[] = { "spc", NULL };
3978 static const gchar *wavpack_exts[] = { "wv", "wvp", NULL };
3979 static const gchar *wavpack_correction_exts[] = { "wvc", NULL };
3980 static const gchar *rar_exts[] = { "rar", NULL };
3981 static const gchar *tar_exts[] = { "tar", NULL };
3982 static const gchar *ar_exts[] = { "a", NULL };
3983 static const gchar *msdos_exts[] = { "dll", "exe", "ocx", "sys", "scr",
3984 "msstyles", "cpl", NULL
3986 static const gchar *flv_exts[] = { "flv", NULL };
3987 static const gchar *m4v_exts[] = { "m4v", NULL };
3988 static const gchar *h264_exts[] = { "h264", "x264", "264", NULL };
3989 static const gchar *nuv_exts[] = { "nuv", NULL };
3990 static const gchar *vivo_exts[] = { "viv", NULL };
3991 static const gchar *nsf_exts[] = { "nsf", NULL };
3992 static const gchar *gym_exts[] = { "gym", NULL };
3993 static const gchar *ay_exts[] = { "ay", NULL };
3994 static const gchar *gbs_exts[] = { "gbs", NULL };
3995 static const gchar *kss_exts[] = { "kss", NULL };
3996 static const gchar *sap_exts[] = { "sap", NULL };
3997 static const gchar *vgm_exts[] = { "vgm", NULL };
3998 static const gchar *mid_exts[] = { "mid", "midi", NULL };
3999 static const gchar *mxmf_exts[] = { "mxmf", NULL };
4000 static const gchar *imelody_exts[] = { "imy", "ime", "imelody", NULL };
4001 static const gchar *pdf_exts[] = { "pdf", NULL };
4002 static const gchar *ps_exts[] = { "ps", NULL };
4003 static const gchar *svg_exts[] = { "svg", NULL };
4004 static const gchar *mxf_exts[] = { "mxf", NULL };
4005 static const gchar *ivf_exts[] = { "ivf", NULL };
4006 static const gchar *msword_exts[] = { "doc", NULL };
4007 static const gchar *dsstore_exts[] = { "DS_Store", NULL };
4008 static const gchar *psd_exts[] = { "psd", NULL };
4010 GST_DEBUG_CATEGORY_INIT (type_find_debug, "typefindfunctions",
4011 GST_DEBUG_FG_GREEN | GST_DEBUG_BG_RED, "generic type find functions");
4013 /* must use strings, macros don't accept initializers */
4014 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ms-asf", GST_RANK_SECONDARY,
4016 "\060\046\262\165\216\146\317\021\246\331\000\252\000\142\316\154", 16,
4017 GST_TYPE_FIND_MAXIMUM);
4018 TYPE_FIND_REGISTER (plugin, "audio/x-musepack", GST_RANK_PRIMARY,
4019 musepack_type_find, musepack_exts, MUSEPACK_CAPS, NULL, NULL);
4020 TYPE_FIND_REGISTER (plugin, "audio/x-au", GST_RANK_MARGINAL,
4021 au_type_find, au_exts, AU_CAPS, NULL, NULL);
4022 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-msvideo", GST_RANK_PRIMARY,
4024 TYPE_FIND_REGISTER_RIFF (plugin, "audio/qcelp", GST_RANK_PRIMARY,
4026 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-cdxa", GST_RANK_PRIMARY,
4028 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-vcd", GST_RANK_PRIMARY,
4029 cdxa_exts, "\000\377\377\377\377\377\377\377\377\377\377\000", 12,
4030 GST_TYPE_FIND_MAXIMUM);
4031 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-imelody", GST_RANK_PRIMARY,
4032 imelody_exts, "BEGIN:IMELODY", 13, GST_TYPE_FIND_MAXIMUM);
4034 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-smoke", GST_RANK_PRIMARY,
4035 NULL, "\x80smoke\x00\x01\x00", 6, GST_TYPE_FIND_MAXIMUM);
4037 TYPE_FIND_REGISTER (plugin, "audio/midi", GST_RANK_PRIMARY, mid_type_find,
4038 mid_exts, MID_CAPS, NULL, NULL);
4039 TYPE_FIND_REGISTER_RIFF (plugin, "audio/riff-midi", GST_RANK_PRIMARY,
4041 TYPE_FIND_REGISTER (plugin, "audio/mobile-xmf", GST_RANK_PRIMARY,
4042 mxmf_type_find, mxmf_exts, MXMF_CAPS, NULL, NULL);
4043 TYPE_FIND_REGISTER (plugin, "video/x-fli", GST_RANK_MARGINAL, flx_type_find,
4044 flx_exts, FLX_CAPS, NULL, NULL);
4045 TYPE_FIND_REGISTER (plugin, "application/x-id3v2", GST_RANK_PRIMARY + 103,
4046 id3v2_type_find, id3_exts, ID3_CAPS, NULL, NULL);
4047 TYPE_FIND_REGISTER (plugin, "application/x-id3v1", GST_RANK_PRIMARY + 101,
4048 id3v1_type_find, id3_exts, ID3_CAPS, NULL, NULL);
4049 TYPE_FIND_REGISTER (plugin, "application/x-apetag", GST_RANK_PRIMARY + 102,
4050 apetag_type_find, apetag_exts, APETAG_CAPS, NULL, NULL);
4051 TYPE_FIND_REGISTER (plugin, "audio/x-ttafile", GST_RANK_PRIMARY,
4052 tta_type_find, tta_exts, TTA_CAPS, NULL, NULL);
4053 TYPE_FIND_REGISTER (plugin, "audio/x-mod", GST_RANK_SECONDARY, mod_type_find,
4054 mod_exts, MOD_CAPS, NULL, NULL);
4055 TYPE_FIND_REGISTER (plugin, "audio/mpeg", GST_RANK_PRIMARY, mp3_type_find,
4056 mp3_exts, MP3_CAPS, NULL, NULL);
4057 TYPE_FIND_REGISTER (plugin, "audio/x-ac3", GST_RANK_PRIMARY, ac3_type_find,
4058 ac3_exts, AC3_CAPS, NULL, NULL);
4059 TYPE_FIND_REGISTER (plugin, "audio/x-dts", GST_RANK_SECONDARY, dts_type_find,
4060 dts_exts, DTS_CAPS, NULL, NULL);
4061 TYPE_FIND_REGISTER (plugin, "audio/x-gsm", GST_RANK_PRIMARY, NULL, gsm_exts,
4062 GSM_CAPS, NULL, NULL);
4063 TYPE_FIND_REGISTER (plugin, "video/mpeg-sys", GST_RANK_PRIMARY,
4064 mpeg_sys_type_find, mpeg_sys_exts, MPEG_SYS_CAPS, NULL, NULL);
4065 TYPE_FIND_REGISTER (plugin, "video/mpegts", GST_RANK_PRIMARY,
4066 mpeg_ts_type_find, mpeg_ts_exts, MPEGTS_CAPS, NULL, NULL);
4067 TYPE_FIND_REGISTER (plugin, "application/ogg", GST_RANK_PRIMARY,
4068 ogganx_type_find, ogg_exts, OGGANX_CAPS, NULL, NULL);
4069 TYPE_FIND_REGISTER (plugin, "video/mpeg-elementary", GST_RANK_MARGINAL,
4070 mpeg_video_stream_type_find, mpeg_video_exts, MPEG_VIDEO_CAPS, NULL,
4072 TYPE_FIND_REGISTER (plugin, "video/mpeg4", GST_RANK_PRIMARY,
4073 mpeg4_video_type_find, m4v_exts, MPEG_VIDEO_CAPS, NULL, NULL);
4074 TYPE_FIND_REGISTER (plugin, "video/x-h264", GST_RANK_PRIMARY,
4075 h264_video_type_find, h264_exts, MPEG_VIDEO_CAPS, NULL, NULL);
4076 TYPE_FIND_REGISTER (plugin, "video/x-nuv", GST_RANK_SECONDARY, nuv_type_find,
4077 nuv_exts, NUV_CAPS, NULL, NULL);
4080 TYPE_FIND_REGISTER (plugin, "audio/x-m4a", GST_RANK_PRIMARY, m4a_type_find,
4081 m4a_exts, M4A_CAPS, NULL, NULL);
4082 TYPE_FIND_REGISTER (plugin, "application/x-3gp", GST_RANK_PRIMARY,
4083 q3gp_type_find, q3gp_exts, Q3GP_CAPS, NULL, NULL);
4084 TYPE_FIND_REGISTER (plugin, "video/quicktime", GST_RANK_SECONDARY,
4085 qt_type_find, qt_exts, QT_CAPS, NULL, NULL);
4086 TYPE_FIND_REGISTER (plugin, "image/x-quicktime", GST_RANK_SECONDARY,
4087 qtif_type_find, qtif_exts, QTIF_CAPS, NULL, NULL);
4088 TYPE_FIND_REGISTER (plugin, "image/jp2", GST_RANK_PRIMARY,
4089 jp2_type_find, jp2_exts, JP2_CAPS, NULL, NULL);
4090 TYPE_FIND_REGISTER (plugin, "video/mj2", GST_RANK_PRIMARY,
4091 jp2_type_find, mj2_exts, MJ2_CAPS, NULL, NULL);
4093 TYPE_FIND_REGISTER (plugin, "text/html", GST_RANK_SECONDARY, html_type_find,
4094 html_exts, HTML_CAPS, NULL, NULL);
4095 TYPE_FIND_REGISTER_START_WITH (plugin, "application/vnd.rn-realmedia",
4096 GST_RANK_SECONDARY, rm_exts, ".RMF", 4, GST_TYPE_FIND_MAXIMUM);
4097 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-pn-realaudio",
4098 GST_RANK_SECONDARY, rm_exts, ".ra\375", 4, GST_TYPE_FIND_MAXIMUM);
4099 TYPE_FIND_REGISTER (plugin, "application/x-shockwave-flash",
4100 GST_RANK_SECONDARY, swf_type_find, swf_exts, SWF_CAPS, NULL, NULL);
4101 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-flv", GST_RANK_SECONDARY,
4102 flv_exts, "FLV", 3, GST_TYPE_FIND_MAXIMUM);
4103 TYPE_FIND_REGISTER (plugin, "text/plain", GST_RANK_MARGINAL, utf8_type_find,
4104 utf8_exts, UTF8_CAPS, NULL, NULL);
4105 TYPE_FIND_REGISTER (plugin, "text/uri-list", GST_RANK_MARGINAL, uri_type_find,
4106 uri_exts, URI_CAPS, NULL, NULL);
4107 TYPE_FIND_REGISTER (plugin, "application/sdp", GST_RANK_SECONDARY,
4108 sdp_type_find, sdp_exts, SDP_CAPS, NULL, NULL);
4109 TYPE_FIND_REGISTER (plugin, "application/smil", GST_RANK_SECONDARY,
4110 smil_type_find, smil_exts, SMIL_CAPS, NULL, NULL);
4111 TYPE_FIND_REGISTER (plugin, "application/xml", GST_RANK_MARGINAL,
4112 xml_type_find, xml_exts, GENERIC_XML_CAPS, NULL, NULL);
4113 TYPE_FIND_REGISTER_RIFF (plugin, "audio/x-wav", GST_RANK_PRIMARY, wav_exts,
4115 TYPE_FIND_REGISTER (plugin, "audio/x-aiff", GST_RANK_SECONDARY,
4116 aiff_type_find, aiff_exts, AIFF_CAPS, NULL, NULL);
4117 TYPE_FIND_REGISTER (plugin, "audio/x-svx", GST_RANK_SECONDARY, svx_type_find,
4118 svx_exts, SVX_CAPS, NULL, NULL);
4119 TYPE_FIND_REGISTER (plugin, "audio/x-paris", GST_RANK_SECONDARY,
4120 paris_type_find, paris_exts, PARIS_CAPS, NULL, NULL);
4121 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nist", GST_RANK_SECONDARY,
4122 nist_exts, "NIST", 4, GST_TYPE_FIND_MAXIMUM);
4123 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-voc", GST_RANK_SECONDARY,
4124 voc_exts, "Creative", 8, GST_TYPE_FIND_MAXIMUM);
4125 TYPE_FIND_REGISTER (plugin, "audio/x-sds", GST_RANK_SECONDARY, sds_type_find,
4126 sds_exts, SDS_CAPS, NULL, NULL);
4127 TYPE_FIND_REGISTER (plugin, "audio/x-ircam", GST_RANK_SECONDARY,
4128 ircam_type_find, ircam_exts, IRCAM_CAPS, NULL, NULL);
4129 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-w64", GST_RANK_SECONDARY,
4130 w64_exts, "riff", 4, GST_TYPE_FIND_MAXIMUM);
4131 TYPE_FIND_REGISTER (plugin, "audio/x-shorten", GST_RANK_SECONDARY,
4132 shn_type_find, shn_exts, SHN_CAPS, NULL, NULL);
4133 TYPE_FIND_REGISTER (plugin, "application/x-ape", GST_RANK_SECONDARY,
4134 ape_type_find, ape_exts, APE_CAPS, NULL, NULL);
4135 TYPE_FIND_REGISTER (plugin, "image/jpeg", GST_RANK_PRIMARY + 15,
4136 jpeg_type_find, jpeg_exts, JPEG_CAPS, NULL, NULL);
4137 TYPE_FIND_REGISTER_START_WITH (plugin, "image/gif", GST_RANK_PRIMARY,
4138 gif_exts, "GIF8", 4, GST_TYPE_FIND_MAXIMUM);
4139 TYPE_FIND_REGISTER_START_WITH (plugin, "image/png", GST_RANK_PRIMARY + 14,
4140 png_exts, "\211PNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
4141 TYPE_FIND_REGISTER (plugin, "image/bmp", GST_RANK_PRIMARY, bmp_type_find,
4142 bmp_exts, BMP_CAPS, NULL, NULL);
4143 TYPE_FIND_REGISTER (plugin, "image/tiff", GST_RANK_PRIMARY, tiff_type_find,
4144 tiff_exts, TIFF_CAPS, NULL, NULL);
4145 TYPE_FIND_REGISTER (plugin, "image/x-portable-pixmap", GST_RANK_SECONDARY,
4146 pnm_type_find, pnm_exts, PNM_CAPS, NULL, NULL);
4147 TYPE_FIND_REGISTER (plugin, "video/x-matroska", GST_RANK_PRIMARY,
4148 matroska_type_find, matroska_exts, MATROSKA_CAPS, NULL, NULL);
4149 TYPE_FIND_REGISTER (plugin, "video/webm", GST_RANK_PRIMARY,
4150 webm_type_find, webm_exts, WEBM_CAPS, NULL, NULL);
4151 TYPE_FIND_REGISTER (plugin, "application/mxf", GST_RANK_PRIMARY,
4152 mxf_type_find, mxf_exts, MXF_CAPS, NULL, NULL);
4153 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mve", GST_RANK_SECONDARY,
4154 mve_exts, "Interplay MVE File\032\000\032\000\000\001\063\021", 26,
4155 GST_TYPE_FIND_MAXIMUM);
4156 TYPE_FIND_REGISTER (plugin, "video/x-dv", GST_RANK_SECONDARY, dv_type_find,
4157 dv_exts, DV_CAPS, NULL, NULL);
4158 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-nb-sh", GST_RANK_PRIMARY,
4159 amr_exts, "#!AMR", 5, GST_TYPE_FIND_LIKELY);
4160 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-wb-sh", GST_RANK_PRIMARY,
4161 amr_exts, "#!AMR-WB", 7, GST_TYPE_FIND_MAXIMUM);
4162 TYPE_FIND_REGISTER (plugin, "audio/iLBC-sh", GST_RANK_PRIMARY,
4163 ilbc_type_find, ilbc_exts, ILBC_CAPS, NULL, NULL);
4164 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sid", GST_RANK_MARGINAL,
4165 sid_exts, "PSID", 4, GST_TYPE_FIND_MAXIMUM);
4166 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xcf", GST_RANK_SECONDARY,
4167 xcf_exts, "gimp xcf", 8, GST_TYPE_FIND_MAXIMUM);
4168 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mng", GST_RANK_SECONDARY,
4169 mng_exts, "\212MNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
4170 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-jng", GST_RANK_SECONDARY,
4171 jng_exts, "\213JNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
4172 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xpixmap", GST_RANK_SECONDARY,
4173 xpm_exts, "/* XPM */", 9, GST_TYPE_FIND_MAXIMUM);
4174 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-sun-raster",
4175 GST_RANK_SECONDARY, ras_exts, "\131\246\152\225", 4,
4176 GST_TYPE_FIND_MAXIMUM);
4177 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-bzip",
4178 GST_RANK_SECONDARY, bz2_exts, "BZh", 3, GST_TYPE_FIND_LIKELY);
4179 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-gzip",
4180 GST_RANK_SECONDARY, gz_exts, "\037\213", 2, GST_TYPE_FIND_LIKELY);
4181 TYPE_FIND_REGISTER_START_WITH (plugin, "application/zip", GST_RANK_SECONDARY,
4182 zip_exts, "PK\003\004", 4, GST_TYPE_FIND_LIKELY);
4183 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-compress",
4184 GST_RANK_SECONDARY, compress_exts, "\037\235", 2, GST_TYPE_FIND_LIKELY);
4185 TYPE_FIND_REGISTER (plugin, "subtitle/x-kate", GST_RANK_MARGINAL,
4186 kate_type_find, NULL, NULL, NULL, NULL);
4187 TYPE_FIND_REGISTER (plugin, "audio/x-flac", GST_RANK_PRIMARY,
4188 flac_type_find, flac_exts, FLAC_CAPS, NULL, NULL);
4189 TYPE_FIND_REGISTER (plugin, "audio/x-vorbis", GST_RANK_PRIMARY,
4190 vorbis_type_find, NULL, VORBIS_CAPS, NULL, NULL);
4191 TYPE_FIND_REGISTER (plugin, "video/x-theora", GST_RANK_PRIMARY,
4192 theora_type_find, NULL, THEORA_CAPS, NULL, NULL);
4193 TYPE_FIND_REGISTER (plugin, "application/x-ogm-video", GST_RANK_PRIMARY,
4194 ogmvideo_type_find, NULL, OGMVIDEO_CAPS, NULL, NULL);
4195 TYPE_FIND_REGISTER (plugin, "application/x-ogm-audio", GST_RANK_PRIMARY,
4196 ogmaudio_type_find, NULL, OGMAUDIO_CAPS, NULL, NULL);
4197 TYPE_FIND_REGISTER (plugin, "application/x-ogm-text", GST_RANK_PRIMARY,
4198 ogmtext_type_find, NULL, OGMTEXT_CAPS, NULL, NULL);
4199 TYPE_FIND_REGISTER (plugin, "audio/x-speex", GST_RANK_PRIMARY,
4200 speex_type_find, NULL, SPEEX_CAPS, NULL, NULL);
4201 TYPE_FIND_REGISTER (plugin, "audio/x-celt", GST_RANK_PRIMARY,
4202 celt_type_find, NULL, CELT_CAPS, NULL, NULL);
4203 TYPE_FIND_REGISTER (plugin, "application/x-ogg-skeleton", GST_RANK_PRIMARY,
4204 oggskel_type_find, NULL, OGG_SKELETON_CAPS, NULL, NULL);
4205 TYPE_FIND_REGISTER (plugin, "text/x-cmml", GST_RANK_PRIMARY, cmml_type_find,
4206 NULL, CMML_CAPS, NULL, NULL);
4207 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-executable",
4208 GST_RANK_MARGINAL, NULL, "\177ELF", 4, GST_TYPE_FIND_MAXIMUM);
4209 TYPE_FIND_REGISTER (plugin, "adts_mpeg_stream", GST_RANK_SECONDARY,
4210 aac_type_find, aac_exts, AAC_CAPS, NULL, NULL);
4211 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-spc", GST_RANK_SECONDARY,
4212 spc_exts, "SNES-SPC700 Sound File Data", 27, GST_TYPE_FIND_MAXIMUM);
4213 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack", GST_RANK_SECONDARY,
4214 wavpack_type_find, wavpack_exts, WAVPACK_CAPS, NULL, NULL);
4215 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack-correction", GST_RANK_SECONDARY,
4216 wavpack_type_find, wavpack_correction_exts, WAVPACK_CORRECTION_CAPS, NULL,
4218 TYPE_FIND_REGISTER (plugin, "application/postscript", GST_RANK_SECONDARY,
4219 postscript_type_find, ps_exts, POSTSCRIPT_CAPS, NULL, NULL);
4220 TYPE_FIND_REGISTER (plugin, "image/svg+xml", GST_RANK_SECONDARY,
4221 svg_type_find, svg_exts, SVG_CAPS, NULL, NULL);
4222 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-rar",
4223 GST_RANK_SECONDARY, rar_exts, "Rar!", 4, GST_TYPE_FIND_LIKELY);
4224 TYPE_FIND_REGISTER (plugin, "application/x-tar", GST_RANK_SECONDARY,
4225 tar_type_find, tar_exts, TAR_CAPS, NULL, NULL);
4226 TYPE_FIND_REGISTER (plugin, "application/x-ar", GST_RANK_SECONDARY,
4227 ar_type_find, ar_exts, AR_CAPS, NULL, NULL);
4228 TYPE_FIND_REGISTER (plugin, "application/x-ms-dos-executable",
4229 GST_RANK_SECONDARY, msdos_type_find, msdos_exts, MSDOS_CAPS, NULL, NULL);
4230 TYPE_FIND_REGISTER (plugin, "video/x-dirac", GST_RANK_PRIMARY,
4231 dirac_type_find, NULL, DIRAC_CAPS, NULL, NULL);
4232 TYPE_FIND_REGISTER (plugin, "multipart/x-mixed-replace", GST_RANK_SECONDARY,
4233 multipart_type_find, NULL, MULTIPART_CAPS, NULL, NULL);
4234 TYPE_FIND_REGISTER (plugin, "application/x-mmsh", GST_RANK_SECONDARY,
4235 mmsh_type_find, NULL, MMSH_CAPS, NULL, NULL);
4236 TYPE_FIND_REGISTER (plugin, "video/vivo", GST_RANK_SECONDARY,
4237 vivo_type_find, vivo_exts, VIVO_CAPS, NULL, NULL);
4238 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nsf",
4239 GST_RANK_SECONDARY, nsf_exts, "NESM\x1a", 5, GST_TYPE_FIND_MAXIMUM);
4240 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gym",
4241 GST_RANK_SECONDARY, gym_exts, "GYMX", 4, GST_TYPE_FIND_MAXIMUM);
4242 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-ay",
4243 GST_RANK_SECONDARY, ay_exts, "ZXAYEMUL", 8, GST_TYPE_FIND_MAXIMUM);
4244 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gbs",
4245 GST_RANK_SECONDARY, gbs_exts, "GBS\x01", 4, GST_TYPE_FIND_MAXIMUM);
4246 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-vgm",
4247 GST_RANK_SECONDARY, vgm_exts, "Vgm\x20", 4, GST_TYPE_FIND_MAXIMUM);
4248 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sap",
4249 GST_RANK_SECONDARY, sap_exts, "SAP\x0d\x0aAUTHOR\x20", 12,
4250 GST_TYPE_FIND_MAXIMUM);
4251 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ivf", GST_RANK_SECONDARY,
4252 ivf_exts, "DKIF", 4, GST_TYPE_FIND_NEARLY_CERTAIN);
4253 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-kss", GST_RANK_SECONDARY,
4254 kss_exts, "KSSX\0", 5, GST_TYPE_FIND_MAXIMUM);
4255 TYPE_FIND_REGISTER_START_WITH (plugin, "application/pdf", GST_RANK_SECONDARY,
4256 pdf_exts, "%PDF-", 5, GST_TYPE_FIND_LIKELY);
4257 TYPE_FIND_REGISTER_START_WITH (plugin, "application/msword",
4258 GST_RANK_SECONDARY, msword_exts, "\320\317\021\340\241\261\032\341", 8,
4259 GST_TYPE_FIND_LIKELY);
4260 /* Mac OS X .DS_Store files tend to be taken for video/mpeg */
4261 TYPE_FIND_REGISTER_START_WITH (plugin, "application/octet-stream",
4262 GST_RANK_SECONDARY, dsstore_exts, "\000\000\000\001Bud1", 8,
4263 GST_TYPE_FIND_LIKELY);
4264 TYPE_FIND_REGISTER_START_WITH (plugin, "image/vnd.adobe.photoshop",
4265 GST_RANK_SECONDARY, psd_exts, "8BPS\000\001\000\000\000\000", 10,
4266 GST_TYPE_FIND_LIKELY);
4269 TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,
4270 xdgmime_typefind, NULL, NULL, NULL, NULL);
4276 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
4278 "typefindfunctions",
4279 "default typefind functions",
4280 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)