rtsp

package
v0.0.0-...-051c27d Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// VerbDescribe        DESCRIBE          C->S             P,S        recommended
	VerbDescribe = "DESCRIBE"
	// VerbAnnounce        ANNOUNCE          C->S, S->C       P,S        optional
	VerbAnnounce = "ANNOUNCE"
	// VerbGetParameter    GET_PARAMETER     C->S, S->C       P,S        optional
	VerbGetParameter = "GET_PARAMETER"
	// VerbOptions         OPTIONS           C->S, S->C       P,S        required (S->C: optional)
	VerbOptions = "OPTIONS"
	// VerbPause           PAUSE             C->S             P,S        recommended
	VerbPause = "PAUSE"
	// VerbPlay            PLAY              C->S             P,S        required
	VerbPlay = "PLAY"
	// VerbRecord          RECORD            C->S             P,S        optional
	VerbRecord = "RECORD"
	// VerbRedirect        REDIRECT          S->C             P,S        optional
	VerbRedirect = "REDIRECT"
	// VerbSetup           SETUP             C->S             S          required
	VerbSetup = "SETUP"
	// VerbSetParameter    SET_PARAMETER     C->S, S->C       P,S        optional
	VerbSetParameter = "SET_PARAMETER"
	// VerbTeardown        TEARDOWN          C->S             P,S        required
	VerbTeardown = "TEARDOWN"
)
View Source
const (
	// ProtoTCP requests TCP as lower protocol.
	ProtoTCP = 0
	// ProtoUnicast requests UDP unicast as lower protocol.
	ProtoUnicast = 1
	// ProtoMulticast requests UDP multicast as lower protocol.
	ProtoMulticast = 2
	// ProtoHTTP opens HTTP connections with GET and POST, transmits and receives base64 encoded RTSP messages over it.
	ProtoHTTP = 3
)
View Source
const (
	// StageInit indicates initialization stage.
	StageInit = iota
	// StageReady indicates that setup of all transports is complete.
	StageReady
	// StagePlay indicates that playback is in progress.
	StagePlay
	// StagePause indicates that playback is paused.
	StagePause
	// StageDone indicates that connection is closing.
	StageDone
)
View Source
const (
	// HeaderAccept is HTTP Accept header.
	HeaderAccept = "Accept"
	// HeaderAuthenticate is HTTP WWW-Authenticate header.
	HeaderAuthenticate = "WWW-Authenticate"
	// HeaderAuthorization is HTTP Accept header.
	HeaderAuthorization = "Authorization"
	// HeaderContentLength is HTTP Content-Length header.
	HeaderContentLength = "Content-Length"
	// HeaderCSeq is RTSP CSeq header.
	HeaderCSeq = "CSeq"
	// HeaderPublic is HTTP Public header.
	HeaderPublic = "Public"
	// HeaderSession is RTSP Session header.
	HeaderSession = "Session"
	// HeaderTransport is RTSP Transport header.
	HeaderTransport = "Transport"
	// HeaderUserAgent is RTSP User-Agent header.
	HeaderUserAgent = "User-Agent"
	// HeaderXSessionCookie is HTTP X-SessionCookie header for RTSP over HTTP.
	HeaderXSessionCookie = "X-SessionCookie"
	// HeaderPragma is HTTP Pragma header.
	HeaderPragma = "Pragma"
	// HeaderCacheControl is HTTP Cache-Control header.
	HeaderCacheControl = "Cache-Control"
)
View Source
const (
	// RtspOK indicates that request has succeeded.
	RtspOK = 200
	// RtspNoContent indicates that server has successfully fulfilled the request and that there is no additional content to send in the response payload body.
	RtspNoContent = 204
	// RtspNotModified indicates that client, which made the request conditional, already has a valid representation.
	RtspNotModified = 304
	// RtspUnauthorized indicates that clients should authorize to be served complete response to current request.
	RtspUnauthorized = 401
	// RtspLowOnStorageSpace indicates insufficient storage space on server to satisfy record request.
	RtspLowOnStorageSpace = 250
	// RtspMethodNotAllowed indicates that method specified in the request is not allowed for the resource identified by the request URI.
	RtspMethodNotAllowed = 405
	// RtspParameterNotUnderstood indicates that recipient of the request does not support one or more parameters contained in the request.
	RtspParameterNotUnderstood = 451
	// RtspConferenceNotFound indicates that conference indicated by a Conference header field is unknown to the media server.
	RtspConferenceNotFound = 452
	// RtspNotEnoughBandwidth indicates that request was refused because there was insufficient bandwidth.
	RtspNotEnoughBandwidth = 453
	// RtspSessionNotFound indicates that RTSP session identifier in the Session header is missing,
	RtspSessionNotFound = 454
	// RtspMethodNotValidInThisState indicates that client or server cannot process this request in its current state.
	RtspMethodNotValidInThisState = 455
	// RtspHeaderFieldNotValidForResource indicates that server could not act on a required request header.
	RtspHeaderFieldNotValidForResource = 456
	// RtspInvalidRange indicates that Range value given is out of bounds.
	RtspInvalidRange = 457
	// RtspParameterIsReadOnly indicates that parameter to be set by SET_PARAMETER can be read but not modified.
	RtspParameterIsReadOnly = 458
	// RtspAggregateOperationNotAllowed indicates that requested method may not be applied on the URL in question since it is an aggregate (presentation) URL.
	RtspAggregateOperationNotAllowed = 459
	// RtspOnlyAggregateOperationAllowed indicates that requested method may not be applied on the URL in question since it is not an aggregate (presentation) URL.
	RtspOnlyAggregateOperationAllowed = 460
	// RtspUnsupportedTransport indicates that Transport field did not contain a supported transport specification.
	RtspUnsupportedTransport = 461
	// RtspDestinationUnreachable indicates that data transmission channel could not be established because the client address could not be reached.
	RtspDestinationUnreachable = 462
	// RtspOptionNotSupported indicates that option given in the Require or the Proxy-Require fields was not supported.
	RtspOptionNotSupported = 551
)
View Source
const (
	// Agent is user agent string for this application.
	Agent = "Ouro/1.0"
)

Variables

View Source
var (
	// ErrAuthMalformedChallenge indicates incorrectly formatted WWW-Authenticate header.
	ErrAuthMalformedChallenge = errors.New("Malformed authentication challenge header")
	// ErrAuthNotImpemented indicates missing implementation for authentication method or encryption.
	ErrAuthNotImpemented = errors.New("Missing implementation for authentication method")
)
View Source
var (
	// ErrMalformedTransport indicates trouble parsing Transport header value.
	ErrMalformedTransport = errors.New("Malformed value of Transport header")
)

Functions

func ConnectHTTP

func ConnectHTTP(verb, uri, cookie string) []byte

ConnectHTTP issues command for RTSP over HTTP wrapper.

func ReceiveHTTP

func ReceiveHTTP(rdr *Conn) error

ReceiveHTTP reads headers form the response to GET.

Types

type Conn

type Conn struct {
	Data chan RawPacket // Channel to feed incoming data and control packet to for further processing

	Proto   int
	Timeout time.Duration
	URL     *url.URL // Parsed out original URI with user credentials.
	BaseURI string   // Formatted URI without user credentials.
	// contains filtered or unexported fields
}

Conn encapsulates low level network connection and hides buffering and packetization.

func Dial

func Dial(uri string, proto int) (*Conn, error)

Dial opens RTSP connection and starts a session.

func (*Conn) AddSink

func (c *Conn) AddSink(ch byte, port int) error

AddSink creates a listener on UDP port for RTP data or control channel.

func (*Conn) Discard

func (c *Conn) Discard(n int) (discarded int, err error)

Discard skips the next n bytes, returning the number of bytes discarded.

func (*Conn) Peek

func (c *Conn) Peek(n int) ([]byte, error)

Peek returns the next n bytes without advancing the reader.

func (*Conn) ReadByte

func (c *Conn) ReadByte() (byte, error)

ReadByte reads and returns a single byte.

func (*Conn) ReadBytes

func (c *Conn) ReadBytes(n int) ([]byte, error)

ReadBytes reads requested number of bytes, returning a slice containing the data.

func (*Conn) ReadLine

func (c *Conn) ReadLine() (string, error)

ReadLine reads until the first occurrence of newline, returning a string containing the data up to and including newline.

func (*Conn) ReadUint16

func (c *Conn) ReadUint16() (data uint16, err error)

ReadUint16 reads and returns an unsigned 2-byte integer.

func (*Conn) Start

func (c *Conn) Start()

Start initiates processing of incoming packets on all UDP listeners created thus far.

func (*Conn) Stop

func (c *Conn) Stop()

Stop tells all UDP listeners to suspend processing and close. The list of listerners is reset.

func (*Conn) Write

func (c *Conn) Write(p []byte) (n int, err error)

type Digest

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

Digest encapsulates all information necessary to perform digest authentication against a remote site.

func NewDigest

func NewDigest(uri, challenge string) (*Digest, error)

NewDigest parses challenge and creates a new basic/digest authentication processor.

func (*Digest) Authenticate

func (d *Digest) Authenticate(username, password string) DigestAuth

Authenticate creates value for Authorization header.

func (*Digest) Next

func (d *Digest) Next()

Next increments session count and generates new cnonce.

type DigestAuth

type DigestAuth func(verb string, body []byte) string

DigestAuth is function to call to encoude authorization for a particular verb in session.

type Feed

type Feed struct {
	sdp.Media

	IsSet bool
	Sets  *h264.ParameterSets
	// contains filtered or unexported fields
}

Feed represents a media feed encapsulating SDP, transport properties, channel, and utility functions.

func ParseFeeds

func ParseFeeds(proto int, buf []byte) (feeds []*Feed, err error)

ParseFeeds creates media feeds from parsed SDP body.

func (*Feed) TransportHeader

func (f *Feed) TransportHeader() string

TransportHeader returns a formatted transport header for SETUP request.

func (*Feed) TransportSetup

func (f *Feed) TransportSetup(value string) error

TransportSetup populates transport properties from response to SETUP verb.

type Headers

type Headers map[string]string

Headers facilitates passing additional headers to the RTSP command formatter.

type MessageHeader

type MessageHeader map[string]string

An MessageHeader represents a MIME-style header mapping keys to values.

func (MessageHeader) Del

func (h MessageHeader) Del(key string)

Del deletes the values associated with key.

func (MessageHeader) Get

func (h MessageHeader) Get(key string) string

Get gets the first value associated with the given key.

func (MessageHeader) Set

func (h MessageHeader) Set(key string, value string)

Set sets the header associated with key to the given value.

type Pair

type Pair struct {
	One int
	Two int
}

Pair represents a pair of channels or ports.

func ParsePair

func ParsePair(val string) (p Pair, err error)

ParsePair parses a pair of channels or ports in transport header.

func (Pair) String

func (p Pair) String() string

String formats a pair of integers into channels or ports in transport header.

type Queue

type Queue map[int]*Request

Queue tracks outgoing requests that have not yet been responded to.

type RawPacket

type RawPacket struct {
	Channel byte
	Payload []byte
}

RawPacket represents channel number and raw data buffer of RTP/RTCP packet.

type Request

type Request struct {
	Verb    string
	Cseq    int
	URI     string
	Auth    string
	Session string
	Header  MessageHeader
}

Request encapsulates verb, uri, and headers for RTSP command.

func (*Request) Pack

func (r *Request) Pack() []byte

Pack request into RTSP message.

type Response

type Response struct {
	Proto         string
	Status        string
	StatusCode    int
	ContentLength int64
	Cseq          int
	Header        MessageHeader
	Body          []byte
}

Response encapsulates RTSP response. It is modeled by http.Response but includes only what is needed to handle RTSP.

func Unpack

func Unpack(rdr *Conn) (*Response, error)

Unpack RTSP message into response structure.

func (Response) Pack

func (r Response) Pack() []byte

Pack response into RTSP message.

type Session

type Session struct {
	*Conn
	sync.Mutex

	State chan int // Stage signaller.
	// contains filtered or unexported fields
}

Session maintains RTSP session and workflow.

func NewSession

func NewSession() *Session

NewSession returns new RTSP session manager.

func (*Session) Describe

func (s *Session) Describe() error

Describe handles DESCRIBE request in RTSP and parses SDP data in response.

func (*Session) KeepAlive

func (s *Session) KeepAlive() error

KeepAlive executes OPTIONS on a regular basis to keep connection alive. RTP over TCP does not need keep-alive messages according to RFC.

func (*Session) Open

func (s *Session) Open(uri string, proto int) error

Open to an RTSP source.

func (*Session) Options

func (s *Session) Options() error

Options handles client OPTIONS request in RTSP.

func (*Session) Pause

func (s *Session) Pause() error

Pause handles client PAUSE request in RTSP.

func (*Session) Play

func (s *Session) Play() error

Play handles client PLAY request in RTSP.

func (*Session) Setup

func (s *Session) Setup() error

Setup issues SETUP command for all playable media.

func (*Session) Teardown

func (s *Session) Teardown() error

Teardown handles client TEARDOWN request in RTSP.

type Transport

type Transport struct {
	IsTCP         bool
	IsMulticast   bool
	IsInterleaved bool
	IsAppend      bool
	Interleave    Pair
	Port          Pair
	ClientPort    Pair
	ServerPort    Pair
	Layers        int
	TTL           int
	Destination   string
	Source        string
	SSRC          string
	Mode          string
}

Transport encapsulates RTSP transport header information.

func NewTransport

func NewTransport(proto int, port int) *Transport

NewTransport creates default transport for media.

func (*Transport) Parse

func (t *Transport) Parse(value string) (err error)

Parse transport header into constituent parts.

func (Transport) String

func (t Transport) String() string

String formats transport parameters into a value for respective RTSP header.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL