Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions WebApp/client/public/bidirectional/js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SendVideo } from "./sendvideo.js";
import { getServerConfig } from "../../js/config.js";
import { createDisplayStringArray } from "../../js/stats.js";

const defaultStreamWidth = 1280;
const defaultStreamHeight = 720;
Expand Down Expand Up @@ -39,16 +40,15 @@ let useCustomResolution = false;

setUpInputSelect();
showCodecSelect();
showStatsMessage();

let sendVideo = new SendVideo();
sendVideo.ondisconnect = async (message) => {
await hangUp();

if (message) {
messageDiv.style.display = 'block';
messageDiv.innerText = message;
}

await hangUp();
};

let useWebSocket;
Expand Down Expand Up @@ -123,9 +123,11 @@ async function setUp() {
codecPreferences.disabled = true;

await sendVideo.setupConnection(remoteVideo, connectionId, useWebSocket, selectedCodecs);
showStatsMessage();
}

async function hangUp() {
clearStatsMessage();
hangUpButton.disabled = true;
setupButton.disabled = false;
await sendVideo.hangUp(connectionId);
Expand Down Expand Up @@ -203,8 +205,11 @@ function showCodecSelect() {
codecPreferences.disabled = false;
}

let lastStats;
let intervalId;

function showStatsMessage() {
setInterval(async () => {
intervalId = setInterval(async () => {
if (localVideo.videoWidth) {
localVideoStatsDiv.innerHTML = `<strong>Sending resolution:</strong> ${localVideo.videoWidth} x ${localVideo.videoHeight} px`;
}
Expand All @@ -221,21 +226,23 @@ function showStatsMessage() {
return;
}

let message = "";
stats.forEach(stat => {
if (stat.type === 'inbound-rtp' && stat.kind === 'video' && stat.codecId !== undefined) {
const codec = stats.get(stat.codecId);
message += `Using for receive video ${codec.mimeType} ${codec.sdpFmtpLine}, payloadType=${codec.payloadType}. Decoder: ${stat.decoderImplementation} \n`;
}
if (stat.type === 'outbound-rtp' && stat.kind === 'video' && stat.codecId !== undefined) {
const codec = stats.get(stat.codecId);
message += `Using for send video ${codec.mimeType} ${codec.sdpFmtpLine}, payloadType=${codec.payloadType}. Encoder: ${stat.encoderImplementation} \n`;
}
});

if (message != "") {
const array = createDisplayStringArray(stats, lastStats);
if (array.length) {
messageDiv.style.display = 'block';
messageDiv.innerText = message;
messageDiv.innerHTML = array.join('<br>');
}
lastStats = stats;
}, 1000);
}

function clearStatsMessage() {
if (intervalId) {
clearInterval(intervalId);
}
lastStats = null;
intervalId = null;
localVideoStatsDiv.innerHTML = '';
remoteVideoStatsDiv.innerHTML = '';
messageDiv.style.display = 'none';
messageDiv.innerHTML = '';
}
91 changes: 91 additions & 0 deletions WebApp/client/public/js/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* create display string array from RTCStatsReport
* @param {RTCStatsReport} report - current RTCStatsReport
* @param {RTCStatsReport} lastReport - latest RTCStatsReport
* @return {Array<string>} - display string Array
*/
export function createDisplayStringArray(report, lastReport) {
let array = new Array();

report.forEach(stat => {
if (stat.type === 'inbound-rtp') {
array.push(`${stat.kind} receiving stream stats`);

if (stat.codecId != undefined) {
const codec = report.get(stat.codecId);
array.push(`Codec: ${codec.mimeType}`);

if (codec.sdpFmtpLine) {
codec.sdpFmtpLine.split(";").forEach(fmtp => {
array.push(` - ${fmtp}`);
});
}

if (codec.payloadType) {
array.push(` - payloadType=${codec.payloadType}`);
}

if (codec.clockRate) {
array.push(` - clockRate=${codec.clockRate}`);
}

if (codec.channels) {
array.push(` - channels=${codec.channels}`);
}
}

if (stat.kind == "video") {
array.push(`Decoder: ${stat.decoderImplementation}`);
array.push(`Resolution: ${stat.frameWidth}x${stat.frameHeight}`);
array.push(`Framerate: ${stat.framesPerSecond}`);
}

if (lastReport && lastReport.has(stat.id)) {
const lastStats = lastReport.get(stat.id);
const duration = (stat.timestamp - lastStats.timestamp) / 1000;
const bitrate = (8 * (stat.bytesReceived - lastStats.bytesReceived) / duration) / 1000;
array.push(`Bitrate: ${bitrate.toFixed(2)} kbit/sec`);
}
} else if (stat.type === 'outbound-rtp') {
array.push(`${stat.kind} sending stream stats`);

if (stat.codecId != undefined) {
const codec = report.get(stat.codecId);
array.push(`Codec: ${codec.mimeType}`);

if (codec.sdpFmtpLine) {
codec.sdpFmtpLine.split(";").forEach(fmtp => {
array.push(` - ${fmtp}`);
});
}

if (codec.payloadType) {
array.push(` - payloadType=${codec.payloadType}`);
}

if (codec.clockRate) {
array.push(` - clockRate=${codec.clockRate}`);
}

if (codec.channels) {
array.push(` - channels=${codec.channels}`);
}
}

if (stat.kind == "video") {
array.push(`Encoder: ${stat.encoderImplementation}`);
array.push(`Resolution: ${stat.frameWidth}x${stat.frameHeight}`);
array.push(`Framerate: ${stat.framesPerSecond}`);
}

if (lastReport && lastReport.has(stat.id)) {
const lastStats = lastReport.get(stat.id);
const duration = (stat.timestamp - lastStats.timestamp) / 1000;
const bitrate = (8 * (stat.bytesSent - lastStats.bytesSent) / duration) / 1000;
array.push(`Bitrate: ${bitrate.toFixed(2)} kbit/sec`);
}
}
});

return array;
}
39 changes: 29 additions & 10 deletions WebApp/client/public/multiplay/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
getServerConfig
} from "../../js/config.js";

import {
createDisplayStringArray
} from "../../js/stats.js"

setup();

let playButton;
Expand Down Expand Up @@ -36,7 +40,6 @@ async function setup() {
useWebSocket = res.useWebSocket;
showWarningIfNeeded(res.startupMode);
showCodecSelect();
showStatsMessage();
showPlayButton();
}

Expand Down Expand Up @@ -124,16 +127,20 @@ async function setupVideoPlayer(elements) {

await videoPlayer.setupConnection(useWebSocket, selectedCodecs);
videoPlayer.ondisconnect = onDisconnect;
showStatsMessage();

return videoPlayer;
}

function onDisconnect(message) {
async function onDisconnect(message) {
clearStatsMessage();
if (message) {
messageDiv.style.display = 'block';
messageDiv.innerText = message;
}

clearChildren(playerDiv);
await videoPlayer.stop();
videoPlayer = null;
if (supportsSetCodecPreferences) {
codecPreferences.disabled = false;
Expand Down Expand Up @@ -167,8 +174,11 @@ function showCodecSelect() {
codecPreferences.disabled = false;
}

let lastStats;
let intervalId;

function showStatsMessage() {
setInterval(async () => {
intervalId = setInterval(async () => {
if (videoPlayer == null) {
return;
}
Expand All @@ -177,13 +187,22 @@ function showStatsMessage() {
if (stats == null) {
return;
}
stats.forEach(stat => {
if (!(stat.type === 'inbound-rtp' && stat.kind === 'video') || stat.codecId === undefined) {
return;
}
const codec = stats.get(stat.codecId);

const array = createDisplayStringArray(stats, lastStats);
if (array.length) {
messageDiv.style.display = 'block';
messageDiv.innerText = `Using ${codec.mimeType} ${codec.sdpFmtpLine}, payloadType=${codec.payloadType}. Decoder: ${stat.decoderImplementation}`;
});
messageDiv.innerHTML = array.join('<br>');
}
lastStats = stats;
}, 1000);
}

function clearStatsMessage() {
if (intervalId) {
clearInterval(intervalId);
}
lastStats = null;
intervalId = null;
messageDiv.style.display = 'none';
messageDiv.innerHTML = '';
}
32 changes: 23 additions & 9 deletions WebApp/client/public/receiver/js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Receiver } from "./receiver.js";
import { getServerConfig } from "../../js/config.js";
import { createDisplayStringArray } from "../../js/stats.js";

setup();

Expand Down Expand Up @@ -34,7 +35,6 @@ async function setup() {
showWarningIfNeeded(res.startupMode);
showCodecSelect();
showPlayButton();
showStatsMessage();
}

function showWarningIfNeeded(startupMode) {
Expand Down Expand Up @@ -170,11 +170,13 @@ async function setupVideoPlayer(elements) {

await videoPlayer.setupConnection(useWebSocket, selectedCodecs);
videoPlayer.ondisconnect = onDisconnect;
showStatsMessage();

return videoPlayer;
}

async function onDisconnect(message) {
clearStatsMessage();
if (message) {
messageDiv.style.display = 'block';
messageDiv.innerText = message;
Expand Down Expand Up @@ -215,8 +217,11 @@ function showCodecSelect() {
codecPreferences.disabled = false;
}

let lastStats;
let intervalId;

function showStatsMessage() {
setInterval(async () => {
intervalId = setInterval(async () => {
if (receiver == null) {
return;
}
Expand All @@ -225,13 +230,22 @@ function showStatsMessage() {
if (stats == null) {
return;
}
stats.forEach(stat => {
if (!(stat.type === 'inbound-rtp' && stat.kind === 'video') || stat.codecId === undefined) {
return;
}
const codec = stats.get(stat.codecId);

const array = createDisplayStringArray(stats, lastStats);
if (array.length) {
messageDiv.style.display = 'block';
messageDiv.innerText = `Using ${codec.mimeType} ${codec.sdpFmtpLine}, payloadType=${codec.payloadType}. Decoder: ${stat.decoderImplementation}`;
});
messageDiv.innerHTML = array.join('<br>');
}
lastStats = stats;
}, 1000);
}

function clearStatsMessage() {
if (intervalId) {
clearInterval(intervalId);
}
lastStats = null;
intervalId = null;
messageDiv.style.display = 'none';
messageDiv.innerHTML = '';
}
5 changes: 3 additions & 2 deletions com.unity.renderstreaming/Runtime/Scripts/Broadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ public class Broadcast : SignalingHandlerBase,
IOfferHandler, IAddChannelHandler, IDisconnectHandler, IDeletedConnectionHandler,
IAddReceiverHandler
{
[SerializeField]
private List<Component> streams = new List<Component>();
[SerializeField] private List<Component> streams = new List<Component>();

private List<string> connectionIds = new List<string>();

public override IEnumerable<Component> Streams => streams;

public void AddComponent(Component component)
{
streams.Add(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public abstract class SignalingHandlerBase : MonoBehaviour
{
private IRenderStreamingHandler m_handler;

/// <summary>
///
/// </summary>
public virtual IEnumerable<Component> Streams => null;

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -303,12 +308,12 @@ internal void SetHandler(IRenderStreamingHandler handler)
public interface IStreamSender
{
/// <summary>
///
///
/// </summary>
MediaStreamTrack Track { get; }

/// <summary>
///
///
/// </summary>
IReadOnlyDictionary<string, RTCRtpTransceiver> Transceivers { get; }

Expand Down
2 changes: 2 additions & 0 deletions com.unity.renderstreaming/Runtime/Scripts/SingleConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class SingleConnection : SignalingHandlerBase,

private string connectionId;

public override IEnumerable<Component> Streams => streams;

public void AddComponent(Component component)
{
streams.Add(component);
Expand Down
Loading