2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include "gstsmoothwave.h"
28 static GstElementDetails gst_smoothwave_details = {
32 "Fading grayscale waveform display",
34 "Erik Walthinsen <omega@cse.ogi.edu>",
39 /* SmoothWave signals and args */
53 static void gst_smoothwave_class_init (GstSmoothWaveClass *klass);
54 static void gst_smoothwave_init (GstSmoothWave *smoothwave);
56 static void gst_smoothwave_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
57 static void gst_smoothwave_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
59 static void gst_smoothwave_chain (GstPad *pad, GstBuffer *buf);
61 static GstElementClass *parent_class = NULL;
62 /*static guint gst_smoothwave_signals[LAST_SIGNAL] = { 0 }; */
66 gst_smoothwave_get_type (void)
68 static GType smoothwave_type = 0;
70 if (!smoothwave_type) {
71 static const GTypeInfo smoothwave_info = {
72 sizeof(GstSmoothWaveClass), NULL,
74 (GClassInitFunc)gst_smoothwave_class_init,
77 sizeof(GstSmoothWave),
79 (GInstanceInitFunc)gst_smoothwave_init,
81 smoothwave_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSmoothWave", &smoothwave_info, 0);
83 return smoothwave_type;
87 gst_smoothwave_class_init (GstSmoothWaveClass *klass)
89 GObjectClass *gobject_class;
90 GstElementClass *gstelement_class;
92 gobject_class = (GObjectClass*)klass;
93 gstelement_class = (GstElementClass*)klass;
95 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
97 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_WIDTH,
98 g_param_spec_int("width","width","width",
99 G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
100 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_HEIGHT,
101 g_param_spec_int("height","height","height",
102 G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
103 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_WIDGET,
104 g_param_spec_object("widget","widget","widget",
105 GTK_TYPE_WIDGET,G_PARAM_READABLE)); /* CHECKME! */
107 gobject_class->set_property = gst_smoothwave_set_property;
108 gobject_class->get_property = gst_smoothwave_get_property;
112 gst_smoothwave_init (GstSmoothWave *smoothwave)
115 guint32 palette[256];
117 smoothwave->sinkpad = gst_pad_new("sink",GST_PAD_SINK);
118 gst_element_add_pad(GST_ELEMENT(smoothwave),smoothwave->sinkpad);
119 gst_pad_set_chain_function(smoothwave->sinkpad,gst_smoothwave_chain);
120 smoothwave->srcpad = gst_pad_new("src",GST_PAD_SRC);
121 gst_element_add_pad(GST_ELEMENT(smoothwave),smoothwave->srcpad);
123 /* smoothwave->meta = NULL; */
124 smoothwave->width = 512;
125 smoothwave->height = 256;
128 /* gtk_widget_set_default_colormap (gdk_rgb_get_cmap()); */
129 /* gtk_widget_set_default_visual (gdk_rgb_get_visual()); */
131 /* GST_DEBUG ("creating palette"); */
133 palette[i] = (i << 16) || (i << 8);
134 /* GST_DEBUG ("creating cmap"); */
135 smoothwave->cmap = gdk_rgb_cmap_new(palette,256);
136 /* GST_DEBUG ("created cmap"); */
137 /* gtk_widget_set_default_colormap (smoothwave->cmap); */
139 smoothwave->image = gtk_drawing_area_new();
140 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
141 smoothwave->width,smoothwave->height);
142 gtk_widget_show(smoothwave->image);
144 smoothwave->imagebuffer = g_malloc(smoothwave->width*smoothwave->height);
145 memset(smoothwave->imagebuffer,0,smoothwave->width*smoothwave->height);
149 gst_smoothwave_chain (GstPad *pad, GstBuffer *buf)
151 GstSmoothWave *smoothwave;
154 register guint32 *ptr;
157 g_return_if_fail(pad != NULL);
158 g_return_if_fail(GST_IS_PAD(pad));
159 g_return_if_fail(buf != NULL);
160 /* g_return_if_fail(GST_IS_BUFFER(buf)); */
162 smoothwave = GST_SMOOTHWAVE(GST_OBJECT_PARENT (pad));
164 /* first deal with audio metadata */
167 if (smoothwave->meta != NULL) {
168 /* FIXME: need to unref the old metadata so it goes away */
170 /* we just make a copy of the pointer */
171 smoothwave->meta = (MetaAudioRaw *)(buf->meta);
172 /* FIXME: now we have to ref the metadata so it doesn't go away */
176 /* g_return_if_fail(smoothwave->meta != NULL); */
178 samples = (gint16 *)GST_BUFFER_DATA(buf);
179 /* samplecount = buf->datasize / (smoothwave->meta->channels * sizeof(gint16)); */
180 samplecount = GST_BUFFER_SIZE(buf) / (2 * sizeof(gint16));
182 qheight = smoothwave->height/4;
184 /* GST_DEBUG ("traversing %d",smoothwave->width); */
185 for (i=0;i<MAX(smoothwave->width,samplecount);i++) {
186 gint16 y1 = (gint32)(samples[i*2] * qheight) / 32768 +
188 gint16 y2 = (gint32)(samples[(i*2)+1] * qheight) / 32768 +
190 smoothwave->imagebuffer[y1*smoothwave->width + i] = 0xff;
191 smoothwave->imagebuffer[y2*smoothwave->width + i] = 0xff;
192 /* smoothwave->imagebuffer[i+(smoothwave->width*5)] = i; */
195 ptr = (guint32 *)smoothwave->imagebuffer;
196 for (i=0;i<(smoothwave->width*smoothwave->height)/4;i++) {
198 *ptr -= ((*ptr & 0xf0f0f0f0ul) >> 4) + ((*ptr & 0xe0e0e0e0ul) >> 5);
205 /* GST_DEBUG ("drawing"); */
206 /* GST_DEBUG ("gdk_draw_indexed_image(%p,%p,%d,%d,%d,%d,%s,%p,%d,%p);",
207 smoothwave->image->window,
208 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
209 0,0,smoothwave->width,smoothwave->height,
210 "GDK_RGB_DITHER_NORMAL",
211 smoothwave->imagebuffer,smoothwave->width,
213 /* gdk_draw_indexed_image(smoothwave->image->window,
214 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
215 0,0,smoothwave->width,smoothwave->height,
217 smoothwave->imagebuffer,smoothwave->width,
219 gdk_draw_gray_image(smoothwave->image->window,
220 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
221 0,0,smoothwave->width,smoothwave->height,
222 GDK_RGB_DITHER_NORMAL,
223 smoothwave->imagebuffer,smoothwave->width);
225 /* gst_trace_add_entry(NULL,0,buf,"smoothwave: calculated smoothwave"); */
227 gst_buffer_unref(buf);
231 gst_smoothwave_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
233 GstSmoothWave *smoothwave;
235 /* it's not null if we got it, but it might not be ours */
236 g_return_if_fail(GST_IS_SMOOTHWAVE(object));
237 smoothwave = GST_SMOOTHWAVE(object);
241 smoothwave->width = g_value_get_int (value);
242 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
243 smoothwave->width,smoothwave->height);
244 gtk_widget_set_usize(GTK_WIDGET(smoothwave->image),
245 smoothwave->width,smoothwave->height);
248 smoothwave->height = g_value_get_int (value);
249 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
250 smoothwave->width,smoothwave->height);
251 gtk_widget_set_usize(GTK_WIDGET(smoothwave->image),
252 smoothwave->width,smoothwave->height);
260 gst_smoothwave_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
262 GstSmoothWave *smoothwave;
264 /* it's not null if we got it, but it might not be ours */
265 smoothwave = GST_SMOOTHWAVE(object);
269 g_value_set_int (value, smoothwave->width);
273 g_value_set_int (value, smoothwave->height);
277 g_value_set_object (value, smoothwave->image);
281 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
290 plugin_init (GModule *module, GstPlugin *plugin)
292 GstElementFactory *factory;
294 /* create an elementfactory for the smoothwave element */
295 factory = gst_element_factory_new("smoothwave",GST_TYPE_SMOOTHWAVE,
296 &gst_smoothwave_details);
297 g_return_val_if_fail(factory != NULL, FALSE);
299 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
304 GstPluginDesc plugin_desc = {