@torrent-tv/proxy 2.95.33 → 2.95.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.95.33",
3
+ "version": "2.95.34",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -37,6 +37,10 @@ import {
37
37
  ZERO
38
38
  } from "./media-time.js";
39
39
 
40
+ // Match the media element's allowance for a range that starts a few frames
41
+ // after its current position (see server/public/domain/buffer-metrics.js).
42
+ const CLIENT_RANGE_START_TOLERANCE_SECONDS = 0.25;
43
+
40
44
  /**
41
45
  * The mean rate predicted over a horizon by the integral of the measured rate.
42
46
  * Polling does not change the last measured service rate.
@@ -148,7 +152,7 @@ export function predictPlaybackReadiness(input = {}) {
148
152
  const position = toSeconds(at);
149
153
  const remaining = Math.max(0, duration - position);
150
154
  const measuredRanges = reported.map((ranges, trackIndex) => ranges ?
151
- heldRanges(ranges, segmentsOf[trackIndex], unit) : null);
155
+ heldRanges(ranges, segmentsOf[trackIndex], unit, at) : null);
152
156
  const measured = measuredRanges.length > 0 && measuredRanges.every(Boolean);
153
157
  const heldEnd = measured ? earliest(...measuredRanges.map((ranges) => contiguousEnd(ranges, at))) : null;
154
158
  // The figure reported back is what the page said it holds; the widening by
@@ -511,13 +515,18 @@ function joinedPiece(served) {
511
515
  * @param {bigint} unit
512
516
  * @returns {import("./media-time.js").MediaRange[]}
513
517
  */
514
- function heldRanges(ranges, segments, unit) {
518
+ function heldRanges(ranges, segments, unit, position) {
515
519
  const pieces = segments.flatMap((segment) => segment.ranges ?? []);
516
520
  const zero = mediaTime(0n, unit);
517
521
  const error = rescale(REPORTED_TIME_ERROR, unit);
522
+ const startTolerance = add(position, rescale(fromSeconds(CLIENT_RANGE_START_TOLERANCE_SECONDS), unit));
518
523
  const held = [];
519
524
  for (const range of ranges) {
520
- const start = latest(zero, subtract(rescale(range.start, unit), error));
525
+ const reportedStart = rescale(range.start, unit);
526
+ let start = latest(zero, subtract(reportedStart, error));
527
+ if (compare(reportedStart, position) > 0 && compare(reportedStart, startTolerance) <= 0) {
528
+ start = position;
529
+ }
521
530
  const end = add(rescale(range.end, unit), error);
522
531
  const inside = pieces.filter((piece) => contains([{ start, end }], piece.start, piece.end));
523
532
  addMediaRange(held, { start, end, frame: latest(zero, ...inside.map(({ frame }) => frame)) });