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

SRT 1.4.2 Support #17

Open
wants to merge 3 commits into
base: master
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
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/openfresh/gosrt

go 1.15

require golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4
4 changes: 2 additions & 2 deletions srt/ipsock_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// general. Unfortunately, we need to run on kernels built without
// IPv6 support too. So probe the kernel to figure it out.
func (p *ipStackCapabilities) probe() {
s, err := srtSocket(syscall.AF_INET, syscall.SOCK_DGRAM, 0)
s, err := srtSocket()
if err == nil {
poll.CloseFunc(s)
p.ipv4Enabled = true
Expand All @@ -45,7 +45,7 @@ func (p *ipStackCapabilities) probe() {
{laddr: SRTAddr{IP: net.IPv4(127, 0, 0, 1)}, value: 0},
}
for i := range probes {
s, err := srtSocket(syscall.AF_INET6, syscall.SOCK_DGRAM, 0)
s, err := srtSocket()
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions srt/sock_closexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

// Wrapper around the socket system call that marks the returned file
// descriptor as nonblocking.
func srtSocket(family, sotype, proto int) (int, error) {
s, err := socketFunc(family, sotype, proto)
func srtSocket() (int, error) {
s, err := socketFunc()
if err != nil {
return -1, os.NewSyscallError("socket", err)
}
Expand Down
2 changes: 1 addition & 1 deletion srt/sock_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type sockaddr interface {

// socket returns a network file descriptor
func socket(ctx context.Context, net string, family, sotype, proto int, ipv6only bool, laddr, raddr sockaddr) (fd *netFD, err error) {
s, err := srtSocket(family, sotype, proto)
s, err := srtSocket()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions srtapi/srtapi_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ func connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) {
return
}

func socket(domain int, typ int, proto int) (fd int, err error) {
func socket() (fd int, err error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
fd = int(C.srt_socket(C.int(domain), C.int(typ), C.int(proto)))
fd = int(C.srt_create_socket())
if fd == APIError {
err = getLastError()
}
Expand Down
7 changes: 2 additions & 5 deletions srtapi/srtapi_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,8 @@ func SetsockflagBool(fd, opt int, value bool) (err error) {
}

// Socket call srt_socket
func Socket(domain, typ, proto int) (fd int, err error) {
if domain == syscall.AF_INET6 && syscall.SocketDisableIPv6 {
return -1, syscall.EAFNOSUPPORT
}
fd, err = socket(domain, typ, proto)
func Socket() (fd int, err error) {
fd, err = socket()
return
}

Expand Down
114 changes: 59 additions & 55 deletions srtapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ type SrtEpollEvent C.SRT_EPOLL_EVENT

//lint:ignore U1000 we want to use it to calculate size
var rsa syscall.RawSockaddrAny

//lint:ignore U1000 we want to use it to calculate size
var rs4 syscall.RawSockaddrInet4

//lint:ignore U1000 we want to use it to calculate size
var rs6 syscall.RawSockaddrInet6

Expand All @@ -46,61 +48,63 @@ const (
StatusNonexist = C.SRTS_NONEXIST
)

const SrtVersion = C.SRT_VERSION_STRING

// SRT socket options
const (
OptionMss = C.SRTO_MSS
OptionSndsyn = C.SRTO_SNDSYN
OptionRcvsyn = C.SRTO_RCVSYN
OptionIsn = C.SRTO_ISN
OptionFc = C.SRTO_FC
OptionSndbuf = C.SRTO_SNDBUF
OptionRcvbuf = C.SRTO_RCVBUF
OptionLinger = C.SRTO_LINGER
OptionUDPSndbuf = C.SRTO_UDP_SNDBUF
OptionUDPRcvbuf = C.SRTO_UDP_RCVBUF
OptionRendezvous = C.SRTO_RENDEZVOUS
OptionSndtimeo = C.SRTO_SNDTIMEO
OptionRcvtimeo = C.SRTO_RCVTIMEO
OptionReuseaddr = C.SRTO_REUSEADDR
OptionMaxbw = C.SRTO_MAXBW
OptionState = C.SRTO_STATE
OptionEvent = C.SRTO_EVENT
OptionSnddata = C.SRTO_SNDDATA
OptionRcvdata = C.SRTO_RCVDATA
OptionSender = C.SRTO_SENDER
OptionTsbpdmode = C.SRTO_TSBPDMODE
OptionLatency = C.SRTO_LATENCY
OptionTsbpddelay = C.SRTO_TSBPDDELAY
OptionInputbw = C.SRTO_INPUTBW
OptionOheadbw = C.SRTO_OHEADBW
OptionPassphrase = C.SRTO_PASSPHRASE
OptionPbkeylen = C.SRTO_PBKEYLEN
OptionKmstate = C.SRTO_KMSTATE
OptionIpttl = C.SRTO_IPTTL
OptionIptos = C.SRTO_IPTOS
OptionTlpktdrop = C.SRTO_TLPKTDROP
OptionSnddropdelay = C.SRTO_SNDDROPDELAY
OptionNakreport = C.SRTO_NAKREPORT
OptionVersion = C.SRTO_VERSION
OptionPeerversion = C.SRTO_PEERVERSION
OptionConntimeo = C.SRTO_CONNTIMEO
OptionSndkmstate = C.SRTO_SNDKMSTATE
OptionRcvkmstate = C.SRTO_RCVKMSTATE
OptionLossmaxttl = C.SRTO_LOSSMAXTTL
OptionRcvlatency = C.SRTO_RCVLATENCY
OptionPeerlatency = C.SRTO_PEERLATENCY
OptionMinversion = C.SRTO_MINVERSION
OptionStreamid = C.SRTO_STREAMID
OptionCongestion = C.SRTO_CONGESTION
OptionMessageapi = C.SRTO_MESSAGEAPI
OptionPayloadsize = C.SRTO_PAYLOADSIZE
OptionTranstype = C.SRTO_TRANSTYPE
OptionKmrefreshrate = C.SRTO_KMREFRESHRATE
OptionKmpreannounce = C.SRTO_KMPREANNOUNCE
OptionMss = C.SRTO_MSS
OptionSndsyn = C.SRTO_SNDSYN
OptionRcvsyn = C.SRTO_RCVSYN
OptionIsn = C.SRTO_ISN
OptionFc = C.SRTO_FC
OptionSndbuf = C.SRTO_SNDBUF
OptionRcvbuf = C.SRTO_RCVBUF
OptionLinger = C.SRTO_LINGER
OptionUDPSndbuf = C.SRTO_UDP_SNDBUF
OptionUDPRcvbuf = C.SRTO_UDP_RCVBUF
OptionRendezvous = C.SRTO_RENDEZVOUS
OptionSndtimeo = C.SRTO_SNDTIMEO
OptionRcvtimeo = C.SRTO_RCVTIMEO
OptionReuseaddr = C.SRTO_REUSEADDR
OptionMaxbw = C.SRTO_MAXBW
OptionState = C.SRTO_STATE
OptionEvent = C.SRTO_EVENT
OptionSnddata = C.SRTO_SNDDATA
OptionRcvdata = C.SRTO_RCVDATA
OptionSender = C.SRTO_SENDER
OptionTsbpdmode = C.SRTO_TSBPDMODE
OptionLatency = C.SRTO_LATENCY
// OptionTsbpddelay = C.SRTO_TSBPDDELAY
OptionInputbw = C.SRTO_INPUTBW
OptionOheadbw = C.SRTO_OHEADBW
OptionPassphrase = C.SRTO_PASSPHRASE
OptionPbkeylen = C.SRTO_PBKEYLEN
OptionKmstate = C.SRTO_KMSTATE
OptionIpttl = C.SRTO_IPTTL
OptionIptos = C.SRTO_IPTOS
OptionTlpktdrop = C.SRTO_TLPKTDROP
OptionSnddropdelay = C.SRTO_SNDDROPDELAY
OptionNakreport = C.SRTO_NAKREPORT
OptionVersion = C.SRTO_VERSION
OptionPeerversion = C.SRTO_PEERVERSION
OptionConntimeo = C.SRTO_CONNTIMEO
OptionSndkmstate = C.SRTO_SNDKMSTATE
OptionRcvkmstate = C.SRTO_RCVKMSTATE
OptionLossmaxttl = C.SRTO_LOSSMAXTTL
OptionRcvlatency = C.SRTO_RCVLATENCY
OptionPeerlatency = C.SRTO_PEERLATENCY
OptionMinversion = C.SRTO_MINVERSION
OptionStreamid = C.SRTO_STREAMID
OptionCongestion = C.SRTO_CONGESTION
OptionMessageapi = C.SRTO_MESSAGEAPI
OptionPayloadsize = C.SRTO_PAYLOADSIZE
OptionTranstype = C.SRTO_TRANSTYPE
OptionKmrefreshrate = C.SRTO_KMREFRESHRATE
OptionKmpreannounce = C.SRTO_KMPREANNOUNCE
OptionEnforcedencryption = C.SRTO_ENFORCEDENCRYPTION
OptionIpv60only = C.SRTO_IPV6ONLY
OptionPeeridletimeo = C.SRTO_PEERIDLETIMEO
OptionPacketfilter = C.SRTO_PACKETFILTER
OptionIpv60only = C.SRTO_IPV6ONLY
OptionPeeridletimeo = C.SRTO_PEERIDLETIMEO
OptionPacketfilter = C.SRTO_PACKETFILTER
)

// SRT trans type
Expand Down Expand Up @@ -158,6 +162,6 @@ const (

// SRT_EPOLL_FLAGS
const (
EpollEnableEmpty = C.SRT_EPOLL_ENABLE_EMPTY
EpollEnableOutputcheck = C.SRT_EPOLL_ENABLE_OUTPUTCHECK
)
EpollEnableEmpty = C.SRT_EPOLL_ENABLE_EMPTY
EpollEnableOutputcheck = C.SRT_EPOLL_ENABLE_OUTPUTCHECK
)