@blockcast/mmt-container 2.2.0-main.da2e7cd1dd5d → 2.2.0-main.ef09fa701ea8
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/browser-runtime.js +1447 -179
- package/dist/browser-runtime.js.map +3 -3
- package/dist/cmaf-block-assembler.js +92 -1
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/codec-utils.d.ts.map +1 -1
- package/dist/codec-utils.js +92 -1
- package/dist/codec-utils.js.map +2 -2
- package/dist/delivery-catalog.js +2 -1
- package/dist/delivery-catalog.js.map +2 -2
- package/dist/delta-fallback-config.js.map +1 -1
- package/dist/fec-manager.d.ts +105 -14
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +502 -58
- package/dist/fec-manager.js.map +2 -2
- package/dist/fec-worker-setup.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +48 -13
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +97 -25
- package/dist/iso-block-locator.js.map +2 -2
- package/dist/iso-bmff-timing.d.ts +10 -1
- package/dist/iso-bmff-timing.d.ts.map +1 -1
- package/dist/iso-bmff-timing.js +36 -2
- package/dist/iso-bmff-timing.js.map +2 -2
- package/dist/media-router.js.map +1 -1
- package/dist/mmtp-container-parser.d.ts +104 -12
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +308 -27
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +310 -30
- package/dist/mmtp-container-parser.no-modules.js.map +3 -3
- package/dist/mmtp-decode-pipeline.js +307 -27
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-router.d.ts +36 -8
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +675 -75
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-manager.d.ts +26 -3
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1267 -152
- package/dist/multicast-manager.js.map +3 -3
- package/dist/multicast-transport.js +4 -3
- package/dist/multicast-transport.js.map +2 -2
- package/dist/no-modules.js +307 -27
- package/dist/no-modules.js.map +3 -3
- package/dist/repair-fetch.d.ts +38 -8
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +286 -27
- package/dist/repair-fetch.js.map +3 -3
- package/dist/track-session.d.ts.map +1 -1
- package/dist/track-session.js +1 -0
- package/dist/track-session.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +307 -27
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +5 -5
- package/src/codec-utils.ts +121 -1
- package/src/fec-manager.ts +571 -32
- package/src/index.ts +3 -0
- package/src/iso-block-locator.ts +133 -31
- package/src/iso-bmff-timing.ts +40 -1
- package/src/mmtp-container-parser.ts +341 -32
- package/src/mmtp-router.ts +600 -55
- package/src/multicast-manager.ts +136 -16
- package/src/repair-fetch.ts +366 -50
- package/src/track-session.ts +3 -0
package/dist/no-modules.js
CHANGED
|
@@ -4576,9 +4576,10 @@ function isH264IntraSlice(nal) {
|
|
|
4576
4576
|
const sliceType = readH264SliceType(nal);
|
|
4577
4577
|
return sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9;
|
|
4578
4578
|
}
|
|
4579
|
+
var H264_SLICE_TYPE_ESCAPED_BYTES = 32;
|
|
4579
4580
|
function readH264SliceType(nal) {
|
|
4580
4581
|
if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
|
|
4581
|
-
const rbsp = removeEmulationPrevention(nal.subarray(1));
|
|
4582
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1, 1 + H264_SLICE_TYPE_ESCAPED_BYTES));
|
|
4582
4583
|
const state = { bitOffset: 0 };
|
|
4583
4584
|
if (readUnsignedExpGolomb(rbsp, state) === null) return null;
|
|
4584
4585
|
return readUnsignedExpGolomb(rbsp, state);
|
|
@@ -4725,6 +4726,96 @@ if (void 0) {
|
|
|
4725
4726
|
]))).toBe(false);
|
|
4726
4727
|
});
|
|
4727
4728
|
});
|
|
4729
|
+
describe("readH264SliceType", () => {
|
|
4730
|
+
const wholeNalSliceType = (nal) => {
|
|
4731
|
+
if (nal.length < 2 || (nal[0] & 31) !== 1) return null;
|
|
4732
|
+
const rbsp = removeEmulationPrevention(nal.subarray(1));
|
|
4733
|
+
const state = { bitOffset: 0 };
|
|
4734
|
+
if (readUnsignedExpGolomb(rbsp, state) === null) return null;
|
|
4735
|
+
return readUnsignedExpGolomb(rbsp, state);
|
|
4736
|
+
};
|
|
4737
|
+
const hex2 = (text2) => Uint8Array.from(text2.match(/../g), (byte) => parseInt(byte, 16));
|
|
4738
|
+
const ue = (value) => {
|
|
4739
|
+
const code = (value + 1).toString(2);
|
|
4740
|
+
return "0".repeat(code.length - 1) + code;
|
|
4741
|
+
};
|
|
4742
|
+
const sliceNal = (bits) => {
|
|
4743
|
+
const rbsp = `${bits}1`.padEnd(Math.ceil((bits.length + 1) / 8) * 8, "0").match(/.{8}/g);
|
|
4744
|
+
const nal = [1];
|
|
4745
|
+
let zeros = 0;
|
|
4746
|
+
for (const byte of rbsp.map((bits8) => parseInt(bits8, 2))) {
|
|
4747
|
+
if (zeros >= 2 && byte <= 3) {
|
|
4748
|
+
nal.push(3);
|
|
4749
|
+
zeros = 0;
|
|
4750
|
+
}
|
|
4751
|
+
nal.push(byte);
|
|
4752
|
+
zeros = byte === 0 ? zeros + 1 : 0;
|
|
4753
|
+
}
|
|
4754
|
+
return Uint8Array.from(nal);
|
|
4755
|
+
};
|
|
4756
|
+
const x264Slices = [
|
|
4757
|
+
["64x48 P", hex2("419a231885bfd53888f63ef5b1e1e39b9ff2eabf03fd3f4d7d4317ffcbf75176"), 5, false],
|
|
4758
|
+
["64x48 B", hex2("419e414212fffeeade283707cb70f7"), 6, false],
|
|
4759
|
+
["64x48 non-IDR I", hex2(
|
|
4760
|
+
"4128899037f384db2be0cfe48aa23558781dd429f7db8e8a6ae44f7ca2333ba1029477da6ddfeac61843c5680cbf66247469d64549b0f5f7ca6acc529f5cf032b35d8dedc6b2412ece24f42f80b593fc0f3ff47a08c84799ff2ada18ac39a527e23eb34c8167fd"
|
|
4761
|
+
), 7, true],
|
|
4762
|
+
["1280x720 B, escape at byte 10", hex2(
|
|
4763
|
+
"01006e27a81109ff000003016b662ea5ea46000f57880f3fb0d3f03ff7dac0546fc9966a5f6d86cb795db178882f6e19b75d92170917306190f262fd58268702db2eff86a9651e48"
|
|
4764
|
+
), 6, false],
|
|
4765
|
+
["1280x720 P, escape at byte 15", hex2(
|
|
4766
|
+
"41006e26a8cd1329e1bffea784000003002b5ef096f0320bd99f00037f22327e886223b7996bb04acd35ad9a0385f02c1801eb6226bc94993d1880172ffbb23db74729569b6f3934cba0cba17b7c29ce0e216080cb7b18e5876df59e85302da9cba203fe6769178a2e02eeaa54a6f87568cbaa019a3442eae19c8a7adc8cd02441bee573c5408b6552abd2d9d3"
|
|
4767
|
+
), 5, false],
|
|
4768
|
+
["1280x720 B, escape at byte 22", hex2("01006e27da9109ff01a4c1dbc27ed915a3172ec80000030352"), 6, false],
|
|
4769
|
+
["7680x4320 IDR, first_mb_in_slice 97440", hex2(
|
|
4770
|
+
"650000be5088843a118a000218f1c00040f63800087949c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9"
|
|
4771
|
+
), null, true],
|
|
4772
|
+
["7680x4320 P, first_mb_in_slice 32640", hex2(
|
|
4773
|
+
"410003fc09a20a806ff0ae0085a611cc7ad5f2020e25900ba4c3398016b57e100011021220200020"
|
|
4774
|
+
), 5, false],
|
|
4775
|
+
["7680x4320 P, first_mb_in_slice 97440", hex2(
|
|
4776
|
+
"410000be509a20a8078f5a83cc40d800783b017f5c6d7e4883fb4801a9c569245bd04135f7c00806"
|
|
4777
|
+
), 5, false]
|
|
4778
|
+
];
|
|
4779
|
+
const syntheticSlices = [
|
|
4780
|
+
["an escape inside first_mb_in_slice", sliceNal(ue(2 ** 24 - 1) + ue(2)), 2],
|
|
4781
|
+
["an escape between the fields", sliceNal(ue(2 ** 21 - 1) + ue(7)), 7],
|
|
4782
|
+
["an escape inside slice_type", sliceNal(ue(0) + ue(2 ** 22 - 1)), 2 ** 22 - 1],
|
|
4783
|
+
["the longest fields, five escapes", sliceNal(ue(2 ** 30 - 1) + ue(2 ** 30 - 1)), 2 ** 30 - 1],
|
|
4784
|
+
["the largest values", sliceNal(ue(2 ** 31 - 2) + ue(2 ** 31 - 2)), 2 ** 31 - 2],
|
|
4785
|
+
["31 leading zeros in first_mb_in_slice", sliceNal(`${"0".repeat(31)}1`), null],
|
|
4786
|
+
["31 leading zeros in slice_type", sliceNal(`1${"0".repeat(31)}1`), null],
|
|
4787
|
+
["escapes running past the slice header", sliceNal(ue(0) + ue(5) + "0".repeat(400)), 5]
|
|
4788
|
+
];
|
|
4789
|
+
test("reads the slice_type of real and synthetic slices", () => {
|
|
4790
|
+
for (const [name, nal, sliceType] of [...x264Slices, ...syntheticSlices]) {
|
|
4791
|
+
expect(readH264SliceType(nal), name).toBe(sliceType);
|
|
4792
|
+
}
|
|
4793
|
+
});
|
|
4794
|
+
test("matches the whole-NAL unescape at every truncation", () => {
|
|
4795
|
+
for (const [name, nal] of [...x264Slices, ...syntheticSlices]) {
|
|
4796
|
+
for (let end = 0; end <= nal.length; end++) {
|
|
4797
|
+
const cut = nal.subarray(0, end);
|
|
4798
|
+
expect(readH264SliceType(cut), `${name}, first ${end} bytes`).toBe(wholeNalSliceType(cut));
|
|
4799
|
+
}
|
|
4800
|
+
}
|
|
4801
|
+
});
|
|
4802
|
+
test("matches the whole-NAL unescape on zero-heavy NAL units", () => {
|
|
4803
|
+
const bytes = [0, 0, 0, 3, 1, 2, 128, 255];
|
|
4804
|
+
let seed = 1;
|
|
4805
|
+
const next = () => (seed = Math.imul(seed, 1103515245) + 12345 >>> 0) >>> 16;
|
|
4806
|
+
for (let i = 0; i < 5e3; i++) {
|
|
4807
|
+
const nal = new Uint8Array(2 + next() % 63);
|
|
4808
|
+
nal[0] = 65;
|
|
4809
|
+
for (let j = 1; j < nal.length; j++) nal[j] = bytes[next() % bytes.length];
|
|
4810
|
+
expect(readH264SliceType(nal), Array.from(nal).join()).toBe(wholeNalSliceType(nal));
|
|
4811
|
+
}
|
|
4812
|
+
});
|
|
4813
|
+
test("classifies the x264 slices as keyframes or not", () => {
|
|
4814
|
+
for (const [name, nal, , keyframe] of x264Slices) {
|
|
4815
|
+
expect(classifyH264Keyframe(rawH264NalToAvcc(nal), { allowPartialAvcc: true }), name).toBe(keyframe);
|
|
4816
|
+
}
|
|
4817
|
+
});
|
|
4818
|
+
});
|
|
4728
4819
|
describe("avccToAnnexB", () => {
|
|
4729
4820
|
test("converts with SPS/PPS on keyframe", () => {
|
|
4730
4821
|
const avcc = new Uint8Array([0, 0, 0, 3, 101, 170, 187]);
|
|
@@ -5568,9 +5659,21 @@ var IsoBmffTimingResolver = class {
|
|
|
5568
5659
|
}
|
|
5569
5660
|
#track = null;
|
|
5570
5661
|
#fragments = /* @__PURE__ */ new Map();
|
|
5662
|
+
/** First sample of each pending fragment, kept in `#delivered` with its sample count. */
|
|
5663
|
+
#firstSamples = /* @__PURE__ */ new Map();
|
|
5664
|
+
/**
|
|
5665
|
+
* First sample and sample count of the newest fragments whose every slot was
|
|
5666
|
+
* cleared. Abandonment counts: `releaseSample` clears a slot too, which
|
|
5667
|
+
* matches the combiner, since it retires an abandoned sample as well.
|
|
5668
|
+
*/
|
|
5669
|
+
#delivered = /* @__PURE__ */ new Map();
|
|
5571
5670
|
#pendingSamples = 0;
|
|
5572
5671
|
#evictedSamples = 0;
|
|
5573
5672
|
#lastMovieFragmentRejection = null;
|
|
5673
|
+
/** True once an FT=0 has bound the track that FT=1 timing is read against. */
|
|
5674
|
+
get initialized() {
|
|
5675
|
+
return this.#track !== null;
|
|
5676
|
+
}
|
|
5574
5677
|
get pendingSampleCount() {
|
|
5575
5678
|
return this.#pendingSamples;
|
|
5576
5679
|
}
|
|
@@ -5594,7 +5697,14 @@ var IsoBmffTimingResolver = class {
|
|
|
5594
5697
|
this.#track = timing;
|
|
5595
5698
|
return true;
|
|
5596
5699
|
}
|
|
5597
|
-
|
|
5700
|
+
/**
|
|
5701
|
+
* `recovered` marks an FEC-recovered copy. A recovered block hands back
|
|
5702
|
+
* every FT=1 it holds, the received ones included, so a recovered copy of a
|
|
5703
|
+
* fragment whose samples are all done is a duplicate: admitting it again
|
|
5704
|
+
* would charge stale timing and could displace the live MPU's. A source
|
|
5705
|
+
* copy is still admitted again (a rendition switch re-arms timing that way).
|
|
5706
|
+
*/
|
|
5707
|
+
addMovieFragment(mpuSequenceNumber, data, additionalSampleLimit = this.maxPendingSamples, recovered = false) {
|
|
5598
5708
|
this.#lastMovieFragmentRejection = null;
|
|
5599
5709
|
if (!Number.isInteger(additionalSampleLimit) || additionalSampleLimit < 0) {
|
|
5600
5710
|
this.#lastMovieFragmentRejection = "invalid";
|
|
@@ -5620,6 +5730,8 @@ var IsoBmffTimingResolver = class {
|
|
|
5620
5730
|
(sample, index) => sample !== null && sameSample(sample, parsed.samples[index])
|
|
5621
5731
|
);
|
|
5622
5732
|
}
|
|
5733
|
+
const delivered = recovered ? this.#delivered.get(key) : void 0;
|
|
5734
|
+
if (delivered && delivered.sampleCount === parsed.samples.length && sameSample(delivered.first, parsed.samples[0])) return true;
|
|
5623
5735
|
let freed = 0;
|
|
5624
5736
|
while (this.#fragments.size > 0 && (this.#pendingSamples + parsed.samples.length > this.maxPendingSamples || parsed.samples.length - freed > additionalSampleLimit)) {
|
|
5625
5737
|
freed += this.#evictOldestFragment();
|
|
@@ -5633,6 +5745,7 @@ var IsoBmffTimingResolver = class {
|
|
|
5633
5745
|
return false;
|
|
5634
5746
|
}
|
|
5635
5747
|
this.#fragments.set(key, [...parsed.samples]);
|
|
5748
|
+
this.#firstSamples.set(key, parsed.samples[0]);
|
|
5636
5749
|
this.#pendingSamples += parsed.samples.length;
|
|
5637
5750
|
return true;
|
|
5638
5751
|
}
|
|
@@ -5690,6 +5803,7 @@ var IsoBmffTimingResolver = class {
|
|
|
5690
5803
|
let live = 0;
|
|
5691
5804
|
for (const sample of samples) if (sample !== null) live++;
|
|
5692
5805
|
this.#fragments.delete(oldest);
|
|
5806
|
+
this.#firstSamples.delete(oldest);
|
|
5693
5807
|
this.#pendingSamples -= live;
|
|
5694
5808
|
this.#evictedSamples += live;
|
|
5695
5809
|
return live;
|
|
@@ -5705,12 +5819,23 @@ var IsoBmffTimingResolver = class {
|
|
|
5705
5819
|
if (!samples || !samples[index]) return false;
|
|
5706
5820
|
samples[index] = null;
|
|
5707
5821
|
this.#pendingSamples--;
|
|
5708
|
-
if (samples.every((value) => value === null))
|
|
5822
|
+
if (samples.every((value) => value === null)) {
|
|
5823
|
+
this.#fragments.delete(key);
|
|
5824
|
+
const first = this.#firstSamples.get(key);
|
|
5825
|
+
this.#firstSamples.delete(key);
|
|
5826
|
+
this.#delivered.delete(key);
|
|
5827
|
+
this.#delivered.set(key, { first, sampleCount: samples.length });
|
|
5828
|
+
if (this.#delivered.size > this.maxPendingSamples) {
|
|
5829
|
+
this.#delivered.delete(this.#delivered.keys().next().value);
|
|
5830
|
+
}
|
|
5831
|
+
}
|
|
5709
5832
|
return true;
|
|
5710
5833
|
}
|
|
5711
5834
|
reset() {
|
|
5712
5835
|
this.#track = null;
|
|
5713
5836
|
this.#fragments.clear();
|
|
5837
|
+
this.#firstSamples.clear();
|
|
5838
|
+
this.#delivered.clear();
|
|
5714
5839
|
this.#pendingSamples = 0;
|
|
5715
5840
|
}
|
|
5716
5841
|
};
|
|
@@ -5880,6 +6005,9 @@ function authoredGap(before, after) {
|
|
|
5880
6005
|
function ssIdAfter(a, b) {
|
|
5881
6006
|
return (a - b | 0) > 0;
|
|
5882
6007
|
}
|
|
6008
|
+
function holdsRebuilt(stream) {
|
|
6009
|
+
return stream.buf.some(({ meta }) => meta.fecSbnFirst !== void 0);
|
|
6010
|
+
}
|
|
5883
6011
|
var FecReleaseSequencer = class {
|
|
5884
6012
|
#streams = /* @__PURE__ */ new Map();
|
|
5885
6013
|
#gate;
|
|
@@ -5942,6 +6070,7 @@ var FecReleaseSequencer = class {
|
|
|
5942
6070
|
stream.lastSbn = void 0;
|
|
5943
6071
|
stream.discontinuity = false;
|
|
5944
6072
|
stream.rapSsId = void 0;
|
|
6073
|
+
stream.sourced = false;
|
|
5945
6074
|
}
|
|
5946
6075
|
if (stream.last !== null && compareFrameOrder(frame, stream.last) <= 0) {
|
|
5947
6076
|
this.#recordStat("droppedStale");
|
|
@@ -5968,6 +6097,7 @@ var FecReleaseSequencer = class {
|
|
|
5968
6097
|
if (compareFrameOrder(stream.buf[mid], frame) < 0) lo = mid + 1;
|
|
5969
6098
|
else hi = mid;
|
|
5970
6099
|
}
|
|
6100
|
+
if (stream.buf[lo]?.passed === true) frame.passed = true;
|
|
5971
6101
|
stream.buf.splice(lo, 0, frame);
|
|
5972
6102
|
this.#drainUnlessDeferred(stream);
|
|
5973
6103
|
}
|
|
@@ -6003,6 +6133,41 @@ var FecReleaseSequencer = class {
|
|
|
6003
6133
|
}
|
|
6004
6134
|
return false;
|
|
6005
6135
|
}
|
|
6136
|
+
/**
|
|
6137
|
+
* These streams' sink is being replaced by one that has seen no source
|
|
6138
|
+
* frame yet. First, from a stream that holds a frame the overlay rebuilt,
|
|
6139
|
+
* release to the sink being replaced the frames the unanchored path had
|
|
6140
|
+
* already released to it (#cursorPassed): there they waited in its queue,
|
|
6141
|
+
* which its replacement flushes. A stream that holds none is not drained:
|
|
6142
|
+
* it holds nothing the anchor kept back, and a drain would still force out
|
|
6143
|
+
* a frame held past the hold limit, which before the anchor waited for the
|
|
6144
|
+
* next push. Then treat the streams as unsourced until a source frame is
|
|
6145
|
+
* released.
|
|
6146
|
+
*/
|
|
6147
|
+
unsource(packetId, catalogTrackName) {
|
|
6148
|
+
for (const stream of this.#streams.values()) {
|
|
6149
|
+
if (stream.packetId === packetId && (catalogTrackName === void 0 || stream.catalogTrackName === catalogTrackName)) {
|
|
6150
|
+
if (stream.draining === 0 && holdsRebuilt(stream)) {
|
|
6151
|
+
if (this.#deferDepth > 0) this.#deferredStreams.add(stream);
|
|
6152
|
+
else this.#drain(stream, true);
|
|
6153
|
+
}
|
|
6154
|
+
stream.sourced = false;
|
|
6155
|
+
}
|
|
6156
|
+
}
|
|
6157
|
+
}
|
|
6158
|
+
/**
|
|
6159
|
+
* Whether a stream of `packetId` holds a frame the keyframe overlay rebuilt
|
|
6160
|
+
* (FrameMeta.fecSbnFirst). Without `catalogTrackName`, every stream of the
|
|
6161
|
+
* packetId.
|
|
6162
|
+
*/
|
|
6163
|
+
holdsRebuilt(packetId, catalogTrackName) {
|
|
6164
|
+
for (const stream of this.#streams.values()) {
|
|
6165
|
+
if (stream.packetId !== packetId) continue;
|
|
6166
|
+
if (catalogTrackName !== void 0 && stream.catalogTrackName !== catalogTrackName) continue;
|
|
6167
|
+
if (holdsRebuilt(stream)) return true;
|
|
6168
|
+
}
|
|
6169
|
+
return false;
|
|
6170
|
+
}
|
|
6006
6171
|
/** Re-evaluate held gaps after FEC state changed. */
|
|
6007
6172
|
poke(streamKey) {
|
|
6008
6173
|
if (streamKey !== void 0) {
|
|
@@ -6094,16 +6259,32 @@ var FecReleaseSequencer = class {
|
|
|
6094
6259
|
last: null,
|
|
6095
6260
|
lastSbn: void 0,
|
|
6096
6261
|
discontinuity: false,
|
|
6097
|
-
rapSsId: void 0
|
|
6262
|
+
rapSsId: void 0,
|
|
6263
|
+
sourced: false,
|
|
6264
|
+
draining: 0
|
|
6098
6265
|
};
|
|
6099
6266
|
this.#streams.set(streamKey, stream);
|
|
6100
6267
|
}
|
|
6101
6268
|
return stream;
|
|
6102
6269
|
}
|
|
6103
|
-
#
|
|
6270
|
+
/** `asUnanchored`: release overlay-rebuilt frames when unanchored did (#cursorPassed). */
|
|
6271
|
+
#drain(stream, asUnanchored = false) {
|
|
6272
|
+
stream.draining++;
|
|
6273
|
+
try {
|
|
6274
|
+
this.#drainLoop(stream, asUnanchored);
|
|
6275
|
+
} finally {
|
|
6276
|
+
stream.draining--;
|
|
6277
|
+
}
|
|
6278
|
+
}
|
|
6279
|
+
#drainLoop(stream, asUnanchored) {
|
|
6104
6280
|
while (stream.buf.length > 0 && stream.last !== null) {
|
|
6105
6281
|
const head = stream.buf[0];
|
|
6106
6282
|
const last = stream.last;
|
|
6283
|
+
if (compareFrameOrder(head, last) <= 0) {
|
|
6284
|
+
stream.buf.shift();
|
|
6285
|
+
this.#release(stream, head, void 0);
|
|
6286
|
+
continue;
|
|
6287
|
+
}
|
|
6107
6288
|
if (stream.discontinuity) {
|
|
6108
6289
|
stream.discontinuity = false;
|
|
6109
6290
|
stream.buf.shift();
|
|
@@ -6117,9 +6298,10 @@ var FecReleaseSequencer = class {
|
|
|
6117
6298
|
}
|
|
6118
6299
|
const headSbn = head.meta.fecSbn;
|
|
6119
6300
|
const from = stream.lastSbn ?? headSbn;
|
|
6120
|
-
const to = headSbn ?? stream.lastSbn;
|
|
6301
|
+
const to = head.meta.fecSbnFirst ?? headSbn ?? stream.lastSbn;
|
|
6121
6302
|
let lost = [];
|
|
6122
6303
|
const unanchored = from === void 0 && to === void 0;
|
|
6304
|
+
let unresolved = false;
|
|
6123
6305
|
if (from !== void 0 && to !== void 0) {
|
|
6124
6306
|
const resolved = this.#gate.resolvedLoss(
|
|
6125
6307
|
stream.packetId,
|
|
@@ -6128,7 +6310,8 @@ var FecReleaseSequencer = class {
|
|
|
6128
6310
|
Math.max(from, to),
|
|
6129
6311
|
from
|
|
6130
6312
|
);
|
|
6131
|
-
|
|
6313
|
+
unresolved = resolved === null;
|
|
6314
|
+
if (unresolved && !this.#cursorPassed(stream, asUnanchored) && !this.#unrepairableWaitOver(stream, last, head, from, to)) {
|
|
6132
6315
|
const heldMs = performance.now() - head.arrivedAtMs;
|
|
6133
6316
|
if (heldMs <= this.#gate.holdLimitMs(stream.packetId, stream.catalogTrackName)) return;
|
|
6134
6317
|
this.#recordStat("forcedWindowFlushes");
|
|
@@ -6136,22 +6319,69 @@ var FecReleaseSequencer = class {
|
|
|
6136
6319
|
this.#release(stream, head, this.#gate.decide(last, head, [], true));
|
|
6137
6320
|
continue;
|
|
6138
6321
|
}
|
|
6139
|
-
lost = resolved;
|
|
6322
|
+
lost = resolved ?? [];
|
|
6140
6323
|
}
|
|
6141
6324
|
stream.buf.shift();
|
|
6142
6325
|
this.#release(
|
|
6143
6326
|
stream,
|
|
6144
6327
|
head,
|
|
6145
|
-
lost.length > 0 || unanchored || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
|
|
6328
|
+
lost.length > 0 || unanchored || unresolved || authoredGap(last.meta, head.meta) ? this.#gate.decide(last, head, lost, false) : void 0
|
|
6146
6329
|
);
|
|
6147
6330
|
}
|
|
6148
6331
|
}
|
|
6332
|
+
/**
|
|
6333
|
+
* The head has waited out a gap only a late source can still fill
|
|
6334
|
+
* (FecReleaseGate.unrepairableWaitMs). Not yet: the gate is asked to poke
|
|
6335
|
+
* the stream when it has (`wakeAt`), since no packet may come by then.
|
|
6336
|
+
*/
|
|
6337
|
+
#unrepairableWaitOver(stream, last, head, from, to) {
|
|
6338
|
+
const waitMs = this.#gate.unrepairableWaitMs?.(last, head, from, to);
|
|
6339
|
+
if (waitMs === void 0) return false;
|
|
6340
|
+
const atMs = head.arrivedAtMs + waitMs;
|
|
6341
|
+
if (performance.now() >= atMs) return true;
|
|
6342
|
+
this.#gate.wakeAt?.(stream.packetId, stream.catalogTrackName, atMs);
|
|
6343
|
+
return false;
|
|
6344
|
+
}
|
|
6345
|
+
/**
|
|
6346
|
+
* An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
|
|
6347
|
+
* source cursor holds it unanchored, and neither does a later frame behind
|
|
6348
|
+
* it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
|
|
6349
|
+
* fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
|
|
6350
|
+
* like each frame that arrived in front of it since (stale there). The head
|
|
6351
|
+
* then goes, decided as it would be unanchored, once a frame the base path
|
|
6352
|
+
* delivered (a source frame, or one base FEC recovered) is buffered after a
|
|
6353
|
+
* marked one: the base path has passed that one, so a frame still missing
|
|
6354
|
+
* before it can only come from a repair. It also goes while no source frame
|
|
6355
|
+
* has been released, when the direct path shows a recovered frame at once.
|
|
6356
|
+
* And it goes at once while a staged switch decides on when frames arrive
|
|
6357
|
+
* (FecReleaseGate.releaseUnanchored), and when unsource releases into a
|
|
6358
|
+
* sink being replaced: unanchored, it had already reached the sink.
|
|
6359
|
+
* The scan also writes: the `passed` marks it sets stay on the frames,
|
|
6360
|
+
* and push marks a frame it inserts in front of a marked one from them.
|
|
6361
|
+
*/
|
|
6362
|
+
#cursorPassed(stream, asUnanchored) {
|
|
6363
|
+
let at = -1;
|
|
6364
|
+
for (let i = 0; i < stream.buf.length; i++) {
|
|
6365
|
+
const frame = stream.buf[i];
|
|
6366
|
+
if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
|
|
6367
|
+
frame.passed = true;
|
|
6368
|
+
if (at < 0) at = i;
|
|
6369
|
+
} else if (frame.passed !== true) break;
|
|
6370
|
+
}
|
|
6371
|
+
if (at < 0) return false;
|
|
6372
|
+
return asUnanchored || !stream.sourced || this.#gate.releaseUnanchored?.(stream.packetId, stream.catalogTrackName) === true || stream.buf.some(({ meta }, i) => i > at && meta.fecSbnFirst === void 0 && (meta.recovered !== true || meta.fecSbn !== void 0));
|
|
6373
|
+
}
|
|
6149
6374
|
#release(stream, frame, decision) {
|
|
6375
|
+
const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
|
|
6376
|
+
if (stale) this.#recordStat("droppedStale");
|
|
6150
6377
|
if (decision) frame.meta.gapBefore = decision;
|
|
6151
6378
|
stream.last = frame;
|
|
6152
|
-
if (frame.meta.fecSbn !== void 0
|
|
6379
|
+
if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
|
|
6380
|
+
stream.lastSbn = frame.meta.fecSbn;
|
|
6381
|
+
}
|
|
6382
|
+
if (frame.meta.recovered !== true) stream.sourced = true;
|
|
6153
6383
|
this.#gate.onReleased?.(frame.data, frame.meta);
|
|
6154
|
-
this.#emit(frame.data, frame.meta);
|
|
6384
|
+
if (!stale) this.#emit(frame.data, frame.meta);
|
|
6155
6385
|
}
|
|
6156
6386
|
};
|
|
6157
6387
|
var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
|
|
@@ -6192,6 +6422,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6192
6422
|
this.#reclaimedTimingSamples = 0;
|
|
6193
6423
|
this.#evictedTimingSamples = 0;
|
|
6194
6424
|
this.#rejectedMovieFragments = 0;
|
|
6425
|
+
this.#recoveredHeadsAwaitingTiming = {
|
|
6426
|
+
held: 0,
|
|
6427
|
+
expired: 0,
|
|
6428
|
+
discarded: 0,
|
|
6429
|
+
superseded: 0
|
|
6430
|
+
};
|
|
6195
6431
|
this.#sequencers = /* @__PURE__ */ new Map();
|
|
6196
6432
|
this.#fecGate = null;
|
|
6197
6433
|
this.#fecSequencer = null;
|
|
@@ -6300,6 +6536,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6300
6536
|
#reclaimedTimingSamples;
|
|
6301
6537
|
#evictedTimingSamples;
|
|
6302
6538
|
#rejectedMovieFragments;
|
|
6539
|
+
#recoveredHeadsAwaitingTiming;
|
|
6303
6540
|
#sequencers;
|
|
6304
6541
|
#fecGate;
|
|
6305
6542
|
#fecSequencer;
|
|
@@ -6405,11 +6642,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6405
6642
|
/**
|
|
6406
6643
|
* Typed view of the ISO-BMFF timing-sample budget.
|
|
6407
6644
|
*
|
|
6408
|
-
*
|
|
6409
|
-
*
|
|
6410
|
-
*
|
|
6411
|
-
*
|
|
6412
|
-
*
|
|
6645
|
+
* Each stream admits timing against its own window of `capacity` slots
|
|
6646
|
+
* (BLO-52085). A stream at capacity displaces its own oldest timing to
|
|
6647
|
+
* admit the moof in hand, and `evicted` counts the slots so displaced:
|
|
6648
|
+
* timing a stream declared and never delivered shows up there. `pending`
|
|
6649
|
+
* sums every stream, so it can exceed `capacity`. Per repo policy this is
|
|
6650
|
+
* a producer-owned counter -- never infer budget state by parsing logs.
|
|
6413
6651
|
*/
|
|
6414
6652
|
get timingBudgetStats() {
|
|
6415
6653
|
return {
|
|
@@ -6420,6 +6658,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6420
6658
|
rejectedMovieFragments: this.#rejectedMovieFragments
|
|
6421
6659
|
};
|
|
6422
6660
|
}
|
|
6661
|
+
/** Recovered heads parked for FT=1 timing (BLO-53369). Survives dispose(). */
|
|
6662
|
+
get recoveredHeadsAwaitingTiming() {
|
|
6663
|
+
let pending = 0;
|
|
6664
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
6665
|
+
for (const head of awaitingTiming) if (head.options?.recovered) pending++;
|
|
6666
|
+
}
|
|
6667
|
+
return { ...this.#recoveredHeadsAwaitingTiming, pending };
|
|
6668
|
+
}
|
|
6423
6669
|
get reorderStats() {
|
|
6424
6670
|
let bufferedFrames = this.#fecSequencer?.buffered ?? 0;
|
|
6425
6671
|
for (const { sequencer } of this.#sequencers.values()) bufferedFrames += sequencer.buffered;
|
|
@@ -6461,6 +6707,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6461
6707
|
fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
|
|
6462
6708
|
return this.#fecSequencer?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
|
|
6463
6709
|
}
|
|
6710
|
+
/** See FecReleaseSequencer.unsource. */
|
|
6711
|
+
unsourceFecRelease(packetId, catalogTrackName) {
|
|
6712
|
+
this.#fecSequencer?.unsource(packetId, catalogTrackName);
|
|
6713
|
+
}
|
|
6714
|
+
/** See FecReleaseSequencer.holdsRebuilt. */
|
|
6715
|
+
fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
|
|
6716
|
+
return this.#fecSequencer?.holdsRebuilt(packetId, catalogTrackName) ?? false;
|
|
6717
|
+
}
|
|
6464
6718
|
/** Re-evaluate held gaps after FEC block state changed. */
|
|
6465
6719
|
pokeFecRelease(packetId, catalogTrackName) {
|
|
6466
6720
|
if (!this.#fecSequencer) return;
|
|
@@ -6593,7 +6847,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6593
6847
|
const now = Date.now();
|
|
6594
6848
|
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
6595
6849
|
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
6596
|
-
awaitingTiming.shift();
|
|
6850
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
6597
6851
|
}
|
|
6598
6852
|
}
|
|
6599
6853
|
}
|
|
@@ -6711,11 +6965,16 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6711
6965
|
if (mpu.fragmentationIndicator !== 0 || mpu.fragmentCounter !== 0)
|
|
6712
6966
|
return this.#drop("fragment-unexpected-fragmentation");
|
|
6713
6967
|
const resolver2 = this.#timingResolver(streamKey, info.packetId, false);
|
|
6714
|
-
if (!resolver2) return this.#drop("fragment-no-resolver");
|
|
6968
|
+
if (!resolver2?.initialized) return this.#drop("fragment-no-resolver");
|
|
6715
6969
|
const pendingBefore = resolver2.pendingSampleCount;
|
|
6716
6970
|
const evictedBefore = resolver2.evictedSampleCount;
|
|
6717
|
-
const remaining = this.#maxPendingTimingSamples -
|
|
6718
|
-
const admitted = resolver2.addMovieFragment(
|
|
6971
|
+
const remaining = this.#maxPendingTimingSamples - resolver2.pendingSampleCount;
|
|
6972
|
+
const admitted = resolver2.addMovieFragment(
|
|
6973
|
+
mpu.mpuSequenceNumber,
|
|
6974
|
+
data,
|
|
6975
|
+
remaining,
|
|
6976
|
+
options?.recovered === true
|
|
6977
|
+
);
|
|
6719
6978
|
this.#pendingTimingSamples += resolver2.pendingSampleCount - pendingBefore;
|
|
6720
6979
|
this.#evictedTimingSamples += resolver2.evictedSampleCount - evictedBefore;
|
|
6721
6980
|
if (!admitted) {
|
|
@@ -6735,7 +6994,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6735
6994
|
};
|
|
6736
6995
|
}
|
|
6737
6996
|
if (fragmentType !== 2) return this.#drop("unknown-fragment-type");
|
|
6738
|
-
const resolver = this.#timingResolver(streamKey, info.packetId,
|
|
6997
|
+
const resolver = this.#timingResolver(streamKey, info.packetId, true);
|
|
6739
6998
|
if (!resolver) return this.#drop("mfu-no-resolver");
|
|
6740
6999
|
if (!Number.isSafeInteger(data.byteLength) || data.byteLength <= 0)
|
|
6741
7000
|
return this.#drop("mfu-empty-payload");
|
|
@@ -6756,6 +7015,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6756
7015
|
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
6757
7016
|
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
6758
7017
|
sampleNumber: mfuDuHeader.sampleNumber,
|
|
7018
|
+
sequenceNumber: info.sequenceNumber,
|
|
6759
7019
|
arrivedAt: Date.now()
|
|
6760
7020
|
});
|
|
6761
7021
|
return this.#drop("mfu-sample-timing-missing");
|
|
@@ -6781,7 +7041,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6781
7041
|
info,
|
|
6782
7042
|
resolver,
|
|
6783
7043
|
options?.recovered === true,
|
|
6784
|
-
options?.fecSbn
|
|
7044
|
+
options?.fecSbn,
|
|
7045
|
+
options?.fecSbnFirst
|
|
6785
7046
|
);
|
|
6786
7047
|
if (deferred.record === void 0) this.#countDeferredOutcome(deferred.reason);
|
|
6787
7048
|
}
|
|
@@ -6874,7 +7135,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6874
7135
|
info,
|
|
6875
7136
|
resolver,
|
|
6876
7137
|
options?.recovered === true,
|
|
6877
|
-
options?.fecSbn
|
|
7138
|
+
options?.fecSbn,
|
|
7139
|
+
options?.fecSbnFirst
|
|
6878
7140
|
);
|
|
6879
7141
|
if (outcome.record !== void 0) return outcome.record;
|
|
6880
7142
|
return this.#drop(outcome.reason);
|
|
@@ -6894,7 +7156,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6894
7156
|
* attribution exists to keep readable. Leaving the choice at the call site
|
|
6895
7157
|
* is what keeps both true.
|
|
6896
7158
|
*/
|
|
6897
|
-
#emitCombinedSample(combined, info, resolver, recovered, fecSbn) {
|
|
7159
|
+
#emitCombinedSample(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
|
|
6898
7160
|
const timing = resolver.sampleTiming(
|
|
6899
7161
|
combined.mpuSequenceNumber,
|
|
6900
7162
|
combined.movieFragmentSequenceNumber,
|
|
@@ -6911,6 +7173,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6911
7173
|
);
|
|
6912
7174
|
if (!meta) return { reason: "combined-meta-build-failed" };
|
|
6913
7175
|
if (fecSbn !== void 0) meta.fecSbn = fecSbn;
|
|
7176
|
+
if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
|
|
6914
7177
|
if (!resolver.consumeSample(
|
|
6915
7178
|
combined.mpuSequenceNumber,
|
|
6916
7179
|
combined.movieFragmentSequenceNumber,
|
|
@@ -7144,6 +7407,9 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
7144
7407
|
for (const { sequencer } of this.#sequencers.values()) sequencer.discard();
|
|
7145
7408
|
this.#sequencers.clear();
|
|
7146
7409
|
this.#fecSequencer?.discard();
|
|
7410
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
7411
|
+
for (const head of awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
7412
|
+
}
|
|
7147
7413
|
this.#timingStreams.clear();
|
|
7148
7414
|
this.#pendingTimingSamples = 0;
|
|
7149
7415
|
this.#reliableMoqStartupGate.clear();
|
|
@@ -7162,10 +7428,23 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
7162
7428
|
return resolver;
|
|
7163
7429
|
}
|
|
7164
7430
|
#awaitTiming(streamKey, head) {
|
|
7165
|
-
const
|
|
7166
|
-
if (!
|
|
7431
|
+
const state = this.#timingStreams.get(streamKey);
|
|
7432
|
+
if (!state) return;
|
|
7433
|
+
if (!head.options?.recovered) {
|
|
7434
|
+
const kept = state.awaitingTiming.filter((queued) => !queued.options?.recovered || queued.sequenceNumber !== head.sequenceNumber);
|
|
7435
|
+
this.#recoveredHeadsAwaitingTiming.superseded += state.awaitingTiming.length - kept.length;
|
|
7436
|
+
state.awaitingTiming = kept;
|
|
7437
|
+
}
|
|
7438
|
+
const awaitingTiming = state.awaitingTiming;
|
|
7167
7439
|
awaitingTiming.push(head);
|
|
7168
|
-
if (
|
|
7440
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming.held++;
|
|
7441
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) {
|
|
7442
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
7443
|
+
}
|
|
7444
|
+
}
|
|
7445
|
+
/** Count a recovered head leaving the queue other than by replay or its source copy. */
|
|
7446
|
+
#leaveAwaitingTiming(head, outcome) {
|
|
7447
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming[outcome]++;
|
|
7169
7448
|
}
|
|
7170
7449
|
/**
|
|
7171
7450
|
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
@@ -7193,6 +7472,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
7193
7472
|
const state = this.#timingStreams.get(streamKey);
|
|
7194
7473
|
if (!state) return;
|
|
7195
7474
|
this.#timingStreams.delete(streamKey);
|
|
7475
|
+
for (const head of state.awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
7196
7476
|
this.#pendingTimingSamples -= state.resolver.pendingSampleCount;
|
|
7197
7477
|
if (this.#pendingTimingSamples < 0) {
|
|
7198
7478
|
throw new Error("[MmtpContainerParser] pending timing sample accounting underflow");
|