Update .po files
[platform/upstream/gst-plugins-good.git] / gst / goom / gstgoom.c
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  * @see_also: synaesthesia
26  *
27  * Goom is an audio visualisation element. It creates warping structures
28  * based on the incoming audio signal.
29  *
30  * <refsect2>
31  * <title>Example launch line</title>
32  * |[
33  * gst-launch-1.0 -v audiotestsrc ! goom ! 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.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
103 G_DEFINE_TYPE (GstGoom, gst_goom, GST_TYPE_AUDIO_VISUALIZER);
104
105 static void
106 gst_goom_class_init (GstGoomClass * klass)
107 {
108   GObjectClass *gobject_class;
109   GstElementClass *gstelement_class;
110   GstAudioVisualizerClass *visualizer_class;
111
112   gobject_class = (GObjectClass *) klass;
113   gstelement_class = (GstElementClass *) klass;
114   visualizer_class = (GstAudioVisualizerClass *) klass;
115
116   gobject_class->finalize = gst_goom_finalize;
117
118   gst_element_class_set_static_metadata (gstelement_class, "GOOM: what a GOOM!",
119       "Visualization",
120       "Takes frames of data and outputs video frames using the GOOM filter",
121       "Wim Taymans <wim@fluendo.com>");
122   gst_element_class_add_pad_template (gstelement_class,
123       gst_static_pad_template_get (&sink_template));
124   gst_element_class_add_pad_template (gstelement_class,
125       gst_static_pad_template_get (&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
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
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
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
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
197 plugin_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 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
209     GST_VERSION_MINOR,
210     goom,
211     "GOOM visualization filter",
212     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)