您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // @flow
  2. import { CFG_LVL_TO_APP_QUALITY_LVL, VIDEO_QUALITY_LEVELS } from './constants';
  3. /**
  4. * Selects {@code VIDEO_QUALITY_LEVELS} for the given {@link availableHeight} and threshold to quality mapping.
  5. *
  6. * @param {number} availableHeight - The height to which a matching video quality level should be found.
  7. * @param {Map<number, number>} heightToLevel - The threshold to quality level mapping. The keys are sorted in the
  8. * ascending order.
  9. * @returns {number} The matching value from {@code VIDEO_QUALITY_LEVELS}.
  10. */
  11. export function getReceiverVideoQualityLevel(availableHeight: number, heightToLevel: Map<number, number>): number {
  12. let selectedLevel = VIDEO_QUALITY_LEVELS.LOW;
  13. for (const [ levelThreshold, level ] of heightToLevel.entries()) {
  14. if (availableHeight >= levelThreshold) {
  15. selectedLevel = level;
  16. }
  17. }
  18. return selectedLevel;
  19. }
  20. /**
  21. * Converts {@code Object} passed in the config which represents height thresholds to vide quality level mapping to
  22. * a {@code Map}.
  23. *
  24. * @param {Object} minHeightForQualityLvl - The 'config.videoQuality.minHeightForQualityLvl' Object from
  25. * the configuration. See config.js for more details.
  26. * @returns {Map<number, number>|undefined} - A mapping of minimal thumbnail height required for given quality level or
  27. * {@code undefined} if the map contains invalid values.
  28. */
  29. export function validateMinHeightForQualityLvl(minHeightForQualityLvl: Object): ?Map<number, number> {
  30. if (typeof minHeightForQualityLvl !== 'object'
  31. || Object.keys(minHeightForQualityLvl).map(lvl => Number(lvl))
  32. .find(lvl => lvl === null || isNaN(lvl) || lvl < 0)) {
  33. return undefined;
  34. }
  35. const levelsSorted
  36. = Object.keys(minHeightForQualityLvl)
  37. .map(k => Number(k))
  38. .sort((a, b) => a - b);
  39. const map = new Map();
  40. for (const level of levelsSorted) {
  41. const configQuality = minHeightForQualityLvl[level];
  42. const appQuality = CFG_LVL_TO_APP_QUALITY_LVL[configQuality];
  43. if (!appQuality) {
  44. return undefined;
  45. }
  46. map.set(level, appQuality);
  47. }
  48. return map;
  49. }