Documentation ¶
Overview ¶
Package gortsplib is a RTSP 1.0 library for the Go programming language, written for rtsp-simple-server.
Examples are available at https://github.com/majoyz/gortsplib/tree/master/examples
Index ¶
- Variables
- type ClientConf
- type ClientConn
- func (c *ClientConn) Announce(u *base.URL, tracks Tracks) (*base.Response, error)
- func (c *ClientConn) Close() error
- func (c *ClientConn) Describe(u *base.URL) (Tracks, *base.Response, error)
- func (c *ClientConn) Do(req *base.Request) (*base.Response, error)
- func (c *ClientConn) NetConn() net.Conn
- func (c *ClientConn) Options(u *base.URL) (*base.Response, error)
- func (c *ClientConn) Pause() (*base.Response, error)
- func (c *ClientConn) Play() (*base.Response, error)
- func (c *ClientConn) RTPInfo() *headers.RTPInfo
- func (c *ClientConn) ReadFrames(onFrame func(int, StreamType, []byte)) chan error
- func (c *ClientConn) Record() (*base.Response, error)
- func (c *ClientConn) Setup(mode headers.TransportMode, track *Track, rtpPort int, rtcpPort int) (*base.Response, error)
- func (c *ClientConn) Tracks() Tracks
- func (c *ClientConn) WriteFrame(trackID int, streamType StreamType, payload []byte) error
- type Server
- type ServerConf
- type ServerConn
- func (sc *ServerConn) AnnouncedTracks() []ServerConnAnnouncedTrack
- func (sc *ServerConn) Close() error
- func (sc *ServerConn) NetConn() net.Conn
- func (sc *ServerConn) Read(readHandlers ServerConnReadHandlers) chan error
- func (sc *ServerConn) SetuppedTracks() map[int]ServerConnSetuppedTrack
- func (sc *ServerConn) State() ServerConnState
- func (sc *ServerConn) StreamProtocol() *StreamProtocol
- func (sc *ServerConn) WriteFrame(trackID int, streamType StreamType, payload []byte)
- type ServerConnAnnounceCtx
- type ServerConnAnnouncedTrack
- type ServerConnDescribeCtx
- type ServerConnGetParameterCtx
- type ServerConnOptionsCtx
- type ServerConnPauseCtx
- type ServerConnPlayCtx
- type ServerConnReadHandlers
- type ServerConnRecordCtx
- type ServerConnSetParameterCtx
- type ServerConnSetupCtx
- type ServerConnSetuppedTrack
- type ServerConnState
- type ServerConnTeardownCtx
- type StreamProtocol
- type StreamType
- type Track
- type Tracks
Constants ¶
This section is empty.
Variables ¶
var DefaultClientConf = ClientConf{}
DefaultClientConf is the default ClientConf.
var DefaultServerConf = ServerConf{}
DefaultServerConf is the default ServerConf.
Functions ¶
This section is empty.
Types ¶
type ClientConf ¶
type ClientConf struct { // the stream protocol (UDP or TCP). // If nil, it is chosen automatically (first UDP, then, if it fails, TCP). // It defaults to nil. StreamProtocol *StreamProtocol // a TLS configuration to connect to TLS (RTSPS) servers. // It defaults to &tls.Config{InsecureSkipVerify:true} TLSConfig *tls.Config // disable being redirected to other servers, that can happen during Describe(). // It defaults to false. RedirectDisable bool // enable communication with servers which don't provide server ports. // this can be a security issue. // It defaults to false. AnyPortEnable bool // 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 buffer count. // If greater than 1, allows to pass buffers to routines different than the one // that is reading frames. // It defaults to 1. ReadBufferCount int // read buffer size. // This must be touched only when the server reports problems about buffer sizes. // It defaults to 2048. ReadBufferSize int // callback called before every request. OnRequest func(req *base.Request) // callback called after very response. OnResponse func(res *base.Response) // function used to initialize the TCP client. // It defaults to net.DialTimeout. DialTimeout func(network, address string, timeout time.Duration) (net.Conn, error) // function used to initialize UDP listeners. // It defaults to net.ListenPacket. ListenPacket func(network, address string) (net.PacketConn, error) }
ClientConf allows to initialize a ClientConn. All fields are optional.
func (ClientConf) Dial ¶
func (c ClientConf) Dial(scheme string, host string) (*ClientConn, error)
Dial connects to a server.
func (ClientConf) DialPublish ¶
func (c ClientConf) DialPublish(address string, tracks Tracks) (*ClientConn, error)
DialPublish connects to the address and starts publishing the tracks.
func (ClientConf) DialRead ¶
func (c ClientConf) DialRead(address string) (*ClientConn, error)
DialRead connects to the address and starts reading all tracks.
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
ClientConn is a client-side RTSP connection.
func DialPublish ¶
func DialPublish(address string, tracks Tracks) (*ClientConn, error)
DialPublish connects to a server and starts publishing the tracks.
func DialRead ¶
func DialRead(address string) (*ClientConn, error)
DialRead connects to a server and starts reading all tracks.
func (*ClientConn) Close ¶
func (c *ClientConn) Close() error
Close closes all the ClientConn resources.
func (*ClientConn) Do ¶
Do writes a Request and reads a Response. Interleaved frames received before the response are ignored.
func (*ClientConn) NetConn ¶
func (c *ClientConn) NetConn() net.Conn
NetConn returns the underlying net.Conn.
func (*ClientConn) Pause ¶
func (c *ClientConn) Pause() (*base.Response, error)
Pause writes a PAUSE request and reads a Response. This can be called only after Play() or Record().
func (*ClientConn) Play ¶
func (c *ClientConn) Play() (*base.Response, error)
Play writes a PLAY request and reads a Response. This can be called only after Setup().
func (*ClientConn) RTPInfo ¶
func (c *ClientConn) RTPInfo() *headers.RTPInfo
RTPInfo returns the RTP-Info header sent by the server in the PLAY response.
func (*ClientConn) ReadFrames ¶
func (c *ClientConn) ReadFrames(onFrame func(int, StreamType, []byte)) chan error
ReadFrames starts reading frames. it returns a channel that is written when the reading stops. This can be called only after Play().
func (*ClientConn) Record ¶
func (c *ClientConn) Record() (*base.Response, error)
Record writes a RECORD request and reads a Response. This can be called only after Announce() and Setup().
func (*ClientConn) Setup ¶
func (c *ClientConn) Setup(mode headers.TransportMode, track *Track, rtpPort int, rtcpPort int) (*base.Response, error)
Setup writes a SETUP request and reads a Response. rtpPort and rtcpPort are used only if protocol is UDP. if rtpPort and rtcpPort are zero, they are chosen automatically.
func (*ClientConn) Tracks ¶
func (c *ClientConn) Tracks() Tracks
Tracks returns all the tracks that the connection is reading or publishing.
func (*ClientConn) WriteFrame ¶
func (c *ClientConn) WriteFrame(trackID int, streamType StreamType, payload []byte) error
WriteFrame writes a frame. This can be called only after Record().
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a RTSP server.
type ServerConf ¶
type ServerConf struct { // a TLS configuration to accept TLS (RTSPS) connections. TLSConfig *tls.Config // a port to send and receive UDP/RTP packets. // If UDPRTPAddress and UDPRTCPAddress are != "", the server can accept and send UDP streams. UDPRTPAddress string // a port to send and receive UDP/RTCP packets. // If UDPRTPAddress and UDPRTCPAddress are != "", the server can accept and send UDP streams. UDPRTCPAddress string // 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 buffer count. // If greater than 1, allows to pass buffers to routines different than the one // that is reading frames. // It also allows to buffer routed frames and mitigate network fluctuations // that are particularly high when using UDP. // It defaults to 512 ReadBufferCount int // read buffer size. // This must be touched only when the server reports problems about buffer sizes. // It defaults to 2048. ReadBufferSize int // function used to initialize the TCP listener. // It defaults to net.Listen Listen func(network string, address string) (net.Listener, error) }
ServerConf allows to configure a Server. All fields are optional.
type ServerConn ¶
type ServerConn struct {
// contains filtered or unexported fields
}
ServerConn is a server-side RTSP connection.
func (*ServerConn) AnnouncedTracks ¶
func (sc *ServerConn) AnnouncedTracks() []ServerConnAnnouncedTrack
AnnouncedTracks returns the announced tracks.
func (*ServerConn) Close ¶
func (sc *ServerConn) Close() error
Close closes all the connection resources.
func (*ServerConn) NetConn ¶
func (sc *ServerConn) NetConn() net.Conn
NetConn returns the underlying net.Conn.
func (*ServerConn) Read ¶
func (sc *ServerConn) Read(readHandlers ServerConnReadHandlers) chan error
Read starts reading requests and frames. it returns a channel that is written when the reading stops.
func (*ServerConn) SetuppedTracks ¶
func (sc *ServerConn) SetuppedTracks() map[int]ServerConnSetuppedTrack
SetuppedTracks returns the setupped tracks.
func (*ServerConn) StreamProtocol ¶
func (sc *ServerConn) StreamProtocol() *StreamProtocol
StreamProtocol returns the stream protocol of the setupped tracks.
func (*ServerConn) WriteFrame ¶
func (sc *ServerConn) WriteFrame(trackID int, streamType StreamType, payload []byte)
WriteFrame writes a frame.
type ServerConnAnnounceCtx ¶
ServerConnAnnounceCtx is the context of a ANNOUNCE request.
type ServerConnAnnouncedTrack ¶
type ServerConnAnnouncedTrack struct {
// contains filtered or unexported fields
}
ServerConnAnnouncedTrack is an announced track of a ServerConn.
type ServerConnDescribeCtx ¶
ServerConnDescribeCtx is the context of a DESCRIBE request.
type ServerConnGetParameterCtx ¶
ServerConnGetParameterCtx is the context of a GET_PARAMETER request.
type ServerConnOptionsCtx ¶
ServerConnOptionsCtx is the context of a OPTIONS request.
type ServerConnPauseCtx ¶
ServerConnPauseCtx is the context of a PAUSE request.
type ServerConnPlayCtx ¶
ServerConnPlayCtx is the context of a PLAY request.
type ServerConnReadHandlers ¶
type ServerConnReadHandlers struct { // called after receiving any request. OnRequest func(req *base.Request) // called before sending any response. OnResponse func(res *base.Response) // called after receiving a OPTIONS request. // if nil, it is generated automatically. OnOptions func(ctx *ServerConnOptionsCtx) (*base.Response, error) // called after receiving a DESCRIBE request. // the 2nd return value is a SDP, that is inserted into the response. OnDescribe func(ctx *ServerConnDescribeCtx) (*base.Response, []byte, error) // called after receiving an ANNOUNCE request. OnAnnounce func(ctx *ServerConnAnnounceCtx) (*base.Response, error) // called after receiving a SETUP request. OnSetup func(ctx *ServerConnSetupCtx) (*base.Response, error) // called after receiving a PLAY request. OnPlay func(ctx *ServerConnPlayCtx) (*base.Response, error) // called after receiving a RECORD request. OnRecord func(ctx *ServerConnRecordCtx) (*base.Response, error) // called after receiving a PAUSE request. OnPause func(ctx *ServerConnPauseCtx) (*base.Response, error) // called after receiving a GET_PARAMETER request. // if nil, it is generated automatically. OnGetParameter func(ctx *ServerConnGetParameterCtx) (*base.Response, error) // called after receiving a SET_PARAMETER request. OnSetParameter func(ctx *ServerConnSetParameterCtx) (*base.Response, error) // called after receiving a TEARDOWN request. // if nil, it is generated automatically. OnTeardown func(ctx *ServerConnTeardownCtx) (*base.Response, error) // called after receiving a frame. OnFrame func(trackID int, streamType StreamType, payload []byte) }
ServerConnReadHandlers allows to set the handlers required by ServerConn.Read. all fields are optional.
type ServerConnRecordCtx ¶
ServerConnRecordCtx is the context of a RECORD request.
type ServerConnSetParameterCtx ¶
ServerConnSetParameterCtx is the context of a SET_PARAMETER request.
type ServerConnSetupCtx ¶
type ServerConnSetupCtx struct { Req *base.Request Path string Query string TrackID int Transport *headers.Transport }
ServerConnSetupCtx is the context of a OPTIONS request.
type ServerConnSetuppedTrack ¶
type ServerConnSetuppedTrack struct {
// contains filtered or unexported fields
}
ServerConnSetuppedTrack is a setupped track of a ServerConn.
type ServerConnState ¶
type ServerConnState int
ServerConnState is the state of the connection.
const ( ServerConnStateInitial ServerConnState = iota ServerConnStatePrePlay ServerConnStatePlay ServerConnStatePreRecord ServerConnStateRecord )
standard states.
func (ServerConnState) String ¶
func (s ServerConnState) String() string
String implements fmt.Stringer.
type ServerConnTeardownCtx ¶
ServerConnTeardownCtx is the context of a TEARDOWN request.
type StreamProtocol ¶
type StreamProtocol = base.StreamProtocol
StreamProtocol is the protocol of a stream.
const ( // StreamProtocolUDP means that the stream uses the UDP protocol StreamProtocolUDP StreamProtocol = base.StreamProtocolUDP // StreamProtocolTCP means that the stream uses the TCP protocol StreamProtocolTCP StreamProtocol = base.StreamProtocolTCP )
type StreamType ¶
type StreamType = base.StreamType
StreamType is the stream type.
const ( // StreamTypeRTP means that the stream contains RTP packets StreamTypeRTP StreamType = base.StreamTypeRTP // StreamTypeRTCP means that the stream contains RTCP packets StreamTypeRTCP StreamType = base.StreamTypeRTCP )
type Track ¶
type Track struct { // base URL BaseURL *base.URL // id ID int // codec and info in SDP format Media *psdp.MediaDescription }
Track is a track available in a certain URL.
func NewTrackAAC ¶
NewTrackAAC initializes an AAC track from a configuration.
func NewTrackH264 ¶
NewTrackH264 initializes an H264 track from a SPS and PPS.
func (*Track) ExtractDataAAC ¶
ExtractDataAAC extracts the config from an AAC track.
func (*Track) ExtractDataH264 ¶
ExtractDataH264 extracts the SPS and PPS from an H264 track.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
pkg
|
|
auth
Package auth contains utilities to perform authentication.
|
Package auth contains utilities to perform authentication. |
base
Package base contains the base elements of the RTSP protocol.
|
Package base contains the base elements of the RTSP protocol. |
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. |
multibuffer
Package multibuffer contains a buffer with multiple levels.
|
Package multibuffer contains a buffer with multiple levels. |
ringbuffer
Package ringbuffer contains a ring buffer.
|
Package ringbuffer contains a ring buffer. |
rtcpreceiver
Package rtcpreceiver contains a utility to generate RTCP receiver reports.
|
Package rtcpreceiver contains a utility to generate RTCP receiver reports. |
rtcpsender
Package rtcpsender contains a utility to generate RTCP sender reports.
|
Package rtcpsender contains a utility to generate RTCP sender reports. |
rtpaac
Package rtpaac contains a RTP/AAC decoder and encoder.
|
Package rtpaac contains a RTP/AAC decoder and encoder. |
rtph264
Package rtph264 contains a RTP/H264 decoder and encoder.
|
Package rtph264 contains a RTP/H264 decoder and encoder. |
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. |