import config from './config' ; import { get } from '../../util' ; import { AverageStatsBase } from '../types/stats' ; export interface QualityEvaluationResults { supported : boolean ; recommendedFrameRate ? : number ; recommendedResolution ? : string ; reason ? : string ; } export default function getVideoQualityEvaluation ( stats ) { const thresholds = config . qualityThresholds . video ; const bitrate = stats . bitrate ; const packetLoss = stats . packetLossRatio ; let supported = false ; let recommendedFrameRate = 30 ; let recommendedResolution = '' ; let recommendedSetting ; for ( let i = 0 ; i < thresholds . length ; i += 1 ) { const threshold = thresholds [ i ] ; if ( bitrate >= threshold . bps && packetLoss <= threshold . plr ) { supported = true ; recommendedSetting = get ( 'recommendedSetting' , threshold ) ; recommendedFrameRate = Number ( recommendedSetting . substring ( recommendedSetting . indexOf ( '@' ) + 1 ) . replace ( 'FPS' , '' ) ) ; recommendedResolution = recommendedSetting . substring ( 0 , recommendedSetting . indexOf ( '@' ) - 1 ) ; break ; } } const result = { supported , recommendedFrameRate , recommendedResolution , } ; if ( ! supported ) { result . reason = config . strings . bandwidthLow ; } else { result . recommendedFrameRate = recommendedFrameRate ; result . recommendedResolution = recommendedResolution ; } return result ; }