@slidevideo/cli 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,6 +37,10 @@ $locked = $false
37
37
  $createdApplication = $false
38
38
  $clock = [Diagnostics.Stopwatch]::StartNew()
39
39
  $origin = 0.0
40
+ $skippedMs = 0.0
41
+ $plannedSkips = @()
42
+ $nextSkipIndex = 0
43
+ $appliedSkips = [Collections.Generic.List[object]]::new()
40
44
  $events = [Collections.Generic.List[object]]::new()
41
45
  $markers = [Collections.Generic.List[object]]::new()
42
46
  $references = [Collections.Generic.List[object]]::new()
@@ -71,6 +75,9 @@ function Check-Cancel {
71
75
  if ($null -ne $parentStartedTicks -and $parent.StartTime.ToUniversalTime().Ticks -ne $parentStartedTicks) { Fail 'INTERRUPTED' 'The CLI process identity changed.' }
72
76
  }
73
77
  }
78
+ function Schedule-Now {
79
+ return ($clock.Elapsed.TotalMilliseconds - $origin) + $script:skippedMs
80
+ }
74
81
  function Wait-Until([double]$deadline) {
75
82
  while ($clock.Elapsed.TotalMilliseconds -lt $deadline) {
76
83
  Check-Cancel
@@ -80,7 +87,41 @@ function Wait-Until([double]$deadline) {
80
87
  $remaining = $deadline - $clock.Elapsed.TotalMilliseconds
81
88
  if ($collectAnnotations) {
82
89
  foreach ($monitor in $annotationMonitors) {
83
- if (!$monitor.complete) { $remaining = [Math]::Min($remaining, $origin + $monitor.next_sample_ms - $clock.Elapsed.TotalMilliseconds) }
90
+ if (!$monitor.complete) { $remaining = [Math]::Min($remaining, $monitor.next_sample_ms - (Schedule-Now)) }
91
+ }
92
+ }
93
+ if ($remaining -gt 4) { Start-Sleep -Milliseconds ([Math]::Min(20, [int]($remaining - 1))) }
94
+ else { [Threading.Thread]::Sleep(1) }
95
+ }
96
+ if ($collectAnnotations) { Check-Annotations }
97
+ }
98
+ function Wait-UntilSchedule([double]$targetMs) {
99
+ while ((Schedule-Now) -lt $targetMs) {
100
+ Check-Cancel
101
+ if ($null -ne $recorder -and $recorder.HasExited) { Fail 'POWERPOINT_CAPTURE' 'FFmpeg exited during native playback.' }
102
+ if ($activeMedia.Count -gt 0) { Check-Media }
103
+ if ($collectAnnotations) { Check-Annotations }
104
+ $now = Schedule-Now
105
+ if ($now -ge $targetMs) { break }
106
+ if ($script:nextSkipIndex -lt $script:plannedSkips.Count) {
107
+ $nextSkip = $script:plannedSkips[$script:nextSkipIndex]
108
+ if ([double]$nextSkip.schedule_start_ms -le $targetMs -and $now -ge [double]$nextSkip.schedule_start_ms) {
109
+ $script:nextSkipIndex++
110
+ $remainingSkip = [double]$nextSkip.schedule_end_ms - (Schedule-Now)
111
+ if ($remainingSkip -gt 0) {
112
+ $appliedSkips.Add(@{ record_at_ms = ($clock.Elapsed.TotalMilliseconds - $origin); skip_ms = $remainingSkip })
113
+ $script:skippedMs += $remainingSkip
114
+ }
115
+ continue
116
+ }
117
+ }
118
+ $remaining = $targetMs - $now
119
+ if ($script:nextSkipIndex -lt $script:plannedSkips.Count -and [double]$script:plannedSkips[$script:nextSkipIndex].schedule_start_ms -le $targetMs) {
120
+ $remaining = [Math]::Min($remaining, [double]$script:plannedSkips[$script:nextSkipIndex].schedule_start_ms - $now)
121
+ }
122
+ if ($collectAnnotations) {
123
+ foreach ($monitor in $annotationMonitors) {
124
+ if (!$monitor.complete) { $remaining = [Math]::Min($remaining, $monitor.next_sample_ms - $now) }
84
125
  }
85
126
  }
86
127
  if ($remaining -gt 4) { Start-Sleep -Milliseconds ([Math]::Min(20, [int]($remaining - 1))) }
@@ -123,7 +164,7 @@ function Read-Package([string]$file) {
123
164
  }
124
165
  }
125
166
  }
126
- if ($entry.FullName -match '\.(gif|svg|glb|gltf)$' -or $entry.FullName -match '(^|/)(activeX|embeddings)/') {
167
+ if ($entry.FullName -match '\.(gif|glb|gltf)$' -or $entry.FullName -match '(^|/)(activeX|embeddings)/') {
127
168
  $unsupported.Add(@{ slide = ''; reason = ('Dynamic or externally controlled package content is unsupported: ' + $entry.FullName) })
128
169
  }
129
170
  }
@@ -138,14 +179,35 @@ function Read-Package([string]$file) {
138
179
  $relationshipId = $slideId.GetAttribute('id', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships')
139
180
  $part = Part-Name 'ppt/presentation.xml' $mapping[$relationshipId]
140
181
  $slideXml = Read-Part $zip $part
182
+ $entranceClickByShape = @{}
183
+ $animReasonsByShape = @{}
184
+ $mainSeq = $slideXml.SelectSingleNode('//*[local-name()="cTn"][@nodeType="mainSeq"]')
185
+ if ($null -ne $mainSeq) {
186
+ $seqClick = 0
187
+ foreach ($effectNode in $mainSeq.SelectNodes('.//*[local-name()="cTn"][@nodeType="clickEffect" or @nodeType="withEffect" or @nodeType="afterEffect"]')) {
188
+ if ($effectNode.GetAttribute('nodeType') -eq 'clickEffect') { $seqClick++ }
189
+ $presetClass = $effectNode.GetAttribute('presetClass')
190
+ $hasGeometryMotion = $null -ne $effectNode.SelectSingleNode('.//*[local-name()="animMotion" or local-name()="animScale" or local-name()="animRot" or local-name()="anim"]')
191
+ foreach ($spTarget in $effectNode.SelectNodes('.//*[local-name()="spTgt"][@spid]')) {
192
+ $spid = [int]$spTarget.GetAttribute('spid')
193
+ if ($presetClass -eq 'entr') {
194
+ $prev = $(if ($entranceClickByShape.ContainsKey($spid)) { [int]$entranceClickByShape[$spid] } else { 0 })
195
+ $entranceClickByShape[$spid] = [Math]::Max($prev, $seqClick)
196
+ }
197
+ if ($presetClass -eq 'path' -or ($presetClass -ne 'entr' -and $hasGeometryMotion)) {
198
+ if (!$animReasonsByShape.ContainsKey($spid)) { $animReasonsByShape[$spid] = [Collections.Generic.List[string]]::new() }
199
+ $animReasonsByShape[$spid].Add('moving or resized animated target')
200
+ }
201
+ }
202
+ }
203
+ }
141
204
  foreach ($identity in $slideXml.SelectNodes('//*[local-name()="cNvPr"]')) {
142
- $owner = $identity.ParentNode.ParentNode
205
+ $spid = [int]$identity.GetAttribute('id')
143
206
  $reasons = [Collections.Generic.List[string]]::new()
144
207
  if ($identity.GetAttribute('hidden') -in @('1', 'true')) { $reasons.Add('hidden shape') }
145
- if ($owner.LocalName -eq 'grpSp' -or $null -ne $owner.SelectSingleNode('ancestor::*[local-name()="grpSp"]')) { $reasons.Add('grouped shape') }
146
- $crop = $owner.SelectSingleNode('./*[local-name()="blipFill"]/*[local-name()="srcRect"]')
147
- if ($null -ne $crop -and @($crop.Attributes | Where-Object { $_.Value -ne '0' }).Count -gt 0) { $reasons.Add('cropped image') }
148
- $targets.Add(@{ native_id = $nativeId; id = [int]$identity.GetAttribute('id'); unsupported = @($reasons.ToArray()) })
208
+ if ($animReasonsByShape.ContainsKey($spid)) { foreach ($reason in $animReasonsByShape[$spid]) { $reasons.Add($reason) } }
209
+ $visibleClick = $(if ($entranceClickByShape.ContainsKey($spid)) { [int]$entranceClickByShape[$spid] } else { 0 })
210
+ $targets.Add(@{ native_id = $nativeId; id = $spid; unsupported = @($reasons.ToArray() | Select-Object -Unique); visible_from_click = $visibleClick })
149
211
  }
150
212
  $slideRelations = @{}
151
213
  $relationPart = ([IO.Path]::GetDirectoryName($part).Replace('\', '/') + '/_rels/' + [IO.Path]::GetFileName($part) + '.rels')
@@ -172,33 +234,28 @@ function Read-Package([string]$file) {
172
234
  $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Video relationships do not identify one embedded source.' })
173
235
  }
174
236
  }
175
- $crop = $picture.SelectSingleNode('.//*[local-name()="srcRect"]')
176
237
  $transform = $picture.SelectSingleNode('./*[local-name()="spPr"]/*[local-name()="xfrm"]')
177
- if ($null -ne $crop -or ($null -ne $transform -and ($transform.HasAttribute('rot') -or $transform.HasAttribute('flipH') -or $transform.HasAttribute('flipV')))) {
178
- $unsupported.Add(@{ slide = [string]$nativeId; reason = ('Video cropping, rotation and flipping are unsupported: ' + $shape.GetAttribute('name')) })
238
+ if ($null -ne $transform -and ($transform.HasAttribute('rot') -or $transform.HasAttribute('flipH') -or $transform.HasAttribute('flipV'))) {
239
+ $unsupported.Add(@{ slide = [string]$nativeId; reason = ('Video rotation and flipping are unsupported: ' + $shape.GetAttribute('name')) })
179
240
  }
180
241
  $shapeId = [int]$shape.GetAttribute('id')
181
242
  $nativeVideo = $slideXml.SelectSingleNode(('//*[local-name()="video"][.//*[local-name()="spTgt"][@spid="' + $shapeId + '"]]'))
182
243
  $fullscreen = 0
183
244
  if ($null -ne $nativeVideo -and $nativeVideo.GetAttribute('fullScrn') -in @('1', 'true')) { $fullscreen = -1 }
184
245
  foreach ($property in $picture.SelectNodes('./*[local-name()="spPr"]/*')) {
185
- if ($property.LocalName -notin @('xfrm', 'prstGeom')) { $unsupported.Add(@{ slide = [string]$nativeId; reason = ('Video shape effects are unsupported: ' + $shape.GetAttribute('name')) }) }
246
+ if ($property.LocalName -notin @('xfrm', 'prstGeom', 'ln', 'effectLst', 'solidFill', 'gradFill', 'noFill')) { $unsupported.Add(@{ slide = [string]$nativeId; reason = ('Unsupported video shape transform or 3D effect: ' + $shape.GetAttribute('name')) }) }
186
247
  }
187
248
  $media.Add(@{ id = $shape.GetAttribute('name'); native_id = $nativeId; shape = $shapeId; sha256 = (Part-Hash $zip $source); part = $source; fullscreen = $fullscreen })
188
249
  }
189
250
  if ($null -ne $slideXml.SelectSingleNode('//*[local-name()="sndAc" or local-name()="snd" or local-name()="sndTgt" or local-name()="audio" or local-name()="oleObj" or local-name()="contentPart"]')) {
190
251
  $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Native audio, animation or slide sounds, OLE and dynamic content are unsupported.' })
191
252
  }
192
- if ($null -ne $slideXml.SelectSingleNode('//*[local-name()="animMotion" or local-name()="animScale" or local-name()="animRot" or local-name()="animClr" or local-name()="anim" or local-name()="cmd"]')) {
193
- $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Custom motion, scale, rotation, color and command animation behaviors are unsupported.' })
194
- }
195
- foreach ($effect in $slideXml.SelectNodes('//*[local-name()="animEffect"]')) {
196
- if ($effect.GetAttribute('filter') -ne 'fade' -or $effect.GetAttribute('transition') -ne 'in') { $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Only native entrance Fade animation filters are supported.' }) }
253
+ if ($null -ne $slideXml.SelectSingleNode('//*[local-name()="cmd"]')) {
254
+ $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Command animation behaviors are unsupported.' })
197
255
  }
198
256
  foreach ($node in $slideXml.SelectNodes('//*[local-name()="cTn"]')) {
199
257
  if ($node.HasAttribute('spd') -and $node.GetAttribute('spd') -ne '100000') { $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Native animation or media speed transforms are unsupported.' }) }
200
- if ($node.HasAttribute('autoRev') -and $node.GetAttribute('autoRev') -ne '0') { $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Native auto-reverse is unsupported.' }) }
201
- if ($node.HasAttribute('repeatCount') -or $node.HasAttribute('repeatDur')) { $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Explicit native repeats are unsupported.' }) }
258
+ if (($node.HasAttribute('repeatCount') -and $node.GetAttribute('repeatCount') -eq 'indefinite') -or ($node.HasAttribute('repeatDur') -and $node.GetAttribute('repeatDur') -eq 'indefinite')) { $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Unbounded native animation repeats are unsupported.' }) }
202
259
  }
203
260
  }
204
261
  return @{ media = @($media.ToArray()); unsupported = @($unsupported.ToArray()); targets = @($targets.ToArray()) }
@@ -216,88 +273,158 @@ function Open-PrivateDeck([bool]$visible) {
216
273
  $script:presentation = $app.Presentations.Open($privateDeck, 0, 0, $(if ($visible) { -1 } else { 0 }))
217
274
  Write-Json 'ownership.json' @{ helper_pid = $PID; helper_started_ticks = ([Diagnostics.Process]::GetCurrentProcess().StartTime.ToUniversalTime().Ticks.ToString()); powerpoint_pid = $processId; powerpoint_started_ticks = $process.StartTime.ToUniversalTime().Ticks.ToString(); application_created = $createdApplication; presentation = $privateDeck }
218
275
  }
219
- function Inspect-Shapes($slide, $shapes, $package, [bool]$grouped) {
276
+ function Find-ShapeById($shapes, [int]$targetId, [bool]$ancestorInvalid = $false) {
277
+ $found = [Collections.Generic.List[object]]::new()
278
+ foreach ($shape in $shapes) {
279
+ $invalid = $ancestorInvalid -or ([int]$shape.Visible -ne -1) -or ([Math]::Abs([double]$shape.Rotation % 360) -gt 0.001) -or ([int]$shape.ThreeD.Visible -ne 0) -or ([int]$shape.HorizontalFlip -ne 0) -or ([int]$shape.VerticalFlip -ne 0)
280
+ if ([int]$shape.Id -eq $targetId) { $found.Add(@{ shape = $shape; invalid = $invalid }) }
281
+ if ([int]$shape.Type -eq 6) {
282
+ foreach ($child in (Find-ShapeById $shape.GroupItems $targetId $invalid)) { $found.Add($child) }
283
+ }
284
+ }
285
+ return @($found.ToArray())
286
+ }
287
+ function Inspect-Shapes([int]$slideId, [double]$slideWidth, [double]$slideHeight, $shapes, $targetsByKey, $effectsByShape, [bool]$ancestorTransformed, [int]$ancestorVisibleFromClick = 0, [string[]]$ancestorAnimReasons = @()) {
220
288
  foreach ($shape in $shapes) {
221
289
  Check-Cancel
290
+ $shapeId = [int]$shape.Id
291
+ $shapeName = [string]$shape.Name
292
+ $shapeType = [int]$shape.Type
222
293
  $reasons = [Collections.Generic.List[string]]::new()
294
+ $animReasons = [Collections.Generic.List[string]]::new()
223
295
  $bounds = @{ x = 0.0; y = 0.0; width = 0.0; height = 0.0 }
224
- $visibleFromClick = 0
296
+ $visibleFromClick = $ancestorVisibleFromClick
297
+ $isTransformed = $ancestorTransformed
298
+ foreach ($inherited in $ancestorAnimReasons) {
299
+ $reasons.Add($inherited)
300
+ $animReasons.Add($inherited)
301
+ }
225
302
  try {
226
- $metadata = @($package.targets | Where-Object { $_.native_id -eq $slide.SlideID -and $_.id -eq $shape.Id })
303
+ $targetKey = [string]$slideId + ':' + [string]$shapeId
304
+ $metadata = $(if ($targetsByKey.ContainsKey($targetKey)) { @($targetsByKey[$targetKey].ToArray()) } else { @() })
227
305
  if ($metadata.Count -ne 1) { $reasons.Add('shape identity is absent or ambiguous in the original slide package') }
228
- else { foreach ($reason in $metadata[0].unsupported) { $reasons.Add($reason) } }
229
- if ($grouped -or [int]$shape.Type -eq 6) { $reasons.Add('grouped shape') }
230
- if ([int]$shape.Visible -ne -1) { $reasons.Add('hidden shape') }
231
- if ([Math]::Abs([double]$shape.Rotation % 360) -gt 0.001 -or [int]$shape.ThreeD.Visible -ne 0) { $reasons.Add('rotated or three-dimensional shape') }
232
- if ([int]$shape.HorizontalFlip -ne 0 -or [int]$shape.VerticalFlip -ne 0) { $reasons.Add('flipped shape') }
233
- $bounds = @{ x = [double]$shape.Left / $presentation.PageSetup.SlideWidth; y = [double]$shape.Top / $presentation.PageSetup.SlideHeight; width = [double]$shape.Width / $presentation.PageSetup.SlideWidth; height = [double]$shape.Height / $presentation.PageSetup.SlideHeight }
306
+ else {
307
+ foreach ($reason in $metadata[0].unsupported) {
308
+ $reasons.Add($reason)
309
+ if ($reason -ne 'hidden shape') { $animReasons.Add($reason) }
310
+ }
311
+ $visibleFromClick = [Math]::Max($visibleFromClick, [int]$metadata[0].visible_from_click)
312
+ }
313
+ if ($ancestorTransformed) { $reasons.Add('ancestor group is hidden, rotated, flipped or three-dimensional') }
314
+ if ([int]$shape.Visible -ne -1) { $reasons.Add('hidden shape'); $isTransformed = $true }
315
+ if ([Math]::Abs([double]$shape.Rotation % 360) -gt 0.001 -or [int]$shape.ThreeD.Visible -ne 0) { $reasons.Add('rotated or three-dimensional shape'); $isTransformed = $true }
316
+ if ([int]$shape.HorizontalFlip -ne 0 -or [int]$shape.VerticalFlip -ne 0) { $reasons.Add('flipped shape'); $isTransformed = $true }
317
+ $bounds = @{ x = [double]$shape.Left / $slideWidth; y = [double]$shape.Top / $slideHeight; width = [double]$shape.Width / $slideWidth; height = [double]$shape.Height / $slideHeight }
234
318
  if ($bounds.width -le 0 -or $bounds.height -le 0 -or $bounds.x -lt 0 -or $bounds.y -lt 0 -or $bounds.x + $bounds.width -gt 1.000001 -or $bounds.y + $bounds.height -gt 1.000001) { $reasons.Add('degenerate shape or shape clipped by slide bounds') }
235
- $click = 0
236
- foreach ($effect in $slide.TimeLine.MainSequence) {
237
- if ([int]$effect.Timing.TriggerType -eq 1) { $click++ }
238
- if ([int]$effect.Shape.Id -ne [int]$shape.Id) { continue }
239
- if ([int]$effect.EffectType -notin @(1, 10) -or [int]$effect.Exit -ne 0 -or [int]$effect.Timing.TriggerType -notin @(1, 2, 3) -or $click -eq 0 -or [int]$effect.Paragraph -gt 0 -or [int]$effect.EffectInformation.AfterEffect -ne 0) { $reasons.Add('moving, partial-text, hidden-after-animation or unsupported animated target') }
240
- $visibleFromClick = [Math]::Max($visibleFromClick, $click)
319
+ if ($effectsByShape.ContainsKey($shapeId)) {
320
+ foreach ($effect in $effectsByShape[$shapeId]) {
321
+ if ([int]$effect.exit -ne 0 -or [int]$effect.trigger -notin @(1, 2, 3) -or [int]$effect.paragraph -gt 0 -or [int]$effect.after_effect -ne 0 -or [double]$effect.repeat_count -lt 0 -or [double]$effect.repeat_count -gt 100 -or [double]$effect.repeat_duration_ms -lt 0) {
322
+ $reason = 'exited, partial-text, hidden-after-animation or unbounded animated target'
323
+ $reasons.Add($reason)
324
+ $animReasons.Add($reason)
325
+ }
326
+ }
241
327
  }
242
328
  } catch { $reasons.Add('native target geometry is unavailable: ' + $_.Exception.Message) }
243
- @{ id = [int]$shape.Id; name = [string]$shape.Name; bounds = $bounds; unsupported = @($reasons.ToArray() | Select-Object -Unique); visible_from_click = $visibleFromClick }
244
- if ([int]$shape.Type -eq 6) { Inspect-Shapes $slide $shape.GroupItems $package $true }
329
+ $children = @()
330
+ if ($shapeType -eq 6) {
331
+ $children = @(Inspect-Shapes $slideId $slideWidth $slideHeight $shape.GroupItems $targetsByKey $effectsByShape $isTransformed $visibleFromClick @($animReasons.ToArray() | Select-Object -Unique))
332
+ foreach ($child in $children) {
333
+ $visibleFromClick = [Math]::Max($visibleFromClick, [int]$child.visible_from_click)
334
+ foreach ($childReason in $child.unsupported) {
335
+ if ($childReason -in @('moving or resized animated target', 'exited, partial-text, hidden-after-animation or unbounded animated target')) {
336
+ $reasons.Add($childReason)
337
+ }
338
+ }
339
+ }
340
+ }
341
+ @{ id = $shapeId; name = $shapeName; bounds = $bounds; unsupported = @($reasons.ToArray() | Select-Object -Unique); visible_from_click = $visibleFromClick }
342
+ foreach ($child in $children) { $child }
245
343
  }
246
344
  }
247
345
  function Inspect-Native($package) {
346
+ $slideWidth = [double]$presentation.PageSetup.SlideWidth
347
+ $slideHeight = [double]$presentation.PageSetup.SlideHeight
348
+ $targetsByKey = @{}
349
+ foreach ($target in $package.targets) {
350
+ $key = [string]$target.native_id + ':' + [string]$target.id
351
+ if (!$targetsByKey.ContainsKey($key)) { $targetsByKey[$key] = [Collections.Generic.List[object]]::new() }
352
+ $targetsByKey[$key].Add($target)
353
+ }
248
354
  $slides = [Collections.Generic.List[object]]::new()
249
355
  foreach ($slide in $presentation.Slides) {
250
356
  Check-Cancel
357
+ $slideId = [int]$slide.SlideID
358
+ $slideName = [string]$slide.Name
251
359
  $effects = [Collections.Generic.List[object]]::new()
360
+ $effectsByShape = @{}
252
361
  foreach ($effect in $slide.TimeLine.MainSequence) {
253
362
  $timing = $effect.Timing
254
- $effects.Add(@{ type = [int]$effect.EffectType; trigger = [int]$timing.TriggerType; duration_ms = [double]$timing.Duration * 1000; delay_ms = [double]$timing.TriggerDelayTime * 1000; repeat_count = [double]$timing.RepeatCount; repeat_duration_ms = [double]$timing.RepeatDuration * 1000; auto_reverse = [int]$timing.AutoReverse; exit = [int]$effect.Exit; shape = [int]$effect.Shape.Id; paragraph = [int]$effect.Paragraph })
363
+ $effectShapeId = [int]$effect.Shape.Id
364
+ $entry = @{ type = [int]$effect.EffectType; trigger = [int]$timing.TriggerType; duration_ms = [double]$timing.Duration * 1000; delay_ms = [double]$timing.TriggerDelayTime * 1000; repeat_count = [double]$timing.RepeatCount; repeat_duration_ms = [double]$timing.RepeatDuration * 1000; auto_reverse = [int]$timing.AutoReverse; exit = [int]$effect.Exit; shape = $effectShapeId; paragraph = [int]$effect.Paragraph }
365
+ $effects.Add($entry)
366
+ if (!$effectsByShape.ContainsKey($effectShapeId)) { $effectsByShape[$effectShapeId] = [Collections.Generic.List[object]]::new() }
367
+ $effectsByShape[$effectShapeId].Add(@{ trigger = $entry.trigger; repeat_count = $entry.repeat_count; repeat_duration_ms = $entry.repeat_duration_ms; exit = $entry.exit; paragraph = $entry.paragraph; after_effect = [int]$effect.EffectInformation.AfterEffect })
255
368
  }
256
- $shapes = @(Inspect-Shapes $slide $slide.Shapes $package $false)
257
- $slides.Add(@{ id = [string]$slide.Name; native_id = [int]$slide.SlideID; index = [int]$slide.SlideIndex; effects = @($effects.ToArray()); shapes = $shapes; transition = [int]$slide.SlideShowTransition.EntryEffect; auto_advance = [int]$slide.SlideShowTransition.AdvanceOnTime; hidden = [int]$slide.SlideShowTransition.Hidden; interactive = [int]$slide.TimeLine.InteractiveSequences.Count })
369
+ $shapes = @(Inspect-Shapes $slideId $slideWidth $slideHeight $slide.Shapes $targetsByKey $effectsByShape $false)
370
+ $transitionEffect = [int]$slide.SlideShowTransition.EntryEffect
371
+ $transitionDurationMs = $(if ($transitionEffect -ne 0) { [Math]::Round([double]$slide.SlideShowTransition.Duration * 1000) } else { 0 })
372
+ $slides.Add(@{ id = $slideName; native_id = $slideId; index = [int]$slide.SlideIndex; effects = @($effects.ToArray()); shapes = $shapes; transition = $transitionEffect; transition_duration_ms = $transitionDurationMs; auto_advance = [int]$slide.SlideShowTransition.AdvanceOnTime; hidden = [int]$slide.SlideShowTransition.Hidden; interactive = [int]$slide.TimeLine.InteractiveSequences.Count })
258
373
  foreach ($shape in $slide.Shapes) {
259
374
  if ([int]$shape.Type -eq 16) {
260
- if ([int]$shape.MediaType -ne 3) { $package.unsupported += @{ slide = [string]$slide.Name; reason = ('Only native video media shapes are supported: ' + $shape.Name) }; continue }
261
- $matches = @($package.media | Where-Object { $_.native_id -eq $slide.SlideID -and $_.shape -eq $shape.Id })
262
- if ($matches.Count -ne 1) { $package.unsupported += @{ slide = [string]$slide.Name; reason = ('Cannot identify exact embedded video bytes: ' + $shape.Name) }; continue }
375
+ $videoShapeId = [int]$shape.Id
376
+ $videoShapeName = [string]$shape.Name
377
+ if ([int]$shape.MediaType -ne 3) { $package.unsupported += @{ slide = $slideName; reason = ('Only native video media shapes are supported: ' + $videoShapeName) }; continue }
378
+ $matches = @($package.media | Where-Object { $_.native_id -eq $slideId -and $_.shape -eq $videoShapeId })
379
+ if ($matches.Count -ne 1) { $package.unsupported += @{ slide = $slideName; reason = ('Cannot identify exact embedded video bytes: ' + $videoShapeName) }; continue }
263
380
  $media = $matches[0]
264
- $media.id = [string]$shape.Name
381
+ $media.id = $videoShapeName
265
382
  $media.duration_ms = [double]$shape.MediaFormat.Length
266
383
  $media.start_ms = [double]$shape.MediaFormat.StartPoint
267
384
  $media.end_ms = [double]$shape.MediaFormat.EndPoint
268
385
  $media.autoplay = [int]$shape.AnimationSettings.PlaySettings.PlayOnEntry
269
386
  $media.loop = [int]$shape.AnimationSettings.PlaySettings.LoopUntilStopped
270
387
  $media.rewind = [int]$shape.AnimationSettings.PlaySettings.RewindMovie
271
- $media.left = [double]$shape.Left / $presentation.PageSetup.SlideWidth
272
- $media.top = [double]$shape.Top / $presentation.PageSetup.SlideHeight
273
- $media.right = ([double]$shape.Left + $shape.Width) / $presentation.PageSetup.SlideWidth
274
- $media.bottom = ([double]$shape.Top + $shape.Height) / $presentation.PageSetup.SlideHeight
388
+ $media.left = [double]$shape.Left / $slideWidth
389
+ $media.top = [double]$shape.Top / $slideHeight
390
+ $media.right = ([double]$shape.Left + $shape.Width) / $slideWidth
391
+ $media.bottom = ([double]$shape.Top + $shape.Height) / $slideHeight
275
392
  }
276
393
  }
277
394
  }
278
- return @{ version = 1; kind = 'inspection'; deck_sha256 = $job.deck_sha256; width = [double]$presentation.PageSetup.SlideWidth; height = [double]$presentation.PageSetup.SlideHeight; slides = @($slides.ToArray()); media = $package.media; unsupported = $package.unsupported; dependencies = (Dependencies) }
395
+ return @{ version = 1; kind = 'inspection'; deck_sha256 = $job.deck_sha256; width = $slideWidth; height = $slideHeight; slides = @($slides.ToArray()); media = $package.media; unsupported = $package.unsupported; dependencies = (Dependencies) }
279
396
  }
280
397
  function Dependencies {
281
398
  $office = [Diagnostics.Process]::GetProcessById($officeProcess).MainModule.FileVersionInfo.FileVersion
282
399
  return @{ powerpoint = [string]$app.Version; office_build = $office; windows = [Environment]::OSVersion.VersionString; powershell = $PSVersionTable.PSVersion.ToString(); ffmpeg = $script:ffmpegVersion }
283
400
  }
284
401
  function Slide-ById([int]$nativeId) { return $presentation.Slides.FindBySlideID($nativeId) }
285
- function Select-Slide([int]$nativeId) {
402
+ function Select-Slide([int]$nativeId, [bool]$cut = $false) {
286
403
  $slide = Slide-ById $nativeId
287
- $show.View.GotoSlide([int]$slide.SlideIndex, -1)
404
+ if ($cut) {
405
+ $saved = [int]$slide.SlideShowTransition.EntryEffect
406
+ $slide.SlideShowTransition.EntryEffect = 0
407
+ try { $show.View.GotoSlide([int]$slide.SlideIndex, -1) }
408
+ finally { $slide.SlideShowTransition.EntryEffect = $saved }
409
+ } else {
410
+ $show.View.GotoSlide([int]$slide.SlideIndex, -1)
411
+ }
288
412
  if ([int]$show.View.Slide.SlideID -ne $nativeId -or [int]$show.View.GetClickIndex() -ne 0) { Fail 'POWERPOINT_NAVIGATION' ('Native slide did not reset: ' + $nativeId) }
289
413
  }
290
414
  function Apply-Operation($operation) {
291
415
  if ($operation.type -eq 'slide') { Select-Slide $operation.native_id; $script:activeVisit = [string]$operation.id; $script:activeScene = [string]$operation.scene }
292
416
  elseif ($operation.type -eq 'reveal') {
293
417
  if ([int]$show.View.Slide.SlideID -ne $operation.native_id) { Fail 'POWERPOINT_NAVIGATION' ('Wrong native slide for reveal ' + $operation.id) }
294
- $show.View.GotoClick([int]$operation.click)
295
- if ([int]$show.View.GetClickIndex() -ne $operation.click) { Fail 'POWERPOINT_REVEAL' ('Native click did not execute: ' + $operation.id) }
418
+ $currentClick = [int]$show.View.GetClickIndex()
419
+ $targetClick = [int]$operation.click
420
+ if ($targetClick -eq $currentClick + 1) { $show.View.Next() }
421
+ else { $show.View.GotoClick($targetClick) }
422
+ if ([int]$show.View.Slide.SlideID -ne $operation.native_id -or [int]$show.View.GetClickIndex() -ne $targetClick) { Fail 'POWERPOINT_REVEAL' ('Native click did not execute: ' + $operation.id) }
296
423
  } elseif ($operation.type -eq 'play') {
297
424
  if ([int]$show.View.Slide.SlideID -ne $operation.native_id) { Fail 'POWERPOINT_MEDIA' ('Wrong native slide for media ' + $operation.id) }
298
425
  $player = $show.View.Player([int]$operation.shape)
299
426
  $player.Stop()
300
- $player.CurrentPosition = 0
427
+ $player.CurrentPosition = [int][Math]::Round([double]$operation.trim_start_ms)
301
428
  $player.Play()
302
429
  return $player
303
430
  } else { Fail 'POWERPOINT_PROTOCOL' ('Unknown operation ' + $operation.type) }
@@ -342,10 +469,10 @@ function Measure-Annotation($request, [bool]$allowPaused = $false) {
342
469
  if ($request.target.type -eq 'region') {
343
470
  $bounds = @{ x = [double]$request.target.x; y = [double]$request.target.y; width = [double]$request.target.width; height = [double]$request.target.height }
344
471
  } else {
345
- $matches = @($show.View.Slide.Shapes | Where-Object { $_.Id -eq $request.target.id })
472
+ $matches = @(Find-ShapeById $show.View.Slide.Shapes ([int]$request.target.id))
346
473
  if ($matches.Count -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ': actual shape is missing or ambiguous.') }
347
- $shape = $matches[0]
348
- if ([int]$shape.Visible -ne -1 -or [int]$shape.Type -eq 6 -or [Math]::Abs([double]$shape.Rotation % 360) -gt 0.001 -or [int]$shape.ThreeD.Visible -ne 0 -or [int]$shape.HorizontalFlip -ne 0 -or [int]$shape.VerticalFlip -ne 0) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ': actual target is hidden, grouped or transformed.') }
474
+ $shape = $matches[0].shape
475
+ if ($matches[0].invalid) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $request.target.id + ': actual target is hidden or transformed.') }
349
476
  $bounds = @{ x = [double]$shape.Left / $presentation.PageSetup.SlideWidth; y = [double]$shape.Top / $presentation.PageSetup.SlideHeight; width = [double]$shape.Width / $presentation.PageSetup.SlideWidth; height = [double]$shape.Height / $presentation.PageSetup.SlideHeight }
350
477
  }
351
478
  foreach ($value in $bounds.Values) { if ([double]::IsNaN($value) -or [double]::IsInfinity($value)) { Fail 'ANNOTATION_GEOMETRY' ($context + ': nonfinite bounds.') } }
@@ -358,11 +485,11 @@ function Check-Annotations {
358
485
  $request = $monitor.request
359
486
  $context = Request-Context $request $true
360
487
  if ($null -eq $monitor.geometry -and $request.start_ms -ge $annotationStartBeforeMs) { continue }
361
- $now = $clock.Elapsed.TotalMilliseconds - $origin
488
+ $now = Schedule-Now
362
489
  if ($now -lt $monitor.next_sample_ms -and $now -lt $request.end_ms) { continue }
363
490
  if ($null -eq $monitor.geometry -and $now -ge $request.end_ms) { Fail 'ANNOTATION_INTERVAL' ($context + ': native playback missed the entire interval.') }
364
491
  $fragments = @(Measure-Annotation $request)
365
- $observed = $clock.Elapsed.TotalMilliseconds - $origin
492
+ $observed = Schedule-Now
366
493
  if ($null -eq $monitor.geometry) {
367
494
  if ($observed -ge $request.end_ms) { Fail 'ANNOTATION_INTERVAL' ($context + ': initial measurement completed after the interval.') }
368
495
  if ($observed - $request.start_ms -gt 100) { Fail 'ANNOTATION_INTERVAL' ($context + ': initial native measurement exceeded the interval boundary by 100 ms.') }
@@ -387,16 +514,24 @@ function Check-Annotations {
387
514
  }
388
515
  }
389
516
  function Check-Media {
390
- $now = $clock.Elapsed.TotalMilliseconds - $origin
517
+ $now = Schedule-Now
391
518
  foreach ($monitor in @($activeMedia.ToArray())) {
392
519
  $position = [double]$monitor.player.CurrentPosition
393
520
  $state = [int]$monitor.player.State
394
521
  if ($position -gt $monitor.last_position + 1) { $monitor.last_position = $position; $monitor.advanced_at = $now }
395
- $expected = $now - $monitor.operation.at_ms
396
- if ($state -in @($ppPaused, $ppStopped) -and $expected -ge $monitor.operation.source_duration_ms - 200 -and $monitor.last_position -ge $monitor.operation.source_duration_ms - 200) {
522
+ $trimStart = [double]$monitor.operation.trim_start_ms
523
+ $trimEnd = [double]$monitor.operation.trim_end_ms
524
+ $elapsed = $now - $monitor.operation.at_ms
525
+ $expected = $trimStart + $elapsed
526
+ $isTrimmedEnd = $trimEnd -lt ([double]$monitor.operation.source_duration_ms - 50)
527
+ if ($isTrimmedEnd -and ($now -ge $monitor.operation.end_ms -or ($position -gt $trimStart + 1 -and $position -ge $trimEnd - 30))) {
528
+ $monitor.player.Pause()
529
+ $events.Add(@{ id = ($monitor.operation.id + ':ended'); type = 'media-ended'; scheduled_ms = $monitor.operation.end_ms; observed_ms = $now; media_ms = $position })
530
+ [void]$activeMedia.Remove($monitor)
531
+ } elseif ($state -in @($ppPaused, $ppStopped) -and $expected -ge $trimEnd - 200 -and $monitor.last_position -ge $trimEnd - 200) {
397
532
  $events.Add(@{ id = ($monitor.operation.id + ':ended'); type = 'media-ended'; scheduled_ms = $monitor.operation.end_ms; observed_ms = $now; media_ms = $monitor.last_position })
398
533
  [void]$activeMedia.Remove($monitor)
399
- } elseif ($now -gt $monitor.operation.end_ms + 250 -or ($expected -gt 300 -and [Math]::Abs($position - $expected) -gt 200) -or ($now - $monitor.advanced_at -gt 250) -or ($expected -gt 150 -and $state -ne $ppPlaying)) {
534
+ } elseif ($now -gt $monitor.operation.end_ms + 250 -or ($elapsed -gt 300 -and [Math]::Abs($position - $expected) -gt 200) -or ($now - $monitor.advanced_at -gt 250) -or ($elapsed -gt 150 -and $state -ne $ppPlaying)) {
400
535
  Fail 'POWERPOINT_MEDIA_STALL' ('Native media stalled: ' + $monitor.operation.id + ', expected ' + [int]$expected + ' ms, observed ' + $position + ' ms, state ' + $state)
401
536
  }
402
537
  }
@@ -404,7 +539,7 @@ function Check-Media {
404
539
  function Wait-MediaCompletion {
405
540
  Check-Media
406
541
  foreach ($monitor in @($activeMedia.ToArray())) {
407
- if ($monitor.last_position -lt $monitor.operation.source_duration_ms - 200) {
542
+ if ($monitor.last_position -lt [double]$monitor.operation.trim_end_ms - 200) {
408
543
  Fail 'POWERPOINT_MEDIA_STALL' ('Native media is not within completion tolerance at the action boundary: ' + $monitor.operation.id)
409
544
  }
410
545
  }
@@ -461,27 +596,32 @@ function Save-Reference([string]$label) {
461
596
  return $file
462
597
  }
463
598
  function Rehearse {
464
- Select-Slide $job.operations[0].native_id
465
- Wait-Until ($clock.Elapsed.TotalMilliseconds + 300)
599
+ Select-Slide $job.operations[0].native_id $true
600
+ Wait-Until ($clock.Elapsed.TotalMilliseconds + [Math]::Max(300, [double]$job.operations[0].settle_ms + 200))
466
601
  $number = 0
467
602
  foreach ($operation in $job.operations) {
468
603
  Check-Cancel
469
604
  $number++
605
+ if ($number -eq 1 -and $operation.type -eq 'slide' -and $operation.at_ms -eq 0) { continue }
470
606
  $before = Save-Reference ('reference-' + $number + '-before')
471
607
  $exclude = @($job.media | Where-Object { $_.native_id -eq [int]$show.View.Slide.SlideID } | ForEach-Object { @{ left = $_.left; top = $_.top; right = $_.right; bottom = $_.bottom } })
472
608
  $player = Apply-Operation $operation
473
609
  if ($operation.type -eq 'play') {
474
610
  $player.Pause()
475
- $samples = @(500, 1500 | Where-Object { $_ -lt $operation.source_duration_ms })
476
- if ($samples.Count -eq 0) { $samples = @($operation.source_duration_ms / 2) }
477
- foreach ($sample in $samples) {
478
- $player.CurrentPosition = [int]$sample
611
+ $trimStart = [double]$operation.trim_start_ms
612
+ $trimEnd = [double]$operation.trim_end_ms
613
+ $clipDuration = $trimEnd - $trimStart
614
+ $offsets = @(500, 1500 | Where-Object { $_ -lt $clipDuration })
615
+ if ($offsets.Count -eq 0) { $offsets = @($clipDuration / 2) }
616
+ foreach ($offset in $offsets) {
617
+ $samplePos = [int][Math]::Round($trimStart + $offset)
618
+ $player.CurrentPosition = $samplePos
479
619
  Wait-Until ($clock.Elapsed.TotalMilliseconds + 250)
480
- if ([Math]::Abs([double]$player.CurrentPosition - $sample) -gt $operation.frame_period_ms) { Fail 'POWERPOINT_REFERENCE' ('Native video seek is unbounded: ' + $operation.id) }
481
- $after = Save-Reference ('reference-' + $number + '-sample-' + $sample)
482
- $references.Add(@{ id = ($operation.id.Replace(':', '-') + '-' + $sample); expected_ms = $operation.at_ms + $sample; before = $before; after = $after; mode = 'sample'; frame_period_ms = $operation.frame_period_ms })
620
+ if ([Math]::Abs([double]$player.CurrentPosition - $samplePos) -gt $operation.frame_period_ms) { Fail 'POWERPOINT_REFERENCE' ('Native video seek is unbounded: ' + $operation.id) }
621
+ $after = Save-Reference ('reference-' + $number + '-sample-' + [int]$offset)
622
+ $references.Add(@{ id = ($operation.id.Replace(':', '-') + '-' + [int]$offset); expected_ms = $operation.at_ms + $offset; before = $before; after = $after; mode = 'sample'; frame_period_ms = $operation.frame_period_ms })
483
623
  }
484
- $player.CurrentPosition = [int][Math]::Max(0, $operation.source_duration_ms - $operation.frame_period_ms)
624
+ $player.CurrentPosition = [int][Math]::Max($trimStart, $trimEnd - $operation.frame_period_ms)
485
625
  Wait-Until ($clock.Elapsed.TotalMilliseconds + 200)
486
626
  $player.Pause()
487
627
  } elseif ($operation.at_ms -gt 0) {
@@ -493,6 +633,25 @@ function Rehearse {
493
633
  foreach ($slide in $presentation.Slides) { foreach ($shape in $slide.Shapes) { if ([int]$shape.Type -eq 16) { try { $show.View.Player([int]$shape.Id).Stop() } catch {} } } }
494
634
  Write-Json 'references.json' @{ version = 1; references = @($references.ToArray()) }
495
635
  }
636
+ function Wait-ShowView([double]$deadline) {
637
+ $lastError = ''
638
+ do {
639
+ Check-Cancel
640
+ try {
641
+ if ($null -eq $script:show) { $script:show = $presentation.SlideShowWindow }
642
+ $view = $script:show.View
643
+ if ($null -ne $view) { return [int]$view.State }
644
+ } catch {
645
+ $lastError = $_.Exception.Message
646
+ }
647
+ try {
648
+ if ($null -ne $presentation.SlideShowWindow) { $script:show = $presentation.SlideShowWindow }
649
+ } catch {}
650
+ Start-Sleep -Milliseconds 20
651
+ } while ($clock.Elapsed.TotalMilliseconds -lt $deadline)
652
+ if ($lastError) { Fail 'POWERPOINT_WINDOW' ('The slideshow view did not initialize: ' + $lastError) }
653
+ Fail 'POWERPOINT_WINDOW' 'The slideshow view did not initialize.'
654
+ }
496
655
  function Stop-Recorder {
497
656
  if ($null -eq $recorder) { return }
498
657
  if (!$recorder.HasExited) {
@@ -561,14 +720,12 @@ try {
561
720
  $deadline = $clock.Elapsed.TotalMilliseconds + 10000
562
721
  do { Check-Cancel; $window = [SlideVideo.Native]::FindShow($officeProcess, [IO.Path]::GetFileNameWithoutExtension($privateDeck), $editorWindow); if ($window -eq 0) { Start-Sleep -Milliseconds 20 } } while ($window -eq 0 -and $clock.Elapsed.TotalMilliseconds -lt $deadline)
563
722
  if ($window -eq 0) { Fail 'POWERPOINT_WINDOW' 'Cannot identify one audience window owned by the private deck.' }
564
- $initialViewState = [int]$show.View.State
723
+ $initialViewState = Wait-ShowView ($clock.Elapsed.TotalMilliseconds + 10000)
565
724
  $show.View.State = 1
566
725
  $show.View.AcceleratorsEnabled = 0
567
- $captureWidth = [Math]::Min([int]$job.output.width, 1600)
568
- $captureHeight = [int][Math]::Round($captureWidth / $deckAspect)
569
- [SlideVideo.Native]::Place($window, $captureWidth, $captureHeight)
726
+ $windowMode = [SlideVideo.Native]::PlaceForAudience($window, [int]$job.output.width, [int]$job.output.height, $deckAspect, $true, $true)
570
727
  $show.View.GotoSlide([int]$markerSlides['#ff00ff'], -1)
571
- Write-Json 'window.json' @{ hwnd = $window.ToString(); editor_hwnd = $editorWindow.ToString(); description = [SlideVideo.Native]::Describe($window); initial_state = $initialViewState; state = [int]$show.View.State; slide_id = [int]$show.View.Slide.SlideID; marker_slide_id = [int]$presentation.Slides.Item([int]$markerSlides['#ff00ff']).SlideID; marker_rgb = [int]$show.View.Slide.Background.Fill.ForeColor.RGB; follows_master = [int]$show.View.Slide.FollowMasterBackground }
728
+ Write-Json 'window.json' @{ hwnd = $window.ToString(); editor_hwnd = $editorWindow.ToString(); description = [SlideVideo.Native]::Describe($window); mode = $windowMode; initial_state = $initialViewState; state = [int]$show.View.State; slide_id = [int]$show.View.Slide.SlideID; marker_slide_id = [int]$presentation.Slides.Item([int]$markerSlides['#ff00ff']).SlideID; marker_rgb = [int]$show.View.Slide.Background.Fill.ForeColor.RGB; follows_master = [int]$show.View.Slide.FollowMasterBackground }
572
729
  $geometry = $null
573
730
  $deadline = $clock.Elapsed.TotalMilliseconds + 5000
574
731
  do {
@@ -587,14 +744,15 @@ try {
587
744
  $outputContent = [SlideVideo.Native]::OutputContent($geometry, [int]$job.output.width, [int]$job.output.height)
588
745
  if ($job.geometry_requests.Count -gt 0) { $scaleFilter = ('scale=' + $outputContent.width + ':' + $outputContent.height + ':flags=bicubic,format=rgb24,pad=' + $job.output.width + ':' + $job.output.height + ':' + $outputContent.x + ':' + $outputContent.y + ',setsar=1') }
589
746
  $captureFilter = ('crop=' + $geometry.width + ':' + $geometry.height + ':' + $geometry.left + ':' + $geometry.top + ':exact=1,' + $scaleFilter)
590
- Write-Json 'geometry.json' @{ version = 1; hwnd = $window.ToString(); rectangle = $geometry; deck_aspect = $deckAspect; requested = $job.output; filter = $captureFilter }
747
+ Write-Json 'geometry.json' @{ version = 1; hwnd = $window.ToString(); mode = $windowMode; rectangle = $geometry; output_content = $outputContent; scale_x = [double]$outputContent.width / $geometry.width; scale_y = [double]$outputContent.height / $geometry.height; deck_aspect = $deckAspect; requested = $job.output; filter = $captureFilter }
591
748
  if ($job.verify_timing) { Rehearse }
592
749
  $firstOperation = $job.operations[0]
593
750
  if ($firstOperation.type -ne 'slide' -or $firstOperation.at_ms -ne 0) { Fail 'POWERPOINT_PROTOCOL' 'The native schedule must initialize a slide at time zero.' }
594
- Select-Slide $firstOperation.native_id
751
+ Select-Slide $firstOperation.native_id $true
752
+ $firstOnsetMatchesYellow = [SlideVideo.Native]::ColorPresent($window, $geometry, '#ffff00')
595
753
  Wait-Until ($clock.Elapsed.TotalMilliseconds + 200)
596
754
  $firstReadback = [SlideVideo.Native]::Readback($window, $geometry)
597
- $deadline = $clock.Elapsed.TotalMilliseconds + 5000
755
+ $deadline = $clock.Elapsed.TotalMilliseconds + [Math]::Max(5000, [double]$firstOperation.settle_ms + 3000)
598
756
  do {
599
757
  Wait-Until ($clock.Elapsed.TotalMilliseconds + 30)
600
758
  $nextReadback = [SlideVideo.Native]::Readback($window, $geometry)
@@ -642,31 +800,38 @@ try {
642
800
  Show-Marker '#ff00ff'
643
801
  if ($job.verify_timing) { Show-Marker '#00ffff' }
644
802
  Show-Marker '#ffff00'
803
+ $markerReadback = $(if ([double]$firstOperation.settle_ms -gt 0) { [SlideVideo.Native]::Readback($window, $geometry) } else { '' })
645
804
  $initialLower = $clock.Elapsed.TotalMilliseconds
646
- Select-Slide $firstOperation.native_id
647
- $deadline = $clock.Elapsed.TotalMilliseconds + 5000
805
+ Select-Slide $firstOperation.native_id $true
806
+ $deadline = $clock.Elapsed.TotalMilliseconds + [Math]::Max(5000, [double]$firstOperation.settle_ms + 3000)
648
807
  do {
649
808
  Check-Cancel
650
- $ready = [SlideVideo.Native]::Readback($window, $geometry) -eq $firstReadback
809
+ $currentReadback = [SlideVideo.Native]::Readback($window, $geometry)
810
+ $ready = $(if ([double]$firstOperation.settle_ms -gt 0) { $firstOnsetMatchesYellow -or ($currentReadback -ne $markerReadback) } else { $currentReadback -eq $firstReadback })
651
811
  if (!$ready) { Start-Sleep -Milliseconds 1 }
652
812
  } while (!$ready -and $clock.Elapsed.TotalMilliseconds -lt $deadline)
653
- if (!$ready) { Fail 'POWERPOINT_READINESS' 'The actual audience pixels did not return to the initialized first-slide state.' }
813
+ if (!$ready) { Fail 'POWERPOINT_READINESS' 'The actual audience pixels did not transition to the initialized first-slide state.' }
654
814
  $script:origin = $clock.Elapsed.TotalMilliseconds
655
- Write-Json 'startup.json' @{ version = 1; native_id = $firstOperation.native_id; readback_sha256 = $firstReadback; navigation_started_ms = $initialLower - $origin; initialized_by_ms = 0; method = 'native target state and matching physical audience readback' }
815
+ $startupMethod = $(if ([double]$firstOperation.settle_ms -gt 0) { 'native target state and first-slide entry onset readback' } else { 'native target state and matching physical audience readback' })
816
+ Write-Json 'startup.json' @{ version = 1; native_id = $firstOperation.native_id; readback_sha256 = $firstReadback; navigation_started_ms = $initialLower - $origin; initialized_by_ms = 0; method = $startupMethod }
656
817
  foreach ($marker in $markers) { $marker.observed_ms -= $origin; $marker.rendered_by_ms -= $origin }
657
818
  $script:activeVisit = [string]$firstOperation.id
658
819
  $script:activeScene = [string]$firstOperation.scene
820
+ $script:skippedMs = 0.0
821
+ $script:nextSkipIndex = 0
822
+ $appliedSkips.Clear()
823
+ $script:plannedSkips = $(if (!$job.verify_timing -and $null -ne $job.PSObject.Properties['static_skips'] -and $null -ne $job.static_skips) { @($job.static_skips) } else { @() })
659
824
  $script:collectAnnotations = $job.geometry_requests.Count -gt 0
660
825
  $initial = $true
661
826
  for ($operationIndex = 0; $operationIndex -lt $job.operations.Count; $operationIndex++) {
662
827
  $operation = $job.operations[$operationIndex]
663
828
  $script:annotationStartBeforeMs = [double]$operation.at_ms
664
- Wait-Until ($origin + $operation.at_ms)
829
+ Wait-UntilSchedule ([double]$operation.at_ms)
665
830
  Check-Media
666
831
  if (!$initial -and $operation.type -in @('slide', 'play')) { Wait-MediaCompletion }
667
832
  [SlideVideo.Native]::EnsureGeometry($window, $geometry)
668
833
  if ($initial) { $player = $null; $now = 0.0; $initial = $false }
669
- else { $player = Apply-Operation $operation; $now = $clock.Elapsed.TotalMilliseconds - $origin }
834
+ else { $player = Apply-Operation $operation; $now = Schedule-Now }
670
835
  $entry = @{ id = $operation.id; type = $operation.type; scheduled_ms = $operation.at_ms; observed_ms = $now }
671
836
  if ($operation.type -eq 'play') {
672
837
  $entry.media_ms = [double]$player.CurrentPosition
@@ -680,7 +845,7 @@ try {
680
845
  Check-Annotations
681
846
  }
682
847
  }
683
- Wait-Until ($origin + $job.duration_ms)
848
+ Wait-UntilSchedule ([double]$job.duration_ms)
684
849
  Check-Annotations
685
850
  if (@($annotationMonitors | Where-Object { !$_.complete }).Count -gt 0) { Fail 'ANNOTATION_GEOMETRY' 'Native playback did not complete every annotation interval.' }
686
851
  $script:collectAnnotations = $false
@@ -697,7 +862,7 @@ try {
697
862
  Wait-Until ($clock.Elapsed.TotalMilliseconds + 200)
698
863
  Stop-Recorder
699
864
  if ($recorder.ExitCode -ne 0) { Fail 'POWERPOINT_CAPTURE' ('FFmpeg exited ' + $recorder.ExitCode + '. See ffmpeg.log.') }
700
- $result = @{ version = 1; kind = 'recording'; file = $file; events = @($events.ToArray()); markers = @($markers.ToArray()); references = @($references.ToArray()); annotation_geometry = @($annotationGeometry.ToArray()); dependencies = (Dependencies) }
865
+ $result = @{ version = 1; kind = 'recording'; file = $file; events = @($events.ToArray()); markers = @($markers.ToArray()); references = @($references.ToArray()); annotation_geometry = @($annotationGeometry.ToArray()); applied_skips = @($appliedSkips.ToArray()); dependencies = (Dependencies) }
701
866
  }
702
867
  } catch {
703
868
  $message = $_.Exception.Message