ServerSession represents a server-side RTSP session. A session is created automatically by the server when a client sends a SETUP or ANNOUNCE request. It tracks the session state, the negotiated transport, setupped media tracks, and optional user data.
ServerConn represents a single TCP connection to a client. One connection can be associated with at most one session, but a session (when using UDP transport) can be associated with multiple connections.
ServerSessionState
The state of a session progresses through the following values:ServerSession methods
State and properties
State and properties
State
ServerSessionState
One of the
ServerSessionState* constants.Stream
ServerStream associated with this session (set during SETUP for reading sessions). Returns nil for publishing sessions or before SETUP.Path
Query
AnnouncedDescription
nil for reading sessions.Medias
Transport
SessionTransport fields:Conns
ServerConn instances currently associated with the session.SetUserData / UserData
Lifecycle
Lifecycle
Close
OnSessionClose to be called. Safe to call from any goroutine.Packet callbacks (inbound — recording sessions)
Packet callbacks (inbound — recording sessions)
OnPacketRTP
OnPacketRTPFunc has signature func(*rtp.Packet).*description.Media
required
The media track to listen on.
format.Format
required
The codec format to receive packets for.
OnPacketRTPFunc
required
Callback invoked for each received RTP packet.
OnPacketRTPAny
OnPacketRTPAnyFunc has signature func(*description.Media, format.Format, *rtp.Packet).OnPacketRTPAnyFunc
required
Callback invoked with media and format context for each received RTP packet.
OnPacketRTCP
OnPacketRTCPFunc has signature func(rtcp.Packet).*description.Media
required
The media track to listen on.
OnPacketRTCPFunc
required
Callback invoked for each received RTCP packet.
OnPacketRTCPAny
OnPacketRTCPAnyFunc has signature func(*description.Media, rtcp.Packet).OnPacketRTCPAnyFunc
required
Callback invoked with media context for each received RTCP packet.
Packet writing (outbound — per-session writes)
Packet writing (outbound — per-session writes)
WritePacketRTP
ServerStream.WritePacketRTP instead when you want to fan out to all readers.*description.Media
required
The media track to write to.
*rtp.Packet
required
The RTP packet to send.
error
Non-nil on write failure.
WritePacketRTPWithNTP
WritePacketRTP but accepts an explicit NTP timestamp for RTCP sender reports.*description.Media
required
The media track to write to.
*rtp.Packet
required
The RTP packet to send.
time.Time
required
Absolute NTP timestamp of the packet.
error
Non-nil on write failure.
WritePacketRTCP
*description.Media
required
The media track to write to.
rtcp.Packet
required
The RTCP packet to send.
error
Non-nil on write failure.
Timestamps
Timestamps
PacketPTS
*description.Media
required
The media track the packet belongs to.
*rtp.Packet
required
The inbound RTP packet.
int64
PTS in media clock units.
bool
true if the PTS could be determined.PacketNTP
*description.Media
required
The media track the packet belongs to.
*rtp.Packet
required
The inbound RTP packet.
time.Time
The absolute NTP timestamp.
bool
true if the NTP could be derived from RTCP sender reports.Statistics
Statistics
ServerConn methods
ServerConn is a server-side TCP connection. It is passed to handler callbacks and provides the following public API.
Connection info
Connection info
NetConn
net.Conn. The remote address (RemoteAddr()) gives the client’s IP and port.Transport
ConnTransport struct has a single field:Session
ServerSession currently associated with this connection, or nil if no session has been established yet.SetUserData / UserData
Authentication
Authentication
VerifyCredentials
req against expectedUser and expectedPass. Supports the authentication methods configured in Server.AuthMethods (Basic and/or Digest).Call this inside handler callbacks (e.g. OnDescribe, OnAnnounce) to enforce access control. Returns false and the server will automatically send a 401 Unauthorized with a WWW-Authenticate challenge on the first attempt. Returns false and closes the connection if wrong credentials are provided after a challenge.*base.Request
required
The incoming RTSP request.
string
required
Expected username. Must not be empty.
string
required
Expected password.
bool
true if credentials are correct, false otherwise.Statistics
Statistics
Lifecycle
Lifecycle