Browse Source

Merge branch 'v0.16'

Paul-Louis Ageneau 3 years ago
parent
commit
fae0f7a2bb
5 changed files with 126 additions and 11 deletions
  1. 35 2
      DOC.md
  2. 2 0
      include/rtc/rtc.h
  3. 35 2
      pages/content/pages/reference.md
  4. 18 0
      src/capi.cpp
  5. 36 7
      test/capi_track.cpp

+ 35 - 2
DOC.md

@@ -701,7 +701,7 @@ Retrieves the SDP media description of a Track.
 
 Arguments:
 
-- `dc`: the Track identifier
+- `tr`: the Track identifier
 - `buffer`: a user-supplied buffer to store the description
 - `size`: the size of `buffer`
 
@@ -709,7 +709,40 @@ Return value: the length of the string copied in buffer (including the terminati
 
 If `buffer` is `NULL`, the description is not copied but the size is still returned.
 
-### Media
+#### rtcGetTrackMid
+
+```
+int rtcGetTrackMid(int tr, char *buffer, int size)
+```
+
+Retrieves the mid (media indentifier) of a Track.
+
+Arguments:
+
+- `tr`: the Track identifier
+- `buffer`: a user-supplied buffer to store the mid
+- `size`: the size of `buffer`
+
+Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
+
+If `buffer` is `NULL`, the mid is not copied but the size is still returned.
+
+#### rtcGetTrackDirection
+
+```
+int rtcGetTrackDirection(int tr, rtcDirection *direction)
+```
+
+Retrieves the direction of a Track.
+
+Arguments:
+
+- `tr`: the Track identifier
+- `direction`: a pointer to a rtcDescription enum to store the result
+
+On success, the value pointed by `direction` will be set to one of the following: `RTC_DIRECTION_SENDONLY`, `RTC_DIRECTION_RECVONLY`, `RTC_DIRECTION_SENDRECV`, `RTC_DIRECTION_INACTIVE`, or `RTC_DIRECTION_UNKNOWN`.
+
+### Media handling
 
 TODO
 

+ 2 - 0
include/rtc/rtc.h

@@ -257,6 +257,8 @@ RTC_EXPORT int rtcAddTrackEx(int pc, const rtcTrackInit *init);      // returns
 RTC_EXPORT int rtcDeleteTrack(int tr);
 
 RTC_EXPORT int rtcGetTrackDescription(int tr, char *buffer, int size);
+RTC_EXPORT int rtcGetTrackMid(int tr, char *buffer, int size);
+RTC_EXPORT int rtcGetTrackDirection(int tr, rtcDirection *direction);
 
 #if RTC_ENABLE_MEDIA
 

+ 35 - 2
pages/content/pages/reference.md

@@ -704,7 +704,7 @@ Retrieves the SDP media description of a Track.
 
 Arguments:
 
-- `dc`: the Track identifier
+- `tr`: the Track identifier
 - `buffer`: a user-supplied buffer to store the description
 - `size`: the size of `buffer`
 
@@ -712,7 +712,40 @@ Return value: the length of the string copied in buffer (including the terminati
 
 If `buffer` is `NULL`, the description is not copied but the size is still returned.
 
-### Media
+#### rtcGetTrackMid
+
+```
+int rtcGetTrackMid(int tr, char *buffer, int size)
+```
+
+Retrieves the mid (media indentifier) of a Track.
+
+Arguments:
+
+- `tr`: the Track identifier
+- `buffer`: a user-supplied buffer to store the mid
+- `size`: the size of `buffer`
+
+Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
+
+If `buffer` is `NULL`, the mid is not copied but the size is still returned.
+
+#### rtcGetTrackDirection
+
+```
+int rtcGetTrackDirection(int tr, rtcDirection *direction)
+```
+
+Retrieves the direction of a Track.
+
+Arguments:
+
+- `tr`: the Track identifier
+- `direction`: a pointer to a rtcDescription enum to store the result
+
+On success, the value pointed by `direction` will be set to one of the following: `RTC_DIRECTION_SENDONLY`, `RTC_DIRECTION_RECVONLY`, `RTC_DIRECTION_SENDRECV`, `RTC_DIRECTION_INACTIVE`, or `RTC_DIRECTION_UNKNOWN`.
+
+### Media handling
 
 TODO
 

+ 18 - 0
src/capi.cpp

@@ -1003,6 +1003,24 @@ int rtcGetTrackDescription(int tr, char *buffer, int size) {
 	});
 }
 
+int rtcGetTrackMid(int tr, char *buffer, int size) {
+	return wrap([&] {
+		auto track = getTrack(tr);
+		return copyAndReturn(track->mid(), buffer, size);
+	});
+}
+
+int rtcGetTrackDirection(int tr, rtcDirection *direction) {
+	return wrap([&] {
+		if (!direction)
+			throw std::invalid_argument("Unexpected null pointer for track direction");
+
+		auto track = getTrack(tr);
+		*direction = static_cast<rtcDirection>(track->direction());
+		return RTC_ERR_SUCCESS;
+	});
+}
+
 #if RTC_ENABLE_MEDIA
 
 void setSSRC(Description::Media *description, uint32_t ssrc, const char *_name, const char *_msid,

+ 36 - 7
test/capi_track.cpp

@@ -41,7 +41,8 @@ static Peer *peer1 = NULL;
 static Peer *peer2 = NULL;
 
 static const char *mediaDescription = "video 9 UDP/TLS/RTP/SAVPF\r\n"
-                                      "a=mid:video\r\n";
+                                      "a=mid:video\r\n"
+                                      "a=sendonly\r\n";
 
 static void RTC_API descriptionCallback(int pc, const char *sdp, const char *type, void *ptr) {
 	Peer *peer = (Peer *)ptr;
@@ -83,15 +84,31 @@ static void RTC_API closedCallback(int id, void *ptr) {
 
 static void RTC_API trackCallback(int pc, int tr, void *ptr) {
 	Peer *peer = (Peer *)ptr;
-	peer->tr = tr;
-	rtcSetOpenCallback(tr, openCallback);
-	rtcSetClosedCallback(tr, closedCallback);
 
 	char buffer[1024];
-	if (rtcGetTrackDescription(tr, buffer, 1024) >= 0)
-		printf("Track %d: Received with media description: \n%s\n", peer == peer1 ? 1 : 2, buffer);
-	else
+	if (rtcGetTrackDescription(tr, buffer, 1024) < 0) {
 		fprintf(stderr, "rtcGetTrackDescription failed\n");
+		return;
+	}
+
+	printf("Track %d: Received with media description: \n%s\n", peer == peer1 ? 1 : 2, buffer);
+
+	char mid[256];
+	if (rtcGetTrackMid(tr, mid, 256) < 0 || strcmp(mid, "video") != 0) {
+		fprintf(stderr, "rtcGetTrackMid failed\n");
+		return;
+	}
+
+	// Description is reversed here
+	rtcDirection direction;
+	if (rtcGetTrackDirection(tr, &direction) < 0 || direction != RTC_DIRECTION_RECVONLY) {
+		fprintf(stderr, "rtcGetTrackDirection failed\n");
+		return;
+	}
+
+	peer->tr = tr;
+	rtcSetOpenCallback(tr, openCallback);
+	rtcSetClosedCallback(tr, closedCallback);
 }
 
 static Peer *createPeer(const rtcConfiguration *config) {
@@ -168,6 +185,18 @@ int test_capi_track_main() {
 	rtcSetOpenCallback(peer1->tr, openCallback);
 	rtcSetClosedCallback(peer1->tr, closedCallback);
 
+	char mid[256];
+	if (rtcGetTrackMid(peer1->tr, mid, 256) < 0 || strcmp(mid, "video") != 0) {
+		fprintf(stderr, "rtcGetTrackMid failed\n");
+		goto error;
+	}
+
+	rtcDirection direction;
+	if (rtcGetTrackDirection(peer1->tr, &direction) < 0 || direction != RTC_DIRECTION_SENDONLY) {
+		fprintf(stderr, "rtcGetTrackDirection failed\n");
+		goto error;
+	}
+
 	// Initiate the handshake
 	rtcSetLocalDescription(peer1->pc, NULL);