2001-12-17 19:03:13 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wim.taymans@chello.be>
|
|
|
|
*
|
|
|
|
* gstosssink.c:
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/soundcard.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2002-12-03 09:39:52 +00:00
|
|
|
#include <string.h>
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
#include <gstosssink.h>
|
|
|
|
|
2002-09-18 19:02:51 +00:00
|
|
|
/* elementfactory information */
|
2001-12-17 19:03:13 +00:00
|
|
|
static GstElementDetails gst_osssink_details = {
|
|
|
|
"Audio Sink (OSS)",
|
|
|
|
"Sink/Audio",
|
2002-09-18 19:02:51 +00:00
|
|
|
"LGPL",
|
2001-12-17 19:03:13 +00:00
|
|
|
"Output to a sound card via OSS",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>, "
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
|
|
|
static void gst_osssink_class_init (GstOssSinkClass *klass);
|
|
|
|
static void gst_osssink_init (GstOssSink *osssink);
|
|
|
|
static void gst_osssink_finalize (GObject *object);
|
|
|
|
|
|
|
|
static gboolean gst_osssink_open_audio (GstOssSink *sink);
|
|
|
|
static void gst_osssink_close_audio (GstOssSink *sink);
|
2002-01-13 22:27:25 +00:00
|
|
|
static gboolean gst_osssink_sync_parms (GstOssSink *osssink);
|
2001-12-17 19:03:13 +00:00
|
|
|
static GstElementStateReturn gst_osssink_change_state (GstElement *element);
|
2002-02-03 20:10:04 +00:00
|
|
|
static void gst_osssink_set_clock (GstElement *element, GstClock *clock);
|
2002-05-28 22:52:52 +00:00
|
|
|
static GstClock* gst_osssink_get_clock (GstElement *element);
|
|
|
|
static GstClockTime gst_osssink_get_time (GstClock *clock, gpointer data);
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2002-07-24 21:46:03 +00:00
|
|
|
static const GstFormat* gst_osssink_get_formats (GstPad *pad);
|
2002-06-01 11:00:27 +00:00
|
|
|
static gboolean gst_osssink_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value);
|
2002-07-24 21:46:03 +00:00
|
|
|
static const GstPadQueryType* gst_osssink_get_query_types (GstPad *pad);
|
2002-06-08 23:45:12 +00:00
|
|
|
static gboolean gst_osssink_query (GstElement *element, GstPadQueryType type,
|
|
|
|
GstFormat *format, gint64 *value);
|
|
|
|
static gboolean gst_osssink_sink_query (GstPad *pad, GstPadQueryType type,
|
2002-06-01 11:00:27 +00:00
|
|
|
GstFormat *format, gint64 *value);
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
static GstPadConnectReturn gst_osssink_sinkconnect (GstPad *pad, GstCaps *caps);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
static void gst_osssink_set_property (GObject *object, guint prop_id, const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gst_osssink_get_property (GObject *object, guint prop_id, GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gst_osssink_chain (GstPad *pad,GstBuffer *buf);
|
|
|
|
|
|
|
|
/* OssSink signals and args */
|
|
|
|
enum {
|
|
|
|
SIGNAL_HANDOFF,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_DEVICE,
|
|
|
|
ARG_MUTE,
|
|
|
|
ARG_FRAGMENT,
|
2002-05-26 23:01:16 +00:00
|
|
|
ARG_BUFFER_SIZE,
|
|
|
|
ARG_SYNC
|
2001-12-17 19:03:13 +00:00
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (osssink_sink_factory,
|
2001-12-17 19:03:13 +00:00
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"osssink_sink",
|
|
|
|
"audio/raw",
|
2002-02-07 14:32:36 +00:00
|
|
|
"format", GST_PROPS_STRING ("int"), /* hack */
|
2001-12-17 19:03:13 +00:00
|
|
|
"law", GST_PROPS_INT (0),
|
|
|
|
"endianness", GST_PROPS_INT (G_BYTE_ORDER),
|
|
|
|
"signed", GST_PROPS_LIST (
|
2002-01-13 22:27:25 +00:00
|
|
|
GST_PROPS_BOOLEAN (FALSE),
|
|
|
|
GST_PROPS_BOOLEAN (TRUE)
|
|
|
|
),
|
2001-12-17 19:03:13 +00:00
|
|
|
"width", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_INT (8),
|
|
|
|
GST_PROPS_INT (16)
|
|
|
|
),
|
|
|
|
"depth", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_INT (8),
|
|
|
|
GST_PROPS_INT (16)
|
|
|
|
),
|
2001-12-29 12:37:00 +00:00
|
|
|
"rate", GST_PROPS_INT_RANGE (1000, 48000),
|
2001-12-17 19:03:13 +00:00
|
|
|
"channels", GST_PROPS_INT_RANGE (1, 2)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
static guint gst_osssink_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_osssink_get_type (void)
|
|
|
|
{
|
|
|
|
static GType osssink_type = 0;
|
|
|
|
|
|
|
|
if (!osssink_type) {
|
|
|
|
static const GTypeInfo osssink_info = {
|
|
|
|
sizeof(GstOssSinkClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_osssink_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstOssSink),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_osssink_init,
|
|
|
|
};
|
|
|
|
osssink_type = g_type_register_static (GST_TYPE_ELEMENT, "GstOssSink", &osssink_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return osssink_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstBufferPool*
|
|
|
|
gst_osssink_get_bufferpool (GstPad *pad)
|
|
|
|
{
|
|
|
|
GstOssSink *oss;
|
|
|
|
|
|
|
|
oss = GST_OSSSINK (gst_pad_get_parent(pad));
|
|
|
|
|
2002-07-24 21:46:03 +00:00
|
|
|
/* 6 buffers per chunk by default */
|
|
|
|
if (!oss->sinkpool)
|
|
|
|
oss->sinkpool = gst_buffer_pool_get_default (oss->bufsize, 6);
|
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
return oss->sinkpool;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osssink_finalize (GObject *object)
|
|
|
|
{
|
2002-02-03 20:10:04 +00:00
|
|
|
GstOssSink *osssink = (GstOssSink *) object;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-02-03 20:10:04 +00:00
|
|
|
g_free (osssink->device);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-02-03 20:10:04 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osssink_class_init (GstOssSinkClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
|
|
|
2002-09-02 19:22:35 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEVICE,
|
|
|
|
g_param_spec_string ("device", "Device", "The device to use for output",
|
|
|
|
"/dev/dsp", G_PARAM_READWRITE)); /* CHECKME! */
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MUTE,
|
|
|
|
g_param_spec_boolean ("mute", "Mute", "Mute the audio",
|
|
|
|
TRUE, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SYNC,
|
|
|
|
g_param_spec_boolean ("sync", "Sync", "If syncing on timestamps should be enabled",
|
|
|
|
TRUE, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FRAGMENT,
|
|
|
|
g_param_spec_int ("fragment", "Fragment",
|
|
|
|
"The fragment as 0xMMMMSSSS (MMMM = total fragments, 2^SSSS = fragment size)",
|
|
|
|
0, G_MAXINT, 6, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BUFFER_SIZE,
|
|
|
|
g_param_spec_int ("buffer_size", "Buffer size", "The buffer size",
|
|
|
|
0, G_MAXINT, 4096, G_PARAM_READWRITE));
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
gst_osssink_signals[SIGNAL_HANDOFF] =
|
2002-09-02 19:22:35 +00:00
|
|
|
g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstOssSinkClass, handoff), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_osssink_set_property;
|
|
|
|
gobject_class->get_property = gst_osssink_get_property;
|
|
|
|
gobject_class->finalize = gst_osssink_finalize;
|
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_osssink_change_state);
|
2002-06-08 23:45:12 +00:00
|
|
|
gstelement_class->query = GST_DEBUG_FUNCPTR (gst_osssink_query);
|
2002-11-27 20:54:43 +00:00
|
|
|
gstelement_class->set_clock = gst_osssink_set_clock;
|
|
|
|
gstelement_class->get_clock = gst_osssink_get_clock;
|
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
}
|
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
static void
|
|
|
|
gst_osssink_init (GstOssSink *osssink)
|
|
|
|
{
|
|
|
|
osssink->sinkpad = gst_pad_new_from_template (
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_GET (osssink_sink_factory), "sink");
|
2001-12-17 19:03:13 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (osssink), osssink->sinkpad);
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_pad_set_connect_function (osssink->sinkpad, gst_osssink_sinkconnect);
|
2001-12-17 19:03:13 +00:00
|
|
|
gst_pad_set_bufferpool_function (osssink->sinkpad, gst_osssink_get_bufferpool);
|
2002-06-01 11:00:27 +00:00
|
|
|
gst_pad_set_convert_function (osssink->sinkpad, gst_osssink_convert);
|
2002-06-08 23:45:12 +00:00
|
|
|
gst_pad_set_query_function (osssink->sinkpad, gst_osssink_sink_query);
|
2002-07-24 21:46:03 +00:00
|
|
|
gst_pad_set_query_type_function (osssink->sinkpad, gst_osssink_get_query_types);
|
|
|
|
gst_pad_set_formats_function (osssink->sinkpad, gst_osssink_get_formats);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
gst_pad_set_chain_function (osssink->sinkpad, gst_osssink_chain);
|
|
|
|
|
|
|
|
osssink->device = g_strdup ("/dev/dsp");
|
|
|
|
osssink->fd = -1;
|
|
|
|
osssink->channels = 1;
|
|
|
|
osssink->frequency = 11025;
|
|
|
|
osssink->fragment = 6;
|
|
|
|
/* AFMT_*_BE not available on all OSS includes (e.g. FBSD) */
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
osssink->format = AFMT_S16_BE;
|
|
|
|
#else
|
|
|
|
osssink->format = AFMT_S16_LE;
|
|
|
|
#endif /* WORDS_BIGENDIAN */
|
|
|
|
osssink->bufsize = 4096;
|
2002-04-28 14:33:09 +00:00
|
|
|
osssink->bps = 0;
|
2002-05-26 21:59:22 +00:00
|
|
|
osssink->resync = FALSE;
|
2002-05-26 23:01:16 +00:00
|
|
|
osssink->sync = TRUE;
|
2002-07-24 21:46:03 +00:00
|
|
|
osssink->sinkpool = NULL;
|
2002-05-28 22:52:52 +00:00
|
|
|
osssink->provided_clock = GST_CLOCK (gst_oss_clock_new ("ossclock", gst_osssink_get_time, osssink));
|
|
|
|
osssink->handled = 0;
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
GST_FLAG_SET (osssink, GST_ELEMENT_THREAD_SUGGESTED);
|
2002-03-30 17:06:26 +00:00
|
|
|
GST_FLAG_SET (osssink, GST_ELEMENT_EVENT_AWARE);
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
2002-05-28 22:52:52 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
static GstPadConnectReturn
|
|
|
|
gst_osssink_sinkconnect (GstPad *pad, GstCaps *caps)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
2002-06-01 11:00:27 +00:00
|
|
|
gint law, endianness, depth;
|
2001-12-17 19:03:13 +00:00
|
|
|
gboolean sign;
|
|
|
|
gint format = -1;
|
2002-01-13 22:27:25 +00:00
|
|
|
GstOssSink *osssink = GST_OSSSINK (gst_pad_get_parent (pad));
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
if (!GST_CAPS_IS_FIXED (caps))
|
|
|
|
return GST_PAD_CONNECT_DELAYED;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-06-01 11:00:27 +00:00
|
|
|
gst_caps_get_int (caps, "width", &osssink->width);
|
2002-03-30 17:06:26 +00:00
|
|
|
gst_caps_get_int (caps, "depth", &depth);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-06-01 11:00:27 +00:00
|
|
|
if (osssink->width != depth)
|
2002-01-13 22:27:25 +00:00
|
|
|
return GST_PAD_CONNECT_REFUSED;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
/* laws 1 and 2 are 1 bps anyway */
|
|
|
|
osssink->bps = 1;
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
gst_caps_get_int (caps, "law", &law);
|
|
|
|
gst_caps_get_int (caps, "endianness", &endianness);
|
|
|
|
gst_caps_get_boolean (caps, "signed", &sign);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
if (law == 0) {
|
2002-06-01 11:00:27 +00:00
|
|
|
if (osssink->width == 16) {
|
2001-12-17 19:03:13 +00:00
|
|
|
if (sign == TRUE) {
|
|
|
|
if (endianness == G_LITTLE_ENDIAN)
|
2002-09-23 09:09:41 +00:00
|
|
|
{
|
2001-12-17 19:03:13 +00:00
|
|
|
format = AFMT_S16_LE;
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO,
|
|
|
|
"gst_osssink_sinkconnect: 16 bit signed LE, no law (%d)",
|
|
|
|
format);
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
else if (endianness == G_BIG_ENDIAN)
|
2002-09-23 09:09:41 +00:00
|
|
|
{
|
2001-12-17 19:03:13 +00:00
|
|
|
format = AFMT_S16_BE;
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO,
|
|
|
|
"gst_osssink_sinkconnect: 16 bit signed BE, no law (%d)",
|
|
|
|
format);
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (endianness == G_LITTLE_ENDIAN)
|
2002-09-23 09:09:41 +00:00
|
|
|
{
|
2001-12-17 19:03:13 +00:00
|
|
|
format = AFMT_U16_LE;
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO,
|
|
|
|
"gst_osssink_sinkconnect: 16 bit unsigned LE, no law (%d)",
|
|
|
|
format);
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
else if (endianness == G_BIG_ENDIAN)
|
2002-09-23 09:09:41 +00:00
|
|
|
{
|
2001-12-17 19:03:13 +00:00
|
|
|
format = AFMT_U16_BE;
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO,
|
|
|
|
"gst_osssink_sinkconnect: 16 bit unsigned BE, no law (%d)",
|
|
|
|
format);
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
2002-02-03 20:10:04 +00:00
|
|
|
osssink->bps = 2;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
2002-06-01 11:00:27 +00:00
|
|
|
else if (osssink->width == 8) {
|
2001-12-17 19:03:13 +00:00
|
|
|
if (sign == TRUE) {
|
|
|
|
format = AFMT_S8;
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO,
|
|
|
|
"gst_osssink_sinkconnect: 8 bit signed, no law (%d)",
|
|
|
|
format);
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
format = AFMT_U8;
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO,
|
|
|
|
"gst_osssink_sinkconnect: 8 bit unsigned, no law (%d)",
|
|
|
|
format);
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
2002-02-03 20:10:04 +00:00
|
|
|
osssink->bps = 1;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
2002-02-17 02:06:04 +00:00
|
|
|
} else if (law == 1) {
|
|
|
|
format = AFMT_MU_LAW;
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO,
|
|
|
|
"gst_osssink_sinkconnect: mu law (%d)",
|
|
|
|
format);
|
2002-02-17 02:06:04 +00:00
|
|
|
} else if (law == 2) {
|
|
|
|
format = AFMT_A_LAW;
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO,
|
|
|
|
"gst_osssink_sinkconnect: a law (%d)",
|
|
|
|
format);
|
2002-02-17 02:06:04 +00:00
|
|
|
} else {
|
|
|
|
g_critical ("unknown law");
|
|
|
|
return GST_PAD_CONNECT_REFUSED;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (format == -1)
|
2002-01-13 22:27:25 +00:00
|
|
|
return GST_PAD_CONNECT_REFUSED;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
osssink->format = format;
|
2002-03-30 17:06:26 +00:00
|
|
|
gst_caps_get_int (caps, "channels", &osssink->channels);
|
|
|
|
gst_caps_get_int (caps, "rate", &osssink->frequency);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-02-03 20:10:04 +00:00
|
|
|
osssink->bps *= osssink->channels;
|
|
|
|
osssink->bps *= osssink->frequency;
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
if (!gst_osssink_sync_parms (osssink)) {
|
|
|
|
return GST_PAD_CONNECT_REFUSED;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
return GST_PAD_CONNECT_OK;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
static gboolean
|
2001-12-17 19:03:13 +00:00
|
|
|
gst_osssink_sync_parms (GstOssSink *osssink)
|
|
|
|
{
|
|
|
|
audio_buf_info ospace;
|
|
|
|
int frag;
|
2002-01-13 22:27:25 +00:00
|
|
|
gint target_format;
|
|
|
|
gint target_channels;
|
|
|
|
gint target_frequency;
|
2002-02-07 14:32:36 +00:00
|
|
|
GObject *object;
|
2002-09-02 19:22:35 +00:00
|
|
|
gint fragscale, frag_ln;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-02-03 20:10:04 +00:00
|
|
|
g_return_val_if_fail (osssink != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_OSSSINK (osssink), FALSE);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
if (osssink->fd == -1)
|
|
|
|
return FALSE;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
if (osssink->fragment >> 16)
|
2002-03-30 17:06:26 +00:00
|
|
|
frag = osssink->fragment;
|
2001-12-17 19:03:13 +00:00
|
|
|
else
|
2002-03-30 17:06:26 +00:00
|
|
|
frag = 0x7FFF0000 | osssink->fragment;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_INFO (GST_CAT_PLUGIN_INFO,
|
|
|
|
"osssink: setting sound card to %dHz %d format %s (%08x fragment)",
|
|
|
|
osssink->frequency, osssink->format,
|
|
|
|
(osssink->channels == 2) ? "stereo" : "mono", frag);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_SETFRAGMENT, &frag);
|
|
|
|
|
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_RESET, 0);
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
target_format = osssink->format;
|
|
|
|
target_channels = osssink->channels;
|
|
|
|
target_frequency = osssink->frequency;
|
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_SETFMT, &osssink->format);
|
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_CHANNELS, &osssink->channels);
|
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_SPEED, &osssink->frequency);
|
|
|
|
|
2002-09-02 19:22:35 +00:00
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_GETBLKSIZE, &osssink->fragment_size);
|
2001-12-17 19:03:13 +00:00
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_GETOSPACE, &ospace);
|
|
|
|
|
2002-09-02 19:22:35 +00:00
|
|
|
/* calculate new fragment using a poor man's logarithm function */
|
|
|
|
fragscale = 1;
|
|
|
|
frag_ln = 0;
|
|
|
|
while (fragscale < ospace.fragsize) {
|
|
|
|
fragscale <<= 1;
|
|
|
|
frag_ln++;
|
|
|
|
}
|
|
|
|
osssink->fragment = ospace.fragstotal << 16 | frag_ln;
|
|
|
|
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_INFO (GST_CAT_PLUGIN_INFO,
|
|
|
|
"osssink: set sound card to %dHz %d format %s "
|
|
|
|
"(%d bytes buffer, %08x fragment)",
|
|
|
|
osssink->frequency, osssink->format,
|
|
|
|
(osssink->channels == 2) ? "stereo" : "mono",
|
|
|
|
ospace.bytes, osssink->fragment);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-02-07 14:32:36 +00:00
|
|
|
object = G_OBJECT (osssink);
|
|
|
|
g_object_freeze_notify (object);
|
|
|
|
g_object_notify (object, "fragment");
|
|
|
|
g_object_thaw_notify (object);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2002-09-02 19:22:35 +00:00
|
|
|
osssink->fragment_time = (GST_SECOND * osssink->fragment_size) / osssink->bps;
|
2002-09-23 09:09:41 +00:00
|
|
|
GST_INFO (GST_CAT_PLUGIN_INFO, "fragment time %u %llu\n",
|
|
|
|
osssink->bps, osssink->fragment_time);
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
if (target_format != osssink->format ||
|
|
|
|
target_channels != osssink->channels ||
|
|
|
|
target_frequency != osssink->frequency)
|
|
|
|
{
|
2002-09-23 09:09:41 +00:00
|
|
|
g_warning ("couldn't set requested OSS parameters, enjoy the noise :)");
|
2002-01-13 22:27:25 +00:00
|
|
|
/* we could eventually return FALSE here, or just do some additional tests
|
|
|
|
* to see that the frequencies don't differ too much etc.. */
|
|
|
|
}
|
|
|
|
return TRUE;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
2002-05-28 22:52:52 +00:00
|
|
|
static inline gint64
|
|
|
|
gst_osssink_get_delay (GstOssSink *osssink)
|
|
|
|
{
|
|
|
|
gint delay = 0;
|
|
|
|
|
2002-06-01 11:00:27 +00:00
|
|
|
if (osssink->fd == -1)
|
|
|
|
return 0;
|
|
|
|
|
2002-05-28 22:52:52 +00:00
|
|
|
if (ioctl (osssink->fd, SNDCTL_DSP_GETODELAY, &delay) < 0) {
|
|
|
|
audio_buf_info info;
|
|
|
|
if (ioctl (osssink->fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
|
|
|
|
delay = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delay = (info.fragstotal * info.fragsize) - info.bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstClockTime
|
|
|
|
gst_osssink_get_time (GstClock *clock, gpointer data)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink = GST_OSSSINK (data);
|
|
|
|
gint delay;
|
|
|
|
GstClockTime res;
|
|
|
|
|
|
|
|
if (!osssink->bps)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
delay = gst_osssink_get_delay (osssink);
|
|
|
|
|
2002-09-23 09:09:41 +00:00
|
|
|
/* sometimes delay is bigger than the number of bytes sent to the device,
|
|
|
|
* which screws up this calculation, we assume that everything is still
|
|
|
|
* in the device then */
|
2002-05-28 22:52:52 +00:00
|
|
|
if (((guint64)delay) > osssink->handled) {
|
|
|
|
delay = osssink->handled;
|
|
|
|
}
|
|
|
|
res = (osssink->handled - delay) * GST_SECOND / osssink->bps;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstClock*
|
|
|
|
gst_osssink_get_clock (GstElement *element)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink;
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (element);
|
|
|
|
|
|
|
|
return GST_CLOCK (osssink->provided_clock);
|
|
|
|
}
|
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
static void
|
|
|
|
gst_osssink_set_clock (GstElement *element, GstClock *clock)
|
2002-02-03 20:10:04 +00:00
|
|
|
{
|
|
|
|
GstOssSink *osssink;
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (element);
|
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
osssink->clock = clock;
|
2002-02-03 20:10:04 +00:00
|
|
|
}
|
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
static void
|
|
|
|
gst_osssink_chain (GstPad *pad, GstBuffer *buf)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink;
|
2002-02-03 20:10:04 +00:00
|
|
|
GstClockTime buftime;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
/* this has to be an audio buffer */
|
|
|
|
osssink = GST_OSSSINK (gst_pad_get_parent (pad));
|
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
if (GST_IS_EVENT (buf)) {
|
2002-05-26 21:59:22 +00:00
|
|
|
GstEvent *event = GST_EVENT (buf);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2002-03-30 17:06:26 +00:00
|
|
|
case GST_EVENT_EOS:
|
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_SYNC);
|
2002-05-31 17:52:50 +00:00
|
|
|
gst_oss_clock_set_active (osssink->provided_clock, FALSE);
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_pad_event_default (pad, event);
|
|
|
|
return;
|
|
|
|
case GST_EVENT_NEW_MEDIA:
|
|
|
|
g_print ("new media\n");
|
2002-07-08 19:44:28 +00:00
|
|
|
break;
|
2002-05-26 21:59:22 +00:00
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
|
|
|
{
|
|
|
|
gint64 value;
|
2002-06-16 21:58:39 +00:00
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_RESET);
|
|
|
|
if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &value)) {
|
2002-05-30 19:10:31 +00:00
|
|
|
if (!gst_clock_handle_discont (osssink->clock, value))
|
|
|
|
gst_oss_clock_set_active (osssink->provided_clock, FALSE);
|
2002-05-28 22:52:52 +00:00
|
|
|
osssink->handled = 0;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
osssink->resync = TRUE;
|
2002-06-16 21:58:39 +00:00
|
|
|
break;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
2002-03-30 17:06:26 +00:00
|
|
|
default:
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_pad_event_default (pad, event);
|
2002-03-30 17:06:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-07-08 19:44:28 +00:00
|
|
|
gst_event_unref (event);
|
2002-06-16 21:58:39 +00:00
|
|
|
return;
|
2002-03-30 17:06:26 +00:00
|
|
|
}
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2002-02-17 02:06:04 +00:00
|
|
|
if (!osssink->bps) {
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
gst_element_error (GST_ELEMENT (osssink), "capsnego was never performed, unknown data type");
|
2002-05-26 21:59:22 +00:00
|
|
|
return;
|
2002-02-17 02:06:04 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
buftime = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
|
2002-02-03 20:10:04 +00:00
|
|
|
if (osssink->fd >= 0) {
|
|
|
|
if (!osssink->mute) {
|
|
|
|
guchar *data = GST_BUFFER_DATA (buf);
|
|
|
|
gint size = GST_BUFFER_SIZE (buf);
|
|
|
|
|
|
|
|
if (osssink->clock) {
|
2002-05-27 23:02:02 +00:00
|
|
|
gint delay = 0;
|
2002-05-26 21:59:22 +00:00
|
|
|
gint64 queued;
|
|
|
|
GstClockTimeDiff jitter;
|
|
|
|
|
2002-05-28 22:52:52 +00:00
|
|
|
delay = gst_osssink_get_delay (osssink);
|
2002-05-26 21:59:22 +00:00
|
|
|
queued = delay * GST_SECOND / osssink->bps;
|
|
|
|
|
2002-05-26 23:01:16 +00:00
|
|
|
if (osssink->resync && osssink->sync) {
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_element_clock_wait (GST_ELEMENT (osssink), osssink->clock,
|
|
|
|
buftime - queued, &jitter);
|
|
|
|
|
2002-07-28 18:13:26 +00:00
|
|
|
if (jitter >= 0) {
|
2002-05-28 22:52:52 +00:00
|
|
|
gst_clock_handle_discont (osssink->clock, buftime - queued + jitter);
|
2002-05-26 21:59:22 +00:00
|
|
|
write (osssink->fd, data, size);
|
2002-05-28 22:52:52 +00:00
|
|
|
gst_oss_clock_set_active (osssink->provided_clock, TRUE);
|
2002-05-26 21:59:22 +00:00
|
|
|
osssink->resync = FALSE;
|
2002-05-28 22:52:52 +00:00
|
|
|
osssink->handled += size;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
write (osssink->fd, data, size);
|
2002-05-28 22:52:52 +00:00
|
|
|
osssink->handled += size;
|
2002-02-03 20:10:04 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-30 17:06:26 +00:00
|
|
|
/* no clock, try to be as fast as possible */
|
2002-02-03 20:10:04 +00:00
|
|
|
else {
|
|
|
|
audio_buf_info ospace;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_GETOSPACE, &ospace);
|
2002-02-03 20:10:04 +00:00
|
|
|
|
|
|
|
if (ospace.bytes >= size) {
|
|
|
|
write (osssink->fd, data, size);
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
|
2002-07-24 21:46:03 +00:00
|
|
|
static const GstFormat*
|
|
|
|
gst_osssink_get_formats (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstFormat formats[] = {
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
GST_FORMAT_UNITS,
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
2002-06-01 11:00:27 +00:00
|
|
|
static gboolean
|
|
|
|
gst_osssink_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
|
|
|
|
GstOssSink *osssink;
|
|
|
|
|
|
|
|
if (src_format == *dest_format) {
|
|
|
|
*dest_value = src_value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (osssink->bps == 0 || osssink->channels == 0 || osssink->width == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_format = GST_FORMAT_TIME;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*dest_value = src_value * GST_SECOND / osssink->bps;
|
|
|
|
break;
|
2002-06-02 15:57:30 +00:00
|
|
|
case GST_FORMAT_UNITS:
|
2002-06-01 11:00:27 +00:00
|
|
|
*dest_value = src_value / (osssink->channels * osssink->width);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_format = GST_FORMAT_BYTES;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * osssink->bps / GST_SECOND;
|
|
|
|
break;
|
2002-06-02 15:57:30 +00:00
|
|
|
case GST_FORMAT_UNITS:
|
2002-06-08 23:45:12 +00:00
|
|
|
*dest_value = src_value * osssink->frequency / GST_SECOND;
|
2002-06-01 11:00:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2002-06-02 15:57:30 +00:00
|
|
|
case GST_FORMAT_UNITS:
|
2002-06-01 11:00:27 +00:00
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_format = GST_FORMAT_TIME;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*dest_value = src_value * GST_SECOND / osssink->frequency;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * osssink->channels * osssink->width;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-07-24 21:46:03 +00:00
|
|
|
static const GstPadQueryType*
|
|
|
|
gst_osssink_get_query_types (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstPadQueryType query_types[] = {
|
|
|
|
GST_PAD_QUERY_LATENCY,
|
|
|
|
GST_PAD_QUERY_POSITION,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
return query_types;
|
|
|
|
}
|
|
|
|
|
2002-06-01 11:00:27 +00:00
|
|
|
static gboolean
|
2002-06-08 23:45:12 +00:00
|
|
|
gst_osssink_sink_query (GstPad *pad, GstPadQueryType type, GstFormat *format, gint64 *value)
|
2002-06-01 11:00:27 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstOssSink *osssink;
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case GST_PAD_QUERY_LATENCY:
|
|
|
|
if (!gst_osssink_convert (pad,
|
|
|
|
GST_FORMAT_BYTES, gst_osssink_get_delay (osssink),
|
|
|
|
format, value))
|
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2002-06-08 23:45:12 +00:00
|
|
|
case GST_PAD_QUERY_POSITION:
|
|
|
|
if (!gst_osssink_convert (pad,
|
|
|
|
GST_FORMAT_TIME, gst_clock_get_time (osssink->provided_clock),
|
|
|
|
format, value))
|
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2002-06-01 11:00:27 +00:00
|
|
|
default:
|
2002-06-08 23:45:12 +00:00
|
|
|
res = gst_pad_query (gst_pad_get_peer (osssink->sinkpad), type, format, value);
|
2002-06-01 11:00:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-06-08 23:45:12 +00:00
|
|
|
static gboolean
|
|
|
|
gst_osssink_query (GstElement *element, GstPadQueryType type, GstFormat *format, gint64 *value)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink = GST_OSSSINK (element);
|
|
|
|
|
|
|
|
return gst_osssink_sink_query (osssink->sinkpad, type, format, value);
|
|
|
|
}
|
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
static void
|
|
|
|
gst_osssink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_OSSSINK (object));
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
2002-02-07 14:32:36 +00:00
|
|
|
/* disallow changing the device while it is opened
|
|
|
|
get_property("device") should return the right one */
|
|
|
|
if (!GST_FLAG_IS_SET (osssink, GST_OSSSINK_OPEN))
|
|
|
|
{
|
|
|
|
g_free (osssink->device);
|
|
|
|
osssink->device = g_strdup (g_value_get_string (value));
|
|
|
|
g_object_notify (object, "device");
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
|
|
|
case ARG_MUTE:
|
|
|
|
osssink->mute = g_value_get_boolean (value);
|
2002-02-21 10:47:27 +00:00
|
|
|
g_object_notify (G_OBJECT (osssink), "mute");
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
|
|
|
case ARG_FRAGMENT:
|
|
|
|
osssink->fragment = g_value_get_int (value);
|
|
|
|
gst_osssink_sync_parms (osssink);
|
|
|
|
break;
|
|
|
|
case ARG_BUFFER_SIZE:
|
2002-02-07 14:32:36 +00:00
|
|
|
if (osssink->bufsize == g_value_get_int (value)) break;
|
2001-12-17 19:03:13 +00:00
|
|
|
osssink->bufsize = g_value_get_int (value);
|
|
|
|
osssink->sinkpool = gst_buffer_pool_get_default (osssink->bufsize, 6);
|
2002-02-07 14:32:36 +00:00
|
|
|
g_object_notify (object, "buffer_size");
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
2002-05-26 23:01:16 +00:00
|
|
|
case ARG_SYNC:
|
|
|
|
osssink->sync = g_value_get_boolean (value);
|
|
|
|
g_object_notify (G_OBJECT (osssink), "sync");
|
2002-09-12 18:47:39 +00:00
|
|
|
break;
|
2001-12-17 19:03:13 +00:00
|
|
|
default:
|
2002-09-12 18:47:39 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osssink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_OSSSINK (object));
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
|
|
|
g_value_set_string (value, osssink->device);
|
|
|
|
break;
|
|
|
|
case ARG_MUTE:
|
|
|
|
g_value_set_boolean (value, osssink->mute);
|
|
|
|
break;
|
|
|
|
case ARG_FRAGMENT:
|
|
|
|
g_value_set_int (value, osssink->fragment);
|
|
|
|
break;
|
|
|
|
case ARG_BUFFER_SIZE:
|
|
|
|
g_value_set_int (value, osssink->bufsize);
|
|
|
|
break;
|
2002-05-26 23:01:16 +00:00
|
|
|
case ARG_SYNC:
|
|
|
|
g_value_set_boolean (value, osssink->sync);
|
|
|
|
break;
|
2001-12-17 19:03:13 +00:00
|
|
|
default:
|
2002-09-12 18:47:39 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_osssink_open_audio (GstOssSink *sink)
|
|
|
|
{
|
|
|
|
gint caps;
|
|
|
|
g_return_val_if_fail (sink->fd == -1, FALSE);
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: attempting to open sound device");
|
|
|
|
|
|
|
|
/* first try to open the sound card */
|
2002-12-03 09:39:52 +00:00
|
|
|
/* FIXME: this code is dubious, why do we need to open and close this ?*/
|
2002-07-10 21:14:13 +00:00
|
|
|
sink->fd = open (sink->device, O_WRONLY | O_NONBLOCK);
|
2001-12-17 19:03:13 +00:00
|
|
|
if (errno == EBUSY) {
|
|
|
|
g_warning ("osssink: unable to open the sound device (in use ?)\n");
|
|
|
|
}
|
|
|
|
|
2002-11-24 11:45:03 +00:00
|
|
|
if (sink->fd >= 0)
|
|
|
|
close (sink->fd);
|
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
/* re-open the sound device in blocking mode */
|
2002-07-10 21:14:13 +00:00
|
|
|
sink->fd = open (sink->device, O_WRONLY);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-07-10 21:14:13 +00:00
|
|
|
if (sink->fd < 0) {
|
2002-12-03 09:39:52 +00:00
|
|
|
switch (errno) {
|
|
|
|
case EISDIR:
|
|
|
|
gst_element_error (GST_ELEMENT (sink),
|
|
|
|
"osssink: Device %s is a directory",
|
|
|
|
sink->device);
|
|
|
|
break;
|
|
|
|
case EACCES:
|
|
|
|
case ETXTBSY:
|
|
|
|
gst_element_error (GST_ELEMENT (sink),
|
|
|
|
"osssink: Cannot access %s, check permissions",
|
|
|
|
sink->device);
|
|
|
|
break;
|
|
|
|
case ENXIO:
|
|
|
|
case ENODEV:
|
|
|
|
case ENOENT:
|
|
|
|
gst_element_error (GST_ELEMENT (sink),
|
|
|
|
"osssink: Cannot access %s, does it exist ?",
|
|
|
|
sink->device);
|
|
|
|
break;
|
|
|
|
case EROFS:
|
|
|
|
gst_element_error (GST_ELEMENT (sink),
|
|
|
|
"osssink: Cannot access %s, read-only filesystem ?",
|
|
|
|
sink->device);
|
|
|
|
default:
|
|
|
|
/* FIXME: strerror is not threadsafe */
|
|
|
|
gst_element_error (GST_ELEMENT (sink),
|
|
|
|
"osssink: Cannot open %s, generic error: %s",
|
|
|
|
sink->device, strerror (errno));
|
|
|
|
break;
|
|
|
|
}
|
2002-07-10 21:14:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* we have it, set the default parameters and go have fun */
|
|
|
|
/* set card state */
|
|
|
|
ioctl (sink->fd, SNDCTL_DSP_GETCAPS, &caps);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-07-10 21:14:13 +00:00
|
|
|
GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Capabilities %08x", caps);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-07-10 21:14:13 +00:00
|
|
|
if (caps & DSP_CAP_DUPLEX) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Full duplex");
|
|
|
|
if (caps & DSP_CAP_REALTIME) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Realtime");
|
|
|
|
if (caps & DSP_CAP_BATCH) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Batch");
|
|
|
|
if (caps & DSP_CAP_COPROC) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Has coprocessor");
|
|
|
|
if (caps & DSP_CAP_TRIGGER) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Trigger");
|
|
|
|
if (caps & DSP_CAP_MMAP) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Direct access");
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
#ifdef DSP_CAP_MULTI
|
2002-07-10 21:14:13 +00:00
|
|
|
if (caps & DSP_CAP_MULTI) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Multiple open");
|
2001-12-17 19:03:13 +00:00
|
|
|
#endif /* DSP_CAP_MULTI */
|
|
|
|
|
|
|
|
#ifdef DSP_CAP_BIND
|
2002-07-10 21:14:13 +00:00
|
|
|
if (caps & DSP_CAP_BIND) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Channel binding");
|
2001-12-17 19:03:13 +00:00
|
|
|
#endif /* DSP_CAP_BIND */
|
|
|
|
|
2002-07-10 21:14:13 +00:00
|
|
|
ioctl(sink->fd, SNDCTL_DSP_GETFMTS, &caps);
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Formats %08x", caps);
|
|
|
|
if (caps & AFMT_MU_LAW) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: MU_LAW");
|
|
|
|
if (caps & AFMT_A_LAW) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: A_LAW");
|
|
|
|
if (caps & AFMT_IMA_ADPCM) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: IMA_ADPCM");
|
|
|
|
if (caps & AFMT_U8) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: U8");
|
|
|
|
if (caps & AFMT_S16_LE) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: S16_LE");
|
|
|
|
if (caps & AFMT_S16_BE) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: S16_BE");
|
|
|
|
if (caps & AFMT_S8) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: S8");
|
|
|
|
if (caps & AFMT_U16_LE) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: U16_LE");
|
|
|
|
if (caps & AFMT_U16_BE) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: U16_BE");
|
|
|
|
if (caps & AFMT_MPEG) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: MPEG");
|
2001-12-17 19:03:13 +00:00
|
|
|
#ifdef AFMT_AC3
|
2002-07-10 21:14:13 +00:00
|
|
|
if (caps & AFMT_AC3) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: AC3");
|
2001-12-17 19:03:13 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-10 21:14:13 +00:00
|
|
|
GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: opened audio (%s) with fd=%d", sink->device, sink->fd);
|
|
|
|
GST_FLAG_SET (sink, GST_OSSSINK_OPEN);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-07-10 21:14:13 +00:00
|
|
|
return TRUE;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osssink_close_audio (GstOssSink *sink)
|
|
|
|
{
|
|
|
|
if (sink->fd < 0) return;
|
|
|
|
|
|
|
|
close(sink->fd);
|
|
|
|
sink->fd = -1;
|
|
|
|
|
|
|
|
GST_FLAG_UNSET (sink, GST_OSSSINK_OPEN);
|
|
|
|
|
|
|
|
GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: closed sound device");
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_osssink_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_OSSSINK (element), FALSE);
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (element);
|
|
|
|
|
2001-12-25 02:17:53 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
if (!GST_FLAG_IS_SET (element, GST_OSSSINK_OPEN)) {
|
|
|
|
if (!gst_osssink_open_audio (osssink)) {
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
2001-12-25 02:17:53 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2002-09-02 19:22:35 +00:00
|
|
|
break;
|
2001-12-25 02:17:53 +00:00
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
2002-05-26 21:59:22 +00:00
|
|
|
osssink->resync = TRUE;
|
2001-12-25 02:17:53 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
2002-02-03 20:10:04 +00:00
|
|
|
{
|
2002-05-04 18:52:32 +00:00
|
|
|
if (GST_FLAG_IS_SET (element, GST_OSSSINK_OPEN))
|
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_RESET, 0);
|
2002-05-28 22:52:52 +00:00
|
|
|
gst_oss_clock_set_active (osssink->provided_clock, FALSE);
|
|
|
|
osssink->resync = TRUE;
|
2001-12-25 02:17:53 +00:00
|
|
|
break;
|
2002-02-03 20:10:04 +00:00
|
|
|
}
|
2001-12-25 02:17:53 +00:00
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2002-02-03 20:10:04 +00:00
|
|
|
if (GST_FLAG_IS_SET (element, GST_OSSSINK_OPEN))
|
|
|
|
ioctl (osssink->fd, SNDCTL_DSP_RESET, 0);
|
2001-12-25 02:17:53 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
if (GST_FLAG_IS_SET (element, GST_OSSSINK_OPEN))
|
|
|
|
gst_osssink_close_audio (osssink);
|
|
|
|
break;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_osssink_factory_init (GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
factory = gst_element_factory_new ("osssink", GST_TYPE_OSSSINK, &gst_osssink_details);
|
2001-12-17 19:03:13 +00:00
|
|
|
g_return_val_if_fail (factory != NULL, FALSE);
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (osssink_sink_factory));
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|