mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-08-09 01:21:06 +00:00
This adds a new protocol shared:URI which is distinct from the existing `cache:` in that it is explicity designed to be thread-safe and cross-process, enabling multiple ffmpeg processes (or multiple ffmpeg decoders within the same process) to share a single cache file, for e.g. a remote HTTP stream. As such, it uses a radically different internal design. To facilitate zero-knowledge cross-process interoperability, the cache file itself is just a memory-mapped representation of the underlying file data, which has the side benefit that the resulting cache file will contain a working copy of the streamed file (assuming the stream was read to completion). To keep track of which regions are cached and which are not, we use a secondary file that contains a minimal header along with a static bytemap of blocks within the file. This secondary file is also used to store metadata such as the filesize, if known, as well as marking "failed" blocks. Both files can grow dynamically in order to accommodate larger/growing files, and can be atomically updated (through the use of shared space maps). I have extensively checked the space map initalization and update code for race conditions, and I believe the current design to be solid. That said, it is the user's responsibility to some extent to ensure that the same URI is not used for different streams, as we rely on the URI to uniquely identify the cache files. That said, we use a cryptographic hash with sufficient collision resistance to protect against possible abuse. The lack of any implicit default on `-cache_dir` also means that `shared:` can't be enabled via URL injection to possibly access random files on the disk (or intentionally leak content from other streams with similar URIs, even if the cryptograhic hash function is broken).
4.9 KiB
4.9 KiB