diff --git a/connclient.go b/connclient.go index e94aab03..32d57792 100644 --- a/connclient.go +++ b/connclient.go @@ -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() } diff --git a/connclientdial.go b/connclientdial.go index 9c9bfc40..f3340fea 100644 --- a/connclientdial.go +++ b/connclientdial.go @@ -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. diff --git a/connclientdial_test.go b/connclientdial_test.go index 795c42fe..1c52dede 100644 --- a/connclientdial_test.go +++ b/connclientdial_test.go @@ -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() diff --git a/examples/client-read-tcp.go b/examples/client-read-tcp.go index 14899213..cf4f6ca3 100644 --- a/examples/client-read-tcp.go +++ b/examples/client-read-tcp.go @@ -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) } diff --git a/examples/client-read-udp.go b/examples/client-read-udp.go index eb3c797b..a6e9fab0 100644 --- a/examples/client-read-udp.go +++ b/examples/client-read-udp.go @@ -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) {