@blockcast/mmt-container 2.2.0-main.bdefba2a99c2 → 2.2.0-main.c1482ff09fa3
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 +1304 -170
- 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 +74 -14
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +419 -61
- 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 +79 -10
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +299 -27
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +301 -30
- package/dist/mmtp-container-parser.no-modules.js.map +3 -3
- package/dist/mmtp-decode-pipeline.js +298 -27
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-router.d.ts +34 -8
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +623 -65
- 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 +1124 -143
- 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 +298 -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 +298 -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 +454 -35
- 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 +306 -29
- package/src/mmtp-router.ts +548 -38
- package/src/multicast-manager.ts +118 -14
- 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)) {
|
|
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,56 @@ 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
|
+
* An overlay-rebuilt frame (fecSbnFirst) waits no longer than the BLO-53342
|
|
6334
|
+
* source cursor holds it unanchored, and neither does a later frame behind
|
|
6335
|
+
* it. Unanchored, a frame that waits on no block (fecSbnFirst set, or no
|
|
6336
|
+
* fecSbn) left the gate once every frame ahead of it had: mark it `passed`,
|
|
6337
|
+
* like each frame that arrived in front of it since (stale there). The head
|
|
6338
|
+
* then goes, decided as it would be unanchored, once a frame the base path
|
|
6339
|
+
* delivered (a source frame, or one base FEC recovered) is buffered after a
|
|
6340
|
+
* marked one: the base path has passed that one, so a frame still missing
|
|
6341
|
+
* before it can only come from a repair. It also goes while no source frame
|
|
6342
|
+
* has been released, when the direct path shows a recovered frame at once.
|
|
6343
|
+
* And it goes at once while a staged switch decides on when frames arrive
|
|
6344
|
+
* (FecReleaseGate.releaseUnanchored), and when unsource releases into a
|
|
6345
|
+
* sink being replaced: unanchored, it had already reached the sink.
|
|
6346
|
+
* The scan also writes: the `passed` marks it sets stay on the frames,
|
|
6347
|
+
* and push marks a frame it inserts in front of a marked one from them.
|
|
6348
|
+
*/
|
|
6349
|
+
#cursorPassed(stream, asUnanchored) {
|
|
6350
|
+
let at = -1;
|
|
6351
|
+
for (let i = 0; i < stream.buf.length; i++) {
|
|
6352
|
+
const frame = stream.buf[i];
|
|
6353
|
+
if (frame.meta.fecSbnFirst !== void 0 || frame.meta.fecSbn === void 0) {
|
|
6354
|
+
frame.passed = true;
|
|
6355
|
+
if (at < 0) at = i;
|
|
6356
|
+
} else if (frame.passed !== true) break;
|
|
6357
|
+
}
|
|
6358
|
+
if (at < 0) return false;
|
|
6359
|
+
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));
|
|
6360
|
+
}
|
|
6149
6361
|
#release(stream, frame, decision) {
|
|
6362
|
+
const stale = stream.last !== null && compareFrameOrder(frame, stream.last) <= 0;
|
|
6363
|
+
if (stale) this.#recordStat("droppedStale");
|
|
6150
6364
|
if (decision) frame.meta.gapBefore = decision;
|
|
6151
6365
|
stream.last = frame;
|
|
6152
|
-
if (frame.meta.fecSbn !== void 0
|
|
6366
|
+
if (frame.meta.fecSbn !== void 0 && (frame.meta.fecSbnFirst === void 0 || stream.lastSbn !== void 0)) {
|
|
6367
|
+
stream.lastSbn = frame.meta.fecSbn;
|
|
6368
|
+
}
|
|
6369
|
+
if (frame.meta.recovered !== true) stream.sourced = true;
|
|
6153
6370
|
this.#gate.onReleased?.(frame.data, frame.meta);
|
|
6154
|
-
this.#emit(frame.data, frame.meta);
|
|
6371
|
+
if (!stale) this.#emit(frame.data, frame.meta);
|
|
6155
6372
|
}
|
|
6156
6373
|
};
|
|
6157
6374
|
var FMPU_BOX_TYPES = /* @__PURE__ */ new Set(["ftyp", "moov", "moof"]);
|
|
@@ -6192,6 +6409,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6192
6409
|
this.#reclaimedTimingSamples = 0;
|
|
6193
6410
|
this.#evictedTimingSamples = 0;
|
|
6194
6411
|
this.#rejectedMovieFragments = 0;
|
|
6412
|
+
this.#recoveredHeadsAwaitingTiming = {
|
|
6413
|
+
held: 0,
|
|
6414
|
+
expired: 0,
|
|
6415
|
+
discarded: 0,
|
|
6416
|
+
superseded: 0
|
|
6417
|
+
};
|
|
6195
6418
|
this.#sequencers = /* @__PURE__ */ new Map();
|
|
6196
6419
|
this.#fecGate = null;
|
|
6197
6420
|
this.#fecSequencer = null;
|
|
@@ -6300,6 +6523,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6300
6523
|
#reclaimedTimingSamples;
|
|
6301
6524
|
#evictedTimingSamples;
|
|
6302
6525
|
#rejectedMovieFragments;
|
|
6526
|
+
#recoveredHeadsAwaitingTiming;
|
|
6303
6527
|
#sequencers;
|
|
6304
6528
|
#fecGate;
|
|
6305
6529
|
#fecSequencer;
|
|
@@ -6405,11 +6629,12 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6405
6629
|
/**
|
|
6406
6630
|
* Typed view of the ISO-BMFF timing-sample budget.
|
|
6407
6631
|
*
|
|
6408
|
-
*
|
|
6409
|
-
*
|
|
6410
|
-
*
|
|
6411
|
-
*
|
|
6412
|
-
*
|
|
6632
|
+
* Each stream admits timing against its own window of `capacity` slots
|
|
6633
|
+
* (BLO-52085). A stream at capacity displaces its own oldest timing to
|
|
6634
|
+
* admit the moof in hand, and `evicted` counts the slots so displaced:
|
|
6635
|
+
* timing a stream declared and never delivered shows up there. `pending`
|
|
6636
|
+
* sums every stream, so it can exceed `capacity`. Per repo policy this is
|
|
6637
|
+
* a producer-owned counter -- never infer budget state by parsing logs.
|
|
6413
6638
|
*/
|
|
6414
6639
|
get timingBudgetStats() {
|
|
6415
6640
|
return {
|
|
@@ -6420,6 +6645,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6420
6645
|
rejectedMovieFragments: this.#rejectedMovieFragments
|
|
6421
6646
|
};
|
|
6422
6647
|
}
|
|
6648
|
+
/** Recovered heads parked for FT=1 timing (BLO-53369). Survives dispose(). */
|
|
6649
|
+
get recoveredHeadsAwaitingTiming() {
|
|
6650
|
+
let pending = 0;
|
|
6651
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
6652
|
+
for (const head of awaitingTiming) if (head.options?.recovered) pending++;
|
|
6653
|
+
}
|
|
6654
|
+
return { ...this.#recoveredHeadsAwaitingTiming, pending };
|
|
6655
|
+
}
|
|
6423
6656
|
get reorderStats() {
|
|
6424
6657
|
let bufferedFrames = this.#fecSequencer?.buffered ?? 0;
|
|
6425
6658
|
for (const { sequencer } of this.#sequencers.values()) bufferedFrames += sequencer.buffered;
|
|
@@ -6461,6 +6694,14 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6461
6694
|
fecReleaseRapAbove(packetId, catalogTrackName, ssId) {
|
|
6462
6695
|
return this.#fecSequencer?.rapAbove(packetId, catalogTrackName, ssId) ?? false;
|
|
6463
6696
|
}
|
|
6697
|
+
/** See FecReleaseSequencer.unsource. */
|
|
6698
|
+
unsourceFecRelease(packetId, catalogTrackName) {
|
|
6699
|
+
this.#fecSequencer?.unsource(packetId, catalogTrackName);
|
|
6700
|
+
}
|
|
6701
|
+
/** See FecReleaseSequencer.holdsRebuilt. */
|
|
6702
|
+
fecReleaseHoldsRebuilt(packetId, catalogTrackName) {
|
|
6703
|
+
return this.#fecSequencer?.holdsRebuilt(packetId, catalogTrackName) ?? false;
|
|
6704
|
+
}
|
|
6464
6705
|
/** Re-evaluate held gaps after FEC block state changed. */
|
|
6465
6706
|
pokeFecRelease(packetId, catalogTrackName) {
|
|
6466
6707
|
if (!this.#fecSequencer) return;
|
|
@@ -6593,7 +6834,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6593
6834
|
const now = Date.now();
|
|
6594
6835
|
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
6595
6836
|
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
6596
|
-
awaitingTiming.shift();
|
|
6837
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
6597
6838
|
}
|
|
6598
6839
|
}
|
|
6599
6840
|
}
|
|
@@ -6711,11 +6952,16 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6711
6952
|
if (mpu.fragmentationIndicator !== 0 || mpu.fragmentCounter !== 0)
|
|
6712
6953
|
return this.#drop("fragment-unexpected-fragmentation");
|
|
6713
6954
|
const resolver2 = this.#timingResolver(streamKey, info.packetId, false);
|
|
6714
|
-
if (!resolver2) return this.#drop("fragment-no-resolver");
|
|
6955
|
+
if (!resolver2?.initialized) return this.#drop("fragment-no-resolver");
|
|
6715
6956
|
const pendingBefore = resolver2.pendingSampleCount;
|
|
6716
6957
|
const evictedBefore = resolver2.evictedSampleCount;
|
|
6717
|
-
const remaining = this.#maxPendingTimingSamples -
|
|
6718
|
-
const admitted = resolver2.addMovieFragment(
|
|
6958
|
+
const remaining = this.#maxPendingTimingSamples - resolver2.pendingSampleCount;
|
|
6959
|
+
const admitted = resolver2.addMovieFragment(
|
|
6960
|
+
mpu.mpuSequenceNumber,
|
|
6961
|
+
data,
|
|
6962
|
+
remaining,
|
|
6963
|
+
options?.recovered === true
|
|
6964
|
+
);
|
|
6719
6965
|
this.#pendingTimingSamples += resolver2.pendingSampleCount - pendingBefore;
|
|
6720
6966
|
this.#evictedTimingSamples += resolver2.evictedSampleCount - evictedBefore;
|
|
6721
6967
|
if (!admitted) {
|
|
@@ -6735,7 +6981,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6735
6981
|
};
|
|
6736
6982
|
}
|
|
6737
6983
|
if (fragmentType !== 2) return this.#drop("unknown-fragment-type");
|
|
6738
|
-
const resolver = this.#timingResolver(streamKey, info.packetId,
|
|
6984
|
+
const resolver = this.#timingResolver(streamKey, info.packetId, true);
|
|
6739
6985
|
if (!resolver) return this.#drop("mfu-no-resolver");
|
|
6740
6986
|
if (!Number.isSafeInteger(data.byteLength) || data.byteLength <= 0)
|
|
6741
6987
|
return this.#drop("mfu-empty-payload");
|
|
@@ -6756,6 +7002,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6756
7002
|
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
6757
7003
|
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
6758
7004
|
sampleNumber: mfuDuHeader.sampleNumber,
|
|
7005
|
+
sequenceNumber: info.sequenceNumber,
|
|
6759
7006
|
arrivedAt: Date.now()
|
|
6760
7007
|
});
|
|
6761
7008
|
return this.#drop("mfu-sample-timing-missing");
|
|
@@ -6781,7 +7028,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6781
7028
|
info,
|
|
6782
7029
|
resolver,
|
|
6783
7030
|
options?.recovered === true,
|
|
6784
|
-
options?.fecSbn
|
|
7031
|
+
options?.fecSbn,
|
|
7032
|
+
options?.fecSbnFirst
|
|
6785
7033
|
);
|
|
6786
7034
|
if (deferred.record === void 0) this.#countDeferredOutcome(deferred.reason);
|
|
6787
7035
|
}
|
|
@@ -6874,7 +7122,8 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6874
7122
|
info,
|
|
6875
7123
|
resolver,
|
|
6876
7124
|
options?.recovered === true,
|
|
6877
|
-
options?.fecSbn
|
|
7125
|
+
options?.fecSbn,
|
|
7126
|
+
options?.fecSbnFirst
|
|
6878
7127
|
);
|
|
6879
7128
|
if (outcome.record !== void 0) return outcome.record;
|
|
6880
7129
|
return this.#drop(outcome.reason);
|
|
@@ -6894,7 +7143,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6894
7143
|
* attribution exists to keep readable. Leaving the choice at the call site
|
|
6895
7144
|
* is what keeps both true.
|
|
6896
7145
|
*/
|
|
6897
|
-
#emitCombinedSample(combined, info, resolver, recovered, fecSbn) {
|
|
7146
|
+
#emitCombinedSample(combined, info, resolver, recovered, fecSbn, fecSbnFirst) {
|
|
6898
7147
|
const timing = resolver.sampleTiming(
|
|
6899
7148
|
combined.mpuSequenceNumber,
|
|
6900
7149
|
combined.movieFragmentSequenceNumber,
|
|
@@ -6911,6 +7160,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
6911
7160
|
);
|
|
6912
7161
|
if (!meta) return { reason: "combined-meta-build-failed" };
|
|
6913
7162
|
if (fecSbn !== void 0) meta.fecSbn = fecSbn;
|
|
7163
|
+
if (fecSbnFirst !== void 0) meta.fecSbnFirst = fecSbnFirst;
|
|
6914
7164
|
if (!resolver.consumeSample(
|
|
6915
7165
|
combined.mpuSequenceNumber,
|
|
6916
7166
|
combined.movieFragmentSequenceNumber,
|
|
@@ -7079,6 +7329,10 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
7079
7329
|
}
|
|
7080
7330
|
this.#emitFrame(data, meta);
|
|
7081
7331
|
}
|
|
7332
|
+
/** Whether FT=1 metadata already names this sample, without claiming it. */
|
|
7333
|
+
hasAuthoredTimingFor(packetId, mpuSequenceNumber, movieFragmentSequenceNumber, sampleNumber, catalogTrackName) {
|
|
7334
|
+
return this.#timingResolver(this.#streamKey(packetId, catalogTrackName), packetId, false)?.sampleTiming(mpuSequenceNumber, movieFragmentSequenceNumber, sampleNumber) != null;
|
|
7335
|
+
}
|
|
7082
7336
|
/**
|
|
7083
7337
|
* Claim and return the authored timing for a recovered sample. Recovery does
|
|
7084
7338
|
* not pass through the ordinary `feed()` completion path, so it must retire
|
|
@@ -7140,6 +7394,9 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
7140
7394
|
for (const { sequencer } of this.#sequencers.values()) sequencer.discard();
|
|
7141
7395
|
this.#sequencers.clear();
|
|
7142
7396
|
this.#fecSequencer?.discard();
|
|
7397
|
+
for (const { awaitingTiming } of this.#timingStreams.values()) {
|
|
7398
|
+
for (const head of awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
7399
|
+
}
|
|
7143
7400
|
this.#timingStreams.clear();
|
|
7144
7401
|
this.#pendingTimingSamples = 0;
|
|
7145
7402
|
this.#reliableMoqStartupGate.clear();
|
|
@@ -7158,10 +7415,23 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
7158
7415
|
return resolver;
|
|
7159
7416
|
}
|
|
7160
7417
|
#awaitTiming(streamKey, head) {
|
|
7161
|
-
const
|
|
7162
|
-
if (!
|
|
7418
|
+
const state = this.#timingStreams.get(streamKey);
|
|
7419
|
+
if (!state) return;
|
|
7420
|
+
if (!head.options?.recovered) {
|
|
7421
|
+
const kept = state.awaitingTiming.filter((queued) => !queued.options?.recovered || queued.sequenceNumber !== head.sequenceNumber);
|
|
7422
|
+
this.#recoveredHeadsAwaitingTiming.superseded += state.awaitingTiming.length - kept.length;
|
|
7423
|
+
state.awaitingTiming = kept;
|
|
7424
|
+
}
|
|
7425
|
+
const awaitingTiming = state.awaitingTiming;
|
|
7163
7426
|
awaitingTiming.push(head);
|
|
7164
|
-
if (
|
|
7427
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming.held++;
|
|
7428
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) {
|
|
7429
|
+
this.#leaveAwaitingTiming(awaitingTiming.shift(), "expired");
|
|
7430
|
+
}
|
|
7431
|
+
}
|
|
7432
|
+
/** Count a recovered head leaving the queue other than by replay or its source copy. */
|
|
7433
|
+
#leaveAwaitingTiming(head, outcome) {
|
|
7434
|
+
if (head.options?.recovered) this.#recoveredHeadsAwaitingTiming[outcome]++;
|
|
7165
7435
|
}
|
|
7166
7436
|
/**
|
|
7167
7437
|
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
@@ -7189,6 +7459,7 @@ var MmtpContainerParser = class _MmtpContainerParser {
|
|
|
7189
7459
|
const state = this.#timingStreams.get(streamKey);
|
|
7190
7460
|
if (!state) return;
|
|
7191
7461
|
this.#timingStreams.delete(streamKey);
|
|
7462
|
+
for (const head of state.awaitingTiming) this.#leaveAwaitingTiming(head, "discarded");
|
|
7192
7463
|
this.#pendingTimingSamples -= state.resolver.pendingSampleCount;
|
|
7193
7464
|
if (this.#pendingTimingSamples < 0) {
|
|
7194
7465
|
throw new Error("[MmtpContainerParser] pending timing sample accounting underflow");
|