@ahmedrowaihi/mediabunny 1.65.2-beta.320 → 1.65.2-beta.321
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 +227 -226
- package/dist/bundles/mediabunny.min.cjs +21 -21
- package/dist/bundles/mediabunny.min.mjs +22 -22
- package/dist/bundles/mediabunny.mjs +227 -226
- package/dist/bundles/mediabunny.node.cjs +227 -226
- package/dist/modules/src/aes.d.ts.map +1 -1
- package/dist/modules/src/aes.js +53 -40
- package/dist/modules/src/isobmff/isobmff-boxes.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-boxes.js +3 -2
- package/dist/modules/src/isobmff/isobmff-demuxer.d.ts +1 -0
- package/dist/modules/src/isobmff/isobmff-demuxer.d.ts.map +1 -1
- package/dist/modules/src/isobmff/isobmff-demuxer.js +96 -85
- package/dist/modules/src/matroska/matroska-demuxer.d.ts +1 -0
- package/dist/modules/src/matroska/matroska-demuxer.d.ts.map +1 -1
- package/dist/modules/src/matroska/matroska-demuxer.js +109 -110
- package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
- package/dist/modules/src/version.d.ts +2 -2
- package/dist/modules/src/version.js +1 -1
- package/package.json +1 -1
- package/src/aes.ts +52 -39
- package/src/isobmff/isobmff-boxes.ts +3 -1
- package/src/isobmff/isobmff-demuxer.ts +106 -103
- package/src/matroska/matroska-demuxer.ts +137 -146
- package/src/version.ts +1 -1
|
@@ -2823,7 +2823,7 @@ var Mediabunny = (() => {
|
|
|
2823
2823
|
var TRUEHD_MAJOR_SYNC_WORD = 4168249274;
|
|
2824
2824
|
|
|
2825
2825
|
// src/version.ts
|
|
2826
|
-
var VERSION = "1.65.
|
|
2826
|
+
var VERSION = "1.65.2";
|
|
2827
2827
|
var VERSIONED_NAME = `Mediabunny v${VERSION}`;
|
|
2828
2828
|
|
|
2829
2829
|
// src/codec-data.ts
|
|
@@ -7303,50 +7303,62 @@ var Mediabunny = (() => {
|
|
|
7303
7303
|
};
|
|
7304
7304
|
var createAes128CbcDecryptStream = (reader, getInit, close) => {
|
|
7305
7305
|
let initted = false;
|
|
7306
|
+
let closed = false;
|
|
7306
7307
|
let pos = 0;
|
|
7307
7308
|
const CHUNK_SIZE = 2 ** 16;
|
|
7308
7309
|
const BLOCK_SIZE = 16;
|
|
7309
7310
|
const aesContext = new Aes128CbcContext();
|
|
7311
|
+
const closeOnce = () => {
|
|
7312
|
+
if (!closed) {
|
|
7313
|
+
closed = true;
|
|
7314
|
+
close();
|
|
7315
|
+
}
|
|
7316
|
+
};
|
|
7310
7317
|
return new ReadableStream({
|
|
7311
7318
|
pull: async (controller) => {
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7319
|
+
try {
|
|
7320
|
+
if (!initted) {
|
|
7321
|
+
aesContext.init(await getInit());
|
|
7322
|
+
initted = true;
|
|
7323
|
+
}
|
|
7324
|
+
const requestedLength = CHUNK_SIZE + BLOCK_SIZE;
|
|
7325
|
+
let nextSlice = reader.requestSliceRange(pos, 0, requestedLength);
|
|
7326
|
+
if (isThenable(nextSlice)) nextSlice = await nextSlice;
|
|
7327
|
+
if (!nextSlice || nextSlice.length === 0) {
|
|
7328
|
+
throw new Error("Invalid ciphertext.");
|
|
7329
|
+
}
|
|
7330
|
+
const sliceLength = nextSlice.length;
|
|
7331
|
+
if (sliceLength % 16 !== 0) {
|
|
7332
|
+
throw new Error("Invalid ciphertext.");
|
|
7333
|
+
}
|
|
7334
|
+
const bytesToRead = sliceLength === requestedLength ? sliceLength - BLOCK_SIZE : sliceLength;
|
|
7335
|
+
const input = readBytes(nextSlice, bytesToRead);
|
|
7336
|
+
const output = new Uint8Array(bytesToRead);
|
|
7337
|
+
for (let i = 0; i < bytesToRead; i += 16) {
|
|
7338
|
+
aesContext.in.set(input.subarray(i, i + 16));
|
|
7339
|
+
aesContext.decrypt();
|
|
7340
|
+
output.set(aesContext.out, i);
|
|
7341
|
+
}
|
|
7342
|
+
if (bytesToRead < sliceLength) {
|
|
7343
|
+
controller.enqueue(output);
|
|
7344
|
+
pos += bytesToRead;
|
|
7345
|
+
} else {
|
|
7346
|
+
const paddingLength = output[bytesToRead - 1];
|
|
7347
|
+
if (paddingLength === 0 || paddingLength > 16) {
|
|
7348
|
+
throw new Error("Invalid PKCS#7 padding. Incorrect key or corrupted data.");
|
|
7349
|
+
}
|
|
7350
|
+
const trimmedOutput = output.subarray(0, bytesToRead - paddingLength);
|
|
7351
|
+
controller.enqueue(trimmedOutput);
|
|
7352
|
+
controller.close();
|
|
7353
|
+
closeOnce();
|
|
7341
7354
|
}
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
close();
|
|
7355
|
+
} catch (error) {
|
|
7356
|
+
closeOnce();
|
|
7357
|
+
throw error;
|
|
7346
7358
|
}
|
|
7347
7359
|
},
|
|
7348
7360
|
cancel: () => {
|
|
7349
|
-
|
|
7361
|
+
closeOnce();
|
|
7350
7362
|
}
|
|
7351
7363
|
});
|
|
7352
7364
|
};
|
|
@@ -8059,7 +8071,8 @@ var Mediabunny = (() => {
|
|
|
8059
8071
|
fragmentPositionCache.splice(insertionIndex + 1, 0, {
|
|
8060
8072
|
moofOffset: fragment.moofOffset,
|
|
8061
8073
|
startTimestamp: trackData.startTimestamp,
|
|
8062
|
-
endTimestamp: trackData.endTimestamp
|
|
8074
|
+
endTimestamp: trackData.endTimestamp,
|
|
8075
|
+
hasKeyFrame: trackData.firstKeyFrameTimestamp !== null
|
|
8063
8076
|
});
|
|
8064
8077
|
}
|
|
8065
8078
|
if (trackData.encryptionAuxInfo && track.encryptionInfo) {
|
|
@@ -10374,7 +10387,8 @@ var Mediabunny = (() => {
|
|
|
10374
10387
|
},
|
|
10375
10388
|
timestampInTimescale,
|
|
10376
10389
|
timestampInTimescale,
|
|
10377
|
-
options
|
|
10390
|
+
options,
|
|
10391
|
+
true
|
|
10378
10392
|
);
|
|
10379
10393
|
}
|
|
10380
10394
|
async getNextKeyPacket(packet, options) {
|
|
@@ -10521,10 +10535,8 @@ var Mediabunny = (() => {
|
|
|
10521
10535
|
return packet;
|
|
10522
10536
|
}
|
|
10523
10537
|
/** Looks for a packet in the fragments while trying to load as few fragments as possible to retrieve it. */
|
|
10524
|
-
async performFragmentedLookup(startFragment, getMatchInFragment, searchTimestamp, latestTimestamp, options,
|
|
10525
|
-
const demuxer = this.internalTrack
|
|
10526
|
-
let currentFragment = null;
|
|
10527
|
-
let precedingFragment = null;
|
|
10538
|
+
async performFragmentedLookup(startFragment, getMatchInFragment, searchTimestamp, latestTimestamp, options, requireKeyFrame = false) {
|
|
10539
|
+
const { demuxer, fragmentLookupTable, fragmentPositionCache } = this.internalTrack;
|
|
10528
10540
|
let bestFragment = null;
|
|
10529
10541
|
let bestSampleIndex = -1;
|
|
10530
10542
|
if (startFragment) {
|
|
@@ -10537,89 +10549,88 @@ var Mediabunny = (() => {
|
|
|
10537
10549
|
bestSampleIndex = sampleIndex;
|
|
10538
10550
|
}
|
|
10539
10551
|
}
|
|
10540
|
-
|
|
10541
|
-
|
|
10542
|
-
|
|
10543
|
-
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10556
|
-
|
|
10557
|
-
|
|
10558
|
-
|
|
10559
|
-
|
|
10560
|
-
} else {
|
|
10561
|
-
if (lookupEntryPosition === null || startFragment.moofOffset >= lookupEntryPosition) {
|
|
10562
|
-
currentPos = startFragment.moofOffset + startFragment.moofSize;
|
|
10563
|
-
currentFragment = startFragment;
|
|
10552
|
+
let lookupEntryIndex = binarySearchLessOrEqual(fragmentLookupTable, searchTimestamp, (x) => x.timestamp);
|
|
10553
|
+
let positionCacheIndex = binarySearchLessOrEqual(fragmentPositionCache, searchTimestamp, (x) => x.startTimestamp);
|
|
10554
|
+
let stopPos = Infinity;
|
|
10555
|
+
while (true) {
|
|
10556
|
+
while (lookupEntryIndex !== -1 && fragmentLookupTable[lookupEntryIndex].moofOffset >= stopPos) {
|
|
10557
|
+
lookupEntryIndex--;
|
|
10558
|
+
}
|
|
10559
|
+
while (positionCacheIndex !== -1 && (fragmentPositionCache[positionCacheIndex].moofOffset >= stopPos || requireKeyFrame && !fragmentPositionCache[positionCacheIndex].hasKeyFrame)) {
|
|
10560
|
+
positionCacheIndex--;
|
|
10561
|
+
}
|
|
10562
|
+
const lookupEntryPosition = Math.max(
|
|
10563
|
+
fragmentLookupTable[lookupEntryIndex]?.moofOffset ?? 0,
|
|
10564
|
+
fragmentPositionCache[positionCacheIndex]?.moofOffset ?? 0
|
|
10565
|
+
) || null;
|
|
10566
|
+
let currentPos;
|
|
10567
|
+
let currentFragment = null;
|
|
10568
|
+
let precedingFragment = null;
|
|
10569
|
+
let scanReachedFragment = false;
|
|
10570
|
+
if (!startFragment) {
|
|
10571
|
+
currentPos = lookupEntryPosition ?? 0;
|
|
10564
10572
|
} else {
|
|
10565
|
-
|
|
10573
|
+
if (lookupEntryPosition === null || startFragment.moofOffset >= lookupEntryPosition) {
|
|
10574
|
+
currentPos = startFragment.moofOffset + startFragment.moofSize;
|
|
10575
|
+
currentFragment = startFragment;
|
|
10576
|
+
} else {
|
|
10577
|
+
currentPos = lookupEntryPosition;
|
|
10578
|
+
}
|
|
10566
10579
|
}
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10580
|
+
const scanStartPos = currentFragment ? currentFragment.moofOffset : currentPos;
|
|
10581
|
+
while (currentPos < stopPos) {
|
|
10582
|
+
if (currentFragment) {
|
|
10583
|
+
const trackData = currentFragment.trackData.get(this.internalTrack.id);
|
|
10584
|
+
if (trackData && trackData.startTimestamp > latestTimestamp) {
|
|
10585
|
+
break;
|
|
10586
|
+
}
|
|
10587
|
+
precedingFragment = currentFragment;
|
|
10588
|
+
currentFragment = null;
|
|
10589
|
+
}
|
|
10590
|
+
const summary = demuxer.fragmentSummaries.get(currentPos);
|
|
10591
|
+
if (summary && !summary.trackIds.has(this.internalTrack.id)) {
|
|
10592
|
+
currentPos += summary.moofSize;
|
|
10593
|
+
continue;
|
|
10594
|
+
}
|
|
10595
|
+
let slice = demuxer.reader.requestSliceRange(currentPos, MIN_BOX_HEADER_SIZE, MAX_BOX_HEADER_SIZE);
|
|
10596
|
+
if (isThenable(slice)) slice = await slice;
|
|
10597
|
+
if (!slice) break;
|
|
10598
|
+
const boxStartPos = currentPos;
|
|
10599
|
+
const boxInfo = readBoxHeader(slice);
|
|
10600
|
+
if (!boxInfo) {
|
|
10574
10601
|
break;
|
|
10575
10602
|
}
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
|
|
10581
|
-
|
|
10582
|
-
|
|
10603
|
+
if (boxInfo.name === "moof") {
|
|
10604
|
+
scanReachedFragment = true;
|
|
10605
|
+
currentFragment = await demuxer.readFragment(boxStartPos, precedingFragment);
|
|
10606
|
+
if (!currentFragment) {
|
|
10607
|
+
break;
|
|
10608
|
+
}
|
|
10609
|
+
const { sampleIndex, correctSampleFound } = getMatchInFragment(currentFragment);
|
|
10610
|
+
if (correctSampleFound) {
|
|
10611
|
+
return this.fetchPacketInFragment(currentFragment, sampleIndex, options);
|
|
10612
|
+
}
|
|
10613
|
+
if (sampleIndex !== -1) {
|
|
10614
|
+
bestFragment = currentFragment;
|
|
10615
|
+
bestSampleIndex = sampleIndex;
|
|
10616
|
+
}
|
|
10617
|
+
}
|
|
10618
|
+
currentPos = boxStartPos + boxInfo.totalSize;
|
|
10583
10619
|
}
|
|
10584
|
-
|
|
10585
|
-
if (isThenable(slice)) slice = await slice;
|
|
10586
|
-
if (!slice) break;
|
|
10587
|
-
const boxStartPos = currentPos;
|
|
10588
|
-
const boxInfo = readBoxHeader(slice);
|
|
10589
|
-
if (!boxInfo) {
|
|
10620
|
+
if (lookupEntryPosition === null || bestFragment && bestFragment.moofOffset >= lookupEntryPosition) {
|
|
10590
10621
|
break;
|
|
10591
10622
|
}
|
|
10592
|
-
if (
|
|
10593
|
-
|
|
10594
|
-
|
|
10595
|
-
if (
|
|
10596
|
-
|
|
10623
|
+
if (scanReachedFragment) {
|
|
10624
|
+
stopPos = scanStartPos;
|
|
10625
|
+
} else {
|
|
10626
|
+
if (fragmentLookupTable[lookupEntryIndex]?.moofOffset === lookupEntryPosition) {
|
|
10627
|
+
lookupEntryIndex--;
|
|
10597
10628
|
}
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
bestFragment = currentFragment;
|
|
10604
|
-
bestSampleIndex = sampleIndex;
|
|
10605
|
-
}
|
|
10606
|
-
}
|
|
10607
|
-
currentPos = boxStartPos + boxInfo.totalSize;
|
|
10608
|
-
}
|
|
10609
|
-
if (lookupEntryPosition !== null && (!bestFragment || bestFragment.moofOffset < lookupEntryPosition)) {
|
|
10610
|
-
const step = 1 << lookupRetryCount;
|
|
10611
|
-
const previousEntryTimestamp = lookupTableWins ? this.internalTrack.fragmentLookupTable[lookupEntryIndex - step]?.timestamp : this.internalTrack.fragmentPositionCache[positionCacheIndex - step]?.startTimestamp;
|
|
10612
|
-
const newSearchTimestamp = previousEntryTimestamp ?? -Infinity;
|
|
10613
|
-
return this.performFragmentedLookup(
|
|
10614
|
-
null,
|
|
10615
|
-
getMatchInFragment,
|
|
10616
|
-
newSearchTimestamp,
|
|
10617
|
-
latestTimestamp,
|
|
10618
|
-
options,
|
|
10619
|
-
// Only cap when the scan reached a fragment; capping a bogus offset hides the rest of the file
|
|
10620
|
-
scanReachedFragment ? scanStartPos : stopPos,
|
|
10621
|
-
lookupRetryCount + 1
|
|
10622
|
-
);
|
|
10629
|
+
if (fragmentPositionCache[positionCacheIndex]?.moofOffset === lookupEntryPosition) {
|
|
10630
|
+
positionCacheIndex--;
|
|
10631
|
+
}
|
|
10632
|
+
}
|
|
10633
|
+
startFragment = null;
|
|
10623
10634
|
}
|
|
10624
10635
|
if (bestFragment) {
|
|
10625
10636
|
return this.fetchPacketInFragment(bestFragment, bestSampleIndex, options);
|
|
@@ -12253,7 +12264,8 @@ var Mediabunny = (() => {
|
|
|
12253
12264
|
if ((!previousEntry || previousEntry.elementStartPos < elementStartPos) && (!nextEntry || nextEntry.elementStartPos > elementStartPos)) {
|
|
12254
12265
|
track.clusterPositionCache.splice(insertionIndex + 1, 0, {
|
|
12255
12266
|
elementStartPos: cluster.elementStartPos,
|
|
12256
|
-
startTimestamp: trackData.startTimestamp
|
|
12267
|
+
startTimestamp: trackData.startTimestamp,
|
|
12268
|
+
hasKeyFrame: trackData.firstKeyFrameTimestamp !== null
|
|
12257
12269
|
});
|
|
12258
12270
|
}
|
|
12259
12271
|
}
|
|
@@ -13747,7 +13759,8 @@ var Mediabunny = (() => {
|
|
|
13747
13759
|
},
|
|
13748
13760
|
timestampInTimescale,
|
|
13749
13761
|
timestampInTimescale,
|
|
13750
|
-
options
|
|
13762
|
+
options,
|
|
13763
|
+
true
|
|
13751
13764
|
);
|
|
13752
13765
|
}
|
|
13753
13766
|
async getNextKeyPacket(packet, options) {
|
|
@@ -13840,9 +13853,8 @@ var Mediabunny = (() => {
|
|
|
13840
13853
|
return packet;
|
|
13841
13854
|
}
|
|
13842
13855
|
/** Looks for a packet in the clusters while trying to load as few clusters as possible to retrieve it. */
|
|
13843
|
-
async performClusterLookup(startCluster, getMatchInCluster, searchTimestamp, latestTimestamp, options,
|
|
13844
|
-
const { demuxer, segment } = this.internalTrack;
|
|
13845
|
-
let currentCluster = null;
|
|
13856
|
+
async performClusterLookup(startCluster, getMatchInCluster, searchTimestamp, latestTimestamp, options, requireKeyFrame = false) {
|
|
13857
|
+
const { demuxer, segment, cuePoints, clusterPositionCache } = this.internalTrack;
|
|
13846
13858
|
let bestCluster = null;
|
|
13847
13859
|
let bestBlockIndex = -1;
|
|
13848
13860
|
if (startCluster) {
|
|
@@ -13855,119 +13867,108 @@ var Mediabunny = (() => {
|
|
|
13855
13867
|
bestBlockIndex = blockIndex;
|
|
13856
13868
|
}
|
|
13857
13869
|
}
|
|
13858
|
-
|
|
13859
|
-
|
|
13860
|
-
|
|
13861
|
-
|
|
13862
|
-
|
|
13863
|
-
|
|
13864
|
-
|
|
13865
|
-
|
|
13866
|
-
|
|
13867
|
-
|
|
13868
|
-
|
|
13869
|
-
|
|
13870
|
-
|
|
13871
|
-
|
|
13872
|
-
|
|
13873
|
-
|
|
13874
|
-
|
|
13875
|
-
|
|
13876
|
-
if (!startCluster) {
|
|
13877
|
-
currentPos = lookupEntryPosition ?? segment.clusterSeekStartPos;
|
|
13878
|
-
} else {
|
|
13879
|
-
if (lookupEntryPosition === null || startCluster.elementStartPos >= lookupEntryPosition) {
|
|
13880
|
-
currentPos = startCluster.elementEndPos;
|
|
13881
|
-
currentCluster = startCluster;
|
|
13870
|
+
let cuePointIndex = binarySearchLessOrEqual(cuePoints, searchTimestamp, (x) => x.time);
|
|
13871
|
+
let positionCacheIndex = binarySearchLessOrEqual(clusterPositionCache, searchTimestamp, (x) => x.startTimestamp);
|
|
13872
|
+
let stopPos = Infinity;
|
|
13873
|
+
while (true) {
|
|
13874
|
+
while (cuePointIndex !== -1 && cuePoints[cuePointIndex].clusterPosition >= stopPos) {
|
|
13875
|
+
cuePointIndex--;
|
|
13876
|
+
}
|
|
13877
|
+
while (positionCacheIndex !== -1 && (clusterPositionCache[positionCacheIndex].elementStartPos >= stopPos || requireKeyFrame && !clusterPositionCache[positionCacheIndex].hasKeyFrame)) {
|
|
13878
|
+
positionCacheIndex--;
|
|
13879
|
+
}
|
|
13880
|
+
const lookupEntryPosition = Math.max(
|
|
13881
|
+
cuePoints[cuePointIndex]?.clusterPosition ?? 0,
|
|
13882
|
+
clusterPositionCache[positionCacheIndex]?.elementStartPos ?? 0
|
|
13883
|
+
) || null;
|
|
13884
|
+
let currentPos;
|
|
13885
|
+
let currentCluster = null;
|
|
13886
|
+
if (!startCluster) {
|
|
13887
|
+
currentPos = lookupEntryPosition ?? segment.clusterSeekStartPos;
|
|
13882
13888
|
} else {
|
|
13883
|
-
|
|
13884
|
-
|
|
13885
|
-
|
|
13886
|
-
|
|
13887
|
-
|
|
13888
|
-
if (currentCluster) {
|
|
13889
|
-
const trackData = currentCluster.trackData.get(this.internalTrack.id);
|
|
13890
|
-
if (trackData && trackData.startTimestamp > latestTimestamp) {
|
|
13891
|
-
break;
|
|
13889
|
+
if (lookupEntryPosition === null || startCluster.elementStartPos >= lookupEntryPosition) {
|
|
13890
|
+
currentPos = startCluster.elementEndPos;
|
|
13891
|
+
currentCluster = startCluster;
|
|
13892
|
+
} else {
|
|
13893
|
+
currentPos = lookupEntryPosition;
|
|
13892
13894
|
}
|
|
13893
|
-
currentCluster = null;
|
|
13894
13895
|
}
|
|
13895
|
-
const
|
|
13896
|
-
|
|
13897
|
-
|
|
13898
|
-
|
|
13899
|
-
|
|
13900
|
-
|
|
13901
|
-
|
|
13902
|
-
|
|
13903
|
-
|
|
13904
|
-
|
|
13905
|
-
|
|
13906
|
-
|
|
13907
|
-
demuxer.reader,
|
|
13908
|
-
elementStartPos + 1,
|
|
13909
|
-
LEVEL_1_EBML_IDS,
|
|
13910
|
-
Math.min(segment.elementEndPos ?? Infinity, elementStartPos + MAX_RESYNC_LENGTH)
|
|
13911
|
-
);
|
|
13912
|
-
if (nextPos) {
|
|
13913
|
-
currentPos = nextPos;
|
|
13896
|
+
const scanStartPos = currentCluster ? currentCluster.elementStartPos : currentPos;
|
|
13897
|
+
while ((segment.elementEndPos === null || currentPos <= segment.elementEndPos - MIN_HEADER_SIZE) && currentPos < stopPos) {
|
|
13898
|
+
if (currentCluster) {
|
|
13899
|
+
const trackData = currentCluster.trackData.get(this.internalTrack.id);
|
|
13900
|
+
if (trackData && trackData.startTimestamp > latestTimestamp) {
|
|
13901
|
+
break;
|
|
13902
|
+
}
|
|
13903
|
+
currentCluster = null;
|
|
13904
|
+
}
|
|
13905
|
+
const summary = segment.clusterSummaries.get(currentPos);
|
|
13906
|
+
if (summary && !summary.trackIds.has(this.internalTrack.id)) {
|
|
13907
|
+
currentPos = summary.elementEndPos;
|
|
13914
13908
|
continue;
|
|
13915
|
-
} else {
|
|
13916
|
-
break;
|
|
13917
13909
|
}
|
|
13918
|
-
|
|
13919
|
-
|
|
13920
|
-
|
|
13921
|
-
|
|
13922
|
-
|
|
13923
|
-
|
|
13924
|
-
|
|
13925
|
-
|
|
13926
|
-
|
|
13927
|
-
|
|
13910
|
+
let slice = demuxer.reader.requestSliceRange(currentPos, MIN_HEADER_SIZE, MAX_HEADER_SIZE);
|
|
13911
|
+
if (isThenable(slice)) slice = await slice;
|
|
13912
|
+
if (!slice) break;
|
|
13913
|
+
const elementStartPos = currentPos;
|
|
13914
|
+
const elementHeader = readElementHeader(slice);
|
|
13915
|
+
if (!elementHeader || !LEVEL_1_EBML_IDS.includes(elementHeader.id) && elementHeader.id !== 236 /* Void */) {
|
|
13916
|
+
const nextPos = await resync(
|
|
13917
|
+
demuxer.reader,
|
|
13918
|
+
elementStartPos + 1,
|
|
13919
|
+
LEVEL_1_EBML_IDS,
|
|
13920
|
+
Math.min(segment.elementEndPos ?? Infinity, elementStartPos + MAX_RESYNC_LENGTH)
|
|
13921
|
+
);
|
|
13922
|
+
if (nextPos) {
|
|
13923
|
+
currentPos = nextPos;
|
|
13924
|
+
continue;
|
|
13925
|
+
} else {
|
|
13926
|
+
break;
|
|
13927
|
+
}
|
|
13928
13928
|
}
|
|
13929
|
-
|
|
13930
|
-
|
|
13931
|
-
|
|
13929
|
+
const id = elementHeader.id;
|
|
13930
|
+
let size = elementHeader.size;
|
|
13931
|
+
const dataStartPos = slice.filePos;
|
|
13932
|
+
if (id === 524531317 /* Cluster */) {
|
|
13933
|
+
currentCluster = await demuxer.readCluster(elementStartPos, segment);
|
|
13934
|
+
size = currentCluster.elementEndPos - dataStartPos;
|
|
13935
|
+
const { blockIndex, correctBlockFound } = getMatchInCluster(currentCluster);
|
|
13936
|
+
if (correctBlockFound) {
|
|
13937
|
+
return this.fetchPacketInCluster(currentCluster, blockIndex, options);
|
|
13938
|
+
}
|
|
13939
|
+
if (blockIndex !== -1) {
|
|
13940
|
+
bestCluster = currentCluster;
|
|
13941
|
+
bestBlockIndex = blockIndex;
|
|
13942
|
+
}
|
|
13943
|
+
}
|
|
13944
|
+
if (size === void 0) {
|
|
13945
|
+
assert(id !== 524531317 /* Cluster */);
|
|
13946
|
+
const nextElementPos = await searchForNextElementId(
|
|
13947
|
+
demuxer.reader,
|
|
13948
|
+
dataStartPos,
|
|
13949
|
+
LEVEL_0_AND_1_EBML_IDS,
|
|
13950
|
+
segment.elementEndPos
|
|
13951
|
+
);
|
|
13952
|
+
size = nextElementPos.pos - dataStartPos;
|
|
13932
13953
|
}
|
|
13933
|
-
|
|
13934
|
-
|
|
13935
|
-
|
|
13936
|
-
|
|
13937
|
-
|
|
13938
|
-
|
|
13939
|
-
|
|
13940
|
-
|
|
13941
|
-
|
|
13942
|
-
|
|
13943
|
-
}
|
|
13944
|
-
const endPos = dataStartPos + size;
|
|
13945
|
-
if (segment.elementEndPos === null) {
|
|
13946
|
-
let slice2 = demuxer.reader.requestSliceRange(endPos, MIN_HEADER_SIZE, MAX_HEADER_SIZE);
|
|
13947
|
-
if (isThenable(slice2)) slice2 = await slice2;
|
|
13948
|
-
if (!slice2) break;
|
|
13949
|
-
const elementId = readElementId(slice2);
|
|
13950
|
-
if (elementId === 408125543 /* Segment */) {
|
|
13951
|
-
segment.elementEndPos = endPos;
|
|
13952
|
-
break;
|
|
13954
|
+
const endPos = dataStartPos + size;
|
|
13955
|
+
if (segment.elementEndPos === null) {
|
|
13956
|
+
let slice2 = demuxer.reader.requestSliceRange(endPos, MIN_HEADER_SIZE, MAX_HEADER_SIZE);
|
|
13957
|
+
if (isThenable(slice2)) slice2 = await slice2;
|
|
13958
|
+
if (!slice2) break;
|
|
13959
|
+
const elementId = readElementId(slice2);
|
|
13960
|
+
if (elementId === 408125543 /* Segment */) {
|
|
13961
|
+
segment.elementEndPos = endPos;
|
|
13962
|
+
break;
|
|
13963
|
+
}
|
|
13953
13964
|
}
|
|
13965
|
+
currentPos = endPos;
|
|
13954
13966
|
}
|
|
13955
|
-
|
|
13956
|
-
|
|
13957
|
-
|
|
13958
|
-
|
|
13959
|
-
|
|
13960
|
-
const newSearchTimestamp = previousEntryTimestamp ?? -Infinity;
|
|
13961
|
-
return this.performClusterLookup(
|
|
13962
|
-
null,
|
|
13963
|
-
getMatchInCluster,
|
|
13964
|
-
newSearchTimestamp,
|
|
13965
|
-
latestTimestamp,
|
|
13966
|
-
options,
|
|
13967
|
-
scanStartPos,
|
|
13968
|
-
// So we don't read the same clusters again
|
|
13969
|
-
lookupRetryCount + 1
|
|
13970
|
-
);
|
|
13967
|
+
if (lookupEntryPosition === null || bestCluster && bestCluster.elementStartPos >= lookupEntryPosition) {
|
|
13968
|
+
break;
|
|
13969
|
+
}
|
|
13970
|
+
stopPos = scanStartPos;
|
|
13971
|
+
startCluster = null;
|
|
13971
13972
|
}
|
|
13972
13973
|
if (bestCluster) {
|
|
13973
13974
|
return this.fetchPacketInCluster(bestCluster, bestBlockIndex, options);
|
|
@@ -40726,7 +40727,7 @@ var Mediabunny = (() => {
|
|
|
40726
40727
|
const uniqueSampleSizes = new Set(allSampleSizes);
|
|
40727
40728
|
const uniqueSampleFlags = new Set(allSampleFlags);
|
|
40728
40729
|
const uniqueSampleCompositionTimeOffsets = new Set(allSampleCompositionTimeOffsets);
|
|
40729
|
-
const firstSampleFlagsPresent = uniqueSampleFlags.size === 2 && allSampleFlags[0]
|
|
40730
|
+
const firstSampleFlagsPresent = uniqueSampleFlags.size === 2 && findLastIndex(allSampleFlags, (x) => x === allSampleFlags[0]) === 0;
|
|
40730
40731
|
const sampleDurationPresent = uniqueSampleDurations.size > 1;
|
|
40731
40732
|
const sampleSizePresent = uniqueSampleSizes.size > 1;
|
|
40732
40733
|
const sampleFlagsPresent = !firstSampleFlagsPresent && uniqueSampleFlags.size > 1;
|