Compare commits
10
Commits
c8b2d0608a
...
02c7004e8c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02c7004e8c | ||
|
|
208fb6c811 | ||
|
|
1d89392cef | ||
|
|
b47f27bd39 | ||
|
|
a47ab190bc | ||
|
|
7a7027391e | ||
|
|
47a5f041ee | ||
|
|
3f4d416076 | ||
|
|
5ebe03a2bb | ||
|
|
d6935df9ae |
@@ -0,0 +1,172 @@
|
||||
---
|
||||
name: verify-gvfg-frame-hold
|
||||
description: "Model-check the GVFG capture frame-hold protocol (gvfg_read_channel_frame / gvfg_release_channel_frame against stop, start and signal-change recovery) with TLA+/TLC, and reproduce the stop->start race on real hardware. Use it before and after any change to gvfg_capture.cpp's channel read/release/stop/start, or to GigabyteCaptureSession's wait_frame, release_frame, start_stream, stop_stream, handle_signal_event or restart_stream_after_signal_change."
|
||||
---
|
||||
|
||||
# Verify the GVFG frame-hold protocol
|
||||
|
||||
## What is verified
|
||||
|
||||
**Property.** While an application holds a frame whose data is the backend capture buffer:
|
||||
(1) `HeldFrameIsCurrent`: the buffer still belongs to the driver stream that is running now, so no recovery
|
||||
restart and no stop/start has replaced it; (2) `ReleaseWillSucceed`: the application's single mandated
|
||||
`gvfg_release_channel_frame()` will succeed.
|
||||
|
||||
**Harm if broken.** In zero-copy mode, the application reads a buffer that the driver is refilling, which gives
|
||||
torn or foreign video. In every mode, the release returns `GVFG_ESTATE` and the channel stays "frame held", so
|
||||
every later read fails with "previous frame has not been released" until the app stops the channel.
|
||||
|
||||
**Model.** The model is `GVFG_SDK/sdk/gvfg/formal/CaptureFrameHold.tla`. It has three threads: the app's video
|
||||
reader (read, OSD branch, deliver, release), the app's lifecycle thread (stop and start, serialized as the
|
||||
customer docs require), and the session event thread (format change or plug-in, followed by the recovery
|
||||
restart). Each action is one mutex-protected section, or one atomic access, in the code, and its comment names
|
||||
the function. A ghost `epoch` counts `GvfgStartCapture` calls, so "same buffer" means "same epoch".
|
||||
|
||||
**Tool.** TLA+ with TLC 1.7.4 (pinned and SHA256-checked). The question is whether events can happen in a bad
|
||||
order across threads, and an exhaustive model checker over the protocol answers that. The C++ cannot be model
|
||||
checked directly, because it sits on Win32 events and the vendor GvfgSdk. A small hardware program
|
||||
(`scripts/f1_hardware_repro.cpp`) stages the one interleaving that matters most on a real card.
|
||||
|
||||
## Scope and bounds
|
||||
|
||||
- One channel. The configs use at most 4 stop/start calls, 2 signal events and 4 read attempts. At those bounds
|
||||
`MC_Contract` covers 45,655 distinct states and `MC_ConcurrentReader` 237,899. A one-off run at 6/3/6 also
|
||||
passed, with 361,278 and 2,822,739 states.
|
||||
- Out of scope: audio frames, unplug events (they bump the generation but never restart), the vendor driver
|
||||
itself (`GvfgGetVideoFrame*`, `GvfgStart/StopCapture` are taken as atomic and correct), the OSD processor's
|
||||
internals (only its keep-hold versus early-release branch is modelled), multi-channel handles,
|
||||
open/close/destroy, and timeouts (a timed-out wait is the same as a failed wait here).
|
||||
- A Pass covers this model under these bounds, not the whole SDK.
|
||||
|
||||
## Run it
|
||||
|
||||
```powershell
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File .agents\skills\verify-gvfg-frame-hold\scripts\check.ps1
|
||||
```
|
||||
|
||||
It needs Java 17 or later (installed on the dev PC: Eclipse Temurin 21, from
|
||||
`winget install --id EclipseAdoptium.Temurin.21.JDK -e`) and tla2tools.jar 1.7.4. The script looks for the jar in
|
||||
`$env:TLA2TOOLS_JAR`, then `GVFG_SDK/sdk/gvfg/formal/tools/` (git-ignored, inside the workspace so a sandboxed
|
||||
agent can read it), then `%USERPROFILE%\.tools\tla`. Pass `-Install` once to download it into `formal/tools/`.
|
||||
All six configs take a few seconds together. TLC runs with one worker,
|
||||
so the first violation it reports is the same on every run. Logs go to
|
||||
`GVFG_SDK/sdk/gvfg/formal/out/<config>.log` (git-ignored). Use `-Only MC_Contract` to run a single config.
|
||||
|
||||
| Config | What it is | Expected |
|
||||
| --- | --- | --- |
|
||||
| `MC_Contract.cfg` | Shipped code. The app pauses or joins its reader before every stop/start (srcroot `GvfgSource::stop` does). | Pass |
|
||||
| `MC_ConcurrentReader.cfg` | Shipped code. The reader keeps running across stop then start. | Pass (F1 fixed) |
|
||||
| `MC_Mut_NoRestartWait.cfg` | Mutation: recovery restart no longer waits for `frame_held_`. | Violation: HeldFrameIsCurrent |
|
||||
| `MC_Mut_NoRecoveryCheck.cfg` | Mutation: capture ignores `recovery_pending_` and the generation. | Violation: HeldFrameIsCurrent |
|
||||
| `MC_Mut_NoRunGeneration.cfg` | Mutation: delivery checks only `running`. This is the code before the F1 fix. | Violation: HeldFrameIsCurrent |
|
||||
| `MC_Mut_NoRunningRecheck.cfg` | Mutation: delivery checks only the run generation. | Violation: ReleaseWillSucceed |
|
||||
|
||||
The script exits 0 only when every config matches its expected result and the covered code is unchanged since
|
||||
the sync commit. Exit 3 (`STALE`) means the model passed but nobody has confirmed it against the changed code.
|
||||
That is not a pass, so follow "Keeping it in step".
|
||||
|
||||
Read a violation with `check.ps1 -Trace <config>`. It reruns that config and prints the shortest counterexample,
|
||||
one row per step: the action, then the variables that step changed. Map each action to code with the table under
|
||||
"Code-to-model map". In Claude Code, the pstack **statechart** skill (`/pstack:statechart`) can also draw the
|
||||
trace, and on a pass it draws how the protocol moves between states. Use its current instructions, and do not
|
||||
copy its commands into this skill.
|
||||
|
||||
## Running it from Codex
|
||||
|
||||
Codex reads this skill from `.agents/skills/` (repo scope). Its Windows sandbox (`[windows] sandbox = "elevated"`)
|
||||
runs commands as a separate low-privilege user on a private desktop.
|
||||
|
||||
- `check.ps1` and `check.ps1 -Trace` only need Java (under `C:\Program Files`) and the jar in `formal/tools/`, so
|
||||
they should run inside the sandbox. `-Install` needs network access.
|
||||
- `f1-hardware-repro.ps1` needs the capture card and the MSVC toolchain. Run it outside the sandbox: approve
|
||||
the escalation when Codex asks, or use full access for that command.
|
||||
- The behaviour above follows the Codex docs. It has not been tried in Codex yet, so if a step fails in the
|
||||
sandbox, rerun that one command outside it before you suspect the code.
|
||||
|
||||
## Hardware check for F1
|
||||
|
||||
On a PC with a GVFG card and a live signal on channel 0, with no viewer holding the card:
|
||||
|
||||
```powershell
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File .agents\skills\verify-gvfg-frame-hold\scripts\f1-hardware-repro.ps1 -GvfgBuildDir GVFG_SDK\build\<name>
|
||||
```
|
||||
|
||||
It compiles `f1_hardware_repro.cpp` against that build's `gvfg.lib`. It attaches a frame processor through the
|
||||
exported `gvfg_control_frame_processor` (the hook OSD uses), which parks one read between capture and delivery.
|
||||
It then calls `gvfg_stop_channel` and `gvfg_start_channel`, and lets the read finish. Exit 0 means the read was
|
||||
rejected and the next read works. Exit 1 means F1 reproduced. Exit 2 means it could not be verified here, and
|
||||
exit 3 means the race could not be staged.
|
||||
|
||||
## Finding F1: fixed in `1d89392`
|
||||
|
||||
**Before the fix.** The trigger is `gvfg_stop_channel()` followed by `gvfg_start_channel()` while
|
||||
`gvfg_read_channel_frame()` sits between getting the frame and delivering it. The delivery check looked only at
|
||||
`running`, which start had set back to true. So the read handed out a frame from the stopped stream as valid.
|
||||
Its release then failed with `GVFG_ESTATE` ("Capture frame release rejected: no frame is held"), because
|
||||
stop/start had reset `frame_held_`. `releaseFrame` returns before clearing `frameHeld`, so every later read
|
||||
failed with "previous frame has not been released". On the dev PC this reproduced on hardware with the code
|
||||
before the fix (3.2.0 at `b47f27b`, built from `git archive`) and with the older 3.1.0 build.
|
||||
|
||||
**The fix**, in `gvfg_capture.cpp` (`gvfg_channel_session_t`):
|
||||
|
||||
- `start()` increments `runGeneration` and sets `running` in one `frameMutex` section.
|
||||
- `readFrame()` records `runGeneration` when it marks the read in progress.
|
||||
- Delivery rejects the frame when `running` is false or the generation moved. It releases the backend hold if
|
||||
the session still has one, and returns `GVFG_ESTATE` with "capture stopped or restarted during the read".
|
||||
|
||||
**Verified.** `MC_ConcurrentReader` passes. `MC_Mut_NoRunGeneration` (the old check) still fails, which shows the
|
||||
check can fail. The hardware program exits 0 against the fixed build (`GVFG_SDK/build/verify-f1`) and 1 against
|
||||
`b47f27b`. srcroot's capture journey passes on the fixed SDK.
|
||||
|
||||
**Still open, related.** `readAudioFrame` has the same `running`-only check. A stop->start during an audio read
|
||||
can deliver one PCM chunk from before the restart. There is no backend hold for audio, so the channel does not
|
||||
get stuck. Audio is outside this model.
|
||||
|
||||
## Telling a real bug from a modeling error
|
||||
|
||||
Map each step of the trace to the code named in the action's comment. Then ask whether the code really allows
|
||||
that step at that moment: are the mutexes the same, and is the check the same? If it does, the trace is a real
|
||||
interleaving. Report it in the code's words, as F1 does. If it does not, the model is wrong. Fix the action so it
|
||||
matches the code. Never weaken an invariant and never drop a thread to get a pass.
|
||||
|
||||
## Code-to-model map (keep in step)
|
||||
|
||||
| Code (gvfg_capture.cpp = C, gigabyte_capture_session.cpp = S) | Model action / guard |
|
||||
| --- | --- |
|
||||
| C `readFrame`: `if (!running)` before the lock | `RBegin` |
|
||||
| C `readFrame`, first `frameMutex` section: held / in-progress checks, record `runGeneration` | `RBeginLock` |
|
||||
| S `wait_frame`: `running_`, `frame_held_`, generation snapshot | `RWaitCheck` |
|
||||
| S `wait_frame`: WaitForMultipleObjects (stop, recovery, frame) | `RWakeFail`, `RWakeFrame` |
|
||||
| S `wait_frame` capture section under `capture_mutex_`: `recovery_pending_` / generation check | `RCapture`, guard `CaptureRejectsDuringRecovery` |
|
||||
| C `readFrame` OSD: keep the backend hold, or `release_frame` early | `ROsdKeep`, `ROsdEarlyRelease` |
|
||||
| C `readFrame` delivery under `frameMutex`: `running` recheck and `runGeneration` comparison | `RDeliver`, guards `DeliverRechecksRunning`, `DeliverChecksRunGeneration` |
|
||||
| C `readFrame` `stoppedWhileWaiting` release | `RStopRelease` |
|
||||
| C `releaseFrame` (calls S `release_frame` inside `frameMutex`) | `RRelease` |
|
||||
| C `stop`: `running = false`, `releaseHeldFrameForStop`, then S `stop_stream` | `UStop`, `UStopFrames`, `UStopBackend`, `UStopStream`, `UStopJoin` |
|
||||
| C `start`: S `start_stream`, then `++runGeneration; running = true` under `frameMutex` | `UStartSession`, `UStartChannel` |
|
||||
| S `handle_signal_event` first block (generation++, `recovery_pending_`) | `ESignal` |
|
||||
| S restart decision (format compare) | `EDecide` (nondeterministic) |
|
||||
| S `restart_stream_after_signal_change`: wait for `!frame_held_ \|\| !running_` | `EWaitHold`, guard `RestartWaitsForRelease` |
|
||||
| S restart Stop/StartCapture under `capture_mutex_` | `ERestart` (epoch + 1) |
|
||||
| S `handle_signal_event` end (`recovery_pending_ = false`) | `EFinish` |
|
||||
|
||||
**Coverage record.** The covered files are `GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp` (`gvfg_channel_session_t`:
|
||||
`start`, `stop`, `readFrame`, `releaseFrame`, `releaseHeldFrameForStop`), and
|
||||
`GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp` with its `.h` (`start_stream`, `stop_stream`,
|
||||
`wait_frame`, `release_frame`, `handle_signal_event`, `restart_stream_after_signal_change`,
|
||||
`wait_for_recovery`). **Sync commit: `1d89392`** (the F1 fix, on master). The model
|
||||
was last confirmed against the code at this commit.
|
||||
|
||||
### Keeping it in step
|
||||
|
||||
1. `check.ps1` prints `STALE` when a covered file differs from the sync commit, working tree included. Read the
|
||||
diff of the covered functions: `git diff <sync commit> -- <file>`.
|
||||
2. For each changed check, lock, or ordering, update the matching action in the table, or its guard in the
|
||||
`Guards` set of `MC_Contract.cfg` and `MC_ConcurrentReader.cfg` when the change removes a guarded check.
|
||||
Add any new step as a new action, with its function named in a comment.
|
||||
3. Run `check.ps1`. A violation in `MC_Contract` or `MC_ConcurrentReader` means the change breaks the property.
|
||||
Read the trace with `check.ps1 -Trace <config>`, and report it with the steps in code words. Do not loosen
|
||||
the model.
|
||||
When the change touches the read, stop or start path, also run the hardware check.
|
||||
4. Move the sync commit (here and in `check.ps1`) forward only after you have confirmed that the model describes
|
||||
the code at the new commit.
|
||||
@@ -0,0 +1,142 @@
|
||||
<#
|
||||
Model-checks GVFG_SDK/sdk/gvfg/formal/CaptureFrameHold.tla with TLC and compares every config with its expected result.
|
||||
Also reports whether the covered code changed since the sync commit (then the model needs another look).
|
||||
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File .agents\skills\verify-gvfg-frame-hold\scripts\check.ps1 [-Only MC_Contract] [-Install]
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File .agents\skills\verify-gvfg-frame-hold\scripts\check.ps1 -Trace MC_Mut_NoRunGeneration
|
||||
|
||||
-Trace <config> runs one config and prints its counterexample as a table: each step's action and the variables it changed.
|
||||
Map each action to code with the table in SKILL.md.
|
||||
|
||||
Exit 0: every config matched its expectation and the covered code is unchanged since the sync commit.
|
||||
1: a mismatch (read the log it names). 2: Java or TLA+ tools missing.
|
||||
3: expectations met, but covered code changed since the sync commit, so update the model first (SKILL.md).
|
||||
|
||||
tla2tools.jar is looked up in $env:TLA2TOOLS_JAR, then GVFG_SDK\sdk\gvfg\formal\tools (git-ignored, inside the
|
||||
workspace so sandboxed agents can read it), then %USERPROFILE%\.tools\tla. -Install downloads the pinned v1.7.4
|
||||
(SHA256 checked) into formal\tools. Java must be installed separately, e.g.
|
||||
winget install --id EclipseAdoptium.Temurin.21.JDK -e.
|
||||
#>
|
||||
param([string[]]$Only, [switch]$Install, [string]$Trace)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repo = (Resolve-Path (Join-Path $PSScriptRoot '..\..\..\..')).Path
|
||||
$formal = Join-Path $repo 'GVFG_SDK\sdk\gvfg\formal'
|
||||
$outDir = Join-Path $formal 'out'
|
||||
|
||||
# ---- tools -----------------------------------------------------------------
|
||||
$jarVersion = '1.7.4'
|
||||
$jarName = "tla2tools-$jarVersion.jar"
|
||||
$jarSha256 = '936A262061C914694DFD669A543BE24573C45D5AA0FF20A8B96B23D01E050E88'
|
||||
$workspaceJar = Join-Path $formal "tools\$jarName"
|
||||
$jar = @($env:TLA2TOOLS_JAR, $workspaceJar, (Join-Path $env:USERPROFILE ".tools\tla\$jarName")) |
|
||||
Where-Object { $_ -and (Test-Path $_) } | Select-Object -First 1
|
||||
if (-not $jar) {
|
||||
if (-not $Install) { Write-Host "Missing $jarName. Rerun with -Install (downloads ~2 MB from github.com/tlaplus into $workspaceJar)."; exit 2 }
|
||||
New-Item -ItemType Directory -Force (Split-Path $workspaceJar) | Out-Null
|
||||
Invoke-WebRequest -UseBasicParsing -OutFile $workspaceJar `
|
||||
-Uri "https://github.com/tlaplus/tlaplus/releases/download/v$jarVersion/tla2tools.jar"
|
||||
$jar = $workspaceJar
|
||||
}
|
||||
if ((Get-FileHash $jar -Algorithm SHA256).Hash -ne $jarSha256) { Write-Host "SHA256 mismatch for $jar"; exit 2 }
|
||||
|
||||
$java = $null
|
||||
if ($env:JAVA_HOME -and (Test-Path "$env:JAVA_HOME\bin\java.exe")) { $java = "$env:JAVA_HOME\bin\java.exe" }
|
||||
if (-not $java) {
|
||||
$java = Get-ChildItem 'C:\Program Files\Eclipse Adoptium' -Directory -ErrorAction SilentlyContinue |
|
||||
Sort-Object Name -Descending | ForEach-Object { Join-Path $_.FullName 'bin\java.exe' } |
|
||||
Where-Object { Test-Path $_ } | Select-Object -First 1
|
||||
}
|
||||
if (-not $java) { $java = (Get-Command java -ErrorAction SilentlyContinue).Source }
|
||||
if (-not $java) { Write-Host 'Java not found. Install it: winget install --id EclipseAdoptium.Temurin.21.JDK -e'; exit 2 }
|
||||
|
||||
# ---- expectations ----------------------------------------------------------
|
||||
# Pass : TLC must report "No error has been found".
|
||||
# Violation:X : TLC must report invariant X violated (mutations prove the check can fail; findings are known bugs).
|
||||
$expect = [ordered]@{
|
||||
'MC_Contract' = 'Pass' # shipped code, app quiesces reader before stop/start
|
||||
'MC_ConcurrentReader' = 'Pass' # shipped code, reader runs across stop->start (F1 fixed)
|
||||
'MC_Mut_NoRestartWait' = 'Violation:HeldFrameIsCurrent' # mutation: restart does not wait for frame_held_
|
||||
'MC_Mut_NoRecoveryCheck' = 'Violation:HeldFrameIsCurrent' # mutation: capture ignores recovery_pending_/generation
|
||||
'MC_Mut_NoRunGeneration' = 'Violation:HeldFrameIsCurrent' # mutation: delivery checks only running (F1, code before the fix)
|
||||
'MC_Mut_NoRunningRecheck' = 'Violation:ReleaseWillSucceed' # mutation: delivery checks only the run generation
|
||||
}
|
||||
|
||||
function Invoke-Tlc([string]$Config) {
|
||||
$log = Join-Path $outDir "$Config.log"
|
||||
$meta = Join-Path $outDir "meta-$Config"
|
||||
# One worker keeps the search order, and so the first violated invariant, the same on every run.
|
||||
& $java -XX:+UseParallelGC -cp $jar tlc2.TLC -config "$Config.cfg" -metadir $meta -workers 1 -cleanup CaptureFrameHold.tla 2>&1 |
|
||||
ForEach-Object { "$_" } | Set-Content -Encoding UTF8 $log
|
||||
Remove-Item -Recurse -Force $meta -ErrorAction SilentlyContinue
|
||||
return $log
|
||||
}
|
||||
|
||||
function Show-Trace([string]$LogPath) {
|
||||
# TLC prints each state as "State N: <Action ...>" followed by "/\ var = value" lines.
|
||||
$text = Get-Content $LogPath
|
||||
$violation = $text | Where-Object { $_ -match 'Invariant \w+ is violated|Deadlock reached' } | Select-Object -First 1
|
||||
if (-not $violation) { 'No counterexample in ' + $LogPath + ' (the config passed or TLC failed; read the log).'; return }
|
||||
$violation.Trim()
|
||||
$prev = @{}; $cur = $null; $action = $null; $step = 0
|
||||
$states = New-Object System.Collections.ArrayList
|
||||
foreach ($line in $text) {
|
||||
if ($line -match '^State (\d+): <(\w+)') {
|
||||
if ($cur) { [void]$states.Add(@($step, $action, $cur)) }
|
||||
$step = [int]$matches[1]; $action = $matches[2]; $cur = [ordered]@{}
|
||||
}
|
||||
elseif ($cur -and $line -match '^/\\ (\w+) = (.+)$') { $cur[$matches[1]] = $matches[2] }
|
||||
}
|
||||
if ($cur) { [void]$states.Add(@($step, $action, $cur)) }
|
||||
foreach ($s in $states) {
|
||||
$vars = $s[2]
|
||||
$changed = foreach ($k in $vars.Keys) { if (-not $prev.Contains($k) -or $prev[$k] -ne $vars[$k]) { "$k=$($vars[$k])" } }
|
||||
'{0,3} {1,-16} {2}' -f $s[0], $s[1], ($changed -join ' ')
|
||||
$prev = $vars
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force $outDir | Out-Null
|
||||
Push-Location $formal
|
||||
try {
|
||||
if ($Trace) {
|
||||
if (-not (Test-Path "$Trace.cfg")) { Write-Host "No config $Trace.cfg in $formal"; exit 2 }
|
||||
Show-Trace (Invoke-Tlc $Trace)
|
||||
exit 0
|
||||
}
|
||||
$failed = $false
|
||||
foreach ($cfg in $expect.Keys) {
|
||||
if ($Only -and $cfg -notin $Only) { continue }
|
||||
$sw = [Diagnostics.Stopwatch]::StartNew()
|
||||
$log = Invoke-Tlc $cfg
|
||||
$sw.Stop()
|
||||
$text = Get-Content $log -Raw
|
||||
$got = if ($text -match 'Model checking completed\. No error has been found') { 'Pass' }
|
||||
elseif ($text -match 'Invariant (\w+) is violated') { "Violation:$($matches[1])" }
|
||||
elseif ($text -match 'Deadlock reached') { 'Deadlock' }
|
||||
else { 'ToolError' }
|
||||
# TLC also prints progress lines with partial counts; the final summary is the last one.
|
||||
$final = [regex]::Matches($text, '(\d+) distinct states found')
|
||||
$states = if ($final.Count) { $final[$final.Count - 1].Groups[1].Value } else { '?' }
|
||||
$ok = $got -eq $expect[$cfg]
|
||||
if (-not $ok) { $failed = $true }
|
||||
'{0,-24} expected {1,-30} got {2,-30} {3,8} states {4,6:n1}s {5}' -f $cfg, $expect[$cfg], $got, $states, $sw.Elapsed.TotalSeconds, $(if ($ok) { 'OK' } else { "MISMATCH -> $log" })
|
||||
}
|
||||
}
|
||||
finally { Pop-Location }
|
||||
|
||||
# ---- is the verification still in step with the code? ---------------------
|
||||
$syncCommit = '1d89392'
|
||||
$covered = @('GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp', 'GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp',
|
||||
'GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.h')
|
||||
$changed = git -C $repo diff --name-only $syncCommit -- @covered
|
||||
if ($changed) {
|
||||
Write-Host "STALE: covered code changed since sync commit ${syncCommit}: $($changed -join ', ')"
|
||||
Write-Host " Re-read the changed functions against the model before trusting a Pass (see SKILL.md, 'Keeping it in step')."
|
||||
} else {
|
||||
Write-Host "In step: covered code unchanged since sync commit $syncCommit."
|
||||
}
|
||||
|
||||
if ($failed) { 'RESULT: MISMATCH'; exit 1 }
|
||||
# A pass against a model nobody re-checked after the code moved proves nothing about the new code.
|
||||
if ($changed) { 'RESULT: STALE - expectations met by the model, but the model is not confirmed against the changed code'; exit 3 }
|
||||
'RESULT: ALL EXPECTATIONS MET'
|
||||
@@ -0,0 +1,37 @@
|
||||
<#
|
||||
Builds and runs f1_hardware_repro.cpp against one GVFG SDK build, on a PC with a GVFG card and a live signal on
|
||||
channel 0. No viewer may hold the card while it runs.
|
||||
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File .agents\skills\verify-gvfg-frame-hold\scripts\f1-hardware-repro.ps1 -GvfgBuildDir GVFG_SDK\build\<name>
|
||||
|
||||
The build dir must contain bin\gvfg.dll and lib\gvfg.lib. Exit codes are the program's: 0 fixed, 1 F1 reproduced,
|
||||
2 not verifiable here, 3 unexpected.
|
||||
#>
|
||||
param([Parameter(Mandatory)][string]$GvfgBuildDir)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repo = (Resolve-Path (Join-Path $PSScriptRoot '..\..\..\..')).Path
|
||||
$sdk = Join-Path $repo 'GVFG_SDK\sdk\gvfg'
|
||||
$build = (Resolve-Path $GvfgBuildDir).Path
|
||||
foreach ($f in 'bin\gvfg.dll', 'lib\gvfg.lib') {
|
||||
if (-not (Test-Path (Join-Path $build $f))) { Write-Host "Missing $f in $build"; exit 3 }
|
||||
}
|
||||
if (Get-Process qt6_viewer, GVFG_CardTest -ErrorAction SilentlyContinue) { Write-Host 'A viewer or card test holds the card; close it first.'; exit 2 }
|
||||
|
||||
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
|
||||
$vs = & $vswhere -products * -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
|
||||
$env:PATH = (Split-Path $vswhere) + ';' + $env:PATH
|
||||
cmd /c "`"$(Join-Path $vs 'VC\Auxiliary\Build\vcvars64.bat')`" >nul 2>&1 && set" | ForEach-Object {
|
||||
if ($_ -match '^([^=]+)=(.*)$') { [Environment]::SetEnvironmentVariable($matches[1], $matches[2]) }
|
||||
}
|
||||
|
||||
$out = Join-Path $env:TEMP ("gvfg-f1-repro-" + (Split-Path $build -Leaf))
|
||||
New-Item -ItemType Directory -Force $out | Out-Null
|
||||
$exe = Join-Path $out 'f1_hardware_repro.exe'
|
||||
& cl.exe /nologo /std:c++17 /EHsc /O2 /utf-8 "/I$sdk\include" "/I$sdk\src" (Join-Path $PSScriptRoot 'f1_hardware_repro.cpp') `
|
||||
"/Fe:$exe" "/Fo:$out\\" /link "/LIBPATH:$build\lib" gvfg.lib | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host 'Compile failed'; exit 3 }
|
||||
|
||||
$env:PATH = (Join-Path $build 'bin') + ';' + $env:PATH
|
||||
Write-Host "SDK build: $build"
|
||||
& $exe
|
||||
exit $LASTEXITCODE
|
||||
@@ -0,0 +1,193 @@
|
||||
// F1 on real hardware, deterministically: stop + start while a read sits between
|
||||
// capture and delivery. A frame processor (the hook OSD uses) parks the reader in
|
||||
// exactly that window, so no timing luck is needed.
|
||||
//
|
||||
// Exit 0: fixed behaviour (the read is rejected, the next read works).
|
||||
// Exit 1: F1 reproduced (stale frame delivered, release rejected or channel stuck).
|
||||
// Exit 2: not verifiable here (no device / no signal). Exit 3: unexpected result.
|
||||
#include <windows.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cstdio>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include "gvfg_capture.h"
|
||||
#include "gvfg_frame_processor.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
std::mutex g_mutex;
|
||||
std::condition_variable g_cv;
|
||||
bool g_armed = false;
|
||||
bool g_parked = false;
|
||||
bool g_resume = false;
|
||||
|
||||
gvfg_status_t parkerCreate(void **context)
|
||||
{
|
||||
*context = nullptr;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
void parkerDestroy(void *) {}
|
||||
|
||||
gvfg_status_t parkerProcess(void *, const gvfg_frame_t &in, gvfg_frame_t &out, bool &applied,
|
||||
gvfg_debug_osd_frame_timing_t *, uint8_t *, bool *inPlace)
|
||||
{
|
||||
out = in;
|
||||
applied = false; // keep the backend hold, like OSD off / in-place OSD
|
||||
if (inPlace)
|
||||
*inPlace = false;
|
||||
std::unique_lock<std::mutex> lock(g_mutex);
|
||||
if (g_armed)
|
||||
{
|
||||
g_armed = false;
|
||||
g_parked = true;
|
||||
g_cv.notify_all();
|
||||
g_cv.wait(lock, [] { return g_resume; });
|
||||
}
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t parkerControl(void *, const void *) { return GVFG_OK; }
|
||||
|
||||
const gvfg_frame_processor kParker{parkerCreate, parkerDestroy, parkerProcess};
|
||||
|
||||
const char *name(gvfg_status_t status) { return gvfg_strerror(status); }
|
||||
|
||||
void lastError(gvfg_handle handle, const char *label)
|
||||
{
|
||||
char message[512] = {};
|
||||
gvfg_get_channel_last_sdk_error_detail(handle, GVFG_CHANNEL_0, message, sizeof(message));
|
||||
std::printf(" %-16s last SDK error: %s\n", label, message[0] ? message : "(none)");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::printf("GVFG SDK %s\n", gvfg_get_version());
|
||||
if (gvfg_enumerate_devices(nullptr, 0) < 1)
|
||||
{
|
||||
std::puts("NOT VERIFIED: no GVFG device");
|
||||
return 2;
|
||||
}
|
||||
|
||||
gvfg_handle handle = nullptr;
|
||||
if (gvfg_create(&handle) != GVFG_OK || gvfg_open_channel(handle, 0, GVFG_CHANNEL_0) != GVFG_OK)
|
||||
{
|
||||
std::puts("NOT VERIFIED: cannot open device 0 channel 0");
|
||||
return 2;
|
||||
}
|
||||
gvfg_status_t st = gvfg_start_channel(handle, GVFG_CHANNEL_0);
|
||||
if (st != GVFG_OK)
|
||||
{
|
||||
std::printf("NOT VERIFIED: start failed (%s); is a signal connected?\n", name(st));
|
||||
gvfg_destroy(handle);
|
||||
return 2;
|
||||
}
|
||||
st = gvfg_control_frame_processor(handle, GVFG_CHANNEL_0, &kParker, true, parkerControl, nullptr,
|
||||
"attach parker failed");
|
||||
if (st != GVFG_OK)
|
||||
{
|
||||
std::printf("UNEXPECTED: cannot attach frame processor (%s)\n", name(st));
|
||||
gvfg_destroy(handle);
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Warm up: capture really flows before the race.
|
||||
int warm = 0;
|
||||
for (int i = 0; i < 20 && warm < 5; ++i)
|
||||
{
|
||||
gvfg_frame_t frame{};
|
||||
if (gvfg_read_channel_frame(handle, GVFG_CHANNEL_0, &frame, 1000) == GVFG_OK)
|
||||
{
|
||||
++warm;
|
||||
gvfg_release_channel_frame(handle, GVFG_CHANNEL_0, &frame);
|
||||
}
|
||||
}
|
||||
if (warm < 5)
|
||||
{
|
||||
std::puts("NOT VERIFIED: frames are not flowing");
|
||||
gvfg_destroy(handle);
|
||||
return 2;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
g_armed = true;
|
||||
}
|
||||
gvfg_status_t readStatus = GVFG_ETIMEOUT;
|
||||
gvfg_status_t releaseStatus = GVFG_ETIMEOUT;
|
||||
bool released = false;
|
||||
std::thread reader([&] {
|
||||
gvfg_frame_t frame{};
|
||||
readStatus = gvfg_read_channel_frame(handle, GVFG_CHANNEL_0, &frame, 2000);
|
||||
if (readStatus == GVFG_OK)
|
||||
{
|
||||
released = true;
|
||||
releaseStatus = gvfg_release_channel_frame(handle, GVFG_CHANNEL_0, &frame);
|
||||
}
|
||||
});
|
||||
|
||||
bool parked = false;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(g_mutex);
|
||||
parked = g_cv.wait_for(lock, std::chrono::seconds(5), [] { return g_parked; });
|
||||
}
|
||||
gvfg_status_t stopStatus = GVFG_ETIMEOUT;
|
||||
gvfg_status_t startStatus = GVFG_ETIMEOUT;
|
||||
if (parked)
|
||||
{
|
||||
stopStatus = gvfg_stop_channel(handle, GVFG_CHANNEL_0);
|
||||
startStatus = gvfg_start_channel(handle, GVFG_CHANNEL_0);
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
g_resume = true;
|
||||
}
|
||||
g_cv.notify_all();
|
||||
reader.join();
|
||||
lastError(handle, "after race:");
|
||||
|
||||
gvfg_status_t nextRead = GVFG_ETIMEOUT;
|
||||
gvfg_status_t nextRelease = GVFG_ETIMEOUT;
|
||||
for (int i = 0; i < 5 && nextRead != GVFG_OK; ++i)
|
||||
{
|
||||
gvfg_frame_t frame{};
|
||||
nextRead = gvfg_read_channel_frame(handle, GVFG_CHANNEL_0, &frame, 1000);
|
||||
if (nextRead == GVFG_OK)
|
||||
nextRelease = gvfg_release_channel_frame(handle, GVFG_CHANNEL_0, &frame);
|
||||
else if (nextRead == GVFG_ESTATE)
|
||||
break; // ESTATE here means the channel is stuck; retrying will not help
|
||||
}
|
||||
lastError(handle, "after next read:");
|
||||
|
||||
std::printf("parked in window : %s\n", parked ? "yes" : "no");
|
||||
std::printf("stop / start : %s / %s\n", name(stopStatus), name(startStatus));
|
||||
std::printf("racing read : %s\n", name(readStatus));
|
||||
std::printf("its release : %s\n", released ? name(releaseStatus) : "(not called: no frame)");
|
||||
std::printf("next read : %s (release %s)\n", name(nextRead),
|
||||
nextRead == GVFG_OK ? name(nextRelease) : "-");
|
||||
|
||||
gvfg_stop_channel(handle, GVFG_CHANNEL_0);
|
||||
gvfg_destroy(handle);
|
||||
|
||||
if (!parked || stopStatus != GVFG_OK || startStatus != GVFG_OK)
|
||||
{
|
||||
std::puts("RESULT: UNEXPECTED (race not staged)");
|
||||
return 3;
|
||||
}
|
||||
if (readStatus == GVFG_OK && (releaseStatus != GVFG_OK || nextRead != GVFG_OK))
|
||||
{
|
||||
std::puts("RESULT: F1 REPRODUCED (stale frame delivered after stop->start)");
|
||||
return 1;
|
||||
}
|
||||
if (readStatus != GVFG_OK && nextRead == GVFG_OK && nextRelease == GVFG_OK)
|
||||
{
|
||||
std::puts("RESULT: FIXED (racing read rejected, channel keeps working)");
|
||||
return 0;
|
||||
}
|
||||
std::puts("RESULT: UNEXPECTED");
|
||||
return 3;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
name: verify-gvfg-frame-hold
|
||||
description: "Model-check the GVFG capture frame-hold protocol (gvfg_read_channel_frame / gvfg_release_channel_frame against stop, start and signal-change recovery) with TLA+/TLC, and reproduce the stop->start race on real hardware. Use it before and after any change to gvfg_capture.cpp's channel read/release/stop/start, or to GigabyteCaptureSession's wait_frame, release_frame, start_stream, stop_stream, handle_signal_event or restart_stream_after_signal_change."
|
||||
---
|
||||
|
||||
# verify-gvfg-frame-hold (Claude Code entry)
|
||||
|
||||
The skill lives in `.agents/skills/verify-gvfg-frame-hold/` at the GVFG_Standalone repository root, so Claude Code
|
||||
and Codex share one copy. Read `.agents/skills/verify-gvfg-frame-hold/SKILL.md` and follow it. Its scripts are in
|
||||
that folder. Do not copy them here.
|
||||
@@ -0,0 +1,41 @@
|
||||
# AGENTS.md
|
||||
|
||||
本指引適用於 `GVFG_Standalone`。以下路徑及指令以此 Git repository 根目錄為準。
|
||||
|
||||
## 專案入口
|
||||
|
||||
| 改動範圍 | 先看哪裡 |
|
||||
| --- | --- |
|
||||
| 擷取 API、裝置、通道、格式事件與 GPU 轉換 | `GVFG_SDK/sdk/gvfg/`,GigabyteLib adapter 位於 `src/gigabyte/` |
|
||||
| 播放 API、模式、緩衝與影音同步 | `GVFG_SDK/helpers/gvfg_playback/` 與該目錄的 [維護說明](GVFG_SDK/helpers/gvfg_playback/README.md) |
|
||||
| D3D 預覽與 WASAPI 音訊輸出 | `GVFG_SDK/helpers/gvfg_preview/`、`GVFG_SDK/helpers/gvfg_audio_playback/`,兩者都是 Playback 的內部靜態元件 |
|
||||
| OSD | `GVFG_SDK/helpers/gvfg_osd/` |
|
||||
| 建置、Sample 串接與安裝 | [內部建置說明](docs/INTERNAL_BUILD_GUIDE.md) 與各 target 的 `CMakeLists.txt` |
|
||||
|
||||
`../Costomer_SDK_Release/GVFG_Customer_Sample/` 是獨立的 Qt Demo,`../srcroot/` 是完整 Viewer。跨專案驗證可使用這些呼叫端,變更範圍依任務決定。`CaptureDemo/` 有舊範例及驅動參考資料。
|
||||
|
||||
## 實作與相容性
|
||||
|
||||
- 修改前先用 `git status --short` 確認既有變更,讀取相關實作、呼叫端及驗收條件。沿用適用的介面,優先在問題所屬模組修正根因。
|
||||
- 公開 C API 變更應核對標頭、DLL 匯出清單(適用時檢查 `.def`)、呼叫端和安裝規則。保留現有呼叫端依賴的結構配置、狀態碼及資源所有權。版本以 `GVFG_SDK/CMakeLists.txt` 的 `GVFG_SDK_VERSION` 為準,依該檔案的版本政策評估變更。
|
||||
- 擷取改動需追蹤裝置與通道的啟停、格式變更及 frame 的 read/release 配對。涉及 callback、等待或 teardown 時,檢查失敗路徑、重複啟停,以及停止或釋放後是否仍可存取緩衝區。
|
||||
- Playback 管理提交資料的播放副本,模式、時鐘和同步邏輯留在 Playback。涵蓋受影響的 video-only、audio-only、audio-video 或單張影像路徑。預覽略過與錄影掉格分開量測。
|
||||
- 維持 GigabyteLib vendor 介面和播放 backend 的既有邊界。客戶 Release 透過公開 API 使用 SDK,內部診斷依各 target 的組態控制。
|
||||
- 公開契約或用法有變動時,更新對應的 [擷取手冊](docs/GVFG_CUSTOMER_API.md)、[播放手冊](docs/GVFG_PLAYBACK_API.md) 或 [API Reference](docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
|
||||
- 修正缺陷時,若同類錯誤能穩定重現,依現有測試入口加入適當的回歸驗證。需要人工判斷時,記下重現步驟與預期結果。
|
||||
|
||||
## 建置與驗證
|
||||
|
||||
SDK 使用 Windows x64、C++17、CMake 3.16 以上及與 vendor `GvfgSdk.lib` 相容的 MSVC x64 工具鏈。SDK 建置無需 Qt。在 MSVC x64 Developer Command Prompt 確認 Ninja 可用後,從 repository 根目錄執行。
|
||||
|
||||
```bat
|
||||
cmake -S GVFG_SDK -B GVFG_SDK/build_release -G Ninja -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build GVFG_SDK/build_release --target gvfg gvfg_playback
|
||||
```
|
||||
|
||||
- 單項建置可將 `--target` 指定為受影響的 target。涉及公開標頭或共用類別配置時,完整重建 SDK,並用同版標頭、匯入庫和 DLL 乾淨重建相關應用程式。切換 generator 或 toolchain 時,使用獨立的 build 目錄。
|
||||
- 封裝或安裝規則變更時,以 `cmake --install GVFG_SDK/build_release --prefix packages/sdk_check` 安裝到新的目錄,再核對公開標頭、匯入庫、DLL 與文件。需要 MinGW 客戶端匯入庫時,依建置說明設定並驗證 `GVFG_MINGW_DLLTOOL`。
|
||||
- 擷取行為變更依影響範圍在有擷取卡、相容驅動及訊號源的環境驗證。播放行為使用對應的視窗或音訊裝置。依改動檢查有訊號、無訊號、格式切換、停止後重啟、輸出或同步。
|
||||
- 修正擷取缺陷時,記錄卡型、驅動版本、輸入格式、重現步驟與預期行為。用相同條件重測,並驗證受影響的格式切換或停止後重啟流程。
|
||||
- 修正影音同步或效能問題時,先量測基準,再用相同輸入、設定與測試時長比較修改前後。依問題記錄同步偏差、掉格數或其他相關指標,並附上單位與量測方式。缺少硬體或量測工具時,列出尚未驗證的情境。
|
||||
- 文件變更核對路徑、指令及來源定義。交付時列出實際執行的檢查、結果與未驗證項目,分別回報編譯、封裝和實機結果。
|
||||
@@ -3,13 +3,9 @@ cmake_minimum_required(VERSION 3.16)
|
||||
project(gvfg_sdk LANGUAGES CXX)
|
||||
|
||||
# Version policy: breaking public API changes bump MAJOR; features bump MINOR; fixes bump PATCH.
|
||||
set(GVFG_SDK_VERSION "3.0.0")
|
||||
set(GVFG_SDK_VERSION "3.2.0")
|
||||
|
||||
option(GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
|
||||
"UNSAFE local experiment: write OSD into driver zero-copy buffers" OFF)
|
||||
if (GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE)
|
||||
message(WARNING "EXPERIMENTAL driver-buffer writes enabled. Writable pages do not guarantee DMA ownership. Do not ship this build.")
|
||||
endif()
|
||||
option(GVFG_ENABLE_INTERNAL_DIAGNOSTICS "Enable SDK diagnostics in non-Debug builds" OFF)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
@@ -51,8 +47,8 @@ if (NOT WIN32)
|
||||
message(FATAL_ERROR "GVFG SDK currently supports Windows only.")
|
||||
endif()
|
||||
|
||||
add_subdirectory(helpers/gvfg_osd)
|
||||
add_subdirectory(sdk/gvfg)
|
||||
add_subdirectory(helpers/gvfg_osd)
|
||||
add_subdirectory(helpers/gvfg_preview)
|
||||
add_subdirectory(helpers/gvfg_audio_playback)
|
||||
add_subdirectory(helpers/gvfg_playback)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
# Internal WASAPI backend. Only gvfg_playback is installed as a playback DLL.
|
||||
add_library(gvfg_audio_playback STATIC
|
||||
include/gvfg_audio_playback.h
|
||||
src/audio_backend_internal.h
|
||||
src/gvfg_audio_playback.cpp
|
||||
src/audio_output_internal.h
|
||||
)
|
||||
set_target_properties(gvfg_audio_playback PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF)
|
||||
target_include_directories(gvfg_audio_playback PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_include_directories(gvfg_audio_playback PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_playback/include)
|
||||
target_link_libraries(gvfg_audio_playback PRIVATE ole32)
|
||||
if(MSVC)
|
||||
target_compile_options(gvfg_audio_playback PRIVATE /utf-8 /EHsc)
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/* Public PCM format types used by gvfg_playback.h. */
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t sample_rate;
|
||||
uint16_t channels;
|
||||
uint16_t bits_per_sample; /* Signed interleaved PCM; must be 16. */
|
||||
} gvfg_audio_playback_format_t;
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
/* Private static backend; not part of the customer API. */
|
||||
#include "gvfg_audio_playback.h"
|
||||
#include "gvfg_playback.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
project(gvfg_osd_core LANGUAGES CXX)
|
||||
|
||||
add_library(gvfg_osd_core STATIC
|
||||
include/gvfg_osd.h
|
||||
src/gvfg_osd.cpp
|
||||
)
|
||||
|
||||
set_target_properties(gvfg_osd_core PROPERTIES
|
||||
AUTOMOC OFF
|
||||
AUTOUIC OFF
|
||||
AUTORCC OFF
|
||||
)
|
||||
|
||||
target_include_directories(gvfg_osd_core
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(gvfg_osd_core PUBLIC
|
||||
d2d1
|
||||
dwrite
|
||||
windowscodecs
|
||||
ole32
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(gvfg_osd_core PRIVATE /utf-8 /EHsc)
|
||||
add_library(gvfg_osd SHARED gvfg_osd.def include/gvfg_osd.h
|
||||
src/gvfg_osd_api.cpp src/gvfg_osd.cpp src/gvfg_osd_core.h
|
||||
src/gvfg_gpu_osd.cpp src/gvfg_gpu_osd.h)
|
||||
set_target_properties(gvfg_osd PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF)
|
||||
target_include_directories(gvfg_osd PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/gvfg/include
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/gvfg/src)
|
||||
target_compile_definitions(gvfg_osd PRIVATE GVFG_OSD_BUILD)
|
||||
target_link_libraries(gvfg_osd PRIVATE gvfg d2d1 dwrite windowscodecs ole32 d3d11 D3DCompiler)
|
||||
if(MSVC)
|
||||
target_compile_options(gvfg_osd PRIVATE /utf-8 /EHsc)
|
||||
endif()
|
||||
if(MSVC AND GVFG_MINGW_DLLTOOL)
|
||||
add_custom_command(TARGET gvfg_osd POST_BUILD
|
||||
COMMAND "${GVFG_MINGW_DLLTOOL}"
|
||||
-d "${CMAKE_CURRENT_SOURCE_DIR}/gvfg_osd.def"
|
||||
-D gvfg_osd.dll -l libgvfg_osd.dll.a
|
||||
WORKING_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}"
|
||||
COMMENT "Generating MinGW import library for gvfg_osd.dll"
|
||||
VERBATIM
|
||||
)
|
||||
install(FILES "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libgvfg_osd.dll.a"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
install(TARGETS gvfg_osd
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(FILES include/gvfg_osd.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
@@ -77,38 +77,3 @@ to application receipt is acquisition plus OSD/delivery cost. Waiting for the
|
||||
next frame is excluded. The public frame timestamp and old timed-read ABI are
|
||||
unchanged; this uses a separate internal result type and export.
|
||||
Do not ship the internal debug header in customer packages.
|
||||
|
||||
### Unsafe local zero-copy experiment (default OFF)
|
||||
|
||||
Set `GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE=ON` in the standalone SDK's
|
||||
CMake configuration, rebuild `gvfg.dll` and its import library, then rebuild
|
||||
the srcroot viewer against the matching SDK. Enable zero-copy and apply OSD.
|
||||
This is an SDK build option, not the viewer console option.
|
||||
|
||||
The experimental backend supplies the original mutable vendor pointer, without
|
||||
casting away const on the public API. Before processing, `VirtualQuery` checks
|
||||
the entire destination ROI span for committed `PAGE_READWRITE` pages; readonly,
|
||||
guard, copy-on-write, and failed queries fall back to independent output and a
|
||||
full-frame copy. Permissions are checked again immediately before ROI writes;
|
||||
failure at that point returns `GVFG_EIO` without writing. No `VirtualProtect`
|
||||
or vendor release contract change is used. Successful in-place processing
|
||||
retains the backend hold until normal application frame release.
|
||||
|
||||
WARNING: these checks do not prevent concurrent DMA, buffer reuse, or a mapping
|
||||
change after the check. Corruption and access violations remain possible; C++
|
||||
exception handling is not an access-violation safety guarantee. Do not ship this
|
||||
configuration. A successful capture does not establish driver ownership safety.
|
||||
|
||||
The viewer warns at startup and labels each 300-frame diagnostic batch as actual
|
||||
driver-buffer writes, fallback copies, or no in-place processing. Flags use the
|
||||
separate `gvfg_debug_get_channel_osd_experiment_flags` export; existing timing
|
||||
struct layouts stay unchanged. Revert by setting the option OFF and rebuilding
|
||||
the SDK. The client-facing frame pointer remains read-only in all modes.
|
||||
|
||||
Fallback batches also report the final frame's first rejected region: a readable
|
||||
reason, native Protect/State/Type, VirtualQuery return byte count, and Win32 error
|
||||
(captured immediately only when VirtualQuery returns zero). Other frames may
|
||||
have different reasons. This uses the separate internal
|
||||
`gvfg_debug_get_channel_osd_page_check` export, queried while the frame is held;
|
||||
rebuild both SDK and viewer together. No per-frame logging or permission changes
|
||||
are introduced. Zero Win32 error does not imply a writable page.
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
LIBRARY gvfg_osd
|
||||
|
||||
EXPORTS
|
||||
gvfg_get_osd_fonts
|
||||
gvfg_measure_osd_text
|
||||
gvfg_render_osd_frame_bgra
|
||||
gvfg_set_channel_osd
|
||||
gvfg_set_channel_osd_visible
|
||||
gvfg_clear_channel_osd
|
||||
@@ -1,96 +1,113 @@
|
||||
#ifndef GVFG_OSD_H
|
||||
#define GVFG_OSD_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "gvfg_capture.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
# if defined(GVFG_OSD_BUILD)
|
||||
# define GVFG_OSD_API __declspec(dllexport)
|
||||
# else
|
||||
# define GVFG_OSD_API __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
# define GVFG_OSD_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Strings are copied synchronously by gvfg_set_channel_osd(). */
|
||||
typedef struct gvfg_channel_osd_config_t
|
||||
{
|
||||
const char *text; /* NUL-terminated printable ASCII, 1..32 characters. */
|
||||
const char *font_family; /* NUL-terminated UTF-8 installed font family name. */
|
||||
uint32_t font_size_px; /* Non-zero em size; 96-DPI rendering, not ink height. */
|
||||
uint32_t color_rgb; /* 0x00RRGGBB. */
|
||||
int32_t x; /* Text-box left in frame pixels; clamped to fit. */
|
||||
int32_t y; /* Text-box top in frame pixels; clamped to fit. */
|
||||
} gvfg_channel_osd_config_t;
|
||||
|
||||
typedef struct gvfg_osd_font_list_t
|
||||
{
|
||||
uint32_t count;
|
||||
const char *const *names; /* SDK-owned UTF-8 family names; do not modify/free. */
|
||||
} gvfg_osd_font_list_t;
|
||||
|
||||
typedef struct gvfg_osd_bitmap_t
|
||||
{
|
||||
const uint8_t *data; /* SDK-owned; do not modify/free. See the render function's lifetime. */
|
||||
uint64_t data_size; /* stride * height bytes. */
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t stride; /* Byte distance between rows; width * 4. */
|
||||
} gvfg_osd_bitmap_t;
|
||||
|
||||
#define GVFG_OSD_SLOT_COUNT 2u
|
||||
#define GVFG_OSD_MAX_TEXT_CHARACTERS 32u
|
||||
|
||||
typedef void *gvfg_osd_handle;
|
||||
/* Refresh installed fonts and return an SDK-owned snapshot. No device needed.
|
||||
* Pointers expire at the next call (including a failed call), or DLL unload.
|
||||
* Copy names before then. Serialize calls and use of this borrowed list.
|
||||
* Returns an empty list on failure; no callback or caller-side free is needed.
|
||||
*/
|
||||
GVFG_OSD_API gvfg_status_t gvfg_get_osd_fonts(
|
||||
GVFG_PARAM_OUT gvfg_osd_font_list_t *out_list);
|
||||
|
||||
typedef enum gvfg_osd_status_t
|
||||
{
|
||||
GVFG_OSD_OK = 0,
|
||||
GVFG_OSD_EINVAL = -1,
|
||||
GVFG_OSD_ENOMEM = -2,
|
||||
GVFG_OSD_ERENDER = -3
|
||||
} gvfg_osd_status_t;
|
||||
/* Measure the same conservative text box used for rendering, including
|
||||
* overhang and a one-pixel guard per edge. Ignores x/y/color; no device needed.
|
||||
* Outputs are zeroed on failure. Missing font/invalid input: GVFG_EINVAL.
|
||||
*/
|
||||
GVFG_OSD_API gvfg_status_t gvfg_measure_osd_text(
|
||||
GVFG_PARAM_IN const gvfg_channel_osd_config_t *config,
|
||||
GVFG_PARAM_OUT uint32_t *out_width,
|
||||
GVFG_PARAM_OUT uint32_t *out_height);
|
||||
|
||||
typedef enum gvfg_osd_pixel_format_t
|
||||
{
|
||||
GVFG_OSD_PIXFMT_YUY2 = 1,
|
||||
GVFG_OSD_PIXFMT_Y210 = 2
|
||||
} gvfg_osd_pixel_format_t;
|
||||
/* Prepare one transparent video-sized overlay for FPGA transfer. No capture
|
||||
* handle needed; pass the target video width/height in pixels. Output is
|
||||
* top-down BGRA8888, premultiplied alpha, stride = width * 4.
|
||||
* NULL slots are omitted (hidden/unused); both NULL produce a blank frame.
|
||||
* x/y are frame coordinates, clamped to fit; oversized text is skipped.
|
||||
* Slot 1 is composited over slot 0. No video pixels are included.
|
||||
* Data is valid until the next call to this function on the same thread
|
||||
* (including failure), thread exit or DLL unload. Copy for async transfer.
|
||||
* Invalid inputs/dimensions (including byte size above UINT32_MAX) return
|
||||
* GVFG_EINVAL; allocation/render failures return GVFG_EIO. On failure the
|
||||
* output is empty. Does not affect GPU capture OSD.
|
||||
*/
|
||||
GVFG_OSD_API gvfg_status_t gvfg_render_osd_frame_bgra(
|
||||
GVFG_PARAM_IN uint32_t video_width,
|
||||
GVFG_PARAM_IN uint32_t video_height,
|
||||
GVFG_PARAM_IN const gvfg_channel_osd_config_t *slot0,
|
||||
GVFG_PARAM_IN const gvfg_channel_osd_config_t *slot1,
|
||||
GVFG_PARAM_OUT gvfg_osd_bitmap_t *out_bitmap);
|
||||
|
||||
/*
|
||||
* Generates an off-line OSD surface using the requested installed system font. Text is
|
||||
* restricted to printable ASCII and at most GVFG_OSD_MAX_TEXT_CHARACTERS
|
||||
* characters on one line without wrapping. color_rgb is 0xRRGGBB.
|
||||
* x/y identify the top-left of the conservative measured text box (including
|
||||
* glyph overhang and a one-pixel guard). They are clamped to keep that box
|
||||
* inside the frame. Rendering returns EINVAL if the box cannot fit the frame.
|
||||
* Output YUV uses BT.709 limited range. The mask is one coverage byte per
|
||||
* pixel: 0 is transparent and 255 is fully covered.
|
||||
*/
|
||||
typedef struct gvfg_osd_config_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t pixel_format;
|
||||
const char *text;
|
||||
const char *font_family; /* UTF-8, NUL-terminated. */
|
||||
uint32_t text_length;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
uint32_t font_size_px;
|
||||
uint32_t color_rgb;
|
||||
} gvfg_osd_config_t;
|
||||
/* Set and show slot 0 or 1 on an opened channel. Strings are copied before
|
||||
* return; slot 1 is blended over slot 0. Applies to subsequent YUY2/Y210
|
||||
* frames using BT.709 limited range. X/Y are clamped to fit the text box.
|
||||
* An oversized slot is skipped until settings/frame size allow it to fit;
|
||||
* capture and the other slot continue. No wrapping/shrinking/truncation.
|
||||
*/
|
||||
GVFG_OSD_API gvfg_status_t gvfg_set_channel_osd(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_IN uint32_t osd_index,
|
||||
GVFG_PARAM_IN const gvfg_channel_osd_config_t *config);
|
||||
|
||||
/* All buffers are caller-owned and are used only for the duration of render. */
|
||||
typedef struct gvfg_osd_output_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
void *yuv_data;
|
||||
uint64_t yuv_size;
|
||||
uint32_t yuv_stride;
|
||||
void *mask_data;
|
||||
uint64_t mask_size;
|
||||
uint32_t mask_stride;
|
||||
} gvfg_osd_output_t;
|
||||
/* visible must be 0 or 1. Retains settings and cached glyph surfaces.
|
||||
* Showing an unconfigured/cleared slot returns GVFG_ESTATE.
|
||||
*/
|
||||
GVFG_OSD_API gvfg_status_t gvfg_set_channel_osd_visible(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_IN uint32_t osd_index,
|
||||
GVFG_PARAM_IN int visible);
|
||||
|
||||
gvfg_osd_status_t gvfg_osd_create(
|
||||
gvfg_osd_handle *out_handle);
|
||||
|
||||
void gvfg_osd_destroy(
|
||||
gvfg_osd_handle handle);
|
||||
|
||||
/* Conservative whole-text bounds in pixels, not pixel-tight raster bounds. */
|
||||
gvfg_osd_status_t gvfg_osd_measure(
|
||||
gvfg_osd_handle handle,
|
||||
const char *text,
|
||||
uint32_t text_length,
|
||||
uint32_t font_size_px,
|
||||
const char *font_family,
|
||||
uint32_t *out_width,
|
||||
uint32_t *out_height);
|
||||
|
||||
/* SDK-owned snapshot, invalidated by the next call. Serialize call/read access. */
|
||||
gvfg_osd_status_t gvfg_osd_get_fonts(uint32_t *out_count, const char *const **out_names);
|
||||
|
||||
gvfg_osd_status_t gvfg_osd_render(
|
||||
gvfg_osd_handle handle,
|
||||
const gvfg_osd_config_t *config,
|
||||
const gvfg_osd_output_t *output);
|
||||
|
||||
const char *gvfg_osd_strerror(
|
||||
gvfg_osd_status_t status);
|
||||
/* Disable one slot and discard its settings and cached glyph surfaces. */
|
||||
GVFG_OSD_API gvfg_status_t gvfg_clear_channel_osd(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_IN uint32_t osd_index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+4
-93
@@ -1,6 +1,6 @@
|
||||
#include "gvfg_gpu_osd.h"
|
||||
|
||||
#include "gvfg_osd.h"
|
||||
#include "gvfg_osd_core.h"
|
||||
|
||||
#include <d3d11_4.h>
|
||||
#include <d3dcompiler.h>
|
||||
@@ -22,56 +22,6 @@ namespace gvfg::internal
|
||||
{
|
||||
namespace
|
||||
{
|
||||
#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
|
||||
// Permission snapshot only: this does NOT establish exclusive DMA ownership.
|
||||
bool writableExperimentalRange(const gvfg_frame_t &source, uint64_t offset, uint64_t span,
|
||||
gvfg_debug_osd_page_check_t *result)
|
||||
{
|
||||
gvfg_debug_osd_page_check_t check{};
|
||||
const auto reject = [&](gvfg_debug_osd_page_reason_t reason) {
|
||||
check.reason = static_cast<uint32_t>(reason);
|
||||
if (result)
|
||||
*result = check;
|
||||
return false;
|
||||
};
|
||||
const uintptr_t base = reinterpret_cast<uintptr_t>(source.data);
|
||||
const uintptr_t limit = (std::numeric_limits<uintptr_t>::max)();
|
||||
if (!span || offset > source.data_size || span > source.data_size - offset ||
|
||||
offset > limit - base || span > limit - (base + offset))
|
||||
return reject(GVFG_DEBUG_OSD_PAGE_INVALID_RANGE);
|
||||
uintptr_t cursor = base + static_cast<uintptr_t>(offset);
|
||||
const uintptr_t end = cursor + static_cast<uintptr_t>(span);
|
||||
while (cursor < end)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION info{};
|
||||
const SIZE_T queried = VirtualQuery(reinterpret_cast<const void *>(cursor), &info, sizeof(info));
|
||||
// Capture the error immediately, and only on a failed native call.
|
||||
check.win32_error = queried == 0 ? GetLastError() : 0;
|
||||
check.query_bytes = static_cast<uint32_t>(queried);
|
||||
check.protect = info.Protect;
|
||||
check.state = info.State;
|
||||
check.type = info.Type;
|
||||
if (queried != sizeof(info))
|
||||
return reject(GVFG_DEBUG_OSD_PAGE_QUERY_FAILED);
|
||||
if (info.State != MEM_COMMIT)
|
||||
return reject(GVFG_DEBUG_OSD_PAGE_NOT_COMMITTED);
|
||||
if (info.Protect & (PAGE_GUARD | PAGE_NOACCESS))
|
||||
return reject(GVFG_DEBUG_OSD_PAGE_GUARD_OR_NOACCESS);
|
||||
if ((info.Protect & 0xffu) != PAGE_READWRITE)
|
||||
return reject(GVFG_DEBUG_OSD_PAGE_NOT_READWRITE);
|
||||
const uintptr_t regionBase = reinterpret_cast<uintptr_t>(info.BaseAddress);
|
||||
if (info.RegionSize > limit - regionBase)
|
||||
return reject(GVFG_DEBUG_OSD_PAGE_INVALID_REGION);
|
||||
const uintptr_t next = regionBase + info.RegionSize;
|
||||
if (next <= cursor)
|
||||
return reject(GVFG_DEBUG_OSD_PAGE_INVALID_REGION);
|
||||
cursor = next;
|
||||
}
|
||||
if (result)
|
||||
*result = {};
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
constexpr char kOsdBlendShader[] = R"(
|
||||
Texture2D<uint4> sourceTexture : register(t0);
|
||||
Texture2D<uint4> osdTexture : register(t1);
|
||||
@@ -499,20 +449,10 @@ struct GpuOsdProcessor::Impl
|
||||
bool &applied,
|
||||
gvfg_debug_osd_frame_timing_t *timing,
|
||||
uint8_t *writableSource,
|
||||
bool experimentalZeroCopy,
|
||||
bool *inPlaceApplied,
|
||||
uint32_t *experimentFlags,
|
||||
gvfg_debug_osd_page_check_t *pageCheck)
|
||||
bool *inPlaceApplied)
|
||||
{
|
||||
if (pageCheck)
|
||||
*pageCheck = {};
|
||||
if (inPlaceApplied)
|
||||
*inPlaceApplied = false;
|
||||
#ifndef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
|
||||
if (experimentalZeroCopy)
|
||||
return GVFG_EINVAL;
|
||||
(void)experimentFlags;
|
||||
#endif
|
||||
using Clock = std::chrono::steady_clock;
|
||||
auto stageStart = timing ? Clock::now() : Clock::time_point{};
|
||||
const auto finishStage = [timing, &stageStart](gvfg_debug_osd_stage_t stage) {
|
||||
@@ -576,19 +516,6 @@ struct GpuOsdProcessor::Impl
|
||||
if (sourceOffset64 > (std::numeric_limits<size_t>::max)())
|
||||
return GVFG_EINVAL;
|
||||
const size_t sourceOffset = static_cast<size_t>(sourceOffset64);
|
||||
#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
|
||||
const uint64_t writeSpan = static_cast<uint64_t>(region.height - 1u) *
|
||||
source.row_stride_bytes + regionRowBytes;
|
||||
if (experimentalZeroCopy &&
|
||||
(!writableSource || !writableExperimentalRange(source, sourceOffset, writeSpan, pageCheck)))
|
||||
{
|
||||
if (!writableSource && pageCheck)
|
||||
pageCheck->reason = GVFG_DEBUG_OSD_PAGE_NO_POINTER;
|
||||
writableSource = nullptr;
|
||||
if (experimentFlags)
|
||||
*experimentFlags |= GVFG_DEBUG_OSD_EXPERIMENT_REJECTED;
|
||||
}
|
||||
#endif
|
||||
if (!writableSource)
|
||||
destination.resize(static_cast<size_t>(rowBytes) * static_cast<size_t>(source.height));
|
||||
uint8_t *outputData = writableSource ? writableSource : destination.data();
|
||||
@@ -651,16 +578,6 @@ struct GpuOsdProcessor::Impl
|
||||
}
|
||||
const size_t destinationOffset = static_cast<size_t>(region.top) * outputStride +
|
||||
static_cast<size_t>(region.left) * bytesPerPixel;
|
||||
#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
|
||||
// Recheck immediately before writing. Permissions can still change after
|
||||
// this check; neither this nor the SDK hold prevents concurrent DMA.
|
||||
if (experimentalZeroCopy && writableSource &&
|
||||
!writableExperimentalRange(source, sourceOffset, writeSpan, pageCheck))
|
||||
{
|
||||
context->Unmap(readbackTexture.Get(), 0);
|
||||
return GVFG_EIO;
|
||||
}
|
||||
#endif
|
||||
for (uint32_t row = 0; row < region.height; ++row)
|
||||
{
|
||||
std::memcpy(outputData + destinationOffset + static_cast<size_t>(row) * outputStride,
|
||||
@@ -674,8 +591,6 @@ struct GpuOsdProcessor::Impl
|
||||
applied = true;
|
||||
if (inPlaceApplied)
|
||||
*inPlaceApplied = writableSource != nullptr;
|
||||
if (experimentalZeroCopy && writableSource && experimentFlags)
|
||||
*experimentFlags |= GVFG_DEBUG_OSD_EXPERIMENT_USED;
|
||||
if (timing)
|
||||
timing->osd_applied = 1;
|
||||
return GVFG_OK;
|
||||
@@ -723,15 +638,11 @@ gvfg_status_t GpuOsdProcessor::process(const gvfg_frame_t &source,
|
||||
bool &applied,
|
||||
gvfg_debug_osd_frame_timing_t *timing,
|
||||
uint8_t *writableSource,
|
||||
bool experimentalZeroCopy,
|
||||
bool *inPlaceApplied,
|
||||
uint32_t *experimentFlags,
|
||||
gvfg_debug_osd_page_check_t *pageCheck)
|
||||
bool *inPlaceApplied)
|
||||
{
|
||||
try
|
||||
{
|
||||
return impl_->process(source, destination, destinationStride, applied, timing, writableSource,
|
||||
experimentalZeroCopy, inPlaceApplied, experimentFlags, pageCheck);
|
||||
return impl_->process(source, destination, destinationStride, applied, timing, writableSource, inPlaceApplied);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
+2
-7
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "gvfg_capture.h"
|
||||
#include "gvfg_osd.h"
|
||||
#include "gvfg_debug.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -20,8 +20,6 @@ public:
|
||||
gvfg_status_t setVisible(uint32_t index, int visible);
|
||||
// writableSource must equal source.data. Only the backend can grant this
|
||||
// writable SDK-owned storage, held until the caller releases the frame.
|
||||
// The default-OFF experimental override admits driver storage only after
|
||||
// page checks; this is not a driver/DMA ownership guarantee.
|
||||
// nullptr preserves the separate-output path used for driver zero-copy.
|
||||
gvfg_status_t process(const gvfg_frame_t &source,
|
||||
std::vector<uint8_t> &destination,
|
||||
@@ -29,10 +27,7 @@ public:
|
||||
bool &applied,
|
||||
gvfg_debug_osd_frame_timing_t *timing = nullptr,
|
||||
uint8_t *writableSource = nullptr,
|
||||
bool experimentalZeroCopy = false,
|
||||
bool *inPlaceApplied = nullptr,
|
||||
uint32_t *experimentFlags = nullptr,
|
||||
gvfg_debug_osd_page_check_t *pageCheck = nullptr);
|
||||
bool *inPlaceApplied = nullptr);
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "gvfg_osd.h"
|
||||
#include "gvfg_osd_core.h"
|
||||
|
||||
#include <d2d1.h>
|
||||
#include <dwrite.h>
|
||||
@@ -225,10 +225,11 @@ gvfg_osd_status_t createTextLayout(OsdContext &context, const char *text,
|
||||
return GVFG_OSD_OK;
|
||||
}
|
||||
|
||||
gvfg_osd_status_t renderMask(OsdContext &context,
|
||||
const gvfg_osd_config_t &config,
|
||||
uint8_t *destination,
|
||||
uint32_t destinationStride)
|
||||
gvfg_osd_status_t renderBitmap(OsdContext &context,
|
||||
const gvfg_osd_config_t &config,
|
||||
uint8_t *destination,
|
||||
uint32_t destinationStride,
|
||||
bool bgra = false)
|
||||
{
|
||||
MeasuredTextLayout textLayout;
|
||||
const gvfg_osd_status_t layoutStatus = createTextLayout(
|
||||
@@ -242,14 +243,14 @@ gvfg_osd_status_t renderMask(OsdContext &context,
|
||||
|
||||
ComPtr<IWICBitmap> bitmap;
|
||||
HRESULT hr = context.wic->CreateBitmap(config.width, config.height,
|
||||
GUID_WICPixelFormat8bppAlpha,
|
||||
bgra ? GUID_WICPixelFormat32bppPBGRA : GUID_WICPixelFormat8bppAlpha,
|
||||
WICBitmapCacheOnLoad, &bitmap);
|
||||
if (FAILED(hr))
|
||||
return GVFG_OSD_ERENDER;
|
||||
|
||||
D2D1_RENDER_TARGET_PROPERTIES properties = D2D1::RenderTargetProperties(
|
||||
D2D1_RENDER_TARGET_TYPE_SOFTWARE,
|
||||
D2D1::PixelFormat(DXGI_FORMAT_A8_UNORM,
|
||||
D2D1::PixelFormat(bgra ? DXGI_FORMAT_B8G8R8A8_UNORM : DXGI_FORMAT_A8_UNORM,
|
||||
D2D1_ALPHA_MODE_PREMULTIPLIED),
|
||||
96.0f, 96.0f);
|
||||
ComPtr<ID2D1RenderTarget> target;
|
||||
@@ -258,7 +259,8 @@ gvfg_osd_status_t renderMask(OsdContext &context,
|
||||
return GVFG_OSD_ERENDER;
|
||||
|
||||
ComPtr<ID2D1SolidColorBrush> brush;
|
||||
hr = target->CreateSolidColorBrush(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f), &brush);
|
||||
hr = target->CreateSolidColorBrush(
|
||||
D2D1::ColorF(bgra ? (config.color_rgb & 0xffffffu) : 0xffffffu, 1.0f), &brush);
|
||||
if (FAILED(hr))
|
||||
return GVFG_OSD_ERENDER;
|
||||
|
||||
@@ -285,12 +287,16 @@ gvfg_osd_status_t renderMask(OsdContext &context,
|
||||
FAILED(lock->GetDataPointer(&sourceSize, &source)) || !source)
|
||||
return GVFG_OSD_ERENDER;
|
||||
|
||||
const uint32_t rowBytes = config.width * (bgra ? 4u : 1u);
|
||||
if (sourceStride < rowBytes ||
|
||||
static_cast<uint64_t>(sourceStride) * (config.height - 1u) + rowBytes > sourceSize)
|
||||
return GVFG_OSD_ERENDER;
|
||||
for (uint32_t y = 0; y < config.height; ++y)
|
||||
{
|
||||
const uint8_t *sourceRow = source + static_cast<size_t>(y) * sourceStride;
|
||||
uint8_t *destinationRow = destination + static_cast<size_t>(y) * destinationStride;
|
||||
// The A8 bitmap already contains one coverage byte per pixel.
|
||||
std::memcpy(destinationRow, sourceRow, config.width);
|
||||
// Copy native WIC pixels without changing channels or alpha.
|
||||
std::memcpy(destinationRow, sourceRow, rowBytes);
|
||||
}
|
||||
return GVFG_OSD_OK;
|
||||
}
|
||||
@@ -534,7 +540,7 @@ gvfg_osd_status_t gvfg_osd_render(gvfg_osd_handle handle,
|
||||
try
|
||||
{
|
||||
std::memset(output->mask_data, 0, static_cast<size_t>(requiredMask));
|
||||
const gvfg_osd_status_t maskStatus = renderMask(
|
||||
const gvfg_osd_status_t maskStatus = renderBitmap(
|
||||
*static_cast<OsdContext *>(handle), *config,
|
||||
static_cast<uint8_t *>(output->mask_data), output->mask_stride);
|
||||
if (maskStatus != GVFG_OSD_OK)
|
||||
@@ -557,6 +563,33 @@ gvfg_osd_status_t gvfg_osd_render(gvfg_osd_handle handle,
|
||||
}
|
||||
}
|
||||
|
||||
gvfg_osd_status_t gvfg_osd_render_bgra(gvfg_osd_handle handle,
|
||||
const gvfg_osd_config_t *config,
|
||||
void *data, uint64_t data_size, uint32_t stride)
|
||||
{
|
||||
if (!handle || !config || !data ||
|
||||
config->struct_size != sizeof(gvfg_osd_config_t) ||
|
||||
!validAscii(config->text, config->text_length) || config->font_size_px == 0 ||
|
||||
config->width == 0 || config->height == 0 ||
|
||||
config->width > static_cast<uint32_t>((std::numeric_limits<INT>::max)()) ||
|
||||
config->height > static_cast<uint32_t>((std::numeric_limits<INT>::max)()) ||
|
||||
static_cast<uint64_t>(config->width) * 4u > stride)
|
||||
return GVFG_OSD_EINVAL;
|
||||
uint64_t bytes = 0;
|
||||
if (!checkedImageBytes(stride, config->height, bytes) || data_size < bytes ||
|
||||
bytes > (std::numeric_limits<UINT>::max)() ||
|
||||
bytes > (std::numeric_limits<size_t>::max)())
|
||||
return GVFG_OSD_EINVAL;
|
||||
try
|
||||
{
|
||||
std::memset(data, 0, static_cast<size_t>(bytes));
|
||||
return renderBitmap(*static_cast<OsdContext *>(handle), *config,
|
||||
static_cast<uint8_t *>(data), stride, true);
|
||||
}
|
||||
catch (const std::bad_alloc &) { return GVFG_OSD_ENOMEM; }
|
||||
catch (...) { return GVFG_OSD_ERENDER; }
|
||||
}
|
||||
|
||||
const char *gvfg_osd_strerror(gvfg_osd_status_t status)
|
||||
{
|
||||
switch (status)
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
#include "gvfg_osd.h"
|
||||
#include "gvfg_osd_core.h"
|
||||
#include "gvfg_gpu_osd.h"
|
||||
#include "gvfg_frame_processor.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct OsdFrameProcessor
|
||||
{
|
||||
gvfg::internal::GpuOsdProcessor gpu;
|
||||
std::vector<uint8_t> pixels;
|
||||
};
|
||||
|
||||
const gvfg_frame_processor processor{
|
||||
[](void **context) -> gvfg_status_t {
|
||||
try
|
||||
{
|
||||
*context = new OsdFrameProcessor;
|
||||
return GVFG_OK;
|
||||
}
|
||||
catch (const std::bad_alloc &)
|
||||
{
|
||||
return GVFG_EIO;
|
||||
}
|
||||
},
|
||||
[](void *context) { delete static_cast<OsdFrameProcessor *>(context); },
|
||||
[](void *context, const gvfg_frame_t &source, gvfg_frame_t &output,
|
||||
bool &applied, gvfg_debug_osd_frame_timing_t *timing, uint8_t *writable,
|
||||
bool *inPlace) {
|
||||
auto &state = *static_cast<OsdFrameProcessor *>(context);
|
||||
int stride = 0;
|
||||
const auto status = state.gpu.process(source, state.pixels, stride, applied, timing,
|
||||
writable, inPlace);
|
||||
if (status == GVFG_OK && applied && !*inPlace)
|
||||
{
|
||||
output.data = state.pixels.data();
|
||||
output.data_size = state.pixels.size();
|
||||
output.row_stride_bytes = stride;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
};
|
||||
|
||||
struct SlotCommand
|
||||
{
|
||||
uint32_t index;
|
||||
const gvfg_channel_osd_config_t *config;
|
||||
int visible;
|
||||
};
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
gvfg_status_t gvfg_get_osd_fonts(gvfg_osd_font_list_t *out_list)
|
||||
{
|
||||
if (!out_list)
|
||||
return GVFG_EINVAL;
|
||||
*out_list = {};
|
||||
const auto status = gvfg_osd_get_fonts(&out_list->count, &out_list->names);
|
||||
return status == GVFG_OSD_OK ? GVFG_OK : GVFG_EIO;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_measure_osd_text(const gvfg_channel_osd_config_t *config,
|
||||
uint32_t *out_width, uint32_t *out_height)
|
||||
{
|
||||
if (out_width) *out_width = 0;
|
||||
if (out_height) *out_height = 0;
|
||||
if (!config || !config->text || !out_width || !out_height)
|
||||
return GVFG_EINVAL;
|
||||
const size_t length = strnlen_s(config->text, GVFG_OSD_MAX_TEXT_CHARACTERS + 1u);
|
||||
if (length == 0 || length > GVFG_OSD_MAX_TEXT_CHARACTERS)
|
||||
return GVFG_EINVAL;
|
||||
try
|
||||
{
|
||||
gvfg_osd_handle rawHandle = nullptr;
|
||||
if (gvfg_osd_create(&rawHandle) != GVFG_OSD_OK)
|
||||
return GVFG_EIO;
|
||||
const std::unique_ptr<void, decltype(&gvfg_osd_destroy)> helper(rawHandle, &gvfg_osd_destroy);
|
||||
const auto status = gvfg_osd_measure(helper.get(), config->text,
|
||||
static_cast<uint32_t>(length), config->font_size_px, config->font_family,
|
||||
out_width, out_height);
|
||||
return status == GVFG_OSD_OK ? GVFG_OK :
|
||||
status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO;
|
||||
}
|
||||
catch (...) { return GVFG_EIO; }
|
||||
}
|
||||
|
||||
static gvfg_status_t renderOsdBgraTile(const gvfg_channel_osd_config_t *config,
|
||||
gvfg_osd_bitmap_t *out_bitmap,
|
||||
std::vector<uint8_t> &pixels)
|
||||
{
|
||||
if (!config || !config->text)
|
||||
return GVFG_EINVAL;
|
||||
const size_t length = strnlen_s(config->text, GVFG_OSD_MAX_TEXT_CHARACTERS + 1u);
|
||||
if (length == 0 || length > GVFG_OSD_MAX_TEXT_CHARACTERS)
|
||||
return GVFG_EINVAL;
|
||||
try
|
||||
{
|
||||
gvfg_osd_handle rawHandle = nullptr;
|
||||
if (gvfg_osd_create(&rawHandle) != GVFG_OSD_OK)
|
||||
return GVFG_EIO;
|
||||
const std::unique_ptr<void, decltype(&gvfg_osd_destroy)> helper(rawHandle, &gvfg_osd_destroy);
|
||||
uint32_t width = 0, height = 0;
|
||||
auto status = gvfg_osd_measure(helper.get(), config->text,
|
||||
static_cast<uint32_t>(length), config->font_size_px, config->font_family,
|
||||
&width, &height);
|
||||
if (status != GVFG_OSD_OK)
|
||||
return status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO;
|
||||
const uint64_t stride = static_cast<uint64_t>(width) * 4u;
|
||||
// WIC GetDataPointer reports its byte count as UINT.
|
||||
if (width > INT_MAX || height > INT_MAX || stride > UINT_MAX ||
|
||||
stride * height > UINT_MAX ||
|
||||
stride * height > (std::numeric_limits<size_t>::max)())
|
||||
return GVFG_EINVAL;
|
||||
pixels.resize(static_cast<size_t>(stride * height));
|
||||
gvfg_osd_config_t render{};
|
||||
render.struct_size = sizeof(render);
|
||||
render.width = width;
|
||||
render.height = height;
|
||||
render.text = config->text;
|
||||
render.font_family = config->font_family;
|
||||
render.text_length = static_cast<uint32_t>(length);
|
||||
render.font_size_px = config->font_size_px;
|
||||
render.color_rgb = config->color_rgb;
|
||||
status = gvfg_osd_render_bgra(helper.get(), &render, pixels.data(), pixels.size(),
|
||||
static_cast<uint32_t>(stride));
|
||||
if (status != GVFG_OSD_OK)
|
||||
return status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO;
|
||||
out_bitmap->data = pixels.data();
|
||||
out_bitmap->data_size = pixels.size();
|
||||
out_bitmap->width = width;
|
||||
out_bitmap->height = height;
|
||||
out_bitmap->stride = static_cast<uint32_t>(stride);
|
||||
return GVFG_OK;
|
||||
}
|
||||
catch (...) { return GVFG_EIO; }
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_render_osd_frame_bgra(uint32_t video_width, uint32_t video_height,
|
||||
const gvfg_channel_osd_config_t *slot0,
|
||||
const gvfg_channel_osd_config_t *slot1,
|
||||
gvfg_osd_bitmap_t *out_bitmap)
|
||||
{
|
||||
thread_local std::vector<uint8_t> frame;
|
||||
frame.clear();
|
||||
if (!out_bitmap)
|
||||
return GVFG_EINVAL;
|
||||
*out_bitmap = {};
|
||||
const uint64_t stride = static_cast<uint64_t>(video_width) * 4u;
|
||||
if (!video_width || !video_height || stride > UINT32_MAX ||
|
||||
stride * video_height > UINT32_MAX ||
|
||||
stride * video_height > (std::numeric_limits<size_t>::max)())
|
||||
return GVFG_EINVAL;
|
||||
|
||||
try
|
||||
{
|
||||
frame.assign(static_cast<size_t>(stride * video_height), 0);
|
||||
std::vector<uint8_t> tilePixels;
|
||||
for (const auto *slot : {slot0, slot1})
|
||||
{
|
||||
if (!slot)
|
||||
continue;
|
||||
gvfg_osd_bitmap_t tile{};
|
||||
const auto status = renderOsdBgraTile(slot, &tile, tilePixels);
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
if (tile.width > video_width || tile.height > video_height)
|
||||
continue;
|
||||
|
||||
const size_t x = std::clamp<int64_t>(slot->x, 0, video_width - tile.width);
|
||||
const size_t y = std::clamp<int64_t>(slot->y, 0, video_height - tile.height);
|
||||
for (uint32_t row = 0; row < tile.height; ++row)
|
||||
{
|
||||
const auto *src = tile.data + static_cast<size_t>(row) * tile.stride;
|
||||
auto *dst = frame.data() + (y + row) * static_cast<size_t>(stride) + x * 4u;
|
||||
for (uint32_t col = 0; col < tile.width; ++col, src += 4, dst += 4)
|
||||
{
|
||||
if (!src[3])
|
||||
continue;
|
||||
// Both layers are premultiplied, including at glyph edges.
|
||||
const unsigned remaining = 255u - src[3];
|
||||
for (unsigned c = 0; c < 4; ++c)
|
||||
dst[c] = static_cast<uint8_t>(src[c] + (dst[c] * remaining + 127u) / 255u);
|
||||
}
|
||||
}
|
||||
}
|
||||
*out_bitmap = {frame.data(), frame.size(), video_width, video_height,
|
||||
static_cast<uint32_t>(stride)};
|
||||
return GVFG_OK;
|
||||
}
|
||||
catch (...) { return GVFG_EIO; }
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_channel_osd(gvfg_handle handle, int channel_index,
|
||||
uint32_t index, const gvfg_channel_osd_config_t *config)
|
||||
{
|
||||
if (!config || index >= GVFG_OSD_SLOT_COUNT)
|
||||
return gvfg_control_frame_processor(handle, channel_index, &processor, false,
|
||||
nullptr, nullptr, "OSD config or index is invalid");
|
||||
const SlotCommand command{index, config, 0};
|
||||
return gvfg_control_frame_processor(handle, channel_index, &processor, true,
|
||||
[](void *context, const void *argument) {
|
||||
const auto &slot = *static_cast<const SlotCommand *>(argument);
|
||||
return static_cast<OsdFrameProcessor *>(context)->gpu.configure(slot.index, *slot.config);
|
||||
}, &command, "Could not configure OSD slot");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_channel_osd_visible(gvfg_handle handle, int channel_index,
|
||||
uint32_t index, int visible)
|
||||
{
|
||||
if (index >= GVFG_OSD_SLOT_COUNT || (visible != 0 && visible != 1))
|
||||
return gvfg_control_frame_processor(handle, channel_index, &processor, false,
|
||||
nullptr, nullptr, "OSD index or visibility is invalid");
|
||||
const SlotCommand command{index, nullptr, visible};
|
||||
return gvfg_control_frame_processor(handle, channel_index, &processor, true,
|
||||
[](void *context, const void *argument) {
|
||||
const auto &slot = *static_cast<const SlotCommand *>(argument);
|
||||
return static_cast<OsdFrameProcessor *>(context)->gpu.setVisible(slot.index, slot.visible);
|
||||
}, &command, "Could not change OSD visibility");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_clear_channel_osd(gvfg_handle handle, int channel_index, uint32_t index)
|
||||
{
|
||||
if (index >= GVFG_OSD_SLOT_COUNT)
|
||||
return gvfg_control_frame_processor(handle, channel_index, &processor, false,
|
||||
nullptr, nullptr, "OSD index is invalid");
|
||||
return gvfg_control_frame_processor(handle, channel_index, &processor, false,
|
||||
[](void *context, const void *argument) {
|
||||
return static_cast<OsdFrameProcessor *>(context)->gpu.clear(*static_cast<const uint32_t *>(argument));
|
||||
}, &index, "Could not clear OSD slot");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
#ifndef GVFG_OSD_H
|
||||
#define GVFG_OSD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef GVFG_OSD_MAX_TEXT_CHARACTERS
|
||||
#define GVFG_OSD_MAX_TEXT_CHARACTERS 32u
|
||||
#endif
|
||||
|
||||
typedef void *gvfg_osd_handle;
|
||||
|
||||
typedef enum gvfg_osd_status_t
|
||||
{
|
||||
GVFG_OSD_OK = 0,
|
||||
GVFG_OSD_EINVAL = -1,
|
||||
GVFG_OSD_ENOMEM = -2,
|
||||
GVFG_OSD_ERENDER = -3
|
||||
} gvfg_osd_status_t;
|
||||
|
||||
typedef enum gvfg_osd_pixel_format_t
|
||||
{
|
||||
GVFG_OSD_PIXFMT_YUY2 = 1,
|
||||
GVFG_OSD_PIXFMT_Y210 = 2
|
||||
} gvfg_osd_pixel_format_t;
|
||||
|
||||
/*
|
||||
* Generates an off-line OSD surface using the requested installed system font. Text is
|
||||
* restricted to printable ASCII and at most GVFG_OSD_MAX_TEXT_CHARACTERS
|
||||
* characters on one line without wrapping. color_rgb is 0xRRGGBB.
|
||||
* x/y identify the top-left of the conservative measured text box (including
|
||||
* glyph overhang and a one-pixel guard). They are clamped to keep that box
|
||||
* inside the frame. Rendering returns EINVAL if the box cannot fit the frame.
|
||||
* Output YUV uses BT.709 limited range. The mask is one coverage byte per
|
||||
* pixel: 0 is transparent and 255 is fully covered.
|
||||
*/
|
||||
typedef struct gvfg_osd_config_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t pixel_format;
|
||||
const char *text;
|
||||
const char *font_family; /* UTF-8, NUL-terminated. */
|
||||
uint32_t text_length;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
uint32_t font_size_px;
|
||||
uint32_t color_rgb;
|
||||
} gvfg_osd_config_t;
|
||||
|
||||
/* All buffers are caller-owned and are used only for the duration of render. */
|
||||
typedef struct gvfg_osd_output_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
void *yuv_data;
|
||||
uint64_t yuv_size;
|
||||
uint32_t yuv_stride;
|
||||
void *mask_data;
|
||||
uint64_t mask_size;
|
||||
uint32_t mask_stride;
|
||||
} gvfg_osd_output_t;
|
||||
|
||||
gvfg_osd_status_t gvfg_osd_create(
|
||||
gvfg_osd_handle *out_handle);
|
||||
|
||||
void gvfg_osd_destroy(
|
||||
gvfg_osd_handle handle);
|
||||
|
||||
/* Conservative whole-text bounds in pixels, not pixel-tight raster bounds. */
|
||||
gvfg_osd_status_t gvfg_osd_measure(
|
||||
gvfg_osd_handle handle,
|
||||
const char *text,
|
||||
uint32_t text_length,
|
||||
uint32_t font_size_px,
|
||||
const char *font_family,
|
||||
uint32_t *out_width,
|
||||
uint32_t *out_height);
|
||||
|
||||
/* SDK-owned snapshot, invalidated by the next call. Serialize call/read access. */
|
||||
gvfg_osd_status_t gvfg_osd_get_fonts(uint32_t *out_count, const char *const **out_names);
|
||||
|
||||
gvfg_osd_status_t gvfg_osd_render(
|
||||
gvfg_osd_handle handle,
|
||||
const gvfg_osd_config_t *config,
|
||||
const gvfg_osd_output_t *output);
|
||||
|
||||
/* Caller-owned, top-down BGRA8888 with premultiplied alpha. Ignores pixel_format.
|
||||
* Unlike YUV output, width may be odd. No RGB/YUV conversion is performed.
|
||||
*/
|
||||
gvfg_osd_status_t gvfg_osd_render_bgra(
|
||||
gvfg_osd_handle handle,
|
||||
const gvfg_osd_config_t *config,
|
||||
void *data, uint64_t data_size, uint32_t stride);
|
||||
|
||||
const char *gvfg_osd_strerror(
|
||||
gvfg_osd_status_t status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -14,15 +14,13 @@ set_target_properties(gvfg_playback PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC O
|
||||
target_include_directories(gvfg_playback
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_preview/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_audio_playback/include
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_audio_playback/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_preview/src
|
||||
)
|
||||
target_compile_definitions(gvfg_playback PRIVATE GVFG_PLAYBACK_BUILD
|
||||
GVFG_INTERNAL_DIAGNOSTICS=$<IF:$<CONFIG:Debug>,1,0>)
|
||||
GVFG_INTERNAL_DIAGNOSTICS=$<OR:$<CONFIG:Debug>,$<BOOL:${GVFG_ENABLE_INTERNAL_DIAGNOSTICS}>>)
|
||||
target_link_libraries(gvfg_playback PRIVATE gvfg_audio_playback gvfg_preview user32 gdi32 comctl32)
|
||||
if(MSVC)
|
||||
target_compile_options(gvfg_playback PRIVATE /utf-8 /EHsc)
|
||||
@@ -42,10 +40,8 @@ endif()
|
||||
install(TARGETS gvfg_playback
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
# Backend headers supply the frame/format/stat types used by the public API.
|
||||
# The unified public header contains all playback types and declarations.
|
||||
install(FILES include/gvfg_playback.h
|
||||
../gvfg_audio_playback/include/gvfg_audio_playback.h
|
||||
../gvfg_preview/include/gvfg_preview.h
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
# This README describes private internals. Customer guides are installed by
|
||||
# the SDK root with the same relative layout as docs/.
|
||||
|
||||
@@ -147,7 +147,8 @@ stop/reset 取消 queue,不是無損 drain。reset 沿用舊 config,音訊
|
||||
呼叫端先停止/join read producers、release token,再停止 Playback 與 Capture。
|
||||
|
||||
詳細統計位於私有 `src/playback_debug.h`,不安裝到客戶套件。核心保留診斷計數與同步狀態。
|
||||
僅 Debug DLL 匯出 `gvfg_playback_debug_get_stats()`;內部工具須定義
|
||||
詳細 Preview delivery 計數型別位於私有 `../gvfg_preview/src/preview_delivery_stats.h`。
|
||||
僅 Debug DLL 匯出 `gvfg_playback_debug_get_stats()` 與 `gvfg_playback_debug_get_delivery_stats()`;內部工具須定義
|
||||
`GVFG_INTERNAL_DIAGNOSTICS=1` 並使用同一版私有標頭與 MSVC Debug 匯入庫。
|
||||
診斷結構不提供穩定 ABI 或舊大小相容;Release DLL 不匯出診斷查詢。
|
||||
config 仍要求目前完整的 struct_size。
|
||||
|
||||
@@ -15,5 +15,4 @@ EXPORTS
|
||||
gvfg_playback_destroy
|
||||
gvfg_playback_get_preview_info
|
||||
gvfg_playback_get_preview_stats
|
||||
gvfg_playback_get_delivery_stats
|
||||
gvfg_playback_strerror
|
||||
|
||||
@@ -7,8 +7,67 @@
|
||||
* Control calls (start/stop/reset/attach/destroy) must be serialized by the
|
||||
* caller; one video producer and one audio producer may submit concurrently.
|
||||
*/
|
||||
#include "gvfg_audio_playback.h"
|
||||
#include "gvfg_preview.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* Public audio, image and presentation types. Backends remain private. */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t sample_rate;
|
||||
uint16_t channels;
|
||||
uint16_t bits_per_sample; /* Signed interleaved PCM; must be 16. */
|
||||
} gvfg_audio_playback_format_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_PREVIEW_PIXFMT_YUY2 = 1,
|
||||
GVFG_PREVIEW_PIXFMT_Y210 = 2,
|
||||
GVFG_PREVIEW_PIXFMT_GRAY16 = 4,
|
||||
|
||||
/* Four interleaved 16-bit UNORM components per pixel: R, G, B, A. */
|
||||
GVFG_PREVIEW_PIXFMT_RGBA16 = 5,
|
||||
|
||||
/* DICOM native YBR_FULL_422: four 16-bit words per pixel pair,
|
||||
* ordered Y0, Y1, Cb, Cr. Values are right-aligned to bit_depth. */
|
||||
GVFG_PREVIEW_PIXFMT_DICOM_YBR_FULL_422 = 6
|
||||
} gvfg_preview_pixel_format_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const void *data;
|
||||
uint64_t data_size;
|
||||
int width;
|
||||
int height;
|
||||
int pixel_format; /* gvfg_preview_pixel_format_t */
|
||||
int bit_depth;
|
||||
int row_bytes;
|
||||
uint64_t frame_id;
|
||||
} gvfg_preview_frame_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int active;
|
||||
int width;
|
||||
int height;
|
||||
int bit_depth;
|
||||
char pixel_format[32];
|
||||
char adapter_name[160];
|
||||
int adapter_index;
|
||||
} gvfg_preview_info_t;
|
||||
|
||||
/*
|
||||
* Preview presentation statistics.
|
||||
*
|
||||
* present_fps counts only frames accepted by DXGI Present, not physical
|
||||
* scanout. The rate uses successful presents from the most recent five
|
||||
* seconds. Pending preview replacements are excluded from this rate.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
double present_fps;
|
||||
uint64_t presented_frames;
|
||||
uint64_t skipped_presents;
|
||||
} gvfg_preview_stats_t;
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef GVFG_PLAYBACK_BUILD
|
||||
@@ -30,7 +89,7 @@ typedef enum {
|
||||
GVFG_PLAYBACK_EINVAL = -1,
|
||||
GVFG_PLAYBACK_ESTATE = -2,
|
||||
GVFG_PLAYBACK_EOUTPUT = -3,
|
||||
GVFG_PLAYBACK_EQUEUE_FULL = -4,
|
||||
GVFG_PLAYBACK_EQUEUE_FULL = -4, /* Reserved; current APIs do not return this value. */
|
||||
GVFG_PLAYBACK_EDISCONTINUITY = -5,
|
||||
GVFG_PLAYBACK_EAUDIO = -6 /* A/V audio output disabled; video remains running. */
|
||||
} gvfg_playback_status_t;
|
||||
@@ -51,6 +110,7 @@ typedef struct {
|
||||
gvfg_playback_master_t master;
|
||||
gvfg_audio_playback_format_t audio_format;
|
||||
uint32_t preroll_ms; /* Default 100; required coverage of both streams. */
|
||||
/* Advanced capacity limits; normally keep the values from default_config. */
|
||||
uint32_t max_video_frames; /* Default 32; late preview frames are retired and counted. */
|
||||
uint32_t max_audio_ms; /* Default 1000. */
|
||||
uint64_t max_video_bytes; /* Default 256 MiB, including in-flight copy. */
|
||||
@@ -85,13 +145,15 @@ GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_submit_video(gvfg_playbac
|
||||
* Requires an attached window and a stopped handle. Caller data stays valid
|
||||
* through return. Used for RAW/DICOM image display; no audio is initialized. */
|
||||
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_present_image(gvfg_playback p, const gvfg_preview_frame_t *image);
|
||||
/* In A/V mode an audio-output failure disables monitoring for this handle,
|
||||
* preserving video playback. Subsequent audio submissions return EAUDIO.
|
||||
* Keep capture/recording audio independent; do not retry output on this handle.
|
||||
* Recreate the handle to retry monitoring. Stop/reset does not clear EAUDIO.
|
||||
/* In A/V mode an unavailable audio output returns EAUDIO while video continues.
|
||||
* With reconnect enabled, keep submitting new PCM so monitoring can resume
|
||||
* when the default output becomes available. Otherwise recreate the handle
|
||||
* to retry monitoring. Keep capture/recording audio independent.
|
||||
* A/V start may succeed with monitoring disabled; audio-only start still fails
|
||||
* if its output is unavailable. Other errors retain their normal meaning. */
|
||||
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_submit_audio(gvfg_playback p, const void *pcm, uint32_t bytes, uint64_t timestamp_ns);
|
||||
/* Opt in before start. Retries the default Windows output in A/V mode only. */
|
||||
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_enable_audio_reconnect(gvfg_playback p);
|
||||
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_set_volume(gvfg_playback p, float gain);
|
||||
/* Default enabled=1. Set 0 for independent best-effort playback with no
|
||||
* automatic return to synchronization. May be called before start or while
|
||||
@@ -105,7 +167,6 @@ GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_stop(gvfg_playback p);
|
||||
GVFG_PLAYBACK_API void gvfg_playback_destroy(gvfg_playback p);
|
||||
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_preview_info(gvfg_playback p, gvfg_preview_info_t *info);
|
||||
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_preview_stats(gvfg_playback p, gvfg_preview_stats_t *stats);
|
||||
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_delivery_stats(gvfg_playback p, gvfg_preview_delivery_stats_t *stats);
|
||||
GVFG_PLAYBACK_API const char *gvfg_playback_strerror(gvfg_playback_status_t status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
#include <condition_variable>
|
||||
#include <cstdlib>
|
||||
#include <deque>
|
||||
#include <future>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <new>
|
||||
#include <thread>
|
||||
@@ -42,6 +44,8 @@ struct gvfg_playback_t {
|
||||
bool stopping = false, active = false;
|
||||
bool sync_enabled = true;
|
||||
bool audio_output_failed = false;
|
||||
bool audio_reconnect_enabled = false;
|
||||
uint64_t audio_retry_at = 0;
|
||||
float gain = 1.0f;
|
||||
void *hwnd = nullptr;
|
||||
SignalCard signal_card;
|
||||
@@ -94,14 +98,14 @@ struct gvfg_playback_t {
|
||||
if (!has_video()) { fail(GVFG_PLAYBACK_EOUTPUT); return; }
|
||||
if (audio_output_failed) return;
|
||||
audio_output_failed = true;
|
||||
audio_retry_at = now_ns() + 1'000'000'000;
|
||||
drop_audio();
|
||||
gvfg_audio_player_destroy(audio); audio = nullptr;
|
||||
audio_source_clock = {}; audio_timeline = {};
|
||||
first_audio = audio_end = 0;
|
||||
stats.audio_timestamp_ns = 0; stats.av_difference_ns = 0;
|
||||
stats.audio_rate_ratio = 1;
|
||||
// Retain video packets and move off a failed audio master. Monitoring
|
||||
// remains disabled across resets; a fresh handle may retry the device.
|
||||
// Retain video packets and move off a failed audio master.
|
||||
degrade(now_ns());
|
||||
}
|
||||
void fail(gvfg_playback_status_t error) {
|
||||
@@ -130,11 +134,46 @@ struct gvfg_playback_t {
|
||||
};
|
||||
|
||||
void gvfg_playback_t::loop() {
|
||||
using AudioPlayer = std::unique_ptr<gvfg_audio_player_t, decltype(&gvfg_audio_player_destroy)>;
|
||||
std::future<AudioPlayer> audio_retry;
|
||||
uint64_t last_control = 0;
|
||||
bool started = false, preview_ready = false;
|
||||
for (;;) {
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
if (stopping) break;
|
||||
if (audio_retry.valid() && audio_retry.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
|
||||
auto candidate = audio_retry.get();
|
||||
audio_retry_at = now_ns() + 1'000'000'000;
|
||||
if (candidate && audio_output_failed) {
|
||||
gvfg_audio_player_set_volume(candidate.get(), gain);
|
||||
audio = candidate.release();
|
||||
last_audio_delivery = last_audio_arrival = 0;
|
||||
recovery_rate = {};
|
||||
fallback_audio_primed = false;
|
||||
audio_wait_since = stable_since = 0;
|
||||
audio_output_failed = false;
|
||||
}
|
||||
}
|
||||
if (audio_reconnect_enabled && config.mode == GVFG_PLAYBACK_AUDIO_VIDEO &&
|
||||
audio_output_failed && !audio_retry.valid() && now_ns() >= audio_retry_at &&
|
||||
stats.last_error == GVFG_PLAYBACK_OK) {
|
||||
const auto format = config.audio_format;
|
||||
try {
|
||||
audio_retry = std::async(std::launch::async, [format] {
|
||||
AudioPlayer candidate(nullptr, gvfg_audio_player_destroy);
|
||||
try {
|
||||
candidate.reset(audio_output_create_managed());
|
||||
if (candidate && gvfg_audio_player_start(candidate.get(), &format) != GVFG_AUDIO_PLAYBACK_OK)
|
||||
candidate.reset();
|
||||
} catch (...) {
|
||||
candidate.reset();
|
||||
}
|
||||
return candidate;
|
||||
});
|
||||
} catch (...) {
|
||||
audio_retry_at = now_ns() + 1'000'000'000;
|
||||
}
|
||||
}
|
||||
if (stats.last_error != GVFG_PLAYBACK_OK) {
|
||||
changed.wait_for(lock, std::chrono::milliseconds(2)); continue;
|
||||
}
|
||||
@@ -468,10 +507,14 @@ gvfg_playback_status_t gvfg_playback_present_image(gvfg_playback p, const gvfg_p
|
||||
}
|
||||
// Like attach/start/stop, callers serialize this control operation. Do not
|
||||
// hold the playback mutex while DXGI can send synchronous HWND messages.
|
||||
gvfg_preview_delivery_stats_t before{}, after{};
|
||||
if (gvfg_preview_wait_idle(preview, 2000) != GVFG_PREVIEW_OK ||
|
||||
gvfg_preview_prepare(preview, image->width, image->height, image->bit_depth) != GVFG_PREVIEW_OK ||
|
||||
gvfg_preview_get_delivery_stats(preview, &before) != GVFG_PREVIEW_OK ||
|
||||
gvfg_preview_render_frame(preview, image) != GVFG_PREVIEW_OK ||
|
||||
gvfg_preview_wait_idle(preview, 2000) != GVFG_PREVIEW_OK)
|
||||
gvfg_preview_wait_idle(preview, 2000) != GVFG_PREVIEW_OK ||
|
||||
gvfg_preview_get_delivery_stats(preview, &after) != GVFG_PREVIEW_OK ||
|
||||
after.presented == before.presented)
|
||||
return GVFG_PLAYBACK_EOUTPUT;
|
||||
return GVFG_PLAYBACK_OK;
|
||||
}
|
||||
@@ -555,6 +598,13 @@ gvfg_playback_status_t gvfg_playback_set_sync_enabled(gvfg_playback p, int enabl
|
||||
if (p->active && !p->sync_enabled) p->degrade(now_ns(), false);
|
||||
return GVFG_PLAYBACK_OK;
|
||||
}
|
||||
gvfg_playback_status_t gvfg_playback_enable_audio_reconnect(gvfg_playback p) {
|
||||
if (!p) return GVFG_PLAYBACK_EINVAL;
|
||||
std::lock_guard<std::mutex> lock(p->mutex);
|
||||
if (p->active) return GVFG_PLAYBACK_ESTATE;
|
||||
p->audio_reconnect_enabled = true;
|
||||
return GVFG_PLAYBACK_OK;
|
||||
}
|
||||
gvfg_playback_status_t gvfg_playback_stop(gvfg_playback p) {
|
||||
if (!p) return GVFG_PLAYBACK_EINVAL;
|
||||
{ std::lock_guard<std::mutex> lock(p->mutex); p->stopping = true; p->changed.notify_all(); }
|
||||
@@ -606,11 +656,13 @@ gvfg_playback_status_t gvfg_playback_get_preview_stats(gvfg_playback p, gvfg_pre
|
||||
*s = {}; return !p->preview || gvfg_preview_get_stats(p->preview, s) == GVFG_PREVIEW_OK ? GVFG_PLAYBACK_OK : GVFG_PLAYBACK_EOUTPUT;
|
||||
}
|
||||
|
||||
gvfg_playback_status_t gvfg_playback_get_delivery_stats(gvfg_playback p, gvfg_preview_delivery_stats_t *s) {
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
gvfg_playback_status_t gvfg_playback_debug_get_delivery_stats(gvfg_playback p, gvfg_preview_delivery_stats_t *s) {
|
||||
if (!p || !s) return GVFG_PLAYBACK_EINVAL;
|
||||
std::lock_guard<std::mutex> lock(p->mutex);
|
||||
*s = {}; return !p->preview || gvfg_preview_get_delivery_stats(p->preview, s) == GVFG_PREVIEW_OK ? GVFG_PLAYBACK_OK : GVFG_PLAYBACK_EOUTPUT;
|
||||
}
|
||||
#endif
|
||||
const char *gvfg_playback_strerror(gvfg_playback_status_t s) {
|
||||
switch (s) {
|
||||
case GVFG_PLAYBACK_OK: return "ok";
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/* Internal playback diagnostics. Do not install or ship this header.
|
||||
* The query is exported only by Debug builds. No stable diagnostic ABI. */
|
||||
#include "gvfg_playback.h"
|
||||
#include "../../gvfg_preview/src/preview_delivery_stats.h"
|
||||
|
||||
typedef struct {
|
||||
int running;
|
||||
@@ -32,6 +33,8 @@ extern "C" {
|
||||
#endif
|
||||
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_debug_get_stats(
|
||||
gvfg_playback p, gvfg_playback_debug_stats_t *stats);
|
||||
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_debug_get_delivery_stats(
|
||||
gvfg_playback p, gvfg_preview_delivery_stats_t *stats);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
add_library(gvfg_preview STATIC
|
||||
include/gvfg_preview.h
|
||||
src/preview_delivery_stats.h
|
||||
src/preview_output_internal.h
|
||||
../../sdk/gvfg/src/gpu/d3d_conversion_pipeline.cpp
|
||||
../../sdk/gvfg/src/gpu/d3d_conversion_pipeline.h
|
||||
@@ -13,9 +13,8 @@ set_target_properties(gvfg_preview PROPERTIES
|
||||
)
|
||||
|
||||
target_include_directories(gvfg_preview
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_playback/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/gvfg/src/gpu
|
||||
)
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/* Public image and presentation types used by gvfg_playback.h. */
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_PREVIEW_PIXFMT_YUY2 = 1,
|
||||
GVFG_PREVIEW_PIXFMT_Y210 = 2,
|
||||
GVFG_PREVIEW_PIXFMT_GRAY16 = 4,
|
||||
|
||||
/* Four interleaved 16-bit UNORM components per pixel: R, G, B, A. */
|
||||
GVFG_PREVIEW_PIXFMT_RGBA16 = 5,
|
||||
|
||||
/* DICOM native YBR_FULL_422: four 16-bit words per pixel pair,
|
||||
* ordered Y0, Y1, Cb, Cr. Values are right-aligned to bit_depth. */
|
||||
GVFG_PREVIEW_PIXFMT_DICOM_YBR_FULL_422 = 6
|
||||
} gvfg_preview_pixel_format_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const void *data;
|
||||
uint64_t data_size;
|
||||
int width;
|
||||
int height;
|
||||
int pixel_format; /* gvfg_preview_pixel_format_t */
|
||||
int bit_depth;
|
||||
int row_bytes;
|
||||
uint64_t frame_id;
|
||||
} gvfg_preview_frame_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int active;
|
||||
int width;
|
||||
int height;
|
||||
int bit_depth;
|
||||
char pixel_format[32];
|
||||
char adapter_name[160];
|
||||
int adapter_index;
|
||||
} gvfg_preview_info_t;
|
||||
|
||||
/*
|
||||
* Preview presentation statistics.
|
||||
*
|
||||
* present_fps counts only frames accepted by DXGI Present, not physical
|
||||
* scanout. The rate uses successful presents from the most recent five
|
||||
* seconds. Pending preview replacements are excluded from this rate.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
double present_fps;
|
||||
uint64_t presented_frames;
|
||||
uint64_t skipped_presents;
|
||||
} gvfg_preview_stats_t;
|
||||
|
||||
/* Lifetime counters (until shutdown); configure/clear do not reset them.
|
||||
* submitted = presented + replaced + busy + failed + cancelled + in_flight.
|
||||
* Presented means DXGI accepted Present, not proof of physical scanout.
|
||||
* Failed render API calls are counted by the caller, not in submitted.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint64_t submitted;
|
||||
uint64_t presented;
|
||||
uint64_t replaced; /* Queued frames discarded after the 50 ms age limit. */
|
||||
uint64_t busy;
|
||||
uint64_t failed;
|
||||
uint64_t cancelled;
|
||||
uint64_t in_flight;
|
||||
uint64_t last_presented_id;
|
||||
uint64_t present_busy;
|
||||
uint64_t slots_busy;
|
||||
uint64_t last_busy_id;
|
||||
} gvfg_preview_delivery_stats_t;
|
||||
@@ -843,7 +843,7 @@ extern "C"
|
||||
switch (frame->pixel_format)
|
||||
{
|
||||
case GVFG_PREVIEW_PIXFMT_YUY2:
|
||||
minimumRowBytes = static_cast<uint64_t>(frame->width) * 2u;
|
||||
minimumRowBytes = (static_cast<uint64_t>(frame->width) + 1u) / 2u * 4u;
|
||||
break;
|
||||
case GVFG_PREVIEW_PIXFMT_Y210:
|
||||
minimumRowBytes = static_cast<uint64_t>(frame->width) * 4u;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
/* Private preview diagnostics; never install this header. */
|
||||
#include <stdint.h>
|
||||
|
||||
/* Lifetime counters (until shutdown); configure/clear do not reset them.
|
||||
* submitted = presented + replaced + busy + failed + cancelled + in_flight.
|
||||
* Presented means DXGI accepted Present, not proof of physical scanout.
|
||||
* Failed render API calls are counted by the caller, not in submitted.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint64_t submitted;
|
||||
uint64_t presented;
|
||||
uint64_t replaced; /* Queued frames discarded after the 50 ms age limit. */
|
||||
uint64_t busy;
|
||||
uint64_t failed;
|
||||
uint64_t cancelled;
|
||||
uint64_t in_flight;
|
||||
uint64_t last_presented_id;
|
||||
uint64_t present_busy;
|
||||
uint64_t slots_busy;
|
||||
uint64_t last_busy_id;
|
||||
} gvfg_preview_delivery_stats_t;
|
||||
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/* Private static backend; not part of the customer API. */
|
||||
#include "gvfg_preview.h"
|
||||
#include "gvfg_playback.h"
|
||||
#include "preview_delivery_stats.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -16,8 +16,7 @@ add_library(gvfg SHARED
|
||||
src/gpu/d3d_conversion_pipeline.cpp
|
||||
src/gpu/d3d_conversion_pipeline.h
|
||||
src/gpu/gvfg_gpu_convert.cpp
|
||||
src/gpu/gvfg_gpu_osd.cpp
|
||||
src/gpu/gvfg_gpu_osd.h
|
||||
src/gvfg_frame_processor.h
|
||||
src/gvfg_error_state.h
|
||||
src/gvfg_capture.cpp
|
||||
)
|
||||
@@ -44,14 +43,10 @@ target_compile_definitions(gvfg PRIVATE
|
||||
)
|
||||
|
||||
target_compile_definitions(gvfg PRIVATE
|
||||
GVFG_INTERNAL_DIAGNOSTICS=$<IF:$<CONFIG:Debug>,1,0>
|
||||
GVFG_INTERNAL_DIAGNOSTICS=$<OR:$<CONFIG:Debug>,$<BOOL:${GVFG_ENABLE_INTERNAL_DIAGNOSTICS}>>
|
||||
)
|
||||
if (GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE)
|
||||
target_compile_definitions(gvfg PRIVATE GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE=1)
|
||||
endif()
|
||||
|
||||
target_link_libraries(gvfg PRIVATE
|
||||
gvfg_osd_core
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/GigabyteLib/GvfgSdk.lib"
|
||||
setupapi
|
||||
user32
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
out/
|
||||
states/
|
||||
*.st
|
||||
tools/
|
||||
@@ -0,0 +1,347 @@
|
||||
--------------------------- MODULE CaptureFrameHold ---------------------------
|
||||
(***************************************************************************)
|
||||
(* The frame-hold protocol of one GVFG capture channel. *)
|
||||
(* *)
|
||||
(* Promise checked: while the application holds a frame whose data is the *)
|
||||
(* backend capture buffer, (1) that buffer still belongs to the running *)
|
||||
(* driver stream -- no recovery restart and no stop/start has replaced it *)
|
||||
(* -- and (2) the one gvfg_release_channel_frame() the application must *)
|
||||
(* make will succeed. *)
|
||||
(* *)
|
||||
(* Harm if broken: the application reads a zero-copy buffer the driver is *)
|
||||
(* refilling (torn or foreign video), and/or its release returns *)
|
||||
(* GVFG_ESTATE and the channel stays "frame held", so every later read is *)
|
||||
(* rejected until stop. *)
|
||||
(* *)
|
||||
(* Threads: R = application video worker (read / release), *)
|
||||
(* U = application lifecycle thread (stop / start, serialized), *)
|
||||
(* E = session event thread (signal change -> recovery restart). *)
|
||||
(* Each action is one indivisible step in the code: a section under one *)
|
||||
(* mutex, or one atomic access. Code references name the function in *)
|
||||
(* C = GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp (gvfg_channel_session_t) *)
|
||||
(* S = GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp *)
|
||||
(***************************************************************************)
|
||||
EXTENDS Naturals
|
||||
|
||||
CONSTANTS
|
||||
AppQuiescesReader, \* TRUE: app joins/pauses its reader before stop/start (srcroot GvfgSource::stop does)
|
||||
Guards, \* code checks present; the shipped code has all of them (see MC .cfg files)
|
||||
MaxLifecycleOps, \* bound on stop/start calls
|
||||
MaxSignalEvents, \* bound on format-change / plug-in events
|
||||
MaxReads \* bound on read attempts
|
||||
|
||||
AllGuards == {"RestartWaitsForRelease", "CaptureRejectsDuringRecovery",
|
||||
"DeliverRechecksRunning", "DeliverChecksRunGeneration"}
|
||||
ASSUME Guards \subseteq AllGuards
|
||||
|
||||
VARIABLES
|
||||
\* --- channel, C: gvfg_channel_session_t -------------------------------
|
||||
running, \* C running (std::atomic<bool>)
|
||||
readInProgress, \* C readInProgress (frameMutex)
|
||||
frameHeld, \* C frameHeld (frameMutex)
|
||||
heldNeedsBackend, \* C heldFrameNeedsBackendRelease (frameMutex)
|
||||
heldEpoch, \* ghost: driver stream epoch of the buffer in heldSessionFrame
|
||||
runGen, \* C runGeneration (frameMutex): +1 on every successful start
|
||||
\* --- session, S: GigabyteCaptureSession -------------------------------
|
||||
sRunning, \* S running_
|
||||
sFrameHeld, \* S frame_held_ (state_mutex_)
|
||||
recoveryPending, \* S recovery_pending_
|
||||
generation, \* S signal_generation_
|
||||
epoch, \* ghost: +1 on every GvfgStartCapture (driver buffers handed out anew)
|
||||
monitoring, \* S monitoring_ (event thread alive)
|
||||
\* --- threads ---------------------------------------------------------
|
||||
rpc, rGen, rRunGen, rEpoch, rNeeds, reads,
|
||||
upc, uNeeds, ops, readerPaused,
|
||||
epc, signals,
|
||||
releaseFailed \* ghost: app's release of a held frame returned GVFG_ESTATE
|
||||
|
||||
chanVars == <<running, readInProgress, frameHeld, heldNeedsBackend, heldEpoch, runGen>>
|
||||
sessVars == <<sRunning, sFrameHeld, recoveryPending, generation, epoch, monitoring>>
|
||||
rVars == <<rpc, rGen, rRunGen, rEpoch, rNeeds, reads>>
|
||||
uVars == <<upc, uNeeds, ops, readerPaused>>
|
||||
eVars == <<epc, signals>>
|
||||
vars == <<chanVars, sessVars, rVars, uVars, eVars, releaseFailed>>
|
||||
|
||||
RStates == {"idle", "begin_lock", "wait_check", "waiting", "capture", "osd", "deliver",
|
||||
"stop_release", "holding", "fail"}
|
||||
UStates == {"idle", "quiesce", "choose", "stop_frames", "stop_backend",
|
||||
"stop_stream", "stop_join", "start_session", "start_channel"}
|
||||
EStates == {"idle", "decide", "wait_hold", "restart", "finish"}
|
||||
|
||||
TypeOK ==
|
||||
/\ running \in BOOLEAN /\ readInProgress \in BOOLEAN /\ frameHeld \in BOOLEAN
|
||||
/\ heldNeedsBackend \in BOOLEAN /\ heldEpoch \in Nat /\ runGen \in Nat
|
||||
/\ sRunning \in BOOLEAN /\ sFrameHeld \in BOOLEAN /\ recoveryPending \in BOOLEAN
|
||||
/\ generation \in Nat /\ epoch \in Nat /\ monitoring \in BOOLEAN
|
||||
/\ rpc \in RStates /\ rGen \in Nat /\ rRunGen \in Nat /\ rEpoch \in Nat
|
||||
/\ rNeeds \in BOOLEAN /\ reads \in Nat
|
||||
/\ upc \in UStates /\ uNeeds \in BOOLEAN /\ ops \in Nat /\ readerPaused \in BOOLEAN
|
||||
/\ epc \in EStates /\ signals \in Nat
|
||||
/\ releaseFailed \in BOOLEAN
|
||||
|
||||
\* Channel open and started once: C start() -> S start_stream() succeeded.
|
||||
Init ==
|
||||
/\ running = TRUE /\ readInProgress = FALSE /\ frameHeld = FALSE
|
||||
/\ heldNeedsBackend = FALSE /\ heldEpoch = 0 /\ runGen = 1
|
||||
/\ sRunning = TRUE /\ sFrameHeld = FALSE /\ recoveryPending = FALSE
|
||||
/\ generation = 0 /\ epoch = 1 /\ monitoring = TRUE
|
||||
/\ rpc = "idle" /\ rGen = 0 /\ rRunGen = 0 /\ rEpoch = 0 /\ rNeeds = FALSE /\ reads = 0
|
||||
/\ upc = "idle" /\ uNeeds = FALSE /\ ops = 0 /\ readerPaused = FALSE
|
||||
/\ epc = "idle" /\ signals = 0 /\ releaseFailed = FALSE
|
||||
|
||||
(***************************************************************************)
|
||||
(* R: gvfg_read_channel_frame / gvfg_release_channel_frame *)
|
||||
(***************************************************************************)
|
||||
|
||||
\* C readFrame: `if (!running)` before taking frameMutex.
|
||||
RBegin ==
|
||||
/\ rpc = "idle" /\ reads < MaxReads
|
||||
/\ ~(AppQuiescesReader /\ readerPaused)
|
||||
/\ running
|
||||
/\ rpc' = "begin_lock" /\ reads' = reads + 1
|
||||
/\ UNCHANGED <<chanVars, sessVars, rGen, rRunGen, rEpoch, rNeeds, uVars, eVars, releaseFailed>>
|
||||
|
||||
\* C readFrame, first frameMutex section: reject if held or another read; record the run.
|
||||
RBeginLock ==
|
||||
/\ rpc = "begin_lock"
|
||||
/\ IF frameHeld \/ readInProgress
|
||||
THEN rpc' = "idle" /\ UNCHANGED <<readInProgress, rRunGen>>
|
||||
ELSE readInProgress' = TRUE /\ rRunGen' = runGen /\ rpc' = "wait_check"
|
||||
/\ UNCHANGED <<running, frameHeld, heldNeedsBackend, heldEpoch, runGen, sessVars,
|
||||
rGen, rEpoch, rNeeds, reads, uVars, eVars, releaseFailed>>
|
||||
|
||||
\* S wait_frame entry: running_ check; state_mutex_: snapshot generation, reject if held.
|
||||
RWaitCheck ==
|
||||
/\ rpc = "wait_check"
|
||||
/\ IF ~sRunning \/ sFrameHeld
|
||||
THEN rpc' = "fail" /\ UNCHANGED rGen
|
||||
ELSE rGen' = generation /\ rpc' = "waiting"
|
||||
/\ UNCHANGED <<chanVars, sessVars, rRunGen, rEpoch, rNeeds, reads, uVars, eVars, releaseFailed>>
|
||||
|
||||
\* S wait_frame: WaitForMultipleObjects(stop, recovery, frame events).
|
||||
\* stop_event set (stop_stream) -> ESTATE; recovery_event -> wait_for_recovery -> non-OK.
|
||||
RWakeFail ==
|
||||
/\ rpc = "waiting" /\ (~sRunning \/ recoveryPending)
|
||||
/\ rpc' = "fail"
|
||||
/\ UNCHANGED <<chanVars, sessVars, rGen, rRunGen, rEpoch, rNeeds, reads, uVars, eVars, releaseFailed>>
|
||||
|
||||
\* A frame event fires while the driver stream runs.
|
||||
RWakeFrame ==
|
||||
/\ rpc = "waiting" /\ sRunning
|
||||
/\ rpc' = "capture"
|
||||
/\ UNCHANGED <<chanVars, sessVars, rGen, rRunGen, rEpoch, rNeeds, reads, uVars, eVars, releaseFailed>>
|
||||
|
||||
\* S wait_frame capture section, one step under capture_mutex_: re-check, get the buffer, frame_held_ = true.
|
||||
RCapture ==
|
||||
/\ rpc = "capture"
|
||||
/\ IF ~sRunning
|
||||
\/ ("CaptureRejectsDuringRecovery" \in Guards /\ (recoveryPending \/ rGen # generation))
|
||||
THEN rpc' = "fail" /\ UNCHANGED <<sFrameHeld, rEpoch>>
|
||||
ELSE sFrameHeld' = TRUE /\ rEpoch' = epoch /\ rpc' = "osd"
|
||||
/\ UNCHANGED <<chanVars, sRunning, recoveryPending, generation, epoch, monitoring,
|
||||
rGen, rRunGen, rNeeds, reads, uVars, eVars, releaseFailed>>
|
||||
|
||||
\* C readFrame frame processor: no OSD, or in-place OSD, keeps the backend hold ...
|
||||
ROsdKeep ==
|
||||
/\ rpc = "osd"
|
||||
/\ rNeeds' = TRUE /\ rpc' = "deliver"
|
||||
/\ UNCHANGED <<chanVars, sessVars, rGen, rRunGen, rEpoch, reads, uVars, eVars, releaseFailed>>
|
||||
|
||||
\* ... OSD into a separate SDK buffer releases the backend frame now (S release_frame).
|
||||
ROsdEarlyRelease ==
|
||||
/\ rpc = "osd"
|
||||
/\ IF sFrameHeld
|
||||
THEN sFrameHeld' = FALSE /\ rNeeds' = FALSE /\ rpc' = "deliver"
|
||||
ELSE rpc' = "fail" /\ UNCHANGED <<sFrameHeld, rNeeds>>
|
||||
/\ UNCHANGED <<chanVars, sRunning, recoveryPending, generation, epoch, monitoring,
|
||||
rGen, rRunGen, rEpoch, reads, uVars, eVars, releaseFailed>>
|
||||
|
||||
\* C readFrame delivery, frameMutex: deliver unless capture stopped, or stopped and
|
||||
\* restarted, since the read began.
|
||||
Stale ==
|
||||
\/ ("DeliverRechecksRunning" \in Guards /\ ~running)
|
||||
\/ ("DeliverChecksRunGeneration" \in Guards /\ rRunGen # runGen)
|
||||
|
||||
RDeliver ==
|
||||
/\ rpc = "deliver"
|
||||
/\ IF Stale
|
||||
THEN /\ readInProgress' = FALSE
|
||||
/\ rpc' = IF rNeeds THEN "stop_release" ELSE "idle"
|
||||
/\ UNCHANGED <<frameHeld, heldNeedsBackend, heldEpoch>>
|
||||
ELSE /\ frameHeld' = TRUE /\ heldNeedsBackend' = rNeeds /\ heldEpoch' = rEpoch
|
||||
/\ readInProgress' = FALSE /\ rpc' = "holding"
|
||||
/\ UNCHANGED <<running, runGen, sessVars, rGen, rRunGen, rEpoch, rNeeds, reads,
|
||||
uVars, eVars, releaseFailed>>
|
||||
|
||||
\* C readFrame stoppedWhileWaiting: session->release_frame() (clears the hold if still held).
|
||||
RStopRelease ==
|
||||
/\ rpc = "stop_release"
|
||||
/\ sFrameHeld' = FALSE /\ rpc' = "idle"
|
||||
/\ UNCHANGED <<chanVars, sRunning, recoveryPending, generation, epoch, monitoring,
|
||||
rGen, rRunGen, rEpoch, rNeeds, reads, uVars, eVars, releaseFailed>>
|
||||
|
||||
\* C releaseFrame, one step under frameMutex (calls S release_frame inside).
|
||||
RRelease ==
|
||||
/\ rpc = "holding"
|
||||
/\ rpc' = "idle"
|
||||
/\ CASE ~frameHeld -> \* invalidated by stop: ESTATE, documented
|
||||
UNCHANGED <<frameHeld, heldNeedsBackend, sFrameHeld, releaseFailed>>
|
||||
[] frameHeld /\ heldNeedsBackend /\ ~sFrameHeld -> \* S rejects; C returns before clearing
|
||||
/\ releaseFailed' = TRUE
|
||||
/\ UNCHANGED <<frameHeld, heldNeedsBackend, sFrameHeld>>
|
||||
[] OTHER ->
|
||||
/\ frameHeld' = FALSE /\ heldNeedsBackend' = FALSE
|
||||
/\ sFrameHeld' = IF heldNeedsBackend THEN FALSE ELSE sFrameHeld
|
||||
/\ UNCHANGED releaseFailed
|
||||
/\ UNCHANGED <<running, readInProgress, heldEpoch, runGen, sRunning, recoveryPending,
|
||||
generation, epoch, monitoring, rGen, rRunGen, rEpoch, rNeeds, reads,
|
||||
uVars, eVars>>
|
||||
|
||||
RFail ==
|
||||
/\ rpc = "fail"
|
||||
/\ readInProgress' = FALSE /\ rpc' = "idle"
|
||||
/\ UNCHANGED <<running, frameHeld, heldNeedsBackend, heldEpoch, runGen, sessVars,
|
||||
rGen, rRunGen, rEpoch, rNeeds, reads, uVars, eVars, releaseFailed>>
|
||||
|
||||
(***************************************************************************)
|
||||
(* U: gvfg_stop_channel / gvfg_start_channel, serialized by the app *)
|
||||
(***************************************************************************)
|
||||
|
||||
UBegin ==
|
||||
/\ upc = "idle" /\ ops < MaxLifecycleOps
|
||||
/\ IF AppQuiescesReader
|
||||
THEN readerPaused' = TRUE /\ upc' = "quiesce"
|
||||
ELSE upc' = "choose" /\ UNCHANGED readerPaused
|
||||
/\ UNCHANGED <<chanVars, sessVars, rVars, uNeeds, ops, eVars, releaseFailed>>
|
||||
|
||||
\* App protocol (docs/GVFG_FRAME_FLOW_AND_STATE.md section 5): reader released its frame and is joined.
|
||||
UQuiesced ==
|
||||
/\ upc = "quiesce" /\ rpc = "idle"
|
||||
/\ upc' = "choose"
|
||||
/\ UNCHANGED <<chanVars, sessVars, rVars, uNeeds, ops, readerPaused, eVars, releaseFailed>>
|
||||
|
||||
\* C stop: running = false.
|
||||
UStop ==
|
||||
/\ upc = "choose" /\ running
|
||||
/\ running' = FALSE /\ ops' = ops + 1 /\ upc' = "stop_frames"
|
||||
/\ UNCHANGED <<readInProgress, frameHeld, heldNeedsBackend, heldEpoch, runGen,
|
||||
sessVars, rVars, uNeeds, readerPaused, eVars, releaseFailed>>
|
||||
|
||||
\* C releaseHeldFrameForStop, frameMutex: invalidate the app's frame.
|
||||
UStopFrames ==
|
||||
/\ upc = "stop_frames"
|
||||
/\ uNeeds' = (frameHeld /\ heldNeedsBackend)
|
||||
/\ frameHeld' = FALSE /\ heldNeedsBackend' = FALSE
|
||||
/\ upc' = "stop_backend"
|
||||
/\ UNCHANGED <<running, readInProgress, heldEpoch, runGen, sessVars, rVars, ops,
|
||||
readerPaused, eVars, releaseFailed>>
|
||||
|
||||
\* C releaseHeldFrameForStop: session->release_frame().
|
||||
UStopBackend ==
|
||||
/\ upc = "stop_backend"
|
||||
/\ sFrameHeld' = IF uNeeds THEN FALSE ELSE sFrameHeld
|
||||
/\ upc' = "stop_stream"
|
||||
/\ UNCHANGED <<chanVars, sRunning, recoveryPending, generation, epoch, monitoring,
|
||||
rVars, uNeeds, ops, readerPaused, eVars, releaseFailed>>
|
||||
|
||||
\* S stop_stream: running_ = false, events set, frame_held_ = false.
|
||||
UStopStream ==
|
||||
/\ upc = "stop_stream"
|
||||
/\ sRunning' = FALSE /\ recoveryPending' = FALSE /\ sFrameHeld' = FALSE
|
||||
/\ monitoring' = FALSE /\ upc' = "stop_join"
|
||||
/\ UNCHANGED <<chanVars, generation, epoch, rVars, uNeeds, ops, readerPaused,
|
||||
eVars, releaseFailed>>
|
||||
|
||||
\* S stop_stream: join the event thread, GvfgStopCapture.
|
||||
UStopJoin ==
|
||||
/\ upc = "stop_join" /\ epc = "idle"
|
||||
/\ upc' = "idle" /\ readerPaused' = FALSE
|
||||
/\ UNCHANGED <<chanVars, sessVars, rVars, uNeeds, ops, eVars, releaseFailed>>
|
||||
|
||||
\* C start: no-op while running. S start_stream: GvfgStartCapture,
|
||||
\* frame_held_ = false, running_ = true, event thread started.
|
||||
UStartSession ==
|
||||
/\ upc = "choose" /\ ~running
|
||||
/\ ops' = ops + 1
|
||||
/\ IF sRunning
|
||||
THEN UNCHANGED <<sRunning, sFrameHeld, recoveryPending, epoch, monitoring>>
|
||||
ELSE /\ sRunning' = TRUE /\ sFrameHeld' = FALSE /\ recoveryPending' = FALSE
|
||||
/\ epoch' = epoch + 1 /\ monitoring' = TRUE
|
||||
/\ upc' = "start_channel"
|
||||
/\ UNCHANGED <<chanVars, generation, rVars, uNeeds, readerPaused, eVars, releaseFailed>>
|
||||
|
||||
\* C start, frameMutex: ++runGeneration; running = true.
|
||||
UStartChannel ==
|
||||
/\ upc = "start_channel"
|
||||
/\ runGen' = runGen + 1 /\ running' = TRUE
|
||||
/\ upc' = "idle" /\ readerPaused' = FALSE
|
||||
/\ UNCHANGED <<readInProgress, frameHeld, heldNeedsBackend, heldEpoch, sessVars,
|
||||
rVars, uNeeds, ops, eVars, releaseFailed>>
|
||||
|
||||
(***************************************************************************)
|
||||
(* E: S event_thread_proc -> handle_signal_event (format change / plug-in) *)
|
||||
(***************************************************************************)
|
||||
|
||||
\* S handle_signal_event first block, under capture_mutex_ + state_mutex_.
|
||||
ESignal ==
|
||||
/\ epc = "idle" /\ monitoring /\ sRunning /\ signals < MaxSignalEvents
|
||||
/\ generation' = generation + 1 /\ recoveryPending' = TRUE
|
||||
/\ signals' = signals + 1 /\ epc' = "decide"
|
||||
/\ UNCHANGED <<chanVars, sRunning, sFrameHeld, epoch, monitoring, rVars, uVars, releaseFailed>>
|
||||
|
||||
\* S handle_signal_event: restart only if the input format really changed.
|
||||
EDecide ==
|
||||
/\ epc = "decide"
|
||||
/\ epc' \in {"wait_hold", "finish"}
|
||||
/\ UNCHANGED <<chanVars, sessVars, rVars, uVars, signals, releaseFailed>>
|
||||
|
||||
\* S restart_stream_after_signal_change: wait for !frame_held_ || !running_.
|
||||
EWaitHold ==
|
||||
/\ epc = "wait_hold"
|
||||
/\ ("RestartWaitsForRelease" \notin Guards \/ ~sFrameHeld \/ ~sRunning)
|
||||
/\ epc' = "restart"
|
||||
/\ UNCHANGED <<chanVars, sessVars, rVars, uVars, signals, releaseFailed>>
|
||||
|
||||
\* S restart_stream_after_signal_change under capture_mutex_: GvfgStopCapture + GvfgStartCapture.
|
||||
ERestart ==
|
||||
/\ epc = "restart"
|
||||
/\ epoch' = IF sRunning THEN epoch + 1 ELSE epoch
|
||||
/\ epc' = "finish"
|
||||
/\ UNCHANGED <<chanVars, sRunning, sFrameHeld, recoveryPending, generation, monitoring,
|
||||
rVars, uVars, signals, releaseFailed>>
|
||||
|
||||
\* S handle_signal_event end: recovery done.
|
||||
EFinish ==
|
||||
/\ epc = "finish"
|
||||
/\ recoveryPending' = FALSE /\ epc' = "idle"
|
||||
/\ UNCHANGED <<chanVars, sRunning, sFrameHeld, generation, epoch, monitoring,
|
||||
rVars, uVars, signals, releaseFailed>>
|
||||
|
||||
(***************************************************************************)
|
||||
|
||||
Terminated ==
|
||||
/\ rpc = "idle" /\ epc = "idle" /\ upc = "idle" /\ ops = MaxLifecycleOps
|
||||
|
||||
Next ==
|
||||
\/ RBegin \/ RBeginLock \/ RWaitCheck \/ RWakeFail \/ RWakeFrame \/ RCapture
|
||||
\/ ROsdKeep \/ ROsdEarlyRelease \/ RDeliver \/ RStopRelease \/ RRelease \/ RFail
|
||||
\/ UBegin \/ UQuiesced \/ UStop \/ UStopFrames \/ UStopBackend \/ UStopStream
|
||||
\/ UStopJoin \/ UStartSession \/ UStartChannel
|
||||
\/ ESignal \/ EDecide \/ EWaitHold \/ ERestart \/ EFinish
|
||||
\/ (Terminated /\ UNCHANGED vars)
|
||||
|
||||
Spec == Init /\ [][Next]_vars
|
||||
|
||||
(***************************************************************************)
|
||||
(* Properties *)
|
||||
(***************************************************************************)
|
||||
|
||||
\* (1) The buffer the app holds belongs to the driver stream that is running now.
|
||||
HeldFrameIsCurrent == (frameHeld /\ heldNeedsBackend) => heldEpoch = epoch
|
||||
|
||||
\* (2) The app's single release of that frame will succeed (S still records the hold).
|
||||
ReleaseWillSucceed == (frameHeld /\ heldNeedsBackend) => sFrameHeld
|
||||
|
||||
\* (2') Consequence observed by the app.
|
||||
NoFailedRelease == ~releaseFailed
|
||||
=============================================================================
|
||||
@@ -0,0 +1,13 @@
|
||||
\* See the verify-gvfg-frame-hold skill for what each config proves.
|
||||
SPECIFICATION Spec
|
||||
CONSTANTS
|
||||
AppQuiescesReader = FALSE
|
||||
Guards = {"RestartWaitsForRelease", "CaptureRejectsDuringRecovery", "DeliverRechecksRunning", "DeliverChecksRunGeneration"}
|
||||
MaxLifecycleOps = 4
|
||||
MaxSignalEvents = 2
|
||||
MaxReads = 4
|
||||
INVARIANTS
|
||||
TypeOK
|
||||
HeldFrameIsCurrent
|
||||
ReleaseWillSucceed
|
||||
NoFailedRelease
|
||||
@@ -0,0 +1,13 @@
|
||||
\* See the verify-gvfg-frame-hold skill for what each config proves.
|
||||
SPECIFICATION Spec
|
||||
CONSTANTS
|
||||
AppQuiescesReader = TRUE
|
||||
Guards = {"RestartWaitsForRelease", "CaptureRejectsDuringRecovery", "DeliverRechecksRunning", "DeliverChecksRunGeneration"}
|
||||
MaxLifecycleOps = 4
|
||||
MaxSignalEvents = 2
|
||||
MaxReads = 4
|
||||
INVARIANTS
|
||||
TypeOK
|
||||
HeldFrameIsCurrent
|
||||
ReleaseWillSucceed
|
||||
NoFailedRelease
|
||||
@@ -0,0 +1,13 @@
|
||||
\* See the verify-gvfg-frame-hold skill for what each config proves.
|
||||
SPECIFICATION Spec
|
||||
CONSTANTS
|
||||
AppQuiescesReader = TRUE
|
||||
Guards = {"RestartWaitsForRelease", "DeliverRechecksRunning", "DeliverChecksRunGeneration"}
|
||||
MaxLifecycleOps = 4
|
||||
MaxSignalEvents = 2
|
||||
MaxReads = 4
|
||||
INVARIANTS
|
||||
TypeOK
|
||||
HeldFrameIsCurrent
|
||||
ReleaseWillSucceed
|
||||
NoFailedRelease
|
||||
@@ -0,0 +1,13 @@
|
||||
\* See the verify-gvfg-frame-hold skill for what each config proves.
|
||||
SPECIFICATION Spec
|
||||
CONSTANTS
|
||||
AppQuiescesReader = TRUE
|
||||
Guards = {"CaptureRejectsDuringRecovery", "DeliverRechecksRunning", "DeliverChecksRunGeneration"}
|
||||
MaxLifecycleOps = 4
|
||||
MaxSignalEvents = 2
|
||||
MaxReads = 4
|
||||
INVARIANTS
|
||||
TypeOK
|
||||
HeldFrameIsCurrent
|
||||
ReleaseWillSucceed
|
||||
NoFailedRelease
|
||||
@@ -0,0 +1,13 @@
|
||||
\* See the verify-gvfg-frame-hold skill for what each config proves.
|
||||
SPECIFICATION Spec
|
||||
CONSTANTS
|
||||
AppQuiescesReader = FALSE
|
||||
Guards = {"RestartWaitsForRelease", "CaptureRejectsDuringRecovery", "DeliverRechecksRunning"}
|
||||
MaxLifecycleOps = 4
|
||||
MaxSignalEvents = 2
|
||||
MaxReads = 4
|
||||
INVARIANTS
|
||||
TypeOK
|
||||
HeldFrameIsCurrent
|
||||
ReleaseWillSucceed
|
||||
NoFailedRelease
|
||||
@@ -0,0 +1,13 @@
|
||||
\* See the verify-gvfg-frame-hold skill for what each config proves.
|
||||
SPECIFICATION Spec
|
||||
CONSTANTS
|
||||
AppQuiescesReader = FALSE
|
||||
Guards = {"RestartWaitsForRelease", "CaptureRejectsDuringRecovery", "DeliverChecksRunGeneration"}
|
||||
MaxLifecycleOps = 4
|
||||
MaxSignalEvents = 2
|
||||
MaxReads = 4
|
||||
INVARIANTS
|
||||
TypeOK
|
||||
HeldFrameIsCurrent
|
||||
ReleaseWillSucceed
|
||||
NoFailedRelease
|
||||
@@ -1,6 +1,7 @@
|
||||
LIBRARY gvfg
|
||||
|
||||
EXPORTS
|
||||
gvfg_control_frame_processor
|
||||
gvfg_enumerate_devices
|
||||
gvfg_create
|
||||
gvfg_destroy
|
||||
@@ -8,11 +9,6 @@ EXPORTS
|
||||
gvfg_set_channel_zero_copy_enabled
|
||||
gvfg_get_channel_zero_copy_enabled
|
||||
gvfg_set_channel_video_format
|
||||
gvfg_get_osd_fonts
|
||||
gvfg_set_channel_osd_visible
|
||||
gvfg_measure_osd_text
|
||||
gvfg_set_channel_osd
|
||||
gvfg_clear_channel_osd
|
||||
gvfg_set_channel_audio_enabled
|
||||
gvfg_get_channel_audio_format
|
||||
gvfg_start_channel
|
||||
@@ -29,6 +25,9 @@ EXPORTS
|
||||
gvfg_stop_channel
|
||||
gvfg_get_channel_signal_status
|
||||
gvfg_get_channel_sdi_info
|
||||
gvfg_get_channel_hdmi_audio_info
|
||||
gvfg_get_channel_hdmi_info
|
||||
gvfg_get_chip_info
|
||||
gvfg_get_channel_runtime_info
|
||||
gvfg_get_version
|
||||
gvfg_get_gigabyte_lib_version
|
||||
@@ -38,8 +37,7 @@ EXPORTS
|
||||
gvfg_debug_get_channel_backend_stats
|
||||
gvfg_debug_read_channel_frame_timed
|
||||
gvfg_debug_read_channel_frame_profiled
|
||||
gvfg_debug_get_channel_osd_experiment_flags
|
||||
gvfg_debug_get_channel_osd_page_check
|
||||
gvfg_debug_get_device_capabilities
|
||||
gvfg_debug_set_user_led
|
||||
gvfg_debug_read_register
|
||||
gvfg_debug_write_register
|
||||
|
||||
@@ -177,6 +177,37 @@ extern "C"
|
||||
char st352_bit_depth_name[24]; /* Null-terminated ST 352 bit-depth description. */
|
||||
} gvfg_sdi_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int connected;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t fps; /* HDMI input frames per second reported by GigabyteLib. */
|
||||
uint32_t color_format; /* HDMI color format code. */
|
||||
uint32_t color_space; /* HDMI color space and range code. */
|
||||
uint32_t bit_depth; /* HDMI input bit depth. */
|
||||
char fps_name[24]; /* Decimal text for fps, without a unit suffix. */
|
||||
char color_format_name[24];
|
||||
char color_space_name[32];
|
||||
} gvfg_hdmi_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int connected; /* HDMI audio signal lock. */
|
||||
uint32_t sample_frequency; /* HDMI audio sample-frequency code. */
|
||||
uint32_t bits_per_sample;
|
||||
uint32_t channels;
|
||||
uint32_t format; /* HDMI audio format code. */
|
||||
char sample_frequency_name[24];
|
||||
char format_name[24];
|
||||
} gvfg_hdmi_audio_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t version_date; /* Chip version date, interpreted in hexadecimal. */
|
||||
uint32_t version_time; /* Chip version time, interpreted in hexadecimal. */
|
||||
} gvfg_chip_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int connected; /* Non-zero while this channel has a valid input signal. */
|
||||
@@ -207,26 +238,6 @@ extern "C"
|
||||
uint64_t timestamp_ns; /* Monotonic SDK delivery time; same clock domain as audio. */
|
||||
} gvfg_frame_t;
|
||||
|
||||
/* Strings are copied synchronously by gvfg_set_channel_osd(). */
|
||||
typedef struct gvfg_channel_osd_config_t
|
||||
{
|
||||
const char *text; /* NUL-terminated printable ASCII, 1..32 characters. */
|
||||
const char *font_family; /* NUL-terminated UTF-8 installed font family name. */
|
||||
uint32_t font_size_px; /* Non-zero em size; 96-DPI rendering, not ink height. */
|
||||
uint32_t color_rgb; /* 0x00RRGGBB. */
|
||||
int32_t x; /* Text-box left in frame pixels; clamped to fit. */
|
||||
int32_t y; /* Text-box top in frame pixels; clamped to fit. */
|
||||
} gvfg_channel_osd_config_t;
|
||||
|
||||
typedef struct gvfg_osd_font_list_t
|
||||
{
|
||||
uint32_t count;
|
||||
const char *const *names; /* SDK-owned UTF-8 family names; do not modify/free. */
|
||||
} gvfg_osd_font_list_t;
|
||||
|
||||
#define GVFG_OSD_SLOT_COUNT 2u
|
||||
#define GVFG_OSD_MAX_TEXT_CHARACTERS 32u
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const void *data; /* PCM data. Valid until gvfg_release_channel_audio_frame(). */
|
||||
@@ -365,56 +376,15 @@ extern "C"
|
||||
* Select the capture output format before capture starts. Only one channel
|
||||
* on a handle may select Y210 at a time; a conflicting request returns
|
||||
* GVFG_EBUSY. Applications may request either channel first.
|
||||
* With a locked input, success means the hardware reports the selected
|
||||
* format. Without a locked input, success means the request was accepted
|
||||
* and its format will be verified when capture starts.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_channel_video_format(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_IN gvfg_pixel_format_t format);
|
||||
|
||||
/* Refresh installed fonts and return an SDK-owned snapshot. No device needed.
|
||||
* Pointers expire at the next call (including a failed call), or DLL unload.
|
||||
* Copy names before then. Serialize calls and use of this borrowed list.
|
||||
* Returns an empty list on failure; no callback or caller-side free is needed.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_osd_fonts(
|
||||
GVFG_PARAM_OUT gvfg_osd_font_list_t *out_list);
|
||||
|
||||
/* Measure the same conservative text box used for rendering, including
|
||||
* overhang and a one-pixel guard per edge. Ignores x/y/color; no device needed.
|
||||
* Outputs are zeroed on failure. Missing font/invalid input: GVFG_EINVAL.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_measure_osd_text(
|
||||
GVFG_PARAM_IN const gvfg_channel_osd_config_t *config,
|
||||
GVFG_PARAM_OUT uint32_t *out_width,
|
||||
GVFG_PARAM_OUT uint32_t *out_height);
|
||||
|
||||
/* Set and show slot 0 or 1 on an opened channel. Strings are copied before
|
||||
* return; slot 1 is blended over slot 0. Applies to subsequent YUY2/Y210
|
||||
* frames using BT.709 limited range. X/Y are clamped to fit the text box.
|
||||
* An oversized slot is skipped until settings/frame size allow it to fit;
|
||||
* capture and the other slot continue. No wrapping/shrinking/truncation.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_channel_osd(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_IN uint32_t osd_index,
|
||||
GVFG_PARAM_IN const gvfg_channel_osd_config_t *config);
|
||||
|
||||
/* visible must be 0 or 1. Retains settings and cached glyph surfaces.
|
||||
* Showing an unconfigured/cleared slot returns GVFG_ESTATE.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_channel_osd_visible(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_IN uint32_t osd_index,
|
||||
GVFG_PARAM_IN int visible);
|
||||
|
||||
/* Disable one slot and discard its settings and cached glyph surfaces. */
|
||||
GVFG_API gvfg_status_t gvfg_clear_channel_osd(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_IN uint32_t osd_index);
|
||||
|
||||
/*
|
||||
* Enable or disable audio for the next channel start. Video remains
|
||||
* enabled; applications do not need to construct stream flag masks.
|
||||
@@ -439,7 +409,8 @@ extern "C"
|
||||
* - GVFG_OK on success, including when capture is already running.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
* - GVFG_ESTATE if no device is open.
|
||||
* - GVFG_ETIMEOUT if a fresh signal query reports no connected input.
|
||||
* - GVFG_ETIMEOUT if a fresh signal query reports no connected input or
|
||||
* the hardware output format differs from the explicitly selected format.
|
||||
* - GVFG_EIO or another status code if stream configuration/start fails.
|
||||
*
|
||||
* After success, call gvfg_read_channel_frame() to receive frames and
|
||||
@@ -623,7 +594,9 @@ extern "C"
|
||||
* out_status->connected set to 0. Before capture starts, this function
|
||||
* refreshes the status from the capture backend. While capture is running, it returns
|
||||
* the SDK cache; format-change, input-plug and input-unplug processing updates
|
||||
* that cache before the corresponding public event is queued.
|
||||
* that cache before the corresponding public event is queued. If the
|
||||
* current state cannot be confirmed after a change, returns an error
|
||||
* until the cache is valid again.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_channel_signal_status(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
@@ -635,6 +608,20 @@ extern "C"
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_OUT gvfg_sdi_info_t *out_info);
|
||||
|
||||
GVFG_API gvfg_status_t gvfg_get_channel_hdmi_info(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_OUT gvfg_hdmi_info_t *out_info);
|
||||
|
||||
GVFG_API gvfg_status_t gvfg_get_channel_hdmi_audio_info(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_OUT gvfg_hdmi_audio_info_t *out_info);
|
||||
|
||||
GVFG_API gvfg_status_t gvfg_get_chip_info(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_OUT gvfg_chip_info_t *out_info);
|
||||
|
||||
/*
|
||||
* Query runtime frame-delivery diagnostics.
|
||||
*
|
||||
|
||||
@@ -103,55 +103,6 @@ typedef struct
|
||||
uint64_t acquisition_begin_ns;
|
||||
} gvfg_debug_frame_read_timing_t;
|
||||
|
||||
enum
|
||||
{
|
||||
GVFG_DEBUG_OSD_EXPERIMENT_ENABLED = 1u,
|
||||
GVFG_DEBUG_OSD_EXPERIMENT_USED = 2u,
|
||||
GVFG_DEBUG_OSD_EXPERIMENT_REJECTED = 4u
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_DEBUG_OSD_PAGE_OK = 0,
|
||||
GVFG_DEBUG_OSD_PAGE_NO_POINTER,
|
||||
GVFG_DEBUG_OSD_PAGE_INVALID_RANGE,
|
||||
GVFG_DEBUG_OSD_PAGE_QUERY_FAILED,
|
||||
GVFG_DEBUG_OSD_PAGE_NOT_COMMITTED,
|
||||
GVFG_DEBUG_OSD_PAGE_GUARD_OR_NOACCESS,
|
||||
GVFG_DEBUG_OSD_PAGE_NOT_READWRITE,
|
||||
GVFG_DEBUG_OSD_PAGE_INVALID_REGION
|
||||
} gvfg_debug_osd_page_reason_t;
|
||||
|
||||
/* Separate diagnostic type: existing timing/flags ABI remains unchanged.
|
||||
* Native Windows values; win32_error is meaningful only for QUERY_FAILED.
|
||||
* Does not expose addresses or imply DMA safety. */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t reason;
|
||||
uint32_t protect;
|
||||
uint32_t state;
|
||||
uint32_t type;
|
||||
uint32_t win32_error;
|
||||
uint32_t query_bytes;
|
||||
} gvfg_debug_osd_page_check_t;
|
||||
|
||||
/* Query before releasing the matching successfully delivered frame. */
|
||||
GVFG_DEBUG_API gvfg_status_t gvfg_debug_get_channel_osd_page_check(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_IN uint64_t frame_id,
|
||||
GVFG_PARAM_OUT gvfg_debug_osd_page_check_t *out_check);
|
||||
|
||||
/* frame_id=0 queries build configuration only. Otherwise the frame must still
|
||||
* be held and its ID must match. Never implies a DMA ownership guarantee.
|
||||
* Separate query preserves all existing timing struct layouts/read ABIs.
|
||||
*/
|
||||
GVFG_DEBUG_API gvfg_status_t gvfg_debug_get_channel_osd_experiment_flags(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_IN uint64_t frame_id,
|
||||
GVFG_PARAM_OUT uint32_t *out_flags);
|
||||
|
||||
GVFG_DEBUG_API gvfg_status_t gvfg_debug_read_channel_frame_profiled(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
@@ -170,6 +121,9 @@ GVFG_DEBUG_API gvfg_status_t gvfg_debug_get_channel_backend_stats(
|
||||
GVFG_PARAM_IN int channel_index,
|
||||
GVFG_PARAM_OUT gvfg_debug_backend_stats_t *out_stats);
|
||||
|
||||
/* Set the board's user LED. At least one channel must be open. */
|
||||
GVFG_DEBUG_API gvfg_status_t gvfg_debug_set_user_led(gvfg_handle handle, int on);
|
||||
|
||||
/* Query device capabilities for internal diagnostics. At least one channel
|
||||
* must already be open on handle. */
|
||||
GVFG_DEBUG_API gvfg_status_t gvfg_debug_get_device_capabilities(
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -10,10 +12,50 @@ namespace
|
||||
constexpr uint32_t kFourccYuyv = GVFG_MAKEFOURCC('Y', 'U', 'Y', 'V');
|
||||
constexpr uint32_t kFourccUyvy = GVFG_MAKEFOURCC('U', 'Y', 'V', 'Y');
|
||||
constexpr uint32_t kFourccY210 = GVFG_MAKEFOURCC('Y', '2', '1', '0');
|
||||
constexpr DWORD kVideoFormatChangeTimeoutMs = 100;
|
||||
// Temporary bring-up workaround: HDMI VideoSignalLock is not implemented
|
||||
// by the current driver/FPGA. Set false once HDMI lock reporting is ready.
|
||||
constexpr bool kBypassHdmiSignalLock = true;
|
||||
constexpr DWORD kVideoFormatChangeTimeoutMs = 1000;
|
||||
constexpr DWORD kVideoFormatSettleMs = 500;
|
||||
|
||||
const char *hdmi_color_format_name(uint32_t code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case GVFG_HDMI_CF_RGB: return "RGB";
|
||||
case GVFG_HDMI_CF_YUV_422: return "YUV 4:2:2";
|
||||
case GVFG_HDMI_CF_YUV_444: return "YUV 4:4:4";
|
||||
case GVFG_HDMI_CF_YUV_420: return "YUV 4:2:0";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char *hdmi_color_space_name(uint32_t code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case GVFG_HDMI_CS_DEFAULT_RGB: return "Default RGB";
|
||||
case GVFG_HDMI_CS_RGB: return "RGB";
|
||||
case GVFG_HDMI_CS_YUV_601: return "YUV 601";
|
||||
case GVFG_HDMI_CS_YUV_709: return "YUV 709";
|
||||
case GVFG_HDMI_CS_YCC_601: return "YCC 601";
|
||||
case GVFG_HDMI_CS_YCC_709: return "YCC 709";
|
||||
case GVFG_HDMI_CS_SYCC_601: return "sYCC 601";
|
||||
case GVFG_HDMI_CS_ADOBE_YCC_601: return "Adobe YCC 601";
|
||||
case GVFG_HDMI_CS_ADOBE_RGB: return "Adobe RGB";
|
||||
case GVFG_HDMI_CS_BT2020_YCC: return "BT.2020 YCC";
|
||||
case GVFG_HDMI_CS_BT2020_RGB: return "BT.2020 RGB";
|
||||
case GVFG_HDMI_CS_AUTO: return "Auto";
|
||||
case GVFG_HDMI_CS_LIM_RGB: return "RGB (Limited)";
|
||||
case GVFG_HDMI_CS_LIM_YUV_601: return "YUV 601 (Limited)";
|
||||
case GVFG_HDMI_CS_LIM_YUV_709: return "YUV 709 (Limited)";
|
||||
case GVFG_HDMI_CS_LIM_YCC_601: return "YCC 601 (Limited)";
|
||||
case GVFG_HDMI_CS_LIM_YCC_709: return "YCC 709 (Limited)";
|
||||
case GVFG_HDMI_CS_LIM_SYCC_601: return "sYCC 601 (Limited)";
|
||||
case GVFG_HDMI_CS_LIM_ADOBE_YCC_601: return "Adobe YCC 601 (Limited)";
|
||||
case GVFG_HDMI_CS_LIM_ADOBE_RGB: return "Adobe RGB (Limited)";
|
||||
case GVFG_HDMI_CS_LIM_BT2020_YCC: return "BT.2020 YCC (Limited)";
|
||||
case GVFG_HDMI_CS_LIM_BT2020_RGB: return "BT.2020 RGB (Limited)";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t monotonic_ns()
|
||||
{
|
||||
@@ -141,6 +183,7 @@ namespace gvfg::internal
|
||||
if (channel_open_ && context_)
|
||||
GvfgCloseVideoChn(context_, channel_);
|
||||
channel_open_ = false;
|
||||
driver_stream_running_ = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
video_info_valid_ = false;
|
||||
@@ -221,15 +264,24 @@ namespace gvfg::internal
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
|
||||
gvfg_pixel_format_t requestedFormat = GVFG_PIXFMT_UNKNOWN;
|
||||
const gvfg_status_t readStatus = refresh_video_info();
|
||||
if (readStatus != GVFG_OK)
|
||||
return readStatus;
|
||||
|
||||
gvfg_pixel_format_t previousFormat = GVFG_PIXFMT_UNKNOWN;
|
||||
bool signalConnected = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
requestedFormat = requested_video_format_;
|
||||
previousFormat = requested_video_format_;
|
||||
signalConnected = cached_signal_.connected != 0;
|
||||
if (signalConnected && cached_signal_.pixel_format == format)
|
||||
{
|
||||
requested_video_format_ = format;
|
||||
format_change_pending_ = false;
|
||||
return GVFG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (requestedFormat == format)
|
||||
return GVFG_OK;
|
||||
|
||||
if (!events_.hVideoFormatChangedEvent)
|
||||
return reject(GVFG_EIO, "Capture backend did not provide a video-format event");
|
||||
#ifndef NDEBUG
|
||||
@@ -244,14 +296,31 @@ namespace gvfg::internal
|
||||
: GVFG_VIDEO_COLOR_DEPTH_8_BITS;
|
||||
const gvfg_status_t status = from_vendor(
|
||||
GvfgSetVideoColorDepth(context_, channel_, colorDepth), "GvfgSetVideoColorDepth");
|
||||
if (status == GVFG_OK)
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
requested_video_format_ = format;
|
||||
format_change_pending_ = true;
|
||||
video_info_valid_ = false;
|
||||
}
|
||||
return status;
|
||||
// Without a locked input, verify the accepted request at start.
|
||||
if (!signalConnected)
|
||||
return GVFG_OK;
|
||||
|
||||
gvfg_signal_status_t signal{};
|
||||
const gvfg_status_t verifyStatus = get_signal_status(signal, true);
|
||||
if (verifyStatus == GVFG_OK && signal.connected)
|
||||
return GVFG_OK;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
requested_video_format_ = previousFormat;
|
||||
format_change_pending_ = false;
|
||||
}
|
||||
if (verifyStatus != GVFG_OK)
|
||||
return verifyStatus;
|
||||
return reject(GVFG_ETIMEOUT, "Input signal lost while verifying capture video format");
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::refresh_video_info()
|
||||
@@ -267,12 +336,7 @@ namespace gvfg::internal
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
gvfg_signal_status_t signal{};
|
||||
// Apply the HDMI workaround here so Start, frame reads and SDK clients
|
||||
// use the same effective signal state. SDI still uses the reported lock.
|
||||
// With bypass enabled, HDMI connected does not prove physical signal lock.
|
||||
const bool bypassLock = kBypassHdmiSignalLock &&
|
||||
info.VideoInterface == GVFG_VIDEO_INTERFACE_HDMI;
|
||||
signal.connected = (bypassLock || info.VideoSignalLock != 0) ? 1 : 0;
|
||||
signal.connected = info.VideoSignalLock != 0 ? 1 : 0;
|
||||
signal.channel = channel_;
|
||||
signal.width = info.Width;
|
||||
signal.height = info.Height;
|
||||
@@ -288,7 +352,8 @@ namespace gvfg::internal
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::get_signal_status(gvfg_signal_status_t &out)
|
||||
gvfg_status_t GigabyteCaptureSession::get_signal_status(gvfg_signal_status_t &out,
|
||||
bool verifyRequestedFormat)
|
||||
{
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
@@ -313,33 +378,32 @@ namespace gvfg::internal
|
||||
#endif
|
||||
if (wait != WAIT_OBJECT_0 && wait != WAIT_TIMEOUT)
|
||||
return reject(GVFG_EIO, "Capture video-format event wait failed");
|
||||
|
||||
// Setting the already-active color depth does not necessarily emit a
|
||||
// format-change event. Query once after the wait and accept the
|
||||
// request when the hardware is already reporting the requested format.
|
||||
const gvfg_status_t status = refresh_video_info();
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
|
||||
bool formatMatches = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
format_change_pending_ = false;
|
||||
formatMatches = cached_signal_.pixel_format == requestedFormat;
|
||||
out = cached_signal_;
|
||||
}
|
||||
if (!formatMatches)
|
||||
return reject(GVFG_ETIMEOUT,
|
||||
"Capture video format did not match the requested format");
|
||||
return GVFG_OK;
|
||||
if (wait == WAIT_OBJECT_0)
|
||||
Sleep(kVideoFormatSettleMs);
|
||||
}
|
||||
|
||||
// The already-active color depth may not emit an event. Read the
|
||||
// hardware status even when the event wait times out.
|
||||
const gvfg_status_t status = refresh_video_info();
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
out = cached_signal_;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
if (formatChangePending && requested_video_format_ == requestedFormat)
|
||||
format_change_pending_ = false;
|
||||
out = cached_signal_;
|
||||
}
|
||||
if ((formatChangePending || verifyRequestedFormat) && out.connected &&
|
||||
requestedFormat != GVFG_PIXFMT_UNKNOWN && out.pixel_format != requestedFormat)
|
||||
{
|
||||
char message[128]{};
|
||||
std::snprintf(message, sizeof(message),
|
||||
"Capture channel %d expected %s, hardware reports %s",
|
||||
static_cast<int>(channel_), gvfg_pixel_format_name(requestedFormat),
|
||||
gvfg_pixel_format_name(static_cast<gvfg_pixel_format_t>(out.pixel_format)));
|
||||
return reject(GVFG_ETIMEOUT, message);
|
||||
}
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
@@ -359,14 +423,122 @@ namespace gvfg::internal
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::get_hdmi_info(gvfg_hdmi_info_t &out)
|
||||
{
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
|
||||
GVFG_HDMI_VIDEO_INPUT_INFO info{};
|
||||
{
|
||||
std::lock_guard<std::mutex> inputInfoLock(input_info_mutex_);
|
||||
const gvfg_status_t status = from_vendor(
|
||||
GvfgGetHdmiVideoInputInfo(context_, channel_, &info), "GvfgGetHdmiVideoInputInfo");
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
}
|
||||
|
||||
out.connected = info.VideoSignalLock != 0;
|
||||
out.width = info.Width;
|
||||
out.height = info.Height;
|
||||
out.fps = info.Fps;
|
||||
out.color_format = info.ColorFormat;
|
||||
out.color_space = info.ColorSpace;
|
||||
out.bit_depth = info.BitsPerPixel;
|
||||
std::snprintf(out.fps_name, sizeof(out.fps_name), "%" PRIu32, out.fps);
|
||||
strncpy_s(out.color_format_name, hdmi_color_format_name(out.color_format), _TRUNCATE);
|
||||
strncpy_s(out.color_space_name, hdmi_color_space_name(out.color_space), _TRUNCATE);
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::get_hdmi_audio_info(gvfg_hdmi_audio_info_t &out)
|
||||
{
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
|
||||
GVFG_HDMI_AUDIO_INPUT_INFO info{};
|
||||
{
|
||||
std::lock_guard<std::mutex> inputInfoLock(input_info_mutex_);
|
||||
const gvfg_status_t status = from_vendor(
|
||||
GvfgGetHdmiAudioInputInfo(context_, channel_, &info), "GvfgGetHdmiAudioInputInfo");
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
}
|
||||
|
||||
out.connected = info.AudioSignalLock != 0;
|
||||
out.sample_frequency = info.SamplesPerSec;
|
||||
out.bits_per_sample = info.BitsPerSample;
|
||||
out.channels = info.Channels;
|
||||
out.format = info.Format;
|
||||
if (!out.connected)
|
||||
return GVFG_OK;
|
||||
|
||||
// Indexed by GVFG_HDMI_AUDIO_SAMPLE_FREQ and GVFG_HDMI_AUDIO_FORMAT.
|
||||
constexpr const char *frequencies[] = {
|
||||
"32 kHz", "44.1 kHz", "48 kHz", "88.2 kHz", "96 kHz", "176.4 kHz",
|
||||
"192 kHz", "HBR", "From stream"
|
||||
};
|
||||
constexpr const char *formats[] = {
|
||||
"Unknown", "Linear PCM", "AC-3", "MPEG-1", "MP3", "MPEG-2", "AAC", "DTS",
|
||||
"ATRAC", "One Bit Audio", "Dolby Digital", "DTS-HD", "MAT", "DST", "WMA Pro"
|
||||
};
|
||||
const char *frequency = out.sample_frequency < sizeof(frequencies) / sizeof(frequencies[0])
|
||||
? frequencies[out.sample_frequency] : "Unknown";
|
||||
const char *format = out.format < sizeof(formats) / sizeof(formats[0])
|
||||
? formats[out.format] : "Unknown";
|
||||
if (out.format == GVFG_HDMI_AUD_FMT_COMPRESSED_AUDIO)
|
||||
format = "Compressed Audio";
|
||||
strncpy_s(out.sample_frequency_name, frequency, _TRUNCATE);
|
||||
strncpy_s(out.format_name, format, _TRUNCATE);
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::get_chip_info(gvfg_chip_info_t &out)
|
||||
{
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
|
||||
GVFG_CHIP_INFO info{};
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
const gvfg_status_t status = from_vendor(GvfgGetChipInfo(context_, &info), "GvfgGetChipInfo");
|
||||
if (status == GVFG_OK)
|
||||
{
|
||||
out.version_date = info.VerDate;
|
||||
out.version_time = info.VerTime;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::set_user_led(bool on)
|
||||
{
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
return from_vendor(GvfgSetLed(context_, on ? 1u : 0u), "GvfgSetLed");
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::get_sdi_info(gvfg_sdi_info_t &out)
|
||||
{
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
std::lock_guard<std::mutex> inputInfoLock(input_info_mutex_);
|
||||
GVFG_SDI_VIDEO_INFO info{};
|
||||
gvfg_status_t status = from_vendor(
|
||||
GvfgGetSdiVideoInputInfo(context_, channel_, &info), "GvfgGetSdiVideoInputInfo");
|
||||
const GVFG_HRESULT result = GvfgGetSdiVideoInputInfo(context_, channel_, &info);
|
||||
char debugMessage[256];
|
||||
std::snprintf(debugMessage, sizeof(debugMessage),
|
||||
"[GVFG] GvfgGetSdiVideoInputInfo CH%" PRIu32
|
||||
" returned 0x%08" PRIX32 " | VideoSignalLock=%" PRIu32
|
||||
" | ErrorCount=%" PRIu32 "\n",
|
||||
static_cast<uint32_t>(channel_), static_cast<uint32_t>(result),
|
||||
static_cast<uint32_t>(info.VideoSignalLock),
|
||||
static_cast<uint32_t>(info.ErrorCount));
|
||||
OutputDebugStringA(debugMessage);
|
||||
|
||||
gvfg_status_t status = from_vendor(result, "GvfgGetSdiVideoInputInfo");
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
GVFG_SDI_VIDEO_INFO_STR text{};
|
||||
@@ -400,12 +572,7 @@ namespace gvfg::internal
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
bool refresh = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
refresh = !audio_info_valid_;
|
||||
}
|
||||
if (refresh)
|
||||
if (!running_)
|
||||
{
|
||||
const gvfg_status_t status = refresh_audio_info();
|
||||
if (status != GVFG_OK)
|
||||
@@ -413,6 +580,10 @@ namespace gvfg::internal
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
out = {};
|
||||
if (recovery_pending_)
|
||||
return GVFG_ETIMEOUT;
|
||||
if (!audio_info_valid_)
|
||||
return audio_info_status_;
|
||||
out.sample_rate = audio_info_.SamplesPerSec;
|
||||
out.channels = audio_info_.Channels;
|
||||
out.bits_per_sample = audio_info_.BitsPerSample;
|
||||
@@ -423,14 +594,19 @@ namespace gvfg::internal
|
||||
gvfg_status_t GigabyteCaptureSession::refresh_audio_info()
|
||||
{
|
||||
GVFG_AUDIO_INFO info{};
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
const gvfg_status_t status = from_vendor(
|
||||
GvfgGetAudioInfo(context_, channel_, &info), "GvfgGetAudioInfo");
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
audio_info_ = info;
|
||||
audio_info_valid_ = true;
|
||||
return GVFG_OK;
|
||||
audio_info_ = {};
|
||||
audio_info_status_ = status;
|
||||
audio_info_valid_ = status == GVFG_OK && info.cbBufSize && info.SamplesPerSec &&
|
||||
info.Channels && info.BitsPerSample;
|
||||
if (audio_info_valid_)
|
||||
audio_info_ = info;
|
||||
else if (status == GVFG_OK)
|
||||
audio_info_status_ = reject(GVFG_ETIMEOUT, "Capture audio format is unavailable");
|
||||
return audio_info_status_;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::set_event_callback(
|
||||
@@ -449,15 +625,20 @@ namespace gvfg::internal
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
#ifndef NDEBUG
|
||||
if (events_.hVideoFormatChangedEvent &&
|
||||
WaitForSingleObject(events_.hVideoFormatChangedEvent, 0) == WAIT_OBJECT_0)
|
||||
OutputDebugStringA("[GVFG] Received VIDEO_FORMAT_CHANGED (before start reset)\n");
|
||||
#endif
|
||||
const gvfg_status_t resetStatus = from_vendor(GvfgResetEvents(&events_), "GvfgResetEvents");
|
||||
if (resetStatus != GVFG_OK)
|
||||
return resetStatus;
|
||||
configured_ = true;
|
||||
const gvfg_status_t status = reset_frame_events();
|
||||
configured_ = status == GVFG_OK;
|
||||
return status;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::reset_frame_events()
|
||||
{
|
||||
// Preserve format and input events for the monitor.
|
||||
for (HANDLE frameEvent : {events_.hVideoFrameInEvent, events_.hVideoExtraFrame,
|
||||
events_.hAudioFrameInEvent, events_.hAudioExtraFrame})
|
||||
{
|
||||
if (frameEvent && !ResetEvent(frameEvent))
|
||||
return reject(GVFG_EIO, "Capture frame event reset failed");
|
||||
}
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
@@ -476,6 +657,7 @@ namespace gvfg::internal
|
||||
"GvfgStartCapture");
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
driver_stream_running_ = true;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
frame_held_ = false;
|
||||
@@ -509,12 +691,14 @@ namespace gvfg::internal
|
||||
if (wasRunning && channel_open_ && context_)
|
||||
{
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
const gvfg_status_t stopStatus = from_vendor(GvfgStopCapture(context_, channel_),
|
||||
"GvfgStopCapture");
|
||||
const gvfg_status_t stopStatus = driver_stream_running_
|
||||
? from_vendor(GvfgStopCapture(context_, channel_), "GvfgStopCapture")
|
||||
: GVFG_OK;
|
||||
if (result == GVFG_OK)
|
||||
result = stopStatus;
|
||||
if (stopStatus == GVFG_OK)
|
||||
{
|
||||
driver_stream_running_ = false;
|
||||
#ifndef NDEBUG
|
||||
if (events_.hVideoFormatChangedEvent &&
|
||||
WaitForSingleObject(events_.hVideoFormatChangedEvent, 0) == WAIT_OBJECT_0)
|
||||
@@ -537,10 +721,14 @@ namespace gvfg::internal
|
||||
*acquisitionBeginNs = 0;
|
||||
if (!running_ || !context_)
|
||||
return reject(GVFG_ESTATE, "Capture frame read rejected: stream is not running");
|
||||
uint64_t generation = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
generation = signal_generation_;
|
||||
if (frame_held_)
|
||||
return reject(GVFG_ESTATE, "Capture frame read rejected: previous frame is held");
|
||||
if (!recovery_pending_ && !video_info_valid_ && video_info_status_ != GVFG_ETIMEOUT)
|
||||
return video_info_status_;
|
||||
}
|
||||
|
||||
std::array<HANDLE, 4> handles{stop_event_, recovery_event_,
|
||||
@@ -570,19 +758,23 @@ namespace gvfg::internal
|
||||
++extra_video_event_wakes_;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
gvfg_signal_status_t signal{};
|
||||
size_t bytes = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
if (!running_)
|
||||
return GVFG_ESTATE;
|
||||
if (recovery_pending_ || generation != signal_generation_)
|
||||
return GVFG_ETIMEOUT;
|
||||
if (!video_info_valid_)
|
||||
return video_info_status_;
|
||||
signal = cached_signal_;
|
||||
bytes = video_info_.cbBufSize;
|
||||
}
|
||||
if (!signal.connected || signal.width == 0 || signal.height == 0)
|
||||
return GVFG_ETIMEOUT;
|
||||
|
||||
size_t bytes = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
bytes = video_info_.cbBufSize;
|
||||
}
|
||||
const void *data = nullptr;
|
||||
void *zeroCopyData = nullptr;
|
||||
gvfg_status_t status = GVFG_OK;
|
||||
@@ -590,11 +782,8 @@ namespace gvfg::internal
|
||||
{
|
||||
void *buffer = nullptr;
|
||||
const auto begin = std::chrono::steady_clock::now();
|
||||
{
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
status = from_vendor(GvfgGetVideoFrameZeroCopy(context_, channel_, &buffer),
|
||||
"GvfgGetVideoFrameZeroCopy");
|
||||
}
|
||||
status = from_vendor(GvfgGetVideoFrameZeroCopy(context_, channel_, &buffer),
|
||||
"GvfgGetVideoFrameZeroCopy");
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
record_get_frame_timing(std::chrono::duration<double, std::micro>(end - begin).count());
|
||||
data = buffer;
|
||||
@@ -605,12 +794,9 @@ namespace gvfg::internal
|
||||
if (copy_buffer_.size() != bytes)
|
||||
copy_buffer_.assign(bytes, 0);
|
||||
const auto begin = std::chrono::steady_clock::now();
|
||||
{
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
status = from_vendor(GvfgGetVideoFrame(context_, channel_, copy_buffer_.data(),
|
||||
static_cast<ULONG>(copy_buffer_.size())),
|
||||
"GvfgGetVideoFrame");
|
||||
}
|
||||
status = from_vendor(GvfgGetVideoFrame(context_, channel_, copy_buffer_.data(),
|
||||
static_cast<ULONG>(copy_buffer_.size())),
|
||||
"GvfgGetVideoFrame");
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
record_get_frame_timing(std::chrono::duration<double, std::micro>(end - begin).count());
|
||||
data = copy_buffer_.data();
|
||||
@@ -646,20 +832,6 @@ namespace gvfg::internal
|
||||
return copy_buffer_.data();
|
||||
}
|
||||
|
||||
uint8_t *GigabyteCaptureSession::experimental_zero_copy_frame_data(const gvfg_frame_t &frame)
|
||||
{
|
||||
#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
if (!zero_copy_enabled_ || !frame_held_ || !held_zero_copy_data_ ||
|
||||
frame.data != held_zero_copy_data_ || frame.data_size != held_zero_copy_bytes_)
|
||||
return nullptr;
|
||||
return static_cast<uint8_t *>(held_zero_copy_data_);
|
||||
#else
|
||||
(void)frame;
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::release_frame()
|
||||
{
|
||||
{
|
||||
@@ -675,25 +847,31 @@ namespace gvfg::internal
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
void GigabyteCaptureSession::get_cached_signal_status(gvfg_signal_status_t &out) const
|
||||
gvfg_status_t GigabyteCaptureSession::get_cached_signal_status(gvfg_signal_status_t &out) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
out = {};
|
||||
if (recovery_pending_)
|
||||
return GVFG_ETIMEOUT;
|
||||
if (!video_info_valid_)
|
||||
return video_info_status_;
|
||||
out = cached_signal_;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::wait_audio(
|
||||
uint32_t timeoutMs, void *destination, uint32_t destinationCapacity, uint32_t &outBytes)
|
||||
uint32_t timeoutMs, std::vector<uint8_t> &buffer, GigabyteAudioInfo &format)
|
||||
{
|
||||
outBytes = 0;
|
||||
if (!running_ || !audio_enabled_ || !destination)
|
||||
format = {};
|
||||
if (!running_ || !audio_enabled_)
|
||||
return reject(GVFG_ESTATE, "Capture audio read rejected");
|
||||
uint32_t frameBytes = 0;
|
||||
uint64_t generation = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
frameBytes = audio_info_.cbBufSize;
|
||||
generation = signal_generation_;
|
||||
if (!recovery_pending_ && !audio_info_valid_ && audio_info_status_ != GVFG_ETIMEOUT)
|
||||
return audio_info_status_;
|
||||
}
|
||||
if (frameBytes == 0 || frameBytes > destinationCapacity)
|
||||
return reject(GVFG_EINVAL, "Capture audio destination is too small");
|
||||
if (!events_.hAudioFrameInEvent)
|
||||
return reject(GVFG_EIO, "Capture backend did not provide an audio-frame event");
|
||||
|
||||
@@ -710,22 +888,30 @@ namespace gvfg::internal
|
||||
return wait_for_recovery(timeoutMs);
|
||||
if (wait != WAIT_OBJECT_0 + 2 && wait != WAIT_OBJECT_0 + 3)
|
||||
return reject(GVFG_EIO, "Capture audio event wait failed");
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
if (!running_)
|
||||
return GVFG_ESTATE;
|
||||
if (recovery_pending_ || generation != signal_generation_)
|
||||
return GVFG_ETIMEOUT;
|
||||
if (!audio_info_valid_)
|
||||
return audio_info_status_;
|
||||
format.sample_rate = audio_info_.SamplesPerSec;
|
||||
format.channels = audio_info_.Channels;
|
||||
format.bits_per_sample = audio_info_.BitsPerSample;
|
||||
format.frame_bytes = audio_info_.cbBufSize;
|
||||
if (wait == WAIT_OBJECT_0 + 2)
|
||||
++audio_event_wakes_;
|
||||
else
|
||||
++extra_audio_event_wakes_;
|
||||
}
|
||||
gvfg_status_t status = GVFG_OK;
|
||||
{
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
status = from_vendor(GvfgGetAudioFrame(context_, channel_, destination, frameBytes),
|
||||
"GvfgGetAudioFrame");
|
||||
}
|
||||
buffer.resize(format.frame_bytes);
|
||||
const gvfg_status_t status = from_vendor(
|
||||
GvfgGetAudioFrame(context_, channel_, buffer.data(), format.frame_bytes),
|
||||
"GvfgGetAudioFrame");
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
outBytes = frameBytes;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
++audio_frames_from_lib_;
|
||||
@@ -776,39 +962,10 @@ namespace gvfg::internal
|
||||
const int kind = kinds[wait - WAIT_OBJECT_0];
|
||||
if (kind == 0 || !monitoring_)
|
||||
return;
|
||||
if (kind == 1)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
OutputDebugStringA("[GVFG] Received VIDEO_FORMAT_CHANGED\n");
|
||||
#endif
|
||||
refresh_video_info();
|
||||
emit_event(GVFG_EVENT_VIDEO_FORMAT_CHANGED);
|
||||
}
|
||||
else if (kind == 2)
|
||||
{
|
||||
refresh_video_info();
|
||||
if (running_)
|
||||
{
|
||||
recovery_status_ = GVFG_OK;
|
||||
recovery_pending_ = true;
|
||||
SetEvent(recovery_event_);
|
||||
recover_stream_after_plugin();
|
||||
// Recovery restarts the vendor stream. Refresh the geometry
|
||||
// again before publishing the plug-in event to clients.
|
||||
refresh_video_info();
|
||||
}
|
||||
emit_event(GVFG_EVENT_VIDEO_INPUT_PLUGIN);
|
||||
}
|
||||
else if (kind == 3)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
cached_signal_ = {};
|
||||
cached_signal_.channel = channel_;
|
||||
video_info_valid_ = false;
|
||||
}
|
||||
emit_event(GVFG_EVENT_VIDEO_INPUT_UNPLUG);
|
||||
}
|
||||
constexpr std::array<gvfg_event_type_t, 3> signalEvents{
|
||||
GVFG_EVENT_VIDEO_FORMAT_CHANGED, GVFG_EVENT_VIDEO_INPUT_PLUGIN,
|
||||
GVFG_EVENT_VIDEO_INPUT_UNPLUG};
|
||||
handle_signal_event(signalEvents[static_cast<size_t>(kind - 1)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -938,7 +1095,100 @@ namespace gvfg::internal
|
||||
return status;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::recover_stream_after_plugin()
|
||||
void GigabyteCaptureSession::handle_signal_event(gvfg_event_type_t event)
|
||||
{
|
||||
const bool unplugged = event == GVFG_EVENT_VIDEO_INPUT_UNPLUG;
|
||||
GVFG_VIDEO_INFO previousVideo{};
|
||||
GVFG_AUDIO_INFO previousAudio{};
|
||||
bool previousVideoValid = false;
|
||||
bool previousAudioValid = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
std::lock_guard<std::mutex> stateLock(state_mutex_);
|
||||
if (!running_)
|
||||
return;
|
||||
++signal_generation_;
|
||||
previousVideo = video_info_;
|
||||
previousAudio = audio_info_;
|
||||
previousVideoValid = video_info_valid_;
|
||||
previousAudioValid = audio_info_valid_;
|
||||
cached_signal_ = {};
|
||||
cached_signal_.channel = channel_;
|
||||
video_info_ = {};
|
||||
audio_info_ = {};
|
||||
video_info_valid_ = unplugged;
|
||||
audio_info_valid_ = false;
|
||||
video_info_status_ = GVFG_ETIMEOUT;
|
||||
audio_info_status_ = GVFG_ETIMEOUT;
|
||||
recovery_status_ = GVFG_OK;
|
||||
recovery_pending_ = !unplugged;
|
||||
if (recovery_pending_)
|
||||
SetEvent(recovery_event_);
|
||||
}
|
||||
|
||||
if (!unplugged)
|
||||
{
|
||||
gvfg_signal_status_t signal{};
|
||||
gvfg_status_t status = get_signal_status(signal, true);
|
||||
if (status == GVFG_OK && !signal.connected)
|
||||
status = reject(GVFG_ETIMEOUT, "Input signal is not locked during capture recovery");
|
||||
|
||||
gvfg_status_t audioStatus = GVFG_OK;
|
||||
if (status == GVFG_OK && audio_enabled_)
|
||||
audioStatus = refresh_audio_info();
|
||||
|
||||
bool restart = event == GVFG_EVENT_VIDEO_INPUT_PLUGIN || !previousVideoValid;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
restart = restart || previousVideo.Fourcc != video_info_.Fourcc ||
|
||||
previousVideo.Width != video_info_.Width ||
|
||||
previousVideo.Height != video_info_.Height ||
|
||||
previousVideo.cbBufSize != video_info_.cbBufSize ||
|
||||
previousVideo.VideoSignalLock != video_info_.VideoSignalLock ||
|
||||
(audio_enabled_ && audio_info_valid_ &&
|
||||
(!previousAudioValid ||
|
||||
previousAudio.SamplesPerSec != audio_info_.SamplesPerSec ||
|
||||
previousAudio.Channels != audio_info_.Channels ||
|
||||
previousAudio.BitsPerSample != audio_info_.BitsPerSample ||
|
||||
previousAudio.cbBufSize != audio_info_.cbBufSize));
|
||||
}
|
||||
|
||||
if (status == GVFG_OK && restart)
|
||||
{
|
||||
status = restart_stream_after_signal_change();
|
||||
if (status == GVFG_OK)
|
||||
status = get_signal_status(signal, true);
|
||||
if (status == GVFG_OK && !signal.connected)
|
||||
status = reject(GVFG_ETIMEOUT, "Input signal lost after capture restarted");
|
||||
if (status == GVFG_OK && audio_enabled_)
|
||||
audioStatus = refresh_audio_info();
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
if (status != GVFG_OK)
|
||||
{
|
||||
video_info_valid_ = false;
|
||||
audio_info_valid_ = false;
|
||||
video_info_status_ = status;
|
||||
audio_info_status_ = status;
|
||||
}
|
||||
else if (audioStatus != GVFG_OK)
|
||||
{
|
||||
audio_info_valid_ = false;
|
||||
audio_info_status_ = audioStatus;
|
||||
}
|
||||
recovery_status_ = status;
|
||||
recovery_pending_ = false;
|
||||
ResetEvent(recovery_event_);
|
||||
}
|
||||
recovery_cv_.notify_all();
|
||||
}
|
||||
if (running_)
|
||||
emit_event(event);
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::restart_stream_after_signal_change()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> stateLock(state_mutex_);
|
||||
@@ -947,26 +1197,22 @@ namespace gvfg::internal
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> captureLock(capture_mutex_);
|
||||
if (!recovery_pending_)
|
||||
{
|
||||
ResetEvent(recovery_event_);
|
||||
return GVFG_OK;
|
||||
}
|
||||
if (!running_)
|
||||
return GVFG_ESTATE;
|
||||
if (driver_stream_running_)
|
||||
{
|
||||
recovery_pending_ = false;
|
||||
ResetEvent(recovery_event_);
|
||||
recovery_cv_.notify_all();
|
||||
return GVFG_OK;
|
||||
const gvfg_status_t stopStatus =
|
||||
from_vendor(GvfgStopCapture(context_, channel_), "GvfgStopCapture");
|
||||
if (stopStatus != GVFG_OK)
|
||||
return stopStatus;
|
||||
driver_stream_running_ = false;
|
||||
}
|
||||
|
||||
gvfg_status_t status = from_vendor(GvfgStopCapture(context_, channel_), "GvfgStopCapture");
|
||||
if (status == GVFG_OK)
|
||||
status = from_vendor(GvfgStartCapture(context_, channel_), "GvfgStartCapture");
|
||||
recovery_status_ = status;
|
||||
recovery_pending_ = false;
|
||||
ResetEvent(recovery_event_);
|
||||
recovery_cv_.notify_all();
|
||||
const gvfg_status_t resetStatus = reset_frame_events();
|
||||
if (resetStatus != GVFG_OK)
|
||||
return resetStatus;
|
||||
const gvfg_status_t status =
|
||||
from_vendor(GvfgStartCapture(context_, channel_), "GvfgStartCapture");
|
||||
driver_stream_running_ = status == GVFG_OK;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,15 @@ namespace gvfg::internal
|
||||
bool zero_copy_enabled() const { return zero_copy_enabled_; }
|
||||
gvfg_status_t set_audio_enabled(bool enabled);
|
||||
gvfg_status_t set_video_format(gvfg_pixel_format_t format);
|
||||
gvfg_status_t get_signal_status(gvfg_signal_status_t &out);
|
||||
void get_cached_signal_status(gvfg_signal_status_t &out) const;
|
||||
gvfg_status_t get_signal_status(gvfg_signal_status_t &out,
|
||||
bool verifyRequestedFormat);
|
||||
gvfg_status_t get_cached_signal_status(gvfg_signal_status_t &out) const;
|
||||
gvfg_status_t get_device_capabilities(gvfg_debug_device_capabilities_t &out);
|
||||
gvfg_status_t get_sdi_info(gvfg_sdi_info_t &out);
|
||||
gvfg_status_t get_hdmi_audio_info(gvfg_hdmi_audio_info_t &out);
|
||||
gvfg_status_t get_hdmi_info(gvfg_hdmi_info_t &out);
|
||||
gvfg_status_t get_chip_info(gvfg_chip_info_t &out);
|
||||
gvfg_status_t set_user_led(bool on);
|
||||
gvfg_status_t get_audio_format(GigabyteAudioInfo &out);
|
||||
gvfg_status_t set_event_callback(GigabyteEventCallback callback, void *user);
|
||||
gvfg_status_t configure_stream();
|
||||
@@ -60,10 +65,8 @@ namespace gvfg::internal
|
||||
// Internal writable access only to the currently held SDK-owned copy.
|
||||
// Driver zero-copy buffers are never returned. Valid until release.
|
||||
uint8_t *writable_copy_frame_data(const gvfg_frame_t &frame);
|
||||
// Opt-in test candidate only, not a driver write/hold guarantee.
|
||||
uint8_t *experimental_zero_copy_frame_data(const gvfg_frame_t &frame);
|
||||
gvfg_status_t wait_audio(uint32_t timeoutMs, void *destination,
|
||||
uint32_t destinationCapacity, uint32_t &outBytes);
|
||||
gvfg_status_t wait_audio(uint32_t timeoutMs, std::vector<uint8_t> &buffer,
|
||||
GigabyteAudioInfo &format);
|
||||
gvfg_status_t release_frame();
|
||||
void fill_debug_stats(gvfg_debug_backend_stats_t &out);
|
||||
gvfg_status_t debug_read_register(uint32_t offset, uint32_t &outValue);
|
||||
@@ -77,7 +80,9 @@ namespace gvfg::internal
|
||||
void stop_event_monitoring();
|
||||
void event_thread_proc();
|
||||
void emit_event(gvfg_event_type_t type) const;
|
||||
gvfg_status_t recover_stream_after_plugin();
|
||||
void handle_signal_event(gvfg_event_type_t event);
|
||||
gvfg_status_t restart_stream_after_signal_change();
|
||||
gvfg_status_t reset_frame_events();
|
||||
gvfg_status_t wait_for_recovery(uint32_t timeoutMs);
|
||||
gvfg_status_t refresh_video_info();
|
||||
gvfg_status_t refresh_audio_info();
|
||||
@@ -95,6 +100,9 @@ namespace gvfg::internal
|
||||
bool events_created_ = false;
|
||||
bool channel_open_ = false;
|
||||
bool video_info_valid_ = false;
|
||||
gvfg_status_t video_info_status_ = GVFG_ETIMEOUT;
|
||||
gvfg_status_t audio_info_status_ = GVFG_ETIMEOUT;
|
||||
uint64_t signal_generation_ = 0;
|
||||
bool format_change_pending_ = false;
|
||||
gvfg_pixel_format_t requested_video_format_ = GVFG_PIXFMT_UNKNOWN;
|
||||
bool audio_info_valid_ = false;
|
||||
@@ -105,6 +113,7 @@ namespace gvfg::internal
|
||||
bool configured_ = false;
|
||||
bool zero_copy_enabled_ = false;
|
||||
bool audio_enabled_ = false;
|
||||
bool driver_stream_running_ = false; // Protected by capture_mutex_ while open.
|
||||
std::atomic<bool> running_{false};
|
||||
std::atomic<bool> recovery_pending_{false};
|
||||
std::atomic<gvfg_status_t> recovery_status_{GVFG_OK};
|
||||
@@ -116,6 +125,7 @@ namespace gvfg::internal
|
||||
mutable std::mutex state_mutex_;
|
||||
std::condition_variable recovery_cv_;
|
||||
std::mutex capture_mutex_;
|
||||
std::mutex input_info_mutex_;
|
||||
std::vector<uint8_t> copy_buffer_;
|
||||
bool frame_held_ = false;
|
||||
void *held_zero_copy_data_ = nullptr;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <setupapi.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cwchar>
|
||||
|
||||
#pragma comment(lib, "SetupAPI.lib")
|
||||
|
||||
@@ -27,6 +28,26 @@ namespace
|
||||
return {};
|
||||
return reinterpret_cast<const wchar_t *>(bytes.data());
|
||||
}
|
||||
|
||||
std::wstring pci_location_path(HDEVINFO info, SP_DEVINFO_DATA &deviceInfo)
|
||||
{
|
||||
DWORD required = 0;
|
||||
SetupDiGetDeviceRegistryPropertyW(info, &deviceInfo, SPDRP_LOCATION_PATHS,
|
||||
nullptr, nullptr, 0, &required);
|
||||
if (required < 2 * sizeof(wchar_t))
|
||||
return {};
|
||||
|
||||
std::vector<wchar_t> paths(required / sizeof(wchar_t) + 2);
|
||||
DWORD type = 0;
|
||||
if (!SetupDiGetDeviceRegistryPropertyW(info, &deviceInfo, SPDRP_LOCATION_PATHS,
|
||||
&type, reinterpret_cast<BYTE *>(paths.data()),
|
||||
required, nullptr) || type != REG_MULTI_SZ)
|
||||
return {};
|
||||
for (const wchar_t *path = paths.data(); *path; path += std::wcslen(path) + 1)
|
||||
if (_wcsnicmp(path, L"PCIROOT(", 8) == 0)
|
||||
return path;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
namespace gvfg::internal
|
||||
@@ -58,6 +79,7 @@ namespace gvfg::internal
|
||||
|
||||
GigabyteDevice device;
|
||||
device.interface_path = detail->DevicePath;
|
||||
device.pci_location_path = pci_location_path(info, deviceInfo);
|
||||
device.friendly_name = device_property(info, deviceInfo, SPDRP_FRIENDLYNAME);
|
||||
if (device.friendly_name.empty())
|
||||
device.friendly_name = device_property(info, deviceInfo, SPDRP_DEVICEDESC);
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace gvfg::internal
|
||||
{
|
||||
std::wstring interface_path;
|
||||
std::wstring friendly_name;
|
||||
std::wstring pci_location_path;
|
||||
};
|
||||
|
||||
std::vector<GigabyteDevice> enumerate_gigabyte_devices();
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "gvfg_capture.h"
|
||||
|
||||
#ifdef GVFG_CAPTURE_TEST_RUNTIME
|
||||
#include "gvfg_test_device.h"
|
||||
#endif
|
||||
|
||||
#include "gvfg_debug.h"
|
||||
#include "gigabyte_capture_session.h"
|
||||
#include "gpu/gvfg_gpu_osd.h"
|
||||
#include "gvfg_osd.h"
|
||||
#include "gvfg_frame_processor.h"
|
||||
#include "gvfgframework.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -16,6 +19,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
@@ -153,7 +157,6 @@ struct gvfg_channel_session_t
|
||||
return stOpen;
|
||||
}
|
||||
|
||||
currentIndex = index;
|
||||
syncSessionEventCallback();
|
||||
selectedChannel = static_cast<uint32_t>(channelIndex);
|
||||
resetRuntimeCounters();
|
||||
@@ -194,7 +197,8 @@ struct gvfg_channel_session_t
|
||||
return cfg;
|
||||
if (audioEnabled)
|
||||
{
|
||||
const gvfg_status_t audioStatus = session->get_audio_format(cachedAudioFormat);
|
||||
GigabyteAudioInfo format{};
|
||||
const gvfg_status_t audioStatus = session->get_audio_format(format);
|
||||
if (audioStatus != GVFG_OK)
|
||||
return audioStatus;
|
||||
}
|
||||
@@ -214,7 +218,11 @@ struct gvfg_channel_session_t
|
||||
if (st != GVFG_OK)
|
||||
return st;
|
||||
|
||||
running = true;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(frameMutex);
|
||||
++runGeneration;
|
||||
running = true;
|
||||
}
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
@@ -249,7 +257,6 @@ struct gvfg_channel_session_t
|
||||
session->close();
|
||||
session.reset();
|
||||
}
|
||||
currentIndex = -1;
|
||||
}
|
||||
|
||||
gvfg_status_t getSignalStatus(gvfg_signal_status_t &out)
|
||||
@@ -310,13 +317,13 @@ struct gvfg_channel_session_t
|
||||
eventCv.notify_one();
|
||||
}
|
||||
|
||||
gvfg_status_t querySignal()
|
||||
gvfg_status_t querySignal(bool verifyRequestedFormat = false)
|
||||
{
|
||||
if (!session)
|
||||
return GVFG_ESTATE;
|
||||
|
||||
gvfg_signal_status_t sig{};
|
||||
const gvfg_status_t status = session->get_signal_status(sig);
|
||||
const gvfg_status_t status = session->get_signal_status(sig, verifyRequestedFormat);
|
||||
|
||||
std::lock_guard<std::mutex> lock(stateMutex);
|
||||
width = status == GVFG_OK ? sig.width : 0;
|
||||
@@ -336,7 +343,7 @@ struct gvfg_channel_session_t
|
||||
return GVFG_ESTATE;
|
||||
|
||||
gvfg_signal_status_t sig{};
|
||||
session->get_cached_signal_status(sig);
|
||||
const gvfg_status_t status = session->get_cached_signal_status(sig);
|
||||
|
||||
std::lock_guard<std::mutex> lock(stateMutex);
|
||||
width = sig.width > 0 ? static_cast<uint32_t>(sig.width) : 0;
|
||||
@@ -345,7 +352,7 @@ struct gvfg_channel_session_t
|
||||
pixelFormat = static_cast<gvfg_pixel_format_t>(sig.pixel_format);
|
||||
videoInterface = sig.video_interface;
|
||||
signalConnected = sig.connected != 0;
|
||||
return GVFG_OK;
|
||||
return status;
|
||||
}
|
||||
|
||||
gvfg_status_t configureStream()
|
||||
@@ -353,10 +360,7 @@ struct gvfg_channel_session_t
|
||||
if (!session)
|
||||
return reject(GVFG_ESTATE, "configure stream rejected: channel is not open");
|
||||
|
||||
const gvfg_status_t st = session->configure_stream();
|
||||
if (st != GVFG_OK)
|
||||
return st;
|
||||
const gvfg_status_t signalStatus = querySignal();
|
||||
const gvfg_status_t signalStatus = querySignal(true);
|
||||
if (signalStatus != GVFG_OK)
|
||||
return signalStatus;
|
||||
{
|
||||
@@ -365,7 +369,7 @@ struct gvfg_channel_session_t
|
||||
return reject(GVFG_ETIMEOUT,
|
||||
"gvfg_start_channel rejected: no input signal");
|
||||
}
|
||||
return GVFG_OK;
|
||||
return session->configure_stream();
|
||||
}
|
||||
|
||||
gvfg_status_t readFrame(gvfg_frame_t &out, uint32_t timeoutMs,
|
||||
@@ -383,6 +387,7 @@ struct gvfg_channel_session_t
|
||||
return reject(GVFG_ESTATE, "gvfg_read_channel_frame rejected: channel is not running");
|
||||
|
||||
const char *stateError = nullptr;
|
||||
uint64_t readRunGeneration = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(frameMutex);
|
||||
if (frameHeld)
|
||||
@@ -390,7 +395,10 @@ struct gvfg_channel_session_t
|
||||
else if (readInProgress)
|
||||
stateError = "gvfg_read_channel_frame rejected: another read is already in progress";
|
||||
else
|
||||
{
|
||||
readInProgress = true;
|
||||
readRunGeneration = runGeneration;
|
||||
}
|
||||
}
|
||||
if (stateError)
|
||||
return reject(GVFG_ESTATE, stateError);
|
||||
@@ -428,28 +436,23 @@ struct gvfg_channel_session_t
|
||||
}
|
||||
|
||||
bool osdApplied = false;
|
||||
int processedStride = 0;
|
||||
// This capability comes from the backend, never from const_cast of a
|
||||
// public frame pointer. Driver storage is excluded by default; only
|
||||
// the explicit unsafe build option below can admit it for experiments.
|
||||
uint8_t *writableSource = session->writable_copy_frame_data(frame);
|
||||
bool experimentalZeroCopy = false;
|
||||
bool inPlaceApplied = false;
|
||||
uint32_t experimentFlags = 0;
|
||||
gvfg_debug_osd_page_check_t pageCheck{};
|
||||
#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
|
||||
experimentFlags = GVFG_DEBUG_OSD_EXPERIMENT_ENABLED;
|
||||
if (!writableSource)
|
||||
gvfg_frame_t processedFrame{};
|
||||
const gvfg_frame_processor *processor = nullptr;
|
||||
void *processorContext = nullptr;
|
||||
{
|
||||
writableSource = session->experimental_zero_copy_frame_data(frame);
|
||||
experimentalZeroCopy = writableSource != nullptr;
|
||||
std::lock_guard<std::mutex> lock(processorMutex);
|
||||
processor = frameProcessor.ops;
|
||||
processorContext = frameProcessor.context;
|
||||
}
|
||||
#endif
|
||||
// Only SDK-owned copy-mode buffers are available for in-place writes.
|
||||
uint8_t *writableSource = processor ? session->writable_copy_frame_data(frame) : nullptr;
|
||||
bool inPlaceApplied = false;
|
||||
const uint64_t processBeginNs = timing ? now_ns() : 0;
|
||||
const gvfg_status_t osdStatus =
|
||||
osdProcessor.process(frame, processedVideoBuffer, processedStride, osdApplied, timing,
|
||||
writableSource, experimentalZeroCopy, &inPlaceApplied, &experimentFlags, &pageCheck);
|
||||
if (timing)
|
||||
const gvfg_status_t osdStatus = processor
|
||||
? processor->process(processorContext, frame, processedFrame, osdApplied, timing,
|
||||
writableSource, &inPlaceApplied)
|
||||
: GVFG_OK;
|
||||
if (timing && processor)
|
||||
timing->stage_ms[GVFG_DEBUG_OSD_PROCESS_TOTAL] = static_cast<double>(now_ns() - processBeginNs) / 1e6;
|
||||
if (osdStatus != GVFG_OK)
|
||||
{
|
||||
@@ -475,15 +478,17 @@ struct gvfg_channel_session_t
|
||||
return releaseStatus;
|
||||
}
|
||||
backendFrameHeld = false;
|
||||
frame.data = processedVideoBuffer.data();
|
||||
frame.data_size = static_cast<uint64_t>(processedVideoBuffer.size());
|
||||
frame.row_stride_bytes = processedStride;
|
||||
frame.data = processedFrame.data;
|
||||
frame.data_size = processedFrame.data_size;
|
||||
frame.row_stride_bytes = processedFrame.row_stride_bytes;
|
||||
}
|
||||
|
||||
bool stoppedWhileWaiting = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(frameMutex);
|
||||
if (!running.load(std::memory_order_acquire))
|
||||
// A stop and start during this read set running back to true, but the
|
||||
// frame belongs to the stopped stream and its backend hold is gone.
|
||||
if (!running.load(std::memory_order_acquire) || runGeneration != readRunGeneration)
|
||||
{
|
||||
readInProgress = false;
|
||||
stoppedWhileWaiting = true;
|
||||
@@ -492,8 +497,6 @@ struct gvfg_channel_session_t
|
||||
{
|
||||
frame.frame_id = ++videoFrameId;
|
||||
heldSessionFrame = frame;
|
||||
heldOsdExperimentFlags = experimentFlags;
|
||||
heldOsdPageCheck = pageCheck;
|
||||
heldFrameNeedsBackendRelease = backendFrameHeld;
|
||||
readInProgress = false;
|
||||
frameHeld = true;
|
||||
@@ -503,20 +506,13 @@ struct gvfg_channel_session_t
|
||||
{
|
||||
if (backendFrameHeld)
|
||||
session->release_frame();
|
||||
return GVFG_ESTATE;
|
||||
return reject(GVFG_ESTATE,
|
||||
"gvfg_read_channel_frame rejected: capture stopped or restarted during the read");
|
||||
}
|
||||
|
||||
updateRuntimeFps(now_ns());
|
||||
|
||||
out.data = frame.data;
|
||||
out.data_size = static_cast<uint64_t>(frame.data_size);
|
||||
out.width = static_cast<int>(frame.width);
|
||||
out.height = static_cast<int>(frame.height);
|
||||
out.row_stride_bytes = frame.row_stride_bytes;
|
||||
out.pixel_format = frame.pixel_format;
|
||||
out.bit_depth = static_cast<int>(frame.bit_depth);
|
||||
out.frame_id = frame.frame_id;
|
||||
out.timestamp_ns = frame.timestamp_ns;
|
||||
out = frame;
|
||||
if (timing)
|
||||
timing->frame_id = out.frame_id;
|
||||
noteDeliveredFrame(out.width, out.height, out.bit_depth, out.pixel_format);
|
||||
@@ -524,31 +520,6 @@ struct gvfg_channel_session_t
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t osdExperimentFlags(uint64_t frameId, uint32_t &flags)
|
||||
{
|
||||
flags = 0;
|
||||
#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
|
||||
flags = GVFG_DEBUG_OSD_EXPERIMENT_ENABLED;
|
||||
#endif
|
||||
if (frameId == 0)
|
||||
return GVFG_OK;
|
||||
std::lock_guard<std::mutex> lock(frameMutex);
|
||||
if (!frameHeld || heldSessionFrame.frame_id != frameId)
|
||||
return GVFG_ESTATE;
|
||||
flags = heldOsdExperimentFlags;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t osdPageCheck(uint64_t frameId, gvfg_debug_osd_page_check_t &check)
|
||||
{
|
||||
check = {};
|
||||
std::lock_guard<std::mutex> lock(frameMutex);
|
||||
if (!frameId || !frameHeld || heldSessionFrame.frame_id != frameId)
|
||||
return GVFG_ESTATE;
|
||||
check = heldOsdPageCheck;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t releaseFrame(const gvfg_frame_t &frameToken)
|
||||
{
|
||||
if (!session)
|
||||
@@ -682,31 +653,28 @@ struct gvfg_channel_session_t
|
||||
return session->set_video_format(format);
|
||||
}
|
||||
|
||||
gvfg_status_t setOsd(uint32_t index, const gvfg_channel_osd_config_t &config)
|
||||
gvfg_status_t controlFrameProcessor(const gvfg_frame_processor *processor, bool create,
|
||||
gvfg_frame_processor_control control, const void *argument,
|
||||
const char *error)
|
||||
{
|
||||
if (!session)
|
||||
return reject(GVFG_ESTATE, "gvfg_set_channel_osd rejected: channel is not open");
|
||||
const gvfg_status_t status = osdProcessor.configure(index, config);
|
||||
return status == GVFG_OK
|
||||
? GVFG_OK
|
||||
: reject(status, status == GVFG_EINVAL
|
||||
? "gvfg_set_channel_osd rejected: configuration is invalid"
|
||||
: "gvfg_set_channel_osd failed to store configuration");
|
||||
}
|
||||
return reject(GVFG_ESTATE, "Frame processor channel is not open");
|
||||
|
||||
gvfg_status_t clearOsd(uint32_t index)
|
||||
{
|
||||
if (!session)
|
||||
return reject(GVFG_ESTATE, "gvfg_clear_channel_osd rejected: channel is not open");
|
||||
return osdProcessor.clear(index);
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(processorMutex);
|
||||
if (!frameProcessor.ops)
|
||||
{
|
||||
if (!create)
|
||||
return GVFG_OK;
|
||||
const auto status = processor->create(&frameProcessor.context);
|
||||
if (status != GVFG_OK)
|
||||
return reject(status, error);
|
||||
frameProcessor.ops = processor;
|
||||
}
|
||||
if (frameProcessor.ops != processor)
|
||||
return reject(GVFG_ESTATE, "A different frame processor is already attached");
|
||||
|
||||
gvfg_status_t setOsdVisible(uint32_t index, int visible)
|
||||
{
|
||||
if (!session)
|
||||
return reject(GVFG_ESTATE, "OSD visibility rejected: channel is not open");
|
||||
const gvfg_status_t status = osdProcessor.setVisible(index, visible);
|
||||
return status == GVFG_OK ? status : reject(status, "OSD visibility rejected: invalid slot, visibility, or no saved configuration");
|
||||
const auto status = control(frameProcessor.context, argument);
|
||||
return status == GVFG_OK ? status : reject(status, error);
|
||||
}
|
||||
|
||||
gvfg_status_t setAudioEnabled(bool enabled)
|
||||
@@ -738,7 +706,6 @@ struct gvfg_channel_session_t
|
||||
const gvfg_status_t status = session->get_audio_format(format);
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
cachedAudioFormat = format;
|
||||
out.sample_rate = format.sample_rate;
|
||||
out.channels = format.channels;
|
||||
out.bits_per_sample = format.bits_per_sample;
|
||||
@@ -762,26 +729,19 @@ struct gvfg_channel_session_t
|
||||
audioReadInProgress = true;
|
||||
}
|
||||
|
||||
const GigabyteAudioInfo format = cachedAudioFormat;
|
||||
gvfg_status_t status = format.frame_bytes != 0 ? GVFG_OK : GVFG_ESTATE;
|
||||
uint32_t bytes = 0;
|
||||
if (status == GVFG_OK)
|
||||
{
|
||||
audioBuffer.resize(format.frame_bytes);
|
||||
status = session->wait_audio(timeoutMs, audioBuffer.data(),
|
||||
static_cast<uint32_t>(audioBuffer.size()), bytes);
|
||||
}
|
||||
GigabyteAudioInfo format{};
|
||||
const gvfg_status_t status = session->wait_audio(timeoutMs, audioBuffer, format);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(audioMutex);
|
||||
audioReadInProgress = false;
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
if (!running.load(std::memory_order_acquire) || bytes == 0 || bytes > audioBuffer.size())
|
||||
if (!running.load(std::memory_order_acquire))
|
||||
return reject(GVFG_ESTATE, "gvfg_read_channel_audio_frame completed after capture stopped or returned invalid data");
|
||||
audioFrameHeld = true;
|
||||
out.data = audioBuffer.data();
|
||||
out.data_size = bytes;
|
||||
out.data_size = format.frame_bytes;
|
||||
out.sample_rate = format.sample_rate;
|
||||
out.channels = format.channels;
|
||||
out.bits_per_sample = format.bits_per_sample;
|
||||
@@ -865,11 +825,9 @@ struct gvfg_channel_session_t
|
||||
|
||||
ChannelErrorState &errorState;
|
||||
std::unique_ptr<gvfg::internal::GigabyteCaptureSession> session;
|
||||
int currentIndex = -1;
|
||||
uint32_t selectedChannel = GVFG_CHANNEL_0;
|
||||
bool zeroCopyRequested = false;
|
||||
bool audioEnabled = false;
|
||||
GigabyteAudioInfo cachedAudioFormat{};
|
||||
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
@@ -890,14 +848,23 @@ struct gvfg_channel_session_t
|
||||
std::atomic<bool> running{false};
|
||||
std::mutex frameMutex;
|
||||
bool readInProgress = false;
|
||||
uint32_t heldOsdExperimentFlags = 0;
|
||||
gvfg_debug_osd_page_check_t heldOsdPageCheck{};
|
||||
bool frameHeld = false;
|
||||
bool heldFrameNeedsBackendRelease = false;
|
||||
uint64_t runGeneration = 0; // Protected by frameMutex; bumped by every successful start.
|
||||
uint64_t videoFrameId = 0;
|
||||
gvfg_frame_t heldSessionFrame{};
|
||||
gvfg::internal::GpuOsdProcessor osdProcessor;
|
||||
std::vector<uint8_t> processedVideoBuffer;
|
||||
std::mutex processorMutex;
|
||||
struct FrameProcessorState
|
||||
{
|
||||
const gvfg_frame_processor *ops = nullptr;
|
||||
void *context = nullptr;
|
||||
|
||||
~FrameProcessorState()
|
||||
{
|
||||
if (ops)
|
||||
ops->destroy(context);
|
||||
}
|
||||
} frameProcessor;
|
||||
std::mutex audioMutex;
|
||||
std::vector<uint8_t> audioBuffer;
|
||||
bool audioReadInProgress = false;
|
||||
@@ -954,7 +921,7 @@ struct gvfg_handle_t
|
||||
return channels[GVFG_CHANNEL_1].get();
|
||||
}
|
||||
|
||||
gvfg_status_t openChannel(int index, int channelIndex)
|
||||
gvfg_status_t openChannel(int index, int channelIndex, const std::wstring *requestedPath = nullptr)
|
||||
{
|
||||
if (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1)
|
||||
return GVFG_EINVAL;
|
||||
@@ -964,7 +931,8 @@ struct gvfg_handle_t
|
||||
channelErrors[slot].set("gvfg_open_channel rejected: device index is invalid");
|
||||
return GVFG_EINVAL;
|
||||
}
|
||||
if (currentIndex >= 0 && currentIndex != index)
|
||||
if (currentIndex >= 0 && (currentIndex != index ||
|
||||
(requestedPath && devicePath != *requestedPath)))
|
||||
{
|
||||
channelErrors[slot].set("gvfg_open_channel rejected: handle is already bound to another device");
|
||||
return GVFG_ESTATE;
|
||||
@@ -978,7 +946,7 @@ struct gvfg_handle_t
|
||||
|
||||
const gvfg_status_t status = channel->open(index,
|
||||
channelIndex,
|
||||
devicePath.empty() ? nullptr : &devicePath);
|
||||
devicePath.empty() ? requestedPath : &devicePath);
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
|
||||
@@ -1075,6 +1043,35 @@ struct gvfg_handle_t
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#ifdef GVFG_CAPTURE_TEST_RUNTIME
|
||||
int gvfg_test_enumerate_devices(gvfg_test_device_t *devices, int capacity)
|
||||
{
|
||||
if (!devices || capacity <= 0)
|
||||
return 0;
|
||||
int written = 0;
|
||||
for (const auto &device : enumerate_gigabyte_devices())
|
||||
{
|
||||
if (written == capacity)
|
||||
break;
|
||||
gvfg_test_device_t entry{};
|
||||
if (device.interface_path.empty() ||
|
||||
wcscpy_s(entry.interface_path, device.interface_path.c_str()) != 0)
|
||||
continue;
|
||||
wcsncpy_s(entry.name, device.friendly_name.c_str(), _TRUNCATE);
|
||||
devices[written++] = entry;
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_test_open_channel(gvfg_handle handle, const wchar_t *interface_path, int channel)
|
||||
{
|
||||
if (!handle || !interface_path || !*interface_path)
|
||||
return GVFG_EINVAL;
|
||||
const std::wstring path(interface_path);
|
||||
return handle->openChannel(0, channel, &path);
|
||||
}
|
||||
#endif
|
||||
|
||||
int gvfg_enumerate_devices(gvfg_device_info_t *out_devices, int max_devices)
|
||||
{
|
||||
const std::vector<gvfg::internal::GigabyteDevice> devices =
|
||||
@@ -1180,73 +1177,18 @@ extern "C"
|
||||
return handle->setChannelVideoFormat(channel_index, format);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_osd_fonts(gvfg_osd_font_list_t *out_list)
|
||||
{
|
||||
if (!out_list)
|
||||
return GVFG_EINVAL;
|
||||
*out_list = {};
|
||||
const auto status = gvfg_osd_get_fonts(&out_list->count, &out_list->names);
|
||||
return status == GVFG_OSD_OK ? GVFG_OK : GVFG_EIO;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_measure_osd_text(const gvfg_channel_osd_config_t *config,
|
||||
uint32_t *out_width, uint32_t *out_height)
|
||||
{
|
||||
if (out_width) *out_width = 0;
|
||||
if (out_height) *out_height = 0;
|
||||
if (!config || !config->text || !out_width || !out_height)
|
||||
return GVFG_EINVAL;
|
||||
const size_t length = strnlen_s(config->text, GVFG_OSD_MAX_TEXT_CHARACTERS + 1u);
|
||||
if (length == 0 || length > GVFG_OSD_MAX_TEXT_CHARACTERS)
|
||||
return GVFG_EINVAL;
|
||||
try
|
||||
{
|
||||
gvfg_osd_handle rawHandle = nullptr;
|
||||
if (gvfg_osd_create(&rawHandle) != GVFG_OSD_OK)
|
||||
return GVFG_EIO;
|
||||
const std::unique_ptr<void, decltype(&gvfg_osd_destroy)> helper(rawHandle, &gvfg_osd_destroy);
|
||||
const auto status = gvfg_osd_measure(helper.get(), config->text,
|
||||
static_cast<uint32_t>(length), config->font_size_px, config->font_family,
|
||||
out_width, out_height);
|
||||
return status == GVFG_OSD_OK ? GVFG_OK :
|
||||
status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO;
|
||||
}
|
||||
catch (...) { return GVFG_EIO; }
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_channel_osd(gvfg_handle handle, int channel_index,
|
||||
uint32_t osd_index, const gvfg_channel_osd_config_t *config)
|
||||
gvfg_status_t gvfg_control_frame_processor(
|
||||
gvfg_handle handle, int channel_index, const gvfg_frame_processor *processor,
|
||||
bool create, gvfg_frame_processor_control control, const void *argument,
|
||||
const char *error)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
if (!config || osd_index >= GVFG_OSD_SLOT_COUNT)
|
||||
return handle->rejectChannel(channel_index, GVFG_EINVAL, "OSD config or index is invalid");
|
||||
if (!control)
|
||||
return handle->rejectChannel(channel_index, GVFG_EINVAL, error);
|
||||
auto *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->setOsd(osd_index, *config)
|
||||
: handle->rejectChannel(channel_index, GVFG_ESTATE, "OSD channel is not open");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_channel_osd_visible(gvfg_handle handle, int channel_index,
|
||||
uint32_t osd_index, int visible)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
if (osd_index >= GVFG_OSD_SLOT_COUNT || (visible != 0 && visible != 1))
|
||||
return handle->rejectChannel(channel_index, GVFG_EINVAL, "OSD index or visibility is invalid");
|
||||
auto *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->setOsdVisible(osd_index, visible)
|
||||
: handle->rejectChannel(channel_index, GVFG_ESTATE, "OSD channel is not open");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_clear_channel_osd(gvfg_handle handle, int channel_index, uint32_t osd_index)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
if (osd_index >= GVFG_OSD_SLOT_COUNT)
|
||||
return handle->rejectChannel(channel_index, GVFG_EINVAL, "OSD index is invalid");
|
||||
auto *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->clearOsd(osd_index)
|
||||
: handle->rejectChannel(channel_index, GVFG_ESTATE, "OSD channel is not open");
|
||||
return channel ? channel->controlFrameProcessor(processor, create, control, argument, error)
|
||||
: handle->rejectChannel(channel_index, GVFG_ESTATE, "Frame processor channel is not open");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle,
|
||||
@@ -1329,32 +1271,6 @@ extern "C"
|
||||
"gvfg_debug_read_channel_frame_profiled rejected: channel is not open");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_get_channel_osd_experiment_flags(gvfg_handle handle,
|
||||
int channel_index,
|
||||
uint64_t frame_id,
|
||||
uint32_t *out_flags)
|
||||
{
|
||||
if (out_flags)
|
||||
*out_flags = 0;
|
||||
if (!handle || !out_flags)
|
||||
return GVFG_EINVAL;
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->osdExperimentFlags(frame_id, *out_flags) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_get_channel_osd_page_check(gvfg_handle handle,
|
||||
int channel_index,
|
||||
uint64_t frame_id,
|
||||
gvfg_debug_osd_page_check_t *out_check)
|
||||
{
|
||||
if (out_check)
|
||||
*out_check = {};
|
||||
if (!handle || !out_check)
|
||||
return GVFG_EINVAL;
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->osdPageCheck(frame_id, *out_check) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_release_channel_frame(gvfg_handle handle,
|
||||
int channel_index,
|
||||
const gvfg_frame_t *frame)
|
||||
@@ -1498,6 +1414,57 @@ extern "C"
|
||||
return channel->session->get_sdi_info(*out_info);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_channel_hdmi_info(
|
||||
gvfg_handle handle, int channel_index, gvfg_hdmi_info_t *out_info)
|
||||
{
|
||||
if (!handle || (channel_index != GVFG_CHANNEL_0 && channel_index != GVFG_CHANNEL_1))
|
||||
return GVFG_EINVAL;
|
||||
if (!out_info)
|
||||
return handle->rejectChannel(
|
||||
channel_index, GVFG_EINVAL,
|
||||
"gvfg_get_channel_hdmi_info rejected: out_info is null");
|
||||
*out_info = {};
|
||||
auto *channel = handle->findChannel(channel_index);
|
||||
if (!channel || !channel->session)
|
||||
return handle->rejectChannel(
|
||||
channel_index, GVFG_ESTATE,
|
||||
"gvfg_get_channel_hdmi_info rejected: channel is not open");
|
||||
return channel->session->get_hdmi_info(*out_info);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_channel_hdmi_audio_info(
|
||||
gvfg_handle handle, int channel_index, gvfg_hdmi_audio_info_t *out_info)
|
||||
{
|
||||
if (!handle || (channel_index != GVFG_CHANNEL_0 && channel_index != GVFG_CHANNEL_1))
|
||||
return GVFG_EINVAL;
|
||||
if (!out_info)
|
||||
return handle->rejectChannel(
|
||||
channel_index, GVFG_EINVAL,
|
||||
"gvfg_get_channel_hdmi_audio_info rejected: out_info is null");
|
||||
*out_info = {};
|
||||
auto *channel = handle->findChannel(channel_index);
|
||||
if (!channel || !channel->session)
|
||||
return handle->rejectChannel(
|
||||
channel_index, GVFG_ESTATE,
|
||||
"gvfg_get_channel_hdmi_audio_info rejected: channel is not open");
|
||||
return channel->session->get_hdmi_audio_info(*out_info);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_chip_info(gvfg_handle handle, gvfg_chip_info_t *out_info)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
if (!out_info)
|
||||
return handle->rejectAllChannels(GVFG_EINVAL,
|
||||
"gvfg_get_chip_info rejected: out_info is null");
|
||||
*out_info = {};
|
||||
auto *channel = handle->findOpenChannel();
|
||||
if (!channel || !channel->session)
|
||||
return handle->rejectAllChannels(GVFG_ESTATE,
|
||||
"gvfg_get_chip_info rejected: device is not open");
|
||||
return channel->session->get_chip_info(*out_info);
|
||||
}
|
||||
|
||||
const char *gvfg_get_version(void)
|
||||
{
|
||||
return GVFG_VERSION_STRING;
|
||||
@@ -1567,6 +1534,17 @@ extern "C"
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_set_user_led(gvfg_handle handle, int on)
|
||||
{
|
||||
if (!handle || (on != 0 && on != 1))
|
||||
return GVFG_EINVAL;
|
||||
auto *channel = handle->findOpenChannel();
|
||||
if (!channel || !channel->session)
|
||||
return handle->rejectAllChannels(GVFG_ESTATE,
|
||||
"gvfg_debug_set_user_led rejected: device is not open");
|
||||
return channel->session->set_user_led(on != 0);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_get_device_capabilities(
|
||||
gvfg_handle handle, gvfg_debug_device_capabilities_t *out_capabilities)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "gvfg_debug.h"
|
||||
|
||||
struct gvfg_frame_processor
|
||||
{
|
||||
gvfg_status_t (*create)(void **);
|
||||
void (*destroy)(void *);
|
||||
gvfg_status_t (*process)(void *, const gvfg_frame_t &, gvfg_frame_t &,
|
||||
bool &, gvfg_debug_osd_frame_timing_t *, uint8_t *,
|
||||
bool *);
|
||||
};
|
||||
|
||||
using gvfg_frame_processor_control = gvfg_status_t (*)(void *, const void *);
|
||||
|
||||
extern "C" GVFG_API gvfg_status_t gvfg_control_frame_processor(
|
||||
gvfg_handle handle, int channel, const gvfg_frame_processor *processor,
|
||||
bool create, gvfg_frame_processor_control control, const void *argument,
|
||||
const char *error);
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "gvfg_capture.h"
|
||||
|
||||
// Private interface compiled only into the capture-test runtime.
|
||||
struct gvfg_test_device_t
|
||||
{
|
||||
wchar_t interface_path[1024];
|
||||
wchar_t name[256];
|
||||
};
|
||||
|
||||
extern "C"
|
||||
{
|
||||
GVFG_API int gvfg_test_enumerate_devices(gvfg_test_device_t *devices, int capacity);
|
||||
GVFG_API gvfg_status_t gvfg_test_open_channel(gvfg_handle handle,
|
||||
const wchar_t *interface_path, int channel);
|
||||
}
|
||||
BIN
Binary file not shown.
+2
-3
@@ -3,10 +3,9 @@
|
||||
This directory contains the supervisor-provided static MSVC library used by the
|
||||
GVFG backend.
|
||||
|
||||
- Upstream version macro: `GVFG_SDK_VER 1.0.2`
|
||||
- Upstream version macro: `GVFG_SDK_VER 1.0.4`
|
||||
- Library: `GvfgSdk.lib`
|
||||
- SHA-256: `EC9577D4BE76861E44DFDD3B537DF2A57CCDA5A5F1B14E0BAAC92213E796A743`
|
||||
- Original source: `ex_demo/GigabyteLib/vfg100_0914_b`
|
||||
- SHA-256: `0BE490FB11C4509716B1281F4EE6E5D5793FB6938C432D2A5619088F26F720BF`
|
||||
|
||||
`GvfgSdk.lib` is linked into `gvfg.dll`; it is not distributed as a separate
|
||||
customer runtime dependency. The supplied package did not contain source,
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ extern "C" {
|
||||
#define GVFG_PARAM_OUT
|
||||
|
||||
#define GVFG_SDK_API
|
||||
#define GVFG_SDK_VER "1.0.3"
|
||||
#define GVFG_SDK_VER "1.0.5"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+227
-1
@@ -42,6 +42,93 @@ extern "C" {
|
||||
|
||||
typedef struct _GVFG_CONTEXT GVFG_CONTEXT, *PGVFG_CONTEXT;
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// HDMI Audio Format
|
||||
|
||||
GVFG_HDMI_AUD_FMT_LINEAR_PCM = 1,
|
||||
GVFG_HDMI_AUD_FMT_AC3 = 2,
|
||||
GVFG_HDMI_AUD_FMT_MPEG1 = 3,
|
||||
GVFG_HDMI_AUD_FMT_MP3 = 4,
|
||||
GVFG_HDMI_AUD_FMT_MPEG2 = 5,
|
||||
GVFG_HDMI_AUD_FMT_AAC = 6,
|
||||
GVFG_HDMI_AUD_FMT_DTS = 7,
|
||||
GVFG_HDMI_AUD_FMT_ATRAC = 8,
|
||||
GVFG_HDMI_AUD_FMT_ONE_BIT_HDMI_AUDIO = 9,
|
||||
GVFG_HDMI_AUD_FMT_DOLBY_DIGITAL = 10,
|
||||
GVFG_HDMI_AUD_FMT_DTS_HD = 11,
|
||||
GVFG_HDMI_AUD_FMT_MAT = 12,
|
||||
GVFG_HDMI_AUD_FMT_DST = 13,
|
||||
GVFG_HDMI_AUD_FMT_WMA_PRO = 14,
|
||||
GVFG_HDMI_AUD_FMT_ID_MAX_SIZE = 15,
|
||||
GVFG_HDMI_AUD_FMT_COMPRESSED_AUDIO = 0xff
|
||||
|
||||
} GVFG_HDMI_AUDIO_FORMAT;
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// HDMI Audio Sampling Frequencey
|
||||
|
||||
GVFG_HDMI_AUD_FREQ_32KHZ = 0,
|
||||
GVFG_HDMI_AUD_FREQ_44KHZ = 1,
|
||||
GVFG_HDMI_AUD_FREQ_48KHZ = 2,
|
||||
GVFG_HDMI_AUD_FREQ_88KHZ = 3,
|
||||
GVFG_HDMI_AUD_FREQ_96KHZ = 4,
|
||||
GVFG_HDMI_AUD_FREQ_176KHZ = 5,
|
||||
GVFG_HDMI_AUD_FREQ_192KHZ = 6,
|
||||
GVFG_HDMI_AUD_FREQ_HBR = 7,
|
||||
GVFG_HDMI_AUD_FREQ_FROM_STRM = 8
|
||||
|
||||
} GVFG_HDMI_AUDIO_SAMPLE_FREQ;
|
||||
|
||||
|
||||
|
||||
// HDMI Video color format
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_HDMI_CS_DEFAULT_RGB = (0<<6)+0, // 0x00 */
|
||||
GVFG_HDMI_CS_RGB = (2<<6)+0, // 0x80 */
|
||||
GVFG_HDMI_CS_YUV_601 = (1<<6)+1, // 0x41 */
|
||||
GVFG_HDMI_CS_YUV_709 = (1<<6)+2, // 0x42 */
|
||||
GVFG_HDMI_CS_YCC_601 = (1<<6)+3+(0<<2), // 0x43 */
|
||||
GVFG_HDMI_CS_YCC_709 = (1<<6)+3+(1<<2), // 0x47 */
|
||||
GVFG_HDMI_CS_SYCC_601 = (1<<6)+3+(2<<2), // 0x4B */
|
||||
GVFG_HDMI_CS_ADOBE_YCC_601 = (1<<6)+3+(3<<2), // 0x4F */
|
||||
GVFG_HDMI_CS_ADOBE_RGB = (1<<6)+3+(4<<2), // 0x53 */
|
||||
GVFG_HDMI_CS_BT2020_YCC = (1<<6)+3+(5<<2), // 0x57 */
|
||||
GVFG_HDMI_CS_BT2020_RGB = (1<<6)+3+(6<<2), // 0x5B */
|
||||
GVFG_HDMI_CS_LIM_RGB = (1<<6)+0, // 0x40 */
|
||||
GVFG_HDMI_CS_LIM_YUV_601 = (0<<6)+1, // 0x01 */
|
||||
GVFG_HDMI_CS_LIM_YUV_709 = (0<<6)+2, // 0x02 */
|
||||
GVFG_HDMI_CS_LIM_YCC_601 = (0<<6)+3+(0<<2), // 0x03 */
|
||||
GVFG_HDMI_CS_LIM_YCC_709 = (0<<6)+3+(1<<2), // 0x07 */
|
||||
GVFG_HDMI_CS_LIM_SYCC_601 = (0<<6)+3+(2<<2), // 0x0B */
|
||||
GVFG_HDMI_CS_LIM_ADOBE_YCC_601 = (0<<6)+3+(3<<2), // 0x0F */
|
||||
GVFG_HDMI_CS_LIM_ADOBE_RGB = (0<<6)+3+(4<<2), // 0x13 */
|
||||
GVFG_HDMI_CS_LIM_BT2020_YCC = (0<<6)+3+(5<<2), // 0x17 */
|
||||
GVFG_HDMI_CS_LIM_BT2020_RGB = (0<<6)+3+(6<<2), // 0x1B */
|
||||
GVFG_HDMI_CS_AUTO = 255
|
||||
|
||||
} GVFG_HDMI_VIDEO_CS;
|
||||
|
||||
// HDMI Video color space
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_HDMI_CF_RGB = 0,
|
||||
GVFG_HDMI_CF_YUV_422 = 1,
|
||||
GVFG_HDMI_CF_YUV_444 = 2,
|
||||
GVFG_HDMI_CF_YUV_420 = 3,
|
||||
GVFG_HDMI_CF_INVALID = 15
|
||||
|
||||
} GVFG_HDMI_VIDEO_CF;
|
||||
|
||||
|
||||
|
||||
// SDK API return code.
|
||||
|
||||
@@ -100,6 +187,22 @@ typedef enum GVFG_HRESULT {
|
||||
((ULONG)(UCHAR)(ch3) << 24))
|
||||
|
||||
|
||||
/* GvfgGetChipInfo(...) parameter.
|
||||
*
|
||||
* Chip version information
|
||||
*/
|
||||
|
||||
typedef struct _GVFG_CHIP_INFO {
|
||||
|
||||
// Data are in hex representation.
|
||||
// For example, VerDate: 0x20161115 is 2026/11/15
|
||||
|
||||
UINT32 VerDate; // YearMonthDate
|
||||
UINT32 VerTime; // HourMinuteSecond
|
||||
|
||||
} GVFG_CHIP_INFO, *PGVFG_CHIP_INFO;
|
||||
|
||||
|
||||
/* GvfgGetDevInfo(...) parameter.
|
||||
*
|
||||
* Device information
|
||||
@@ -270,6 +373,37 @@ typedef struct _GVFG_SDI_VIDEO_INFO_STR {
|
||||
|
||||
|
||||
|
||||
typedef struct _GVFG_HDMI_VIDEO_INPUT_INFO {
|
||||
|
||||
UINT32 VideoSignalLock; // 0: signal is not locked.
|
||||
// 1: signal is locked.
|
||||
|
||||
UINT32 Width; // pixels
|
||||
UINT32 Height; // pixels
|
||||
UINT32 Fps;
|
||||
|
||||
UINT32 ColorFormat; // GVFG_HDMI_VIDEO_CF;
|
||||
UINT32 ColorSpace; // GVFG_HDMI_VIDEO_CS
|
||||
UINT32 BitsPerPixel; // Color Depth: 8, 10, 12
|
||||
|
||||
} GVFG_HDMI_VIDEO_INPUT_INFO, *PGVFG_HDMI_VIDEO_INPUT_INFO;
|
||||
|
||||
|
||||
typedef struct _GVFG_HDMI_AUDIO_INPUT_INFO {
|
||||
|
||||
UINT32 AudioSignalLock; // 0: signal is not locked.
|
||||
// 1: signal is locked.
|
||||
|
||||
UINT16 SamplesPerSec; // GVFG_HDMI_AUDIO_SAMPLE_FREQ
|
||||
UINT16 BitsPerSample; // 16 or 24
|
||||
UINT16 Channels; // number of channels
|
||||
|
||||
UINT16 Format; // GVFG_HDMI_AUDIO_FORMAT
|
||||
|
||||
|
||||
} GVFG_HDMI_AUDIO_INPUT_INFO, *PGVFG_HDMI_AUDIO_INPUT_INFO;
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTION: Create events notify handles.
|
||||
* PURPOSE: Driver uses these handles to notify user active events.
|
||||
@@ -355,6 +489,26 @@ GVFG_SDK_API GVFG_HRESULT GvfgOpenDev(GVFG_PARAM_IN HANDLE hDev,
|
||||
*********************************************************************/
|
||||
GVFG_SDK_API GVFG_HRESULT GvfgCloseDev(GVFG_PARAM_IN PGVFG_CONTEXT *pCxt);
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTION: Get Gigabyte chip information.
|
||||
*
|
||||
*
|
||||
* PURPOSE: Get the chip's version in timestamp format
|
||||
*
|
||||
* PARAMS: pCxt - Gigabyte device context.
|
||||
* Device context created by the GvfgOpenDev(...).
|
||||
*
|
||||
* pChipInfo - Chip information.
|
||||
*
|
||||
* RETURNS: GVFG_HRESULT_OK: success.
|
||||
* other: failure.
|
||||
*
|
||||
*********************************************************************/
|
||||
GVFG_SDK_API GVFG_HRESULT GvfgGetChipInfo(GVFG_PARAM_IN PGVFG_CONTEXT pCxt,
|
||||
GVFG_PARAM_OUT PGVFG_CHIP_INFO pChipInfo);
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTION: Get Gigabyte device information.
|
||||
@@ -736,7 +890,79 @@ GVFG_SDK_API GVFG_HRESULT GvfgSetVideoColorDepth(GVFG_PARAM_IN PGVFG_CONTEXT pCx
|
||||
GVFG_PARAM_IN ULONG videoChn,
|
||||
GVFG_PARAM_IN ULONG colorDepth);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTION: Get HDMI video interface information.
|
||||
*
|
||||
*
|
||||
* PURPOSE: This is the video input information, decoding from the HDMI payload stream.
|
||||
*
|
||||
* PARAMS: pCxt - Gigabyte device context.
|
||||
* Device context created by the GvfgOpenDev(...)
|
||||
*
|
||||
* videoChn - video channel index.
|
||||
*
|
||||
* pHdmiInfo - HDMI video input information.
|
||||
*
|
||||
*
|
||||
* RETURNS: GVFG_HRESULT_OK: success.
|
||||
* other: failure.
|
||||
*
|
||||
* Note : It may take upto 100 ms to execute.
|
||||
*
|
||||
*********************************************************************/
|
||||
GVFG_SDK_API GVFG_HRESULT GvfgGetHdmiVideoInputInfo(GVFG_PARAM_IN PGVFG_CONTEXT pCxt,
|
||||
GVFG_PARAM_IN ULONG videoChn,
|
||||
GVFG_PARAM_OUT PGVFG_HDMI_VIDEO_INPUT_INFO pHdmiInfo);
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTION: Get HDMI interface audio information.
|
||||
*
|
||||
*
|
||||
* PURPOSE: This is the HDMI video input information, decoding from the HDMI audio payload stream.
|
||||
*
|
||||
* PARAMS: pCxt - Gigabyte device context.
|
||||
* Device context created by the GvfgOpenDev(...)
|
||||
*
|
||||
* videoChn - video channel index.
|
||||
*
|
||||
* pHdmiInfo - HDMI audio input information.
|
||||
*
|
||||
*
|
||||
* RETURNS: GVFG_HRESULT_OK: success.
|
||||
* other: failure.
|
||||
*
|
||||
* Note : It may take upto 100 ms to execute.
|
||||
*
|
||||
*********************************************************************/
|
||||
GVFG_SDK_API GVFG_HRESULT GvfgGetHdmiAudioInputInfo(GVFG_PARAM_IN PGVFG_CONTEXT pCxt,
|
||||
GVFG_PARAM_IN ULONG videoChn,
|
||||
GVFG_PARAM_OUT PGVFG_HDMI_AUDIO_INPUT_INFO pHdmiAudioInfo);
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTION: Set user LED ON/OFF
|
||||
*
|
||||
*
|
||||
* PURPOSE: This is a LED for user to control.
|
||||
*
|
||||
* PARAMS: pCxt - Gigabyte device context.
|
||||
* Device context created by the GvfgOpenDev(...)
|
||||
*
|
||||
* On - 1: Led on, 0: LED off
|
||||
*
|
||||
*
|
||||
* RETURNS: GVFG_HRESULT_OK: success.
|
||||
* other: failure.
|
||||
*
|
||||
*********************************************************************/
|
||||
GVFG_SDK_API GVFG_HRESULT GvfgSetLed(GVFG_PARAM_IN PGVFG_CONTEXT pCxt, GVFG_PARAM_IN ULONG On);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -53,8 +53,6 @@ Demo 從 [獨立專案目錄](../Costomer_SDK_Release/GVFG_Customer_Sample/READM
|
||||
```text
|
||||
include/gvfg_capture.h
|
||||
include/gvfg_playback.h
|
||||
include/gvfg_preview.h
|
||||
include/gvfg_audio_playback.h
|
||||
bin/gvfg.dll
|
||||
bin/gvfg_playback.dll
|
||||
lib/gvfg.lib
|
||||
|
||||
+120
-62
@@ -1,11 +1,11 @@
|
||||
# GVFG 客戶 API 使用手冊
|
||||
|
||||
本文件說明 SDK 3.0.0 的公開擷取介面 `gvfg_capture.h`。
|
||||
本文件說明 SDK 3.1.0 的公開擷取介面 `gvfg_capture.h`。
|
||||
影像/音訊/同步播放另使用 `gvfg_playback.h`,完整流程見
|
||||
[統一影音播放使用手冊](GVFG_PLAYBACK_API.md)。Capture 與 Playback 是不同 handle 與 DLL。
|
||||
|
||||
客戶套件不應包含 `gvfg_debug.h`、`sdk/gvfg/src/`、driver IOCTL、FPGA
|
||||
register、IRQ 或 DMA ring 實作細節。
|
||||
先依下列流程完成擷取整合;逐參數定義與完整限制見
|
||||
[API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
|
||||
|
||||
## 1. 套件內容
|
||||
|
||||
@@ -17,15 +17,12 @@ lib/gvfg.lib
|
||||
bin/gvfg.dll
|
||||
```
|
||||
|
||||
Application 只 link `gvfg.lib`。內部 Gigabyte library 已靜態連結進
|
||||
`gvfg.dll`,不需要部署 `giga_ioctl.dll` 或額外公開 private header。
|
||||
核心擷取只需連結 `gvfg.lib`,並部署相同版本的 `gvfg.dll`。
|
||||
|
||||
選用播放(純影像、純音訊或影音):
|
||||
|
||||
```text
|
||||
include/gvfg_playback.h
|
||||
include/gvfg_preview.h
|
||||
include/gvfg_audio_playback.h
|
||||
lib/gvfg_playback.lib
|
||||
bin/gvfg_playback.dll
|
||||
```
|
||||
@@ -106,7 +103,7 @@ int main(void)
|
||||
Pointer 只在對應的 `gvfg_release_channel_frame()` 前有效,資料若要長期保存,必須先複製。
|
||||
- 每個 channel 同時最多持有一個 frame。尚未 release 又對同一 channel 呼叫
|
||||
`gvfg_read_channel_frame()`,會回傳 `GVFG_ESTATE`。
|
||||
- release 時傳回 read 取得的 `gvfg_frame_t`;SDK 以 `data + frame_id` 確認目前 held frame。
|
||||
- release 時傳回 read 取得的 `gvfg_frame_t`;不要自行修改 frame descriptor 的內容。
|
||||
- `gvfg_stop()` 會中止等待並使尚未 release 的 frame 失效。
|
||||
- 同一個 handle 的 lifecycle 操作應由應用程式自行序列化;不要同時 open、
|
||||
start、stop 或 destroy。
|
||||
@@ -118,7 +115,7 @@ Audio 採用相同的 pull 與 ownership 模型:
|
||||
`gvfg_release_channel_audio_frame()` 前有效。
|
||||
- 同一 channel 同時只能持有一個 audio frame;未 release 再 read 會回傳
|
||||
`GVFG_ESTATE`。
|
||||
- release 時傳回 read 取得的 `gvfg_audio_frame_t`;SDK 以 `data + frame_id` 確認目前 held frame。
|
||||
- release 時傳回 read 取得的 `gvfg_audio_frame_t`;不要自行修改 frame descriptor 的內容。
|
||||
- 若播放或錄音需要在 release 後繼續使用 PCM,Application 必須先複製。
|
||||
- Capture 保有自己的交付 buffer;播放副本、queue、同步與輸出由 Playback 管理。
|
||||
- 使用 Playback 時,submit 已完成複製後即可 release,Demo 不自行實作音訊調速或同步。
|
||||
@@ -136,7 +133,7 @@ Audio 採用相同的 pull 與 ownership 模型:
|
||||
| `GVFG_EINVAL` | 參數、channel 或 frame token 無效 |
|
||||
| `GVFG_ENODEV` | 找不到裝置或裝置無法開啟 |
|
||||
| `GVFG_ESTATE` | 呼叫時機或 handle 狀態不正確 |
|
||||
| `GVFG_EIO` | SDK/backend I/O、GPU 或 internal extension 失敗 |
|
||||
| `GVFG_EIO` | 擷取、轉換或其他 I/O 失敗 |
|
||||
| `GVFG_ENOTSUP` | 格式或功能不支援 |
|
||||
| `GVFG_ETIMEOUT` | 等待逾時 |
|
||||
| `GVFG_EBUSY` | 裝置或 capture resource 正在使用中 |
|
||||
@@ -148,10 +145,9 @@ Windows `FAILED()`/`SUCCEEDED()`。
|
||||
可用 `gvfg_strerror()` 取得靜態英文說明字串;呼叫端不可釋放該字串。
|
||||
|
||||
可用 `gvfg_get_version()` 查詢目前實際載入的 `gvfg.dll` 版本。回傳值為
|
||||
靜態字串,例如 `"1.0.0"`,呼叫端不可釋放。
|
||||
靜態字串,例如 `"3.1.0"`,呼叫端不可釋放。
|
||||
需要記錄最近一次失敗的詳細原因時,可在 API 失敗後立即呼叫
|
||||
`gvfg_get_channel_last_sdk_error_detail()`。此 API 只提供不含底層 library 名稱與原始錯誤碼的
|
||||
公開診斷文字;library、driver、register 等實作資訊只保留在未隨客戶套件交付的 debug API。
|
||||
`gvfg_get_channel_last_sdk_error_detail()`。此 API 回傳可供問題回報使用的公開診斷文字。
|
||||
|
||||
## 5. 資料格式
|
||||
|
||||
@@ -213,7 +209,7 @@ audio API 不是 zero-copy,但上層仍使用和 video 相同的 read/release
|
||||
- `gvfg_stop(handle)`:停止擷取;重複呼叫仍回傳成功。
|
||||
- `gvfg_destroy(handle)`:必要時先停止,再銷毀 handle。銷毀後不得再使用。
|
||||
|
||||
Zero-copy mode 的 driver lifecycle 由 SDK 管理:open 時 enable,destroy/close 前 disable。
|
||||
Zero-copy 模式必須在 channel open 前選擇;要切換模式時,先銷毀並重新建立 session。
|
||||
每次成功 `gvfg_read_channel_frame()` 後仍須呼叫 `gvfg_release_channel_frame()`,用來結束
|
||||
公開 pointer/token lifetime;依目前 Lib 契約不送逐 frame driver release。Device open 後
|
||||
不可直接切換;應 destroy session、重新 create、設定模式後再 open。
|
||||
@@ -226,58 +222,85 @@ Zero-copy mode 的 driver lifecycle 由 SDK 管理:open 時 enable,destroy/c
|
||||
|
||||
### SDK OSD
|
||||
|
||||
每個已 open 的 channel 支援兩組獨立 OSD,`osd_index` 為 `0` 或 `1`;
|
||||
重疊時第 `1` 組蓋在第 `0` 組上。後續 `gvfg_read_channel_frame()` 交付含 OSD 的
|
||||
YUY2/Y210 frame,使用後照常 release。
|
||||
使用 OSD 時請包含 `gvfg_osd.h`,連結 `gvfg_osd.lib`(MinGW 使用 `libgvfg_osd.dll.a`),並隨應用程式部署同一次 SDK 建置的 `gvfg_osd.dll` 和 `gvfg.dll`。一般擷取只需連結 `gvfg.dll` 對應的 import library。
|
||||
|
||||
- `gvfg_get_osd_fonts(&list)`:重新檢查 Windows 已安裝字型,取得當前可用家族名稱。
|
||||
不需要 handle、callback 或客戶端 free。`list.count` 是數量,`list.names[i]` 是 UTF-8 名稱。
|
||||
清單由 SDK 管理,指標有效到下一次呼叫此函式(包含失敗呼叫)或 DLL 卸載為止;
|
||||
填入 UI 或長期保存時自行複製。呼叫及讀取借用清單須由 caller 序列化。
|
||||
- `gvfg_measure_osd_text(&config, &width, &height)`:使用設定中的文字、字型與大小量測;
|
||||
忽略位置與顏色,不需要開啟裝置。
|
||||
- `gvfg_set_channel_osd(handle, channel, osd_index, &config)`:設定並顯示一組 OSD。
|
||||
函式返回前同步複製文字與字型名稱;設定失敗保留該組原設定。
|
||||
- `gvfg_set_channel_osd_visible(handle, channel, osd_index, visible)`:`0` 隱藏、`1` 顯示。
|
||||
保留設定、YUV 字圖、Mask 與 GPU 資源;單純 Hide/Show 不重新產生字圖。
|
||||
影像尺寸或格式改變仍可能更新資源。尚未設定或已清除的組別不能直接 Show。
|
||||
- `gvfg_clear_channel_osd(handle, channel, osd_index)`:停用該組並清除設定與字圖快取;
|
||||
後續須重新 Set 才能顯示,不影響另一組。
|
||||
每個已 open 的 channel 可設定兩組 OSD,`osd_index` 為 `0`、`1`;重疊時第 `1` 組在上方。
|
||||
OSD 會加入後續取得的 YUY2/Y210 frame,preview、snapshot 或錄影是否顯示 OSD,
|
||||
取決於它們是否使用這份 frame。
|
||||
|
||||
`gvfg_channel_osd_config_t` 沒有 `struct_size` 或 `text_length`,欄位順序為:
|
||||
1. 呼叫 `gvfg_get_osd_fonts(&list)`,取得可用字型,將選到的 UTF-8 名稱複製保存。
|
||||
客戶可先在 Windows 安裝新字型,再重新取得清單。SDK 管理清單,不需 callback 或 free;
|
||||
指標有效到下一次清單查詢或 DLL 卸載,查詢與讀取清單須由 caller 序列化。
|
||||
2. 填寫 `gvfg_channel_osd_config_t`:文字、`font_family`、大小、顏色與 `x/y`。
|
||||
`text` 是 NUL 結尾的 1–32 個可列印 ASCII 字元,不接受中文或換行;
|
||||
字型名稱是 NUL 結尾的 UTF-8 字串,不是檔案路徑。字號必須大於 0。
|
||||
3. 用 `gvfg_measure_osd_text(&config, &width, &height)` 量測,再呼叫
|
||||
`gvfg_set_channel_osd(handle, channel, osd_index, &config)` 設定並顯示該組。
|
||||
Set 返回前已複製字串,caller 不必持續保存原設定字串。
|
||||
4. 暫時不顯示時,呼叫 `gvfg_set_channel_osd_visible(..., 0)`;恢復使用 `1`。
|
||||
Hide/Show 保留該組設定;`gvfg_clear_channel_osd()` 才清除該組,之後須重新 Set。
|
||||
|
||||
```c
|
||||
const char *text; /* NUL 結尾,1–32 個可列印 ASCII 字元 */
|
||||
const char *font_family; /* NUL 結尾的 UTF-8 字型家族名稱,不是檔案路徑 */
|
||||
uint32_t font_size_px; /* 大於 0 */
|
||||
uint32_t color_rgb; /* 0x00RRGGBB */
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
`x/y` 是量測文字框左上角;位置會限制在影像內。文字框本身放不下時,該組暫停顯示,
|
||||
另一組與擷取繼續;文字或影像尺寸調整後可恢復。不自動縮字、截字或換行。
|
||||
無效字型/文字/組別回傳 `GVFG_EINVAL`;尚未設定的組別不能直接 Show。
|
||||
SDK handle 銷毀後,應用程式需自行保存並重設所需的 OSD 設定。
|
||||
|
||||
完整欄位、字級定義、回傳值與限制見
|
||||
[API Reference:OSD](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md#226-osd-字型設定顯示隱藏與清除)。
|
||||
|
||||
### OSD 呼叫範例
|
||||
|
||||
以下 C++ 範例假設 `handle` 的 `channel` 已 open。先選擇清單中的實際字型,
|
||||
立即複製名稱,再使用相同設定量測與繪製;每一步都檢查回傳值。
|
||||
|
||||
```cpp
|
||||
#include <gvfg_capture.h>
|
||||
#include <string>
|
||||
|
||||
gvfg_status_t configure_osd(gvfg_handle handle, int channel)
|
||||
{
|
||||
gvfg_osd_font_list_t fonts{};
|
||||
auto status = gvfg_get_osd_fonts(&fonts);
|
||||
if (status != GVFG_OK) return status;
|
||||
if (fonts.count == 0) return GVFG_EINVAL;
|
||||
const std::string family(fonts.names[0]);
|
||||
|
||||
gvfg_channel_osd_config_t first{};
|
||||
first.text = "CAMERA 01";
|
||||
first.font_family = family.c_str();
|
||||
first.font_size_px = 48;
|
||||
first.color_rgb = 0xffffff;
|
||||
first.x = 32;
|
||||
first.y = 32;
|
||||
|
||||
// Measurement uses text, font and size; it does not open a device.
|
||||
uint32_t width = 0, height = 0;
|
||||
status = gvfg_measure_osd_text(&first, &width, &height);
|
||||
if (status != GVFG_OK) return status;
|
||||
status = gvfg_set_channel_osd(handle, channel, 0, &first);
|
||||
if (status != GVFG_OK) return status;
|
||||
|
||||
auto second = first;
|
||||
second.text = "ROOM 02";
|
||||
second.font_size_px = 32;
|
||||
second.color_rgb = 0xffff00;
|
||||
second.y = 120;
|
||||
return gvfg_set_channel_osd(handle, channel, 1, &second);
|
||||
}
|
||||
```
|
||||
|
||||
客戶先在 Windows 安裝字型,再重新取得清單,將選到的名稱放入 `font_family`。
|
||||
只下載但未安裝的字型不會自動列入。字型名稱可為 UTF-8,但 OSD 文字仍只接受
|
||||
ASCII `0x20`–`0x7e`,不接受中文或換行。清單中的字型不保證含有所有語言的字元。
|
||||
不存在的字型或無效 UTF-8 名稱回傳 `GVFG_EINVAL`,不靜默改用 Arial。
|
||||
Set 返回前已複製字串,函式內的 `family` 可正常離開作用域。兩次 Set 各自生效;
|
||||
若第二次失敗,第一組仍保持成功設定。下列是之後對第二組的三個獨立操作範例,
|
||||
並非必須連續執行的初始化步驟;每個結果仍須檢查。
|
||||
|
||||
字型為 normal weight/style/stretch。字級傳給 DirectWrite 的 em 大小,繪製目標固定
|
||||
96 DPI,因此數值可對應影像像素;不是 Word 的 pt,也不是字形實際墨色高度。
|
||||
SDK 沒有 viewer 的 512 px UI 上限。顏色轉為 BT.709 limited range,由 GPU 混合。
|
||||
|
||||
量測框包含排版空白、glyph overhang 及四邊各 1 px 安全邊,不是 pixel-tight 邊界。
|
||||
`x/y` 是該框左上角,SDK 依每張影像限制位置,使完整文字框留在影像內。
|
||||
某組文字框比影像大時,只暫停疊該組;擷取及另一組繼續。設定、尺寸或格式改變後
|
||||
重新判斷,可容納時恢復,不縮字、截字或換行。
|
||||
|
||||
量測失敗時可寫入的尺寸 output 歸零。無效參數、文字、字號、字型或組別回傳
|
||||
`GVFG_EINVAL`;channel 未 open 或要求顯示未設定的組別回傳 `GVFG_ESTATE`;
|
||||
其他初始化、量測或資源失敗回傳 `GVFG_EIO`。設定成功不表示已取得的 frame 會被修改。
|
||||
SDK 不跨 `gvfg_destroy()` 保留設定;viewer 自行保存兩組設定及 visibility,於重新 Start 時還原。
|
||||
|
||||
這次是 breaking API 更新:客戶須使用同一版本的 header、import library 與 DLL 重新編譯。
|
||||
|
||||
SDK 本身不提供固定角落的預設位置;呼叫端明確傳入 `x/y`。`srcroot` Viewer 的
|
||||
OSD 1 預設 `(32, 32)`、OSD 2 預設右下角屬於 APP 行為,不是 SDK 自動錨定規則。
|
||||
```cpp
|
||||
auto status = gvfg_set_channel_osd_visible(handle, channel, 1, 0); // Hide
|
||||
if (status != GVFG_OK) return status;
|
||||
status = gvfg_set_channel_osd_visible(handle, channel, 1, 1); // Show
|
||||
if (status != GVFG_OK) return status;
|
||||
status = gvfg_clear_channel_osd(handle, channel, 1); // Clear
|
||||
if (status != GVFG_OK) return status;
|
||||
```
|
||||
|
||||
### SDK 3.0.0 介面遷移
|
||||
|
||||
@@ -285,8 +308,9 @@ OSD 1 預設 `(32, 32)`、OSD 2 預設右下角屬於 APP 行為,不是 SDK
|
||||
- `gvfg_channel_osd_config_t` 改用 NUL 結尾字串、移除 `text_length`,新增 `font_family`;
|
||||
量測函式改收同一份設定,沒有舊版相容入口。
|
||||
- 公開 Playback 移除 `gvfg_playback_stats_t` 與 `gvfg_playback_get_stats()`。
|
||||
仍可查詢公開 preview/delivery 統計;詳細核心診斷改為私有的 Debug-only 介面,
|
||||
不屬於客戶 API,也不提供 Release 匯出或穩定 ABI。
|
||||
一般顯示資訊與呈現統計改用 `gvfg_playback_get_preview_info()`、`gvfg_playback_get_preview_stats()`。
|
||||
- 公開 Playback 另移除 `gvfg_preview_delivery_stats_t` 與 `gvfg_playback_get_delivery_stats()`;
|
||||
詳細佇列與呈現流程計數移至內部 Debug API,不提供公開相容入口。
|
||||
- 字型清單不需要 capture handle。先選擇實際已安裝的字型,再量測/設定 OSD,
|
||||
並檢查每次 API 回傳值。單一組別的 Set 不提供兩組一起更新的交易保證。
|
||||
|
||||
@@ -356,6 +380,40 @@ plane;使用 BT.709 limited range。
|
||||
- `gvfg_gpu_convert_to_rgb10a2()`
|
||||
- `gvfg_gpu_convert_to_nv12()`
|
||||
|
||||
### GPU 轉換範例
|
||||
|
||||
例如,要建立一個與輸入 frame 同尺寸的 BGRA8 destination:
|
||||
以下片段放在回傳 `gvfg_status_t` 的函式內,使用 `<limits.h>`、`<stdint.h>`、`<stdlib.h>`;
|
||||
`source` 必須有效,且尚未 release。
|
||||
|
||||
```c
|
||||
if (source.width <= 0 || source.height <= 0 || source.width > INT_MAX / 4)
|
||||
return GVFG_EINVAL;
|
||||
const int row_bytes = source.width * 4;
|
||||
const uint64_t buffer_size = (uint64_t)row_bytes * (uint64_t)source.height;
|
||||
if (buffer_size > SIZE_MAX)
|
||||
return GVFG_EINVAL;
|
||||
void *pixels = malloc((size_t)buffer_size);
|
||||
if (!pixels)
|
||||
return GVFG_EIO;
|
||||
|
||||
gvfg_gpu_output_buffer_t output = {0};
|
||||
output.data = pixels;
|
||||
output.data_size = buffer_size;
|
||||
output.row_bytes = row_bytes;
|
||||
output.pixel_format = GVFG_GPU_OUTPUT_BGRA8;
|
||||
|
||||
gvfg_status_t status = gvfg_gpu_convert_to_buffer(&source, &output);
|
||||
if (status == GVFG_OK) {
|
||||
/* 在這裡使用 pixels。 */
|
||||
}
|
||||
free(pixels);
|
||||
return status;
|
||||
```
|
||||
|
||||
配置前須確認尺寸乘法不會 overflow,並檢查 `malloc()` 是否成功。
|
||||
不論 conversion 成功或失敗,呼叫端都需在不再使用輸出時釋放自行配置的 `pixels`。
|
||||
|
||||
## 8. 播放 API
|
||||
|
||||
`gvfg_playback.dll` 提供影像、音訊播放與影音同步功能。
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# GVFG 客戶 API Reference
|
||||
|
||||
SDK 3.0.0。Capture 與 Playback 使用各自的 API 與狀態碼。
|
||||
SDK 3.1.0。Capture 與 Playback 使用各自的 API 與狀態碼。
|
||||
|
||||
本版含不相容的 OSD 介面更新,並移除公開的 Playback 核心詳細統計查詢。
|
||||
本版含不相容的 OSD 介面更新,並移除公開的 Playback 核心與 Preview delivery 詳細統計查詢。
|
||||
使用本版 header、import library 與 DLL 重新編譯;不可混用 SDK 2.x 二進位檔案。
|
||||
|
||||
- [擷取型別與常數](#1-gvfg-api-結構與常數)
|
||||
@@ -228,24 +228,8 @@ Video/audio 的 `timestamp_ns` 可在同一 process/session 內直接比較。
|
||||
| `row_bytes` | `int` | Destination stride;NV12 的 Y/UV plane 共用此 stride |
|
||||
| `pixel_format` | `int` | 要求的 `gvfg_gpu_output_format_t` 值 |
|
||||
|
||||
例如,要建立一個與輸入 frame 同尺寸的 BGRA8 destination:
|
||||
|
||||
```c
|
||||
const int row_bytes = source.width * 4;
|
||||
const uint64_t buffer_size = (uint64_t)row_bytes * (uint64_t)source.height;
|
||||
void *pixels = malloc((size_t)buffer_size);
|
||||
|
||||
gvfg_gpu_output_buffer_t output = {0};
|
||||
output.data = pixels;
|
||||
output.data_size = buffer_size;
|
||||
output.row_bytes = row_bytes;
|
||||
output.pixel_format = GVFG_GPU_OUTPUT_BGRA8;
|
||||
|
||||
gvfg_status_t status = gvfg_gpu_convert_to_buffer(&source, &output);
|
||||
/* 使用 pixels 後由 caller 呼叫 free(pixels)。 */
|
||||
```
|
||||
|
||||
Caller 必須確認尺寸乘法沒有 overflow,並在 conversion 返回前保持 destination 有效。
|
||||
呼叫流程見 [使用手冊:GPU 轉換範例](../GVFG_CUSTOMER_API.md#gpu-轉換範例)。
|
||||
|
||||
### 1.18 `gvfg_event_type_t`
|
||||
|
||||
@@ -270,6 +254,8 @@ typedef struct gvfg_handle_t *gvfg_handle;
|
||||
|
||||
### 1.20 `gvfg_channel_osd_config_t` 與 `gvfg_osd_font_list_t`
|
||||
|
||||
使用 OSD 時請包含 `gvfg_osd.h`,連結 `gvfg_osd.lib`(MinGW 使用 `libgvfg_osd.dll.a`),並隨應用程式部署同一次 SDK 建置的 `gvfg_osd.dll` 和 `gvfg.dll`。一般擷取只需連結 `gvfg.dll` 對應的 import library。
|
||||
|
||||
```c
|
||||
typedef struct gvfg_channel_osd_config_t {
|
||||
const char *text;
|
||||
@@ -287,7 +273,7 @@ typedef struct gvfg_osd_font_list_t {
|
||||
```
|
||||
|
||||
`text` 為 NUL 結尾的 1–32 字元可列印 ASCII;`font_family` 為 NUL 結尾的 UTF-8
|
||||
已安裝字型家族名稱。Set 返回前複製兩個字串。沒有 `struct_size`、`text_length`。
|
||||
已安裝字型家族名稱。Set 返回前複製兩個字串。字串須以 NUL 結尾。
|
||||
`font_size_px` 必須非零;`color_rgb` 為 `0x00RRGGBB`;`x/y` 是文字框左上角影像座標。
|
||||
字型清單由 SDK 管理,客戶不能修改或 free,使用期限與完整行為見第 2.26 節。
|
||||
|
||||
@@ -366,6 +352,47 @@ gvfg_status_t gvfg_get_channel_sdi_info(
|
||||
- `GVFG_ESTATE`:指定 channel 尚未 open。
|
||||
- 裝置查詢失敗時可能回傳 `GVFG_EIO`。
|
||||
|
||||
### HDMI 輸入資訊與晶片版本
|
||||
|
||||
```c
|
||||
gvfg_status_t gvfg_get_channel_hdmi_info(
|
||||
gvfg_handle handle, int channel_index, gvfg_hdmi_info_t *out_info);
|
||||
gvfg_status_t gvfg_get_chip_info(gvfg_handle handle, gvfg_chip_info_t *out_info);
|
||||
```
|
||||
|
||||
- 以 `gvfg_get_channel_signal_status()` 的 `video_interface` 選擇 SDI 或 HDMI 查詢。
|
||||
HDMI 查詢要求指定 channel 已 open,回傳來源鎖定狀態、寬高、FPS、色彩格式、
|
||||
色彩空間及位深。來源位深與 DMA 輸出位深可不同。
|
||||
- HDMI 的 `fps_name`、`color_format_name` 和 `color_space_name` 可直接顯示。
|
||||
HDMI 的 `fps` 是每秒幀數,例如 `60`,`fps_name` 是對應的十進位文字 `"60"`。
|
||||
色彩名稱範例為 `YUV 4:2:2` 和 `BT.2020 RGB (Limited)`。
|
||||
- 晶片版本屬於裝置,只需同一 handle 至少有一個 channel 已 open。
|
||||
日期與時間保留原始 32-bit 數值,將十六進位數字分別讀作 `YYYYMMDD` 和 `HHMMSS`。
|
||||
例如 `0x20261113`、`0x174645` 顯示為 `2026-11-13 17:46:45`。
|
||||
- 兩支 API 都要求非 NULL 的 handle 和輸出指標,否則回傳 `GVFG_EINVAL`。
|
||||
查詢所需的 channel 尚未 open 時回傳 `GVFG_ESTATE`。
|
||||
只有回傳 `GVFG_OK` 時才可使用輸出資料。
|
||||
|
||||
```c
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <gvfg_capture.h>
|
||||
|
||||
void print_chip_info(gvfg_handle handle)
|
||||
{
|
||||
gvfg_chip_info_t info = {0};
|
||||
if (gvfg_get_chip_info(handle, &info) == GVFG_OK) {
|
||||
char date[9];
|
||||
char time[9];
|
||||
int date_len = snprintf(date, sizeof date, "%08" PRIX32, info.version_date);
|
||||
int time_len = snprintf(time, sizeof time, "%06" PRIX32, info.version_time);
|
||||
if (date_len == 8 && time_len == 6)
|
||||
printf("Chip version: %.4s-%.2s-%.2s %.2s:%.2s:%.2s\n",
|
||||
date, date + 4, date + 6, time, time + 2, time + 4);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.6 Zero-copy mode selection
|
||||
|
||||
```c
|
||||
@@ -463,7 +490,7 @@ gvfg_status_t gvfg_read_channel_frame(/* [in] */ gvfg_handle handle,
|
||||
- `timeout_ms`:0 為 non-blocking;`GVFG_TIMEOUT_INFINITE` 為無限等待;其他值為毫秒。
|
||||
- `GVFG_OK`:成功取得 frame,caller 現在持有一個必須 release 的 token。
|
||||
- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。
|
||||
- `GVFG_ESTATE`:未 running、已有 held frame、已有另一個 read,或等待時被 stop。
|
||||
- `GVFG_ESTATE`:未 running、已有 held frame、已有另一個 read,或 read 期間被 stop(包含 stop 後又重新 start;此時不會交出 stop 前的 frame)。
|
||||
- `GVFG_ETIMEOUT`:期限內沒有 frame。
|
||||
- `GVFG_EBUSY` 表示 capture resource 正在使用中;`GVFG_EIO` 表示 capture 或 I/O 失敗;
|
||||
`GVFG_ENOTSUP` 表示 SDK 不支援該格式。
|
||||
@@ -628,7 +655,7 @@ const char *gvfg_get_version(void);
|
||||
const char *gvfg_get_gigabyte_lib_version(void);
|
||||
```
|
||||
|
||||
- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"3.0.0"`。
|
||||
- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"3.1.0"`。
|
||||
- 回傳值是靜態 null-terminated 字串,caller 不可 free。
|
||||
- 可用於 log、問題回報,以及確認 header、DLL 是否來自同一版本。
|
||||
- `gvfg_get_gigabyte_lib_version()` 回傳編譯進目前 runtime 的 GigabyteLib 版本常數,
|
||||
@@ -696,120 +723,31 @@ gvfg_status_t gvfg_clear_channel_osd(
|
||||
gvfg_handle handle, int channel_index, uint32_t osd_index);
|
||||
```
|
||||
|
||||
每個已 open 的 channel 支援兩組獨立 OSD,`osd_index` 為 `0` 或 `1`;
|
||||
重疊時第 `1` 組蓋在第 `0` 組上。後續 `gvfg_read_channel_frame()` 交付含 OSD 的
|
||||
YUY2/Y210 frame,使用後照常 release。
|
||||
| 項目 | 契約 |
|
||||
|---|---|
|
||||
| channel/組別 | Set、visibility、Clear 要求 channel 已 open;`osd_index` 為 0 或 1,重疊時 1 在上方 |
|
||||
| `gvfg_get_osd_fonts()` | 不需要 handle;每次重新檢查 Windows 已安裝字型。成功時回傳 `count` 與 UTF-8 `names`,失敗時清單為空 |
|
||||
| 清單所有權 | SDK 擁有陣列及字串,caller 不可修改或 free;有效到下一次清單查詢(含失敗呼叫)或 DLL 卸載。長期保存需自行複製;查詢及讀取須由 caller 序列化 |
|
||||
| `gvfg_set_channel_osd()` | 設定並顯示一組,返回前複製文字與字型名稱,套用到後續 frame;失敗保留原設定 |
|
||||
| 文字/字型 | `text` 為 NUL 結尾的 1–32 個 ASCII 0x20–0x7e;`font_family` 為 NUL 結尾的 UTF-8 已安裝家族名稱。不接受缺少的字型或無效 UTF-8 |
|
||||
| 字級/顏色 | `font_size_px` 是非零 em 大小,不等於字形實際墨色高度;normal weight/style/stretch。`color_rgb` 為 0x00RRGGBB,輸出為 BT.709 limited range |
|
||||
| 位置/尺寸 | `x/y` 為保守量測文字框左上角,會限制在影像內。框太大時只暫停該組;設定或影像尺寸改變後可恢復,不縮字、截字或換行 |
|
||||
| `gvfg_set_channel_osd_visible()` | `visible` 只接受 0/1;隱藏保留設定,顯示不必重新 Set。顯示未設定或已清除的組別回傳 `GVFG_ESTATE` |
|
||||
| `gvfg_clear_channel_osd()` | 停用並清除指定組別;之後須重新 Set,不影響另一組 |
|
||||
| 設定生命週期 | `gvfg_destroy()` 後不保留設定;應用程式自行保存需要還原的內容 |
|
||||
|
||||
- `gvfg_get_osd_fonts(&list)`:重新檢查 Windows 已安裝字型,取得當前可用家族名稱。
|
||||
不需要 handle、callback 或客戶端 free。`list.count` 是數量,`list.names[i]` 是 UTF-8 名稱。
|
||||
清單由 SDK 管理,指標有效到下一次呼叫此函式(包含失敗呼叫)或 DLL 卸載為止;
|
||||
填入 UI 或長期保存時自行複製。呼叫及讀取借用清單須由 caller 序列化。
|
||||
- `gvfg_measure_osd_text(&config, &width, &height)`:使用設定中的文字、字型與大小量測;
|
||||
忽略位置與顏色,不需要開啟裝置。
|
||||
- `gvfg_set_channel_osd(handle, channel, osd_index, &config)`:設定並顯示一組 OSD。
|
||||
函式返回前同步複製文字與字型名稱;設定失敗保留該組原設定。
|
||||
- `gvfg_set_channel_osd_visible(handle, channel, osd_index, visible)`:`0` 隱藏、`1` 顯示。
|
||||
保留設定、YUV 字圖、Mask 與 GPU 資源;單純 Hide/Show 不重新產生字圖。
|
||||
影像尺寸或格式改變仍可能更新資源。尚未設定或已清除的組別不能直接 Show。
|
||||
- `gvfg_clear_channel_osd(handle, channel, osd_index)`:停用該組並清除設定與字圖快取;
|
||||
後續須重新 Set 才能顯示,不影響另一組。
|
||||
- `GVFG_OK`:呼叫成功;不代表已交付的舊 frame 會改變。
|
||||
- `GVFG_EINVAL`:NULL pointer、無效字串/字型/字號/組別/visibility 等參數錯誤。
|
||||
- `GVFG_ESTATE`:channel 未 open,或要求顯示未設定的組別。
|
||||
- `GVFG_EIO`:量測、配置或其他處理失敗。
|
||||
|
||||
`gvfg_channel_osd_config_t` 沒有 `struct_size` 或 `text_length`,欄位順序為:
|
||||
|
||||
```c
|
||||
const char *text; /* NUL 結尾,1–32 個可列印 ASCII 字元 */
|
||||
const char *font_family; /* NUL 結尾的 UTF-8 字型家族名稱,不是檔案路徑 */
|
||||
uint32_t font_size_px; /* 大於 0 */
|
||||
uint32_t color_rgb; /* 0x00RRGGBB */
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
```
|
||||
|
||||
客戶先在 Windows 安裝字型,再重新取得清單,將選到的名稱放入 `font_family`。
|
||||
只下載但未安裝的字型不會自動列入。字型名稱可為 UTF-8,但 OSD 文字仍只接受
|
||||
ASCII `0x20`–`0x7e`,不接受中文或換行。清單中的字型不保證含有所有語言的字元。
|
||||
不存在的字型或無效 UTF-8 名稱回傳 `GVFG_EINVAL`,不靜默改用 Arial。
|
||||
|
||||
字型為 normal weight/style/stretch。字級傳給 DirectWrite 的 em 大小,繪製目標固定
|
||||
96 DPI,因此數值可對應影像像素;不是 Word 的 pt,也不是字形實際墨色高度。
|
||||
SDK 沒有 viewer 的 512 px UI 上限。顏色轉為 BT.709 limited range,由 GPU 混合。
|
||||
|
||||
量測框包含排版空白、glyph overhang 及四邊各 1 px 安全邊,不是 pixel-tight 邊界。
|
||||
`x/y` 是該框左上角,SDK 依每張影像限制位置,使完整文字框留在影像內。
|
||||
某組文字框比影像大時,只暫停疊該組;擷取及另一組繼續。設定、尺寸或格式改變後
|
||||
重新判斷,可容納時恢復,不縮字、截字或換行。
|
||||
|
||||
量測失敗時可寫入的尺寸 output 歸零。無效參數、文字、字號、字型或組別回傳
|
||||
`GVFG_EINVAL`;channel 未 open 或要求顯示未設定的組別回傳 `GVFG_ESTATE`;
|
||||
其他初始化、量測或資源失敗回傳 `GVFG_EIO`。設定成功不表示已取得的 frame 會被修改。
|
||||
SDK 不跨 `gvfg_destroy()` 保留設定;viewer 自行保存兩組設定及 visibility,於重新 Start 時還原。
|
||||
|
||||
這次是 breaking API 更新:客戶須使用同一版本的 header、import library 與 DLL 重新編譯。
|
||||
|
||||
SDK 不自動選擇畫面角落,`x/y` 由 caller 指定。`srcroot` Viewer 中 OSD 1 預設
|
||||
`(32, 32)`、OSD 2 預設右下角屬於 APP 設定,不是 SDK 提供的持續角落錨定。
|
||||
|
||||
### 2.27 OSD 呼叫範例
|
||||
|
||||
以下 C++ 範例假設 `handle` 的 `channel` 已 open。先選擇清單中的實際字型,
|
||||
立即複製名稱,再使用相同設定量測與繪製;每一步都檢查回傳值。
|
||||
|
||||
```cpp
|
||||
#include <gvfg_capture.h>
|
||||
#include <string>
|
||||
|
||||
gvfg_status_t configure_osd(gvfg_handle handle, int channel)
|
||||
{
|
||||
gvfg_osd_font_list_t fonts{};
|
||||
auto status = gvfg_get_osd_fonts(&fonts);
|
||||
if (status != GVFG_OK) return status;
|
||||
if (fonts.count == 0) return GVFG_EINVAL;
|
||||
const std::string family(fonts.names[0]);
|
||||
|
||||
gvfg_channel_osd_config_t first{};
|
||||
first.text = "CAMERA 01";
|
||||
first.font_family = family.c_str();
|
||||
first.font_size_px = 48;
|
||||
first.color_rgb = 0xffffff;
|
||||
first.x = 32;
|
||||
first.y = 32;
|
||||
```
|
||||
|
||||
量測只使用文字、字型與大小;不需要額外開啟裝置。
|
||||
|
||||
```cpp
|
||||
uint32_t width = 0, height = 0;
|
||||
status = gvfg_measure_osd_text(&first, &width, &height);
|
||||
if (status != GVFG_OK) return status;
|
||||
status = gvfg_set_channel_osd(handle, channel, 0, &first);
|
||||
if (status != GVFG_OK) return status;
|
||||
|
||||
auto second = first;
|
||||
second.text = "ROOM 02";
|
||||
second.font_size_px = 32;
|
||||
second.color_rgb = 0xffff00;
|
||||
second.y = 120;
|
||||
return gvfg_set_channel_osd(handle, channel, 1, &second);
|
||||
}
|
||||
```
|
||||
|
||||
Set 返回前已複製字串,函式內的 `family` 可正常離開作用域。兩次 Set 各自生效;
|
||||
若第二次失敗,第一組仍保持成功設定。下列是之後對第二組的三個獨立操作範例,
|
||||
並非必須連續執行的初始化步驟;每個結果仍須檢查。
|
||||
|
||||
```cpp
|
||||
auto status = gvfg_set_channel_osd_visible(handle, channel, 1, 0); // Hide
|
||||
if (status != GVFG_OK) return status;
|
||||
status = gvfg_set_channel_osd_visible(handle, channel, 1, 1); // Show
|
||||
if (status != GVFG_OK) return status;
|
||||
status = gvfg_clear_channel_osd(handle, channel, 1); // Clear
|
||||
if (status != GVFG_OK) return status;
|
||||
```
|
||||
完整呼叫流程與程式範例見
|
||||
[使用手冊:OSD 呼叫範例](../GVFG_CUSTOMER_API.md#osd-呼叫範例)。
|
||||
|
||||
## 3. Playback 使用的影像型別
|
||||
|
||||
以下型別定義於 `gvfg_preview.h`,由 `gvfg_playback.h` 引入。
|
||||
此標頭只提供 Playback 使用的影像與統計型別;播放操作見第 4 節。
|
||||
以下型別直接定義於 `gvfg_playback.h`,使用端不需額外的後端標頭。
|
||||
此標頭包含 Playback 的公開型別與操作函式;本節介紹影像型別,播放操作見第 4 節。
|
||||
|
||||
### 3.1 Preview 型別
|
||||
|
||||
@@ -852,30 +790,7 @@ if (status != GVFG_OK) return status;
|
||||
| ------------------ | ------------------------------------ |
|
||||
| `present_fps` | 最近五秒成功 Present 的速率 |
|
||||
| `presented_frames` | 成功 Present 的累積 frame 數 |
|
||||
| `skipped_presents` | 底層 Preview 的 Present busy、submit busy 與 queue age 等略過累積;不含所有 core 提前退休 |
|
||||
|
||||
`gvfg_preview_delivery_stats_t`:以下 counter 從 create 或前一次 shutdown 開始累積;
|
||||
configure 與 clear 不會重設。`presented` 表示 DXGI 接受 Present,不代表已實際 scanout。
|
||||
|
||||
| 欄位 | 說明 |
|
||||
| ------------------- | ---------------------------------------------- |
|
||||
| `submitted` | Preview 接收到並納入 delivery 統計的 render request 數 |
|
||||
| `presented` | 已被 DXGI Present 接受的 frame 數 |
|
||||
| `replaced` | 在 50 ms age limit 後被捨棄的 queued frame 數 |
|
||||
| `busy` | 遇到 upload slot busy 或 Present busy 的 request 數 |
|
||||
| `failed` | 已提交但後續處理失敗的 frame 數 |
|
||||
| `cancelled` | Shutdown 等流程取消的 frame 數 |
|
||||
| `in_flight` | 目前仍在 pipeline 中的 frame 數 |
|
||||
| `last_presented_id` | 最近成功 Present 的 `frame_id` |
|
||||
| `present_busy` | 因 Present busy 而略過的累積次數 |
|
||||
| `slots_busy` | 因內部 upload slot busy 而略過的累積次數 |
|
||||
| `last_busy_id` | 最近一次 busy frame 的 `frame_id` |
|
||||
|
||||
正常情況下:
|
||||
|
||||
```text
|
||||
submitted = presented + replaced + busy + failed + cancelled + in_flight
|
||||
```
|
||||
| `skipped_presents` | 預覽端略過呈現的累積數;不是 Capture 或錄影掉格總數 |
|
||||
|
||||
## 4. 統一 Playback API
|
||||
|
||||
@@ -904,12 +819,11 @@ MinGW 使用 `libgvfg_playback.dll.a`。
|
||||
| `gvfg_playback_get_preview_info(p, info)` | 影像輸出資訊 |
|
||||
| `gvfg_playback_get_preview_stats(p, stats)` | GPU/呈現統計 |
|
||||
| `gvfg_playback_set_signal_connected(p, connected)` | UI 執行緒轉交訊號狀態:0 顯示 helper 內建 NO SIGNAL 圖卡,1 隱藏 |
|
||||
| `gvfg_playback_get_delivery_stats(p, stats)` | 影像呈現與略過等計數 |
|
||||
| `gvfg_playback_strerror(status)` | 靜態英文錯誤字串,不可 free |
|
||||
|
||||
狀態碼為 OK、EINVAL、ESTATE、EOUTPUT、EQUEUE_FULL、EDISCONTINUITY、EAUDIO;
|
||||
queue 壓力會自動降級並略過過期資料,不要求 caller 因此停止擷取。
|
||||
正常同步時 External/Audio master 會退休過期預覽影格;GPU busy 也可略過,真正 GPU 失敗才回報 EOUTPUT。
|
||||
預覽可能略過過時影格;成功提交不保證每張影像都實際顯示。
|
||||
音訊及獨立錄影不受此預覽策略影響。
|
||||
submit 返回後 caller 可立即釋放 SDK frame;present_image 則須保留資料到函式返回。
|
||||
控制操作(含 present_image)須由 caller 序列化;可由獨立影音 producer 併行 submit。
|
||||
@@ -922,6 +836,7 @@ stop/reset 是取消,不是無損 EOS drain。
|
||||
|
||||
先呼叫 `gvfg_playback_default_config(&config)`,不需要自行填 struct_size。
|
||||
start 會複製設定;只接受停止狀態的 handle,不會代替 caller 停掉既有播放。
|
||||
一般使用者保留 `max_video_frames`、`max_audio_ms`、`max_video_bytes` 的預設值即可;這三項是進階容量上限,僅在有明確記憶體或待播容量需求時調整,不代表固定播放延遲。
|
||||
|
||||
| 欄位 | 預設值 | 限制與語意 |
|
||||
|---|---|---|
|
||||
@@ -934,7 +849,7 @@ start 會複製設定;只接受停止狀態的 handle,不會代替 caller
|
||||
| `preroll_ms` | 100 | 1~1000 ms;啟用串流需要的初始/重新緩衝覆蓋範圍 |
|
||||
| `max_video_frames` | 32 | 1~600,待播影像張數上限;純音訊仍須填合法值 |
|
||||
| `max_audio_ms` | 1000 | 不小於 preroll_ms,且不超過 10000;包括共用 queue 與輸出端待播量 |
|
||||
| `max_video_bytes` | 256 MiB | 必須大於 0;包括目前 worker 處理中的 CPU 影像副本 |
|
||||
| `max_video_bytes` | 256 MiB | 必須大於 0;包括待播與正在處理的影像 |
|
||||
|
||||
External/Audio master 的預覽允許過期退休與 GPU-busy 略過,不是逐幀無損輸出。
|
||||
Video master 不啟用自動過期退休;有限緩衝也不保證在輸出速度不足時永久接收所有 frame。
|
||||
@@ -975,7 +890,7 @@ submit 會複製實際影像列範圍,frame ID 僅作身分/統計資訊,
|
||||
| -1 | `GVFG_PLAYBACK_EINVAL` | 修正 NULL、格式、尺寸、對齊、struct_size 或 config 範圍 |
|
||||
| -2 | `GVFG_PLAYBACK_ESTATE` | 檢查是否 start、模式是否啟用該路、單張操作是否在停止且已綁窗狀態 |
|
||||
| -3 | `GVFG_PLAYBACK_EOUTPUT` | 檢查 WASAPI/GPU/視窗/記憶體及重啟流程;不能假設會自動恢復 |
|
||||
| -4 | `GVFG_PLAYBACK_EQUEUE_FULL` | 保留的未接受狀態;先 release SDK frame,不可持有擷取資源等待 |
|
||||
| -4 | `GVFG_PLAYBACK_EQUEUE_FULL` | 保留值,目前 API 不回傳;queue 壓力由核心自動處理,單筆資料超出容量回傳 EINVAL |
|
||||
| -5 | `GVFG_PLAYBACK_EDISCONTINUITY` | 協調 producer,重設時間軸;新音訊格式須以新 config stop/start |
|
||||
| -6 | `GVFG_PLAYBACK_EAUDIO` | 影音模式的監聽音效已因輸出故障停用,影像繼續;提示一次,繼續獨立擷取/錄影。此 handle 不再接受音訊,重建 handle 才重試音效 |
|
||||
|
||||
@@ -1000,13 +915,12 @@ submit 會複製實際影像列範圍,frame ID 僅作身分/統計資訊,
|
||||
| `submit_audio(p, pcm, bytes, ts)` | 已 start 且啟用音訊;成功返回前完成複製 |
|
||||
| `present_image(p, image)` | 停止狀態且有 HWND;同步等待工作完成,資料須有效到返回;GPU busy 不等於實體顯示成功 |
|
||||
| `set_volume(p, gain)` | finite 0.0~2.0;可先設定再 start,0 是靜音而不是停音訊 |
|
||||
| `reset_timeline(p)` | stop、清畫面、若原本 active 則用原 config start;未建立呈現表面(swapchain)的空畫面視為清除成功;會取消舊 queue,真正的清畫面或重啟失敗仍回報錯誤 |
|
||||
| `stop(p)` | 可重複呼叫;join 共用 worker、銷毀音訊輸出並清 queue;保留 Preview 物件供後續重用 |
|
||||
| `destroy(p)` | NULL 安全;stop 後銷毀 Preview 與 handle |
|
||||
| `reset_timeline(p)` | 取消舊待播資料並重設時間軸;保留 config,若原本在播放則恢復播放。須檢查回傳值 |
|
||||
| `stop(p)` | 停止播放並取消待播資料;可重複呼叫 |
|
||||
| `destroy(p)` | NULL 安全;停止播放並釋放 handle |
|
||||
| `get_preview_info(p, info)` | 回傳影像資訊;尚未建立 Preview 時為零值 |
|
||||
| `get_preview_stats(p, stats)` | 回傳呈現 FPS/計數;尚未建立 Preview 時為零值 |
|
||||
| `set_signal_connected(p, connected)` | 僅接受 0/1,預設 1。0 顯示 helper 內建圖卡、1 隱藏。可在 attach 前設定,跨 stop/start/reset/reattach 保留;與 attach/destroy 在 HWND 執行緒序列化。圖卡隨視窗縮放,detach/destroy 釋放。此 API 不查詢 Capture、不更動影格或同步、不依 FPS 判斷訊號 |
|
||||
| `get_delivery_stats(p, stats)` | 回傳底層 Preview delivery 計數;不包含共用核心提前退休的所有過期影格 |
|
||||
| `strerror(status)` | 靜態字串,不可 free;未知值回傳 unknown error 文字 |
|
||||
|
||||
函式完整名稱皆為 `gvfg_playback_` 加上表中名稱。getters 的輸出指標不可 NULL。
|
||||
|
||||
Binary file not shown.
@@ -163,7 +163,10 @@ try {
|
||||
if ((Get-Item -LiteralPath $temporaryPdf).Length -lt 10000) {
|
||||
throw 'The generated PDF is unexpectedly small.'
|
||||
}
|
||||
Copy-Item -LiteralPath $temporaryPdf -Destination $OutputPdf -Force
|
||||
$bundledPython = Join-Path $env:USERPROFILE '.cache/codex-runtimes/codex-primary-runtime/dependencies/python/python.exe'
|
||||
$python = if (Test-Path -LiteralPath $bundledPython) { $bundledPython } else { (Get-Command python.exe -ErrorAction Stop).Source }
|
||||
& $python (Join-Path $scriptDir 'build_api_reference_pdf.py') --add-bookmarks $htmlPath $temporaryPdf $OutputPdf
|
||||
if ($LASTEXITCODE -ne 0) { throw 'PDF bookmark generation failed (requires Python and pypdf).' }
|
||||
Write-Host "PDF created: $OutputPdf" -ForegroundColor Green
|
||||
} finally {
|
||||
if (Test-Path -LiteralPath $temporaryRoot) {
|
||||
|
||||
@@ -133,6 +133,43 @@ def extract_banner(template_docx: Path) -> bytes:
|
||||
raise RuntimeError("Branding template does not contain word/media/image1.jpeg") from error
|
||||
|
||||
|
||||
def add_pdf_bookmarks(body: str, source_pdf: Path, output_pdf: Path) -> None:
|
||||
"""Reuse Edge's named destinations so bookmarks land at heading positions."""
|
||||
from pypdf import PdfReader, PdfWriter
|
||||
from pypdf.generic import Fit
|
||||
|
||||
reader = PdfReader(source_pdf)
|
||||
writer = PdfWriter()
|
||||
writer.clone_document_from_reader(reader)
|
||||
destinations = reader.named_destinations
|
||||
parent = None
|
||||
count = 0
|
||||
for match in re.finditer(r'<h([23])\s+id="(section-\d+)">(.*?)</h\1>', body, re.DOTALL):
|
||||
level, section_id, inner = match.groups()
|
||||
title = html.unescape(re.sub(r"<[^>]+>", "", inner)).strip()
|
||||
destination = destinations.get('/' + section_id)
|
||||
if destination is None:
|
||||
destination = destinations.get(section_id)
|
||||
if destination is None:
|
||||
raise RuntimeError(f"PDF heading destination not found: {section_id}")
|
||||
page = reader.get_destination_page_number(destination)
|
||||
if page is None:
|
||||
raise RuntimeError(f"PDF heading page not found: {section_id}")
|
||||
bookmark = writer.add_outline_item(
|
||||
title, page, parent=parent if level == '3' else None,
|
||||
fit=Fit.xyz(destination.left, destination.top, destination.zoom),
|
||||
)
|
||||
if level == '2':
|
||||
parent = bookmark
|
||||
count += 1
|
||||
if not count:
|
||||
raise RuntimeError("No chapter headings found for PDF bookmarks.")
|
||||
writer.page_mode = '/UseOutlines'
|
||||
with output_pdf.open('wb') as stream:
|
||||
writer.write(stream)
|
||||
print(f"PDF bookmarks created: {count}")
|
||||
|
||||
|
||||
def build_pdf(input_markdown: Path, output_pdf: Path, template_docx: Path) -> None:
|
||||
for required in (input_markdown, template_docx):
|
||||
if not required.is_file():
|
||||
@@ -187,7 +224,7 @@ def build_pdf(input_markdown: Path, output_pdf: Path, template_docx: Path) -> No
|
||||
details = completed.stderr.decode(errors="replace").strip()
|
||||
raise RuntimeError(f"Microsoft Edge did not create a valid PDF. {details}")
|
||||
|
||||
shutil.copyfile(plain_pdf, output_pdf)
|
||||
add_pdf_bookmarks(body, plain_pdf, output_pdf)
|
||||
if not output_pdf.is_file() or output_pdf.stat().st_size < 10_000:
|
||||
raise RuntimeError("The generated PDF is missing or unexpectedly small.")
|
||||
|
||||
@@ -195,11 +232,18 @@ def build_pdf(input_markdown: Path, output_pdf: Path, template_docx: Path) -> No
|
||||
def main() -> None:
|
||||
script_dir = Path(__file__).resolve().parent
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--add-bookmarks', action='store_true', help='Add bookmarks using HTML, input PDF, and output PDF positional arguments.')
|
||||
parser.add_argument("input_markdown", nargs="?", type=Path, default=script_dir / "GVFG_CUSTOMER_API_REFERENCE.md")
|
||||
parser.add_argument("output_pdf", nargs="?", type=Path)
|
||||
parser.add_argument("template_docx", nargs="?", type=Path, default=script_dir / "GVFG_CUSTOMER_API_REFERENCE.docx")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.add_bookmarks:
|
||||
if args.output_pdf is None:
|
||||
parser.error('--add-bookmarks requires HTML, input PDF, and output PDF paths')
|
||||
add_pdf_bookmarks(args.input_markdown.read_text(encoding='utf-8'), args.output_pdf, args.template_docx)
|
||||
return
|
||||
|
||||
input_markdown = args.input_markdown.resolve()
|
||||
output_pdf = (args.output_pdf or input_markdown.with_suffix(".pdf")).resolve()
|
||||
build_pdf(input_markdown, output_pdf, args.template_docx.resolve())
|
||||
|
||||
@@ -48,12 +48,12 @@ if (st == GVFG_OK) {
|
||||
## 3. Playback status 與非同步錯誤
|
||||
|
||||
Playback 的錯誤型別是 gvfg_playback_status_t:OK=0、EINVAL=-1、ESTATE=-2、
|
||||
EOUTPUT=-3、EQUEUE_FULL=-4、EDISCONTINUITY=-5。
|
||||
例如 Capture 的 -4 是 EIO,Playback 的 -4 是 queue full;這正是不能混用 strerror 的原因。
|
||||
EOUTPUT=-3、EQUEUE_FULL=-4(保留值,目前 API 不回傳)、EDISCONTINUITY=-5、EAUDIO=-6。
|
||||
例如 Capture 的 -4 是 EIO,Playback 的 -4 則是保留的 EQUEUE_FULL;兩套狀態碼不能混用 strerror。
|
||||
|
||||
submit 是接受/複製,不是實體輸出完成。其他非同步輸出失敗會由後續 submit 回報;
|
||||
start 或 submit 成功不保證後續輸出一定正常。
|
||||
目前輸出錯誤沒有自動重建裝置的保證,由 caller 協調停止與重啟。
|
||||
影音模式遇到音訊輸出故障時,停用該 handle 的監聽音效,影像繼續播放;後續音訊 submit 回傳 EAUDIO。影音 start 也可能在音效開啟失敗時成功,應檢查後續音訊 submit。此停用狀態跨 stop/start/reset 保留,需先協調 producer,再銷毀並重建 Playback handle 才會重試音效;獨立擷取與錄音可繼續。純音訊模式的輸出故障回報 EOUTPUT。
|
||||
|
||||
| 情況 | ownership 與後續處理 |
|
||||
|---|---|
|
||||
@@ -62,7 +62,8 @@ start 或 submit 成功不保證後續輸出一定正常。
|
||||
| read 成功,submit 拒收/失敗 | 仍 release 原始 token;若要重試,先保存應用程式自有副本 |
|
||||
| Playback queue 壓力 | 自動進入獨立播放並略過過時資料;不因 queue 滿而停止擷取,單筆超出配置容量則是 EINVAL |
|
||||
| Playback timestamp 不連續 | 協調 producer 後 reset;音訊格式改變用新 config stop/start |
|
||||
| 過期預覽或 GPU busy 略過 | 計入 video_dropped,不當成 Capture failure |
|
||||
| 過期預覽或 GPU busy 略過 | 不當成 Capture failure;公開 skipped_presents 僅涵蓋預覽端略過數,不包含同步核心提前捨棄的所有影格 |
|
||||
| Playback EAUDIO | 提示一次監聽音效停用;繼續影像與獨立擷取/錄音,需重建 Playback handle 才重試音效 |
|
||||
| Playback EOUTPUT | 檢查裝置/視窗與輸出路徑,明確決定重啟,不無限重試 |
|
||||
|
||||
## 4. 生命週期與 Demo
|
||||
|
||||
@@ -6,13 +6,16 @@
|
||||
|
||||
1. [客戶 Capture 使用手冊](GVFG_CUSTOMER_API.md):裝置、channel、影音 read/release 與事件。
|
||||
2. [統一 Playback 使用手冊](GVFG_PLAYBACK_API.md):一個播放 DLL、三種模式、單張顯示與舊版遷移。
|
||||
3. [公開 API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md):所有 Capture API,以及 Playback config、輸入、狀態、stats、函式契約。
|
||||
3. [公開 API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md):Capture/Playback 型別、參數、所有權、狀態碼與限制;完整流程範例放在使用手冊。
|
||||
4. [Customer Sample README](../../Costomer_SDK_Release/GVFG_Customer_Sample/README.md):Qt Creator/CMake 建置與 Demo 操作。
|
||||
|
||||
不需先讀 driver、WASAPI 或 D3D 才能使用公開 API。Demo 只展示 API,不實作同步演算法。
|
||||
|
||||
## SDK 維護與學習
|
||||
|
||||
客戶文件中的實作原理已移至 [study:文件分工與內部說明](../../study/notes/customer_vs_internal_docs.md),
|
||||
兩組 OSD 的字型、mask、YUV、快取與 shader 見 [study:OSD 實作章](../../study/03_helpers_gpu/04_osd_text_to_gpu.md)。
|
||||
|
||||
1. [物件架構](GVFG_Overview.md):Capture/Playback 兩種 handle、內部物件及 DLL/靜態 library。
|
||||
2. [資料流與狀態](GVFG_FRAME_FLOW_AND_STATE.md):借用 pointer、播放副本、read/release、重設與停止。
|
||||
3. [Capture 錯誤處理](GVFG_ERROR_HANDLING.md):Capture status/detail 與 ownership;播放錯誤另看 API Reference 第 4 節。
|
||||
|
||||
+27
-21
@@ -13,8 +13,22 @@
|
||||
MinGW 使用對應的 `libgvfg.dll.a`、`libgvfg_playback.dll.a`。
|
||||
播放功能只有一個 DLL;擷取仍有自己的 DLL。Windows 與 C/C++ runtime 相依仍須滿足。
|
||||
|
||||
公開標頭需一起交付:`gvfg_capture.h`、`gvfg_playback.h`、`gvfg_preview.h`、
|
||||
`gvfg_audio_playback.h`。後兩個由 Playback 標頭引入,提供影像、PCM 格式及統計型別。
|
||||
Playback 僅需交付 `gvfg_playback.h`,其中已包含所有公開函式、影像、PCM 格式及統計型別。擷取功能另使用 `gvfg_capture.h`;內部音訊與顯示後端不需另外提供標頭。
|
||||
|
||||
### 顯示資訊與呈現統計
|
||||
|
||||
公開查詢提供一般應用程式需要的資訊:
|
||||
|
||||
| 查詢 | 結果 | 用途 |
|
||||
|---|---|---|
|
||||
| `gvfg_playback_get_preview_info()` | `gvfg_preview_info_t` | 取得影像尺寸、格式與顯示卡資訊 |
|
||||
| `gvfg_playback_get_preview_stats()` | `gvfg_preview_stats_t` | 取得 `present_fps`、`presented_frames`、`skipped_presents` |
|
||||
|
||||
呼叫時傳入有效的 Playback handle 與結果結構指標,並檢查回傳值。
|
||||
`present_fps` 是最近五秒成功被 DXGI Present 接受的速率;`presented_frames` 是成功 Present 的累積數,兩者均不代表螢幕實際掃描輸出。
|
||||
`skipped_presents` 是預覽端略過呈現的累積數,不是擷取或錄影掉格總數。
|
||||
|
||||
詳細佇列、GPU upload slot 與逐影格 delivery 計數屬於內部 Debug 診斷,不在公開 header 或客戶 API 中提供。應用程式不需管理這些內部狀態。
|
||||
|
||||
## 2. 選擇模式
|
||||
|
||||
@@ -140,23 +154,16 @@ bool SubmitOneAudio(gvfg_handle capture, int channel, gvfg_playback player)
|
||||
應用程式可像範例一樣直接 submit 後 release,也可先複製、release,再 submit 自有副本。
|
||||
兩種方式都必須在 release 前完成對 SDK 記憶體的使用。
|
||||
|
||||
## 6. 時間戳、緩衝與落後
|
||||
## 6. 時間戳與播放延遲
|
||||
|
||||
- 直接傳入 SDK 的 `timestamp_ns`;它是同一單調交付時鐘的奈秒值,不是 UTC,也不是已知的硬體曝光/收音時間。
|
||||
- 各路時間必須大於 0、嚴格遞增且不超過 `INT64_MAX`。不要把第一筆音影差值歸零來掩蓋未知延遲。
|
||||
- 第一包 PCM 以交付時間扣除包長估計起點,後續維持連續時間軸,並平滑追蹤與交付時鐘的長期偏差。無法辨認驅動內的未知舊資料或遺失 samples。
|
||||
- 預設共同 preroll 為 100 ms,以已收到的啟用串流時間覆蓋範圍判斷。缺資料時只短暫等待,超時會降級為獨立播放;正常排程的影像保留一張 lookahead。
|
||||
- 正常同步時 External/Audio master 會略過已過播放期限的預覽影格,保留最新到期影格;GPU busy 的略過也會計數。Video master 在正常同步時不啟用這個自動過期退休策略。
|
||||
- `video_dropped` 是預覽略過數,不是 Capture/driver 遺失數,也不是錄影掉格數。
|
||||
- 微幅音訊速率補償有上限;持續缺資料、未知底層延遲或大幅落後,不能保證由補償自動修復。
|
||||
|
||||
預設上限為影像 32 張/256 MiB、音訊 1000 ms。queue 壓力、長時間缺資料或影音偏差過大時,
|
||||
Playback 自動降級:影像持續顯示最新可用影格,音訊以正常速率播放並丟棄積壓的待播資料。
|
||||
沒有音訊資料時保持靜音,不會因為等待音訊而持續凍結影像;資料不足仍可能聽見音訊間斷。
|
||||
來源與輸出穩定後會自動恢復同步,重新對齊時可能短暫保留目前畫面。
|
||||
降級、待播資料丟棄與恢復由 Playback 內部處理,應用程式不需另寫控制邏輯。
|
||||
submit 返回 OK 表示資料已由播放器管理,包含略過顯示或丟棄待播副本的情況;不保證每筆都輸出。
|
||||
單張影像/單包 PCM 超出其設定容量屬於 `EINVAL`,應修正 config 或輸入大小。
|
||||
- 直接傳入 Capture 的 `timestamp_ns`;video 與 audio 必須使用同一單調時間軸,單位為奈秒。
|
||||
各路時間戳必須大於 0、嚴格遞增且不超過 `INT64_MAX`。
|
||||
- 時間戳不是 UTC,也不代表硬體曝光/收音時間;不要各自歸零兩路時間戳來改變原本相對關係。
|
||||
- 同步播放可能增加延遲。需要獨立播放時使用 `gvfg_playback_set_sync_enabled(p, 0)`;
|
||||
應用程式不必自行調整播放速率或實作同步演算法。
|
||||
- 來源不穩定時可能出現靜音、間斷或略過影格;應用程式仍須持續提交可用資料。
|
||||
API 接受資料不保證每張 frame 都顯示,也不能保證恢復未知的底層遺失或延遲。
|
||||
- 一般應用程式保留 `gvfg_playback_default_config()` 提供的緩衝預設值。`max_video_frames`、`max_audio_ms`、`max_video_bytes` 是進階容量上限,僅在有明確記憶體或待播容量需求時調整;它們不是固定播放延遲的保證。欄位與合法範圍見 API Reference 的 `gvfg_playback_config_t`。
|
||||
|
||||
## 7. 執行緒、重設與停止
|
||||
|
||||
@@ -170,8 +177,7 @@ Playback stop/destroy → Capture stop;最後一個 channel 結束後才 destr
|
||||
|
||||
遇到時間倒退、重連或切格式,先協調 producer,再檢查 `reset_timeline()` 回傳值。
|
||||
reset 會清除待播資料並沿用原 config 重新建立時間軸;音訊格式改變時應 stop/start 新 config。
|
||||
尚未建立呈現表面(swapchain)時,清除空畫面視為成功,reset 後仍會重新啟動原本運行的時間軸。
|
||||
已建立的影像輸出若真的清除失敗,reset 仍可能回報 `EOUTPUT`,不能假設一定成功。
|
||||
reset 失敗仍須依回傳狀態處理,不可假設一定成功。
|
||||
|
||||
stop/reset 都會取消待播資料,沒有無損 EOS/drain 語意;有限檔案的尾幀完整輸出不是目前 API 的保證。
|
||||
影音模式遇到音訊輸出故障時,helper 停用監聽音效並繼續播放影像,
|
||||
@@ -202,7 +208,7 @@ if (gvfg_get_channel_signal_status(capture, channel, &signal) == GVFG_OK) {
|
||||
|
||||
在綁定 HWND 的 UI 執行緒呼叫,與 attach/destroy 序列化。0 顯示固定圖卡,1 隱藏。
|
||||
預設為 1;可先設定再 attach,狀態保留至下次明確設定,stop/start/reset 不改變它。
|
||||
視窗 resize 與圖卡資源由 helper 處理,不需 Qt 圖片資源或應用端繪圖。
|
||||
圖卡會隨視窗縮放,應用程式不必自行繪製。
|
||||
此 API 不讀 Capture、不以 FPS 或黑色像素推測訊號,也不改影格內容、PTS 或錄影。
|
||||
若未使用此 API,維持一般預覽行為。destroy/detach 也應在 HWND 執行緒執行。
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# GVFG SDK 與 Demo 建置說明
|
||||
|
||||
SDK version 由 `GVFG_SDK/CMakeLists.txt` 決定,目前為 3.0.0。
|
||||
SDK version 由 `GVFG_SDK/CMakeLists.txt` 決定,目前為 3.1.0。
|
||||
|
||||
修改共用類別的成員配置或公開 API 後,先完整重建 SDK,再清理並重建使用它的 APP。
|
||||
連結成功不代表 object 使用相同的類別大小;標頭相依追蹤失效時,舊 object 可能造成
|
||||
@@ -34,7 +34,8 @@ SDK 與 Demo 現在不是同一個頂層 CMake 專案。不存在 `BUILD_GVFG_SA
|
||||
|
||||
| SDK target | 類型 | 說明 |
|
||||
|---|---|---|
|
||||
| `gvfg` | SHARED | Capture facade、vendor adapter、GPU conversion/OSD |
|
||||
| `gvfg` | SHARED | Capture facade、vendor adapter、GPU conversion |
|
||||
| `gvfg_osd` | SHARED | 文字與字型、BGRA 疊圖、GPU 通道 OSD |
|
||||
| `gvfg_playback` | SHARED | 對外播放 DLL,只匯出 Playback 函式 |
|
||||
| `gvfg_preview` | STATIC | D3D backend,私下連結進 Playback |
|
||||
| `gvfg_audio_playback` | STATIC | WASAPI backend,私下連結進 Playback |
|
||||
@@ -54,7 +55,8 @@ SDK build 不需要 Qt,也不產生 Demo EXE。
|
||||
|
||||
`GVFG_MINGW_DLLTOOL` 是 FILEPATH,可指向 dlltool 以產生客戶端 GNU 匯入庫。
|
||||
這不表示 MSVC vendor 靜態庫可直接由 MinGW 建置 SDK。
|
||||
`GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE` 是現有預設 OFF 的實驗選項,不屬於客戶播放設定。
|
||||
SDK 會一併建置 `gvfg_osd.dll`。使用 OSD 的應用程式(例如 Qt Viewer)需包含 `gvfg_osd.h`、連結 OSD import library,並部署 OSD DLL。
|
||||
|
||||
|
||||
## 4. Sample 的三種 SDK 來源
|
||||
|
||||
|
||||
Reference in New Issue
Block a user