Andy Wingo | b0c01cd | 2002-03-20 21:45:04 +0000 | [diff] [blame] | 1 | /* GStreamer |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 2 | * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public |
| 15 | * License along with this library; if not, write to the |
Tim-Philipp Müller | 9e1b75f | 2012-11-03 20:38:00 +0000 | [diff] [blame] | 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 18 | */ |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 19 | |
Jeremy Simon | 870168f | 2002-03-01 17:25:42 +0000 | [diff] [blame] | 20 | /* |
| 21 | Code based on modplugxmms |
| 22 | XMMS plugin: |
| 23 | Kenton Varda <temporal@gauge3d.org> |
| 24 | Sound Engine: |
| 25 | Olivier Lapicque <olivierl@jps.net> |
| 26 | */ |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 27 | |
Stefan Kost | b28ee64 | 2007-07-03 07:52:52 +0000 | [diff] [blame] | 28 | /** |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 29 | * SECTION:element-modplug |
| 30 | * |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 31 | * Modplug uses the <ulink url="http://modplug-xmms.sourceforge.net/">modplug</ulink> |
| 32 | * library to decode tracked music in the MOD/S3M/XM/IT and related formats. |
Stefan Kost | 2affd3d | 2008-06-13 11:59:23 +0000 | [diff] [blame] | 33 | * |
| 34 | * <refsect2> |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 35 | * <title>Example pipeline</title> |
Stefan Kost | 2affd3d | 2008-06-13 11:59:23 +0000 | [diff] [blame] | 36 | * |[ |
Luis de Bethencourt | 4d6b9c4 | 2015-02-24 13:16:21 +0000 | [diff] [blame] | 37 | * gst-launch-1.0 -v filesrc location=1990s-nostalgia.xm ! modplug ! audioconvert ! alsasink |
Stefan Kost | 2affd3d | 2008-06-13 11:59:23 +0000 | [diff] [blame] | 38 | * ]| Play a FastTracker xm file. |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 39 | * </refsect2> |
| 40 | */ |
| 41 | |
Ronald S. Bultje | cb90622 | 2003-11-07 12:47:02 +0000 | [diff] [blame] | 42 | #ifdef HAVE_CONFIG_H |
| 43 | #include "config.h" |
| 44 | #endif |
| 45 | |
Benjamin Otte | 06242ff | 2010-03-24 15:05:50 +0100 | [diff] [blame] | 46 | /* Required to not get an undefined warning |
| 47 | * https://bugzilla.gnome.org/show_bug.cgi?id=613795 |
| 48 | */ |
| 49 | #ifndef WORDS_BIGENDIAN |
| 50 | #define WORDS_BIGENDIAN 0 |
| 51 | #endif |
| 52 | |
Iain Lane | fd4cb22 | 2013-09-10 08:48:32 +0000 | [diff] [blame] | 53 | #include <libmodplug/stdafx.h> |
LRN | d4ff729 | 2009-03-19 15:37:17 -0700 | [diff] [blame] | 54 | #include <libmodplug/sndfile.h> |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 55 | |
| 56 | #include "gstmodplug.h" |
| 57 | |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 58 | #include <gst/gst.h> |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 59 | #include <stdlib.h> |
Jeremy Simon | 8029993 | 2002-11-17 12:23:43 +0000 | [diff] [blame] | 60 | #include <gst/audio/audio.h> |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 61 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 62 | GST_DEBUG_CATEGORY_STATIC (modplug_debug); |
| 63 | #define GST_CAT_DEFAULT modplug_debug |
| 64 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 65 | enum |
| 66 | { |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 67 | ARG_0, |
| 68 | ARG_SONGNAME, |
| 69 | ARG_REVERB, |
| 70 | ARG_REVERB_DEPTH, |
| 71 | ARG_REVERB_DELAY, |
| 72 | ARG_MEGABASS, |
| 73 | ARG_MEGABASS_AMOUNT, |
| 74 | ARG_MEGABASS_RANGE, |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 75 | ARG_NOISE_REDUCTION, |
| 76 | ARG_SURROUND, |
| 77 | ARG_SURROUND_DEPTH, |
| 78 | ARG_SURROUND_DELAY, |
David Schleef | b144bc6 | 2003-12-22 01:47:09 +0000 | [diff] [blame] | 79 | ARG_OVERSAMP |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 82 | #define DEFAULT_REVERB FALSE |
| 83 | #define DEFAULT_REVERB_DEPTH 30 |
| 84 | #define DEFAULT_REVERB_DELAY 100 |
| 85 | #define DEFAULT_MEGABASS FALSE |
| 86 | #define DEFAULT_MEGABASS_AMOUNT 40 |
| 87 | #define DEFAULT_MEGABASS_RANGE 30 |
| 88 | #define DEFAULT_SURROUND TRUE |
| 89 | #define DEFAULT_SURROUND_DEPTH 20 |
| 90 | #define DEFAULT_SURROUND_DELAY 20 |
| 91 | #define DEFAULT_OVERSAMP TRUE |
| 92 | #define DEFAULT_NOISE_REDUCTION TRUE |
| 93 | |
Sebastian Dröge | bce2f8f | 2016-02-18 00:24:04 +0200 | [diff] [blame] | 94 | #define FORMATS "{ " GST_AUDIO_NE (S32) ", " GST_AUDIO_NE (S16) ", U8 }" |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 95 | |
David Schleef | b144bc6 | 2003-12-22 01:47:09 +0000 | [diff] [blame] | 96 | static GstStaticPadTemplate modplug_src_template_factory = |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 97 | GST_STATIC_PAD_TEMPLATE ("src", |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 98 | GST_PAD_SRC, |
| 99 | GST_PAD_ALWAYS, |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 100 | GST_STATIC_CAPS ("audio/x-raw," |
| 101 | " format = (string) " FORMATS ", " |
| 102 | " layout = (string) interleaved, " |
Kaj-Michael Lang | 212cf43 | 2009-12-29 16:07:59 +0200 | [diff] [blame] | 103 | " rate = (int) { 8000, 11025, 22050, 44100 }," |
Stefan Kost | 77d0162 | 2007-08-21 12:59:00 +0000 | [diff] [blame] | 104 | " channels = (int) [ 1, 2 ]")); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 105 | |
David Schleef | b144bc6 | 2003-12-22 01:47:09 +0000 | [diff] [blame] | 106 | static GstStaticPadTemplate modplug_sink_template_factory = |
Hans de Goede | e4afe4b | 2007-07-14 18:48:25 +0000 | [diff] [blame] | 107 | GST_STATIC_PAD_TEMPLATE ("sink", |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 108 | GST_PAD_SINK, |
| 109 | GST_PAD_ALWAYS, |
Hans de Goede | e4afe4b | 2007-07-14 18:48:25 +0000 | [diff] [blame] | 110 | GST_STATIC_CAPS ("audio/x-mod; audio/x-xm; audio/x-it; audio/x-s3m; " |
| 111 | "audio/x-stm")); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 112 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 113 | static void gst_modplug_dispose (GObject * object); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 114 | static void gst_modplug_set_property (GObject * object, |
| 115 | guint id, const GValue * value, GParamSpec * pspec); |
| 116 | static void gst_modplug_get_property (GObject * object, |
| 117 | guint id, GValue * value, GParamSpec * pspec); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 118 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 119 | static gboolean gst_modplug_src_event (GstPad * pad, GstObject * parent, |
| 120 | GstEvent * event); |
| 121 | static gboolean gst_modplug_src_query (GstPad * pad, GstObject * parent, |
| 122 | GstQuery * query); |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 123 | static GstStateChangeReturn gst_modplug_change_state (GstElement * element, |
| 124 | GstStateChange transition); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 125 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 126 | static gboolean gst_modplug_sinkpad_activate (GstPad * pad, GstObject * parent); |
| 127 | static gboolean gst_modplug_sinkpad_activate_mode (GstPad * pad, |
| 128 | GstObject * parent, GstPadMode mode, gboolean active); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 129 | static void gst_modplug_loop (GstModPlug * element); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 130 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 131 | #define parent_class gst_modplug_parent_class |
| 132 | G_DEFINE_TYPE (GstModPlug, gst_modplug, GST_TYPE_ELEMENT); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 133 | |
| 134 | static void |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 135 | gst_modplug_class_init (GstModPlugClass * klass) |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 136 | { |
| 137 | GObjectClass *gobject_class; |
| 138 | GstElementClass *gstelement_class; |
| 139 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 140 | gobject_class = (GObjectClass *) klass; |
| 141 | gstelement_class = (GstElementClass *) klass; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 142 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 143 | gobject_class->set_property = gst_modplug_set_property; |
| 144 | gobject_class->get_property = gst_modplug_get_property; |
| 145 | gobject_class->dispose = gst_modplug_dispose; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 146 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 147 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SONGNAME, |
| 148 | g_param_spec_string ("songname", "Songname", "The song name", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 149 | NULL, (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 150 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 151 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 152 | g_param_spec_boolean ("reverb", "reverb", "Reverb", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 153 | DEFAULT_REVERB, |
| 154 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 155 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 156 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB_DEPTH, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 157 | g_param_spec_int ("reverb-depth", "reverb depth", "Reverb depth", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 158 | 0, 100, DEFAULT_REVERB_DEPTH, |
| 159 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 160 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 161 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB_DELAY, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 162 | g_param_spec_int ("reverb-delay", "reverb delay", "Reverb delay", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 163 | 0, 200, DEFAULT_REVERB_DELAY, |
| 164 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 165 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 166 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MEGABASS, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 167 | g_param_spec_boolean ("megabass", "megabass", "Megabass", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 168 | DEFAULT_MEGABASS, |
| 169 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 170 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 171 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MEGABASS_AMOUNT, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 172 | g_param_spec_int ("megabass-amount", "megabass amount", "Megabass amount", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 173 | 0, 100, DEFAULT_MEGABASS_AMOUNT, |
| 174 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 175 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 176 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MEGABASS_RANGE, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 177 | g_param_spec_int ("megabass-range", "megabass range", "Megabass range", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 178 | 0, 100, DEFAULT_MEGABASS_RANGE, |
| 179 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 180 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 181 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 182 | g_param_spec_boolean ("surround", "surround", "Surround", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 183 | DEFAULT_SURROUND, |
| 184 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 185 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 186 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND_DEPTH, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 187 | g_param_spec_int ("surround-depth", "surround depth", "Surround depth", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 188 | 0, 100, DEFAULT_SURROUND_DEPTH, |
| 189 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 190 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 191 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND_DELAY, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 192 | g_param_spec_int ("surround-delay", "surround delay", "Surround delay", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 193 | 0, 40, DEFAULT_SURROUND_DELAY, |
| 194 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 195 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 196 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_OVERSAMP, |
| 197 | g_param_spec_boolean ("oversamp", "oversamp", "oversamp", |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 198 | DEFAULT_OVERSAMP, |
| 199 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 200 | |
| 201 | g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NOISE_REDUCTION, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 202 | g_param_spec_boolean ("noise-reduction", "noise reduction", |
| 203 | "noise reduction", DEFAULT_NOISE_REDUCTION, |
Stefan Kost | 0387a89 | 2010-10-19 16:23:23 +0300 | [diff] [blame] | 204 | (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 205 | |
Jens Granseuer | 9b1bffb | 2007-01-03 16:41:10 +0000 | [diff] [blame] | 206 | gstelement_class->change_state = gst_modplug_change_state; |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 207 | |
Vineeth TM | 8cdfb13 | 2016-03-04 15:50:26 +0900 | [diff] [blame] | 208 | gst_element_class_add_static_pad_template (gstelement_class, &modplug_sink_template_factory); |
| 209 | gst_element_class_add_static_pad_template (gstelement_class, &modplug_src_template_factory); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 210 | |
Tim-Philipp Müller | 32ba17c | 2012-10-17 17:34:26 +0100 | [diff] [blame] | 211 | gst_element_class_set_static_metadata (gstelement_class, "ModPlug", |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 212 | "Codec/Decoder/Audio", "Module decoder based on modplug engine", |
| 213 | "Jeremy SIMON <jsimon13@yahoo.fr>"); |
| 214 | |
| 215 | GST_DEBUG_CATEGORY_INIT (modplug_debug, "modplug", 0, "ModPlug element"); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 218 | static void |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 219 | gst_modplug_init (GstModPlug * modplug) |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 220 | { |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 221 | /* create the sink and src pads */ |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 222 | modplug->sinkpad = |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 223 | gst_pad_new_from_static_template (&modplug_sink_template_factory, "sink"); |
| 224 | gst_pad_set_activate_function (modplug->sinkpad, |
| 225 | GST_DEBUG_FUNCPTR (gst_modplug_sinkpad_activate)); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 226 | gst_pad_set_activatemode_function (modplug->sinkpad, |
| 227 | GST_DEBUG_FUNCPTR (gst_modplug_sinkpad_activate_mode)); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 228 | gst_element_add_pad (GST_ELEMENT (modplug), modplug->sinkpad); |
Jeremy Simon | 8029993 | 2002-11-17 12:23:43 +0000 | [diff] [blame] | 229 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 230 | modplug->srcpad = |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 231 | gst_pad_new_from_static_template (&modplug_src_template_factory, "src"); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 232 | gst_pad_set_event_function (modplug->srcpad, |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 233 | GST_DEBUG_FUNCPTR (gst_modplug_src_event)); |
| 234 | gst_pad_set_query_function (modplug->srcpad, |
| 235 | GST_DEBUG_FUNCPTR (gst_modplug_src_query)); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 236 | gst_element_add_pad (GST_ELEMENT (modplug), modplug->srcpad); |
| 237 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 238 | modplug->reverb = DEFAULT_REVERB; |
| 239 | modplug->reverb_depth = DEFAULT_REVERB_DEPTH; |
| 240 | modplug->reverb_delay = DEFAULT_REVERB_DELAY; |
| 241 | modplug->megabass = DEFAULT_MEGABASS; |
| 242 | modplug->megabass_amount = DEFAULT_MEGABASS_AMOUNT; |
| 243 | modplug->megabass_range = DEFAULT_MEGABASS_RANGE; |
| 244 | modplug->surround = DEFAULT_SURROUND; |
| 245 | modplug->surround_depth = DEFAULT_SURROUND_DEPTH; |
| 246 | modplug->surround_delay = DEFAULT_SURROUND_DELAY; |
| 247 | modplug->oversamp = DEFAULT_OVERSAMP; |
| 248 | modplug->noise_reduction = DEFAULT_NOISE_REDUCTION; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 249 | |
Kaj-Michael Lang | 212cf43 | 2009-12-29 16:07:59 +0200 | [diff] [blame] | 250 | modplug->bits = 16; |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 251 | modplug->channel = 2; |
| 252 | modplug->frequency = 44100; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 253 | } |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 254 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 255 | |
| 256 | static void |
| 257 | gst_modplug_dispose (GObject * object) |
| 258 | { |
| 259 | GstModPlug *modplug = GST_MODPLUG (object); |
| 260 | |
| 261 | G_OBJECT_CLASS (parent_class)->dispose (object); |
| 262 | |
| 263 | if (modplug->buffer) { |
| 264 | gst_buffer_unref (modplug->buffer); |
| 265 | modplug->buffer = NULL; |
| 266 | } |
| 267 | } |
| 268 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 269 | static gboolean |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 270 | gst_modplug_src_query (GstPad * pad, GstObject * parent, GstQuery * query) |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 271 | { |
| 272 | GstModPlug *modplug; |
| 273 | gboolean res = FALSE; |
| 274 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 275 | modplug = GST_MODPLUG (parent); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 276 | |
| 277 | switch (GST_QUERY_TYPE (query)) { |
| 278 | case GST_QUERY_DURATION: |
| 279 | { |
| 280 | GstFormat format; |
| 281 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 282 | if (!modplug->mSoundFile) |
| 283 | goto done; |
| 284 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 285 | gst_query_parse_duration (query, &format, NULL); |
| 286 | if (format == GST_FORMAT_TIME) { |
| 287 | gst_query_set_duration (query, format, modplug->song_length); |
| 288 | res = TRUE; |
| 289 | } |
| 290 | } |
| 291 | break; |
| 292 | case GST_QUERY_POSITION: |
| 293 | { |
| 294 | GstFormat format; |
| 295 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 296 | if (!modplug->mSoundFile) |
| 297 | goto done; |
| 298 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 299 | gst_query_parse_position (query, &format, NULL); |
| 300 | if (format == GST_FORMAT_TIME) { |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 301 | gint64 pos; |
| 302 | |
Jonathan Matthew | baf6486 | 2006-12-11 09:51:17 +0000 | [diff] [blame] | 303 | pos = (modplug->song_length * modplug->mSoundFile->GetCurrentPos ()); |
| 304 | pos /= modplug->mSoundFile->GetMaxPosition (); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 305 | gst_query_set_position (query, format, pos); |
| 306 | res = TRUE; |
| 307 | } |
| 308 | } |
| 309 | break; |
| 310 | default: |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 311 | res = gst_pad_query_default (pad, parent, query); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 312 | break; |
| 313 | } |
| 314 | |
| 315 | done: |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 316 | return res; |
| 317 | } |
| 318 | |
| 319 | static gboolean |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 320 | gst_modplug_do_seek (GstModPlug * modplug, GstEvent * event) |
| 321 | { |
| 322 | gdouble rate; |
| 323 | GstFormat format; |
| 324 | GstSeekFlags flags; |
| 325 | GstSeekType cur_type, stop_type; |
| 326 | gboolean flush; |
| 327 | gint64 cur, stop; |
| 328 | GstSegment seg; |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 329 | |
| 330 | if (modplug->frequency == 0) |
| 331 | goto no_song; |
| 332 | |
Stefan Sauer | 0e3917b | 2013-12-20 18:12:53 +0100 | [diff] [blame] | 333 | gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &cur, |
| 334 | &stop_type, &stop); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 335 | |
| 336 | if (format != GST_FORMAT_TIME) |
| 337 | goto no_time; |
| 338 | |
| 339 | /* FIXME: we should be using GstSegment for all this */ |
| 340 | if (cur_type != GST_SEEK_TYPE_SET || stop_type != GST_SEEK_TYPE_NONE) |
| 341 | goto not_supported; |
| 342 | |
| 343 | if (stop_type == GST_SEEK_TYPE_NONE) |
| 344 | stop = GST_CLOCK_TIME_NONE; |
Stefan Sauer | 0e3917b | 2013-12-20 18:12:53 +0100 | [diff] [blame] | 345 | if (!GST_CLOCK_TIME_IS_VALID (stop) && modplug->song_length > 0) |
| 346 | stop = modplug->song_length; |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 347 | |
Stefan Sauer | 0e3917b | 2013-12-20 18:12:53 +0100 | [diff] [blame] | 348 | cur = CLAMP (cur, -1, modplug->song_length); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 349 | |
| 350 | GST_DEBUG_OBJECT (modplug, "seek to %" GST_TIME_FORMAT, |
| 351 | GST_TIME_ARGS ((guint64) cur)); |
| 352 | |
| 353 | modplug->seek_at = cur; |
| 354 | |
| 355 | flush = ((flags & GST_SEEK_FLAG_FLUSH) == GST_SEEK_FLAG_FLUSH); |
| 356 | |
| 357 | if (flush) { |
| 358 | gst_pad_push_event (modplug->srcpad, gst_event_new_flush_start ()); |
| 359 | } else { |
| 360 | gst_pad_stop_task (modplug->sinkpad); |
| 361 | } |
| 362 | |
| 363 | GST_PAD_STREAM_LOCK (modplug->sinkpad); |
| 364 | |
| 365 | if (flags & GST_SEEK_FLAG_SEGMENT) { |
| 366 | gst_element_post_message (GST_ELEMENT (modplug), |
| 367 | gst_message_new_segment_start (GST_OBJECT (modplug), format, cur)); |
| 368 | } |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 369 | |
| 370 | if (flush) { |
| 371 | gst_pad_push_event (modplug->srcpad, gst_event_new_flush_stop (TRUE)); |
| 372 | } |
| 373 | |
| 374 | GST_LOG_OBJECT (modplug, "sending newsegment from %" GST_TIME_FORMAT "-%" |
| 375 | GST_TIME_FORMAT ", pos=%" GST_TIME_FORMAT, |
| 376 | GST_TIME_ARGS ((guint64) cur), GST_TIME_ARGS ((guint64) stop), |
| 377 | GST_TIME_ARGS ((guint64) cur)); |
| 378 | |
| 379 | gst_segment_init (&seg, GST_FORMAT_TIME); |
| 380 | seg.rate = rate; |
| 381 | seg.start = cur; |
| 382 | seg.stop = stop; |
| 383 | seg.time = cur; |
| 384 | gst_pad_push_event (modplug->srcpad, gst_event_new_segment (&seg)); |
| 385 | |
| 386 | modplug->offset = |
| 387 | gst_util_uint64_scale_int (cur, modplug->frequency, GST_SECOND); |
| 388 | |
| 389 | gst_pad_start_task (modplug->sinkpad, |
Wim Taymans | dbed726 | 2012-06-20 10:34:48 +0200 | [diff] [blame] | 390 | (GstTaskFunction) gst_modplug_loop, modplug, NULL); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 391 | |
| 392 | GST_PAD_STREAM_UNLOCK (modplug->sinkpad); |
| 393 | |
| 394 | return TRUE; |
| 395 | |
| 396 | /* ERROR */ |
| 397 | no_song: |
| 398 | { |
| 399 | GST_DEBUG_OBJECT (modplug, "no song loaded yet"); |
| 400 | return FALSE; |
| 401 | } |
| 402 | no_time: |
| 403 | { |
| 404 | GST_DEBUG_OBJECT (modplug, "seeking is only supported in TIME format"); |
| 405 | return FALSE; |
| 406 | } |
| 407 | not_supported: |
| 408 | { |
| 409 | GST_DEBUG_OBJECT (modplug, "unsupported seek type"); |
| 410 | return FALSE; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | static gboolean |
| 415 | gst_modplug_src_event (GstPad * pad, GstObject * parent, GstEvent * event) |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 416 | { |
| 417 | GstModPlug *modplug; |
| 418 | gboolean res = FALSE; |
| 419 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 420 | modplug = GST_MODPLUG (parent); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 421 | |
| 422 | switch (GST_EVENT_TYPE (event)) { |
| 423 | case GST_EVENT_SEEK: |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 424 | res = gst_modplug_do_seek (modplug, event); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 425 | break; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 426 | default: |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 427 | res = gst_pad_event_default (pad, parent, event); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 428 | break; |
| 429 | } |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 430 | return res; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 433 | static gboolean |
| 434 | gst_modplug_load_song (GstModPlug * modplug) |
| 435 | { |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 436 | GstCaps *newcaps; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 437 | GstStructure *structure; |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 438 | GstMapInfo map; |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 439 | const gchar *format; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 440 | |
Stefan Kost | 77d0162 | 2007-08-21 12:59:00 +0000 | [diff] [blame] | 441 | GST_DEBUG_OBJECT (modplug, "Setting caps"); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 442 | |
| 443 | /* negotiate srcpad caps */ |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 444 | if ((newcaps = gst_pad_get_allowed_caps (modplug->srcpad)) == NULL) { |
| 445 | newcaps = gst_pad_get_pad_template_caps (modplug->srcpad); |
Stefan Kost | 77d0162 | 2007-08-21 12:59:00 +0000 | [diff] [blame] | 446 | } |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 447 | newcaps = gst_caps_make_writable (newcaps); |
| 448 | |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 449 | GST_DEBUG_OBJECT (modplug, "allowed caps %" GST_PTR_FORMAT, newcaps); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 450 | |
| 451 | structure = gst_caps_get_structure (newcaps, 0); |
| 452 | |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 453 | if (!gst_structure_fixate_field_string (structure, "format", |
| 454 | GST_AUDIO_NE (S16))) |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 455 | GST_WARNING_OBJECT (modplug, "Failed to fixate format to S16NE"); |
| 456 | if (!gst_structure_fixate_field_nearest_int (structure, "rate", 44100)) |
| 457 | GST_WARNING_OBJECT (modplug, "Failed to fixate rate to 44100"); |
| 458 | if (!gst_structure_fixate_field_nearest_int (structure, "channels", 2)) |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 459 | GST_WARNING_OBJECT (modplug, |
| 460 | "Failed to fixate number of channels to stereo"); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 461 | |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 462 | GST_DEBUG_OBJECT (modplug, "normalized caps %" GST_PTR_FORMAT, newcaps); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 463 | |
Wim Taymans | 77299ba | 2012-03-11 19:06:59 +0100 | [diff] [blame] | 464 | newcaps = gst_caps_fixate (newcaps); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 465 | |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 466 | GST_DEBUG_OBJECT (modplug, "fixated caps %" GST_PTR_FORMAT, newcaps); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 467 | |
| 468 | /* set up modplug to output the negotiated format */ |
| 469 | structure = gst_caps_get_structure (newcaps, 0); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 470 | format = gst_structure_get_string (structure, "format"); |
| 471 | |
| 472 | if (g_str_equal (format, GST_AUDIO_NE (S32))) |
| 473 | modplug->bits = 32; |
| 474 | else if (g_str_equal (format, GST_AUDIO_NE (S16))) |
| 475 | modplug->bits = 16; |
| 476 | else |
| 477 | modplug->bits = 8; |
| 478 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 479 | gst_structure_get_int (structure, "channels", &modplug->channel); |
| 480 | gst_structure_get_int (structure, "rate", &modplug->frequency); |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 481 | |
| 482 | GST_DEBUG_OBJECT (modplug, |
Stefan Sauer | bece1c9 | 2012-03-23 18:16:08 +0100 | [diff] [blame] | 483 | "Audio settings: %d bits, %d channel(s), %d Hz sampling rate", |
| 484 | modplug->bits, modplug->channel, modplug->frequency); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 485 | |
Vincent Penquerc'h | 57ec735 | 2012-01-10 17:27:54 +0000 | [diff] [blame] | 486 | gst_pad_set_caps (modplug->srcpad, newcaps); |
| 487 | gst_caps_unref (newcaps); |
| 488 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 489 | modplug->read_samples = 1152; |
Sebastian Dröge | b648638 | 2010-01-04 10:23:37 +0100 | [diff] [blame] | 490 | modplug->read_bytes = |
| 491 | modplug->read_samples * modplug->channel * modplug->bits / 8; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 492 | |
Stefan Kost | 77d0162 | 2007-08-21 12:59:00 +0000 | [diff] [blame] | 493 | GST_DEBUG_OBJECT (modplug, "Loading song"); |
| 494 | |
| 495 | modplug->mSoundFile = new CSoundFile; |
| 496 | |
Kaj-Michael Lang | 212cf43 | 2009-12-29 16:07:59 +0200 | [diff] [blame] | 497 | modplug->mSoundFile->SetWaveConfig (modplug->frequency, modplug->bits, |
Sebastian Dröge | b648638 | 2010-01-04 10:23:37 +0100 | [diff] [blame] | 498 | modplug->channel); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 499 | |
| 500 | modplug->mSoundFile->SetWaveConfigEx (modplug->surround, !modplug->oversamp, |
| 501 | modplug->reverb, true, modplug->megabass, modplug->noise_reduction, true); |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 502 | modplug->mSoundFile->SetResamplingMode (SRCMODE_POLYPHASE); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 503 | |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 504 | if (modplug->surround) |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 505 | modplug->mSoundFile->SetSurroundParameters (modplug->surround_depth, |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 506 | modplug->surround_delay); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 507 | |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 508 | if (modplug->megabass) |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 509 | modplug->mSoundFile->SetXBassParameters (modplug->megabass_amount, |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 510 | modplug->megabass_range); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 511 | |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 512 | if (modplug->reverb) |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 513 | modplug->mSoundFile->SetReverbParameters (modplug->reverb_depth, |
Thomas Vander Stichele | 4fd57bb | 2004-03-15 19:32:27 +0000 | [diff] [blame] | 514 | modplug->reverb_delay); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 515 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 516 | |
| 517 | gst_buffer_map (modplug->buffer, &map, GST_MAP_READ); |
| 518 | if (!modplug->mSoundFile->Create (map.data, modplug->song_size)) |
| 519 | goto load_error; |
| 520 | gst_buffer_unmap (modplug->buffer, &map); |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 521 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 522 | modplug->song_length = modplug->mSoundFile->GetSongTime () * GST_SECOND; |
| 523 | modplug->seek_at = -1; |
| 524 | |
| 525 | GST_INFO_OBJECT (modplug, "Song length: %" GST_TIME_FORMAT, |
Julien Moutte | ca11b12 | 2006-03-10 22:41:14 +0000 | [diff] [blame] | 526 | GST_TIME_ARGS ((guint64) modplug->song_length)); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 527 | |
| 528 | return TRUE; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 529 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 530 | /* ERRORS */ |
| 531 | load_error: |
| 532 | { |
| 533 | gst_buffer_unmap (modplug->buffer, &map); |
| 534 | GST_ELEMENT_ERROR (modplug, STREAM, DECODE, (NULL), |
| 535 | ("Unable to load song")); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 536 | return FALSE; |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 537 | } |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static gboolean |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 541 | gst_modplug_sinkpad_activate (GstPad * sinkpad, GstObject * parent) |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 542 | { |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 543 | GstQuery *query; |
| 544 | gboolean pull_mode; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 545 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 546 | query = gst_query_new_scheduling (); |
| 547 | |
| 548 | if (!gst_pad_peer_query (sinkpad, query)) { |
| 549 | gst_query_unref (query); |
| 550 | goto activate_push; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 551 | } |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 552 | |
Mark Nauwelaerts | b807753 | 2012-09-11 17:47:16 +0200 | [diff] [blame] | 553 | pull_mode = gst_query_has_scheduling_mode_with_flags (query, |
| 554 | GST_PAD_MODE_PULL, GST_SCHEDULING_FLAG_SEEKABLE); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 555 | gst_query_unref (query); |
| 556 | |
| 557 | if (!pull_mode) |
| 558 | goto activate_push; |
| 559 | |
| 560 | GST_DEBUG_OBJECT (sinkpad, "activating pull"); |
| 561 | return gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PULL, TRUE); |
| 562 | |
| 563 | activate_push: |
| 564 | { |
| 565 | GST_DEBUG_OBJECT (sinkpad, "activating push"); |
| 566 | return gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PUSH, TRUE); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | static gboolean |
| 571 | gst_modplug_sinkpad_activate_mode (GstPad * pad, GstObject * parent, |
| 572 | GstPadMode mode, gboolean active) |
| 573 | { |
| 574 | GstModPlug *modplug = GST_MODPLUG (parent); |
| 575 | gboolean res; |
| 576 | |
| 577 | switch (mode) { |
| 578 | case GST_PAD_MODE_PUSH: |
| 579 | res = TRUE; |
| 580 | break; |
| 581 | case GST_PAD_MODE_PULL: |
| 582 | if (active) { |
| 583 | res = gst_pad_start_task (pad, (GstTaskFunction) gst_modplug_loop, |
Wim Taymans | dbed726 | 2012-06-20 10:34:48 +0200 | [diff] [blame] | 584 | modplug, NULL); |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 585 | } else { |
| 586 | res = gst_pad_stop_task (pad); |
| 587 | } |
| 588 | break; |
| 589 | default: |
| 590 | res = FALSE; |
| 591 | break; |
| 592 | } |
| 593 | return res; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | static gboolean |
| 597 | gst_modplug_get_upstream_size (GstModPlug * modplug, gint64 * length) |
| 598 | { |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 599 | gboolean res = FALSE; |
| 600 | GstPad *peer; |
| 601 | |
| 602 | peer = gst_pad_get_peer (modplug->sinkpad); |
| 603 | if (peer == NULL) |
| 604 | return FALSE; |
| 605 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 606 | if (gst_pad_query_duration (peer, GST_FORMAT_BYTES, length) && *length >= 0) { |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 607 | res = TRUE; |
| 608 | } |
| 609 | |
| 610 | gst_object_unref (peer); |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 611 | return res; |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 614 | static void |
| 615 | gst_modplug_loop (GstModPlug * modplug) |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 616 | { |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 617 | GstFlowReturn flow; |
| 618 | GstBuffer *out = NULL; |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 619 | GstMapInfo map; |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 620 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 621 | g_assert (GST_IS_MODPLUG (modplug)); |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 622 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 623 | /* first, get the size of the song */ |
| 624 | if (!modplug->song_size) { |
| 625 | if (!gst_modplug_get_upstream_size (modplug, &modplug->song_size)) { |
| 626 | GST_ELEMENT_ERROR (modplug, STREAM, DECODE, (NULL), |
| 627 | ("Unable to load song")); |
| 628 | goto pause; |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 629 | } |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 630 | |
| 631 | if (modplug->buffer) { |
| 632 | gst_buffer_unref (modplug->buffer); |
| 633 | } |
| 634 | modplug->buffer = gst_buffer_new_and_alloc (modplug->song_size); |
| 635 | modplug->offset = 0; |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 636 | } |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 637 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 638 | /* read in the song data */ |
| 639 | if (!modplug->mSoundFile) { |
| 640 | GstBuffer *buffer = NULL; |
| 641 | guint64 read_size = modplug->song_size - modplug->offset; |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 642 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 643 | if (read_size > 4096) |
| 644 | read_size = 4096; |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 645 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 646 | flow = |
| 647 | gst_pad_pull_range (modplug->sinkpad, modplug->offset, read_size, |
| 648 | &buffer); |
| 649 | if (flow != GST_FLOW_OK) { |
| 650 | GST_ELEMENT_ERROR (modplug, STREAM, DECODE, (NULL), |
| 651 | ("Unable to load song")); |
| 652 | goto pause; |
| 653 | } |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 654 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 655 | /* GST_LOG_OBJECT (modplug, "Read %u bytes", GST_BUFFER_SIZE (buffer)); */ |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 656 | gst_buffer_map (buffer, &map, GST_MAP_READ); |
| 657 | gst_buffer_fill (modplug->buffer, modplug->offset, map.data, map.size); |
| 658 | gst_buffer_unmap (buffer, &map); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 659 | gst_buffer_unref (buffer); |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 660 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 661 | modplug->offset += read_size; |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 662 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 663 | /* actually load it */ |
| 664 | if (modplug->offset == modplug->song_size) { |
Stefan Kost | a5bf402 | 2008-11-04 20:26:00 +0000 | [diff] [blame] | 665 | GstTagList *tags; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 666 | gboolean ok; |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 667 | #define COMMENT_SIZE 16384 |
Stefan Sauer | d84d989 | 2012-03-23 18:36:21 +0100 | [diff] [blame] | 668 | gchar comment[COMMENT_SIZE]; |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 669 | GstSegment seg; |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 670 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 671 | ok = gst_modplug_load_song (modplug); |
| 672 | gst_buffer_unref (modplug->buffer); |
| 673 | modplug->buffer = NULL; |
| 674 | modplug->offset = 0; |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 675 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 676 | if (!ok) { |
| 677 | goto pause; |
Benjamin Otte | 94f1403 | 2004-03-14 12:40:57 +0000 | [diff] [blame] | 678 | } |
Jeremy Simon | 6f92032 | 2003-01-20 21:02:58 +0000 | [diff] [blame] | 679 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 680 | gst_segment_init (&seg, GST_FORMAT_TIME); |
| 681 | seg.stop = modplug->song_length; |
| 682 | gst_pad_push_event (modplug->srcpad, gst_event_new_segment (&seg)); |
Stefan Kost | a5bf402 | 2008-11-04 20:26:00 +0000 | [diff] [blame] | 683 | |
| 684 | /* get and send metadata */ |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 685 | tags = gst_tag_list_new_empty (); |
Stefan Kost | a5bf402 | 2008-11-04 20:26:00 +0000 | [diff] [blame] | 686 | gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, |
| 687 | GST_TAG_TITLE, modplug->mSoundFile->GetTitle (), |
| 688 | GST_TAG_BEATS_PER_MINUTE, |
| 689 | (gdouble) modplug->mSoundFile->GetMusicTempo (), NULL); |
| 690 | |
Stefan Sauer | d84d989 | 2012-03-23 18:36:21 +0100 | [diff] [blame] | 691 | if (modplug->mSoundFile->GetSongComments ((gchar *) & comment, |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 692 | COMMENT_SIZE, 32)) { |
Stefan Sauer | d84d989 | 2012-03-23 18:36:21 +0100 | [diff] [blame] | 693 | comment[COMMENT_SIZE - 1] = '\0'; |
Stefan Kost | a5bf402 | 2008-11-04 20:26:00 +0000 | [diff] [blame] | 694 | gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, |
| 695 | GST_TAG_COMMENT, comment, NULL); |
| 696 | } |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 697 | gst_pad_push_event (modplug->srcpad, gst_event_new_tag (tags)); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 698 | } else { |
| 699 | /* not fully loaded yet */ |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 700 | return; |
| 701 | } |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 702 | } |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 703 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 704 | /* could move this to gst_modplug_src_event |
| 705 | * if libmodplug was definitely thread safe.. */ |
| 706 | if (modplug->seek_at != -1) { |
| 707 | gint seek_to_pos; |
| 708 | gfloat temp; |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 709 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 710 | temp = (gfloat) modplug->song_length / modplug->seek_at; |
Stefan Sauer | bece1c9 | 2012-03-23 18:16:08 +0100 | [diff] [blame] | 711 | seek_to_pos = (gint) (modplug->mSoundFile->GetMaxPosition () / temp); |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 712 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 713 | GST_DEBUG_OBJECT (modplug, "Seeking to row %d", seek_to_pos); |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 714 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 715 | modplug->mSoundFile->SetCurrentPos (seek_to_pos); |
| 716 | modplug->seek_at = -1; |
| 717 | } |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 718 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 719 | /* read and output a buffer */ |
Sebastian Dröge | afd50a7 | 2012-07-28 00:32:58 +0200 | [diff] [blame] | 720 | GST_LOG_OBJECT (modplug, "Read %d bytes", (gint) modplug->read_bytes); |
Stefan Sauer | bece1c9 | 2012-03-23 18:16:08 +0100 | [diff] [blame] | 721 | /* libmodplug 0.8.7 trashes memory */ |
Sebastian Dröge | 860ccd4 | 2012-03-29 17:41:53 +0200 | [diff] [blame] | 722 | out = gst_buffer_new_allocate (NULL, modplug->read_bytes * 2, NULL); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 723 | |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 724 | gst_buffer_map (out, &map, GST_MAP_WRITE); |
| 725 | if (!modplug->mSoundFile->Read (map.data, modplug->read_bytes)) { |
| 726 | gst_buffer_unmap (out, &map); |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 727 | goto eos; |
Wim Taymans | 9fcfa60 | 2012-02-09 18:08:22 +0100 | [diff] [blame] | 728 | } |
| 729 | gst_buffer_unmap (out, &map); |
Sebastian Dröge | 860ccd4 | 2012-03-29 17:41:53 +0200 | [diff] [blame] | 730 | gst_buffer_resize (out, 0, modplug->read_bytes); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 731 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 732 | GST_BUFFER_DURATION (out) = |
| 733 | gst_util_uint64_scale_int (modplug->read_samples, GST_SECOND, |
| 734 | modplug->frequency); |
| 735 | GST_BUFFER_OFFSET (out) = modplug->offset; |
| 736 | GST_BUFFER_TIMESTAMP (out) = |
| 737 | gst_util_uint64_scale_int (modplug->offset, GST_SECOND, |
| 738 | modplug->frequency); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 739 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 740 | modplug->offset += modplug->read_samples; |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 741 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 742 | flow = gst_pad_push (modplug->srcpad, out); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 743 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 744 | if (flow != GST_FLOW_OK) { |
| 745 | GST_LOG_OBJECT (modplug, "pad push flow: %s", gst_flow_get_name (flow)); |
| 746 | goto pause; |
| 747 | } |
| 748 | |
| 749 | return; |
| 750 | |
| 751 | eos: |
| 752 | { |
| 753 | gst_buffer_unref (out); |
| 754 | GST_INFO_OBJECT (modplug, "EOS"); |
| 755 | gst_pad_push_event (modplug->srcpad, gst_event_new_eos ()); |
| 756 | goto pause; |
| 757 | } |
| 758 | |
| 759 | pause: |
| 760 | { |
| 761 | GST_INFO_OBJECT (modplug, "Pausing"); |
| 762 | gst_pad_pause_task (modplug->sinkpad); |
Jeremy Simon | c99d527 | 2002-12-07 15:28:24 +0000 | [diff] [blame] | 763 | } |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 767 | static GstStateChangeReturn |
| 768 | gst_modplug_change_state (GstElement * element, GstStateChange transition) |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 769 | { |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 770 | GstModPlug *modplug; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 771 | GstStateChangeReturn ret; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 772 | |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 773 | modplug = GST_MODPLUG (element); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 774 | |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 775 | switch (transition) { |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 776 | case GST_STATE_CHANGE_READY_TO_PAUSED: |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 777 | modplug->buffer = NULL; |
| 778 | modplug->offset = 0; |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 779 | modplug->song_size = 0; |
Jeremy Simon | c99d527 | 2002-12-07 15:28:24 +0000 | [diff] [blame] | 780 | break; |
| 781 | default: |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 782 | break; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 783 | } |
Jeremy Simon | dc46176 | 2002-06-09 19:00:27 +0000 | [diff] [blame] | 784 | |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 785 | ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); |
| 786 | if (ret == GST_STATE_CHANGE_FAILURE) |
| 787 | return ret; |
| 788 | |
| 789 | switch (transition) { |
| 790 | case GST_STATE_CHANGE_PAUSED_TO_READY: |
| 791 | if (modplug->buffer) { |
| 792 | gst_buffer_unref (modplug->buffer); |
| 793 | modplug->buffer = NULL; |
| 794 | } |
| 795 | if (modplug->mSoundFile) { |
| 796 | modplug->mSoundFile->Destroy (); |
Stefan Sauer | d84d989 | 2012-03-23 18:36:21 +0100 | [diff] [blame] | 797 | delete modplug->mSoundFile; |
Tim-Philipp Müller | 55e2df5 | 2006-03-10 17:10:09 +0000 | [diff] [blame] | 798 | modplug->mSoundFile = NULL; |
| 799 | } |
| 800 | break; |
| 801 | default: |
| 802 | break; |
| 803 | } |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 804 | |
Jan Schmidt | 012dfb8 | 2005-09-05 17:20:29 +0000 | [diff] [blame] | 805 | return GST_STATE_CHANGE_SUCCESS; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Jeremy Simon | 8029993 | 2002-11-17 12:23:43 +0000 | [diff] [blame] | 808 | |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 809 | static void |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 810 | gst_modplug_set_property (GObject * object, guint id, const GValue * value, |
| 811 | GParamSpec * pspec) |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 812 | { |
| 813 | GstModPlug *modplug; |
| 814 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 815 | g_return_if_fail (GST_IS_MODPLUG (object)); |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 816 | modplug = GST_MODPLUG (object); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 817 | |
| 818 | switch (id) { |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 819 | case ARG_REVERB: |
| 820 | modplug->reverb = g_value_get_boolean (value); |
| 821 | break; |
| 822 | case ARG_REVERB_DEPTH: |
| 823 | modplug->reverb_depth = g_value_get_int (value); |
| 824 | break; |
| 825 | case ARG_REVERB_DELAY: |
| 826 | modplug->reverb_delay = g_value_get_int (value); |
| 827 | break; |
| 828 | case ARG_MEGABASS: |
| 829 | modplug->megabass = g_value_get_boolean (value); |
| 830 | break; |
| 831 | case ARG_MEGABASS_AMOUNT: |
| 832 | modplug->megabass_amount = g_value_get_int (value); |
| 833 | break; |
| 834 | case ARG_MEGABASS_RANGE: |
| 835 | modplug->megabass_range = g_value_get_int (value); |
| 836 | break; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 837 | case ARG_NOISE_REDUCTION: |
| 838 | modplug->noise_reduction = g_value_get_boolean (value); |
| 839 | break; |
| 840 | case ARG_SURROUND: |
| 841 | modplug->surround = g_value_get_boolean (value); |
| 842 | break; |
| 843 | case ARG_SURROUND_DEPTH: |
| 844 | modplug->surround_depth = g_value_get_int (value); |
| 845 | break; |
| 846 | case ARG_SURROUND_DELAY: |
| 847 | modplug->surround_delay = g_value_get_int (value); |
| 848 | break; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 849 | default: |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 850 | break; |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | static void |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 855 | gst_modplug_get_property (GObject * object, guint id, GValue * value, |
| 856 | GParamSpec * pspec) |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 857 | { |
| 858 | GstModPlug *modplug; |
| 859 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 860 | g_return_if_fail (GST_IS_MODPLUG (object)); |
Jeremy Simon | 3f676b1 | 2002-12-30 17:21:45 +0000 | [diff] [blame] | 861 | modplug = GST_MODPLUG (object); |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 862 | |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 863 | switch (id) { |
| 864 | case ARG_REVERB: |
| 865 | g_value_set_boolean (value, modplug->reverb); |
| 866 | break; |
| 867 | case ARG_REVERB_DEPTH: |
| 868 | g_value_set_int (value, modplug->reverb_depth); |
| 869 | break; |
| 870 | case ARG_REVERB_DELAY: |
| 871 | g_value_set_int (value, modplug->reverb_delay); |
| 872 | break; |
| 873 | case ARG_MEGABASS: |
| 874 | g_value_set_boolean (value, modplug->megabass); |
| 875 | break; |
| 876 | case ARG_MEGABASS_AMOUNT: |
| 877 | g_value_set_int (value, modplug->megabass_amount); |
| 878 | break; |
| 879 | case ARG_MEGABASS_RANGE: |
| 880 | g_value_set_int (value, modplug->megabass_range); |
| 881 | break; |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 882 | case ARG_SURROUND: |
| 883 | g_value_set_boolean (value, modplug->surround); |
| 884 | break; |
| 885 | case ARG_SURROUND_DEPTH: |
| 886 | g_value_set_int (value, modplug->surround_depth); |
| 887 | break; |
| 888 | case ARG_SURROUND_DELAY: |
| 889 | g_value_set_int (value, modplug->surround_delay); |
| 890 | break; |
| 891 | case ARG_NOISE_REDUCTION: |
| 892 | g_value_set_boolean (value, modplug->noise_reduction); |
| 893 | break; |
| 894 | default: |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 895 | break; |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | static gboolean |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 900 | plugin_init (GstPlugin * plugin) |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 901 | { |
Ronald S. Bultje | 4e3bf35 | 2003-11-02 23:00:38 +0000 | [diff] [blame] | 902 | return gst_element_register (plugin, "modplug", |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 903 | GST_RANK_PRIMARY, GST_TYPE_MODPLUG); |
Jeremy Simon | ac87bfc | 2002-02-28 21:10:42 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 906 | GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, |
| 907 | GST_VERSION_MINOR, |
Sebastian Dröge | cda192b | 2012-04-05 18:02:56 +0200 | [diff] [blame] | 908 | modplug, |
Thomas Vander Stichele | 87960e4 | 2004-03-14 23:20:41 +0000 | [diff] [blame] | 909 | ".MOD audio decoding", |
Tim-Philipp Müller | f902029 | 2006-04-03 10:34:54 +0000 | [diff] [blame] | 910 | plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) |