From f78fc697cd3bbfa3faa6ad0f439a24be2efcb935 Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Mon, 7 Jul 2025 10:40:28 +0200 Subject: [PATCH] Allow DataView as AllowSharedBufferSource --- package-lock.json | 4 ++-- package.json | 2 +- src/misc.ts | 11 +++++++---- src/sample.ts | 6 +----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index bf4ade0..becac23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mediabunny", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mediabunny", - "version": "1.0.0", + "version": "1.0.1", "license": "MPL-2.0", "dependencies": { "@types/dom-mediacapture-transform": "^0.1.11", diff --git a/package.json b/package.json index 66031b4..9a6e1b5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mediabunny", "author": "Vanilagy", - "version": "1.0.0", + "version": "1.0.1", "description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.", "type": "module", "main": "./dist/mediabunny.js", diff --git a/src/misc.ts b/src/misc.ts index 92c7321..4a76869 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -134,7 +134,9 @@ export const writeBits = (bytes: Uint8Array, start: number, end: number, value: }; export const toUint8Array = (source: AllowSharedBufferSource): Uint8Array => { - if (source instanceof ArrayBuffer) { + if (source instanceof Uint8Array) { + return source; + } else if (source instanceof ArrayBuffer) { return new Uint8Array(source); } else { return new Uint8Array(source.buffer, source.byteOffset, source.byteLength); @@ -142,7 +144,9 @@ export const toUint8Array = (source: AllowSharedBufferSource): Uint8Array => { }; export const toDataView = (source: AllowSharedBufferSource) => { - if (source instanceof ArrayBuffer) { + if (source instanceof DataView) { + return source; + } else if (source instanceof ArrayBuffer) { return new DataView(source); } else { return new DataView(source.buffer, source.byteOffset, source.byteLength); @@ -202,11 +206,10 @@ export const colorSpaceIsComplete = ( }; export const isAllowSharedBufferSource = (x: unknown) => { - // Quite a mouthful: return ( x instanceof ArrayBuffer || (typeof SharedArrayBuffer !== 'undefined' && x instanceof SharedArrayBuffer) - || (ArrayBuffer.isView(x) && !(x instanceof DataView)) + || ArrayBuffer.isView(x) ); }; diff --git a/src/sample.ts b/src/sample.ts index 62475f1..a1255a0 100644 --- a/src/sample.ts +++ b/src/sample.ts @@ -890,7 +890,6 @@ export class AudioSample { } return new AudioData({ - format: this.format, sampleRate: this.sampleRate, numberOfFrames: this.numberOfFrames, @@ -900,11 +899,9 @@ export class AudioSample { }); } else { const data = new ArrayBuffer(this.allocationSize({ planeIndex: 0, format: this.format })); - - this.copyTo(new DataView(data), { planeIndex: 0, format: this.format }); + this.copyTo(data, { planeIndex: 0, format: this.format }); return new AudioData({ - format: this.format, sampleRate: this.sampleRate, numberOfFrames: this.numberOfFrames, @@ -916,7 +913,6 @@ export class AudioSample { } } else { return new AudioData({ - format: this.format, sampleRate: this.sampleRate, numberOfFrames: this.numberOfFrames,