From fdb0d708707f802da35ab8dd52e3d4c196d974b2 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 31 Oct 2021 13:01:36 +0100 Subject: [PATCH] client: remove default client --- client.go | 18 ------------------ client_publish_test.go | 4 +++- client_read_test.go | 16 ++++++++++++---- client_test.go | 12 +++++++++--- examples/client-publish-aac/main.go | 4 +++- examples/client-publish-h264/main.go | 4 +++- examples/client-publish-opus/main.go | 4 +++- examples/client-publish-pause/main.go | 4 +++- examples/client-query/main.go | 4 +++- examples/client-read-h264-save-to-disk/main.go | 4 +++- examples/client-read-h264/main.go | 4 +++- examples/client-read-partial/main.go | 4 +++- examples/client-read-pause/main.go | 4 +++- examples/client-read/main.go | 4 +++- 14 files changed, 54 insertions(+), 36 deletions(-) diff --git a/client.go b/client.go index ca63fa61..fb263d0b 100644 --- a/client.go +++ b/client.go @@ -17,24 +17,6 @@ import ( "github.com/aler9/gortsplib/pkg/headers" ) -// DefaultClient is the default Client. -var DefaultClient = &Client{} - -// Dial connects to a server. -func Dial(scheme string, host string) (*ClientConn, error) { - return DefaultClient.Dial(scheme, host) -} - -// DialRead connects to a server and starts reading all tracks. -func DialRead(address string) (*ClientConn, error) { - return DefaultClient.DialRead(address) -} - -// DialPublish connects to a server and starts publishing the tracks. -func DialPublish(address string, tracks Tracks) (*ClientConn, error) { - return DefaultClient.DialPublish(address, tracks) -} - // Client is a RTSP client. type Client struct { // diff --git a/client_publish_test.go b/client_publish_test.go index dedf1caa..098de68a 100644 --- a/client_publish_test.go +++ b/client_publish_test.go @@ -745,7 +745,9 @@ func TestClientPublishAutomaticProtocol(t *testing.T) { track, err := NewTrackH264(96, &TrackConfigH264{[]byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04}}) require.NoError(t, err) - conn, err := DialPublish("rtsp://localhost:8554/teststream", + c := Client{} + + conn, err := c.DialPublish("rtsp://localhost:8554/teststream", Tracks{track}) require.NoError(t, err) defer conn.Close() diff --git a/client_read_test.go b/client_read_test.go index f3670b06..da513137 100644 --- a/client_read_test.go +++ b/client_read_test.go @@ -130,7 +130,9 @@ func TestClientReadTracks(t *testing.T) { require.NoError(t, err) }() - conn, err := DialRead("rtsp://localhost:8554/teststream") + c := Client{} + + conn, err := c.DialRead("rtsp://localhost:8554/teststream") require.NoError(t, err) defer conn.Close() @@ -801,7 +803,9 @@ func TestClientReadNoContentBase(t *testing.T) { require.NoError(t, err) }() - conn, err := DialRead("rtsp://localhost:8554/teststream") + c := Client{} + + conn, err := c.DialRead("rtsp://localhost:8554/teststream") require.NoError(t, err) conn.Close() } @@ -1039,7 +1043,9 @@ func TestClientReadAutomaticProtocol(t *testing.T) { require.NoError(t, err) }() - conn, err := DialRead("rtsp://localhost:8554/teststream") + c := Client{} + + conn, err := c.DialRead("rtsp://localhost:8554/teststream") require.NoError(t, err) frameRecv := make(chan struct{}) @@ -1522,7 +1528,9 @@ func TestClientReadRedirect(t *testing.T) { }) }() - conn, err := DialRead("rtsp://localhost:8554/path1") + c := Client{} + + conn, err := c.DialRead("rtsp://localhost:8554/path1") require.NoError(t, err) frameRecv := make(chan struct{}) diff --git a/client_test.go b/client_test.go index 17c0a213..34ff4eaa 100644 --- a/client_test.go +++ b/client_test.go @@ -88,7 +88,9 @@ func TestClientSession(t *testing.T) { u, err := base.ParseURL("rtsp://localhost:8554/stream") require.NoError(t, err) - conn, err := Dial(u.Scheme, u.Host) + c := Client{} + + conn, err := c.Dial(u.Scheme, u.Host) require.NoError(t, err) defer conn.Close() @@ -167,7 +169,9 @@ func TestClientAuth(t *testing.T) { u, err := base.ParseURL("rtsp://myuser:mypass@localhost:8554/stream") require.NoError(t, err) - conn, err := Dial(u.Scheme, u.Host) + c := Client{} + + conn, err := c.Dial(u.Scheme, u.Host) require.NoError(t, err) defer conn.Close() @@ -229,7 +233,9 @@ func TestClientDescribeCharset(t *testing.T) { u, err := base.ParseURL("rtsp://localhost:8554/teststream") require.NoError(t, err) - conn, err := Dial(u.Scheme, u.Host) + c := Client{} + + conn, err := c.Dial(u.Scheme, u.Host) require.NoError(t, err) defer conn.Close() diff --git a/examples/client-publish-aac/main.go b/examples/client-publish-aac/main.go index 6af6bf06..1b95dfab 100644 --- a/examples/client-publish-aac/main.go +++ b/examples/client-publish-aac/main.go @@ -39,8 +39,10 @@ func main() { panic(err) } + c := gortsplib.Client{} + // connect to the server and start publishing the track - conn, err := gortsplib.DialPublish("rtsp://localhost:8554/mystream", + conn, err := c.DialPublish("rtsp://localhost:8554/mystream", gortsplib.Tracks{track}) if err != nil { panic(err) diff --git a/examples/client-publish-h264/main.go b/examples/client-publish-h264/main.go index 9e7b0d1a..f60fcb54 100644 --- a/examples/client-publish-h264/main.go +++ b/examples/client-publish-h264/main.go @@ -40,8 +40,10 @@ func main() { panic(err) } + c := gortsplib.Client{} + // connect to the server and start publishing the track - conn, err := gortsplib.DialPublish("rtsp://localhost:8554/mystream", + conn, err := c.DialPublish("rtsp://localhost:8554/mystream", gortsplib.Tracks{track}) if err != nil { panic(err) diff --git a/examples/client-publish-opus/main.go b/examples/client-publish-opus/main.go index 8a9a8a88..68747626 100644 --- a/examples/client-publish-opus/main.go +++ b/examples/client-publish-opus/main.go @@ -39,8 +39,10 @@ func main() { panic(err) } + c := gortsplib.Client{} + // connect to the server and start publishing the track - conn, err := gortsplib.DialPublish("rtsp://localhost:8554/mystream", + conn, err := c.DialPublish("rtsp://localhost:8554/mystream", gortsplib.Tracks{track}) if err != nil { panic(err) diff --git a/examples/client-publish-pause/main.go b/examples/client-publish-pause/main.go index 4adefd5a..aa92065c 100644 --- a/examples/client-publish-pause/main.go +++ b/examples/client-publish-pause/main.go @@ -42,8 +42,10 @@ func main() { panic(err) } + c := gortsplib.Client{} + // connect to the server and start publishing the track - conn, err := gortsplib.DialPublish("rtsp://localhost:8554/mystream", + conn, err := c.DialPublish("rtsp://localhost:8554/mystream", gortsplib.Tracks{track}) if err != nil { panic(err) diff --git a/examples/client-query/main.go b/examples/client-query/main.go index 3dbb92b3..9c32ef1e 100644 --- a/examples/client-query/main.go +++ b/examples/client-query/main.go @@ -17,7 +17,9 @@ func main() { panic(err) } - conn, err := gortsplib.Dial(u.Scheme, u.Host) + c := gortsplib.Client{} + + conn, err := c.Dial(u.Scheme, u.Host) if err != nil { panic(err) } diff --git a/examples/client-read-h264-save-to-disk/main.go b/examples/client-read-h264-save-to-disk/main.go index 7a506f3f..6912f9ac 100644 --- a/examples/client-read-h264-save-to-disk/main.go +++ b/examples/client-read-h264-save-to-disk/main.go @@ -25,8 +25,10 @@ const ( ) func main() { + c := gortsplib.Client{} + // connect to the server and start reading all tracks - conn, err := gortsplib.DialRead(inputStream) + conn, err := c.DialRead(inputStream) if err != nil { panic(err) } diff --git a/examples/client-read-h264/main.go b/examples/client-read-h264/main.go index d7ca0cf4..071dd2dd 100644 --- a/examples/client-read-h264/main.go +++ b/examples/client-read-h264/main.go @@ -14,8 +14,10 @@ import ( // 3. get H264 NALUs of that track func main() { + c := gortsplib.Client{} + // connect to the server and start reading all tracks - conn, err := gortsplib.DialRead("rtsp://localhost:8554/mystream") + conn, err := c.DialRead("rtsp://localhost:8554/mystream") if err != nil { panic(err) } diff --git a/examples/client-read-partial/main.go b/examples/client-read-partial/main.go index 3fb95a23..ec41c140 100644 --- a/examples/client-read-partial/main.go +++ b/examples/client-read-partial/main.go @@ -19,7 +19,9 @@ func main() { panic(err) } - conn, err := gortsplib.Dial(u.Scheme, u.Host) + c := gortsplib.Client{} + + conn, err := c.Dial(u.Scheme, u.Host) if err != nil { panic(err) } diff --git a/examples/client-read-pause/main.go b/examples/client-read-pause/main.go index f05cfb4f..d1640ad4 100644 --- a/examples/client-read-pause/main.go +++ b/examples/client-read-pause/main.go @@ -14,8 +14,10 @@ import ( // 4. repeat func main() { + c := gortsplib.Client{} + // connect to the server and start reading all tracks - conn, err := gortsplib.DialRead("rtsp://localhost:8554/mystream") + conn, err := c.DialRead("rtsp://localhost:8554/mystream") if err != nil { panic(err) } diff --git a/examples/client-read/main.go b/examples/client-read/main.go index eded7418..ee9574cb 100644 --- a/examples/client-read/main.go +++ b/examples/client-read/main.go @@ -10,8 +10,10 @@ import ( // 1. connect to a RTSP server and read all tracks on a path func main() { + c := gortsplib.Client{} + // connect to the server and start reading all tracks - conn, err := gortsplib.DialRead("rtsp://localhost:8554/mystream") + conn, err := c.DialRead("rtsp://localhost:8554/mystream") if err != nil { panic(err) }