@observertc/observer-js
Version:
Server Side NodeJS Library for processing ObserveRTC Samples
194 lines (193 loc) • 7.38 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObservedInboundRtp = void 0;
class ObservedInboundRtp {
timestamp;
id;
ssrc;
kind;
trackIdentifier;
_peerConnection;
appData;
_visited = false;
transportId;
codecId;
packetsReceived;
packetsLost;
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;
attachments;
jitter;
bitrate = 0;
fractionLost;
bitPerPixel = 0;
deltaLostPackets = 0;
deltaReceivedPackets = 0;
deltaBytesReceived = 0;
deltaReceivedSamples = 0;
deltaSilentConcealedSamples = 0;
constructor(timestamp, id, ssrc, kind, trackIdentifier, _peerConnection) {
this.timestamp = timestamp;
this.id = id;
this.ssrc = ssrc;
this.kind = kind;
this.trackIdentifier = trackIdentifier;
this._peerConnection = _peerConnection;
}
get visited() {
const visited = this._visited;
this._visited = false;
return visited;
}
getPeerConnection() {
return this._peerConnection;
}
getRemoteOutboundRtp() {
return this._peerConnection.observedRemoteOutboundRtps.get(this.ssrc);
}
getIceTransport() {
return this._peerConnection.observedIceTransports.get(this.transportId ?? '');
}
getCodec() {
return this._peerConnection.observedCodecs.get(this.codecId ?? '');
}
getMediaPlayout() {
return this._peerConnection.observedMediaPlayouts.get(this.playoutId ?? '');
}
getTrack() {
return this._peerConnection.observedInboundTracks.get(this.trackIdentifier);
}
update(stats) {
this._visited = true;
this.deltaBytesReceived = 0;
this.deltaLostPackets = 0;
this.deltaReceivedPackets = 0;
this.deltaReceivedSamples = 0;
this.deltaSilentConcealedSamples = 0;
this.bitrate = 0;
this.jitter = undefined;
this.fractionLost = undefined;
this.bitPerPixel = 0;
const elapsedTimeInMs = stats.timestamp - this.timestamp;
if (elapsedTimeInMs) {
// update metrics here
if (this.bytesReceived && stats.bytesReceived && this.bytesReceived < stats.bytesReceived) {
this.bitrate = ((stats.bytesReceived - (this.bytesReceived ?? 0)) * 8) / elapsedTimeInMs;
}
if (this.packetsLost && stats.packetsLost && this.packetsLost < stats.packetsLost) {
this.deltaLostPackets = stats.packetsLost - this.packetsLost;
}
if (this.packetsReceived && stats.packetsReceived && this.packetsReceived < stats.packetsReceived) {
this.deltaReceivedPackets = stats.packetsReceived - this.packetsReceived;
}
if (this.totalSamplesReceived && stats.totalSamplesReceived && this.totalSamplesReceived < stats.totalSamplesReceived) {
this.deltaReceivedSamples = stats.totalSamplesReceived - this.totalSamplesReceived;
}
if (this.silentConcealedSamples && stats.silentConcealedSamples && this.silentConcealedSamples < stats.silentConcealedSamples) {
this.deltaSilentConcealedSamples = stats.silentConcealedSamples - this.silentConcealedSamples;
}
if (stats.bytesReceived && this.framesReceived && stats.framesReceived && this.framesReceived < stats.framesReceived) {
this.bitPerPixel = (stats.bytesReceived - (this.bytesReceived ?? 0)) / (stats.framesReceived - this.framesReceived);
}
if (this.deltaLostPackets && this.deltaReceivedPackets) {
this.fractionLost = this.deltaLostPackets / (this.deltaLostPackets + this.deltaReceivedPackets);
}
}
this.timestamp = stats.timestamp;
this.transportId = stats.transportId;
this.codecId = stats.codecId;
this.packetsReceived = stats.packetsReceived;
this.packetsLost = stats.packetsLost;
this.mid = stats.mid;
this.remoteId = stats.remoteId;
this.framesDecoded = stats.framesDecoded;
this.keyFramesDecoded = stats.keyFramesDecoded;
this.framesRendered = stats.framesRendered;
this.framesDropped = stats.framesDropped;
this.frameWidth = stats.frameWidth;
this.frameHeight = stats.frameHeight;
this.framesPerSecond = stats.framesPerSecond;
this.qpSum = stats.qpSum;
this.totalDecodeTime = stats.totalDecodeTime;
this.totalInterFrameDelay = stats.totalInterFrameDelay;
this.totalSquaredInterFrameDelay = stats.totalSquaredInterFrameDelay;
this.pauseCount = stats.pauseCount;
this.totalPausesDuration = stats.totalPausesDuration;
this.freezeCount = stats.freezeCount;
this.totalFreezesDuration = stats.totalFreezesDuration;
this.lastPacketReceivedTimestamp = stats.lastPacketReceivedTimestamp;
this.headerBytesReceived = stats.headerBytesReceived;
this.packetsDiscarded = stats.packetsDiscarded;
this.fecBytesReceived = stats.fecBytesReceived;
this.fecPacketsReceived = stats.fecPacketsReceived;
this.fecPacketsDiscarded = stats.fecPacketsDiscarded;
this.bytesReceived = stats.bytesReceived;
this.nackCount = stats.nackCount;
this.firCount = stats.firCount;
this.pliCount = stats.pliCount;
this.totalProcessingDelay = stats.totalProcessingDelay;
this.estimatedPlayoutTimestamp = stats.estimatedPlayoutTimestamp;
this.jitterBufferDelay = stats.jitterBufferDelay;
this.jitterBufferTargetDelay = stats.jitterBufferTargetDelay;
this.jitterBufferEmittedCount = stats.jitterBufferEmittedCount;
this.jitterBufferMinimumDelay = stats.jitterBufferMinimumDelay;
this.totalSamplesReceived = stats.totalSamplesReceived;
this.concealedSamples = stats.concealedSamples;
this.silentConcealedSamples = stats.silentConcealedSamples;
this.concealmentEvents = stats.concealmentEvents;
}
}
exports.ObservedInboundRtp = ObservedInboundRtp;