2001-12-22 23:26:33 +00:00
|
|
|
/* -*- c-basic-offset: 2 -*-
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 1999-2001 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:26:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <gst/gst.h>
|
2001-12-23 12:18:18 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2001-12-22 23:26:33 +00:00
|
|
|
#include "gstpassthrough.h"
|
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
#define PASSTHRU_BUF_SIZE 4096
|
|
|
|
#define PASSTHRU_NUM_BUFS 4
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2001-12-22 23:26:33 +00:00
|
|
|
static GstElementDetails passthrough_details = {
|
|
|
|
"Passthrough",
|
2003-11-16 22:02:23 +00:00
|
|
|
"Filter/Effect/Audio",
|
2001-12-22 23:26:33 +00:00
|
|
|
"Transparent filter for audio/raw (boilerplate for effects)",
|
|
|
|
"Thomas <thomas@apestaart.org>, "\
|
2003-11-02 21:37:09 +00:00
|
|
|
"Andy Wingo <apwingo@eos.ncsu.edu>"
|
2001-12-22 23:26:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
/* static guint gst_filter_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_SILENT
|
|
|
|
};
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate passthrough_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE (
|
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (
|
|
|
|
GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
|
|
|
|
GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate passthrough_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE (
|
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (
|
|
|
|
GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
|
|
|
|
GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS
|
|
|
|
)
|
|
|
|
);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
static void passthrough_class_init (GstPassthroughClass *klass);
|
2003-11-02 21:37:09 +00:00
|
|
|
static void passthrough_base_init (GstPassthroughClass *klass);
|
2001-12-22 23:26:33 +00:00
|
|
|
static void passthrough_init (GstPassthrough *filter);
|
|
|
|
|
|
|
|
static void passthrough_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
|
2002-01-22 04:43:10 +00:00
|
|
|
static void passthrough_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstPadLinkReturn passthrough_connect_sink (GstPad *pad, const GstCaps *caps);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-10-08 16:08:19 +00:00
|
|
|
static void passthrough_chain (GstPad *pad, GstData *_data);
|
2001-12-22 23:26:33 +00:00
|
|
|
static void inline passthrough_fast_float_chain (gfloat* data, guint numsamples);
|
|
|
|
static void inline passthrough_fast_16bit_chain (gint16* data, guint numsamples);
|
2002-01-22 04:43:10 +00:00
|
|
|
static void inline passthrough_fast_8bit_chain (gint8* data, guint numsamples);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2003-12-22 01:47:09 +00:00
|
|
|
passthrough_connect_sink (GstPad *pad, const GstCaps *caps)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2003-07-06 20:49:52 +00:00
|
|
|
const gchar *mimetype;
|
2002-01-22 04:43:10 +00:00
|
|
|
GstPassthrough *filter;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
g_return_val_if_fail (pad != NULL, GST_PAD_LINK_DELAYED);
|
|
|
|
g_return_val_if_fail (caps != NULL, GST_PAD_LINK_DELAYED);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
filter = GST_PASSTHROUGH (gst_pad_get_parent (pad));
|
2003-01-10 10:22:25 +00:00
|
|
|
g_return_val_if_fail (filter != NULL, GST_PAD_LINK_REFUSED);
|
|
|
|
g_return_val_if_fail (GST_IS_PASSTHROUGH (filter), GST_PAD_LINK_REFUSED);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2003-07-19 23:47:42 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
mimetype = gst_structure_get_name (structure);
|
|
|
|
gst_structure_get_int (structure, "rate", &filter->rate);
|
|
|
|
gst_structure_get_int (structure, "channels", &filter->channels);
|
|
|
|
gst_structure_get_int (structure, "width", &filter->width);
|
|
|
|
gst_structure_get_int (structure, "endianness", &filter->endianness);
|
2003-07-19 23:47:42 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
if (strcmp (mimetype, "audio/x-raw-int") == 0) {
|
2003-07-19 23:47:42 +00:00
|
|
|
filter->format = GST_PASSTHROUGH_FORMAT_INT;
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_get_int (structure, "depth", &filter->depth);
|
|
|
|
gst_structure_get_boolean (structure, "signed", &filter->is_signed);
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
if (! filter->silent) {
|
2003-07-19 23:47:42 +00:00
|
|
|
g_print ("Passthrough : channels %d, rate %d\n", filter->channels, filter->rate);
|
2001-12-22 23:26:33 +00:00
|
|
|
g_print ("Passthrough : format int, bit width %d, endianness %d, signed %s\n",
|
|
|
|
filter->width, filter->endianness, filter->is_signed ? "yes" : "no");
|
|
|
|
}
|
2003-07-06 20:49:52 +00:00
|
|
|
} else if (strcmp (mimetype, "audio/x-raw-float") == 0) {
|
2003-07-19 23:47:42 +00:00
|
|
|
filter->format = GST_PASSTHROUGH_FORMAT_FLOAT;
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
if (! filter->silent) {
|
2003-07-19 23:47:42 +00:00
|
|
|
g_print ("Passthrough : channels %d, rate %d\n", filter->channels, filter->rate);
|
|
|
|
g_print ("Passthrough : format float, width %d\n", filter->width);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
return gst_pad_try_set_caps (filter->srcpad, caps);
|
2002-01-22 04:43:10 +00:00
|
|
|
}
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
GType
|
2002-01-22 04:43:10 +00:00
|
|
|
gst_passthrough_get_type (void)
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
static GType passthrough_type = 0;
|
|
|
|
|
|
|
|
if (!passthrough_type) {
|
|
|
|
static const GTypeInfo passthrough_info = {
|
2003-11-02 21:37:09 +00:00
|
|
|
sizeof (GstPassthroughClass),
|
|
|
|
(GBaseInitFunc) passthrough_base_init,
|
2001-12-22 23:26:33 +00:00
|
|
|
NULL,
|
2002-01-22 04:43:10 +00:00
|
|
|
(GClassInitFunc) passthrough_class_init,
|
2001-12-22 23:26:33 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-01-22 04:43:10 +00:00
|
|
|
sizeof (GstPassthrough),
|
2001-12-22 23:26:33 +00:00
|
|
|
0,
|
2002-01-22 04:43:10 +00:00
|
|
|
(GInstanceInitFunc) passthrough_init,
|
2001-12-22 23:26:33 +00:00
|
|
|
};
|
2002-01-22 04:43:10 +00:00
|
|
|
passthrough_type = g_type_register_static (GST_TYPE_ELEMENT, "GstPassthrough", &passthrough_info, 0);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
return passthrough_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 21:37:09 +00:00
|
|
|
static void
|
|
|
|
passthrough_base_init (GstPassthroughClass *klass)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&passthrough_src_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&passthrough_sink_template));
|
2003-11-02 21:37:09 +00:00
|
|
|
gst_element_class_set_details (element_class, &passthrough_details);
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
static void
|
|
|
|
passthrough_class_init (GstPassthroughClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
gstelement_class = (GstElementClass*) klass;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SILENT,
|
|
|
|
g_param_spec_boolean("silent","silent","silent",
|
2002-01-22 04:43:10 +00:00
|
|
|
TRUE, G_PARAM_READWRITE)); /* CHECKME */
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = passthrough_set_property;
|
|
|
|
gobject_class->get_property = passthrough_get_property;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
passthrough_init (GstPassthrough *filter)
|
|
|
|
{
|
2003-12-22 01:47:09 +00:00
|
|
|
filter->srcpad = gst_pad_new_from_template (
|
|
|
|
gst_static_pad_template_get (&passthrough_src_template), "src");
|
2002-01-22 04:43:10 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
2003-12-22 01:47:09 +00:00
|
|
|
filter->sinkpad = gst_pad_new_from_template (
|
|
|
|
gst_static_pad_template_get (&passthrough_sink_template), "sink");
|
2002-01-22 04:43:10 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
gst_pad_set_link_function (filter->sinkpad, passthrough_connect_sink);
|
2002-01-22 04:43:10 +00:00
|
|
|
gst_pad_set_chain_function (filter->sinkpad, passthrough_chain);
|
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
filter->silent = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-08 16:08:19 +00:00
|
|
|
passthrough_chain (GstPad *pad, GstData *_data)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2003-10-08 16:08:19 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-22 23:26:33 +00:00
|
|
|
GstPassthrough *filter;
|
|
|
|
gint16 *int_data;
|
|
|
|
gfloat *float_data;
|
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
filter = GST_PASSTHROUGH (gst_pad_get_parent (pad));
|
|
|
|
g_return_if_fail (filter != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PASSTHROUGH (filter));
|
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
switch (filter->format) {
|
|
|
|
case GST_PASSTHROUGH_FORMAT_INT:
|
2002-01-22 04:43:10 +00:00
|
|
|
int_data = (gint16 *) GST_BUFFER_DATA (buf);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
switch (filter->width) {
|
|
|
|
case 16:
|
2002-01-22 04:43:10 +00:00
|
|
|
passthrough_fast_16bit_chain (int_data, GST_BUFFER_SIZE (buf) / 2);
|
2001-12-22 23:26:33 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
2002-01-22 04:43:10 +00:00
|
|
|
passthrough_fast_8bit_chain ((gint8*) int_data, GST_BUFFER_SIZE (buf));
|
2001-12-22 23:26:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case GST_PASSTHROUGH_FORMAT_FLOAT:
|
2002-01-22 04:43:10 +00:00
|
|
|
float_data = (gfloat *) GST_BUFFER_DATA (buf);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
passthrough_fast_float_chain (float_data, GST_BUFFER_SIZE (buf) / sizeof (gfloat));
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-10-08 16:08:19 +00:00
|
|
|
gst_pad_push (filter->srcpad, GST_DATA (buf));
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void inline
|
2002-01-22 04:43:10 +00:00
|
|
|
passthrough_fast_float_chain(gfloat* data, guint num_samples)
|
2001-12-22 23:26:33 +00:00
|
|
|
#include "filter.func"
|
|
|
|
|
|
|
|
static void inline
|
2002-01-22 04:43:10 +00:00
|
|
|
passthrough_fast_16bit_chain(gint16* data, guint num_samples)
|
2001-12-22 23:26:33 +00:00
|
|
|
#include "filter.func"
|
|
|
|
|
|
|
|
static void inline
|
2002-01-22 04:43:10 +00:00
|
|
|
passthrough_fast_8bit_chain(gint8* data, guint num_samples)
|
2001-12-22 23:26:33 +00:00
|
|
|
#include "filter.func"
|
|
|
|
|
|
|
|
static void
|
|
|
|
passthrough_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstPassthrough *filter;
|
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
g_return_if_fail (GST_IS_PASSTHROUGH (object));
|
|
|
|
filter = GST_PASSTHROUGH (object);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case ARG_SILENT:
|
|
|
|
filter->silent = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
passthrough_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstPassthrough *filter;
|
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
g_return_if_fail (GST_IS_PASSTHROUGH (object));
|
|
|
|
filter = GST_PASSTHROUGH (object);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_SILENT:
|
|
|
|
g_value_set_boolean (value, filter->silent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-11-02 21:37:09 +00:00
|
|
|
plugin_init (GstPlugin *plugin)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2003-11-02 21:37:09 +00:00
|
|
|
return gst_element_register (plugin, "passthrough",
|
|
|
|
GST_RANK_NONE, GST_TYPE_PASSTHROUGH);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 21:37:09 +00:00
|
|
|
GST_PLUGIN_DEFINE (
|
2001-12-22 23:26:33 +00:00
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"passthrough",
|
2003-11-02 21:37:09 +00:00
|
|
|
"Transparent filter for audio/raw (boilerplate for effects)",
|
|
|
|
plugin_init,
|
|
|
|
VERSION,
|
|
|
|
"LGPL",
|
|
|
|
GST_PACKAGE,
|
|
|
|
GST_ORIGIN
|
|
|
|
)
|