Skip to content

Commit

Permalink
feat: add bitrates config for webcam and screenshare and adjust the d…
Browse files Browse the repository at this point in the history
…efault sendEncoding to VP9 bitrate (#104)

* add bitrates config based on video type

---------

Co-authored-by: Yohan Totting <[email protected]>
Co-authored-by: Faiq Naufal <[email protected]>
  • Loading branch information
3 people authored Apr 3, 2024
1 parent b12bce5 commit dcddf8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
10 changes: 10 additions & 0 deletions packages/room/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ export const media = {
simulcast: false,
svc: true,
scalabilityMode: 'L3T1',
bitrates: {
high: 700 * 1000,
mid: 300 * 1000,
low: 100 * 1000,
},
},
screen: {
maxFramerate: 30,
videoCodecs: ['video/VP8', 'video/H264', 'video/VP9'],
simulcast: false,
svc: true,
scalabilityMode: 'L1T2',
bitrates: {
high: 1200 * 1000,
mid: 500 * 1000,
low: 150 * 1000,
},
},
microphone: {
audioCodecs: ['audio/red', 'audio/opus'],
Expand Down
23 changes: 10 additions & 13 deletions packages/room/peer/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
_bwController
/** @type {VideoObserver | null} */
_videoObserver
/** @type {number} */
_highBitrate
/** @type {number} */
_midBitrate
/** @type {number} */
_lowBitrate
/** @type {Array<HTMLVideoElement>} */
_pendingObservedVideo
/** @type {Array<RTCIceCandidate>} */
Expand All @@ -50,9 +44,6 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
})

this._videoObserver = null
this._highBitrate = 1200 * 1000
this._midBitrate = 500 * 1000
this._lowBitrate = 150 * 1000
this._pendingObservedVideo = []
this._pendingIceCandidates = []
/**
Expand Down Expand Up @@ -557,6 +548,12 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
const transceiverInit = {
direction: 'sendonly',
streams: [stream.mediaStream],
sendEncodings: [
{
maxBitrate: config.media[type].bitrates.high,
maxFramerate: config.media[type].maxFramerate,
},
],
}

const svcEnabled = config.media[type].svc && browserName !== FIREFOX
Expand All @@ -569,21 +566,21 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
{
rid: 'high',
maxFramerate: config.media[type].maxFramerate,
maxBitrate: this._highBitrate,
maxBitrate: config.media[type].bitrates.high,
},
{
rid: 'mid',
// eslint-disable-next-line unicorn/no-zero-fractions
scaleResolutionDownBy: 2.0,
maxFramerate: config.media[type].maxFramerate,
maxBitrate: this._midBitrate,
maxBitrate: config.media[type].bitrates.mid,
},
{
rid: 'low',
// eslint-disable-next-line unicorn/no-zero-fractions
scaleResolutionDownBy: 4.0,
maxFramerate: config.media[type].maxFramerate,
maxBitrate: this._lowBitrate,
maxBitrate: config.media[type].bitrates.low,
},
]

Expand All @@ -606,7 +603,7 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
transceiverInit.sendEncodings = sendEncodings
} else {
const sendEncodings = {
maxBitrate: this._highBitrate,
maxBitrate: config.media[type].bitrates.high,
scalabilityMode: config.media[type].scalabilityMode,
maxFramerate: config.media[type].maxFramerate,
}
Expand Down

0 comments on commit dcddf8e

Please sign in to comment.