Debian Codegraph @

srtcore/srt.h

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