aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c4
-rw-r--r--src/output_all.c124
-rw-r--r--src/output_all.h28
-rw-r--r--src/player_thread.c22
4 files changed, 97 insertions, 81 deletions
diff --git a/src/main.c b/src/main.c
index 5dc07975e..1325685c5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -258,7 +258,7 @@ int main(int argc, char *argv[])
initialize_decoder_and_player();
volume_init();
initAudioConfig();
- initAudioDriver();
+ audio_output_all_init();
client_manager_init();
replay_gain_global_init();
initNormalization();
@@ -314,7 +314,7 @@ int main(int argc, char *argv[])
input_stream_global_finish();
finishNormalization();
- finishAudioDriver();
+ audio_output_all_finish();
finishAudioConfig();
volume_finish();
mapper_finish();
diff --git a/src/output_all.c b/src/output_all.c
index dff84e04a..253bed8bc 100644
--- a/src/output_all.c
+++ b/src/output_all.c
@@ -24,26 +24,26 @@
static struct audio_format input_audio_format;
-static struct audio_output *audioOutputArray;
-static unsigned int audioOutputArraySize;
+static struct audio_output *audio_outputs;
+static unsigned int num_audio_outputs;
unsigned int audio_output_count(void)
{
- return audioOutputArraySize;
+ return num_audio_outputs;
}
struct audio_output *
audio_output_get(unsigned i)
{
- assert(i < audioOutputArraySize);
+ assert(i < num_audio_outputs);
- return &audioOutputArray[i];
+ return &audio_outputs[i];
}
struct audio_output *
audio_output_find(const char *name)
{
- for (unsigned i = 0; i < audioOutputArraySize; ++i) {
+ for (unsigned i = 0; i < num_audio_outputs; ++i) {
struct audio_output *ao = audio_output_get(i);
if (strcmp(ao->name, name) == 0)
@@ -67,26 +67,26 @@ audio_output_config_count(void)
return nr;
}
-/* make sure initPlayerData is called before this function!! */
-void initAudioDriver(void)
+void
+audio_output_all_init(void)
{
const struct config_param *param = NULL;
unsigned int i;
notify_init(&audio_output_client_notify);
- audioOutputArraySize = audio_output_config_count();
- audioOutputArray = g_new(struct audio_output, audioOutputArraySize);
+ num_audio_outputs = audio_output_config_count();
+ audio_outputs = g_new(struct audio_output, num_audio_outputs);
- for (i = 0; i < audioOutputArraySize; i++)
+ for (i = 0; i < num_audio_outputs; i++)
{
- struct audio_output *output = &audioOutputArray[i];
+ struct audio_output *output = &audio_outputs[i];
unsigned int j;
param = config_get_next_param(CONF_AUDIO_OUTPUT, param);
/* only allow param to be NULL if there just one audioOutput */
- assert(param || (audioOutputArraySize == 1));
+ assert(param || (num_audio_outputs == 1));
if (!audio_output_init(output, param)) {
if (param)
@@ -103,7 +103,7 @@ void initAudioDriver(void)
/* require output names to be unique: */
for (j = 0; j < i; j++) {
- if (!strcmp(output->name, audioOutputArray[j].name)) {
+ if (!strcmp(output->name, audio_outputs[j].name)) {
g_error("output devices with identical "
"names: %s\n", output->name);
}
@@ -111,17 +111,18 @@ void initAudioDriver(void)
}
}
-void finishAudioDriver(void)
+void
+audio_output_all_finish(void)
{
unsigned int i;
- for (i = 0; i < audioOutputArraySize; i++) {
- audio_output_finish(&audioOutputArray[i]);
+ for (i = 0; i < num_audio_outputs; i++) {
+ audio_output_finish(&audio_outputs[i]);
}
- g_free(audioOutputArray);
- audioOutputArray = NULL;
- audioOutputArraySize = 0;
+ g_free(audio_outputs);
+ audio_outputs = NULL;
+ num_audio_outputs = 0;
notify_deinit(&audio_output_client_notify);
}
@@ -133,9 +134,9 @@ static void audio_output_wait_all(void)
while (1) {
int finished = 1;
- for (i = 0; i < audioOutputArraySize; ++i)
- if (audio_output_is_open(&audioOutputArray[i]) &&
- !audio_output_command_is_finished(&audioOutputArray[i]))
+ for (i = 0; i < num_audio_outputs; ++i)
+ if (audio_output_is_open(&audio_outputs[i]) &&
+ !audio_output_command_is_finished(&audio_outputs[i]))
finished = 0;
if (finished)
@@ -145,18 +146,20 @@ static void audio_output_wait_all(void)
};
}
-static void syncAudioDeviceStates(void)
+static void
+audio_output_all_update(void)
{
unsigned int i;
if (!audio_format_defined(&input_audio_format))
return;
- for (i = 0; i < audioOutputArraySize; ++i)
- audio_output_update(&audioOutputArray[i], &input_audio_format);
+ for (i = 0; i < num_audio_outputs; ++i)
+ audio_output_update(&audio_outputs[i], &input_audio_format);
}
-bool playAudio(const char *buffer, size_t length)
+bool
+audio_output_all_play(const char *buffer, size_t length)
{
bool ret = false;
unsigned int i;
@@ -165,18 +168,18 @@ bool playAudio(const char *buffer, size_t length)
/* no partial frames allowed */
assert((length % audio_format_frame_size(&input_audio_format)) == 0);
- syncAudioDeviceStates();
+ audio_output_all_update();
- for (i = 0; i < audioOutputArraySize; ++i)
- if (audio_output_is_open(&audioOutputArray[i]))
- audio_output_play(&audioOutputArray[i],
+ for (i = 0; i < num_audio_outputs; ++i)
+ if (audio_output_is_open(&audio_outputs[i]))
+ audio_output_play(&audio_outputs[i],
buffer, length);
while (true) {
bool finished = true;
- for (i = 0; i < audioOutputArraySize; ++i) {
- struct audio_output *ao = &audioOutputArray[i];
+ for (i = 0; i < num_audio_outputs; ++i) {
+ struct audio_output *ao = &audio_outputs[i];
if (!audio_output_is_open(ao))
continue;
@@ -198,73 +201,78 @@ bool playAudio(const char *buffer, size_t length)
return ret;
}
-bool openAudioDevice(const struct audio_format *audioFormat)
+bool
+audio_output_all_open(const struct audio_format *audio_format)
{
bool ret = false;
unsigned int i;
- if (!audioOutputArray)
+ if (!audio_outputs)
return false;
- if (audioFormat != NULL)
- input_audio_format = *audioFormat;
+ if (audio_format != NULL)
+ input_audio_format = *audio_format;
- syncAudioDeviceStates();
+ audio_output_all_update();
- for (i = 0; i < audioOutputArraySize; ++i) {
- if (audioOutputArray[i].open)
+ for (i = 0; i < num_audio_outputs; ++i) {
+ if (audio_outputs[i].open)
ret = true;
}
if (!ret)
/* close all devices if there was an error */
- closeAudioDevice();
+ audio_output_all_close();
return ret;
}
-void audio_output_pause_all(void)
+void
+audio_output_all_pause(void)
{
unsigned int i;
- syncAudioDeviceStates();
+ audio_output_all_update();
- for (i = 0; i < audioOutputArraySize; ++i)
- if (audio_output_is_open(&audioOutputArray[i]))
- audio_output_pause(&audioOutputArray[i]);
+ for (i = 0; i < num_audio_outputs; ++i)
+ if (audio_output_is_open(&audio_outputs[i]))
+ audio_output_pause(&audio_outputs[i]);
audio_output_wait_all();
}
-void dropBufferedAudio(void)
+void
+audio_output_all_cancel(void)
{
unsigned int i;
- syncAudioDeviceStates();
+ audio_output_all_update();
- for (i = 0; i < audioOutputArraySize; ++i) {
- if (audio_output_is_open(&audioOutputArray[i]))
- audio_output_cancel(&audioOutputArray[i]);
+ for (i = 0; i < num_audio_outputs; ++i) {
+ if (audio_output_is_open(&audio_outputs[i]))
+ audio_output_cancel(&audio_outputs[i]);
}
audio_output_wait_all();
}
-void closeAudioDevice(void)
+void
+audio_output_all_close(void)
{
unsigned int i;
- for (i = 0; i < audioOutputArraySize; ++i)
- audio_output_close(&audioOutputArray[i]);
+ for (i = 0; i < num_audio_outputs; ++i)
+ audio_output_close(&audio_outputs[i]);
}
-void sendMetadataToAudioDevice(const struct tag *tag)
+void
+audio_output_all_tag(const struct tag *tag)
{
unsigned int i;
- for (i = 0; i < audioOutputArraySize; ++i)
- if (audio_output_is_open(&audioOutputArray[i]))
- audio_output_send_tag(&audioOutputArray[i], tag);
+ for (i = 0; i < num_audio_outputs; ++i)
+ if (audio_output_is_open(&audio_outputs[i]))
+ audio_output_send_tag(&audio_outputs[i], tag);
audio_output_wait_all();
}
diff --git a/src/output_all.h b/src/output_all.h
index 15a1dce7d..0b782f11b 100644
--- a/src/output_all.h
+++ b/src/output_all.h
@@ -31,6 +31,12 @@
struct audio_format;
struct tag;
+void
+audio_output_all_init(void);
+
+void
+audio_output_all_finish(void);
+
/**
* Returns the total number of audio output devices, including those
* who are disabled right now.
@@ -50,20 +56,22 @@ audio_output_get(unsigned i);
struct audio_output *
audio_output_find(const char *name);
-void initAudioDriver(void);
-
-void finishAudioDriver(void);
-
-bool openAudioDevice(const struct audio_format *audioFormat);
+bool
+audio_output_all_open(const struct audio_format *audio_format);
-bool playAudio(const char *playChunk, size_t size);
+void
+audio_output_all_close(void);
-void audio_output_pause_all(void);
+bool
+audio_output_all_play(const char *data, size_t size);
-void dropBufferedAudio(void);
+void
+audio_output_all_tag(const struct tag *tag);
-void closeAudioDevice(void);
+void
+audio_output_all_pause(void);
-void sendMetadataToAudioDevice(const struct tag *tag);
+void
+audio_output_all_cancel(void);
#endif
diff --git a/src/player_thread.c b/src/player_thread.c
index a8f89197b..e16a46d5d 100644
--- a/src/player_thread.c
+++ b/src/player_thread.c
@@ -181,10 +181,10 @@ static void player_process_command(struct player *player)
case PLAYER_COMMAND_PAUSE:
player->paused = !player->paused;
if (player->paused) {
- audio_output_pause_all();
+ audio_output_all_pause();
pc.state = PLAYER_STATE_PAUSE;
} else {
- if (openAudioDevice(NULL)) {
+ if (audio_output_all_open(NULL)) {
pc.state = PLAYER_STATE_PLAY;
} else {
char *uri = song_get_uri(dc.next_song);
@@ -203,7 +203,7 @@ static void player_process_command(struct player *player)
break;
case PLAYER_COMMAND_SEEK:
- dropBufferedAudio();
+ audio_output_all_cancel();
if (player_seek_decoder(player)) {
player->xfade = XFADE_UNKNOWN;
@@ -245,7 +245,7 @@ play_chunk(struct song *song, struct music_chunk *chunk,
pc.bit_rate = chunk->bit_rate;
if (chunk->tag != NULL) {
- sendMetadataToAudioDevice(chunk->tag);
+ audio_output_all_tag(chunk->tag);
if (!song_is_file(song)) {
/* always update the tag of remote streams */
@@ -272,7 +272,7 @@ play_chunk(struct song *song, struct music_chunk *chunk,
pcm_volume(chunk->data, chunk->length,
format, pc.software_volume);
- if (!playAudio(chunk->data, chunk->length)) {
+ if (!audio_output_all_play(chunk->data, chunk->length)) {
pc.errored_song = dc.current_song;
pc.error = PLAYER_ERROR_AUDIO;
return false;
@@ -320,7 +320,7 @@ static void do_play(void)
if (pc.command == PLAYER_COMMAND_STOP ||
pc.command == PLAYER_COMMAND_EXIT ||
pc.command == PLAYER_COMMAND_CLOSE_AUDIO) {
- dropBufferedAudio();
+ audio_output_all_cancel();
break;
}
@@ -348,7 +348,7 @@ static void do_play(void)
else if (!decoder_is_starting()) {
/* the decoder is ready and ok */
player.decoder_starting = false;
- if (!openAudioDevice(&dc.out_audio_format)) {
+ if (!audio_output_all_open(&dc.out_audio_format)) {
char *uri = song_get_uri(dc.next_song);
g_warning("problems opening audio device "
"while playing \"%s\"", uri);
@@ -361,7 +361,7 @@ static void do_play(void)
}
if (player.paused)
- closeAudioDevice();
+ audio_output_all_close();
pc.total_time = dc.total_time;
pc.audio_format = dc.in_audio_format;
@@ -506,7 +506,7 @@ static void do_play(void)
unsigned num_frames = CHUNK_SIZE / frame_size;
/*DEBUG("waiting for decoded audio, play silence\n");*/
- if (!playAudio(silence, num_frames * frame_size))
+ if (!audio_output_all_play(silence, num_frames * frame_size))
break;
}
}
@@ -540,13 +540,13 @@ static gpointer player_task(G_GNUC_UNUSED gpointer arg)
break;
case PLAYER_COMMAND_CLOSE_AUDIO:
- closeAudioDevice();
+ audio_output_all_close();
player_command_finished();
break;
case PLAYER_COMMAND_EXIT:
dc_quit();
- closeAudioDevice();
+ audio_output_all_close();
player_command_finished();
g_thread_exit(NULL);
break;