@torrent-tv/proxy 2.95.10 → 2.95.11

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.10",
3
+ "version": "2.95.11",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -986,7 +986,7 @@ export class EncodeRuns {
986
986
  if (Number.isInteger(index) && (index < safeIndex || index > run.to)) return null;
987
987
  let bytes = null;
988
988
  if (admittedInput && session.segmentFormat.id === "fmp4" && session.spec.carries !== "audio-only" &&
989
- session.spec.audio && !this.#host.servesAudioSeparately(session)) {
989
+ (admittedInput.original || session.spec.audio && !this.#host.servesAudioSeparately(session))) {
990
990
  try {
991
991
  const address = session.outputKey ?? "";
992
992
  const grid = session.timeline.published ?? session.timeline.boundaries;
@@ -9,7 +9,7 @@ export function presentationSegment(current, following, { from, to }) {
9
9
  const edit = own.edits.get(id);
10
10
  if (!edit) throw new Error("A segment track has no declared clock.");
11
11
  const samples = [...track.samples];
12
- if (track.kind === "soun" && next?.tracks.has(id)) {
12
+ if (next?.tracks.has(id)) {
13
13
  const nextEdit = next.edits.get(id);
14
14
  if (!nextEdit || nextEdit.timescale !== edit.timescale) throw new Error("Adjacent segment clocks differ.");
15
15
  for (const sample of next.tracks.get(id).samples) {
@@ -18,18 +18,33 @@ export function presentationSegment(current, following, { from, to }) {
18
18
  }
19
19
  const start = BigInt(Math.round(from * Number(edit.timescale)));
20
20
  const end = BigInt(Math.round(to * Number(edit.timescale)));
21
- const selected = samples.filter(sample => {
21
+ const wanted = samples.filter(sample => {
22
22
  const pts = sample.dts + sample.composition + edit.offset;
23
- return pts < end && pts + sample.duration > start;
23
+ return pts < end && (track.kind === "vide" ? pts >= start : pts + sample.duration > start);
24
24
  });
25
+ if (!wanted.length) throw new Error("A presentation segment lacks required media.");
26
+ // An open-GOP picture before the cut can follow the next CRA in decode
27
+ // order. Retain the reference pictures through its last required DTS;
28
+ // dropping the CRA would make the recovered leading pictures undecodable.
29
+ const lastDecode = wanted.reduce((last, sample) => sample.dts > last ? sample.dts : last, -1n);
30
+ const firstDecode = wanted.reduce((first, sample) => first === null || sample.dts < first ? sample.dts : first, null);
31
+ const selected = track.kind === "vide" ? samples.filter(sample =>
32
+ sample.dts >= firstDecode && sample.dts <= lastDecode && sample.dts + sample.composition + edit.offset >= start) : wanted;
25
33
  selected.sort((left, right) => left.dts < right.dts ? -1 : left.dts > right.dts ? 1 : 0);
26
- if (!selected.length) throw new Error("A presentation segment lacks required media.");
27
34
  tracks.push({ id, samples: selected });
28
35
  }
29
36
  const makeMoof = offset => box("moof", full("mfhd", 0, 0, u32(1)), ...tracks.map(track => {
30
- const entries = track.samples.map(sample => Buffer.concat([
31
- u32(Number(sample.duration)), u32(sample.bytes.length), u32(sample.flags), i32(Number(sample.composition))
32
- ]));
37
+ let decodeTime = track.samples[0].dts;
38
+ const entries = track.samples.map(sample => {
39
+ // Removing leading pictures can leave a gap in decode timestamps.
40
+ // trun advances by durations only; retain each original presentation
41
+ // timestamp relative to the decode clock actually written here.
42
+ const composition = sample.dts + sample.composition - decodeTime;
43
+ decodeTime += sample.duration;
44
+ return Buffer.concat([
45
+ u32(Number(sample.duration)), u32(sample.bytes.length), u32(sample.flags), i32(Number(composition))
46
+ ]);
47
+ });
33
48
  const payload = Buffer.concat([u32(track.samples.length), i32(offset), ...entries]);
34
49
  offset += track.samples.reduce((bytes, sample) => bytes + sample.bytes.length, 0);
35
50
  const clock = Buffer.alloc(8);