diff options
author | Max Kellermann <max@duempel.org> | 2014-05-22 11:10:41 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-05-22 12:35:20 +0200 |
commit | 4eeea640f4641ec7c2b303567adf3e79855eb885 (patch) | |
tree | b56039e1576a437594230027766b7bd0c5cec9e7 /src/decoder/DecoderAPI.cxx | |
parent | cc6f1020d01a6f8f814a6a6a211a00d490459f66 (diff) | |
download | mpd-4eeea640f4641ec7c2b303567adf3e79855eb885.tar.gz mpd-4eeea640f4641ec7c2b303567adf3e79855eb885.tar.xz mpd-4eeea640f4641ec7c2b303567adf3e79855eb885.zip |
DecoderAPI: add function decoder_open_uri()
Move and refactor code from the Wavpack decoder plugin.
Diffstat (limited to '')
-rw-r--r-- | src/decoder/DecoderAPI.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/decoder/DecoderAPI.cxx b/src/decoder/DecoderAPI.cxx index 555e5c89b..5c4822804 100644 --- a/src/decoder/DecoderAPI.cxx +++ b/src/decoder/DecoderAPI.cxx @@ -240,6 +240,38 @@ void decoder_seek_error(Decoder & decoder) decoder_command_finished(decoder); } +InputStream * +decoder_open_uri(Decoder &decoder, const char *uri, Error &error) +{ + assert(decoder.dc.state == DecoderState::START || + decoder.dc.state == DecoderState::DECODE); + + DecoderControl &dc = decoder.dc; + Mutex &mutex = dc.mutex; + Cond &cond = dc.cond; + + InputStream *is = InputStream::Open(uri, mutex, cond, error); + if (is == nullptr) + return nullptr; + + mutex.lock(); + while (true) { + is->Update(); + if (is->IsReady()) { + mutex.unlock(); + return is; + } + + if (dc.command == DecoderCommand::STOP) { + mutex.unlock(); + delete is; + return nullptr; + } + + cond.wait(mutex); + } +} + /** * Should be read operation be cancelled? That is the case when the * player thread has sent a command such as "STOP". |