Skip to content

Commit 0397ec1

Browse files
committed
feat: Add stats for bandwidth probing to debug (rtcstats).
1 parent fc2f291 commit 0397ec1

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

jvb/src/main/kotlin/org/jitsi/videobridge/cc/BandwidthProbing.kt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ package org.jitsi.videobridge.cc
1818

1919
import org.jitsi.nlj.rtp.bandwidthestimation.BandwidthEstimator
2020
import org.jitsi.nlj.util.Bandwidth
21+
import org.jitsi.nlj.util.BitrateTracker
22+
import org.jitsi.nlj.util.bytes
2123
import org.jitsi.rtp.extensions.unsigned.toPositiveLong
2224
import org.jitsi.utils.concurrent.PeriodicRunnable
2325
import org.jitsi.utils.logging.DiagnosticContext
2426
import org.jitsi.utils.logging.TimeSeriesLogger
27+
import org.jitsi.utils.ms
28+
import org.jitsi.utils.secs
2529
import org.jitsi.videobridge.cc.allocation.BitrateControllerStatusSnapshot
2630
import org.jitsi.videobridge.cc.config.BandwidthProbingConfig.Companion.config
2731
import org.json.simple.JSONObject
@@ -36,18 +40,28 @@ class BandwidthProbing(
3640
/**
3741
* The sequence number to use if probing with the JVB's SSRC.
3842
*/
39-
private var seqNum = Random.nextInt(0xFFFF)
43+
private val seqNum = Random.nextInt(0xFFFF)
4044

4145
/**
4246
* The RTP timestamp to use if probing with the JVB's SSRC.
4347
*/
44-
private var ts: Long = Random.nextInt().toPositiveLong()
48+
private val ts: Long = Random.nextInt().toPositiveLong()
4549

4650
/**
4751
* Whether or not probing is currently enabled
4852
*/
4953
var enabled = false
5054

55+
private var lastTotalNeededBps = 0L
56+
private var lastMaxPaddingBps = 0L
57+
private var lastPaddingBps = 0L
58+
private fun zeroStats() {
59+
lastTotalNeededBps = 0
60+
lastMaxPaddingBps = 0
61+
lastPaddingBps = 0
62+
}
63+
private val probingBitrate = BitrateTracker(5.secs, 100.ms)
64+
5165
/**
5266
* The number of bytes left over from one run of probing to the next. This
5367
* avoids accumulated rounding errors causing us to under-shoot the probing
@@ -67,6 +81,7 @@ class BandwidthProbing(
6781
override fun run() {
6882
super.run()
6983
if (!enabled) {
84+
zeroStats()
7085
return
7186
}
7287

@@ -80,18 +95,24 @@ class BandwidthProbing(
8095
if (totalNeededBps < 1) {
8196
// Don't need to send any probing.
8297
bytesLeftOver = 0
98+
zeroStats()
8399
return
84100
}
85101

86102
val latestBweCopy = latestBwe
87103
if (bitrateControllerStatus.currentIdealBps <= latestBweCopy) {
104+
zeroStats()
88105
return
89106
}
90107

91108
// How much padding can we afford?
92109
val maxPaddingBps = latestBweCopy - bitrateControllerStatus.currentTargetBps
93110
val paddingBps = totalNeededBps.coerceAtMost(maxPaddingBps)
94111

112+
lastTotalNeededBps = totalNeededBps
113+
lastMaxPaddingBps = maxPaddingBps
114+
lastPaddingBps = paddingBps
115+
95116
var timeSeriesPoint: DiagnosticContext.TimeSeriesPoint? = null
96117
val newBytesNeeded = (config.paddingPeriodMs * paddingBps / 1000.0 / 8.0)
97118
val bytesNeeded = newBytesNeeded + bytesLeftOver
@@ -113,6 +134,7 @@ class BandwidthProbing(
113134

114135
if (bytesNeeded >= 1) {
115136
val bytesSent = probingDataSender.sendProbing(bitrateControllerStatus.activeSsrcs, bytesNeeded.toInt())
137+
probingBitrate.update(bytesSent.bytes)
116138
bytesLeftOver = (bytesNeeded - bytesSent).coerceAtLeast(0.0).toInt()
117139
timeSeriesPoint?.addField("bytes_sent", bytesSent)?.addField("new_bytes_left_over", bytesLeftOver)
118140
} else {
@@ -129,6 +151,10 @@ class BandwidthProbing(
129151
put("ts", ts)
130152
put("enabled", enabled)
131153
put("latestBwe", latestBwe)
154+
put("lastTotalNeededBps", lastTotalNeededBps)
155+
put("lastMaxPaddingBps", lastMaxPaddingBps)
156+
put("lastPaddingBps", lastPaddingBps)
157+
put("probingBps", probingBitrate.getRateBps())
132158
}
133159

134160
companion object {

0 commit comments

Comments
 (0)