diff --git a/clientdialer.go b/clientconf.go similarity index 87% rename from clientdialer.go rename to clientconf.go index ccab4727..bc6ff7e1 100644 --- a/clientdialer.go +++ b/clientconf.go @@ -14,27 +14,27 @@ import ( "github.com/aler9/gortsplib/pkg/rtcpsender" ) -// DefaultClientDialer is the default dialer, used by Dial, DialRead and DialPublish. -var DefaultClientDialer = ClientDialer{} +// DefaultClientConf is the default ClientConf. +var DefaultClientConf = ClientConf{} // Dial connects to a server. func Dial(host string) (*ClientConn, error) { - return DefaultClientDialer.Dial(host) + return DefaultClientConf.Dial(host) } // DialRead connects to a server and starts reading all tracks. func DialRead(address string) (*ClientConn, error) { - return DefaultClientDialer.DialRead(address) + return DefaultClientConf.DialRead(address) } // DialPublish connects to a server and starts publishing the tracks. func DialPublish(address string, tracks Tracks) (*ClientConn, error) { - return DefaultClientDialer.DialPublish(address, tracks) + return DefaultClientConf.DialPublish(address, tracks) } -// ClientDialer allows to initialize a ClientConn. +// ClientConf allows to initialize a ClientConn. // All fields are optional. -type ClientDialer struct { +type ClientConf struct { // the stream protocol (UDP or TCP). // If nil, it is chosen automatically (first UDP, then, if it fails, TCP). // It defaults to nil. @@ -68,7 +68,7 @@ type ClientDialer struct { } // Dial connects to a server. -func (d ClientDialer) Dial(host string) (*ClientConn, error) { +func (d ClientConf) Dial(host string) (*ClientConn, error) { if d.ReadTimeout == 0 { d.ReadTimeout = 10 * time.Second } @@ -110,7 +110,7 @@ func (d ClientDialer) Dial(host string) (*ClientConn, error) { } // DialRead connects to the address and starts reading all tracks. -func (d ClientDialer) DialRead(address string) (*ClientConn, error) { +func (d ClientConf) DialRead(address string) (*ClientConn, error) { u, err := base.ParseURL(address) if err != nil { return nil, err @@ -151,7 +151,7 @@ func (d ClientDialer) DialRead(address string) (*ClientConn, error) { } // DialPublish connects to the address and starts publishing the tracks. -func (d ClientDialer) DialPublish(address string, tracks Tracks) (*ClientConn, error) { +func (d ClientConf) DialPublish(address string, tracks Tracks) (*ClientConn, error) { u, err := base.ParseURL(address) if err != nil { return nil, err diff --git a/clientdialer_test.go b/clientconf_test.go similarity index 94% rename from clientdialer_test.go rename to clientconf_test.go index af7af0ee..68363e24 100644 --- a/clientdialer_test.go +++ b/clientconf_test.go @@ -85,7 +85,7 @@ func TestDialRead(t *testing.T) { time.Sleep(1 * time.Second) - dialer := ClientDialer{ + conf := ClientConf{ StreamProtocol: func() *StreamProtocol { if proto == "udp" { v := StreamProtocolUDP @@ -96,7 +96,7 @@ func TestDialRead(t *testing.T) { }(), } - conn, err := dialer.DialRead("rtsp://localhost:8554/teststream") + conn, err := conf.DialRead("rtsp://localhost:8554/teststream") require.NoError(t, err) var firstFrame int32 @@ -142,9 +142,9 @@ func TestDialReadAutomaticProtocol(t *testing.T) { time.Sleep(1 * time.Second) - dialer := ClientDialer{StreamProtocol: nil} + conf := ClientConf{StreamProtocol: nil} - conn, err := dialer.DialRead("rtsp://localhost:8554/teststream") + conn, err := conf.DialRead("rtsp://localhost:8554/teststream") require.NoError(t, err) var firstFrame int32 @@ -229,7 +229,7 @@ func TestDialReadPause(t *testing.T) { time.Sleep(1 * time.Second) - dialer := ClientDialer{ + conf := ClientConf{ StreamProtocol: func() *StreamProtocol { if proto == "udp" { v := StreamProtocolUDP @@ -240,7 +240,7 @@ func TestDialReadPause(t *testing.T) { }(), } - conn, err := dialer.DialRead("rtsp://localhost:8554/teststream") + conn, err := conf.DialRead("rtsp://localhost:8554/teststream") require.NoError(t, err) firstFrame := int32(0) @@ -304,7 +304,7 @@ func TestDialPublishSerial(t *testing.T) { track, err := NewTrackH264(96, sps, pps) require.NoError(t, err) - dialer := ClientDialer{ + conf := ClientConf{ StreamProtocol: func() *StreamProtocol { if proto == "udp" { v := StreamProtocolUDP @@ -315,7 +315,7 @@ func TestDialPublishSerial(t *testing.T) { }(), } - conn, err := dialer.DialPublish("rtsp://localhost:8554/teststream", + conn, err := conf.DialPublish("rtsp://localhost:8554/teststream", Tracks{track}) require.NoError(t, err) @@ -390,7 +390,7 @@ func TestDialPublishParallel(t *testing.T) { var conn *ClientConn defer func() { conn.Close() }() - dialer := ClientDialer{ + conf := ClientConf{ StreamProtocol: func() *StreamProtocol { if ca.proto == "udp" { v := StreamProtocolUDP @@ -409,7 +409,7 @@ func TestDialPublishParallel(t *testing.T) { port = "8555" } var err error - conn, err = dialer.DialPublish("rtsp://localhost:"+port+"/teststream", + conn, err = conf.DialPublish("rtsp://localhost:"+port+"/teststream", Tracks{track}) require.NoError(t, err) @@ -478,7 +478,7 @@ func TestDialPublishPauseSerial(t *testing.T) { track, err := NewTrackH264(96, sps, pps) require.NoError(t, err) - dialer := ClientDialer{ + conf := ClientConf{ StreamProtocol: func() *StreamProtocol { if proto == "udp" { v := StreamProtocolUDP @@ -489,7 +489,7 @@ func TestDialPublishPauseSerial(t *testing.T) { }(), } - conn, err := dialer.DialPublish("rtsp://localhost:8554/teststream", + conn, err := conf.DialPublish("rtsp://localhost:8554/teststream", Tracks{track}) require.NoError(t, err) defer conn.Close() @@ -550,7 +550,7 @@ func TestDialPublishPauseParallel(t *testing.T) { track, err := NewTrackH264(96, sps, pps) require.NoError(t, err) - dialer := ClientDialer{ + conf := ClientConf{ StreamProtocol: func() *StreamProtocol { if proto == "udp" { v := StreamProtocolUDP @@ -561,7 +561,7 @@ func TestDialPublishPauseParallel(t *testing.T) { }(), } - conn, err := dialer.DialPublish("rtsp://localhost:8554/teststream", + conn, err := conf.DialPublish("rtsp://localhost:8554/teststream", Tracks{track}) require.NoError(t, err) diff --git a/clientconn.go b/clientconn.go index 0ecb6f8a..ea7efc89 100644 --- a/clientconn.go +++ b/clientconn.go @@ -63,7 +63,7 @@ func (s clientConnState) String() string { // ClientConn is a client-side RTSP connection. type ClientConn struct { - d ClientDialer + d ClientConf nconn net.Conn br *bufio.Reader bw *bufio.Writer @@ -384,7 +384,7 @@ func (c *ClientConn) Setup(mode headers.TransportMode, track *Track, return *c.streamProtocol } - // protocol set by dialer + // protocol set by conf if c.d.StreamProtocol != nil { return *c.d.StreamProtocol } diff --git a/examples/client-publish-options.go b/examples/client-publish-options.go index 97c4fc47..80432712 100644 --- a/examples/client-publish-options.go +++ b/examples/client-publish-options.go @@ -43,8 +43,8 @@ func main() { panic(err) } - // ClientDialer allows to set additional client options - dialer := gortsplib.ClientDialer{ + // ClientConf allows to set additional client options + conf := gortsplib.ClientConf{ // the stream protocol (UDP or TCP). If nil, it is chosen automatically StreamProtocol: nil, // timeout of read operations @@ -54,7 +54,7 @@ func main() { } // connect to the server and start publishing the track - conn, err := dialer.DialPublish("rtsp://localhost:8554/mystream", + conn, err := conf.DialPublish("rtsp://localhost:8554/mystream", gortsplib.Tracks{track}) if err != nil { panic(err) diff --git a/examples/client-read-options.go b/examples/client-read-options.go index d35ae08a..58aa718d 100644 --- a/examples/client-read-options.go +++ b/examples/client-read-options.go @@ -15,8 +15,8 @@ import ( // 3. read all tracks on a path func main() { - // ClientDialer allows to set additional client options - dialer := gortsplib.ClientDialer{ + // ClientConf allows to set additional client options + conf := gortsplib.ClientConf{ // the stream protocol (UDP or TCP). If nil, it is chosen automatically StreamProtocol: nil, // timeout of read operations @@ -26,7 +26,7 @@ func main() { } // connect to the server and start reading all tracks - conn, err := dialer.DialRead("rtsp://localhost:8554/mystream") + conn, err := conf.DialRead("rtsp://localhost:8554/mystream") if err != nil { panic(err) }