diff options
author | wm4 <wm4@nowhere> | 2014-06-22 02:50:52 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-06-22 05:04:05 +0200 |
commit | 5b8298376b3ea548b21b652c495b5fcf3d4b5e78 (patch) | |
tree | a02fd4a94abc0c75b953fb8d2cad55894c3de305 /stream/stream.c | |
parent | ea1650fcc338a11adfbbbf950719c65f33acc574 (diff) | |
download | mpv-5b8298376b3ea548b21b652c495b5fcf3d4b5e78.tar.bz2 mpv-5b8298376b3ea548b21b652c495b5fcf3d4b5e78.tar.xz |
stream: add a file cache
For remarks, pretty much see the manpage additions. Could help with
network streams that require too much seeking (maybe), or might be
extended to help with the use case of watching and downloading a file
at the same time.
In general, it might be a useless feature and could be removed again.
Diffstat (limited to 'stream/stream.c')
-rw-r--r-- | stream/stream.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/stream/stream.c b/stream/stream.c index 2a6136f036..6e903bc8ec 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -766,6 +766,28 @@ stream_t *open_memory_stream(void *data, int len) return s; } +static stream_t *open_cache(stream_t *orig, const char *name) +{ + stream_t *cache = new_stream(); + cache->uncached_type = orig->type; + cache->uncached_stream = orig; + cache->seekable = true; + cache->mode = STREAM_READ; + cache->read_chunk = 4 * STREAM_BUFFER_SIZE; + + cache->url = talloc_strdup(cache, orig->url); + cache->mime_type = talloc_strdup(cache, orig->mime_type); + cache->demuxer = talloc_strdup(cache, orig->demuxer); + cache->lavf_type = talloc_strdup(cache, orig->lavf_type); + cache->safe_origin = orig->safe_origin; + cache->opts = orig->opts; + cache->global = orig->global; + + cache->log = mp_log_new(cache, cache->global->log, name); + + return cache; +} + static struct mp_cache_opts check_cache_opts(stream_t *stream, struct mp_cache_opts *opts) { @@ -794,27 +816,21 @@ int stream_enable_cache(stream_t **stream, struct mp_cache_opts *opts) if (use_opts.size < 1) return -1; - stream_t *cache = new_stream(); - cache->uncached_type = orig->type; - cache->uncached_stream = orig; - cache->seekable = true; - cache->mode = STREAM_READ; - cache->read_chunk = 4 * STREAM_BUFFER_SIZE; - - cache->url = talloc_strdup(cache, orig->url); - cache->mime_type = talloc_strdup(cache, orig->mime_type); - cache->demuxer = talloc_strdup(cache, orig->demuxer); - cache->lavf_type = talloc_strdup(cache, orig->lavf_type); - cache->safe_origin = orig->safe_origin; - cache->opts = orig->opts; - cache->global = orig->global; + stream_t *fcache = open_cache(orig, "file-cache"); + if (stream_file_cache_init(fcache, orig, &use_opts) <= 0) { + fcache->uncached_stream = NULL; // don't free original stream + free_stream(fcache); + fcache = orig; + } - cache->log = mp_log_new(cache, cache->global->log, "cache"); + stream_t *cache = open_cache(fcache, "cache"); - int res = stream_cache_init(cache, orig, &use_opts); + int res = stream_cache_init(cache, fcache, &use_opts); if (res <= 0) { cache->uncached_stream = NULL; // don't free original stream free_stream(cache); + if (fcache != orig) + free_stream(fcache); } else { *stream = cache; } |