This document describes the current concurrency model in NX-Cast.
The threading model must ensure:
- Protocol entry points do not block directly on heavy playback work.
- Playback state has one real writer.
- Protocol, playback, and eventing boundaries stay clear.
Stable execution units:
main/ foreground render loop.SSDPthread.HTTPthread.- Player owner thread.
libmpvevent pumping through the player backend.- GENA event worker.
HTTP/SOAP thread
-> protocol handler
-> renderer/player command
-> player owner thread
-> backend/libmpv
-> PlayerEvent
-> protocol_state
-> event worker
The player owner thread is the only executor for playback control.
It is responsible for:
- Opening media.
- Playback commands.
- Backend event processing.
- Snapshot updates.
- Emitting
PlayerEvent.
This prevents SOAP threads from directly driving the backend and makes command ordering easier to reason about.
protocol_state is not a thread. It is the shared protocol-facing state surface.
It is updated from player events and read by:
- SOAP query actions.
LastChangegeneration.- Compatibility helpers.
This avoids duplicated runtime state across query and event paths.
Render-related ownership:
- The main thread owns foreground pages and render-context lifecycle.
- The backend does not own foreground UI lifecycle.
- The backend exposes narrow render attachment and frame rendering hooks.
- UI code must not call blocking playback operations from the render path.
- Prefer clear ownership over adding more threads.
- Keep one real writer for playback state.
- Do not add concurrency for hypothetical future needs.
- Keep network/protocol work separate from render-context ownership.
- Shut down in dependency order: UI/player first, protocol/server next, network and platform services last.
Threading work should focus on:
- Better shutdown sequencing.
- Better logging around cross-thread commands.
- Avoiding accidental render-thread blocking from touch or controller input.
- Keeping protocol notifications asynchronous.