2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3 * Copyright (C) 2005-2009 Tim-Philipp Müller <tim centricular net>
4 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * gsttypefindfunctions.c: collection of various typefind functions
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 #include <glib/gprintf.h>
31 /* don't want to add gio xdgmime typefinder if gio was disabled via configure */
43 #include <gst/pbutils/pbutils.h>
44 #include <gst/base/gstbytereader.h>
46 GST_DEBUG_CATEGORY_STATIC (type_find_debug);
47 #define GST_CAT_DEFAULT type_find_debug
49 /* so our code stays ready for 0.11 */
50 #define gst_type_find_peek(tf,off,len) \
51 ((const guint8 *)gst_type_find_peek((tf),(off),(len)))
53 /* DataScanCtx: helper for typefind functions that scan through data
54 * step-by-step, to avoid doing a peek at each and every offset */
56 #define DATA_SCAN_CTX_CHUNK_SIZE 4096
66 data_scan_ctx_advance (GstTypeFind * tf, DataScanCtx * c, guint bytes_to_skip)
68 c->offset += bytes_to_skip;
69 if (G_LIKELY (c->size > bytes_to_skip)) {
70 c->size -= bytes_to_skip;
71 c->data += bytes_to_skip;
78 static inline gboolean
79 data_scan_ctx_ensure_data (GstTypeFind * tf, DataScanCtx * c, gint min_len)
83 guint chunk_len = MAX (DATA_SCAN_CTX_CHUNK_SIZE, min_len);
85 if (G_LIKELY (c->size >= min_len))
88 data = gst_type_find_peek (tf, c->offset, chunk_len);
89 if (G_LIKELY (data != NULL)) {
95 /* if there's less than our chunk size, try to get as much as we can, but
96 * always at least min_len bytes (we might be typefinding the first buffer
97 * of the stream and not have as much data available as we'd like) */
98 len = gst_type_find_get_length (tf);
100 len = CLAMP (len - c->offset, min_len, chunk_len);
105 data = gst_type_find_peek (tf, c->offset, len);
115 static inline gboolean
116 data_scan_ctx_memcmp (GstTypeFind * tf, DataScanCtx * c, guint offset,
117 const gchar * data, guint len)
119 if (!data_scan_ctx_ensure_data (tf, c, offset + len))
122 return (memcmp (c->data + offset, data, len) == 0);
126 static gboolean xml_check_first_element (GstTypeFind * tf,
127 const gchar * element, guint elen, gboolean strict);
128 static gboolean sdp_check_header (GstTypeFind * tf);
130 static GstStaticCaps utf8_caps = GST_STATIC_CAPS ("text/plain");
132 #define UTF8_CAPS gst_static_caps_get(&utf8_caps)
135 utf8_type_find_have_valid_utf8_at_offset (GstTypeFind * tf, guint64 offset,
136 GstTypeFindProbability * prob)
140 /* randomly decided values */
141 guint min_size = 16; /* minimum size */
142 guint size = 32 * 1024; /* starting size */
143 guint probability = 95; /* starting probability */
144 guint step = 10; /* how much we reduce probability in each
147 while (probability > step && size > min_size) {
148 data = gst_type_find_peek (tf, offset, size);
151 gchar *start = (gchar *) data;
153 if (g_utf8_validate (start, size, (const gchar **) &end) || (end - start + 4 > size)) { /* allow last char to be cut off */
168 utf8_type_find (GstTypeFind * tf, gpointer unused)
170 GstTypeFindProbability start_prob, mid_prob;
173 /* leave xml to the xml typefinders */
174 if (xml_check_first_element (tf, "", 0, TRUE))
177 /* leave sdp to the sdp typefinders */
178 if (sdp_check_header (tf))
181 /* check beginning of stream */
182 if (!utf8_type_find_have_valid_utf8_at_offset (tf, 0, &start_prob))
185 GST_LOG ("start is plain text with probability of %u", start_prob);
187 /* POSSIBLE is the highest probability we ever return if we can't
188 * probe into the middle of the file and don't know its length */
190 length = gst_type_find_get_length (tf);
191 if (length == 0 || length == (guint64) - 1) {
192 gst_type_find_suggest (tf, MIN (start_prob, GST_TYPE_FIND_POSSIBLE),
197 if (length < 64 * 1024) {
198 gst_type_find_suggest (tf, start_prob, UTF8_CAPS);
202 /* check middle of stream */
203 if (!utf8_type_find_have_valid_utf8_at_offset (tf, length / 2, &mid_prob))
206 GST_LOG ("middle is plain text with probability of %u", mid_prob);
207 gst_type_find_suggest (tf, (start_prob + mid_prob) / 2, UTF8_CAPS);
210 /*** text/utf-16 and text/utf-32} ***/
211 /* While UTF-8 is unicode too, using text/plain for UTF-16 and UTF-32
212 is going to break stuff. */
217 const char *const bom;
218 gboolean (*checker) (const guint8 *, gint, gint);
224 check_utf16 (const guint8 * data, gint len, gint endianness)
234 gst_byte_reader_init (&br, data, len);
236 /* test first for a single 16 bit value in the BMP */
237 if (endianness == G_BIG_ENDIAN)
238 gst_byte_reader_get_uint16_be (&br, &high);
240 gst_byte_reader_get_uint16_le (&br, &high);
241 if (high >= 0xD800 && high <= 0xDBFF) {
242 /* start of a surrogate pair */
246 if (endianness == G_BIG_ENDIAN)
247 gst_byte_reader_get_uint16_be (&br, &low);
249 gst_byte_reader_get_uint16_le (&br, &low);
250 if (low >= 0xDC00 && low <= 0xDFFF) {
251 /* second half of the surrogate pair */
255 if (high >= 0xDC00 && high <= 0xDFFF)
264 check_utf32 (const guint8 * data, gint len, gint endianness)
270 if (endianness == G_BIG_ENDIAN)
271 v = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
273 v = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0];
283 unicode_type_find (GstTypeFind * tf, const GstUnicodeTester * tester,
284 guint n_tester, const char *media_type, gboolean require_bom)
288 const guint8 *data = gst_type_find_peek (tf, 0, len);
290 const gint max_scan_size = 256 * 1024;
295 data = gst_type_find_peek (tf, 0, len);
300 /* find a large enough size that works */
301 while (len < max_scan_size) {
302 size_t newlen = len << 1;
303 const guint8 *newdata = gst_type_find_peek (tf, 0, newlen);
310 for (n = 0; n < n_tester; ++n) {
311 int bom_boost = 0, tmpprob;
312 if (len >= tester[n].bomlen) {
313 if (!memcmp (data, tester[n].bom, tester[n].bomlen))
314 bom_boost = tester[n].boost;
316 if (require_bom && bom_boost == 0)
318 if (!(*tester[n].checker) (data, len, tester[n].endianness))
320 tmpprob = GST_TYPE_FIND_POSSIBLE - 20 + bom_boost;
321 if (tmpprob > prob) {
323 endianness = tester[n].endianness;
328 GST_DEBUG ("This is valid %s %s", media_type,
329 endianness == G_BIG_ENDIAN ? "be" : "le");
330 gst_type_find_suggest_simple (tf, prob, media_type,
331 "endianness", G_TYPE_INT, endianness, NULL);
335 static GstStaticCaps utf16_caps = GST_STATIC_CAPS ("text/utf-16");
337 #define UTF16_CAPS gst_static_caps_get(&utf16_caps)
340 utf16_type_find (GstTypeFind * tf, gpointer unused)
342 static const GstUnicodeTester utf16tester[2] = {
343 {2, "\xff\xfe", check_utf16, 10, G_LITTLE_ENDIAN},
344 {2, "\xfe\xff", check_utf16, 20, G_BIG_ENDIAN},
346 unicode_type_find (tf, utf16tester, G_N_ELEMENTS (utf16tester),
347 "text/utf-16", TRUE);
350 static GstStaticCaps utf32_caps = GST_STATIC_CAPS ("text/utf-32");
352 #define UTF32_CAPS gst_static_caps_get(&utf32_caps)
355 utf32_type_find (GstTypeFind * tf, gpointer unused)
357 static const GstUnicodeTester utf32tester[2] = {
358 {4, "\xff\xfe\x00\x00", check_utf32, 10, G_LITTLE_ENDIAN},
359 {4, "\x00\x00\xfe\xff", check_utf32, 20, G_BIG_ENDIAN}
361 unicode_type_find (tf, utf32tester, G_N_ELEMENTS (utf32tester),
362 "text/utf-32", TRUE);
365 /*** text/uri-list ***/
367 static GstStaticCaps uri_caps = GST_STATIC_CAPS ("text/uri-list");
369 #define URI_CAPS (gst_static_caps_get(&uri_caps))
370 #define BUFFER_SIZE 16 /* If the string is < 16 bytes we're screwed */
371 #define INC_BUFFER { \
373 if (pos == BUFFER_SIZE) { \
375 offset += BUFFER_SIZE; \
376 data = gst_type_find_peek (tf, offset, BUFFER_SIZE); \
377 if (data == NULL) return; \
383 uri_type_find (GstTypeFind * tf, gpointer unused)
385 const guint8 *data = gst_type_find_peek (tf, 0, BUFFER_SIZE);
390 /* Search for # comment lines */
391 while (*data == '#') {
392 /* Goto end of line */
393 while (*data != '\n') {
400 if (!g_ascii_isalpha (*data)) {
401 /* Had a non alpha char - can't be uri-list */
407 while (g_ascii_isalnum (*data)) {
412 /* First non alpha char is not a : */
416 /* Get the next 2 bytes as well */
417 data = gst_type_find_peek (tf, offset + pos, 3);
421 if (data[1] != '/' && data[2] != '/') {
425 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, URI_CAPS);
429 /*** application/x-hls ***/
431 static GstStaticCaps hls_caps = GST_STATIC_CAPS ("application/x-hls");
432 #define HLS_CAPS (gst_static_caps_get(&hls_caps))
434 /* See http://tools.ietf.org/html/draft-pantos-http-live-streaming-05 */
436 hls_type_find (GstTypeFind * tf, gpointer unused)
438 DataScanCtx c = { 0, NULL, 0 };
440 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 7)))
443 if (memcmp (c.data, "#EXTM3U", 7))
446 data_scan_ctx_advance (tf, &c, 7);
448 /* Check only the first 256 bytes */
449 while (c.offset < 256) {
450 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 21)))
453 /* Search for # comment lines */
454 if (c.data[0] == '#' && (memcmp (c.data, "#EXT-X-TARGETDURATION", 21) == 0
455 || memcmp (c.data, "#EXT-X-STREAM-INF", 17) == 0)) {
456 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HLS_CAPS);
460 data_scan_ctx_advance (tf, &c, 1);
465 /*** application/xml **********************************************************/
467 #define XML_BUFFER_SIZE 16
468 #define XML_INC_BUFFER { \
470 if (pos == XML_BUFFER_SIZE) { \
472 offset += XML_BUFFER_SIZE; \
473 data = gst_type_find_peek (tf, offset, XML_BUFFER_SIZE); \
474 if (data == NULL) return FALSE; \
481 xml_check_first_element (GstTypeFind * tf, const gchar * element, guint elen,
489 data = gst_type_find_peek (tf, 0, XML_BUFFER_SIZE);
493 /* look for the XMLDec
494 * see XML spec 2.8, Prolog and Document Type Declaration
495 * http://www.w3.org/TR/2004/REC-xml-20040204/#sec-prolog-dtd */
496 got_xmldec = (memcmp (data, "<?xml", 5) == 0);
498 if (strict && !got_xmldec)
501 /* skip XMLDec in any case if we've got one */
507 /* look for the first element, it has to be the requested element. Bail
508 * out if it is not within the first 4kB. */
509 while (data && (offset + pos) < 4096) {
510 while (*data != '<' && (offset + pos) < 4096) {
515 if (!g_ascii_isalpha (*data)) {
516 /* if not alphabetic, it's a PI or an element / attribute declaration
517 * like <?xxx or <!xxx */
522 /* the first normal element, check if it's the one asked for */
523 data = gst_type_find_peek (tf, offset + pos, elen + 1);
524 return (data && element && strncmp ((char *) data, element, elen) == 0);
530 static GstStaticCaps generic_xml_caps = GST_STATIC_CAPS ("application/xml");
532 #define GENERIC_XML_CAPS (gst_static_caps_get(&generic_xml_caps))
534 xml_type_find (GstTypeFind * tf, gpointer unused)
536 if (xml_check_first_element (tf, "", 0, TRUE)) {
537 gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, GENERIC_XML_CAPS);
541 /*** application/sdp *********************************************************/
543 static GstStaticCaps sdp_caps = GST_STATIC_CAPS ("application/sdp");
545 #define SDP_CAPS (gst_static_caps_get(&sdp_caps))
547 sdp_check_header (GstTypeFind * tf)
551 data = gst_type_find_peek (tf, 0, 5);
555 /* sdp must start with v=0[\r]\n */
556 if (memcmp (data, "v=0", 3))
559 if (data[3] == '\r' && data[4] == '\n')
568 sdp_type_find (GstTypeFind * tf, gpointer unused)
570 if (sdp_check_header (tf))
571 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDP_CAPS);
574 /*** application/smil *********************************************************/
576 static GstStaticCaps smil_caps = GST_STATIC_CAPS ("application/smil");
578 #define SMIL_CAPS (gst_static_caps_get(&smil_caps))
580 smil_type_find (GstTypeFind * tf, gpointer unused)
582 if (xml_check_first_element (tf, "smil", 4, FALSE)) {
583 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SMIL_CAPS);
589 static GstStaticCaps html_caps = GST_STATIC_CAPS ("text/html");
591 #define HTML_CAPS gst_static_caps_get (&html_caps)
594 html_type_find (GstTypeFind * tf, gpointer unused)
596 const gchar *d, *data;
598 data = (const gchar *) gst_type_find_peek (tf, 0, 16);
602 if (!g_ascii_strncasecmp (data, "<!DOCTYPE HTML", 14)) {
603 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
604 } else if (xml_check_first_element (tf, "html", 4, FALSE)) {
605 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
606 } else if ((d = memchr (data, '<', 16))) {
607 data = (const gchar *) gst_type_find_peek (tf, d - data, 6);
608 if (data && g_ascii_strncasecmp (data, "<html>", 6) == 0) {
609 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, HTML_CAPS);
616 static GstStaticCaps mid_caps = GST_STATIC_CAPS ("audio/midi");
618 #define MID_CAPS gst_static_caps_get(&mid_caps)
620 mid_type_find (GstTypeFind * tf, gpointer unused)
622 const guint8 *data = gst_type_find_peek (tf, 0, 4);
624 /* http://jedi.ks.uiuc.edu/~johns/links/music/midifile.html */
625 if (data && data[0] == 'M' && data[1] == 'T' && data[2] == 'h'
627 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MID_CAPS);
630 /*** audio/mobile-xmf ***/
632 static GstStaticCaps mxmf_caps = GST_STATIC_CAPS ("audio/mobile-xmf");
634 #define MXMF_CAPS gst_static_caps_get(&mxmf_caps)
636 mxmf_type_find (GstTypeFind * tf, gpointer unused)
638 const guint8 *data = NULL;
640 /* Search FileId "XMF_" 4 bytes */
641 data = gst_type_find_peek (tf, 0, 4);
642 if (data && data[0] == 'X' && data[1] == 'M' && data[2] == 'F'
644 /* Search Format version "2.00" 4 bytes */
645 data = gst_type_find_peek (tf, 4, 4);
646 if (data && data[0] == '2' && data[1] == '.' && data[2] == '0'
648 /* Search TypeId 2 1 byte */
649 data = gst_type_find_peek (tf, 11, 1);
650 if (data && data[0] == 2) {
651 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXMF_CAPS);
658 /*** video/x-fli ***/
660 static GstStaticCaps flx_caps = GST_STATIC_CAPS ("video/x-fli");
662 #define FLX_CAPS gst_static_caps_get(&flx_caps)
664 flx_type_find (GstTypeFind * tf, gpointer unused)
666 const guint8 *data = gst_type_find_peek (tf, 0, 134);
669 /* check magic and the frame type of the first frame */
670 if ((data[4] == 0x11 || data[4] == 0x12 ||
671 data[4] == 0x30 || data[4] == 0x44) &&
673 ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1)) {
674 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLX_CAPS);
678 data = gst_type_find_peek (tf, 0, 6);
680 /* check magic only */
681 if ((data[4] == 0x11 || data[4] == 0x12 ||
682 data[4] == 0x30 || data[4] == 0x44) && data[5] == 0xaf) {
683 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, FLX_CAPS);
689 /*** application/x-id3 ***/
691 static GstStaticCaps id3_caps = GST_STATIC_CAPS ("application/x-id3");
693 #define ID3_CAPS gst_static_caps_get(&id3_caps)
695 id3v2_type_find (GstTypeFind * tf, gpointer unused)
697 const guint8 *data = gst_type_find_peek (tf, 0, 10);
699 if (data && memcmp (data, "ID3", 3) == 0 &&
700 data[3] != 0xFF && data[4] != 0xFF &&
701 (data[6] & 0x80) == 0 && (data[7] & 0x80) == 0 &&
702 (data[8] & 0x80) == 0 && (data[9] & 0x80) == 0) {
703 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
708 id3v1_type_find (GstTypeFind * tf, gpointer unused)
710 const guint8 *data = gst_type_find_peek (tf, -128, 3);
712 if (data && memcmp (data, "TAG", 3) == 0) {
713 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, ID3_CAPS);
717 /*** application/x-ape ***/
719 static GstStaticCaps apetag_caps = GST_STATIC_CAPS ("application/x-apetag");
721 #define APETAG_CAPS gst_static_caps_get(&apetag_caps)
723 apetag_type_find (GstTypeFind * tf, gpointer unused)
727 /* APEv1/2 at start of file */
728 data = gst_type_find_peek (tf, 0, 8);
729 if (data && !memcmp (data, "APETAGEX", 8)) {
730 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
734 /* APEv1/2 at end of file */
735 data = gst_type_find_peek (tf, -32, 8);
736 if (data && !memcmp (data, "APETAGEX", 8)) {
737 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, APETAG_CAPS);
742 /*** audio/x-ttafile ***/
744 static GstStaticCaps tta_caps = GST_STATIC_CAPS ("audio/x-ttafile");
746 #define TTA_CAPS gst_static_caps_get(&tta_caps)
748 tta_type_find (GstTypeFind * tf, gpointer unused)
750 const guint8 *data = gst_type_find_peek (tf, 0, 3);
753 if (memcmp (data, "TTA", 3) == 0) {
754 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TTA_CAPS);
760 /*** audio/x-flac ***/
761 static GstStaticCaps flac_caps = GST_STATIC_CAPS ("audio/x-flac");
763 #define FLAC_CAPS (gst_static_caps_get(&flac_caps))
766 flac_type_find (GstTypeFind * tf, gpointer unused)
768 DataScanCtx c = { 0, NULL, 0 };
770 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
773 /* standard flac (also old/broken flac-in-ogg with an initial 4-byte marker
774 * packet and without the usual packet framing) */
775 if (memcmp (c.data, "fLaC", 4) == 0) {
776 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
780 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
783 /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */
784 if (memcmp (c.data, "\177FLAC\001", 6) == 0) {
785 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS);
789 /* disabled because it happily typefinds /dev/urandom as audio/x-flac, and
790 * because I yet have to see header-less flac in the wild */
792 /* flac without headers (subset format) */
793 /* 64K should be enough */
794 while (c.offset < (64 * 1024)) {
795 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
798 /* look for frame header,
799 * http://flac.sourceforge.net/format.html#frame_header
801 if (c.data[0] == 0xff && (c.data[1] >> 2) == 0x3e) {
802 /* bit 15 in the header must be 0 */
803 if (((c.data[1] >> 1) & 0x01) == 0x01)
806 /* blocksize must be != 0x00 */
807 if ((c.data[2] >> 4) == 0x00)
810 /* samplerate must be != 0x0f */
811 if ((c.data[2] & 0x0f) == 0x0f)
813 /* also 0 is invalid, as it means get the info from the header and we
814 * don't have headers if we are here */
815 if ((c.data[2] & 0x0f) == 0x00)
818 /* channel assignment must be < 11 */
819 if ((c.data[3] >> 4) >= 11)
822 /* sample size must be != 0x07 and != 0x05 */
823 if (((c.data[3] >> 1) & 0x07) == 0x07)
825 if (((c.data[3] >> 1) & 0x07) == 0x05)
827 /* also 0 is invalid, as it means get the info from the header and we
828 * don't have headers if we are here */
829 if (((c.data[3] >> 1) & 0x07) == 0x00)
832 /* next bit must be 0 */
833 if ((c.data[3] & 0x01) == 0x01)
836 /* FIXME: shouldn't we include the crc check ? */
838 GST_DEBUG ("Found flac without headers at %d", (gint) c.offset);
839 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, FLAC_CAPS);
843 data_scan_ctx_advance (tf, &c, 1);
848 /*** audio/mpeg version 2, 4 ***/
850 static GstStaticCaps aac_caps = GST_STATIC_CAPS ("audio/mpeg, "
851 "mpegversion = (int) { 2, 4 }, framed = (bool) false");
852 #define AAC_CAPS (gst_static_caps_get(&aac_caps))
853 #define AAC_AMOUNT (4096)
855 aac_type_find (GstTypeFind * tf, gpointer unused)
857 /* LUT to convert the AudioObjectType from the ADTS header to a string */
858 DataScanCtx c = { 0, NULL, 0 };
860 while (c.offset < AAC_AMOUNT) {
863 /* detect adts header or adif header.
864 * The ADIF header is 4 bytes, that should be OK. The ADTS header, on
865 * the other hand, is 14 bits only, so we require one valid frame with
866 * again a valid syncpoint on the next one (28 bits) for certainty. We
867 * require 4 kB, which is quite a lot, since frames are generally 200-400
869 * LOAS has 2 possible syncwords, which are 11 bits and 16 bits long.
870 * The following stream syntax depends on which one is found.
872 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6)))
875 snc = GST_READ_UINT16_BE (c.data);
876 if (G_UNLIKELY ((snc & 0xfff6) == 0xfff0)) {
877 /* ADTS header - find frame length */
878 GST_DEBUG ("Found one ADTS syncpoint at offset 0x%" G_GINT64_MODIFIER
879 "x, tracing next...", c.offset);
880 len = ((c.data[3] & 0x03) << 11) |
881 (c.data[4] << 3) | ((c.data[5] & 0xe0) >> 5);
883 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
884 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
888 /* check if there's a second ADTS frame */
889 snc = GST_READ_UINT16_BE (c.data + len);
890 if ((snc & 0xfff6) == 0xfff0) {
892 guint mpegversion, sample_freq_idx, channel_config, profile_idx, rate;
893 guint8 audio_config[2];
895 mpegversion = (c.data[1] & 0x08) ? 2 : 4;
896 profile_idx = c.data[2] >> 6;
897 sample_freq_idx = ((c.data[2] & 0x3c) >> 2);
898 channel_config = ((c.data[2] & 0x01) << 2) + (c.data[3] >> 6);
900 GST_DEBUG ("Found second ADTS-%d syncpoint at offset 0x%"
901 G_GINT64_MODIFIER "x, framelen %u", mpegversion, c.offset, len);
903 /* 0xd and 0xe are reserved. 0xf means the sample frequency is directly
904 * specified in the header, but that's not allowed for ADTS */
905 if (sample_freq_idx > 0xc) {
906 GST_DEBUG ("Unexpected sample frequency index %d or wrong sync",
911 rate = gst_codec_utils_aac_get_sample_rate_from_index (sample_freq_idx);
912 GST_LOG ("ADTS: profile=%u, rate=%u", profile_idx, rate);
914 /* The ADTS frame header is slightly different from the
915 * AudioSpecificConfig defined for the MPEG-4 container, so we just
916 * construct enough of it for getting the level here. */
917 /* ADTS counts profiles from 0 instead of 1 to save bits */
918 audio_config[0] = (profile_idx + 1) << 3;
919 audio_config[0] |= (sample_freq_idx >> 1) & 0x7;
920 audio_config[1] = (sample_freq_idx & 0x1) << 7;
921 audio_config[1] |= (channel_config & 0xf) << 3;
923 caps = gst_caps_new_simple ("audio/mpeg",
924 "framed", G_TYPE_BOOLEAN, FALSE,
925 "mpegversion", G_TYPE_INT, mpegversion,
926 "stream-format", G_TYPE_STRING, "adts", NULL);
928 gst_codec_utils_aac_caps_set_level_and_profile (caps, audio_config, 2);
930 /* add rate and number of channels if we can */
931 if (channel_config != 0 && channel_config <= 7) {
932 const guint channels_map[] = { 0, 1, 2, 3, 4, 5, 6, 8 };
934 gst_caps_set_simple (caps, "channels", G_TYPE_INT,
935 channels_map[channel_config], "rate", G_TYPE_INT, rate, NULL);
938 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, caps);
939 gst_caps_unref (caps);
943 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
944 } else if (G_UNLIKELY (((snc & 0xffe0) == 0x56e0) || (snc == 0x4de1))) {
947 GST_DEBUG ("Found one LOAS syncword at offset 0x%" G_GINT64_MODIFIER
948 "x, tracing next...", c.offset);
950 /* check length of frame for each type of detectable LOAS streams */
952 /* EPAudioSyncStream */
953 len = ((c.data[2] & 0x0f) << 9) | (c.data[3] << 1) |
954 ((c.data[4] & 0x80) >> 7);
955 /* add size of EP sync stream header */
958 /* AudioSyncStream */
959 len = ((c.data[1] & 0x1f) << 8) | c.data[2];
960 /* add size of sync stream header */
964 if (len == 0 || !data_scan_ctx_ensure_data (tf, &c, len + 2)) {
965 GST_DEBUG ("Wrong sync or next frame not within reach, len=%u", len);
969 /* check if there's a second LOAS frame */
970 snc = GST_READ_UINT16_BE (c.data + len);
971 if (((snc & 0xffe0) == 0x56e0) || (snc == 0x4de1)) {
972 GST_DEBUG ("Found second LOAS syncword at offset 0x%"
973 G_GINT64_MODIFIER "x, framelen %u", c.offset, len);
975 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
976 "framed", G_TYPE_BOOLEAN, FALSE,
977 "mpegversion", G_TYPE_INT, 4,
978 "stream-format", G_TYPE_STRING, "loas", NULL);
982 GST_DEBUG ("No next frame found... (should have been at 0x%x)", len);
983 } else if (!memcmp (c.data, "ADIF", 4)) {
985 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg",
986 "framed", G_TYPE_BOOLEAN, FALSE, "mpegversion", G_TYPE_INT, 4,
987 "stream-format", G_TYPE_STRING, "adif", NULL);
993 data_scan_ctx_advance (tf, &c, 1);
997 /*** audio/mpeg version 1 ***/
1000 * The chance that random data is identified as a valid mp3 header is 63 / 2^18
1001 * (0.024%) per try. This makes the function for calculating false positives
1002 * 1 - (1 - ((63 / 2 ^18) ^ GST_MP3_TYPEFIND_MIN_HEADERS)) ^ buffersize)
1003 * This has the following probabilities of false positives:
1004 * datasize MIN_HEADERS
1006 * 4096 62.6% 0.02% 0% 0%
1007 * 16384 98% 0.09% 0% 0%
1008 * 1 MiB 100% 5.88% 0% 0%
1009 * 1 GiB 100% 100% 1.44% 0%
1010 * 1 TiB 100% 100% 100% 0.35%
1011 * This means that the current choice (3 headers by most of the time 4096 byte
1012 * buffers is pretty safe for now.
1014 * The max. size of each frame is 1440 bytes, which means that for N frames to
1015 * be detected, we need 1440 * GST_MP3_TYPEFIND_MIN_HEADERS + 3 bytes of data.
1016 * Assuming we step into the stream right after the frame header, this
1017 * means we need 1440 * (GST_MP3_TYPEFIND_MIN_HEADERS + 1) - 1 + 3 bytes
1018 * of data (5762) to always detect any mp3.
1021 static const guint mp3types_bitrates[2][3][16] =
1022 { {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
1023 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
1024 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
1025 {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
1026 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
1027 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}},
1030 static const guint mp3types_freqs[3][3] = { {11025, 12000, 8000},
1031 {22050, 24000, 16000},
1032 {44100, 48000, 32000}
1036 mp3_type_frame_length_from_header (guint32 header, guint * put_layer,
1037 guint * put_channels, guint * put_bitrate, guint * put_samplerate,
1038 gboolean * may_be_free_format, gint possible_free_framelen)
1040 guint bitrate, layer, length, mode, samplerate, version, channels;
1042 if ((header & 0xffe00000) != 0xffe00000)
1045 /* we don't need extension, copyright, original or
1046 * emphasis for the frame length */
1050 mode = header & 0x3;
1054 length = header & 0x1;
1057 /* sampling frequency */
1058 samplerate = header & 0x3;
1059 if (samplerate == 3)
1064 bitrate = header & 0xF;
1065 if (bitrate == 0 && possible_free_framelen == -1) {
1066 GST_LOG ("Possibly a free format mp3 - signaling");
1067 *may_be_free_format = TRUE;
1069 if (bitrate == 15 || (bitrate == 0 && possible_free_framelen == -1))
1072 /* ignore error correction, too */
1076 layer = 4 - (header & 0x3);
1081 /* version 0=MPEG2.5; 2=MPEG2; 3=MPEG1 */
1082 version = header & 0x3;
1087 channels = (mode == 3) ? 1 : 2;
1088 samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate];
1092 length += possible_free_framelen;
1093 bitrate = length * samplerate / 48000;
1095 length += possible_free_framelen;
1096 bitrate = length * samplerate /
1097 ((layer == 3 && version != 3) ? 72000 : 144000);
1101 bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate];
1103 length = ((12000 * bitrate / samplerate) + length) * 4;
1105 length += ((layer == 3
1106 && version != 3) ? 72000 : 144000) * bitrate / samplerate;
1110 GST_LOG ("mp3typefind: calculated mp3 frame length of %u bytes", length);
1112 ("mp3typefind: samplerate = %u - bitrate = %u - layer = %u - version = %u"
1113 " - channels = %u", samplerate, bitrate, layer, version, channels);
1118 *put_channels = channels;
1120 *put_bitrate = bitrate;
1122 *put_samplerate = samplerate;
1128 static GstStaticCaps mp3_caps = GST_STATIC_CAPS ("audio/mpeg, "
1129 "mpegversion = (int) 1, layer = (int) [ 1, 3 ]");
1130 #define MP3_CAPS (gst_static_caps_get(&mp3_caps))
1132 * random values for typefinding
1133 * if no more data is available, we will return a probability of
1134 * (found_headers/TRY_HEADERS) * (MAXIMUM * (TRY_SYNC - bytes_skipped)
1136 * if found_headers >= MIN_HEADERS
1138 #define GST_MP3_TYPEFIND_MIN_HEADERS (2)
1139 #define GST_MP3_TYPEFIND_TRY_HEADERS (5)
1140 #define GST_MP3_TYPEFIND_TRY_SYNC (GST_TYPE_FIND_MAXIMUM * 100) /* 10kB */
1141 #define GST_MP3_TYPEFIND_SYNC_SIZE (2048)
1142 #define GST_MP3_WRONG_HEADER (10)
1145 mp3_type_find_at_offset (GstTypeFind * tf, guint64 start_off,
1146 guint * found_layer, GstTypeFindProbability * found_prob)
1148 const guint8 *data = NULL;
1149 const guint8 *data_end = NULL;
1152 gint last_free_offset = -1;
1153 gint last_free_framelen = -1;
1154 gboolean headerstart = TRUE;
1161 while (skipped < GST_MP3_TYPEFIND_TRY_SYNC) {
1163 size = GST_MP3_TYPEFIND_SYNC_SIZE * 2;
1166 data = gst_type_find_peek (tf, skipped + start_off, size);
1167 } while (size > 10 && !data);
1170 data_end = data + size;
1172 if (*data == 0xFF) {
1173 const guint8 *head_data = NULL;
1174 guint layer = 0, bitrate, samplerate, channels;
1175 guint found = 0; /* number of valid headers found */
1176 guint64 offset = skipped;
1177 gboolean changed = FALSE;
1179 while (found < GST_MP3_TYPEFIND_TRY_HEADERS) {
1182 guint prev_layer = 0;
1183 guint prev_channels = 0, prev_samplerate = 0;
1184 gboolean free = FALSE;
1186 if ((gint64) (offset - skipped + 4) >= 0 &&
1187 data + offset - skipped + 4 < data_end) {
1188 head_data = data + offset - skipped;
1190 head_data = gst_type_find_peek (tf, offset + start_off, 4);
1194 head = GST_READ_UINT32_BE (head_data);
1195 if (!(length = mp3_type_frame_length_from_header (head, &layer,
1196 &channels, &bitrate, &samplerate, &free,
1197 last_free_framelen))) {
1199 if (last_free_offset == -1)
1200 last_free_offset = offset;
1202 last_free_framelen = offset - last_free_offset;
1203 offset = last_free_offset;
1207 last_free_framelen = -1;
1210 /* Mark the fact that we didn't find a valid header at the beginning */
1212 headerstart = FALSE;
1214 GST_LOG ("%d. header at offset %" G_GUINT64_FORMAT
1215 " (0x%" G_GINT64_MODIFIER "x) was not an mp3 header "
1216 "(possibly-free: %s)", found + 1, start_off + offset,
1217 start_off + offset, free ? "yes" : "no");
1220 if ((prev_layer && prev_layer != layer) ||
1221 /* (prev_bitrate && prev_bitrate != bitrate) || <-- VBR */
1222 (prev_samplerate && prev_samplerate != samplerate) ||
1223 (prev_channels && prev_channels != channels)) {
1224 /* this means an invalid property, or a change, which might mean
1225 * that this is not a mp3 but just a random bytestream. It could
1226 * be a freaking funky encoded mp3 though. We'll just not count
1231 prev_channels = channels;
1232 prev_samplerate = samplerate;
1235 GST_LOG ("found %d. header at offset %" G_GUINT64_FORMAT " (0x%"
1236 G_GINT64_MODIFIER "X)", found, start_off + offset,
1237 start_off + offset);
1241 g_assert (found <= GST_MP3_TYPEFIND_TRY_HEADERS);
1242 if (head_data == NULL &&
1243 gst_type_find_peek (tf, offset + start_off - 1, 1) == NULL)
1244 /* Incomplete last frame - don't count it. */
1246 if (found == GST_MP3_TYPEFIND_TRY_HEADERS ||
1247 (found >= GST_MP3_TYPEFIND_MIN_HEADERS && head_data == NULL)) {
1248 /* we can make a valid guess */
1249 guint probability = found * GST_TYPE_FIND_MAXIMUM *
1250 (GST_MP3_TYPEFIND_TRY_SYNC - skipped) /
1251 GST_MP3_TYPEFIND_TRY_HEADERS / GST_MP3_TYPEFIND_TRY_SYNC;
1254 && probability > (GST_TYPE_FIND_MINIMUM + GST_MP3_WRONG_HEADER))
1255 probability -= GST_MP3_WRONG_HEADER;
1256 if (probability < GST_TYPE_FIND_MINIMUM)
1257 probability = GST_TYPE_FIND_MINIMUM;
1261 probability = (probability + GST_TYPE_FIND_MAXIMUM) / 2;
1264 ("audio/mpeg calculated %u = %u * %u / %u * (%u - %"
1265 G_GUINT64_FORMAT ") / %u", probability, GST_TYPE_FIND_MAXIMUM,
1266 found, GST_MP3_TYPEFIND_TRY_HEADERS, GST_MP3_TYPEFIND_TRY_SYNC,
1267 (guint64) skipped, GST_MP3_TYPEFIND_TRY_SYNC);
1268 /* make sure we're not id3 tagged */
1269 head_data = gst_type_find_peek (tf, -128, 3);
1270 if (head_data && (memcmp (head_data, "TAG", 3) == 0)) {
1273 g_assert (probability <= GST_TYPE_FIND_MAXIMUM);
1275 *found_prob = probability;
1276 if (probability > 0)
1277 *found_layer = layer;
1288 mp3_type_find (GstTypeFind * tf, gpointer unused)
1290 GstTypeFindProbability prob, mid_prob;
1292 guint layer, mid_layer;
1295 mp3_type_find_at_offset (tf, 0, &layer, &prob);
1296 length = gst_type_find_get_length (tf);
1298 if (length == 0 || length == (guint64) - 1) {
1304 /* if we're pretty certain already, skip the additional check */
1305 if (prob >= GST_TYPE_FIND_LIKELY)
1308 mp3_type_find_at_offset (tf, length / 2, &mid_layer, &mid_prob);
1312 GST_LOG ("detected audio/mpeg only in the middle (p=%u)", mid_prob);
1318 if (layer != mid_layer) {
1319 GST_WARNING ("audio/mpeg layer discrepancy: %u vs. %u", layer, mid_layer);
1320 return; /* FIXME: or should we just go with the one in the middle? */
1323 /* detected mpeg audio both in middle of the file and at the start */
1324 prob = (prob + mid_prob) / 2;
1328 /* let's see if there's a valid header right at the start */
1329 data = gst_type_find_peek (tf, 0, 4); /* use min. frame size? */
1330 if (data && mp3_type_frame_length_from_header (GST_READ_UINT32_BE (data),
1331 &layer, NULL, NULL, NULL, NULL, 0) != 0) {
1333 prob = GST_TYPE_FIND_POSSIBLE - 10;
1335 prob = MAX (GST_TYPE_FIND_POSSIBLE - 10, prob + 10);
1345 g_return_if_fail (layer >= 1 && layer <= 3);
1347 gst_type_find_suggest_simple (tf, prob, "audio/mpeg",
1348 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, layer, NULL);
1352 /*** audio/x-musepack ***/
1354 static GstStaticCaps musepack_caps =
1355 GST_STATIC_CAPS ("audio/x-musepack, streamversion= (int) { 7, 8 }");
1357 #define MUSEPACK_CAPS (gst_static_caps_get(&musepack_caps))
1359 musepack_type_find (GstTypeFind * tf, gpointer unused)
1361 const guint8 *data = gst_type_find_peek (tf, 0, 4);
1362 GstTypeFindProbability prop = GST_TYPE_FIND_MINIMUM;
1363 gint streamversion = -1;
1365 if (data && memcmp (data, "MP+", 3) == 0) {
1367 if ((data[3] & 0x7f) == 7) {
1368 prop = GST_TYPE_FIND_MAXIMUM;
1370 prop = GST_TYPE_FIND_LIKELY + 10;
1372 } else if (data && memcmp (data, "MPCK", 4) == 0) {
1374 prop = GST_TYPE_FIND_MAXIMUM;
1377 if (streamversion != -1) {
1378 gst_type_find_suggest_simple (tf, prop, "audio/x-musepack",
1379 "streamversion", G_TYPE_INT, streamversion, NULL);
1383 /*** audio/x-ac3 ***/
1384 /* FIXME 0.11: should be audio/ac3, but isn't for backwards compatibility */
1385 static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
1387 #define AC3_CAPS (gst_static_caps_get(&ac3_caps))
1389 static GstStaticCaps eac3_caps = GST_STATIC_CAPS ("audio/x-eac3");
1391 #define EAC3_CAPS (gst_static_caps_get(&eac3_caps))
1395 unsigned short bit_rate;
1396 unsigned short frm_size[3];
1399 static const struct ac3_frmsize ac3_frmsizecod_tbl[] = {
1402 {40, {80, 87, 120}},
1403 {40, {80, 88, 120}},
1404 {48, {96, 104, 144}},
1405 {48, {96, 105, 144}},
1406 {56, {112, 121, 168}},
1407 {56, {112, 122, 168}},
1408 {64, {128, 139, 192}},
1409 {64, {128, 140, 192}},
1410 {80, {160, 174, 240}},
1411 {80, {160, 175, 240}},
1412 {96, {192, 208, 288}},
1413 {96, {192, 209, 288}},
1414 {112, {224, 243, 336}},
1415 {112, {224, 244, 336}},
1416 {128, {256, 278, 384}},
1417 {128, {256, 279, 384}},
1418 {160, {320, 348, 480}},
1419 {160, {320, 349, 480}},
1420 {192, {384, 417, 576}},
1421 {192, {384, 418, 576}},
1422 {224, {448, 487, 672}},
1423 {224, {448, 488, 672}},
1424 {256, {512, 557, 768}},
1425 {256, {512, 558, 768}},
1426 {320, {640, 696, 960}},
1427 {320, {640, 697, 960}},
1428 {384, {768, 835, 1152}},
1429 {384, {768, 836, 1152}},
1430 {448, {896, 975, 1344}},
1431 {448, {896, 976, 1344}},
1432 {512, {1024, 1114, 1536}},
1433 {512, {1024, 1115, 1536}},
1434 {576, {1152, 1253, 1728}},
1435 {576, {1152, 1254, 1728}},
1436 {640, {1280, 1393, 1920}},
1437 {640, {1280, 1394, 1920}}
1441 ac3_type_find (GstTypeFind * tf, gpointer unused)
1443 DataScanCtx c = { 0, NULL, 0 };
1445 /* Search for an ac3 frame; not necessarily right at the start, but give it
1446 * a lower probability if not found right at the start. Check that the
1447 * frame is followed by a second frame at the expected offset.
1448 * We could also check the two ac3 CRCs, but we don't do that right now */
1449 while (c.offset < 1024) {
1450 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 5)))
1453 if (c.data[0] == 0x0b && c.data[1] == 0x77) {
1454 guint bsid = c.data[5] >> 3;
1458 guint fscod = c.data[4] >> 6;
1459 guint frmsizecod = c.data[4] & 0x3f;
1461 if (fscod < 3 && frmsizecod < 38) {
1462 DataScanCtx c_next = c;
1465 frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
1466 GST_LOG ("possible AC3 frame sync at offset %"
1467 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1468 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1469 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1471 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1472 fscod = c_next.data[4] >> 6;
1473 frmsizecod = c_next.data[4] & 0x3f;
1475 if (fscod < 3 && frmsizecod < 38) {
1476 GstTypeFindProbability prob;
1478 GST_LOG ("found second AC3 frame (size=%u), looks good",
1479 ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod]);
1481 prob = GST_TYPE_FIND_MAXIMUM;
1483 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1485 gst_type_find_suggest (tf, prob, AC3_CAPS);
1489 GST_LOG ("no second AC3 frame found, false sync");
1493 } else if (bsid <= 16 && bsid > 10) {
1495 DataScanCtx c_next = c;
1498 frame_size = (((c.data[2] & 0x07) << 8) + c.data[3]) + 1;
1499 GST_LOG ("possible E-AC3 frame sync at offset %"
1500 G_GUINT64_FORMAT ", size=%u", c.offset, frame_size);
1501 if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
1502 data_scan_ctx_advance (tf, &c_next, frame_size * 2);
1504 if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
1505 GstTypeFindProbability prob;
1507 GST_LOG ("found second E-AC3 frame, looks good");
1509 prob = GST_TYPE_FIND_MAXIMUM;
1511 prob = GST_TYPE_FIND_NEARLY_CERTAIN;
1513 gst_type_find_suggest (tf, prob, EAC3_CAPS);
1516 GST_LOG ("no second E-AC3 frame found, false sync");
1520 GST_LOG ("invalid AC3 BSID: %u", bsid);
1523 data_scan_ctx_advance (tf, &c, 1);
1527 /*** audio/x-dts ***/
1528 static GstStaticCaps dts_caps = GST_STATIC_CAPS ("audio/x-dts");
1529 #define DTS_CAPS (gst_static_caps_get (&dts_caps))
1530 #define DTS_MIN_FRAMESIZE 96
1531 #define DTS_MAX_FRAMESIZE 18725 /* 16384*16/14 */
1534 dts_parse_frame_header (DataScanCtx * c, guint * frame_size,
1535 guint * sample_rate, guint * channels, guint * depth, guint * endianness)
1537 static const int sample_rates[16] = { 0, 8000, 16000, 32000, 0, 0, 11025,
1538 22050, 44100, 0, 0, 12000, 24000, 48000, 96000, 192000
1540 static const guint8 channels_table[16] = { 1, 2, 2, 2, 2, 3, 3, 4, 4, 5,
1545 guint num_blocks, chans, lfe, i;
1547 marker = GST_READ_UINT32_BE (c->data);
1549 /* raw big endian or 14-bit big endian */
1550 if (marker == 0x7FFE8001 || marker == 0x1FFFE800) {
1551 *endianness = G_BIG_ENDIAN;
1552 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1553 hdr[i] = GST_READ_UINT16_BE (c->data + (i * sizeof (guint16)));
1555 /* raw little endian or 14-bit little endian */
1556 if (marker == 0xFE7F0180 || marker == 0xFF1F00E8) {
1557 *endianness = G_LITTLE_ENDIAN;
1558 for (i = 0; i < G_N_ELEMENTS (hdr); ++i)
1559 hdr[i] = GST_READ_UINT16_LE (c->data + (i * sizeof (guint16)));
1564 GST_LOG ("dts sync marker 0x%08x at offset %u", marker, (guint) c->offset);
1567 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8) {
1568 if ((hdr[2] & 0xFFF0) != 0x07F0)
1570 /* discard top 2 bits (2 void), shift in 2 */
1571 hdr[0] = (hdr[0] << 2) | ((hdr[1] >> 12) & 0x0003);
1572 /* discard top 4 bits (2 void, 2 shifted into hdr[0]), shift in 4 etc. */
1573 hdr[1] = (hdr[1] << 4) | ((hdr[2] >> 10) & 0x000F);
1574 hdr[2] = (hdr[2] << 6) | ((hdr[3] >> 8) & 0x003F);
1575 hdr[3] = (hdr[3] << 8) | ((hdr[4] >> 6) & 0x00FF);
1576 hdr[4] = (hdr[4] << 10) | ((hdr[5] >> 4) & 0x03FF);
1577 hdr[5] = (hdr[5] << 12) | ((hdr[6] >> 2) & 0x0FFF);
1578 hdr[6] = (hdr[6] << 14) | ((hdr[7] >> 0) & 0x3FFF);
1579 g_assert (hdr[0] == 0x7FFE && hdr[1] == 0x8001);
1585 GST_LOG ("frame header: %04x%04x%04x%04x", hdr[2], hdr[3], hdr[4], hdr[5]);
1587 num_blocks = (hdr[2] >> 2) & 0x7F;
1588 *frame_size = (((hdr[2] & 0x03) << 12) | (hdr[3] >> 4)) + 1;
1589 chans = ((hdr[3] & 0x0F) << 2) | (hdr[4] >> 14);
1590 *sample_rate = sample_rates[(hdr[4] >> 10) & 0x0F];
1591 lfe = (hdr[5] >> 9) & 0x03;
1593 if (num_blocks < 5 || *frame_size < 96 || *sample_rate == 0)
1596 if (marker == 0x1FFFE800 || marker == 0xFF1F00E8)
1597 *frame_size = (*frame_size * 16) / 14; /* FIXME: round up? */
1599 if (chans < G_N_ELEMENTS (channels_table))
1600 *channels = channels_table[chans] + ((lfe) ? 1 : 0);
1608 dts_type_find (GstTypeFind * tf, gpointer unused)
1610 DataScanCtx c = { 0, NULL, 0 };
1612 /* Search for an dts frame; not necessarily right at the start, but give it
1613 * a lower probability if not found right at the start. Check that the
1614 * frame is followed by a second frame at the expected offset. */
1615 while (c.offset <= DTS_MAX_FRAMESIZE) {
1616 guint frame_size = 0, rate = 0, chans = 0, depth = 0, endianness = 0;
1618 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, DTS_MIN_FRAMESIZE)))
1621 if (G_UNLIKELY (dts_parse_frame_header (&c, &frame_size, &rate, &chans,
1622 &depth, &endianness))) {
1623 GstTypeFindProbability prob;
1626 prob = (c.offset == 0) ? GST_TYPE_FIND_LIKELY : GST_TYPE_FIND_POSSIBLE;
1628 /* check for second frame sync */
1630 data_scan_ctx_advance (tf, &next_c, frame_size);
1631 if (data_scan_ctx_ensure_data (tf, &next_c, 4)) {
1632 GST_LOG ("frame size: %u 0x%04x", frame_size, frame_size);
1633 GST_MEMDUMP ("second frame sync", next_c.data, 4);
1634 if (GST_READ_UINT32_BE (c.data) == GST_READ_UINT32_BE (next_c.data))
1635 prob = GST_TYPE_FIND_MAXIMUM;
1639 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
1640 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, chans,
1641 "depth", G_TYPE_INT, depth, "endianness", G_TYPE_INT, endianness,
1642 "framed", G_TYPE_BOOLEAN, FALSE, NULL);
1644 gst_type_find_suggest_simple (tf, prob, "audio/x-dts",
1645 "rate", G_TYPE_INT, rate, "depth", G_TYPE_INT, depth,
1646 "endianness", G_TYPE_INT, endianness,
1647 "framed", G_TYPE_BOOLEAN, FALSE, NULL);
1653 data_scan_ctx_advance (tf, &c, 1);
1659 /* can only be detected by using the extension, in which case we use the default
1661 static GstStaticCaps gsm_caps =
1662 GST_STATIC_CAPS ("audio/x-gsm, rate=8000, channels=1");
1664 #define GSM_CAPS (gst_static_caps_get(&gsm_caps))
1668 static GstStaticCaps wavpack_caps =
1669 GST_STATIC_CAPS ("audio/x-wavpack, framed = (boolean) false");
1671 #define WAVPACK_CAPS (gst_static_caps_get(&wavpack_caps))
1673 static GstStaticCaps wavpack_correction_caps =
1674 GST_STATIC_CAPS ("audio/x-wavpack-correction, framed = (boolean) false");
1676 #define WAVPACK_CORRECTION_CAPS (gst_static_caps_get(&wavpack_correction_caps))
1679 wavpack_type_find (GstTypeFind * tf, gpointer unused)
1685 data = gst_type_find_peek (tf, 0, 32);
1689 if (data[0] != 'w' || data[1] != 'v' || data[2] != 'p' || data[3] != 'k')
1692 /* Note: wavpack blocks can be fairly large (easily 60-110k), possibly
1693 * larger than the max. limits imposed by certain typefinding elements
1694 * like id3demux or apedemux, so typefinding is most likely only going to
1695 * work in pull-mode */
1696 blocksize = GST_READ_UINT32_LE (data + 4);
1697 GST_LOG ("wavpack header, blocksize=0x%04x", blocksize);
1699 while (offset < 32 + blocksize) {
1702 /* get chunk header */
1703 GST_LOG ("peeking at chunk at offset 0x%04x", (guint) offset);
1704 data = gst_type_find_peek (tf, offset, 4);
1707 sublen = ((guint32) data[1]) << 1;
1708 if (data[0] & 0x80) {
1709 sublen |= (((guint32) data[2]) << 9) | (((guint32) data[3]) << 17);
1710 sublen += 1 + 3; /* id + length */
1712 sublen += 1 + 1; /* id + length */
1714 if (sublen > blocksize - offset + 32) {
1715 GST_LOG ("chunk length too big (%u > %" G_GUINT64_FORMAT ")", sublen,
1716 blocksize - offset);
1719 if ((data[0] & 0x20) == 0) {
1720 switch (data[0] & 0x0f) {
1721 case 0xa: /* ID_WV_BITSTREAM */
1722 case 0xc: /* ID_WVX_BITSTREAM */
1723 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, WAVPACK_CAPS);
1725 case 0xb: /* ID_WVC_BITSTREAM */
1726 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY,
1727 WAVPACK_CORRECTION_CAPS);
1737 /*** application/postscrip ***/
1738 static GstStaticCaps postscript_caps =
1739 GST_STATIC_CAPS ("application/postscript");
1741 #define POSTSCRIPT_CAPS (gst_static_caps_get(&postscript_caps))
1744 postscript_type_find (GstTypeFind * tf, gpointer unused)
1746 const guint8 *data = gst_type_find_peek (tf, 0, 3);
1750 if (data[0] == 0x04)
1752 if (data[0] == '%' && data[1] == '!')
1753 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, POSTSCRIPT_CAPS);
1757 /*** image/svg+xml ***/
1758 static GstStaticCaps svg_caps = GST_STATIC_CAPS ("image/svg+xml");
1760 #define SVG_CAPS (gst_static_caps_get(&svg_caps))
1763 svg_type_find (GstTypeFind * tf, gpointer unused)
1765 static const gchar svg_doctype[] = "!DOCTYPE svg";
1766 static const gchar svg_tag[] = "<svg";
1767 DataScanCtx c = { 0, NULL, 0 };
1769 while (c.offset <= 1024) {
1770 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 12)))
1773 if (memcmp (svg_doctype, c.data, 12) == 0) {
1774 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVG_CAPS);
1776 } else if (memcmp (svg_tag, c.data, 4) == 0) {
1777 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, SVG_CAPS);
1780 data_scan_ctx_advance (tf, &c, 1);
1784 /*** multipart/x-mixed-replace mimestream ***/
1786 static GstStaticCaps multipart_caps =
1787 GST_STATIC_CAPS ("multipart/x-mixed-replace");
1788 #define MULTIPART_CAPS gst_static_caps_get(&multipart_caps)
1790 /* multipart/x-mixed replace is:
1791 * <maybe some whitespace>--<some ascii chars>[\r]\n
1792 * <more ascii chars>[\r]\nContent-type:<more ascii>[\r]\n */
1794 multipart_type_find (GstTypeFind * tf, gpointer unused)
1799 #define MULTIPART_MAX_BOUNDARY_OFFSET 16
1800 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_BOUNDARY_OFFSET);
1805 x - data < MULTIPART_MAX_BOUNDARY_OFFSET - 2 && g_ascii_isspace (*x);
1807 if (x[0] != '-' || x[1] != '-')
1810 /* Could be okay, peek what should be enough for a complete header */
1811 #define MULTIPART_MAX_HEADER_SIZE 256
1812 data = gst_type_find_peek (tf, 0, MULTIPART_MAX_HEADER_SIZE);
1816 for (x = data; x - data < MULTIPART_MAX_HEADER_SIZE - 14; x++) {
1817 if (!isascii (*x)) {
1821 !g_ascii_strncasecmp ("content-type:", (gchar *) x + 1, 13)) {
1822 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MULTIPART_CAPS);
1828 /*** video/mpeg systemstream ***/
1829 static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, "
1830 "systemstream = (boolean) true, mpegversion = (int) [ 1, 2 ]");
1832 #define MPEG_SYS_CAPS gst_static_caps_get(&mpeg_sys_caps)
1833 #define IS_MPEG_HEADER(data) (G_UNLIKELY((((guint8 *)(data))[0] == 0x00) && \
1834 (((guint8 *)(data))[1] == 0x00) && \
1835 (((guint8 *)(data))[2] == 0x01)))
1837 #define IS_MPEG_PACK_CODE(b) ((b) == 0xBA)
1838 #define IS_MPEG_SYS_CODE(b) ((b) == 0xBB)
1839 #define IS_MPEG_PACK_HEADER(data) (IS_MPEG_HEADER (data) && \
1840 IS_MPEG_PACK_CODE (((guint8 *)(data))[3]))
1842 #define IS_MPEG_PES_CODE(b) (((b) & 0xF0) == 0xE0 || ((b) & 0xF0) == 0xC0 || \
1844 #define IS_MPEG_PES_HEADER(data) (IS_MPEG_HEADER (data) && \
1845 IS_MPEG_PES_CODE (((guint8 *)(data))[3]))
1847 #define MPEG2_MAX_PROBE_LENGTH (128 * 1024) /* 128kB should be 64 packs of the
1848 * most common 2kB pack size. */
1850 #define MPEG2_MIN_SYS_HEADERS 2
1851 #define MPEG2_MAX_SYS_HEADERS 5
1854 mpeg_sys_is_valid_pack (GstTypeFind * tf, const guint8 * data, guint len,
1857 /* Check the pack header @ offset for validity, assuming that the 4 byte header
1858 * itself has already been checked. */
1864 /* Check marker bits */
1865 if ((data[4] & 0xC4) == 0x44) {
1870 if ((data[6] & 0x04) != 0x04 ||
1871 (data[8] & 0x04) != 0x04 ||
1872 (data[9] & 0x01) != 0x01 || (data[12] & 0x03) != 0x03)
1875 stuff_len = data[13] & 0x07;
1877 /* Check the following header bytes, if we can */
1878 if ((14 + stuff_len + 4) <= len) {
1879 if (!IS_MPEG_HEADER (data + 14 + stuff_len))
1883 *pack_size = 14 + stuff_len;
1885 } else if ((data[4] & 0xF1) == 0x21) {
1887 if ((data[6] & 0x01) != 0x01 ||
1888 (data[8] & 0x01) != 0x01 ||
1889 (data[9] & 0x80) != 0x80 || (data[11] & 0x01) != 0x01)
1892 /* Check the following header bytes, if we can */
1893 if ((12 + 4) <= len) {
1894 if (!IS_MPEG_HEADER (data + 12))
1906 mpeg_sys_is_valid_pes (GstTypeFind * tf, const guint8 * data, guint len,
1909 guint pes_packet_len;
1911 /* Check the PES header at the given position, assuming the header code itself
1912 * was already checked */
1916 /* For MPEG Program streams, unbounded PES is not allowed, so we must have a
1917 * valid length present */
1918 pes_packet_len = GST_READ_UINT16_BE (data + 4);
1919 if (pes_packet_len == 0)
1922 /* Check the following header, if we can */
1923 if (6 + pes_packet_len + 4 <= len) {
1924 if (!IS_MPEG_HEADER (data + 6 + pes_packet_len))
1929 *pack_size = 6 + pes_packet_len;
1934 mpeg_sys_is_valid_sys (GstTypeFind * tf, const guint8 * data, guint len,
1939 /* Check the System header at the given position, assuming the header code itself
1940 * was already checked */
1943 sys_hdr_len = GST_READ_UINT16_BE (data + 4);
1944 if (sys_hdr_len < 6)
1947 /* Check the following header, if we can */
1948 if (6 + sys_hdr_len + 4 <= len) {
1949 if (!IS_MPEG_HEADER (data + 6 + sys_hdr_len))
1954 *pack_size = 6 + sys_hdr_len;
1959 /* calculation of possibility to identify random data as mpeg systemstream:
1960 * bits that must match in header detection: 32 (or more)
1961 * chance that random data is identifed: 1/2^32
1962 * chance that MPEG2_MIN_PACK_HEADERS headers are identified:
1963 * 1/2^(32*MPEG2_MIN_PACK_HEADERS)
1964 * chance that this happens in MPEG2_MAX_PROBE_LENGTH bytes:
1965 * 1-(1+1/2^(32*MPEG2_MIN_PACK_HEADERS)^MPEG2_MAX_PROBE_LENGTH)
1966 * for current values:
1967 * 1-(1+1/2^(32*4)^101024)
1969 * Since we also check marker bits and pes packet lengths, this probability is a
1970 * very coarse upper bound.
1973 mpeg_sys_type_find (GstTypeFind * tf, gpointer unused)
1975 const guint8 *data, *data0, *first_sync, *end;
1976 gint mpegversion = 0;
1977 guint pack_headers = 0;
1978 guint pes_headers = 0;
1980 guint since_last_sync = 0;
1981 guint32 sync_word = 0xffffffff;
1986 len = MPEG2_MAX_PROBE_LENGTH;
1989 data = gst_type_find_peek (tf, 0, 5 + len);
1990 } while (data == NULL && len >= 32);
2002 while (data < end) {
2004 if (sync_word == 0x00000100) {
2005 /* Found potential sync word */
2006 if (first_sync == NULL)
2007 first_sync = data - 3;
2009 if (since_last_sync > 4) {
2010 /* If more than 4 bytes since the last sync word, reset our counters,
2011 * as we're only interested in counting contiguous packets */
2012 pes_headers = pack_headers = 0;
2016 if (IS_MPEG_PACK_CODE (data[0])) {
2017 if ((data[1] & 0xC0) == 0x40) {
2020 } else if ((data[1] & 0xF0) == 0x20) {
2023 if (mpegversion != 0 &&
2024 mpeg_sys_is_valid_pack (tf, data - 3, end - data + 3, &pack_size)) {
2027 } else if (IS_MPEG_PES_CODE (data[0])) {
2029 if (mpeg_sys_is_valid_pes (tf, data - 3, end - data + 3, &pack_size)) {
2031 if (mpegversion == 0)
2034 } else if (IS_MPEG_SYS_CODE (data[0])) {
2035 if (mpeg_sys_is_valid_sys (tf, data - 3, end - data + 3, &pack_size)) {
2040 /* If we found a packet with a known size, skip the bytes in it and loop
2041 * around to check the next packet. */
2042 if (pack_size != 0) {
2043 data += pack_size - 3;
2044 sync_word = 0xffffffff;
2045 since_last_sync = 0;
2050 sync_word |= data[0];
2054 /* If we have found MAX headers, and *some* were pes headers (pack headers
2055 * are optional in an mpeg system stream) then return our high-probability
2057 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MAX_SYS_HEADERS)
2061 /* If we at least saw MIN headers, and *some* were pes headers (pack headers
2062 * are optional in an mpeg system stream) then return a lower-probability
2064 if (pes_headers > 0 && (pack_headers + pes_headers) > MPEG2_MIN_SYS_HEADERS)
2072 prob = GST_TYPE_FIND_POSSIBLE + (10 * (pack_headers + pes_headers));
2073 prob = MIN (prob, GST_TYPE_FIND_MAXIMUM);
2075 /* lower probability if the first packet wasn't right at the start */
2076 if (data0 != first_sync && prob >= 10)
2079 GST_LOG ("Suggesting MPEG %d system stream, %d packs, %d pes, prob %u%%\n",
2080 mpegversion, pack_headers, pes_headers, prob);
2082 gst_type_find_suggest_simple (tf, prob, "video/mpeg",
2083 "systemstream", G_TYPE_BOOLEAN, TRUE,
2084 "mpegversion", G_TYPE_INT, mpegversion, NULL);
2088 /*** video/mpegts Transport Stream ***/
2089 static GstStaticCaps mpegts_caps = GST_STATIC_CAPS ("video/mpegts, "
2090 "systemstream = (boolean) true, packetsize = (int) [ 188, 208 ]");
2091 #define MPEGTS_CAPS gst_static_caps_get(&mpegts_caps)
2093 #define GST_MPEGTS_TYPEFIND_MIN_HEADERS 4
2094 #define GST_MPEGTS_TYPEFIND_MAX_HEADERS 10
2095 #define GST_MPEGTS_MAX_PACKET_SIZE 208
2096 #define GST_MPEGTS_TYPEFIND_SYNC_SIZE \
2097 (GST_MPEGTS_TYPEFIND_MIN_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
2098 #define GST_MPEGTS_TYPEFIND_MAX_SYNC \
2099 (GST_MPEGTS_TYPEFIND_MAX_HEADERS * GST_MPEGTS_MAX_PACKET_SIZE)
2100 #define GST_MPEGTS_TYPEFIND_SCAN_LENGTH \
2101 (GST_MPEGTS_TYPEFIND_MAX_SYNC * 4)
2103 #define MPEGTS_HDR_SIZE 4
2104 /* Check for sync byte, error_indicator == 0 and packet has payload */
2105 #define IS_MPEGTS_HEADER(data) (((data)[0] == 0x47) && \
2106 (((data)[1] & 0x80) == 0x00) && \
2107 (((data)[3] & 0x30) != 0x00))
2109 /* Helper function to search ahead at intervals of packet_size for mpegts
2112 mpeg_ts_probe_headers (GstTypeFind * tf, guint64 offset, gint packet_size)
2114 /* We always enter this function having found at least one header already */
2116 const guint8 *data = NULL;
2118 GST_LOG ("looking for mpeg-ts packets of size %u", packet_size);
2119 while (found < GST_MPEGTS_TYPEFIND_MAX_HEADERS) {
2120 offset += packet_size;
2122 data = gst_type_find_peek (tf, offset, MPEGTS_HDR_SIZE);
2123 if (data == NULL || !IS_MPEGTS_HEADER (data))
2127 GST_LOG ("mpeg-ts sync #%2d at offset %" G_GUINT64_FORMAT, found, offset);
2133 /* Try and detect at least 4 packets in at most 10 packets worth of
2134 * data. Need to try several possible packet sizes */
2136 mpeg_ts_type_find (GstTypeFind * tf, gpointer unused)
2138 /* TS packet sizes to test: normal, DVHS packet size and
2139 * FEC with 16 or 20 byte codes packet size. */
2140 const gint pack_sizes[] = { 188, 192, 204, 208 };
2141 const guint8 *data = NULL;
2143 guint64 skipped = 0;
2145 while (skipped < GST_MPEGTS_TYPEFIND_SCAN_LENGTH) {
2146 if (size < MPEGTS_HDR_SIZE) {
2147 data = gst_type_find_peek (tf, skipped, GST_MPEGTS_TYPEFIND_SYNC_SIZE);
2150 size = GST_MPEGTS_TYPEFIND_SYNC_SIZE;
2153 /* Have at least MPEGTS_HDR_SIZE bytes at this point */
2154 if (IS_MPEGTS_HEADER (data)) {
2157 GST_LOG ("possible mpeg-ts sync at offset %" G_GUINT64_FORMAT, skipped);
2159 for (p = 0; p < G_N_ELEMENTS (pack_sizes); p++) {
2162 /* Probe ahead at size pack_sizes[p] */
2163 found = mpeg_ts_probe_headers (tf, skipped, pack_sizes[p]);
2164 if (found >= GST_MPEGTS_TYPEFIND_MIN_HEADERS) {
2167 /* found at least 4 headers. 10 headers = MAXIMUM probability.
2168 * Arbitrarily, I assigned 10% probability for each header we
2169 * found, 40% -> 100% */
2170 probability = MIN (10 * found, GST_TYPE_FIND_MAXIMUM);
2172 gst_type_find_suggest_simple (tf, probability, "video/mpegts",
2173 "systemstream", G_TYPE_BOOLEAN, TRUE,
2174 "packetsize", G_TYPE_INT, pack_sizes[p], NULL);
2185 #define GST_MPEGVID_TYPEFIND_TRY_PICTURES 6
2186 #define GST_MPEGVID_TYPEFIND_TRY_SYNC (100 * 1024) /* 100 kB */
2188 /* Scan ahead a maximum of max_extra_offset bytes until the next IS_MPEG_HEADER
2189 * offset. After the call, offset will be after the 0x000001, i.e. at the 4th
2190 * byte of the MPEG header. Returns TRUE if a header was found, FALSE if not.
2193 mpeg_find_next_header (GstTypeFind * tf, DataScanCtx * c,
2194 guint64 max_extra_offset)
2196 guint64 extra_offset;
2198 for (extra_offset = 0; extra_offset <= max_extra_offset; ++extra_offset) {
2199 if (!data_scan_ctx_ensure_data (tf, c, 4))
2201 if (IS_MPEG_HEADER (c->data)) {
2202 data_scan_ctx_advance (tf, c, 3);
2205 data_scan_ctx_advance (tf, c, 1);
2210 /*** video/mpeg MPEG-4 elementary video stream ***/
2212 static GstStaticCaps mpeg4_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2213 "systemstream=(boolean)false, mpegversion=4, parsed=(boolean)false");
2214 #define MPEG4_VIDEO_CAPS gst_static_caps_get(&mpeg4_video_caps)
2217 * This typefind is based on the elementary video header defined in
2218 * http://xhelmboyx.tripod.com/formats/mpeg-layout.txt
2219 * In addition, it allows the visual object sequence header to be
2220 * absent, and even the VOS header to be absent. In the latter case,
2221 * a number of VOPs have to be present.
2224 mpeg4_video_type_find (GstTypeFind * tf, gpointer unused)
2226 DataScanCtx c = { 0, NULL, 0 };
2227 gboolean seen_vios_at_0 = FALSE;
2228 gboolean seen_vios = FALSE;
2229 gboolean seen_vos = FALSE;
2230 gboolean seen_vol = FALSE;
2231 guint num_vop_headers = 0;
2234 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2235 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2238 if (!mpeg_find_next_header (tf, &c,
2239 GST_MPEGVID_TYPEFIND_TRY_SYNC - c.offset))
2244 /* visual_object_sequence_start_code */
2247 break; /* Terminate at second vios */
2249 seen_vios_at_0 = TRUE;
2251 data_scan_ctx_advance (tf, &c, 2);
2252 if (!mpeg_find_next_header (tf, &c, 0))
2257 /* Optional metadata */
2259 if (!mpeg_find_next_header (tf, &c, 24))
2263 /* visual_object_start_code (consider it optional) */
2265 data_scan_ctx_advance (tf, &c, 2);
2266 /* may contain ID marker and YUV clamping */
2267 if (!mpeg_find_next_header (tf, &c, 7))
2273 /* video_object_start_code */
2276 break; /* Terminate at second vos */
2278 data_scan_ctx_advance (tf, &c, 2);
2282 /* video_object_layer_start_code */
2283 if (sc >= 0x20 && sc <= 0x2F) {
2285 data_scan_ctx_advance (tf, &c, 5);
2289 /* video_object_plane_start_code */
2292 data_scan_ctx_advance (tf, &c, 2);
2296 /* Unknown start code. */
2299 if (num_vop_headers > 0 || seen_vol) {
2300 GstTypeFindProbability probability = 0;
2302 GST_LOG ("Found %d pictures, vios: %d, vos:%d, vol:%d", num_vop_headers,
2303 seen_vios, seen_vos, seen_vol);
2305 if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios_at_0
2306 && seen_vos && seen_vol)
2307 probability = GST_TYPE_FIND_MAXIMUM - 1;
2308 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vios
2309 && seen_vos && seen_vol)
2310 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2311 else if (seen_vios_at_0 && seen_vos && seen_vol)
2312 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2313 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vos
2315 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 6;
2316 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_vol)
2317 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2318 else if (num_vop_headers >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2319 probability = GST_TYPE_FIND_LIKELY - 1;
2320 else if (num_vop_headers > 2 && seen_vios && seen_vos && seen_vol)
2321 probability = GST_TYPE_FIND_LIKELY - 9;
2322 else if (seen_vios && seen_vos && seen_vol)
2323 probability = GST_TYPE_FIND_LIKELY - 20;
2324 else if (num_vop_headers > 0 && seen_vos && seen_vol)
2325 probability = GST_TYPE_FIND_POSSIBLE;
2326 else if (num_vop_headers > 0)
2327 probability = GST_TYPE_FIND_POSSIBLE - 10;
2328 else if (seen_vos && seen_vol)
2329 probability = GST_TYPE_FIND_POSSIBLE - 20;
2331 gst_type_find_suggest (tf, probability, MPEG4_VIDEO_CAPS);
2335 /*** video/x-h263 H263 video stream ***/
2336 static GstStaticCaps h263_video_caps = GST_STATIC_CAPS ("video/x-h263");
2338 #define H263_VIDEO_CAPS gst_static_caps_get(&h263_video_caps)
2340 #define H263_MAX_PROBE_LENGTH (128 * 1024)
2343 h263_video_type_find (GstTypeFind * tf, gpointer unused)
2345 DataScanCtx c = { 0, NULL, 0 };
2353 while (c.offset < H263_MAX_PROBE_LENGTH) {
2354 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
2357 /* Find the picture start code */
2358 data = (data << 8) + c.data[0];
2359 psc = data & G_GUINT64_CONSTANT (0xfffffc0000);
2360 if (psc == 0x800000) {
2363 tr = (data & 0x3fc) >> 2;
2367 /* Now that we have a Valid PSC, check if we also have a valid PTYPE and
2368 the Source Format, which should range between 1 and 5 */
2369 if (((tr >> 6) == 0x2) && (format > 0 && format < 6))
2374 /* FIXME: maybe bail out early if we get mostly bad syncs ? */
2377 data_scan_ctx_advance (tf, &c, 1);
2380 if (good > 0 && bad == 0)
2381 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H263_VIDEO_CAPS);
2382 else if (good > 2 * bad)
2383 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H263_VIDEO_CAPS);
2388 /*** video/x-h264 H264 elementary video stream ***/
2390 static GstStaticCaps h264_video_caps =
2391 GST_STATIC_CAPS ("video/x-h264,stream-format=byte-stream");
2393 #define H264_VIDEO_CAPS gst_static_caps_get(&h264_video_caps)
2395 #define H264_MAX_PROBE_LENGTH (128 * 1024) /* 128kB for HD should be enough. */
2398 h264_video_type_find (GstTypeFind * tf, gpointer unused)
2400 DataScanCtx c = { 0, NULL, 0 };
2402 /* Stream consists of: a series of sync codes (00 00 00 01) followed
2409 while (c.offset < H264_MAX_PROBE_LENGTH) {
2410 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4)))
2413 if (IS_MPEG_HEADER (c.data)) {
2414 nut = c.data[3] & 0x9f; /* forbiden_zero_bit | nal_unit_type */
2415 ref = c.data[3] & 0x60; /* nal_ref_idc */
2417 /* if forbidden bit is different to 0 won't be h264 */
2423 /* collect statistics about the NAL types */
2424 if ((nut >= 1 && nut <= 13) || nut == 19) {
2425 if ((nut == 5 && ref == 0) ||
2426 ((nut == 6 || (nut >= 9 && nut <= 12)) && ref != 0)) {
2431 } else if (nut >= 14 && nut <= 33) {
2433 /* Theoretically these are good, since if they exist in the
2434 stream it merely means that a newer backwards-compatible
2435 h.264 stream. But we should be identifying that separately. */
2438 /* unspecified, application specific */
2439 /* don't consider these bad */
2442 GST_DEBUG ("good %d bad %d", good, bad);
2444 if (good >= 10 && bad < 4) {
2445 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, H264_VIDEO_CAPS);
2449 data_scan_ctx_advance (tf, &c, 4);
2451 data_scan_ctx_advance (tf, &c, 1);
2454 if (good >= 2 && bad < 1) {
2455 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, H264_VIDEO_CAPS);
2460 /*** video/mpeg video stream ***/
2462 static GstStaticCaps mpeg_video_caps = GST_STATIC_CAPS ("video/mpeg, "
2463 "systemstream = (boolean) false");
2464 #define MPEG_VIDEO_CAPS gst_static_caps_get(&mpeg_video_caps)
2467 * Idea is the same as MPEG system stream typefinding: We check each
2468 * byte of the stream to see if - from that point on - the stream
2469 * matches a predefined set of marker bits as defined in the MPEG
2472 * I'm sure someone will do a chance calculation here too.
2476 mpeg_video_stream_type_find (GstTypeFind * tf, gpointer unused)
2478 DataScanCtx c = { 0, NULL, 0 };
2479 gboolean seen_seq_at_0 = FALSE;
2480 gboolean seen_seq = FALSE;
2481 gboolean seen_gop = FALSE;
2482 guint64 last_pic_offset = 0;
2483 guint num_pic_headers = 0;
2486 while (c.offset < GST_MPEGVID_TYPEFIND_TRY_SYNC) {
2487 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2490 if (!data_scan_ctx_ensure_data (tf, &c, 5))
2493 if (!IS_MPEG_HEADER (c.data))
2496 /* a pack header indicates that this isn't an elementary stream */
2497 if (c.data[3] == 0xBA && mpeg_sys_is_valid_pack (tf, c.data, c.size, NULL))
2500 /* do we have a sequence header? */
2501 if (c.data[3] == 0xB3) {
2502 seen_seq_at_0 = seen_seq_at_0 || (c.offset == 0);
2504 data_scan_ctx_advance (tf, &c, 4 + 8);
2508 /* or a GOP header */
2509 if (c.data[3] == 0xB8) {
2511 data_scan_ctx_advance (tf, &c, 8);
2515 /* but what we'd really like to see is a picture header */
2516 if (c.data[3] == 0x00) {
2518 last_pic_offset = c.offset;
2519 data_scan_ctx_advance (tf, &c, 8);
2523 /* ... each followed by a slice header with slice_vertical_pos=1 that's
2524 * not too far away from the previously seen picture header. */
2525 if (c.data[3] == 0x01 && num_pic_headers > found &&
2526 (c.offset - last_pic_offset) >= 4 &&
2527 (c.offset - last_pic_offset) <= 64) {
2528 data_scan_ctx_advance (tf, &c, 4);
2535 data_scan_ctx_advance (tf, &c, 1);
2538 if (found > 0 || seen_seq) {
2539 GstTypeFindProbability probability = 0;
2541 GST_LOG ("Found %d pictures, seq:%d, gop:%d", found, seen_seq, seen_gop);
2543 if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq && seen_gop)
2544 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 1;
2545 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES && seen_seq)
2546 probability = GST_TYPE_FIND_NEARLY_CERTAIN - 9;
2547 else if (found >= GST_MPEGVID_TYPEFIND_TRY_PICTURES)
2548 probability = GST_TYPE_FIND_LIKELY;
2549 else if (seen_seq_at_0 && seen_gop && found > 2)
2550 probability = GST_TYPE_FIND_LIKELY - 10;
2551 else if (seen_seq && seen_gop && found > 2)
2552 probability = GST_TYPE_FIND_LIKELY - 20;
2553 else if (seen_seq_at_0 && found > 0)
2554 probability = GST_TYPE_FIND_POSSIBLE;
2555 else if (seen_seq && found > 0)
2556 probability = GST_TYPE_FIND_POSSIBLE - 5;
2558 probability = GST_TYPE_FIND_POSSIBLE - 10;
2560 probability = GST_TYPE_FIND_POSSIBLE - 20;
2562 gst_type_find_suggest_simple (tf, probability, "video/mpeg",
2563 "systemstream", G_TYPE_BOOLEAN, FALSE,
2564 "mpegversion", G_TYPE_INT, 1, NULL);
2568 /*** audio/x-aiff ***/
2570 static GstStaticCaps aiff_caps = GST_STATIC_CAPS ("audio/x-aiff");
2572 #define AIFF_CAPS gst_static_caps_get(&aiff_caps)
2574 aiff_type_find (GstTypeFind * tf, gpointer unused)
2576 const guint8 *data = gst_type_find_peek (tf, 0, 4);
2578 if (data && memcmp (data, "FORM", 4) == 0) {
2580 if (memcmp (data, "AIFF", 4) == 0 || memcmp (data, "AIFC", 4) == 0)
2581 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AIFF_CAPS);
2585 /*** audio/x-svx ***/
2587 static GstStaticCaps svx_caps = GST_STATIC_CAPS ("audio/x-svx");
2589 #define SVX_CAPS gst_static_caps_get(&svx_caps)
2591 svx_type_find (GstTypeFind * tf, gpointer unused)
2593 const guint8 *data = gst_type_find_peek (tf, 0, 4);
2595 if (data && memcmp (data, "FORM", 4) == 0) {
2597 if (memcmp (data, "8SVX", 4) == 0 || memcmp (data, "16SV", 4) == 0)
2598 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SVX_CAPS);
2602 /*** audio/x-shorten ***/
2604 static GstStaticCaps shn_caps = GST_STATIC_CAPS ("audio/x-shorten");
2606 #define SHN_CAPS gst_static_caps_get(&shn_caps)
2608 shn_type_find (GstTypeFind * tf, gpointer unused)
2610 const guint8 *data = gst_type_find_peek (tf, 0, 4);
2612 if (data && memcmp (data, "ajkg", 4) == 0) {
2613 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2615 data = gst_type_find_peek (tf, -8, 8);
2616 if (data && memcmp (data, "SHNAMPSK", 8) == 0) {
2617 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SHN_CAPS);
2621 /*** application/x-ape ***/
2623 static GstStaticCaps ape_caps = GST_STATIC_CAPS ("application/x-ape");
2625 #define APE_CAPS gst_static_caps_get(&ape_caps)
2627 ape_type_find (GstTypeFind * tf, gpointer unused)
2629 const guint8 *data = gst_type_find_peek (tf, 0, 4);
2631 if (data && memcmp (data, "MAC ", 4) == 0) {
2632 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY + 10, APE_CAPS);
2636 /*** ISO FORMATS ***/
2638 /*** audio/x-m4a ***/
2640 static GstStaticCaps m4a_caps = GST_STATIC_CAPS ("audio/x-m4a");
2642 #define M4A_CAPS (gst_static_caps_get(&m4a_caps))
2644 m4a_type_find (GstTypeFind * tf, gpointer unused)
2646 const guint8 *data = gst_type_find_peek (tf, 4, 8);
2648 if (data && (memcmp (data, "ftypM4A ", 8) == 0)) {
2649 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
2653 /*** application/x-3gp ***/
2655 /* The Q is there because variables can't start with a number. */
2656 static GstStaticCaps q3gp_caps = GST_STATIC_CAPS ("application/x-3gp");
2657 #define Q3GP_CAPS (gst_static_caps_get(&q3gp_caps))
2659 static const gchar *
2660 q3gp_type_find_get_profile (const guint8 * data)
2662 switch (GST_MAKE_FOURCC (data[0], data[1], data[2], 0)) {
2663 case GST_MAKE_FOURCC ('3', 'g', 'g', 0):
2665 case GST_MAKE_FOURCC ('3', 'g', 'p', 0):
2667 case GST_MAKE_FOURCC ('3', 'g', 's', 0):
2668 return "streaming-server";
2669 case GST_MAKE_FOURCC ('3', 'g', 'r', 0):
2670 return "progressive-download";
2678 q3gp_type_find (GstTypeFind * tf, gpointer unused)
2680 const gchar *profile;
2681 guint32 ftyp_size = 0;
2683 const guint8 *data = NULL;
2685 if ((data = gst_type_find_peek (tf, 0, 12)) == NULL) {
2690 if (memcmp (data, "ftyp", 4) != 0) {
2694 /* check major brand */
2696 if ((profile = q3gp_type_find_get_profile (data))) {
2697 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
2698 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
2702 /* check compatible brands */
2703 if ((data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2704 ftyp_size = GST_READ_UINT32_BE (data);
2706 for (offset = 16; offset < ftyp_size; offset += 4) {
2707 if ((data = gst_type_find_peek (tf, offset, 3)) == NULL) {
2710 if ((profile = q3gp_type_find_get_profile (data))) {
2711 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
2712 "application/x-3gp", "profile", G_TYPE_STRING, profile, NULL);
2721 /*** video/mj2 and image/jp2 ***/
2722 static GstStaticCaps mj2_caps = GST_STATIC_CAPS ("video/mj2");
2724 #define MJ2_CAPS gst_static_caps_get(&mj2_caps)
2726 static GstStaticCaps jp2_caps = GST_STATIC_CAPS ("image/jp2");
2728 #define JP2_CAPS gst_static_caps_get(&jp2_caps)
2731 jp2_type_find (GstTypeFind * tf, gpointer unused)
2735 data = gst_type_find_peek (tf, 0, 24);
2740 if (memcmp (data, "\000\000\000\014jP \015\012\207\012", 12) != 0)
2743 /* check ftyp box */
2745 if (memcmp (data + 4, "ftyp", 4) == 0) {
2746 if (memcmp (data + 8, "jp2 ", 4) == 0)
2747 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, JP2_CAPS);
2748 else if (memcmp (data + 8, "mjp2", 4) == 0)
2749 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MJ2_CAPS);
2753 /*** video/quicktime ***/
2755 static GstStaticCaps qt_caps = GST_STATIC_CAPS ("video/quicktime");
2757 #define QT_CAPS gst_static_caps_get(&qt_caps)
2758 #define STRNCMP(x,y,z) (strncmp ((char*)(x), (char*)(y), z))
2760 /* FIXME 0.11: go through http://www.ftyps.com/ */
2762 qt_type_find (GstTypeFind * tf, gpointer unused)
2768 const gchar *variant = NULL;
2770 while ((data = gst_type_find_peek (tf, offset, 12)) != NULL) {
2773 if (STRNCMP (&data[4], "ftypqt ", 8) == 0) {
2774 tip = GST_TYPE_FIND_MAXIMUM;
2778 if (STRNCMP (&data[4], "ftypisom", 8) == 0 ||
2779 STRNCMP (&data[4], "ftypavc1", 8) == 0 ||
2780 STRNCMP (&data[4], "ftypmp42", 8) == 0) {
2781 tip = GST_TYPE_FIND_MAXIMUM;
2786 /* box/atom types that are in common with ISO base media file format */
2787 if (STRNCMP (&data[4], "moov", 4) == 0 ||
2788 STRNCMP (&data[4], "mdat", 4) == 0 ||
2789 STRNCMP (&data[4], "ftyp", 4) == 0 ||
2790 STRNCMP (&data[4], "free", 4) == 0 ||
2791 STRNCMP (&data[4], "uuid", 4) == 0 ||
2792 STRNCMP (&data[4], "skip", 4) == 0) {
2794 tip = GST_TYPE_FIND_LIKELY;
2796 tip = GST_TYPE_FIND_NEARLY_CERTAIN;
2799 /* other box/atom types, apparently quicktime specific */
2800 else if (STRNCMP (&data[4], "pnot", 4) == 0 ||
2801 STRNCMP (&data[4], "PICT", 4) == 0 ||
2802 STRNCMP (&data[4], "wide", 4) == 0 ||
2803 STRNCMP (&data[4], "prfl", 4) == 0) {
2804 tip = GST_TYPE_FIND_MAXIMUM;
2811 size = GST_READ_UINT32_BE (data);
2812 /* check compatible brands rather than ever expaning major brands above */
2813 if ((STRNCMP (&data[4], "ftyp", 4) == 0) && (size >= 16)) {
2814 new_offset = offset + 12;
2815 while (new_offset + 4 <= offset + size) {
2816 data = gst_type_find_peek (tf, new_offset, 4);
2819 if (STRNCMP (&data[4], "isom", 4) == 0 ||
2820 STRNCMP (&data[4], "avc1", 4) == 0 ||
2821 STRNCMP (&data[4], "mp41", 4) == 0 ||
2822 STRNCMP (&data[4], "mp42", 4) == 0) {
2823 tip = GST_TYPE_FIND_MAXIMUM;
2831 const guint8 *sizedata;
2833 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2834 if (sizedata == NULL)
2837 size = GST_READ_UINT64_BE (sizedata);
2842 new_offset = offset + size;
2843 if (new_offset <= offset)
2845 offset = new_offset;
2851 GstCaps *caps = gst_caps_copy (QT_CAPS);
2853 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, variant, NULL);
2854 gst_type_find_suggest (tf, tip, caps);
2855 gst_caps_unref (caps);
2857 gst_type_find_suggest (tf, tip, QT_CAPS);
2863 /*** image/x-quicktime ***/
2865 static GstStaticCaps qtif_caps = GST_STATIC_CAPS ("image/x-quicktime");
2867 #define QTIF_CAPS gst_static_caps_get(&qtif_caps)
2869 /* how many atoms we check before we give up */
2870 #define QTIF_MAXROUNDS 25
2873 qtif_type_find (GstTypeFind * tf, gpointer unused)
2876 gboolean found_idsc = FALSE;
2877 gboolean found_idat = FALSE;
2881 while ((data = gst_type_find_peek (tf, offset, 8)) != NULL) {
2884 size = GST_READ_UINT32_BE (data);
2886 const guint8 *sizedata;
2888 sizedata = gst_type_find_peek (tf, offset + 8, 8);
2889 if (sizedata == NULL)
2892 size = GST_READ_UINT64_BE (sizedata);
2897 if (STRNCMP (data + 4, "idsc", 4) == 0)
2899 if (STRNCMP (data + 4, "idat", 4) == 0)
2902 if (found_idsc && found_idat) {
2903 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, QTIF_CAPS);
2908 if (++rounds > QTIF_MAXROUNDS)
2912 if (found_idsc || found_idat) {
2913 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, QTIF_CAPS);
2918 /*** audio/x-mod ***/
2920 static GstStaticCaps mod_caps = GST_STATIC_CAPS ("audio/x-mod");
2922 #define MOD_CAPS gst_static_caps_get(&mod_caps)
2923 /* FIXME: M15 CheckType to do */
2925 mod_type_find (GstTypeFind * tf, gpointer unused)
2930 if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) {
2931 /* Protracker and variants */
2932 if ((memcmp (data, "M.K.", 4) == 0) || (memcmp (data, "M!K!", 4) == 0) ||
2934 (memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) ||
2935 (memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) ||
2936 /* Oktalyzer (Amiga) */
2937 (memcmp (data, "OKTA", 4) == 0) ||
2938 /* Oktalyser (Atari) */
2939 (memcmp (data, "CD81", 4) == 0) ||
2941 (memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) ||
2942 /* Fasttracker or Taketracker */
2943 (memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0])
2944 && isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0
2945 && isdigit (data[0]) && isdigit (data[1]))) {
2946 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2951 if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) {
2952 if (memcmp (data, "Extended Module: ", 17) == 0 && data[37] == 0x1A) {
2953 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2958 if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) {
2959 if (memcmp (data, "OKTASONG", 8) == 0) {
2960 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2964 if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) {
2966 if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) {
2967 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
2971 if ((memcmp (data, "AMF", 3) == 0 && data[3] > 10 && data[3] < 14) ||
2973 (memcmp (data, "IMPM", 4) == 0) ||
2975 (memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0) ||
2977 (memcmp (data, "MTM", 3) == 0)) {
2978 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2982 if (memcmp (data, "RIFF", 4) == 0) {
2983 const guint8 *data2 = gst_type_find_peek (tf, 8, 4);
2986 if (memcmp (data2, "DSMF", 4) == 0) {
2987 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
2993 if (memcmp (data, "FAM\xFE", 4) == 0) {
2994 const guint8 *data2 = gst_type_find_peek (tf, 44, 3);
2997 if (memcmp (data2, "compare", 3) == 0) {
2998 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3002 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
3007 if (memcmp (data, "GDM\xFE", 4) == 0) {
3008 const guint8 *data2 = gst_type_find_peek (tf, 71, 4);
3011 if (memcmp (data2, "GMFS", 4) == 0) {
3012 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3016 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS);
3022 if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) {
3023 if (memcmp (data, "IM10", 4) == 0) {
3024 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3029 if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) {
3030 if (memcmp (data, "SCRM", 4) == 0) {
3031 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3036 if ((data = gst_type_find_peek (tf, 20, 8)) != NULL) {
3037 if (g_ascii_strncasecmp ((gchar *) data, "!Scream!", 8) == 0 ||
3038 g_ascii_strncasecmp ((gchar *) data, "BMOD2STM", 8) == 0) {
3039 const guint8 *id, *stmtype;
3041 if ((id = gst_type_find_peek (tf, 28, 1)) == NULL)
3043 if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL)
3045 if (*id == 0x1A && *stmtype == 2)
3046 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3051 if ((data = gst_type_find_peek (tf, 0, 19)) != NULL) {
3052 if (memcmp (data, "ASYLUM Music Format", 19) == 0) {
3053 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS);
3059 /*** application/x-shockwave-flash ***/
3061 static GstStaticCaps swf_caps =
3062 GST_STATIC_CAPS ("application/x-shockwave-flash");
3063 #define SWF_CAPS (gst_static_caps_get(&swf_caps))
3065 swf_type_find (GstTypeFind * tf, gpointer unused)
3067 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3069 if (data && (data[0] == 'F' || data[0] == 'C') &&
3070 data[1] == 'W' && data[2] == 'S') {
3071 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SWF_CAPS);
3075 /*** image/jpeg ***/
3077 #define JPEG_MARKER_IS_START_OF_FRAME(x) \
3078 ((x)>=0xc0 && (x) <= 0xcf && (x)!=0xc4 && (x)!=0xc8 && (x)!=0xcc)
3080 static GstStaticCaps jpeg_caps = GST_STATIC_CAPS ("image/jpeg");
3082 #define JPEG_CAPS (gst_static_caps_get(&jpeg_caps))
3084 jpeg_type_find (GstTypeFind * tf, gpointer unused)
3086 GstTypeFindProbability prob = GST_TYPE_FIND_POSSIBLE;
3087 DataScanCtx c = { 0, NULL, 0 };
3091 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 2)))
3094 if (c.data[0] != 0xff || c.data[1] != 0xd8)
3098 data_scan_ctx_advance (tf, &c, 2);
3100 caps = gst_caps_copy (JPEG_CAPS);
3102 while (data_scan_ctx_ensure_data (tf, &c, 4) && c.offset < (200 * 1024)) {
3106 if (c.data[0] != 0xff)
3110 if (G_UNLIKELY (marker == 0xff)) {
3111 data_scan_ctx_advance (tf, &c, 1);
3115 data_scan_ctx_advance (tf, &c, 2);
3117 /* we assume all markers we'll see before SOF have a payload length; if
3118 * that's not the case we'll just detect a false sync and bail out, but
3119 * still report POSSIBLE probability */
3120 len = GST_READ_UINT16_BE (c.data);
3122 GST_LOG ("possible JPEG marker 0x%02x (@0x%04x), segment length %u",
3123 marker, (guint) c.offset, len);
3125 if (!data_scan_ctx_ensure_data (tf, &c, len))
3128 if (marker == 0xc4 || /* DEFINE_HUFFMAN_TABLES */
3129 marker == 0xcc || /* DEFINE_ARITHMETIC_CONDITIONING */
3130 marker == 0xdb || /* DEFINE_QUANTIZATION_TABLES */
3131 marker == 0xdd || /* DEFINE_RESTART_INTERVAL */
3132 marker == 0xfe) { /* COMMENT */
3133 data_scan_ctx_advance (tf, &c, len);
3135 } else if (marker == 0xe0 && len >= (2 + 4) && /* APP0 */
3136 data_scan_ctx_memcmp (tf, &c, 2, "JFIF", 4)) {
3137 GST_LOG ("found JFIF tag");
3138 prob = GST_TYPE_FIND_MAXIMUM;
3139 data_scan_ctx_advance (tf, &c, len);
3141 /* we continue until we find a start of frame marker */
3142 } else if (marker == 0xe1 && len >= (2 + 4) && /* APP1 */
3143 data_scan_ctx_memcmp (tf, &c, 2, "Exif", 4)) {
3144 GST_LOG ("found Exif tag");
3145 prob = GST_TYPE_FIND_MAXIMUM;
3146 data_scan_ctx_advance (tf, &c, len);
3148 /* we continue until we find a start of frame marker */
3149 } else if (marker >= 0xe0 && marker <= 0xef) { /* APPn */
3150 data_scan_ctx_advance (tf, &c, len);
3152 } else if (JPEG_MARKER_IS_START_OF_FRAME (marker) && len >= (2 + 8)) {
3155 h = GST_READ_UINT16_BE (c.data + 2 + 1);
3156 w = GST_READ_UINT16_BE (c.data + 2 + 1 + 2);
3157 if (h == 0 || w == 0) {
3158 GST_WARNING ("bad width %u and/or height %u in SOF header", w, h);
3162 GST_LOG ("SOF at offset %" G_GUINT64_FORMAT ", num_markers=%d, "
3163 "WxH=%dx%d", c.offset - 2, num_markers, w, h);
3165 if (num_markers >= 5 || prob == GST_TYPE_FIND_MAXIMUM)
3166 prob = GST_TYPE_FIND_MAXIMUM;
3168 prob = GST_TYPE_FIND_LIKELY;
3170 gst_caps_set_simple (caps, "width", G_TYPE_INT, w,
3171 "height", G_TYPE_INT, h, "sof-marker", G_TYPE_INT, marker & 0xf,
3176 GST_WARNING ("bad length or unexpected JPEG marker 0xff 0x%02x", marker);
3181 gst_type_find_suggest (tf, prob, caps);
3182 gst_caps_unref (caps);
3187 static GstStaticCaps bmp_caps = GST_STATIC_CAPS ("image/bmp");
3189 #define BMP_CAPS (gst_static_caps_get(&bmp_caps))
3191 bmp_type_find (GstTypeFind * tf, gpointer unused)
3193 DataScanCtx c = { 0, NULL, 0 };
3194 guint32 struct_size, w, h, planes, bpp;
3196 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 54)))
3199 if (c.data[0] != 'B' || c.data[1] != 'M')
3202 /* skip marker + size */
3203 data_scan_ctx_advance (tf, &c, 2 + 4);
3205 /* reserved, must be 0 */
3206 if (c.data[0] != 0 || c.data[1] != 0 || c.data[2] != 0 || c.data[3] != 0)
3209 data_scan_ctx_advance (tf, &c, 2 + 2);
3211 /* offset to start of image data in bytes (check for sanity) */
3212 GST_LOG ("offset=%u", GST_READ_UINT32_LE (c.data));
3213 if (GST_READ_UINT32_LE (c.data) > (10 * 1024 * 1024))
3216 struct_size = GST_READ_UINT32_LE (c.data + 4);
3217 GST_LOG ("struct_size=%u", struct_size);
3219 data_scan_ctx_advance (tf, &c, 4 + 4);
3221 if (struct_size == 0x0C) {
3222 w = GST_READ_UINT16_LE (c.data);
3223 h = GST_READ_UINT16_LE (c.data + 2);
3224 planes = GST_READ_UINT16_LE (c.data + 2 + 2);
3225 bpp = GST_READ_UINT16_LE (c.data + 2 + 2 + 2);
3226 } else if (struct_size == 40 || struct_size == 64 || struct_size == 108
3227 || struct_size == 124 || struct_size == 0xF0) {
3228 w = GST_READ_UINT32_LE (c.data);
3229 h = GST_READ_UINT32_LE (c.data + 4);
3230 planes = GST_READ_UINT16_LE (c.data + 4 + 4);
3231 bpp = GST_READ_UINT16_LE (c.data + 4 + 4 + 2);
3236 /* image sizes sanity check */
3237 GST_LOG ("w=%u, h=%u, planes=%u, bpp=%u", w, h, planes, bpp);
3238 if (w == 0 || w > 0xfffff || h == 0 || h > 0xfffff || planes != 1 ||
3239 (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32))
3242 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "image/bmp",
3243 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, "bpp", G_TYPE_INT, bpp,
3247 /*** image/tiff ***/
3248 static GstStaticCaps tiff_caps = GST_STATIC_CAPS ("image/tiff, "
3249 "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }");
3250 #define TIFF_CAPS (gst_static_caps_get(&tiff_caps))
3251 static GstStaticCaps tiff_be_caps = GST_STATIC_CAPS ("image/tiff, "
3252 "endianness = (int) BIG_ENDIAN");
3253 #define TIFF_BE_CAPS (gst_static_caps_get(&tiff_be_caps))
3254 static GstStaticCaps tiff_le_caps = GST_STATIC_CAPS ("image/tiff, "
3255 "endianness = (int) LITTLE_ENDIAN");
3256 #define TIFF_LE_CAPS (gst_static_caps_get(&tiff_le_caps))
3258 tiff_type_find (GstTypeFind * tf, gpointer ununsed)
3260 const guint8 *data = gst_type_find_peek (tf, 0, 8);
3261 guint8 le_header[4] = { 0x49, 0x49, 0x2A, 0x00 };
3262 guint8 be_header[4] = { 0x4D, 0x4D, 0x00, 0x2A };
3265 if (memcmp (data, le_header, 4) == 0) {
3266 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_LE_CAPS);
3267 } else if (memcmp (data, be_header, 4) == 0) {
3268 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, TIFF_BE_CAPS);
3275 static GstStaticCaps pnm_caps = GST_STATIC_CAPS ("image/x-portable-bitmap; "
3276 "image/x-portable-graymap; image/x-portable-pixmap; "
3277 "image/x-portable-anymap");
3279 #define PNM_CAPS (gst_static_caps_get(&pnm_caps))
3281 #define IS_PNM_WHITESPACE(c) \
3282 ((c) == ' ' || (c) == '\r' || (c) == '\n' || (c) == 't')
3285 pnm_type_find (GstTypeFind * tf, gpointer ununsed)
3287 const gchar *media_type = NULL;
3288 DataScanCtx c = { 0, NULL, 0 };
3291 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
3294 /* see http://en.wikipedia.org/wiki/Netpbm_format */
3295 if (c.data[0] != 'P' || c.data[1] < '1' || c.data[1] > '7' ||
3296 !IS_PNM_WHITESPACE (c.data[2]) ||
3297 (c.data[3] != '#' && c.data[3] < '0' && c.data[3] > '9'))
3300 switch (c.data[1]) {
3302 media_type = "image/x-portable-bitmap"; /* ASCII */
3305 media_type = "image/x-portable-graymap"; /* ASCII */
3308 media_type = "image/x-portable-pixmap"; /* ASCII */
3311 media_type = "image/x-portable-bitmap"; /* Raw */
3314 media_type = "image/x-portable-graymap"; /* Raw */
3317 media_type = "image/x-portable-pixmap"; /* Raw */
3320 media_type = "image/x-portable-anymap";
3323 g_return_if_reached ();
3326 /* try to extract width and height as well */
3327 if (c.data[1] != '7') {
3328 gchar s[64] = { 0, }
3331 /* need to skip any comment lines first */
3332 data_scan_ctx_advance (tf, &c, 3);
3333 while (c.data[0] == '#') { /* we know there's still data left */
3334 data_scan_ctx_advance (tf, &c, 1);
3335 while (c.data[0] != '\n' && c.data[0] != '\r') {
3336 if (!data_scan_ctx_ensure_data (tf, &c, 4))
3338 data_scan_ctx_advance (tf, &c, 1);
3340 data_scan_ctx_advance (tf, &c, 1);
3341 GST_LOG ("skipped comment line in PNM header");
3344 if (!data_scan_ctx_ensure_data (tf, &c, 32) &&
3345 !data_scan_ctx_ensure_data (tf, &c, 4)) {
3349 /* need to NUL-terminate data for sscanf */
3350 memcpy (s, c.data, MIN (sizeof (s) - 1, c.size));
3351 if (sscanf (s, "%u%c%u%c", &w, &sep1, &h, &sep2) == 4 &&
3352 IS_PNM_WHITESPACE (sep1) && IS_PNM_WHITESPACE (sep2) &&
3353 w > 0 && w < G_MAXINT && h > 0 && h < G_MAXINT) {
3354 GST_LOG ("extracted PNM width and height: %dx%d", w, h);
3360 /* FIXME: extract width + height for anymaps too */
3363 if (w > 0 && h > 0) {
3364 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, media_type,
3365 "width", G_TYPE_INT, w, "height", G_TYPE_INT, h, NULL);
3367 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, media_type, NULL);
3371 static GstStaticCaps sds_caps = GST_STATIC_CAPS ("audio/x-sds");
3373 #define SDS_CAPS (gst_static_caps_get(&sds_caps))
3375 sds_type_find (GstTypeFind * tf, gpointer ununsed)
3377 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3378 guint8 mask[4] = { 0xFF, 0xFF, 0x80, 0xFF };
3379 guint8 match[4] = { 0xF0, 0x7E, 0, 0x01 };
3383 for (x = 0; x < 4; x++) {
3384 if ((data[x] & mask[x]) != match[x]) {
3388 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SDS_CAPS);
3392 static GstStaticCaps ircam_caps = GST_STATIC_CAPS ("audio/x-ircam");
3394 #define IRCAM_CAPS (gst_static_caps_get(&ircam_caps))
3396 ircam_type_find (GstTypeFind * tf, gpointer ununsed)
3398 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3399 guint8 mask[4] = { 0xFF, 0xFF, 0xF8, 0xFF };
3400 guint8 match[4] = { 0x64, 0xA3, 0x00, 0x00 };
3402 gboolean matched = TRUE;
3407 for (x = 0; x < 4; x++) {
3408 if ((data[x] & mask[x]) != match[x]) {
3413 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, IRCAM_CAPS);
3416 /* now try the reverse version */
3418 for (x = 0; x < 4; x++) {
3419 if ((data[x] & mask[3 - x]) != match[3 - x]) {
3425 /* EBML typefind helper */
3427 ebml_check_header (GstTypeFind * tf, const gchar * doctype, int doctype_len)
3429 /* 4 bytes for EBML ID, 1 byte for header length identifier */
3430 const guint8 *data = gst_type_find_peek (tf, 0, 4 + 1);
3431 gint len_mask = 0x80, size = 1, n = 1, total;
3437 if (data[0] != 0x1A || data[1] != 0x45 || data[2] != 0xDF || data[3] != 0xA3)
3440 /* length of header */
3442 while (size <= 8 && !(total & len_mask)) {
3448 total &= (len_mask - 1);
3450 total = (total << 8) | data[4 + n++];
3452 /* get new data for full header, 4 bytes for EBML ID,
3453 * EBML length tag and the actual header */
3454 data = gst_type_find_peek (tf, 0, 4 + size + total);
3458 /* only check doctype if asked to do so */
3459 if (doctype == NULL || doctype_len == 0)
3462 /* the header must contain the doctype. For now, we don't parse the
3463 * whole header but simply check for the availability of that array
3464 * of characters inside the header. Not fully fool-proof, but good
3466 for (n = 4 + size; n <= 4 + size + total - doctype_len; n++)
3467 if (!memcmp (&data[n], doctype, doctype_len))
3473 /*** video/x-matroska ***/
3474 static GstStaticCaps matroska_caps = GST_STATIC_CAPS ("video/x-matroska");
3476 #define MATROSKA_CAPS (gst_static_caps_get(&matroska_caps))
3478 matroska_type_find (GstTypeFind * tf, gpointer ununsed)
3480 if (ebml_check_header (tf, "matroska", 8))
3481 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MATROSKA_CAPS);
3482 else if (ebml_check_header (tf, NULL, 0))
3483 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MATROSKA_CAPS);
3486 /*** video/webm ***/
3487 static GstStaticCaps webm_caps = GST_STATIC_CAPS ("video/webm");
3489 #define WEBM_CAPS (gst_static_caps_get(&webm_caps))
3491 webm_type_find (GstTypeFind * tf, gpointer ununsed)
3493 if (ebml_check_header (tf, "webm", 4))
3494 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, WEBM_CAPS);
3497 /*** application/mxf ***/
3498 static GstStaticCaps mxf_caps = GST_STATIC_CAPS ("application/mxf");
3500 #define MXF_MAX_PROBE_LENGTH (1024 * 64)
3501 #define MXF_CAPS (gst_static_caps_get(&mxf_caps))
3504 * MXF files start with a header partition pack key of 16 bytes which is defined
3505 * at SMPTE-377M 6.1. Before this there can be up to 64K of run-in which _must_
3506 * not contain the partition pack key.
3509 mxf_type_find (GstTypeFind * tf, gpointer ununsed)
3511 static const guint8 partition_pack_key[] =
3512 { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
3515 DataScanCtx c = { 0, NULL, 0 };
3517 while (c.offset <= MXF_MAX_PROBE_LENGTH) {
3519 if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 1024)))
3522 /* look over in chunks of 1kbytes to avoid too much overhead */
3524 for (i = 0; i < 1024 - 16; i++) {
3525 /* Check first byte before calling more expensive memcmp function */
3526 if (G_UNLIKELY (c.data[i] == 0x06
3527 && memcmp (c.data + i, partition_pack_key, 13) == 0)) {
3528 /* Header partition pack? */
3529 if (c.data[i + 13] != 0x02)
3532 /* Partition status */
3533 if (c.data[i + 14] >= 0x05)
3536 /* Reserved, must be 0x00 */
3537 if (c.data[i + 15] != 0x00)
3540 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
3546 data_scan_ctx_advance (tf, &c, 1024 - 16);
3550 /*** video/x-dv ***/
3552 static GstStaticCaps dv_caps = GST_STATIC_CAPS ("video/x-dv, "
3553 "systemstream = (boolean) true");
3554 #define DV_CAPS (gst_static_caps_get(&dv_caps))
3556 dv_type_find (GstTypeFind * tf, gpointer private)
3560 data = gst_type_find_peek (tf, 0, 5);
3562 /* check for DIF and DV flag */
3563 if (data && (data[0] == 0x1f) && (data[1] == 0x07) && (data[2] == 0x00)) {
3564 const gchar *format;
3566 if (data[3] & 0x80) {
3572 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM, "video/x-dv",
3573 "systemstream", G_TYPE_BOOLEAN, TRUE,
3574 "format", G_TYPE_STRING, format, NULL);
3579 /*** application/ogg and application/x-annodex ***/
3580 static GstStaticCaps ogg_caps = GST_STATIC_CAPS ("application/ogg");
3581 static GstStaticCaps annodex_caps = GST_STATIC_CAPS ("application/x-annodex");
3582 static GstStaticCaps ogg_annodex_caps =
3583 GST_STATIC_CAPS ("application/ogg;application/x-annodex");
3585 #define OGGANX_CAPS (gst_static_caps_get(&ogg_annodex_caps))
3588 ogganx_type_find (GstTypeFind * tf, gpointer private)
3590 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3592 if ((data != NULL) && (memcmp (data, "OggS", 4) == 0)) {
3594 /* Check for an annodex fishbone header */
3595 data = gst_type_find_peek (tf, 28, 8);
3596 if (data && memcmp (data, "fishead\0", 8) == 0)
3597 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
3598 gst_static_caps_get (&annodex_caps));
3600 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
3601 gst_static_caps_get (&ogg_caps));
3605 /*** audio/x-vorbis ***/
3606 static GstStaticCaps vorbis_caps = GST_STATIC_CAPS ("audio/x-vorbis");
3608 #define VORBIS_CAPS (gst_static_caps_get(&vorbis_caps))
3610 vorbis_type_find (GstTypeFind * tf, gpointer private)
3612 const guint8 *data = gst_type_find_peek (tf, 0, 30);
3618 /* 1 byte packet type (identification=0x01)
3619 6 byte string "vorbis"
3620 4 byte vorbis version */
3621 if (memcmp (data, "\001vorbis\000\000\000\000", 11) != 0)
3624 /* 1 byte channels must be != 0 */
3628 /* 4 byte samplerate must be != 0 */
3629 if (GST_READ_UINT32_LE (data) == 0)
3632 /* blocksize checks */
3633 blocksize_0 = data[0] & 0x0F;
3634 blocksize_1 = (data[0] & 0xF0) >> 4;
3635 if (blocksize_0 > blocksize_1)
3637 if (blocksize_0 < 6 || blocksize_0 > 13)
3639 if (blocksize_1 < 6 || blocksize_1 > 13)
3643 if ((data[0] & 0x01) != 1)
3645 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VORBIS_CAPS);
3649 /*** video/x-theora ***/
3651 static GstStaticCaps theora_caps = GST_STATIC_CAPS ("video/x-theora");
3653 #define THEORA_CAPS (gst_static_caps_get(&theora_caps))
3655 theora_type_find (GstTypeFind * tf, gpointer private)
3657 const guint8 *data = gst_type_find_peek (tf, 0, 7); //42);
3660 if (data[0] != 0x80)
3662 if (memcmp (&data[1], "theora", 6) != 0)
3664 /* FIXME: make this more reliable when specs are out */
3666 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, THEORA_CAPS);
3672 kate_type_find (GstTypeFind * tf, gpointer private)
3674 const guint8 *data = gst_type_find_peek (tf, 0, 64);
3675 gchar category[16] = { 0, };
3677 if (G_UNLIKELY (data == NULL))
3680 /* see: http://wiki.xiph.org/index.php/OggKate#Format_specification */
3681 if (G_LIKELY (memcmp (data, "\200kate\0\0\0", 8) != 0))
3684 /* make sure we always have a NUL-terminated string */
3685 memcpy (category, data + 48, 15);
3686 GST_LOG ("kate category: %s", category);
3687 /* canonical categories for subtitles: subtitles, spu-subtitles, SUB, K-SPU */
3688 if (strcmp (category, "subtitles") == 0 || strcmp (category, "SUB") == 0 ||
3689 strcmp (category, "spu-subtitles") == 0 ||
3690 strcmp (category, "K-SPU") == 0) {
3691 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3692 "subtitle/x-kate", NULL);
3694 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_MAXIMUM,
3695 "application/x-kate", NULL);
3699 /*** application/x-ogm-video or audio***/
3701 static GstStaticCaps ogmvideo_caps =
3702 GST_STATIC_CAPS ("application/x-ogm-video");
3703 #define OGMVIDEO_CAPS (gst_static_caps_get(&ogmvideo_caps))
3705 ogmvideo_type_find (GstTypeFind * tf, gpointer private)
3707 const guint8 *data = gst_type_find_peek (tf, 0, 9);
3710 if (memcmp (data, "\001video\000\000\000", 9) != 0)
3712 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMVIDEO_CAPS);
3716 static GstStaticCaps ogmaudio_caps =
3717 GST_STATIC_CAPS ("application/x-ogm-audio");
3718 #define OGMAUDIO_CAPS (gst_static_caps_get(&ogmaudio_caps))
3720 ogmaudio_type_find (GstTypeFind * tf, gpointer private)
3722 const guint8 *data = gst_type_find_peek (tf, 0, 9);
3725 if (memcmp (data, "\001audio\000\000\000", 9) != 0)
3727 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMAUDIO_CAPS);
3731 static GstStaticCaps ogmtext_caps = GST_STATIC_CAPS ("application/x-ogm-text");
3733 #define OGMTEXT_CAPS (gst_static_caps_get(&ogmtext_caps))
3735 ogmtext_type_find (GstTypeFind * tf, gpointer private)
3737 const guint8 *data = gst_type_find_peek (tf, 0, 9);
3740 if (memcmp (data, "\001text\000\000\000\000", 9) != 0)
3742 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGMTEXT_CAPS);
3746 /*** audio/x-speex ***/
3748 static GstStaticCaps speex_caps = GST_STATIC_CAPS ("audio/x-speex");
3750 #define SPEEX_CAPS (gst_static_caps_get(&speex_caps))
3752 speex_type_find (GstTypeFind * tf, gpointer private)
3754 const guint8 *data = gst_type_find_peek (tf, 0, 80);
3757 /* 8 byte string "Speex "
3758 24 byte speex version string + int */
3759 if (memcmp (data, "Speex ", 8) != 0)
3763 /* 4 byte header size >= 80 */
3764 if (GST_READ_UINT32_LE (data) < 80)
3768 /* 4 byte sample rate <= 48000 */
3769 if (GST_READ_UINT32_LE (data) > 48000)
3773 /* currently there are only 3 speex modes. */
3774 if (GST_READ_UINT32_LE (data) > 3)
3778 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SPEEX_CAPS);
3782 /*** audio/x-celt ***/
3784 static GstStaticCaps celt_caps = GST_STATIC_CAPS ("audio/x-celt");
3786 #define CELT_CAPS (gst_static_caps_get(&celt_caps))
3788 celt_type_find (GstTypeFind * tf, gpointer private)
3790 const guint8 *data = gst_type_find_peek (tf, 0, 8);
3793 /* 8 byte string "CELT " */
3794 if (memcmp (data, "CELT ", 8) != 0)
3797 /* TODO: Check other values of the CELT header */
3798 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CELT_CAPS);
3802 /*** application/x-ogg-skeleton ***/
3803 static GstStaticCaps ogg_skeleton_caps =
3804 GST_STATIC_CAPS ("application/x-ogg-skeleton, parsed=(boolean)FALSE");
3805 #define OGG_SKELETON_CAPS (gst_static_caps_get(&ogg_skeleton_caps))
3807 oggskel_type_find (GstTypeFind * tf, gpointer private)
3809 const guint8 *data = gst_type_find_peek (tf, 0, 12);
3812 /* 8 byte string "fishead\0" for the ogg skeleton stream */
3813 if (memcmp (data, "fishead\0", 8) != 0)
3817 /* Require that the header contains version 3.0 */
3818 if (GST_READ_UINT16_LE (data) != 3)
3821 if (GST_READ_UINT16_LE (data) != 0)
3824 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, OGG_SKELETON_CAPS);
3828 static GstStaticCaps cmml_caps = GST_STATIC_CAPS ("text/x-cmml");
3830 #define CMML_CAPS (gst_static_caps_get(&cmml_caps))
3832 cmml_type_find (GstTypeFind * tf, gpointer private)
3834 /* Header is 12 bytes minimum (though we don't check the minor version */
3835 const guint8 *data = gst_type_find_peek (tf, 0, 12);
3839 /* 8 byte string "CMML\0\0\0\0" for the magic number */
3840 if (memcmp (data, "CMML\0\0\0\0", 8) != 0)
3844 /* Require that the header contains at least version 2.0 */
3845 if (GST_READ_UINT16_LE (data) < 2)
3848 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, CMML_CAPS);
3852 /*** application/x-tar ***/
3854 static GstStaticCaps tar_caps = GST_STATIC_CAPS ("application/x-tar");
3856 #define TAR_CAPS (gst_static_caps_get(&tar_caps))
3857 #define OLDGNU_MAGIC "ustar " /* 7 chars and a NUL */
3858 #define NEWGNU_MAGIC "ustar" /* 5 chars and a NUL */
3860 tar_type_find (GstTypeFind * tf, gpointer unused)
3862 const guint8 *data = gst_type_find_peek (tf, 257, 8);
3864 /* of course we are not certain, but we don't want other typefind funcs
3865 * to detect formats of files within the tar archive, e.g. mp3s */
3867 if (memcmp (data, OLDGNU_MAGIC, 8) == 0) { /* sic */
3868 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3869 } else if (memcmp (data, NEWGNU_MAGIC, 6) == 0 && /* sic */
3870 g_ascii_isdigit (data[6]) && g_ascii_isdigit (data[7])) {
3871 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, TAR_CAPS);
3876 /*** application/x-ar ***/
3878 static GstStaticCaps ar_caps = GST_STATIC_CAPS ("application/x-ar");
3880 #define AR_CAPS (gst_static_caps_get(&ar_caps))
3882 ar_type_find (GstTypeFind * tf, gpointer unused)
3884 const guint8 *data = gst_type_find_peek (tf, 0, 24);
3886 if (data && memcmp (data, "!<arch>", 7) == 0) {
3889 for (i = 7; i < 24; ++i) {
3890 if (!g_ascii_isprint (data[i]) && data[i] != '\n') {
3891 gst_type_find_suggest (tf, GST_TYPE_FIND_POSSIBLE, AR_CAPS);
3895 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, AR_CAPS);
3899 /*** audio/x-au ***/
3901 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3902 * as it is only possible to register one typefind factory per 'name'
3903 * (which is in this case the caps), and the first one would be replaced by
3904 * the second one. */
3905 static GstStaticCaps au_caps = GST_STATIC_CAPS ("audio/x-au");
3907 #define AU_CAPS (gst_static_caps_get(&au_caps))
3909 au_type_find (GstTypeFind * tf, gpointer unused)
3911 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3914 if (memcmp (data, ".snd", 4) == 0 || memcmp (data, "dns.", 4) == 0) {
3915 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, AU_CAPS);
3921 /*** video/x-nuv ***/
3923 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
3924 * as it is only possible to register one typefind factory per 'name'
3925 * (which is in this case the caps), and the first one would be replaced by
3926 * the second one. */
3927 static GstStaticCaps nuv_caps = GST_STATIC_CAPS ("video/x-nuv");
3929 #define NUV_CAPS (gst_static_caps_get(&nuv_caps))
3931 nuv_type_find (GstTypeFind * tf, gpointer unused)
3933 const guint8 *data = gst_type_find_peek (tf, 0, 11);
3936 if (memcmp (data, "MythTVVideo", 11) == 0
3937 || memcmp (data, "NuppelVideo", 11) == 0) {
3938 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, NUV_CAPS);
3943 /*** audio/x-paris ***/
3944 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3945 static GstStaticCaps paris_caps = GST_STATIC_CAPS ("audio/x-paris");
3947 #define PARIS_CAPS (gst_static_caps_get(&paris_caps))
3949 paris_type_find (GstTypeFind * tf, gpointer unused)
3951 const guint8 *data = gst_type_find_peek (tf, 0, 4);
3954 if (memcmp (data, " paf", 4) == 0 || memcmp (data, "fap ", 4) == 0) {
3955 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, PARIS_CAPS);
3960 /*** audio/iLBC-sh ***/
3961 /* NOTE: do not replace this function with two TYPE_FIND_REGISTER_START_WITH */
3962 static GstStaticCaps ilbc_caps = GST_STATIC_CAPS ("audio/iLBC-sh");
3964 #define ILBC_CAPS (gst_static_caps_get(&ilbc_caps))
3966 ilbc_type_find (GstTypeFind * tf, gpointer unused)
3968 const guint8 *data = gst_type_find_peek (tf, 0, 8);
3971 if (memcmp (data, "#!iLBC30", 8) == 0 || memcmp (data, "#!iLBC20", 8) == 0) {
3972 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, ILBC_CAPS);
3977 /*** application/x-ms-dos-executable ***/
3979 static GstStaticCaps msdos_caps =
3980 GST_STATIC_CAPS ("application/x-ms-dos-executable");
3981 #define MSDOS_CAPS (gst_static_caps_get(&msdos_caps))
3982 /* see http://www.madchat.org/vxdevl/papers/winsys/pefile/pefile.htm */
3984 msdos_type_find (GstTypeFind * tf, gpointer unused)
3986 const guint8 *data = gst_type_find_peek (tf, 0, 64);
3988 if (data && data[0] == 'M' && data[1] == 'Z' &&
3989 GST_READ_UINT16_LE (data + 8) == 4) {
3990 guint32 pe_offset = GST_READ_UINT32_LE (data + 60);
3992 data = gst_type_find_peek (tf, pe_offset, 2);
3993 if (data && data[0] == 'P' && data[1] == 'E') {
3994 gst_type_find_suggest (tf, GST_TYPE_FIND_NEARLY_CERTAIN, MSDOS_CAPS);
3999 /*** application/x-mmsh ***/
4001 static GstStaticCaps mmsh_caps = GST_STATIC_CAPS ("application/x-mmsh");
4003 #define MMSH_CAPS gst_static_caps_get(&mmsh_caps)
4005 /* This is to recognise mssh-over-http */
4007 mmsh_type_find (GstTypeFind * tf, gpointer unused)
4009 static const guint8 asf_marker[16] = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66,
4010 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
4015 data = gst_type_find_peek (tf, 0, 2 + 2 + 4 + 2 + 2 + 16);
4016 if (data && data[0] == 0x24 && data[1] == 0x48 &&
4017 GST_READ_UINT16_LE (data + 2) > 2 + 2 + 4 + 2 + 2 + 16 &&
4018 memcmp (data + 2 + 2 + 4 + 2 + 2, asf_marker, 16) == 0) {
4019 gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MMSH_CAPS);
4023 /*** video/x-dirac ***/
4025 /* NOTE: we cannot replace this function with TYPE_FIND_REGISTER_START_WITH,
4026 * as it is only possible to register one typefind factory per 'name'
4027 * (which is in this case the caps), and the first one would be replaced by
4028 * the second one. */
4029 static GstStaticCaps dirac_caps = GST_STATIC_CAPS ("video/x-dirac");
4031 #define DIRAC_CAPS (gst_static_caps_get(&dirac_caps))
4033 dirac_type_find (GstTypeFind * tf, gpointer unused)
4035 const guint8 *data = gst_type_find_peek (tf, 0, 8);
4038 if (memcmp (data, "BBCD", 4) == 0 || memcmp (data, "KW-DIRAC", 8) == 0) {
4039 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, DIRAC_CAPS);
4044 /*** video/vivo ***/
4046 static GstStaticCaps vivo_caps = GST_STATIC_CAPS ("video/vivo");
4048 #define VIVO_CAPS gst_static_caps_get(&vivo_caps)
4051 vivo_type_find (GstTypeFind * tf, gpointer unused)
4053 static const guint8 vivo_marker[] = { 'V', 'e', 'r', 's', 'i', 'o', 'n',
4054 ':', 'V', 'i', 'v', 'o', '/'
4059 data = gst_type_find_peek (tf, 0, 1024);
4060 if (data == NULL || data[0] != 0x00)
4063 if ((data[1] & 0x80)) {
4064 if ((data[2] & 0x80))
4066 hdr_len = ((guint) (data[1] & 0x7f)) << 7;
4076 /* 1008 = 1022 - strlen ("Version:Vivo/") - 1 */
4077 while (pos < 1008 && data[pos] == '\r' && data[pos + 1] == '\n')
4080 if (memcmp (data + pos, vivo_marker, sizeof (vivo_marker)) == 0) {
4081 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, VIVO_CAPS);
4085 /*** XDG MIME typefinder (to avoid false positives mostly) ***/
4089 xdgmime_typefind (GstTypeFind * find, gpointer user_data)
4092 gsize length = 16384;
4097 if ((tf_length = gst_type_find_get_length (find)) > 0)
4098 length = MIN (length, tf_length);
4100 if ((data = gst_type_find_peek (find, 0, length)) == NULL)
4103 tmp = g_content_type_guess (NULL, data, length, NULL);
4104 if (tmp == NULL || g_content_type_is_unknown (tmp)) {
4109 mimetype = g_content_type_get_mime_type (tmp);
4112 if (mimetype == NULL)
4115 GST_DEBUG ("Got mimetype '%s'", mimetype);
4117 /* Ignore audio/video types:
4118 * - our own typefinders in -base are likely to be better at this
4119 * (and if they're not, we really want to fix them, that's why we don't
4120 * report xdg-detected audio/video types at all, not even with a low
4122 * - we want to detect GStreamer media types and not MIME types
4123 * - the purpose of this xdg mime finder is mainly to prevent false
4124 * positives of non-media formats, not to typefind audio/video formats */
4125 if (g_str_has_prefix (mimetype, "audio/") ||
4126 g_str_has_prefix (mimetype, "video/")) {
4127 GST_LOG ("Ignoring audio/video mime type");
4132 /* Again, we mainly want the xdg typefinding to prevent false-positives on
4133 * non-media formats, so suggest the type with a probability that trumps
4134 * uncertain results of our typefinders, but not more than that. */
4135 GST_LOG ("Suggesting '%s' with probability POSSIBLE", mimetype);
4136 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE, mimetype, NULL);
4139 #endif /* USE_GIO */
4141 /*** Windows icon typefinder (to avoid false positives mostly) ***/
4144 windows_icon_typefind (GstTypeFind * find, gpointer user_data)
4148 guint16 type, nimages;
4149 gint32 size, offset;
4151 datalen = gst_type_find_get_length (find);
4152 if ((data = gst_type_find_peek (find, 0, 6)) == NULL)
4155 /* header - simple and not enough to rely on it alone */
4156 if (GST_READ_UINT16_LE (data) != 0)
4158 type = GST_READ_UINT16_LE (data + 2);
4159 if (type != 1 && type != 2)
4161 nimages = GST_READ_UINT16_LE (data + 4);
4162 if (nimages == 0) /* we can assume we can't have an empty image file ? */
4166 if (data[6 + 3] != 0)
4169 guint16 planes = GST_READ_UINT16_LE (data + 6 + 4);
4173 size = GST_READ_UINT32_LE (data + 6 + 8);
4174 offset = GST_READ_UINT32_LE (data + 6 + 12);
4175 if (offset < 0 || size <= 0 || size >= datalen || offset >= datalen
4176 || size + offset > datalen)
4179 gst_type_find_suggest_simple (find, GST_TYPE_FIND_NEARLY_CERTAIN,
4180 "image/x-icon", NULL);
4183 /*** WAP WBMP typefinder ***/
4186 wbmp_typefind (GstTypeFind * find, gpointer user_data)
4192 /* http://en.wikipedia.org/wiki/Wireless_Application_Protocol_Bitmap_Format */
4193 datalen = gst_type_find_get_length (find);
4197 data = gst_type_find_peek (find, 0, 5);
4201 /* want 0x00 0x00 at start */
4202 if (*data++ != 0 || *data++ != 0)
4205 /* min header size */
4208 /* let's assume max width/height is 65536 */
4211 w = (w << 8) | *data++;
4215 data = gst_type_find_peek (find, 4, 2);
4221 h = (h << 8) | *data++;
4227 if (w == 0 || h == 0)
4230 /* now add bitmap size */
4231 size += h * (GST_ROUND_UP_8 (w) / 8);
4233 if (datalen == size) {
4234 gst_type_find_suggest_simple (find, GST_TYPE_FIND_POSSIBLE - 10,
4235 "image/vnd.wap.wbmp", NULL);
4239 /*** DEGAS Atari images (also to avoid false positives, see #625129) ***/
4241 degas_type_find (GstTypeFind * tf, gpointer private)
4243 /* No magic, but it should have a fixed size and a few invalid values */
4244 /* http://www.fileformat.info/format/atari/spec/6ecf9f6eb5be494284a47feb8a214687/view.htm */
4250 len = gst_type_find_get_length (tf);
4251 if (len < 34) /* smallest header of the lot */
4253 data = gst_type_find_peek (tf, 0, 4);
4254 if (G_UNLIKELY (data == NULL))
4256 resolution = GST_READ_UINT16_BE (data);
4258 /* could be DEGAS */
4259 if (resolution <= 2)
4260 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
4261 "image/x-degas", NULL);
4262 } else if (len == 32066) {
4263 /* could be DEGAS Elite */
4264 if (resolution <= 2) {
4265 data = gst_type_find_peek (tf, len - 16, 8);
4266 if (G_UNLIKELY (data == NULL))
4268 for (n = 0; n < 4; n++) {
4269 if (GST_READ_UINT16_BE (data + n * 2) > 2)
4272 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
4273 "image/x-degas", NULL);
4275 } else if (len >= 66 && len < 32066) {
4276 /* could be compressed DEGAS Elite, but it's compressed and so we can't rely on size,
4277 it does have 4 16 bytes values near the end that are 0-2 though. */
4278 if ((resolution & 0x8000) && (resolution & 0x7fff) <= 2) {
4279 data = gst_type_find_peek (tf, len - 16, 8);
4280 if (G_UNLIKELY (data == NULL))
4282 for (n = 0; n < 4; n++) {
4283 if (GST_READ_UINT16_BE (data + n * 2) > 2)
4286 gst_type_find_suggest_simple (tf, GST_TYPE_FIND_POSSIBLE + 5,
4287 "image/x-degas", NULL);
4292 /*** generic typefind for streams that have some data at a specific position***/
4303 start_with_type_find (GstTypeFind * tf, gpointer private)
4305 GstTypeFindData *start_with = (GstTypeFindData *) private;
4308 GST_LOG ("trying to find mime type %s with the first %u bytes of data",
4309 gst_structure_get_name (gst_caps_get_structure (start_with->caps, 0)),
4311 data = gst_type_find_peek (tf, 0, start_with->size);
4312 if (data && memcmp (data, start_with->data, start_with->size) == 0) {
4313 gst_type_find_suggest (tf, start_with->probability, start_with->caps);
4318 sw_data_destroy (GstTypeFindData * sw_data)
4320 if (G_LIKELY (sw_data->caps != NULL))
4321 gst_caps_unref (sw_data->caps);
4325 #define TYPE_FIND_REGISTER_START_WITH(plugin,name,rank,ext,_data,_size,_probability)\
4327 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
4328 sw_data->data = (const guint8 *)_data; \
4329 sw_data->size = _size; \
4330 sw_data->probability = _probability; \
4331 sw_data->caps = gst_caps_new_empty_simple (name); \
4332 if (!gst_type_find_register (plugin, name, rank, start_with_type_find,\
4333 (char **) ext, sw_data->caps, sw_data, \
4334 (GDestroyNotify) (sw_data_destroy))) { \
4335 gst_caps_unref (sw_data->caps); \
4340 /*** same for riff types ***/
4343 riff_type_find (GstTypeFind * tf, gpointer private)
4345 GstTypeFindData *riff_data = (GstTypeFindData *) private;
4346 const guint8 *data = gst_type_find_peek (tf, 0, 12);
4348 if (data && (memcmp (data, "RIFF", 4) == 0 || memcmp (data, "AVF0", 4) == 0)) {
4350 if (memcmp (data, riff_data->data, 4) == 0)
4351 gst_type_find_suggest (tf, riff_data->probability, riff_data->caps);
4355 #define TYPE_FIND_REGISTER_RIFF(plugin,name,rank,ext,_data) \
4357 GstTypeFindData *sw_data = g_new (GstTypeFindData, 1); \
4358 sw_data->data = (gpointer)_data; \
4359 sw_data->size = 4; \
4360 sw_data->probability = GST_TYPE_FIND_MAXIMUM; \
4361 sw_data->caps = gst_caps_new_empty_simple (name); \
4362 if (!gst_type_find_register (plugin, name, rank, riff_type_find, \
4363 (char **) ext, sw_data->caps, sw_data, \
4364 (GDestroyNotify) (sw_data_destroy))) { \
4365 gst_caps_unref (sw_data->caps); \
4371 /*** plugin initialization ***/
4373 #define TYPE_FIND_REGISTER(plugin,name,rank,func,ext,caps,priv,notify) \
4375 if (!gst_type_find_register (plugin, name, rank, func, (char **) ext, caps, priv, notify))\
4381 plugin_init (GstPlugin * plugin)
4383 /* can't initialize this via a struct as caps can't be statically initialized */
4385 /* note: asx/wax/wmx are XML files, asf doesn't handle them */
4386 /* FIXME-0.11: these should be const,
4387 this requires gstreamer/gst/gsttypefind::gst_type_find_register()
4388 to have define the parameter as const
4390 static const gchar *asf_exts[] = { "asf", "wm", "wma", "wmv", NULL };
4391 static const gchar *au_exts[] = { "au", "snd", NULL };
4392 static const gchar *avi_exts[] = { "avi", NULL };
4393 static const gchar *qcp_exts[] = { "qcp", NULL };
4394 static const gchar *cdxa_exts[] = { "dat", NULL };
4395 static const gchar *flac_exts[] = { "flac", NULL };
4396 static const gchar *flx_exts[] = { "flc", "fli", NULL };
4397 static const gchar *id3_exts[] =
4398 { "mp3", "mp2", "mp1", "mpga", "ogg", "flac", "tta", NULL };
4399 static const gchar *apetag_exts[] = { "mp3", "ape", "mpc", "wv", NULL };
4400 static const gchar *tta_exts[] = { "tta", NULL };
4401 static const gchar *mod_exts[] = { "669", "amf", "dsm", "gdm", "far", "imf",
4402 "it", "med", "mod", "mtm", "okt", "sam",
4403 "s3m", "stm", "stx", "ult", "xm", NULL
4405 static const gchar *mp3_exts[] = { "mp3", "mp2", "mp1", "mpga", NULL };
4406 static const gchar *ac3_exts[] = { "ac3", "eac3", NULL };
4407 static const gchar *dts_exts[] = { "dts", NULL };
4408 static const gchar *gsm_exts[] = { "gsm", NULL };
4409 static const gchar *musepack_exts[] = { "mpc", "mpp", "mp+", NULL };
4410 static const gchar *mpeg_sys_exts[] = { "mpe", "mpeg", "mpg", NULL };
4411 static const gchar *mpeg_video_exts[] = { "mpv", "mpeg", "mpg", NULL };
4412 static const gchar *mpeg_ts_exts[] = { "ts", "mts", NULL };
4413 static const gchar *ogg_exts[] = { "anx", "ogg", "ogm", NULL };
4414 static const gchar *qt_exts[] = { "mov", NULL };
4415 static const gchar *qtif_exts[] = { "qif", "qtif", "qti", NULL };
4416 static const gchar *mj2_exts[] = { "mj2", NULL };
4417 static const gchar *jp2_exts[] = { "jp2", NULL };
4418 static const gchar *rm_exts[] = { "ra", "ram", "rm", "rmvb", NULL };
4419 static const gchar *swf_exts[] = { "swf", "swfl", NULL };
4420 static const gchar *utf8_exts[] = { "txt", NULL };
4421 static const gchar *unicode_exts[] = { "txt", NULL };
4422 static const gchar *wav_exts[] = { "wav", NULL };
4423 static const gchar *aiff_exts[] = { "aiff", "aif", "aifc", NULL };
4424 static const gchar *svx_exts[] = { "iff", "svx", NULL };
4425 static const gchar *paris_exts[] = { "paf", NULL };
4426 static const gchar *nist_exts[] = { "nist", NULL };
4427 static const gchar *voc_exts[] = { "voc", NULL };
4428 static const gchar *sds_exts[] = { "sds", NULL };
4429 static const gchar *ircam_exts[] = { "sf", NULL };
4430 static const gchar *w64_exts[] = { "w64", NULL };
4431 static const gchar *shn_exts[] = { "shn", NULL };
4432 static const gchar *ape_exts[] = { "ape", NULL };
4433 static const gchar *uri_exts[] = { "ram", NULL };
4434 static const gchar *hls_exts[] = { "m3u8", NULL };
4435 static const gchar *sdp_exts[] = { "sdp", NULL };
4436 static const gchar *smil_exts[] = { "smil", NULL };
4437 static const gchar *html_exts[] = { "htm", "html", NULL };
4438 static const gchar *xml_exts[] = { "xml", NULL };
4439 static const gchar *jpeg_exts[] = { "jpg", "jpe", "jpeg", NULL };
4440 static const gchar *gif_exts[] = { "gif", NULL };
4441 static const gchar *png_exts[] = { "png", NULL };
4442 static const gchar *bmp_exts[] = { "bmp", NULL };
4443 static const gchar *tiff_exts[] = { "tif", "tiff", NULL };
4444 static const gchar *matroska_exts[] = { "mkv", "mka", NULL };
4445 static const gchar *webm_exts[] = { "webm", NULL };
4446 static const gchar *mve_exts[] = { "mve", NULL };
4447 static const gchar *dv_exts[] = { "dv", "dif", NULL };
4448 static const gchar *amr_exts[] = { "amr", NULL };
4449 static const gchar *ilbc_exts[] = { "ilbc", NULL };
4450 static const gchar *sid_exts[] = { "sid", NULL };
4451 static const gchar *xcf_exts[] = { "xcf", NULL };
4452 static const gchar *mng_exts[] = { "mng", NULL };
4453 static const gchar *jng_exts[] = { "jng", NULL };
4454 static const gchar *xpm_exts[] = { "xpm", NULL };
4455 static const gchar *pnm_exts[] = { "pnm", "ppm", "pgm", "pbm", NULL };
4456 static const gchar *ras_exts[] = { "ras", NULL };
4457 static const gchar *bz2_exts[] = { "bz2", NULL };
4458 static const gchar *gz_exts[] = { "gz", NULL };
4459 static const gchar *zip_exts[] = { "zip", NULL };
4460 static const gchar *compress_exts[] = { "Z", NULL };
4461 static const gchar *m4a_exts[] = { "m4a", NULL };
4462 static const gchar *q3gp_exts[] = { "3gp", NULL };
4463 static const gchar *aac_exts[] = { "aac", "adts", "adif", "loas", NULL };
4464 static const gchar *spc_exts[] = { "spc", NULL };
4465 static const gchar *wavpack_exts[] = { "wv", "wvp", NULL };
4466 static const gchar *wavpack_correction_exts[] = { "wvc", NULL };
4467 static const gchar *rar_exts[] = { "rar", NULL };
4468 static const gchar *tar_exts[] = { "tar", NULL };
4469 static const gchar *ar_exts[] = { "a", NULL };
4470 static const gchar *msdos_exts[] = { "dll", "exe", "ocx", "sys", "scr",
4471 "msstyles", "cpl", NULL
4473 static const gchar *flv_exts[] = { "flv", NULL };
4474 static const gchar *m4v_exts[] = { "m4v", NULL };
4475 static const gchar *h263_exts[] = { "h263", "263", NULL };
4476 static const gchar *h264_exts[] = { "h264", "x264", "264", NULL };
4477 static const gchar *nuv_exts[] = { "nuv", NULL };
4478 static const gchar *vivo_exts[] = { "viv", NULL };
4479 static const gchar *nsf_exts[] = { "nsf", NULL };
4480 static const gchar *gym_exts[] = { "gym", NULL };
4481 static const gchar *ay_exts[] = { "ay", NULL };
4482 static const gchar *gbs_exts[] = { "gbs", NULL };
4483 static const gchar *kss_exts[] = { "kss", NULL };
4484 static const gchar *sap_exts[] = { "sap", NULL };
4485 static const gchar *vgm_exts[] = { "vgm", NULL };
4486 static const gchar *mid_exts[] = { "mid", "midi", NULL };
4487 static const gchar *mxmf_exts[] = { "mxmf", NULL };
4488 static const gchar *imelody_exts[] = { "imy", "ime", "imelody", NULL };
4489 static const gchar *pdf_exts[] = { "pdf", NULL };
4490 static const gchar *ps_exts[] = { "ps", NULL };
4491 static const gchar *svg_exts[] = { "svg", NULL };
4492 static const gchar *mxf_exts[] = { "mxf", NULL };
4493 static const gchar *ivf_exts[] = { "ivf", NULL };
4494 static const gchar *msword_exts[] = { "doc", NULL };
4495 static const gchar *dsstore_exts[] = { "DS_Store", NULL };
4496 static const gchar *psd_exts[] = { "psd", NULL };
4497 static const gchar *y4m_exts[] = { "y4m", NULL };
4499 GST_DEBUG_CATEGORY_INIT (type_find_debug, "typefindfunctions",
4500 GST_DEBUG_FG_GREEN | GST_DEBUG_BG_RED, "generic type find functions");
4502 /* must use strings, macros don't accept initializers */
4503 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ms-asf", GST_RANK_SECONDARY,
4505 "\060\046\262\165\216\146\317\021\246\331\000\252\000\142\316\154", 16,
4506 GST_TYPE_FIND_MAXIMUM);
4507 TYPE_FIND_REGISTER (plugin, "audio/x-musepack", GST_RANK_PRIMARY,
4508 musepack_type_find, musepack_exts, MUSEPACK_CAPS, NULL, NULL);
4509 TYPE_FIND_REGISTER (plugin, "audio/x-au", GST_RANK_MARGINAL,
4510 au_type_find, au_exts, AU_CAPS, NULL, NULL);
4511 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-msvideo", GST_RANK_PRIMARY,
4513 TYPE_FIND_REGISTER_RIFF (plugin, "audio/qcelp", GST_RANK_PRIMARY,
4515 TYPE_FIND_REGISTER_RIFF (plugin, "video/x-cdxa", GST_RANK_PRIMARY,
4517 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-vcd", GST_RANK_PRIMARY,
4518 cdxa_exts, "\000\377\377\377\377\377\377\377\377\377\377\000", 12,
4519 GST_TYPE_FIND_MAXIMUM);
4520 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-imelody", GST_RANK_PRIMARY,
4521 imelody_exts, "BEGIN:IMELODY", 13, GST_TYPE_FIND_MAXIMUM);
4523 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-smoke", GST_RANK_PRIMARY,
4524 NULL, "\x80smoke\x00\x01\x00", 6, GST_TYPE_FIND_MAXIMUM);
4526 TYPE_FIND_REGISTER (plugin, "audio/midi", GST_RANK_PRIMARY, mid_type_find,
4527 mid_exts, MID_CAPS, NULL, NULL);
4528 TYPE_FIND_REGISTER_RIFF (plugin, "audio/riff-midi", GST_RANK_PRIMARY,
4530 TYPE_FIND_REGISTER (plugin, "audio/mobile-xmf", GST_RANK_PRIMARY,
4531 mxmf_type_find, mxmf_exts, MXMF_CAPS, NULL, NULL);
4532 TYPE_FIND_REGISTER (plugin, "video/x-fli", GST_RANK_MARGINAL, flx_type_find,
4533 flx_exts, FLX_CAPS, NULL, NULL);
4534 TYPE_FIND_REGISTER (plugin, "application/x-id3v2", GST_RANK_PRIMARY + 103,
4535 id3v2_type_find, id3_exts, ID3_CAPS, NULL, NULL);
4536 TYPE_FIND_REGISTER (plugin, "application/x-id3v1", GST_RANK_PRIMARY + 101,
4537 id3v1_type_find, id3_exts, ID3_CAPS, NULL, NULL);
4538 TYPE_FIND_REGISTER (plugin, "application/x-apetag", GST_RANK_PRIMARY + 102,
4539 apetag_type_find, apetag_exts, APETAG_CAPS, NULL, NULL);
4540 TYPE_FIND_REGISTER (plugin, "audio/x-ttafile", GST_RANK_PRIMARY,
4541 tta_type_find, tta_exts, TTA_CAPS, NULL, NULL);
4542 TYPE_FIND_REGISTER (plugin, "audio/x-mod", GST_RANK_SECONDARY, mod_type_find,
4543 mod_exts, MOD_CAPS, NULL, NULL);
4544 TYPE_FIND_REGISTER (plugin, "audio/mpeg", GST_RANK_PRIMARY, mp3_type_find,
4545 mp3_exts, MP3_CAPS, NULL, NULL);
4546 TYPE_FIND_REGISTER (plugin, "audio/x-ac3", GST_RANK_PRIMARY, ac3_type_find,
4547 ac3_exts, AC3_CAPS, NULL, NULL);
4548 TYPE_FIND_REGISTER (plugin, "audio/x-dts", GST_RANK_SECONDARY, dts_type_find,
4549 dts_exts, DTS_CAPS, NULL, NULL);
4550 TYPE_FIND_REGISTER (plugin, "audio/x-gsm", GST_RANK_PRIMARY, NULL, gsm_exts,
4551 GSM_CAPS, NULL, NULL);
4552 TYPE_FIND_REGISTER (plugin, "video/mpeg-sys", GST_RANK_PRIMARY,
4553 mpeg_sys_type_find, mpeg_sys_exts, MPEG_SYS_CAPS, NULL, NULL);
4554 TYPE_FIND_REGISTER (plugin, "video/mpegts", GST_RANK_PRIMARY,
4555 mpeg_ts_type_find, mpeg_ts_exts, MPEGTS_CAPS, NULL, NULL);
4556 TYPE_FIND_REGISTER (plugin, "application/ogg", GST_RANK_PRIMARY,
4557 ogganx_type_find, ogg_exts, OGGANX_CAPS, NULL, NULL);
4558 TYPE_FIND_REGISTER (plugin, "video/mpeg-elementary", GST_RANK_MARGINAL,
4559 mpeg_video_stream_type_find, mpeg_video_exts, MPEG_VIDEO_CAPS, NULL,
4561 TYPE_FIND_REGISTER (plugin, "video/mpeg4", GST_RANK_PRIMARY,
4562 mpeg4_video_type_find, m4v_exts, MPEG_VIDEO_CAPS, NULL, NULL);
4563 TYPE_FIND_REGISTER (plugin, "video/x-h263", GST_RANK_SECONDARY,
4564 h263_video_type_find, h263_exts, H263_VIDEO_CAPS, NULL, NULL);
4565 TYPE_FIND_REGISTER (plugin, "video/x-h264", GST_RANK_PRIMARY,
4566 h264_video_type_find, h264_exts, H264_VIDEO_CAPS, NULL, NULL);
4567 TYPE_FIND_REGISTER (plugin, "video/x-nuv", GST_RANK_SECONDARY, nuv_type_find,
4568 nuv_exts, NUV_CAPS, NULL, NULL);
4571 TYPE_FIND_REGISTER (plugin, "audio/x-m4a", GST_RANK_PRIMARY, m4a_type_find,
4572 m4a_exts, M4A_CAPS, NULL, NULL);
4573 TYPE_FIND_REGISTER (plugin, "application/x-3gp", GST_RANK_PRIMARY,
4574 q3gp_type_find, q3gp_exts, Q3GP_CAPS, NULL, NULL);
4575 TYPE_FIND_REGISTER (plugin, "video/quicktime", GST_RANK_SECONDARY,
4576 qt_type_find, qt_exts, QT_CAPS, NULL, NULL);
4577 TYPE_FIND_REGISTER (plugin, "image/x-quicktime", GST_RANK_SECONDARY,
4578 qtif_type_find, qtif_exts, QTIF_CAPS, NULL, NULL);
4579 TYPE_FIND_REGISTER (plugin, "image/jp2", GST_RANK_PRIMARY,
4580 jp2_type_find, jp2_exts, JP2_CAPS, NULL, NULL);
4581 TYPE_FIND_REGISTER (plugin, "video/mj2", GST_RANK_PRIMARY,
4582 jp2_type_find, mj2_exts, MJ2_CAPS, NULL, NULL);
4584 TYPE_FIND_REGISTER (plugin, "text/html", GST_RANK_SECONDARY, html_type_find,
4585 html_exts, HTML_CAPS, NULL, NULL);
4586 TYPE_FIND_REGISTER_START_WITH (plugin, "application/vnd.rn-realmedia",
4587 GST_RANK_SECONDARY, rm_exts, ".RMF", 4, GST_TYPE_FIND_MAXIMUM);
4588 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-pn-realaudio",
4589 GST_RANK_SECONDARY, rm_exts, ".ra\375", 4, GST_TYPE_FIND_MAXIMUM);
4590 TYPE_FIND_REGISTER (plugin, "application/x-shockwave-flash",
4591 GST_RANK_SECONDARY, swf_type_find, swf_exts, SWF_CAPS, NULL, NULL);
4592 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-flv", GST_RANK_SECONDARY,
4593 flv_exts, "FLV", 3, GST_TYPE_FIND_MAXIMUM);
4594 TYPE_FIND_REGISTER (plugin, "text/plain", GST_RANK_MARGINAL, utf8_type_find,
4595 utf8_exts, UTF8_CAPS, NULL, NULL);
4596 TYPE_FIND_REGISTER (plugin, "text/utf-16", GST_RANK_MARGINAL, utf16_type_find,
4597 unicode_exts, UTF16_CAPS, NULL, NULL);
4598 TYPE_FIND_REGISTER (plugin, "text/utf-32", GST_RANK_MARGINAL, utf32_type_find,
4599 unicode_exts, UTF32_CAPS, NULL, NULL);
4600 TYPE_FIND_REGISTER (plugin, "text/uri-list", GST_RANK_MARGINAL, uri_type_find,
4601 uri_exts, URI_CAPS, NULL, NULL);
4602 TYPE_FIND_REGISTER (plugin, "application/x-hls", GST_RANK_MARGINAL,
4603 hls_type_find, hls_exts, HLS_CAPS, NULL, NULL);
4604 TYPE_FIND_REGISTER (plugin, "application/sdp", GST_RANK_SECONDARY,
4605 sdp_type_find, sdp_exts, SDP_CAPS, NULL, NULL);
4606 TYPE_FIND_REGISTER (plugin, "application/smil", GST_RANK_SECONDARY,
4607 smil_type_find, smil_exts, SMIL_CAPS, NULL, NULL);
4608 TYPE_FIND_REGISTER (plugin, "application/xml", GST_RANK_MARGINAL,
4609 xml_type_find, xml_exts, GENERIC_XML_CAPS, NULL, NULL);
4610 TYPE_FIND_REGISTER_RIFF (plugin, "audio/x-wav", GST_RANK_PRIMARY, wav_exts,
4612 TYPE_FIND_REGISTER (plugin, "audio/x-aiff", GST_RANK_SECONDARY,
4613 aiff_type_find, aiff_exts, AIFF_CAPS, NULL, NULL);
4614 TYPE_FIND_REGISTER (plugin, "audio/x-svx", GST_RANK_SECONDARY, svx_type_find,
4615 svx_exts, SVX_CAPS, NULL, NULL);
4616 TYPE_FIND_REGISTER (plugin, "audio/x-paris", GST_RANK_SECONDARY,
4617 paris_type_find, paris_exts, PARIS_CAPS, NULL, NULL);
4618 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nist", GST_RANK_SECONDARY,
4619 nist_exts, "NIST", 4, GST_TYPE_FIND_MAXIMUM);
4620 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-voc", GST_RANK_SECONDARY,
4621 voc_exts, "Creative", 8, GST_TYPE_FIND_MAXIMUM);
4622 TYPE_FIND_REGISTER (plugin, "audio/x-sds", GST_RANK_SECONDARY, sds_type_find,
4623 sds_exts, SDS_CAPS, NULL, NULL);
4624 TYPE_FIND_REGISTER (plugin, "audio/x-ircam", GST_RANK_SECONDARY,
4625 ircam_type_find, ircam_exts, IRCAM_CAPS, NULL, NULL);
4626 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-w64", GST_RANK_SECONDARY,
4627 w64_exts, "riff", 4, GST_TYPE_FIND_MAXIMUM);
4628 TYPE_FIND_REGISTER (plugin, "audio/x-shorten", GST_RANK_SECONDARY,
4629 shn_type_find, shn_exts, SHN_CAPS, NULL, NULL);
4630 TYPE_FIND_REGISTER (plugin, "application/x-ape", GST_RANK_SECONDARY,
4631 ape_type_find, ape_exts, APE_CAPS, NULL, NULL);
4632 TYPE_FIND_REGISTER (plugin, "image/jpeg", GST_RANK_PRIMARY + 15,
4633 jpeg_type_find, jpeg_exts, JPEG_CAPS, NULL, NULL);
4634 TYPE_FIND_REGISTER_START_WITH (plugin, "image/gif", GST_RANK_PRIMARY,
4635 gif_exts, "GIF8", 4, GST_TYPE_FIND_MAXIMUM);
4636 TYPE_FIND_REGISTER_START_WITH (plugin, "image/png", GST_RANK_PRIMARY + 14,
4637 png_exts, "\211PNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
4638 TYPE_FIND_REGISTER (plugin, "image/bmp", GST_RANK_PRIMARY, bmp_type_find,
4639 bmp_exts, BMP_CAPS, NULL, NULL);
4640 TYPE_FIND_REGISTER (plugin, "image/tiff", GST_RANK_PRIMARY, tiff_type_find,
4641 tiff_exts, TIFF_CAPS, NULL, NULL);
4642 TYPE_FIND_REGISTER (plugin, "image/x-portable-pixmap", GST_RANK_SECONDARY,
4643 pnm_type_find, pnm_exts, PNM_CAPS, NULL, NULL);
4644 TYPE_FIND_REGISTER (plugin, "video/x-matroska", GST_RANK_PRIMARY,
4645 matroska_type_find, matroska_exts, MATROSKA_CAPS, NULL, NULL);
4646 TYPE_FIND_REGISTER (plugin, "video/webm", GST_RANK_PRIMARY,
4647 webm_type_find, webm_exts, WEBM_CAPS, NULL, NULL);
4648 TYPE_FIND_REGISTER (plugin, "application/mxf", GST_RANK_PRIMARY,
4649 mxf_type_find, mxf_exts, MXF_CAPS, NULL, NULL);
4650 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mve", GST_RANK_SECONDARY,
4651 mve_exts, "Interplay MVE File\032\000\032\000\000\001\063\021", 26,
4652 GST_TYPE_FIND_MAXIMUM);
4653 TYPE_FIND_REGISTER (plugin, "video/x-dv", GST_RANK_SECONDARY, dv_type_find,
4654 dv_exts, DV_CAPS, NULL, NULL);
4655 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-nb-sh", GST_RANK_PRIMARY,
4656 amr_exts, "#!AMR", 5, GST_TYPE_FIND_LIKELY);
4657 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-amr-wb-sh", GST_RANK_PRIMARY,
4658 amr_exts, "#!AMR-WB", 7, GST_TYPE_FIND_MAXIMUM);
4659 TYPE_FIND_REGISTER (plugin, "audio/iLBC-sh", GST_RANK_PRIMARY,
4660 ilbc_type_find, ilbc_exts, ILBC_CAPS, NULL, NULL);
4661 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sid", GST_RANK_MARGINAL,
4662 sid_exts, "PSID", 4, GST_TYPE_FIND_MAXIMUM);
4663 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xcf", GST_RANK_SECONDARY,
4664 xcf_exts, "gimp xcf", 8, GST_TYPE_FIND_MAXIMUM);
4665 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-mng", GST_RANK_SECONDARY,
4666 mng_exts, "\212MNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
4667 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-jng", GST_RANK_SECONDARY,
4668 jng_exts, "\213JNG\015\012\032\012", 8, GST_TYPE_FIND_MAXIMUM);
4669 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-xpixmap", GST_RANK_SECONDARY,
4670 xpm_exts, "/* XPM */", 9, GST_TYPE_FIND_MAXIMUM);
4671 TYPE_FIND_REGISTER_START_WITH (plugin, "image/x-sun-raster",
4672 GST_RANK_SECONDARY, ras_exts, "\131\246\152\225", 4,
4673 GST_TYPE_FIND_MAXIMUM);
4674 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-bzip",
4675 GST_RANK_SECONDARY, bz2_exts, "BZh", 3, GST_TYPE_FIND_LIKELY);
4676 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-gzip",
4677 GST_RANK_SECONDARY, gz_exts, "\037\213", 2, GST_TYPE_FIND_LIKELY);
4678 TYPE_FIND_REGISTER_START_WITH (plugin, "application/zip", GST_RANK_SECONDARY,
4679 zip_exts, "PK\003\004", 4, GST_TYPE_FIND_LIKELY);
4680 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-compress",
4681 GST_RANK_SECONDARY, compress_exts, "\037\235", 2, GST_TYPE_FIND_LIKELY);
4682 TYPE_FIND_REGISTER (plugin, "subtitle/x-kate", GST_RANK_MARGINAL,
4683 kate_type_find, NULL, NULL, NULL, NULL);
4684 TYPE_FIND_REGISTER (plugin, "audio/x-flac", GST_RANK_PRIMARY,
4685 flac_type_find, flac_exts, FLAC_CAPS, NULL, NULL);
4686 TYPE_FIND_REGISTER (plugin, "audio/x-vorbis", GST_RANK_PRIMARY,
4687 vorbis_type_find, NULL, VORBIS_CAPS, NULL, NULL);
4688 TYPE_FIND_REGISTER (plugin, "video/x-theora", GST_RANK_PRIMARY,
4689 theora_type_find, NULL, THEORA_CAPS, NULL, NULL);
4690 TYPE_FIND_REGISTER (plugin, "application/x-ogm-video", GST_RANK_PRIMARY,
4691 ogmvideo_type_find, NULL, OGMVIDEO_CAPS, NULL, NULL);
4692 TYPE_FIND_REGISTER (plugin, "application/x-ogm-audio", GST_RANK_PRIMARY,
4693 ogmaudio_type_find, NULL, OGMAUDIO_CAPS, NULL, NULL);
4694 TYPE_FIND_REGISTER (plugin, "application/x-ogm-text", GST_RANK_PRIMARY,
4695 ogmtext_type_find, NULL, OGMTEXT_CAPS, NULL, NULL);
4696 TYPE_FIND_REGISTER (plugin, "audio/x-speex", GST_RANK_PRIMARY,
4697 speex_type_find, NULL, SPEEX_CAPS, NULL, NULL);
4698 TYPE_FIND_REGISTER (plugin, "audio/x-celt", GST_RANK_PRIMARY,
4699 celt_type_find, NULL, CELT_CAPS, NULL, NULL);
4700 TYPE_FIND_REGISTER (plugin, "application/x-ogg-skeleton", GST_RANK_PRIMARY,
4701 oggskel_type_find, NULL, OGG_SKELETON_CAPS, NULL, NULL);
4702 TYPE_FIND_REGISTER (plugin, "text/x-cmml", GST_RANK_PRIMARY, cmml_type_find,
4703 NULL, CMML_CAPS, NULL, NULL);
4704 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-executable",
4705 GST_RANK_MARGINAL, NULL, "\177ELF", 4, GST_TYPE_FIND_MAXIMUM);
4706 TYPE_FIND_REGISTER (plugin, "audio/aac", GST_RANK_SECONDARY,
4707 aac_type_find, aac_exts, AAC_CAPS, NULL, NULL);
4708 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-spc", GST_RANK_SECONDARY,
4709 spc_exts, "SNES-SPC700 Sound File Data", 27, GST_TYPE_FIND_MAXIMUM);
4710 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack", GST_RANK_SECONDARY,
4711 wavpack_type_find, wavpack_exts, WAVPACK_CAPS, NULL, NULL);
4712 TYPE_FIND_REGISTER (plugin, "audio/x-wavpack-correction", GST_RANK_SECONDARY,
4713 wavpack_type_find, wavpack_correction_exts, WAVPACK_CORRECTION_CAPS, NULL,
4715 TYPE_FIND_REGISTER (plugin, "application/postscript", GST_RANK_SECONDARY,
4716 postscript_type_find, ps_exts, POSTSCRIPT_CAPS, NULL, NULL);
4717 TYPE_FIND_REGISTER (plugin, "image/svg+xml", GST_RANK_SECONDARY,
4718 svg_type_find, svg_exts, SVG_CAPS, NULL, NULL);
4719 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-rar",
4720 GST_RANK_SECONDARY, rar_exts, "Rar!", 4, GST_TYPE_FIND_LIKELY);
4721 TYPE_FIND_REGISTER (plugin, "application/x-tar", GST_RANK_SECONDARY,
4722 tar_type_find, tar_exts, TAR_CAPS, NULL, NULL);
4723 TYPE_FIND_REGISTER (plugin, "application/x-ar", GST_RANK_SECONDARY,
4724 ar_type_find, ar_exts, AR_CAPS, NULL, NULL);
4725 TYPE_FIND_REGISTER (plugin, "application/x-ms-dos-executable",
4726 GST_RANK_SECONDARY, msdos_type_find, msdos_exts, MSDOS_CAPS, NULL, NULL);
4727 TYPE_FIND_REGISTER (plugin, "video/x-dirac", GST_RANK_PRIMARY,
4728 dirac_type_find, NULL, DIRAC_CAPS, NULL, NULL);
4729 TYPE_FIND_REGISTER (plugin, "multipart/x-mixed-replace", GST_RANK_SECONDARY,
4730 multipart_type_find, NULL, MULTIPART_CAPS, NULL, NULL);
4731 TYPE_FIND_REGISTER (plugin, "application/x-mmsh", GST_RANK_SECONDARY,
4732 mmsh_type_find, NULL, MMSH_CAPS, NULL, NULL);
4733 TYPE_FIND_REGISTER (plugin, "video/vivo", GST_RANK_SECONDARY,
4734 vivo_type_find, vivo_exts, VIVO_CAPS, NULL, NULL);
4735 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-nsf",
4736 GST_RANK_SECONDARY, nsf_exts, "NESM\x1a", 5, GST_TYPE_FIND_MAXIMUM);
4737 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gym",
4738 GST_RANK_SECONDARY, gym_exts, "GYMX", 4, GST_TYPE_FIND_MAXIMUM);
4739 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-ay",
4740 GST_RANK_SECONDARY, ay_exts, "ZXAYEMUL", 8, GST_TYPE_FIND_MAXIMUM);
4741 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-gbs",
4742 GST_RANK_SECONDARY, gbs_exts, "GBS\x01", 4, GST_TYPE_FIND_MAXIMUM);
4743 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-vgm",
4744 GST_RANK_SECONDARY, vgm_exts, "Vgm\x20", 4, GST_TYPE_FIND_MAXIMUM);
4745 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sap",
4746 GST_RANK_SECONDARY, sap_exts, "SAP\x0d\x0a" "AUTHOR\x20", 12,
4747 GST_TYPE_FIND_MAXIMUM);
4748 TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-ivf", GST_RANK_SECONDARY,
4749 ivf_exts, "DKIF", 4, GST_TYPE_FIND_NEARLY_CERTAIN);
4750 TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-kss", GST_RANK_SECONDARY,
4751 kss_exts, "KSSX\0", 5, GST_TYPE_FIND_MAXIMUM);
4752 TYPE_FIND_REGISTER_START_WITH (plugin, "application/pdf", GST_RANK_SECONDARY,
4753 pdf_exts, "%PDF-", 5, GST_TYPE_FIND_LIKELY);
4754 TYPE_FIND_REGISTER_START_WITH (plugin, "application/msword",
4755 GST_RANK_SECONDARY, msword_exts, "\320\317\021\340\241\261\032\341", 8,
4756 GST_TYPE_FIND_LIKELY);
4757 /* Mac OS X .DS_Store files tend to be taken for video/mpeg */
4758 TYPE_FIND_REGISTER_START_WITH (plugin, "application/octet-stream",
4759 GST_RANK_SECONDARY, dsstore_exts, "\000\000\000\001Bud1", 8,
4760 GST_TYPE_FIND_LIKELY);
4761 TYPE_FIND_REGISTER_START_WITH (plugin, "image/vnd.adobe.photoshop",
4762 GST_RANK_SECONDARY, psd_exts, "8BPS\000\001\000\000\000\000", 10,
4763 GST_TYPE_FIND_LIKELY);
4764 TYPE_FIND_REGISTER (plugin, "image/vnd.wap.wbmp", GST_RANK_MARGINAL,
4765 wbmp_typefind, NULL, NULL, NULL, NULL);
4766 TYPE_FIND_REGISTER_START_WITH (plugin, "application/x-yuv4mpeg",
4767 GST_RANK_SECONDARY, y4m_exts, "YUV4MPEG2 ", 10, GST_TYPE_FIND_LIKELY);
4768 TYPE_FIND_REGISTER (plugin, "image/x-icon", GST_RANK_MARGINAL,
4769 windows_icon_typefind, NULL, NULL, NULL, NULL);
4772 TYPE_FIND_REGISTER (plugin, "xdgmime-base", GST_RANK_MARGINAL,
4773 xdgmime_typefind, NULL, NULL, NULL, NULL);
4776 TYPE_FIND_REGISTER (plugin, "image/x-degas", GST_RANK_MARGINAL,
4777 degas_type_find, NULL, NULL, NULL, NULL);
4782 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
4784 "typefindfunctions",
4785 "default typefind functions",
4786 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)