sunaudio: Support new flags for options and actions

Use new audio mixer flags added in Base 0.10.23 to expose flags and options
on the SunAudio devices.

Fixes: #583593
Patch By: Brian Cameron <brian.cameron@sun.com>
Patch By: Garrett D'Amore <garrett.damore@sun.com>
This commit is contained in:
Jan Schmidt 2009-06-04 12:27:19 +01:00
parent 29111fa1f8
commit 0fc43060e5
7 changed files with 590 additions and 118 deletions

View file

@ -5,6 +5,7 @@ libgstsunaudio_la_SOURCES = gstsunaudio.c \
gstsunaudiomixerctrl.c \
gstsunaudiomixer.c \
gstsunaudiomixertrack.c \
gstsunaudiomixeroptions.c \
gstsunaudiosrc.c
libgstsunaudio_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
@ -20,5 +21,6 @@ noinst_HEADERS = gstsunaudiosink.h \
gstsunaudiomixer.h \
gstsunaudiomixerctrl.h \
gstsunaudiomixertrack.h \
gstsunaudiomixeroptions.h \
gstsunaudiosrc.h

View file

@ -1,9 +1,11 @@
/*
* GStreamer - SunAudio mixer interface element
* Copyright (C) 2005,2006,2008 Sun Microsystems, Inc.,
* Copyright (C) 2005,2006,2008,2009 Sun Microsystems, Inc.,
* Brian Cameron <brian.cameron@sun.com>
* Copyright (C) 2008 Sun Microsystems, Inc.,
* Jan Schmidt <jan.schmidt@sun.com>
* Copyright (C) 2009 Sun Microsystems, Inc.,
* Garrett D'Amore <garrett.damore@sun.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -32,12 +34,14 @@
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/audio.h>
#include <sys/mixer.h>
#include <gst/gst-i18n-plugin.h>
#include "gstsunaudiomixerctrl.h"
#include "gstsunaudiomixertrack.h"
#include "gstsunaudiomixeroptions.h"
GST_DEBUG_CATEGORY_EXTERN (sunaudio_debug);
#define GST_CAT_DEFAULT sunaudio_debug
@ -74,6 +78,7 @@ void
gst_sunaudiomixer_ctrl_build_list (GstSunAudioMixerCtrl * mixer)
{
GstMixerTrack *track;
GstMixerOptions *options;
struct audio_info audioinfo;
@ -83,35 +88,54 @@ gst_sunaudiomixer_ctrl_build_list (GstSunAudioMixerCtrl * mixer)
if (mixer->tracklist == NULL) {
g_return_if_fail (mixer->mixer_fd != -1);
/* Output & should be MASTER when it's the only one. */
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_OUTPUT,
2, GST_MIXER_TRACK_OUTPUT | GST_MIXER_TRACK_MASTER);
mixer->tracklist = g_list_append (mixer->tracklist, track);
/* Input */
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_LINE_IN,
2, GST_MIXER_TRACK_INPUT);
/* Set whether we are recording from microphone or from line-in */
/* query available ports */
if (ioctl (mixer->mixer_fd, AUDIO_GETINFO, &audioinfo) < 0) {
g_warning ("Error getting audio device volume");
return;
}
/* Set initial RECORD status */
if (audioinfo.record.port == AUDIO_MICROPHONE) {
mixer->recdevs |= (1 << GST_SUNAUDIO_TRACK_LINE_IN);
track->flags |= GST_MIXER_TRACK_RECORD;
} else {
mixer->recdevs &= ~(1 << GST_SUNAUDIO_TRACK_LINE_IN);
track->flags &= ~GST_MIXER_TRACK_RECORD;
}
/* Output & should be MASTER when it's the only one. */
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_OUTPUT);
mixer->tracklist = g_list_append (mixer->tracklist, track);
/* Input */
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_RECORD);
mixer->tracklist = g_list_append (mixer->tracklist, track);
/* Monitor */
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_MONITOR);
mixer->tracklist = g_list_append (mixer->tracklist, track);
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_MONITOR,
2, GST_MIXER_TRACK_INPUT);
mixer->tracklist = g_list_append (mixer->tracklist, track);
if (audioinfo.play.avail_ports & AUDIO_SPEAKER) {
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_SPEAKER);
mixer->tracklist = g_list_append (mixer->tracklist, track);
}
if (audioinfo.play.avail_ports & AUDIO_HEADPHONE) {
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_HP);
mixer->tracklist = g_list_append (mixer->tracklist, track);
}
if (audioinfo.play.avail_ports & AUDIO_LINE_OUT) {
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_LINEOUT);
mixer->tracklist = g_list_append (mixer->tracklist, track);
}
if (audioinfo.play.avail_ports & AUDIO_SPDIF_OUT) {
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_SPDIFOUT);
mixer->tracklist = g_list_append (mixer->tracklist, track);
}
if (audioinfo.play.avail_ports & AUDIO_AUX1_OUT) {
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_AUX1OUT);
mixer->tracklist = g_list_append (mixer->tracklist, track);
}
if (audioinfo.play.avail_ports & AUDIO_AUX2_OUT) {
track = gst_sunaudiomixer_track_new (GST_SUNAUDIO_TRACK_AUX2OUT);
mixer->tracklist = g_list_append (mixer->tracklist, track);
}
if (audioinfo.record.avail_ports != AUDIO_NONE) {
options =
gst_sunaudiomixer_options_new (mixer, GST_SUNAUDIO_TRACK_RECSRC);
mixer->tracklist = g_list_append (mixer->tracklist, options);
}
}
}
@ -164,6 +188,12 @@ gst_sunaudiomixer_ctrl_free (GstSunAudioMixerCtrl * mixer)
g_free (mixer);
}
GstMixerFlags
gst_sunaudiomixer_ctrl_get_mixer_flags (GstSunAudioMixerCtrl * mixer)
{
return GST_MIXER_FLAG_HAS_WHITELIST | GST_MIXER_FLAG_GROUPING;
}
const GList *
gst_sunaudiomixer_ctrl_list_tracks (GstSunAudioMixerCtrl * mixer)
{
@ -179,7 +209,10 @@ gst_sunaudiomixer_ctrl_get_volume (GstSunAudioMixerCtrl * mixer,
gint gain, balance;
float ratio;
struct audio_info audioinfo;
GstSunAudioMixerTrack *sunaudiotrack = GST_SUNAUDIO_MIXER_TRACK (track);
GstSunAudioMixerTrack *sunaudiotrack;
g_return_if_fail (GST_IS_SUNAUDIO_MIXER_TRACK (track));
sunaudiotrack = GST_SUNAUDIO_MIXER_TRACK (track);
g_return_if_fail (mixer->mixer_fd != -1);
@ -188,12 +221,15 @@ gst_sunaudiomixer_ctrl_get_volume (GstSunAudioMixerCtrl * mixer,
return;
}
balance = AUDIO_MID_BALANCE;
gain = 0;
switch (sunaudiotrack->track_num) {
case GST_SUNAUDIO_TRACK_OUTPUT:
gain = (int) audioinfo.play.gain;
balance = audioinfo.play.balance;
break;
case GST_SUNAUDIO_TRACK_LINE_IN:
case GST_SUNAUDIO_TRACK_RECORD:
gain = (int) audioinfo.record.gain;
balance = audioinfo.record.balance;
break;
@ -201,46 +237,54 @@ gst_sunaudiomixer_ctrl_get_volume (GstSunAudioMixerCtrl * mixer,
gain = (int) audioinfo.monitor_gain;
balance = audioinfo.record.balance;
break;
case GST_SUNAUDIO_TRACK_SPEAKER:
if (audioinfo.play.port & AUDIO_SPEAKER)
gain = AUDIO_MAX_GAIN;
break;
case GST_SUNAUDIO_TRACK_HP:
if (audioinfo.play.port & AUDIO_HEADPHONE)
gain = AUDIO_MAX_GAIN;
break;
case GST_SUNAUDIO_TRACK_LINEOUT:
if (audioinfo.play.port & AUDIO_LINE_OUT)
gain = AUDIO_MAX_GAIN;
break;
case GST_SUNAUDIO_TRACK_SPDIFOUT:
if (audioinfo.play.port & AUDIO_SPDIF_OUT)
gain = AUDIO_MAX_GAIN;
break;
case GST_SUNAUDIO_TRACK_AUX1OUT:
if (audioinfo.play.port & AUDIO_AUX1_OUT)
gain = AUDIO_MAX_GAIN;
break;
case GST_SUNAUDIO_TRACK_AUX2OUT:
if (audioinfo.play.port & AUDIO_AUX2_OUT)
gain = AUDIO_MAX_GAIN;
break;
default:
g_assert_not_reached ();
break;
}
if (balance == AUDIO_MID_BALANCE) {
volumes[0] = gain;
volumes[1] = gain;
} else if (balance < AUDIO_MID_BALANCE) {
volumes[0] = gain;
ratio = 1 - (float) (AUDIO_MID_BALANCE - balance) /
(float) AUDIO_MID_BALANCE;
volumes[1] = (int) ((float) gain * ratio + 0.5);
} else {
volumes[1] = gain;
ratio = 1 - (float) (balance - AUDIO_MID_BALANCE) /
(float) AUDIO_MID_BALANCE;
volumes[0] = (int) ((float) gain * ratio + 0.5);
}
/*
* Reset whether we are recording from microphone or from line-in.
* This can change if another program resets the value (such as
* sdtaudiocontrol), so it is good to update the flag when we
* get the volume. The gnome-volume-control program calls this
* function in a loop so the value will update properly when
* changed.
*/
if ((audioinfo.record.port == AUDIO_MICROPHONE &&
!GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)) ||
(audioinfo.record.port == AUDIO_LINE_IN &&
GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD))) {
if (audioinfo.record.port == AUDIO_MICROPHONE) {
mixer->recdevs |= (1 << GST_SUNAUDIO_TRACK_LINE_IN);
track->flags |= GST_MIXER_TRACK_RECORD;
} else {
mixer->recdevs &= ~(1 << GST_SUNAUDIO_TRACK_LINE_IN);
track->flags &= ~GST_MIXER_TRACK_RECORD;
}
switch (track->num_channels) {
case 2:
if (balance == AUDIO_MID_BALANCE) {
volumes[0] = gain;
volumes[1] = gain;
} else if (balance < AUDIO_MID_BALANCE) {
volumes[0] = gain;
ratio = 1 - (float) (AUDIO_MID_BALANCE - balance) /
(float) AUDIO_MID_BALANCE;
volumes[1] = (int) ((float) gain * ratio + 0.5);
} else {
volumes[1] = gain;
ratio = 1 - (float) (balance - AUDIO_MID_BALANCE) /
(float) AUDIO_MID_BALANCE;
volumes[0] = (int) ((float) gain * ratio + 0.5);
}
break;
case 1:
volumes[0] = gain;
break;
}
/* Likewise reset MUTE */
@ -314,7 +358,7 @@ gst_sunaudiomixer_ctrl_set_volume (GstSunAudioMixerCtrl * mixer,
audioinfo.play.gain = gain;
audioinfo.play.balance = balance;
break;
case GST_SUNAUDIO_TRACK_LINE_IN:
case GST_SUNAUDIO_TRACK_RECORD:
audioinfo.record.gain = gain;
audioinfo.record.balance = balance;
break;
@ -322,6 +366,8 @@ gst_sunaudiomixer_ctrl_set_volume (GstSunAudioMixerCtrl * mixer,
audioinfo.monitor_gain = gain;
audioinfo.record.balance = balance;
break;
default:
break;
}
g_return_if_fail (mixer->mixer_fd != -1);
@ -337,11 +383,17 @@ gst_sunaudiomixer_ctrl_set_mute (GstSunAudioMixerCtrl * mixer,
GstMixerTrack * track, gboolean mute)
{
struct audio_info audioinfo;
struct audio_info oldinfo;
GstSunAudioMixerTrack *sunaudiotrack = GST_SUNAUDIO_MIXER_TRACK (track);
gint volume, balance;
AUDIO_INITINFO (&audioinfo);
if (ioctl (mixer->mixer_fd, AUDIO_GETINFO, &oldinfo) < 0) {
g_warning ("Error getting audio device volume");
return;
}
if (mute) {
volume = 0;
track->flags |= GST_MIXER_TRACK_MUTE;
@ -354,7 +406,6 @@ gst_sunaudiomixer_ctrl_set_mute (GstSunAudioMixerCtrl * mixer,
switch (sunaudiotrack->track_num) {
case GST_SUNAUDIO_TRACK_OUTPUT:
if (mute)
audioinfo.output_muted = 1;
else
@ -363,7 +414,7 @@ gst_sunaudiomixer_ctrl_set_mute (GstSunAudioMixerCtrl * mixer,
audioinfo.play.gain = volume;
audioinfo.play.balance = balance;
break;
case GST_SUNAUDIO_TRACK_LINE_IN:
case GST_SUNAUDIO_TRACK_RECORD:
audioinfo.record.gain = volume;
audioinfo.record.balance = balance;
break;
@ -371,12 +422,62 @@ gst_sunaudiomixer_ctrl_set_mute (GstSunAudioMixerCtrl * mixer,
audioinfo.monitor_gain = volume;
audioinfo.record.balance = balance;
break;
case GST_SUNAUDIO_TRACK_SPEAKER:
if (mute) {
audioinfo.play.port = oldinfo.play.port & ~AUDIO_SPEAKER;
} else {
audioinfo.play.port = oldinfo.play.port | AUDIO_SPEAKER;
}
break;
case GST_SUNAUDIO_TRACK_HP:
if (mute) {
audioinfo.play.port = oldinfo.play.port & ~AUDIO_HEADPHONE;
} else {
audioinfo.play.port = oldinfo.play.port | AUDIO_HEADPHONE;
}
break;
case GST_SUNAUDIO_TRACK_LINEOUT:
if (mute) {
audioinfo.play.port = oldinfo.play.port & ~AUDIO_LINE_OUT;
} else {
audioinfo.play.port = oldinfo.play.port | AUDIO_LINE_OUT;
}
break;
case GST_SUNAUDIO_TRACK_SPDIFOUT:
if (mute) {
audioinfo.play.port = oldinfo.play.port & ~AUDIO_SPDIF_OUT;
} else {
audioinfo.play.port = oldinfo.play.port | AUDIO_SPDIF_OUT;
}
break;
case GST_SUNAUDIO_TRACK_AUX1OUT:
if (mute) {
audioinfo.play.port = oldinfo.play.port & ~AUDIO_AUX1_OUT;
} else {
audioinfo.play.port = oldinfo.play.port | AUDIO_AUX1_OUT;
}
break;
case GST_SUNAUDIO_TRACK_AUX2OUT:
if (mute) {
audioinfo.play.port = oldinfo.play.port & ~AUDIO_AUX2_OUT;
} else {
audioinfo.play.port = oldinfo.play.port | AUDIO_AUX2_OUT;
}
break;
default:
break;
}
if (audioinfo.play.port != ((unsigned) ~0)) {
/* mask off ports we can't modify */
audioinfo.play.port &= oldinfo.play.mod_ports;
/* and add in any that are forced to be on */
audioinfo.play.port |= (oldinfo.play.port & ~oldinfo.play.mod_ports);
}
g_return_if_fail (mixer->mixer_fd != -1);
if (ioctl (mixer->mixer_fd, AUDIO_SETINFO, &audioinfo) < 0) {
g_warning ("Error setting audio device volume");
g_warning ("Error setting audio settings");
return;
}
}
@ -385,43 +486,85 @@ void
gst_sunaudiomixer_ctrl_set_record (GstSunAudioMixerCtrl * mixer,
GstMixerTrack * track, gboolean record)
{
GstSunAudioMixerTrack *sunaudiotrack = GST_SUNAUDIO_MIXER_TRACK (track);
}
void
gst_sunaudiomixer_ctrl_set_option (GstSunAudioMixerCtrl * mixer,
GstMixerOptions * options, gchar * value)
{
struct audio_info audioinfo;
GList *trk;
/* Don't change the setting */
if ((record && GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)) ||
(!record && !GST_MIXER_TRACK_HAS_FLAG (track, GST_MIXER_TRACK_RECORD)))
return;
/*
* So there is probably no need to look for others, but reset them all
* to being off.
*/
for (trk = mixer->tracklist; trk != NULL; trk = trk->next) {
GstMixerTrack *turn = (GstMixerTrack *) trk->data;
turn->flags &= ~GST_MIXER_TRACK_RECORD;
}
mixer->recdevs = 0;
/* Set the port */
AUDIO_INITINFO (&audioinfo);
if (record) {
audioinfo.record.port = AUDIO_MICROPHONE;
mixer->recdevs |= (1 << sunaudiotrack->track_num);
track->flags |= GST_MIXER_TRACK_RECORD;
} else {
audioinfo.record.port = AUDIO_LINE_IN;
mixer->recdevs &= ~(1 << sunaudiotrack->track_num);
track->flags &= ~GST_MIXER_TRACK_RECORD;
}
GstMixerTrack *track;
GstSunAudioMixerOptions *opts;
GQuark q;
int i;
g_return_if_fail (mixer != NULL);
g_return_if_fail (mixer->mixer_fd != -1);
g_return_if_fail (value != NULL);
g_return_if_fail (GST_IS_SUNAUDIO_MIXER_OPTIONS (options));
track = GST_MIXER_TRACK (options);
opts = GST_SUNAUDIO_MIXER_OPTIONS (options);
if (opts->track_num != GST_SUNAUDIO_TRACK_RECSRC) {
g_warning ("set_option not supported on track %s", track->label);
return;
}
q = g_quark_try_string (value);
if (q == 0) {
g_warning ("unknown option '%s'", value);
return;
}
for (i = 0; i < 8; i++) {
if (opts->names[i] == q) {
break;
}
}
if (((1 << (i)) & opts->avail) == 0) {
g_warning ("Record port %s not available", g_quark_to_string (q));
return;
}
AUDIO_INITINFO (&audioinfo);
audioinfo.record.port = (1 << (i));
if (ioctl (mixer->mixer_fd, AUDIO_SETINFO, &audioinfo) < 0) {
g_warning ("Error setting audio device volume");
return;
g_warning ("Error setting audio record port");
}
}
const gchar *
gst_sunaudiomixer_ctrl_get_option (GstSunAudioMixerCtrl * mixer,
GstMixerOptions * options)
{
GstMixerTrack *track;
GstSunAudioMixerOptions *opts;
struct audio_info audioinfo;
int i;
g_return_val_if_fail (mixer != NULL, NULL);
g_return_val_if_fail (mixer->fd != -1, NULL);
g_return_val_if_fail (GST_IS_SUNAUDIO_MIXER_OPTIONS (options), NULL);
track = GST_MIXER_TRACK (options);
opts = GST_SUNAUDIO_MIXER_OPTIONS (options);
g_return_val_if_fail (opts->track_num == GST_SUNAUDIO_TRACK_RECSRC, NULL);
if (ioctl (mixer->mixer_fd, AUDIO_GETINFO, &audioinfo) < 0) {
g_warning ("Error getting audio device settings");
return (NULL);
}
for (i = 0; i < 8; i++) {
if ((1 << i) == audioinfo.record.port) {
return (g_quark_to_string (opts->names[i]));
}
}
g_warning ("Record port value %d seems illegal", audioinfo.record.port);
return (NULL);
}

View file

@ -1,7 +1,9 @@
/*
* GStreamer - SunAudio mixer interface element.
* Copyright (C) 2005,2006 Sun Microsystems, Inc.,
* Copyright (C) 2005,2006,2009 Sun Microsystems, Inc.,
* Brian Cameron <brian.cameron@sun.com>
* Copyright (C) 2009 Sun Microsystems, Inc.,
* Garrett D'Amore <garrett.damore@sun.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -39,7 +41,6 @@ struct _GstSunAudioMixerCtrl {
gint mixer_fd;
gchar * device;
gint recdevs;
};
GstSunAudioMixerCtrl* gst_sunaudiomixer_ctrl_new (const gchar *device);
@ -58,6 +59,12 @@ void gst_sunaudiomixer_ctrl_set_record (GstSunAudioMixerCtrl
void gst_sunaudiomixer_ctrl_set_mute (GstSunAudioMixerCtrl * mixer,
GstMixerTrack * track,
gboolean mute);
void gst_sunaudiomixer_ctrl_set_option (GstSunAudioMixerCtrl * mixer,
GstMixerOptions * options,
gchar * value);
const gchar * gst_sunaudiomixer_ctrl_get_option (GstSunAudioMixerCtrl * mixer,
GstMixerOptions * options);
GstMixerFlags gst_sunaudiomixer_ctrl_get_mixer_flags (GstSunAudioMixerCtrl *mixer);
#define GST_IMPLEMENT_SUNAUDIO_MIXER_CTRL_METHODS(Type, interface_as_function) \
static gboolean \
@ -126,7 +133,41 @@ interface_as_function ## _set_mute (GstMixer * mixer, GstMixerTrack * track,
\
gst_sunaudiomixer_ctrl_set_mute (this->mixer, track, mute); \
} \
\
static const gchar * \
interface_as_function ## _get_option (GstMixer * mixer, GstMixerOptions * opts) \
{ \
Type *this = (Type*) mixer; \
\
g_return_val_if_fail (this != NULL, NULL); \
g_return_val_if_fail (this->mixer != NULL, NULL); \
\
return gst_sunaudiomixer_ctrl_get_option (this->mixer, opts); \
} \
\
static void \
interface_as_function ## _set_option (GstMixer * mixer, GstMixerOptions * opts, \
gchar * value) \
{ \
Type *this = (Type*) mixer; \
\
g_return_if_fail (this != NULL); \
g_return_if_fail (this->mixer != NULL); \
\
gst_sunaudiomixer_ctrl_set_option (this->mixer, opts, value); \
} \
\
static GstMixerFlags \
interface_as_function ## _get_mixer_flags (GstMixer * mixer) \
{ \
Type *this = (Type*) mixer; \
\
g_return_val_if_fail (this != NULL, GST_MIXER_FLAG_NONE); \
g_return_val_if_fail (this->mixer != NULL, GST_MIXER_FLAG_NONE); \
\
return gst_sunaudiomixer_ctrl_get_mixer_flags (this->mixer); \
} \
\
static void \
interface_as_function ## _interface_init (GstMixerClass * klass) \
{ \
@ -138,6 +179,9 @@ interface_as_function ## _interface_init (GstMixerClass * klass)
klass->get_volume = interface_as_function ## _get_volume; \
klass->set_mute = interface_as_function ## _set_mute; \
klass->set_record = interface_as_function ## _set_record; \
klass->get_option = interface_as_function ## _get_option; \
klass->set_option = interface_as_function ## _set_option; \
klass->get_mixer_flags = interface_as_function ## _get_mixer_flags; \
}
G_END_DECLS

View file

@ -0,0 +1,149 @@
/*
* GStreamer SunAudio mixer track implementation
* Copyright (C) 2009 Sun Microsystems, Inc.,
* Brian Cameron <brian.cameron@sun.com>
* Garrett D'Amore <garrett.damore@sun.com>
*
* gstsunaudiomixeroptions.c: Sun Audio mixer options object
*
* 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/audio.h>
#include <sys/mixer.h>
#include <gst/gst-i18n-plugin.h>
#include "gstsunaudiomixeroptions.h"
#include "gstsunaudiomixertrack.h"
static void gst_sunaudiomixer_options_init (GstSunAudioMixerOptions * sun_opts);
static void gst_sunaudiomixer_options_class_init (gpointer g_class,
gpointer class_data);
static GstMixerOptionsClass *parent_class = NULL;
GType
gst_sunaudiomixer_options_get_type (void)
{
static GType opts_type = 0;
if (!opts_type) {
static const GTypeInfo opts_info = {
sizeof (GstSunAudioMixerOptionsClass),
NULL,
NULL,
gst_sunaudiomixer_options_class_init,
NULL,
NULL,
sizeof (GstSunAudioMixerOptions),
0,
(GInstanceInitFunc) gst_sunaudiomixer_options_init,
};
opts_type =
g_type_register_static (GST_TYPE_MIXER_OPTIONS,
"GstSunAudioMixerOptions", &opts_info, 0);
}
return opts_type;
}
static void
gst_sunaudiomixer_options_class_init (gpointer g_class, gpointer class_data)
{
parent_class = g_type_class_peek_parent (g_class);
}
static void
gst_sunaudiomixer_options_init (GstSunAudioMixerOptions * sun_opts)
{
}
GstMixerOptions *
gst_sunaudiomixer_options_new (GstSunAudioMixerCtrl * mixer, gint track_num)
{
GstMixerOptions *opts;
GstSunAudioMixerOptions *sun_opts;
GstMixerTrack *track;
const gchar *label;
gint i;
struct audio_info audioinfo;
if ((mixer == NULL) || (mixer->mixer_fd == -1)) {
g_warning ("mixer not initialized");
return NULL;
}
if (track_num != GST_SUNAUDIO_TRACK_RECSRC) {
g_warning ("invalid options track");
return (NULL);
}
label = N_("Record Source");
opts = g_object_new (GST_TYPE_SUNAUDIO_MIXER_OPTIONS,
"untranslated-label", label, NULL);
sun_opts = GST_SUNAUDIO_MIXER_OPTIONS (opts);
track = GST_MIXER_TRACK (opts);
/* save off names for the record sources */
sun_opts->names[0] = g_quark_from_string (_("Microphone"));
sun_opts->names[1] = g_quark_from_string (_("Line In"));
sun_opts->names[2] = g_quark_from_string (_("Internal CD"));
sun_opts->names[3] = g_quark_from_string (_("SPDIF In"));
sun_opts->names[4] = g_quark_from_string (_("AUX 1 In"));
sun_opts->names[5] = g_quark_from_string (_("AUX 2 In"));
sun_opts->names[6] = g_quark_from_string (_("Codec Loopback"));
sun_opts->names[7] = g_quark_from_string (_("SunVTS Loopback"));
/* set basic information */
track->label = g_strdup (_(label));
track->num_channels = 0;
track->min_volume = 0;
track->max_volume = 0;
track->flags =
GST_MIXER_TRACK_INPUT | GST_MIXER_TRACK_WHITELIST |
GST_MIXER_TRACK_NO_RECORD;
if (ioctl (mixer->mixer_fd, AUDIO_GETINFO, &audioinfo) < 0) {
g_warning ("Error getting audio device settings");
g_object_unref (G_OBJECT (sun_opts));
return NULL;
}
sun_opts->avail = audioinfo.record.avail_ports;
sun_opts->track_num = track_num;
for (i = 0; i < 8; i++) {
if ((1 << i) & audioinfo.record.avail_ports) {
const char *s = g_quark_to_string (sun_opts->names[i]);
opts->values = g_list_append (opts->values, g_strdup (s));
}
}
return opts;
}

View file

@ -0,0 +1,65 @@
/*
* GStreamer SunAudio mixer track implementation
* Copyright (C) 2009 Sun Microsystems, Inc.,
* Brian Cameron <brian.cameron@sun.com>
* Garrett D'Amore <garrett.damore@sun.com>
*
* gstsunaudiomixeroptions.h: Sun Audio mixer options object
*
* 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,
*/
#ifndef __GST_SUNAUDIO_MIXER_OPTIONS_H__
#define __GST_SUNAUDIO_MIXER_OPTIONS_H__
#include "gstsunaudiomixer.h"
#include <gst/interfaces/mixeroptions.h>
G_BEGIN_DECLS
#define GST_SUNAUDIO_MIXER_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SUNAUDIO_MIXER_OPTIONS, GstSunAudioMixerOptions))
#define GST_SUNAUDIO_MIXER_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SUNAUDIO_MIXER_OPTIONS, GstSunAudioMixerOptionsClass))
#define GST_IS_SUNAUDIO_MIXER_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SUNAUDIO_MIXER_OPTIONS))
#define GST_IS_SUNAUDIO_MIXER_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SUNAUDIO_MIXER_OPTIONS))
#define GST_TYPE_SUNAUDIO_MIXER_OPTIONS (gst_sunaudiomixer_options_get_type())
typedef struct _GstSunAudioMixerOptions GstSunAudioMixerOptions;
typedef struct _GstSunAudioMixerOptionsClass GstSunAudioMixerOptionsClass;
struct _GstSunAudioMixerOptions {
GstMixerOptions parent;
gint track_num;
GQuark names[8]; /* only 8 possible */
gint avail; /* mask of avail */
};
struct _GstSunAudioMixerOptionsClass {
GstMixerOptionsClass parent;
};
GType gst_sunaudiomixer_options_get_type (void);
GstMixerOptions *gst_sunaudiomixer_options_new (GstSunAudioMixerCtrl *mixer, gint track_num);
G_END_DECLS
#endif /* __GST_SUNAUDIO_MIXER_OPTIONS_H__ */

View file

@ -1,7 +1,9 @@
/*
* GStreamer
* Copyright (C) 2005,2008 Sun Microsystems, Inc.,
* Copyright (C) 2005,2008, 2009 Sun Microsystems, Inc.,
* Brian Cameron <brian.cameron@sun.com>
* Copyright (C) 2009 Sun Microsystems, Inc.,
* Garrett D'Amore <garrett.damore@sun.com>
*
* gstsunaudiomixer.c: mixer interface implementation for OSS
*
@ -59,10 +61,19 @@ gst_sunaudiomixer_track_init (GstSunAudioMixerTrack * track)
}
GstMixerTrack *
gst_sunaudiomixer_track_new (GstSunAudioTrackType track_num,
gint max_chans, gint flags)
gst_sunaudiomixer_track_new (GstSunAudioTrackType track_num)
{
const gchar *labels[] = { N_("Volume"), N_("Gain"), N_("Monitor") };
const gchar *labels[] = { N_("Volume"),
N_("Gain"),
N_("Monitor"),
N_("Built-in Speaker"),
N_("Headphone"),
N_("Line Out"),
N_("SPDIF Out"),
N_("AUX 1 Out"),
N_("AUX 2 Out"),
};
GstSunAudioMixerTrack *sunaudiotrack;
GstMixerTrack *track;
@ -84,15 +95,66 @@ gst_sunaudiomixer_track_new (GstSunAudioTrackType track_num,
}
g_type_class_unref (klass);
track = GST_MIXER_TRACK (sunaudiotrack);
track->label = g_strdup (_(untranslated_label));
track->num_channels = max_chans;
track->flags = flags;
track->min_volume = 0;
track->max_volume = 255;
sunaudiotrack->track_num = track_num;
sunaudiotrack->gain = (0 & 0xff);
sunaudiotrack->balance = AUDIO_MID_BALANCE;
switch (track_num) {
case GST_SUNAUDIO_TRACK_OUTPUT:
/* these are sliders */
track = GST_MIXER_TRACK (sunaudiotrack);
track->label = g_strdup (_(untranslated_label));
track->num_channels = 2;
track->flags = GST_MIXER_TRACK_OUTPUT | GST_MIXER_TRACK_WHITELIST |
GST_MIXER_TRACK_MASTER;
track->min_volume = 0;
track->max_volume = 255;
sunaudiotrack->track_num = track_num;
sunaudiotrack->gain = (0 & 0xff);
sunaudiotrack->balance = AUDIO_MID_BALANCE;
break;
case GST_SUNAUDIO_TRACK_RECORD:
/* these are sliders */
track = GST_MIXER_TRACK (sunaudiotrack);
track->label = g_strdup (_(untranslated_label));
track->num_channels = 2;
track->flags = GST_MIXER_TRACK_INPUT | GST_MIXER_TRACK_NO_RECORD |
GST_MIXER_TRACK_WHITELIST;
track->min_volume = 0;
track->max_volume = 255;
sunaudiotrack->track_num = track_num;
sunaudiotrack->gain = (0 & 0xff);
sunaudiotrack->balance = AUDIO_MID_BALANCE;
break;
case GST_SUNAUDIO_TRACK_MONITOR:
/* these are sliders */
track = GST_MIXER_TRACK (sunaudiotrack);
track->label = g_strdup (_(untranslated_label));
track->num_channels = 2;
track->flags = GST_MIXER_TRACK_INPUT | GST_MIXER_TRACK_NO_RECORD;
track->min_volume = 0;
track->max_volume = 255;
sunaudiotrack->track_num = track_num;
sunaudiotrack->gain = (0 & 0xff);
sunaudiotrack->balance = AUDIO_MID_BALANCE;
break;
case GST_SUNAUDIO_TRACK_SPEAKER:
case GST_SUNAUDIO_TRACK_HP:
case GST_SUNAUDIO_TRACK_LINEOUT:
case GST_SUNAUDIO_TRACK_SPDIFOUT:
case GST_SUNAUDIO_TRACK_AUX1OUT:
case GST_SUNAUDIO_TRACK_AUX2OUT:
/* these are switches */
track = GST_MIXER_TRACK (sunaudiotrack);
track->label = g_strdup (_(untranslated_label));
track->num_channels = 0;
track->flags = GST_MIXER_TRACK_OUTPUT | GST_MIXER_TRACK_WHITELIST;
track->min_volume = 0;
track->max_volume = 255;
sunaudiotrack->track_num = track_num;
sunaudiotrack->gain = (0 & 0xff);
sunaudiotrack->balance = AUDIO_MID_BALANCE;
break;
default:
g_warning ("Unknown sun audio track num %d", track_num);
track = NULL;
}
return track;
}

View file

@ -1,7 +1,9 @@
/*
* GStreamer SunAudio mixer track implementation
* Copyright (C) 2005,2006 Sun Microsystems, Inc.,
* Copyright (C) 2005,2006,2009 Sun Microsystems, Inc.,
* Brian Cameron <brian.cameron@sun.com>
* Copyright (C) 2009 Sun Microsystems, Inc.,
* Garrett D'Amore <garrett.damore@sun.com>
*
* gstsunaudiomixertrack.h: SunAudio mixer tracks
*
@ -32,12 +34,17 @@ G_BEGIN_DECLS
typedef enum
{
GST_SUNAUDIO_TRACK_OUTPUT = 0,
GST_SUNAUDIO_TRACK_LINE_IN = 1,
GST_SUNAUDIO_TRACK_MONITOR = 2,
GST_SUNAUDIO_TRACK_RECORD,
GST_SUNAUDIO_TRACK_MONITOR,
GST_SUNAUDIO_TRACK_SPEAKER,
GST_SUNAUDIO_TRACK_HP,
GST_SUNAUDIO_TRACK_LINEOUT,
GST_SUNAUDIO_TRACK_SPDIFOUT,
GST_SUNAUDIO_TRACK_AUX1OUT,
GST_SUNAUDIO_TRACK_AUX2OUT,
GST_SUNAUDIO_TRACK_RECSRC
} GstSunAudioTrackType;
#define MIXER_DEVICES 3
#define GST_TYPE_SUNAUDIO_MIXER_TRACK \
(gst_sunaudiomixer_track_get_type ())
#define GST_SUNAUDIO_MIXER_TRACK(obj) \
@ -64,7 +71,7 @@ typedef struct _GstSunAudioMixerTrackClass {
} GstSunAudioMixerTrackClass;
GType gst_sunaudiomixer_track_get_type (void);
GstMixerTrack* gst_sunaudiomixer_track_new (GstSunAudioTrackType track_num, gint max_chans, gint flags);
GstMixerTrack* gst_sunaudiomixer_track_new (GstSunAudioTrackType track_num);
G_END_DECLS