Testing bitrate/res downscaling on n>4

This commit is contained in:
Arya Vohra 2020-06-02 10:52:54 +08:00
parent 003fca0399
commit f72d77494e
1 changed files with 28 additions and 3 deletions

View File

@ -225,6 +225,15 @@ var VideoChat = {
break;
}
};
// Downscale send resolution and bitrate if num in room > 4
if (VideoChat.peerConnections.size > 3) {
for (var pc in VideoChat.peerConnections) {
downscaleStream(pc);
}
}
callback(uuid);
};
},
@ -500,9 +509,25 @@ function sendToAllDataChannels(message) {
// End Fullscreen
// Downscale own stream
function downscaleStreams() {
// To be implemented
// Downscale single stream
async function downscaleStream(pc) {
height = 480;
rate = 800000;
try {
do {
h = height;
r = rate;
const [sender] = pc.getSenders();
const ratio = sender.track.getSettings().height / height;
const params = sender.getParameters();
if (!params.encodings) params.encodings = [{}]; // Firefox workaround!
params.encodings[0].scaleResolutionDownBy = Math.max(ratio, 1);
params.encodings[0].maxBitrate = rate;
await sender.setParameters(params);
} while (h != height);
} catch (e) {
logIt(e);
}
}
// Mute microphone