2001-12-17 19:03:13 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstosssrc.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/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/soundcard.h>
|
|
|
|
#include <sys/ioctl.h>
|
2003-01-27 20:23:55 +00:00
|
|
|
#include <errno.h>
|
2001-12-17 19:03:13 +00:00
|
|
|
#include <unistd.h>
|
2003-01-27 20:23:55 +00:00
|
|
|
#include <string.h>
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
#include <gstosssrc.h>
|
2003-09-13 01:22:59 +00:00
|
|
|
#include <gstosselement.h>
|
2003-07-16 16:08:14 +00:00
|
|
|
#include <gst/audio/audioclock.h>
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-09-18 19:02:51 +00:00
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails gst_osssrc_details =
|
|
|
|
GST_ELEMENT_DETAILS ("Audio Source (OSS)",
|
|
|
|
"Source/Audio",
|
|
|
|
"Read from the sound card",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>");
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* OssSrc signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-17 19:03:13 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-17 19:03:13 +00:00
|
|
|
ARG_0,
|
2002-12-07 20:54:47 +00:00
|
|
|
ARG_BUFFERSIZE,
|
|
|
|
ARG_FRAGMENT,
|
2001-12-17 19:03:13 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstStaticPadTemplate osssrc_src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"endianness = (int) BYTE_ORDER, "
|
|
|
|
"signed = (boolean) { TRUE, FALSE }, "
|
|
|
|
"width = (int) { 8, 16 }, "
|
|
|
|
"depth = (int) { 8, 16 }, "
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
"rate = (int) [ 1, MAX ], " "channels = (int) [ 1, 2 ]")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static void gst_osssrc_base_init (gpointer g_class);
|
|
|
|
static void gst_osssrc_class_init (GstOssSrcClass * klass);
|
|
|
|
static void gst_osssrc_init (GstOssSrc * osssrc);
|
|
|
|
static void gst_osssrc_dispose (GObject * object);
|
|
|
|
|
|
|
|
static GstPadLinkReturn gst_osssrc_srcconnect (GstPad * pad,
|
|
|
|
const GstCaps * caps);
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
static GstCaps *gst_osssrc_getcaps (GstPad * pad);
|
2004-03-14 22:34:33 +00:00
|
|
|
static const GstFormat *gst_osssrc_get_formats (GstPad * pad);
|
|
|
|
static gboolean gst_osssrc_convert (GstPad * pad,
|
|
|
|
GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value);
|
|
|
|
|
|
|
|
static void gst_osssrc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_osssrc_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static GstElementStateReturn gst_osssrc_change_state (GstElement * element);
|
|
|
|
|
|
|
|
static void gst_osssrc_set_clock (GstElement * element, GstClock * clock);
|
|
|
|
static GstClock *gst_osssrc_get_clock (GstElement * element);
|
|
|
|
static GstClockTime gst_osssrc_get_time (GstClock * clock, gpointer data);
|
|
|
|
|
|
|
|
static const GstEventMask *gst_osssrc_get_event_masks (GstPad * pad);
|
|
|
|
static gboolean gst_osssrc_src_event (GstPad * pad, GstEvent * event);
|
|
|
|
static gboolean gst_osssrc_send_event (GstElement * element, GstEvent * event);
|
|
|
|
static const GstQueryType *gst_osssrc_get_query_types (GstPad * pad);
|
|
|
|
static gboolean gst_osssrc_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value);
|
|
|
|
|
|
|
|
static GstData *gst_osssrc_get (GstPad * pad);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-03-19 04:10:05 +00:00
|
|
|
/*static guint gst_osssrc_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
GType
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_get_type (void)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
|
|
|
static GType osssrc_type = 0;
|
|
|
|
|
|
|
|
if (!osssrc_type) {
|
|
|
|
static const GTypeInfo osssrc_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstOssSrcClass),
|
2003-10-31 20:03:30 +00:00
|
|
|
gst_osssrc_base_init,
|
2001-12-17 19:03:13 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) gst_osssrc_class_init,
|
2001-12-17 19:03:13 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstOssSrc),
|
2001-12-17 19:03:13 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_osssrc_init,
|
2001-12-17 19:03:13 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
osssrc_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_OSSELEMENT, "GstOssSrc", &osssrc_info,
|
|
|
|
0);
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
return osssrc_type;
|
|
|
|
}
|
|
|
|
|
2003-10-31 20:03:30 +00:00
|
|
|
static void
|
|
|
|
gst_osssrc_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-10-31 20:03:30 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_osssrc_details);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&osssrc_src_factory));
|
2003-10-31 20:03:30 +00:00
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_class_init (GstOssSrcClass * klass)
|
2001-12-17 19:03:13 +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-17 19:03:13 +00:00
|
|
|
|
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
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BUFFERSIZE,
|
|
|
|
g_param_spec_ulong ("buffersize", "Buffer Size",
|
2004-03-15 19:32:27 +00:00
|
|
|
"The size of the buffers with samples", 0, G_MAXULONG, 0,
|
|
|
|
G_PARAM_READWRITE));
|
2002-12-07 20:54:47 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FRAGMENT,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_int ("fragment", "Fragment",
|
2004-03-15 19:32:27 +00:00
|
|
|
"The fragment as 0xMMMMSSSS (MMMM = total fragments, 2^SSSS = fragment size)",
|
|
|
|
0, G_MAXINT, 6, G_PARAM_READWRITE));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
gobject_class->set_property = gst_osssrc_set_property;
|
|
|
|
gobject_class->get_property = gst_osssrc_get_property;
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class->dispose = gst_osssrc_dispose;
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = gst_osssrc_change_state;
|
2002-12-06 01:23:41 +00:00
|
|
|
gstelement_class->send_event = gst_osssrc_send_event;
|
2003-03-30 21:19:08 +00:00
|
|
|
|
|
|
|
gstelement_class->set_clock = gst_osssrc_set_clock;
|
|
|
|
gstelement_class->get_clock = gst_osssrc_get_clock;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_osssrc_init (GstOssSrc * osssrc)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
osssrc->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&osssrc_src_factory), "src");
|
2002-12-07 14:25:18 +00:00
|
|
|
gst_pad_set_get_function (osssrc->srcpad, gst_osssrc_get);
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
gst_pad_set_getcaps_function (osssrc->srcpad, gst_osssrc_getcaps);
|
2003-01-10 10:22:25 +00:00
|
|
|
gst_pad_set_link_function (osssrc->srcpad, gst_osssrc_srcconnect);
|
2002-12-07 20:54:47 +00:00
|
|
|
gst_pad_set_convert_function (osssrc->srcpad, gst_osssrc_convert);
|
|
|
|
gst_pad_set_formats_function (osssrc->srcpad, gst_osssrc_get_formats);
|
|
|
|
gst_pad_set_event_function (osssrc->srcpad, gst_osssrc_src_event);
|
|
|
|
gst_pad_set_event_mask_function (osssrc->srcpad, gst_osssrc_get_event_masks);
|
|
|
|
gst_pad_set_query_function (osssrc->srcpad, gst_osssrc_src_query);
|
|
|
|
gst_pad_set_query_type_function (osssrc->srcpad, gst_osssrc_get_query_types);
|
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (osssrc), osssrc->srcpad);
|
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
osssrc->buffersize = 4096;
|
2001-12-17 19:03:13 +00:00
|
|
|
osssrc->curoffset = 0;
|
2003-03-30 21:19:08 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
osssrc->provided_clock =
|
|
|
|
gst_audio_clock_new ("ossclock", gst_osssrc_get_time, osssrc);
|
|
|
|
gst_object_set_parent (GST_OBJECT (osssrc->provided_clock),
|
|
|
|
GST_OBJECT (osssrc));
|
|
|
|
|
2003-03-30 21:19:08 +00:00
|
|
|
osssrc->clock = NULL;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-05-10 11:35:59 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_dispose (GObject * object)
|
2003-05-10 11:35:59 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *osssrc = (GstOssSrc *) object;
|
|
|
|
|
|
|
|
gst_object_unparent (GST_OBJECT (osssrc->provided_clock));
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
|
sys/oss/gstosselement.c: Add code to handle rate probing (bug #120883)
Original commit message from CVS:
* sys/oss/gstosselement.c: (gst_osselement_sync_parms),
(gst_osselement_close_audio), (gst_osselement_probe_caps),
(gst_osselement_get_format_structure),
(gst_osselement_rate_probe_check), (gst_osselement_rate_add_range),
(gst_osselement_rate_check_rate), (gst_osselement_rate_add_rate),
(gst_osselement_rate_int_compare): Add code to handle rate probing
(bug #120883)
* sys/oss/gstosselement.h: same
* sys/oss/gstosssink.c: (gst_osssink_init), (gst_osssink_getcaps):
Use rate probing provided by osselement.
* sys/oss/gstosssrc.c: (gst_osssrc_init), (gst_osssrc_getcaps): same
2004-03-25 02:43:48 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_osssrc_getcaps (GstPad * pad)
|
|
|
|
{
|
|
|
|
GstOssSrc *src;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
src = GST_OSSSRC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
gst_osselement_probe_caps (GST_OSSELEMENT (src));
|
|
|
|
|
|
|
|
if (GST_OSSELEMENT (src)->probed_caps == NULL) {
|
|
|
|
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
|
|
|
|
} else {
|
|
|
|
caps = gst_caps_copy (GST_OSSELEMENT (src)->probed_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstPadLinkReturn
|
|
|
|
gst_osssrc_srcconnect (GstPad * pad, const GstCaps * caps)
|
2002-12-07 14:25:18 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *src;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
src = GST_OSSSRC (gst_pad_get_parent (pad));
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (!gst_osselement_parse_caps (GST_OSSELEMENT (src), caps))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (!gst_osselement_sync_parms (GST_OSSELEMENT (src)))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
2002-12-07 14:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_negotiate (GstPad * pad)
|
2002-12-07 14:25:18 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *src;
|
|
|
|
GstCaps *allowed;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
src = GST_OSSSRC (gst_pad_get_parent (pad));
|
2002-12-07 14:25:18 +00:00
|
|
|
|
|
|
|
allowed = gst_pad_get_allowed_caps (pad);
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (!gst_osselement_merge_fixed_caps (GST_OSSELEMENT (src), allowed))
|
2002-12-07 20:54:47 +00:00
|
|
|
return FALSE;
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (!gst_osselement_sync_parms (GST_OSSELEMENT (src)))
|
2002-12-07 14:25:18 +00:00
|
|
|
return FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-12-07 14:25:18 +00:00
|
|
|
/* set caps on src pad */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (gst_pad_try_set_caps (src->srcpad,
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_caps_new_simple ("audio/x-raw-int",
|
|
|
|
"endianness", G_TYPE_INT, GST_OSSELEMENT (src)->endianness,
|
|
|
|
"signed", G_TYPE_BOOLEAN, GST_OSSELEMENT (src)->sign,
|
|
|
|
"width", G_TYPE_INT, GST_OSSELEMENT (src)->width,
|
|
|
|
"depth", G_TYPE_INT, GST_OSSELEMENT (src)->depth,
|
|
|
|
"rate", G_TYPE_INT, GST_OSSELEMENT (src)->rate,
|
|
|
|
"channels", G_TYPE_INT, GST_OSSELEMENT (src)->channels,
|
|
|
|
NULL)) <= 0) {
|
2002-12-07 14:25:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-03-30 21:19:08 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstClockTime
|
|
|
|
gst_osssrc_get_time (GstClock * clock, gpointer data)
|
2003-03-30 21:19:08 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *osssrc = GST_OSSSRC (data);
|
|
|
|
audio_buf_info info;
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
if (!GST_OSSELEMENT (osssrc)->bps)
|
2003-03-30 21:19:08 +00:00
|
|
|
return 0;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (GST_OSSELEMENT (osssrc)->fd, SNDCTL_DSP_GETISPACE, &info) < 0)
|
2003-03-30 21:19:08 +00:00
|
|
|
return 0;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
return (osssrc->curoffset +
|
|
|
|
info.bytes) * GST_SECOND / GST_OSSELEMENT (osssrc)->bps;
|
2003-03-30 21:19:08 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstClock *
|
|
|
|
gst_osssrc_get_clock (GstElement * element)
|
2003-03-30 21:19:08 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *osssrc;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-03-30 21:19:08 +00:00
|
|
|
osssrc = GST_OSSSRC (element);
|
|
|
|
|
|
|
|
return GST_CLOCK (osssrc->provided_clock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_set_clock (GstElement * element, GstClock * clock)
|
2003-03-30 21:19:08 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *osssrc;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-03-30 21:19:08 +00:00
|
|
|
osssrc = GST_OSSSRC (element);
|
|
|
|
|
|
|
|
osssrc->clock = clock;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-10-08 16:08:18 +00:00
|
|
|
static GstData *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_get (GstPad * pad)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *src;
|
|
|
|
GstBuffer *buf;
|
|
|
|
glong readbytes;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
src = GST_OSSSRC (gst_pad_get_parent (pad));
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("attempting to read something from the soundcard");
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-12-06 01:23:41 +00:00
|
|
|
if (src->need_eos) {
|
|
|
|
src->need_eos = FALSE;
|
2003-10-08 16:08:18 +00:00
|
|
|
return GST_DATA (gst_event_new (GST_EVENT_EOS));
|
2002-12-06 01:23:41 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
buf = gst_buffer_new_and_alloc (src->buffersize);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-04-04 21:02:18 +00:00
|
|
|
if (!GST_PAD_CAPS (pad)) {
|
|
|
|
/* nothing was negotiated, we can decide on a format */
|
|
|
|
if (!gst_osssrc_negotiate (pad)) {
|
|
|
|
gst_buffer_unref (buf);
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL), (NULL));
|
2003-10-08 16:08:18 +00:00
|
|
|
return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
|
2003-04-04 21:02:18 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-13 01:22:59 +00:00
|
|
|
if (GST_OSSELEMENT (src)->bps == 0) {
|
2003-04-04 21:02:18 +00:00
|
|
|
gst_buffer_unref (buf);
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("format wasn't negotiated before chain function"));
|
2003-10-08 16:08:18 +00:00
|
|
|
return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
|
2003-04-04 21:02:18 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
readbytes = read (GST_OSSELEMENT (src)->fd, GST_BUFFER_DATA (buf),
|
|
|
|
src->buffersize);
|
2003-01-27 20:23:55 +00:00
|
|
|
if (readbytes < 0) {
|
|
|
|
gst_buffer_unref (buf);
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
|
2003-10-08 16:08:18 +00:00
|
|
|
return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
|
2003-01-27 20:23:55 +00:00
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
if (readbytes == 0) {
|
2003-01-27 20:23:55 +00:00
|
|
|
gst_buffer_unref (buf);
|
2002-02-02 16:26:41 +00:00
|
|
|
gst_element_set_eos (GST_ELEMENT (src));
|
2003-10-08 16:08:18 +00:00
|
|
|
return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
GST_BUFFER_SIZE (buf) = readbytes;
|
|
|
|
GST_BUFFER_OFFSET (buf) = src->curoffset;
|
2003-03-30 21:19:08 +00:00
|
|
|
|
|
|
|
/* FIXME: we are falsely assuming that we are the master clock here */
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buf) =
|
|
|
|
src->curoffset * GST_SECOND / GST_OSSELEMENT (src)->bps;
|
|
|
|
GST_BUFFER_DURATION (buf) =
|
|
|
|
(GST_SECOND * GST_BUFFER_SIZE (buf)) / (GST_OSSELEMENT (src)->bps *
|
|
|
|
GST_OSSELEMENT (src)->rate);
|
2002-03-02 15:52:46 +00:00
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
src->curoffset += readbytes;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("pushed buffer from soundcard of %ld bytes, timestamp %"
|
|
|
|
G_GINT64_FORMAT, readbytes, GST_BUFFER_TIMESTAMP (buf));
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2003-10-08 16:08:18 +00:00
|
|
|
return GST_DATA (buf);
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_osssrc_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *src;
|
|
|
|
|
|
|
|
src = GST_OSSSRC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-12-07 20:54:47 +00:00
|
|
|
case ARG_BUFFERSIZE:
|
|
|
|
src->buffersize = g_value_get_ulong (value);
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
2002-12-07 20:54:47 +00:00
|
|
|
case ARG_FRAGMENT:
|
2003-09-13 01:22:59 +00:00
|
|
|
GST_OSSELEMENT (src)->fragment = g_value_get_int (value);
|
|
|
|
gst_osselement_sync_parms (GST_OSSELEMENT (src));
|
2004-03-14 22:34:33 +00:00
|
|
|
break;
|
2001-12-17 19:03:13 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_osssrc_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *src;
|
|
|
|
|
|
|
|
src = GST_OSSSRC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-12-07 20:54:47 +00:00
|
|
|
case ARG_BUFFERSIZE:
|
|
|
|
g_value_set_ulong (value, src->buffersize);
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
2002-12-07 20:54:47 +00:00
|
|
|
case ARG_FRAGMENT:
|
2003-09-13 01:22:59 +00:00
|
|
|
g_value_set_int (value, GST_OSSELEMENT (src)->fragment);
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_osssrc_change_state (GstElement * element)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
2002-12-03 00:36:54 +00:00
|
|
|
GstOssSrc *osssrc = GST_OSSSRC (element);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("osssrc: state change");
|
2002-12-03 00:36:54 +00:00
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
2003-03-30 21:19:08 +00:00
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
osssrc->curoffset = 0;
|
|
|
|
break;
|
2002-12-07 14:25:18 +00:00
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_audio_clock_set_active (GST_AUDIO_CLOCK (osssrc->provided_clock),
|
2004-03-15 19:32:27 +00:00
|
|
|
TRUE);
|
2002-12-07 14:25:18 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_audio_clock_set_active (GST_AUDIO_CLOCK (osssrc->provided_clock),
|
2004-03-15 19:32:27 +00:00
|
|
|
FALSE);
|
2002-12-07 14:25:18 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2003-03-30 21:19:08 +00:00
|
|
|
if (GST_FLAG_IS_SET (element, GST_OSSSRC_OPEN))
|
2004-03-15 19:32:27 +00:00
|
|
|
ioctl (GST_OSSELEMENT (osssrc)->fd, SNDCTL_DSP_RESET, 0);
|
2003-03-30 21:19:08 +00:00
|
|
|
break;
|
2003-09-13 01:22:59 +00:00
|
|
|
default:
|
2002-12-07 14:25:18 +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);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static const GstFormat *
|
|
|
|
gst_osssrc_get_formats (GstPad * pad)
|
2002-12-07 20:54:47 +00:00
|
|
|
{
|
|
|
|
static const GstFormat formats[] = {
|
|
|
|
GST_FORMAT_TIME,
|
2003-05-24 10:45:27 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
2002-12-07 20:54:47 +00:00
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
0
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
2002-12-06 01:23:41 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_convert (GstPad * pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2002-12-07 20:54:47 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *osssrc;
|
|
|
|
|
|
|
|
osssrc = GST_OSSSRC (gst_pad_get_parent (pad));
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
return gst_osselement_convert (GST_OSSELEMENT (osssrc), src_format, src_value,
|
2004-03-14 22:34:33 +00:00
|
|
|
dest_format, dest_value);
|
2002-12-07 20:54:47 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static const GstEventMask *
|
|
|
|
gst_osssrc_get_event_masks (GstPad * pad)
|
2002-12-07 20:54:47 +00:00
|
|
|
{
|
|
|
|
static const GstEventMask gst_osssrc_src_event_masks[] = {
|
2004-03-14 22:34:33 +00:00
|
|
|
{GST_EVENT_EOS, 0},
|
|
|
|
{GST_EVENT_SIZE, 0},
|
|
|
|
{0,}
|
2002-12-07 20:54:47 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
return gst_osssrc_src_event_masks;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2002-12-07 20:54:47 +00:00
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_src_event (GstPad * pad, GstEvent * event)
|
2002-12-06 01:23:41 +00:00
|
|
|
{
|
|
|
|
GstOssSrc *osssrc;
|
2002-12-07 20:54:47 +00:00
|
|
|
gboolean retval = FALSE;
|
2002-12-06 01:23:41 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
osssrc = GST_OSSSRC (gst_pad_get_parent (pad));
|
2002-12-06 01:23:41 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2002-12-07 14:25:18 +00:00
|
|
|
case GST_EVENT_EOS:
|
|
|
|
osssrc->need_eos = TRUE;
|
|
|
|
retval = TRUE;
|
|
|
|
break;
|
2002-12-07 20:54:47 +00:00
|
|
|
case GST_EVENT_SIZE:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
gint64 value;
|
|
|
|
|
|
|
|
format = GST_FORMAT_BYTES;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
/* convert to bytes */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (gst_osselement_convert (GST_OSSELEMENT (osssrc),
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_EVENT_SIZE_FORMAT (event),
|
|
|
|
GST_EVENT_SIZE_VALUE (event), &format, &value)) {
|
|
|
|
osssrc->buffersize = GST_EVENT_SIZE_VALUE (event);
|
|
|
|
g_object_notify (G_OBJECT (osssrc), "buffersize");
|
|
|
|
retval = TRUE;
|
2002-12-07 20:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-07 14:25:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
2002-12-06 01:23:41 +00:00
|
|
|
}
|
|
|
|
gst_event_unref (event);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_send_event (GstElement * element, GstEvent * event)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
2002-12-07 20:54:47 +00:00
|
|
|
GstOssSrc *osssrc = GST_OSSSRC (element);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
return gst_osssrc_src_event (osssrc->srcpad, event);
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static const GstQueryType *
|
|
|
|
gst_osssrc_get_query_types (GstPad * pad)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType query_types[] = {
|
|
|
|
GST_QUERY_POSITION,
|
2002-12-07 20:54:47 +00:00
|
|
|
0,
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
return query_types;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_osssrc_src_query (GstPad * pad, GstQueryType type, GstFormat * format,
|
|
|
|
gint64 * value)
|
2001-12-17 19:03:13 +00:00
|
|
|
{
|
2002-12-07 20:54:47 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
GstOssSrc *osssrc;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
osssrc = GST_OSSSRC (gst_pad_get_parent (pad));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2004-03-14 22:34:33 +00:00
|
|
|
res = gst_osselement_convert (GST_OSSELEMENT (osssrc),
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_FORMAT_BYTES, osssrc->curoffset, format, value);
|
2002-12-07 20:54:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2002-12-07 14:25:18 +00:00
|
|
|
}
|
2002-12-07 20:54:47 +00:00
|
|
|
return res;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|