From ece3dd7077f823e5763fe8e3ed1b9bd51dad8360 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 1 Nov 2020 22:09:22 +0100 Subject: [PATCH] change ConnClient.Tracks() signature --- connclient.go | 11 +++++------ examples/client-read-udp.go | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/connclient.go b/connclient.go index d5ff35d7..8d6fe9e0 100644 --- a/connclient.go +++ b/connclient.go @@ -86,7 +86,7 @@ type ConnClient struct { state connClientState streamUrl *base.URL streamProtocol *StreamProtocol - tracks map[int]*Track + tracks Tracks rtcpReceivers map[int]*rtcpreceiver.RtcpReceiver udpLastFrameTimes map[int]*int64 udpRtpListeners map[int]*connClientUDPListener @@ -137,7 +137,6 @@ 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), @@ -192,8 +191,8 @@ 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 { +// Tracks returns all the tracks that the connection is reading or publishing. +func (c *ConnClient) Tracks() Tracks { return c.tracks } @@ -569,7 +568,7 @@ func (c *ConnClient) SetupUDP(u *base.URL, mode TransportMode, track *Track, rtp streamProtocol := StreamProtocolUDP c.streamProtocol = &streamProtocol - c.tracks[track.Id] = track + c.tracks = append(c.tracks, track) if mode == TransportModePlay { c.rtcpReceivers[track.Id] = rtcpreceiver.New() @@ -635,7 +634,7 @@ func (c *ConnClient) SetupTCP(u *base.URL, mode TransportMode, track *Track) (*b streamProtocol := StreamProtocolTCP c.streamProtocol = &streamProtocol - c.tracks[track.Id] = track + c.tracks = append(c.tracks, track) if mode == TransportModePlay { c.rtcpReceivers[track.Id] = rtcpreceiver.New() diff --git a/examples/client-read-udp.go b/examples/client-read-udp.go index a9e44880..2d0af7ab 100644 --- a/examples/client-read-udp.go +++ b/examples/client-read-udp.go @@ -24,7 +24,7 @@ func main() { defer wg.Wait() defer conn.CloseUDPListeners() - for trackId := range conn.Tracks() { + for _, track := range conn.Tracks() { // read RTP frames wg.Add(1) go func(trackId int) { @@ -38,7 +38,7 @@ func main() { fmt.Printf("frame from track %d, type RTP: %v\n", trackId, buf) } - }(trackId) + }(track.Id) // read RTCP frames wg.Add(1) @@ -53,7 +53,7 @@ func main() { fmt.Printf("frame from track %d, type RTCP: %v\n", trackId, buf) } - }(trackId) + }(track.Id) } // wait until the connection is closed