Skip to content

Commit 93d1306

Browse files
client: add UDPSourcePortRange parameter (#988)
Co-authored-by: Bjørn Steen Saethre <[email protected]>
1 parent ad9b020 commit 93d1306

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ type Client struct {
497497
DisableRTCPSenderReports bool
498498
// explicitly request back channels to the server.
499499
RequestBackChannels bool
500+
// Range of ports used as source port in outgoing UDP packets.
501+
// It defaults to [10000, 65535].
502+
UDPSourcePortRange [2]uint16
500503

501504
//
502505
// system functions (all optional)
@@ -614,6 +617,9 @@ func (c *Client) Start() error {
614617
if c.UserAgent == "" {
615618
c.UserAgent = clientUserAgent
616619
}
620+
if c.UDPSourcePortRange == [2]uint16{0, 0} {
621+
c.UDPSourcePortRange = [2]uint16{10000, 65535}
622+
}
617623

618624
// system functions
619625
if c.DialContext == nil {

client_media.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ func createUDPListenerPair(
7777
return l1, l2, nil
7878
}
7979

80-
// pick two consecutive ports in range 65535-10000
81-
// RTP port must be even and RTCP port odd
80+
// pick two consecutive ports.
81+
// RTP port must be even and RTCP port odd.
8282
for {
83-
v, err := randInRange((65535 - 10000) / 2)
83+
v, err := randInRange(int((c.UDPSourcePortRange[1] - c.UDPSourcePortRange[0]) / 2))
8484
if err != nil {
8585
return nil, nil, err
8686
}
8787

88-
rtpPort := v*2 + 10000
88+
rtpPort := v*2 + int(c.UDPSourcePortRange[0])
8989
rtcpPort := rtpPort + 1
9090

9191
l1 := &clientUDPListener{

0 commit comments

Comments
 (0)