mirror of
https://github.com/mpv-player/mpv
synced 2024-12-18 21:06:00 +00:00
stream: better method signal caching, rename weird uncached_stream field
"uncached_stream" is a pretty bad name. It could be mistaken for a boolean, and then its meaning would be inverted. Rename it. Also add a "caching" field, which signals that the stream is a cache or reads from a cache. This is easier to understand and more flexible.
This commit is contained in:
parent
d11c03faee
commit
e13a62fc34
@ -1246,8 +1246,7 @@ static struct demuxer *open_given_type(struct mpv_global *global,
|
||||
.events = DEMUX_EVENT_ALL,
|
||||
};
|
||||
demuxer->seekable = stream->seekable;
|
||||
if (demuxer->stream->uncached_stream &&
|
||||
!demuxer->stream->uncached_stream->seekable)
|
||||
if (demuxer->stream->underlying && !demuxer->stream->underlying->seekable)
|
||||
demuxer->seekable = false;
|
||||
|
||||
struct demux_internal *in = demuxer->in = talloc_ptrtype(demuxer, in);
|
||||
@ -1264,7 +1263,7 @@ static struct demuxer *open_given_type(struct mpv_global *global,
|
||||
pthread_mutex_init(&in->lock, NULL);
|
||||
pthread_cond_init(&in->wakeup, NULL);
|
||||
|
||||
if (stream->uncached_stream)
|
||||
if (stream->caching)
|
||||
in->min_secs = MPMAX(in->min_secs, opts->min_secs_cache);
|
||||
|
||||
*in->d_thread = *demuxer;
|
||||
|
@ -328,7 +328,7 @@ stream_t *open_output_stream(const char *filename, struct mpv_global *global)
|
||||
|
||||
static bool stream_reconnect(stream_t *s)
|
||||
{
|
||||
if (!s->streaming || s->uncached_stream || !s->seekable || !s->cancel)
|
||||
if (!s->streaming || s->caching || !s->seekable || !s->cancel)
|
||||
return false;
|
||||
|
||||
int64_t pos = s->pos;
|
||||
@ -616,7 +616,7 @@ void free_stream(stream_t *s)
|
||||
|
||||
if (s->close)
|
||||
s->close(s);
|
||||
free_stream(s->uncached_stream);
|
||||
free_stream(s->underlying);
|
||||
talloc_free(s);
|
||||
}
|
||||
|
||||
@ -636,7 +636,8 @@ static stream_t *open_cache(stream_t *orig, const char *name)
|
||||
{
|
||||
stream_t *cache = new_stream();
|
||||
cache->uncached_type = orig->uncached_type;
|
||||
cache->uncached_stream = orig;
|
||||
cache->underlying = orig;
|
||||
cache->caching = true;
|
||||
cache->seekable = true;
|
||||
cache->mode = STREAM_READ;
|
||||
cache->read_chunk = 4 * STREAM_BUFFER_SIZE;
|
||||
@ -687,7 +688,7 @@ static int stream_enable_cache(stream_t **stream, struct mp_cache_opts *opts)
|
||||
|
||||
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
|
||||
fcache->underlying = NULL; // don't free original stream
|
||||
free_stream(fcache);
|
||||
fcache = orig;
|
||||
}
|
||||
@ -696,10 +697,10 @@ static int stream_enable_cache(stream_t **stream, struct mp_cache_opts *opts)
|
||||
|
||||
int res = stream_cache_init(cache, fcache, &use_opts);
|
||||
if (res <= 0) {
|
||||
cache->uncached_stream = NULL; // don't free original stream
|
||||
cache->underlying = NULL; // don't free original stream
|
||||
free_stream(cache);
|
||||
if (fcache != orig) {
|
||||
fcache->uncached_stream = NULL;
|
||||
fcache->underlying = NULL;
|
||||
free_stream(fcache);
|
||||
}
|
||||
} else {
|
||||
|
@ -197,13 +197,14 @@ typedef struct stream {
|
||||
bool fast_skip : 1; // consider stream fast enough to fw-seek by skipping
|
||||
bool is_network : 1; // original stream_info_t.is_network flag
|
||||
bool allow_caching : 1; // stream cache makes sense
|
||||
bool caching : 1; // is a cache, or accesses a cache
|
||||
bool access_references : 1; // open other streams
|
||||
struct mp_log *log;
|
||||
struct mpv_global *global;
|
||||
|
||||
struct mp_cancel *cancel; // cancellation notification
|
||||
|
||||
struct stream *uncached_stream; // underlying stream for cache wrapper
|
||||
struct stream *underlying; // e.g. cache wrapper
|
||||
|
||||
// Includes additional padding in case sizes get rounded up by sector size.
|
||||
unsigned char buffer[];
|
||||
|
Loading…
Reference in New Issue
Block a user