Files
jitsi-meet/react/features/video-quality/functions.js
paweldomas d3d5847605 feat: configurable quality levels for video height
Allows to adjust thresholds which control the video quality level
in the thumbnail view.

Changes the default behaviour to request the SD (360p) resolution only
when the thumbnails are at least 360 pixels tall and the height of
720 is required for the high quality level.

The thresholds can be configured with the 'videoQuality.minHeightForQualityLvl'
config property. Check the description in the config.js for more details.
2020-08-20 11:07:36 -07:00

63 lines
2.2 KiB
JavaScript

// @flow
import { VIDEO_QUALITY_LEVELS } from '../base/conference';
import { CFG_LVL_TO_APP_QUALITY_LVL } from './constants';
/**
* Selects {@code VIDEO_QUALITY_LEVELS} for the given {@link availableHeight} and threshold to quality mapping.
*
* @param {number} availableHeight - The height to which a matching video quality level should be found.
* @param {Map<number, number>} heightToLevel - The threshold to quality level mapping. The keys are sorted in the
* ascending order.
* @returns {number} The matching value from {@code VIDEO_QUALITY_LEVELS}.
*/
export function getReceiverVideoQualityLevel(availableHeight: number, heightToLevel: Map<number, number>): number {
let selectedLevel = VIDEO_QUALITY_LEVELS.LOW;
for (const [ levelThreshold, level ] of heightToLevel.entries()) {
if (availableHeight >= levelThreshold) {
selectedLevel = level;
}
}
return selectedLevel;
}
/**
* Converts {@code Object} passed in the config which represents height thresholds to vide quality level mapping to
* a {@code Map}.
*
* @param {Object} minHeightForQualityLvl - The 'config.videoQuality.minHeightForQualityLvl' Object from
* the configuration. See config.js for more details.
* @returns {Map<number, number>|undefined} - A mapping of minimal thumbnail height required for given quality level or
* {@code undefined} if the map contains invalid values.
*/
export function validateMinHeightForQualityLvl(minHeightForQualityLvl: Object): ?Map<number, number> {
if (typeof minHeightForQualityLvl !== 'object'
|| Object.keys(minHeightForQualityLvl).map(lvl => Number(lvl))
.find(lvl => lvl === null || isNaN(lvl) || lvl < 0)) {
return undefined;
}
const levelsSorted
= Object.keys(minHeightForQualityLvl)
.map(k => Number(k))
.sort((a, b) => a - b);
const map = new Map();
for (const level of levelsSorted) {
const configQuality = minHeightForQualityLvl[level];
const appQuality = CFG_LVL_TO_APP_QUALITY_LVL[configQuality];
if (!appQuality) {
return undefined;
}
map.set(level, appQuality);
}
return map;
}