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 */
165 /* if (buf->meta) { */
166 /* if (smoothwave->meta != NULL) { */
167 /* /* FIXME: need to unref the old metadata so it goes away */ */
169 /* /* we just make a copy of the pointer */ */
170 /* smoothwave->meta = (MetaAudioRaw *)(buf->meta); */
171 /* /* FIXME: now we have to ref the metadata so it doesn't go away */ */
174 /* g_return_if_fail(smoothwave->meta != NULL); */
176 samples = (gint16 *)GST_BUFFER_DATA(buf);
177 /* samplecount = buf->datasize / (smoothwave->meta->channels * sizeof(gint16)); */
178 samplecount = GST_BUFFER_SIZE(buf) / (2 * sizeof(gint16));
180 qheight = smoothwave->height/4;
182 /* GST_DEBUG ("traversing %d",smoothwave->width); */
183 for (i=0;i<MAX(smoothwave->width,samplecount);i++) {
184 gint16 y1 = (gint32)(samples[i*2] * qheight) / 32768 +
186 gint16 y2 = (gint32)(samples[(i*2)+1] * qheight) / 32768 +
188 smoothwave->imagebuffer[y1*smoothwave->width + i] = 0xff;
189 smoothwave->imagebuffer[y2*smoothwave->width + i] = 0xff;
190 /* smoothwave->imagebuffer[i+(smoothwave->width*5)] = i; */
193 ptr = (guint32 *)smoothwave->imagebuffer;
194 for (i=0;i<(smoothwave->width*smoothwave->height)/4;i++) {
196 *(ptr++) -= ((*ptr & 0xf0f0f0f0ul) >> 4) + ((*ptr & 0xe0e0e0e0ul) >> 5);
201 /* GST_DEBUG ("drawing"); */
202 /* GST_DEBUG ("gdk_draw_indexed_image(%p,%p,%d,%d,%d,%d,%s,%p,%d,%p);",
203 smoothwave->image->window,
204 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
205 0,0,smoothwave->width,smoothwave->height,
206 "GDK_RGB_DITHER_NORMAL",
207 smoothwave->imagebuffer,smoothwave->width,
209 /* gdk_draw_indexed_image(smoothwave->image->window,
210 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
211 0,0,smoothwave->width,smoothwave->height,
213 smoothwave->imagebuffer,smoothwave->width,
215 gdk_draw_gray_image(smoothwave->image->window,
216 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
217 0,0,smoothwave->width,smoothwave->height,
218 GDK_RGB_DITHER_NORMAL,
219 smoothwave->imagebuffer,smoothwave->width);
221 /* gst_trace_add_entry(NULL,0,buf,"smoothwave: calculated smoothwave"); */
223 gst_buffer_unref(buf);
227 gst_smoothwave_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
229 GstSmoothWave *smoothwave;
231 /* it's not null if we got it, but it might not be ours */
232 g_return_if_fail(GST_IS_SMOOTHWAVE(object));
233 smoothwave = GST_SMOOTHWAVE(object);
237 smoothwave->width = g_value_get_int (value);
238 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
239 smoothwave->width,smoothwave->height);
240 gtk_widget_set_usize(GTK_WIDGET(smoothwave->image),
241 smoothwave->width,smoothwave->height);
244 smoothwave->height = g_value_get_int (value);
245 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
246 smoothwave->width,smoothwave->height);
247 gtk_widget_set_usize(GTK_WIDGET(smoothwave->image),
248 smoothwave->width,smoothwave->height);
256 gst_smoothwave_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
258 GstSmoothWave *smoothwave;
260 /* it's not null if we got it, but it might not be ours */
261 smoothwave = GST_SMOOTHWAVE(object);
265 g_value_set_int (value, smoothwave->width);
269 g_value_set_int (value, smoothwave->height);
273 g_value_set_object (value, smoothwave->image);
277 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
286 plugin_init (GModule *module, GstPlugin *plugin)
288 GstElementFactory *factory;
290 /* create an elementfactory for the smoothwave element */
291 factory = gst_element_factory_new("smoothwave",GST_TYPE_SMOOTHWAVE,
292 &gst_smoothwave_details);
293 g_return_val_if_fail(factory != NULL, FALSE);
295 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
300 GstPluginDesc plugin_desc = {