diff options
-rw-r--r-- | DOCS/man/input.rst | 32 | ||||
-rw-r--r-- | DOCS/man/options.rst | 100 | ||||
-rw-r--r-- | demux/demux.c | 54 | ||||
-rw-r--r-- | demux/demux.h | 3 | ||||
-rw-r--r-- | demux/demux_disc.c | 7 | ||||
-rw-r--r-- | demux/demux_mkv_timeline.c | 10 | ||||
-rw-r--r-- | options/options.c | 3 | ||||
-rw-r--r-- | options/options.h | 12 | ||||
-rw-r--r-- | player/command.c | 134 | ||||
-rw-r--r-- | player/core.h | 2 | ||||
-rw-r--r-- | player/loadfile.c | 1 | ||||
-rw-r--r-- | player/misc.c | 18 | ||||
-rw-r--r-- | player/osd.c | 32 | ||||
-rw-r--r-- | player/playloop.c | 7 | ||||
-rw-r--r-- | stream/cache.c | 809 | ||||
-rw-r--r-- | stream/cache_file.c | 158 | ||||
-rw-r--r-- | stream/stream.c | 97 | ||||
-rw-r--r-- | stream/stream.h | 27 | ||||
-rw-r--r-- | stream/stream_avdevice.c | 1 | ||||
-rw-r--r-- | stream/stream_dvb.c | 1 | ||||
-rw-r--r-- | stream/stream_dvdnav.c | 1 | ||||
-rw-r--r-- | stream/stream_edl.c | 1 | ||||
-rw-r--r-- | stream/stream_file.c | 1 | ||||
-rw-r--r-- | stream/stream_memory.c | 1 | ||||
-rw-r--r-- | stream/stream_mf.c | 1 | ||||
-rw-r--r-- | stream/stream_tv.c | 1 | ||||
-rw-r--r-- | wscript_build.py | 2 |
27 files changed, 49 insertions, 1467 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index b577b688d0..5413ad79be 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -1455,38 +1455,6 @@ Property list playing at all. In other words, it's only ``no`` if there's actually video playing. (Behavior since mpv 0.7.0.) -``cache`` - Network cache fill state (0-100.0). - -``cache-size`` (RW) - Network cache size in KB. This is similar to ``--cache``. This allows - setting the cache size at runtime. Currently, it's not possible to enable - or disable the cache at runtime using this property, just to resize an - existing cache. - - This does not include the backbuffer size (changed after mpv 0.10.0). - - Note that this tries to keep the cache contents as far as possible. To make - this easier, the cache resizing code will allocate the new cache while the - old cache is still allocated. - - Don't use this when playing DVD or Blu-ray. - -``cache-free`` (R) - Total free cache size in KB. - -``cache-used`` (R) - Total used cache size in KB. - -``cache-speed`` (R) - Current I/O read speed between the cache and the lower layer (like network). - This gives the number bytes per seconds over a 1 second window (using - the type ``MPV_FORMAT_INT64`` for the client API). - -``cache-idle`` (R) - Returns ``yes`` if the cache is idle, which means the cache is filled as - much as possible, and is currently not reading more data. - ``demuxer-cache-duration`` Approximate duration of video buffered in the demuxer, in seconds. The guess is very unreliable, and often the property will not be available diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 9c66ca35cb..c8e75556c0 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3836,97 +3836,15 @@ TV Cache ----- -``--cache=<kBytes|yes|no|auto>`` - Set the size of the cache in kilobytes, disable it with ``no``, or - automatically enable it if needed with ``auto`` (default: ``auto``). - With ``auto``, the cache will usually be enabled for network streams, - using the size set by ``--cache-default``. With ``yes``, the cache will - always be enabled with the size set by ``--cache-default`` (unless the - stream cannot be cached, or ``--cache-default`` disables caching). - - May be useful when playing files from slow media, but can also have - negative effects, especially with file formats that require a lot of - seeking, such as MP4. - - Note that half the cache size will be used to allow fast seeking back. This - is also the reason why a full cache is usually not reported as 100% full. - The cache fill display does not include the part of the cache reserved for - seeking back. The actual maximum percentage will usually be the ratio - between readahead and backbuffer sizes. - -``--cache-default=<kBytes|no>`` - Set the size of the cache in kilobytes (default: 10000 KB). Using ``no`` - will not automatically enable the cache e.g. when playing from a network - stream. Note that using ``--cache`` will always override this option. - -``--cache-initial=<kBytes>`` - Playback will start when the cache has been filled up with this many - kilobytes of data (default: 0). - -``--cache-seek-min=<kBytes>`` - If a seek is to be made to a position within ``<kBytes>`` of the cache - size from the current position, mpv will wait for the cache to be - filled to this position rather than performing a stream seek (default: - 500). - - This matters for small forward seeks. With slow streams (especially HTTP - streams) there is a tradeoff between skipping the data between current - position and seek destination, or performing an actual seek. Depending - on the situation, either of these might be slower than the other method. - This option allows control over this. - -``--cache-backbuffer=<kBytes>`` - Size of the cache back buffer (default: 10000 KB). This will add to the total - cache size, and reserved the amount for seeking back. The reserved amount - will not be used for readahead, and instead preserves already read data to - enable fast seeking back. - -``--cache-file=<TMP|path>`` - Create a cache file on the filesystem. - - There are two ways of using this: - - 1. Passing a path (a filename). The file will always be overwritten. When - the general cache is enabled, this file cache will be used to store - whatever is read from the source stream. - - This will always overwrite the cache file, and you can't use an existing - cache file to resume playback of a stream. (Technically, mpv wouldn't - even know which blocks in the file are valid and which not.) - - The resulting file will not necessarily contain all data of the source - stream. For example, if you seek, the parts that were skipped over are - never read and consequently are not written to the cache. The skipped over - parts are filled with zeros. This means that the cache file doesn't - necessarily correspond to a full download of the source stream. - - Both of these issues could be improved if there is any user interest. - - .. warning:: Causes random corruption when used with ordered chapters or - with ``--audio-file``. - - 2. Passing the string ``TMP``. This will not be interpreted as filename. - Instead, an invisible temporary file is created. It depends on your - C library where this file is created (usually ``/tmp/``), and whether - filename is visible (the ``tmpfile()`` function is used). On some - systems, automatic deletion of the cache file might not be guaranteed. - - If you want to use a file cache, this mode is recommended, because it - doesn't break ordered chapters or ``--audio-file``. These modes open - multiple cache streams, and using the same file for them obviously - clashes. - - See also: ``--cache-file-size``. - -``--cache-file-size=<kBytes>`` - Maximum size of the file created with ``--cache-file``. For read accesses - above this size, the cache is simply not used. - - Keep in mind that some use-cases, like playing ordered chapters with cache - enabled, will actually create multiple cache files, each of which will - use up to this much disk space. - - (Default: 1048576, 1 GB.) +``--cache=<yes|no|auto>`` + Decide whether to use network cache settings (default: auto). + + If enabled, use the maximum of ``--cache-secs`` and ``--demuxer-max-bytes`` + for the cache size. If disabled, ``--cache-pause`` and related are + implicitly disabled. + + The ``auto`` choice sets this depending on whether the stream is thought to + involve network accesses (this is an imperfect heuristic). ``--no-cache`` Turn off input stream caching. See ``--cache``. diff --git a/demux/demux.c b/demux/demux.c index 3e9d897bb2..45f472cfc9 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -86,6 +86,7 @@ const demuxer_desc_t *const demuxer_list[] = { }; struct demux_opts { + int enable_cache; int64_t max_bytes; int64_t max_bytes_bw; double min_secs; @@ -102,6 +103,8 @@ struct demux_opts { const struct m_sub_options demux_conf = { .opts = (const struct m_option[]){ + OPT_CHOICE("cache", enable_cache, 0, + ({"no", 0}, {"auto", -1}, {"yes", 1})), OPT_DOUBLE("demuxer-readahead-secs", min_secs, M_OPT_MIN, .min = 0), // (The MAX_BYTES sizes may not be accurate because the max field is // of double type.) @@ -117,6 +120,7 @@ const struct m_sub_options demux_conf = { }, .size = sizeof(struct demux_opts), .defaults = &(const struct demux_opts){ + .enable_cache = -1, // auto .max_bytes = 150 * 1024 * 1024, .max_bytes_bw = 50 * 1024 * 1024, .min_secs = 1.0, @@ -129,6 +133,8 @@ const struct m_sub_options demux_conf = { struct demux_internal { struct mp_log *log; + struct demux_opts *opts; + // The demuxer runs potentially in another thread, so we keep two demuxer // structs; the real demuxer can access the shadow struct only. struct demuxer *d_thread; // accessed by demuxer impl. (producer) @@ -215,8 +221,6 @@ struct demux_internal { // Transient state. double duration; // Cached state. - bool force_cache_update; - struct stream_cache_info stream_cache_info; int64_t stream_size; // Updated during init only. char *stream_base_filename; @@ -1695,9 +1699,6 @@ static void execute_trackswitch(struct demux_internal *in) if (in->d_thread->desc->control) in->d_thread->desc->control(in->d_thread, DEMUXER_CTRL_SWITCHED_TRACKS, 0); - stream_control(in->d_thread->stream, STREAM_CTRL_SET_READAHEAD, - &(int){any_selected}); - pthread_mutex_lock(&in->lock); } @@ -1746,13 +1747,6 @@ static bool thread_work(struct demux_internal *in) if (read_packet(in)) return true; // read_packet unlocked, so recheck conditions } - if (in->force_cache_update) { - pthread_mutex_unlock(&in->lock); - update_cache(in); - pthread_mutex_lock(&in->lock); - in->force_cache_update = false; - return true; - } return false; } @@ -2276,6 +2270,19 @@ static void fixup_metadata(struct demux_internal *in) } } +// Return whether "heavy" caching on this stream is enabled. By default, this +// corresponds to whether the source stream is considered in the network. The +// only effect should be adjusting display behavior (of cache stats etc.), and +// possibly switching between which set of options influence cache settings. +bool demux_is_network_cached(demuxer_t *demuxer) +{ + struct demux_internal *in = demuxer->in; + bool use_cache = demuxer->is_network; + if (in->opts->enable_cache >= 0) + use_cache = in->opts->enable_cache == 1; + return use_cache; +} + static struct demuxer *open_given_type(struct mpv_global *global, struct mp_log *log, const struct demuxer_desc *desc, @@ -2305,12 +2312,11 @@ static struct demuxer *open_given_type(struct mpv_global *global, .extended_ctrls = stream->extended_ctrls, }; demuxer->seekable = stream->seekable; - if (demuxer->stream->underlying && !demuxer->stream->underlying->seekable) - demuxer->seekable = false; struct demux_internal *in = demuxer->in = talloc_ptrtype(demuxer, in); *in = (struct demux_internal){ .log = demuxer->log, + .opts = opts, .d_thread = talloc(demuxer, struct demuxer), .d_user = demuxer, .min_secs = opts->min_secs, @@ -2371,10 +2377,8 @@ static struct demuxer *open_given_type(struct mpv_global *global, fixup_metadata(in); in->events = DEMUX_EVENT_ALL; demux_update(demuxer); - stream_control(demuxer->stream, STREAM_CTRL_SET_READAHEAD, - &(int){params ? params->initial_readahead : false}); int seekable = opts->seekable_cache; - if (demuxer->is_network || stream->caching) { + if (demux_is_network_cached(demuxer)) { in->min_secs = MPMAX(in->min_secs, opts->min_secs_cache); if (seekable < 0) seekable = 1; @@ -2486,8 +2490,6 @@ struct demuxer *demux_open_url(const char *url, talloc_free(priv_cancel); return NULL; } - if (!params->disable_cache) - stream_enable_cache_defaults(&s); struct demuxer *d = demux_open(s, params, global); if (d) { talloc_steal(d->in, priv_cancel); @@ -3042,15 +3044,12 @@ static void update_cache(struct demux_internal *in) // Don't lock while querying the stream. struct mp_tags *stream_metadata = NULL; - struct stream_cache_info stream_cache_info = {.size = -1}; int64_t stream_size = stream_get_size(stream); stream_control(stream, STREAM_CTRL_GET_METADATA, &stream_metadata); - stream_control(stream, STREAM_CTRL_GET_CACHE_INFO, &stream_cache_info); pthread_mutex_lock(&in->lock); in->stream_size = stream_size; - in->stream_cache_info = stream_cache_info; if (stream_metadata) { for (int n = 0; n < in->num_streams; n++) { struct demux_stream *ds = in->streams[n]->ds; @@ -3065,18 +3064,7 @@ static void update_cache(struct demux_internal *in) // must be called locked static int cached_stream_control(struct demux_internal *in, int cmd, void *arg) { - // If the cache is active, wake up the thread to possibly update cache state. - if (in->stream_cache_info.size >= 0) { - in->force_cache_update = true; - pthread_cond_signal(&in->wakeup); - } - switch (cmd) { - case STREAM_CTRL_GET_CACHE_INFO: - if (in->stream_cache_info.size < 0) - return STREAM_UNSUPPORTED; - *(struct stream_cache_info *)arg = in->stream_cache_info; - return STREAM_OK; case STREAM_CTRL_GET_SIZE: if (in->stream_size < 0) return STREAM_UNSUPPORTED; diff --git a/demux/demux.h b/demux/demux.h index 7d2924000a..5b92e97f49 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -174,13 +174,11 @@ struct demuxer_params { bool *matroska_was_valid; struct timeline *timeline; bool disable_timeline; - bool initial_readahead; bstr init_fragment; bool skip_lavf_probing; bool does_not_own_stream; // if false, stream is free'd on demux_free() // -- demux_open_url() only int stream_flags; - bool disable_cache; // result bool demuxer_failed; }; @@ -317,6 +315,7 @@ void demux_metadata_changed(demuxer_t *demuxer); void demux_update(demuxer_t *demuxer); void demux_disable_cache(demuxer_t *demuxer); +bool demux_is_network_cached(demuxer_t *demuxer); struct sh_stream *demuxer_stream_by_demuxer_id(struct demuxer *d, enum stream_type t, int id); diff --git a/demux/demux_disc.c b/demux/demux_disc.c index 15ccb2313d..e5c63cea17 100644 --- a/demux/demux_disc.c +++ b/demux/demux_disc.c @@ -292,11 +292,8 @@ static int d_open(demuxer_t *demuxer, enum demux_check check) struct stream *cur = demuxer->stream; const char *sname = ""; - while (cur) { - if (cur->info) - sname = cur->info->name; - cur = cur->underlying; // down the caching chain - } + if (cur->info) + sname = cur->info->name; p->is_cdda = strcmp(sname, "cdda") == 0; p->is_dvd = strcmp(sname, "dvd") == 0 || diff --git a/demux/demux_mkv_timeline.c b/demux/demux_mkv_timeline.c index 32eab2ca8f..69cf26e681 100644 --- a/demux/demux_mkv_timeline.c +++ b/demux/demux_mkv_timeline.c @@ -172,7 +172,6 @@ static bool check_file_seg(struct tl_ctx *ctx, char *filename, int segment) .matroska_wanted_segment = segment, .matroska_was_valid = &was_valid, .disable_timeline = true, - .disable_cache = true, }; struct mp_cancel *cancel = ctx->tl->cancel; if (mp_cancel_test(cancel)) @@ -216,15 +215,6 @@ static bool check_file_seg(struct tl_ctx *ctx, char *filename, int segment) } } - if (stream_wants_cache(d->stream, ctx->opts->stream_cache)) { - demux_free(d); - params.disable_cache = false; - params.matroska_wanted_uids = ctx->uids; // potentially reallocated, same data - d = demux_open_url(filename, ¶ms, cancel, ctx->global); - if (!d) - return false; - } - ctx->sources[i] = d; return true; } diff --git a/options/options.c b/options/options.c index 5a77e9973d..2548759ddb 100644 --- a/options/options.c +++ b/options/options.c @@ -59,7 +59,6 @@ extern const struct m_sub_options tv_params_conf; extern const struct m_sub_options stream_cdda_conf; extern const struct m_sub_options stream_dvb_conf; extern const struct m_sub_options stream_lavf_conf; -extern const struct m_sub_options stream_cache_conf; extern const struct m_sub_options sws_conf; extern const struct m_sub_options drm_conf; extern const struct m_sub_options demux_rawaudio_conf; @@ -387,8 +386,6 @@ const m_option_t mp_opts[] = { // ------------------------- stream options -------------------- - OPT_SUBSTRUCT("", stream_cache, stream_cache_conf, 0), - #if HAVE_DVDREAD || HAVE_DVDNAV OPT_SUBSTRUCT("", dvd_opts, dvd_conf, 0), #endif /* HAVE_DVDREAD */ diff --git a/options/options.h b/options/options.h index 0eb5451794..a6532b4458 100644 --- a/options/options.h +++ b/options/options.h @@ -59,16 +59,6 @@ typedef struct mp_vo_opts { struct drm_opts *drm_opts; } mp_vo_opts; -struct mp_cache_opts { - int size; - int def_size; - int initial; - int seek_min; - int back_buffer; - char *file; - int file_max; -}; - // Subtitle options needed by the subtitle decoders/renderers. struct mp_subtitle_opts { int sub_visibility; @@ -204,7 +194,6 @@ typedef struct MPOpts { char *force_configdir; int use_filedir_conf; int hls_bitrate; - struct mp_cache_opts *stream_cache; int chapterrange[2]; int edition_id; int correct_pts; @@ -358,7 +347,6 @@ struct filter_opts { extern const m_option_t mp_opts[]; extern const struct MPOpts mp_default_opts; extern const struct m_sub_options vo_sub_opts; -extern const struct m_sub_options stream_cache_conf; extern const struct m_sub_options dvd_conf; extern const struct m_sub_options mp_subtitle_sub_opts; extern const struct m_sub_options mp_osd_render_sub_opts; diff --git a/player/command.c b/player/command.c index f556e7211d..ab9a09fcac 100644 --- a/player/command.c +++ b/player/command.c @@ -1559,134 +1559,6 @@ static int mp_property_playback_abort(void *ctx, struct m_property *prop, return m_property_flag_ro(action, arg, !mpctx->playing || mpctx->stop_play); } -static int mp_property_cache(void *ctx, struct m_property *prop, - int action, void *arg) -{ - MPContext *mpctx = ctx; - float cache = mp_get_cache_percent(mpctx); - if (cache < 0) - return M_PROPERTY_UNAVAILABLE; - - if (action == M_PROPERTY_PRINT) { - *(char **)arg = talloc_asprintf(NULL, "%d", (int)cache); - return M_PROPERTY_OK; - } - - return m_property_float_ro(action, arg, cache); -} - -static int property_int_kb_size(int kb_size, int action, void *arg) -{ - switch (action) { - case M_PROPERTY_GET: - *(int *)arg = kb_size; - return M_PROPERTY_OK; - case M_PROPERTY_PRINT: - *(char **)arg = format_file_size(kb_size * 1024LL); - return M_PROPERTY_OK; - case M_PROPERTY_GET_TYPE: - *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_INT}; - return M_PROPERTY_OK; - } - return M_PROPERTY_NOT_IMPLEMENTED; -} - -static int mp_property_cache_size(void *ctx, struct m_property *prop, - int action, void *arg) -{ - MPContext *mpctx = ctx; - struct demuxer *demuxer = mpctx->demuxer; - if (!demuxer) - return M_PROPERTY_UNAVAILABLE; - switch (action) { - case M_PROPERTY_GET: - case M_PROPERTY_PRINT: { - struct stream_cache_info info = {0}; - demux_stream_control(demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); - if (info.size <= 0) - break; - return property_int_kb_size(info.size / 1024, action, arg); - } - case M_PROPERTY_GET_TYPE: - *(struct m_option *)arg = (struct m_option){ - .type = CONF_TYPE_INT, - .flags = M_OPT_MIN, - .min = 0, - }; - return M_PROPERTY_OK; - case M_PROPERTY_SET: { - int64_t size = *(int *)arg * 1024LL; - int r = demux_stream_control(demuxer, STREAM_CTRL_SET_CACHE_SIZE, &size); - if (r == STREAM_UNSUPPORTED) - break; - if (r == STREAM_OK) - return M_PROPERTY_OK; - return M_PROPERTY_ERROR; - } - } - return M_PROPERTY_NOT_IMPLEMENTED; -} - -static int mp_property_cache_used(void *ctx, struct m_property *prop, - int action, void *arg) -{ - MPContext *mpctx = ctx; - if (!mpctx->demuxer) - return M_PROPERTY_UNAVAILABLE; - - struct stream_cache_info info = {0}; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); - if (info.size <= 0) - return M_PROPERTY_UNAVAILABLE; - return property_int_kb_size(info.fill / 1024, action, arg); -} - -static int mp_property_cache_free(void *ctx, struct m_property *prop, - int action, void *arg) -{ - MPContext *mpctx = ctx; - if (!mpctx->demuxer) - return M_PROPERTY_UNAVAILABLE; - - struct stream_cache_info info = {0}; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); - if (info.size <= 0) - return M_PROPERTY_UNAVAILABLE; - - return property_int_kb_size((info.size - info.fill) / 1024, action, arg); -} - -static int mp_property_cache_speed(void *ctx, struct m_property *prop, - int action, void *arg) -{ - MPContext *mpctx = ctx; - if (!mpctx->demuxer) - return M_PROPERTY_UNAVAILABLE; - - struct stream_cache_info info = {0}; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); - if (info.size <= 0) - return M_PROPERTY_UNAVAILABLE; - - if (action == M_PROPERTY_PRINT) { - *(char **)arg = talloc_strdup_append(format_file_size(info.speed), "/s"); - return M_PROPERTY_OK; - } - return m_property_int64_ro(action, arg, info.speed); -} - -static int mp_property_cache_idle(void *ctx, struct m_property *prop, - int action, void *arg) -{ - MPContext *mpctx = ctx; - struct stream_cache_info info = {0}; - if (mpctx->demuxer) - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); - if (info.size <= 0) - return M_PROPERTY_UNAVAILABLE; - return m_property_flag_ro(action, arg, info.idle); -} - static int mp_property_demuxer_cache_duration(void *ctx, struct m_property *prop, int action, void *arg) { @@ -3897,12 +3769,6 @@ static const struct m_property mp_properties_base[] = { {"eof-reached", mp_property_eof_reached}, {"seeking", mp_property_seeking}, {"playback-abort", mp_property_playback_abort}, - {"cache-percent", mp_property_cache}, - {"cache-free", mp_property_cache_free}, - {"cache-used", mp_property_cache_used}, - {"cache-size", mp_property_cache_size}, - {"cache-idle", mp_property_cache_idle}, - {"cache-speed", mp_property_cache_speed}, {"demuxer-cache-duration", mp_property_demuxer_cache_duration}, {"demuxer-cache-time", mp_property_demuxer_cache_time}, {"demuxer-cache-idle", mp_property_demuxer_cache_idle}, diff --git a/player/core.h b/player/core.h index 193537652b..7fab8776d7 100644 --- a/player/core.h +++ b/player/core.h @@ -554,8 +554,6 @@ double get_play_end_pts(struct MPContext *mpctx); double get_play_start_pts(struct MPContext *mpctx); double get_ab_loop_start_time(struct MPContext *mpctx); void merge_playlist_files(struct playlist *pl); -float mp_get_cache_percent(struct MPContext *mpctx); -bool mp_get_cache_idle(struct MPContext *mpctx); void update_vo_playback_state(struct MPContext *mpctx); void update_window_title(struct MPContext *mpctx, bool force); void error_on_track(struct MPContext *mpctx, struct track *track); diff --git a/player/loadfile.c b/player/loadfile.c index d854ab04a9..2fb69eb635 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -971,7 +971,6 @@ static void *open_demux_thread(void *ctx) struct demuxer_params p = { .force_format = mpctx->open_format, .stream_flags = mpctx->open_url_flags, - .initial_readahead = true, }; mpctx->open_res_demuxer = demux_open_url(mpctx->open_url, &p, mpctx->open_cancel, mpctx->global); diff --git a/player/misc.c b/player/misc.c index f2e6f05173..ce353b9590 100644 --- a/player/misc.c +++ b/player/misc.c @@ -203,24 +203,6 @@ void issue_refresh_seek(struct MPContext *mpctx, enum seek_precision min_prec) queue_seek(mpctx, MPSEEK_ABSOLUTE, get_current_time(mpctx), min_prec, 0); } -float mp_get_cache_percent(struct MPContext *mpctx) -{ - struct stream_cache_info info = {0}; - if (mpctx->demuxer) - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); - if (info.size > 0 && info.fill >= 0) - return info.fill / (info.size / 100.0); - return -1; -} - -bool mp_get_cache_idle(struct MPContext *mpctx) -{ - struct stream_cache_info info = {0}; - if (mpctx->demuxer) - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); - return info.idle; -} - void update_vo_playback_state(struct MPContext *mpctx) { if (mpctx->video_out && mpctx->video_out->config_ok) { diff --git a/player/osd.c b/player/osd.c index 9faf6eb6a5..7d24c01619 100644 --- a/player/osd.c +++ b/player/osd.c @@ -229,27 +229,23 @@ static char *get_term_status_msg(struct MPContext *mpctx) } } - if (mpctx->demuxer) { - struct stream_cache_info info = {0}; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); - if (info.size > 0 || mpctx->demuxer->is_network) { - saddf(&line, " Cache: "); + if (mpctx->demuxer && demux_is_network_cached(mpctx->demuxer)) { + saddf(&line, " Cache: "); - struct demux_ctrl_reader_state s = {.ts_duration = -1}; - demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s); + struct demux_ctrl_reader_state s = {.ts_duration = -1}; + demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s); - if (s.ts_duration < 0) { - saddf(&line, "???"); + if (s.ts_duration < 0) { + saddf(&line, "???"); + } else { + saddf(&line, "%2ds", (int)s.ts_duration); + } + int64_t cache_size = s.fw_bytes; + if (cache_size > 0) { + if (cache_size >= 1024 * 1024) { + saddf(&line, "+%lldMB", (long long)(cache_size / 1024 / 1024)); } else { - saddf(&line, "%2ds", (int)s.ts_duration); - } - int64_t cache_size = s.fw_bytes + info.fill; - if (cache_size > 0) { - if (cache_size >= 1024 * 1024) { - saddf(&line, "+%lldMB", (long long)(cache_size / 1024 / 1024)); - } else { - saddf(&line, "+%lldKB", (long long)(cache_size / 1024)); - } + saddf(&line, "+%lldKB", (long long)(cache_size / 1024)); } } } diff --git a/player/playloop.c b/player/playloop.c index fa1cc544cb..59e3211df9 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -627,14 +627,11 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx) double now = mp_time_sec(); - struct stream_cache_info c = {.idle = true}; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &c); - struct demux_ctrl_reader_state s = {.idle = true, .ts_duration = -1}; demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s); int cache_buffer = 100; - bool use_pause_on_low_cache = (c.size > 0 || mpctx->demuxer->is_network) && + bool use_pause_on_low_cache = demux_is_network_cached(mpctx->demuxer) && opts->cache_pause; if (!mpctx->restart_complete) { @@ -669,7 +666,7 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx) } // Also update cache properties. - bool busy = !s.idle || !c.idle; + bool busy = !s.idle; |