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>
6 *
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.
11 *
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.
16 *
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.
21 */
22
23 /**
24 * SECTION:element-goom
25 * @title: goom
26 * @see_also: synaesthesia
27 *
28 * Goom is an audio visualisation element. It creates warping structures
29 * based on the incoming audio signal.
30 *
31 * ## Example launch line
32 * |[
33 * gst-launch-1.0 -v audiotestsrc ! goom ! videoconvert ! xvimagesink
34 * ]|
35 *
36 */
37
38 #ifdef HAVE_CONFIG_H
39 #include "config.h"
40 #endif
41
42 #include <string.h>
43 #include "gstgoom.h"
44 #include "goom.h"
45
46 #if HAVE_ORC
47 #include <orc/orc.h>
48 #endif
49
50 GST_DEBUG_CATEGORY (goom_debug);
51 #define GST_CAT_DEFAULT goom_debug
52
53 #define DEFAULT_WIDTH 320
54 #define DEFAULT_HEIGHT 240
55
56 /* signals and args */
57 enum
58 {
59 /* FILL ME */
60 LAST_SIGNAL
61 };
62
63 enum
64 {
65 ARG_0
66 /* FILL ME */
67 };
68
69 #if G_BYTE_ORDER == G_BIG_ENDIAN
70 #define RGB_ORDER "xRGB"
71 #else
72 #define RGB_ORDER "BGRx"
73 #endif
74
75 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
76 GST_PAD_SRC,
77 GST_PAD_ALWAYS,
78 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (RGB_ORDER))
79 );
80
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; "
89 "audio/x-raw, "
90 "format = (string) " GST_AUDIO_NE (S16) ", "
91 "rate = (int) [ 8000, 96000 ], "
92 "channels = (int) 2, "
93 "channel-mask = (bitmask) 0x3, " "layout = (string) interleaved")
94 );
95
96
97 static void gst_goom_finalize (GObject * object);
98
99 static gboolean gst_goom_setup (GstAudioVisualizer * base);
100 static gboolean gst_goom_render (GstAudioVisualizer * base, GstBuffer * audio,
101 GstVideoFrame * video);
102 static gboolean goom_element_init (GstPlugin * plugin);
103
104 G_DEFINE_TYPE (GstGoom, gst_goom, GST_TYPE_AUDIO_VISUALIZER);
105 GST_ELEMENT_REGISTER_DEFINE_CUSTOM (goom, goom_element_init);
106
107 static void
gst_goom_class_init(GstGoomClass * klass)108 gst_goom_class_init (GstGoomClass * klass)
109 {
110 GObjectClass *gobject_class;
111 GstElementClass *gstelement_class;
112 GstAudioVisualizerClass *visualizer_class;
113
114 gobject_class = (GObjectClass *) klass;
115 gstelement_class = (GstElementClass *) klass;
116 visualizer_class = (GstAudioVisualizerClass *) klass;
117
118 gobject_class->finalize = gst_goom_finalize;
119
120 gst_element_class_set_static_metadata (gstelement_class, "GOOM: what a GOOM!",
121 "Visualization",
122 "Takes frames of data and outputs video frames using the GOOM filter",
123 "Wim Taymans <wim@fluendo.com>");
124 gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
125 gst_element_class_add_static_pad_template (gstelement_class, &src_template);
126
127 visualizer_class->setup = GST_DEBUG_FUNCPTR (gst_goom_setup);
128 visualizer_class->render = GST_DEBUG_FUNCPTR (gst_goom_render);
129 }
130
131 static void
gst_goom_init(GstGoom * goom)132 gst_goom_init (GstGoom * goom)
133 {
134 goom->width = DEFAULT_WIDTH;
135 goom->height = DEFAULT_HEIGHT;
136 goom->channels = 0;
137
138 goom->plugin = goom_init (goom->width, goom->height);
139 }
140
141 static void
gst_goom_finalize(GObject * object)142 gst_goom_finalize (GObject * object)
143 {
144 GstGoom *goom = GST_GOOM (object);
145
146 goom_close (goom->plugin);
147 goom->plugin = NULL;
148
149 G_OBJECT_CLASS (gst_goom_parent_class)->finalize (object);
150 }
151
152 static gboolean
gst_goom_setup(GstAudioVisualizer * base)153 gst_goom_setup (GstAudioVisualizer * base)
154 {
155 GstGoom *goom = GST_GOOM (base);
156
157 goom->width = GST_VIDEO_INFO_WIDTH (&base->vinfo);
158 goom->height = GST_VIDEO_INFO_HEIGHT (&base->vinfo);
159 goom_set_resolution (goom->plugin, goom->width, goom->height);
160
161 return TRUE;
162 }
163
164 static gboolean
gst_goom_render(GstAudioVisualizer * base,GstBuffer * audio,GstVideoFrame * video)165 gst_goom_render (GstAudioVisualizer * base, GstBuffer * audio,
166 GstVideoFrame * video)
167 {
168 GstGoom *goom = GST_GOOM (base);
169 GstMapInfo amap;
170 gint16 datain[2][GOOM_SAMPLES];
171 gint16 *adata;
172 gint i;
173
174 /* get next GOOM_SAMPLES, we have at least this amount of samples */
175 gst_buffer_map (audio, &amap, GST_MAP_READ);
176 adata = (gint16 *) amap.data;
177
178 if (goom->channels == 2) {
179 for (i = 0; i < GOOM_SAMPLES; i++) {
180 datain[0][i] = *adata++;
181 datain[1][i] = *adata++;
182 }
183 } else {
184 for (i = 0; i < GOOM_SAMPLES; i++) {
185 datain[0][i] = *adata;
186 datain[1][i] = *adata++;
187 }
188 }
189
190 video->data[0] = goom_update (goom->plugin, datain, 0, 0);
191 gst_buffer_unmap (audio, &amap);
192
193 return TRUE;
194 }
195
196 static gboolean
goom_element_init(GstPlugin * plugin)197 goom_element_init (GstPlugin * plugin)
198 {
199 GST_DEBUG_CATEGORY_INIT (goom_debug, "goom", 0, "goom visualisation element");
200
201 #if HAVE_ORC
202 orc_init ();
203 #endif
204
205 return gst_element_register (plugin, "goom", GST_RANK_NONE, GST_TYPE_GOOM);
206 }
207
208 static gboolean
plugin_init(GstPlugin * plugin)209 plugin_init (GstPlugin * plugin)
210 {
211 return GST_ELEMENT_REGISTER (goom, plugin);
212 }
213
214 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
215 GST_VERSION_MINOR,
216 goom,
217 "GOOM visualization filter",
218 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
219