Delta stats throughout (#615)
* Use delta stats throughout and avoid calculating deltas in telemetry * Fix a few things after testing * Remove debug * Fix tests * delete instead of setting to nil * Point to the latest protocol
This commit is contained in:
+32
-18
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/pion/webrtc/v3"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/utils"
|
||||
@@ -75,6 +76,7 @@ type Buffer struct {
|
||||
rtpStats *RTPStats
|
||||
rrSnapshotId uint32
|
||||
connectionQualitySnapshotId uint32
|
||||
deltaStatsSnapshotId uint32
|
||||
|
||||
lastFractionLostToReport uint8 // Last fraction lost from subscribers, should report to publisher; Audio only
|
||||
|
||||
@@ -104,7 +106,7 @@ func NewBuffer(ssrc uint32, vp, ap *sync.Pool) *Buffer {
|
||||
audioPool: ap,
|
||||
pliThrottle: int64(500 * time.Millisecond),
|
||||
logger: logger,
|
||||
callbacksQueue: utils.NewOpsQueue(logger),
|
||||
callbacksQueue: utils.NewOpsQueue(logger, "sfu-buffer", 50),
|
||||
}
|
||||
b.extPackets.SetMinCapacity(7)
|
||||
return b
|
||||
@@ -134,6 +136,7 @@ func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapabili
|
||||
})
|
||||
b.rrSnapshotId = b.rtpStats.NewSnapshotId()
|
||||
b.connectionQualitySnapshotId = b.rtpStats.NewSnapshotId()
|
||||
b.deltaStatsSnapshotId = b.rtpStats.NewSnapshotId()
|
||||
|
||||
b.callbacksQueue.Start()
|
||||
|
||||
@@ -581,7 +584,7 @@ func (b *Buffer) GetClockRate() uint32 {
|
||||
return b.clockRate
|
||||
}
|
||||
|
||||
func (b *Buffer) GetStats() *StreamStatsWithLayers {
|
||||
func (b *Buffer) GetStats() *livekit.RTPStats {
|
||||
b.RLock()
|
||||
defer b.RUnlock()
|
||||
|
||||
@@ -589,22 +592,7 @@ func (b *Buffer) GetStats() *StreamStatsWithLayers {
|
||||
return nil
|
||||
}
|
||||
|
||||
stats := b.rtpStats.ToProto()
|
||||
if stats == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
layers := make(map[int]LayerStats)
|
||||
layers[0] = LayerStats{
|
||||
TotalPackets: stats.Packets + stats.PacketsDuplicate + stats.PacketsPadding,
|
||||
TotalBytes: stats.Bytes + stats.BytesDuplicate + stats.BytesPadding,
|
||||
TotalFrames: stats.Frames,
|
||||
}
|
||||
|
||||
return &StreamStatsWithLayers{
|
||||
RTPStats: stats,
|
||||
Layers: layers,
|
||||
}
|
||||
return b.rtpStats.ToProto()
|
||||
}
|
||||
|
||||
func (b *Buffer) GetQualityInfo() *RTPSnapshotInfo {
|
||||
@@ -617,3 +605,29 @@ func (b *Buffer) GetQualityInfo() *RTPSnapshotInfo {
|
||||
|
||||
return b.rtpStats.SnapshotInfo(b.connectionQualitySnapshotId)
|
||||
}
|
||||
|
||||
func (b *Buffer) GetDeltaStats() *StreamStatsWithLayers {
|
||||
b.RLock()
|
||||
defer b.RUnlock()
|
||||
|
||||
if b.rtpStats == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
deltaStats := b.rtpStats.DeltaInfo(b.deltaStatsSnapshotId)
|
||||
if deltaStats == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
layers := make(map[int]LayerStats)
|
||||
layers[0] = LayerStats{
|
||||
Packets: deltaStats.Packets + deltaStats.PacketsDuplicate + deltaStats.PacketsPadding,
|
||||
Bytes: deltaStats.Bytes + deltaStats.BytesDuplicate + deltaStats.BytesPadding,
|
||||
Frames: deltaStats.Frames,
|
||||
}
|
||||
|
||||
return &StreamStatsWithLayers{
|
||||
RTPStats: deltaStats,
|
||||
Layers: layers,
|
||||
}
|
||||
}
|
||||
|
||||
+122
-40
@@ -35,12 +35,37 @@ type RTPFlowState struct {
|
||||
type RTPSnapshotInfo struct {
|
||||
PacketsExpected uint32
|
||||
PacketsLost uint32
|
||||
MaxJitter float64
|
||||
MaxRtt uint32
|
||||
JitterMax float64
|
||||
RttMax uint32
|
||||
}
|
||||
|
||||
type RTPDeltaInfo struct {
|
||||
Packets uint32
|
||||
Bytes uint64
|
||||
PacketsDuplicate uint32
|
||||
BytesDuplicate uint64
|
||||
PacketsPadding uint32
|
||||
BytesPadding uint64
|
||||
PacketsLost uint32
|
||||
Frames uint32
|
||||
RttMax uint32
|
||||
JitterMax float64
|
||||
Nacks uint32
|
||||
Plis uint32
|
||||
Firs uint32
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
extStartSN uint32
|
||||
bytes uint64
|
||||
packetsDuplicate uint32
|
||||
bytesDuplicate uint64
|
||||
packetsPadding uint32
|
||||
bytesPadding uint64
|
||||
frames uint32
|
||||
nacks uint32
|
||||
plis uint32
|
||||
firs uint32
|
||||
maxJitter float64
|
||||
isJitterOverridden bool
|
||||
maxJitterOverridden float64
|
||||
@@ -516,22 +541,21 @@ func (r *RTPStats) GetRtcpSenderReport(ssrc uint32) *rtcp.SenderReport {
|
||||
|
||||
func (r *RTPStats) SnapshotRtcpReceptionReport(ssrc uint32, proxyFracLost uint8, snapshotId uint32) *rtcp.ReceptionReport {
|
||||
r.lock.Lock()
|
||||
snapshot := r.getAndResetSnapshot(snapshotId)
|
||||
then, now := r.getAndResetSnapshot(snapshotId)
|
||||
r.lock.Unlock()
|
||||
|
||||
if snapshot == nil {
|
||||
if now == nil || then == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
|
||||
extHighestSN := r.getExtHighestSN()
|
||||
packetsExpected := extHighestSN - snapshot.extStartSN + 1
|
||||
packetsExpected := now.extStartSN - then.extStartSN + 1
|
||||
if packetsExpected > NumSequenceNumbers {
|
||||
logger.Warnw(
|
||||
"too many packets expected in receiver report",
|
||||
fmt.Errorf("start: %d, end: %d, expected: %d", snapshot.extStartSN, extHighestSN, packetsExpected),
|
||||
fmt.Errorf("start: %d, end: %d, expected: %d", then.extStartSN, now.extStartSN, packetsExpected),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
@@ -539,7 +563,7 @@ func (r *RTPStats) SnapshotRtcpReceptionReport(ssrc uint32, proxyFracLost uint8,
|
||||
return nil
|
||||
}
|
||||
|
||||
packetsLost := r.numMissingSNs(uint16(snapshot.extStartSN), uint16(extHighestSN))
|
||||
packetsLost := r.numMissingSNs(uint16(then.extStartSN), uint16(now.extStartSN))
|
||||
lossRate := float32(packetsLost) / float32(packetsExpected)
|
||||
fracLost := uint8(lossRate * 256.0)
|
||||
if proxyFracLost > fracLost {
|
||||
@@ -562,7 +586,7 @@ func (r *RTPStats) SnapshotRtcpReceptionReport(ssrc uint32, proxyFracLost uint8,
|
||||
SSRC: ssrc,
|
||||
FractionLost: fracLost,
|
||||
TotalLost: r.packetsLost,
|
||||
LastSequenceNumber: extHighestSN,
|
||||
LastSequenceNumber: now.extStartSN,
|
||||
Jitter: uint32(jitter),
|
||||
LastSenderReport: uint32(r.ntpSR >> 16),
|
||||
Delay: dlsr,
|
||||
@@ -571,22 +595,21 @@ func (r *RTPStats) SnapshotRtcpReceptionReport(ssrc uint32, proxyFracLost uint8,
|
||||
|
||||
func (r *RTPStats) SnapshotInfo(snapshotId uint32) *RTPSnapshotInfo {
|
||||
r.lock.Lock()
|
||||
snapshot := r.getAndResetSnapshot(snapshotId)
|
||||
then, now := r.getAndResetSnapshot(snapshotId)
|
||||
r.lock.Unlock()
|
||||
|
||||
if snapshot == nil {
|
||||
if now == nil || then == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
|
||||
extHighestSN := r.getExtHighestSN()
|
||||
packetsExpected := extHighestSN - snapshot.extStartSN + 1
|
||||
packetsExpected := now.extStartSN - then.extStartSN + 1
|
||||
if packetsExpected > NumSequenceNumbers {
|
||||
logger.Warnw(
|
||||
"too many packets expected in loss percentage",
|
||||
fmt.Errorf("start: %d, end: %d, expected: %d", snapshot.extStartSN, extHighestSN, packetsExpected),
|
||||
"too many packets expected in snapshot",
|
||||
fmt.Errorf("start: %d, end: %d, expected: %d", then.extStartSN, now.extStartSN, packetsExpected),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
@@ -594,19 +617,70 @@ func (r *RTPStats) SnapshotInfo(snapshotId uint32) *RTPSnapshotInfo {
|
||||
return nil
|
||||
}
|
||||
|
||||
packetsLost := r.numMissingSNs(uint16(snapshot.extStartSN), uint16(extHighestSN))
|
||||
packetsLost := r.numMissingSNs(uint16(then.extStartSN), uint16(now.extStartSN))
|
||||
|
||||
maxJitter := snapshot.maxJitter
|
||||
if snapshot.isJitterOverridden {
|
||||
maxJitter = snapshot.maxJitterOverridden
|
||||
maxJitter := then.maxJitter
|
||||
if then.isJitterOverridden {
|
||||
maxJitter = then.maxJitterOverridden
|
||||
}
|
||||
maxJitterTime := maxJitter / float64(r.params.ClockRate) * 1e6
|
||||
|
||||
return &RTPSnapshotInfo{
|
||||
PacketsExpected: packetsExpected,
|
||||
PacketsLost: packetsLost,
|
||||
MaxJitter: maxJitterTime,
|
||||
MaxRtt: snapshot.maxRtt,
|
||||
JitterMax: maxJitterTime,
|
||||
RttMax: then.maxRtt,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RTPStats) DeltaInfo(snapshotId uint32) *RTPDeltaInfo {
|
||||
r.lock.Lock()
|
||||
then, now := r.getAndResetSnapshot(snapshotId)
|
||||
r.lock.Unlock()
|
||||
|
||||
if now == nil || then == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
|
||||
packetsExpected := now.extStartSN - then.extStartSN + 1
|
||||
if packetsExpected > NumSequenceNumbers {
|
||||
logger.Warnw(
|
||||
"too many packets expected in delta",
|
||||
fmt.Errorf("start: %d, end: %d, expected: %d", then.extStartSN, now.extStartSN, packetsExpected),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
if packetsExpected == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
packetsLost := r.numMissingSNs(uint16(then.extStartSN), uint16(now.extStartSN))
|
||||
packetsPadding := now.packetsPadding - then.packetsPadding
|
||||
bytesPadding := now.bytesPadding - then.bytesPadding
|
||||
|
||||
maxJitter := then.maxJitter
|
||||
if then.isJitterOverridden {
|
||||
maxJitter = then.maxJitterOverridden
|
||||
}
|
||||
maxJitterTime := maxJitter / float64(r.params.ClockRate) * 1e6
|
||||
|
||||
return &RTPDeltaInfo{
|
||||
Packets: packetsExpected - packetsPadding,
|
||||
Bytes: now.bytes - then.bytes - bytesPadding,
|
||||
PacketsDuplicate: now.packetsDuplicate - then.packetsDuplicate,
|
||||
BytesDuplicate: now.bytesDuplicate - then.bytesDuplicate,
|
||||
PacketsPadding: packetsPadding,
|
||||
BytesPadding: bytesPadding,
|
||||
PacketsLost: packetsLost,
|
||||
Frames: now.frames - then.frames,
|
||||
RttMax: then.maxRtt,
|
||||
JitterMax: maxJitterTime,
|
||||
Nacks: now.nacks - then.nacks,
|
||||
Plis: now.plis - then.plis,
|
||||
Firs: now.firs - then.firs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -877,32 +951,40 @@ func (r *RTPStats) updateGapHistogram(gap int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RTPStats) getAndResetSnapshot(snapshotId uint32) *Snapshot {
|
||||
func (r *RTPStats) getAndResetSnapshot(snapshotId uint32) (*Snapshot, *Snapshot) {
|
||||
if !r.initialized {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
snapshot := r.snapshots[snapshotId]
|
||||
if snapshot == nil {
|
||||
snapshot = &Snapshot{
|
||||
extStartSN: r.extStartSN,
|
||||
maxJitter: 0.0,
|
||||
isJitterOverridden: false,
|
||||
maxJitterOverridden: 0.0,
|
||||
maxRtt: 0,
|
||||
then := r.snapshots[snapshotId]
|
||||
if then == nil {
|
||||
then = &Snapshot{
|
||||
extStartSN: r.extStartSN,
|
||||
}
|
||||
r.snapshots[snapshotId] = snapshot
|
||||
r.snapshots[snapshotId] = then
|
||||
}
|
||||
|
||||
toReturn := *snapshot
|
||||
// snapshot now
|
||||
r.snapshots[snapshotId] = &Snapshot{
|
||||
extStartSN: r.getExtHighestSN(),
|
||||
bytes: r.bytes,
|
||||
packetsDuplicate: r.packetsDuplicate,
|
||||
bytesDuplicate: r.bytesDuplicate,
|
||||
packetsPadding: r.packetsPadding,
|
||||
bytesPadding: r.bytesPadding,
|
||||
frames: r.frames,
|
||||
nacks: r.nacks,
|
||||
plis: r.plis,
|
||||
firs: r.firs,
|
||||
maxJitter: 0.0,
|
||||
isJitterOverridden: false,
|
||||
maxJitterOverridden: 0.0,
|
||||
maxRtt: 0,
|
||||
}
|
||||
// make a copy so that it can be used independently
|
||||
now := *r.snapshots[snapshotId]
|
||||
|
||||
snapshot.extStartSN = r.getExtHighestSN() + 1
|
||||
snapshot.maxJitter = 0.0
|
||||
snapshot.isJitterOverridden = false
|
||||
snapshot.maxJitterOverridden = 0.0
|
||||
snapshot.maxRtt = 0
|
||||
|
||||
return &toReturn
|
||||
return then, &now
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package buffer
|
||||
|
||||
import "github.com/livekit/protocol/livekit"
|
||||
|
||||
type LayerStats struct {
|
||||
TotalPackets uint32
|
||||
TotalBytes uint64
|
||||
TotalFrames uint32
|
||||
Packets uint32
|
||||
Bytes uint64
|
||||
Frames uint32
|
||||
}
|
||||
|
||||
type StreamStatsWithLayers struct {
|
||||
RTPStats *livekit.RTPStats
|
||||
RTPStats *RTPDeltaInfo
|
||||
Layers map[int]LayerStats
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ const (
|
||||
type ConnectionStatsParams struct {
|
||||
UpdateInterval time.Duration
|
||||
CodecType webrtc.RTPCodecType
|
||||
GetTrackStats func() map[uint32]*buffer.StreamStatsWithLayers
|
||||
GetDeltaStats func() map[uint32]*buffer.StreamStatsWithLayers
|
||||
GetQualityParams func() *buffer.ConnectionQualityParams
|
||||
GetIsReducedQuality func() bool
|
||||
Logger logger.Logger
|
||||
@@ -92,11 +92,11 @@ func (cs *ConnectionStats) updateScore() float32 {
|
||||
}
|
||||
|
||||
func (cs *ConnectionStats) getStat() *livekit.AnalyticsStat {
|
||||
if cs.params.GetTrackStats == nil {
|
||||
if cs.params.GetDeltaStats == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
streams := cs.params.GetTrackStats()
|
||||
streams := cs.params.GetDeltaStats()
|
||||
if len(streams) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -154,30 +154,30 @@ func (cs *ConnectionStats) updateStats() {
|
||||
}
|
||||
}
|
||||
|
||||
func ToAnalyticsStream(ssrc uint32, rtpStats *livekit.RTPStats) *livekit.AnalyticsStream {
|
||||
func ToAnalyticsStream(ssrc uint32, deltaStats *buffer.RTPDeltaInfo) *livekit.AnalyticsStream {
|
||||
return &livekit.AnalyticsStream{
|
||||
Ssrc: ssrc,
|
||||
TotalPrimaryPackets: rtpStats.Packets,
|
||||
TotalPrimaryBytes: rtpStats.Bytes,
|
||||
TotalRetransmitPackets: rtpStats.PacketsDuplicate,
|
||||
TotalRetransmitBytes: rtpStats.BytesDuplicate,
|
||||
TotalPaddingPackets: rtpStats.PacketsPadding,
|
||||
TotalPaddingBytes: rtpStats.BytesPadding,
|
||||
TotalPacketsLost: rtpStats.PacketsLost,
|
||||
TotalFrames: rtpStats.Frames,
|
||||
Rtt: rtpStats.RttMax,
|
||||
Jitter: uint32(rtpStats.JitterMax),
|
||||
TotalNacks: rtpStats.Nacks,
|
||||
TotalPlis: rtpStats.Plis,
|
||||
TotalFirs: rtpStats.Firs,
|
||||
Ssrc: ssrc,
|
||||
PrimaryPackets: deltaStats.Packets,
|
||||
PrimaryBytes: deltaStats.Bytes,
|
||||
RetransmitPackets: deltaStats.PacketsDuplicate,
|
||||
RetransmitBytes: deltaStats.BytesDuplicate,
|
||||
PaddingPackets: deltaStats.PacketsPadding,
|
||||
PaddingBytes: deltaStats.BytesPadding,
|
||||
PacketsLost: deltaStats.PacketsLost,
|
||||
Frames: deltaStats.Frames,
|
||||
Rtt: deltaStats.RttMax,
|
||||
Jitter: uint32(deltaStats.JitterMax),
|
||||
Nacks: deltaStats.Nacks,
|
||||
Plis: deltaStats.Plis,
|
||||
Firs: deltaStats.Firs,
|
||||
}
|
||||
}
|
||||
|
||||
func ToAnalyticsVideoLayer(layer int, layerStats *buffer.LayerStats) *livekit.AnalyticsVideoLayer {
|
||||
return &livekit.AnalyticsVideoLayer{
|
||||
Layer: int32(layer),
|
||||
TotalPackets: layerStats.TotalPackets,
|
||||
TotalBytes: layerStats.TotalBytes,
|
||||
TotalFrames: layerStats.TotalFrames,
|
||||
Layer: int32(layer),
|
||||
Packets: layerStats.Packets,
|
||||
Bytes: layerStats.Bytes,
|
||||
Frames: layerStats.Frames,
|
||||
}
|
||||
}
|
||||
|
||||
+31
-25
@@ -111,6 +111,7 @@ type DownTrack struct {
|
||||
|
||||
connectionStats *connectionquality.ConnectionStats
|
||||
connectionQualitySnapshotId uint32
|
||||
deltaStatsSnapshotId uint32
|
||||
|
||||
// Debug info
|
||||
pktsDropped atomic.Uint32
|
||||
@@ -181,12 +182,12 @@ func NewDownTrack(
|
||||
codec: c,
|
||||
kind: kind,
|
||||
forwarder: NewForwarder(c, kind, logger),
|
||||
callbacksQueue: utils.NewOpsQueue(logger),
|
||||
callbacksQueue: utils.NewOpsQueue(logger, "sfu-downtrack", 50),
|
||||
}
|
||||
|
||||
d.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
|
||||
CodecType: kind,
|
||||
GetTrackStats: d.GetTrackStats,
|
||||
GetDeltaStats: d.getDeltaStats,
|
||||
GetQualityParams: d.getQualityParams,
|
||||
GetIsReducedQuality: func() bool {
|
||||
return d.GetForwardingStatus() != ForwardingStatusOptimal
|
||||
@@ -206,6 +207,7 @@ func NewDownTrack(
|
||||
Logger: d.logger,
|
||||
})
|
||||
d.connectionQualitySnapshotId = d.rtpStats.NewSnapshotId()
|
||||
d.deltaStatsSnapshotId = d.rtpStats.NewSnapshotId()
|
||||
|
||||
return d, nil
|
||||
}
|
||||
@@ -1252,27 +1254,8 @@ func (d *DownTrack) GetConnectionScore() float32 {
|
||||
return d.connectionStats.GetScore()
|
||||
}
|
||||
|
||||
func (d *DownTrack) GetTrackStats() map[uint32]*buffer.StreamStatsWithLayers {
|
||||
streamStats := make(map[uint32]*buffer.StreamStatsWithLayers, 1)
|
||||
|
||||
stats := d.rtpStats.ToProto()
|
||||
if stats == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
layers := make(map[int]buffer.LayerStats)
|
||||
layers[0] = buffer.LayerStats{
|
||||
TotalPackets: stats.Packets + stats.PacketsDuplicate + stats.PacketsPadding,
|
||||
TotalBytes: stats.Bytes + stats.BytesDuplicate + stats.BytesPadding,
|
||||
TotalFrames: stats.Frames,
|
||||
}
|
||||
|
||||
streamStats[d.ssrc] = &buffer.StreamStatsWithLayers{
|
||||
RTPStats: stats,
|
||||
Layers: layers,
|
||||
}
|
||||
|
||||
return streamStats
|
||||
func (d *DownTrack) GetTrackStats() *livekit.RTPStats {
|
||||
return d.rtpStats.ToProto()
|
||||
}
|
||||
|
||||
func (d *DownTrack) getQualityParams() *buffer.ConnectionQualityParams {
|
||||
@@ -1288,11 +1271,34 @@ func (d *DownTrack) getQualityParams() *buffer.ConnectionQualityParams {
|
||||
|
||||
return &buffer.ConnectionQualityParams{
|
||||
LossPercentage: lossPercentage,
|
||||
Jitter: float32(s.MaxJitter / 1000.0),
|
||||
Rtt: s.MaxRtt,
|
||||
Jitter: float32(s.JitterMax / 1000.0),
|
||||
Rtt: s.RttMax,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DownTrack) getDeltaStats() map[uint32]*buffer.StreamStatsWithLayers {
|
||||
streamStats := make(map[uint32]*buffer.StreamStatsWithLayers, 1)
|
||||
|
||||
deltaStats := d.rtpStats.DeltaInfo(d.deltaStatsSnapshotId)
|
||||
if deltaStats == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
layers := make(map[int]buffer.LayerStats)
|
||||
layers[0] = buffer.LayerStats{
|
||||
Packets: deltaStats.Packets + deltaStats.PacketsDuplicate + deltaStats.PacketsPadding,
|
||||
Bytes: deltaStats.Bytes + deltaStats.BytesDuplicate + deltaStats.BytesPadding,
|
||||
Frames: deltaStats.Frames,
|
||||
}
|
||||
|
||||
streamStats[d.ssrc] = &buffer.StreamStatsWithLayers{
|
||||
RTPStats: deltaStats,
|
||||
Layers: layers,
|
||||
}
|
||||
|
||||
return streamStats
|
||||
}
|
||||
|
||||
func (d *DownTrack) GetNackStats() (totalPackets uint32, totalRepeatedNACKs uint32) {
|
||||
totalPackets = d.rtpStats.GetTotalPacketsPrimary()
|
||||
|
||||
|
||||
+39
-18
@@ -170,7 +170,7 @@ func NewWebRTCReceiver(
|
||||
|
||||
w.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
|
||||
CodecType: w.kind,
|
||||
GetTrackStats: w.GetTrackStats,
|
||||
GetDeltaStats: w.getDeltaStats,
|
||||
GetQualityParams: w.getQualityParams,
|
||||
GetIsReducedQuality: func() bool {
|
||||
return w.streamTrackerManager.IsReducedQuality()
|
||||
@@ -406,13 +406,12 @@ func (w *WebRTCReceiver) ReadRTP(buf []byte, layer uint8, sn uint16) (int, error
|
||||
return buff.GetPacket(buf, sn)
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) GetTrackStats() map[uint32]*buffer.StreamStatsWithLayers {
|
||||
func (w *WebRTCReceiver) GetTrackStats() *livekit.RTPStats {
|
||||
w.bufferMu.RLock()
|
||||
defer w.bufferMu.RUnlock()
|
||||
|
||||
stats := make(map[uint32]*buffer.StreamStatsWithLayers, len(w.buffers))
|
||||
|
||||
for layer, buff := range w.buffers {
|
||||
var stats []*livekit.RTPStats
|
||||
for _, buff := range w.buffers {
|
||||
if buff == nil {
|
||||
continue
|
||||
}
|
||||
@@ -422,17 +421,10 @@ func (w *WebRTCReceiver) GetTrackStats() map[uint32]*buffer.StreamStatsWithLayer
|
||||
continue
|
||||
}
|
||||
|
||||
// if simulcast, patch buffer stats with correct layer
|
||||
if w.isSimulcast {
|
||||
patched := make(map[int]buffer.LayerStats, 1)
|
||||
patched[layer] = sswl.Layers[0]
|
||||
sswl.Layers = patched
|
||||
}
|
||||
|
||||
stats[w.SSRC(layer)] = sswl
|
||||
stats = append(stats, sswl)
|
||||
}
|
||||
|
||||
return stats
|
||||
return buffer.AggregateRTPStats(stats)
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) getQualityParams() *buffer.ConnectionQualityParams {
|
||||
@@ -455,11 +447,11 @@ func (w *WebRTCReceiver) getQualityParams() *buffer.ConnectionQualityParams {
|
||||
|
||||
packetsExpected += q.PacketsExpected
|
||||
packetsLost += q.PacketsLost
|
||||
if q.MaxJitter > maxJitter {
|
||||
maxJitter = q.MaxJitter
|
||||
if q.JitterMax > maxJitter {
|
||||
maxJitter = q.JitterMax
|
||||
}
|
||||
if q.MaxRtt > maxRtt {
|
||||
maxRtt = q.MaxRtt
|
||||
if q.RttMax > maxRtt {
|
||||
maxRtt = q.RttMax
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,6 +467,35 @@ func (w *WebRTCReceiver) getQualityParams() *buffer.ConnectionQualityParams {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) getDeltaStats() map[uint32]*buffer.StreamStatsWithLayers {
|
||||
w.bufferMu.RLock()
|
||||
defer w.bufferMu.RUnlock()
|
||||
|
||||
deltaStats := make(map[uint32]*buffer.StreamStatsWithLayers, len(w.buffers))
|
||||
|
||||
for layer, buff := range w.buffers {
|
||||
if buff == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
sswl := buff.GetDeltaStats()
|
||||
if sswl == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// if simulcast, patch buffer stats with correct layer
|
||||
if w.isSimulcast {
|
||||
patched := make(map[int]buffer.LayerStats, 1)
|
||||
patched[layer] = sswl.Layers[0]
|
||||
sswl.Layers = patched
|
||||
}
|
||||
|
||||
deltaStats[w.SSRC(layer)] = sswl
|
||||
}
|
||||
|
||||
return deltaStats
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) forwardRTP(layer int32) {
|
||||
tracker := w.streamTrackerManager.GetTracker(layer)
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func NewStreamTracker(params StreamTrackerParams) *StreamTracker {
|
||||
s := &StreamTracker{
|
||||
params: params,
|
||||
status: StreamStatusStopped,
|
||||
callbacksQueue: utils.NewOpsQueue(params.Logger),
|
||||
callbacksQueue: utils.NewOpsQueue(params.Logger, "streamtracker", 50),
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user