gstgoom.c 5.66 KB
Newer Older
1 2 3
/* gstgoom.c: implementation of goom drawing element
 * Copyright (C) <2001> Richard Boulton <richard@tartarus.org>
 *           (C) <2006> Wim Taymans <wim at fluendo dot com>
4
 *           (C) <2015> Luis de Bethencourt <luis@debethencourt.com>
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
18 19
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
20 21 22
 */

/**
Jan Schmidt's avatar
Jan Schmidt committed
23 24
 * SECTION:element-goom2k1
 * @see_also: goom, synaesthesia
25
 *
Jan Schmidt's avatar
Jan Schmidt committed
26 27 28
 * 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.
29 30
 *
 * <refsect2>
31
 * <title>Example launch line</title>
32
 * |[
33
 * gst-launch-1.0 -v audiotestsrc ! goom2k1 ! videoconvert ! xvimagesink
34
 * ]|
35 36 37 38 39 40 41 42 43 44 45 46 47 48
 * </refsect2>
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>
#include "gstgoom.h"
#include "goom_core.h"

GST_DEBUG_CATEGORY_STATIC (goom_debug);
#define GST_CAT_DEFAULT goom_debug

49 50 51 52 53
#define DEFAULT_WIDTH  320
#define DEFAULT_HEIGHT 240
#define DEFAULT_FPS_N  25
#define DEFAULT_FPS_D  1

54 55 56
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
Mark Nauwelaerts's avatar
Mark Nauwelaerts committed
57 58 59 60 61
#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
62 63 64 65 66
    );

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 */
Mark Nauwelaerts's avatar
Mark Nauwelaerts committed
67 68 69 70 71 72 73 74 75 76
    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")
77 78 79 80
    );

static void gst_goom_finalize (GObject * object);

81 82 83
static gboolean gst_goom_setup (GstAudioVisualizer * base);
static gboolean gst_goom_render (GstAudioVisualizer * base, GstBuffer * audio,
    GstVideoFrame * video);
84

85 86
typedef GstGoom GstGoom2k1;
typedef GstGoomClass GstGoom2k1Class;
87 88

G_DEFINE_TYPE (GstGoom2k1, gst_goom, GST_TYPE_AUDIO_VISUALIZER);
89 90 91 92 93 94

static void
gst_goom_class_init (GstGoomClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;
95
  GstAudioVisualizerClass *visualizer_class;
96 97 98

  gobject_class = (GObjectClass *) klass;
  gstelement_class = (GstElementClass *) klass;
99
  visualizer_class = (GstAudioVisualizerClass *) klass;
100 101 102

  gobject_class->finalize = gst_goom_finalize;

103
  gst_element_class_set_static_metadata (gstelement_class,
Mark Nauwelaerts's avatar
Mark Nauwelaerts committed
104 105 106 107 108 109 110 111
      "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));

112
  GST_DEBUG_CATEGORY_INIT (goom_debug, "goom", 0, "goom visualisation element");
113 114 115

  visualizer_class->setup = GST_DEBUG_FUNCPTR (gst_goom_setup);
  visualizer_class->render = GST_DEBUG_FUNCPTR (gst_goom_render);
116 117 118 119 120
}

static void
gst_goom_init (GstGoom * goom)
{
121 122
  goom->width = DEFAULT_WIDTH;
  goom->height = DEFAULT_HEIGHT;
123 124 125 126 127 128 129 130 131 132 133 134
  goom->channels = 0;

  goom_init (&(goom->goomdata), goom->width, goom->height);
}

static void
gst_goom_finalize (GObject * object)
{
  GstGoom *goom = GST_GOOM (object);

  goom_close (&(goom->goomdata));

135
  G_OBJECT_CLASS (gst_goom_parent_class)->finalize (object);
136 137 138
}

static gboolean
139
gst_goom_setup (GstAudioVisualizer * base)
140
{
141
  GstGoom *goom = GST_GOOM (base);
142

143 144
  goom->width = GST_VIDEO_INFO_WIDTH (&base->vinfo);
  goom->height = GST_VIDEO_INFO_HEIGHT (&base->vinfo);
145 146 147 148 149 150 151

  goom_set_resolution (&(goom->goomdata), goom->width, goom->height);

  return TRUE;
}

static gboolean
152 153 154 155 156
gst_goom_render (GstAudioVisualizer * base, GstBuffer * audio,
    GstVideoFrame * video)
{
  GstGoom *goom = GST_GOOM (base);
  GstMapInfo amap;
157
  gint16 datain[2][GOOM_SAMPLES];
158 159 160 161 162 163 164 165 166
  gint16 *adata;
  gint i;

  /* get next GOOM_SAMPLES, we have at least this amount of samples */
  gst_buffer_map (audio, &amap, GST_MAP_READ);
  adata = (gint16 *) amap.data;

  if (goom->channels == 2) {
    for (i = 0; i < GOOM_SAMPLES; i++) {
167 168
      datain[0][i] = *adata++;
      datain[1][i] = *adata++;
169
    }
170 171
  } else {
    for (i = 0; i < GOOM_SAMPLES; i++) {
172 173
      datain[0][i] = *adata;
      datain[1][i] = *adata++;
174 175 176
    }
  }

177
  video->data[0] = goom_update (&(goom->goomdata), datain);
178
  gst_buffer_unmap (audio, &amap);
179

180
  return TRUE;
181 182 183 184 185 186 187 188 189 190
}

static gboolean
plugin_init (GstPlugin * plugin)
{
  return gst_element_register (plugin, "goom2k1", GST_RANK_NONE, GST_TYPE_GOOM);
}

GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
191
    goom2k1,
192 193
    "GOOM 2k1 visualization filter",
    plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)