change ConnClient.Tracks() signature

This commit is contained in:
aler9
2020-11-01 22:09:22 +01:00
parent 551eea72b5
commit ece3dd7077
2 changed files with 8 additions and 9 deletions

View File

@@ -86,7 +86,7 @@ type ConnClient struct {
state connClientState state connClientState
streamUrl *base.URL streamUrl *base.URL
streamProtocol *StreamProtocol streamProtocol *StreamProtocol
tracks map[int]*Track tracks Tracks
rtcpReceivers map[int]*rtcpreceiver.RtcpReceiver rtcpReceivers map[int]*rtcpreceiver.RtcpReceiver
udpLastFrameTimes map[int]*int64 udpLastFrameTimes map[int]*int64
udpRtpListeners map[int]*connClientUDPListener udpRtpListeners map[int]*connClientUDPListener
@@ -137,7 +137,6 @@ func NewConnClient(conf ConnClientConf) (*ConnClient, error) {
conf: conf, conf: conf,
br: bufio.NewReaderSize(conf.Conn, clientReadBufferSize), br: bufio.NewReaderSize(conf.Conn, clientReadBufferSize),
bw: bufio.NewWriterSize(conf.Conn, clientWriteBufferSize), bw: bufio.NewWriterSize(conf.Conn, clientWriteBufferSize),
tracks: make(map[int]*Track),
rtcpReceivers: make(map[int]*rtcpreceiver.RtcpReceiver), rtcpReceivers: make(map[int]*rtcpreceiver.RtcpReceiver),
udpLastFrameTimes: make(map[int]*int64), udpLastFrameTimes: make(map[int]*int64),
udpRtpListeners: make(map[int]*connClientUDPListener), udpRtpListeners: make(map[int]*connClientUDPListener),
@@ -192,8 +191,8 @@ func (c *ConnClient) NetConn() net.Conn {
return c.conf.Conn return c.conf.Conn
} }
// Tracks returns all the tracks passed to SetupUDP() or SetupTCP(). // Tracks returns all the tracks that the connection is reading or publishing.
func (c *ConnClient) Tracks() map[int]*Track { func (c *ConnClient) Tracks() Tracks {
return c.tracks return c.tracks
} }
@@ -569,7 +568,7 @@ func (c *ConnClient) SetupUDP(u *base.URL, mode TransportMode, track *Track, rtp
streamProtocol := StreamProtocolUDP streamProtocol := StreamProtocolUDP
c.streamProtocol = &streamProtocol c.streamProtocol = &streamProtocol
c.tracks[track.Id] = track c.tracks = append(c.tracks, track)
if mode == TransportModePlay { if mode == TransportModePlay {
c.rtcpReceivers[track.Id] = rtcpreceiver.New() c.rtcpReceivers[track.Id] = rtcpreceiver.New()
@@ -635,7 +634,7 @@ func (c *ConnClient) SetupTCP(u *base.URL, mode TransportMode, track *Track) (*b
streamProtocol := StreamProtocolTCP streamProtocol := StreamProtocolTCP
c.streamProtocol = &streamProtocol c.streamProtocol = &streamProtocol
c.tracks[track.Id] = track c.tracks = append(c.tracks, track)
if mode == TransportModePlay { if mode == TransportModePlay {
c.rtcpReceivers[track.Id] = rtcpreceiver.New() c.rtcpReceivers[track.Id] = rtcpreceiver.New()

View File

@@ -24,7 +24,7 @@ func main() {
defer wg.Wait() defer wg.Wait()
defer conn.CloseUDPListeners() defer conn.CloseUDPListeners()
for trackId := range conn.Tracks() { for _, track := range conn.Tracks() {
// read RTP frames // read RTP frames
wg.Add(1) wg.Add(1)
go func(trackId int) { go func(trackId int) {
@@ -38,7 +38,7 @@ func main() {
fmt.Printf("frame from track %d, type RTP: %v\n", trackId, buf) fmt.Printf("frame from track %d, type RTP: %v\n", trackId, buf)
} }
}(trackId) }(track.Id)
// read RTCP frames // read RTCP frames
wg.Add(1) wg.Add(1)
@@ -53,7 +53,7 @@ func main() {
fmt.Printf("frame from track %d, type RTCP: %v\n", trackId, buf) fmt.Printf("frame from track %d, type RTCP: %v\n", trackId, buf)
} }
}(trackId) }(track.Id)
} }
// wait until the connection is closed // wait until the connection is closed