summaryrefslogtreecommitdiff
path: root/src/player/Thread.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/player/Thread.cxx')
-rw-r--r--src/player/Thread.cxx61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx
index 9acc091a3..42f3d8d4e 100644
--- a/src/player/Thread.cxx
+++ b/src/player/Thread.cxx
@@ -37,6 +37,8 @@
#include "thread/Name.hxx"
#include "Log.hxx"
+#include <stdexcept>
+
#include <string.h>
static constexpr Domain player_domain("player");
@@ -443,20 +445,10 @@ Player::OpenOutput()
assert(pc.state == PlayerState::PLAY ||
pc.state == PlayerState::PAUSE);
- Error error;
- if (pc.outputs.Open(play_audio_format, buffer, error)) {
- output_open = true;
- paused = false;
-
- pc.Lock();
- pc.state = PlayerState::PLAY;
- pc.Unlock();
-
- idle_add(IDLE_PLAYER);
-
- return true;
- } else {
- LogError(error);
+ try {
+ pc.outputs.Open(play_audio_format, buffer);
+ } catch (const std::runtime_error &e) {
+ LogError(e);
output_open = false;
@@ -465,7 +457,7 @@ Player::OpenOutput()
paused = true;
pc.Lock();
- pc.SetError(PlayerError::OUTPUT, std::move(error));
+ pc.SetError(PlayerError::OUTPUT, std::current_exception());
pc.state = PlayerState::PAUSE;
pc.Unlock();
@@ -473,6 +465,17 @@ Player::OpenOutput()
return false;
}
+
+ output_open = true;
+ paused = false;
+
+ pc.Lock();
+ pc.state = PlayerState::PLAY;
+ pc.Unlock();
+
+ idle_add(IDLE_PLAYER);
+
+ return true;
}
bool
@@ -556,9 +559,10 @@ Player::SendSilence()
chunk->length = num_frames * frame_size;
PcmSilence({chunk->data, chunk->length}, play_audio_format.format);
- Error error;
- if (!pc.outputs.Play(chunk, error)) {
- LogError(error);
+ try {
+ pc.outputs.Play(chunk);
+ } catch (const std::runtime_error &e) {
+ LogError(e);
buffer.Return(chunk);
return false;
}
@@ -770,12 +774,11 @@ update_song_tag(PlayerControl &pc, DetachedSong &song, const Tag &new_tag)
*
* Player lock is not held.
*/
-static bool
+static void
play_chunk(PlayerControl &pc,
DetachedSong &song, MusicChunk *chunk,
MusicBuffer &buffer,
- const AudioFormat format,
- Error &error)
+ const AudioFormat format)
{
assert(chunk->CheckFormat(format));
@@ -784,7 +787,7 @@ play_chunk(PlayerControl &pc,
if (chunk->IsEmpty()) {
buffer.Return(chunk);
- return true;
+ return;
}
pc.Lock();
@@ -793,12 +796,9 @@ play_chunk(PlayerControl &pc,
/* send the chunk to the audio outputs */
- if (!pc.outputs.Play(chunk, error))
- return false;
-
+ pc.outputs.Play(chunk);
pc.total_play_time += (double)chunk->length /
format.GetTimeToSize();
- return true;
}
inline bool
@@ -899,15 +899,16 @@ Player::PlayNextChunk()
/* play the current chunk */
- Error error;
- if (!play_chunk(pc, *song, chunk, buffer, play_audio_format, error)) {
- LogError(error);
+ try {
+ play_chunk(pc, *song, chunk, buffer, play_audio_format);
+ } catch (const std::runtime_error &e) {
+ LogError(e);
buffer.Return(chunk);
pc.Lock();
- pc.SetError(PlayerError::OUTPUT, std::move(error));
+ pc.SetError(PlayerError::OUTPUT, std::current_exception());
/* pause: the user may resume playback as soon as an
audio output becomes available */