send downtrack binding reports

fixed tests
This commit is contained in:
David Zhao
2021-01-10 22:36:24 -08:00
parent 456df0fb91
commit 6464ae3cd6
6 changed files with 238 additions and 47 deletions
+32 -38
View File
@@ -134,7 +134,7 @@ func (t *MediaTrack) AddSubscriber(participant types.Participant) error {
t.handleRTCP(outTrack, pkt)
})
}
//go t.scheduleDownTrackBindingReports(recv.Name())
go t.sendDownTrackBindingReports(participant.ID(), participant.RTCPChan())
})
outTrack.OnCloseHandler(func() {
t.lock.Lock()
@@ -187,43 +187,37 @@ func (t *MediaTrack) RemoveAllSubscribers() {
t.downtracks = make(map[string]types.DownTrack)
}
//func (t *MediaTrack) scheduleDownTrackBindingReports(streamId string) {
// var sd []rtcp.SourceDescriptionChunk
//
// p.lock.RLock()
// dts := p.subscribedTracks[streamId]
// for _, dt := range dts {
// if !dt.IsBound() {
// continue
// }
// chunks := dt.CreateSourceDescriptionChunks()
// if chunks != nil {
// sd = append(sd, chunks...)
// }
// }
// p.lock.RUnlock()
//
// pkts := []rtcp.Packet{
// &rtcp.SourceDescription{Chunks: sd},
// }
//
// go func() {
// batch := pkts
// i := 0
// for {
// if err := p.peerConn.WriteRTCP(batch); err != nil {
// logger.GetLogger().Debugw("error sending track binding reports",
// "participant", p.id,
// "err", err)
// }
// if i > 5 {
// return
// }
// i++
// time.Sleep(20 * time.Millisecond)
// }
// }()
//}
func (t *MediaTrack) sendDownTrackBindingReports(participantId string, rtcpCh chan<- []rtcp.Packet) {
var sd []rtcp.SourceDescriptionChunk
t.lock.RLock()
defer t.lock.RUnlock()
dt := t.downtracks[participantId]
if !dt.IsBound() {
return
}
chunks := dt.CreateSourceDescriptionChunks()
if chunks != nil {
sd = append(sd, chunks...)
}
pkts := []rtcp.Packet{
&rtcp.SourceDescription{Chunks: sd},
}
go func() {
batch := pkts
i := 0
for {
rtcpCh <- batch
if i > 5 {
return
}
i++
time.Sleep(20 * time.Millisecond)
}
}()
}
// b reads from the receiver and writes to each sender
func (t *MediaTrack) forwardRTPWorker() {