summaryrefslogtreecommitdiff
path: root/gst/audiovisualizers/gstspacescope.c
diff options
context:
space:
mode:
Diffstat (limited to 'gst/audiovisualizers/gstspacescope.c')
-rw-r--r--gst/audiovisualizers/gstspacescope.c153
1 files changed, 141 insertions, 12 deletions
diff --git a/gst/audiovisualizers/gstspacescope.c b/gst/audiovisualizers/gstspacescope.c
index 85621f619..973dd74be 100644
--- a/gst/audiovisualizers/gstspacescope.c
+++ b/gst/audiovisualizers/gstspacescope.c
@@ -35,6 +35,7 @@
#include "config.h"
#endif
+#include <stdlib.h>
#include "gstspacescope.h"
static GstStaticPadTemplate gst_space_scope_src_template =
@@ -61,6 +62,47 @@ GST_STATIC_PAD_TEMPLATE ("sink",
GST_DEBUG_CATEGORY_STATIC (space_scope_debug);
#define GST_CAT_DEFAULT space_scope_debug
+enum
+{
+ PROP_0,
+ PROP_STYLE
+};
+
+enum
+{
+ STYLE_DOTS = 0,
+ STYLE_LINES,
+ NUM_STYLES
+};
+
+#define GST_TYPE_SPACE_SCOPE_STYLE (gst_space_scope_style_get_type ())
+static GType
+gst_space_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 ("GstSpaceScopeStyle", values);
+ }
+ return gtype;
+}
+
+static void gst_space_scope_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void gst_space_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_space_scope_render (GstBaseAudioVisualizer * scope,
GstBuffer * audio, GstBuffer * video);
@@ -70,6 +112,7 @@ G_DEFINE_TYPE (GstSpaceScope, gst_space_scope, GST_TYPE_BASE_AUDIO_VISUALIZER);
static void
gst_space_scope_class_init (GstSpaceScopeClass * g_class)
{
+ GObjectClass *gobject_class = (GObjectClass *) g_class;
GstElementClass *element_class = (GstElementClass *) g_class;
GstBaseAudioVisualizerClass *scope_class =
(GstBaseAudioVisualizerClass *) g_class;
@@ -83,7 +126,16 @@ gst_space_scope_class_init (GstSpaceScopeClass * g_class)
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_space_scope_sink_template));
+ gobject_class->set_property = gst_space_scope_set_property;
+ gobject_class->get_property = gst_space_scope_get_property;
+
scope_class->render = GST_DEBUG_FUNCPTR (gst_space_scope_render);
+
+ g_object_class_install_property (gobject_class, PROP_STYLE,
+ g_param_spec_enum ("style", "drawing style",
+ "Drawing styles for the space scope display.",
+ GST_TYPE_SPACE_SCOPE_STYLE, STYLE_DOTS,
+ G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
static void
@@ -92,21 +144,57 @@ gst_space_scope_init (GstSpaceScope * scope)
/* do nothing */
}
-static gboolean
-gst_space_scope_render (GstBaseAudioVisualizer * scope, GstBuffer * audio,
- GstBuffer * video)
+static void
+gst_space_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, s, x, y, off, ox, oy;
- guint num_samples;
+ GstSpaceScope *scope = GST_SPACE_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_space_scope_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
+{
+ GstSpaceScope *scope = GST_SPACE_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)
+{
+ guint i, s, x, y, ox, oy;
gfloat dx, dy;
guint w = scope->width;
/* draw dots 1st channel x, 2nd channel y */
- num_samples = asize / (scope->channels * sizeof (gint16));
dx = scope->width / 65536.0;
ox = scope->width / 2;
dy = scope->height / 65536.0;
@@ -115,9 +203,50 @@ gst_space_scope_render (GstBaseAudioVisualizer * scope, GstBuffer * audio,
for (i = 0; i < num_samples; i++) {
x = (guint) (ox + (gfloat) adata[s++] * dx);
y = (guint) (oy + (gfloat) adata[s++] * dy);
- off = (y * w) + x;
- vdata[off] = 0x00FFFFFF;
+ draw_dot (vdata, x, y, w, 0x00FFFFFF);
+ }
+}
+
+static void
+render_lines (GstBaseAudioVisualizer * scope, guint32 * vdata, gint16 * adata,
+ guint num_samples)
+{
+ guint i, s, x, y, ox, oy;
+ gfloat dx, dy;
+ guint w = scope->width;
+ guint h = scope->height;
+ gint x2, y2;
+
+ /* draw lines 1st channel x, 2nd channel y */
+ dx = (w - 1) / 65536.0;
+ ox = (w - 1) / 2;
+ dy = (h - 1) / 65536.0;
+ oy = (h - 1) / 2;
+ s = 0;
+ x2 = (guint) (ox + (gfloat) adata[s++] * dx);
+ y2 = (guint) (oy + (gfloat) adata[s++] * dy);
+ for (i = 1; i < num_samples; i++) {
+ x = (guint) (ox + (gfloat) adata[s++] * dx);
+ y = (guint) (oy + (gfloat) adata[s++] * dy);
+ draw_line_aa (vdata, x2, x, y2, y, w, 0x00FFFFFF);
+ x2 = x;
+ y2 = y;
}
+}
+
+static gboolean
+gst_space_scope_render (GstBaseAudioVisualizer * base, GstBuffer * audio,
+ GstBuffer * video)
+{
+ GstSpaceScope *scope = GST_SPACE_SCOPE (base);
+ 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 num_samples;
+
+ 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;