UNPKG

rtp.js

Version:

RTP stack for Node.js and browser written in TypeScript

91 lines (90 loc) 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseExtendedReportChunk = parseExtendedReportChunk; exports.createExtendedReportRunLengthChunk = createExtendedReportRunLengthChunk; exports.createExtendedReportBitVectorChunk = createExtendedReportBitVectorChunk; const bitOps_1 = require("../../../utils/bitOps"); /** * Parse given 2 bytes number as a Extended Report chunk. * * @category RTCP Extended Reports * * @see * - [RFC 3611 section 4.1](https://datatracker.ietf.org/doc/html/rfc3611#section-4.1) */ function parseExtendedReportChunk(chunk) { if (chunk < 0 || chunk > 0xffff) { throw new TypeError('invalid chunk value'); } if (chunk === 0) { return { chunkType: 'terminating-null' }; } // Bit Vector Chunk. if ((0, bitOps_1.readBit)({ value: chunk, bit: 15 })) { return { chunkType: 'bit-vector', bitVector: chunk & 0b0111111111111111, }; } // Run Length Chunk. else { return { chunkType: 'run-length', runType: (0, bitOps_1.readBit)({ value: chunk, bit: 14 }) ? 'ones' : 'zeros', runLength: chunk & 0b0011111111111111, }; } } /** * Create a Run Length Chunk and return a 2 bytes number representing it. * * ```text * 0 1 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |C|R| run length | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ``` * * @category RTCP Extended Reports * * @see * - [RFC 3611 section 4.1.1](https://datatracker.ietf.org/doc/html/rfc3611#section-4.1.1) */ function createExtendedReportRunLengthChunk(runType, runLength) { if (runLength < 0 || runLength > 16383) { throw new TypeError('invalid run length value'); } let chunk = runLength; chunk = (0, bitOps_1.writeBit)({ value: chunk, bit: 15, flag: false }); chunk = (0, bitOps_1.writeBit)({ value: chunk, bit: 14, flag: runType === 'ones' ? true : false, }); return chunk; } /** * Create a Bit Vector Chunk and return a 2 bytes number representing it. * * ```text * 0 1 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * |C| bit vector | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ``` * * @category RTCP Extended Reports * * @see * - [RFC 3611 section 4.1.2](https://datatracker.ietf.org/doc/html/rfc3611#section-4.1.2) */ function createExtendedReportBitVectorChunk(bitVector) { if (bitVector < 0 || bitVector > 32767) { throw new TypeError('invalid bit vector value'); } let chunk = bitVector; chunk = (0, bitOps_1.writeBit)({ value: chunk, bit: 15, flag: true }); return chunk; }