@slidevideo/cli 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/IMPRESSUM.md +13 -0
- package/LICENSE-TERMS.md +58 -0
- package/README.md +25 -0
- package/addons/slidevideo/geometry.ts +127 -0
- package/addons/slidevideo/global-top.vue +232 -0
- package/addons/slidevideo/package.json +1 -0
- package/addons/slidevideo/playback-entries.ts +14 -0
- package/addons/slidevideo/preview.ts +157 -0
- package/dist/adapters/browser-runtime.d.ts +37 -0
- package/dist/adapters/browser-runtime.js +1 -0
- package/dist/adapters/edge.d.ts +7 -0
- package/dist/adapters/edge.js +46 -0
- package/dist/adapters/elevenlabs.d.ts +7 -0
- package/dist/adapters/elevenlabs.js +58 -0
- package/dist/adapters/powerpoint-preview.d.ts +2 -0
- package/dist/adapters/powerpoint-preview.js +18 -0
- package/dist/adapters/powerpoint.d.ts +21 -0
- package/dist/adapters/powerpoint.js +434 -0
- package/dist/adapters/registry.d.ts +4 -0
- package/dist/adapters/registry.js +13 -0
- package/dist/adapters/slidev-inputs.d.ts +1 -0
- package/dist/adapters/slidev-inputs.js +86 -0
- package/dist/adapters/slidev-inspection.d.ts +3 -0
- package/dist/adapters/slidev-inspection.js +79 -0
- package/dist/adapters/slidev-server.d.ts +1 -0
- package/dist/adapters/slidev-server.js +48 -0
- package/dist/adapters/slidev.d.ts +30 -0
- package/dist/adapters/slidev.js +251 -0
- package/dist/annotation-paint.d.ts +19 -0
- package/dist/annotation-paint.js +13 -0
- package/dist/annotations.d.ts +27 -0
- package/dist/annotations.js +115 -0
- package/dist/assembly.d.ts +48 -0
- package/dist/assembly.js +138 -0
- package/dist/calibration.d.ts +24 -0
- package/dist/calibration.js +346 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +180 -0
- package/dist/compositor.d.ts +18 -0
- package/dist/compositor.js +155 -0
- package/dist/contracts.d.ts +358 -0
- package/dist/contracts.js +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +15 -0
- package/dist/executables.d.ts +23 -0
- package/dist/executables.js +165 -0
- package/dist/installation.d.ts +6 -0
- package/dist/installation.js +32 -0
- package/dist/license-key.d.ts +12 -0
- package/dist/license-key.js +55 -0
- package/dist/license-status.d.ts +16 -0
- package/dist/license-status.js +12 -0
- package/dist/media.d.ts +12 -0
- package/dist/media.js +57 -0
- package/dist/overlay-assets.d.ts +2 -0
- package/dist/overlay-assets.js +58 -0
- package/dist/pipeline.d.ts +50 -0
- package/dist/pipeline.js +257 -0
- package/dist/preview/contracts.d.ts +34 -0
- package/dist/preview/contracts.js +1 -0
- package/dist/preview/player.d.ts +1 -0
- package/dist/preview/player.js +129 -0
- package/dist/preview/server.d.ts +1 -0
- package/dist/preview/server.js +112 -0
- package/dist/preview/view.d.ts +1 -0
- package/dist/preview/view.js +36 -0
- package/dist/revoked-keys.json +1 -0
- package/dist/run.d.ts +12 -0
- package/dist/run.js +109 -0
- package/dist/setup-install.d.ts +7 -0
- package/dist/setup-install.js +98 -0
- package/dist/setup-license.d.ts +2 -0
- package/dist/setup-license.js +63 -0
- package/dist/setup.d.ts +34 -0
- package/dist/setup.js +218 -0
- package/dist/speech.d.ts +6 -0
- package/dist/speech.js +125 -0
- package/dist/storyboard.d.ts +6 -0
- package/dist/storyboard.js +86 -0
- package/dist/timing.d.ts +6 -0
- package/dist/timing.js +162 -0
- package/package.json +134 -0
- package/schemas/annotation-geometry.v1.json +130 -0
- package/schemas/revoked-keys.schema.json +11 -0
- package/schemas/run-manifest.v1.json +96 -0
- package/schemas/schedule.v1.json +108 -0
- package/schemas/schedule.v2.json +496 -0
- package/schemas/speech.v1.json +173 -0
- package/schemas/storyboard.v1.json +461 -0
- package/schemas/storyboard.v2.json +802 -0
- package/schemas/timing-evidence.v1.json +129 -0
- package/skills/slidevideo/SKILL.md +56 -0
- package/skills/slidevideo/references/production.md +76 -0
- package/skills/slidevideo/references/storyboard.md +272 -0
- package/tools/edge-tts/edge-tts.py +19 -0
- package/tools/edge-tts/requirements.lock +34 -0
- package/tools/powerpoint/Native.cs +277 -0
- package/tools/powerpoint/powerpoint.ps1 +714 -0
- package/tools/powerpoint/preview.ps1 +100 -0
- package/tools/powerpoint/requirements.json +11 -0
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[Parameter(Mandatory = $true, ParameterSetName = 'Production')][string]$Request,
|
|
3
|
+
[Parameter(Mandatory = $true, ParameterSetName = 'Setup')][switch]$CheckSetup
|
|
4
|
+
)
|
|
5
|
+
$ErrorActionPreference = 'Stop'
|
|
6
|
+
Set-StrictMode -Version Latest
|
|
7
|
+
if ($CheckSetup) {
|
|
8
|
+
$supportedPowerShell = $PSVersionTable.PSVersion.Major -eq 5 -and $PSVersionTable.PSVersion.Minor -eq 1
|
|
9
|
+
Add-Type -AssemblyName System.Drawing
|
|
10
|
+
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
11
|
+
Add-Type -Path (Join-Path $PSScriptRoot 'Native.cs') -ReferencedAssemblies System.Drawing
|
|
12
|
+
@{
|
|
13
|
+
powershell = $supportedPowerShell
|
|
14
|
+
powerpoint = $null -ne [type]::GetTypeFromProgID('PowerPoint.Application')
|
|
15
|
+
desktop = [SlideVideo.Native]::HasInteractiveDesktop()
|
|
16
|
+
} | ConvertTo-Json -Compress
|
|
17
|
+
exit 0
|
|
18
|
+
}
|
|
19
|
+
$requestFile = [IO.Path]::GetFullPath($Request)
|
|
20
|
+
$job = Get-Content -Raw -Encoding UTF8 -LiteralPath $requestFile | ConvertFrom-Json
|
|
21
|
+
$directory = [IO.Path]::GetFullPath($job.directory)
|
|
22
|
+
$utf8 = [Text.UTF8Encoding]::new($false)
|
|
23
|
+
if ($job.mode -eq 'stop-recorder') {
|
|
24
|
+
if ($job.version -ne 1) { throw 'Unsupported recorder shutdown request.' }
|
|
25
|
+
Add-Type -AssemblyName System.Drawing
|
|
26
|
+
Add-Type -Path (Join-Path $PSScriptRoot 'Native.cs') -ReferencedAssemblies System.Drawing
|
|
27
|
+
[SlideVideo.Native]::StopRecorder([int]$job.recorder_pid, [long]$job.recorder_started_ticks, [string]$job.recorder_process_name)
|
|
28
|
+
exit 0
|
|
29
|
+
}
|
|
30
|
+
$app = $null
|
|
31
|
+
$presentation = $null
|
|
32
|
+
$show = $null
|
|
33
|
+
$recorder = $null
|
|
34
|
+
$recorderError = $null
|
|
35
|
+
$mutex = $null
|
|
36
|
+
$locked = $false
|
|
37
|
+
$createdApplication = $false
|
|
38
|
+
$clock = [Diagnostics.Stopwatch]::StartNew()
|
|
39
|
+
$origin = 0.0
|
|
40
|
+
$events = [Collections.Generic.List[object]]::new()
|
|
41
|
+
$markers = [Collections.Generic.List[object]]::new()
|
|
42
|
+
$references = [Collections.Generic.List[object]]::new()
|
|
43
|
+
$cleanup = [Collections.Generic.List[string]]::new()
|
|
44
|
+
$activeMedia = [Collections.Generic.List[object]]::new()
|
|
45
|
+
$annotationMonitors = [Collections.Generic.List[object]]::new()
|
|
46
|
+
$annotationGeometry = [Collections.Generic.List[object]]::new()
|
|
47
|
+
$collectAnnotations = $false
|
|
48
|
+
$annotationStartBeforeMs = [double]::PositiveInfinity
|
|
49
|
+
$activeVisit = ''
|
|
50
|
+
$activeScene = ''
|
|
51
|
+
$failure = $null
|
|
52
|
+
$result = $null
|
|
53
|
+
$parentStartedTicks = $null
|
|
54
|
+
$ppPlaying = 0
|
|
55
|
+
$ppPaused = 1
|
|
56
|
+
$ppStopped = 2
|
|
57
|
+
$script:ffmpegVersion = 'not required'
|
|
58
|
+
$geometry = $null
|
|
59
|
+
|
|
60
|
+
function Write-Json([string]$name, $value) {
|
|
61
|
+
$path = Join-Path $directory $name
|
|
62
|
+
[IO.File]::WriteAllText(($path + '.tmp'), (ConvertTo-Json -InputObject $value -Depth 50), $utf8)
|
|
63
|
+
Move-Item -LiteralPath ($path + '.tmp') -Destination $path -Force
|
|
64
|
+
}
|
|
65
|
+
function Fail([string]$code, [string]$message) { throw ($code + ': ' + $message) }
|
|
66
|
+
function Check-Cancel {
|
|
67
|
+
if (Test-Path -LiteralPath (Join-Path $directory 'cancel')) { Fail 'INTERRUPTED' 'Native production was cancelled.' }
|
|
68
|
+
if ($job.parent_pid -gt 0) {
|
|
69
|
+
try { $parent = [Diagnostics.Process]::GetProcessById([int]$job.parent_pid) }
|
|
70
|
+
catch { Fail 'INTERRUPTED' 'The CLI process exited.' }
|
|
71
|
+
if ($null -ne $parentStartedTicks -and $parent.StartTime.ToUniversalTime().Ticks -ne $parentStartedTicks) { Fail 'INTERRUPTED' 'The CLI process identity changed.' }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function Wait-Until([double]$deadline) {
|
|
75
|
+
while ($clock.Elapsed.TotalMilliseconds -lt $deadline) {
|
|
76
|
+
Check-Cancel
|
|
77
|
+
if ($null -ne $recorder -and $recorder.HasExited) { Fail 'POWERPOINT_CAPTURE' 'FFmpeg exited during native playback.' }
|
|
78
|
+
if ($activeMedia.Count -gt 0) { Check-Media }
|
|
79
|
+
if ($collectAnnotations) { Check-Annotations }
|
|
80
|
+
$remaining = $deadline - $clock.Elapsed.TotalMilliseconds
|
|
81
|
+
if ($collectAnnotations) {
|
|
82
|
+
foreach ($monitor in $annotationMonitors) {
|
|
83
|
+
if (!$monitor.complete) { $remaining = [Math]::Min($remaining, $origin + $monitor.next_sample_ms - $clock.Elapsed.TotalMilliseconds) }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if ($remaining -gt 4) { Start-Sleep -Milliseconds ([Math]::Min(20, [int]($remaining - 1))) }
|
|
87
|
+
else { [Threading.Thread]::Sleep(1) }
|
|
88
|
+
}
|
|
89
|
+
if ($collectAnnotations) { Check-Annotations }
|
|
90
|
+
}
|
|
91
|
+
function File-Hash([string]$file) { return (Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash.ToLowerInvariant() }
|
|
92
|
+
function Part-Name([string]$owner, [string]$target) {
|
|
93
|
+
$uri = [Uri]::new([Uri]::new('http://slidevideo/' + $owner), $target)
|
|
94
|
+
if ($uri.Host -ne 'slidevideo') { Fail 'POWERPOINT_DEPENDENCY' ('External package target ' + $target) }
|
|
95
|
+
return [Uri]::UnescapeDataString($uri.AbsolutePath.TrimStart('/'))
|
|
96
|
+
}
|
|
97
|
+
function Read-Part($zip, [string]$name) {
|
|
98
|
+
$entry = $zip.GetEntry($name)
|
|
99
|
+
if ($null -eq $entry) { Fail 'POWERPOINT_PACKAGE' ('Missing PPTX part ' + $name) }
|
|
100
|
+
$reader = [IO.StreamReader]::new($entry.Open())
|
|
101
|
+
try { return [xml]$reader.ReadToEnd() } finally { $reader.Dispose() }
|
|
102
|
+
}
|
|
103
|
+
function Part-Hash($zip, [string]$name) {
|
|
104
|
+
$entry = $zip.GetEntry($name)
|
|
105
|
+
if ($null -eq $entry) { Fail 'POWERPOINT_PACKAGE' ('Missing embedded media ' + $name) }
|
|
106
|
+
$stream = $entry.Open()
|
|
107
|
+
$sha = [Security.Cryptography.SHA256]::Create()
|
|
108
|
+
try { return [BitConverter]::ToString($sha.ComputeHash($stream)).Replace('-', '').ToLowerInvariant() }
|
|
109
|
+
finally { $sha.Dispose(); $stream.Dispose() }
|
|
110
|
+
}
|
|
111
|
+
function Read-Package([string]$file) {
|
|
112
|
+
$zip = [IO.Compression.ZipFile]::OpenRead($file)
|
|
113
|
+
$media = [Collections.Generic.List[object]]::new()
|
|
114
|
+
$unsupported = [Collections.Generic.List[object]]::new()
|
|
115
|
+
$targets = [Collections.Generic.List[object]]::new()
|
|
116
|
+
try {
|
|
117
|
+
foreach ($entry in $zip.Entries) {
|
|
118
|
+
if ($entry.FullName.EndsWith('.rels')) {
|
|
119
|
+
$rels = Read-Part $zip $entry.FullName
|
|
120
|
+
foreach ($relationship in $rels.DocumentElement.ChildNodes) {
|
|
121
|
+
if ($relationship.GetAttribute('TargetMode') -eq 'External' -and !$relationship.GetAttribute('Type').EndsWith('/hyperlink')) {
|
|
122
|
+
$unsupported.Add(@{ slide = ''; reason = ('External rendering relationship is unsupported: ' + $entry.FullName + ' -> ' + $relationship.GetAttribute('Target')) })
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if ($entry.FullName -match '\.(gif|svg|glb|gltf)$' -or $entry.FullName -match '(^|/)(activeX|embeddings)/') {
|
|
127
|
+
$unsupported.Add(@{ slide = ''; reason = ('Dynamic or externally controlled package content is unsupported: ' + $entry.FullName) })
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
$document = Read-Part $zip 'ppt/presentation.xml'
|
|
131
|
+
$rels = Read-Part $zip 'ppt/_rels/presentation.xml.rels'
|
|
132
|
+
$mapping = @{}
|
|
133
|
+
foreach ($relationship in $rels.DocumentElement.ChildNodes) { $mapping[$relationship.GetAttribute('Id')] = $relationship.GetAttribute('Target') }
|
|
134
|
+
$index = 0
|
|
135
|
+
foreach ($slideId in $document.SelectNodes('//*[local-name()="sldIdLst"]/*')) {
|
|
136
|
+
$index++
|
|
137
|
+
$nativeId = [int]$slideId.GetAttribute('id')
|
|
138
|
+
$relationshipId = $slideId.GetAttribute('id', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships')
|
|
139
|
+
$part = Part-Name 'ppt/presentation.xml' $mapping[$relationshipId]
|
|
140
|
+
$slideXml = Read-Part $zip $part
|
|
141
|
+
foreach ($identity in $slideXml.SelectNodes('//*[local-name()="cNvPr"]')) {
|
|
142
|
+
$owner = $identity.ParentNode.ParentNode
|
|
143
|
+
$reasons = [Collections.Generic.List[string]]::new()
|
|
144
|
+
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()) })
|
|
149
|
+
}
|
|
150
|
+
$slideRelations = @{}
|
|
151
|
+
$relationPart = ([IO.Path]::GetDirectoryName($part).Replace('\', '/') + '/_rels/' + [IO.Path]::GetFileName($part) + '.rels')
|
|
152
|
+
if ($null -ne $zip.GetEntry($relationPart)) {
|
|
153
|
+
$slideRels = Read-Part $zip $relationPart
|
|
154
|
+
foreach ($relationship in $slideRels.DocumentElement.ChildNodes) { $slideRelations[$relationship.GetAttribute('Id')] = $relationship }
|
|
155
|
+
}
|
|
156
|
+
foreach ($picture in $slideXml.SelectNodes('//*[local-name()="pic"]')) {
|
|
157
|
+
$video = $picture.SelectSingleNode('.//*[local-name()="videoFile"]')
|
|
158
|
+
$audio = $picture.SelectSingleNode('.//*[local-name()="audioFile"]')
|
|
159
|
+
if ($null -ne $audio) { $unsupported.Add(@{ slide = [string]$nativeId; reason = 'Native audio shapes and recorded narration are unsupported.' }) }
|
|
160
|
+
if ($null -eq $video) { continue }
|
|
161
|
+
$shape = $picture.SelectSingleNode('./*[local-name()="nvPicPr"]/*[local-name()="cNvPr"]')
|
|
162
|
+
$embedded = $picture.SelectSingleNode('.//*[local-name()="media"]')
|
|
163
|
+
$linkId = $video.GetAttribute('link', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships')
|
|
164
|
+
$relation = $slideRelations[$linkId]
|
|
165
|
+
if ($null -eq $relation -or $relation.GetAttribute('TargetMode') -eq 'External') {
|
|
166
|
+
$unsupported.Add(@{ slide = [string]$nativeId; reason = ('Linked or online video is unsupported: ' + $shape.GetAttribute('name')) }); continue
|
|
167
|
+
}
|
|
168
|
+
$source = Part-Name $part $relation.GetAttribute('Target')
|
|
169
|
+
if ($null -ne $embedded) {
|
|
170
|
+
$embedId = $embedded.GetAttribute('embed', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships')
|
|
171
|
+
if (!$embedId -or !$slideRelations.ContainsKey($embedId) -or (Part-Name $part $slideRelations[$embedId].GetAttribute('Target')) -ne $source) {
|
|
172
|
+
$unsupported.Add(@{ slide = [string]$nativeId; reason = 'Video relationships do not identify one embedded source.' })
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
$crop = $picture.SelectSingleNode('.//*[local-name()="srcRect"]')
|
|
176
|
+
$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')) })
|
|
179
|
+
}
|
|
180
|
+
$shapeId = [int]$shape.GetAttribute('id')
|
|
181
|
+
$nativeVideo = $slideXml.SelectSingleNode(('//*[local-name()="video"][.//*[local-name()="spTgt"][@spid="' + $shapeId + '"]]'))
|
|
182
|
+
$fullscreen = 0
|
|
183
|
+
if ($null -ne $nativeVideo -and $nativeVideo.GetAttribute('fullScrn') -in @('1', 'true')) { $fullscreen = -1 }
|
|
184
|
+
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')) }) }
|
|
186
|
+
}
|
|
187
|
+
$media.Add(@{ id = $shape.GetAttribute('name'); native_id = $nativeId; shape = $shapeId; sha256 = (Part-Hash $zip $source); part = $source; fullscreen = $fullscreen })
|
|
188
|
+
}
|
|
189
|
+
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
|
+
$unsupported.Add(@{ slide = [string]$nativeId; reason = 'Native audio, animation or slide sounds, OLE and dynamic content are unsupported.' })
|
|
191
|
+
}
|
|
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.' }) }
|
|
197
|
+
}
|
|
198
|
+
foreach ($node in $slideXml.SelectNodes('//*[local-name()="cTn"]')) {
|
|
199
|
+
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.' }) }
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return @{ media = @($media.ToArray()); unsupported = @($unsupported.ToArray()); targets = @($targets.ToArray()) }
|
|
205
|
+
} finally { $zip.Dispose() }
|
|
206
|
+
}
|
|
207
|
+
function Open-PrivateDeck([bool]$visible) {
|
|
208
|
+
if ([type]::GetTypeFromProgID('PowerPoint.Application') -eq $null) { Fail 'POWERPOINT_DEPENDENCY' 'Install desktop Microsoft PowerPoint and launch it once before using PPTX production.' }
|
|
209
|
+
$before = @{}
|
|
210
|
+
foreach ($process in @(Get-Process -Name POWERPNT -ErrorAction SilentlyContinue)) { $before[$process.Id] = $process.StartTime.ToUniversalTime().Ticks }
|
|
211
|
+
$script:app = New-Object -ComObject PowerPoint.Application
|
|
212
|
+
$processId = [SlideVideo.Native]::WindowProcess([long]$app.HWND)
|
|
213
|
+
$process = [Diagnostics.Process]::GetProcessById($processId)
|
|
214
|
+
$script:createdApplication = !$before.ContainsKey($processId) -or $before[$processId] -ne $process.StartTime.ToUniversalTime().Ticks
|
|
215
|
+
$script:officeProcess = $processId
|
|
216
|
+
$script:presentation = $app.Presentations.Open($privateDeck, 0, 0, $(if ($visible) { -1 } else { 0 }))
|
|
217
|
+
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
|
+
}
|
|
219
|
+
function Inspect-Shapes($slide, $shapes, $package, [bool]$grouped) {
|
|
220
|
+
foreach ($shape in $shapes) {
|
|
221
|
+
Check-Cancel
|
|
222
|
+
$reasons = [Collections.Generic.List[string]]::new()
|
|
223
|
+
$bounds = @{ x = 0.0; y = 0.0; width = 0.0; height = 0.0 }
|
|
224
|
+
$visibleFromClick = 0
|
|
225
|
+
try {
|
|
226
|
+
$metadata = @($package.targets | Where-Object { $_.native_id -eq $slide.SlideID -and $_.id -eq $shape.Id })
|
|
227
|
+
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 }
|
|
234
|
+
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)
|
|
241
|
+
}
|
|
242
|
+
} 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 }
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function Inspect-Native($package) {
|
|
248
|
+
$slides = [Collections.Generic.List[object]]::new()
|
|
249
|
+
foreach ($slide in $presentation.Slides) {
|
|
250
|
+
Check-Cancel
|
|
251
|
+
$effects = [Collections.Generic.List[object]]::new()
|
|
252
|
+
foreach ($effect in $slide.TimeLine.MainSequence) {
|
|
253
|
+
$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 })
|
|
255
|
+
}
|
|
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 })
|
|
258
|
+
foreach ($shape in $slide.Shapes) {
|
|
259
|
+
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 }
|
|
263
|
+
$media = $matches[0]
|
|
264
|
+
$media.id = [string]$shape.Name
|
|
265
|
+
$media.duration_ms = [double]$shape.MediaFormat.Length
|
|
266
|
+
$media.start_ms = [double]$shape.MediaFormat.StartPoint
|
|
267
|
+
$media.end_ms = [double]$shape.MediaFormat.EndPoint
|
|
268
|
+
$media.autoplay = [int]$shape.AnimationSettings.PlaySettings.PlayOnEntry
|
|
269
|
+
$media.loop = [int]$shape.AnimationSettings.PlaySettings.LoopUntilStopped
|
|
270
|
+
$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
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
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) }
|
|
279
|
+
}
|
|
280
|
+
function Dependencies {
|
|
281
|
+
$office = [Diagnostics.Process]::GetProcessById($officeProcess).MainModule.FileVersionInfo.FileVersion
|
|
282
|
+
return @{ powerpoint = [string]$app.Version; office_build = $office; windows = [Environment]::OSVersion.VersionString; powershell = $PSVersionTable.PSVersion.ToString(); ffmpeg = $script:ffmpegVersion }
|
|
283
|
+
}
|
|
284
|
+
function Slide-ById([int]$nativeId) { return $presentation.Slides.FindBySlideID($nativeId) }
|
|
285
|
+
function Select-Slide([int]$nativeId) {
|
|
286
|
+
$slide = Slide-ById $nativeId
|
|
287
|
+
$show.View.GotoSlide([int]$slide.SlideIndex, -1)
|
|
288
|
+
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
|
+
}
|
|
290
|
+
function Apply-Operation($operation) {
|
|
291
|
+
if ($operation.type -eq 'slide') { Select-Slide $operation.native_id; $script:activeVisit = [string]$operation.id; $script:activeScene = [string]$operation.scene }
|
|
292
|
+
elseif ($operation.type -eq 'reveal') {
|
|
293
|
+
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) }
|
|
296
|
+
} elseif ($operation.type -eq 'play') {
|
|
297
|
+
if ([int]$show.View.Slide.SlideID -ne $operation.native_id) { Fail 'POWERPOINT_MEDIA' ('Wrong native slide for media ' + $operation.id) }
|
|
298
|
+
$player = $show.View.Player([int]$operation.shape)
|
|
299
|
+
$player.Stop()
|
|
300
|
+
$player.CurrentPosition = 0
|
|
301
|
+
$player.Play()
|
|
302
|
+
return $player
|
|
303
|
+
} else { Fail 'POWERPOINT_PROTOCOL' ('Unknown operation ' + $operation.type) }
|
|
304
|
+
}
|
|
305
|
+
function Prepare-Annotations($catalog) {
|
|
306
|
+
foreach ($annotation in $job.annotations) {
|
|
307
|
+
$context = 'Annotation ' + $annotation.id + ', slide ' + $annotation.slide + ', visit ' + $annotation.visit
|
|
308
|
+
$visits = @($job.operations | Where-Object { $_.type -eq 'slide' -and $_.id -eq $annotation.visit -and $_.native_id -eq $annotation.native_id -and $_.scene -eq $annotation.scene })
|
|
309
|
+
if ($visits.Count -ne 1) { Fail 'ANNOTATION_STATE' ($context + ': no unique scheduled slide visit.') }
|
|
310
|
+
if ($annotation.start_ms -lt $visits[0].at_ms + $visits[0].settle_ms -or $annotation.end_ms -le $annotation.start_ms -or $annotation.end_ms -gt $job.duration_ms) { Fail 'ANNOTATION_INTERVAL' ($context + ': interval is outside settled playback.') }
|
|
311
|
+
$click = 0
|
|
312
|
+
foreach ($operation in $job.operations) {
|
|
313
|
+
if ($operation.type -notin @('slide', 'reveal')) { continue }
|
|
314
|
+
if ($operation.at_ms -le $annotation.start_ms) {
|
|
315
|
+
if ($operation.type -eq 'slide') { $visit = [string]$operation.id; $click = 0 }
|
|
316
|
+
else { $click = [int]$operation.click }
|
|
317
|
+
if ($operation.at_ms + $operation.settle_ms -gt $annotation.start_ms) { Fail 'ANNOTATION_INTERVAL' ($context + ': interval starts before a native action settles.') }
|
|
318
|
+
} elseif ($operation.at_ms -lt $annotation.end_ms) { Fail 'ANNOTATION_INTERVAL' ($context + ': interval crosses a native slide or reveal action.') }
|
|
319
|
+
}
|
|
320
|
+
if ($visit -ne $annotation.visit -or $click -ne $annotation.click) { Fail 'ANNOTATION_STATE' ($context + ': resolved click or visit does not match native operations.') }
|
|
321
|
+
if ($annotation.target.type -eq 'element') { Fail 'ANNOTATION_TARGET' ($context + ': use an existing native shape ID or normalized region; selectors are unsupported.') }
|
|
322
|
+
if ($annotation.target.type -eq 'shape') {
|
|
323
|
+
$slides = @($catalog.slides | Where-Object { $_.native_id -eq $annotation.native_id })
|
|
324
|
+
$matches = @($slides[0].shapes | Where-Object { $_.id -eq $annotation.target.id })
|
|
325
|
+
if ($matches.Count -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $annotation.target.id + ': identity is missing or ambiguous.') }
|
|
326
|
+
if ($matches[0].unsupported.Count -gt 0 -or $annotation.click -lt $matches[0].visible_from_click) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $annotation.target.id + ' (' + $matches[0].name + '): unsupported or hidden target. ' + ($matches[0].unsupported -join '; ')) }
|
|
327
|
+
}
|
|
328
|
+
$annotationMonitors.Add(@{ annotation = $annotation; geometry = $null; next_sample_ms = [double]$annotation.start_ms; complete = $false })
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function Measure-Annotation($annotation, [bool]$allowPaused = $false) {
|
|
332
|
+
$context = 'Annotation ' + $annotation.id + ', slide ' + $annotation.slide + ', visit ' + $annotation.visit + ', click ' + $annotation.click
|
|
333
|
+
[SlideVideo.Native]::EnsureGeometry($window, $geometry)
|
|
334
|
+
if ($activeVisit -ne $annotation.visit -or $activeScene -ne $annotation.scene -or [int]$show.View.Slide.SlideID -ne $annotation.native_id -or [int]$show.View.GetClickIndex() -ne $annotation.click -or ([int]$show.View.State -ne 1 -and !($allowPaused -and [int]$show.View.State -eq 2))) { Fail 'ANNOTATION_STATE' ($context + ': actual slideshow state changed.') }
|
|
335
|
+
if ($annotation.target.type -eq 'region') {
|
|
336
|
+
$bounds = @{ x = [double]$annotation.target.x; y = [double]$annotation.target.y; width = [double]$annotation.target.width; height = [double]$annotation.target.height }
|
|
337
|
+
} else {
|
|
338
|
+
$matches = @($show.View.Slide.Shapes | Where-Object { $_.Id -eq $annotation.target.id })
|
|
339
|
+
if ($matches.Count -ne 1) { Fail 'ANNOTATION_TARGET' ($context + ', shape ' + $annotation.target.id + ': actual shape is missing or ambiguous.') }
|
|
340
|
+
$shape = $matches[0]
|
|
341
|
+
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 ' + $annotation.target.id + ': actual target is hidden, grouped or transformed.') }
|
|
342
|
+
$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 }
|
|
343
|
+
}
|
|
344
|
+
foreach ($value in $bounds.Values) { if ([double]::IsNaN($value) -or [double]::IsInfinity($value)) { Fail 'ANNOTATION_GEOMETRY' ($context + ': nonfinite bounds.') } }
|
|
345
|
+
if ($bounds.x -lt 0 -or $bounds.y -lt 0 -or $bounds.width -le 0 -or $bounds.height -le 0 -or $bounds.x + $bounds.width -gt 1.000001 -or $bounds.y + $bounds.height -gt 1.000001) { Fail 'ANNOTATION_GEOMETRY' ($context + ': target is degenerate or clipped by the slide.') }
|
|
346
|
+
return $bounds
|
|
347
|
+
}
|
|
348
|
+
function Check-Annotations {
|
|
349
|
+
foreach ($monitor in $annotationMonitors) {
|
|
350
|
+
if ($monitor.complete) { continue }
|
|
351
|
+
$annotation = $monitor.annotation
|
|
352
|
+
if ($null -eq $monitor.geometry -and $annotation.start_ms -ge $annotationStartBeforeMs) { continue }
|
|
353
|
+
$now = $clock.Elapsed.TotalMilliseconds - $origin
|
|
354
|
+
if ($now -lt $monitor.next_sample_ms -and $now -lt $annotation.end_ms) { continue }
|
|
355
|
+
if ($null -eq $monitor.geometry -and $now -ge $annotation.end_ms) { Fail 'ANNOTATION_INTERVAL' ('Annotation ' + $annotation.id + ': native playback missed the entire interval.') }
|
|
356
|
+
$bounds = Measure-Annotation $annotation
|
|
357
|
+
$observed = $clock.Elapsed.TotalMilliseconds - $origin
|
|
358
|
+
if ($null -eq $monitor.geometry) {
|
|
359
|
+
if ($observed -ge $annotation.end_ms) { Fail 'ANNOTATION_INTERVAL' ('Annotation ' + $annotation.id + ': initial measurement completed after the interval.') }
|
|
360
|
+
if ($observed - $annotation.start_ms -gt 100) { Fail 'ANNOTATION_INTERVAL' ('Annotation ' + $annotation.id + ': initial native measurement exceeded the interval boundary by 100 ms.') }
|
|
361
|
+
$monitor.geometry = @{ id = $annotation.id; scene = $annotation.scene; slide = $annotation.slide; visit = $annotation.visit; click = $annotation.click; start_ms = $annotation.start_ms; end_ms = $annotation.end_ms; observed_start_ms = $observed; observed_end_ms = $observed; viewport = @{ width = [int]$job.output.width; height = [int]$job.output.height }; content = @{ x = $outputContent.x; y = $outputContent.y; width = $outputContent.width; height = $outputContent.height }; bounds = $bounds; samples = 1 }
|
|
362
|
+
$annotationGeometry.Add($monitor.geometry)
|
|
363
|
+
} else {
|
|
364
|
+
foreach ($key in @('x', 'y', 'width', 'height')) {
|
|
365
|
+
$pixels = $(if ($key -in @('x', 'width')) { $outputContent.width } else { $outputContent.height })
|
|
366
|
+
if ([Math]::Abs($bounds[$key] - $monitor.geometry.bounds[$key]) * $pixels -gt 0.5) { Fail 'ANNOTATION_MOVING_TARGET' ('Annotation ' + $annotation.id + ': target moved during its native interval.') }
|
|
367
|
+
}
|
|
368
|
+
$monitor.geometry.samples++
|
|
369
|
+
$monitor.geometry.observed_end_ms = $observed
|
|
370
|
+
}
|
|
371
|
+
$monitor.next_sample_ms = [Math]::Min($observed + 50, [double]$annotation.end_ms)
|
|
372
|
+
if ($now -ge $annotation.end_ms) {
|
|
373
|
+
if ($observed - $annotation.end_ms -gt 100) { Fail 'ANNOTATION_INTERVAL' ('Annotation ' + $annotation.id + ': final native measurement exceeded the interval boundary by 100 ms.') }
|
|
374
|
+
$monitor.complete = $true
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function Check-Media {
|
|
379
|
+
$now = $clock.Elapsed.TotalMilliseconds - $origin
|
|
380
|
+
foreach ($monitor in @($activeMedia.ToArray())) {
|
|
381
|
+
$position = [double]$monitor.player.CurrentPosition
|
|
382
|
+
$state = [int]$monitor.player.State
|
|
383
|
+
if ($position -gt $monitor.last_position + 1) { $monitor.last_position = $position; $monitor.advanced_at = $now }
|
|
384
|
+
$expected = $now - $monitor.operation.at_ms
|
|
385
|
+
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) {
|
|
386
|
+
$events.Add(@{ id = ($monitor.operation.id + ':ended'); type = 'media-ended'; scheduled_ms = $monitor.operation.end_ms; observed_ms = $now; media_ms = $monitor.last_position })
|
|
387
|
+
[void]$activeMedia.Remove($monitor)
|
|
388
|
+
} 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)) {
|
|
389
|
+
Fail 'POWERPOINT_MEDIA_STALL' ('Native media stalled: ' + $monitor.operation.id + ', expected ' + [int]$expected + ' ms, observed ' + $position + ' ms, state ' + $state)
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function Wait-MediaCompletion {
|
|
394
|
+
Check-Media
|
|
395
|
+
foreach ($monitor in @($activeMedia.ToArray())) {
|
|
396
|
+
if ($monitor.last_position -lt $monitor.operation.source_duration_ms - 200) {
|
|
397
|
+
Fail 'POWERPOINT_MEDIA_STALL' ('Native media is not within completion tolerance at the action boundary: ' + $monitor.operation.id)
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
while ($activeMedia.Count -gt 0) {
|
|
401
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 5)
|
|
402
|
+
Check-Media
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function New-Marker([string]$color) {
|
|
406
|
+
$slide = $presentation.Slides.Add($presentation.Slides.Count + 1, 12)
|
|
407
|
+
$slide.Name = 'slidevideo-marker-' + $color.TrimStart('#')
|
|
408
|
+
$slide.FollowMasterBackground = 0
|
|
409
|
+
$slide.DisplayMasterShapes = 0
|
|
410
|
+
$slide.Background.Fill.Solid()
|
|
411
|
+
$red = [Convert]::ToInt32($color.Substring(1, 2), 16)
|
|
412
|
+
$green = [Convert]::ToInt32($color.Substring(3, 2), 16)
|
|
413
|
+
$blue = [Convert]::ToInt32($color.Substring(5, 2), 16)
|
|
414
|
+
$slide.Background.Fill.ForeColor.RGB = $red + ($green -shl 8) + ($blue -shl 16)
|
|
415
|
+
$slide.SlideShowTransition.EntryEffect = 0
|
|
416
|
+
$slide.SlideShowTransition.AdvanceOnTime = 0
|
|
417
|
+
return [int]$slide.SlideIndex
|
|
418
|
+
}
|
|
419
|
+
function Show-Marker([string]$color) {
|
|
420
|
+
Check-Cancel
|
|
421
|
+
$lower = $clock.Elapsed.TotalMilliseconds
|
|
422
|
+
$show.View.GotoSlide([int]$markerSlides[$color], -1)
|
|
423
|
+
$deadline = $lower + 5000
|
|
424
|
+
do {
|
|
425
|
+
Check-Cancel
|
|
426
|
+
$painted = [SlideVideo.Native]::ColorPresent($window, $geometry, $color)
|
|
427
|
+
$upper = $clock.Elapsed.TotalMilliseconds
|
|
428
|
+
if (!$painted) { Start-Sleep -Milliseconds 1 }
|
|
429
|
+
} while (!$painted -and $upper -lt $deadline)
|
|
430
|
+
if (!$painted) { Fail 'POWERPOINT_MARKER' ('The audience marker did not paint: ' + $color) }
|
|
431
|
+
$measured = [SlideVideo.Native]::Measure($window, $color, $deckAspect)
|
|
432
|
+
if ($measured.left -ne $geometry.left -or $measured.top -ne $geometry.top -or $measured.width -ne $geometry.width -or $measured.height -ne $geometry.height) { Fail 'POWERPOINT_GEOMETRY' 'The actual audience rectangle changed.' }
|
|
433
|
+
$markers.Add(@{ color = $color; observed_ms = $lower; rendered_by_ms = $upper; paint_interval_ms = $upper - $lower })
|
|
434
|
+
Wait-Until ($upper + 350)
|
|
435
|
+
}
|
|
436
|
+
function Save-Reference([string]$label) {
|
|
437
|
+
$raw = Join-Path $directory ($label + '-native.png')
|
|
438
|
+
$file = Join-Path $directory ($label + '.png')
|
|
439
|
+
[SlideVideo.Native]::Save($window, $geometry, $raw, $geometry.width, $geometry.height)
|
|
440
|
+
$process = [Diagnostics.Process]::new()
|
|
441
|
+
$process.StartInfo = [Diagnostics.ProcessStartInfo]::new($ffmpeg, ('-v error -xerror -i "' + $raw + '" -vf "' + $scaleFilter + '" -frames:v 1 "' + $file + '"'))
|
|
442
|
+
$process.StartInfo.UseShellExecute = $false
|
|
443
|
+
$process.StartInfo.CreateNoWindow = $true
|
|
444
|
+
$process.StartInfo.RedirectStandardError = $true
|
|
445
|
+
[void]$process.Start()
|
|
446
|
+
$diagnostic = $process.StandardError.ReadToEndAsync()
|
|
447
|
+
if (!$process.WaitForExit(30000)) { $process.Kill(); Fail 'POWERPOINT_REFERENCE' 'Native reference scaling timed out.' }
|
|
448
|
+
if ($process.ExitCode -ne 0) { Fail 'POWERPOINT_REFERENCE' $diagnostic.GetAwaiter().GetResult() }
|
|
449
|
+
$process.Dispose()
|
|
450
|
+
return $file
|
|
451
|
+
}
|
|
452
|
+
function Rehearse {
|
|
453
|
+
Select-Slide $job.operations[0].native_id
|
|
454
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 300)
|
|
455
|
+
$number = 0
|
|
456
|
+
foreach ($operation in $job.operations) {
|
|
457
|
+
Check-Cancel
|
|
458
|
+
$number++
|
|
459
|
+
$before = Save-Reference ('reference-' + $number + '-before')
|
|
460
|
+
$exclude = @($job.media | Where-Object { $_.native_id -eq [int]$show.View.Slide.SlideID } | ForEach-Object { @{ left = $_.left; top = $_.top; right = $_.right; bottom = $_.bottom } })
|
|
461
|
+
$player = Apply-Operation $operation
|
|
462
|
+
if ($operation.type -eq 'play') {
|
|
463
|
+
$player.Pause()
|
|
464
|
+
$samples = @(500, 1500 | Where-Object { $_ -lt $operation.source_duration_ms })
|
|
465
|
+
if ($samples.Count -eq 0) { $samples = @($operation.source_duration_ms / 2) }
|
|
466
|
+
foreach ($sample in $samples) {
|
|
467
|
+
$player.CurrentPosition = [int]$sample
|
|
468
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 250)
|
|
469
|
+
if ([Math]::Abs([double]$player.CurrentPosition - $sample) -gt $operation.frame_period_ms) { Fail 'POWERPOINT_REFERENCE' ('Native video seek is unbounded: ' + $operation.id) }
|
|
470
|
+
$after = Save-Reference ('reference-' + $number + '-sample-' + $sample)
|
|
471
|
+
$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 })
|
|
472
|
+
}
|
|
473
|
+
$player.CurrentPosition = [int][Math]::Max(0, $operation.source_duration_ms - $operation.frame_period_ms)
|
|
474
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 200)
|
|
475
|
+
$player.Pause()
|
|
476
|
+
} elseif ($operation.at_ms -gt 0) {
|
|
477
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + $operation.settle_ms + 200)
|
|
478
|
+
$after = Save-Reference ('reference-' + $number + '-after')
|
|
479
|
+
$references.Add(@{ id = $operation.id.Replace(':', '-'); expected_ms = $operation.at_ms; before = $before; after = $after; mode = 'transition'; frame_period_ms = 0; settle_ms = $operation.settle_ms; exclude = $exclude })
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
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 {} } } }
|
|
483
|
+
Write-Json 'references.json' @{ version = 1; references = @($references.ToArray()) }
|
|
484
|
+
}
|
|
485
|
+
function Stop-Recorder {
|
|
486
|
+
if ($null -eq $recorder) { return }
|
|
487
|
+
if (!$recorder.HasExited) {
|
|
488
|
+
try { $recorder.StandardInput.WriteLine('q'); $recorder.StandardInput.Flush() } catch { $cleanup.Add('Could not send graceful stop to the owned FFmpeg recorder.') }
|
|
489
|
+
if (!$recorder.WaitForExit(10000)) { $recorder.Kill(); [void]$recorder.WaitForExit(5000); $cleanup.Add('The owned FFmpeg recorder required termination after its finalization timeout.') }
|
|
490
|
+
}
|
|
491
|
+
if ($null -ne $recorderError) { [IO.File]::WriteAllText((Join-Path $directory 'ffmpeg.log'), $recorderError.GetAwaiter().GetResult(), $utf8) }
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
try {
|
|
495
|
+
[void][IO.Directory]::CreateDirectory($directory)
|
|
496
|
+
if ($job.version -ne 1 -or $job.mode -notin @('inspect', 'record', 'preview')) { Fail 'POWERPOINT_PROTOCOL' 'Unsupported native worker request.' }
|
|
497
|
+
Add-Type -AssemblyName System.Drawing
|
|
498
|
+
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
499
|
+
Add-Type -Path (Join-Path $PSScriptRoot 'Native.cs') -ReferencedAssemblies System.Drawing
|
|
500
|
+
[void][SlideVideo.Native]::SetProcessDPIAware()
|
|
501
|
+
$parentStartedTicks = [Diagnostics.Process]::GetProcessById([int]$job.parent_pid).StartTime.ToUniversalTime().Ticks
|
|
502
|
+
Check-Cancel
|
|
503
|
+
$mutex = [Threading.Mutex]::new($false, 'Local\SlideVideo.NativePowerPoint')
|
|
504
|
+
try { $locked = $mutex.WaitOne(0) } catch [Threading.AbandonedMutexException] { $locked = $true }
|
|
505
|
+
if (!$locked) { Fail 'POWERPOINT_BUSY' 'Another native PowerPoint inspection, preview or recording owns this desktop session.' }
|
|
506
|
+
if ($job.mode -eq 'record') {
|
|
507
|
+
$ffmpeg = [string]$job.ffmpeg
|
|
508
|
+
if (!(Test-Path -LiteralPath $ffmpeg -PathType Leaf) -or !(Test-Path -LiteralPath $job.ffprobe -PathType Leaf)) {
|
|
509
|
+
Fail 'POWERPOINT_DEPENDENCY' 'Install FFmpeg with gdigrab and ffprobe, then run slidevideo setup.'
|
|
510
|
+
}
|
|
511
|
+
$versionInfo = & $ffmpeg -version
|
|
512
|
+
if ($LASTEXITCODE -ne 0) { Fail 'POWERPOINT_DEPENDENCY' 'FFmpeg did not report its version.' }
|
|
513
|
+
$script:ffmpegVersion = [string]$versionInfo[0]
|
|
514
|
+
}
|
|
515
|
+
if ((File-Hash $job.deck) -ne $job.deck_sha256) { Fail 'POWERPOINT_SOURCE_CHANGED' 'The presentation changed after inspection. Start a new run.' }
|
|
516
|
+
$privateDeck = Join-Path $directory ('slidevideo-' + [Guid]::NewGuid().ToString('N') + '.pptx')
|
|
517
|
+
Copy-Item -LiteralPath $job.deck -Destination $privateDeck
|
|
518
|
+
if ((File-Hash $privateDeck) -ne $job.deck_sha256) { Fail 'POWERPOINT_SOURCE_CHANGED' 'The private deck copy does not match the inspected input.' }
|
|
519
|
+
$package = Read-Package $privateDeck
|
|
520
|
+
Open-PrivateDeck ($job.mode -ne 'inspect')
|
|
521
|
+
if ((File-Hash $job.deck) -ne $job.deck_sha256) { Fail 'POWERPOINT_SOURCE_CHANGED' 'The source presentation changed while PowerPoint opened its private copy.' }
|
|
522
|
+
if ($job.mode -eq 'inspect') { $result = Inspect-Native $package }
|
|
523
|
+
else {
|
|
524
|
+
if ($job.annotations.Count -gt 0) { Prepare-Annotations (Inspect-Native $package) }
|
|
525
|
+
foreach ($media in $job.media) {
|
|
526
|
+
$matches = @($package.media | Where-Object { $_.native_id -eq $media.native_id -and $_.shape -eq $media.shape -and $_.id -eq $media.id -and $_.sha256 -eq $media.sha256 })
|
|
527
|
+
if ($matches.Count -ne 1 -or (File-Hash $media.src) -ne $media.sha256) { Fail 'MEDIA_SOURCE_MISMATCH' ('Native video bytes no longer match ' + $media.id) }
|
|
528
|
+
}
|
|
529
|
+
foreach ($media in $package.media) {
|
|
530
|
+
$slide = Slide-ById $media.native_id
|
|
531
|
+
$shape = @($slide.Shapes | Where-Object { $_.Id -eq $media.shape })[0]
|
|
532
|
+
$shape.MediaFormat.Volume = 0
|
|
533
|
+
}
|
|
534
|
+
$deckAspect = [double]$presentation.PageSetup.SlideWidth / $presentation.PageSetup.SlideHeight
|
|
535
|
+
if ($job.mode -eq 'preview') {
|
|
536
|
+
. (Join-Path $PSScriptRoot 'preview.ps1')
|
|
537
|
+
Run-Preview
|
|
538
|
+
return
|
|
539
|
+
}
|
|
540
|
+
$markerSlides = @{}
|
|
541
|
+
foreach ($color in @('#202020', '#ff00ff', '#00ffff', '#ffff00', '#00ff00', '#ff0000', '#0000ff')) { $markerSlides[$color] = New-Marker $color }
|
|
542
|
+
$presentation.SlideShowSettings.ShowType = 2
|
|
543
|
+
$presentation.SlideShowSettings.AdvanceMode = 1
|
|
544
|
+
$presentation.SlideShowSettings.ShowWithNarration = 0
|
|
545
|
+
$presentation.SlideShowSettings.StartingSlide = 1
|
|
546
|
+
$presentation.SlideShowSettings.EndingSlide = $presentation.Slides.Count
|
|
547
|
+
$presentation.SlideShowSettings.RangeType = 1
|
|
548
|
+
$editorWindow = [long]$app.HWND
|
|
549
|
+
$script:show = $presentation.SlideShowSettings.Run()
|
|
550
|
+
$deadline = $clock.Elapsed.TotalMilliseconds + 10000
|
|
551
|
+
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)
|
|
552
|
+
if ($window -eq 0) { Fail 'POWERPOINT_WINDOW' 'Cannot identify one audience window owned by the private deck.' }
|
|
553
|
+
$initialViewState = [int]$show.View.State
|
|
554
|
+
$show.View.State = 1
|
|
555
|
+
$show.View.AcceleratorsEnabled = 0
|
|
556
|
+
$captureWidth = [Math]::Min([int]$job.output.width, 1600)
|
|
557
|
+
$captureHeight = [int][Math]::Round($captureWidth / $deckAspect)
|
|
558
|
+
[SlideVideo.Native]::Place($window, $captureWidth, $captureHeight)
|
|
559
|
+
$show.View.GotoSlide([int]$markerSlides['#ff00ff'], -1)
|
|
560
|
+
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 }
|
|
561
|
+
$geometry = $null
|
|
562
|
+
$deadline = $clock.Elapsed.TotalMilliseconds + 5000
|
|
563
|
+
do {
|
|
564
|
+
Check-Cancel
|
|
565
|
+
try { $geometry = [SlideVideo.Native]::Measure($window, '#ff00ff', $deckAspect) }
|
|
566
|
+
catch {
|
|
567
|
+
if ($clock.Elapsed.TotalMilliseconds -ge $deadline) {
|
|
568
|
+
[SlideVideo.Native]::SaveWindow($window, (Join-Path $directory 'failure-window.png'))
|
|
569
|
+
[SlideVideo.Native]::SaveDesktopWindow($window, (Join-Path $directory 'failure-desktop.png'))
|
|
570
|
+
Fail 'POWERPOINT_GEOMETRY' ('The audience marker did not establish a crop: ' + $_.Exception.Message)
|
|
571
|
+
}
|
|
572
|
+
Start-Sleep -Milliseconds 20
|
|
573
|
+
}
|
|
574
|
+
} while ($null -eq $geometry)
|
|
575
|
+
$scaleFilter = ('scale=' + $job.output.width + ':' + $job.output.height + ':force_original_aspect_ratio=decrease:flags=bicubic,pad=' + $job.output.width + ':' + $job.output.height + ':(ow-iw)/2:(oh-ih)/2,setsar=1')
|
|
576
|
+
$outputContent = [SlideVideo.Native]::OutputContent($geometry, [int]$job.output.width, [int]$job.output.height)
|
|
577
|
+
if ($job.annotations.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') }
|
|
578
|
+
$captureFilter = ('crop=' + $geometry.width + ':' + $geometry.height + ':' + $geometry.left + ':' + $geometry.top + ':exact=1,' + $scaleFilter)
|
|
579
|
+
Write-Json 'geometry.json' @{ version = 1; hwnd = $window.ToString(); rectangle = $geometry; deck_aspect = $deckAspect; requested = $job.output; filter = $captureFilter }
|
|
580
|
+
if ($job.verify_timing) { Rehearse }
|
|
581
|
+
$firstOperation = $job.operations[0]
|
|
582
|
+
if ($firstOperation.type -ne 'slide' -or $firstOperation.at_ms -ne 0) { Fail 'POWERPOINT_PROTOCOL' 'The native schedule must initialize a slide at time zero.' }
|
|
583
|
+
Select-Slide $firstOperation.native_id
|
|
584
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 200)
|
|
585
|
+
$firstReadback = [SlideVideo.Native]::Readback($window, $geometry)
|
|
586
|
+
$deadline = $clock.Elapsed.TotalMilliseconds + 5000
|
|
587
|
+
do {
|
|
588
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 30)
|
|
589
|
+
$nextReadback = [SlideVideo.Native]::Readback($window, $geometry)
|
|
590
|
+
$stable = $firstReadback -eq $nextReadback
|
|
591
|
+
$firstReadback = $nextReadback
|
|
592
|
+
} while (!$stable -and $clock.Elapsed.TotalMilliseconds -lt $deadline)
|
|
593
|
+
if (!$stable) { Fail 'POWERPOINT_READINESS' 'The initial native slide did not reach a stable startup state.' }
|
|
594
|
+
$show.View.GotoSlide([int]$markerSlides['#202020'], -1)
|
|
595
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 300)
|
|
596
|
+
if (![SlideVideo.Native]::ColorPresent($window, $geometry, '#202020')) {
|
|
597
|
+
[SlideVideo.Native]::SaveWindow($window, (Join-Path $directory 'failure-neutral.png'))
|
|
598
|
+
Write-Json 'neutral-state.json' @{ state = [int]$show.View.State; slide_id = [int]$show.View.Slide.SlideID; rgb = [int]$show.View.Slide.Background.Fill.ForeColor.RGB; range = [int]$presentation.SlideShowSettings.RangeType }
|
|
599
|
+
Fail 'POWERPOINT_MARKER' 'The neutral frame did not paint before recording.'
|
|
600
|
+
}
|
|
601
|
+
Write-Json 'prepared.json' @{ version = 1; status = 'ready'; dependencies = (Dependencies) }
|
|
602
|
+
$deadline = $clock.Elapsed.TotalMilliseconds + 120000
|
|
603
|
+
while (!(Test-Path -LiteralPath (Join-Path $directory 'start'))) { Check-Cancel; if ($clock.Elapsed.TotalMilliseconds -gt $deadline) { Fail 'POWERPOINT_TIMEOUT' 'The CLI did not start the prepared native session.' }; Start-Sleep -Milliseconds 20 }
|
|
604
|
+
$file = Join-Path $directory 'native.mp4'
|
|
605
|
+
$progress = Join-Path $directory 'ffmpeg-progress.txt'
|
|
606
|
+
$arguments = ('-y -v warning -xerror -stats_period 0.1 -f gdigrab -draw_mouse 0 -framerate ' + $job.output.fps + ' -i hwnd=' + $window + ' -an -vf "' + $captureFilter + '" -c:v libx264 -preset ultrafast -crf 18 -pix_fmt yuv420p -progress "' + $progress + '" "' + $file + '"')
|
|
607
|
+
$script:recorder = [Diagnostics.Process]::new()
|
|
608
|
+
$recorder.StartInfo = [Diagnostics.ProcessStartInfo]::new($ffmpeg, $arguments)
|
|
609
|
+
$recorder.StartInfo.UseShellExecute = $false
|
|
610
|
+
$recorder.StartInfo.CreateNoWindow = $true
|
|
611
|
+
$recorder.StartInfo.RedirectStandardInput = $true
|
|
612
|
+
$recorder.StartInfo.RedirectStandardError = $true
|
|
613
|
+
[void]$recorder.Start()
|
|
614
|
+
$script:recorderError = $recorder.StandardError.ReadToEndAsync()
|
|
615
|
+
Write-Json 'recorder.json' @{ pid = $recorder.Id; started_ticks = $recorder.StartTime.ToUniversalTime().Ticks.ToString(); process_name = $recorder.ProcessName; executable = $ffmpeg; file = $file }
|
|
616
|
+
$deadline = $clock.Elapsed.TotalMilliseconds + 15000
|
|
617
|
+
$recording = $false
|
|
618
|
+
while (!$recording) {
|
|
619
|
+
Check-Cancel
|
|
620
|
+
if ($recorder.HasExited) { Fail 'POWERPOINT_CAPTURE' 'FFmpeg exited before recording readiness. See ffmpeg.log.' }
|
|
621
|
+
if (Test-Path -LiteralPath $progress) {
|
|
622
|
+
$stream = [IO.File]::Open($progress, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
|
|
623
|
+
$reader = [IO.StreamReader]::new($stream)
|
|
624
|
+
try { $recording = $reader.ReadToEnd() -match '(?m)^frame=[1-9][0-9]*\s*$' }
|
|
625
|
+
finally { $reader.Dispose() }
|
|
626
|
+
}
|
|
627
|
+
if ($clock.Elapsed.TotalMilliseconds -gt $deadline) { Fail 'POWERPOINT_CAPTURE' 'FFmpeg did not encode a startup frame within 15 seconds.' }
|
|
628
|
+
if (!$recording) { Start-Sleep -Milliseconds 20 }
|
|
629
|
+
}
|
|
630
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 200)
|
|
631
|
+
Show-Marker '#ff00ff'
|
|
632
|
+
if ($job.verify_timing) { Show-Marker '#00ffff' }
|
|
633
|
+
Show-Marker '#ffff00'
|
|
634
|
+
$initialLower = $clock.Elapsed.TotalMilliseconds
|
|
635
|
+
Select-Slide $firstOperation.native_id
|
|
636
|
+
$deadline = $clock.Elapsed.TotalMilliseconds + 5000
|
|
637
|
+
do {
|
|
638
|
+
Check-Cancel
|
|
639
|
+
$ready = [SlideVideo.Native]::Readback($window, $geometry) -eq $firstReadback
|
|
640
|
+
if (!$ready) { Start-Sleep -Milliseconds 1 }
|
|
641
|
+
} while (!$ready -and $clock.Elapsed.TotalMilliseconds -lt $deadline)
|
|
642
|
+
if (!$ready) { Fail 'POWERPOINT_READINESS' 'The actual audience pixels did not return to the initialized first-slide state.' }
|
|
643
|
+
$script:origin = $clock.Elapsed.TotalMilliseconds
|
|
644
|
+
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' }
|
|
645
|
+
foreach ($marker in $markers) { $marker.observed_ms -= $origin; $marker.rendered_by_ms -= $origin }
|
|
646
|
+
$script:activeVisit = [string]$firstOperation.id
|
|
647
|
+
$script:activeScene = [string]$firstOperation.scene
|
|
648
|
+
$script:collectAnnotations = $job.annotations.Count -gt 0
|
|
649
|
+
$initial = $true
|
|
650
|
+
for ($operationIndex = 0; $operationIndex -lt $job.operations.Count; $operationIndex++) {
|
|
651
|
+
$operation = $job.operations[$operationIndex]
|
|
652
|
+
$script:annotationStartBeforeMs = [double]$operation.at_ms
|
|
653
|
+
Wait-Until ($origin + $operation.at_ms)
|
|
654
|
+
Check-Media
|
|
655
|
+
if (!$initial -and $operation.type -in @('slide', 'play')) { Wait-MediaCompletion }
|
|
656
|
+
[SlideVideo.Native]::EnsureGeometry($window, $geometry)
|
|
657
|
+
if ($initial) { $player = $null; $now = 0.0; $initial = $false }
|
|
658
|
+
else { $player = Apply-Operation $operation; $now = $clock.Elapsed.TotalMilliseconds - $origin }
|
|
659
|
+
$entry = @{ id = $operation.id; type = $operation.type; scheduled_ms = $operation.at_ms; observed_ms = $now }
|
|
660
|
+
if ($operation.type -eq 'play') {
|
|
661
|
+
$entry.media_ms = [double]$player.CurrentPosition
|
|
662
|
+
$activeMedia.Add(@{ operation = $operation; player = $player; last_position = $entry.media_ms; advanced_at = $now })
|
|
663
|
+
}
|
|
664
|
+
$events.Add($entry)
|
|
665
|
+
Write-Json 'events.json' @{ version = 1; events = @($events.ToArray()); markers = @($markers.ToArray()); failure = $null }
|
|
666
|
+
if ($job.verify_timing -and $now - $operation.at_ms -gt 100) { Fail 'POWERPOINT_LATE_ACTION' ('Native action exceeded 100 ms: ' + $operation.id) }
|
|
667
|
+
if ($operationIndex + 1 -eq $job.operations.Count -or $job.operations[$operationIndex + 1].at_ms -gt $operation.at_ms) {
|
|
668
|
+
$script:annotationStartBeforeMs = [double]::PositiveInfinity
|
|
669
|
+
Check-Annotations
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
Wait-Until ($origin + $job.duration_ms)
|
|
673
|
+
Check-Annotations
|
|
674
|
+
if (@($annotationMonitors | Where-Object { !$_.complete }).Count -gt 0) { Fail 'ANNOTATION_GEOMETRY' 'Native playback did not complete every annotation interval.' }
|
|
675
|
+
$script:collectAnnotations = $false
|
|
676
|
+
Write-Json 'annotation-geometry.json' @{ version = 1; geometry = @($annotationGeometry.ToArray()); failure = $null }
|
|
677
|
+
Wait-MediaCompletion
|
|
678
|
+
if ($job.verify_timing) { Show-Marker '#00ff00'; Show-Marker '#ff0000'; Show-Marker '#0000ff'; foreach ($marker in @($markers.ToArray() | Select-Object -Skip 3)) { $marker.observed_ms -= $origin; $marker.rendered_by_ms -= $origin } }
|
|
679
|
+
else {
|
|
680
|
+
[SlideVideo.Native]::EnsureGeometry($window, $geometry)
|
|
681
|
+
$show.View.GotoSlide([int]$markerSlides['#00ff00'], -1)
|
|
682
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 100)
|
|
683
|
+
$finalGeometry = [SlideVideo.Native]::Measure($window, '#00ff00', $deckAspect)
|
|
684
|
+
if ($finalGeometry.left -ne $geometry.left -or $finalGeometry.top -ne $geometry.top -or $finalGeometry.width -ne $geometry.width -or $finalGeometry.height -ne $geometry.height) { Fail 'POWERPOINT_GEOMETRY' 'The final audience rectangle changed.' }
|
|
685
|
+
}
|
|
686
|
+
Wait-Until ($clock.Elapsed.TotalMilliseconds + 200)
|
|
687
|
+
Stop-Recorder
|
|
688
|
+
if ($recorder.ExitCode -ne 0) { Fail 'POWERPOINT_CAPTURE' ('FFmpeg exited ' + $recorder.ExitCode + '. See ffmpeg.log.') }
|
|
689
|
+
$result = @{ version = 1; kind = 'recording'; file = $file; events = @($events.ToArray()); markers = @($markers.ToArray()); references = @($references.ToArray()); annotation_geometry = @($annotationGeometry.ToArray()); dependencies = (Dependencies) }
|
|
690
|
+
}
|
|
691
|
+
} catch {
|
|
692
|
+
$message = $_.Exception.Message
|
|
693
|
+
$code = 'POWERPOINT_NATIVE'
|
|
694
|
+
if ($message -match '^([A-Z_]+): (.*)$') { $code = $Matches[1]; $message = $Matches[2] }
|
|
695
|
+
$failure = @{ code = $code; message = $message; detail = $_.ToString(); location = $_.ScriptStackTrace }
|
|
696
|
+
} finally {
|
|
697
|
+
try { Stop-Recorder } catch { $cleanup.Add('Recorder cleanup failed: ' + $_.Exception.Message) }
|
|
698
|
+
foreach ($monitor in @($activeMedia.ToArray())) { try { $monitor.player.Stop() } catch { $cleanup.Add('Owned native media did not stop: ' + $_.Exception.Message) } }
|
|
699
|
+
if ($null -ne $show) { try { $show.View.Exit() } catch { $cleanup.Add('The owned slideshow did not close: ' + $_.Exception.Message) } }
|
|
700
|
+
if ($null -ne $presentation) { try { $presentation.Saved = -1; $presentation.Close() } catch { $cleanup.Add('The private presentation did not close: ' + $_.Exception.Message) } }
|
|
701
|
+
if ($null -ne $app) {
|
|
702
|
+
try { if ($createdApplication -and $app.Presentations.Count -eq 0) { $app.Quit() } }
|
|
703
|
+
catch { $cleanup.Add('The native application was preserved because its ownership or presentation inventory could not be confirmed: ' + $_.Exception.Message) }
|
|
704
|
+
try { [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) } catch { $cleanup.Add('The COM application reference did not release.') }
|
|
705
|
+
}
|
|
706
|
+
try { Write-Json 'events.json' @{ version = 1; events = @($events.ToArray()); markers = @($markers.ToArray()); failure = $failure } } catch {}
|
|
707
|
+
try { Write-Json 'annotation-geometry.json' @{ version = 1; geometry = @($annotationGeometry.ToArray()); intervals = @($annotationMonitors | ForEach-Object { @{ id = $_.annotation.id; complete = $_.complete } }); failure = $failure } } catch {}
|
|
708
|
+
try { Write-Json 'cleanup.json' @{ version = 1; gaps = @($cleanup.ToArray()); application_created = $createdApplication } } catch {}
|
|
709
|
+
if ($locked) { $mutex.ReleaseMutex() }
|
|
710
|
+
if ($null -ne $mutex) { $mutex.Dispose() }
|
|
711
|
+
}
|
|
712
|
+
if ($null -ne $failure) { Write-Json 'failure.json' $failure; exit 1 }
|
|
713
|
+
Write-Json 'result.json' $result
|
|
714
|
+
exit 0
|