aboutsummaryrefslogtreecommitdiffstats
path: root/src/player_thread.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-10-06 20:55:52 +0200
committerMax Kellermann <max@duempel.org>2011-10-06 20:55:52 +0200
commit63b33b6ec584a6730174c45a119a27b4add76777 (patch)
tree79526a2ae0e6a430971a1aeda06c62944d68fd83 /src/player_thread.c
parent23670795db6a1ef9f16862513b2efa6fe82928c4 (diff)
downloadmpd-63b33b6ec584a6730174c45a119a27b4add76777.tar.gz
mpd-63b33b6ec584a6730174c45a119a27b4add76777.tar.xz
mpd-63b33b6ec584a6730174c45a119a27b4add76777.zip
player_thread: move code to player_open_output()
Common function that manages "player" attributes after audio_output_all_open() has returned.
Diffstat (limited to '')
-rw-r--r--src/player_thread.c59
1 files changed, 37 insertions, 22 deletions
diff --git a/src/player_thread.c b/src/player_thread.c
index 31bb3d50d..9a7c917f4 100644
--- a/src/player_thread.c
+++ b/src/player_thread.c
@@ -277,6 +277,41 @@ real_song_duration(const struct song *song, double decoder_duration)
}
/**
+ * Wrapper for audio_output_all_open(). Upon failure, it pauses the
+ * player.
+ *
+ * @return true on success
+ */
+static bool
+player_open_output(struct player *player)
+{
+ assert(audio_format_defined(&player->play_audio_format));
+ assert(pc.state == PLAYER_STATE_PLAY ||
+ pc.state == PLAYER_STATE_PAUSE);
+
+ if (audio_output_all_open(&player->play_audio_format, player_buffer)) {
+ player->paused = false;
+
+ player_lock();
+ pc.state = PLAYER_STATE_PLAY;
+ player_unlock();
+
+ return true;
+ } else {
+ /* pause: the user may resume playback as soon as an
+ audio output becomes available */
+ player->paused = true;
+
+ player_lock();
+ pc.error = PLAYER_ERROR_AUDIO;
+ pc.state = PLAYER_STATE_PAUSE;
+ player_unlock();
+
+ return false;
+ }
+}
+
+/**
* The decoder has acknowledged the "START" command (see
* player_wait_for_decoder()). This function checks if the decoder
* initialization has completed yet.
@@ -321,23 +356,12 @@ player_check_decoder_startup(struct player *player)
player->play_audio_format = dc->out_audio_format;
player->decoder_starting = false;
- if (!player->paused &&
- !audio_output_all_open(&dc->out_audio_format,
- player_buffer)) {
+ if (!player->paused && !player_open_output(player)) {
char *uri = song_get_uri(dc->song);
g_warning("problems opening audio device "
"while playing \"%s\"", uri);
g_free(uri);
- player_lock();
- pc.error = PLAYER_ERROR_AUDIO;
-
- /* pause: the user may resume playback as soon
- as an audio output becomes available */
- pc.state = PLAYER_STATE_PAUSE;
- player_unlock();
-
- player->paused = true;
return true;
}
@@ -517,17 +541,8 @@ static void player_process_command(struct player *player)
player_lock();
pc.state = PLAYER_STATE_PLAY;
- } else if (audio_output_all_open(&player->play_audio_format, player_buffer)) {
- /* unpaused, continue playing */
- player_lock();
-
- pc.state = PLAYER_STATE_PLAY;
} else {
- /* the audio device has failed - rollback to
- pause mode */
- pc.error = PLAYER_ERROR_AUDIO;
-
- player->paused = true;
+ player_open_output(player);
player_lock();
}