2002-05-04 18:57:44 +00:00
|
|
|
/* -*- Mode: C; c-basic-offset: 4 -*- */
|
2002-03-18 04:41:35 +00:00
|
|
|
/*
|
2003-09-30 12:56:27 +00:00
|
|
|
Copyright (C) 2002, 2003 Andy Wingo <wingo@pobox.com>
|
2002-03-18 04:41:35 +00:00
|
|
|
|
|
|
|
This library 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 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
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2002-03-18 04:41:35 +00:00
|
|
|
#include <stdlib.h>
|
2002-05-05 19:39:17 +00:00
|
|
|
#include <string.h>
|
2002-03-18 04:41:35 +00:00
|
|
|
#include "gstjack.h"
|
|
|
|
#include <gst/audio/audio.h>
|
|
|
|
|
|
|
|
/* TODO:
|
2003-07-19 23:25:25 +00:00
|
|
|
|
2002-03-18 04:41:35 +00:00
|
|
|
- work out the src side (caps setting, etc)
|
|
|
|
|
|
|
|
future core TODO:
|
|
|
|
- make a jack clock provider
|
|
|
|
- add GST_ELEMENT_FIXED_DATA_RATE, GST_ELEMENT_QOS,
|
|
|
|
GST_ELEMENT_CHANGES_DATA_RATE element flags, and make the scheduler
|
|
|
|
sensitive to them
|
|
|
|
*/
|
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2003-07-19 23:25:25 +00:00
|
|
|
static GstElementDetails gst_jack_bin_details = {
|
2004-03-14 22:34:33 +00:00
|
|
|
"Jack Bin",
|
|
|
|
"Generic/Bin",
|
|
|
|
"Jack processing bin",
|
|
|
|
"Andy Wingo <wingo@pobox.com>",
|
2002-04-16 17:14:05 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails gst_jack_sink_details = {
|
|
|
|
"Jack Sink",
|
|
|
|
"Sink/Audio",
|
|
|
|
"Output to a Jack processing network",
|
|
|
|
"Andy Wingo <wingo@pobox.com>",
|
2002-03-18 04:41:35 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails gst_jack_src_details = {
|
|
|
|
"Jack Src",
|
|
|
|
"Source/Audio",
|
|
|
|
"Input from a Jack processing network",
|
|
|
|
"Andy Wingo <wingo@pobox.com>",
|
2002-03-18 04:41:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-07-02 23:35:07 +00:00
|
|
|
static GHashTable *port_name_counts = NULL;
|
2002-04-16 17:14:05 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-03-18 04:41:35 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_jack_base_init (gpointer g_class);
|
|
|
|
static void gst_jack_src_base_init (gpointer g_class);
|
|
|
|
static void gst_jack_sink_base_init (gpointer g_class);
|
|
|
|
static void gst_jack_init (GstJack * this);
|
|
|
|
static void gst_jack_class_init (GstJackClass * klass);
|
|
|
|
static void gst_jack_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_jack_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
static GstPadTemplate *gst_jack_src_request_pad_factory ();
|
|
|
|
static GstPadTemplate *gst_jack_sink_request_pad_factory ();
|
|
|
|
static GstPad *gst_jack_request_new_pad (GstElement * element,
|
|
|
|
GstPadTemplate * templ, const gchar * name);
|
|
|
|
static GstElementStateReturn gst_jack_change_state (GstElement * element);
|
|
|
|
static GstPadLinkReturn gst_jack_link (GstPad * pad, const GstCaps * caps);
|
|
|
|
|
|
|
|
static void gst_jack_loop (GstElement * element);
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
2004-05-21 23:28:57 +00:00
|
|
|
ARG_PORT_NAME_PREFIX
|
2002-03-18 04:41:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_get_type (void)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
|
|
|
static GType jack_type = 0;
|
|
|
|
|
|
|
|
if (!jack_type) {
|
|
|
|
static const GTypeInfo jack_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstJackClass),
|
2003-11-01 23:43:13 +00:00
|
|
|
gst_jack_base_init,
|
2002-03-18 04:41:35 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstJack),
|
2002-03-18 04:41:35 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
jack_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstJack", &jack_info, 0);
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
return jack_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_sink_get_type (void)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
2003-11-01 23:43:13 +00:00
|
|
|
static GType jack_type = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-01 23:43:13 +00:00
|
|
|
if (!jack_type) {
|
|
|
|
static const GTypeInfo jack_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstJackClass),
|
2003-11-01 23:43:13 +00:00
|
|
|
gst_jack_sink_base_init,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) gst_jack_class_init,
|
2003-11-01 23:43:13 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstJack),
|
2003-11-01 23:43:13 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_jack_init,
|
2003-11-01 23:43:13 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
jack_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_JACK, "GstJackSink", &jack_info, 0);
|
2003-11-01 23:43:13 +00:00
|
|
|
}
|
|
|
|
return jack_type;
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_src_get_type (void)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
2003-11-01 23:43:13 +00:00
|
|
|
static GType jack_type = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-01 23:43:13 +00:00
|
|
|
if (!jack_type) {
|
|
|
|
static const GTypeInfo jack_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstJackClass),
|
2003-11-01 23:43:13 +00:00
|
|
|
gst_jack_src_base_init,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) gst_jack_class_init,
|
2003-11-01 23:43:13 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstJack),
|
2003-11-01 23:43:13 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_jack_init,
|
2003-11-01 23:43:13 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
jack_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_JACK, "GstJackSrc", &jack_info, 0);
|
2003-11-01 23:43:13 +00:00
|
|
|
}
|
|
|
|
return jack_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_jack_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_jack_bin_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_jack_src_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_jack_src_request_pad_factory ());
|
2003-11-01 23:43:13 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_jack_src_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_jack_sink_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_jack_sink_request_pad_factory ());
|
2003-11-01 23:43:13 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_jack_sink_details);
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_class_init (GstJackClass * klass)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GstElementClass *element_class;
|
|
|
|
GParamSpec *pspec;
|
|
|
|
gchar *prefix;
|
|
|
|
|
|
|
|
object_class = (GObjectClass *) klass;
|
|
|
|
element_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
if (parent_class == NULL)
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
object_class->get_property = gst_jack_get_property;
|
|
|
|
object_class->set_property = gst_jack_set_property;
|
|
|
|
|
|
|
|
if (GST_IS_JACK_SINK_CLASS (klass))
|
|
|
|
prefix = "gst-out-";
|
|
|
|
else
|
|
|
|
prefix = "gst-in-";
|
|
|
|
|
|
|
|
pspec = g_param_spec_string ("port-name-prefix", "Port name prefix",
|
|
|
|
"String to prepend to jack port names",
|
|
|
|
prefix, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
|
|
|
|
g_object_class_install_property (object_class, ARG_PORT_NAME_PREFIX, pspec);
|
|
|
|
|
|
|
|
element_class->change_state = gst_jack_change_state;
|
|
|
|
|
|
|
|
element_class->request_new_pad = gst_jack_request_new_pad;
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_init (GstJack * this)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
if (G_OBJECT_TYPE (this) == GST_TYPE_JACK_SRC)
|
|
|
|
this->direction = GST_PAD_SRC;
|
|
|
|
else if (G_OBJECT_TYPE (this) == GST_TYPE_JACK_SINK)
|
|
|
|
this->direction = GST_PAD_SINK;
|
|
|
|
else
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (this), gst_jack_loop);
|
2003-09-30 12:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2003-09-30 12:56:27 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
GstJack *this = (GstJack *) object;
|
2003-09-30 12:56:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (prop_id) {
|
2003-09-30 12:56:27 +00:00
|
|
|
case ARG_PORT_NAME_PREFIX:
|
2004-03-14 22:34:33 +00:00
|
|
|
if (this->port_name_prefix)
|
2004-03-15 19:32:27 +00:00
|
|
|
g_free (this->port_name_prefix);
|
2004-03-14 22:34:33 +00:00
|
|
|
this->port_name_prefix = g_strdup (g_value_get_string (value));
|
|
|
|
break;
|
2003-09-30 12:56:27 +00:00
|
|
|
default:
|
2004-03-14 22:34:33 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
return;
|
|
|
|
}
|
2003-09-30 12:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2003-09-30 12:56:27 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
GstJack *this = (GstJack *) object;
|
2003-09-30 12:56:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (prop_id) {
|
2003-09-30 12:56:27 +00:00
|
|
|
case ARG_PORT_NAME_PREFIX:
|
2004-03-14 22:34:33 +00:00
|
|
|
g_value_set_string (value, this->port_name_prefix);
|
|
|
|
break;
|
2003-09-30 12:56:27 +00:00
|
|
|
default:
|
2004-03-14 22:34:33 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2003-09-30 12:56:27 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstPadTemplate *
|
2003-09-30 12:56:27 +00:00
|
|
|
gst_jack_src_request_pad_factory (void)
|
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstPadTemplate *template = NULL;
|
|
|
|
|
|
|
|
if (!template) {
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_caps_from_string (GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS);
|
|
|
|
template = gst_pad_template_new ("%s", GST_PAD_SRC, GST_PAD_REQUEST, caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return template;
|
2003-09-30 12:56:27 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstPadTemplate *
|
2003-09-30 12:56:27 +00:00
|
|
|
gst_jack_sink_request_pad_factory (void)
|
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstPadTemplate *template = NULL;
|
|
|
|
|
|
|
|
if (!template) {
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_caps_from_string (GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS);
|
|
|
|
template = gst_pad_template_new ("%s", GST_PAD_SINK, GST_PAD_REQUEST, caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return template;
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstPad *
|
|
|
|
gst_jack_request_new_pad (GstElement * element, GstPadTemplate * templ,
|
|
|
|
const gchar * name)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
GstJack *this;
|
|
|
|
gchar *newname;
|
|
|
|
GList *l, **pad_list;
|
|
|
|
GstJackPad *pad;
|
|
|
|
gint count;
|
|
|
|
|
|
|
|
g_return_val_if_fail ((this = GST_JACK (element)), NULL);
|
|
|
|
|
|
|
|
if (!this->bin)
|
|
|
|
pad_list = &this->pads;
|
|
|
|
else if (this->direction == GST_PAD_SRC)
|
|
|
|
pad_list = &this->bin->src_pads;
|
|
|
|
else
|
|
|
|
pad_list = &this->bin->sink_pads;
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
l = *pad_list;
|
|
|
|
while (l) {
|
|
|
|
if (strcmp (GST_JACK_PAD (l)->name, name) == 0) {
|
2004-03-15 19:32:27 +00:00
|
|
|
g_warning ("requested port name %s already in use.", name);
|
|
|
|
return NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
|
|
|
l = l->next;
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
newname = g_strdup (name);
|
|
|
|
} else {
|
|
|
|
if (this->direction == GST_PAD_SINK)
|
|
|
|
newname = g_strdup ("alsa_pcm:playback_1");
|
|
|
|
else
|
|
|
|
newname = g_strdup ("alsa_pcm:capture_1");
|
|
|
|
}
|
|
|
|
|
|
|
|
pad = g_new0 (GstJackPad, 1);
|
|
|
|
|
|
|
|
if (!port_name_counts)
|
|
|
|
port_name_counts = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
|
|
|
count =
|
|
|
|
GPOINTER_TO_INT (g_hash_table_lookup (port_name_counts,
|
2004-03-15 19:32:27 +00:00
|
|
|
this->port_name_prefix));
|
2004-03-14 22:34:33 +00:00
|
|
|
g_hash_table_insert (port_name_counts, g_strdup (this->port_name_prefix),
|
|
|
|
GINT_TO_POINTER (count + 1));
|
|
|
|
|
|
|
|
pad->name = g_strdup_printf ("%s%d", this->port_name_prefix, count);
|
|
|
|
|
|
|
|
pad->peer_name = newname;
|
|
|
|
pad->pad = gst_pad_new_from_template (templ, newname);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (this), pad->pad);
|
|
|
|
gst_pad_set_link_function (pad->pad, gst_jack_link);
|
|
|
|
|
|
|
|
this->pads = g_list_append (this->pads, pad);
|
|
|
|
|
|
|
|
g_print ("returning from request_new_pad, pad %s created, to connect to %s\n",
|
|
|
|
pad->name, pad->peer_name);
|
|
|
|
return pad->pad;
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_change_state (GstElement * element)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
GstJack *this;
|
|
|
|
GList *l = NULL, **pads;
|
|
|
|
GstJackPad *pad;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
g_return_val_if_fail (element != NULL, FALSE);
|
|
|
|
this = GST_JACK (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_PENDING (element)) {
|
2002-03-18 04:41:35 +00:00
|
|
|
case GST_STATE_NULL:
|
2004-03-14 22:34:33 +00:00
|
|
|
JACK_DEBUG ("%s: NULL", GST_OBJECT_NAME (GST_OBJECT (this)));
|
|
|
|
|
|
|
|
break;
|
2002-05-04 20:53:35 +00:00
|
|
|
|
2002-03-18 04:41:35 +00:00
|
|
|
case GST_STATE_READY:
|
2004-03-14 22:34:33 +00:00
|
|
|
JACK_DEBUG ("%s: READY", GST_OBJECT_NAME (GST_OBJECT (this)));
|
|
|
|
|
|
|
|
if (!this->bin) {
|
2004-03-15 19:32:27 +00:00
|
|
|
if (!(this->bin = (GstJackBin *) gst_element_get_managing_bin (element))
|
|
|
|
|| !GST_IS_JACK_BIN (this->bin)) {
|
|
|
|
this->bin = NULL;
|
|
|
|
g_warning ("jack element %s needs to be contained in a jack bin.",
|
|
|
|
GST_OBJECT_NAME (element));
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fixme: verify that all names are unique */
|
|
|
|
l = this->pads;
|
|
|
|
pads =
|
|
|
|
(this->direction ==
|
|
|
|
GST_PAD_SRC) ? &this->bin->src_pads : &this->bin->sink_pads;
|
|
|
|
while (l) {
|
|
|
|
pad = GST_JACK_PAD (l);
|
|
|
|
JACK_DEBUG ("%s: appending pad %s:%s to list", GST_OBJECT_NAME (this),
|
|
|
|
pad->name, pad->peer_name);
|
|
|
|
*pads = g_list_append (*pads, pad);
|
|
|
|
l = g_list_next (l);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-03-18 04:41:35 +00:00
|
|
|
case GST_STATE_PAUSED:
|
2004-03-14 22:34:33 +00:00
|
|
|
JACK_DEBUG ("%s: PAUSED", GST_OBJECT_NAME (GST_OBJECT (this)));
|
|
|
|
|
|
|
|
if (GST_STATE (element) == GST_STATE_READY) {
|
2004-03-15 19:32:27 +00:00
|
|
|
/* we're in READY->PAUSED */
|
|
|
|
l = this->pads;
|
|
|
|
while (l) {
|
|
|
|
pad = GST_JACK_PAD (l);
|
|
|
|
caps = gst_caps_copy (gst_pad_get_negotiated_caps (pad->pad));
|
|
|
|
gst_caps_set_simple (caps,
|
|
|
|
"rate", G_TYPE_INT, (int) this->bin->rate,
|
|
|
|
"buffer-frames", G_TYPE_INT, (gint) this->bin->nframes, NULL);
|
|
|
|
if (gst_pad_try_set_caps (pad->pad, caps) <= 0)
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
l = g_list_next (l);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-03-18 04:41:35 +00:00
|
|
|
case GST_STATE_PLAYING:
|
2004-03-14 22:34:33 +00:00
|
|
|
JACK_DEBUG ("%s: PLAYING", GST_OBJECT_NAME (GST_OBJECT (this)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
JACK_DEBUG ("%s: state change finished", GST_OBJECT_NAME (this));
|
2002-03-18 04:41:35 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_link (GstPad * pad, const GstCaps * caps)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
|
|
|
GstJack *this;
|
2003-09-30 12:56:27 +00:00
|
|
|
gint rate, buffer_frames;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-30 12:56:27 +00:00
|
|
|
this = GST_JACK (GST_OBJECT_PARENT (pad));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_structure_get_int (structure, "rate", &rate);
|
|
|
|
gst_structure_get_int (structure, "buffer-frames", &buffer_frames);
|
2003-12-22 01:47:09 +00:00
|
|
|
if (this->bin && (rate != this->bin->rate ||
|
2004-03-15 19:32:27 +00:00
|
|
|
buffer_frames != this->bin->nframes))
|
2004-03-14 22:34:33 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_jack_loop (GstElement * element)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
GstJack *this;
|
|
|
|
GList *pads;
|
|
|
|
gint len;
|
|
|
|
GstJackPad *pad;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
this = GST_JACK (element);
|
|
|
|
|
|
|
|
len = this->bin->nframes * sizeof (sample_t);
|
|
|
|
|
|
|
|
pads = this->pads;
|
|
|
|
while (pads) {
|
|
|
|
pad = GST_JACK_PAD (pads);
|
|
|
|
|
|
|
|
if (this->direction == GST_PAD_SINK) {
|
|
|
|
buffer = GST_BUFFER (gst_pad_pull (pad->pad));
|
|
|
|
|
|
|
|
if (GST_IS_EVENT (buffer)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
GstEvent *event = GST_EVENT (buffer);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (buffer)) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
gst_element_set_eos (element);
|
|
|
|
gst_event_unref (event);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
gst_pad_event_default (pad->pad, event);
|
|
|
|
return;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if the other plugins only give out buffer-frames or less (as
|
|
|
|
they should), if the length of the GstBuffer is different
|
|
|
|
from nframes then the buffer is short and we will get EOS
|
|
|
|
next */
|
|
|
|
memcpy (pad->data, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
|
|
|
|
if (len != GST_BUFFER_SIZE (buffer))
|
2004-03-15 19:32:27 +00:00
|
|
|
memset (pad->data + GST_BUFFER_SIZE (buffer), 0,
|
|
|
|
len - GST_BUFFER_SIZE (buffer));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
} else {
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
gst_buffer_set_data (buffer, pad->data, len);
|
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_DONTFREE);
|
|
|
|
|
|
|
|
gst_pad_push (pad->pad, GST_DATA (buffer));
|
2003-09-30 12:56:27 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
pads = g_list_next (pads);
|
|
|
|
}
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2002-03-18 04:41:35 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_element_register (plugin, "jackbin", GST_RANK_NONE,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_JACK_BIN))
|
2003-11-01 23:43:13 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_element_register (plugin, "jacksrc", GST_RANK_NONE,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_JACK_SRC))
|
2003-11-01 23:43:13 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_element_register (plugin, "jacksink", GST_RANK_NONE,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_JACK_SINK))
|
2003-11-01 23:43:13 +00:00
|
|
|
return FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-01 23:43:13 +00:00
|
|
|
return TRUE;
|
2002-03-18 04:41:35 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"jack",
|
|
|
|
"Jack Plugin Library", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN)
|