input/cache: first draft of the file cache
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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,
|
||||
|
@@ -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) {}
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user