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.
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:| Constant | Value | Meaning |
|---|---|---|
ServerSessionStateInitial | 0 | Session created; no tracks set up yet |
ServerSessionStatePrePlay | 1 | At least one track set up for reading; PLAY not yet sent |
ServerSessionStatePlay | 2 | Actively reading — packets are being delivered to the client |
ServerSessionStatePreRecord | 3 | ANNOUNCE received; at least one track set up for publishing; RECORD not yet sent |
ServerSessionStateRecord | 4 | Actively recording — packets are being received from the client |
ServerSession methods
State and properties
State and properties
State
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:| Field | Type | Description |
|---|---|---|
Protocol | Protocol | Transport protocol: ProtocolUDP, ProtocolUDPMulticast, or ProtocolTCP |
Profile | headers.TransportProfile | RTSP transport profile (TransportProfileAVP or TransportProfileSAVP) |
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).The media track to listen on.
The codec format to receive packets for.
Callback invoked for each received RTP packet.
OnPacketRTPAny
OnPacketRTPAnyFunc has signature func(*description.Media, format.Format, *rtp.Packet).Callback invoked with media and format context for each received RTP packet.
OnPacketRTCP
OnPacketRTCPFunc has signature func(rtcp.Packet).The media track to listen on.
Callback invoked for each received RTCP packet.
OnPacketRTCPAny
OnPacketRTCPAnyFunc has signature func(*description.Media, rtcp.Packet).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.The media track to write to.
The RTP packet to send.
Non-nil on write failure.
WritePacketRTPWithNTP
WritePacketRTP but accepts an explicit NTP timestamp for RTCP sender reports.The media track to write to.
The RTP packet to send.
Absolute NTP timestamp of the packet.
Non-nil on write failure.
WritePacketRTCP
The media track to write to.
The RTCP packet to send.
Non-nil on write failure.
Timestamps
Timestamps
PacketPTS
The media track the packet belongs to.
The inbound RTP packet.
PTS in media clock units.
true if the PTS could be determined.PacketNTP
The media track the packet belongs to.
The inbound RTP packet.
The absolute NTP timestamp.
true if the NTP could be derived from RTCP sender reports.Statistics
Statistics
Stats
SessionStats fields:| Field | Type | Description |
|---|---|---|
InboundBytes | uint64 | Total inbound bytes |
InboundRTPPackets | uint64 | RTP packets correctly received and processed |
InboundRTPPacketsLost | uint64 | Lost inbound RTP packets |
InboundRTPPacketsInError | uint64 | Inbound RTP packets that could not be processed |
InboundRTPPacketsJitter | float64 | Mean jitter of inbound RTP packets |
InboundRTCPPackets | uint64 | RTCP packets received and processed |
InboundRTCPPacketsInError | uint64 | Inbound RTCP packets that could not be processed |
OutboundBytes | uint64 | Total outbound bytes |
OutboundRTPPackets | uint64 | RTP packets sent |
OutboundRTPPacketsReportedLost | uint64 | RTP packets reported lost by the remote |
OutboundRTCPPackets | uint64 | RTCP packets sent |
Medias | map[*description.Media]SessionStatsMedia | Per-media breakdown |
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:| Field | Type | Description |
|---|---|---|
Tunnel | Tunnel | Tunneling method: TunnelNone, TunnelHTTP, or TunnelWebSocket |
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.The incoming RTSP request.
Expected username. Must not be empty.
Expected password.
true if credentials are correct, false otherwise.Statistics
Statistics
Stats
ConnStats fields:| Field | Type | Description |
|---|---|---|
InboundBytes | uint64 | Total bytes received on this connection |
OutboundBytes | uint64 | Total bytes sent on this connection |
Lifecycle
Lifecycle