UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 2.25 kB
export class DecoderPerformanceDetector{trackMonitor;static ISSUE_TYPE="video-decoder-overloaded";name="decoder-performance-detector";disabled=!1;issueKey;_consecutiveTicks=0;_alertOn=!1;_startedAt;constructor(e){this.trackMonitor=e,this.issueKey=`${DecoderPerformanceDetector.ISSUE_TYPE}-track-${e.track.id}`}get config(){return this.peerConnection.parent.config.decoderPerformanceDetector}get peerConnection(){return this.trackMonitor.getPeerConnection()}update(){if(this.disabled)return;const e=this.trackMonitor.getInboundRtp();if(!e||"video"!==e.kind)return;const t=e.deltaFramesReceived??0;if(t<this.config.minFramesReceived)return this._consecutiveTicks=0,this._alertOn?this._clear("not enough frames to evaluate"):void 0;const i=e.deltaFractionLost??0;if(this.config.quietLossThreshold<i)return this._consecutiveTicks=0,this._alertOn?this._clear("loss dominates; not a decoder problem"):void 0;const o=e.framesPerSecond??e.avgFramesPerSec,r=o&&0<o?1e3/o:void 0,n=e.decodeTimePerFrameInMs,s=void 0!==r&&void 0!==n&&r*this.config.decodeTimeBudgetRatio<n,c=void 0!==e.dropRatio&&this.config.dropRatioThreshold<e.dropRatio;if(!s&&!c)return this._consecutiveTicks=0,void(this._alertOn&&this._clear("decoder keeping up again"));if(this._consecutiveTicks+=1,this._alertOn)return;if(this._consecutiveTicks<this.config.minConsecutiveTicks)return;this._alertOn=!0,this._startedAt=Date.now();const d=this.peerConnection.parent;d.emit("video-decoder-overloaded",{clientMonitor:d,trackMonitor:this.trackMonitor,decodeTimePerFrameInMs:n,frameBudgetInMs:r}),d.raiseIssue(this.issueKey,{type:DecoderPerformanceDetector.ISSUE_TYPE,payload:{peerConnectionId:this.peerConnection.peerConnectionId,trackId:this.trackMonitor.track.id,decodeTimePerFrameInMs:n,frameBudgetInMs:r,dropRatio:e.dropRatio,renderRatio:e.renderRatio,framesReceived:t,decoderImplementation:e.decoderImplementation,powerEfficientDecoder:e.powerEfficientDecoder,consecutiveTicks:this._consecutiveTicks}})}_clear(e){this._alertOn=!1;const t=this.peerConnection.parent,i=t.activeIssues.get(this.issueKey);let o;i&&(o={...i.payload,durationInMs:this._startedAt?Date.now()-this._startedAt:void 0}),t.resolveIssue(this.issueKey,{comment:e,payload:o,resolvedAt:Date.now()}),this._startedAt=void 0}}