2004-02-24 00:41:20 +01:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-02-24 00:41:20 +01:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "audio.h"
|
2008-09-07 19:19:55 +02:00
|
|
|
#include "audio_format.h"
|
2008-09-07 22:41:22 +02:00
|
|
|
#include "output_api.h"
|
2008-09-09 10:02:34 +02:00
|
|
|
#include "output_control.h"
|
2008-09-24 07:20:55 +02:00
|
|
|
#include "output_internal.h"
|
2008-04-12 06:19:26 +02:00
|
|
|
#include "path.h"
|
2008-10-14 22:38:14 +02:00
|
|
|
#include "idle.h"
|
2009-01-04 17:35:51 +01:00
|
|
|
#include "mixer_api.h"
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2008-10-28 20:33:56 +01:00
|
|
|
#include <glib.h>
|
|
|
|
|
2008-12-29 17:28:32 +01:00
|
|
|
#include <assert.h>
|
2009-01-03 13:36:20 +01:00
|
|
|
#include <stdlib.h>
|
2008-12-29 17:28:32 +01:00
|
|
|
|
2008-10-12 01:00:00 +02:00
|
|
|
static struct audio_format configured_audio_format;
|
|
|
|
static struct audio_format input_audio_format;
|
2004-05-10 04:20:15 +02:00
|
|
|
|
2008-09-07 22:41:22 +02:00
|
|
|
static struct audio_output *audioOutputArray;
|
2008-03-26 11:37:54 +01:00
|
|
|
static unsigned int audioOutputArraySize;
|
2006-08-01 12:07:12 +02:00
|
|
|
|
2008-12-31 15:10:53 +01:00
|
|
|
unsigned int audio_output_count(void)
|
2009-02-10 17:21:10 +01:00
|
|
|
{
|
|
|
|
return audioOutputArraySize;
|
|
|
|
}
|
|
|
|
|
2009-02-10 17:21:19 +01:00
|
|
|
struct audio_output *
|
|
|
|
audio_output_get(unsigned i)
|
|
|
|
{
|
|
|
|
assert(i < audioOutputArraySize);
|
|
|
|
|
|
|
|
return &audioOutputArray[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
struct audio_output *
|
|
|
|
audio_output_find(const char *name)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < audioOutputArraySize; ++i) {
|
|
|
|
struct audio_output *ao = audio_output_get(i);
|
|
|
|
|
|
|
|
if (strcmp(ao->name, name) == 0)
|
|
|
|
return ao;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* name not found */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-10 17:21:10 +01:00
|
|
|
static unsigned
|
|
|
|
audio_output_config_count(void)
|
2006-08-01 12:07:07 +02:00
|
|
|
{
|
2008-03-26 11:38:21 +01:00
|
|
|
unsigned int nr = 0;
|
2009-01-25 16:03:49 +01:00
|
|
|
const struct config_param *param = NULL;
|
2006-08-01 12:07:07 +02:00
|
|
|
|
2009-01-17 20:23:27 +01:00
|
|
|
while ((param = config_get_next_param(CONF_AUDIO_OUTPUT, param)))
|
2006-08-01 12:07:07 +02:00
|
|
|
nr++;
|
|
|
|
if (!nr)
|
|
|
|
nr = 1; /* we'll always have at least one device */
|
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
|
2006-07-16 16:57:26 +02:00
|
|
|
/* make sure initPlayerData is called before this function!! */
|
2006-07-20 18:02:40 +02:00
|
|
|
void initAudioDriver(void)
|
|
|
|
{
|
2009-01-25 16:03:49 +01:00
|
|
|
const struct config_param *param = NULL;
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2006-07-16 16:57:26 +02:00
|
|
|
|
2008-12-27 20:53:52 +01:00
|
|
|
notify_init(&audio_output_client_notify);
|
|
|
|
|
2009-02-10 17:21:10 +01:00
|
|
|
audioOutputArraySize = audio_output_config_count();
|
2009-01-03 13:36:20 +01:00
|
|
|
audioOutputArray = g_new(struct audio_output, audioOutputArraySize);
|
2004-11-02 22:48:53 +01:00
|
|
|
|
2006-10-03 04:57:01 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; i++)
|
|
|
|
{
|
2008-09-07 22:41:22 +02:00
|
|
|
struct audio_output *output = &audioOutputArray[i];
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int j;
|
2006-03-18 04:58:31 +01:00
|
|
|
|
2009-01-17 20:23:27 +01:00
|
|
|
param = config_get_next_param(CONF_AUDIO_OUTPUT, param);
|
2006-10-03 04:57:01 +02:00
|
|
|
|
2006-10-03 05:06:30 +02:00
|
|
|
/* only allow param to be NULL if there just one audioOutput */
|
|
|
|
assert(param || (audioOutputArraySize == 1));
|
|
|
|
|
2008-09-09 10:03:24 +02:00
|
|
|
if (!audio_output_init(output, param)) {
|
2006-10-03 04:57:01 +02:00
|
|
|
if (param)
|
|
|
|
{
|
2008-11-25 17:47:46 +01:00
|
|
|
g_error("problems configuring output device "
|
|
|
|
"defined at line %i\n", param->line);
|
2006-10-03 04:57:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-25 17:47:46 +01:00
|
|
|
g_error("No audio_output specified and unable to "
|
|
|
|
"detect a default audio output device\n");
|
2006-10-03 04:57:01 +02:00
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2006-03-18 04:58:31 +01:00
|
|
|
|
|
|
|
/* require output names to be unique: */
|
2006-10-03 04:57:01 +02:00
|
|
|
for (j = 0; j < i; j++) {
|
2006-08-01 12:07:16 +02:00
|
|
|
if (!strcmp(output->name, audioOutputArray[j].name)) {
|
2008-11-25 17:47:46 +01:00
|
|
|
g_error("output devices with identical "
|
|
|
|
"names: %s\n", output->name);
|
2006-03-18 04:58:31 +01:00
|
|
|
}
|
|
|
|
}
|
2006-10-03 04:57:01 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 19:19:55 +02:00
|
|
|
void getOutputAudioFormat(const struct audio_format *inAudioFormat,
|
|
|
|
struct audio_format *outAudioFormat)
|
2004-05-10 04:20:15 +02:00
|
|
|
{
|
2008-10-12 01:00:00 +02:00
|
|
|
*outAudioFormat = audio_format_defined(&configured_audio_format)
|
|
|
|
? configured_audio_format
|
2008-09-09 10:04:42 +02:00
|
|
|
: *inAudioFormat;
|
2004-05-10 04:20:15 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void initAudioConfig(void)
|
|
|
|
{
|
2009-01-25 16:03:49 +01:00
|
|
|
const struct config_param *param = config_get_param(CONF_AUDIO_OUTPUT_FORMAT);
|
2004-05-10 04:20:15 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (NULL == param || NULL == param->value)
|
|
|
|
return;
|
2004-05-10 04:20:15 +02:00
|
|
|
|
2008-10-12 01:00:00 +02:00
|
|
|
if (0 != parseAudioConfig(&configured_audio_format, param->value)) {
|
2008-11-25 17:47:46 +01:00
|
|
|
g_error("error parsing \"%s\" at line %i\n",
|
|
|
|
CONF_AUDIO_OUTPUT_FORMAT, param->line);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2004-10-23 03:04:58 +02:00
|
|
|
}
|
|
|
|
|
2008-09-07 19:19:55 +02:00
|
|
|
int parseAudioConfig(struct audio_format *audioFormat, char *conf)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
char *test;
|
|
|
|
|
2008-09-07 19:19:55 +02:00
|
|
|
memset(audioFormat, 0, sizeof(*audioFormat));
|
2004-10-23 03:04:58 +02:00
|
|
|
|
2008-10-10 14:40:54 +02:00
|
|
|
audioFormat->sample_rate = strtol(conf, &test, 10);
|
2004-05-10 04:20:15 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (*test != ':') {
|
2008-11-25 17:47:46 +01:00
|
|
|
g_warning("error parsing audio output format: %s\n", conf);
|
2004-10-23 03:04:58 +02:00
|
|
|
return -1;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-10 14:40:54 +02:00
|
|
|
if (audioFormat->sample_rate <= 0) {
|
2008-11-25 17:47:46 +01:00
|
|
|
g_warning("sample rate %u is not >= 0\n",
|
|
|
|
audioFormat->sample_rate);
|
2004-10-23 03:04:58 +02:00
|
|
|
return -1;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-10 14:03:33 +02:00
|
|
|
audioFormat->bits = (uint8_t)strtoul(test + 1, &test, 10);
|
2004-05-10 04:20:15 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (*test != ':') {
|
2008-11-25 17:47:46 +01:00
|
|
|
g_warning("error parsing audio output format: %s\n", conf);
|
2004-10-23 03:04:58 +02:00
|
|
|
return -1;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
|
|
|
|
2008-10-23 16:57:58 +02:00
|
|
|
if (audioFormat->bits != 16 && audioFormat->bits != 24 &&
|
|
|
|
audioFormat->bits != 8) {
|
2008-11-25 17:47:46 +01:00
|
|
|
g_warning("bits %u can not be used for audio output\n",
|
|
|
|
audioFormat->bits);
|
2004-10-23 03:04:58 +02:00
|
|
|
return -1;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
2004-05-10 04:20:15 +02:00
|
|
|
|
2008-10-10 14:03:33 +02:00
|
|
|
audioFormat->channels = (uint8_t)strtoul(test + 1, &test, 10);
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
if (*test != '\0') {
|
2008-11-25 17:47:46 +01:00
|
|
|
g_warning("error parsing audio output format: %s\n", conf);
|
2004-10-23 03:04:58 +02:00
|
|
|
return -1;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
2004-05-10 04:20:15 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
switch (audioFormat->channels) {
|
2004-10-23 03:04:58 +02:00
|
|
|
case 1:
|
2006-07-20 18:02:40 +02:00
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
default:
|
2008-11-25 17:47:46 +01:00
|
|
|
g_warning("channels %u can not be used for audio output\n",
|
|
|
|
audioFormat->channels);
|
2004-10-23 03:04:58 +02:00
|
|
|
return -1;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
2004-10-23 03:04:58 +02:00
|
|
|
|
|
|
|
return 0;
|
2004-05-10 04:20:15 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void finishAudioConfig(void)
|
|
|
|
{
|
2008-10-12 01:00:00 +02:00
|
|
|
audio_format_clear(&configured_audio_format);
|
2004-05-10 04:20:15 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void finishAudioDriver(void)
|
|
|
|
{
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; i++) {
|
2008-09-09 10:03:24 +02:00
|
|
|
audio_output_finish(&audioOutputArray[i]);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
2009-01-25 18:47:21 +01:00
|
|
|
g_free(audioOutputArray);
|
2004-10-28 07:14:55 +02:00
|
|
|
audioOutputArray = NULL;
|
2004-11-03 00:08:00 +01:00
|
|
|
audioOutputArraySize = 0;
|
2008-12-27 20:53:52 +01:00
|
|
|
|
|
|
|
notify_deinit(&audio_output_client_notify);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-09-24 07:23:19 +02:00
|
|
|
static void audio_output_wait_all(void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int finished = 1;
|
|
|
|
|
|
|
|
for (i = 0; i < audioOutputArraySize; ++i)
|
2008-09-24 07:25:07 +02:00
|
|
|
if (audio_output_is_open(&audioOutputArray[i]) &&
|
2008-09-24 07:23:19 +02:00
|
|
|
!audio_output_command_is_finished(&audioOutputArray[i]))
|
|
|
|
finished = 0;
|
|
|
|
|
|
|
|
if (finished)
|
|
|
|
break;
|
|
|
|
|
|
|
|
notify_wait(&audio_output_client_notify);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2006-08-01 14:00:17 +02:00
|
|
|
static void syncAudioDeviceStates(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2004-11-09 01:13:42 +01:00
|
|
|
|
2008-10-12 01:00:00 +02:00
|
|
|
if (!audio_format_defined(&input_audio_format))
|
2006-08-01 14:00:17 +02:00
|
|
|
return;
|
2007-06-09 23:40:56 +02:00
|
|
|
|
2008-10-29 22:17:44 +01:00
|
|
|
for (i = 0; i < audioOutputArraySize; ++i)
|
|
|
|
audio_output_update(&audioOutputArray[i], &input_audio_format);
|
2006-08-01 14:00:17 +02:00
|
|
|
}
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
bool playAudio(const char *buffer, size_t length)
|
2006-08-01 14:00:17 +02:00
|
|
|
{
|
2008-10-29 20:40:27 +01:00
|
|
|
bool ret = false;
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2006-08-01 14:00:17 +02:00
|
|
|
|
2008-11-02 20:16:56 +01:00
|
|
|
assert(length > 0);
|
2008-10-23 16:48:49 +02:00
|
|
|
/* no partial frames allowed */
|
|
|
|
assert((length % audio_format_frame_size(&input_audio_format)) == 0);
|
|
|
|
|
2006-08-01 14:00:17 +02:00
|
|
|
syncAudioDeviceStates();
|
|
|
|
|
2008-09-24 07:23:19 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; ++i)
|
2008-09-24 07:25:07 +02:00
|
|
|
if (audio_output_is_open(&audioOutputArray[i]))
|
2008-09-24 07:23:19 +02:00
|
|
|
audio_output_play(&audioOutputArray[i],
|
2008-10-12 00:42:33 +02:00
|
|
|
buffer, length);
|
2008-09-24 07:23:19 +02:00
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
while (true) {
|
|
|
|
bool finished = true;
|
2008-09-24 07:23:19 +02:00
|
|
|
|
|
|
|
for (i = 0; i < audioOutputArraySize; ++i) {
|
2008-09-26 07:12:29 +02:00
|
|
|
struct audio_output *ao = &audioOutputArray[i];
|
2008-09-24 07:23:19 +02:00
|
|
|
|
2008-09-24 07:25:07 +02:00
|
|
|
if (!audio_output_is_open(ao))
|
2008-09-24 07:23:19 +02:00
|
|
|
continue;
|
|
|
|
|
2008-10-29 22:34:37 +01:00
|
|
|
if (audio_output_command_is_finished(ao))
|
|
|
|
ret = true;
|
|
|
|
else {
|
2008-10-29 20:40:27 +01:00
|
|
|
finished = false;
|
2008-09-26 07:12:29 +02:00
|
|
|
audio_output_signal(ao);
|
|
|
|
}
|
2008-09-24 07:23:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (finished)
|
|
|
|
break;
|
|
|
|
|
|
|
|
notify_wait(&audio_output_client_notify);
|
|
|
|
};
|
2004-11-09 01:13:42 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
bool openAudioDevice(const struct audio_format *audioFormat)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-29 20:40:27 +01:00
|
|
|
bool ret = false;
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!audioOutputArray)
|
2008-10-29 20:40:27 +01:00
|
|
|
return false;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2008-10-13 14:31:18 +02:00
|
|
|
if (audioFormat != NULL)
|
2008-10-12 01:00:00 +02:00
|
|
|
input_audio_format = *audioFormat;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-08-01 14:00:17 +02:00
|
|
|
syncAudioDeviceStates();
|
|
|
|
|
2006-10-03 04:22:37 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; ++i) {
|
2006-08-01 14:00:17 +02:00
|
|
|
if (audioOutputArray[i].open)
|
2008-10-29 20:40:27 +01:00
|
|
|
ret = true;
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
if (!ret)
|
2004-11-02 22:06:44 +01:00
|
|
|
/* close all devices if there was an error */
|
2008-10-29 20:39:56 +01:00
|
|
|
closeAudioDevice();
|
2004-11-02 22:06:44 +01:00
|
|
|
|
2004-10-28 07:14:55 +02:00
|
|
|
return ret;
|
2004-10-20 18:16:50 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-09-29 16:43:55 +02:00
|
|
|
void audio_output_pause_all(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
syncAudioDeviceStates();
|
|
|
|
|
|
|
|
for (i = 0; i < audioOutputArraySize; ++i)
|
|
|
|
if (audio_output_is_open(&audioOutputArray[i]))
|
|
|
|
audio_output_pause(&audioOutputArray[i]);
|
|
|
|
|
|
|
|
audio_output_wait_all();
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void dropBufferedAudio(void)
|
|
|
|
{
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2005-03-05 15:01:13 +01:00
|
|
|
|
2006-08-01 14:00:17 +02:00
|
|
|
syncAudioDeviceStates();
|
|
|
|
|
2006-10-03 04:22:37 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; ++i) {
|
2008-09-24 07:25:07 +02:00
|
|
|
if (audio_output_is_open(&audioOutputArray[i]))
|
2008-09-09 10:03:24 +02:00
|
|
|
audio_output_cancel(&audioOutputArray[i]);
|
2005-03-05 15:01:13 +01:00
|
|
|
}
|
2008-09-24 07:23:19 +02:00
|
|
|
|
|
|
|
audio_output_wait_all();
|
2005-03-05 15:01:13 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void closeAudioDevice(void)
|
|
|
|
{
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2008-09-24 07:25:07 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; ++i)
|
2008-09-09 10:03:24 +02:00
|
|
|
audio_output_close(&audioOutputArray[i]);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-10-25 22:09:03 +02:00
|
|
|
|
2008-08-29 09:38:11 +02:00
|
|
|
void sendMetadataToAudioDevice(const struct tag *tag)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2008-09-24 07:21:58 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; ++i)
|
2008-09-24 07:25:07 +02:00
|
|
|
if (audio_output_is_open(&audioOutputArray[i]))
|
2008-09-24 07:21:58 +02:00
|
|
|
audio_output_send_tag(&audioOutputArray[i], tag);
|
2008-09-24 07:23:19 +02:00
|
|
|
|
|
|
|
audio_output_wait_all();
|
2004-10-25 22:09:03 +02:00
|
|
|
}
|
2004-11-02 22:06:44 +01:00
|
|
|
|
2008-09-07 13:51:50 +02:00
|
|
|
int enableAudioDevice(unsigned int device)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:51:50 +02:00
|
|
|
if (device >= audioOutputArraySize)
|
2004-11-02 22:06:44 +01:00
|
|
|
return -1;
|
|
|
|
|
2008-10-29 22:32:50 +01:00
|
|
|
audioOutputArray[device].reopen_after = 0;
|
2008-10-29 20:49:51 +01:00
|
|
|
audioOutputArray[device].enabled = true;
|
2008-10-14 22:38:14 +02:00
|
|
|
idle_add(IDLE_OUTPUT);
|
2004-11-02 22:06:44 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 13:51:50 +02:00
|
|
|
int disableAudioDevice(unsigned int device)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-07 13:51:50 +02:00
|
|
|
if (device >= audioOutputArraySize)
|
2004-11-02 22:06:44 +01:00
|
|
|
return -1;
|
2008-09-07 13:51:50 +02:00
|
|
|
|
2008-10-29 20:49:51 +01:00
|
|
|
audioOutputArray[device].enabled = false;
|
2008-10-14 22:38:14 +02:00
|
|
|
idle_add(IDLE_OUTPUT);
|
2004-11-02 22:06:44 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-11-03 00:08:00 +01:00
|
|
|
|
2008-12-31 16:46:41 +01:00
|
|
|
bool mixer_control_setvol(unsigned int device, int volume, int rel)
|
|
|
|
{
|
|
|
|
struct audio_output *output;
|
|
|
|
if (device >= audioOutputArraySize)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
output = &audioOutputArray[device];
|
|
|
|
if (output->plugin && output->plugin->control) {
|
|
|
|
if (rel) {
|
|
|
|
int cur_volume;
|
|
|
|
if (!output->plugin->control(output->data, AC_MIXER_GETVOL, &cur_volume)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
volume = volume + cur_volume;
|
|
|
|
}
|
|
|
|
if (volume > 100)
|
|
|
|
volume = 100;
|
|
|
|
else if (volume < 0)
|
|
|
|
volume = 0;
|
|
|
|
|
|
|
|
return output->plugin->control(output->data, AC_MIXER_SETVOL, &volume);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mixer_control_getvol(unsigned int device, int *volume)
|
|
|
|
{
|
|
|
|
struct audio_output *output;
|
|
|
|
if (device >= audioOutputArraySize)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
output = &audioOutputArray[device];
|
|
|
|
if (output->plugin && output->plugin->control) {
|
|
|
|
return output->plugin->control(output->data, AC_MIXER_GETVOL, volume);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|