@torrent-tv/proxy 2.98.16 → 2.98.17

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.98.16",
3
+ "version": "2.98.17",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -1319,8 +1319,13 @@ export class EncodeRuns {
1319
1319
  /**
1320
1320
  * How long this run took to open its original input, for sizing the next
1321
1321
  * stretch: from its spawn to the name of its first closed piece, less what
1322
- * encoding that piece costs at the run's speed — its own where it measured
1323
- * one, else the output's. Nothing is noted where either is unknown.
1322
+ * encoding that piece costs at a measured speed — the run's own where it
1323
+ * closed two pieces, else the output's newest reading, which is taken
1324
+ * between two closed pieces of a run too. Never a predicted speed: the
1325
+ * output's starting figure, scaled by a machine share that missed short
1326
+ * runs, read 0.08x on Home Assistant and recorded opens of 0.00 s (r41,
1327
+ * torrent-tv/meta#178). Nothing is noted where no speed was measured or the
1328
+ * rest is negative, and the open estimated before stands.
1324
1329
  *
1325
1330
  * @param {object} session
1326
1331
  * @param {import("./EncodeRun.js").EncodeRun} run
@@ -1330,14 +1335,21 @@ export class EncodeRuns {
1330
1335
  #noteOpen(session, run, ended) {
1331
1336
  const grid = session.timeline?.published ?? session.timeline?.boundaries;
1332
1337
  const pieceSeconds = Number(grid?.[run.from + 1]) - Number(grid?.[run.from]);
1333
- const speed = run.speedX > 0 ? run.speedX : this.#host.encodeOrchestrator.speedOn?.(session.outputKey) ?? 0;
1338
+ const speed = run.speedX > 0 ? run.speedX : this.#speedReadings.windowOf(session).at(-1)?.speed ?? 0;
1334
1339
  // FFmpeg's reads may have waited for the stretch being copied; that wait
1335
1340
  // is the copy's, and the stretch is sized from the open (`run-open.js`).
1336
1341
  const open = runOpenOf({
1337
1342
  firstNamedMs: ended.firstNamedMs, firstNamedWallMs: ended.firstNamedWallMs, startedAt: run.startedAt,
1338
1343
  waitedBefore: run.originalInput?.waitedBefore, pieceSeconds, speed
1339
1344
  });
1340
- if (!open) return;
1345
+ if (!open) {
1346
+ if (Number.isFinite(ended.firstNamedMs) && pieceSeconds > 0) {
1347
+ this.#host.logger.info(`encode input of run #${run.from}..#${run.to} on ${session.outputKey}: open not measured ` +
1348
+ `(first piece named at ${ended.firstNamedMs}ms, ${pieceSeconds.toFixed(3)}s of film, ` +
1349
+ `${speed > 0 ? `at a measured ${speed.toFixed(2)}x the piece takes longer than that` : "no speed measured between two closed pieces"})`);
1350
+ }
1351
+ return;
1352
+ }
1341
1353
  const { openSeconds, waitedMs } = open;
1342
1354
  this.#host.encodeOrchestrator.noteOpen?.(session.outputKey ?? "", openSeconds);
1343
1355
  this.#host.logger.info(`encode input of run #${run.from}..#${run.to} on ${session.outputKey}: opened in ` +
@@ -8,6 +8,14 @@
8
8
  * wall clock, so they are taken up to the wall-clock moment the first piece
9
9
  * was named — the run's start plus its time to that name, not that time alone,
10
10
  * which as a moment lay before every wait and counted none of them.
11
+ *
12
+ * THE SPEED IS A MEASURED ONE, between two closed pieces, and a negative rest
13
+ * is no open at all: on Home Assistant runs of one piece took 6.0-7.5 s to it
14
+ * for 4 s of film, were priced at a speed of 0.08x that no run had measured,
15
+ * and recorded opens of 0.00 s; the next inputs were sized from them to one
16
+ * piece, and the runs stayed one piece each (r41, torrent-tv/meta#178). A rest
17
+ * below zero says the speed does not describe that piece, and nothing is
18
+ * recorded: the open estimated before stands.
11
19
  */
12
20
 
13
21
  /**
@@ -18,12 +26,14 @@
18
26
  * @param {((until: number) => number) | null | undefined} params.waitedBefore - The input's wall-clock waits for its copy before `until`, ms.
19
27
  * @param {number} params.pieceSeconds - The first piece's film.
20
28
  * @param {number} params.speed - Film seconds per second; 0 when not known.
21
- * @returns {{ openSeconds: number, waitedMs: number } | null} Null where any term is unknown.
29
+ * @returns {{ openSeconds: number, waitedMs: number } | null} Null where any term is
30
+ * unknown, or where the piece's encoding at that speed exceeds the time to it.
22
31
  */
23
32
  export function runOpenOf({ firstNamedMs, firstNamedWallMs, startedAt, waitedBefore, pieceSeconds, speed }) {
24
33
  if (!Number.isFinite(firstNamedMs) || !(pieceSeconds > 0) || !(speed > 0)) return null;
25
34
  const waitedMs = Number.isFinite(firstNamedWallMs) && startedAt > 0 && typeof waitedBefore === "function"
26
35
  ? waitedBefore(startedAt + firstNamedWallMs)
27
36
  : 0;
28
- return { waitedMs, openSeconds: Math.max(0, (firstNamedMs - waitedMs) / 1000 - pieceSeconds / speed) };
37
+ const openSeconds = (firstNamedMs - waitedMs) / 1000 - pieceSeconds / speed;
38
+ return openSeconds >= 0 ? { waitedMs, openSeconds } : null;
29
39
  }