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"
|
"github.com/aler9/gortsplib/pkg/rtcpsender"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultClientDialer is the default dialer, used by Dial, DialRead and DialPublish.
|
// DefaultClientConf is the default ClientConf.
|
||||||
var DefaultClientDialer = ClientDialer{}
|
var DefaultClientConf = ClientConf{}
|
||||||
|
|
||||||
// Dial connects to a server.
|
// Dial connects to a server.
|
||||||
func Dial(host string) (*ClientConn, error) {
|
func Dial(host string) (*ClientConn, error) {
|
||||||
return DefaultClientDialer.Dial(host)
|
return DefaultClientConf.Dial(host)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialRead connects to a server and starts reading all tracks.
|
// DialRead connects to a server and starts reading all tracks.
|
||||||
func DialRead(address string) (*ClientConn, error) {
|
func DialRead(address string) (*ClientConn, error) {
|
||||||
return DefaultClientDialer.DialRead(address)
|
return DefaultClientConf.DialRead(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialPublish connects to a server and starts publishing the tracks.
|
// DialPublish connects to a server and starts publishing the tracks.
|
||||||
func DialPublish(address string, tracks Tracks) (*ClientConn, error) {
|
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.
|
// All fields are optional.
|
||||||
type ClientDialer struct {
|
type ClientConf struct {
|
||||||
// the stream protocol (UDP or TCP).
|
// the stream protocol (UDP or TCP).
|
||||||
// If nil, it is chosen automatically (first UDP, then, if it fails, TCP).
|
// If nil, it is chosen automatically (first UDP, then, if it fails, TCP).
|
||||||
// It defaults to nil.
|
// It defaults to nil.
|
||||||
@@ -68,7 +68,7 @@ type ClientDialer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dial connects to a server.
|
// 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 {
|
if d.ReadTimeout == 0 {
|
||||||
d.ReadTimeout = 10 * time.Second
|
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.
|
// 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)
|
u, err := base.ParseURL(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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.
|
// 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)
|
u, err := base.ParseURL(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
@@ -85,7 +85,7 @@ func TestDialRead(t *testing.T) {
|
|||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
dialer := ClientDialer{
|
conf := ClientConf{
|
||||||
StreamProtocol: func() *StreamProtocol {
|
StreamProtocol: func() *StreamProtocol {
|
||||||
if proto == "udp" {
|
if proto == "udp" {
|
||||||
v := StreamProtocolUDP
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var firstFrame int32
|
var firstFrame int32
|
||||||
@@ -142,9 +142,9 @@ func TestDialReadAutomaticProtocol(t *testing.T) {
|
|||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var firstFrame int32
|
var firstFrame int32
|
||||||
@@ -229,7 +229,7 @@ func TestDialReadPause(t *testing.T) {
|
|||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
dialer := ClientDialer{
|
conf := ClientConf{
|
||||||
StreamProtocol: func() *StreamProtocol {
|
StreamProtocol: func() *StreamProtocol {
|
||||||
if proto == "udp" {
|
if proto == "udp" {
|
||||||
v := StreamProtocolUDP
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
firstFrame := int32(0)
|
firstFrame := int32(0)
|
||||||
@@ -304,7 +304,7 @@ func TestDialPublishSerial(t *testing.T) {
|
|||||||
track, err := NewTrackH264(96, sps, pps)
|
track, err := NewTrackH264(96, sps, pps)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dialer := ClientDialer{
|
conf := ClientConf{
|
||||||
StreamProtocol: func() *StreamProtocol {
|
StreamProtocol: func() *StreamProtocol {
|
||||||
if proto == "udp" {
|
if proto == "udp" {
|
||||||
v := StreamProtocolUDP
|
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})
|
Tracks{track})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -390,7 +390,7 @@ func TestDialPublishParallel(t *testing.T) {
|
|||||||
var conn *ClientConn
|
var conn *ClientConn
|
||||||
defer func() { conn.Close() }()
|
defer func() { conn.Close() }()
|
||||||
|
|
||||||
dialer := ClientDialer{
|
conf := ClientConf{
|
||||||
StreamProtocol: func() *StreamProtocol {
|
StreamProtocol: func() *StreamProtocol {
|
||||||
if ca.proto == "udp" {
|
if ca.proto == "udp" {
|
||||||
v := StreamProtocolUDP
|
v := StreamProtocolUDP
|
||||||
@@ -409,7 +409,7 @@ func TestDialPublishParallel(t *testing.T) {
|
|||||||
port = "8555"
|
port = "8555"
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
conn, err = dialer.DialPublish("rtsp://localhost:"+port+"/teststream",
|
conn, err = conf.DialPublish("rtsp://localhost:"+port+"/teststream",
|
||||||
Tracks{track})
|
Tracks{track})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -478,7 +478,7 @@ func TestDialPublishPauseSerial(t *testing.T) {
|
|||||||
track, err := NewTrackH264(96, sps, pps)
|
track, err := NewTrackH264(96, sps, pps)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dialer := ClientDialer{
|
conf := ClientConf{
|
||||||
StreamProtocol: func() *StreamProtocol {
|
StreamProtocol: func() *StreamProtocol {
|
||||||
if proto == "udp" {
|
if proto == "udp" {
|
||||||
v := StreamProtocolUDP
|
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})
|
Tracks{track})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
@@ -550,7 +550,7 @@ func TestDialPublishPauseParallel(t *testing.T) {
|
|||||||
track, err := NewTrackH264(96, sps, pps)
|
track, err := NewTrackH264(96, sps, pps)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dialer := ClientDialer{
|
conf := ClientConf{
|
||||||
StreamProtocol: func() *StreamProtocol {
|
StreamProtocol: func() *StreamProtocol {
|
||||||
if proto == "udp" {
|
if proto == "udp" {
|
||||||
v := StreamProtocolUDP
|
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})
|
Tracks{track})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@@ -63,7 +63,7 @@ func (s clientConnState) String() string {
|
|||||||
|
|
||||||
// ClientConn is a client-side RTSP connection.
|
// ClientConn is a client-side RTSP connection.
|
||||||
type ClientConn struct {
|
type ClientConn struct {
|
||||||
d ClientDialer
|
d ClientConf
|
||||||
nconn net.Conn
|
nconn net.Conn
|
||||||
br *bufio.Reader
|
br *bufio.Reader
|
||||||
bw *bufio.Writer
|
bw *bufio.Writer
|
||||||
@@ -384,7 +384,7 @@ func (c *ClientConn) Setup(mode headers.TransportMode, track *Track,
|
|||||||
return *c.streamProtocol
|
return *c.streamProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
// protocol set by dialer
|
// protocol set by conf
|
||||||
if c.d.StreamProtocol != nil {
|
if c.d.StreamProtocol != nil {
|
||||||
return *c.d.StreamProtocol
|
return *c.d.StreamProtocol
|
||||||
}
|
}
|
||||||
|
@@ -43,8 +43,8 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientDialer allows to set additional client options
|
// ClientConf allows to set additional client options
|
||||||
dialer := gortsplib.ClientDialer{
|
conf := gortsplib.ClientConf{
|
||||||
// the stream protocol (UDP or TCP). If nil, it is chosen automatically
|
// the stream protocol (UDP or TCP). If nil, it is chosen automatically
|
||||||
StreamProtocol: nil,
|
StreamProtocol: nil,
|
||||||
// timeout of read operations
|
// timeout of read operations
|
||||||
@@ -54,7 +54,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// connect to the server and start publishing the track
|
// 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})
|
gortsplib.Tracks{track})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@@ -15,8 +15,8 @@ import (
|
|||||||
// 3. read all tracks on a path
|
// 3. read all tracks on a path
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// ClientDialer allows to set additional client options
|
// ClientConf allows to set additional client options
|
||||||
dialer := gortsplib.ClientDialer{
|
conf := gortsplib.ClientConf{
|
||||||
// the stream protocol (UDP or TCP). If nil, it is chosen automatically
|
// the stream protocol (UDP or TCP). If nil, it is chosen automatically
|
||||||
StreamProtocol: nil,
|
StreamProtocol: nil,
|
||||||
// timeout of read operations
|
// timeout of read operations
|
||||||
@@ -26,7 +26,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// connect to the server and start reading all tracks
|
// 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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user