@camstack/addon-provider-reolink 1.2.146 → 1.2.147
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/dist/BaichuanVideoStream-FOE2DBVZ-94yIU75L.mjs +2 -0
- package/dist/BaichuanVideoStream-FOE2DBVZ-DJcEkVak.js +3 -0
- package/dist/addon.js +1469 -630
- package/dist/addon.mjs +1310 -471
- package/dist/{chunk-4KBXJ7U3-BpV_ui8q.js → chunk-ZBACPERX-BM6Ll-rh.js} +6 -8
- package/dist/{chunk-4KBXJ7U3-CCQfaWmi.mjs → chunk-ZBACPERX-cDJK1KXE.mjs} +6 -8
- package/package.json +2 -2
- package/dist/BaichuanVideoStream-GFJX465B-D_s-iWc1.mjs +0 -2
- package/dist/BaichuanVideoStream-GFJX465B-EThalnJS.js +0 -3
- /package/dist/{DiagnosticsTools-DZ5RWXSM-9NV95vRN.mjs → DiagnosticsTools-ZC7I7QM6-9NV95vRN.mjs} +0 -0
- /package/dist/{DiagnosticsTools-DZ5RWXSM-CD4rRF8a.js → DiagnosticsTools-ZC7I7QM6-CD4rRF8a.js} +0 -0
package/dist/addon.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as __toCommonJS, i as __require, n as __esmMin, o as __toESM, r as __exportAll, t as __commonJSMin } from "./chunk-CNf5ZN-e.mjs";
|
|
2
|
-
import { A as splitAnnexBToNalPayloads, C as extractSpsFromAnnexB, D as md5StrModern, E as isH265Irap, M as talkTraceLog, N as traceLog, O as normalizeDebugOptions, S as extractPpsFromAnnexB, T as getH265NalType, _ as convertToAnnexB, a as BC_MAGIC, b as deriveAesKey, c as BaichuanVideoStream, d as __require$1, f as aesDecrypt, g as bcHeaderHasPayloadOffset, h as bcEncrypt, i as BC_CLASS_MODERN_24, j as splitAnnexBToNalPayloads2, k as recordingsTraceLog, l as BcMediaAnnexBDecoder, m as bcDecrypt, n as BC_CLASS_LEGACY, o as BC_MAGIC_REV, p as aesEncrypt, r as BC_CLASS_MODERN_20, t as BC_CLASS_FILE_DOWNLOAD, v as convertToAnnexB2, w as extractVpsFromAnnexB, x as eventTraceLog, y as debugLog } from "./chunk-
|
|
2
|
+
import { A as splitAnnexBToNalPayloads, C as extractSpsFromAnnexB, D as md5StrModern, E as isH265Irap, M as talkTraceLog, N as traceLog, O as normalizeDebugOptions, S as extractPpsFromAnnexB, T as getH265NalType, _ as convertToAnnexB, a as BC_MAGIC, b as deriveAesKey, c as BaichuanVideoStream, d as __require$1, f as aesDecrypt, g as bcHeaderHasPayloadOffset, h as bcEncrypt, i as BC_CLASS_MODERN_24, j as splitAnnexBToNalPayloads2, k as recordingsTraceLog, l as BcMediaAnnexBDecoder, m as bcDecrypt, n as BC_CLASS_LEGACY, o as BC_MAGIC_REV, p as aesEncrypt, r as BC_CLASS_MODERN_20, t as BC_CLASS_FILE_DOWNLOAD, v as convertToAnnexB2, w as extractVpsFromAnnexB, x as eventTraceLog, y as debugLog } from "./chunk-ZBACPERX-cDJK1KXE.mjs";
|
|
3
3
|
import { createHash, randomBytes } from "node:crypto";
|
|
4
4
|
import { EventEmitter } from "events";
|
|
5
5
|
import * as fs2 from "fs";
|
|
@@ -5385,7 +5385,7 @@ var ZodIssueCode = {
|
|
|
5385
5385
|
var ZodFirstPartyTypeKind;
|
|
5386
5386
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5387
5387
|
//#endregion
|
|
5388
|
-
//#region ../types/dist/sleep-
|
|
5388
|
+
//#region ../types/dist/sleep-CaB_hL5g.mjs
|
|
5389
5389
|
/**
|
|
5390
5390
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5391
5391
|
* window to float samples (D455).
|
|
@@ -7432,6 +7432,8 @@ var EVENT_OWNER_TYPES = [
|
|
|
7432
7432
|
* nothing failing until a caller asked.
|
|
7433
7433
|
*/
|
|
7434
7434
|
var EventOwnerTypeSchema = _enum(EVENT_OWNER_TYPES);
|
|
7435
|
+
/** The same list as a Zod enum, for the cap input that carries it. */
|
|
7436
|
+
var MediaPresenceOwnerKindSchema = _enum([...EVENT_OWNER_TYPES, "track"]);
|
|
7435
7437
|
new Set(EVENT_OWNER_TYPES);
|
|
7436
7438
|
var EncodeProfileSchema = object({
|
|
7437
7439
|
video: object({
|
|
@@ -14977,8 +14979,6 @@ method(object({
|
|
|
14977
14979
|
deviceId: number(),
|
|
14978
14980
|
capName: string(),
|
|
14979
14981
|
wrapperAddonId: string(),
|
|
14980
|
-
/** The `ClipSource.source` id to toggle. Absent = all of the addon's. */
|
|
14981
|
-
sourceId: string().optional(),
|
|
14982
14982
|
active: boolean()
|
|
14983
14983
|
}), _void(), {
|
|
14984
14984
|
kind: "mutation",
|
|
@@ -22007,7 +22007,11 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
|
|
|
22007
22007
|
ownerType: EventOwnerTypeSchema,
|
|
22008
22008
|
eventId: number().int(),
|
|
22009
22009
|
deviceId: number()
|
|
22010
|
-
}), array(MediaFileInfoSchema).readonly()), method(
|
|
22010
|
+
}), array(MediaFileInfoSchema).readonly()), method(object({
|
|
22011
|
+
deviceId: number(),
|
|
22012
|
+
ownerKind: MediaPresenceOwnerKindSchema,
|
|
22013
|
+
ownerIds: array(string()).max(5e3)
|
|
22014
|
+
}), array(string()).readonly()), method(SearchObjectEventsInput, array(ScoredObjectEventSchema).readonly()), method(object({}), WipeObjectEmbeddingsResultSchema, {
|
|
22011
22015
|
kind: "mutation",
|
|
22012
22016
|
auth: "admin"
|
|
22013
22017
|
}), method(RebuildObjectEmbeddingsInput, RebuildObjectEmbeddingsResultSchema, {
|
|
@@ -25105,6 +25109,24 @@ method(VectorDeclareIndexInputSchema, _void(), {
|
|
|
25105
25109
|
kind: "mutation",
|
|
25106
25110
|
auth: "admin"
|
|
25107
25111
|
}), method(VectorStatsInputSchema, VectorStatsResultSchema, { auth: "admin" });
|
|
25112
|
+
_enum([
|
|
25113
|
+
"queue-full",
|
|
25114
|
+
"camera-backoff",
|
|
25115
|
+
"sleeping",
|
|
25116
|
+
"camera-refused",
|
|
25117
|
+
"no-keyframe",
|
|
25118
|
+
"no-catalog-row",
|
|
25119
|
+
"unsupported",
|
|
25120
|
+
"unknown-device",
|
|
25121
|
+
"uid-missing"
|
|
25122
|
+
]);
|
|
25123
|
+
_enum(["deferred", "final"]);
|
|
25124
|
+
/** The camera's / provider's own words. Kept verbatim, never parsed. */
|
|
25125
|
+
var CLIP_STILL_REASON_HEADER = "x-camstack-reason";
|
|
25126
|
+
/** One {@link ClipStillRefusalCodeSchema} token, alone. */
|
|
25127
|
+
var CLIP_STILL_REASON_CODE_HEADER = "x-camstack-reason-code";
|
|
25128
|
+
/** One {@link ClipStillDispositionSchema} token, alone. */
|
|
25129
|
+
var CLIP_STILL_DISPOSITION_HEADER = "x-camstack-disposition";
|
|
25108
25130
|
var ClipSchema = object({
|
|
25109
25131
|
/** Opaque, provider-namespaced id. The default provider encodes the time
|
|
25110
25132
|
* window so `getClipPlayback` is self-contained (no event re-query). */
|
|
@@ -25255,7 +25277,25 @@ var ClipSchema = object({
|
|
|
25255
25277
|
*/
|
|
25256
25278
|
playable: boolean().optional(),
|
|
25257
25279
|
/** Why {@link playable} is false, verbatim (`no-file-for-window`). */
|
|
25258
|
-
unplayableReason: string().optional()
|
|
25280
|
+
unplayableReason: string().optional(),
|
|
25281
|
+
/**
|
|
25282
|
+
* This clip is STILL BEING WRITTEN, so {@link ClipSchema.timeRange}`.endMs`
|
|
25283
|
+
* is not its end.
|
|
25284
|
+
*
|
|
25285
|
+
* Absent — the common case — means the row is closed and its `endMs` is the
|
|
25286
|
+
* end of the recording. Present and `true` means the source told us the file
|
|
25287
|
+
* has no end yet, and the `endMs` we carry is whatever the camera's index
|
|
25288
|
+
* entry happened to hold: on a Reolink E1 Outdoor PoE (592, measured
|
|
25289
|
+
* 2026-09-20) the newest file `…_192927_000000_…_0.mp4` reported an `endTime`
|
|
25290
|
+
* of 19:29:56 and STILL reported it eight minutes later, while the file went
|
|
25291
|
+
* on growing. A surface that drew 29 s there was lying about a clip that
|
|
25292
|
+
* plays for minutes, on the one row the operator looks at first.
|
|
25293
|
+
*
|
|
25294
|
+
* `endMs` is deliberately still a number: it is the best bound anything has
|
|
25295
|
+
* for a mint window or a byte fetch, and every consumer already requires it.
|
|
25296
|
+
* This flag says what it is WORTH, and a duration is not drawn from it.
|
|
25297
|
+
*/
|
|
25298
|
+
inProgress: boolean().optional()
|
|
25259
25299
|
});
|
|
25260
25300
|
var ClipPlaybackSchema = object({
|
|
25261
25301
|
/**
|
|
@@ -25338,59 +25378,17 @@ var ClipSourceSchema = object({
|
|
|
25338
25378
|
* alternative — a `native:reolink:* → provider-reolink` table inside the
|
|
25339
25379
|
* widget — is a second authority on provider identity living in the one
|
|
25340
25380
|
* package with no business knowing it, wrong the day a third source appears
|
|
25341
|
-
* (D557). One addon may serve SEVERAL sources
|
|
25342
|
-
*
|
|
25343
|
-
*
|
|
25344
|
-
*
|
|
25381
|
+
* (D557). One addon may serve SEVERAL sources, which is why the per-device
|
|
25382
|
+
* switch is keyed by SOURCE and not by this (D555) — `addon-provider-reolink`
|
|
25383
|
+
* served a hub child two of them until the two views were measured to be one
|
|
25384
|
+
* store read twice (D555) and then read ONE way (D565).
|
|
25345
25385
|
*
|
|
25346
25386
|
* Optional for version skew only. The collection dispatcher stamps it from
|
|
25347
25387
|
* the registry, so a row that travelled through the fan-out carries the
|
|
25348
25388
|
* authoritative id whatever the provider filled in.
|
|
25349
25389
|
*/
|
|
25350
25390
|
addonId: string().optional(),
|
|
25351
|
-
|
|
25352
|
-
* Which API this source resolved to FOR THIS CAMERA, when it has a choice.
|
|
25353
|
-
*
|
|
25354
|
-
* A source may cover one store through more than one surface — the Reolink
|
|
25355
|
-
* provider reads a hub child through the parent's event log and a standalone
|
|
25356
|
-
* through its own file list, because that is what each camera answers. The
|
|
25357
|
-
* CHOICE is the provider's, made from what the camera is, and is never a row
|
|
25358
|
-
* the operator has to understand; but it is REPORTED, because a source that
|
|
25359
|
-
* silently reads a different API on two cameras and then behaves differently
|
|
25360
|
-
* is the thing nobody can debug later. Absent when the source has only one
|
|
25361
|
-
* way to read its store.
|
|
25362
|
-
*/
|
|
25363
|
-
via: string().optional(),
|
|
25364
|
-
availability: ClipSourceAvailabilitySchema,
|
|
25365
|
-
/**
|
|
25366
|
-
* The operator switched this source OFF for this camera.
|
|
25367
|
-
*
|
|
25368
|
-
* Deliberately NOT a member of {@link ClipSourceAvailabilitySchema}'s
|
|
25369
|
-
* vocabulary. That enum models what the source CAN do — a sleeping camera, an
|
|
25370
|
-
* unmounted card, an index that disagrees with its own calendar — and a
|
|
25371
|
-
* switched-off source could answer perfectly well; the operator decided it
|
|
25372
|
-
* should not. Folding the choice in is how `disabled` and `broken` stop being
|
|
25373
|
-
* distinguishable, which is the D62 rule this repo has already paid for twice:
|
|
25374
|
-
* an off switch is REPORTED off (`CameraStatus.switchedOff`, the same word),
|
|
25375
|
-
* and disabled must never look like broken. It is also what lets every
|
|
25376
|
-
* exhaustive consumer of the availability enum keep compiling.
|
|
25377
|
-
*
|
|
25378
|
-
* A switched-off source contributes NO clips (`listClips` never calls it) and
|
|
25379
|
-
* its row carries no `catalogAsOf`: nothing confirms a catalog it is not
|
|
25380
|
-
* allowed to serve, and a frozen age that can only grow draws a stalling
|
|
25381
|
-
* source rather than an off switch.
|
|
25382
|
-
*
|
|
25383
|
-
* The row survives BECAUSE it is the control the operator switches the source
|
|
25384
|
-
* back on from — D554 decision 4's rule ("a source that cannot answer
|
|
25385
|
-
* produces a ROW, not an absence") applied to the one case D556 carved out of
|
|
25386
|
-
* it, and D557's own kept property ("a source is never hidden, only its
|
|
25387
|
-
* rows"). Absent means on.
|
|
25388
|
-
*
|
|
25389
|
-
* A provider never sets this — like {@link ClipSourceSchema.addonId} it is
|
|
25390
|
-
* stamped by the collection dispatcher, which holds the registry's projection
|
|
25391
|
-
* of the persisted authority (D556) and is the only place that knows it.
|
|
25392
|
-
*/
|
|
25393
|
-
switchedOff: boolean().optional()
|
|
25391
|
+
availability: ClipSourceAvailabilitySchema
|
|
25394
25392
|
});
|
|
25395
25393
|
var videoclipsCapability = {
|
|
25396
25394
|
name: "videoclips",
|
|
@@ -41437,6 +41435,12 @@ Object.freeze({
|
|
|
41437
41435
|
addonId: null,
|
|
41438
41436
|
access: "view"
|
|
41439
41437
|
},
|
|
41438
|
+
"pipelineAnalytics.ownersWithMedia": {
|
|
41439
|
+
capName: "pipeline-analytics",
|
|
41440
|
+
capScope: "device",
|
|
41441
|
+
addonId: null,
|
|
41442
|
+
access: "view"
|
|
41443
|
+
},
|
|
41440
41444
|
"pipelineAnalytics.pauseForStorageMigration": {
|
|
41441
41445
|
capName: "pipeline-analytics",
|
|
41442
41446
|
capScope: "device",
|
|
@@ -45337,6 +45341,11 @@ Object.freeze({
|
|
|
45337
45341
|
form: "single",
|
|
45338
45342
|
optional: false
|
|
45339
45343
|
}],
|
|
45344
|
+
"pipelineAnalytics.ownersWithMedia": [{
|
|
45345
|
+
name: "deviceId",
|
|
45346
|
+
form: "single",
|
|
45347
|
+
optional: false
|
|
45348
|
+
}],
|
|
45340
45349
|
"pipelineAnalytics.proposeRetrainAnnotations": [{
|
|
45341
45350
|
name: "deviceId",
|
|
45342
45351
|
form: "single",
|
|
@@ -69356,11 +69365,11 @@ var require_yazl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
69356
69365
|
}
|
|
69357
69366
|
}));
|
|
69358
69367
|
//#endregion
|
|
69359
|
-
//#region node_modules/@apocaliss92/nodelink-js/dist/chunk-
|
|
69368
|
+
//#region node_modules/@apocaliss92/nodelink-js/dist/chunk-UIQ527B6.js
|
|
69360
69369
|
var import_undici = require_undici();
|
|
69361
69370
|
var import_yazl = /* @__PURE__ */ __toESM(require_yazl(), 1);
|
|
69362
69371
|
var formatterCache = /* @__PURE__ */ new Map();
|
|
69363
|
-
function formatterFor$
|
|
69372
|
+
function formatterFor$2(timeZone) {
|
|
69364
69373
|
const cached = formatterCache.get(timeZone);
|
|
69365
69374
|
if (cached) return cached;
|
|
69366
69375
|
const fmt = new Intl.DateTimeFormat("en-US", {
|
|
@@ -69385,7 +69394,7 @@ function wallClockParts(d, timeZone) {
|
|
|
69385
69394
|
minute: d.getMinutes(),
|
|
69386
69395
|
second: d.getSeconds()
|
|
69387
69396
|
};
|
|
69388
|
-
const parts = formatterFor$
|
|
69397
|
+
const parts = formatterFor$2(timeZone).formatToParts(d);
|
|
69389
69398
|
const pick = (type) => {
|
|
69390
69399
|
const p = parts.find((x) => x.type === type);
|
|
69391
69400
|
return Number.parseInt(p?.value ?? "", 10);
|
|
@@ -75842,7 +75851,7 @@ var require_lz4 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
75842
75851
|
};
|
|
75843
75852
|
}));
|
|
75844
75853
|
//#endregion
|
|
75845
|
-
//#region node_modules/@apocaliss92/nodelink-js/dist/chunk-
|
|
75854
|
+
//#region node_modules/@apocaliss92/nodelink-js/dist/chunk-5PJ6XPBF.js
|
|
75846
75855
|
var import_fxp = require_fxp();
|
|
75847
75856
|
var import_lz4 = /* @__PURE__ */ __toESM(require_lz4(), 1);
|
|
75848
75857
|
function encodeHeader(h) {
|
|
@@ -83946,6 +83955,128 @@ function patchMotionSensitivityListXml(currentXml, bands) {
|
|
|
83946
83955
|
const fragment = encodeMotionSensitivityListXml(bands);
|
|
83947
83956
|
return currentXml.replace(/<sensitivityInfoList[\s\S]*?(?:\/>|<\/sensitivityInfoList>)/, fragment);
|
|
83948
83957
|
}
|
|
83958
|
+
var ADTS_SAMPLES_PER_FRAME = 1024;
|
|
83959
|
+
var ADTS_SAMPLE_RATES = [
|
|
83960
|
+
96e3,
|
|
83961
|
+
88200,
|
|
83962
|
+
64e3,
|
|
83963
|
+
48e3,
|
|
83964
|
+
44100,
|
|
83965
|
+
32e3,
|
|
83966
|
+
24e3,
|
|
83967
|
+
22050,
|
|
83968
|
+
16e3,
|
|
83969
|
+
12e3,
|
|
83970
|
+
11025,
|
|
83971
|
+
8e3,
|
|
83972
|
+
7350,
|
|
83973
|
+
null,
|
|
83974
|
+
null,
|
|
83975
|
+
null
|
|
83976
|
+
];
|
|
83977
|
+
var ADTS_PROFILES = [
|
|
83978
|
+
"Main",
|
|
83979
|
+
"LC",
|
|
83980
|
+
"SSR",
|
|
83981
|
+
"LTP"
|
|
83982
|
+
];
|
|
83983
|
+
var parseAdtsHeader = (frame) => {
|
|
83984
|
+
if (frame.length < 7) return null;
|
|
83985
|
+
const b0 = frame[0];
|
|
83986
|
+
const b1 = frame[1];
|
|
83987
|
+
if (b0 !== 255 || (b1 & 240) !== 240) return null;
|
|
83988
|
+
const b2 = frame[2];
|
|
83989
|
+
const b3 = frame[3];
|
|
83990
|
+
const b4 = frame[4];
|
|
83991
|
+
const b5 = frame[5];
|
|
83992
|
+
const profile = b2 >> 6 & 3;
|
|
83993
|
+
const sampleRateIndex = b2 >> 2 & 15;
|
|
83994
|
+
const channelConfig = (b2 & 1) << 2 | b3 >> 6 & 3;
|
|
83995
|
+
const frameLength = (b3 & 3) << 11 | b4 << 3 | b5 >> 5 & 7;
|
|
83996
|
+
if (frameLength < 7) return null;
|
|
83997
|
+
return {
|
|
83998
|
+
profile,
|
|
83999
|
+
profileName: ADTS_PROFILES[profile] ?? "unknown",
|
|
84000
|
+
sampleRate: ADTS_SAMPLE_RATES[sampleRateIndex] ?? null,
|
|
84001
|
+
channels: channelConfig > 0 ? channelConfig : null,
|
|
84002
|
+
frameLength
|
|
84003
|
+
};
|
|
84004
|
+
};
|
|
84005
|
+
var buildRecordingAudioTrack = (params) => {
|
|
84006
|
+
const { codec, frames } = params;
|
|
84007
|
+
if (codec == null || frames.length === 0) return null;
|
|
84008
|
+
const data = frames.length === 1 ? frames[0] : Buffer.concat([...frames]);
|
|
84009
|
+
if (codec === "Adpcm") return {
|
|
84010
|
+
codec,
|
|
84011
|
+
format: "adpcm",
|
|
84012
|
+
data,
|
|
84013
|
+
frames: frames.length,
|
|
84014
|
+
bytes: data.length,
|
|
84015
|
+
sampleRate: null,
|
|
84016
|
+
channels: null,
|
|
84017
|
+
durationSeconds: null
|
|
84018
|
+
};
|
|
84019
|
+
const head = parseAdtsHeader(frames[0]);
|
|
84020
|
+
if (head == null) return {
|
|
84021
|
+
codec,
|
|
84022
|
+
format: "unknown",
|
|
84023
|
+
data,
|
|
84024
|
+
frames: frames.length,
|
|
84025
|
+
bytes: data.length,
|
|
84026
|
+
sampleRate: null,
|
|
84027
|
+
channels: null,
|
|
84028
|
+
durationSeconds: null
|
|
84029
|
+
};
|
|
84030
|
+
const durationSeconds = head.sampleRate != null && head.sampleRate > 0 ? frames.length * ADTS_SAMPLES_PER_FRAME / head.sampleRate : null;
|
|
84031
|
+
return {
|
|
84032
|
+
codec,
|
|
84033
|
+
format: "adts",
|
|
84034
|
+
data,
|
|
84035
|
+
frames: frames.length,
|
|
84036
|
+
bytes: data.length,
|
|
84037
|
+
sampleRate: head.sampleRate,
|
|
84038
|
+
channels: head.channels,
|
|
84039
|
+
durationSeconds
|
|
84040
|
+
};
|
|
84041
|
+
};
|
|
84042
|
+
var roundRecordingFps = (fps) => {
|
|
84043
|
+
if (fps > 14 && fps < 16) return 15;
|
|
84044
|
+
if (fps > 23 && fps < 26) return 25;
|
|
84045
|
+
if (fps > 29 && fps < 31) return 30;
|
|
84046
|
+
return Math.round(fps * 100) / 100;
|
|
84047
|
+
};
|
|
84048
|
+
var estimateVideoTiming = (params) => {
|
|
84049
|
+
const { timestampsUs } = params;
|
|
84050
|
+
const infoFps = params.infoFps != null && params.infoFps > 0 ? params.infoFps : null;
|
|
84051
|
+
const accessUnits = timestampsUs.length;
|
|
84052
|
+
if (accessUnits >= 2) {
|
|
84053
|
+
const spanUs = timestampsUs[accessUnits - 1] - timestampsUs[0];
|
|
84054
|
+
if (spanUs > 0) {
|
|
84055
|
+
const durationSeconds = spanUs / 1e6;
|
|
84056
|
+
return {
|
|
84057
|
+
accessUnits,
|
|
84058
|
+
fps: roundRecordingFps((accessUnits - 1) / durationSeconds),
|
|
84059
|
+
durationSeconds,
|
|
84060
|
+
infoFps,
|
|
84061
|
+
fpsSource: "timestamps"
|
|
84062
|
+
};
|
|
84063
|
+
}
|
|
84064
|
+
}
|
|
84065
|
+
if (infoFps != null) return {
|
|
84066
|
+
accessUnits,
|
|
84067
|
+
fps: infoFps,
|
|
84068
|
+
durationSeconds: accessUnits > 0 ? accessUnits / infoFps : null,
|
|
84069
|
+
infoFps,
|
|
84070
|
+
fpsSource: "infoFps"
|
|
84071
|
+
};
|
|
84072
|
+
return {
|
|
84073
|
+
accessUnits,
|
|
84074
|
+
fps: null,
|
|
84075
|
+
durationSeconds: null,
|
|
84076
|
+
infoFps,
|
|
84077
|
+
fpsSource: "unknown"
|
|
84078
|
+
};
|
|
84079
|
+
};
|
|
83949
84080
|
var buildDetectionClasses = (parsed, recordType) => {
|
|
83950
84081
|
const classes = [];
|
|
83951
84082
|
const flags = parsed?.flags;
|
|
@@ -88860,7 +88991,7 @@ var ReolinkBaichuanApi = class _ReolinkBaichuanApi {
|
|
|
88860
88991
|
return;
|
|
88861
88992
|
}
|
|
88862
88993
|
entry.startInFlight = (async () => {
|
|
88863
|
-
const { BaichuanVideoStream: BaichuanVideoStream2 } = await import("./BaichuanVideoStream-
|
|
88994
|
+
const { BaichuanVideoStream: BaichuanVideoStream2 } = await import("./BaichuanVideoStream-FOE2DBVZ-94yIU75L.mjs");
|
|
88864
88995
|
const sessionKey = `live:object-detections:ch${entry.channel}:${entry.profile}`;
|
|
88865
88996
|
const dedicated = await this.createDedicatedSession(sessionKey);
|
|
88866
88997
|
const stream = new BaichuanVideoStream2({
|
|
@@ -91973,25 +92104,46 @@ ${stderr}`));
|
|
|
91973
92104
|
async downloadRecordingDemuxed(params) {
|
|
91974
92105
|
const raw = await this.downloadRecording(params);
|
|
91975
92106
|
const frames = [];
|
|
92107
|
+
const timestampsUs = [];
|
|
92108
|
+
const audioFrames = [];
|
|
91976
92109
|
const decoder = new BcMediaAnnexBDecoder({
|
|
91977
92110
|
strict: false,
|
|
91978
92111
|
logger: this.logger,
|
|
91979
|
-
onVideoAccessUnit: ({ annexB }) => {
|
|
92112
|
+
onVideoAccessUnit: ({ annexB, microseconds }) => {
|
|
91980
92113
|
frames.push(annexB);
|
|
92114
|
+
timestampsUs.push(microseconds);
|
|
92115
|
+
},
|
|
92116
|
+
onAudioFrame: ({ data }) => {
|
|
92117
|
+
audioFrames.push(data);
|
|
91981
92118
|
}
|
|
91982
92119
|
});
|
|
91983
92120
|
decoder.push(raw);
|
|
91984
92121
|
const stats = decoder.getStats();
|
|
92122
|
+
const audio = buildRecordingAudioTrack({
|
|
92123
|
+
codec: stats.audioType,
|
|
92124
|
+
frames: audioFrames
|
|
92125
|
+
});
|
|
92126
|
+
const timing = estimateVideoTiming({
|
|
92127
|
+
timestampsUs,
|
|
92128
|
+
infoFps: stats.infos[0]?.fps ?? null
|
|
92129
|
+
});
|
|
92130
|
+
if (audio == null) this.logger?.debug?.(`[downloadRecordingDemuxed] no audio packet in ${stats.packets} BcMedia packets (${stats.bytesIn} bytes) for ${params.fileName}`);
|
|
91985
92131
|
return {
|
|
91986
92132
|
annexB: Buffer.concat(frames),
|
|
91987
92133
|
videoType: stats.videoType,
|
|
92134
|
+
audio,
|
|
91988
92135
|
stats: {
|
|
91989
92136
|
bytesIn: stats.bytesIn,
|
|
91990
92137
|
bytesOut: stats.bytesOut,
|
|
91991
92138
|
packets: stats.packets,
|
|
91992
92139
|
videoPackets: stats.videoPackets,
|
|
91993
92140
|
audioPackets: stats.audioPackets,
|
|
91994
|
-
|
|
92141
|
+
audioBytes: stats.audioBytesOut,
|
|
92142
|
+
keyframes: stats.keyframes,
|
|
92143
|
+
fps: timing.fps,
|
|
92144
|
+
durationSeconds: timing.durationSeconds,
|
|
92145
|
+
infoFps: timing.infoFps,
|
|
92146
|
+
fpsSource: timing.fpsSource
|
|
91995
92147
|
}
|
|
91996
92148
|
};
|
|
91997
92149
|
}
|
|
@@ -92037,28 +92189,12 @@ ${stderr}`));
|
|
|
92037
92189
|
decoder.push(raw);
|
|
92038
92190
|
const decoderStats = decoder.getStats();
|
|
92039
92191
|
const videoCodec = decoderStats.videoType ?? "H264";
|
|
92040
|
-
|
|
92041
|
-
|
|
92042
|
-
|
|
92043
|
-
|
|
92044
|
-
|
|
92045
|
-
|
|
92046
|
-
durationSeconds = durationUs / 1e6;
|
|
92047
|
-
fps = (videoFrames.length - 1) / durationSeconds;
|
|
92048
|
-
} else {
|
|
92049
|
-
const infoFps = decoderStats.infos[0]?.fps;
|
|
92050
|
-
fps = infoFps && infoFps > 0 ? infoFps : 15;
|
|
92051
|
-
durationSeconds = videoFrames.length / fps;
|
|
92052
|
-
}
|
|
92053
|
-
} else {
|
|
92054
|
-
const infoFps = decoderStats.infos[0]?.fps;
|
|
92055
|
-
fps = infoFps && infoFps > 0 ? infoFps : 15;
|
|
92056
|
-
durationSeconds = videoFrames.length / fps;
|
|
92057
|
-
}
|
|
92058
|
-
if (fps > 14 && fps < 16) fps = 15;
|
|
92059
|
-
else if (fps > 23 && fps < 26) fps = 25;
|
|
92060
|
-
else if (fps > 29 && fps < 31) fps = 30;
|
|
92061
|
-
else fps = Math.round(fps * 100) / 100;
|
|
92192
|
+
const timing = estimateVideoTiming({
|
|
92193
|
+
timestampsUs: videoFrames.map((f) => f.microseconds),
|
|
92194
|
+
infoFps: decoderStats.infos[0]?.fps ?? null
|
|
92195
|
+
});
|
|
92196
|
+
const fps = timing.fps ?? 15;
|
|
92197
|
+
const durationSeconds = timing.durationSeconds ?? videoFrames.length / fps;
|
|
92062
92198
|
const videoData = Buffer.concat(videoFrames.map((f) => f.annexB));
|
|
92063
92199
|
const audioData = audioFrames.length > 0 ? Buffer.concat(audioFrames) : null;
|
|
92064
92200
|
const hasAudio = audioData != null && audioData.length > 0;
|
|
@@ -95011,7 +95147,7 @@ ${xml}`);
|
|
|
95011
95147
|
* @returns Test results for all stream types and profiles
|
|
95012
95148
|
*/
|
|
95013
95149
|
async testChannelStreams(channel, logger) {
|
|
95014
|
-
const { testChannelStreams } = await import("./DiagnosticsTools-
|
|
95150
|
+
const { testChannelStreams } = await import("./DiagnosticsTools-ZC7I7QM6-9NV95vRN.mjs");
|
|
95015
95151
|
return await testChannelStreams({
|
|
95016
95152
|
api: this,
|
|
95017
95153
|
channel: this.normalizeChannel(channel),
|
|
@@ -95027,7 +95163,7 @@ ${xml}`);
|
|
|
95027
95163
|
* @returns Complete diagnostics for all channels and streams
|
|
95028
95164
|
*/
|
|
95029
95165
|
async collectMultifocalDiagnostics(logger) {
|
|
95030
|
-
const { collectMultifocalDiagnostics } = await import("./DiagnosticsTools-
|
|
95166
|
+
const { collectMultifocalDiagnostics } = await import("./DiagnosticsTools-ZC7I7QM6-9NV95vRN.mjs");
|
|
95031
95167
|
return await collectMultifocalDiagnostics({
|
|
95032
95168
|
api: this,
|
|
95033
95169
|
logger
|
|
@@ -144089,7 +144225,7 @@ function buildAacAudioSpecificConfigHex(params) {
|
|
|
144089
144225
|
if (!Number.isFinite(audioObjectType) || audioObjectType <= 0 || audioObjectType > 31) return;
|
|
144090
144226
|
return ((audioObjectType & 31) << 11 | (samplingFreqIndex & 15) << 7 | (channels & 15) << 3).toString(16).padStart(4, "0");
|
|
144091
144227
|
}
|
|
144092
|
-
function
|
|
144228
|
+
function parseAdtsHeader2(adtsFrame) {
|
|
144093
144229
|
if (adtsFrame.length < 7) return null;
|
|
144094
144230
|
if (adtsFrame[0] !== 255 || (adtsFrame[1] & 240) !== 240) return null;
|
|
144095
144231
|
const protectionAbsent = (adtsFrame[1] & 1) === 1;
|
|
@@ -144194,7 +144330,7 @@ function packetizeH265(nal, rtp, opts, markerOnLast, isLastNal) {
|
|
|
144194
144330
|
return out;
|
|
144195
144331
|
}
|
|
144196
144332
|
function packetizeAacAdtsFrame(adts, rtp) {
|
|
144197
|
-
const parsed =
|
|
144333
|
+
const parsed = parseAdtsHeader2(adts);
|
|
144198
144334
|
if (!parsed) return { packets: [] };
|
|
144199
144335
|
const raw = adts.subarray(parsed.headerLength);
|
|
144200
144336
|
if (!raw.length) return { packets: [] };
|
|
@@ -145844,7 +145980,7 @@ async function createRfc4571TcpServerInternal(options) {
|
|
|
145844
145980
|
}, isCompositeStream ? Math.min(1e4, keyframeTimeoutMs) : 5e3);
|
|
145845
145981
|
const onAudio = (frame) => {
|
|
145846
145982
|
sawAnyAudio = true;
|
|
145847
|
-
const parsed =
|
|
145983
|
+
const parsed = parseAdtsHeader2(frame);
|
|
145848
145984
|
if (!parsed) {
|
|
145849
145985
|
if (debugLogsLeft-- > 0) {
|
|
145850
145986
|
const head = frame.subarray(0, Math.min(16, frame.length)).toString("hex");
|
|
@@ -147027,6 +147163,23 @@ var reolinkCameraSchema = object({
|
|
|
147027
147163
|
motionEnabled: boolean().optional(),
|
|
147028
147164
|
motionSensitivity: number().int().min(1).max(50).optional(),
|
|
147029
147165
|
/**
|
|
147166
|
+
* Per-device clip-catalog refresh interval, in minutes — the OVERRIDE half
|
|
147167
|
+
* of the cascade whose global default lives in the addon store under the
|
|
147168
|
+
* same key. Absent means "use the global", which is the same thing a reset
|
|
147169
|
+
* means (`resolveClipCatalogRefreshMinutes`, D562). `0` turns the timer off
|
|
147170
|
+
* for this camera. What the timer DOES with it differs by topology and the
|
|
147171
|
+
* field description says both: a free read on a hub child and on mains, and
|
|
147172
|
+
* stale-marking only on a standalone battery camera.
|
|
147173
|
+
*/
|
|
147174
|
+
clipCatalogRefreshMinutes: number().int().min(0).max(1440).optional(),
|
|
147175
|
+
/**
|
|
147176
|
+
* Let the clip timer WAKE this standalone battery camera. Off by default and
|
|
147177
|
+
* per device only — a 15-minute forced timer is 96 wakes/day against a
|
|
147178
|
+
* natural rate of 1–20 clips/day on this fleet (D562). Inert on every other
|
|
147179
|
+
* topology, which is why it is one switch and not a second meaning.
|
|
147180
|
+
*/
|
|
147181
|
+
clipCatalogForcedWake: boolean().optional(),
|
|
147182
|
+
/**
|
|
147030
147183
|
* Per-AI-class sensitivity overrides — pushed via
|
|
147031
147184
|
* `setAiDetection(aiType, sensitivity)` (cmdId=343). Reolink
|
|
147032
147185
|
* range 0..100 — same scale the reolink_aio CGI exposes
|
|
@@ -147571,6 +147724,20 @@ var ClipCatalogCache = class ClipCatalogCache {
|
|
|
147571
147724
|
}
|
|
147572
147725
|
return null;
|
|
147573
147726
|
}
|
|
147727
|
+
/**
|
|
147728
|
+
* Every day key this device holds a listing for, in no particular order.
|
|
147729
|
+
*
|
|
147730
|
+
* It is what lets an availability probe say WHEN a catalog was last
|
|
147731
|
+
* confirmed without listing anything: a camera nobody may wake reports the
|
|
147732
|
+
* age of what is held, and a source with nothing held says so rather than
|
|
147733
|
+
* claiming to be current.
|
|
147734
|
+
*/
|
|
147735
|
+
daysHeld(deviceId) {
|
|
147736
|
+
const out = [];
|
|
147737
|
+
const prefix = `${deviceId}|`;
|
|
147738
|
+
for (const key of this.slots.keys()) if (key.startsWith(prefix)) out.push(key.slice(prefix.length));
|
|
147739
|
+
return out;
|
|
147740
|
+
}
|
|
147574
147741
|
/** Every row held for a device, in no particular order. The prefetch sorts. */
|
|
147575
147742
|
allRows(deviceId) {
|
|
147576
147743
|
const out = [];
|
|
@@ -147624,6 +147791,57 @@ var ClipCatalogCache = class ClipCatalogCache {
|
|
|
147624
147791
|
}
|
|
147625
147792
|
};
|
|
147626
147793
|
//#endregion
|
|
147794
|
+
//#region src/clips/clip-still-refusal.ts
|
|
147795
|
+
/** "You are in the queue." */
|
|
147796
|
+
function deferStill(code, reason, retryAfterMs) {
|
|
147797
|
+
return {
|
|
147798
|
+
ok: false,
|
|
147799
|
+
code,
|
|
147800
|
+
disposition: "deferred",
|
|
147801
|
+
reason,
|
|
147802
|
+
retryAfterMs
|
|
147803
|
+
};
|
|
147804
|
+
}
|
|
147805
|
+
/** "This will not happen." */
|
|
147806
|
+
function refuseStill(code, reason) {
|
|
147807
|
+
return {
|
|
147808
|
+
ok: false,
|
|
147809
|
+
code,
|
|
147810
|
+
disposition: "final",
|
|
147811
|
+
reason
|
|
147812
|
+
};
|
|
147813
|
+
}
|
|
147814
|
+
/**
|
|
147815
|
+
* The queue's own refusal — the only failure that is about the LANE rather
|
|
147816
|
+
* than about the camera, and therefore the only one that is deferred.
|
|
147817
|
+
*
|
|
147818
|
+
* It carries its own `retryAfterMs` because the queue is the only thing that
|
|
147819
|
+
* knows it: the depth it is holding, or the exact instant a host's backoff
|
|
147820
|
+
* closes.
|
|
147821
|
+
*/
|
|
147822
|
+
var ThumbQueueRefusedError = class extends Error {
|
|
147823
|
+
code;
|
|
147824
|
+
retryAfterMs;
|
|
147825
|
+
constructor(code, message, retryAfterMs) {
|
|
147826
|
+
super(message);
|
|
147827
|
+
this.name = "ThumbQueueRefusedError";
|
|
147828
|
+
this.code = code;
|
|
147829
|
+
this.retryAfterMs = retryAfterMs;
|
|
147830
|
+
}
|
|
147831
|
+
};
|
|
147832
|
+
/**
|
|
147833
|
+
* A thrown value from the queue, as a wire answer — or `null` when it was not
|
|
147834
|
+
* the queue at all.
|
|
147835
|
+
*
|
|
147836
|
+
* `null` is not a default: it is what makes the caller name `camera-refused`
|
|
147837
|
+
* explicitly, instead of a socket close quietly inheriting "come back later"
|
|
147838
|
+
* and a tile retrying four times against a camera that is not there.
|
|
147839
|
+
*/
|
|
147840
|
+
function queueRefusal(err) {
|
|
147841
|
+
if (!(err instanceof ThumbQueueRefusedError)) return null;
|
|
147842
|
+
return deferStill(err.code, err.message, err.retryAfterMs);
|
|
147843
|
+
}
|
|
147844
|
+
//#endregion
|
|
147627
147845
|
//#region src/clips/clip-data-plane.ts
|
|
147628
147846
|
/**
|
|
147629
147847
|
* The addon's two data-plane handlers — the still and the bytes.
|
|
@@ -147645,6 +147863,19 @@ var ClipCatalogCache = class ClipCatalogCache {
|
|
|
147645
147863
|
* which. Waiting instead would hold a request open behind a camera that is
|
|
147646
147864
|
* asleep for the night.
|
|
147647
147865
|
*
|
|
147866
|
+
* **And it says whether to COME BACK.** Those reasons are two kinds of answer:
|
|
147867
|
+
* `queue-full` and `camera-backoff` mean the still is still coming, the rest
|
|
147868
|
+
* mean it will not. The branch that refused decides — nothing here maps a code
|
|
147869
|
+
* to a disposition, and no client parses one out of the prose — and the answer
|
|
147870
|
+
* travels as its own headers (`x-camstack-reason-code`,
|
|
147871
|
+
* `x-camstack-disposition`, plus `retry-after` on a deferred one) beside the
|
|
147872
|
+
* prose, which stays verbatim because a `camera-refused` is only ever
|
|
147873
|
+
* explained by the camera's own words.
|
|
147874
|
+
*
|
|
147875
|
+
* A response with no disposition header is read as FINAL by every surface,
|
|
147876
|
+
* which is exactly how this route behaved before: an older addon under a newer
|
|
147877
|
+
* admin UI keeps the old behaviour instead of gaining a retry loop.
|
|
147878
|
+
*
|
|
147648
147879
|
* ## Why Range is hand-rolled here
|
|
147649
147880
|
*
|
|
147650
147881
|
* One file, one path, no root mapping — and `createReadStream().pipe(res)`
|
|
@@ -147687,26 +147918,45 @@ function createClipThumbHandler(deps) {
|
|
|
147687
147918
|
try {
|
|
147688
147919
|
minted = await deps.mint(deviceId, clipKey);
|
|
147689
147920
|
} catch (err) {
|
|
147690
|
-
minted =
|
|
147691
|
-
ok: false,
|
|
147692
|
-
reason: err instanceof Error ? err.message : String(err)
|
|
147693
|
-
};
|
|
147921
|
+
minted = refuseStill("camera-refused", err instanceof Error ? err.message : String(err));
|
|
147694
147922
|
}
|
|
147695
147923
|
if (!minted.ok) {
|
|
147696
|
-
|
|
147697
|
-
tags: { deviceId },
|
|
147698
|
-
meta: {
|
|
147699
|
-
clipKey,
|
|
147700
|
-
reason: minted.reason
|
|
147701
|
-
}
|
|
147702
|
-
});
|
|
147703
|
-
res.writeHead(204, { "x-camstack-reason": minted.reason.slice(0, 500) });
|
|
147704
|
-
res.end();
|
|
147924
|
+
writeRefusal(res, minted, deviceId, deps.logger, clipKey);
|
|
147705
147925
|
return;
|
|
147706
147926
|
}
|
|
147707
147927
|
writeJpeg(res, minted.bytes, req.method === "HEAD");
|
|
147708
147928
|
};
|
|
147709
147929
|
}
|
|
147930
|
+
/**
|
|
147931
|
+
* The 204, with everything the tile needs to decide what to draw next.
|
|
147932
|
+
*
|
|
147933
|
+
* A FINAL refusal is work that was dropped, so it is warned, per camera. A
|
|
147934
|
+
* DEFERRED one dropped nothing — the still is queued behind another — and
|
|
147935
|
+
* warning it would put 43 lines on the log for one 60-tile page against a
|
|
147936
|
+
* 16-deep lane, which is how a real drop stops being visible.
|
|
147937
|
+
*/
|
|
147938
|
+
function writeRefusal(res, refusal, deviceId, logger, clipKey) {
|
|
147939
|
+
const line = "videoclips: thumbnail not minted";
|
|
147940
|
+
const extras = {
|
|
147941
|
+
tags: { deviceId },
|
|
147942
|
+
meta: {
|
|
147943
|
+
clipKey,
|
|
147944
|
+
code: refusal.code,
|
|
147945
|
+
disposition: refusal.disposition,
|
|
147946
|
+
reason: refusal.reason
|
|
147947
|
+
}
|
|
147948
|
+
};
|
|
147949
|
+
if (refusal.disposition === "final") logger.warn(line, extras);
|
|
147950
|
+
else logger.debug(line, extras);
|
|
147951
|
+
const retryAfterMs = refusal.disposition === "deferred" ? refusal.retryAfterMs : void 0;
|
|
147952
|
+
res.writeHead(204, {
|
|
147953
|
+
[CLIP_STILL_REASON_HEADER]: refusal.reason.slice(0, 500),
|
|
147954
|
+
[CLIP_STILL_REASON_CODE_HEADER]: refusal.code,
|
|
147955
|
+
[CLIP_STILL_DISPOSITION_HEADER]: refusal.disposition,
|
|
147956
|
+
...retryAfterMs === void 0 ? {} : { "retry-after": String(Math.max(1, Math.ceil(retryAfterMs / 1e3))) }
|
|
147957
|
+
});
|
|
147958
|
+
res.end();
|
|
147959
|
+
}
|
|
147710
147960
|
function writeJpeg(res, bytes, headOnly) {
|
|
147711
147961
|
res.writeHead(200, {
|
|
147712
147962
|
"content-type": "image/jpeg",
|
|
@@ -147825,21 +148075,73 @@ function createClipPlaybackHandler(deps) {
|
|
|
147825
148075
|
//#region src/clips/clip-mux.ts
|
|
147826
148076
|
/** A clip that has not transferred by here is not going to. */
|
|
147827
148077
|
var CLIP_MUX_TIMEOUT_MS = 6e4;
|
|
148078
|
+
/**
|
|
148079
|
+
* Decide what to do with the track the download returned.
|
|
148080
|
+
*
|
|
148081
|
+
* The gate is `format === 'adts'` and NOT `audio !== null`: an `adpcm` or
|
|
148082
|
+
* `unknown` track stream-copied into MP4 produces a file whose audio track is
|
|
148083
|
+
* garbage, which is worse than a clip that is honestly silent. A track that
|
|
148084
|
+
* arrived with no frames is no track — counting it would promise sound the
|
|
148085
|
+
* file does not have.
|
|
148086
|
+
*/
|
|
148087
|
+
function decideClipAudio(audio) {
|
|
148088
|
+
if (audio === null) return {
|
|
148089
|
+
kind: "silent",
|
|
148090
|
+
reason: "no-audio-track",
|
|
148091
|
+
format: null
|
|
148092
|
+
};
|
|
148093
|
+
if (audio.frames === 0 || audio.bytes === 0) return {
|
|
148094
|
+
kind: "silent",
|
|
148095
|
+
reason: "no-audio-track",
|
|
148096
|
+
format: audio.format
|
|
148097
|
+
};
|
|
148098
|
+
if (audio.format !== "adts") return {
|
|
148099
|
+
kind: "silent",
|
|
148100
|
+
reason: "audio-not-copyable",
|
|
148101
|
+
format: audio.format
|
|
148102
|
+
};
|
|
148103
|
+
return {
|
|
148104
|
+
kind: "copy",
|
|
148105
|
+
format: "adts",
|
|
148106
|
+
data: audio.data
|
|
148107
|
+
};
|
|
148108
|
+
}
|
|
148109
|
+
function usableFps(fps) {
|
|
148110
|
+
if (fps === null || fps === void 0) return null;
|
|
148111
|
+
return Number.isFinite(fps) && fps > 0 ? fps : null;
|
|
148112
|
+
}
|
|
147828
148113
|
function buildClipMuxArgs(input) {
|
|
148114
|
+
const demuxer = input.videoType === "H265" ? "hevc" : "h264";
|
|
148115
|
+
const fps = usableFps(input.fps);
|
|
147829
148116
|
return [
|
|
147830
148117
|
"-hide_banner",
|
|
147831
148118
|
"-loglevel",
|
|
147832
148119
|
"error",
|
|
147833
148120
|
"-nostdin",
|
|
147834
148121
|
"-y",
|
|
148122
|
+
...fps !== null ? ["-r", String(fps)] : [],
|
|
147835
148123
|
"-f",
|
|
147836
|
-
|
|
148124
|
+
demuxer,
|
|
147837
148125
|
"-i",
|
|
147838
148126
|
input.inputPath,
|
|
147839
|
-
|
|
148127
|
+
...input.audio !== void 0 ? [
|
|
148128
|
+
"-f",
|
|
148129
|
+
"aac",
|
|
148130
|
+
"-i",
|
|
148131
|
+
input.audio.path
|
|
148132
|
+
] : [],
|
|
148133
|
+
"-c:v",
|
|
147840
148134
|
"copy",
|
|
148135
|
+
...input.audio !== void 0 ? [
|
|
148136
|
+
"-c:a",
|
|
148137
|
+
"copy",
|
|
148138
|
+
"-bsf:a",
|
|
148139
|
+
"aac_adtstoasc"
|
|
148140
|
+
] : [],
|
|
147841
148141
|
"-movflags",
|
|
147842
148142
|
"+faststart",
|
|
148143
|
+
"-f",
|
|
148144
|
+
"mp4",
|
|
147843
148145
|
input.outputPath
|
|
147844
148146
|
];
|
|
147845
148147
|
}
|
|
@@ -147926,6 +148228,40 @@ function describeMuxFailure(run) {
|
|
|
147926
148228
|
if (run.code !== 0) return `mux-failed (exit ${String(run.code)}): ${run.stderr.slice(0, 300)}`;
|
|
147927
148229
|
return null;
|
|
147928
148230
|
}
|
|
148231
|
+
//#endregion
|
|
148232
|
+
//#region src/clips/clip-thumb-queue.ts
|
|
148233
|
+
/**
|
|
148234
|
+
* The provider's OWN CoverPreview lane — two queues, one in flight per host.
|
|
148235
|
+
*
|
|
148236
|
+
* The library already serialises CoverPreview: one in flight per api instance,
|
|
148237
|
+
* a 50-deep FIFO that throws past that, and a process-wide host-keyed backoff
|
|
148238
|
+
* that doubles on a 400. What a FIFO cannot express is PRIORITY, and the two
|
|
148239
|
+
* kinds of mint this feature has are not equal — an operator staring at a tile
|
|
148240
|
+
* must not wait behind twenty prefetches for clips nobody opened.
|
|
148241
|
+
*
|
|
148242
|
+
* So the provider keeps two queues of its own, hands the library at most ONE
|
|
148243
|
+
* CoverPreview per host at a time, drains `interactive` before `prefetch`, and
|
|
148244
|
+
* re-checks between every prefetch mint (D549 16).
|
|
148245
|
+
*
|
|
148246
|
+
* ## Two things it refuses to do
|
|
148247
|
+
*
|
|
148248
|
+
* **Wait when the queue is full.** A request past the bound is REFUSED with
|
|
148249
|
+
* `queue-full`, so the route can answer 204 with a reason. A request held open
|
|
148250
|
+
* behind forty-nine others is a spinner the operator cannot cancel, and the
|
|
148251
|
+
* camera will have rolled the clip over before it is served.
|
|
148252
|
+
*
|
|
148253
|
+
* **Let a prefetch probe a sulking host.** While a host's 400 backoff is open
|
|
148254
|
+
* a prefetch is skipped entirely; only an interactive request may probe it,
|
|
148255
|
+
* because only an interactive request has somebody waiting for the answer.
|
|
148256
|
+
*
|
|
148257
|
+
* The backoff mirrors the library's (1 s doubling to 30 s) rather than
|
|
148258
|
+
* replacing it: this one decides whether to ASK at all, the library's decides
|
|
148259
|
+
* how long to wait once asked.
|
|
148260
|
+
*/
|
|
148261
|
+
/** How long one waiting mint is worth, as a retry hint. Coarse on purpose:
|
|
148262
|
+
* the client floors it with its own backoff and caps its own attempts, so a
|
|
148263
|
+
* wrong hint can neither cause a hammer nor a hang. */
|
|
148264
|
+
var THUMB_DRAIN_HINT_PER_WAITER_MS = 1e3;
|
|
147929
148265
|
var THUMB_BACKOFF_INITIAL_MS = 1e3;
|
|
147930
148266
|
var THUMB_BACKOFF_MAX_MS = 3e4;
|
|
147931
148267
|
/**
|
|
@@ -147946,6 +148282,28 @@ var ClipThumbQueue = class {
|
|
|
147946
148282
|
const state = this.hosts.get(host);
|
|
147947
148283
|
return state !== void 0 && state.backoffUntilMs > this.now();
|
|
147948
148284
|
}
|
|
148285
|
+
/**
|
|
148286
|
+
* Is this host busy with, or owed, operator-facing work?
|
|
148287
|
+
*
|
|
148288
|
+
* The periodic catalog refresh asks before it spends the host's one lane:
|
|
148289
|
+
* an operator staring at a tile must never wait behind a timer, and a host
|
|
148290
|
+
* whose 400 backoff is open must not be probed by anything that has nobody
|
|
148291
|
+
* waiting for the answer — the same rule that already keeps a PREFETCH off
|
|
148292
|
+
* a sulking host.
|
|
148293
|
+
*
|
|
148294
|
+
* Either a mint is in flight or the host is sulking. There is deliberately
|
|
148295
|
+
* no third clause for "an interactive request is queued": a queued request
|
|
148296
|
+
* means a mint is running, so `running` already covers it, and a clause
|
|
148297
|
+
* that can never be the reason for the answer is a leftover that reads as
|
|
148298
|
+
* verification. The lane is one per host, so a PREFETCH holding it defers
|
|
148299
|
+
* the refresh too — which is right: the refresh is the lowest-priority
|
|
148300
|
+
* thing on this host.
|
|
148301
|
+
*/
|
|
148302
|
+
busy(host) {
|
|
148303
|
+
const state = this.hosts.get(host);
|
|
148304
|
+
if (state === void 0) return false;
|
|
148305
|
+
return state.backoffUntilMs > this.now() || state.running;
|
|
148306
|
+
}
|
|
147949
148307
|
backoffUntil(host) {
|
|
147950
148308
|
return this.hosts.get(host)?.backoffUntilMs ?? 0;
|
|
147951
148309
|
}
|
|
@@ -147968,8 +148326,8 @@ var ClipThumbQueue = class {
|
|
|
147968
148326
|
*/
|
|
147969
148327
|
async submit(job) {
|
|
147970
148328
|
const state = this.stateFor(job.host);
|
|
147971
|
-
if (job.lane === "prefetch" && state.backoffUntilMs > this.now()) throw new
|
|
147972
|
-
if (state.waiting.length >= 16) throw new
|
|
148329
|
+
if (job.lane === "prefetch" && state.backoffUntilMs > this.now()) throw new ThumbQueueRefusedError("camera-backoff", `camera-backoff: host ${job.host} refused a CoverPreview recently; prefetch skipped until the backoff closes (only an interactive request probes it)`, state.backoffUntilMs - this.now());
|
|
148330
|
+
if (state.waiting.length >= 16) throw new ThumbQueueRefusedError("queue-full", `queue-full: ${state.waiting.length} thumbnail mints already waiting for host ${job.host}`, state.waiting.length * THUMB_DRAIN_HINT_PER_WAITER_MS);
|
|
147973
148331
|
return new Promise((resolve, reject) => {
|
|
147974
148332
|
state.waiting.push({
|
|
147975
148333
|
lane: job.lane,
|
|
@@ -147989,7 +148347,7 @@ var ClipThumbQueue = class {
|
|
|
147989
148347
|
if (next === void 0) return;
|
|
147990
148348
|
state.waiting.splice(pick, 1);
|
|
147991
148349
|
if (next.lane === "prefetch" && state.backoffUntilMs > this.now()) {
|
|
147992
|
-
next.reject(
|
|
148350
|
+
next.reject(new ThumbQueueRefusedError("camera-backoff", `camera-backoff: host ${host} is backing off; prefetch skipped`, state.backoffUntilMs - this.now()));
|
|
147993
148351
|
this.drain(host);
|
|
147994
148352
|
return;
|
|
147995
148353
|
}
|
|
@@ -148042,12 +148400,13 @@ var ClipThumbQueue = class {
|
|
|
148042
148400
|
* exactly — 29 events, 28 inside the 20 listed files, and all 20 files
|
|
148043
148401
|
* carrying an event. They are two VIEWS of one store.
|
|
148044
148402
|
*
|
|
148045
|
-
* So the operator collapsed them (2026-09-20): one source, which
|
|
148046
|
-
* best API for what the camera IS
|
|
148047
|
-
*
|
|
148048
|
-
*
|
|
148049
|
-
*
|
|
148050
|
-
*
|
|
148403
|
+
* So the operator collapsed them (2026-09-20): one source, which picked the
|
|
148404
|
+
* best API for what the camera IS, and REPORTED the pick on `ClipSource.via`.
|
|
148405
|
+
* Later the same day the pick went too (D565): `FileInfoList` is the catalog
|
|
148406
|
+
* on every topology, so `via` had one value and is gone. What is left is one
|
|
148407
|
+
* source reading one API — and `clipKeyFor` below is still keyed off
|
|
148408
|
+
* `(channel, fileName)` rather than the source, which is now simply true
|
|
148409
|
+
* rather than a concession.
|
|
148051
148410
|
*/
|
|
148052
148411
|
var CLIP_SOURCE_ONBOARD = "native:reolink:onboard";
|
|
148053
148412
|
/** Every source this provider can name. Order is the picker's order. */
|
|
@@ -148098,10 +148457,10 @@ function parseClipId(clipId) {
|
|
|
148098
148457
|
}
|
|
148099
148458
|
/**
|
|
148100
148459
|
* The on-disk key for a clip's derived artifacts (its thumbnail, its muxed
|
|
148101
|
-
* MP4). Derived from `(channel, fileName)` and NOT from the source:
|
|
148102
|
-
*
|
|
148103
|
-
*
|
|
148104
|
-
*
|
|
148460
|
+
* MP4). Derived from `(channel, fileName)` and NOT from the source: a
|
|
148461
|
+
* thumbnail belongs to the FILE, so any surface that names the same file
|
|
148462
|
+
* finds the same picture and the camera is never asked for a second
|
|
148463
|
+
* CoverPreview of it.
|
|
148105
148464
|
*
|
|
148106
148465
|
* A hash rather than the encoded name because a hub `<Id>` is a full path and
|
|
148107
148466
|
* the encoded form is long enough to hit a file-name limit.
|
|
@@ -148250,7 +148609,7 @@ function startOf(file) {
|
|
|
148250
148609
|
return file.startTime?.getTime() ?? 0;
|
|
148251
148610
|
}
|
|
148252
148611
|
var partsCache = /* @__PURE__ */ new Map();
|
|
148253
|
-
function formatterFor(timeZone) {
|
|
148612
|
+
function formatterFor$1(timeZone) {
|
|
148254
148613
|
const cached = partsCache.get(timeZone);
|
|
148255
148614
|
if (cached !== void 0) return cached;
|
|
148256
148615
|
const made = new Intl.DateTimeFormat("en-US", {
|
|
@@ -148267,7 +148626,7 @@ function formatterFor(timeZone) {
|
|
|
148267
148626
|
return made;
|
|
148268
148627
|
}
|
|
148269
148628
|
function partsAt(epochMs, timeZone) {
|
|
148270
|
-
const parts = formatterFor(timeZone).formatToParts(new Date(epochMs));
|
|
148629
|
+
const parts = formatterFor$1(timeZone).formatToParts(new Date(epochMs));
|
|
148271
148630
|
const read = (type) => {
|
|
148272
148631
|
const found = parts.find((p) => p.type === type);
|
|
148273
148632
|
return found === void 0 ? 0 : Number(found.value);
|
|
@@ -148338,36 +148697,6 @@ function enumerateWallClockDays(sinceMs, untilMs, timeZone) {
|
|
|
148338
148697
|
//#endregion
|
|
148339
148698
|
//#region src/clips/clip-catalog.ts
|
|
148340
148699
|
/**
|
|
148341
|
-
* Reading a Reolink camera's own clip catalog: the cheap question, the day
|
|
148342
|
-
* index, then one day's files.
|
|
148343
|
-
*
|
|
148344
|
-
* ## The order is the point
|
|
148345
|
-
*
|
|
148346
|
-
* 1. **Is there a card at all?** `getHddInfoList` (cmd 102). 640 answers
|
|
148347
|
-
* `mount 0, capacity 0` — no SD card — and searching it is 400s and wasted
|
|
148348
|
-
* wake budget. "The cheap question comes first" (D549 4 / D54).
|
|
148349
|
-
* 2. **Which days hold footage?** `getDayRecords` (cmd 142) once per month.
|
|
148350
|
-
* The per-day listing loop of the earlier plan is deleted, not kept as a
|
|
148351
|
-
* fallback (D549 8): 19 days in 50 ms beats 30 searches.
|
|
148352
|
-
* 3. **What is in one day?** `FileInfoList` (cmd 14/15/16), sub AND main, then
|
|
148353
|
-
* twinned (D549 14b). A clip IS a file: its name is its id, its bytes
|
|
148354
|
-
* (cmd 5) and its still (cmd 298) are addressed from it (D549 10).
|
|
148355
|
-
*
|
|
148356
|
-
* This is the API a STANDALONE camera's one source resolves to — a standalone
|
|
148357
|
-
* answers `findEventLog` with an empty body. A hub child resolves to the event
|
|
148358
|
-
* view instead (`clip-event-catalog.ts`), and still uses this reader for the
|
|
148359
|
-
* day's files, which is what an event's window is joined against (D555).
|
|
148360
|
-
*
|
|
148361
|
-
* ## What an empty answer means
|
|
148362
|
-
*
|
|
148363
|
-
* A day the CALENDAR names and the INDEX answers with nothing is a defect on
|
|
148364
|
-
* the camera, measured on 618: the calendar marks 3–20 September, days 6–20
|
|
148365
|
-
* list zero files on both streams, on both filters, on a hand-built window,
|
|
148366
|
-
* with 177 GB free. The reader reports `indexEmpty` for that day so the
|
|
148367
|
-
* provider can say `index-empty` — never "no clips", which would be a lie
|
|
148368
|
-
* about a card that is full of them (D549 18).
|
|
148369
|
-
*/
|
|
148370
|
-
/**
|
|
148371
148700
|
* Locate the disk record structurally.
|
|
148372
148701
|
*
|
|
148373
148702
|
* The library's declared `HddInfoListConfig` and the captured wire disagree —
|
|
@@ -148452,6 +148781,30 @@ function monthsBetween(sinceMs, untilMs, timeZone) {
|
|
|
148452
148781
|
}
|
|
148453
148782
|
return out;
|
|
148454
148783
|
}
|
|
148784
|
+
/**
|
|
148785
|
+
* Is this file still being written?
|
|
148786
|
+
*
|
|
148787
|
+
* A Reolink recording is named `<prefix>_DST<date>_<start>_<end>_<hex>_<hex>`,
|
|
148788
|
+
* and while it is open the camera writes the END stamp as `000000` and the
|
|
148789
|
+
* size as `0` — measured on 592, 2026-09-20:
|
|
148790
|
+
* `RecS03_DST20260920_192927_000000_2B1E808_0.mp4`. Its `<endTime>` block is
|
|
148791
|
+
* FROZEN at whatever the index entry held when it was created (19:29:56, read
|
|
148792
|
+
* three times over fifteen minutes while the file grew), so a duration drawn
|
|
148793
|
+
* from it is a lie about the one row the operator sees first.
|
|
148794
|
+
*
|
|
148795
|
+
* BOTH signals are required. A recording that happens to end at midnight is
|
|
148796
|
+
* named `_000000_` and is closed; its bytes are what separate the two. Nothing
|
|
148797
|
+
* on the wire distinguishes them otherwise, and a false positive here would
|
|
148798
|
+
* replace a correct duration with `Recording…` for ever. Re-measured
|
|
148799
|
+
* read-only the same evening: of 355 sub and 355 main files on that camera's
|
|
148800
|
+
* day, zero carried a `_000000_` segment and zero carried a size of 0.
|
|
148801
|
+
*/
|
|
148802
|
+
function isFileStillBeingWritten(file) {
|
|
148803
|
+
if (file.sizeBytes !== void 0 && file.sizeBytes > 0) return false;
|
|
148804
|
+
return OPEN_END_STAMP.test(file.fileName);
|
|
148805
|
+
}
|
|
148806
|
+
/** The end-stamp field of an open recording, between its own separators. */
|
|
148807
|
+
var OPEN_END_STAMP = /_000000_/;
|
|
148455
148808
|
function handleOf(file) {
|
|
148456
148809
|
const id = file.id;
|
|
148457
148810
|
return id !== void 0 && id !== "" ? id : file.fileName;
|
|
@@ -148492,139 +148845,123 @@ async function listDayRows(api, input) {
|
|
|
148492
148845
|
...pair.sub.sizeBytes !== void 0 ? { subBytes: pair.sub.sizeBytes } : {},
|
|
148493
148846
|
...pair.main !== void 0 ? { mainFileName: handleOf(pair.main) } : {},
|
|
148494
148847
|
...pair.main?.sizeBytes !== void 0 ? { mainBytes: pair.main.sizeBytes } : {},
|
|
148848
|
+
...pair.main?.startTime !== void 0 ? { mainStartMs: pair.main.startTime.getTime() } : {},
|
|
148495
148849
|
supportSub: pair.sub.supportSub !== false,
|
|
148496
|
-
nativeTypes: parseNativeTypes(pair.sub.recordType)
|
|
148850
|
+
nativeTypes: parseNativeTypes(pair.sub.recordType),
|
|
148851
|
+
...isFileStillBeingWritten(pair.sub) ? { inProgress: true } : {}
|
|
148497
148852
|
};
|
|
148498
148853
|
}),
|
|
148499
148854
|
indexEmpty: subs.length === 0,
|
|
148500
148855
|
...mainSearchFailed !== void 0 ? { mainSearchFailed } : {}
|
|
148501
148856
|
};
|
|
148502
148857
|
}
|
|
148503
|
-
|
|
148504
|
-
|
|
148505
|
-
|
|
148506
|
-
* The
|
|
148507
|
-
*
|
|
148508
|
-
*
|
|
148509
|
-
|
|
148510
|
-
|
|
148511
|
-
|
|
148512
|
-
|
|
148513
|
-
|
|
148514
|
-
|
|
148515
|
-
|
|
148516
|
-
|
|
148517
|
-
|
|
148518
|
-
|
|
148519
|
-
* ## An event is not a promise of a clip
|
|
148520
|
-
*
|
|
148521
|
-
* A row whose `hasRecFile` is false has nothing to play, and both of the wrong
|
|
148522
|
-
* things are easy: dropping it under-reports a camera's events, and showing it
|
|
148523
|
-
* as playable fails on click. It is listed with `playable: false` and a
|
|
148524
|
-
* reason, which is what `ClipSchema.unplayableReason` exists for.
|
|
148525
|
-
*
|
|
148526
|
-
* **How often that bites is a per-camera fact.** Measured 2026-09-20 over 20
|
|
148527
|
-
* days: 3628 → 222 rows with 0 orphans, 3629 → 1 059 rows with 0 orphans, and
|
|
148528
|
-
* the orphans D549 19 describes are on 3825 — the child whose uid was never
|
|
148529
|
-
* persisted, which this provider cannot address at all today. So one camera's
|
|
148530
|
-
* events are all playable and another's are all not, and a surface built for
|
|
148531
|
-
* either extreme is wrong on the other.
|
|
148532
|
-
*
|
|
148533
|
-
* ## Where the file comes from
|
|
148534
|
-
*
|
|
148535
|
-
* `findEventLog` rows carry no file name — they name events, not files. So the
|
|
148536
|
-
* file is resolved by WINDOW CONTAINMENT against the day's `FileInfoList`
|
|
148537
|
-
* rows, which the `onboard` reader already fetches: an event whose
|
|
148538
|
-
* `[start, end]` lies inside a file's `[start − 3 s, end + 3 s]`. 28 of 29 on
|
|
148539
|
-
* the measured day; the one that did not is a real orphan (the hub refused its
|
|
148540
|
-
* CoverPreview too), not a join bug.
|
|
148541
|
-
*
|
|
148542
|
-
* Deliberately NOT used here: `searchAlarmVideos` (272/273/274). It does carry
|
|
148543
|
-
* a `fileName`, and its containment is measured at 1271/1271 — but it is
|
|
148544
|
-
* clamped to ONE camera-local day (an 18→19 September window silently answered
|
|
148545
|
-
* 462 windows all dated the 18th) where `searchEventLog` spans the whole
|
|
148546
|
-
* window in one open, and D549 19 chose the event list on the measured timing.
|
|
148547
|
-
* Its place is the per-window label upgrade for a clip's DETAIL (D549 20), and
|
|
148548
|
-
* that is a separate slice.
|
|
148549
|
-
*
|
|
148550
|
-
* ## `devices` is the selector; `chnbits` is inert
|
|
148551
|
-
*
|
|
148552
|
-
* Measured: `chnbits: 3` answered exactly the same 9 rows as the default, and
|
|
148553
|
-
* OMITTING `devices` is refused outright by the library ("no devices to
|
|
148554
|
-
* search") rather than answered emptily — a hub that has pushed nothing yet is
|
|
148555
|
-
* a refusal, not an empty result. This module always passes `devices`, never
|
|
148556
|
-
* sends `chnbits`, and never derives one from the other. With one child named,
|
|
148557
|
-
* foreign rows in the reply were 0; the uid filter below is belt and braces.
|
|
148558
|
-
*/
|
|
148559
|
-
/**
|
|
148560
|
-
* Every event for ONE child in the window, newest first, in ONE call.
|
|
148561
|
-
*
|
|
148562
|
-
* The event list is multi-day by construction — a per-day loop would pay the
|
|
148563
|
-
* open/close for each day and answer the same rows. The bound the caller owes
|
|
148564
|
-
* is on the WINDOW, and it has a number behind it: measured on one hub child,
|
|
148565
|
-
* ONE day is 267 ms and 20 days is 3.6–5.4 s. A day-range default is therefore
|
|
148566
|
-
* a UI decision, not a free one.
|
|
148567
|
-
*/
|
|
148568
|
-
async function listEventRows(api, input) {
|
|
148569
|
-
const entries = await api.searchEventLog({
|
|
148570
|
-
devices: [{ uid: input.uid }],
|
|
148571
|
-
start: new Date(input.since),
|
|
148572
|
-
end: new Date(input.until),
|
|
148573
|
-
timeZone: input.timeZone
|
|
148858
|
+
/**
|
|
148859
|
+
* Every alarm window of ONE camera-local day.
|
|
148860
|
+
*
|
|
148861
|
+
* The one-day clamp is the firmware's, not ours: an 18→19 September ask
|
|
148862
|
+
* answered 462 windows all dated the 18th. The caller owns the iteration, and
|
|
148863
|
+
* this is asked from inside the day loop the listing already runs.
|
|
148864
|
+
*/
|
|
148865
|
+
async function readAlarmWindows(api, input) {
|
|
148866
|
+
const { startMs, endMs } = dayBounds(input.day, input.timeZone);
|
|
148867
|
+
return await api.searchAlarmVideos({
|
|
148868
|
+
channel: input.channel,
|
|
148869
|
+
start: new Date(startMs),
|
|
148870
|
+
end: new Date(endMs),
|
|
148871
|
+
streamType: 1,
|
|
148872
|
+
timeZone: input.timeZone,
|
|
148873
|
+
...input.uid !== void 0 ? { uid: input.uid } : {}
|
|
148574
148874
|
});
|
|
148575
|
-
|
|
148576
|
-
|
|
148577
|
-
|
|
148578
|
-
|
|
148579
|
-
|
|
148580
|
-
|
|
148581
|
-
|
|
148582
|
-
|
|
148583
|
-
|
|
148584
|
-
|
|
148585
|
-
|
|
148586
|
-
|
|
148875
|
+
}
|
|
148876
|
+
/** The camera declined to class this file: `none`, or no `recordType` at all. */
|
|
148877
|
+
function fileCarriesNoClass(nativeTypes) {
|
|
148878
|
+
return nativeTypes.every((type) => type === "none");
|
|
148879
|
+
}
|
|
148880
|
+
/**
|
|
148881
|
+
* Should this day's labels be asked for separately?
|
|
148882
|
+
*
|
|
148883
|
+
* Only when NOTHING in the day carried a class. One file saying `md` is proof
|
|
148884
|
+
* that this camera writes `recordType`, and then the free answer is the
|
|
148885
|
+
* answer — paying 8–9 s to restate it is the cheap-question rule inverted.
|
|
148886
|
+
*/
|
|
148887
|
+
function dayNeedsAlarmLabels(rows) {
|
|
148888
|
+
return rows.length > 0 && rows.every((row) => fileCarriesNoClass(row.nativeTypes));
|
|
148889
|
+
}
|
|
148890
|
+
/**
|
|
148891
|
+
* Attach each window's `alarmType`s to the file whose START it names.
|
|
148892
|
+
*
|
|
148893
|
+
* A row the camera already classed is returned untouched: the file's own
|
|
148894
|
+
* `recordType` is the authority wherever it exists, and a per-window answer
|
|
148895
|
+
* must not narrow it. A window that names no listed file contributes nothing
|
|
148896
|
+
* and is COUNTED — it is never attached to the nearest neighbour, which is how
|
|
148897
|
+
* a surface ends up showing one recording's class on another's row.
|
|
148898
|
+
*/
|
|
148899
|
+
function joinAlarmLabels(rows, windows, timeZone) {
|
|
148900
|
+
const byStamp = /* @__PURE__ */ new Map();
|
|
148901
|
+
for (const window of windows) {
|
|
148902
|
+
const key = window.fileName.slice(-STAMP_LENGTH);
|
|
148903
|
+
const existing = byStamp.get(key);
|
|
148904
|
+
const target = existing ?? [];
|
|
148905
|
+
if (existing === void 0) byStamp.set(key, target);
|
|
148906
|
+
for (const type of window.alarmTypes) if (type !== "" && !target.includes(type)) target.push(type);
|
|
148587
148907
|
}
|
|
148588
|
-
|
|
148908
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
148909
|
+
let matched = 0;
|
|
148910
|
+
return {
|
|
148911
|
+
rows: rows.map((row) => {
|
|
148912
|
+
if (!fileCarriesNoClass(row.nativeTypes)) return row;
|
|
148913
|
+
const subKey = alarmJoinKey(row.startMs, timeZone);
|
|
148914
|
+
const mainKey = row.mainStartMs !== void 0 ? alarmJoinKey(row.mainStartMs, timeZone) : void 0;
|
|
148915
|
+
const key = byStamp.has(subKey) ? subKey : mainKey !== void 0 && byStamp.has(mainKey) ? mainKey : void 0;
|
|
148916
|
+
if (key === void 0) return row;
|
|
148917
|
+
const types = byStamp.get(key);
|
|
148918
|
+
if (types === void 0 || types.length === 0) return row;
|
|
148919
|
+
claimed.add(key);
|
|
148920
|
+
matched += 1;
|
|
148921
|
+
return {
|
|
148922
|
+
...row,
|
|
148923
|
+
nativeTypes: [...types]
|
|
148924
|
+
};
|
|
148925
|
+
}),
|
|
148926
|
+
matched,
|
|
148927
|
+
unmatchedWindows: byStamp.size - claimed.size
|
|
148928
|
+
};
|
|
148589
148929
|
}
|
|
148590
|
-
|
|
148591
|
-
|
|
148592
|
-
|
|
148593
|
-
|
|
148594
|
-
|
|
148595
|
-
|
|
148596
|
-
|
|
148597
|
-
|
|
148598
|
-
|
|
148599
|
-
|
|
148600
|
-
|
|
148601
|
-
|
|
148602
|
-
|
|
148603
|
-
|
|
148604
|
-
|
|
148605
|
-
return {
|
|
148606
|
-
...event,
|
|
148607
|
-
clipKey: file.clipKey,
|
|
148608
|
-
fileName: file.subFileName,
|
|
148609
|
-
playable: true
|
|
148610
|
-
};
|
|
148930
|
+
/** `YYYYMMDDHHMMSS` — 14 digits. */
|
|
148931
|
+
var STAMP_LENGTH = 14;
|
|
148932
|
+
var FORMATTER_BY_ZONE = /* @__PURE__ */ new Map();
|
|
148933
|
+
function formatterFor(timeZone) {
|
|
148934
|
+
const cached = FORMATTER_BY_ZONE.get(timeZone);
|
|
148935
|
+
if (cached !== void 0) return cached;
|
|
148936
|
+
const made = new Intl.DateTimeFormat("en-CA", {
|
|
148937
|
+
timeZone,
|
|
148938
|
+
year: "numeric",
|
|
148939
|
+
month: "2-digit",
|
|
148940
|
+
day: "2-digit",
|
|
148941
|
+
hour: "2-digit",
|
|
148942
|
+
minute: "2-digit",
|
|
148943
|
+
second: "2-digit",
|
|
148944
|
+
hour12: false
|
|
148611
148945
|
});
|
|
148946
|
+
FORMATTER_BY_ZONE.set(timeZone, made);
|
|
148947
|
+
return made;
|
|
148612
148948
|
}
|
|
148613
|
-
/**
|
|
148614
|
-
|
|
148615
|
-
|
|
148949
|
+
/**
|
|
148950
|
+
* The 14-digit tail of the short name a window carries — the file's start in
|
|
148951
|
+
* the CAMERA's wall clock. Never a UTC stamp: 00:30 Rome on the 17th is 22:30
|
|
148952
|
+
* UTC on the 16th, and a UTC key would file it under the wrong day and join it
|
|
148953
|
+
* to nothing.
|
|
148954
|
+
*/
|
|
148955
|
+
function alarmJoinKey(atMs, timeZone) {
|
|
148956
|
+
const parts = new Map(formatterFor(timeZone).formatToParts(new Date(atMs)).map((part) => [part.type, part.value]));
|
|
148957
|
+
return `${parts.get("year") ?? ""}${parts.get("month") ?? ""}${parts.get("day") ?? ""}${normaliseHour(parts.get("hour"))}${parts.get("minute") ?? ""}${parts.get("second") ?? ""}`;
|
|
148958
|
+
}
|
|
148959
|
+
/** `hourCycle: h23` still renders midnight as `24` in some ICU builds. */
|
|
148960
|
+
function normaliseHour(hour) {
|
|
148961
|
+
return hour === "24" ? "00" : hour ?? "";
|
|
148616
148962
|
}
|
|
148617
148963
|
//#endregion
|
|
148618
148964
|
//#region src/clips/reolink-videoclips-provider.ts
|
|
148619
|
-
/**
|
|
148620
|
-
* Which API the ONE source resolved to for a camera — reported on
|
|
148621
|
-
* `ClipSource.via` and on the listing log line.
|
|
148622
|
-
*
|
|
148623
|
-
* The CHOICE is made from what the camera is (`viaFor`); naming it is what
|
|
148624
|
-
* makes "why do these two cameras behave differently" answerable at all.
|
|
148625
|
-
*/
|
|
148626
|
-
var CATALOG_VIA_EVENTS = "events";
|
|
148627
|
-
var CATALOG_VIA_FILES = "files";
|
|
148628
148965
|
function createReolinkVideoclipsProvider(deps) {
|
|
148629
148966
|
/** Last known availability per `deviceId|source`, written by every read. */
|
|
148630
148967
|
const health = /* @__PURE__ */ new Map();
|
|
@@ -148748,7 +149085,7 @@ function createReolinkVideoclipsProvider(deps) {
|
|
|
148748
149085
|
error: result.mainSearchFailed
|
|
148749
149086
|
}
|
|
148750
149087
|
});
|
|
148751
|
-
return result.rows;
|
|
149088
|
+
return await labelDay(device, api, day, result.rows);
|
|
148752
149089
|
});
|
|
148753
149090
|
if (entry.clips.length === 0) emptyDays.push(day);
|
|
148754
149091
|
rows.push(...entry.clips);
|
|
@@ -148776,11 +149113,7 @@ function createReolinkVideoclipsProvider(deps) {
|
|
|
148776
149113
|
days: emptyDays
|
|
148777
149114
|
}
|
|
148778
149115
|
});
|
|
148779
|
-
noteHealth(device.deviceId, CLIP_SOURCE_ONBOARD,
|
|
148780
|
-
state: "index-empty",
|
|
148781
|
-
reason: `The camera’s calendar marks ${emptyDays.length} day(s) with footage that its own index lists no files for: ${emptyDays.join(", ")}.`,
|
|
148782
|
-
catalogAsOf: deps.now()
|
|
148783
|
-
});
|
|
149116
|
+
noteHealth(device.deviceId, CLIP_SOURCE_ONBOARD, indexEmpty(emptyDays));
|
|
148784
149117
|
} else noteHealth(device.deviceId, CLIP_SOURCE_ONBOARD, {
|
|
148785
149118
|
state: "ok",
|
|
148786
149119
|
catalogAsOf: deps.now()
|
|
@@ -148788,140 +149121,55 @@ function createReolinkVideoclipsProvider(deps) {
|
|
|
148788
149121
|
return rows;
|
|
148789
149122
|
};
|
|
148790
149123
|
/**
|
|
148791
|
-
*
|
|
149124
|
+
* Give a day's rows a class when the FILES carried none.
|
|
148792
149125
|
*
|
|
148793
|
-
*
|
|
148794
|
-
*
|
|
148795
|
-
*
|
|
148796
|
-
*
|
|
148797
|
-
*
|
|
148798
|
-
*
|
|
149126
|
+
* The gate is what the day actually said, never what the camera is: a hub
|
|
149127
|
+
* child's files are `recordType: none` on every row (measured), a
|
|
149128
|
+
* standalone's carry `md,people,dog_cat,sched`, and a camera that changes
|
|
149129
|
+
* firmware changes which of those it is without this code learning a new
|
|
149130
|
+
* topology. The cheap question comes first (D54) — on 592 an alarm search
|
|
149131
|
+
* costs 8.2–9.5 s for 1 271 windows to restate labels already on the row.
|
|
148799
149132
|
*
|
|
148800
|
-
*
|
|
148801
|
-
*
|
|
148802
|
-
*
|
|
148803
|
-
* rows still list, each saying why it cannot play.
|
|
149133
|
+
* A refusal costs the LABELS and nothing else. Losing the day because its
|
|
149134
|
+
* class could not be read would be the upgrade destroying the thing it
|
|
149135
|
+
* upgrades — the same rule the MAIN search already lives by.
|
|
148804
149136
|
*/
|
|
148805
|
-
const
|
|
149137
|
+
const labelDay = async (device, api, day, rows) => {
|
|
148806
149138
|
const tags = { deviceId: device.deviceId };
|
|
148807
|
-
if (!
|
|
148808
|
-
const uid = device.uid;
|
|
148809
|
-
if (uid === void 0) {
|
|
148810
|
-
deps.logger.warn("videoclips: no uid for this camera — the hub cannot be asked about it", {
|
|
148811
|
-
tags,
|
|
148812
|
-
meta: {
|
|
148813
|
-
branch: "uid-missing",
|
|
148814
|
-
via: CATALOG_VIA_EVENTS
|
|
148815
|
-
}
|
|
148816
|
-
});
|
|
148817
|
-
noteHealth(device.deviceId, CLIP_SOURCE_ONBOARD, {
|
|
148818
|
-
state: "unreachable",
|
|
148819
|
-
reason: UID_MISSING_REASON
|
|
148820
|
-
});
|
|
148821
|
-
return [];
|
|
148822
|
-
}
|
|
148823
|
-
let api;
|
|
148824
|
-
try {
|
|
148825
|
-
api = await device.getApi();
|
|
148826
|
-
} catch (err) {
|
|
148827
|
-
const reason = err instanceof Error ? err.message : String(err);
|
|
148828
|
-
deps.logger.warn("videoclips: could not reach the hub", {
|
|
148829
|
-
tags,
|
|
148830
|
-
meta: {
|
|
148831
|
-
branch: "camera-refused",
|
|
148832
|
-
via: CATALOG_VIA_EVENTS,
|
|
148833
|
-
error: reason
|
|
148834
|
-
}
|
|
148835
|
-
});
|
|
148836
|
-
noteHealth(device.deviceId, CLIP_SOURCE_ONBOARD, {
|
|
148837
|
-
state: "unreachable",
|
|
148838
|
-
reason
|
|
148839
|
-
});
|
|
148840
|
-
return [];
|
|
148841
|
-
}
|
|
149139
|
+
if (!dayNeedsAlarmLabels(rows)) return rows;
|
|
148842
149140
|
const startedAt = deps.now();
|
|
148843
|
-
let
|
|
148844
|
-
let joined = [];
|
|
149141
|
+
let windows;
|
|
148845
149142
|
try {
|
|
148846
|
-
|
|
148847
|
-
uid,
|
|
149143
|
+
windows = await readAlarmWindows(api, {
|
|
148848
149144
|
channel: device.channel,
|
|
149145
|
+
uid: device.uid,
|
|
148849
149146
|
timeZone: device.timeZone,
|
|
148850
|
-
|
|
148851
|
-
until
|
|
149147
|
+
day
|
|
148852
149148
|
});
|
|
148853
|
-
events = rows;
|
|
148854
|
-
joined = joinEventsToFiles(rows, await readOnboard(device, since, until).catch(() => []));
|
|
148855
149149
|
} catch (err) {
|
|
148856
|
-
|
|
148857
|
-
deps.logger.warn("videoclips: the hub event log refused", {
|
|
149150
|
+
deps.logger.warn("videoclips: the label search refused — the day lists without classes", {
|
|
148858
149151
|
tags,
|
|
148859
149152
|
meta: {
|
|
148860
149153
|
branch: "camera-refused",
|
|
148861
|
-
|
|
148862
|
-
error:
|
|
149154
|
+
day,
|
|
149155
|
+
error: err instanceof Error ? err.message : String(err)
|
|
148863
149156
|
}
|
|
148864
149157
|
});
|
|
148865
|
-
|
|
148866
|
-
state: "unreachable",
|
|
148867
|
-
reason
|
|
148868
|
-
});
|
|
148869
|
-
return [];
|
|
149158
|
+
return rows;
|
|
148870
149159
|
}
|
|
148871
|
-
const
|
|
148872
|
-
deps.logger.info("videoclips: read the
|
|
149160
|
+
const joined = joinAlarmLabels(rows, windows, device.timeZone);
|
|
149161
|
+
deps.logger.info("videoclips: read the classes a day of files does not carry", {
|
|
148873
149162
|
tags,
|
|
148874
149163
|
meta: {
|
|
148875
|
-
|
|
148876
|
-
|
|
148877
|
-
|
|
148878
|
-
|
|
148879
|
-
|
|
149164
|
+
day,
|
|
149165
|
+
windows: windows.length,
|
|
149166
|
+
rows: rows.length,
|
|
149167
|
+
labelled: joined.matched,
|
|
149168
|
+
unmatchedWindows: joined.unmatchedWindows,
|
|
149169
|
+
elapsedMs: deps.now() - startedAt
|
|
148880
149170
|
}
|
|
148881
149171
|
});
|
|
148882
|
-
|
|
148883
|
-
state: "ok",
|
|
148884
|
-
catalogAsOf: deps.now()
|
|
148885
|
-
});
|
|
148886
|
-
return joined;
|
|
148887
|
-
};
|
|
148888
|
-
/**
|
|
148889
|
-
* An events-view row as a `Clip`.
|
|
148890
|
-
*
|
|
148891
|
-
* The id carries the event WINDOW as well as the file, because a file holds
|
|
148892
|
-
* 1–13 windows and two events of one recording must not collapse into one
|
|
148893
|
-
* row. A row with nothing to play carries `playable: false` and its reason,
|
|
148894
|
-
* and offers no thumbnail mint — the hub refused the CoverPreview for
|
|
148895
|
-
* exactly that orphan event, so an offer here would be a tile that spins and
|
|
148896
|
-
* then fails.
|
|
148897
|
-
*/
|
|
148898
|
-
const toEventClip = async (device, row, catalogAsOf) => {
|
|
148899
|
-
const classification = classifyNativeTypes(row.nativeTypes);
|
|
148900
|
-
const still = await deps.hasVouchedThumbnail(device.deviceId, row.clipKey) ? { thumbnail: deps.thumbnailUrl(device.deviceId, row.clipKey) } : row.playable ? { thumbnailMint: deps.thumbnailMintUrl(device.deviceId, row.clipKey) } : { thumbnailUnavailable: { reason: "no-keyframe" } };
|
|
148901
|
-
return {
|
|
148902
|
-
id: mintClipId({
|
|
148903
|
-
source: CLIP_SOURCE_ONBOARD,
|
|
148904
|
-
channel: row.channel,
|
|
148905
|
-
fileName: row.fileName ?? `event:${row.startMs}-${row.endMs}`,
|
|
148906
|
-
window: {
|
|
148907
|
-
startMs: row.startMs,
|
|
148908
|
-
endMs: row.endMs
|
|
148909
|
-
}
|
|
148910
|
-
}),
|
|
148911
|
-
source: CLIP_SOURCE_ONBOARD,
|
|
148912
|
-
kind: classification.kind,
|
|
148913
|
-
timeRange: {
|
|
148914
|
-
startMs: row.startMs,
|
|
148915
|
-
endMs: row.endMs
|
|
148916
|
-
},
|
|
148917
|
-
...classification.labels.length > 0 ? { labels: [...classification.labels] } : {},
|
|
148918
|
-
...classification.behaviours.length > 0 ? { behaviours: [...classification.behaviours] } : {},
|
|
148919
|
-
...classification.nativeTypes.length > 0 ? { nativeTypes: [...classification.nativeTypes] } : {},
|
|
148920
|
-
...still,
|
|
148921
|
-
...catalogAsOf !== void 0 ? { catalogAsOf } : {},
|
|
148922
|
-
playable: row.playable,
|
|
148923
|
-
...row.unplayableReason !== void 0 ? { unplayableReason: row.unplayableReason } : {}
|
|
148924
|
-
};
|
|
149172
|
+
return joined.rows;
|
|
148925
149173
|
};
|
|
148926
149174
|
const toClip = async (device, source, row, catalogAsOf) => {
|
|
148927
149175
|
rowsByKey.set(`${device.deviceId}|${row.clipKey}`, row);
|
|
@@ -148940,6 +149188,7 @@ function createReolinkVideoclipsProvider(deps) {
|
|
|
148940
149188
|
startMs: row.startMs,
|
|
148941
149189
|
endMs: row.endMs
|
|
148942
149190
|
},
|
|
149191
|
+
...row.inProgress === true ? { inProgress: true } : {},
|
|
148943
149192
|
...classification.labels.length > 0 ? { labels: [...classification.labels] } : {},
|
|
148944
149193
|
...classification.behaviours.length > 0 ? { behaviours: [...classification.behaviours] } : {},
|
|
148945
149194
|
...classification.nativeTypes.length > 0 ? { nativeTypes: [...classification.nativeTypes] } : {},
|
|
@@ -148970,36 +149219,26 @@ function createReolinkVideoclipsProvider(deps) {
|
|
|
148970
149219
|
listSources: async ({ deviceId }) => {
|
|
148971
149220
|
const device = await deps.resolveDevice(deviceId);
|
|
148972
149221
|
if (device === null) return [];
|
|
148973
|
-
const via = viaFor(device);
|
|
148974
149222
|
return [{
|
|
148975
149223
|
source: CLIP_SOURCE_ONBOARD,
|
|
148976
149224
|
addonId: REOLINK_ADDON_ID,
|
|
148977
149225
|
label: "Camera storage",
|
|
148978
|
-
|
|
148979
|
-
availability: await resolveAvailability(device, via)
|
|
149226
|
+
availability: await resolveAvailability(device)
|
|
148980
149227
|
}];
|
|
148981
149228
|
},
|
|
148982
149229
|
listClips: async ({ deviceId, since, until, limit }) => {
|
|
148983
149230
|
const device = await deps.resolveDevice(deviceId);
|
|
148984
149231
|
if (device === null) return [];
|
|
148985
149232
|
const tags = { deviceId };
|
|
148986
|
-
const
|
|
148987
|
-
const
|
|
148988
|
-
|
|
148989
|
-
const asOf = health.get(healthKey(deviceId, CLIP_SOURCE_ONBOARD))?.availability.catalogAsOf;
|
|
148990
|
-
return await Promise.all(events.map((row) => toEventClip(device, row, asOf)));
|
|
148991
|
-
})() : await (async () => {
|
|
148992
|
-
const rows = await readOnboard(device, since, until);
|
|
148993
|
-
const asOf = health.get(healthKey(deviceId, CLIP_SOURCE_ONBOARD))?.availability.catalogAsOf;
|
|
148994
|
-
return await Promise.all(rows.toSorted((a, b) => b.startMs - a.startMs).map((row) => toClip(device, CLIP_SOURCE_ONBOARD, row, asOf)));
|
|
148995
|
-
})()).toSorted((a, b) => b.timeRange.startMs - a.timeRange.startMs);
|
|
149233
|
+
const rows = await readOnboard(device, since, until);
|
|
149234
|
+
const asOf = health.get(healthKey(deviceId, CLIP_SOURCE_ONBOARD))?.availability.catalogAsOf;
|
|
149235
|
+
const ordered = (await Promise.all(rows.toSorted((a, b) => b.startMs - a.startMs).map((row) => toClip(device, CLIP_SOURCE_ONBOARD, row, asOf)))).toSorted((a, b) => b.timeRange.startMs - a.timeRange.startMs);
|
|
148996
149236
|
const capped = limit !== void 0 ? ordered.slice(0, limit) : ordered;
|
|
148997
149237
|
const vouched = capped.filter((c) => c.thumbnail !== void 0).length;
|
|
148998
149238
|
deps.logger.info("videoclips: listed a Reolink catalog", {
|
|
148999
149239
|
tags,
|
|
149000
149240
|
meta: {
|
|
149001
149241
|
source: CLIP_SOURCE_ONBOARD,
|
|
149002
|
-
via,
|
|
149003
149242
|
clips: capped.length,
|
|
149004
149243
|
truncated: limit !== void 0 && ordered.length > limit,
|
|
149005
149244
|
unplayable: capped.filter((c) => c.playable === false).length,
|
|
@@ -149008,6 +149247,18 @@ function createReolinkVideoclipsProvider(deps) {
|
|
|
149008
149247
|
availability: health.get(healthKey(deviceId, CLIP_SOURCE_ONBOARD))?.availability.state
|
|
149009
149248
|
}
|
|
149010
149249
|
});
|
|
149250
|
+
const availability = health.get(healthKey(deviceId, CLIP_SOURCE_ONBOARD))?.availability;
|
|
149251
|
+
if (capped.length === 0 && availability !== void 0 && availability.state !== "ok") {
|
|
149252
|
+
deps.logger.warn("videoclips: nothing to list, and the source cannot answer", {
|
|
149253
|
+
tags,
|
|
149254
|
+
meta: {
|
|
149255
|
+
branch: "refused-empty",
|
|
149256
|
+
state: availability.state,
|
|
149257
|
+
reason: availability.reason ?? null
|
|
149258
|
+
}
|
|
149259
|
+
});
|
|
149260
|
+
throw new Error(`videoclips: device ${deviceId} listed no clips, and that is not an empty day — the source is "${availability.state}"` + (availability.reason !== void 0 ? `: ${availability.reason}` : "."));
|
|
149261
|
+
}
|
|
149011
149262
|
return capped;
|
|
149012
149263
|
},
|
|
149013
149264
|
getClipPlayback: async ({ deviceId, clipId, profile }) => {
|
|
@@ -149016,7 +149267,6 @@ function createReolinkVideoclipsProvider(deps) {
|
|
|
149016
149267
|
const device = await deps.resolveDevice(deviceId);
|
|
149017
149268
|
if (device === null) throw new Error(`videoclips: device ${deviceId} is not a Reolink camera`);
|
|
149018
149269
|
if (device.isBattery && device.sleeping && !device.isHubChild) throw new Error(`videoclips: device ${deviceId} is a standalone battery camera and is sleeping — fetching a clip would wake it. Use "Wake and refresh" first.`);
|
|
149019
|
-
if (parsed.fileName.startsWith("event:")) throw new Error(`videoclips: clip ${clipId} is an event with no recording file (no-rec-file) — the hub listed the event, not a clip.`);
|
|
149020
149270
|
const row = rowsByKey.get(`${deviceId}|${clipKeyFor(parsed.channel, parsed.fileName)}`) ?? null;
|
|
149021
149271
|
const wantsMain = profile === "high" && row?.mainFileName !== void 0;
|
|
149022
149272
|
const fileName = wantsMain ? row?.mainFileName ?? parsed.fileName : parsed.fileName;
|
|
@@ -149035,46 +149285,350 @@ function createReolinkVideoclipsProvider(deps) {
|
|
|
149035
149285
|
}
|
|
149036
149286
|
};
|
|
149037
149287
|
/**
|
|
149038
|
-
*
|
|
149039
|
-
*
|
|
149040
|
-
*
|
|
149041
|
-
*
|
|
149042
|
-
*
|
|
149043
|
-
*
|
|
149044
|
-
*
|
|
149045
|
-
*
|
|
149046
|
-
|
|
149047
|
-
|
|
149048
|
-
|
|
149049
|
-
|
|
149050
|
-
|
|
149288
|
+
* What a source is saying right now — MEASURED, never defaulted.
|
|
149289
|
+
*
|
|
149290
|
+
* A listing that already ran is the better answer and wins: `listClips`
|
|
149291
|
+
* asked the whole window and this probe asks one day, so re-deciding from
|
|
149292
|
+
* the narrower question would throw away 618's other nineteen empty days.
|
|
149293
|
+
* With nothing established, the probe runs — and `ok` is only ever returned
|
|
149294
|
+
* because something was really read.
|
|
149295
|
+
*
|
|
149296
|
+
* ## What it costs, per call, and why
|
|
149297
|
+
*
|
|
149298
|
+
* This used to answer `ok` after at most one storage command, and `ok` is
|
|
149299
|
+
* the one state whose list may be read as complete. On the live hub, on the
|
|
149300
|
+
* cold runners a deploy had just produced, that default made 640 (no SD
|
|
149301
|
+
* card) and 618 (an index that lists nothing for days its own calendar
|
|
149302
|
+
* marks) both answer `ok` and then an empty list — the exact lie this line
|
|
149303
|
+
* of work exists to end. So `listSources` pays for its answer:
|
|
149304
|
+
*
|
|
149305
|
+
* - **a standalone battery camera: NOTHING, ever.** No `getApi`, no command,
|
|
149306
|
+
* not even the cheap one — on UDP the login IS the wake. `sleeping`, with
|
|
149307
|
+
* the age of whatever is cached. The gate is `isBattery`, never the
|
|
149308
|
+
* BELIEF `sleeping`: that belief is `state.battery.sleeping ?? false`, so
|
|
149309
|
+
* a slice that has not restored reads as awake, and a probe on it is a
|
|
149310
|
+
* wake nobody asked for.
|
|
149311
|
+
* - **a hub child: one `getDayRecords` through the parent's existing socket**
|
|
149312
|
+
* (65 ms measured on 3628). The child never hears it; the storage question
|
|
149313
|
+
* is the HUB's and is not asked.
|
|
149314
|
+
* - **a mains standalone: `getHddInfoList` (ms) + `getDayRecords`
|
|
149315
|
+
* (38 ms–1.9 s) + ONE day listing of the NEWEST day the calendar claims**
|
|
149316
|
+
* (0.3–6 s, and cache-backed — `serveAndRevalidate`, so a day already
|
|
149317
|
+
* listed costs nothing and a day listed here is free for the `listClips`
|
|
149318
|
+
* that follows). The day listing is what distinguishes `index-empty` from
|
|
149319
|
+
* `ok`, and nothing cheaper can: `no-storage` is the cheap question and it
|
|
149320
|
+
* comes first precisely so a camera with no card never pays the rest.
|
|
149321
|
+
*
|
|
149322
|
+
* The calendar is read for the CURRENT month only. A picker asks "can this
|
|
149323
|
+
* source answer", not "what does it hold since April", and the measured
|
|
149324
|
+
* defect (618) is in the month the operator is looking at.
|
|
149325
|
+
*/
|
|
149326
|
+
async function resolveAvailability(device) {
|
|
149051
149327
|
const known = health.get(healthKey(device.deviceId, CLIP_SOURCE_ONBOARD))?.availability;
|
|
149052
149328
|
if (known !== void 0) return known;
|
|
149053
|
-
|
|
149054
|
-
|
|
149055
|
-
|
|
149056
|
-
|
|
149057
|
-
|
|
149058
|
-
|
|
149059
|
-
|
|
149329
|
+
const availability = await probeAvailability(device);
|
|
149330
|
+
noteHealth(device.deviceId, CLIP_SOURCE_ONBOARD, availability);
|
|
149331
|
+
return availability;
|
|
149332
|
+
}
|
|
149333
|
+
async function probeAvailability(device) {
|
|
149334
|
+
const tags = { deviceId: device.deviceId };
|
|
149335
|
+
if (device.isBattery && !device.isHubChild) {
|
|
149336
|
+
const asOf = newestCachedAsOf(device.deviceId);
|
|
149337
|
+
deps.logger.warn("videoclips: not probing a standalone battery camera — login is the wake", {
|
|
149338
|
+
tags,
|
|
149339
|
+
meta: {
|
|
149340
|
+
branch: "sleeping",
|
|
149341
|
+
believedSleeping: device.sleeping,
|
|
149342
|
+
confirmedAt: asOf
|
|
149343
|
+
}
|
|
149344
|
+
});
|
|
149345
|
+
return {
|
|
149346
|
+
state: "sleeping",
|
|
149347
|
+
reason: asOf === void 0 ? "A read would wake this standalone battery camera. Nothing has been confirmed yet." : "A read would wake this standalone battery camera; showing the catalog as last confirmed.",
|
|
149348
|
+
...asOf !== void 0 ? { catalogAsOf: asOf } : {}
|
|
149349
|
+
};
|
|
149350
|
+
}
|
|
149351
|
+
if (uidIsMissing(device)) {
|
|
149352
|
+
deps.logger.warn("videoclips: no uid for this camera — its catalog cannot be addressed", {
|
|
149353
|
+
tags,
|
|
149354
|
+
meta: {
|
|
149355
|
+
branch: "uid-missing",
|
|
149356
|
+
probe: true
|
|
149357
|
+
}
|
|
149358
|
+
});
|
|
149359
|
+
return {
|
|
149360
|
+
state: "unreachable",
|
|
149361
|
+
reason: UID_MISSING_REASON
|
|
149362
|
+
};
|
|
149363
|
+
}
|
|
149364
|
+
let api;
|
|
149365
|
+
try {
|
|
149366
|
+
api = await device.getApi();
|
|
149367
|
+
} catch (err) {
|
|
149368
|
+
return unreachableFrom(device, "camera-refused", err);
|
|
149369
|
+
}
|
|
149370
|
+
if (!device.isHubChild) {
|
|
149371
|
+
const storage = await readStorageState(api);
|
|
149372
|
+
if (storage.state === "absent") {
|
|
149373
|
+
deps.logger.info("videoclips: no SD card mounted — nothing to list", {
|
|
149374
|
+
tags,
|
|
149375
|
+
meta: {
|
|
149376
|
+
branch: "no-storage",
|
|
149377
|
+
probe: true
|
|
149378
|
+
}
|
|
149379
|
+
});
|
|
149380
|
+
return {
|
|
149381
|
+
state: "no-storage",
|
|
149382
|
+
reason: "The camera reports no mounted storage (HddInfo mount 0)."
|
|
149383
|
+
};
|
|
149384
|
+
}
|
|
149385
|
+
if (storage.state === "unknown") {
|
|
149386
|
+
deps.logger.warn("videoclips: the storage question was not answered", {
|
|
149387
|
+
tags,
|
|
149388
|
+
meta: {
|
|
149389
|
+
branch: "camera-refused",
|
|
149390
|
+
probe: true,
|
|
149391
|
+
error: storage.reason ?? null
|
|
149392
|
+
}
|
|
149393
|
+
});
|
|
149394
|
+
return {
|
|
149395
|
+
state: "unreachable",
|
|
149396
|
+
reason: storage.reason ?? "The camera did not answer the storage question (HddInfo unreadable)."
|
|
149397
|
+
};
|
|
149398
|
+
}
|
|
149399
|
+
}
|
|
149400
|
+
const today = wallClockDayKey(deps.now(), device.timeZone);
|
|
149401
|
+
let calendar;
|
|
149402
|
+
try {
|
|
149403
|
+
calendar = await readDayIndex(api, {
|
|
149404
|
+
channel: device.channel,
|
|
149405
|
+
uid: device.uid,
|
|
149406
|
+
months: [{
|
|
149407
|
+
year: Number(today.slice(0, 4)),
|
|
149408
|
+
month: Number(today.slice(5, 7))
|
|
149409
|
+
}]
|
|
149410
|
+
});
|
|
149411
|
+
} catch (err) {
|
|
149412
|
+
return unreachableFrom(device, "camera-refused", err);
|
|
149413
|
+
}
|
|
149414
|
+
const claimed = [...calendar].toSorted().toReversed();
|
|
149415
|
+
if (claimed.length === 0) return {
|
|
149416
|
+
state: "ok",
|
|
149417
|
+
catalogAsOf: deps.now()
|
|
149418
|
+
};
|
|
149419
|
+
const newest = claimed[0];
|
|
149420
|
+
if (newest === void 0) return {
|
|
149421
|
+
state: "ok",
|
|
149422
|
+
catalogAsOf: deps.now()
|
|
149060
149423
|
};
|
|
149061
|
-
|
|
149424
|
+
try {
|
|
149425
|
+
await deps.cache.serveAndRevalidate(device.deviceId, newest, { closed: newest !== today }, async () => (await listDayRows(api, {
|
|
149426
|
+
channel: device.channel,
|
|
149427
|
+
uid: device.uid,
|
|
149428
|
+
timeZone: device.timeZone,
|
|
149429
|
+
day: newest
|
|
149430
|
+
})).rows);
|
|
149431
|
+
} catch (err) {
|
|
149432
|
+
return unreachableFrom(device, "camera-refused", err);
|
|
149433
|
+
}
|
|
149434
|
+
const emptyClaimed = claimed.filter((day) => deps.cache.peek(device.deviceId, day)?.clips.length === 0);
|
|
149435
|
+
if (emptyClaimed.length > 0) {
|
|
149436
|
+
deps.logger.warn("videoclips: the calendar marks days the index will not list", {
|
|
149437
|
+
tags,
|
|
149438
|
+
meta: {
|
|
149439
|
+
branch: "index-empty",
|
|
149440
|
+
probe: true,
|
|
149441
|
+
days: emptyClaimed
|
|
149442
|
+
}
|
|
149443
|
+
});
|
|
149444
|
+
return indexEmpty(emptyClaimed);
|
|
149445
|
+
}
|
|
149446
|
+
return {
|
|
149447
|
+
state: "ok",
|
|
149448
|
+
catalogAsOf: deps.now()
|
|
149449
|
+
};
|
|
149450
|
+
}
|
|
149451
|
+
function unreachableFrom(device, branch, err) {
|
|
149452
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
149453
|
+
deps.logger.warn("videoclips: the source could not be probed", {
|
|
149454
|
+
tags: { deviceId: device.deviceId },
|
|
149455
|
+
meta: {
|
|
149456
|
+
branch,
|
|
149457
|
+
probe: true,
|
|
149458
|
+
error: reason
|
|
149459
|
+
}
|
|
149460
|
+
});
|
|
149461
|
+
return {
|
|
149062
149462
|
state: "unreachable",
|
|
149063
|
-
reason
|
|
149463
|
+
reason
|
|
149064
149464
|
};
|
|
149465
|
+
}
|
|
149466
|
+
/** When any day of this device's catalog was last confirmed, newest first. */
|
|
149467
|
+
function newestCachedAsOf(deviceId) {
|
|
149468
|
+
let newest;
|
|
149469
|
+
for (const day of deps.cache.daysHeld(deviceId)) {
|
|
149470
|
+
const asOf = deps.cache.peek(deviceId, day)?.catalogAsOf;
|
|
149471
|
+
if (asOf !== void 0 && (newest === void 0 || asOf > newest)) newest = asOf;
|
|
149472
|
+
}
|
|
149473
|
+
return newest;
|
|
149474
|
+
}
|
|
149475
|
+
/** The one wording for "the camera's calendar and its own index disagree". */
|
|
149476
|
+
function indexEmpty(days) {
|
|
149477
|
+
return {
|
|
149478
|
+
state: "index-empty",
|
|
149479
|
+
reason: `The camera’s calendar marks ${days.length} day(s) with footage that its own index lists no files for: ${days.join(", ")}.`,
|
|
149480
|
+
catalogAsOf: deps.now()
|
|
149481
|
+
};
|
|
149482
|
+
}
|
|
149483
|
+
}
|
|
149484
|
+
//#endregion
|
|
149485
|
+
//#region src/clips/clip-refresh.ts
|
|
149486
|
+
/** The settings key, global default and per-device override (D562). */
|
|
149487
|
+
var CLIP_CATALOG_REFRESH_MINUTES_KEY = "clipCatalogRefreshMinutes";
|
|
149488
|
+
/** The settings key, per device only, OFF by default (D562). */
|
|
149489
|
+
var CLIP_CATALOG_FORCED_WAKE_KEY = "clipCatalogForcedWake";
|
|
149490
|
+
/** A day. Past this the catalog's own TTLs are the thing doing the work. */
|
|
149491
|
+
var CLIP_CATALOG_REFRESH_MINUTES_MAX = 1440;
|
|
149492
|
+
/**
|
|
149493
|
+
* How much of the catalog one refresh confirms.
|
|
149494
|
+
*
|
|
149495
|
+
* A day. The listing cost is per DAY (0.3–6 s on a standalone, 267 ms for one
|
|
149496
|
+
* child-day on the hub) and a 20-day window measured 3.6–5.4 s per child, so a
|
|
149497
|
+
* timer that re-confirmed everything would spend the whole budget re-reading
|
|
149498
|
+
* days that cannot change. Older days are immutable and the cache holds them
|
|
149499
|
+
* under their own 24 h TTL.
|
|
149500
|
+
*/
|
|
149501
|
+
var CLIP_CATALOG_REFRESH_WINDOW_MS = 1440 * 6e4;
|
|
149502
|
+
/**
|
|
149503
|
+
* The mode for one camera. Pure, and decided from what the camera IS — never
|
|
149504
|
+
* from a belief about whether it is asleep right now: the gate has to hold for
|
|
149505
|
+
* a camera whose sleep slice has not restored, which reads "awake" and is how
|
|
149506
|
+
* a picker draw once logged into 640 (D561).
|
|
149507
|
+
*/
|
|
149508
|
+
function resolveClipRefreshMode(topology) {
|
|
149509
|
+
if (topology.isHubChild) return "via-hub";
|
|
149510
|
+
if (!topology.isBattery) return "direct";
|
|
149511
|
+
return topology.forcedWake ? "forced-wake" : "mark-stale";
|
|
149512
|
+
}
|
|
149513
|
+
/**
|
|
149514
|
+
* The refresh interval for one camera: the per-device override on top of the
|
|
149515
|
+
* global default, with **reset == unset == the default**.
|
|
149516
|
+
*
|
|
149517
|
+
* Never throws on a bad blob. An invalid value at either level resolves to the
|
|
149518
|
+
* level above it, so a store written by an older release cannot stop the timer
|
|
149519
|
+
* — the same cascade `stationary-settings.ts` uses, for the same reason.
|
|
149520
|
+
*/
|
|
149521
|
+
function resolveClipCatalogRefreshMinutes(globalValue, deviceValue) {
|
|
149522
|
+
return asRefreshMinutes(deviceValue) ?? asRefreshMinutes(globalValue) ?? 30;
|
|
149523
|
+
}
|
|
149524
|
+
function asRefreshMinutes(value) {
|
|
149525
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
149526
|
+
const rounded = Math.round(value);
|
|
149527
|
+
if (rounded === 0) return 0;
|
|
149528
|
+
if (rounded < 5) return null;
|
|
149529
|
+
if (rounded > 1440) return null;
|
|
149530
|
+
return rounded;
|
|
149531
|
+
}
|
|
149532
|
+
/** Is the operator's forced-wake switch on for this camera? */
|
|
149533
|
+
function resolveClipCatalogForcedWake(value) {
|
|
149534
|
+
return value === true;
|
|
149535
|
+
}
|
|
149536
|
+
/**
|
|
149537
|
+
* The timer. `tick()` is the whole surface, so a test drives it from COLD and
|
|
149538
|
+
* the scheduler owns no clock of its own — the addon supplies the interval.
|
|
149539
|
+
*/
|
|
149540
|
+
var ClipCatalogRefreshScheduler = class {
|
|
149541
|
+
deps;
|
|
149542
|
+
/** Last time an interval was SPENT on a camera, successful or not. */
|
|
149543
|
+
lastRunAt = /* @__PURE__ */ new Map();
|
|
149544
|
+
/** Cameras whose refresh has not come back yet. */
|
|
149545
|
+
inFlight = /* @__PURE__ */ new Set();
|
|
149546
|
+
constructor(deps) {
|
|
149547
|
+
this.deps = deps;
|
|
149548
|
+
}
|
|
149549
|
+
async tick() {
|
|
149550
|
+
const now = this.deps.now();
|
|
149551
|
+
const due = this.deps.listTargets().filter((target) => this.isDue(target, now));
|
|
149552
|
+
for (const target of due) await this.run(target, now);
|
|
149553
|
+
}
|
|
149554
|
+
isDue(target, now) {
|
|
149555
|
+
if (target.intervalMinutes <= 0) return false;
|
|
149556
|
+
if (this.inFlight.has(target.deviceId)) return false;
|
|
149557
|
+
const last = this.lastRunAt.get(target.deviceId);
|
|
149558
|
+
if (last === void 0) return true;
|
|
149559
|
+
return now - last >= target.intervalMinutes * 6e4;
|
|
149560
|
+
}
|
|
149561
|
+
async run(target, now) {
|
|
149562
|
+
const tags = { deviceId: target.deviceId };
|
|
149563
|
+
const mode = resolveClipRefreshMode(target);
|
|
149564
|
+
if (this.deps.hostBusy(target.hostKey)) {
|
|
149565
|
+
this.deps.logger.warn("videoclips: catalog refresh deferred — the host is serving a read", {
|
|
149566
|
+
tags,
|
|
149567
|
+
meta: {
|
|
149568
|
+
branch: "deferred-interactive",
|
|
149569
|
+
mode,
|
|
149570
|
+
host: target.hostKey
|
|
149571
|
+
}
|
|
149572
|
+
});
|
|
149573
|
+
return;
|
|
149574
|
+
}
|
|
149575
|
+
if (mode === "mark-stale") {
|
|
149576
|
+
this.deps.markStale(target.deviceId);
|
|
149577
|
+
this.lastRunAt.set(target.deviceId, now);
|
|
149578
|
+
this.deps.logger.info("videoclips: catalog marked stale — a timer cannot read a standalone battery camera", {
|
|
149579
|
+
tags,
|
|
149580
|
+
meta: {
|
|
149581
|
+
branch: "mark-stale",
|
|
149582
|
+
mode,
|
|
149583
|
+
refreshesOn: "onWakeTransition",
|
|
149584
|
+
intervalMinutes: target.intervalMinutes
|
|
149585
|
+
}
|
|
149586
|
+
});
|
|
149587
|
+
return;
|
|
149588
|
+
}
|
|
149589
|
+
this.lastRunAt.set(target.deviceId, now);
|
|
149590
|
+
this.inFlight.add(target.deviceId);
|
|
149065
149591
|
try {
|
|
149066
|
-
if (
|
|
149067
|
-
|
|
149068
|
-
|
|
149069
|
-
|
|
149070
|
-
|
|
149592
|
+
if (mode === "forced-wake") try {
|
|
149593
|
+
await this.deps.wake(target.deviceId);
|
|
149594
|
+
} catch (err) {
|
|
149595
|
+
this.deps.markStale(target.deviceId);
|
|
149596
|
+
this.deps.logger.warn("videoclips: the authorised wake did not bring the camera up — catalog left stale", {
|
|
149597
|
+
tags,
|
|
149598
|
+
meta: {
|
|
149599
|
+
branch: "forced-wake-failed",
|
|
149600
|
+
mode,
|
|
149601
|
+
error: errMessage$1(err)
|
|
149602
|
+
}
|
|
149603
|
+
});
|
|
149604
|
+
return;
|
|
149605
|
+
}
|
|
149606
|
+
await this.deps.refresh(target.deviceId);
|
|
149607
|
+
this.deps.logger.info("videoclips: catalog refreshed", {
|
|
149608
|
+
tags,
|
|
149609
|
+
meta: {
|
|
149610
|
+
branch: "refreshed",
|
|
149611
|
+
mode,
|
|
149612
|
+
elapsedMs: this.deps.now() - now
|
|
149613
|
+
}
|
|
149614
|
+
});
|
|
149071
149615
|
} catch (err) {
|
|
149072
|
-
|
|
149073
|
-
|
|
149074
|
-
|
|
149075
|
-
|
|
149616
|
+
this.deps.markStale(target.deviceId);
|
|
149617
|
+
this.deps.logger.warn("videoclips: catalog refresh failed — the catalog stays as it was", {
|
|
149618
|
+
tags,
|
|
149619
|
+
meta: {
|
|
149620
|
+
branch: "refresh-failed",
|
|
149621
|
+
mode,
|
|
149622
|
+
error: errMessage$1(err)
|
|
149623
|
+
}
|
|
149624
|
+
});
|
|
149625
|
+
} finally {
|
|
149626
|
+
this.inFlight.delete(target.deviceId);
|
|
149076
149627
|
}
|
|
149077
149628
|
}
|
|
149629
|
+
};
|
|
149630
|
+
function errMessage$1(err) {
|
|
149631
|
+
return err instanceof Error ? err.message : String(err);
|
|
149078
149632
|
}
|
|
149079
149633
|
function createClipService(deps) {
|
|
149080
149634
|
const now = deps.now ?? (() => Date.now());
|
|
@@ -149105,23 +149659,11 @@ function createClipService(deps) {
|
|
|
149105
149659
|
};
|
|
149106
149660
|
const mintThumbnail = async (deviceId, clipKey, lane) => {
|
|
149107
149661
|
const device = await deps.resolveDevice(deviceId);
|
|
149108
|
-
if (device === null) return {
|
|
149109
|
-
|
|
149110
|
-
|
|
149111
|
-
};
|
|
149112
|
-
if (device.isBattery && device.sleeping && !device.isHubChild) return {
|
|
149113
|
-
ok: false,
|
|
149114
|
-
reason: "sleeping: a still would wake this standalone battery camera"
|
|
149115
|
-
};
|
|
149116
|
-
if (uidIsMissing(device)) return {
|
|
149117
|
-
ok: false,
|
|
149118
|
-
reason: UID_MISSING_REASON
|
|
149119
|
-
};
|
|
149662
|
+
if (device === null) return refuseStill("unknown-device", `unknown-device: ${deviceId} is not a Reolink camera here`);
|
|
149663
|
+
if (device.isBattery && device.sleeping && !device.isHubChild) return refuseStill("sleeping", "sleeping: a still would wake this standalone battery camera");
|
|
149664
|
+
if (uidIsMissing(device)) return refuseStill("uid-missing", UID_MISSING_REASON);
|
|
149120
149665
|
const row = rowFor(deviceId, clipKey);
|
|
149121
|
-
if (row === null) return
|
|
149122
|
-
ok: false,
|
|
149123
|
-
reason: "no-catalog-row: list this day before asking for its stills"
|
|
149124
|
-
};
|
|
149666
|
+
if (row === null) return refuseStill("no-catalog-row", "no-catalog-row: list this day before asking for its stills");
|
|
149125
149667
|
try {
|
|
149126
149668
|
const bytes = await queue.submit({
|
|
149127
149669
|
host: device.hostKey,
|
|
@@ -149138,10 +149680,7 @@ function createClipService(deps) {
|
|
|
149138
149680
|
});
|
|
149139
149681
|
}
|
|
149140
149682
|
});
|
|
149141
|
-
if (bytes.byteLength === 0) return
|
|
149142
|
-
ok: false,
|
|
149143
|
-
reason: "no-keyframe: the camera returned an empty frame"
|
|
149144
|
-
};
|
|
149683
|
+
if (bytes.byteLength === 0) return refuseStill("no-keyframe", "no-keyframe: the camera returned an empty frame");
|
|
149145
149684
|
await thumbs.put(deviceId, clipKey, bytes);
|
|
149146
149685
|
return {
|
|
149147
149686
|
ok: true,
|
|
@@ -149149,6 +149688,19 @@ function createClipService(deps) {
|
|
|
149149
149688
|
};
|
|
149150
149689
|
} catch (err) {
|
|
149151
149690
|
const reason = err instanceof Error ? err.message : String(err);
|
|
149691
|
+
const deferred = queueRefusal(err);
|
|
149692
|
+
if (deferred !== null) {
|
|
149693
|
+
deps.logger.debug("videoclips: a thumbnail mint was deferred", {
|
|
149694
|
+
tags: { deviceId },
|
|
149695
|
+
meta: {
|
|
149696
|
+
clipKey,
|
|
149697
|
+
lane,
|
|
149698
|
+
code: deferred.code,
|
|
149699
|
+
retryAfterMs: deferred.retryAfterMs
|
|
149700
|
+
}
|
|
149701
|
+
});
|
|
149702
|
+
return deferred;
|
|
149703
|
+
}
|
|
149152
149704
|
deps.logger.warn("videoclips: a thumbnail mint refused", {
|
|
149153
149705
|
tags: { deviceId },
|
|
149154
149706
|
meta: {
|
|
@@ -149158,10 +149710,7 @@ function createClipService(deps) {
|
|
|
149158
149710
|
error: reason
|
|
149159
149711
|
}
|
|
149160
149712
|
});
|
|
149161
|
-
return
|
|
149162
|
-
ok: false,
|
|
149163
|
-
reason
|
|
149164
|
-
};
|
|
149713
|
+
return refuseStill("camera-refused", reason);
|
|
149165
149714
|
}
|
|
149166
149715
|
};
|
|
149167
149716
|
const prepareClip = async (deviceId, clipKey) => {
|
|
@@ -149210,15 +149759,43 @@ function createClipService(deps) {
|
|
|
149210
149759
|
}),
|
|
149211
149760
|
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
149212
149761
|
});
|
|
149762
|
+
const audio = decideClipAudio(downloaded.audio);
|
|
149763
|
+
if (audio.kind === "silent") deps.logger.warn("videoclips: serving a clip with no sound", {
|
|
149764
|
+
tags: { deviceId },
|
|
149765
|
+
meta: {
|
|
149766
|
+
clipKey,
|
|
149767
|
+
branch: audio.reason,
|
|
149768
|
+
audioFormat: audio.format,
|
|
149769
|
+
audioPackets: downloaded.stats.audioPackets,
|
|
149770
|
+
audioBytes: downloaded.stats.audioBytes
|
|
149771
|
+
}
|
|
149772
|
+
});
|
|
149773
|
+
if (downloaded.stats.fpsSource !== "timestamps") deps.logger.warn("videoclips: no measured frame rate for this clip", {
|
|
149774
|
+
tags: { deviceId },
|
|
149775
|
+
meta: {
|
|
149776
|
+
clipKey,
|
|
149777
|
+
branch: "fps-unmeasured",
|
|
149778
|
+
fpsSource: downloaded.stats.fpsSource,
|
|
149779
|
+
fps: downloaded.stats.fps,
|
|
149780
|
+
infoFps: downloaded.stats.infoFps
|
|
149781
|
+
}
|
|
149782
|
+
});
|
|
149213
149783
|
const scratch = await mkdtemp(join$1(tmpdir(), "camstack-clip-mux-"));
|
|
149214
149784
|
try {
|
|
149215
149785
|
const rawPath = join$1(scratch, "clip.h264");
|
|
149786
|
+
const audioPath = join$1(scratch, "clip.aac");
|
|
149216
149787
|
const outPath = join$1(scratch, "clip.mp4");
|
|
149217
149788
|
await writeFile(rawPath, downloaded.annexB);
|
|
149789
|
+
if (audio.kind === "copy") await writeFile(audioPath, audio.data);
|
|
149218
149790
|
const failure = describeMuxFailure(await muxRunner(buildClipMuxArgs({
|
|
149219
149791
|
inputPath: rawPath,
|
|
149220
149792
|
outputPath: outPath,
|
|
149221
|
-
videoType: downloaded.videoType
|
|
149793
|
+
videoType: downloaded.videoType,
|
|
149794
|
+
fps: downloaded.stats.fps,
|
|
149795
|
+
...audio.kind === "copy" ? { audio: {
|
|
149796
|
+
path: audioPath,
|
|
149797
|
+
format: audio.format
|
|
149798
|
+
} } : {}
|
|
149222
149799
|
})));
|
|
149223
149800
|
if (failure !== null) {
|
|
149224
149801
|
deps.logger.warn("videoclips: the clip mux failed", {
|
|
@@ -149240,21 +149817,31 @@ function createClipService(deps) {
|
|
|
149240
149817
|
});
|
|
149241
149818
|
}
|
|
149242
149819
|
};
|
|
149243
|
-
|
|
149244
|
-
|
|
149245
|
-
|
|
149246
|
-
|
|
149247
|
-
|
|
149248
|
-
|
|
149249
|
-
|
|
149250
|
-
|
|
149251
|
-
|
|
149252
|
-
|
|
149253
|
-
served: profile === "high" ? "high" : "low"
|
|
149254
|
-
}),
|
|
149255
|
-
logger: deps.logger
|
|
149820
|
+
const provider = createReolinkVideoclipsProvider({
|
|
149821
|
+
now,
|
|
149822
|
+
cache,
|
|
149823
|
+
resolveDevice: deps.resolveDevice,
|
|
149824
|
+
hasVouchedThumbnail: (deviceId, clipKey) => thumbs.has(deviceId, clipKey),
|
|
149825
|
+
thumbnailUrl: (deviceId, clipKey) => `/addon/${REOLINK_ADDON_ID}/${CLIP_THUMB_PREFIX}/${deviceId}/${clipKey}`,
|
|
149826
|
+
thumbnailMintUrl: (deviceId, clipKey) => `/addon/${REOLINK_ADDON_ID}/${CLIP_THUMB_PREFIX}/${deviceId}/${clipKey}`,
|
|
149827
|
+
preparePlayback: async ({ device, clipKey, profile }) => ({
|
|
149828
|
+
playbackUrl: `/addon/${REOLINK_ADDON_ID}/${CLIP_MEDIA_PREFIX}/${device.deviceId}/${clipKey}.mp4`,
|
|
149829
|
+
served: profile === "high" ? "high" : "low"
|
|
149256
149830
|
}),
|
|
149831
|
+
logger: deps.logger
|
|
149832
|
+
});
|
|
149833
|
+
return {
|
|
149834
|
+
provider,
|
|
149257
149835
|
cache,
|
|
149836
|
+
refreshCatalog: async (deviceId) => {
|
|
149837
|
+
const until = now();
|
|
149838
|
+
await provider.listClips({
|
|
149839
|
+
deviceId,
|
|
149840
|
+
since: until - CLIP_CATALOG_REFRESH_WINDOW_MS,
|
|
149841
|
+
until
|
|
149842
|
+
});
|
|
149843
|
+
},
|
|
149844
|
+
hostBusy: (hostKey) => queue.busy(hostKey),
|
|
149258
149845
|
thumbPrefix: CLIP_THUMB_PREFIX,
|
|
149259
149846
|
mediaPrefix: CLIP_MEDIA_PREFIX,
|
|
149260
149847
|
thumbHandler: createClipThumbHandler({
|
|
@@ -149279,6 +149866,79 @@ function createClipService(deps) {
|
|
|
149279
149866
|
};
|
|
149280
149867
|
}
|
|
149281
149868
|
//#endregion
|
|
149869
|
+
//#region src/clips/clip-refresh-settings.ts
|
|
149870
|
+
/** The section id, so the addon's declaration and this schema cannot drift. */
|
|
149871
|
+
var CLIP_REFRESH_SECTION_ID = "clip-catalog-refresh";
|
|
149872
|
+
/**
|
|
149873
|
+
* The one sentence the interval must always carry.
|
|
149874
|
+
*
|
|
149875
|
+
* It does TWO different things depending on what the camera is, and a knob
|
|
149876
|
+
* that silently means two things on two cameras is how this repo has shipped
|
|
149877
|
+
* settings nobody could reason about. So the difference is in the operator's
|
|
149878
|
+
* own text, at both levels, not only in a record.
|
|
149879
|
+
*/
|
|
149880
|
+
var CLIP_CATALOG_REFRESH_MINUTES_DESCRIPTION = "How often CamStack re-reads what a Reolink camera holds on its own storage. It costs almost nothing on a camera it can reach: a hub child is read through the hub on the session that is already open (measured 65 ms, and the camera itself never hears it), and a mains camera is read on its own socket. On a STANDALONE BATTERY camera the timer cannot read anything at all — logging in is what wakes such a camera — so there it only marks the catalog as ageing, and the real re-read happens the next time the camera wakes up for its own reasons (motion, a stream, something you did). Set 0 to switch the timer off.";
|
|
149881
|
+
var CLIP_CATALOG_FORCED_WAKE_DESCRIPTION = "Let the refresh timer WAKE this camera. Off unless you mean it: on a standalone battery camera every read is a login and every login is a wake, so a 15-minute timer is 96 wakes a day (24 at 60 minutes) against the 1–20 clips a day these cameras actually record — five to a hundred times their normal wake count, and the battery pays for all of it. One interval buys exactly one wake, successful or not. It has no effect on a hub child or a mains camera, which are never woken by this timer.";
|
|
149882
|
+
/**
|
|
149883
|
+
* The addon-level (global) default. Per-camera overrides live on the device,
|
|
149884
|
+
* under the SAME key, and a device that sets nothing — or resets — resolves to
|
|
149885
|
+
* this value (`resolveClipCatalogRefreshMinutes`).
|
|
149886
|
+
*/
|
|
149887
|
+
function buildClipRefreshSettingsSchema() {
|
|
149888
|
+
return { sections: [{
|
|
149889
|
+
id: CLIP_REFRESH_SECTION_ID,
|
|
149890
|
+
title: "Clip catalog refresh",
|
|
149891
|
+
description: "The default for every Reolink camera. Each camera can override it in its own Recording settings; a camera that overrides nothing uses this value.",
|
|
149892
|
+
columns: 1,
|
|
149893
|
+
fields: [{
|
|
149894
|
+
type: "number",
|
|
149895
|
+
key: CLIP_CATALOG_REFRESH_MINUTES_KEY,
|
|
149896
|
+
label: "Refresh interval (min)",
|
|
149897
|
+
description: CLIP_CATALOG_REFRESH_MINUTES_DESCRIPTION,
|
|
149898
|
+
default: 30,
|
|
149899
|
+
min: 0,
|
|
149900
|
+
max: CLIP_CATALOG_REFRESH_MINUTES_MAX,
|
|
149901
|
+
step: 5
|
|
149902
|
+
}]
|
|
149903
|
+
}] };
|
|
149904
|
+
}
|
|
149905
|
+
/**
|
|
149906
|
+
* The per-camera section: the interval override, and — only where it can mean
|
|
149907
|
+
* anything — the forced wake.
|
|
149908
|
+
*
|
|
149909
|
+
* `forcedWake` is a plain persisted switch on purpose. It is NOT a
|
|
149910
|
+
* `device-action-button` and there is no custom action behind it, so nothing
|
|
149911
|
+
* that dispatches device actions (a schedule, an automation, a rule) can spend
|
|
149912
|
+
* a battery camera's wakes; the only way to turn it on is an operator editing
|
|
149913
|
+
* this camera's settings.
|
|
149914
|
+
*/
|
|
149915
|
+
function buildClipRefreshDeviceSection(input) {
|
|
149916
|
+
const forcedWakeApplies = input.isBattery && !input.isHubChild;
|
|
149917
|
+
return [{
|
|
149918
|
+
id: CLIP_REFRESH_SECTION_ID,
|
|
149919
|
+
tab: "recording",
|
|
149920
|
+
title: "Clip catalog refresh",
|
|
149921
|
+
description: "How often this camera’s own clip list is re-read. Leave the interval empty to use the default from the Reolink addon settings.",
|
|
149922
|
+
columns: 1,
|
|
149923
|
+
fields: [{
|
|
149924
|
+
type: "number",
|
|
149925
|
+
key: CLIP_CATALOG_REFRESH_MINUTES_KEY,
|
|
149926
|
+
label: "Refresh interval (min)",
|
|
149927
|
+
description: CLIP_CATALOG_REFRESH_MINUTES_DESCRIPTION,
|
|
149928
|
+
min: 0,
|
|
149929
|
+
max: CLIP_CATALOG_REFRESH_MINUTES_MAX,
|
|
149930
|
+
step: 5
|
|
149931
|
+
}, ...forcedWakeApplies ? [{
|
|
149932
|
+
type: "boolean",
|
|
149933
|
+
key: CLIP_CATALOG_FORCED_WAKE_KEY,
|
|
149934
|
+
label: "Wake this camera to refresh",
|
|
149935
|
+
description: CLIP_CATALOG_FORCED_WAKE_DESCRIPTION,
|
|
149936
|
+
default: false,
|
|
149937
|
+
style: "switch"
|
|
149938
|
+
}] : []]
|
|
149939
|
+
}];
|
|
149940
|
+
}
|
|
149941
|
+
//#endregion
|
|
149282
149942
|
//#region src/intercom-failure-report.ts
|
|
149283
149943
|
/**
|
|
149284
149944
|
* Per-camera talk-back counters, published through `failure-contribution`.
|
|
@@ -154356,6 +155016,73 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
|
|
|
154356
155016
|
* provider still treats a missing `uid` as a dropped branch rather than as
|
|
154357
155017
|
* an empty catalog.
|
|
154358
155018
|
*/
|
|
155019
|
+
/**
|
|
155020
|
+
* Re-read this camera's clip catalog. Set by the addon for every camera it
|
|
155021
|
+
* owns; `null` until it is wired (a redeploy re-registers the device, and
|
|
155022
|
+
* the addon re-wires on `DeviceRegistered` AND `DeviceMetaChanged` — the
|
|
155023
|
+
* same fan-out the email-push resolver needed, for the same reason).
|
|
155024
|
+
*/
|
|
155025
|
+
clipCatalogRefresher = null;
|
|
155026
|
+
setClipCatalogRefresher(refresh) {
|
|
155027
|
+
this.clipCatalogRefresher = refresh;
|
|
155028
|
+
}
|
|
155029
|
+
/**
|
|
155030
|
+
* This camera's OVERRIDE of the clip-refresh interval, or `undefined` when
|
|
155031
|
+
* it overrides nothing — which is what a reset leaves behind too, and is
|
|
155032
|
+
* why the resolver takes `unknown` rather than a number (D562).
|
|
155033
|
+
*/
|
|
155034
|
+
getClipCatalogRefreshMinutes() {
|
|
155035
|
+
return this.config.get("clipCatalogRefreshMinutes");
|
|
155036
|
+
}
|
|
155037
|
+
/** Whether the operator authorised the clip timer to wake this camera. */
|
|
155038
|
+
getClipCatalogForcedWake() {
|
|
155039
|
+
return this.config.get("clipCatalogForcedWake");
|
|
155040
|
+
}
|
|
155041
|
+
/**
|
|
155042
|
+
* The clip refresh the TIMER cannot do.
|
|
155043
|
+
*
|
|
155044
|
+
* On a standalone battery camera a catalog read is a login and a login is
|
|
155045
|
+
* the wake, so the periodic refresh only marks the catalog stale (D562).
|
|
155046
|
+
* This is the other half: the moment the camera confirmed itself awake for
|
|
155047
|
+
* its own reasons — a camera event, a stream, an operator action — is a free
|
|
155048
|
+
* read, and it is the same moment that already warms the stream catalog and
|
|
155049
|
+
* every settings slice. Called from `onWakeTransition`, best-effort, last:
|
|
155050
|
+
* a clip listing must never delay the live-stream catalog the operator is
|
|
155051
|
+
* waiting for.
|
|
155052
|
+
*/
|
|
155053
|
+
async refreshClipCatalogOnWake() {
|
|
155054
|
+
const refresh = this.clipCatalogRefresher;
|
|
155055
|
+
if (refresh === null) {
|
|
155056
|
+
this.ctx.logger.debug("onWakeTransition: no clip catalog refresher wired", {
|
|
155057
|
+
tags: { deviceId: this.id },
|
|
155058
|
+
meta: { branch: "clip-refresher-unwired" }
|
|
155059
|
+
});
|
|
155060
|
+
return;
|
|
155061
|
+
}
|
|
155062
|
+
try {
|
|
155063
|
+
await refresh();
|
|
155064
|
+
} catch (err) {
|
|
155065
|
+
this.ctx.logger.warn("onWakeTransition: the clip catalog refresh failed", {
|
|
155066
|
+
tags: { deviceId: this.id },
|
|
155067
|
+
meta: {
|
|
155068
|
+
branch: "clip-refresh-failed",
|
|
155069
|
+
error: err instanceof Error ? err.message : String(err)
|
|
155070
|
+
}
|
|
155071
|
+
});
|
|
155072
|
+
}
|
|
155073
|
+
}
|
|
155074
|
+
/**
|
|
155075
|
+
* Wake this camera because the OPERATOR authorised the clip timer to
|
|
155076
|
+
* (`clipCatalogForcedWake`, off by default — D562).
|
|
155077
|
+
*
|
|
155078
|
+
* The only path from the timer to a battery camera's radio, and it is the
|
|
155079
|
+
* same forced wake `wakeIfSleeping` already drives for a config button.
|
|
155080
|
+
* Throws when the camera did not come up, so the scheduler can say so and
|
|
155081
|
+
* leave the catalog stale rather than stamping it fresh.
|
|
155082
|
+
*/
|
|
155083
|
+
async wakeForClipCatalogRefresh() {
|
|
155084
|
+
if (!await this.wakeIfSleeping()) throw new Error(`ReolinkCamera ${this.id}: the authorised clip-refresh wake did not bring the camera up`);
|
|
155085
|
+
}
|
|
154359
155086
|
getClipDeviceRef() {
|
|
154360
155087
|
const uid = this.config.get("uid");
|
|
154361
155088
|
return {
|
|
@@ -158616,6 +159343,7 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
|
|
|
158616
159343
|
await this.warmSnapshotOnWake();
|
|
158617
159344
|
await this.alignAuxDevicesState("wake");
|
|
158618
159345
|
await this.refreshParentSettingsSnapshot();
|
|
159346
|
+
await this.refreshClipCatalogOnWake();
|
|
158619
159347
|
}
|
|
158620
159348
|
static PING_INTERVAL_MS = 3e4;
|
|
158621
159349
|
static PING_MAX_FAILURES = 3;
|
|
@@ -159801,7 +160529,11 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
|
|
|
159801
160529
|
}),
|
|
159802
160530
|
...this.buildSessionsTabSections(),
|
|
159803
160531
|
...this.buildEmailPushSection(),
|
|
159804
|
-
...this.buildEmailTabSections()
|
|
160532
|
+
...this.buildEmailTabSections(),
|
|
160533
|
+
...buildClipRefreshDeviceSection({
|
|
160534
|
+
isHubChild: this.isHubChild(),
|
|
160535
|
+
isBattery: this.isBattery
|
|
160536
|
+
})
|
|
159805
160537
|
]
|
|
159806
160538
|
};
|
|
159807
160539
|
const emailSnap = cache?.emailConfigSnapshot;
|
|
@@ -159820,6 +160552,8 @@ var ReolinkCamera = class ReolinkCamera extends BaseDevice {
|
|
|
159820
160552
|
emailRecipient3: emailSnap?.recipients?.[2] ?? "",
|
|
159821
160553
|
emailSendNickname: emailSnap?.sendNickname ?? this.name,
|
|
159822
160554
|
emailScheduleEnabled: emailSnap?.taskEnabled ?? false,
|
|
160555
|
+
clipCatalogRefreshMinutes: this.config.get("clipCatalogRefreshMinutes"),
|
|
160556
|
+
clipCatalogForcedWake: this.config.get("clipCatalogForcedWake") ?? false,
|
|
159823
160557
|
debugGeneral: this.config.get("debugGeneral") ?? false,
|
|
159824
160558
|
debugSocketLogs: this.config.get("debugSocketLogs") ?? [],
|
|
159825
160559
|
motionEnabled: this.config.get("motionEnabled") ?? motionSnap.enabled ?? true,
|
|
@@ -163093,6 +163827,10 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
163093
163827
|
throw new Error(`Reolink: ${reason}`);
|
|
163094
163828
|
}
|
|
163095
163829
|
async onShutdown() {
|
|
163830
|
+
if (this.clipRefreshTimer) {
|
|
163831
|
+
clearInterval(this.clipRefreshTimer);
|
|
163832
|
+
this.clipRefreshTimer = null;
|
|
163833
|
+
}
|
|
163096
163834
|
this.logChannels?.stop();
|
|
163097
163835
|
await this.emailPushServer?.stop().catch(() => {});
|
|
163098
163836
|
await this.autodetectCache.dispose();
|
|
@@ -163103,6 +163841,7 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
163103
163841
|
* logged inside the server and leaves it stopped until the next edit.
|
|
163104
163842
|
*/
|
|
163105
163843
|
async onConfigChanged() {
|
|
163844
|
+
await this.refreshClipRefreshGlobalStore();
|
|
163106
163845
|
await this.emailPushServer?.restart().catch((err) => {
|
|
163107
163846
|
this.ctx.logger.warn("email-push: restart after settings change failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
163108
163847
|
});
|
|
@@ -163122,7 +163861,7 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
163122
163861
|
* for core to select from.
|
|
163123
163862
|
*/
|
|
163124
163863
|
globalSettingsSchema() {
|
|
163125
|
-
return buildEmailPushSettingsSchema(listLanHosts()[0] ?? "127.0.0.1");
|
|
163864
|
+
return { sections: [...buildEmailPushSettingsSchema(listLanHosts()[0] ?? "127.0.0.1").sections, ...buildClipRefreshSettingsSchema().sections] };
|
|
163126
163865
|
}
|
|
163127
163866
|
/**
|
|
163128
163867
|
* Both email-push sections ARE this integration's configuration — one SMTP
|
|
@@ -163169,6 +163908,9 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
163169
163908
|
capability: videoclipsCapability,
|
|
163170
163909
|
provider: this.clipService.provider
|
|
163171
163910
|
});
|
|
163911
|
+
await this.refreshClipRefreshGlobalStore();
|
|
163912
|
+
this.startClipCatalogRefresh(this.clipService);
|
|
163913
|
+
this.wireClipCatalogRefreshers();
|
|
163172
163914
|
await this.serveClipPlanes(this.clipService);
|
|
163173
163915
|
this.ensureEmailPushServer().start().catch((err) => {
|
|
163174
163916
|
this.ctx.logger.warn("email-push: SMTP intake failed to start at init", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
@@ -163181,6 +163923,7 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
163181
163923
|
if (dev instanceof ReolinkCamera) {
|
|
163182
163924
|
const server = this.ensureEmailPushServer();
|
|
163183
163925
|
dev.setEmailPushParamsResolver(() => server.buildCameraSetupParams(dev));
|
|
163926
|
+
this.wireClipCatalogRefreshers();
|
|
163184
163927
|
this.ctx.logger.debug("email-push: resolver wired", {
|
|
163185
163928
|
tags: { deviceId: data.deviceId },
|
|
163186
163929
|
meta: { via }
|
|
@@ -163194,6 +163937,102 @@ var ReolinkProviderAddon = class extends BaseDeviceProvider {
|
|
|
163194
163937
|
}
|
|
163195
163938
|
/** The clip catalog, its thumbnail cache and its two routes (D549). */
|
|
163196
163939
|
clipService = null;
|
|
163940
|
+
clipRefreshTimer = null;
|
|
163941
|
+
/**
|
|
163942
|
+
* The addon store as the refresh timer last saw it.
|
|
163943
|
+
*
|
|
163944
|
+
* `listTargets` is synchronous on purpose — a tick that awaited a settings
|
|
163945
|
+
* read per camera would be a store round-trip per camera per tick — so the
|
|
163946
|
+
* global half of the cascade is mirrored here and refreshed at init and on
|
|
163947
|
+
* every `onConfigChanged`. An empty mirror resolves to the DEFAULT, never to
|
|
163948
|
+
* "off": a settings read that has not happened yet must not switch the timer
|
|
163949
|
+
* off for the whole fleet.
|
|
163950
|
+
*/
|
|
163951
|
+
clipRefreshGlobalStore = {};
|
|
163952
|
+
/**
|
|
163953
|
+
* Give every camera the wake-side refresh.
|
|
163954
|
+
*
|
|
163955
|
+
* Idempotent, and re-run on both device lifecycle events for the reason the
|
|
163956
|
+
* email-push resolver documents: an addon-only redeploy re-registers a
|
|
163957
|
+
* device the hub already knows, which emits `DeviceMetaChanged` and NOT
|
|
163958
|
+
* `DeviceRegistered`, and subscribing to one left every battery camera
|
|
163959
|
+
* unwired.
|
|
163960
|
+
*/
|
|
163961
|
+
wireClipCatalogRefreshers() {
|
|
163962
|
+
const service = this.clipService;
|
|
163963
|
+
if (service === null) return;
|
|
163964
|
+
for (const camera of this.listReolinkCameras()) {
|
|
163965
|
+
const deviceId = camera.getClipDeviceRef().deviceId;
|
|
163966
|
+
camera.setClipCatalogRefresher(async () => {
|
|
163967
|
+
await service.refreshCatalog(deviceId);
|
|
163968
|
+
});
|
|
163969
|
+
}
|
|
163970
|
+
}
|
|
163971
|
+
/** Re-read the global half of the clip-refresh cascade. */
|
|
163972
|
+
async refreshClipRefreshGlobalStore() {
|
|
163973
|
+
try {
|
|
163974
|
+
this.clipRefreshGlobalStore = await this.resolveGlobalStore();
|
|
163975
|
+
} catch (err) {
|
|
163976
|
+
this.ctx.logger.warn("videoclips: could not read the clip refresh default — keeping the last", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
163977
|
+
}
|
|
163978
|
+
}
|
|
163979
|
+
/**
|
|
163980
|
+
* Arm the clip-catalog refresh.
|
|
163981
|
+
*
|
|
163982
|
+
* The scheduler owns no clock: it is ticked, so its rules are testable from
|
|
163983
|
+
* COLD (`clip-refresh.spec.ts` — the discipline D561 cost us). The tick
|
|
163984
|
+
* cadence is the FLOOR of what any camera can be configured to, not the
|
|
163985
|
+
* interval itself; each camera's own interval is decided inside the tick
|
|
163986
|
+
* from the cascade, so changing a setting takes effect without re-arming.
|
|
163987
|
+
*/
|
|
163988
|
+
startClipCatalogRefresh(service) {
|
|
163989
|
+
const scheduler = new ClipCatalogRefreshScheduler({
|
|
163990
|
+
now: () => Date.now(),
|
|
163991
|
+
listTargets: () => this.clipRefreshTargets(),
|
|
163992
|
+
refresh: async (deviceId) => {
|
|
163993
|
+
await service.refreshCatalog(deviceId);
|
|
163994
|
+
},
|
|
163995
|
+
markStale: (deviceId) => {
|
|
163996
|
+
service.cache.markStale(deviceId);
|
|
163997
|
+
},
|
|
163998
|
+
wake: async (deviceId) => {
|
|
163999
|
+
const device = this.ctx.kernel.deviceRegistry?.getById(deviceId);
|
|
164000
|
+
if (!(device instanceof ReolinkCamera)) throw new Error(`clip refresh: device ${String(deviceId)} is not a Reolink camera here`);
|
|
164001
|
+
await device.wakeForClipCatalogRefresh();
|
|
164002
|
+
},
|
|
164003
|
+
hostBusy: (hostKey) => service.hostBusy(hostKey),
|
|
164004
|
+
logger: this.ctx.logger
|
|
164005
|
+
});
|
|
164006
|
+
this.clipRefreshTimer = setInterval(() => {
|
|
164007
|
+
scheduler.tick().catch((err) => {
|
|
164008
|
+
this.ctx.logger.warn("videoclips: the catalog refresh tick failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
164009
|
+
});
|
|
164010
|
+
}, 5 * 6e4);
|
|
164011
|
+
if (typeof this.clipRefreshTimer.unref === "function") this.clipRefreshTimer.unref();
|
|
164012
|
+
}
|
|
164013
|
+
/**
|
|
164014
|
+
* Every Reolink CAMERA this process owns, with its cascade resolved.
|
|
164015
|
+
*
|
|
164016
|
+
* Cameras only — the Home Hub (639) is `type: hub` and never binds
|
|
164017
|
+
* `videoclips` (`deviceTypes: [Camera]`); its catalog IS its children's and
|
|
164018
|
+
* is refreshed per child, on its one session. Accessories are not cameras.
|
|
164019
|
+
*/
|
|
164020
|
+
clipRefreshTargets() {
|
|
164021
|
+
const globalMinutes = this.clipRefreshGlobalStore[CLIP_CATALOG_REFRESH_MINUTES_KEY];
|
|
164022
|
+
const out = [];
|
|
164023
|
+
for (const device of this.listReolinkCameras()) {
|
|
164024
|
+
const ref = device.getClipDeviceRef();
|
|
164025
|
+
out.push({
|
|
164026
|
+
deviceId: ref.deviceId,
|
|
164027
|
+
hostKey: ref.hostKey,
|
|
164028
|
+
isHubChild: ref.isHubChild,
|
|
164029
|
+
isBattery: ref.isBattery,
|
|
164030
|
+
forcedWake: resolveClipCatalogForcedWake(device.getClipCatalogForcedWake()),
|
|
164031
|
+
intervalMinutes: resolveClipCatalogRefreshMinutes(globalMinutes, device.getClipCatalogRefreshMinutes())
|
|
164032
|
+
});
|
|
164033
|
+
}
|
|
164034
|
+
return out;
|
|
164035
|
+
}
|
|
163197
164036
|
/**
|
|
163198
164037
|
* Host the thumbnail and media planes, and never let a host without the
|
|
163199
164038
|
* facility take the addon down with it — a data plane is an enhancement to
|