From 4de40d8ccd21dca15aaf792a842d266604cc59a7 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 23 Oct 2003 02:14:06 +0000 Subject: initial typefind checkin. All typefind functions have been put into one single plugin in gst/typefind Original commit message from CVS: initial typefind checkin. All typefind functions have been put into one single plugin in gst/typefind --- configure.ac | 6 +- ext/audiofile/gstafparse.h | 2 +- ext/ivorbis/vorbis.c | 2 +- ext/ivorbis/vorbisfile.c | 2 +- ext/jack/gstjack.h | 2 +- ext/ladspa/gstladspa.h | 2 +- ext/mplex/gstmplex.h | 2 +- ext/swfdec/gstswfdec.c | 27 ---- gst/cdxaparse/gstcdxaparse.c | 41 ------ gst/cdxaparse/gstcdxaparse.h | 2 +- gst/festival/gstfestival.c | 50 ------- gst/flx/gstflxdec.c | 44 ------ gst/flx/gstflxdec.h | 2 +- gst/mixmatrix/mixmatrix.c | 2 +- gst/modplug/Makefile.am | 4 +- gst/modplug/gstmodplug.cc | 59 +------- gst/modplug/gstmodplug.h | 4 +- gst/modplug/modplug_types.cc | 221 ---------------------------- gst/modplug/modplug_types.h | 44 ------ gst/mpegaudioparse/gstmp3types.c | 254 +++++++++++++++++++++++++++++++++ gst/mpegaudioparse/gstmpegaudioparse.c | 86 ----------- gst/qtdemux/qtdemux.c | 39 ----- gst/qtdemux/qtdemux.h | 2 +- gst/rtjpeg/gstrtjpeg.c | 7 - 24 files changed, 274 insertions(+), 632 deletions(-) delete mode 100644 gst/modplug/modplug_types.cc delete mode 100644 gst/modplug/modplug_types.h create mode 100644 gst/mpegaudioparse/gstmp3types.c diff --git a/configure.ac b/configure.ac index 313dc49b6..c836aaf37 100644 --- a/configure.ac +++ b/configure.ac @@ -264,10 +264,10 @@ GST_PLUGINS_ALL="\ cutter debug deinterlace effectv festival \ filter flx goom id3 intfloat law level median mixmatrix \ mpeg1sys mpeg1videoparse mpeg2enc mpeg2sub \ - mpegaudio mpegaudioparse mpegstream mpegtypes \ + mpegaudio mpegaudioparse mpegstream \ monoscope oneton overlay passthrough playondemand qtdemux \ realmedia rtp rtjpeg silence sine smooth smpte \ - spectrum speed stereo synaesthesia tcp udp vbidec \ + spectrum speed stereo synaesthesia tcp typefind udp vbidec \ videocrop videodrop videofilter videoflip videoscale \ videotestsrc volenv volume wavenc wavparse y4m" @@ -1193,7 +1193,6 @@ gst/mpeg2sub/Makefile gst/mpegaudio/Makefile gst/mpegaudioparse/Makefile gst/mpegstream/Makefile -gst/mpegtypes/Makefile gst/modplug/Makefile gst/modplug/libmodplug/Makefile gst/monoscope/Makefile @@ -1214,6 +1213,7 @@ gst/speed/Makefile gst/stereo/Makefile gst/synaesthesia/Makefile gst/tcp/Makefile +gst/typefind/Makefile gst/udp/Makefile gst/vbidec/Makefile gst/videocrop/Makefile diff --git a/ext/audiofile/gstafparse.h b/ext/audiofile/gstafparse.h index 1cf7b1e1c..51877bae6 100644 --- a/ext/audiofile/gstafparse.h +++ b/ext/audiofile/gstafparse.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include /* what else are we to do */ #include diff --git a/ext/ivorbis/vorbis.c b/ext/ivorbis/vorbis.c index 359190593..a68e01a1d 100644 --- a/ext/ivorbis/vorbis.c +++ b/ext/ivorbis/vorbis.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include extern GType ivorbisfile_get_type(void); diff --git a/ext/ivorbis/vorbisfile.c b/ext/ivorbis/vorbisfile.c index fa9f8ef38..ef76a0cc4 100644 --- a/ext/ivorbis/vorbisfile.c +++ b/ext/ivorbis/vorbisfile.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #define GST_TYPE_IVORBISFILE \ (ivorbisfile_get_type()) diff --git a/ext/jack/gstjack.h b/ext/jack/gstjack.h index 80fd2b63a..2bb13858e 100644 --- a/ext/jack/gstjack.h +++ b/ext/jack/gstjack.h @@ -22,7 +22,7 @@ #include #include -#include +#include //#define JACK_DEBUG(str, a...) g_message (str, ##a) #define JACK_DEBUG(str, a...) diff --git a/ext/ladspa/gstladspa.h b/ext/ladspa/gstladspa.h index 85348a955..a33062ff8 100644 --- a/ext/ladspa/gstladspa.h +++ b/ext/ladspa/gstladspa.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include "ladspa.h" diff --git a/ext/mplex/gstmplex.h b/ext/mplex/gstmplex.h index 8b108ed18..2af373794 100644 --- a/ext/mplex/gstmplex.h +++ b/ext/mplex/gstmplex.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include "outputstream.hh" #include "bits.hh" diff --git a/ext/swfdec/gstswfdec.c b/ext/swfdec/gstswfdec.c index 58e96e87a..78ed29b45 100644 --- a/ext/swfdec/gstswfdec.c +++ b/ext/swfdec/gstswfdec.c @@ -626,34 +626,10 @@ gst_swfdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSp } } -static GstCaps * -swf_type_find(GstByteStream *bs, gpointer private) -{ - GstBuffer *buf; - gchar *data; - - gst_bytestream_peek (bs, &buf, 4); - data = GST_BUFFER_DATA(buf); - - if (GST_BUFFER_SIZE (buf) < 4) - return NULL; - - if((data[0] != 'F' && data[0] != 'C') || - data[1] != 'W' || data[2] != 'S')return NULL; - - return gst_caps_new("swf_type_find","application/x-shockwave-flash", - NULL); -} - -static GstTypeDefinition swftype_definition = - { "swfdecode/x-shockwave-flash", "application/x-shockwave-flash", - ".swf .swfl", swf_type_find }; - static gboolean plugin_init (GModule *module, GstPlugin *plugin) { GstElementFactory *factory; - GstTypeFactory *type; /* create an elementfactory for the swfdec element */ factory = gst_element_factory_new("swfdec",GST_TYPE_SWFDEC, @@ -670,9 +646,6 @@ plugin_init (GModule *module, GstPlugin *plugin) gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); - type = gst_type_factory_new(&swftype_definition); - gst_plugin_add_feature(plugin, GST_PLUGIN_FEATURE(type)); - return TRUE; } diff --git a/gst/cdxaparse/gstcdxaparse.c b/gst/cdxaparse/gstcdxaparse.c index a601b7274..8356dc844 100644 --- a/gst/cdxaparse/gstcdxaparse.c +++ b/gst/cdxaparse/gstcdxaparse.c @@ -50,16 +50,6 @@ static GstElementDetails gst_cdxa_parse_details = { "(C) 2002", }; -static GstCaps* cdxa_type_find (GstByteStream *bs, gpointer private); - -/* typefactory for 'cdxa' */ -static GstTypeDefinition cdxadefinition = { - "cdxaparse_video", - "video/x-cdxa", - ".dat", - cdxa_type_find, -}; - /* CDXAParse signals and args */ enum { /* FILL ME */ @@ -158,33 +148,6 @@ gst_cdxa_parse_init (GstCDXAParse *cdxa_parse) } -static GstCaps* -cdxa_type_find (GstByteStream *bs, - gpointer private) -{ - GstBuffer *buf = NULL; - GstCaps *new = NULL; - - GST_DEBUG ("cdxa_parse: typefind"); - - if (gst_bytestream_peek (bs, &buf, 12) == 12) { - guint32 head1 = GUINT32_FROM_LE (((guint32 *) GST_BUFFER_DATA (buf))[0]), - head2 = GUINT32_FROM_LE (((guint32 *) GST_BUFFER_DATA (buf))[2]); - - if (head1 == GST_RIFF_TAG_RIFF && head2 == GST_RIFF_RIFF_CDXA) { - new = GST_CAPS_NEW ("cdxa_type_find", - "video/x-cdxa", - NULL); - } - } - - if (buf != NULL) { - gst_buffer_unref (buf); - } - - return new; -} - static gboolean gst_cdxa_parse_handle_event (GstCDXAParse *cdxa_parse) { @@ -343,7 +306,6 @@ static gboolean plugin_init (GModule *module, GstPlugin *plugin) { GstElementFactory *factory; - GstTypeFactory *type; /* create an elementfactory for the cdxa_parse element */ factory = gst_element_factory_new ("cdxaparse", GST_TYPE_CDXA_PARSE, @@ -353,9 +315,6 @@ plugin_init (GModule *module, GstPlugin *plugin) gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (src_templ)); gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (sink_templ)); - type = gst_type_factory_new (&cdxadefinition); - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type)); - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); return TRUE; diff --git a/gst/cdxaparse/gstcdxaparse.h b/gst/cdxaparse/gstcdxaparse.h index c46df1490..ff4660147 100644 --- a/gst/cdxaparse/gstcdxaparse.h +++ b/gst/cdxaparse/gstcdxaparse.h @@ -24,7 +24,7 @@ #include #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/gst/festival/gstfestival.c b/gst/festival/gstfestival.c index a0f3b8f60..636f1e12b 100644 --- a/gst/festival/gstfestival.c +++ b/gst/festival/gstfestival.c @@ -80,8 +80,6 @@ static void gst_festival_class_init (GstFestivalClass *klass); static void gst_festival_init (GstFestival *festival); -static GstCaps* text_type_find (GstByteStream *bs, gpointer private); - static void gst_festival_chain (GstPad *pad, GstData *_data); static GstElementStateReturn gst_festival_change_state (GstElement *element); @@ -123,17 +121,6 @@ GST_PAD_TEMPLATE_FACTORY (src_template_factory, ) ) -/* typefactory for 'wav' */ -static GstTypeDefinition -textdefinition = -{ - "festival_text/plain", - "text/plain", - ".txt", - text_type_find, -}; - - /* Festival signals and args */ enum { /* FILL ME */ @@ -197,40 +184,6 @@ gst_festival_init (GstFestival *festival) festival->info = festival_default_info(); } -static GstCaps* -text_type_find (GstByteStream *bs, gpointer private) -{ - GstBuffer *buf = NULL; - GstCaps *new = NULL; - -#define TEXT_SIZE 32 - - /* read arbitrary number and see if it's textual */ - if (gst_bytestream_peek (bs, &buf, TEXT_SIZE) == TEXT_SIZE) { - gchar *data = GST_BUFFER_DATA (buf); - gint i; - - for (i = 0; i < TEXT_SIZE; i++) { - if (!isprint (data[i]) && data[i] != '\n') { - goto out; - } - } - - /* well, we found something that looks like text... */ - new = gst_caps_new ("text_type_find", - "text/plain", - NULL); - } -out: - - if (buf != NULL) { - gst_buffer_unref (buf); - } - - return new; -} - - static void gst_festival_chain (GstPad *pad, GstData *_data) { @@ -484,7 +437,6 @@ static gboolean plugin_init (GModule *module, GstPlugin *plugin) { GstElementFactory *factory; - GstTypeFactory *type; /* create an elementfactory for the festival element */ factory = gst_element_factory_new ("festival", GST_TYPE_FESTIVAL, @@ -495,9 +447,7 @@ plugin_init (GModule *module, GstPlugin *plugin) gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (sink_template_factory)); gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (src_template_factory)); - type = gst_type_factory_new (&textdefinition); gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type)); return TRUE; } diff --git a/gst/flx/gstflxdec.c b/gst/flx/gstflxdec.c index 7ed55f1bf..51ceec48b 100644 --- a/gst/flx/gstflxdec.c +++ b/gst/flx/gstflxdec.c @@ -28,8 +28,6 @@ #define JIFFIE (GST_SECOND/70) -static GstCaps* flxdec_type_find (GstByteStream *bs, gpointer private); - /* flx element information */ static GstElementDetails flxdec_details = { "FLX Decoder", @@ -41,13 +39,6 @@ static GstElementDetails flxdec_details = { "(C) 2001", }; -static GstTypeDefinition flxdec_definition = { - "flxdec_video/fli", - "video/fli", - ".flc .fli", - flxdec_type_find, -}; - /* Flx signals and args */ enum { /* FILL ME */ @@ -112,37 +103,6 @@ static void flx_decode_delta_flc (GstFlxDec *, guchar *, guchar *); static GstElementClass *parent_class = NULL; -static GstCaps* -flxdec_type_find (GstByteStream *bs, gpointer private) -{ - GstBuffer *buf = NULL; - GstCaps *new = NULL; - - if (gst_bytestream_peek (bs, &buf, 134) == 134) { - guint8 *data = GST_BUFFER_DATA (buf); - - /* check magic */ - if ((data[4] == 0x11 || data[4] == 0x12 || - data[4] == 0x30 || data[4] == 0x44) && - data[5] == 0xaf) { - /* check the frame type of the first frame */ - if ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1) { - GST_DEBUG ("GstFlxDec: found supported flx format"); - new = gst_caps_new ("flxdec_type_find", - "video/x-fli", - NULL); - } - } - } - - if (buf != NULL) { - gst_buffer_unref (buf); - } - - return new; -} - - GType gst_flxdec_get_type(void) { @@ -688,7 +648,6 @@ static gboolean plugin_init (GModule *module, GstPlugin *plugin) { GstElementFactory *factory; - GstTypeFactory *type; factory = gst_element_factory_new("flxdec", GST_TYPE_FLXDEC, &flxdec_details); g_return_val_if_fail(factory != NULL, FALSE); @@ -699,9 +658,6 @@ plugin_init (GModule *module, GstPlugin *plugin) gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); - type = gst_type_factory_new (&flxdec_definition); - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type)); - return TRUE; } diff --git a/gst/flx/gstflxdec.h b/gst/flx/gstflxdec.h index 0ee4b1c5b..be4fa4ba0 100644 --- a/gst/flx/gstflxdec.h +++ b/gst/flx/gstflxdec.h @@ -23,7 +23,7 @@ #include #include "flx_color.h" -#include +#include #ifdef __cplusplus diff --git a/gst/mixmatrix/mixmatrix.c b/gst/mixmatrix/mixmatrix.c index a795a6f5e..5e9ebe53f 100644 --- a/gst/mixmatrix/mixmatrix.c +++ b/gst/mixmatrix/mixmatrix.c @@ -22,7 +22,7 @@ #endif #include #include -#include +#include #include #include diff --git a/gst/modplug/Makefile.am b/gst/modplug/Makefile.am index 52d9d4084..ffbc56b07 100644 --- a/gst/modplug/Makefile.am +++ b/gst/modplug/Makefile.am @@ -2,9 +2,9 @@ SUBDIRS=libmodplug . plugin_LTLIBRARIES = libgstmodplug.la -libgstmodplug_la_SOURCES = modplug_types.cc gstmodplug.cc +libgstmodplug_la_SOURCES = gstmodplug.cc libgstmodplug_la_CXXFLAGS = $(GST_CFLAGS) libgstmodplug_la_LIBADD = $(top_builddir)/gst/modplug/libmodplug/libmodplug.la libgstmodplug_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -noinst_HEADERS = gstmodplug.h modplug_types.h +noinst_HEADERS = gstmodplug.h diff --git a/gst/modplug/gstmodplug.cc b/gst/modplug/gstmodplug.cc index 0401a6c64..c8d2555bd 100644 --- a/gst/modplug/gstmodplug.cc +++ b/gst/modplug/gstmodplug.cc @@ -129,50 +129,6 @@ static GstElementStateReturn static GstElementClass *parent_class = NULL; -static GstCaps* -modplug_type_find (GstByteStream *bs, gpointer priv) -{ - GstBuffer *buf = NULL; - GstCaps *newc = NULL; - - if (gst_bytestream_peek (bs, &buf, 75) == 75) { - if (MOD_CheckType (buf) || - Mod_669_CheckType (buf) || - Amf_CheckType (buf) || - Dsm_CheckType (buf) || - Fam_CheckType (buf) || - Gdm_CheckType (buf) || - Imf_CheckType (buf) || - It_CheckType (buf) || - M15_CheckType (buf) || -#if 0 - Med_CheckType (buf) || /* FIXME */ -#endif - Mtm_CheckType (buf) || - Okt_CheckType (buf) || - S3m_CheckType (buf) || - Xm_CheckType (buf)) { - newc = GST_CAPS_NEW ("modplug_type_find", - "audio/x-mod", - NULL); - } - } - - if (buf != NULL) { - gst_buffer_unref (buf); - } - - return newc; -} - -static GstTypeDefinition modplug_definitions[] = { - { "modplug_audio/mod", "audio/x-mod", - ".mod .sam .med .stm .mtm .669 .ult .far .amf " - ".dsm .imf .gdm .stx .okt .xm .it .s3m", - modplug_type_find }, - { NULL, NULL, NULL, NULL } -}; - GType gst_modplug_get_type(void) { static GType modplug_type = 0; @@ -858,12 +814,12 @@ gst_modplug_get_property (GObject *object, guint id, GValue *value, GParamSpec * static gboolean plugin_init (GModule *module, GstPlugin *plugin) { - GstElementFactory *factory; - guint i; + GstElementFactory *factory; + guint i; /* this filter needs the bytestream package */ -/* if (!gst_library_load ("gstbytestream")) - return FALSE;*/ + if (!gst_library_load ("gstbytestream")) + return FALSE; factory = gst_element_factory_new ("modplug", GST_TYPE_MODPLUG, &modplug_details); g_return_val_if_fail (factory != NULL, FALSE); @@ -874,13 +830,6 @@ plugin_init (GModule *module, GstPlugin *plugin) gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (modplug_src_template_factory)); i = 0; - while (modplug_definitions[i].name) { - GstTypeFactory *type; - - type = gst_type_factory_new (&modplug_definitions[i]); - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type)); - i++; - } gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); diff --git a/gst/modplug/gstmodplug.h b/gst/modplug/gstmodplug.h index dcdbf0628..86f815e37 100644 --- a/gst/modplug/gstmodplug.h +++ b/gst/modplug/gstmodplug.h @@ -28,10 +28,8 @@ extern "C" { #endif /* __cplusplus */ #include -#include +#include -#include "modplug_types.h" - #define GST_TYPE_MODPLUG \ (gst_modplug_get_type()) diff --git a/gst/modplug/modplug_types.cc b/gst/modplug/modplug_types.cc deleted file mode 100644 index a6ca7874f..000000000 --- a/gst/modplug/modplug_types.cc +++ /dev/null @@ -1,221 +0,0 @@ -/* GStreamer - * Copyright (C) <1999> Erik Walthinsen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include -#include /* memcmp */ -#include /* isdigit */ - -#include "modplug_types.h" - -#define MODULEHEADERSIZE 0x438 - - -gboolean MOD_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ) + MODULEHEADERSIZE; - - /* Protracker and variants */ - if (( ! memcmp( data, "M.K.", 4 )) || ( ! memcmp( data, "M!K!", 4 ))) - return TRUE; - - /* Star Tracker */ - if ((( ! memcmp( data, "FLT", 3 )) || ( ! memcmp( data, "EXO", 3 ))) && ( isdigit( data[3] ))) - return TRUE; - - /* Oktalyzer (Amiga) */ - if (! memcmp( data, "OKTA", 4 )) - return TRUE; - - /* Oktalyser (Atari) */ - if ( ! memcmp( data, "CD81", 4 )) - return TRUE; - - /* Fasttracker */ - if (( ! memcmp( data + 1, "CHN", 3 )) && ( isdigit( data[0] ))) - return TRUE; - - /* Fasttracker or Taketracker */ - if ((( ! memcmp( data + 2, "CH", 2 )) || ( ! memcmp( data + 2, "CN", 2 ))) && ( isdigit( data[0] )) && ( isdigit( data[1] ))) - return TRUE; - - return FALSE; -} - -gboolean Mod_669_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "if", 2 ) || ! memcmp( data, "JN", 2 )) - return TRUE; - - return FALSE; -} - -gboolean Amf_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ); - - if( memcmp( data, "AMF", 3) ) - return FALSE; - - data = GST_BUFFER_DATA( buf ) + 3; - - if (( (gint)*data >= 10 ) && ( (gint)*data <= 14 )) - return TRUE; - - return FALSE; -} - -gboolean Dsm_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "RIFF", 4 ) && ! memcmp( data + 8, "DSMF", 4 )) - return TRUE; - - return FALSE; -} - -gboolean Fam_CheckType( GstBuffer *buf ) -{ -guint8 *data; -static unsigned char FARSIG[4+3]={'F','A','R',0xfe,13,10,26}; - - data = GST_BUFFER_DATA( buf ); - - if(( memcmp( data, FARSIG, 4 )) || ( memcmp( data + 44, FARSIG + 4, 3 ))) - return FALSE; - - return 1; -} - -gboolean Gdm_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ); - - if ( ! memcmp( data, "GDM\xfe", 4 ) && ! memcmp( data + 71, "GMFS", 4 )) - return TRUE; - - return FALSE; -} - -gboolean Imf_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ) + 0x3c; - - if( ! memcmp( data, "IM10", 4)) - return TRUE; - - return FALSE; -} - -gboolean It_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "IMPM", 4 )) - return TRUE; - - return FALSE; -} - -gboolean M15_CheckType( GstBuffer *buf ) -{ - /* FIXME: M15 CheckType to do */ - return FALSE; -} - -gboolean Med_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ); - - if(( ! memcmp(data, "MMD0", 4 )) || ( memcmp( data, "MMD1", 4 ))) - return TRUE; - - return FALSE; -} - -gboolean Mtm_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "MTM", 3 )) - return TRUE; - - return FALSE; -} - -gboolean Okt_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "OKTSONG", 8 )) - return TRUE; - - return FALSE; -} - -gboolean S3m_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ) + 0x2c; - - if( ! memcmp( data, "SCRM", 4 )) - return TRUE; - - return FALSE; -} - -gboolean Xm_CheckType( GstBuffer *buf ) -{ -guint8 *data; - - data = GST_BUFFER_DATA( buf ); - - if( memcmp( data, "Extended Module: ", 17 )) - return FALSE; - - if( data[ 37 ] == 0x1a ) - return TRUE; - - return FALSE; -} - - diff --git a/gst/modplug/modplug_types.h b/gst/modplug/modplug_types.h deleted file mode 100644 index 63b5a08cb..000000000 --- a/gst/modplug/modplug_types.h +++ /dev/null @@ -1,44 +0,0 @@ -/* GStreamer - * Copyright (C) <1999> Erik Walthinsen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __MODPLUG_TYPES_H__ -#define __MODPLUG_TYPES_H__ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -gboolean MOD_CheckType (GstBuffer *buf); -gboolean Mod_669_CheckType (GstBuffer *buf); -gboolean Amf_CheckType (GstBuffer *buf); -gboolean Dsm_CheckType (GstBuffer *buf); -gboolean Fam_CheckType (GstBuffer *buf); -gboolean Gdm_CheckType (GstBuffer *buf); -gboolean Imf_CheckType (GstBuffer *buf); -gboolean It_CheckType (GstBuffer *buf); -gboolean M15_CheckType (GstBuffer *buf); -gboolean Mtm_CheckType (GstBuffer *buf); -gboolean Okt_CheckType (GstBuffer *buf); -gboolean S3m_CheckType (GstBuffer *buf); -gboolean Xm_CheckType (GstBuffer *buf); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __MODPLUG_TYPES_H__ */ diff --git a/gst/mpegaudioparse/gstmp3types.c b/gst/mpegaudioparse/gstmp3types.c new file mode 100644 index 000000000..af2f49146 --- /dev/null +++ b/gst/mpegaudioparse/gstmp3types.c @@ -0,0 +1,254 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/*#define DEBUG_ENABLED */ +#include +#include /* memcmp */ + +static GstCaps* mp3_type_find(GstBuffer *buf, gpointer private); +static GstCaps* mp3_type_find_stream(GstBuffer *buf, gpointer private); + +static GstTypeDefinition mp3type_definitions[] = { + { "mp3types_audio/mpeg", "audio/mpeg", ".mp3 .mp2 .mp1 .mpga", mp3_type_find }, + { "mp3types_stream_audio/mpeg", "audio/mpeg", ".mp3 .mp2 .mp1 .mpga", mp3_type_find_stream }, + { NULL, NULL, NULL, NULL }, +}; + +static GstCaps* +mp3_type_find(GstBuffer *buf, gpointer private) +{ + guint8 *data; + gint size, layer; + guint32 head; + GstCaps *caps; + + data = GST_BUFFER_DATA (buf); + size = GST_BUFFER_SIZE (buf); + + GST_DEBUG ("mp3typefind: typefind"); + + /* gracefully ripped from libid3 */ + if (size >= 3 && + data[0] == 'T' && data[1] == 'A' && data[2] == 'G') { + /* ID V1 tags */ + data += 128; + size -= 128; + + GST_DEBUG ("mp3typefind: detected ID3 Tag V1"); + } else if (size >= 10 && + (data[0] == 'I' && data[1] == 'D' && data[2] == '3') && + data[3] < 0xff && data[4] < 0xff && + data[6] < 0x80 && data[7] < 0x80 && data[8] < 0x80 && data[9] < 0x80) + { + guint32 skip = 0; + + skip = (skip << 7) | (data[6] & 0x7f); + skip = (skip << 7) | (data[7] & 0x7f); + skip = (skip << 7) | (data[8] & 0x7f); + skip = (skip << 7) | (data[9] & 0x7f); + + /* include size of header */ + skip += 10; + /* footer present? (only available since version 4) */ + if (data[3] > 3 && (data[5] & 0x10)) + skip += 10; + + GST_DEBUG ("mp3typefind: detected ID3 Tag V2 with %u bytes", skip); + size -= skip; + data += skip; + } + + if (size < 4) + return NULL; + + /* now with the right postion, do typefinding */ + head = GUINT32_FROM_BE(*((guint32 *)data)); + if ((head & 0xffe00000) != 0xffe00000) + return NULL; + if (!(layer = ((head >> 17) & 3))) + return NULL; + layer = 4 - layer; + if (((head >> 12) & 0xf) == 0xf) + return NULL; + if (!((head >> 12) & 0xf)) + return NULL; + if (((head >> 10) & 0x3) == 0x3) + return NULL; + + caps = GST_CAPS_NEW ("mp3_type_find", "audio/mpeg", "layer", GST_PROPS_INT (layer)); + + return caps; +} +static guint mp3types_bitrates[2][3][16] = +{ { {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, }, + {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, }, + {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, } }, + { {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, }, + {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, }, + {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, } }, +}; +static guint mp3types_freqs[3][3] = +{ {44100, 48000, 32000}, + {22050, 24000, 16000}, + {11025, 12000, 8000}}; +static inline guint +mp3_type_frame_length_from_header (guint32 header, guint *put_layer) +{ + guint length; + gulong samplerate, bitrate, layer, version; + + /* we don't need extension, mode, copyright, original or emphasis for the frame length */ + header >>= 9; + /* padding */ + length = header & 0x1; + header >>= 1; + /* sampling frequency */ + samplerate = header & 0x3; + if (samplerate == 3) + return 0; + header >>= 2; + /* bitrate index */ + bitrate = header & 0xF; + if (bitrate == 15 || bitrate == 0) + return 0; + /* ignore error correction, too */ + header >>= 5; + /* layer */ + layer = 4 - (header & 0x3); + if (layer == 4) + return 0; + header >>= 2; + /* version */ + version = header & 0x3; + if (version == 1) + return 0; + /* lookup */ + bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate]; + samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate]; + /* calculating */ + if (layer == 1) { + length = ((12000 * bitrate / samplerate) + length) * 4; + } else { + length += ((layer == 3 && version == 0) ? 144000 : 72000) * bitrate / samplerate; + } + + GST_DEBUG ("Calculated mad frame length of %u bytes", length); + GST_DEBUG ("samplerate = %lu - bitrate = %lu - layer = %lu - version = %lu", samplerate, bitrate, layer, version); + if (put_layer) + *put_layer = layer; + return length; +} +/* increase this value when this function finds too many false positives */ +/** + * The chance that random data is identified as a valid mp3 header is 63 / 2^18 + * (0.024%) per try. This makes the function for calculating false positives + * 1 - (1 - ((63 / 2 ^18) ^ GST_MP3_TYPEFIND_MIN_HEADERS)) ^ buffersize) + * This has the following probabilities of false positives: + * bufsize MIN_HEADERS + * (bytes) 1 2 3 4 + * 4096 62.6% 0.02% 0% 0% + * 16384 98% 0.09% 0% 0% + * 1 MiB 100% 5.88% 0% 0% + * 1 GiB 100% 100% 1.44% 0% + * 1 TiB 100% 100% 100% 0.35% + * This means that the current choice (3 headers by most of the time 4096 byte + * buffers is pretty safe for now. + * It is however important to note that in a worst case example a buffer of size + * 1440 * GST_MP3_TYPEFIND_MIN_HEADERS + 3 + * bytes is needed to reliable find the mp3 stream in a buffer when scanning + * starts at a random position. This is currently (4323 bytes) slightly above + * the default buffer size. But you rarely hit the worst case - average mp3 + * frames are in the 500 bytes range. + */ +#define GST_MP3_TYPEFIND_MIN_HEADERS 3 +static GstCaps* +mp3_type_find_stream (GstBuffer *buf, gpointer private) +{ + guint8 *data; + guint size; + guint32 head; + gint layer = 0; + + data = GST_BUFFER_DATA (buf); + size = GST_BUFFER_SIZE (buf); + + while (size >= 4) { + head = GUINT32_FROM_BE(*((guint32 *)data)); + if ((head & 0xffe00000) == 0xffe00000) { + guint length; + guint prev_layer = 0; + guint found = 0; /* number of valid headers found */ + guint pos = 0; + do { + if ((length = mp3_type_frame_length_from_header (head, &layer))) { + if (prev_layer && prev_layer != layer) + break; + prev_layer = layer; + pos += length; + found++; + if (pos + 4 >= size) { + if (found >= GST_MP3_TYPEFIND_MIN_HEADERS) { + goto success; + } else { + break; + } + } + head = GUINT32_FROM_BE(*((guint32 *) &(data[pos]))); + if ((head & 0xffe00000) != 0xffe00000) + break; + } else { + break; + } + } while (TRUE); + } + data++; + size--; + } + + return NULL; + +success: + g_assert (layer); + return GST_CAPS_NEW ("mp3_type_find", "audio/mpeg", "layer", GST_PROPS_INT (layer)); +} + +static gboolean +plugin_init (GModule *module, GstPlugin *plugin) +{ + gint i=0; + + while (mp3type_definitions[i].name) { + GstTypeFactory *type; + + type = gst_type_factory_new (&mp3type_definitions[i]); + gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type)); + i++; + } + + /* gst_info("gsttypes: loaded %d mp3 types\n",i); */ + + return TRUE; +} + +GstPluginDesc plugin_desc = { + GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mp3types", + plugin_init +}; diff --git a/gst/mpegaudioparse/gstmpegaudioparse.c b/gst/mpegaudioparse/gstmpegaudioparse.c index b0a308065..a4d7a8492 100644 --- a/gst/mpegaudioparse/gstmpegaudioparse.c +++ b/gst/mpegaudioparse/gstmpegaudioparse.c @@ -35,15 +35,6 @@ static GstElementDetails mp3parse_details = { "(C) 1999", }; -static GstCaps * mp3_type_find (GstByteStream *bs, gpointer data); - -static GstTypeDefinition mp3type_definition = { - "mp3_audio/mpeg", - "audio/mpeg", - ".mp3 .mp2 .mp1 .mpga", - mp3_type_find, -}; - static GstPadTemplate* mp3_src_factory (void) { @@ -267,78 +258,6 @@ mp3_caps_create (guint layer, guint channels, return new; } -static GstCaps * -mp3_type_find (GstByteStream *bs, gpointer private) -{ - GstBuffer *buf = NULL; - GstCaps *new = NULL; - guint8 *data; - guint size; - guint32 head; - guint layer = 0, bitrate = 0, samplerate = 0, channels = 0; - - /* note that even if we don't get the requested size, - * it might still be a (very small) mp3 */ - gst_bytestream_peek (bs, &buf, GST_MP3_TYPEFIND_MIN_DATA); - if (!buf) { - goto done; - } - - data = GST_BUFFER_DATA (buf); - size = GST_BUFFER_SIZE (buf); - - while (size >= 4) { - head = GUINT32_FROM_BE(*((guint32 *)data)); - if ((head & 0xffe00000) == 0xffe00000) { - guint length; - guint prev_layer = 0, prev_bitrate = 0, - prev_channels = 0, prev_samplerate = 0; - guint found = 0; /* number of valid headers found */ - guint pos = 0; - - do { - if (!(length = mp3_type_frame_length_from_header (head, &layer, - &channels, &bitrate, - &samplerate))) { - break; - } - if ((prev_layer && prev_layer != layer) || !layer || - (prev_bitrate && prev_bitrate != bitrate) || !bitrate || - (prev_samplerate && prev_samplerate != samplerate) || !samplerate || - (prev_channels && prev_channels != channels) || !channels) { - /* this means an invalid property, or a change, which likely - * indicates that this is not a mp3 but just a random bytestream */ - break; - } - prev_layer = layer; - prev_bitrate = bitrate; - prev_channels = channels; - prev_samplerate = samplerate; - pos += length; - if (++found >= GST_MP3_TYPEFIND_MIN_HEADERS) { - /* we're pretty sure that this is mp3 now */ - new = mp3_caps_create (layer, channels, bitrate, samplerate); - goto done; - } - - /* and now, find a new head */ - head = GUINT32_FROM_BE(*((guint32 *) &(data[pos]))); - if ((head & 0xffe00000) != 0xffe00000) - break; - } while (TRUE); - } - data++; - size--; - } - -done: - if (buf != NULL) { - gst_buffer_unref (buf); - } - - return new; -} - static void gst_mp3parse_class_init (GstMPEGAudioParseClass *klass) { @@ -658,7 +577,6 @@ static gboolean plugin_init (GModule *module, GstPlugin *plugin) { GstElementFactory *factory; - GstTypeFactory *type; /* create an elementfactory for the mp3parse element */ factory = gst_element_factory_new ("mp3parse", @@ -674,10 +592,6 @@ plugin_init (GModule *module, GstPlugin *plugin) gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); - /* type finding */ - type = gst_type_factory_new (&mp3type_definition); - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type)); - return TRUE; } diff --git a/gst/qtdemux/qtdemux.c b/gst/qtdemux/qtdemux.c index dfd4b2c50..c3cb63fb7 100644 --- a/gst/qtdemux/qtdemux.c +++ b/gst/qtdemux/qtdemux.c @@ -104,15 +104,6 @@ gst_qtdemux_details = "(C) 2003", }; -static GstCaps* quicktime_type_find (GstByteStream *bs, gpointer private); - -static GstTypeDefinition quicktimedefinition = { - "qtdemux_video/quicktime", - "video/quicktime", - ".mov", - quicktime_type_find, -}; - enum { LAST_SIGNAL }; @@ -186,37 +177,10 @@ gst_qtdemux_init (GstQTDemux *qtdemux) gst_element_add_pad (GST_ELEMENT (qtdemux), qtdemux->sinkpad); } -static GstCaps* -quicktime_type_find (GstByteStream *bs, gpointer private) -{ - GstBuffer *buf = NULL; - GstCaps *new = NULL; - - if (gst_bytestream_peek (bs, &buf, 8) == 8) { - gchar *data = GST_BUFFER_DATA (buf); - - if (!strncmp (&data[4], "wide", 4) || - !strncmp (&data[4], "moov", 4) || - !strncmp (&data[4], "mdat", 4) || - !strncmp (&data[4], "free", 4)) { - new = GST_CAPS_NEW ("quicktime_type_find", - "video/quicktime", - NULL); - } - } - - if (buf != NULL) { - gst_buffer_unref (buf); - } - - return new; -} - static gboolean plugin_init (GModule *module, GstPlugin *plugin) { GstElementFactory *factory; - GstTypeFactory *type; GstCaps *audiocaps = NULL, *videocaps = NULL, *temp; const guint32 audio_fcc[] = { /* FILLME */ @@ -254,9 +218,6 @@ plugin_init (GModule *module, GstPlugin *plugin) gst_element_factory_add_pad_template (factory, videosrctempl); gst_element_factory_add_pad_template (factory, audiosrctempl); - type = gst_type_factory_new (&quicktimedefinition); - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type)); - gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); return TRUE; diff --git a/gst/qtdemux/qtdemux.h b/gst/qtdemux/qtdemux.h index 46684be89..c005a96ec 100644 --- a/gst/qtdemux/qtdemux.h +++ b/gst/qtdemux/qtdemux.h @@ -22,7 +22,7 @@ #define __GST_QTDEMUX_H__ #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/gst/rtjpeg/gstrtjpeg.c b/gst/rtjpeg/gstrtjpeg.c index c88428824..4284b8ddc 100644 --- a/gst/rtjpeg/gstrtjpeg.c +++ b/gst/rtjpeg/gstrtjpeg.c @@ -25,13 +25,6 @@ extern GstElementDetails gst_rtjpegenc_details; extern GstElementDetails gst_rtjpegdec_details; -GstTypeDefinition rtjpegdefinition = { - "rtjpeg_video/rtjpeg", - "video/x-rtjpeg", - ".rtj", - NULL, -}; - static gboolean plugin_init (GModule *module, GstPlugin *plugin) { -- cgit v1.2.1