Repository navigation
add: experimental binary stream transport via Source Workers (Deezer first) - #261
Draft
1Lucas1apk wants to merge 11 commits into
Draft
1Lucas1apk wants to merge 11 commits into
1Lucas1apk wants to merge 11 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Draft / Experimental: Isolates heavy source stream fetching and decryption inside Source Workers, delivering audio back to Players over dedicated Named Pipes / Unix Domain Sockets instead of Node.js IPC.
Why
Even with URL resolution running in Source Workers, the playback process still ends up doing the heavy HTTP streaming, retries, and decryption inside the Player event loop. When multiple streams stall, reconnect, or decrypt at the same time, that I/O and crypto work fights directly with active audio playback.
The goal here is to move that heavy stream production out to the Source Worker threads without touching the
Playeraudio pipeline (decoding, filters, fading, and Opus encoding stay where they are). Deezer (src/sources/deezer.ts) is the first source wired into this transport because of its continuous HTTP streaming, aligned-boundary CDN retries, and Blowfish-CBC decryption, while theStreamTransportlayer (src/playback/streamTransport.ts) is kept generic so any other heavy source can use the same transport later.Delegation & Transport
Instead of passing chunks over IPC/JSON/Base64, each stream gets its own dedicated socket connection with end-to-end backpressure. The playback worker registers a one-time
streamIdandsecurityTokenon its localStreamTransportServer, strips non-serializable callbacks fromadditionalData, and delegatesstartStreamTransportover the Master Command Socket (src/workers/main.ts) toSourceWorkerManager, which picks the least-loaded Source Worker thread (src/workers/source.ts). That thread opens the upstream stream, connects to the Player's Named Pipe or Unix Domain Socket, validates the binary handshake, and pumps framed records in the background while pausing whenever the Player's reserve buffer hits its high watermark. On finish, stop, or native seek,cancelStreamTransporttears down the active producer in the Source Worker.Magic,Version,Type,Flags, 16BstreamId, 32BsecurityToken)crypto.timingSafeEqualType+ 4B big-endianLength)DATA,END, andERRORrecords64 KBlow /192 KBtarget /384 KBhigh (128 KBbackpressure cap)Current bottlenecks
startStreamTransportreturns{ started: true }as soon as the stream starts pumping in the background (client.run()), soSourceWorkerManager'sworkerLoadscounter drops immediately and doesn't yet account for long-livedactiveTransportswhen scheduling heavyloadTracksor playlist parsing on the same threads. On native seeks, closing the old pipe and opening a new one is fast locally, so the main latency left is the upstream CDNRangewarm-up on the new offset.