Support for TCP-ICE, updated config documentation

This commit is contained in:
David Zhao
2021-04-10 21:53:50 -07:00
parent e47754179c
commit 3bba717eb5
4 changed files with 96 additions and 15 deletions
+11 -7
View File
@@ -22,17 +22,19 @@ type Config struct {
}
type RTCConfig struct {
ICEPortRangeStart uint16 `yaml:"port_range_start"`
ICEPortRangeEnd uint16 `yaml:"port_range_end"`
StunServers []string `yaml:"stun_servers"`
UseExternalIP bool `yaml:"use_external_ip"`
ICETCPPort uint16 `yaml:"ice_tcp_port"`
ICEPortRangeStart uint16 `yaml:"port_range_start"`
ICEPortRangeEnd uint16 `yaml:"port_range_end"`
// for testing, disable UDP
ForceTCP bool `yaml:"force_tcp"`
StunServers []string `yaml:"stun_servers"`
UseExternalIP bool `yaml:"use_external_ip"`
// Number of packets to buffer for NACK
PacketBufferSize int `yaml:"packet_buffer_size"`
// Max bitrate for REMB
MaxBitrate uint64 `yaml:"max_bitrate"`
MaxBufferTime int `yaml:"max_buffer_time"`
MaxBitrate uint64 `yaml:"max_bitrate"`
}
type AudioConfig struct {
@@ -47,6 +49,7 @@ type AudioConfig struct {
type RedisConfig struct {
Address string `yaml:"address"`
Username string `yaml:"username"`
Password string `yaml:"password"`
}
@@ -63,7 +66,8 @@ func NewConfig(confString string) (*Config, error) {
conf := &Config{
Port: 7880,
RTC: RTCConfig{
UseExternalIP: true,
UseExternalIP: true,
ICEPortRangeStart: 9000,
ICEPortRangeEnd: 11000,
StunServers: []string{
+33 -2
View File
@@ -1,7 +1,9 @@
package rtc
import (
"errors"
"fmt"
"net"
"github.com/go-logr/zapr"
"github.com/pion/ion-sfu/pkg/buffer"
@@ -21,7 +23,6 @@ type WebRTCConfig struct {
type ReceiverConfig struct {
packetBufferSize int
maxBitrate uint64
maxBufferTime int
}
func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig, error) {
@@ -55,6 +56,37 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig,
bufferFactory := buffer.NewBufferFactory(conf.PacketBufferSize, zapr.NewLogger(logger.Desugar()))
s.BufferFactory = bufferFactory.GetOrNew
networkTypes := []webrtc.NetworkType{}
if !conf.ForceTCP {
networkTypes = append(networkTypes,
webrtc.NetworkTypeUDP4,
webrtc.NetworkTypeUDP6)
}
// use TCP mux when it's set
if conf.ICETCPPort != 0 {
networkTypes = append(networkTypes,
webrtc.NetworkTypeTCP4,
webrtc.NetworkTypeTCP6,
)
tcpListener, err := net.ListenTCP("tcp", &net.TCPAddr{
IP: net.IP{0, 0, 0, 0},
Port: int(conf.ICETCPPort),
})
if err != nil {
return nil, err
}
tcpMux := webrtc.NewICETCPMux(nil, tcpListener, 10)
s.SetICETCPMux(tcpMux)
}
if len(networkTypes) == 0 {
return nil, errors.New("TCP is forced but not configured")
}
s.SetNetworkTypes(networkTypes)
return &WebRTCConfig{
Configuration: c,
SettingEngine: s,
@@ -62,7 +94,6 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig,
Receiver: ReceiverConfig{
packetBufferSize: conf.PacketBufferSize,
maxBitrate: conf.MaxBitrate,
maxBufferTime: conf.MaxBufferTime,
},
}, nil
}