feat(stream): bitrate-sized readahead for play-while-download
The torrent reader used a static 5 MiB readahead — about 1.9s of a 20 Mbps 4K stream — so streaming a torrent while it downloaded outran the download and stalled. anacrolix's reader already prioritises the pieces in the readahead window ahead of the playhead (and re-prioritises on seek); the window was just too small. dynamicReadahead sizes it to ~30s of video (clamped 8-96 MiB, 24 MiB default when bitrate is unknown). The torrent provider probes the bitrate asynchronously so stream start never blocks on ffprobe; readers created after the probe resolves pick up the accurate size. Real 4K (20.7 Mbps) -> 73 MiB.
This commit is contained in:
parent
e4373454ba
commit
9c995fc4dd
6 changed files with 110 additions and 6 deletions
|
|
@ -642,7 +642,10 @@ func (d *TorrentDownloader) GetStreamProvider(taskID string) (FileProvider, erro
|
|||
return nil, fmt.Errorf("torrent has no files")
|
||||
}
|
||||
|
||||
return NewTorrentFileProvider(video), nil
|
||||
// The provider probes the bitrate asynchronously (to size the streaming
|
||||
// readahead) — passing DataDir lets it locate the on-disk file without
|
||||
// blocking stream start.
|
||||
return NewTorrentFileProvider(video, d.cfg.DataDir), nil
|
||||
}
|
||||
|
||||
// VideoExts is the canonical set of video file extensions used for file selection.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue