mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-13 07:02:53 +00:00
first batch
Original commit message from CVS: first batch
This commit is contained in:
parent
754313ab71
commit
f0bb7eef82
12 changed files with 2315 additions and 0 deletions
5
sys/Makefile.am
Normal file
5
sys/Makefile.am
Normal file
|
@ -0,0 +1,5 @@
|
|||
### use HAVE_ stuff to decide on dirs
|
||||
DIRS=qcam v4l vcdsrc vgasink xvideosink
|
||||
|
||||
DIST_SUBDIRS=qcam v4l vcdsrc vgasink xvideosink
|
||||
|
11
sys/oss/Makefile.am
Normal file
11
sys/oss/Makefile.am
Normal file
|
@ -0,0 +1,11 @@
|
|||
filterdir = $(libdir)/gst
|
||||
|
||||
filter_LTLIBRARIES = libgstossaudio.la libgstosshelper.la
|
||||
|
||||
libgstossaudio_la_SOURCES = gstosssink.c gstosssrc.c gstossaudio.c gstossgst.c
|
||||
libgstossaudio_la_CFLAGS = $(GST_CFLAGS)
|
||||
|
||||
libgstosshelper_la_SOURCES = gstosshelper.c
|
||||
|
||||
noinst_HEADERS = gstosssink.h gstosssrc.h gstossgst.h gstosshelper.h
|
||||
|
37
sys/oss/README
Normal file
37
sys/oss/README
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
|
||||
GStreamer
|
||||
|
||||
|
||||
(------------------------------------)
|
||||
! !
|
||||
sink GstOss src
|
||||
! !
|
||||
! !
|
||||
(------------------------------------)
|
||||
! ^
|
||||
! 500 ! 501
|
||||
V !
|
||||
(------------------------------------)
|
||||
! GstOssHelper !
|
||||
(------------------------------------)
|
||||
! Native OSS APP !
|
||||
! !
|
||||
(------------------------------------)
|
||||
|
||||
|
||||
Port 500 protocol
|
||||
-----------------
|
||||
|
||||
nothing yet
|
||||
|
||||
port 501 protocol
|
||||
-----------------
|
||||
|
||||
1 <N> <N-bytes>
|
||||
N bytes of raw audio data following
|
||||
|
||||
2 <OSS format>
|
||||
|
||||
|
||||
|
47
sys/oss/gstossaudio.c
Normal file
47
sys/oss/gstossaudio.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* Gnome-Streamer
|
||||
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
||||
*
|
||||
* 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 "gstosssink.h"
|
||||
#include "gstosssrc.h"
|
||||
#include "gstossgst.h"
|
||||
|
||||
static gboolean
|
||||
plugin_init (GModule *module, GstPlugin *plugin)
|
||||
{
|
||||
gboolean ret;
|
||||
|
||||
ret = gst_osssink_factory_init (plugin);
|
||||
g_return_val_if_fail (ret == TRUE, FALSE);
|
||||
|
||||
ret = gst_osssrc_factory_init (plugin);
|
||||
g_return_val_if_fail (ret == TRUE, FALSE);
|
||||
|
||||
ret = gst_ossgst_factory_init (plugin);
|
||||
g_return_val_if_fail (ret == TRUE, FALSE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GstPluginDesc plugin_desc = {
|
||||
GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"ossaudio",
|
||||
plugin_init
|
||||
};
|
448
sys/oss/gstossgst.c
Normal file
448
sys/oss/gstossgst.c
Normal file
|
@ -0,0 +1,448 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wim.taymans@chello.be>
|
||||
*
|
||||
* gstossgst.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>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "gstossgst.h"
|
||||
|
||||
#include "gstosshelper.h"
|
||||
|
||||
static GstElementDetails gst_ossgst_details = {
|
||||
"Audio Wrapper (OSS)",
|
||||
"Src/Audio",
|
||||
"Hijacks /dev/dsp to get the output of OSS apps into GStreamer",
|
||||
VERSION,
|
||||
"Wim Taymans <wim.taymans@chello.be>",
|
||||
"(C) 2001",
|
||||
};
|
||||
|
||||
static void gst_ossgst_class_init (GstOssGstClass *klass);
|
||||
static void gst_ossgst_init (GstOssGst *ossgst);
|
||||
|
||||
static GstElementStateReturn gst_ossgst_change_state (GstElement *element);
|
||||
|
||||
static void gst_ossgst_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
|
||||
static void gst_ossgst_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
|
||||
|
||||
static GstBuffer* gst_ossgst_get (GstPad *pad);
|
||||
|
||||
/* OssGst signals and args */
|
||||
enum {
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum {
|
||||
ARG_0,
|
||||
ARG_MUTE,
|
||||
ARG_PROGRAM,
|
||||
/* FILL ME */
|
||||
};
|
||||
|
||||
static GstPadTemplate*
|
||||
ossgst_src_factory (void)
|
||||
{
|
||||
return
|
||||
gst_padtemplate_new (
|
||||
"src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
gst_caps_new (
|
||||
"ossgst_src",
|
||||
"audio/raw",
|
||||
gst_props_new (
|
||||
"format", GST_PROPS_STRING ("int"),
|
||||
"law", GST_PROPS_INT (0),
|
||||
"endianness", GST_PROPS_INT (G_BYTE_ORDER),
|
||||
"signed", GST_PROPS_LIST (
|
||||
GST_PROPS_BOOLEAN (FALSE),
|
||||
GST_PROPS_BOOLEAN (TRUE)
|
||||
),
|
||||
"width", GST_PROPS_LIST (
|
||||
GST_PROPS_INT (8),
|
||||
GST_PROPS_INT (16)
|
||||
),
|
||||
"depth", GST_PROPS_LIST (
|
||||
GST_PROPS_INT (8),
|
||||
GST_PROPS_INT (16)
|
||||
),
|
||||
"rate", GST_PROPS_INT_RANGE (8000, 48000),
|
||||
"channels", GST_PROPS_INT_RANGE (1, 2),
|
||||
NULL)),
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
static GstElementClass *parent_class = NULL;
|
||||
static GstPadTemplate *gst_ossgst_src_template;
|
||||
|
||||
static gchar *plugin_dir = NULL;
|
||||
|
||||
GType
|
||||
gst_ossgst_get_type (void)
|
||||
{
|
||||
static GType ossgst_type = 0;
|
||||
|
||||
if (!ossgst_type) {
|
||||
static const GTypeInfo ossgst_info = {
|
||||
sizeof(GstOssGstClass),
|
||||
NULL,
|
||||
NULL,
|
||||
(GClassInitFunc)gst_ossgst_class_init,
|
||||
NULL,
|
||||
NULL,
|
||||
sizeof(GstOssGst),
|
||||
0,
|
||||
(GInstanceInitFunc)gst_ossgst_init,
|
||||
};
|
||||
ossgst_type = g_type_register_static (GST_TYPE_ELEMENT, "GstOssGst", &ossgst_info, 0);
|
||||
}
|
||||
|
||||
return ossgst_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_ossgst_class_init (GstOssGstClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
gobject_class = (GObjectClass*)klass;
|
||||
gstelement_class = (GstElementClass*)klass;
|
||||
|
||||
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
||||
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MUTE,
|
||||
g_param_spec_boolean("mute","mute","mute",
|
||||
TRUE,G_PARAM_READWRITE)); // CHECKME
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_PROGRAM,
|
||||
g_param_spec_string("command","command","command",
|
||||
NULL, G_PARAM_READWRITE)); // CHECKME
|
||||
|
||||
gobject_class->set_property = gst_ossgst_set_property;
|
||||
gobject_class->get_property = gst_ossgst_get_property;
|
||||
|
||||
gstelement_class->change_state = gst_ossgst_change_state;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_ossgst_init (GstOssGst *ossgst)
|
||||
{
|
||||
ossgst->srcpad = gst_pad_new_from_template (gst_ossgst_src_template, "src");
|
||||
gst_element_add_pad (GST_ELEMENT (ossgst), ossgst->srcpad);
|
||||
|
||||
gst_pad_set_get_function (ossgst->srcpad, gst_ossgst_get);
|
||||
|
||||
ossgst->command = NULL;
|
||||
}
|
||||
|
||||
static GstCaps*
|
||||
gst_ossgst_format_to_caps (gint format, gint stereo, gint rate)
|
||||
{
|
||||
GstCaps *caps = NULL;
|
||||
gint law = 0;
|
||||
gulong endianness = G_BYTE_ORDER;
|
||||
gboolean is_signed = TRUE;
|
||||
gint width = 16;
|
||||
gboolean supported = TRUE;
|
||||
|
||||
GST_DEBUG (0, "have format 0x%08x %d %d\n", format, stereo, rate);
|
||||
|
||||
switch (format) {
|
||||
case AFMT_MU_LAW:
|
||||
law = 1;
|
||||
break;
|
||||
case AFMT_A_LAW:
|
||||
law = 2;
|
||||
break;
|
||||
case AFMT_U8:
|
||||
width = 8;
|
||||
is_signed = FALSE;
|
||||
break;
|
||||
case AFMT_S16_LE:
|
||||
width = 16;
|
||||
endianness = G_LITTLE_ENDIAN;
|
||||
is_signed = TRUE;
|
||||
break;
|
||||
case AFMT_S16_BE:
|
||||
endianness = G_BIG_ENDIAN;
|
||||
width = 16;
|
||||
is_signed = TRUE;
|
||||
break;
|
||||
case AFMT_S8:
|
||||
width = 8;
|
||||
is_signed = TRUE;
|
||||
break;
|
||||
case AFMT_U16_LE:
|
||||
width = 16;
|
||||
endianness = G_LITTLE_ENDIAN;
|
||||
is_signed = FALSE;
|
||||
break;
|
||||
case AFMT_U16_BE:
|
||||
width = 16;
|
||||
endianness = G_BIG_ENDIAN;
|
||||
is_signed = FALSE;
|
||||
break;
|
||||
case AFMT_IMA_ADPCM:
|
||||
case AFMT_MPEG:
|
||||
#ifdef AFMT_AC3
|
||||
case AFMT_AC3:
|
||||
#endif
|
||||
default:
|
||||
supported = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (supported) {
|
||||
caps = gst_caps_new (
|
||||
"ossgst_caps",
|
||||
"audio/raw",
|
||||
gst_props_new (
|
||||
"format", GST_PROPS_STRING ("int"),
|
||||
"law", GST_PROPS_INT (law),
|
||||
"endianness", GST_PROPS_INT (endianness),
|
||||
"signed", GST_PROPS_BOOLEAN (is_signed),
|
||||
"width", GST_PROPS_INT (width),
|
||||
"depth", GST_PROPS_INT (width),
|
||||
"rate", GST_PROPS_INT (rate),
|
||||
"channels", GST_PROPS_INT (stereo?2:1),
|
||||
NULL));
|
||||
}
|
||||
else {
|
||||
g_warning ("gstossgst: program tried to use unsupported format %x\n", format);
|
||||
}
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
static GstBuffer*
|
||||
gst_ossgst_get (GstPad *pad)
|
||||
{
|
||||
GstOssGst *ossgst;
|
||||
GstBuffer *buf = NULL;
|
||||
command cmd;
|
||||
gboolean have_data = FALSE;
|
||||
|
||||
g_return_val_if_fail (pad != NULL, NULL);
|
||||
g_return_val_if_fail (GST_IS_PAD (pad), NULL);
|
||||
|
||||
/* this has to be an audio buffer */
|
||||
ossgst = GST_OSSGST (gst_pad_get_parent (pad));
|
||||
|
||||
while (!have_data) {
|
||||
/* read the command */
|
||||
read (ossgst->fdout[0], &cmd, sizeof (command));
|
||||
|
||||
switch (cmd.id) {
|
||||
case CMD_DATA:
|
||||
buf = gst_buffer_new ();
|
||||
GST_BUFFER_SIZE (buf) = cmd.cmd.length;
|
||||
GST_BUFFER_DATA (buf) = g_malloc (GST_BUFFER_SIZE (buf));
|
||||
|
||||
GST_BUFFER_SIZE (buf) = read (ossgst->fdout[0], GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
||||
have_data = TRUE;
|
||||
break;
|
||||
case CMD_FORMAT:
|
||||
{
|
||||
GstCaps *caps;
|
||||
|
||||
caps = gst_ossgst_format_to_caps (cmd.cmd.format.format,
|
||||
cmd.cmd.format.stereo,
|
||||
cmd.cmd.format.rate);
|
||||
|
||||
gst_pad_set_caps (ossgst->srcpad, caps);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_ossgst_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GstOssGst *ossgst;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail (GST_IS_OSSGST (object));
|
||||
|
||||
ossgst = GST_OSSGST (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_MUTE:
|
||||
ossgst->mute = g_value_get_boolean (value);
|
||||
break;
|
||||
case ARG_PROGRAM:
|
||||
if (ossgst->command)
|
||||
g_free (ossgst->command);
|
||||
ossgst->command = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_ossgst_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GstOssGst *ossgst;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail (GST_IS_OSSGST (object));
|
||||
|
||||
ossgst = GST_OSSGST (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_MUTE:
|
||||
g_value_set_boolean (value, ossgst->mute);
|
||||
break;
|
||||
case ARG_PROGRAM:
|
||||
g_value_set_string (value, ossgst->command);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_ossgst_spawn_process (GstOssGst *ossgst)
|
||||
{
|
||||
static gchar *ld_preload;
|
||||
|
||||
pipe(ossgst->fdin);
|
||||
pipe(ossgst->fdout);
|
||||
|
||||
GST_DEBUG (0, "about to fork\n");
|
||||
|
||||
if((ossgst->childpid = fork()) == -1)
|
||||
{
|
||||
perror("fork");
|
||||
gst_element_error(GST_ELEMENT(ossgst),"forking");
|
||||
return FALSE;
|
||||
}
|
||||
GST_DEBUG (0,"forked %d\n", ossgst->childpid);
|
||||
|
||||
if(ossgst->childpid == 0)
|
||||
{
|
||||
gchar **args;
|
||||
|
||||
GST_DEBUG (0, "fork command %d\n", ossgst->childpid);
|
||||
|
||||
ld_preload = getenv ("LD_PRELOAD");
|
||||
|
||||
if (ld_preload == NULL) {
|
||||
ld_preload = "";
|
||||
}
|
||||
|
||||
ld_preload = g_strconcat (ld_preload, " ", plugin_dir, G_DIR_SEPARATOR_S,
|
||||
"libgstosshelper.so", NULL);
|
||||
|
||||
setenv ("LD_PRELOAD", ld_preload, TRUE);
|
||||
|
||||
// child
|
||||
dup2(ossgst->fdin[0], HELPER_MAGIC_IN); /* set the childs input stream */
|
||||
dup2(ossgst->fdout[1], HELPER_MAGIC_OUT); /* set the childs output stream */
|
||||
|
||||
// split the arguments
|
||||
args = g_strsplit (ossgst->command, " ", 0);
|
||||
|
||||
execvp(args[0], args);
|
||||
|
||||
// will only reach if error
|
||||
perror("exec");
|
||||
gst_element_error(GST_ELEMENT(ossgst),"starting child process");
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
GST_FLAG_SET(ossgst,GST_OSSGST_OPEN);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_ossgst_kill_process (GstOssGst *ossgst)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstElementStateReturn
|
||||
gst_ossgst_change_state (GstElement *element)
|
||||
{
|
||||
g_return_val_if_fail (GST_IS_OSSGST (element), FALSE);
|
||||
|
||||
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
||||
if (GST_FLAG_IS_SET (element, GST_OSSGST_OPEN))
|
||||
gst_ossgst_kill_process (GST_OSSGST (element));
|
||||
} else {
|
||||
if (!GST_FLAG_IS_SET (element, GST_OSSGST_OPEN)) {
|
||||
if (!gst_ossgst_spawn_process (GST_OSSGST (element))) {
|
||||
return GST_STATE_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
||||
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
||||
return GST_STATE_SUCCESS;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_ossgst_factory_init (GstPlugin *plugin)
|
||||
{
|
||||
GstElementFactory *factory;
|
||||
gchar **path;
|
||||
gint i =0;
|
||||
|
||||
// get the path of this plugin, we assume the helper progam lives in the
|
||||
// same directory.
|
||||
path = g_strsplit (plugin->filename, G_DIR_SEPARATOR_S, 0);
|
||||
while (path[i]) {
|
||||
i++;
|
||||
if (path[i] == NULL) {
|
||||
g_free (path[i-1]);
|
||||
path[i-1] = NULL;
|
||||
}
|
||||
}
|
||||
plugin_dir = g_strjoinv (G_DIR_SEPARATOR_S, path);
|
||||
g_strfreev (path);
|
||||
|
||||
factory = gst_elementfactory_new ("ossgst", GST_TYPE_OSSGST, &gst_ossgst_details);
|
||||
g_return_val_if_fail (factory != NULL, FALSE);
|
||||
|
||||
gst_ossgst_src_template = ossgst_src_factory ();
|
||||
gst_elementfactory_add_padtemplate (factory, gst_ossgst_src_template);
|
||||
|
||||
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
87
sys/oss/gstossgst.h
Normal file
87
sys/oss/gstossgst.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wtay@chello.be>
|
||||
*
|
||||
* gstossgst.h:
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_OSSGST_H__
|
||||
#define __GST_OSSGST_H__
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#define GST_TYPE_OSSGST \
|
||||
(gst_ossgst_get_type())
|
||||
#define GST_OSSGST(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OSSGST,GstOssGst))
|
||||
#define GST_OSSGST_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OSSGST,GstOssGstClass))
|
||||
#define GST_IS_OSSGST(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OSSGST))
|
||||
#define GST_IS_OSSGST_CLASS(obj) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OSSGST))
|
||||
|
||||
typedef enum {
|
||||
GST_OSSGST_OPEN = GST_ELEMENT_FLAG_LAST,
|
||||
|
||||
GST_OSSGST_FLAG_LAST = GST_ELEMENT_FLAG_LAST+2,
|
||||
} GstOssGstFlags;
|
||||
|
||||
typedef struct _GstOssGst GstOssGst;
|
||||
typedef struct _GstOssGstClass GstOssGstClass;
|
||||
|
||||
struct _GstOssGst {
|
||||
GstElement element;
|
||||
|
||||
GstPad *srcpad;
|
||||
|
||||
gint fdout[2];
|
||||
gint fdin[2];
|
||||
pid_t childpid;
|
||||
|
||||
/* soundcard state */
|
||||
gboolean mute;
|
||||
gchar *command;
|
||||
};
|
||||
|
||||
struct _GstOssGstClass {
|
||||
GstElementClass parent_class;
|
||||
|
||||
/* signals */
|
||||
};
|
||||
|
||||
GType gst_ossgst_get_type(void);
|
||||
|
||||
gboolean gst_ossgst_factory_init(GstPlugin *plugin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* __GST_OSSGST_H__ */
|
401
sys/oss/gstosshelper.c
Normal file
401
sys/oss/gstosshelper.c
Normal file
|
@ -0,0 +1,401 @@
|
|||
/* Evil evil evil hack to get OSS apps to cooperate with esd
|
||||
* Copyright (C) 1998, 1999 Manish Singh <yosh@gimp.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//#define DSP_DEBUG
|
||||
|
||||
/* This lets you run multiple instances of x11amp by setting the X11AMPNUM
|
||||
environment variable. Only works on glibc2.
|
||||
*/
|
||||
/* #define MULTIPLE_X11AMP */
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
|
||||
#ifdef DSP_DEBUG
|
||||
#define DPRINTF(format, args...) printf(format, ## args)
|
||||
#else
|
||||
#define DPRINTF(format, args...)
|
||||
#endif
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_MACHINE_SOUNDCARD_H
|
||||
# include <machine/soundcard.h>
|
||||
#else
|
||||
# ifdef HAVE_SOUNDCARD_H
|
||||
# include <soundcard.h>
|
||||
# else
|
||||
# include <sys/soundcard.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "gstosshelper.h"
|
||||
|
||||
/* BSDI has this functionality, but not define :() */
|
||||
#if defined(RTLD_NEXT)
|
||||
#define REAL_LIBC RTLD_NEXT
|
||||
#else
|
||||
#define REAL_LIBC ((void *) -1L)
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__bsdi__)
|
||||
typedef unsigned long request_t;
|
||||
#else
|
||||
typedef int request_t;
|
||||
#endif
|
||||
|
||||
static int sndfd = -1;
|
||||
static int new_format = 1;
|
||||
static int fmt = AFMT_S16_LE;
|
||||
static int speed = 44100;
|
||||
static int stereo = 1;
|
||||
|
||||
int
|
||||
open (const char *pathname, int flags, ...)
|
||||
{
|
||||
static int (*func) (const char *, int, mode_t) = NULL;
|
||||
va_list args;
|
||||
mode_t mode;
|
||||
|
||||
if (!func)
|
||||
func = (int (*) (const char *, int, mode_t)) dlsym (REAL_LIBC, "open");
|
||||
|
||||
va_start (args, flags);
|
||||
mode = va_arg (args, mode_t);
|
||||
va_end (args);
|
||||
|
||||
if (!strcmp (pathname, "/dev/dsp")) {
|
||||
DPRINTF ("hijacking /dev/dsp open, and taking it to GStreamer...\n");
|
||||
return (sndfd = HELPER_MAGIC_SNDFD);
|
||||
}
|
||||
return (sndfd = (*func) (pathname, flags, mode));
|
||||
}
|
||||
|
||||
static int
|
||||
dspctl (int fd, request_t request, void *argp)
|
||||
{
|
||||
int *arg = (int *) argp;
|
||||
|
||||
DPRINTF ("hijacking /dev/dsp ioctl, and sending it to GStreamer "
|
||||
"(%d : %x - %p)\n", fd, request, argp);
|
||||
|
||||
switch (request)
|
||||
{
|
||||
case SNDCTL_DSP_RESET:
|
||||
case SNDCTL_DSP_POST:
|
||||
break;
|
||||
|
||||
case SNDCTL_DSP_SETFMT:
|
||||
fmt = *arg;
|
||||
new_format = 1;
|
||||
break;
|
||||
|
||||
case SNDCTL_DSP_SPEED:
|
||||
speed = *arg;
|
||||
new_format = 1;
|
||||
break;
|
||||
|
||||
case SNDCTL_DSP_STEREO:
|
||||
stereo = *arg;
|
||||
new_format = 1;
|
||||
break;
|
||||
|
||||
case SNDCTL_DSP_GETBLKSIZE:
|
||||
*arg = 4096;
|
||||
break;
|
||||
|
||||
case SNDCTL_DSP_GETFMTS:
|
||||
*arg = 0x38;
|
||||
break;
|
||||
|
||||
#ifdef SNDCTL_DSP_GETCAPS
|
||||
case SNDCTL_DSP_GETCAPS:
|
||||
*arg = 0;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SNDCTL_DSP_GETOSPACE:
|
||||
{
|
||||
audio_buf_info *bufinfo = (audio_buf_info *) argp;
|
||||
bufinfo->bytes = 4096;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
DPRINTF ("unhandled /dev/dsp ioctl (%x - %p)\n", request, argp);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
mmap(void *start, size_t length, int prot , int flags, int fd, off_t offset)
|
||||
{
|
||||
static void * (*func) (void *, size_t, int, int, int, off_t) = NULL;
|
||||
|
||||
if (!func)
|
||||
func = (void * (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap");
|
||||
|
||||
if ((fd == sndfd) && (sndfd != -1))
|
||||
{
|
||||
DPRINTF("MMAP: oops... we're in trouble here. /dev/dsp mmap()ed. Not supported yet.\n");
|
||||
errno = EACCES;
|
||||
return (void *)-1; /* Better causing an error than silently not working, in this case */
|
||||
}
|
||||
|
||||
return (*func) (start, length, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
write (int fd, const void *buf, size_t len)
|
||||
{
|
||||
static int (*func) (int, const void *, size_t) = NULL;
|
||||
command cmd;
|
||||
|
||||
if (!func)
|
||||
func = (int (*) (int, const void *, size_t)) dlsym (REAL_LIBC, "write");
|
||||
|
||||
if ((fd != sndfd) || (sndfd == -1))
|
||||
{
|
||||
return (*func) (fd, buf, len);
|
||||
}
|
||||
|
||||
DPRINTF("WRITE: called for %d bytes\n", len);
|
||||
|
||||
if (new_format) {
|
||||
new_format = 0;
|
||||
|
||||
cmd.id = CMD_FORMAT;
|
||||
cmd.cmd.format.format = fmt;
|
||||
cmd.cmd.format.stereo = stereo;
|
||||
cmd.cmd.format.rate = speed;
|
||||
|
||||
(*func) (HELPER_MAGIC_OUT, &cmd, sizeof(command));
|
||||
}
|
||||
cmd.id = CMD_DATA;
|
||||
cmd.cmd.length = len;
|
||||
|
||||
(*func) (HELPER_MAGIC_OUT, &cmd, sizeof(command));
|
||||
(*func) (HELPER_MAGIC_OUT, buf, len);
|
||||
|
||||
//return (*func) (fd, buf, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int
|
||||
select (int n, fd_set *readfds, fd_set *writefds,
|
||||
fd_set *exceptfds, struct timeval *timeout)
|
||||
{
|
||||
static int (*func) (int, fd_set *, fd_set *, fd_set *, struct timeval *) = NULL;
|
||||
|
||||
if (!func)
|
||||
func = (int (*) (int, fd_set *, fd_set *, fd_set *, struct timeval *)) dlsym (REAL_LIBC, "select");
|
||||
|
||||
if (n == sndfd) {
|
||||
DPRINTF ("audiooss: hijacking /dev/dsp select() [output]\n");
|
||||
}
|
||||
|
||||
return (*func) (n, readfds, writefds, exceptfds, timeout);
|
||||
}
|
||||
|
||||
int
|
||||
dup2 (int oldfd, int newfd)
|
||||
{
|
||||
static int (*func) (int, int) = NULL;
|
||||
|
||||
if (!func)
|
||||
func = (int (*) (int, int)) dlsym (REAL_LIBC, "dup2");
|
||||
|
||||
if ((oldfd == sndfd) && (oldfd != -1) && (newfd != -1))
|
||||
{
|
||||
DPRINTF("dup2(%d,%d) (oldfd == sndfd) called\n", oldfd, newfd);
|
||||
|
||||
/* Do not close(newfd) as that would mark it available for reuse by the system -
|
||||
* just tell the program that yes, we got the fd you asked for. Hackish. */
|
||||
sndfd = newfd;
|
||||
return newfd;
|
||||
}
|
||||
return (*func) (oldfd, newfd);
|
||||
}
|
||||
|
||||
int
|
||||
ioctl (int fd, request_t request, ...)
|
||||
{
|
||||
static int (*func) (int, request_t, void *) = NULL;
|
||||
va_list args;
|
||||
void *argp;
|
||||
|
||||
if (!func)
|
||||
func = (int (*) (int, request_t, void *)) dlsym (REAL_LIBC, "ioctl");
|
||||
|
||||
va_start (args, request);
|
||||
argp = va_arg (args, void *);
|
||||
va_end (args);
|
||||
|
||||
if (fd == sndfd)
|
||||
return dspctl (fd, request, argp);
|
||||
|
||||
return (*func) (fd, request, argp);
|
||||
}
|
||||
|
||||
int
|
||||
fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
static int (*func) (int, int, void *) = NULL;
|
||||
va_list args;
|
||||
void *argp;
|
||||
|
||||
if (!func)
|
||||
func = (int (*) (int, int, void *)) dlsym (REAL_LIBC, "fcntl");
|
||||
|
||||
va_start (args, cmd);
|
||||
argp = va_arg (args, void *);
|
||||
va_end (args);
|
||||
|
||||
if ((fd != -1) && (fd == sndfd))
|
||||
{
|
||||
DPRINTF ("hijacking /dev/dsp fcntl() "
|
||||
"(%d : %x - %p)\n", fd, cmd, argp);
|
||||
if (cmd == F_GETFL) return O_RDWR;
|
||||
if (cmd == F_GETFD) return sndfd;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (*func) (fd, cmd, argp);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
close (int fd)
|
||||
{
|
||||
static int (*func) (int) = NULL;
|
||||
|
||||
if (!func)
|
||||
func = (int (*) (int)) dlsym (REAL_LIBC, "close");
|
||||
|
||||
if (fd == sndfd)
|
||||
sndfd = -1;
|
||||
|
||||
return (*func) (fd);
|
||||
}
|
||||
|
||||
#ifdef MULTIPLE_X11AMP
|
||||
|
||||
#include <socketbits.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#define ENVSET "X11AMPNUM"
|
||||
|
||||
int
|
||||
unlink (const char *filename)
|
||||
{
|
||||
static int (*func) (const char *) = NULL;
|
||||
char *num;
|
||||
|
||||
if (!func)
|
||||
func = (int (*) (const char *)) dlsym (REAL_LIBC, "unlink");
|
||||
|
||||
if (!strcmp (filename, "/tmp/X11Amp_CTRL") && (num = getenv (ENVSET)))
|
||||
{
|
||||
char buf[PATH_MAX] = "/tmp/X11Amp_CTRL";
|
||||
strcat (buf, num);
|
||||
return (*func) (buf);
|
||||
}
|
||||
else
|
||||
return (*func) (filename);
|
||||
}
|
||||
|
||||
typedef int (*sa_func_t) (int, struct sockaddr *, int);
|
||||
|
||||
static int
|
||||
sockaddr_mangle (sa_func_t func, int fd, struct sockaddr *addr, int len)
|
||||
{
|
||||
char *num;
|
||||
|
||||
if (!strcmp (((struct sockaddr_un *) addr)->sun_path, "/tmp/X11Amp_CTRL")
|
||||
&& (num = getenv(ENVSET)))
|
||||
{
|
||||
int ret;
|
||||
char buf[PATH_MAX] = "/tmp/X11Amp_CTRL";
|
||||
|
||||
struct sockaddr_un *new_addr = malloc (len);
|
||||
|
||||
strcat (buf, num);
|
||||
memcpy (new_addr, addr, len);
|
||||
strcpy (new_addr->sun_path, buf);
|
||||
|
||||
ret = (*func) (fd, (struct sockaddr *) new_addr, len);
|
||||
|
||||
free (new_addr);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
return (*func) (fd, addr, len);
|
||||
}
|
||||
|
||||
int
|
||||
bind (int fd, struct sockaddr *addr, int len)
|
||||
{
|
||||
static sa_func_t func = NULL;
|
||||
|
||||
if (!func)
|
||||
func = (sa_func_t) dlsym (REAL_LIBC, "bind");
|
||||
return sockaddr_mangle (func, fd, addr, len);
|
||||
}
|
||||
|
||||
int
|
||||
connect (int fd, struct sockaddr *addr, int len)
|
||||
{
|
||||
static sa_func_t func = NULL;
|
||||
|
||||
if (!func)
|
||||
func = (sa_func_t) dlsym (REAL_LIBC, "connect");
|
||||
return sockaddr_mangle (func, fd, addr, len);
|
||||
}
|
||||
|
||||
#endif /* MULTIPLE_X11AMP */
|
||||
|
||||
#else /* __GNUC__ */
|
||||
static char *ident = NULL;
|
||||
|
||||
void
|
||||
nogcc (void)
|
||||
{
|
||||
ident = NULL;
|
||||
}
|
||||
|
||||
#endif /* __GNUC__ */
|
44
sys/oss/gstosshelper.h
Normal file
44
sys/oss/gstosshelper.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* Evil evil evil hack to get OSS apps to cooperate with esd
|
||||
* Copyright (C) 1998, 1999 Manish Singh <yosh@gimp.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __GST_OSSGST_HELPER_H__
|
||||
#define __GST_OSSGST_HELPER_H__
|
||||
|
||||
#define HELPER_MAGIC_IN 500
|
||||
#define HELPER_MAGIC_OUT 501
|
||||
#define HELPER_MAGIC_SNDFD 502
|
||||
|
||||
#define CMD_DATA 1
|
||||
#define CMD_FORMAT 2
|
||||
|
||||
typedef struct {
|
||||
char id;
|
||||
|
||||
union {
|
||||
unsigned int length;
|
||||
struct {
|
||||
int format;
|
||||
int stereo;
|
||||
int rate;
|
||||
} format;
|
||||
} cmd;
|
||||
} command;
|
||||
|
||||
|
||||
#endif /* __GST_OSSGST_HELPER_H__ */
|
626
sys/oss/gstosssink.c
Normal file
626
sys/oss/gstosssink.c
Normal file
|
@ -0,0 +1,626 @@
|
|||
/* 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>
|
||||
|
||||
#include <gstosssink.h>
|
||||
|
||||
static GstElementDetails gst_osssink_details = {
|
||||
"Audio Sink (OSS)",
|
||||
"Sink/Audio",
|
||||
"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);
|
||||
static void gst_osssink_sync_parms (GstOssSink *osssink);
|
||||
static GstElementStateReturn gst_osssink_change_state (GstElement *element);
|
||||
static GstPadNegotiateReturn gst_osssink_negotiate (GstPad *pad, GstCaps **caps, gpointer *user_data);
|
||||
|
||||
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_FORMAT,
|
||||
ARG_CHANNELS,
|
||||
ARG_FREQUENCY,
|
||||
ARG_FRAGMENT,
|
||||
ARG_BUFFER_SIZE
|
||||
/* FILL ME */
|
||||
};
|
||||
|
||||
GST_PADTEMPLATE_FACTORY (osssink_sink_factory,
|
||||
"sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_CAPS_NEW (
|
||||
"osssink_sink",
|
||||
"audio/raw",
|
||||
"format", GST_PROPS_STRING ("int"), // hack
|
||||
"law", GST_PROPS_INT (0),
|
||||
"endianness", GST_PROPS_INT (G_BYTE_ORDER),
|
||||
"signed", GST_PROPS_LIST (
|
||||
GST_PROPS_BOOLEAN (FALSE),
|
||||
GST_PROPS_BOOLEAN (TRUE)
|
||||
),
|
||||
"width", GST_PROPS_LIST (
|
||||
GST_PROPS_INT (8),
|
||||
GST_PROPS_INT (16)
|
||||
),
|
||||
"depth", GST_PROPS_LIST (
|
||||
GST_PROPS_INT (8),
|
||||
GST_PROPS_INT (16)
|
||||
),
|
||||
"rate", GST_PROPS_INT_RANGE (8000, 48000),
|
||||
"channels", GST_PROPS_INT_RANGE (1, 2)
|
||||
)
|
||||
);
|
||||
|
||||
#define GST_TYPE_OSSSINK_CHANNELS (gst_osssink_channels_get_type())
|
||||
static GType
|
||||
gst_osssink_channels_get_type(void) {
|
||||
static GType osssink_channels_type = 0;
|
||||
static GEnumValue osssink_channels[] = {
|
||||
{0, "0", "Silence"},
|
||||
{1, "1", "Mono"},
|
||||
{2, "2", "Stereo"},
|
||||
{0, NULL, NULL},
|
||||
};
|
||||
if (!osssink_channels_type) {
|
||||
osssink_channels_type = g_enum_register_static("GstAudiosinkChannels", osssink_channels);
|
||||
}
|
||||
return osssink_channels_type;
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
|
||||
return oss->sinkpool;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_osssink_finalize (GObject *object)
|
||||
{
|
||||
GstOssSink *osssink = (GstOssSink *) object;
|
||||
|
||||
g_free (osssink->device);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE,
|
||||
g_param_spec_string("device","device","device",
|
||||
"/dev/dsp",G_PARAM_READWRITE)); // CHECKME!
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MUTE,
|
||||
g_param_spec_boolean("mute","mute","mute",
|
||||
TRUE,G_PARAM_READWRITE));
|
||||
|
||||
// it would be nice to show format in symbolic form, oh well
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FORMAT,
|
||||
g_param_spec_int ("format","format","format",
|
||||
0, G_MAXINT, AFMT_S16_LE, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CHANNELS,
|
||||
g_param_spec_enum("channels","channels","channels",
|
||||
GST_TYPE_OSSSINK_CHANNELS,2,G_PARAM_READWRITE));
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FREQUENCY,
|
||||
g_param_spec_int("frequency","frequency","frequency",
|
||||
0,G_MAXINT,44100,G_PARAM_READWRITE));
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FRAGMENT,
|
||||
g_param_spec_int("fragment","fragment","fragment",
|
||||
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","buffer_size",
|
||||
0,G_MAXINT,4096,G_PARAM_READWRITE));
|
||||
|
||||
gst_osssink_signals[SIGNAL_HANDOFF] =
|
||||
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);
|
||||
|
||||
gobject_class->set_property = gst_osssink_set_property;
|
||||
gobject_class->get_property = gst_osssink_get_property;
|
||||
gobject_class->finalize = gst_osssink_finalize;
|
||||
|
||||
gstelement_class->change_state = gst_osssink_change_state;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_osssink_init (GstOssSink *osssink)
|
||||
{
|
||||
osssink->sinkpad = gst_pad_new_from_template (
|
||||
GST_PADTEMPLATE_GET (osssink_sink_factory), "sink");
|
||||
gst_element_add_pad (GST_ELEMENT (osssink), osssink->sinkpad);
|
||||
gst_pad_set_negotiate_function (osssink->sinkpad, gst_osssink_negotiate);
|
||||
gst_pad_set_bufferpool_function (osssink->sinkpad, gst_osssink_get_bufferpool);
|
||||
|
||||
gst_pad_set_chain_function (osssink->sinkpad, gst_osssink_chain);
|
||||
|
||||
osssink->device = g_strdup ("/dev/dsp");
|
||||
osssink->fd = -1;
|
||||
osssink->clock = gst_clock_get_system();
|
||||
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 */
|
||||
gst_clock_register (osssink->clock, GST_OBJECT (osssink));
|
||||
osssink->bufsize = 4096;
|
||||
/* 6 buffers per chunk by default */
|
||||
osssink->sinkpool = gst_buffer_pool_get_default (osssink->bufsize, 6);
|
||||
|
||||
GST_FLAG_SET (osssink, GST_ELEMENT_THREAD_SUGGESTED);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_osssink_parse_caps (GstOssSink *osssink, GstCaps *caps)
|
||||
{
|
||||
gint law, endianness, width, depth;
|
||||
gboolean sign;
|
||||
gint format = -1;
|
||||
|
||||
// deal with the case where there are no props...
|
||||
if (gst_caps_get_props(caps) == NULL) return FALSE;
|
||||
|
||||
width = gst_caps_get_int (caps, "width");
|
||||
depth = gst_caps_get_int (caps, "depth");
|
||||
|
||||
if (width != depth) return FALSE;
|
||||
|
||||
law = gst_caps_get_int (caps, "law");
|
||||
endianness = gst_caps_get_int (caps, "endianness");
|
||||
sign = gst_caps_get_boolean (caps, "signed");
|
||||
|
||||
if (law == 0) {
|
||||
if (width == 16) {
|
||||
if (sign == TRUE) {
|
||||
if (endianness == G_LITTLE_ENDIAN)
|
||||
format = AFMT_S16_LE;
|
||||
else if (endianness == G_BIG_ENDIAN)
|
||||
format = AFMT_S16_BE;
|
||||
}
|
||||
else {
|
||||
if (endianness == G_LITTLE_ENDIAN)
|
||||
format = AFMT_U16_LE;
|
||||
else if (endianness == G_BIG_ENDIAN)
|
||||
format = AFMT_U16_BE;
|
||||
}
|
||||
}
|
||||
else if (width == 8) {
|
||||
if (sign == TRUE) {
|
||||
format = AFMT_S8;
|
||||
}
|
||||
else {
|
||||
format = AFMT_U8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (format == -1)
|
||||
return FALSE;
|
||||
|
||||
osssink->format = format;
|
||||
osssink->channels = gst_caps_get_int (caps, "channels");
|
||||
osssink->frequency = gst_caps_get_int (caps, "rate");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstPadNegotiateReturn
|
||||
gst_osssink_negotiate (GstPad *pad, GstCaps **caps, gpointer *user_data)
|
||||
{
|
||||
GstOssSink *osssink;
|
||||
|
||||
g_return_val_if_fail (pad != NULL, GST_PAD_NEGOTIATE_FAIL);
|
||||
g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_NEGOTIATE_FAIL);
|
||||
|
||||
osssink = GST_OSSSINK (gst_pad_get_parent (pad));
|
||||
|
||||
GST_INFO (GST_CAT_NEGOTIATION, "osssink: negotiate");
|
||||
// we decide
|
||||
if (user_data == NULL) {
|
||||
*caps = NULL;
|
||||
return GST_PAD_NEGOTIATE_TRY;
|
||||
}
|
||||
// have we got caps?
|
||||
else if (*caps) {
|
||||
|
||||
if (gst_osssink_parse_caps (osssink, *caps)) {
|
||||
gst_osssink_sync_parms (osssink);
|
||||
|
||||
return GST_PAD_NEGOTIATE_AGREE;
|
||||
}
|
||||
|
||||
// FIXME check if the sound card was really set to these caps,
|
||||
// else send out another caps..
|
||||
|
||||
return GST_PAD_NEGOTIATE_FAIL;
|
||||
}
|
||||
|
||||
return GST_PAD_NEGOTIATE_FAIL;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_osssink_sync_parms (GstOssSink *osssink)
|
||||
{
|
||||
audio_buf_info ospace;
|
||||
int frag;
|
||||
|
||||
g_return_if_fail (osssink != NULL);
|
||||
g_return_if_fail (GST_IS_OSSSINK (osssink));
|
||||
|
||||
if (osssink->fd == -1) return;
|
||||
|
||||
if (osssink->fragment >> 16)
|
||||
frag = osssink->fragment;
|
||||
else
|
||||
frag = 0x7FFF0000 | osssink->fragment;
|
||||
|
||||
ioctl (osssink->fd, SNDCTL_DSP_SETFRAGMENT, &frag);
|
||||
|
||||
ioctl (osssink->fd, SNDCTL_DSP_RESET, 0);
|
||||
|
||||
ioctl (osssink->fd, SNDCTL_DSP_SETFMT, &osssink->format);
|
||||
ioctl (osssink->fd, SNDCTL_DSP_CHANNELS, &osssink->channels);
|
||||
ioctl (osssink->fd, SNDCTL_DSP_SPEED, &osssink->frequency);
|
||||
|
||||
ioctl (osssink->fd, SNDCTL_DSP_GETBLKSIZE, &frag);
|
||||
ioctl (osssink->fd, SNDCTL_DSP_GETOSPACE, &ospace);
|
||||
|
||||
/*
|
||||
g_warning ("osssink: setting sound card to %dHz %d bit %s (%d bytes buffer, %d fragment)\n",
|
||||
osssink->frequency, osssink->format,
|
||||
(osssink->channels == 2) ? "stereo" : "mono", ospace.bytes, frag);
|
||||
*/
|
||||
GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: setting sound card to %dHz %d bit %s (%d bytes buffer, %d fragment)",
|
||||
osssink->frequency, osssink->format,
|
||||
(osssink->channels == 2) ? "stereo" : "mono", ospace.bytes, frag);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
gst_osssink_chain (GstPad *pad, GstBuffer *buf)
|
||||
{
|
||||
GstOssSink *osssink;
|
||||
gboolean in_flush;
|
||||
audio_buf_info ospace;
|
||||
|
||||
g_return_if_fail (pad != NULL);
|
||||
g_return_if_fail (GST_IS_PAD (pad));
|
||||
g_return_if_fail (buf != NULL);
|
||||
|
||||
|
||||
/* this has to be an audio buffer */
|
||||
osssink = GST_OSSSINK (gst_pad_get_parent (pad));
|
||||
// g_return_if_fail(GST_FLAG_IS_SET(osssink,GST_STATE_RUNNING));
|
||||
|
||||
if (GST_IS_EVENT (buf)) {
|
||||
g_print ("eos on osssink\n");
|
||||
gst_element_set_state (osssink, GST_STATE_PAUSED);
|
||||
gst_event_free (GST_EVENT (buf));
|
||||
}
|
||||
|
||||
if ((in_flush = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLUSH))) {
|
||||
GST_DEBUG (GST_CAT_PLUGIN_INFO,"osssink: flush\n");
|
||||
ioctl (osssink->fd, SNDCTL_DSP_RESET, 0);
|
||||
}
|
||||
|
||||
g_signal_emit (G_OBJECT (osssink), gst_osssink_signals[SIGNAL_HANDOFF], 0,
|
||||
osssink);
|
||||
|
||||
if (GST_BUFFER_DATA (buf) != NULL) {
|
||||
#ifndef GST_DISABLE_TRACE
|
||||
gst_trace_add_entry(NULL, 0, buf, "osssink: writing to soundcard");
|
||||
#endif // GST_DISABLE_TRACE
|
||||
//g_print("osssink: writing to soundcard\n");
|
||||
if (osssink->fd >= 0) {
|
||||
if (!osssink->mute) {
|
||||
gst_clock_wait (osssink->clock, GST_BUFFER_TIMESTAMP (buf), GST_OBJECT (osssink));
|
||||
ioctl (osssink->fd, SNDCTL_DSP_GETOSPACE, &ospace);
|
||||
GST_DEBUG (GST_CAT_PLUGIN_INFO,"osssink: (%d bytes buffer) %d %p %d\n", ospace.bytes,
|
||||
osssink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
||||
write (osssink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
||||
//write(STDOUT_FILENO,GST_BUFFER_DATA(buf),GST_BUFFER_SIZE(buf));
|
||||
}
|
||||
}
|
||||
}
|
||||
gst_buffer_unref (buf);
|
||||
}
|
||||
|
||||
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:
|
||||
osssink->device = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
case ARG_MUTE:
|
||||
osssink->mute = g_value_get_boolean (value);
|
||||
break;
|
||||
case ARG_FORMAT:
|
||||
osssink->format = g_value_get_int (value);
|
||||
gst_osssink_sync_parms (osssink);
|
||||
break;
|
||||
case ARG_CHANNELS:
|
||||
osssink->channels = g_value_get_enum (value);
|
||||
gst_osssink_sync_parms (osssink);
|
||||
break;
|
||||
case ARG_FREQUENCY:
|
||||
osssink->frequency = g_value_get_int (value);
|
||||
gst_osssink_sync_parms (osssink);
|
||||
break;
|
||||
case ARG_FRAGMENT:
|
||||
osssink->fragment = g_value_get_int (value);
|
||||
gst_osssink_sync_parms (osssink);
|
||||
break;
|
||||
case ARG_BUFFER_SIZE:
|
||||
osssink->bufsize = g_value_get_int (value);
|
||||
osssink->sinkpool = gst_buffer_pool_get_default (osssink->bufsize, 6);
|
||||
break;
|
||||
default:
|
||||
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_FORMAT:
|
||||
g_value_set_int (value, osssink->format);
|
||||
break;
|
||||
case ARG_CHANNELS:
|
||||
g_value_set_enum (value, osssink->channels);
|
||||
break;
|
||||
case ARG_FREQUENCY:
|
||||
g_value_set_int (value, osssink->frequency);
|
||||
break;
|
||||
case ARG_FRAGMENT:
|
||||
g_value_set_int (value, osssink->fragment);
|
||||
break;
|
||||
case ARG_BUFFER_SIZE:
|
||||
g_value_set_int (value, osssink->bufsize);
|
||||
break;
|
||||
default:
|
||||
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 */
|
||||
sink->fd = open(sink->device, O_WRONLY | O_NONBLOCK);
|
||||
if (errno == EBUSY) {
|
||||
g_warning ("osssink: unable to open the sound device (in use ?)\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* re-open the sound device in blocking mode */
|
||||
close(sink->fd);
|
||||
sink->fd = open(sink->device, O_WRONLY);
|
||||
|
||||
/* if we have it, set the default parameters and go have fun */
|
||||
if (sink->fd >= 0) {
|
||||
/* set card state */
|
||||
ioctl(sink->fd, SNDCTL_DSP_GETCAPS, &caps);
|
||||
|
||||
GST_INFO(GST_CAT_PLUGIN_INFO, "osssink: Capabilities %08x", caps);
|
||||
|
||||
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");
|
||||
|
||||
#ifdef DSP_CAP_MULTI
|
||||
if (caps & DSP_CAP_MULTI) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Multiple open");
|
||||
#endif /* DSP_CAP_MULTI */
|
||||
|
||||
#ifdef DSP_CAP_BIND
|
||||
if (caps & DSP_CAP_BIND) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: Channel binding");
|
||||
#endif /* DSP_CAP_BIND */
|
||||
|
||||
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");
|
||||
#ifdef AFMT_AC3
|
||||
if (caps & AFMT_AC3) GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: AC3");
|
||||
#endif
|
||||
|
||||
GST_INFO (GST_CAT_PLUGIN_INFO, "osssink: opened audio (%s) with fd=%d", sink->device, sink->fd);
|
||||
GST_FLAG_SET (sink, GST_OSSSINK_OPEN);
|
||||
|
||||
gst_osssink_sync_parms (sink);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* if going down into NULL state, close the file if it's open */
|
||||
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
||||
if (GST_FLAG_IS_SET (element, GST_OSSSINK_OPEN))
|
||||
gst_osssink_close_audio (osssink);
|
||||
|
||||
/* otherwise (READY) we need to open the sound card */
|
||||
} else if (GST_STATE_PENDING (element) == GST_STATE_READY) {
|
||||
if (!GST_FLAG_IS_SET (element, GST_OSSSINK_OPEN)) {
|
||||
if (!gst_osssink_open_audio (osssink)) {
|
||||
return GST_STATE_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
factory = gst_elementfactory_new ("osssink", GST_TYPE_OSSSINK, &gst_osssink_details);
|
||||
g_return_val_if_fail (factory != NULL, FALSE);
|
||||
|
||||
gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (osssink_sink_factory));
|
||||
|
||||
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
96
sys/oss/gstosssink.h
Normal file
96
sys/oss/gstosssink.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wtay@chello.be>
|
||||
*
|
||||
* gstosssink.h:
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_OSSSINK_H__
|
||||
#define __GST_OSSSINK_H__
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#define GST_TYPE_OSSSINK \
|
||||
(gst_osssink_get_type())
|
||||
#define GST_OSSSINK(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OSSSINK,GstOssSink))
|
||||
#define GST_OSSSINK_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OSSSINK,GstOssSinkClass))
|
||||
#define GST_IS_OSSSINK(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OSSSINK))
|
||||
#define GST_IS_OSSSINK_CLASS(obj) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OSSSINK))
|
||||
|
||||
typedef enum {
|
||||
GST_OSSSINK_OPEN = GST_ELEMENT_FLAG_LAST,
|
||||
|
||||
GST_OSSSINK_FLAG_LAST = GST_ELEMENT_FLAG_LAST+2,
|
||||
} GstOssSinkFlags;
|
||||
|
||||
typedef struct _GstOssSink GstOssSink;
|
||||
typedef struct _GstOssSinkClass GstOssSinkClass;
|
||||
|
||||
struct _GstOssSink {
|
||||
GstElement element;
|
||||
|
||||
GstPad *sinkpad;
|
||||
GstBufferPool *sinkpool;
|
||||
|
||||
//GstClockTime clocktime;
|
||||
GstClock *clock;
|
||||
|
||||
/* device */
|
||||
gchar *device;
|
||||
|
||||
/* soundcard state */
|
||||
int fd;
|
||||
int caps; /* the capabilities */
|
||||
gint format;
|
||||
gint channels;
|
||||
gint frequency;
|
||||
gint fragment;
|
||||
gboolean mute;
|
||||
guint bufsize;
|
||||
};
|
||||
|
||||
struct _GstOssSinkClass {
|
||||
GstElementClass parent_class;
|
||||
|
||||
/* signals */
|
||||
void (*handoff) (GstElement *element,GstPad *pad);
|
||||
};
|
||||
|
||||
GType gst_osssink_get_type(void);
|
||||
|
||||
gboolean gst_osssink_factory_init(GstPlugin *plugin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* __GST_OSSSINK_H__ */
|
419
sys/oss/gstosssrc.c
Normal file
419
sys/oss/gstosssrc.c
Normal file
|
@ -0,0 +1,419 @@
|
|||
/* 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>
|
||||
|
||||
//#define WEIRD_THING /* show the weird thing with 44100 KHz rec */
|
||||
|
||||
static GstElementDetails gst_osssrc_details = {
|
||||
"Audio Source (OSS)",
|
||||
"Source/Audio",
|
||||
"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,
|
||||
ARG_BYTESPERREAD,
|
||||
ARG_CUROFFSET,
|
||||
ARG_FORMAT,
|
||||
ARG_CHANNELS,
|
||||
ARG_FREQUENCY
|
||||
};
|
||||
|
||||
GST_PADTEMPLATE_FACTORY (osssrc_src_factory,
|
||||
"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)
|
||||
),
|
||||
"rate", GST_PROPS_INT_RANGE (8000, 48000),
|
||||
"channels", GST_PROPS_INT_RANGE (1, 2)
|
||||
)
|
||||
)
|
||||
|
||||
static void gst_osssrc_class_init (GstOssSrcClass *klass);
|
||||
static void gst_osssrc_init (GstOssSrc *osssrc);
|
||||
|
||||
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_close_audio (GstOssSrc *src);
|
||||
static gboolean gst_osssrc_open_audio (GstOssSrc *src);
|
||||
static void gst_osssrc_sync_parms (GstOssSrc *osssrc);
|
||||
|
||||
static GstBuffer * gst_osssrc_get (GstPad *pad);
|
||||
|
||||
static GstElementClass *parent_class = NULL;
|
||||
//static guint gst_osssrc_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
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);
|
||||
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BYTESPERREAD,
|
||||
g_param_spec_ulong("bytes_per_read","bytes_per_read","bytes_per_read",
|
||||
0,G_MAXULONG,0,G_PARAM_READWRITE)); // CHECKME
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CUROFFSET,
|
||||
g_param_spec_ulong("curoffset","curoffset","curoffset",
|
||||
0,G_MAXULONG,0,G_PARAM_READABLE)); // CHECKME
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FORMAT,
|
||||
g_param_spec_int("format","format","format",
|
||||
G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); // CHECKME
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CHANNELS,
|
||||
g_param_spec_int("channels","channels","channels",
|
||||
G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); // CHECKME
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FREQUENCY,
|
||||
g_param_spec_int("frequency","frequency","frequency",
|
||||
G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); // CHECKME
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE,
|
||||
g_param_spec_string("device","device","oss device (/dev/dspN usually)",
|
||||
"default",G_PARAM_READWRITE));
|
||||
|
||||
gobject_class->set_property = gst_osssrc_set_property;
|
||||
gobject_class->get_property = gst_osssrc_get_property;
|
||||
|
||||
gstelement_class->change_state = gst_osssrc_change_state;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_osssrc_init (GstOssSrc *osssrc)
|
||||
{
|
||||
osssrc->srcpad = gst_pad_new_from_template (
|
||||
GST_PADTEMPLATE_GET (osssrc_src_factory), "src");
|
||||
gst_pad_set_get_function(osssrc->srcpad,gst_osssrc_get);
|
||||
gst_element_add_pad (GST_ELEMENT (osssrc), osssrc->srcpad);
|
||||
|
||||
osssrc->device = g_strdup ("/dev/dsp");
|
||||
osssrc->fd = -1;
|
||||
|
||||
/* adding some default values */
|
||||
osssrc->format = AFMT_S16_LE;
|
||||
osssrc->channels = 2;
|
||||
osssrc->frequency = 44100;
|
||||
|
||||
osssrc->bytes_per_read = 4096;
|
||||
osssrc->curoffset = 0;
|
||||
osssrc->seq = 0;
|
||||
}
|
||||
|
||||
static GstBuffer *
|
||||
gst_osssrc_get (GstPad *pad)
|
||||
{
|
||||
GstOssSrc *src;
|
||||
GstBuffer *buf;
|
||||
glong readbytes;
|
||||
|
||||
g_return_val_if_fail (pad != NULL, NULL);
|
||||
src = GST_OSSSRC(gst_pad_get_parent (pad));
|
||||
|
||||
GST_DEBUG (0, "attempting to read something from soundcard\n");
|
||||
|
||||
buf = gst_buffer_new ();
|
||||
g_return_val_if_fail (buf, NULL);
|
||||
|
||||
GST_BUFFER_DATA (buf) = (gpointer)g_malloc (src->bytes_per_read);
|
||||
|
||||
readbytes = read (src->fd,GST_BUFFER_DATA (buf),
|
||||
src->bytes_per_read);
|
||||
|
||||
if (readbytes == 0) {
|
||||
gst_element_signal_eos (GST_ELEMENT (src));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GST_BUFFER_SIZE (buf) = readbytes;
|
||||
GST_BUFFER_OFFSET (buf) = src->curoffset;
|
||||
|
||||
src->curoffset += readbytes;
|
||||
|
||||
GST_DEBUG (0, "pushed buffer from soundcard of %ld bytes\n", readbytes);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_osssrc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GstOssSrc *src;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail (GST_IS_OSSSRC (object));
|
||||
|
||||
src = GST_OSSSRC (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_BYTESPERREAD:
|
||||
src->bytes_per_read = g_value_get_ulong (value);
|
||||
break;
|
||||
case ARG_FORMAT:
|
||||
src->format = g_value_get_int (value);
|
||||
break;
|
||||
case ARG_CHANNELS:
|
||||
src->channels = g_value_get_int (value);
|
||||
break;
|
||||
case ARG_FREQUENCY:
|
||||
src->frequency = g_value_get_int (value);
|
||||
break;
|
||||
case ARG_CUROFFSET:
|
||||
src->curoffset = g_value_get_int (value);
|
||||
break;
|
||||
case ARG_DEVICE:
|
||||
g_free(src->device);
|
||||
src->device = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_osssrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GstOssSrc *src;
|
||||
|
||||
/* it's not null if we got it, but it might not be ours */
|
||||
g_return_if_fail (GST_IS_OSSSRC (object));
|
||||
|
||||
src = GST_OSSSRC (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case ARG_BYTESPERREAD:
|
||||
g_value_set_ulong (value, src->bytes_per_read);
|
||||
break;
|
||||
case ARG_FORMAT:
|
||||
g_value_set_int (value, src->format);
|
||||
break;
|
||||
case ARG_CHANNELS:
|
||||
g_value_set_int (value, src->channels);
|
||||
break;
|
||||
case ARG_FREQUENCY:
|
||||
g_value_set_int (value, src->frequency);
|
||||
break;
|
||||
case ARG_CUROFFSET:
|
||||
g_value_set_ulong (value, src->curoffset);
|
||||
break;
|
||||
case ARG_DEVICE:
|
||||
g_value_set_string (value, src->device);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static GstElementStateReturn
|
||||
gst_osssrc_change_state (GstElement *element)
|
||||
{
|
||||
g_return_val_if_fail (GST_IS_OSSSRC (element), FALSE);
|
||||
GST_DEBUG (0, "osssrc: state change\n");
|
||||
/* if going down into NULL state, close the file if it's open */
|
||||
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
||||
if (GST_FLAG_IS_SET (element, GST_OSSSRC_OPEN))
|
||||
gst_osssrc_close_audio (GST_OSSSRC (element));
|
||||
/* otherwise (READY or higher) we need to open the sound card */
|
||||
} else {
|
||||
GST_DEBUG (0, "DEBUG: osssrc: ready or higher\n");
|
||||
|
||||
if (!GST_FLAG_IS_SET (element, GST_OSSSRC_OPEN)) {
|
||||
if (!gst_osssrc_open_audio (GST_OSSSRC (element)))
|
||||
return GST_STATE_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
||||
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
||||
|
||||
return GST_STATE_SUCCESS;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_osssrc_open_audio (GstOssSrc *src)
|
||||
{
|
||||
g_return_val_if_fail (!GST_FLAG_IS_SET (src, GST_OSSSRC_OPEN), FALSE);
|
||||
|
||||
/* first try to open the sound card */
|
||||
src->fd = open(src->device, O_RDONLY);
|
||||
|
||||
/* if we have it, set the default parameters and go have fun */
|
||||
if (src->fd > 0) {
|
||||
|
||||
/* set card state */
|
||||
gst_osssrc_sync_parms (src);
|
||||
GST_DEBUG (0,"opened audio: %s\n",src->device);
|
||||
|
||||
GST_FLAG_SET (src, GST_OSSSRC_OPEN);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_osssrc_close_audio (GstOssSrc *src)
|
||||
{
|
||||
g_return_if_fail (GST_FLAG_IS_SET (src, GST_OSSSRC_OPEN));
|
||||
|
||||
close(src->fd);
|
||||
src->fd = -1;
|
||||
|
||||
GST_FLAG_UNSET (src, GST_OSSSRC_OPEN);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_osssrc_sync_parms (GstOssSrc *osssrc)
|
||||
{
|
||||
audio_buf_info ispace;
|
||||
gint frag;
|
||||
/* hack : ioctl on frequency seems to *change* the frequency
|
||||
maybe this is right, but at least for 44100 Khz, it
|
||||
gives unexpected results ! */
|
||||
|
||||
guint frequency;
|
||||
|
||||
g_return_if_fail (osssrc != NULL);
|
||||
g_return_if_fail (GST_IS_OSSSRC (osssrc));
|
||||
g_return_if_fail (osssrc->fd > 0);
|
||||
|
||||
frequency = osssrc->frequency;
|
||||
|
||||
frag = 0x7fff0006;
|
||||
|
||||
ioctl(osssrc->fd, SNDCTL_DSP_SETFRAGMENT, &frag);
|
||||
ioctl(osssrc->fd, SNDCTL_DSP_RESET, 0);
|
||||
|
||||
ioctl(osssrc->fd, SNDCTL_DSP_SETFMT, &osssrc->format);
|
||||
ioctl(osssrc->fd, SNDCTL_DSP_CHANNELS, &osssrc->channels);
|
||||
#ifdef WEIRD_THING
|
||||
g_print ("DEBUG: do you want to see A Weird Thing (TM) ?\n");
|
||||
g_print ("DEBUG: then set osssrc to a 44100 frequency and check these numbers.\n");
|
||||
g_print ("DEBUG: osssrc frequency before ioctl: %d\n", osssrc->frequency);
|
||||
#endif
|
||||
ioctl(osssrc->fd, SNDCTL_DSP_SPEED, &osssrc->frequency);
|
||||
#ifdef WEIRD_THING
|
||||
g_print ("DEBUG: osssrc frequency after ioctl : %d\n", osssrc->frequency);
|
||||
g_print ("DEBUG: redoing ioctl using a temp variable, and resetting osssrc->frequency\n");
|
||||
osssrc->frequency = frequency;
|
||||
ioctl(osssrc->fd, SNDCTL_DSP_SPEED, &frequency);
|
||||
#endif
|
||||
ioctl(osssrc->fd, SNDCTL_DSP_GETISPACE, &ispace);
|
||||
ioctl(osssrc->fd, SNDCTL_DSP_GETBLKSIZE, &frag);
|
||||
|
||||
g_print("setting sound card to %dKHz %d bit %s (%d bytes buffer, %d fragment)\n",
|
||||
osssrc->frequency, osssrc->format,
|
||||
(osssrc->channels == 2) ? "stereo" : "mono", ispace.bytes, frag);
|
||||
|
||||
/* set caps on src pad */
|
||||
gst_pad_set_caps (osssrc->srcpad, gst_caps_new (
|
||||
"oss_src",
|
||||
"audio/raw",
|
||||
gst_props_new (
|
||||
"format", GST_PROPS_STRING ("int"),
|
||||
"law", GST_PROPS_INT (0), //FIXME
|
||||
"endianness", GST_PROPS_INT (G_BYTE_ORDER), //FIXME
|
||||
"signed", GST_PROPS_BOOLEAN (TRUE), //FIXME
|
||||
"width", GST_PROPS_INT (osssrc->format),
|
||||
"depth", GST_PROPS_INT (osssrc->format),
|
||||
"rate", GST_PROPS_INT (osssrc->frequency),
|
||||
"channels", GST_PROPS_INT (osssrc->channels),
|
||||
NULL
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_osssrc_factory_init (GstPlugin *plugin)
|
||||
{
|
||||
GstElementFactory *factory;
|
||||
|
||||
factory = gst_elementfactory_new ("osssrc", GST_TYPE_OSSSRC, &gst_osssrc_details);
|
||||
g_return_val_if_fail (factory != NULL, FALSE);
|
||||
|
||||
gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (osssrc_src_factory));
|
||||
|
||||
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
94
sys/oss/gstosssrc.h
Normal file
94
sys/oss/gstosssrc.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* 2000 Wim Taymans <wtay@chello.be>
|
||||
*
|
||||
* gstosssrc.h:
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_OSSSRC_H__
|
||||
#define __GST_OSSSRC_H__
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#define GST_TYPE_OSSSRC \
|
||||
(gst_osssrc_get_type())
|
||||
#define GST_OSSSRC(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OSSSRC,GstOssSrc))
|
||||
#define GST_OSSSRC_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OSSSRC,GstOssSrcClass))
|
||||
#define GST_IS_OSSSRC(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OSSSRC))
|
||||
#define GST_IS_OSSSRC_CLASS(obj) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OSSSRC))
|
||||
|
||||
typedef enum {
|
||||
GST_OSSSRC_OPEN = GST_ELEMENT_FLAG_LAST,
|
||||
|
||||
GST_OSSSRC_FLAG_LAST = GST_ELEMENT_FLAG_LAST+2,
|
||||
} GstOssSrcFlags;
|
||||
|
||||
typedef struct _GstOssSrc GstOssSrc;
|
||||
typedef struct _GstOssSrcClass GstOssSrcClass;
|
||||
|
||||
struct _GstOssSrc {
|
||||
GstElement element;
|
||||
|
||||
/* pads */
|
||||
GstPad *srcpad;
|
||||
|
||||
/* device */
|
||||
gchar *device;
|
||||
|
||||
/* sound card */
|
||||
gint fd;
|
||||
|
||||
/* audio parameters */
|
||||
gint format;
|
||||
gint channels;
|
||||
gint frequency;
|
||||
|
||||
/* blocking */
|
||||
gulong curoffset;
|
||||
gulong bytes_per_read;
|
||||
|
||||
gulong seq;
|
||||
};
|
||||
|
||||
struct _GstOssSrcClass {
|
||||
GstElementClass parent_class;
|
||||
};
|
||||
|
||||
GType gst_osssrc_get_type(void);
|
||||
|
||||
gboolean gst_osssrc_factory_init (GstPlugin *plugin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* __GST_OSSSRC_H__ */
|
Loading…
Reference in a new issue