@@ -43,6 +43,7 @@ type SendSideBWE struct {
43
43
feedbackAdapter * cc.FeedbackAdapter
44
44
45
45
onTargetBitrateChange func (bitrate int )
46
+ onLossRateChange func (loss float64 )
46
47
47
48
lock sync.Mutex
48
49
latestStats Stats
@@ -164,6 +165,14 @@ func (e *SendSideBWE) GetTargetBitrate() int {
164
165
return e .latestBitrate
165
166
}
166
167
168
+ // GetLossRate returns the current packet loss rate in the range [0, 1].
169
+ func (e * SendSideBWE ) GetLossRate () float64 {
170
+ e .lossController .lock .Lock ()
171
+ defer e .lossController .lock .Unlock ()
172
+
173
+ return e .lossController .averageLoss
174
+ }
175
+
167
176
// GetStats returns some internal statistics of the bandwidth estimator
168
177
func (e * SendSideBWE ) GetStats () map [string ]interface {} {
169
178
e .lock .Lock ()
@@ -188,6 +197,12 @@ func (e *SendSideBWE) OnTargetBitrateChange(f func(bitrate int)) {
188
197
e .onTargetBitrateChange = f
189
198
}
190
199
200
+ // OnLossRateChange sets the callback that is called when the packet loss
201
+ // rate changes
202
+ func (e * SendSideBWE ) OnLossRateChange (f func (loss float64 )) {
203
+ e .onLossRateChange = f
204
+ }
205
+
191
206
// isClosed returns true if SendSideBWE is closed
192
207
func (e * SendSideBWE ) isClosed () bool {
193
208
select {
@@ -227,6 +242,11 @@ func (e *SendSideBWE) onDelayUpdate(delayStats DelayStats) {
227
242
go e .onTargetBitrateChange (bitrate )
228
243
}
229
244
245
+ // in principle this could update more frequently but this is a convenient place to put this hook.
246
+ if e .latestStats .LossStats .AverageLoss != lossStats .AverageLoss && e .onLossRateChange != nil {
247
+ go e .onLossRateChange (lossStats .AverageLoss )
248
+ }
249
+
230
250
e .latestStats = Stats {
231
251
LossStats : lossStats ,
232
252
DelayStats : delayStats ,
0 commit comments