[Asterisk-code-review] res pjsip sdp rtp: Save track label to stream opaque data (asterisk[15])
George Joseph
asteriskteam at digium.com
Thu Apr 12 11:48:05 CDT 2018
George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/8772
Change subject: res_pjsip_sdp_rtp: Save track label to stream opaque data
......................................................................
res_pjsip_sdp_rtp: Save track label to stream opaque data
Save the track label to the stream so it can be used as a correlation
id on events to a client.
Also added a unit test for stream opaque data.
Change-Id: I48ab35c5e72f5ee53fa06cf9a5af5a88a1e3b1c9
---
M include/asterisk/stream.h
M res/res_pjsip_sdp_rtp.c
M tests/test_stream.c
3 files changed, 65 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/72/8772/1
diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h
index bbde73d..13f8d71 100644
--- a/include/asterisk/stream.h
+++ b/include/asterisk/stream.h
@@ -86,6 +86,10 @@
*/
AST_STREAM_DATA_RTP_CODECS = 0,
/*!
+ * \brief Data slot for the track label part of the msid
+ */
+ AST_STREAM_DATA_TRACK_LABEL,
+ /*!
* \brief Controls the size of the data pointer array
*/
AST_STREAM_DATA_SLOT_MAX
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index 11ab726..bc6218d 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -1050,6 +1050,7 @@
pj_str_t stmp;
pjmedia_sdp_attr *attr;
char msid[(AST_UUID_STR_LEN * 2) + 2];
+ char *track_label;
if (!session->endpoint->media.webrtc) {
return;
@@ -1075,6 +1076,21 @@
snprintf(msid, sizeof(msid), "%s %s", session_media->mslabel, session_media->label);
attr = pjmedia_sdp_attr_create(pool, "msid", pj_cstr(&stmp, msid));
pjmedia_sdp_attr_add(&media->attr_count, media->attr, attr);
+
+ /*
+ * Get the stream's current track label, if any.
+ * If it's not there or it doesn't match the current label,
+ * reset it.
+ */
+ track_label = ast_stream_get_data(stream, AST_STREAM_DATA_TRACK_LABEL);
+ if (!track_label || strcmp(track_label, session_media->label) != 0) {
+ ast_free(track_label);
+ track_label = ast_strdup(session_media->label);
+ if (!track_label) {
+ return;
+ }
+ ast_stream_set_data(stream, AST_STREAM_DATA_TRACK_LABEL, track_label, ast_free_ptr);
+ }
}
static void add_rtcp_fb_to_stream(struct ast_sip_session *session,
diff --git a/tests/test_stream.c b/tests/test_stream.c
index 8c88704..9c2b15d 100644
--- a/tests/test_stream.c
+++ b/tests/test_stream.c
@@ -38,6 +38,7 @@
#include "asterisk/format_cap.h"
#include "asterisk/format_cache.h"
#include "asterisk/channel.h"
+#include "asterisk/uuid.h"
AST_TEST_DEFINE(stream_create)
{
@@ -218,6 +219,48 @@
if (ast_stream_get_state(stream) != AST_STREAM_STATE_SENDRECV) {
ast_test_status_update(test, "Changed stream does not have expected sendrecv state\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(stream_set_data)
+{
+ RAII_VAR(struct ast_stream *, stream, NULL, ast_stream_free);
+ char track_label[AST_UUID_STR_LEN + 1];
+ const char *stream_track_label;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "stream_set_data";
+ info->category = "/main/stream/";
+ info->summary = "stream data setting unit test";
+ info->description =
+ "Test that changing the opaque data of a stream works";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ stream = ast_stream_alloc("test", AST_MEDIA_TYPE_AUDIO);
+ if (!stream) {
+ ast_test_status_update(test, "Failed to create media stream given proper arguments\n");
+ return AST_TEST_FAIL;
+ }
+
+ ast_uuid_generate_str(track_label, sizeof(track_label));
+
+ ast_stream_set_data(stream, AST_STREAM_DATA_TRACK_LABEL, track_label, ast_free_ptr);
+
+ stream_track_label = ast_stream_get_data(stream, AST_STREAM_DATA_TRACK_LABEL);
+ if (!stream_track_label) {
+ ast_test_status_update(test, "Changed stream does not have a track label\n");
+ return AST_TEST_FAIL;
+ }
+
+ if (strcmp(stream_track_label, track_label) != 0) {
+ ast_test_status_update(test, "Changed stream did not return same track label\n");
return AST_TEST_FAIL;
}
@@ -2139,6 +2182,7 @@
AST_TEST_UNREGISTER(stream_set_type);
AST_TEST_UNREGISTER(stream_set_formats);
AST_TEST_UNREGISTER(stream_set_state);
+ AST_TEST_UNREGISTER(stream_set_data);
AST_TEST_UNREGISTER(stream_topology_create);
AST_TEST_UNREGISTER(stream_topology_clone);
AST_TEST_UNREGISTER(stream_topology_clone);
@@ -2169,6 +2213,7 @@
AST_TEST_REGISTER(stream_set_type);
AST_TEST_REGISTER(stream_set_formats);
AST_TEST_REGISTER(stream_set_state);
+ AST_TEST_REGISTER(stream_set_data);
AST_TEST_REGISTER(stream_topology_create);
AST_TEST_REGISTER(stream_topology_clone);
AST_TEST_REGISTER(stream_topology_append_stream);
--
To view, visit https://gerrit.asterisk.org/8772
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I48ab35c5e72f5ee53fa06cf9a5af5a88a1e3b1c9
Gerrit-Change-Number: 8772
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180412/db18ef32/attachment.html>
More information about the asterisk-code-review
mailing list