Added rtcGetSelectedCandidatePair() to C API

This commit is contained in:
Paul-Louis Ageneau
2020-10-17 23:29:31 +02:00
parent 6d6ab9eeb7
commit e1f60cd34d
3 changed files with 50 additions and 0 deletions

View File

@ -127,6 +127,8 @@ RTC_EXPORT int rtcGetRemoteDescription(int pc, char *buffer, int size);
RTC_EXPORT int rtcGetLocalAddress(int pc, char *buffer, int size); RTC_EXPORT int rtcGetLocalAddress(int pc, char *buffer, int size);
RTC_EXPORT int rtcGetRemoteAddress(int pc, char *buffer, int size); RTC_EXPORT int rtcGetRemoteAddress(int pc, char *buffer, int size);
RTC_EXPORT int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote, int remoteSize);
// DataChannel // DataChannel
RTC_EXPORT int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb); RTC_EXPORT int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb);
RTC_EXPORT int rtcAddDataChannel(int pc, const char *label); // returns dc id RTC_EXPORT int rtcAddDataChannel(int pc, const char *label); // returns dc id

View File

@ -619,6 +619,37 @@ int rtcGetRemoteAddress(int pc, char *buffer, int size) {
}); });
} }
int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote, int remoteSize) {
return WRAP({
auto peerConnection = getPeerConnection(pc);
if (!local)
localSize = 0;
if (!remote)
remoteSize = 0;
Candidate localCand;
Candidate remoteCand;
if (peerConnection->getSelectedCandidatePair(&localCand, &remoteCand)) {
if (localSize > 0) {
string localSdp = string(localCand);
localSize = std::min(localSize - 1, int(localSdp.size()));
std::copy(localSdp.begin(), localSdp.begin() + localSize, local);
local[localSize] = '\0';
}
if (remoteSize > 0) {
string remoteSdp = string(remoteCand);
remoteSize = std::min(remoteSize - 1, int(remoteSdp.size()));
std::copy(remoteSdp.begin(), remoteSdp.begin() + remoteSize, remote);
remote[remoteSize] = '\0';
}
return localSize + remoteSize;
}
return RTC_ERR_FAILURE;
});
}
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);

View File

@ -186,6 +186,7 @@ int test_capi_connectivity_main() {
} }
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
char buffer2[BUFFER_SIZE];
if (rtcGetLocalDescription(peer1->pc, buffer, BUFFER_SIZE) < 0) { if (rtcGetLocalDescription(peer1->pc, buffer, BUFFER_SIZE) < 0) {
fprintf(stderr, "rtcGetLocalDescription failed\n"); fprintf(stderr, "rtcGetLocalDescription failed\n");
@ -235,6 +236,22 @@ int test_capi_connectivity_main() {
} }
printf("Remote address 2: %s\n", buffer); printf("Remote address 2: %s\n", buffer);
if (rtcGetSelectedCandidatePair(peer1->pc, buffer, BUFFER_SIZE, buffer2, BUFFER_SIZE) < 0) {
fprintf(stderr, "rtcGetSelectedCandidatePair failed\n");
goto error;
}
printf("Local candidate 1: %s\n", buffer);
printf("Remote candidate 1: %s\n", buffer2);
if (rtcGetSelectedCandidatePair(peer2->pc, buffer, BUFFER_SIZE, buffer2, BUFFER_SIZE) < 0) {
fprintf(stderr, "rtcGetSelectedCandidatePair failed\n");
goto error;
}
printf("Local candidate 2: %s\n", buffer);
printf("Remote candidate 2: %s\n", buffer2);
deletePeer(peer1); deletePeer(peer1);
sleep(1); sleep(1);
deletePeer(peer2); deletePeer(peer2);