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.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-17 19:03:13 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/soundcard.h>
|
2003-05-31 14:14:21 +00:00
|
|
|
#include <errno.h>
|
2003-06-29 19:46:12 +00:00
|
|
|
#include <unistd.h>
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#include "gstosssink.h"
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-09-18 19:02:51 +00:00
|
|
|
/* elementfactory information */
|
2003-10-31 20:03:30 +00:00
|
|
|
static GstElementDetails gst_osssink_details = GST_ELEMENT_DETAILS (
|
2001-12-17 19:03:13 +00:00
|
|
|
"Audio Sink (OSS)",
|
|
|
|
"Sink/Audio",
|
|
|
|
"Output to a sound card via OSS",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>, "
|
2003-10-31 20:03:30 +00:00
|
|
|
"Wim Taymans <wim.taymans@chello.be>"
|
|
|
|
);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2003-10-31 20:03:30 +00:00
|
|
|
static void gst_osssink_base_init (gpointer g_class);
|
2001-12-17 19:03:13 +00:00
|
|
|
static void gst_osssink_class_init (GstOssSinkClass *klass);
|
|
|
|
static void gst_osssink_init (GstOssSink *osssink);
|
2003-05-10 11:35:59 +00:00
|
|
|
static void gst_osssink_dispose (GObject *object);
|
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-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType* gst_osssink_get_query_types (GstPad *pad);
|
|
|
|
static gboolean gst_osssink_query (GstElement *element, GstQueryType type,
|
2002-06-08 23:45:12 +00:00
|
|
|
GstFormat *format, gint64 *value);
|
2002-12-30 17:53:18 +00:00
|
|
|
static gboolean gst_osssink_sink_query (GstPad *pad, GstQueryType type,
|
2002-06-01 11:00:27 +00:00
|
|
|
GstFormat *format, gint64 *value);
|
|
|
|
|
2003-12-24 03:31:06 +00:00
|
|
|
static GstCaps * gst_osssink_sink_fixate (GstPad *pad, const GstCaps *caps, gpointer user_data);
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstPadLinkReturn gst_osssink_sinkconnect (GstPad *pad, const 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);
|
|
|
|
|
2003-10-08 16:08:18 +00:00
|
|
|
static void gst_osssink_chain (GstPad *pad,GstData *_data);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
/* OssSink signals and args */
|
|
|
|
enum {
|
|
|
|
SIGNAL_HANDOFF,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_MUTE,
|
|
|
|
ARG_FRAGMENT,
|
2002-05-26 23:01:16 +00:00
|
|
|
ARG_BUFFER_SIZE,
|
2003-05-24 10:45:27 +00:00
|
|
|
ARG_SYNC,
|
|
|
|
ARG_CHUNK_SIZE,
|
2001-12-17 19:03:13 +00:00
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate osssink_sink_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE (
|
2001-12-17 19:03:13 +00:00
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
|
|
|
"endianness = (int) BYTE_ORDER, "
|
|
|
|
"signed = (boolean) { TRUE, FALSE }, "
|
|
|
|
"width = (int) { 8, 16 }, "
|
|
|
|
"depth = (int) { 8, 16 }, "
|
|
|
|
"rate = (int) [ 1000, 48000 ], "
|
|
|
|
"channels = (int) [ 1, 2 ]"
|
2001-12-17 19:03:13 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
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),
|
2003-10-31 20:03:30 +00:00
|
|
|
gst_osssink_base_init,
|
2001-12-17 19:03:13 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_osssink_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstOssSink),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_osssink_init,
|
|
|
|
};
|
2003-09-13 01:22:59 +00:00
|
|
|
osssink_type = g_type_register_static (GST_TYPE_OSSELEMENT, "GstOssSink", &osssink_info, 0);
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return osssink_type;
|
|
|
|
}
|
|
|
|
|
2003-05-10 11:35:59 +00:00
|
|
|
static void
|
|
|
|
gst_osssink_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink = (GstOssSink *) object;
|
|
|
|
|
|
|
|
gst_object_unparent (GST_OBJECT (osssink->provided_clock));
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2003-10-31 20:03:30 +00:00
|
|
|
static void
|
|
|
|
gst_osssink_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_osssink_details);
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&osssink_sink_factory));
|
2003-10-31 20:03:30 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
parent_class = g_type_class_ref(GST_TYPE_OSSELEMENT);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-09-02 19:22:35 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MUTE,
|
|
|
|
g_param_spec_boolean ("mute", "Mute", "Mute the audio",
|
2003-07-03 14:35:50 +00:00
|
|
|
FALSE, G_PARAM_READWRITE));
|
2002-09-02 19:22:35 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SYNC,
|
|
|
|
g_param_spec_boolean ("sync", "Sync", "If syncing on timestamps should be enabled",
|
2003-01-19 19:42:18 +00:00
|
|
|
TRUE, G_PARAM_READWRITE));
|
2002-09-02 19:22:35 +00:00
|
|
|
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,
|
2003-07-03 14:35:50 +00:00
|
|
|
g_param_spec_uint ("buffer_size", "Buffer size", "Size of buffers in osssink's bufferpool (bytes)",
|
2003-05-24 10:45:27 +00:00
|
|
|
0, G_MAXINT, 4096, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CHUNK_SIZE,
|
|
|
|
g_param_spec_uint ("chunk_size", "Chunk size", "Write data in chunk sized buffers",
|
|
|
|
0, G_MAXUINT, 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;
|
2003-05-10 11:35:59 +00:00
|
|
|
gobject_class->dispose = gst_osssink_dispose;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
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 (
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_static_pad_template_get (&osssink_sink_factory), "sink");
|
2001-12-17 19:03:13 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (osssink), osssink->sinkpad);
|
2003-01-10 10:22:25 +00:00
|
|
|
gst_pad_set_link_function (osssink->sinkpad, gst_osssink_sinkconnect);
|
2003-12-24 03:31:06 +00:00
|
|
|
gst_pad_set_fixate_function (osssink->sinkpad, gst_osssink_sink_fixate);
|
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->bufsize = 4096;
|
2003-05-24 10:45:27 +00:00
|
|
|
osssink->chunk_size = 4096;
|
2002-05-26 21:59:22 +00:00
|
|
|
osssink->resync = FALSE;
|
2003-07-03 14:35:50 +00:00
|
|
|
osssink->mute = FALSE;
|
2003-01-19 19:42:18 +00:00
|
|
|
osssink->sync = TRUE;
|
2003-07-16 16:08:14 +00:00
|
|
|
osssink->provided_clock = gst_audio_clock_new ("ossclock", gst_osssink_get_time, osssink);
|
2003-05-10 11:35:59 +00:00
|
|
|
gst_object_set_parent (GST_OBJECT (osssink->provided_clock), GST_OBJECT (osssink));
|
2002-05-28 22:52:52 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-12-24 03:31:06 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_osssink_sink_fixate (GstPad *pad, const GstCaps *caps, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstCaps *newcaps;
|
|
|
|
GstStructure *structure;
|
|
|
|
|
|
|
|
structure = gst_structure_copy(gst_caps_get_structure (caps, 0));
|
|
|
|
newcaps = gst_caps_new_full (structure, NULL);
|
|
|
|
|
|
|
|
if (gst_caps_structure_fixate_field_nearest_int (structure, "rate", 44100)) {
|
|
|
|
return newcaps;
|
|
|
|
}
|
|
|
|
if (gst_caps_structure_fixate_field_nearest_int (structure, "depth", 16)) {
|
|
|
|
return newcaps;
|
|
|
|
}
|
|
|
|
if (gst_caps_structure_fixate_field_nearest_int (structure, "width", 16)) {
|
|
|
|
return newcaps;
|
|
|
|
}
|
|
|
|
if (gst_caps_structure_fixate_field_nearest_int (structure, "channels", 2)) {
|
|
|
|
return newcaps;
|
|
|
|
}
|
|
|
|
|
2003-12-24 17:01:00 +00:00
|
|
|
gst_caps_free (newcaps);
|
|
|
|
|
|
|
|
return NULL;
|
2003-12-24 03:31:06 +00:00
|
|
|
}
|
2002-05-28 22:52:52 +00:00
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_osssink_sinkconnect (GstPad *pad, const GstCaps *caps)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
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
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (!gst_osselement_parse_caps (GST_OSSELEMENT (osssink), caps))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (!gst_osselement_sync_parms (GST_OSSELEMENT (osssink))) {
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
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;
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (GST_OSSELEMENT (osssink)->fd == -1)
|
2002-06-01 11:00:27 +00:00
|
|
|
return 0;
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (ioctl (GST_OSSELEMENT (osssink)->fd, SNDCTL_DSP_GETODELAY, &delay) < 0) {
|
2002-05-28 22:52:52 +00:00
|
|
|
audio_buf_info info;
|
2003-09-13 01:22:59 +00:00
|
|
|
if (ioctl (GST_OSSELEMENT (osssink)->fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
|
2002-05-28 22:52:52 +00:00
|
|
|
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;
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (!GST_OSSELEMENT (osssink)->bps)
|
2002-05-28 22:52:52 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-09-13 01:22:59 +00:00
|
|
|
res = (osssink->handled - delay) * GST_SECOND / GST_OSSELEMENT (osssink)->bps;
|
2002-05-28 22:52:52 +00:00
|
|
|
|
|
|
|
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
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_osssink_chain (GstPad *pad, GstData *_data)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
2003-10-08 16:08:18 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-17 19:03:13 +00:00
|
|
|
GstOssSink *osssink;
|
2002-02-03 20:10:04 +00:00
|
|
|
GstClockTime buftime;
|
2003-12-16 22:00:21 +00:00
|
|
|
|
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:
|
2003-09-13 01:22:59 +00:00
|
|
|
ioctl (GST_OSSELEMENT (osssink)->fd, SNDCTL_DSP_SYNC);
|
2003-07-16 16:08:14 +00:00
|
|
|
gst_audio_clock_set_active (GST_AUDIO_CLOCK (osssink->provided_clock), FALSE);
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_pad_event_default (pad, event);
|
|
|
|
return;
|
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
|
|
|
{
|
|
|
|
gint64 value;
|
2003-12-16 22:00:21 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
ioctl (GST_OSSELEMENT (osssink)->fd, SNDCTL_DSP_RESET);
|
2002-05-26 21:59:22 +00:00
|
|
|
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))
|
2003-12-17 22:36:20 +00:00
|
|
|
gst_audio_clock_set_active (GST_AUDIO_CLOCK (osssink->provided_clock), FALSE);
|
2002-05-28 22:52:52 +00:00
|
|
|
osssink->handled = 0;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
2003-12-17 22:36:20 +00:00
|
|
|
osssink->resync = TRUE;
|
2003-12-16 22:00:21 +00:00
|
|
|
|
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
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (!GST_OSSELEMENT (osssink)->bps) {
|
2002-02-17 02:06:04 +00:00
|
|
|
gst_buffer_unref (buf);
|
2003-09-16 10:00:02 +00:00
|
|
|
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);
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (GST_OSSELEMENT (osssink)->fd >= 0) {
|
2002-02-03 20:10:04 +00:00
|
|
|
if (!osssink->mute) {
|
|
|
|
guchar *data = GST_BUFFER_DATA (buf);
|
|
|
|
gint size = GST_BUFFER_SIZE (buf);
|
2003-05-31 14:14:21 +00:00
|
|
|
gint to_write = 0;
|
2002-02-03 20:10:04 +00:00
|
|
|
|
|
|
|
if (osssink->clock) {
|
2002-05-27 23:02:02 +00:00
|
|
|
gint delay = 0;
|
2002-05-26 21:59:22 +00:00
|
|
|
gint64 queued;
|
2003-12-17 22:36:20 +00:00
|
|
|
GstClockTimeDiff jitter;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-05-28 22:52:52 +00:00
|
|
|
delay = gst_osssink_get_delay (osssink);
|
2003-09-13 01:22:59 +00:00
|
|
|
queued = delay * GST_SECOND / GST_OSSELEMENT (osssink)->bps;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-05-26 23:01:16 +00:00
|
|
|
if (osssink->resync && osssink->sync) {
|
2003-12-17 22:36:20 +00:00
|
|
|
GstClockID id = gst_clock_new_single_shot_id (osssink->clock, buftime - queued);
|
|
|
|
|
|
|
|
gst_element_clock_wait (GST_ELEMENT (osssink), id, &jitter);
|
|
|
|
gst_clock_id_free (id);
|
|
|
|
|
|
|
|
if (jitter >= 0) {
|
|
|
|
gst_clock_handle_discont (osssink->clock, buftime - queued + jitter);
|
|
|
|
to_write = size;
|
|
|
|
gst_audio_clock_set_active ((GstAudioClock*)osssink->provided_clock, TRUE);
|
|
|
|
osssink->resync = FALSE;
|
|
|
|
}
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-05-31 14:14:21 +00:00
|
|
|
to_write = 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
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
ioctl (GST_OSSELEMENT (osssink)->fd, SNDCTL_DSP_GETOSPACE, &ospace);
|
2002-02-03 20:10:04 +00:00
|
|
|
|
|
|
|
if (ospace.bytes >= size) {
|
2003-05-31 14:14:21 +00:00
|
|
|
to_write = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (to_write > 0) {
|
2003-09-13 01:22:59 +00:00
|
|
|
gint done = write (GST_OSSELEMENT (osssink)->fd, data,
|
2003-05-31 14:14:21 +00:00
|
|
|
MIN (to_write, osssink->chunk_size));
|
|
|
|
|
|
|
|
if (done == -1) {
|
|
|
|
if (errno != EINTR)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
to_write -= done;
|
|
|
|
data += done;
|
|
|
|
osssink->handled += done;
|
2002-02-03 20:10:04 +00:00
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-12-16 22:00:21 +00:00
|
|
|
|
2003-07-16 16:08:14 +00:00
|
|
|
gst_audio_clock_update_time ((GstAudioClock*)osssink->provided_clock, buftime);
|
2003-07-03 14:35:50 +00:00
|
|
|
|
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,
|
2003-05-24 10:45:27 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
2002-07-24 21:46:03 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink;
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (gst_pad_get_parent (pad));
|
2002-12-07 20:54:47 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
return gst_osselement_convert (GST_OSSELEMENT (osssink),
|
|
|
|
src_format, src_value,
|
|
|
|
dest_format, dest_value);
|
2002-06-01 11:00:27 +00:00
|
|
|
}
|
|
|
|
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType*
|
2002-07-24 21:46:03 +00:00
|
|
|
gst_osssink_get_query_types (GstPad *pad)
|
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType query_types[] = {
|
|
|
|
GST_QUERY_LATENCY,
|
|
|
|
GST_QUERY_POSITION,
|
2002-07-24 21:46:03 +00:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
return query_types;
|
|
|
|
}
|
|
|
|
|
2002-06-01 11:00:27 +00:00
|
|
|
static gboolean
|
2002-12-30 17:53:18 +00:00
|
|
|
gst_osssink_sink_query (GstPad *pad, GstQueryType 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) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_LATENCY:
|
2002-06-01 11:00:27 +00:00
|
|
|
if (!gst_osssink_convert (pad,
|
|
|
|
GST_FORMAT_BYTES, gst_osssink_get_delay (osssink),
|
|
|
|
format, value))
|
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-06-08 23:45:12 +00:00
|
|
|
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
|
2002-12-30 17:53:18 +00:00
|
|
|
gst_osssink_query (GstElement *element, GstQueryType type, GstFormat *format, gint64 *value)
|
2002-06-08 23:45:12 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
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:
|
2003-09-13 01:22:59 +00:00
|
|
|
GST_OSSELEMENT (osssink)->fragment = g_value_get_int (value);
|
|
|
|
gst_osselement_sync_parms (GST_OSSELEMENT (osssink));
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
|
|
|
case ARG_BUFFER_SIZE:
|
2003-05-24 10:45:27 +00:00
|
|
|
osssink->bufsize = g_value_get_uint (value);
|
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;
|
2003-05-24 10:45:27 +00:00
|
|
|
case ARG_CHUNK_SIZE:
|
|
|
|
osssink->chunk_size = g_value_get_uint (value);
|
|
|
|
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;
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_MUTE:
|
|
|
|
g_value_set_boolean (value, osssink->mute);
|
|
|
|
break;
|
|
|
|
case ARG_FRAGMENT:
|
2003-09-13 01:22:59 +00:00
|
|
|
g_value_set_int (value, GST_OSSELEMENT (osssink)->fragment);
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
|
|
|
case ARG_BUFFER_SIZE:
|
2003-05-24 10:45:27 +00:00
|
|
|
g_value_set_uint (value, osssink->bufsize);
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
2002-05-26 23:01:16 +00:00
|
|
|
case ARG_SYNC:
|
|
|
|
g_value_set_boolean (value, osssink->sync);
|
|
|
|
break;
|
2003-05-24 10:45:27 +00:00
|
|
|
case ARG_CHUNK_SIZE:
|
|
|
|
g_value_set_uint (value, osssink->chunk_size);
|
|
|
|
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 GstElementStateReturn
|
|
|
|
gst_osssink_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstOssSink *osssink;
|
|
|
|
|
|
|
|
osssink = GST_OSSSINK (element);
|
|
|
|
|
2001-12-25 02:17:53 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
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-05-04 18:52:32 +00:00
|
|
|
if (GST_FLAG_IS_SET (element, GST_OSSSINK_OPEN))
|
2003-09-13 01:22:59 +00:00
|
|
|
ioctl (GST_OSSELEMENT (osssink)->fd, SNDCTL_DSP_RESET, 0);
|
2003-07-16 16:08:14 +00:00
|
|
|
gst_audio_clock_set_active (GST_AUDIO_CLOCK (osssink->provided_clock), FALSE);
|
2002-05-28 22:52:52 +00:00
|
|
|
osssink->resync = TRUE;
|
2001-12-25 02:17:53 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2002-02-03 20:10:04 +00:00
|
|
|
if (GST_FLAG_IS_SET (element, GST_OSSSINK_OPEN))
|
2003-09-13 01:22:59 +00:00
|
|
|
ioctl (GST_OSSELEMENT (osssink)->fd, SNDCTL_DSP_RESET, 0);
|
|
|
|
gst_osselement_reset (GST_OSSELEMENT (osssink));
|
2001-12-25 02:17:53 +00:00
|
|
|
break;
|
2003-09-13 01:22:59 +00:00
|
|
|
default:
|
2001-12-25 02:17:53 +00:00
|
|
|
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;
|
|
|
|
}
|