RtspDriver
Source:
RtspDriver.h
SendCtx¶
src/light/drivers/RtspDriver.h:304What one datagram needs to reach the viewer, handed to the packetiser's sink.
Public Attributes¶
platform::UdpSocket * sock
const uint8_t * ip
uint16_t port
uint32_t * sent
RtspDriver¶
src/light/drivers/RtspDriver.h:43Inherits:
DriverBase
Output driver: serves the rendered frame as an H.264 stream a player pulls over RTSP, which arrives with a fraction of the delay HLS carries.
HLS ships whole segments and a player buffers several before it starts, so a viewer sees seconds ago. RTSP sends each frame as the encoder produces it, which puts a viewer far closer to live.
Prior art: RTSP is RFC 2326, its RTP payload format for H.264 is RFC 6184, and the hardware encoder is the one HLS already drives.
Public Attributes¶
uint8_t targetFps = 30
: Frames per second the encoder is asked for, which is also its GOP.
uint8_t scale = 0
: Lights per encoded block, or 0 to pick the smallest that clears the encoder's floor.
Public Methods¶
inline ~RtspDriver() override
: A destroyed driver releases the encoder, since nothing else can: a claim outliving its owner would refuse every later driver, and the next one can even land on this address.
inline RtspDriver()
: Bind the scratch buffers to this module, so their memory is accounted for.
virtual inline const char * tags() const override
: The catalog tags shown on this driver's card.
virtual inline void setSourceBuffer(Buffer * buf) override
: Point the driver at the shared source buffer.
virtual inline void defineDriverControls() override
: Bind the frame rate, the scale, and the address a player is pointed at.
virtual inline bool affectsPrepare(const char * name) const override
: Which controls need a fresh encode, the encoder fixing its rate at spawn.
virtual inline void prepare() override
: Derive the scaled geometry, start the encoder, and listen for a client.
virtual inline void release() override
: Stop the encoder, drop the session and stop listening.
virtual inline void tick() override
: The hot tick, which by default ticks every enabled child and times each.
Public Static Attributes¶
constexpr const char * kTags = "🖥️"
: The catalog tag this driver carries.
More info¶
One encoder, one driver at a time¶
HLS muxes the encoder's output into segments where this packetises the same NALs into RTP, so the two read the same shape of frame. They cannot run together: there is one encoder instance, and a second encoderStart would silently reconfigure the first driver's stream. So the encoder is claimed, and whichever driver starts second reports that it is in use. Sharing one encode between both readers is the better end state, filed in the backlog. It needs the two drivers to agree on geometry, rate and bitrate, which nothing makes them do today.
The newest viewer is the viewer¶
Each viewer costs another send on a device that is also driving lights, so one session plays at a time and a new connection takes it over. A player that vanishes without TEARDOWN leaves a socket open and silent, since TCP reports a peer's absence only to a write it stops acknowledging. Waiting on that would strand the stream for minutes, so someone asking to watch now outranks an old socket's silence. The displaced viewer sees its connection close, which every player reports.
Where it runs¶
The encoder is the P4's in hardware and the desktop's ffmpeg, so hasRtsp is true on both. Every other board reaches viewers through the preview driver, which sends raw pixels and no codec.
