@torrent-tv/proxy 2.80.18 → 2.81.0
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/CHANGELOG.md +22 -0
- package/docs/encode-architecture.md +51 -2
- package/package.json +1 -1
- package/research/double-spawn-2026-09-10.md +171 -0
- package/services/disk/DiskSpace.js +146 -0
- package/services/disk/wire.js +60 -0
- package/services/encode/EncodeRun.js +37 -9
- package/services/encode/SegmentStore.js +284 -232
- package/services/encode/run-command.js +16 -1
- package/services/hls-session-manager.js +31 -128
- package/services/orchestrators/EncodeOrchestrator.js +52 -38
- package/services/piece-store/allowance.js +107 -0
- package/services/piece-store/piece-disk-store.js +365 -0
- package/services/piece-store/shared-piece-store.js +1549 -1535
- package/services/segment-formats/fmp4.js +54 -0
- package/services/segment-formats/mpegts.js +54 -0
- package/services/torrent-worker/client.js +32 -0
- package/services/torrent-worker/pool-adapter.js +15 -0
- package/services/torrent-worker/protocol.js +9 -0
- package/services/torrent-worker/worker.js +8 -1
- package/services/viewer/positions.js +48 -0
- package/test/audio-inventory.test.js +176 -176
- package/test/auto-quality-step.test.js +514 -514
- package/test/concurrent-cost.test.js +138 -138
- package/test/coverage-follows-the-disk.test.js +191 -187
- package/test/coverage-map.test.js +195 -195
- package/test/declared-tracks.test.js +35 -35
- package/test/disk-space.test.js +138 -0
- package/test/encode-orchestrator.test.js +0 -3
- package/test/encode-run.test.js +5 -12
- package/test/held-request-width.test.js +155 -155
- package/test/helpers/encode-run.js +2 -2
- package/test/matroska-blocks.test.js +0 -0
- package/test/matroska-cues-track.test.js +192 -192
- package/test/mp4-composition-times.test.js +0 -0
- package/test/mp4-subtitles.test.js +173 -173
- package/test/one-authority.test.js +281 -220
- package/test/orchestrator-wired.test.js +199 -195
- package/test/packet-witness-ring.test.js +236 -236
- package/test/packet-witness.test.js +148 -148
- package/test/piece-disk-store.test.js +267 -0
- package/test/piece-reader.test.js +4 -4
- package/test/piece-store-eviction.test.js +17 -17
- package/test/piece-store-reservations.test.js +20 -1
- package/test/piece-store-slow-disk.test.js +16 -1
- package/test/produced-copy-choice.test.js +258 -358
- package/test/read-window.test.js +6 -6
- package/test/run-intervals.test.js +100 -100
- package/test/seek-landing.test.js +109 -109
- package/test/segment-serve-wiring.test.js +8 -9
- package/test/segment-store-eviction.test.js +232 -0
- package/test/segment-store.test.js +238 -216
- package/test/segments-are-shared.test.js +1 -1
- package/test/shared-piece-store.test.js +12 -12
- package/test/sidecar-naming.test.js +142 -142
- package/test/subtitle-cue-framing.test.js +200 -200
- package/test/subtitle-cue-walk.test.js +369 -369
- package/test/subtitle-defaults.test.js +97 -97
- package/test/subtitle-track-numbering.test.js +370 -370
- package/test/tail-duplication.test.js +167 -167
- package/test/tracks-begin-together.test.js +195 -195
- package/test/two-viewers-one-picture.test.js +374 -374
- package/test/video-facts.test.js +102 -102
- package/test/wedge-certainty.test.js +131 -131
- package/services/encode/open-piece.js +0 -135
- package/services/piece-store/disk-tier.js +0 -151
- package/test/open-piece.test.js +0 -152
|
@@ -1,192 +1,192 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file The container's table names a track, and only the picture's entries are
|
|
3
|
-
* cut points.
|
|
4
|
-
*
|
|
5
|
-
* Measured 2026-08-18 on the two files the field sessions were recorded from:
|
|
6
|
-
* `Minions.and.Monsters.1080p.mkv` carries 2778 cue entries for its video track
|
|
7
|
-
* — one every 2.002 s — and 4669 more across four subtitle tracks;
|
|
8
|
-
* `Moana.2 … MegaPeer.mkv` carries 1055 for video and 5007 across five subtitle
|
|
9
|
-
* tracks. Read without the track, both sets went into the cut list together,
|
|
10
|
-
* and ffmpeg — which can only cut a copied picture at a real keyframe at or
|
|
11
|
-
* after the time it is asked for — moved every such cut forward to the next
|
|
12
|
-
* keyframe. That is the whole of the disagreement the field reported: 2.002 s
|
|
13
|
-
* on the first file, a median of 6.3 s and a worst case of 21 s on the second,
|
|
14
|
-
* and never once negative.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import test from "node:test";
|
|
18
|
-
import assert from "node:assert/strict";
|
|
19
|
-
import { MatroskaContainer } from "../services/container/MatroskaContainer.js";
|
|
20
|
-
|
|
21
|
-
const ID_EBML = 0x1a45dfa3;
|
|
22
|
-
const ID_SEGMENT = 0x18538067;
|
|
23
|
-
const ID_SEEK_HEAD = 0x114d9b74;
|
|
24
|
-
const ID_SEEK = 0x4dbb;
|
|
25
|
-
const ID_SEEK_ID = 0x53ab;
|
|
26
|
-
const ID_SEEK_POSITION = 0x53ac;
|
|
27
|
-
const ID_INFO = 0x1549a966;
|
|
28
|
-
const ID_TIMESTAMP_SCALE = 0x2ad7b1;
|
|
29
|
-
const ID_TRACKS = 0x1654ae6b;
|
|
30
|
-
const ID_TRACK_ENTRY = 0xae;
|
|
31
|
-
const ID_TRACK_NUMBER = 0xd7;
|
|
32
|
-
const ID_TRACK_TYPE = 0x83;
|
|
33
|
-
const ID_CUES = 0x1c53bb6b;
|
|
34
|
-
const ID_CUE_POINT = 0xbb;
|
|
35
|
-
const ID_CUE_TIME = 0xb3;
|
|
36
|
-
const ID_CUE_TRACK_POSITIONS = 0xb7;
|
|
37
|
-
const ID_CUE_TRACK = 0xf7;
|
|
38
|
-
const ID_CUE_CLUSTER_POSITION = 0xf1;
|
|
39
|
-
|
|
40
|
-
/** An element id, as the bytes the specification gives it. */
|
|
41
|
-
function idBytes(id) {
|
|
42
|
-
const bytes = [];
|
|
43
|
-
let rest = id;
|
|
44
|
-
while (rest > 0) {
|
|
45
|
-
bytes.unshift(rest & 0xff);
|
|
46
|
-
rest = Math.floor(rest / 256);
|
|
47
|
-
}
|
|
48
|
-
return Buffer.from(bytes);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** A size, as a four-byte EBML variable-length integer. */
|
|
52
|
-
function sizeBytes(size) {
|
|
53
|
-
const buffer = Buffer.alloc(4);
|
|
54
|
-
buffer.writeUInt32BE(size, 0);
|
|
55
|
-
buffer[0] |= 0x10;
|
|
56
|
-
return buffer;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function element(id, payload) {
|
|
60
|
-
return Buffer.concat([idBytes(id), sizeBytes(payload.length), payload]);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** An unsigned value, in as few bytes as it needs. */
|
|
64
|
-
function uintElement(id, value) {
|
|
65
|
-
const bytes = [];
|
|
66
|
-
let rest = value;
|
|
67
|
-
do {
|
|
68
|
-
bytes.unshift(rest & 0xff);
|
|
69
|
-
rest = Math.floor(rest / 256);
|
|
70
|
-
} while (rest > 0);
|
|
71
|
-
return element(id, Buffer.from(bytes));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function cuePoint(timeMs, tracks) {
|
|
75
|
-
return element(ID_CUE_POINT, Buffer.concat([
|
|
76
|
-
uintElement(ID_CUE_TIME, timeMs),
|
|
77
|
-
...tracks.map((track) => element(ID_CUE_TRACK_POSITIONS, Buffer.concat([
|
|
78
|
-
uintElement(ID_CUE_TRACK, track),
|
|
79
|
-
uintElement(ID_CUE_CLUSTER_POSITION, 4096)
|
|
80
|
-
])))
|
|
81
|
-
]));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* A file with the shape the field files have: one picture, one set of subtitles,
|
|
86
|
-
* and a table that indexes both.
|
|
87
|
-
*
|
|
88
|
-
* @param {{ withTracks?: boolean }} [options]
|
|
89
|
-
* @returns {Buffer}
|
|
90
|
-
*/
|
|
91
|
-
function buildFile({ withTracks = true, cueTrack = null } = {}) {
|
|
92
|
-
const info = element(ID_INFO, uintElement(ID_TIMESTAMP_SCALE, 1_000_000));
|
|
93
|
-
const tracks = element(ID_TRACKS, Buffer.concat([
|
|
94
|
-
element(ID_TRACK_ENTRY, Buffer.concat([
|
|
95
|
-
uintElement(ID_TRACK_NUMBER, 1),
|
|
96
|
-
uintElement(ID_TRACK_TYPE, 1) // video
|
|
97
|
-
])),
|
|
98
|
-
element(ID_TRACK_ENTRY, Buffer.concat([
|
|
99
|
-
uintElement(ID_TRACK_NUMBER, 2),
|
|
100
|
-
uintElement(ID_TRACK_TYPE, 17) // subtitles
|
|
101
|
-
]))
|
|
102
|
-
]));
|
|
103
|
-
const forPicture = cueTrack ?? 1;
|
|
104
|
-
const forSubtitles = cueTrack ?? 2;
|
|
105
|
-
const cues = element(ID_CUES, Buffer.concat([
|
|
106
|
-
cuePoint(0, [forPicture]),
|
|
107
|
-
cuePoint(1070, [forSubtitles]),
|
|
108
|
-
cuePoint(2002, [forPicture]),
|
|
109
|
-
cuePoint(3141, [forSubtitles]),
|
|
110
|
-
cuePoint(4004, [forPicture])
|
|
111
|
-
]));
|
|
112
|
-
|
|
113
|
-
const seekEntry = (targetId, position) => element(ID_SEEK, Buffer.concat([
|
|
114
|
-
element(ID_SEEK_ID, idBytes(targetId)),
|
|
115
|
-
element(ID_SEEK_POSITION, (() => {
|
|
116
|
-
const buffer = Buffer.alloc(4);
|
|
117
|
-
buffer.writeUInt32BE(position, 0);
|
|
118
|
-
return buffer;
|
|
119
|
-
})())
|
|
120
|
-
]));
|
|
121
|
-
// Positions are relative to the Segment's payload, so the SeekHead has to be
|
|
122
|
-
// measured before they can be stated. Its own length does not change when the
|
|
123
|
-
// placeholders become real values: every size and position here is written at
|
|
124
|
-
// a fixed width.
|
|
125
|
-
const draft = element(ID_SEEK_HEAD, Buffer.concat([
|
|
126
|
-
seekEntry(ID_INFO, 0),
|
|
127
|
-
...(withTracks ? [seekEntry(ID_TRACKS, 0)] : []),
|
|
128
|
-
seekEntry(ID_CUES, 0)
|
|
129
|
-
]));
|
|
130
|
-
const infoAt = draft.length;
|
|
131
|
-
const tracksAt = infoAt + info.length;
|
|
132
|
-
const cuesAt = withTracks ? tracksAt + tracks.length : infoAt + info.length;
|
|
133
|
-
const seekHead = element(ID_SEEK_HEAD, Buffer.concat([
|
|
134
|
-
seekEntry(ID_INFO, infoAt),
|
|
135
|
-
...(withTracks ? [seekEntry(ID_TRACKS, tracksAt)] : []),
|
|
136
|
-
seekEntry(ID_CUES, cuesAt)
|
|
137
|
-
]));
|
|
138
|
-
|
|
139
|
-
const segmentPayload = Buffer.concat(
|
|
140
|
-
withTracks ? [seekHead, info, tracks, cues] : [seekHead, info, cues]
|
|
141
|
-
);
|
|
142
|
-
return Buffer.concat([
|
|
143
|
-
element(ID_EBML, Buffer.from([0x42, 0x86, 0x81, 0x01])),
|
|
144
|
-
element(ID_SEGMENT, segmentPayload)
|
|
145
|
-
]);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function readerOver(file) {
|
|
149
|
-
return async (start, end) => {
|
|
150
|
-
const last = Math.min(end, file.length - 1);
|
|
151
|
-
return start > last ? null : file.subarray(start, last + 1);
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
test("only the picture's entries become cut times", async () => {
|
|
156
|
-
const file = buildFile();
|
|
157
|
-
|
|
158
|
-
const times = await MatroskaContainer.readKeyframeTimes(readerOver(file), file.length);
|
|
159
|
-
|
|
160
|
-
assert.deepEqual(
|
|
161
|
-
times.map((time) => Number(time.toFixed(3))),
|
|
162
|
-
[0, 2.002, 4.004],
|
|
163
|
-
"the subtitle entries at 1.070 and 3.141 are not keyframes, and a cut asked for there lands late"
|
|
164
|
-
);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test("a table whose entries name no known track is still used", async () => {
|
|
168
|
-
// The cue points reference track 9, which Tracks never declares. Filtering
|
|
169
|
-
// leaves nothing — and returning nothing would put an even grid on a copied
|
|
170
|
-
// picture, the failure this reader exists to prevent.
|
|
171
|
-
const file = buildFile({ cueTrack: 9 });
|
|
172
|
-
|
|
173
|
-
const times = await MatroskaContainer.readKeyframeTimes(readerOver(file), file.length);
|
|
174
|
-
|
|
175
|
-
assert.deepEqual(
|
|
176
|
-
times.map((time) => Number(time.toFixed(3))),
|
|
177
|
-
[0, 1.07, 2.002, 3.141, 4.004],
|
|
178
|
-
"an unrecognised table beats no table at all"
|
|
179
|
-
);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test("a file whose tracks cannot be read keeps every entry", async () => {
|
|
183
|
-
const file = buildFile({ withTracks: false });
|
|
184
|
-
|
|
185
|
-
const times = await MatroskaContainer.readKeyframeTimes(readerOver(file), file.length);
|
|
186
|
-
|
|
187
|
-
assert.deepEqual(
|
|
188
|
-
times.map((time) => Number(time.toFixed(3))),
|
|
189
|
-
[0, 1.07, 2.002, 3.141, 4.004],
|
|
190
|
-
"with nothing to tell the tracks apart, the old behaviour is the only one available"
|
|
191
|
-
);
|
|
192
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @file The container's table names a track, and only the picture's entries are
|
|
3
|
+
* cut points.
|
|
4
|
+
*
|
|
5
|
+
* Measured 2026-08-18 on the two files the field sessions were recorded from:
|
|
6
|
+
* `Minions.and.Monsters.1080p.mkv` carries 2778 cue entries for its video track
|
|
7
|
+
* — one every 2.002 s — and 4669 more across four subtitle tracks;
|
|
8
|
+
* `Moana.2 … MegaPeer.mkv` carries 1055 for video and 5007 across five subtitle
|
|
9
|
+
* tracks. Read without the track, both sets went into the cut list together,
|
|
10
|
+
* and ffmpeg — which can only cut a copied picture at a real keyframe at or
|
|
11
|
+
* after the time it is asked for — moved every such cut forward to the next
|
|
12
|
+
* keyframe. That is the whole of the disagreement the field reported: 2.002 s
|
|
13
|
+
* on the first file, a median of 6.3 s and a worst case of 21 s on the second,
|
|
14
|
+
* and never once negative.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import test from "node:test";
|
|
18
|
+
import assert from "node:assert/strict";
|
|
19
|
+
import { MatroskaContainer } from "../services/container/MatroskaContainer.js";
|
|
20
|
+
|
|
21
|
+
const ID_EBML = 0x1a45dfa3;
|
|
22
|
+
const ID_SEGMENT = 0x18538067;
|
|
23
|
+
const ID_SEEK_HEAD = 0x114d9b74;
|
|
24
|
+
const ID_SEEK = 0x4dbb;
|
|
25
|
+
const ID_SEEK_ID = 0x53ab;
|
|
26
|
+
const ID_SEEK_POSITION = 0x53ac;
|
|
27
|
+
const ID_INFO = 0x1549a966;
|
|
28
|
+
const ID_TIMESTAMP_SCALE = 0x2ad7b1;
|
|
29
|
+
const ID_TRACKS = 0x1654ae6b;
|
|
30
|
+
const ID_TRACK_ENTRY = 0xae;
|
|
31
|
+
const ID_TRACK_NUMBER = 0xd7;
|
|
32
|
+
const ID_TRACK_TYPE = 0x83;
|
|
33
|
+
const ID_CUES = 0x1c53bb6b;
|
|
34
|
+
const ID_CUE_POINT = 0xbb;
|
|
35
|
+
const ID_CUE_TIME = 0xb3;
|
|
36
|
+
const ID_CUE_TRACK_POSITIONS = 0xb7;
|
|
37
|
+
const ID_CUE_TRACK = 0xf7;
|
|
38
|
+
const ID_CUE_CLUSTER_POSITION = 0xf1;
|
|
39
|
+
|
|
40
|
+
/** An element id, as the bytes the specification gives it. */
|
|
41
|
+
function idBytes(id) {
|
|
42
|
+
const bytes = [];
|
|
43
|
+
let rest = id;
|
|
44
|
+
while (rest > 0) {
|
|
45
|
+
bytes.unshift(rest & 0xff);
|
|
46
|
+
rest = Math.floor(rest / 256);
|
|
47
|
+
}
|
|
48
|
+
return Buffer.from(bytes);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A size, as a four-byte EBML variable-length integer. */
|
|
52
|
+
function sizeBytes(size) {
|
|
53
|
+
const buffer = Buffer.alloc(4);
|
|
54
|
+
buffer.writeUInt32BE(size, 0);
|
|
55
|
+
buffer[0] |= 0x10;
|
|
56
|
+
return buffer;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function element(id, payload) {
|
|
60
|
+
return Buffer.concat([idBytes(id), sizeBytes(payload.length), payload]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** An unsigned value, in as few bytes as it needs. */
|
|
64
|
+
function uintElement(id, value) {
|
|
65
|
+
const bytes = [];
|
|
66
|
+
let rest = value;
|
|
67
|
+
do {
|
|
68
|
+
bytes.unshift(rest & 0xff);
|
|
69
|
+
rest = Math.floor(rest / 256);
|
|
70
|
+
} while (rest > 0);
|
|
71
|
+
return element(id, Buffer.from(bytes));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function cuePoint(timeMs, tracks) {
|
|
75
|
+
return element(ID_CUE_POINT, Buffer.concat([
|
|
76
|
+
uintElement(ID_CUE_TIME, timeMs),
|
|
77
|
+
...tracks.map((track) => element(ID_CUE_TRACK_POSITIONS, Buffer.concat([
|
|
78
|
+
uintElement(ID_CUE_TRACK, track),
|
|
79
|
+
uintElement(ID_CUE_CLUSTER_POSITION, 4096)
|
|
80
|
+
])))
|
|
81
|
+
]));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A file with the shape the field files have: one picture, one set of subtitles,
|
|
86
|
+
* and a table that indexes both.
|
|
87
|
+
*
|
|
88
|
+
* @param {{ withTracks?: boolean }} [options]
|
|
89
|
+
* @returns {Buffer}
|
|
90
|
+
*/
|
|
91
|
+
function buildFile({ withTracks = true, cueTrack = null } = {}) {
|
|
92
|
+
const info = element(ID_INFO, uintElement(ID_TIMESTAMP_SCALE, 1_000_000));
|
|
93
|
+
const tracks = element(ID_TRACKS, Buffer.concat([
|
|
94
|
+
element(ID_TRACK_ENTRY, Buffer.concat([
|
|
95
|
+
uintElement(ID_TRACK_NUMBER, 1),
|
|
96
|
+
uintElement(ID_TRACK_TYPE, 1) // video
|
|
97
|
+
])),
|
|
98
|
+
element(ID_TRACK_ENTRY, Buffer.concat([
|
|
99
|
+
uintElement(ID_TRACK_NUMBER, 2),
|
|
100
|
+
uintElement(ID_TRACK_TYPE, 17) // subtitles
|
|
101
|
+
]))
|
|
102
|
+
]));
|
|
103
|
+
const forPicture = cueTrack ?? 1;
|
|
104
|
+
const forSubtitles = cueTrack ?? 2;
|
|
105
|
+
const cues = element(ID_CUES, Buffer.concat([
|
|
106
|
+
cuePoint(0, [forPicture]),
|
|
107
|
+
cuePoint(1070, [forSubtitles]),
|
|
108
|
+
cuePoint(2002, [forPicture]),
|
|
109
|
+
cuePoint(3141, [forSubtitles]),
|
|
110
|
+
cuePoint(4004, [forPicture])
|
|
111
|
+
]));
|
|
112
|
+
|
|
113
|
+
const seekEntry = (targetId, position) => element(ID_SEEK, Buffer.concat([
|
|
114
|
+
element(ID_SEEK_ID, idBytes(targetId)),
|
|
115
|
+
element(ID_SEEK_POSITION, (() => {
|
|
116
|
+
const buffer = Buffer.alloc(4);
|
|
117
|
+
buffer.writeUInt32BE(position, 0);
|
|
118
|
+
return buffer;
|
|
119
|
+
})())
|
|
120
|
+
]));
|
|
121
|
+
// Positions are relative to the Segment's payload, so the SeekHead has to be
|
|
122
|
+
// measured before they can be stated. Its own length does not change when the
|
|
123
|
+
// placeholders become real values: every size and position here is written at
|
|
124
|
+
// a fixed width.
|
|
125
|
+
const draft = element(ID_SEEK_HEAD, Buffer.concat([
|
|
126
|
+
seekEntry(ID_INFO, 0),
|
|
127
|
+
...(withTracks ? [seekEntry(ID_TRACKS, 0)] : []),
|
|
128
|
+
seekEntry(ID_CUES, 0)
|
|
129
|
+
]));
|
|
130
|
+
const infoAt = draft.length;
|
|
131
|
+
const tracksAt = infoAt + info.length;
|
|
132
|
+
const cuesAt = withTracks ? tracksAt + tracks.length : infoAt + info.length;
|
|
133
|
+
const seekHead = element(ID_SEEK_HEAD, Buffer.concat([
|
|
134
|
+
seekEntry(ID_INFO, infoAt),
|
|
135
|
+
...(withTracks ? [seekEntry(ID_TRACKS, tracksAt)] : []),
|
|
136
|
+
seekEntry(ID_CUES, cuesAt)
|
|
137
|
+
]));
|
|
138
|
+
|
|
139
|
+
const segmentPayload = Buffer.concat(
|
|
140
|
+
withTracks ? [seekHead, info, tracks, cues] : [seekHead, info, cues]
|
|
141
|
+
);
|
|
142
|
+
return Buffer.concat([
|
|
143
|
+
element(ID_EBML, Buffer.from([0x42, 0x86, 0x81, 0x01])),
|
|
144
|
+
element(ID_SEGMENT, segmentPayload)
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function readerOver(file) {
|
|
149
|
+
return async (start, end) => {
|
|
150
|
+
const last = Math.min(end, file.length - 1);
|
|
151
|
+
return start > last ? null : file.subarray(start, last + 1);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
test("only the picture's entries become cut times", async () => {
|
|
156
|
+
const file = buildFile();
|
|
157
|
+
|
|
158
|
+
const times = await MatroskaContainer.readKeyframeTimes(readerOver(file), file.length);
|
|
159
|
+
|
|
160
|
+
assert.deepEqual(
|
|
161
|
+
times.map((time) => Number(time.toFixed(3))),
|
|
162
|
+
[0, 2.002, 4.004],
|
|
163
|
+
"the subtitle entries at 1.070 and 3.141 are not keyframes, and a cut asked for there lands late"
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("a table whose entries name no known track is still used", async () => {
|
|
168
|
+
// The cue points reference track 9, which Tracks never declares. Filtering
|
|
169
|
+
// leaves nothing — and returning nothing would put an even grid on a copied
|
|
170
|
+
// picture, the failure this reader exists to prevent.
|
|
171
|
+
const file = buildFile({ cueTrack: 9 });
|
|
172
|
+
|
|
173
|
+
const times = await MatroskaContainer.readKeyframeTimes(readerOver(file), file.length);
|
|
174
|
+
|
|
175
|
+
assert.deepEqual(
|
|
176
|
+
times.map((time) => Number(time.toFixed(3))),
|
|
177
|
+
[0, 1.07, 2.002, 3.141, 4.004],
|
|
178
|
+
"an unrecognised table beats no table at all"
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("a file whose tracks cannot be read keeps every entry", async () => {
|
|
183
|
+
const file = buildFile({ withTracks: false });
|
|
184
|
+
|
|
185
|
+
const times = await MatroskaContainer.readKeyframeTimes(readerOver(file), file.length);
|
|
186
|
+
|
|
187
|
+
assert.deepEqual(
|
|
188
|
+
times.map((time) => Number(time.toFixed(3))),
|
|
189
|
+
[0, 1.07, 2.002, 3.141, 4.004],
|
|
190
|
+
"with nothing to tell the tracks apart, the old behaviour is the only one available"
|
|
191
|
+
);
|
|
192
|
+
});
|
|
Binary file
|