srt.h 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. /*
  2. * SRT - Secure, Reliable, Transport
  3. * Copyright (c) 2018 Haivision Systems Inc.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. */
  10. /*****************************************************************************
  11. written by
  12. Haivision Systems Inc.
  13. *****************************************************************************/
  14. #ifndef INC_SRTC_H
  15. #define INC_SRTC_H
  16. #include "version.h"
  17. #include "platform_sys.h"
  18. #include <string.h>
  19. #include <stdlib.h>
  20. #include "logging_api.h"
  21. ////////////////////////////////////////////////////////////////////////////////
  22. //if compiling on VC6.0 or pre-WindowsXP systems
  23. //use -DLEGACY_WIN32
  24. //if compiling with MinGW, it only works on XP or above
  25. //use -D_WIN32_WINNT=0x0501
  26. #ifdef _WIN32
  27. #ifndef __MINGW32__
  28. // Explicitly define 32-bit and 64-bit numbers
  29. typedef __int32 int32_t;
  30. typedef __int64 int64_t;
  31. typedef unsigned __int32 uint32_t;
  32. #ifndef LEGACY_WIN32
  33. typedef unsigned __int64 uint64_t;
  34. #else
  35. // VC 6.0 does not support unsigned __int64: may cause potential problems.
  36. typedef __int64 uint64_t;
  37. #endif
  38. #endif
  39. #ifdef SRT_DYNAMIC
  40. #ifdef SRT_EXPORTS
  41. #define SRT_API __declspec(dllexport)
  42. #else
  43. #define SRT_API __declspec(dllimport)
  44. #endif
  45. #else // !SRT_DYNAMIC
  46. #define SRT_API
  47. #endif
  48. #else
  49. #define SRT_API __attribute__ ((visibility("default")))
  50. #endif
  51. // For feature tests if you need.
  52. // You can use these constants with SRTO_MINVERSION option.
  53. #define SRT_VERSION_FEAT_HSv5 0x010300
  54. #if defined(__cplusplus) && __cplusplus > 201406
  55. #define SRT_HAVE_CXX17 1
  56. #else
  57. #define SRT_HAVE_CXX17 0
  58. #endif
  59. // Standard attributes
  60. // When compiling in C++17 mode, use the standard C++17 attributes
  61. // (out of these, only [[deprecated]] is supported in C++14, so
  62. // for all lesser standard use compiler-specific attributes).
  63. #if SRT_HAVE_CXX17
  64. // Unused: DO NOT issue a warning if this entity is unused.
  65. #define SRT_ATR_UNUSED [[maybe_unused]]
  66. // Nodiscard: issue a warning if the return value was discarded.
  67. #define SRT_ATR_NODISCARD [[nodiscard]]
  68. // GNUG is GNU C/C++; this syntax is also supported by Clang
  69. #elif defined(__GNUC__)
  70. #define SRT_ATR_UNUSED __attribute__((unused))
  71. #define SRT_ATR_NODISCARD __attribute__((warn_unused_result))
  72. #elif defined(_MSC_VER)
  73. #define SRT_ATR_UNUSED __pragma(warning(suppress: 4100 4101))
  74. #define SRT_ATR_NODISCARD _Check_return_
  75. #else
  76. #define SRT_ATR_UNUSED
  77. #define SRT_ATR_NODISCARD
  78. #endif
  79. // DEPRECATED attributes
  80. // There's needed DEPRECATED and DEPRECATED_PX, as some compilers require them
  81. // before the entity, others after the entity.
  82. // The *_PX version is the prefix attribute, which applies only
  83. // to functions (Microsoft compilers).
  84. // When deprecating a function, mark it:
  85. //
  86. // SRT_ATR_DEPRECATED_PX retval function(arguments) SRT_ATR_DEPRECATED;
  87. //
  88. // When SRT_NO_DEPRECATED defined, do not issue any deprecation warnings.
  89. // Regardless of the compiler type.
  90. #if defined(SRT_NO_DEPRECATED)
  91. #define SRT_ATR_DEPRECATED
  92. #define SRT_ATR_DEPRECATED_PX
  93. #elif SRT_HAVE_CXX17
  94. #define SRT_ATR_DEPRECATED
  95. #define SRT_ATR_DEPRECATED_PX [[deprecated]]
  96. // GNUG is GNU C/C++; this syntax is also supported by Clang
  97. #elif defined(__GNUC__)
  98. #define SRT_ATR_DEPRECATED_PX
  99. #define SRT_ATR_DEPRECATED __attribute__((deprecated))
  100. #elif defined(_MSC_VER)
  101. #define SRT_ATR_DEPRECATED_PX __declspec(deprecated)
  102. #define SRT_ATR_DEPRECATED // no postfix-type modifier
  103. #else
  104. #define SRT_ATR_DEPRECATED_PX
  105. #define SRT_ATR_DEPRECATED
  106. #endif
  107. #ifdef __cplusplus
  108. extern "C" {
  109. #endif
  110. typedef int32_t SRTSOCKET;
  111. // The most significant bit 31 (sign bit actually) is left unused,
  112. // so that all people who check the value for < 0 instead of -1
  113. // still get what they want. The bit 30 is reserved for marking
  114. // the "socket group". Most of the API functions should work
  115. // transparently with the socket descriptor designating a single
  116. // socket or a socket group.
  117. static const int32_t SRTGROUP_MASK = (1 << 30);
  118. #ifdef _WIN32
  119. typedef SOCKET SYSSOCKET;
  120. #else
  121. typedef int SYSSOCKET;
  122. #endif
  123. #ifndef ENABLE_BONDING
  124. #define ENABLE_BONDING 0
  125. #endif
  126. typedef SYSSOCKET UDPSOCKET;
  127. // Values returned by srt_getsockstate()
  128. typedef enum SRT_SOCKSTATUS {
  129. SRTS_INIT = 1,
  130. SRTS_OPENED,
  131. SRTS_LISTENING,
  132. SRTS_CONNECTING,
  133. SRTS_CONNECTED,
  134. SRTS_BROKEN,
  135. SRTS_CLOSING,
  136. SRTS_CLOSED,
  137. SRTS_NONEXIST
  138. } SRT_SOCKSTATUS;
  139. // This is a duplicate enum. Must be kept in sync with the original UDT enum for
  140. // backward compatibility until all compat is destroyed.
  141. typedef enum SRT_SOCKOPT {
  142. SRTO_MSS = 0, // the Maximum Transfer Unit
  143. SRTO_SNDSYN = 1, // if sending is blocking
  144. SRTO_RCVSYN = 2, // if receiving is blocking
  145. SRTO_ISN = 3, // Initial Sequence Number (valid only after srt_connect or srt_accept-ed sockets)
  146. SRTO_FC = 4, // Flight flag size (window size)
  147. SRTO_SNDBUF = 5, // maximum buffer in sending queue
  148. SRTO_RCVBUF = 6, // UDT receiving buffer size
  149. SRTO_LINGER = 7, // waiting for unsent data when closing
  150. SRTO_UDP_SNDBUF = 8, // UDP sending buffer size
  151. SRTO_UDP_RCVBUF = 9, // UDP receiving buffer size
  152. // (some space left)
  153. SRTO_RENDEZVOUS = 12, // rendezvous connection mode
  154. SRTO_SNDTIMEO = 13, // send() timeout
  155. SRTO_RCVTIMEO = 14, // recv() timeout
  156. SRTO_REUSEADDR = 15, // reuse an existing port or create a new one
  157. SRTO_MAXBW = 16, // maximum bandwidth (bytes per second) that the connection can use
  158. SRTO_STATE = 17, // current socket state, see UDTSTATUS, read only
  159. SRTO_EVENT = 18, // current available events associated with the socket
  160. SRTO_SNDDATA = 19, // size of data in the sending buffer
  161. SRTO_RCVDATA = 20, // size of data available for recv
  162. SRTO_SENDER = 21, // Sender mode (independent of conn mode), for encryption, tsbpd handshake.
  163. SRTO_TSBPDMODE = 22, // Enable/Disable TsbPd. Enable -> Tx set origin timestamp, Rx deliver packet at origin time + delay
  164. SRTO_LATENCY = 23, // NOT RECOMMENDED. SET: to both SRTO_RCVLATENCY and SRTO_PEERLATENCY. GET: same as SRTO_RCVLATENCY.
  165. SRTO_INPUTBW = 24, // Estimated input stream rate.
  166. SRTO_OHEADBW, // MaxBW ceiling based on % over input stream rate. Applies when UDT_MAXBW=0 (auto).
  167. SRTO_PASSPHRASE = 26, // Crypto PBKDF2 Passphrase (must be 10..79 characters, or empty to disable encryption)
  168. SRTO_PBKEYLEN, // Crypto key len in bytes {16,24,32} Default: 16 (AES-128)
  169. SRTO_KMSTATE, // Key Material exchange status (UDT_SRTKmState)
  170. SRTO_IPTTL = 29, // IP Time To Live (passthru for system sockopt IPPROTO_IP/IP_TTL)
  171. SRTO_IPTOS, // IP Type of Service (passthru for system sockopt IPPROTO_IP/IP_TOS)
  172. SRTO_TLPKTDROP = 31, // Enable receiver pkt drop
  173. SRTO_SNDDROPDELAY = 32, // Extra delay towards latency for sender TLPKTDROP decision (-1 to off)
  174. SRTO_NAKREPORT = 33, // Enable receiver to send periodic NAK reports
  175. SRTO_VERSION = 34, // Local SRT Version
  176. SRTO_PEERVERSION, // Peer SRT Version (from SRT Handshake)
  177. SRTO_CONNTIMEO = 36, // Connect timeout in msec. Caller default: 3000, rendezvous (x 10)
  178. SRTO_DRIFTTRACER = 37, // Enable or disable drift tracer
  179. SRTO_MININPUTBW = 38, // Minimum estimate of input stream rate.
  180. // (some space left)
  181. SRTO_SNDKMSTATE = 40, // (GET) the current state of the encryption at the peer side
  182. SRTO_RCVKMSTATE, // (GET) the current state of the encryption at the agent side
  183. SRTO_LOSSMAXTTL, // Maximum possible packet reorder tolerance (number of packets to receive after loss to send lossreport)
  184. SRTO_RCVLATENCY, // TsbPd receiver delay (mSec) to absorb burst of missed packet retransmission
  185. SRTO_PEERLATENCY, // Minimum value of the TsbPd receiver delay (mSec) for the opposite side (peer)
  186. SRTO_MINVERSION, // Minimum SRT version needed for the peer (peers with less version will get connection reject)
  187. SRTO_STREAMID, // A string set to a socket and passed to the listener's accepted socket
  188. SRTO_CONGESTION, // Congestion controller type selection
  189. SRTO_MESSAGEAPI, // In File mode, use message API (portions of data with boundaries)
  190. SRTO_PAYLOADSIZE, // Maximum payload size sent in one UDP packet (0 if unlimited)
  191. SRTO_TRANSTYPE = 50, // Transmission type (set of options required for given transmission type)
  192. SRTO_KMREFRESHRATE, // After sending how many packets the encryption key should be flipped to the new key
  193. SRTO_KMPREANNOUNCE, // How many packets before key flip the new key is annnounced and after key flip the old one decommissioned
  194. SRTO_ENFORCEDENCRYPTION, // Connection to be rejected or quickly broken when one side encryption set or bad password
  195. SRTO_IPV6ONLY, // IPV6_V6ONLY mode
  196. SRTO_PEERIDLETIMEO, // Peer-idle timeout (max time of silence heard from peer) in [ms]
  197. SRTO_BINDTODEVICE, // Forward the SOL_SOCKET/SO_BINDTODEVICE option on socket (pass packets only from that device)
  198. SRTO_GROUPCONNECT, // Set on a listener to allow group connection (ENABLE_BONDING)
  199. SRTO_GROUPMINSTABLETIMEO, // Minimum Link Stability timeout (backup mode) in milliseconds (ENABLE_BONDING)
  200. SRTO_GROUPTYPE, // Group type to which an accepted socket is about to be added, available in the handshake (ENABLE_BONDING)
  201. SRTO_PACKETFILTER = 60, // Add and configure a packet filter
  202. SRTO_RETRANSMITALGO = 61, // An option to select packet retransmission algorithm
  203. #ifdef ENABLE_AEAD_API_PREVIEW
  204. SRTO_CRYPTOMODE = 62, // Encryption cipher mode (AES-CTR, AES-GCM, ...).
  205. #endif
  206. #ifdef ENABLE_MAXREXMITBW
  207. SRTO_MAXREXMITBW = 63, // Maximum bandwidth limit for retransmision (Bytes/s)
  208. #endif
  209. SRTO_E_SIZE // Always last element, not a valid option.
  210. } SRT_SOCKOPT;
  211. #ifdef __cplusplus
  212. #if __cplusplus > 199711L // C++11
  213. // Newer compilers report error when [[deprecated]] is applied to types,
  214. // and C++11 and higher uses this.
  215. // Note that this doesn't exactly use the 'deprecated' attribute,
  216. // as it's introduced in C++14. What is actually used here is the
  217. // fact that unknown attributes are ignored, but still warned about.
  218. // This should only catch an eye - and that's what it does.
  219. #define SRT_DEPRECATED_OPTION(value) ((SRT_SOCKOPT [[deprecated]])value)
  220. #else
  221. // Older (pre-C++11) compilers use gcc deprecated applied to a typedef
  222. typedef SRT_ATR_DEPRECATED_PX SRT_SOCKOPT SRT_SOCKOPT_DEPRECATED SRT_ATR_DEPRECATED;
  223. #define SRT_DEPRECATED_OPTION(value) ((SRT_SOCKOPT_DEPRECATED)value)
  224. #endif
  225. #else
  226. // deprecated enum labels are supported only since gcc 6, so in C there
  227. // will be a whole deprecated enum type, as it's not an error in C to mix
  228. // enum types
  229. enum SRT_ATR_DEPRECATED SRT_SOCKOPT_DEPRECATED
  230. {
  231. // Dummy last option, as every entry ends with a comma
  232. SRTO_DEPRECATED_END = 0
  233. };
  234. #define SRT_DEPRECATED_OPTION(value) ((enum SRT_SOCKOPT_DEPRECATED)value)
  235. #endif
  236. // Note that there are no deprecated options at the moment, but the mechanism
  237. // stays so that it can be used in future. Example:
  238. // #define SRTO_STRICTENC SRT_DEPRECATED_OPTION(53)
  239. typedef enum SRT_TRANSTYPE
  240. {
  241. SRTT_LIVE,
  242. SRTT_FILE,
  243. SRTT_INVALID
  244. } SRT_TRANSTYPE;
  245. // These sizes should be used for Live mode. In Live mode you should not
  246. // exceed the size that fits in a single MTU.
  247. // This is for MPEG TS and it's a default SRTO_PAYLOADSIZE for SRTT_LIVE.
  248. static const int SRT_LIVE_DEF_PLSIZE = 1316; // = 188*7, recommended for MPEG TS
  249. // This is the maximum payload size for Live mode, should you have a different
  250. // payload type than MPEG TS.
  251. static const int SRT_LIVE_MAX_PLSIZE = 1456; // MTU(1500) - UDP.hdr(28) - SRT.hdr(16)
  252. // Latency for Live transmission: default is 120
  253. static const int SRT_LIVE_DEF_LATENCY_MS = 120;
  254. // Importrant note: please add new fields to this structure to the end and don't remove any existing fields
  255. struct CBytePerfMon
  256. {
  257. // global measurements
  258. int64_t msTimeStamp; // time since the UDT entity is started, in milliseconds
  259. int64_t pktSentTotal; // total number of sent data packets, including retransmissions
  260. int64_t pktRecvTotal; // total number of received packets
  261. int pktSndLossTotal; // total number of lost packets (sender side)
  262. int pktRcvLossTotal; // total number of lost packets (receiver side)
  263. int pktRetransTotal; // total number of retransmitted packets
  264. int pktSentACKTotal; // total number of sent ACK packets
  265. int pktRecvACKTotal; // total number of received ACK packets
  266. int pktSentNAKTotal; // total number of sent NAK packets
  267. int pktRecvNAKTotal; // total number of received NAK packets
  268. int64_t usSndDurationTotal; // total time duration when UDT is sending data (idle time exclusive)
  269. //>new
  270. int pktSndDropTotal; // number of too-late-to-send dropped packets
  271. int pktRcvDropTotal; // number of too-late-to play missing packets
  272. int pktRcvUndecryptTotal; // number of undecrypted packets
  273. uint64_t byteSentTotal; // total number of sent data bytes, including retransmissions
  274. uint64_t byteRecvTotal; // total number of received bytes
  275. uint64_t byteRcvLossTotal; // total number of lost bytes
  276. uint64_t byteRetransTotal; // total number of retransmitted bytes
  277. uint64_t byteSndDropTotal; // number of too-late-to-send dropped bytes
  278. uint64_t byteRcvDropTotal; // number of too-late-to play missing bytes (estimate based on average packet size)
  279. uint64_t byteRcvUndecryptTotal; // number of undecrypted bytes
  280. //<
  281. // local measurements
  282. int64_t pktSent; // number of sent data packets, including retransmissions
  283. int64_t pktRecv; // number of received packets
  284. int pktSndLoss; // number of lost packets (sender side)
  285. int pktRcvLoss; // number of lost packets (receiver side)
  286. int pktRetrans; // number of retransmitted packets
  287. int pktRcvRetrans; // number of retransmitted packets received
  288. int pktSentACK; // number of sent ACK packets
  289. int pktRecvACK; // number of received ACK packets
  290. int pktSentNAK; // number of sent NAK packets
  291. int pktRecvNAK; // number of received NAK packets
  292. double mbpsSendRate; // sending rate in Mb/s
  293. double mbpsRecvRate; // receiving rate in Mb/s
  294. int64_t usSndDuration; // busy sending time (i.e., idle time exclusive)
  295. int pktReorderDistance; // size of order discrepancy in received sequences
  296. double pktRcvAvgBelatedTime; // average time of packet delay for belated packets (packets with sequence past the ACK)
  297. int64_t pktRcvBelated; // number of received AND IGNORED packets due to having come too late
  298. //>new
  299. int pktSndDrop; // number of too-late-to-send dropped packets
  300. int pktRcvDrop; // number of too-late-to play missing packets
  301. int pktRcvUndecrypt; // number of undecrypted packets
  302. uint64_t byteSent; // number of sent data bytes, including retransmissions
  303. uint64_t byteRecv; // number of received bytes
  304. uint64_t byteRcvLoss; // number of retransmitted bytes
  305. uint64_t byteRetrans; // number of retransmitted bytes
  306. uint64_t byteSndDrop; // number of too-late-to-send dropped bytes
  307. uint64_t byteRcvDrop; // number of too-late-to play missing bytes (estimate based on average packet size)
  308. uint64_t byteRcvUndecrypt; // number of undecrypted bytes
  309. //<
  310. // instant measurements
  311. double usPktSndPeriod; // packet sending period, in microseconds
  312. int pktFlowWindow; // flow window size, in number of packets
  313. int pktCongestionWindow; // congestion window size, in number of packets
  314. int pktFlightSize; // number of packets on flight
  315. double msRTT; // RTT, in milliseconds
  316. double mbpsBandwidth; // estimated bandwidth, in Mb/s
  317. int byteAvailSndBuf; // available UDT sender buffer size
  318. int byteAvailRcvBuf; // available UDT receiver buffer size
  319. //>new
  320. double mbpsMaxBW; // Transmit Bandwidth ceiling (Mbps)
  321. int byteMSS; // MTU
  322. int pktSndBuf; // UnACKed packets in UDT sender
  323. int byteSndBuf; // UnACKed bytes in UDT sender
  324. int msSndBuf; // UnACKed timespan (msec) of UDT sender
  325. int msSndTsbPdDelay; // Timestamp-based Packet Delivery Delay
  326. int pktRcvBuf; // Undelivered packets in UDT receiver
  327. int byteRcvBuf; // Undelivered bytes of UDT receiver
  328. int msRcvBuf; // Undelivered timespan (msec) of UDT receiver
  329. int msRcvTsbPdDelay; // Timestamp-based Packet Delivery Delay
  330. int pktSndFilterExtraTotal; // number of control packets supplied by packet filter
  331. int pktRcvFilterExtraTotal; // number of control packets received and not supplied back
  332. int pktRcvFilterSupplyTotal; // number of packets that the filter supplied extra (e.g. FEC rebuilt)
  333. int pktRcvFilterLossTotal; // number of packet loss not coverable by filter
  334. int pktSndFilterExtra; // number of control packets supplied by packet filter
  335. int pktRcvFilterExtra; // number of control packets received and not supplied back
  336. int pktRcvFilterSupply; // number of packets that the filter supplied extra (e.g. FEC rebuilt)
  337. int pktRcvFilterLoss; // number of packet loss not coverable by filter
  338. int pktReorderTolerance; // packet reorder tolerance value
  339. //<
  340. // New stats in 1.5.0
  341. // Total
  342. int64_t pktSentUniqueTotal; // total number of data packets sent by the application
  343. int64_t pktRecvUniqueTotal; // total number of packets to be received by the application
  344. uint64_t byteSentUniqueTotal; // total number of data bytes, sent by the application
  345. uint64_t byteRecvUniqueTotal; // total number of data bytes to be received by the application
  346. // Local
  347. int64_t pktSentUnique; // number of data packets sent by the application
  348. int64_t pktRecvUnique; // number of packets to be received by the application
  349. uint64_t byteSentUnique; // number of data bytes, sent by the application
  350. uint64_t byteRecvUnique; // number of data bytes to be received by the application
  351. };
  352. ////////////////////////////////////////////////////////////////////////////////
  353. // Error codes - define outside the CUDTException class
  354. // because otherwise you'd have to use CUDTException::MJ_SUCCESS etc.
  355. // in all throw CUDTException expressions.
  356. enum CodeMajor
  357. {
  358. MJ_UNKNOWN = -1,
  359. MJ_SUCCESS = 0,
  360. MJ_SETUP = 1,
  361. MJ_CONNECTION = 2,
  362. MJ_SYSTEMRES = 3,
  363. MJ_FILESYSTEM = 4,
  364. MJ_NOTSUP = 5,
  365. MJ_AGAIN = 6,
  366. MJ_PEERERROR = 7
  367. };
  368. enum CodeMinor
  369. {
  370. // These are "minor" error codes from various "major" categories
  371. // MJ_SETUP
  372. MN_NONE = 0,
  373. MN_TIMEOUT = 1,
  374. MN_REJECTED = 2,
  375. MN_NORES = 3,
  376. MN_SECURITY = 4,
  377. MN_CLOSED = 5,
  378. // MJ_CONNECTION
  379. MN_CONNLOST = 1,
  380. MN_NOCONN = 2,
  381. // MJ_SYSTEMRES
  382. MN_THREAD = 1,
  383. MN_MEMORY = 2,
  384. MN_OBJECT = 3,
  385. // MJ_FILESYSTEM
  386. MN_SEEKGFAIL = 1,
  387. MN_READFAIL = 2,
  388. MN_SEEKPFAIL = 3,
  389. MN_WRITEFAIL = 4,
  390. // MJ_NOTSUP
  391. MN_ISBOUND = 1,
  392. MN_ISCONNECTED = 2,
  393. MN_INVAL = 3,
  394. MN_SIDINVAL = 4,
  395. MN_ISUNBOUND = 5,
  396. MN_NOLISTEN = 6,
  397. MN_ISRENDEZVOUS = 7,
  398. MN_ISRENDUNBOUND = 8,
  399. MN_INVALMSGAPI = 9,
  400. MN_INVALBUFFERAPI = 10,
  401. MN_BUSY = 11,
  402. MN_XSIZE = 12,
  403. MN_EIDINVAL = 13,
  404. MN_EEMPTY = 14,
  405. MN_BUSYPORT = 15,
  406. // MJ_AGAIN
  407. MN_WRAVAIL = 1,
  408. MN_RDAVAIL = 2,
  409. MN_XMTIMEOUT = 3,
  410. MN_CONGESTION = 4
  411. };
  412. // Stupid, but effective. This will be #undefined, so don't worry.
  413. #define SRT_EMJ(major) (1000 * MJ_##major)
  414. #define SRT_EMN(major, minor) (1000 * MJ_##major + MN_##minor)
  415. // Some better way to define it, and better for C language.
  416. typedef enum SRT_ERRNO
  417. {
  418. SRT_EUNKNOWN = -1,
  419. SRT_SUCCESS = MJ_SUCCESS,
  420. SRT_ECONNSETUP = SRT_EMJ(SETUP),
  421. SRT_ENOSERVER = SRT_EMN(SETUP, TIMEOUT),
  422. SRT_ECONNREJ = SRT_EMN(SETUP, REJECTED),
  423. SRT_ESOCKFAIL = SRT_EMN(SETUP, NORES),
  424. SRT_ESECFAIL = SRT_EMN(SETUP, SECURITY),
  425. SRT_ESCLOSED = SRT_EMN(SETUP, CLOSED),
  426. SRT_ECONNFAIL = SRT_EMJ(CONNECTION),
  427. SRT_ECONNLOST = SRT_EMN(CONNECTION, CONNLOST),
  428. SRT_ENOCONN = SRT_EMN(CONNECTION, NOCONN),
  429. SRT_ERESOURCE = SRT_EMJ(SYSTEMRES),
  430. SRT_ETHREAD = SRT_EMN(SYSTEMRES, THREAD),
  431. SRT_ENOBUF = SRT_EMN(SYSTEMRES, MEMORY),
  432. SRT_ESYSOBJ = SRT_EMN(SYSTEMRES, OBJECT),
  433. SRT_EFILE = SRT_EMJ(FILESYSTEM),
  434. SRT_EINVRDOFF = SRT_EMN(FILESYSTEM, SEEKGFAIL),
  435. SRT_ERDPERM = SRT_EMN(FILESYSTEM, READFAIL),
  436. SRT_EINVWROFF = SRT_EMN(FILESYSTEM, SEEKPFAIL),
  437. SRT_EWRPERM = SRT_EMN(FILESYSTEM, WRITEFAIL),
  438. SRT_EINVOP = SRT_EMJ(NOTSUP),
  439. SRT_EBOUNDSOCK = SRT_EMN(NOTSUP, ISBOUND),
  440. SRT_ECONNSOCK = SRT_EMN(NOTSUP, ISCONNECTED),
  441. SRT_EINVPARAM = SRT_EMN(NOTSUP, INVAL),
  442. SRT_EINVSOCK = SRT_EMN(NOTSUP, SIDINVAL),
  443. SRT_EUNBOUNDSOCK = SRT_EMN(NOTSUP, ISUNBOUND),
  444. SRT_ENOLISTEN = SRT_EMN(NOTSUP, NOLISTEN),
  445. SRT_ERDVNOSERV = SRT_EMN(NOTSUP, ISRENDEZVOUS),
  446. SRT_ERDVUNBOUND = SRT_EMN(NOTSUP, ISRENDUNBOUND),
  447. SRT_EINVALMSGAPI = SRT_EMN(NOTSUP, INVALMSGAPI),
  448. SRT_EINVALBUFFERAPI = SRT_EMN(NOTSUP, INVALBUFFERAPI),
  449. SRT_EDUPLISTEN = SRT_EMN(NOTSUP, BUSY),
  450. SRT_ELARGEMSG = SRT_EMN(NOTSUP, XSIZE),
  451. SRT_EINVPOLLID = SRT_EMN(NOTSUP, EIDINVAL),
  452. SRT_EPOLLEMPTY = SRT_EMN(NOTSUP, EEMPTY),
  453. SRT_EBINDCONFLICT = SRT_EMN(NOTSUP, BUSYPORT),
  454. SRT_EASYNCFAIL = SRT_EMJ(AGAIN),
  455. SRT_EASYNCSND = SRT_EMN(AGAIN, WRAVAIL),
  456. SRT_EASYNCRCV = SRT_EMN(AGAIN, RDAVAIL),
  457. SRT_ETIMEOUT = SRT_EMN(AGAIN, XMTIMEOUT),
  458. SRT_ECONGEST = SRT_EMN(AGAIN, CONGESTION),
  459. SRT_EPEERERR = SRT_EMJ(PEERERROR)
  460. } SRT_ERRNO;
  461. #undef SRT_EMJ
  462. #undef SRT_EMN
  463. enum SRT_REJECT_REASON
  464. {
  465. SRT_REJ_UNKNOWN, // initial set when in progress
  466. SRT_REJ_SYSTEM, // broken due to system function error
  467. SRT_REJ_PEER, // connection was rejected by peer
  468. SRT_REJ_RESOURCE, // internal problem with resource allocation
  469. SRT_REJ_ROGUE, // incorrect data in handshake messages
  470. SRT_REJ_BACKLOG, // listener's backlog exceeded
  471. SRT_REJ_IPE, // internal program error
  472. SRT_REJ_CLOSE, // socket is closing
  473. SRT_REJ_VERSION, // peer is older version than agent's minimum set
  474. SRT_REJ_RDVCOOKIE, // rendezvous cookie collision
  475. SRT_REJ_BADSECRET, // wrong password
  476. SRT_REJ_UNSECURE, // password required or unexpected
  477. SRT_REJ_MESSAGEAPI, // streamapi/messageapi collision
  478. SRT_REJ_CONGESTION, // incompatible congestion-controller type
  479. SRT_REJ_FILTER, // incompatible packet filter
  480. SRT_REJ_GROUP, // incompatible group
  481. SRT_REJ_TIMEOUT, // connection timeout
  482. #ifdef ENABLE_AEAD_API_PREVIEW
  483. SRT_REJ_CRYPTO, // conflicting cryptographic configurations
  484. #endif
  485. SRT_REJ_E_SIZE,
  486. };
  487. // XXX This value remains for some time, but it's deprecated
  488. // Planned deprecation removal: rel1.6.0.
  489. #define SRT_REJ__SIZE SRT_REJ_E_SIZE
  490. // Reject category codes:
  491. #define SRT_REJC_VALUE(code) (1000 * (code/1000))
  492. #define SRT_REJC_INTERNAL 0 // Codes from above SRT_REJECT_REASON enum
  493. #define SRT_REJC_PREDEFINED 1000 // Standard server error codes
  494. #define SRT_REJC_USERDEFINED 2000 // User defined error codes
  495. // Logging API - specialization for SRT.
  496. // WARNING: This part is generated.
  497. // Logger Functional Areas
  498. // Note that 0 is "general".
  499. // Values 0* - general, unqualified
  500. // Values 1* - control
  501. // Values 2* - receiving
  502. // Values 3* - sending
  503. // Values 4* - management
  504. // Made by #define so that it's available also for C API.
  505. // Use ../scripts/generate-logging-defs.tcl to regenerate.
  506. // SRT_LOGFA BEGIN GENERATED SECTION {
  507. #define SRT_LOGFA_GENERAL 0 // gglog: General uncategorized log, for serious issues only
  508. #define SRT_LOGFA_SOCKMGMT 1 // smlog: Socket create/open/close/configure activities
  509. #define SRT_LOGFA_CONN 2 // cnlog: Connection establishment and handshake
  510. #define SRT_LOGFA_XTIMER 3 // xtlog: The checkTimer and around activities
  511. #define SRT_LOGFA_TSBPD 4 // tslog: The TsBPD thread
  512. #define SRT_LOGFA_RSRC 5 // rslog: System resource allocation and management
  513. #define SRT_LOGFA_CONGEST 7 // cclog: Congestion control module
  514. #define SRT_LOGFA_PFILTER 8 // pflog: Packet filter module
  515. #define SRT_LOGFA_API_CTRL 11 // aclog: API part for socket and library managmenet
  516. #define SRT_LOGFA_QUE_CTRL 13 // qclog: Queue control activities
  517. #define SRT_LOGFA_EPOLL_UPD 16 // eilog: EPoll, internal update activities
  518. #define SRT_LOGFA_API_RECV 21 // arlog: API part for receiving
  519. #define SRT_LOGFA_BUF_RECV 22 // brlog: Buffer, receiving side
  520. #define SRT_LOGFA_QUE_RECV 23 // qrlog: Queue, receiving side
  521. #define SRT_LOGFA_CHN_RECV 24 // krlog: CChannel, receiving side
  522. #define SRT_LOGFA_GRP_RECV 25 // grlog: Group, receiving side
  523. #define SRT_LOGFA_API_SEND 31 // aslog: API part for sending
  524. #define SRT_LOGFA_BUF_SEND 32 // bslog: Buffer, sending side
  525. #define SRT_LOGFA_QUE_SEND 33 // qslog: Queue, sending side
  526. #define SRT_LOGFA_CHN_SEND 34 // kslog: CChannel, sending side
  527. #define SRT_LOGFA_GRP_SEND 35 // gslog: Group, sending side
  528. #define SRT_LOGFA_INTERNAL 41 // inlog: Internal activities not connected directly to a socket
  529. #define SRT_LOGFA_QUE_MGMT 43 // qmlog: Queue, management part
  530. #define SRT_LOGFA_CHN_MGMT 44 // kmlog: CChannel, management part
  531. #define SRT_LOGFA_GRP_MGMT 45 // gmlog: Group, management part
  532. #define SRT_LOGFA_EPOLL_API 46 // ealog: EPoll, API part
  533. #define SRT_LOGFA_HAICRYPT 6 // hclog: Haicrypt module area
  534. #define SRT_LOGFA_APPLOG 10 // aplog: Applications
  535. // } SRT_LOGFA END GENERATED SECTION
  536. // To make a typical int64_t size, although still use std::bitset.
  537. // C API will carry it over.
  538. #define SRT_LOGFA_LASTNONE 63
  539. enum SRT_KM_STATE
  540. {
  541. SRT_KM_S_UNSECURED = 0, // No encryption
  542. SRT_KM_S_SECURING = 1, // Stream encrypted, exchanging Keying Material
  543. SRT_KM_S_SECURED = 2, // Stream encrypted, keying Material exchanged, decrypting ok.
  544. SRT_KM_S_NOSECRET = 3, // Stream encrypted and no secret to decrypt Keying Material
  545. SRT_KM_S_BADSECRET = 4 // Stream encrypted and wrong secret is used, cannot decrypt Keying Material
  546. #ifdef ENABLE_AEAD_API_PREVIEW
  547. ,SRT_KM_S_BADCRYPTOMODE = 5 // Stream encrypted but wrong cryptographic mode is used, cannot decrypt. Since v1.5.2.
  548. #endif
  549. };
  550. enum SRT_EPOLL_OPT
  551. {
  552. SRT_EPOLL_OPT_NONE = 0x0, // fallback
  553. // Values intended to be the same as in `<sys/epoll.h>`.
  554. // so that if system values are used by mistake, they should have the same effect
  555. // This applies to: IN, OUT, ERR and ET.
  556. /// Ready for 'recv' operation:
  557. ///
  558. /// - For stream mode it means that at least 1 byte is available.
  559. /// In this mode the buffer may extract only a part of the packet,
  560. /// leaving next data possible for extraction later.
  561. ///
  562. /// - For message mode it means that there is at least one packet
  563. /// available (this may change in future, as it is desired that
  564. /// one full message should only wake up, not single packet of a
  565. /// not yet extractable message).
  566. ///
  567. /// - For live mode it means that there's at least one packet
  568. /// ready to play.
  569. ///
  570. /// - For listener sockets, this means that there is a new connection
  571. /// waiting for pickup through the `srt_accept()` call, that is,
  572. /// the next call to `srt_accept()` will succeed without blocking
  573. /// (see an alias SRT_EPOLL_ACCEPT below).
  574. SRT_EPOLL_IN = 0x1,
  575. /// Ready for 'send' operation.
  576. ///
  577. /// - For stream mode it means that there's a free space in the
  578. /// sender buffer for at least 1 byte of data. The next send
  579. /// operation will only allow to send as much data as it is free
  580. /// space in the buffer.
  581. ///
  582. /// - For message mode it means that there's a free space for at
  583. /// least one UDP packet. The edge-triggered mode can be used to
  584. /// pick up updates as the free space in the sender buffer grows.
  585. ///
  586. /// - For live mode it means that there's a free space for at least
  587. /// one UDP packet. On the other hand, no readiness for OUT usually
  588. /// means an extraordinary congestion on the link, meaning also that
  589. /// you should immediately slow down the sending rate or you may get
  590. /// a connection break soon.
  591. ///
  592. /// - For non-blocking sockets used with `srt_connect*` operation,
  593. /// this flag simply means that the connection was established.
  594. SRT_EPOLL_OUT = 0x4,
  595. /// The socket has encountered an error in the last operation
  596. /// and the next operation on that socket will end up with error.
  597. /// You can retry the operation, but getting the error from it
  598. /// is certain, so you may as well close the socket.
  599. SRT_EPOLL_ERR = 0x8,
  600. // To avoid confusion in the internal code, the following
  601. // duplicates are introduced to improve clarity.
  602. SRT_EPOLL_CONNECT = SRT_EPOLL_OUT,
  603. SRT_EPOLL_ACCEPT = SRT_EPOLL_IN,
  604. SRT_EPOLL_UPDATE = 0x10,
  605. SRT_EPOLL_ET = 1u << 31
  606. };
  607. // These are actually flags - use a bit container:
  608. typedef int32_t SRT_EPOLL_T;
  609. // Define which epoll flags determine events. All others are special flags.
  610. #define SRT_EPOLL_EVENTTYPES (SRT_EPOLL_IN | SRT_EPOLL_OUT | SRT_EPOLL_UPDATE | SRT_EPOLL_ERR)
  611. #define SRT_EPOLL_ETONLY (SRT_EPOLL_UPDATE)
  612. enum SRT_EPOLL_FLAGS
  613. {
  614. /// This allows the EID container to be empty when calling the waiting
  615. /// function with infinite time. This means an infinite hangup, although
  616. /// a socket can be added to this EID from a separate thread.
  617. SRT_EPOLL_ENABLE_EMPTY = 1,
  618. /// This makes the waiting function check if there is output container
  619. /// passed to it, and report an error if it isn't. By default it is allowed
  620. /// that the output container is 0 size or NULL and therefore the readiness
  621. /// state is reported only as a number of ready sockets from return value.
  622. SRT_EPOLL_ENABLE_OUTPUTCHECK = 2
  623. };
  624. #ifdef __cplusplus
  625. // In C++ these enums cannot be treated as int and glued by operator |.
  626. // Unless this operator is defined.
  627. inline SRT_EPOLL_OPT operator|(SRT_EPOLL_OPT a1, SRT_EPOLL_OPT a2)
  628. {
  629. return SRT_EPOLL_OPT( (int)a1 | (int)a2 );
  630. }
  631. #endif
  632. typedef struct CBytePerfMon SRT_TRACEBSTATS;
  633. static const SRTSOCKET SRT_INVALID_SOCK = -1;
  634. static const int SRT_ERROR = -1;
  635. // library initialization
  636. SRT_API int srt_startup(void);
  637. SRT_API int srt_cleanup(void);
  638. //
  639. // Socket operations
  640. //
  641. // DEPRECATED: srt_socket with 3 arguments. All these arguments are ignored
  642. // and socket creation doesn't need any arguments. Use srt_create_socket().
  643. // Planned deprecation removal: rel1.6.0
  644. SRT_ATR_DEPRECATED_PX SRT_API SRTSOCKET srt_socket(int, int, int) SRT_ATR_DEPRECATED;
  645. SRT_API SRTSOCKET srt_create_socket(void);
  646. SRT_API int srt_bind (SRTSOCKET u, const struct sockaddr* name, int namelen);
  647. SRT_API int srt_bind_acquire (SRTSOCKET u, UDPSOCKET sys_udp_sock);
  648. // Old name of srt_bind_acquire(), please don't use
  649. // Planned deprecation removal: rel1.6.0
  650. SRT_ATR_DEPRECATED_PX static inline int srt_bind_peerof(SRTSOCKET u, UDPSOCKET sys_udp_sock) SRT_ATR_DEPRECATED;
  651. static inline int srt_bind_peerof (SRTSOCKET u, UDPSOCKET sys_udp_sock) { return srt_bind_acquire(u, sys_udp_sock); }
  652. SRT_API int srt_listen (SRTSOCKET u, int backlog);
  653. SRT_API SRTSOCKET srt_accept (SRTSOCKET u, struct sockaddr* addr, int* addrlen);
  654. SRT_API SRTSOCKET srt_accept_bond (const SRTSOCKET listeners[], int lsize, int64_t msTimeOut);
  655. typedef int srt_listen_callback_fn (void* opaq, SRTSOCKET ns, int hsversion, const struct sockaddr* peeraddr, const char* streamid);
  656. SRT_API int srt_listen_callback(SRTSOCKET lsn, srt_listen_callback_fn* hook_fn, void* hook_opaque);
  657. typedef void srt_connect_callback_fn (void* opaq, SRTSOCKET ns, int errorcode, const struct sockaddr* peeraddr, int token);
  658. SRT_API int srt_connect_callback(SRTSOCKET clr, srt_connect_callback_fn* hook_fn, void* hook_opaque);
  659. SRT_API int srt_connect (SRTSOCKET u, const struct sockaddr* name, int namelen);
  660. SRT_API int srt_connect_debug(SRTSOCKET u, const struct sockaddr* name, int namelen, int forced_isn);
  661. SRT_API int srt_connect_bind (SRTSOCKET u, const struct sockaddr* source,
  662. const struct sockaddr* target, int len);
  663. SRT_API int srt_rendezvous (SRTSOCKET u, const struct sockaddr* local_name, int local_namelen,
  664. const struct sockaddr* remote_name, int remote_namelen);
  665. SRT_API int srt_close (SRTSOCKET u);
  666. SRT_API int srt_getpeername (SRTSOCKET u, struct sockaddr* name, int* namelen);
  667. SRT_API int srt_getsockname (SRTSOCKET u, struct sockaddr* name, int* namelen);
  668. SRT_API int srt_getsockopt (SRTSOCKET u, int level /*ignored*/, SRT_SOCKOPT optname, void* optval, int* optlen);
  669. SRT_API int srt_setsockopt (SRTSOCKET u, int level /*ignored*/, SRT_SOCKOPT optname, const void* optval, int optlen);
  670. SRT_API int srt_getsockflag (SRTSOCKET u, SRT_SOCKOPT opt, void* optval, int* optlen);
  671. SRT_API int srt_setsockflag (SRTSOCKET u, SRT_SOCKOPT opt, const void* optval, int optlen);
  672. typedef struct SRT_SocketGroupData_ SRT_SOCKGROUPDATA;
  673. typedef struct SRT_MsgCtrl_
  674. {
  675. int flags; // Left for future
  676. int msgttl; // TTL for a message (millisec), default -1 (no TTL limitation)
  677. int inorder; // Whether a message is allowed to supersede partially lost one. Unused in stream and live mode.
  678. int boundary; // 0:mid pkt, 1(01b):end of frame, 2(11b):complete frame, 3(10b): start of frame
  679. int64_t srctime; // source time since epoch (usec), 0: use internal time (sender)
  680. int32_t pktseq; // sequence number of the first packet in received message (unused for sending)
  681. int32_t msgno; // message number (output value for both sending and receiving)
  682. SRT_SOCKGROUPDATA* grpdata;
  683. size_t grpdata_size;
  684. } SRT_MSGCTRL;
  685. // Trap representation for sequence and message numbers
  686. // This value means that this is "unset", and it's never
  687. // a result of an operation made on this number.
  688. static const int32_t SRT_SEQNO_NONE = -1; // -1: no seq (0 is a valid seqno!)
  689. static const int32_t SRT_MSGNO_NONE = -1; // -1: unset
  690. static const int32_t SRT_MSGNO_CONTROL = 0; // 0: control (used by packet filter)
  691. static const int SRT_MSGTTL_INF = -1; // unlimited TTL specification for message TTL
  692. // XXX Might be useful also other special uses of -1:
  693. // - -1 as infinity for srt_epoll_wait
  694. // - -1 as a trap index value used in list.cpp
  695. // You are free to use either of these two methods to set SRT_MSGCTRL object
  696. // to default values: either call srt_msgctrl_init(&obj) or obj = srt_msgctrl_default.
  697. SRT_API void srt_msgctrl_init(SRT_MSGCTRL* mctrl);
  698. SRT_API extern const SRT_MSGCTRL srt_msgctrl_default;
  699. // The send/receive functions.
  700. // These functions have different names due to different sets of parameters
  701. // to be supplied. Not all of them are needed or make sense in all modes:
  702. // Plain: supply only the buffer and its size.
  703. // Msg: supply additionally
  704. // - TTL (message is not delivered when exceeded) and
  705. // - INORDER (when false, the message is allowed to be delivered in different
  706. // order than when it was sent, when the later message is earlier ready to
  707. // deliver)
  708. // Msg2: Supply extra parameters in SRT_MSGCTRL. When receiving, these
  709. // parameters will be filled, as needed. NULL is acceptable, in which case
  710. // the defaults are used.
  711. //
  712. // Sending functions
  713. //
  714. SRT_API int srt_send (SRTSOCKET u, const char* buf, int len);
  715. SRT_API int srt_sendmsg (SRTSOCKET u, const char* buf, int len, int ttl/* = -1*/, int inorder/* = false*/);
  716. SRT_API int srt_sendmsg2(SRTSOCKET u, const char* buf, int len, SRT_MSGCTRL *mctrl);
  717. //
  718. // Receiving functions
  719. //
  720. SRT_API int srt_recv (SRTSOCKET u, char* buf, int len);
  721. // srt_recvmsg is actually an alias to srt_recv, it stays under the old name for compat reasons.
  722. SRT_API int srt_recvmsg (SRTSOCKET u, char* buf, int len);
  723. SRT_API int srt_recvmsg2(SRTSOCKET u, char *buf, int len, SRT_MSGCTRL *mctrl);
  724. // Special send/receive functions for files only.
  725. #define SRT_DEFAULT_SENDFILE_BLOCK 364000
  726. #define SRT_DEFAULT_RECVFILE_BLOCK 7280000
  727. SRT_API int64_t srt_sendfile(SRTSOCKET u, const char* path, int64_t* offset, int64_t size, int block);
  728. SRT_API int64_t srt_recvfile(SRTSOCKET u, const char* path, int64_t* offset, int64_t size, int block);
  729. // last error detection
  730. SRT_API const char* srt_getlasterror_str(void);
  731. SRT_API int srt_getlasterror(int* errno_loc);
  732. SRT_API const char* srt_strerror(int code, int errnoval);
  733. SRT_API void srt_clearlasterror(void);
  734. // Performance tracking
  735. // Performance monitor with Byte counters for better bitrate estimation.
  736. SRT_API int srt_bstats(SRTSOCKET u, SRT_TRACEBSTATS * perf, int clear);
  737. // Performance monitor with Byte counters and instantaneous stats instead of moving averages for Snd/Rcvbuffer sizes.
  738. SRT_API int srt_bistats(SRTSOCKET u, SRT_TRACEBSTATS * perf, int clear, int instantaneous);
  739. // Socket Status (for problem tracking)
  740. SRT_API SRT_SOCKSTATUS srt_getsockstate(SRTSOCKET u);
  741. SRT_API int srt_epoll_create(void);
  742. SRT_API int srt_epoll_clear_usocks(int eid);
  743. SRT_API int srt_epoll_add_usock(int eid, SRTSOCKET u, const int* events);
  744. SRT_API int srt_epoll_add_ssock(int eid, SYSSOCKET s, const int* events);
  745. SRT_API int srt_epoll_remove_usock(int eid, SRTSOCKET u);
  746. SRT_API int srt_epoll_remove_ssock(int eid, SYSSOCKET s);
  747. SRT_API int srt_epoll_update_usock(int eid, SRTSOCKET u, const int* events);
  748. SRT_API int srt_epoll_update_ssock(int eid, SYSSOCKET s, const int* events);
  749. SRT_API int srt_epoll_wait(int eid, SRTSOCKET* readfds, int* rnum, SRTSOCKET* writefds, int* wnum, int64_t msTimeOut,
  750. SYSSOCKET* lrfds, int* lrnum, SYSSOCKET* lwfds, int* lwnum);
  751. typedef struct SRT_EPOLL_EVENT_STR
  752. {
  753. SRTSOCKET fd;
  754. int events; // SRT_EPOLL_IN | SRT_EPOLL_OUT | SRT_EPOLL_ERR
  755. #ifdef __cplusplus
  756. SRT_EPOLL_EVENT_STR(SRTSOCKET s, int ev): fd(s), events(ev) {}
  757. SRT_EPOLL_EVENT_STR(): fd(-1), events(0) {} // NOTE: allows singular values, no init.
  758. #endif
  759. } SRT_EPOLL_EVENT;
  760. SRT_API int srt_epoll_uwait(int eid, SRT_EPOLL_EVENT* fdsSet, int fdsSize, int64_t msTimeOut);
  761. SRT_API int32_t srt_epoll_set(int eid, int32_t flags);
  762. SRT_API int srt_epoll_release(int eid);
  763. // Logging control
  764. SRT_API void srt_setloglevel(int ll);
  765. SRT_API void srt_addlogfa(int fa);
  766. SRT_API void srt_dellogfa(int fa);
  767. SRT_API void srt_resetlogfa(const int* fara, size_t fara_size);
  768. // This isn't predicted, will be only available in SRT C++ API.
  769. // For the time being, until this API is ready, use UDT::setlogstream.
  770. // SRT_API void srt_setlogstream(std::ostream& stream);
  771. SRT_API void srt_setloghandler(void* opaque, SRT_LOG_HANDLER_FN* handler);
  772. SRT_API void srt_setlogflags(int flags);
  773. SRT_API int srt_getsndbuffer(SRTSOCKET sock, size_t* blocks, size_t* bytes);
  774. SRT_API int srt_getrejectreason(SRTSOCKET sock);
  775. SRT_API int srt_setrejectreason(SRTSOCKET sock, int value);
  776. // The srt_rejectreason_msg[] array is deprecated (as unsafe).
  777. // Planned removal: v1.6.0.
  778. SRT_API SRT_ATR_DEPRECATED extern const char* const srt_rejectreason_msg [];
  779. SRT_API const char* srt_rejectreason_str(int id);
  780. SRT_API uint32_t srt_getversion(void);
  781. SRT_API int64_t srt_time_now(void);
  782. SRT_API int64_t srt_connection_time(SRTSOCKET sock);
  783. // Possible internal clock types
  784. #define SRT_SYNC_CLOCK_STDCXX_STEADY 0 // C++11 std::chrono::steady_clock
  785. #define SRT_SYNC_CLOCK_GETTIME_MONOTONIC 1 // clock_gettime with CLOCK_MONOTONIC
  786. #define SRT_SYNC_CLOCK_WINQPC 2
  787. #define SRT_SYNC_CLOCK_MACH_ABSTIME 3
  788. #define SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY 4
  789. #define SRT_SYNC_CLOCK_AMD64_RDTSC 5
  790. #define SRT_SYNC_CLOCK_IA32_RDTSC 6
  791. #define SRT_SYNC_CLOCK_IA64_ITC 7
  792. SRT_API int srt_clock_type(void);
  793. // SRT Socket Groups API (ENABLE_BONDING)
  794. typedef enum SRT_GROUP_TYPE
  795. {
  796. SRT_GTYPE_UNDEFINED,
  797. SRT_GTYPE_BROADCAST,
  798. SRT_GTYPE_BACKUP,
  799. // ...
  800. SRT_GTYPE_E_END
  801. } SRT_GROUP_TYPE;
  802. // Free-form flags for groups
  803. // Flags may be type-specific!
  804. static const uint32_t SRT_GFLAG_SYNCONMSG = 1;
  805. typedef enum SRT_MemberStatus
  806. {
  807. SRT_GST_PENDING, // The socket is created correctly, but not yet ready for getting data.
  808. SRT_GST_IDLE, // The socket is ready to be activated
  809. SRT_GST_RUNNING, // The socket was already activated and is in use
  810. SRT_GST_BROKEN // The last operation broke the socket, it should be closed.
  811. } SRT_MEMBERSTATUS;
  812. struct SRT_SocketGroupData_
  813. {
  814. SRTSOCKET id;
  815. struct sockaddr_storage peeraddr; // Don't want to expose sockaddr_any to public API
  816. SRT_SOCKSTATUS sockstate;
  817. uint16_t weight;
  818. SRT_MEMBERSTATUS memberstate;
  819. int result;
  820. int token;
  821. };
  822. typedef struct SRT_SocketOptionObject SRT_SOCKOPT_CONFIG;
  823. typedef struct SRT_GroupMemberConfig_
  824. {
  825. SRTSOCKET id;
  826. struct sockaddr_storage srcaddr;
  827. struct sockaddr_storage peeraddr; // Don't want to expose sockaddr_any to public API
  828. uint16_t weight;
  829. SRT_SOCKOPT_CONFIG* config;
  830. int errorcode;
  831. int token;
  832. } SRT_SOCKGROUPCONFIG;
  833. SRT_API SRTSOCKET srt_create_group(SRT_GROUP_TYPE);
  834. SRT_API SRTSOCKET srt_groupof(SRTSOCKET socket);
  835. SRT_API int srt_group_data(SRTSOCKET socketgroup, SRT_SOCKGROUPDATA* output, size_t* inoutlen);
  836. SRT_API SRT_SOCKOPT_CONFIG* srt_create_config(void);
  837. SRT_API void srt_delete_config(SRT_SOCKOPT_CONFIG* config /*nullable*/);
  838. SRT_API int srt_config_add(SRT_SOCKOPT_CONFIG* config, SRT_SOCKOPT option, const void* contents, int len);
  839. SRT_API SRT_SOCKGROUPCONFIG srt_prepare_endpoint(const struct sockaddr* src /*nullable*/, const struct sockaddr* adr, int namelen);
  840. SRT_API int srt_connect_group(SRTSOCKET group, SRT_SOCKGROUPCONFIG name[], int arraysize);
  841. #ifdef __cplusplus
  842. }
  843. #endif
  844. #endif