input/Stream: remove attribute "cond", replace with handler interface

This adds a bit of overhead, but also adds flexibility to the API,
because arbitrary triggers may be invoked from that virtual method
implementation, not just Cond::signal().

The motivation for this is to make the handlers more dynamic, for the
upcoming buffering class utilizing ProxyInputStream.
This commit is contained in:
Max Kellermann
2018-06-22 19:37:18 +02:00
parent 01d8eb6290
commit d0fbf6db59
66 changed files with 403 additions and 280 deletions

View File

@@ -370,7 +370,8 @@ DecoderBridge::OpenUri(const char *uri)
Mutex &mutex = dc.mutex;
Cond &cond = dc.cond;
auto is = InputStream::Open(uri, mutex, cond);
auto is = InputStream::Open(uri, mutex);
is->SetHandler(&dc);
const std::lock_guard<Mutex> lock(mutex);
while (true) {
@@ -404,7 +405,7 @@ try {
if (is.IsAvailable())
break;
is.cond.wait(is.mutex);
dc.cond.wait(is.mutex);
}
size_t nbytes = is.Read(buffer, length);

View File

@@ -23,6 +23,7 @@
#include "DecoderCommand.hxx"
#include "AudioFormat.hxx"
#include "MixRampInfo.hxx"
#include "input/Handler.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "thread/Thread.hxx"
@@ -60,7 +61,7 @@ enum class DecoderState : uint8_t {
ERROR,
};
struct DecoderControl {
struct DecoderControl final : InputStreamHandler {
/**
* The handle of the decoder thread.
*/
@@ -422,6 +423,15 @@ public:
private:
void RunThread() noexcept;
/* virtual methods from class InputStreamHandler */
void OnInputStreamReady() noexcept override {
cond.signal();
}
void OnInputStreamAvailable() noexcept override {
cond.signal();
}
};
#endif

View File

@@ -56,7 +56,8 @@ static constexpr Domain decoder_thread_domain("decoder_thread");
static InputStreamPtr
decoder_input_stream_open(DecoderControl &dc, const char *uri)
{
auto is = InputStream::Open(uri, dc.mutex, dc.cond);
auto is = InputStream::Open(uri, dc.mutex);
is->SetHandler(&dc);
/* wait for the input stream to become ready; its metadata
will be available then */
@@ -81,7 +82,7 @@ decoder_input_stream_open(DecoderControl &dc, const char *uri)
static InputStreamPtr
decoder_input_stream_open(DecoderControl &dc, Path path)
{
auto is = OpenLocalInputStream(path, dc.mutex, dc.cond);
auto is = OpenLocalInputStream(path, dc.mutex);
assert(is->IsReady());