UNPKG

@observertc/samples-decoder

Version:

ObserveRTC Library for Decoding Samples

99 lines (98 loc) 4.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoteInboundRtpDecoder = void 0; const utils_1 = require("./utils"); const Logger_1 = require("./Logger"); class RemoteInboundRtpDecoder { constructor(ssrc, _attachmentsDecoder) { this.ssrc = ssrc; this._attachmentsDecoder = _attachmentsDecoder; this._visited = false; this._actualValue = undefined; this._timestampDecoder = new utils_1.NumberToNumberDecoder(); this._idDecoder = new utils_1.StringToStringDecoder(); this._kindDecoder = new utils_1.StringToStringDecoder(); this._transportIdDecoder = new utils_1.OneTimePassDecoder(); this._codecIdDecoder = new utils_1.OneTimePassDecoder(); this._packetsReceivedDecoder = new utils_1.NumberToNumberDecoder(); this._packetsLostDecoder = new utils_1.NumberToNumberDecoder(); this._jitterDecoder = new utils_1.NumberToNumberDecoder(); this._localIdDecoder = new utils_1.StringToStringDecoder(); this._roundTripTimeDecoder = new utils_1.NumberToNumberDecoder(); this._totalRoundTripTimeDecoder = new utils_1.NumberToNumberDecoder(); this._fractionLostDecoder = new utils_1.NumberToNumberDecoder(); this._roundTripTimeMeasurementsDecoder = new utils_1.NumberToNumberDecoder(); } get visited() { const result = this._visited; this._visited = false; return result; } reset() { this._timestampDecoder.reset(); this._idDecoder.reset(); this._kindDecoder.reset(); this._transportIdDecoder.reset(); this._codecIdDecoder.reset(); this._packetsReceivedDecoder.reset(); this._packetsLostDecoder.reset(); this._jitterDecoder.reset(); this._localIdDecoder.reset(); this._roundTripTimeDecoder.reset(); this._totalRoundTripTimeDecoder.reset(); this._fractionLostDecoder.reset(); this._roundTripTimeMeasurementsDecoder.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 === undefined) { Logger_1.logger.warn("Invalid remote inbound RTP sample: missing timestamp or id"); return undefined; } this._actualValue = { ssrc: this.ssrc, timestamp, id, kind, transportId: this._transportIdDecoder.decode(input.transportId), codecId: this._codecIdDecoder.decode(input.codecId), packetsReceived: this._packetsReceivedDecoder.decode(input.packetsReceived), packetsLost: this._packetsLostDecoder.decode(input.packetsLost), jitter: this._jitterDecoder.decode(input.jitter), localId: this._localIdDecoder.decode(input.localId), roundTripTime: this._roundTripTimeDecoder.decode(input.roundTripTime), totalRoundTripTime: this._totalRoundTripTimeDecoder.decode(input.totalRoundTripTime), fractionLost: this._fractionLostDecoder.decode(input.fractionLost), roundTripTimeMeasurements: this._roundTripTimeMeasurementsDecoder.decode(input.roundTripTimeMeasurements), attachments: this._attachmentsDecoder.decode(input.attachments), }; 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._transportIdDecoder.actualValue = sample.transportId; this._codecIdDecoder.actualValue = sample.codecId; this._packetsReceivedDecoder.actualValue = sample.packetsReceived; this._packetsLostDecoder.actualValue = sample.packetsLost; this._jitterDecoder.actualValue = sample.jitter; this._localIdDecoder.actualValue = sample.localId; this._roundTripTimeDecoder.actualValue = sample.roundTripTime; this._totalRoundTripTimeDecoder.actualValue = sample.totalRoundTripTime; this._fractionLostDecoder.actualValue = sample.fractionLost; this._roundTripTimeMeasurementsDecoder.actualValue = sample.roundTripTimeMeasurements; this._attachmentsDecoder.actualValue = sample.attachments; } } exports.RemoteInboundRtpDecoder = RemoteInboundRtpDecoder;