Commit 6fc2023e authored by Andy Wingo's avatar Andy Wingo

sys/oss/: Port from THREADED+wim's fixes.

Original commit message from CVS:
2005-07-08  Andy Wingo  <wingo@pobox.com>

* sys/oss/: Port from THREADED+wim's fixes.
parent 266b8744
2005-07-08 Andy Wingo <wingo@pobox.com>
* sys/oss/: Port from THREADED+wim's fixes.
* gst/avi/Makefile.am (libgstavi_la_CFLAGS): No gettext hacks, the
defines come from config.h.
......
......@@ -4,11 +4,11 @@
# DXR3_DIR=
# endif
# if USE_OSS
# OSS_DIR=oss
# else
if USE_OSS
OSS_DIR=oss
else
OSS_DIR=
# endif
endif
# if USE_OSX_AUDIO
# OSX_AUDIO_DIR=osxaudio
......@@ -34,12 +34,6 @@ OSS_DIR=
# SUNAUDIO_DIR=
# endif
# if USE_GST_V4L
# V4L_DIR=v4l
# else
# V4L_DIR=
# endif
# if USE_GST_V4L2
# V4L2_DIR=v4l2
# else
......
plugin_LTLIBRARIES = libgstossaudio.la
libgstossaudio_la_SOURCES = gstossaudio.c \
gstosselement.c \
gstosselement.c \
gstosshelper.c \
gstossmixer.c \
gstosssink.c \
gstosssrc.c
gstosssink.c
libgstossaudio_la_CFLAGS = $(GST_CFLAGS)
libgstossaudio_la_LIBADD = $(top_builddir)/gst-libs/gst/libgstinterfaces-@GST_MAJORMINOR@.la
libgstossaudio_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(GST_PLUGINS_BASE_LIBS)
# gstossdmabuffer.c
noinst_HEADERS = gstosssink.h \
gstosssrc.h \
gstosselement.h\
gstossmixer.h \
gst-i18n-plugin.h \
gettext.h
libgstossaudio_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
libgstossaudio_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) \
-lgstinterfaces-@GST_MAJORMINOR@ \
-lgstaudio-@GST_MAJORMINOR@
libgstossaudio_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_PROGRAMS = oss_probe
noinst_HEADERS = gstosssink.h \
gstosssrc.h \
gstosselement.h \
gstosshelper.h \
gstossdmabuffer.h \
gstossmixer.h
oss_probe_SOURCES = oss_probe.c
oss_probe_CFLAGS = $(GST_CFLAGS)
oss_probe_LDADD = $(GLIB_LIBS)
# noinst_PROGRAMS = #oss_probe
# oss_probe_SOURCES = oss_probe.c
# oss_probe_CFLAGS = $(GST_CFLAGS)
# oss_probe_LDADD = $(GLIB_LIBS)
......@@ -21,7 +21,7 @@
#include "config.h"
#endif
#include "gst-i18n-plugin.h"
#include "gst/gst-i18n-plugin.h"
#include "gstosselement.h"
#include "gstosssink.h"
......@@ -34,13 +34,10 @@ GST_DEBUG_CATEGORY (oss_debug);
static gboolean
plugin_init (GstPlugin * plugin)
{
if (!gst_library_load ("gstaudio"))
return FALSE;
if (!gst_element_register (plugin, "ossmixer", GST_RANK_PRIMARY,
GST_TYPE_OSSELEMENT) ||
!gst_element_register (plugin, "osssrc", GST_RANK_PRIMARY,
GST_TYPE_OSSSRC) ||
if ( /*!gst_element_register (plugin, "ossmixer", GST_RANK_PRIMARY,
GST_TYPE_OSSELEMENT) ||
!gst_element_register (plugin, "osssrc", GST_RANK_PRIMARY,
GST_TYPE_OSSSRC) || */
!gst_element_register (plugin, "osssink", GST_RANK_PRIMARY,
GST_TYPE_OSSSINK)) {
return FALSE;
......
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2005 Wim Taymans <wim@fluendo.com>
*
* gstossdmabuffer.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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/soundcard.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <pthread.h>
#include "gstossdmabuffer.h"
static void gst_ossdmabuffer_class_init (GstOssDMABufferClass * klass);
static void gst_ossdmabuffer_init (GstOssDMABuffer * ossdmabuffer);
static void gst_ossdmabuffer_dispose (GObject * object);
static void gst_ossdmabuffer_finalize (GObject * object);
static gboolean gst_ossdmabuffer_acquire (GstRingBuffer * buf,
GstRingBufferSpec * spec);
static gboolean gst_ossdmabuffer_release (GstRingBuffer * buf);
static gboolean gst_ossdmabuffer_play (GstRingBuffer * buf);
static gboolean gst_ossdmabuffer_stop (GstRingBuffer * buf);
static GstRingBufferClass *parent_class = NULL;
GType
gst_ossdmabuffer_get_type (void)
{
static GType ossdmabuffer_type = 0;
if (!ossdmabuffer_type) {
static const GTypeInfo ossdmabuffer_info = {
sizeof (GstOssDMABufferClass),
NULL,
NULL,
(GClassInitFunc) gst_ossdmabuffer_class_init,
NULL,
NULL,
sizeof (GstOssDMABuffer),
0,
(GInstanceInitFunc) gst_ossdmabuffer_init,
NULL
};
ossdmabuffer_type =
g_type_register_static (GST_TYPE_RINGBUFFER, "GstOssDMABuffer",
&ossdmabuffer_info, 0);
}
return ossdmabuffer_type;
}
static void
gst_ossdmabuffer_class_init (GstOssDMABufferClass * klass)
{
GObjectClass *gobject_class;
GstObjectClass *gstobject_class;
GstRingBufferClass *gstringbuffer_class;
gobject_class = (GObjectClass *) klass;
gstobject_class = (GstObjectClass *) klass;
gstringbuffer_class = (GstRingBufferClass *) klass;
parent_class = g_type_class_ref (GST_TYPE_RINGBUFFER);
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ossdmabuffer_dispose);
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_ossdmabuffer_finalize);
gstringbuffer_class->acquire = gst_ossdmabuffer_acquire;
gstringbuffer_class->release = gst_ossdmabuffer_release;
gstringbuffer_class->play = gst_ossdmabuffer_play;
gstringbuffer_class->stop = gst_ossdmabuffer_stop;
}
static void
gst_ossdmabuffer_init (GstOssDMABuffer * ossdmabuffer)
{
ossdmabuffer->cond = g_cond_new ();
ossdmabuffer->element = g_object_new (GST_TYPE_OSSELEMENT, NULL);
}
static void
gst_ossdmabuffer_dispose (GObject * object)
{
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gst_ossdmabuffer_finalize (GObject * object)
{
GstOssDMABuffer *obuf = (GstOssDMABuffer *) object;
g_cond_free (obuf->cond);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_ossdmabuffer_func (GstRingBuffer * buf)
{
fd_set writeset;
struct count_info count;
GstOssDMABuffer *obuf = (GstOssDMABuffer *) buf;
GST_LOCK (buf);
while (obuf->running) {
if (buf->state == GST_RINGBUFFER_STATE_PLAYING) {
int segsize;
GST_UNLOCK (buf);
segsize = buf->spec.segsize;
FD_ZERO (&writeset);
FD_SET (obuf->fd, &writeset);
select (obuf->fd + 1, NULL, &writeset, NULL, NULL);
if (ioctl (obuf->fd, SNDCTL_DSP_GETOPTR, &count) == -1) {
perror ("GETOPTR");
continue;
}
if (count.blocks > buf->spec.segtotal)
count.blocks = buf->spec.segtotal;
gst_ringbuffer_callback (buf, count.blocks);
GST_LOCK (buf);
} else {
GST_OSSDMABUFFER_SIGNAL (obuf);
GST_OSSDMABUFFER_WAIT (obuf);
}
}
GST_UNLOCK (buf);
}
static gboolean
gst_ossdmabuffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
{
int tmp;
struct audio_buf_info info;
GstOssDMABuffer *obuf = (GstOssDMABuffer *) buf;;
caddr_t mmap_buf;
int mode;
gint size;
gboolean parsed;
parsed = gst_osselement_parse_caps (obuf->element, spec->caps);
if (!parsed)
return FALSE;
mode = O_RDWR;
mode |= O_NONBLOCK;
obuf->fd = open ("/dev/dsp", mode, 0);
if (obuf->fd == -1) {
perror ("OPEN");
return FALSE;
}
//obuf->frag = 0x00040008;
obuf->frag = 0xffff000a;
tmp = obuf->element->format;
if (ioctl (obuf->fd, SNDCTL_DSP_SETFMT, &tmp) == -1) {
perror ("SETFMT");
return FALSE;
}
tmp = obuf->element->channels;
if (ioctl (obuf->fd, SNDCTL_DSP_STEREO, &tmp) == -1) {
perror ("STEREO");
return FALSE;
}
tmp = obuf->element->channels;
if (ioctl (obuf->fd, SNDCTL_DSP_CHANNELS, &tmp) == -1) {
perror ("CHANNELS");
return FALSE;
}
tmp = obuf->element->rate;
if (ioctl (obuf->fd, SNDCTL_DSP_SPEED, &tmp) == -1) {
perror ("SPEED");
return FALSE;
}
if (ioctl (obuf->fd, SNDCTL_DSP_GETCAPS, &obuf->caps) == -1) {
perror ("/dev/dsp");
fprintf (stderr, "Sorry but your sound driver is too old\n");
return FALSE;
}
if (!(obuf->caps & DSP_CAP_TRIGGER) || !(obuf->caps & DSP_CAP_MMAP)) {
fprintf (stderr, "Sorry but your soundcard can't do this\n");
return FALSE;
}
if (ioctl (obuf->fd, SNDCTL_DSP_SETFRAGMENT, &obuf->frag) == -1) {
perror ("SETFRAGMENT");
return FALSE;
}
if (ioctl (obuf->fd, SNDCTL_DSP_GETOSPACE, &info) == -1) {
perror ("GETOSPACE");
return FALSE;
}
buf->spec.segsize = info.fragsize;
buf->spec.segtotal = info.fragstotal;
size = info.fragsize * info.fragstotal;
g_print ("segsize %d, segtotal %d\n", info.fragsize, info.fragstotal);
mmap_buf = (caddr_t) mmap (NULL, size, PROT_WRITE,
MAP_FILE | MAP_SHARED, obuf->fd, 0);
if ((caddr_t) mmap_buf == (caddr_t) - 1) {
perror ("mmap (write)");
return FALSE;
}
buf->data = gst_buffer_new ();
GST_BUFFER_DATA (buf->data) = mmap_buf;
GST_BUFFER_SIZE (buf->data) = size;
GST_BUFFER_FLAG_SET (buf->data, GST_BUFFER_DONTFREE);
tmp = 0;
if (ioctl (obuf->fd, SNDCTL_DSP_SETTRIGGER, &tmp) == -1) {
perror ("SETTRIGGER");
return FALSE;
}
GST_LOCK (obuf);
obuf->running = TRUE;
obuf->thread = g_thread_create ((GThreadFunc) gst_ossdmabuffer_func,
buf, TRUE, NULL);
GST_OSSDMABUFFER_WAIT (obuf);
GST_UNLOCK (obuf);
return TRUE;
}
static gboolean
gst_ossdmabuffer_release (GstRingBuffer * buf)
{
GstOssDMABuffer *obuf = (GstOssDMABuffer *) buf;;
gst_buffer_unref (buf->data);
GST_LOCK (obuf);
obuf->running = FALSE;
GST_OSSDMABUFFER_SIGNAL (obuf);
GST_UNLOCK (obuf);
g_thread_join (obuf->thread);
return TRUE;
}
static gboolean
gst_ossdmabuffer_play (GstRingBuffer * buf)
{
int tmp;
GstOssDMABuffer *obuf;
obuf = (GstOssDMABuffer *) buf;
tmp = PCM_ENABLE_OUTPUT;
if (ioctl (obuf->fd, SNDCTL_DSP_SETTRIGGER, &tmp) == -1) {
perror ("SETTRIGGER");
}
GST_OSSDMABUFFER_SIGNAL (obuf);
return TRUE;
}
static gboolean
gst_ossdmabuffer_stop (GstRingBuffer * buf)
{
int tmp;
GstOssDMABuffer *obuf;
obuf = (GstOssDMABuffer *) buf;
tmp = 0;
if (ioctl (obuf->fd, SNDCTL_DSP_SETTRIGGER, &tmp) == -1) {
perror ("SETTRIGGER");
}
GST_OSSDMABUFFER_WAIT (obuf);
buf->playseg = 0;
return TRUE;
}
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2005 Wim Taymans <wim@fluendo.com>
*
* gstossdmabuffer.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_OSSDMABUFFER_H__
#define __GST_OSSDMABUFFER_H__
#include <gst/gst.h>
#include "gstosselement.h"
#include <gst/audio/gstringbuffer.h>
G_BEGIN_DECLS
#define GST_TYPE_OSSDMABUFFER (gst_ossdmabuffer_get_type())
#define GST_OSSDMABUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OSSDMABUFFER,GstOssDMABuffer))
#define GST_OSSDMABUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OSSDMABUFFER,GstOssDMABufferClass))
#define GST_IS_OSSDMABUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OSSDMABUFFER))
#define GST_IS_OSSDMABUFFER_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OSSDMABUFFER))
#define GST_OSSELEMENT_GET(obj) GST_OSSELEMENT (obj->element)
typedef enum {
GST_OSSDMABUFFER_OPEN = (1 << 0),
} GstOssDMABufferFlags;
typedef struct _GstOssDMABuffer GstOssDMABuffer;
typedef struct _GstOssDMABufferClass GstOssDMABufferClass;
#define GST_OSSDMABUFFER_THREAD(buf) (GST_OSSDMABUFFER(buf)->thread)
#define GST_OSSDMABUFFER_LOCK GST_LOCK
#define GST_OSSDMABUFFER_UNLOCK GST_UNLOCK
#define GST_OSSDMABUFFER_COND(buf) (GST_OSSDMABUFFER(buf)->cond)
#define GST_OSSDMABUFFER_SIGNAL(buf) (g_cond_signal (GST_OSSDMABUFFER_COND (buf)))
#define GST_OSSDMABUFFER_WAIT(buf) (g_cond_wait (GST_OSSDMABUFFER_COND (buf), GST_GET_LOCK (buf)))
struct _GstOssDMABuffer {
GstRingBuffer buffer;
GstOssElement *element;
int fd;
int caps;
int frag;
GThread *thread;
GCond *cond;
gboolean running;
};
struct _GstOssDMABufferClass {
GstRingBufferClass parent_class;
};
GType gst_ossdmabuffer_get_type(void);
G_END_DECLS
#endif /* __GST_OSSDMABUFFER_H__ */
This diff is collapsed.
......@@ -26,9 +26,7 @@
#include <gst/gst.h>
#include <sys/types.h>
/* debugging category */
GST_DEBUG_CATEGORY_EXTERN (oss_debug);
#define GST_CAT_DEFAULT oss_debug
#include "gstosshelper.h"
G_BEGIN_DECLS
......@@ -48,16 +46,6 @@ G_BEGIN_DECLS
typedef struct _GstOssElement GstOssElement;
typedef struct _GstOssElementClass GstOssElementClass;
typedef enum {
GST_OSSELEMENT_READ,
GST_OSSELEMENT_WRITE,
} GstOssOpenMode;
typedef struct _GstOssDeviceCombination {
gchar *dsp, *mixer;
dev_t dev;
} GstOssDeviceCombination;
struct _GstOssElement
{
/* yes, we're a gstelement too */
......@@ -73,7 +61,6 @@ struct _GstOssElement
gint fragment;
guint64 fragment_time;
gint fragment_size;
GstOssOpenMode mode;
GstCaps *probed_caps;
/* stats bytes per *second* */
......@@ -90,6 +77,7 @@ struct _GstOssElement
gint depth;
gint channels;
gint rate;
gint mode;
/* mixer stuff */
GList *tracklist;
......@@ -115,8 +103,12 @@ gboolean gst_osselement_parse_caps (GstOssElement *oss,
gboolean gst_osselement_merge_fixed_caps (GstOssElement *oss,
GstCaps *caps);
gboolean gst_osselement_open_audio (GstOssElement *oss, GstOssOpenMode mode);
gboolean gst_osselement_sync_parms (GstOssElement *oss);
void gst_osselement_reset (GstOssElement *oss);
void gst_osselement_close_audio (GstOssElement *oss);
gboolean gst_osselement_convert (GstOssElement *oss,
GstFormat src_format,
......
......@@ -30,22 +30,9 @@
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#ifdef HAVE_OSS_INCLUDE_IN_SYS
#include <sys/soundcard.h>
#else
#ifdef HAVE_OSS_INCLUDE_IN_ROOT
#include <soundcard.h>
#else
#include <machine/soundcard.h>
#endif /* HAVE_OSS_INCLUDE_IN_ROOT */
#endif /* HAVE_OSS_INCLUDE_IN_SYS */
#include <gst-i18n-plugin.h>
#include <gst/gst-i18n-plugin.h>
#include "gstossmixer.h"
......@@ -202,7 +189,7 @@ gst_ossmixer_track_init (GstOssMixerTrack * track)
}
GstMixerTrack *
gst_ossmixer_track_new (GstOssElement * oss,
gst_ossmixer_track_new (GstOssDevice * oss,
gint track_num, gint max_chans, gint flags)
{
GstOssMixerTrack *osstrack;
......@@ -258,14 +245,17 @@ gst_ossmixer_interface_init (GstMixerClass * klass)
static gboolean
gst_ossmixer_supported (GstImplementsInterface * iface, GType iface_type)
{
GstOssDevice *oss = g_object_get_data (G_OBJECT (iface), "oss-data");
g_return_val_if_fail (oss != NULL, FALSE);
g_assert (iface_type == GST_TYPE_MIXER);
return (GST_OSSELEMENT (iface)->mixer_fd != -1);
return (oss->mixer_fd != -1);
}
/* unused with G_DISABLE_* */
static G_GNUC_UNUSED gboolean
gst_ossmixer_contains_track (GstOssElement * oss, GstOssMixerTrack * osstrack)
gst_ossmixer_contains_track (GstOssDevice * oss, GstOssMixerTrack * osstrack)
{
const GList *item;
......@@ -279,7 +269,9 @@ gst_ossmixer_contains_track (GstOssElement * oss, GstOssMixerTrack * osstrack)
static const GList *
gst_ossmixer_list_tracks (GstMixer * mixer)
{
return (const GList *) GST_OSSELEMENT (mixer)->tracklist;
GstOssDevice *oss = g_object_get_data (G_OBJECT (mixer), "oss-data");
return (const GList *) oss->tracklist;
}
static void
......@@ -287,10 +279,11 @@ gst_ossmixer_get_volume (GstMixer * mixer,
GstMixerTrack * track, gint * volumes)
{
gint volume;
GstOssElement *oss = GST_OSSELEMENT (mixer);
GstOssDevice *oss = g_object_get_data (G_OBJECT (mixer), "oss-data");
GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
/* assert that we're opened and that we're using a known item */
g_return_if_fail (oss != NULL);
g_return_if_fail (oss->mixer_fd != -1);
g_return_if_fail (gst_ossmixer_contains_track (oss, osstrack));
......@@ -319,10 +312,11 @@ gst_ossmixer_set_volume (GstMixer * mixer,
GstMixerTrack * track, gint * volumes)
{
gint volume;
GstOssElement *oss = GST_OSSELEMENT (mixer);
GstOssDevice *oss = g_object_get_data (G_OBJECT (mixer), "oss-data");
GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
/* assert that we're opened and that we're using a known item */
g_return_if_fail (oss != NULL);
g_return_if_fail (oss->mixer_fd != -1);
g_return_if_fail (gst_ossmixer_contains_track (oss, osstrack));
......@@ -351,10 +345,11 @@ static void
gst_ossmixer_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
{
int volume;
GstOssElement *oss = GST_OSSELEMENT (mixer);
GstOssDevice *oss = g_object_get_data (G_OBJECT (mixer), "oss-data");
GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
/* assert that we're opened and that we're using a known item */
g_return_if_fail (oss != NULL);
g_return_if_fail (oss->mixer