decoder/Control: throw exception on Seek() error

This commit is contained in:
Max Kellermann 2016-11-07 09:03:17 +01:00
parent 403f0f8c64
commit 4cd21f1e07
4 changed files with 18 additions and 21 deletions

View File

@ -362,7 +362,6 @@ CommandResult
command_process(Client &client, unsigned num, char *line)
try {
Response r(client, num);
Error error;
/* get the command name (first word on the line) */
/* we have to set current_command because Response::Error()

View File

@ -22,7 +22,8 @@
#include "DecoderError.hxx"
#include "MusicPipe.hxx"
#include "DetachedSong.hxx"
#include "util/Error.hxx"
#include <stdexcept>
#include <assert.h>
@ -104,8 +105,8 @@ DecoderControl::Stop()
SynchronousCommandLocked(DecoderCommand::STOP);
}
bool
DecoderControl::Seek(SongTime t, Error &error_r)
void
DecoderControl::Seek(SongTime t)
{
assert(state != DecoderState::START);
assert(state != DecoderState::ERROR);
@ -118,28 +119,21 @@ DecoderControl::Seek(SongTime t, Error &error_r)
case DecoderState::STOP:
/* TODO: if this happens, the caller should be given a
chance to restart the decoder */
error_r.Set(decoder_domain, "Decoder is dead");
return false;
throw std::runtime_error("Decoder is dead");
case DecoderState::DECODE:
break;
}
if (!seekable) {
error_r.Set(decoder_domain, "Not seekable");
return false;
}
if (!seekable)
throw std::runtime_error("Not seekable");
seek_time = t;
seek_error = false;
LockSynchronousCommand(DecoderCommand::SEEK);
if (seek_error) {
error_r.Set(decoder_domain, "Decoder failed to seek");
return false;
}
return true;
if (seek_error)
throw std::runtime_error("Decoder failed to seek");
}
void

View File

@ -40,7 +40,6 @@
#undef ERROR
#endif
class Error;
class DetachedSong;
class MusicBuffer;
class MusicPipe;
@ -367,7 +366,10 @@ public:
void Stop();
bool Seek(SongTime t, Error &error_r);
/**
* Throws #std::runtime_error on error.
*/
void Seek(SongTime t);
void Quit();

View File

@ -618,10 +618,12 @@ Player::SeekDecoder()
where = total_time;
}
Error error;
if (!dc.Seek(where + start_time, error)) {
try {
dc.Seek(where + start_time);
} catch (...) {
/* decoder failure */
pc.SetError(PlayerError::DECODER, std::move(error));
pc.SetError(PlayerError::DECODER,
std::current_exception());
pc.LockCommandFinished();
return false;
}