Update SDK 3.2 documentation and add English and Traditional Chinese versions

- Check the README, customer guides, API reference, and internal notes against the
  SDK 3.2.0 headers, export lists, and CMake rules. Fix stale versions, the OSD move to
  gvfg_osd.dll, the OSD example header, and missing APIs (HDMI audio info, the HDMI and
  chip structs, gvfg_render_osd_frame_bgra, gvfg_playback_enable_audio_reconnect).
- Document present_image returning EOUTPUT when nothing was presented, opt-in audio
  reconnect for EAUDIO, and whole-macropixel YUY2 row sizes.
- Make English the primary *.md for the README and customer documents, keep Traditional
  Chinese as *.zh-TW.md, and install both language versions.
- Update the GigabyteLib README version and checksum to 1.0.5 and redraw the
  architecture diagram for the Capture, OSD, and Playback DLLs.

Validation: git diff --cached --check passed. All relative links and anchors in the
changed Markdown files resolve, and the drawio XML parses with valid edges and
non-overlapping boxes. No build, cmake --install, or PDF regeneration was run, and the
diagram was not opened in draw.io.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 16:03:38 +08:00
co-authored by Claude Opus 5.5
parent 02c7004e8c
commit 784aa5c579
21 changed files with 3277 additions and 1044 deletions
+3 -3
View File
@@ -9,7 +9,7 @@
| 擷取 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/` |
| OSD(`gvfg_osd.dll`,選用) | `GVFG_SDK/helpers/gvfg_osd/` 與該目錄的 README |
| 建置、Sample 串接與安裝 | [內部建置說明](docs/INTERNAL_BUILD_GUIDE.md) 與各 target 的 `CMakeLists.txt` |
`../Costomer_SDK_Release/GVFG_Customer_Sample/` 是獨立的 Qt Demo,`../srcroot/` 是完整 Viewer。跨專案驗證可使用這些呼叫端,變更範圍依任務決定。`CaptureDemo/` 有舊範例及驅動參考資料。
@@ -21,7 +21,7 @@
- 擷取改動需追蹤裝置與通道的啟停、格式變更及 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)。
- 公開契約或用法有變動時,更新對應的 [擷取手冊](docs/GVFG_CUSTOMER_API.md)、[播放手冊](docs/GVFG_PLAYBACK_API.md) 或 [API Reference](docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。客戶文件與 README 都有英文(`*.md`)和繁體中文(`*.zh-TW.md`)兩版,兩版須同步更新。
- 修正缺陷時,若同類錯誤能穩定重現,依現有測試入口加入適當的回歸驗證。需要人工判斷時,記下重現步驟與預期結果。
## 建置與驗證
@@ -30,7 +30,7 @@ SDK 使用 Windows x64、C++17、CMake 3.16 以上及與 vendor `GvfgSdk.lib`
```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
cmake --build GVFG_SDK/build_release --target gvfg gvfg_osd gvfg_playback
```
- 單項建置可將 `--target` 指定為受影響的 target。涉及公開標頭或共用類別配置時,完整重建 SDK,並用同版標頭、匯入庫和 DLL 乾淨重建相關應用程式。切換 generator 或 toolchain 時,使用獨立的 build 目錄。
+5 -1
View File
@@ -55,9 +55,13 @@ add_subdirectory(helpers/gvfg_playback)
install(FILES
../docs/GVFG_CUSTOMER_API.md
../docs/GVFG_CUSTOMER_API.zh-TW.md
../docs/GVFG_PLAYBACK_API.md
../docs/GVFG_PLAYBACK_API.zh-TW.md
DESTINATION ${CMAKE_INSTALL_DOCDIR}
)
install(FILES ../docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md
install(FILES
../docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md
../docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md
DESTINATION ${CMAKE_INSTALL_DOCDIR}/GVFG_Customer_doc
)
+21 -10
View File
@@ -1,12 +1,20 @@
# GVFG OSD core
# GVFG OSD
`gvfg_osd_core` is an internal static library that generates a full-frame
YUV422 OSD surface when text settings change. It does not capture, process
live video frames, communicate with the driver, or present a preview. The
library is linked into `gvfg.dll`; it is not installed or shipped as a
separate customer DLL.
Since SDK 3.2.0, OSD is built as the `gvfg_osd` SHARED target and shipped as the
optional customer DLL `gvfg_osd.dll`, with the public header `gvfg_osd.h` and the
import library `gvfg_osd.lib` (`libgvfg_osd.dll.a` for MinGW). It exports
`gvfg_get_osd_fonts`, `gvfg_measure_osd_text`, `gvfg_render_osd_frame_bgra`,
`gvfg_set_channel_osd`, `gvfg_set_channel_osd_visible`, and
`gvfg_clear_channel_osd`. Channel OSD attaches to capture through the
`gvfg_control_frame_processor` export of `gvfg.dll`, which is not declared in any
public header, so `gvfg_osd.dll` must come from the same SDK build as `gvfg.dll`.
The helper supports:
The private OSD core (`src/gvfg_osd_core.h`, `src/gvfg_osd.cpp`) generates a
full-frame YUV422 OSD surface when text settings change. It does not capture,
communicate with the driver, or present a preview; the GPU blend into live
frames is in `src/gvfg_gpu_osd.cpp`.
The core supports:
- YUY2 and Y210 output
- printable ASCII text, up to 32 characters
@@ -23,7 +31,7 @@ at least `width` bytes per row.
`gvfg_osd_measure()` returns a conservative complete text box containing logical
spacing, glyph overhang, and a one-pixel guard on each edge. It is not a
pixel-tight raster bound. The public `gvfg_measure_osd_text()` API in `gvfg.dll`
pixel-tight raster bound. The public `gvfg_measure_osd_text()` API in `gvfg_osd.dll`
provides the same measurement without creating a capture handle or opening a
device. Font size must be non-zero; the SDK does not impose the viewer's
512-pixel UI limit.
@@ -45,14 +53,17 @@ uploaded on settings/geometry changes, not every frame. Hidden slots retain
their rasterized surfaces and textures; shader visibility bits implement show/hide
without rebuilding. If all slots are hidden, no blend or readback is performed.
Clearing a slot discards its configuration and surfaces. An oversized slot is
skipped independently, leaving capture and the other slot active. For non-zero-copy acquisition, the backend explicitly
skipped independently, leaving capture and the other slot active.
For non-zero-copy (copy-mode) acquisition, the backend explicitly
grants writable access to its currently held SDK-owned capture buffer: the
GPU result replaces only that rectangle in place, retaining the original
stride and size. No second full-frame copy or output-buffer resize is needed.
The backend frame stays held until the application's normal release, including
across signal-recovery requests. The application still receives read-only data.
By default, driver zero-copy acquisition grants no writable access. The SDK still
Driver zero-copy acquisition grants no writable access (the experimental in-place
zero-copy OSD path was removed in 3.2.0). The SDK
copies the complete native frame into independent output storage, replaces
the processed rectangle there, and releases the backend frame before delivery.
CPU code copies bytes but does not blend pixels. Text with no visible coverage
+9 -5
View File
@@ -1,7 +1,7 @@
# Playback 維護與同步實作
SDK 3.0.0;客戶整合從 [公開播放手冊](../../../docs/GVFG_PLAYBACK_API.md) 開始,
逐參數契約見 [API Reference](../../../docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
SDK 3.2.0;客戶整合從 [公開播放手冊](../../../docs/GVFG_PLAYBACK_API.zh-TW.md) 開始,
逐參數契約見 [API Reference](../../../docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md)。
本文件供 SDK 維護者,說明目前實作,不作為 Customer Demo 的除錯畫面需求。
`signal_card.cpp` 管理 UI 執行緒上的原生 child overlay;圖片以 bitmap resource
@@ -22,7 +22,7 @@ gvfg_preview STATIC gvfg_audio_playback STATIC
```
Playback 是 SHARED target;兩個 backend 是 PRIVATE 連結的 STATIC target,只有 Playback 函式匯出。
`.def` 在本目錄。客戶標頭包含 backend header 只是重用資料型別,不對外匯出 backend 函式。
`.def` 在本目錄。公開 PCM、影像與呈現型別直接定義在 `gvfg_playback.h`;backend 標頭為私有,不安裝也不匯出 backend 函式。
Capture DLL 與 Playback DLL 沒有互相接管 handle,SDK source 仍依 target 各自維護。
## 2. 物件與執行緒
@@ -109,6 +109,7 @@ backend position 的 resetting 旗標與 generation 在 mutex 下協調,避免
HWND owner 的同步等待仍服務 sent messages,避免 DXGI 與 UI thread 互等。
初次 prepare 在緩衝期間做;正常每張不再重複 prepare 與前置 idle 等待。
`present_image()` 比對 render 前後的 presented 計數,沒有增加(GPU busy、逾時)就回傳 EOUTPUT。
真正後端 failure 導致 EOUTPUT;GPU busy/後端過期是計數略過,不是 Capture failure。
`video_processed` 包含呈現、隱藏消化與略過;`video_dropped` 是過期/busy 略過,不能當 driver drop。
底層 Preview delivery 計數不包含 core 在送 GPU 前已退休的所有 frame。
@@ -124,6 +125,9 @@ Audio master 不調整音訊速率。其他 master 每約 20 ms 以 audio PTS
WASAPI 使用 shared-mode AUTOCONVERTPCM、SRC_DEFAULT_QUALITY、RATEADJUST,
透過 `IAudioClockAdjustment::SetSampleRate()` 執行指令;不支援或操作失敗會回報輸出錯誤。
本實作沒有舊 QAudioSink 的兩秒自動重建裝置策略,也沒有無界加速補回未知遺失 samples。
影音模式可選用 `gvfg_playback_enable_audio_reconnect()`(start 前):音訊輸出失效後,worker 以背景 `std::async`
約每秒建立並 start 一個新的預設輸出;成功時換上新 player、重設音訊映射與恢復狀態並清除 `audio_output_failed`。
純音訊模式或核心已有 `last_error` 時不重試。
## 8. 與 FFplay 的對應及差異
@@ -148,9 +152,9 @@ stop/reset 取消 queue,不是無損 drain。reset 沿用舊 config,音訊
詳細統計位於私有 `src/playback_debug.h`,不安裝到客戶套件。核心保留診斷計數與同步狀態。
詳細 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`(Debug 組態,或頂層選項 `GVFG_ENABLE_INTERNAL_DIAGNOSTICS=ON`)建置的 DLL 匯出 `gvfg_playback_debug_get_stats()` 與 `gvfg_playback_debug_get_delivery_stats()`;內部工具須定義
`GVFG_INTERNAL_DIAGNOSTICS=1` 並使用同一版私有標頭與 MSVC Debug 匯入庫。
診斷結構不提供穩定 ABI 或舊大小相容;Release DLL 不匯出診斷查詢。
診斷結構不提供穩定 ABI 或舊大小相容;預設 Release DLL 不匯出診斷查詢。
config 仍要求目前完整的 struct_size。
公開 API/資料變更需同步標頭、匯入庫、DLL、Reference 與 Demo,避免混版。
+2 -2
View File
@@ -3,9 +3,9 @@
This directory contains the supervisor-provided static MSVC library used by the
GVFG backend.
- Upstream version macro: `GVFG_SDK_VER 1.0.4`
- Upstream version macro: `GVFG_SDK_VER 1.0.5`
- Library: `GvfgSdk.lib`
- SHA-256: `0BE490FB11C4509716B1281F4EE6E5D5793FB6938C432D2A5619088F26F720BF`
- SHA-256: `065745F64D2085C8AD153BE2FB0C368342172FEBF3153693828CB52B14D7A439`
`GvfgSdk.lib` is linked into `gvfg.dll`; it is not distributed as a separate
customer runtime dependency. The supplied package did not contain source,
+80 -49
View File
@@ -1,84 +1,115 @@
# GVFG Standalone SDK
目前 SDK 版本為 3.0.0,來源是 [GVFG_SDK/CMakeLists.txt](GVFG_SDK/CMakeLists.txt)。
擷取使用 `gvfg.dll`;選用播放功能使用 `gvfg_playback.dll`。Audio 與 Preview 是
Playback 內部靜態 library,不再各自部署 DLL。
English | [繁體中文](README.zh-TW.md)
## 文件入口
The current SDK version is 3.2.0, defined in [GVFG_SDK/CMakeLists.txt](GVFG_SDK/CMakeLists.txt).
Capture uses `gvfg.dll`. The optional OSD feature uses `gvfg_osd.dll`, and the optional
playback feature uses `gvfg_playback.dll`. Audio and Preview are internal static libraries
of Playback and are no longer deployed as separate DLLs.
| 目的 | 文件 |
## Where to start
| Goal | Document |
|---|---|
| 第一次使用擷取 API | [客戶 API 使用手冊](docs/GVFG_CUSTOMER_API.md) |
| 播放影像、音訊或同步影音 | [統一影音播放使用手冊](docs/GVFG_PLAYBACK_API.md) |
| 查結構、參數、限制與狀態碼 | [公開 API Reference](docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md) |
| 理解 source、ownership 與執行緒 | [學習入口](docs/GVFG_LEARNING_INDEX.md) |
| 建置 SDK、連結 Demo、安裝 | [內部建置說明](docs/INTERNAL_BUILD_GUIDE.md) |
| 維護同步、WASAPI、D3D 實作 | [Playback 維護說明](GVFG_SDK/helpers/gvfg_playback/README.md) |
| First use of the capture API (including OSD) | [Customer API Guide](docs/GVFG_CUSTOMER_API.md) |
| Play video, audio, or synchronized audio/video | [Unified Playback Guide](docs/GVFG_PLAYBACK_API.md) |
| Look up structs, parameters, limits, and status codes | [Public API Reference](docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md) |
| Understand sources, ownership, and threading | [Learning Index](docs/GVFG_LEARNING_INDEX.md) |
| Build the SDK, link the demo, install | [Internal Build Guide](docs/INTERNAL_BUILD_GUIDE.md) |
| Maintain sync, WASAPI, and D3D implementation | [Playback Maintenance Notes](GVFG_SDK/helpers/gvfg_playback/README.md) |
客戶先讀使用手冊,不需要理解 backend、driver 或同步演算法才可呼叫 API。
Customer documents are available in English (`*.md`) and Traditional Chinese
(`*.zh-TW.md`); internal maintenance documents are in Chinese only.
Customers should start with the guides. Calling the API does not require understanding
the backend, the driver, or the sync algorithms.
## 原始碼與責任
## Source layout and responsibilities
```text
GVFG_SDK/
sdk/gvfg/ Capture C API、GigabyteLib adapter、OSD/GPU conversion
helpers/gvfg_playback/ 公開播放 API、模式、時鐘、緩衝、同步排程
helpers/gvfg_audio_playback/ 內部 WASAPI 靜態 backend
helpers/gvfg_preview/ 內部 D3D 靜態 backend
helpers/gvfg_osd/ 內部 OSD 元件
docs/ 客戶與維護文件
../Costomer_SDK_Release/GVFG_Customer_Sample/ 獨立 Qt Demo 專案
../srcroot/ 完整 Viewer,匯入 Standalone SDK
sdk/gvfg/ Capture C API, GigabyteLib adapter, GPU conversion
helpers/gvfg_osd/ OSD DLL: fonts, text measurement, per-channel GPU OSD
helpers/gvfg_playback/ Public playback API, modes, clock, buffering, sync scheduling
helpers/gvfg_audio_playback/ Internal static WASAPI backend
helpers/gvfg_preview/ Internal static D3D backend
third_party/GigabyteLib/ Vendor GigabyteLib headers and libraries
docs/ Customer and maintenance documentation
tools/gigabytelib_probe/ GigabyteLib probing tool
CaptureDemo/exdemo/ Reference CaptureDemo (audio player example)
../Costomer_SDK_Release/GVFG_Customer_Sample/ Standalone Qt demo project
../srcroot/ Full Viewer, consumes the Standalone SDK
```
Capture 的 read/release、裝置與 channel lifecycle 由應用程式管理;Playback 只管理收到的播放副本。
GigabyteLib `GvfgSdk.lib` 靜態連結在 Capture DLL,private vendor headers 不屬於客戶 API。
The application owns capture read/release as well as the device and channel lifecycle;
Playback only manages the copies it receives for playback.
GigabyteLib `GvfgSdk.lib` is statically linked into the capture DLL. Private vendor
headers are not part of the customer API.
## 建置
## Build
SDK 不需要 Qt。在已載入 MSVC x64 環境的命令提示字元,於此目錄執行:
The SDK does not require Qt. From a command prompt with the MSVC x64 environment loaded,
run in this directory:
```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
cmake --build GVFG_SDK/build_release --target gvfg gvfg_osd gvfg_playback
```
SDK 的頂層 CMake 不建置 Qt Sample,也沒有 `BUILD_GVFG_SAMPLES` 選項。
Demo 從 [獨立專案目錄](../Costomer_SDK_Release/GVFG_Customer_Sample/README.md) 建置,僅需要 Qt Widgets。
內附 vendor `.lib` 需要相容的 MSVC x64 SDK 建置環境;MinGW 客戶端可連結產生的 GNU 匯入庫。
若找不到 dlltool,可設定 `GVFG_MINGW_DLLTOOL`,細節見建置說明。
The top-level SDK CMake does not build the Qt sample and has no `BUILD_GVFG_SAMPLES`
option. Build the demo from its [standalone project directory](../Costomer_SDK_Release/GVFG_Customer_Sample/README.md);
it only needs Qt Widgets.
The bundled vendor `.lib` requires a compatible MSVC x64 build environment; MinGW clients
can link against the generated GNU import libraries. If `dlltool` is not found
automatically, set `GVFG_MINGW_DLLTOOL`; see the build guide for details.
`GVFG_ENABLE_INTERNAL_DIAGNOSTICS` (default `OFF`) enables SDK diagnostics in non-Debug
builds and is for internal use only.
## 客戶檔案
## Customer files
```text
include/gvfg_capture.h
include/gvfg_osd.h
include/gvfg_playback.h
bin/gvfg.dll
bin/gvfg_osd.dll
bin/gvfg_playback.dll
lib/gvfg.lib
lib/gvfg_osd.lib
lib/gvfg_playback.lib
lib/libgvfg.dll.a # 有啟用 dlltool 時
lib/libgvfg_playback.dll.a # 有啟用 dlltool 時
lib/libgvfg.dll.a # when dlltool is enabled
lib/libgvfg_osd.dll.a # when dlltool is enabled
lib/libgvfg_playback.dll.a # when dlltool is enabled
share/doc/ # customer guides and API reference (English and Traditional Chinese)
```
只擷取、不播放時,只需要 Capture 的 header/匯入庫/DLL。使用 Playback 時,
另外攜帶三個播放相關標頭;後端標頭只為公開資料型別,不代表其函式對外匯出。
不要把建置目錄內的 `gvfg_preview.lib`、`gvfg_audio_playback.lib` 誤當成部署用匯入庫。
For capture only, you need just the capture header, import library, and DLL. To use OSD,
also ship `gvfg_osd.h`, its import library, and `gvfg_osd.dll`. To use Playback, also ship
`gvfg_playback.h`, its import library, and `gvfg_playback.dll`. All DLLs must come from the
same SDK build.
Do not mistake `gvfg_preview.lib` or `gvfg_audio_playback.lib` in the build directory for
deployable import libraries.
使用 `cmake --install <sdk-build> --prefix <new-package-directory>` 取得配套輸出。
Customer Demo 的 Release 打包腳本使用 EXE 同目錄中的 Capture/Playback DLL,
不會代為編譯,也不從其他 build 目錄任意挑 DLL。
Run `cmake --install <sdk-build> --prefix <new-package-directory>` to get a matching set of
outputs. The Customer Demo's Release packaging script uses the Capture and Playback
DLLs located next to the EXE; it does not build them and does not pick DLLs from arbitrary
build directories.
## 模式、遷移與驗證
## Modes, migration, and validation
Playback 支援 video-only、audio-only、audio-video;純音訊不需視窗,
單張 RAW/DICOM 可用 `gvfg_playback_present_image()`,不啟動播放時間軸。
同步策略在 SDK,不放在 Demo。普通 Demo 顯示基本狀態及 API 錯誤;內部分支的
Debug 診斷與客戶 Release 套件分開,不能以 Debug 畫面作為客戶 API 契約。
Playback supports video-only, audio-only, and audio-video. Audio-only playback needs no
window. A single RAW/DICOM image can be shown with `gvfg_playback_present_image()` without
starting the playback timeline.
The sync policy lives in the SDK, not in the demo. The standard demo shows basic status
and API errors. Debug diagnostics on internal branches are separate from the customer
Release package; the Debug UI is not part of the customer API contract.
舊程式應移除直接使用 Audio/Preview helper 的程式碼與 DLL 相依,
重新編譯並改用 `gvfg_playback_*`;遷移步驟見播放手冊。
既有擷取錄影流程與即時預覽是不同消費路徑,預覽略過數不等於錄影掉格數。
Existing code should remove any direct use of the Audio/Preview helpers and their DLL
dependencies, rebuild, and switch to `gvfg_playback_*`; see the playback guide for the
migration steps.
The existing capture-to-recording flow and live preview are different consumer paths:
the preview skip count is not the recording dropped-frame count.
既有 2 分鐘實機測試與慢速輸出模擬的範圍記在 Playback 維護說明;
短測、建置通過不代表完成聲學嘴型精度、小時級漂移或所有硬體/格式驗證。
The scope of the existing 2-minute hardware test and the slow-output simulation is
documented in the Playback maintenance notes. Short tests and successful builds do not
constitute validation of acoustic lip-sync accuracy, hour-long drift, or all
hardware/format combinations.
+97
View File
@@ -0,0 +1,97 @@
# GVFG Standalone SDK
[English](README.md) | 繁體中文
目前 SDK 版本為 3.2.0,來源是 [GVFG_SDK/CMakeLists.txt](GVFG_SDK/CMakeLists.txt)。
擷取使用 `gvfg.dll`;選用 OSD 功能使用 `gvfg_osd.dll`;選用播放功能使用 `gvfg_playback.dll`。
Audio 與 Preview 是 Playback 內部靜態 library,不再各自部署 DLL。
## 文件入口
| 目的 | 文件 |
|---|---|
| 第一次使用擷取 API(含 OSD) | [客戶 API 使用手冊](docs/GVFG_CUSTOMER_API.zh-TW.md) |
| 播放影像、音訊或同步影音 | [統一影音播放使用手冊](docs/GVFG_PLAYBACK_API.zh-TW.md) |
| 查結構、參數、限制與狀態碼 | [公開 API Reference](docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md) |
| 理解 source、ownership 與執行緒 | [學習入口](docs/GVFG_LEARNING_INDEX.md) |
| 建置 SDK、連結 Demo、安裝 | [內部建置說明](docs/INTERNAL_BUILD_GUIDE.md) |
| 維護同步、WASAPI、D3D 實作 | [Playback 維護說明](GVFG_SDK/helpers/gvfg_playback/README.md) |
客戶文件提供英文(`*.md`)與繁體中文(`*.zh-TW.md`)兩版;內部維護文件只有中文。
客戶先讀使用手冊,不需要理解 backend、driver 或同步演算法才可呼叫 API。
## 原始碼與責任
```text
GVFG_SDK/
sdk/gvfg/ Capture C API、GigabyteLib adapter、GPU conversion
helpers/gvfg_osd/ OSD DLL:字型、文字量測、通道 GPU OSD
helpers/gvfg_playback/ 公開播放 API、模式、時鐘、緩衝、同步排程
helpers/gvfg_audio_playback/ 內部 WASAPI 靜態 backend
helpers/gvfg_preview/ 內部 D3D 靜態 backend
third_party/GigabyteLib/ Vendor GigabyteLib 標頭與 library
docs/ 客戶與維護文件
tools/gigabytelib_probe/ GigabyteLib 探測工具
CaptureDemo/exdemo/ 參考用 CaptureDemo(音訊播放範例)
../Costomer_SDK_Release/GVFG_Customer_Sample/ 獨立 Qt Demo 專案
../srcroot/ 完整 Viewer,匯入 Standalone SDK
```
Capture 的 read/release、裝置與 channel lifecycle 由應用程式管理;Playback 只管理收到的播放副本。
GigabyteLib `GvfgSdk.lib` 靜態連結在 Capture DLL,private vendor headers 不屬於客戶 API。
## 建置
SDK 不需要 Qt。在已載入 MSVC x64 環境的命令提示字元,於此目錄執行:
```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_osd gvfg_playback
```
SDK 的頂層 CMake 不建置 Qt Sample,也沒有 `BUILD_GVFG_SAMPLES` 選項。
Demo 從 [獨立專案目錄](../Costomer_SDK_Release/GVFG_Customer_Sample/README.md) 建置,僅需要 Qt Widgets。
內附 vendor `.lib` 需要相容的 MSVC x64 SDK 建置環境;MinGW 客戶端可連結產生的 GNU 匯入庫。
若找不到 dlltool,可設定 `GVFG_MINGW_DLLTOOL`,細節見建置說明。
`GVFG_ENABLE_INTERNAL_DIAGNOSTICS`(預設 `OFF`)會在非 Debug 建置啟用 SDK 診斷,只供內部使用。
## 客戶檔案
```text
include/gvfg_capture.h
include/gvfg_osd.h
include/gvfg_playback.h
bin/gvfg.dll
bin/gvfg_osd.dll
bin/gvfg_playback.dll
lib/gvfg.lib
lib/gvfg_osd.lib
lib/gvfg_playback.lib
lib/libgvfg.dll.a # 有啟用 dlltool 時
lib/libgvfg_osd.dll.a # 有啟用 dlltool 時
lib/libgvfg_playback.dll.a # 有啟用 dlltool 時
share/doc/ # 客戶手冊與 API Reference(英文與繁體中文)
```
只擷取、不播放時,只需要 Capture 的 header/匯入庫/DLL。使用 OSD 時,另外攜帶
`gvfg_osd.h`、其匯入庫與 `gvfg_osd.dll`;使用 Playback 時,另外攜帶 `gvfg_playback.h`、
其匯入庫與 `gvfg_playback.dll`。所有 DLL 必須來自同一次 SDK 建置。
不要把建置目錄內的 `gvfg_preview.lib`、`gvfg_audio_playback.lib` 誤當成部署用匯入庫。
使用 `cmake --install <sdk-build> --prefix <new-package-directory>` 取得配套輸出。
Customer Demo 的 Release 打包腳本使用 EXE 同目錄中的 Capture/Playback DLL,
不會代為編譯,也不從其他 build 目錄任意挑 DLL。
## 模式、遷移與驗證
Playback 支援 video-only、audio-only、audio-video;純音訊不需視窗,
單張 RAW/DICOM 可用 `gvfg_playback_present_image()`,不啟動播放時間軸。
同步策略在 SDK,不放在 Demo。普通 Demo 顯示基本狀態及 API 錯誤;內部分支的
Debug 診斷與客戶 Release 套件分開,不能以 Debug 畫面作為客戶 API 契約。
舊程式應移除直接使用 Audio/Preview helper 的程式碼與 DLL 相依,
重新編譯並改用 `gvfg_playback_*`;遷移步驟見播放手冊。
既有擷取錄影流程與即時預覽是不同消費路徑,預覽略過數不等於錄影掉格數。
既有 2 分鐘實機測試與慢速輸出模擬的範圍記在 Playback 維護說明;
短測、建置通過不代表完成聲學嘴型精度、小時級漂移或所有硬體/格式驗證。
+134 -85
View File
@@ -1,110 +1,159 @@
<mxfile host="Electron" modified="2026-07-30T00:00:00.000Z">
<mxfile host="Electron" modified="2026-12-01T00:00:00.000Z">
<diagram id="gvfg-architecture-overview" name="Architecture Overview">
<mxGraphModel dx="1230" dy="1558" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1280" pageHeight="820" math="0" shadow="0">
<mxGraphModel dx="1280" dy="900" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1280" pageHeight="900" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="e2" edge="1" parent="1" source="customerApp" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="publicHeader" value="include / link">
<!-- Title -->
<mxCell id="title" parent="1" vertex="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=24;fontStyle=1;align=left;verticalAlign=middle;" value="GVFG Standalone SDK - Architecture Overview">
<mxGeometry x="40" y="0" width="900" height="36" as="geometry" />
</mxCell>
<mxCell id="subtitle" parent="1" vertex="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=13;fontColor=#555555;align=left;verticalAlign=middle;" value="SDK 3.2.0 · three DLLs: Capture (required), OSD and Playback (optional) · updated 2026-12-01">
<mxGeometry x="40" y="36" width="900" height="22" as="geometry" />
</mxCell>
<!-- Lanes -->
<mxCell id="laneApps" parent="1" vertex="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontStyle=1;fontSize=15;align=left;verticalAlign=top;spacingLeft=10;spacingTop=4;" value="1. Applications">
<mxGeometry x="40" y="70" width="1200" height="120" as="geometry" />
</mxCell>
<mxCell id="lanePublic" parent="1" vertex="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontStyle=1;fontSize=15;align=left;verticalAlign=top;spacingLeft=10;spacingTop=4;" value="2. Public API (customer package)">
<mxGeometry x="40" y="230" width="1200" height="130" as="geometry" />
</mxCell>
<mxCell id="laneInternal" parent="1" vertex="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontStyle=1;fontSize=15;align=left;verticalAlign=top;spacingLeft=10;spacingTop=4;" value="3. DLL internals (private)">
<mxGeometry x="40" y="400" width="1200" height="250" as="geometry" />
</mxCell>
<mxCell id="laneVendor" parent="1" vertex="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontStyle=1;fontSize=15;align=center;verticalAlign=top;spacingTop=4;" value="4. Vendor library, driver, Windows outputs">
<mxGeometry x="40" y="690" width="1200" height="170" as="geometry" />
</mxCell>
<!-- 1. Applications -->
<mxCell id="sample" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=13;" value="&lt;b&gt;Customer Sample (Qt)&lt;/b&gt;&lt;br&gt;../Costomer_SDK_Release/GVFG_Customer_Sample&lt;br&gt;uses Capture + Playback">
<mxGeometry x="70" y="110" width="340" height="60" as="geometry" />
</mxCell>
<mxCell id="customerApp" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=13;" value="&lt;b&gt;Customer application&lt;/b&gt;&lt;br&gt;uses Capture;&lt;br&gt;OSD and Playback when needed">
<mxGeometry x="470" y="110" width="340" height="60" as="geometry" />
</mxCell>
<mxCell id="viewer" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=13;" value="&lt;b&gt;Full Viewer&lt;/b&gt;&lt;br&gt;../srcroot&lt;br&gt;uses Capture + OSD + Playback">
<mxGeometry x="870" y="110" width="340" height="60" as="geometry" />
</mxCell>
<!-- 2. Public API -->
<mxCell id="capDll" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;strokeWidth=2;fontSize=13;" value="&lt;b&gt;gvfg.dll - Capture&lt;/b&gt;&lt;br&gt;gvfg_capture.h · gvfg.lib&lt;br&gt;devices, channels, video/audio read/release, events,&lt;br&gt;signal / SDI / HDMI / chip info, GPU conversion">
<mxGeometry x="70" y="270" width="340" height="72" as="geometry" />
</mxCell>
<mxCell id="osdDll" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;strokeWidth=2;dashed=1;fontSize=13;" value="&lt;b&gt;gvfg_osd.dll - OSD (optional)&lt;/b&gt;&lt;br&gt;gvfg_osd.h · gvfg_osd.lib&lt;br&gt;font list, text measurement, 2 slots per channel,&lt;br&gt;standalone BGRA overlay · needs same-build gvfg.dll">
<mxGeometry x="470" y="270" width="340" height="72" as="geometry" />
</mxCell>
<mxCell id="pbDll" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;strokeWidth=2;dashed=1;fontSize=13;" value="&lt;b&gt;gvfg_playback.dll - Playback (optional)&lt;/b&gt;&lt;br&gt;gvfg_playback.h · gvfg_playback.lib&lt;br&gt;video-only / audio-only / audio-video,&lt;br&gt;single RAW/DICOM image, NO SIGNAL card">
<mxGeometry x="870" y="270" width="340" height="72" as="geometry" />
</mxCell>
<!-- 3. Internals: Capture column -->
<mxCell id="facade" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=12;" value="&lt;b&gt;gvfg_handle_t facade&lt;/b&gt; (sdk/gvfg/src/gvfg_capture.cpp)&lt;br&gt;channels[0] + channels[1], one held frame each&lt;br&gt;event queue (64), runtime FPS, last error detail">
<mxGeometry x="70" y="440" width="340" height="70" as="geometry" />
</mxCell>
<mxCell id="gpuConvert" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=12;" value="&lt;b&gt;sdk/gvfg/src/gpu&lt;/b&gt; - D3D11 conversion&lt;br&gt;YUY2/Y210 to BGRA8 / RGB10A2 / NV12&lt;br&gt;(pipeline source shared with gvfg_preview)">
<mxGeometry x="70" y="522" width="340" height="56" as="geometry" />
</mxCell>
<mxCell id="frameProc" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=12;" value="&lt;b&gt;channel frame processor hook&lt;/b&gt;&lt;br&gt;gvfg_control_frame_processor (exported, no public header)">
<mxGeometry x="70" y="590" width="340" height="45" as="geometry" />
</mxCell>
<!-- 3. Internals: OSD column -->
<mxCell id="osdCore" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=12;" value="&lt;b&gt;OSD core&lt;/b&gt; (DirectWrite)&lt;br&gt;text to YUV422 surface + A8 coverage mask&lt;br&gt;BT.709 limited range, 96 DPI layout">
<mxGeometry x="470" y="440" width="340" height="70" as="geometry" />
</mxCell>
<mxCell id="osdGpu" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=12;" value="&lt;b&gt;GPU OSD blend&lt;/b&gt; (gvfg_gpu_osd)&lt;br&gt;slot 0 then slot 1, one ROI readback per frame">
<mxGeometry x="470" y="522" width="340" height="56" as="geometry" />
</mxCell>
<mxCell id="osdBgra" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=12;" value="&lt;b&gt;standalone BGRA8888 renderer&lt;/b&gt;&lt;br&gt;gvfg_render_osd_frame_bgra (no capture handle)">
<mxGeometry x="470" y="590" width="340" height="45" as="geometry" />
</mxCell>
<!-- 3. Internals: Playback column -->
<mxCell id="pbCore" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=12;" value="&lt;b&gt;Playback core&lt;/b&gt; (gvfg_playback.cpp)&lt;br&gt;modes, master clock, shared bounded queues,&lt;br&gt;AudioTimeline, DriftFilter, audio reconnect, signal card">
<mxGeometry x="870" y="440" width="340" height="70" as="geometry" />
</mxCell>
<mxCell id="preview" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=12;" value="&lt;b&gt;gvfg_preview&lt;/b&gt; - STATIC, linked into Playback&lt;br&gt;D3D11 upload slots, conversion, Present">
<mxGeometry x="870" y="522" width="340" height="56" as="geometry" />
</mxCell>
<mxCell id="audioOut" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=12;" value="&lt;b&gt;gvfg_audio_playback&lt;/b&gt; - STATIC, linked into Playback&lt;br&gt;WASAPI shared mode, rate adjustment">
<mxGeometry x="870" y="590" width="340" height="45" as="geometry" />
</mxCell>
<!-- 4. Vendor / driver / OS -->
<mxCell id="session" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#666666;fontSize=12;" value="&lt;b&gt;GigabyteCaptureSession&lt;/b&gt; × CH0 / CH1&lt;br&gt;gigabyte_device (SetupAPI enumeration)&lt;br&gt;gigabyte_driver_extensions (register R/W gap)">
<mxGeometry x="70" y="730" width="340" height="62" as="geometry" />
</mxCell>
<mxCell id="vendorLib" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#666666;fontSize=12;" value="&lt;b&gt;GvfgSdk.lib 1.0.5&lt;/b&gt; (third_party/GigabyteLib)&lt;br&gt;static, linked into gvfg.dll; not shipped separately">
<mxGeometry x="470" y="730" width="340" height="50" as="geometry" />
</mxCell>
<mxCell id="driver" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#f5f5f5;strokeColor=#666666;dashed=1;fontColor=#333333;fontSize=12;" value="vfg100.sys / FPGA / DMA - frames and events">
<mxGeometry x="470" y="815" width="340" height="32" as="geometry" />
</mxCell>
<mxCell id="osOut" parent="1" vertex="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#f5f5f5;strokeColor=#666666;dashed=1;fontColor=#333333;fontSize=12;" value="&lt;b&gt;Windows outputs&lt;/b&gt;&lt;br&gt;DXGI swap chain on the application HWND&lt;br&gt;WASAPI default audio endpoint">
<mxGeometry x="870" y="730" width="340" height="62" as="geometry" />
</mxCell>
<!-- Edges -->
<mxCell id="eLink" parent="1" edge="1" source="laneApps" target="lanePublic" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;fontSize=12;labelBackgroundColor=#ffffff;" value="include headers · link import libraries · deploy DLLs from the same SDK build">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="title" parent="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=24;fontStyle=1;align=left;verticalAlign=middle;" value="GVFG Standalone SDK - Code Scope Overview" vertex="1">
<mxGeometry height="38" width="720" x="40" y="-38" as="geometry" />
</mxCell>
<mxCell id="appLayer" parent="1" style="swimlane;html=1;startSize=34;horizontal=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontStyle=1;align=left;" value="1. Top App / Sample" vertex="1">
<mxGeometry height="120" width="1180" x="40" y="40" as="geometry" />
</mxCell>
<mxCell id="apiLayer" parent="1" style="swimlane;html=1;startSize=34;horizontal=1;fillColor=#d5e8d4;strokeColor=#82b366;fontStyle=1;align=left;" value="2. Public API / gvfg.dll" vertex="1">
<mxGeometry height="230" width="1180" x="50" y="230" as="geometry" />
</mxCell>
<mxCell id="render" parent="appLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=14;" value="helpers/gvfg_preview&lt;br&gt;optional gvfg_preview.dll" vertex="1">
<mxGeometry height="58" width="330" x="820" y="45" as="geometry" />
</mxCell>
<mxCell id="publicHeader" parent="apiLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="sdk/gvfg/include/gvfg_capture.h&lt;br&gt;customer-facing C API" vertex="1">
<mxGeometry height="58" width="280" x="450" y="50" as="geometry" />
</mxCell>
<mxCell id="gpuConvert" parent="apiLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="sdk/gvfg/src/gpu&lt;br&gt;D3D11 YUY2/Y210 conversion&lt;br&gt;BGRA8 / RGB10A2 readback" vertex="1">
<mxGeometry height="72" width="300" x="820" y="45" as="geometry" />
</mxCell>
<mxCell id="backendLayer" parent="1" style="swimlane;html=1;startSize=34;horizontal=1;fillColor=#fff2cc;strokeColor=#d6b656;fontStyle=1;align=left;" value="3. SDK Internal Backend / Data Flow" vertex="1">
<mxGeometry height="275" width="1180" x="50" y="515" as="geometry">
<mxRectangle height="34" width="240" x="50" y="515" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="backendTypes" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="GigabyteLib backend adapter&lt;br&gt;per-channel context / Windows HANDLE&lt;br&gt;GvfgSdk.lib" vertex="1">
<mxGeometry height="58" width="285" x="30" y="95" as="geometry" />
</mxCell>
<mxCell id="workers" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="per-channel workers&lt;br&gt;caller read thread waits DMA&lt;br&gt;event thread waits format / plug events" vertex="1">
<mxGeometry height="52" width="280" x="510" y="173" as="geometry" />
</mxCell>
<mxCell id="gigabyteSession" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="CH0 + CH1 GigabyteCaptureSession&lt;br&gt;independent events / state / direct frame read" vertex="1">
<mxGeometry height="58" width="340" x="420" y="65" as="geometry" />
</mxCell>
<mxCell id="e6" edge="1" parent="backendLayer" source="gigabyteSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="backendTypes" value="uses">
<mxCell id="eCapImpl" parent="1" edge="1" source="capDll" target="facade" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;entryX=0.75;entryY=0;exitX=0.75;exitY=1;" value="">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e7" edge="1" parent="backendLayer" source="gigabyteSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="workers" value="owns">
<mxGeometry relative="1" x="-0.004" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="qtSample" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=14;" value="samples/gvfg_qt_preview&lt;br&gt;MainWindow / PreviewWindow" vertex="1">
<mxGeometry height="52" width="270" x="275" y="85" as="geometry" />
</mxCell>
<mxCell id="customerApp" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=14;" value="Customer application" vertex="1">
<mxGeometry height="52" width="230" x="715" y="85" as="geometry" />
</mxCell>
<mxCell id="facade" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="gvfg_handle_t&lt;br&gt;shared device connection&lt;br&gt;channels[0] + channels[1] facade state" vertex="1">
<mxGeometry height="58" width="340" x="470" y="385" as="geometry" />
</mxCell>
<mxCell id="ring" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="one outstanding frame per channel&lt;br&gt;copy_buffer_ or driver pointer&lt;br&gt;read / held / release" vertex="1">
<mxGeometry height="58" width="270" x="880" y="610" as="geometry" />
</mxCell>
<mxCell id="eventFlow" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=13;" value="Public event flow&lt;br&gt;hVideoFormatChangedEvent -&gt; VIDEO_FORMAT_CHANGED&lt;br&gt;hVideoInputPluginEvent / hVideoInputUnplugEvent -&gt; matching public event" vertex="1">
<mxGeometry height="82" width="330" x="850" y="690" as="geometry" />
</mxCell>
<mxCell id="externalBoundary" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#f5f5f5;strokeColor=#666666;dashed=1;fontColor=#333333;fontSize=14;" value="vfg100.sys / FPGA / DMA frame and events" vertex="1">
<mxGeometry height="52" width="280" x="410" y="900" as="geometry" />
</mxCell>
<mxCell id="e1" edge="1" parent="1" source="qtSample" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="publicHeader" value="include / link">
<mxCell id="eOsdImpl" parent="1" edge="1" source="osdDll" target="osdCore" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;" value="">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e3" edge="1" parent="1" source="publicHeader" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="facade" value="exports">
<mxCell id="ePbImpl" parent="1" edge="1" source="pbDll" target="pbCore" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;entryX=0.7;entryY=0;exitX=0.7;exitY=1;" value="">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="eGpu" edge="1" parent="1" source="publicHeader" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="gpuConvert" value="gvfg_gpu_convert_to_buffer">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="ePreviewGpu" edge="1" parent="1" source="render" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="gpuConvert" value="shared pipeline source">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e4" edge="1" parent="1" source="qtSample" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="render" value="private preview">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e5" edge="1" parent="1" source="facade" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="gigabyteSession" value="backend API calls">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e8" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="ring" value="">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e11" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="eventFlow" value="callback / queue">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e9" edge="1" parent="1" source="gigabyteSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="facade" value="frames / events / status">
<mxCell id="eAppPath" parent="1" edge="1" source="facade" target="pbCore" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;dashed=1;strokeColor=#b85450;fontColor=#b85450;fontSize=12;labelBackgroundColor=#fff2cc;exitX=0.9;exitY=0;entryX=0.2;entryY=0;" value="">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="420" y="589" />
<mxPoint x="420" y="434" />
<mxPoint x="376" y="380" />
<mxPoint x="938" y="380" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="e10" edge="1" parent="1" source="externalBoundary" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="gigabyteSession" value="input boundary">
<mxCell id="eOsdHook" parent="1" edge="1" source="osdGpu" target="frameProc" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;fontSize=10;labelBackgroundColor=#fff2cc;exitX=0;exitY=0.5;entryX=1;entryY=0.5;" value="attaches&lt;br&gt;channel OSD">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="eBackend" parent="1" edge="1" source="facade" target="session" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;fontSize=11;labelBackgroundColor=#ffffff;exitX=0;exitY=0.5;entryX=0;entryY=0.5;" value="backend calls /&lt;br&gt;frames, events">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="550" y="780" />
<mxPoint x="550" y="780" />
<mxPoint x="55" y="475" />
<mxPoint x="55" y="761" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="eVendor" parent="1" edge="1" source="session" target="vendorLib" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;fontSize=11;labelBackgroundColor=#f5f5f5;exitX=1;exitY=0.4;entryX=0;entryY=0.5;" value="vendor API">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="eDriver" parent="1" edge="1" source="vendorLib" target="driver" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;dashed=1;" value="">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="eAudioOut" parent="1" edge="1" source="audioOut" target="osOut" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;fontSize=11;labelBackgroundColor=#ffffff;exitX=0.3;exitY=1;entryX=0.3;entryY=0;" value="WASAPI render">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="ePresent" parent="1" edge="1" source="preview" target="osOut" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;endArrow=block;strokeWidth=2;fontSize=11;labelBackgroundColor=#ffffff;exitX=1;exitY=0.5;entryX=1;entryY=0.5;" value="DXGI&lt;br&gt;Present">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1228" y="550" />
<mxPoint x="1228" y="761" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="appPathLabel" parent="1" vertex="1" style="text;html=1;strokeColor=none;fillColor=#ffffff;fontSize=12;fontColor=#b85450;align=center;verticalAlign=middle;" value="read → submit (Playback copies) → release">
<mxGeometry x="660" y="369" width="250" height="22" as="geometry" />
</mxCell>
<!-- Legend -->
<mxCell id="legend" parent="1" vertex="1" style="text;html=1;strokeColor=none;fillColor=none;fontSize=12;fontColor=#555555;align=left;verticalAlign=top;" value="Solid border: always shipped · dashed border: optional DLL or external component · red dashed arrow: data passes through the application, not a direct DLL-to-DLL call">
<mxGeometry x="40" y="870" width="1200" height="22" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
+304 -231
View File
@@ -1,15 +1,18 @@
# GVFG 客戶 API 使用手冊
# GVFG Customer API Guide
本文件說明 SDK 3.1.0 的公開擷取介面 `gvfg_capture.h`。
影像/音訊/同步播放另使用 `gvfg_playback.h`,完整流程見
[統一影音播放使用手冊](GVFG_PLAYBACK_API.md)。Capture 與 Playback 是不同 handle 與 DLL。
English | [繁體中文](GVFG_CUSTOMER_API.zh-TW.md)
先依下列流程完成擷取整合;逐參數定義與完整限制見
[API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
This guide covers the public capture interface `gvfg_capture.h` in SDK 3.2.0, and the optional
OSD interface `gvfg_osd.h`. Video, audio, and synchronized playback use `gvfg_playback.h`; see the
[Unified Playback Guide](GVFG_PLAYBACK_API.md) for the full flow. Capture, OSD, and Playback are
separate DLLs, and Capture and Playback use separate handles.
## 1. 套件內容
Follow the flow below to integrate capture. For per-parameter definitions and all limits, see the
[API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md).
核心擷取:
## 1. Package contents
Core capture:
```text
include/gvfg_capture.h
@@ -17,9 +20,19 @@ lib/gvfg.lib
bin/gvfg.dll
```
核心擷取只需連結 `gvfg.lib`,並部署相同版本的 `gvfg.dll`。
Core capture only needs `gvfg.lib` at link time and the matching `gvfg.dll` at run time.
選用播放(純影像、純音訊或影音):
Optional OSD (font list, text measurement, channel OSD, standalone BGRA overlay):
```text
include/gvfg_osd.h
lib/gvfg_osd.lib
bin/gvfg_osd.dll
```
`gvfg_osd.dll` depends on the `gvfg.dll` from the same SDK build; update both together.
Optional playback (video-only, audio-only, or audio-video):
```text
include/gvfg_playback.h
@@ -27,9 +40,10 @@ lib/gvfg_playback.lib
bin/gvfg_playback.dll
```
目前支援 Windows x64。API 使用 C ABI,可由 C 或 C++ 呼叫。
MinGW uses the matching `libgvfg.dll.a`, `libgvfg_osd.dll.a`, and `libgvfg_playback.dll.a`.
Windows x64 is currently supported. The API uses a C ABI and can be called from C or C++.
## 2. 最小擷取流程
## 2. Minimal capture flow
```text
gvfg_enumerate_devices
@@ -38,19 +52,19 @@ gvfg_enumerate_devices
-> gvfg_open_channel
-> gvfg_set_channel_audio_enabled (optional, before start)
-> gvfg_start_channel
-> 重複:
-> repeat:
gvfg_read_channel_frame
使用/複製/轉換 frame
use / copy / convert the frame
gvfg_release_channel_frame
若已啟用 audio,另一個 worker thread 重複:
if audio is enabled, on a separate worker thread repeat:
gvfg_read_channel_audio_frame
使用/複製 PCM
use / copy the PCM
gvfg_release_channel_audio_frame
-> gvfg_stop
-> gvfg_destroy
```
完整範例:
Complete example:
```c
#include <gvfg_capture.h>
@@ -79,7 +93,7 @@ int main(void)
if (st != GVFG_OK)
break;
/* 在 release 前處理、轉換或複製 frame.data。 */
/* Process, convert, or copy frame.data before release. */
st = gvfg_release_channel_frame(h, GVFG_CHANNEL_0, &frame);
if (st != GVFG_OK)
@@ -93,168 +107,191 @@ int main(void)
}
```
## 3. 執行緒與 frame 所有權
## 3. Threading and frame ownership
- API 是 pull model;應用程式自行決定在哪個執行緒呼叫
`gvfg_read_channel_frame()`。GUI 程式建議每個 channel 使用一個 worker thread,再把 UI 更新送回
UI thread。
- `frame.data` 是唯讀的借用 pointer,可能指向原生擷取 buffer 或 SDK 處理後的
buffer。Zero-copy 設定控制擷取方式;啟用 OSD 時仍可能交付 SDK-owned buffer。
Pointer 只在對應的 `gvfg_release_channel_frame()` 前有效,資料若要長期保存,必須先複製。
- 每個 channel 同時最多持有一個 frame。尚未 release 又對同一 channel 呼叫
`gvfg_read_channel_frame()`,會回傳 `GVFG_ESTATE`。
- release 時傳回 read 取得的 `gvfg_frame_t`;不要自行修改 frame descriptor 的內容。
- `gvfg_stop()` 會中止等待並使尚未 release 的 frame 失效。
- 同一個 handle 的 lifecycle 操作應由應用程式自行序列化;不要同時 open、
start、stop 或 destroy。
- The API is pull-based; the application decides which thread calls
`gvfg_read_channel_frame()`. GUI applications should use one worker thread per channel and
post UI updates back to the UI thread.
- `frame.data` is a read-only borrowed pointer. It may point to the native capture buffer or to an
SDK-processed buffer. The zero-copy setting controls acquisition; with OSD enabled, the SDK may
still deliver an SDK-owned buffer. The pointer is valid only until the matching
`gvfg_release_channel_frame()`; copy the data if it must be kept longer.
- Each channel holds at most one frame at a time. Calling `gvfg_read_channel_frame()` again on the
same channel before release returns `GVFG_ESTATE`.
- Pass the `gvfg_frame_t` returned by read back to release; do not modify the frame descriptor.
- `gvfg_stop()` aborts waits and invalidates unreleased frames.
- The application must serialize lifecycle operations on a handle; do not open, start, stop, or
destroy concurrently.
Audio 採用相同的 pull 與 ownership 模型:
Audio uses the same pull and ownership model:
- 建議使用獨立 audio worker thread,避免阻塞 video read 或 UI thread。
- `gvfg_audio_frame_t.data` 是 SDK-owned PCM,只在對應的
`gvfg_release_channel_audio_frame()` 前有效。
- 同一 channel 同時只能持有一個 audio frame;未 release 再 read 會回傳
`GVFG_ESTATE`。
- release 時傳回 read 取得的 `gvfg_audio_frame_t`;不要自行修改 frame descriptor 的內容。
- 若播放或錄音需要在 release 後繼續使用 PCM,Application 必須先複製。
- Capture 保有自己的交付 buffer;播放副本、queue、同步與輸出由 Playback 管理。
- 使用 Playback 時,submit 已完成複製後即可 release,Demo 不自行實作音訊調速或同步。
- 播放錯誤由 Playback API 回傳狀態碼回報,caller 決定停止與重啟。
輸出裝置故障後,應用程式須處理錯誤並決定是否重新啟動播放。
- Use a separate audio worker thread so that audio does not block video reads or the UI thread.
- `gvfg_audio_frame_t.data` is SDK-owned PCM, valid only until the matching
`gvfg_release_channel_audio_frame()`.
- Each channel holds at most one audio frame at a time; reading again before release returns
`GVFG_ESTATE`.
- Pass the `gvfg_audio_frame_t` returned by read back to release; do not modify the descriptor.
- If playback or recording needs the PCM after release, the application must copy it first.
- Capture keeps its own delivery buffers; playback copies, queues, synchronization, and output are
managed by Playback.
- With Playback, release the frame once submit has copied it; the demo does not implement its own
audio rate adjustment or synchronization.
- Playback errors are reported through Playback API status codes, and the caller decides whether to
stop and restart. After an output-device failure, the application handles the error and decides
whether to restart playback.
`timeout_ms` 的共同規則:`0` 表示不等待;`GVFG_TIMEOUT_INFINITE` 表示無限等待;
其他值的單位為毫秒。
Common `timeout_ms` rule: `0` does not wait; `GVFG_TIMEOUT_INFINITE` waits indefinitely; other
values are in milliseconds.
## 4. 狀態碼
## 4. Status codes
| 狀態 | 說明 |
| --------------- | --------------------------- |
| `GVFG_OK` | 成功 |
| `GVFG_EINVAL` | 參數、channel 或 frame token 無效 |
| `GVFG_ENODEV` | 找不到裝置或裝置無法開啟 |
| `GVFG_ESTATE` | 呼叫時機或 handle 狀態不正確 |
| `GVFG_EIO` | 擷取、轉換或其他 I/O 失敗 |
| `GVFG_ENOTSUP` | 格式或功能不支援 |
| `GVFG_ETIMEOUT` | 等待逾時 |
| `GVFG_EBUSY` | 裝置或 capture resource 正在使用中 |
| Status | Meaning |
| --------------- | ----------------------------------------------- |
| `GVFG_OK` | Success |
| `GVFG_EINVAL` | Invalid argument, channel, or frame token |
| `GVFG_ENODEV` | No device found, or the device cannot be opened |
| `GVFG_ESTATE` | Wrong call timing or handle state |
| `GVFG_EIO` | Capture, conversion, or other I/O failure |
| `GVFG_ENOTSUP` | Format or feature not supported |
| `GVFG_ETIMEOUT` | Wait timed out |
| `GVFG_EBUSY` | Device or capture resource is in use |
公開 API 不暴露底層 capture library 的錯誤型別。所有失敗都會轉成上述
`GVFG_E*` 狀態;Application 應使用 `status != GVFG_OK` 判斷,不可套用
Windows `FAILED()`/`SUCCEEDED()`。
The public API does not expose the underlying capture library's error types. Every failure is
mapped to one of the `GVFG_E*` statuses above. Test with `status != GVFG_OK`; do not use the
Windows `FAILED()`/`SUCCEEDED()` macros.
可用 `gvfg_strerror()` 取得靜態英文說明字串;呼叫端不可釋放該字串。
`gvfg_strerror()` returns a static English description; the caller must not free it.
可用 `gvfg_get_version()` 查詢目前實際載入的 `gvfg.dll` 版本。回傳值為
靜態字串,例如 `"3.1.0"`,呼叫端不可釋放。
需要記錄最近一次失敗的詳細原因時,可在 API 失敗後立即呼叫
`gvfg_get_channel_last_sdk_error_detail()`。此 API 回傳可供問題回報使用的公開診斷文字。
`gvfg_get_version()` returns the version of the `gvfg.dll` actually loaded, as a static string such
as `"3.2.0"`; the caller must not free it. To record the detailed reason for the most recent
failure, call `gvfg_get_channel_last_sdk_error_detail()` immediately after the failing call. It
returns public diagnostic text suitable for problem reports.
## 5. 資料格式
## 5. Data formats
### 原生擷取格式
### Native capture formats
| 格式 | `pixel_format` | bit depth | 每列大小 |
| ----------------- | ------------------:| ---------:| -----------:|
| YUY2 packed 4:2:2 (`Y0 U0 Y1 V0`) | `GVFG_PIXFMT_YUY2` | 8 | `width * 2` |
| Y210 packed 4:2:2 | `GVFG_PIXFMT_Y210` | 10 | `width * 4` |
| Format | `pixel_format` | Bit depth | Row size |
| --------------------------------- | ------------------:| ---------:| -----------:|
| YUY2 packed 4:2:2 (`Y0 U0 Y1 V0`) | `GVFG_PIXFMT_YUY2` | 8 | `width * 2` |
| Y210 packed 4:2:2 | `GVFG_PIXFMT_Y210` | 10 | `width * 4` |
實際列距以 `gvfg_frame_t.row_stride_bytes` 為準。
目前不支援的輸入格式會回傳 `GVFG_ENOTSUP`。可用
`gvfg_pixel_format_name()` 取得靜態格式名稱。
Always use `gvfg_frame_t.row_stride_bytes` as the actual row pitch. Currently unsupported input
formats return `GVFG_ENOTSUP`. `gvfg_pixel_format_name()` returns a static format name.
### `gvfg_frame_t`
- `data`、`data_size`:SDK buffer 與可用 byte 數。
- `width`、`height`:影像尺寸。
- `row_stride_bytes`:相鄰兩列起點的 byte 距離。
- `pixel_format`、`bit_depth`:原生 payload 格式。
- `frame_id`:SDK 成功交付序號;每次 channel Start 從 1 重新開始。
- `timestamp_ns`:SDK monotonic delivery timestamp,與 audio 使用相同 clock domain。
- `data`, `data_size`: SDK buffer and its usable byte count.
- `width`, `height`: image size.
- `row_stride_bytes`: byte distance between the starts of adjacent rows.
- `pixel_format`, `bit_depth`: native payload format.
- `frame_id`: SDK delivery sequence number; restarts at 1 on every channel start.
- `timestamp_ns`: SDK monotonic delivery timestamp, in the same clock domain as audio.
### PCM audio
`gvfg_audio_format_t` 只提供上層實際需要的播放格式:`sample_rate`、
`channels`、`bits_per_sample`。Driver frame 大小與 block alignment 是 backend
細節,不要求 Application 配置相同大小的 buffer。
`gvfg_audio_format_t` provides only the playback format the application needs: `sample_rate`,
`channels`, and `bits_per_sample`. Driver frame size and block alignment are backend details; the
application does not need to allocate buffers of the same size.
`gvfg_audio_frame_t` 包含:
`gvfg_audio_frame_t` contains:
- `data`、`data_size`:SDK-owned PCM 與本次有效 byte 數。
- `sample_rate`、`channels`、`bits_per_sample`:此 frame 的 PCM 格式。
- `frame_id`:SDK 成功交付序號;每次 channel Start 從 1 重新開始。
- `timestamp_ns`:SDK monotonic delivery timestamp,與 video 使用相同 clock domain。
- `data`, `data_size`: SDK-owned PCM and its valid byte count for this frame.
- `sample_rate`, `channels`, `bits_per_sample`: PCM format of this frame.
- `frame_id`: SDK delivery sequence number; restarts at 1 on every channel start.
- `timestamp_ns`: SDK monotonic delivery timestamp, in the same clock domain as video.
`timestamp_ns` 用於比較同一 process/session 內的 video/audio delivery timing;它
不是 driver 或硬體 capture timestamp。
Use `timestamp_ns` to compare video and audio delivery timing within the same process/session. It
is not a driver or hardware capture timestamp.
目前 audio 僅支援 CH0,且必須與 video 一起啟動;不支援 audio-only。公開
audio API 不是 zero-copy,但上層仍使用和 video 相同的 read/release contract。
Audio is currently supported on CH0 only and must start together with video; audio-only capture is
not supported. The public audio API is not zero-copy, but it uses the same read/release contract as
video.
## 6. 公開 API
## 6. Public API
### 裝置與生命週期
### Devices and lifecycle
- `gvfg_enumerate_devices(out_devices, max_devices)`:列舉裝置。傳入
`NULL, 0` 可只查數量;回傳值是寫入數量或可用裝置數,無裝置時為 `0`。
- `gvfg_create(&handle)`:建立 closed session。
- `gvfg_set_channel_zero_copy_enabled(handle, channel, enabled)`:替指定 channel
選用 zero-copy;只能在該 channel open 前呼叫,預設為關閉。
- `gvfg_get_channel_zero_copy_enabled(handle, channel, &enabled)`:查詢指定
channel 選擇的模式。
- `gvfg_open_channel(handle, device_index, channel)`:開啟列舉所得裝置,channel
必須為 `GVFG_CHANNEL_0` 或 `GVFG_CHANNEL_1`。
- `gvfg_start_channel(handle, channel)`:開始指定 channel 擷取。每次明確 Start 都會重新查詢一次
signal;若目前沒有 lock,回傳 `GVFG_ETIMEOUT`,channel 維持 stopped,接上訊號後須由
Application 再次呼叫 Start。
- `gvfg_stop(handle)`:停止擷取;重複呼叫仍回傳成功。
- `gvfg_destroy(handle)`:必要時先停止,再銷毀 handle。銷毀後不得再使用。
- `gvfg_enumerate_devices(out_devices, max_devices)`: enumerate devices. Pass `NULL, 0` to query
the count only. Returns the number written or the number available; `0` when there is no device.
- `gvfg_create(&handle)`: create a closed session.
- `gvfg_set_channel_zero_copy_enabled(handle, channel, enabled)`: select zero-copy for a channel.
Call only before that channel is opened; the default is off.
- `gvfg_get_channel_zero_copy_enabled(handle, channel, &enabled)`: query the mode selected for a
channel.
- `gvfg_open_channel(handle, device_index, channel)`: open an enumerated device; `channel` must be
`GVFG_CHANNEL_0` or `GVFG_CHANNEL_1`.
- `gvfg_start_channel(handle, channel)`: start capture on a channel. Every explicit start queries
the signal once. If there is no lock, it returns `GVFG_ETIMEOUT` and the channel stays stopped;
the application must call start again after the signal is connected.
- `gvfg_stop_channel(handle, channel)`: stop only the given channel; the other channel keeps
capturing.
- `gvfg_stop(handle)`: stop every opened channel on the handle; repeated calls still succeed.
- `gvfg_destroy(handle)`: stop if necessary, then destroy the handle. Do not use it afterwards.
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。
Zero-copy mode must be selected before the channel is opened. To switch modes, destroy and
recreate the session. Every successful `gvfg_read_channel_frame()` still requires
`gvfg_release_channel_frame()` to end the public pointer/token lifetime; under the current library
contract no per-frame driver release is sent. The mode cannot be switched after the device is
opened: destroy the session, create it again, set the mode, then open.
### Frame
### Frames
- `gvfg_read_channel_frame(handle, channel, &frame, timeout_ms)`:取得原生或 SDK 處理後的唯讀
frame;copy/zero-copy acquisition 的 release contract 相同。
- `gvfg_release_channel_frame(handle, channel, &frame)`:釋放原 frame token。
- `gvfg_read_channel_frame(handle, channel, &frame, timeout_ms)`: get a read-only native or
SDK-processed frame. Copy and zero-copy acquisition share the same release contract.
- `gvfg_release_channel_frame(handle, channel, &frame)`: release the original frame token.
### SDK OSD
使用 OSD 時請包含 `gvfg_osd.h`,連結 `gvfg_osd.lib`(MinGW 使用 `libgvfg_osd.dll.a`),並隨應用程式部署同一次 SDK 建置的 `gvfg_osd.dll` 和 `gvfg.dll`。一般擷取只需連結 `gvfg.dll` 對應的 import library。
To use OSD, include `gvfg_osd.h`, link `gvfg_osd.lib` (`libgvfg_osd.dll.a` for MinGW), and deploy
`gvfg_osd.dll` and `gvfg.dll` from the same SDK build with the application. Plain capture only
needs the import library for `gvfg.dll`.
每個已 open 的 channel 可設定兩組 OSD,`osd_index` 為 `0`、`1`;重疊時第 `1` 組在上方。
OSD 會加入後續取得的 YUY2/Y210 frame,preview、snapshot 或錄影是否顯示 OSD,
取決於它們是否使用這份 frame。
Each opened channel has two OSD slots, `osd_index` `0` and `1`; where they overlap, slot `1` is on
top. OSD is applied to subsequently read YUY2/Y210 frames. Whether a preview, snapshot, or
recording shows the OSD depends on whether it uses those frames.
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。
1. Call `gvfg_get_osd_fonts(&list)` to get the available fonts, and copy the chosen UTF-8 name.
Customers can install new fonts in Windows and query the list again. The SDK manages the list,
so no callback or free is needed. The pointers are valid until the next list query or DLL
unload, and the caller must serialize querying and reading the list.
2. Fill in `gvfg_channel_osd_config_t`: text, `font_family`, size, color, and `x/y`.
`text` is a NUL-terminated string of 1–32 printable ASCII characters; Chinese text and line
breaks are not accepted. The font name is a NUL-terminated UTF-8 string, not a file path. The
font size must be greater than 0.
3. Measure with `gvfg_measure_osd_text(&config, &width, &height)`, then call
`gvfg_set_channel_osd(handle, channel, osd_index, &config)` to configure and show that slot.
Set copies the strings before it returns, so the caller does not need to keep them.
4. To hide a slot temporarily, call `gvfg_set_channel_osd_visible(..., 0)`; use `1` to show it
again. Hide/show keeps the slot's settings; only `gvfg_clear_channel_osd()` clears the slot, after
which it must be set again.
`x/y` 是量測文字框左上角;位置會限制在影像內。文字框本身放不下時,該組暫停顯示,
另一組與擷取繼續;文字或影像尺寸調整後可恢復。不自動縮字、截字或換行。
無效字型/文字/組別回傳 `GVFG_EINVAL`;尚未設定的組別不能直接 Show。
SDK handle 銷毀後,應用程式需自行保存並重設所需的 OSD 設定。
To hand the OSD to an FPGA or another component for compositing, call
`gvfg_render_osd_frame_bgra(video_width, video_height, slot0, slot1, &bitmap)`. It needs no
capture handle and produces a top-down, premultiplied BGRA8888 image with a transparent background,
the same size as the video, with a stride of `width * 4`. Pass NULL for `slot0`/`slot1` to omit that
slot. The output is SDK-owned and valid until the next call to this function on the same thread
(including a failed call), thread exit, or DLL unload; copy it before any asynchronous transfer. This
function does not affect the channel's GPU OSD.
完整欄位、字級定義、回傳值與限制見
[API Reference:OSD](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md#226-osd-字型設定顯示隱藏與清除)。
`x/y` is the top-left corner of the measured text box; the position is clamped to stay inside the
frame. If the text box itself does not fit, that slot is paused while the other slot and capture
continue; it resumes once the text or frame size allows it to fit. Text is never shrunk, truncated,
or wrapped. Invalid fonts, text, or slots return `GVFG_EINVAL`; a slot that has never been set
cannot be shown directly. After the SDK handle is destroyed, the application must keep and reapply
any OSD settings it needs.
### OSD 呼叫範例
For all fields, size definitions, return values, and limits, see
[API Reference: OSD](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md#3-osd-api).
以下 C++ 範例假設 `handle` 的 `channel` 已 open。先選擇清單中的實際字型,
立即複製名稱,再使用相同設定量測與繪製;每一步都檢查回傳值。
### OSD example
The following C++ example assumes `channel` is already open on `handle`. It picks an actual font
from the list, copies the name immediately, then measures and draws with the same settings,
checking every return value.
```cpp
#include <gvfg_capture.h>
#include <gvfg_osd.h> // includes gvfg_capture.h
#include <string>
gvfg_status_t configure_osd(gvfg_handle handle, int channel)
@@ -289,9 +326,10 @@ gvfg_status_t configure_osd(gvfg_handle handle, int channel)
}
```
Set 返回前已複製字串,函式內的 `family` 可正常離開作用域。兩次 Set 各自生效;
若第二次失敗,第一組仍保持成功設定。下列是之後對第二組的三個獨立操作範例,
並非必須連續執行的初始化步驟;每個結果仍須檢查。
Set copies the strings before returning, so `family` can go out of scope normally. Each Set takes
effect on its own; if the second one fails, the first slot stays configured. The following are three
independent later operations on the second slot, not initialization steps that must run in
sequence; check each result.
```cpp
auto status = gvfg_set_channel_osd_visible(handle, channel, 1, 0); // Hide
@@ -302,89 +340,121 @@ status = gvfg_clear_channel_osd(handle, channel, 1); // Clear
if (status != GVFG_OK) return status;
```
### SDK 3.0.0 介面遷移
### Migrating to SDK 3.2.0
- OSD 的 `set`/`clear` 新增 `osd_index`;原先的一組設定改為每 channel 兩組。
- `gvfg_channel_osd_config_t` 改用 NUL 結尾字串、移除 `text_length`,新增 `font_family`;
量測函式改收同一份設定,沒有舊版相容入口。
- 公開 Playback 移除 `gvfg_playback_stats_t` 與 `gvfg_playback_get_stats()`。
一般顯示資訊與呈現統計改用 `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 不提供兩組一起更新的交易保證。
- OSD functions and types moved from `gvfg_capture.h`/`gvfg.dll` to `gvfg_osd.h`/`gvfg_osd.dll`.
Applications that use OSD must include `gvfg_osd.h`, link `gvfg_osd.lib`, and deploy
`gvfg_osd.dll`. Function names and parameters are unchanged, but existing applications must be
recompiled and relinked.
- Added `gvfg_get_channel_hdmi_audio_info()`.
### Audio frame
### Migrating to SDK 3.1.0
- `gvfg_set_channel_audio_enabled(handle, channel, enabled)`:在 start 前啟用或停用
audio;video 永遠保留,不需要組合 stream flags。
- `gvfg_get_channel_audio_format(handle, channel, &format)`:取得 PCM 播放格式。
- `gvfg_read_channel_audio_frame(handle, channel, &frame, timeout_ms)`:取得一個
SDK-owned PCM frame。
- `gvfg_release_channel_audio_frame(handle, channel, &frame)`:釋放原 audio token。
- Added `gvfg_get_channel_hdmi_info()` and `gvfg_get_chip_info()`.
- The full-frame OSD overlay function was renamed to `gvfg_render_osd_frame_bgra()`, replacing
`gvfg_render_osd_bgra()`.
成功 read 後,不論 PCM 是送往播放、錄音或被丟棄,都必須正好 release 一次。
### Migrating to SDK 3.0.0
`gvfg_set_channel_video_format()` 可在 stream 尚未開始或已 stop 時選擇 YUY2/Y210。
此功能由 SDK 的 capture backend 實作。
- OSD `set`/`clear` gained an `osd_index`; the single configuration became two slots per channel.
- `gvfg_channel_osd_config_t` now uses NUL-terminated strings, drops `text_length`, and adds
`font_family`. The measurement function takes the same configuration; there is no compatibility
entry point for the old form.
- Public Playback removed `gvfg_playback_stats_t` and `gvfg_playback_get_stats()`. Use
`gvfg_playback_get_preview_info()` and `gvfg_playback_get_preview_stats()` for general display
information and presentation statistics.
- Public Playback also removed `gvfg_preview_delivery_stats_t` and
`gvfg_playback_get_delivery_stats()`; detailed queue and presentation counters moved to the
internal Debug API with no public compatibility entry point.
- The font list does not need a capture handle. Pick an actually installed font, then measure/set
the OSD and check every return value. A Set on one slot does not provide a transactional guarantee
of updating both slots together.
### 查詢
### Audio frames
- `gvfg_get_version()`:目前載入的 GVFG runtime 版本。
- `gvfg_get_gigabyte_lib_version()`:編譯進該 runtime 的 GigabyteLib 版本;不是 driver
或 FPGA 的執行時版本查詢。兩者回傳靜態字串,不需要 handle 或 free。
- `gvfg_get_channel_signal_status(handle, channel, &status)`:查詢指定 channel 的連線、尺寸、
原生格式與 bit depth。沒有輸入訊號是正常狀態:回傳 `GVFG_OK` 且
`connected == 0`。Channel 尚未 running 時會向 capture backend 更新;running 期間則回傳
SDK cache,不再額外讀取硬體。
- `gvfg_get_channel_runtime_info(handle, channel, &info)`:取得指定 channel 已交付 frame 數與
依 read 間隔估算的 `capture_fps`。start 時統計值重設。
- `gvfg_set_channel_audio_enabled(handle, channel, enabled)`: enable or disable audio before start.
Video is always kept; there are no stream flags to combine.
- `gvfg_get_channel_audio_format(handle, channel, &format)`: get the PCM playback format.
- `gvfg_read_channel_audio_frame(handle, channel, &frame, timeout_ms)`: get one SDK-owned PCM frame.
- `gvfg_release_channel_audio_frame(handle, channel, &frame)`: release the original audio token.
### Event
After a successful read, release exactly once, whether the PCM goes to playback, to recording, or is
discarded.
`gvfg_poll_channel_event(handle, channel, &event, timeout_ms)` 一次取出指定 channel 的事件,只能在 running
狀態使用。stop 會喚醒阻塞中的 poll,並回傳 `GVFG_ESTATE`。
`gvfg_set_channel_video_format()` selects YUY2/Y210 while the stream has not started or has been
stopped. It is implemented by the SDK's capture backend.
| Event | 應用程式動作 |
| -------------------------------- | --------------------------- |
| `GVFG_EVENT_VIDEO_FORMAT_CHANGED` | Lib 的 video format changed event |
| `GVFG_EVENT_VIDEO_INPUT_PLUGIN` | Lib 的 video input plug-in event |
| `GVFG_EVENT_VIDEO_INPUT_UNPLUG` | Lib 的 video input unplug event |
### Queries
`event` 使用 `gvfg_event_type_t`;SDK 直接寫入本次取出的事件種類。
SDK 會在 format changed、input plug-in 或 input unplug event 放入 public queue 前先同步
signal cache。Application 收到事件後可呼叫 `gvfg_get_channel_signal_status()` 取得對應的新狀態;
running 期間此查詢讀取 cache,不會再次向 driver 查詢。
- `gvfg_get_version()`: version of the loaded GVFG runtime.
- `gvfg_get_gigabyte_lib_version()`: version of GigabyteLib compiled into that runtime; it is not a
run-time driver or FPGA version query. Both return static strings and need no handle or free.
- `gvfg_get_channel_signal_status(handle, channel, &status)`: connection state, size, native
format, and bit depth of a channel. No input signal is a normal state: it returns `GVFG_OK` with
`connected == 0`. While the channel is not running, the status is refreshed from the capture
backend; while running, the SDK cache is returned without reading the hardware again.
- `gvfg_get_channel_runtime_info(handle, channel, &info)`: frames delivered on the channel and
`capture_fps` estimated from read intervals. The statistics reset on start.
- `gvfg_get_channel_sdi_info(handle, channel, &info)`: raw values and display strings for SDI mode,
resolution, fps, scan, ST 352, and so on.
- `gvfg_get_channel_hdmi_info(handle, channel, &info)`: HDMI lock, width/height, FPS, color format,
color space, and bit depth.
- `gvfg_get_channel_hdmi_audio_info(handle, channel, &info)`: HDMI audio lock, sample-frequency
code, bits per sample, channel count, and format code.
- `gvfg_get_chip_info(handle, &info)`: chip version date and time; at least one channel on the
handle must be open.
## 7. GPU 同步轉換
Use the `video_interface` from `gvfg_get_channel_signal_status()` to choose between the SDI and HDMI
queries. All of these queries require the channel to be open and otherwise return `GVFG_ESTATE`;
use the output only when the call returns `GVFG_OK`.
GPU 轉換在 `gvfg.dll` 內完成,呼叫是同步的。必須在
`gvfg_release_channel_frame()` 前轉換;函式返回後 SDK 不保留 source 或 destination
pointer。
### Events
支援輸出:
`gvfg_poll_channel_event(handle, channel, &event, timeout_ms)` takes one event for the given
channel and can only be used while running. Stop wakes a blocked poll, which then returns
`GVFG_ESTATE`.
| 格式 | 配置需求 |
| ------------------------- | --------------------------------------- |
| `GVFG_GPU_OUTPUT_BGRA8` | `row_bytes >= width * 4`;alpha = 255 |
| `GVFG_GPU_OUTPUT_RGB10A2` | `row_bytes >= width * 4`;alpha = 3 |
| `GVFG_GPU_OUTPUT_NV12` | width/height 必須為偶數;`row_bytes >= width` |
| Event | Source |
| --------------------------------- | ------------------------------------- |
| `GVFG_EVENT_VIDEO_FORMAT_CHANGED` | Library video format changed event |
| `GVFG_EVENT_VIDEO_INPUT_PLUGIN` | Library video input plug-in event |
| `GVFG_EVENT_VIDEO_INPUT_UNPLUG` | Library video input unplug event |
BGRA8/RGB10A2 的 destination 至少為 `row_bytes * height`。NV12 至少為
`row_bytes * (height + height / 2)`,排列為 Y plane,接著是 interleaved UV
plane;使用 BT.709 limited range。
`event` is a `gvfg_event_type_t`; the SDK writes the kind of the event taken. Before a format
changed, input plug-in, or input unplug event is placed in the public queue, the SDK synchronizes
its signal cache. After receiving an event, the application can call
`gvfg_get_channel_signal_status()` to get the corresponding new state; while running, that query
reads the cache and does not query the driver again.
可使用通用函式 `gvfg_gpu_convert_to_buffer()`,或便利函式:
## 7. Synchronous GPU conversion
GPU conversion runs inside `gvfg.dll` and is synchronous. Convert before
`gvfg_release_channel_frame()`; after the function returns, the SDK keeps neither the source nor the
destination pointer.
Supported outputs:
| Format | Requirements |
| ------------------------- | ------------------------------------------------ |
| `GVFG_GPU_OUTPUT_BGRA8` | `row_bytes >= width * 4`; alpha = 255 |
| `GVFG_GPU_OUTPUT_RGB10A2` | `row_bytes >= width * 4`; alpha = 3 |
| `GVFG_GPU_OUTPUT_NV12` | width and height must be even; `row_bytes >= width` |
For BGRA8/RGB10A2 the destination must be at least `row_bytes * height`. For NV12 it must be at
least `row_bytes * (height + height / 2)`, laid out as the Y plane followed by the interleaved UV
plane, using BT.709 limited range.
Use the generic `gvfg_gpu_convert_to_buffer()` or a convenience function:
- `gvfg_gpu_convert_to_bgra8()`
- `gvfg_gpu_convert_to_rgb10a2()`
- `gvfg_gpu_convert_to_nv12()`
### GPU 轉換範例
### GPU conversion example
例如,要建立一個與輸入 frame 同尺寸的 BGRA8 destination:
以下片段放在回傳 `gvfg_status_t` 的函式內,使用 `<limits.h>`、`<stdint.h>`、`<stdlib.h>`;
`source` 必須有效,且尚未 release。
For example, to create a BGRA8 destination of the same size as the input frame. The snippet belongs
inside a function that returns `gvfg_status_t` and uses `<limits.h>`, `<stdint.h>`, and
`<stdlib.h>`; `source` must be valid and not yet released.
```c
if (source.width <= 0 || source.height <= 0 || source.width > INT_MAX / 4)
@@ -405,48 +475,51 @@ output.pixel_format = GVFG_GPU_OUTPUT_BGRA8;
gvfg_status_t status = gvfg_gpu_convert_to_buffer(&source, &output);
if (status == GVFG_OK) {
/* 在這裡使用 pixels。 */
/* Use pixels here. */
}
free(pixels);
return status;
```
配置前須確認尺寸乘法不會 overflow,並檢查 `malloc()` 是否成功。
不論 conversion 成功或失敗,呼叫端都需在不再使用輸出時釋放自行配置的 `pixels`。
Check that the size multiplication cannot overflow before allocating, and check that `malloc()`
succeeded. Whether the conversion succeeds or fails, free the `pixels` you allocated once you no
longer need the output.
## 8. 播放 API
## 8. Playback API
`gvfg_playback.dll` 提供影像、音訊播放與影音同步功能。
擷取仍由應用程式呼叫 `gvfg.dll`。典型流程:
`gvfg_playback.dll` provides video and audio playback and audio/video synchronization. Capture is
still done by the application through `gvfg.dll`. Typical flow:
```text
gvfg_playback_create -> attach_window -> default_config -> start
capture video/audio -> submit_video / submit_audio -> release SDK frame
停止提交 -> gvfg_playback_stop -> gvfg_playback_destroy
stop submitting -> gvfg_playback_stop -> gvfg_playback_destroy
```
submit 成功前已完成資料複製,返回後即可 release SDK frame;失敗時也必須 release,
時間不連續或輸出錯誤仍須處理;queue 壓力由 Playback 自動降級並略過過時資料,不要求停止擷取。
stop/reset 會丟棄待播資料,不代表無損排空。
單張影像用 `gvfg_playback_present_image()`,在已綁定視窗、未 start 的 handle 上同步呼叫。
詳細模式、master、緩衝與 timestamp 規則見
[`統一影音播放使用手冊`](GVFG_PLAYBACK_API.md)。
Submit has copied the data before it returns successfully, so the SDK frame can be released right
after; release it on failure too. Timestamp discontinuities and output errors still need handling.
Under queue pressure, Playback automatically degrades and skips stale data; it does not require
capture to stop. Stop and reset discard pending data; they are not a lossless drain. For a single
image, call `gvfg_playback_present_image()` synchronously on a handle that has a window attached and
is not started. For modes, masters, buffering, and timestamp rules, see the
[Unified Playback Guide](GVFG_PLAYBACK_API.md).
## 9. 錯誤處理建議
## 9. Error-handling recommendations
- `GVFG_ETIMEOUT`:連線期間通常可重試,並檢查 signal status/event。收到
`GVFG_EVENT_VIDEO_INPUT_UNPLUG` 後,不應高速輪詢 read API;應等待
`GVFG_EVENT_VIDEO_INPUT_PLUGIN`(或 application stop)再恢復 video/audio read。
- 每次成功取得的 frame 仍必須恰好 release 一次。若 release 與實體拔線競爭,
SDK 會處理 driver 已撤銷 zero-copy ownership 的情況,application 不應特判
`ERROR_BAD_COMMAND (22)`。
- `GVFG_EVENT_VIDEO_FORMAT_CHANGED`:依 Lib 更新後的 video info 重建格式相關資源。
- `GVFG_ESTATE`:檢查 lifecycle、是否重複 read、或是否已 stop。
- `GVFG_EIO`/`GVFG_ENODEV`:停止 session,記錄 `gvfg_strerror()`,再由應用程式
決定是否重新列舉與開啟。
- 不要讀寫硬體 register 或依賴 driver/backend counter;這些不是客戶 API。
- `GVFG_ETIMEOUT`: while connected, this is usually retryable; also check the signal status and
events. After `GVFG_EVENT_VIDEO_INPUT_UNPLUG`, do not poll the read API in a tight loop; wait for
`GVFG_EVENT_VIDEO_INPUT_PLUGIN` (or an application stop) before resuming video/audio reads.
- Every frame read successfully must still be released exactly once. If release races with a
physical unplug, the SDK handles the case where the driver has already revoked zero-copy
ownership; the application should not special-case `ERROR_BAD_COMMAND (22)`.
- `GVFG_EVENT_VIDEO_FORMAT_CHANGED`: rebuild format-dependent resources from the updated video info.
- `GVFG_ESTATE`: check the lifecycle, a repeated read, or whether capture has been stopped.
- `GVFG_EIO`/`GVFG_ENODEV`: stop the session, log `gvfg_strerror()`, and let the application decide
whether to enumerate and open again.
- Do not read or write hardware registers or rely on driver/backend counters; they are not part of
the customer API.
## 完整 API Reference
## Full API Reference
所有公開常數、型別、結構欄位、函式參數與回傳值,請參閱
[`GVFG_CUSTOMER_API_REFERENCE.md`](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
For every public constant, type, struct field, function parameter, and return value, see
[`GVFG_CUSTOMER_API_REFERENCE.md`](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md).
+496
View File
@@ -0,0 +1,496 @@
# GVFG 客戶 API 使用手冊
[English](GVFG_CUSTOMER_API.md) | 繁體中文
本文件說明 SDK 3.2.0 的公開擷取介面 `gvfg_capture.h`,以及選用的 OSD 介面 `gvfg_osd.h`。
影像/音訊/同步播放另使用 `gvfg_playback.h`,完整流程見
[統一影音播放使用手冊](GVFG_PLAYBACK_API.zh-TW.md)。Capture、OSD 與 Playback 是不同的 DLL;
Capture 與 Playback 使用不同 handle。
先依下列流程完成擷取整合;逐參數定義與完整限制見
[API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md)。
## 1. 套件內容
核心擷取:
```text
include/gvfg_capture.h
lib/gvfg.lib
bin/gvfg.dll
```
核心擷取只需連結 `gvfg.lib`,並部署相同版本的 `gvfg.dll`。
選用 OSD(字型清單、文字量測、通道 OSD、獨立 BGRA 疊圖):
```text
include/gvfg_osd.h
lib/gvfg_osd.lib
bin/gvfg_osd.dll
```
`gvfg_osd.dll` 依賴同一次 SDK 建置的 `gvfg.dll`,兩者必須一起更新。
選用播放(純影像、純音訊或影音):
```text
include/gvfg_playback.h
lib/gvfg_playback.lib
bin/gvfg_playback.dll
```
MinGW 使用對應的 `libgvfg.dll.a`、`libgvfg_osd.dll.a`、`libgvfg_playback.dll.a`。
目前支援 Windows x64。API 使用 C ABI,可由 C 或 C++ 呼叫。
## 2. 最小擷取流程
```text
gvfg_enumerate_devices
-> gvfg_create
-> gvfg_set_channel_zero_copy_enabled (optional, before channel open)
-> gvfg_open_channel
-> gvfg_set_channel_audio_enabled (optional, before start)
-> gvfg_start_channel
-> 重複:
gvfg_read_channel_frame
使用/複製/轉換 frame
gvfg_release_channel_frame
若已啟用 audio,另一個 worker thread 重複:
gvfg_read_channel_audio_frame
使用/複製 PCM
gvfg_release_channel_audio_frame
-> gvfg_stop
-> gvfg_destroy
```
完整範例:
```c
#include <gvfg_capture.h>
int main(void)
{
gvfg_device_info_t devices[GVFG_MAX_DEVICES] = {0};
int count = gvfg_enumerate_devices(devices, GVFG_MAX_DEVICES);
if (count <= 0)
return 1;
gvfg_handle h = NULL;
if (gvfg_create(&h) != GVFG_OK)
return 2;
gvfg_status_t st = gvfg_open_channel(h, 0, GVFG_CHANNEL_0);
if (st == GVFG_OK)
st = gvfg_start_channel(h, GVFG_CHANNEL_0);
if (st == GVFG_OK) {
for (int i = 0; i < 100; ++i) {
gvfg_frame_t frame = {0};
st = gvfg_read_channel_frame(h, GVFG_CHANNEL_0, &frame, 1000);
if (st == GVFG_ETIMEOUT)
continue;
if (st != GVFG_OK)
break;
/* 在 release 前處理、轉換或複製 frame.data。 */
st = gvfg_release_channel_frame(h, GVFG_CHANNEL_0, &frame);
if (st != GVFG_OK)
break;
}
}
gvfg_stop(h);
gvfg_destroy(h);
return st == GVFG_OK ? 0 : 3;
}
```
## 3. 執行緒與 frame 所有權
- API 是 pull model;應用程式自行決定在哪個執行緒呼叫
`gvfg_read_channel_frame()`。GUI 程式建議每個 channel 使用一個 worker thread,再把 UI 更新送回
UI thread。
- `frame.data` 是唯讀的借用 pointer,可能指向原生擷取 buffer 或 SDK 處理後的
buffer。Zero-copy 設定控制擷取方式;啟用 OSD 時仍可能交付 SDK-owned buffer。
Pointer 只在對應的 `gvfg_release_channel_frame()` 前有效,資料若要長期保存,必須先複製。
- 每個 channel 同時最多持有一個 frame。尚未 release 又對同一 channel 呼叫
`gvfg_read_channel_frame()`,會回傳 `GVFG_ESTATE`。
- release 時傳回 read 取得的 `gvfg_frame_t`;不要自行修改 frame descriptor 的內容。
- `gvfg_stop()` 會中止等待並使尚未 release 的 frame 失效。
- 同一個 handle 的 lifecycle 操作應由應用程式自行序列化;不要同時 open、
start、stop 或 destroy。
Audio 採用相同的 pull 與 ownership 模型:
- 建議使用獨立 audio worker thread,避免阻塞 video read 或 UI thread。
- `gvfg_audio_frame_t.data` 是 SDK-owned PCM,只在對應的
`gvfg_release_channel_audio_frame()` 前有效。
- 同一 channel 同時只能持有一個 audio frame;未 release 再 read 會回傳
`GVFG_ESTATE`。
- release 時傳回 read 取得的 `gvfg_audio_frame_t`;不要自行修改 frame descriptor 的內容。
- 若播放或錄音需要在 release 後繼續使用 PCM,Application 必須先複製。
- Capture 保有自己的交付 buffer;播放副本、queue、同步與輸出由 Playback 管理。
- 使用 Playback 時,submit 已完成複製後即可 release,Demo 不自行實作音訊調速或同步。
- 播放錯誤由 Playback API 回傳狀態碼回報,caller 決定停止與重啟。
輸出裝置故障後,應用程式須處理錯誤並決定是否重新啟動播放。
`timeout_ms` 的共同規則:`0` 表示不等待;`GVFG_TIMEOUT_INFINITE` 表示無限等待;
其他值的單位為毫秒。
## 4. 狀態碼
| 狀態 | 說明 |
| --------------- | --------------------------- |
| `GVFG_OK` | 成功 |
| `GVFG_EINVAL` | 參數、channel 或 frame token 無效 |
| `GVFG_ENODEV` | 找不到裝置或裝置無法開啟 |
| `GVFG_ESTATE` | 呼叫時機或 handle 狀態不正確 |
| `GVFG_EIO` | 擷取、轉換或其他 I/O 失敗 |
| `GVFG_ENOTSUP` | 格式或功能不支援 |
| `GVFG_ETIMEOUT` | 等待逾時 |
| `GVFG_EBUSY` | 裝置或 capture resource 正在使用中 |
公開 API 不暴露底層 capture library 的錯誤型別。所有失敗都會轉成上述
`GVFG_E*` 狀態;Application 應使用 `status != GVFG_OK` 判斷,不可套用
Windows `FAILED()`/`SUCCEEDED()`。
可用 `gvfg_strerror()` 取得靜態英文說明字串;呼叫端不可釋放該字串。
可用 `gvfg_get_version()` 查詢目前實際載入的 `gvfg.dll` 版本。回傳值為
靜態字串,例如 `"3.2.0"`,呼叫端不可釋放。
需要記錄最近一次失敗的詳細原因時,可在 API 失敗後立即呼叫
`gvfg_get_channel_last_sdk_error_detail()`。此 API 回傳可供問題回報使用的公開診斷文字。
## 5. 資料格式
### 原生擷取格式
| 格式 | `pixel_format` | bit depth | 每列大小 |
| ----------------- | ------------------:| ---------:| -----------:|
| YUY2 packed 4:2:2 (`Y0 U0 Y1 V0`) | `GVFG_PIXFMT_YUY2` | 8 | `width * 2` |
| Y210 packed 4:2:2 | `GVFG_PIXFMT_Y210` | 10 | `width * 4` |
實際列距以 `gvfg_frame_t.row_stride_bytes` 為準。
目前不支援的輸入格式會回傳 `GVFG_ENOTSUP`。可用
`gvfg_pixel_format_name()` 取得靜態格式名稱。
### `gvfg_frame_t`
- `data`、`data_size`:SDK buffer 與可用 byte 數。
- `width`、`height`:影像尺寸。
- `row_stride_bytes`:相鄰兩列起點的 byte 距離。
- `pixel_format`、`bit_depth`:原生 payload 格式。
- `frame_id`:SDK 成功交付序號;每次 channel Start 從 1 重新開始。
- `timestamp_ns`:SDK monotonic delivery timestamp,與 audio 使用相同 clock domain。
### PCM audio
`gvfg_audio_format_t` 只提供上層實際需要的播放格式:`sample_rate`、
`channels`、`bits_per_sample`。Driver frame 大小與 block alignment 是 backend
細節,不要求 Application 配置相同大小的 buffer。
`gvfg_audio_frame_t` 包含:
- `data`、`data_size`:SDK-owned PCM 與本次有效 byte 數。
- `sample_rate`、`channels`、`bits_per_sample`:此 frame 的 PCM 格式。
- `frame_id`:SDK 成功交付序號;每次 channel Start 從 1 重新開始。
- `timestamp_ns`:SDK monotonic delivery timestamp,與 video 使用相同 clock domain。
`timestamp_ns` 用於比較同一 process/session 內的 video/audio delivery timing;它
不是 driver 或硬體 capture timestamp。
目前 audio 僅支援 CH0,且必須與 video 一起啟動;不支援 audio-only。公開
audio API 不是 zero-copy,但上層仍使用和 video 相同的 read/release contract。
## 6. 公開 API
### 裝置與生命週期
- `gvfg_enumerate_devices(out_devices, max_devices)`:列舉裝置。傳入
`NULL, 0` 可只查數量;回傳值是寫入數量或可用裝置數,無裝置時為 `0`。
- `gvfg_create(&handle)`:建立 closed session。
- `gvfg_set_channel_zero_copy_enabled(handle, channel, enabled)`:替指定 channel
選用 zero-copy;只能在該 channel open 前呼叫,預設為關閉。
- `gvfg_get_channel_zero_copy_enabled(handle, channel, &enabled)`:查詢指定
channel 選擇的模式。
- `gvfg_open_channel(handle, device_index, channel)`:開啟列舉所得裝置,channel
必須為 `GVFG_CHANNEL_0` 或 `GVFG_CHANNEL_1`。
- `gvfg_start_channel(handle, channel)`:開始指定 channel 擷取。每次明確 Start 都會重新查詢一次
signal;若目前沒有 lock,回傳 `GVFG_ETIMEOUT`,channel 維持 stopped,接上訊號後須由
Application 再次呼叫 Start。
- `gvfg_stop_channel(handle, channel)`:只停止指定 channel;另一條 channel 繼續擷取。
- `gvfg_stop(handle)`:停止同一 handle 已開啟的所有 channel;重複呼叫仍回傳成功。
- `gvfg_destroy(handle)`:必要時先停止,再銷毀 handle。銷毀後不得再使用。
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。
### Frame
- `gvfg_read_channel_frame(handle, channel, &frame, timeout_ms)`:取得原生或 SDK 處理後的唯讀
frame;copy/zero-copy acquisition 的 release contract 相同。
- `gvfg_release_channel_frame(handle, channel, &frame)`:釋放原 frame token。
### SDK OSD
使用 OSD 時請包含 `gvfg_osd.h`,連結 `gvfg_osd.lib`(MinGW 使用 `libgvfg_osd.dll.a`),並隨應用程式部署同一次 SDK 建置的 `gvfg_osd.dll` 和 `gvfg.dll`。一般擷取只需連結 `gvfg.dll` 對應的 import library。
每個已 open 的 channel 可設定兩組 OSD,`osd_index` 為 `0`、`1`;重疊時第 `1` 組在上方。
OSD 會加入後續取得的 YUY2/Y210 frame,preview、snapshot 或錄影是否顯示 OSD,
取決於它們是否使用這份 frame。
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。
若需要把 OSD 交給 FPGA 或其他元件自行疊合,可呼叫
`gvfg_render_osd_frame_bgra(video_width, video_height, slot0, slot1, &bitmap)`。
它不需要 capture handle,輸出與影像同尺寸、透明背景的 top-down premultiplied BGRA8888,
stride 為 `width * 4`;`slot0`/`slot1` 傳 NULL 表示該組不顯示。輸出資料由 SDK 擁有,
有效到同一執行緒下一次呼叫此函式(含失敗)、執行緒結束或 DLL 卸載;非同步傳輸前須先複製。
此函式不影響通道上的 GPU OSD。
`x/y` 是量測文字框左上角;位置會限制在影像內。文字框本身放不下時,該組暫停顯示,
另一組與擷取繼續;文字或影像尺寸調整後可恢復。不自動縮字、截字或換行。
無效字型/文字/組別回傳 `GVFG_EINVAL`;尚未設定的組別不能直接 Show。
SDK handle 銷毀後,應用程式需自行保存並重設所需的 OSD 設定。
完整欄位、字級定義、回傳值與限制見
[API Reference:OSD](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md#3-osd-api)。
### OSD 呼叫範例
以下 C++ 範例假設 `handle` 的 `channel` 已 open。先選擇清單中的實際字型,
立即複製名稱,再使用相同設定量測與繪製;每一步都檢查回傳值。
```cpp
#include <gvfg_osd.h> // 已包含 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);
}
```
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;
```
### SDK 3.2.0 介面遷移
- OSD 函式與型別從 `gvfg_capture.h`/`gvfg.dll` 移到 `gvfg_osd.h`/`gvfg_osd.dll`。
使用 OSD 的程式改為包含 `gvfg_osd.h`、連結 `gvfg_osd.lib`,並一併部署 `gvfg_osd.dll`;
函式名稱與參數不變,但舊程式必須重新編譯連結。
- 新增 `gvfg_get_channel_hdmi_audio_info()`。
### SDK 3.1.0 介面遷移
- 新增 `gvfg_get_channel_hdmi_info()` 與 `gvfg_get_chip_info()`。
- 整張 OSD 疊圖函式更名為 `gvfg_render_osd_frame_bgra()`,取代原本的 `gvfg_render_osd_bgra()`。
### SDK 3.0.0 介面遷移
- OSD 的 `set`/`clear` 新增 `osd_index`;原先的一組設定改為每 channel 兩組。
- `gvfg_channel_osd_config_t` 改用 NUL 結尾字串、移除 `text_length`,新增 `font_family`;
量測函式改收同一份設定,沒有舊版相容入口。
- 公開 Playback 移除 `gvfg_playback_stats_t` 與 `gvfg_playback_get_stats()`。
一般顯示資訊與呈現統計改用 `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 不提供兩組一起更新的交易保證。
### Audio frame
- `gvfg_set_channel_audio_enabled(handle, channel, enabled)`:在 start 前啟用或停用
audio;video 永遠保留,不需要組合 stream flags。
- `gvfg_get_channel_audio_format(handle, channel, &format)`:取得 PCM 播放格式。
- `gvfg_read_channel_audio_frame(handle, channel, &frame, timeout_ms)`:取得一個
SDK-owned PCM frame。
- `gvfg_release_channel_audio_frame(handle, channel, &frame)`:釋放原 audio token。
成功 read 後,不論 PCM 是送往播放、錄音或被丟棄,都必須正好 release 一次。
`gvfg_set_channel_video_format()` 可在 stream 尚未開始或已 stop 時選擇 YUY2/Y210。
此功能由 SDK 的 capture backend 實作。
### 查詢
- `gvfg_get_version()`:目前載入的 GVFG runtime 版本。
- `gvfg_get_gigabyte_lib_version()`:編譯進該 runtime 的 GigabyteLib 版本;不是 driver
或 FPGA 的執行時版本查詢。兩者回傳靜態字串,不需要 handle 或 free。
- `gvfg_get_channel_signal_status(handle, channel, &status)`:查詢指定 channel 的連線、尺寸、
原生格式與 bit depth。沒有輸入訊號是正常狀態:回傳 `GVFG_OK` 且
`connected == 0`。Channel 尚未 running 時會向 capture backend 更新;running 期間則回傳
SDK cache,不再額外讀取硬體。
- `gvfg_get_channel_runtime_info(handle, channel, &info)`:取得指定 channel 已交付 frame 數與
依 read 間隔估算的 `capture_fps`。start 時統計值重設。
- `gvfg_get_channel_sdi_info(handle, channel, &info)`:SDI 輸入的 mode、resolution、fps、
scan、ST 352 等原始值與可顯示文字。
- `gvfg_get_channel_hdmi_info(handle, channel, &info)`:HDMI 輸入的 lock、寬高、FPS、色彩格式、
色彩空間與位深。
- `gvfg_get_channel_hdmi_audio_info(handle, channel, &info)`:HDMI 音訊的 lock、取樣頻率代碼、
位元數、聲道數與格式代碼。
- `gvfg_get_chip_info(handle, &info)`:晶片版本日期與時間;同一 handle 至少要有一個 channel 已 open。
依 `gvfg_get_channel_signal_status()` 的 `video_interface` 選擇查詢 SDI 或 HDMI。
以上查詢都要求指定 channel 已 open,否則回傳 `GVFG_ESTATE`;只有回傳 `GVFG_OK` 時才可使用輸出。
### Event
`gvfg_poll_channel_event(handle, channel, &event, timeout_ms)` 一次取出指定 channel 的事件,只能在 running
狀態使用。stop 會喚醒阻塞中的 poll,並回傳 `GVFG_ESTATE`。
| Event | 應用程式動作 |
| -------------------------------- | --------------------------- |
| `GVFG_EVENT_VIDEO_FORMAT_CHANGED` | Lib 的 video format changed event |
| `GVFG_EVENT_VIDEO_INPUT_PLUGIN` | Lib 的 video input plug-in event |
| `GVFG_EVENT_VIDEO_INPUT_UNPLUG` | Lib 的 video input unplug event |
`event` 使用 `gvfg_event_type_t`;SDK 直接寫入本次取出的事件種類。
SDK 會在 format changed、input plug-in 或 input unplug event 放入 public queue 前先同步
signal cache。Application 收到事件後可呼叫 `gvfg_get_channel_signal_status()` 取得對應的新狀態;
running 期間此查詢讀取 cache,不會再次向 driver 查詢。
## 7. GPU 同步轉換
GPU 轉換在 `gvfg.dll` 內完成,呼叫是同步的。必須在
`gvfg_release_channel_frame()` 前轉換;函式返回後 SDK 不保留 source 或 destination
pointer。
支援輸出:
| 格式 | 配置需求 |
| ------------------------- | --------------------------------------- |
| `GVFG_GPU_OUTPUT_BGRA8` | `row_bytes >= width * 4`;alpha = 255 |
| `GVFG_GPU_OUTPUT_RGB10A2` | `row_bytes >= width * 4`;alpha = 3 |
| `GVFG_GPU_OUTPUT_NV12` | width/height 必須為偶數;`row_bytes >= width` |
BGRA8/RGB10A2 的 destination 至少為 `row_bytes * height`。NV12 至少為
`row_bytes * (height + height / 2)`,排列為 Y plane,接著是 interleaved UV
plane;使用 BT.709 limited range。
可使用通用函式 `gvfg_gpu_convert_to_buffer()`,或便利函式:
- `gvfg_gpu_convert_to_bgra8()`
- `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` 提供影像、音訊播放與影音同步功能。
擷取仍由應用程式呼叫 `gvfg.dll`。典型流程:
```text
gvfg_playback_create -> attach_window -> default_config -> start
capture video/audio -> submit_video / submit_audio -> release SDK frame
停止提交 -> gvfg_playback_stop -> gvfg_playback_destroy
```
submit 成功前已完成資料複製,返回後即可 release SDK frame;失敗時也必須 release,
時間不連續或輸出錯誤仍須處理;queue 壓力由 Playback 自動降級並略過過時資料,不要求停止擷取。
stop/reset 會丟棄待播資料,不代表無損排空。
單張影像用 `gvfg_playback_present_image()`,在已綁定視窗、未 start 的 handle 上同步呼叫。
詳細模式、master、緩衝與 timestamp 規則見
[`統一影音播放使用手冊`](GVFG_PLAYBACK_API.zh-TW.md)。
## 9. 錯誤處理建議
- `GVFG_ETIMEOUT`:連線期間通常可重試,並檢查 signal status/event。收到
`GVFG_EVENT_VIDEO_INPUT_UNPLUG` 後,不應高速輪詢 read API;應等待
`GVFG_EVENT_VIDEO_INPUT_PLUGIN`(或 application stop)再恢復 video/audio read。
- 每次成功取得的 frame 仍必須恰好 release 一次。若 release 與實體拔線競爭,
SDK 會處理 driver 已撤銷 zero-copy ownership 的情況,application 不應特判
`ERROR_BAD_COMMAND (22)`。
- `GVFG_EVENT_VIDEO_FORMAT_CHANGED`:依 Lib 更新後的 video info 重建格式相關資源。
- `GVFG_ESTATE`:檢查 lifecycle、是否重複 read、或是否已 stop。
- `GVFG_EIO`/`GVFG_ENODEV`:停止 session,記錄 `gvfg_strerror()`,再由應用程式
決定是否重新列舉與開啟。
- 不要讀寫硬體 register 或依賴 driver/backend counter;這些不是客戶 API。
## 完整 API Reference
所有公開常數、型別、結構欄位、函式參數與回傳值,請參閱
[`GVFG_CUSTOMER_API_REFERENCE.zh-TW.md`](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md)。
+7 -6
View File
@@ -1,12 +1,13 @@
# GigabyteLib 1.0.2 integration gaps
# GigabyteLib 1.0.5 integration gaps
Capture, audio, events, signal information, copy mode, and zero-copy mode use
the supervisor-provided `GvfgSdk.lib` API directly.
Capture, audio, events, signal information, SDI/HDMI input information, HDMI
audio information, chip information, the user LED, copy mode, and zero-copy mode
use the supervisor-provided `GvfgSdk.lib` API directly.
## Action required from the GigabyteLib owner
The following existing GVFG capabilities are not exposed by the declared
`GvfgSdk.lib 1.0.2` API:
The following existing GVFG capabilities are still not exposed by the declared
`GvfgSdk.lib 1.0.5` API (first reported against 1.0.2):
| GVFG capability | Current temporary implementation | Requested GigabyteLib API |
|---|---|---|
@@ -15,7 +16,7 @@ The following existing GVFG capabilities are not exposed by the declared
These are marked `GIGABYTELIB GAP` in source. They intentionally do not use
the removed `giga_ioctl.dll`; the minimal fallback is compiled into `gvfg.dll`.
GigabyteLib 1.0.2 supplies `GvfgSetVideoColorDepth()` for YUY2/Y210 selection,
Since 1.0.2, GigabyteLib supplies `GvfgSetVideoColorDepth()` for YUY2/Y210 selection,
so format switching no longer uses the extension. Once official register functions
exist, replace the remaining two extension calls and delete
`gigabyte_driver_extensions.*`.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+5 -4
View File
@@ -53,7 +53,7 @@ EOUTPUT=-3、EQUEUE_FULL=-4(保留值,目前 API 不回傳)、EDISCONTINUI
submit 是接受/複製,不是實體輸出完成。其他非同步輸出失敗會由後續 submit 回報;
start 或 submit 成功不保證後續輸出一定正常。
影音模式遇到音訊輸出故障時,停用該 handle 的監聽音效,影像繼續播放;後續音訊 submit 回傳 EAUDIO。影音 start 也可能在音效開啟失敗時成功,應檢查後續音訊 submit。此停用狀態跨 stop/start/reset 保留,需先協調 producer,再銷毀並重建 Playback handle 才會重試音效;獨立擷取與錄音可繼續。純音訊模式的輸出故障回報 EOUTPUT。
影音模式遇到音訊輸出故障時,停用該 handle 的監聽音效,影像繼續播放;後續音訊 submit 回傳 EAUDIO。影音 start 也可能在音效開啟失敗時成功,應檢查後續音訊 submit。預設此停用狀態跨 stop/start/reset 保留,需先協調 producer,再銷毀並重建 Playback handle 才會重試音效;若 start 前呼叫過 `gvfg_playback_enable_audio_reconnect()`,影音模式會約每秒重試預設輸出,恢復後音訊 submit 再回傳 OK。獨立擷取與錄音可繼續。純音訊模式的輸出故障回報 EOUTPUT。
| 情況 | ownership 與後續處理 |
|---|---|
@@ -63,7 +63,8 @@ start 或 submit 成功不保證後續輸出一定正常。
| Playback queue 壓力 | 自動進入獨立播放並略過過時資料;不因 queue 滿而停止擷取,單筆超出配置容量則是 EINVAL |
| Playback timestamp 不連續 | 協調 producer 後 reset;音訊格式改變用新 config stop/start |
| 過期預覽或 GPU busy 略過 | 不當成 Capture failure;公開 skipped_presents 僅涵蓋預覽端略過數,不包含同步核心提前捨棄的所有影格 |
| Playback EAUDIO | 提示一次監聽音效停用;繼續影像與獨立擷取/錄音,需重建 Playback handle 才重試音效 |
| Playback EAUDIO | 提示一次監聽音效停用;繼續影像與獨立擷取/錄音。已啟用 audio reconnect 時持續提交 PCM 等待恢復,否則需重建 Playback handle 才重試音效 |
| Playback present_image EOUTPUT | 單張影像未被 Present 接受(例如 GPU busy 或逾時);可稍後重試 |
| Playback EOUTPUT | 檢查裝置/視窗與輸出路徑,明確決定重啟,不無限重試 |
## 4. 生命週期與 Demo
@@ -74,5 +75,5 @@ reset/stop 是取消待播資料,不是錯誤重試或無損 drain。
Customer Demo 只顯示 API 名稱與必要公開錯誤;queue/PTS/driver counters 屬於另行選用的診斷。
內部分支的 Debug diagnostics 與 Release Demo 分開,不能把內部輸出當成公開 API 契約。
完整欄位與狀態限制見 [API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md),
操作流程見 [Playback 手冊](GVFG_PLAYBACK_API.md)。
完整欄位與狀態限制見 [API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md),
操作流程見 [Playback 手冊](GVFG_PLAYBACK_API.zh-TW.md)。
+3 -2
View File
@@ -1,6 +1,6 @@
# GVFG 影音資料流與生命週期
更新於 2026-10-20。公開使用範例見 [Playback 手冊](GVFG_PLAYBACK_API.md),
更新於 2026-12-01(SDK 3.2.0)。公開使用範例見 [Playback 手冊](GVFG_PLAYBACK_API.zh-TW.md),
內部 scheduling 見 [Playback 維護說明](../GVFG_SDK/helpers/gvfg_playback/README.md)。
## 1. Capture 與 Playback 是兩個生命週期
@@ -77,7 +77,8 @@ reset 會 stop、清除畫面,原本 active 時再用原 config start;每一
音訊格式變動應以新 audio_format 做 stop/start,而不是只呼叫沿用舊 config 的 reset。
Capture backend 自身的恢復與 Playback 輸出裝置恢復是不同邊界;不能把舊 QAudioSink 重建策略套到目前 WASAPI backend。
目前播放輸出沒有自動切換/重建預設裝置的契約。
預設不自動重建播放輸出;影音模式可在 start 前呼叫 `gvfg_playback_enable_audio_reconnect()`,
讓 Playback 約每秒重試 Windows 預設輸出裝置。純音訊模式不重試。
## 7. 計數與完整性
+23 -10
View File
@@ -9,21 +9,21 @@ release。舊 `giga_ioctl.dll` 與直接 register/IOCTL
backend 已移除。`GvfgSdk.lib` 靜態連結進 `gvfg.dll`,不是客戶 runtime 相依。
本文件只供 GVFG SDK、driver、FPGA 與內部診斷工具維護者使用。客戶行為與公開
契約請以 `GVFG_CUSTOMER_API.md`、`GVFG_CUSTOMER_API_REFERENCE.md` 和
`gvfg_capture.h` 為準。本文件中的 IOCTL、
契約請以 `GVFG_CUSTOMER_API.md`、`GVFG_CUSTOMER_API_REFERENCE.md`(或其 `.zh-TW.md` 版本)和
`gvfg_capture.h`、`gvfg_osd.h` 為準。本文件中的 IOCTL、
register、ring、counter 與執行緒模型都不是公開 ABI。
## 1. 客戶/內部邊界
| 類別 | 客戶套件 | 僅內部 |
|---|---|---|
| Header | `gvfg_capture.h`、選用 `gvfg_playback.h` | `gvfg_debug.h`、backend headers |
| Binary | `gvfg.dll/.lib`、選用 `gvfg_playback.dll/.lib` | driver/FPGA 診斷工具 |
| 文件 | `GVFG_CUSTOMER_API.md`、`GVFG_CUSTOMER_API_REFERENCE.md` | 本文件 |
| Header | `gvfg_capture.h`、選用 `gvfg_osd.h`、選用 `gvfg_playback.h` | `gvfg_debug.h`、backend headers |
| Binary | `gvfg.dll/.lib`、選用 `gvfg_osd.dll/.lib`、選用 `gvfg_playback.dll/.lib` | driver/FPGA 診斷工具 |
| 文件 | `GVFG_CUSTOMER_API*.md`、`GVFG_PLAYBACK_API*.md`、`GVFG_CUSTOMER_API_REFERENCE*.md`(英文與 zh-TW) | 本文件 |
| 資訊 | lifecycle、frame、event、signal、runtime FPS | IOCTL、IRQ、register、DMA/ring、debug counters |
CMake install 會安裝公開的 `gvfg_capture.h`、選用的 `gvfg_playback.h`、客戶文件,
以及 `gvfg.dll`、`gvfg_playback.dll` 等 target 產物;不得把
CMake install 會安裝公開的 `gvfg_capture.h`、選用的 `gvfg_osd.h`、`gvfg_playback.h`、客戶文件,
以及 `gvfg.dll`、`gvfg_osd.dll`、`gvfg_playback.dll` 等 target 產物;不得把
`gvfg_debug.h`、GigabyteLib private header/lib 或 `sdk/gvfg/src` 加入 customer package。
## 2. 元件責任
@@ -65,6 +65,11 @@ customer/sample (optional)
| `gvfg_get_channel_signal_status()` | `GVFG_VIDEO_INFO` cache | `VideoSignalLock` 轉 connected、FourCC 轉 SDK pixel format,並由格式推導 bit depth;正常 UI refresh 只讀 cache |
| `gvfg_debug_get_device_capabilities()` | `GvfgGetDevInfo()` | Video channel count 與 audio capability 僅供內部診斷工具使用 |
| `gvfg_get_channel_sdi_info()` | `GvfgGetSdiVideoInputInfo()`、`GvfgStringifySdiVideoInputInfo()` | 同時提供 Lib 原始欄位的 SDK enum/value 與全部八個未改寫的 Lib 格式化字串,不公開 private struct |
| `gvfg_get_channel_hdmi_info()` | `GvfgGetHdmiVideoInputInfo()` | 複製 lock、寬高、FPS、色彩格式/空間代碼與位深;`fps_name` 與色彩名稱由 SDK 依代碼產生 |
| `gvfg_get_channel_hdmi_audio_info()` | `GvfgGetHdmiAudioInputInfo()` | 複製 lock、取樣頻率代碼、位元數、聲道數與格式代碼;只在 lock 時由 SDK 填入名稱字串 |
| `gvfg_get_chip_info()` | `GvfgGetChipInfo()` | 需任一 channel 已 open;保留原始十六進位日期/時間 |
| `gvfg_debug_set_user_led()` | `GvfgSetLed()` | 僅供內部診斷;需任一 channel 已 open |
| OSD APIs(`gvfg_osd.dll`) | SDK DirectWrite/D3D11 | `gvfg_osd.dll` 透過 `gvfg.dll` 未公開於標頭的匯出 `gvfg_control_frame_processor` 掛上 channel frame processor;GigabyteLib 不參與 |
| `gvfg_get_channel_audio_format()` | `GvfgGetAudioInfo()` | 只公開 sample rate、channels、bits per sample;`cbBufSize` 留在 SDK 作為讀取 buffer 大小,忽略 Lib FrameCount |
| `gvfg_start_channel()`、stop APIs | `GvfgStartCapture()`、`GvfgStopCapture()` | 驗證狀態、處理 wait cancellation、held frame、event queue、熱插拔恢復與 SDK counters |
| `gvfg_read_channel_frame()` | Lib video events + GetFrame API | 驗證 read/held 狀態,加入 row stride、SDK delivery frame ID、monotonic timestamp 與 delivery FPS 統計 |
@@ -135,8 +140,8 @@ x64 `gvfg_frame_t` ABI 已在 `gvfg_capture.cpp` 以 static assertions 固定為
## GigabyteLib requirement
Capture、audio、event 與 frame ownership 的 driver ABI 由主管提供的
`GvfgSdk.lib` 負責。Output-format selection 已改用 library 1.0.2 的
`GvfgSetVideoColorDepth()`;目前唯一例外是 diagnostic register R/W,集中在
`GvfgSdk.lib` 負責。Output-format selection 自 library 1.0.2 起改用
`GvfgSetVideoColorDepth()`;目前(GigabyteLib 1.0.5)唯一例外是 diagnostic register R/W,集中在
`gigabyte_driver_extensions.*`,不得擴大成第二套 capture backend。待主管補上正式
register API 後應刪除此 extension。
@@ -181,6 +186,14 @@ cached signal。Facade callback 會先將 backend cache 同步到 channel cache
- `gvfg_debug_get_channel_backend_stats()`:指定 channel 的 running/frame-held 狀態、
event queue depth、frame wait timeout、video/audio event wake、audio 讀取量與
GigabyteLib GetFrame/acquire timing。
- `gvfg_debug_read_channel_frame_timed()`/`gvfg_debug_read_channel_frame_profiled()`:
與公開 read 相同 ownership 的讀取變體,另回傳 OSD 各階段 CPU 時間與 acquisition 起點。
- `gvfg_debug_get_device_capabilities()`:video channel 數與是否有 audio。
- `gvfg_debug_set_user_led()`:板上 user LED。
- `gvfg_debug_read_register()`/`gvfg_debug_write_register()`:GigabyteLib gap 的 direct driver extension。
這些函式列在 `gvfg.def`,Release `gvfg.dll` 也會匯出;客戶套件不附 `gvfg_debug.h`,
Customer Demo 的封裝腳本會檢查 EXE 未匯入 `gvfg_debug_*`。
公開的 `gvfg_runtime_info_t` 只保留 application-facing capture FPS 與 delivered frame
數;zero-copy 用公開 getter 查詢。Debug 結構不重複這些公開資訊,也不偽造
@@ -217,7 +230,7 @@ Audio backend 操作 PCM/WASAPI、raw frame position、pause/rate;Preview
present_fps/video_presented 是 DXGI 接受 Present,不是實體 scanout。
video_dropped 包含 core 過期退休與 backend busy 等略過,不代表 Capture 或錄影 loss。
欄位定義見 [公開 Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md),
欄位定義見 [公開 Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md),
實作見 [Playback 維護說明](../GVFG_SDK/helpers/gvfg_playback/README.md)。
## 10. 已知限制與發佈檢查表
+7 -6
View File
@@ -1,12 +1,12 @@
# GVFG 文件閱讀入口
更新於 2026-10-29;SDK 3.0.0。以下連結以目前 source tree 為準。
更新於 2026-12-01;SDK 3.2.0。以下連結以目前 source tree 為準。
## 客戶與 Demo 使用者
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/Playback 型別、參數、所有權、狀態碼與限制;完整流程範例放在使用手冊。
1. [客戶 Capture 使用手冊](GVFG_CUSTOMER_API.zh-TW.md):裝置、channel、影音 read/release、事件與 OSD。
2. [統一 Playback 使用手冊](GVFG_PLAYBACK_API.zh-TW.md):一個播放 DLL、三種模式、單張顯示與舊版遷移。
3. [公開 API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md):Capture/OSD/Playback 型別、參數、所有權、狀態碼與限制;完整流程範例放在使用手冊。
4. [Customer Sample README](../../Costomer_SDK_Release/GVFG_Customer_Sample/README.md):Qt Creator/CMake 建置與 Demo 操作。
不需先讀 driver、WASAPI 或 D3D 才能使用公開 API。Demo 只展示 API,不實作同步演算法。
@@ -16,9 +16,10 @@
客戶文件中的實作原理已移至 [study:文件分工與內部說明](../../study/notes/customer_vs_internal_docs.md),
兩組 OSD 的字型、mask、YUV、快取與 shader 見 [study:OSD 實作章](../../study/03_helpers_gpu/04_osd_text_to_gpu.md)。
0. [架構總覽圖](GVFG_ARCHITECTURE_OVERVIEW.drawio)(draw.io):三個 DLL、內部元件與 vendor/OS 邊界的一頁圖。
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 節。
3. [Capture 錯誤處理](GVFG_ERROR_HANDLING.md):Capture status/detail 與 ownership;播放錯誤另看 API Reference 第 5 節。
4. [Playback 實作](../GVFG_SDK/helpers/gvfg_playback/README.md):PTS、master、共同緩衝、WASAPI 進度、漂移與過期預覽追趕。
5. [內部建置說明](INTERNAL_BUILD_GUIDE.md):實際 target、Sample 三種 SDK 來源、install 與版本配套。
6. [內部設計筆記](GVFG_INTERNAL_NOTES.md):Capture facade、vendor adapter 與內部診斷邊界。
@@ -28,7 +29,7 @@
| 問題 | 從哪裡看 |
|---|---|
| 公開型別與函式 | `GVFG_SDK/sdk/gvfg/include/gvfg_capture.h`、`helpers/gvfg_playback/include/gvfg_playback.h` |
| 公開型別與函式 | `GVFG_SDK/sdk/gvfg/include/gvfg_capture.h`、`helpers/gvfg_osd/include/gvfg_osd.h`、`helpers/gvfg_playback/include/gvfg_playback.h` |
| Capture token/channel lifecycle | `GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp` |
| vendor frame/event | `GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp` |
| 開始播放、queue、master、過期退休 | `GVFG_SDK/helpers/gvfg_playback/src/gvfg_playback.cpp` |
+4 -1
View File
@@ -1,6 +1,6 @@
# GVFG 擷取與播放物件架構
更新於 2026-10-20,依目前原始碼整理。完整閱讀順序見 [學習入口](GVFG_LEARNING_INDEX.md)。
更新於 2026-12-01(SDK 3.2.0),依目前原始碼整理。完整閱讀順序見 [學習入口](GVFG_LEARNING_INDEX.md)。
本版以目前可查證的物件與邊界說明,不把概念欄位當成公開 ABI。
## 1. 兩個公開 handle
@@ -17,6 +17,8 @@
flowchart LR
V[GigabyteLib / driver] --> C[gvfg.dll: Capture]
C -->|借用 video / PCM| A[Application: read → submit → release]
O[gvfg_osd.dll: 字型 / 量測 / 通道 OSD] -->|frame processor| C
A -->|設定 OSD| O
A -->|已複製播放資料| P[gvfg_playback.dll: clocks / queues / scheduling]
P --> D[Preview 靜態 backend: D3D]
P --> W[Audio 靜態 backend: WASAPI]
@@ -60,6 +62,7 @@ Preview backend 只知道影像上傳與呈現,不決定哪一路當 master。
| Target | 類型 | 客戶部署 |
|---|---|---|
| `gvfg` | SHARED | `gvfg.dll` |
| `gvfg_osd` | SHARED | `gvfg_osd.dll`(選用;依賴同版 `gvfg.dll`) |
| `gvfg_playback` | SHARED | `gvfg_playback.dll` |
| `gvfg_audio_playback` | STATIC | 不另外部署 |
| `gvfg_preview` | STATIC | 不另外部署 |
+131 -94
View File
@@ -1,65 +1,80 @@
# GVFG 統一影音播放使用手冊
# GVFG Unified Playback Guide
適用於 SDK 3.0.0。應用程式使用 `gvfg_capture.h` 擷取資料,使用
`gvfg_playback.h` 播放;時鐘、共同緩衝及影音同步由 Playback 管理。
English | [繁體中文](GVFG_PLAYBACK_API.zh-TW.md)
## 1. 連結與部署
Applies to SDK 3.2.0. The application captures data with `gvfg_capture.h` and plays it with
`gvfg_playback.h`; Playback manages the clocks, the shared buffering, and audio/video
synchronization.
| 用途 | MSVC 匯入庫 | 執行期 DLL |
## 1. Linking and deployment
| Purpose | MSVC import library | Runtime DLL |
|---|---|---|
| 裝置、channel、影音擷取 | `gvfg.lib` | `gvfg.dll` |
| 影像、音訊、影音同步、單張影像顯示 | `gvfg_playback.lib` | `gvfg_playback.dll` |
| Devices, channels, audio/video capture | `gvfg.lib` | `gvfg.dll` |
| Video, audio, A/V sync, single-image display | `gvfg_playback.lib` | `gvfg_playback.dll` |
MinGW 使用對應的 `libgvfg.dll.a`、`libgvfg_playback.dll.a`。
播放功能只有一個 DLL;擷取仍有自己的 DLL。Windows 與 C/C++ runtime 相依仍須滿足。
MinGW uses the matching `libgvfg.dll.a` and `libgvfg_playback.dll.a`.
Playback is a single DLL; capture keeps its own DLL. Windows and C/C++ runtime dependencies must
still be satisfied.
Playback 僅需交付 `gvfg_playback.h`,其中已包含所有公開函式、影像、PCM 格式及統計型別。擷取功能另使用 `gvfg_capture.h`;內部音訊與顯示後端不需另外提供標頭。
Playback only needs `gvfg_playback.h`, which contains every public function, the image and PCM
formats, and the statistics types. Capture additionally uses `gvfg_capture.h`; the internal audio
and display backends need no extra headers.
### 顯示資訊與呈現統計
### Display information and presentation statistics
公開查詢提供一般應用程式需要的資訊:
The public queries provide what a typical application needs:
| 查詢 | 結果 | 用途 |
| Query | Result | Use |
|---|---|---|
| `gvfg_playback_get_preview_info()` | `gvfg_preview_info_t` | 取得影像尺寸、格式與顯示卡資訊 |
| `gvfg_playback_get_preview_stats()` | `gvfg_preview_stats_t` | 取得 `present_fps`、`presented_frames`、`skipped_presents` |
| `gvfg_playback_get_preview_info()` | `gvfg_preview_info_t` | Image size, format, and graphics adapter information |
| `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` 是預覽端略過呈現的累積數,不是擷取或錄影掉格總數。
Pass a valid Playback handle and a pointer to the result struct, and check the return value.
`present_fps` is the rate of frames accepted by DXGI Present over the last five seconds;
`presented_frames` is the cumulative count of successful Presents. Neither represents actual
scanout on the display. `skipped_presents` is the cumulative number of presents skipped by the
preview, not the total number of frames dropped by capture or recording.
詳細佇列、GPU upload slot 與逐影格 delivery 計數屬於內部 Debug 診斷,不在公開 header 或客戶 API 中提供。應用程式不需管理這些內部狀態。
Detailed queue, GPU upload slot, and per-frame delivery counters are internal Debug diagnostics and
are not part of the public header or the customer API. Applications do not manage this internal
state.
## 2. 選擇模式
## 2. Choosing a mode
先以 `gvfg_playback_default_config()` 初始化 config,再修改需要的欄位。
Initialize the config with `gvfg_playback_default_config()` first, then change the fields you need.
同步預設開啟;可在 create 後、start 前,或播放途中選擇:
Synchronization is on by default. You can change it after create, before start, or during playback:
```cpp
gvfg_playback_set_sync_enabled(player, 0); // 影音各自播放,不自動回到同步。
gvfg_playback_set_sync_enabled(player, 1); // 啟用同步;播放途中會先等待來源與輸出穩定。
gvfg_playback_set_sync_enabled(player, 0); // Play audio and video independently; never resync automatically.
gvfg_playback_set_sync_enabled(player, 1); // Enable sync; during playback it first waits for stable input and output.
```
兩行代表不同選擇,擇一呼叫並檢查回傳值。此設定會保留到後續 stop/start 與 reset_timeline。
關閉同步時仍有有界緩衝與過時資料清理;不需要由應用程式調整底層影音輸出。
The two lines are alternatives: call one and check its return value. The setting persists across
later stop/start and reset_timeline. With sync off, buffering is still bounded and stale data is
still cleaned up; the application does not need to adjust the underlying audio/video output.
| `mode` | 資料需求 | 有效 master | 音訊輸出 |
| `mode` | Data required | Effective master | Audio output |
|---|---|---|---|
| `GVFG_PLAYBACK_VIDEO_ONLY` | 持續提交影像 | 強制 External | 不建立 |
| `GVFG_PLAYBACK_AUDIO_ONLY` | 持續提交 PCM | 強制 Audio | 建立 |
| `GVFG_PLAYBACK_AUDIO_VIDEO` | 兩路都須持續提交 | External/Audio/Video,預設 External | 建立 |
| `GVFG_PLAYBACK_VIDEO_ONLY` | Keep submitting video | Forced External | Not created |
| `GVFG_PLAYBACK_AUDIO_ONLY` | Keep submitting PCM | Forced Audio | Created |
| `GVFG_PLAYBACK_AUDIO_VIDEO` | Keep submitting both | External/Audio/Video, default External | Created |
純音訊不需 HWND。`attach_window(nullptr)` 是隱藏畫面,仍須提交啟用模式所需的影像;
它不會把影音模式改成純音訊。`set_volume(0)` 是靜音,仍須提交 PCM,音訊時間軸繼續運行。
Audio-only playback needs no HWND. `attach_window(nullptr)` hides the picture, but you must still
submit the video the mode requires; it does not turn an audio-video mode into audio-only.
`set_volume(0)` mutes, but you must still submit PCM and the audio timeline keeps running.
共同 PTS 說明資料屬於哪個時間;master 決定「現在播到哪裡」。相同時間軸不代表兩個
實際輸出裝置的速度與延遲相同。External 用單調系統時鐘排程;Audio 用估計音訊輸出進度;
Video 用最近成功呈現的影像時間及經過時間。Video master 不保證 GPU 能呈現每張輸入影格。
The shared PTS says which point in time the data belongs to; the master decides "where playback is
now". A shared timeline does not mean two physical output devices run at the same speed or latency.
External schedules with a monotonic system clock; Audio uses the estimated audio output progress;
Video uses the time of the most recently presented image plus elapsed time. Video master does not
guarantee that the GPU can present every input frame.
## 3. 建立與啟動
## 3. Creating and starting
以下為 C++ 初始化範例;`format` 應由 Capture API 查詢取得,不應假設所有輸入都是 48 kHz。
The following is a C++ initialization example. Get `format` from the Capture API; do not assume
every input is 48 kHz.
```cpp
#include "gvfg_capture.h"
@@ -94,21 +109,22 @@ gvfg_playback_status_t BeginPlayback(
}
```
一般順序是:建立 Capture handle、選擇/開啟 channel、設定 audio enable、查詢格式、
成功 start capture、建立/綁定/start Playback,最後啟動應用程式的影音讀取執行緒。
任何步驟失敗都須回收已建立資源。Playback 不會代替應用程式開啟或停止擷取裝置。
The usual order is: create the Capture handle, select/open the channel, set audio enable, query the
format, start capture successfully, create/attach/start Playback, and finally start the
application's audio and video read threads. Release whatever was created if any step fails.
Playback never opens or stops the capture device on the application's behalf.
## 4. 提交影像與 release
## 4. Submitting video and releasing
`gvfg_frame_t` 與 `gvfg_preview_frame_t` 是不同型別,pixel format 必須明確對應。
不要直接假設兩個 enum 的整數值相同。
`gvfg_frame_t` and `gvfg_preview_frame_t` are different types, and the pixel format must be mapped
explicitly. Do not assume the two enums have the same integer values.
```cpp
bool SubmitOneVideo(gvfg_handle capture, int channel, gvfg_playback player)
{
gvfg_frame_t source{};
const auto read = gvfg_read_channel_frame(capture, channel, &source, 100);
if (read == GVFG_ETIMEOUT) return true; // 本次無 frame,沒有 release
if (read == GVFG_ETIMEOUT) return true; // No frame this time, so nothing to release
if (read != GVFG_OK) return false;
gvfg_playback_video_frame_t v{};
@@ -131,10 +147,11 @@ bool SubmitOneVideo(gvfg_handle capture, int channel, gvfg_playback player)
}
```
成功 read 的原始 token 必須恰好 release 一次,包含 submit 失敗路徑。
submit 成功表示已完成複製並接受排程,不表示已經顯示。Playback 不長期持有 Capture frame。
The original token from a successful read must be released exactly once, including when submit
fails. A successful submit means the frame was copied and accepted for scheduling, not that it has
been displayed. Playback never holds a Capture frame for long.
## 5. 提交 PCM 與 release
## 5. Submitting PCM and releasing
```cpp
bool SubmitOneAudio(gvfg_handle capture, int channel, gvfg_playback player)
@@ -150,72 +167,92 @@ bool SubmitOneAudio(gvfg_handle capture, int channel, gvfg_playback player)
}
```
目前接受 signed interleaved PCM16;bytes 必須對齊 `channels * 2`,每包最多 100 ms。
應用程式可像範例一樣直接 submit 後 release,也可先複製、release,再 submit 自有副本。
兩種方式都必須在 release 前完成對 SDK 記憶體的使用。
Signed interleaved PCM16 is accepted; `bytes` must be a multiple of `channels * 2`, with at most
100 ms per packet. The application can submit and then release as in the example, or copy, release,
and then submit its own copy. Either way, it must finish using SDK memory before release.
## 6. 時間戳與播放延遲
## 6. Timestamps and playback latency
- 直接傳入 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`。
- Pass the Capture `timestamp_ns` directly. Video and audio must use the same monotonic timeline, in
nanoseconds. Each stream's timestamps must be greater than 0, strictly increasing, and no larger
than `INT64_MAX`.
- Timestamps are not UTC and do not represent the hardware exposure/recording time. Do not rebase
the two streams to zero separately, which would change their relative timing.
- Synchronized playback can add latency. Use `gvfg_playback_set_sync_enabled(p, 0)` for independent
playback; the application does not need to adjust playback rates or implement synchronization.
- When the source is unstable there may be silence, gaps, or skipped frames; the application should
keep submitting the data it has. Acceptance by the API does not guarantee every frame is displayed,
and it cannot recover unknown loss or latency upstream.
- Typical applications keep the buffering defaults from `gvfg_playback_default_config()`.
`max_video_frames`, `max_audio_ms`, and `max_video_bytes` are advanced capacity limits; change them
only for specific memory or pending-capacity requirements. They do not guarantee a fixed playback
latency. See `gvfg_playback_config_t` in the API Reference for the fields and valid ranges.
## 7. 執行緒、重設與停止
## 7. Threads, reset, and stop
一個 handle 可由一個 video producer 與一個 audio producer 同時 submit。
start、stop、reset、attach、present_image、destroy 等控制操作由 caller 序列化,
並在控制操作前停止/協調 producer;HWND 操作在其所屬 UI 執行緒進行。
One video producer and one audio producer can submit to a handle concurrently. Control operations
such as start, stop, reset, attach, present_image, and destroy must be serialized by the caller, and
producers must be stopped or coordinated before a control operation. HWND operations run on the
thread that owns the window.
停止順序:設停止旗標 → join 影音讀取執行緒 → 確認所有成功 read 都已 release →
Playback stop/destroy → Capture stop;最後一個 channel 結束後才 destroy 共用 Capture handle。
視窗應存活到使用它的播放器結束。
Shutdown order: set the stop flag → join the audio/video read threads → confirm every successful read
has been released → Playback stop/destroy → Capture stop. Destroy a shared Capture handle only after
the last channel has finished. Keep the window alive until the player that uses it has finished.
遇到時間倒退、重連或切格式,先協調 producer,再檢查 `reset_timeline()` 回傳值。
reset 會清除待播資料並沿用原 config 重新建立時間軸;音訊格式改變時應 stop/start 新 config。
reset 失敗仍須依回傳狀態處理,不可假設一定成功。
When timestamps go backwards, a reconnection happens, or the format changes, coordinate the
producers first and then check the return value of `reset_timeline()`. Reset clears pending data and
rebuilds the timeline with the original config; when the audio format changes, stop and start with
a new config. Handle a failed reset according to its status; do not assume it always succeeds.
stop/reset 都會取消待播資料,沒有無損 EOS/drain 語意;有限檔案的尾幀完整輸出不是目前 API 的保證。
影音模式遇到音訊輸出故障時,helper 停用監聽音效並繼續播放影像,
後續音訊提交回傳 `EAUDIO`;caller 可提示一次警告,繼續擷取與錄影音訊。
包括啟動時音效裝置無法開啟的情況,影音 start 仍可成功、由音訊提交回報 `EAUDIO`。
此狀態保留至 handle 銷毀,stop/reset 不會重試音效;重建 handle 才會再嘗試。
純音訊模式沒有影像可保留,輸出故障仍回報 `EOUTPUT`。
其他 `EOUTPUT` 應檢查 GPU/視窗/記憶體等輸出問題,依錯誤停止或重啟。
Stop and reset both cancel pending data; there are no lossless EOS/drain semantics, and complete
output of the final frames of a finite file is not guaranteed by the current API.
In audio-video mode, when the audio output fails, the helper disables audio monitoring and keeps
playing video; later audio submissions return `EAUDIO`. The caller can show a warning once and keep
capturing and recording audio. This includes the case where the audio device cannot be opened at
start: audio-video start can still succeed, and audio submissions report `EAUDIO`.
By default this state persists until the handle is destroyed, and stop/reset do not retry audio;
only a recreated handle tries again. To recover monitoring automatically after headphones are
reconnected or the default output changes, call `gvfg_playback_enable_audio_reconnect(player)`
before start: in audio-video mode Playback retries the Windows default output device about once per
second, the application keeps submitting new PCM, and audio submissions return OK again once output
is restored. Audio-only mode has no video to keep, does not retry, and still reports output failure
as `EOUTPUT`. For other `EOUTPUT` errors, check the GPU, window, memory, or other output problems,
and stop or restart according to the error.
## 8. 單張 RAW/DICOM 影像
## 8. Single RAW/DICOM images
在 create、attach_window 成功後,用 `gvfg_playback_present_image(player, &image)`;
不要 start。它不需要 PTS,也不啟動音訊,會同步等待已提交的預覽工作完成。
輸入資料須保持有效到返回;只允許停止狀態且已綁定視窗的 handle。
GPU busy 可能略過呈現,OK 不等於已完成實體螢幕掃描。
After create and attach_window succeed, call `gvfg_playback_present_image(player, &image)`; do not
call start. It needs no PTS, does not start audio, and waits synchronously for the submitted preview
work to finish. The input data must stay valid until it returns. Only a stopped handle with an
attached window is allowed; otherwise it returns `ESTATE`. If the image is not accepted by DXGI
Present (for example the GPU is busy or the wait times out), it returns `EOUTPUT`. OK means the image
was presented, not that physical display scanout has completed.
## 9. 範例與 API Reference
## 9. Examples and API Reference
NO SIGNAL 圖卡由 Playback helper 內建與顯示,應用端只需轉交 Capture 的訊號狀態:
The NO SIGNAL card is built into and displayed by the Playback helper; the application only forwards
the Capture signal state:
```cpp
gvfg_signal_status_t signal{};
if (gvfg_get_channel_signal_status(capture, channel, &signal) == GVFG_OK) {
auto status = gvfg_playback_set_signal_connected(player, signal.connected ? 1 : 0);
// 檢查 status;失敗時使用 gvfg_playback_strerror(status)。
// Check status; on failure use gvfg_playback_strerror(status).
}
```
在綁定 HWND 的 UI 執行緒呼叫,與 attach/destroy 序列化。0 顯示固定圖卡,1 隱藏。
預設為 1;可先設定再 attach,狀態保留至下次明確設定,stop/start/reset 不改變它。
圖卡會隨視窗縮放,應用程式不必自行繪製。
此 API 不讀 Capture、不以 FPS 或黑色像素推測訊號,也不改影格內容、PTS 或錄影。
若未使用此 API,維持一般預覽行為。destroy/detach 也應在 HWND 執行緒執行。
Call it on the UI thread that owns the attached HWND, serialized with attach/destroy. 0 shows the
fixed card and 1 hides it. The default is 1. It can be set before attach, and the state persists
until it is set explicitly again; stop/start/reset do not change it. The card scales with the window,
so the application does not draw it. This API does not read Capture, does not infer the signal from
FPS or black pixels, and does not change frame content, PTS, or recording. Without this API, normal
preview behavior is kept. Destroy/detach should also run on the HWND thread.
Customer Demo 展示 API 的啟停、提交、release、事件及基本錯誤處理。
The Customer Demo shows API start/stop, submission, release, events, and basic error handling.
應用程式透過 `gvfg_playback_*` 控制播放:獨立預覽使用 video-only,
單張顯示使用 present_image。同步控制由 Playback 處理。
更新 SDK 時,標頭、匯入庫、DLL 與 CMake 應使用同一版本。
Applications control playback through `gvfg_playback_*`: independent preview uses video-only, and
single-image display uses present_image. Synchronization is handled by Playback. When updating the
SDK, use the same version for headers, import libraries, DLLs, and CMake.
逐欄位限制與所有函式見 [公開 API Reference,第 4 節](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md#4-統一-playback-api)。
For per-field limits and every function, see
[Public API Reference, section 5](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md#5-unified-playback-api).
+227
View File
@@ -0,0 +1,227 @@
# GVFG 統一影音播放使用手冊
[English](GVFG_PLAYBACK_API.md) | 繁體中文
適用於 SDK 3.2.0。應用程式使用 `gvfg_capture.h` 擷取資料,使用
`gvfg_playback.h` 播放;時鐘、共同緩衝及影音同步由 Playback 管理。
## 1. 連結與部署
| 用途 | MSVC 匯入庫 | 執行期 DLL |
|---|---|---|
| 裝置、channel、影音擷取 | `gvfg.lib` | `gvfg.dll` |
| 影像、音訊、影音同步、單張影像顯示 | `gvfg_playback.lib` | `gvfg_playback.dll` |
MinGW 使用對應的 `libgvfg.dll.a`、`libgvfg_playback.dll.a`。
播放功能只有一個 DLL;擷取仍有自己的 DLL。Windows 與 C/C++ runtime 相依仍須滿足。
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. 選擇模式
先以 `gvfg_playback_default_config()` 初始化 config,再修改需要的欄位。
同步預設開啟;可在 create 後、start 前,或播放途中選擇:
```cpp
gvfg_playback_set_sync_enabled(player, 0); // 影音各自播放,不自動回到同步。
gvfg_playback_set_sync_enabled(player, 1); // 啟用同步;播放途中會先等待來源與輸出穩定。
```
兩行代表不同選擇,擇一呼叫並檢查回傳值。此設定會保留到後續 stop/start 與 reset_timeline。
關閉同步時仍有有界緩衝與過時資料清理;不需要由應用程式調整底層影音輸出。
| `mode` | 資料需求 | 有效 master | 音訊輸出 |
|---|---|---|---|
| `GVFG_PLAYBACK_VIDEO_ONLY` | 持續提交影像 | 強制 External | 不建立 |
| `GVFG_PLAYBACK_AUDIO_ONLY` | 持續提交 PCM | 強制 Audio | 建立 |
| `GVFG_PLAYBACK_AUDIO_VIDEO` | 兩路都須持續提交 | External/Audio/Video,預設 External | 建立 |
純音訊不需 HWND。`attach_window(nullptr)` 是隱藏畫面,仍須提交啟用模式所需的影像;
它不會把影音模式改成純音訊。`set_volume(0)` 是靜音,仍須提交 PCM,音訊時間軸繼續運行。
共同 PTS 說明資料屬於哪個時間;master 決定「現在播到哪裡」。相同時間軸不代表兩個
實際輸出裝置的速度與延遲相同。External 用單調系統時鐘排程;Audio 用估計音訊輸出進度;
Video 用最近成功呈現的影像時間及經過時間。Video master 不保證 GPU 能呈現每張輸入影格。
## 3. 建立與啟動
以下為 C++ 初始化範例;`format` 應由 Capture API 查詢取得,不應假設所有輸入都是 48 kHz。
```cpp
#include "gvfg_capture.h"
#include "gvfg_playback.h"
gvfg_playback_status_t BeginPlayback(
gvfg_playback *out, void *hwnd, const gvfg_audio_format_t &format,
bool enableAudio)
{
if (!out) return GVFG_PLAYBACK_EINVAL;
*out = nullptr;
gvfg_playback p = nullptr;
auto st = gvfg_playback_create(&p);
if (st != GVFG_PLAYBACK_OK) return st;
if (hwnd) st = gvfg_playback_attach_window(p, hwnd);
if (st == GVFG_PLAYBACK_OK) {
gvfg_playback_config_t c{};
gvfg_playback_default_config(&c);
c.mode = enableAudio ? GVFG_PLAYBACK_AUDIO_VIDEO : GVFG_PLAYBACK_VIDEO_ONLY;
if (enableAudio)
c.audio_format = {format.sample_rate,
static_cast<uint16_t>(format.channels),
static_cast<uint16_t>(format.bits_per_sample)};
st = gvfg_playback_start(p, &c);
}
if (st != GVFG_PLAYBACK_OK) {
gvfg_playback_destroy(p);
return st;
}
*out = p;
return GVFG_PLAYBACK_OK;
}
```
一般順序是:建立 Capture handle、選擇/開啟 channel、設定 audio enable、查詢格式、
成功 start capture、建立/綁定/start Playback,最後啟動應用程式的影音讀取執行緒。
任何步驟失敗都須回收已建立資源。Playback 不會代替應用程式開啟或停止擷取裝置。
## 4. 提交影像與 release
`gvfg_frame_t` 與 `gvfg_preview_frame_t` 是不同型別,pixel format 必須明確對應。
不要直接假設兩個 enum 的整數值相同。
```cpp
bool SubmitOneVideo(gvfg_handle capture, int channel, gvfg_playback player)
{
gvfg_frame_t source{};
const auto read = gvfg_read_channel_frame(capture, channel, &source, 100);
if (read == GVFG_ETIMEOUT) return true; // 本次無 frame,沒有 release
if (read != GVFG_OK) return false;
gvfg_playback_video_frame_t v{};
v.image.data = source.data;
v.image.data_size = source.data_size;
v.image.width = source.width;
v.image.height = source.height;
v.image.bit_depth = source.bit_depth;
v.image.row_bytes = source.row_stride_bytes;
v.image.frame_id = source.frame_id;
v.timestamp_ns = source.timestamp_ns;
switch (source.pixel_format) {
case GVFG_PIXFMT_YUY2: v.image.pixel_format = GVFG_PREVIEW_PIXFMT_YUY2; break;
case GVFG_PIXFMT_Y210: v.image.pixel_format = GVFG_PREVIEW_PIXFMT_Y210; break;
default: v.image.pixel_format = 0; break;
}
const auto submit = gvfg_playback_submit_video(player, &v);
const auto release = gvfg_release_channel_frame(capture, channel, &source);
return submit == GVFG_PLAYBACK_OK && release == GVFG_OK;
}
```
成功 read 的原始 token 必須恰好 release 一次,包含 submit 失敗路徑。
submit 成功表示已完成複製並接受排程,不表示已經顯示。Playback 不長期持有 Capture frame。
## 5. 提交 PCM 與 release
```cpp
bool SubmitOneAudio(gvfg_handle capture, int channel, gvfg_playback player)
{
gvfg_audio_frame_t source{};
const auto read = gvfg_read_channel_audio_frame(capture, channel, &source, 100);
if (read == GVFG_ETIMEOUT) return true;
if (read != GVFG_OK) return false;
const auto submit = gvfg_playback_submit_audio(
player, source.data, source.data_size, source.timestamp_ns);
const auto release = gvfg_release_channel_audio_frame(capture, channel, &source);
return submit == GVFG_PLAYBACK_OK && release == GVFG_OK;
}
```
目前接受 signed interleaved PCM16;bytes 必須對齊 `channels * 2`,每包最多 100 ms。
應用程式可像範例一樣直接 submit 後 release,也可先複製、release,再 submit 自有副本。
兩種方式都必須在 release 前完成對 SDK 記憶體的使用。
## 6. 時間戳與播放延遲
- 直接傳入 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. 執行緒、重設與停止
一個 handle 可由一個 video producer 與一個 audio producer 同時 submit。
start、stop、reset、attach、present_image、destroy 等控制操作由 caller 序列化,
並在控制操作前停止/協調 producer;HWND 操作在其所屬 UI 執行緒進行。
停止順序:設停止旗標 → join 影音讀取執行緒 → 確認所有成功 read 都已 release →
Playback stop/destroy → Capture stop;最後一個 channel 結束後才 destroy 共用 Capture handle。
視窗應存活到使用它的播放器結束。
遇到時間倒退、重連或切格式,先協調 producer,再檢查 `reset_timeline()` 回傳值。
reset 會清除待播資料並沿用原 config 重新建立時間軸;音訊格式改變時應 stop/start 新 config。
reset 失敗仍須依回傳狀態處理,不可假設一定成功。
stop/reset 都會取消待播資料,沒有無損 EOS/drain 語意;有限檔案的尾幀完整輸出不是目前 API 的保證。
影音模式遇到音訊輸出故障時,helper 停用監聽音效並繼續播放影像,
後續音訊提交回傳 `EAUDIO`;caller 可提示一次警告,繼續擷取與錄影音訊。
包括啟動時音效裝置無法開啟的情況,影音 start 仍可成功、由音訊提交回報 `EAUDIO`。
預設此狀態保留至 handle 銷毀,stop/reset 不會重試音效;重建 handle 才會再嘗試。
若希望拔插耳機或切換預設輸出後自動恢復監聽,可在 start 前呼叫
`gvfg_playback_enable_audio_reconnect(player)`:影音模式會約每秒重試一次 Windows 預設輸出裝置,
應用程式持續提交新的 PCM,恢復後音訊提交重新回傳 OK。
純音訊模式沒有影像可保留,不會重試,輸出故障仍回報 `EOUTPUT`。
其他 `EOUTPUT` 應檢查 GPU/視窗/記憶體等輸出問題,依錯誤停止或重啟。
## 8. 單張 RAW/DICOM 影像
在 create、attach_window 成功後,用 `gvfg_playback_present_image(player, &image)`;
不要 start。它不需要 PTS,也不啟動音訊,會同步等待已提交的預覽工作完成。
輸入資料須保持有效到返回;只允許停止狀態且已綁定視窗的 handle,否則回傳 `ESTATE`。
若影像沒有被 DXGI Present 接受(例如 GPU busy 或等待逾時),回傳 `EOUTPUT`;
OK 表示已 Present,但不等於已完成實體螢幕掃描。
## 9. 範例與 API Reference
NO SIGNAL 圖卡由 Playback helper 內建與顯示,應用端只需轉交 Capture 的訊號狀態:
```cpp
gvfg_signal_status_t signal{};
if (gvfg_get_channel_signal_status(capture, channel, &signal) == GVFG_OK) {
auto status = gvfg_playback_set_signal_connected(player, signal.connected ? 1 : 0);
// 檢查 status;失敗時使用 gvfg_playback_strerror(status)。
}
```
在綁定 HWND 的 UI 執行緒呼叫,與 attach/destroy 序列化。0 顯示固定圖卡,1 隱藏。
預設為 1;可先設定再 attach,狀態保留至下次明確設定,stop/start/reset 不改變它。
圖卡會隨視窗縮放,應用程式不必自行繪製。
此 API 不讀 Capture、不以 FPS 或黑色像素推測訊號,也不改影格內容、PTS 或錄影。
若未使用此 API,維持一般預覽行為。destroy/detach 也應在 HWND 執行緒執行。
Customer Demo 展示 API 的啟停、提交、release、事件及基本錯誤處理。
應用程式透過 `gvfg_playback_*` 控制播放:獨立預覽使用 video-only,
單張顯示使用 present_image。同步控制由 Playback 處理。
更新 SDK 時,標頭、匯入庫、DLL 與 CMake 應使用同一版本。
逐欄位限制與所有函式見 [公開 API Reference,第 5 節](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md#5-統一-playback-api)。
+10 -6
View File
@@ -1,10 +1,10 @@
# GVFG SDK 與 Demo 建置說明
SDK version 由 `GVFG_SDK/CMakeLists.txt` 決定,目前為 3.1.0。
SDK version 由 `GVFG_SDK/CMakeLists.txt` 決定,目前為 3.2.0。
修改共用類別的成員配置或公開 API 後,先完整重建 SDK,再清理並重建使用它的 APP。
連結成功不代表 object 使用相同的類別大小;標頭相依追蹤失效時,舊 object 可能造成
heap corruption。SDK 3.0.0 的 OSD 與 Playback 統計介面含不相容變更,部署時必須配套
heap corruption。SDK 3.0.0 的 OSD 與 Playback 統計介面,以及 3.2.0 將 OSD 移到 `gvfg_osd.dll`,都是不相容變更;部署時必須配套
使用同版 header、import library 與 DLL,不可只替換單一檔案。
Sample version 由自己的 CMake 決定;目前 checkout 是內部分支,與 customer master 不必相同。
@@ -46,7 +46,7 @@ SDK 與 Demo 現在不是同一個頂層 CMake 專案。不存在 `BUILD_GVFG_SA
```bat
cmake -S GVFG_Standalone/GVFG_SDK -B GVFG_Standalone/GVFG_SDK/build_release -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build GVFG_Standalone/GVFG_SDK/build_release --target gvfg gvfg_playback
cmake --build GVFG_Standalone/GVFG_SDK/build_release --target gvfg gvfg_osd gvfg_playback
```
Ninja 使用 CMAKE_BUILD_TYPE;Visual Studio 多組態 generator 使用 `--config Release`。
@@ -86,8 +86,10 @@ Customer Demo 使用公開 API、基本狀態與必要錯誤,不輸出同步
Release 不編譯該診斷來源。內部版規則以 Sample 的 INTERNAL_BRANCH_WORKFLOW.md 為準;
不要把內部分支或 Debug binary 當成客戶交付版本。
SDK 與 Preview 的 `GVFG_INTERNAL_DIAGNOSTICS` 各由其 CMake 依組態定義,
不是可任意切換所有模組的統一 runtime 設定。不要假設 Debug 有 vendor 未提供的 IRQ/DMA loss counter。
`GVFG_INTERNAL_DIAGNOSTICS` 是編譯期定義,各 target 的 CMake 自行決定:`gvfg` 與 `gvfg_playback`
在 Debug 組態,或設定頂層 CMake 選項 `-DGVFG_ENABLE_INTERNAL_DIAGNOSTICS=ON`(預設 OFF)時啟用;
`gvfg_preview` 只在 Debug 啟用。它不是可任意切換所有模組的統一 runtime 設定。
客戶 Release 套件應使用預設 OFF 建置。不要假設 Debug 有 vendor 未提供的 IRQ/DMA loss counter。
## 6. 安裝與封裝
@@ -95,9 +97,11 @@ SDK 與 Preview 的 `GVFG_INTERNAL_DIAGNOSTICS` 各由其 CMake 依組態定義
cmake --install GVFG_Standalone/GVFG_SDK/build_release --prefix sdk_package
```
乾淨 install tree 只交付 Capture/Playback 的 DLL 與匯入庫、公開標頭及客戶文件。
乾淨 install tree 只交付 Capture/OSD/Playback 的 DLL 與匯入庫、公開標頭及客戶文件。
不交付 backend 靜態 `.lib`、private source、gvfg_debug.h、vendor headers 或舊 helper DLL。
客戶文件同時安裝英文(`*.md`)與繁體中文(`*.zh-TW.md`)兩個版本。
文件保留 `GVFG_Customer_doc/` 子目錄,使使用手冊與 API Reference 的相對連結在安裝後仍成立。
`GVFG_Customer_doc/` 內的 PDF 與 DOCX 是產生當時的快照,安裝規則不包含它們。
使用新目錄安裝;cmake install 不會自動移除舊套件留下的 helper DLL 或舊文件。
Customer Sample 的 `package_release.bat` 由已建好的 Release EXE 打包: