UNPKG

@observertc/samples-decoder

Version:

ObserveRTC Library for Decoding Samples

304 lines (303 loc) 20.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InboundRtpDecoder = void 0; const utils_1 = require("./utils"); const utils_2 = require("./utils"); const Logger_1 = require("./Logger"); class InboundRtpDecoder { constructor(ssrc, _trackIdentifierDecoder, _attachmentsDecoder) { this.ssrc = ssrc; this._trackIdentifierDecoder = _trackIdentifierDecoder; this._attachmentsDecoder = _attachmentsDecoder; this._visited = false; this._actualValue = undefined; this._idDecoder = new utils_2.StringToStringDecoder(); this._kindDecoder = new utils_2.StringToStringDecoder(); this._timestampDecoder = new utils_2.NumberToNumberDecoder(); this._audioLevelDecoder = new utils_2.NumberToNumberDecoder(); this._bytesReceivedDecoder = new utils_1.BigIntToNumberDecoder(); this._codecIdDecoder = new utils_1.OneTimePassDecoder(); this._concealedSamplesDecoder = new utils_2.NumberToNumberDecoder(); this._concealmentEventsDecoder = new utils_2.NumberToNumberDecoder(); this._corruptionMeasurementsDecoder = new utils_2.NumberToNumberDecoder(); this._decoderImplementationDecoder = new utils_2.StringToStringDecoder(); this._estimatedPlayoutTimestampDecoder = new utils_2.NumberToNumberDecoder(); this._fecBytesReceivedDecoder = new utils_1.BigIntToNumberDecoder(); this._fecPacketsDiscardedDecoder = new utils_2.NumberToNumberDecoder(); this._fecPacketsReceivedDecoder = new utils_2.NumberToNumberDecoder(); this._fecSsrcDecoder = new utils_1.BigIntToNumberDecoder(); this._firCountDecoder = new utils_2.NumberToNumberDecoder(); this._frameHeightDecoder = new utils_2.NumberToNumberDecoder(); this._frameWidthDecoder = new utils_2.NumberToNumberDecoder(); this._framesAssembledFromMultiplePacketsDecoder = new utils_2.NumberToNumberDecoder(); this._framesDecodedDecoder = new utils_2.NumberToNumberDecoder(); this._framesDroppedDecoder = new utils_2.NumberToNumberDecoder(); this._framesPerSecondDecoder = new utils_2.NumberToNumberDecoder(); this._framesReceivedDecoder = new utils_2.NumberToNumberDecoder(); this._framesRenderedDecoder = new utils_2.NumberToNumberDecoder(); this._freezeCountDecoder = new utils_2.NumberToNumberDecoder(); this._headerBytesReceivedDecoder = new utils_1.BigIntToNumberDecoder(); this._insertedSamplesForDecelerationDecoder = new utils_2.NumberToNumberDecoder(); this._jitterDecoder = new utils_2.NumberToNumberDecoder(); this._jitterBufferDelayDecoder = new utils_2.NumberToNumberDecoder(); this._jitterBufferEmittedCountDecoder = new utils_2.NumberToNumberDecoder(); this._jitterBufferMinimumDelayDecoder = new utils_2.NumberToNumberDecoder(); this._jitterBufferTargetDelayDecoder = new utils_2.NumberToNumberDecoder(); this._keyFramesDecodedDecoder = new utils_2.NumberToNumberDecoder(); this._lastPacketReceivedTimestampDecoder = new utils_2.NumberToNumberDecoder(); this._midDecoder = new utils_1.OneTimePassDecoder(); this._nackCountDecoder = new utils_2.NumberToNumberDecoder(); this._packetsDiscardedDecoder = new utils_2.NumberToNumberDecoder(); this._packetsLostDecoder = new utils_2.NumberToNumberDecoder(); this._packetsReceivedDecoder = new utils_2.NumberToNumberDecoder(); this._pauseCountDecoder = new utils_2.NumberToNumberDecoder(); this._pliCountDecoder = new utils_2.NumberToNumberDecoder(); this._playoutIdDecoder = new utils_2.StringToStringDecoder(); this._powerEfficientDecoderDecoder = new utils_1.BooleanToBooleanDecoder(); this._qpSumDecoder = new utils_2.NumberToNumberDecoder(); this._remoteIdDecoder = new utils_2.StringToStringDecoder(); this._removedSamplesForAccelerationDecoder = new utils_2.NumberToNumberDecoder(); this._retransmittedBytesReceivedDecoder = new utils_1.BigIntToNumberDecoder(); this._retransmittedPacketsReceivedDecoder = new utils_2.NumberToNumberDecoder(); this._rtxSsrcDecoder = new utils_1.BigIntToNumberDecoder(); this._silentConcealedSamplesDecoder = new utils_2.NumberToNumberDecoder(); this._totalAssemblyTimeDecoder = new utils_2.NumberToNumberDecoder(); this._totalAudioEnergyDecoder = new utils_2.NumberToNumberDecoder(); this._totalCorruptionProbabilityDecoder = new utils_2.NumberToNumberDecoder(); this._totalDecodeTimeDecoder = new utils_2.NumberToNumberDecoder(); this._totalFreezesDurationDecoder = new utils_2.NumberToNumberDecoder(); this._totalInterFrameDelayDecoder = new utils_2.NumberToNumberDecoder(); this._totalPausesDurationDecoder = new utils_2.NumberToNumberDecoder(); this._totalProcessingDelayDecoder = new utils_2.NumberToNumberDecoder(); this._totalSamplesDurationDecoder = new utils_2.NumberToNumberDecoder(); this._totalSamplesReceivedDecoder = new utils_2.NumberToNumberDecoder(); this._totalSquaredCorruptionProbabilityDecoder = new utils_2.NumberToNumberDecoder(); this._totalSquaredInterFrameDelayDecoder = new utils_2.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._audioLevelDecoder.reset(); this._bytesReceivedDecoder.reset(); this._codecIdDecoder.reset(); this._concealedSamplesDecoder.reset(); this._concealmentEventsDecoder.reset(); this._corruptionMeasurementsDecoder.reset(); this._decoderImplementationDecoder.reset(); this._estimatedPlayoutTimestampDecoder.reset(); this._fecBytesReceivedDecoder.reset(); this._fecPacketsDiscardedDecoder.reset(); this._fecPacketsReceivedDecoder.reset(); this._fecSsrcDecoder.reset(); this._firCountDecoder.reset(); this._frameHeightDecoder.reset(); this._frameWidthDecoder.reset(); this._framesAssembledFromMultiplePacketsDecoder.reset(); this._framesDecodedDecoder.reset(); this._framesDroppedDecoder.reset(); this._framesPerSecondDecoder.reset(); this._framesReceivedDecoder.reset(); this._framesRenderedDecoder.reset(); this._freezeCountDecoder.reset(); this._headerBytesReceivedDecoder.reset(); this._insertedSamplesForDecelerationDecoder.reset(); this._jitterDecoder.reset(); this._jitterBufferDelayDecoder.reset(); this._jitterBufferEmittedCountDecoder.reset(); this._jitterBufferMinimumDelayDecoder.reset(); this._jitterBufferTargetDelayDecoder.reset(); this._keyFramesDecodedDecoder.reset(); this._lastPacketReceivedTimestampDecoder.reset(); this._midDecoder.reset(); this._nackCountDecoder.reset(); this._packetsDiscardedDecoder.reset(); this._packetsLostDecoder.reset(); this._packetsReceivedDecoder.reset(); this._pauseCountDecoder.reset(); this._pliCountDecoder.reset(); this._playoutIdDecoder.reset(); this._powerEfficientDecoderDecoder.reset(); this._qpSumDecoder.reset(); this._remoteIdDecoder.reset(); this._removedSamplesForAccelerationDecoder.reset(); this._retransmittedBytesReceivedDecoder.reset(); this._retransmittedPacketsReceivedDecoder.reset(); this._rtxSsrcDecoder.reset(); this._silentConcealedSamplesDecoder.reset(); this._totalAssemblyTimeDecoder.reset(); this._totalAudioEnergyDecoder.reset(); this._totalCorruptionProbabilityDecoder.reset(); this._totalDecodeTimeDecoder.reset(); this._totalFreezesDurationDecoder.reset(); this._totalInterFrameDelayDecoder.reset(); this._totalPausesDurationDecoder.reset(); this._totalProcessingDelayDecoder.reset(); this._totalSamplesDurationDecoder.reset(); this._totalSamplesReceivedDecoder.reset(); this._totalSquaredCorruptionProbabilityDecoder.reset(); this._totalSquaredInterFrameDelayDecoder.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); const trackIdentifier = this._trackIdentifierDecoder.decode(input.trackIdentifier); if (!timestamp || id === undefined || trackIdentifier === undefined || kind === undefined) { Logger_1.logger.warn("Invalid inbound RTP sample: missing timestamp or id"); return undefined; } this._actualValue = { ssrc: this.ssrc, kind, trackIdentifier, attachments: this._attachmentsDecoder.decode(input.attachments), id, timestamp, audioLevel: this._audioLevelDecoder.decode(input.audioLevel), bytesReceived: this._bytesReceivedDecoder.decode(input.bytesReceived), codecId: this._codecIdDecoder.decode(input.codecId), concealedSamples: this._concealedSamplesDecoder.decode(input.concealedSamples), concealmentEvents: this._concealmentEventsDecoder.decode(input.concealmentEvents), corruptionMeasurements: this._corruptionMeasurementsDecoder.decode(input.corruptionMeasurements), decoderImplementation: this._decoderImplementationDecoder.decode(input.decoderImplementation), estimatedPlayoutTimestamp: this._estimatedPlayoutTimestampDecoder.decode(input.estimatedPlayoutTimestamp), fecBytesReceived: this._fecBytesReceivedDecoder.decode(input.fecBytesReceived), fecPacketsDiscarded: this._fecPacketsDiscardedDecoder.decode(input.fecPacketsDiscarded), fecPacketsReceived: this._fecPacketsReceivedDecoder.decode(input.fecPacketsReceived), fecSsrc: this._fecSsrcDecoder.decode(input.fecSsrc), firCount: this._firCountDecoder.decode(input.firCount), frameHeight: this._frameHeightDecoder.decode(input.frameHeight), frameWidth: this._frameWidthDecoder.decode(input.frameWidth), framesAssembledFromMultiplePackets: this._framesAssembledFromMultiplePacketsDecoder.decode(input.framesAssembledFromMultiplePackets), framesDecoded: this._framesDecodedDecoder.decode(input.framesDecoded), framesDropped: this._framesDroppedDecoder.decode(input.framesDropped), framesPerSecond: this._framesPerSecondDecoder.decode(input.framesPerSecond), framesReceived: this._framesReceivedDecoder.decode(input.framesReceived), framesRendered: this._framesRenderedDecoder.decode(input.framesRendered), freezeCount: this._freezeCountDecoder.decode(input.freezeCount), headerBytesReceived: this._headerBytesReceivedDecoder.decode(input.headerBytesReceived), insertedSamplesForDeceleration: this._insertedSamplesForDecelerationDecoder.decode(input.insertedSamplesForDeceleration), jitter: this._jitterDecoder.decode(input.jitter), jitterBufferDelay: this._jitterBufferDelayDecoder.decode(input.jitterBufferDelay), jitterBufferEmittedCount: this._jitterBufferEmittedCountDecoder.decode(input.jitterBufferEmittedCount), jitterBufferMinimumDelay: this._jitterBufferMinimumDelayDecoder.decode(input.jitterBufferMinimumDelay), jitterBufferTargetDelay: this._jitterBufferTargetDelayDecoder.decode(input.jitterBufferTargetDelay), keyFramesDecoded: this._keyFramesDecodedDecoder.decode(input.keyFramesDecoded), lastPacketReceivedTimestamp: this._lastPacketReceivedTimestampDecoder.decode(input.lastPacketReceivedTimestamp), mid: this._midDecoder.decode(input.mid), nackCount: this._nackCountDecoder.decode(input.nackCount), packetsDiscarded: this._packetsDiscardedDecoder.decode(input.packetsDiscarded), packetsLost: this._packetsLostDecoder.decode(input.packetsLost), packetsReceived: this._packetsReceivedDecoder.decode(input.packetsReceived), pauseCount: this._pauseCountDecoder.decode(input.pauseCount), pliCount: this._pliCountDecoder.decode(input.pliCount), playoutId: this._playoutIdDecoder.decode(input.playoutId), powerEfficientDecoder: this._powerEfficientDecoderDecoder.decode(input.powerEfficientDecoder), qpSum: this._qpSumDecoder.decode(input.qpSum), remoteId: this._remoteIdDecoder.decode(input.remoteId), removedSamplesForAcceleration: this._removedSamplesForAccelerationDecoder.decode(input.removedSamplesForAcceleration), retransmittedBytesReceived: this._retransmittedBytesReceivedDecoder.decode(input.retransmittedBytesReceived), retransmittedPacketsReceived: this._retransmittedPacketsReceivedDecoder.decode(input.retransmittedPacketsReceived), rtxSsrc: this._rtxSsrcDecoder.decode(input.rtxSsrc), silentConcealedSamples: this._silentConcealedSamplesDecoder.decode(input.silentConcealedSamples), totalAssemblyTime: this._totalAssemblyTimeDecoder.decode(input.totalAssemblyTime), totalAudioEnergy: this._totalAudioEnergyDecoder.decode(input.totalAudioEnergy), totalCorruptionProbability: this._totalCorruptionProbabilityDecoder.decode(input.totalCorruptionProbability), totalDecodeTime: this._totalDecodeTimeDecoder.decode(input.totalDecodeTime), totalFreezesDuration: this._totalFreezesDurationDecoder.decode(input.totalFreezesDuration), totalInterFrameDelay: this._totalInterFrameDelayDecoder.decode(input.totalInterFrameDelay), totalPausesDuration: this._totalPausesDurationDecoder.decode(input.totalPausesDuration), totalProcessingDelay: this._totalProcessingDelayDecoder.decode(input.totalProcessingDelay), totalSamplesDuration: this._totalSamplesDurationDecoder.decode(input.totalSamplesDuration), totalSamplesReceived: this._totalSamplesReceivedDecoder.decode(input.totalSamplesReceived), totalSquaredCorruptionProbability: this._totalSquaredCorruptionProbabilityDecoder.decode(input.totalSquaredCorruptionProbability), totalSquaredInterFrameDelay: this._totalSquaredInterFrameDelayDecoder.decode(input.totalSquaredInterFrameDelay), 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._idDecoder.actualValue = sample.id; this._kindDecoder.actualValue = sample.kind; this._timestampDecoder.actualValue = sample.timestamp; this._audioLevelDecoder.actualValue = sample.audioLevel; this._bytesReceivedDecoder.actualValue = sample.bytesReceived; this._codecIdDecoder.actualValue = sample.codecId; this._concealedSamplesDecoder.actualValue = sample.concealedSamples; this._concealmentEventsDecoder.actualValue = sample.concealmentEvents; this._corruptionMeasurementsDecoder.actualValue = sample.corruptionMeasurements; this._decoderImplementationDecoder.actualValue = sample.decoderImplementation; this._estimatedPlayoutTimestampDecoder.actualValue = sample.estimatedPlayoutTimestamp; this._fecBytesReceivedDecoder.actualValue = sample.fecBytesReceived; this._fecPacketsDiscardedDecoder.actualValue = sample.fecPacketsDiscarded; this._fecPacketsReceivedDecoder.actualValue = sample.fecPacketsReceived; this._fecSsrcDecoder.actualValue = sample.fecSsrc; this._firCountDecoder.actualValue = sample.firCount; this._frameHeightDecoder.actualValue = sample.frameHeight; this._frameWidthDecoder.actualValue = sample.frameWidth; this._framesAssembledFromMultiplePacketsDecoder.actualValue = sample.framesAssembledFromMultiplePackets; this._framesDecodedDecoder.actualValue = sample.framesDecoded; this._framesDroppedDecoder.actualValue = sample.framesDropped; this._framesPerSecondDecoder.actualValue = sample.framesPerSecond; this._framesReceivedDecoder.actualValue = sample.framesReceived; this._framesRenderedDecoder.actualValue = sample.framesRendered; this._freezeCountDecoder.actualValue = sample.freezeCount; this._headerBytesReceivedDecoder.actualValue = sample.headerBytesReceived; this._insertedSamplesForDecelerationDecoder.actualValue = sample.insertedSamplesForDeceleration; this._jitterDecoder.actualValue = sample.jitter; this._jitterBufferDelayDecoder.actualValue = sample.jitterBufferDelay; this._jitterBufferEmittedCountDecoder.actualValue = sample.jitterBufferEmittedCount; this._jitterBufferMinimumDelayDecoder.actualValue = sample.jitterBufferMinimumDelay; this._jitterBufferTargetDelayDecoder.actualValue = sample.jitterBufferTargetDelay; this._keyFramesDecodedDecoder.actualValue = sample.keyFramesDecoded; this._lastPacketReceivedTimestampDecoder.actualValue = sample.lastPacketReceivedTimestamp; this._midDecoder.actualValue = sample.mid; this._nackCountDecoder.actualValue = sample.nackCount; this._packetsDiscardedDecoder.actualValue = sample.packetsDiscarded; this._packetsLostDecoder.actualValue = sample.packetsLost; this._packetsReceivedDecoder.actualValue = sample.packetsReceived; this._pauseCountDecoder.actualValue = sample.pauseCount; this._pliCountDecoder.actualValue = sample.pliCount; this._playoutIdDecoder.actualValue = sample.playoutId; this._powerEfficientDecoderDecoder.actualValue = sample.powerEfficientDecoder; this._qpSumDecoder.actualValue = sample.qpSum; this._remoteIdDecoder.actualValue = sample.remoteId; this._removedSamplesForAccelerationDecoder.actualValue = sample.removedSamplesForAcceleration; this._retransmittedBytesReceivedDecoder.actualValue = sample.retransmittedBytesReceived; this._retransmittedPacketsReceivedDecoder.actualValue = sample.retransmittedPacketsReceived; this._rtxSsrcDecoder.actualValue = sample.rtxSsrc; this._silentConcealedSamplesDecoder.actualValue = sample.silentConcealedSamples; this._totalAssemblyTimeDecoder.actualValue = sample.totalAssemblyTime; this._totalAudioEnergyDecoder.actualValue = sample.totalAudioEnergy; this._totalCorruptionProbabilityDecoder.actualValue = sample.totalCorruptionProbability; this._totalDecodeTimeDecoder.actualValue = sample.totalDecodeTime; this._totalFreezesDurationDecoder.actualValue = sample.totalFreezesDuration; this._totalInterFrameDelayDecoder.actualValue = sample.totalInterFrameDelay; this._totalPausesDurationDecoder.actualValue = sample.totalPausesDuration; this._totalProcessingDelayDecoder.actualValue = sample.totalProcessingDelay; this._totalSamplesDurationDecoder.actualValue = sample.totalSamplesDuration; this._totalSamplesReceivedDecoder.actualValue = sample.totalSamplesReceived; this._totalSquaredCorruptionProbabilityDecoder.actualValue = sample.totalSquaredCorruptionProbability; this._totalSquaredInterFrameDelayDecoder.actualValue = sample.totalSquaredInterFrameDelay; this._transportIdDecoder.actualValue = sample.transportId; this._attachmentsDecoder.actualValue = sample.attachments; this._trackIdentifierDecoder.actualValue = sample.trackIdentifier; } } exports.InboundRtpDecoder = InboundRtpDecoder;