2002-03-20 21:45:04 +00:00
|
|
|
/* GStreamer
|
2002-02-28 21:10:42 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-03-01 17:25:42 +00:00
|
|
|
/*
|
|
|
|
Code based on modplugxmms
|
|
|
|
XMMS plugin:
|
|
|
|
Kenton Varda <temporal@gauge3d.org>
|
|
|
|
Sound Engine:
|
|
|
|
Olivier Lapicque <olivierl@jps.net>
|
|
|
|
*/
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2003-11-07 12:47:02 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-02-28 21:10:42 +00:00
|
|
|
#include "libmodplug/stdafx.h"
|
|
|
|
#include "libmodplug/sndfile.h"
|
|
|
|
|
|
|
|
#include "gstmodplug.h"
|
|
|
|
|
2002-06-09 19:00:27 +00:00
|
|
|
#include <gst/gst.h>
|
2002-02-28 21:10:42 +00:00
|
|
|
#include <stdlib.h>
|
2002-11-17 12:23:43 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2002-02-28 21:10:42 +00:00
|
|
|
GstElementDetails modplug_details = {
|
|
|
|
"ModPlug",
|
2003-11-16 22:02:23 +00:00
|
|
|
"Codec/Decoder/Audio",
|
2002-03-01 17:25:42 +00:00
|
|
|
"Module decoder based on modplug engine",
|
2003-11-02 23:00:38 +00:00
|
|
|
"Jeremy SIMON <jsimon13@yahoo.fr>"
|
2002-02-28 21:10:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Filter signals and args */
|
2004-03-14 23:20:41 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-02-28 21:10:42 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-02-28 21:10:42 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_SONGNAME,
|
|
|
|
ARG_REVERB,
|
|
|
|
ARG_REVERB_DEPTH,
|
|
|
|
ARG_REVERB_DELAY,
|
|
|
|
ARG_MEGABASS,
|
|
|
|
ARG_MEGABASS_AMOUNT,
|
|
|
|
ARG_MEGABASS_RANGE,
|
|
|
|
ARG_NOISE_REDUCTION,
|
|
|
|
ARG_SURROUND,
|
|
|
|
ARG_SURROUND_DEPTH,
|
|
|
|
ARG_SURROUND_DELAY,
|
2003-12-22 01:47:09 +00:00
|
|
|
ARG_OVERSAMP
|
2002-02-28 21:10:42 +00:00
|
|
|
};
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate modplug_src_template_factory =
|
2004-03-14 23:20:41 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, " "endianness = (int) BYTE_ORDER, " "signed = (boolean) TRUE, " "width = (int) 16, " "depth = (int) 16, " "rate = (int) { 8000, 11025, 22050, 44100 }, " /* FIXME? */
|
2005-02-08 15:03:41 +00:00
|
|
|
"channels = (int) [ 1, 2 ]; " "audio/x-raw-int, " "endianness = (int) BYTE_ORDER, " "signed = (boolean) FALSE, " "width = (int) 8, " "depth = (int) 8, " "rate = (int) { 8000, 11025, 22050, 44100 }, " /* FIXME? */
|
2004-03-15 19:32:27 +00:00
|
|
|
"channels = (int) [ 1, 2 ]")
|
2004-03-14 23:20:41 +00:00
|
|
|
);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate modplug_sink_template_factory =
|
2004-03-14 23:20:41 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-mod")
|
|
|
|
);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2002-12-30 17:21:45 +00:00
|
|
|
MODPLUG_STATE_NEED_TUNE = 1,
|
|
|
|
MODPLUG_STATE_LOAD_TUNE = 2,
|
2004-05-21 22:39:30 +00:00
|
|
|
MODPLUG_STATE_PLAY_TUNE = 3
|
2002-12-30 17:21:45 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
static void gst_modplug_base_init (GstModPlugClass * klass);
|
|
|
|
static void gst_modplug_class_init (GstModPlugClass * klass);
|
|
|
|
static void gst_modplug_init (GstModPlug * filter);
|
|
|
|
static void gst_modplug_set_property (GObject * object,
|
|
|
|
guint id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_modplug_get_property (GObject * object,
|
|
|
|
guint id, GValue * value, GParamSpec * pspec);
|
2003-07-06 20:49:52 +00:00
|
|
|
static GstPadLinkReturn
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_srclink (GstPad * pad, const GstCaps * caps);
|
|
|
|
static GstCaps *gst_modplug_fixate (GstPad * pad, const GstCaps * caps);
|
|
|
|
static void gst_modplug_loop (GstElement * element);
|
|
|
|
static void gst_modplug_setup (GstModPlug * modplug);
|
|
|
|
static const GstFormat *gst_modplug_get_formats (GstPad * pad);
|
|
|
|
static const GstQueryType *gst_modplug_get_query_types (GstPad * pad);
|
|
|
|
static gboolean gst_modplug_src_event (GstPad * pad, GstEvent * event);
|
|
|
|
static gboolean gst_modplug_src_query (GstPad * pad,
|
|
|
|
GstQueryType type, GstFormat * format, gint64 * value);
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn gst_modplug_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
GType
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_get_type (void)
|
|
|
|
{
|
2002-02-28 21:10:42 +00:00
|
|
|
static GType modplug_type = 0;
|
|
|
|
|
|
|
|
if (!modplug_type) {
|
|
|
|
static const GTypeInfo modplug_info = {
|
2004-03-14 23:20:41 +00:00
|
|
|
sizeof (GstModPlugClass),
|
|
|
|
(GBaseInitFunc) gst_modplug_base_init,
|
2002-02-28 21:10:42 +00:00
|
|
|
NULL,
|
2004-03-14 23:20:41 +00:00
|
|
|
(GClassInitFunc) gst_modplug_class_init,
|
2002-02-28 21:10:42 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 23:20:41 +00:00
|
|
|
sizeof (GstModPlug),
|
2002-02-28 21:10:42 +00:00
|
|
|
0,
|
2004-03-14 23:20:41 +00:00
|
|
|
(GInstanceInitFunc) gst_modplug_init,
|
2002-02-28 21:10:42 +00:00
|
|
|
NULL
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstModPlug", &modplug_info,
|
|
|
|
(GTypeFlags) 0);
|
2002-02-28 21:10:42 +00:00
|
|
|
}
|
|
|
|
return modplug_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 23:00:38 +00:00
|
|
|
static void
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_base_init (GstModPlugClass * klass)
|
2003-11-02 23:00:38 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_static_pad_template_get (&modplug_sink_template_factory));
|
2003-11-02 23:00:38 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_static_pad_template_get (&modplug_src_template_factory));
|
2003-11-02 23:00:38 +00:00
|
|
|
gst_element_class_set_details (element_class, &modplug_details);
|
|
|
|
}
|
2002-02-28 21:10:42 +00:00
|
|
|
|
|
|
|
static void
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_class_init (GstModPlugClass * klass)
|
2002-02-28 21:10:42 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
parent_class = GST_ELEMENT_CLASS (g_type_class_ref (GST_TYPE_ELEMENT));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SONGNAME,
|
|
|
|
g_param_spec_string ("songname", "Songname", "The song name",
|
2004-03-15 19:32:27 +00:00
|
|
|
"", G_PARAM_READABLE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB,
|
|
|
|
g_param_spec_boolean ("reverb", "reverb", "reverb",
|
2004-03-15 19:32:27 +00:00
|
|
|
FALSE, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB_DEPTH,
|
|
|
|
g_param_spec_int ("reverb_depth", "reverb_depth", "reverb_depth",
|
2004-03-15 19:32:27 +00:00
|
|
|
0, 100, 30, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB_DELAY,
|
|
|
|
g_param_spec_int ("reverb_delay", "reverb_delay", "reverb_delay",
|
2004-03-15 19:32:27 +00:00
|
|
|
0, 200, 100, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MEGABASS,
|
|
|
|
g_param_spec_boolean ("megabass", "megabass", "megabass",
|
2004-03-15 19:32:27 +00:00
|
|
|
FALSE, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MEGABASS_AMOUNT,
|
|
|
|
g_param_spec_int ("megabass_amount", "megabass_amount", "megabass_amount",
|
2004-03-15 19:32:27 +00:00
|
|
|
0, 100, 40, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MEGABASS_RANGE,
|
|
|
|
g_param_spec_int ("megabass_range", "megabass_range", "megabass_range",
|
2004-03-15 19:32:27 +00:00
|
|
|
0, 100, 30, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND,
|
|
|
|
g_param_spec_boolean ("surround", "surround", "surround",
|
2004-03-15 19:32:27 +00:00
|
|
|
TRUE, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND_DEPTH,
|
|
|
|
g_param_spec_int ("surround_depth", "surround_depth", "surround_depth",
|
2004-03-15 19:32:27 +00:00
|
|
|
0, 100, 20, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND_DELAY,
|
|
|
|
g_param_spec_int ("surround_delay", "surround_delay", "surround_delay",
|
2004-03-15 19:32:27 +00:00
|
|
|
0, 40, 20, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_OVERSAMP,
|
|
|
|
g_param_spec_boolean ("oversamp", "oversamp", "oversamp",
|
2004-03-15 19:32:27 +00:00
|
|
|
TRUE, (GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NOISE_REDUCTION,
|
|
|
|
g_param_spec_boolean ("noise_reduction", "noise_reduction",
|
2004-03-15 19:32:27 +00:00
|
|
|
"noise_reduction", TRUE, (GParamFlags) G_PARAM_READWRITE));
|
2002-12-30 17:21:45 +00:00
|
|
|
|
2002-02-28 21:10:42 +00:00
|
|
|
gobject_class->set_property = gst_modplug_set_property;
|
|
|
|
gobject_class->get_property = gst_modplug_get_property;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_modplug_change_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_init (GstModPlug * modplug)
|
|
|
|
{
|
|
|
|
modplug->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&modplug_sink_template_factory), "sink");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (modplug), modplug->sinkpad);
|
|
|
|
|
|
|
|
modplug->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&modplug_src_template_factory), "src");
|
2003-07-06 20:49:52 +00:00
|
|
|
gst_pad_set_link_function (modplug->srcpad, gst_modplug_srclink);
|
2004-03-14 10:33:44 +00:00
|
|
|
gst_pad_set_fixate_function (modplug->srcpad, gst_modplug_fixate);
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_pad_set_event_function (modplug->srcpad,
|
|
|
|
(GstPadEventFunction) GST_DEBUG_FUNCPTR (gst_modplug_src_event));
|
2002-06-09 19:00:27 +00:00
|
|
|
gst_pad_set_query_function (modplug->srcpad, gst_modplug_src_query);
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_pad_set_query_type_function (modplug->srcpad, (GstPadQueryTypeFunction)
|
2004-03-14 23:20:41 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_modplug_get_query_types));
|
|
|
|
gst_pad_set_formats_function (modplug->srcpad,
|
|
|
|
(GstPadFormatsFunction) GST_DEBUG_FUNCPTR (gst_modplug_get_formats));
|
|
|
|
gst_element_add_pad (GST_ELEMENT (modplug), modplug->srcpad);
|
|
|
|
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (modplug), gst_modplug_loop);
|
|
|
|
|
|
|
|
modplug->reverb = FALSE;
|
|
|
|
modplug->reverb_depth = 30;
|
|
|
|
modplug->reverb_delay = 100;
|
|
|
|
modplug->megabass = FALSE;
|
2002-02-28 21:10:42 +00:00
|
|
|
modplug->megabass_amount = 40;
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->megabass_range = 30;
|
|
|
|
modplug->surround = TRUE;
|
|
|
|
modplug->surround_depth = 20;
|
|
|
|
modplug->surround_delay = 20;
|
|
|
|
modplug->oversamp = TRUE;
|
2002-02-28 21:10:42 +00:00
|
|
|
modplug->noise_reduction = TRUE;
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->_16bit = TRUE;
|
|
|
|
modplug->channel = 2;
|
|
|
|
modplug->frequency = 44100;
|
2003-06-27 23:46:13 +00:00
|
|
|
modplug->audiobuffer = NULL;
|
|
|
|
modplug->buffer_in = NULL;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2003-01-20 21:02:58 +00:00
|
|
|
modplug->state = MODPLUG_STATE_NEED_TUNE;
|
2004-03-14 12:40:57 +00:00
|
|
|
GST_FLAG_SET (modplug, GST_ELEMENT_EVENT_AWARE);
|
2002-02-28 21:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_setup (GstModPlug * modplug)
|
2002-02-28 21:10:42 +00:00
|
|
|
{
|
2004-03-14 23:20:41 +00:00
|
|
|
if (modplug->_16bit)
|
|
|
|
modplug->mSoundFile->SetWaveConfig (modplug->frequency, 16,
|
2004-03-15 19:32:27 +00:00
|
|
|
modplug->channel);
|
2002-02-28 21:10:42 +00:00
|
|
|
else
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->mSoundFile->SetWaveConfig (modplug->frequency, 8,
|
2004-03-15 19:32:27 +00:00
|
|
|
modplug->channel);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
|
|
|
modplug->mSoundFile->SetWaveConfigEx (modplug->surround, !modplug->oversamp,
|
|
|
|
modplug->reverb, true, modplug->megabass, modplug->noise_reduction, true);
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug->mSoundFile->SetResamplingMode (SRCMODE_POLYPHASE);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
if (modplug->surround)
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->mSoundFile->SetSurroundParameters (modplug->surround_depth,
|
2004-03-15 19:32:27 +00:00
|
|
|
modplug->surround_delay);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
if (modplug->megabass)
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->mSoundFile->SetXBassParameters (modplug->megabass_amount,
|
2004-03-15 19:32:27 +00:00
|
|
|
modplug->megabass_range);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
if (modplug->reverb)
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->mSoundFile->SetReverbParameters (modplug->reverb_depth,
|
2004-03-15 19:32:27 +00:00
|
|
|
modplug->reverb_delay);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
|
|
|
}
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
static const GstFormat *
|
|
|
|
gst_modplug_get_formats (GstPad * pad)
|
2002-12-30 17:21:45 +00:00
|
|
|
{
|
|
|
|
static const GstFormat src_formats[] = {
|
|
|
|
/* GST_FORMAT_BYTES,
|
2003-05-24 10:41:58 +00:00
|
|
|
GST_FORMAT_DEFAULT,*/
|
2002-12-30 17:21:45 +00:00
|
|
|
GST_FORMAT_TIME,
|
2004-03-14 23:20:41 +00:00
|
|
|
(GstFormat) 0
|
2002-12-30 17:21:45 +00:00
|
|
|
};
|
|
|
|
static const GstFormat sink_formats[] = {
|
2004-03-14 23:20:41 +00:00
|
|
|
/*GST_FORMAT_BYTES, */
|
2002-12-30 17:21:45 +00:00
|
|
|
GST_FORMAT_TIME,
|
2004-03-14 23:20:41 +00:00
|
|
|
(GstFormat) 0
|
2002-12-30 17:21:45 +00:00
|
|
|
};
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
|
|
|
|
}
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
static const GstQueryType *
|
|
|
|
gst_modplug_get_query_types (GstPad * pad)
|
2002-12-30 17:21:45 +00:00
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType gst_modplug_src_query_types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
2004-03-14 23:20:41 +00:00
|
|
|
(GstQueryType) 0
|
2002-12-30 17:21:45 +00:00
|
|
|
};
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
return gst_modplug_src_query_types;
|
|
|
|
}
|
2003-01-19 21:20:40 +00:00
|
|
|
|
|
|
|
|
2002-06-09 19:00:27 +00:00
|
|
|
static gboolean
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value)
|
2002-06-09 19:00:27 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstModPlug *modplug;
|
2002-12-07 15:28:24 +00:00
|
|
|
gfloat tmp;
|
2002-06-09 19:00:27 +00:00
|
|
|
|
|
|
|
modplug = GST_MODPLUG (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2002-06-09 19:00:27 +00:00
|
|
|
switch (*format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*value = (gint64) modplug->mSoundFile->GetSongTime () * GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-06-09 19:00:27 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-06-09 19:00:27 +00:00
|
|
|
switch (*format) {
|
ext/flac/gstflacdec.c: Only return true if we actually filled something in. Prevents player applications from showing...
Original commit message from CVS:
* ext/flac/gstflacdec.c: (gst_flacdec_src_query):
Only return true if we actually filled something in. Prevents
player applications from showing a random length for flac files.
* gst-libs/gst/riff/riff-read.c: (gst_riff_read_class_init),
(gst_riff_read_use_event), (gst_riff_read_handle_event),
(gst_riff_read_seek), (gst_riff_read_skip), (gst_riff_read_strh),
(gst_riff_read_strf_vids_with_data),
(gst_riff_read_strf_auds_with_data), (gst_riff_read_strf_iavs):
OK, ok, so I implemented event handling. Apparently it's normal
that we receive random events at random points without asking
for it.
* gst/avi/gstavidemux.c: (gst_avi_demux_reset),
(gst_avi_demux_src_convert), (gst_avi_demux_handle_src_query),
(gst_avi_demux_handle_src_event), (gst_avi_demux_stream_index),
(gst_avi_demux_sync), (gst_avi_demux_stream_scan),
(gst_avi_demux_massage_index), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry),
(gst_avi_demux_stream_data), (gst_avi_demux_loop):
* gst/avi/gstavidemux.h:
Implement non-lineair chunk handling and subchunk processing.
The first solves playback of AVI files where the audio and video
data of individual buffers that we read are not synchronized.
This should not happen according to the wonderful AVI specs, but
of course it does happen in reality. It is also a prerequisite for
the second. Subchunk processing allows us to cut chunks in small
pieces and process each of these pieces separately. This is
required because I've seen several AVI files with incredibly large
audio chunks, even some files with only one audio chunk for the
whole file. This allows for proper playback including seeking.
This patch is supposed to fix all AVI A/V sync issues.
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(flx_decode_chunks), (flx_decode_color), (gst_flxdec_loop):
Work.
* gst/modplug/gstmodplug.cc:
Proper return value setting for the query() function.
* gst/playback/gstplaybasebin.c: (setup_source):
Being in non-playing state (after, e.g., EOS) is not necessarily
a bad thing. Allow for that. This fixes playback of short files.
They don't actually playback fully now, because the clock already
runs. This means that small files (<500kB) with a small length
(<2sec) will still not or barely play. Other files, such as mod
or flx, will work correctly, however.
2004-09-29 09:45:40 +00:00
|
|
|
case GST_FORMAT_TIME:
|
2004-03-15 19:32:27 +00:00
|
|
|
tmp =
|
|
|
|
((float) (modplug->mSoundFile->GetSongTime () *
|
|
|
|
modplug->mSoundFile->GetCurrentPos ()) /
|
|
|
|
(float) modplug->mSoundFile->GetMaxPosition ());
|
|
|
|
*value = (gint64) (tmp * GST_SECOND);
|
|
|
|
break;
|
ext/flac/gstflacdec.c: Only return true if we actually filled something in. Prevents player applications from showing...
Original commit message from CVS:
* ext/flac/gstflacdec.c: (gst_flacdec_src_query):
Only return true if we actually filled something in. Prevents
player applications from showing a random length for flac files.
* gst-libs/gst/riff/riff-read.c: (gst_riff_read_class_init),
(gst_riff_read_use_event), (gst_riff_read_handle_event),
(gst_riff_read_seek), (gst_riff_read_skip), (gst_riff_read_strh),
(gst_riff_read_strf_vids_with_data),
(gst_riff_read_strf_auds_with_data), (gst_riff_read_strf_iavs):
OK, ok, so I implemented event handling. Apparently it's normal
that we receive random events at random points without asking
for it.
* gst/avi/gstavidemux.c: (gst_avi_demux_reset),
(gst_avi_demux_src_convert), (gst_avi_demux_handle_src_query),
(gst_avi_demux_handle_src_event), (gst_avi_demux_stream_index),
(gst_avi_demux_sync), (gst_avi_demux_stream_scan),
(gst_avi_demux_massage_index), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry),
(gst_avi_demux_stream_data), (gst_avi_demux_loop):
* gst/avi/gstavidemux.h:
Implement non-lineair chunk handling and subchunk processing.
The first solves playback of AVI files where the audio and video
data of individual buffers that we read are not synchronized.
This should not happen according to the wonderful AVI specs, but
of course it does happen in reality. It is also a prerequisite for
the second. Subchunk processing allows us to cut chunks in small
pieces and process each of these pieces separately. This is
required because I've seen several AVI files with incredibly large
audio chunks, even some files with only one audio chunk for the
whole file. This allows for proper playback including seeking.
This patch is supposed to fix all AVI A/V sync issues.
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(flx_decode_chunks), (flx_decode_color), (gst_flxdec_loop):
Work.
* gst/modplug/gstmodplug.cc:
Proper return value setting for the query() function.
* gst/playback/gstplaybasebin.c: (setup_source):
Being in non-playing state (after, e.g., EOS) is not necessarily
a bad thing. Allow for that. This fixes playback of short files.
They don't actually playback fully now, because the clock already
runs. This means that small files (<500kB) with a small length
(<2sec) will still not or barely play. Other files, such as mod
or flx, will work correctly, however.
2004-09-29 09:45:40 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-06-09 19:00:27 +00:00
|
|
|
}
|
2005-02-15 16:25:48 +00:00
|
|
|
break;
|
2002-06-09 19:00:27 +00:00
|
|
|
default:
|
ext/flac/gstflacdec.c: Only return true if we actually filled something in. Prevents player applications from showing...
Original commit message from CVS:
* ext/flac/gstflacdec.c: (gst_flacdec_src_query):
Only return true if we actually filled something in. Prevents
player applications from showing a random length for flac files.
* gst-libs/gst/riff/riff-read.c: (gst_riff_read_class_init),
(gst_riff_read_use_event), (gst_riff_read_handle_event),
(gst_riff_read_seek), (gst_riff_read_skip), (gst_riff_read_strh),
(gst_riff_read_strf_vids_with_data),
(gst_riff_read_strf_auds_with_data), (gst_riff_read_strf_iavs):
OK, ok, so I implemented event handling. Apparently it's normal
that we receive random events at random points without asking
for it.
* gst/avi/gstavidemux.c: (gst_avi_demux_reset),
(gst_avi_demux_src_convert), (gst_avi_demux_handle_src_query),
(gst_avi_demux_handle_src_event), (gst_avi_demux_stream_index),
(gst_avi_demux_sync), (gst_avi_demux_stream_scan),
(gst_avi_demux_massage_index), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry),
(gst_avi_demux_stream_data), (gst_avi_demux_loop):
* gst/avi/gstavidemux.h:
Implement non-lineair chunk handling and subchunk processing.
The first solves playback of AVI files where the audio and video
data of individual buffers that we read are not synchronized.
This should not happen according to the wonderful AVI specs, but
of course it does happen in reality. It is also a prerequisite for
the second. Subchunk processing allows us to cut chunks in small
pieces and process each of these pieces separately. This is
required because I've seen several AVI files with incredibly large
audio chunks, even some files with only one audio chunk for the
whole file. This allows for proper playback including seeking.
This patch is supposed to fix all AVI A/V sync issues.
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(flx_decode_chunks), (flx_decode_color), (gst_flxdec_loop):
Work.
* gst/modplug/gstmodplug.cc:
Proper return value setting for the query() function.
* gst/playback/gstplaybasebin.c: (setup_source):
Being in non-playing state (after, e.g., EOS) is not necessarily
a bad thing. Allow for that. This fixes playback of short files.
They don't actually playback fully now, because the clock already
runs. This means that small files (<500kB) with a small length
(<2sec) will still not or barely play. Other files, such as mod
or flx, will work correctly, however.
2004-09-29 09:45:40 +00:00
|
|
|
res = FALSE;
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2004-03-14 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
2002-06-09 19:00:27 +00:00
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_src_event (GstPad * pad, GstEvent * event)
|
2002-06-09 19:00:27 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2004-03-14 23:20:41 +00:00
|
|
|
GstModPlug *modplug;
|
2002-06-09 19:00:27 +00:00
|
|
|
|
|
|
|
modplug = GST_MODPLUG (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2004-03-14 23:20:41 +00:00
|
|
|
/* the all-formats seek logic */
|
2002-12-30 17:21:45 +00:00
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
gboolean flush;
|
|
|
|
GstFormat format;
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
format = GST_FORMAT_TIME;
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
/* shave off the flush flag, we'll need it later */
|
|
|
|
flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug->seek_at = GST_EVENT_SEEK_OFFSET (event);
|
2003-01-20 22:42:57 +00:00
|
|
|
break;
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-06-09 19:00:27 +00:00
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-07-08 19:42:06 +00:00
|
|
|
gst_event_unref (event);
|
2002-06-09 19:00:27 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
#if 0
|
2004-03-14 23:20:41 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_modplug_get_streaminfo (GstModPlug * modplug)
|
2002-12-30 17:21:45 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
props = gst_props_empty_new ();
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
entry =
|
|
|
|
gst_props_entry_new ("Patterns",
|
|
|
|
G_TYPE_INT ((gint) modplug->mSoundFile->GetNumPatterns ()));
|
2002-12-30 17:21:45 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
caps = gst_caps_new_simple ("application/x-gst-streaminfo", NULL);
|
2002-12-30 17:21:45 +00:00
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2002-02-28 21:10:42 +00:00
|
|
|
|
|
|
|
static void
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_update_info (GstModPlug * modplug)
|
|
|
|
{
|
|
|
|
if (modplug->streaminfo) {
|
|
|
|
gst_caps_unref (modplug->streaminfo);
|
|
|
|
}
|
2003-01-19 21:20:40 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->streaminfo = gst_modplug_get_streaminfo (modplug);
|
|
|
|
g_object_notify (G_OBJECT (modplug), "streaminfo");
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
static void
|
|
|
|
gst_modplug_update_metadata (GstModPlug * modplug)
|
|
|
|
{
|
2002-12-30 17:21:45 +00:00
|
|
|
GstProps *props;
|
|
|
|
GstPropsEntry *entry;
|
|
|
|
const gchar *title;
|
|
|
|
|
|
|
|
props = gst_props_empty_new ();
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
title = modplug->mSoundFile->GetTitle ();
|
2003-12-22 01:47:09 +00:00
|
|
|
entry = gst_props_entry_new ("Title", G_TYPE_STRING (title));
|
2002-12-30 17:21:45 +00:00
|
|
|
gst_props_add_entry (props, entry);
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->metadata = gst_caps_new_simple ("application/x-gst-metadata", NULL);
|
2002-12-30 17:21:45 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (modplug), "metadata");
|
|
|
|
}
|
2003-12-22 01:47:09 +00:00
|
|
|
#endif
|
2002-12-30 17:21:45 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
static GstPadLinkReturn
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_srclink (GstPad * pad, const GstCaps * caps)
|
2003-07-06 20:49:52 +00:00
|
|
|
{
|
2004-03-14 23:20:41 +00:00
|
|
|
GstModPlug *modplug;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
|
|
|
gint depth;
|
2003-07-06 20:49:52 +00:00
|
|
|
|
|
|
|
modplug = GST_MODPLUG (gst_pad_get_parent (pad));
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
gst_structure_get_int (structure, "depth", &depth);
|
|
|
|
modplug->_16bit = (depth == 16);
|
|
|
|
gst_structure_get_int (structure, "channels", &modplug->channel);
|
|
|
|
gst_structure_get_int (structure, "rate", &modplug->frequency);
|
2003-07-06 20:49:52 +00:00
|
|
|
|
2004-03-09 21:09:11 +00:00
|
|
|
modplug->length = 1152 * modplug->channel * depth / 8;
|
|
|
|
gst_modplug_setup (modplug);
|
|
|
|
|
|
|
|
return GST_PAD_LINK_OK;
|
2003-07-06 20:49:52 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 10:33:44 +00:00
|
|
|
static GstCaps *
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_fixate (GstPad * pad, const GstCaps * caps)
|
2004-03-14 10:33:44 +00:00
|
|
|
{
|
|
|
|
if (gst_caps_is_simple (caps)) {
|
|
|
|
GstCaps *copy;
|
|
|
|
GstStructure *structure;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2004-03-14 10:33:44 +00:00
|
|
|
copy = gst_caps_copy (caps);
|
|
|
|
structure = gst_caps_get_structure (copy, 0);
|
2005-11-21 14:33:11 +00:00
|
|
|
if (gst_structure_fixate_field_nearest_int (structure, "rate", 44100))
|
2004-03-14 10:33:44 +00:00
|
|
|
return copy;
|
2005-11-21 14:33:11 +00:00
|
|
|
if (gst_structure_fixate_field_nearest_int (structure, "channels", 2))
|
2004-03-14 10:33:44 +00:00
|
|
|
return copy;
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_caps_free (copy);
|
2004-03-14 10:33:44 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-01-20 21:02:58 +00:00
|
|
|
static void
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_handle_event (GstModPlug * modplug)
|
2003-01-20 21:02:58 +00:00
|
|
|
{
|
2004-03-14 12:40:57 +00:00
|
|
|
gint64 value;
|
2003-01-20 21:02:58 +00:00
|
|
|
guint32 remaining;
|
|
|
|
GstEvent *event;
|
|
|
|
|
|
|
|
gst_bytestream_get_status (modplug->bs, &remaining, &event);
|
|
|
|
|
|
|
|
if (!event) {
|
|
|
|
g_warning ("modplug: no bytestream event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2004-03-14 12:40:57 +00:00
|
|
|
case GST_EVENT_EOS:
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
2003-01-20 21:02:58 +00:00
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
2004-03-14 12:40:57 +00:00
|
|
|
if (gst_event_discont_get_value (event, GST_FORMAT_BYTES, &value)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
if (remaining == value) {
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 12:40:57 +00:00
|
|
|
}
|
2003-01-20 21:02:58 +00:00
|
|
|
gst_bytestream_flush_fast (modplug->bs, remaining);
|
|
|
|
default:
|
|
|
|
gst_pad_event_default (modplug->sinkpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
static void
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_loop (GstElement * element)
|
2002-12-30 17:21:45 +00:00
|
|
|
{
|
2004-03-14 23:20:41 +00:00
|
|
|
GstModPlug *modplug;
|
|
|
|
GstEvent *event;
|
2002-12-30 17:21:45 +00:00
|
|
|
|
|
|
|
g_return_if_fail (element != NULL);
|
|
|
|
g_return_if_fail (GST_IS_MODPLUG (element));
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug = GST_MODPLUG (element);
|
2003-01-19 21:20:40 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
if (modplug->state == MODPLUG_STATE_NEED_TUNE) {
|
2003-01-19 21:20:40 +00:00
|
|
|
/* GstBuffer *buf;*/
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug->seek_at = -1;
|
2004-03-14 13:11:14 +00:00
|
|
|
modplug->need_discont = TRUE;
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug->eos = FALSE;
|
2003-01-19 21:20:40 +00:00
|
|
|
/*
|
2002-12-30 17:21:45 +00:00
|
|
|
buf = gst_pad_pull (modplug->sinkpad);
|
|
|
|
g_assert (buf != NULL);
|
2002-11-17 12:23:43 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
if (GST_IS_EVENT (buf)) {
|
|
|
|
GstEvent *event = GST_EVENT (buf);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (buf)) {
|
2003-01-12 21:23:49 +00:00
|
|
|
case GST_EVENT_EOS:
|
|
|
|
modplug->state = MODPLUG_STATE_LOAD_TUNE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
|
|
|
break;
|
|
|
|
default:
|
2003-01-19 21:20:40 +00:00
|
|
|
bail out, we're not going to do anything
|
2003-01-12 21:23:49 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
gst_pad_send_event (modplug->srcpad, gst_event_new (GST_EVENT_EOS));
|
|
|
|
gst_element_set_eos (element);
|
|
|
|
return;
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memcpy (modplug->buffer_in + modplug->song_size, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
|
|
|
modplug->song_size += GST_BUFFER_SIZE (buf);
|
2002-06-11 19:12:51 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
2003-01-19 21:20:40 +00:00
|
|
|
*/
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
if (modplug->bs) {
|
2003-01-20 21:02:58 +00:00
|
|
|
guint64 got;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2003-01-20 21:02:58 +00:00
|
|
|
modplug->song_size = gst_bytestream_length (modplug->bs);
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
got =
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_bytestream_peek_bytes (modplug->bs, &modplug->buffer_in,
|
|
|
|
modplug->song_size);
|
2003-01-20 21:02:58 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
if (got < modplug->song_size) {
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_modplug_handle_event (modplug);
|
|
|
|
return;
|
2003-01-20 21:02:58 +00:00
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->state = MODPLUG_STATE_LOAD_TUNE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modplug->state == MODPLUG_STATE_LOAD_TUNE) {
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug->mSoundFile = new CSoundFile;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
if (!GST_PAD_CAPS (modplug->srcpad) &&
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_PAD_LINK_FAILED (gst_pad_renegotiate (modplug->srcpad))) {
|
2004-01-29 23:20:45 +00:00
|
|
|
GST_ELEMENT_ERROR (modplug, CORE, NEGOTIATION, (NULL), (NULL));
|
2002-12-30 17:21:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
|
|
|
modplug->mSoundFile->Create (modplug->buffer_in, modplug->song_size);
|
2003-06-27 23:46:13 +00:00
|
|
|
modplug->opened = TRUE;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2003-01-20 21:24:37 +00:00
|
|
|
gst_bytestream_flush (modplug->bs, modplug->song_size);
|
|
|
|
modplug->buffer_in = NULL;
|
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug->audiobuffer = (guchar *) g_malloc (modplug->length);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
//gst_modplug_update_metadata (modplug);
|
|
|
|
//gst_modplug_update_info (modplug);
|
2002-12-30 17:21:45 +00:00
|
|
|
|
|
|
|
modplug->state = MODPLUG_STATE_PLAY_TUNE;
|
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
|
|
|
if (modplug->state == MODPLUG_STATE_PLAY_TUNE && !modplug->eos) {
|
|
|
|
if (modplug->seek_at != -1) {
|
2002-12-30 17:21:45 +00:00
|
|
|
gint seek_to_pos;
|
2002-12-07 15:28:24 +00:00
|
|
|
gint64 total;
|
2002-12-30 17:21:45 +00:00
|
|
|
gfloat temp;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
total = modplug->mSoundFile->GetSongTime () * GST_SECOND;
|
2002-06-11 19:12:51 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
temp = (gfloat) total / modplug->seek_at;
|
2002-12-30 17:21:45 +00:00
|
|
|
seek_to_pos = (int) (modplug->mSoundFile->GetMaxPosition () / temp);
|
2002-06-11 19:12:51 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->mSoundFile->SetCurrentPos (seek_to_pos);
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug->need_discont = TRUE;
|
|
|
|
modplug->seek_at = -1;
|
2002-12-07 15:28:24 +00:00
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
|
|
|
if (modplug->need_discont && GST_PAD_IS_USABLE (modplug->srcpad)) {
|
2004-03-14 13:11:14 +00:00
|
|
|
GstEvent *discont;
|
|
|
|
gint64 value;
|
|
|
|
GstFormat format = GST_FORMAT_TIME;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
|
|
|
if (gst_modplug_src_query (modplug->srcpad, GST_QUERY_POSITION, &format,
|
2004-03-15 19:32:27 +00:00
|
|
|
&value)) {
|
|
|
|
discont =
|
|
|
|
gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, value,
|
|
|
|
GST_FORMAT_UNDEFINED);
|
|
|
|
modplug->timestamp = value;
|
2004-03-14 13:11:14 +00:00
|
|
|
} else {
|
2004-03-15 19:32:27 +00:00
|
|
|
modplug->timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_UNDEFINED);
|
2004-03-14 13:11:14 +00:00
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_pad_push (modplug->srcpad, GST_DATA (discont));
|
|
|
|
modplug->need_discont = FALSE;
|
2004-03-14 13:11:14 +00:00
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
|
|
|
if (modplug->mSoundFile->Read (modplug->audiobuffer, modplug->length) != 0) {
|
2002-12-30 17:21:45 +00:00
|
|
|
GstBuffer *buffer_out;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
buffer_out = gst_buffer_new ();
|
2004-03-14 23:20:41 +00:00
|
|
|
GST_BUFFER_DATA (buffer_out) =
|
2004-03-15 19:32:27 +00:00
|
|
|
(guchar *) g_memdup (modplug->audiobuffer, modplug->length);
|
2002-12-30 17:21:45 +00:00
|
|
|
GST_BUFFER_SIZE (buffer_out) = modplug->length;
|
2004-03-14 13:11:14 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer_out) = modplug->timestamp;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2004-03-14 13:11:14 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (modplug->timestamp)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_DURATION (buffer_out) =
|
|
|
|
modplug->length * GST_SECOND / modplug->frequency /
|
|
|
|
modplug->channel / (modplug->_16bit ? 2 : 1);
|
|
|
|
modplug->timestamp += GST_BUFFER_DURATION (buffer_out);
|
2004-03-14 13:11:14 +00:00
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2003-01-19 21:20:40 +00:00
|
|
|
if (GST_PAD_IS_USABLE (modplug->srcpad))
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_pad_push (modplug->srcpad, GST_DATA (buffer_out));
|
2004-03-14 23:20:41 +00:00
|
|
|
} else if (GST_PAD_IS_LINKED (modplug->srcpad)) {
|
|
|
|
/* FIXME, hack, pull final EOS from peer */
|
|
|
|
gst_bytestream_flush (modplug->bs, 1);
|
|
|
|
|
|
|
|
event = gst_event_new (GST_EVENT_EOS);
|
|
|
|
gst_pad_push (modplug->srcpad, GST_DATA (event));
|
|
|
|
gst_element_set_eos (element);
|
|
|
|
modplug->eos = TRUE;
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
2002-12-07 15:28:24 +00:00
|
|
|
}
|
2002-02-28 21:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_modplug_change_state (GstElement * element, GstStateChange transition)
|
2002-02-28 21:10:42 +00:00
|
|
|
{
|
2002-06-09 19:00:27 +00:00
|
|
|
GstModPlug *modplug;
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug = GST_MODPLUG (element);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2003-01-19 21:20:40 +00:00
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2003-01-19 21:20:40 +00:00
|
|
|
modplug->bs = gst_bytestream_new (modplug->sinkpad);
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug->song_size = 0;
|
2003-01-12 21:23:49 +00:00
|
|
|
modplug->state = MODPLUG_STATE_NEED_TUNE;
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_bytestream_destroy (modplug->bs);
|
2003-06-27 23:46:13 +00:00
|
|
|
modplug->bs = NULL;
|
2004-03-14 23:20:41 +00:00
|
|
|
if (modplug->opened) {
|
2004-03-15 19:32:27 +00:00
|
|
|
modplug->mSoundFile->Destroy ();
|
|
|
|
modplug->opened = FALSE;
|
2003-06-27 23:46:13 +00:00
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
if (modplug->audiobuffer)
|
2004-03-15 19:32:27 +00:00
|
|
|
g_free (modplug->audiobuffer);
|
2003-01-19 21:20:40 +00:00
|
|
|
modplug->buffer_in = NULL;
|
2003-01-20 21:24:37 +00:00
|
|
|
modplug->audiobuffer = NULL;
|
2003-01-19 21:20:40 +00:00
|
|
|
modplug->state = MODPLUG_STATE_NEED_TUNE;
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2002-12-07 15:28:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
2002-02-28 21:10:42 +00:00
|
|
|
}
|
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
2005-09-05 17:20:29 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
return GST_STATE_CHANGE_SUCCESS;
|
2002-02-28 21:10:42 +00:00
|
|
|
}
|
|
|
|
|
2002-11-17 12:23:43 +00:00
|
|
|
|
2002-02-28 21:10:42 +00:00
|
|
|
static void
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_set_property (GObject * object, guint id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-02-28 21:10:42 +00:00
|
|
|
{
|
|
|
|
GstModPlug *modplug;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 23:20:41 +00:00
|
|
|
g_return_if_fail (GST_IS_MODPLUG (object));
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug = GST_MODPLUG (object);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case ARG_REVERB:
|
|
|
|
modplug->reverb = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_REVERB_DEPTH:
|
|
|
|
modplug->reverb_depth = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_REVERB_DELAY:
|
|
|
|
modplug->reverb_delay = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_MEGABASS:
|
|
|
|
modplug->megabass = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_MEGABASS_AMOUNT:
|
|
|
|
modplug->megabass_amount = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_MEGABASS_RANGE:
|
|
|
|
modplug->megabass_range = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_NOISE_REDUCTION:
|
|
|
|
modplug->noise_reduction = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_SURROUND:
|
|
|
|
modplug->surround = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_SURROUND_DEPTH:
|
|
|
|
modplug->surround_depth = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_SURROUND_DELAY:
|
|
|
|
modplug->surround_delay = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_modplug_get_property (GObject * object, guint id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-02-28 21:10:42 +00:00
|
|
|
{
|
|
|
|
GstModPlug *modplug;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 23:20:41 +00:00
|
|
|
g_return_if_fail (GST_IS_MODPLUG (object));
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug = GST_MODPLUG (object);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2002-02-28 21:10:42 +00:00
|
|
|
switch (id) {
|
|
|
|
case ARG_REVERB:
|
|
|
|
g_value_set_boolean (value, modplug->reverb);
|
|
|
|
break;
|
|
|
|
case ARG_REVERB_DEPTH:
|
|
|
|
g_value_set_int (value, modplug->reverb_depth);
|
|
|
|
break;
|
|
|
|
case ARG_REVERB_DELAY:
|
|
|
|
g_value_set_int (value, modplug->reverb_delay);
|
|
|
|
break;
|
|
|
|
case ARG_MEGABASS:
|
|
|
|
g_value_set_boolean (value, modplug->megabass);
|
|
|
|
break;
|
|
|
|
case ARG_MEGABASS_AMOUNT:
|
|
|
|
g_value_set_int (value, modplug->megabass_amount);
|
|
|
|
break;
|
|
|
|
case ARG_MEGABASS_RANGE:
|
|
|
|
g_value_set_int (value, modplug->megabass_range);
|
|
|
|
break;
|
|
|
|
case ARG_SURROUND:
|
|
|
|
g_value_set_boolean (value, modplug->surround);
|
|
|
|
break;
|
|
|
|
case ARG_SURROUND_DEPTH:
|
|
|
|
g_value_set_int (value, modplug->surround_depth);
|
|
|
|
break;
|
|
|
|
case ARG_SURROUND_DELAY:
|
|
|
|
g_value_set_int (value, modplug->surround_delay);
|
|
|
|
break;
|
|
|
|
case ARG_NOISE_REDUCTION:
|
|
|
|
g_value_set_boolean (value, modplug->noise_reduction);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 23:20:41 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2002-02-28 21:10:42 +00:00
|
|
|
{
|
2002-11-17 12:23:43 +00:00
|
|
|
/* this filter needs the bytestream package */
|
2003-10-28 20:52:41 +00:00
|
|
|
if (!gst_library_load ("gstbytestream"))
|
|
|
|
return FALSE;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2003-11-02 23:00:38 +00:00
|
|
|
return gst_element_register (plugin, "modplug",
|
2004-03-14 23:20:41 +00:00
|
|
|
GST_RANK_PRIMARY, GST_TYPE_MODPLUG);
|
2002-02-28 21:10:42 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"modplug",
|
|
|
|
".MOD audio decoding",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
|