mattebox 0.6.0 → 0.6.1

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.
Files changed (158) hide show
  1. package/dist/cdn/mattebox.dash-drm.min.js +3 -3
  2. package/dist/cdn/mattebox.dash.min.js +3 -3
  3. package/dist/cdn/mattebox.dual-drm.min.js +3 -3
  4. package/dist/cdn/mattebox.dual-ts-drm.min.js +3 -3
  5. package/dist/cdn/mattebox.dual-ts.min.js +3 -3
  6. package/dist/cdn/mattebox.dual.min.js +3 -3
  7. package/dist/cdn/mattebox.hls-drm.min.js +3 -3
  8. package/dist/cdn/mattebox.hls-ts-drm.min.js +3 -3
  9. package/dist/cdn/mattebox.hls-ts.min.js +3 -3
  10. package/dist/cdn/mattebox.hls.min.js +3 -3
  11. package/dist/cdn/mattebox.kernel.min.js +1 -1
  12. package/dist/cdn/mattebox.min.js +4 -4
  13. package/dist/containers/mp4-box/index.d.ts +9 -7
  14. package/dist/containers/mp4-box/index.d.ts.map +1 -1
  15. package/dist/containers/mp4-box/index.js +20 -28
  16. package/dist/containers/mp4-box/index.js.map +1 -1
  17. package/dist/containers/packed-audio/index.d.ts.map +1 -1
  18. package/dist/containers/packed-audio/index.js +5 -1
  19. package/dist/containers/packed-audio/index.js.map +1 -1
  20. package/dist/containers/ts-transmux/index.d.ts.map +1 -1
  21. package/dist/containers/ts-transmux/index.js +2 -1
  22. package/dist/containers/ts-transmux/index.js.map +1 -1
  23. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/asyncToGenerator.js +1 -1
  24. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/defineProperty.js +1 -1
  25. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectSpread2.js +1 -1
  26. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectWithoutProperties.js +1 -1
  27. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectWithoutPropertiesLoose.js +1 -1
  28. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPrimitive.js +1 -1
  29. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPropertyKey.js +1 -1
  30. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/typeof.js +1 -1
  31. package/dist/es2015/containers/id3.js +1 -1
  32. package/dist/es2015/containers/mp4-box/index.js +19 -22
  33. package/dist/es2015/containers/packed-audio/index.js +2 -5
  34. package/dist/es2015/containers/ts-transmux/h264.js +1 -1
  35. package/dist/es2015/containers/ts-transmux/index.js +3 -6
  36. package/dist/es2015/index.js +34 -27
  37. package/dist/es2015/kernel/append-queue.js +1 -1
  38. package/dist/es2015/kernel/context.js +7 -0
  39. package/dist/es2015/kernel/loader.js +5 -4
  40. package/dist/es2015/kernel/mse.js +27 -71
  41. package/dist/es2015/kernel/prepare.js +77 -0
  42. package/dist/es2015/kernel/reducer.js +233 -64
  43. package/dist/es2015/kernel/refresh.js +35 -0
  44. package/dist/es2015/kernel/rendition-select.js +62 -2
  45. package/dist/es2015/kernel/scheduler.js +23 -5
  46. package/dist/es2015/kernel/timeline.js +22 -1
  47. package/dist/es2015/kernel/trace.js +1 -1
  48. package/dist/es2015/kernel/transport.js +4 -4
  49. package/dist/es2015/presets/define.js +2 -2
  50. package/dist/es2015/presets/tiers.js +7 -6
  51. package/dist/es2015/protocols/dash-cmaf/index.js +136 -55
  52. package/dist/es2015/protocols/dash-cmaf/parse.js +2 -10
  53. package/dist/es2015/protocols/dash-live/index.js +54 -14
  54. package/dist/es2015/protocols/hls-cmaf/index.js +119 -71
  55. package/dist/es2015/protocols/hls-cmaf/parse.js +35 -25
  56. package/dist/es2015/protocols/hls-cmaf/unavailable.js +42 -0
  57. package/dist/es2015/protocols/hls-live/index.js +191 -85
  58. package/dist/es2015/stages/abr/index.js +1 -1
  59. package/dist/es2015/stages/abr-persist/index.js +1 -1
  60. package/dist/es2015/stages/aes-128/index.js +1 -1
  61. package/dist/es2015/stages/alt-audio/index.js +1 -1
  62. package/dist/es2015/stages/cmaf-timing/index.js +24 -39
  63. package/dist/es2015/stages/cmcd/index.js +15 -2
  64. package/dist/es2015/stages/content-steering/index.js +1 -1
  65. package/dist/es2015/stages/eme-core/index.js +2 -2
  66. package/dist/es2015/stages/eme-fairplay/index.js +1 -1
  67. package/dist/es2015/stages/recovery/index.js +1 -1
  68. package/dist/es2015/stages/text-cea608/decode.js +1 -1
  69. package/dist/es2015/stages/text-webvtt/parse.js +1 -1
  70. package/dist/es2015/stages/thumbnails/index.js +1 -1
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +31 -32
  73. package/dist/index.js.map +1 -1
  74. package/dist/kernel/context.d.ts +5 -1
  75. package/dist/kernel/context.d.ts.map +1 -1
  76. package/dist/kernel/context.js +10 -0
  77. package/dist/kernel/context.js.map +1 -1
  78. package/dist/kernel/loader.d.ts.map +1 -1
  79. package/dist/kernel/loader.js +5 -7
  80. package/dist/kernel/loader.js.map +1 -1
  81. package/dist/kernel/mse.d.ts +6 -10
  82. package/dist/kernel/mse.d.ts.map +1 -1
  83. package/dist/kernel/mse.js +20 -73
  84. package/dist/kernel/mse.js.map +1 -1
  85. package/dist/kernel/prepare.d.ts +28 -0
  86. package/dist/kernel/prepare.d.ts.map +1 -0
  87. package/dist/kernel/prepare.js +89 -0
  88. package/dist/kernel/prepare.js.map +1 -0
  89. package/dist/kernel/reducer.d.ts +15 -0
  90. package/dist/kernel/reducer.d.ts.map +1 -1
  91. package/dist/kernel/reducer.js +317 -82
  92. package/dist/kernel/reducer.js.map +1 -1
  93. package/dist/kernel/refresh.d.ts +14 -0
  94. package/dist/kernel/refresh.d.ts.map +1 -0
  95. package/dist/kernel/refresh.js +50 -0
  96. package/dist/kernel/refresh.js.map +1 -0
  97. package/dist/kernel/rendition-select.d.ts +19 -1
  98. package/dist/kernel/rendition-select.d.ts.map +1 -1
  99. package/dist/kernel/rendition-select.js +69 -0
  100. package/dist/kernel/rendition-select.js.map +1 -1
  101. package/dist/kernel/scheduler.d.ts +18 -3
  102. package/dist/kernel/scheduler.d.ts.map +1 -1
  103. package/dist/kernel/scheduler.js +32 -7
  104. package/dist/kernel/scheduler.js.map +1 -1
  105. package/dist/kernel/timeline.d.ts +18 -6
  106. package/dist/kernel/timeline.d.ts.map +1 -1
  107. package/dist/kernel/timeline.js +19 -5
  108. package/dist/kernel/timeline.js.map +1 -1
  109. package/dist/kernel/transport.d.ts.map +1 -1
  110. package/dist/kernel/transport.js +1 -0
  111. package/dist/kernel/transport.js.map +1 -1
  112. package/dist/presets/tiers.d.ts +7 -6
  113. package/dist/presets/tiers.d.ts.map +1 -1
  114. package/dist/presets/tiers.js +7 -6
  115. package/dist/presets/tiers.js.map +1 -1
  116. package/dist/protocols/dash-cmaf/index.d.ts +2 -2
  117. package/dist/protocols/dash-cmaf/index.d.ts.map +1 -1
  118. package/dist/protocols/dash-cmaf/index.js +166 -57
  119. package/dist/protocols/dash-cmaf/index.js.map +1 -1
  120. package/dist/protocols/dash-live/index.d.ts.map +1 -1
  121. package/dist/protocols/dash-live/index.js +55 -9
  122. package/dist/protocols/dash-live/index.js.map +1 -1
  123. package/dist/protocols/hls-cmaf/index.d.ts +3 -2
  124. package/dist/protocols/hls-cmaf/index.d.ts.map +1 -1
  125. package/dist/protocols/hls-cmaf/index.js +140 -88
  126. package/dist/protocols/hls-cmaf/index.js.map +1 -1
  127. package/dist/protocols/hls-cmaf/parse.d.ts +9 -5
  128. package/dist/protocols/hls-cmaf/parse.d.ts.map +1 -1
  129. package/dist/protocols/hls-cmaf/parse.js +50 -47
  130. package/dist/protocols/hls-cmaf/parse.js.map +1 -1
  131. package/dist/protocols/hls-cmaf/unavailable.d.ts +17 -0
  132. package/dist/protocols/hls-cmaf/unavailable.d.ts.map +1 -0
  133. package/dist/protocols/hls-cmaf/unavailable.js +36 -0
  134. package/dist/protocols/hls-cmaf/unavailable.js.map +1 -0
  135. package/dist/protocols/hls-live/index.d.ts +17 -0
  136. package/dist/protocols/hls-live/index.d.ts.map +1 -1
  137. package/dist/protocols/hls-live/index.js +213 -82
  138. package/dist/protocols/hls-live/index.js.map +1 -1
  139. package/dist/stages/aes-128/index.js +2 -2
  140. package/dist/stages/aes-128/index.js.map +1 -1
  141. package/dist/stages/alt-audio/index.d.ts.map +1 -1
  142. package/dist/stages/alt-audio/index.js +5 -3
  143. package/dist/stages/alt-audio/index.js.map +1 -1
  144. package/dist/stages/cmaf-timing/index.d.ts.map +1 -1
  145. package/dist/stages/cmaf-timing/index.js +33 -42
  146. package/dist/stages/cmaf-timing/index.js.map +1 -1
  147. package/dist/stages/cmcd/index.d.ts.map +1 -1
  148. package/dist/stages/cmcd/index.js +15 -3
  149. package/dist/stages/cmcd/index.js.map +1 -1
  150. package/dist/types/kernel.d.ts +39 -13
  151. package/dist/types/kernel.d.ts.map +1 -1
  152. package/dist/types/kernel.js +2 -1
  153. package/dist/types/kernel.js.map +1 -1
  154. package/dist/types/messages.d.ts +50 -10
  155. package/dist/types/messages.d.ts.map +1 -1
  156. package/dist/types/stage.d.ts +18 -0
  157. package/dist/types/stage.d.ts.map +1 -1
  158. package/package.json +1 -1
@@ -1,14 +1,16 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
2
  import { normalizeMimeType } from "./mime.js";
3
- import { segmentAtTime } from "./timeline.js";
3
+ import { applyRefresh } from "./refresh.js";
4
+ import { reconciledOffset, segmentAtTime } from "./timeline.js";
4
5
  import { bufferedEndFrom, schedule } from "./scheduler.js";
5
- import { canSwitchTo, codecFamily, createArbiter, planPinApply } from "./rendition-select.js";
6
+ import { canSwitchTo, codecFamily, createArbiter, planPinApply, withDeadGroups } from "./rendition-select.js";
6
7
  import { sbIdFor } from "./sinks/mse-sink.js";
7
- import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectWithoutProperties.js";
8
+ import _objectWithoutProperties from "../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectWithoutProperties.js";
8
9
  //#region src/kernel/reducer.ts
9
10
  const _excluded = ["pendingInit"];
10
11
  const _excluded2 = ["repeat"];
11
- const _excluded3 = ["initFor"];
12
+ const _excluded3 = ["appended"];
13
+ const _excluded4 = ["initFor"];
12
14
  /**
13
15
  * The default tuning. Every value is overridable through the `config`
14
16
  * parameters of `initialState` and `createReducer`; these are starting
@@ -24,8 +26,7 @@ const DEFAULT_KERNEL_CONFIG = {
24
26
  bufferGoalSeconds: 30,
25
27
  manifestTimeoutMs: 1e4,
26
28
  traceCapacity: 0,
27
- baseRetryDelayMs: 400,
28
- mediaTimeNormalized: false
29
+ baseRetryDelayMs: 400
29
30
  };
30
31
  function resolveConfig(config) {
31
32
  return _objectSpread2(_objectSpread2({}, DEFAULT_KERNEL_CONFIG), config);
@@ -37,7 +38,8 @@ function initialState(config) {
37
38
  presentation: null,
38
39
  timeline: {
39
40
  periodOffsets: /* @__PURE__ */ new Map(),
40
- discontinuitySeq: 0
41
+ discontinuitySeq: 0,
42
+ reconciled: /* @__PURE__ */ new Map()
41
43
  },
42
44
  buffers: /* @__PURE__ */ new Map(),
43
45
  bufferErrors: /* @__PURE__ */ new Map(),
@@ -166,6 +168,61 @@ function mergeCoverage(coverage, added) {
166
168
  merged.push(pending);
167
169
  return merged.sort((a, b) => a.start - b.start);
168
170
  }
171
+ /**
172
+ * The spans `before` holds and `after` does not. Browsers round the ranges
173
+ * they report, so a loss narrower than the gap tolerance is that rounding.
174
+ */
175
+ function lostSpans(before, after) {
176
+ const held = [...after].sort((a, b) => a.start - b.start);
177
+ const lost = [];
178
+ for (const range of before) {
179
+ let cursor = range.start;
180
+ for (const kept of held) {
181
+ if (kept.end <= cursor) continue;
182
+ if (kept.start >= range.end) break;
183
+ if (kept.start - cursor >= GAP_TOLERANCE) lost.push({
184
+ start: cursor,
185
+ end: kept.start
186
+ });
187
+ cursor = kept.end;
188
+ }
189
+ if (range.end - cursor >= GAP_TOLERANCE) lost.push({
190
+ start: cursor,
191
+ end: range.end
192
+ });
193
+ }
194
+ return lost;
195
+ }
196
+ /** The buffers without what they remember receiving: one buffer, or all of them. */
197
+ function forgetAppended(buffers, only) {
198
+ const next = new Map(buffers);
199
+ for (const [sbId, buffer] of buffers) {
200
+ if (buffer.appended === void 0 || only !== void 0 && sbId !== only) continue;
201
+ const { appended: _appended } = buffer, rest = _objectWithoutProperties(buffer, _excluded3);
202
+ next.set(sbId, rest);
203
+ }
204
+ return next;
205
+ }
206
+ /**
207
+ * The buffers after the flushes among `effects`. A flush is an unbounded
208
+ * remove, and it forgets every segment that ends past its start: the next
209
+ * append there starts a new run, so a segment that left nothing the first
210
+ * time can land whole the second time. Lost content cannot say this, a
211
+ * segment that left nothing has none to lose. A bounded remove is eviction
212
+ * and reports through its updateend.
213
+ */
214
+ function forgetFlushed(buffers, effects) {
215
+ let next = buffers;
216
+ for (const effect of effects) {
217
+ if (effect.kind !== "remove" || effect.end !== Number.POSITIVE_INFINITY) continue;
218
+ const buffer = next.get(effect.sbId);
219
+ if ((buffer === null || buffer === void 0 ? void 0 : buffer.appended) === void 0) continue;
220
+ const appended = buffer.appended.filter((seg) => seg.end <= effect.start);
221
+ if (appended.length === buffer.appended.length) continue;
222
+ next = new Map(next).set(effect.sbId, _objectSpread2(_objectSpread2({}, buffer), {}, { appended }));
223
+ }
224
+ return next;
225
+ }
169
226
  function findTrack(presentation, trackId) {
170
227
  if (presentation === null) return null;
171
228
  for (const period of presentation.periods) for (const track of period.tracks) if (track.id === trackId) return track;
@@ -317,9 +374,11 @@ function reduceCommand(state, msg, cfg, hooks) {
317
374
  }]];
318
375
  }
319
376
  case "SELECT_TRACK": {
320
- var _segmentedAt, _previousTrack$rendit;
377
+ var _state$quality$constr, _state$quality$constr2, _segmentedAt, _previousTrack$rendit;
321
378
  const track = findTrack(state.presentation, msg.trackId);
322
379
  if (track === null) return reject(state, msg.type, `unknown track: ${msg.trackId}`);
380
+ const undecodableIds = (_state$quality$constr = (_state$quality$constr2 = state.quality.constraints.get(CODECS)) === null || _state$quality$constr2 === void 0 ? void 0 : _state$quality$constr2.excludeIds) !== null && _state$quality$constr !== void 0 ? _state$quality$constr : [];
381
+ if (track.renditions.length > 0 && track.renditions.every((r) => undecodableIds.includes(r.id))) return reject(state, msg.type, `undecodable track: ${msg.trackId}`);
323
382
  const previous = state.tracks.active.get(track.contentType);
324
383
  const active = new Map(state.tracks.active);
325
384
  active.set(track.contentType, track.id);
@@ -347,7 +406,7 @@ function reduceCommand(state, msg, cfg, hooks) {
347
406
  });
348
407
  for (const effect of plan.effects) if (effect.kind !== "seekElement" || track.contentType === "video") effects.push(effect);
349
408
  const next = new Map(state.buffers);
350
- const { initFor: _initFor } = buffer, rest = _objectWithoutProperties(buffer, _excluded3);
409
+ const { initFor: _initFor } = buffer, rest = _objectWithoutProperties(buffer, _excluded4);
351
410
  next.set(sbId, rest);
352
411
  buffers = next;
353
412
  const pruned = new Map(state.scheduling.inflight);
@@ -463,51 +522,105 @@ function reduceCommand(state, msg, cfg, hooks) {
463
522
  case "ABORT_INFLIGHT": return abortInflight(state, msg.trackId);
464
523
  }
465
524
  }
525
+ /** The constraint source for renditions this browser cannot decode. */
526
+ const CODECS = "codecs";
527
+ /**
528
+ * The renditions this browser cannot play: a declared codec it does not
529
+ * decode, and a video variant whose audio group it cannot decode at all.
530
+ * VHS drops these when the manifest loads; left in, ABR climbs onto one and
531
+ * its buffer fails to open or to append. A rendition that declares no
532
+ * codec counts as decodable.
533
+ */
534
+ function undecodable(presentation, decodable) {
535
+ const out = /* @__PURE__ */ new Set();
536
+ for (const period of presentation.periods) for (const track of period.tracks) {
537
+ if (track.contentType !== "video" && track.contentType !== "audio") continue;
538
+ for (const r of track.renditions) if (r.codecs !== null && !decodable(`${r.mimeType}; codecs="${r.codecs}"`)) out.add(r.id);
539
+ }
540
+ return withDeadGroups(presentation, out);
541
+ }
542
+ /**
543
+ * A presentation replaces the one held: a manifest landed, or a playlist
544
+ * merged into it. Activates default tracks and reports what changed.
545
+ */
546
+ function loadPresentation(state, presentation, undecodableIds = /* @__PURE__ */ new Set()) {
547
+ const available = [];
548
+ for (const period of presentation.periods) for (const track of period.tracks) available.push(track.id);
549
+ const inflight = new Map(state.scheduling.inflight);
550
+ for (const [token, request] of inflight) if (request.trackId === "manifest") inflight.delete(token);
551
+ const phase = state.lifecycle.phase === "loading" ? "ready" : state.lifecycle.phase;
552
+ const active = new Map(state.tracks.active);
553
+ for (const period of presentation.periods) for (const track of period.tracks) if ((track.contentType === "video" || track.contentType === "audio") && !active.has(track.contentType) && track.renditions.some((r) => !undecodableIds.has(r.id))) active.set(track.contentType, track.id);
554
+ const loaded = _objectSpread2(_objectSpread2({}, state), {}, {
555
+ lifecycle: { phase },
556
+ presentation,
557
+ scheduling: _objectSpread2(_objectSpread2({}, state.scheduling), {}, { inflight }),
558
+ tracks: {
559
+ active,
560
+ available
561
+ },
562
+ quality: bumped(state.quality)
563
+ });
564
+ const manifestEffects = available.length === state.tracks.available.length && available.every((id, index) => id === state.tracks.available[index]) ? [] : [{
565
+ kind: "emit",
566
+ event: "tracks:changed",
567
+ payload: { available }
568
+ }];
569
+ const schemes = presentation.periods.flatMap((period) => period.tracks.flatMap((track) => {
570
+ var _track$protection$sch, _track$protection;
571
+ return (_track$protection$sch = (_track$protection = track.protection) === null || _track$protection === void 0 ? void 0 : _track$protection.schemes) !== null && _track$protection$sch !== void 0 ? _track$protection$sch : [];
572
+ }));
573
+ if (schemes.length > 0) manifestEffects.push({
574
+ kind: "emit",
575
+ event: "presentation:protection",
576
+ payload: schemes
577
+ });
578
+ if (!presentation.isLive && presentation.duration !== void 0) manifestEffects.push({
579
+ kind: "setDuration",
580
+ seconds: presentation.duration
581
+ });
582
+ return [loaded, manifestEffects];
583
+ }
466
584
  function reduceFact(state, msg, cfg, hooks) {
467
585
  switch (msg.type) {
468
586
  case "ELEMENT_ATTACHED":
469
587
  case "MEDIASOURCE_OPEN":
470
588
  case "MEDIASOURCE_CLOSED": return [state, []];
471
589
  case "MANIFEST_LOADED": {
472
- const available = [];
473
- for (const period of msg.presentation.periods) for (const track of period.tracks) available.push(track.id);
474
- const inflight = new Map(state.scheduling.inflight);
475
- for (const [token, request] of inflight) if (request.trackId === "manifest") inflight.delete(token);
476
- const phase = state.lifecycle.phase === "loading" ? "ready" : state.lifecycle.phase;
477
- const active = new Map(state.tracks.active);
478
- for (const period of msg.presentation.periods) for (const track of period.tracks) if ((track.contentType === "video" || track.contentType === "audio") && !active.has(track.contentType)) active.set(track.contentType, track.id);
479
- const loaded = _objectSpread2(_objectSpread2({}, state), {}, {
480
- lifecycle: { phase },
481
- presentation: msg.presentation,
482
- scheduling: _objectSpread2(_objectSpread2({}, state.scheduling), {}, { inflight }),
483
- tracks: {
484
- active,
485
- available
486
- },
487
- quality: bumped(state.quality)
488
- });
489
- const manifestEffects = available.length === state.tracks.available.length && available.every((id, index) => id === state.tracks.available[index]) ? [] : [{
490
- kind: "emit",
491
- event: "tracks:changed",
492
- payload: { available }
493
- }];
494
- const schemes = msg.presentation.periods.flatMap((period) => period.tracks.flatMap((track) => {
495
- var _track$protection$sch, _track$protection;
496
- return (_track$protection$sch = (_track$protection = track.protection) === null || _track$protection === void 0 ? void 0 : _track$protection.schemes) !== null && _track$protection$sch !== void 0 ? _track$protection$sch : [];
497
- }));
498
- if (schemes.length > 0) manifestEffects.push({
499
- kind: "emit",
500
- event: "presentation:protection",
501
- payload: schemes
502
- });
503
- if (!msg.presentation.isLive && msg.presentation.duration !== void 0) manifestEffects.push({
504
- kind: "setDuration",
505
- seconds: msg.presentation.duration
506
- });
507
- return [loaded, manifestEffects];
590
+ if (hooks.decodable === void 0) return loadPresentation(state, msg.presentation);
591
+ const excluded = undecodable(msg.presentation, hooks.decodable);
592
+ const tracks = msg.presentation.periods.flatMap((period) => period.tracks);
593
+ const lead = ["video", "audio"].find((c) => tracks.some((t) => t.contentType === c));
594
+ if (lead !== void 0 && !tracks.some((t) => t.contentType === lead && t.renditions.some((r) => !excluded.has(r.id)))) {
595
+ const codecs = new Set(tracks.flatMap((t) => t.renditions.map((r) => {
596
+ var _r$codecs;
597
+ return (_r$codecs = r.codecs) !== null && _r$codecs !== void 0 ? _r$codecs : "";
598
+ })));
599
+ codecs.delete("");
600
+ return failManifest(state, {
601
+ category: "media",
602
+ code: "MEDIA_CODEC_UNSUPPORTED",
603
+ fatal: true,
604
+ recoverable: false
605
+ }, { codecs: [...codecs] });
606
+ }
607
+ const constraints = new Map(state.quality.constraints);
608
+ if (excluded.size > 0) constraints.set(CODECS, { excludeIds: [...excluded] });
609
+ else constraints.delete(CODECS);
610
+ return loadPresentation(_objectSpread2(_objectSpread2({}, state), {}, { quality: _objectSpread2(_objectSpread2({}, state.quality), {}, { constraints }) }), msg.presentation, excluded);
508
611
  }
509
612
  case "MANIFEST_FAILED": return failManifest(state, msg.error);
510
- case "PLAYLIST_REFRESHED": return [state, []];
613
+ case "PLAYLIST_REFRESHED": {
614
+ const merged = state.presentation === null ? null : applyRefresh(state.presentation, msg);
615
+ if (merged === null) return [state, []];
616
+ return loadPresentation(state, merged);
617
+ }
618
+ case "MEDIA_ERROR": {
619
+ if (state.lifecycle.phase === "error") return [state, []];
620
+ const [stopped, aborts] = abortInflight(state);
621
+ const [failed, report] = failManifest(stopped, _objectSpread2(_objectSpread2({}, msg.error), {}, { fatal: true }), { context: msg.error.context });
622
+ return [failed, [...aborts, ...report]];
623
+ }
511
624
  case "SEGMENT_LOADED": {
512
625
  let matched = null;
513
626
  if (msg.token !== void 0) {
@@ -599,33 +712,58 @@ function reduceFact(state, msg, cfg, hooks) {
599
712
  initFor
600
713
  }
601
714
  }]];
602
- if (matched.timestampOffset !== void 0 && state.timeline.periodOffsets.get(matched.sbId) !== matched.timestampOffset) {
715
+ let reconciled = state.timeline.reconciled;
716
+ let offset = matched.epoch === void 0 ? void 0 : reconciled.get(matched.epoch);
717
+ if (offset === void 0 && matched.epoch !== void 0 && matched.seq >= 0 && matched.segmentStart !== void 0) {
718
+ const settled = msg.mediaStart !== void 0 ? reconciledOffset(matched.segmentStart, msg.mediaStart) : matched.timestampOffset;
719
+ if (settled !== void 0) {
720
+ offset = settled;
721
+ reconciled = new Map(reconciled).set(matched.epoch, settled);
722
+ }
723
+ }
724
+ if (offset === void 0) offset = matched.timestampOffset;
725
+ let periodOffsets = state.timeline.periodOffsets;
726
+ if (offset !== void 0 && periodOffsets.get(matched.sbId) !== offset) {
603
727
  effects.push({
604
728
  kind: "setTimestampOffset",
605
729
  sbId: matched.sbId,
606
- offset: matched.timestampOffset
730
+ offset
607
731
  });
608
- const periodOffsets = new Map(state.timeline.periodOffsets);
609
- periodOffsets.set(matched.sbId, matched.timestampOffset);
610
- timeline = _objectSpread2(_objectSpread2({}, state.timeline), {}, { periodOffsets });
732
+ periodOffsets = new Map(periodOffsets).set(matched.sbId, offset);
611
733
  }
612
- effects.push(_objectSpread2(_objectSpread2(_objectSpread2({
734
+ if (periodOffsets !== state.timeline.periodOffsets || reconciled !== state.timeline.reconciled) timeline = _objectSpread2(_objectSpread2({}, state.timeline), {}, {
735
+ periodOffsets,
736
+ reconciled
737
+ });
738
+ effects.push({
613
739
  kind: "append",
614
740
  sbId: matched.sbId,
615
741
  data: msg.bytes
616
- }, matched.segmentStart !== void 0 ? { start: matched.segmentStart } : {}), matched.renditionId !== void 0 ? { renditionId: matched.renditionId } : {}), {}, { seq: matched.seq }));
742
+ });
617
743
  const buffer = buffers.get(matched.sbId);
618
744
  if (buffer !== void 0) {
619
745
  const nextBuffers = new Map(buffers);
620
- nextBuffers.set(matched.sbId, _objectSpread2(_objectSpread2({}, buffer), {}, { pendingAppends: buffer.pendingAppends + 1 }));
746
+ let appended = buffer.appended;
747
+ const { renditionId, seq, segmentStart } = matched;
748
+ if (seq >= 0 && renditionId !== void 0 && segmentStart !== void 0) {
749
+ var _matched$segmentDurat3, _appended2;
750
+ const entry = {
751
+ renditionId,
752
+ seq,
753
+ start: segmentStart,
754
+ end: segmentStart + ((_matched$segmentDurat3 = matched.segmentDuration) !== null && _matched$segmentDurat3 !== void 0 ? _matched$segmentDurat3 : 0)
755
+ };
756
+ appended = [...((_appended2 = appended) !== null && _appended2 !== void 0 ? _appended2 : []).filter((seg) => seg.seq !== seq || seg.renditionId !== renditionId).slice(-31), entry];
757
+ }
758
+ nextBuffers.set(matched.sbId, _objectSpread2(_objectSpread2({}, buffer), {}, { pendingAppends: buffer.pendingAppends + 1 }, appended !== void 0 ? { appended } : {}));
621
759
  buffers = nextBuffers;
622
760
  }
623
761
  if (matched.sbId === sbIdFor("video") && matched.renditionId !== void 0 && matched.segmentStart !== void 0) {
624
- var _matched$segmentDurat3;
762
+ var _matched$segmentDurat4;
625
763
  const watermark = state.playback.currentTime - cfg.backBufferSeconds;
626
764
  const appendLog = [...state.quality.appendLog.filter(([range]) => range.end > watermark), [{
627
765
  start: matched.segmentStart,
628
- end: matched.segmentStart + ((_matched$segmentDurat3 = matched.segmentDuration) !== null && _matched$segmentDurat3 !== void 0 ? _matched$segmentDurat3 : 0)
766
+ end: matched.segmentStart + ((_matched$segmentDurat4 = matched.segmentDuration) !== null && _matched$segmentDurat4 !== void 0 ? _matched$segmentDurat4 : 0)
629
767
  }, matched.renditionId]];
630
768
  quality = _objectSpread2(_objectSpread2({}, quality), {}, { appendLog });
631
769
  }
@@ -711,8 +849,13 @@ function reduceFact(state, msg, cfg, hooks) {
711
849
  case "SOURCEBUFFER_UPDATEEND": {
712
850
  const buffer = state.buffers.get(msg.sbId);
713
851
  if (buffer === void 0) return [state, []];
852
+ let appended = buffer.appended;
853
+ if (appended !== void 0 && msg.ranges !== void 0) {
854
+ const lost = lostSpans(buffer.ranges, msg.ranges);
855
+ if (lost.length > 0) appended = appended.filter((seg) => !lost.some((span) => span.start <= seg.end && span.end >= seg.start));
856
+ }
714
857
  const buffers = new Map(state.buffers);
715
- buffers.set(msg.sbId, _objectSpread2(_objectSpread2(_objectSpread2({}, buffer), msg.ranges !== void 0 ? { ranges: msg.ranges } : {}), {}, { pendingAppends: Math.max(0, buffer.pendingAppends - 1) }));
858
+ buffers.set(msg.sbId, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, buffer), msg.ranges !== void 0 ? { ranges: msg.ranges } : {}), appended !== void 0 ? { appended } : {}), {}, { pendingAppends: Math.max(0, buffer.pendingAppends - 1) }));
716
859
  let bufferErrors = state.bufferErrors;
717
860
  if (bufferErrors.has(msg.sbId)) {
718
861
  bufferErrors = new Map(bufferErrors);
@@ -729,8 +872,12 @@ function reduceFact(state, msg, cfg, hooks) {
729
872
  const bufferErrors = new Map(state.bufferErrors);
730
873
  bufferErrors.set(msg.sbId, count);
731
874
  const scheduling = withPendingInit(state.scheduling, withoutPendingInit(state.scheduling.pendingInit, msg.sbId));
875
+ let buffers = forgetAppended(state.buffers, msg.sbId);
732
876
  const fatal = msg.error.fatal || count >= cfg.bufferErrorLimit;
733
877
  const phase = fatal ? "error" : state.lifecycle.phase;
878
+ const neverAppended = msg.error.code === "MEDIA_CONTAINER_INVALID";
879
+ const waiting = buffers.get(msg.sbId);
880
+ if (neverAppended && waiting !== void 0 && waiting.pendingAppends > 0) buffers = new Map(buffers).set(msg.sbId, _objectSpread2(_objectSpread2({}, waiting), {}, { pendingAppends: waiting.pendingAppends - 1 }));
734
881
  const effects = [{
735
882
  kind: "emit",
736
883
  event: "error",
@@ -742,6 +889,15 @@ function reduceFact(state, msg, cfg, hooks) {
742
889
  sbId: msg.sbId
743
890
  }, fatal && !msg.error.fatal ? { consecutiveFailures: count } : {})
744
891
  }];
892
+ if (neverAppended && !fatal) effects.push({
893
+ kind: "schedule",
894
+ token: "kernel:retry",
895
+ delayMs: cfg.baseRetryDelayMs,
896
+ then: {
897
+ type: "TICK",
898
+ token: "kernel:retry"
899
+ }
900
+ });
745
901
  let inflight = state.scheduling.inflight;
746
902
  if (fatal) {
747
903
  const pruned = new Map(state.scheduling.inflight);
@@ -755,6 +911,7 @@ function reduceFact(state, msg, cfg, hooks) {
755
911
  inflight = pruned;
756
912
  }
757
913
  return [_objectSpread2(_objectSpread2({}, state), {}, {
914
+ buffers,
758
915
  bufferErrors,
759
916
  lifecycle: { phase },
760
917
  scheduling: _objectSpread2(_objectSpread2({}, scheduling), {}, { inflight })
@@ -782,6 +939,7 @@ function reduceFact(state, msg, cfg, hooks) {
782
939
  const phase = state.lifecycle.phase === "ended" ? "ready" : state.lifecycle.phase;
783
940
  return [_objectSpread2(_objectSpread2({}, state), {}, {
784
941
  lifecycle: { phase },
942
+ buffers: forgetAppended(state.buffers),
785
943
  playback: _objectSpread2(_objectSpread2({}, state.playback), {}, {
786
944
  currentTime: msg.to,
787
945
  seeking: true
@@ -872,7 +1030,7 @@ function driveScheduling(state, hooks, cfg) {
872
1030
  const initFetches = [];
873
1031
  let quality = state.quality;
874
1032
  for (const contentType of ["video", "audio"]) {
875
- var _state$buffers$get$pe, _state$buffers$get2, _state$buffers$get$ra2, _state$buffers$get3, _hooks$abr, _hooks$switchPolicy, _state$buffers$get4, _state$buffers$get$ra3, _state$buffers$get5;
1033
+ var _state$buffers$get$pe, _state$buffers$get2, _state$buffers$get$ra2, _state$buffers$get3, _hooks$abr, _hooks$switchPolicy, _state$buffers$get4, _state$buffers$get5, _state$buffers$get$ra3, _state$buffers$get6;
876
1034
  const trackId = state.tracks.active.get(contentType);
877
1035
  if (trackId === void 0) continue;
878
1036
  const found = findTrackSite(state.presentation, trackId);
@@ -923,14 +1081,15 @@ function driveScheduling(state, hooks, cfg) {
923
1081
  });
924
1082
  continue;
925
1083
  }
926
- tracks.push({
1084
+ const appended = (_state$buffers$get5 = state.buffers.get(sbId)) === null || _state$buffers$get5 === void 0 ? void 0 : _state$buffers$get5.appended;
1085
+ tracks.push(_objectSpread2({
927
1086
  trackId,
928
1087
  period: found.period,
929
1088
  rendition,
930
- ranges: (_state$buffers$get$ra3 = (_state$buffers$get5 = state.buffers.get(sbId)) === null || _state$buffers$get5 === void 0 ? void 0 : _state$buffers$get5.ranges) !== null && _state$buffers$get$ra3 !== void 0 ? _state$buffers$get$ra3 : [],
1089
+ ranges: (_state$buffers$get$ra3 = (_state$buffers$get6 = state.buffers.get(sbId)) === null || _state$buffers$get6 === void 0 ? void 0 : _state$buffers$get6.ranges) !== null && _state$buffers$get$ra3 !== void 0 ? _state$buffers$get$ra3 : [],
931
1090
  sbId,
932
1091
  inflight
933
- });
1092
+ }, appended !== void 0 ? { appended } : {}));
934
1093
  }
935
1094
  for (const contentType of ["text", "metadata"]) {
936
1095
  var _state$cues$get;
@@ -949,13 +1108,18 @@ function driveScheduling(state, hooks, cfg) {
949
1108
  inflight
950
1109
  });
951
1110
  }
1111
+ const leadSbId = sbIdFor(state.tracks.active.has("video") ? "video" : "audio");
1112
+ const leadPending = initFetches.some((pending) => pending.sbId === leadSbId) || [...state.scheduling.inflight.values()].some((request) => request.sbId === leadSbId);
952
1113
  const result = schedule({
953
1114
  currentTime: state.playback.currentTime,
954
1115
  bufferGoal: state.scheduling.bufferGoal,
955
1116
  tokenSeq: state.scheduling.tokenSeq + initFetches.length,
956
1117
  tracks,
957
1118
  liveWindow: state.presentation.isLive ? (_state$live$span = (_state$live = state.live) === null || _state$live === void 0 ? void 0 : _state$live.span) !== null && _state$live$span !== void 0 ? _state$live$span : null : null,
958
- mediaTimeNormalized: cfg.mediaTimeNormalized
1119
+ reconciles: hooks.timeProbe != null,
1120
+ leadSbId,
1121
+ reconciled: state.timeline.reconciled,
1122
+ leadPending
959
1123
  });
960
1124
  const decisionKey = [...initFetches.map((p) => `${p.trackId}:init:${p.rendition}`), ...result.requests.map((r) => {
961
1125
  var _r$renditionId;
@@ -1072,6 +1236,7 @@ function createReducer(slices, config, hooks = {}) {
1072
1236
  const cfg = resolveConfig(config);
1073
1237
  const DRIVING_FACTS = /* @__PURE__ */ new Set([
1074
1238
  "MANIFEST_LOADED",
1239
+ "PLAYLIST_REFRESHED",
1075
1240
  "SEGMENT_LOADED",
1076
1241
  "SOURCEBUFFER_CREATED",
1077
1242
  "SOURCEBUFFER_UPDATEEND",
@@ -1084,7 +1249,8 @@ function createReducer(slices, config, hooks = {}) {
1084
1249
  const manifestRequest = !isCommand(msg) && msg.type === "SEGMENT_LOADED" ? manifestRequestFor(state, msg) : null;
1085
1250
  let [next, effects] = isCommand(msg) ? reduceCommand(state, msg, cfg, hooks) : reduceFact(state, msg, cfg, hooks);
1086
1251
  if (isCommand(msg) && effects.some((effect) => effect.kind === "emit" && effect.event === "command:rejected")) return [next, effects];
1087
- if (!isCommand(msg) && DRIVING_FACTS.has(msg.type)) {
1252
+ const merged = msg.type !== "PLAYLIST_REFRESHED" || next.presentation !== state.presentation;
1253
+ if (!isCommand(msg) && DRIVING_FACTS.has(msg.type) && merged) {
1088
1254
  const [driven, driveEffects] = driveScheduling(next, hooks, cfg);
1089
1255
  next = driven;
1090
1256
  if (driveEffects.length > 0) effects = [...effects, ...driveEffects];
@@ -1117,6 +1283,9 @@ function createReducer(slices, config, hooks = {}) {
1117
1283
  next = failed;
1118
1284
  effects = [...effects, ...failEffects];
1119
1285
  }
1286
+ const buffers = forgetFlushed(next.buffers, effects);
1287
+ if (buffers !== next.buffers) next = _objectSpread2(_objectSpread2({}, next), {}, { buffers });
1288
+ if (next.lifecycle.phase === "error") effects = effects.filter((effect) => effect.kind === "emit" || effect.kind === "abort");
1120
1289
  return [next, effects];
1121
1290
  };
1122
1291
  }
@@ -0,0 +1,35 @@
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
+ //#region src/kernel/refresh.ts
3
+ /** The presentation with the refresh merged, or null when it names no rendition the presentation holds. */
4
+ function applyRefresh(presentation, refresh) {
5
+ const renditionId = refresh.renditionId;
6
+ if (renditionId === void 0) return null;
7
+ let found = false;
8
+ const periods = presentation.periods.map((period) => _objectSpread2(_objectSpread2({}, period), {}, { tracks: period.tracks.map((track) => {
9
+ var _ref, _track$protection;
10
+ if (!track.renditions.some((r) => r.id === renditionId)) return track;
11
+ found = true;
12
+ return _objectSpread2(_objectSpread2({}, track), {}, {
13
+ protection: (_ref = (_track$protection = track.protection) !== null && _track$protection !== void 0 ? _track$protection : refresh.protection) !== null && _ref !== void 0 ? _ref : null,
14
+ renditions: track.renditions.map((rendition) => rendition.id === renditionId ? _objectSpread2(_objectSpread2({}, rendition), {}, { segments: refresh.segments }, refresh.init !== void 0 ? { init: refresh.init } : {}) : rendition)
15
+ });
16
+ }) }));
17
+ if (!found) return null;
18
+ if (refresh.endlist === void 0) return _objectSpread2(_objectSpread2({}, presentation), {}, { periods });
19
+ if (refresh.endlist) {
20
+ var _presentation$duratio;
21
+ const duration = refresh.segments.reduce((sum, s) => sum + s.duration, 0);
22
+ return _objectSpread2(_objectSpread2({}, presentation), {}, {
23
+ isLive: false,
24
+ duration: Math.max((_presentation$duratio = presentation.duration) !== null && _presentation$duratio !== void 0 ? _presentation$duratio : 0, duration),
25
+ periods
26
+ });
27
+ }
28
+ return _objectSpread2(_objectSpread2({}, presentation), {}, {
29
+ isLive: true,
30
+ live: _objectSpread2(_objectSpread2(_objectSpread2({}, presentation.live), refresh.updatePeriod !== void 0 ? { updatePeriod: refresh.updatePeriod } : {}), refresh.dateAnchor !== void 0 ? { dateAnchor: refresh.dateAnchor } : {}),
31
+ periods
32
+ });
33
+ }
34
+ //#endregion
35
+ export { applyRefresh };
@@ -1,4 +1,4 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
2
  import { segmentAtTime } from "./timeline.js";
3
3
  import { bufferedEndFrom } from "./scheduler.js";
4
4
  //#region src/kernel/rendition-select.ts
@@ -33,6 +33,66 @@ function lowest(allowed) {
33
33
  for (const candidate of allowed) if (candidate.bitrate < best.bitrate) best = candidate;
34
34
  return best;
35
35
  }
36
+ /**
37
+ * The video renditions an adapter resolves ahead of need: the active one
38
+ * and the nearest rung below and above on its pathway. ABR moves one rung
39
+ * at a time from a full buffer, so its next pick is resolved before it is
40
+ * chosen; a longer jump resolves when it happens, while the buffer plays.
41
+ * Renditions a constraint excludes by id (another pathway, a failed
42
+ * playlist) are skipped, and renditions that share a playlist count once.
43
+ * Without a usable active rendition the lowest stands in, as arbitration picks it.
44
+ */
45
+ function ladderNeighbours(renditions, activeId, constraints) {
46
+ var _pool$find;
47
+ const excluded = /* @__PURE__ */ new Set();
48
+ for (const constraint of constraints.values()) {
49
+ var _constraint$excludeId2;
50
+ for (const id of (_constraint$excludeId2 = constraint.excludeIds) !== null && _constraint$excludeId2 !== void 0 ? _constraint$excludeId2 : []) excluded.add(id);
51
+ }
52
+ const usable = renditions.filter((r) => !excluded.has(r.id));
53
+ const pool = [...usable.length > 0 ? usable : renditions].sort((a, b) => a.bitrate - b.bitrate);
54
+ const active = (_pool$find = pool.find((r) => r.id === activeId)) !== null && _pool$find !== void 0 ? _pool$find : pool[0];
55
+ if (active === void 0) return [];
56
+ const key = (r) => {
57
+ var _r$playlistUrl;
58
+ return (_r$playlistUrl = r.playlistUrl) !== null && _r$playlistUrl !== void 0 ? _r$playlistUrl : r.id;
59
+ };
60
+ const ladder = [];
61
+ const seen = /* @__PURE__ */ new Set();
62
+ for (const rendition of pool) {
63
+ if (rendition.pathway !== active.pathway || seen.has(key(rendition))) continue;
64
+ seen.add(key(rendition));
65
+ ladder.push(rendition);
66
+ }
67
+ const at = ladder.findIndex((r) => key(r) === key(active));
68
+ if (at === -1) return [active];
69
+ return [
70
+ ...at > 0 ? [ladder[at - 1]] : [],
71
+ active,
72
+ ...at + 1 < ladder.length ? [ladder[at + 1]] : []
73
+ ];
74
+ }
75
+ /**
76
+ * `dead` plus the video variants that require an audio group none of whose
77
+ * renditions is left. A variant names its audio by group, and the group
78
+ * carries the audio playlist and codec, so a group that cannot play takes
79
+ * its variants with it, the way videojs-http-streaming excludes them.
80
+ * Another track in the group (another language) keeps it alive.
81
+ */
82
+ function withDeadGroups(presentation, dead) {
83
+ const out = new Set(dead);
84
+ const known = /* @__PURE__ */ new Set();
85
+ const alive = /* @__PURE__ */ new Set();
86
+ for (const period of presentation.periods) for (const track of period.tracks) {
87
+ if (track.contentType !== "audio") continue;
88
+ const colon = track.id.indexOf(":");
89
+ const group = colon === -1 ? track.id : track.id.slice(0, colon);
90
+ known.add(group);
91
+ if (track.renditions.some((r) => !dead.has(r.id))) alive.add(group);
92
+ }
93
+ for (const { renditionId, requires } of presentation.couplings) if (requires.audio !== void 0 && known.has(requires.audio) && !alive.has(requires.audio)) out.add(renditionId);
94
+ return out;
95
+ }
36
96
  /** The strict arbitration order from docs/08. Never deviate; never return zero renditions. */
37
97
  function arbitrate(ctx) {
38
98
  const events = [];
@@ -261,4 +321,4 @@ function planPinApply(input) {
261
321
  };
262
322
  }
263
323
  //#endregion
264
- export { arbitrate, canSwitchTo, codecFamily, createArbiter, planPinApply };
324
+ export { arbitrate, canSwitchTo, codecFamily, createArbiter, ladderNeighbours, planPinApply, withDeadGroups };
@@ -1,5 +1,5 @@
1
- import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/objectSpread2.js";
2
- import { buildEpochs, epochForSeq, segmentAtTime, timestampOffsetFor } from "./timeline.js";
1
+ import _objectSpread2 from "../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/objectSpread2.js";
2
+ import { buildEpochs, epochForSeq, epochKey, segmentAtTime, timestampOffsetFor } from "./timeline.js";
3
3
  //#region src/kernel/scheduler.ts
4
4
  const DEFAULT_GAP_TOLERANCE = .25;
5
5
  /**
@@ -32,6 +32,12 @@ function coveringSegment(ranges, segment, tolerance) {
32
32
  const tail = Math.max(mid, segment.start + segment.duration - tolerance);
33
33
  return (_ranges$find = ranges.find((range) => range.start <= mid && range.end > mid || range.start <= tail && range.end >= tail)) !== null && _ranges$find !== void 0 ? _ranges$find : null;
34
34
  }
35
+ /** Whether the track's buffer received `seq` of the track's rendition since the last seek. */
36
+ function received(track, seq) {
37
+ var _track$appended;
38
+ const id = track.rendition.id;
39
+ return ((_track$appended = track.appended) === null || _track$appended === void 0 ? void 0 : _track$appended.some((entry) => entry.seq === seq && entry.renditionId === id)) === true;
40
+ }
35
41
  function schedule(input) {
36
42
  var _input$gapToleranceSe;
37
43
  const tolerance = (_input$gapToleranceSe = input.gapToleranceSeconds) !== null && _input$gapToleranceSe !== void 0 ? _input$gapToleranceSe : DEFAULT_GAP_TOLERANCE;
@@ -39,6 +45,7 @@ function schedule(input) {
39
45
  const requests = [];
40
46
  let tokenSeq = input.tokenSeq;
41
47
  for (const track of input.tracks) {
48
+ var _input$reconciled;
42
49
  if (track.inflight.length > 0) continue;
43
50
  const bufferedEnd = bufferedEndFrom(track.ranges, input.currentTime, tolerance);
44
51
  if (bufferedEnd - input.currentTime >= input.bufferGoal) continue;
@@ -47,7 +54,16 @@ function schedule(input) {
47
54
  let segment = segmentAtTime(track.rendition.segments, target + tolerance, track.period.start);
48
55
  let frontier = bufferedEnd;
49
56
  while (segment !== null) {
50
- const covering = coveringSegment(track.ranges, segment, tolerance);
57
+ let covering = coveringSegment(track.ranges, segment, tolerance);
58
+ if (covering === null && received(track, segment.seq)) {
59
+ var _left$end;
60
+ const { start, duration } = segment;
61
+ const left = track.ranges.find((range) => range.start >= start && range.start < start + duration);
62
+ covering = {
63
+ start,
64
+ end: (_left$end = left === null || left === void 0 ? void 0 : left.end) !== null && _left$end !== void 0 ? _left$end : start + duration
65
+ };
66
+ }
51
67
  if (covering === null) break;
52
68
  frontier = Math.max(frontier, covering.end);
53
69
  if (frontier - input.currentTime >= input.bufferGoal) {
@@ -63,6 +79,8 @@ function schedule(input) {
63
79
  rendition: track.rendition
64
80
  }]);
65
81
  const epoch = epochForSeq(epochs, segment.seq);
82
+ const key = epoch === null ? void 0 : epochKey(epochs, epoch);
83
+ if (input.reconciles === true && key !== void 0 && track.sbId !== void 0 && track.sbId !== input.leadSbId && ((_input$reconciled = input.reconciled) === null || _input$reconciled === void 0 ? void 0 : _input$reconciled.has(key)) !== true && (input.leadPending === true || requests.some((r) => r.sbId === input.leadSbId))) continue;
66
84
  tokenSeq += 1;
67
85
  const token = `t${tokenSeq}:${track.trackId}:${segment.seq}`;
68
86
  effects.push(_objectSpread2({
@@ -70,7 +88,7 @@ function schedule(input) {
70
88
  token,
71
89
  url: segment.url
72
90
  }, segment.byteRange !== void 0 ? { range: segment.byteRange } : {}));
73
- requests.push(_objectSpread2(_objectSpread2({
91
+ requests.push(_objectSpread2(_objectSpread2(_objectSpread2({
74
92
  token,
75
93
  trackId: track.trackId,
76
94
  seq: segment.seq,
@@ -78,7 +96,7 @@ function schedule(input) {
78
96
  renditionId: track.rendition.id,
79
97
  segmentStart: segment.start,
80
98
  segmentDuration: segment.duration
81
- }, track.sbId !== void 0 ? { sbId: track.sbId } : {}), input.mediaTimeNormalized === true ? { timestampOffset: 0 } : epoch !== null ? { timestampOffset: timestampOffsetFor(epoch) } : {}));
99
+ }, track.sbId !== void 0 ? { sbId: track.sbId } : {}), epoch !== null ? { timestampOffset: timestampOffsetFor(epoch) } : {}), key !== void 0 ? { epoch: key } : {}));
82
100
  }
83
101
  return {
84
102
  effects,