UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 11.6 kB
import{positiveDelta as e}from"../utils/common";export class InboundRtpMonitor{_peerConnection;_visited=!0;addedAt=Date.now();timestamp;id;ssrc;kind;trackIdentifier;transportId;codecId;packetsReceived;packetsReceivedWithEct1;packetsReceivedWithCe;packetsReportedAsLost;packetsReportedAsLostButRecovered;packetsLost;jitter;mid;remoteId;framesDecoded;keyFramesDecoded;framesRendered;framesDropped;frameWidth;frameHeight;framesPerSecond;qpSum;totalDecodeTime;totalInterFrameDelay;totalSquaredInterFrameDelay;pauseCount;totalPausesDuration;freezeCount;totalFreezesDuration;lastPacketReceivedTimestamp;headerBytesReceived;packetsDiscarded;fecBytesReceived;fecPacketsReceived;fecPacketsDiscarded;bytesReceived;nackCount;firCount;pliCount;totalProcessingDelay;estimatedPlayoutTimestamp;jitterBufferDelay;jitterBufferTargetDelay;jitterBufferEmittedCount;jitterBufferMinimumDelay;totalSamplesReceived;concealedSamples;silentConcealedSamples;concealmentEvents;insertedSamplesForDeceleration;removedSamplesForAcceleration;audioLevel;totalAudioEnergy;totalSamplesDuration;framesReceived;decoderImplementation;playoutId;powerEfficientDecoder;framesAssembledFromMultiplePackets;totalAssemblyTime;retransmittedPacketsReceived;retransmittedBytesReceived;rtxSsrc;fecSsrc;totalCorruptionProbability;totalSquaredCorruptionProbability;corruptionMeasurements;bitrate;isFreezed;desync;avgFramesPerSec;fpsVolatility;lastNFramesPerSec=[];receivingAudioSamples;totalFractionLost;bitPerPixel;packetRate;ewmaFps;deltaPacketsLost;deltaPacketsReceived;deltaBytesReceived;deltaJitterBufferDelay;deltaCorruptionProbability;deltaFractionLost;deltaFramesDecoded;deltaFramesReceived;deltaFramesRendered;deltaTime;deltaTotalSamplesReceived;deltaConcealedSamples;deltaSilentConcealedSamples;deltaConcealmentEvents;deltaInsertedSamplesForDeceleration;deltaRemovedSamplesForAcceleration;deltaPacketsDiscarded;deltaJitterBufferEmittedCount;deltaJitterBufferTargetDelay;concealmentRate;concealmentEventRate;timeStretchRate;avgJitterBufferDelayInMs;jitterBufferTargetDelayInMs;discardRate;deltaFramesDropped;deltaKeyFramesDecoded;deltaTotalDecodeTime;deltaPliCount;deltaFirCount;deltaNackCount;deltaRetransmittedBytesReceived;deltaRetransmittedPacketsReceived;retransmissionRatio;decodeTimePerFrameInMs;dropRatio;renderRatio;keyFrameRate;pliRate;firRate;nackRate;attachments;appData;constructor(e,t){this._peerConnection=e,this.id=t.id,this.timestamp=t.timestamp,this.ssrc=t.ssrc,this.kind=t.kind,this.trackIdentifier=t.trackIdentifier,Object.assign(this,t)}get visited(){const e=this._visited;return this._visited=!1,e}getPeerConnection(){return this._peerConnection}accept(t){this._visited=!0;const i=t.timestamp-this.timestamp;if(i<=0)return void Object.assign(this,t);const s=i/1e3;if(this.deltaTotalSamplesReceived=e(t.totalSamplesReceived,this.totalSamplesReceived),void 0!==this.deltaTotalSamplesReceived&&(this.receivingAudioSamples=this.deltaTotalSamplesReceived),void 0!==this.bytesReceived&&void 0!==t.bytesReceived&&(this.deltaBytesReceived=e(t.bytesReceived,this.bytesReceived)??0,this.bitrate=Math.max(0,8*this.deltaBytesReceived/s)),void 0!==this.packetsLost&&void 0!==t.packetsLost&&(this.deltaPacketsLost=e(t.packetsLost,this.packetsLost)??0),void 0!==this.packetsReceived&&void 0!==t.packetsReceived&&(this.deltaPacketsReceived=e(t.packetsReceived,this.packetsReceived)??0,this.packetRate=this.deltaPacketsReceived/s),this.deltaConcealedSamples=e(t.concealedSamples,this.concealedSamples),this.deltaSilentConcealedSamples=e(t.silentConcealedSamples,this.silentConcealedSamples),this.deltaConcealmentEvents=e(t.concealmentEvents,this.concealmentEvents),this.deltaInsertedSamplesForDeceleration=e(t.insertedSamplesForDeceleration,this.insertedSamplesForDeceleration),this.deltaRemovedSamplesForAcceleration=e(t.removedSamplesForAcceleration,this.removedSamplesForAcceleration),this.deltaPacketsDiscarded=e(t.packetsDiscarded,this.packetsDiscarded),this.deltaJitterBufferEmittedCount=e(t.jitterBufferEmittedCount,this.jitterBufferEmittedCount),void 0!==this.deltaConcealedSamples&&0<(this.deltaTotalSamplesReceived??0)){const e=Math.max(0,this.deltaConcealedSamples-(this.deltaSilentConcealedSamples??0));this.concealmentRate=e/this.deltaTotalSamplesReceived}else this.concealmentRate=void 0;if(this.concealmentEventRate=void 0!==this.deltaConcealmentEvents?this.deltaConcealmentEvents/s:void 0,0<(this.deltaTotalSamplesReceived??0)){const e=(this.deltaInsertedSamplesForDeceleration??0)+(this.deltaRemovedSamplesForAcceleration??0);this.timeStretchRate=e/this.deltaTotalSamplesReceived}else this.timeStretchRate=void 0;if(void 0!==this.deltaPacketsDiscarded){const e=this.deltaPacketsDiscarded+(this.deltaPacketsReceived??0);this.discardRate=0<e?this.deltaPacketsDiscarded/e:0}if(void 0!==this.totalCorruptionProbability&&void 0!==t.totalCorruptionProbability&&void 0!==this.corruptionMeasurements&&void 0!==t.corruptionMeasurements){const e=t.totalCorruptionProbability-this.totalCorruptionProbability,i=Math.max(1,t.corruptionMeasurements-this.corruptionMeasurements);this.deltaCorruptionProbability=Math.max(0,e/i)}if(this.deltaJitterBufferDelay=e(t.jitterBufferDelay,this.jitterBufferDelay),this.deltaFramesDecoded=e(t.framesDecoded,this.framesDecoded),this.deltaFramesReceived=e(t.framesReceived,this.framesReceived),this.deltaFramesRendered=e(t.framesRendered,this.framesRendered),this.deltaFramesDropped=e(t.framesDropped,this.framesDropped),this.deltaKeyFramesDecoded=e(t.keyFramesDecoded,this.keyFramesDecoded),this.deltaTotalDecodeTime=e(t.totalDecodeTime,this.totalDecodeTime),this.deltaPliCount=e(t.pliCount,this.pliCount),this.deltaFirCount=e(t.firCount,this.firCount),this.deltaNackCount=e(t.nackCount,this.nackCount),this.deltaRetransmittedBytesReceived=e(t.retransmittedBytesReceived,this.retransmittedBytesReceived),this.deltaRetransmittedPacketsReceived=e(t.retransmittedPacketsReceived,this.retransmittedPacketsReceived),this.retransmissionRatio=void 0!==this.deltaRetransmittedBytesReceived&&0<(this.deltaBytesReceived??0)?Math.min(1,this.deltaRetransmittedBytesReceived/this.deltaBytesReceived):void 0,this.avgJitterBufferDelayInMs=0<(this.deltaJitterBufferEmittedCount??0)&&void 0!==this.deltaJitterBufferDelay?this.deltaJitterBufferDelay/this.deltaJitterBufferEmittedCount*1e3:void 0,this.deltaJitterBufferTargetDelay=e(t.jitterBufferTargetDelay,this.jitterBufferTargetDelay),this.jitterBufferTargetDelayInMs=0<(this.deltaJitterBufferEmittedCount??0)&&void 0!==this.deltaJitterBufferTargetDelay?this.deltaJitterBufferTargetDelay/this.deltaJitterBufferEmittedCount*1e3:void 0,this.decodeTimePerFrameInMs=0<(this.deltaFramesDecoded??0)&&void 0!==this.deltaTotalDecodeTime?this.deltaTotalDecodeTime/this.deltaFramesDecoded*1e3:void 0,this.dropRatio=0<(this.deltaFramesReceived??0)&&void 0!==this.deltaFramesDropped?this.deltaFramesDropped/this.deltaFramesReceived:void 0,this.renderRatio=0<(this.deltaFramesDecoded??0)&&void 0!==this.deltaFramesRendered?this.deltaFramesRendered/this.deltaFramesDecoded:void 0,this.keyFrameRate=void 0!==this.deltaKeyFramesDecoded?this.deltaKeyFramesDecoded/s:void 0,this.pliRate=void 0!==this.deltaPliCount?this.deltaPliCount/s:void 0,this.firRate=void 0!==this.deltaFirCount?this.deltaFirCount/s:void 0,this.nackRate=void 0!==this.deltaNackCount?this.deltaNackCount/s:void 0,this.deltaTime=i,Object.assign(this,t),this.framesPerSecond){this.lastNFramesPerSec.push(this.framesPerSecond),this.lastNFramesPerSec.length>10&&this.lastNFramesPerSec.shift();const e=this.lastNFramesPerSec.reduce(((e,t)=>e+t),0)/this.lastNFramesPerSec.length,t=this.lastNFramesPerSec.reduce(((t,i)=>t+Math.abs(i-e)),0)/this.lastNFramesPerSec.length;this.avgFramesPerSec=e,this.fpsVolatility=t/e,this.bitrate&&this.frameWidth&&this.frameHeight&&(this.bitPerPixel=this.bitrate/(this.frameWidth*this.frameHeight*this.framesPerSecond))}void 0!==this.packetsReceived&&void 0!==this.packetsLost&&(this.totalFractionLost=0<this.packetsReceived&&0<this.packetsLost?this.packetsLost/(this.packetsLost+this.packetsReceived):0),void 0!==this.deltaPacketsReceived&&void 0!==this.deltaPacketsLost&&(this.deltaFractionLost=0<this.deltaPacketsReceived&&0<this.deltaPacketsLost?this.deltaPacketsLost/(this.deltaPacketsLost+this.deltaPacketsReceived):0),void 0!==this.framesPerSecond&&(this.ewmaFps=this.ewmaFps?.9*this.ewmaFps+.1*this.framesPerSecond:this.framesPerSecond)}getRemoteOutboundRtp(){return this._peerConnection.mappedRemoteOutboundRtpMonitors.get(this.ssrc)}getIceTransport(){return this._peerConnection.mappedIceTransportMonitors.get(this.transportId??"")}getCodec(){return this._peerConnection.mappedCodecMonitors.get(this.codecId??"")}getMediaPlayout(){return this._peerConnection.mappedMediaPlayoutMonitors.get(this.playoutId??"")}getTrack(){return this._peerConnection.mappedInboundTracks.get(this.trackIdentifier)}createSample(){return{timestamp:this.timestamp,id:this.id,ssrc:this.ssrc,kind:this.kind,trackIdentifier:this.trackIdentifier,transportId:this.transportId,codecId:this.codecId,packetsReceived:this.packetsReceived,packetsReceivedWithEct1:this.packetsReceivedWithEct1,packetsReceivedWithCe:this.packetsReceivedWithCe,packetsReportedAsLost:this.packetsReportedAsLost,packetsReportedAsLostButRecovered:this.packetsReportedAsLostButRecovered,packetsLost:this.packetsLost,jitter:this.jitter,mid:this.mid,remoteId:this.remoteId,framesDecoded:this.framesDecoded,keyFramesDecoded:this.keyFramesDecoded,framesRendered:this.framesRendered,framesDropped:this.framesDropped,frameWidth:this.frameWidth,frameHeight:this.frameHeight,framesPerSecond:this.framesPerSecond,qpSum:this.qpSum,totalDecodeTime:this.totalDecodeTime,totalInterFrameDelay:this.totalInterFrameDelay,totalSquaredInterFrameDelay:this.totalSquaredInterFrameDelay,pauseCount:this.pauseCount,totalPausesDuration:this.totalPausesDuration,freezeCount:this.freezeCount,totalFreezesDuration:this.totalFreezesDuration,lastPacketReceivedTimestamp:this.lastPacketReceivedTimestamp,headerBytesReceived:this.headerBytesReceived,packetsDiscarded:this.packetsDiscarded,fecBytesReceived:this.fecBytesReceived,fecPacketsReceived:this.fecPacketsReceived,fecPacketsDiscarded:this.fecPacketsDiscarded,bytesReceived:this.bytesReceived,nackCount:this.nackCount,firCount:this.firCount,pliCount:this.pliCount,totalProcessingDelay:this.totalProcessingDelay,estimatedPlayoutTimestamp:this.estimatedPlayoutTimestamp,jitterBufferDelay:this.jitterBufferDelay,jitterBufferTargetDelay:this.jitterBufferTargetDelay,jitterBufferEmittedCount:this.jitterBufferEmittedCount,jitterBufferMinimumDelay:this.jitterBufferMinimumDelay,totalSamplesReceived:this.totalSamplesReceived,concealedSamples:this.concealedSamples,silentConcealedSamples:this.silentConcealedSamples,concealmentEvents:this.concealmentEvents,insertedSamplesForDeceleration:this.insertedSamplesForDeceleration,removedSamplesForAcceleration:this.removedSamplesForAcceleration,audioLevel:this.audioLevel,totalAudioEnergy:this.totalAudioEnergy,totalSamplesDuration:this.totalSamplesDuration,framesReceived:this.framesReceived,decoderImplementation:this.decoderImplementation,playoutId:this.playoutId,powerEfficientDecoder:this.powerEfficientDecoder,framesAssembledFromMultiplePackets:this.framesAssembledFromMultiplePackets,totalAssemblyTime:this.totalAssemblyTime,retransmittedPacketsReceived:this.retransmittedPacketsReceived,retransmittedBytesReceived:this.retransmittedBytesReceived,rtxSsrc:this.rtxSsrc,fecSsrc:this.fecSsrc,totalCorruptionProbability:this.totalCorruptionProbability,totalSquaredCorruptionProbability:this.totalSquaredCorruptionProbability,corruptionMeasurements:this.corruptionMeasurements,attachments:this.attachments}}}