audio: remove AUDIO_MAX_DEVICES limit
Some people have more than 8 devices (the old limit). It's pretty easy to support as many as our hardware and OS allows so we might as well. git-svn-id: https://svn.musicpd.org/mpd/trunk@4513 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
89073cfbba
commit
c22a53d373
45
src/audio.c
45
src/audio.c
@ -49,7 +49,7 @@ 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_sint8 *pdAudioDevicesEnabled = NULL;
|
static mpd_sint8 *pdAudioDevicesEnabled = NULL;
|
||||||
static mpd_sint8 myAudioDevicesEnabled[AUDIO_MAX_DEVICES];
|
static mpd_sint8 *myAudioDevicesEnabled = NULL;
|
||||||
|
|
||||||
static mpd_uint8 audioOpened = 0;
|
static mpd_uint8 audioOpened = 0;
|
||||||
|
|
||||||
@ -57,6 +57,18 @@ static mpd_sint32 audioBufferSize = 0;
|
|||||||
static char *audioBuffer = NULL;
|
static char *audioBuffer = NULL;
|
||||||
static mpd_sint32 audioBufferPos = 0;
|
static mpd_sint32 audioBufferPos = 0;
|
||||||
|
|
||||||
|
size_t audio_device_count(void)
|
||||||
|
{
|
||||||
|
size_t nr = 0;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
void copyAudioFormat(AudioFormat * dest, AudioFormat * src)
|
void copyAudioFormat(AudioFormat * dest, AudioFormat * src)
|
||||||
{
|
{
|
||||||
if (!src)
|
if (!src)
|
||||||
@ -101,31 +113,21 @@ void initAudioDriver(void)
|
|||||||
|
|
||||||
loadAudioDrivers();
|
loadAudioDrivers();
|
||||||
|
|
||||||
|
audioOutputArraySize = audio_device_count();
|
||||||
pdAudioDevicesEnabled = (getPlayerData())->audioDeviceEnabled;
|
pdAudioDevicesEnabled = (getPlayerData())->audioDeviceEnabled;
|
||||||
|
audioOutputArray = malloc(sizeof(AudioOutput *) * audioOutputArraySize);
|
||||||
|
myAudioDevicesEnabled = malloc(sizeof(mpd_sint8)*audioOutputArraySize);
|
||||||
|
|
||||||
for (i = 0; i < AUDIO_MAX_DEVICES; i++) {
|
for (i = 0; i < audioOutputArraySize; i++)
|
||||||
pdAudioDevicesEnabled[i] = 1;
|
myAudioDevicesEnabled[i] = pdAudioDevicesEnabled[i] = 1;
|
||||||
myAudioDevicesEnabled[i] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
i = 0;
|
||||||
param = getNextConfigParam(CONF_AUDIO_OUTPUT, param);
|
param = getNextConfigParam(CONF_AUDIO_OUTPUT, param);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
AudioOutput *output;
|
AudioOutput *output;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
if (audioOutputArraySize == AUDIO_MAX_DEVICES) {
|
|
||||||
ERROR("only up to 255 audio output devices are "
|
|
||||||
"supported");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
i = audioOutputArraySize++;
|
|
||||||
|
|
||||||
audioOutputArray = realloc(audioOutputArray,
|
|
||||||
audioOutputArraySize *
|
|
||||||
sizeof(AudioOutput *));
|
|
||||||
|
|
||||||
output = newAudioOutput(param);
|
output = newAudioOutput(param);
|
||||||
if (!output && param) {
|
if (!output && param) {
|
||||||
ERROR("problems configuring output device defined at "
|
ERROR("problems configuring output device defined at "
|
||||||
@ -141,7 +143,7 @@ void initAudioDriver(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
audioOutputArray[i] = output;
|
audioOutputArray[i++] = output;
|
||||||
} while ((param = getNextConfigParam(CONF_AUDIO_OUTPUT, param)));
|
} while ((param = getNextConfigParam(CONF_AUDIO_OUTPUT, param)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +273,8 @@ static void syncAudioDevicesEnabledArrays(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memcpy(myAudioDevicesEnabled, pdAudioDevicesEnabled, AUDIO_MAX_DEVICES);
|
memcpy(myAudioDevicesEnabled, pdAudioDevicesEnabled,
|
||||||
|
audioOutputArraySize);
|
||||||
|
|
||||||
for (i = 0; i < audioOutputArraySize; i++) {
|
for (i = 0; i < audioOutputArraySize; i++) {
|
||||||
if (myAudioDevicesEnabled[i]) {
|
if (myAudioDevicesEnabled[i]) {
|
||||||
@ -292,7 +295,7 @@ static int flushAudioBuffer(void)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (0 != memcmp(pdAudioDevicesEnabled, myAudioDevicesEnabled,
|
if (0 != memcmp(pdAudioDevicesEnabled, myAudioDevicesEnabled,
|
||||||
AUDIO_MAX_DEVICES)) {
|
audioOutputArraySize)) {
|
||||||
syncAudioDevicesEnabledArrays();
|
syncAudioDevicesEnabledArrays();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,7 +388,7 @@ void dropBufferedAudio(void)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (0 != memcmp(pdAudioDevicesEnabled, myAudioDevicesEnabled,
|
if (0 != memcmp(pdAudioDevicesEnabled, myAudioDevicesEnabled,
|
||||||
AUDIO_MAX_DEVICES)) {
|
audioOutputArraySize)) {
|
||||||
syncAudioDevicesEnabledArrays();
|
syncAudioDevicesEnabledArrays();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,14 +28,14 @@
|
|||||||
|
|
||||||
#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;
|
||||||
volatile mpd_sint8 bits;
|
volatile mpd_sint8 bits;
|
||||||
} AudioFormat;
|
} AudioFormat;
|
||||||
|
|
||||||
|
size_t audio_device_count(void);
|
||||||
|
|
||||||
void copyAudioFormat(AudioFormat * dest, AudioFormat * src);
|
void copyAudioFormat(AudioFormat * dest, AudioFormat * src);
|
||||||
|
|
||||||
int cmpAudioFormat(AudioFormat * dest, AudioFormat * src);
|
int cmpAudioFormat(AudioFormat * dest, AudioFormat * src);
|
||||||
|
@ -45,6 +45,7 @@ void initPlayerData(void)
|
|||||||
size_t allocationSize;
|
size_t allocationSize;
|
||||||
OutputBuffer *buffer;
|
OutputBuffer *buffer;
|
||||||
ConfigParam *param;
|
ConfigParam *param;
|
||||||
|
size_t device_array_size = audio_device_count() * sizeof(mpd_sint8);
|
||||||
|
|
||||||
param = getConfigParam(CONF_AUDIO_BUFFER_SIZE);
|
param = getConfigParam(CONF_AUDIO_BUFFER_SIZE);
|
||||||
|
|
||||||
@ -91,6 +92,9 @@ void initPlayerData(void)
|
|||||||
allocationSize += buffered_chunks * sizeof(mpd_sint8); /*for metaChunk */
|
allocationSize += buffered_chunks * sizeof(mpd_sint8); /*for metaChunk */
|
||||||
allocationSize += sizeof(PlayerData); /*for playerData struct */
|
allocationSize += sizeof(PlayerData); /*for playerData struct */
|
||||||
|
|
||||||
|
/* for audioDeviceEnabled[] */
|
||||||
|
allocationSize += device_array_size;
|
||||||
|
|
||||||
if ((shmid = shmget(IPC_PRIVATE, allocationSize, IPC_CREAT | 0600)) < 0) {
|
if ((shmid = shmget(IPC_PRIVATE, allocationSize, IPC_CREAT | 0600)) < 0) {
|
||||||
ERROR("problems shmget'ing\n");
|
ERROR("problems shmget'ing\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -104,6 +108,8 @@ void initPlayerData(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playerData_pd->audioDeviceEnabled = (char *)playerData_pd +
|
||||||
|
allocationSize - device_array_size;
|
||||||
buffer = &(playerData_pd->buffer);
|
buffer = &(playerData_pd->buffer);
|
||||||
|
|
||||||
buffer->chunks = ((char *)playerData_pd) + sizeof(PlayerData);
|
buffer->chunks = ((char *)playerData_pd) + sizeof(PlayerData);
|
||||||
|
@ -37,7 +37,7 @@ typedef struct _PlayerData {
|
|||||||
OutputBuffer buffer;
|
OutputBuffer buffer;
|
||||||
PlayerControl playerControl;
|
PlayerControl playerControl;
|
||||||
DecoderControl decoderControl;
|
DecoderControl decoderControl;
|
||||||
mpd_sint8 audioDeviceEnabled[AUDIO_MAX_DEVICES];
|
mpd_sint8 *audioDeviceEnabled;
|
||||||
int pid;
|
int pid;
|
||||||
} PlayerData;
|
} PlayerData;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user