@trillboards/edge-sdk 0.2.243 → 0.2.245

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 (82) hide show
  1. package/deploy/windows/build-windows.ps1 +17 -1
  2. package/deploy/windows/ci/test-alert-window-field.ps1 +28 -6
  3. package/deploy/windows/ci/test-detector-looks-field.ps1 +31 -7
  4. package/deploy/windows/ci/test-private-live-view-staging.ps1 +43 -0
  5. package/deploy/windows/ci/test-stop-existing-processes.ps1 +58 -0
  6. package/deploy/windows/e2e/test-headless-principal.ps1 +24 -2
  7. package/deploy/windows/stage-private-live-view.ps1 +59 -0
  8. package/deploy/windows/stop-existing.ps1 +6 -5
  9. package/deploy/windows/stop-local-ai.ps1 +4 -0
  10. package/dist/AlertClips.d.ts +8 -1
  11. package/dist/AlertClips.d.ts.map +1 -1
  12. package/dist/AlertClips.js +29 -3
  13. package/dist/AlertClips.js.map +1 -1
  14. package/dist/CctvLiveViewCoordinator.d.ts +123 -0
  15. package/dist/CctvLiveViewCoordinator.d.ts.map +1 -0
  16. package/dist/CctvLiveViewCoordinator.js +393 -0
  17. package/dist/CctvLiveViewCoordinator.js.map +1 -0
  18. package/dist/ChannelProber.d.ts +15 -0
  19. package/dist/ChannelProber.d.ts.map +1 -1
  20. package/dist/ChannelProber.js +61 -0
  21. package/dist/ChannelProber.js.map +1 -1
  22. package/dist/ConnectorStatusClient.d.ts +9 -1
  23. package/dist/ConnectorStatusClient.d.ts.map +1 -1
  24. package/dist/ConnectorStatusClient.js +3 -0
  25. package/dist/ConnectorStatusClient.js.map +1 -1
  26. package/dist/EdgeAgent.js +1 -1
  27. package/dist/LiveViewControlHttp.d.ts +10 -0
  28. package/dist/LiveViewControlHttp.d.ts.map +1 -0
  29. package/dist/LiveViewControlHttp.js +84 -0
  30. package/dist/LiveViewControlHttp.js.map +1 -0
  31. package/dist/LiveViewOwnedSenderScope.d.ts +38 -0
  32. package/dist/LiveViewOwnedSenderScope.d.ts.map +1 -0
  33. package/dist/LiveViewOwnedSenderScope.js +88 -0
  34. package/dist/LiveViewOwnedSenderScope.js.map +1 -0
  35. package/dist/LiveViewProducerSignaling.d.ts +37 -0
  36. package/dist/LiveViewProducerSignaling.d.ts.map +1 -0
  37. package/dist/LiveViewProducerSignaling.js +97 -0
  38. package/dist/LiveViewProducerSignaling.js.map +1 -0
  39. package/dist/LiveViewRelayBootstrap.d.ts +26 -0
  40. package/dist/LiveViewRelayBootstrap.d.ts.map +1 -0
  41. package/dist/LiveViewRelayBootstrap.js +85 -0
  42. package/dist/LiveViewRelayBootstrap.js.map +1 -0
  43. package/dist/MainStreamRing.d.ts +246 -0
  44. package/dist/MainStreamRing.d.ts.map +1 -0
  45. package/dist/MainStreamRing.js +436 -0
  46. package/dist/MainStreamRing.js.map +1 -0
  47. package/dist/SensingProfileClient.d.ts +20 -0
  48. package/dist/SensingProfileClient.d.ts.map +1 -1
  49. package/dist/SensingProfileClient.js +10 -1
  50. package/dist/SensingProfileClient.js.map +1 -1
  51. package/dist/VideoSegmentUploader.d.ts +45 -1
  52. package/dist/VideoSegmentUploader.d.ts.map +1 -1
  53. package/dist/VideoSegmentUploader.js +112 -19
  54. package/dist/VideoSegmentUploader.js.map +1 -1
  55. package/dist/autoSense.d.ts +5 -0
  56. package/dist/autoSense.d.ts.map +1 -1
  57. package/dist/autoSense.js +55 -2
  58. package/dist/autoSense.js.map +1 -1
  59. package/dist/cli.d.ts.map +1 -1
  60. package/dist/cli.js +2 -0
  61. package/dist/cli.js.map +1 -1
  62. package/dist/connectorUpdate.d.ts +9 -0
  63. package/dist/connectorUpdate.d.ts.map +1 -1
  64. package/dist/connectorUpdate.js +22 -13
  65. package/dist/connectorUpdate.js.map +1 -1
  66. package/dist/diagnose.d.ts +1 -1
  67. package/dist/diagnose.js +1 -1
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +6 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/localSensing.d.ts.map +1 -1
  73. package/dist/localSensing.js +3 -0
  74. package/dist/localSensing.js.map +1 -1
  75. package/dist/sensingRunMode.d.ts +1 -0
  76. package/dist/sensingRunMode.d.ts.map +1 -1
  77. package/dist/sensingRunMode.js.map +1 -1
  78. package/dist/windowsLiveView.d.ts +57 -0
  79. package/dist/windowsLiveView.d.ts.map +1 -0
  80. package/dist/windowsLiveView.js +180 -0
  81. package/dist/windowsLiveView.js.map +1 -0
  82. package/package.json +2 -2
@@ -45,6 +45,12 @@
45
45
  workflow reads the pin from here rather than restating
46
46
  it, so the two can never drift.
47
47
 
48
+
49
+ .PARAMETER PrivateLiveViewArchive
50
+ Optional exact worker bundle for a private lab build.
51
+ .PARAMETER PrivateLiveViewSha256
52
+ SHA-256 of that archive before any extraction.
53
+
48
54
  .OUTPUTS
49
55
  Prints the inner installer path on the last line:
50
56
  <pkgroot>\deploy\windows\dist-installer\inner\TrillboardsEdgeSetup-core-<ver>-x64.exe
@@ -55,12 +61,18 @@ param(
55
61
  [switch]$Offline,
56
62
  [switch]$SkipNsis,
57
63
  [string]$FfmpegPath = "",
58
- [switch]$PrintFfmpegPin
64
+ [switch]$PrintFfmpegPin,
65
+ [string]$PrivateLiveViewArchive = "",
66
+ [string]$PrivateLiveViewSha256 = ""
59
67
  )
60
68
 
61
69
  $ErrorActionPreference = "Stop"
62
70
  Set-StrictMode -Version Latest
63
71
 
72
+ if ([bool]$PrivateLiveViewArchive -ne [bool]$PrivateLiveViewSha256) {
73
+ throw "A private live-view archive and its SHA-256 are required together."
74
+ }
75
+
64
76
  # ─── Pinned static ffmpeg (win32-x64) — eugeneware/ffmpeg-static b6.0 ──────────
65
77
  # Same upstream + release the macOS build pins, so behavior matches. SHA-256
66
78
  # verified after download; refuse to bundle an unverified binary.
@@ -119,6 +131,10 @@ New-Item -ItemType Directory -Force -Path "$Payload\lib\edge-sdk" | Out-Null
119
131
  Copy-Item -Recurse -Force "$PkgRoot\dist" "$Payload\lib\edge-sdk\dist"
120
132
  Copy-RetainedRuntime -Source "$PkgRoot\retained" -Destination "$Payload\lib\edge-sdk\retained"
121
133
  Copy-Item -Force "$PkgRoot\package.json" "$Payload\lib\edge-sdk\package.json"
134
+ if ($PrivateLiveViewArchive) {
135
+ $liveViewStage = @{ Archive = $PrivateLiveViewArchive; ExpectedSha256 = $PrivateLiveViewSha256; SdkPayload = "$Payload\lib\edge-sdk" }
136
+ & "$Here\stage-private-live-view.ps1" @liveViewStage
137
+ }
122
138
 
123
139
  # ─── 3. Runtime node_modules subset (NO heavy native stack) ────────────────────
124
140
  # robocopy /E mirrors the tree; /XD prunes the heavy/native/dev packages cloud-
@@ -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
@@ -0,0 +1,43 @@
1
+ param([string]$Stager = (Join-Path $PSScriptRoot "..\stage-private-live-view.ps1"))
2
+ $ErrorActionPreference = 'Stop'
3
+ $root = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd('\') + '\'
4
+ $temp = (New-Item -ItemType Directory -Path (Join-Path $root ('sense-stage-lab-' + [guid]::NewGuid().ToString('N')))).FullName
5
+ try {
6
+ $inputs = (New-Item -ItemType Directory -Path (Join-Path $temp 'input')).FullName
7
+ $output = (New-Item -ItemType Directory -Path (Join-Path $temp 'sdk')).FullName
8
+ $entry = Join-Path $inputs 'platform.cjs'
9
+ Set-Content -LiteralPath $entry -Value 'module.exports.createPlatform = () => undefined;'
10
+ $entryHash = (Get-FileHash -LiteralPath $entry).Hash.ToLowerInvariant()
11
+ @{ apiVersion = 1; entrySha256 = $entryHash } | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $inputs 'platform.json')
12
+ Set-Content -LiteralPath (Join-Path $inputs 'owned-relay.node') -Value 'test fixture bytes'
13
+ $archive = Join-Path $temp 'fixture.zip'
14
+ Compress-Archive -Path (Join-Path $inputs '*') -DestinationPath $archive
15
+ $sha = (Get-FileHash -LiteralPath $archive).Hash
16
+ if (-not (Test-Path -LiteralPath $Stager)) { throw 'The normal Windows builder has no private media stager.' }
17
+ $rejected = $false
18
+ try { & $Stager -Archive $archive -ExpectedSha256 ('0' * 64) -SdkPayload $output }
19
+ catch { $rejected = $_.Exception.Message -match 'digest' }
20
+ if (-not $rejected -or (Test-Path -LiteralPath (Join-Path $output 'live-view'))) { throw 'Wrong archive digest was accepted' }
21
+ $bad = Join-Path $temp 'unsafe.zip'
22
+ Copy-Item -LiteralPath $archive -Destination $bad
23
+ $zip = [IO.Compression.ZipFile]::Open($bad, [IO.Compression.ZipArchiveMode]::Update)
24
+ try { $null = $zip.CreateEntry('../outside.txt') }
25
+ finally { $zip.Dispose() }
26
+ $rejected = $false
27
+ try { & $Stager -Archive $bad -ExpectedSha256 (Get-FileHash -LiteralPath $bad).Hash -SdkPayload $output }
28
+ catch { $rejected = $_.Exception.Message -match 'Unsafe private live-view archive entry' }
29
+ if (-not $rejected -or (Test-Path -LiteralPath (Join-Path $output 'live-view'))) { throw 'Unsafe archive path was accepted' }
30
+ & $Stager -Archive $archive -ExpectedSha256 $sha -SdkPayload $output
31
+ $staged = Join-Path $output 'live-view'
32
+ foreach ($file in @('platform.cjs', 'platform.json', 'owned-relay.node')) {
33
+ $from = (Get-FileHash -LiteralPath (Join-Path $inputs $file)).Hash
34
+ $to = (Get-FileHash -LiteralPath (Join-Path $staged $file)).Hash
35
+ if ($from -ne $to) { throw 'Windows builder changed the pinned bundle bytes' }
36
+ }
37
+ Write-Output 'PASS wrong hash and unsafe paths refused before extraction, exact bundle staged'
38
+ } finally {
39
+ $resolved = [IO.Path]::GetFullPath($temp)
40
+ if (-not $resolved.StartsWith($root, [StringComparison]::OrdinalIgnoreCase) -or
41
+ (Split-Path -Leaf $resolved) -notmatch '^sense-stage-lab-[a-f0-9]{32}$') { throw 'Unexpected test directory' }
42
+ Remove-Item -LiteralPath $resolved -Recurse -Force
43
+ }
@@ -0,0 +1,58 @@
1
+ [CmdletBinding()]
2
+ param([string]$StopScriptPath = (Join-Path $PSScriptRoot '..\stop-existing.ps1'))
3
+
4
+ Set-StrictMode -Version Latest
5
+ $ErrorActionPreference = 'Stop'
6
+ $stopScript = [scriptblock]::Create((Get-Content -LiteralPath $StopScriptPath -Raw))
7
+
8
+ function Test-ProcessCounts([int]$OwnedCount) {
9
+ $root = Join-Path ([IO.Path]::GetTempPath()) ('stop-existing-test-' + [Guid]::NewGuid().ToString('N'))
10
+ $bin = Join-Path $root 'bin'
11
+ $null = New-Item -Path $bin -ItemType Directory
12
+ try {
13
+ $ownedIds = @(for ($i = 0; $i -lt $OwnedCount; $i++) { 99101 + $i })
14
+ $script:caseState = @{
15
+ Queries = 0
16
+ Stopped = [Collections.Generic.List[int]]::new()
17
+ Owned = @(foreach ($id in $ownedIds) {
18
+ [pscustomobject]@{ ProcessId = $id; Name = 'node.exe'; CommandLine = 'node cli.js';
19
+ ExecutablePath = (Join-Path $bin 'node.exe') }
20
+ })
21
+ }
22
+ for ($i = 0; $i -lt $OwnedCount; $i++) {
23
+ $name = @('node.exe', 'ffmpeg.exe')[$i]
24
+ [IO.File]::WriteAllText((Join-Path $bin $name), 'unlocked fixture binary')
25
+ }
26
+
27
+ function Get-CimInstance {
28
+ [CmdletBinding()]
29
+ param([string]$ClassName)
30
+ if ($ClassName -ne 'Win32_Process') { throw "Unexpected query $ClassName" }
31
+ $script:caseState.Queries++
32
+ [pscustomobject]@{ ProcessId = 99301; Name = 'node.exe'; CommandLine = 'node unrelated.js';
33
+ ExecutablePath = (Join-Path ([IO.Path]::GetTempPath()) 'unrelated\node.exe') }
34
+ if ($script:caseState.Queries -le 2) { $script:caseState.Owned }
35
+ }
36
+ function Stop-Process {
37
+ [CmdletBinding()]
38
+ param([int]$Id, [switch]$Force)
39
+ if ($Id -notin $ownedIds -or $Force) { throw "Unexpected stop of process $Id" }
40
+ $script:caseState.Stopped.Add($Id)
41
+ }
42
+ function Disable-ScheduledTask { [CmdletBinding()] param([string]$TaskName) }
43
+ function Stop-ScheduledTask { [CmdletBinding()] param([string]$TaskName) }
44
+ function Start-Sleep { param([int]$Milliseconds) }
45
+
46
+ & $stopScript -InstallDir $root
47
+ if (($script:caseState.Stopped -join ',') -ne ($ownedIds -join ',') -or $script:caseState.Queries -lt 3) {
48
+ throw "Wrong owned process stop or recheck for count $OwnedCount"
49
+ }
50
+ Write-Host "PASS strict cleanup with $OwnedCount owned processes and binaries"
51
+ } finally {
52
+ foreach ($file in @(Get-ChildItem -LiteralPath $bin -File)) { $file.Delete() }
53
+ [IO.Directory]::Delete($bin)
54
+ [IO.Directory]::Delete($root)
55
+ }
56
+ }
57
+
58
+ foreach ($count in @(0, 1, 2)) { Test-ProcessCounts $count }
@@ -300,8 +300,30 @@ try {
300
300
  # profile. On a customer machine this is always true: the installing user has
301
301
  # logged on. Without it Arm D would be measuring first-logon profile creation.
302
302
  Log ' materialising the probe user profile'
303
- Start-Process -FilePath $env:ComSpec -ArgumentList '/c', 'exit' -Credential $cred -LoadUserProfile `
304
- -WorkingDirectory 'C:\' -Wait -ErrorAction Stop
303
+ # Own the creation handle while this intentionally short-lived process exits.
304
+ # Start-Process -Wait failed after exit in native CI, before any headless arm.
305
+ # WaitForExit uses this Process object's handle rather than rediscovering a PID.
306
+ $profileStartInfo = New-Object System.Diagnostics.ProcessStartInfo
307
+ $profileStartInfo.FileName = $env:ComSpec
308
+ $profileStartInfo.Arguments = '/c exit 0'
309
+ $profileStartInfo.WorkingDirectory = 'C:\'
310
+ $profileStartInfo.UseShellExecute = $false
311
+ $profileStartInfo.CreateNoWindow = $true
312
+ $profileStartInfo.LoadUserProfile = $true
313
+ $profileStartInfo.UserName = $cred.GetNetworkCredential().UserName
314
+ $profileStartInfo.Domain = $cred.GetNetworkCredential().Domain
315
+ $profileStartInfo.Password = $cred.Password
316
+ $profileProcess = New-Object System.Diagnostics.Process
317
+ $profileProcess.StartInfo = $profileStartInfo
318
+ try {
319
+ if (-not $profileProcess.Start()) { Die 'Probe profile warmup did not start' }
320
+ if (-not $profileProcess.WaitForExit(30000)) {
321
+ $profileProcess.Kill()
322
+ $profileProcess.WaitForExit()
323
+ Die 'Probe profile warmup did not exit within 30 seconds'
324
+ }
325
+ if ($profileProcess.ExitCode -ne 0) { Die "Probe profile warmup exited $($profileProcess.ExitCode)" }
326
+ } finally { $profileProcess.Dispose() }
305
327
  $probeProfile = (Get-CimInstance Win32_UserProfile -ErrorAction SilentlyContinue |
306
328
  Where-Object { $_.LocalPath -like "*\$ProbeUser" } | Select-Object -First 1).LocalPath
307
329
  Log " probe user profile: $probeProfile"
@@ -0,0 +1,59 @@
1
+ [CmdletBinding()]
2
+ param(
3
+ [Parameter(Mandatory)][string]$Archive,
4
+ [Parameter(Mandatory)][ValidatePattern('^[a-fA-F0-9]{64}$')][string]$ExpectedSha256,
5
+ [Parameter(Mandatory)][string]$SdkPayload
6
+ )
7
+ $ErrorActionPreference = 'Stop'
8
+ Add-Type -AssemblyName System.IO.Compression
9
+ Add-Type -AssemblyName System.IO.Compression.FileSystem
10
+
11
+ $source = [IO.File]::OpenRead((Resolve-Path -LiteralPath $Archive).ProviderPath)
12
+ try {
13
+ if ($source.Length -gt 64MB -or (Get-FileHash -InputStream $source -Algorithm SHA256).Hash -ne $ExpectedSha256) {
14
+ throw 'Private live-view archive digest did not match.'
15
+ }
16
+ $source.Position = 0
17
+ $bundle = [IO.Compression.ZipArchive]::new($source, [IO.Compression.ZipArchiveMode]::Read, $true)
18
+ try {
19
+ $names = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
20
+ [long]$expanded = 0
21
+ if ($bundle.Entries.Count -gt 2048) { throw 'Private live-view archive has too many files.' }
22
+ foreach ($item in $bundle.Entries) {
23
+ $name = $item.FullName
24
+ if ($name -cnotmatch '^[A-Za-z0-9_-][A-Za-z0-9_.-]*(/[A-Za-z0-9_-][A-Za-z0-9_.-]*)*$' -or
25
+ $name -match '(?:^|/)(?:CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])(?:[./]|$)' -or
26
+ $name -match '\.(?:/|$)' -or -not $names.Add($name)) {
27
+ throw 'Unsafe private live-view archive entry.'
28
+ }
29
+ $expanded += $item.Length
30
+ if ($expanded -gt 128MB) { throw 'Private live-view archive expanded size exceeded its limit.' }
31
+ }
32
+ $manifest = $bundle.GetEntry('platform.json')
33
+ $platform = $bundle.GetEntry('platform.cjs')
34
+ $addon = $bundle.GetEntry('owned-relay.node')
35
+ if (-not $manifest -or $manifest.Length -gt 4096 -or -not $platform -or $platform.Length -gt 256KB -or
36
+ -not $addon -or $addon.Length -le 0) {
37
+ throw 'Private live-view archive is missing the startup manifest, platform or native worker.'
38
+ }
39
+ $reader = [IO.StreamReader]::new($manifest.Open())
40
+ try { $stamp = $reader.ReadToEnd() | ConvertFrom-Json }
41
+ finally { $reader.Dispose() }
42
+ $entry = $platform.Open()
43
+ try { $entrySha = (Get-FileHash -InputStream $entry -Algorithm SHA256).Hash.ToLowerInvariant() }
44
+ finally { $entry.Dispose() }
45
+ if ($stamp.apiVersion -ne 1 -or $stamp.entrySha256 -cne $entrySha) {
46
+ throw 'Private live-view platform entry digest did not match.'
47
+ }
48
+
49
+ $sdk = (Resolve-Path -LiteralPath $SdkPayload).ProviderPath
50
+ $destination = Join-Path $sdk 'live-view'
51
+ if (Test-Path -LiteralPath $destination) { throw 'Private live-view destination already exists.' }
52
+ New-Item -ItemType Directory -Path $destination | Out-Null
53
+ foreach ($item in $bundle.Entries) {
54
+ $file = Join-Path $destination $item.FullName
55
+ New-Item -ItemType Directory -Force -Path (Split-Path -Parent $file) | Out-Null
56
+ [IO.Compression.ZipFileExtensions]::ExtractToFile($item, $file, $false)
57
+ }
58
+ } finally { $bundle.Dispose() }
59
+ } finally { $source.Dispose() }
@@ -93,7 +93,7 @@ function Get-TrillboardsEdgeProcesses {
93
93
  })
94
94
  }
95
95
 
96
- $processes = Get-TrillboardsEdgeProcesses
96
+ $processes = @(Get-TrillboardsEdgeProcesses)
97
97
  foreach ($process in $processes) {
98
98
  Stop-Process -Id $process.ProcessId -ErrorAction SilentlyContinue
99
99
  }
@@ -101,7 +101,7 @@ foreach ($process in $processes) {
101
101
  $deadline = [DateTime]::UtcNow.AddSeconds(5)
102
102
  do {
103
103
  Start-Sleep -Milliseconds 250
104
- $remaining = Get-TrillboardsEdgeProcesses
104
+ $remaining = @(Get-TrillboardsEdgeProcesses)
105
105
  } while ($remaining.Count -gt 0 -and [DateTime]::UtcNow -lt $deadline)
106
106
 
107
107
  foreach ($process in $remaining) {
@@ -109,7 +109,7 @@ foreach ($process in $remaining) {
109
109
  }
110
110
 
111
111
  Start-Sleep -Milliseconds 250
112
- $remaining = Get-TrillboardsEdgeProcesses
112
+ $remaining = @(Get-TrillboardsEdgeProcesses)
113
113
  if ($remaining.Count -gt 0) {
114
114
  $ids = ($remaining | ForEach-Object { $_.ProcessId }) -join ', '
115
115
  throw "Could not stop the existing Trillboards connector processes: $ids"
@@ -124,8 +124,9 @@ function Assert-BinariesUnlocked {
124
124
 
125
125
  $targets = @(
126
126
  (Join-Path $Root 'bin\node.exe'),
127
- (Join-Path $Root 'bin\ffmpeg.exe')
128
- ) | Where-Object { Test-Path -LiteralPath $_ }
127
+ (Join-Path $Root 'bin\ffmpeg.exe') |
128
+ Where-Object { Test-Path -LiteralPath $_ }
129
+ )
129
130
  if ($targets.Count -eq 0) { return }
130
131
 
131
132
  $deadline = [DateTime]::UtcNow.AddSeconds($TimeoutSeconds)
@@ -224,6 +224,10 @@ try {
224
224
  }
225
225
  if (-not $process.CreationDate -or -not $live.CreationDate -or -not $live.ExecutablePath) { continue }
226
226
  try { Stop-Process -Id $process.ProcessId -Force -ErrorAction Stop } catch {
227
+ # CIM may still list an exiting process after Stop-Process reports it
228
+ # gone. Only that error retries via the owned-process and port checks.
229
+ if ($_.CategoryInfo.Category -eq 'ObjectNotFound' -and
230
+ $_.FullyQualifiedErrorId -like 'NoProcessFoundForGivenId,*') { continue }
227
231
  if (Get-CimInstance Win32_Process -Filter ('ProcessId=' + $process.ProcessId) -OperationTimeoutSec 5 -ErrorAction Stop) { throw }
228
232
  }
229
233
  }
@@ -8,7 +8,14 @@ export interface RingSegment {
8
8
  captureEndMs: number;
9
9
  bytes: number;
10
10
  codec: string | null;
11
+ /** The stream's frame size from the sidecar: the substream's, or the main stream's (MainStreamRing). */
12
+ width: number | null;
13
+ height: number | null;
14
+ /** Which recording closed it: the main-stream recorder names its files `<start>-main-…` (MainStreamRing). */
15
+ stream: 'sub' | 'main';
11
16
  }
17
+ /** Which recording a ring file came from, by its name. */
18
+ export declare function ringSegmentStream(name: string): 'sub' | 'main';
12
19
  /**
13
20
  * The ring segments that overlap [fromMs, toMs], oldest first. Lists the ring
14
21
  * once and reads a sidecar only for names whose start could reach the window.
@@ -18,7 +25,7 @@ export declare function listRingSegments(closedDir: string, fromMs: number, toMs
18
25
  * The contiguous run to cut from: the one holding the alert's capture time,
19
26
  * else the one overlapping the window most. A gap (a session restart) splits
20
27
  * runs, because the concat timeline would silently drop it and misdate every
21
- * later frame.
28
+ * later frame; so does a change of stream (codec or frame size).
22
29
  */
23
30
  export declare function selectWindowRun(segments: RingSegment[], alertMs: number, fromMs: number, toMs: number): RingSegment[];
24
31
  /** The cut, exactly. Pure, so the argv can be asserted. */
@@ -1 +1 @@
1
- {"version":3,"file":"AlertClips.d.ts","sourceRoot":"","sources":["../src/AlertClips.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEvF,+EAA+E;AAC/E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAYD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAmC/F;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAYrH;AAOD,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,CAAC,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,EAAE,CAclI;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB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,gBAAgB,EAAE,KAAK,IAAI,CAAC;IACnD,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACzD;AAED;;;;;GAKG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyC;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IACpC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoD;IACxE,OAAO,CAAC,MAAM,CAA2E;IACzF;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,KAAK,CAA+B;IAC5C,oEAAoE;IACpE,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,QAAQ,CAAC,KAAK;;;;;;MAAmE;gBAErE,OAAO,EAAE,6BAA6B;IAalD,yEAAyE;IACzE,gBAAgB,IAAI,OAAO;IAS3B,qEAAqE;IACrE,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAe9D,IAAI,IAAI,IAAI;IASZ,OAAO,CAAC,QAAQ;YAWF,IAAI;CAwEnB"}
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.AlertClipReceiptPoller = exports.RECEIPT_POLL_FOR_MS = exports.RECEIPT_POLL_EVERY_MS = exports.RECEIPT_POLL_FIRST_DELAYS_MS = exports.EVENT_CLIPS_MAX_AGE_MS = exports.EVENT_CLIPS_MAX = void 0;
37
+ exports.ringSegmentStream = ringSegmentStream;
37
38
  exports.listRingSegments = listRingSegments;
38
39
  exports.selectWindowRun = selectWindowRun;
39
40
  exports.buildCutArgs = buildCutArgs;
@@ -77,6 +78,12 @@ const child_process_1 = require("child_process");
77
78
  const crypto_1 = require("crypto");
78
79
  const AudienceAnalyzeClient_1 = require("./AudienceAnalyzeClient");
79
80
  const SensingProfileClient_1 = require("./SensingProfileClient");
81
+ /** The main-stream recorder's ring files: `<13-digit capture start>-main-<…>.mp4` (edge-platform-rtsp MAIN_STREAM_WORKDIR_PREFIX). */
82
+ const MAIN_RING_NAME_RE = /^\d{13}-main-/i;
83
+ /** Which recording a ring file came from, by its name. */
84
+ function ringSegmentStream(name) {
85
+ return MAIN_RING_NAME_RE.test(path.basename(name)) ? 'main' : 'sub';
86
+ }
80
87
  /** `<13-digit capture start>-<work dir tag>-<segment name>.mp4`, as the provider names ring files. */
81
88
  const RING_NAME_RE = /^(\d{13})-.+\.mp4$/i;
82
89
  /** A ring segment never spans more than this, so older names cannot reach a window. */
@@ -120,6 +127,7 @@ function listRingSegments(closedDir, fromMs, toMs) {
120
127
  if (captureEndMs <= fromMs || captureStartMs >= toMs)
121
128
  continue;
122
129
  const stream = meta.stream;
130
+ const size = (v) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : null);
123
131
  out.push({
124
132
  file,
125
133
  metaFile,
@@ -127,21 +135,35 @@ function listRingSegments(closedDir, fromMs, toMs) {
127
135
  captureEndMs,
128
136
  bytes: Number.isFinite(bytes) ? bytes : 0,
129
137
  codec: stream && typeof stream.codec === 'string' ? stream.codec : null,
138
+ width: size(stream?.width),
139
+ height: size(stream?.height),
140
+ stream: ringSegmentStream(name),
130
141
  });
131
142
  }
132
143
  return out.sort((a, b) => a.captureStartMs - b.captureStartMs);
133
144
  }
145
+ /**
146
+ * Two ring segments of one stream: the same codec and frame size, as far as
147
+ * their sidecars say. A camera whose ring moves between its substream and its
148
+ * main stream (MainStreamRing) holds both, for a few seconds side by side, and
149
+ * a stream copy cannot join them into one file.
150
+ */
151
+ function sameStream(a, b) {
152
+ const same = (x, y) => x === null || y === null || x === y;
153
+ return same(a.codec, b.codec) && same(a.width, b.width) && same(a.height, b.height);
154
+ }
134
155
  /**
135
156
  * The contiguous run to cut from: the one holding the alert's capture time,
136
157
  * else the one overlapping the window most. A gap (a session restart) splits
137
158
  * runs, because the concat timeline would silently drop it and misdate every
138
- * later frame.
159
+ * later frame; so does a change of stream (codec or frame size).
139
160
  */
140
161
  function selectWindowRun(segments, alertMs, fromMs, toMs) {
141
162
  const runs = [];
142
163
  for (const segment of segments) {
143
164
  const run = runs[runs.length - 1];
144
- if (run && segment.captureStartMs - run[run.length - 1].captureEndMs <= RUN_GAP_MS)
165
+ const last = run ? run[run.length - 1] : null;
166
+ if (run && last && segment.captureStartMs - last.captureEndMs <= RUN_GAP_MS && sameStream(last, segment))
145
167
  run.push(segment);
146
168
  else
147
169
  runs.push([segment]);
@@ -177,7 +199,11 @@ async function cutAlertWindow(o) {
177
199
  const { request } = o;
178
200
  const fromMs = request.capturedAtMs - request.beforeSeconds * 1000;
179
201
  const toMs = request.capturedAtMs + request.afterSeconds * 1000;
180
- const run = selectWindowRun(listRingSegments(o.closedDir, fromMs, toMs), request.capturedAtMs, fromMs, toMs);
202
+ // A request names its recording (the substream or the main stream) and is cut
203
+ // only from it; an alert's window is cut from whatever the ring holds.
204
+ const wanted = request.kind && request.kind !== 'alert' && request.stream ? request.stream : null;
205
+ const segments = listRingSegments(o.closedDir, fromMs, toMs).filter((s) => wanted === null || s.stream === wanted);
206
+ const run = selectWindowRun(segments, request.capturedAtMs, fromMs, toMs);
181
207
  if (!run.length)
182
208
  return { unavailable: 'no_buffered_video' };
183
209
  const clipStart = Math.max(fromMs, run[0].captureStartMs);