[Pkg-voip-commits] [janus] 30/163: Updated plugin to send events at layer changes, and demo to use those (as VP8 simulcasting stuff does)

Jonas Smedegaard dr at jones.dk
Sat Oct 28 01:22:06 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 1d58b2dd68f1d77aaaf6597f2a14dbf6362bca6f
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Wed Jul 12 18:21:14 2017 +0200

    Updated plugin to send events at layer changes, and demo to use those (as VP8 simulcasting stuff does)
---
 conf/janus.plugin.videoroom.cfg.sample |   2 +-
 html/vp9svctest.html                   | 114 +++++----------------
 html/vp9svctest.js                     | 174 ++++++++++++++++++++++++---------
 plugins/janus_videoroom.c              |  47 ++++++++-
 4 files changed, 199 insertions(+), 138 deletions(-)

diff --git a/conf/janus.plugin.videoroom.cfg.sample b/conf/janus.plugin.videoroom.cfg.sample
index e563135..3295683 100644
--- a/conf/janus.plugin.videoroom.cfg.sample
+++ b/conf/janus.plugin.videoroom.cfg.sample
@@ -51,7 +51,7 @@ record = false
 description = VP9-SVC Demo Room
 secret = adminpwd
 publishers = 6
-bitrate = 1024000
+bitrate = 512000
 fir_freq = 10
 videocodec = vp9
 video_svc = true
diff --git a/html/vp9svctest.html b/html/vp9svctest.html
index 24c7503..8a29a42 100644
--- a/html/vp9svctest.html
+++ b/html/vp9svctest.html
@@ -88,7 +88,24 @@
 					<div class="col-md-4">
 						<div class="panel panel-default">
 							<div class="panel-heading">
-								<h3 class="panel-title">Local Video <span class="label label-primary hide" id="publisher"></span></h3>
+								<h3 class="panel-title">Local Video <span class="label label-primary hide" id="publisher"></span>
+									<div class="btn-group btn-group-xs pull-right hide">
+										<div class="btn-group btn-group-xs">
+											<button id="bitrateset" autocomplete="off" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
+												Bandwidth<span class="caret"></span>
+											</button>
+											<ul id="bitrate" class="dropdown-menu" role="menu">
+												<li><a href="#" id="0">No limit</a></li>
+												<li><a href="#" id="128">Cap to 128kbit</a></li>
+												<li><a href="#" id="256">Cap to 256kbit</a></li>
+												<li><a href="#" id="512">Cap to 512kbit</a></li>
+												<li><a href="#" id="1024">Cap to 1mbit</a></li>
+												<li><a href="#" id="1500">Cap to 1.5mbit</a></li>
+												<li><a href="#" id="2000">Cap to 2mbit</a></li>
+											</ul>
+										</div>
+									</div>
+								</h3>
 							</div>
 							<div class="panel-body" id="videolocal"></div>
 						</div>
@@ -96,24 +113,7 @@
 					<div class="col-md-4">
 						<div class="panel panel-default">
 							<div class="panel-heading">
-								<h3 class="panel-title">Remote Video #1
-									<span class="label label-info hide" id="remote1"></span>
-									<div id="layers1" class="btn-group-vertical btn-group-vertical-xs pull-right hide">
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="sl1-1" type="button" class="btn btn-primary" style="width: 50%">SL 1</button>
-												<button id="sl1-0" type="button" class="btn btn-primary" style="width: 50%">SL 0</button>
-											</div>
-										</div>
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="tl1-2" type="button" class="btn btn-primary" style="width: 34%">TL 2</button>
-												<button id="tl1-1" type="button" class="btn btn-primary" style="width: 33%">TL 1</button>
-												<button id="tl1-0" type="button" class="btn btn-primary" style="width: 33%">TL 0</button>
-											</div>
-										</div>
-									</div>
-								</h3>
+								<h3 class="panel-title">Remote Video #1 <span class="label label-info hide" id="remote1"></span></h3>
 							</div>
 							<div class="panel-body relative" id="videoremote1"></div>
 						</div>
@@ -121,24 +121,7 @@
 					<div class="col-md-4">
 						<div class="panel panel-default">
 							<div class="panel-heading">
-								<h3 class="panel-title">Remote Video #2
-									<span class="label label-info hide" id="remote2"></span>
-									<div id="layers2" class="btn-group-vertical btn-group-vertical-xs pull-right hide">
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="sl2-1" type="button" class="btn btn-primary" style="width: 50%">SL 1</button>
-												<button id="sl2-0" type="button" class="btn btn-primary" style="width: 50%">SL 0</button>
-											</div>
-										</div>
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="tl2-2" type="button" class="btn btn-primary" style="width: 34%">TL 2</button>
-												<button id="tl2-1" type="button" class="btn btn-primary" style="width: 33%">TL 1</button>
-												<button id="tl2-0" type="button" class="btn btn-primary" style="width: 33%">TL 0</button>
-											</div>
-										</div>
-									</div>
-								</h3>
+								<h3 class="panel-title">Remote Video #2 <span class="label label-info hide" id="remote2"></span></h3>
 							</div>
 							<div class="panel-body relative" id="videoremote2"></div>
 						</div>
@@ -148,24 +131,7 @@
 					<div class="col-md-4">
 						<div class="panel panel-default">
 							<div class="panel-heading">
-								<h3 class="panel-title">Remote Video #3
-									<span class="label label-info hide" id="remote3"></span>
-									<div id="layers3" class="btn-group-vertical btn-group-vertical-xs pull-right hide">
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="sl3-1" type="button" class="btn btn-primary" style="width: 50%">SL 1</button>
-												<button id="sl3-0" type="button" class="btn btn-primary" style="width: 50%">SL 0</button>
-											</div>
-										</div>
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="tl3-2" type="button" class="btn btn-primary" style="width: 34%">TL 2</button>
-												<button id="tl3-1" type="button" class="btn btn-primary" style="width: 33%">TL 1</button>
-												<button id="tl3-0" type="button" class="btn btn-primary" style="width: 33%">TL 0</button>
-											</div>
-										</div>
-									</div>
-								</h3>
+								<h3 class="panel-title">Remote Video #3 <span class="label label-info hide" id="remote3"></span></h3>
 							</div>
 							<div class="panel-body relative" id="videoremote3"></div>
 						</div>
@@ -173,24 +139,7 @@
 					<div class="col-md-4">
 						<div class="panel panel-default">
 							<div class="panel-heading">
-								<h3 class="panel-title">Remote Video #4
-									<span class="label label-info hide" id="remote4"></span>
-									<div id="layers4" class="btn-group-vertical btn-group-vertical-xs pull-right hide">
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="sl4-1" type="button" class="btn btn-primary" style="width: 50%">SL 1</button>
-												<button id="sl4-0" type="button" class="btn btn-primary" style="width: 50%">SL 0</button>
-											</div>
-										</div>
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="tl4-2" type="button" class="btn btn-primary" style="width: 34%">TL 2</button>
-												<button id="tl4-1" type="button" class="btn btn-primary" style="width: 33%">TL 1</button>
-												<button id="tl4-0" type="button" class="btn btn-primary" style="width: 33%">TL 0</button>
-											</div>
-										</div>
-									</div>
-								</h3>
+								<h3 class="panel-title">Remote Video #4 <span class="label label-info hide" id="remote4"></span></h3>
 							</div>
 							<div class="panel-body relative" id="videoremote4"></div>
 						</div>
@@ -198,24 +147,7 @@
 					<div class="col-md-4">
 						<div class="panel panel-default">
 							<div class="panel-heading">
-								<h3 class="panel-title">Remote Video #5
-									<span class="label label-info hide" id="remote5"></span>
-									<div id="layers5" class="btn-group-vertical btn-group-vertical-xs pull-right hide">
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="sl5-1" type="button" class="btn btn-primary" style="width: 50%">SL 1</button>
-												<button id="sl5-0" type="button" class="btn btn-primary" style="width: 50%">SL 0</button>
-											</div>
-										</div>
-										<div class"row">
-											<div class="btn-group btn-group-xs" style="width: 100%">
-												<button id="tl5-2" type="button" class="btn btn-primary" style="width: 34%">TL 2</button>
-												<button id="tl5-1" type="button" class="btn btn-primary" style="width: 33%">TL 1</button>
-												<button id="tl5-0" type="button" class="btn btn-primary" style="width: 33%">TL 0</button>
-											</div>
-										</div>
-									</div>
-								</h3>
+								<h3 class="panel-title">Remote Video #5 <span class="label label-info hide" id="remote5"></span></h3>
 							</div>
 							<div class="panel-body relative" id="videoremote5"></div>
 						</div>
diff --git a/html/vp9svctest.js b/html/vp9svctest.js
index a9e8b59..2f14738 100644
--- a/html/vp9svctest.js
+++ b/html/vp9svctest.js
@@ -134,6 +134,20 @@ $(document).ready(function() {
 								webrtcState: function(on) {
 									Janus.log("Janus says our WebRTC PeerConnection is " + (on ? "up" : "down") + " now");
 									$("#videolocal").parent().parent().unblock();
+									// This controls allows us to override the global room bitrate cap
+									$('#bitrate').parent().parent().removeClass('hide').show();
+									$('#bitrate a').click(function() {
+										var id = $(this).attr("id");
+										var bitrate = parseInt(id)*1000;
+										if(bitrate === 0) {
+											Janus.log("Not limiting bandwidth via REMB");
+										} else {
+											Janus.log("Capping bandwidth to " + bitrate + " via REMB");
+										}
+										$('#bitrateset').html($(this).html() + '<span class="caret"></span>').parent().removeClass('open');
+										sfutest.send({"message": { "request": "configure", "bitrate": bitrate }});
+										return false;
+									});
 								},
 								onmessage: function(msg, jsep) {
 									Janus.debug(" ::: Got a message (publisher) :::");
@@ -286,6 +300,8 @@ $(document).ready(function() {
 									$('#videolocal').html('<button id="publish" class="btn btn-primary">Publish</button>');
 									$('#publish').click(function() { publishOwnFeed(true); });
 									$("#videolocal").parent().parent().unblock();
+									$('#bitrate').parent().parent().addClass('hide');
+									$('#bitrate a').unbind('click');
 								}
 							});
 					},
@@ -432,6 +448,19 @@ function newRemoteFeed(id, display) {
 						}
 						Janus.log("Successfully attached to feed " + remoteFeed.rfid + " (" + remoteFeed.rfdisplay + ") in room " + msg["room"]);
 						$('#remote'+remoteFeed.rfindex).removeClass('hide').html(remoteFeed.rfdisplay).show();
+					} else if(event === "event") {
+						// Check if we got an event on a SVC-related event from this publisher
+						var spatial = msg["spatial_layer"];
+						var temporal = msg["temporal_layer"];
+						if((spatial !== null && spatial !== undefined) || (temporal !== null && temporal !== undefined)) {
+							if(!remoteFeed.svcStarted) {
+								remoteFeed.svcStarted = true;
+								// Add some new buttons
+								addSvcButtons(remoteFeed.rfindex);
+							}
+							// We just received notice that there's been a switch, update the buttons
+							updateSvcButtons(remoteFeed.rfindex, spatial, temporal);
+						}
 					} else if(msg["error"] !== undefined && msg["error"] !== null) {
 						bootbox.alert(msg["error"]);
 					} else {
@@ -487,51 +516,6 @@ function newRemoteFeed(id, display) {
 					var width = this.videoWidth;
 					var height = this.videoHeight;
 					$('#curres'+remoteFeed.rfindex).removeClass('hide').text(width+'x'+height).show();
-					// Enable the layer selection buttons
-					$('#sl'+remoteFeed.rfindex+'-1').removeClass('btn-primary btn-success').addClass('btn-success')
-						.unbind('click').click(function() {
-							toastr.success("Selected spatial layer 1 of " + remoteFeed.rfdisplay + "'s video (normal resolution)", null, {timeOut: 2000});
-							$('#sl'+remoteFeed.rfindex+'-1').removeClass('btn-primary btn-success').addClass('btn-success');
-							$('#sl'+remoteFeed.rfindex+'-0').removeClass('btn-primary btn-success').addClass('btn-primary');
-							var body = { request: "configure", spatial_layer: 1};
-							remoteFeed.send({message: body});
-						});
-					$('#sl'+remoteFeed.rfindex+'-0').removeClass('btn-primary btn-success').addClass('btn-primary')
-						.unbind('click').click(function() {
-							toastr.success("Selected spatial layer 0 of " + remoteFeed.rfdisplay + "'s video (smaller resolution)", null, {timeOut: 2000});
-							$('#sl'+remoteFeed.rfindex+'-1').removeClass('btn-primary btn-success').addClass('btn-primary');
-							$('#sl'+remoteFeed.rfindex+'-0').removeClass('btn-primary btn-success').addClass('btn-success');
-							var body = { request: "configure", spatial_layer: 0};
-							remoteFeed.send({message: body});
-						});
-					$('#tl'+remoteFeed.rfindex+'-2').removeClass('btn-primary btn-success').addClass('btn-success')
-						.unbind('click').click(function() {
-							toastr.success("Selected temporal layer 2 of " + remoteFeed.rfdisplay + "'s video (normal FPS)", null, {timeOut: 2000});
-							$('#tl'+remoteFeed.rfindex+'-2').removeClass('btn-primary btn-success').addClass('btn-success');
-							$('#tl'+remoteFeed.rfindex+'-1').removeClass('btn-primary btn-success').addClass('btn-primary');
-							$('#tl'+remoteFeed.rfindex+'-0').removeClass('btn-primary btn-success').addClass('btn-primary');
-							var body = { request: "configure", temporal_layer: 2};
-							remoteFeed.send({message: body});
-						});
-					$('#tl'+remoteFeed.rfindex+'-1').removeClass('btn-primary btn-success').addClass('btn-primary')
-						.unbind('click').click(function() {
-							toastr.success("Selected temporal layer 1 of " + remoteFeed.rfdisplay + "'s video (low FPS)", null, {timeOut: 2000});
-							$('#tl'+remoteFeed.rfindex+'-2').removeClass('btn-primary btn-success').addClass('btn-primary');
-							$('#tl'+remoteFeed.rfindex+'-1').removeClass('btn-primary btn-success').addClass('btn-success');
-							$('#tl'+remoteFeed.rfindex+'-0').removeClass('btn-primary btn-success').addClass('btn-primary');
-							var body = { request: "configure", temporal_layer: 1};
-							remoteFeed.send({message: body});
-						});
-					$('#tl'+remoteFeed.rfindex+'-0').removeClass('btn-primary btn-success').addClass('btn-primary')
-						.unbind('click').click(function() {
-							toastr.success("Selected temporal layer 0 of " + remoteFeed.rfdisplay + "'s video (lowest FPS)", {timeOut: 2000});
-							$('#tl'+remoteFeed.rfindex+'-2').removeClass('btn-primary btn-success').addClass('btn-primary');
-							$('#tl'+remoteFeed.rfindex+'-1').removeClass('btn-primary btn-success').addClass('btn-primary');
-							$('#tl'+remoteFeed.rfindex+'-0').removeClass('btn-primary btn-success').addClass('btn-success');
-							var body = { request: "configure", temporal_layer: 0};
-							remoteFeed.send({message: body});
-						});
-					$('#layers'+remoteFeed.rfindex).removeClass('hide');
 				});
 				Janus.attachMediaStream($('#remotevideo'+remoteFeed.rfindex).get(0), stream);
 				var videoTracks = stream.getVideoTracks();
@@ -577,3 +561,103 @@ function newRemoteFeed(id, display) {
 			}
 		});
 }
+
+// Helpers to create SVC-related UI for a new viewer
+function addSvcButtons(feed) {
+	var index = feed;
+	$('#remote'+index).parent().append(
+		'<div id="layers'+index+'" class="btn-group-vertical btn-group-vertical-xs pull-right">' +
+		'	<div class"row">' +
+		'		<div class="btn-group btn-group-xs" style="width: 100%">' +
+		'			<button id="sl'+index+'-1" type="button" class="btn btn-primary" data-toggle="tooltip" title="Switch to normal resolution" style="width: 50%">SL 1</button>' +
+		'			<button id="sl'+index+'-0" type="button" class="btn btn-primary" data-toggle="tooltip" title="Switch to low resolution" style="width: 50%">SL 0</button>' +
+		'		</div>' +
+		'	</div>' +
+		'	<div class"row">' +
+		'		<div class="btn-group btn-group-xs" style="width: 100%">' +
+		'			<button id="tl'+index+'-2" type="button" class="btn btn-primary" data-toggle="tooltip" title="Cap to temporal layer 2 (high FPS)" style="width: 34%">TL 2</button>' +
+		'			<button id="tl'+index+'-1" type="button" class="btn btn-primary" data-toggle="tooltip" title="Cap to temporal layer 1 (medium FPS)" style="width: 33%">TL 1</button>' +
+		'			<button id="tl'+index+'-0" type="button" class="btn btn-primary" data-toggle="tooltip" title="Cap to temporal layer 0 (low FPS)" style="width: 33%">TL 0</button>' +
+		'		</div>' +
+		'	</div>' +
+		'</div>'
+	);
+	// Enable the VP8 simulcast selection buttons
+	$('#sl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary')
+		.unbind('click').click(function() {
+			toastr.info("Switching SVC spatial layer, wait for it... (low resolution)", null, {timeOut: 2000});
+			if(!$('#sl' + index + '-1').hasClass('btn-success'))
+				$('#sl' + index + '-1').removeClass('btn-primary btn-info').addClass('btn-primary');
+			$('#sl' + index + '-0').removeClass('btn-primary btn-info btn-success').addClass('btn-info');
+			feeds[index].send({message: { request: "configure", spatial_layer: 0 }});
+		});
+	$('#sl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary')
+		.unbind('click').click(function() {
+			toastr.info("Switching SVC spatial layer, wait for it... (normal resolution)", null, {timeOut: 2000});
+			$('#sl' + index + '-1').removeClass('btn-primary btn-info btn-success').addClass('btn-info');
+			if(!$('#sl' + index + '-0').hasClass('btn-success'))
+				$('#sl' + index + '-0').removeClass('btn-primary btn-info').addClass('btn-primary');
+			feeds[index].send({message: { request: "configure", spatial_layer: 1 }});
+		});
+	$('#tl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary')
+		.unbind('click').click(function() {
+			toastr.info("Capping SVC temporal layer, wait for it... (lowest FPS)", null, {timeOut: 2000});
+			if(!$('#tl' + index + '-2').hasClass('btn-success'))
+				$('#tl' + index + '-2').removeClass('btn-primary btn-info').addClass('btn-primary');
+			if(!$('#tl' + index + '-1').hasClass('btn-success'))
+				$('#tl' + index + '-1').removeClass('btn-primary btn-info').addClass('btn-primary');
+			$('#tl' + index + '-0').removeClass('btn-primary btn-info btn-success').addClass('btn-info');
+			feeds[index].send({message: { request: "configure", temporal_layer: 0 }});
+		});
+	$('#tl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary')
+		.unbind('click').click(function() {
+			toastr.info("Capping SVC temporal layer, wait for it... (medium FPS)", null, {timeOut: 2000});
+			if(!$('#tl' + index + '-2').hasClass('btn-success'))
+				$('#tl' + index + '-2').removeClass('btn-primary btn-info').addClass('btn-primary');
+			$('#tl' + index + '-1').removeClass('btn-primary btn-info').addClass('btn-info');
+			if(!$('#tl' + index + '-0').hasClass('btn-success'))
+				$('#tl' + index + '-0').removeClass('btn-primary btn-info').addClass('btn-primary');
+			feeds[index].send({message: { request: "configure", temporal_layer: 1 }});
+		});
+	$('#tl' + index + '-2').removeClass('btn-primary btn-success').addClass('btn-primary')
+		.unbind('click').click(function() {
+			toastr.info("Capping SVC temporal layer, wait for it... (highest FPS)", null, {timeOut: 2000});
+			$('#tl' + index + '-2').removeClass('btn-primary btn-info btn-success').addClass('btn-info');
+			if(!$('#tl' + index + '-1').hasClass('btn-success'))
+				$('#tl' + index + '-1').removeClass('btn-primary btn-info').addClass('btn-primary');
+			if(!$('#tl' + index + '-0').hasClass('btn-success'))
+				$('#tl' + index + '-0').removeClass('btn-primary btn-info').addClass('btn-primary');
+			feeds[index].send({message: { request: "configure", temporal_layer: 2 }});
+		});
+}
+
+function updateSvcButtons(feed, spatial, temporal) {
+	// Check the spatial layer
+	var index = feed;
+	if(spatial === 0) {
+		toastr.success("Switched SVC spatial layer! (lower resolution)", null, {timeOut: 2000});
+		$('#sl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary');
+		$('#sl' + index + '-0').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
+	} else if(spatial === 1) {
+		toastr.success("Switched SVC spatial layer! (normal resolution)", null, {timeOut: 2000});
+		$('#sl' + index + '-1').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
+		$('#sl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary');
+	}
+	// Check the temporal layer
+	if(temporal === 0) {
+		toastr.success("Capped SVC temporal layer! (lowest FPS)", null, {timeOut: 2000});
+		$('#tl' + index + '-2').removeClass('btn-primary btn-success').addClass('btn-primary');
+		$('#tl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary');
+		$('#tl' + index + '-0').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
+	} else if(temporal === 1) {
+		toastr.success("Capped SVC temporal layer! (medium FPS)", null, {timeOut: 2000});
+		$('#tl' + index + '-2').removeClass('btn-primary btn-success').addClass('btn-primary');
+		$('#tl' + index + '-1').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
+		$('#tl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary');
+	} else if(temporal === 2) {
+		toastr.success("Capped SVC temporal layer! (highest FPS)", null, {timeOut: 2000});
+		$('#tl' + index + '-2').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
+		$('#tl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary');
+		$('#tl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary');
+	}
+}
diff --git a/plugins/janus_videoroom.c b/plugins/janus_videoroom.c
index 5e5d9ed..b736060 100644
--- a/plugins/janus_videoroom.c
+++ b/plugins/janus_videoroom.c
@@ -3483,7 +3483,15 @@ static void *janus_videoroom_handler(void *data) {
 						if(spatial_layer > 1) {
 							JANUS_LOG(LOG_WARN, "Spatial layer higher than 1, will probably be ignored\n");
 						}
-						if(spatial_layer != listener->target_spatial_layer) {
+						if(spatial_layer == listener->spatial_layer) {
+							/* No need to do anything, we're already getting the right spatial layer, so notify the user */
+							json_t *event = json_object();
+							json_object_set_new(event, "videoroom", json_string("event"));
+							json_object_set_new(event, "room", json_integer(listener->room->room_id));
+							json_object_set_new(event, "spatial_layer", json_integer(listener->spatial_layer));
+							gateway->push_event(msg->handle, &janus_videoroom_plugin, NULL, event, NULL);
+							json_decref(event);
+						} else if(spatial_layer != listener->target_spatial_layer) {
 							/* Send a FIR to the new RTP forward publisher */
 							char buf[20];
 							janus_rtcp_fir((char *)&buf, 20, &publisher->fir_seq);
@@ -3501,6 +3509,15 @@ static void *janus_videoroom_handler(void *data) {
 						if(temporal_layer > 2) {
 							JANUS_LOG(LOG_WARN, "Temporal layer higher than 2, will probably be ignored\n");
 						}
+						if(temporal_layer == listener->temporal_layer) {
+							/* No need to do anything, we're already getting the right temporal layer, so notify the user */
+							json_t *event = json_object();
+							json_object_set_new(event, "videoroom", json_string("event"));
+							json_object_set_new(event, "room", json_integer(listener->room->room_id));
+							json_object_set_new(event, "temporal_layer", json_integer(listener->temporal_layer));
+							gateway->push_event(msg->handle, &janus_videoroom_plugin, NULL, event, NULL);
+							json_decref(event);
+						}
 						listener->target_temporal_layer = temporal_layer;
 					}
 				}
@@ -4133,6 +4150,13 @@ static void janus_videoroom_relay_rtp_packet(gpointer data, gpointer user_data)
 						packet->temporal_layer, listener->target_temporal_layer);
 					listener->temporal_layer = packet->temporal_layer;
 					temporal_layer = listener->temporal_layer;
+					/* Notify the viewer */
+					json_t *event = json_object();
+					json_object_set_new(event, "videoroom", json_string("event"));
+					json_object_set_new(event, "room", json_integer(listener->room->room_id));
+					json_object_set_new(event, "temporal_layer", json_integer(listener->temporal_layer));
+					gateway->push_event(listener->session->handle, &janus_videoroom_plugin, NULL, event, NULL);
+					json_decref(event);
 				}
 			} else if(listener->target_temporal_layer < listener->temporal_layer) {
 				/* We need to downscale */
@@ -4141,6 +4165,13 @@ static void janus_videoroom_relay_rtp_packet(gpointer data, gpointer user_data)
 					JANUS_LOG(LOG_HUGE, "  -- Downscaling temporal layer: %u --> %u\n",
 						listener->temporal_layer, listener->target_temporal_layer);
 					listener->temporal_layer = listener->target_temporal_layer;
+					/* Notify the viewer */
+					json_t *event = json_object();
+					json_object_set_new(event, "videoroom", json_string("event"));
+					json_object_set_new(event, "room", json_integer(listener->room->room_id));
+					json_object_set_new(event, "temporal_layer", json_integer(listener->temporal_layer));
+					gateway->push_event(listener->session->handle, &janus_videoroom_plugin, NULL, event, NULL);
+					json_decref(event);
 				}
 			}
 			if(temporal_layer < packet->temporal_layer) {
@@ -4158,6 +4189,13 @@ static void janus_videoroom_relay_rtp_packet(gpointer data, gpointer user_data)
 						packet->spatial_layer, listener->target_spatial_layer);
 					listener->spatial_layer = packet->spatial_layer;
 					spatial_layer = listener->spatial_layer;
+					/* Notify the viewer */
+					json_t *event = json_object();
+					json_object_set_new(event, "videoroom", json_string("event"));
+					json_object_set_new(event, "room", json_integer(listener->room->room_id));
+					json_object_set_new(event, "spatial_layer", json_integer(listener->spatial_layer));
+					gateway->push_event(listener->session->handle, &janus_videoroom_plugin, NULL, event, NULL);
+					json_decref(event);
 				}
 			} else if(listener->target_spatial_layer < listener->spatial_layer) {
 				/* We need to downscale */
@@ -4166,6 +4204,13 @@ static void janus_videoroom_relay_rtp_packet(gpointer data, gpointer user_data)
 					JANUS_LOG(LOG_HUGE, "  -- Downscaling spatial layer: %u --> %u\n",
 						listener->spatial_layer, listener->target_spatial_layer);
 					listener->spatial_layer = listener->target_spatial_layer;
+					/* Notify the viewer */
+					json_t *event = json_object();
+					json_object_set_new(event, "videoroom", json_string("event"));
+					json_object_set_new(event, "room", json_integer(listener->room->room_id));
+					json_object_set_new(event, "spatial_layer", json_integer(listener->spatial_layer));
+					gateway->push_event(listener->session->handle, &janus_videoroom_plugin, NULL, event, NULL);
+					json_decref(event);
 				}
 			}
 			if(spatial_layer < packet->spatial_layer) {

-- 
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