split configuration into sections

This commit is contained in:
aler9
2021-05-07 15:34:54 +02:00
parent bec905ed9c
commit a8c6af39e3
3 changed files with 75 additions and 25 deletions

View File

@@ -29,15 +29,26 @@ func DialPublish(address string, tracks Tracks) (*ClientConn, error) {
// Client is a RTSP client. // Client is a RTSP client.
type Client struct { type Client struct {
// the stream protocol (UDP or TCP). //
// If nil, it is chosen automatically (first UDP, then, if it fails, TCP). // connection
// It defaults to nil. //
StreamProtocol *StreamProtocol
// 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. // a TLS configuration to connect to TLS (RTSPS) servers.
// It defaults to &tls.Config{InsecureSkipVerify:true} // It defaults to &tls.Config{InsecureSkipVerify:true}
TLSConfig *tls.Config TLSConfig *tls.Config
//
// initialization
//
// disable being redirected to other servers, that can happen during Describe(). // disable being redirected to other servers, that can happen during Describe().
// It defaults to false. // It defaults to false.
RedirectDisable bool RedirectDisable bool
@@ -47,19 +58,20 @@ type Client struct {
// It defaults to false. // It defaults to false.
AnyPortEnable bool AnyPortEnable bool
// timeout of read operations. //
// It defaults to 10 seconds. // reading / writing
ReadTimeout time.Duration //
// 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 // If the client is reading with UDP, it must receive
// at least a packet within this timeout. // at least a packet within this timeout.
// It defaults to 3 seconds. // It defaults to 3 seconds.
InitialUDPReadTimeout time.Duration InitialUDPReadTimeout time.Duration
// timeout of write operations.
// It defaults to 10 seconds.
WriteTimeout time.Duration
// read buffer count. // read buffer count.
// If greater than 1, allows to pass buffers to routines different than the one // If greater than 1, allows to pass buffers to routines different than the one
// that is reading frames. // that is reading frames.
@@ -71,12 +83,20 @@ type Client struct {
// It defaults to 2048. // It defaults to 2048.
ReadBufferSize int ReadBufferSize int
//
// callbacks
//
// callback called before every request. // callback called before every request.
OnRequest func(req *base.Request) OnRequest func(req *base.Request)
// callback called after every response. // callback called after every response.
OnResponse func(res *base.Response) OnResponse func(res *base.Response)
//
// system functions
//
// function used to initialize the TCP client. // function used to initialize the TCP client.
// It defaults to net.DialTimeout. // It defaults to net.DialTimeout.
DialTimeout func(network, address string, timeout time.Duration) (net.Conn, error) DialTimeout func(network, address string, timeout time.Duration) (net.Conn, error)
@@ -85,6 +105,10 @@ type Client struct {
// It defaults to net.ListenPacket. // It defaults to net.ListenPacket.
ListenPacket func(network, address string) (net.PacketConn, error) ListenPacket func(network, address string) (net.PacketConn, error)
//
// private
//
senderReportPeriod time.Duration senderReportPeriod time.Duration
receiverReportPeriod time.Duration receiverReportPeriod time.Duration
} }

View File

@@ -104,25 +104,30 @@ type ClientConn struct {
} }
func newClientConn(c *Client, scheme string, host string) (*ClientConn, error) { func newClientConn(c *Client, scheme string, host string) (*ClientConn, error) {
if c.TLSConfig == nil { // connection
c.TLSConfig = &tls.Config{InsecureSkipVerify: true}
}
if c.ReadTimeout == 0 { if c.ReadTimeout == 0 {
c.ReadTimeout = 10 * time.Second c.ReadTimeout = 10 * time.Second
} }
if c.InitialUDPReadTimeout == 0 {
c.InitialUDPReadTimeout = 3 * time.Second
}
if c.WriteTimeout == 0 { if c.WriteTimeout == 0 {
c.WriteTimeout = 10 * time.Second 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 { if c.ReadBufferCount == 0 {
c.ReadBufferCount = 1 c.ReadBufferCount = 1
} }
if c.ReadBufferSize == 0 { if c.ReadBufferSize == 0 {
c.ReadBufferSize = 2048 c.ReadBufferSize = 2048
} }
// system functions
if c.DialTimeout == nil { if c.DialTimeout == nil {
c.DialTimeout = net.DialTimeout c.DialTimeout = net.DialTimeout
} }
@@ -130,6 +135,7 @@ func newClientConn(c *Client, scheme string, host string) (*ClientConn, error) {
c.ListenPacket = net.ListenPacket c.ListenPacket = net.ListenPacket
} }
// private
if c.senderReportPeriod == 0 { if c.senderReportPeriod == 0 {
c.senderReportPeriod = 10 * time.Second c.senderReportPeriod = 10 * time.Second
} }

View File

@@ -60,9 +60,25 @@ type sessionReq struct {
// Server is a RTSP server. // Server is a RTSP server.
type Server struct { type Server struct {
//
// handler
//
// an handler to handle requests. // an handler to handle requests.
Handler ServerHandler 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. // a TLS configuration to accept TLS (RTSPS) connections.
TLSConfig *tls.Config TLSConfig *tls.Config
@@ -74,13 +90,9 @@ type Server struct {
// If UDPRTPAddress and UDPRTCPAddress are != "", the server can accept and send UDP streams. // If UDPRTPAddress and UDPRTCPAddress are != "", the server can accept and send UDP streams.
UDPRTCPAddress string UDPRTCPAddress string
// timeout of read operations. //
// It defaults to 10 seconds // reading / writing
ReadTimeout time.Duration //
// timeout of write operations.
// It defaults to 10 seconds
WriteTimeout time.Duration
// read buffer count. // read buffer count.
// If greater than 1, allows to pass buffers to routines different than the one // 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. // It defaults to 2048.
ReadBufferSize int ReadBufferSize int
//
// system functions
//
// function used to initialize the TCP listener. // function used to initialize the TCP listener.
// It defaults to net.Listen // It defaults to net.Listen
Listen func(network string, address string) (net.Listener, error) Listen func(network string, address string) (net.Listener, error)
//
// private
//
receiverReportPeriod time.Duration receiverReportPeriod time.Duration
closeSessionAfterNoRequestsFor time.Duration closeSessionAfterNoRequestsFor time.Duration