Skip to content

Commit d08789b

Browse files
committed
Solve data race in ReadSimulcast
TrackEndcodings could change when reading
1 parent 3e2a804 commit d08789b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

peerconnection_renegotiation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func sendVideoUntilDone(t *testing.T, done <-chan struct{}, tracks []*TrackLocal
3434
select {
3535
case <-time.After(20 * time.Millisecond):
3636
for _, track := range tracks {
37-
assert.NoError(t, track.WriteSample(media.Sample{Data: []byte{0x00}, Duration: time.Second}))
37+
assert.NoError(t, track.WriteSample(media.Sample{Data: []byte{0x00}, Duration: 20 * time.Millisecond}))
3838
}
3939
case <-done:
4040
return

rtpsender.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,16 @@ func (r *RTPSender) ReadRTCP() ([]rtcp.Packet, interceptor.Attributes, error) {
437437
func (r *RTPSender) ReadSimulcast(b []byte, rid string) (n int, a interceptor.Attributes, err error) {
438438
select {
439439
case <-r.sendCalled:
440+
r.mu.Lock()
440441
for _, t := range r.trackEncodings {
441442
if t.track != nil && t.track.RID() == rid {
442-
return t.rtcpInterceptor.Read(b, a)
443+
reader := t.rtcpInterceptor
444+
r.mu.Unlock()
445+
446+
return reader.Read(b, a)
443447
}
444448
}
449+
r.mu.Unlock()
445450

446451
return 0, nil, fmt.Errorf("%w: %s", errRTPSenderNoTrackForRID, rid)
447452
case <-r.stopCalled:

0 commit comments

Comments
 (0)