Skip to content

Commit 772e0b1

Browse files
authored
(fix) lock race (#620)
1 parent 2dbc5f1 commit 772e0b1

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pkg/buffer/buffer.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,9 @@ func (b *Buffer) buildReceptionReport() rtcp.ReceptionReport {
471471
}
472472
var dlsr uint32
473473

474-
if b.lastSRRecv != 0 {
475-
delayMS := uint32((time.Now().UnixNano() - b.lastSRRecv) / 1e6)
474+
lastSRRecv := atomic.LoadInt64(&b.lastSRRecv)
475+
if lastSRRecv != 0 {
476+
delayMS := uint32((time.Now().UnixNano() - lastSRRecv) / 1e6)
476477
dlsr = (delayMS / 1e3) << 16
477478
dlsr |= (delayMS % 1e3) * 65536 / 1000
478479
}
@@ -483,18 +484,16 @@ func (b *Buffer) buildReceptionReport() rtcp.ReceptionReport {
483484
TotalLost: lost,
484485
LastSequenceNumber: extMaxSeq,
485486
Jitter: uint32(b.stats.Jitter),
486-
LastSenderReport: uint32(b.lastSRNTPTime >> 16),
487+
LastSenderReport: uint32(atomic.LoadUint64(&b.lastSRNTPTime) >> 16),
487488
Delay: dlsr,
488489
}
489490
return rr
490491
}
491492

492493
func (b *Buffer) SetSenderReportData(rtpTime uint32, ntpTime uint64) {
493-
b.Lock()
494-
b.lastSRRTPTime = rtpTime
495-
b.lastSRNTPTime = ntpTime
496-
b.lastSRRecv = time.Now().UnixNano()
497-
b.Unlock()
494+
atomic.StoreUint64(&b.lastSRNTPTime, ntpTime)
495+
atomic.StoreUint32(&b.lastSRRTPTime, rtpTime)
496+
atomic.StoreInt64(&b.lastSRRecv, time.Now().UnixNano())
498497
}
499498

500499
func (b *Buffer) getRTCP() []rtcp.Packet {

0 commit comments

Comments
 (0)