mirror of
https://github.com/bluenviron/mediamtx
synced 2025-02-01 12:11:47 +00:00
move automatic udp port selection into gortsplib
This commit is contained in:
parent
0b99a2fddc
commit
985d1613cd
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.12
|
||||
require (
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
|
||||
github.com/aler9/gortsplib v0.0.0-20200919120125-3cee9afbf0af
|
||||
github.com/aler9/gortsplib v0.0.0-20200920093758-10469faa0777
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/stretchr/testify v1.6.1
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
||||
|
4
go.sum
4
go.sum
@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/aler9/gortsplib v0.0.0-20200919120125-3cee9afbf0af h1:cC0wbPnVEzZn+quuMaHwrpdjo4loj2vD0T7NMypw6Kk=
|
||||
github.com/aler9/gortsplib v0.0.0-20200919120125-3cee9afbf0af/go.mod h1:IQy51zikcH4wQFNwYPHtC0+HTcPlahJcxcYiMqlCyiw=
|
||||
github.com/aler9/gortsplib v0.0.0-20200920093758-10469faa0777 h1:WpP46odBYEPXa1GLtGrf8W8gZGLohDJCJTYmlPJCo2w=
|
||||
github.com/aler9/gortsplib v0.0.0-20200920093758-10469faa0777/go.mod h1:IQy51zikcH4wQFNwYPHtC0+HTcPlahJcxcYiMqlCyiw=
|
||||
github.com/aler9/sdp-dirty/v3 v3.0.0-20200919115950-f1abc664f625 h1:A3upkpYzceQTuBPvVleu1zd6R8jInhg5ifimSO7ku/o=
|
||||
github.com/aler9/sdp-dirty/v3 v3.0.0-20200919115950-f1abc664f625/go.mod h1:5bO/aUQr9m3OasDatNNcVqKAgs7r5hgGXmszWHaC6mI=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
|
29
proxy.go
29
proxy.go
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -189,27 +188,15 @@ func (s *proxy) runUDP(conn *gortsplib.ConnClient) bool {
|
||||
var rtcpReads []gortsplib.UDPReadFunc
|
||||
|
||||
for _, track := range s.tracks {
|
||||
for {
|
||||
// choose two consecutive ports in range 65535-10000
|
||||
// rtp must be even and rtcp odd
|
||||
rtpPort := (rand.Intn((65535-10000)/2) * 2) + 10000
|
||||
rtcpPort := rtpPort + 1
|
||||
|
||||
rtpRead, rtcpRead, _, err := conn.SetupUDP(s.pathConf.sourceUrl, track, rtpPort, rtcpPort)
|
||||
if err != nil {
|
||||
if isBindError(err) {
|
||||
continue // retry
|
||||
}
|
||||
|
||||
conn.Close()
|
||||
s.path.log("proxy ERR: %s", err)
|
||||
return true
|
||||
}
|
||||
|
||||
rtpReads = append(rtpReads, rtpRead)
|
||||
rtcpReads = append(rtcpReads, rtcpRead)
|
||||
break
|
||||
rtpRead, rtcpRead, _, err := conn.SetupUDP(s.pathConf.sourceUrl, track, 0, 0)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
s.path.log("proxy ERR: %s", err)
|
||||
return true
|
||||
}
|
||||
|
||||
rtpReads = append(rtpReads, rtpRead)
|
||||
rtcpReads = append(rtcpReads, rtcpRead)
|
||||
}
|
||||
|
||||
_, err := conn.Play(s.pathConf.sourceUrl)
|
||||
|
12
utils.go
12
utils.go
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -135,17 +134,6 @@ func checkPathName(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func isBindError(err error) bool {
|
||||
if nerr, ok := err.(*net.OpError); ok {
|
||||
if serr, ok := nerr.Err.(*os.SyscallError); ok {
|
||||
if serr.Syscall == "bind" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type udpPublisherAddr struct {
|
||||
ip [net.IPv6len]byte // use a fixed-size array to enable the equality operator
|
||||
port int
|
||||
|
Loading…
Reference in New Issue
Block a user