srt.h 43 KB

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