1 /* gstgoom.c: implementation of goom drawing element
2 * Copyright (C) <2001> Richard Boulton <richard@tartarus.org>
3 * (C) <2006> Wim Taymans <wim at fluendo dot com>
4 * (C) <2011> Wim Taymans <wim.taymans at gmail dot com>
5 * (C) <2015> Luis de Bethencourt <luis@debethencourt.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * SECTION:element-goom
25 * @see_also: synaesthesia
27 * Goom is an audio visualisation element. It creates warping structures
28 * based on the incoming audio signal.
31 * <title>Example launch line</title>
33 * gst-launch-1.0 -v audiotestsrc ! goom ! videoconvert ! xvimagesink
50 GST_DEBUG_CATEGORY (goom_debug);
51 #define GST_CAT_DEFAULT goom_debug
53 #define DEFAULT_WIDTH 320
54 #define DEFAULT_HEIGHT 240
56 /* signals and args */
69 #if G_BYTE_ORDER == G_BIG_ENDIAN
70 #define RGB_ORDER "xRGB"
72 #define RGB_ORDER "BGRx"
75 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
78 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (RGB_ORDER))
81 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", /* the name of the pads */
82 GST_PAD_SINK, /* type of the pad */
83 GST_PAD_ALWAYS, /* ALWAYS/SOMETIMES */
84 GST_STATIC_CAPS ("audio/x-raw, "
85 "format = (string) " GST_AUDIO_NE (S16) ", "
86 "rate = (int) [ 8000, 96000 ], "
87 "channels = (int) 1, "
88 "layout = (string) interleaved; "
90 "format = (string) " GST_AUDIO_NE (S16) ", "
91 "rate = (int) [ 8000, 96000 ], "
92 "channels = (int) 2, "
93 "channel-mask = (bitmask) 0x3, " "layout = (string) interleaved")
97 static void gst_goom_finalize (GObject * object);
99 static gboolean gst_goom_setup (GstAudioVisualizer * base);
100 static gboolean gst_goom_render (GstAudioVisualizer * base, GstBuffer * audio,
101 GstVideoFrame * video);
103 G_DEFINE_TYPE (GstGoom, gst_goom, GST_TYPE_AUDIO_VISUALIZER);
106 gst_goom_class_init (GstGoomClass * klass)
108 GObjectClass *gobject_class;
109 GstElementClass *gstelement_class;
110 GstAudioVisualizerClass *visualizer_class;
112 gobject_class = (GObjectClass *) klass;
113 gstelement_class = (GstElementClass *) klass;
114 visualizer_class = (GstAudioVisualizerClass *) klass;
116 gobject_class->finalize = gst_goom_finalize;
118 gst_element_class_set_static_metadata (gstelement_class, "GOOM: what a GOOM!",
120 "Takes frames of data and outputs video frames using the GOOM filter",
121 "Wim Taymans <wim@fluendo.com>");
122 gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
123 gst_element_class_add_static_pad_template (gstelement_class, &src_template);
125 visualizer_class->setup = GST_DEBUG_FUNCPTR (gst_goom_setup);
126 visualizer_class->render = GST_DEBUG_FUNCPTR (gst_goom_render);
130 gst_goom_init (GstGoom * goom)
132 goom->width = DEFAULT_WIDTH;
133 goom->height = DEFAULT_HEIGHT;
136 goom->plugin = goom_init (goom->width, goom->height);
140 gst_goom_finalize (GObject * object)
142 GstGoom *goom = GST_GOOM (object);
144 goom_close (goom->plugin);
147 G_OBJECT_CLASS (gst_goom_parent_class)->finalize (object);
151 gst_goom_setup (GstAudioVisualizer * base)
153 GstGoom *goom = GST_GOOM (base);
155 goom->width = GST_VIDEO_INFO_WIDTH (&base->vinfo);
156 goom->height = GST_VIDEO_INFO_HEIGHT (&base->vinfo);
157 goom_set_resolution (goom->plugin, goom->width, goom->height);
163 gst_goom_render (GstAudioVisualizer * base, GstBuffer * audio,
164 GstVideoFrame * video)
166 GstGoom *goom = GST_GOOM (base);
168 gint16 datain[2][GOOM_SAMPLES];
172 /* get next GOOM_SAMPLES, we have at least this amount of samples */
173 gst_buffer_map (audio, &amap, GST_MAP_READ);
174 adata = (gint16 *) amap.data;
176 if (goom->channels == 2) {
177 for (i = 0; i < GOOM_SAMPLES; i++) {
178 datain[0][i] = *adata++;
179 datain[1][i] = *adata++;
182 for (i = 0; i < GOOM_SAMPLES; i++) {
183 datain[0][i] = *adata;
184 datain[1][i] = *adata++;
188 video->data[0] = goom_update (goom->plugin, datain, 0, 0);
189 gst_buffer_unmap (audio, &amap);
195 plugin_init (GstPlugin * plugin)
197 GST_DEBUG_CATEGORY_INIT (goom_debug, "goom", 0, "goom visualisation element");
203 return gst_element_register (plugin, "goom", GST_RANK_NONE, GST_TYPE_GOOM);
206 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
209 "GOOM visualization filter",
210 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)