Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable webrtcSTUNGatherTimeout #4221

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apidocs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ components:
type: string
webrtcTrackGatherTimeout:
type: string
webrtcSTUNGatherTimeout:
type: string

# SRT server
srt:
Expand Down
2 changes: 2 additions & 0 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ type Conf struct {
WebRTCICEServers2 WebRTCICEServers `json:"webrtcICEServers2"`
WebRTCHandshakeTimeout Duration `json:"webrtcHandshakeTimeout"`
WebRTCTrackGatherTimeout Duration `json:"webrtcTrackGatherTimeout"`
WebRTCSTUNGatherTimeout Duration `json:"webrtcSTUNGatherTimeout"`
WebRTCICEUDPMuxAddress *string `json:"webrtcICEUDPMuxAddress,omitempty"` // deprecated
WebRTCICETCPMuxAddress *string `json:"webrtcICETCPMuxAddress,omitempty"` // deprecated
WebRTCICEHostNAT1To1IPs *[]string `json:"webrtcICEHostNAT1To1IPs,omitempty"` // deprecated
Expand Down Expand Up @@ -405,6 +406,7 @@ func (conf *Conf) setDefaults() {
conf.WebRTCICEServers2 = []WebRTCICEServer{}
conf.WebRTCHandshakeTimeout = 10 * Duration(time.Second)
conf.WebRTCTrackGatherTimeout = 2 * Duration(time.Second)
conf.WebRTCSTUNGatherTimeout = 5 * Duration(time.Second)

// SRT server
conf.SRT = true
Expand Down
2 changes: 2 additions & 0 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ func (p *Core) createResources(initial bool) error {
AdditionalHosts: p.conf.WebRTCAdditionalHosts,
ICEServers: p.conf.WebRTCICEServers2,
HandshakeTimeout: p.conf.WebRTCHandshakeTimeout,
STUNGatherTimeout: p.conf.WebRTCSTUNGatherTimeout,
TrackGatherTimeout: p.conf.WebRTCTrackGatherTimeout,
ExternalCmdPool: p.externalCmdPool,
PathManager: p.pathManager,
Expand Down Expand Up @@ -816,6 +817,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
!reflect.DeepEqual(newConf.WebRTCAdditionalHosts, p.conf.WebRTCAdditionalHosts) ||
!reflect.DeepEqual(newConf.WebRTCICEServers2, p.conf.WebRTCICEServers2) ||
newConf.WebRTCHandshakeTimeout != p.conf.WebRTCHandshakeTimeout ||
newConf.WebRTCSTUNGatherTimeout != p.conf.WebRTCSTUNGatherTimeout ||
newConf.WebRTCTrackGatherTimeout != p.conf.WebRTCTrackGatherTimeout ||
closeMetrics ||
closePathManager ||
Expand Down
2 changes: 2 additions & 0 deletions internal/protocols/webrtc/peer_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type PeerConnection struct {
ICETCPMux ice.TCPMux
HandshakeTimeout conf.Duration
TrackGatherTimeout conf.Duration
STUNGatherTimeout conf.Duration
LocalRandomUDP bool
IPsFromInterfaces bool
IPsFromInterfacesList []string
Expand Down Expand Up @@ -136,6 +137,7 @@ func (co *PeerConnection) Start() error {
}

settingsEngine.SetNetworkTypes(networkTypes)
settingsEngine.SetSTUNGatherTimeout(time.Duration(co.STUNGatherTimeout))

mediaEngine := &webrtc.MediaEngine{}

Expand Down
1 change: 1 addition & 0 deletions internal/protocols/webrtc/peer_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestPeerConnectionCloseImmediately(t *testing.T) {
pc := &PeerConnection{
HandshakeTimeout: conf.Duration(10 * time.Second),
TrackGatherTimeout: conf.Duration(2 * time.Second),
STUNGatherTimeout: conf.Duration(5 * time.Second),
LocalRandomUDP: true,
IPsFromInterfaces: true,
Publish: false,
Expand Down
1 change: 1 addition & 0 deletions internal/servers/webrtc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ type Server struct {
ICEServers []conf.WebRTCICEServer
HandshakeTimeout conf.Duration
TrackGatherTimeout conf.Duration
STUNGatherTimeout conf.Duration
ExternalCmdPool *externalcmd.Pool
PathManager serverPathManager
Parent serverParent
Expand Down
5 changes: 5 additions & 0 deletions internal/servers/webrtc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func initializeTestServer(t *testing.T) *Server {
ICEServers: []conf.WebRTCICEServer{},
HandshakeTimeout: conf.Duration(10 * time.Second),
TrackGatherTimeout: conf.Duration(2 * time.Second),
STUNGatherTimeout: conf.Duration(5 * time.Second),
ExternalCmdPool: nil,
PathManager: pm,
Parent: test.NilLogger,
Expand Down Expand Up @@ -187,6 +188,7 @@ func TestServerOptionsICEServer(t *testing.T) {
}},
HandshakeTimeout: conf.Duration(10 * time.Second),
TrackGatherTimeout: conf.Duration(2 * time.Second),
STUNGatherTimeout: conf.Duration(5 * time.Second),
ExternalCmdPool: nil,
PathManager: pathManager,
Parent: test.NilLogger,
Expand Down Expand Up @@ -257,6 +259,7 @@ func TestServerPublish(t *testing.T) {
ICEServers: []conf.WebRTCICEServer{},
HandshakeTimeout: conf.Duration(10 * time.Second),
TrackGatherTimeout: conf.Duration(2 * time.Second),
STUNGatherTimeout: conf.Duration(5 * time.Second),
ExternalCmdPool: nil,
PathManager: pathManager,
Parent: test.NilLogger,
Expand Down Expand Up @@ -544,6 +547,7 @@ func TestServerRead(t *testing.T) {
ICEServers: []conf.WebRTCICEServer{},
HandshakeTimeout: conf.Duration(10 * time.Second),
TrackGatherTimeout: conf.Duration(2 * time.Second),
STUNGatherTimeout: conf.Duration(5 * time.Second),
ExternalCmdPool: nil,
PathManager: pathManager,
Parent: test.NilLogger,
Expand Down Expand Up @@ -632,6 +636,7 @@ func TestServerReadNotFound(t *testing.T) {
ICEServers: []conf.WebRTCICEServer{},
HandshakeTimeout: conf.Duration(10 * time.Second),
TrackGatherTimeout: conf.Duration(2 * time.Second),
STUNGatherTimeout: conf.Duration(5 * time.Second),
ExternalCmdPool: nil,
PathManager: pm,
Parent: test.NilLogger,
Expand Down
2 changes: 2 additions & 0 deletions internal/servers/webrtc/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (s *session) runPublish() (int, error) {
ICEServers: iceServers,
HandshakeTimeout: s.parent.HandshakeTimeout,
TrackGatherTimeout: s.parent.TrackGatherTimeout,
STUNGatherTimeout: s.parent.STUNGatherTimeout,
IPsFromInterfaces: s.ipsFromInterfaces,
IPsFromInterfacesList: s.ipsFromInterfacesList,
AdditionalHosts: s.additionalHosts,
Expand Down Expand Up @@ -271,6 +272,7 @@ func (s *session) runRead() (int, error) {
ICEServers: iceServers,
HandshakeTimeout: s.parent.HandshakeTimeout,
TrackGatherTimeout: s.parent.TrackGatherTimeout,
STUNGatherTimeout: s.parent.STUNGatherTimeout,
IPsFromInterfaces: s.ipsFromInterfaces,
IPsFromInterfacesList: s.ipsFromInterfacesList,
AdditionalHosts: s.additionalHosts,
Expand Down
1 change: 1 addition & 0 deletions internal/staticsources/webrtc/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestSource(t *testing.T) {
Publish: true,
HandshakeTimeout: conf.Duration(10 * time.Second),
TrackGatherTimeout: conf.Duration(2 * time.Second),
STUNGatherTimeout: conf.Duration(5 * time.Second),
OutgoingTracks: outgoingTracks,
Log: test.NilLogger,
}
Expand Down
2 changes: 2 additions & 0 deletions mediamtx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ webrtcICEServers2: []
webrtcHandshakeTimeout: 10s
# Maximum time to gather video tracks.
webrtcTrackGatherTimeout: 2s
# The maximum time to gather STUN candidates.
webrtcSTUNGatherTimeout: 5s

###############################################
# Global settings -> SRT server
Expand Down