2002-03-20 21:45:04 +00:00
|
|
|
/* GStreamer
|
2001-12-30 20:10:15 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-30 20:10:15 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstsmoothwave.h"
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails gst_smoothwave_details =
|
|
|
|
GST_ELEMENT_DETAILS ("Smooth waveform",
|
|
|
|
"Visualization",
|
|
|
|
"Fading grayscale waveform display",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>");
|
2001-12-30 20:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* SmoothWave signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-30 20:10:15 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-30 20:10:15 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_WIDTH,
|
|
|
|
ARG_HEIGHT,
|
2004-05-21 23:28:57 +00:00
|
|
|
ARG_WIDGET
|
2001-12-30 20:10:15 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_smoothwave_base_init (gpointer g_class);
|
|
|
|
static void gst_smoothwave_class_init (GstSmoothWaveClass * klass);
|
|
|
|
static void gst_smoothwave_init (GstSmoothWave * smoothwave);
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_smoothwave_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_smoothwave_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_smoothwave_chain (GstPad * pad, GstData * _data);
|
2001-12-30 20:10:15 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-03-19 04:10:06 +00:00
|
|
|
/*static guint gst_smoothwave_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-30 20:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_smoothwave_get_type (void)
|
|
|
|
{
|
|
|
|
static GType smoothwave_type = 0;
|
|
|
|
|
|
|
|
if (!smoothwave_type) {
|
|
|
|
static const GTypeInfo smoothwave_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstSmoothWaveClass),
|
2003-11-02 01:32:40 +00:00
|
|
|
gst_smoothwave_base_init,
|
2001-12-30 20:10:15 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) gst_smoothwave_class_init,
|
2001-12-30 20:10:15 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstSmoothWave),
|
2001-12-30 20:10:15 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_smoothwave_init,
|
2001-12-30 20:10:15 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
smoothwave_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstSmoothWave",
|
|
|
|
&smoothwave_info, 0);
|
2001-12-30 20:10:15 +00:00
|
|
|
}
|
|
|
|
return smoothwave_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 01:32:40 +00:00
|
|
|
static void
|
|
|
|
gst_smoothwave_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_smoothwave_details);
|
|
|
|
}
|
|
|
|
|
2001-12-30 20:10:15 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_smoothwave_class_init (GstSmoothWaveClass * klass)
|
2001-12-30 20:10:15 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_WIDTH, g_param_spec_int ("width", "width", "width", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HEIGHT, g_param_spec_int ("height", "height", "height", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_WIDGET, g_param_spec_object ("widget", "widget", "widget", GTK_TYPE_WIDGET, G_PARAM_READABLE)); /* CHECKME! */
|
2001-12-30 20:10:15 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_smoothwave_set_property;
|
|
|
|
gobject_class->get_property = gst_smoothwave_get_property;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_smoothwave_init (GstSmoothWave * smoothwave)
|
2001-12-30 20:10:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
guint32 palette[256];
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
smoothwave->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (smoothwave), smoothwave->sinkpad);
|
|
|
|
gst_pad_set_chain_function (smoothwave->sinkpad, gst_smoothwave_chain);
|
|
|
|
smoothwave->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (smoothwave), smoothwave->srcpad);
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2002-03-19 04:10:06 +00:00
|
|
|
/* smoothwave->meta = NULL; */
|
2001-12-30 20:10:15 +00:00
|
|
|
smoothwave->width = 512;
|
|
|
|
smoothwave->height = 256;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gdk_rgb_init ();
|
2002-03-19 04:10:06 +00:00
|
|
|
/* gtk_widget_set_default_colormap (gdk_rgb_get_cmap()); */
|
|
|
|
/* gtk_widget_set_default_visual (gdk_rgb_get_visual()); */
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
/* GST_DEBUG ("creating palette"); */
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
2001-12-30 20:10:15 +00:00
|
|
|
palette[i] = (i << 16) || (i << 8);
|
2003-06-29 19:46:13 +00:00
|
|
|
/* GST_DEBUG ("creating cmap"); */
|
2004-03-14 22:34:33 +00:00
|
|
|
smoothwave->cmap = gdk_rgb_cmap_new (palette, 256);
|
2003-06-29 19:46:13 +00:00
|
|
|
/* GST_DEBUG ("created cmap"); */
|
2002-03-19 04:10:06 +00:00
|
|
|
/* gtk_widget_set_default_colormap (smoothwave->cmap); */
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
smoothwave->image = gtk_drawing_area_new ();
|
|
|
|
gtk_drawing_area_size (GTK_DRAWING_AREA (smoothwave->image),
|
|
|
|
smoothwave->width, smoothwave->height);
|
|
|
|
gtk_widget_show (smoothwave->image);
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
smoothwave->imagebuffer = g_malloc (smoothwave->width * smoothwave->height);
|
|
|
|
memset (smoothwave->imagebuffer, 0, smoothwave->width * smoothwave->height);
|
2001-12-30 20:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_smoothwave_chain (GstPad * pad, GstData * _data)
|
2001-12-30 20:10:15 +00:00
|
|
|
{
|
2003-10-08 16:08:19 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-30 20:10:15 +00:00
|
|
|
GstSmoothWave *smoothwave;
|
|
|
|
gint16 *samples;
|
2004-03-14 22:34:33 +00:00
|
|
|
gint samplecount, i;
|
2001-12-30 20:10:15 +00:00
|
|
|
register guint32 *ptr;
|
|
|
|
gint qheight;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2002-03-19 04:10:06 +00:00
|
|
|
/* g_return_if_fail(GST_IS_BUFFER(buf)); */
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
smoothwave = GST_SMOOTHWAVE (GST_OBJECT_PARENT (pad));
|
2001-12-30 20:10:15 +00:00
|
|
|
|
|
|
|
/* first deal with audio metadata */
|
2003-07-17 04:16:42 +00:00
|
|
|
#if 0
|
|
|
|
if (buf->meta) {
|
|
|
|
if (smoothwave->meta != NULL) {
|
|
|
|
/* FIXME: need to unref the old metadata so it goes away */
|
|
|
|
}
|
|
|
|
/* we just make a copy of the pointer */
|
2004-03-14 22:34:33 +00:00
|
|
|
smoothwave->meta = (MetaAudioRaw *) (buf->meta);
|
2003-07-17 04:16:42 +00:00
|
|
|
/* FIXME: now we have to ref the metadata so it doesn't go away */
|
|
|
|
}
|
|
|
|
#endif
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2002-03-19 04:10:06 +00:00
|
|
|
/* g_return_if_fail(smoothwave->meta != NULL); */
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
samples = (gint16 *) GST_BUFFER_DATA (buf);
|
2002-03-19 04:10:06 +00:00
|
|
|
/* samplecount = buf->datasize / (smoothwave->meta->channels * sizeof(gint16)); */
|
2004-03-14 22:34:33 +00:00
|
|
|
samplecount = GST_BUFFER_SIZE (buf) / (2 * sizeof (gint16));
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
qheight = smoothwave->height / 4;
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
/* GST_DEBUG ("traversing %d",smoothwave->width); */
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < MAX (smoothwave->width, samplecount); i++) {
|
|
|
|
gint16 y1 = (gint32) (samples[i * 2] * qheight) / 32768 + qheight;
|
|
|
|
gint16 y2 = (gint32) (samples[(i * 2) + 1] * qheight) / 32768 +
|
2004-03-15 19:32:27 +00:00
|
|
|
(qheight * 3);
|
2004-03-14 22:34:33 +00:00
|
|
|
smoothwave->imagebuffer[y1 * smoothwave->width + i] = 0xff;
|
|
|
|
smoothwave->imagebuffer[y2 * smoothwave->width + i] = 0xff;
|
2002-03-19 04:10:06 +00:00
|
|
|
/* smoothwave->imagebuffer[i+(smoothwave->width*5)] = i; */
|
2001-12-30 20:10:15 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
ptr = (guint32 *) smoothwave->imagebuffer;
|
|
|
|
for (i = 0; i < (smoothwave->width * smoothwave->height) / 4; i++) {
|
|
|
|
if (*ptr) {
|
2003-07-17 04:16:42 +00:00
|
|
|
*ptr -= ((*ptr & 0xf0f0f0f0ul) >> 4) + ((*ptr & 0xe0e0e0e0ul) >> 5);
|
|
|
|
ptr++;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2001-12-30 20:10:15 +00:00
|
|
|
ptr++;
|
2003-07-17 04:16:42 +00:00
|
|
|
}
|
2001-12-30 20:10:15 +00:00
|
|
|
}
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
/* GST_DEBUG ("drawing"); */
|
|
|
|
/* GST_DEBUG ("gdk_draw_indexed_image(%p,%p,%d,%d,%d,%d,%s,%p,%d,%p);",
|
2001-12-30 20:10:15 +00:00
|
|
|
smoothwave->image->window,
|
|
|
|
smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
|
|
|
|
0,0,smoothwave->width,smoothwave->height,
|
|
|
|
"GDK_RGB_DITHER_NORMAL",
|
|
|
|
smoothwave->imagebuffer,smoothwave->width,
|
|
|
|
smoothwave->cmap);*/
|
|
|
|
/* gdk_draw_indexed_image(smoothwave->image->window,
|
|
|
|
smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
|
|
|
|
0,0,smoothwave->width,smoothwave->height,
|
|
|
|
GDK_RGB_DITHER_NONE,
|
|
|
|
smoothwave->imagebuffer,smoothwave->width,
|
|
|
|
smoothwave->cmap);*/
|
2004-03-14 22:34:33 +00:00
|
|
|
gdk_draw_gray_image (smoothwave->image->window,
|
|
|
|
smoothwave->image->style->fg_gc[GTK_STATE_NORMAL],
|
|
|
|
0, 0, smoothwave->width, smoothwave->height,
|
|
|
|
GDK_RGB_DITHER_NORMAL, smoothwave->imagebuffer, smoothwave->width);
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2002-03-19 04:10:06 +00:00
|
|
|
/* gst_trace_add_entry(NULL,0,buf,"smoothwave: calculated smoothwave"); */
|
2001-12-30 20:10:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_buffer_unref (buf);
|
2001-12-30 20:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_smoothwave_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2001-12-30 20:10:15 +00:00
|
|
|
{
|
|
|
|
GstSmoothWave *smoothwave;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_SMOOTHWAVE (object));
|
|
|
|
smoothwave = GST_SMOOTHWAVE (object);
|
2001-12-30 20:10:15 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_WIDTH:
|
|
|
|
smoothwave->width = g_value_get_int (value);
|
2004-03-14 22:34:33 +00:00
|
|
|
gtk_drawing_area_size (GTK_DRAWING_AREA (smoothwave->image),
|
2004-03-15 19:32:27 +00:00
|
|
|
smoothwave->width, smoothwave->height);
|
2004-03-14 22:34:33 +00:00
|
|
|
gtk_widget_set_usize (GTK_WIDGET (smoothwave->image),
|
2004-03-15 19:32:27 +00:00
|
|
|
smoothwave->width, smoothwave->height);
|
2001-12-30 20:10:15 +00:00
|
|
|
break;
|
|
|
|
case ARG_HEIGHT:
|
|
|
|
smoothwave->height = g_value_get_int (value);
|
2004-03-14 22:34:33 +00:00
|
|
|
gtk_drawing_area_size (GTK_DRAWING_AREA (smoothwave->image),
|
2004-03-15 19:32:27 +00:00
|
|
|
smoothwave->width, smoothwave->height);
|
2004-03-14 22:34:33 +00:00
|
|
|
gtk_widget_set_usize (GTK_WIDGET (smoothwave->image),
|
2004-03-15 19:32:27 +00:00
|
|
|
smoothwave->width, smoothwave->height);
|
2001-12-30 20:10:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_smoothwave_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-30 20:10:15 +00:00
|
|
|
{
|
|
|
|
GstSmoothWave *smoothwave;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:33 +00:00
|
|
|
smoothwave = GST_SMOOTHWAVE (object);
|
2001-12-30 20:10:15 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2004-03-14 22:34:33 +00:00
|
|
|
case ARG_WIDTH:{
|
2001-12-30 20:10:15 +00:00
|
|
|
g_value_set_int (value, smoothwave->width);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
case ARG_HEIGHT:{
|
2001-12-30 20:10:15 +00:00
|
|
|
g_value_set_int (value, smoothwave->height);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
case ARG_WIDGET:{
|
2001-12-30 20:10:15 +00:00
|
|
|
g_value_set_object (value, smoothwave->image);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
default:{
|
2001-12-30 20:10:15 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-30 20:10:15 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_element_register (plugin, "smoothwave", GST_RANK_NONE,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_SMOOTHWAVE))
|
2003-11-02 01:32:40 +00:00
|
|
|
return FALSE;
|
2001-12-30 20:10:15 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"smoothwave",
|
|
|
|
"Fading greyscale waveform display",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
|