mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
Fix flaky FLAC metadata reading
This commit is contained in:
Generated
+6
-6
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "mediabunny",
|
"name": "mediabunny",
|
||||||
"version": "1.17.2",
|
"version": "1.17.3",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "mediabunny",
|
"name": "mediabunny",
|
||||||
"version": "1.17.2",
|
"version": "1.17.3",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
@@ -7749,9 +7749,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mediabunny": {
|
"node_modules/mediabunny": {
|
||||||
"version": "1.17.1",
|
"version": "1.17.2",
|
||||||
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.17.1.tgz",
|
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.17.2.tgz",
|
||||||
"integrity": "sha512-2kLYbcv2NufwZ05AQXKjik54h4LUBQ1XBNoaVCOXU49pGXZzDq0krhJI77c4056QLH3QDPZ9DgYXosi92iEA1g==",
|
"integrity": "sha512-I7l/WDv7howETh0Vhc9J8Y0XZ1Z1qUpUEcud05Eqf/MeaaOT8FGb744sTXN6U4Rk5ZxFYRz7g3JHcA1XvsFkWg==",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"peer": true,
|
"peer": true,
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
@@ -12242,7 +12242,7 @@
|
|||||||
},
|
},
|
||||||
"packages/mp3-encoder": {
|
"packages/mp3-encoder": {
|
||||||
"name": "@mediabunny/mp3-encoder",
|
"name": "@mediabunny/mp3-encoder",
|
||||||
"version": "1.17.2",
|
"version": "1.17.3",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/emscripten": "^1.40.1"
|
"@types/emscripten": "^1.40.1"
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "mediabunny",
|
"name": "mediabunny",
|
||||||
"author": "Vanilagy",
|
"author": "Vanilagy",
|
||||||
"version": "1.17.2",
|
"version": "1.17.3",
|
||||||
"description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.",
|
"description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@mediabunny/mp3-encoder",
|
"name": "@mediabunny/mp3-encoder",
|
||||||
"author": "Vanilagy",
|
"author": "Vanilagy",
|
||||||
"version": "1.17.2",
|
"version": "1.17.3",
|
||||||
"description": "MP3 encoder extension for Mediabunny, based on LAME.",
|
"description": "MP3 encoder extension for Mediabunny, based on LAME.",
|
||||||
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||||
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||||
|
|||||||
@@ -115,7 +115,8 @@ export class FlacDemuxer extends Demuxer {
|
|||||||
this.reader.fileSize === null
|
this.reader.fileSize === null
|
||||||
|| currentPos < this.reader.fileSize
|
|| currentPos < this.reader.fileSize
|
||||||
) {
|
) {
|
||||||
const sizeSlice = await this.reader.requestSlice(currentPos, 4);
|
let sizeSlice = this.reader.requestSlice(currentPos, 4);
|
||||||
|
if (sizeSlice instanceof Promise) sizeSlice = await sizeSlice;
|
||||||
currentPos += 4;
|
currentPos += 4;
|
||||||
|
|
||||||
if (sizeSlice === null) {
|
if (sizeSlice === null) {
|
||||||
@@ -135,10 +136,12 @@ export class FlacDemuxer extends Demuxer {
|
|||||||
case FlacBlockType.STREAMINFO: {
|
case FlacBlockType.STREAMINFO: {
|
||||||
// Parse streaminfo block
|
// Parse streaminfo block
|
||||||
// https://www.rfc-editor.org/rfc/rfc9639.html#section-8.2
|
// https://www.rfc-editor.org/rfc/rfc9639.html#section-8.2
|
||||||
const streamInfoBlock = await this.reader.requestSlice(
|
let streamInfoBlock = this.reader.requestSlice(
|
||||||
currentPos,
|
currentPos,
|
||||||
size,
|
size,
|
||||||
);
|
);
|
||||||
|
if (streamInfoBlock instanceof Promise) streamInfoBlock = await streamInfoBlock;
|
||||||
|
|
||||||
assert(streamInfoBlock);
|
assert(streamInfoBlock);
|
||||||
if (streamInfoBlock === null) {
|
if (streamInfoBlock === null) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -192,17 +195,16 @@ export class FlacDemuxer extends Demuxer {
|
|||||||
case FlacBlockType.VORBIS_COMMENT: {
|
case FlacBlockType.VORBIS_COMMENT: {
|
||||||
// Parse vorbis comment block
|
// Parse vorbis comment block
|
||||||
// https://www.rfc-editor.org/rfc/rfc9639.html#name-vorbis-comment
|
// https://www.rfc-editor.org/rfc/rfc9639.html#name-vorbis-comment
|
||||||
const vorbisCommentBlock = await this.reader.requestSlice(
|
let vorbisCommentBlock = this.reader.requestSlice(
|
||||||
currentPos,
|
currentPos,
|
||||||
size,
|
size,
|
||||||
);
|
);
|
||||||
|
if (vorbisCommentBlock instanceof Promise) vorbisCommentBlock = await vorbisCommentBlock;
|
||||||
|
|
||||||
assert(vorbisCommentBlock);
|
assert(vorbisCommentBlock);
|
||||||
|
|
||||||
readVorbisComments(
|
readVorbisComments(
|
||||||
vorbisCommentBlock.bytes.subarray(
|
readBytes(vorbisCommentBlock, size),
|
||||||
vorbisCommentBlock.start,
|
|
||||||
vorbisCommentBlock.end,
|
|
||||||
),
|
|
||||||
this.metadataTags,
|
this.metadataTags,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -211,10 +213,11 @@ export class FlacDemuxer extends Demuxer {
|
|||||||
case FlacBlockType.PICTURE: {
|
case FlacBlockType.PICTURE: {
|
||||||
// Parse picture block
|
// Parse picture block
|
||||||
// https://www.rfc-editor.org/rfc/rfc9639.html#name-picture
|
// https://www.rfc-editor.org/rfc/rfc9639.html#name-picture
|
||||||
const pictureBlock = await this.reader.requestSlice(
|
let pictureBlock = this.reader.requestSlice(
|
||||||
currentPos,
|
currentPos,
|
||||||
size,
|
size,
|
||||||
);
|
);
|
||||||
|
if (pictureBlock instanceof Promise) pictureBlock = await pictureBlock;
|
||||||
|
|
||||||
assert(pictureBlock);
|
assert(pictureBlock);
|
||||||
const pictureType = readU32Be(pictureBlock);
|
const pictureType = readU32Be(pictureBlock);
|
||||||
@@ -654,10 +657,11 @@ class FlacAudioTrackBacking implements InputAudioTrackBacking {
|
|||||||
if (options.metadataOnly) {
|
if (options.metadataOnly) {
|
||||||
data = PLACEHOLDER_DATA;
|
data = PLACEHOLDER_DATA;
|
||||||
} else {
|
} else {
|
||||||
const slice = await this.demuxer.reader.requestSlice(
|
let slice = this.demuxer.reader.requestSlice(
|
||||||
rawSample.byteOffset,
|
rawSample.byteOffset,
|
||||||
rawSample.byteSize,
|
rawSample.byteSize,
|
||||||
);
|
);
|
||||||
|
if (slice instanceof Promise) slice = await slice;
|
||||||
|
|
||||||
if (!slice) {
|
if (!slice) {
|
||||||
return null; // Data didn't fit into the rest of the file
|
return null; // Data didn't fit into the rest of the file
|
||||||
|
|||||||
@@ -80,13 +80,19 @@ export class Reader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class FileSlice {
|
export class FileSlice {
|
||||||
|
/** The current position in the backing buffer. Do not modify directly, prefer `.skip()` instead. */
|
||||||
bufferPos: number;
|
bufferPos: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
/** The underlying bytes backing this slice. Avoid using this directly and prefer reader functions instead. */
|
||||||
public readonly bytes: Uint8Array,
|
public readonly bytes: Uint8Array,
|
||||||
|
/** A view into the bytes backing this slice. Avoid using this directly and prefer reader functions instead. */
|
||||||
public readonly view: DataView,
|
public readonly view: DataView,
|
||||||
|
/** The offset in "file bytes" at which `bytes` begins in the file. */
|
||||||
private readonly offset: number,
|
private readonly offset: number,
|
||||||
|
/** The offset in "file bytes" where this slice begins. */
|
||||||
public readonly start: number,
|
public readonly start: number,
|
||||||
|
/** The offset in "file bytes" where this slice ends (exclusive). */
|
||||||
public readonly end: number,
|
public readonly end: number,
|
||||||
) {
|
) {
|
||||||
this.bufferPos = start - offset;
|
this.bufferPos = start - offset;
|
||||||
@@ -118,6 +124,7 @@ export class FileSlice {
|
|||||||
this.bufferPos += byteCount;
|
this.bufferPos += byteCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Creates a new subslice of this slice whose byte range must be contained within this slice. */
|
||||||
slice(filePos: number, length = this.end - filePos) {
|
slice(filePos: number, length = this.end - filePos) {
|
||||||
if (filePos < this.start || filePos + length > this.end) {
|
if (filePos < this.start || filePos + length > this.end) {
|
||||||
throw new RangeError('Slicing outside of original slice.');
|
throw new RangeError('Slicing outside of original slice.');
|
||||||
|
|||||||
Reference in New Issue
Block a user