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
*Server
required
The server instance this stream belongs to. Must be set before calling
Initialize().*description.Session
required
The session description (SDP) that describes the media contained in this stream. Must be set before calling
Initialize().map[*description.Media]StreamMediaMulticastParams
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:Methods
Lifecycle
Lifecycle
Initialize
Server and Desc, and after the server has been started with Server.Start().error
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
*description.Media
required
The media track the packet belongs to. Must be one of the medias in
Desc.*rtp.Packet
required
The RTP packet to distribute.
error
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.*description.Media
required
The media track the packet belongs to.
*rtp.Packet
required
The RTP packet to distribute.
time.Time
required
Absolute NTP timestamp of the packet.
error
ErrServerStreamClosed if the stream has been closed; otherwise a write error.WritePacketRTCP
*description.Media
required
The media track the packet belongs to.
rtcp.Packet
required
The RTCP packet to distribute.
error
ErrServerStreamClosed if the stream has been closed; otherwise a write error.Statistics
Statistics
Stats
ServerStreamStats fields:ServerStreamStatsMedia fields:ServerStreamStatsFormat fields: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).