@camstack/addon-post-analysis 1.2.51 → 1.2.53

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.
@@ -1,649 +0,0 @@
1
- import { G as buildFfmpegArgs, K as isSoftwareDecode, U as errMsg, W as Fmp4BoxSplitter } from "./dist-DTeVOZBt.mjs";
2
- import * as fs from "node:fs";
3
- import * as path$1 from "node:path";
4
- import { randomUUID } from "node:crypto";
5
- import "node:child_process";
6
- var STORAGE_LOCATION_TYPES = [
7
- "data",
8
- "media",
9
- "recordings",
10
- "recordings-high",
11
- "recordings-low",
12
- "recordings-clips",
13
- "event-images",
14
- "models",
15
- "addons-data",
16
- "cache",
17
- "logs",
18
- "backups"
19
- ];
20
- var DEFAULT_LOCATION_SUBDIRS = {
21
- data: "db",
22
- media: "media",
23
- recordings: "recordings",
24
- "recordings-high": "recordings-high",
25
- "recordings-low": "recordings-low",
26
- "recordings-clips": "recordings-clips",
27
- "event-images": "event-images",
28
- models: "models",
29
- "addons-data": "addons-data",
30
- cache: "/tmp/camstack-cache",
31
- logs: "logs",
32
- backups: "backups"
33
- };
34
- /**
35
- * Filesystem storage provider — serves all location types from a local directory tree.
36
- *
37
- * Default layout:
38
- * {rootPath}/recordings-high/
39
- * {rootPath}/recordings-low/
40
- * {rootPath}/recordings-clips/
41
- * {rootPath}/event-images/
42
- * {rootPath}/models/
43
- * {rootPath}/addons-data/
44
- * {rootPath}/logs/
45
- * /tmp/camstack-cache/ (cache is always local)
46
- *
47
- * Individual location paths can be overridden.
48
- */
49
- var FilesystemStorageProvider = class {
50
- id = "local";
51
- name = "Local Filesystem";
52
- supportedLocations = [...STORAGE_LOCATION_TYPES];
53
- rootPath;
54
- locationPaths;
55
- constructor(rootPath, overrides) {
56
- this.rootPath = path$1.resolve(rootPath);
57
- this.locationPaths = /* @__PURE__ */ new Map();
58
- for (const loc of STORAGE_LOCATION_TYPES) {
59
- const override = overrides?.[loc];
60
- if (override) this.locationPaths.set(loc, path$1.resolve(override));
61
- else {
62
- const subdir = DEFAULT_LOCATION_SUBDIRS[loc] ?? loc;
63
- this.locationPaths.set(loc, path$1.isAbsolute(subdir) ? subdir : path$1.join(this.rootPath, subdir));
64
- }
65
- }
66
- for (const [loc, override] of Object.entries(overrides ?? {})) if (typeof override === "string" && !this.locationPaths.has(loc)) this.locationPaths.set(loc, path$1.resolve(override));
67
- }
68
- async resolve({ location, relativePath }) {
69
- const base = this.locationPaths.get(location) ?? path$1.join(this.rootPath, location);
70
- return path$1.join(base, relativePath);
71
- }
72
- async write({ location, relativePath, data }) {
73
- const filePath = await this.resolve({
74
- location,
75
- relativePath
76
- });
77
- await fs.promises.mkdir(path$1.dirname(filePath), { recursive: true });
78
- if (Buffer.isBuffer(data)) await fs.promises.writeFile(filePath, data);
79
- else {
80
- const writeStream = fs.createWriteStream(filePath);
81
- await new Promise((resolve, reject) => {
82
- data.pipe(writeStream);
83
- writeStream.on("finish", resolve);
84
- writeStream.on("error", reject);
85
- });
86
- }
87
- }
88
- async read({ location, relativePath }) {
89
- return fs.promises.readFile(await this.resolve({
90
- location,
91
- relativePath
92
- }));
93
- }
94
- async exists({ location, relativePath }) {
95
- try {
96
- await fs.promises.access(await this.resolve({
97
- location,
98
- relativePath
99
- }));
100
- return true;
101
- } catch {
102
- return false;
103
- }
104
- }
105
- async list({ location, prefix }) {
106
- const base = this.locationPaths.get(location);
107
- if (!base) return [];
108
- const dir = prefix ? path$1.join(base, prefix) : base;
109
- try {
110
- return (await fs.promises.readdir(dir, { withFileTypes: true })).map((e) => prefix ? `${prefix}/${e.name}` : e.name);
111
- } catch {
112
- return [];
113
- }
114
- }
115
- async delete({ location, relativePath }) {
116
- const filePath = await this.resolve({
117
- location,
118
- relativePath
119
- });
120
- await fs.promises.rm(filePath, { force: true });
121
- }
122
- async getAvailableSpace({ location }) {
123
- const base = this.locationPaths.get(location);
124
- if (!base) return null;
125
- try {
126
- let target = base;
127
- while (!fs.existsSync(target)) {
128
- const parent = path$1.dirname(target);
129
- if (!parent || parent === target) return null;
130
- target = parent;
131
- }
132
- const stats = await fs.promises.statfs(target);
133
- return stats.bavail * stats.bsize;
134
- } catch {
135
- return null;
136
- }
137
- }
138
- /** Get the resolved path for a location type (addon-declared ids fall back
139
- * to `<rootPath>/<id>`). */
140
- getLocationPath(location) {
141
- return this.locationPaths.get(location) ?? path$1.join(this.rootPath, location);
142
- }
143
- /** Get the root path */
144
- getRootPath() {
145
- return this.rootPath;
146
- }
147
- };
148
- /**
149
- * Fmp4FragmentPlane — a SUBSCRIBABLE fragmented-MP4 plane, fed by one
150
- * {@link import('./fmp4-box-splitter.js').Fmp4BoxSplitter}.
151
- *
152
- * ## Why a plane and not a callback
153
- *
154
- * The operator's requirement for HKSV was explicit: the live fMP4 source built
155
- * for it must be **dual-use**, so a HomeKit-triggered recording also lands in
156
- * CamStack as an additional videoclip source alongside the recorder and the NC
157
- * clip ring — *one fragmenter, two consumers; do not build an HKSV-only pipe*
158
- * (`docs/roadmap.md` item 4b). A single-callback pipe makes the second consumer
159
- * a second ffmpeg child of the same camera. So this is the same shape the
160
- * broker's other multi-consumer surfaces already have
161
- * (`AudioChunkPlane`, the push packet plane): N independent subscriptions over
162
- * one producer.
163
- *
164
- * **Nothing consumes it yet.** Phase 4 brings the HKSV delegate and phase 4b the
165
- * clip source; both are named here so the seam is not re-invented, and neither
166
- * is built.
167
- *
168
- * ## The init segment is RETAINED
169
- *
170
- * A subscriber that attaches mid-stream — the clip consumer joining an already
171
- * running HKSV session, which is the whole dual-use case — receives the
172
- * retained `ftyp`+`moov` as its first packet and then live fragments. Without
173
- * retention its fragments are undecodable and the failure looks like a codec
174
- * problem.
175
- *
176
- * ## A slow subscriber is CLOSED, never silently gapped
177
- *
178
- * `AudioChunkPlane` drops its oldest chunk on overflow, which for audio costs a
179
- * click. An fMP4 stream with a hole is not a shorter clip, it is a corrupt one:
180
- * `moof` sequence numbers jump, the consumer's demuxer desynchronises, and HKSV
181
- * shows a clip that fails to play with nothing anywhere saying why. So a
182
- * subscription whose queue overflows is ENDED with a reason, loudly, and the
183
- * other subscriptions are untouched.
184
- *
185
- * ## The PREBUFFER (phase 3)
186
- *
187
- * HKSV asks for context BEFORE the trigger — `CameraRecordingOptions.prebufferLength`
188
- * is a HAP-mandated minimum of 4000 ms — and a subscriber that attaches at the
189
- * motion edge has none. So the plane optionally retains the last few fragments
190
- * and replays them to a subscriber that asks for them.
191
- *
192
- * Three things this ring gets right, each of which is a measured fact rather
193
- * than a preference (see [D84](../../../../docs/decisions/adr-0084.md)):
194
- *
195
- * - **It is bounded by TIME *and* BYTES.** On the live fleet a 720p copy
196
- * fragment is ~255 KB and a 4K one is ~6.35 MB — a 25× spread over the same
197
- * window. A time-only bound is a per-camera RAM figure nobody can predict.
198
- * - **The window is measured on ARRIVAL, not parsed from `tfdt`.** The
199
- * splitter deliberately never computes a fragment's duration (a second
200
- * opinion about a fact the muxer owns), and a prebuffer cares about how long
201
- * ago the bytes turned up, which is exactly what arrival time answers.
202
- * - **A replay is not backlog.** A subscriber taking N retained fragments gets
203
- * its queue capacity raised by N for them, because closing a subscriber as a
204
- * slow consumer for the prebuffer it explicitly asked for would be the
205
- * stupidest possible failure — and, with `DEFAULT_QUEUE_CAPACITY` of 4 and a
206
- * ring of 4, the guaranteed one.
207
- *
208
- * ## `isLast`
209
- *
210
- * hap-nodejs requires the delegate to mark exactly one `RecordingPacket` with
211
- * `isLast` — a generator that finishes without it produces the twelve-second
212
- * timeout loop [D50](../../../../../docs/decisions/adr-0050.md) deleted. The
213
- * plane therefore computes it at DELIVERY time: a packet is last when the plane
214
- * has ended and nothing remains queued behind it. A subscription that ends
215
- * having delivered NOTHING says so through {@link Fmp4Subscription.delivered};
216
- * the future delegate must not open an HDS stream it cannot feed.
217
- */
218
- var DEFAULT_QUEUE_CAPACITY = 4;
219
- var Fmp4FragmentPlane = class {
220
- logger;
221
- prebuffer;
222
- now;
223
- subscriptions = /* @__PURE__ */ new Map();
224
- /** The last init unit seen, handed to every later subscriber. */
225
- retainedInit = null;
226
- ended = false;
227
- /** Oldest first. Empty unless {@link Fmp4PrebufferOptions} was supplied. */
228
- ring = [];
229
- ringBytes = 0;
230
- constructor(logger, prebuffer, now = Date.now) {
231
- this.logger = logger;
232
- this.prebuffer = prebuffer;
233
- this.now = now;
234
- }
235
- get subscriberCount() {
236
- return this.subscriptions.size;
237
- }
238
- /** True once {@link end} has been called — no further units are accepted. */
239
- get isEnded() {
240
- return this.ended;
241
- }
242
- /** What the prebuffer ring holds right now. All zeroes when disabled. */
243
- prebufferStats() {
244
- const oldest = this.ring[0];
245
- return {
246
- fragments: this.ring.length,
247
- bytes: this.ringBytes,
248
- spanMs: oldest === void 0 ? 0 : this.now() - oldest.arrivedAt
249
- };
250
- }
251
- subscribe(input) {
252
- const replay = input.withPrebuffer === true ? this.trimmedRing() : [];
253
- const requested = Math.max(1, input.queueCapacity ?? DEFAULT_QUEUE_CAPACITY);
254
- const sub = {
255
- id: `fmp4-${randomUUID()}`,
256
- tag: input.tag,
257
- subscribedAt: this.now(),
258
- capacity: requested + replay.length,
259
- queue: [],
260
- delivered: 0,
261
- closedReason: null,
262
- wake: null,
263
- iterating: false
264
- };
265
- this.subscriptions.set(sub.id, sub);
266
- if (this.retainedInit !== null) this.enqueue(sub, this.retainedInit);
267
- for (const retained of replay) this.enqueue(sub, retained.unit);
268
- if (this.ended) this.closeSubscription(sub, "ended");
269
- this.logger?.info("fmp4 plane: subscribed", { meta: {
270
- subscriptionId: sub.id,
271
- tag: sub.tag,
272
- hasRetainedInit: this.retainedInit !== null,
273
- prebufferFragments: replay.length,
274
- prebufferBytes: replay.reduce((n, r) => n + r.unit.data.length, 0)
275
- } });
276
- return this.facade(sub);
277
- }
278
- /**
279
- * Fan one splitter unit out. An `init` REPLACES the retained one — ffmpeg
280
- * emits exactly one per child, and a second means the child was respawned, in
281
- * which case the old one describes a stream that no longer exists.
282
- */
283
- publish(unit) {
284
- if (this.ended) return;
285
- if (unit.kind === "init") {
286
- this.retainedInit = unit;
287
- this.ring.length = 0;
288
- this.ringBytes = 0;
289
- } else this.retain(unit);
290
- for (const sub of this.subscriptions.values()) {
291
- if (sub.closedReason !== null) continue;
292
- this.enqueue(sub, unit);
293
- }
294
- }
295
- /**
296
- * The producer stopped. Every subscriber drains what it holds; its final
297
- * packet carries `isLast`, and its generator then completes.
298
- */
299
- end(reason = "producer ended") {
300
- if (this.ended) return;
301
- this.ended = true;
302
- this.logger?.info("fmp4 plane: ended", { meta: {
303
- reason,
304
- subscribers: this.subscriptions.size
305
- } });
306
- for (const sub of this.subscriptions.values()) if (sub.closedReason === null) this.closeSubscription(sub, "ended");
307
- }
308
- listSubscribers() {
309
- return [...this.subscriptions.values()].map((s) => ({
310
- tag: s.tag,
311
- subscribedAt: s.subscribedAt,
312
- delivered: s.delivered,
313
- closedReason: s.closedReason
314
- }));
315
- }
316
- /** End and forget everything. Idempotent. */
317
- dispose() {
318
- this.end("disposed");
319
- this.subscriptions.clear();
320
- this.retainedInit = null;
321
- this.ring.length = 0;
322
- this.ringBytes = 0;
323
- }
324
- /**
325
- * Add one fragment to the ring and evict from the front until BOTH bounds
326
- * hold. Eviction is oldest-first, which is the one place in this file where
327
- * dropping is correct: the ring is context, not stream — nobody is mid-decode
328
- * on it, and a subscriber only ever receives a contiguous tail of it.
329
- */
330
- retain(unit) {
331
- const prebuffer = this.prebuffer;
332
- if (prebuffer === void 0) return;
333
- const arrivedAt = this.now();
334
- this.ring.push({
335
- unit,
336
- arrivedAt
337
- });
338
- this.ringBytes += unit.data.length;
339
- const cutoff = arrivedAt - prebuffer.windowMs;
340
- while (this.ring.length > 0) {
341
- const oldest = this.ring[0];
342
- if (oldest === void 0) break;
343
- const tooOld = oldest.arrivedAt < cutoff;
344
- const tooBig = this.ringBytes > prebuffer.maxBytes;
345
- if (!tooOld && !tooBig || this.ring.length === 1) break;
346
- this.ring.shift();
347
- this.ringBytes -= oldest.unit.data.length;
348
- }
349
- }
350
- /**
351
- * The ring as a subscriber should receive it — window applied AT SUBSCRIBE
352
- * time, not only at publish time. A camera that went quiet keeps its last
353
- * fragment in the ring indefinitely (see the never-evict-the-newest rule),
354
- * and replaying a 40-second-old fragment as "prebuffer" would put stale video
355
- * at the head of a clip iOS presents as the moment of the event.
356
- */
357
- trimmedRing() {
358
- const prebuffer = this.prebuffer;
359
- if (prebuffer === void 0) return [];
360
- const cutoff = this.now() - prebuffer.windowMs;
361
- return this.ring.filter((r) => r.arrivedAt >= cutoff);
362
- }
363
- enqueue(sub, unit) {
364
- if (sub.queue.length >= sub.capacity) {
365
- this.logger?.warn("fmp4 plane: subscriber fell behind — CLOSING it rather than gapping it", { meta: {
366
- subscriptionId: sub.id,
367
- tag: sub.tag,
368
- capacity: sub.capacity,
369
- delivered: sub.delivered
370
- } });
371
- this.closeSubscription(sub, "slow-consumer");
372
- return;
373
- }
374
- sub.queue.push({
375
- kind: unit.kind,
376
- data: unit.data,
377
- sequence: unit.sequence,
378
- isLast: false
379
- });
380
- this.wake(sub);
381
- }
382
- closeSubscription(sub, reason) {
383
- if (sub.closedReason !== null) return;
384
- sub.closedReason = reason;
385
- if (reason === "slow-consumer") sub.queue.length = 0;
386
- this.wake(sub);
387
- }
388
- wake(sub) {
389
- const resume = sub.wake;
390
- sub.wake = null;
391
- resume?.();
392
- }
393
- facade(sub) {
394
- const plane = this;
395
- return {
396
- id: sub.id,
397
- tag: sub.tag,
398
- get delivered() {
399
- return sub.delivered;
400
- },
401
- get closedReason() {
402
- return sub.closedReason;
403
- },
404
- packets: () => plane.iterate(sub),
405
- release: () => {
406
- plane.closeSubscription(sub, "released");
407
- plane.subscriptions.delete(sub.id);
408
- }
409
- };
410
- }
411
- async *iterate(sub) {
412
- if (sub.iterating) throw new Error(`fmp4 plane: subscription ${sub.tag} is already being consumed — take a second subscription`);
413
- sub.iterating = true;
414
- for (;;) {
415
- const next = sub.queue.shift();
416
- if (next === void 0) {
417
- if (sub.closedReason !== null) return;
418
- await new Promise((resolve) => {
419
- sub.wake = resolve;
420
- });
421
- continue;
422
- }
423
- const isLast = sub.closedReason === "ended" && sub.queue.length === 0;
424
- sub.delivered += 1;
425
- yield {
426
- ...next,
427
- isLast
428
- };
429
- if (isLast) return;
430
- }
431
- }
432
- };
433
- var DEFAULT_FIRST_UNIT_TIMEOUT_MS = 12e3;
434
- /** Heartbeat cadence — ~2 minutes of 4 s fragments. */
435
- var FRAGMENT_LOG_EVERY = 30;
436
- var Fmp4FragmentChild = class {
437
- deps;
438
- args;
439
- child = null;
440
- splitter = new Fmp4BoxSplitter();
441
- stopped = false;
442
- unitsOut = 0;
443
- activeHwAccel = null;
444
- constructor(deps, args) {
445
- this.deps = deps;
446
- this.args = args;
447
- }
448
- /** Spawn, and resolve once the INIT segment has been cut out of stdout. */
449
- async start() {
450
- const requested = this.args.invocation.decodeHwAccel;
451
- this.activeHwAccel = requested;
452
- try {
453
- await this.spawnAttempt(requested);
454
- return;
455
- } catch (err) {
456
- if (this.stopped) throw err;
457
- if (requested === null || isSoftwareDecode(requested)) throw err;
458
- this.deps.logger.warn("fmp4 fragment child: hardware decode produced NO fragment — retrying in SOFTWARE", {
459
- tags: { deviceId: this.args.deviceId },
460
- meta: {
461
- sourceId: this.args.sourceId,
462
- decodeHwAccel: requested,
463
- error: errMsg(err)
464
- }
465
- });
466
- this.killChild();
467
- this.splitter = new Fmp4BoxSplitter();
468
- this.activeHwAccel = null;
469
- await this.spawnAttempt(null);
470
- }
471
- }
472
- /** The backend the child ACTUALLY ran with — `null` for software. */
473
- activeDecodeHwAccel() {
474
- const value = this.activeHwAccel;
475
- return value === null || value === "none" || value === "copy" ? null : value;
476
- }
477
- /** Kill ffmpeg and end the plane. Idempotent. */
478
- async stop() {
479
- if (this.stopped) return;
480
- this.stopped = true;
481
- this.killChild();
482
- this.args.plane.end("the fragment child stopped");
483
- }
484
- spawnAttempt(decodeHwAccel) {
485
- const args = buildFfmpegArgs({
486
- ...this.args.invocation,
487
- decodeHwAccel,
488
- sink: {
489
- kind: "stdout",
490
- container: "mp4",
491
- fragmentMs: this.args.fragmentMs
492
- }
493
- });
494
- this.deps.logger.info("fmp4 fragment child: spawning ffmpeg", {
495
- tags: { deviceId: this.args.deviceId },
496
- meta: {
497
- sourceId: this.args.sourceId,
498
- fragmentMs: this.args.fragmentMs,
499
- decodeHwAccel: decodeHwAccel ?? "software",
500
- argv: args.join(" ")
501
- }
502
- });
503
- return new Promise((resolve, reject) => {
504
- const child = this.deps.spawnFn(this.deps.ffmpegBinaryPath, args, { stdio: [
505
- "ignore",
506
- "pipe",
507
- "pipe"
508
- ] });
509
- this.child = child;
510
- let settled = false;
511
- /**
512
- * This attempt FAILED. Set before the kill, because SIGTERM makes the
513
- * child exit and that exit must not be reported as a death: the retry —
514
- * or the caller's rejection — already owns what happens next. Without it
515
- * the timeout path ends the plane the software retry is about to fill,
516
- * and the consumer sees a stream that stopped for no reason. A "which
517
- * spawn is current" counter does NOT cover this: the retry has not been
518
- * spawned when the kill's exit arrives.
519
- */
520
- let failed = false;
521
- /**
522
- * This attempt is still the live producer: it has not failed (a failure
523
- * hands ownership to the retry, or to the caller's rejection) and nothing
524
- * has stopped the child. Those two cover every way an attempt stops being
525
- * current — `start` only respawns after a rejection.
526
- */
527
- const isCurrent = () => !this.stopped && !failed;
528
- const timeoutMs = this.deps.firstUnitTimeoutMs ?? DEFAULT_FIRST_UNIT_TIMEOUT_MS;
529
- const settle = (fail) => {
530
- if (settled) return;
531
- settled = true;
532
- clearTimeout(timer);
533
- if (fail) {
534
- failed = true;
535
- reject(fail);
536
- } else resolve();
537
- };
538
- const timer = setTimeout(() => {
539
- settle(/* @__PURE__ */ new Error(`fmp4 fragment child: no fragment within ${timeoutMs}ms`));
540
- this.killChild();
541
- }, timeoutMs);
542
- timer.unref?.();
543
- child.stdout?.on("data", (chunk) => {
544
- for (const unit of this.splitter.push(chunk)) {
545
- this.unitsOut += 1;
546
- this.args.plane.publish(unit);
547
- if (unit.kind === "init") {
548
- this.deps.logger.info("fmp4 fragment child: INIT segment cut", {
549
- tags: { deviceId: this.args.deviceId },
550
- meta: {
551
- sourceId: this.args.sourceId,
552
- bytes: unit.data.length
553
- }
554
- });
555
- settle();
556
- } else if (this.unitsOut % FRAGMENT_LOG_EVERY === 0) this.deps.logger.info("fmp4 fragment child: fragments still flowing", {
557
- tags: { deviceId: this.args.deviceId },
558
- meta: {
559
- sourceId: this.args.sourceId,
560
- unitsOut: this.unitsOut,
561
- bytes: unit.data.length,
562
- subscribers: this.args.plane.subscriberCount
563
- }
564
- });
565
- }
566
- const fault = this.splitter.fault;
567
- if (fault !== null) this.onFault(fault, settled, isCurrent(), settle);
568
- });
569
- child.stderr?.setEncoding("utf8");
570
- child.stderr?.on("data", (line) => {
571
- this.deps.logger.debug("fmp4 fragment child ffmpeg", {
572
- tags: { deviceId: this.args.deviceId },
573
- meta: {
574
- sourceId: this.args.sourceId,
575
- line: line.trim()
576
- }
577
- });
578
- });
579
- child.once("error", (err) => {
580
- if (!settled) {
581
- settle(err);
582
- return;
583
- }
584
- if (!isCurrent()) return;
585
- this.args.plane.end("the fragment child errored");
586
- this.deps.onChildExit?.(err);
587
- });
588
- child.once("exit", (code, signal) => {
589
- if (!settled) {
590
- settle(/* @__PURE__ */ new Error(`fmp4 fragment child: ffmpeg exited before any fragment (code=${code} signal=${signal})`));
591
- return;
592
- }
593
- if (!isCurrent()) return;
594
- const error = /* @__PURE__ */ new Error(`fmp4 fragment child: ffmpeg exited while live (code=${code} signal=${signal})`);
595
- this.deps.logger.warn("fmp4 fragment child: ffmpeg exited while live", {
596
- tags: { deviceId: this.args.deviceId },
597
- meta: {
598
- sourceId: this.args.sourceId,
599
- code,
600
- signal,
601
- unitsOut: this.unitsOut
602
- }
603
- });
604
- this.args.plane.end("the fragment child exited");
605
- this.deps.onChildExit?.(error);
606
- });
607
- });
608
- }
609
- /**
610
- * The byte stream stopped being splittable. Not recoverable — the splitter
611
- * cannot resynchronise mid-box — so the child is a corpse and every consumer
612
- * has to be told, loudly, with the reason.
613
- */
614
- onFault(reason, wasLive, current, settle) {
615
- const error = /* @__PURE__ */ new Error(`fmp4 fragment child: ${reason}`);
616
- this.deps.logger.error("fmp4 fragment child: the ffmpeg output stopped parsing as fMP4", {
617
- tags: { deviceId: this.args.deviceId },
618
- meta: {
619
- sourceId: this.args.sourceId,
620
- unitsOut: this.unitsOut,
621
- interstitial: this.splitter.discardedInterstitialTypes,
622
- reason
623
- }
624
- });
625
- this.killChild();
626
- settle(error);
627
- if (wasLive && current) {
628
- this.args.plane.end("the fragment child produced unsplittable output");
629
- this.deps.onChildExit?.(error);
630
- }
631
- }
632
- killChild() {
633
- const child = this.child;
634
- this.child = null;
635
- if (child && !child.killed) try {
636
- child.kill("SIGTERM");
637
- } catch (err) {
638
- this.deps.logger.warn("fmp4 fragment child: kill error", {
639
- tags: { deviceId: this.args.deviceId },
640
- meta: {
641
- sourceId: this.args.sourceId,
642
- error: errMsg(err)
643
- }
644
- });
645
- }
646
- }
647
- };
648
- //#endregion
649
- export { FilesystemStorageProvider, Fmp4FragmentChild, Fmp4FragmentPlane };