Enable upstream nack for opus only audio track (#1343)
This commit is contained in:
@@ -207,6 +207,9 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
RTCPFeedback: RTCPFeedbackConfig{
|
RTCPFeedback: RTCPFeedbackConfig{
|
||||||
|
Audio: []webrtc.RTCPFeedback{
|
||||||
|
{Type: webrtc.TypeRTCPFBNACK},
|
||||||
|
},
|
||||||
Video: []webrtc.RTCPFeedback{
|
Video: []webrtc.RTCPFeedback{
|
||||||
{Type: webrtc.TypeRTCPFBTransportCC},
|
{Type: webrtc.TypeRTCPFBTransportCC},
|
||||||
{Type: webrtc.TypeRTCPFBCCM, Parameter: "fir"},
|
{Type: webrtc.TypeRTCPFBCCM, Parameter: "fir"},
|
||||||
|
|||||||
@@ -34,10 +34,7 @@ func (p *ParticipantImpl) setCodecPreferencesOpusRedForPublisher(offer webrtc.Se
|
|||||||
p.pendingTracksLock.RLock()
|
p.pendingTracksLock.RLock()
|
||||||
_, info := p.getPendingTrack(streamID, livekit.TrackType_AUDIO)
|
_, info := p.getPendingTrack(streamID, livekit.TrackType_AUDIO)
|
||||||
// if RED is disabled for this track, don't prefer RED codec in offer
|
// if RED is disabled for this track, don't prefer RED codec in offer
|
||||||
if info != nil && info.DisableRed {
|
disableRed := info != nil && info.DisableRed
|
||||||
p.pendingTracksLock.RUnlock()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
p.pendingTracksLock.RUnlock()
|
p.pendingTracksLock.RUnlock()
|
||||||
|
|
||||||
codecs, err := codecsFromMediaDescription(unmatchAudio)
|
codecs, err := codecsFromMediaDescription(unmatchAudio)
|
||||||
@@ -60,13 +57,28 @@ func (p *ParticipantImpl) setCodecPreferencesOpusRedForPublisher(offer webrtc.Se
|
|||||||
var preferredCodecs, leftCodecs []string
|
var preferredCodecs, leftCodecs []string
|
||||||
for _, codec := range codecs {
|
for _, codec := range codecs {
|
||||||
// codec contain opus/red
|
// codec contain opus/red
|
||||||
if strings.EqualFold(codec.Name, "red") && strings.Contains(codec.Fmtp, strconv.FormatInt(int64(opusPayload), 10)) {
|
if !disableRed && strings.EqualFold(codec.Name, "red") && strings.Contains(codec.Fmtp, strconv.FormatInt(int64(opusPayload), 10)) {
|
||||||
preferredCodecs = append(preferredCodecs, strconv.FormatInt(int64(codec.PayloadType), 10))
|
preferredCodecs = append(preferredCodecs, strconv.FormatInt(int64(codec.PayloadType), 10))
|
||||||
} else {
|
} else {
|
||||||
leftCodecs = append(leftCodecs, strconv.FormatInt(int64(codec.PayloadType), 10))
|
leftCodecs = append(leftCodecs, strconv.FormatInt(int64(codec.PayloadType), 10))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure nack enabled for audio in publisher offer
|
||||||
|
var nackFound bool
|
||||||
|
for _, attr := range unmatchAudio.Attributes {
|
||||||
|
if attr.Key == "rtcp-fb" && strings.Contains(attr.Value, fmt.Sprintf("%d nack", opusPayload)) {
|
||||||
|
nackFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !nackFound {
|
||||||
|
unmatchAudio.Attributes = append(unmatchAudio.Attributes, sdp.Attribute{
|
||||||
|
Key: "rtcp-fb",
|
||||||
|
Value: fmt.Sprintf("%d nack", opusPayload),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// no opus/red found
|
// no opus/red found
|
||||||
if len(preferredCodecs) == 0 {
|
if len(preferredCodecs) == 0 {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -216,6 +216,12 @@ func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapabili
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case webrtc.TypeRTCPFBNACK:
|
case webrtc.TypeRTCPFBNACK:
|
||||||
|
// pion use a single mediaengine to manage negotiated codecs of peerconnection, that means we can't have different
|
||||||
|
// codec settings at track level for same codec type, so enable nack for all audio receivers but don't create nack queue
|
||||||
|
// for red codec.
|
||||||
|
if strings.EqualFold(b.mime, "audio/red") {
|
||||||
|
return
|
||||||
|
}
|
||||||
b.logger.Debugw("Setting feedback", "type", webrtc.TypeRTCPFBNACK)
|
b.logger.Debugw("Setting feedback", "type", webrtc.TypeRTCPFBNACK)
|
||||||
b.nacker = nack.NewNACKQueue()
|
b.nacker = nack.NewNACKQueue()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user