summaryrefslogtreecommitdiff
path: root/gst/audiovisualizers
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2011-11-23 11:08:39 +0100
committerWim Taymans <wim.taymans@collabora.co.uk>2011-11-23 11:08:39 +0100
commit0a9387c43cffab2c357d79a64b02c1058b7cee89 (patch)
tree8cb09e4a9b5bdae8ffb8d4df3394920e132c3aa4 /gst/audiovisualizers
parente813abf631ac9cddd94f0137d2d717cf551fe4c9 (diff)
parente3d1a50c0d2a30558e3a46d9ba74d27f153cc670 (diff)
Merge branch 'master' into 0.11
Conflicts: ext/opus/gstopusdec.c ext/opus/gstopusenc.c ext/opus/gstopusparse.c gst/audiovisualizers/gstwavescope.c gst/filter/Makefile.am gst/filter/gstfilter.c gst/filter/gstiir.c gst/playondemand/gstplayondemand.c
Diffstat (limited to 'gst/audiovisualizers')
-rw-r--r--gst/audiovisualizers/Makefile.am2
-rw-r--r--gst/audiovisualizers/gstdrawhelpers.h37
-rw-r--r--gst/audiovisualizers/gstwavescope.c188
-rw-r--r--gst/audiovisualizers/gstwavescope.h6
4 files changed, 206 insertions, 27 deletions
diff --git a/gst/audiovisualizers/Makefile.am b/gst/audiovisualizers/Makefile.am
index d98bf05d2..c83f84a35 100644
--- a/gst/audiovisualizers/Makefile.am
+++ b/gst/audiovisualizers/Makefile.am
@@ -17,7 +17,7 @@ libgstaudiovisualizers_la_LIBADD = \
libgstaudiovisualizers_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstaudiovisualizers_la_LIBTOOLFLAGS = --tag=disable-static
-noinst_HEADERS = gstbaseaudiovisualizer.h \
+noinst_HEADERS = gstbaseaudiovisualizer.h gstdrawhelpers.h \
gstspacescope.h gstspectrascope.h gstsynaescope.h gstwavescope.h
Android.mk: Makefile.am $(BUILT_SOURCES)
diff --git a/gst/audiovisualizers/gstdrawhelpers.h b/gst/audiovisualizers/gstdrawhelpers.h
new file mode 100644
index 000000000..d3597ff62
--- /dev/null
+++ b/gst/audiovisualizers/gstdrawhelpers.h
@@ -0,0 +1,37 @@
+/* GStreamer
+ * Copyright (C) <2011> Stefan Sauer <ensonic@users.sf.net>
+ *
+ * gstdrawhelpers.h: simple drawing helpers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#define draw_dot(_vd, _x, _y, _st, _c) G_STMT_START { \
+ _vd[(_y * _st) + _x] = _c; \
+} G_STMT_END
+
+#define draw_line(_vd, _x1, _x2, _y1, _y2, _st, _c) G_STMT_START { \
+ guint _i, _j, _x, _y; \
+ gint _dx = _x2 - _x1, _dy = _y2 - _y1; \
+ gfloat _f; \
+ \
+ _j = abs (_dx) > abs (_dy) ? abs (_dx) : abs (_dy); \
+ for (_i = 0; _i < _j; _i++) { \
+ _f = (gfloat) _i / (gfloat) _j; \
+ _x = _x1 + _dx * _f; \
+ _y = _y1 + _dy * _f; \
+ draw_dot (_vd, _x, _y, _st, _c); \
+ } \
+} G_STMT_END
diff --git a/gst/audiovisualizers/gstwavescope.c b/gst/audiovisualizers/gstwavescope.c
index 62ef81671..1d2abd1ef 100644
--- a/gst/audiovisualizers/gstwavescope.c
+++ b/gst/audiovisualizers/gstwavescope.c
@@ -35,6 +35,7 @@
#include "config.h"
#endif
+#include <stdlib.h>
#include "gstwavescope.h"
static GstStaticPadTemplate gst_wave_scope_src_template =
@@ -61,26 +62,76 @@ GST_STATIC_PAD_TEMPLATE ("sink",
GST_DEBUG_CATEGORY_STATIC (wave_scope_debug);
#define GST_CAT_DEFAULT wave_scope_debug
-static gboolean gst_wave_scope_render (GstBaseAudioVisualizer * scope,
- GstBuffer * audio, GstBuffer * video);
+enum
+{
+ PROP_0,
+ PROP_STYLE
+};
+
+enum
+{
+ STYLE_DOTS = 0,
+ STYLE_LINES,
+ NUM_STYLES
+};
+
+#define GST_TYPE_WAVE_SCOPE_STYLE (gst_wave_scope_style_get_type ())
+static GType
+gst_wave_scope_style_get_type (void)
+{
+ static GType gtype = 0;
+
+ if (gtype == 0) {
+ static const GEnumValue values[] = {
+ {STYLE_DOTS, "draw dots (default)", "dots"},
+ {STYLE_LINES, "draw lines", "lines"},
+ {0, NULL, NULL}
+ };
+ gtype = g_enum_register_static ("GstWaveScopeStyle", values);
+ }
+ return gtype;
+}
+
+static void gst_wave_scope_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void gst_wave_scope_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec);
+
+static void render_dots (GstBaseAudioVisualizer * scope, guint32 * vdata,
+ gint16 * adata, guint num_samples);
+static void render_lines (GstBaseAudioVisualizer * scope, guint32 * vdata,
+ gint16 * adata, guint num_samples);
+
+static gboolean gst_wave_scope_render (GstBaseAudioVisualizer * base,
+ GstBuffer * audio, GstBuffer * video);
G_DEFINE_TYPE (GstWaveScope, gst_wave_scope, GST_TYPE_BASE_AUDIO_VISUALIZER);
static void
gst_wave_scope_class_init (GstWaveScopeClass * g_class)
{
- GstElementClass *element_class = (GstElementClass *) g_class;
+ GObjectClass *gobject_class = (GObjectClass *) g_class;
+ GstElementClass *gstelement_class = (GstElementClass *) g_class;
GstBaseAudioVisualizerClass *scope_class =
(GstBaseAudioVisualizerClass *) g_class;
- gst_element_class_set_details_simple (element_class, "Waveform oscilloscope",
- "Visualization",
- "Simple waveform oscilloscope", "Stefan Kost <ensonic@users.sf.net>");
+ gobject_class->set_property = gst_wave_scope_set_property;
+ gobject_class->get_property = gst_wave_scope_get_property;
+
+ g_object_class_install_property (gobject_class, PROP_STYLE,
+ g_param_spec_enum ("style", "drawing style",
+ "Drawing styles for the wave form display.",
+ GST_TYPE_WAVE_SCOPE_STYLE, STYLE_DOTS,
+ G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
- gst_element_class_add_pad_template (element_class,
+ gst_element_class_set_details_simple (gstelement_class,
+ "Waveform oscilloscope", "Visualization", "Simple waveform oscilloscope",
+ "Stefan Kost <ensonic@users.sf.net>");
+
+ gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_wave_scope_src_template));
- gst_element_class_add_pad_template (element_class,
+ gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_wave_scope_sink_template));
scope_class->render = GST_DEBUG_FUNCPTR (gst_wave_scope_render);
@@ -92,35 +143,120 @@ gst_wave_scope_init (GstWaveScope * scope)
/* do nothing */
}
-static gboolean
-gst_wave_scope_render (GstBaseAudioVisualizer * scope, GstBuffer * audio,
- GstBuffer * video)
+static void
+gst_wave_scope_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
{
- gsize asize;
- guint32 *vdata =
- (guint32 *) gst_buffer_map (video, NULL, NULL, GST_MAP_WRITE);
- gint16 *adata = (gint16 *) gst_buffer_map (audio, &asize, NULL, GST_MAP_READ);
- guint i, c, s, x, y, off, oy;
- guint num_samples;
+ GstWaveScope *scope = GST_WAVE_SCOPE (object);
+
+ switch (prop_id) {
+ case PROP_STYLE:
+ scope->style = g_value_get_enum (value);
+ switch (scope->style) {
+ case STYLE_DOTS:
+ scope->process = render_dots;
+ break;
+ case STYLE_LINES:
+ scope->process = render_lines;
+ break;
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_wave_scope_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
+{
+ GstWaveScope *scope = GST_WAVE_SCOPE (object);
+
+ switch (prop_id) {
+ case PROP_STYLE:
+ g_value_set_enum (value, scope->style);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+#include "gstdrawhelpers.h"
+
+static void
+render_dots (GstBaseAudioVisualizer * scope, guint32 * vdata, gint16 * adata,
+ guint num_samples)
+{
+ gint channels = scope->channels;
+ guint i, c, s, x, y, oy;
gfloat dx, dy;
guint w = scope->width;
/* draw dots */
- num_samples = asize / (scope->channels * sizeof (gint16));
- dx = (gfloat) scope->width / (gfloat) num_samples;
+ dx = (gfloat) w / (gfloat) num_samples;
dy = scope->height / 65536.0;
oy = scope->height / 2;
- s = 0;
- for (i = 0; i < num_samples; i++) {
- x = (guint) ((gfloat) i * dx);
- for (c = 0; c < scope->channels; c++) {
- y = (guint) (oy + (gfloat) adata[s++] * dy);
- off = (y * w) + x;
- vdata[off] = 0x00FFFFFF;
+ for (c = 0; c < channels; c++) {
+ s = c;
+ for (i = 0; i < num_samples; i++) {
+ x = (guint) ((gfloat) i * dx);
+ y = (guint) (oy + (gfloat) adata[s] * dy);
+ s += channels;
+ draw_dot (vdata, x, y, w, 0x00FFFFFF);
}
}
+}
+
+static void
+render_lines (GstBaseAudioVisualizer * scope, guint32 * vdata, gint16 * adata,
+ guint num_samples)
+{
+ gint channels = scope->channels;
+ guint i, c, s, x, y, oy;
+ gfloat dx, dy;
+ guint w = scope->width;
+ gint x2, y2;
+
+ /* draw lines */
+ dx = (gfloat) w / (gfloat) num_samples;
+ dy = scope->height / 65536.0;
+ oy = scope->height / 2;
+ for (c = 0; c < channels; c++) {
+ s = c;
+ x2 = 0;
+ y2 = (guint) (oy + (gfloat) adata[s] * dy);
+ for (i = 1; i < num_samples; i++) {
+ x = (guint) ((gfloat) i * dx);
+ y = (guint) (oy + (gfloat) adata[s] * dy);
+ s += channels;
+ draw_line (vdata, x2, x, y2, y, w, 0x00FFFFFF);
+ x2 = x;
+ y2 = y;
+ }
+ }
+}
+
+static gboolean
+gst_wave_scope_render (GstBaseAudioVisualizer * base, GstBuffer * audio,
+ GstBuffer * video)
+{
+ GstWaveScope *scope = GST_WAVE_SCOPE (base);
+ guint32 *vdata;
+ gsize asize;
+ gint16 *adata;
+ guint num_samples;
+
+ adata = gst_buffer_map (audio, &asize, NULL, GST_MAP_READ);
+ vdata = gst_buffer_map (video, NULL, NULL, GST_MAP_WRITE);
+
+ num_samples = asize / (base->channels * sizeof (gint16));
+ scope->process (base, vdata, adata, num_samples);
+
gst_buffer_unmap (video, vdata, -1);
gst_buffer_unmap (audio, adata, -1);
+
return TRUE;
}
diff --git a/gst/audiovisualizers/gstwavescope.h b/gst/audiovisualizers/gstwavescope.h
index 1467663a3..ffe3411f5 100644
--- a/gst/audiovisualizers/gstwavescope.h
+++ b/gst/audiovisualizers/gstwavescope.h
@@ -33,9 +33,15 @@ G_BEGIN_DECLS
typedef struct _GstWaveScope GstWaveScope;
typedef struct _GstWaveScopeClass GstWaveScopeClass;
+typedef void (*GstWaveScopeProcessFunc) (GstBaseAudioVisualizer *, guint32 *, gint16 *, guint);
+
struct _GstWaveScope
{
GstBaseAudioVisualizer parent;
+
+ /* < private > */
+ GstWaveScopeProcessFunc process;
+ gint style;
};
struct _GstWaveScopeClass