summaryrefslogtreecommitdiff
path: root/src/decoder
diff options
context:
space:
mode:
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/Bridge.cxx14
-rw-r--r--src/decoder/Bridge.hxx2
-rw-r--r--src/decoder/Control.cxx2
-rw-r--r--src/decoder/Control.hxx4
-rw-r--r--src/decoder/Thread.cxx2
5 files changed, 21 insertions, 3 deletions
diff --git a/src/decoder/Bridge.cxx b/src/decoder/Bridge.cxx
index 36f991529..36c269489 100644
--- a/src/decoder/Bridge.cxx
+++ b/src/decoder/Bridge.cxx
@@ -31,6 +31,8 @@
#include "Log.hxx"
#include "input/InputStream.hxx"
#include "input/LocalOpen.hxx"
+#include "input/cache/Manager.hxx"
+#include "input/cache/Stream.hxx"
#include "fs/Path.hxx"
#include "util/ConstBuffer.hxx"
#include "util/StringBuffer.hxx"
@@ -52,8 +54,18 @@ DecoderBridge::~DecoderBridge() noexcept
}
InputStreamPtr
-DecoderBridge::OpenLocal(Path path_fs)
+DecoderBridge::OpenLocal(Path path_fs, const char *uri_utf8)
{
+ if (dc.input_cache != nullptr) {
+ auto lease = dc.input_cache->Get(uri_utf8, true);
+ if (lease) {
+ auto is = std::make_unique<CacheInputStream>(std::move(lease),
+ dc.mutex);
+ is->SetHandler(&dc);
+ return is;
+ }
+ }
+
return OpenLocalInputStream(path_fs, dc.mutex);
}
diff --git a/src/decoder/Bridge.hxx b/src/decoder/Bridge.hxx
index 2f1833b6d..3814d7a42 100644
--- a/src/decoder/Bridge.hxx
+++ b/src/decoder/Bridge.hxx
@@ -157,7 +157,7 @@ public:
/**
* Open a local file.
*/
- InputStreamPtr OpenLocal(Path path_fs);
+ InputStreamPtr OpenLocal(Path path_fs, const char *uri_utf8);
/* virtual methods from DecoderClient */
void Ready(AudioFormat audio_format,
diff --git a/src/decoder/Control.cxx b/src/decoder/Control.cxx
index 75473d5e2..c8c04c079 100644
--- a/src/decoder/Control.cxx
+++ b/src/decoder/Control.cxx
@@ -26,9 +26,11 @@
#include <assert.h>
DecoderControl::DecoderControl(Mutex &_mutex, Cond &_client_cond,
+ InputCacheManager *_input_cache,
const AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config) noexcept
:thread(BIND_THIS_METHOD(RunThread)),
+ input_cache(_input_cache),
mutex(_mutex), client_cond(_client_cond),
configured_audio_format(_configured_audio_format),
replay_gain_config(_replay_gain_config) {}
diff --git a/src/decoder/Control.hxx b/src/decoder/Control.hxx
index f6a45a2b4..e68cd609e 100644
--- a/src/decoder/Control.hxx
+++ b/src/decoder/Control.hxx
@@ -46,6 +46,7 @@
class DetachedSong;
class MusicBuffer;
class MusicPipe;
+class InputCacheManager;
enum class DecoderState : uint8_t {
STOP = 0,
@@ -68,6 +69,8 @@ class DecoderControl final : public InputStreamHandler {
Thread thread;
public:
+ InputCacheManager *const input_cache;
+
/**
* This lock protects #state and #command.
*
@@ -181,6 +184,7 @@ public:
* @param _client_cond see #client_cond
*/
DecoderControl(Mutex &_mutex, Cond &_client_cond,
+ InputCacheManager *_input_cache,
const AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config) noexcept;
~DecoderControl() noexcept;
diff --git a/src/decoder/Thread.cxx b/src/decoder/Thread.cxx
index 6bc1836ec..ec8cf49ad 100644
--- a/src/decoder/Thread.cxx
+++ b/src/decoder/Thread.cxx
@@ -346,7 +346,7 @@ decoder_run_file(DecoderBridge &bridge, const char *uri_utf8, Path path_fs)
InputStreamPtr input_stream;
try {
- input_stream = bridge.OpenLocal(path_fs);
+ input_stream = bridge.OpenLocal(path_fs, uri_utf8);
} catch (const std::system_error &e) {
if (IsPathNotFound(e) &&
/* ENOTDIR means this may be a path inside a