* Thottle the publisher data channel sending when subscriber is slow Avoid the publisher overwhelm the sfu data channel buffer when the subscriber has lower receive bitrates. It will drop message if the subscriber is considered too slow to block the entire room. * Enable nack in mediaengine and disable it in transceiver as need pion doesn't support per transciver codec configuration, so the nack of this session will be disabled forever once it is first disabled by a transceiver. https://github.com/pion/webrtc/pull/2972
181 lines
5.7 KiB
Go
181 lines
5.7 KiB
Go
// Copyright 2023 LiveKit, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package rtc
|
|
|
|
import (
|
|
"slices"
|
|
|
|
"github.com/pion/sdp/v3"
|
|
"github.com/pion/webrtc/v4"
|
|
|
|
"github.com/livekit/livekit-server/pkg/config"
|
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
|
dd "github.com/livekit/livekit-server/pkg/sfu/rtpextension/dependencydescriptor"
|
|
"github.com/livekit/mediatransportutil/pkg/rtcconfig"
|
|
)
|
|
|
|
const (
|
|
frameMarking = "urn:ietf:params:rtp-hdrext:framemarking"
|
|
repairedRTPStreamID = "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"
|
|
)
|
|
|
|
type WebRTCConfig struct {
|
|
rtcconfig.WebRTCConfig
|
|
|
|
BufferFactory *buffer.Factory
|
|
Receiver ReceiverConfig
|
|
Publisher DirectionConfig
|
|
Subscriber DirectionConfig
|
|
}
|
|
|
|
type ReceiverConfig struct {
|
|
PacketBufferSizeVideo int
|
|
PacketBufferSizeAudio int
|
|
}
|
|
|
|
type RTPHeaderExtensionConfig struct {
|
|
Audio []string
|
|
Video []string
|
|
}
|
|
|
|
type RTCPFeedbackConfig struct {
|
|
Audio []webrtc.RTCPFeedback
|
|
Video []webrtc.RTCPFeedback
|
|
}
|
|
|
|
type DirectionConfig struct {
|
|
RTPHeaderExtension RTPHeaderExtensionConfig
|
|
RTCPFeedback RTCPFeedbackConfig
|
|
}
|
|
|
|
func NewWebRTCConfig(conf *config.Config) (*WebRTCConfig, error) {
|
|
rtcConf := conf.RTC
|
|
|
|
webRTCConfig, err := rtcconfig.NewWebRTCConfig(&rtcConf.RTCConfig, conf.Development)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// we don't want to use active TCP on a server, clients should be dialing
|
|
webRTCConfig.SettingEngine.DisableActiveTCP(true)
|
|
|
|
webRTCConfig.SettingEngine.EnableSCTPZeroChecksum(true)
|
|
|
|
if rtcConf.PacketBufferSize == 0 {
|
|
rtcConf.PacketBufferSize = 500
|
|
}
|
|
if rtcConf.PacketBufferSizeVideo == 0 {
|
|
rtcConf.PacketBufferSizeVideo = rtcConf.PacketBufferSize
|
|
}
|
|
if rtcConf.PacketBufferSizeAudio == 0 {
|
|
rtcConf.PacketBufferSizeAudio = rtcConf.PacketBufferSize
|
|
}
|
|
|
|
// publisher configuration
|
|
publisherConfig := DirectionConfig{
|
|
RTPHeaderExtension: RTPHeaderExtensionConfig{
|
|
Audio: []string{
|
|
sdp.SDESMidURI,
|
|
sdp.SDESRTPStreamIDURI,
|
|
sdp.AudioLevelURI,
|
|
//act.AbsCaptureTimeURI,
|
|
},
|
|
Video: []string{
|
|
sdp.SDESMidURI,
|
|
sdp.SDESRTPStreamIDURI,
|
|
sdp.TransportCCURI,
|
|
frameMarking,
|
|
dd.ExtensionURI,
|
|
repairedRTPStreamID,
|
|
//act.AbsCaptureTimeURI,
|
|
},
|
|
},
|
|
RTCPFeedback: RTCPFeedbackConfig{
|
|
Audio: []webrtc.RTCPFeedback{
|
|
{Type: webrtc.TypeRTCPFBNACK},
|
|
},
|
|
Video: []webrtc.RTCPFeedback{
|
|
{Type: webrtc.TypeRTCPFBTransportCC},
|
|
{Type: webrtc.TypeRTCPFBCCM, Parameter: "fir"},
|
|
{Type: webrtc.TypeRTCPFBNACK},
|
|
{Type: webrtc.TypeRTCPFBNACK, Parameter: "pli"},
|
|
},
|
|
},
|
|
}
|
|
|
|
// subscriber configuration
|
|
subscriberConfig := DirectionConfig{
|
|
RTPHeaderExtension: RTPHeaderExtensionConfig{
|
|
Video: []string{
|
|
dd.ExtensionURI,
|
|
//act.AbsCaptureTimeURI,
|
|
},
|
|
Audio: []string{
|
|
//act.AbsCaptureTimeURI,
|
|
},
|
|
},
|
|
RTCPFeedback: RTCPFeedbackConfig{
|
|
Audio: []webrtc.RTCPFeedback{
|
|
// always enable NACK for audio but disable it later for red enabled transceiver. https://github.com/pion/webrtc/pull/2972
|
|
{Type: webrtc.TypeRTCPFBNACK},
|
|
},
|
|
Video: []webrtc.RTCPFeedback{
|
|
{Type: webrtc.TypeRTCPFBCCM, Parameter: "fir"},
|
|
{Type: webrtc.TypeRTCPFBNACK},
|
|
{Type: webrtc.TypeRTCPFBNACK, Parameter: "pli"},
|
|
},
|
|
},
|
|
}
|
|
if rtcConf.CongestionControl.UseSendSideBWEInterceptor || rtcConf.CongestionControl.UseSendSideBWE {
|
|
subscriberConfig.RTPHeaderExtension.Video = append(subscriberConfig.RTPHeaderExtension.Video, sdp.TransportCCURI)
|
|
subscriberConfig.RTCPFeedback.Video = append(subscriberConfig.RTCPFeedback.Video, webrtc.RTCPFeedback{Type: webrtc.TypeRTCPFBTransportCC})
|
|
} else {
|
|
subscriberConfig.RTPHeaderExtension.Video = append(subscriberConfig.RTPHeaderExtension.Video, sdp.ABSSendTimeURI)
|
|
subscriberConfig.RTCPFeedback.Video = append(subscriberConfig.RTCPFeedback.Video, webrtc.RTCPFeedback{Type: webrtc.TypeRTCPFBGoogREMB})
|
|
}
|
|
|
|
return &WebRTCConfig{
|
|
WebRTCConfig: *webRTCConfig,
|
|
Receiver: ReceiverConfig{
|
|
PacketBufferSizeVideo: rtcConf.PacketBufferSizeVideo,
|
|
PacketBufferSizeAudio: rtcConf.PacketBufferSizeAudio,
|
|
},
|
|
Publisher: publisherConfig,
|
|
Subscriber: subscriberConfig,
|
|
}, nil
|
|
}
|
|
|
|
func (c *WebRTCConfig) UpdateCongestionControl(conf config.CongestionControlConfig) {
|
|
c.Subscriber.RTPHeaderExtension.Video = slices.DeleteFunc(c.Subscriber.RTPHeaderExtension.Video, func(ext string) bool {
|
|
return ext == sdp.TransportCCURI || ext == sdp.ABSSendTimeURI
|
|
})
|
|
c.Subscriber.RTCPFeedback.Video = slices.DeleteFunc(c.Subscriber.RTCPFeedback.Video, func(fb webrtc.RTCPFeedback) bool {
|
|
return fb.Type == webrtc.TypeRTCPFBTransportCC || fb.Type == webrtc.TypeRTCPFBGoogREMB
|
|
})
|
|
|
|
if conf.UseSendSideBWEInterceptor || conf.UseSendSideBWE {
|
|
c.Subscriber.RTPHeaderExtension.Video = append(c.Subscriber.RTPHeaderExtension.Video, sdp.TransportCCURI)
|
|
c.Subscriber.RTCPFeedback.Video = append(c.Subscriber.RTCPFeedback.Video, webrtc.RTCPFeedback{Type: webrtc.TypeRTCPFBTransportCC})
|
|
} else {
|
|
c.Subscriber.RTPHeaderExtension.Video = append(c.Subscriber.RTPHeaderExtension.Video, sdp.ABSSendTimeURI)
|
|
c.Subscriber.RTCPFeedback.Video = append(c.Subscriber.RTCPFeedback.Video, webrtc.RTCPFeedback{Type: webrtc.TypeRTCPFBGoogREMB})
|
|
}
|
|
}
|
|
|
|
func (c *WebRTCConfig) SetBufferFactory(factory *buffer.Factory) {
|
|
c.BufferFactory = factory
|
|
c.SettingEngine.BufferFactory = factory.GetOrNew
|
|
}
|