• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
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>
5  * Copyright (C) 2020 Huawei Technologies Co., Ltd.
6  *   @Author: Stéphane Cerveau <scerveau@collabora.com>
7  *
8  * gsttypefindfunctionsstartwith.c: collection of various typefind functions
9  * using the start with pattern
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24  * Boston, MA 02110-1301, USA.
25  */
26 
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30 
31 #include <gst/gst.h>
32 
33 #include "gsttypefindfunctionsplugin.h"
34 #include "gsttypefindfunctionsdata.h"
35 
36 static void
start_with_type_find(GstTypeFind * tf,gpointer private)37 start_with_type_find (GstTypeFind * tf, gpointer private)
38 {
39   GstTypeFindData *start_with = (GstTypeFindData *) private;
40   const guint8 *data;
41 
42   GST_LOG ("trying to find mime type %s with the first %u bytes of data",
43       gst_structure_get_name (gst_caps_get_structure (start_with->caps, 0)),
44       start_with->size);
45   data = gst_type_find_peek (tf, 0, start_with->size);
46   if (data && memcmp (data, start_with->data, start_with->size) == 0) {
47     gst_type_find_suggest (tf, start_with->probability, start_with->caps);
48   }
49 }
50 
51 #define TYPE_FIND_REGISTER_START_WITH_DEFINE(typefind_name, name, rank, ext, _data, _size, _probability)\
52 G_BEGIN_DECLS \
53 static gboolean \
54 G_PASTE(_private_type_find_start_with_, typefind_name) (GstPlugin * plugin) \
55 { \
56   GstTypeFindData *sw_data = g_slice_new (GstTypeFindData);             \
57   sw_data->data = (const guint8 *)_data;                                \
58   sw_data->size = _size;                                                \
59   sw_data->probability = _probability;                                  \
60   sw_data->caps = gst_caps_new_empty_simple (name);                     \
61   if (!gst_type_find_register (plugin, name, rank, start_with_type_find,\
62                      ext, sw_data->caps, sw_data,                       \
63                      (GDestroyNotify) (sw_data_destroy))) {             \
64     sw_data_destroy (sw_data);                                          \
65     return FALSE; \
66   } \
67   return TRUE; \
68 }\
69 GST_TYPE_FIND_REGISTER_DEFINE_CUSTOM (typefind_name, G_PASTE(_private_type_find_start_with_, typefind_name)); \
70 G_END_DECLS
71 
72 /*'Start with' type find definition */
73 TYPE_FIND_REGISTER_START_WITH_DEFINE (asf, "video/x-ms-asf",
74     GST_RANK_SECONDARY, "asf,wm,wma,wmv",
75     "\060\046\262\165\216\146\317\021\246\331\000\252\000\142\316\154", 16,
76     GST_TYPE_FIND_MAXIMUM);
77 TYPE_FIND_REGISTER_START_WITH_DEFINE (vcd, "video/x-vcd", GST_RANK_PRIMARY,
78     "dat", "\000\377\377\377\377\377\377\377\377\377\377\000", 12,
79     GST_TYPE_FIND_MAXIMUM);
80 TYPE_FIND_REGISTER_START_WITH_DEFINE (imelody, "audio/x-imelody",
81     GST_RANK_PRIMARY, "imy,ime,imelody", "BEGIN:IMELODY", 13,
82     GST_TYPE_FIND_MAXIMUM);
83 TYPE_FIND_REGISTER_START_WITH_DEFINE (scc, "application/x-scc",
84     GST_RANK_PRIMARY, "scc", "Scenarist_SCC V1.0", 18, GST_TYPE_FIND_MAXIMUM);
85 #if 0
86 TYPE_FIND_REGISTER_START_WITH_DEFINE (smoke, "video/x-smoke",
87     GST_RANK_PRIMARY, NULL, "\x80smoke\x00\x01\x00", 6, GST_TYPE_FIND_MAXIMUM);
88 #endif
89 TYPE_FIND_REGISTER_START_WITH_DEFINE (rmf, "application/vnd.rn-realmedia",
90     GST_RANK_SECONDARY, "ra,ram,rm,rmvb", ".RMF", 4, GST_TYPE_FIND_MAXIMUM);
91 TYPE_FIND_REGISTER_START_WITH_DEFINE (ram, "application/x-pn-realaudio",
92     GST_RANK_SECONDARY, "ra,ram,rm,rmvb", ".ra\375", 4, GST_TYPE_FIND_MAXIMUM);
93 TYPE_FIND_REGISTER_START_WITH_DEFINE (flv, "video/x-flv",
94     GST_RANK_SECONDARY, "flv", "FLV", 3, GST_TYPE_FIND_MAXIMUM);
95 TYPE_FIND_REGISTER_START_WITH_DEFINE (nist, "audio/x-nist",
96     GST_RANK_SECONDARY, "nist", "NIST", 4, GST_TYPE_FIND_MAXIMUM);
97 TYPE_FIND_REGISTER_START_WITH_DEFINE (voc, "audio/x-voc",
98     GST_RANK_SECONDARY, "voc", "Creative", 8, GST_TYPE_FIND_MAXIMUM);
99 TYPE_FIND_REGISTER_START_WITH_DEFINE (w64, "audio/x-w64",
100     GST_RANK_SECONDARY, "w64", "riff", 4, GST_TYPE_FIND_MAXIMUM);
101 TYPE_FIND_REGISTER_START_WITH_DEFINE (rf64, "audio/x-rf64",
102     GST_RANK_PRIMARY, "rf64", "RF64", 4, GST_TYPE_FIND_MAXIMUM);
103 TYPE_FIND_REGISTER_START_WITH_DEFINE (gif, "image/gif", GST_RANK_PRIMARY,
104     "gif", "GIF8", 4, GST_TYPE_FIND_MAXIMUM);
105 TYPE_FIND_REGISTER_START_WITH_DEFINE (png, "image/png",
106     GST_RANK_PRIMARY + 14, "png", "\211PNG\015\012\032\012", 8,
107     GST_TYPE_FIND_MAXIMUM);
108 TYPE_FIND_REGISTER_START_WITH_DEFINE (mve, "video/x-mve",
109     GST_RANK_SECONDARY, "mve",
110     "Interplay MVE File\032\000\032\000\000\001\063\021", 26,
111     GST_TYPE_FIND_MAXIMUM);
112 TYPE_FIND_REGISTER_START_WITH_DEFINE (amr, "audio/x-amr-nb-sh",
113     GST_RANK_PRIMARY, "amr", "#!AMR", 5, GST_TYPE_FIND_LIKELY);
114 TYPE_FIND_REGISTER_START_WITH_DEFINE (amr_wb, "audio/x-amr-wb-sh",
115     GST_RANK_PRIMARY, "amr", "#!AMR-WB", 7, GST_TYPE_FIND_MAXIMUM);
116 TYPE_FIND_REGISTER_START_WITH_DEFINE (sid, "audio/x-sid", GST_RANK_MARGINAL,
117     "sid", "PSID", 4, GST_TYPE_FIND_MAXIMUM);
118 TYPE_FIND_REGISTER_START_WITH_DEFINE (xcf, "image/x-xcf",
119     GST_RANK_SECONDARY, "xcf", "gimp xcf", 8, GST_TYPE_FIND_MAXIMUM);
120 TYPE_FIND_REGISTER_START_WITH_DEFINE (mng, "video/x-mng",
121     GST_RANK_SECONDARY, "mng", "\212MNG\015\012\032\012", 8,
122     GST_TYPE_FIND_MAXIMUM);
123 TYPE_FIND_REGISTER_START_WITH_DEFINE (jng, "image/x-jng",
124     GST_RANK_SECONDARY, "jng", "\213JNG\015\012\032\012", 8,
125     GST_TYPE_FIND_MAXIMUM);
126 TYPE_FIND_REGISTER_START_WITH_DEFINE (xpm, "image/x-xpixmap",
127     GST_RANK_SECONDARY, "xpm", "/* XPM */", 9, GST_TYPE_FIND_MAXIMUM);
128 TYPE_FIND_REGISTER_START_WITH_DEFINE (ras, "image/x-sun-raster",
129     GST_RANK_SECONDARY, "ras", "\131\246\152\225", 4, GST_TYPE_FIND_MAXIMUM);
130 TYPE_FIND_REGISTER_START_WITH_DEFINE (bz2, "application/x-bzip",
131     GST_RANK_SECONDARY, "bz2", "BZh", 3, GST_TYPE_FIND_LIKELY);
132 TYPE_FIND_REGISTER_START_WITH_DEFINE (gz, "application/x-gzip",
133     GST_RANK_SECONDARY, "gz", "\037\213", 2, GST_TYPE_FIND_LIKELY);
134 TYPE_FIND_REGISTER_START_WITH_DEFINE (zip, "application/zip",
135     GST_RANK_SECONDARY, "zip", "PK\003\004", 4, GST_TYPE_FIND_LIKELY);
136 TYPE_FIND_REGISTER_START_WITH_DEFINE (z, "application/x-compress",
137     GST_RANK_SECONDARY, "Z", "\037\235", 2, GST_TYPE_FIND_LIKELY);
138 TYPE_FIND_REGISTER_START_WITH_DEFINE (elf, "application/x-executable",
139     GST_RANK_MARGINAL, NULL, "\177ELF", 4, GST_TYPE_FIND_MAXIMUM);
140 TYPE_FIND_REGISTER_START_WITH_DEFINE (spc, "audio/x-spc",
141     GST_RANK_SECONDARY, "spc", "SNES-SPC700 Sound File Data", 27,
142     GST_TYPE_FIND_MAXIMUM);
143 TYPE_FIND_REGISTER_START_WITH_DEFINE (caf, "audio/x-caf",
144     GST_RANK_SECONDARY, "caf", "caff\000\001", 6, GST_TYPE_FIND_MAXIMUM);
145 TYPE_FIND_REGISTER_START_WITH_DEFINE (rar, "application/x-rar",
146     GST_RANK_SECONDARY, "rar", "Rar!", 4, GST_TYPE_FIND_LIKELY);
147 TYPE_FIND_REGISTER_START_WITH_DEFINE (nsf, "audio/x-nsf",
148     GST_RANK_SECONDARY, "nsf", "NESM\x1a", 5, GST_TYPE_FIND_MAXIMUM);
149 TYPE_FIND_REGISTER_START_WITH_DEFINE (gym, "audio/x-gym",
150     GST_RANK_SECONDARY, "gym", "GYMX", 4, GST_TYPE_FIND_MAXIMUM);
151 TYPE_FIND_REGISTER_START_WITH_DEFINE (ay, "audio/x-ay", GST_RANK_SECONDARY,
152     "ay", "ZXAYEMUL", 8, GST_TYPE_FIND_MAXIMUM);
153 TYPE_FIND_REGISTER_START_WITH_DEFINE (gbs, "audio/x-gbs",
154     GST_RANK_SECONDARY, "gbs", "GBS\x01", 4, GST_TYPE_FIND_MAXIMUM);
155 TYPE_FIND_REGISTER_START_WITH_DEFINE (vgm, "audio/x-vgm",
156     GST_RANK_SECONDARY, "vgm", "Vgm\x20", 4, GST_TYPE_FIND_MAXIMUM);
157 TYPE_FIND_REGISTER_START_WITH_DEFINE (sap, "audio/x-sap",
158     GST_RANK_SECONDARY, "sap", "SAP\x0d\x0a" "AUTHOR\x20", 12,
159     GST_TYPE_FIND_MAXIMUM);
160 TYPE_FIND_REGISTER_START_WITH_DEFINE (ivf, "video/x-ivf",
161     GST_RANK_SECONDARY, "ivf", "DKIF", 4, GST_TYPE_FIND_NEARLY_CERTAIN);
162 TYPE_FIND_REGISTER_START_WITH_DEFINE (kss, "audio/x-kss",
163     GST_RANK_SECONDARY, "kss", "KSSX\0", 5, GST_TYPE_FIND_MAXIMUM);
164 TYPE_FIND_REGISTER_START_WITH_DEFINE (pdf, "application/pdf",
165     GST_RANK_SECONDARY, "pdf", "%PDF-", 5, GST_TYPE_FIND_LIKELY);
166 TYPE_FIND_REGISTER_START_WITH_DEFINE (doc, "application/msword",
167     GST_RANK_SECONDARY, "doc", "\320\317\021\340\241\261\032\341", 8,
168     GST_TYPE_FIND_LIKELY);
169 /* Mac OS X .DS_Store files tend to be taken for video/mpeg */
170 TYPE_FIND_REGISTER_START_WITH_DEFINE (ds_store, "application/octet-stream",
171     GST_RANK_SECONDARY, "DS_Store", "\000\000\000\001Bud1", 8,
172     GST_TYPE_FIND_LIKELY);
173 TYPE_FIND_REGISTER_START_WITH_DEFINE (psd, "image/vnd.adobe.photoshop",
174     GST_RANK_SECONDARY, "psd", "8BPS\000\001\000\000\000\000", 10,
175     GST_TYPE_FIND_LIKELY);
176 TYPE_FIND_REGISTER_START_WITH_DEFINE (xi, "audio/x-xi", GST_RANK_SECONDARY,
177     "xi", "Extended Instrument: ", 21, GST_TYPE_FIND_MAXIMUM);
178 TYPE_FIND_REGISTER_START_WITH_DEFINE (dmp, "audio/x-tap-dmp",
179     GST_RANK_SECONDARY, "dmp", "DC2N-TAP-RAW", 12, GST_TYPE_FIND_LIKELY);
180