enabling and disabling individual audioOutputs is mostly done, just need
to add the command hooks git-svn-id: https://svn.musicpd.org/mpd/trunk@2484 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
8b08ee82b4
commit
69176148bf
65
src/audio.c
65
src/audio.c
@ -22,6 +22,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "sig_handlers.h"
|
#include "sig_handlers.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
#include "playerData.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -36,7 +37,8 @@ static AudioOutput ** audioOutputArray = NULL;
|
|||||||
static mpd_uint8 audioOutputArraySize = 0;
|
static mpd_uint8 audioOutputArraySize = 0;
|
||||||
/* the audioEnabledArray should be stuck into shared memory, and then disable
|
/* the audioEnabledArray should be stuck into shared memory, and then disable
|
||||||
and enable in playAudio() routine */
|
and enable in playAudio() routine */
|
||||||
static mpd_uint8 * audioEnabledArray = NULL;
|
static mpd_sint8 * pdAudioDevicesEnabled = NULL;
|
||||||
|
static mpd_sint8 myAudioDevicesEnabled[AUDIO_MAX_DEVICES];
|
||||||
|
|
||||||
static mpd_uint8 audioOpened = 0;
|
static mpd_uint8 audioOpened = 0;
|
||||||
|
|
||||||
@ -54,6 +56,7 @@ extern AudioOutputPlugin aoPlugin;
|
|||||||
extern AudioOutputPlugin shoutPlugin;
|
extern AudioOutputPlugin shoutPlugin;
|
||||||
extern AudioOutputPlugin ossPlugin;
|
extern AudioOutputPlugin ossPlugin;
|
||||||
|
|
||||||
|
/* make sure initPlayerData is called before this function!! */
|
||||||
void initAudioDriver() {
|
void initAudioDriver() {
|
||||||
ConfigParam * param = NULL;
|
ConfigParam * param = NULL;
|
||||||
int i;
|
int i;
|
||||||
@ -63,8 +66,15 @@ void initAudioDriver() {
|
|||||||
loadAudioOutputPlugin(&shoutPlugin);
|
loadAudioOutputPlugin(&shoutPlugin);
|
||||||
loadAudioOutputPlugin(&ossPlugin);
|
loadAudioOutputPlugin(&ossPlugin);
|
||||||
|
|
||||||
|
pdAudioDevicesEnabled = (getPlayerData())->audioDeviceEnabled;
|
||||||
|
|
||||||
|
for(i = 0; i < AUDIO_MAX_DEVICES; i++) {
|
||||||
|
pdAudioDevicesEnabled[i] = 1;
|
||||||
|
myAudioDevicesEnabled[i] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
while((param = getNextConfigParam(CONF_AUDIO_OUTPUT, param))) {
|
while((param = getNextConfigParam(CONF_AUDIO_OUTPUT, param))) {
|
||||||
if(audioOutputArraySize == 255) {
|
if(audioOutputArraySize == AUDIO_MAX_DEVICES) {
|
||||||
ERROR("only up to 255 audio output devices are "
|
ERROR("only up to 255 audio output devices are "
|
||||||
"supported");
|
"supported");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -74,11 +84,8 @@ void initAudioDriver() {
|
|||||||
|
|
||||||
audioOutputArray = realloc(audioOutputArray,
|
audioOutputArray = realloc(audioOutputArray,
|
||||||
audioOutputArraySize*sizeof(AudioOutput *));
|
audioOutputArraySize*sizeof(AudioOutput *));
|
||||||
audioEnabledArray = realloc(audioEnabledArray,
|
|
||||||
audioOutputArraySize*sizeof(mpd_uint8));
|
|
||||||
|
|
||||||
audioOutputArray[i] = newAudioOutput(param);
|
audioOutputArray[i] = newAudioOutput(param);
|
||||||
audioEnabledArray[i] = 1;
|
|
||||||
|
|
||||||
if(!audioOutputArray[i]) {
|
if(!audioOutputArray[i]) {
|
||||||
ERROR("problems configuring output device defined at "
|
ERROR("problems configuring output device defined at "
|
||||||
@ -188,10 +195,11 @@ void finishAudioDriver() {
|
|||||||
finishAudioOutput(audioOutputArray[i]);
|
finishAudioOutput(audioOutputArray[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(audioEnabledArray);
|
|
||||||
free(audioOutputArray);
|
free(audioOutputArray);
|
||||||
audioOutputArray = NULL;
|
audioOutputArray = NULL;
|
||||||
audioOutputArraySize = 0;
|
/* don't set to zero cause we're gonna use this for enabling
|
||||||
|
and disabling devices */
|
||||||
|
/*audioOutputArraySize = 0;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
int isCurrentAudioFormat(AudioFormat * audioFormat) {
|
int isCurrentAudioFormat(AudioFormat * audioFormat) {
|
||||||
@ -202,6 +210,19 @@ int isCurrentAudioFormat(AudioFormat * audioFormat) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void syncAudioDevicesEnabledArrays() {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memcpy(myAudioDevicesEnabled, pdAudioDevicesEnabled,AUDIO_MAX_DEVICES);
|
||||||
|
|
||||||
|
for(i = 0; i < audioOutputArraySize; i++) {
|
||||||
|
if(myAudioDevicesEnabled[i]) {
|
||||||
|
openAudioOutput(audioOutputArray[i], &audio_format);
|
||||||
|
}
|
||||||
|
else closeAudioOutput(audioOutputArray[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int openAudioDevice(AudioFormat * audioFormat) {
|
int openAudioDevice(AudioFormat * audioFormat) {
|
||||||
int isCurrentFormat = isCurrentAudioFormat(audioFormat);
|
int isCurrentFormat = isCurrentAudioFormat(audioFormat);
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -213,11 +234,9 @@ int openAudioDevice(AudioFormat * audioFormat) {
|
|||||||
copyAudioFormat(&audio_format, audioFormat);
|
copyAudioFormat(&audio_format, audioFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syncAudioDevicesEnabledArrays();
|
||||||
|
|
||||||
for(i = 0; i < audioOutputArraySize; i++) {
|
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(audioOutputArray[i]->open) ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,10 +257,14 @@ int playAudio(char * playChunk, int size) {
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* put some here to determine if enabled array changed */
|
if(0 != memcmp(pdAudioDevicesEnabled, myAudioDevicesEnabled,
|
||||||
|
AUDIO_MAX_DEVICES))
|
||||||
|
{
|
||||||
|
syncAudioDevicesEnabledArrays();
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 0; i < audioOutputArraySize; i++) {
|
for(i = 0; i < audioOutputArraySize; i++) {
|
||||||
if(!audioEnabledArray[i]) continue;
|
if(!myAudioDevicesEnabled[i]) continue;
|
||||||
if(0 == playAudioOutput(audioOutputArray[i], playChunk, size)) {
|
if(0 == playAudioOutput(audioOutputArray[i], playChunk, size)) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
@ -251,14 +274,6 @@ int playAudio(char * playChunk, int size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int isAudioDeviceOpen() {
|
int isAudioDeviceOpen() {
|
||||||
/*int ret = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i = 0; i < audioOutputArraySize; i++) {
|
|
||||||
if(!audioEnabledArray[i]) continue;
|
|
||||||
ret |= audioOutputArray[i]->open;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return audioOpened;
|
return audioOpened;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,10 +302,7 @@ int enableAudioDevice(FILE * fp, int device) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
audioEnabledArray[device] = 1;
|
pdAudioDevicesEnabled[device] = 1;
|
||||||
/*if(audioOpened && !audioOutputArray[device]->open) {
|
|
||||||
openAudioOutput(audioOutputArray[device], &audio_format);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -302,8 +314,7 @@ int disableAudioDevice(FILE * fp, int device) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
audioEnabledArray[device] = 0;
|
pdAudioDevicesEnabled[device] = 0;
|
||||||
/*closeAudioOutput(audioOutputArray[device]);*/
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#define AUDIO_AO_DRIVER_DEFAULT "default"
|
#define AUDIO_AO_DRIVER_DEFAULT "default"
|
||||||
|
|
||||||
|
#define AUDIO_MAX_DEVICES 8
|
||||||
|
|
||||||
typedef struct _AudioFormat {
|
typedef struct _AudioFormat {
|
||||||
volatile mpd_sint8 channels;
|
volatile mpd_sint8 channels;
|
||||||
volatile mpd_uint32 sampleRate;
|
volatile mpd_uint32 sampleRate;
|
||||||
@ -42,6 +44,7 @@ void getOutputAudioFormat(AudioFormat * inFormat, AudioFormat * outFormat);
|
|||||||
|
|
||||||
int parseAudioConfig(AudioFormat * audioFormat, char * conf);
|
int parseAudioConfig(AudioFormat * audioFormat, char * conf);
|
||||||
|
|
||||||
|
/* make sure initPlayerData is called before this function!! */
|
||||||
void initAudioConfig();
|
void initAudioConfig();
|
||||||
|
|
||||||
void finishAudioConfig();
|
void finishAudioConfig();
|
||||||
|
@ -427,9 +427,9 @@ int main(int argc, char * argv[]) {
|
|||||||
openDB(&options, argv[0]);
|
openDB(&options, argv[0]);
|
||||||
|
|
||||||
initCommands();
|
initCommands();
|
||||||
|
initPlayerData();
|
||||||
initAudioConfig();
|
initAudioConfig();
|
||||||
initAudioDriver();
|
initAudioDriver();
|
||||||
initPlayerData();
|
|
||||||
initVolume();
|
initVolume();
|
||||||
initInterfaces();
|
initInterfaces();
|
||||||
initInputStream();
|
initInputStream();
|
||||||
|
@ -37,6 +37,7 @@ typedef struct _PlayerData {
|
|||||||
OutputBuffer buffer;
|
OutputBuffer buffer;
|
||||||
PlayerControl playerControl;
|
PlayerControl playerControl;
|
||||||
DecoderControl decoderControl;
|
DecoderControl decoderControl;
|
||||||
|
mpd_sint8 audioDeviceEnabled[AUDIO_MAX_DEVICES];
|
||||||
} PlayerData;
|
} PlayerData;
|
||||||
|
|
||||||
void initPlayerData();
|
void initPlayerData();
|
||||||
@ -46,4 +47,3 @@ PlayerData * getPlayerData();
|
|||||||
void freePlayerData();
|
void freePlayerData();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
|
||||||
|
Loading…
Reference in New Issue
Block a user