mirror of
https://github.com/mpv-player/mpv
synced 2025-04-01 23:00:41 +00:00
cache_file: add a mode that creates a temporary file
Since we have to be portable, our options for creating temporary files are somewhat limited. tmpfile() happens to be available everywhere, so use that. This function doesn't allow having a "visible" filename or location, so we use the magic string "TMP" for this.
This commit is contained in:
parent
829fdef219
commit
c80adac077
@ -2767,10 +2767,14 @@ Cache
|
||||
on the situation, either of these might be slower than the other method.
|
||||
This option allows control over this.
|
||||
|
||||
``--cache-file=<path>``
|
||||
Create a cache file on the filesystem with the given name. The file is
|
||||
always overwritten. When the general cache is enabled, this file cache
|
||||
will be used to store whatever is read from the source stream.
|
||||
``--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
|
||||
@ -2784,14 +2788,31 @@ Cache
|
||||
|
||||
Both of these issues could be improved if there is any user interest.
|
||||
|
||||
Also see ``--cache-file-size``.
|
||||
.. warning:: Causes random corruption when used with ordered chapters or
|
||||
with ``--audio-file``.
|
||||
|
||||
.. warning:: Causes random corruption when used with ordered chapters.
|
||||
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
|
||||
(like on MS Windows).
|
||||
|
||||
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.
|
||||
|
||||
Also see ``--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.)
|
||||
|
||||
``--no-cache``
|
||||
|
@ -127,7 +127,8 @@ int stream_file_cache_init(stream_t *cache, stream_t *stream,
|
||||
if (!opts->file || !opts->file[0] || opts->file_max < 1)
|
||||
return 0;
|
||||
|
||||
FILE *file = fopen(opts->file, "wb+");
|
||||
bool use_anon_file = strcmp(opts->file, "TMP") == 0;
|
||||
FILE *file = use_anon_file ? tmpfile() : fopen(opts->file, "wb+");
|
||||
if (!file) {
|
||||
MP_ERR(cache, "can't open cache file '%s'\n", opts->file);
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user