Skip to content

Commit

Permalink
(fix) lock race (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
adwpc authored Nov 28, 2021
1 parent 2dbc5f1 commit 772e0b1
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pkg/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,9 @@ func (b *Buffer) buildReceptionReport() rtcp.ReceptionReport {
}
var dlsr uint32

if b.lastSRRecv != 0 {
delayMS := uint32((time.Now().UnixNano() - b.lastSRRecv) / 1e6)
lastSRRecv := atomic.LoadInt64(&b.lastSRRecv)
if lastSRRecv != 0 {
delayMS := uint32((time.Now().UnixNano() - lastSRRecv) / 1e6)
dlsr = (delayMS / 1e3) << 16
dlsr |= (delayMS % 1e3) * 65536 / 1000
}
Expand All @@ -483,18 +484,16 @@ func (b *Buffer) buildReceptionReport() rtcp.ReceptionReport {
TotalLost: lost,
LastSequenceNumber: extMaxSeq,
Jitter: uint32(b.stats.Jitter),
LastSenderReport: uint32(b.lastSRNTPTime >> 16),
LastSenderReport: uint32(atomic.LoadUint64(&b.lastSRNTPTime) >> 16),
Delay: dlsr,
}
return rr
}

func (b *Buffer) SetSenderReportData(rtpTime uint32, ntpTime uint64) {
b.Lock()
b.lastSRRTPTime = rtpTime
b.lastSRNTPTime = ntpTime
b.lastSRRecv = time.Now().UnixNano()
b.Unlock()
atomic.StoreUint64(&b.lastSRNTPTime, ntpTime)
atomic.StoreUint32(&b.lastSRRTPTime, rtpTime)
atomic.StoreInt64(&b.lastSRRecv, time.Now().UnixNano())
}

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

0 comments on commit 772e0b1

Please sign in to comment.