1
Fork 0

Rename mono to rtptime.

This commit is contained in:
Juliusz Chroboczek 2020-06-03 20:12:25 +02:00
parent e373054f7e
commit 7ae9a9ea69
5 changed files with 23 additions and 22 deletions

View File

@ -16,7 +16,7 @@ import (
"sync/atomic"
"time"
"sfu/mono"
"sfu/rtptime"
"github.com/pion/webrtc/v2"
)
@ -587,12 +587,13 @@ func getClientStats(c *webClient) clientStats {
for _, down := range c.down {
conns := connStats{id: down.id}
for _, t := range down.tracks {
loss, jitter := t.stats.Get(mono.Microseconds())
us := rtptime.Microseconds()
loss, jitter := t.stats.Get(us)
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(mono.Microseconds()),
maxBitrate: t.GetMaxBitrate(us),
loss: uint8(uint32(loss) * 100 / 256),
jitter: j,
})

View File

@ -3,7 +3,7 @@ package jitter
import (
"sync/atomic"
"sfu/mono"
"sfu/rtptime"
)
type Estimator struct {
@ -37,7 +37,7 @@ func (e *Estimator) accumulate(timestamp, now uint32) {
}
func (e *Estimator) Accumulate(timestamp uint32) {
e.accumulate(timestamp, uint32(mono.Now(e.hz)))
e.accumulate(timestamp, uint32(rtptime.Now(e.hz)))
}
func (e *Estimator) Jitter() uint32 {

View File

@ -1,4 +1,4 @@
package mono
package rtptime
import (
"time"

View File

@ -1,4 +1,4 @@
package mono
package rtptime
import (
"testing"

View File

@ -20,7 +20,7 @@ import (
"sfu/estimator"
"sfu/jitter"
"sfu/mono"
"sfu/rtptime"
"sfu/packetcache"
"github.com/gorilla/websocket"
@ -559,7 +559,7 @@ func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) {
switch p := p.(type) {
case *rtcp.SenderReport:
track.mu.Lock()
track.srTime = mono.Now(0x10000)
track.srTime = rtptime.Now(0x10000)
track.srNTPTime = p.NTPTime
track.srRTPTime = p.RTPTime
track.mu.Unlock()
@ -574,7 +574,7 @@ func sendRR(conn *upConnection) error {
return nil
}
now := mono.Now(0x10000)
now := rtptime.Now(0x10000)
reports := make([]rtcp.ReceptionReport, 0, len(conn.tracks))
for _, t := range conn.tracks {
@ -631,7 +631,7 @@ func sendSR(conn *rtpDownConnection) error {
packets := make([]rtcp.Packet, 0, len(conn.tracks))
now := time.Now()
nowNTP := mono.TimeToNTP(now)
nowNTP := rtptime.TimeToNTP(now)
for _, t := range conn.tracks {
clockrate := t.track.Codec().ClockRate
@ -643,10 +643,10 @@ func sendSR(conn *rtpDownConnection) error {
nowRTP := srRTPTime
if srNTPTime != 0 {
srTime := mono.NTPToTime(srNTPTime)
srTime := rtptime.NTPToTime(srNTPTime)
delay := now.Sub(srTime)
if delay > 0 && delay < time.Hour {
d := mono.FromDuration(delay, clockrate)
d := rtptime.FromDuration(delay, clockrate)
nowRTP = srRTPTime + uint32(d)
}
}
@ -918,7 +918,7 @@ func rtcpDownListener(conn *rtpDownConnection, track *rtpDownTrack, s *webrtc.RT
}
case *rtcp.ReceiverEstimatedMaximumBitrate:
track.maxREMBBitrate.Set(
p.Bitrate, mono.Microseconds(),
p.Bitrate, rtptime.Microseconds(),
)
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(
mono.Microseconds(),
rtptime.Microseconds(),
)
bitrate := track.rate.Estimate()
if uint64(bitrate)*7/8 < maxBitrate {
@ -946,7 +946,7 @@ func rtcpDownListener(conn *rtpDownConnection, track *rtpDownTrack, s *webrtc.RT
}
func handleReport(track *rtpDownTrack, report rtcp.ReceptionReport) {
now := mono.Microseconds()
now := rtptime.Microseconds()
track.stats.Set(report.FractionLost, report.Jitter, now)
track.updateRate(report.FractionLost, now)
}
@ -972,7 +972,7 @@ func trackKinds(down *rtpDownConnection) (audio bool, video bool) {
}
func updateUpBitrate(up *upConnection, maxVideoRate uint64) {
now := mono.Microseconds()
now := rtptime.Microseconds()
for _, track := range up.tracks {
isvideo := track.track.Kind() == webrtc.RTPCodecTypeVideo
@ -1011,7 +1011,7 @@ func (up *upConnection) sendPLI(track *upTrack) error {
return ErrUnsupportedFeedback
}
last := atomic.LoadUint64(&track.lastPLI)
now := mono.Microseconds()
now := rtptime.Microseconds()
if now >= last && now-last < 200000 {
return ErrRateLimited
}
@ -1039,7 +1039,7 @@ func (up *upConnection) sendFIR(track *upTrack, increment bool) error {
return ErrUnsupportedFeedback
}
last := atomic.LoadUint64(&track.lastFIR)
now := mono.Microseconds()
now := rtptime.Microseconds()
if now >= last && now-last < 200000 {
return ErrRateLimited
}