node-av 6.2.0-beta.8 → 6.2.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.
Files changed (103) hide show
  1. package/README.md +7 -19
  2. package/dist/api/audio-frame-buffer.d.ts +378 -19
  3. package/dist/api/audio-frame-buffer.js +715 -101
  4. package/dist/api/audio-frame-buffer.js.map +1 -1
  5. package/dist/api/data/test_av1.ivf +0 -0
  6. package/dist/api/data/test_hevc.h265 +0 -0
  7. package/dist/api/data/test_vp9.ivf +0 -0
  8. package/dist/api/decoder.d.ts +117 -2
  9. package/dist/api/decoder.js +290 -23
  10. package/dist/api/decoder.js.map +1 -1
  11. package/dist/api/demuxer.d.ts +19 -3
  12. package/dist/api/demuxer.js +95 -29
  13. package/dist/api/demuxer.js.map +1 -1
  14. package/dist/api/encoder-pool.js +9 -1
  15. package/dist/api/encoder-pool.js.map +1 -1
  16. package/dist/api/encoder.d.ts +100 -6
  17. package/dist/api/encoder.js +249 -108
  18. package/dist/api/encoder.js.map +1 -1
  19. package/dist/api/filter-presets.d.ts +25 -1
  20. package/dist/api/filter-presets.js +63 -3
  21. package/dist/api/filter-presets.js.map +1 -1
  22. package/dist/api/filter.d.ts +62 -3
  23. package/dist/api/filter.js +118 -36
  24. package/dist/api/filter.js.map +1 -1
  25. package/dist/api/fmp4-stream.d.ts +179 -15
  26. package/dist/api/fmp4-stream.js +341 -120
  27. package/dist/api/fmp4-stream.js.map +1 -1
  28. package/dist/api/hardware.d.ts +2 -0
  29. package/dist/api/hardware.js +33 -10
  30. package/dist/api/hardware.js.map +1 -1
  31. package/dist/api/index.d.ts +2 -2
  32. package/dist/api/index.js.map +1 -1
  33. package/dist/api/io-stream.d.ts +3 -2
  34. package/dist/api/io-stream.js +23 -7
  35. package/dist/api/io-stream.js.map +1 -1
  36. package/dist/api/muxer.d.ts +276 -7
  37. package/dist/api/muxer.js +649 -116
  38. package/dist/api/muxer.js.map +1 -1
  39. package/dist/api/pipeline.d.ts +22 -0
  40. package/dist/api/pipeline.js +53 -0
  41. package/dist/api/pipeline.js.map +1 -1
  42. package/dist/api/rtp-stream.d.ts +58 -20
  43. package/dist/api/rtp-stream.js +237 -129
  44. package/dist/api/rtp-stream.js.map +1 -1
  45. package/dist/api/scaler.d.ts +39 -6
  46. package/dist/api/scaler.js +72 -18
  47. package/dist/api/scaler.js.map +1 -1
  48. package/dist/api/utilities/live-decoding.d.ts +15 -0
  49. package/dist/api/utilities/live-decoding.js +32 -0
  50. package/dist/api/utilities/live-decoding.js.map +1 -0
  51. package/dist/api/utilities/packet-age-watchdog.d.ts +198 -0
  52. package/dist/api/utilities/packet-age-watchdog.js +594 -0
  53. package/dist/api/utilities/packet-age-watchdog.js.map +1 -0
  54. package/dist/api/utilities/scale-size.d.ts +51 -0
  55. package/dist/api/utilities/scale-size.js +55 -0
  56. package/dist/api/utilities/scale-size.js.map +1 -0
  57. package/dist/api/utilities/video-transcode.d.ts +218 -0
  58. package/dist/api/utilities/video-transcode.js +624 -0
  59. package/dist/api/utilities/video-transcode.js.map +1 -0
  60. package/dist/constants/constants.d.ts +1 -0
  61. package/dist/constants/constants.js +1 -0
  62. package/dist/constants/constants.js.map +1 -1
  63. package/dist/constants/filter-options.d.ts +2 -0
  64. package/dist/ffmpeg/utils.js +7 -4
  65. package/dist/ffmpeg/utils.js.map +1 -1
  66. package/dist/lib/binding.d.ts +10 -1
  67. package/dist/lib/binding.js +25 -16
  68. package/dist/lib/binding.js.map +1 -1
  69. package/dist/lib/bitstream-filter-context.d.ts +2 -0
  70. package/dist/lib/bitstream-filter-context.js +2 -0
  71. package/dist/lib/bitstream-filter-context.js.map +1 -1
  72. package/dist/lib/filter-context.d.ts +3 -0
  73. package/dist/lib/filter-context.js +3 -0
  74. package/dist/lib/filter-context.js.map +1 -1
  75. package/dist/lib/filter-graph-segment.d.ts +3 -2
  76. package/dist/lib/filter-graph-segment.js +3 -2
  77. package/dist/lib/filter-graph-segment.js.map +1 -1
  78. package/dist/lib/filter-graph.d.ts +4 -4
  79. package/dist/lib/filter-graph.js +4 -4
  80. package/dist/lib/filter-inout.d.ts +4 -0
  81. package/dist/lib/filter-inout.js +4 -0
  82. package/dist/lib/filter-inout.js.map +1 -1
  83. package/dist/lib/format-context.d.ts +27 -3
  84. package/dist/lib/format-context.js +30 -6
  85. package/dist/lib/format-context.js.map +1 -1
  86. package/dist/lib/frame.d.ts +6 -2
  87. package/dist/lib/frame.js +11 -3
  88. package/dist/lib/frame.js.map +1 -1
  89. package/dist/lib/io-context.d.ts +4 -2
  90. package/dist/lib/io-context.js +4 -2
  91. package/dist/lib/io-context.js.map +1 -1
  92. package/dist/lib/native-types.d.ts +7 -3
  93. package/dist/lib/output-format.d.ts +42 -0
  94. package/dist/lib/output-format.js +46 -0
  95. package/dist/lib/output-format.js.map +1 -1
  96. package/dist/lib/stream.d.ts +5 -0
  97. package/dist/lib/stream.js +5 -0
  98. package/dist/lib/stream.js.map +1 -1
  99. package/dist/lib/utilities.d.ts +26 -0
  100. package/dist/lib/utilities.js +28 -0
  101. package/dist/lib/utilities.js.map +1 -1
  102. package/install/check.js +14 -16
  103. package/package.json +27 -44
@@ -0,0 +1,594 @@
1
+ /**
2
+ * Box types (big-endian fourcc) the watchdog reads from the fMP4 output.
3
+ *
4
+ * @internal
5
+ */
6
+ const BOX = {
7
+ moof: 0x6d6f6f66,
8
+ moov: 0x6d6f6f76,
9
+ traf: 0x74726166,
10
+ tfhd: 0x74666864,
11
+ trun: 0x7472756e,
12
+ trak: 0x7472616b,
13
+ tkhd: 0x746b6864,
14
+ mdia: 0x6d646961,
15
+ minf: 0x6d696e66,
16
+ stbl: 0x7374626c,
17
+ stsz: 0x7374737a,
18
+ stz2: 0x73747a32,
19
+ };
20
+ /**
21
+ * Largest moof/moov collected across output chunks; anything larger is treated as corrupt framing.
22
+ *
23
+ * @internal
24
+ */
25
+ const MAX_COLLECTED_BOX = 32 * 1024 * 1024;
26
+ /**
27
+ * Longest time between two packets (ms) that counts towards packet ages; a longer pause of the whole input counts as this much.
28
+ *
29
+ * @internal
30
+ */
31
+ const MAX_COUNTED_GAP_MS = 2000;
32
+ /**
33
+ * FIFO of packet arrival times (ms on the watchdog's input clock) for one output stream, kept in a growable ring buffer.
34
+ *
35
+ * @internal
36
+ */
37
+ class ArrivalQueue {
38
+ ring = new Float64Array(256);
39
+ head = 0;
40
+ _count = 0;
41
+ /**
42
+ * Number of packets waiting for a fragment.
43
+ *
44
+ * @returns Pending packet count
45
+ *
46
+ * @internal
47
+ */
48
+ get count() {
49
+ return this._count;
50
+ }
51
+ /**
52
+ * Arrival time of the oldest pending packet.
53
+ *
54
+ * @returns Time in ms, or NaN when nothing is pending
55
+ *
56
+ * @internal
57
+ */
58
+ oldest() {
59
+ return this._count > 0 ? this.ring[this.head] : NaN;
60
+ }
61
+ /**
62
+ * Append the arrival time of a packet the muxer accepted.
63
+ *
64
+ * @param time - Arrival time in ms
65
+ *
66
+ * @internal
67
+ */
68
+ push(time) {
69
+ if (this._count === this.ring.length) {
70
+ // Doubling keeps pushes amortised O(1); the ring only grows while a
71
+ // stream is held back, which the watchdog bounds.
72
+ const grown = new Float64Array(this.ring.length * 2);
73
+ const tail = this.ring.subarray(this.head);
74
+ grown.set(tail);
75
+ grown.set(this.ring.subarray(0, this.head), tail.length);
76
+ this.ring = grown;
77
+ this.head = 0;
78
+ }
79
+ this.ring[(this.head + this._count) & (this.ring.length - 1)] = time;
80
+ this._count++;
81
+ }
82
+ /**
83
+ * Remove the most recent arrival (a packet the muxer dropped).
84
+ *
85
+ * @internal
86
+ */
87
+ dropNewest() {
88
+ if (this._count > 0) {
89
+ this._count--;
90
+ }
91
+ }
92
+ /**
93
+ * Remove the oldest arrivals (packets emitted in a fragment).
94
+ *
95
+ * Removes at most what is pending: more emitted samples than recorded
96
+ * packets cannot be credited to later packets.
97
+ *
98
+ * @param n - Number of emitted samples
99
+ *
100
+ * @internal
101
+ */
102
+ dropOldest(n) {
103
+ const k = Math.min(n, this._count);
104
+ this.head = (this.head + k) & (this.ring.length - 1);
105
+ this._count -= k;
106
+ }
107
+ }
108
+ /**
109
+ * Bounds how long an fMP4 muxer may hold a packet before emitting it in a fragment.
110
+ *
111
+ * Remembers when each packet reached the muxer, per output stream and in order, and
112
+ * forgets packets as the fragments carrying them are written. When the oldest pending
113
+ * packet of any stream is older than the limit, the next packet write fails with a
114
+ * descriptive error. The age does not depend on packet timestamps, so it also bounds
115
+ * retention caused by missing, constant or runaway timestamps. It counts the time
116
+ * while packets arrive: a pause of the whole input counts at most 2 s, so a source
117
+ * that goes quiet and resumes is not mistaken for a stalled muxer.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * const watchdog = new PacketAgeWatchdog(60, (index) => `stream ${index}`);
122
+ * const output = await Muxer.open(
123
+ * {
124
+ * write: (chunk) => {
125
+ * watchdog.consumeChunk(chunk);
126
+ * return chunk.length;
127
+ * },
128
+ * },
129
+ * { format: 'mp4', options: { movflags: '+frag_keyframe+empty_moov' } },
130
+ * );
131
+ * output.setPacketObserver(watchdog);
132
+ * ```
133
+ *
134
+ * @see {@link Muxer.setPacketObserver} For registering it with a muxer
135
+ *
136
+ * @internal
137
+ */
138
+ export class PacketAgeWatchdog {
139
+ limitMs;
140
+ limitSeconds;
141
+ describeStream;
142
+ queues = [];
143
+ // Input clock (ms): advances with performance.now() between packets, by at
144
+ // most MAX_COUNTED_GAP_MS per gap. Arrival times and ages are on this clock.
145
+ clock = 0;
146
+ lastArrival = performance.now();
147
+ // Chunk mode framing: header bytes of the current top-level box, bytes left to
148
+ // skip in a box nobody needs (mdat), and a moof/moov collected across chunks.
149
+ header = Buffer.alloc(16);
150
+ headerFill = 0;
151
+ skipRemaining = 0;
152
+ partialBox = null;
153
+ partialFill = 0;
154
+ blind = false;
155
+ /**
156
+ * @param limitSeconds - Maximum age of a pending packet in seconds (> 0)
157
+ *
158
+ * @param describeStream - Label for an output stream in the error message (e.g. its media type)
159
+ *
160
+ * @internal
161
+ */
162
+ constructor(limitSeconds, describeStream) {
163
+ this.limitSeconds = limitSeconds;
164
+ this.limitMs = limitSeconds * 1000;
165
+ this.describeStream = describeStream;
166
+ }
167
+ /**
168
+ * Number of packets of a stream that have not been emitted in a fragment yet.
169
+ *
170
+ * @param streamIndex - Output stream index
171
+ *
172
+ * @returns Pending packet count
173
+ *
174
+ * @internal
175
+ */
176
+ pendingPackets(streamIndex) {
177
+ return this.queues[streamIndex]?.count ?? 0;
178
+ }
179
+ /**
180
+ * Age of the oldest pending packet of a stream, as the next packet would see it.
181
+ *
182
+ * @param streamIndex - Output stream index
183
+ *
184
+ * @param now - Current time in ms (performance.now() clock)
185
+ *
186
+ * @returns Age in ms of input time, or 0 when nothing is pending
187
+ *
188
+ * @internal
189
+ */
190
+ pendingAge(streamIndex, now = performance.now()) {
191
+ const queue = this.queues[streamIndex];
192
+ if (!queue || queue.count === 0) {
193
+ return 0;
194
+ }
195
+ return this.clock + Math.min(now - this.lastArrival, MAX_COUNTED_GAP_MS) - queue.oldest();
196
+ }
197
+ /**
198
+ * Record a packet the muxer accepted.
199
+ *
200
+ * Checks every stream first, so a stream that is held back is caught by the
201
+ * packets of the streams that still flow.
202
+ *
203
+ * @param streamIndex - Output stream index
204
+ *
205
+ * @throws {Error} If a pending packet of any stream is older than the limit
206
+ *
207
+ * @internal
208
+ */
209
+ onPacket(streamIndex) {
210
+ if (this.blind) {
211
+ return;
212
+ }
213
+ // Ages count input time, not wall-clock time. mux.c keeps the last packet
214
+ // of each stream until the next one arrives and movenc emits a sample only
215
+ // when a later packet closes its fragment, so a few packets are always
216
+ // pending. Across a pause of the whole input (a stalled source, host
217
+ // suspend) they would otherwise age and fail the first packet after it,
218
+ // although nothing piled up. Packets pile up only while packets flow, with
219
+ // gaps far below the cap, so capping each gap does not delay detection.
220
+ const now = performance.now();
221
+ this.clock += Math.min(now - this.lastArrival, MAX_COUNTED_GAP_MS);
222
+ this.lastArrival = now;
223
+ const clock = this.clock;
224
+ for (let i = 0; i < this.queues.length; i++) {
225
+ const queue = this.queues[i];
226
+ if (queue && queue.count > 0 && clock - queue.oldest() > this.limitMs) {
227
+ throw this.violation(i, clock - queue.oldest(), queue.count);
228
+ }
229
+ }
230
+ (this.queues[streamIndex] ??= new ArrivalQueue()).push(clock);
231
+ }
232
+ /**
233
+ * Forget a packet of a stream that the muxer accepted but dropped.
234
+ *
235
+ * @param streamIndex - Output stream index
236
+ *
237
+ * @internal
238
+ */
239
+ onPacketRejected(streamIndex) {
240
+ // Usually the dropped packet is the newest one, but libavformat can reject a
241
+ // packet while later ones already wait behind it. Removing the newest keeps
242
+ // the count exact and errs towards older arrival times, by no more than the
243
+ // packets queued behind it.
244
+ // A failed av_interleaved_write_frame() is reported against the packet the
245
+ // muxer submitted, but mux.c also returns the error of writing out an
246
+ // earlier buffered packet, possibly of another stream. The total stays
247
+ // exact; per stream one entry can land in the wrong queue, which skews
248
+ // ages by about one packet interval and leaves one entry that ages if the
249
+ // stream that really lost the packet then goes quiet. movenc fails that
250
+ // late only on I/O and allocation errors and a few packet checks (a PTS
251
+ // 2^31 or more ticks from its DTS, a malformed first AAC packet). An AVIO
252
+ // error is sticky and fails every later write, so the age limit ending such
253
+ // a session is wanted, not a false alarm.
254
+ this.queues[streamIndex]?.dropNewest();
255
+ }
256
+ /**
257
+ * Stop judging packet ages for the rest of the session.
258
+ *
259
+ * For a caller that frames the output itself and lost the box boundaries:
260
+ * emitted samples can no longer be counted, and pending packets would
261
+ * otherwise look stalled. Drops what it has recorded and records nothing
262
+ * more, so a blind session holds no state.
263
+ *
264
+ * @internal
265
+ */
266
+ onFramingLost() {
267
+ this.blind = true;
268
+ this.queues = [];
269
+ this.partialBox = null;
270
+ this.skipRemaining = 0;
271
+ this.headerFill = 0;
272
+ }
273
+ /**
274
+ * Account for one complete top-level box of the muxer output.
275
+ *
276
+ * Only `moof` (fragment samples) and `moov` (samples of a first fragment
277
+ * written without `empty_moov`) matter; other boxes are ignored.
278
+ *
279
+ * @param box - The whole box including its header
280
+ *
281
+ * @internal
282
+ */
283
+ consumeBox(box) {
284
+ if (box.length < 8) {
285
+ return;
286
+ }
287
+ const type = box.readUInt32BE(4);
288
+ if (type !== BOX.moof && type !== BOX.moov) {
289
+ return;
290
+ }
291
+ const headerSize = box.readUInt32BE(0) === 1 ? 16 : 8;
292
+ if (type === BOX.moof) {
293
+ this.drainFragment(box, headerSize, box.length);
294
+ }
295
+ else {
296
+ this.drainInitSegment(box, headerSize, box.length);
297
+ }
298
+ }
299
+ /**
300
+ * Account for a raw chunk of the muxer output.
301
+ *
302
+ * Frames top-level boxes across chunk boundaries without buffering media
303
+ * data: only `moof`/`moov` boxes are collected, everything else is skipped.
304
+ * If the framing breaks (a size the muxer never writes), the watchdog stops
305
+ * judging ages for the rest of the session instead of guessing.
306
+ *
307
+ * @param chunk - Output chunk in stream order
308
+ *
309
+ * @internal
310
+ */
311
+ consumeChunk(chunk) {
312
+ let offset = 0;
313
+ while (offset < chunk.length && !this.blind) {
314
+ if (this.skipRemaining > 0) {
315
+ const n = Math.min(this.skipRemaining, chunk.length - offset);
316
+ this.skipRemaining -= n;
317
+ offset += n;
318
+ continue;
319
+ }
320
+ if (this.partialBox) {
321
+ const n = Math.min(this.partialBox.length - this.partialFill, chunk.length - offset);
322
+ chunk.copy(this.partialBox, this.partialFill, offset, offset + n);
323
+ this.partialFill += n;
324
+ offset += n;
325
+ if (this.partialFill === this.partialBox.length) {
326
+ const box = this.partialBox;
327
+ this.partialBox = null;
328
+ this.consumeBox(box);
329
+ }
330
+ continue;
331
+ }
332
+ // The header itself may straddle chunks: 8 bytes, 16 for a 64-bit size.
333
+ let need = this.headerFill < 8 ? 8 : this.header.readUInt32BE(0) === 1 ? 16 : 8;
334
+ if (this.headerFill < need) {
335
+ const n = Math.min(need - this.headerFill, chunk.length - offset);
336
+ chunk.copy(this.header, this.headerFill, offset, offset + n);
337
+ this.headerFill += n;
338
+ offset += n;
339
+ if (this.headerFill < need) {
340
+ continue;
341
+ }
342
+ need = this.header.readUInt32BE(0) === 1 ? 16 : 8;
343
+ if (this.headerFill < need) {
344
+ continue;
345
+ }
346
+ }
347
+ const size32 = this.header.readUInt32BE(0);
348
+ const size = size32 === 1 ? Number(this.header.readBigUInt64BE(8)) : size32;
349
+ const type = this.header.readUInt32BE(4);
350
+ this.headerFill = 0;
351
+ // size 0 ("to the end of the file") cannot be framed in a live stream;
352
+ // movenc writes it only when it could not seek back to patch a box.
353
+ if (size < need) {
354
+ this.onFramingLost();
355
+ return;
356
+ }
357
+ if (type === BOX.moof || type === BOX.moov) {
358
+ if (size > MAX_COLLECTED_BOX) {
359
+ this.onFramingLost();
360
+ return;
361
+ }
362
+ this.partialBox = Buffer.allocUnsafe(size);
363
+ this.header.copy(this.partialBox, 0, 0, need);
364
+ this.partialFill = need;
365
+ if (this.partialFill === size) {
366
+ const box = this.partialBox;
367
+ this.partialBox = null;
368
+ this.consumeBox(box);
369
+ }
370
+ }
371
+ else {
372
+ this.skipRemaining = size - need;
373
+ }
374
+ }
375
+ }
376
+ /**
377
+ * Drain the samples of every track fragment in a moof.
378
+ *
379
+ * @param buf - Buffer holding the moof
380
+ *
381
+ * @param start - Offset of the moof payload
382
+ *
383
+ * @param end - End offset of the moof
384
+ *
385
+ * @internal
386
+ */
387
+ drainFragment(buf, start, end) {
388
+ for (let offset = start; offset + 8 <= end;) {
389
+ const size = childSize(buf, offset, end);
390
+ if (size === 0) {
391
+ return;
392
+ }
393
+ if (buf.readUInt32BE(offset + 4) === BOX.traf) {
394
+ this.drainTrackFragment(buf, offset + headerSizeAt(buf, offset), offset + size);
395
+ }
396
+ offset += size;
397
+ }
398
+ }
399
+ /**
400
+ * Drain the samples of one traf: its tfhd names the track, each trun counts samples.
401
+ *
402
+ * movenc writes several truns per traf when the sample data is not contiguous.
403
+ *
404
+ * @param buf - Buffer holding the traf
405
+ *
406
+ * @param start - Offset of the traf payload
407
+ *
408
+ * @param end - End offset of the traf
409
+ *
410
+ * @internal
411
+ */
412
+ drainTrackFragment(buf, start, end) {
413
+ let trackId = 0;
414
+ let samples = 0;
415
+ for (let offset = start; offset + 8 <= end;) {
416
+ const size = childSize(buf, offset, end);
417
+ if (size === 0) {
418
+ break;
419
+ }
420
+ const type = buf.readUInt32BE(offset + 4);
421
+ const payload = offset + headerSizeAt(buf, offset);
422
+ // Both start with version/flags (4 bytes), then track_ID resp. sample_count.
423
+ if ((type === BOX.tfhd || type === BOX.trun) && payload + 8 <= offset + size) {
424
+ if (type === BOX.tfhd) {
425
+ trackId = buf.readUInt32BE(payload + 4);
426
+ }
427
+ else {
428
+ samples += buf.readUInt32BE(payload + 4);
429
+ }
430
+ }
431
+ offset += size;
432
+ }
433
+ this.drain(trackId, samples);
434
+ }
435
+ /**
436
+ * Drain samples a moov carries in its sample tables.
437
+ *
438
+ * With `empty_moov` the tables are empty. Without it movenc writes the first
439
+ * fragment's samples into the moov instead of a moof.
440
+ *
441
+ * @param buf - Buffer holding the moov
442
+ *
443
+ * @param start - Offset of the moov payload
444
+ *
445
+ * @param end - End offset of the moov
446
+ *
447
+ * @internal
448
+ */
449
+ drainInitSegment(buf, start, end) {
450
+ for (let offset = start; offset + 8 <= end;) {
451
+ const size = childSize(buf, offset, end);
452
+ if (size === 0) {
453
+ return;
454
+ }
455
+ if (buf.readUInt32BE(offset + 4) === BOX.trak) {
456
+ const trakEnd = offset + size;
457
+ let trackId = 0;
458
+ let samples = 0;
459
+ for (let child = offset + headerSizeAt(buf, offset); child + 8 <= trakEnd;) {
460
+ const childBoxSize = childSize(buf, child, trakEnd);
461
+ if (childBoxSize === 0) {
462
+ break;
463
+ }
464
+ const type = buf.readUInt32BE(child + 4);
465
+ const payload = child + headerSizeAt(buf, child);
466
+ if (type === BOX.tkhd && payload + 24 <= child + childBoxSize) {
467
+ // track_ID follows creation/modification time: 32-bit in version 0, 64-bit in version 1
468
+ trackId = buf.readUInt32BE(payload + (buf[payload] === 1 ? 20 : 12));
469
+ }
470
+ else if (type === BOX.mdia) {
471
+ samples = sampleTableCount(buf, payload, child + childBoxSize);
472
+ }
473
+ child += childBoxSize;
474
+ }
475
+ this.drain(trackId, samples);
476
+ }
477
+ offset += size;
478
+ }
479
+ }
480
+ /**
481
+ * Remove emitted samples from the queue of the stream behind a track.
482
+ *
483
+ * movenc numbers the tracks of the muxer's streams stream index + 1; tracks
484
+ * it adds itself (chapters, timecode) have no queue and are ignored.
485
+ *
486
+ * @param trackId - mp4 track_ID
487
+ *
488
+ * @param samples - Number of emitted samples
489
+ *
490
+ * @internal
491
+ */
492
+ drain(trackId, samples) {
493
+ if (trackId > 0 && samples > 0) {
494
+ this.queues[trackId - 1]?.dropOldest(samples);
495
+ }
496
+ }
497
+ /**
498
+ * Build the error for a stream whose oldest pending packet is too old.
499
+ *
500
+ * @param streamIndex - Output stream index
501
+ *
502
+ * @param ageMs - Age of its oldest pending packet in ms
503
+ *
504
+ * @param pending - Number of its pending packets
505
+ *
506
+ * @returns Error describing the stalled stream
507
+ *
508
+ * @internal
509
+ */
510
+ violation(streamIndex, ageMs, pending) {
511
+ const type = this.describeStream(streamIndex);
512
+ const label = type ? ` (${type})` : '';
513
+ const what = `the oldest of ${pending} pending packets has waited ${(ageMs / 1000).toFixed(1)}s without being emitted in a fragment`;
514
+ return new Error(`Muxer stall on output stream ${streamIndex}${label}: ${what}, more than maxPacketAge (${this.limitSeconds}s)`);
515
+ }
516
+ }
517
+ /**
518
+ * Header size of the box at an offset: 16 for a 64-bit size, else 8.
519
+ *
520
+ * @param buf - Buffer holding the box
521
+ *
522
+ * @param offset - Box start
523
+ *
524
+ * @returns Header size in bytes
525
+ *
526
+ * @internal
527
+ */
528
+ function headerSizeAt(buf, offset) {
529
+ return buf.readUInt32BE(offset) === 1 ? 16 : 8;
530
+ }
531
+ /**
532
+ * Size of a child box that must end within its parent.
533
+ *
534
+ * @param buf - Buffer holding the box
535
+ *
536
+ * @param offset - Box start (at least 8 bytes before end)
537
+ *
538
+ * @param end - End offset of the parent
539
+ *
540
+ * @returns Box size, or 0 when the box is malformed or overruns the parent
541
+ *
542
+ * @internal
543
+ */
544
+ function childSize(buf, offset, end) {
545
+ let size = buf.readUInt32BE(offset);
546
+ let header = 8;
547
+ if (size === 1) {
548
+ if (offset + 16 > end) {
549
+ return 0;
550
+ }
551
+ size = Number(buf.readBigUInt64BE(offset + 8));
552
+ header = 16;
553
+ }
554
+ return size >= header && offset + size <= end ? size : 0;
555
+ }
556
+ /**
557
+ * Sample count of a track's sample table (mdia > minf > stbl > stsz/stz2).
558
+ *
559
+ * @param buf - Buffer holding the mdia
560
+ *
561
+ * @param start - Offset of the mdia payload
562
+ *
563
+ * @param end - End offset of the mdia
564
+ *
565
+ * @returns Number of samples, 0 if absent
566
+ *
567
+ * @internal
568
+ */
569
+ function sampleTableCount(buf, start, end) {
570
+ const path = [BOX.minf, BOX.stbl];
571
+ let level = 0;
572
+ for (let offset = start; offset + 8 <= end;) {
573
+ const size = childSize(buf, offset, end);
574
+ if (size === 0) {
575
+ return 0;
576
+ }
577
+ const type = buf.readUInt32BE(offset + 4);
578
+ const payload = offset + headerSizeAt(buf, offset);
579
+ if (level < path.length && type === path[level]) {
580
+ // Descend: continue with the children of this box.
581
+ level++;
582
+ end = offset + size;
583
+ offset = payload;
584
+ continue;
585
+ }
586
+ // stsz and stz2 both keep sample_count after version/flags and one 32-bit field.
587
+ if (level === path.length && (type === BOX.stsz || type === BOX.stz2) && payload + 12 <= offset + size) {
588
+ return buf.readUInt32BE(payload + 8);
589
+ }
590
+ offset += size;
591
+ }
592
+ return 0;
593
+ }
594
+ //# sourceMappingURL=packet-age-watchdog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packet-age-watchdog.js","sourceRoot":"","sources":["../../../src/api/utilities/packet-age-watchdog.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,GAAG,GAAG;IACV,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;I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**
2
+ * Resolve a scale target where -1 keeps the source aspect ratio.
3
+ *
4
+ * Like the scale filter's -2: the derived side is rounded to an even number so
5
+ * 4:2:0 encoders accept it. Both sides -1 keeps the source size.
6
+ *
7
+ * @param srcWidth - Source width
8
+ *
9
+ * @param srcHeight - Source height
10
+ *
11
+ * @param width - Target width, or -1 to derive it from the height
12
+ *
13
+ * @param height - Target height, or -1 to derive it from the width
14
+ *
15
+ * @returns The target size
16
+ *
17
+ * @internal
18
+ */
19
+ export declare function resolveScaleSize(srcWidth: number, srcHeight: number, width: number, height: number): {
20
+ width: number;
21
+ height: number;
22
+ };
23
+ /**
24
+ * Scale target and output size of a transcode, never larger than the source.
25
+ *
26
+ * A requested width or height above the source keeps the source size, since a
27
+ * bigger picture only raises the bitrate.
28
+ *
29
+ * @param srcWidth - Source width, 0 when unknown before the first frame
30
+ *
31
+ * @param srcHeight - Source height, 0 when unknown before the first frame
32
+ *
33
+ * @param width - Requested width, or -1 to derive it from the height
34
+ *
35
+ * @param height - Requested height, or -1 to derive it from the width
36
+ *
37
+ * @returns The target for the scale filter (-1 follows the source) and the
38
+ * resolved output size, undefined while the source size is unknown
39
+ *
40
+ * @internal
41
+ */
42
+ export declare function transcodeScale(srcWidth: number, srcHeight: number, width?: number, height?: number): {
43
+ target: {
44
+ width: number;
45
+ height: number;
46
+ };
47
+ output?: {
48
+ width: number;
49
+ height: number;
50
+ };
51
+ };