Commit 94c9fafe authored by Max Kellermann's avatar Max Kellermann

lib/chromaprint/DecoderClient: catch and postpone InputStream::LockRead() errors

parent 8480b834
...@@ -305,7 +305,12 @@ GetChromaprintCommand::Read(InputStream &is, void *buffer, size_t length) ...@@ -305,7 +305,12 @@ GetChromaprintCommand::Read(InputStream &is, void *buffer, size_t length)
cond.wait(lock); cond.wait(lock);
} }
try {
return is.Read(lock, buffer, length); return is.Read(lock, buffer, length);
} catch (...) {
ChromaprintDecoderClient::error = std::current_exception();
return 0;
}
} }
CommandResult CommandResult
......
...@@ -28,6 +28,9 @@ ChromaprintDecoderClient::~ChromaprintDecoderClient() noexcept = default; ...@@ -28,6 +28,9 @@ ChromaprintDecoderClient::~ChromaprintDecoderClient() noexcept = default;
void void
ChromaprintDecoderClient::Finish() ChromaprintDecoderClient::Finish()
{ {
if (error)
std::rethrow_exception(error);
if (!ready) if (!ready)
throw std::runtime_error("Decoding failed"); throw std::runtime_error("Decoding failed");
...@@ -86,5 +89,10 @@ ChromaprintDecoderClient::SubmitData(InputStream *, ...@@ -86,5 +89,10 @@ ChromaprintDecoderClient::SubmitData(InputStream *,
size_t size_t
ChromaprintDecoderClient::Read(InputStream &is, void *buffer, size_t length) ChromaprintDecoderClient::Read(InputStream &is, void *buffer, size_t length)
{ {
try {
return is.LockRead(buffer, length); return is.LockRead(buffer, length);
} catch (...) {
error = std::current_exception();
return 0;
}
} }
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "decoder/Client.hxx" #include "decoder/Client.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include <exception>
#include <memory> #include <memory>
#include <stdint.h> #include <stdint.h>
...@@ -39,6 +40,13 @@ class ChromaprintDecoderClient : public DecoderClient { ...@@ -39,6 +40,13 @@ class ChromaprintDecoderClient : public DecoderClient {
uint64_t remaining_bytes; uint64_t remaining_bytes;
protected:
/**
* This is set when an I/O error occurs while decoding; it
* will be rethrown by Finish().
*/
std::exception_ptr error;
public: public:
Mutex mutex; Mutex mutex;
...@@ -63,7 +71,7 @@ public: ...@@ -63,7 +71,7 @@ public:
bool seekable, SignedSongTime duration) override; bool seekable, SignedSongTime duration) override;
DecoderCommand GetCommand() noexcept override { DecoderCommand GetCommand() noexcept override {
return remaining_bytes > 0 return !error && remaining_bytes > 0
? DecoderCommand::NONE ? DecoderCommand::NONE
: DecoderCommand::STOP; : DecoderCommand::STOP;
} }
......
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