mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Update TypeScript, fix generic ArrayBufferView type errors, allow SharedArrayBuffer as input for BufferSource
This commit is contained in:
@@ -433,4 +433,12 @@ await textSource.add('00:00:00.000 --> 00:00:02.000\nHello there!\n\n');
|
||||
await textSource.add('00:00:02.500 --> 00:00:04.000\nChunky chunks.\n\n');
|
||||
```
|
||||
|
||||
The chunks have certain constraints: A cue must be fully contained within a chunk and cannot be split across multiple smaller chunks (although a chunk can contain multiple cues). Also, the WebVTT preamble must be added first and all at once.
|
||||
The chunks have certain constraints: A cue must be fully contained within a chunk and cannot be split across multiple smaller chunks (although a chunk can contain multiple cues). Also, the WebVTT preamble must be added first and all at once.
|
||||
|
||||
::: info
|
||||
For QuickTime to display WebVTT subtitles, it typically expects alignment information to be specified:
|
||||
```
|
||||
00:00:00.000 --> 00:00:02.000 align:center
|
||||
This is your last chance.
|
||||
```
|
||||
:::
|
||||
@@ -21,7 +21,7 @@ const context = canvas.getContext('2d', { alpha: false, desynchronized: true })!
|
||||
|
||||
const frameRate = 30;
|
||||
|
||||
const chunks: Uint8Array[] = [];
|
||||
const chunks: Uint8Array<ArrayBuffer>[] = [];
|
||||
let recording = false;
|
||||
let output: Output;
|
||||
let videoSource: CanvasSource;
|
||||
|
||||
@@ -97,7 +97,7 @@ const extractMetadata = (resource: File | string) => {
|
||||
'Lyrics': tags.lyrics,
|
||||
'Comment': tags.comment,
|
||||
'Images': tags.images?.map((image) => {
|
||||
const blob = new Blob([image.data], { type: image.mimeType });
|
||||
const blob = new Blob([image.data.slice()], { type: image.mimeType });
|
||||
const element = new Image();
|
||||
element.src = URL.createObjectURL(blob);
|
||||
|
||||
|
||||
Generated
+279
-456
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -70,7 +70,7 @@
|
||||
"@eslint/js": "^9.22.0",
|
||||
"@fontsource-variable/rubik": "^5.2.6",
|
||||
"@fontsource/dm-mono": "^5.2.6",
|
||||
"@microsoft/api-extractor": "^7.52.1",
|
||||
"@microsoft/api-extractor": "^7.55.1",
|
||||
"@stylistic/eslint-plugin": "^4.2.0",
|
||||
"@tailwindcss/vite": "^4.1.7",
|
||||
"@types/markdown-it-footnote": "^3.0.4",
|
||||
@@ -84,8 +84,8 @@
|
||||
"mermaid": "^11.6.0",
|
||||
"tailwindcss": "^4.1.7",
|
||||
"tsx": "^4.19.4",
|
||||
"typescript": "^5.8.2",
|
||||
"typescript-eslint": "^8.26.1",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.48.0",
|
||||
"vite": "^6.3.5",
|
||||
"vitepress": "^1.6.3",
|
||||
"vitepress-plugin-llms": "^1.5.1",
|
||||
|
||||
@@ -850,7 +850,7 @@ export const dOps = (trackData: IsobmffAudioTrackData) => {
|
||||
let inputSampleRate = trackData.info.sampleRate;
|
||||
let outputGain = 0;
|
||||
let channelMappingFamily = 0;
|
||||
let channelMappingTable = new Uint8Array(0);
|
||||
let channelMappingTable: Uint8Array<ArrayBufferLike> = new Uint8Array(0);
|
||||
|
||||
// Read preskip and from codec private data from the encoder
|
||||
// https://www.rfc-editor.org/rfc/rfc7845#section-5
|
||||
|
||||
+7
-7
@@ -157,20 +157,20 @@ export const writeBits = (bytes: Uint8Array, start: number, end: number, value:
|
||||
export const toUint8Array = (source: AllowSharedBufferSource): Uint8Array => {
|
||||
if (source.constructor === Uint8Array) { // We want a true Uint8Array, not something that extends it like Buffer
|
||||
return source;
|
||||
} else if (source instanceof ArrayBuffer) {
|
||||
return new Uint8Array(source);
|
||||
} else {
|
||||
} else if (ArrayBuffer.isView(source)) {
|
||||
return new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
||||
} else {
|
||||
return new Uint8Array(source);
|
||||
}
|
||||
};
|
||||
|
||||
export const toDataView = (source: AllowSharedBufferSource) => {
|
||||
export const toDataView = (source: AllowSharedBufferSource): DataView => {
|
||||
if (source.constructor === DataView) {
|
||||
return source;
|
||||
} else if (source instanceof ArrayBuffer) {
|
||||
return new DataView(source);
|
||||
} else {
|
||||
} else if (ArrayBuffer.isView(source)) {
|
||||
return new DataView(source.buffer, source.byteOffset, source.byteLength);
|
||||
} else {
|
||||
return new DataView(source);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+3
-1
@@ -1250,7 +1250,9 @@ export class AudioSample implements Disposable {
|
||||
numberOfFrames: this.numberOfFrames,
|
||||
numberOfChannels: this.numberOfChannels,
|
||||
timestamp: this.microsecondTimestamp,
|
||||
data: this._data,
|
||||
data: this._data.buffer instanceof ArrayBuffer
|
||||
? this._data.buffer
|
||||
: this._data.slice(), // In the case of SharedArrayBuffer, convert to ArrayBuffer
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+11
-4
@@ -102,10 +102,17 @@ export class BufferSource extends Source {
|
||||
/** @internal */
|
||||
_onreadCalled = false;
|
||||
|
||||
/** Creates a new {@link BufferSource} backed the specified `ArrayBuffer` or `ArrayBufferView`. */
|
||||
constructor(buffer: ArrayBuffer | ArrayBufferView) {
|
||||
if (!(buffer instanceof ArrayBuffer) && !ArrayBuffer.isView(buffer)) {
|
||||
throw new TypeError('buffer must be an ArrayBuffer or ArrayBufferView.');
|
||||
/**
|
||||
* Creates a new {@link BufferSource} backed by the specified `ArrayBuffer`, `SharedArrayBuffer`,
|
||||
* or `ArrayBufferView`.
|
||||
*/
|
||||
constructor(buffer: AllowSharedBufferSource) {
|
||||
if (
|
||||
!(buffer instanceof ArrayBuffer)
|
||||
&& !(typeof SharedArrayBuffer !== 'undefined' && buffer instanceof SharedArrayBuffer)
|
||||
&& !ArrayBuffer.isView(buffer)
|
||||
) {
|
||||
throw new TypeError('buffer must be an ArrayBuffer, SharedArrayBuffer, or ArrayBufferView.');
|
||||
}
|
||||
|
||||
super();
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ export type StreamTargetChunk = {
|
||||
/** The operation type. */
|
||||
type: 'write'; // This ensures automatic compatibility with FileSystemWritableFileStream
|
||||
/** The data to write. */
|
||||
data: Uint8Array;
|
||||
data: Uint8Array<ArrayBuffer>;
|
||||
/** The byte offset in the output file at which to write the data. */
|
||||
position: number;
|
||||
};
|
||||
|
||||
+2
-2
@@ -190,7 +190,7 @@ const MAX_CHUNKS_AT_ONCE = 2;
|
||||
interface Chunk {
|
||||
start: number;
|
||||
written: ChunkSection[];
|
||||
data: Uint8Array;
|
||||
data: Uint8Array<ArrayBuffer>;
|
||||
shouldFlush: boolean;
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ export class StreamTargetWriter extends Writer {
|
||||
const chunks: {
|
||||
start: number;
|
||||
size: number;
|
||||
data?: Uint8Array;
|
||||
data?: Uint8Array<ArrayBuffer>;
|
||||
}[] = [];
|
||||
const sorted = [...this.sections].sort((a, b) => a.start - b.start);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user