player/Control: add "noexcept"

This commit is contained in:
Max Kellermann 2017-11-26 12:02:08 +01:00
parent 618704f504
commit 624e679e35
3 changed files with 66 additions and 66 deletions

View File

@ -32,7 +32,7 @@ PlayerControl::PlayerControl(PlayerListener &_listener,
unsigned _buffer_chunks, unsigned _buffer_chunks,
unsigned _buffered_before_play, unsigned _buffered_before_play,
AudioFormat _configured_audio_format, AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config) const ReplayGainConfig &_replay_gain_config) noexcept
:listener(_listener), outputs(_outputs), :listener(_listener), outputs(_outputs),
buffer_chunks(_buffer_chunks), buffer_chunks(_buffer_chunks),
buffered_before_play(_buffered_before_play), buffered_before_play(_buffered_before_play),
@ -42,14 +42,14 @@ PlayerControl::PlayerControl(PlayerListener &_listener,
{ {
} }
PlayerControl::~PlayerControl() PlayerControl::~PlayerControl() noexcept
{ {
delete next_song; delete next_song;
delete tagged_song; delete tagged_song;
} }
bool bool
PlayerControl::WaitOutputConsumed(unsigned threshold) PlayerControl::WaitOutputConsumed(unsigned threshold) noexcept
{ {
bool result = outputs.Check() < threshold; bool result = outputs.Check() < threshold;
if (!result && command == PlayerCommand::NONE) { if (!result && command == PlayerCommand::NONE) {
@ -75,14 +75,14 @@ PlayerControl::Play(DetachedSong *song)
} }
void void
PlayerControl::LockCancel() PlayerControl::LockCancel() noexcept
{ {
LockSynchronousCommand(PlayerCommand::CANCEL); LockSynchronousCommand(PlayerCommand::CANCEL);
assert(next_song == nullptr); assert(next_song == nullptr);
} }
void void
PlayerControl::LockStop() PlayerControl::LockStop() noexcept
{ {
LockSynchronousCommand(PlayerCommand::CLOSE_AUDIO); LockSynchronousCommand(PlayerCommand::CLOSE_AUDIO);
assert(next_song == nullptr); assert(next_song == nullptr);
@ -91,13 +91,13 @@ PlayerControl::LockStop()
} }
void void
PlayerControl::LockUpdateAudio() PlayerControl::LockUpdateAudio() noexcept
{ {
LockSynchronousCommand(PlayerCommand::UPDATE_AUDIO); LockSynchronousCommand(PlayerCommand::UPDATE_AUDIO);
} }
void void
PlayerControl::Kill() PlayerControl::Kill() noexcept
{ {
assert(thread.IsDefined()); assert(thread.IsDefined());
@ -108,7 +108,7 @@ PlayerControl::Kill()
} }
void void
PlayerControl::PauseLocked() PlayerControl::PauseLocked() noexcept
{ {
if (state != PlayerState::STOP) { if (state != PlayerState::STOP) {
SynchronousCommand(PlayerCommand::PAUSE); SynchronousCommand(PlayerCommand::PAUSE);
@ -117,14 +117,14 @@ PlayerControl::PauseLocked()
} }
void void
PlayerControl::LockPause() PlayerControl::LockPause() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
PauseLocked(); PauseLocked();
} }
void void
PlayerControl::LockSetPause(bool pause_flag) PlayerControl::LockSetPause(bool pause_flag) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
@ -145,7 +145,7 @@ PlayerControl::LockSetPause(bool pause_flag)
} }
void void
PlayerControl::LockSetBorderPause(bool _border_pause) PlayerControl::LockSetBorderPause(bool _border_pause) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
border_pause = _border_pause; border_pause = _border_pause;
@ -172,7 +172,7 @@ PlayerControl::LockGetStatus() noexcept
} }
void void
PlayerControl::SetError(PlayerError type, std::exception_ptr &&_error) PlayerControl::SetError(PlayerError type, std::exception_ptr &&_error) noexcept
{ {
assert(type != PlayerError::NONE); assert(type != PlayerError::NONE);
assert(_error); assert(_error);
@ -182,14 +182,14 @@ PlayerControl::SetError(PlayerError type, std::exception_ptr &&_error)
} }
void void
PlayerControl::LockClearError() PlayerControl::LockClearError() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
ClearError(); ClearError();
} }
void void
PlayerControl::LockSetTaggedSong(const DetachedSong &song) PlayerControl::LockSetTaggedSong(const DetachedSong &song) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
delete tagged_song; delete tagged_song;
@ -197,14 +197,14 @@ PlayerControl::LockSetTaggedSong(const DetachedSong &song)
} }
void void
PlayerControl::ClearTaggedSong() PlayerControl::ClearTaggedSong() noexcept
{ {
delete tagged_song; delete tagged_song;
tagged_song = nullptr; tagged_song = nullptr;
} }
void void
PlayerControl::LockEnqueueSong(DetachedSong *song) PlayerControl::LockEnqueueSong(DetachedSong *song) noexcept
{ {
assert(song != nullptr); assert(song != nullptr);
@ -255,7 +255,7 @@ PlayerControl::LockSeek(DetachedSong *song, SongTime t)
} }
void void
PlayerControl::SetCrossFade(float _cross_fade_seconds) PlayerControl::SetCrossFade(float _cross_fade_seconds) noexcept
{ {
if (_cross_fade_seconds < 0) if (_cross_fade_seconds < 0)
_cross_fade_seconds = 0; _cross_fade_seconds = 0;
@ -265,7 +265,7 @@ PlayerControl::SetCrossFade(float _cross_fade_seconds)
} }
void void
PlayerControl::SetMixRampDb(float _mixramp_db) PlayerControl::SetMixRampDb(float _mixramp_db) noexcept
{ {
cross_fade.mixramp_db = _mixramp_db; cross_fade.mixramp_db = _mixramp_db;
@ -273,7 +273,7 @@ PlayerControl::SetMixRampDb(float _mixramp_db)
} }
void void
PlayerControl::SetMixRampDelay(float _mixramp_delay_seconds) PlayerControl::SetMixRampDelay(float _mixramp_delay_seconds) noexcept
{ {
cross_fade.mixramp_delay = _mixramp_delay_seconds; cross_fade.mixramp_delay = _mixramp_delay_seconds;

View File

@ -194,20 +194,20 @@ struct PlayerControl final : AudioOutputClient {
unsigned buffer_chunks, unsigned buffer_chunks,
unsigned buffered_before_play, unsigned buffered_before_play,
AudioFormat _configured_audio_format, AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config); const ReplayGainConfig &_replay_gain_config) noexcept;
~PlayerControl(); ~PlayerControl() noexcept;
/** /**
* Locks the object. * Locks the object.
*/ */
void Lock() const { void Lock() const noexcept {
mutex.lock(); mutex.lock();
} }
/** /**
* Unlocks the object. * Unlocks the object.
*/ */
void Unlock() const { void Unlock() const noexcept {
mutex.unlock(); mutex.unlock();
} }
@ -215,7 +215,7 @@ struct PlayerControl final : AudioOutputClient {
* Signals the object. The object should be locked prior to * Signals the object. The object should be locked prior to
* calling this function. * calling this function.
*/ */
void Signal() { void Signal() noexcept {
cond.signal(); cond.signal();
} }
@ -223,7 +223,7 @@ struct PlayerControl final : AudioOutputClient {
* Signals the object. The object is temporarily locked by * Signals the object. The object is temporarily locked by
* this function. * this function.
*/ */
void LockSignal() { void LockSignal() noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
Signal(); Signal();
} }
@ -233,7 +233,7 @@ struct PlayerControl final : AudioOutputClient {
* valid in the player thread. The object must be locked * valid in the player thread. The object must be locked
* prior to calling this function. * prior to calling this function.
*/ */
void Wait() { void Wait() noexcept {
assert(thread.IsInside()); assert(thread.IsInside());
cond.wait(mutex); cond.wait(mutex);
@ -244,7 +244,7 @@ struct PlayerControl final : AudioOutputClient {
* *
* Caller must lock the object. * Caller must lock the object.
*/ */
void ClientSignal() { void ClientSignal() noexcept {
assert(thread.IsInside()); assert(thread.IsInside());
client_cond.signal(); client_cond.signal();
@ -256,7 +256,7 @@ struct PlayerControl final : AudioOutputClient {
* *
* Caller must lock the object. * Caller must lock the object.
*/ */
void ClientWait() { void ClientWait() noexcept {
assert(!thread.IsInside()); assert(!thread.IsInside());
client_cond.wait(mutex); client_cond.wait(mutex);
@ -269,14 +269,14 @@ struct PlayerControl final : AudioOutputClient {
* To be called from the player thread. Caller must lock the * To be called from the player thread. Caller must lock the
* object. * object.
*/ */
void CommandFinished() { void CommandFinished() noexcept {
assert(command != PlayerCommand::NONE); assert(command != PlayerCommand::NONE);
command = PlayerCommand::NONE; command = PlayerCommand::NONE;
ClientSignal(); ClientSignal();
} }
void LockCommandFinished() { void LockCommandFinished() noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
CommandFinished(); CommandFinished();
} }
@ -291,9 +291,9 @@ struct PlayerControl final : AudioOutputClient {
* @param threshold the maximum number of chunks in the pipe * @param threshold the maximum number of chunks in the pipe
* @return true if there are less than #threshold chunks in the pipe * @return true if there are less than #threshold chunks in the pipe
*/ */
bool WaitOutputConsumed(unsigned threshold); bool WaitOutputConsumed(unsigned threshold) noexcept;
bool LockWaitOutputConsumed(unsigned threshold) { bool LockWaitOutputConsumed(unsigned threshold) noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return WaitOutputConsumed(threshold); return WaitOutputConsumed(threshold);
} }
@ -305,7 +305,7 @@ private:
* To be called from the main thread. Caller must lock the * To be called from the main thread. Caller must lock the
* object. * object.
*/ */
void WaitCommandLocked() { void WaitCommandLocked() noexcept {
while (command != PlayerCommand::NONE) while (command != PlayerCommand::NONE)
ClientWait(); ClientWait();
} }
@ -349,43 +349,43 @@ public:
/** /**
* see PlayerCommand::CANCEL * see PlayerCommand::CANCEL
*/ */
void LockCancel(); void LockCancel() noexcept;
void LockSetPause(bool pause_flag); void LockSetPause(bool pause_flag) noexcept;
private: private:
void PauseLocked(); void PauseLocked() noexcept;
void ClearError() { void ClearError() noexcept {
error_type = PlayerError::NONE; error_type = PlayerError::NONE;
error = std::exception_ptr(); error = std::exception_ptr();
} }
public: public:
void LockPause(); void LockPause() noexcept;
/** /**
* Set the player's #border_pause flag. * Set the player's #border_pause flag.
*/ */
void LockSetBorderPause(bool border_pause); void LockSetBorderPause(bool border_pause) noexcept;
bool ApplyBorderPause() { bool ApplyBorderPause() noexcept {
if (border_pause) if (border_pause)
state = PlayerState::PAUSE; state = PlayerState::PAUSE;
return border_pause; return border_pause;
} }
bool LockApplyBorderPause() { bool LockApplyBorderPause() noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::lock_guard<Mutex> lock(mutex);
return ApplyBorderPause(); return ApplyBorderPause();
} }
void Kill(); void Kill() noexcept;
gcc_pure gcc_pure
player_status LockGetStatus() noexcept; player_status LockGetStatus() noexcept;
PlayerState GetState() const { PlayerState GetState() const noexcept {
return state; return state;
} }
@ -396,12 +396,12 @@ public:
* *
* @param type the error type; must not be #PlayerError::NONE * @param type the error type; must not be #PlayerError::NONE
*/ */
void SetError(PlayerError type, std::exception_ptr &&_error); void SetError(PlayerError type, std::exception_ptr &&_error) noexcept;
/** /**
* Set the error and set state to PlayerState::PAUSE. * Set the error and set state to PlayerState::PAUSE.
*/ */
void SetOutputError(std::exception_ptr &&_error) { void SetOutputError(std::exception_ptr &&_error) noexcept {
SetError(PlayerError::OUTPUT, std::move(_error)); SetError(PlayerError::OUTPUT, std::move(_error));
/* pause: the user may resume playback as soon as an /* pause: the user may resume playback as soon as an
@ -409,7 +409,7 @@ public:
state = PlayerState::PAUSE; state = PlayerState::PAUSE;
} }
void LockSetOutputError(std::exception_ptr &&_error) { void LockSetOutputError(std::exception_ptr &&_error) noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::lock_guard<Mutex> lock(mutex);
SetOutputError(std::move(_error)); SetOutputError(std::move(_error));
} }
@ -433,9 +433,9 @@ public:
CheckRethrowError(); CheckRethrowError();
} }
void LockClearError(); void LockClearError() noexcept;
PlayerError GetErrorType() const { PlayerError GetErrorType() const noexcept {
return error_type; return error_type;
} }
@ -443,16 +443,16 @@ public:
* Set the #tagged_song attribute to a newly allocated copy of * Set the #tagged_song attribute to a newly allocated copy of
* the given #DetachedSong. Locks and unlocks the object. * the given #DetachedSong. Locks and unlocks the object.
*/ */
void LockSetTaggedSong(const DetachedSong &song); void LockSetTaggedSong(const DetachedSong &song) noexcept;
void ClearTaggedSong(); void ClearTaggedSong() noexcept;
/** /**
* Read and clear the #tagged_song attribute. * Read and clear the #tagged_song attribute.
* *
* Caller must lock the object. * Caller must lock the object.
*/ */
DetachedSong *ReadTaggedSong() { DetachedSong *ReadTaggedSong() noexcept {
DetachedSong *result = tagged_song; DetachedSong *result = tagged_song;
tagged_song = nullptr; tagged_song = nullptr;
return result; return result;
@ -461,17 +461,17 @@ public:
/** /**
* Like ReadTaggedSong(), but locks and unlocks the object. * Like ReadTaggedSong(), but locks and unlocks the object.
*/ */
DetachedSong *LockReadTaggedSong() { DetachedSong *LockReadTaggedSong() noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return ReadTaggedSong(); return ReadTaggedSong();
} }
void LockStop(); void LockStop() noexcept;
void LockUpdateAudio(); void LockUpdateAudio() noexcept;
private: private:
void EnqueueSongLocked(DetachedSong *song) { void EnqueueSongLocked(DetachedSong *song) noexcept {
assert(song != nullptr); assert(song != nullptr);
assert(next_song == nullptr); assert(next_song == nullptr);
@ -490,7 +490,7 @@ public:
* @param song the song to be queued; the given instance will be owned * @param song the song to be queued; the given instance will be owned
* and freed by the player * and freed by the player
*/ */
void LockEnqueueSong(DetachedSong *song); void LockEnqueueSong(DetachedSong *song) noexcept;
/** /**
* Makes the player thread seek the specified song to a position. * Makes the player thread seek the specified song to a position.
@ -502,30 +502,30 @@ public:
*/ */
void LockSeek(DetachedSong *song, SongTime t); void LockSeek(DetachedSong *song, SongTime t);
void SetCrossFade(float cross_fade_seconds); void SetCrossFade(float cross_fade_seconds) noexcept;
float GetCrossFade() const { float GetCrossFade() const noexcept {
return cross_fade.duration; return cross_fade.duration;
} }
void SetMixRampDb(float mixramp_db); void SetMixRampDb(float mixramp_db) noexcept;
float GetMixRampDb() const { float GetMixRampDb() const noexcept {
return cross_fade.mixramp_db; return cross_fade.mixramp_db;
} }
void SetMixRampDelay(float mixramp_delay_seconds); void SetMixRampDelay(float mixramp_delay_seconds) noexcept;
float GetMixRampDelay() const { float GetMixRampDelay() const noexcept {
return cross_fade.mixramp_delay; return cross_fade.mixramp_delay;
} }
void LockSetReplayGainMode(ReplayGainMode _mode) { void LockSetReplayGainMode(ReplayGainMode _mode) noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
replay_gain_mode = _mode; replay_gain_mode = _mode;
} }
double GetTotalPlayTime() const { double GetTotalPlayTime() const noexcept {
return total_play_time; return total_play_time;
} }
@ -539,7 +539,7 @@ public:
} }
private: private:
void RunThread(); void RunThread() noexcept;
}; };
#endif #endif

View File

@ -1146,7 +1146,7 @@ do_play(PlayerControl &pc, DecoderControl &dc,
} }
void void
PlayerControl::RunThread() PlayerControl::RunThread() noexcept
{ {
SetThreadName("player"); SetThreadName("player");