Commit d0f6131b authored by Max Kellermann's avatar Max Kellermann

output/Interface: allow Pause() to throw exception

Coverity discovered that the Pulse plugin could throw exceptions from Pause(), but that method was marked "noexcept" because its caller was not designed to catch exceptions. So instead of avoiding exceptions (by catching and logging them in each and every implementation), let's allow them, and do the catch/log game in the MPD core.
parent 9cc37bde
...@@ -140,8 +140,11 @@ public: ...@@ -140,8 +140,11 @@ public:
* *
* @return false on error (output will be closed by caller), * @return false on error (output will be closed by caller),
* true for continue to pause * true for continue to pause
*
* Instead of returning false, the method may throw an
* exception, which will be logged.
*/ */
virtual bool Pause() noexcept { virtual bool Pause() {
/* fail because this method is not implemented */ /* fail because this method is not implemented */
return false; return false;
} }
......
...@@ -135,7 +135,7 @@ struct JackOutput final : AudioOutput { ...@@ -135,7 +135,7 @@ struct JackOutput final : AudioOutput {
size_t Play(const void *chunk, size_t size) override; size_t Play(const void *chunk, size_t size) override;
bool Pause() noexcept override; bool Pause() override;
}; };
static constexpr Domain jack_output_domain("jack_output"); static constexpr Domain jack_output_domain("jack_output");
...@@ -661,7 +661,7 @@ JackOutput::Play(const void *chunk, size_t size) ...@@ -661,7 +661,7 @@ JackOutput::Play(const void *chunk, size_t size)
} }
inline bool inline bool
JackOutput::Pause() noexcept JackOutput::Pause()
{ {
if (shutdown) if (shutdown)
return false; return false;
......
...@@ -103,7 +103,7 @@ public: ...@@ -103,7 +103,7 @@ public:
std::chrono::steady_clock::duration Delay() const noexcept override; std::chrono::steady_clock::duration Delay() const noexcept override;
size_t Play(const void *chunk, size_t size) override; size_t Play(const void *chunk, size_t size) override;
void Cancel() noexcept override; void Cancel() noexcept override;
bool Pause() noexcept override; bool Pause() override;
private: private:
/** /**
...@@ -826,7 +826,7 @@ PulseOutput::Cancel() noexcept ...@@ -826,7 +826,7 @@ PulseOutput::Cancel() noexcept
} }
bool bool
PulseOutput::Pause() noexcept PulseOutput::Pause()
{ {
assert(mainloop != nullptr); assert(mainloop != nullptr);
assert(stream != nullptr); assert(stream != nullptr);
......
...@@ -65,7 +65,7 @@ struct ShoutOutput final : AudioOutput { ...@@ -65,7 +65,7 @@ struct ShoutOutput final : AudioOutput {
void SendTag(const Tag &tag) override; void SendTag(const Tag &tag) override;
size_t Play(const void *chunk, size_t size) override; size_t Play(const void *chunk, size_t size) override;
void Cancel() noexcept override; void Cancel() noexcept override;
bool Pause() noexcept override; bool Pause() override;
private: private:
void WritePage(); void WritePage();
...@@ -378,16 +378,12 @@ ShoutOutput::Play(const void *chunk, size_t size) ...@@ -378,16 +378,12 @@ ShoutOutput::Play(const void *chunk, size_t size)
} }
bool bool
ShoutOutput::Pause() noexcept ShoutOutput::Pause()
{ {
static char silence[1020]; static char silence[1020];
try {
encoder->Write(silence, sizeof(silence)); encoder->Write(silence, sizeof(silence));
WritePage(); WritePage();
} catch (const std::runtime_error &) {
return false;
}
return true; return true;
} }
......
...@@ -252,7 +252,7 @@ public: ...@@ -252,7 +252,7 @@ public:
void CancelAllClients(); void CancelAllClients();
void Cancel() noexcept override; void Cancel() noexcept override;
bool Pause() noexcept override; bool Pause() override;
private: private:
virtual void RunDeferred() override; virtual void RunDeferred() override;
......
...@@ -371,7 +371,7 @@ HttpdOutput::Play(const void *chunk, size_t size) ...@@ -371,7 +371,7 @@ HttpdOutput::Play(const void *chunk, size_t size)
} }
bool bool
HttpdOutput::Pause() noexcept HttpdOutput::Pause()
{ {
pause = true; pause = true;
......
...@@ -102,7 +102,7 @@ private: ...@@ -102,7 +102,7 @@ private:
void Drain() override; void Drain() override;
void Cancel() noexcept override; void Cancel() noexcept override;
bool Pause() noexcept override; bool Pause() override;
private: private:
void PlayedCallback(); void PlayedCallback();
...@@ -368,7 +368,7 @@ SlesOutput::Cancel() noexcept ...@@ -368,7 +368,7 @@ SlesOutput::Cancel() noexcept
} }
bool bool
SlesOutput::Pause() noexcept SlesOutput::Pause()
{ {
cancel = false; cancel = false;
...@@ -378,10 +378,8 @@ SlesOutput::Pause() noexcept ...@@ -378,10 +378,8 @@ SlesOutput::Pause() noexcept
pause = true; pause = true;
SLresult result = play.SetPlayState(SL_PLAYSTATE_PAUSED); SLresult result = play.SetPlayState(SL_PLAYSTATE_PAUSED);
if (result != SL_RESULT_SUCCESS) { if (result != SL_RESULT_SUCCESS)
FormatError(sles_domain, "Play.SetPlayState(PAUSED) failed"); throw std::runtime_error("Play.SetPlayState(PAUSED) failed");
return false;
}
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment