Bläddra i källkod

Added rtcGetLocalDescriptionType() and rtcGetRemoteDescriptionType()

Paul-Louis Ageneau 4 år sedan
förälder
incheckning
9e2e7a7722
3 ändrade filer med 56 tillägg och 7 borttagningar
  1. 4 1
      include/rtc/rtc.h
  2. 22 0
      src/capi.cpp
  3. 30 6
      test/capi_connectivity.cpp

+ 4 - 1
include/rtc/rtc.h

@@ -175,6 +175,9 @@ RTC_EXPORT int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid);
 RTC_EXPORT int rtcGetLocalDescription(int pc, char *buffer, int size);
 RTC_EXPORT int rtcGetRemoteDescription(int pc, char *buffer, int size);
 
+RTC_EXPORT int rtcGetLocalDescriptionType(int pc, char *buffer, int size);
+RTC_EXPORT int rtcGetRemoteDescriptionType(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);
 
@@ -216,7 +219,7 @@ RTC_EXPORT int rtcGetTrackDescription(int tr, char *buffer, int size);
 /// @param _direction Direction
 /// @param _name Name (optional)
 /// @param _msid MSID (optional)
-/// @param _trackID Track ID used in MSID (optional) 
+/// @param _trackID Track ID used in MSID (optional)
 /// @returns Track id
 RTC_EXPORT int rtcAddTrackEx(int pc, rtcCodec codec, int payloadType, uint32_t ssrc, const char *_mid, rtcDirection direction, const char *_name, const char *_msid, const char *_trackID);
 

+ 22 - 0
src/capi.cpp

@@ -895,6 +895,28 @@ 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) {
 	return WRAP({
 		auto peerConnection = getPeerConnection(pc);

+ 30 - 6
test/capi_connectivity.cpp

@@ -235,35 +235,59 @@ int test_capi_connectivity_main() {
 	char buffer[BUFFER_SIZE];
 	char buffer2[BUFFER_SIZE];
 
+	if (rtcGetLocalDescriptionType(peer1->pc, buffer, BUFFER_SIZE) < 0) {
+		fprintf(stderr, "rtcGetLocalDescriptionType failed\n");
+		goto error;
+	}
+	printf("Local description type 1: %s\n", buffer);
+
 	if (rtcGetLocalDescription(peer1->pc, buffer, BUFFER_SIZE) < 0) {
 		fprintf(stderr, "rtcGetLocalDescription failed\n");
 		goto error;
 	}
-	printf("Local description 1:  %s\n", buffer);
+	printf("Local description 1: %s\n", buffer);
+
+	if (rtcGetRemoteDescriptionType(peer1->pc, buffer, BUFFER_SIZE) < 0) {
+		fprintf(stderr, "rtcGetRemoteDescriptionType failed\n");
+		goto error;
+	}
+	printf("Remote description type 1: %s\n", buffer);
 
 	if (rtcGetRemoteDescription(peer1->pc, buffer, BUFFER_SIZE) < 0) {
 		fprintf(stderr, "rtcGetRemoteDescription failed\n");
 		goto error;
 	}
-	printf("Remote description 1:  %s\n", buffer);
+	printf("Remote description 1: %s\n", buffer);
+
+	if (rtcGetLocalDescriptionType(peer2->pc, buffer, BUFFER_SIZE) < 0) {
+		fprintf(stderr, "rtcGetLocalDescriptionType failed\n");
+		goto error;
+	}
+	printf("Local description type 2: %s\n", buffer);
 
 	if (rtcGetLocalDescription(peer2->pc, buffer, BUFFER_SIZE) < 0) {
 		fprintf(stderr, "rtcGetLocalDescription failed\n");
 		goto error;
 	}
-	printf("Local description 2:  %s\n", buffer);
+	printf("Local description 2: %s\n", buffer);
+
+	if (rtcGetRemoteDescriptionType(peer2->pc, buffer, BUFFER_SIZE) < 0) {
+		fprintf(stderr, "rtcGetRemoteDescriptionType failed\n");
+		goto error;
+	}
+	printf("Remote description type 2: %s\n", buffer);
 
 	if (rtcGetRemoteDescription(peer2->pc, buffer, BUFFER_SIZE) < 0) {
 		fprintf(stderr, "rtcGetRemoteDescription failed\n");
 		goto error;
 	}
-	printf("Remote description 2:  %s\n", buffer);
+	printf("Remote description 2: %s\n", buffer);
 
 	if (rtcGetLocalAddress(peer1->pc, buffer, BUFFER_SIZE) < 0) {
 		fprintf(stderr, "rtcGetLocalAddress failed\n");
 		goto error;
 	}
-	printf("Local address 1:  %s\n", buffer);
+	printf("Local address 1: %s\n", buffer);
 
 	if (rtcGetRemoteAddress(peer1->pc, buffer, BUFFER_SIZE) < 0) {
 		fprintf(stderr, "rtcGetRemoteAddress failed\n");
@@ -275,7 +299,7 @@ int test_capi_connectivity_main() {
 		fprintf(stderr, "rtcGetLocalAddress failed\n");
 		goto error;
 	}
-	printf("Local address 2:  %s\n", buffer);
+	printf("Local address 2: %s\n", buffer);
 
 	if (rtcGetRemoteAddress(peer2->pc, buffer, BUFFER_SIZE) < 0) {
 		fprintf(stderr, "rtcGetRemoteAddress failed\n");