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"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "log.h"
|
2008-04-12 06:19:26 +02:00
|
|
|
#include "path.h"
|
2008-09-07 14:04:16 +02:00
|
|
|
#include "client.h"
|
2008-10-14 22:38:14 +02:00
|
|
|
#include "idle.h"
|
2008-09-07 22:41:17 +02:00
|
|
|
#include "utils.h"
|
2008-01-03 08:29:49 +01:00
|
|
|
#include "os_compat.h"
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2008-10-28 20:33:56 +01:00
|
|
|
#include <glib.h>
|
|
|
|
|
2006-03-18 04:58:31 +01:00
|
|
|
#define AUDIO_DEVICE_STATE "audio_device_state:"
|
2007-12-28 03:56:25 +01:00
|
|
|
#define AUDIO_BUFFER_SIZE 2*MPD_PATH_MAX
|
2004-02-24 00:41:20 +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-06-02 12:10:26 +02:00
|
|
|
static unsigned int audio_output_count(void)
|
2006-08-01 12:07:07 +02:00
|
|
|
{
|
2008-03-26 11:38:21 +01:00
|
|
|
unsigned int nr = 0;
|
2006-08-01 12:07:07 +02:00
|
|
|
ConfigParam *param = NULL;
|
|
|
|
|
|
|
|
while ((param = getNextConfigParam(CONF_AUDIO_OUTPUT, param)))
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ConfigParam *param = NULL;
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2006-07-16 16:57:26 +02:00
|
|
|
|
2008-06-02 12:10:26 +02:00
|
|
|
audioOutputArraySize = audio_output_count();
|
2008-09-07 22:41:22 +02:00
|
|
|
audioOutputArray = xmalloc(sizeof(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
|
|
|
|
2006-10-03 04:57:01 +02:00
|
|
|
param = getNextConfigParam(CONF_AUDIO_OUTPUT, param);
|
|
|
|
|
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)
|
|
|
|
{
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("problems configuring output device "
|
2006-10-03 04:57:01 +02:00
|
|
|
"defined at line %i\n", param->line);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("No audio_output specified and unable to "
|
2006-10-03 04:57:01 +02:00
|
|
|
"detect a default audio output device\n");
|
|
|
|
}
|
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)) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("output devices with identical "
|
2006-07-20 18:02:40 +02:00
|
|
|
"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)
|
|
|
|
{
|
|
|
|
ConfigParam *param = getConfigParam(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)) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("error parsing \"%s\" at line %i\n",
|
2006-07-20 18:02:40 +02:00
|
|
|
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 != ':') {
|
|
|
|
ERROR("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) {
|
|
|
|
ERROR("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 != ':') {
|
|
|
|
ERROR("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-10-10 14:03:33 +02:00
|
|
|
ERROR("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') {
|
|
|
|
ERROR("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:
|
|
|
|
ERROR("channels %i can not be used for audio output\n",
|
|
|
|
(int)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
|
|
|
}
|
|
|
|
|
|
|
|
free(audioOutputArray);
|
|
|
|
audioOutputArray = NULL;
|
2004-11-03 00:08:00 +01:00
|
|
|
audioOutputArraySize = 0;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-10-08 11:03:39 +02:00
|
|
|
bool
|
|
|
|
isCurrentAudioFormat(const struct audio_format *audioFormat)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-09-10 11:43:40 +02:00
|
|
|
assert(audioFormat != NULL);
|
|
|
|
|
2008-10-12 01:00:00 +02:00
|
|
|
return audio_format_equals(audioFormat, &input_audio_format);
|
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-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-09-07 14:04:16 +02:00
|
|
|
void printAudioDevices(struct client *client)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2004-11-03 00:08:00 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; i++) {
|
2008-09-07 14:04:16 +02:00
|
|
|
client_printf(client,
|
|
|
|
"outputid: %i\n"
|
|
|
|
"outputname: %s\n"
|
|
|
|
"outputenabled: %i\n",
|
|
|
|
i,
|
|
|
|
audioOutputArray[i].name,
|
2008-10-29 20:49:51 +01:00
|
|
|
audioOutputArray[i].enabled);
|
2004-11-03 00:08:00 +01:00
|
|
|
}
|
|
|
|
}
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2006-07-31 01:32:47 +02:00
|
|
|
void saveAudioDevicesState(FILE *fp)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2006-03-18 04:58:31 +01:00
|
|
|
assert(audioOutputArraySize != 0);
|
2006-05-20 21:56:29 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; i++) {
|
2006-07-31 01:32:39 +02:00
|
|
|
fprintf(fp, AUDIO_DEVICE_STATE "%d:%s\n",
|
2008-10-29 20:49:51 +01:00
|
|
|
audioOutputArray[i].enabled,
|
2006-08-01 12:07:16 +02:00
|
|
|
audioOutputArray[i].name);
|
2005-08-23 14:01:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-31 01:32:47 +02:00
|
|
|
void readAudioDevicesState(FILE *fp)
|
2006-03-18 04:58:31 +01:00
|
|
|
{
|
|
|
|
char buffer[AUDIO_BUFFER_SIZE];
|
2008-03-26 11:37:54 +01:00
|
|
|
unsigned int i;
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2006-03-18 04:58:31 +01:00
|
|
|
assert(audioOutputArraySize != 0);
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
while (myFgets(buffer, AUDIO_BUFFER_SIZE, fp)) {
|
2006-03-18 04:58:31 +01:00
|
|
|
char *c, *name;
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2008-10-28 20:33:56 +01:00
|
|
|
if (!g_str_has_prefix(buffer, AUDIO_DEVICE_STATE))
|
2006-03-18 04:58:31 +01:00
|
|
|
continue;
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
c = strchr(buffer, ':');
|
2006-03-18 04:58:31 +01:00
|
|
|
if (!c || !(++c))
|
|
|
|
goto errline;
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
name = strchr(c, ':');
|
2006-03-18 04:58:31 +01:00
|
|
|
if (!name || !(++name))
|
|
|
|
goto errline;
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2006-10-03 04:22:37 +02:00
|
|
|
for (i = 0; i < audioOutputArraySize; ++i) {
|
2006-08-01 12:07:16 +02:00
|
|
|
if (!strcmp(name, audioOutputArray[i].name)) {
|
2006-08-01 12:07:12 +02:00
|
|
|
/* devices default to on */
|
|
|
|
if (!atoi(c))
|
2008-10-29 20:49:51 +01:00
|
|
|
audioOutputArray[i].enabled = false;
|
2006-03-18 04:58:31 +01:00
|
|
|
break;
|
2005-08-23 14:01:37 +02:00
|
|
|
}
|
|
|
|
}
|
2006-03-18 04:58:31 +01:00
|
|
|
continue;
|
2006-08-10 00:18:06 +02:00
|
|
|
errline:
|
2006-03-18 04:58:31 +01:00
|
|
|
/* nonfatal */
|
|
|
|
ERROR("invalid line in state_file: %s\n", buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|