Browse Source

Merge pull request #610 from paullouisageneau/capi-get-max-stream

Add rtcGetMaxDataChannelStream() to C API
Paul-Louis Ageneau 3 years ago
parent
commit
1c7c02d26b
5 changed files with 40 additions and 2 deletions
  1. 13 1
      DOC.md
  2. 2 0
      include/rtc/rtc.h
  3. 13 1
      pages/content/pages/reference.md
  4. 7 0
      src/capi.cpp
  5. 5 0
      test/capi_connectivity.cpp

+ 13 - 1
DOC.md

@@ -339,7 +339,7 @@ If `buffer` is `NULL`, the address is not copied but the size is still returned.
 int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote, int remoteSize)
 ```
 
-Retrieve the currently selected candidate pair. The call may fail if the state is not `RTC_CONNECTED`, and the selected candidate pair might change if the state is not `RTC_COMPLETED`.
+Retrieves the currently selected candidate pair. The call may fail if the state is not `RTC_CONNECTED`, and the selected candidate pair might change if the state is not `RTC_COMPLETED`.
 
 Arguments:
 
@@ -353,6 +353,18 @@ Return value: the maximun length of strings copied in buffers (including the ter
 
 If `local`, `remote`, or both, are `NULL`, the corresponding candidate is not copied, but the maximum length is still returned.
 
+#### rtcGetMaxDataChannelStream
+```
+int rtcGetMaxDataChannelStream(int pc);
+```
+
+Retrieves the maximum stream ID a Data Channel may use. It is useful to create user-negotiated Data Channels with `negotiated=true` and `manualStream=true`. The maximum is negotiated during connection, therefore the final value after connection might be lower than before connection if the remote maximum is lower.
+
+Arguments:
+- `pc`: the Peer Connection identifier
+
+Return value: the maximum stream ID (`stream` for a Data Channel may be set from 0 to this value included) or a negative error code
+
 ### Channel (Common API for Data Channel, Track, and WebSocket)
 
 The following common functions might be called with a generic channel identifier. It may be the identifier of either a Data Channel, a Track, or a WebSocket.

+ 2 - 0
include/rtc/rtc.h

@@ -190,6 +190,8 @@ RTC_EXPORT int rtcGetRemoteAddress(int pc, char *buffer, int size);
 RTC_EXPORT int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote,
                                            int remoteSize);
 
+RTC_EXPORT int rtcGetMaxDataChannelStream(int pc);
+
 // DataChannel, Track, and WebSocket common API
 
 RTC_EXPORT int rtcSetOpenCallback(int id, rtcOpenCallbackFunc cb);

+ 13 - 1
pages/content/pages/reference.md

@@ -343,7 +343,7 @@ If `buffer` is `NULL`, the address is not copied but the size is still returned.
 int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote, int remoteSize)
 ```
 
-Retrieve the currently selected candidate pair. The call may fail if the state is not `RTC_CONNECTED`, and the selected candidate pair might change if the state is not `RTC_COMPLETED`.
+Retrieves the currently selected candidate pair. The call may fail if the state is not `RTC_CONNECTED`, and the selected candidate pair might change if the state is not `RTC_COMPLETED`.
 
 Arguments:
 
@@ -357,6 +357,18 @@ Return value: the maximun length of strings copied in buffers (including the ter
 
 If `local`, `remote`, or both, are `NULL`, the corresponding candidate is not copied, but the maximum length is still returned.
 
+#### rtcGetMaxDataChannelStream
+```
+int rtcGetMaxDataChannelStream(int pc);
+```
+
+Retrieves the maximum stream ID a Data Channel may use. It is useful to create user-negotiated Data Channels with `negotiated=true` and `manualStream=true`. The maximum is negotiated during connection, therefore the final value after connection might be lower than before connection if the remote maximum is lower.
+
+Arguments:
+- `pc`: the Peer Connection identifier
+
+Return value: the maximum stream ID (`stream` for a Data Channel may be set from 0 to this value included) or a negative error code
+
 ### Channel (Common API for Data Channel, Track, and WebSocket)
 
 The following common functions might be called with a generic channel identifier. It may be the identifier of either a Data Channel, a Track, or a WebSocket.

+ 7 - 0
src/capi.cpp

@@ -614,6 +614,13 @@ int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, char *remote
 	});
 }
 
+int rtcGetMaxDataChannelStream(int pc) {
+	return wrap([&] {
+		auto peerConnection = getPeerConnection(pc);
+		return int(peerConnection->maxDataChannelId());
+	});
+}
+
 int rtcSetOpenCallback(int id, rtcOpenCallbackFunc cb) {
 	return wrap([&] {
 		auto channel = getChannel(id);

+ 5 - 0
test/capi_connectivity.cpp

@@ -346,6 +346,11 @@ int test_capi_connectivity_main() {
 	printf("Local candidate 2:  %s\n", buffer);
 	printf("Remote candidate 2: %s\n", buffer2);
 
+	if (rtcGetMaxDataChannelStream(peer1->pc) <= 0 || rtcGetMaxDataChannelStream(peer2->pc) <= 0) {
+		fprintf(stderr, "rtcGetMaxDataChannelStream failed\n");
+		goto error;
+	}
+
 	deletePeer(peer1);
 	sleep(1);
 	deletePeer(peer2);