UNPKG

rtp.js

Version:

RTP stack for Node.js and browser written in TypeScript

116 lines (115 loc) 4.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RrtExtendedReport = void 0; const ExtendedReport_1 = require("./ExtendedReport"); // Common header + NTP timestamp. const RRT_EXTENDED_REPORT_LENGTH = ExtendedReport_1.COMMON_HEADER_LENGTH + 8; /** * Receiver Reference Time Extended Report. * * ```text * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | BT=4 | reserved | block length = 2 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | NTP timestamp, most significant word | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | NTP timestamp, least significant word | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ``` * * @category RTCP Extended Reports * * @see * - [RFC 3611 section 4.4](https://datatracker.ietf.org/doc/html/rfc3611#section-4.4) */ class RrtExtendedReport extends ExtendedReport_1.ExtendedReport { /** * @param view - If given it will be parsed. Otherwise an empty Receiver * Reference Time Extended Report will be created. */ constructor(view) { super(ExtendedReport_1.ExtendedReportType.RRT, view); if (!this.view) { this.view = new DataView(new ArrayBuffer(RRT_EXTENDED_REPORT_LENGTH)); // Write report type. this.writeCommonHeader(); return; } if (this.view.byteLength !== RRT_EXTENDED_REPORT_LENGTH) { throw new TypeError('wrong byte length for a Receiver Reference Time Extended Report'); } } /** * Dump Receiver Reference Time Extended Report info. */ dump() { return { ...super.dump(), ntpSeq: this.getNtpSeconds(), ntpFraction: this.getNtpFraction(), }; } /** * @inheritDoc */ getByteLength() { return RRT_EXTENDED_REPORT_LENGTH; } /** * @inheritDoc */ serialize(buffer, byteOffset) { const view = this.serializeBase(buffer, byteOffset); const uint8Array = new Uint8Array(view.buffer, view.byteOffset, view.byteLength); // Position relative to the DataView byte offset. let pos = 0; // Move to the fixed header fields after the common header. pos += ExtendedReport_1.COMMON_HEADER_LENGTH; // Copy the rest of the Extended Report into the new buffer. uint8Array.set(new Uint8Array(this.view.buffer, this.view.byteOffset + pos, RRT_EXTENDED_REPORT_LENGTH - ExtendedReport_1.COMMON_HEADER_LENGTH), pos); // Move to the end. pos += RRT_EXTENDED_REPORT_LENGTH - ExtendedReport_1.COMMON_HEADER_LENGTH; if (pos !== view.byteLength) { throw new RangeError(`filled length (${pos} bytes) does not match the available buffer size (${view.byteLength} bytes)`); } // Update DataView. this.view = view; this.setSerializationNeeded(false); } /** * @inheritDoc */ clone(buffer, byteOffset, serializationBuffer, serializationByteOffset) { const view = this.cloneInternal(buffer, byteOffset, serializationBuffer, serializationByteOffset); return new RrtExtendedReport(view); } /** * Get NTP seconds. */ getNtpSeconds() { return this.view.getUint32(4); } /** * Set NTP seconds. */ setNtpSeconds(seconds) { this.view.setUint32(4, seconds); this.setSerializationNeeded(true); } /** * Get NTP fraction. */ getNtpFraction() { return this.view.getUint32(8); } /** * Set NTP fraction. */ setNtpFraction(fraction) { this.view.setUint32(8, fraction); this.setSerializationNeeded(true); } } exports.RrtExtendedReport = RrtExtendedReport;