UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 1.28 kB
export const BPP_RANGES={lowmotion:{h264:{low:.1,high:.2},h265:{low:.05,high:.15},vp8:{low:.1,high:.2},vp9:{low:.05,high:.15}},standard:{h264:{low:.15,high:.25},h265:{low:.1,high:.2},vp8:{low:.15,high:.25},vp9:{low:.1,high:.2}},highmotion:{h264:{low:.25,high:.4},h265:{low:.15,high:.3},vp8:{low:.25,high:.4},vp9:{low:.15,high:.3}}};export const MAX_VIDEO_SCORE=5;export const MIN_VIDEO_SCORE=0;export function calculateBaseVideoScore(t){const{frameHeight:o,frameWidth:e,bitrate:r,framesPerSecond:h,codec:i,contentType:n}=t;if(!(o&&e&&r&&h))return[0,"Missing data for score calculation"];if("vp8"!==i&&"vp9"!==i&&"h264"!==i&&"h265"!==i)return[0,"Unsupported codec"];const c=r/(o*e*h),l=BPP_RANGES[n]?.[i];if(!l)return[0,"Unsupported content type or codec"];if(c<l.low)return[Math.max(0,c/l.low),`Bitrate per pixel is too low for ${n} content`];if(c>=l.high)return[5,`Bitrate per pixel is excellent for ${n} content`];return[0+5*(Math.log(c-l.low+1)/Math.log(l.high-l.low+1)),`Bitrate per pixel is within acceptable range for ${n} content`]}export function calculateLatencyMOS({avgJitter:t,rttInMs:o,packetsLoss:e}){const r=o+2*t+10;let h=r<160?93.2-r/40:93.2-r/120-10;return h-=2.5*e,1+.035*h+7e-6*h*(h-60)*(100-h)}export function getRttScore(t){return-1.2984*Math.log(t)+7.5059}