Use bytestream to get buffer from sinkpad ( gst-player should play mod file now ;)

Original commit message from CVS:
Use bytestream to get buffer from sinkpad ( gst-player should play mod file now ;)
Move module types build from mikmod to modplug
This commit is contained in:
Jeremy Simon 2002-11-17 12:23:43 +00:00
parent 92b11a0a08
commit 8029993b12
5 changed files with 361 additions and 58 deletions

View file

@ -4,10 +4,10 @@ plugindir = $(libdir)/gst
plugin_LTLIBRARIES = libgstmodplug.la plugin_LTLIBRARIES = libgstmodplug.la
libgstmodplug_la_SOURCES = gstmodplug.cc libgstmodplug_la_SOURCES = gstmodplug.cc modplug_types.c
libgstmodplug_la_CXXFLAGS = $(GST_CFLAGS) libgstmodplug_la_CXXFLAGS = $(GST_CFLAGS)
libgstmodplug_la_LIBADD = libmodplug/libmodplug.la -lstdc++ libgstmodplug_la_LIBADD = libmodplug/libmodplug.la -lstdc++
libgstmodplug_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstmodplug_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstmodplug.h noinst_HEADERS = gstmodplug.h modplug_types.h

View file

@ -32,6 +32,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <stdlib.h> #include <stdlib.h>
#include <gst/audio/audio.h>
/* elementfactory information */ /* elementfactory information */
GstElementDetails modplug_details = { GstElementDetails modplug_details = {
@ -96,7 +97,7 @@ GST_PAD_TEMPLATE_FACTORY (modplug_sink_template_factory,
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_CAPS_NEW ( GST_CAPS_NEW (
"mad_sink", "modplug_sink",
"audio/mod", "audio/mod",
NULL NULL
) )
@ -136,6 +137,63 @@ gst_modplug_mixfreq_get_type (void)
} }
static GstCaps*
modplug_type_find (GstBuffer *buf, gpointer priv)
{
if ( MOD_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( Mod_669_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( Amf_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( Dsm_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( Fam_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( Gdm_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( Imf_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( It_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( M15_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
/* FIXME
if ( Med_CheckType( buf ) )
return gst_caps_new ("mikmod_type_find", "audio/mod", NULL);
*/
if ( Mtm_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( Okt_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( S3m_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
if ( Xm_CheckType( buf ) )
return gst_caps_new ("modplug_type_find", "audio/mod", NULL);
return NULL;
}
static GstTypeDefinition modplug_definition = {
"modplug_audio/mod", "audio/mod", ".mod .sam .med .s3m .it .xm .stm .mtm .669 .ult .far .amf .dsm .imf .gdm .stx .okt", modplug_type_find
};
GType GType
gst_modplug_get_type(void) { gst_modplug_get_type(void) {
static GType modplug_type = 0; static GType modplug_type = 0;
@ -237,17 +295,18 @@ static void
gst_modplug_init (GstModPlug *modplug) gst_modplug_init (GstModPlug *modplug)
{ {
modplug->sinkpad = gst_pad_new_from_template( GST_PAD_TEMPLATE_GET (modplug_sink_template_factory), "sink"); modplug->sinkpad = gst_pad_new_from_template( GST_PAD_TEMPLATE_GET (modplug_sink_template_factory), "sink");
modplug->srcpad = gst_pad_new_from_template( GST_PAD_TEMPLATE_GET (modplug_src_template_factory), "src");
gst_element_add_pad(GST_ELEMENT(modplug),modplug->sinkpad); gst_element_add_pad(GST_ELEMENT(modplug),modplug->sinkpad);
modplug->srcpad = gst_pad_new_from_template( GST_PAD_TEMPLATE_GET (modplug_src_template_factory), "src");
gst_element_add_pad(GST_ELEMENT(modplug),modplug->srcpad); gst_element_add_pad(GST_ELEMENT(modplug),modplug->srcpad);
modplug->bs = gst_bytestream_new (modplug->sinkpad);
gst_pad_set_event_function (modplug->srcpad, (GstPadEventFunction)GST_DEBUG_FUNCPTR(gst_modplug_src_event)); gst_pad_set_event_function (modplug->srcpad, (GstPadEventFunction)GST_DEBUG_FUNCPTR(gst_modplug_src_event));
gst_pad_set_query_function (modplug->srcpad, gst_modplug_src_query); gst_pad_set_query_function (modplug->srcpad, gst_modplug_src_query);
gst_element_set_loop_function (GST_ELEMENT (modplug), gst_modplug_loop); gst_element_set_loop_function (GST_ELEMENT (modplug), gst_modplug_loop);
modplug->Buffer = NULL;
modplug->reverb = FALSE; modplug->reverb = FALSE;
modplug->reverb_depth = 30; modplug->reverb_depth = 30;
modplug->reverb_delay = 100; modplug->reverb_delay = 100;
@ -373,7 +432,7 @@ static void
gst_modplug_loop (GstElement *element) gst_modplug_loop (GstElement *element)
{ {
GstModPlug *modplug; GstModPlug *modplug;
GstBuffer *buffer_in, *buffer_out; GstBuffer *buffer_out;
gint mode16bits; gint mode16bits;
guint64 total_samples, sync_point; guint64 total_samples, sync_point;
float temp; float temp;
@ -383,39 +442,10 @@ gst_modplug_loop (GstElement *element)
modplug = GST_MODPLUG (element); modplug = GST_MODPLUG (element);
srcpad = modplug->srcpad; srcpad = modplug->srcpad;
while ((buffer_in = gst_pad_pull( modplug->sinkpad ))) { modplug->buffer_in = (guint8 *) g_malloc( gst_bytestream_length (modplug->bs));
if ( GST_IS_EVENT (buffer_in) ) { gst_bytestream_peek_bytes (modplug->bs, &modplug->buffer_in, gst_bytestream_length (modplug->bs));
GstEvent *event = GST_EVENT (buffer_in);
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
gst_event_unref (event);
break;
}
gst_event_unref (event);
}
else
{
if ( modplug->Buffer ) {
GstBuffer *merge;
merge = gst_buffer_merge( modplug->Buffer, buffer_in );
gst_buffer_unref( buffer_in );
gst_buffer_unref( modplug->Buffer );
modplug->Buffer = merge;
}
else {
modplug->Buffer = buffer_in;
}
}
}
if ( modplug->Buffer == NULL) {
gst_pad_push (modplug->srcpad, GST_BUFFER (gst_event_new (GST_EVENT_EOS)));
gst_element_set_eos (GST_ELEMENT (modplug));
return;
}
if ( modplug->_16bit ) if ( modplug->_16bit )
mode16bits = 16; mode16bits = 16;
@ -425,11 +455,8 @@ gst_modplug_loop (GstElement *element)
gst_modplug_setup( modplug ); gst_modplug_setup( modplug );
modplug->mSoundFile = new CSoundFile; modplug->mSoundFile = new CSoundFile;
modplug->mSoundFile->Create( GST_BUFFER_DATA( modplug->Buffer ), GST_BUFFER_SIZE( modplug->Buffer )); modplug->mSoundFile->Create( modplug->buffer_in, gst_bytestream_length (modplug->bs));
gst_buffer_unref( modplug->Buffer );
modplug->Buffer = NULL;
gst_pad_try_set_caps (modplug->srcpad, gst_pad_try_set_caps (modplug->srcpad,
GST_CAPS_NEW ( GST_CAPS_NEW (
"modplug_src", "modplug_src",
@ -451,9 +478,9 @@ gst_modplug_loop (GstElement *element)
modplug->audiobuffer = (guchar *) g_malloc( modplug->length ); modplug->audiobuffer = (guchar *) g_malloc( modplug->length );
total_samples = 0; total_samples = 0;
sync_point = 0; sync_point = 0;
do { do {
if ( modplug->seek_at != 0 ) if ( modplug->seek_at != -1 )
{ {
int seek_to_pos; int seek_to_pos;
gint64 total; gint64 total;
@ -469,19 +496,19 @@ gst_modplug_loop (GstElement *element)
if( modplug->mSoundFile->Read ( modplug->audiobuffer, modplug->length ) != 0 ) if( modplug->mSoundFile->Read ( modplug->audiobuffer, modplug->length ) != 0 )
{ {
GstClockTime time; GstClockTime time;
buffer_out = gst_buffer_new(); buffer_out = gst_buffer_new();
GST_BUFFER_DATA( buffer_out ) = (guchar *) g_memdup( modplug->audiobuffer, modplug->length ); GST_BUFFER_DATA( buffer_out ) = (guchar *) g_memdup( modplug->audiobuffer, modplug->length );
GST_BUFFER_SIZE( buffer_out ) = modplug->length; GST_BUFFER_SIZE( buffer_out ) = modplug->length;
total_samples+=1152; total_samples+=1152;
if ( modplug->seek_at != 0 ) if ( modplug->seek_at != -1)
{ {
GstEvent *discont; GstEvent *discont;
gint64 total; gint64 total;
modplug->seek_at = 0; modplug->seek_at = -1;
/* get stream stats */ /* get stream stats */
total = modplug->mSoundFile->GetSongTime() * GST_SECOND; total = modplug->mSoundFile->GetSongTime() * GST_SECOND;
@ -519,21 +546,21 @@ gst_modplug_change_state (GstElement *element)
switch (GST_STATE_TRANSITION (element)) { switch (GST_STATE_TRANSITION (element)) {
case GST_STATE_NULL_TO_READY: case GST_STATE_NULL_TO_READY:
// modplug->mSoundFile = new CSoundFile;
break; break;
case GST_STATE_READY_TO_PAUSED: case GST_STATE_READY_TO_PAUSED:
break; break;
case GST_STATE_PAUSED_TO_PLAYING: case GST_STATE_PAUSED_TO_PLAYING:
modplug->Buffer = NULL;
break; break;
case GST_STATE_PLAYING_TO_PAUSED: case GST_STATE_PLAYING_TO_PAUSED:
break; break;
case GST_STATE_PAUSED_TO_READY: case GST_STATE_PAUSED_TO_READY:
// modplug->mSoundFile->SetCurrentPos( 0 ); /* modplug->mSoundFile->SetCurrentPos( 0 ); */
break; break;
case GST_STATE_READY_TO_NULL: case GST_STATE_READY_TO_NULL:
free( modplug->audiobuffer ); /* g_free( modplug->buffer_in );
modplug->mSoundFile->Destroy(); g_free( modplug->audiobuffer );
modplug->mSoundFile->Destroy();*/
break; break;
} }
@ -542,6 +569,7 @@ gst_modplug_change_state (GstElement *element)
return GST_STATE_SUCCESS; return GST_STATE_SUCCESS;
} }
static void static void
gst_modplug_set_property (GObject *object, guint id, const GValue *value, GParamSpec *pspec ) gst_modplug_set_property (GObject *object, guint id, const GValue *value, GParamSpec *pspec )
{ {
@ -595,7 +623,6 @@ gst_modplug_set_property (GObject *object, guint id, const GValue *value, GParam
modplug->_16bit = g_value_get_boolean (value); modplug->_16bit = g_value_get_boolean (value);
break; break;
default: default:
// G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
} }
} }
@ -650,7 +677,6 @@ gst_modplug_get_property (GObject *object, guint id, GValue *value, GParamSpec *
g_value_set_boolean (value, modplug->noise_reduction); g_value_set_boolean (value, modplug->noise_reduction);
break; break;
default: default:
// G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
} }
} }
@ -659,15 +685,23 @@ static gboolean
plugin_init (GModule *module, GstPlugin *plugin) plugin_init (GModule *module, GstPlugin *plugin)
{ {
GstElementFactory *factory; GstElementFactory *factory;
GstTypeFactory *type;
/* this filter needs the bytestream package */
if (!gst_library_load ("gstbytestream"))
return FALSE;
factory = gst_element_factory_new("modplug",GST_TYPE_MODPLUG, factory = gst_element_factory_new("modplug",GST_TYPE_MODPLUG,
&modplug_details); &modplug_details);
g_return_val_if_fail(factory != NULL, FALSE); g_return_val_if_fail(factory != NULL, FALSE);
gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_PRIMARY); gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_PRIMARY);
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (modplug_sink_template_factory)); gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (modplug_sink_template_factory));
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (modplug_src_template_factory)); gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (modplug_src_template_factory));
type = gst_type_factory_new (&modplug_definition);
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
return TRUE; return TRUE;

View file

@ -26,7 +26,11 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/bytestream/bytestream.h>
#include "modplug_types.h"
#define GST_TYPE_MODPLUG \ #define GST_TYPE_MODPLUG \
(gst_modplug_get_type()) (gst_modplug_get_type())
@ -43,7 +47,8 @@ extern "C" {
struct _GstModPlug { struct _GstModPlug {
GstElement element; GstElement element;
GstPad *sinkpad, *srcpad; GstPad *sinkpad, *srcpad;
GstBuffer *Buffer; guint8 *buffer_in;
GstByteStream *bs;
const gchar *songname; const gchar *songname;
gboolean reverb; gboolean reverb;

220
gst/modplug/modplug_types.c Normal file
View file

@ -0,0 +1,220 @@
/* 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.
*/
#include <gst/gst.h>
#include "modplug_types.h"
#include <string.h> /* memcmp */
#include <ctype.h> /* isdigit */
#define MODULEHEADERSIZE 0x438
gboolean MOD_CheckType( GstBuffer *buf )
{
gchar *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 )
{
gchar *data;
data = GST_BUFFER_DATA( buf );
if( ! memcmp( data, "if", 2 ) || ! memcmp( data, "JN", 2 ))
return TRUE;
return FALSE;
}
gboolean Amf_CheckType( GstBuffer *buf )
{
gchar *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 )
{
gchar *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 )
{
gchar *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 )
{
gchar *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 )
{
gchar *data;
data = GST_BUFFER_DATA( buf ) + 0x3c;
if( ! memcmp( data, "IM10", 4))
return TRUE;
return FALSE;
}
gboolean It_CheckType( GstBuffer *buf )
{
gchar *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 )
{
gchar *data;
data = GST_BUFFER_DATA( buf );
if(( ! memcmp(data, "MMD0", 4 )) || ( memcmp( data, "MMD1", 4 )))
return TRUE;
return FALSE;
}
gboolean Mtm_CheckType( GstBuffer *buf )
{
gchar *data;
data = GST_BUFFER_DATA( buf );
if( ! memcmp( data, "MTM", 3 ))
return TRUE;
return FALSE;
}
gboolean Okt_CheckType( GstBuffer *buf )
{
gchar *data;
data = GST_BUFFER_DATA( buf );
if( ! memcmp( data, "OKTSONG", 8 ))
return TRUE;
return FALSE;
}
gboolean S3m_CheckType( GstBuffer *buf )
{
gchar *data;
data = GST_BUFFER_DATA( buf ) + 0x2c;
if( ! memcmp( data, "SCRM", 4 ))
return TRUE;
return FALSE;
}
gboolean Xm_CheckType( GstBuffer *buf )
{
gchar *data;
data = GST_BUFFER_DATA( buf );
if( memcmp( data, "Extended Module: ", 17 ))
return FALSE;
if( data[ 37 ] == 0x1a )
return TRUE;
return FALSE;
}

View file

@ -0,0 +1,44 @@
/* 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.
*/
#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__ */