From 439c7c47e5bf7acfb4903f419f72586f883934e7 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Fri, 27 May 2011 11:14:19 +0300 Subject: [PATCH] scopes: first version of a scopes plugin using a new baseclass Add a new baseclass for writing visualisation plugins. Provide a simple wave oscilloscope as a first subclass. https://bugzilla.gnome.org/show_bug.cgi?id=651536 --- configure.ac | 2 + gst/scopes/Makefile.am | 30 +++ gst/scopes/gstbasescope.c | 422 ++++++++++++++++++++++++++++++++++++++ gst/scopes/gstbasescope.h | 81 ++++++++ gst/scopes/gstwavescope.c | 141 +++++++++++++ gst/scopes/gstwavescope.h | 50 +++++ gst/scopes/plugin.c | 37 ++++ 7 files changed, 763 insertions(+) create mode 100644 gst/scopes/Makefile.am create mode 100644 gst/scopes/gstbasescope.c create mode 100644 gst/scopes/gstbasescope.h create mode 100644 gst/scopes/gstwavescope.c create mode 100644 gst/scopes/gstwavescope.h create mode 100644 gst/scopes/plugin.c diff --git a/configure.ac b/configure.ac index 7ba1571e6c..56ac549ebc 100644 --- a/configure.ac +++ b/configure.ac @@ -346,6 +346,7 @@ AG_GST_CHECK_PLUGIN(real) AG_GST_CHECK_PLUGIN(rtpmux) AG_GST_CHECK_PLUGIN(rtpvp8) AG_GST_CHECK_PLUGIN(scaletempo) +AG_GST_CHECK_PLUGIN(scopes) AG_GST_CHECK_PLUGIN(sdi) AG_GST_CHECK_PLUGIN(sdp) AG_GST_CHECK_PLUGIN(segmentclip) @@ -1897,6 +1898,7 @@ gst/real/Makefile gst/rtpmux/Makefile gst/rtpvp8/Makefile gst/scaletempo/Makefile +gst/scopes/Makefile gst/sdi/Makefile gst/sdp/Makefile gst/segmentclip/Makefile diff --git a/gst/scopes/Makefile.am b/gst/scopes/Makefile.am new file mode 100644 index 0000000000..0df5d0d8e1 --- /dev/null +++ b/gst/scopes/Makefile.am @@ -0,0 +1,30 @@ +plugin_LTLIBRARIES = libgstscopes.la + +libgstscopes_la_SOURCES = \ + gstbasescope.c plugin.c \ + gstwavescope.c gstwavescope.h + +libgstscopes_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS)\ + $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) +libgstscopes_la_LIBADD = \ + $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_MAJORMINOR) \ + -lgstvideo-$(GST_MAJORMINOR) $(GST_BASE_LIBS) $(GST_LIBS) +libgstscopes_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) +libgstscopes_la_LIBTOOLFLAGS = --tag=disable-static + +noinst_HEADERS = gstbasescope.h gstwavescope.h + +Android.mk: Makefile.am $(BUILT_SOURCES) + androgenizer \ + -:PROJECT scopes -:SHARED scopes \ + -:TAGS eng debug \ + -:REL_TOP $(top_srcdir) -:ABS_TOP $(abs_top_srcdir) \ + -:SOURCES $(libgstscopes_la_SOURCES) \ + -:CFLAGS $(DEFS) $(DEFAULT_INCLUDES) $(libgstscopes_la_CFLAGS) \ + -:LDFLAGS $(libgstscopes_la_LDFLAGS) \ + $(libgstscopes_la_LIBADD) \ + -ldl \ + -:PASSTHROUGH LOCAL_ARM_MODE:=arm \ + LOCAL_MODULE_PATH:='$$(TARGET_OUT)/lib/gstreamer-0.10' \ + > $@ + diff --git a/gst/scopes/gstbasescope.c b/gst/scopes/gstbasescope.c new file mode 100644 index 0000000000..3e134eefd9 --- /dev/null +++ b/gst/scopes/gstbasescope.c @@ -0,0 +1,422 @@ +/* GStreamer + * Copyright (C) <2011> Stefan Kost + * + * gstbasescope.h: base class for audio visualisation elements + * + * 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. + */ +/** + * SECTION:gstbasescope + * + * A basclass for scopes. Takes care of re-fitting the audio-rate to video-rate. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include + +#include "gstbasescope.h" + +GST_DEBUG_CATEGORY_STATIC (base_scope_debug); +#define GST_CAT_DEFAULT (base_scope_debug) + +static GstBaseTransformClass *parent_class = NULL; + +static void gst_base_scope_class_init (GstBaseScopeClass * klass); +static void gst_base_scope_init (GstBaseScope * scope, + GstBaseScopeClass * g_class); +static void gst_base_scope_dispose (GObject * object); + +static gboolean gst_base_scope_src_negotiate (GstBaseScope * scope); +static gboolean gst_base_scope_src_setcaps (GstPad * pad, GstCaps * caps); +static gboolean gst_base_scope_sink_setcaps (GstPad * pad, GstCaps * caps); + +static GstFlowReturn gst_base_scope_chain (GstPad * pad, GstBuffer * buffer); +static GstStateChangeReturn gst_base_scope_change_state (GstElement * element, + GstStateChange transition); + +GType +gst_base_scope_get_type (void) +{ + static volatile gsize base_scope_type = 0; + + if (g_once_init_enter (&base_scope_type)) { + static const GTypeInfo base_scope_info = { + sizeof (GstBaseScopeClass), + NULL, + NULL, + (GClassInitFunc) gst_base_scope_class_init, + NULL, + NULL, + sizeof (GstBaseScope), + 0, + (GInstanceInitFunc) gst_base_scope_init, + }; + GType _type; + + _type = g_type_register_static (GST_TYPE_ELEMENT, + "GstBaseScope", &base_scope_info, G_TYPE_FLAG_ABSTRACT); + g_once_init_leave (&base_scope_type, _type); + } + return (GType) base_scope_type; +} + +static void +gst_base_scope_class_init (GstBaseScopeClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GstElementClass *element_class = (GstElementClass *) klass; + + parent_class = g_type_class_peek_parent (klass); + + GST_DEBUG_CATEGORY_INIT (base_scope_debug, "basescope", 0, + "scope audio visualisation base class"); + + gobject_class->dispose = gst_base_scope_dispose; + element_class->change_state = GST_DEBUG_FUNCPTR (gst_base_scope_change_state); +} + +static void +gst_base_scope_init (GstBaseScope * scope, GstBaseScopeClass * g_class) +{ + GstPadTemplate *pad_template; + + /* create the sink and src pads */ + pad_template = + gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "sink"); + g_return_if_fail (pad_template != NULL); + scope->sinkpad = gst_pad_new_from_template (pad_template, "sink"); + gst_pad_set_chain_function (scope->sinkpad, + GST_DEBUG_FUNCPTR (gst_base_scope_chain)); + gst_pad_set_setcaps_function (scope->sinkpad, + GST_DEBUG_FUNCPTR (gst_base_scope_sink_setcaps)); + gst_element_add_pad (GST_ELEMENT (scope), scope->sinkpad); + + pad_template = + gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src"); + g_return_if_fail (pad_template != NULL); + scope->srcpad = gst_pad_new_from_template (pad_template, "src"); + gst_pad_set_setcaps_function (scope->srcpad, + GST_DEBUG_FUNCPTR (gst_base_scope_src_setcaps)); + gst_element_add_pad (GST_ELEMENT (scope), scope->srcpad); + + scope->adapter = gst_adapter_new (); + scope->inbuf = gst_buffer_new (); + + /* reset the initial video state */ + scope->width = 320; + scope->height = 200; + scope->fps_n = 25; /* desired frame rate */ + scope->fps_d = 1; + scope->frame_duration = GST_CLOCK_TIME_NONE; + + /* reset the initial audio state */ + scope->rate = GST_AUDIO_DEF_RATE; + scope->channels = 2; + + scope->next_ts = GST_CLOCK_TIME_NONE; + +} + +static void +gst_base_scope_dispose (GObject * object) +{ + GstBaseScope *scope = GST_BASE_SCOPE (object); + + if (scope->adapter) { + g_object_unref (scope->adapter); + scope->adapter = NULL; + } + if (scope->inbuf) { + gst_buffer_unref (scope->inbuf); + scope->inbuf = NULL; + } + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static gboolean +gst_base_scope_sink_setcaps (GstPad * pad, GstCaps * caps) +{ + GstBaseScope *scope; + GstStructure *structure; + gint channels; + gint rate; + gboolean res = TRUE; + + scope = GST_BASE_SCOPE (gst_pad_get_parent (pad)); + structure = gst_caps_get_structure (caps, 0); + + if (!gst_structure_get_int (structure, "channels", &channels) || + !gst_structure_get_int (structure, "rate", &rate)) + goto missing_caps_details; + + if (channels != 2) + goto wrong_channels; + + if (rate <= 0) + goto wrong_rate; + + scope->channels = channels; + scope->rate = rate; + + GST_DEBUG_OBJECT (scope, "audio: channels %d, rate %d", + scope->channels, scope->rate); + +done: + gst_object_unref (scope); + return res; + + /* Errors */ +missing_caps_details: + { + GST_WARNING_OBJECT (scope, "missing channels or rate in the caps"); + res = FALSE; + goto done; + } +wrong_channels: + { + GST_WARNING_OBJECT (scope, "number of channels must be 2, but is %d", + channels); + res = FALSE; + goto done; + } +wrong_rate: + { + GST_WARNING_OBJECT (scope, "sample rate must be >0, but is %d", rate); + res = FALSE; + goto done; + } +} + +static gboolean +gst_base_scope_src_negotiate (GstBaseScope * scope) +{ + GstCaps *othercaps, *target, *intersect; + GstStructure *structure; + const GstCaps *templ; + + templ = gst_pad_get_pad_template_caps (scope->srcpad); + + GST_DEBUG_OBJECT (scope, "performing negotiation"); + + /* see what the peer can do */ + othercaps = gst_pad_peer_get_caps (scope->srcpad); + if (othercaps) { + intersect = gst_caps_intersect (othercaps, templ); + gst_caps_unref (othercaps); + + if (gst_caps_is_empty (intersect)) + goto no_format; + + target = gst_caps_copy_nth (intersect, 0); + gst_caps_unref (intersect); + } else { + target = gst_caps_ref ((GstCaps *) templ); + } + + structure = gst_caps_get_structure (target, 0); + gst_structure_fixate_field_nearest_int (structure, "width", scope->width); + gst_structure_fixate_field_nearest_int (structure, "height", scope->height); + gst_structure_fixate_field_nearest_fraction (structure, "framerate", + scope->fps_n, scope->fps_d); + + GST_DEBUG_OBJECT (scope, "final caps are %" GST_PTR_FORMAT, target); + + gst_pad_set_caps (scope->srcpad, target); + gst_caps_unref (target); + + return TRUE; + +no_format: + { + gst_caps_unref (intersect); + return FALSE; + } +} + +static gboolean +gst_base_scope_src_setcaps (GstPad * pad, GstCaps * caps) +{ + GstBaseScope *scope; + GstBaseScopeClass *klass; + gint w, h; + gint num, denom; + GstVideoFormat format; + gboolean res = TRUE; + + scope = GST_BASE_SCOPE (gst_pad_get_parent (pad)); + klass = GST_BASE_SCOPE_CLASS (G_OBJECT_GET_CLASS (scope)); + + if (!gst_video_format_parse_caps (caps, &format, &w, &h)) { + goto missing_caps_details; + } + if (!gst_video_parse_caps_framerate (caps, &num, &denom)) { + goto missing_caps_details; + } + + scope->width = w; + scope->height = h; + scope->fps_n = num; + scope->fps_d = denom; + scope->video_format = format; + + scope->frame_duration = gst_util_uint64_scale_int (GST_SECOND, + scope->fps_d, scope->fps_n); + scope->spf = gst_util_uint64_scale_int (scope->rate, + scope->fps_d, scope->fps_n); + + /* + synaesthesia_resize (scope->si, scope->width, scope->height); + */ + if (klass->setup) + res = klass->setup (scope); + + GST_DEBUG_OBJECT (scope, "video: dimension %dx%d, framerate %d/%d, spf %d", + scope->width, scope->height, scope->fps_n, scope->fps_d, scope->spf); + +done: + gst_object_unref (scope); + return res; + + /* Errors */ +missing_caps_details: + { + GST_WARNING_OBJECT (scope, + "missing width, height or framerate in the caps"); + res = FALSE; + goto done; + } +} + +static GstFlowReturn +gst_base_scope_chain (GstPad * pad, GstBuffer * buffer) +{ + GstFlowReturn ret = GST_FLOW_OK; + GstBaseScope *scope; + GstBaseScopeClass *klass; + GstBuffer *inbuf; + guint32 avail, bytesperread; + guint bpp; + gboolean (*render) (GstBaseScope * scope, GstBuffer * audio, + GstBuffer * video); + + scope = GST_BASE_SCOPE (gst_pad_get_parent (pad)); + klass = GST_BASE_SCOPE_CLASS (G_OBJECT_GET_CLASS (scope)); + + render = klass->render; + + GST_LOG_OBJECT (scope, "chainfunc called"); + + /* resync on DISCONT */ + if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) { + scope->next_ts = GST_CLOCK_TIME_NONE; + gst_adapter_clear (scope->adapter); + } + + if (GST_PAD_CAPS (scope->srcpad) == NULL) { + if (!gst_base_scope_src_negotiate (scope)) + return GST_FLOW_NOT_NEGOTIATED; + } + + /* Match timestamps from the incoming audio */ + if (GST_BUFFER_TIMESTAMP (buffer) != GST_CLOCK_TIME_NONE) + scope->next_ts = GST_BUFFER_TIMESTAMP (buffer); + + gst_adapter_push (scope->adapter, buffer); + + /* this is what we want */ + bytesperread = scope->spf * scope->channels * sizeof (gint16); + + bpp = gst_video_format_get_pixel_stride (scope->video_format, 0); + + inbuf = scope->inbuf; + /* FIXME: the timestamp in the adapter would be different */ + gst_buffer_copy_metadata (inbuf, buffer, GST_BUFFER_COPY_ALL); + + /* this is what we have */ + avail = gst_adapter_available (scope->adapter); + while (avail > bytesperread) { + GstBuffer *outbuf; + + ret = gst_pad_alloc_buffer_and_set_caps (scope->srcpad, + GST_BUFFER_OFFSET_NONE, + scope->width * scope->height * bpp, + GST_PAD_CAPS (scope->srcpad), &outbuf); + + /* no buffer allocated, we don't care why. */ + if (ret != GST_FLOW_OK) + break; + + GST_BUFFER_TIMESTAMP (outbuf) = scope->next_ts; + GST_BUFFER_DURATION (outbuf) = scope->frame_duration; + memset (GST_BUFFER_DATA (outbuf), 0, GST_BUFFER_SIZE (outbuf)); + + GST_BUFFER_DATA (inbuf) = + (guint8 *) gst_adapter_peek (scope->adapter, bytesperread); + GST_BUFFER_SIZE (inbuf) = bytesperread; + + /* + guchar * out_frame = (guchar *) + scope_update (scope->si, scope->datain); + memcpy (GST_BUFFER_DATA (outbuf), out_frame, GST_BUFFER_SIZE (outbuf)); + */ + /* call class->render() vmethod */ + if (render) + if (!render (scope, inbuf, outbuf)) { + ret = GST_FLOW_ERROR; + } + + ret = gst_pad_push (scope->srcpad, outbuf); + outbuf = NULL; + + /* FIXME: we want to ev. take less + * we need to align the audio-rate, video-rate and blocksize for render + */ + gst_adapter_flush (scope->adapter, bytesperread); + + if (ret != GST_FLOW_OK) + break; + + if (scope->next_ts != GST_CLOCK_TIME_NONE) + scope->next_ts += scope->frame_duration; + + avail = gst_adapter_available (scope->adapter); + } + + gst_object_unref (scope); + + return ret; +} + +static GstStateChangeReturn +gst_base_scope_change_state (GstElement * element, GstStateChange transition) +{ + GstBaseScope *scope; + + scope = GST_BASE_SCOPE (element); + + switch (transition) { + case GST_STATE_CHANGE_READY_TO_PAUSED: + scope->next_ts = GST_CLOCK_TIME_NONE; + gst_adapter_clear (scope->adapter); + break; + default: + break; + } + + return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); +} diff --git a/gst/scopes/gstbasescope.h b/gst/scopes/gstbasescope.h new file mode 100644 index 0000000000..6db0c575b0 --- /dev/null +++ b/gst/scopes/gstbasescope.h @@ -0,0 +1,81 @@ +/* GStreamer + * Copyright (C) <2011> Stefan Kost + * + * gstbasescope.c: base class for audio visualisation elements + * + * 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. + */ + +#ifndef __GST_BASE_SCOPE_H__ +#define __GST_BASE_SCOPE_H__ + +#include +#include + +#include +#include +#include + +G_BEGIN_DECLS +#define GST_TYPE_BASE_SCOPE (gst_base_scope_get_type()) +#define GST_BASE_SCOPE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_SCOPE,GstBaseScope)) +#define GST_BASE_SCOPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_SCOPE,GstBaseScopeClass)) +#define GST_IS_SYNAESTHESIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_SCOPE)) +#define GST_IS_SYNAESTHESIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_SCOPE)) +typedef struct _GstBaseScope GstBaseScope; +typedef struct _GstBaseScopeClass GstBaseScopeClass; + +struct _GstBaseScope +{ + GstElement parent; + + /* pads */ + GstPad *srcpad, *sinkpad; + + GstAdapter *adapter; + GstBuffer *inbuf; + + guint64 next_ts; /* the timestamp of the next frame */ + guint64 frame_duration; + guint bps; /* bytes per sample */ + guint spf; /* samples per video frame */ + + /* video state */ + GstVideoFormat video_format; + gint fps_n, fps_d; + gint width; + gint height; + gint channels; + + /* audio state */ + gint sample_rate; + gint rate; +}; + +struct _GstBaseScopeClass +{ + GstElementClass parent_class; + + /* virtual function, called whenever the format changes */ + gboolean (*setup) (GstBaseScope * scope); + + /* virtual function for rendering a frame */ + gboolean (*render) (GstBaseScope * scope, GstBuffer * audio, GstBuffer * video); +}; + +GType gst_base_scope_get_type (void); + +G_END_DECLS +#endif /* __GST_BASE_SCOPE_H__ */ diff --git a/gst/scopes/gstwavescope.c b/gst/scopes/gstwavescope.c new file mode 100644 index 0000000000..3d8519268a --- /dev/null +++ b/gst/scopes/gstwavescope.c @@ -0,0 +1,141 @@ +/* GStreamer + * Copyright (C) <2011> Stefan Kost + * + * gstwavescope.c: simple oscilloscope + * + * 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. + */ +/** + * SECTION:element-wavescope + * @see_also: goom + * + * Wavescope is a simple audio visualisation element. It renders the waveforms + * like on an oscilloscope. + * + * + * Example launch line + * |[ + * gst-launch audiotestsrc ! audioconvert ! wavescope ! ximagesink + * ]| + * + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstwavescope.h" + +static GstStaticPadTemplate gst_wave_scope_src_template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN) + ); + +static GstStaticPadTemplate gst_wave_scope_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS) + ); + + +GST_DEBUG_CATEGORY_STATIC (wave_scope_debug); +#define GST_CAT_DEFAULT wave_scope_debug + +static gboolean gst_wave_scope_setup (GstBaseScope * scope); +static gboolean gst_wave_scope_render (GstBaseScope * scope, GstBuffer * audio, + GstBuffer * video); + + +GST_BOILERPLATE (GstWaveScope, gst_wave_scope, GstBaseScope, + GST_TYPE_BASE_SCOPE); + +static void +gst_wave_scope_base_init (gpointer g_class) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + + gst_element_class_set_details_simple (element_class, "Waveform oscilloscope", + "Visualization", + "Simple waveform oscilloscope", "Stefan Kost "); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_wave_scope_src_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_wave_scope_sink_template)); +} + +static void +gst_wave_scope_class_init (GstWaveScopeClass * g_class) +{ + /*GObjectClass *gobject_class = (GObjectClass *) g_class; */ + GstBaseScopeClass *scope_class = (GstBaseScopeClass *) g_class; + + scope_class->setup = GST_DEBUG_FUNCPTR (gst_wave_scope_setup); + scope_class->render = GST_DEBUG_FUNCPTR (gst_wave_scope_render); +} + +static void +gst_wave_scope_init (GstWaveScope * scope, GstWaveScopeClass * g_class) +{ + /* do nothing */ +} + +static gboolean +gst_wave_scope_setup (GstBaseScope * scope) +{ + return TRUE; +} + +static gboolean +gst_wave_scope_render (GstBaseScope * scope, GstBuffer * audio, + GstBuffer * video) +{ + guint8 *vdata = GST_BUFFER_DATA (video); + gint16 *adata = (gint16 *) GST_BUFFER_DATA (audio); + guint i, c, s, x, y, off, oy; + guint num_samples; + gfloat dx, dy; + guint bpp = gst_video_format_get_pixel_stride (scope->video_format, 0); + guint bpl = bpp * scope->width; + + /* draw dots */ + num_samples = GST_BUFFER_SIZE (audio) / (scope->channels * sizeof (gint16)); + dx = (gfloat) scope->width / (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 * bpl) + (x * bpp); + vdata[off + 0] = 0xFF; + vdata[off + 1] = 0xFF; + vdata[off + 2] = 0xFF; + } + } + return TRUE; +} + +gboolean +gst_wave_scope_plugin_init (GstPlugin * plugin) +{ + GST_DEBUG_CATEGORY_INIT (wave_scope_debug, "wavescope", 0, "wavescope"); + + return gst_element_register (plugin, "wavescope", GST_RANK_NONE, + GST_TYPE_WAVE_SCOPE); +} diff --git a/gst/scopes/gstwavescope.h b/gst/scopes/gstwavescope.h new file mode 100644 index 0000000000..a4c734f412 --- /dev/null +++ b/gst/scopes/gstwavescope.h @@ -0,0 +1,50 @@ +/* GStreamer + * Copyright (C) <2011> Stefan Kost + * + * gstwavescope.h: simple oscilloscope + * + * 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. + */ + + +#ifndef __GST_WAVE_SCOPE_H__ +#define __GST_WAVE_SCOPE_H__ + +#include "gstbasescope.h" + +G_BEGIN_DECLS +#define GST_TYPE_WAVE_SCOPE (gst_wave_scope_get_type()) +#define GST_WAVE_SCOPE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WAVE_SCOPE,GstWaveScope)) +#define GST_WAVE_SCOPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_WAVE_SCOPE,GstWaveScopeClass)) +#define GST_IS_WAVE_SCOPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WAVE_SCOPE)) +#define GST_IS_WAVE_SCOPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_WAVE_SCOPE)) +typedef struct _GstWaveScope GstWaveScope; +typedef struct _GstWaveScopeClass GstWaveScopeClass; + +struct _GstWaveScope +{ + GstBaseScope parent; +}; + +struct _GstWaveScopeClass +{ + GstBaseScopeClass parent_class; +}; + +GType gst_wave_scope_get_type (void); +gboolean gst_wave_scope_plugin_init (GstPlugin * plugin); + +G_END_DECLS +#endif /* __GST_WAVE_SCOPE_H__ */ \ No newline at end of file diff --git a/gst/scopes/plugin.c b/gst/scopes/plugin.c new file mode 100644 index 0000000000..2a816e1d0a --- /dev/null +++ b/gst/scopes/plugin.c @@ -0,0 +1,37 @@ +/* GStreamer + * Copyright (C) <2011> Stefan Kost + * + * plugin.c: scopes plugin + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include "gstwavescope.h" + +static gboolean +plugin_init (GstPlugin * plugin) +{ + return gst_wave_scope_plugin_init (plugin); +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "scopes", + "Creates video visualizations of audio input", + plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)