Skip to content

PreviewDriver

Source: PreviewDriver.h

PreviewDriver

class PreviewDriver
src/light/drivers/PreviewDriver.h:41

Inherits: DriverBase, ClientMessageSink

Streams a true-shape 3D preview to the web UI over the binary WebSocket.

The preview is a POINT LIST, not a dense grid. Only the real lights are sent, at their real (x, y, z) positions, on MoonLight's PhysicalLayer model. Positions go out once at mapping time and channels per frame. This driver owns both wire formats, and the HTTP server is a domain-neutral broadcaster that writes the bytes.

Resolution is client-driven: the browser reads the drops counter each frame carries and posts the standing request it wants. No standing request means no work at all.

Public Attributes

uint8_t targetFps = 24 : The frame rate the preview aims for, in Hz, independent of the render rate.

Public Methods

virtual inline bool userEditable() const override : Not user-editable: deleting it from the UI would silently kill the 3D preview.

inline void setBroadcaster(BinaryBroadcaster * b) : Set the sink each message is pushed to, and register as its inbound-message sink.

virtual inline void onClientMessage(int slot, const uint8_t * payload, int len) override : Handle a client request: a standing frame request, or a one-shot table request.

virtual inline void onClientGone(int slot) override : Drop a departed client's standing request, so its slot stops being served.

inline bool keptAtStride(nrOfLightsType k, nrOfLightsType fs) const : Does this kept light survive a frame at fs? The device's own rule, on its own coordinates.

inline nrOfLightsType frameStride() const : The stride a color frame ships at: the link's pacing, never finer than the table's.

inline nrOfLightsType frameCount() const : How many lights a frame at frameStride() carries, counted the way the table is.

inline nrOfLightsType downscaleForTest() const : Test-only: the currently served downsample factor, 1 being full resolution.

virtual inline bool hasCorrectionControls() const override : Preview shows the raw logical buffer, no correction.

virtual inline void defineDriverControls() override : Bind the target frame rate, which is the ceiling the browser trades resolution toward.

virtual inline void setSourceBuffer(Buffer * buf) override : Point the driver at the same sparse buffer the other drivers read, with no copy.

virtual inline void prepare() override : Rebuild the coordinate table for the new geometry and start a fresh epoch.

virtual inline void release() override : Free the preview buffers, then release the base.

virtual inline bool affectsPrepare(const char *) const override : No control changes the transport structure, so nothing here re-runs prepare.

virtual inline void tick() override : Serve a requested table, then stream one frame if the previous one finished draining.

inline void buildCoordTable() : Build the cached coordinate table from the layout's real lights.

inline bool sendCoordTable() : Answer a table request, returning whether the send was accepted or the slot was busy.

inline bool sendAim() : Stream one aim message, so the preview can draw where each moving head points.

inline bool sendFrame() : Stream one color frame, gathered into staging in the coord table's order.

More info

The wire format

–8<– [start:wire-format]

0x03 coordinate table, sent only in answer to a client's request:
     [0x03][count:u32][bx][by][bz][stride:u16][epoch:u8][(x,y,z):u8x3 x count]
0x02 per-frame channels:
     [0x02][count:u32][stride:u16][epoch:u8][drops:u8][(r,g,b) x count]
0x04 per-frame aim, only for a rig whose fixtures carry pan and tilt:
     [0x04][count:u32][stride:u16][epoch:u8][reserved:u8][(pan,tilt):u8x2 x count]
Client requests: [0x51][stride][fps] standing, [0x52] one-shot table. The table's own stride is memory-derived, so the request carries none.
–8<– [end:wire-format]

Its own channel, and why

Preview frames are lossy and large; control-plane state is small and latency-sensitive. Sharing one WebSocket queues the small messages behind the big ones, which reads as a flickering connection indicator, so each gets its own.

PreviewDriver card