2008-02-23 01:51:37 +00:00
|
|
|
/* gstgoom.c: implementation of goom drawing element
|
|
|
|
* Copyright (C) <2001> Richard Boulton <richard@tartarus.org>
|
|
|
|
* (C) <2006> Wim Taymans <wim at fluendo dot com>
|
2015-06-02 16:52:46 +00:00
|
|
|
* (C) <2015> Luis de Bethencourt <luis@debethencourt.com>
|
2008-02-23 01:51:37 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-02-23 01:51:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2008-05-11 14:43:26 +00:00
|
|
|
* SECTION:element-goom2k1
|
|
|
|
* @see_also: goom, synaesthesia
|
2008-02-23 01:51:37 +00:00
|
|
|
*
|
2008-05-11 14:43:26 +00:00
|
|
|
* Goom2k1 is an audio visualisation element. It creates warping structures
|
|
|
|
* based on the incomming audio signal. Goom2k1 is the older version of the
|
|
|
|
* visualisation. Also available is goom2k4, with a different look.
|
2009-01-28 10:29:42 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
2008-02-23 01:51:37 +00:00
|
|
|
* <title>Example launch line</title>
|
2009-01-28 10:29:42 +00:00
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 -v audiotestsrc ! goom2k1 ! videoconvert ! xvimagesink
|
2009-01-28 10:29:42 +00:00
|
|
|
* ]|
|
2008-02-23 01:51:37 +00:00
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "gstgoom.h"
|
|
|
|
#include "goom_core.h"
|
|
|
|
|
2015-08-10 19:55:19 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (goom2k1_debug);
|
|
|
|
#define GST_CAT_DEFAULT goom2k1_debug
|
2008-02-23 01:51:37 +00:00
|
|
|
|
2010-10-04 16:56:15 +00:00
|
|
|
#define DEFAULT_WIDTH 320
|
|
|
|
#define DEFAULT_HEIGHT 240
|
|
|
|
#define DEFAULT_FPS_N 25
|
|
|
|
#define DEFAULT_FPS_D 1
|
|
|
|
|
2008-02-23 01:51:37 +00:00
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-02-16 22:33:01 +00:00
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("xRGB"))
|
|
|
|
#else
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("BGRx"))
|
|
|
|
#endif
|
2008-02-23 01:51:37 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", /* the name of the pads */
|
|
|
|
GST_PAD_SINK, /* type of the pad */
|
|
|
|
GST_PAD_ALWAYS, /* ALWAYS/SOMETIMES */
|
2012-02-16 22:33:01 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw, "
|
|
|
|
"format = (string) " GST_AUDIO_NE (S16) ", "
|
|
|
|
"rate = (int) [ 8000, 96000 ], "
|
|
|
|
"channels = (int) 1, "
|
|
|
|
"layout = (string) interleaved; "
|
|
|
|
"audio/x-raw, "
|
|
|
|
"format = (string) " GST_AUDIO_NE (S16) ", "
|
|
|
|
"rate = (int) [ 8000, 96000 ], "
|
|
|
|
"channels = (int) 2, "
|
|
|
|
"channel-mask = (bitmask) 0x3, " "layout = (string) interleaved")
|
2008-02-23 01:51:37 +00:00
|
|
|
);
|
|
|
|
|
2015-08-10 19:55:19 +00:00
|
|
|
static void gst_goom2k1_finalize (GObject * object);
|
2008-02-23 01:51:37 +00:00
|
|
|
|
2015-08-10 19:55:19 +00:00
|
|
|
static gboolean gst_goom2k1_setup (GstAudioVisualizer * base);
|
2015-08-10 20:19:18 +00:00
|
|
|
static gboolean gst_goom2k1_render (GstAudioVisualizer * base,
|
2015-08-10 19:55:19 +00:00
|
|
|
GstBuffer * audio, GstVideoFrame * video);
|
2008-02-23 01:51:37 +00:00
|
|
|
|
2015-06-02 16:52:46 +00:00
|
|
|
|
2015-08-10 19:55:19 +00:00
|
|
|
G_DEFINE_TYPE (GstGoom2k1, gst_goom2k1, GST_TYPE_AUDIO_VISUALIZER);
|
2008-02-23 01:51:37 +00:00
|
|
|
|
|
|
|
static void
|
2015-08-10 19:55:19 +00:00
|
|
|
gst_goom2k1_class_init (GstGoom2k1Class * klass)
|
2008-02-23 01:51:37 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2015-06-02 16:52:46 +00:00
|
|
|
GstAudioVisualizerClass *visualizer_class;
|
2008-02-23 01:51:37 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2015-06-02 16:52:46 +00:00
|
|
|
visualizer_class = (GstAudioVisualizerClass *) klass;
|
2008-02-23 01:51:37 +00:00
|
|
|
|
2015-08-10 19:55:19 +00:00
|
|
|
gobject_class->finalize = gst_goom2k1_finalize;
|
2008-02-23 01:51:37 +00:00
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2012-02-16 22:33:01 +00:00
|
|
|
"GOOM: what a GOOM! 2k1 edition", "Visualization",
|
|
|
|
"Takes frames of data and outputs video frames using the GOOM 2k1 filter",
|
|
|
|
"Wim Taymans <wim@fluendo.com>");
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&sink_template));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&src_template));
|
|
|
|
|
2015-08-10 19:55:19 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (goom2k1_debug, "goom2k1", 0,
|
|
|
|
"goom2k1 visualisation element");
|
2015-06-02 16:52:46 +00:00
|
|
|
|
2015-08-10 19:55:19 +00:00
|
|
|
visualizer_class->setup = GST_DEBUG_FUNCPTR (gst_goom2k1_setup);
|
|
|
|
visualizer_class->render = GST_DEBUG_FUNCPTR (gst_goom2k1_render);
|
2008-02-23 01:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-10 19:55:19 +00:00
|
|
|
gst_goom2k1_init (GstGoom2k1 * goom)
|
2008-02-23 01:51:37 +00:00
|
|
|
{
|
2010-10-04 16:56:15 +00:00
|
|
|
goom->width = DEFAULT_WIDTH;
|
|
|
|
goom->height = DEFAULT_HEIGHT;
|
2008-02-23 01:51:37 +00:00
|
|
|
goom->channels = 0;
|
|
|
|
|
|
|
|
goom_init (&(goom->goomdata), goom->width, goom->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-10 19:55:19 +00:00
|
|
|
gst_goom2k1_finalize (GObject * object)
|
2008-02-23 01:51:37 +00:00
|
|
|
{
|
2015-08-10 19:55:19 +00:00
|
|
|
GstGoom2k1 *goom = GST_GOOM2K1 (object);
|
2008-02-23 01:51:37 +00:00
|
|
|
|
|
|
|
goom_close (&(goom->goomdata));
|
|
|
|
|
2015-08-10 19:55:19 +00:00
|
|
|
G_OBJECT_CLASS (gst_goom2k1_parent_class)->finalize (object);
|
2008-02-23 01:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-08-10 19:55:19 +00:00
|
|
|
gst_goom2k1_setup (GstAudioVisualizer * base)
|
2008-02-23 01:51:37 +00:00
|
|
|
{
|
2015-08-10 19:55:19 +00:00
|
|
|
GstGoom2k1 *goom = GST_GOOM2K1 (base);
|
2008-02-23 01:51:37 +00:00
|
|
|
|
2015-06-02 16:52:46 +00:00
|
|
|
goom->width = GST_VIDEO_INFO_WIDTH (&base->vinfo);
|
|
|
|
goom->height = GST_VIDEO_INFO_HEIGHT (&base->vinfo);
|
2008-02-23 01:51:37 +00:00
|
|
|
|
|
|
|
goom_set_resolution (&(goom->goomdata), goom->width, goom->height);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-08-10 19:55:19 +00:00
|
|
|
gst_goom2k1_render (GstAudioVisualizer * base, GstBuffer * audio,
|
2015-06-02 16:52:46 +00:00
|
|
|
GstVideoFrame * video)
|
|
|
|
{
|
2015-08-10 19:55:19 +00:00
|
|
|
GstGoom2k1 *goom = GST_GOOM2K1 (base);
|
2015-06-02 16:52:46 +00:00
|
|
|
GstMapInfo amap;
|
2015-08-10 19:55:19 +00:00
|
|
|
gint16 datain[2][GOOM2K1_SAMPLES];
|
2015-06-02 16:52:46 +00:00
|
|
|
gint16 *adata;
|
|
|
|
gint i;
|
|
|
|
|
2015-08-10 19:55:19 +00:00
|
|
|
/* get next GOOM2K1_SAMPLES, we have at least this amount of samples */
|
2015-06-02 16:52:46 +00:00
|
|
|
gst_buffer_map (audio, &amap, GST_MAP_READ);
|
|
|
|
adata = (gint16 *) amap.data;
|
|
|
|
|
|
|
|
if (goom->channels == 2) {
|
2015-08-10 19:55:19 +00:00
|
|
|
for (i = 0; i < GOOM2K1_SAMPLES; i++) {
|
2015-06-02 17:09:48 +00:00
|
|
|
datain[0][i] = *adata++;
|
|
|
|
datain[1][i] = *adata++;
|
2008-02-23 01:51:37 +00:00
|
|
|
}
|
2015-06-02 16:52:46 +00:00
|
|
|
} else {
|
2015-08-10 19:55:19 +00:00
|
|
|
for (i = 0; i < GOOM2K1_SAMPLES; i++) {
|
2015-06-02 17:09:48 +00:00
|
|
|
datain[0][i] = *adata;
|
|
|
|
datain[1][i] = *adata++;
|
2008-02-23 01:51:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 17:09:48 +00:00
|
|
|
video->data[0] = goom_update (&(goom->goomdata), datain);
|
2015-06-02 16:52:46 +00:00
|
|
|
gst_buffer_unmap (audio, &amap);
|
2008-02-23 01:51:37 +00:00
|
|
|
|
2015-06-02 16:52:46 +00:00
|
|
|
return TRUE;
|
2008-02-23 01:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2015-08-10 19:55:19 +00:00
|
|
|
return gst_element_register (plugin, "goom2k1", GST_RANK_NONE,
|
|
|
|
GST_TYPE_GOOM2K1);
|
2008-02-23 01:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 15:36:38 +00:00
|
|
|
goom2k1,
|
2008-02-23 01:51:37 +00:00
|
|
|
"GOOM 2k1 visualization filter",
|
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|