Skip to content

Commit

Permalink
Fix sub transceiver direction and rate limit pli (#264)
Browse files Browse the repository at this point in the history
* Fix sub transceiver direction and rate limit pli

* Fix tests
  • Loading branch information
OrlandoCo authored Oct 28, 2020
1 parent f5fee24 commit 8c28071
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 37 deletions.
23 changes: 10 additions & 13 deletions pkg/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,29 +188,26 @@ func (r *router) addSender(p *WebRTCTransport, rr *receiverRouter) error {
return err
}
// Create webrtc sender for the peer we are sending track to
s, err := p.pc.AddTrack(outTrack)
t, err := p.pc.AddTransceiverFromTrack(outTrack, webrtc.RtpTransceiverInit{
Direction: webrtc.RTPTransceiverDirectionSendonly,
})
if err != nil {
return err
}
if rr.kind == SimulcastReceiver {
sender = NewSimulcastSender(p.ctx, p.id, rr, s, recv.SpatialLayer(), r.config.Simulcast)
sender = NewSimulcastSender(p.ctx, p.id, rr, t.Sender(), recv.SpatialLayer(), r.config.Simulcast)
} else {
sender = NewSimpleSender(p.ctx, p.id, rr, s)
sender = NewSimpleSender(p.ctx, p.id, rr, t.Sender())
}
sender.OnCloseHandler(func() {
if err := p.pc.RemoveTrack(s); err != nil {
if err := p.pc.RemoveTrack(t.Sender()); err != nil {
log.Errorf("Error closing sender: %s", err)
}
})
for _, t := range p.pc.GetTransceivers() {
if t.Sender() != nil && t.Sender().Track().SSRC() == ssrc {
p.pendingSenders.PushBack(&pendingSender{
transceiver: t,
sender: sender,
})
break
}
}
p.pendingSenders.PushBack(&pendingSender{
transceiver: t,
sender: sender,
})
p.AddSender(rr.stream, sender)
recv.AddSender(sender)
return nil
Expand Down
7 changes: 5 additions & 2 deletions pkg/simplesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (s *SimpleSender) ID() string {
func (s *SimpleSender) Start() {
s.start.Do(func() {
log.Debugf("starting sender %s with ssrc %d", s.id, s.track.SSRC())
s.reSync.set(true)
s.enabled.set(true)
})
}
Expand Down Expand Up @@ -216,8 +217,10 @@ func (s *SimpleSender) receiveRTCP() {
for _, pkt := range pkts {
switch pkt := pkt.(type) {
case *rtcp.PictureLossIndication, *rtcp.FullIntraRequest:
fwdPkts = append(fwdPkts, pkt)
s.lastPli = time.Now()
if !s.reSync.get() && s.enabled.get() && time.Now().Sub(s.lastPli) > time.Second {
fwdPkts = append(fwdPkts, pkt)
s.lastPli = time.Now()
}
case *rtcp.TransportLayerNack:
log.Tracef("sender got nack: %+v", pkt)
for _, pair := range pkt.Nacks {
Expand Down
11 changes: 3 additions & 8 deletions pkg/simplesender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,6 @@ forLoop:
MediaSSRC: 1234,
},
},
{
name: "Sender must forward FIR messages",
want: &rtcp.FullIntraRequest{
SenderSSRC: 1234,
MediaSSRC: 1234,
},
},
}
for _, tt := range tests {
tt := tt
Expand All @@ -212,12 +205,14 @@ forLoop:
sender: s,
track: senderTrack,
}
wss.enabled.set(true)
wss.lastPli = time.Now().Add(-5 * time.Second)
go wss.receiveRTCP()
tmr := time.NewTimer(5000 * time.Millisecond)
testLoop:
for {
select {
case <-time.After(20 * time.Millisecond):
case <-time.After(10 * time.Millisecond):
err := remote.WriteRTCP([]rtcp.Packet{tt.want, tt.want, tt.want, tt.want})
assert.NoError(t, err)
case <-tmr.C:
Expand Down
19 changes: 12 additions & 7 deletions pkg/simulcastsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,19 @@ func (s *SimulcastSender) receiveRTCP() {
for _, pkt := range pkts {
switch pkt := pkt.(type) {
case *rtcp.PictureLossIndication:
pkt.MediaSSRC = s.lSSRC
pkt.SenderSSRC = s.lSSRC
fwdPkts = append(fwdPkts, pkt)
s.lastPli = time.Now()
if s.enabled.get() && time.Now().Sub(s.lastPli) > time.Second {
pkt.MediaSSRC = s.lSSRC
pkt.SenderSSRC = s.lSSRC
fwdPkts = append(fwdPkts, pkt)
s.lastPli = time.Now()
}
case *rtcp.FullIntraRequest:
pkt.MediaSSRC = s.lSSRC
pkt.SenderSSRC = s.lSSRC
fwdPkts = append(fwdPkts, pkt)
if s.enabled.get() && time.Now().Sub(s.lastPli) > time.Second {
pkt.MediaSSRC = s.lSSRC
pkt.SenderSSRC = s.lSSRC
fwdPkts = append(fwdPkts, pkt)
s.lastPli = time.Now()
}
case *rtcp.TransportLayerNack:
log.Tracef("sender got nack: %+v", pkt)
for _, pair := range pkt.Nacks {
Expand Down
7 changes: 0 additions & 7 deletions pkg/simulcastsender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,6 @@ forLoop:
MediaSSRC: simulcastSSRC,
},
},
{
name: "Sender must forward FIR messages, with correct SSRC",
want: &rtcp.FullIntraRequest{
SenderSSRC: simulcastSSRC,
MediaSSRC: simulcastSSRC,
},
},
}
for _, tt := range tests {
tt := tt
Expand Down

0 comments on commit 8c28071

Please sign in to comment.