mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
rename ClientDialer into ClientConf
This commit is contained in:
@@ -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
|
@@ -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)
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user