1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-12-22 23:35:46 +01:00

Use jiffies instead of microseconds.

This commit is contained in:
Juliusz Chroboczek 2020-06-03 20:26:54 +02:00
parent dddecd8610
commit 3e305e9827
3 changed files with 25 additions and 24 deletions

23
conn.go
View file

@ -13,6 +13,7 @@ import (
"sfu/estimator"
"sfu/jitter"
"sfu/packetcache"
"sfu/rtptime"
"github.com/pion/rtp"
"github.com/pion/webrtc/v2"
@ -223,42 +224,42 @@ func (up *upConnection) complete() bool {
}
type bitrate struct {
bitrate uint64
microseconds uint64
bitrate uint64
jiffies uint64
}
const receiverReportTimeout = 8000000
const receiverReportTimeout = 8 * rtptime.JiffiesPerSec
func (br *bitrate) Set(bitrate uint64, now uint64) {
// this is racy -- a reader might read the
// data between the two writes. This shouldn't
// matter, we'll recover at the next sample.
atomic.StoreUint64(&br.bitrate, bitrate)
atomic.StoreUint64(&br.microseconds, now)
atomic.StoreUint64(&br.jiffies, now)
}
func (br *bitrate) Get(now uint64) uint64 {
ts := atomic.LoadUint64(&br.microseconds)
if now < ts || now > ts+receiverReportTimeout {
ts := atomic.LoadUint64(&br.jiffies)
if now < ts || now-ts > receiverReportTimeout {
return ^uint64(0)
}
return atomic.LoadUint64(&br.bitrate)
}
type receiverStats struct {
loss uint32
jitter uint32
microseconds uint64
loss uint32
jitter uint32
jiffies uint64
}
func (s *receiverStats) Set(loss uint8, jitter uint32, now uint64) {
atomic.StoreUint32(&s.loss, uint32(loss))
atomic.StoreUint32(&s.jitter, jitter)
atomic.StoreUint64(&s.microseconds, now)
atomic.StoreUint64(&s.jiffies, now)
}
func (s *receiverStats) Get(now uint64) (uint8, uint32) {
ts := atomic.LoadUint64(&s.microseconds)
ts := atomic.LoadUint64(&s.jiffies)
if now < ts || now > ts+receiverReportTimeout {
return 0, 0
}

View file

@ -587,13 +587,13 @@ func getClientStats(c *webClient) clientStats {
for _, down := range c.down {
conns := connStats{id: down.id}
for _, t := range down.tracks {
us := rtptime.Microseconds()
loss, jitter := t.stats.Get(us)
jiffies := rtptime.Jiffies()
loss, jitter := t.stats.Get(jiffies)
j := time.Duration(jitter) * time.Second /
time.Duration(t.track.Codec().ClockRate)
conns.tracks = append(conns.tracks, trackStats{
bitrate: uint64(t.rate.Estimate()) * 8,
maxBitrate: t.GetMaxBitrate(us),
maxBitrate: t.GetMaxBitrate(jiffies),
loss: uint8(uint32(loss) * 100 / 256),
jitter: j,
})

View file

@ -918,7 +918,7 @@ func rtcpDownListener(conn *rtpDownConnection, track *rtpDownTrack, s *webrtc.RT
}
case *rtcp.ReceiverEstimatedMaximumBitrate:
track.maxREMBBitrate.Set(
p.Bitrate, rtptime.Microseconds(),
p.Bitrate, rtptime.Jiffies(),
)
case *rtcp.ReceiverReport:
for _, r := range p.Reports {
@ -934,7 +934,7 @@ func rtcpDownListener(conn *rtpDownConnection, track *rtpDownTrack, s *webrtc.RT
}
case *rtcp.TransportLayerNack:
maxBitrate := track.GetMaxBitrate(
rtptime.Microseconds(),
rtptime.Jiffies(),
)
bitrate := track.rate.Estimate()
if uint64(bitrate)*7/8 < maxBitrate {
@ -946,9 +946,9 @@ func rtcpDownListener(conn *rtpDownConnection, track *rtpDownTrack, s *webrtc.RT
}
func handleReport(track *rtpDownTrack, report rtcp.ReceptionReport) {
now := rtptime.Microseconds()
track.stats.Set(report.FractionLost, report.Jitter, now)
track.updateRate(report.FractionLost, now)
jiffies := rtptime.Jiffies()
track.stats.Set(report.FractionLost, report.Jitter, jiffies)
track.updateRate(report.FractionLost, jiffies)
}
func trackKinds(down *rtpDownConnection) (audio bool, video bool) {
@ -972,7 +972,7 @@ func trackKinds(down *rtpDownConnection) (audio bool, video bool) {
}
func updateUpBitrate(up *upConnection, maxVideoRate uint64) {
now := rtptime.Microseconds()
now := rtptime.Jiffies()
for _, track := range up.tracks {
isvideo := track.track.Kind() == webrtc.RTPCodecTypeVideo
@ -1011,8 +1011,8 @@ func (up *upConnection) sendPLI(track *upTrack) error {
return ErrUnsupportedFeedback
}
last := atomic.LoadUint64(&track.lastPLI)
now := rtptime.Microseconds()
if now >= last && now-last < 200000 {
now := rtptime.Jiffies()
if now >= last && now-last < rtptime.JiffiesPerSec / 5 {
return ErrRateLimited
}
atomic.StoreUint64(&track.lastPLI, now)
@ -1039,8 +1039,8 @@ func (up *upConnection) sendFIR(track *upTrack, increment bool) error {
return ErrUnsupportedFeedback
}
last := atomic.LoadUint64(&track.lastFIR)
now := rtptime.Microseconds()
if now >= last && now-last < 200000 {
now := rtptime.Jiffies()
if now >= last && now-last < rtptime.JiffiesPerSec / 5 {
return ErrRateLimited
}
atomic.StoreUint64(&track.lastFIR, now)