2011-05-27 08:14:19 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2011> Stefan Kost <ensonic@users.sf.net>
|
|
|
|
*
|
2011-06-04 11:33:29 +00:00
|
|
|
* gstbaseaudiovisualizer.h: base class for audio visualisation elements
|
2011-05-27 08:14:19 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
/**
|
2011-06-04 11:33:29 +00:00
|
|
|
* SECTION:gstbaseaudiovisualizer
|
2011-05-27 08:14:19 +00:00
|
|
|
*
|
2011-08-12 19:22:20 +00:00
|
|
|
* A basclass for scopes (visualizers). It takes care of re-fitting the
|
|
|
|
* audio-rate to video-rate and handles renegotiation (downstream video size
|
|
|
|
* changes).
|
|
|
|
*
|
|
|
|
* It also provides several background shading effects. These effects are
|
|
|
|
* applied to a previous picture before the render() implementation can draw a
|
|
|
|
* new frame.
|
2011-05-27 08:14:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
#include "gstbaseaudiovisualizer.h"
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (base_audio_visualizer_debug);
|
|
|
|
#define GST_CAT_DEFAULT (base_audio_visualizer_debug)
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
#define DEFAULT_SHADER GST_BASE_AUDIO_VISUALIZER_SHADER_FADE
|
2011-05-28 11:08:05 +00:00
|
|
|
#define DEFAULT_SHADE_AMOUNT 0x000a0a0a
|
|
|
|
|
2011-05-27 20:25:00 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2011-05-28 11:08:05 +00:00
|
|
|
PROP_SHADER,
|
|
|
|
PROP_SHADE_AMOUNT
|
2011-05-27 20:25:00 +00:00
|
|
|
};
|
|
|
|
|
2011-05-27 08:14:19 +00:00
|
|
|
static GstBaseTransformClass *parent_class = NULL;
|
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
static void gst_base_audio_visualizer_class_init (GstBaseAudioVisualizerClass *
|
|
|
|
klass);
|
|
|
|
static void gst_base_audio_visualizer_init (GstBaseAudioVisualizer * scope,
|
|
|
|
GstBaseAudioVisualizerClass * g_class);
|
|
|
|
static void gst_base_audio_visualizer_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_base_audio_visualizer_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_base_audio_visualizer_dispose (GObject * object);
|
|
|
|
|
|
|
|
static gboolean gst_base_audio_visualizer_src_negotiate (GstBaseAudioVisualizer
|
|
|
|
* scope);
|
2011-11-09 19:09:01 +00:00
|
|
|
static gboolean gst_base_audio_visualizer_src_setcaps (GstBaseAudioVisualizer *
|
|
|
|
scope, GstCaps * caps);
|
|
|
|
static gboolean gst_base_audio_visualizer_sink_setcaps (GstBaseAudioVisualizer *
|
|
|
|
scope, GstCaps * caps);
|
2011-06-04 11:33:29 +00:00
|
|
|
|
|
|
|
static GstFlowReturn gst_base_audio_visualizer_chain (GstPad * pad,
|
2011-11-17 14:53:42 +00:00
|
|
|
GstObject * parent, GstBuffer * buffer);
|
2011-11-09 19:09:01 +00:00
|
|
|
|
|
|
|
static gboolean gst_base_audio_visualizer_src_event (GstPad * pad,
|
2011-11-17 14:53:42 +00:00
|
|
|
GstObject * parent, GstEvent * event);
|
2011-11-09 19:09:01 +00:00
|
|
|
static gboolean gst_base_audio_visualizer_sink_event (GstPad * pad,
|
2011-11-17 14:53:42 +00:00
|
|
|
GstObject * parent, GstEvent * event);
|
2011-11-09 19:09:01 +00:00
|
|
|
|
|
|
|
static gboolean gst_base_audio_visualizer_src_query (GstPad * pad,
|
2011-11-16 16:28:10 +00:00
|
|
|
GstObject * parent, GstQuery * query);
|
2011-11-09 19:09:01 +00:00
|
|
|
static gboolean gst_base_audio_visualizer_sink_query (GstPad * pad,
|
2011-11-16 16:28:10 +00:00
|
|
|
GstObject * parent, GstQuery * query);
|
2011-11-09 19:09:01 +00:00
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
static GstStateChangeReturn gst_base_audio_visualizer_change_state (GstElement *
|
|
|
|
element, GstStateChange transition);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-05-27 20:25:00 +00:00
|
|
|
/* shading functions */
|
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
#define GST_TYPE_BASE_AUDIO_VISUALIZER_SHADER (gst_base_audio_visualizer_shader_get_type())
|
2011-05-27 20:25:00 +00:00
|
|
|
static GType
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_shader_get_type (void)
|
2011-05-27 20:25:00 +00:00
|
|
|
{
|
|
|
|
static GType shader_type = 0;
|
|
|
|
static const GEnumValue shaders[] = {
|
2011-06-04 11:33:29 +00:00
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_NONE, "None", "none"},
|
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_FADE, "Fade", "fade"},
|
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_UP, "Fade and move up",
|
2011-05-27 20:25:00 +00:00
|
|
|
"fade-and-move-up"},
|
2011-06-04 11:33:29 +00:00
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_DOWN, "Fade and move down",
|
2011-05-28 11:36:51 +00:00
|
|
|
"fade-and-move-down"},
|
2011-08-12 20:39:53 +00:00
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_LEFT, "Fade and move left",
|
|
|
|
"fade-and-move-left"},
|
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_RIGHT,
|
|
|
|
"Fade and move right",
|
|
|
|
"fade-and-move-right"},
|
2011-06-04 11:33:29 +00:00
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_OUT,
|
2011-08-12 20:39:53 +00:00
|
|
|
"Fade and move horizontally out", "fade-and-move-horiz-out"},
|
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_IN,
|
|
|
|
"Fade and move horizontally in", "fade-and-move-horiz-in"},
|
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_OUT,
|
|
|
|
"Fade and move vertically out", "fade-and-move-vert-out"},
|
|
|
|
{GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_IN,
|
|
|
|
"Fade and move vertically in", "fade-and-move-vert-in"},
|
2011-05-27 20:25:00 +00:00
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (G_UNLIKELY (shader_type == 0)) {
|
2011-06-04 11:33:29 +00:00
|
|
|
shader_type =
|
|
|
|
g_enum_register_static ("GstBaseAudioVisualizerShader", shaders);
|
2011-05-27 20:25:00 +00:00
|
|
|
}
|
|
|
|
return shader_type;
|
|
|
|
}
|
|
|
|
|
2011-08-12 20:39:53 +00:00
|
|
|
/* we're only supporting GST_VIDEO_FORMAT_xRGB right now) */
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
|
|
|
|
#define SHADE1(_d, _s, _i, _r, _g, _b) \
|
|
|
|
G_STMT_START { \
|
|
|
|
_d[_i] = (_s[_i] > _b) ? _s[_i] - _b : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_i] = (_s[_i] > _g) ? _s[_i] - _g : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_i] = (_s[_i] > _r) ? _s[_i] - _r : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_i++] = 0; \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define SHADE2(_d, _s, _j, _i, _r, _g, _b) \
|
|
|
|
G_STMT_START { \
|
|
|
|
_d[_j++] = (_s[_i] > _b) ? _s[_i] - _b : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_j++] = (_s[_i] > _g) ? _s[_i] - _g : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_j++] = (_s[_i] > _r) ? _s[_i] - _r : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_j++] = 0; \
|
|
|
|
_i++; \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define SHADE1(_d, _s, _i, _r, _g, _b) \
|
|
|
|
G_STMT_START { \
|
|
|
|
_d[_i++] = 0; \
|
|
|
|
_d[_i] = (_s[_i] > _r) ? _s[_i] - _r : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_i] = (_s[_i] > _g) ? _s[_i] - _g : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_i] = (_s[_i] > _b) ? _s[_i] - _b : 0; \
|
|
|
|
_i++; \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define SHADE2(_d, _s, _j, _i, _r, _g, _b) \
|
|
|
|
G_STMT_START { \
|
|
|
|
_d[_j++] = 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_j++] = (_s[_i] > _r) ? _s[_i] - _r : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_j++] = (_s[_i] > _g) ? _s[_i] - _g : 0; \
|
|
|
|
_i++; \
|
|
|
|
_d[_j++] = (_s[_i] > _b) ? _s[_i] - _b : 0; \
|
|
|
|
_i++; \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-05-27 20:25:00 +00:00
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
shader_fade (GstBaseAudioVisualizer * scope, const guint8 * s, guint8 * d)
|
2011-05-27 20:25:00 +00:00
|
|
|
{
|
|
|
|
guint i, bpf = scope->bpf;
|
2011-05-28 11:08:05 +00:00
|
|
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
|
|
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
|
|
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
|
|
|
|
|
|
|
for (i = 0; i < bpf;) {
|
2011-08-12 20:39:53 +00:00
|
|
|
SHADE1 (d, s, i, r, g, b);
|
2011-05-28 11:08:05 +00:00
|
|
|
}
|
2011-05-27 20:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
shader_fade_and_move_up (GstBaseAudioVisualizer * scope, const guint8 * s,
|
|
|
|
guint8 * d)
|
2011-05-27 20:25:00 +00:00
|
|
|
{
|
|
|
|
guint i, j, bpf = scope->bpf;
|
|
|
|
guint bpl = 4 * scope->width;
|
2011-05-28 11:08:05 +00:00
|
|
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
|
|
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
|
|
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
|
|
|
|
|
|
|
for (j = 0, i = bpl; i < bpf;) {
|
2011-08-12 20:39:53 +00:00
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
2011-05-27 20:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-28 11:36:51 +00:00
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
shader_fade_and_move_down (GstBaseAudioVisualizer * scope, const guint8 * s,
|
|
|
|
guint8 * d)
|
2011-05-28 11:36:51 +00:00
|
|
|
{
|
|
|
|
guint i, j, bpf = scope->bpf;
|
|
|
|
guint bpl = 4 * scope->width;
|
|
|
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
|
|
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
|
|
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
|
|
|
|
|
|
|
for (j = bpl, i = 0; j < bpf;) {
|
2011-08-12 20:39:53 +00:00
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
2011-05-28 11:36:51 +00:00
|
|
|
}
|
2011-08-12 20:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shader_fade_and_move_left (GstBaseAudioVisualizer * scope,
|
|
|
|
const guint8 * s, guint8 * d)
|
|
|
|
{
|
|
|
|
guint i, j, k, bpf = scope->bpf;
|
|
|
|
guint w = scope->width;
|
|
|
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
|
|
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
|
|
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
|
|
|
|
|
|
|
/* move to the left */
|
|
|
|
for (j = 0, i = 4; i < bpf;) {
|
|
|
|
for (k = 0; k < w - 1; k++) {
|
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
|
|
|
}
|
|
|
|
i += 4;
|
|
|
|
j += 4;
|
2011-05-28 11:36:51 +00:00
|
|
|
}
|
2011-08-12 20:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shader_fade_and_move_right (GstBaseAudioVisualizer * scope,
|
|
|
|
const guint8 * s, guint8 * d)
|
|
|
|
{
|
|
|
|
guint i, j, k, bpf = scope->bpf;
|
|
|
|
guint w = scope->width;
|
|
|
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
|
|
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
|
|
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
|
|
|
|
|
|
|
/* move to the left */
|
|
|
|
for (j = 4, i = 0; i < bpf;) {
|
|
|
|
for (k = 0; k < w - 1; k++) {
|
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
|
|
|
}
|
|
|
|
i += 4;
|
|
|
|
j += 4;
|
2011-05-28 11:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
shader_fade_and_move_horiz_out (GstBaseAudioVisualizer * scope,
|
|
|
|
const guint8 * s, guint8 * d)
|
2011-05-28 11:36:51 +00:00
|
|
|
{
|
|
|
|
guint i, j, bpf = scope->bpf / 2;
|
|
|
|
guint bpl = 4 * scope->width;
|
|
|
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
|
|
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
|
|
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
|
|
|
|
2011-08-12 20:39:53 +00:00
|
|
|
/* move upper half up */
|
2011-05-28 11:36:51 +00:00
|
|
|
for (j = 0, i = bpl; i < bpf;) {
|
2011-08-12 20:39:53 +00:00
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
2011-05-28 11:36:51 +00:00
|
|
|
}
|
2011-08-12 20:39:53 +00:00
|
|
|
/* move lower half down */
|
2011-05-28 11:36:51 +00:00
|
|
|
for (j = bpf + bpl, i = bpf; j < bpf + bpf;) {
|
2011-08-12 20:39:53 +00:00
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
2011-05-28 11:36:51 +00:00
|
|
|
}
|
2011-08-12 20:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shader_fade_and_move_horiz_in (GstBaseAudioVisualizer * scope,
|
|
|
|
const guint8 * s, guint8 * d)
|
|
|
|
{
|
|
|
|
guint i, j, bpf = scope->bpf / 2;
|
|
|
|
guint bpl = 4 * scope->width;
|
|
|
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
|
|
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
|
|
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
|
|
|
|
|
|
|
/* move upper half down */
|
|
|
|
for (i = 0, j = bpl; i < bpf;) {
|
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
2011-05-28 11:36:51 +00:00
|
|
|
}
|
2011-08-12 20:39:53 +00:00
|
|
|
/* move lower half up */
|
|
|
|
for (i = bpf + bpl, j = bpf; i < bpf + bpf;) {
|
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
2011-05-28 11:36:51 +00:00
|
|
|
}
|
2011-08-12 20:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shader_fade_and_move_vert_out (GstBaseAudioVisualizer * scope,
|
|
|
|
const guint8 * s, guint8 * d)
|
|
|
|
{
|
|
|
|
guint i, j, k, bpf = scope->bpf;
|
|
|
|
guint m = scope->width / 2;
|
|
|
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
|
|
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
|
|
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
|
|
|
|
|
|
|
/* move left half to the left */
|
|
|
|
for (j = 0, i = 4; i < bpf;) {
|
|
|
|
for (k = 0; k < m; k++) {
|
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
|
|
|
}
|
|
|
|
j += 4 * m;
|
|
|
|
i += 4 * m;
|
2011-05-28 11:36:51 +00:00
|
|
|
}
|
2011-08-12 20:39:53 +00:00
|
|
|
/* move right half to the right */
|
|
|
|
for (j = 4 * (m + 1), i = 4 * m; j < bpf;) {
|
|
|
|
for (k = 0; k < m; k++) {
|
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
|
|
|
}
|
|
|
|
j += 4 * m;
|
|
|
|
i += 4 * m;
|
2011-05-28 11:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 20:39:53 +00:00
|
|
|
static void
|
|
|
|
shader_fade_and_move_vert_in (GstBaseAudioVisualizer * scope,
|
|
|
|
const guint8 * s, guint8 * d)
|
|
|
|
{
|
|
|
|
guint i, j, k, bpf = scope->bpf;
|
|
|
|
guint m = scope->width / 2;
|
|
|
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
|
|
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
|
|
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
|
|
|
|
|
|
|
/* move left half to the right */
|
|
|
|
for (j = 4, i = 0; j < bpf;) {
|
|
|
|
for (k = 0; k < m; k++) {
|
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
|
|
|
}
|
|
|
|
j += 4 * m;
|
|
|
|
i += 4 * m;
|
|
|
|
}
|
|
|
|
/* move right half to the left */
|
|
|
|
for (j = 4 * m, i = 4 * (m + 1); i < bpf;) {
|
|
|
|
for (k = 0; k < m; k++) {
|
|
|
|
SHADE2 (d, s, j, i, r, g, b);
|
|
|
|
}
|
|
|
|
j += 4 * m;
|
|
|
|
i += 4 * m;
|
|
|
|
}
|
|
|
|
}
|
2011-05-28 11:36:51 +00:00
|
|
|
|
2011-05-27 20:25:00 +00:00
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_change_shader (GstBaseAudioVisualizer * scope)
|
2011-05-27 20:25:00 +00:00
|
|
|
{
|
|
|
|
switch (scope->shader_type) {
|
2011-06-04 11:33:29 +00:00
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_NONE:
|
2011-05-27 20:25:00 +00:00
|
|
|
scope->shader = NULL;
|
|
|
|
break;
|
2011-06-04 11:33:29 +00:00
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_FADE:
|
2011-05-27 20:25:00 +00:00
|
|
|
scope->shader = shader_fade;
|
|
|
|
break;
|
2011-06-04 11:33:29 +00:00
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_UP:
|
2011-05-27 20:25:00 +00:00
|
|
|
scope->shader = shader_fade_and_move_up;
|
|
|
|
break;
|
2011-06-04 11:33:29 +00:00
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_DOWN:
|
2011-05-28 11:36:51 +00:00
|
|
|
scope->shader = shader_fade_and_move_down;
|
|
|
|
break;
|
2011-08-12 20:39:53 +00:00
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_LEFT:
|
|
|
|
scope->shader = shader_fade_and_move_left;
|
|
|
|
break;
|
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_RIGHT:
|
|
|
|
scope->shader = shader_fade_and_move_right;
|
|
|
|
break;
|
2011-06-04 11:33:29 +00:00
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_OUT:
|
2011-05-28 11:36:51 +00:00
|
|
|
scope->shader = shader_fade_and_move_horiz_out;
|
|
|
|
break;
|
2011-08-12 20:39:53 +00:00
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_IN:
|
|
|
|
scope->shader = shader_fade_and_move_horiz_in;
|
|
|
|
break;
|
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_OUT:
|
|
|
|
scope->shader = shader_fade_and_move_vert_out;
|
|
|
|
break;
|
|
|
|
case GST_BASE_AUDIO_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_IN:
|
|
|
|
scope->shader = shader_fade_and_move_vert_in;
|
|
|
|
break;
|
2011-05-27 20:25:00 +00:00
|
|
|
default:
|
|
|
|
GST_ERROR ("invalid shader function");
|
|
|
|
scope->shader = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* base class */
|
|
|
|
|
2011-05-27 08:14:19 +00:00
|
|
|
GType
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_get_type (void)
|
2011-05-27 08:14:19 +00:00
|
|
|
{
|
2011-06-04 11:33:29 +00:00
|
|
|
static volatile gsize base_audio_visualizer_type = 0;
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
if (g_once_init_enter (&base_audio_visualizer_type)) {
|
|
|
|
static const GTypeInfo base_audio_visualizer_info = {
|
|
|
|
sizeof (GstBaseAudioVisualizerClass),
|
2011-05-27 08:14:19 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-06-04 11:33:29 +00:00
|
|
|
(GClassInitFunc) gst_base_audio_visualizer_class_init,
|
2011-05-27 08:14:19 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-06-04 11:33:29 +00:00
|
|
|
sizeof (GstBaseAudioVisualizer),
|
2011-05-27 08:14:19 +00:00
|
|
|
0,
|
2011-06-04 11:33:29 +00:00
|
|
|
(GInstanceInitFunc) gst_base_audio_visualizer_init,
|
2011-05-27 08:14:19 +00:00
|
|
|
};
|
|
|
|
GType _type;
|
|
|
|
|
|
|
|
_type = g_type_register_static (GST_TYPE_ELEMENT,
|
2011-06-04 11:33:29 +00:00
|
|
|
"GstBaseAudioVisualizer", &base_audio_visualizer_info,
|
|
|
|
G_TYPE_FLAG_ABSTRACT);
|
|
|
|
g_once_init_leave (&base_audio_visualizer_type, _type);
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
2011-06-04 11:33:29 +00:00
|
|
|
return (GType) base_audio_visualizer_type;
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_class_init (GstBaseAudioVisualizerClass * klass)
|
2011-05-27 08:14:19 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *element_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (base_audio_visualizer_debug, "baseaudiovisualizer",
|
|
|
|
0, "scope audio visualisation base class");
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
gobject_class->set_property = gst_base_audio_visualizer_set_property;
|
|
|
|
gobject_class->get_property = gst_base_audio_visualizer_get_property;
|
|
|
|
gobject_class->dispose = gst_base_audio_visualizer_dispose;
|
2011-05-27 20:25:00 +00:00
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
element_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_visualizer_change_state);
|
2011-05-27 20:25:00 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SHADER,
|
|
|
|
g_param_spec_enum ("shader", "shader type",
|
2011-06-04 11:33:29 +00:00
|
|
|
"Shader function to apply on each frame",
|
|
|
|
GST_TYPE_BASE_AUDIO_VISUALIZER_SHADER, DEFAULT_SHADER,
|
2011-05-27 20:25:00 +00:00
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
|
2011-05-28 11:08:05 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SHADE_AMOUNT,
|
|
|
|
g_param_spec_uint ("shade-amount", "shade amount",
|
|
|
|
"Shading color to use (big-endian ARGB)", 0, G_MAXUINT32,
|
|
|
|
DEFAULT_SHADE_AMOUNT,
|
|
|
|
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_init (GstBaseAudioVisualizer * scope,
|
|
|
|
GstBaseAudioVisualizerClass * g_class)
|
2011-05-27 08:14:19 +00:00
|
|
|
{
|
|
|
|
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,
|
2011-06-04 11:33:29 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_visualizer_chain));
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_pad_set_event_function (scope->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_visualizer_sink_event));
|
|
|
|
gst_pad_set_query_function (scope->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_visualizer_sink_query));
|
2011-05-27 08:14:19 +00:00
|
|
|
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");
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_pad_set_event_function (scope->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_visualizer_src_event));
|
|
|
|
gst_pad_set_query_function (scope->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_base_audio_visualizer_src_query));
|
2011-05-27 08:14:19 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (scope), scope->srcpad);
|
|
|
|
|
|
|
|
scope->adapter = gst_adapter_new ();
|
|
|
|
scope->inbuf = gst_buffer_new ();
|
|
|
|
|
2011-05-27 20:25:00 +00:00
|
|
|
/* properties */
|
|
|
|
scope->shader_type = DEFAULT_SHADER;
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_change_shader (scope);
|
2011-05-28 11:08:05 +00:00
|
|
|
scope->shade_amount = DEFAULT_SHADE_AMOUNT;
|
2011-05-27 20:25:00 +00:00
|
|
|
|
2011-05-27 08:14:19 +00:00
|
|
|
/* 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;
|
|
|
|
|
2011-08-12 19:18:44 +00:00
|
|
|
scope->config_lock = g_mutex_new ();
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
|
|
|
|
2011-05-27 20:25:00 +00:00
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_set_property (GObject * object, guint prop_id,
|
2011-05-27 20:25:00 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-06-04 11:33:29 +00:00
|
|
|
GstBaseAudioVisualizer *scope = GST_BASE_AUDIO_VISUALIZER (object);
|
2011-05-27 20:25:00 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_SHADER:
|
|
|
|
scope->shader_type = g_value_get_enum (value);
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_change_shader (scope);
|
2011-05-27 20:25:00 +00:00
|
|
|
break;
|
2011-05-28 11:08:05 +00:00
|
|
|
case PROP_SHADE_AMOUNT:
|
|
|
|
scope->shade_amount = g_value_get_uint (value);
|
|
|
|
break;
|
2011-05-27 20:25:00 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_get_property (GObject * object, guint prop_id,
|
2011-05-27 20:25:00 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-06-04 11:33:29 +00:00
|
|
|
GstBaseAudioVisualizer *scope = GST_BASE_AUDIO_VISUALIZER (object);
|
2011-05-27 20:25:00 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_SHADER:
|
|
|
|
g_value_set_enum (value, scope->shader_type);
|
|
|
|
break;
|
2011-05-28 11:08:05 +00:00
|
|
|
case PROP_SHADE_AMOUNT:
|
|
|
|
g_value_set_uint (value, scope->shade_amount);
|
|
|
|
break;
|
2011-05-27 20:25:00 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 08:14:19 +00:00
|
|
|
static void
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_dispose (GObject * object)
|
2011-05-27 08:14:19 +00:00
|
|
|
{
|
2011-06-04 11:33:29 +00:00
|
|
|
GstBaseAudioVisualizer *scope = GST_BASE_AUDIO_VISUALIZER (object);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
|
|
|
if (scope->adapter) {
|
|
|
|
g_object_unref (scope->adapter);
|
|
|
|
scope->adapter = NULL;
|
|
|
|
}
|
|
|
|
if (scope->inbuf) {
|
|
|
|
gst_buffer_unref (scope->inbuf);
|
|
|
|
scope->inbuf = NULL;
|
|
|
|
}
|
2011-05-27 20:25:00 +00:00
|
|
|
if (scope->pixelbuf) {
|
|
|
|
g_free (scope->pixelbuf);
|
|
|
|
scope->pixelbuf = NULL;
|
|
|
|
}
|
2011-08-12 19:18:44 +00:00
|
|
|
if (scope->config_lock) {
|
|
|
|
g_mutex_free (scope->config_lock);
|
|
|
|
scope->config_lock = NULL;
|
|
|
|
}
|
2011-05-27 08:14:19 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
static void
|
|
|
|
gst_base_audio_visualizer_reset (GstBaseAudioVisualizer * scope)
|
|
|
|
{
|
|
|
|
gst_adapter_clear (scope->adapter);
|
|
|
|
gst_segment_init (&scope->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (scope);
|
|
|
|
scope->proportion = 1.0;
|
|
|
|
scope->earliest_time = -1;
|
|
|
|
GST_OBJECT_UNLOCK (scope);
|
|
|
|
}
|
|
|
|
|
2011-05-27 08:14:19 +00:00
|
|
|
static gboolean
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_base_audio_visualizer_sink_setcaps (GstBaseAudioVisualizer * scope,
|
|
|
|
GstCaps * caps)
|
2011-05-27 08:14:19 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
gint channels;
|
|
|
|
gint rate;
|
|
|
|
gboolean res = TRUE;
|
|
|
|
|
|
|
|
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:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
static gboolean
|
|
|
|
gst_base_audio_visualizer_src_setcaps (GstBaseAudioVisualizer * scope,
|
|
|
|
GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstBaseAudioVisualizerClass *klass;
|
|
|
|
GstStructure *structure;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
if (!gst_structure_get_int (structure, "width", &scope->width) ||
|
|
|
|
!gst_structure_get_int (structure, "height", &scope->height) ||
|
|
|
|
!gst_structure_get_fraction (structure, "framerate", &scope->fps_n,
|
|
|
|
&scope->fps_d))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
klass = GST_BASE_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope));
|
|
|
|
|
|
|
|
//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);
|
|
|
|
scope->req_spf = scope->spf;
|
|
|
|
|
|
|
|
scope->bpf = scope->width * scope->height * 4;
|
|
|
|
|
|
|
|
if (scope->pixelbuf)
|
|
|
|
g_free (scope->pixelbuf);
|
|
|
|
scope->pixelbuf = g_malloc0 (scope->bpf);
|
|
|
|
|
|
|
|
if (klass->setup)
|
|
|
|
res = klass->setup (scope);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (scope, "video: dimension %dx%d, framerate %d/%d",
|
|
|
|
scope->width, scope->height, scope->fps_n, scope->fps_d);
|
|
|
|
GST_DEBUG_OBJECT (scope, "blocks: spf %u, req_spf %u",
|
|
|
|
scope->spf, scope->req_spf);
|
|
|
|
|
|
|
|
res = gst_pad_push_event (scope->srcpad, gst_event_new_caps (caps));
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (scope, "error parsing caps");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 08:14:19 +00:00
|
|
|
static gboolean
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_src_negotiate (GstBaseAudioVisualizer * scope)
|
2011-05-27 08:14:19 +00:00
|
|
|
{
|
2011-11-09 19:09:01 +00:00
|
|
|
GstCaps *othercaps, *target;
|
2011-05-27 08:14:19 +00:00
|
|
|
GstStructure *structure;
|
2011-11-09 19:09:01 +00:00
|
|
|
GstCaps *templ;
|
|
|
|
GstQuery *query;
|
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
guint size, min, max, prefix, alignment;
|
2011-05-27 08:14:19 +00:00
|
|
|
|
|
|
|
templ = gst_pad_get_pad_template_caps (scope->srcpad);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (scope, "performing negotiation");
|
|
|
|
|
|
|
|
/* see what the peer can do */
|
2011-11-15 16:24:07 +00:00
|
|
|
othercaps = gst_pad_peer_query_caps (scope->srcpad, NULL);
|
2011-05-27 08:14:19 +00:00
|
|
|
if (othercaps) {
|
2011-11-09 19:09:01 +00:00
|
|
|
target = gst_caps_intersect (othercaps, templ);
|
2011-05-27 08:14:19 +00:00
|
|
|
gst_caps_unref (othercaps);
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_caps_unref (templ);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
if (gst_caps_is_empty (target))
|
2011-05-27 08:14:19 +00:00
|
|
|
goto no_format;
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_caps_truncate (target);
|
2011-05-27 08:14:19 +00:00
|
|
|
} 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);
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_base_audio_visualizer_src_setcaps (scope, target);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
/* try to get a bufferpool now */
|
|
|
|
/* find a pool for the negotiated caps now */
|
|
|
|
query = gst_query_new_allocation (target, TRUE);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
if (gst_pad_peer_query (scope->srcpad, query)) {
|
|
|
|
/* we got configuration from our peer, parse them */
|
|
|
|
gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
|
|
|
|
&alignment, &pool);
|
|
|
|
} else {
|
|
|
|
size = scope->bpf;
|
|
|
|
min = max = 0;
|
|
|
|
prefix = 0;
|
|
|
|
alignment = 0;
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
if (pool == NULL) {
|
|
|
|
GstStructure *config;
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
/* we did not get a pool, make one ourselves then */
|
|
|
|
pool = gst_buffer_pool_new ();
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set (config, target, size, min, max, prefix,
|
|
|
|
alignment);
|
|
|
|
gst_buffer_pool_set_config (pool, config);
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
if (scope->pool)
|
|
|
|
gst_object_unref (scope->pool);
|
|
|
|
scope->pool = pool;
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
/* and activate */
|
|
|
|
gst_buffer_pool_set_active (pool, TRUE);
|
2011-05-27 20:25:00 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_caps_unref (target);
|
2011-05-27 20:25:00 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
return TRUE;
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
no_format:
|
|
|
|
{
|
|
|
|
gst_caps_unref (target);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2011-08-12 19:18:44 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
/* make sure we are negotiated */
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_base_audio_visualizer_ensure_negotiated (GstBaseAudioVisualizer * scope)
|
|
|
|
{
|
|
|
|
gboolean reconfigure;
|
2011-08-12 19:18:44 +00:00
|
|
|
|
2011-11-16 11:40:58 +00:00
|
|
|
reconfigure = gst_pad_check_reconfigure (scope->srcpad);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
/* we don't know an output format yet, pick one */
|
|
|
|
if (reconfigure || !gst_pad_has_current_caps (scope->srcpad)) {
|
|
|
|
if (!gst_base_audio_visualizer_src_negotiate (scope))
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
2011-11-09 19:09:01 +00:00
|
|
|
return GST_FLOW_OK;
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer)
|
2011-05-27 08:14:19 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2011-06-04 11:33:29 +00:00
|
|
|
GstBaseAudioVisualizer *scope;
|
|
|
|
GstBaseAudioVisualizerClass *klass;
|
2011-05-27 08:14:19 +00:00
|
|
|
GstBuffer *inbuf;
|
2011-11-09 19:09:01 +00:00
|
|
|
guint64 dist, ts;
|
2011-05-27 20:12:00 +00:00
|
|
|
guint avail, sbpf;
|
2011-11-09 19:09:01 +00:00
|
|
|
gpointer adata, vdata;
|
2011-06-04 11:33:29 +00:00
|
|
|
gboolean (*render) (GstBaseAudioVisualizer * scope, GstBuffer * audio,
|
2011-05-27 08:14:19 +00:00
|
|
|
GstBuffer * video);
|
|
|
|
|
2011-11-17 14:53:42 +00:00
|
|
|
scope = GST_BASE_AUDIO_VISUALIZER (parent);
|
2011-06-04 11:33:29 +00:00
|
|
|
klass = GST_BASE_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope));
|
2011-05-27 08:14:19 +00:00
|
|
|
|
|
|
|
render = klass->render;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (scope, "chainfunc called");
|
|
|
|
|
|
|
|
/* resync on DISCONT */
|
|
|
|
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) {
|
|
|
|
gst_adapter_clear (scope->adapter);
|
|
|
|
}
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
if (scope->bps == 0) {
|
|
|
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
/* Make sure have an output format */
|
|
|
|
ret = gst_base_audio_visualizer_ensure_negotiated (scope);
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
goto beach;
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_adapter_push (scope->adapter, buffer);
|
|
|
|
|
2011-08-12 19:18:44 +00:00
|
|
|
g_mutex_lock (scope->config_lock);
|
|
|
|
|
2011-05-27 08:14:19 +00:00
|
|
|
/* this is what we want */
|
2011-05-27 20:12:00 +00:00
|
|
|
sbpf = scope->req_spf * scope->channels * sizeof (gint16);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
|
|
|
inbuf = scope->inbuf;
|
|
|
|
/* FIXME: the timestamp in the adapter would be different */
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_buffer_copy_into (inbuf, buffer, GST_BUFFER_COPY_METADATA, 0, -1);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
|
|
|
/* this is what we have */
|
|
|
|
avail = gst_adapter_available (scope->adapter);
|
2011-06-06 12:20:30 +00:00
|
|
|
GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf);
|
|
|
|
while (avail >= sbpf) {
|
2011-05-27 08:14:19 +00:00
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
/* get timestamp of the current adapter content */
|
|
|
|
ts = gst_adapter_prev_timestamp (scope->adapter, &dist);
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (ts)) {
|
|
|
|
/* convert bytes to time */
|
|
|
|
dist /= scope->bps;
|
|
|
|
ts += gst_util_uint64_scale_int (dist, GST_SECOND, scope->rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (ts)) {
|
|
|
|
gint64 qostime;
|
|
|
|
gboolean need_skip;
|
|
|
|
|
|
|
|
qostime =
|
|
|
|
gst_segment_to_running_time (&scope->segment, GST_FORMAT_TIME, ts) +
|
|
|
|
scope->frame_duration;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (scope);
|
|
|
|
/* check for QoS, don't compute buffers that are known to be late */
|
|
|
|
need_skip = scope->earliest_time != -1 && qostime <= scope->earliest_time;
|
|
|
|
GST_OBJECT_UNLOCK (scope);
|
|
|
|
|
|
|
|
if (need_skip) {
|
|
|
|
GST_WARNING_OBJECT (scope,
|
|
|
|
"QoS: skip ts: %" GST_TIME_FORMAT ", earliest: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (qostime), GST_TIME_ARGS (scope->earliest_time));
|
|
|
|
goto skip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 19:18:44 +00:00
|
|
|
g_mutex_unlock (scope->config_lock);
|
2011-11-09 19:09:01 +00:00
|
|
|
ret = gst_buffer_pool_acquire_buffer (scope->pool, &outbuf, NULL);
|
2011-08-12 19:18:44 +00:00
|
|
|
g_mutex_lock (scope->config_lock);
|
|
|
|
/* recheck as the value could have changed */
|
|
|
|
sbpf = scope->req_spf * scope->channels * sizeof (gint16);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
|
|
|
/* no buffer allocated, we don't care why. */
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
break;
|
|
|
|
|
2011-05-27 20:25:00 +00:00
|
|
|
/* sync controlled properties */
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_object_sync_values (GST_OBJECT (scope), ts);
|
2011-05-27 20:25:00 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = ts;
|
2011-05-27 08:14:19 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) = scope->frame_duration;
|
2011-11-09 19:09:01 +00:00
|
|
|
|
|
|
|
vdata = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE);
|
2011-05-27 20:25:00 +00:00
|
|
|
if (scope->shader) {
|
2011-11-09 19:09:01 +00:00
|
|
|
memcpy (vdata, scope->pixelbuf, scope->bpf);
|
2011-05-27 20:25:00 +00:00
|
|
|
} else {
|
2011-11-09 19:09:01 +00:00
|
|
|
memset (vdata, 0, scope->bpf);
|
2011-05-27 20:25:00 +00:00
|
|
|
}
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-08-12 19:18:44 +00:00
|
|
|
/* this can fail as the data size we need could have changed */
|
2011-11-09 19:09:01 +00:00
|
|
|
if (!(adata = (gpointer) gst_adapter_map (scope->adapter, sbpf)))
|
2011-08-12 19:18:44 +00:00
|
|
|
break;
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_buffer_take_memory (inbuf, -1,
|
|
|
|
gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, adata, NULL, sbpf, 0,
|
|
|
|
sbpf));
|
2011-05-27 08:14:19 +00:00
|
|
|
|
|
|
|
/* call class->render() vmethod */
|
2011-05-27 20:25:00 +00:00
|
|
|
if (render) {
|
2011-05-27 08:14:19 +00:00
|
|
|
if (!render (scope, inbuf, outbuf)) {
|
|
|
|
ret = GST_FLOW_ERROR;
|
2011-05-27 20:25:00 +00:00
|
|
|
} else {
|
|
|
|
/* run various post processing (shading and geometri transformation */
|
|
|
|
if (scope->shader) {
|
2011-11-09 19:09:01 +00:00
|
|
|
scope->shader (scope, vdata, scope->pixelbuf);
|
2011-05-27 20:25:00 +00:00
|
|
|
}
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|
2011-05-27 20:25:00 +00:00
|
|
|
}
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_buffer_unmap (outbuf, vdata, scope->bpf);
|
|
|
|
|
2011-08-12 19:18:44 +00:00
|
|
|
g_mutex_unlock (scope->config_lock);
|
2011-05-27 08:14:19 +00:00
|
|
|
ret = gst_pad_push (scope->srcpad, outbuf);
|
|
|
|
outbuf = NULL;
|
2011-08-12 19:18:44 +00:00
|
|
|
g_mutex_lock (scope->config_lock);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
skip:
|
2011-08-12 19:18:44 +00:00
|
|
|
/* recheck as the value could have changed */
|
|
|
|
sbpf = scope->req_spf * scope->channels * sizeof (gint16);
|
2011-05-27 20:12:00 +00:00
|
|
|
GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf);
|
|
|
|
/* we want to take less or more, depending on spf : req_spf */
|
2011-06-06 12:20:30 +00:00
|
|
|
if (avail - sbpf >= sbpf) {
|
2011-05-27 20:12:00 +00:00
|
|
|
gst_adapter_flush (scope->adapter, sbpf);
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_adapter_unmap (scope->adapter);
|
2011-06-06 12:20:30 +00:00
|
|
|
} else if (avail - sbpf >= 0) {
|
|
|
|
/* just flush a bit and stop */
|
2011-05-27 20:12:00 +00:00
|
|
|
gst_adapter_flush (scope->adapter, (avail - sbpf));
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_adapter_unmap (scope->adapter);
|
2011-06-06 12:20:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-05-27 20:12:00 +00:00
|
|
|
avail = gst_adapter_available (scope->adapter);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-12 19:18:44 +00:00
|
|
|
g_mutex_unlock (scope->config_lock);
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
beach:
|
2011-05-27 08:14:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
static gboolean
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_base_audio_visualizer_src_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2011-11-09 19:09:01 +00:00
|
|
|
{
|
|
|
|
gboolean res;
|
|
|
|
GstBaseAudioVisualizer *scope;
|
|
|
|
|
2011-11-17 14:53:42 +00:00
|
|
|
scope = GST_BASE_AUDIO_VISUALIZER (parent);
|
2011-11-09 19:09:01 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_QOS:
|
|
|
|
{
|
|
|
|
gdouble proportion;
|
|
|
|
GstClockTimeDiff diff;
|
|
|
|
GstClockTime timestamp;
|
|
|
|
|
|
|
|
gst_event_parse_qos (event, NULL, &proportion, &diff, ×tamp);
|
|
|
|
|
|
|
|
/* save stuff for the _chain() function */
|
|
|
|
GST_OBJECT_LOCK (scope);
|
|
|
|
scope->proportion = proportion;
|
|
|
|
if (diff >= 0)
|
|
|
|
/* we're late, this is a good estimate for next displayable
|
|
|
|
* frame (see part-qos.txt) */
|
|
|
|
scope->earliest_time = timestamp + 2 * diff + scope->frame_duration;
|
|
|
|
else
|
|
|
|
scope->earliest_time = timestamp + diff;
|
|
|
|
GST_OBJECT_UNLOCK (scope);
|
|
|
|
|
|
|
|
res = gst_pad_push_event (scope->sinkpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = gst_pad_push_event (scope->sinkpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-17 14:53:42 +00:00
|
|
|
gst_base_audio_visualizer_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2011-11-09 19:09:01 +00:00
|
|
|
{
|
|
|
|
gboolean res;
|
|
|
|
GstBaseAudioVisualizer *scope;
|
|
|
|
|
2011-11-17 14:53:42 +00:00
|
|
|
scope = GST_BASE_AUDIO_VISUALIZER (parent);
|
2011-11-09 19:09:01 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
res = gst_base_audio_visualizer_sink_setcaps (scope, caps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
res = gst_pad_push_event (scope->srcpad, event);
|
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
gst_base_audio_visualizer_reset (scope);
|
|
|
|
res = gst_pad_push_event (scope->srcpad, event);
|
|
|
|
break;
|
|
|
|
case GST_EVENT_SEGMENT:
|
|
|
|
{
|
|
|
|
/* the newsegment values are used to clip the input samples
|
|
|
|
* and to convert the incomming timestamps to running time so
|
|
|
|
* we can do QoS */
|
|
|
|
gst_event_copy_segment (event, &scope->segment);
|
|
|
|
|
|
|
|
res = gst_pad_push_event (scope->srcpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = gst_pad_push_event (scope->srcpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-16 16:28:10 +00:00
|
|
|
gst_base_audio_visualizer_src_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query)
|
2011-11-09 19:09:01 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
GstBaseAudioVisualizer *scope;
|
|
|
|
|
2011-11-16 16:28:10 +00:00
|
|
|
scope = GST_BASE_AUDIO_VISUALIZER (parent);
|
2011-11-09 19:09:01 +00:00
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
{
|
|
|
|
/* We need to send the query upstream and add the returned latency to our
|
|
|
|
* own */
|
|
|
|
GstClockTime min_latency, max_latency;
|
|
|
|
gboolean us_live;
|
|
|
|
GstClockTime our_latency;
|
|
|
|
guint max_samples;
|
|
|
|
|
|
|
|
if (scope->rate == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((res = gst_pad_peer_query (scope->sinkpad, query))) {
|
|
|
|
gst_query_parse_latency (query, &us_live, &min_latency, &max_latency);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (scope, "Peer latency: min %"
|
|
|
|
GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
|
|
|
|
|
|
|
|
/* the max samples we must buffer buffer */
|
|
|
|
max_samples = MAX (scope->req_spf, scope->spf);
|
|
|
|
our_latency =
|
|
|
|
gst_util_uint64_scale_int (max_samples, GST_SECOND, scope->rate);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (scope, "Our latency: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (our_latency));
|
|
|
|
|
|
|
|
/* we add some latency but only if we need to buffer more than what
|
|
|
|
* upstream gives us */
|
|
|
|
min_latency += our_latency;
|
|
|
|
if (max_latency != -1)
|
|
|
|
max_latency += our_latency;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (scope, "Calculated total latency : min %"
|
|
|
|
GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
|
|
|
|
|
|
|
|
gst_query_set_latency (query, TRUE, min_latency, max_latency);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2011-11-16 16:28:10 +00:00
|
|
|
res = gst_pad_query_default (pad, parent, query);
|
2011-11-09 19:09:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-16 16:28:10 +00:00
|
|
|
gst_base_audio_visualizer_sink_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query)
|
2011-11-09 19:09:01 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
default:
|
2011-11-16 16:28:10 +00:00
|
|
|
res = gst_pad_query_default (pad, parent, query);
|
2011-11-09 19:09:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-05-27 08:14:19 +00:00
|
|
|
static GstStateChangeReturn
|
2011-06-04 11:33:29 +00:00
|
|
|
gst_base_audio_visualizer_change_state (GstElement * element,
|
|
|
|
GstStateChange transition)
|
2011-05-27 08:14:19 +00:00
|
|
|
{
|
2011-11-09 19:09:01 +00:00
|
|
|
GstStateChangeReturn ret;
|
2011-06-04 11:33:29 +00:00
|
|
|
GstBaseAudioVisualizer *scope;
|
2011-05-27 08:14:19 +00:00
|
|
|
|
2011-06-04 11:33:29 +00:00
|
|
|
scope = GST_BASE_AUDIO_VISUALIZER (element);
|
2011-05-27 08:14:19 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2011-11-09 19:09:01 +00:00
|
|
|
gst_base_audio_visualizer_reset (scope);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
if (scope->pool) {
|
|
|
|
gst_buffer_pool_set_active (scope->pool, FALSE);
|
|
|
|
gst_object_replace ((GstObject **) & scope->pool, NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2011-05-27 08:14:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-09 19:09:01 +00:00
|
|
|
return ret;
|
2011-05-27 08:14:19 +00:00
|
|
|
}
|