[Pkg-voip-commits] [janus] 50/163: Added ability for VideoRoom listeners to not negotiate support for media the publishers are sending
Jonas Smedegaard
dr at jones.dk
Sat Oct 28 01:22:09 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/0.2.5-1
in repository janus.
commit a9b6dcee5ae19ffe8502231d9b72877f34ce9099
Author: Lorenzo Miniero <lminiero at gmail.com>
Date: Mon Jul 31 19:05:33 2017 +0200
Added ability for VideoRoom listeners to not negotiate support for media the publishers are sending
---
html/videoroomtest.js | 10 +++++--
plugins/janus_videoroom.c | 74 +++++++++++++++++++++++++++++++++++++----------
sdp-utils.c | 18 ++++++++++++
sdp-utils.h | 8 +++++
4 files changed, 92 insertions(+), 18 deletions(-)
diff --git a/html/videoroomtest.js b/html/videoroomtest.js
index d14c15f..8b5ad08 100644
--- a/html/videoroomtest.js
+++ b/html/videoroomtest.js
@@ -423,6 +423,10 @@ function newRemoteFeed(id, display) {
Janus.log(" -- This is a subscriber");
// We wait for the plugin to send us an offer
var listen = { "request": "join", "room": myroom, "ptype": "listener", "feed": id, "private_id": mypvtid };
+ // In case you don't want to receive audio, video or data, even if the
+ // publisher is sending them, set the 'offer_audio', 'offer_video' or
+ // 'offer_data' properties to false (they're true by default), e.g.:
+ // listen["offer_video"] = false;
remoteFeed.send({"message": listen});
},
error: function(error) {
@@ -434,7 +438,9 @@ function newRemoteFeed(id, display) {
Janus.debug(JSON.stringify(msg));
var event = msg["videoroom"];
Janus.debug("Event: " + event);
- if(event != undefined && event != null) {
+ if(msg["error"] !== undefined && msg["error"] !== null) {
+ bootbox.alert(msg["error"]);
+ } else if(event != undefined && event != null) {
if(event === "attached") {
// Subscriber created and attached
for(var i=1;i<6;i++) {
@@ -467,8 +473,6 @@ function newRemoteFeed(id, display) {
// We just received notice that there's been a switch, update the buttons
updateSimulcastButtons(remoteFeed.rfindex, substream, temporal);
}
- } else if(msg["error"] !== undefined && msg["error"] !== null) {
- bootbox.alert(msg["error"]);
} else {
// What has just happened?
}
diff --git a/plugins/janus_videoroom.c b/plugins/janus_videoroom.c
index f5d93b5..3495cb9 100644
--- a/plugins/janus_videoroom.c
+++ b/plugins/janus_videoroom.c
@@ -321,7 +321,10 @@ static struct janus_json_parameter listener_parameters[] = {
{"private_id", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"audio", JANUS_JSON_BOOL, 0},
{"video", JANUS_JSON_BOOL, 0},
- {"data", JANUS_JSON_BOOL, 0}
+ {"data", JANUS_JSON_BOOL, 0},
+ {"offer_audio", JANUS_JSON_BOOL, 0},
+ {"offer_video", JANUS_JSON_BOOL, 0},
+ {"offer_data", JANUS_JSON_BOOL, 0}
};
/* Static configuration instance */
@@ -582,7 +585,9 @@ typedef struct janus_videoroom_listener {
int templayer_target; /* As above, but to handle transitions (e.g., wait for keyframe) */
gint64 last_relayed; /* When we relayed the last packet (used to detect when substreams become unavailable) */
janus_vp8_simulcast_context simulcast_context;
- gboolean audio, video, data; /* Whether audio, video and/or data must be sent to this publisher */
+ gboolean audio, video, data; /* Whether audio, video and/or data must be sent to this listener */
+ /* As above, but can't change dynamically (says whether something was negotiated at all in SDP) */
+ gboolean audio_offered, video_offered, data_offered;
gboolean paused;
gboolean kicked; /* Whether this subscription belongs to a participant that has been kicked */
/* The following are only relevant if we're doing VP9 SVC, and are not to be confused with VP8
@@ -1229,9 +1234,9 @@ json_t *janus_videoroom_query_session(janus_plugin_session *handle) {
json_object_set_new(info, "feed_display", json_string(feed->display));
}
json_t *media = json_object();
- json_object_set_new(media, "audio", json_integer(participant->audio));
- json_object_set_new(media, "video", json_integer(participant->video));
- json_object_set_new(media, "data", json_integer(participant->data));
+ json_object_set_new(media, "audio", json_integer(participant->audio_offered));
+ json_object_set_new(media, "video", json_integer(participant->video_offered));
+ json_object_set_new(media, "data", json_integer(participant->data_offered));
if(feed->ssrc[0] != 0) {
json_object_set_new(info, "simulcast", json_true());
json_object_set_new(info, "substream", json_integer(participant->substream));
@@ -3219,6 +3224,9 @@ static void *janus_videoroom_handler(void *data) {
json_t *audio = json_object_get(root, "audio");
json_t *video = json_object_get(root, "video");
json_t *data = json_object_get(root, "data");
+ json_t *offer_audio = json_object_get(root, "offer_audio");
+ json_t *offer_video = json_object_get(root, "offer_video");
+ json_t *offer_data = json_object_get(root, "offer_data");
janus_mutex_lock(&videoroom->participants_mutex);
janus_videoroom_participant *owner = NULL;
janus_videoroom_participant *publisher = g_hash_table_lookup(videoroom->participants, &feed_id);
@@ -3247,15 +3255,33 @@ static void *janus_videoroom_handler(void *data) {
listener->pvt_id = pvt_id;
/* Initialize the listener context */
janus_rtp_switching_context_reset(&listener->context);
- listener->audio = audio ? json_is_true(audio) : TRUE; /* True by default */
+ listener->audio_offered = offer_audio ? json_is_true(offer_audio) : TRUE; /* True by default */
if(!publisher->audio)
- listener->audio = FALSE; /* ... unless the publisher isn't sending any audio */
- listener->video = video ? json_is_true(video) : TRUE; /* True by default */
+ listener->audio_offered = FALSE; /* ... unless the publisher isn't sending any audio */
+ listener->video_offered = offer_video ? json_is_true(offer_video) : TRUE; /* True by default */
if(!publisher->video)
- listener->video = FALSE; /* ... unless the publisher isn't sending any video */
- listener->data = data ? json_is_true(data) : TRUE; /* True by default */
+ listener->video_offered = FALSE; /* ... unless the publisher isn't sending any video */
+ listener->data_offered = offer_data ? json_is_true(offer_data) : TRUE; /* True by default */
if(!publisher->data)
- listener->data = FALSE; /* ... unless the publisher isn't sending any data */
+ listener->data_offered = FALSE; /* ... unless the publisher isn't sending any data */
+ if((!publisher->audio || !listener->audio_offered) &&
+ (!publisher->video || !listener->video_offered) &&
+ (!publisher->data || !listener->data_offered)) {
+ g_free(listener);
+ JANUS_LOG(LOG_ERR, "Can't offer an SDP with no audio, video or data\n");
+ error_code = JANUS_VIDEOROOM_ERROR_INVALID_SDP;
+ g_snprintf(error_cause, 512, "Can't offer an SDP with no audio, video or data");
+ goto error;
+ }
+ listener->audio = audio ? json_is_true(audio) : TRUE; /* True by default */
+ if(!publisher->audio || !listener->audio_offered)
+ listener->audio = FALSE; /* ... unless the publisher isn't sending any audio or we're skipping it */
+ listener->video = video ? json_is_true(video) : TRUE; /* True by default */
+ if(!publisher->video || !listener->video_offered)
+ listener->video = FALSE; /* ... unless the publisher isn't sending any video or we're skipping it */
+ listener->data = data ? json_is_true(data) : TRUE; /* True by default */
+ if(!publisher->data || !listener->data_offered)
+ listener->data = FALSE; /* ... unless the publisher isn't sending any data or we're skipping it */
listener->paused = TRUE; /* We need an explicit start from the listener */
listener->substream = -1;
listener->substream_target = 2;
@@ -3290,7 +3316,25 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_VERB, "Preparing JSON event as a reply\n");
/* Negotiate by sending the selected publisher SDP back */
if(publisher->sdp != NULL) {
- json_t *jsep = json_pack("{ssss}", "type", "offer", "sdp", publisher->sdp);
+ /* Check if there's something the original SDP has that we should remove */
+ char *sdp = publisher->sdp;
+ if((publisher->audio && !listener->audio_offered) ||
+ (publisher->video && !listener->video_offered) ||
+ (publisher->data && !listener->data_offered)) {
+ JANUS_LOG(LOG_VERB, "Munging SDP offer to adapt it to the listener's requirements\n");
+ janus_sdp *offer = janus_sdp_parse(publisher->sdp, NULL, 0);
+ if(publisher->audio && !listener->audio_offered)
+ janus_sdp_mline_remove(offer, JANUS_SDP_AUDIO);
+ if(publisher->video && !listener->video_offered)
+ janus_sdp_mline_remove(offer, JANUS_SDP_VIDEO);
+ if(publisher->data && !listener->data_offered)
+ janus_sdp_mline_remove(offer, JANUS_SDP_APPLICATION);
+ sdp = janus_sdp_write(offer);
+ janus_sdp_free(offer);
+ }
+ json_t *jsep = json_pack("{ssss}", "type", "offer", "sdp", sdp);
+ if(sdp != publisher->sdp)
+ g_free(sdp);
/* How long will the gateway take to push the event? */
g_atomic_int_set(&session->hangingup, 0);
gint64 start = janus_get_monotonic_time();
@@ -3579,11 +3623,11 @@ static void *janus_videoroom_handler(void *data) {
/* Update the audio/video/data flags, if set */
janus_videoroom_participant *publisher = listener->feed;
if(publisher) {
- if(audio && publisher->audio)
+ if(audio && publisher->audio && listener->audio_offered)
listener->audio = json_is_true(audio);
- if(video && publisher->video)
+ if(video && publisher->video && listener->video_offered)
listener->video = json_is_true(video);
- if(data && publisher->data)
+ if(data && publisher->data && listener->data_offered)
listener->data = json_is_true(data);
/* Check if a simulcasting-related request is involved */
if(sc_substream && publisher->ssrc[0] != 0) {
diff --git a/sdp-utils.c b/sdp-utils.c
index 6d61613..5c853ca 100644
--- a/sdp-utils.c
+++ b/sdp-utils.c
@@ -95,6 +95,24 @@ janus_sdp_mline *janus_sdp_mline_find(janus_sdp *sdp, janus_sdp_mtype type) {
return NULL;
}
+int janus_sdp_mline_remove(janus_sdp *sdp, janus_sdp_mtype type) {
+ if(sdp == NULL)
+ return -1;
+ GList *ml = sdp->m_lines;
+ while(ml) {
+ janus_sdp_mline *m = (janus_sdp_mline *)ml->data;
+ if(m->type == type) {
+ /* Found! */
+ sdp->m_lines = g_list_remove(sdp->m_lines, m);
+ janus_sdp_mline_destroy(m);
+ return 0;
+ }
+ ml = ml->next;
+ }
+ /* If we got here, we couldn't the m-line */
+ return -2;
+}
+
janus_sdp_attribute *janus_sdp_attribute_create(const char *name, const char *value, ...) {
if(!name)
return NULL;
diff --git a/sdp-utils.h b/sdp-utils.h
index d8303d1..ba21c7b 100644
--- a/sdp-utils.h
+++ b/sdp-utils.h
@@ -142,6 +142,14 @@ void janus_sdp_mline_destroy(janus_sdp_mline *mline);
* @param[in] type The type of media to search
* @returns The janus_sdp_mline instance, if found, or NULL otherwise */
janus_sdp_mline *janus_sdp_mline_find(janus_sdp *sdp, janus_sdp_mtype type);
+/*! \brief Helper method to remove the janus_sdp_mline associated to a media type from the SDP
+ * @note This currently removes the first m-line of the specified type it finds: in
+ * general, it shouldn't be an issue as we currently only support a single stream
+ * of the same type per session anyway... this will need to be fixed in the future.
+ * @param[in] sdp The Janus SDP object to modify
+ * @param[in] type The type of media to remove
+ * @returns 0 if successful, a negative integer otherwise */
+int janus_sdp_mline_remove(janus_sdp *sdp, janus_sdp_mtype type);
/*! \brief SDP a= attribute representation */
typedef struct janus_sdp_attribute {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git
More information about the Pkg-voip-commits
mailing list