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 */
|
2006-04-25 21:56:38 +00:00
|
|
|
static const GstElementDetails passthrough_details =
|
2006-04-06 11:35:26 +00:00
|
|
|
GST_ELEMENT_DETAILS ("Passthrough",
|
|
|
|
"Filter/Effect/Audio",
|
|
|
|
"Transparent filter for audio/raw (boilerplate for effects)",
|
|
|
|
"Thomas <thomas@apestaart.org>, " "Andy Wingo <apwingo@eos.ncsu.edu>");
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2002-01-22 04:43:10 +00:00
|
|
|
/* static guint gst_filter_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_SILENT
|
|
|
|
};
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate passthrough_sink_template =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS)
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2003-12-22 01:47:09 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate passthrough_src_template =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS)
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void passthrough_class_init (GstPassthroughClass * klass);
|
|
|
|
static void passthrough_base_init (GstPassthroughClass * klass);
|
|
|
|
static void passthrough_init (GstPassthrough * filter);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void passthrough_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void passthrough_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstPadLinkReturn passthrough_connect_sink (GstPad * pad,
|
|
|
|
const GstCaps * caps);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void passthrough_chain (GstPad * pad, GstData * _data);
|
|
|
|
static void inline passthrough_fast_float_chain (gfloat * data,
|
|
|
|
guint numsamples);
|
|
|
|
static void inline passthrough_fast_16bit_chain (gint16 * data,
|
|
|
|
guint numsamples);
|
|
|
|
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
|
2004-03-14 22:34:33 +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;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, GST_PAD_LINK_DELAYED);
|
2003-01-10 10:22:25 +00:00
|
|
|
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);
|
2004-03-14 22:34:33 +00:00
|
|
|
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;
|
|
|
|
|
2004-03-14 22:34:33 +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
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!filter->silent) {
|
|
|
|
g_print ("Passthrough : channels %d, rate %d\n", filter->channels,
|
2004-03-15 19:32:27 +00:00
|
|
|
filter->rate);
|
2004-03-14 22:34:33 +00:00
|
|
|
g_print
|
2004-03-15 19:32:27 +00:00
|
|
|
("Passthrough : format int, bit width %d, endianness %d, signed %s\n",
|
|
|
|
filter->width, filter->endianness, filter->is_signed ? "yes" : "no");
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
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
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!filter->silent) {
|
|
|
|
g_print ("Passthrough : channels %d, rate %d\n", filter->channels,
|
2004-03-15 19:32:27 +00:00
|
|
|
filter->rate);
|
2003-07-19 23:47:42 +00:00
|
|
|
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
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
passthrough_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
passthrough_base_init (GstPassthroughClass * klass)
|
2003-11-02 21:37:09 +00:00
|
|
|
{
|
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
passthrough_class_init (GstPassthroughClass * klass)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2006-04-08 21:48:01 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT, g_param_spec_boolean ("silent", "silent", "silent", 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
|
2004-03-14 22:34:33 +00:00
|
|
|
passthrough_init (GstPassthrough * filter)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
filter->srcpad =
|
2007-06-22 10:46:33 +00:00
|
|
|
gst_pad_new_from_static_template (&passthrough_src_template, "src");
|
2002-01-22 04:43:10 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
2004-03-14 22:34:33 +00:00
|
|
|
filter->sinkpad =
|
2007-06-22 10:46:33 +00:00
|
|
|
gst_pad_new_from_static_template (&passthrough_sink_template, "sink");
|
2002-01-22 04:43:10 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_set_link_function (filter->sinkpad, passthrough_connect_sink);
|
|
|
|
gst_pad_set_chain_function (filter->sinkpad, passthrough_chain);
|
2002-01-22 04:43:10 +00:00
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
filter->silent = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +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;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
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);
|
2004-03-14 22:34: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) {
|
2004-03-14 22:34:33 +00:00
|
|
|
case GST_PASSTHROUGH_FORMAT_INT:
|
|
|
|
int_data = (gint16 *) GST_BUFFER_DATA (buf);
|
|
|
|
|
|
|
|
switch (filter->width) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case 16:
|
|
|
|
passthrough_fast_16bit_chain (int_data, GST_BUFFER_SIZE (buf) / 2);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
passthrough_fast_8bit_chain ((gint8 *) int_data,
|
|
|
|
GST_BUFFER_SIZE (buf));
|
|
|
|
break;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
break;
|
2004-03-14 22:34:33 +00:00
|
|
|
case GST_PASSTHROUGH_FORMAT_FLOAT:
|
|
|
|
float_data = (gfloat *) GST_BUFFER_DATA (buf);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
passthrough_fast_float_chain (float_data,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_SIZE (buf) / sizeof (gfloat));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
break;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
passthrough_fast_float_chain (gfloat * data, guint num_samples)
|
2001-12-22 23:26:33 +00:00
|
|
|
#include "filter.func"
|
2004-03-14 22:34:33 +00:00
|
|
|
static void inline
|
2004-03-15 19:32:27 +00:00
|
|
|
passthrough_fast_16bit_chain (gint16 * data, guint num_samples)
|
2001-12-22 23:26:33 +00:00
|
|
|
#include "filter.func"
|
2004-03-14 22:34:33 +00:00
|
|
|
static void inline
|
2004-03-15 19:32:27 +00:00
|
|
|
passthrough_fast_8bit_chain (gint8 * data, guint num_samples)
|
2001-12-22 23:26:33 +00:00
|
|
|
#include "filter.func"
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
2004-03-15 19:32:27 +00:00
|
|
|
passthrough_set_property (GObject * object, guint prop_id,
|
2004-03-14 22:34:33 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (prop_id) {
|
2001-12-22 23:26:33 +00:00
|
|
|
case ARG_SILENT:
|
|
|
|
filter->silent = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
passthrough_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-22 23:26:33 +00:00
|
|
|
{
|
|
|
|
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
|
2004-03-14 22:34:33 +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",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_RANK_NONE, GST_TYPE_PASSTHROUGH);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"passthrough",
|
|
|
|
"Transparent filter for audio/raw (boilerplate for effects)",
|
2006-04-01 10:09:11 +00:00
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|