rtc.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * Copyright (c) 2019 Paul-Louis Ageneau
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef RTC_C_API
  19. #define RTC_C_API
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #include <stdint.h>
  24. // libdatachannel C API
  25. typedef enum {
  26. RTC_NEW = 0,
  27. RTC_CONNECTING = 1,
  28. RTC_CONNECTED = 2,
  29. RTC_DISCONNECTED = 3,
  30. RTC_FAILED = 4,
  31. RTC_CLOSED = 5
  32. } rtcState;
  33. typedef enum {
  34. RTC_GATHERING_NEW = 0,
  35. RTC_GATHERING_INPROGRESS = 1,
  36. RTC_GATHERING_COMPLETE = 2
  37. } rtcGatheringState;
  38. // Don't change, it must match plog severity
  39. typedef enum {
  40. RTC_LOG_NONE = 0,
  41. RTC_LOG_FATAL = 1,
  42. RTC_LOG_ERROR = 2,
  43. RTC_LOG_WARNING = 3,
  44. RTC_LOG_INFO = 4,
  45. RTC_LOG_DEBUG = 5,
  46. RTC_LOG_VERBOSE = 6
  47. } rtcLogLevel;
  48. typedef struct {
  49. const char **iceServers;
  50. int iceServersCount;
  51. uint16_t portRangeBegin;
  52. uint16_t portRangeEnd;
  53. } rtcConfiguration;
  54. typedef void (*dataChannelCallbackFunc)(int dc, void *ptr);
  55. typedef void (*descriptionCallbackFunc)(const char *sdp, const char *type, void *ptr);
  56. typedef void (*candidateCallbackFunc)(const char *cand, const char *mid, void *ptr);
  57. typedef void (*stateChangeCallbackFunc)(rtcState state, void *ptr);
  58. typedef void (*gatheringStateCallbackFunc)(rtcGatheringState state, void *ptr);
  59. typedef void (*openCallbackFunc)(void *ptr);
  60. typedef void (*closedCallbackFunc)(void *ptr);
  61. typedef void (*errorCallbackFunc)(const char *error, void *ptr);
  62. typedef void (*messageCallbackFunc)(const char *message, int size, void *ptr);
  63. typedef void (*bufferedAmountLowCallbackFunc)(void *ptr);
  64. typedef void (*availableCallbackFunc)(void *ptr);
  65. // Log
  66. void rtcInitLogger(rtcLogLevel level);
  67. // User pointer
  68. void rtcSetUserPointer(int i, void *ptr);
  69. // PeerConnection
  70. int rtcCreatePeerConnection(const rtcConfiguration *config);
  71. int rtcDeletePeerConnection(int pc);
  72. int rtcSetDataChannelCallback(int pc, dataChannelCallbackFunc cb);
  73. int rtcSetLocalDescriptionCallback(int pc, descriptionCallbackFunc cb);
  74. int rtcSetLocalCandidateCallback(int pc, candidateCallbackFunc cb);
  75. int rtcSetStateChangeCallback(int pc, stateChangeCallbackFunc cb);
  76. int rtcSetGatheringStateChangeCallback(int pc, gatheringStateCallbackFunc cb);
  77. int rtcSetRemoteDescription(int pc, const char *sdp, const char *type);
  78. int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid);
  79. int rtcGetLocalAddress(int pc, char *buffer, int size);
  80. int rtcGetRemoteAddress(int pc, char *buffer, int size);
  81. // DataChannel
  82. int rtcCreateDataChannel(int pc, const char *label);
  83. int rtcDeleteDataChannel(int dc);
  84. int rtcGetDataChannelLabel(int dc, char *buffer, int size);
  85. int rtcSetOpenCallback(int dc, openCallbackFunc cb);
  86. int rtcSetClosedCallback(int dc, closedCallbackFunc cb);
  87. int rtcSetErrorCallback(int dc, errorCallbackFunc cb);
  88. int rtcSetMessageCallback(int dc, messageCallbackFunc cb);
  89. int rtcSendMessage(int dc, const char *data, int size);
  90. int rtcGetBufferedAmount(int dc); // total size buffered to send
  91. int rtcSetBufferedAmountLowThreshold(int dc, int amount);
  92. int rtcSetBufferedAmountLowCallback(int dc, bufferedAmountLowCallbackFunc cb);
  93. // DataChannel extended API
  94. int rtcGetAvailableAmount(int dc); // total size available to receive
  95. int rtcSetAvailableCallback(int dc, availableCallbackFunc cb);
  96. int rtcReceiveMessage(int dc, char *buffer, int *size);
  97. // Cleanup
  98. void rtcCleanup();
  99. #ifdef __cplusplus
  100. } // extern "C"
  101. #endif
  102. #endif