• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * @title: goom2k1
25  * @see_also: goom, synaesthesia
26  *
27  * Goom2k1 is an audio visualisation element. It creates warping structures
28  * based on the incoming audio signal. Goom2k1 is the older version of the
29  * visualisation. Also available is goom2k4, with a different look.
30  *
31  * ## Example launch line
32  * |[
33  * gst-launch-1.0 -v audiotestsrc ! goom2k1 ! 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_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 GST_ELEMENT_REGISTER_DEFINE (goom2k1, "goom2k1", GST_RANK_NONE,
90     GST_TYPE_GOOM2K1);
91 static void
gst_goom2k1_class_init(GstGoom2k1Class * klass)92 gst_goom2k1_class_init (GstGoom2k1Class * klass)
93 {
94   GObjectClass *gobject_class;
95   GstElementClass *gstelement_class;
96   GstAudioVisualizerClass *visualizer_class;
97 
98   gobject_class = (GObjectClass *) klass;
99   gstelement_class = (GstElementClass *) klass;
100   visualizer_class = (GstAudioVisualizerClass *) klass;
101 
102   gobject_class->finalize = gst_goom2k1_finalize;
103 
104   gst_element_class_set_static_metadata (gstelement_class,
105       "GOOM: what a GOOM! 2k1 edition", "Visualization",
106       "Takes frames of data and outputs video frames using the GOOM 2k1 filter",
107       "Wim Taymans <wim@fluendo.com>");
108   gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
109   gst_element_class_add_static_pad_template (gstelement_class, &src_template);
110 
111   GST_DEBUG_CATEGORY_INIT (goom2k1_debug, "goom2k1", 0,
112       "goom2k1 visualisation element");
113 
114   visualizer_class->setup = GST_DEBUG_FUNCPTR (gst_goom2k1_setup);
115   visualizer_class->render = GST_DEBUG_FUNCPTR (gst_goom2k1_render);
116 }
117 
118 static void
gst_goom2k1_init(GstGoom2k1 * goom)119 gst_goom2k1_init (GstGoom2k1 * goom)
120 {
121   goom->width = DEFAULT_WIDTH;
122   goom->height = DEFAULT_HEIGHT;
123   goom->channels = 0;
124 
125   goom_init (&(goom->goomdata), goom->width, goom->height);
126 }
127 
128 static void
gst_goom2k1_finalize(GObject * object)129 gst_goom2k1_finalize (GObject * object)
130 {
131   GstGoom2k1 *goom = GST_GOOM2K1 (object);
132 
133   goom_close (&(goom->goomdata));
134 
135   G_OBJECT_CLASS (gst_goom2k1_parent_class)->finalize (object);
136 }
137 
138 static gboolean
gst_goom2k1_setup(GstAudioVisualizer * base)139 gst_goom2k1_setup (GstAudioVisualizer * base)
140 {
141   GstGoom2k1 *goom = GST_GOOM2K1 (base);
142 
143   goom->width = GST_VIDEO_INFO_WIDTH (&base->vinfo);
144   goom->height = GST_VIDEO_INFO_HEIGHT (&base->vinfo);
145 
146   goom_set_resolution (&(goom->goomdata), goom->width, goom->height);
147 
148   return TRUE;
149 }
150 
151 static gboolean
gst_goom2k1_render(GstAudioVisualizer * base,GstBuffer * audio,GstVideoFrame * video)152 gst_goom2k1_render (GstAudioVisualizer * base, GstBuffer * audio,
153     GstVideoFrame * video)
154 {
155   GstGoom2k1 *goom = GST_GOOM2K1 (base);
156   GstMapInfo amap;
157   gint16 datain[2][GOOM2K1_SAMPLES];
158   gint16 *adata;
159   gint i;
160 
161   /* get next GOOM2K1_SAMPLES, we have at least this amount of samples */
162   gst_buffer_map (audio, &amap, GST_MAP_READ);
163   adata = (gint16 *) amap.data;
164 
165   if (goom->channels == 2) {
166     for (i = 0; i < GOOM2K1_SAMPLES; i++) {
167       datain[0][i] = *adata++;
168       datain[1][i] = *adata++;
169     }
170   } else {
171     for (i = 0; i < GOOM2K1_SAMPLES; i++) {
172       datain[0][i] = *adata;
173       datain[1][i] = *adata++;
174     }
175   }
176 
177   video->data[0] = goom_update (&(goom->goomdata), datain);
178   gst_buffer_unmap (audio, &amap);
179 
180   return TRUE;
181 }
182 
183 static gboolean
plugin_init(GstPlugin * plugin)184 plugin_init (GstPlugin * plugin)
185 {
186   return GST_ELEMENT_REGISTER (goom2k1, plugin);
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