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
|
|
|
|
2007-07-03 07:52:52 +00:00
|
|
|
/**
|
2006-03-10 17:10:09 +00:00
|
|
|
* SECTION:element-modplug
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <para>
|
|
|
|
* Modplug uses the <ulink url="http://modplug-xmms.sourceforge.net/">modplug</ulink>
|
|
|
|
* library to decode tracked music in the MOD/S3M/XM/IT and related formats.
|
|
|
|
* </para>
|
|
|
|
* <title>Example pipeline</title>
|
|
|
|
* <programlisting>
|
|
|
|
* gst-launch -v filesrc location=1990s-nostalgia.xm ! modplug ! audioconvert ! alsasink
|
|
|
|
* </programlisting>
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (modplug_debug);
|
|
|
|
#define GST_CAT_DEFAULT modplug_debug
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
#define DEFAULT_REVERB FALSE
|
|
|
|
#define DEFAULT_REVERB_DEPTH 30
|
|
|
|
#define DEFAULT_REVERB_DELAY 100
|
|
|
|
#define DEFAULT_MEGABASS FALSE
|
|
|
|
#define DEFAULT_MEGABASS_AMOUNT 40
|
|
|
|
#define DEFAULT_MEGABASS_RANGE 30
|
|
|
|
#define DEFAULT_SURROUND TRUE
|
|
|
|
#define DEFAULT_SURROUND_DEPTH 20
|
|
|
|
#define DEFAULT_SURROUND_DELAY 20
|
|
|
|
#define DEFAULT_OVERSAMP TRUE
|
|
|
|
#define DEFAULT_NOISE_REDUCTION TRUE
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate modplug_src_template_factory =
|
2007-08-21 12:59:00 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2004-03-14 23:20:41 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2007-08-21 12:59:00 +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 },"
|
|
|
|
" channels = (int) 2; "
|
|
|
|
"audio/x-raw-int,"
|
|
|
|
" endianness = (int) BYTE_ORDER,"
|
|
|
|
" signed = (boolean) false,"
|
|
|
|
" width = (int) 8,"
|
|
|
|
" depth = (int) 8,"
|
|
|
|
" rate = (int) { 8000, 11025, 22050, 44100 }, "
|
|
|
|
" channels = (int) [ 1, 2 ]"));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate modplug_sink_template_factory =
|
2007-07-14 18:48:25 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2004-03-14 23:20:41 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2007-07-14 18:48:25 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-mod; audio/x-xm; audio/x-it; audio/x-s3m; "
|
|
|
|
"audio/x-stm"));
|
2002-12-30 17:21:45 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
static void gst_modplug_dispose (GObject * object);
|
2004-03-14 23:20:41 +00:00
|
|
|
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);
|
2006-03-10 17:10:09 +00:00
|
|
|
|
|
|
|
static void gst_modplug_fixate (GstPad * pad, GstCaps * caps);
|
2004-03-14 23:20:41 +00:00
|
|
|
static const GstQueryType *gst_modplug_get_query_types (GstPad * pad);
|
|
|
|
static gboolean gst_modplug_src_event (GstPad * pad, GstEvent * event);
|
2006-03-10 17:10:09 +00:00
|
|
|
static gboolean gst_modplug_src_query (GstPad * pad, GstQuery * query);
|
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
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
static gboolean gst_modplug_sinkpad_activate (GstPad * pad);
|
|
|
|
static gboolean gst_modplug_sinkpad_activate_pull (GstPad * pad,
|
|
|
|
gboolean active);
|
|
|
|
static void gst_modplug_loop (GstModPlug * element);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
GST_BOILERPLATE (GstModPlug, gst_modplug, GstElement, GST_TYPE_ELEMENT);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2003-11-02 23:00:38 +00:00
|
|
|
static void
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_modplug_base_init (gpointer g_class)
|
2003-11-02 23:00:38 +00:00
|
|
|
{
|
2006-03-10 17:10:09 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
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_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);
|
2006-03-10 17:10:09 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (modplug_debug, "modplug", 0, "ModPlug element");
|
2003-11-02 23:00:38 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
gobject_class->set_property = gst_modplug_set_property;
|
|
|
|
gobject_class->get_property = gst_modplug_get_property;
|
|
|
|
gobject_class->dispose = gst_modplug_dispose;
|
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",
|
2006-03-10 17:10:09 +00:00
|
|
|
NULL, 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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_boolean ("reverb", "reverb", "Reverb",
|
|
|
|
DEFAULT_REVERB, (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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_int ("reverb-depth", "reverb depth", "Reverb depth",
|
|
|
|
0, 100, DEFAULT_REVERB_DEPTH, (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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_int ("reverb-delay", "reverb delay", "Reverb delay",
|
|
|
|
0, 200, DEFAULT_REVERB_DELAY, (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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_boolean ("megabass", "megabass", "Megabass",
|
|
|
|
DEFAULT_MEGABASS, (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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_int ("megabass-amount", "megabass amount", "Megabass amount",
|
|
|
|
0, 100, DEFAULT_MEGABASS_AMOUNT, (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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_int ("megabass-range", "megabass range", "Megabass range",
|
|
|
|
0, 100, DEFAULT_MEGABASS_RANGE, (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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_boolean ("surround", "surround", "Surround",
|
|
|
|
DEFAULT_SURROUND, (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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_int ("surround-depth", "surround depth", "Surround depth",
|
|
|
|
0, 100, DEFAULT_SURROUND_DEPTH, (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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_int ("surround-delay", "surround delay", "Surround delay",
|
|
|
|
0, 40, DEFAULT_SURROUND_DELAY, (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",
|
2006-03-10 17:10:09 +00:00
|
|
|
DEFAULT_OVERSAMP, (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,
|
2006-03-10 17:10:09 +00:00
|
|
|
g_param_spec_boolean ("noise-reduction", "noise reduction",
|
|
|
|
"noise reduction", DEFAULT_NOISE_REDUCTION,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE));
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2007-01-03 16:41:10 +00:00
|
|
|
gstelement_class->change_state = gst_modplug_change_state;
|
2002-02-28 21:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_modplug_init (GstModPlug * modplug, GstModPlugClass * klass)
|
2004-03-14 23:20:41 +00:00
|
|
|
{
|
2006-03-10 17:10:09 +00:00
|
|
|
/* create the sink and src pads */
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->sinkpad =
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_pad_new_from_static_template (&modplug_sink_template_factory, "sink");
|
|
|
|
gst_pad_set_activate_function (modplug->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_modplug_sinkpad_activate));
|
|
|
|
gst_pad_set_activatepull_function (modplug->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_modplug_sinkpad_activate_pull));
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (modplug), modplug->sinkpad);
|
|
|
|
|
|
|
|
modplug->srcpad =
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_pad_new_from_static_template (&modplug_src_template_factory, "src");
|
|
|
|
gst_pad_set_fixatecaps_function (modplug->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_modplug_fixate));
|
2004-03-14 23:20:41 +00:00
|
|
|
gst_pad_set_event_function (modplug->srcpad,
|
2006-03-10 17:10:09 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_modplug_src_event));
|
|
|
|
gst_pad_set_query_function (modplug->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_modplug_src_query));
|
|
|
|
gst_pad_set_query_type_function (modplug->srcpad,
|
2004-03-14 23:20:41 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_modplug_get_query_types));
|
|
|
|
gst_element_add_pad (GST_ELEMENT (modplug), modplug->srcpad);
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
modplug->reverb = DEFAULT_REVERB;
|
|
|
|
modplug->reverb_depth = DEFAULT_REVERB_DEPTH;
|
|
|
|
modplug->reverb_delay = DEFAULT_REVERB_DELAY;
|
|
|
|
modplug->megabass = DEFAULT_MEGABASS;
|
|
|
|
modplug->megabass_amount = DEFAULT_MEGABASS_AMOUNT;
|
|
|
|
modplug->megabass_range = DEFAULT_MEGABASS_RANGE;
|
|
|
|
modplug->surround = DEFAULT_SURROUND;
|
|
|
|
modplug->surround_depth = DEFAULT_SURROUND_DEPTH;
|
|
|
|
modplug->surround_delay = DEFAULT_SURROUND_DELAY;
|
|
|
|
modplug->oversamp = DEFAULT_OVERSAMP;
|
|
|
|
modplug->noise_reduction = DEFAULT_NOISE_REDUCTION;
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
modplug->_16bit = TRUE;
|
|
|
|
modplug->channel = 2;
|
|
|
|
modplug->frequency = 44100;
|
2002-02-28 21:10:42 +00:00
|
|
|
}
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
|
2002-02-28 21:10:42 +00:00
|
|
|
static void
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_modplug_dispose (GObject * object)
|
2002-02-28 21:10:42 +00:00
|
|
|
{
|
2006-03-10 17:10:09 +00:00
|
|
|
GstModPlug *modplug = GST_MODPLUG (object);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (modplug->buffer) {
|
|
|
|
gst_buffer_unref (modplug->buffer);
|
|
|
|
modplug->buffer = NULL;
|
|
|
|
}
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
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[] = {
|
2006-03-10 17:10:09 +00:00
|
|
|
GST_QUERY_DURATION,
|
2002-12-30 17:53:18 +00:00
|
|
|
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
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_modplug_src_query (GstPad * pad, GstQuery * query)
|
2002-06-09 19:00:27 +00:00
|
|
|
{
|
|
|
|
GstModPlug *modplug;
|
2006-03-10 17:10:09 +00:00
|
|
|
gboolean res = FALSE;
|
2002-06-09 19:00:27 +00:00
|
|
|
|
|
|
|
modplug = GST_MODPLUG (gst_pad_get_parent (pad));
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (!modplug->mSoundFile)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
|
|
|
if (format == GST_FORMAT_TIME) {
|
|
|
|
gst_query_set_duration (query, format, modplug->song_length);
|
|
|
|
res = TRUE;
|
2002-06-09 19:00:27 +00:00
|
|
|
}
|
2006-03-10 17:10:09 +00:00
|
|
|
}
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2006-03-10 17:10:09 +00:00
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
gst_query_parse_position (query, &format, NULL);
|
|
|
|
if (format == GST_FORMAT_TIME) {
|
|
|
|
gint64 pos;
|
|
|
|
|
2006-12-11 09:51:17 +00:00
|
|
|
pos = (modplug->song_length * modplug->mSoundFile->GetCurrentPos ());
|
|
|
|
pos /= modplug->mSoundFile->GetMaxPosition ();
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_query_set_position (query, format, pos);
|
|
|
|
res = TRUE;
|
2002-06-09 19:00:27 +00:00
|
|
|
}
|
2006-03-10 17:10:09 +00:00
|
|
|
}
|
2005-02-15 16:25:48 +00:00
|
|
|
break;
|
2002-06-09 19:00:27 +00:00
|
|
|
default:
|
2006-03-10 17:10:09 +00:00
|
|
|
res = gst_pad_query_default (pad, query);
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
done:
|
|
|
|
gst_object_unref (modplug);
|
|
|
|
|
2002-06-09 19:00:27 +00:00
|
|
|
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
|
|
|
{
|
2004-03-14 23:20:41 +00:00
|
|
|
GstModPlug *modplug;
|
2006-03-10 17:10:09 +00:00
|
|
|
gboolean res = FALSE;
|
2002-06-09 19:00:27 +00:00
|
|
|
|
|
|
|
modplug = GST_MODPLUG (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2002-12-30 17:21:45 +00:00
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
2006-03-10 17:10:09 +00:00
|
|
|
gdouble rate;
|
2002-12-30 17:21:45 +00:00
|
|
|
GstFormat format;
|
2006-03-10 17:10:09 +00:00
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType cur_type, stop_type;
|
|
|
|
gboolean flush;
|
|
|
|
gint64 cur, stop;
|
2006-03-10 22:41:14 +00:00
|
|
|
guint64 timestamp;
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (modplug->frequency == 0) {
|
|
|
|
GST_DEBUG_OBJECT (modplug, "no song loaded yet");
|
|
|
|
break;
|
|
|
|
}
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
timestamp = gst_util_uint64_scale_int (modplug->offset, GST_SECOND,
|
|
|
|
modplug->frequency);
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags,
|
|
|
|
&cur_type, &cur, &stop_type, &stop);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (format != GST_FORMAT_TIME) {
|
|
|
|
GST_DEBUG_OBJECT (modplug, "seeking is only supported in TIME format");
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
}
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
/* FIXME: we should be using GstSegment for all this */
|
|
|
|
if (cur_type != GST_SEEK_TYPE_SET || stop_type != GST_SEEK_TYPE_NONE) {
|
|
|
|
GST_DEBUG_OBJECT (modplug, "unsupported seek type");
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
}
|
2002-06-09 19:00:27 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (stop_type == GST_SEEK_TYPE_NONE)
|
|
|
|
stop = GST_CLOCK_TIME_NONE;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
cur = CLAMP (cur, 0, modplug->song_length);
|
2002-12-30 17:21:45 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
GST_DEBUG_OBJECT (modplug, "seek to %" GST_TIME_FORMAT,
|
2006-03-10 22:41:14 +00:00
|
|
|
GST_TIME_ARGS ((guint64) cur));
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
modplug->seek_at = cur;
|
2002-12-30 17:21:45 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
flush = ((flags & GST_SEEK_FLAG_FLUSH) == GST_SEEK_FLAG_FLUSH);
|
2002-02-28 21:10:42 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (flush) {
|
|
|
|
gst_pad_push_event (modplug->srcpad, gst_event_new_flush_start ());
|
|
|
|
} else {
|
|
|
|
gst_pad_stop_task (modplug->sinkpad);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_PAD_STREAM_LOCK (modplug->sinkpad);
|
|
|
|
|
|
|
|
if (flags & GST_SEEK_FLAG_SEGMENT) {
|
|
|
|
gst_element_post_message (GST_ELEMENT (modplug),
|
|
|
|
gst_message_new_segment_start (GST_OBJECT (modplug), format, cur));
|
|
|
|
}
|
|
|
|
if (stop == -1 && modplug->song_length > 0)
|
|
|
|
stop = modplug->song_length;
|
|
|
|
|
|
|
|
if (flush) {
|
|
|
|
gst_pad_push_event (modplug->srcpad, gst_event_new_flush_stop ());
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (modplug, "sending newsegment from %" GST_TIME_FORMAT "-%"
|
2006-03-10 22:41:14 +00:00
|
|
|
GST_TIME_FORMAT ", pos=%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS ((guint64) cur), GST_TIME_ARGS ((guint64) stop),
|
|
|
|
GST_TIME_ARGS ((guint64) cur));
|
2006-03-10 17:10:09 +00:00
|
|
|
|
|
|
|
gst_pad_push_event (modplug->srcpad,
|
|
|
|
gst_event_new_new_segment (FALSE, rate,
|
|
|
|
GST_FORMAT_TIME, cur, stop, cur));
|
|
|
|
|
|
|
|
modplug->offset =
|
|
|
|
gst_util_uint64_scale_int (cur, modplug->frequency, GST_SECOND);
|
|
|
|
|
|
|
|
gst_pad_start_task (modplug->sinkpad,
|
|
|
|
(GstTaskFunction) gst_modplug_loop, modplug);
|
|
|
|
|
|
|
|
GST_PAD_STREAM_UNLOCK (modplug->sinkpad);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = gst_pad_event_default (pad, event);
|
|
|
|
break;
|
2004-03-14 23:20:41 +00:00
|
|
|
}
|
2003-01-19 21:20:40 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_object_unref (modplug);
|
|
|
|
return res;
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 23:20:41 +00:00
|
|
|
static void
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_modplug_fixate (GstPad * pad, GstCaps * caps)
|
2004-03-14 23:20:41 +00:00
|
|
|
{
|
2006-03-10 17:10:09 +00:00
|
|
|
GstStructure *structure;
|
2002-12-30 17:21:45 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
if (gst_structure_fixate_field_nearest_int (structure, "rate", 44100))
|
|
|
|
return;
|
|
|
|
if (gst_structure_fixate_field_nearest_int (structure, "channels", 2))
|
|
|
|
return;
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
static gboolean
|
|
|
|
gst_modplug_load_song (GstModPlug * modplug)
|
2003-07-06 20:49:52 +00:00
|
|
|
{
|
2006-03-10 17:10:09 +00:00
|
|
|
GstCaps *newcaps, *othercaps;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
|
|
|
gint depth;
|
2003-07-06 20:49:52 +00:00
|
|
|
|
2007-08-21 12:59:00 +00:00
|
|
|
GST_DEBUG_OBJECT (modplug, "Setting caps");
|
2003-12-22 01:47:09 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
/* negotiate srcpad caps */
|
2007-08-21 15:59:39 +00:00
|
|
|
if ((othercaps = gst_pad_get_allowed_caps (modplug->srcpad))) {
|
2007-08-21 12:59:00 +00:00
|
|
|
newcaps = gst_caps_copy_nth (othercaps, 0);
|
|
|
|
gst_caps_unref (othercaps);
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("no allowed caps on srcpad, no peer linked");
|
|
|
|
/* FIXME: this can be done in a better way */
|
|
|
|
newcaps =
|
|
|
|
gst_caps_copy_nth (gst_pad_get_pad_template_caps (modplug->srcpad), 0);
|
|
|
|
}
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_pad_fixate_caps (modplug->srcpad, newcaps);
|
|
|
|
gst_pad_set_caps (modplug->srcpad, newcaps);
|
|
|
|
|
|
|
|
/* set up modplug to output the negotiated format */
|
|
|
|
structure = gst_caps_get_structure (newcaps, 0);
|
2003-12-22 01:47:09 +00:00
|
|
|
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
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
modplug->read_samples = 1152;
|
|
|
|
modplug->read_bytes = modplug->read_samples * modplug->channel * depth / 8;
|
|
|
|
|
2007-08-21 12:59:00 +00:00
|
|
|
GST_DEBUG_OBJECT (modplug, "Loading song");
|
|
|
|
|
|
|
|
modplug->mSoundFile = new CSoundFile;
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (modplug->_16bit)
|
|
|
|
modplug->mSoundFile->SetWaveConfig (modplug->frequency, 16,
|
|
|
|
modplug->channel);
|
|
|
|
else
|
|
|
|
modplug->mSoundFile->SetWaveConfig (modplug->frequency, 8,
|
|
|
|
modplug->channel);
|
|
|
|
|
|
|
|
modplug->mSoundFile->SetWaveConfigEx (modplug->surround, !modplug->oversamp,
|
|
|
|
modplug->reverb, true, modplug->megabass, modplug->noise_reduction, true);
|
|
|
|
modplug->mSoundFile->SetResamplingMode (SRCMODE_POLYPHASE);
|
2004-03-09 21:09:11 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (modplug->surround)
|
|
|
|
modplug->mSoundFile->SetSurroundParameters (modplug->surround_depth,
|
|
|
|
modplug->surround_delay);
|
|
|
|
|
|
|
|
if (modplug->megabass)
|
|
|
|
modplug->mSoundFile->SetXBassParameters (modplug->megabass_amount,
|
|
|
|
modplug->megabass_range);
|
|
|
|
|
|
|
|
if (modplug->reverb)
|
|
|
|
modplug->mSoundFile->SetReverbParameters (modplug->reverb_depth,
|
|
|
|
modplug->reverb_delay);
|
|
|
|
|
|
|
|
if (!modplug->mSoundFile->Create (GST_BUFFER_DATA (modplug->buffer),
|
|
|
|
modplug->song_size)) {
|
|
|
|
GST_ELEMENT_ERROR (modplug, STREAM, DECODE, (NULL),
|
|
|
|
("Unable to load song"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
modplug->song_length = modplug->mSoundFile->GetSongTime () * GST_SECOND;
|
|
|
|
modplug->seek_at = -1;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (modplug, "Song length: %" GST_TIME_FORMAT,
|
2006-03-10 22:41:14 +00:00
|
|
|
GST_TIME_ARGS ((guint64) modplug->song_length));
|
2006-03-10 17:10:09 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_modplug_sinkpad_activate (GstPad * pad)
|
|
|
|
{
|
|
|
|
if (!gst_pad_check_pull_range (pad))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gst_pad_activate_pull (pad, TRUE);
|
2003-07-06 20:49:52 +00:00
|
|
|
}
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
static gboolean
|
|
|
|
gst_modplug_sinkpad_activate_pull (GstPad * pad, gboolean active)
|
2004-03-14 10:33:44 +00:00
|
|
|
{
|
2006-03-10 17:10:09 +00:00
|
|
|
GstModPlug *modplug = GST_MODPLUG (GST_OBJECT_PARENT (pad));
|
|
|
|
|
|
|
|
if (active) {
|
|
|
|
return gst_pad_start_task (pad, (GstTaskFunction) gst_modplug_loop,
|
|
|
|
modplug);
|
|
|
|
} else {
|
|
|
|
return gst_pad_stop_task (pad);
|
2004-03-14 10:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
static gboolean
|
|
|
|
gst_modplug_get_upstream_size (GstModPlug * modplug, gint64 * length)
|
2003-01-20 21:02:58 +00:00
|
|
|
{
|
2006-03-10 17:10:09 +00:00
|
|
|
GstFormat format = GST_FORMAT_BYTES;
|
|
|
|
gboolean res = FALSE;
|
|
|
|
GstPad *peer;
|
2003-01-20 21:02:58 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
peer = gst_pad_get_peer (modplug->sinkpad);
|
|
|
|
if (peer == NULL)
|
|
|
|
return FALSE;
|
2003-01-20 21:02:58 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (gst_pad_query_duration (peer, &format, length) && *length >= 0) {
|
|
|
|
res = TRUE;
|
2003-01-20 21:02:58 +00:00
|
|
|
}
|
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_object_unref (peer);
|
|
|
|
return res;
|
2003-01-20 21:02:58 +00:00
|
|
|
}
|
|
|
|
|
2002-12-30 17:21:45 +00:00
|
|
|
static void
|
2006-03-10 17:10:09 +00:00
|
|
|
gst_modplug_loop (GstModPlug * modplug)
|
2002-12-30 17:21:45 +00:00
|
|
|
{
|
2006-03-10 17:10:09 +00:00
|
|
|
GstFlowReturn flow;
|
|
|
|
GstBuffer *out = NULL;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
g_assert (GST_IS_MODPLUG (modplug));
|
2003-01-19 21:20:40 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
/* first, get the size of the song */
|
|
|
|
if (!modplug->song_size) {
|
|
|
|
if (!gst_modplug_get_upstream_size (modplug, &modplug->song_size)) {
|
|
|
|
GST_ELEMENT_ERROR (modplug, STREAM, DECODE, (NULL),
|
|
|
|
("Unable to load song"));
|
|
|
|
goto pause;
|
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (modplug->buffer) {
|
|
|
|
gst_buffer_unref (modplug->buffer);
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
2006-03-10 17:10:09 +00:00
|
|
|
modplug->buffer = gst_buffer_new_and_alloc (modplug->song_size);
|
|
|
|
modplug->offset = 0;
|
|
|
|
}
|
2002-06-11 19:12:51 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
/* read in the song data */
|
|
|
|
if (!modplug->mSoundFile) {
|
|
|
|
GstBuffer *buffer = NULL;
|
|
|
|
guint64 read_size = modplug->song_size - modplug->offset;
|
|
|
|
|
|
|
|
if (read_size > 4096)
|
|
|
|
read_size = 4096;
|
|
|
|
|
|
|
|
flow =
|
|
|
|
gst_pad_pull_range (modplug->sinkpad, modplug->offset, read_size,
|
|
|
|
&buffer);
|
|
|
|
if (flow != GST_FLOW_OK) {
|
|
|
|
GST_ELEMENT_ERROR (modplug, STREAM, DECODE, (NULL),
|
|
|
|
("Unable to load song"));
|
|
|
|
goto pause;
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
2003-01-19 21:20:40 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
/* GST_LOG_OBJECT (modplug, "Read %u bytes", GST_BUFFER_SIZE (buffer)); */
|
|
|
|
g_memmove (GST_BUFFER_DATA (modplug->buffer) + modplug->offset,
|
|
|
|
GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
|
|
|
|
gst_buffer_unref (buffer);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
modplug->offset += read_size;
|
2003-01-20 21:02:58 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
/* actually load it */
|
|
|
|
if (modplug->offset == modplug->song_size) {
|
|
|
|
GstEvent *newsegment;
|
|
|
|
gboolean ok;
|
2003-01-20 21:02:58 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
ok = gst_modplug_load_song (modplug);
|
|
|
|
gst_buffer_unref (modplug->buffer);
|
|
|
|
modplug->buffer = NULL;
|
|
|
|
modplug->offset = 0;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (!ok) {
|
|
|
|
goto pause;
|
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
newsegment = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
|
|
|
|
0, modplug->song_length, 0);
|
|
|
|
gst_pad_push_event (modplug->srcpad, newsegment);
|
|
|
|
} else {
|
|
|
|
/* not fully loaded yet */
|
2002-12-30 17:21:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-03-10 17:10:09 +00:00
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
/* could move this to gst_modplug_src_event
|
|
|
|
* if libmodplug was definitely thread safe.. */
|
|
|
|
if (modplug->seek_at != -1) {
|
|
|
|
gint seek_to_pos;
|
|
|
|
gfloat temp;
|
2003-01-20 21:24:37 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
temp = (gfloat) modplug->song_length / modplug->seek_at;
|
|
|
|
seek_to_pos = (int) (modplug->mSoundFile->GetMaxPosition () / temp);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
GST_DEBUG_OBJECT (modplug, "Seeking to row %d", seek_to_pos);
|
2002-12-30 17:21:45 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
modplug->mSoundFile->SetCurrentPos (seek_to_pos);
|
|
|
|
modplug->seek_at = -1;
|
2002-12-30 17:21:45 +00:00
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
/* read and output a buffer */
|
|
|
|
flow = gst_pad_alloc_buffer_and_set_caps (modplug->srcpad,
|
|
|
|
GST_BUFFER_OFFSET_NONE, modplug->read_bytes,
|
|
|
|
GST_PAD_CAPS (modplug->srcpad), &out);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (flow != GST_FLOW_OK) {
|
|
|
|
GST_LOG_OBJECT (modplug, "pad alloc flow: %s", gst_flow_get_name (flow));
|
|
|
|
goto pause;
|
|
|
|
}
|
2002-06-11 19:12:51 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (!modplug->mSoundFile->Read (GST_BUFFER_DATA (out), modplug->read_bytes))
|
|
|
|
goto eos;
|
2002-06-11 19:12:51 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
GST_BUFFER_SIZE (out) = modplug->read_bytes;
|
|
|
|
GST_BUFFER_DURATION (out) =
|
|
|
|
gst_util_uint64_scale_int (modplug->read_samples, GST_SECOND,
|
|
|
|
modplug->frequency);
|
|
|
|
GST_BUFFER_OFFSET (out) = modplug->offset;
|
|
|
|
GST_BUFFER_TIMESTAMP (out) =
|
|
|
|
gst_util_uint64_scale_int (modplug->offset, GST_SECOND,
|
|
|
|
modplug->frequency);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
modplug->offset += modplug->read_samples;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
flow = gst_pad_push (modplug->srcpad, out);
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
if (flow != GST_FLOW_OK) {
|
|
|
|
GST_LOG_OBJECT (modplug, "pad push flow: %s", gst_flow_get_name (flow));
|
|
|
|
goto pause;
|
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
return;
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
eos:
|
|
|
|
{
|
|
|
|
gst_buffer_unref (out);
|
|
|
|
GST_INFO_OBJECT (modplug, "EOS");
|
|
|
|
gst_pad_push_event (modplug->srcpad, gst_event_new_eos ());
|
|
|
|
goto pause;
|
|
|
|
}
|
2004-03-14 23:20:41 +00:00
|
|
|
|
2006-03-10 17:10:09 +00:00
|
|
|
pause:
|
|
|
|
{
|
|
|
|
GST_INFO_OBJECT (modplug, "Pausing");
|
|
|
|
gst_pad_pause_task (modplug->sinkpad);
|
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;
|
2006-03-10 17:10:09 +00:00
|
|
|
GstStateChangeReturn ret;
|
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_READY_TO_PAUSED:
|
2006-03-10 17:10:09 +00:00
|
|
|
modplug->buffer = NULL;
|
|
|
|
modplug->offset = 0;
|
2002-12-30 17:21:45 +00:00
|
|
|
modplug->song_size = 0;
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
2006-03-10 17:10:09 +00:00
|
|
|
default:
|
2002-06-09 19:00:27 +00:00
|
|
|
break;
|
2006-03-10 17:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2006-03-10 17:10:09 +00:00
|
|
|
if (modplug->buffer) {
|
|
|
|
gst_buffer_unref (modplug->buffer);
|
|
|
|
modplug->buffer = NULL;
|
|
|
|
}
|
|
|
|
if (modplug->mSoundFile) {
|
2004-03-15 19:32:27 +00:00
|
|
|
modplug->mSoundFile->Destroy ();
|
2006-03-10 17:10:09 +00:00
|
|
|
modplug->mSoundFile = NULL;
|
2003-06-27 23:46:13 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
{
|
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",
|
2006-04-03 10:34:54 +00:00
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|