mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 14:52:46 +08:00
add docs
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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),
|
||||
|
@@ -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 == "" {
|
||||
|
@@ -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
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Request is a RTSP request.
|
||||
type Request struct {
|
||||
Method string
|
||||
Url string
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Response is a RTSP response.
|
||||
type Response struct {
|
||||
StatusCode int
|
||||
Status string
|
||||
|
Reference in New Issue
Block a user