Skip to content

Commit

Permalink
Allow plugins to specify msid in SDPs (#2998)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Aug 1, 2022
1 parent 461c419 commit 1c6d80e
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 28 deletions.
3 changes: 2 additions & 1 deletion conf/janus.plugin.streaming.jcfg.sample.in
Expand Up @@ -155,7 +155,8 @@ rtp-sample: {
# each identifying a single stream to add, that will then translate to
# a dedicated m-line in the SDP. For each stream, you specify the type,
# a unique ID (mid), and can provide a short description (label) so that
# the client side can know what's what when rendering the streams. Notice
# the client side can know what's what when rendering the streams;
# optionally, a msid to add to the SDP m-line can be provided as well. Notice
# how the port/pt/codec/fmtp/etc. stuff is called just like that, without
# any audio/video/data prefix: in fact, each media stream can be configured
# the same way, and it's the type that allows us to differentiate them.
Expand Down
2 changes: 2 additions & 0 deletions html/mvideoroomtest.js
Expand Up @@ -25,6 +25,7 @@ var doSimulcast = (getQueryStringValue("simulcast") === "yes" || getQueryStringV
var acodec = (getQueryStringValue("acodec") !== "" ? getQueryStringValue("acodec") : null);
var vcodec = (getQueryStringValue("vcodec") !== "" ? getQueryStringValue("vcodec") : null);
var subscriber_mode = (getQueryStringValue("subscriber-mode") === "yes" || getQueryStringValue("subscriber-mode") === "true");
var use_msid = (getQueryStringValue("msid") === "yes" || getQueryStringValue("msid") === "true");

$(document).ready(function() {
// Initialize the library (all console debuggers enabled)
Expand Down Expand Up @@ -630,6 +631,7 @@ function subscribeTo(sources) {
room: myroom,
ptype: "subscriber",
streams: subscription,
use_msid: use_msid,
private_id: mypvtid
};
remoteFeed.send({ message: subscribe });
Expand Down
2 changes: 2 additions & 0 deletions html/videoroomtest.js
Expand Up @@ -25,6 +25,7 @@ var acodec = (getQueryStringValue("acodec") !== "" ? getQueryStringValue("acodec
var vcodec = (getQueryStringValue("vcodec") !== "" ? getQueryStringValue("vcodec") : null);
var doDtx = (getQueryStringValue("dtx") === "yes" || getQueryStringValue("dtx") === "true");
var subscriber_mode = (getQueryStringValue("subscriber-mode") === "yes" || getQueryStringValue("subscriber-mode") === "true");
var use_msid = (getQueryStringValue("msid") === "yes" || getQueryStringValue("msid") === "true");

$(document).ready(function() {
// Initialize the library (all console debuggers enabled)
Expand Down Expand Up @@ -550,6 +551,7 @@ function newRemoteFeed(id, display, streams) {
room: myroom,
ptype: "subscriber",
streams: subscription,
use_msid: use_msid,
private_id: mypvtid
};
remoteFeed.send({ message: subscribe });
Expand Down
4 changes: 4 additions & 0 deletions src/ice.c
Expand Up @@ -1829,6 +1829,10 @@ static void janus_ice_peerconnection_medium_dereference(janus_ice_peerconnection
static void janus_ice_peerconnection_medium_free(const janus_refcount *medium_ref) {
janus_ice_peerconnection_medium *medium = janus_refcount_containerof(medium_ref, janus_ice_peerconnection_medium, ref);
g_free(medium->mid);
g_free(medium->msid);
g_free(medium->mstid);
g_free(medium->remote_msid);
g_free(medium->remote_mstid);
g_free(medium->rid[0]);
medium->rid[0] = NULL;
g_free(medium->rid[1]);
Expand Down
2 changes: 2 additions & 0 deletions src/ice.h
Expand Up @@ -512,6 +512,8 @@ struct janus_ice_peerconnection_medium {
int mindex;
/*! \brief Media ID */
char *mid;
/*! \brief Media Stream ID info */
char *msid, *mstid, *remote_msid, *remote_mstid;
/*! \brief SSRC of the server for this medium */
guint32 ssrc;
/*! \brief Retransmission SSRC of the server for this medium */
Expand Down
52 changes: 50 additions & 2 deletions src/janus.c
Expand Up @@ -3213,6 +3213,20 @@ json_t *janus_admin_peerconnection_medium_summary(janus_ice_peerconnection_mediu
json_object_set_new(m, "type", json_string("data"));
json_object_set_new(m, "mindex", json_integer(medium->mindex));
json_object_set_new(m, "mid", json_string(medium->mid));
if(medium->msid || medium->remote_msid) {
json_t *mm = json_object();
if(medium->msid) {
json_object_set_new(mm, "local-stream", json_string(medium->msid));
if(medium->mstid)
json_object_set_new(mm, "local-track", json_string(medium->mstid));
}
if(medium->remote_msid) {
json_object_set_new(mm, "remote-stream", json_string(medium->remote_msid));
if(medium->remote_mstid)
json_object_set_new(mm, "remote-track", json_string(medium->remote_mstid));
}
json_object_set_new(m, "msid", mm);
}
if(medium->type != JANUS_MEDIA_DATA) {
json_object_set_new(m, "do_nacks", medium->do_nacks ? json_true() : json_false());
json_object_set_new(m, "nack-queue-ms", json_integer(medium->nack_queue_ms));
Expand Down Expand Up @@ -3799,12 +3813,40 @@ json_t *janus_plugin_handle_sdp(janus_plugin_session *plugin_session, janus_plug
janus_ice_peerconnection_medium *medium = ice_handle->pc ?
g_hash_table_lookup(ice_handle->pc->media, GUINT_TO_POINTER(mindex)) : NULL;
gboolean have_mid = FALSE, have_rid = FALSE, have_repaired_rid = FALSE,
have_twcc = FALSE, have_dd = FALSE, have_abs_send_time = FALSE;
have_twcc = FALSE, have_dd = FALSE, have_abs_send_time = FALSE, have_msid = FALSE;
int opusred_pt = -1;
GList *tempA = m->attributes;
while(tempA) {
janus_sdp_attribute *a = (janus_sdp_attribute *)tempA->data;
if(a->name && a->value && !strcasecmp(a->name, "extmap")) {
if(a->name && a->value && !strcasecmp(a->name, "msid")) {
/* Found msid attribute */
have_msid = TRUE;
char msid[65], mstid[65];
msid[0] = '\0';
mstid[0] = '\0';
if(sscanf(a->value, "%64s %64s", msid, mstid) != 2) {
JANUS_LOG(LOG_ERR, "[%"SCNu64"] Invalid msid on m-line #%d\n",
ice_handle->handle_id, m->index);
janus_sdp_destroy(parsed_sdp);
return NULL;
}
if(medium->msid == NULL || strcasecmp(medium->msid, msid)) {
char *old_msid = medium->msid;
medium->msid = g_strdup(msid);
g_free(old_msid);
}
if(medium->mstid == NULL || strcasecmp(medium->mstid, mstid)) {
char *old_mstid = medium->mstid;
medium->mstid = g_strdup(mstid);
g_free(old_mstid);
}
/* Remove this msid attribute, the core will add it again later */
GList *msid_attr = tempA;
tempA = tempA->next;
m->attributes = g_list_remove_link(m->attributes, msid_attr);
g_list_free_full(msid_attr, (GDestroyNotify)janus_sdp_attribute_destroy);
continue;
} else if(a->name && a->value && !strcasecmp(a->name, "extmap")) {
if(strstr(a->value, JANUS_RTP_EXTMAP_MID))
have_mid = TRUE;
else if(strstr(a->value, JANUS_RTP_EXTMAP_RID))
Expand All @@ -3826,6 +3868,12 @@ json_t *janus_plugin_handle_sdp(janus_plugin_session *plugin_session, janus_plug
/* If the user offered RED but the plugin rejected it, disable it */
if(opusred_pt < 0 && medium != NULL && medium->opusred_pt > 0)
medium->opusred_pt = 0;
if(!have_msid) {
g_free(medium->msid);
medium->msid = NULL;
g_free(medium->mstid);
medium->mstid = NULL;
}
/* Check if rid-based simulcasting is available */
if(!have_rid && medium != NULL) {
g_free(medium->rid[0]);
Expand Down

0 comments on commit 1c6d80e

Please sign in to comment.