Server is a RTSP server. It accepts connections from clients, manages sessions, and dispatches events to a user-supplied handler.
Struct fields
Network configuration
string
required
The TCP address the server listens on (e.g.
":8554"). Also used for TCP transport. This field is required.string
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.string
Address for the UDP RTCP listener (e.g.
":8001"). Must be set together with UDPRTPAddress. The RTCP port must equal UDPRTPPort + 1.string
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.int
Port for multicast RTP packets. Must be even.
int
Port for multicast RTCP packets. Must equal
MulticastRTPPort + 1.Timeouts
time.Duration
default:"10s"
Timeout for read operations.
time.Duration
default:"10s"
Timeout for write operations.
time.Duration
default:"60s"
Read timeout for idle connections and sessions with no activity.
TLS
*tls.Config
TLS configuration. When set, the server accepts RTSPS connections and enforces SRTP for UDP transport.
I/O tuning
int
default:"OS default"
Size of the UDP read buffer. Increase to reduce packet loss on high-bandwidth streams.
int
default:"256"
Size of the outbound packet queue per session. Must be a power of two.
int
default:"1472"
Maximum size of outbound RTP/RTCP packets in bytes. Must be less than the IPv4/UDP MTU (1472 bytes).
bool
default:"false"
Disable automatic generation and sending of RTCP sender reports to readers.
Authentication
[]auth.VerifyMethod
default:"[Basic, DigestMD5]"
Allowed authentication methods. Defaults to
[auth.VerifyMethodBasic, auth.VerifyMethodDigestMD5]. DigestSHA256 is omitted by default because it prevents FFmpeg from authenticating.Handler
ServerHandler
An object that implements one or more of the
ServerHandler* interfaces to handle server events. See Handler interfaces below.System functions
func(network, address string) (net.Listener, error)
default:"net.Listen"
Function used to create the TCP listener. Override for custom networking.
func(network, address string) (net.PacketConn, error)
default:"net.ListenPacket"
Function used to create UDP listeners.
Methods
Lifecycle
Lifecycle
Start
error
Non-nil if configuration is invalid or listeners cannot be opened.
StartAndWait
Close() is called. Equivalent to calling Start() then Wait().error
The terminal error, or
nil if closed cleanly.Wait
error
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:ServerHandlerOnConnClose
ServerHandlerOnConnClose
ServerHandlerOnConnCloseCtx:ServerHandlerOnRequest / ServerHandlerOnResponse
ServerHandlerOnRequest / ServerHandlerOnResponse
Session events
ServerHandlerOnSessionOpen
ServerHandlerOnSessionOpen
ServerHandlerOnSessionOpenCtx:ServerHandlerOnSessionClose
ServerHandlerOnSessionClose
ServerHandlerOnSessionCloseCtx:RTSP method handlers
ServerHandlerOnDescribe
ServerHandlerOnDescribe
ServerStream to use. The server serializes the stream description into the response body automatically.Context struct ServerHandlerOnDescribeCtx:ServerHandlerOnAnnounce
ServerHandlerOnAnnounce
ServerHandlerOnAnnounceCtx:ServerHandlerOnSetup
ServerHandlerOnSetup
ServerStream to associate the session with it as a reader. Return nil for the stream when handling publishers.Context struct ServerHandlerOnSetupCtx:ServerHandlerOnPlay
ServerHandlerOnPlay
ServerHandlerOnPlayCtx:ServerHandlerOnRecord
ServerHandlerOnRecord
ServerHandlerOnRecordCtx:ServerHandlerOnPause
ServerHandlerOnPause
ServerHandlerOnPauseCtx:ServerHandlerOnGetParameter / ServerHandlerOnSetParameter
ServerHandlerOnGetParameter / ServerHandlerOnSetParameter
Session, Conn, Request, Path, and Query fields.Error and diagnostic handlers
ServerHandlerOnPacketsLost
ServerHandlerOnPacketsLost
ServerHandlerOnPacketsLostCtx:ServerHandlerOnDecodeError
ServerHandlerOnDecodeError
ServerHandlerOnDecodeErrorCtx:ServerHandlerOnStreamWriteError
ServerHandlerOnStreamWriteError
ServerStream fails to write packets to a reader session. Defaults to logging the error if not implemented.Context struct ServerHandlerOnStreamWriteErrorCtx: