mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 07:37:07 +08:00
add ConnClient.Tracks(); remove Tracks from DialRead returned values
This commit is contained in:
@@ -86,6 +86,7 @@ type ConnClient struct {
|
||||
state connClientState
|
||||
streamUrl *url.URL
|
||||
streamProtocol *StreamProtocol
|
||||
tracks map[int]*Track
|
||||
rtcpReceivers map[int]*rtcpreceiver.RtcpReceiver
|
||||
udpLastFrameTimes map[int]*int64
|
||||
udpRtpListeners map[int]*connClientUDPListener
|
||||
@@ -131,6 +132,7 @@ func NewConnClient(conf ConnClientConf) (*ConnClient, error) {
|
||||
conf: conf,
|
||||
br: bufio.NewReaderSize(conf.Conn, clientReadBufferSize),
|
||||
bw: bufio.NewWriterSize(conf.Conn, clientWriteBufferSize),
|
||||
tracks: make(map[int]*Track),
|
||||
rtcpReceivers: make(map[int]*rtcpreceiver.RtcpReceiver),
|
||||
udpLastFrameTimes: make(map[int]*int64),
|
||||
udpRtpListeners: make(map[int]*connClientUDPListener),
|
||||
@@ -184,6 +186,11 @@ func (c *ConnClient) NetConn() net.Conn {
|
||||
return c.conf.Conn
|
||||
}
|
||||
|
||||
// Tracks returns all the tracks passed to SetupUDP() or SetupTCP().
|
||||
func (c *ConnClient) Tracks() map[int]*Track {
|
||||
return c.tracks
|
||||
}
|
||||
|
||||
func (c *ConnClient) readFrameTCPOrResponse() (interface{}, error) {
|
||||
frame := c.tcpFrames.next()
|
||||
|
||||
@@ -579,6 +586,8 @@ func (c *ConnClient) SetupUDP(u *url.URL, mode TransportMode, track *Track, rtpP
|
||||
streamProtocol := StreamProtocolUDP
|
||||
c.streamProtocol = &streamProtocol
|
||||
|
||||
c.tracks[track.Id] = track
|
||||
|
||||
if mode == TransportModePlay {
|
||||
c.rtcpReceivers[track.Id] = rtcpreceiver.New()
|
||||
|
||||
@@ -643,6 +652,8 @@ func (c *ConnClient) SetupTCP(u *url.URL, mode TransportMode, track *Track) (*ba
|
||||
streamProtocol := StreamProtocolTCP
|
||||
c.streamProtocol = &streamProtocol
|
||||
|
||||
c.tracks[track.Id] = track
|
||||
|
||||
if mode == TransportModePlay {
|
||||
c.rtcpReceivers[track.Id] = rtcpreceiver.New()
|
||||
}
|
||||
|
@@ -5,34 +5,34 @@ import (
|
||||
)
|
||||
|
||||
// DialRead connects to the address and starts reading all tracks.
|
||||
func DialRead(address string, proto StreamProtocol) (*ConnClient, Tracks, error) {
|
||||
func DialRead(address string, proto StreamProtocol) (*ConnClient, error) {
|
||||
u, err := url.Parse(address)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conn, err := NewConnClient(ConnClientConf{Host: u.Host})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = conn.Options(u)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tracks, _, err := conn.Describe(u)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if proto == StreamProtocolUDP {
|
||||
for _, track := range tracks {
|
||||
_, err := conn.SetupUDP(u, TransportModePlay, track, 0, 0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func DialRead(address string, proto StreamProtocol) (*ConnClient, Tracks, error)
|
||||
_, err := conn.SetupTCP(u, TransportModePlay, track)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,10 +49,10 @@ func DialRead(address string, proto StreamProtocol) (*ConnClient, Tracks, error)
|
||||
_, err = conn.Play(u)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return conn, tracks, nil
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
// DialPublish connects to the address and starts publishing the tracks.
|
||||
|
@@ -79,7 +79,7 @@ func TestConnClientDialReadUDP(t *testing.T) {
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
conn, _, err := DialRead("rtsp://localhost:8554/teststream", StreamProtocolUDP)
|
||||
conn, err := DialRead("rtsp://localhost:8554/teststream", StreamProtocolUDP)
|
||||
require.NoError(t, err)
|
||||
defer conn.Close()
|
||||
|
||||
@@ -118,7 +118,7 @@ func TestConnClientDialReadTCP(t *testing.T) {
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
conn, _, err := DialRead("rtsp://localhost:8554/teststream", StreamProtocolTCP)
|
||||
conn, err := DialRead("rtsp://localhost:8554/teststream", StreamProtocolTCP)
|
||||
require.NoError(t, err)
|
||||
defer conn.Close()
|
||||
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func main() {
|
||||
// connect to the server and start reading all tracks
|
||||
conn, _, err := gortsplib.DialRead("rtsp://localhost:8554/mystream", gortsplib.StreamProtocolTCP)
|
||||
conn, err := gortsplib.DialRead("rtsp://localhost:8554/mystream", gortsplib.StreamProtocolTCP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
func main() {
|
||||
// connect to the server and start reading all tracks
|
||||
conn, tracks, err := gortsplib.DialRead("rtsp://localhost:8554/mystream", gortsplib.StreamProtocolUDP)
|
||||
conn, err := gortsplib.DialRead("rtsp://localhost:8554/mystream", gortsplib.StreamProtocolUDP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -24,7 +24,7 @@ func main() {
|
||||
defer wg.Wait()
|
||||
defer conn.CloseUDPListeners()
|
||||
|
||||
for trackId := range tracks {
|
||||
for trackId := range conn.Tracks() {
|
||||
// read RTP frames
|
||||
wg.Add(1)
|
||||
go func(trackId int) {
|
||||
|
Reference in New Issue
Block a user