output_all: no CamelCase

Renamed functions and variables.
This commit is contained in:
Max Kellermann 2009-02-10 18:51:51 +01:00
parent a3a6eefcfe
commit 4493a96425
4 changed files with 97 additions and 81 deletions

View File

@ -258,7 +258,7 @@ int main(int argc, char *argv[])
initialize_decoder_and_player(); initialize_decoder_and_player();
volume_init(); volume_init();
initAudioConfig(); initAudioConfig();
initAudioDriver(); audio_output_all_init();
client_manager_init(); client_manager_init();
replay_gain_global_init(); replay_gain_global_init();
initNormalization(); initNormalization();
@ -314,7 +314,7 @@ int main(int argc, char *argv[])
input_stream_global_finish(); input_stream_global_finish();
finishNormalization(); finishNormalization();
finishAudioDriver(); audio_output_all_finish();
finishAudioConfig(); finishAudioConfig();
volume_finish(); volume_finish();
mapper_finish(); mapper_finish();

View File

@ -24,26 +24,26 @@
static struct audio_format input_audio_format; static struct audio_format input_audio_format;
static struct audio_output *audioOutputArray; static struct audio_output *audio_outputs;
static unsigned int audioOutputArraySize; static unsigned int num_audio_outputs;
unsigned int audio_output_count(void) unsigned int audio_output_count(void)
{ {
return audioOutputArraySize; return num_audio_outputs;
} }
struct audio_output * struct audio_output *
audio_output_get(unsigned i) audio_output_get(unsigned i)
{ {
assert(i < audioOutputArraySize); assert(i < num_audio_outputs);
return &audioOutputArray[i]; return &audio_outputs[i];
} }
struct audio_output * struct audio_output *
audio_output_find(const char *name) 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); struct audio_output *ao = audio_output_get(i);
if (strcmp(ao->name, name) == 0) if (strcmp(ao->name, name) == 0)
@ -67,26 +67,26 @@ audio_output_config_count(void)
return nr; return nr;
} }
/* make sure initPlayerData is called before this function!! */ void
void initAudioDriver(void) audio_output_all_init(void)
{ {
const struct config_param *param = NULL; const struct config_param *param = NULL;
unsigned int i; unsigned int i;
notify_init(&audio_output_client_notify); notify_init(&audio_output_client_notify);
audioOutputArraySize = audio_output_config_count(); num_audio_outputs = audio_output_config_count();
audioOutputArray = g_new(struct audio_output, audioOutputArraySize); 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; unsigned int j;
param = config_get_next_param(CONF_AUDIO_OUTPUT, param); param = config_get_next_param(CONF_AUDIO_OUTPUT, param);
/* only allow param to be NULL if there just one audioOutput */ /* 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 (!audio_output_init(output, param)) {
if (param) if (param)
@ -103,7 +103,7 @@ void initAudioDriver(void)
/* require output names to be unique: */ /* require output names to be unique: */
for (j = 0; j < i; j++) { 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 " g_error("output devices with identical "
"names: %s\n", output->name); "names: %s\n", output->name);
} }
@ -111,17 +111,18 @@ void initAudioDriver(void)
} }
} }
void finishAudioDriver(void) void
audio_output_all_finish(void)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < audioOutputArraySize; i++) { for (i = 0; i < num_audio_outputs; i++) {
audio_output_finish(&audioOutputArray[i]); audio_output_finish(&audio_outputs[i]);
} }
g_free(audioOutputArray); g_free(audio_outputs);
audioOutputArray = NULL; audio_outputs = NULL;
audioOutputArraySize = 0; num_audio_outputs = 0;
notify_deinit(&audio_output_client_notify); notify_deinit(&audio_output_client_notify);
} }
@ -133,9 +134,9 @@ static void audio_output_wait_all(void)
while (1) { while (1) {
int finished = 1; int finished = 1;
for (i = 0; i < audioOutputArraySize; ++i) for (i = 0; i < num_audio_outputs; ++i)
if (audio_output_is_open(&audioOutputArray[i]) && if (audio_output_is_open(&audio_outputs[i]) &&
!audio_output_command_is_finished(&audioOutputArray[i])) !audio_output_command_is_finished(&audio_outputs[i]))
finished = 0; finished = 0;
if (finished) 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; unsigned int i;
if (!audio_format_defined(&input_audio_format)) if (!audio_format_defined(&input_audio_format))
return; return;
for (i = 0; i < audioOutputArraySize; ++i) for (i = 0; i < num_audio_outputs; ++i)
audio_output_update(&audioOutputArray[i], &input_audio_format); 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; bool ret = false;
unsigned int i; unsigned int i;
@ -165,18 +168,18 @@ bool playAudio(const char *buffer, size_t length)
/* no partial frames allowed */ /* no partial frames allowed */
assert((length % audio_format_frame_size(&input_audio_format)) == 0); assert((length % audio_format_frame_size(&input_audio_format)) == 0);
syncAudioDeviceStates(); audio_output_all_update();
for (i = 0; i < audioOutputArraySize; ++i) for (i = 0; i < num_audio_outputs; ++i)
if (audio_output_is_open(&audioOutputArray[i])) if (audio_output_is_open(&audio_outputs[i]))
audio_output_play(&audioOutputArray[i], audio_output_play(&audio_outputs[i],
buffer, length); buffer, length);
while (true) { while (true) {
bool finished = true; bool finished = true;
for (i = 0; i < audioOutputArraySize; ++i) { for (i = 0; i < num_audio_outputs; ++i) {
struct audio_output *ao = &audioOutputArray[i]; struct audio_output *ao = &audio_outputs[i];
if (!audio_output_is_open(ao)) if (!audio_output_is_open(ao))
continue; continue;
@ -198,73 +201,78 @@ bool playAudio(const char *buffer, size_t length)
return ret; return ret;
} }
bool openAudioDevice(const struct audio_format *audioFormat) bool
audio_output_all_open(const struct audio_format *audio_format)
{ {
bool ret = false; bool ret = false;
unsigned int i; unsigned int i;
if (!audioOutputArray) if (!audio_outputs)
return false; return false;
if (audioFormat != NULL) if (audio_format != NULL)
input_audio_format = *audioFormat; input_audio_format = *audio_format;
syncAudioDeviceStates(); audio_output_all_update();
for (i = 0; i < audioOutputArraySize; ++i) { for (i = 0; i < num_audio_outputs; ++i) {
if (audioOutputArray[i].open) if (audio_outputs[i].open)
ret = true; ret = true;
} }
if (!ret) if (!ret)
/* close all devices if there was an error */ /* close all devices if there was an error */
closeAudioDevice(); audio_output_all_close();
return ret; return ret;
} }
void audio_output_pause_all(void) void
audio_output_all_pause(void)
{ {
unsigned int i; unsigned int i;
syncAudioDeviceStates(); audio_output_all_update();
for (i = 0; i < audioOutputArraySize; ++i) for (i = 0; i < num_audio_outputs; ++i)
if (audio_output_is_open(&audioOutputArray[i])) if (audio_output_is_open(&audio_outputs[i]))
audio_output_pause(&audioOutputArray[i]); audio_output_pause(&audio_outputs[i]);
audio_output_wait_all(); audio_output_wait_all();
} }
void dropBufferedAudio(void) void
audio_output_all_cancel(void)
{ {
unsigned int i; unsigned int i;
syncAudioDeviceStates(); audio_output_all_update();
for (i = 0; i < audioOutputArraySize; ++i) { for (i = 0; i < num_audio_outputs; ++i) {
if (audio_output_is_open(&audioOutputArray[i])) if (audio_output_is_open(&audio_outputs[i]))
audio_output_cancel(&audioOutputArray[i]); audio_output_cancel(&audio_outputs[i]);
} }
audio_output_wait_all(); audio_output_wait_all();
} }
void closeAudioDevice(void) void
audio_output_all_close(void)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < audioOutputArraySize; ++i) for (i = 0; i < num_audio_outputs; ++i)
audio_output_close(&audioOutputArray[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; unsigned int i;
for (i = 0; i < audioOutputArraySize; ++i) for (i = 0; i < num_audio_outputs; ++i)
if (audio_output_is_open(&audioOutputArray[i])) if (audio_output_is_open(&audio_outputs[i]))
audio_output_send_tag(&audioOutputArray[i], tag); audio_output_send_tag(&audio_outputs[i], tag);
audio_output_wait_all(); audio_output_wait_all();
} }

View File

@ -31,6 +31,12 @@
struct audio_format; struct audio_format;
struct tag; struct tag;
void
audio_output_all_init(void);
void
audio_output_all_finish(void);
/** /**
* Returns the total number of audio output devices, including those * Returns the total number of audio output devices, including those
* who are disabled right now. * who are disabled right now.
@ -50,20 +56,22 @@ audio_output_get(unsigned i);
struct audio_output * struct audio_output *
audio_output_find(const char *name); audio_output_find(const char *name);
void initAudioDriver(void); bool
audio_output_all_open(const struct audio_format *audio_format);
void finishAudioDriver(void); void
audio_output_all_close(void);
bool openAudioDevice(const struct audio_format *audioFormat); bool
audio_output_all_play(const char *data, size_t size);
bool playAudio(const char *playChunk, size_t size); void
audio_output_all_tag(const struct tag *tag);
void audio_output_pause_all(void); void
audio_output_all_pause(void);
void dropBufferedAudio(void); void
audio_output_all_cancel(void);
void closeAudioDevice(void);
void sendMetadataToAudioDevice(const struct tag *tag);
#endif #endif

View File

@ -181,10 +181,10 @@ static void player_process_command(struct player *player)
case PLAYER_COMMAND_PAUSE: case PLAYER_COMMAND_PAUSE:
player->paused = !player->paused; player->paused = !player->paused;
if (player->paused) { if (player->paused) {
audio_output_pause_all(); audio_output_all_pause();
pc.state = PLAYER_STATE_PAUSE; pc.state = PLAYER_STATE_PAUSE;
} else { } else {
if (openAudioDevice(NULL)) { if (audio_output_all_open(NULL)) {
pc.state = PLAYER_STATE_PLAY; pc.state = PLAYER_STATE_PLAY;
} else { } else {
char *uri = song_get_uri(dc.next_song); char *uri = song_get_uri(dc.next_song);
@ -203,7 +203,7 @@ static void player_process_command(struct player *player)
break; break;
case PLAYER_COMMAND_SEEK: case PLAYER_COMMAND_SEEK:
dropBufferedAudio(); audio_output_all_cancel();
if (player_seek_decoder(player)) { if (player_seek_decoder(player)) {
player->xfade = XFADE_UNKNOWN; player->xfade = XFADE_UNKNOWN;
@ -245,7 +245,7 @@ play_chunk(struct song *song, struct music_chunk *chunk,
pc.bit_rate = chunk->bit_rate; pc.bit_rate = chunk->bit_rate;
if (chunk->tag != NULL) { if (chunk->tag != NULL) {
sendMetadataToAudioDevice(chunk->tag); audio_output_all_tag(chunk->tag);
if (!song_is_file(song)) { if (!song_is_file(song)) {
/* always update the tag of remote streams */ /* 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, pcm_volume(chunk->data, chunk->length,
format, pc.software_volume); 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.errored_song = dc.current_song;
pc.error = PLAYER_ERROR_AUDIO; pc.error = PLAYER_ERROR_AUDIO;
return false; return false;
@ -320,7 +320,7 @@ static void do_play(void)
if (pc.command == PLAYER_COMMAND_STOP || if (pc.command == PLAYER_COMMAND_STOP ||
pc.command == PLAYER_COMMAND_EXIT || pc.command == PLAYER_COMMAND_EXIT ||
pc.command == PLAYER_COMMAND_CLOSE_AUDIO) { pc.command == PLAYER_COMMAND_CLOSE_AUDIO) {
dropBufferedAudio(); audio_output_all_cancel();
break; break;
} }
@ -348,7 +348,7 @@ static void do_play(void)
else if (!decoder_is_starting()) { else if (!decoder_is_starting()) {
/* the decoder is ready and ok */ /* the decoder is ready and ok */
player.decoder_starting = false; 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); char *uri = song_get_uri(dc.next_song);
g_warning("problems opening audio device " g_warning("problems opening audio device "
"while playing \"%s\"", uri); "while playing \"%s\"", uri);
@ -361,7 +361,7 @@ static void do_play(void)
} }
if (player.paused) if (player.paused)
closeAudioDevice(); audio_output_all_close();
pc.total_time = dc.total_time; pc.total_time = dc.total_time;
pc.audio_format = dc.in_audio_format; pc.audio_format = dc.in_audio_format;
@ -506,7 +506,7 @@ static void do_play(void)
unsigned num_frames = CHUNK_SIZE / frame_size; unsigned num_frames = CHUNK_SIZE / frame_size;
/*DEBUG("waiting for decoded audio, play silence\n");*/ /*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; break;
} }
} }
@ -540,13 +540,13 @@ static gpointer player_task(G_GNUC_UNUSED gpointer arg)
break; break;
case PLAYER_COMMAND_CLOSE_AUDIO: case PLAYER_COMMAND_CLOSE_AUDIO:
closeAudioDevice(); audio_output_all_close();
player_command_finished(); player_command_finished();
break; break;
case PLAYER_COMMAND_EXIT: case PLAYER_COMMAND_EXIT:
dc_quit(); dc_quit();
closeAudioDevice(); audio_output_all_close();
player_command_finished(); player_command_finished();
g_thread_exit(NULL); g_thread_exit(NULL);
break; break;