diff --git a/connclient.go b/connclient.go index 21a50064..878bbfc5 100644 --- a/connclient.go +++ b/connclient.go @@ -6,6 +6,7 @@ import ( "strconv" ) +// ConnClient is a client-side RTSP connection. type ConnClient struct { nconn net.Conn br *bufio.Reader @@ -16,6 +17,7 @@ type ConnClient struct { authProv *authClientProvider } +// NewConnClient allocates a ConnClient. func NewConnClient(nconn net.Conn) *ConnClient { return &ConnClient{ nconn: nconn, @@ -24,22 +26,29 @@ func NewConnClient(nconn net.Conn) *ConnClient { } } +// NetConn returns the underlying new.Conn. func (c *ConnClient) NetConn() net.Conn { return c.nconn } +// SetSession sets a Session header that is automatically inserted into every outgoing request. func (c *ConnClient) SetSession(v string) { c.session = v } +// EnableCseq allows to automatically insert the CSeq header into every outgoing request. +// CSeq is incremented after every request. func (c *ConnClient) EnableCseq() { c.cseqEnabled = true } +// SetCredentials allows to automatically insert Authenticate header into every outgoing request. +// The content of the header is computed with the given user, password, realm and nonce. func (c *ConnClient) SetCredentials(user string, pass string, realm string, nonce string) { c.authProv = newAuthClientProvider(user, pass, realm, nonce) } +// WriteRequest writes a Request. func (c *ConnClient) WriteRequest(req *Request) error { if c.session != "" { if req.Header == nil { @@ -63,14 +72,17 @@ func (c *ConnClient) WriteRequest(req *Request) error { return req.write(c.bw) } +// ReadResponse reads a response. func (c *ConnClient) ReadResponse() (*Response, error) { return readResponse(c.br) } +// ReadInterleavedFrame reads an InterleavedFrame. func (c *ConnClient) ReadInterleavedFrame() (*InterleavedFrame, error) { return readInterleavedFrame(c.br) } +// WriteInterleavedFrame writes an InterleavedFrame. func (c *ConnClient) WriteInterleavedFrame(frame *InterleavedFrame) error { return frame.write(c.bw) } diff --git a/connserver.go b/connserver.go index 07738231..ed103a64 100644 --- a/connserver.go +++ b/connserver.go @@ -5,12 +5,14 @@ import ( "net" ) +// ConnServer is a server-side RTSP connection. type ConnServer struct { nconn net.Conn br *bufio.Reader bw *bufio.Writer } +// NewConnServer allocates a ConnClient. func NewConnServer(nconn net.Conn) *ConnServer { return &ConnServer{ nconn: nconn, @@ -19,22 +21,27 @@ func NewConnServer(nconn net.Conn) *ConnServer { } } +// NetConn returns the underlying new.Conn. func (s *ConnServer) NetConn() net.Conn { return s.nconn } +// ReadRequest reads a Request. func (s *ConnServer) ReadRequest() (*Request, error) { return readRequest(s.br) } +// WriteResponse writes a response. func (s *ConnServer) WriteResponse(res *Response) error { return res.write(s.bw) } +// ReadInterleavedFrame reads an InterleavedFrame. func (s *ConnServer) ReadInterleavedFrame() (*InterleavedFrame, error) { return readInterleavedFrame(s.br) } +// WriteInterleavedFrame writes an InterleavedFrame. func (s *ConnServer) WriteInterleavedFrame(frame *InterleavedFrame) error { return frame.write(s.bw) } diff --git a/header.go b/header.go index c06574da..787648f0 100644 --- a/header.go +++ b/header.go @@ -12,6 +12,7 @@ const ( _MAX_HEADER_VALUE_LENGTH = 255 ) +// Header is a RTSP reader, present in both Requests and Responses. type Header map[string][]string func readHeader(rb *bufio.Reader) (Header, error) { diff --git a/headerauth.go b/headerauth.go index 063b9ce0..baa56b3c 100644 --- a/headerauth.go +++ b/headerauth.go @@ -6,11 +6,13 @@ import ( "strings" ) +// HeaderAuth is an Authenticate or a WWWW-Authenticate header. type HeaderAuth struct { Prefix string Values map[string]string } +// ReadHeaderAuth parses an Authenticate or a WWW-Authenticate header. func ReadHeaderAuth(in string) (*HeaderAuth, error) { a := &HeaderAuth{ Values: make(map[string]string), diff --git a/headertransport.go b/headertransport.go index ca0ab2a3..2be81f80 100644 --- a/headertransport.go +++ b/headertransport.go @@ -5,8 +5,10 @@ import ( "strings" ) +// HeaderTransport is a Transport header. type HeaderTransport map[string]struct{} +// ReadHeaderTransport parses a Transport header. func ReadHeaderTransport(in string) HeaderTransport { th := make(map[string]struct{}) for _, t := range strings.Split(in, ";") { @@ -15,6 +17,7 @@ func ReadHeaderTransport(in string) HeaderTransport { return th } +// GetValue gets a value from the header. func (th HeaderTransport) GetValue(key string) string { prefix := key + "=" for t := range th { @@ -25,6 +28,7 @@ func (th HeaderTransport) GetValue(key string) string { return "" } +// GetPorts gets a given header value and parses its ports. func (th HeaderTransport) GetPorts(key string) (int, int) { val := th.GetValue(key) if val == "" { diff --git a/interleavedframe.go b/interleavedframe.go index 07e6aa72..59a0b29b 100644 --- a/interleavedframe.go +++ b/interleavedframe.go @@ -12,6 +12,8 @@ const ( _INTERLEAVED_FRAME_MAX_CONTENT_SIZE = (_INTERLEAVED_FRAME_MAX_SIZE - 4) ) +// InterleavedFrame is a wrapper for sending and receiving binary data into RTSP connections. +// It is usually used to send RTP and RTCP with RTSP. type InterleavedFrame struct { Channel uint8 Content []byte diff --git a/request.go b/request.go index e84d9aa9..5d847a81 100644 --- a/request.go +++ b/request.go @@ -5,6 +5,7 @@ import ( "fmt" ) +// Request is a RTSP request. type Request struct { Method string Url string diff --git a/response.go b/response.go index 8fc1e5f6..a422a794 100644 --- a/response.go +++ b/response.go @@ -6,6 +6,7 @@ import ( "strconv" ) +// Response is a RTSP response. type Response struct { StatusCode int Status string