Disable audio loss proxying. (#2629)

* Disable audio loss proxying.

Added a config which is off by default.
With audio NACKs, that is the preferred repair mechanism.
With RED, repair is built in via packet redundancy to recover from
isolated losses.
So, proxying is not required. But, leaving it in there with a config
that is disabled by default.

* fix test
This commit is contained in:
Raja Subramanian
2024-04-06 11:28:04 +05:30
committed by GitHub
parent f4314686d1
commit 8852d71a8a
5 changed files with 56 additions and 6 deletions
+2
View File
@@ -191,6 +191,8 @@ type AudioConfig struct {
SmoothIntervals uint32 `yaml:"smooth_intervals,omitempty"` SmoothIntervals uint32 `yaml:"smooth_intervals,omitempty"`
// enable red encoding downtrack for opus only audio up track // enable red encoding downtrack for opus only audio up track
ActiveREDEncoding bool `yaml:"active_red_encoding,omitempty"` ActiveREDEncoding bool `yaml:"active_red_encoding,omitempty"`
// enable proxying weakest subscriber loss to publisher in RTCP Receiver Report
EnableLossProxying bool `yaml:"enable_loss_proxying,omitempty"`
} }
type StreamTrackerPacketConfig struct { type StreamTrackerPacketConfig struct {
-1
View File
@@ -96,7 +96,6 @@ func NewMediaTrack(params MediaTrackParams, ti *livekit.TrackInfo) *MediaTrack {
}) })
t.MediaLossProxy.OnMediaLossUpdate(func(fractionalLoss uint8) { t.MediaLossProxy.OnMediaLossUpdate(func(fractionalLoss uint8) {
if t.buffer != nil { if t.buffer != nil {
// ok to access buffer since receivers are added before subscribers
t.buffer.SetLastFractionLostReport(fractionalLoss) t.buffer.SetLastFractionLostReport(fractionalLoss)
} }
}) })
+14 -1
View File
@@ -96,6 +96,7 @@ type Buffer struct {
twcc *twcc.Responder twcc *twcc.Responder
audioLevelParams audio.AudioLevelParams audioLevelParams audio.AudioLevelParams
audioLevel *audio.AudioLevel audioLevel *audio.AudioLevel
enableAudioLossProxying bool
lastPacketRead int lastPacketRead int
@@ -182,6 +183,13 @@ func (b *Buffer) SetAudioLevelParams(audioLevelParams audio.AudioLevelParams) {
b.audioLevelParams = audioLevelParams b.audioLevelParams = audioLevelParams
} }
func (b *Buffer) SetAudioLossProxying(enable bool) {
b.Lock()
defer b.Unlock()
b.enableAudioLossProxying = enable
}
func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapability) { func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapability) {
b.Lock() b.Lock()
defer b.Unlock() defer b.Unlock()
@@ -824,7 +832,12 @@ func (b *Buffer) buildReceptionReport() *rtcp.ReceptionReport {
return nil return nil
} }
return b.rtpStats.GetRtcpReceptionReport(b.mediaSSRC, b.lastFractionLostToReport, b.rrSnapshotId) proxyLoss := b.lastFractionLostToReport
if b.codecType == webrtc.RTPCodecTypeAudio && !b.enableAudioLossProxying {
proxyLoss = 0
}
return b.rtpStats.GetRtcpReceptionReport(b.mediaSSRC, proxyLoss, b.rrSnapshotId)
} }
func (b *Buffer) SetSenderReportData(rtpTime uint32, ntpTime uint64) { func (b *Buffer) SetSenderReportData(rtpTime uint32, ntpTime uint64) {
+36 -1
View File
@@ -208,9 +208,12 @@ func TestNewBuffer(t *testing.T) {
func TestFractionLostReport(t *testing.T) { func TestFractionLostReport(t *testing.T) {
buff := NewBuffer(123, 1, 1) buff := NewBuffer(123, 1, 1)
require.NotNil(t, buff) require.NotNil(t, buff)
buff.codecType = webrtc.RTPCodecTypeVideo
var wg sync.WaitGroup var wg sync.WaitGroup
// with loss proxying
wg.Add(1) wg.Add(1)
buff.SetAudioLossProxying(true)
buff.SetLastFractionLostReport(55) buff.SetLastFractionLostReport(55)
buff.OnRtcpFeedback(func(fb []rtcp.Packet) { buff.OnRtcpFeedback(func(fb []rtcp.Packet) {
for _, pkt := range fb { for _, pkt := range fb {
@@ -241,6 +244,38 @@ func TestFractionLostReport(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
} }
wg.Wait() wg.Wait()
wg.Add(1)
buff.SetAudioLossProxying(false)
buff.OnRtcpFeedback(func(fb []rtcp.Packet) {
for _, pkt := range fb {
switch p := pkt.(type) {
case *rtcp.ReceiverReport:
for _, v := range p.Reports {
require.EqualValues(t, 0, v.FractionLost)
}
wg.Done()
}
}
})
buff.Bind(webrtc.RTPParameters{
HeaderExtensions: nil,
Codecs: []webrtc.RTPCodecParameters{opusCodec},
}, opusCodec.RTPCodecCapability)
for i := 0; i < 15; i++ {
pkt := rtp.Packet{
Header: rtp.Header{SequenceNumber: uint16(i), Timestamp: uint32(i)},
Payload: []byte{0xff, 0xff, 0xff, 0xfd, 0xb4, 0x9f, 0x94, 0x1},
}
b, err := pkt.Marshal()
require.NoError(t, err)
if i == 1 {
time.Sleep(1 * time.Second)
}
_, err = buff.Write(b)
require.NoError(t, err)
}
wg.Wait()
} }
func BenchmarkMemcpu(b *testing.B) { func BenchmarkMemcpu(b *testing.B) {
+1
View File
@@ -344,6 +344,7 @@ func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buff
ObserveDuration: w.audioConfig.UpdateInterval, ObserveDuration: w.audioConfig.UpdateInterval,
SmoothIntervals: w.audioConfig.SmoothIntervals, SmoothIntervals: w.audioConfig.SmoothIntervals,
}) })
buff.SetAudioLossProxying(w.audioConfig.EnableLossProxying)
buff.OnRtcpFeedback(w.sendRTCP) buff.OnRtcpFeedback(w.sendRTCP)
buff.OnRtcpSenderReport(func() { buff.OnRtcpSenderReport(func() {
srData := buff.GetSenderReportData() srData := buff.GetSenderReportData()