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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/soundcard.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <gstosssrc.h>
|
2002-12-07 14:25:18 +00:00
|
|
|
#include <gstosscommon.h>
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-09-18 19:02:51 +00:00
|
|
|
/* elementfactory information */
|
2001-12-17 19:03:13 +00:00
|
|
|
static GstElementDetails gst_osssrc_details = {
|
|
|
|
"Audio Source (OSS)",
|
|
|
|
"Source/Audio",
|
2002-09-18 19:02:51 +00:00
|
|
|
"LGPL",
|
2001-12-17 19:03:13 +00:00
|
|
|
"Read from the sound card",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* OssSrc signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_DEVICE,
|
2002-12-07 20:54:47 +00:00
|
|
|
ARG_BUFFERSIZE,
|
|
|
|
ARG_FRAGMENT,
|
2001-12-17 19:03:13 +00:00
|
|
|
};
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (osssrc_src_factory,
|
2001-12-17 19:03:13 +00:00
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"osssrc_src",
|
|
|
|
"audio/raw",
|
|
|
|
"format", GST_PROPS_STRING ("int"),
|
|
|
|
"law", GST_PROPS_INT (0),
|
|
|
|
"endianness", GST_PROPS_INT (G_BYTE_ORDER),
|
|
|
|
"signed", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_BOOLEAN (TRUE),
|
|
|
|
GST_PROPS_BOOLEAN (FALSE)
|
|
|
|
),
|
|
|
|
"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 void gst_osssrc_class_init (GstOssSrcClass *klass);
|
|
|
|
static void gst_osssrc_init (GstOssSrc *osssrc);
|
|
|
|
|
2002-12-07 14:25:18 +00:00
|
|
|
static GstPadConnectReturn gst_osssrc_srcconnect (GstPad *pad, GstCaps *caps);
|
2002-12-07 20:54:47 +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);
|
|
|
|
|
2002-12-07 14:25:18 +00:00
|
|
|
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);
|
2001-12-17 19:03:13 +00:00
|
|
|
static GstElementStateReturn gst_osssrc_change_state (GstElement *element);
|
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
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);
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType* gst_osssrc_get_query_types (GstPad *pad);
|
|
|
|
static gboolean gst_osssrc_src_query (GstPad *pad, GstQueryType type,
|
2002-12-07 20:54:47 +00:00
|
|
|
GstFormat *format, gint64 *value);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
static GstBuffer * gst_osssrc_get (GstPad *pad);
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
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
|
|
|
|
gst_osssrc_get_type (void)
|
|
|
|
{
|
|
|
|
static GType osssrc_type = 0;
|
|
|
|
|
|
|
|
if (!osssrc_type) {
|
|
|
|
static const GTypeInfo osssrc_info = {
|
|
|
|
sizeof(GstOssSrcClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_osssrc_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstOssSrc),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_osssrc_init,
|
|
|
|
};
|
|
|
|
osssrc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstOssSrc", &osssrc_info, 0);
|
|
|
|
}
|
|
|
|
return osssrc_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osssrc_class_init (GstOssSrcClass *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-12-07 20:54:47 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BUFFERSIZE,
|
|
|
|
g_param_spec_ulong ("buffersize","Buffer Size","The size of the buffers with samples",
|
|
|
|
0, G_MAXULONG, 0, G_PARAM_READWRITE));
|
2001-12-17 19:03:13 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE,
|
2002-12-07 20:54:47 +00:00
|
|
|
g_param_spec_string ("device", "device", "oss device (/dev/dspN usually)",
|
|
|
|
"default", 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));
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_osssrc_set_property;
|
|
|
|
gobject_class->get_property = gst_osssrc_get_property;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_osssrc_change_state;
|
2002-12-06 01:23:41 +00:00
|
|
|
gstelement_class->send_event = gst_osssrc_send_event;
|
2001-12-17 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osssrc_init (GstOssSrc *osssrc)
|
|
|
|
{
|
|
|
|
osssrc->srcpad = gst_pad_new_from_template (
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_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);
|
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
|
|
|
gst_osscommon_init (&osssrc->common);
|
|
|
|
|
|
|
|
osssrc->buffersize = 4096;
|
2001-12-17 19:03:13 +00:00
|
|
|
osssrc->curoffset = 0;
|
|
|
|
}
|
|
|
|
|
2002-12-07 14:25:18 +00:00
|
|
|
static GstPadConnectReturn
|
|
|
|
gst_osssrc_srcconnect (GstPad *pad, GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstOssSrc *src;
|
|
|
|
|
|
|
|
src = GST_OSSSRC(gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (!GST_CAPS_IS_FIXED (caps))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
if (!gst_osscommon_parse_caps (&src->common, caps))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
if (!gst_osscommon_sync_parms (&src->common))
|
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
|
|
|
|
gst_osssrc_negotiate (GstPad *pad)
|
|
|
|
{
|
|
|
|
GstOssSrc *src;
|
|
|
|
GstCaps *allowed;
|
|
|
|
|
|
|
|
src = GST_OSSSRC(gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
allowed = gst_pad_get_allowed_caps (pad);
|
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
if (!gst_osscommon_merge_fixed_caps (&src->common, allowed))
|
|
|
|
return FALSE;
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
if (!gst_osscommon_sync_parms (&src->common))
|
2002-12-07 14:25:18 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* set caps on src pad */
|
|
|
|
if (gst_pad_try_set_caps (src->srcpad,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"oss_src",
|
|
|
|
"audio/raw",
|
|
|
|
"format", GST_PROPS_STRING ("int"),
|
2002-12-07 20:54:47 +00:00
|
|
|
"law", GST_PROPS_INT (src->common.law),
|
|
|
|
"endianness", GST_PROPS_INT (src->common.endianness),
|
|
|
|
"signed", GST_PROPS_BOOLEAN (src->common.sign),
|
|
|
|
"width", GST_PROPS_INT (src->common.width),
|
|
|
|
"depth", GST_PROPS_INT (src->common.depth),
|
|
|
|
"rate", GST_PROPS_INT (src->common.rate),
|
|
|
|
"channels", GST_PROPS_INT (src->common.channels)
|
2002-12-07 14:25:18 +00:00
|
|
|
)) <= 0)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
static GstBuffer *
|
|
|
|
gst_osssrc_get (GstPad *pad)
|
|
|
|
{
|
|
|
|
GstOssSrc *src;
|
|
|
|
GstBuffer *buf;
|
|
|
|
glong readbytes;
|
|
|
|
|
|
|
|
src = GST_OSSSRC(gst_pad_get_parent (pad));
|
|
|
|
|
2002-07-13 23:13:42 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO, "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;
|
|
|
|
return GST_BUFFER (gst_event_new (GST_EVENT_EOS));
|
|
|
|
}
|
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
buf = gst_buffer_new_and_alloc (src->buffersize);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
readbytes = read (src->common.fd,GST_BUFFER_DATA (buf),
|
|
|
|
src->buffersize);
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
if (readbytes == 0) {
|
2002-02-02 16:26:41 +00:00
|
|
|
gst_element_set_eos (GST_ELEMENT (src));
|
2001-12-17 19:03:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-12-07 14:25:18 +00:00
|
|
|
|
2002-02-05 21:58:41 +00:00
|
|
|
if (!GST_PAD_CAPS (pad)) {
|
2002-12-07 14:25:18 +00:00
|
|
|
/* nothing was negotiated, we can decide on a format */
|
|
|
|
if (!gst_osssrc_negotiate (pad)) {
|
|
|
|
gst_element_error (GST_ELEMENT (src), "could not negotiate format");
|
2002-02-05 21:58:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2002-12-07 20:54:47 +00:00
|
|
|
if (src->common.bps == 0) {
|
|
|
|
gst_element_error (GST_ELEMENT (src), "no format negotiated");
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
GST_BUFFER_SIZE (buf) = readbytes;
|
|
|
|
GST_BUFFER_OFFSET (buf) = src->curoffset;
|
2002-12-07 20:54:47 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buf) = src->curoffset * GST_SECOND / src->common.bps;
|
2002-03-02 15:52:46 +00:00
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
src->curoffset += readbytes;
|
|
|
|
|
2002-12-07 14:25:18 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO, "pushed buffer from soundcard of %ld bytes, timestamp %lld",
|
|
|
|
readbytes, GST_BUFFER_TIMESTAMP (buf));
|
|
|
|
|
2001-12-17 19:03:13 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osssrc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
case ARG_DEVICE:
|
2002-12-07 20:54:47 +00:00
|
|
|
g_free(src->common.device);
|
|
|
|
src->common.device = g_strdup (g_value_get_string (value));
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
2002-12-07 20:54:47 +00:00
|
|
|
case ARG_FRAGMENT:
|
|
|
|
src->common.fragment = g_value_get_int (value);
|
|
|
|
gst_osscommon_sync_parms (&src->common);
|
|
|
|
break;
|
2001-12-17 19:03:13 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_osssrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
case ARG_DEVICE:
|
2002-12-07 20:54:47 +00:00
|
|
|
g_value_set_string (value, src->common.device);
|
|
|
|
break;
|
|
|
|
case ARG_FRAGMENT:
|
|
|
|
g_value_set_int (value, src->common.fragment);
|
2001-12-17 19:03:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_osssrc_change_state (GstElement *element)
|
|
|
|
{
|
2002-12-03 00:36:54 +00:00
|
|
|
GstOssSrc *osssrc = GST_OSSSRC (element);
|
2002-02-20 16:23:56 +00:00
|
|
|
|
2002-03-24 22:07:03 +00:00
|
|
|
GST_DEBUG (GST_CAT_PLUGIN_INFO, "osssrc: state change");
|
2002-12-03 00:36:54 +00:00
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
2002-12-07 14:25:18 +00:00
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
if (!GST_FLAG_IS_SET (element, GST_OSSSRC_OPEN)) {
|
2002-12-07 20:54:47 +00:00
|
|
|
gchar *error;
|
|
|
|
if (!gst_osscommon_open_audio (&osssrc->common, GST_OSSCOMMON_READ, &error)) {
|
|
|
|
gst_element_error (GST_ELEMENT (osssrc), error);
|
|
|
|
g_free (error);
|
2002-12-07 14:25:18 +00:00
|
|
|
return GST_STATE_FAILURE;
|
2002-12-07 20:54:47 +00:00
|
|
|
}
|
|
|
|
GST_FLAG_SET (osssrc, GST_OSSSRC_OPEN);
|
2002-12-07 14:25:18 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2002-12-07 20:54:47 +00:00
|
|
|
if (GST_FLAG_IS_SET (element, GST_OSSSRC_OPEN)) {
|
|
|
|
gst_osscommon_close_audio (&osssrc->common);
|
|
|
|
GST_FLAG_UNSET (osssrc, GST_OSSSRC_OPEN);
|
|
|
|
}
|
|
|
|
gst_osscommon_init (&osssrc->common);
|
2002-12-07 14:25:18 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
static const GstFormat*
|
|
|
|
gst_osssrc_get_formats (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstFormat formats[] = {
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
GST_FORMAT_UNITS,
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
2002-12-06 01:23:41 +00:00
|
|
|
static gboolean
|
2002-12-07 20:54:47 +00:00
|
|
|
gst_osssrc_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
GstOssSrc *osssrc;
|
|
|
|
|
|
|
|
osssrc = GST_OSSSRC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
return gst_osscommon_convert (&osssrc->common, src_format, src_value,
|
|
|
|
dest_format, dest_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GstEventMask*
|
|
|
|
gst_osssrc_get_event_masks (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstEventMask gst_osssrc_src_event_masks[] = {
|
|
|
|
{ GST_EVENT_EOS, 0 },
|
|
|
|
{ GST_EVENT_SIZE, 0 },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
return gst_osssrc_src_event_masks;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* convert to bytes */
|
|
|
|
if (gst_osscommon_convert (&osssrc->common,
|
|
|
|
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 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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType*
|
2002-12-07 20:54:47 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
return query_types;
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
|
2002-12-07 20:54:47 +00:00
|
|
|
static gboolean
|
2002-12-30 17:53:18 +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;
|
|
|
|
|
|
|
|
osssrc = GST_OSSSRC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-12-07 20:54:47 +00:00
|
|
|
res = gst_osscommon_convert (&osssrc->common,
|
|
|
|
GST_FORMAT_BYTES, osssrc->curoffset,
|
|
|
|
format, value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2002-12-07 14:25:18 +00:00
|
|
|
}
|
2002-12-07 20:54:47 +00:00
|
|
|
return res;
|
|
|
|
}
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_osssrc_factory_init (GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
2002-12-07 14:25:18 +00:00
|
|
|
factory = gst_element_factory_new ("osssrc",
|
|
|
|
GST_TYPE_OSSSRC,
|
|
|
|
&gst_osssrc_details);
|
2001-12-17 19:03:13 +00:00
|
|
|
g_return_val_if_fail (factory != NULL, FALSE);
|
|
|
|
|
2002-12-07 14:25:18 +00:00
|
|
|
gst_element_factory_add_pad_template (factory,
|
|
|
|
GST_PAD_TEMPLATE_GET (osssrc_src_factory));
|
2001-12-17 19:03:13 +00:00
|
|
|
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|