diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-11-02 21:06:44 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-11-02 21:06:44 +0000 |
commit | 8b08ee82b492735947d917ed647a3e6cdf388ad3 (patch) | |
tree | d9c397cc208ace22f6119fcd7c9a042cf8c61484 | |
parent | 54679d9028117360e50a85a1f4b4f376f13ad6a3 (diff) | |
download | mpd-8b08ee82b492735947d917ed647a3e6cdf388ad3.tar.gz mpd-8b08ee82b492735947d917ed647a3e6cdf388ad3.tar.xz mpd-8b08ee82b492735947d917ed647a3e6cdf388ad3.zip |
begin work on avuton's disabling and enabling of individual audio outputs
git-svn-id: https://svn.musicpd.org/mpd/trunk@2483 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/audio.c | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/src/audio.c b/src/audio.c index c8ece7a90..4c8bff55e 100644 --- a/src/audio.c +++ b/src/audio.c @@ -21,6 +21,7 @@ #include "conf.h" #include "log.h" #include "sig_handlers.h" +#include "command.h" #include <stdlib.h> #include <string.h> @@ -31,6 +32,14 @@ static AudioFormat audio_format; static AudioFormat * audio_configFormat = NULL; +static AudioOutput ** audioOutputArray = NULL; +static mpd_uint8 audioOutputArraySize = 0; +/* the audioEnabledArray should be stuck into shared memory, and then disable + and enable in playAudio() routine */ +static mpd_uint8 * audioEnabledArray = NULL; + +static mpd_uint8 audioOpened = 0; + void copyAudioFormat(AudioFormat * dest, AudioFormat * src) { if(!src) return; @@ -41,9 +50,6 @@ int cmpAudioFormat(AudioFormat * f1, AudioFormat * f2) { return memcmp(f1, f2, sizeof(AudioFormat)); } -static AudioOutput ** audioOutputArray = NULL; -static int audioOutputArraySize = 0; - extern AudioOutputPlugin aoPlugin; extern AudioOutputPlugin shoutPlugin; extern AudioOutputPlugin ossPlugin; @@ -58,12 +64,21 @@ void initAudioDriver() { loadAudioOutputPlugin(&ossPlugin); while((param = getNextConfigParam(CONF_AUDIO_OUTPUT, param))) { + if(audioOutputArraySize == 255) { + ERROR("only up to 255 audio output devices are " + "supported"); + exit(EXIT_FAILURE); + } + i = audioOutputArraySize++; audioOutputArray = realloc(audioOutputArray, audioOutputArraySize*sizeof(AudioOutput *)); + audioEnabledArray = realloc(audioEnabledArray, + audioOutputArraySize*sizeof(mpd_uint8)); audioOutputArray[i] = newAudioOutput(param); + audioEnabledArray[i] = 1; if(!audioOutputArray[i]) { ERROR("problems configuring output device defined at " @@ -173,6 +188,7 @@ void finishAudioDriver() { finishAudioOutput(audioOutputArray[i]); } + free(audioEnabledArray); free(audioOutputArray); audioOutputArray = NULL; audioOutputArraySize = 0; @@ -198,12 +214,23 @@ int openAudioDevice(AudioFormat * audioFormat) { } for(i = 0; i < audioOutputArraySize; i++) { + if(!audioEnabledArray[i]) continue; if(!audioOutputArray[i]->open || !isCurrentFormat) { openAudioOutput(audioOutputArray[i], &audio_format); } if(audioOutputArray[i]->open) ret = 0; } + if(ret == 0) audioOpened = 1; + else { + /* close all devices if there was an error */ + for(i = 0; i < audioOutputArraySize; i++) { + closeAudioOutput(audioOutputArray[i]); + } + + audioOpened = 0; + } + return ret; } @@ -211,7 +238,10 @@ int playAudio(char * playChunk, int size) { int ret = -1; int i; + /* put some here to determine if enabled array changed */ + for(i = 0; i < audioOutputArraySize; i++) { + if(!audioEnabledArray[i]) continue; if(0 == playAudioOutput(audioOutputArray[i], playChunk, size)) { ret = 0; } @@ -221,14 +251,15 @@ int playAudio(char * playChunk, int size) { } int isAudioDeviceOpen() { - int ret = 0; + /*int ret = 0; int i; for(i = 0; i < audioOutputArraySize; i++) { + if(!audioEnabledArray[i]) continue; ret |= audioOutputArray[i]->open; - } + }*/ - return ret; + return audioOpened; } void closeAudioDevice() { @@ -237,6 +268,8 @@ void closeAudioDevice() { for(i = 0; i < audioOutputArraySize; i++) { closeAudioOutput(audioOutputArray[i]); } + + audioOpened = 0; } void sendMetadataToAudioDevice(MpdTag * tag) { @@ -246,3 +279,31 @@ void sendMetadataToAudioDevice(MpdTag * tag) { sendMetadataToAudioOutput(audioOutputArray[i], tag); } } + +int enableAudioDevice(FILE * fp, int device) { + if(device < 0 || device >= audioOutputArraySize) { + commandError(fp, ACK_ERROR_ARG, "audio output device id %i " + "doesn't exist\n", device); + return -1; + } + + audioEnabledArray[device] = 1; + /*if(audioOpened && !audioOutputArray[device]->open) { + openAudioOutput(audioOutputArray[device], &audio_format); + }*/ + + return 0; +} + +int disableAudioDevice(FILE * fp, int device) { + if(device < 0 || device >= audioOutputArraySize) { + commandError(fp, ACK_ERROR_ARG, "audio output device id %i " + "doesn't exist\n", device); + return -1; + } + + audioEnabledArray[device] = 0; + /*closeAudioOutput(audioOutputArray[device]);*/ + + return 0; +} |