UNPKG

@observertc/samples-decoder

Version:

ObserveRTC Library for Decoding Samples

100 lines (99 loc) 4.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MediaSourceStatsDecoder = void 0; const utils_1 = require("./utils"); const utils_2 = require("./utils"); const Logger_1 = require("./Logger"); class MediaSourceStatsDecoder { constructor(id, _attachmentsDecoder) { this.id = id; this._attachmentsDecoder = _attachmentsDecoder; this._visited = false; this._actualValue = undefined; this._timestampDecoder = new utils_2.NumberToNumberDecoder(); this._idDecoder = new utils_2.StringToStringDecoder(); this._kindDecoder = new utils_2.StringToStringDecoder(); this._trackIdentifierDecoder = new utils_1.Uint8ArrayToStringDecoder(); this._audioLevelDecoder = new utils_2.NumberToNumberDecoder(); this._totalAudioEnergyDecoder = new utils_2.NumberToNumberDecoder(); this._totalSamplesDurationDecoder = new utils_2.NumberToNumberDecoder(); this._echoReturnLossDecoder = new utils_2.NumberToNumberDecoder(); this._echoReturnLossEnhancementDecoder = new utils_2.NumberToNumberDecoder(); this._widthDecoder = new utils_2.NumberToNumberDecoder(); this._heightDecoder = new utils_2.NumberToNumberDecoder(); this._framesDecoder = new utils_2.NumberToNumberDecoder(); this._framesPerSecondDecoder = new utils_2.NumberToNumberDecoder(); } get visited() { const result = this._visited; this._visited = false; return result; } reset() { this._timestampDecoder.reset(); this._idDecoder.reset(); this._kindDecoder.reset(); this._trackIdentifierDecoder.reset(); this._audioLevelDecoder.reset(); this._totalAudioEnergyDecoder.reset(); this._totalSamplesDurationDecoder.reset(); this._echoReturnLossDecoder.reset(); this._echoReturnLossEnhancementDecoder.reset(); this._widthDecoder.reset(); this._heightDecoder.reset(); this._framesDecoder.reset(); this._framesPerSecondDecoder.reset(); this._attachmentsDecoder.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 media source stats sample: missing timestamp or id"); return undefined; } this._actualValue = { timestamp, id, kind, trackIdentifier: this._trackIdentifierDecoder.decode(input.trackIdentifier), audioLevel: this._audioLevelDecoder.decode(input.audioLevel), totalAudioEnergy: this._totalAudioEnergyDecoder.decode(input.totalAudioEnergy), totalSamplesDuration: this._totalSamplesDurationDecoder.decode(input.totalSamplesDuration), echoReturnLoss: this._echoReturnLossDecoder.decode(input.echoReturnLoss), echoReturnLossEnhancement: this._echoReturnLossEnhancementDecoder.decode(input.echoReturnLossEnhancement), width: this._widthDecoder.decode(input.width), height: this._heightDecoder.decode(input.height), frames: this._framesDecoder.decode(input.frames), framesPerSecond: this._framesPerSecondDecoder.decode(input.framesPerSecond), 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._trackIdentifierDecoder.actualValue = sample.trackIdentifier; this._audioLevelDecoder.actualValue = sample.audioLevel; this._totalAudioEnergyDecoder.actualValue = sample.totalAudioEnergy; this._totalSamplesDurationDecoder.actualValue = sample.totalSamplesDuration; this._echoReturnLossDecoder.actualValue = sample.echoReturnLoss; this._echoReturnLossEnhancementDecoder.actualValue = sample.echoReturnLossEnhancement; this._widthDecoder.actualValue = sample.width; this._heightDecoder.actualValue = sample.height; this._framesDecoder.actualValue = sample.frames; this._framesPerSecondDecoder.actualValue = sample.framesPerSecond; this._attachmentsDecoder.actualValue = sample.attachments; } } exports.MediaSourceStatsDecoder = MediaSourceStatsDecoder;