mirror of
https://github.com/jech/galene.git
synced 2024-11-14 04:35:57 +01:00
Use jiffies instead of microseconds.
This commit is contained in:
parent
dddecd8610
commit
3e305e9827
3 changed files with 25 additions and 24 deletions
17
conn.go
17
conn.go
|
@ -13,6 +13,7 @@ import (
|
||||||
"sfu/estimator"
|
"sfu/estimator"
|
||||||
"sfu/jitter"
|
"sfu/jitter"
|
||||||
"sfu/packetcache"
|
"sfu/packetcache"
|
||||||
|
"sfu/rtptime"
|
||||||
|
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
"github.com/pion/webrtc/v2"
|
"github.com/pion/webrtc/v2"
|
||||||
|
@ -224,22 +225,22 @@ func (up *upConnection) complete() bool {
|
||||||
|
|
||||||
type bitrate struct {
|
type bitrate struct {
|
||||||
bitrate uint64
|
bitrate uint64
|
||||||
microseconds uint64
|
jiffies uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
const receiverReportTimeout = 8000000
|
const receiverReportTimeout = 8 * rtptime.JiffiesPerSec
|
||||||
|
|
||||||
func (br *bitrate) Set(bitrate uint64, now uint64) {
|
func (br *bitrate) Set(bitrate uint64, now uint64) {
|
||||||
// this is racy -- a reader might read the
|
// this is racy -- a reader might read the
|
||||||
// data between the two writes. This shouldn't
|
// data between the two writes. This shouldn't
|
||||||
// matter, we'll recover at the next sample.
|
// matter, we'll recover at the next sample.
|
||||||
atomic.StoreUint64(&br.bitrate, bitrate)
|
atomic.StoreUint64(&br.bitrate, bitrate)
|
||||||
atomic.StoreUint64(&br.microseconds, now)
|
atomic.StoreUint64(&br.jiffies, now)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *bitrate) Get(now uint64) uint64 {
|
func (br *bitrate) Get(now uint64) uint64 {
|
||||||
ts := atomic.LoadUint64(&br.microseconds)
|
ts := atomic.LoadUint64(&br.jiffies)
|
||||||
if now < ts || now > ts+receiverReportTimeout {
|
if now < ts || now-ts > receiverReportTimeout {
|
||||||
return ^uint64(0)
|
return ^uint64(0)
|
||||||
}
|
}
|
||||||
return atomic.LoadUint64(&br.bitrate)
|
return atomic.LoadUint64(&br.bitrate)
|
||||||
|
@ -248,17 +249,17 @@ func (br *bitrate) Get(now uint64) uint64 {
|
||||||
type receiverStats struct {
|
type receiverStats struct {
|
||||||
loss uint32
|
loss uint32
|
||||||
jitter uint32
|
jitter uint32
|
||||||
microseconds uint64
|
jiffies uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *receiverStats) Set(loss uint8, jitter uint32, now uint64) {
|
func (s *receiverStats) Set(loss uint8, jitter uint32, now uint64) {
|
||||||
atomic.StoreUint32(&s.loss, uint32(loss))
|
atomic.StoreUint32(&s.loss, uint32(loss))
|
||||||
atomic.StoreUint32(&s.jitter, jitter)
|
atomic.StoreUint32(&s.jitter, jitter)
|
||||||
atomic.StoreUint64(&s.microseconds, now)
|
atomic.StoreUint64(&s.jiffies, now)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *receiverStats) Get(now uint64) (uint8, uint32) {
|
func (s *receiverStats) Get(now uint64) (uint8, uint32) {
|
||||||
ts := atomic.LoadUint64(&s.microseconds)
|
ts := atomic.LoadUint64(&s.jiffies)
|
||||||
if now < ts || now > ts+receiverReportTimeout {
|
if now < ts || now > ts+receiverReportTimeout {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
6
group.go
6
group.go
|
@ -587,13 +587,13 @@ func getClientStats(c *webClient) clientStats {
|
||||||
for _, down := range c.down {
|
for _, down := range c.down {
|
||||||
conns := connStats{id: down.id}
|
conns := connStats{id: down.id}
|
||||||
for _, t := range down.tracks {
|
for _, t := range down.tracks {
|
||||||
us := rtptime.Microseconds()
|
jiffies := rtptime.Jiffies()
|
||||||
loss, jitter := t.stats.Get(us)
|
loss, jitter := t.stats.Get(jiffies)
|
||||||
j := time.Duration(jitter) * time.Second /
|
j := time.Duration(jitter) * time.Second /
|
||||||
time.Duration(t.track.Codec().ClockRate)
|
time.Duration(t.track.Codec().ClockRate)
|
||||||
conns.tracks = append(conns.tracks, trackStats{
|
conns.tracks = append(conns.tracks, trackStats{
|
||||||
bitrate: uint64(t.rate.Estimate()) * 8,
|
bitrate: uint64(t.rate.Estimate()) * 8,
|
||||||
maxBitrate: t.GetMaxBitrate(us),
|
maxBitrate: t.GetMaxBitrate(jiffies),
|
||||||
loss: uint8(uint32(loss) * 100 / 256),
|
loss: uint8(uint32(loss) * 100 / 256),
|
||||||
jitter: j,
|
jitter: j,
|
||||||
})
|
})
|
||||||
|
|
20
webclient.go
20
webclient.go
|
@ -918,7 +918,7 @@ func rtcpDownListener(conn *rtpDownConnection, track *rtpDownTrack, s *webrtc.RT
|
||||||
}
|
}
|
||||||
case *rtcp.ReceiverEstimatedMaximumBitrate:
|
case *rtcp.ReceiverEstimatedMaximumBitrate:
|
||||||
track.maxREMBBitrate.Set(
|
track.maxREMBBitrate.Set(
|
||||||
p.Bitrate, rtptime.Microseconds(),
|
p.Bitrate, rtptime.Jiffies(),
|
||||||
)
|
)
|
||||||
case *rtcp.ReceiverReport:
|
case *rtcp.ReceiverReport:
|
||||||
for _, r := range p.Reports {
|
for _, r := range p.Reports {
|
||||||
|
@ -934,7 +934,7 @@ func rtcpDownListener(conn *rtpDownConnection, track *rtpDownTrack, s *webrtc.RT
|
||||||
}
|
}
|
||||||
case *rtcp.TransportLayerNack:
|
case *rtcp.TransportLayerNack:
|
||||||
maxBitrate := track.GetMaxBitrate(
|
maxBitrate := track.GetMaxBitrate(
|
||||||
rtptime.Microseconds(),
|
rtptime.Jiffies(),
|
||||||
)
|
)
|
||||||
bitrate := track.rate.Estimate()
|
bitrate := track.rate.Estimate()
|
||||||
if uint64(bitrate)*7/8 < maxBitrate {
|
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) {
|
func handleReport(track *rtpDownTrack, report rtcp.ReceptionReport) {
|
||||||
now := rtptime.Microseconds()
|
jiffies := rtptime.Jiffies()
|
||||||
track.stats.Set(report.FractionLost, report.Jitter, now)
|
track.stats.Set(report.FractionLost, report.Jitter, jiffies)
|
||||||
track.updateRate(report.FractionLost, now)
|
track.updateRate(report.FractionLost, jiffies)
|
||||||
}
|
}
|
||||||
|
|
||||||
func trackKinds(down *rtpDownConnection) (audio bool, video bool) {
|
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) {
|
func updateUpBitrate(up *upConnection, maxVideoRate uint64) {
|
||||||
now := rtptime.Microseconds()
|
now := rtptime.Jiffies()
|
||||||
|
|
||||||
for _, track := range up.tracks {
|
for _, track := range up.tracks {
|
||||||
isvideo := track.track.Kind() == webrtc.RTPCodecTypeVideo
|
isvideo := track.track.Kind() == webrtc.RTPCodecTypeVideo
|
||||||
|
@ -1011,8 +1011,8 @@ func (up *upConnection) sendPLI(track *upTrack) error {
|
||||||
return ErrUnsupportedFeedback
|
return ErrUnsupportedFeedback
|
||||||
}
|
}
|
||||||
last := atomic.LoadUint64(&track.lastPLI)
|
last := atomic.LoadUint64(&track.lastPLI)
|
||||||
now := rtptime.Microseconds()
|
now := rtptime.Jiffies()
|
||||||
if now >= last && now-last < 200000 {
|
if now >= last && now-last < rtptime.JiffiesPerSec / 5 {
|
||||||
return ErrRateLimited
|
return ErrRateLimited
|
||||||
}
|
}
|
||||||
atomic.StoreUint64(&track.lastPLI, now)
|
atomic.StoreUint64(&track.lastPLI, now)
|
||||||
|
@ -1039,8 +1039,8 @@ func (up *upConnection) sendFIR(track *upTrack, increment bool) error {
|
||||||
return ErrUnsupportedFeedback
|
return ErrUnsupportedFeedback
|
||||||
}
|
}
|
||||||
last := atomic.LoadUint64(&track.lastFIR)
|
last := atomic.LoadUint64(&track.lastFIR)
|
||||||
now := rtptime.Microseconds()
|
now := rtptime.Jiffies()
|
||||||
if now >= last && now-last < 200000 {
|
if now >= last && now-last < rtptime.JiffiesPerSec / 5 {
|
||||||
return ErrRateLimited
|
return ErrRateLimited
|
||||||
}
|
}
|
||||||
atomic.StoreUint64(&track.lastFIR, now)
|
atomic.StoreUint64(&track.lastFIR, now)
|
||||||
|
|
Loading…
Reference in a new issue