mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
demux: cache STREAM_CTRL_GET_BASE_FILENAME
It's needed for some obscure feature in combination with .rar reading. However, it's unconditionally used by the subtitle loader code, so take care of not blocking the main thread unnecessarily. (Untested.)
This commit is contained in:
@@ -129,6 +129,8 @@ struct demux_internal {
|
||||
int64_t stream_cache_size;
|
||||
int64_t stream_cache_fill;
|
||||
int stream_cache_idle;
|
||||
// Updated during init only.
|
||||
char *stream_base_filename;
|
||||
};
|
||||
|
||||
struct demux_stream {
|
||||
@@ -786,6 +788,16 @@ void demux_update(demuxer_t *demuxer)
|
||||
pthread_mutex_unlock(&in->lock);
|
||||
}
|
||||
|
||||
static void demux_init_cache(struct demuxer *demuxer)
|
||||
{
|
||||
struct demux_internal *in = demuxer->in;
|
||||
struct stream *stream = demuxer->stream;
|
||||
|
||||
char *base = NULL;
|
||||
stream_control(stream, STREAM_CTRL_GET_BASE_FILENAME, &base);
|
||||
in->stream_base_filename = talloc_steal(demuxer, base);
|
||||
}
|
||||
|
||||
static struct demuxer *open_given_type(struct mpv_global *global,
|
||||
struct mp_log *log,
|
||||
const struct demuxer_desc *desc,
|
||||
@@ -855,6 +867,7 @@ static struct demuxer *open_given_type(struct mpv_global *global,
|
||||
mp_warn(log, "Enabling seeking because stream cache is active.\n");
|
||||
in->d_thread->seekable = true;
|
||||
}
|
||||
demux_init_cache(demuxer);
|
||||
demux_changed(in->d_thread, DEMUX_EVENT_ALL);
|
||||
demux_update(demuxer);
|
||||
return demuxer;
|
||||
@@ -1146,6 +1159,11 @@ static int cached_stream_control(struct demux_internal *in, int cmd, void *arg)
|
||||
return STREAM_UNSUPPORTED;
|
||||
*(int64_t *)arg = in->stream_size;
|
||||
return STREAM_OK;
|
||||
case STREAM_CTRL_GET_BASE_FILENAME:
|
||||
if (!in->stream_base_filename)
|
||||
return STREAM_UNSUPPORTED;
|
||||
*(char **)arg = talloc_strdup(NULL, in->stream_base_filename);
|
||||
return STREAM_OK;
|
||||
}
|
||||
return STREAM_ERROR;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user