@trillboards/edge-sdk 0.2.244 → 0.2.246

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/deploy/detector/bench/detect_frames.py +88 -0
  2. package/deploy/detector/bench/openvino_parity.py +152 -0
  3. package/deploy/detector/pyproject.toml +10 -1
  4. package/deploy/detector/tests/test_actor_tracking.py +32 -0
  5. package/deploy/detector/tests/test_actor_tracking_wire.py +11 -0
  6. package/deploy/detector/tests/test_openvino_engines.py +251 -0
  7. package/deploy/detector/tests/test_server.py +43 -0
  8. package/deploy/detector/tests/test_version_stamp.py +17 -4
  9. package/deploy/detector/trillboards_detector/_version.py +2 -2
  10. package/deploy/detector/trillboards_detector/actor_tracking.py +51 -0
  11. package/deploy/detector/trillboards_detector/cli.py +5 -0
  12. package/deploy/detector/trillboards_detector/detections.py +5 -0
  13. package/deploy/detector/trillboards_detector/execution.py +386 -0
  14. package/deploy/detector/trillboards_detector/loader.py +12 -1
  15. package/deploy/detector/trillboards_detector/registry.py +6 -0
  16. package/deploy/detector/trillboards_detector/server.py +41 -0
  17. package/deploy/detector/trillboards_detector/session.py +81 -3
  18. package/deploy/detector/trillboards_detector/track_records.py +113 -0
  19. package/deploy/windows/ci/test-alert-window-field.ps1 +28 -6
  20. package/deploy/windows/ci/test-detector-looks-field.ps1 +31 -7
  21. package/deploy/windows/ci/test-detector-reinstall.ps1 +474 -0
  22. package/deploy/windows/setup-detector.ps1 +122 -29
  23. package/dist/ActorTracking.d.ts +38 -0
  24. package/dist/ActorTracking.d.ts.map +1 -1
  25. package/dist/ActorTracking.js +40 -0
  26. package/dist/ActorTracking.js.map +1 -1
  27. package/dist/AlertClips.d.ts +12 -3
  28. package/dist/AlertClips.d.ts.map +1 -1
  29. package/dist/AlertClips.js +52 -11
  30. package/dist/AlertClips.js.map +1 -1
  31. package/dist/ChannelProber.d.ts +15 -0
  32. package/dist/ChannelProber.d.ts.map +1 -1
  33. package/dist/ChannelProber.js +61 -0
  34. package/dist/ChannelProber.js.map +1 -1
  35. package/dist/CloudSensingManager.d.ts.map +1 -1
  36. package/dist/CloudSensingManager.js +6 -1
  37. package/dist/CloudSensingManager.js.map +1 -1
  38. package/dist/ConnectorStatusClient.d.ts +9 -1
  39. package/dist/ConnectorStatusClient.d.ts.map +1 -1
  40. package/dist/ConnectorStatusClient.js +3 -0
  41. package/dist/ConnectorStatusClient.js.map +1 -1
  42. package/dist/DurableVlmCandidateSpool.d.ts +11 -0
  43. package/dist/DurableVlmCandidateSpool.d.ts.map +1 -1
  44. package/dist/DurableVlmCandidateSpool.js +31 -2
  45. package/dist/DurableVlmCandidateSpool.js.map +1 -1
  46. package/dist/EdgeAgent.js +1 -1
  47. package/dist/FrameGroupingShadow.d.ts +57 -0
  48. package/dist/FrameGroupingShadow.d.ts.map +1 -1
  49. package/dist/FrameGroupingShadow.js +123 -5
  50. package/dist/FrameGroupingShadow.js.map +1 -1
  51. package/dist/LocalDetectorClient.d.ts +25 -1
  52. package/dist/LocalDetectorClient.d.ts.map +1 -1
  53. package/dist/LocalDetectorClient.js +60 -0
  54. package/dist/LocalDetectorClient.js.map +1 -1
  55. package/dist/LocalVideoBuffer.d.ts +14 -2
  56. package/dist/LocalVideoBuffer.d.ts.map +1 -1
  57. package/dist/LocalVideoBuffer.js +23 -3
  58. package/dist/LocalVideoBuffer.js.map +1 -1
  59. package/dist/MainStreamRing.d.ts +246 -0
  60. package/dist/MainStreamRing.d.ts.map +1 -0
  61. package/dist/MainStreamRing.js +436 -0
  62. package/dist/MainStreamRing.js.map +1 -0
  63. package/dist/SensingProfileClient.d.ts +20 -0
  64. package/dist/SensingProfileClient.d.ts.map +1 -1
  65. package/dist/SensingProfileClient.js +13 -1
  66. package/dist/SensingProfileClient.js.map +1 -1
  67. package/dist/VideoSegmentUploader.d.ts +59 -8
  68. package/dist/VideoSegmentUploader.d.ts.map +1 -1
  69. package/dist/VideoSegmentUploader.js +143 -54
  70. package/dist/VideoSegmentUploader.js.map +1 -1
  71. package/dist/VlmCandidateBuffer.d.ts +13 -0
  72. package/dist/VlmCandidateBuffer.d.ts.map +1 -1
  73. package/dist/VlmCandidateBuffer.js.map +1 -1
  74. package/dist/autoSense.d.ts +4 -0
  75. package/dist/autoSense.d.ts.map +1 -1
  76. package/dist/autoSense.js +6 -0
  77. package/dist/autoSense.js.map +1 -1
  78. package/dist/cli.d.ts.map +1 -1
  79. package/dist/cli.js +2 -0
  80. package/dist/cli.js.map +1 -1
  81. package/dist/connectorUpdate.d.ts +9 -0
  82. package/dist/connectorUpdate.d.ts.map +1 -1
  83. package/dist/connectorUpdate.js +22 -13
  84. package/dist/connectorUpdate.js.map +1 -1
  85. package/dist/continuousReview.d.ts +6 -2
  86. package/dist/continuousReview.d.ts.map +1 -1
  87. package/dist/continuousReview.js.map +1 -1
  88. package/dist/detectorBackendRelay.d.ts +24 -0
  89. package/dist/detectorBackendRelay.d.ts.map +1 -0
  90. package/dist/detectorBackendRelay.js +70 -0
  91. package/dist/detectorBackendRelay.js.map +1 -0
  92. package/dist/diagnose.d.ts +1 -1
  93. package/dist/diagnose.js +1 -1
  94. package/dist/localSensing.d.ts +3 -0
  95. package/dist/localSensing.d.ts.map +1 -1
  96. package/dist/localSensing.js +72 -3
  97. package/dist/localSensing.js.map +1 -1
  98. package/dist/pipelineSwitches.d.ts +59 -0
  99. package/dist/pipelineSwitches.d.ts.map +1 -0
  100. package/dist/pipelineSwitches.js +240 -0
  101. package/dist/pipelineSwitches.js.map +1 -0
  102. package/package.json +4 -4
  103. package/retained/RetainedCaptureClient.cjs +37 -2
  104. package/retained/WebsiteAdmissionCaptureClient.cjs +57 -2
  105. package/retained/__tests__/look-reuse.test.cjs +167 -0
  106. package/retained/manager.cjs +28 -2
@@ -33,7 +33,7 @@ from .decode import (
33
33
  )
34
34
  from .detections import Detection, DetectionBatch
35
35
  from .errors import ModelContractError
36
- from .execution import LocalOrtSession
36
+ from .execution import DetectorEngines, LocalOrtSession
37
37
  from .labels import (ClassIndex, ModelVocabulary, PIL_IMAGENET_STRETCH, RGB_HALF_PIXEL_IMAGENET,
38
38
  BGR_BYTES_STRETCH, YOLO_LETTERBOX, resolve_input_preprocessing)
39
39
 
@@ -383,6 +383,7 @@ class OnnxDetector:
383
383
  vocabulary: ModelVocabulary,
384
384
  intra_op_threads: "int | None" = None,
385
385
  accelerator: str = "auto",
386
+ backend_policy=None,
386
387
  ):
387
388
  self.model_path = model_path
388
389
  self.vocabulary = vocabulary
@@ -406,6 +407,16 @@ class OnnxDetector:
406
407
  self._session = LocalOrtSession(ort, model_bytes, opts, accelerator)
407
408
  del model_bytes
408
409
  self.spec = _read_graph_spec(self._session, vocabulary)
410
+ # Plan v7 W8: an RF-DETR graph may also run on OpenVINO (CPU, and the
411
+ # integrated GPU), each only after its parity probe against ORT passed on
412
+ # this host. Under the default policy ("ort") nothing else is built and
413
+ # every frame runs exactly as before. Other layouts stay on ORT.
414
+ self._engines = None
415
+ if backend_policy is not None and self.spec.output_layout == RFDETR_DETS_LABELS:
416
+ self._engines = DetectorEngines(self._session, self._verified_model_bytes, backend_policy,
417
+ self._compare_outputs, threads=intra_op_threads)
418
+ person = [slot for slot, name in vocabulary.slot_names.items() if name == "person"]
419
+ self._person_slot = person[0] if person else None
409
420
 
410
421
  def detect(
411
422
  self,
@@ -428,11 +439,19 @@ class OnnxDetector:
428
439
  input_preprocessing=self.spec.preprocessing,
429
440
  )
430
441
 
431
- with self._lock:
442
+ engine = None
443
+ if self._engines is not None:
432
444
  infer_started = time.perf_counter()
433
- outputs = self._session.run(list(self.spec.output_names), {self.spec.input_name: blob})
445
+ outputs, engine = self._engines.run(list(self.spec.output_names), {self.spec.input_name: blob},
446
+ min_confidence=min_confidence)
434
447
  self.spec.providers = list(self._session.get_providers())
435
448
  infer_ms = (time.perf_counter() - infer_started) * 1000.0
449
+ else:
450
+ with self._lock:
451
+ infer_started = time.perf_counter()
452
+ outputs = self._session.run(list(self.spec.output_names), {self.spec.input_name: blob})
453
+ self.spec.providers = list(self._session.get_providers())
454
+ infer_ms = (time.perf_counter() - infer_started) * 1000.0
436
455
 
437
456
  if layout == RFDETR_DETS_LABELS:
438
457
  batch = postprocess(
@@ -463,12 +482,71 @@ class OnnxDetector:
463
482
  batch.inference_ms = infer_ms
464
483
  batch.total_ms = (time.perf_counter() - started) * 1000.0
465
484
  batch.model_hashes = {self.model_name: self.model_sha256}
485
+ if engine is not None:
486
+ batch.engine = engine
466
487
  return batch
467
488
 
468
489
  @property
469
490
  def acceleration(self):
470
491
  return self._session.acceleration
471
492
 
493
+ def backend_snapshot(self):
494
+ """The `/health` engine view (plan v7 W8), or None for a model that runs on ORT only."""
495
+ return self._engines.snapshot() if self._engines is not None else None
496
+
497
+ def _verified_model_bytes(self) -> bytes:
498
+ """The artifact ORT loaded, re-read and re-hashed: an OTA that replaced the
499
+ file since must not hand OpenVINO a different model under the same name."""
500
+ data = Path(self.model_path).read_bytes()
501
+ if hashlib.sha256(data).hexdigest() != self.model_sha256:
502
+ raise ModelContractError("the model file changed since ORT loaded it; OpenVINO not built")
503
+ return data
504
+
505
+ def _compare_outputs(self, reference, candidate) -> dict:
506
+ """Grade one frame's candidate-engine outputs against ORT's (plan v7 W8).
507
+
508
+ Measured on the shipped artifact and Texas frames (2026-11-16): OpenVINO and ORT
509
+ agree on every query a detection floor of 0.2 or more can keep (person diff
510
+ <= 6.5e-4), and differ on rare sub-0.2 queries (one by 0.088 on 60 frames), so
511
+ parity is graded where detections live:
512
+
513
+ `person_diff`: the largest person-probability gap over queries either engine
514
+ scores at or above PARITY_FLOOR. `score_diff`: the same over every class.
515
+ `mismatches`: (query, class) pairs kept at an operating threshold
516
+ (OPERATING_THRESHOLDS) by one engine and not the other, selected exactly as
517
+ `postprocess` selects. `box_shift`: the largest box-coordinate gap among pairs
518
+ both keep, as a fraction of the frame.
519
+ """
520
+ ref_boxes, ref_logits = reference
521
+ cand_boxes, cand_logits = candidate
522
+ p_ref = _sigmoid(np.asarray(ref_logits)[0])
523
+ p_cand = _sigmoid(np.asarray(cand_logits)[0])
524
+ live = (p_ref >= PARITY_FLOOR) | (p_cand >= PARITY_FLOOR)
525
+ diff = np.where(live, np.abs(p_ref - p_cand), 0.0)
526
+ person = getattr(self, "_person_slot", None)
527
+ person_diff = float(diff[:, person].max()) if person is not None else float(diff.max())
528
+ mismatches, box_shift = 0, 0.0
529
+ n_classes = p_ref.shape[1]
530
+ rb, cb = np.asarray(ref_boxes)[0], np.asarray(cand_boxes)[0]
531
+ for threshold in OPERATING_THRESHOLDS:
532
+ kept = []
533
+ for prob in (p_ref, p_cand):
534
+ flat = prob.reshape(-1)
535
+ order = np.argsort(-flat, kind="stable")[:NUM_SELECT]
536
+ kept.append({int(i) for i in order[flat[order] > threshold]})
537
+ mismatches += len(kept[0] ^ kept[1])
538
+ for index in kept[0] & kept[1]:
539
+ query = index // n_classes
540
+ box_shift = max(box_shift, float(np.abs(rb[query] - cb[query]).max()))
541
+ return {"person_diff": person_diff, "score_diff": float(diff.max()), "mismatches": mismatches,
542
+ "box_shift": box_shift}
543
+
544
+
545
+ #: Where the parity probe grades scores: no shipped request asks below it and OpenVINO serves.
546
+ PARITY_FLOOR = 0.2
547
+ #: The thresholds the connector counts at: its detection floor, the cascade gate, the counts.
548
+ OPERATING_THRESHOLDS = (0.25, 0.2939, 0.5)
549
+
472
550
 
473
551
  def _read_graph_spec(
474
552
  session: "ort.InferenceSession",
@@ -0,0 +1,113 @@
1
+ """Per-track records: what the journal knows about each live actor, beside its identity.
2
+
3
+ ActorTrackerJournal assigns identities. A TrackRecord is the running record one
4
+ identity carries while it is live on one camera: when it was first and last
5
+ OBSERVED (capture time; a predicted box is never an observation), how many frames
6
+ observed it, its newest observed box and score, and one reserved slot for a face
7
+ vector. It is the per-track cache later work reads instead of re-deriving state
8
+ from the frame journal (plan v7 W8 decision, 2026-11-16).
9
+
10
+ Lifetime. A record is written in the same SQLite transaction as the frame that
11
+ observed its actor and deleted in the transaction that ends that actor (listed in
12
+ `endedActors`, or left behind by a new motion epoch). So a record never outlives
13
+ its track, a restart keeps it (it is committed, not cached), and a camera holds at
14
+ most MAX_RECORDS_PER_CAMERA of them.
15
+
16
+ The face slot. Empty everywhere today. Its one intended writer is the face
17
+ watchlist (plan v7 T1), through ActorTrackerJournal.record_face, which stores one
18
+ FaceSlot on a LIVE actor's record and refuses an ended or unknown actor. The face
19
+ vector therefore drops with the track it was read from; nothing here persists a
20
+ face beyond its track. Nothing in this module computes a face vector.
21
+
22
+ Wire (version 1), served as `tracks` beside `tracking` on a tracked /detect
23
+ response, one object per live actor of the camera, oldest first:
24
+
25
+ {"version": 1, "actorId": "pa_...", "kind": "person", "epoch": "te_...",
26
+ "firstSeenAtMs": int, "lastSeenAtMs": int, "frames": int,
27
+ "box": {"x", "y", "width", "height"}, # newest observed box, original-frame pixels
28
+ "confidence": float, # newest observed detector score
29
+ "face": null | {"modelId", "modelSha256", "dims", "vector": [float],
30
+ "frameId", "capturedAtMs", "quality"}}
31
+
32
+ Consumers: src/ActorTracking.ts parseActorTrackRecords (TypeScript twin of this
33
+ shape) and LocalDetectorClient.detect -> DetectResult.tracks.
34
+ """
35
+ from __future__ import annotations
36
+
37
+ import math
38
+ import re
39
+ from dataclasses import dataclass
40
+ from typing import Optional
41
+
42
+ WIRE_VERSION = 1
43
+ MAX_RECORDS_PER_CAMERA = 256
44
+ MAX_FACE_DIMS = 1024
45
+ _ID = re.compile(r"[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}\Z")
46
+ _SHA = re.compile(r"[a-f0-9]{64}\Z")
47
+ _SAFE_INTEGER = 9007199254740991
48
+
49
+
50
+ def _finite(value) -> bool:
51
+ return not isinstance(value, bool) and isinstance(value, (int, float)) and math.isfinite(value)
52
+
53
+
54
+ @dataclass(frozen=True)
55
+ class FaceSlot:
56
+ """One face vector read from a live actor's own crop (plan v7 T1 writes it).
57
+
58
+ vector the face model's embedding exactly as it emits it, `dims` long
59
+ quality the face model's own 0..1 quality for that crop
60
+ frameId / capturedAtMs the frame the crop came from (the actor's camera)
61
+ """
62
+ model_id: str
63
+ model_sha256: str
64
+ vector: tuple
65
+ frame_id: str
66
+ captured_at_ms: int
67
+ quality: float
68
+
69
+ @property
70
+ def dims(self) -> int:
71
+ return len(self.vector)
72
+
73
+ def to_wire(self) -> dict:
74
+ return {"modelId": self.model_id, "modelSha256": self.model_sha256, "dims": self.dims,
75
+ "vector": list(self.vector), "frameId": self.frame_id,
76
+ "capturedAtMs": self.captured_at_ms, "quality": self.quality}
77
+
78
+ @classmethod
79
+ def from_wire(cls, value) -> "FaceSlot":
80
+ if (not isinstance(value, dict)
81
+ or set(value) != {"modelId", "modelSha256", "dims", "vector", "frameId", "capturedAtMs", "quality"}
82
+ or not isinstance(value["modelId"], str) or not _ID.fullmatch(value["modelId"])
83
+ or not isinstance(value["modelSha256"], str) or not _SHA.fullmatch(value["modelSha256"])
84
+ or not isinstance(value["frameId"], str) or not _ID.fullmatch(value["frameId"])
85
+ or type(value["capturedAtMs"]) is not int or not 0 <= value["capturedAtMs"] <= _SAFE_INTEGER
86
+ or not _finite(value["quality"]) or not 0 <= value["quality"] <= 1
87
+ or not isinstance(value["vector"], list) or not 1 <= len(value["vector"]) <= MAX_FACE_DIMS
88
+ or type(value["dims"]) is not int or value["dims"] != len(value["vector"])
89
+ or any(not _finite(v) for v in value["vector"])):
90
+ raise ValueError("Invalid face slot")
91
+ return cls(value["modelId"], value["modelSha256"], tuple(float(v) for v in value["vector"]),
92
+ value["frameId"], value["capturedAtMs"], float(value["quality"]))
93
+
94
+
95
+ @dataclass(frozen=True)
96
+ class TrackRecord:
97
+ """A live actor's running record on one camera (see the module docstring)."""
98
+ actor_id: str
99
+ kind: str
100
+ epoch: str
101
+ first_seen_ms: int
102
+ last_seen_ms: int
103
+ frames: int
104
+ box: tuple # (x, y, width, height), original-frame pixels
105
+ confidence: float
106
+ face: Optional[FaceSlot] = None
107
+
108
+ def to_wire(self) -> dict:
109
+ x, y, width, height = self.box
110
+ return {"version": WIRE_VERSION, "actorId": self.actor_id, "kind": self.kind, "epoch": self.epoch,
111
+ "firstSeenAtMs": self.first_seen_ms, "lastSeenAtMs": self.last_seen_ms,
112
+ "frames": self.frames, "box": {"x": x, "y": y, "width": width, "height": height},
113
+ "confidence": self.confidence, "face": None if self.face is None else self.face.to_wire()}
@@ -16,7 +16,12 @@
16
16
  the alert fired, and nothing else is uploaded;
17
17
  - a look that supports no alert sends no photo, except the camera's one
18
18
  sample per 10 minutes (the run lasts long enough to see two);
19
- - the status beacon reports the feed's free disk and buffer depth.
19
+ - the status beacon reports the feed's free disk and buffer depth;
20
+ - (T2-0) a second camera with no profile, video mode off and ring_stream
21
+ main (configured on Streaming/Channels/102, its main stream derived on
22
+ the PC as Streaming/Channels/101 at 1280x720) is never looked at, fills
23
+ its ring with main-stream segments, and a clip request for its main
24
+ stream is cut from them and uploaded at 1280x720.
20
25
 
21
26
  The install tree is assembled from the built workspace (bin\node.exe is the
22
27
  runner's Node 22, bin\ffmpeg.exe the pinned static build, lib\edge-sdk a
@@ -31,7 +36,8 @@
31
36
  [CmdletBinding()]
32
37
  param(
33
38
  [ValidateRange(5, 30)][double]$ObserveMinutes = 11.5,
34
- [ValidateRange(30, 600)][int]$AlertAfterSeconds = 150
39
+ [ValidateRange(30, 600)][int]$AlertAfterSeconds = 150,
40
+ [ValidateRange(0, 1)][int]$MainCameras = 1
35
41
  )
36
42
  $ErrorActionPreference = 'Stop'
37
43
  Set-StrictMode -Version Latest
@@ -142,6 +148,13 @@ authInternalUsers:
142
148
  - action: api
143
149
  paths:
144
150
  cam:
151
+ srcmain:
152
+ Streaming/Channels/102:
153
+ source: rtsp://127.0.0.1:$rtspPort/cam
154
+ sourceOnDemand: no
155
+ Streaming/Channels/101:
156
+ source: rtsp://127.0.0.1:$rtspPort/srcmain
157
+ sourceOnDemand: no
145
158
  "@ | Set-Content -LiteralPath (Join-Path $rig 'mediamtx.yml') -Encoding utf8
146
159
  $owned.Add((Start-Process -FilePath (Join-Path $rig 'mediamtx.exe') -ArgumentList ('"' + (Join-Path $rig 'mediamtx.yml') + '"') -WorkingDirectory $rig -PassThru -WindowStyle Hidden -RedirectStandardOutput (Join-Path $root 'mediamtx.log') -RedirectStandardError (Join-Path $root 'mediamtx.err.log')))
147
160
  Start-Sleep -Seconds 2
@@ -151,22 +164,30 @@ paths:
151
164
  Copy-Item -LiteralPath $ffmpeg -Destination $cameraFfmpeg
152
165
  $publishArgs = '-hide_banner -loglevel error -re -f lavfi -i testsrc2=size=640x360:rate=4 -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p -g 8 -threads 1 -f rtsp -rtsp_transport tcp rtsp://127.0.0.1:' + $rtspPort + '/cam'
153
166
  $owned.Add((Start-Process -FilePath $cameraFfmpeg -ArgumentList $publishArgs -PassThru -WindowStyle Hidden -RedirectStandardOutput (Join-Path $root 'camera.log') -RedirectStandardError (Join-Path $root 'camera.err.log')))
154
- $deadline = [DateTime]::UtcNow.AddSeconds(30)
167
+ # The main-stream camera's main stream (T2-0): the same pattern at 1280x720.
168
+ $mainArgs = '-hide_banner -loglevel error -re -f lavfi -i testsrc2=size=1280x720:rate=8 -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p -g 16 -threads 1 -f rtsp -rtsp_transport tcp rtsp://127.0.0.1:' + $rtspPort + '/srcmain'
169
+ $owned.Add((Start-Process -FilePath $cameraFfmpeg -ArgumentList $mainArgs -PassThru -WindowStyle Hidden -RedirectStandardOutput (Join-Path $root 'camera-main.log') -RedirectStandardError (Join-Path $root 'camera-main.err.log')))
170
+ $wanted = @('cam', 'Streaming/Channels/102', 'Streaming/Channels/101')
171
+ $deadline = [DateTime]::UtcNow.AddSeconds(45)
155
172
  do {
156
173
  Start-Sleep -Seconds 1
157
174
  $ready = $false
158
- try { $ready = @((Invoke-RestMethod -Uri ('http://127.0.0.1:' + $apiPort + '/v3/paths/list') -TimeoutSec 3).items | Where-Object { $_.name -eq 'cam' -and $_.ready }).Count -eq 1 } catch { }
175
+ try { $ready = @((Invoke-RestMethod -Uri ('http://127.0.0.1:' + $apiPort + '/v3/paths/list') -TimeoutSec 3).items | Where-Object { $wanted -contains $_.name -and $_.ready }).Count -eq $wanted.Count } catch { }
159
176
  } while (-not $ready -and [DateTime]::UtcNow -lt $deadline)
160
- if (-not $ready) { throw 'The RTSP camera never became readable' }
177
+ if (-not $ready) { throw 'The RTSP cameras never became readable' }
161
178
  Note ('camera live at rtsp://127.0.0.1:' + $rtspPort + '/cam')
162
179
 
163
180
  $receipt.phase = 'stand-ins'
164
181
  $readyFile = Join-Path $root 'ready.json'
165
182
  $configPath = Join-Path $installDir 'trillboards.config.json'
166
183
  $systemNode = (Get-Command node.exe -ErrorAction Stop).Source
184
+ # The connector's data root, named so the proof can read the main camera's ring off disk.
185
+ $dataDir = Join-Path $root 'data'
167
186
  $proofArgs = @((Join-Path $PkgRoot 'scripts\alert-window-field-proof.mjs'), '--out', $evidence, '--api-port', $stubPort,
168
187
  '--rtsp', ('rtsp://127.0.0.1:' + $rtspPort + '/cam'), '--write-config', $configPath, '--ready-file', $readyFile,
169
- '--minutes', $ObserveMinutes, '--alert-after-sec', $AlertAfterSeconds, '--ffmpeg', $ffmpeg) | ForEach-Object { '"' + $_ + '"' }
188
+ '--minutes', $ObserveMinutes, '--alert-after-sec', $AlertAfterSeconds, '--ffmpeg', $ffmpeg,
189
+ '--main-cameras', $MainCameras, '--main-rtsp', ('rtsp://127.0.0.1:' + $rtspPort + '/Streaming/Channels/102'),
190
+ '--data-dir', $dataDir) | ForEach-Object { '"' + $_ + '"' }
170
191
  $proof = Start-Process -FilePath $systemNode -ArgumentList ($proofArgs -join ' ') -PassThru -WindowStyle Hidden `
171
192
  -RedirectStandardOutput (Join-Path $root 'proof.log') -RedirectStandardError (Join-Path $root 'proof.err.log')
172
193
  $owned.Add($proof)
@@ -211,6 +232,7 @@ paths:
211
232
  $verdict = Get-Content -LiteralPath $verdictPath -Raw | ConvertFrom-Json
212
233
  $receipt.verdict = $verdict
213
234
  if ($proof.ExitCode -ne 0 -or -not $verdict.passed) { throw ('The field proof failed: ' + (@($verdict.failures) -join '; ')) }
235
+ if ($MainCameras -gt 0) { Note ('main camera: ' + ($verdict.mainCamera | ConvertTo-Json -Compress -Depth 6)) }
214
236
  Note ('PASS: event segment ' + $verdict.event.secondsAfterAlert + ' s after the alert, ' + $verdict.event.durationMs + ' ms of media, ' +
215
237
  $verdict.photos.withheldPhotos + ' photos withheld, ' + $verdict.photos.quietWithPhoto + ' samples, buffer ' + $verdict.videoBuffer.bufferSeconds + ' s')
216
238
  $receipt.phase = 'complete'; $receipt.passed = $true
@@ -13,8 +13,12 @@
13
13
  and ingesting through the REAL retained review parser).
14
14
 
15
15
  Three alert cameras (Texas camera 23's detector-owned lasso, camera 24's
16
- unattended-customer rule with RF person counts, camera 22's RF person fields)
17
- and six cameras with no profile. PASS (proof.json) requires one /detect per
16
+ unattended-customer rule with RF person counts, camera 22's RF person fields),
17
+ six cameras with no profile, and (T2-0) one camera with no profile whose
18
+ ring_stream knob is `main`: configured on Streaming/Channels/102 (the 640x360
19
+ pattern), its main stream derived on the PC as Streaming/Channels/101 (a
20
+ 1280x720 pattern). It must add no look and fill its ring with main-stream
21
+ segments. PASS (proof.json) requires one /detect per
18
22
  look, no Gemma call, two detector looks overlapping across cameras and never
19
23
  more, no persistent RTSP reader on an idle camera's path after warm-up while
20
24
  each still proves a frame on the health heartbeat, the alert cameras' sessions
@@ -31,7 +35,8 @@
31
35
  [CmdletBinding()]
32
36
  param(
33
37
  [ValidateRange(3, 30)][double]$ObserveMinutes = 6,
34
- [ValidateRange(1, 12)][int]$IdleCameras = 6
38
+ [ValidateRange(1, 12)][int]$IdleCameras = 6,
39
+ [ValidateRange(0, 2)][int]$MainCameras = 1
35
40
  )
36
41
  $ErrorActionPreference = 'Stop'
37
42
  Set-StrictMode -Version Latest
@@ -135,6 +140,16 @@ try {
135
140
  $cameraCount = 3 + $IdleCameras
136
141
  # Every camera path re-serves the one published pattern: one encode, N independent RTSP streams.
137
142
  $paths = (1..$cameraCount | ForEach-Object { " cam$($_):`n source: rtsp://127.0.0.1:$rtspPort/src`n sourceOnDemand: no" }) -join "`n"
143
+ # A main-stream camera (T2-0): its substream re-serves the publisher cam1 reads (src, or src1 under
144
+ # the source-identity rewrite), so it adds no reader to a camera path; its main stream is its own
145
+ # larger pattern on srcmain, declared here so the paths block below stays `src` alone.
146
+ if ($MainCameras -gt 0) {
147
+ $subSource = ([regex]::Match($paths, '(?m)^ cam1:\s+source: (\S+)')).Groups[1].Value
148
+ if (-not $subSource) { throw 'Main camera: cam1 names no source to re-serve' }
149
+ $paths += "`n srcmain:`n" + ((1..$MainCameras | ForEach-Object {
150
+ " Streaming/Channels/$($_)02:`n source: $subSource`n sourceOnDemand: no`n" +
151
+ " Streaming/Channels/$($_)01:`n source: rtsp://127.0.0.1:$rtspPort/srcmain`n sourceOnDemand: no" }) -join "`n")
152
+ }
138
153
  @"
139
154
  logLevel: warn
140
155
  rtspAddress: 127.0.0.1:$rtspPort
@@ -167,22 +182,30 @@ $paths
167
182
  Copy-Item -LiteralPath $ffmpeg -Destination $cameraFfmpeg
168
183
  $publishArgs = '-hide_banner -loglevel error -re -f lavfi -i testsrc2=size=640x360:rate=15 -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p -g 30 -threads 1 -f rtsp -rtsp_transport tcp rtsp://127.0.0.1:' + $rtspPort + '/src'
169
184
  $owned.Add((Start-Process -FilePath $cameraFfmpeg -ArgumentList $publishArgs -PassThru -WindowStyle Hidden -RedirectStandardOutput (Join-Path $root 'camera.log') -RedirectStandardError (Join-Path $root 'camera.err.log')))
185
+ if ($MainCameras -gt 0) {
186
+ # The main stream: the same pattern at 1280x720, what the recorder must copy into the ring.
187
+ $mainArgs = '-hide_banner -loglevel error -re -f lavfi -i testsrc2=size=1280x720:rate=15 -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p -g 30 -threads 1 -f rtsp -rtsp_transport tcp rtsp://127.0.0.1:' + $rtspPort + '/srcmain'
188
+ $owned.Add((Start-Process -FilePath $cameraFfmpeg -ArgumentList $mainArgs -PassThru -WindowStyle Hidden -RedirectStandardOutput (Join-Path $root 'camera-main.log') -RedirectStandardError (Join-Path $root 'camera-main.err.log')))
189
+ }
170
190
  $deadline = [DateTime]::UtcNow.AddSeconds(45)
171
191
  do {
172
192
  Start-Sleep -Seconds 1
173
193
  $ready = 0
174
- try { $ready = @((Invoke-RestMethod -Uri ('http://127.0.0.1:' + $apiPort + '/v3/paths/list') -TimeoutSec 3).items | Where-Object { $_.name -like 'cam*' -and $_.ready }).Count } catch { }
175
- } while ($ready -lt $cameraCount -and [DateTime]::UtcNow -lt $deadline)
176
- if ($ready -lt $cameraCount) { throw ('Only ' + $ready + ' of ' + $cameraCount + ' RTSP cameras became readable') }
194
+ try { $ready = @((Invoke-RestMethod -Uri ('http://127.0.0.1:' + $apiPort + '/v3/paths/list') -TimeoutSec 3).items | Where-Object { ($_.name -like 'cam*' -or $_.name -like 'Streaming/*') -and $_.ready }).Count } catch { }
195
+ } while ($ready -lt ($cameraCount + 2 * $MainCameras) -and [DateTime]::UtcNow -lt $deadline)
196
+ if ($ready -lt ($cameraCount + 2 * $MainCameras)) { throw ('Only ' + $ready + ' of ' + ($cameraCount + 2 * $MainCameras) + ' RTSP camera paths became readable') }
177
197
  Note ($cameraCount.ToString() + ' cameras live at rtsp://127.0.0.1:' + $rtspPort + '/cam1..cam' + $cameraCount)
178
198
 
179
199
  $receipt.phase = 'stand-ins'
180
200
  $readyFile = Join-Path $root 'ready.json'
181
201
  $configPath = Join-Path $installDir 'trillboards.config.json'
182
202
  $systemNode = (Get-Command node.exe -ErrorAction Stop).Source
203
+ # The connector's data root, named so the proof can read each main camera's ring off disk.
204
+ $dataDir = Join-Path $root 'data'
183
205
  $proofArgs = @((Join-Path $PkgRoot 'scripts\detector-looks-field-proof.mjs'), '--out', $evidence, '--api-port', $stubPort,
184
206
  '--rtsp-base', ('rtsp://127.0.0.1:' + $rtspPort + '/'), '--mediamtx-api', ('http://127.0.0.1:' + $apiPort),
185
- '--idle-cameras', $IdleCameras, '--write-config', $configPath, '--ready-file', $readyFile,
207
+ '--idle-cameras', $IdleCameras, '--main-cameras', $MainCameras, '--data-dir', $dataDir,
208
+ '--write-config', $configPath, '--ready-file', $readyFile,
186
209
  '--minutes', $ObserveMinutes) | ForEach-Object { '"' + $_ + '"' }
187
210
  $proof = Start-Process -FilePath $systemNode -ArgumentList ($proofArgs -join ' ') -PassThru -WindowStyle Hidden `
188
211
  -RedirectStandardOutput (Join-Path $root 'proof.log') -RedirectStandardError (Join-Path $root 'proof.err.log')
@@ -248,6 +271,7 @@ $paths
248
271
  Where-Object { $_ -match '^\[idle cam\d+\] (RTSP down|error: Camera not opened)' })
249
272
  $receipt.idleCameraDownLines = $flaps.Count
250
273
  if ($flaps.Count -gt 0) { throw ('An idle camera read as down while handing its session back: ' + $flaps[0]) }
274
+ if ($MainCameras -gt 0) { Note ('main cameras: ' + ($verdict.mainCameras | ConvertTo-Json -Compress -Depth 6)) }
251
275
  Note ('PASS: ' + ($verdict.cameras | ConvertTo-Json -Compress -Depth 4) + ' overlap ' + ($verdict.overlap | ConvertTo-Json -Compress) +
252
276
  ' load ' + ($receipt['load'] | ConvertTo-Json -Compress))
253
277
  $receipt.phase = 'complete'; $receipt.passed = $true