|
@@ -16,16 +16,9 @@
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
*/
|
|
|
|
|
|
-#include "include.hpp"
|
|
|
|
-
|
|
|
|
#include "rtc.h"
|
|
#include "rtc.h"
|
|
|
|
|
|
-#include "datachannel.hpp"
|
|
|
|
-#include "log.hpp"
|
|
|
|
-#include "peerconnection.hpp"
|
|
|
|
-#if RTC_ENABLE_WEBSOCKET
|
|
|
|
-#include "websocket.hpp"
|
|
|
|
-#endif
|
|
|
|
|
|
+#include "rtc.hpp"
|
|
|
|
|
|
#include "plog/Formatters/FuncMessageFormatter.h"
|
|
#include "plog/Formatters/FuncMessageFormatter.h"
|
|
|
|
|
|
@@ -42,9 +35,6 @@
|
|
#endif
|
|
#endif
|
|
|
|
|
|
using namespace rtc;
|
|
using namespace rtc;
|
|
-using std::optional;
|
|
|
|
-using std::shared_ptr;
|
|
|
|
-using std::string;
|
|
|
|
using std::chrono::milliseconds;
|
|
using std::chrono::milliseconds;
|
|
|
|
|
|
namespace {
|
|
namespace {
|
|
@@ -53,7 +43,8 @@ std::unordered_map<int, shared_ptr<PeerConnection>> peerConnectionMap;
|
|
std::unordered_map<int, shared_ptr<DataChannel>> dataChannelMap;
|
|
std::unordered_map<int, shared_ptr<DataChannel>> dataChannelMap;
|
|
std::unordered_map<int, shared_ptr<Track>> trackMap;
|
|
std::unordered_map<int, shared_ptr<Track>> trackMap;
|
|
#if RTC_ENABLE_MEDIA
|
|
#if RTC_ENABLE_MEDIA
|
|
-std::unordered_map<int, shared_ptr<RtcpSenderReporter>> rtcpSenderMap;
|
|
|
|
|
|
+std::unordered_map<int, shared_ptr<MediaChainableHandler>> rtcpChainableHandlerMap;
|
|
|
|
+std::unordered_map<int, shared_ptr<RtcpSrReporter>> rtcpSrReporterMap;
|
|
std::unordered_map<int, shared_ptr<RtpPacketizationConfig>> rtpConfigMap;
|
|
std::unordered_map<int, shared_ptr<RtpPacketizationConfig>> rtpConfigMap;
|
|
#endif
|
|
#endif
|
|
#if RTC_ENABLE_WEBSOCKET
|
|
#if RTC_ENABLE_WEBSOCKET
|
|
@@ -63,7 +54,7 @@ std::unordered_map<int, void *> userPointerMap;
|
|
std::mutex mutex;
|
|
std::mutex mutex;
|
|
int lastId = 0;
|
|
int lastId = 0;
|
|
|
|
|
|
-std::optional<void *> getUserPointer(int id) {
|
|
|
|
|
|
+optional<void *> getUserPointer(int id) {
|
|
std::lock_guard lock(mutex);
|
|
std::lock_guard lock(mutex);
|
|
auto it = userPointerMap.find(id);
|
|
auto it = userPointerMap.find(id);
|
|
return it != userPointerMap.end() ? std::make_optional(it->second) : nullopt;
|
|
return it != userPointerMap.end() ? std::make_optional(it->second) : nullopt;
|
|
@@ -141,7 +132,8 @@ void eraseTrack(int tr) {
|
|
if (trackMap.erase(tr) == 0)
|
|
if (trackMap.erase(tr) == 0)
|
|
throw std::invalid_argument("Track ID does not exist");
|
|
throw std::invalid_argument("Track ID does not exist");
|
|
#if RTC_ENABLE_MEDIA
|
|
#if RTC_ENABLE_MEDIA
|
|
- rtcpSenderMap.erase(tr);
|
|
|
|
|
|
+ rtcpSrReporterMap.erase(tr);
|
|
|
|
+ rtcpChainableHandlerMap.erase(tr);
|
|
rtpConfigMap.erase(tr);
|
|
rtpConfigMap.erase(tr);
|
|
#endif
|
|
#endif
|
|
userPointerMap.erase(tr);
|
|
userPointerMap.erase(tr);
|
|
@@ -149,25 +141,41 @@ void eraseTrack(int tr) {
|
|
|
|
|
|
#if RTC_ENABLE_MEDIA
|
|
#if RTC_ENABLE_MEDIA
|
|
|
|
|
|
-shared_ptr<RtcpSenderReporter> getRTCPSender(int id) {
|
|
|
|
|
|
+shared_ptr<RtcpSrReporter> getRtcpSrReporter(int id) {
|
|
std::lock_guard lock(mutex);
|
|
std::lock_guard lock(mutex);
|
|
- if (auto it = rtcpSenderMap.find(id); it != rtcpSenderMap.end())
|
|
|
|
|
|
+ if (auto it = rtcpSrReporterMap.find(id); it != rtcpSrReporterMap.end()) {
|
|
return it->second;
|
|
return it->second;
|
|
- else
|
|
|
|
- throw std::invalid_argument("RtcpSenderReporter ID does not exist");
|
|
|
|
|
|
+ } else {
|
|
|
|
+ throw std::invalid_argument("RtcpSRReporter ID does not exist");
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void emplaceRtcpSrReporter(shared_ptr<RtcpSrReporter> ptr, int tr) {
|
|
|
|
+ std::lock_guard lock(mutex);
|
|
|
|
+ rtcpSrReporterMap.emplace(std::make_pair(tr, ptr));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+shared_ptr<MediaChainableHandler> getMediaChainableHandler(int id) {
|
|
|
|
+ std::lock_guard lock(mutex);
|
|
|
|
+ if (auto it = rtcpChainableHandlerMap.find(id); it != rtcpChainableHandlerMap.end()) {
|
|
|
|
+ return it->second;
|
|
|
|
+ } else {
|
|
|
|
+ throw std::invalid_argument("RtcpChainableHandler ID does not exist");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-void emplaceRTCPSender(shared_ptr<RtcpSenderReporter> ptr, int tr) {
|
|
|
|
|
|
+void emplaceMediaChainableHandler(shared_ptr<MediaChainableHandler> ptr, int tr) {
|
|
std::lock_guard lock(mutex);
|
|
std::lock_guard lock(mutex);
|
|
- rtcpSenderMap.emplace(std::make_pair(tr, ptr));
|
|
|
|
|
|
+ rtcpChainableHandlerMap.emplace(std::make_pair(tr, ptr));
|
|
}
|
|
}
|
|
|
|
|
|
shared_ptr<RtpPacketizationConfig> getRTPConfig(int id) {
|
|
shared_ptr<RtpPacketizationConfig> getRTPConfig(int id) {
|
|
std::lock_guard lock(mutex);
|
|
std::lock_guard lock(mutex);
|
|
- if (auto it = rtpConfigMap.find(id); it != rtpConfigMap.end())
|
|
|
|
|
|
+ if (auto it = rtpConfigMap.find(id); it != rtpConfigMap.end()) {
|
|
return it->second;
|
|
return it->second;
|
|
- else
|
|
|
|
|
|
+ } else {
|
|
throw std::invalid_argument("RTPConfiguration ID does not exist");
|
|
throw std::invalid_argument("RTPConfiguration ID does not exist");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void emplaceRTPConfig(shared_ptr<RtpPacketizationConfig> ptr, int tr) {
|
|
void emplaceRTPConfig(shared_ptr<RtpPacketizationConfig> ptr, int tr) {
|
|
@@ -254,12 +262,6 @@ template <typename F> int wrap(F func) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-#define WRAP(statement) \
|
|
|
|
- wrap([&]() { \
|
|
|
|
- statement; \
|
|
|
|
- return RTC_ERR_SUCCESS; \
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
int copyAndReturn(string s, char *buffer, int size) {
|
|
int copyAndReturn(string s, char *buffer, int size) {
|
|
if (!buffer)
|
|
if (!buffer)
|
|
return int(s.size() + 1);
|
|
return int(s.size() + 1);
|
|
@@ -325,7 +327,7 @@ private:
|
|
} // namespace
|
|
} // namespace
|
|
|
|
|
|
void rtcInitLogger(rtcLogLevel level, rtcLogCallbackFunc cb) {
|
|
void rtcInitLogger(rtcLogLevel level, rtcLogCallbackFunc cb) {
|
|
- static std::optional<plogAppender> appender;
|
|
|
|
|
|
+ static optional<plogAppender> appender;
|
|
const auto severity = static_cast<plog::Severity>(level);
|
|
const auto severity = static_cast<plog::Severity>(level);
|
|
std::lock_guard lock(mutex);
|
|
std::lock_guard lock(mutex);
|
|
if (appender) {
|
|
if (appender) {
|
|
@@ -344,23 +346,28 @@ void rtcSetUserPointer(int i, void *ptr) { setUserPointer(i, ptr); }
|
|
void *rtcGetUserPointer(int i) { return getUserPointer(i).value_or(nullptr); }
|
|
void *rtcGetUserPointer(int i) { return getUserPointer(i).value_or(nullptr); }
|
|
|
|
|
|
int rtcCreatePeerConnection(const rtcConfiguration *config) {
|
|
int rtcCreatePeerConnection(const rtcConfiguration *config) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([config] {
|
|
Configuration c;
|
|
Configuration c;
|
|
for (int i = 0; i < config->iceServersCount; ++i)
|
|
for (int i = 0; i < config->iceServersCount; ++i)
|
|
c.iceServers.emplace_back(string(config->iceServers[i]));
|
|
c.iceServers.emplace_back(string(config->iceServers[i]));
|
|
|
|
|
|
- if (config->portRangeBegin || config->portRangeEnd) {
|
|
|
|
|
|
+ c.enableIceTcp = config->enableIceTcp;
|
|
|
|
+ c.disableAutoNegotiation = config->disableAutoNegotiation;
|
|
|
|
+
|
|
|
|
+ if (config->portRangeBegin > 0 || config->portRangeEnd > 0) {
|
|
c.portRangeBegin = config->portRangeBegin;
|
|
c.portRangeBegin = config->portRangeBegin;
|
|
c.portRangeEnd = config->portRangeEnd;
|
|
c.portRangeEnd = config->portRangeEnd;
|
|
}
|
|
}
|
|
|
|
|
|
- c.enableIceTcp = config->enableIceTcp;
|
|
|
|
|
|
+ if(config->mtu > 0)
|
|
|
|
+ c.mtu = size_t(config->mtu);
|
|
|
|
+
|
|
return emplacePeerConnection(std::make_shared<PeerConnection>(c));
|
|
return emplacePeerConnection(std::make_shared<PeerConnection>(c));
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcDeletePeerConnection(int pc) {
|
|
int rtcDeletePeerConnection(int pc) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([pc] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
peerConnection->onDataChannel(nullptr);
|
|
peerConnection->onDataChannel(nullptr);
|
|
peerConnection->onTrack(nullptr);
|
|
peerConnection->onTrack(nullptr);
|
|
@@ -370,13 +377,16 @@ int rtcDeletePeerConnection(int pc) {
|
|
peerConnection->onGatheringStateChange(nullptr);
|
|
peerConnection->onGatheringStateChange(nullptr);
|
|
|
|
|
|
erasePeerConnection(pc);
|
|
erasePeerConnection(pc);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-int rtcAddDataChannel(int pc, const char *label) { return rtcAddDataChannelEx(pc, label, nullptr); }
|
|
|
|
|
|
+int rtcCreateDataChannel(int pc, const char *label) {
|
|
|
|
+ return rtcCreateDataChannelEx(pc, label, nullptr);
|
|
|
|
+}
|
|
|
|
|
|
-int rtcAddDataChannelEx(int pc, const char *label, const rtcDataChannelInit *init) {
|
|
|
|
- return WRAP({
|
|
|
|
|
|
+int rtcCreateDataChannelEx(int pc, const char *label, const rtcDataChannelInit *init) {
|
|
|
|
+ return wrap([&] {
|
|
DataChannelInit dci = {};
|
|
DataChannelInit dci = {};
|
|
if (init) {
|
|
if (init) {
|
|
auto *reliability = &init->reliability;
|
|
auto *reliability = &init->reliability;
|
|
@@ -387,7 +397,7 @@ int rtcAddDataChannelEx(int pc, const char *label, const rtcDataChannelInit *ini
|
|
dci.reliability.rexmit = milliseconds(reliability->maxPacketLifeTime);
|
|
dci.reliability.rexmit = milliseconds(reliability->maxPacketLifeTime);
|
|
} else {
|
|
} else {
|
|
dci.reliability.type = Reliability::Type::Rexmit;
|
|
dci.reliability.type = Reliability::Type::Rexmit;
|
|
- dci.reliability.rexmit = int(reliability->maxRetransmits);
|
|
|
|
|
|
+ dci.reliability.rexmit = reliability->maxRetransmits;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
dci.reliability.type = Reliability::Type::Reliable;
|
|
dci.reliability.type = Reliability::Type::Reliable;
|
|
@@ -400,7 +410,7 @@ int rtcAddDataChannelEx(int pc, const char *label, const rtcDataChannelInit *ini
|
|
|
|
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
int dc = emplaceDataChannel(
|
|
int dc = emplaceDataChannel(
|
|
- peerConnection->addDataChannel(string(label ? label : ""), std::move(dci)));
|
|
|
|
|
|
+ peerConnection->createDataChannel(string(label ? label : ""), std::move(dci)));
|
|
|
|
|
|
if (auto ptr = getUserPointer(pc))
|
|
if (auto ptr = getUserPointer(pc))
|
|
rtcSetUserPointer(dc, *ptr);
|
|
rtcSetUserPointer(dc, *ptr);
|
|
@@ -409,18 +419,8 @@ int rtcAddDataChannelEx(int pc, const char *label, const rtcDataChannelInit *ini
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-int rtcCreateDataChannel(int pc, const char *label) {
|
|
|
|
- return rtcCreateDataChannelEx(pc, label, nullptr);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int rtcCreateDataChannelEx(int pc, const char *label, const rtcDataChannelInit *init) {
|
|
|
|
- int dc = rtcAddDataChannelEx(pc, label, init);
|
|
|
|
- rtcSetLocalDescription(pc, NULL);
|
|
|
|
- return dc;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
int rtcDeleteDataChannel(int dc) {
|
|
int rtcDeleteDataChannel(int dc) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([dc] {
|
|
auto dataChannel = getDataChannel(dc);
|
|
auto dataChannel = getDataChannel(dc);
|
|
dataChannel->onOpen(nullptr);
|
|
dataChannel->onOpen(nullptr);
|
|
dataChannel->onClosed(nullptr);
|
|
dataChannel->onClosed(nullptr);
|
|
@@ -430,12 +430,14 @@ int rtcDeleteDataChannel(int dc) {
|
|
dataChannel->onAvailable(nullptr);
|
|
dataChannel->onAvailable(nullptr);
|
|
|
|
|
|
eraseDataChannel(dc);
|
|
eraseDataChannel(dc);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
#if RTC_ENABLE_MEDIA
|
|
#if RTC_ENABLE_MEDIA
|
|
|
|
|
|
-void setSSRC(Description::Media *description, uint32_t ssrc, const char *_name, const char *_msid) {
|
|
|
|
|
|
+void setSSRC(Description::Media *description, uint32_t ssrc, const char *_name, const char *_msid,
|
|
|
|
+ const char *_trackID) {
|
|
|
|
|
|
optional<string> name = nullopt;
|
|
optional<string> name = nullopt;
|
|
if (_name) {
|
|
if (_name) {
|
|
@@ -447,12 +449,18 @@ void setSSRC(Description::Media *description, uint32_t ssrc, const char *_name,
|
|
msid = string(_msid);
|
|
msid = string(_msid);
|
|
}
|
|
}
|
|
|
|
|
|
- description->addSSRC(ssrc, name, msid);
|
|
|
|
|
|
+ optional<string> trackID = nullopt;
|
|
|
|
+ if (_trackID) {
|
|
|
|
+ trackID = string(_trackID);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ description->addSSRC(ssrc, name, msid, trackID);
|
|
}
|
|
}
|
|
|
|
|
|
int rtcAddTrackEx(int pc, rtcCodec codec, int payloadType, uint32_t ssrc, const char *_mid,
|
|
int rtcAddTrackEx(int pc, rtcCodec codec, int payloadType, uint32_t ssrc, const char *_mid,
|
|
- rtcDirection _direction, const char *_name, const char *_msid) {
|
|
|
|
- return WRAP({
|
|
|
|
|
|
+ rtcDirection _direction, const char *_name, const char *_msid,
|
|
|
|
+ const char *_trackID) {
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
|
|
|
|
auto direction = rtcDirectionToDirection(_direction);
|
|
auto direction = rtcDirectionToDirection(_direction);
|
|
@@ -516,7 +524,7 @@ int rtcAddTrackEx(int pc, rtcCodec codec, int payloadType, uint32_t ssrc, const
|
|
throw std::invalid_argument("Unexpected codec");
|
|
throw std::invalid_argument("Unexpected codec");
|
|
} else {
|
|
} else {
|
|
auto description = optDescription.value();
|
|
auto description = optDescription.value();
|
|
- setSSRC(&description, ssrc, _name, _msid);
|
|
|
|
|
|
+ setSSRC(&description, ssrc, _name, _msid, _trackID);
|
|
|
|
|
|
int tr = emplaceTrack(peerConnection->addTrack(std::move(description)));
|
|
int tr = emplaceTrack(peerConnection->addTrack(std::move(description)));
|
|
if (auto ptr = getUserPointer(pc)) {
|
|
if (auto ptr = getUserPointer(pc)) {
|
|
@@ -528,116 +536,146 @@ int rtcAddTrackEx(int pc, rtcCodec codec, int payloadType, uint32_t ssrc, const
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetH264PacketizationHandler(int tr, uint32_t ssrc, const char *cname, uint8_t payloadType,
|
|
int rtcSetH264PacketizationHandler(int tr, uint32_t ssrc, const char *cname, uint8_t payloadType,
|
|
- uint32_t clockRate, uint16_t maxFragmentSize, uint16_t sequenceNumber,
|
|
|
|
- uint32_t timestamp) {
|
|
|
|
- return WRAP({
|
|
|
|
|
|
+ uint32_t clockRate, uint16_t maxFragmentSize,
|
|
|
|
+ uint16_t sequenceNumber, uint32_t timestamp) {
|
|
|
|
+ return wrap([&] {
|
|
auto track = getTrack(tr);
|
|
auto track = getTrack(tr);
|
|
// create RTP configuration
|
|
// create RTP configuration
|
|
auto rtpConfig = getNewRtpPacketizationConfig(ssrc, cname, payloadType, clockRate,
|
|
auto rtpConfig = getNewRtpPacketizationConfig(ssrc, cname, payloadType, clockRate,
|
|
sequenceNumber, timestamp);
|
|
sequenceNumber, timestamp);
|
|
// create packetizer
|
|
// create packetizer
|
|
- auto packetizer = shared_ptr<H264RtpPacketizer>(new H264RtpPacketizer(rtpConfig));
|
|
|
|
- // create H264 and RTCP SP handler
|
|
|
|
- shared_ptr<H264PacketizationHandler> h264Handler(
|
|
|
|
- new H264PacketizationHandler(H264PacketizationHandler::Separator::Length, packetizer, maxFragmentSize));
|
|
|
|
- emplaceRTCPSender(h264Handler, tr);
|
|
|
|
|
|
+ auto packetizer = std::make_shared<H264RtpPacketizer>(rtpConfig, maxFragmentSize);
|
|
|
|
+ // create H264 handler
|
|
|
|
+ auto h264Handler = std::make_shared<H264PacketizationHandler>(packetizer);
|
|
|
|
+ emplaceMediaChainableHandler(h264Handler, tr);
|
|
emplaceRTPConfig(rtpConfig, tr);
|
|
emplaceRTPConfig(rtpConfig, tr);
|
|
// set handler
|
|
// set handler
|
|
- track->setRtcpHandler(h264Handler);
|
|
|
|
|
|
+ track->setMediaHandler(h264Handler);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetOpusPacketizationHandler(int tr, uint32_t ssrc, const char *cname, uint8_t payloadType,
|
|
int rtcSetOpusPacketizationHandler(int tr, uint32_t ssrc, const char *cname, uint8_t payloadType,
|
|
uint32_t clockRate, uint16_t sequenceNumber,
|
|
uint32_t clockRate, uint16_t sequenceNumber,
|
|
uint32_t timestamp) {
|
|
uint32_t timestamp) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto track = getTrack(tr);
|
|
auto track = getTrack(tr);
|
|
// create RTP configuration
|
|
// create RTP configuration
|
|
auto rtpConfig = getNewRtpPacketizationConfig(ssrc, cname, payloadType, clockRate,
|
|
auto rtpConfig = getNewRtpPacketizationConfig(ssrc, cname, payloadType, clockRate,
|
|
sequenceNumber, timestamp);
|
|
sequenceNumber, timestamp);
|
|
// create packetizer
|
|
// create packetizer
|
|
- auto packetizer = shared_ptr<OpusRtpPacketizer>(new OpusRtpPacketizer(rtpConfig));
|
|
|
|
- // create Opus and RTCP SP handler
|
|
|
|
- shared_ptr<OpusPacketizationHandler> opusHandler(new OpusPacketizationHandler(packetizer));
|
|
|
|
- emplaceRTCPSender(opusHandler, tr);
|
|
|
|
|
|
+ auto packetizer = std::make_shared<OpusRtpPacketizer>(rtpConfig);
|
|
|
|
+ // create Opus handler
|
|
|
|
+ auto opusHandler = std::make_shared<OpusPacketizationHandler>(packetizer);
|
|
|
|
+ emplaceMediaChainableHandler(opusHandler, tr);
|
|
emplaceRTPConfig(rtpConfig, tr);
|
|
emplaceRTPConfig(rtpConfig, tr);
|
|
// set handler
|
|
// set handler
|
|
- track->setRtcpHandler(opusHandler);
|
|
|
|
|
|
+ track->setMediaHandler(opusHandler);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int rtcChainRtcpSrReporter(int tr) {
|
|
|
|
+ return wrap([tr] {
|
|
|
|
+ auto config = getRTPConfig(tr);
|
|
|
|
+ auto reporter = std::make_shared<RtcpSrReporter>(config);
|
|
|
|
+ emplaceRtcpSrReporter(reporter, tr);
|
|
|
|
+ auto chainableHandler = getMediaChainableHandler(tr);
|
|
|
|
+ chainableHandler->addToChain(reporter);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int rtcChainRtcpNackResponder(int tr, unsigned maxStoredPacketsCount) {
|
|
|
|
+ return wrap([tr, maxStoredPacketsCount] {
|
|
|
|
+ auto responder = std::make_shared<RtcpNackResponder>(maxStoredPacketsCount);
|
|
|
|
+ auto chainableHandler = getMediaChainableHandler(tr);
|
|
|
|
+ chainableHandler->addToChain(responder);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetRtpConfigurationStartTime(int id, double startTime_s, bool timeIntervalSince1970,
|
|
int rtcSetRtpConfigurationStartTime(int id, double startTime_s, bool timeIntervalSince1970,
|
|
uint32_t timestamp) {
|
|
uint32_t timestamp) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto config = getRTPConfig(id);
|
|
auto config = getRTPConfig(id);
|
|
auto epoch = RtpPacketizationConfig::EpochStart::T1900;
|
|
auto epoch = RtpPacketizationConfig::EpochStart::T1900;
|
|
if (timeIntervalSince1970) {
|
|
if (timeIntervalSince1970) {
|
|
epoch = RtpPacketizationConfig::EpochStart::T1970;
|
|
epoch = RtpPacketizationConfig::EpochStart::T1970;
|
|
}
|
|
}
|
|
config->setStartTime(startTime_s, epoch, timestamp);
|
|
config->setStartTime(startTime_s, epoch, timestamp);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcStartRtcpSenderReporterRecording(int id) {
|
|
int rtcStartRtcpSenderReporterRecording(int id) {
|
|
- return WRAP({
|
|
|
|
- auto sender = getRTCPSender(id);
|
|
|
|
|
|
+ return wrap([id] {
|
|
|
|
+ auto sender = getRtcpSrReporter(id);
|
|
sender->startRecording();
|
|
sender->startRecording();
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcTransformSecondsToTimestamp(int id, double seconds, uint32_t *timestamp) {
|
|
int rtcTransformSecondsToTimestamp(int id, double seconds, uint32_t *timestamp) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto config = getRTPConfig(id);
|
|
auto config = getRTPConfig(id);
|
|
*timestamp = config->secondsToTimestamp(seconds);
|
|
*timestamp = config->secondsToTimestamp(seconds);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcTransformTimestampToSeconds(int id, uint32_t timestamp, double *seconds) {
|
|
int rtcTransformTimestampToSeconds(int id, uint32_t timestamp, double *seconds) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto config = getRTPConfig(id);
|
|
auto config = getRTPConfig(id);
|
|
*seconds = config->timestampToSeconds(timestamp);
|
|
*seconds = config->timestampToSeconds(timestamp);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetCurrentTrackTimestamp(int id, uint32_t *timestamp) {
|
|
int rtcGetCurrentTrackTimestamp(int id, uint32_t *timestamp) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto config = getRTPConfig(id);
|
|
auto config = getRTPConfig(id);
|
|
*timestamp = config->timestamp;
|
|
*timestamp = config->timestamp;
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetTrackStartTimestamp(int id, uint32_t *timestamp) {
|
|
int rtcGetTrackStartTimestamp(int id, uint32_t *timestamp) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto config = getRTPConfig(id);
|
|
auto config = getRTPConfig(id);
|
|
*timestamp = config->startTimestamp;
|
|
*timestamp = config->startTimestamp;
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetTrackRTPTimestamp(int id, uint32_t timestamp) {
|
|
int rtcSetTrackRTPTimestamp(int id, uint32_t timestamp) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto config = getRTPConfig(id);
|
|
auto config = getRTPConfig(id);
|
|
config->timestamp = timestamp;
|
|
config->timestamp = timestamp;
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetPreviousTrackSenderReportTimestamp(int id, uint32_t *timestamp) {
|
|
int rtcGetPreviousTrackSenderReportTimestamp(int id, uint32_t *timestamp) {
|
|
- return WRAP({
|
|
|
|
- auto sender = getRTCPSender(id);
|
|
|
|
|
|
+ return wrap([&] {
|
|
|
|
+ auto sender = getRtcpSrReporter(id);
|
|
*timestamp = sender->previousReportedTimestamp;
|
|
*timestamp = sender->previousReportedTimestamp;
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-int rtcSetNeedsToSendRTCPSR(int id) {
|
|
|
|
- return WRAP({
|
|
|
|
- auto sender = getRTCPSender(id);
|
|
|
|
|
|
+int rtcSetNeedsToSendRtcpSr(int id) {
|
|
|
|
+ return wrap([id] {
|
|
|
|
+ auto sender = getRtcpSrReporter(id);
|
|
sender->setNeedsToReport();
|
|
sender->setNeedsToReport();
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
#endif // RTC_ENABLE_MEDIA
|
|
#endif // RTC_ENABLE_MEDIA
|
|
|
|
|
|
int rtcAddTrack(int pc, const char *mediaDescriptionSdp) {
|
|
int rtcAddTrack(int pc, const char *mediaDescriptionSdp) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
if (!mediaDescriptionSdp)
|
|
if (!mediaDescriptionSdp)
|
|
throw std::invalid_argument("Unexpected null pointer for track media description");
|
|
throw std::invalid_argument("Unexpected null pointer for track media description");
|
|
|
|
|
|
@@ -652,7 +690,7 @@ int rtcAddTrack(int pc, const char *mediaDescriptionSdp) {
|
|
}
|
|
}
|
|
|
|
|
|
int rtcDeleteTrack(int tr) {
|
|
int rtcDeleteTrack(int tr) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto track = getTrack(tr);
|
|
auto track = getTrack(tr);
|
|
track->onOpen(nullptr);
|
|
track->onOpen(nullptr);
|
|
track->onClosed(nullptr);
|
|
track->onClosed(nullptr);
|
|
@@ -662,11 +700,12 @@ int rtcDeleteTrack(int tr) {
|
|
track->onAvailable(nullptr);
|
|
track->onAvailable(nullptr);
|
|
|
|
|
|
eraseTrack(tr);
|
|
eraseTrack(tr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetTrackDescription(int tr, char *buffer, int size) {
|
|
int rtcGetTrackDescription(int tr, char *buffer, int size) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto track = getTrack(tr);
|
|
auto track = getTrack(tr);
|
|
return copyAndReturn(track->description(), buffer, size);
|
|
return copyAndReturn(track->description(), buffer, size);
|
|
});
|
|
});
|
|
@@ -674,7 +713,7 @@ int rtcGetTrackDescription(int tr, char *buffer, int size) {
|
|
|
|
|
|
#if RTC_ENABLE_WEBSOCKET
|
|
#if RTC_ENABLE_WEBSOCKET
|
|
int rtcCreateWebSocket(const char *url) {
|
|
int rtcCreateWebSocket(const char *url) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto ws = std::make_shared<WebSocket>();
|
|
auto ws = std::make_shared<WebSocket>();
|
|
ws->open(url);
|
|
ws->open(url);
|
|
return emplaceWebSocket(ws);
|
|
return emplaceWebSocket(ws);
|
|
@@ -682,7 +721,7 @@ int rtcCreateWebSocket(const char *url) {
|
|
}
|
|
}
|
|
|
|
|
|
int rtcCreateWebSocketEx(const char *url, const rtcWsConfiguration *config) {
|
|
int rtcCreateWebSocketEx(const char *url, const rtcWsConfiguration *config) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
WebSocket::Configuration c;
|
|
WebSocket::Configuration c;
|
|
c.disableTlsVerification = config->disableTlsVerification;
|
|
c.disableTlsVerification = config->disableTlsVerification;
|
|
auto ws = std::make_shared<WebSocket>(c);
|
|
auto ws = std::make_shared<WebSocket>(c);
|
|
@@ -692,7 +731,7 @@ int rtcCreateWebSocketEx(const char *url, const rtcWsConfiguration *config) {
|
|
}
|
|
}
|
|
|
|
|
|
int rtcDeleteWebsocket(int ws) {
|
|
int rtcDeleteWebsocket(int ws) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto webSocket = getWebSocket(ws);
|
|
auto webSocket = getWebSocket(ws);
|
|
webSocket->onOpen(nullptr);
|
|
webSocket->onOpen(nullptr);
|
|
webSocket->onClosed(nullptr);
|
|
webSocket->onClosed(nullptr);
|
|
@@ -702,12 +741,13 @@ int rtcDeleteWebsocket(int ws) {
|
|
webSocket->onAvailable(nullptr);
|
|
webSocket->onAvailable(nullptr);
|
|
|
|
|
|
eraseWebSocket(ws);
|
|
eraseWebSocket(ws);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
int rtcSetLocalDescriptionCallback(int pc, rtcDescriptionCallbackFunc cb) {
|
|
int rtcSetLocalDescriptionCallback(int pc, rtcDescriptionCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
if (cb)
|
|
if (cb)
|
|
peerConnection->onLocalDescription([pc, cb](Description desc) {
|
|
peerConnection->onLocalDescription([pc, cb](Description desc) {
|
|
@@ -716,11 +756,12 @@ int rtcSetLocalDescriptionCallback(int pc, rtcDescriptionCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
peerConnection->onLocalDescription(nullptr);
|
|
peerConnection->onLocalDescription(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetLocalCandidateCallback(int pc, rtcCandidateCallbackFunc cb) {
|
|
int rtcSetLocalCandidateCallback(int pc, rtcCandidateCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
if (cb)
|
|
if (cb)
|
|
peerConnection->onLocalCandidate([pc, cb](Candidate cand) {
|
|
peerConnection->onLocalCandidate([pc, cb](Candidate cand) {
|
|
@@ -729,11 +770,12 @@ int rtcSetLocalCandidateCallback(int pc, rtcCandidateCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
peerConnection->onLocalCandidate(nullptr);
|
|
peerConnection->onLocalCandidate(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetStateChangeCallback(int pc, rtcStateChangeCallbackFunc cb) {
|
|
int rtcSetStateChangeCallback(int pc, rtcStateChangeCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
if (cb)
|
|
if (cb)
|
|
peerConnection->onStateChange([pc, cb](PeerConnection::State state) {
|
|
peerConnection->onStateChange([pc, cb](PeerConnection::State state) {
|
|
@@ -742,11 +784,12 @@ int rtcSetStateChangeCallback(int pc, rtcStateChangeCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
peerConnection->onStateChange(nullptr);
|
|
peerConnection->onStateChange(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetGatheringStateChangeCallback(int pc, rtcGatheringStateCallbackFunc cb) {
|
|
int rtcSetGatheringStateChangeCallback(int pc, rtcGatheringStateCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
if (cb)
|
|
if (cb)
|
|
peerConnection->onGatheringStateChange([pc, cb](PeerConnection::GatheringState state) {
|
|
peerConnection->onGatheringStateChange([pc, cb](PeerConnection::GatheringState state) {
|
|
@@ -755,11 +798,12 @@ int rtcSetGatheringStateChangeCallback(int pc, rtcGatheringStateCallbackFunc cb)
|
|
});
|
|
});
|
|
else
|
|
else
|
|
peerConnection->onGatheringStateChange(nullptr);
|
|
peerConnection->onGatheringStateChange(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetSignalingStateChangeCallback(int pc, rtcSignalingStateCallbackFunc cb) {
|
|
int rtcSetSignalingStateChangeCallback(int pc, rtcSignalingStateCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
if (cb)
|
|
if (cb)
|
|
peerConnection->onSignalingStateChange([pc, cb](PeerConnection::SignalingState state) {
|
|
peerConnection->onSignalingStateChange([pc, cb](PeerConnection::SignalingState state) {
|
|
@@ -768,14 +812,15 @@ int rtcSetSignalingStateChangeCallback(int pc, rtcSignalingStateCallbackFunc cb)
|
|
});
|
|
});
|
|
else
|
|
else
|
|
peerConnection->onGatheringStateChange(nullptr);
|
|
peerConnection->onGatheringStateChange(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb) {
|
|
int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
if (cb)
|
|
if (cb)
|
|
- peerConnection->onDataChannel([pc, cb](std::shared_ptr<DataChannel> dataChannel) {
|
|
|
|
|
|
+ peerConnection->onDataChannel([pc, cb](shared_ptr<DataChannel> dataChannel) {
|
|
int dc = emplaceDataChannel(dataChannel);
|
|
int dc = emplaceDataChannel(dataChannel);
|
|
if (auto ptr = getUserPointer(pc)) {
|
|
if (auto ptr = getUserPointer(pc)) {
|
|
rtcSetUserPointer(dc, *ptr);
|
|
rtcSetUserPointer(dc, *ptr);
|
|
@@ -784,14 +829,15 @@ int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
peerConnection->onDataChannel(nullptr);
|
|
peerConnection->onDataChannel(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetTrackCallback(int pc, rtcTrackCallbackFunc cb) {
|
|
int rtcSetTrackCallback(int pc, rtcTrackCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
if (cb)
|
|
if (cb)
|
|
- peerConnection->onTrack([pc, cb](std::shared_ptr<Track> track) {
|
|
|
|
|
|
+ peerConnection->onTrack([pc, cb](shared_ptr<Track> track) {
|
|
int tr = emplaceTrack(track);
|
|
int tr = emplaceTrack(track);
|
|
if (auto ptr = getUserPointer(pc)) {
|
|
if (auto ptr = getUserPointer(pc)) {
|
|
rtcSetUserPointer(tr, *ptr);
|
|
rtcSetUserPointer(tr, *ptr);
|
|
@@ -800,41 +846,45 @@ int rtcSetTrackCallback(int pc, rtcTrackCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
peerConnection->onTrack(nullptr);
|
|
peerConnection->onTrack(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetLocalDescription(int pc, const char *type) {
|
|
int rtcSetLocalDescription(int pc, const char *type) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
peerConnection->setLocalDescription(type ? Description::stringToType(type)
|
|
peerConnection->setLocalDescription(type ? Description::stringToType(type)
|
|
: Description::Type::Unspec);
|
|
: Description::Type::Unspec);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetRemoteDescription(int pc, const char *sdp, const char *type) {
|
|
int rtcSetRemoteDescription(int pc, const char *sdp, const char *type) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
|
|
|
|
if (!sdp)
|
|
if (!sdp)
|
|
throw std::invalid_argument("Unexpected null pointer for remote description");
|
|
throw std::invalid_argument("Unexpected null pointer for remote description");
|
|
|
|
|
|
peerConnection->setRemoteDescription({string(sdp), type ? string(type) : ""});
|
|
peerConnection->setRemoteDescription({string(sdp), type ? string(type) : ""});
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid) {
|
|
int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
|
|
|
|
if (!cand)
|
|
if (!cand)
|
|
throw std::invalid_argument("Unexpected null pointer for remote candidate");
|
|
throw std::invalid_argument("Unexpected null pointer for remote candidate");
|
|
|
|
|
|
peerConnection->addRemoteCandidate({string(cand), mid ? string(mid) : ""});
|
|
peerConnection->addRemoteCandidate({string(cand), mid ? string(mid) : ""});
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetLocalDescription(int pc, char *buffer, int size) {
|
|
int rtcGetLocalDescription(int pc, char *buffer, int size) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
|
|
|
|
if (auto desc = peerConnection->localDescription())
|
|
if (auto desc = peerConnection->localDescription())
|
|
@@ -845,7 +895,7 @@ int rtcGetLocalDescription(int pc, char *buffer, int size) {
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetRemoteDescription(int pc, char *buffer, int size) {
|
|
int rtcGetRemoteDescription(int pc, char *buffer, int size) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
|
|
|
|
if (auto desc = peerConnection->remoteDescription())
|
|
if (auto desc = peerConnection->remoteDescription())
|
|
@@ -855,8 +905,30 @@ int rtcGetRemoteDescription(int pc, char *buffer, int size) {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int rtcGetLocalDescriptionType(int pc, char *buffer, int size) {
|
|
|
|
+ return wrap([&] {
|
|
|
|
+ auto peerConnection = getPeerConnection(pc);
|
|
|
|
+
|
|
|
|
+ if (auto desc = peerConnection->localDescription())
|
|
|
|
+ return copyAndReturn(desc->typeString(), buffer, size);
|
|
|
|
+ else
|
|
|
|
+ return RTC_ERR_NOT_AVAIL;
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int rtcGetRemoteDescriptionType(int pc, char *buffer, int size) {
|
|
|
|
+ return wrap([&] {
|
|
|
|
+ auto peerConnection = getPeerConnection(pc);
|
|
|
|
+
|
|
|
|
+ if (auto desc = peerConnection->remoteDescription())
|
|
|
|
+ return copyAndReturn(desc->typeString(), buffer, size);
|
|
|
|
+ else
|
|
|
|
+ return RTC_ERR_NOT_AVAIL;
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
int rtcGetLocalAddress(int pc, char *buffer, int size) {
|
|
int rtcGetLocalAddress(int pc, char *buffer, int size) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
|
|
|
|
if (auto addr = peerConnection->localAddress())
|
|
if (auto addr = peerConnection->localAddress())
|
|
@@ -867,7 +939,7 @@ int rtcGetLocalAddress(int pc, char *buffer, int size) {
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetRemoteAddress(int pc, char *buffer, int size) {
|
|
int rtcGetRemoteAddress(int pc, char *buffer, int size) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
|
|
|
|
if (auto addr = peerConnection->remoteAddress())
|
|
if (auto addr = peerConnection->remoteAddress())
|
|
@@ -878,7 +950,7 @@ int rtcGetRemoteAddress(int pc, char *buffer, int size) {
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote, int remoteSize) {
|
|
int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote, int remoteSize) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto peerConnection = getPeerConnection(pc);
|
|
auto peerConnection = getPeerConnection(pc);
|
|
|
|
|
|
Candidate localCand;
|
|
Candidate localCand;
|
|
@@ -899,28 +971,28 @@ int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetDataChannelStream(int dc) {
|
|
int rtcGetDataChannelStream(int dc) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([dc] {
|
|
auto dataChannel = getDataChannel(dc);
|
|
auto dataChannel = getDataChannel(dc);
|
|
return int(dataChannel->id());
|
|
return int(dataChannel->id());
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetDataChannelLabel(int dc, char *buffer, int size) {
|
|
int rtcGetDataChannelLabel(int dc, char *buffer, int size) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto dataChannel = getDataChannel(dc);
|
|
auto dataChannel = getDataChannel(dc);
|
|
return copyAndReturn(dataChannel->label(), buffer, size);
|
|
return copyAndReturn(dataChannel->label(), buffer, size);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetDataChannelProtocol(int dc, char *buffer, int size) {
|
|
int rtcGetDataChannelProtocol(int dc, char *buffer, int size) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto dataChannel = getDataChannel(dc);
|
|
auto dataChannel = getDataChannel(dc);
|
|
return copyAndReturn(dataChannel->protocol(), buffer, size);
|
|
return copyAndReturn(dataChannel->protocol(), buffer, size);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetDataChannelReliability(int dc, rtcReliability *reliability) {
|
|
int rtcGetDataChannelReliability(int dc, rtcReliability *reliability) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto dataChannel = getDataChannel(dc);
|
|
auto dataChannel = getDataChannel(dc);
|
|
|
|
|
|
if (!reliability)
|
|
if (!reliability)
|
|
@@ -931,10 +1003,10 @@ int rtcGetDataChannelReliability(int dc, rtcReliability *reliability) {
|
|
reliability->unordered = dcr.unordered;
|
|
reliability->unordered = dcr.unordered;
|
|
if (dcr.type == Reliability::Type::Timed) {
|
|
if (dcr.type == Reliability::Type::Timed) {
|
|
reliability->unreliable = true;
|
|
reliability->unreliable = true;
|
|
- reliability->maxPacketLifeTime = unsigned(std::get<milliseconds>(dcr.rexmit).count());
|
|
|
|
|
|
+ reliability->maxPacketLifeTime = int(std::get<milliseconds>(dcr.rexmit).count());
|
|
} else if (dcr.type == Reliability::Type::Rexmit) {
|
|
} else if (dcr.type == Reliability::Type::Rexmit) {
|
|
reliability->unreliable = true;
|
|
reliability->unreliable = true;
|
|
- reliability->maxRetransmits = unsigned(std::get<int>(dcr.rexmit));
|
|
|
|
|
|
+ reliability->maxRetransmits = std::get<int>(dcr.rexmit);
|
|
} else {
|
|
} else {
|
|
reliability->unreliable = false;
|
|
reliability->unreliable = false;
|
|
}
|
|
}
|
|
@@ -943,7 +1015,7 @@ int rtcGetDataChannelReliability(int dc, rtcReliability *reliability) {
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetOpenCallback(int id, rtcOpenCallbackFunc cb) {
|
|
int rtcSetOpenCallback(int id, rtcOpenCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
if (cb)
|
|
if (cb)
|
|
channel->onOpen([id, cb]() {
|
|
channel->onOpen([id, cb]() {
|
|
@@ -952,11 +1024,12 @@ int rtcSetOpenCallback(int id, rtcOpenCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
channel->onOpen(nullptr);
|
|
channel->onOpen(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetClosedCallback(int id, rtcClosedCallbackFunc cb) {
|
|
int rtcSetClosedCallback(int id, rtcClosedCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
if (cb)
|
|
if (cb)
|
|
channel->onClosed([id, cb]() {
|
|
channel->onClosed([id, cb]() {
|
|
@@ -965,11 +1038,12 @@ int rtcSetClosedCallback(int id, rtcClosedCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
channel->onClosed(nullptr);
|
|
channel->onClosed(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetErrorCallback(int id, rtcErrorCallbackFunc cb) {
|
|
int rtcSetErrorCallback(int id, rtcErrorCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
if (cb)
|
|
if (cb)
|
|
channel->onError([id, cb](string error) {
|
|
channel->onError([id, cb](string error) {
|
|
@@ -978,11 +1052,12 @@ int rtcSetErrorCallback(int id, rtcErrorCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
channel->onError(nullptr);
|
|
channel->onError(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetMessageCallback(int id, rtcMessageCallbackFunc cb) {
|
|
int rtcSetMessageCallback(int id, rtcMessageCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
if (cb)
|
|
if (cb)
|
|
channel->onMessage(
|
|
channel->onMessage(
|
|
@@ -996,11 +1071,12 @@ int rtcSetMessageCallback(int id, rtcMessageCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
channel->onMessage(nullptr);
|
|
channel->onMessage(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSendMessage(int id, const char *data, int size) {
|
|
int rtcSendMessage(int id, const char *data, int size) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
|
|
|
|
if (!data && size != 0)
|
|
if (!data && size != 0)
|
|
@@ -1020,21 +1096,22 @@ int rtcSendMessage(int id, const char *data, int size) {
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetBufferedAmount(int id) {
|
|
int rtcGetBufferedAmount(int id) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([id] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
return int(channel->bufferedAmount());
|
|
return int(channel->bufferedAmount());
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetBufferedAmountLowThreshold(int id, int amount) {
|
|
int rtcSetBufferedAmountLowThreshold(int id, int amount) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
channel->setBufferedAmountLowThreshold(size_t(amount));
|
|
channel->setBufferedAmountLowThreshold(size_t(amount));
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetBufferedAmountLowCallback(int id, rtcBufferedAmountLowCallbackFunc cb) {
|
|
int rtcSetBufferedAmountLowCallback(int id, rtcBufferedAmountLowCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
if (cb)
|
|
if (cb)
|
|
channel->onBufferedAmountLow([id, cb]() {
|
|
channel->onBufferedAmountLow([id, cb]() {
|
|
@@ -1043,15 +1120,16 @@ int rtcSetBufferedAmountLowCallback(int id, rtcBufferedAmountLowCallbackFunc cb)
|
|
});
|
|
});
|
|
else
|
|
else
|
|
channel->onBufferedAmountLow(nullptr);
|
|
channel->onBufferedAmountLow(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcGetAvailableAmount(int id) {
|
|
int rtcGetAvailableAmount(int id) {
|
|
- return WRAP({ return int(getChannel(id)->availableAmount()); });
|
|
|
|
|
|
+ return wrap([id] { return int(getChannel(id)->availableAmount()); });
|
|
}
|
|
}
|
|
|
|
|
|
int rtcSetAvailableCallback(int id, rtcAvailableCallbackFunc cb) {
|
|
int rtcSetAvailableCallback(int id, rtcAvailableCallbackFunc cb) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
if (cb)
|
|
if (cb)
|
|
channel->onAvailable([id, cb]() {
|
|
channel->onAvailable([id, cb]() {
|
|
@@ -1060,11 +1138,12 @@ int rtcSetAvailableCallback(int id, rtcAvailableCallbackFunc cb) {
|
|
});
|
|
});
|
|
else
|
|
else
|
|
channel->onAvailable(nullptr);
|
|
channel->onAvailable(nullptr);
|
|
|
|
+ return RTC_ERR_SUCCESS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int rtcReceiveMessage(int id, char *buffer, int *size) {
|
|
int rtcReceiveMessage(int id, char *buffer, int *size) {
|
|
- return WRAP({
|
|
|
|
|
|
+ return wrap([&] {
|
|
auto channel = getChannel(id);
|
|
auto channel = getChannel(id);
|
|
|
|
|
|
if (!size)
|
|
if (!size)
|