Protocol 11: split-track relay (YouTube video+audio), chunked upstream reads

Relayed media can carry 2-4 byte tracks (video, audio): yt-dlp picks a
split pair when no single-file format exists (h264 first), the source
channel serves each track, the server keeps a buffer per track (budget
split by size, 8 MiB floor) and viewers open an mpv edl:// of the track
URLs. Expired URLs re-resolve once for all tracks. Upstream GETs are cut
into <= http_chunk_size (10 MiB) ranges: YouTube throttles larger ones.
Live streams and DRM are refused; HLS/DASH pieces are a follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
foxyzandClaude Opus 5.5 committed 2026-10-09 19:59:41 +03:00
1 parent b2b77a6b3f
commit b038706dff
19 files changed
+945 -286

No files matched your search

+5 -3
View File
@@ -50,7 +50,8 @@ Future<void> main(List<String> argv) async {
.toJson()));
await Future<void>.delayed(const Duration(milliseconds: 300));
final via = a['via'] as String? ?? '$port';
var source = RelaySource(Uri.parse('ws://127.0.0.1:$via/r/default/${srcW.token}/source'), FileRelayBytes(file));
var source = RelaySource(
Uri.parse('ws://127.0.0.1:$via/r/default/${srcW.token}/source'), RelayMedia.single(FileRelayBytes(file)));
await source.start();
final urls = <String>[];
for (var i = 0; i < int.parse(a['viewers'] as String); i++) {
@@ -58,14 +59,15 @@ Future<void> main(List<String> argv) async {
}
stdout.writeln('URL ${urls.join(',')}');
Timer.periodic(const Duration(seconds: 5), (_) {
final b = server.hub.relay?.buffer;
final b = server.hub.relay?.buffers.firstOrNull;
stdout.writeln('STATS sourceSent=${source.bytesSent} toViewers=${b?.bytesToViewers} '
'cached=${b?.cachedBytes} window=${source.window.window}');
});
// SIGUSR1: drop the source; SIGUSR2: bring it back (outage tests).
ProcessSignal.sigusr1.watch().listen((_) => source.close());
ProcessSignal.sigusr2.watch().listen((_) async {
source = RelaySource(Uri.parse('ws://127.0.0.1:$via/r/default/${srcW.token}/source'), FileRelayBytes(file));
source = RelaySource(
Uri.parse('ws://127.0.0.1:$via/r/default/${srcW.token}/source'), RelayMedia.single(FileRelayBytes(file)));
await source.start();
});
}