sys/oss/gstossmixer.*: Refactored to be more like alsamixer.

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

* sys/oss/gstossmixer.h:
* sys/oss/gstossmixer.c: Refactored to be more like alsamixer.

* sys/oss/gstossmixertrack.h:
* sys/oss/gstossmixertrack.c: Split out from gstossmixer.[ch],
like gstalsamixer.

* sys/oss/gstosssrc.c:
* sys/oss/gstosssink.c: Where before we used a gstosselement
object as a helper library, now just call functions from
gstosshelper.

* sys/oss/gstosshelper.h:
* sys/oss/gstosshelper.c: Made a real library. Removed
propertyprobe for now, should add it back later.

* sys/oss/gstosselement.h:
* sys/oss/gstosselement.c: Removed, we don't have a shared base
class.

* sys/oss/gstosshelper.c (gst_oss_helper_probe_caps): Search
higher-to-lower, makes 16 bit appear earlier in the caps, which
makes it preferred.
This commit is contained in:
Andy Wingo 2005-08-23 13:26:21 +00:00
parent ffaaa7528a
commit d1d21600f8
15 changed files with 614 additions and 2824 deletions

View file

@ -1,9 +1,9 @@
plugin_LTLIBRARIES = libgstossaudio.la
libgstossaudio_la_SOURCES = gstossaudio.c \
gstosselement.c \
gstosshelper.c \
gstossmixer.c \
gstossmixertrack.c \
gstosssink.c \
gstosssrc.c
@ -17,10 +17,10 @@ libgstossaudio_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstosssink.h \
gstosssrc.h \
gstosselement.h \
gstosshelper.h \
gstossdmabuffer.h \
gstossmixer.h
gstossmixer.h \
gstossmixertrack.h
# noinst_PROGRAMS = #oss_probe

View file

@ -23,7 +23,6 @@
#include "gst/gst-i18n-plugin.h"
#include "gstosselement.h"
#include "gstosssink.h"
#include "gstosssrc.h"

View file

@ -25,7 +25,7 @@
#include <gst/gst.h>
#include "gstosselement.h"
#include "gstosshelper.h"
#include <gst/audio/gstringbuffer.h>
G_BEGIN_DECLS

File diff suppressed because it is too large Load diff

View file

@ -1,122 +0,0 @@
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wim.taymans@chello.be>
*
* gstosselement.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_OSS_ELEMENT_H__
#define __GST_OSS_ELEMENT_H__
#include <gst/gst.h>
#include <sys/types.h>
#include "gstosshelper.h"
G_BEGIN_DECLS
#define GST_TYPE_OSSELEMENT \
(gst_osselement_get_type())
#define GST_OSSELEMENT(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OSSELEMENT,GstOssElement))
#define GST_OSSELEMENT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OSSELEMENT,GstOssElementClass))
#define GST_IS_OSSELEMENT(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OSSELEMENT))
#define GST_IS_OSSELEMENT_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OSSELEMENT))
#define GST_OSSELEMENT_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_OSSELEMENT, GstOssElementClass))
typedef struct _GstOssElement GstOssElement;
typedef struct _GstOssElementClass GstOssElementClass;
struct _GstOssElement
{
/* yes, we're a gstelement too */
GstElement parent;
gchar *device,
*mixer_dev;
/* device state */
int fd;
int caps; /* the capabilities */
gint format;
gint fragment;
guint64 fragment_time;
gint fragment_size;
GstCaps *probed_caps;
/* stats bytes per *second* */
guint bps;
/* sample width in bytes */
guint sample_width;
/* parameters */
gint law;
gint endianness;
gboolean sign;
gint width;
gint depth;
gint channels;
gint rate;
gint mode;
/* mixer stuff */
GList *tracklist;
guint32 stereomask,
recdevs,
recmask,
mixcaps;
gint mixer_fd;
gchar *device_name;
};
struct _GstOssElementClass {
GstElementClass klass;
GList *device_combinations;
};
GType gst_osselement_get_type (void);
/* some useful functions */
gboolean gst_osselement_parse_caps (GstOssElement *oss,
const GstCaps *caps);
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,
gint64 src_value,
GstFormat *dest_format,
gint64 *dest_value);
void gst_osselement_probe_caps (GstOssElement *oss);
G_END_DECLS
#endif /* __GST_OSS_ELEMENT_H__ */

File diff suppressed because it is too large Load diff

View file

@ -2,11 +2,7 @@
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wim.taymans@chello.be>
*
* gstosshelper.h: helper functions for OSS Device handling. This
* set of functions takes care of device setting/getting,
* opening/closing devices, parsing caps to OSS formats/settings
* or the other way around, device probing, supported format
* probing and mixer integration.
* gstosshelper.h: OSS helper routines.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -24,128 +20,24 @@
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_OSS_HELPER_H__
#define __GST_OSS_HELPER_H__
#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
enum {
ARG_0,
OSS_ARG_DEVICE,
OSS_ARG_MIXER_DEVICE,
OSS_ARG_DEVICE_NAME,
OSS_ARG_0
};
typedef enum {
GST_OSS_MODE_READ,
GST_OSS_MODE_WRITE,
GST_OSS_MODE_VOLUME,
GST_OSS_MODE_MIXER
} GstOssOpenMode;
GstCaps* gst_oss_helper_probe_caps (gint fd);
/*
* Embed those two in whatever object you're creating.
*/
typedef struct _GstOssDeviceCombination {
gchar *dsp, *mixer;
dev_t dev;
} GstOssDeviceCombination;
typedef struct _GstOssDevice {
/* device state */
int fd;
int caps; /* the capabilities */
gint format;
gint fragment;
guint64 fragment_time;
gint fragment_size;
GstOssOpenMode mode;
GstCaps *probed_caps;
/* stats bytes per *second* */
guint bps;
/* sample width in bytes */
guint sample_width;
/* parameters */
gint law;
gint endianness;
gboolean sign;
gint width;
gint depth;
gint channels;
gint rate;
/* mixer stuff */
GList *tracklist;
guint32 stereomask,
recdevs,
recmask,
mixcaps;
gint mixer_fd;
gchar *device_name;
} GstOssDevice;
/*
* class/type/interface handling for mixer/device handling.
*/
void gst_oss_add_mixer_type (GType type);
void gst_oss_add_device_properties (GstElementClass * klass);
void gst_oss_set_device_property (GstElement * element,
GstOssDeviceCombination * c,
GstOssDevice * dev,
guint prop_id,
GParamSpec * pspec,
const GValue * value);
void gst_oss_get_device_property (GstElement * element,
GstOssDeviceCombination * c,
GstOssDevice * d,
guint prop_id,
GParamSpec * pspec,
GValue * value);
/*
* device open/close.
*/
void gst_oss_init (GObject * obj,
GstOssDeviceCombination * c,
GstOssDevice * dev,
GstOssOpenMode mode);
void gst_oss_dispose (GstOssDeviceCombination * c,
GstOssDevice * dev);
gboolean gst_oss_open (GstElement * element,
GstOssDeviceCombination * c,
GstOssDevice * dev);
void gst_oss_close (GstOssDevice * dev);
/*
* caps parsing/probing.
*/
gboolean gst_oss_parse_caps (GstOssDevice * dev,
const GstCaps * caps);
gboolean gst_oss_merge_fixed_caps (GstOssDevice * dev,
GstCaps * caps);
gboolean gst_oss_sync_parms (GstOssDevice * dev);
void gst_oss_reset (GstOssDevice * dev);
gboolean gst_oss_convert (GstOssDevice * dev,
GstFormat src_format,
gint64 src_value,
GstFormat * dest_format,
gint64 * dest_value);
void gst_oss_probe_caps (GstOssDevice * dev);
G_END_DECLS
#endif /* __GST_OSS_HELPER_H__ */

View file

@ -35,257 +35,186 @@
#include <gst/gst-i18n-plugin.h>
#include "gstossmixer.h"
#include "gstossmixertrack.h"
#define MASK_BIT_IS_SET(mask, bit) \
(mask & (1 << bit))
static void gst_ossmixer_track_class_init (GstOssMixerTrackClass * klass);
static void gst_ossmixer_track_init (GstOssMixerTrack * track);
static gboolean gst_ossmixer_supported (GstImplementsInterface * iface,
GType iface_type);
static const GList *gst_ossmixer_list_tracks (GstMixer * ossmixer);
static void gst_ossmixer_set_volume (GstMixer * ossmixer,
GstMixerTrack * track, gint * volumes);
static void gst_ossmixer_get_volume (GstMixer * ossmixer,
GstMixerTrack * track, gint * volumes);
static void gst_ossmixer_set_record (GstMixer * ossmixer,
GstMixerTrack * track, gboolean record);
static void gst_ossmixer_set_mute (GstMixer * ossmixer,
GstMixerTrack * track, gboolean mute);
static const gchar **labels = NULL;
static GstMixerTrackClass *parent_class = NULL;
/* three functions: firstly, OSS has the nasty habit of inserting
* spaces in the labels, we want to get rid of them. Secondly,
* i18n is impossible with OSS' way of providing us with mixer
* labels, so we make a 'given' list of i18n'ed labels. Thirdly, I
* personally don't like the "1337" names that OSS gives to their
* labels ("Vol", "Mic", "Rec"), I'd rather see full names. */
static void
fill_labels (void)
{
gint i, pos;
gchar *origs[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS;
struct
{
gchar *given, *wanted;
}
cases[] = {
/* Note: this list is simply ripped from soundcard.h. For
* some people, some values might be missing (3D surround,
* etc.) - feel free to add them. That's the reason why
* I'm doing this in such a horribly complicated way. */
{
"Vol ", _("Volume")}
, {
"Bass ", _("Bass")}
, {
"Trebl", _("Treble")}
, {
"Synth", _("Synth")}
, {
"Pcm ", _("PCM")}
, {
"Spkr ", _("Speaker")}
, {
"Line ", _("Line-in")}
, {
"Mic ", _("Microphone")}
, {
"CD ", _("CD")}
, {
"Mix ", _("Mixer")}
, {
"Pcm2 ", _("PCM-2")}
, {
"Rec ", _("Record")}
, {
"IGain", _("In-gain")}
, {
"OGain", _("Out-gain")}
, {
"Line1", _("Line-1")}
, {
"Line2", _("Line-2")}
, {
"Line3", _("Line-3")}
, {
"Digital1", _("Digital-1")}
, {
"Digital2", _("Digital-2")}
, {
"Digital3", _("Digital-3")}
, {
"PhoneIn", _("Phone-in")}
, {
"PhoneOut", _("Phone-out")}
, {
"Video", _("Video")}
, {
"Radio", _("Radio")}
, {
"Monitor", _("Monitor")}
, {
NULL, NULL}
};
labels = g_malloc (sizeof (gchar *) * SOUND_MIXER_NRDEVICES);
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
for (pos = 0; cases[pos].given != NULL; pos++) {
if (!strcmp (cases[pos].given, origs[i])) {
labels[i] = g_strdup (cases[pos].wanted);
break;
}
}
if (cases[pos].given == NULL)
labels[i] = g_strdup (origs[i]);
}
}
GType
gst_ossmixer_track_get_type (void)
{
static GType gst_ossmixer_track_type = 0;
if (!gst_ossmixer_track_type) {
static const GTypeInfo ossmixer_track_info = {
sizeof (GstOssMixerTrackClass),
NULL,
NULL,
(GClassInitFunc) gst_ossmixer_track_class_init,
NULL,
NULL,
sizeof (GstOssMixerTrack),
0,
(GInstanceInitFunc) gst_ossmixer_track_init,
NULL
};
gst_ossmixer_track_type =
g_type_register_static (GST_TYPE_MIXER_TRACK,
"GstOssMixerTrack", &ossmixer_track_info, 0);
}
return gst_ossmixer_track_type;
}
static void
gst_ossmixer_track_class_init (GstOssMixerTrackClass * klass)
{
parent_class = g_type_class_ref (GST_TYPE_MIXER_TRACK);
}
static void
gst_ossmixer_track_init (GstOssMixerTrack * track)
{
track->lvol = track->rvol = 0;
track->track_num = 0;
}
GstMixerTrack *
gst_ossmixer_track_new (GstOssDevice * oss,
gint track_num, gint max_chans, gint flags)
{
GstOssMixerTrack *osstrack;
GstMixerTrack *track;
gint volume;
if (!labels)
fill_labels ();
osstrack = g_object_new (GST_TYPE_OSSMIXER_TRACK, NULL);
track = GST_MIXER_TRACK (osstrack);
track->label = g_strdup (labels[track_num]);
track->num_channels = max_chans;
track->flags = flags;
track->min_volume = 0;
track->max_volume = 100;
osstrack->track_num = track_num;
/* volume */
if (ioctl (oss->mixer_fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
g_warning ("Error getting device (%d) volume: %s",
osstrack->track_num, strerror (errno));
volume = 0;
}
osstrack->lvol = (volume & 0xff);
if (track->num_channels == 2) {
osstrack->rvol = ((volume >> 8) & 0xff);
}
return track;
}
void
gst_oss_interface_init (GstImplementsInterfaceClass * klass)
{
/* default virtual functions */
klass->supported = gst_ossmixer_supported;
}
void
gst_ossmixer_interface_init (GstMixerClass * klass)
{
GST_MIXER_TYPE (klass) = GST_MIXER_HARDWARE;
/* default virtual functions */
klass->list_tracks = gst_ossmixer_list_tracks;
klass->set_volume = gst_ossmixer_set_volume;
klass->get_volume = gst_ossmixer_get_volume;
klass->set_mute = gst_ossmixer_set_mute;
klass->set_record = gst_ossmixer_set_record;
}
static gboolean
gst_ossmixer_supported (GstImplementsInterface * iface, GType iface_type)
gst_ossmixer_open (GstOssMixer * mixer)
{
GstOssDevice *oss = g_object_get_data (G_OBJECT (iface), "oss-data");
#ifdef SOUND_MIXER_INFO
struct mixer_info minfo;
#endif
g_return_val_if_fail (oss != NULL, FALSE);
g_assert (iface_type == GST_TYPE_MIXER);
g_return_val_if_fail (mixer->mixer_fd == -1, FALSE);
return (oss->mixer_fd != -1);
mixer->mixer_fd = open (mixer->device, O_RDWR);
if (mixer->mixer_fd == -1) {
/* this is valid. OSS devices don't need to expose a mixer */
GST_DEBUG ("Failed to open mixer device %s, mixing disabled: %s",
mixer->device, strerror (errno));
return FALSE;
}
/* get masks */
if (ioctl (mixer->mixer_fd, SOUND_MIXER_READ_RECMASK, &mixer->recmask) < 0
|| ioctl (mixer->mixer_fd, SOUND_MIXER_READ_RECSRC, &mixer->recdevs) < 0
|| ioctl (mixer->mixer_fd, SOUND_MIXER_READ_STEREODEVS,
&mixer->stereomask) < 0
|| ioctl (mixer->mixer_fd, SOUND_MIXER_READ_DEVMASK, &mixer->devmask) < 0
|| ioctl (mixer->mixer_fd, SOUND_MIXER_READ_CAPS, &mixer->mixcaps) < 0) {
GST_DEBUG ("Failed to get device masks");
close (mixer->mixer_fd);
mixer->mixer_fd = -1;
return FALSE;
}
/* get name */
#ifdef SOUND_MIXER_INFO
if (ioctl (mixer->mixer_fd, SOUND_MIXER_INFO, &minfo) == 0) {
mixer->cardname = g_strdup (minfo.name);
}
#else
oss->cardname = g_strdup ("Unknown");
#endif
return TRUE;
}
static void
gst_ossmixer_ensure_track_list (GstOssMixer * mixer)
{
gint i, master = -1;
g_return_if_fail (mixer->mixer_fd != -1);
if (mixer->tracklist)
return;
/* find master volume */
if (mixer->devmask & SOUND_MASK_VOLUME)
master = SOUND_MIXER_VOLUME;
else if (mixer->devmask & SOUND_MASK_PCM)
master = SOUND_MIXER_PCM;
else if (mixer->devmask & SOUND_MASK_SPEAKER)
master = SOUND_MIXER_SPEAKER; /* doubtful... */
/* else: no master, so we won't set any */
/* build track list */
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
if (mixer->devmask & (1 << i)) {
GstMixerTrack *track;
gboolean input = FALSE, stereo = FALSE, record = FALSE;
/* track exists, make up capabilities */
if (MASK_BIT_IS_SET (mixer->stereomask, i))
stereo = TRUE;
if (MASK_BIT_IS_SET (mixer->recmask, i))
input = TRUE;
if (MASK_BIT_IS_SET (mixer->recdevs, i))
record = TRUE;
/* do we want this in our list? */
if (!((mixer->dir & GST_OSS_MIXER_CAPTURE && input == TRUE) ||
(mixer->dir & GST_OSS_MIXER_PLAYBACK && i != SOUND_MIXER_PCM)))
/* the PLAYBACK case seems hacky, but that's how 0.8 had it */
continue;
/* add track to list */
track = gst_ossmixer_track_new (mixer->mixer_fd, i, stereo ? 2 : 1,
(record ? GST_MIXER_TRACK_RECORD : 0) |
(input ? GST_MIXER_TRACK_INPUT :
GST_MIXER_TRACK_OUTPUT) |
((master != i) ? 0 : GST_MIXER_TRACK_MASTER));
mixer->tracklist = g_list_append (mixer->tracklist, track);
}
}
}
GstOssMixer *
gst_ossmixer_new (const char *device, GstOssMixerDirection dir)
{
GstOssMixer *ret = NULL;
g_return_val_if_fail (device != NULL, NULL);
ret = g_new0 (GstOssMixer, 1);
ret->device = g_strdup (device);
ret->dir = dir;
if (!gst_ossmixer_open (ret))
goto error;
return ret;
error:
if (ret)
gst_ossmixer_free (ret);
return NULL;
}
void
gst_ossmixer_free (GstOssMixer * mixer)
{
g_return_if_fail (mixer != NULL);
if (mixer->device) {
g_free (mixer->device);
mixer->device = NULL;
}
if (mixer->cardname) {
g_free (mixer->cardname);
mixer->cardname = NULL;
}
if (mixer->tracklist) {
g_list_foreach (mixer->tracklist, (GFunc) g_object_unref, NULL);
g_list_free (mixer->tracklist);
mixer->tracklist = NULL;
}
if (mixer->mixer_fd != -1) {
close (mixer->mixer_fd);
mixer->mixer_fd = -1;
}
g_free (mixer);
}
/* unused with G_DISABLE_* */
static G_GNUC_UNUSED gboolean
gst_ossmixer_contains_track (GstOssDevice * oss, GstOssMixerTrack * osstrack)
gst_ossmixer_contains_track (GstOssMixer * mixer, GstOssMixerTrack * osstrack)
{
const GList *item;
for (item = oss->tracklist; item != NULL; item = item->next)
for (item = mixer->tracklist; item != NULL; item = item->next)
if (item->data == osstrack)
return TRUE;
return FALSE;
}
static const GList *
gst_ossmixer_list_tracks (GstMixer * mixer)
const GList *
gst_ossmixer_list_tracks (GstOssMixer * mixer)
{
GstOssDevice *oss = g_object_get_data (G_OBJECT (mixer), "oss-data");
gst_ossmixer_ensure_track_list (mixer);
return (const GList *) oss->tracklist;
return (const GList *) mixer->tracklist;
}
static void
gst_ossmixer_get_volume (GstMixer * mixer,
void
gst_ossmixer_get_volume (GstOssMixer * mixer,
GstMixerTrack * track, gint * volumes)
{
gint volume;
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));
g_return_if_fail (mixer->mixer_fd != -1);
g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
if (track->flags & GST_MIXER_TRACK_MUTE) {
volumes[0] = osstrack->lvol;
@ -294,7 +223,7 @@ gst_ossmixer_get_volume (GstMixer * mixer,
}
} else {
/* get */
if (ioctl (oss->mixer_fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
if (ioctl (mixer->mixer_fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
g_warning ("Error getting recording device (%d) volume: %s",
osstrack->track_num, strerror (errno));
volume = 0;
@ -307,18 +236,15 @@ gst_ossmixer_get_volume (GstMixer * mixer,
}
}
static void
gst_ossmixer_set_volume (GstMixer * mixer,
void
gst_ossmixer_set_volume (GstOssMixer * mixer,
GstMixerTrack * track, gint * volumes)
{
gint volume;
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));
g_return_if_fail (mixer->mixer_fd != -1);
g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
/* prepare the value for ioctl() */
if (!(track->flags & GST_MIXER_TRACK_MUTE)) {
@ -328,7 +254,7 @@ gst_ossmixer_set_volume (GstMixer * mixer,
}
/* set */
if (ioctl (oss->mixer_fd, MIXER_WRITE (osstrack->track_num), &volume) < 0) {
if (ioctl (mixer->mixer_fd, MIXER_WRITE (osstrack->track_num), &volume) < 0) {
g_warning ("Error setting recording device (%d) volume (0x%x): %s",
osstrack->track_num, volume, strerror (errno));
return;
@ -341,28 +267,26 @@ gst_ossmixer_set_volume (GstMixer * mixer,
}
}
static void
gst_ossmixer_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
void
gst_ossmixer_set_mute (GstOssMixer * mixer, GstMixerTrack * track,
gboolean mute)
{
int volume;
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));
g_return_if_fail (mixer->mixer_fd != -1);
g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
if (mute) {
volume = 0;
} else {
volume = (osstrack->lvol & 0xff);
if (MASK_BIT_IS_SET (oss->stereomask, osstrack->track_num)) {
if (MASK_BIT_IS_SET (mixer->stereomask, osstrack->track_num)) {
volume |= ((osstrack->rvol & 0xff) << 8);
}
}
if (ioctl (oss->mixer_fd, MIXER_WRITE (osstrack->track_num), &volume) < 0) {
if (ioctl (mixer->mixer_fd, MIXER_WRITE (osstrack->track_num), &volume) < 0) {
g_warning ("Error setting mixer recording device volume (0x%x): %s",
volume, strerror (errno));
return;
@ -375,17 +299,14 @@ gst_ossmixer_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
}
}
static void
gst_ossmixer_set_record (GstMixer * mixer,
void
gst_ossmixer_set_record (GstOssMixer * mixer,
GstMixerTrack * track, gboolean record)
{
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));
g_return_if_fail (mixer->mixer_fd != -1);
g_return_if_fail (gst_ossmixer_contains_track (mixer, osstrack));
/* if there's nothing to do... */
if ((record && GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)) ||
@ -393,28 +314,28 @@ gst_ossmixer_set_record (GstMixer * mixer,
return;
/* if we're exclusive, then we need to unset the current one(s) */
if (oss->mixcaps & SOUND_CAP_EXCL_INPUT) {
if (mixer->mixcaps & SOUND_CAP_EXCL_INPUT) {
GList *track;
for (track = oss->tracklist; track != NULL; track = track->next) {
for (track = mixer->tracklist; track != NULL; track = track->next) {
GstMixerTrack *turn = (GstMixerTrack *) track->data;
turn->flags &= ~GST_MIXER_TRACK_RECORD;
}
oss->recdevs = 0;
mixer->recdevs = 0;
}
/* set new record bit, if needed */
if (record) {
oss->recdevs |= (1 << osstrack->track_num);
mixer->recdevs |= (1 << osstrack->track_num);
} else {
oss->recdevs &= ~(1 << osstrack->track_num);
mixer->recdevs &= ~(1 << osstrack->track_num);
}
/* set it to the device */
if (ioctl (oss->mixer_fd, SOUND_MIXER_WRITE_RECSRC, &oss->recdevs) < 0) {
if (ioctl (mixer->mixer_fd, SOUND_MIXER_WRITE_RECSRC, &mixer->recdevs) < 0) {
g_warning ("Error setting mixer recording devices (0x%x): %s",
oss->recdevs, strerror (errno));
mixer->recdevs, strerror (errno));
return;
}
@ -424,101 +345,3 @@ gst_ossmixer_set_record (GstMixer * mixer,
track->flags &= ~GST_MIXER_TRACK_RECORD;
}
}
void
gst_ossmixer_build_list (GstOssDeviceCombination * c, GstOssDevice * oss)
{
gint i, devmask, master = -1;
#ifdef SOUND_MIXER_INFO
struct mixer_info minfo;
#endif
g_return_if_fail (oss->mixer_fd == -1);
oss->mixer_fd = open (c->mixer, O_RDWR);
if (oss->mixer_fd == -1) {
/* this is valid. OSS devices don't need to expose a mixer */
GST_DEBUG ("Failed to open mixer device %s, mixing disabled: %s",
c->mixer, strerror (errno));
return;
}
/* get masks */
if (ioctl (oss->mixer_fd, SOUND_MIXER_READ_RECMASK, &oss->recmask) < 0 ||
ioctl (oss->mixer_fd, SOUND_MIXER_READ_RECSRC, &oss->recdevs) < 0 ||
ioctl (oss->mixer_fd, SOUND_MIXER_READ_STEREODEVS, &oss->stereomask) < 0
|| ioctl (oss->mixer_fd, SOUND_MIXER_READ_DEVMASK, &devmask) < 0
|| ioctl (oss->mixer_fd, SOUND_MIXER_READ_CAPS, &oss->mixcaps) < 0) {
GST_DEBUG ("Failed to get device masks - disabling mixer");
close (oss->mixer_fd);
oss->mixer_fd = -1;
return;
}
/* get name */
#ifdef SOUND_MIXER_INFO
if (ioctl (oss->mixer_fd, SOUND_MIXER_INFO, &minfo) == 0) {
oss->device_name = g_strdup (minfo.name);
}
#else
oss->device_name = g_strdup ("Unknown");
#endif
/* find master volume */
if (devmask & SOUND_MASK_VOLUME)
master = SOUND_MIXER_VOLUME;
else if (devmask & SOUND_MASK_PCM)
master = SOUND_MIXER_PCM;
else if (devmask & SOUND_MASK_SPEAKER)
master = SOUND_MIXER_SPEAKER; /* doubtful... */
/* else: no master, so we won't set any */
/* build track list */
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
if (devmask & (1 << i)) {
GstMixerTrack *track;
gboolean input = FALSE, stereo = FALSE, record = FALSE;
/* track exists, make up capabilities */
if (MASK_BIT_IS_SET (oss->stereomask, i))
stereo = TRUE;
if (MASK_BIT_IS_SET (oss->recmask, i))
input = TRUE;
if (MASK_BIT_IS_SET (oss->recdevs, i))
record = TRUE;
/* do we want this in our list? */
if ((oss->mode == GST_OSS_MODE_READ && input == FALSE) ||
(oss->mode == GST_OSS_MODE_WRITE && i != SOUND_MIXER_PCM))
continue;
/* add track to list */
track = gst_ossmixer_track_new (oss, i, stereo ? 2 : 1,
(record ? GST_MIXER_TRACK_RECORD : 0) |
(input ? GST_MIXER_TRACK_INPUT :
GST_MIXER_TRACK_OUTPUT) |
((master != i) ? 0 : GST_MIXER_TRACK_MASTER));
oss->tracklist = g_list_append (oss->tracklist, track);
}
}
}
void
gst_ossmixer_free_list (GstOssDevice * oss)
{
if (oss->mixer_fd == -1)
return;
g_list_foreach (oss->tracklist, (GFunc) g_object_unref, NULL);
g_list_free (oss->tracklist);
oss->tracklist = NULL;
if (oss->device_name) {
g_free (oss->device_name);
oss->device_name = NULL;
}
close (oss->mixer_fd);
oss->mixer_fd = -1;
}

View file

@ -19,48 +19,153 @@
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_OSS_MIXER_H__
#define __GST_OSS_MIXER_H__
#include <gst/gst.h>
#include <gst/interfaces/mixer.h>
#include "gstosshelper.h"
G_BEGIN_DECLS
#define GST_TYPE_OSSMIXER_TRACK \
(gst_ossmixer_track_get_type ())
#define GST_OSSMIXER_TRACK(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OSSMIXER_TRACK, \
GstOssMixerTrack))
#define GST_OSSMIXER_TRACK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OSSMIXER_TRACK, \
GstOssMixerTrackClass))
#define GST_IS_OSSMIXER_TRACK(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OSSMIXER_TRACK))
#define GST_IS_OSSMIXER_TRACK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OSSMIXER_TRACK))
typedef struct _GstOssMixerTrack {
GstMixerTrack parent;
#define GST_OSS_MIXER(obj) ((GstOssMixer*)(obj))
gint lvol, rvol;
gint track_num;
} GstOssMixerTrack;
typedef struct _GstOssMixerTrackClass {
GstMixerTrackClass parent;
} GstOssMixerTrackClass;
typedef enum {
GST_OSS_MIXER_CAPTURE = 1<<0,
GST_OSS_MIXER_PLAYBACK = 1<<1,
GST_OSS_MIXER_ALL = GST_OSS_MIXER_CAPTURE | GST_OSS_MIXER_PLAYBACK
} GstOssMixerDirection;
GType gst_ossmixer_track_get_type (void);
void gst_ossmixer_interface_init (GstMixerClass *klass);
void gst_oss_interface_init (GstImplementsInterfaceClass *klass);
void gst_ossmixer_build_list (GstOssDeviceCombination * c,
GstOssDevice *oss);
void gst_ossmixer_free_list (GstOssDevice *oss);
typedef struct _GstOssMixer GstOssMixer;
struct _GstOssMixer {
GList * tracklist; /* list of available tracks */
gint mixer_fd;
gchar * device;
gchar * cardname;
gint recmask;
gint recdevs;
gint stereomask;
gint devmask;
gint mixcaps;
GstOssMixerDirection dir;
};
GstOssMixer* gst_ossmixer_new (const gchar *device,
GstOssMixerDirection dir);
void gst_ossmixer_free (GstOssMixer *mixer);
const GList* gst_ossmixer_list_tracks (GstOssMixer * mixer);
void gst_ossmixer_set_volume (GstOssMixer * mixer,
GstMixerTrack * track,
gint * volumes);
void gst_ossmixer_get_volume (GstOssMixer * mixer,
GstMixerTrack * track,
gint * volumes);
void gst_ossmixer_set_record (GstOssMixer * mixer,
GstMixerTrack * track,
gboolean record);
void gst_ossmixer_set_mute (GstOssMixer * mixer,
GstMixerTrack * track,
gboolean mute);
#define GST_IMPLEMENT_OSS_MIXER_METHODS(Type, interface_as_function) \
static gboolean \
interface_as_function ## _supported (Type *this, GType iface_type) \
{ \
g_assert (iface_type == GST_TYPE_MIXER); \
\
return (this->mixer != NULL); \
} \
\
static const GList* \
interface_as_function ## _list_tracks (GstMixer * mixer) \
{ \
Type *this = (Type*) mixer; \
\
g_return_val_if_fail (this != NULL, NULL); \
g_return_val_if_fail (this->mixer != NULL, NULL); \
\
return gst_ossmixer_list_tracks (this->mixer); \
} \
\
static void \
interface_as_function ## _set_volume (GstMixer * mixer, GstMixerTrack * track, \
gint * volumes) \
{ \
Type *this = (Type*) mixer; \
\
g_return_if_fail (this != NULL); \
g_return_if_fail (this->mixer != NULL); \
\
gst_ossmixer_set_volume (this->mixer, track, volumes); \
} \
\
static void \
interface_as_function ## _get_volume (GstMixer * mixer, GstMixerTrack * track, \
gint * volumes) \
{ \
Type *this = (Type*) mixer; \
\
g_return_if_fail (this != NULL); \
g_return_if_fail (this->mixer != NULL); \
\
gst_ossmixer_get_volume (this->mixer, track, volumes); \
} \
\
static void \
interface_as_function ## _set_record (GstMixer * mixer, GstMixerTrack * track, \
gboolean record) \
{ \
Type *this = (Type*) mixer; \
\
g_return_if_fail (this != NULL); \
g_return_if_fail (this->mixer != NULL); \
\
gst_ossmixer_set_record (this->mixer, track, record); \
} \
\
static void \
interface_as_function ## _set_mute (GstMixer * mixer, GstMixerTrack * track, \
gboolean mute) \
{ \
Type *this = (Type*) mixer; \
\
g_return_if_fail (this != NULL); \
g_return_if_fail (this->mixer != NULL); \
\
gst_ossmixer_set_mute (this->mixer, track, mute); \
} \
\
static void \
interface_as_function ## _interface_init (GstMixerClass * klass) \
{ \
GST_MIXER_TYPE (klass) = GST_MIXER_HARDWARE; \
\
/* set up the interface hooks */ \
klass->list_tracks = interface_as_function ## _list_tracks; \
klass->set_volume = interface_as_function ## _set_volume; \
klass->get_volume = interface_as_function ## _get_volume; \
klass->set_mute = interface_as_function ## _set_mute; \
klass->set_record = interface_as_function ## _set_record; \
}
G_END_DECLS
#endif /* __GST_OSS_MIXER_H__ */

180
sys/oss/gstossmixertrack.c Normal file
View file

@ -0,0 +1,180 @@
/* GStreamer OSS Mixer implementation
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
*
* gstossmixer.c: mixer interface implementation for OSS
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <gst/gst-i18n-plugin.h>
#include "gstossmixertrack.h"
#define MASK_BIT_IS_SET(mask, bit) \
(mask & (1 << bit))
G_DEFINE_TYPE (GstOssMixerTrack, gst_ossmixer_track, GST_TYPE_MIXER_TRACK);
static void
gst_ossmixer_track_class_init (GstOssMixerTrackClass * klass)
{
/* nop */
}
static void
gst_ossmixer_track_init (GstOssMixerTrack * track)
{
track->lvol = track->rvol = 0;
track->track_num = 0;
}
static const gchar **labels = NULL;
/* three functions: firstly, OSS has the nasty habit of inserting
* spaces in the labels, we want to get rid of them. Secondly,
* i18n is impossible with OSS' way of providing us with mixer
* labels, so we make a 'given' list of i18n'ed labels. Thirdly, I
* personally don't like the "1337" names that OSS gives to their
* labels ("Vol", "Mic", "Rec"), I'd rather see full names. */
static void
fill_labels (void)
{
gint i, pos;
gchar *origs[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS;
struct
{
gchar *given, *wanted;
}
cases[] = {
/* Note: this list is simply ripped from soundcard.h. For
* some people, some values might be missing (3D surround,
* etc.) - feel free to add them. That's the reason why
* I'm doing this in such a horribly complicated way. */
{
"Vol ", _("Volume")}
, {
"Bass ", _("Bass")}
, {
"Trebl", _("Treble")}
, {
"Synth", _("Synth")}
, {
"Pcm ", _("PCM")}
, {
"Spkr ", _("Speaker")}
, {
"Line ", _("Line-in")}
, {
"Mic ", _("Microphone")}
, {
"CD ", _("CD")}
, {
"Mix ", _("Mixer")}
, {
"Pcm2 ", _("PCM-2")}
, {
"Rec ", _("Record")}
, {
"IGain", _("In-gain")}
, {
"OGain", _("Out-gain")}
, {
"Line1", _("Line-1")}
, {
"Line2", _("Line-2")}
, {
"Line3", _("Line-3")}
, {
"Digital1", _("Digital-1")}
, {
"Digital2", _("Digital-2")}
, {
"Digital3", _("Digital-3")}
, {
"PhoneIn", _("Phone-in")}
, {
"PhoneOut", _("Phone-out")}
, {
"Video", _("Video")}
, {
"Radio", _("Radio")}
, {
"Monitor", _("Monitor")}
, {
NULL, NULL}
};
labels = g_malloc (sizeof (gchar *) * SOUND_MIXER_NRDEVICES);
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
for (pos = 0; cases[pos].given != NULL; pos++) {
if (!strcmp (cases[pos].given, origs[i])) {
labels[i] = g_strdup (cases[pos].wanted);
break;
}
}
if (cases[pos].given == NULL)
labels[i] = g_strdup (origs[i]);
}
}
GstMixerTrack *
gst_ossmixer_track_new (gint mixer_fd,
gint track_num, gint max_chans, gint flags)
{
GstOssMixerTrack *osstrack;
GstMixerTrack *track;
gint volume;
if (!labels)
fill_labels ();
osstrack = g_object_new (GST_TYPE_OSSMIXER_TRACK, NULL);
track = GST_MIXER_TRACK (osstrack);
track->label = g_strdup (labels[track_num]);
track->num_channels = max_chans;
track->flags = flags;
track->min_volume = 0;
track->max_volume = 100;
osstrack->track_num = track_num;
/* volume */
if (ioctl (mixer_fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
g_warning ("Error getting device (%d) volume: %s",
osstrack->track_num, strerror (errno));
volume = 0;
}
osstrack->lvol = (volume & 0xff);
if (track->num_channels == 2) {
osstrack->rvol = ((volume >> 8) & 0xff);
}
return track;
}

View file

@ -0,0 +1,62 @@
/* GStreamer OSS Mixer implementation
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
*
* gstossmixertrack.h: OSS mixer tracks
*
* 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_OSS_MIXER_TRACK_H__
#define __GST_OSS_MIXER_TRACK_H__
#include <gst/gst.h>
#include <gst/interfaces/mixer.h>
#include "gstosshelper.h"
G_BEGIN_DECLS
#define GST_TYPE_OSSMIXER_TRACK \
(gst_ossmixer_track_get_type ())
#define GST_OSSMIXER_TRACK(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OSSMIXER_TRACK, \
GstOssMixerTrack))
#define GST_OSSMIXER_TRACK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OSSMIXER_TRACK, \
GstOssMixerTrackClass))
#define GST_IS_OSSMIXER_TRACK(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OSSMIXER_TRACK))
#define GST_IS_OSSMIXER_TRACK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OSSMIXER_TRACK))
typedef struct _GstOssMixerTrack {
GstMixerTrack parent;
gint lvol, rvol;
gint track_num;
} GstOssMixerTrack;
typedef struct _GstOssMixerTrackClass {
GstMixerTrackClass parent;
} GstOssMixerTrackClass;
GType gst_ossmixer_track_get_type (void);
GstMixerTrack* gst_ossmixer_track_new (gint mixer_fd,
gint track_num, gint max_chans, gint flags);
G_END_DECLS
#endif /* __GST_OSS_MIXER_TRACK_H__ */

View file

@ -162,27 +162,22 @@ gst_oss_sink_init (GstOssSink * osssink)
{
GST_DEBUG ("initializing osssink");
osssink->element = g_object_new (GST_TYPE_OSSELEMENT, NULL);
osssink->fd = -1;
}
static GstCaps *
gst_oss_sink_getcaps (GstBaseSink * bsink)
{
GstOssSink *osssink;
GstOssElement *element;
GstCaps *caps;
osssink = GST_OSSSINK (bsink);
element = osssink->element;
gst_osselement_probe_caps (element);
if (element->probed_caps == NULL) {
caps =
gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD
if (osssink->fd == -1) {
caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD
(bsink)));
} else {
caps = gst_caps_ref (element->probed_caps);
caps = gst_oss_helper_probe_caps (osssink->fd);
}
return caps;

View file

@ -28,7 +28,7 @@
#include <gst/gst.h>
#include <gst/audio/gstaudiosink.h>
#include "gstosselement.h"
#include "gstosshelper.h"
G_BEGIN_DECLS
@ -44,8 +44,6 @@ typedef struct _GstOssSinkClass GstOssSinkClass;
struct _GstOssSink {
GstAudioSink sink;
GstOssElement *element;
gint fd;
gint bytes_per_sample;
};

View file

@ -192,27 +192,23 @@ gst_oss_src_init (GstOssSrc * osssrc)
{
GST_DEBUG ("initializing osssrc");
osssrc->fd = -1;
osssrc->device = g_strdup ("/dev/dsp");
osssrc->element = g_object_new (GST_TYPE_OSSELEMENT, NULL);
}
static GstCaps *
gst_oss_src_getcaps (GstBaseSrc * bsrc)
{
GstOssSrc *osssrc;
GstOssElement *element;
GstCaps *caps;
osssrc = GST_OSS_SRC (bsrc);
element = osssrc->element;
gst_osselement_probe_caps (element);
if (element->probed_caps == NULL) {
caps =
gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc)));
if (osssrc->fd == -1) {
caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD
(bsrc)));
} else {
caps = gst_caps_ref (element->probed_caps);
caps = gst_oss_helper_probe_caps (osssrc->fd);
}
return caps;

View file

@ -28,7 +28,7 @@
#include <gst/gst.h>
#include <gst/audio/gstaudiosrc.h>
#include "gstosselement.h"
#include "gstosshelper.h"
G_BEGIN_DECLS
@ -44,8 +44,6 @@ typedef struct _GstOssSrcClass GstOssSrcClass;
struct _GstOssSrc {
GstAudioSrc src;
GstOssElement *element;
gint fd;
gint bytes_per_sample;