rtsp

package module
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 9 Imported by: 0

README

RTSP 1.0

A low level package for writing rtsp servers and clients

Supports:

  • Interleaved data frames.
  • Basic/Digest authentication.
  • RTP decoding.

Documentation

Index

Constants

View Source
const (
	MethodAnnounce     = "ANNOUNCE"
	MethodDescribe     = "DESCRIBE"
	MethodGetParameter = "GET_PARAMETER"
	MethodOptions      = "OPTIONS"
	MethodPause        = "PAUSE"
	MethodPlay         = "PLAY"
	MethodRecord       = "RECORD"
	MethodRedirect     = "REDIRECT"
	MethodSetParameter = "SET_PARAMETER"
	MethodSetup        = "SETUP"
	MethodTeardown     = "TEARDOWN"
)

RTSP Verbs

View Source
const (
	StatusContinue                      = 100
	StatusOK                            = 200
	StatusCreated                       = 201
	StatusLowOnStorageSpace             = 250
	StatusMultipleChoices               = 300
	StatusMovedPermanently              = 301
	StatusMovedTemporarily              = 302
	StatusSeeOther                      = 303
	StatusNotModified                   = 304
	StatusUseProxy                      = 305
	StatusBadRequest                    = 400
	StatusUnauthorized                  = 401
	StatusPaymentRequired               = 402
	StatusForbidden                     = 403
	StatusNotFound                      = 404
	StatusMethodNotAllowed              = 405
	StatusNotAcceptable                 = 406
	StatusProxyAuthenticationRequired   = 407
	StatusRequestTimeout                = 408
	StatusGone                          = 410
	StatusLengthRequired                = 411
	StatusPreconditionFailed            = 412
	StatusRequestEntityTooLarge         = 413
	StatusRequestURITooLong             = 414
	StatusUnsupportedMediaType          = 415
	StatusInvalidparameter              = 451
	StatusIllegalConferenceIdentifier   = 452
	StatusNotEnoughBandwidth            = 453
	StatusSessionNotFound               = 454
	StatusMethodNotValidInThisState     = 455
	StatusHeaderFieldNotValid           = 456
	StatusInvalidRange                  = 457
	StatusParameterIsReadOnly           = 458
	StatusAggregateOperationNotAllowed  = 459
	StatusOnlyAggregateOperationAllowed = 460
	StatusUnsupportedTransport          = 461
	StatusDestinationUnreachable        = 462
	StatusInternalServerError           = 500
	StatusNotImplemented                = 501
	StatusBadGateway                    = 502
	StatusServiceUnavailable            = 503
	StatusGatewayTimeout                = 504
	StatusRTSPVersionNotSupported       = 505
	StatusOptionNotsupport              = 551
)

RTSP response status codes

Variables

This section is empty.

Functions

func IsFrame added in v0.3.0

func IsFrame(r *bufio.Reader) (bool, error)

IsFrame returns true when the next message is an interleaved frame. This will block until at least one byte is available in the reader

func Session

func Session(res *Response) (string, error)

Session parses the session id from a SETUP response.

func StatusText added in v0.5.0

func StatusText(code int) string

StatusText returns a text of the RTSP status code. It returns the empty string if the code is unknown

Types

type Auth

type Auth interface {
	// Authorize the request given the response
	// This is called once before the request is send with a nil Response
	// and a second time if the response came back with status code 401
	// unauthorized
	Authorize(*Request, *Response) (bool, error)
}

Auth provides a mechanism for authenticating requests. Implementations may be found in the auth subpackage.

type Client

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

Client allows sending and recieving rtsp data over a socket connection.

func NewClient

func NewClient(conn io.ReadWriter, options ...Option) *Client

NewClient constructs an rtsp Client wrapping a connection.

func (*Client) Describe

func (c *Client) Describe(endpoint string) (*Response, error)

Describe is a helper method for sending an DESCRIBE request.

func (*Client) Do

func (c *Client) Do(req *Request) (*Response, error)

Do sends a request and reads the response.

func (*Client) Options

func (c *Client) Options(endpoint string) (*Response, error)

Options is a helper method for sending an OPTIONS request.

func (*Client) Play

func (c *Client) Play(endpoint, session string) (*Response, error)

Play is a helper method for sending a PLAY request.

func (*Client) Setup

func (c *Client) Setup(endpoint, transport string) (*Response, error)

Setup is a helper method for sending a SETUP request.

func (*Client) Teardown

func (c *Client) Teardown(endpoint, session string) (*Response, error)

Teardown is a helper method for sending a TEARDOWN request.

type Frame

type Frame struct {
	Channel int
	Data    []byte
}

Frame of interleaved binary data. This is encoded in RTP format.

func ReadFrame

func ReadFrame(r io.Reader) (Frame, error)

ReadFrame reads an interleaved binary frame from the reader.

func (Frame) Write

func (f Frame) Write(w io.Writer) error

Write the interleaved frame to the provided writer.

type Header map[string][]string

Header is a collection of key/value pairs belonging to a request or response.

func ReadHeader added in v0.2.0

func ReadHeader(r *bufio.Reader) (Header, error)

ReadHeader reads headers from the provided reader

func (Header) Add added in v0.9.0

func (h Header) Add(name, value string)

Add adds the header value

func (Header) Clone added in v0.2.0

func (h Header) Clone() Header

Clone returns a copy of the headers

func (Header) Field added in v0.8.0

func (h Header) Field(name string, index int) (string, bool)

Field looks up the header by name and returns the field for the provided index. The expected format is field1;field2;field3 ...

func (Header) Get added in v0.9.0

func (h Header) Get(name string) string

Get returns the first header value with the provided name. If not found, an empty string is returned.

func (Header) Param added in v0.8.0

func (h Header) Param(name, key string) (string, bool)

Param looks up the header by name and returns the corresponding value for the provided key. The expected format is key1=value1;key2=value2 ...

func (Header) Set added in v0.9.0

func (h Header) Set(name, value string)

Set sets the header value

func (Header) Write added in v0.2.0

func (h Header) Write(w io.Writer) error

Write the header key/values to the provided writer

type Option

type Option func(*Client)

Option configures a client.

func WithAuth

func WithAuth(a Auth) Option

WithAuth configures the client authentication.

func WithFrameHandler

func WithFrameHandler(handler func(Frame) error) Option

WithFrameHandler sets a callback for incoming interleaved binary frames.

func WithUserAgent

func WithUserAgent(userAgent string) Option

WithUserAgent specifies the user-agent to be sent with each request.

type Request

type Request struct {
	Method string
	URL    *url.URL
	Header Header
	Body   []byte
}

Request contains all the information required to send a request

func NewRequest

func NewRequest(method, endpoint string, body []byte) (*Request, error)

NewRequest constructs a new request. The endpoint must be an absolute url. The body may be nil.

func ReadRequest

func ReadRequest(r *bufio.Reader) (req *Request, err error)

ReadRequest reads and parses an RTSP request from the provided reader.

func (Request) String

func (r Request) String() string

String returns a string representation of the request.

func (Request) Write

func (r Request) Write(w io.Writer) error

Write the request to the provided writer in the wire format.

type Response

type Response struct {
	StatusCode int
	Status     string
	Header     Header
	Body       []byte
}

Response is a parsed RTSP response.

func NewResponse

func NewResponse(code int, body []byte) (*Response, error)

NewResponse constructs a new response. The body may be nil.

func ReadResponse

func ReadResponse(r *bufio.Reader) (res *Response, err error)

ReadResponse reads and parses an RTSP response from the provided reader.

func (Response) Err added in v0.8.0

func (res Response) Err() error

Err returns an error containing the status text if the status code is not 2xx

func (Response) String

func (res Response) String() string

String returns the string representation of the response.

func (Response) Write

func (res Response) Write(w io.Writer) error

Write the response to the provided writer in wire format.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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