@observertc/samples-decoder
Version:
ObserveRTC Library for Decoding Samples
78 lines (77 loc) • 3.64 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MediaPlayoutStatsDecoder = void 0;
const utils_1 = require("./utils");
const Logger_1 = require("./Logger");
class MediaPlayoutStatsDecoder {
constructor(id, _attachmentsDecoder) {
this.id = id;
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._synthesizedSamplesDurationDecoder = new utils_1.NumberToNumberDecoder();
this._synthesizedSamplesEventsDecoder = new utils_1.NumberToNumberDecoder();
this._totalSamplesDurationDecoder = new utils_1.NumberToNumberDecoder();
this._totalPlayoutDelayDecoder = new utils_1.NumberToNumberDecoder();
this._totalSamplesCountDecoder = 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._synthesizedSamplesDurationDecoder.reset();
this._synthesizedSamplesEventsDecoder.reset();
this._totalSamplesDurationDecoder.reset();
this._totalPlayoutDelayDecoder.reset();
this._totalSamplesCountDecoder.reset();
this._attachmentsDecoder.reset();
}
decode(input) {
this._visited = true;
const timestamp = this._timestampDecoder.decode(input.timestamp);
const kind = this._kindDecoder.decode(input.kind);
if (!timestamp || kind === undefined) {
Logger_1.logger.warn("Invalid media playout stats sample: missing timestamp or id");
return undefined;
}
this._actualValue = {
timestamp,
id: this.id,
kind,
synthesizedSamplesDuration: this._synthesizedSamplesDurationDecoder.decode(input.synthesizedSamplesDuration),
synthesizedSamplesEvents: this._synthesizedSamplesEventsDecoder.decode(input.synthesizedSamplesEvents),
totalSamplesDuration: this._totalSamplesDurationDecoder.decode(input.totalSamplesDuration),
totalPlayoutDelay: this._totalPlayoutDelayDecoder.decode(input.totalPlayoutDelay),
totalSamplesCount: this._totalSamplesCountDecoder.decode(input.totalSamplesCount),
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._synthesizedSamplesDurationDecoder.actualValue = sample.synthesizedSamplesDuration;
this._synthesizedSamplesEventsDecoder.actualValue = sample.synthesizedSamplesEvents;
this._totalSamplesDurationDecoder.actualValue = sample.totalSamplesDuration;
this._totalPlayoutDelayDecoder.actualValue = sample.totalPlayoutDelay;
this._totalSamplesCountDecoder.actualValue = sample.totalSamplesCount;
this._attachmentsDecoder.actualValue = sample.attachments;
}
}
exports.MediaPlayoutStatsDecoder = MediaPlayoutStatsDecoder;