@observertc/observer-js
Version:
Server Side NodeJS Library for processing ObserveRTC Samples
145 lines (144 loc) • 5.14 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObservedOutboundRtp = void 0;
class ObservedOutboundRtp {
timestamp;
id;
ssrc;
kind;
_peerConnection;
_visited = false;
appData;
transportId;
codecId;
packetsSent;
bytesSent;
mid;
mediaSourceId;
remoteId;
rid;
headerBytesSent;
retransmittedPacketsSent;
retransmittedBytesSent;
rtxSsrc;
targetBitrate;
totalEncodedBytesTarget;
frameWidth;
frameHeight;
framesPerSecond;
framesSent;
hugeFramesSent;
framesEncoded;
keyFramesEncoded;
qpSum;
totalEncodeTime;
totalPacketSendDelay;
qualityLimitationReason;
qualityLimitationResolutionChanges;
nackCount;
firCount;
pliCount;
encoderImplementation;
powerEfficientEncoder;
active;
scalabilityMode;
qualityLimitationDurations;
attachments;
// derived fields
bitrate = 0;
payloadBitrate = 0;
packetRate = 0;
bitPerPixel = 0;
deltaPacketsSent = 0;
deltaBytesSent = 0;
constructor(timestamp, id, ssrc, kind, _peerConnection) {
this.timestamp = timestamp;
this.id = id;
this.ssrc = ssrc;
this.kind = kind;
this._peerConnection = _peerConnection;
}
get visited() {
const visited = this._visited;
this._visited = false;
return visited;
}
getPeerConnection() {
return this._peerConnection;
}
getRemoteInboundRtp() {
return this._peerConnection.observedRemoteInboundRtps.get(this.ssrc);
}
getCodec() {
return this._peerConnection.observedCodecs.get(this.codecId ?? '');
}
getMediaSource() {
return this._peerConnection.observedMediaSources.get(this.mediaSourceId ?? '');
}
getTrack() {
return this.getMediaSource()?.getTrack();
}
update(stats) {
this._visited = true;
this.bitPerPixel = 0;
this.bitrate = 0;
this.payloadBitrate = 0;
this.packetRate = 0;
this.deltaPacketsSent = 0;
this.deltaBytesSent = 0;
const elapsedTimeInMs = stats.timestamp - this.timestamp;
if (elapsedTimeInMs) {
if (stats.packetsSent !== undefined && this.packetsSent !== undefined) {
this.deltaPacketsSent = stats.packetsSent - this.packetsSent;
this.packetRate = this.deltaPacketsSent / (elapsedTimeInMs / 1000);
}
if (stats.bytesSent !== undefined && this.bytesSent !== undefined) {
this.deltaBytesSent = stats.bytesSent - this.bytesSent;
this.bitrate = (this.deltaBytesSent * 8) / (elapsedTimeInMs / 1000);
}
if (stats.headerBytesSent !== undefined && this.headerBytesSent !== undefined) {
this.payloadBitrate = ((this.deltaBytesSent ?? 0 - (stats.headerBytesSent - this.headerBytesSent)) * 8) / (elapsedTimeInMs / 1000);
}
if (this.framesSent !== undefined && stats.framesSent !== undefined) {
this.bitPerPixel = this.deltaBytesSent ? (this.deltaBytesSent * 8) / (this.framesSent - stats.framesSent) : 0;
}
}
this.timestamp = stats.timestamp;
this.transportId = stats.transportId;
this.codecId = stats.codecId;
this.packetsSent = stats.packetsSent;
this.bytesSent = stats.bytesSent;
this.mid = stats.mid;
this.mediaSourceId = stats.mediaSourceId;
this.remoteId = stats.remoteId;
this.rid = stats.rid;
this.headerBytesSent = stats.headerBytesSent;
this.retransmittedPacketsSent = stats.retransmittedPacketsSent;
this.retransmittedBytesSent = stats.retransmittedBytesSent;
this.rtxSsrc = stats.rtxSsrc;
this.targetBitrate = stats.targetBitrate;
this.totalEncodedBytesTarget = stats.totalEncodedBytesTarget;
this.frameWidth = stats.frameWidth;
this.frameHeight = stats.frameHeight;
this.framesPerSecond = stats.framesPerSecond;
this.framesSent = stats.framesSent;
this.hugeFramesSent = stats.hugeFramesSent;
this.framesEncoded = stats.framesEncoded;
this.keyFramesEncoded = stats.keyFramesEncoded;
this.qpSum = stats.qpSum;
this.totalEncodeTime = stats.totalEncodeTime;
this.totalPacketSendDelay = stats.totalPacketSendDelay;
this.qualityLimitationReason = stats.qualityLimitationReason;
this.qualityLimitationResolutionChanges = stats.qualityLimitationResolutionChanges;
this.nackCount = stats.nackCount;
this.firCount = stats.firCount;
this.pliCount = stats.pliCount;
this.encoderImplementation = stats.encoderImplementation;
this.powerEfficientEncoder = stats.powerEfficientEncoder;
this.active = stats.active;
this.scalabilityMode = stats.scalabilityMode;
this.qualityLimitationDurations = stats.qualityLimitationDurations;
this.attachments = stats.attachments;
}
}
exports.ObservedOutboundRtp = ObservedOutboundRtp;