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 = GST_ELEMENT_DETAILS (
31 "Fading grayscale waveform display",
32 "Erik Walthinsen <omega@cse.ogi.edu>"
36 /* SmoothWave signals and args */
49 static void gst_smoothwave_base_init (gpointer g_class);
50 static void gst_smoothwave_class_init (GstSmoothWaveClass *klass);
51 static void gst_smoothwave_init (GstSmoothWave *smoothwave);
53 static void gst_smoothwave_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
54 static void gst_smoothwave_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
56 static void gst_smoothwave_chain (GstPad *pad, GstData *_data);
58 static GstElementClass *parent_class = NULL;
59 /*static guint gst_smoothwave_signals[LAST_SIGNAL] = { 0 }; */
63 gst_smoothwave_get_type (void)
65 static GType smoothwave_type = 0;
67 if (!smoothwave_type) {
68 static const GTypeInfo smoothwave_info = {
69 sizeof(GstSmoothWaveClass),
70 gst_smoothwave_base_init,
72 (GClassInitFunc)gst_smoothwave_class_init,
75 sizeof(GstSmoothWave),
77 (GInstanceInitFunc)gst_smoothwave_init,
79 smoothwave_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSmoothWave", &smoothwave_info, 0);
81 return smoothwave_type;
85 gst_smoothwave_base_init (gpointer g_class)
87 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
89 gst_element_class_set_details (element_class, &gst_smoothwave_details);
93 gst_smoothwave_class_init (GstSmoothWaveClass *klass)
95 GObjectClass *gobject_class;
96 GstElementClass *gstelement_class;
98 gobject_class = (GObjectClass*)klass;
99 gstelement_class = (GstElementClass*)klass;
101 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
103 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_WIDTH,
104 g_param_spec_int("width","width","width",
105 G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
106 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_HEIGHT,
107 g_param_spec_int("height","height","height",
108 G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
109 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_WIDGET,
110 g_param_spec_object("widget","widget","widget",
111 GTK_TYPE_WIDGET,G_PARAM_READABLE)); /* CHECKME! */
113 gobject_class->set_property = gst_smoothwave_set_property;
114 gobject_class->get_property = gst_smoothwave_get_property;
118 gst_smoothwave_init (GstSmoothWave *smoothwave)
121 guint32 palette[256];
123 smoothwave->sinkpad = gst_pad_new("sink",GST_PAD_SINK);
124 gst_element_add_pad(GST_ELEMENT(smoothwave),smoothwave->sinkpad);
125 gst_pad_set_chain_function(smoothwave->sinkpad,gst_smoothwave_chain);
126 smoothwave->srcpad = gst_pad_new("src",GST_PAD_SRC);
127 gst_element_add_pad(GST_ELEMENT(smoothwave),smoothwave->srcpad);
129 /* smoothwave->meta = NULL; */
130 smoothwave->width = 512;
131 smoothwave->height = 256;
134 /* gtk_widget_set_default_colormap (gdk_rgb_get_cmap()); */
135 /* gtk_widget_set_default_visual (gdk_rgb_get_visual()); */
137 /* GST_DEBUG ("creating palette"); */
139 palette[i] = (i << 16) || (i << 8);
140 /* GST_DEBUG ("creating cmap"); */
141 smoothwave->cmap = gdk_rgb_cmap_new(palette,256);
142 /* GST_DEBUG ("created cmap"); */
143 /* gtk_widget_set_default_colormap (smoothwave->cmap); */
145 smoothwave->image = gtk_drawing_area_new();
146 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
147 smoothwave->width,smoothwave->height);
148 gtk_widget_show(smoothwave->image);
150 smoothwave->imagebuffer = g_malloc(smoothwave->width*smoothwave->height);
151 memset(smoothwave->imagebuffer,0,smoothwave->width*smoothwave->height);
155 gst_smoothwave_chain (GstPad *pad, GstData *_data)
157 GstBuffer *buf = GST_BUFFER (_data);
158 GstSmoothWave *smoothwave;
161 register guint32 *ptr;
164 g_return_if_fail(pad != NULL);
165 g_return_if_fail(GST_IS_PAD(pad));
166 g_return_if_fail(buf != NULL);
167 /* g_return_if_fail(GST_IS_BUFFER(buf)); */
169 smoothwave = GST_SMOOTHWAVE(GST_OBJECT_PARENT (pad));
171 /* first deal with audio metadata */
174 if (smoothwave->meta != NULL) {
175 /* FIXME: need to unref the old metadata so it goes away */
177 /* we just make a copy of the pointer */
178 smoothwave->meta = (MetaAudioRaw *)(buf->meta);
179 /* FIXME: now we have to ref the metadata so it doesn't go away */
183 /* g_return_if_fail(smoothwave->meta != NULL); */
185 samples = (gint16 *)GST_BUFFER_DATA(buf);
186 /* samplecount = buf->datasize / (smoothwave->meta->channels * sizeof(gint16)); */
187 samplecount = GST_BUFFER_SIZE(buf) / (2 * sizeof(gint16));
189 qheight = smoothwave->height/4;
191 /* GST_DEBUG ("traversing %d",smoothwave->width); */
192 for (i=0;i<MAX(smoothwave->width,samplecount);i++) {
193 gint16 y1 = (gint32)(samples[i*2] * qheight) / 32768 +
195 gint16 y2 = (gint32)(samples[(i*2)+1] * qheight) / 32768 +
197 smoothwave->imagebuffer[y1*smoothwave->width + i] = 0xff;
198 smoothwave->imagebuffer[y2*smoothwave->width + i] = 0xff;
199 /* smoothwave->imagebuffer[i+(smoothwave->width*5)] = i; */
202 ptr = (guint32 *)smoothwave->imagebuffer;
203 for (i=0;i<(smoothwave->width*smoothwave->height)/4;i++) {
205 *ptr -= ((*ptr & 0xf0f0f0f0ul) >> 4) + ((*ptr & 0xe0e0e0e0ul) >> 5);
212 /* GST_DEBUG ("drawing"); */
213 /* GST_DEBUG ("gdk_draw_indexed_image(%p,%p,%d,%d,%d,%d,%s,%p,%d,%p);",
214 smoothwave->image->window,
215 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
216 0,0,smoothwave->width,smoothwave->height,
217 "GDK_RGB_DITHER_NORMAL",
218 smoothwave->imagebuffer,smoothwave->width,
220 /* gdk_draw_indexed_image(smoothwave->image->window,
221 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
222 0,0,smoothwave->width,smoothwave->height,
224 smoothwave->imagebuffer,smoothwave->width,
226 gdk_draw_gray_image(smoothwave->image->window,
227 smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
228 0,0,smoothwave->width,smoothwave->height,
229 GDK_RGB_DITHER_NORMAL,
230 smoothwave->imagebuffer,smoothwave->width);
232 /* gst_trace_add_entry(NULL,0,buf,"smoothwave: calculated smoothwave"); */
234 gst_buffer_unref(buf);
238 gst_smoothwave_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
240 GstSmoothWave *smoothwave;
242 /* it's not null if we got it, but it might not be ours */
243 g_return_if_fail(GST_IS_SMOOTHWAVE(object));
244 smoothwave = GST_SMOOTHWAVE(object);
248 smoothwave->width = 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);
255 smoothwave->height = g_value_get_int (value);
256 gtk_drawing_area_size(GTK_DRAWING_AREA(smoothwave->image),
257 smoothwave->width,smoothwave->height);
258 gtk_widget_set_usize(GTK_WIDGET(smoothwave->image),
259 smoothwave->width,smoothwave->height);
267 gst_smoothwave_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
269 GstSmoothWave *smoothwave;
271 /* it's not null if we got it, but it might not be ours */
272 smoothwave = GST_SMOOTHWAVE(object);
276 g_value_set_int (value, smoothwave->width);
280 g_value_set_int (value, smoothwave->height);
284 g_value_set_object (value, smoothwave->image);
288 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
297 plugin_init (GstPlugin *plugin)
299 if (!gst_element_register (plugin, "smoothwave", GST_RANK_NONE, GST_TYPE_SMOOTHWAVE))
309 "Fading greyscale waveform display",