Documentation
¶
Index ¶
- Constants
- Variables
- func CleanupSRT()
- func CreateAddrInet(name string, port uint16) (*C.struct_sockaddr, int, error)
- func InitSRT()
- func SrtSetLogHandler(cb LogCallBackFunc)
- func SrtSetLogLevel(level SrtLogLevel)
- func SrtUnsetLogHandler()
- type ConnectCallbackFunc
- type ListenCallbackFunc
- type LogCallBackFunc
- type PollMode
- type SRTErrno
- type SrtConnectTimeout
- type SrtConnectionRejected
- type SrtEpollTimeout
- type SrtInvalidSock
- type SrtLogLevel
- type SrtRendezvousUnbound
- type SrtSockConnected
- type SrtSocket
- func (s SrtSocket) Accept() (*SrtSocket, *net.UDPAddr, error)
- func (s *SrtSocket) Close()
- func (s *SrtSocket) Connect() error
- func (s SrtSocket) GetSockOptBool(opt int) (bool, error)
- func (s SrtSocket) GetSockOptByte(opt int) (byte, error)
- func (s SrtSocket) GetSockOptInt(opt int) (int, error)
- func (s SrtSocket) GetSockOptInt64(opt int) (int64, error)
- func (s SrtSocket) GetSockOptString(opt int) (string, error)
- func (s SrtSocket) GetSocket() C.int
- func (s *SrtSocket) Listen(backlog int) error
- func (s SrtSocket) Mode() int
- func (s SrtSocket) PacketSize() int
- func (s SrtSocket) PollTimeout() time.Duration
- func (s SrtSocket) Read(b []byte) (n int, err error)
- func (s SrtSocket) SetConnectCallback(cb ConnectCallbackFunc)
- func (s *SrtSocket) SetDeadline(deadline time.Time)
- func (s SrtSocket) SetListenCallback(cb ListenCallbackFunc)
- func (s *SrtSocket) SetPollTimeout(pollTimeout time.Duration)
- func (s *SrtSocket) SetReadDeadline(deadline time.Time)
- func (s SrtSocket) SetRejectReason(value int) error
- func (s SrtSocket) SetSockOptBool(opt int, value bool) error
- func (s SrtSocket) SetSockOptByte(opt int, value byte) error
- func (s SrtSocket) SetSockOptInt(opt int, value int) error
- func (s SrtSocket) SetSockOptInt64(opt int, value int64) error
- func (s SrtSocket) SetSockOptString(opt int, value string) error
- func (s *SrtSocket) SetWriteDeadline(deadline time.Time)
- func (s SrtSocket) Stats() (*SrtStats, error)
- func (s SrtSocket) Write(b []byte) (n int, err error)
- type SrtSocketClosed
- type SrtStats
Constants ¶
const ( Unknown = SRTErrno(C.SRT_EUNKNOWN) Success = SRTErrno(C.SRT_SUCCESS) //Major: SETUP EConnSetup = SRTErrno(C.SRT_ECONNSETUP) ENoServer = SRTErrno(C.SRT_ENOSERVER) EConnRej = SRTErrno(C.SRT_ECONNREJ) ESockFail = SRTErrno(C.SRT_ESOCKFAIL) ESecFail = SRTErrno(C.SRT_ESECFAIL) ESClosed = SRTErrno(C.SRT_ESCLOSED) //Major: CONNECTION EConnFail = SRTErrno(C.SRT_ECONNFAIL) EConnLost = SRTErrno(C.SRT_ECONNLOST) ENoConn = SRTErrno(C.SRT_ENOCONN) //Major: SYSTEMRES EResource = SRTErrno(C.SRT_ERESOURCE) EThread = SRTErrno(C.SRT_ETHREAD) EnoBuf = SRTErrno(C.SRT_ENOBUF) ESysObj = SRTErrno(C.SRT_ESYSOBJ) //Major: FILESYSTEM EFile = SRTErrno(C.SRT_EFILE) EInvRdOff = SRTErrno(C.SRT_EINVRDOFF) ERdPerm = SRTErrno(C.SRT_ERDPERM) EInvWrOff = SRTErrno(C.SRT_EINVWROFF) EWrPerm = SRTErrno(C.SRT_EWRPERM) //Major: NOTSUP EInvOp = SRTErrno(C.SRT_EINVOP) EBoundSock = SRTErrno(C.SRT_EBOUNDSOCK) EConnSock = SRTErrno(C.SRT_ECONNSOCK) EInvParam = SRTErrno(C.SRT_EINVPARAM) EInvSock = SRTErrno(C.SRT_EINVSOCK) EUnboundSock = SRTErrno(C.SRT_EUNBOUNDSOCK) ENoListen = SRTErrno(C.SRT_ENOLISTEN) ERdvNoServ = SRTErrno(C.SRT_ERDVNOSERV) ERdvUnbound = SRTErrno(C.SRT_ERDVUNBOUND) EInvalMsgAPI = SRTErrno(C.SRT_EINVALMSGAPI) EInvalBufferAPI = SRTErrno(C.SRT_EINVALBUFFERAPI) EDupListen = SRTErrno(C.SRT_EDUPLISTEN) ELargeMsg = SRTErrno(C.SRT_ELARGEMSG) EInvPollID = SRTErrno(C.SRT_EINVPOLLID) EPollEmpty = SRTErrno(C.SRT_EPOLLEMPTY) //EBindConflict = SRTErrno(C.SRT_EBINDCONFLICT) //Major: AGAIN EAsyncFAIL = SRTErrno(C.SRT_EASYNCFAIL) EAsyncSND = SRTErrno(C.SRT_EASYNCSND) EAsyncRCV = SRTErrno(C.SRT_EASYNCRCV) ETimeout = SRTErrno(C.SRT_ETIMEOUT) ECongest = SRTErrno(C.SRT_ECONGEST) //Major: PEERERROR EPeer = SRTErrno(C.SRT_EPEERERR) )
Shadows SRT_ERRNO srtcore/srt.h line 490+
const ( ModeRead = PollMode(iota) ModeWrite // ModeReadWrite addresses the read and the write side at once. It must be // its own value: ModeRead is 0, so the expression ModeRead+ModeWrite is // just ModeWrite and cannot be distinguished from it. ModeReadWrite )
const ( ModeFailure = iota ModeListener ModeCaller ModeRendezvouz )
SRT Socket mode
const ( SRTO_TRANSTYPE = C.SRTO_TRANSTYPE SRTO_MAXBW = C.SRTO_MAXBW SRTO_PBKEYLEN = C.SRTO_PBKEYLEN SRTO_PASSPHRASE = C.SRTO_PASSPHRASE SRTO_MSS = C.SRTO_MSS SRTO_FC = C.SRTO_FC SRTO_SNDBUF = C.SRTO_SNDBUF SRTO_RCVBUF = C.SRTO_RCVBUF SRTO_IPTTL = C.SRTO_IPTTL SRTO_IPTOS = C.SRTO_IPTOS SRTO_INPUTBW = C.SRTO_INPUTBW SRTO_OHEADBW = C.SRTO_OHEADBW SRTO_LATENCY = C.SRTO_LATENCY SRTO_TSBPDMODE = C.SRTO_TSBPDMODE SRTO_TLPKTDROP = C.SRTO_TLPKTDROP SRTO_SNDDROPDELAY = C.SRTO_SNDDROPDELAY SRTO_NAKREPORT = C.SRTO_NAKREPORT SRTO_CONNTIMEO = C.SRTO_CONNTIMEO SRTO_LOSSMAXTTL = C.SRTO_LOSSMAXTTL SRTO_RCVLATENCY = C.SRTO_RCVLATENCY SRTO_PEERLATENCY = C.SRTO_PEERLATENCY SRTO_MINVERSION = C.SRTO_MINVERSION SRTO_STREAMID = C.SRTO_STREAMID SRTO_CONGESTION = C.SRTO_CONGESTION SRTO_MESSAGEAPI = C.SRTO_MESSAGEAPI SRTO_PAYLOADSIZE = C.SRTO_PAYLOADSIZE SRTO_KMREFRESHRATE = C.SRTO_KMREFRESHRATE SRTO_KMPREANNOUNCE = C.SRTO_KMPREANNOUNCE SRTO_ENFORCEDENCRYPTION = C.SRTO_ENFORCEDENCRYPTION SRTO_PEERIDLETIMEO = C.SRTO_PEERIDLETIMEO SRTO_PACKETFILTER = C.SRTO_PACKETFILTER SRTO_STATE = C.SRTO_STATE )
Variables ¶
var ( SRT_INVALID_SOCK = C.get_srt_invalid_sock() SRT_ERROR = C.get_srt_error() SRTS_CONNECTED = C.SRTS_CONNECTED )
Static consts from library
var ( // Start of range for predefined rejection reasons RejectionReasonPredefined = int(C.get_srt_error_reject_predefined()) // General syntax error in the SocketID specification (also a fallback code for undefined cases) RejectionReasonBadRequest = RejectionReasonPredefined + 400 RejectionReasonUnauthorized = RejectionReasonPredefined + 401 // The server is too heavily loaded, or you have exceeded credits for accessing the service and the resource. RejectionReasonOverload = RejectionReasonPredefined + 402 // Access denied to the resource by any kind of reason RejectionReasonForbidden = RejectionReasonPredefined + 403 // Resource not found at this time. RejectionReasonNotFound = RejectionReasonPredefined + 404 // The mode specified in `m` key in StreamID is not supported for this request. RejectionReasonBadMode = RejectionReasonPredefined + 405 // The requested parameters specified in SocketID cannot be satisfied for the requested resource. Also when m=publish and the data format is not acceptable. RejectionReasonUnacceptable = RejectionReasonPredefined + 406 // Start of range for application defined rejection reasons RejectionReasonUserDefined = int(C.get_srt_error_reject_predefined()) )
Rejection reasons
var SocketOptions = []socketOption{ {"transtype", 0, SRTO_TRANSTYPE, bindingPre, tTransType}, {"maxbw", 0, SRTO_MAXBW, bindingPre, tInteger64}, {"pbkeylen", 0, SRTO_PBKEYLEN, bindingPre, tInteger32}, {"passphrase", 0, SRTO_PASSPHRASE, bindingPre, tString}, {"mss", 0, SRTO_MSS, bindingPre, tInteger32}, {"fc", 0, SRTO_FC, bindingPre, tInteger32}, {"sndbuf", 0, SRTO_SNDBUF, bindingPre, tInteger32}, {"rcvbuf", 0, SRTO_RCVBUF, bindingPre, tInteger32}, {"ipttl", 0, SRTO_IPTTL, bindingPre, tInteger32}, {"iptos", 0, SRTO_IPTOS, bindingPre, tInteger32}, {"inputbw", 0, SRTO_INPUTBW, bindingPost, tInteger64}, {"oheadbw", 0, SRTO_OHEADBW, bindingPost, tInteger32}, {"latency", 0, SRTO_LATENCY, bindingPre, tInteger32}, {"tsbpdmode", 0, SRTO_TSBPDMODE, bindingPre, tBoolean}, {"tlpktdrop", 0, SRTO_TLPKTDROP, bindingPre, tBoolean}, {"snddropdelay", 0, SRTO_SNDDROPDELAY, bindingPost, tInteger32}, {"nakreport", 0, SRTO_NAKREPORT, bindingPre, tBoolean}, {"conntimeo", 0, SRTO_CONNTIMEO, bindingPre, tInteger32}, {"lossmaxttl", 0, SRTO_LOSSMAXTTL, bindingPre, tInteger32}, {"rcvlatency", 0, SRTO_RCVLATENCY, bindingPre, tInteger32}, {"peerlatency", 0, SRTO_PEERLATENCY, bindingPre, tInteger32}, {"minversion", 0, SRTO_MINVERSION, bindingPre, tInteger32}, {"streamid", 0, SRTO_STREAMID, bindingPre, tString}, {"congestion", 0, SRTO_CONGESTION, bindingPre, tString}, {"messageapi", 0, SRTO_MESSAGEAPI, bindingPre, tBoolean}, {"payloadsize", 0, SRTO_PAYLOADSIZE, bindingPre, tInteger32}, {"kmrefreshrate", 0, SRTO_KMREFRESHRATE, bindingPre, tInteger32}, {"kmpreannounce", 0, SRTO_KMPREANNOUNCE, bindingPre, tInteger32}, {"enforcedencryption", 0, SRTO_ENFORCEDENCRYPTION, bindingPre, tBoolean}, {"peeridletimeo", 0, SRTO_PEERIDLETIMEO, bindingPre, tInteger32}, {"packetfilter", 0, SRTO_PACKETFILTER, bindingPre, tString}, }
List of possible srt socket options
Functions ¶
func CleanupSRT ¶
func CleanupSRT()
CleanupSRT - Cleanup SRT lib
Stops the internal poll server before calling srt_cleanup, so SRT is not torn down while a goroutine is still waiting inside srt_epoll_uwait. Programs should call this before exiting: SRT runs its own receive-queue threads, and letting the process exit while they are live lets libsrt's global destructors free state underneath them.
Note that srt_cleanup is reference counted against srt_startup, so this only takes effect once the counts balance.
func CreateAddrInet ¶
func SrtSetLogHandler ¶
func SrtSetLogHandler(cb LogCallBackFunc)
func SrtSetLogLevel ¶
func SrtSetLogLevel(level SrtLogLevel)
func SrtUnsetLogHandler ¶
func SrtUnsetLogHandler()
Types ¶
type ConnectCallbackFunc ¶
ConnectCallbackFunc specifies a function to be called after a socket or connection in a group has failed.
type ListenCallbackFunc ¶
type ListenCallbackFunc func(socket *SrtSocket, version int, addr *net.UDPAddr, streamid string) bool
ListenCallbackFunc specifies a function to be called before a connecting socket is passed to accept
type LogCallBackFunc ¶
type LogCallBackFunc func(level SrtLogLevel, file string, line int, area, message string)
type SRTErrno ¶
type SRTErrno int
Based of off golang errno handling: https://cs.opensource.google/go/go/+/refs/tags/go1.16.6:src/syscall/syscall_unix.go;l=114
type SrtConnectTimeout ¶
type SrtConnectTimeout struct{}
func (*SrtConnectTimeout) Error ¶
func (m *SrtConnectTimeout) Error() string
type SrtConnectionRejected ¶
type SrtConnectionRejected struct{}
func (*SrtConnectionRejected) Error ¶
func (m *SrtConnectionRejected) Error() string
type SrtEpollTimeout ¶
type SrtEpollTimeout struct{}
func (*SrtEpollTimeout) Error ¶
func (m *SrtEpollTimeout) Error() string
func (*SrtEpollTimeout) Temporary ¶
func (m *SrtEpollTimeout) Temporary() bool
func (*SrtEpollTimeout) Timeout ¶
func (m *SrtEpollTimeout) Timeout() bool
type SrtInvalidSock ¶
type SrtInvalidSock struct{}
func (*SrtInvalidSock) Error ¶
func (m *SrtInvalidSock) Error() string
type SrtLogLevel ¶
type SrtLogLevel int
const ( // SrtLogLevelEmerg = int(C.LOG_EMERG) // SrtLogLevelAlert = int(C.LOG_ALERT) SrtLogLevelCrit SrtLogLevel = SrtLogLevel(C.LOG_CRIT) SrtLogLevelErr SrtLogLevel = SrtLogLevel(C.LOG_ERR) SrtLogLevelWarning SrtLogLevel = SrtLogLevel(C.LOG_WARNING) SrtLogLevelNotice SrtLogLevel = SrtLogLevel(C.LOG_NOTICE) SrtLogLevelInfo SrtLogLevel = SrtLogLevel(C.LOG_INFO) SrtLogLevelDebug SrtLogLevel = SrtLogLevel(C.LOG_DEBUG) SrtLogLevelTrace SrtLogLevel = SrtLogLevel(8) )
type SrtRendezvousUnbound ¶
type SrtRendezvousUnbound struct{}
func (*SrtRendezvousUnbound) Error ¶
func (m *SrtRendezvousUnbound) Error() string
type SrtSockConnected ¶
type SrtSockConnected struct{}
func (*SrtSockConnected) Error ¶
func (m *SrtSockConnected) Error() string
type SrtSocket ¶
type SrtSocket struct {
// contains filtered or unexported fields
}
SrtSocket - SRT socket
func NewSrtSocket ¶
NewSrtSocket - Create a new SRT Socket
func (SrtSocket) Accept ¶
Accept an incoming connection
The accept path deliberately mirrors Read and Write: try first, and only wait when SRT reports there is nothing pending. Waiting first is what made a listener lose connections. Sockets are registered edge-triggered, and libsrt collapses every connection that arrives between two srt_epoll_uwait calls into a single SRT_EPOLL_IN notice, which it then clears once reported. A backlog therefore produces exactly one readiness edge no matter how many connections it holds, and libsrt raises no further edge while the readiness bit is still set -- so a listener that accepted one connection and went back to waiting would never be woken for the rest, nor for any later arrival. Attempting the accept up front drains the backlog across successive calls without needing an edge that is never coming.
func (SrtSocket) GetSockOptBool ¶
GetSockOptBool - return bool value obtained with srt_getsockopt
func (SrtSocket) GetSockOptByte ¶
GetSockOptByte - return byte value obtained with srt_getsockopt
func (SrtSocket) GetSockOptInt ¶
GetSockOptInt - return int value obtained with srt_getsockopt
func (SrtSocket) GetSockOptInt64 ¶
GetSockOptInt64 - return int64 value obtained with srt_getsockopt
func (SrtSocket) GetSockOptString ¶
GetSockOptString - return string value obtained with srt_getsockopt
func (*SrtSocket) Listen ¶
Listen for incoming connections. The backlog setting defines how many sockets may be allowed to wait until they are accepted (excessive connection requests are rejected in advance)
func (SrtSocket) PacketSize ¶
PacketSize - Return packet size of the SRT socket
func (SrtSocket) PollTimeout ¶
PollTimeout - Return polling max time, for connect/read/write operations. Only applied when socket is in non-blocking mode.
func (SrtSocket) SetConnectCallback ¶
func (s SrtSocket) SetConnectCallback(cb ConnectCallbackFunc)
SetConnectCallback - set a function to be called after a socket or connection in a group has failed Note that the function is not guaranteed to be called if the socket is set to blocking mode.
func (*SrtSocket) SetDeadline ¶
func (SrtSocket) SetListenCallback ¶
func (s SrtSocket) SetListenCallback(cb ListenCallbackFunc)
SetListenCallback - set a function to be called early in the handshake before a client is handed to accept on a listening socket. The connection can be rejected by returning false from the callback. See examples/echo-receiver for more details.
func (*SrtSocket) SetPollTimeout ¶
SetPollTimeout - Sets polling max time, for connect/read/write operations. Only applied when socket is in non-blocking mode.
func (*SrtSocket) SetReadDeadline ¶
func (SrtSocket) SetRejectReason ¶
SetRejectReason - set custom reason for connection reject
func (SrtSocket) SetSockOptBool ¶
SetSockOptBool - set bool value using srt_setsockopt
func (SrtSocket) SetSockOptByte ¶
SetSockOptByte - set byte value using srt_setsockopt
func (SrtSocket) SetSockOptInt ¶
SetSockOptInt - set int value using srt_setsockopt
func (SrtSocket) SetSockOptInt64 ¶
SetSockOptInt64 - set int64 value using srt_setsockopt
func (SrtSocket) SetSockOptString ¶
SetSockOptString - set string value using srt_setsockopt
func (*SrtSocket) SetWriteDeadline ¶
type SrtSocketClosed ¶
type SrtSocketClosed struct{}
func (*SrtSocketClosed) Error ¶
func (m *SrtSocketClosed) Error() string
type SrtStats ¶
type SrtStats struct {
// Global measurements
MsTimeStamp int64 // time since the UDT entity is started, in milliseconds
PktSentTotal int64 // total number of sent data packets, including retransmissions
PktRecvTotal int64 // total number of received packets
PktSndLossTotal int // total number of lost packets (sender side)
PktRcvLossTotal int // total number of lost packets (receiver side)
PktRetransTotal int // total number of retransmitted packets
PktSentACKTotal int // total number of sent ACK packets
PktRecvACKTotal int // total number of received ACK packets
PktSentNAKTotal int // total number of sent NAK packets
PktRecvNAKTotal int // total number of received NAK packets
UsSndDurationTotal int64 // total time duration when UDT is sending data (idle time exclusive)
PktSndDropTotal int // number of too-late-to-send dropped packets
PktRcvDropTotal int // number of too-late-to play missing packets
PktRcvUndecryptTotal int // number of undecrypted packets
ByteSentTotal int64 // total number of sent data bytes, including retransmissions
ByteRecvTotal int64 // total number of received bytes
ByteRcvLossTotal int64 // total number of lost bytes
ByteRetransTotal int64 // total number of retransmitted bytes
ByteSndDropTotal int64 // number of too-late-to-send dropped bytes
ByteRcvDropTotal int64 // number of too-late-to play missing bytes (estimate based on average packet size)
ByteRcvUndecryptTotal int64 // number of undecrypted bytes
// Local measurements
PktSent int64 // number of sent data packets, including retransmissions
PktRecv int64 // number of received packets
PktSndLoss int // number of lost packets (sender side)
PktRcvLoss int // number of lost packets (receiver side)
PktRetrans int // number of retransmitted packets
PktRcvRetrans int // number of retransmitted packets received
PktSentACK int // number of sent ACK packets
PktRecvACK int // number of received ACK packets
PktSentNAK int // number of sent NAK packets
PktRecvNAK int // number of received NAK packets
MbpsSendRate float64 // sending rate in Mb/s
MbpsRecvRate float64 // receiving rate in Mb/s
UsSndDuration int64 // busy sending time (i.e., idle time exclusive)
PktReorderDistance int // size of order discrepancy in received sequences
PktRcvAvgBelatedTime float64 // average time of packet delay for belated packets (packets with sequence past the ACK)
PktRcvBelated int64 // number of received AND IGNORED packets due to having come too late
PktSndDrop int // number of too-late-to-send dropped packets
PktRcvDrop int // number of too-late-to play missing packets
PktRcvUndecrypt int // number of undecrypted packets
ByteSent int64 // number of sent data bytes, including retransmissions
ByteRecv int64 // number of received bytes
ByteRcvLoss int64 // number of retransmitted Bytes
ByteRetrans int64 // number of retransmitted Bytes
ByteSndDrop int64 // number of too-late-to-send dropped Bytes
ByteRcvDrop int64 // number of too-late-to play missing Bytes (estimate based on average packet size)
ByteRcvUndecrypt int64 // number of undecrypted bytes
// Instant measurements
UsPktSndPeriod float64 // packet sending period, in microseconds
PktFlowWindow int // flow window size, in number of packets
PktCongestionWindow int // congestion window size, in number of packets
PktFlightSize int // number of packets on flight
MsRTT float64 // RTT, in milliseconds
MbpsBandwidth float64 // estimated bandwidth, in Mb/s
ByteAvailSndBuf int // available UDT sender buffer size
ByteAvailRcvBuf int // available UDT receiver buffer size
MbpsMaxBW float64 // Transmit Bandwidth ceiling (Mbps)
ByteMSS int // MTU
PktSndBuf int // UnACKed packets in UDT sender
ByteSndBuf int // UnACKed bytes in UDT sender
MsSndBuf int // UnACKed timespan (msec) of UDT sender
MsSndTsbPdDelay int // Timestamp-based Packet Delivery Delay
PktRcvBuf int // Undelivered packets in UDT receiver
ByteRcvBuf int // Undelivered bytes of UDT receiver
MsRcvBuf int // Undelivered timespan (msec) of UDT receiver
MsRcvTsbPdDelay int // Timestamp-based Packet Delivery Delay
PktSndFilterExtraTotal int // number of control packets supplied by packet filter
PktRcvFilterExtraTotal int // number of control packets received and not supplied back
PktRcvFilterSupplyTotal int // number of packets that the filter supplied extra (e.g. FEC rebuilt)
PktRcvFilterLossTotal int // number of packet loss not coverable by filter
PktSndFilterExtra int // number of control packets supplied by packet filter
PktRcvFilterExtra int // number of control packets received and not supplied back
PktRcvFilterSupply int // number of packets that the filter supplied extra (e.g. FEC rebuilt)
PktRcvFilterLoss int // number of packet loss not coverable by filter
PktReorderTolerance int // packet reorder tolerance value
}