Commit d9e4457f authored by Ronald S. Bultje's avatar Ronald S. Bultje

New typefind system: bytestream is now part of the core all plugins have been...

New typefind system: bytestream is now part of the core all plugins have been modified to use this new typefind syste...

Original commit message from CVS:
New typefind system:
* bytestream is now part of the core
* all plugins have been modified to use this new typefind system
* asf typefinding added
* mpeg video stream typefiding removed because it's broken
* duplicate typefind entries removed
* extra id3 typefinding added, because we've seen 4 types of files
(riff/wav, flac, vorbis, mp3) with id3 headers and each of these needs
to work. Instead, I've added an id3 element and let it redo typefiding
after the id3 header. this needs a hack because spider only typefinds
once. We can remove this hack once spider supports multiple typefinds.
* with all this, mp3 typefinding is semi-rewritten
* id3 typefinding in flac/vorbis is removed, it's no longer needed
* fixed spider and gst-typefind to use this, too.
* Other general cleanups
parent b569848e
......@@ -262,7 +262,7 @@ GST_PLUGINS_ALL="\
ac3parse adder audioscale auparse avi \
asfdemux audioconvert cdxaparse chart \
cutter debug deinterlace effectv festival \
filter flx goom intfloat law level median mixmatrix \
filter flx goom id3 intfloat law level median mixmatrix \
mpeg1sys mpeg1videoparse mpeg2enc mpeg2sub \
mpegaudio mpegaudioparse mpegstream mpegtypes \
monoscope oneton overlay passthrough playondemand qtdemux \
......@@ -1180,6 +1180,7 @@ gst/festival/Makefile
gst/filter/Makefile
gst/flx/Makefile
gst/goom/Makefile
gst/id3/Makefile
gst/intfloat/Makefile
gst/law/Makefile
gst/level/Makefile
......
......@@ -278,8 +278,9 @@ SUBDIRS=$(A52DEC_DIR) $(AALIB_DIR) $(ALSA_DIR) \
$(ARTS_DIR) $(ARTSC_DIR) $(AUDIOFILE_DIR) \
$(CDPARANOIA_DIR) $(DIVX_DIR) \
$(DVDREAD_DIR) $(DVDNAV_DIR) $(ESD_DIR) $(MAS_DIR) \
$(FFMPEG_DIR) $(FLAC_DIR) $(GDK_PIXBUF_DIR) $(GNOMEVFS_DIR) $(GSM_DIR) \
$(HERMES_DIR) $(JACK_DIR) $(JPEG_DIR) \
$(FFMPEG_DIR) $(FLAC_DIR) $(GDK_PIXBUF_DIR) \
$(GNOMEVFS_DIR) $(GSM_DIR) $(HERMES_DIR) \
$(JACK_DIR) $(JPEG_DIR) \
$(LADSPA_DIR) $(LAME_DIR) $(LCS_DIR) \
$(LIBDV_DIR) $(LIBFAME_DIR) $(LIBPNG_DIR) \
$(MAD_DIR) $(MATROSKA_DIR) $(MIKMOD_DIR) \
......
......@@ -337,8 +337,7 @@ gst_afparse_plugin_init (GModule *module, GstPlugin *plugin)
/* load audio support library */
if (!gst_library_load ("gstaudio"))
return FALSE;
if (!gst_library_load ("gstbytestream"))
return FALSE;
return TRUE;
}
......
......@@ -27,7 +27,7 @@
#include <config.h>
#include <gst/gst.h>
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
#include <audiofile.h> /* what else are we to do */
#include <af_vfs.h>
......
......@@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
extern GType ivorbisfile_get_type(void);
......@@ -132,10 +132,6 @@ plugin_init (GModule *module, GstPlugin *plugin)
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (file));
/* this filter needs the bytestream package */
if (!gst_library_load ("gstbytestream"))
return FALSE;
type = gst_type_factory_new (&vorbisdefinition);
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
......
......@@ -24,7 +24,7 @@
#include <gst/gst.h>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
#define GST_TYPE_IVORBISFILE \
(ivorbisfile_get_type())
......
......@@ -22,7 +22,7 @@
#include <jack/jack.h>
#include <gst/gst.h>
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
//#define JACK_DEBUG(str, a...) g_message (str, ##a)
#define JACK_DEBUG(str, a...)
......
......@@ -993,9 +993,6 @@ plugin_init (GModule *module, GstPlugin *plugin)
LADSPAPluginSearch(ladspa_describe_plugin);
if (! gst_library_load ("gstbytestream"))
return FALSE;
/* initialize dparam support library */
gst_control_init(NULL,NULL);
......
......@@ -26,7 +26,7 @@
#include <config.h>
#include <gst/gst.h>
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
#include "ladspa.h"
......
......@@ -26,7 +26,7 @@
#include <stdlib.h>
#include <gst/gst.h>
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
#include "outputstream.hh"
#include "bits.hh"
......
......@@ -50,7 +50,7 @@ static GstElementDetails gst_cdxa_parse_details = {
"(C) 2002",
};
static GstCaps* cdxa_type_find (GstBuffer *buf, gpointer private);
static GstCaps* cdxa_type_find (GstByteStream *bs, gpointer private);
/* typefactory for 'cdxa' */
static GstTypeDefinition cdxadefinition = {
......@@ -159,25 +159,28 @@ gst_cdxa_parse_init (GstCDXAParse *cdxa_parse)
}
static GstCaps*
cdxa_type_find (GstBuffer *buf,
gpointer private)
cdxa_type_find (GstByteStream *bs,
gpointer private)
{
gchar *data = GST_BUFFER_DATA (buf);
GstCaps *new;
GstBuffer *buf = NULL;
GstCaps *new = NULL;
GST_DEBUG ("cdxa_parse: typefind");
if (GST_BUFFER_SIZE (buf) < 12)
return NULL;
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 (GUINT32_FROM_LE (((guint32 *)data)[0]) != GST_RIFF_TAG_RIFF)
return NULL;
if (GUINT32_FROM_LE (((guint32 *)data)[2]) != GST_RIFF_RIFF_CDXA)
return NULL;
if (head1 == GST_RIFF_TAG_RIFF && head2 == GST_RIFF_RIFF_CDXA) {
new = GST_CAPS_NEW ("cdxa_type_find",
"video/x-cdxa",
NULL);
}
}
new = GST_CAPS_NEW ("cdxa_type_find",
"video/x-cdxa",
NULL);
if (buf != NULL) {
gst_buffer_unref (buf);
}
return new;
}
......@@ -342,10 +345,6 @@ plugin_init (GModule *module, GstPlugin *plugin)
GstElementFactory *factory;
GstTypeFactory *type;
/* this filter needs the riff parser */
if (!gst_library_load ("gstbytestream"))
return FALSE;
/* create an elementfactory for the cdxa_parse element */
factory = gst_element_factory_new ("cdxaparse", GST_TYPE_CDXA_PARSE,
&gst_cdxa_parse_details);
......
......@@ -24,7 +24,7 @@
#include <config.h>
#include <gst/gst.h>
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
#ifdef __cplusplus
extern "C" {
......
......@@ -80,7 +80,7 @@
static void gst_festival_class_init (GstFestivalClass *klass);
static void gst_festival_init (GstFestival *festival);
static GstCaps* text_type_find (GstBuffer *buf, gpointer private);
static GstCaps* text_type_find (GstByteStream *bs, gpointer private);
static void gst_festival_chain (GstPad *pad, GstBuffer *buf);
static GstElementStateReturn
......@@ -198,21 +198,35 @@ gst_festival_init (GstFestival *festival)
}
static GstCaps*
text_type_find (GstBuffer *buf, gpointer private)
text_type_find (GstByteStream *bs, gpointer private)
{
gchar *data = GST_BUFFER_DATA (buf);
gint i;
GstBuffer *buf = NULL;
GstCaps *new = NULL;
/* 20 is arbitrary. 4 is definitely too small. */
if (GST_BUFFER_SIZE (buf) < 20)
return NULL;
#define TEXT_SIZE 32
for (i=0; i<GST_BUFFER_SIZE (buf); i++) {
if (!isprint(data[i]) && data[i]!='\n')
return NULL;
/* 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') {
break;
}
}
/* well, we found something that looks like text... */
new = gst_caps_new ("text_type_find",
"text/plain",
NULL);
}
if (buf != NULL) {
gst_buffer_unref (buf);
}
return gst_caps_new ("text_type_find", "text/plain", NULL);
return new;
}
......
......@@ -28,7 +28,7 @@
#define JIFFIE (GST_SECOND/70)
static GstCaps* flxdec_type_find(GstBuffer *buf, gpointer private);
static GstCaps* flxdec_type_find (GstByteStream *bs, gpointer private);
/* flx element information */
static GstElementDetails flxdec_details = {
......@@ -113,27 +113,33 @@ static void flx_decode_delta_flc (GstFlxDec *, guchar *, guchar *);
static GstElementClass *parent_class = NULL;
static GstCaps*
flxdec_type_find (GstBuffer *buf, gpointer private)
flxdec_type_find (GstByteStream *bs, gpointer private)
{
guchar *data = GST_BUFFER_DATA(buf);
GstCaps *new;
GstBuffer *buf = NULL;
GstCaps *new = NULL;
if (GST_BUFFER_SIZE(buf) < 134){
return 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 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);
return new;
new = gst_caps_new ("flxdec_type_find",
"video/x-fli",
NULL);
}
}
}
return NULL;
if (buf != NULL) {
gst_buffer_unref (buf);
}
return new;
}
......@@ -684,10 +690,6 @@ plugin_init (GModule *module, GstPlugin *plugin)
GstElementFactory *factory;
GstTypeFactory *type;
/* this filter needs the bytestream package */
if (!gst_library_load ("gstbytestream"))
return FALSE;
factory = gst_element_factory_new("flxdec", GST_TYPE_FLXDEC, &flxdec_details);
g_return_val_if_fail(factory != NULL, FALSE);
gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_PRIMARY);
......
......@@ -23,7 +23,7 @@
#include <gst/gst.h>
#include "flx_color.h"
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
#ifdef __cplusplus
......
......@@ -22,7 +22,7 @@
#endif
#include <config.h>
#include <gst/gst.h>
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
#include <gst/audio/audio.h>
#include <string.h>
......@@ -500,10 +500,6 @@ plugin_init (GModule *module, GstPlugin *plugin)
{
GstElementFactory *factory;
/* this filter needs the bytestream package */
if (!gst_library_load ("gstbytestream"))
return FALSE;
factory = gst_element_factory_new ("mixmatrix", GST_TYPE_MIXMATRIX,
&mixmatrix_details);
g_return_val_if_fail (factory != NULL, FALSE);
......
......@@ -130,31 +130,39 @@ static GstElementStateReturn
static GstElementClass *parent_class = NULL;
static GstCaps*
modplug_type_find (GstBuffer *buf, gpointer priv)
{
if (GST_BUFFER_SIZE (buf) < 75)
return NULL;
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) ||
/*Med_CheckType (buf) || <- FIXME */
Mtm_CheckType (buf) ||
Okt_CheckType (buf) ||
S3m_CheckType (buf) ||
Xm_CheckType (buf)) {
return gst_caps_new ("modplug_type_find",
"audio/x-mod",
NULL);
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);
}
}
return NULL;
if (buf != NULL) {
gst_buffer_unref (buf);
}
return newc;
}
static GstTypeDefinition modplug_definitions[] = {
......
......@@ -28,7 +28,7 @@ extern "C" {
#endif /* __cplusplus */
#include <gst/gst.h>
#include <gst/bytestream/bytestream.h>
#include <gst/gstbytestream.h>
#include "modplug_types.h"
......
#FIXME clean me up a bit
plugin_LTLIBRARIES = libgstmpegaudioparse.la libgstmp3types.la
plugin_LTLIBRARIES = libgstmpegaudioparse.la
libgstmpegaudioparse_la_SOURCES = gstmpegaudioparse.c
libgstmpegaudioparse_la_CFLAGS = $(GST_CFLAGS)
libgstmpegaudioparse_la_LIBADD =
libgstmpegaudioparse_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstmp3types_la_SOURCES = gstmp3types.c
libgstmp3types_la_CFLAGS = $(GST_CFLAGS)
libgstmp3types_la_LIBADD =
libgstmp3types_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstmpegaudioparse.h
EXTRA_DIST = README
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* 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 <gst/gst.h>
#include <string.h> /* 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;
}
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); */