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) <2015> Luis de Bethencourt <luis@debethencourt.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 /**
23 * SECTION:element-goom2k1
24 * @see_also: goom, synaesthesia
25 *
26 * Goom2k1 is an audio visualisation element. It creates warping structures
27 * based on the incoming audio signal. Goom2k1 is the older version of the
28 * visualisation. Also available is goom2k4, with a different look.
29 *
30 * <refsect2>
31 * <title>Example launch line</title>
32 * |[
33 * gst-launch-1.0 -v audiotestsrc ! goom2k1 ! videoconvert ! xvimagesink
34 * ]|
35 * </refsect2>
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_core.h"
45
46 GST_DEBUG_CATEGORY_STATIC (goom2k1_debug);
47 #define GST_CAT_DEFAULT goom2k1_debug
48
49 #define DEFAULT_WIDTH 320
50 #define DEFAULT_HEIGHT 240
51 #define DEFAULT_FPS_N 25
52 #define DEFAULT_FPS_D 1
53
54 #if G_BYTE_ORDER == G_BIG_ENDIAN
55 #define RGB_ORDER "xRGB"
56 #else
57 #define RGB_ORDER "BGRx"
58 #endif
59
60 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
61 GST_PAD_SRC,
62 GST_PAD_ALWAYS,
63 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (RGB_ORDER))
64 );
65
66 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", /* the name of the pads */
67 GST_PAD_SINK, /* type of the pad */
68 GST_PAD_ALWAYS, /* ALWAYS/SOMETIMES */
69 GST_STATIC_CAPS ("audio/x-raw, "
70 "format = (string) " GST_AUDIO_NE (S16) ", "
71 "rate = (int) [ 8000, 96000 ], "
72 "channels = (int) 1, "
73 "layout = (string) interleaved; "
74 "audio/x-raw, "
75 "format = (string) " GST_AUDIO_NE (S16) ", "
76 "rate = (int) [ 8000, 96000 ], "
77 "channels = (int) 2, "
78 "channel-mask = (bitmask) 0x3, " "layout = (string) interleaved")
79 );
80
81 static void gst_goom2k1_finalize (GObject * object);
82
83 static gboolean gst_goom2k1_setup (GstAudioVisualizer * base);
84 static gboolean gst_goom2k1_render (GstAudioVisualizer * base,
85 GstBuffer * audio, GstVideoFrame * video);
86
87
88 G_DEFINE_TYPE (GstGoom2k1, gst_goom2k1, GST_TYPE_AUDIO_VISUALIZER);
89
90 static void
gst_goom2k1_class_init(GstGoom2k1Class * klass)91 gst_goom2k1_class_init (GstGoom2k1Class * klass)
92 {
93 GObjectClass *gobject_class;
94 GstElementClass *gstelement_class;
95 GstAudioVisualizerClass *visualizer_class;
96
97 gobject_class = (GObjectClass *) klass;
98 gstelement_class = (GstElementClass *) klass;
99 visualizer_class = (GstAudioVisualizerClass *) klass;
100
101 gobject_class->finalize = gst_goom2k1_finalize;
102
103 gst_element_class_set_static_metadata (gstelement_class,
104 "GOOM: what a GOOM! 2k1 edition", "Visualization",
105 "Takes frames of data and outputs video frames using the GOOM 2k1 filter",
106 "Wim Taymans <wim@fluendo.com>");
107 gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
108 gst_element_class_add_static_pad_template (gstelement_class, &src_template);
109
110 GST_DEBUG_CATEGORY_INIT (goom2k1_debug, "goom2k1", 0,
111 "goom2k1 visualisation element");
112
113 visualizer_class->setup = GST_DEBUG_FUNCPTR (gst_goom2k1_setup);
114 visualizer_class->render = GST_DEBUG_FUNCPTR (gst_goom2k1_render);
115 }
116
117 static void
gst_goom2k1_init(GstGoom2k1 * goom)118 gst_goom2k1_init (GstGoom2k1 * goom)
119 {
120 goom->width = DEFAULT_WIDTH;
121 goom->height = DEFAULT_HEIGHT;
122 goom->channels = 0;
123
124 goom_init (&(goom->goomdata), goom->width, goom->height);
125 }
126
127 static void
gst_goom2k1_finalize(GObject * object)128 gst_goom2k1_finalize (GObject * object)
129 {
130 GstGoom2k1 *goom = GST_GOOM2K1 (object);
131
132 goom_close (&(goom->goomdata));
133
134 G_OBJECT_CLASS (gst_goom2k1_parent_class)->finalize (object);
135 }
136
137 static gboolean
gst_goom2k1_setup(GstAudioVisualizer * base)138 gst_goom2k1_setup (GstAudioVisualizer * base)
139 {
140 GstGoom2k1 *goom = GST_GOOM2K1 (base);
141
142 goom->width = GST_VIDEO_INFO_WIDTH (&base->vinfo);
143 goom->height = GST_VIDEO_INFO_HEIGHT (&base->vinfo);
144
145 goom_set_resolution (&(goom->goomdata), goom->width, goom->height);
146
147 return TRUE;
148 }
149
150 static gboolean
gst_goom2k1_render(GstAudioVisualizer * base,GstBuffer * audio,GstVideoFrame * video)151 gst_goom2k1_render (GstAudioVisualizer * base, GstBuffer * audio,
152 GstVideoFrame * video)
153 {
154 GstGoom2k1 *goom = GST_GOOM2K1 (base);
155 GstMapInfo amap;
156 gint16 datain[2][GOOM2K1_SAMPLES];
157 gint16 *adata;
158 gint i;
159
160 /* get next GOOM2K1_SAMPLES, we have at least this amount of samples */
161 gst_buffer_map (audio, &amap, GST_MAP_READ);
162 adata = (gint16 *) amap.data;
163
164 if (goom->channels == 2) {
165 for (i = 0; i < GOOM2K1_SAMPLES; i++) {
166 datain[0][i] = *adata++;
167 datain[1][i] = *adata++;
168 }
169 } else {
170 for (i = 0; i < GOOM2K1_SAMPLES; i++) {
171 datain[0][i] = *adata;
172 datain[1][i] = *adata++;
173 }
174 }
175
176 video->data[0] = goom_update (&(goom->goomdata), datain);
177 gst_buffer_unmap (audio, &amap);
178
179 return TRUE;
180 }
181
182 static gboolean
plugin_init(GstPlugin * plugin)183 plugin_init (GstPlugin * plugin)
184 {
185 return gst_element_register (plugin, "goom2k1", GST_RANK_NONE,
186 GST_TYPE_GOOM2K1);
187 }
188
189 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
190 GST_VERSION_MINOR,
191 goom2k1,
192 "GOOM 2k1 visualization filter",
193 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
194