input/cache: first draft of the file cache

This commit is contained in:
Max Kellermann
2019-05-08 18:39:00 +02:00
parent e8a0ce643a
commit 5d74b5cee1
27 changed files with 880 additions and 6 deletions

View File

@@ -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);
}

View File

@@ -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,

View File

@@ -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) {}

View File

@@ -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;

View File

@@ -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