@torrent-tv/proxy 2.100.14 → 2.100.15
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
|
@@ -337,9 +337,15 @@ export class EncodeInputs {
|
|
|
337
337
|
* @returns {{ bytes: number, openMeasured: boolean } | null}
|
|
338
338
|
*/
|
|
339
339
|
stretchFor(output) {
|
|
340
|
+
const sizing = this.#sizingFor(output);
|
|
341
|
+
return sizing ? { bytes: sizing.bytes, openMeasured: sizing.openMeasured } : null;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
#sizingFor(output) {
|
|
340
345
|
const rate = middleOf(this.#copyRates);
|
|
341
346
|
const open = this.#openOf(output);
|
|
342
|
-
return rate === null || !open ? null : { bytes: Math.floor(rate * open.seconds * 1000),
|
|
347
|
+
return rate === null || !open ? null : { bytes: Math.floor(rate * open.seconds * 1000),
|
|
348
|
+
openMeasured: open.measured, openSeconds: open.seconds, copyBytesPerMs: rate };
|
|
343
349
|
}
|
|
344
350
|
|
|
345
351
|
/**
|
|
@@ -493,6 +499,9 @@ export class EncodeInputs {
|
|
|
493
499
|
*/
|
|
494
500
|
async #admitStretch(request, firstSources) {
|
|
495
501
|
const { output, from } = request;
|
|
502
|
+
// Record existing decisions only: diagnostics must not resolve another
|
|
503
|
+
// interval or ask storage for an additional availability reading.
|
|
504
|
+
const probes = [], reservations = [];
|
|
496
505
|
let minimum = originalInputBytes(firstSources);
|
|
497
506
|
const stretches = new Map([[from, { sources: firstSources, bytes: minimum }]]);
|
|
498
507
|
const held = new Map();
|
|
@@ -508,7 +517,11 @@ export class EncodeInputs {
|
|
|
508
517
|
};
|
|
509
518
|
const fits = async (end, maxBytes) => {
|
|
510
519
|
const stretch = await at(end);
|
|
511
|
-
|
|
520
|
+
const withinLimit = Boolean(stretch) && stretch.bytes <= maxBytes;
|
|
521
|
+
const result = !stretch ? "unresolved" : !withinLimit ? "size"
|
|
522
|
+
: await this.#present(stretch.sources, held, request.timing) ? "fits" : "missing-bytes";
|
|
523
|
+
probes.push({ end, limitBytes: maxBytes, bytes: stretch?.bytes ?? null, result });
|
|
524
|
+
return result === "fits";
|
|
512
525
|
};
|
|
513
526
|
// Grows by doubling and then halves back: a handful of resolutions find
|
|
514
527
|
// the end whether it is a piece away or the rest of the film.
|
|
@@ -535,10 +548,11 @@ export class EncodeInputs {
|
|
|
535
548
|
}
|
|
536
549
|
return good;
|
|
537
550
|
};
|
|
538
|
-
const sizing = this
|
|
551
|
+
const sizing = this.#sizingFor(output);
|
|
539
552
|
const target = sizing?.bytes ?? null;
|
|
540
553
|
if (sizing && !sizing.openMeasured) request.timing.openApproximate = true;
|
|
541
554
|
let end = target === null || this.#heldRanges === null ? floor : await longest(target);
|
|
555
|
+
const targetEnd = end;
|
|
542
556
|
if (this.#requests.get(request.key) !== request) return undefined;
|
|
543
557
|
this.#wanted.set(request.key, { wanted: stretches.get(end).bytes, required: minimum });
|
|
544
558
|
await this.#spent(request.timing, "budgetMs", () => this.#revise());
|
|
@@ -576,7 +590,13 @@ export class EncodeInputs {
|
|
|
576
590
|
if (this.#requests.get(request.key) !== request) return undefined;
|
|
577
591
|
this.#wanted.set(request.key, { wanted: chosen.bytes, required: chosen.bytes });
|
|
578
592
|
result = await admitOriginalInput({ sources: chosen.sources, readRanges: this.#read, now: this.#now,
|
|
579
|
-
reserve: async bytes =>
|
|
593
|
+
reserve: async bytes => {
|
|
594
|
+
const reservation = { bytes, allowed: this.#allowed, held: this.#held, capacity,
|
|
595
|
+
room: roomNow(), end };
|
|
596
|
+
const release = this.#hold(request, bytes);
|
|
597
|
+
reservations.push({ ...reservation, admitted: typeof release === "function" });
|
|
598
|
+
return release;
|
|
599
|
+
} });
|
|
580
600
|
// Another output's copy can take the room this one was sized for while
|
|
581
601
|
// it was being chosen. A shorter stretch is tried at once rather than
|
|
582
602
|
// waiting for a memory change that may never come.
|
|
@@ -585,6 +605,12 @@ export class EncodeInputs {
|
|
|
585
605
|
}
|
|
586
606
|
if (result.kind === "needs-memory") this.#wanted.set(request.key, { wanted: minimum, required: minimum });
|
|
587
607
|
if (result.kind === "result") {
|
|
608
|
+
this.#log(`encode input selection of ${addressOf(output)}: ${JSON.stringify({
|
|
609
|
+
from, requestedTo: request.to, serves, floor, targetEnd, chosenEnd: end,
|
|
610
|
+
targetBytes: target, minimumBytes: minimum, inputBytes: result.bytes,
|
|
611
|
+
copyBytesPerMs: sizing?.copyBytesPerMs ?? null, openSeconds: sizing?.openSeconds ?? null,
|
|
612
|
+
openMeasured: sizing?.openMeasured ?? null, reservations, probes
|
|
613
|
+
})}`);
|
|
588
614
|
Object.assign(result, { from, to: end });
|
|
589
615
|
// The stretch is copied after the answer, while the run opens; the rate
|
|
590
616
|
// is the whole copy's, learned once it is done.
|