UNPKG

@observertc/samples-decoder

Version:

ObserveRTC Library for Decoding Samples

213 lines (212 loc) 12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OutboundRtpDecoder = exports.QualityLimitationDurationsDecoder = void 0; const utils_1 = require("./utils"); const Logger_1 = require("./Logger"); class QualityLimitationDurationsDecoder { reset() { this.actualValue = undefined; } decode(input) { if (!input) return this.actualValue; const newValue = { bandwidth: input.bandwidth ?? 0, cpu: input.cpu ?? 0, none: input.none ?? 0, other: input.other ?? 0, }; this.actualValue = newValue; return newValue; } } exports.QualityLimitationDurationsDecoder = QualityLimitationDurationsDecoder; class OutboundRtpDecoder { constructor(ssrc, _attachmentsDecoder) { this.ssrc = ssrc; this._attachmentsDecoder = _attachmentsDecoder; this._visited = false; this._actualValue = undefined; this._idDecoder = new utils_1.StringToStringDecoder(); this._kindDecoder = new utils_1.StringToStringDecoder(); this._timestampDecoder = new utils_1.NumberToNumberDecoder(); this._activeDecoder = new utils_1.BooleanToBooleanDecoder(); this._bytesSentDecoder = new utils_1.BigIntToNumberDecoder(); this._codecIdDecoder = new utils_1.OneTimePassDecoder(); this._encoderImplementationDecoder = new utils_1.OneTimePassDecoder(); this._firCountDecoder = new utils_1.NumberToNumberDecoder(); this._frameHeightDecoder = new utils_1.NumberToNumberDecoder(); this._frameWidthDecoder = new utils_1.NumberToNumberDecoder(); this._framesEncodedDecoder = new utils_1.NumberToNumberDecoder(); this._framesPerSecondDecoder = new utils_1.NumberToNumberDecoder(); this._framesSentDecoder = new utils_1.NumberToNumberDecoder(); this._headerBytesSentDecoder = new utils_1.BigIntToNumberDecoder(); this._hugeFramesSentDecoder = new utils_1.NumberToNumberDecoder(); this._keyFramesEncodedDecoder = new utils_1.NumberToNumberDecoder(); this._mediaSourceIdDecoder = new utils_1.OneTimePassDecoder(); this._midDecoder = new utils_1.OneTimePassDecoder(); this._nackCountDecoder = new utils_1.NumberToNumberDecoder(); this._packetsSentDecoder = new utils_1.NumberToNumberDecoder(); this._pliCountDecoder = new utils_1.NumberToNumberDecoder(); this._powerEfficientEncoderDecoder = new utils_1.BooleanToBooleanDecoder(); this._qpSumDecoder = new utils_1.NumberToNumberDecoder(); this._qualityLimitationDurationsDecoder = new QualityLimitationDurationsDecoder(); this._qualityLimitationReasonDecoder = new utils_1.StringToStringDecoder(); this._qualityLimitationResolutionChangesDecoder = new utils_1.NumberToNumberDecoder(); this._remoteIdDecoder = new utils_1.StringToStringDecoder(); this._retransmittedBytesSentDecoder = new utils_1.BigIntToNumberDecoder(); this._retransmittedPacketsSentDecoder = new utils_1.NumberToNumberDecoder(); this._ridDecoder = new utils_1.StringToStringDecoder(); this._rtxSsrcDecoder = new utils_1.BigIntToNumberDecoder(); this._scalabilityModeDecoder = new utils_1.StringToStringDecoder(); this._targetBitrateDecoder = new utils_1.NumberToNumberDecoder(); this._totalEncodeTimeDecoder = new utils_1.NumberToNumberDecoder(); this._totalEncodedBytesTargetDecoder = new utils_1.BigIntToNumberDecoder(); this._totalPacketSendDelayDecoder = new utils_1.NumberToNumberDecoder(); this._transportIdDecoder = new utils_1.OneTimePassDecoder(); } get visited() { const result = this._visited; this._visited = false; return result; } reset() { this._idDecoder.reset(); this._kindDecoder.reset(); this._timestampDecoder.reset(); this._activeDecoder.reset(); this._bytesSentDecoder.reset(); this._codecIdDecoder.reset(); this._encoderImplementationDecoder.reset(); this._firCountDecoder.reset(); this._frameHeightDecoder.reset(); this._frameWidthDecoder.reset(); this._framesEncodedDecoder.reset(); this._framesPerSecondDecoder.reset(); this._framesSentDecoder.reset(); this._headerBytesSentDecoder.reset(); this._hugeFramesSentDecoder.reset(); this._keyFramesEncodedDecoder.reset(); this._mediaSourceIdDecoder.reset(); this._midDecoder.reset(); this._nackCountDecoder.reset(); this._packetsSentDecoder.reset(); this._pliCountDecoder.reset(); this._powerEfficientEncoderDecoder.reset(); this._qpSumDecoder.reset(); this._qualityLimitationDurationsDecoder.reset(); this._qualityLimitationReasonDecoder.reset(); this._qualityLimitationResolutionChangesDecoder.reset(); this._remoteIdDecoder.reset(); this._retransmittedBytesSentDecoder.reset(); this._retransmittedPacketsSentDecoder.reset(); this._ridDecoder.reset(); this._rtxSsrcDecoder.reset(); this._scalabilityModeDecoder.reset(); this._targetBitrateDecoder.reset(); this._totalEncodeTimeDecoder.reset(); this._totalEncodedBytesTargetDecoder.reset(); this._totalPacketSendDelayDecoder.reset(); this._transportIdDecoder.reset(); } decode(input) { this._visited = true; const timestamp = this._timestampDecoder.decode(input.timestamp); const id = this._idDecoder.decode(input.id); const kind = this._kindDecoder.decode(input.kind); if (!timestamp || id === undefined || !kind) { Logger_1.logger.warn("Invalid outbound RTP sample: missing timestamp or id", input, this); return undefined; } this._actualValue = { ssrc: this.ssrc, id, kind, timestamp, active: this._activeDecoder.decode(input.active), attachments: this._attachmentsDecoder.decode(input.attachments), bytesSent: this._bytesSentDecoder.decode(input.bytesSent), codecId: this._codecIdDecoder.decode(input.codecId), encoderImplementation: this._encoderImplementationDecoder.decode(input.encoderImplementation), firCount: this._firCountDecoder.decode(input.firCount), frameHeight: this._frameHeightDecoder.decode(input.frameHeight), frameWidth: this._frameWidthDecoder.decode(input.frameWidth), framesEncoded: this._framesEncodedDecoder.decode(input.framesEncoded), framesPerSecond: this._framesPerSecondDecoder.decode(input.framesPerSecond), framesSent: this._framesSentDecoder.decode(input.framesSent), headerBytesSent: this._headerBytesSentDecoder.decode(input.headerBytesSent), hugeFramesSent: this._hugeFramesSentDecoder.decode(input.hugeFramesSent), keyFramesEncoded: this._keyFramesEncodedDecoder.decode(input.keyFramesEncoded), mediaSourceId: this._mediaSourceIdDecoder.decode(input.mediaSourceId), mid: this._midDecoder.decode(input.mid), nackCount: this._nackCountDecoder.decode(input.nackCount), packetsSent: this._packetsSentDecoder.decode(input.packetsSent), pliCount: this._pliCountDecoder.decode(input.pliCount), powerEfficientEncoder: this._powerEfficientEncoderDecoder.decode(input.powerEfficientEncoder), qpSum: this._qpSumDecoder.decode(input.qpSum), qualityLimitationDurations: this._qualityLimitationDurationsDecoder.decode(input.qualityLimitationDurations), qualityLimitationReason: this._qualityLimitationReasonDecoder.decode(input.qualityLimitationReason), qualityLimitationResolutionChanges: this._qualityLimitationResolutionChangesDecoder.decode(input.qualityLimitationResolutionChanges), remoteId: this._remoteIdDecoder.decode(input.remoteId), retransmittedBytesSent: this._retransmittedBytesSentDecoder.decode(input.retransmittedBytesSent), retransmittedPacketsSent: this._retransmittedPacketsSentDecoder.decode(input.retransmittedPacketsSent), rid: this._ridDecoder.decode(input.rid), rtxSsrc: this._rtxSsrcDecoder.decode(input.rtxSsrc), scalabilityMode: this._scalabilityModeDecoder.decode(input.scalabilityMode), targetBitrate: this._targetBitrateDecoder.decode(input.targetBitrate), totalEncodeTime: this._totalEncodeTimeDecoder.decode(input.totalEncodeTime), totalEncodedBytesTarget: this._totalEncodedBytesTargetDecoder.decode(input.totalEncodedBytesTarget), totalPacketSendDelay: this._totalPacketSendDelayDecoder.decode(input.totalPacketSendDelay), transportId: this._transportIdDecoder.decode(input.transportId), }; return this._actualValue; } get actualValue() { return this._actualValue; } set actualValue(sample) { if (!sample) return; this._visited = true; this._actualValue = sample; this._timestampDecoder.actualValue = sample.timestamp; this._idDecoder.actualValue = sample.id; this._kindDecoder.actualValue = sample.kind; this._activeDecoder.actualValue = sample.active; this._bytesSentDecoder.actualValue = sample.bytesSent; this._codecIdDecoder.actualValue = sample.codecId; this._encoderImplementationDecoder.actualValue = sample.encoderImplementation; this._firCountDecoder.actualValue = sample.firCount; this._frameHeightDecoder.actualValue = sample.frameHeight; this._frameWidthDecoder.actualValue = sample.frameWidth; this._framesEncodedDecoder.actualValue = sample.framesEncoded; this._framesPerSecondDecoder.actualValue = sample.framesPerSecond; this._framesSentDecoder.actualValue = sample.framesSent; this._headerBytesSentDecoder.actualValue = sample.headerBytesSent; this._hugeFramesSentDecoder.actualValue = sample.hugeFramesSent; this._keyFramesEncodedDecoder.actualValue = sample.keyFramesEncoded; this._mediaSourceIdDecoder.actualValue = sample.mediaSourceId; this._midDecoder.actualValue = sample.mid; this._nackCountDecoder.actualValue = sample.nackCount; this._packetsSentDecoder.actualValue = sample.packetsSent; this._pliCountDecoder.actualValue = sample.pliCount; this._powerEfficientEncoderDecoder.actualValue = sample.powerEfficientEncoder; this._qpSumDecoder.actualValue = sample.qpSum; this._qualityLimitationDurationsDecoder.actualValue = sample.qualityLimitationDurations; this._qualityLimitationReasonDecoder.actualValue = sample.qualityLimitationReason; this._qualityLimitationResolutionChangesDecoder.actualValue = sample.qualityLimitationResolutionChanges; this._remoteIdDecoder.actualValue = sample.remoteId; this._retransmittedBytesSentDecoder.actualValue = sample.retransmittedBytesSent; this._retransmittedPacketsSentDecoder.actualValue = sample.retransmittedPacketsSent; this._ridDecoder.actualValue = sample.rid; this._rtxSsrcDecoder.actualValue = sample.rtxSsrc; this._scalabilityModeDecoder.actualValue = sample.scalabilityMode; this._targetBitrateDecoder.actualValue = sample.targetBitrate; this._totalEncodeTimeDecoder.actualValue = sample.totalEncodeTime; this._totalEncodedBytesTargetDecoder.actualValue = sample.totalEncodedBytesTarget; this._totalPacketSendDelayDecoder.actualValue = sample.totalPacketSendDelay; this._transportIdDecoder.actualValue = sample.transportId; this._attachmentsDecoder.actualValue = sample.attachments; } } exports.OutboundRtpDecoder = OutboundRtpDecoder;