diff --git a/client.go b/client.go index f000d2ec..0b17b034 100644 --- a/client.go +++ b/client.go @@ -29,15 +29,26 @@ func DialPublish(address string, tracks Tracks) (*ClientConn, error) { // Client is a RTSP client. type Client 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 + // + // connection + // + + // timeout of read operations. + // It defaults to 10 seconds. + ReadTimeout time.Duration + + // timeout of write operations. + // It defaults to 10 seconds. + WriteTimeout time.Duration // a TLS configuration to connect to TLS (RTSPS) servers. // It defaults to &tls.Config{InsecureSkipVerify:true} TLSConfig *tls.Config + // + // initialization + // + // disable being redirected to other servers, that can happen during Describe(). // It defaults to false. RedirectDisable bool @@ -47,19 +58,20 @@ type Client struct { // It defaults to false. AnyPortEnable bool - // timeout of read operations. - // It defaults to 10 seconds. - ReadTimeout time.Duration + // + // reading / writing + // + + // 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 // If the client is reading with UDP, it must receive // at least a packet within this timeout. // It defaults to 3 seconds. InitialUDPReadTimeout 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. @@ -71,12 +83,20 @@ type Client struct { // It defaults to 2048. ReadBufferSize int + // + // callbacks + // + // callback called before every request. OnRequest func(req *base.Request) // callback called after every response. OnResponse func(res *base.Response) + // + // system functions + // + // function used to initialize the TCP client. // It defaults to net.DialTimeout. DialTimeout func(network, address string, timeout time.Duration) (net.Conn, error) @@ -85,6 +105,10 @@ type Client struct { // It defaults to net.ListenPacket. ListenPacket func(network, address string) (net.PacketConn, error) + // + // private + // + senderReportPeriod time.Duration receiverReportPeriod time.Duration } diff --git a/clientconn.go b/clientconn.go index d57313ba..21f6af2e 100644 --- a/clientconn.go +++ b/clientconn.go @@ -104,25 +104,30 @@ type ClientConn struct { } func newClientConn(c *Client, scheme string, host string) (*ClientConn, error) { - if c.TLSConfig == nil { - c.TLSConfig = &tls.Config{InsecureSkipVerify: true} - } + // connection if c.ReadTimeout == 0 { c.ReadTimeout = 10 * time.Second } - if c.InitialUDPReadTimeout == 0 { - c.InitialUDPReadTimeout = 3 * time.Second - } if c.WriteTimeout == 0 { c.WriteTimeout = 10 * time.Second } + if c.TLSConfig == nil { + c.TLSConfig = &tls.Config{InsecureSkipVerify: true} + } + + // reading / writing + if c.InitialUDPReadTimeout == 0 { + c.InitialUDPReadTimeout = 3 * time.Second + } + if c.ReadBufferCount == 0 { c.ReadBufferCount = 1 } - if c.ReadBufferSize == 0 { c.ReadBufferSize = 2048 } + + // system functions if c.DialTimeout == nil { c.DialTimeout = net.DialTimeout } @@ -130,6 +135,7 @@ func newClientConn(c *Client, scheme string, host string) (*ClientConn, error) { c.ListenPacket = net.ListenPacket } + // private if c.senderReportPeriod == 0 { c.senderReportPeriod = 10 * time.Second } diff --git a/server.go b/server.go index 1bb28f00..3d5f0925 100644 --- a/server.go +++ b/server.go @@ -60,9 +60,25 @@ type sessionReq struct { // Server is a RTSP server. type Server struct { + // + // handler + // + // an handler to handle requests. Handler ServerHandler + // + // connection + // + + // timeout of read operations. + // It defaults to 10 seconds + ReadTimeout time.Duration + + // timeout of write operations. + // It defaults to 10 seconds + WriteTimeout time.Duration + // a TLS configuration to accept TLS (RTSPS) connections. TLSConfig *tls.Config @@ -74,13 +90,9 @@ type Server struct { // 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 + // + // reading / writing + // // read buffer count. // If greater than 1, allows to pass buffers to routines different than the one @@ -95,10 +107,18 @@ type Server struct { // It defaults to 2048. ReadBufferSize int + // + // system functions + // + // function used to initialize the TCP listener. // It defaults to net.Listen Listen func(network string, address string) (net.Listener, error) + // + // private + // + receiverReportPeriod time.Duration closeSessionAfterNoRequestsFor time.Duration