mirror of
https://github.com/mpv-player/mpv
synced 2024-12-27 17:42:17 +00:00
17da9071a4
Somewhat similar to the old --cache-file, except for the demuxer cache. Instead of keeping packet data in memory, it's written to disk and read back when needed. The idea is to reduce main memory usage, while allowing fast seeking in large cached network streams (especially live streams). Keeping the packet metadata on disk would be rather hard (would use mmap or so, or rewrite the entire demux.c packet queue handling), and since it's relatively small, just keep it in memory. Also for simplicity, the disk cache is append-only. If you're watching really long livestreams, and need pruning, you're probably out of luck. This still could be improved by trying to free unused blocks with fallocate(), but since we're writing multiple streams in an interleaved manner, this is slightly hard. Some rather gross ugliness in packet.h: we want to store the file position of the cached data somewhere, but on 32 bit architectures, we don't have any usable 64 bit members for this, just the buf/len fields, which add up to 64 bit - so the shitty union aliases this memory. Error paths untested. Side data (the complicated part of trying to serialize ffmpeg packets) untested. Stream recording had to be adjusted. Some minor details change due to this, but probably nothing important. The change in attempt_range_joining() is because packets in cache have no valid len field. It was a useful check (heuristically finding broken cases), but not a necessary one. Various other approaches were tried. It would be interesting to list them and to mention the pros and cons, but I don't feel like it.
17 lines
457 B
C
17 lines
457 B
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
struct demux_packet;
|
|
struct mp_log;
|
|
struct mpv_global;
|
|
|
|
struct demux_cache;
|
|
|
|
struct demux_cache *demux_cache_create(struct mpv_global *global,
|
|
struct mp_log *log);
|
|
|
|
int64_t demux_cache_write(struct demux_cache *cache, struct demux_packet *pkt);
|
|
struct demux_packet *demux_cache_read(struct demux_cache *cache, uint64_t pos);
|
|
uint64_t demux_cache_get_size(struct demux_cache *cache);
|