diff --git a/.eslintrc.js b/.eslintrc.js index 18996bdd94e..51e7d12b98b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -79,6 +79,9 @@ module.exports = { }, overrides: [ { + parserOptions: { + project: ['./tsconfig.json'], + }, files: ['*.ts'], rules: { 'no-unused-vars': 0, diff --git a/src/controller/audio-stream-controller.ts b/src/controller/audio-stream-controller.ts index 43be1d2a9e2..71066e776d3 100644 --- a/src/controller/audio-stream-controller.ts +++ b/src/controller/audio-stream-controller.ts @@ -205,7 +205,7 @@ class AudioStreamController this.waitingData = null; this.waitingVideoCC = -1; this.state = State.FRAG_LOADING; - const payload = cache.flush(); + const payload = cache.flush().buffer; const data: FragLoadedData = { frag, part, diff --git a/src/controller/eme-controller.ts b/src/controller/eme-controller.ts index 8a2ed35080f..56da024059c 100644 --- a/src/controller/eme-controller.ts +++ b/src/controller/eme-controller.ts @@ -347,7 +347,7 @@ class EMEController implements ComponentAPI { this.generateRequestWithPreferredKeySession( keySessionContext, scheme, - decryptdata.pssh, + decryptdata.pssh.buffer, 'expired', ); } else { @@ -444,10 +444,13 @@ class EMEController implements ComponentAPI { decryptdata, }); const scheme = 'cenc'; + const initData = decryptdata.pssh + ? decryptdata.pssh?.buffer + : null; return this.generateRequestWithPreferredKeySession( keySessionContext, scheme, - decryptdata.pssh, + initData, 'playlist-key', ); }); @@ -541,7 +544,7 @@ class EMEController implements ComponentAPI { const json = bin2str(new Uint8Array(initData)); try { const sinf = base64Decode(JSON.parse(json).sinf); - const tenc = parseSinf(new Uint8Array(sinf)); + const tenc = parseSinf(sinf); if (!tenc) { return; } @@ -692,9 +695,8 @@ class EMEController implements ComponentAPI { ); } initDataType = mappedInitData.initDataType; - initData = context.decryptdata.pssh = mappedInitData.initData - ? new Uint8Array(mappedInitData.initData) - : null; + initData = mappedInitData.initData ? mappedInitData.initData : null; + context.decryptdata.pssh = initData ? new Uint8Array(initData) : null; } catch (error) { this.warn(error.message); if (this.hls?.config.debug) { diff --git a/src/controller/timeline-controller.ts b/src/controller/timeline-controller.ts index 4055b22bdb0..f5b21ab6fb0 100644 --- a/src/controller/timeline-controller.ts +++ b/src/controller/timeline-controller.ts @@ -560,7 +560,7 @@ export class TimelineController implements ComponentAPI { const hls = this.hls; // Parse the WebVTT file contents. const payloadWebVTT = frag.initSegment?.data - ? appendUint8Array(frag.initSegment.data, new Uint8Array(payload)) + ? appendUint8Array(frag.initSegment.data, new Uint8Array(payload)).buffer : payload; parseWebVTT( payloadWebVTT, diff --git a/src/crypt/decrypter.ts b/src/crypt/decrypter.ts index ada612153dc..9c32acf99cb 100644 --- a/src/crypt/decrypter.ts +++ b/src/crypt/decrypter.ts @@ -85,7 +85,8 @@ export default class Decrypter { ): Promise { if (this.useSoftware) { return new Promise((resolve, reject) => { - this.softwareDecrypt(new Uint8Array(data), key, iv); + const dataView = ArrayBuffer.isView(data) ? data : new Uint8Array(data); + this.softwareDecrypt(dataView, key, iv); const decryptResult = this.flush(); if (decryptResult) { resolve(decryptResult.buffer); diff --git a/src/demux/chunk-cache.ts b/src/demux/chunk-cache.ts index 28f6da55bbe..dcaf691f09f 100644 --- a/src/demux/chunk-cache.ts +++ b/src/demux/chunk-cache.ts @@ -9,7 +9,7 @@ export default class ChunkCache { flush(): Uint8Array { const { chunks, dataLength } = this; - let result; + let result: Uint8Array; if (!chunks.length) { return new Uint8Array(0); } else if (chunks.length === 1) { diff --git a/src/demux/transmuxer.ts b/src/demux/transmuxer.ts index 62f7a19fe2c..2dac3e81574 100644 --- a/src/demux/transmuxer.ts +++ b/src/demux/transmuxer.ts @@ -127,7 +127,8 @@ export default class Transmuxer { // For Low-Latency HLS Parts, decrypt in place, since part parsing is expected on push progress const loadingParts = chunkMeta.part > -1; if (loadingParts) { - decryptedData = decrypter.flush(); + const data = decrypter.flush(); + decryptedData = data ? data.buffer : data; } if (!decryptedData) { stats.executeEnd = now(); @@ -231,7 +232,7 @@ export default class Transmuxer { if (decryptedData) { // Push always returns a TransmuxerResult if decryptdata is null transmuxResults.push( - this.push(decryptedData, null, chunkMeta) as TransmuxerResult, + this.push(decryptedData.buffer, null, chunkMeta) as TransmuxerResult, ); } } diff --git a/src/types/buffer.ts b/src/types/buffer.ts index 15182c46666..7490c4d04a6 100644 --- a/src/types/buffer.ts +++ b/src/types/buffer.ts @@ -1,3 +1,12 @@ +declare global { + interface ArrayBuffer { + ' buffer_kind'?: 'array'; + } + interface Uint8Array { + ' buffer_kind'?: 'uint8'; + } +} + export type SourceBufferName = 'video' | 'audio' | 'audiovideo'; // eslint-disable-next-line no-restricted-globals diff --git a/src/utils/fetch-loader.ts b/src/utils/fetch-loader.ts index 6e038d76038..10d9ed7a261 100644 --- a/src/utils/fetch-loader.ts +++ b/src/utils/fetch-loader.ts @@ -233,7 +233,7 @@ class FetchLoader implements Loader { .then((data) => { if (data.done) { if (chunkCache.dataLength) { - onProgress(stats, context, chunkCache.flush(), response); + onProgress(stats, context, chunkCache.flush().buffer, response); } return Promise.resolve(new ArrayBuffer(0)); @@ -247,12 +247,12 @@ class FetchLoader implements Loader { chunkCache.push(chunk); if (chunkCache.dataLength >= highWaterMark) { // flush in order to join the typed arrays - onProgress(stats, context, chunkCache.flush(), response); + onProgress(stats, context, chunkCache.flush().buffer, response); } } else { // If there's nothing cached already, and the chache is large enough // just emit the progress event - onProgress(stats, context, chunk, response); + onProgress(stats, context, chunk.buffer, response); } return pump(); }) diff --git a/tests/unit/demuxer/transmuxer.ts b/tests/unit/demuxer/transmuxer.ts index f13518ae0c6..07572eb5e2a 100644 --- a/tests/unit/demuxer/transmuxer.ts +++ b/tests/unit/demuxer/transmuxer.ts @@ -218,7 +218,7 @@ describe('TransmuxerInterface tests', function () { newFrag.level = 2; newFrag.start = 1000; const part = null; - const data = new Uint8Array(new ArrayBuffer(8)); + const data = new ArrayBuffer(8); const initSegmentData = new Uint8Array(0); const audioCodec = ''; const videoCodec = '';