mirror of
https://github.com/jech/galene.git
synced 2024-11-09 02:05:59 +01:00
Rename mono to rtptime.
This commit is contained in:
parent
e373054f7e
commit
7ae9a9ea69
5 changed files with 23 additions and 22 deletions
7
group.go
7
group.go
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -3,13 +3,13 @@ package jitter
|
|||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"sfu/mono"
|
||||
"sfu/rtptime"
|
||||
)
|
||||
|
||||
type Estimator struct {
|
||||
hz uint32
|
||||
timestamp uint32
|
||||
time uint32
|
||||
time uint32
|
||||
|
||||
jitter uint32 // atomic
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ func (e *Estimator) accumulate(timestamp, now uint32) {
|
|||
}
|
||||
|
||||
d := uint32((e.time - now) - (e.timestamp - timestamp))
|
||||
if d & 0x80000000 != 0 {
|
||||
if d&0x80000000 != 0 {
|
||||
d = uint32(-int32(d))
|
||||
}
|
||||
oldjitter := atomic.LoadUint32(&e.jitter)
|
||||
jitter := (oldjitter * 15 + d) / 16
|
||||
jitter := (oldjitter*15 + d) / 16
|
||||
atomic.StoreUint32(&e.jitter, jitter)
|
||||
|
||||
e.timestamp = timestamp
|
||||
|
@ -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 {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package mono
|
||||
package rtptime
|
||||
|
||||
import (
|
||||
"time"
|
|
@ -1,4 +1,4 @@
|
|||
package mono
|
||||
package rtptime
|
||||
|
||||
import (
|
||||
"testing"
|
24
webclient.go
24
webclient.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue