2003-09-13 13:42:09 +00:00
|
|
|
/* GStreamer OSS Mixer implementation
|
|
|
|
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2003-09-13 01:22:59 +00:00
|
|
|
*
|
2003-10-10 12:24:20 +00:00
|
|
|
* gstossmixer.c: mixer interface implementation for OSS
|
2003-09-13 01:22:59 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2004-06-07 13:40:08 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_OSS_INCLUDE_IN_SYS
|
2003-09-13 01:22:59 +00:00
|
|
|
#include <sys/soundcard.h>
|
2004-06-07 13:40:08 +00:00
|
|
|
#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 */
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2004-07-15 23:56:05 +00:00
|
|
|
#include <gst/gst-i18n-plugin.h>
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
#include "gstossmixer.h"
|
|
|
|
|
|
|
|
#define MASK_BIT_IS_SET(mask, bit) \
|
|
|
|
(mask & (1 << bit))
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_ossmixer_track_class_init (GstOssMixerTrackClass * klass);
|
|
|
|
static void gst_ossmixer_track_init (GstOssMixerTrack * track);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
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);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-14 10:11:14 +00:00
|
|
|
static const gchar **labels = NULL;
|
2003-10-10 12:24:20 +00:00
|
|
|
static GstMixerTrackClass *parent_class = NULL;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-14 10:11:14 +00:00
|
|
|
/* 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
|
2004-07-15 23:56:05 +00:00
|
|
|
* labels, so we make a 'given' list of i18n'ed labels. Thirdly, I
|
2003-10-14 10:11:14 +00:00
|
|
|
* 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;
|
2004-03-14 22:34:33 +00:00
|
|
|
struct
|
|
|
|
{
|
2003-10-14 10:11:14 +00:00
|
|
|
gchar *given, *wanted;
|
2004-03-15 19:32:27 +00:00
|
|
|
}
|
|
|
|
cases[] =
|
|
|
|
{
|
2003-10-14 10:11:14 +00:00
|
|
|
/* 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. */
|
2004-03-14 22:34:33 +00:00
|
|
|
{
|
2004-03-15 19:32:27 +00:00
|
|
|
"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")}
|
|
|
|
, {
|
2004-03-14 22:34:33 +00:00
|
|
|
NULL, NULL}
|
2003-10-14 10:11:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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])) {
|
2004-03-15 19:32:27 +00:00
|
|
|
labels[i] = g_strdup (cases[pos].wanted);
|
|
|
|
break;
|
2003-10-14 10:11:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cases[pos].given == NULL)
|
|
|
|
labels[i] = g_strdup (origs[i]);
|
|
|
|
}
|
|
|
|
}
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
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 =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_MIXER_TRACK,
|
|
|
|
"GstOssMixerTrack", &ossmixer_track_info, 0);
|
2003-10-10 12:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gst_ossmixer_track_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_track_class_init (GstOssMixerTrackClass * klass)
|
2003-10-10 12:24:20 +00:00
|
|
|
{
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_MIXER_TRACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_track_init (GstOssMixerTrack * track)
|
2003-10-10 12:24:20 +00:00
|
|
|
{
|
|
|
|
track->lvol = track->rvol = 0;
|
|
|
|
track->track_num = 0;
|
|
|
|
}
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
GstMixerTrack *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_track_new (GstOssElement * oss,
|
|
|
|
gint track_num, gint max_chans, gint flags)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
2003-10-10 12:24:20 +00:00
|
|
|
GstOssMixerTrack *osstrack;
|
|
|
|
GstMixerTrack *track;
|
2003-10-14 10:11:14 +00:00
|
|
|
gint volume;
|
|
|
|
|
|
|
|
if (!labels)
|
|
|
|
fill_labels ();
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
osstrack = g_object_new (GST_TYPE_OSSMIXER_TRACK, NULL);
|
|
|
|
track = GST_MIXER_TRACK (osstrack);
|
2003-10-09 22:02:37 +00:00
|
|
|
track->label = g_strdup (labels[track_num]);
|
|
|
|
track->num_channels = max_chans;
|
|
|
|
track->flags = flags;
|
|
|
|
track->min_volume = 0;
|
|
|
|
track->max_volume = 100;
|
2003-10-10 12:24:20 +00:00
|
|
|
osstrack->track_num = track_num;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
/* volume */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (oss->mixer_fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
|
|
|
|
g_warning ("Error getting device (%d) volume: %s",
|
2004-03-15 19:32:27 +00:00
|
|
|
osstrack->track_num, strerror (errno));
|
2003-10-14 10:11:14 +00:00
|
|
|
volume = 0;
|
|
|
|
}
|
|
|
|
osstrack->lvol = (volume & 0xff);
|
|
|
|
if (track->num_channels == 2) {
|
|
|
|
osstrack->rvol = ((volume >> 8) & 0xff);
|
|
|
|
}
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
return track;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_oss_interface_init (GstImplementsInterfaceClass * klass)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
/* default virtual functions */
|
|
|
|
klass->supported = gst_ossmixer_supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_interface_init (GstMixerClass * klass)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
ext/alsa/gstalsamixer.c: Setting mixer interface type to HARDWARE.
Original commit message from CVS:
2004-01-15 Julien MOUTTE <julien@moutte.net>
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_interface_init): Setting
mixer interface type to HARDWARE.
* gst-libs/gst/mixer/mixer.c: (gst_mixer_class_init): Adding a default
type to SOFTWARE.
* gst-libs/gst/mixer/mixer.h: Adding mixer interface type and macro.
* gst-libs/gst/mixer/mixertrack.h: Adding mixertrack flag SOFTWARE.
* gst/volume/gstvolume.c: (gst_volume_interface_supported),
(gst_volume_interface_init), (gst_volume_list_tracks),
(gst_volume_set_volume), (gst_volume_get_volume),
(gst_volume_set_mute), (gst_volume_mixer_init),
(gst_volume_dispose), (gst_volume_get_type), (volume_class_init),
(volume_init): Implementing mixer interface.
* gst/volume/gstvolume.h: Adding tracklist for mixer interface.
* sys/oss/gstosselement.c: (gst_osselement_get_type),
(gst_osselement_change_state): Removing some trailing commas in
structures.
* sys/oss/gstossmixer.c: (gst_ossmixer_interface_init): Setting mixer
interface type to HARDWARE.
* sys/v4l/gstv4lcolorbalance.c:
(gst_v4l_color_balance_interface_init): Setting colorbalance interface
type to HARDWARE.
* sys/v4l2/gstv4l2colorbalance.c:
(gst_v4l2_color_balance_interface_init): Setting colorbalance
interface type to HARDWARE.
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_chain): use exactly the
same code than ximagesink for event handling.
2004-01-15 15:50:10 +00:00
|
|
|
GST_MIXER_TYPE (klass) = GST_MIXER_HARDWARE;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
/* default virtual functions */
|
2003-10-09 22:02:37 +00:00
|
|
|
klass->list_tracks = gst_ossmixer_list_tracks;
|
2003-09-13 01:22:59 +00:00
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_supported (GstImplementsInterface * iface, GType iface_type)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
2003-09-13 15:47:59 +00:00
|
|
|
g_assert (iface_type == GST_TYPE_MIXER);
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
return (GST_OSSELEMENT (iface)->mixer_fd != -1);
|
|
|
|
}
|
|
|
|
|
compile fixes for --disable-gst-debug, G_DISABLE_ASSERT and friends
Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_get_volume),
(gst_alsa_mixer_set_volume), (gst_alsa_mixer_set_mute),
(gst_alsa_mixer_set_record), (gst_alsa_mixer_set_option),
(gst_alsa_mixer_get_option):
* ext/dvdnav/dvdnavsrc.c: (dvdnav_get_event_name),
(dvdnavsrc_print_event):
* ext/ogg/gstoggdemux.c: (_find_chain_process), (gst_ogg_print):
* ext/ogg/gstoggmux.c: (gst_ogg_mux_pad_link),
(gst_ogg_mux_pad_unlink):
* gst/multipart/multipartmux.c: (gst_multipart_mux_pad_link),
(gst_multipart_mux_pad_unlink):
* gst/videofilter/gstvideobalance.c:
(gst_videobalance_colorbalance_set_value):
* gst/videomixer/videomixer.c: (gst_videomixer_pad_link),
(gst_videomixer_pad_unlink):
* po/uk.po:
* sys/oss/gstossmixer.c:
* sys/v4l/gstv4lcolorbalance.c:
* sys/v4l/gstv4ltuner.c:
* sys/v4l/v4lsrc_calls.c:
* sys/v4l2/gstv4l2colorbalance.c:
* sys/v4l2/gstv4l2tuner.c:
compile fixes for --disable-gst-debug, G_DISABLE_ASSERT and friends
2004-08-03 16:06:09 +00:00
|
|
|
/* unused with G_DISABLE_* */
|
|
|
|
static G_GNUC_UNUSED gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_contains_track (GstOssElement * oss, GstOssMixerTrack * osstrack)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
2003-10-10 12:24:20 +00:00
|
|
|
const GList *item;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
for (item = oss->tracklist; item != NULL; item = item->next)
|
|
|
|
if (item->data == osstrack)
|
|
|
|
return TRUE;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GList *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_list_tracks (GstMixer * mixer)
|
2003-10-10 12:24:20 +00:00
|
|
|
{
|
2003-10-09 22:02:37 +00:00
|
|
|
return (const GList *) GST_OSSELEMENT (mixer)->tracklist;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_get_volume (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gint * volumes)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
gint volume;
|
|
|
|
GstOssElement *oss = GST_OSSELEMENT (mixer);
|
2003-10-10 12:24:20 +00:00
|
|
|
GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
/* assert that we're opened and that we're using a known item */
|
2003-09-13 01:22:59 +00:00
|
|
|
g_return_if_fail (oss->mixer_fd != -1);
|
2003-10-10 12:24:20 +00:00
|
|
|
g_return_if_fail (gst_ossmixer_contains_track (oss, osstrack));
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
if (track->flags & GST_MIXER_TRACK_MUTE) {
|
|
|
|
volumes[0] = osstrack->lvol;
|
|
|
|
if (track->num_channels == 2) {
|
|
|
|
volumes[1] = osstrack->rvol;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* get */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (oss->mixer_fd, MIXER_READ (osstrack->track_num), &volume) < 0) {
|
|
|
|
g_warning ("Error getting recording device (%d) volume: %s",
|
2004-03-15 19:32:27 +00:00
|
|
|
osstrack->track_num, strerror (errno));
|
2003-09-13 01:22:59 +00:00
|
|
|
volume = 0;
|
|
|
|
}
|
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
osstrack->lvol = volumes[0] = (volume & 0xff);
|
|
|
|
if (track->num_channels == 2) {
|
|
|
|
osstrack->rvol = volumes[1] = ((volume >> 8) & 0xff);
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_set_volume (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gint * volumes)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
gint volume;
|
|
|
|
GstOssElement *oss = GST_OSSELEMENT (mixer);
|
2003-10-10 12:24:20 +00:00
|
|
|
GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
/* assert that we're opened and that we're using a known item */
|
2003-09-13 01:22:59 +00:00
|
|
|
g_return_if_fail (oss->mixer_fd != -1);
|
2003-10-10 12:24:20 +00:00
|
|
|
g_return_if_fail (gst_ossmixer_contains_track (oss, osstrack));
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
/* prepare the value for ioctl() */
|
2003-10-09 22:02:37 +00:00
|
|
|
if (!(track->flags & GST_MIXER_TRACK_MUTE)) {
|
2003-09-13 01:22:59 +00:00
|
|
|
volume = (volumes[0] & 0xff);
|
2003-10-09 22:02:37 +00:00
|
|
|
if (track->num_channels == 2) {
|
2003-09-13 01:22:59 +00:00
|
|
|
volume |= ((volumes[1] & 0xff) << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (oss->mixer_fd, MIXER_WRITE (osstrack->track_num), &volume) < 0) {
|
|
|
|
g_warning ("Error setting recording device (%d) volume (0x%x): %s",
|
2004-03-15 19:32:27 +00:00
|
|
|
osstrack->track_num, volume, strerror (errno));
|
2003-09-13 01:22:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
osstrack->lvol = volumes[0];
|
|
|
|
if (track->num_channels == 2) {
|
|
|
|
osstrack->rvol = volumes[1];
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
int volume;
|
|
|
|
GstOssElement *oss = GST_OSSELEMENT (mixer);
|
2003-10-10 12:24:20 +00:00
|
|
|
GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
/* assert that we're opened and that we're using a known item */
|
2003-09-13 01:22:59 +00:00
|
|
|
g_return_if_fail (oss->mixer_fd != -1);
|
2003-10-10 12:24:20 +00:00
|
|
|
g_return_if_fail (gst_ossmixer_contains_track (oss, osstrack));
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
if (mute) {
|
|
|
|
volume = 0;
|
|
|
|
} else {
|
2003-10-09 22:02:37 +00:00
|
|
|
volume = (osstrack->lvol & 0xff);
|
|
|
|
if (MASK_BIT_IS_SET (oss->stereomask, osstrack->track_num)) {
|
|
|
|
volume |= ((osstrack->rvol & 0xff) << 8);
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (oss->mixer_fd, MIXER_WRITE (osstrack->track_num), &volume) < 0) {
|
|
|
|
g_warning ("Error setting mixer recording device volume (0x%x): %s",
|
2004-03-15 19:32:27 +00:00
|
|
|
volume, strerror (errno));
|
2003-09-13 01:22:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mute) {
|
2003-10-09 22:02:37 +00:00
|
|
|
track->flags |= GST_MIXER_TRACK_MUTE;
|
2003-09-13 01:22:59 +00:00
|
|
|
} else {
|
2003-10-09 22:02:37 +00:00
|
|
|
track->flags &= ~GST_MIXER_TRACK_MUTE;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_set_record (GstMixer * mixer,
|
|
|
|
GstMixerTrack * track, gboolean record)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
|
|
|
GstOssElement *oss = GST_OSSELEMENT (mixer);
|
2003-10-10 12:24:20 +00:00
|
|
|
GstOssMixerTrack *osstrack = GST_OSSMIXER_TRACK (track);
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
/* assert that we're opened and that we're using a known item */
|
2003-09-13 01:22:59 +00:00
|
|
|
g_return_if_fail (oss->mixer_fd != -1);
|
2003-10-10 12:24:20 +00:00
|
|
|
g_return_if_fail (gst_ossmixer_contains_track (oss, osstrack));
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-11-09 10:51:26 +00:00
|
|
|
/* if there's nothing to do... */
|
|
|
|
if ((record && GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)) ||
|
|
|
|
(!record && !GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)))
|
|
|
|
return;
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
/* if we're exclusive, then we need to unset the current one(s) */
|
|
|
|
if (oss->mixcaps & SOUND_CAP_EXCL_INPUT) {
|
2003-10-09 22:02:37 +00:00
|
|
|
GList *track;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
for (track = oss->tracklist; track != NULL; track = track->next) {
|
|
|
|
GstMixerTrack *turn = (GstMixerTrack *) track->data;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
turn->flags &= ~GST_MIXER_TRACK_RECORD;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
oss->recdevs = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set new record bit, if needed */
|
|
|
|
if (record) {
|
2003-10-09 22:02:37 +00:00
|
|
|
oss->recdevs |= (1 << osstrack->track_num);
|
2003-09-13 01:22:59 +00:00
|
|
|
} else {
|
2003-10-09 22:02:37 +00:00
|
|
|
oss->recdevs &= ~(1 << osstrack->track_num);
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set it to the device */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (oss->mixer_fd, SOUND_MIXER_WRITE_RECSRC, &oss->recdevs) < 0) {
|
|
|
|
g_warning ("Error setting mixer recording devices (0x%x): %s",
|
2004-03-15 19:32:27 +00:00
|
|
|
oss->recdevs, strerror (errno));
|
2003-09-13 01:22:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (record) {
|
2003-10-09 22:02:37 +00:00
|
|
|
track->flags |= GST_MIXER_TRACK_RECORD;
|
2003-09-13 01:22:59 +00:00
|
|
|
} else {
|
2003-10-09 22:02:37 +00:00
|
|
|
track->flags &= ~GST_MIXER_TRACK_RECORD;
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_build_list (GstOssElement * oss)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
2004-01-06 15:59:02 +00:00
|
|
|
gint i, devmask, master = -1;
|
2003-10-10 12:24:20 +00:00
|
|
|
const GList *pads = gst_element_get_pad_list (GST_ELEMENT (oss));
|
|
|
|
GstPadDirection dir = GST_PAD_UNKNOWN;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-11-13 08:39:45 +00:00
|
|
|
#ifdef SOUND_MIXER_INFO
|
2003-10-10 12:24:20 +00:00
|
|
|
struct mixer_info minfo;
|
2003-11-13 08:39:45 +00:00
|
|
|
#endif
|
2003-09-13 01:22:59 +00:00
|
|
|
|
|
|
|
g_return_if_fail (oss->mixer_fd == -1);
|
|
|
|
|
|
|
|
oss->mixer_fd = open (oss->mixer_dev, O_RDWR);
|
|
|
|
if (oss->mixer_fd == -1) {
|
2003-10-10 12:24:20 +00:00
|
|
|
/* this is valid. OSS devices don't need to expose a mixer */
|
|
|
|
GST_DEBUG ("Failed to open mixer device %s, mixing disabled: %s",
|
2004-03-15 19:32:27 +00:00
|
|
|
oss->mixer_dev, strerror (errno));
|
2003-09-13 01:22:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
/* get direction */
|
|
|
|
if (pads && g_list_length ((GList *) pads) == 1)
|
|
|
|
dir = GST_PAD_DIRECTION (GST_PAD (pads->data));
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
/* get masks */
|
2003-10-10 12:24:20 +00:00
|
|
|
if (ioctl (oss->mixer_fd, SOUND_MIXER_READ_RECMASK, &oss->recmask) < 0 ||
|
|
|
|
ioctl (oss->mixer_fd, SOUND_MIXER_READ_RECSRC, &oss->recdevs) < 0 ||
|
2004-03-14 22:34:33 +00:00
|
|
|
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) {
|
2003-10-10 12:24:20 +00:00
|
|
|
GST_DEBUG ("Failed to get device masks - disabling mixer");
|
|
|
|
close (oss->mixer_fd);
|
|
|
|
oss->mixer_fd = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get name */
|
2003-11-13 08:39:45 +00:00
|
|
|
#ifdef SOUND_MIXER_INFO
|
2003-10-10 12:24:20 +00:00
|
|
|
if (ioctl (oss->mixer_fd, SOUND_MIXER_INFO, &minfo) == 0) {
|
|
|
|
oss->device_name = g_strdup (minfo.name);
|
|
|
|
}
|
2003-11-13 08:39:45 +00:00
|
|
|
#else
|
|
|
|
oss->device_name = g_strdup ("Unknown");
|
|
|
|
#endif
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2004-01-06 15:59:02 +00:00
|
|
|
/* 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)
|
2004-03-15 19:32:27 +00:00
|
|
|
master = SOUND_MIXER_SPEAKER; /* doubtful... */
|
2004-01-06 15:59:02 +00:00
|
|
|
/* else: no master, so we won't set any */
|
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
/* build track list */
|
2003-09-13 01:22:59 +00:00
|
|
|
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
|
|
|
|
if (devmask & (1 << i)) {
|
2003-10-09 22:02:37 +00:00
|
|
|
GstMixerTrack *track;
|
2003-09-13 01:22:59 +00:00
|
|
|
gboolean input = FALSE, stereo = FALSE, record = FALSE;
|
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
/* track exists, make up capabilities */
|
2003-09-13 01:22:59 +00:00
|
|
|
if (MASK_BIT_IS_SET (oss->stereomask, i))
|
2004-03-15 19:32:27 +00:00
|
|
|
stereo = TRUE;
|
2003-09-13 01:22:59 +00:00
|
|
|
if (MASK_BIT_IS_SET (oss->recmask, i))
|
2004-03-15 19:32:27 +00:00
|
|
|
input = TRUE;
|
2003-09-13 01:22:59 +00:00
|
|
|
if (MASK_BIT_IS_SET (oss->recdevs, i))
|
2004-03-15 19:32:27 +00:00
|
|
|
record = TRUE;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
/* do we want this in our list? */
|
|
|
|
if ((dir == GST_PAD_SRC && input == FALSE) ||
|
2004-03-15 19:32:27 +00:00
|
|
|
(dir == GST_PAD_SINK && i != SOUND_MIXER_PCM))
|
|
|
|
continue;
|
2003-10-10 12:24:20 +00:00
|
|
|
|
2003-10-09 22:02:37 +00:00
|
|
|
/* add track to list */
|
|
|
|
track = gst_ossmixer_track_new (oss, i, stereo ? 2 : 1,
|
2004-03-15 19:32:27 +00:00
|
|
|
(record ? GST_MIXER_TRACK_RECORD : 0) |
|
|
|
|
(input ? GST_MIXER_TRACK_INPUT :
|
|
|
|
GST_MIXER_TRACK_OUTPUT) |
|
|
|
|
((master != i) ? 0 : GST_MIXER_TRACK_MASTER));
|
2003-10-09 22:02:37 +00:00
|
|
|
oss->tracklist = g_list_append (oss->tracklist, track);
|
2003-09-13 01:22:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ossmixer_free_list (GstOssElement * oss)
|
2003-09-13 01:22:59 +00:00
|
|
|
{
|
2003-10-10 12:24:20 +00:00
|
|
|
if (oss->mixer_fd == -1)
|
|
|
|
return;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
g_list_foreach (oss->tracklist, (GFunc) g_object_unref, NULL);
|
2003-10-09 22:02:37 +00:00
|
|
|
g_list_free (oss->tracklist);
|
|
|
|
oss->tracklist = NULL;
|
2003-09-13 01:22:59 +00:00
|
|
|
|
2003-10-10 12:24:20 +00:00
|
|
|
if (oss->device_name) {
|
|
|
|
g_free (oss->device_name);
|
|
|
|
oss->device_name = NULL;
|
|
|
|
}
|
|
|
|
|
2003-09-13 01:22:59 +00:00
|
|
|
close (oss->mixer_fd);
|
|
|
|
oss->mixer_fd = -1;
|
|
|
|
}
|