Documentation Index
Fetch the complete documentation index at: https://mintlify.com/bluenviron/gortsplib/llms.txt
Use this file to discover all available pages before exploring further.
ServerStream represents a media stream on the server side. It stores the stream description, manages SSRC allocation, distributes packets to all active reader sessions, and optionally manages multicast listeners.
A ServerStream is created by the application and shared between the publisher session and all reader sessions. The publisher writes packets into the stream via WritePacketRTP / WritePacketRTCP, and the stream fans the packets out to every active reader.
Struct fields
The server instance this stream belongs to. Must be set before calling
Initialize().The session description (SDP) that describes the media contained in this stream. Must be set before calling
Initialize().Optional per-media multicast configuration. When set, the specified IP and ports are used instead of the server’s auto-assigned multicast addresses.
StreamMediaMulticastParams fields:| Field | Type | Description |
|---|---|---|
IP | net.IP | Multicast group IP |
RTPPort | int | Multicast RTP port |
RTCPPort | int | Multicast RTCP port |
Methods
Lifecycle
Lifecycle
Initialize
Server and Desc, and after the server has been started with Server.Start().Non-nil if the server is not present or not yet initialized, or if SSRC/SRTP setup fails.
Close
Close() is called, subsequent WritePacketRTP / WritePacketRTCP calls return ErrServerStreamClosed.Packet writing
Packet writing
WritePacketRTP
The media track the packet belongs to. Must be one of the medias in
Desc.The RTP packet to distribute.
ErrServerStreamClosed if the stream has been closed; otherwise a write error.WritePacketRTPWithNTP
WritePacketRTP but accepts an explicit NTP timestamp. The NTP value is included in periodic RTCP sender reports sent to readers. Use this when you have an accurate external clock source.The media track the packet belongs to.
The RTP packet to distribute.
Absolute NTP timestamp of the packet.
ErrServerStreamClosed if the stream has been closed; otherwise a write error.WritePacketRTCP
The media track the packet belongs to.
The RTCP packet to distribute.
ErrServerStreamClosed if the stream has been closed; otherwise a write error.Statistics
Statistics
Stats
ServerStreamStats fields:| Field | Type | Description |
|---|---|---|
OutboundBytes | uint64 | Total bytes written to readers |
OutboundRTPPackets | uint64 | Total RTP packets distributed |
OutboundRTCPPackets | uint64 | Total RTCP packets distributed |
Medias | map[*description.Media]ServerStreamStatsMedia | Per-media statistics |
ServerStreamStatsMedia fields:| Field | Type | Description |
|---|---|---|
OutboundBytes | uint64 | Bytes written for this media |
OutboundRTCPPackets | uint64 | RTCP packets distributed for this media |
Formats | map[format.Format]ServerStreamStatsFormat | Per-format statistics |
ServerStreamStatsFormat fields:| Field | Type | Description |
|---|---|---|
OutboundRTPPackets | uint64 | RTP packets distributed for this format |
LocalSSRC | uint32 | Locally assigned SSRC for this format |
Usage example
ServerStream is not associated with any particular publisher connection. It is the application’s responsibility to create the stream when a publisher arrives (e.g. in OnAnnounce) and close it when the publisher leaves (e.g. in OnSessionClose).