rtc.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. // libdatachannel C API
  24. typedef enum {
  25. RTC_NEW = 0,
  26. RTC_CONNECTING = 1,
  27. RTC_CONNECTED = 2,
  28. RTC_DISCONNECTED = 3,
  29. RTC_FAILED = 4,
  30. RTC_CLOSED = 5
  31. } rtcState;
  32. typedef enum {
  33. RTC_GATHERING_NEW = 0,
  34. RTC_GATHERING_INPROGRESS = 1,
  35. RTC_GATHERING_COMPLETE = 2
  36. } rtcGatheringState;
  37. // Don't change, it must match plog severity
  38. typedef enum {
  39. RTC_LOG_NONE = 0,
  40. RTC_LOG_FATAL = 1,
  41. RTC_LOG_ERROR = 2,
  42. RTC_LOG_WARNING = 3,
  43. RTC_LOG_INFO = 4,
  44. RTC_LOG_DEBUG = 5,
  45. RTC_LOG_VERBOSE = 6
  46. } rtcLogLevel;
  47. typedef struct {
  48. const char **iceServers;
  49. int iceServersCount;
  50. } rtcConfiguration;
  51. typedef void (*dataChannelCallbackFunc)(int dc, void *ptr);
  52. typedef void (*descriptionCallbackFunc)(const char *sdp, const char *type, void *ptr);
  53. typedef void (*candidateCallbackFunc)(const char *cand, const char *mid, void *ptr);
  54. typedef void (*stateChangeCallbackFunc)(rtcState state, void *ptr);
  55. typedef void (*gatheringStateCallbackFunc)(rtcGatheringState state, void *ptr);
  56. typedef void (*openCallbackFunc)(void *ptr);
  57. typedef void (*closedCallbackFunc)(void *ptr);
  58. typedef void (*errorCallbackFunc)(const char *error, void *ptr);
  59. typedef void (*messageCallbackFunc)(const char *message, int size, void *ptr);
  60. typedef void (*bufferedAmountLowCallbackFunc)(void *ptr);
  61. typedef void (*availableCallbackFunc)(void *ptr);
  62. // Log
  63. void rtcInitLogger(rtcLogLevel level);
  64. // User pointer
  65. void rtcSetUserPointer(int i, void *ptr);
  66. // PeerConnection
  67. int rtcCreatePeerConnection(const rtcConfiguration *config);
  68. int rtcDeletePeerConnection(int pc);
  69. int rtcSetDataChannelCallback(int pc, dataChannelCallbackFunc cb);
  70. int rtcSetLocalDescriptionCallback(int pc, descriptionCallbackFunc cb);
  71. int rtcSetLocalCandidateCallback(int pc, candidateCallbackFunc cb);
  72. int rtcSetStateChangeCallback(int pc, stateChangeCallbackFunc cb);
  73. int rtcSetGatheringStateChangeCallback(int pc, gatheringStateCallbackFunc cb);
  74. int rtcSetRemoteDescription(int pc, const char *sdp, const char *type);
  75. int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid);
  76. int rtcGetLocalAddress(int pc, char *buffer, int size);
  77. int rtcGetRemoteAddress(int pc, char *buffer, int size);
  78. // DataChannel
  79. int rtcCreateDataChannel(int pc, const char *label);
  80. int rtcDeleteDataChannel(int dc);
  81. int rtcGetDataChannelLabel(int dc, char *buffer, int size);
  82. int rtcSetOpenCallback(int dc, openCallbackFunc cb);
  83. int rtcSetClosedCallback(int dc, closedCallbackFunc cb);
  84. int rtcSetErrorCallback(int dc, errorCallbackFunc cb);
  85. int rtcSetMessageCallback(int dc, messageCallbackFunc cb);
  86. int rtcSendMessage(int dc, const char *data, int size);
  87. int rtcGetBufferedAmount(int dc); // total size buffered to send
  88. int rtcSetBufferedAmountLowThreshold(int dc, int amount);
  89. int rtcSetBufferedAmountLowCallback(int dc, bufferedAmountLowCallbackFunc cb);
  90. // DataChannel extended API
  91. int rtcGetAvailableAmount(int dc); // total size available to receive
  92. int rtcSetAvailableCallback(int dc, availableCallbackFunc cb);
  93. int rtcReceiveMessage(int dc, char *buffer, int *size);
  94. #ifdef __cplusplus
  95. } // extern "C"
  96. #endif
  97. #endif