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.
23 #include "gstsmoothwave.h"
25 static GstElementDetails gst_smoothwave_details = {
28 "Fading grayscale waveform display",
30 "Erik Walthinsen <omega@cse.ogi.edu>",
35 /* SmoothWave signals and args */
49 static void gst_smoothwave_class_init (GstSmoothWaveClass *klass);
50 static void gst_smoothwave_init (GstSmoothWave *smoothwave);
52 static void gst_smoothwave_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
53 static void gst_smoothwave_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
55 static void gst_smoothwave_chain (GstPad *pad, GstBuffer *buf);
57 static GstElementClass *parent_class = NULL;
58 /*static guint gst_smoothwave_signals[LAST_SIGNAL] = { 0 }; */
62 gst_smoothwave_get_type (void)
64 static GType smoothwave_type = 0;
66 if (!smoothwave_type) {
67 static const GTypeInfo smoothwave_info = {
68 sizeof(GstSmoothWaveClass), NULL,
70 (GClassInitFunc)gst_smoothwave_class_init,
73 sizeof(GstSmoothWave),
75 (GInstanceInitFunc)gst_smoothwave_init,
77 smoothwave_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSmoothWave", &smoothwave_info, 0);
79 return smoothwave_type;
83 gst_smoothwave_class_init (GstSmoothWaveClass *klass)
85 GObjectClass *gobject_class;
86 GstElementClass *gstelement_class;
88 gobject_class = (GObjectClass*)klass;
89 gstelement_class = (GstElementClass*)klass;
91 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
93 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_WIDTH,
94 g_param_spec_int("width","width","width",
95 G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
96 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_HEIGHT,
97 g_param_spec_int("height","height","height",
98 G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
99 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_WIDGET,
100 g_param_spec_object("widget","widget","widget",
101 GTK_TYPE_WIDGET,G_PARAM_READABLE)); /* CHECKME! */
103 gobject_class->set_property = gst_smoothwave_set_property;
104 gobject_class->get_property = gst_smoothwave_get_property;
108 gst_smoothwave_init (GstSmoothWave *smoothwave)
111 guint32 palette[256];
113 smoothwave->sinkpad = gst_pad_new("sink",GST_PAD_SINK);
114 gst_element_add_pad(GST_ELEMENT(smoothwave),smoothwave->sinkpad);
115 gst_pad_set_chain_function(smoothwave->sinkpad,gst_smoothwave_chain);
116 smoothwave->srcpad = gst_pad_new("src",GST_PAD_SRC);
117 gst_element_add_pad(GST_ELEMENT(smoothwave),smoothwave->srcpad);
119 /* smoothwave->meta = NULL; */
120 smoothwave->width = 512;
121 smoothwave->height = 256;
124 /* gtk_widget_set_default_colormap (gdk_rgb_get_cmap()); */
125 /* gtk_widget_set_default_visual (gdk_rgb_get_visual()); */
127 /* GST_DEBUG (0,"creating palette"); */
129 palette[i] = (i << 16) || (i << 8);
130 /* GST_DEBUG (0,"creating cmap"); */
131 smoothwave->cmap = gdk_rgb_cmap_new(palette,256);
132 /* GST_DEBUG (0,"created cmap"); */
133 /* gtk_widget_set_default_colormap (smoothwave->cmap); */
135 smoothwave->image = gtk_drawing_area_new();
136 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
137 smoothwave->width,smoothwave->height);
138 gtk_widget_show(smoothwave->image);
140 smoothwave->imagebuffer = g_malloc(smoothwave->width*smoothwave->height);
141 memset(smoothwave->imagebuffer,0,smoothwave->width*smoothwave->height);
145 gst_smoothwave_chain (GstPad *pad, GstBuffer *buf)
147 GstSmoothWave *smoothwave;
150 register guint32 *ptr;
153 g_return_if_fail(pad != NULL);
154 g_return_if_fail(GST_IS_PAD(pad));
155 g_return_if_fail(buf != NULL);
156 /* g_return_if_fail(GST_IS_BUFFER(buf)); */
158 smoothwave = GST_SMOOTHWAVE(GST_OBJECT_PARENT (pad));
160 /* first deal with audio metadata */
161 /* if (buf->meta) { */
162 /* if (smoothwave->meta != NULL) { */
163 /* /* FIXME: need to unref the old metadata so it goes away */ */
165 /* /* we just make a copy of the pointer */ */
166 /* smoothwave->meta = (MetaAudioRaw *)(buf->meta); */
167 /* /* FIXME: now we have to ref the metadata so it doesn't go away */ */
170 /* g_return_if_fail(smoothwave->meta != NULL); */
172 samples = (gint16 *)GST_BUFFER_DATA(buf);
173 /* samplecount = buf->datasize / (smoothwave->meta->channels * sizeof(gint16)); */
174 samplecount = GST_BUFFER_SIZE(buf) / (2 * sizeof(gint16));
176 qheight = smoothwave->height/4;
178 /* GST_DEBUG (0,"traversing %d",smoothwave->width); */
179 for (i=0;i<MAX(smoothwave->width,samplecount);i++) {
180 gint16 y1 = (gint32)(samples[i*2] * qheight) / 32768 +
182 gint16 y2 = (gint32)(samples[(i*2)+1] * qheight) / 32768 +
184 smoothwave->imagebuffer[y1*smoothwave->width + i] = 0xff;
185 smoothwave->imagebuffer[y2*smoothwave->width + i] = 0xff;
186 /* smoothwave->imagebuffer[i+(smoothwave->width*5)] = i; */
189 ptr = (guint32 *)smoothwave->imagebuffer;
190 for (i=0;i<(smoothwave->width*smoothwave->height)/4;i++) {
192 *(ptr++) -= ((*ptr & 0xf0f0f0f0ul) >> 4) + ((*ptr & 0xe0e0e0e0ul) >> 5);
197 /* GST_DEBUG (0,"drawing"); */
198 /* GST_DEBUG (0,"gdk_draw_indexed_image(%p,%p,%d,%d,%d,%d,%s,%p,%d,%p);",
199 smoothwave->image->window,
200 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
201 0,0,smoothwave->width,smoothwave->height,
202 "GDK_RGB_DITHER_NORMAL",
203 smoothwave->imagebuffer,smoothwave->width,
205 /* gdk_draw_indexed_image(smoothwave->image->window,
206 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
207 0,0,smoothwave->width,smoothwave->height,
209 smoothwave->imagebuffer,smoothwave->width,
211 gdk_draw_gray_image(smoothwave->image->window,
212 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
213 0,0,smoothwave->width,smoothwave->height,
214 GDK_RGB_DITHER_NORMAL,
215 smoothwave->imagebuffer,smoothwave->width);
217 /* gst_trace_add_entry(NULL,0,buf,"smoothwave: calculated smoothwave"); */
219 gst_buffer_unref(buf);
223 gst_smoothwave_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
225 GstSmoothWave *smoothwave;
227 /* it's not null if we got it, but it might not be ours */
228 g_return_if_fail(GST_IS_SMOOTHWAVE(object));
229 smoothwave = GST_SMOOTHWAVE(object);
233 smoothwave->width = g_value_get_int (value);
234 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
235 smoothwave->width,smoothwave->height);
236 gtk_widget_set_usize(GTK_WIDGET(smoothwave->image),
237 smoothwave->width,smoothwave->height);
240 smoothwave->height = g_value_get_int (value);
241 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
242 smoothwave->width,smoothwave->height);
243 gtk_widget_set_usize(GTK_WIDGET(smoothwave->image),
244 smoothwave->width,smoothwave->height);
252 gst_smoothwave_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
254 GstSmoothWave *smoothwave;
256 /* it's not null if we got it, but it might not be ours */
257 smoothwave = GST_SMOOTHWAVE(object);
261 g_value_set_int (value, smoothwave->width);
265 g_value_set_int (value, smoothwave->height);
269 g_value_set_object (value, smoothwave->image);
273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
282 plugin_init (GModule *module, GstPlugin *plugin)
284 GstElementFactory *factory;
286 /* create an elementfactory for the smoothwave element */
287 factory = gst_elementfactory_new("smoothwave",GST_TYPE_SMOOTHWAVE,
288 &gst_smoothwave_details);
289 g_return_val_if_fail(factory != NULL, FALSE);
291 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
296 GstPluginDesc plugin_desc = {