restore Windows compatibility (#4860)

This commit is contained in:
Alessandro Ros
2025-08-12 13:00:45 +02:00
committed by GitHub
parent 03623799f5
commit afff90f00e
8 changed files with 19 additions and 40 deletions

2
go.mod
View File

@@ -10,7 +10,7 @@ require (
github.com/alecthomas/kong v1.12.1
github.com/asticode/go-astits v1.13.0
github.com/bluenviron/gohlslib/v2 v2.2.2
github.com/bluenviron/gortsplib/v4 v4.16.1
github.com/bluenviron/gortsplib/v4 v4.16.2
github.com/bluenviron/mediacommon/v2 v2.4.1
github.com/datarhei/gosrt v0.9.0
github.com/fsnotify/fsnotify v1.9.0

4
go.sum
View File

@@ -35,8 +35,8 @@ github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c h1:8XZeJrs4+ZYh
github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c/go.mod h1:x1vxHcL/9AVzuk5HOloOEPrtJY0MaalYr78afXZ+pWI=
github.com/bluenviron/gohlslib/v2 v2.2.2 h1:Q86VloPjwONKF8pu6jSEh9ENm4UzdMl5SzYvtjneL5k=
github.com/bluenviron/gohlslib/v2 v2.2.2/go.mod h1:3Lby/VMDD/cN0B3uJPd3bEEiJZ34LqXs71FEvN/fq2k=
github.com/bluenviron/gortsplib/v4 v4.16.1 h1:1uqWp+0we2OKp/fWaWXhBSpqdhEtZSk7g96nAA3iayk=
github.com/bluenviron/gortsplib/v4 v4.16.1/go.mod h1:Vm07yUMys9XKnuZJLfTT8zluAN2n9ZOtz40Xb8RKh+8=
github.com/bluenviron/gortsplib/v4 v4.16.2 h1:10HaMsorjW13gscLp3R7Oj41ck2i1EHIUYCNWD2wpkI=
github.com/bluenviron/gortsplib/v4 v4.16.2/go.mod h1:Vm07yUMys9XKnuZJLfTT8zluAN2n9ZOtz40Xb8RKh+8=
github.com/bluenviron/mediacommon/v2 v2.4.1 h1:PsKrO/c7hDjXxiOGRUBsYtMGNb4lKWIFea6zcOchoVs=
github.com/bluenviron/mediacommon/v2 v2.4.1/go.mod h1:a6MbPmXtYda9mKibKVMZlW20GYLLrX2R7ZkUE+1pwV0=
github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ=

View File

@@ -9,50 +9,16 @@ import (
"time"
"github.com/bluenviron/gortsplib/v4/pkg/multicast"
"github.com/bluenviron/gortsplib/v4/pkg/readbuffer"
"github.com/bluenviron/mediamtx/internal/restrictnetwork"
)
type packetConn interface {
net.PacketConn
SetReadBuffer(bytes int) error
SyscallConn() (syscall.RawConn, error)
}
func setAndVerifyReadBufferSize(pc packetConn, v int) error {
rawConn, err := pc.SyscallConn()
if err != nil {
panic(err)
}
var err2 error
err = rawConn.Control(func(fd uintptr) {
err2 = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, v)
if err2 != nil {
return
}
var v2 int
v2, err2 = syscall.GetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
if err2 != nil {
return
}
if v2 != (v * 2) {
err2 = fmt.Errorf("unable to set read buffer size to %v - check that net.core.rmem_max is greater than %v", v, v)
return
}
})
if err != nil {
return err
}
if err2 != nil {
return err2
}
return nil
}
type udpConn struct {
pc net.PacketConn
sourceIP net.IP
@@ -184,11 +150,24 @@ func CreateConn(u *url.URL, udpReadBufferSize int) (net.Conn, error) {
}
if udpReadBufferSize != 0 {
err = setAndVerifyReadBufferSize(pc, udpReadBufferSize)
err = pc.SetReadBuffer(udpReadBufferSize)
if err != nil {
pc.Close()
return nil, err
}
var v int
v, err = readbuffer.ReadBuffer(pc)
if err != nil {
pc.Close()
return nil, err
}
if v != udpReadBufferSize {
pc.Close()
return nil, fmt.Errorf("unable to set read buffer size to %v, check that the operating system allows that",
udpReadBufferSize)
}
}
return &udpConn{pc: pc, sourceIP: sourceIP}, nil