@remotion/media-parser 4.0.333 → 4.0.335
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/containers/iso-base-media/mdat/mdat.js +39 -47
- package/dist/esm/index.mjs +129 -181
- package/dist/esm/worker-server-entry.mjs +128 -180
- package/dist/esm/worker-web-entry.mjs +128 -180
- package/dist/index.d.ts +11 -4
- package/dist/parse-loop.js +1 -0
- package/dist/perform-seek.d.ts +3 -1
- package/dist/perform-seek.js +4 -1
- package/dist/state/iso-base-media/cached-sample-positions.d.ts +17 -25
- package/dist/state/iso-base-media/cached-sample-positions.js +83 -24
- package/dist/state/iso-base-media/iso-state.d.ts +11 -4
- package/dist/state/parser-state.d.ts +11 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/work-on-seek-request.js +2 -0
- package/package.json +3 -3
|
@@ -7931,7 +7931,8 @@ var performSeek = async ({
|
|
|
7931
7931
|
src,
|
|
7932
7932
|
discardReadBytes,
|
|
7933
7933
|
fields,
|
|
7934
|
-
prefetchCache
|
|
7934
|
+
prefetchCache,
|
|
7935
|
+
isoState
|
|
7935
7936
|
}) => {
|
|
7936
7937
|
const byteInMediaSection = isByteInMediaSection({
|
|
7937
7938
|
position: seekTo,
|
|
@@ -7995,6 +7996,9 @@ var performSeek = async ({
|
|
|
7995
7996
|
prefetchCache
|
|
7996
7997
|
});
|
|
7997
7998
|
}
|
|
7999
|
+
if (userInitiated) {
|
|
8000
|
+
isoState.flatSamples.updateAfterSeek(seekTo);
|
|
8001
|
+
}
|
|
7998
8002
|
await controller._internals.checkForAbortAndPause();
|
|
7999
8003
|
};
|
|
8000
8004
|
|
|
@@ -8173,7 +8177,8 @@ var workOnSeekRequest = async (options) => {
|
|
|
8173
8177
|
src,
|
|
8174
8178
|
discardReadBytes,
|
|
8175
8179
|
fields,
|
|
8176
|
-
prefetchCache
|
|
8180
|
+
prefetchCache,
|
|
8181
|
+
isoState
|
|
8177
8182
|
});
|
|
8178
8183
|
return;
|
|
8179
8184
|
}
|
|
@@ -8193,7 +8198,8 @@ var workOnSeekRequest = async (options) => {
|
|
|
8193
8198
|
src,
|
|
8194
8199
|
discardReadBytes,
|
|
8195
8200
|
fields,
|
|
8196
|
-
prefetchCache
|
|
8201
|
+
prefetchCache,
|
|
8202
|
+
isoState
|
|
8197
8203
|
});
|
|
8198
8204
|
const { hasChanged } = controller._internals.seekSignal.clearSeekIfStillSame(seek2);
|
|
8199
8205
|
if (hasChanged) {
|
|
@@ -9303,9 +9309,10 @@ var parseFlac = ({
|
|
|
9303
9309
|
};
|
|
9304
9310
|
|
|
9305
9311
|
// src/state/iso-base-media/cached-sample-positions.ts
|
|
9306
|
-
var
|
|
9312
|
+
var calculateSamplePositions = ({
|
|
9307
9313
|
state,
|
|
9308
|
-
mediaSectionStart
|
|
9314
|
+
mediaSectionStart,
|
|
9315
|
+
trackIds
|
|
9309
9316
|
}) => {
|
|
9310
9317
|
const tracks2 = getTracks(state, true);
|
|
9311
9318
|
const moofBoxes = getMoofBoxes(state.structure.getIsoStructure().boxes);
|
|
@@ -9327,11 +9334,13 @@ var calculateFlatSamples = ({
|
|
|
9327
9334
|
if (!moov) {
|
|
9328
9335
|
throw new Error("No moov box found");
|
|
9329
9336
|
}
|
|
9330
|
-
const
|
|
9331
|
-
const trackIds = [];
|
|
9332
|
-
const map = new Map;
|
|
9337
|
+
const trackIdAndSamplePositions = [];
|
|
9333
9338
|
for (const track of tracks2) {
|
|
9334
9339
|
const trakBox = getTrakBoxByTrackId(moov, track.trackId);
|
|
9340
|
+
if (!trackIds.includes(track.trackId)) {
|
|
9341
|
+
Log.verbose(state.logLevel, "Skipping calculating sample positions for track", track.trackId);
|
|
9342
|
+
continue;
|
|
9343
|
+
}
|
|
9335
9344
|
if (!trakBox) {
|
|
9336
9345
|
throw new Error("No trak box found");
|
|
9337
9346
|
}
|
|
@@ -9341,36 +9350,88 @@ var calculateFlatSamples = ({
|
|
|
9341
9350
|
moofComplete,
|
|
9342
9351
|
trexBoxes: getTrexBoxes(moov)
|
|
9343
9352
|
});
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
|
|
9349
|
-
|
|
9350
|
-
|
|
9353
|
+
trackIdAndSamplePositions.push({
|
|
9354
|
+
trackId: track.trackId,
|
|
9355
|
+
samplePositions
|
|
9356
|
+
});
|
|
9357
|
+
}
|
|
9358
|
+
return trackIdAndSamplePositions;
|
|
9359
|
+
};
|
|
9360
|
+
var updateSampleIndicesAfterSeek = ({
|
|
9361
|
+
samplePositionsForMdatStart,
|
|
9362
|
+
seekedByte
|
|
9363
|
+
}) => {
|
|
9364
|
+
const currentSampleIndices = {};
|
|
9365
|
+
const keys = Object.keys(samplePositionsForMdatStart).map(Number).sort();
|
|
9366
|
+
const mdat = keys.find((key) => seekedByte >= key);
|
|
9367
|
+
if (!mdat) {
|
|
9368
|
+
return currentSampleIndices;
|
|
9369
|
+
}
|
|
9370
|
+
const samplePositions = samplePositionsForMdatStart[mdat];
|
|
9371
|
+
if (!samplePositions) {
|
|
9372
|
+
return currentSampleIndices;
|
|
9373
|
+
}
|
|
9374
|
+
for (const track of samplePositions) {
|
|
9375
|
+
const currentSampleIndex = track.samplePositions.findIndex((sample) => sample.offset >= seekedByte);
|
|
9376
|
+
if (!currentSampleIndices[mdat]) {
|
|
9377
|
+
currentSampleIndices[mdat] = {};
|
|
9378
|
+
}
|
|
9379
|
+
if (!currentSampleIndices[mdat][track.trackId]) {
|
|
9380
|
+
currentSampleIndices[mdat][track.trackId] = 0;
|
|
9381
|
+
}
|
|
9382
|
+
if (currentSampleIndex === -1) {
|
|
9383
|
+
currentSampleIndices[mdat][track.trackId] = track.samplePositions.length;
|
|
9384
|
+
} else {
|
|
9385
|
+
currentSampleIndices[mdat][track.trackId] = currentSampleIndex;
|
|
9351
9386
|
}
|
|
9352
9387
|
}
|
|
9353
|
-
|
|
9354
|
-
return { flatSamples: map, offsets, trackIds };
|
|
9388
|
+
return currentSampleIndices;
|
|
9355
9389
|
};
|
|
9356
9390
|
var cachedSamplePositionsState = () => {
|
|
9357
|
-
const
|
|
9358
|
-
|
|
9391
|
+
const samplePositionsForMdatStart = {};
|
|
9392
|
+
let currentSampleIndex = {};
|
|
9359
9393
|
return {
|
|
9360
9394
|
getSamples: (mdatStart) => {
|
|
9361
|
-
return
|
|
9395
|
+
return samplePositionsForMdatStart[mdatStart] ?? null;
|
|
9362
9396
|
},
|
|
9363
9397
|
setSamples: (mdatStart, samples) => {
|
|
9364
|
-
|
|
9398
|
+
samplePositionsForMdatStart[mdatStart] = samples;
|
|
9365
9399
|
},
|
|
9366
|
-
|
|
9367
|
-
|
|
9400
|
+
setCurrentSampleIndex: (mdatStart, trackId, index) => {
|
|
9401
|
+
if (!currentSampleIndex[mdatStart]) {
|
|
9402
|
+
currentSampleIndex[mdatStart] = {};
|
|
9403
|
+
}
|
|
9404
|
+
if (!currentSampleIndex[mdatStart][trackId]) {
|
|
9405
|
+
currentSampleIndex[mdatStart][trackId] = 0;
|
|
9406
|
+
}
|
|
9407
|
+
currentSampleIndex[mdatStart][trackId] = index;
|
|
9368
9408
|
},
|
|
9369
|
-
|
|
9370
|
-
return
|
|
9409
|
+
getCurrentSampleIndices: (mdatStart) => {
|
|
9410
|
+
return currentSampleIndex[mdatStart] ?? {};
|
|
9411
|
+
},
|
|
9412
|
+
updateAfterSeek: (seekedByte) => {
|
|
9413
|
+
currentSampleIndex = updateSampleIndicesAfterSeek({
|
|
9414
|
+
samplePositionsForMdatStart,
|
|
9415
|
+
seekedByte
|
|
9416
|
+
});
|
|
9371
9417
|
}
|
|
9372
9418
|
};
|
|
9373
9419
|
};
|
|
9420
|
+
var getSampleWithLowestDts = (samplePositions, currentSampleIndexMap) => {
|
|
9421
|
+
const lowestDts = [];
|
|
9422
|
+
for (const track of samplePositions) {
|
|
9423
|
+
const currentSampleIndex = currentSampleIndexMap[track.trackId] ?? 0;
|
|
9424
|
+
const currentSample = track.samplePositions[currentSampleIndex];
|
|
9425
|
+
if (currentSample && (lowestDts.length === 0 || currentSample.decodingTimestamp <= lowestDts[0].samplePosition.decodingTimestamp)) {
|
|
9426
|
+
lowestDts.push({
|
|
9427
|
+
samplePosition: currentSample,
|
|
9428
|
+
trackId: track.trackId,
|
|
9429
|
+
index: currentSampleIndex
|
|
9430
|
+
});
|
|
9431
|
+
}
|
|
9432
|
+
}
|
|
9433
|
+
return lowestDts;
|
|
9434
|
+
};
|
|
9374
9435
|
|
|
9375
9436
|
// src/state/iso-base-media/last-moof-box.ts
|
|
9376
9437
|
var getLastMoofBox = (boxes) => {
|
|
@@ -11727,118 +11788,6 @@ var getMoovAtom = async ({
|
|
|
11727
11788
|
return moov;
|
|
11728
11789
|
};
|
|
11729
11790
|
|
|
11730
|
-
// src/containers/iso-base-media/mdat/calculate-jump-marks.ts
|
|
11731
|
-
var MAX_SPREAD_IN_SECONDS = 8;
|
|
11732
|
-
var getKey = (samplePositionTrack) => {
|
|
11733
|
-
return `${samplePositionTrack.track.trackId}-${samplePositionTrack.samplePosition.decodingTimestamp}.${samplePositionTrack.samplePosition.offset}`;
|
|
11734
|
-
};
|
|
11735
|
-
var findBestJump = ({
|
|
11736
|
-
sampleMap,
|
|
11737
|
-
offsetsSorted,
|
|
11738
|
-
visited,
|
|
11739
|
-
progresses
|
|
11740
|
-
}) => {
|
|
11741
|
-
const minProgress = Math.min(...Object.values(progresses));
|
|
11742
|
-
const trackNumberWithLowestProgress = Object.entries(progresses).find(([, progress]) => progress === minProgress)?.[0];
|
|
11743
|
-
const firstSampleAboveMinProgress = offsetsSorted.findIndex((offset) => sampleMap.get(offset).track.trackId === Number(trackNumberWithLowestProgress) && !visited.has(getKey(sampleMap.get(offset))));
|
|
11744
|
-
if (firstSampleAboveMinProgress === -1) {
|
|
11745
|
-
const backup = offsetsSorted.findIndex((offset) => !visited.has(getKey(sampleMap.get(offset))));
|
|
11746
|
-
if (backup === -1) {
|
|
11747
|
-
throw new Error("this should not happen");
|
|
11748
|
-
}
|
|
11749
|
-
return backup;
|
|
11750
|
-
}
|
|
11751
|
-
return firstSampleAboveMinProgress;
|
|
11752
|
-
};
|
|
11753
|
-
var calculateJumpMarks = ({
|
|
11754
|
-
sampleMap,
|
|
11755
|
-
offsetsSorted,
|
|
11756
|
-
trackIds,
|
|
11757
|
-
endOfMdat
|
|
11758
|
-
}) => {
|
|
11759
|
-
const progresses = {};
|
|
11760
|
-
for (const trackId of trackIds) {
|
|
11761
|
-
progresses[trackId] = 0;
|
|
11762
|
-
}
|
|
11763
|
-
const jumpMarks = [];
|
|
11764
|
-
let indexToVisit = 0;
|
|
11765
|
-
const visited = new Set;
|
|
11766
|
-
const increaseIndex = () => {
|
|
11767
|
-
indexToVisit++;
|
|
11768
|
-
if (indexToVisit >= offsetsSorted.length) {
|
|
11769
|
-
throw new Error("should not roll over, should jump");
|
|
11770
|
-
}
|
|
11771
|
-
};
|
|
11772
|
-
let lastVisitedSample = null;
|
|
11773
|
-
const addJumpMark = ({
|
|
11774
|
-
firstSampleAboveMinProgress
|
|
11775
|
-
}) => {
|
|
11776
|
-
if (!lastVisitedSample) {
|
|
11777
|
-
throw new Error("no last visited sample");
|
|
11778
|
-
}
|
|
11779
|
-
const jumpMark = {
|
|
11780
|
-
afterSampleWithOffset: lastVisitedSample.samplePosition.offset,
|
|
11781
|
-
jumpToOffset: offsetsSorted[firstSampleAboveMinProgress]
|
|
11782
|
-
};
|
|
11783
|
-
if (firstSampleAboveMinProgress === offsetsSorted.indexOf(lastVisitedSample.samplePosition.offset) + 1) {
|
|
11784
|
-
indexToVisit = firstSampleAboveMinProgress;
|
|
11785
|
-
return;
|
|
11786
|
-
}
|
|
11787
|
-
indexToVisit = firstSampleAboveMinProgress;
|
|
11788
|
-
jumpMarks.push(jumpMark);
|
|
11789
|
-
};
|
|
11790
|
-
const addFinalJumpIfNecessary = () => {
|
|
11791
|
-
if (indexToVisit === offsetsSorted.length - 1) {
|
|
11792
|
-
return;
|
|
11793
|
-
}
|
|
11794
|
-
jumpMarks.push({
|
|
11795
|
-
afterSampleWithOffset: offsetsSorted[indexToVisit],
|
|
11796
|
-
jumpToOffset: endOfMdat
|
|
11797
|
-
});
|
|
11798
|
-
};
|
|
11799
|
-
const considerJump = () => {
|
|
11800
|
-
const firstSampleAboveMinProgress = findBestJump({
|
|
11801
|
-
sampleMap,
|
|
11802
|
-
offsetsSorted,
|
|
11803
|
-
visited,
|
|
11804
|
-
progresses
|
|
11805
|
-
});
|
|
11806
|
-
addJumpMark({ firstSampleAboveMinProgress });
|
|
11807
|
-
};
|
|
11808
|
-
while (true) {
|
|
11809
|
-
const currentSamplePosition = sampleMap.get(offsetsSorted[indexToVisit]);
|
|
11810
|
-
const sampleKey = getKey(currentSamplePosition);
|
|
11811
|
-
if (visited.has(sampleKey)) {
|
|
11812
|
-
considerJump();
|
|
11813
|
-
continue;
|
|
11814
|
-
}
|
|
11815
|
-
visited.add(sampleKey);
|
|
11816
|
-
lastVisitedSample = currentSamplePosition;
|
|
11817
|
-
if (visited.size === offsetsSorted.length) {
|
|
11818
|
-
addFinalJumpIfNecessary();
|
|
11819
|
-
break;
|
|
11820
|
-
}
|
|
11821
|
-
const timestamp = currentSamplePosition.samplePosition.decodingTimestamp / currentSamplePosition.track.originalTimescale;
|
|
11822
|
-
progresses[currentSamplePosition.track.trackId] = timestamp;
|
|
11823
|
-
const progressValues = Object.values(progresses);
|
|
11824
|
-
const maxProgress = Math.max(...progressValues);
|
|
11825
|
-
const minProgress = Math.min(...progressValues);
|
|
11826
|
-
const spread = maxProgress - minProgress;
|
|
11827
|
-
if (visited.size === offsetsSorted.length) {
|
|
11828
|
-
addFinalJumpIfNecessary();
|
|
11829
|
-
break;
|
|
11830
|
-
}
|
|
11831
|
-
if (spread > MAX_SPREAD_IN_SECONDS) {
|
|
11832
|
-
considerJump();
|
|
11833
|
-
} else if (indexToVisit === offsetsSorted.length - 1) {
|
|
11834
|
-
considerJump();
|
|
11835
|
-
} else {
|
|
11836
|
-
increaseIndex();
|
|
11837
|
-
}
|
|
11838
|
-
}
|
|
11839
|
-
return jumpMarks;
|
|
11840
|
-
};
|
|
11841
|
-
|
|
11842
11791
|
// src/containers/iso-base-media/mdat/postprocess-bytes.ts
|
|
11843
11792
|
var postprocessBytes = ({
|
|
11844
11793
|
bytes,
|
|
@@ -11899,52 +11848,53 @@ var parseMdatSection = async (state) => {
|
|
|
11899
11848
|
endOfMdat,
|
|
11900
11849
|
state
|
|
11901
11850
|
});
|
|
11851
|
+
const tracksFromMoov = getTracksFromMoovBox(moov);
|
|
11902
11852
|
state.iso.moov.setMoovBox({
|
|
11903
11853
|
moovBox: moov,
|
|
11904
11854
|
precomputed: false
|
|
11905
11855
|
});
|
|
11856
|
+
const existingTracks = state.callbacks.tracks.getTracks();
|
|
11857
|
+
for (const trackFromMoov of tracksFromMoov) {
|
|
11858
|
+
if (existingTracks.find((t) => t.trackId === trackFromMoov.trackId)) {
|
|
11859
|
+
continue;
|
|
11860
|
+
}
|
|
11861
|
+
if (trackFromMoov.type === "other") {
|
|
11862
|
+
continue;
|
|
11863
|
+
}
|
|
11864
|
+
state.callbacks.tracks.addTrack(trackFromMoov);
|
|
11865
|
+
}
|
|
11906
11866
|
state.callbacks.tracks.setIsDone(state.logLevel);
|
|
11907
11867
|
state.structure.getIsoStructure().boxes.push(moov);
|
|
11908
11868
|
return parseMdatSection(state);
|
|
11909
11869
|
}
|
|
11870
|
+
const tracks2 = state.callbacks.tracks.getTracks();
|
|
11910
11871
|
if (!state.iso.flatSamples.getSamples(mediaSection.start)) {
|
|
11911
|
-
const {
|
|
11912
|
-
flatSamples: flatSamplesMap,
|
|
11913
|
-
offsets,
|
|
11914
|
-
trackIds
|
|
11915
|
-
} = calculateFlatSamples({
|
|
11872
|
+
const samplePosition = calculateSamplePositions({
|
|
11916
11873
|
state,
|
|
11917
|
-
mediaSectionStart: mediaSection.start
|
|
11918
|
-
|
|
11919
|
-
const calcedJumpMarks = calculateJumpMarks({
|
|
11920
|
-
sampleMap: flatSamplesMap,
|
|
11921
|
-
offsetsSorted: offsets,
|
|
11922
|
-
trackIds,
|
|
11923
|
-
endOfMdat
|
|
11874
|
+
mediaSectionStart: mediaSection.start,
|
|
11875
|
+
trackIds: tracks2.map((t) => t.trackId)
|
|
11924
11876
|
});
|
|
11925
|
-
state.iso.flatSamples.
|
|
11926
|
-
state.iso.flatSamples.setSamples(mediaSection.start, flatSamplesMap);
|
|
11877
|
+
state.iso.flatSamples.setSamples(mediaSection.start, samplePosition);
|
|
11927
11878
|
}
|
|
11928
|
-
const
|
|
11929
|
-
const
|
|
11930
|
-
const
|
|
11931
|
-
|
|
11932
|
-
|
|
11933
|
-
const offsets = Array.from(flatSamples.keys());
|
|
11934
|
-
const nextSample_ = offsets.filter((s) => s > iterator.counter.getOffset()).sort((a, b) => a - b)[0];
|
|
11935
|
-
if (nextSample_) {
|
|
11936
|
-
iterator.discard(nextSample_ - iterator.counter.getOffset());
|
|
11937
|
-
return null;
|
|
11938
|
-
}
|
|
11939
|
-
Log.verbose(state.logLevel, "Could not find sample at offset", iterator.counter.getOffset(), "skipping to end of mdat");
|
|
11879
|
+
const samplePositions = state.iso.flatSamples.getSamples(mediaSection.start);
|
|
11880
|
+
const sampleIndices = state.iso.flatSamples.getCurrentSampleIndices(mediaSection.start);
|
|
11881
|
+
const nextSampleArray = getSampleWithLowestDts(samplePositions, sampleIndices);
|
|
11882
|
+
if (nextSampleArray.length === 0) {
|
|
11883
|
+
Log.verbose(state.logLevel, "Iterated over all samples.", endOfMdat);
|
|
11940
11884
|
return makeSkip(endOfMdat);
|
|
11941
11885
|
}
|
|
11942
|
-
|
|
11943
|
-
|
|
11886
|
+
const exactMatch = nextSampleArray.find((s) => s.samplePosition.offset === state.iterator.counter.getOffset());
|
|
11887
|
+
const nextSample = exactMatch ?? nextSampleArray[0];
|
|
11888
|
+
if (nextSample.samplePosition.offset !== state.iterator.counter.getOffset()) {
|
|
11889
|
+
return makeSkip(nextSample.samplePosition.offset);
|
|
11890
|
+
}
|
|
11891
|
+
if (nextSample.samplePosition.offset + nextSample.samplePosition.size > state.contentLength) {
|
|
11892
|
+
Log.verbose(state.logLevel, "Sample is beyond the end of the file. Don't process it.", nextSample.samplePosition.offset + nextSample.samplePosition.size, endOfMdat);
|
|
11944
11893
|
return makeSkip(endOfMdat);
|
|
11945
11894
|
}
|
|
11946
|
-
|
|
11947
|
-
|
|
11895
|
+
const { iterator } = state;
|
|
11896
|
+
if (iterator.bytesRemaining() < nextSample.samplePosition.size) {
|
|
11897
|
+
return makeFetchMoreData(nextSample.samplePosition.size - iterator.bytesRemaining());
|
|
11948
11898
|
}
|
|
11949
11899
|
const {
|
|
11950
11900
|
timestamp: rawCts,
|
|
@@ -11954,21 +11904,22 @@ var parseMdatSection = async (state) => {
|
|
|
11954
11904
|
offset,
|
|
11955
11905
|
bigEndian,
|
|
11956
11906
|
chunkSize
|
|
11957
|
-
} =
|
|
11907
|
+
} = nextSample.samplePosition;
|
|
11908
|
+
const track = tracks2.find((t) => t.trackId === nextSample.trackId);
|
|
11958
11909
|
const {
|
|
11959
11910
|
originalTimescale,
|
|
11960
11911
|
startInSeconds,
|
|
11961
11912
|
trackMediaTimeOffsetInTrackTimescale,
|
|
11962
11913
|
timescale: trackTimescale
|
|
11963
|
-
} =
|
|
11914
|
+
} = track;
|
|
11964
11915
|
const cts = rawCts + startInSeconds * originalTimescale - trackMediaTimeOffsetInTrackTimescale / trackTimescale * WEBCODECS_TIMESCALE;
|
|
11965
11916
|
const dts = rawDts + startInSeconds * originalTimescale - trackMediaTimeOffsetInTrackTimescale / trackTimescale * WEBCODECS_TIMESCALE;
|
|
11966
11917
|
const bytes = postprocessBytes({
|
|
11967
|
-
bytes: iterator.getSlice(
|
|
11918
|
+
bytes: iterator.getSlice(nextSample.samplePosition.size),
|
|
11968
11919
|
bigEndian,
|
|
11969
11920
|
chunkSize
|
|
11970
11921
|
});
|
|
11971
|
-
if (
|
|
11922
|
+
if (track.type === "audio") {
|
|
11972
11923
|
const audioSample = convertAudioOrVideoSampleToWebCodecsTimestamps({
|
|
11973
11924
|
sample: {
|
|
11974
11925
|
data: bytes,
|
|
@@ -11982,10 +11933,10 @@ var parseMdatSection = async (state) => {
|
|
|
11982
11933
|
});
|
|
11983
11934
|
await state.callbacks.onAudioSample({
|
|
11984
11935
|
audioSample,
|
|
11985
|
-
trackId:
|
|
11936
|
+
trackId: track.trackId
|
|
11986
11937
|
});
|
|
11987
11938
|
}
|
|
11988
|
-
if (
|
|
11939
|
+
if (track.type === "video") {
|
|
11989
11940
|
const nalUnitType = bytes[4] & 31;
|
|
11990
11941
|
let isRecoveryPoint = false;
|
|
11991
11942
|
if (nalUnitType === 6) {
|
|
@@ -12005,14 +11956,10 @@ var parseMdatSection = async (state) => {
|
|
|
12005
11956
|
});
|
|
12006
11957
|
await state.callbacks.onVideoSample({
|
|
12007
11958
|
videoSample,
|
|
12008
|
-
trackId:
|
|
11959
|
+
trackId: track.trackId
|
|
12009
11960
|
});
|
|
12010
11961
|
}
|
|
12011
|
-
|
|
12012
|
-
if (jump) {
|
|
12013
|
-
Log.verbose(state.logLevel, "Found jump mark", jump.jumpToOffset, "skipping to jump mark");
|
|
12014
|
-
return makeSkip(jump.jumpToOffset);
|
|
12015
|
-
}
|
|
11962
|
+
state.iso.flatSamples.setCurrentSampleIndex(mediaSection.start, nextSample.trackId, nextSample.index + 1);
|
|
12016
11963
|
return null;
|
|
12017
11964
|
};
|
|
12018
11965
|
|
|
@@ -16072,7 +16019,8 @@ var parseLoop = async ({
|
|
|
16072
16019
|
fields: state.fields,
|
|
16073
16020
|
src: state.src,
|
|
16074
16021
|
discardReadBytes: state.discardReadBytes,
|
|
16075
|
-
prefetchCache: state.prefetchCache
|
|
16022
|
+
prefetchCache: state.prefetchCache,
|
|
16023
|
+
isoState: state.iso
|
|
16076
16024
|
});
|
|
16077
16025
|
state.timings.timeSeeking += Date.now() - seekStart;
|
|
16078
16026
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -901,10 +901,17 @@ export declare const MediaParserInternals: {
|
|
|
901
901
|
};
|
|
902
902
|
iso: {
|
|
903
903
|
flatSamples: {
|
|
904
|
-
getSamples: (mdatStart: number) =>
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
904
|
+
getSamples: (mdatStart: number) => {
|
|
905
|
+
trackId: number;
|
|
906
|
+
samplePositions: SamplePosition[];
|
|
907
|
+
}[] | null;
|
|
908
|
+
setSamples: (mdatStart: number, samples: {
|
|
909
|
+
trackId: number;
|
|
910
|
+
samplePositions: SamplePosition[];
|
|
911
|
+
}[]) => void;
|
|
912
|
+
setCurrentSampleIndex: (mdatStart: number, trackId: number, index: number) => void;
|
|
913
|
+
getCurrentSampleIndices: (mdatStart: number) => Record<number, number>;
|
|
914
|
+
updateAfterSeek: (seekedByte: number) => void;
|
|
908
915
|
};
|
|
909
916
|
moov: {
|
|
910
917
|
setMoovBox: (moov: {
|
package/dist/parse-loop.js
CHANGED
package/dist/perform-seek.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ import type { MediaParserLogLevel } from './log';
|
|
|
6
6
|
import type { ParseMediaMode, ParseMediaSrc } from './options';
|
|
7
7
|
import type { MediaParserReaderInterface } from './readers/reader';
|
|
8
8
|
import type { CurrentReader } from './state/current-reader';
|
|
9
|
+
import type { IsoBaseMediaState } from './state/iso-base-media/iso-state';
|
|
9
10
|
import type { SeekInfiniteLoop } from './state/seek-infinite-loop';
|
|
10
11
|
import type { MediaSectionState } from './state/video-section';
|
|
11
|
-
export declare const performSeek: ({ seekTo, userInitiated, controller, mediaSection, iterator, seekInfiniteLoop, logLevel, mode, contentLength, currentReader, readerInterface, src, discardReadBytes, fields, prefetchCache, }: {
|
|
12
|
+
export declare const performSeek: ({ seekTo, userInitiated, controller, mediaSection, iterator, seekInfiniteLoop, logLevel, mode, contentLength, currentReader, readerInterface, src, discardReadBytes, fields, prefetchCache, isoState, }: {
|
|
12
13
|
seekTo: number;
|
|
13
14
|
userInitiated: boolean;
|
|
14
15
|
controller: MediaParserController;
|
|
@@ -24,4 +25,5 @@ export declare const performSeek: ({ seekTo, userInitiated, controller, mediaSec
|
|
|
24
25
|
src: ParseMediaSrc;
|
|
25
26
|
discardReadBytes: (force: boolean) => Promise<void>;
|
|
26
27
|
prefetchCache: PrefetchCache;
|
|
28
|
+
isoState: IsoBaseMediaState;
|
|
27
29
|
}) => Promise<void>;
|
package/dist/perform-seek.js
CHANGED
|
@@ -5,7 +5,7 @@ const log_1 = require("./log");
|
|
|
5
5
|
const seek_backwards_1 = require("./seek-backwards");
|
|
6
6
|
const seek_forwards_1 = require("./seek-forwards");
|
|
7
7
|
const video_section_1 = require("./state/video-section");
|
|
8
|
-
const performSeek = async ({ seekTo, userInitiated, controller, mediaSection, iterator, seekInfiniteLoop, logLevel, mode, contentLength, currentReader, readerInterface, src, discardReadBytes, fields, prefetchCache, }) => {
|
|
8
|
+
const performSeek = async ({ seekTo, userInitiated, controller, mediaSection, iterator, seekInfiniteLoop, logLevel, mode, contentLength, currentReader, readerInterface, src, discardReadBytes, fields, prefetchCache, isoState, }) => {
|
|
9
9
|
const byteInMediaSection = (0, video_section_1.isByteInMediaSection)({
|
|
10
10
|
position: seekTo,
|
|
11
11
|
mediaSections: mediaSection.getMediaSections(),
|
|
@@ -69,6 +69,9 @@ const performSeek = async ({ seekTo, userInitiated, controller, mediaSection, it
|
|
|
69
69
|
prefetchCache,
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
+
if (userInitiated) {
|
|
73
|
+
isoState.flatSamples.updateAfterSeek(seekTo);
|
|
74
|
+
}
|
|
72
75
|
await controller._internals.checkForAbortAndPause();
|
|
73
76
|
};
|
|
74
77
|
exports.performSeek = performSeek;
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
import type { JumpMark } from '../../containers/iso-base-media/mdat/calculate-jump-marks';
|
|
2
1
|
import type { SamplePosition } from '../../get-sample-positions';
|
|
3
|
-
import type { MediaParserAudioTrack, MediaParserOtherTrack, MediaParserVideoTrack } from '../../get-tracks';
|
|
4
2
|
import type { ParserState } from '../parser-state';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
export type MinimalFlatSampleForTesting = {
|
|
10
|
-
track: {
|
|
11
|
-
trackId: number;
|
|
12
|
-
originalTimescale: number;
|
|
13
|
-
type: 'audio' | 'video' | 'other';
|
|
14
|
-
};
|
|
15
|
-
samplePosition: {
|
|
16
|
-
decodingTimestamp: number;
|
|
17
|
-
offset: number;
|
|
18
|
-
};
|
|
3
|
+
type TrackIdAndSamplePositions = {
|
|
4
|
+
trackId: number;
|
|
5
|
+
samplePositions: SamplePosition[];
|
|
19
6
|
};
|
|
20
|
-
export declare const
|
|
7
|
+
export declare const calculateSamplePositions: ({ state, mediaSectionStart, trackIds, }: {
|
|
21
8
|
state: ParserState;
|
|
22
9
|
mediaSectionStart: number;
|
|
23
|
-
}) => {
|
|
24
|
-
flatSamples: Map<number, FlatSample>;
|
|
25
|
-
offsets: number[];
|
|
26
10
|
trackIds: number[];
|
|
27
|
-
};
|
|
11
|
+
}) => TrackIdAndSamplePositions[];
|
|
28
12
|
export declare const cachedSamplePositionsState: () => {
|
|
29
|
-
getSamples: (mdatStart: number) =>
|
|
30
|
-
setSamples: (mdatStart: number, samples:
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
getSamples: (mdatStart: number) => TrackIdAndSamplePositions[] | null;
|
|
14
|
+
setSamples: (mdatStart: number, samples: TrackIdAndSamplePositions[]) => void;
|
|
15
|
+
setCurrentSampleIndex: (mdatStart: number, trackId: number, index: number) => void;
|
|
16
|
+
getCurrentSampleIndices: (mdatStart: number) => Record<number, number>;
|
|
17
|
+
updateAfterSeek: (seekedByte: number) => void;
|
|
18
|
+
};
|
|
19
|
+
type Lowest = {
|
|
20
|
+
samplePosition: SamplePosition;
|
|
21
|
+
trackId: number;
|
|
22
|
+
index: number;
|
|
33
23
|
};
|
|
24
|
+
export declare const getSampleWithLowestDts: (samplePositions: TrackIdAndSamplePositions[], currentSampleIndexMap: Record<number, number>) => Lowest[];
|
|
25
|
+
export {};
|