client: remove default client

This commit is contained in:
aler9
2021-10-31 13:01:36 +01:00
committed by Alessandro Ros
parent a66a038a23
commit fdb0d70870
14 changed files with 54 additions and 36 deletions

View File

@@ -17,24 +17,6 @@ import (
"github.com/aler9/gortsplib/pkg/headers" "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. // Client is a RTSP client.
type Client struct { type Client struct {
// //

View File

@@ -745,7 +745,9 @@ func TestClientPublishAutomaticProtocol(t *testing.T) {
track, err := NewTrackH264(96, &TrackConfigH264{[]byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04}}) track, err := NewTrackH264(96, &TrackConfigH264{[]byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err) require.NoError(t, err)
conn, err := DialPublish("rtsp://localhost:8554/teststream", c := Client{}
conn, err := c.DialPublish("rtsp://localhost:8554/teststream",
Tracks{track}) Tracks{track})
require.NoError(t, err) require.NoError(t, err)
defer conn.Close() defer conn.Close()

View File

@@ -130,7 +130,9 @@ func TestClientReadTracks(t *testing.T) {
require.NoError(t, err) 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) require.NoError(t, err)
defer conn.Close() defer conn.Close()
@@ -801,7 +803,9 @@ func TestClientReadNoContentBase(t *testing.T) {
require.NoError(t, err) 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) require.NoError(t, err)
conn.Close() conn.Close()
} }
@@ -1039,7 +1043,9 @@ func TestClientReadAutomaticProtocol(t *testing.T) {
require.NoError(t, err) 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) require.NoError(t, err)
frameRecv := make(chan struct{}) 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) require.NoError(t, err)
frameRecv := make(chan struct{}) frameRecv := make(chan struct{})

View File

@@ -88,7 +88,9 @@ func TestClientSession(t *testing.T) {
u, err := base.ParseURL("rtsp://localhost:8554/stream") u, err := base.ParseURL("rtsp://localhost:8554/stream")
require.NoError(t, err) 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) require.NoError(t, err)
defer conn.Close() defer conn.Close()
@@ -167,7 +169,9 @@ func TestClientAuth(t *testing.T) {
u, err := base.ParseURL("rtsp://myuser:mypass@localhost:8554/stream") u, err := base.ParseURL("rtsp://myuser:mypass@localhost:8554/stream")
require.NoError(t, err) 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) require.NoError(t, err)
defer conn.Close() defer conn.Close()
@@ -229,7 +233,9 @@ func TestClientDescribeCharset(t *testing.T) {
u, err := base.ParseURL("rtsp://localhost:8554/teststream") u, err := base.ParseURL("rtsp://localhost:8554/teststream")
require.NoError(t, err) 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) require.NoError(t, err)
defer conn.Close() defer conn.Close()

View File

@@ -39,8 +39,10 @@ func main() {
panic(err) panic(err)
} }
c := gortsplib.Client{}
// connect to the server and start publishing the track // 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}) gortsplib.Tracks{track})
if err != nil { if err != nil {
panic(err) panic(err)

View File

@@ -40,8 +40,10 @@ func main() {
panic(err) panic(err)
} }
c := gortsplib.Client{}
// connect to the server and start publishing the track // 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}) gortsplib.Tracks{track})
if err != nil { if err != nil {
panic(err) panic(err)

View File

@@ -39,8 +39,10 @@ func main() {
panic(err) panic(err)
} }
c := gortsplib.Client{}
// connect to the server and start publishing the track // 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}) gortsplib.Tracks{track})
if err != nil { if err != nil {
panic(err) panic(err)

View File

@@ -42,8 +42,10 @@ func main() {
panic(err) panic(err)
} }
c := gortsplib.Client{}
// connect to the server and start publishing the track // 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}) gortsplib.Tracks{track})
if err != nil { if err != nil {
panic(err) panic(err)

View File

@@ -17,7 +17,9 @@ func main() {
panic(err) panic(err)
} }
conn, err := gortsplib.Dial(u.Scheme, u.Host) c := gortsplib.Client{}
conn, err := c.Dial(u.Scheme, u.Host)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -25,8 +25,10 @@ const (
) )
func main() { func main() {
c := gortsplib.Client{}
// connect to the server and start reading all tracks // connect to the server and start reading all tracks
conn, err := gortsplib.DialRead(inputStream) conn, err := c.DialRead(inputStream)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -14,8 +14,10 @@ import (
// 3. get H264 NALUs of that track // 3. get H264 NALUs of that track
func main() { func main() {
c := gortsplib.Client{}
// connect to the server and start reading all tracks // 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 { if err != nil {
panic(err) panic(err)
} }

View File

@@ -19,7 +19,9 @@ func main() {
panic(err) panic(err)
} }
conn, err := gortsplib.Dial(u.Scheme, u.Host) c := gortsplib.Client{}
conn, err := c.Dial(u.Scheme, u.Host)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -14,8 +14,10 @@ import (
// 4. repeat // 4. repeat
func main() { func main() {
c := gortsplib.Client{}
// connect to the server and start reading all tracks // 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 { if err != nil {
panic(err) panic(err)
} }

View File

@@ -10,8 +10,10 @@ import (
// 1. connect to a RTSP server and read all tracks on a path // 1. connect to a RTSP server and read all tracks on a path
func main() { func main() {
c := gortsplib.Client{}
// connect to the server and start reading all tracks // 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 { if err != nil {
panic(err) panic(err)
} }