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>
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.
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.
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.
23 * SECTION:element-goom2k1
24 * @see_also: goom, synaesthesia
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.
31 * <title>Example launch line</title>
33 * gst-launch-1.0 -v audiotestsrc ! goom2k1 ! videoconvert ! xvimagesink
44 #include "goom_core.h"
46 GST_DEBUG_CATEGORY_STATIC (goom2k1_debug);
47 #define GST_CAT_DEFAULT goom2k1_debug
49 #define DEFAULT_WIDTH 320
50 #define DEFAULT_HEIGHT 240
51 #define DEFAULT_FPS_N 25
52 #define DEFAULT_FPS_D 1
54 #if G_BYTE_ORDER == G_BIG_ENDIAN
55 #define RGB_ORDER "xRGB"
57 #define RGB_ORDER "BGRx"
60 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
63 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (RGB_ORDER))
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; "
75 "format = (string) " GST_AUDIO_NE (S16) ", "
76 "rate = (int) [ 8000, 96000 ], "
77 "channels = (int) 2, "
78 "channel-mask = (bitmask) 0x3, " "layout = (string) interleaved")
81 static void gst_goom2k1_finalize (GObject * object);
83 static gboolean gst_goom2k1_setup (GstAudioVisualizer * base);
84 static gboolean gst_goom2k1_render (GstAudioVisualizer * base,
85 GstBuffer * audio, GstVideoFrame * video);
88 G_DEFINE_TYPE (GstGoom2k1, gst_goom2k1, GST_TYPE_AUDIO_VISUALIZER);
91 gst_goom2k1_class_init (GstGoom2k1Class * klass)
93 GObjectClass *gobject_class;
94 GstElementClass *gstelement_class;
95 GstAudioVisualizerClass *visualizer_class;
97 gobject_class = (GObjectClass *) klass;
98 gstelement_class = (GstElementClass *) klass;
99 visualizer_class = (GstAudioVisualizerClass *) klass;
101 gobject_class->finalize = gst_goom2k1_finalize;
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);
110 GST_DEBUG_CATEGORY_INIT (goom2k1_debug, "goom2k1", 0,
111 "goom2k1 visualisation element");
113 visualizer_class->setup = GST_DEBUG_FUNCPTR (gst_goom2k1_setup);
114 visualizer_class->render = GST_DEBUG_FUNCPTR (gst_goom2k1_render);
118 gst_goom2k1_init (GstGoom2k1 * goom)
120 goom->width = DEFAULT_WIDTH;
121 goom->height = DEFAULT_HEIGHT;
124 goom_init (&(goom->goomdata), goom->width, goom->height);
128 gst_goom2k1_finalize (GObject * object)
130 GstGoom2k1 *goom = GST_GOOM2K1 (object);
132 goom_close (&(goom->goomdata));
134 G_OBJECT_CLASS (gst_goom2k1_parent_class)->finalize (object);
138 gst_goom2k1_setup (GstAudioVisualizer * base)
140 GstGoom2k1 *goom = GST_GOOM2K1 (base);
142 goom->width = GST_VIDEO_INFO_WIDTH (&base->vinfo);
143 goom->height = GST_VIDEO_INFO_HEIGHT (&base->vinfo);
145 goom_set_resolution (&(goom->goomdata), goom->width, goom->height);
151 gst_goom2k1_render (GstAudioVisualizer * base, GstBuffer * audio,
152 GstVideoFrame * video)
154 GstGoom2k1 *goom = GST_GOOM2K1 (base);
156 gint16 datain[2][GOOM2K1_SAMPLES];
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;
164 if (goom->channels == 2) {
165 for (i = 0; i < GOOM2K1_SAMPLES; i++) {
166 datain[0][i] = *adata++;
167 datain[1][i] = *adata++;
170 for (i = 0; i < GOOM2K1_SAMPLES; i++) {
171 datain[0][i] = *adata;
172 datain[1][i] = *adata++;
176 video->data[0] = goom_update (&(goom->goomdata), datain);
177 gst_buffer_unmap (audio, &amap);
183 plugin_init (GstPlugin * plugin)
185 return gst_element_register (plugin, "goom2k1", GST_RANK_NONE,
189 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
192 "GOOM 2k1 visualization filter",
193 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)