@observertc/samples-decoder
Version:
ObserveRTC Library for Decoding Samples
99 lines (98 loc) • 4.77 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoteOutboundRtpDecoder = void 0;
const utils_1 = require("./utils");
const Logger_1 = require("./Logger");
class RemoteOutboundRtpDecoder {
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._packetsSentDecoder = new utils_1.NumberToNumberDecoder();
this._bytesSentDecoder = new utils_1.BigIntToNumberDecoder();
this._localIdDecoder = new utils_1.StringToStringDecoder();
this._remoteTimestampDecoder = new utils_1.NumberToNumberDecoder();
this._reportsSentDecoder = new utils_1.NumberToNumberDecoder();
this._roundTripTimeDecoder = new utils_1.NumberToNumberDecoder();
this._totalRoundTripTimeDecoder = 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._packetsSentDecoder.reset();
this._bytesSentDecoder.reset();
this._localIdDecoder.reset();
this._remoteTimestampDecoder.reset();
this._reportsSentDecoder.reset();
this._roundTripTimeDecoder.reset();
this._totalRoundTripTimeDecoder.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 outbound RTP sample: missing timestamp or id or kind", input);
return undefined;
}
this._actualValue = {
ssrc: this.ssrc,
timestamp,
id,
kind,
transportId: this._transportIdDecoder.decode(input.transportId),
codecId: this._codecIdDecoder.decode(input.codecId),
packetsSent: this._packetsSentDecoder.decode(input.packetsSent),
bytesSent: this._bytesSentDecoder.decode(input.bytesSent),
localId: this._localIdDecoder.decode(input.localId),
remoteTimestamp: this._remoteTimestampDecoder.decode(input.remoteTimestamp),
reportsSent: this._reportsSentDecoder.decode(input.reportsSent),
roundTripTime: this._roundTripTimeDecoder.decode(input.roundTripTime),
totalRoundTripTime: this._totalRoundTripTimeDecoder.decode(input.totalRoundTripTime),
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._packetsSentDecoder.actualValue = sample.packetsSent;
this._bytesSentDecoder.actualValue = sample.bytesSent;
this._localIdDecoder.actualValue = sample.localId;
this._remoteTimestampDecoder.actualValue = sample.remoteTimestamp;
this._reportsSentDecoder.actualValue = sample.reportsSent;
this._roundTripTimeDecoder.actualValue = sample.roundTripTime;
this._totalRoundTripTimeDecoder.actualValue = sample.totalRoundTripTime;
this._roundTripTimeMeasurementsDecoder.actualValue = sample.roundTripTimeMeasurements;
this._attachmentsDecoder.actualValue = sample.attachments;
}
}
exports.RemoteOutboundRtpDecoder = RemoteOutboundRtpDecoder;