Sfoglia il codice sorgente

Merge pull request #205 from hanseuljun/rtcgetlocaldescriptionsdp

Add rtcGetLocalDescriptionSdp() as a C API
Paul-Louis Ageneau 4 anni fa
parent
commit
46878519c0
2 ha cambiato i file con 25 aggiunte e 0 eliminazioni
  1. 2 0
      include/rtc/rtc.h
  2. 23 0
      src/capi.cpp

+ 2 - 0
include/rtc/rtc.h

@@ -121,6 +121,8 @@ RTC_EXPORT int rtcSetLocalDescription(int pc);
 RTC_EXPORT int rtcSetRemoteDescription(int pc, const char *sdp, const char *type);
 RTC_EXPORT int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid);
 
+RTC_EXPORT int rtcGetLocalDescriptionSdp(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);
 

+ 23 - 0
src/capi.cpp

@@ -529,6 +529,29 @@ int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid) {
 	});
 }
 
+int rtcGetLocalDescriptionSdp(int pc, char *buffer, int size) {
+	return WRAP({
+		auto peerConnection = getPeerConnection(pc);
+
+		if (size <= 0)
+			return 0;
+
+		if (!buffer)
+			throw std::invalid_argument("Unexpected null pointer for buffer");
+
+		if (auto desc = peerConnection->localDescription()) {
+			auto sdp = string(*desc);
+			const char *data = sdp.data();
+			size = std::min(size - 1, int(sdp.size()));
+			std::copy(data, data + size, buffer);
+			buffer[size] = '\0';
+			return size + 1;
+		}
+
+		return RTC_ERR_FAILURE;
+	});
+}
+
 int rtcGetLocalAddress(int pc, char *buffer, int size) {
 	return WRAP({
 		auto peerConnection = getPeerConnection(pc);