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.
Server is a RTSP server. It accepts connections from clients, manages sessions, and dispatches events to a user-supplied handler.
Struct fields
Network configuration
The TCP address the server listens on (e.g.
":8554"). Also used for TCP transport. This field is required.Address for the UDP RTP listener (e.g.
":8000"). Must be set together with UDPRTCPAddress to enable UDP transport. The RTP port must be even.Address for the UDP RTCP listener (e.g.
":8001"). Must be set together with UDPRTPAddress. The RTCP port must equal UDPRTPPort + 1.CIDR range of multicast IPs to assign (e.g.
"224.1.0.0/16"). Must be set together with MulticastRTPPort and MulticastRTCPPort to enable UDP-multicast transport.Port for multicast RTP packets. Must be even.
Port for multicast RTCP packets. Must equal
MulticastRTPPort + 1.Timeouts
Timeout for read operations.
Timeout for write operations.
Read timeout for idle connections and sessions with no activity.
TLS
TLS configuration. When set, the server accepts RTSPS connections and enforces SRTP for UDP transport.
I/O tuning
Size of the UDP read buffer. Increase to reduce packet loss on high-bandwidth streams.
Size of the outbound packet queue per session. Must be a power of two.
Maximum size of outbound RTP/RTCP packets in bytes. Must be less than the IPv4/UDP MTU (1472 bytes).
Disable automatic generation and sending of RTCP sender reports to readers.
Authentication
Allowed authentication methods. Defaults to
[auth.VerifyMethodBasic, auth.VerifyMethodDigestMD5]. DigestSHA256 is omitted by default because it prevents FFmpeg from authenticating.Handler
An object that implements one or more of the
ServerHandler* interfaces to handle server events. See Handler interfaces below.System functions
Function used to create the TCP listener. Override for custom networking.
Function used to create UDP listeners.
Methods
Lifecycle
Lifecycle
Start
Non-nil if configuration is invalid or listeners cannot be opened.
StartAndWait
Close() is called. Equivalent to calling Start() then Wait().The terminal error, or
nil if closed cleanly.Wait
The terminal error, or
nil if closed cleanly.Close
NetListener
net.Listener for the TCP RTSP socket. Useful for obtaining the dynamically assigned port when RTSPAddress uses port 0.Handler interfaces
TheHandler field accepts any value that implements one or more of the following interfaces. Implement only the interfaces relevant to your use case.
Connection events
ServerHandlerOnConnOpen
ServerHandlerOnConnOpen
ServerHandlerOnConnOpenCtx:| Field | Type | Description |
|---|---|---|
Conn | *ServerConn | The newly opened connection |
ServerHandlerOnConnClose
ServerHandlerOnConnClose
ServerHandlerOnConnCloseCtx:| Field | Type | Description |
|---|---|---|
Conn | *ServerConn | The closed connection |
Error | error | The error that caused the close, or nil |
ServerHandlerOnRequest / ServerHandlerOnResponse
ServerHandlerOnRequest / ServerHandlerOnResponse
Session events
ServerHandlerOnSessionOpen
ServerHandlerOnSessionOpen
ServerHandlerOnSessionOpenCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The new session |
Conn | *ServerConn | The connection that opened the session |
ServerHandlerOnSessionClose
ServerHandlerOnSessionClose
ServerHandlerOnSessionCloseCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The closed session |
Error | error | The error that caused the close, or nil |
RTSP method handlers
ServerHandlerOnDescribe
ServerHandlerOnDescribe
ServerStream to use. The server serializes the stream description into the response body automatically.Context struct ServerHandlerOnDescribeCtx:| Field | Type | Description |
|---|---|---|
Conn | *ServerConn | The connection |
Request | *base.Request | The raw request |
Path | string | Request path |
Query | string | Request query string |
ServerHandlerOnAnnounce
ServerHandlerOnAnnounce
ServerHandlerOnAnnounceCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The session |
Conn | *ServerConn | The connection |
Request | *base.Request | The raw request |
Path | string | Announced path |
Query | string | Query string |
Description | *description.Session | Parsed SDP from the request body |
ServerHandlerOnSetup
ServerHandlerOnSetup
ServerStream to associate the session with it as a reader. Return nil for the stream when handling publishers.Context struct ServerHandlerOnSetupCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The session |
Conn | *ServerConn | The connection |
Request | *base.Request | The raw request |
Path | string | Request path |
Query | string | Query string |
Transport | *SessionTransport | Negotiated transport details |
ServerHandlerOnPlay
ServerHandlerOnPlay
ServerHandlerOnPlayCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The session |
Conn | *ServerConn | The connection |
Request | *base.Request | The raw request |
Path | string | Request path |
Query | string | Query string |
ServerHandlerOnRecord
ServerHandlerOnRecord
ServerHandlerOnRecordCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The session |
Conn | *ServerConn | The connection |
Request | *base.Request | The raw request |
Path | string | Request path |
Query | string | Query string |
ServerHandlerOnPause
ServerHandlerOnPause
ServerHandlerOnPauseCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The session |
Conn | *ServerConn | The connection |
Request | *base.Request | The raw request |
Path | string | Request path |
Query | string | Query string |
ServerHandlerOnGetParameter / ServerHandlerOnSetParameter
ServerHandlerOnGetParameter / ServerHandlerOnSetParameter
Session, Conn, Request, Path, and Query fields.Error and diagnostic handlers
ServerHandlerOnPacketsLost
ServerHandlerOnPacketsLost
ServerHandlerOnPacketsLostCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The session where loss was detected |
Lost | uint64 | Number of lost packets |
ServerHandlerOnDecodeError
ServerHandlerOnDecodeError
ServerHandlerOnDecodeErrorCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The session that encountered the error |
Error | error | The decode error |
ServerHandlerOnStreamWriteError
ServerHandlerOnStreamWriteError
ServerStream fails to write packets to a reader session. Defaults to logging the error if not implemented.Context struct ServerHandlerOnStreamWriteErrorCtx:| Field | Type | Description |
|---|---|---|
Session | *ServerSession | The reader session that failed |
Error | error | The write error |