mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Use a proper accessor for timestampedByterate.
This commit is contained in:
parent
8fa68f9605
commit
5a1ef1ddd7
2 changed files with 27 additions and 23 deletions
26
client.go
26
client.go
|
@ -579,12 +579,6 @@ func addDownTrack(c *client, id string, remoteTrack *upTrack, remoteConn *upConn
|
||||||
return conn, s, nil
|
return conn, s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var epoch = time.Now()
|
|
||||||
|
|
||||||
func msSinceEpoch() uint64 {
|
|
||||||
return uint64(time.Since(epoch) / time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
func rtcpDownListener(g *group, conn *downConnection, track *downTrack, s *webrtc.RTPSender) {
|
func rtcpDownListener(g *group, conn *downConnection, track *downTrack, s *webrtc.RTPSender) {
|
||||||
for {
|
for {
|
||||||
ps, err := s.ReadRTCP()
|
ps, err := s.ReadRTCP()
|
||||||
|
@ -603,18 +597,7 @@ func rtcpDownListener(g *group, conn *downConnection, track *downTrack, s *webrt
|
||||||
log.Printf("sendPLI: %v", err)
|
log.Printf("sendPLI: %v", err)
|
||||||
}
|
}
|
||||||
case *rtcp.ReceiverEstimatedMaximumBitrate:
|
case *rtcp.ReceiverEstimatedMaximumBitrate:
|
||||||
ms := msSinceEpoch()
|
track.maxBitrate.Set(p.Bitrate, msSinceEpoch())
|
||||||
// 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(
|
|
||||||
&track.maxBitrate.bitrate,
|
|
||||||
p.Bitrate,
|
|
||||||
)
|
|
||||||
atomic.StoreUint64(
|
|
||||||
&track.maxBitrate.timestamp,
|
|
||||||
uint64(ms),
|
|
||||||
)
|
|
||||||
case *rtcp.ReceiverReport:
|
case *rtcp.ReceiverReport:
|
||||||
for _, r := range p.Reports {
|
for _, r := range p.Reports {
|
||||||
if r.SSRC == track.track.SSRC() {
|
if r.SSRC == track.track.SSRC() {
|
||||||
|
@ -658,10 +641,8 @@ func updateUpBitrate(up *upConnection) {
|
||||||
track.maxBitrate = ^uint64(0)
|
track.maxBitrate = ^uint64(0)
|
||||||
local := track.getLocal()
|
local := track.getLocal()
|
||||||
for _, l := range local {
|
for _, l := range local {
|
||||||
ms := atomic.LoadUint64(&l.maxBitrate.timestamp)
|
bitrate := l.maxBitrate.Get(now)
|
||||||
bitrate := atomic.LoadUint64(&l.maxBitrate.bitrate)
|
if bitrate == ^uint64(0) {
|
||||||
loss := atomic.LoadUint32(&l.loss)
|
|
||||||
if now < ms || now > ms+5000 || bitrate == 0 {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,6 +654,7 @@ func updateUpBitrate(up *upConnection) {
|
||||||
minrate2 = 512000
|
minrate2 = 512000
|
||||||
}
|
}
|
||||||
if bitrate < minrate2 {
|
if bitrate < minrate2 {
|
||||||
|
loss := atomic.LoadUint32(&l.loss)
|
||||||
if loss <= 13 {
|
if loss <= 13 {
|
||||||
// less than 10% loss, go ahead
|
// less than 10% loss, go ahead
|
||||||
bitrate = minrate2
|
bitrate = minrate2
|
||||||
|
|
24
group.go
24
group.go
|
@ -68,11 +68,33 @@ type upConnection struct {
|
||||||
tracks []*upTrack
|
tracks []*upTrack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func msSinceEpoch() uint64 {
|
||||||
|
return uint64(time.Since(epoch) / time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
var epoch = time.Now()
|
||||||
|
|
||||||
type timeStampedBitrate struct {
|
type timeStampedBitrate struct {
|
||||||
bitrate uint64
|
bitrate uint64
|
||||||
timestamp uint64
|
timestamp uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tb *timeStampedBitrate) Set(bitrate, timestamp 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(&tb.bitrate, bitrate)
|
||||||
|
atomic.StoreUint64(&tb.timestamp, timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tb *timeStampedBitrate) Get(now uint64) uint64 {
|
||||||
|
ts := atomic.LoadUint64(&tb.timestamp)
|
||||||
|
if now < ts || now > ts + 1000 {
|
||||||
|
return ^uint64(0)
|
||||||
|
}
|
||||||
|
return atomic.LoadUint64(&tb.bitrate)
|
||||||
|
}
|
||||||
|
|
||||||
type downTrack struct {
|
type downTrack struct {
|
||||||
track *webrtc.Track
|
track *webrtc.Track
|
||||||
remote *upTrack
|
remote *upTrack
|
||||||
|
@ -695,7 +717,7 @@ func getClientStats(c *client) clientStats {
|
||||||
loss := atomic.LoadUint32(&t.loss)
|
loss := atomic.LoadUint32(&t.loss)
|
||||||
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: atomic.LoadUint64(&t.maxBitrate.bitrate),
|
maxBitrate: t.maxBitrate.Get(msSinceEpoch()),
|
||||||
loss: uint8((loss * 100) / 256),
|
loss: uint8((loss * 100) / 256),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue