mediabunny 1.55.4 → 1.55.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles/mediabunny.cjs +119 -61
- package/dist/bundles/mediabunny.min.cjs +9 -9
- package/dist/bundles/mediabunny.min.mjs +9 -9
- package/dist/bundles/mediabunny.mjs +119 -61
- package/dist/bundles/mediabunny.node.cjs +119 -61
- package/dist/modules/src/input-track.d.ts.map +1 -1
- package/dist/modules/src/input-track.js +2 -2
- package/dist/modules/src/output-format.d.ts.map +1 -1
- package/dist/modules/src/output-format.js +4 -4
- package/dist/modules/src/sample.d.ts.map +1 -1
- package/dist/modules/src/sample.js +102 -65
- package/dist/modules/src/source.d.ts.map +1 -1
- package/dist/modules/src/source.js +26 -1
- package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/input-track.ts +11 -2
- package/src/output-format.ts +4 -4
- package/src/sample.ts +113 -68
- package/src/source.ts +36 -4
|
@@ -17063,6 +17063,10 @@ var Mediabunny = (() => {
|
|
|
17063
17063
|
_dispose() {
|
|
17064
17064
|
}
|
|
17065
17065
|
};
|
|
17066
|
+
var blobReaderRegistry = typeof FinalizationRegistry !== "undefined" ? new FinalizationRegistry((reader) => {
|
|
17067
|
+
void reader.cancel().catch(() => {
|
|
17068
|
+
});
|
|
17069
|
+
}) : null;
|
|
17066
17070
|
var BlobSource = class extends Source {
|
|
17067
17071
|
/**
|
|
17068
17072
|
* Creates a new {@link BlobSource} backed by the specified
|
|
@@ -17090,6 +17094,15 @@ var Mediabunny = (() => {
|
|
|
17090
17094
|
maxCacheSize: options.maxCacheSize ?? 8 * 2 ** 20,
|
|
17091
17095
|
maxWorkerCount: 4,
|
|
17092
17096
|
runWorker: this._runWorker.bind(this),
|
|
17097
|
+
onIdleWorkerRemoved: (worker) => {
|
|
17098
|
+
const reader = this._readers.get(worker);
|
|
17099
|
+
if (reader) {
|
|
17100
|
+
this._readers.delete(worker);
|
|
17101
|
+
blobReaderRegistry?.unregister(worker);
|
|
17102
|
+
void reader.cancel().catch(() => {
|
|
17103
|
+
});
|
|
17104
|
+
}
|
|
17105
|
+
},
|
|
17093
17106
|
prefetchProfile: PREFETCH_PROFILES.fileSystem
|
|
17094
17107
|
});
|
|
17095
17108
|
this._orchestrator.fileSize = blob.size;
|
|
@@ -17110,6 +17123,7 @@ var Mediabunny = (() => {
|
|
|
17110
17123
|
if ("stream" in this._blob && !isWebKit() && this._options.useStreamReader !== false) {
|
|
17111
17124
|
const slice = this._blob.slice(worker.currentPos);
|
|
17112
17125
|
reader = slice.stream().getReader();
|
|
17126
|
+
blobReaderRegistry?.register(worker, reader, worker);
|
|
17113
17127
|
} else {
|
|
17114
17128
|
reader = null;
|
|
17115
17129
|
}
|
|
@@ -18149,6 +18163,7 @@ var Mediabunny = (() => {
|
|
|
18149
18163
|
assert(oldestIndex !== null);
|
|
18150
18164
|
assert(oldestWorker.pendingSlices.length === 0);
|
|
18151
18165
|
this.workers.splice(oldestIndex, 1);
|
|
18166
|
+
this.options.onIdleWorkerRemoved?.(oldestWorker);
|
|
18152
18167
|
} else {
|
|
18153
18168
|
return null;
|
|
18154
18169
|
}
|
|
@@ -18265,6 +18280,7 @@ var Mediabunny = (() => {
|
|
|
18265
18280
|
// These should typically be equal when the worker's idle
|
|
18266
18281
|
)) {
|
|
18267
18282
|
this.workers.splice(i, 1);
|
|
18283
|
+
this.options.onIdleWorkerRemoved?.(otherWorker);
|
|
18268
18284
|
i--;
|
|
18269
18285
|
}
|
|
18270
18286
|
}
|
|
@@ -18319,6 +18335,7 @@ var Mediabunny = (() => {
|
|
|
18319
18335
|
assert(index !== -1);
|
|
18320
18336
|
worker.running = false;
|
|
18321
18337
|
this.workers.splice(index, 1);
|
|
18338
|
+
this.options.onIdleWorkerRemoved?.(worker);
|
|
18322
18339
|
if (this.fileSize === null) {
|
|
18323
18340
|
this.supplyFileSize(worker.currentPos);
|
|
18324
18341
|
}
|
|
@@ -18399,6 +18416,9 @@ var Mediabunny = (() => {
|
|
|
18399
18416
|
}
|
|
18400
18417
|
worker.pendingSlices.length = 0;
|
|
18401
18418
|
worker.aborted = true;
|
|
18419
|
+
if (!worker.running) {
|
|
18420
|
+
this.options.onIdleWorkerRemoved?.(worker);
|
|
18421
|
+
}
|
|
18402
18422
|
}
|
|
18403
18423
|
for (const queuedRead of this.queuedReads) {
|
|
18404
18424
|
for (const slice of queuedRead.pendingSlices) {
|
|
@@ -21903,7 +21923,7 @@ var Mediabunny = (() => {
|
|
|
21903
21923
|
}
|
|
21904
21924
|
const { format, frameCount: optFrameCount, frameOffset: optFrameOffset } = options;
|
|
21905
21925
|
let { planeIndex } = options;
|
|
21906
|
-
|
|
21926
|
+
let srcFormat = this.format;
|
|
21907
21927
|
const destFormat = format ?? this.format;
|
|
21908
21928
|
if (!destFormat) throw new Error("Destination format not determined");
|
|
21909
21929
|
const numFrames = this.numberOfFrames;
|
|
@@ -21943,75 +21963,113 @@ var Mediabunny = (() => {
|
|
|
21943
21963
|
frameOffset,
|
|
21944
21964
|
copyFrameCount
|
|
21945
21965
|
);
|
|
21966
|
+
return;
|
|
21946
21967
|
} else {
|
|
21947
|
-
|
|
21948
|
-
|
|
21949
|
-
|
|
21950
|
-
|
|
21951
|
-
|
|
21952
|
-
|
|
21968
|
+
try {
|
|
21969
|
+
this._data.copyTo(destination, {
|
|
21970
|
+
planeIndex,
|
|
21971
|
+
frameOffset,
|
|
21972
|
+
frameCount: copyFrameCount,
|
|
21973
|
+
format: destFormat
|
|
21974
|
+
});
|
|
21975
|
+
return;
|
|
21976
|
+
} catch (error) {
|
|
21977
|
+
if (destFormat === "f32-planar") {
|
|
21978
|
+
throw error;
|
|
21979
|
+
}
|
|
21980
|
+
srcFormat = "f32-planar";
|
|
21981
|
+
}
|
|
21953
21982
|
}
|
|
21954
|
-
}
|
|
21955
|
-
|
|
21956
|
-
|
|
21957
|
-
|
|
21958
|
-
|
|
21959
|
-
|
|
21960
|
-
|
|
21961
|
-
|
|
21962
|
-
|
|
21963
|
-
|
|
21964
|
-
|
|
21965
|
-
|
|
21966
|
-
|
|
21967
|
-
|
|
21968
|
-
|
|
21969
|
-
|
|
21983
|
+
}
|
|
21984
|
+
const readFn = getReadFunction(srcFormat);
|
|
21985
|
+
const srcBytesPerSample = getBytesPerSample(srcFormat);
|
|
21986
|
+
const srcIsPlanar = formatIsPlanar(srcFormat);
|
|
21987
|
+
let uint8Data;
|
|
21988
|
+
if (this._data instanceof AudioSampleResource) {
|
|
21989
|
+
const getDataPlaneValidated = (index) => {
|
|
21990
|
+
const result = this._data.getDataPlane(index);
|
|
21991
|
+
if (!(result instanceof Uint8Array)) {
|
|
21992
|
+
throw new TypeError("getDataPlane() must return a Uint8Array.");
|
|
21993
|
+
}
|
|
21994
|
+
const expectedSize = numFrames * srcBytesPerSample * (srcIsPlanar ? 1 : numChannels);
|
|
21995
|
+
if (result.byteLength !== expectedSize) {
|
|
21996
|
+
throw new TypeError(
|
|
21997
|
+
`Data plane ${index} has invalid size. Expected exactly ${expectedSize} bytes, got ${result.byteLength} bytes.`
|
|
21998
|
+
);
|
|
21999
|
+
}
|
|
22000
|
+
return result;
|
|
22001
|
+
};
|
|
22002
|
+
if (srcIsPlanar) {
|
|
22003
|
+
if (destIsPlanar) {
|
|
22004
|
+
uint8Data = getDataPlaneValidated(planeIndex);
|
|
22005
|
+
planeIndex = 0;
|
|
22006
|
+
} else {
|
|
22007
|
+
uint8Data = new Uint8Array(numFrames * srcBytesPerSample * numChannels);
|
|
22008
|
+
for (let ch = 0; ch < numChannels; ch++) {
|
|
22009
|
+
const planeData = getDataPlaneValidated(ch);
|
|
22010
|
+
uint8Data.set(planeData, ch * numFrames * srcBytesPerSample);
|
|
21970
22011
|
}
|
|
21971
|
-
|
|
21972
|
-
|
|
21973
|
-
|
|
21974
|
-
|
|
21975
|
-
|
|
21976
|
-
|
|
21977
|
-
|
|
21978
|
-
|
|
21979
|
-
|
|
21980
|
-
|
|
21981
|
-
|
|
22012
|
+
}
|
|
22013
|
+
} else {
|
|
22014
|
+
uint8Data = getDataPlaneValidated(0);
|
|
22015
|
+
}
|
|
22016
|
+
} else if (this._data instanceof Uint8Array) {
|
|
22017
|
+
uint8Data = this._data;
|
|
22018
|
+
} else {
|
|
22019
|
+
assert(srcFormat === "f32-planar");
|
|
22020
|
+
if (destIsPlanar) {
|
|
22021
|
+
uint8Data = new Uint8Array(this._data.allocationSize({
|
|
22022
|
+
format: "f32-planar",
|
|
22023
|
+
planeIndex
|
|
22024
|
+
}));
|
|
22025
|
+
this._data.copyTo(uint8Data, {
|
|
22026
|
+
format: "f32-planar",
|
|
22027
|
+
planeIndex
|
|
22028
|
+
});
|
|
22029
|
+
planeIndex = 0;
|
|
22030
|
+
} else {
|
|
22031
|
+
uint8Data = new Uint8Array(this._data.allocationSize({
|
|
22032
|
+
format: "f32-planar",
|
|
22033
|
+
planeIndex: 0
|
|
22034
|
+
}) * numChannels);
|
|
22035
|
+
for (let ch = 0; ch < numChannels; ch++) {
|
|
22036
|
+
this._data.copyTo(
|
|
22037
|
+
uint8Data.subarray(
|
|
22038
|
+
ch * numFrames * srcBytesPerSample,
|
|
22039
|
+
(ch + 1) * numFrames * srcBytesPerSample
|
|
22040
|
+
),
|
|
22041
|
+
{
|
|
22042
|
+
format: "f32-planar",
|
|
22043
|
+
planeIndex: ch
|
|
21982
22044
|
}
|
|
21983
|
-
|
|
22045
|
+
);
|
|
22046
|
+
}
|
|
22047
|
+
}
|
|
22048
|
+
}
|
|
22049
|
+
const srcView = toDataView(uint8Data);
|
|
22050
|
+
for (let i = 0; i < copyFrameCount; i++) {
|
|
22051
|
+
if (destIsPlanar) {
|
|
22052
|
+
const destOffset = i * destBytesPerSample;
|
|
22053
|
+
let srcOffset;
|
|
22054
|
+
if (srcIsPlanar) {
|
|
22055
|
+
srcOffset = (planeIndex * numFrames + (i + frameOffset)) * srcBytesPerSample;
|
|
21984
22056
|
} else {
|
|
21985
|
-
|
|
22057
|
+
srcOffset = ((i + frameOffset) * numChannels + planeIndex) * srcBytesPerSample;
|
|
21986
22058
|
}
|
|
22059
|
+
const normalized = readFn(srcView, srcOffset);
|
|
22060
|
+
writeFn(destView, destOffset, normalized);
|
|
21987
22061
|
} else {
|
|
21988
|
-
|
|
21989
|
-
|
|
21990
|
-
|
|
21991
|
-
for (let i = 0; i < copyFrameCount; i++) {
|
|
21992
|
-
if (destIsPlanar) {
|
|
21993
|
-
const destOffset = i * destBytesPerSample;
|
|
22062
|
+
for (let ch = 0; ch < numChannels; ch++) {
|
|
22063
|
+
const destIndex = i * numChannels + ch;
|
|
22064
|
+
const destOffset = destIndex * destBytesPerSample;
|
|
21994
22065
|
let srcOffset;
|
|
21995
22066
|
if (srcIsPlanar) {
|
|
21996
|
-
srcOffset = (
|
|
22067
|
+
srcOffset = (ch * numFrames + (i + frameOffset)) * srcBytesPerSample;
|
|
21997
22068
|
} else {
|
|
21998
|
-
srcOffset = ((i + frameOffset) * numChannels +
|
|
22069
|
+
srcOffset = ((i + frameOffset) * numChannels + ch) * srcBytesPerSample;
|
|
21999
22070
|
}
|
|
22000
22071
|
const normalized = readFn(srcView, srcOffset);
|
|
22001
22072
|
writeFn(destView, destOffset, normalized);
|
|
22002
|
-
} else {
|
|
22003
|
-
for (let ch = 0; ch < numChannels; ch++) {
|
|
22004
|
-
const destIndex = i * numChannels + ch;
|
|
22005
|
-
const destOffset = destIndex * destBytesPerSample;
|
|
22006
|
-
let srcOffset;
|
|
22007
|
-
if (srcIsPlanar) {
|
|
22008
|
-
srcOffset = (ch * numFrames + (i + frameOffset)) * srcBytesPerSample;
|
|
22009
|
-
} else {
|
|
22010
|
-
srcOffset = ((i + frameOffset) * numChannels + ch) * srcBytesPerSample;
|
|
22011
|
-
}
|
|
22012
|
-
const normalized = readFn(srcView, srcOffset);
|
|
22013
|
-
writeFn(destView, destOffset, normalized);
|
|
22014
|
-
}
|
|
22015
22073
|
}
|
|
22016
22074
|
}
|
|
22017
22075
|
}
|
|
@@ -25702,7 +25760,7 @@ var Mediabunny = (() => {
|
|
|
25702
25760
|
if (!options || typeof options !== "object") {
|
|
25703
25761
|
throw new TypeError("options must be an object.");
|
|
25704
25762
|
}
|
|
25705
|
-
if (options.targetPacketCount !== void 0 && (!
|
|
25763
|
+
if (options.targetPacketCount !== void 0 && (!isNumber(options.targetPacketCount) || options.targetPacketCount < 0)) {
|
|
25706
25764
|
throw new TypeError("options.targetPacketCount must be a non-negative number.");
|
|
25707
25765
|
}
|
|
25708
25766
|
const timeResolution = await this.getTimeResolution();
|
|
@@ -37729,7 +37787,7 @@ ${cue.notes ?? ""}`;
|
|
|
37729
37787
|
"options.fastStart, when provided, must be false, 'in-memory', 'reserve', or 'fragmented'."
|
|
37730
37788
|
);
|
|
37731
37789
|
}
|
|
37732
|
-
if (options.minimumFragmentDuration !== void 0 && (!
|
|
37790
|
+
if (options.minimumFragmentDuration !== void 0 && (!isNumber(options.minimumFragmentDuration) || options.minimumFragmentDuration < 0)) {
|
|
37733
37791
|
throw new TypeError("options.minimumFragmentDuration, when provided, must be a non-negative number.");
|
|
37734
37792
|
}
|
|
37735
37793
|
if (options.onFtyp !== void 0 && typeof options.onFtyp !== "function") {
|
|
@@ -37889,7 +37947,7 @@ ${cue.notes ?? ""}`;
|
|
|
37889
37947
|
if (options.appendOnly !== void 0 && typeof options.appendOnly !== "boolean") {
|
|
37890
37948
|
throw new TypeError("options.appendOnly, when provided, must be a boolean.");
|
|
37891
37949
|
}
|
|
37892
|
-
if (options.minimumClusterDuration !== void 0 && (!
|
|
37950
|
+
if (options.minimumClusterDuration !== void 0 && (!isNumber(options.minimumClusterDuration) || options.minimumClusterDuration < 0)) {
|
|
37893
37951
|
throw new TypeError("options.minimumClusterDuration, when provided, must be a non-negative number.");
|
|
37894
37952
|
}
|
|
37895
37953
|
if (options.onEbmlHeader !== void 0 && typeof options.onEbmlHeader !== "function") {
|
|
@@ -38079,7 +38137,7 @@ ${cue.notes ?? ""}`;
|
|
|
38079
38137
|
if (!options || typeof options !== "object") {
|
|
38080
38138
|
throw new TypeError("options must be an object.");
|
|
38081
38139
|
}
|
|
38082
|
-
if (options.maximumPageDuration !== void 0 && (!
|
|
38140
|
+
if (options.maximumPageDuration !== void 0 && (!isNumber(options.maximumPageDuration) || options.maximumPageDuration <= 0)) {
|
|
38083
38141
|
throw new TypeError("options.maximumPageDuration, when provided, must be a positive number.");
|
|
38084
38142
|
}
|
|
38085
38143
|
if (options.onPage !== void 0 && typeof options.onPage !== "function") {
|