a14094ce907d58b909e7e536d8fbb1a0b00ff53c
1 /* Gnome-Streamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
20 //#define DEBUG_ENABLED
21 #include <gst/gst.h>
22 #include <string.h> /* memcmp */
24 static GstCaps* mp3_typefind(GstBuffer *buf, gpointer private);
26 static GstTypeDefinition mp3type_definitions[] = {
27 { "mp3types_audio/mp3", "audio/mp3", ".mp3 .mp2 .mp1 .mpga", mp3_typefind },
28 { NULL, NULL, NULL, NULL },
29 };
31 static GstCaps*
32 mp3_typefind(GstBuffer *buf, gpointer private)
33 {
34 gchar *data;
35 gulong head;
36 GstCaps *caps;
38 data = GST_BUFFER_DATA(buf);
40 GST_DEBUG (0,"mp3typefind: typefind\n");
42 /* check for ID3 Tag first and forward ID3 length */
43 if (!memcmp (data, "ID3", 3))
44 {
45 guint32 skip;
46 /* ignore next 3 bytes */
47 data += 6;
48 /* if you want that thing faster, do it */
49 skip = GUINT32_FROM_BE(*((guint32 *)data));
50 skip = (((skip & 0x7f000000) >> 3) |
51 ((skip & 0x007f0000) >> 2) |
52 ((skip & 0x00007f00) >> 1) |
53 ((skip & 0x0000007f) >> 0)) + 4;
54 GST_DEBUG (0, "mp3typefind: detected ID3 Tag with %u bytes\n", skip + 6);
55 /* return if buffer is not big enough */
56 if (GST_BUFFER_SIZE (buf) < skip + 10)
57 {
58 GST_DEBUG (0, "mp3typefind: buffer too small (%d) to go on typefinding\n", skip + 6);
59 return NULL;
60 }
61 data += skip;
62 }
64 /* now with the right postion, do typefinding */
65 head = GULONG_FROM_BE(*((gulong *)data));
66 if ((head & 0xffe00000) != 0xffe00000)
67 return NULL;
68 if (!((head >> 17) & 3))
69 return NULL;
70 if (((head >> 12) & 0xf) == 0xf)
71 return NULL;
72 if (!((head >> 12) & 0xf))
73 return NULL;
74 if (((head >> 10) & 0x3) == 0x3)
75 return NULL;
77 caps = gst_caps_new ("mp3_typefind", "audio/mp3", NULL);
78 /* gst_caps_set(caps,"layer",GST_PROPS_INT(4-((head>>17)&0x3))); */
80 return caps;
81 }
83 static gboolean
84 plugin_init (GModule *module, GstPlugin *plugin)
85 {
86 gint i=0;
88 while (mp3type_definitions[i].name) {
89 GstTypeFactory *type;
91 type = gst_typefactory_new (&mp3type_definitions[i]);
92 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
93 i++;
94 }
96 /* gst_info("gsttypes: loaded %d mp3 types\n",i); */
98 return TRUE;
99 }
101 GstPluginDesc plugin_desc = {
102 GST_VERSION_MAJOR,
103 GST_VERSION_MINOR,
104 "mp3types",
105 plugin_init
106 };