1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

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" "sync/atomic"
"time" "time"
"sfu/mono" "sfu/rtptime"
"github.com/pion/webrtc/v2" "github.com/pion/webrtc/v2"
) )
@ -587,12 +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 {
loss, jitter := t.stats.Get(mono.Microseconds()) us := rtptime.Microseconds()
loss, jitter := t.stats.Get(us)
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(mono.Microseconds()), maxBitrate: t.GetMaxBitrate(us),
loss: uint8(uint32(loss) * 100 / 256), loss: uint8(uint32(loss) * 100 / 256),
jitter: j, jitter: j,
}) })

View file

@ -3,13 +3,13 @@ package jitter
import ( import (
"sync/atomic" "sync/atomic"
"sfu/mono" "sfu/rtptime"
) )
type Estimator struct { type Estimator struct {
hz uint32 hz uint32
timestamp uint32 timestamp uint32
time uint32 time uint32
jitter uint32 // atomic jitter uint32 // atomic
} }
@ -25,11 +25,11 @@ func (e *Estimator) accumulate(timestamp, now uint32) {
} }
d := uint32((e.time - now) - (e.timestamp - timestamp)) d := uint32((e.time - now) - (e.timestamp - timestamp))
if d & 0x80000000 != 0 { if d&0x80000000 != 0 {
d = uint32(-int32(d)) d = uint32(-int32(d))
} }
oldjitter := atomic.LoadUint32(&e.jitter) oldjitter := atomic.LoadUint32(&e.jitter)
jitter := (oldjitter * 15 + d) / 16 jitter := (oldjitter*15 + d) / 16
atomic.StoreUint32(&e.jitter, jitter) atomic.StoreUint32(&e.jitter, jitter)
e.timestamp = timestamp e.timestamp = timestamp
@ -37,7 +37,7 @@ func (e *Estimator) accumulate(timestamp, now uint32) {
} }
func (e *Estimator) Accumulate(timestamp 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 { func (e *Estimator) Jitter() uint32 {

View file

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

View file

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

View file

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