gortsplib

package module
v5.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 45 Imported by: 0

README ΒΆ

gortsplib

Test Lint Go Report Card CodeCov PkgGoDev

RTSP client and server library for the Go programming language, written for MediaMTX.

Go β‰₯ 1.24 is required.

Features:

  • Client
    • Support secure protocol variants (RTSPS, TLS, SRTP, SRTCP)
    • Support tunneling (RTSP-over-HTTP, RTSP-over-WebSocket)
    • Query servers about available media streams
    • Read media streams from a server ("play")
      • Read streams with the UDP, UDP-multicast or TCP transport protocol
      • Switch transport protocol automatically
      • Read selected media streams
      • Pause or seek without disconnecting from the server
      • Write to ONVIF back channels
      • Get PTS (presentation timestamp) of incoming packets
      • Get NTP (absolute timestamp) of incoming packets
    • Write media streams to a server ("record")
      • Write streams with the UDP or TCP transport protocol
      • Switch transport protocol automatically
      • Pause without disconnecting from the server
  • Server
    • Support secure protocol variants (RTSPS, TLS, SRTP, SRTCP)
    • Support tunneling (RTSP-over-HTTP, RTSP-over-WebSocket)
    • Handle requests from clients
    • Validate client credentials
    • Read media streams from clients ("record")
      • Read streams with the UDP or TCP transport protocol
      • Get PTS (presentation timestamp) of incoming packets
      • Get NTP (absolute timestamp) of incoming packets
    • Serve media streams to clients ("play")
      • Write streams with the UDP, UDP-multicast or TCP transport protocol
      • Compute and provide SSRC, RTP-Info to clients
      • Read ONVIF back channels
  • Utilities
    • Parse RTSP elements
    • Encode/decode RTP packets into/from codec-specific frames

Table of contents

Examples

API Documentation

Click to open the API Documentation

RTP Payload Formats

In RTSP, media streams are transmitted by using RTP packets, which are encoded in a specific, codec-dependent, format. This library supports the following formats:

Video
format documentation encoder and decoder available
AV1 link βœ”
VP9 link βœ”
VP8 link βœ”
H265 link βœ”
H264 link βœ”
MPEG-4 Video (H263, Xvid) link βœ”
MPEG-1/2 Video link βœ”
M-JPEG link βœ”
Audio
format documentation encoder and decoder available
Opus link βœ”
Vorbis link
MPEG-4 Audio (AAC) link βœ”
MPEG-4 Audio LATM (AAC-LATM) link βœ”
MPEG-1/2 Audio (MP3) link οΏ½οΏ½οΏ½
AC-3 link βœ”
Speex link
G726 link
G722 link βœ”
G711 (PCMA, PCMU) link βœ”
LPCM link βœ”
Other
format documentation encoder and decoder available
MPEG-TS link
KLV link βœ”

Specifications

name area
RFC2326, RTSP 1.0 protocol
RFC7826, RTSP 2.0 protocol
ONVIF Streaming Specification 23.06 protocol
RFC8866, SDP: Session Description Protocol SDP
RFC4567, Key Management Extensions for Session Description Protocol (SDP) and Real Time Streaming Protocol (RTSP) secure variants
RFC3830, MIKEY: Multimedia Internet KEYing secure variants
RTP Payload Format For AV1 (v1.0) payload formats / AV1
RFC9628, RTP Payload Format for VP9 Video payload formats / VP9
RFC7741, RTP Payload Format for VP8 Video payload formats / VP8
RFC7798, RTP Payload Format for High Efficiency Video Coding (HEVC) payload formats / H265
RFC6184, RTP Payload Format for H.264 Video payload formats / H264
RFC3640, RTP Payload Format for Transport of MPEG-4 Elementary Streams payload formats / MPEG-4 audio, MPEG-4 video
RFC2250, RTP Payload Format for MPEG1/MPEG2 Video payload formats / MPEG-1 video, MPEG-2 audio, MPEG-TS
RFC2435, RTP Payload Format for JPEG-compressed Video payload formats / M-JPEG
RFC7587, RTP Payload Format for the Opus Speech and Audio Codec payload formats / Opus
Multiopus in libwebrtc payload formats / Opus
RFC5215, RTP Payload Format for Vorbis Encoded Audio payload formats / Vorbis
RFC4184, RTP Payload Format for AC-3 Audio payload formats / AC-3
RFC6416, RTP Payload Format for MPEG-4 Audio/Visual Streams payload formats / MPEG-4 audio LATM
RFC5574, RTP Payload Format for the Speex Codec payload formats / Speex
RFC3551, RTP Profile for Audio and Video Conferences with Minimal Control payload formats / G726, G722, G711, LPCM
RFC3190, RTP Payload Format for 12-bit DAT Audio and 20- and 24-bit Linear Sampled Audio payload formats / LPCM
RFC6597, RTP Payload Format for Society of Motion Picture and Television Engineers (SMPTE) ST 336 Encoded Data payload formats / KLV
Codec specifications codecs
Golang project layout project layout

Documentation ΒΆ

Overview ΒΆ

Package gortsplib is a RTSP library for the Go programming language.

Examples are available at https://github.com/bluenviron/gortsplib/tree/main/examples

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type Client ΒΆ

type Client struct {
	//
	// Target
	//
	// Scheme. Either "rtsp" or "rtsps".
	Scheme string
	// Host and port.
	Host string

	//
	// RTSP parameters (all optional)
	//
	// timeout of read operations.
	// It defaults to 10 seconds.
	ReadTimeout time.Duration
	// timeout of write operations.
	// It defaults to 10 seconds.
	WriteTimeout time.Duration
	// a TLS configuration to connect to TLS/RTSPS servers.
	// It defaults to nil.
	TLSConfig *tls.Config
	// tunneling method.
	Tunnel Tunnel
	// transport protocol (UDP, Multicast or TCP).
	// If nil, it is chosen automatically (first UDP, then, if it fails, TCP).
	// It defaults to nil.
	Protocol *Protocol
	// enable communication with servers which don't provide UDP server ports
	// or use different server ports than the announced ones.
	// This can be a security issue.
	// It defaults to false.
	AnyPortEnable bool
	// If the client is reading with UDP, it must receive
	// at least a packet within this timeout, otherwise it switches to TCP.
	// It defaults to 3 seconds.
	InitialUDPReadTimeout time.Duration
	// Size of the UDP read buffer.
	// This can be increased to reduce packet losses.
	// It defaults to the operating system default value.
	UDPReadBufferSize int
	// Size of the queue of outgoing packets.
	// It defaults to 256.
	WriteQueueSize int
	// maximum size of outgoing RTP / RTCP packets.
	// This must be less than the UDP MTU (1472 bytes).
	// It defaults to 1472.
	MaxPacketSize int
	// user agent header.
	// It defaults to "gortsplib"
	UserAgent string
	// disable automatic RTCP sender reports.
	DisableRTCPSenderReports bool
	// explicitly request back channels to the server.
	RequestBackChannels bool

	//
	// system functions (all optional)
	//
	// function used to initialize the TCP client.
	// It defaults to (&net.Dialer{}).DialContext.
	DialContext func(ctx context.Context, network, address string) (net.Conn, error)
	// function used to initialize UDP listeners.
	// It defaults to net.ListenPacket.
	ListenPacket func(network, address string) (net.PacketConn, error)

	//
	// callbacks (all optional)
	//
	// called when sending a request to the server.
	OnRequest ClientOnRequestFunc
	// called when receiving a response from the server.
	OnResponse ClientOnResponseFunc
	// called when receiving a request from the server.
	OnServerRequest ClientOnRequestFunc
	// called when sending a response to the server.
	OnServerResponse ClientOnResponseFunc
	// called when the transport protocol changes.
	OnTransportSwitch ClientOnTransportSwitchFunc
	// called when the client detects lost packets.
	OnPacketsLost ClientOnPacketsLostFunc
	// called when a non-fatal decode error occurs.
	OnDecodeError ClientOnDecodeErrorFunc
	// contains filtered or unexported fields
}

Client is a RTSP client.

func (*Client) Announce ΒΆ

func (c *Client) Announce(u *base.URL, desc *description.Session) (*base.Response, error)

Announce sends an ANNOUNCE request.

func (*Client) Close ΒΆ

func (c *Client) Close()

Close closes all client resources and waits for them to exit.

func (*Client) Describe ΒΆ

func (c *Client) Describe(u *base.URL) (*description.Session, *base.Response, error)

Describe sends a DESCRIBE request.

func (*Client) OnPacketRTCP ΒΆ

func (c *Client) OnPacketRTCP(medi *description.Media, cb OnPacketRTCPFunc)

OnPacketRTCP sets a callback that is called when a RTCP packet is read.

func (*Client) OnPacketRTCPAny ΒΆ

func (c *Client) OnPacketRTCPAny(cb OnPacketRTCPAnyFunc)

OnPacketRTCPAny sets a callback that is called when a RTCP packet is read from any setupped media.

func (*Client) OnPacketRTP ΒΆ

func (c *Client) OnPacketRTP(medi *description.Media, forma format.Format, cb OnPacketRTPFunc)

OnPacketRTP sets a callback that is called when a RTP packet is read.

func (*Client) OnPacketRTPAny ΒΆ

func (c *Client) OnPacketRTPAny(cb OnPacketRTPAnyFunc)

OnPacketRTPAny sets a callback that is called when a RTP packet is read from any setupped media.

func (*Client) Options ΒΆ

func (c *Client) Options(u *base.URL) (*base.Response, error)

Options sends an OPTIONS request.

func (*Client) PacketNTP ΒΆ

func (c *Client) PacketNTP(medi *description.Media, pkt *rtp.Packet) (time.Time, bool)

PacketNTP returns the NTP (absolute timestamp) of an incoming RTP packet. The NTP is computed from RTCP sender reports.

func (*Client) PacketPTS ΒΆ

func (c *Client) PacketPTS(medi *description.Media, pkt *rtp.Packet) (int64, bool)

PacketPTS returns the PTS (presentation timestamp) of an incoming RTP packet. It is computed by decoding the packet timestamp and sychronizing it with other tracks.

func (*Client) Pause ΒΆ

func (c *Client) Pause() (*base.Response, error)

Pause sends a PAUSE request. This can be called only after Play() or Record().

func (*Client) Play ΒΆ

func (c *Client) Play(ra *headers.Range) (*base.Response, error)

Play sends a PLAY request. This can be called only after Setup().

func (*Client) Record ΒΆ

func (c *Client) Record() (*base.Response, error)

Record sends a RECORD request. This can be called only after Announce() and Setup().

func (*Client) Setup ΒΆ

func (c *Client) Setup(
	baseURL *base.URL,
	media *description.Media,
	rtpPort int,
	rtcpPort int,
) (*base.Response, error)

Setup sends a SETUP request. rtpPort and rtcpPort are used only if transport is UDP. if rtpPort and rtcpPort are zero, they are chosen automatically.

func (*Client) SetupAll ΒΆ

func (c *Client) SetupAll(baseURL *base.URL, medias []*description.Media) error

SetupAll setups all the given medias.

func (*Client) Start ΒΆ

func (c *Client) Start() error

Start initializes the connection to a server.

func (*Client) StartRecording ΒΆ

func (c *Client) StartRecording(address string, desc *description.Session) error

StartRecording connects to the address and starts publishing given media.

func (*Client) Stats ΒΆ

func (c *Client) Stats() *ClientStats

Stats returns client statistics.

func (*Client) Transport ΒΆ

func (c *Client) Transport() *ClientTransport

Transport returns transport details.

func (*Client) Wait ΒΆ

func (c *Client) Wait() error

Wait waits until all client resources are closed. This can happen when a fatal error occurs or when Close() is called.

func (*Client) WritePacketRTCP ΒΆ

func (c *Client) WritePacketRTCP(medi *description.Media, pkt rtcp.Packet) error

WritePacketRTCP writes a RTCP packet to the server.

func (*Client) WritePacketRTP ΒΆ

func (c *Client) WritePacketRTP(medi *description.Media, pkt *rtp.Packet) error

WritePacketRTP writes a RTP packet to the server.

func (*Client) WritePacketRTPWithNTP ΒΆ

func (c *Client) WritePacketRTPWithNTP(medi *description.Media, pkt *rtp.Packet, ntp time.Time) error

WritePacketRTPWithNTP writes a RTP packet to the server. ntp is the absolute timestamp of the packet, and is sent with periodic RTCP sender reports.

type ClientOnDecodeErrorFunc ΒΆ

type ClientOnDecodeErrorFunc func(err error)

ClientOnDecodeErrorFunc is the prototype of Client.OnDecodeError.

type ClientOnPacketsLostFunc ΒΆ

type ClientOnPacketsLostFunc func(lost uint64)

ClientOnPacketsLostFunc is the prototype of Client.OnPacketsLost.

type ClientOnRequestFunc ΒΆ

type ClientOnRequestFunc func(*base.Request)

ClientOnRequestFunc is the prototype of Client.OnRequest.

type ClientOnResponseFunc ΒΆ

type ClientOnResponseFunc func(*base.Response)

ClientOnResponseFunc is the prototype of Client.OnResponse.

type ClientOnTransportSwitchFunc ΒΆ

type ClientOnTransportSwitchFunc func(err error)

ClientOnTransportSwitchFunc is the prototype of Client.OnTransportSwitch.

type ClientStats ΒΆ

type ClientStats struct {
	Conn    ConnStats
	Session SessionStats
}

ClientStats are client statistics

type ClientTransport ΒΆ

type ClientTransport struct {
	Conn ConnTransport
	// present only when SETUP has been called at least once.
	Session *SessionTransport
}

ClientTransport contains details about the client transport.

type ConnStats ΒΆ

type ConnStats struct {
	// received bytes
	BytesReceived uint64
	// sent bytes
	BytesSent uint64
}

ConnStats are connection statistics.

type ConnTransport ΒΆ

type ConnTransport struct {
	Tunnel Tunnel
}

ConnTransport contains details about the transport of a connection.

type OnPacketRTCPAnyFunc ΒΆ

type OnPacketRTCPAnyFunc func(*description.Media, rtcp.Packet)

OnPacketRTCPAnyFunc is the prototype of the callback passed to OnPacketRTCPAny().

type OnPacketRTCPFunc ΒΆ

type OnPacketRTCPFunc func(rtcp.Packet)

OnPacketRTCPFunc is the prototype of the callback passed to OnPacketRTCP().

type OnPacketRTPAnyFunc ΒΆ

type OnPacketRTPAnyFunc func(*description.Media, format.Format, *rtp.Packet)

OnPacketRTPAnyFunc is the prototype of the callback passed to OnPacketRTP(Any).

type OnPacketRTPFunc ΒΆ

type OnPacketRTPFunc func(*rtp.Packet)

OnPacketRTPFunc is the prototype of the callback passed to OnPacketRTP().

type Protocol ΒΆ

type Protocol int

Protocol is a RTSP transport protocol.

const (
	ProtocolUDP Protocol = iota
	ProtocolUDPMulticast
	ProtocolTCP
)

transport protocols.

func (Protocol) String ΒΆ

func (t Protocol) String() string

String implements fmt.Stringer.

type Server ΒΆ

type Server struct {
	//
	// RTSP parameters (all optional except RTSPAddress)
	//
	// the RTSP address of the server, to accept connections and send and receive
	// packets with the TCP transport.
	RTSPAddress string
	// a port to send and receive RTP packets with the UDP transport.
	// If UDPRTPAddress and UDPRTCPAddress are filled, the server can support the UDP transport.
	UDPRTPAddress string
	// a port to send and receive RTCP packets with the UDP transport.
	// If UDPRTPAddress and UDPRTCPAddress are filled, the server can support the UDP transport.
	UDPRTCPAddress string
	// a range of multicast IPs to use with the UDP-multicast transport.
	// If MulticastIPRange, MulticastRTPPort, MulticastRTCPPort are filled, the server
	// can support the UDP-multicast transport.
	MulticastIPRange string
	// a port to send RTP packets with the UDP-multicast transport.
	// If MulticastIPRange, MulticastRTPPort, MulticastRTCPPort are filled, the server
	// can support the UDP-multicast transport.
	MulticastRTPPort int
	// a port to send RTCP packets with the UDP-multicast transport.
	// If MulticastIPRange, MulticastRTPPort, MulticastRTCPPort are filled, the server
	// can support the UDP-multicast transport.
	MulticastRTCPPort int
	// timeout of read operations.
	// It defaults to 10 seconds.
	ReadTimeout time.Duration
	// timeout of write operations.
	// It defaults to 10 seconds.
	WriteTimeout time.Duration
	// read timeout of idle connections and sessions.
	// It defaults to 60 seconds.
	IdleTimeout time.Duration
	// a TLS configuration to accept TLS (RTSPS) connections.
	TLSConfig *tls.Config
	// Size of the UDP read buffer.
	// This can be increased to reduce packet losses.
	// It defaults to the operating system default value.
	UDPReadBufferSize int
	// Size of the queue of outgoing packets.
	// It defaults to 256.
	WriteQueueSize int
	// maximum size of outgoing RTP / RTCP packets.
	// This must be less than the UDP MTU (1472 bytes).
	// It defaults to 1472.
	MaxPacketSize int
	// disable automatic RTCP sender reports.
	DisableRTCPSenderReports bool
	// authentication methods.
	// It defaults to plain and digest+MD5.
	AuthMethods []auth.VerifyMethod

	//
	// handler (optional)
	//
	// an handler to handle server events.
	// It may implement one or more of the ServerHandler* interfaces.
	Handler ServerHandler

	//
	// system functions (all optional)
	//
	// function used to initialize the TCP listener.
	// It defaults to net.Listen.
	Listen func(network string, address string) (net.Listener, error)
	// function used to initialize UDP listeners.
	// It defaults to net.ListenPacket.
	ListenPacket func(network, address string) (net.PacketConn, error)
	// contains filtered or unexported fields
}

Server is a RTSP server.

func (*Server) Close ΒΆ

func (s *Server) Close()

Close closes all the server resources and waits for them to exit.

func (*Server) Start ΒΆ

func (s *Server) Start() error

Start starts the server.

func (*Server) StartAndWait ΒΆ

func (s *Server) StartAndWait() error

StartAndWait starts the server and waits until a fatal error.

func (*Server) Wait ΒΆ

func (s *Server) Wait() error

Wait waits until all server resources are closed. This can happen when a fatal error occurs or when Close() is called.

type ServerConn ΒΆ

type ServerConn struct {
	// contains filtered or unexported fields
}

ServerConn is a server-side RTSP connection.

func (*ServerConn) Close ΒΆ

func (sc *ServerConn) Close()

Close closes the ServerConn.

func (*ServerConn) NetConn ΒΆ

func (sc *ServerConn) NetConn() net.Conn

NetConn returns the underlying net.Conn.

func (*ServerConn) Session ΒΆ

func (sc *ServerConn) Session() *ServerSession

Session returns the associated session.

func (*ServerConn) SetUserData ΒΆ

func (sc *ServerConn) SetUserData(v interface{})

SetUserData sets some user data associated with the connection.

func (*ServerConn) Stats ΒΆ

func (sc *ServerConn) Stats() *ConnStats

Stats returns connection statistics.

func (*ServerConn) Transport ΒΆ

func (sc *ServerConn) Transport() *ConnTransport

Transport returns transport details.

func (*ServerConn) UserData ΒΆ

func (sc *ServerConn) UserData() interface{}

UserData returns some user data associated with the connection.

func (*ServerConn) VerifyCredentials ΒΆ

func (sc *ServerConn) VerifyCredentials(
	req *base.Request,
	expectedUser string,
	expectedPass string,
) bool

VerifyCredentials verifies credentials provided by the user.

type ServerHandler ΒΆ

type ServerHandler interface{}

ServerHandler is the interface implemented by all the server handlers.

type ServerHandlerOnAnnounce ΒΆ

type ServerHandlerOnAnnounce interface {
	// called when receiving an ANNOUNCE request.
	OnAnnounce(*ServerHandlerOnAnnounceCtx) (*base.Response, error)
}

ServerHandlerOnAnnounce can be implemented by a ServerHandler.

type ServerHandlerOnAnnounceCtx ΒΆ

type ServerHandlerOnAnnounceCtx struct {
	Session     *ServerSession
	Conn        *ServerConn
	Request     *base.Request
	Path        string
	Query       string
	Description *description.Session
}

ServerHandlerOnAnnounceCtx is the context of OnAnnounce.

type ServerHandlerOnConnClose ΒΆ

type ServerHandlerOnConnClose interface {
	// called when a connection is closed.
	OnConnClose(*ServerHandlerOnConnCloseCtx)
}

ServerHandlerOnConnClose can be implemented by a ServerHandler.

type ServerHandlerOnConnCloseCtx ΒΆ

type ServerHandlerOnConnCloseCtx struct {
	Conn  *ServerConn
	Error error
}

ServerHandlerOnConnCloseCtx is the context of OnConnClose.

type ServerHandlerOnConnOpen ΒΆ

type ServerHandlerOnConnOpen interface {
	// called when a connection is opened.
	OnConnOpen(*ServerHandlerOnConnOpenCtx)
}

ServerHandlerOnConnOpen can be implemented by a ServerHandler.

type ServerHandlerOnConnOpenCtx ΒΆ

type ServerHandlerOnConnOpenCtx struct {
	Conn *ServerConn
}

ServerHandlerOnConnOpenCtx is the context of OnConnOpen.

type ServerHandlerOnDecodeError ΒΆ

type ServerHandlerOnDecodeError interface {
	// called when a non-fatal decode error occurs.
	OnDecodeError(*ServerHandlerOnDecodeErrorCtx)
}

ServerHandlerOnDecodeError can be implemented by a ServerHandler.

type ServerHandlerOnDecodeErrorCtx ΒΆ

type ServerHandlerOnDecodeErrorCtx struct {
	Session *ServerSession
	Error   error
}

ServerHandlerOnDecodeErrorCtx is the context of OnDecodeError.

type ServerHandlerOnDescribe ΒΆ

type ServerHandlerOnDescribe interface {
	// called when receiving a DESCRIBE request.
	OnDescribe(*ServerHandlerOnDescribeCtx) (*base.Response, *ServerStream, error)
}

ServerHandlerOnDescribe can be implemented by a ServerHandler.

type ServerHandlerOnDescribeCtx ΒΆ

type ServerHandlerOnDescribeCtx struct {
	Conn    *ServerConn
	Request *base.Request
	Path    string
	Query   string
}

ServerHandlerOnDescribeCtx is the context of OnDescribe.

type ServerHandlerOnGetParameter ΒΆ

type ServerHandlerOnGetParameter interface {
	// called when receiving a GET_PARAMETER request.
	OnGetParameter(*ServerHandlerOnGetParameterCtx) (*base.Response, error)
}

ServerHandlerOnGetParameter can be implemented by a ServerHandler.

type ServerHandlerOnGetParameterCtx ΒΆ

type ServerHandlerOnGetParameterCtx struct {
	Session *ServerSession
	Conn    *ServerConn
	Request *base.Request
	Path    string
	Query   string
}

ServerHandlerOnGetParameterCtx is the context of OnGetParameter.

type ServerHandlerOnPacketsLost ΒΆ

type ServerHandlerOnPacketsLost interface {
	// called when the server detects lost packets.
	OnPacketsLost(*ServerHandlerOnPacketsLostCtx)
}

ServerHandlerOnPacketsLost can be implemented by a ServerHandler.

type ServerHandlerOnPacketsLostCtx ΒΆ

type ServerHandlerOnPacketsLostCtx struct {
	Session *ServerSession
	Lost    uint64
}

ServerHandlerOnPacketsLostCtx is the context of OnPacketsLost.

type ServerHandlerOnPause ΒΆ

type ServerHandlerOnPause interface {
	// called when receiving a PAUSE request.
	OnPause(*ServerHandlerOnPauseCtx) (*base.Response, error)
}

ServerHandlerOnPause can be implemented by a ServerHandler.

type ServerHandlerOnPauseCtx ΒΆ

type ServerHandlerOnPauseCtx struct {
	Session *ServerSession
	Conn    *ServerConn
	Request *base.Request
	Path    string
	Query   string
}

ServerHandlerOnPauseCtx is the context of OnPause.

type ServerHandlerOnPlay ΒΆ

type ServerHandlerOnPlay interface {
	// called when receiving a PLAY request.
	OnPlay(*ServerHandlerOnPlayCtx) (*base.Response, error)
}

ServerHandlerOnPlay can be implemented by a ServerHandler.

type ServerHandlerOnPlayCtx ΒΆ

type ServerHandlerOnPlayCtx struct {
	Session *ServerSession
	Conn    *ServerConn
	Request *base.Request
	Path    string
	Query   string
}

ServerHandlerOnPlayCtx is the context of OnPlay.

type ServerHandlerOnRecord ΒΆ

type ServerHandlerOnRecord interface {
	// called when receiving a RECORD request.
	OnRecord(*ServerHandlerOnRecordCtx) (*base.Response, error)
}

ServerHandlerOnRecord can be implemented by a ServerHandler.

type ServerHandlerOnRecordCtx ΒΆ

type ServerHandlerOnRecordCtx struct {
	Session *ServerSession
	Conn    *ServerConn
	Request *base.Request
	Path    string
	Query   string
}

ServerHandlerOnRecordCtx is the context of OnRecord.

type ServerHandlerOnRequest ΒΆ

type ServerHandlerOnRequest interface {
	// called when receiving a request from a connection.
	OnRequest(*ServerConn, *base.Request)
}

ServerHandlerOnRequest can be implemented by a ServerHandler.

type ServerHandlerOnResponse ΒΆ

type ServerHandlerOnResponse interface {
	// called when sending a response to a connection.
	OnResponse(*ServerConn, *base.Response)
}

ServerHandlerOnResponse can be implemented by a ServerHandler.

type ServerHandlerOnSessionClose ΒΆ

type ServerHandlerOnSessionClose interface {
	// called when a session is closed.
	OnSessionClose(*ServerHandlerOnSessionCloseCtx)
}

ServerHandlerOnSessionClose can be implemented by a ServerHandler.

type ServerHandlerOnSessionCloseCtx ΒΆ

type ServerHandlerOnSessionCloseCtx struct {
	Session *ServerSession
	Error   error
}

ServerHandlerOnSessionCloseCtx is the context of ServerHandlerOnSessionClose.

type ServerHandlerOnSessionOpen ΒΆ

type ServerHandlerOnSessionOpen interface {
	// called when a session is opened.
	OnSessionOpen(*ServerHandlerOnSessionOpenCtx)
}

ServerHandlerOnSessionOpen can be implemented by a ServerHandler.

type ServerHandlerOnSessionOpenCtx ΒΆ

type ServerHandlerOnSessionOpenCtx struct {
	Session *ServerSession
	Conn    *ServerConn
}

ServerHandlerOnSessionOpenCtx is the context OnSessionOpen.

type ServerHandlerOnSetParameter ΒΆ

type ServerHandlerOnSetParameter interface {
	// called when receiving a SET_PARAMETER request.
	OnSetParameter(*ServerHandlerOnSetParameterCtx) (*base.Response, error)
}

ServerHandlerOnSetParameter can be implemented by a ServerHandler.

type ServerHandlerOnSetParameterCtx ΒΆ

type ServerHandlerOnSetParameterCtx struct {
	Session *ServerSession
	Conn    *ServerConn
	Request *base.Request
	Path    string
	Query   string
}

ServerHandlerOnSetParameterCtx is the context of OnSetParameter.

type ServerHandlerOnSetup ΒΆ

type ServerHandlerOnSetup interface {
	// called when receiving a SETUP request.
	// must return a Response and a stream.
	// the stream is needed to
	// - add the session the the stream's readers
	// - send the stream SSRC to the session
	OnSetup(*ServerHandlerOnSetupCtx) (*base.Response, *ServerStream, error)
}

ServerHandlerOnSetup can be implemented by a ServerHandler.

type ServerHandlerOnSetupCtx ΒΆ

type ServerHandlerOnSetupCtx struct {
	Session   *ServerSession
	Conn      *ServerConn
	Request   *base.Request
	Path      string
	Query     string
	Transport *SessionTransport
}

ServerHandlerOnSetupCtx is the context of OnSetup.

type ServerHandlerOnStreamWriteError ΒΆ

type ServerHandlerOnStreamWriteError interface {
	// called when a ServerStream is unable to write packets to a session.
	OnStreamWriteError(*ServerHandlerOnStreamWriteErrorCtx)
}

ServerHandlerOnStreamWriteError can be implemented by a ServerHandler.

type ServerHandlerOnStreamWriteErrorCtx ΒΆ

type ServerHandlerOnStreamWriteErrorCtx struct {
	Session *ServerSession
	Error   error
}

ServerHandlerOnStreamWriteErrorCtx is the context of OnStreamWriteError.

type ServerSession ΒΆ

type ServerSession struct {
	// contains filtered or unexported fields
}

ServerSession is a server-side RTSP session.

func (*ServerSession) AnnouncedDescription ΒΆ

func (ss *ServerSession) AnnouncedDescription() *description.Session

AnnouncedDescription returns the announced stream description.

func (*ServerSession) Close ΒΆ

func (ss *ServerSession) Close()

Close closes the ServerSession.

func (*ServerSession) Medias ΒΆ

func (ss *ServerSession) Medias() []*description.Media

Medias returns setupped medias.

func (*ServerSession) OnPacketRTCP ΒΆ

func (ss *ServerSession) OnPacketRTCP(medi *description.Media, cb OnPacketRTCPFunc)

OnPacketRTCP sets a callback that is called when a RTCP packet is read.

func (*ServerSession) OnPacketRTCPAny ΒΆ

func (ss *ServerSession) OnPacketRTCPAny(cb OnPacketRTCPAnyFunc)

OnPacketRTCPAny sets a callback that is called when a RTCP packet is read from any setupped media.

func (*ServerSession) OnPacketRTP ΒΆ

func (ss *ServerSession) OnPacketRTP(medi *description.Media, forma format.Format, cb OnPacketRTPFunc)

OnPacketRTP sets a callback that is called when a RTP packet is read.

func (*ServerSession) OnPacketRTPAny ΒΆ

func (ss *ServerSession) OnPacketRTPAny(cb OnPacketRTPAnyFunc)

OnPacketRTPAny sets a callback that is called when a RTP packet is read from any setupped media.

func (*ServerSession) PacketNTP ΒΆ

func (ss *ServerSession) PacketNTP(medi *description.Media, pkt *rtp.Packet) (time.Time, bool)

PacketNTP returns the NTP (absolute timestamp) of an incoming RTP packet. The NTP is computed from RTCP sender reports.

func (*ServerSession) PacketPTS ΒΆ

func (ss *ServerSession) PacketPTS(medi *description.Media, pkt *rtp.Packet) (int64, bool)

PacketPTS returns the PTS (presentation timestamp) of an incoming RTP packet. It is computed by decoding the packet timestamp and sychronizing it with other tracks.

func (*ServerSession) Path ΒΆ

func (ss *ServerSession) Path() string

Path returns the path sent during SETUP or ANNOUNCE.

func (*ServerSession) Query ΒΆ

func (ss *ServerSession) Query() string

Query returns the query sent during SETUP or ANNOUNCE.

func (*ServerSession) SetUserData ΒΆ

func (ss *ServerSession) SetUserData(v interface{})

SetUserData sets some user data associated with the session.

func (*ServerSession) State ΒΆ

func (ss *ServerSession) State() ServerSessionState

State returns the state of the session.

func (*ServerSession) Stats ΒΆ

func (ss *ServerSession) Stats() *SessionStats

Stats returns server session statistics.

func (*ServerSession) Stream ΒΆ

func (ss *ServerSession) Stream() *ServerStream

Stream returns the stream associated with the session.

func (*ServerSession) Transport ΒΆ

func (ss *ServerSession) Transport() *SessionTransport

Transport returns transport details. This is non-nil only if SETUP has been called at least once.

func (*ServerSession) UserData ΒΆ

func (ss *ServerSession) UserData() interface{}

UserData returns some user data associated with the session.

func (*ServerSession) WritePacketRTCP ΒΆ

func (ss *ServerSession) WritePacketRTCP(medi *description.Media, pkt rtcp.Packet) error

WritePacketRTCP writes a RTCP packet to the session.

func (*ServerSession) WritePacketRTP ΒΆ

func (ss *ServerSession) WritePacketRTP(medi *description.Media, pkt *rtp.Packet) error

WritePacketRTP writes a RTP packet to the session.

type ServerSessionState ΒΆ

type ServerSessionState int

ServerSessionState is a state of a ServerSession.

const (
	ServerSessionStateInitial ServerSessionState = iota
	ServerSessionStatePrePlay
	ServerSessionStatePlay
	ServerSessionStatePreRecord
	ServerSessionStateRecord
)

states.

func (ServerSessionState) String ΒΆ

func (s ServerSessionState) String() string

String implements fmt.Stringer.

type ServerStream ΒΆ

type ServerStream struct {
	Server *Server
	Desc   *description.Session
	// contains filtered or unexported fields
}

ServerStream represents a data stream. This is in charge of - storing stream description and statistics - distributing the stream to each reader - allocating multicast listeners

func (*ServerStream) Close ΒΆ

func (st *ServerStream) Close()

Close closes a ServerStream.

func (*ServerStream) Initialize ΒΆ

func (st *ServerStream) Initialize() error

Initialize initializes a ServerStream.

func (*ServerStream) Stats ΒΆ

func (st *ServerStream) Stats() *ServerStreamStats

Stats returns stream statistics.

func (*ServerStream) WritePacketRTCP ΒΆ

func (st *ServerStream) WritePacketRTCP(medi *description.Media, pkt rtcp.Packet) error

WritePacketRTCP writes a RTCP packet to all the readers of the stream.

func (*ServerStream) WritePacketRTP ΒΆ

func (st *ServerStream) WritePacketRTP(medi *description.Media, pkt *rtp.Packet) error

WritePacketRTP writes a RTP packet to all the readers of the stream.

func (*ServerStream) WritePacketRTPWithNTP ΒΆ

func (st *ServerStream) WritePacketRTPWithNTP(medi *description.Media, pkt *rtp.Packet, ntp time.Time) error

WritePacketRTPWithNTP writes a RTP packet to all the readers of the stream. ntp is the absolute timestamp of the packet, and is sent with periodic RTCP sender reports.

type ServerStreamStats ΒΆ

type ServerStreamStats struct {
	// sent bytes
	BytesSent uint64
	// number of sent RTP packets
	RTPPacketsSent uint64
	// number of sent RTCP packets
	RTCPPacketsSent uint64

	// media statistics
	Medias map[*description.Media]ServerStreamStatsMedia
}

ServerStreamStats are stream statistics.

type ServerStreamStatsFormat ΒΆ

type ServerStreamStatsFormat struct {
	// number of sent RTP packets
	RTPPacketsSent uint64
	// local SSRC
	LocalSSRC uint32
}

ServerStreamStatsFormat are stream format statistics.

type ServerStreamStatsMedia ΒΆ

type ServerStreamStatsMedia struct {
	// sent bytes
	BytesSent uint64
	// number of sent RTCP packets
	RTCPPacketsSent uint64

	// format statistics
	Formats map[format.Format]ServerStreamStatsFormat
}

ServerStreamStatsMedia are stream media statistics.

type SessionStats ΒΆ

type SessionStats struct {
	// received bytes
	BytesReceived uint64
	// sent bytes
	BytesSent uint64
	// number of RTP packets correctly received and processed
	RTPPacketsReceived uint64
	// number of sent RTP packets
	RTPPacketsSent uint64
	// number of lost RTP packets
	RTPPacketsLost uint64
	// number of RTP packets that could not be processed
	RTPPacketsInError uint64
	// mean jitter of received RTP packets
	RTPPacketsJitter float64
	// number of RTCP packets correctly received and processed
	RTCPPacketsReceived uint64
	// number of sent RTCP packets
	RTCPPacketsSent uint64
	// number of RTCP packets that could not be processed
	RTCPPacketsInError uint64

	// media statistics
	Medias map[*description.Media]SessionStatsMedia
}

SessionStats are session statistics.

type SessionStatsFormat ΒΆ

type SessionStatsFormat struct {
	// number of RTP packets correctly received and processed
	RTPPacketsReceived uint64
	// number of sent RTP packets
	RTPPacketsSent uint64
	// number of lost RTP packets
	RTPPacketsLost uint64
	// mean jitter of received RTP packets
	RTPPacketsJitter float64
	// local SSRC
	LocalSSRC uint32
	// remote SSRC
	RemoteSSRC uint32
	// last sequence number of incoming/outgoing RTP packets
	RTPPacketsLastSequenceNumber uint16
	// last RTP time of incoming/outgoing RTP packets
	RTPPacketsLastRTP uint32
	// last NTP time of incoming/outgoing NTP packets
	RTPPacketsLastNTP time.Time
}

SessionStatsFormat are session format statistics.

type SessionStatsMedia ΒΆ

type SessionStatsMedia struct {
	// received bytes
	BytesReceived uint64
	// sent bytes
	BytesSent uint64
	// number of RTP packets that could not be processed
	RTPPacketsInError uint64
	// number of RTCP packets correctly received and processed
	RTCPPacketsReceived uint64
	// number of sent RTCP packets
	RTCPPacketsSent uint64
	// number of RTCP packets that could not be processed
	RTCPPacketsInError uint64

	// format statistics
	Formats map[format.Format]SessionStatsFormat
}

SessionStatsMedia are session media statistics.

type SessionTransport ΒΆ

type SessionTransport struct {
	Protocol Protocol
	Profile  headers.TransportProfile
}

SessionTransport contains details about the transport of a session.

type Tunnel ΒΆ

type Tunnel int

Tunnel is a tunneling method.

const (
	TunnelNone Tunnel = iota
	TunnelHTTP
	TunnelWebSocket
)

tunneling methods.

Directories ΒΆ

Path Synopsis
examples
client-play command
Package main contains an example.
Package main contains an example.
client-play-backchannel command
Package main contains an example.
Package main contains an example.
client-play-format-av1 command
Package main contains an example.
Package main contains an example.
client-play-format-av1-to-jpeg command
Package main contains an example.
Package main contains an example.
client-play-format-g711 command
Package main contains an example.
Package main contains an example.
client-play-format-h264 command
Package main contains an example.
Package main contains an example.
client-play-format-h264-mpeg4audio-to-disk command
Package main contains an example.
Package main contains an example.
client-play-format-h264-to-disk command
Package main contains an example.
Package main contains an example.
client-play-format-h264-to-jpeg command
Package main contains an example.
Package main contains an example.
client-play-format-h265 command
Package main contains an example.
Package main contains an example.
client-play-format-h265-to-disk command
Package main contains an example.
Package main contains an example.
client-play-format-h265-to-jpeg command
Package main contains an example.
Package main contains an example.
client-play-format-lpcm command
Package main contains an example.
Package main contains an example.
client-play-format-mjpeg command
Package main contains an example.
Package main contains an example.
client-play-format-mpeg4audio command
Package main contains an example.
Package main contains an example.
client-play-format-mpeg4audio-to-disk command
Package main contains an example.
Package main contains an example.
client-play-format-opus command
Package main contains an example.
Package main contains an example.
client-play-format-opus-to-disk command
Package main contains an example.
Package main contains an example.
client-play-format-vp8 command
Package main contains an example.
Package main contains an example.
client-play-format-vp9 command
Package main contains an example.
Package main contains an example.
client-play-options command
Package main contains an example.
Package main contains an example.
client-play-pause command
Package main contains an example.
Package main contains an example.
client-play-timestamp command
Package main contains an example.
Package main contains an example.
client-play-to-record command
Package main contains an example.
Package main contains an example.
client-query command
Package main contains an example.
Package main contains an example.
client-record-format-av1 command
Package main contains an example.
Package main contains an example.
client-record-format-g711 command
Package main contains an example.
Package main contains an example.
client-record-format-h264 command
Package main contains an example.
Package main contains an example.
client-record-format-h264-from-disk command
Package main contains an example.
Package main contains an example.
client-record-format-h265 command
Package main contains an example.
Package main contains an example.
client-record-format-lpcm command
Package main contains an example.
Package main contains an example.
client-record-format-mjpeg command
Package main contains an example.
Package main contains an example.
client-record-format-mpeg4audio command
Package main contains an example.
Package main contains an example.
client-record-format-opus command
Package main contains an example.
Package main contains an example.
client-record-format-vp8 command
Package main contains an example.
Package main contains an example.
client-record-format-vp9 command
Package main contains an example.
Package main contains an example.
client-record-options command
Package main contains an example.
Package main contains an example.
client-record-pause command
Package main contains an example.
Package main contains an example.
proxy command
Package main contains an example.
Package main contains an example.
proxy-backchannel command
Package main contains an example.
Package main contains an example.
server command
Package main contains an example.
Package main contains an example.
server-auth command
Package main contains an example.
Package main contains an example.
server-play-backchannel command
Package main contains an example.
Package main contains an example.
server-play-format-h264-from-disk command
Package main contains an example.
Package main contains an example.
server-record-format-h264-to-disk command
Package main contains an example.
Package main contains an example.
server-secure command
Package main contains an example.
Package main contains an example.
internal
asyncprocessor
Package asyncprocessor contains an asynchronous processor.
Package asyncprocessor contains an asynchronous processor.
base64streamreader
Package base64streamreader contains a base64 reader for a stream-based connection.
Package base64streamreader contains a base64 reader for a stream-based connection.
pkg
auth
Package auth contains utilities to perform authentication.
Package auth contains utilities to perform authentication.
base
Package base contains the primitives of the RTSP protocol.
Package base contains the primitives of the RTSP protocol.
bytecounter
Package bytecounter contains a io.ReadWriter wrapper that allows to count read and written bytes.
Package bytecounter contains a io.ReadWriter wrapper that allows to count read and written bytes.
conn
Package conn contains a RTSP connection implementation.
Package conn contains a RTSP connection implementation.
description
Package description contains objects to describe streams.
Package description contains objects to describe streams.
format
Package format contains RTP format definitions, decoders and encoders.
Package format contains RTP format definitions, decoders and encoders.
format/rtpac3
Package rtpac3 contains a RTP/AC-3 decoder and encoder.
Package rtpac3 contains a RTP/AC-3 decoder and encoder.
format/rtpav1
Package rtpav1 contains a RTP/AV1 decoder and encoder.
Package rtpav1 contains a RTP/AV1 decoder and encoder.
format/rtpfragmented
Package rtpfragmented contains a RTP decoder and encoder for codecs with access units that can be fragmented.
Package rtpfragmented contains a RTP decoder and encoder for codecs with access units that can be fragmented.
format/rtph264
Package rtph264 contains a RTP/H264 decoder and encoder.
Package rtph264 contains a RTP/H264 decoder and encoder.
format/rtph265
Package rtph265 contains a RTP/H265 decoder and encoder.
Package rtph265 contains a RTP/H265 decoder and encoder.
format/rtpklv
Package rtpklv contains a RTP decoder and encoder for KLV data.
Package rtpklv contains a RTP decoder and encoder for KLV data.
format/rtplpcm
Package rtplpcm contains a RTP/LPCM decoder and encoder.
Package rtplpcm contains a RTP/LPCM decoder and encoder.
format/rtpmjpeg
Package rtpmjpeg contains a RTP/M-JPEG decoder and encoder.
Package rtpmjpeg contains a RTP/M-JPEG decoder and encoder.
format/rtpmpeg1audio
Package rtpmpeg1audio contains a RTP/MPEG-1/2 Audio decoder and encoder.
Package rtpmpeg1audio contains a RTP/MPEG-1/2 Audio decoder and encoder.
format/rtpmpeg1video
Package rtpmpeg1video contains a RTP/MPEG-1/2 Video decoder and encoder.
Package rtpmpeg1video contains a RTP/MPEG-1/2 Video decoder and encoder.
format/rtpmpeg4audio
Package rtpmpeg4audio contains a RTP/MPEG-4 Audio decoder and encoder.
Package rtpmpeg4audio contains a RTP/MPEG-4 Audio decoder and encoder.
format/rtpsimpleaudio
Package rtpsimpleaudio contains a RTP decoder and encoder for audio codecs that fit in a single packet.
Package rtpsimpleaudio contains a RTP decoder and encoder for audio codecs that fit in a single packet.
format/rtpvp8
Package rtpvp8 contains a RTP/VP8 decoder and encoder.
Package rtpvp8 contains a RTP/VP8 decoder and encoder.
format/rtpvp9
Package rtpvp9 contains a RTP/VP9 decoder and encoder.
Package rtpvp9 contains a RTP/VP9 decoder and encoder.
headers
Package headers contains various RTSP headers.
Package headers contains various RTSP headers.
liberrors
Package liberrors contains errors returned by the library.
Package liberrors contains errors returned by the library.
mikey
Package mikey contains functions to decode and encode MIKEY messages.
Package mikey contains functions to decode and encode MIKEY messages.
multicast
Package multicast contains multicast connections.
Package multicast contains multicast connections.
ntp
Package ntp contains functions to encode and decode timestamps to/from NTP format.
Package ntp contains functions to encode and decode timestamps to/from NTP format.
readbuffer
Package readbuffer contains a function to get the read buffer size of a socket.
Package readbuffer contains a function to get the read buffer size of a socket.
ringbuffer
Package ringbuffer contains a ring buffer.
Package ringbuffer contains a ring buffer.
rtpreceiver
Package rtpreceiver contains a utility to receive RTP packets.
Package rtpreceiver contains a utility to receive RTP packets.
rtpsender
Package rtpsender contains a utility to send RTP packets.
Package rtpsender contains a utility to send RTP packets.
rtptime
Package rtptime contains a time decoder.
Package rtptime contains a time decoder.
sdp
Package sdp contains a SDP encoder/decoder compatible with most RTSP implementations.
Package sdp contains a SDP encoder/decoder compatible with most RTSP implementations.