encoder: migrate from class Error to C++ exceptions
This commit is contained in:
@@ -171,8 +171,10 @@ public:
|
||||
|
||||
/**
|
||||
* Caller must lock the mutex.
|
||||
*
|
||||
* Throws #std::runtime_error on error.
|
||||
*/
|
||||
bool OpenEncoder(AudioFormat &audio_format, Error &error);
|
||||
void OpenEncoder(AudioFormat &audio_format);
|
||||
|
||||
/**
|
||||
* Caller must lock the mutex.
|
||||
@@ -237,7 +239,10 @@ public:
|
||||
*/
|
||||
void BroadcastFromEncoder();
|
||||
|
||||
bool EncodeAndPlay(const void *chunk, size_t size, Error &error);
|
||||
/**
|
||||
* Throws #std::runtime_error on error.
|
||||
*/
|
||||
void EncodeAndPlay(const void *chunk, size_t size);
|
||||
|
||||
void SendTag(const Tag &tag);
|
||||
|
||||
|
||||
@@ -221,7 +221,12 @@ HttpdOutput::ReadPage()
|
||||
/* we have fed a lot of input into the encoder, but it
|
||||
didn't give anything back yet - flush now to avoid
|
||||
buffer underruns */
|
||||
encoder->Flush(IgnoreError());
|
||||
try {
|
||||
encoder->Flush();
|
||||
} catch (const std::runtime_error &) {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
unflushed_input = 0;
|
||||
}
|
||||
|
||||
@@ -260,12 +265,10 @@ httpd_output_disable(AudioOutput *ao)
|
||||
httpd->Unbind();
|
||||
}
|
||||
|
||||
inline bool
|
||||
HttpdOutput::OpenEncoder(AudioFormat &audio_format, Error &error)
|
||||
inline void
|
||||
HttpdOutput::OpenEncoder(AudioFormat &audio_format)
|
||||
{
|
||||
encoder = prepared_encoder->Open(audio_format, error);
|
||||
if (encoder == nullptr)
|
||||
return false;
|
||||
encoder = prepared_encoder->Open(audio_format);
|
||||
|
||||
/* we have to remember the encoder header, i.e. the first
|
||||
bytes of encoder output after opening it, because it has to
|
||||
@@ -273,20 +276,15 @@ HttpdOutput::OpenEncoder(AudioFormat &audio_format, Error &error)
|
||||
header = ReadPage();
|
||||
|
||||
unflushed_input = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool
|
||||
HttpdOutput::Open(AudioFormat &audio_format, Error &error)
|
||||
HttpdOutput::Open(AudioFormat &audio_format, Error &)
|
||||
{
|
||||
assert(!open);
|
||||
assert(clients.empty());
|
||||
|
||||
/* open the encoder */
|
||||
|
||||
if (!OpenEncoder(audio_format, error))
|
||||
return false;
|
||||
OpenEncoder(audio_format);
|
||||
|
||||
/* initialize other attributes */
|
||||
|
||||
@@ -410,25 +408,21 @@ HttpdOutput::BroadcastFromEncoder()
|
||||
DeferredMonitor::Schedule();
|
||||
}
|
||||
|
||||
inline bool
|
||||
HttpdOutput::EncodeAndPlay(const void *chunk, size_t size, Error &error)
|
||||
inline void
|
||||
HttpdOutput::EncodeAndPlay(const void *chunk, size_t size)
|
||||
{
|
||||
if (!encoder->Write(chunk, size, error))
|
||||
return false;
|
||||
encoder->Write(chunk, size);
|
||||
|
||||
unflushed_input += size;
|
||||
|
||||
BroadcastFromEncoder();
|
||||
return true;
|
||||
}
|
||||
|
||||
inline size_t
|
||||
HttpdOutput::Play(const void *chunk, size_t size, Error &error)
|
||||
HttpdOutput::Play(const void *chunk, size_t size, Error &)
|
||||
{
|
||||
if (LockHasClients()) {
|
||||
if (!EncodeAndPlay(chunk, size, error))
|
||||
return 0;
|
||||
}
|
||||
if (LockHasClients())
|
||||
EncodeAndPlay(chunk, size);
|
||||
|
||||
if (!timer->IsStarted())
|
||||
timer->Start();
|
||||
@@ -468,13 +462,22 @@ HttpdOutput::SendTag(const Tag &tag)
|
||||
|
||||
/* flush the current stream, and end it */
|
||||
|
||||
encoder->PreTag(IgnoreError());
|
||||
try {
|
||||
encoder->PreTag();
|
||||
} catch (const std::runtime_error &) {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
BroadcastFromEncoder();
|
||||
|
||||
/* send the tag to the encoder - which starts a new
|
||||
stream now */
|
||||
|
||||
encoder->SendTag(tag, IgnoreError());
|
||||
try {
|
||||
encoder->SendTag(tag);
|
||||
} catch (const std::runtime_error &) {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
/* the first page generated by the encoder will now be
|
||||
used as the new "header" page, which is sent to all
|
||||
|
||||
Reference in New Issue
Block a user