2
0

rtc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /**
  2. * Copyright (c) 2019-2021 Paul-Louis Ageneau
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. */
  8. #ifndef RTC_C_API
  9. #define RTC_C_API
  10. #include "version.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #include <stdbool.h>
  15. #include <stdint.h>
  16. #ifdef RTC_STATIC
  17. #define RTC_C_EXPORT
  18. #else // dynamic library
  19. #ifdef _WIN32
  20. #ifdef RTC_EXPORTS
  21. #define RTC_C_EXPORT __declspec(dllexport) // building the library
  22. #else
  23. #define RTC_C_EXPORT __declspec(dllimport) // using the library
  24. #endif
  25. #else // not WIN32
  26. #define RTC_C_EXPORT
  27. #endif
  28. #endif
  29. #ifndef RTC_ENABLE_WEBSOCKET
  30. #define RTC_ENABLE_WEBSOCKET 1
  31. #endif
  32. #ifndef RTC_ENABLE_MEDIA
  33. #define RTC_ENABLE_MEDIA 1
  34. #endif
  35. #define RTC_DEFAULT_MTU 1280 // IPv6 minimum guaranteed MTU
  36. #if RTC_ENABLE_MEDIA
  37. #define RTC_DEFAULT_MAX_FRAGMENT_SIZE ((uint16_t)(RTC_DEFAULT_MTU - 12 - 8 - 40)) // SRTP/UDP/IPv6
  38. #define RTC_DEFAULT_MAX_STORED_PACKET_COUNT 512
  39. // Deprecated, do not use
  40. #define RTC_DEFAULT_MAXIMUM_FRAGMENT_SIZE RTC_DEFAULT_MAX_FRAGMENT_SIZE
  41. #define RTC_DEFAULT_MAXIMUM_PACKET_COUNT_FOR_NACK_CACHE RTC_DEFAULT_MAX_STORED_PACKET_COUNT
  42. #endif
  43. #ifdef _WIN32
  44. #ifdef CAPI_STDCALL
  45. #define RTC_API __stdcall
  46. #else
  47. #define RTC_API
  48. #endif
  49. #else // not WIN32
  50. #define RTC_API
  51. #endif
  52. #if defined(__GNUC__) || defined(__clang__)
  53. #define RTC_DEPRECATED __attribute__((deprecated))
  54. #elif defined(_MSC_VER)
  55. #define RTC_DEPRECATED __declspec(deprecated)
  56. #else
  57. #define DEPRECATED
  58. #endif
  59. // libdatachannel C API
  60. typedef enum {
  61. RTC_NEW = 0,
  62. RTC_CONNECTING = 1,
  63. RTC_CONNECTED = 2,
  64. RTC_DISCONNECTED = 3,
  65. RTC_FAILED = 4,
  66. RTC_CLOSED = 5
  67. } rtcState;
  68. typedef enum {
  69. RTC_ICE_NEW = 0,
  70. RTC_ICE_CHECKING = 1,
  71. RTC_ICE_CONNECTED = 2,
  72. RTC_ICE_COMPLETED = 3,
  73. RTC_ICE_FAILED = 4,
  74. RTC_ICE_DISCONNECTED = 5,
  75. RTC_ICE_CLOSED = 6
  76. } rtcIceState;
  77. typedef enum {
  78. RTC_GATHERING_NEW = 0,
  79. RTC_GATHERING_INPROGRESS = 1,
  80. RTC_GATHERING_COMPLETE = 2
  81. } rtcGatheringState;
  82. typedef enum {
  83. RTC_SIGNALING_STABLE = 0,
  84. RTC_SIGNALING_HAVE_LOCAL_OFFER = 1,
  85. RTC_SIGNALING_HAVE_REMOTE_OFFER = 2,
  86. RTC_SIGNALING_HAVE_LOCAL_PRANSWER = 3,
  87. RTC_SIGNALING_HAVE_REMOTE_PRANSWER = 4,
  88. } rtcSignalingState;
  89. typedef enum { // Don't change, it must match plog severity
  90. RTC_LOG_NONE = 0,
  91. RTC_LOG_FATAL = 1,
  92. RTC_LOG_ERROR = 2,
  93. RTC_LOG_WARNING = 3,
  94. RTC_LOG_INFO = 4,
  95. RTC_LOG_DEBUG = 5,
  96. RTC_LOG_VERBOSE = 6
  97. } rtcLogLevel;
  98. typedef enum {
  99. RTC_CERTIFICATE_DEFAULT = 0, // ECDSA
  100. RTC_CERTIFICATE_ECDSA = 1,
  101. RTC_CERTIFICATE_RSA = 2,
  102. } rtcCertificateType;
  103. typedef enum {
  104. // video
  105. RTC_CODEC_H264 = 0,
  106. RTC_CODEC_VP8 = 1,
  107. RTC_CODEC_VP9 = 2,
  108. RTC_CODEC_H265 = 3,
  109. RTC_CODEC_AV1 = 4,
  110. // audio
  111. RTC_CODEC_OPUS = 128,
  112. RTC_CODEC_PCMU = 129,
  113. RTC_CODEC_PCMA = 130,
  114. RTC_CODEC_AAC = 131,
  115. } rtcCodec;
  116. typedef enum {
  117. RTC_DIRECTION_UNKNOWN = 0,
  118. RTC_DIRECTION_SENDONLY = 1,
  119. RTC_DIRECTION_RECVONLY = 2,
  120. RTC_DIRECTION_SENDRECV = 3,
  121. RTC_DIRECTION_INACTIVE = 4
  122. } rtcDirection;
  123. typedef enum { RTC_TRANSPORT_POLICY_ALL = 0, RTC_TRANSPORT_POLICY_RELAY = 1 } rtcTransportPolicy;
  124. #define RTC_ERR_SUCCESS 0
  125. #define RTC_ERR_INVALID -1 // invalid argument
  126. #define RTC_ERR_FAILURE -2 // runtime error
  127. #define RTC_ERR_NOT_AVAIL -3 // element not available
  128. #define RTC_ERR_TOO_SMALL -4 // buffer too small
  129. typedef void(RTC_API *rtcLogCallbackFunc)(rtcLogLevel level, const char *message);
  130. typedef void(RTC_API *rtcDescriptionCallbackFunc)(int pc, const char *sdp, const char *type,
  131. void *ptr);
  132. typedef void(RTC_API *rtcCandidateCallbackFunc)(int pc, const char *cand, const char *mid,
  133. void *ptr);
  134. typedef void(RTC_API *rtcStateChangeCallbackFunc)(int pc, rtcState state, void *ptr);
  135. typedef void(RTC_API *rtcIceStateChangeCallbackFunc)(int pc, rtcIceState state, void *ptr);
  136. typedef void(RTC_API *rtcGatheringStateCallbackFunc)(int pc, rtcGatheringState state, void *ptr);
  137. typedef void(RTC_API *rtcSignalingStateCallbackFunc)(int pc, rtcSignalingState state, void *ptr);
  138. typedef void(RTC_API *rtcDataChannelCallbackFunc)(int pc, int dc, void *ptr);
  139. typedef void(RTC_API *rtcTrackCallbackFunc)(int pc, int tr, void *ptr);
  140. typedef void(RTC_API *rtcOpenCallbackFunc)(int id, void *ptr);
  141. typedef void(RTC_API *rtcClosedCallbackFunc)(int id, void *ptr);
  142. typedef void(RTC_API *rtcErrorCallbackFunc)(int id, const char *error, void *ptr);
  143. typedef void(RTC_API *rtcMessageCallbackFunc)(int id, const char *message, int size, void *ptr);
  144. typedef void *(RTC_API *rtcInterceptorCallbackFunc)(int pc, const char *message, int size,
  145. void *ptr);
  146. typedef void(RTC_API *rtcBufferedAmountLowCallbackFunc)(int id, void *ptr);
  147. typedef void(RTC_API *rtcAvailableCallbackFunc)(int id, void *ptr);
  148. typedef void(RTC_API *rtcPliHandlerCallbackFunc)(int tr, void *ptr);
  149. typedef void(RTC_API *rtcRembHandlerCallbackFunc)(int tr, unsigned int bitrate, void *ptr);
  150. // Log
  151. // NULL cb on the first call will log to stdout
  152. RTC_C_EXPORT void rtcInitLogger(rtcLogLevel level, rtcLogCallbackFunc cb);
  153. // User pointer
  154. RTC_C_EXPORT void rtcSetUserPointer(int id, void *ptr);
  155. RTC_C_EXPORT void *rtcGetUserPointer(int i);
  156. // PeerConnection
  157. typedef struct {
  158. const char **iceServers;
  159. int iceServersCount;
  160. const char *proxyServer; // libnice only
  161. const char *bindAddress; // libjuice only, NULL means any
  162. rtcCertificateType certificateType;
  163. rtcTransportPolicy iceTransportPolicy;
  164. bool enableIceTcp; // libnice only
  165. bool enableIceUdpMux; // libjuice only
  166. bool disableAutoNegotiation;
  167. bool forceMediaTransport;
  168. uint16_t portRangeBegin; // 0 means automatic
  169. uint16_t portRangeEnd; // 0 means automatic
  170. int mtu; // <= 0 means automatic
  171. int maxMessageSize; // <= 0 means default
  172. } rtcConfiguration;
  173. RTC_C_EXPORT int rtcCreatePeerConnection(const rtcConfiguration *config); // returns pc id
  174. RTC_C_EXPORT int rtcClosePeerConnection(int pc);
  175. RTC_C_EXPORT int rtcDeletePeerConnection(int pc);
  176. RTC_C_EXPORT int rtcSetLocalDescriptionCallback(int pc, rtcDescriptionCallbackFunc cb);
  177. RTC_C_EXPORT int rtcSetLocalCandidateCallback(int pc, rtcCandidateCallbackFunc cb);
  178. RTC_C_EXPORT int rtcSetStateChangeCallback(int pc, rtcStateChangeCallbackFunc cb);
  179. RTC_C_EXPORT int rtcSetIceStateChangeCallback(int pc, rtcIceStateChangeCallbackFunc cb);
  180. RTC_C_EXPORT int rtcSetGatheringStateChangeCallback(int pc, rtcGatheringStateCallbackFunc cb);
  181. RTC_C_EXPORT int rtcSetSignalingStateChangeCallback(int pc, rtcSignalingStateCallbackFunc cb);
  182. RTC_C_EXPORT int rtcSetLocalDescription(int pc, const char *type);
  183. RTC_C_EXPORT int rtcSetRemoteDescription(int pc, const char *sdp, const char *type);
  184. RTC_C_EXPORT int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid);
  185. RTC_C_EXPORT int rtcGetLocalDescription(int pc, char *buffer, int size);
  186. RTC_C_EXPORT int rtcGetRemoteDescription(int pc, char *buffer, int size);
  187. RTC_C_EXPORT int rtcGetLocalDescriptionType(int pc, char *buffer, int size);
  188. RTC_C_EXPORT int rtcGetRemoteDescriptionType(int pc, char *buffer, int size);
  189. RTC_C_EXPORT int rtcGetLocalAddress(int pc, char *buffer, int size);
  190. RTC_C_EXPORT int rtcGetRemoteAddress(int pc, char *buffer, int size);
  191. RTC_C_EXPORT int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote,
  192. int remoteSize);
  193. RTC_C_EXPORT bool rtcIsNegotiationNeeded(int pc);
  194. RTC_C_EXPORT int rtcGetMaxDataChannelStream(int pc);
  195. RTC_C_EXPORT int rtcGetRemoteMaxMessageSize(int pc);
  196. // DataChannel, Track, and WebSocket common API
  197. RTC_C_EXPORT int rtcSetOpenCallback(int id, rtcOpenCallbackFunc cb);
  198. RTC_C_EXPORT int rtcSetClosedCallback(int id, rtcClosedCallbackFunc cb);
  199. RTC_C_EXPORT int rtcSetErrorCallback(int id, rtcErrorCallbackFunc cb);
  200. RTC_C_EXPORT int rtcSetMessageCallback(int id, rtcMessageCallbackFunc cb);
  201. RTC_C_EXPORT int rtcSendMessage(int id, const char *data, int size);
  202. RTC_C_EXPORT int rtcClose(int id);
  203. RTC_C_EXPORT int rtcDelete(int id);
  204. RTC_C_EXPORT bool rtcIsOpen(int id);
  205. RTC_C_EXPORT bool rtcIsClosed(int id);
  206. RTC_C_EXPORT int rtcMaxMessageSize(int id);
  207. RTC_C_EXPORT int rtcGetBufferedAmount(int id); // total size buffered to send
  208. RTC_C_EXPORT int rtcSetBufferedAmountLowThreshold(int id, int amount);
  209. RTC_C_EXPORT int rtcSetBufferedAmountLowCallback(int id, rtcBufferedAmountLowCallbackFunc cb);
  210. // DataChannel, Track, and WebSocket common extended API
  211. RTC_C_EXPORT int rtcGetAvailableAmount(int id); // total size available to receive
  212. RTC_C_EXPORT int rtcSetAvailableCallback(int id, rtcAvailableCallbackFunc cb);
  213. RTC_C_EXPORT int rtcReceiveMessage(int id, char *buffer, int *size);
  214. // DataChannel
  215. typedef struct {
  216. bool unordered;
  217. bool unreliable;
  218. unsigned int maxPacketLifeTime; // ignored if reliable
  219. unsigned int maxRetransmits; // ignored if reliable
  220. } rtcReliability;
  221. typedef struct {
  222. rtcReliability reliability;
  223. const char *protocol; // empty string if NULL
  224. bool negotiated;
  225. bool manualStream;
  226. uint16_t stream; // numeric ID 0-65534, ignored if manualStream is false
  227. } rtcDataChannelInit;
  228. RTC_C_EXPORT int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb);
  229. RTC_C_EXPORT int rtcCreateDataChannel(int pc, const char *label); // returns dc id
  230. RTC_C_EXPORT int rtcCreateDataChannelEx(int pc, const char *label,
  231. const rtcDataChannelInit *init); // returns dc id
  232. RTC_C_EXPORT int rtcDeleteDataChannel(int dc);
  233. RTC_C_EXPORT int rtcGetDataChannelStream(int dc);
  234. RTC_C_EXPORT int rtcGetDataChannelLabel(int dc, char *buffer, int size);
  235. RTC_C_EXPORT int rtcGetDataChannelProtocol(int dc, char *buffer, int size);
  236. RTC_C_EXPORT int rtcGetDataChannelReliability(int dc, rtcReliability *reliability);
  237. // Track
  238. typedef struct {
  239. rtcDirection direction;
  240. rtcCodec codec;
  241. int payloadType;
  242. uint32_t ssrc;
  243. const char *mid;
  244. const char *name; // optional
  245. const char *msid; // optional
  246. const char *trackId; // optional, track ID used in MSID
  247. const char *profile; // optional, codec profile
  248. } rtcTrackInit;
  249. RTC_C_EXPORT int rtcSetTrackCallback(int pc, rtcTrackCallbackFunc cb);
  250. RTC_C_EXPORT int rtcAddTrack(int pc, const char *mediaDescriptionSdp); // returns tr id
  251. RTC_C_EXPORT int rtcAddTrackEx(int pc, const rtcTrackInit *init); // returns tr id
  252. RTC_C_EXPORT int rtcDeleteTrack(int tr);
  253. RTC_C_EXPORT int rtcGetTrackDescription(int tr, char *buffer, int size);
  254. RTC_C_EXPORT int rtcGetTrackMid(int tr, char *buffer, int size);
  255. RTC_C_EXPORT int rtcGetTrackDirection(int tr, rtcDirection *direction);
  256. RTC_C_EXPORT int rtcRequestKeyframe(int tr);
  257. RTC_C_EXPORT int rtcRequestBitrate(int tr, unsigned int bitrate);
  258. #if RTC_ENABLE_MEDIA
  259. // Media
  260. // Define how OBUs are packetizied in a AV1 Sample
  261. typedef enum {
  262. RTC_OBU_PACKETIZED_OBU = 0,
  263. RTC_OBU_PACKETIZED_TEMPORAL_UNIT = 1,
  264. } rtcObuPacketization;
  265. // Define how NAL units are separated in a H264/H265 sample
  266. typedef enum {
  267. RTC_NAL_SEPARATOR_LENGTH = 0, // first 4 bytes are NAL unit length
  268. RTC_NAL_SEPARATOR_LONG_START_SEQUENCE = 1, // 0x00, 0x00, 0x00, 0x01
  269. RTC_NAL_SEPARATOR_SHORT_START_SEQUENCE = 2, // 0x00, 0x00, 0x01
  270. RTC_NAL_SEPARATOR_START_SEQUENCE = 3, // long or short start sequence
  271. } rtcNalUnitSeparator;
  272. typedef struct {
  273. uint32_t ssrc;
  274. const char *cname;
  275. uint8_t payloadType;
  276. uint32_t clockRate;
  277. uint16_t sequenceNumber;
  278. uint32_t timestamp;
  279. // H264, H265, AV1
  280. uint16_t maxFragmentSize; // Maximum fragment size, 0 means default
  281. // H264/H265 only
  282. rtcNalUnitSeparator nalSeparator; // NAL unit separator
  283. // AV1 only
  284. rtcObuPacketization obuPacketization; // OBU paketization for AV1 samples
  285. uint8_t playoutDelayId;
  286. uint16_t playoutDelayMin;
  287. uint16_t playoutDelayMax;
  288. } rtcPacketizerInit;
  289. // Deprecated, do not use
  290. typedef rtcPacketizerInit rtcPacketizationHandlerInit;
  291. typedef struct {
  292. uint32_t ssrc;
  293. const char *name; // optional
  294. const char *msid; // optional
  295. const char *trackId; // optional, track ID used in MSID
  296. } rtcSsrcForTypeInit;
  297. // Opaque type used (via rtcMessage*) to reference an rtc::Message
  298. typedef void *rtcMessage;
  299. // Allocate a new opaque message.
  300. // Must be explicitly freed by rtcDeleteOpaqueMessage() unless
  301. // explicitly returned by a media interceptor callback;
  302. RTC_C_EXPORT rtcMessage *rtcCreateOpaqueMessage(void *data, int size);
  303. RTC_C_EXPORT void rtcDeleteOpaqueMessage(rtcMessage *msg);
  304. // Set MediaInterceptor on peer connection
  305. RTC_C_EXPORT int rtcSetMediaInterceptorCallback(int id, rtcInterceptorCallbackFunc cb);
  306. // Set a packetizer on track
  307. RTC_C_EXPORT int rtcSetH264Packetizer(int tr, const rtcPacketizerInit *init);
  308. RTC_C_EXPORT int rtcSetH265Packetizer(int tr, const rtcPacketizerInit *init);
  309. RTC_C_EXPORT int rtcSetAV1Packetizer(int tr, const rtcPacketizerInit *init);
  310. RTC_C_EXPORT int rtcSetOpusPacketizer(int tr, const rtcPacketizerInit *init);
  311. RTC_C_EXPORT int rtcSetAACPacketizer(int tr, const rtcPacketizerInit *init);
  312. // Deprecated, do not use
  313. RTC_DEPRECATED static inline int
  314. rtcSetH264PacketizationHandler(int tr, const rtcPacketizationHandlerInit *init) {
  315. return rtcSetH264Packetizer(tr, init);
  316. }
  317. RTC_DEPRECATED static inline int
  318. rtcSetH265PacketizationHandler(int tr, const rtcPacketizationHandlerInit *init) {
  319. return rtcSetH265Packetizer(tr, init);
  320. }
  321. RTC_DEPRECATED static inline int
  322. rtcSetAV1PacketizationHandler(int tr, const rtcPacketizationHandlerInit *init) {
  323. return rtcSetAV1Packetizer(tr, init);
  324. }
  325. RTC_DEPRECATED static inline int
  326. rtcSetOpusPacketizationHandler(int tr, const rtcPacketizationHandlerInit *init) {
  327. return rtcSetOpusPacketizer(tr, init);
  328. }
  329. RTC_DEPRECATED static inline int
  330. rtcSetAACPacketizationHandler(int tr, const rtcPacketizationHandlerInit *init) {
  331. return rtcSetAACPacketizer(tr, init);
  332. }
  333. // Chain RtcpReceivingSession on track
  334. RTC_C_EXPORT int rtcChainRtcpReceivingSession(int tr);
  335. // Chain RtcpSrReporter on track
  336. RTC_C_EXPORT int rtcChainRtcpSrReporter(int tr);
  337. // Chain RtcpNackResponder on track
  338. RTC_C_EXPORT int rtcChainRtcpNackResponder(int tr, unsigned int maxStoredPacketsCount);
  339. // Chain PliHandler on track
  340. RTC_C_EXPORT int rtcChainPliHandler(int tr, rtcPliHandlerCallbackFunc cb);
  341. // Chain RembHandler on track
  342. RTC_C_EXPORT int rtcChainRembHandler(int tr, rtcRembHandlerCallbackFunc cb);
  343. // Transform seconds to timestamp using track's clock rate, result is written to timestamp
  344. RTC_C_EXPORT int rtcTransformSecondsToTimestamp(int id, double seconds, uint32_t *timestamp);
  345. // Transform timestamp to seconds using track's clock rate, result is written to seconds
  346. RTC_C_EXPORT int rtcTransformTimestampToSeconds(int id, uint32_t timestamp, double *seconds);
  347. // Get current timestamp, result is written to timestamp
  348. RTC_C_EXPORT int rtcGetCurrentTrackTimestamp(int id, uint32_t *timestamp);
  349. // Set RTP timestamp for track identified by given id
  350. RTC_C_EXPORT int rtcSetTrackRtpTimestamp(int id, uint32_t timestamp);
  351. // Get timestamp of last RTCP SR, result is written to timestamp
  352. RTC_C_EXPORT int rtcGetLastTrackSenderReportTimestamp(int id, uint32_t *timestamp);
  353. // Set NeedsToReport flag in RtcpSrReporter handler identified by given track id
  354. RTC_C_EXPORT int rtcSetNeedsToSendRtcpSr(int id);
  355. // Get all available payload types for given codec and stores them in buffer, does nothing if
  356. // buffer is NULL
  357. int rtcGetTrackPayloadTypesForCodec(int tr, const char *ccodec, int *buffer, int size);
  358. // Get all SSRCs for given track
  359. int rtcGetSsrcsForTrack(int tr, uint32_t *buffer, int count);
  360. // Get CName for SSRC
  361. int rtcGetCNameForSsrc(int tr, uint32_t ssrc, char *cname, int cnameSize);
  362. // Get all SSRCs for given media type in given SDP
  363. int rtcGetSsrcsForType(const char *mediaType, const char *sdp, uint32_t *buffer, int bufferSize);
  364. // Set SSRC for given media type in given SDP
  365. int rtcSetSsrcForType(const char *mediaType, const char *sdp, char *buffer, const int bufferSize,
  366. rtcSsrcForTypeInit *init);
  367. #endif // RTC_ENABLE_MEDIA
  368. #if RTC_ENABLE_WEBSOCKET
  369. // WebSocket
  370. typedef struct {
  371. bool disableTlsVerification; // if true, don't verify the TLS certificate
  372. const char *proxyServer; // only non-authenticated http supported for now
  373. const char **protocols;
  374. int protocolsCount;
  375. int connectionTimeoutMs; // in milliseconds, 0 means default, < 0 means disabled
  376. int pingIntervalMs; // in milliseconds, 0 means default, < 0 means disabled
  377. int maxOutstandingPings; // 0 means default, < 0 means disabled
  378. int maxMessageSize; // <= 0 means default
  379. } rtcWsConfiguration;
  380. RTC_C_EXPORT int rtcCreateWebSocket(const char *url); // returns ws id
  381. RTC_C_EXPORT int rtcCreateWebSocketEx(const char *url, const rtcWsConfiguration *config);
  382. RTC_C_EXPORT int rtcDeleteWebSocket(int ws);
  383. RTC_C_EXPORT int rtcGetWebSocketRemoteAddress(int ws, char *buffer, int size);
  384. RTC_C_EXPORT int rtcGetWebSocketPath(int ws, char *buffer, int size);
  385. // WebSocketServer
  386. typedef void(RTC_API *rtcWebSocketClientCallbackFunc)(int wsserver, int ws, void *ptr);
  387. typedef struct {
  388. uint16_t port; // 0 means automatic selection
  389. bool enableTls; // if true, enable TLS (WSS)
  390. const char *certificatePemFile; // NULL for autogenerated certificate
  391. const char *keyPemFile; // NULL for autogenerated certificate
  392. const char *keyPemPass; // NULL if no pass
  393. const char *bindAddress; // NULL for any
  394. int connectionTimeoutMs; // in milliseconds, 0 means default, < 0 means disabled
  395. int maxMessageSize; // <= 0 means default
  396. } rtcWsServerConfiguration;
  397. RTC_C_EXPORT int rtcCreateWebSocketServer(const rtcWsServerConfiguration *config,
  398. rtcWebSocketClientCallbackFunc cb); // returns wsserver id
  399. RTC_C_EXPORT int rtcDeleteWebSocketServer(int wsserver);
  400. RTC_C_EXPORT int rtcGetWebSocketServerPort(int wsserver);
  401. #endif
  402. // Optional global preload and cleanup
  403. RTC_C_EXPORT void rtcPreload(void);
  404. RTC_C_EXPORT void rtcCleanup(void);
  405. // SCTP global settings
  406. typedef struct {
  407. int recvBufferSize; // in bytes, <= 0 means optimized default
  408. int sendBufferSize; // in bytes, <= 0 means optimized default
  409. int maxChunksOnQueue; // in chunks, <= 0 means optimized default
  410. int initialCongestionWindow; // in MTUs, <= 0 means optimized default
  411. int maxBurst; // in MTUs, 0 means optimized default, < 0 means disabled
  412. int congestionControlModule; // 0: RFC2581 (default), 1: HSTCP, 2: H-TCP, 3: RTCC
  413. int delayedSackTimeMs; // in milliseconds, 0 means optimized default, < 0 means disabled
  414. int minRetransmitTimeoutMs; // in milliseconds, <= 0 means optimized default
  415. int maxRetransmitTimeoutMs; // in milliseconds, <= 0 means optimized default
  416. int initialRetransmitTimeoutMs; // in milliseconds, <= 0 means optimized default
  417. int maxRetransmitAttempts; // number of retransmissions, <= 0 means optimized default
  418. int heartbeatIntervalMs; // in milliseconds, <= 0 means optimized default
  419. } rtcSctpSettings;
  420. // Note: SCTP settings apply to newly-created PeerConnections only
  421. RTC_C_EXPORT int rtcSetSctpSettings(const rtcSctpSettings *settings);
  422. #ifdef __cplusplus
  423. } // extern "C"
  424. #endif
  425. #endif