path: root/
diff options
authorwm4 <wm4@nowhere>2019-06-13 19:10:32 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:05 +0200
commit17da9071a4a524139e2ef945ed6cde17dd08c99c (patch)
tree66201f387ae33c5f6dbdb283d62066177b0cedf3 /
parentef507ad50a0933581f39a0bb86dd85fce9d8f7bc (diff)
demux: add a on-disk cache
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.
Diffstat (limited to '')
1 files changed, 1 insertions, 0 deletions
diff --git a/ b/
index 127fe820fe..51bb01fac4 100644
--- a/
+++ b/
@@ -273,6 +273,7 @@ def build(ctx):
## Demuxers
( "demux/codec_tags.c" ),
( "demux/cue.c" ),
+ ( "demux/cache.c" ),
( "demux/demux.c" ),
( "demux/demux_cue.c" ),
( "demux/demux_edl.c" ),