From 784aa5c579ee9af94a48e7c3a21f2097653848a6 Mon Sep 17 00:00:00 2001 From: "Mark.lin" Date: Tue, 1 Dec 2026 16:03:38 +0800 Subject: [PATCH] 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 --- AGENTS.md | 6 +- GVFG_SDK/CMakeLists.txt | 6 +- GVFG_SDK/helpers/gvfg_osd/README.md | 31 +- GVFG_SDK/helpers/gvfg_playback/README.md | 14 +- GVFG_SDK/third_party/GigabyteLib/README.md | 4 +- README.md | 129 +- README.zh-TW.md | 97 ++ docs/GVFG_ARCHITECTURE_OVERVIEW.drawio | 219 +-- docs/GVFG_CUSTOMER_API.md | 535 ++++---- docs/GVFG_CUSTOMER_API.zh-TW.md | 496 +++++++ docs/GVFG_Customer_doc/GIGABYTELIB_GAPS.md | 13 +- .../GVFG_CUSTOMER_API_REFERENCE.md | 1206 +++++++++-------- .../GVFG_CUSTOMER_API_REFERENCE.zh-TW.md | 1032 ++++++++++++++ docs/GVFG_ERROR_HANDLING.md | 9 +- docs/GVFG_FRAME_FLOW_AND_STATE.md | 5 +- docs/GVFG_INTERNAL_NOTES.md | 33 +- docs/GVFG_LEARNING_INDEX.md | 13 +- docs/GVFG_Overview.md | 5 +- docs/GVFG_PLAYBACK_API.md | 225 +-- docs/GVFG_PLAYBACK_API.zh-TW.md | 227 ++++ docs/INTERNAL_BUILD_GUIDE.md | 16 +- 21 files changed, 3277 insertions(+), 1044 deletions(-) create mode 100644 README.zh-TW.md create mode 100644 docs/GVFG_CUSTOMER_API.zh-TW.md create mode 100644 docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md create mode 100644 docs/GVFG_PLAYBACK_API.zh-TW.md diff --git a/AGENTS.md b/AGENTS.md index c05dd03..a4619df 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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 目錄。 diff --git a/GVFG_SDK/CMakeLists.txt b/GVFG_SDK/CMakeLists.txt index 72738b6..cd13c7b 100644 --- a/GVFG_SDK/CMakeLists.txt +++ b/GVFG_SDK/CMakeLists.txt @@ -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 ) diff --git a/GVFG_SDK/helpers/gvfg_osd/README.md b/GVFG_SDK/helpers/gvfg_osd/README.md index 7ea90f8..3d691ef 100644 --- a/GVFG_SDK/helpers/gvfg_osd/README.md +++ b/GVFG_SDK/helpers/gvfg_osd/README.md @@ -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 diff --git a/GVFG_SDK/helpers/gvfg_playback/README.md b/GVFG_SDK/helpers/gvfg_playback/README.md index 80c863d..ddef4ac 100644 --- a/GVFG_SDK/helpers/gvfg_playback/README.md +++ b/GVFG_SDK/helpers/gvfg_playback/README.md @@ -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,避免混版。 diff --git a/GVFG_SDK/third_party/GigabyteLib/README.md b/GVFG_SDK/third_party/GigabyteLib/README.md index bdd77f1..1236163 100644 --- a/GVFG_SDK/third_party/GigabyteLib/README.md +++ b/GVFG_SDK/third_party/GigabyteLib/README.md @@ -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, diff --git a/README.md b/README.md index 3f58b28..3958af4 100644 --- a/README.md +++ b/README.md @@ -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 --prefix ` 取得配套輸出。 -Customer Demo 的 Release 打包腳本使用 EXE 同目錄中的 Capture/Playback DLL, -不會代為編譯,也不從其他 build 目錄任意挑 DLL。 +Run `cmake --install --prefix ` 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. diff --git a/README.zh-TW.md b/README.zh-TW.md new file mode 100644 index 0000000..0e51fda --- /dev/null +++ b/README.zh-TW.md @@ -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 --prefix ` 取得配套輸出。 +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 維護說明; +短測、建置通過不代表完成聲學嘴型精度、小時級漂移或所有硬體/格式驗證。 diff --git a/docs/GVFG_ARCHITECTURE_OVERVIEW.drawio b/docs/GVFG_ARCHITECTURE_OVERVIEW.drawio index cf41a1e..a388722 100644 --- a/docs/GVFG_ARCHITECTURE_OVERVIEW.drawio +++ b/docs/GVFG_ARCHITECTURE_OVERVIEW.drawio @@ -1,110 +1,159 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - + - - + + - + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/GVFG_CUSTOMER_API.md b/docs/GVFG_CUSTOMER_API.md index b3c856f..3c3e3dc 100644 --- a/docs/GVFG_CUSTOMER_API.md +++ b/docs/GVFG_CUSTOMER_API.md @@ -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 @@ -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 +#include // includes gvfg_capture.h #include 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` 的函式內,使用 ``、``、``; -`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 ``, ``, and +``; `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). diff --git a/docs/GVFG_CUSTOMER_API.zh-TW.md b/docs/GVFG_CUSTOMER_API.zh-TW.md new file mode 100644 index 0000000..982667b --- /dev/null +++ b/docs/GVFG_CUSTOMER_API.zh-TW.md @@ -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 + +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_capture.h +#include + +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` 的函式內,使用 ``、``、``; +`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)。 diff --git a/docs/GVFG_Customer_doc/GIGABYTELIB_GAPS.md b/docs/GVFG_Customer_doc/GIGABYTELIB_GAPS.md index ed6c4fd..07efa8b 100644 --- a/docs/GVFG_Customer_doc/GIGABYTELIB_GAPS.md +++ b/docs/GVFG_Customer_doc/GIGABYTELIB_GAPS.md @@ -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.*`. diff --git a/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md b/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md index e70678e..25ff22d 100644 --- a/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md +++ b/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md @@ -1,72 +1,75 @@ -# GVFG 客戶 API Reference +# GVFG Customer API Reference -SDK 3.1.0。Capture 與 Playback 使用各自的 API 與狀態碼。 +English | [繁體中文](GVFG_CUSTOMER_API_REFERENCE.zh-TW.md) -本版含不相容的 OSD 介面更新,並移除公開的 Playback 核心與 Preview delivery 詳細統計查詢。 -使用本版 header、import library 與 DLL 重新編譯;不可混用 SDK 2.x 二進位檔案。 +SDK 3.2.0. Capture, OSD, and Playback are three DLLs. Capture and Playback have their own APIs and +status codes; OSD uses the Capture `gvfg_status_t`. -- [擷取型別與常數](#1-gvfg-api-結構與常數) -- [擷取函式](#2-gvfg-api-函式) -- [播放影像型別](#3-playback-使用的影像型別) -- [播放 API、config 與限制](#4-統一-playback-api) +SDK 3.2.0 moved the OSD functions and types from `gvfg_capture.h`/`gvfg.dll` to +`gvfg_osd.h`/`gvfg_osd.dll`, and added an HDMI audio query. Recompile with this version's headers, +import libraries, and DLLs; do not mix in binaries from 3.1 or earlier. -## 1. GVFG API 結構與常數 +- [Capture types and constants](#1-gvfg-api-types-and-constants) +- [Capture functions](#2-gvfg-api-functions) +- [OSD API](#3-osd-api) +- [Playback image types](#4-image-types-used-by-playback) +- [Playback API, config, and limits](#5-unified-playback-api) -說明 `gvfg_capture.h` 的所有公開常數、型別、結構。除非特別註明, -所有輸出結構都建議先用 `{0}` 初始化。 +## 1. GVFG API types and constants -### 1.1 公開常數 +This section describes every public constant, type, and struct in `gvfg_capture.h`; OSD types are in +section 3. Unless noted otherwise, initialize every output struct with `{0}` first. -| 常數 | 值 | 說明 | -| ----------------------- | ------------:| ----------------------------- | -| `GVFG_MAX_DEVICES` | 16 | 一次最多列舉的裝置數 | -| `GVFG_TIMEOUT_INFINITE` | `UINT32_MAX` | 無限等待;`timeout_ms == 0` 則完全不等待 | -| `GVFG_OSD_MAX_TEXT_CHARACTERS` | 32 | 每組 OSD 可列印 ASCII 字元數上限 | -| `GVFG_OSD_SLOT_COUNT` | 2 | 每個 channel 的獨立 OSD 組數 | +### 1.1 Public constants + +| Constant | Value | Meaning | +| ----------------------- | ------------:| -------------------------------------------------------- | +| `GVFG_MAX_DEVICES` | 16 | Maximum number of devices enumerated at once | +| `GVFG_TIMEOUT_INFINITE` | `UINT32_MAX` | Wait indefinitely; `timeout_ms == 0` never waits | ### 1.2 `gvfg_status_t` -`gvfg_status_t` 是 32-bit 整數。`0` 表示成功,失敗時回傳負數的 `GVFG_E*` 狀態。 +`gvfg_status_t` is a 32-bit integer. `0` means success; failures return a negative `GVFG_E*` status. -| 成員 | 值 | 說明 | -| --------------- | ---:| ---------------------------------------------- | -| `GVFG_OK` | 0 | 成功 | -| `GVFG_EINVAL` | -1 | NULL pointer、無效 channel、buffer 大小或 token 等參數錯誤 | -| `GVFG_ENODEV` | -2 | 找不到裝置或裝置無法開啟 | -| `GVFG_ESTATE` | -3 | 呼叫順序或目前 session 狀態不允許此操作 | -| `GVFG_EIO` | -4 | SDK I/O、GPU 或其他處理失敗 | -| `GVFG_ENOTSUP` | -5 | 不支援指定功能或格式 | -| `GVFG_ETIMEOUT` | -6 | 在期限內等不到 frame、event 或操作完成 | -| `GVFG_EBUSY` | -7 | 裝置或 capture resource 正在使用中 | +| Member | Value | Meaning | +| --------------- | ---:| ---------------------------------------------------------------------- | +| `GVFG_OK` | 0 | Success | +| `GVFG_EINVAL` | -1 | Invalid argument such as a NULL pointer, channel, buffer size, or token | +| `GVFG_ENODEV` | -2 | No device found, or the device cannot be opened | +| `GVFG_ESTATE` | -3 | The call order or current session state does not allow the operation | +| `GVFG_EIO` | -4 | SDK I/O, GPU, or other processing failure | +| `GVFG_ENOTSUP` | -5 | Requested feature or format is not supported | +| `GVFG_ETIMEOUT` | -6 | No frame, event, or completion within the time limit | +| `GVFG_EBUSY` | -7 | Device or capture resource is in use | -統一以 `status != GVFG_OK` 判斷失敗,不可使用 Windows `FAILED()`/`SUCCEEDED()`。 -`gvfg_strerror()` 回傳對應的公開英文錯誤說明。 +Always test for failure with `status != GVFG_OK`; do not use Windows `FAILED()`/`SUCCEEDED()`. +`gvfg_strerror()` returns the matching public English description. ### 1.3 `gvfg_pixel_format_t` -| 成員 | 值 | 說明 | -| --------------------- | ---:| ------------------------------------------------------------- | -| `GVFG_PIXFMT_UNKNOWN` | 0 | 未知或尚無有效訊號格式 | -| `GVFG_PIXFMT_YUY2` | 1 | 8-bit packed YUV 4:2:2;byte order Y0 U0 Y1 V0,每 pixel 2 bytes | -| `GVFG_PIXFMT_Y210` | 2 | 10-bit packed YUV 4:2:2;目前每 pixel 4 bytes | +| Member | Value | Meaning | +| --------------------- | ---:| ---------------------------------------------------------------------- | +| `GVFG_PIXFMT_UNKNOWN` | 0 | Unknown, or no valid signal format yet | +| `GVFG_PIXFMT_YUY2` | 1 | 8-bit packed YUV 4:2:2; byte order Y0 U0 Y1 V0, 2 bytes per pixel | +| `GVFG_PIXFMT_Y210` | 2 | 10-bit packed YUV 4:2:2; currently 4 bytes per pixel | ### 1.4 `gvfg_channel_t` -| 成員 | 值 | 說明 | -| ---------------- | ---:| -------- | -| `GVFG_CHANNEL_0` | 0 | 裝置輸入通道 0 | -| `GVFG_CHANNEL_1` | 1 | 裝置輸入通道 1 | +| Member | Value | Meaning | +| ---------------- | ---:| ---------------------- | +| `GVFG_CHANNEL_0` | 0 | Device input channel 0 | +| `GVFG_CHANNEL_1` | 1 | Device input channel 1 | ### 1.5 `gvfg_video_interface_t` -| 成員 | 值 | 說明 | +| Member | Value | Meaning | | --------------------------- | ---:| ---------- | | `GVFG_INPUT_INTERFACE_SDI` | 0 | SDI input | | `GVFG_INPUT_INTERFACE_HDMI` | 1 | HDMI input | ### 1.6 `gvfg_sdi_mode_t` -| 成員 | 值 | 說明 | +| Member | Value | Meaning | | ------------------------ | ---:| ------------ | | `GVFG_SDI_INPUT_MODE_HD` | 0 | HD-SDI input | | `GVFG_SDI_INPUT_MODE_SD` | 1 | SD-SDI input | @@ -74,174 +77,178 @@ SDK 3.1.0。Capture 與 Playback 使用各自的 API 與狀態碼。 ### 1.7 `gvfg_sdi_resolution_t` -| 成員 | 值 | 說明 | -| -------------------------------------------------- | -----:| ------------------------ | -| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_ST_274_1920X1080` | `0x0` | SMPTE ST 274,1920 x 1080 | -| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_ST_296_1280X720` | `0x1` | SMPTE ST 296,1280 x 720 | -| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_2048_2048X1080` | `0x2` | SMPTE 2048,2048 x 1080 | -| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_295_1920X1080` | `0x3` | SMPTE 295,1920 x 1080 | -| `GVFG_SDI_INPUT_RESOLUTION_NTSC_720X486` | `0x8` | NTSC,720 x 486 | -| `GVFG_SDI_INPUT_RESOLUTION_PAL_720X576` | `0x9` | PAL,720 x 576 | -| `GVFG_SDI_INPUT_RESOLUTION_UNKNOWN` | `0xF` | 未知或不支援的 resolution | +| Member | Value | Meaning | +| -------------------------------------------------- | -----:| ------------------------------------- | +| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_ST_274_1920X1080` | `0x0` | SMPTE ST 274, 1920 x 1080 | +| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_ST_296_1280X720` | `0x1` | SMPTE ST 296, 1280 x 720 | +| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_2048_2048X1080` | `0x2` | SMPTE 2048, 2048 x 1080 | +| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_295_1920X1080` | `0x3` | SMPTE 295, 1920 x 1080 | +| `GVFG_SDI_INPUT_RESOLUTION_NTSC_720X486` | `0x8` | NTSC, 720 x 486 | +| `GVFG_SDI_INPUT_RESOLUTION_PAL_720X576` | `0x9` | PAL, 720 x 576 | +| `GVFG_SDI_INPUT_RESOLUTION_UNKNOWN` | `0xF` | Unknown or unsupported resolution | ### 1.8 `gvfg_sdi_fps_t` -| 成員 | 值 | 說明 | -| -------------------------- | -----:| -------------- | -| `GVFG_SDI_INPUT_FPS_NONE` | `0x0` | 無可用 frame rate | -| `GVFG_SDI_INPUT_FPS_23_98` | `0x2` | 23.98 fps | -| `GVFG_SDI_INPUT_FPS_24` | `0x3` | 24 fps | -| `GVFG_SDI_INPUT_FPS_47_95` | `0x4` | 47.95 fps | -| `GVFG_SDI_INPUT_FPS_25` | `0x5` | 25 fps | -| `GVFG_SDI_INPUT_FPS_29_97` | `0x6` | 29.97 fps | -| `GVFG_SDI_INPUT_FPS_30` | `0x7` | 30 fps | -| `GVFG_SDI_INPUT_FPS_48` | `0x8` | 48 fps | -| `GVFG_SDI_INPUT_FPS_50` | `0x9` | 50 fps | -| `GVFG_SDI_INPUT_FPS_59_94` | `0xA` | 59.94 fps | -| `GVFG_SDI_INPUT_FPS_60` | `0xB` | 60 fps | +| Member | Value | Meaning | +| -------------------------- | -----:| -------------------------- | +| `GVFG_SDI_INPUT_FPS_NONE` | `0x0` | No frame rate available | +| `GVFG_SDI_INPUT_FPS_23_98` | `0x2` | 23.98 fps | +| `GVFG_SDI_INPUT_FPS_24` | `0x3` | 24 fps | +| `GVFG_SDI_INPUT_FPS_47_95` | `0x4` | 47.95 fps | +| `GVFG_SDI_INPUT_FPS_25` | `0x5` | 25 fps | +| `GVFG_SDI_INPUT_FPS_29_97` | `0x6` | 29.97 fps | +| `GVFG_SDI_INPUT_FPS_30` | `0x7` | 30 fps | +| `GVFG_SDI_INPUT_FPS_48` | `0x8` | 48 fps | +| `GVFG_SDI_INPUT_FPS_50` | `0x9` | 50 fps | +| `GVFG_SDI_INPUT_FPS_59_94` | `0xA` | 59.94 fps | +| `GVFG_SDI_INPUT_FPS_60` | `0xB` | 60 fps | ### 1.9 `gvfg_device_info_t` -由 `gvfg_enumerate_devices()` 填入。 +Filled by `gvfg_enumerate_devices()`. -| 欄位 | 型別 | 說明 | -| ------ | ----------- | --------------------------------------- | -| `name` | `char[128]` | 供 UI/log 顯示的 UTF-8、null-terminated 裝置名稱 | +| Field | Type | Meaning | +| ------ | ----------- | ------------------------------------------------------------ | +| `name` | `char[128]` | UTF-8, null-terminated device name for UI/log display | ### 1.10 `gvfg_sdi_info_t` -由 `gvfg_get_channel_sdi_info()` 填入。數值欄位可供程式判斷;對應的 `*_name` -欄位是可直接用於 UI 或 log 的 null-terminated 英文字串。 +Filled by `gvfg_get_channel_sdi_info()`. Numeric fields are for program logic; the matching `*_name` +fields are null-terminated English strings that can be shown directly in a UI or log. -| 欄位 | 型別 | 說明 | -| -------------------------- | ----------------------- | -------------------------------- | -| `connected` | `int` | 非 0 表示 SDI 輸入訊號已 lock | -| `mode` | `gvfg_sdi_mode_t` | 偵測到的 SDI link mode | -| `resolution` | `gvfg_sdi_resolution_t` | 偵測到的 SDI resolution code | -| `fps` | `gvfg_sdi_fps_t` | 偵測到的 SDI frame-rate code | -| `progressive` | `int` | 非 0 為 progressive;0 為 interlaced | -| `level_b` | `int` | 非 0 表示 3G-SDI Level B | -| `st352_payload` | `uint32_t` | SMPTE ST 352 payload identifier | -| `error_count` | `uint32_t` | 裝置回報的 signal error count | -| `signal_lock_name[32]` | `char[32]` | Signal lock 說明 | -| `mode_name[16]` | `char[16]` | SDI mode 名稱 | -| `resolution_name[64]` | `char[64]` | Resolution 名稱 | -| `fps_name[24]` | `char[24]` | Frame-rate 名稱 | -| `scan_name[16]` | `char[16]` | Scan mode 名稱 | -| `st352_format_name[64]` | `char[64]` | ST 352 format 名稱 | -| `st352_fps_name[24]` | `char[24]` | ST 352 frame-rate 名稱 | -| `st352_chroma_name[36]` | `char[36]` | ST 352 chroma 名稱 | -| `st352_bit_depth_name[24]` | `char[24]` | ST 352 bit-depth 名稱 | +| Field | Type | Meaning | +| -------------------------- | ----------------------- | ------------------------------------------ | +| `connected` | `int` | Non-zero when the SDI input signal is locked | +| `mode` | `gvfg_sdi_mode_t` | Detected SDI link mode | +| `resolution` | `gvfg_sdi_resolution_t` | Detected SDI resolution code | +| `fps` | `gvfg_sdi_fps_t` | Detected SDI frame-rate code | +| `progressive` | `int` | Non-zero for progressive; 0 for interlaced | +| `level_b` | `int` | Non-zero for 3G-SDI Level B | +| `st352_payload` | `uint32_t` | SMPTE ST 352 payload identifier | +| `error_count` | `uint32_t` | Signal error count reported by the device | +| `signal_lock_name[32]` | `char[32]` | Signal lock description | +| `mode_name[16]` | `char[16]` | SDI mode name | +| `resolution_name[64]` | `char[64]` | Resolution name | +| `fps_name[24]` | `char[24]` | Frame-rate name | +| `scan_name[16]` | `char[16]` | Scan mode name | +| `st352_format_name[64]` | `char[64]` | ST 352 format name | +| `st352_fps_name[24]` | `char[24]` | ST 352 frame-rate name | +| `st352_chroma_name[36]` | `char[36]` | ST 352 chroma name | +| `st352_bit_depth_name[24]` | `char[24]` | ST 352 bit-depth name | ### 1.11 `gvfg_signal_status_t` -由 `gvfg_get_channel_signal_status()` 填入。 +Filled by `gvfg_get_channel_signal_status()`. -| 欄位 | 型別 | 說明 | -| ----------------- | ----- | ------------------------------------------ | -| `connected` | `int` | 非 0 表示查詢的 channel 目前有有效輸入訊號 | -| `channel` | `int` | 本次查詢對應的 `gvfg_channel_t` 值 | -| `width` | `int` | 連線時的輸入寬度;未連線時為 0 | -| `height` | `int` | 連線時的輸入高度;未連線時為 0 | -| `pixel_format` | `int` | 實際 frame payload 的 `gvfg_pixel_format_t` 值 | -| `bit_depth` | `int` | 從 payload 格式取得的每色彩 channel bit depth | -| `video_interface` | `int` | `gvfg_video_interface_t`,為 SDI 或 HDMI | +| Field | Type | Meaning | +| ----------------- | ----- | ----------------------------------------------------------------- | +| `connected` | `int` | Non-zero when the queried channel currently has a valid input signal | +| `channel` | `int` | The `gvfg_channel_t` value for this query | +| `width` | `int` | Input width when connected; 0 when not connected | +| `height` | `int` | Input height when connected; 0 when not connected | +| `pixel_format` | `int` | `gvfg_pixel_format_t` value of the actual frame payload | +| `bit_depth` | `int` | Bits per color channel derived from the payload format | +| `video_interface` | `int` | `gvfg_video_interface_t`: SDI or HDMI | ### 1.12 `gvfg_runtime_info_t` -由 `gvfg_get_channel_runtime_info()` 填入。Channel 從 stopped 成功進入新的 running -session 時重設統計;對已 running 的 channel 再次呼叫 Start 不會重設。 +Filled by `gvfg_get_channel_runtime_info()`. The statistics reset when a channel successfully moves +from stopped into a new running session; calling start again on a running channel does not reset +them. -| 欄位 | 型別 | 說明 | -| ------------------ | ---------- | ----------------------------------------------------------- | -| `capture_fps` | `double` | 依 `gvfg_read_channel_frame()` 成功交付時間估算的 FPS;尚無足夠 frame 時為 0 | -| `delivered_frames` | `uint64_t` | 此次 running session 中成功交付給 caller 的 frame 數 | +| Field | Type | Meaning | +| ------------------ | ---------- | ------------------------------------------------------------------------------- | +| `capture_fps` | `double` | FPS estimated from successful `gvfg_read_channel_frame()` deliveries; 0 until enough frames | +| `delivered_frames` | `uint64_t` | Frames successfully delivered to the caller in this running session | ### 1.13 `gvfg_frame_t` -由 `gvfg_read_channel_frame()` 填入,也是稍後傳給 `gvfg_release_channel_frame()` 的 frame descriptor。 +Filled by `gvfg_read_channel_frame()`; it is also the frame descriptor later passed to +`gvfg_release_channel_frame()`. -| 欄位 | 型別 | 說明 | -| ------------------ | -------------- | ----------------------------------------- | -| `data` | `const void *` | 借用的 frame buffer;release 或 stop 後失效 | -| `data_size` | `uint64_t` | 此 frame payload 的總 byte 數 | -| `width` | `int` | frame 寬度,單位 pixel | -| `height` | `int` | frame 高度,單位 pixel | -| `row_stride_bytes` | `int` | 相鄰兩列起點間距,單位 byte;處理每列時必須使用此值 | -| `pixel_format` | `int` | `gvfg_pixel_format_t` 值 | -| `bit_depth` | `int` | 原生 frame 每色彩 channel 的 bit depth | -| `frame_id` | `uint64_t` | SDK 成功交付序號;每次 channel Start 從 1 重新開始 | -| `timestamp_ns` | `uint64_t` | SDK 交付時間;與 audio 共用 monotonic clock,單位 ns | +| Field | Type | Meaning | +| ------------------ | -------------- | ----------------------------------------------------------------- | +| `data` | `const void *` | Borrowed frame buffer; invalid after release or stop | +| `data_size` | `uint64_t` | Total bytes in this frame payload | +| `width` | `int` | Frame width in pixels | +| `height` | `int` | Frame height in pixels | +| `row_stride_bytes` | `int` | Bytes between the starts of adjacent rows; always use it when processing rows | +| `pixel_format` | `int` | `gvfg_pixel_format_t` value | +| `bit_depth` | `int` | Bits per color channel of the native frame | +| `frame_id` | `uint64_t` | SDK delivery sequence number; restarts at 1 on every channel start | +| `timestamp_ns` | `uint64_t` | SDK delivery time in ns; shares the monotonic clock with audio | -Caller 應把 read 取得的 descriptor 傳回 release;SDK 以 `data + frame_id` 確認目前 held frame。 +The caller passes the descriptor from read back to release; the SDK identifies the currently held +frame by `data + frame_id`. ### 1.14 `gvfg_audio_format_t` -由 `gvfg_get_channel_audio_format()` 填入,只包含 Application 建立播放或錄音 -格式所需的 PCM metadata。 +Filled by `gvfg_get_channel_audio_format()`. It contains only the PCM metadata the application needs +to set up playback or recording. -| 欄位 | 型別 | 說明 | -| ----------------- | ---------- | ------------------------- | -| `sample_rate` | `uint32_t` | 每秒 sample 數 | -| `channels` | `uint32_t` | interleaved PCM channel 數 | -| `bits_per_sample` | `uint32_t` | 每個 PCM sample 的 bit 數 | +| Field | Type | Meaning | +| ----------------- | ---------- | -------------------------------- | +| `sample_rate` | `uint32_t` | Samples per second | +| `channels` | `uint32_t` | Interleaved PCM channel count | +| `bits_per_sample` | `uint32_t` | Bits per PCM sample | -每個 audio frame 的有效資料長度由 `gvfg_audio_frame_t.data_size` 提供。 +The valid data length of each audio frame is given by `gvfg_audio_frame_t.data_size`. ### 1.15 `gvfg_audio_frame_t` -由 `gvfg_read_channel_audio_frame()` 填入,也是稍後傳給 -`gvfg_release_channel_audio_frame()` 的 audio frame descriptor。 +Filled by `gvfg_read_channel_audio_frame()`; it is also the audio frame descriptor later passed to +`gvfg_release_channel_audio_frame()`. -| 欄位 | 型別 | 說明 | -| ----------------- | -------------- | ----------------------------------------- | -| `data` | `const void *` | 借用的 interleaved PCM;release 或 stop 後失效 | -| `data_size` | `uint64_t` | 此 frame 的有效 PCM byte 數 | -| `sample_rate` | `uint32_t` | 每秒 sample 數 | -| `channels` | `uint32_t` | interleaved PCM channel 數 | -| `bits_per_sample` | `uint32_t` | 每個 PCM sample 的 bit 數 | -| `frame_id` | `uint64_t` | SDK 成功交付序號;每次 channel Start 從 1 重新開始 | -| `timestamp_ns` | `uint64_t` | SDK 交付時間;與 video 共用 monotonic clock,單位 ns | +| Field | Type | Meaning | +| ----------------- | -------------- | ---------------------------------------------------------------- | +| `data` | `const void *` | Borrowed interleaved PCM; invalid after release or stop | +| `data_size` | `uint64_t` | Valid PCM bytes in this frame | +| `sample_rate` | `uint32_t` | Samples per second | +| `channels` | `uint32_t` | Interleaved PCM channel count | +| `bits_per_sample` | `uint32_t` | Bits per PCM sample | +| `frame_id` | `uint64_t` | SDK delivery sequence number; restarts at 1 on every channel start | +| `timestamp_ns` | `uint64_t` | SDK delivery time in ns; shares the monotonic clock with video | -與 video 相同,每個 channel 同時只能持有一個 audio frame;release 以 -`data + frame_id` 確認目前 held frame。 +As with video, each channel holds at most one audio frame at a time; release identifies the held +frame by `data + frame_id`. -Video/audio 的 `timestamp_ns` 可在同一 process/session 內直接比較。它代表 SDK -交付時間,不代表訊號來源端產生 frame 的時間。 +Video and audio `timestamp_ns` values can be compared directly within the same process/session. They +represent SDK delivery time, not the time the frame was produced at the signal source. ### 1.16 `gvfg_gpu_output_format_t` -| 成員 | 值 | 說明 | -| ------------------------- | ---:| ---------------------------------------------------------- | -| `GVFG_GPU_OUTPUT_BGRA8` | 1 | DXGI `B8G8R8A8_UNORM` byte layout,alpha 為 255 | -| `GVFG_GPU_OUTPUT_RGB10A2` | 2 | DXGI `R10G10B10A2_UNORM` packed `uint32_t`,alpha 為 3 | -| `GVFG_GPU_OUTPUT_NV12` | 3 | 8-bit BT.709 limited-range 4:2:0;Y plane 後接 interleaved UV | +| Member | Value | Meaning | +| ------------------------- | ---:| ------------------------------------------------------------------ | +| `GVFG_GPU_OUTPUT_BGRA8` | 1 | DXGI `B8G8R8A8_UNORM` byte layout, alpha 255 | +| `GVFG_GPU_OUTPUT_RGB10A2` | 2 | DXGI `R10G10B10A2_UNORM` packed `uint32_t`, alpha 3 | +| `GVFG_GPU_OUTPUT_NV12` | 3 | 8-bit BT.709 limited-range 4:2:0; Y plane followed by interleaved UV | ### 1.17 `gvfg_gpu_output_buffer_t` -由 caller 建立並傳給 `gvfg_gpu_convert_to_buffer()`。 +Created by the caller and passed to `gvfg_gpu_convert_to_buffer()`. -| 欄位 | 型別 | 說明 | -| -------------- | ---------- | ----------------------------------------------- | -| `data` | `void *` | Caller-owned destination buffer,不可為 NULL | -| `data_size` | `uint64_t` | Destination buffer 可用 byte 數 | -| `row_bytes` | `int` | Destination stride;NV12 的 Y/UV plane 共用此 stride | -| `pixel_format` | `int` | 要求的 `gvfg_gpu_output_format_t` 值 | +| Field | Type | Meaning | +| -------------- | ---------- | --------------------------------------------------------- | +| `data` | `void *` | Caller-owned destination buffer; must not be NULL | +| `data_size` | `uint64_t` | Usable bytes in the destination buffer | +| `row_bytes` | `int` | Destination stride; NV12 Y and UV planes share it | +| `pixel_format` | `int` | Requested `gvfg_gpu_output_format_t` value | -Caller 必須確認尺寸乘法沒有 overflow,並在 conversion 返回前保持 destination 有效。 -呼叫流程見 [使用手冊:GPU 轉換範例](../GVFG_CUSTOMER_API.md#gpu-轉換範例)。 +The caller must check that the size multiplication does not overflow and keep the destination valid +until the conversion returns. For the calling sequence, see +[Guide: GPU conversion example](../GVFG_CUSTOMER_API.md#gpu-conversion-example). ### 1.18 `gvfg_event_type_t` -| 成員 | 值 | 說明 | -| --------------------------------- | ---:| ------------------- | -| `GVFG_EVENT_UNKNOWN` | 0 | 未知事件;正常流程不應依賴此值 | -| `GVFG_EVENT_VIDEO_FORMAT_CHANGED` | 1 | 輸入 video format 已變更 | -| `GVFG_EVENT_VIDEO_INPUT_PLUGIN` | 2 | Video input 已連接 | -| `GVFG_EVENT_VIDEO_INPUT_UNPLUG` | 3 | Video input 已中斷 | +| Member | Value | Meaning | +| --------------------------------- | ---:| --------------------------------------------- | +| `GVFG_EVENT_UNKNOWN` | 0 | Unknown event; normal flows should not rely on it | +| `GVFG_EVENT_VIDEO_FORMAT_CHANGED` | 1 | Input video format changed | +| `GVFG_EVENT_VIDEO_INPUT_PLUGIN` | 2 | Video input connected | +| `GVFG_EVENT_VIDEO_INPUT_UNPLUG` | 3 | Video input disconnected | -SDK 會建立並管理完整的 channel event 集合;使用者直接透過 -`gvfg_poll_channel_event()` 接收。 +The SDK creates and manages the complete set of channel events; applications receive them through +`gvfg_poll_channel_event()`. ### 1.19 `gvfg_handle` @@ -249,39 +256,59 @@ SDK 會建立並管理完整的 channel event 集合;使用者直接透過 typedef struct gvfg_handle_t *gvfg_handle; ``` -只能由 `gvfg_create()` 建立、由 `gvfg_destroy()` 銷毀;caller -不可取得、配置或修改其內部內容。 +Created only by `gvfg_create()` and destroyed only by `gvfg_destroy()`; the caller must not access, +allocate, or modify its contents. -### 1.20 `gvfg_channel_osd_config_t` 與 `gvfg_osd_font_list_t` +### 1.20 `gvfg_hdmi_info_t` -使用 OSD 時請包含 `gvfg_osd.h`,連結 `gvfg_osd.lib`(MinGW 使用 `libgvfg_osd.dll.a`),並隨應用程式部署同一次 SDK 建置的 `gvfg_osd.dll` 和 `gvfg.dll`。一般擷取只需連結 `gvfg.dll` 對應的 import library。 +Filled by `gvfg_get_channel_hdmi_info()`. -```c -typedef struct gvfg_channel_osd_config_t { - const char *text; - const char *font_family; - uint32_t font_size_px; - uint32_t color_rgb; - int32_t x; - int32_t y; -} gvfg_channel_osd_config_t; +| Field | Type | Meaning | +| ----------------------- | ---------- | --------------------------------------------------------------- | +| `connected` | `int` | Non-zero when the HDMI video signal is locked | +| `width`, `height` | `uint32_t` | Source width and height in pixels | +| `fps` | `uint32_t` | Frames per second, for example `60` | +| `color_format` | `uint32_t` | HDMI color format code | +| `color_space` | `uint32_t` | HDMI color space and range code | +| `bit_depth` | `uint32_t` | Source bit depth; may differ from the DMA output bit depth | +| `fps_name[24]` | `char[24]` | Decimal text of `fps` without a unit, for example `"60"` | +| `color_format_name[24]` | `char[24]` | For example `RGB`, `YUV 4:2:2`, `YUV 4:4:4`, `YUV 4:2:0`; `Unknown` otherwise | +| `color_space_name[32]` | `char[32]` | For example `YUV 709`, `BT.2020 RGB`, `RGB (Limited)`; `Unknown` otherwise | -typedef struct gvfg_osd_font_list_t { - uint32_t count; - const char *const *names; -} gvfg_osd_font_list_t; -``` +### 1.21 `gvfg_hdmi_audio_info_t` -`text` 為 NUL 結尾的 1–32 字元可列印 ASCII;`font_family` 為 NUL 結尾的 UTF-8 -已安裝字型家族名稱。Set 返回前複製兩個字串。字串須以 NUL 結尾。 -`font_size_px` 必須非零;`color_rgb` 為 `0x00RRGGBB`;`x/y` 是文字框左上角影像座標。 -字型清單由 SDK 管理,客戶不能修改或 free,使用期限與完整行為見第 2.26 節。 +Filled by `gvfg_get_channel_hdmi_audio_info()`. -## 2. GVFG API 函式 +| Field | Type | Meaning | +| --------------------------- | ---------- | -------------------------------------------------------------- | +| `connected` | `int` | Non-zero when the HDMI audio signal is locked | +| `sample_frequency` | `uint32_t` | HDMI audio sample-frequency code, not a value in Hz | +| `bits_per_sample` | `uint32_t` | Bits per sample | +| `channels` | `uint32_t` | Number of audio channels | +| `format` | `uint32_t` | HDMI audio format code | +| `sample_frequency_name[24]` | `char[24]` | For example `48 kHz`, `96 kHz`, `HBR`; `Unknown` otherwise | +| `format_name[24]` | `char[24]` | For example `Linear PCM`, `AC-3`, `Compressed Audio`; `Unknown` otherwise | -說明 `gvfg_capture.h` 的所有公開函式。 +When `connected == 0`, only the numeric fields are filled and both name fields stay empty. -函式參數方向以 `[in]`、`[out]` 與 `[in, out]` 標示:`[in]` 由 caller 提供, `[out]` 由函式寫入,`[in, out]` 則同時包含 caller 必須先設定的輸入欄位與函式寫回的結果。 +### 1.22 `gvfg_chip_info_t` + +Filled by `gvfg_get_chip_info()`. + +| Field | Type | Meaning | +| -------------- | ---------- | -------------------------------------------------------- | +| `version_date` | `uint32_t` | Chip version date; read its hexadecimal digits as `YYYYMMDD` | +| `version_time` | `uint32_t` | Chip version time; read its hexadecimal digits as `HHMMSS` | + +For example, `0x20261113` and `0x174645` represent `2026-11-13 17:46:45`. + +## 2. GVFG API functions + +This section describes every public function in `gvfg_capture.h`. + +Parameter directions are marked `[in]`, `[out]`, and `[in, out]`: `[in]` is provided by the caller, +`[out]` is written by the function, and `[in, out]` contains input fields the caller must set as well +as results written back by the function. ### 2.1 `gvfg_enumerate_devices` @@ -290,14 +317,15 @@ int gvfg_enumerate_devices(/* [out] */ gvfg_device_info_t *out_devices, /* [in] */ int max_devices); ``` -參數: +Parameters: -- `out_devices`:接收裝置資料的陣列;只查數量時傳 `NULL`。 -- `max_devices`:陣列可容納的項目數;超過 `GVFG_MAX_DEVICES` 會被截斷。當 - `out_devices == NULL` 時應傳 0。 +- `out_devices`: array that receives device entries; pass `NULL` to query the count only. +- `max_devices`: number of entries the array can hold; values larger than `GVFG_MAX_DEVICES` are + clamped. Pass 0 when `out_devices == NULL`. -回傳值:有提供 output array 時為實際寫入數量;只查數量時為可用裝置數;沒有裝置 -時為 0。此函式回傳數量,不回傳 `gvfg_status_t`。 +Return value: the number of entries written when an output array is provided; the number of +available devices when only the count is queried; 0 when there is no device. This function returns a +count, not a `gvfg_status_t`. ### 2.2 `gvfg_create` @@ -305,9 +333,9 @@ int gvfg_enumerate_devices(/* [out] */ gvfg_device_info_t *out_devices, gvfg_status_t gvfg_create(/* [out] */ gvfg_handle *out_handle); ``` -- `out_handle`:接收新 handle,不可為 NULL。 -- 成功:`GVFG_OK`,handle 處於 closed 狀態。 -- 失敗:`GVFG_EINVAL`(output pointer 為 NULL)。 +- `out_handle`: receives the new handle; must not be NULL. +- Success: `GVFG_OK`; the handle starts in the closed state. +- Failure: `GVFG_EINVAL` (the output pointer is NULL). ### 2.3 `gvfg_destroy` @@ -315,8 +343,9 @@ gvfg_status_t gvfg_create(/* [out] */ gvfg_handle *out_handle); gvfg_status_t gvfg_destroy(/* [in] */ gvfg_handle handle); ``` -- `handle`:`gvfg_create()` 回傳的 handle;可為 NULL。 -- 回傳:`GVFG_OK`。若仍在 running,SDK 會先停止。返回後 handle 不得再使用。 +- `handle`: handle returned by `gvfg_create()`; may be NULL. +- Returns `GVFG_OK`. If capture is still running, the SDK stops it first. Do not use the handle after + this call. ### 2.4 `gvfg_open_channel` @@ -326,14 +355,13 @@ gvfg_status_t gvfg_open_channel(/* [in] */ gvfg_handle handle, /* [in] */ int channel_index); ``` -- `handle`:已建立的 session handle。 -- `device_index`:`gvfg_enumerate_devices()` 結果中的 zero-based 陣列位置。 -- `channel_index`:`GVFG_CHANNEL_0` 或 `GVFG_CHANNEL_1`。 -- 可能回傳:`GVFG_OK`、`GVFG_EINVAL`、`GVFG_ENODEV`、`GVFG_ESTATE`、 - `GVFG_EBUSY`、`GVFG_EIO`。 +- `handle`: an existing session handle. +- `device_index`: zero-based position in the `gvfg_enumerate_devices()` result. +- `channel_index`: `GVFG_CHANNEL_0` or `GVFG_CHANNEL_1`. +- May return `GVFG_OK`, `GVFG_EINVAL`, `GVFG_ENODEV`, `GVFG_ESTATE`, `GVFG_EBUSY`, or `GVFG_EIO`. -對同一 handle 可分別 open CH0、CH1。已開啟任一 channel 後,不可使用同一 handle -切換至其他 device index。 +CH0 and CH1 can each be opened on the same handle. Once any channel is open, the same handle cannot +switch to a different device index. ### 2.5 `gvfg_get_channel_sdi_info` @@ -344,34 +372,39 @@ gvfg_status_t gvfg_get_channel_sdi_info( /* [out] */ gvfg_sdi_info_t *out_info); ``` -- `handle`:已 open 指定 channel 的 session。 -- `channel_index`:要查詢的 `GVFG_CHANNEL_0` 或 `GVFG_CHANNEL_1`。 -- `out_info`:接收 SDI 詳細資訊,不可為 NULL。 -- `GVFG_OK`:查詢成功。 -- `GVFG_EINVAL`:handle 或 output pointer 為 NULL,或 channel index 無效。 -- `GVFG_ESTATE`:指定 channel 尚未 open。 -- 裝置查詢失敗時可能回傳 `GVFG_EIO`。 +- `handle`: session on which the channel is open. +- `channel_index`: `GVFG_CHANNEL_0` or `GVFG_CHANNEL_1` to query. +- `out_info`: receives detailed SDI information; must not be NULL. +- `GVFG_OK`: query succeeded. +- `GVFG_EINVAL`: handle or output pointer is NULL, or the channel index is invalid. +- `GVFG_ESTATE`: the channel is not open. +- May return `GVFG_EIO` if the device query fails. -### HDMI 輸入資訊與晶片版本 +### 2.6 HDMI input information, HDMI audio information, and chip version ```c gvfg_status_t gvfg_get_channel_hdmi_info( - gvfg_handle handle, int channel_index, gvfg_hdmi_info_t *out_info); -gvfg_status_t gvfg_get_chip_info(gvfg_handle handle, gvfg_chip_info_t *out_info); + /* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_hdmi_info_t *out_info); +gvfg_status_t gvfg_get_channel_hdmi_audio_info( + /* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_hdmi_audio_info_t *out_info); +gvfg_status_t gvfg_get_chip_info( + /* [in] */ gvfg_handle handle, + /* [out] */ gvfg_chip_info_t *out_info); ``` -- 以 `gvfg_get_channel_signal_status()` 的 `video_interface` 選擇 SDI 或 HDMI 查詢。 - HDMI 查詢要求指定 channel 已 open,回傳來源鎖定狀態、寬高、FPS、色彩格式、 - 色彩空間及位深。來源位深與 DMA 輸出位深可不同。 -- HDMI 的 `fps_name`、`color_format_name` 和 `color_space_name` 可直接顯示。 - HDMI 的 `fps` 是每秒幀數,例如 `60`,`fps_name` 是對應的十進位文字 `"60"`。 - 色彩名稱範例為 `YUV 4:2:2` 和 `BT.2020 RGB (Limited)`。 -- 晶片版本屬於裝置,只需同一 handle 至少有一個 channel 已 open。 - 日期與時間保留原始 32-bit 數值,將十六進位數字分別讀作 `YYYYMMDD` 和 `HHMMSS`。 - 例如 `0x20261113`、`0x174645` 顯示為 `2026-11-13 17:46:45`。 -- 兩支 API 都要求非 NULL 的 handle 和輸出指標,否則回傳 `GVFG_EINVAL`。 - 查詢所需的 channel 尚未 open 時回傳 `GVFG_ESTATE`。 - 只有回傳 `GVFG_OK` 時才可使用輸出資料。 +- Use the `video_interface` from `gvfg_get_channel_signal_status()` to choose the SDI or HDMI query. +- The HDMI video and HDMI audio queries require the channel to be open; see sections 1.20 and 1.21 + for the fields. +- The chip version belongs to the device; at least one channel on the handle must be open. See + section 1.22 for the fields. +- `GVFG_EINVAL`: handle or output pointer is NULL, or the channel index is invalid. +- `GVFG_ESTATE`: the channel required for the query is not open. +- May return `GVFG_EIO` or another `GVFG_E*` status if the device query fails. +- The output struct is cleared on entry; use the output only when the call returns `GVFG_OK`. ```c #include @@ -393,7 +426,7 @@ void print_chip_info(gvfg_handle handle) } ``` -### 2.6 Zero-copy mode selection +### 2.7 Zero-copy mode selection ```c gvfg_status_t gvfg_set_channel_zero_copy_enabled(/* [in] */ gvfg_handle handle, @@ -404,16 +437,18 @@ gvfg_status_t gvfg_get_channel_zero_copy_enabled(/* [in] */ gvfg_handle handle, /* [out] */ int *out_enabled); ``` -- `set` 只能在 `gvfg_create()` 後、指定 channel open 前呼叫。 -- `enabled` 只接受 0(copy)或 1(zero-copy);每個 channel 預設為 0。 -- 指定 channel 已 open 時呼叫 `set` 會回傳 `GVFG_ESTATE`;不影響另一條 channel。 -- `get` 可查詢指定 channel 的模式;`out_enabled` 不可為 NULL。 -- Zero-copy mode 的 `frame.data` 是借用的 pointer;仍必須以相同 descriptor - 呼叫 `gvfg_release_channel_frame()`,且每個 channel 同時最多持有一張 frame。 -- 此設定控制原生 frame 的擷取方式。OSD 等 SDK 處理可能交付 SDK-owned output - buffer;caller 的 read/release 流程相同。 +- Call `set` only after `gvfg_create()` and before the channel is opened. +- `enabled` accepts only 0 (copy) or 1 (zero-copy); each channel defaults to 0. +- Calling `set` when the channel is already open returns `GVFG_ESTATE`; the other channel is not + affected. +- `get` queries the channel's mode; `out_enabled` must not be NULL. +- In zero-copy mode `frame.data` is a borrowed pointer; you must still call + `gvfg_release_channel_frame()` with the same descriptor, and each channel holds at most one frame + at a time. +- This setting controls how native frames are acquired. SDK processing such as OSD may deliver an + SDK-owned output buffer; the caller's read/release flow is the same. -### 2.7 `gvfg_set_channel_video_format` +### 2.8 `gvfg_set_channel_video_format` ```c gvfg_status_t gvfg_set_channel_video_format(/* [in] */ gvfg_handle handle, @@ -421,12 +456,12 @@ gvfg_status_t gvfg_set_channel_video_format(/* [in] */ gvfg_handle handle, /* [in] */ gvfg_pixel_format_t format); ``` -- 支援 `GVFG_PIXFMT_YUY2` 與 `GVFG_PIXFMT_Y210`。 -- Channel 必須已 open,且 capture 必須尚未 start 或已 stop。 -- 同一 handle 同時只能有一個 channel 選擇 Y210;衝突的要求回傳 `GVFG_EBUSY`。 -- YUY2 對應 8-bit color depth,Y210 對應 10-bit。 +- Supports `GVFG_PIXFMT_YUY2` and `GVFG_PIXFMT_Y210`. +- The channel must be open, and capture must not have started or must have been stopped. +- Only one channel on a handle can select Y210 at a time; a conflicting request returns `GVFG_EBUSY`. +- YUY2 corresponds to 8-bit color depth and Y210 to 10-bit. -### 2.8 Audio capture selection and frame ownership +### 2.9 Audio capture selection and frame ownership ```c gvfg_status_t gvfg_set_channel_audio_enabled(/* [in] */ gvfg_handle handle, @@ -444,39 +479,42 @@ gvfg_status_t gvfg_release_channel_audio_frame(/* [in] */ gvfg_handle handle, /* [in] */ const gvfg_audio_frame_t *frame); ``` -- 預設只擷取 video。CH0 可在 start 前用 `gvfg_set_channel_audio_enabled()` - 啟用 audio。 -- `gvfg_start_channel()` 會依 audio enabled 狀態開始 video-only 或 video + audio capture。 -- `gvfg_read_channel_audio_frame()` 取得下一個 PCM frame 並交付借用的 - descriptor。使用完成後必須呼叫 `gvfg_release_channel_audio_frame()`。 -- 未 release 前再次 read 會回傳 `GVFG_ESTATE`。 -- `out_frame` 為 NULL 或 release token 被修改時回傳 `GVFG_EINVAL`。 -- `timeout_ms` 遵循其他 read API:`0` 不等待,`GVFG_TIMEOUT_INFINITE` 無限等待, - 超時回傳 `GVFG_ETIMEOUT`。 -- Video 與 audio 應由不同 worker thread read;同一 channel 不可同時執行兩個 - audio read。 -- Stop/close 後 descriptor 立即失效;要跨越 release/stop 保存 PCM 必須先複製。 +- By default only video is captured. On CH0, enable audio with `gvfg_set_channel_audio_enabled()` + before start. +- `gvfg_start_channel()` starts video-only or video + audio capture according to the audio setting. +- `gvfg_read_channel_audio_frame()` gets the next PCM frame and hands over a borrowed descriptor. Call + `gvfg_release_channel_audio_frame()` when you are done with it. +- Reading again before release returns `GVFG_ESTATE`. +- A NULL `out_frame` or a modified release token returns `GVFG_EINVAL`. +- `timeout_ms` follows the other read APIs: `0` does not wait, `GVFG_TIMEOUT_INFINITE` waits + indefinitely, and a timeout returns `GVFG_ETIMEOUT`. +- Read video and audio on separate worker threads; do not run two audio reads on the same channel + concurrently. +- The descriptor becomes invalid immediately after stop/close; copy the PCM if it must survive + release or stop. -### 2.9 `gvfg_start_channel` +### 2.10 `gvfg_start_channel` ```c gvfg_status_t gvfg_start_channel(/* [in] */ gvfg_handle handle, /* [in] */ int channel_index); ``` -- `handle`:已成功 open 的 session handle。 -- `GVFG_OK`:開始擷取,或 channel 已經 running。 -- `GVFG_EINVAL`:handle 為 NULL。 -- `GVFG_ESTATE`:尚未 open 裝置。 -- `GVFG_ETIMEOUT`:本次 Start 的即時 signal query 顯示沒有 lock;channel 不會進入 running。 -- `GVFG_EBUSY`:裝置或 capture resource 正在使用中。 -- `GVFG_EIO`:capture 啟動或 I/O 失敗。 +- `handle`: a session handle that has been opened successfully. +- `GVFG_OK`: capture started, or the channel is already running. +- `GVFG_EINVAL`: handle is NULL. +- `GVFG_ESTATE`: no device is open. +- `GVFG_ETIMEOUT`: the live signal query for this start shows no lock; the channel does not enter + running. +- `GVFG_EBUSY`: the device or capture resource is in use. +- `GVFG_EIO`: capture start or I/O failure. -Channel 從 stopped 開始新的 running session 時會執行一次新的 signal query,不沿用 -停止前的 signal cache。對已 running 的 channel 再次呼叫 Start 會直接回傳 `GVFG_OK`, -不會重新查詢訊號。無訊號時 Application 應等待輸入恢復後再次呼叫 Start。 +When a channel starts a new running session from stopped, it runs a fresh signal query instead of +reusing the signal cache from before the stop. Calling start again on a running channel returns +`GVFG_OK` directly without querying the signal again. With no signal, the application should wait +for the input to return and then call start again. -### 2.10 `gvfg_read_channel_frame` +### 2.11 `gvfg_read_channel_frame` ```c gvfg_status_t gvfg_read_channel_frame(/* [in] */ gvfg_handle handle, @@ -485,20 +523,23 @@ gvfg_status_t gvfg_read_channel_frame(/* [in] */ gvfg_handle handle, /* [in] */ uint32_t timeout_ms); ``` -- `handle`:running session。 -- `out_frame`:接收 frame descriptor,不可為 NULL;呼叫前建議清零。 -- `timeout_ms`:0 為 non-blocking;`GVFG_TIMEOUT_INFINITE` 為無限等待;其他值為毫秒。 -- `GVFG_OK`:成功取得 frame,caller 現在持有一個必須 release 的 token。 -- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。 -- `GVFG_ESTATE`:未 running、已有 held frame、已有另一個 read,或 read 期間被 stop(包含 stop 後又重新 start;此時不會交出 stop 前的 frame)。 -- `GVFG_ETIMEOUT`:期限內沒有 frame。 -- `GVFG_EBUSY` 表示 capture resource 正在使用中;`GVFG_EIO` 表示 capture 或 I/O 失敗; - `GVFG_ENOTSUP` 表示 SDK 不支援該格式。 +- `handle`: a running session. +- `out_frame`: receives the frame descriptor; must not be NULL. Clear it before the call. +- `timeout_ms`: 0 is non-blocking; `GVFG_TIMEOUT_INFINITE` waits indefinitely; other values are in + milliseconds. +- `GVFG_OK`: a frame was received, and the caller now holds a token that must be released. +- `GVFG_EINVAL`: handle or output pointer is NULL. +- `GVFG_ESTATE`: not running, a frame is already held, another read is in progress, or the channel + was stopped during the read (including a stop followed by a new start; a frame from before the + stop is never delivered). +- `GVFG_ETIMEOUT`: no frame within the time limit. +- `GVFG_EBUSY` means the capture resource is in use; `GVFG_EIO` means a capture or I/O failure; + `GVFG_ENOTSUP` means the SDK does not support the format. -Copy mode 與 zero-copy mode 都會回傳借用的 frame buffer。兩者的 pointer 都只保證 -有效到對應的 `gvfg_release_channel_frame()`。 +Both copy mode and zero-copy mode return a borrowed frame buffer. In both cases the pointer is only +guaranteed valid until the matching `gvfg_release_channel_frame()`. -### 2.11 `gvfg_release_channel_frame` +### 2.12 `gvfg_release_channel_frame` ```c gvfg_status_t gvfg_release_channel_frame(/* [in] */ gvfg_handle handle, @@ -506,15 +547,15 @@ gvfg_status_t gvfg_release_channel_frame(/* [in] */ gvfg_handle handle, /* [in] */ const gvfg_frame_t *frame); ``` -- `handle`:取得該 frame 的同一個 handle。 -- `frame`:`gvfg_read_channel_frame()` 原封不動回傳的完整 descriptor。 -- `GVFG_OK`:成功歸還 frame。 -- 即使輸入訊號在持有 frame 期間中斷,application 仍應對原本成功取得的 frame - 呼叫一次 release。 -- `GVFG_EINVAL`:NULL 或 token 內容與 held frame 不符。 -- `GVFG_ESTATE`:channel 未開啟,或目前沒有可 release 的 held frame。 +- `handle`: the same handle that read the frame. +- `frame`: the complete descriptor returned unchanged by `gvfg_read_channel_frame()`. +- `GVFG_OK`: the frame was returned. +- Even if the input signal drops while the frame is held, the application should still release each + frame it read successfully once. +- `GVFG_EINVAL`: NULL, or the token does not match the held frame. +- `GVFG_ESTATE`: the channel is not open, or no frame is currently held. -### 2.12 `gvfg_gpu_convert_to_buffer` +### 2.13 `gvfg_gpu_convert_to_buffer` ```c gvfg_status_t gvfg_gpu_convert_to_buffer( @@ -522,14 +563,14 @@ gvfg_status_t gvfg_gpu_convert_to_buffer( /* [in] */ const gvfg_gpu_output_buffer_t *output); ``` -- `source`:有效的 YUY2/Y210 frame;若來自 read,必須尚未 release。 -- `output`:caller 填好的 destination descriptor。 -- `GVFG_OK`:同步轉換及 copy 完成。 -- `GVFG_EINVAL`:NULL、尺寸、stride、buffer size、奇偶尺寸或 overflow 錯誤。 -- `GVFG_ENOTSUP`:input/output format 不支援。 -- `GVFG_EIO`:D3D/GPU resource、dispatch 或 readback 失敗。 +- `source`: a valid YUY2/Y210 frame; if it came from read, it must not be released yet. +- `output`: the destination descriptor filled in by the caller. +- `GVFG_OK`: synchronous conversion and copy completed. +- `GVFG_EINVAL`: NULL, size, stride, buffer size, odd/even size, or overflow error. +- `GVFG_ENOTSUP`: input or output format not supported. +- `GVFG_EIO`: D3D/GPU resource, dispatch, or readback failure. -### 2.13 `gvfg_gpu_convert_to_bgra8` +### 2.14 `gvfg_gpu_convert_to_bgra8` ```c gvfg_status_t gvfg_gpu_convert_to_bgra8( @@ -539,13 +580,13 @@ gvfg_status_t gvfg_gpu_convert_to_bgra8( /* [in] */ int row_bytes); ``` -- `source`:有效且尚未 release 的 YUY2/Y210 frame。 -- `destination`:caller-owned BGRA8 buffer。 -- `destination_size`:buffer byte 數,至少 `row_bytes * source->height`。 -- `row_bytes`:destination stride,至少 `source->width * 4`。 -- 回傳狀態與通用 GPU conversion 相同。 +- `source`: a valid YUY2/Y210 frame that has not been released. +- `destination`: caller-owned BGRA8 buffer. +- `destination_size`: buffer size in bytes, at least `row_bytes * source->height`. +- `row_bytes`: destination stride, at least `source->width * 4`. +- Return statuses are the same as for the generic GPU conversion. -### 2.14 `gvfg_gpu_convert_to_rgb10a2` +### 2.15 `gvfg_gpu_convert_to_rgb10a2` ```c gvfg_status_t gvfg_gpu_convert_to_rgb10a2( @@ -555,10 +596,11 @@ gvfg_status_t gvfg_gpu_convert_to_rgb10a2( /* [in] */ int row_bytes); ``` -參數與 BGRA8 wrapper 相同,但 destination layout 是 packed RGB10A2;每列仍至少 -`source->width * 4` bytes。回傳狀態與通用 GPU conversion 相同。 +Parameters are the same as for the BGRA8 wrapper, but the destination layout is packed RGB10A2; +each row still needs at least `source->width * 4` bytes. Return statuses are the same as for the +generic GPU conversion. -### 2.15 `gvfg_gpu_convert_to_nv12` +### 2.16 `gvfg_gpu_convert_to_nv12` ```c gvfg_status_t gvfg_gpu_convert_to_nv12( @@ -568,13 +610,13 @@ gvfg_status_t gvfg_gpu_convert_to_nv12( /* [in] */ int row_bytes); ``` -- `source`:有效且尚未 release 的 YUY2/Y210 frame;width、height 必須為偶數。 -- `destination`:caller-owned NV12 buffer。 -- `destination_size`:至少 `row_bytes * (height + height / 2)`。 -- `row_bytes`:Y 與 UV plane 共用的 stride,至少為 `width`。 -- 回傳狀態與通用 GPU conversion 相同。 +- `source`: a valid YUY2/Y210 frame that has not been released; width and height must be even. +- `destination`: caller-owned NV12 buffer. +- `destination_size`: at least `row_bytes * (height + height / 2)`. +- `row_bytes`: stride shared by the Y and UV planes, at least `width`. +- Return statuses are the same as for the generic GPU conversion. -### 2.16 `gvfg_poll_channel_event` +### 2.17 `gvfg_poll_channel_event` ```c gvfg_status_t gvfg_poll_channel_event(/* [in] */ gvfg_handle handle, @@ -583,37 +625,37 @@ gvfg_status_t gvfg_poll_channel_event(/* [in] */ gvfg_handle handle, /* [in] */ uint32_t timeout_ms); ``` -- `handle`:running session。 -- `out_event_type`:接收一個 `gvfg_event_type_t` 事件種類,不可為 NULL。 -- `timeout_ms`:規則與 read 相同。 -- `GVFG_OK`:成功取出一個事件。 -- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。 -- `GVFG_ESTATE`:未 running,或等待時被 stop。 -- `GVFG_ETIMEOUT`:期限內沒有事件。 +- `handle`: a running session. +- `out_event_type`: receives one `gvfg_event_type_t` event kind; must not be NULL. +- `timeout_ms`: same rules as read. +- `GVFG_OK`: one event was taken. +- `GVFG_EINVAL`: handle or output pointer is NULL. +- `GVFG_ESTATE`: not running, or stopped while waiting. +- `GVFG_ETIMEOUT`: no event within the time limit. -### 2.17 `gvfg_stop` +### 2.18 `gvfg_stop` ```c gvfg_status_t gvfg_stop(/* [in] */ gvfg_handle handle); ``` -- `handle`:session handle,不可為 NULL。 -- `GVFG_OK`:成功;已經 stopped 也視為成功。 -- `GVFG_EINVAL`:handle 為 NULL。 +- `handle`: session handle; must not be NULL. +- `GVFG_OK`: success; already stopped also counts as success. +- `GVFG_EINVAL`: handle is NULL. -此函式會停止 capture、喚醒等待中的 read/poll,並使未 release frame 失效。 +This function stops capture, wakes waiting read/poll calls, and invalidates unreleased frames. -### 2.18 `gvfg_stop_channel` +### 2.19 `gvfg_stop_channel` ```c gvfg_status_t gvfg_stop_channel(/* [in] */ gvfg_handle handle, /* [in] */ int channel_index); ``` -- 只停止指定 channel;`gvfg_stop()` 會停止同一 handle 已開啟的所有 channel。 -- 尚未 open 的 channel 回傳 `GVFG_ESTATE`。 +- Stops only the given channel; `gvfg_stop()` stops every opened channel on the handle. +- A channel that is not open returns `GVFG_ESTATE`. -### 2.19 `gvfg_get_channel_signal_status` +### 2.20 `gvfg_get_channel_signal_status` ```c gvfg_status_t gvfg_get_channel_signal_status( @@ -622,18 +664,18 @@ gvfg_status_t gvfg_get_channel_signal_status( /* [out] */ gvfg_signal_status_t *out_status); ``` -- `handle`:已 open 的 session。 -- `out_status`:接收 signal status,不可為 NULL。 -- `GVFG_OK`:查詢成功;沒有訊號時仍成功,但 `connected == 0`。 -- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。 -- `GVFG_ESTATE`:尚未 open 裝置。 -- Capture I/O 失敗時可能回傳 `GVFG_EIO`。 +- `handle`: an opened session. +- `out_status`: receives the signal status; must not be NULL. +- `GVFG_OK`: query succeeded; with no signal it still succeeds, with `connected == 0`. +- `GVFG_EINVAL`: handle or output pointer is NULL. +- `GVFG_ESTATE`: no device is open. +- May return `GVFG_EIO` on capture I/O failure. -Channel 尚未 running 時,此 API 會更新目前的 signal status;running 期間回傳最近一次 -觀察到的狀態。Format changed、input plug-in 與 input unplug event 發生後,後續查詢會 -反映更新後的狀態。 +While the channel is not running, this API refreshes the current signal status; while running, it +returns the most recently observed state. After a format changed, input plug-in, or input unplug +event, later queries reflect the updated state. -### 2.20 `gvfg_get_channel_runtime_info` +### 2.21 `gvfg_get_channel_runtime_info` ```c gvfg_status_t gvfg_get_channel_runtime_info( @@ -642,45 +684,48 @@ gvfg_status_t gvfg_get_channel_runtime_info( /* [out] */ gvfg_runtime_info_t *out_info); ``` -- `handle`:已 open 或 running 的 session。 -- `out_info`:接收 runtime statistics,不可為 NULL。 -- `GVFG_OK`:查詢成功。 -- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。 -- `GVFG_ESTATE`:指定 channel 尚未 open。 +- `handle`: an opened or running session. +- `out_info`: receives runtime statistics; must not be NULL. +- `GVFG_OK`: query succeeded. +- `GVFG_EINVAL`: handle or output pointer is NULL. +- `GVFG_ESTATE`: the channel is not open. -### 2.21 `gvfg_get_version`/`gvfg_get_gigabyte_lib_version` +### 2.22 `gvfg_get_version` / `gvfg_get_gigabyte_lib_version` ```c const char *gvfg_get_version(void); const char *gvfg_get_gigabyte_lib_version(void); ``` -- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"3.1.0"`。 -- 回傳值是靜態 null-terminated 字串,caller 不可 free。 -- 可用於 log、問題回報,以及確認 header、DLL 是否來自同一版本。 -- `gvfg_get_gigabyte_lib_version()` 回傳編譯進目前 runtime 的 GigabyteLib 版本常數, - 不是執行時查詢的 driver/FPGA 版本;同樣是靜態字串,不需要 handle,也不可 free。 +- `gvfg_get_version()` returns the version of the GVFG runtime DLL actually loaded, for example + `"3.2.0"`. +- The return value is a static null-terminated string; the caller must not free it. +- Use it for logs, problem reports, and to confirm that the header and DLL come from the same + version. +- `gvfg_get_gigabyte_lib_version()` returns the GigabyteLib version constant compiled into the + current runtime. It is not a run-time driver/FPGA version query. It is also a static string, needs + no handle, and must not be freed. -### 2.22 `gvfg_pixel_format_name` +### 2.23 `gvfg_pixel_format_name` ```c const char *gvfg_pixel_format_name(/* [in] */ int pixel_format); ``` -- `pixel_format`:`gvfg_pixel_format_t` 或其他整數值。 -- 回傳:靜態英文字串 `"YUY2"`、`"Y210"` 或 `"UNKNOWN"`。Caller 不可 free。 +- `pixel_format`: a `gvfg_pixel_format_t` or any other integer. +- Returns the static English string `"YUY2"`, `"Y210"`, or `"UNKNOWN"`. The caller must not free it. -### 2.23 `gvfg_strerror` +### 2.24 `gvfg_strerror` ```c const char *gvfg_strerror(/* [in] */ gvfg_status_t status); ``` -- `status`:任一 GVFG status code。 -- 回傳:靜態、null-terminated 英文說明字串;未知值回傳 unknown 類型說明。 - Caller 不可 free。 +- `status`: any GVFG status code. +- Returns a static, null-terminated English description; unknown values return an "unknown" style + description. The caller must not free it. -### 2.24 `gvfg_get_channel_last_sdk_error_detail` +### 2.25 `gvfg_get_channel_last_sdk_error_detail` ```c gvfg_status_t gvfg_get_channel_last_sdk_error_detail(/* [in] */ gvfg_handle handle, @@ -689,31 +734,81 @@ gvfg_status_t gvfg_get_channel_last_sdk_error_detail(/* [in] */ gvfg_handle hand /* [in] */ uint32_t out_message_size); ``` -此函式提供公開 `GVFG_E*` 失敗狀態的補充說明。回傳內容只描述應用程式可採取行動的 -公開錯誤資訊。 +This function adds detail to a public `GVFG_E*` failure status. The content only describes public +error information the application can act on. -- 複製指定 channel 最近一次 fault 或被拒絕操作的 UTF-8 詳細說明;即使該 channel open 失敗仍可查詢。 -- `gvfg_read_channel_frame()`/`gvfg_poll_channel_event()` 的 timeout、non-blocking 無資料, - 以及正常 stop 喚醒 waiter 都不會覆寫此內容。 -- 每次呼叫 `gvfg_start_channel()` 時會清除先前保存的錯誤說明。 -- 同一 channel 若被多執行緒同時操作,內容可能被後續錯誤覆蓋;應在失敗後立即取得。 -- `GVFG_EINVAL`:handle/message 為 NULL、channel index 無效,或 buffer size 為 0。 +- Copies the UTF-8 detail of the channel's most recent fault or rejected operation; it can be queried + even if opening that channel failed. +- Timeouts and empty non-blocking results from `gvfg_read_channel_frame()`/`gvfg_poll_channel_event()`, + and a normal stop waking a waiter, do not overwrite it. +- Every call to `gvfg_start_channel()` clears the previously saved detail. +- If several threads operate on the same channel, a later error may overwrite the detail; query it + right after the failure. +- `GVFG_EINVAL`: handle/message is NULL, the channel index is invalid, or the buffer size is 0. -### 2.25 `gvfg_measure_osd_text` +## 3. OSD API + +OSD is declared in `gvfg_osd.h` (which includes `gvfg_capture.h`), exported by `gvfg_osd.dll`, and +returns the Capture `gvfg_status_t`. 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`. + +### 3.1 OSD constants and types + +| Constant | Value | Meaning | +|---|---:|---| +| `GVFG_OSD_MAX_TEXT_CHARACTERS` | 32 | Maximum printable ASCII characters per OSD slot | +| `GVFG_OSD_SLOT_COUNT` | 2 | Independent OSD slots per channel | + +```c +typedef struct gvfg_channel_osd_config_t { + const char *text; + const char *font_family; + uint32_t font_size_px; + uint32_t color_rgb; + int32_t x; + int32_t y; +} gvfg_channel_osd_config_t; + +typedef struct gvfg_osd_font_list_t { + uint32_t count; + const char *const *names; +} gvfg_osd_font_list_t; + +typedef struct gvfg_osd_bitmap_t { + const uint8_t *data; + uint64_t data_size; + uint32_t width; + uint32_t height; + uint32_t stride; +} gvfg_osd_bitmap_t; +``` + +`text` is NUL-terminated printable ASCII of 1–32 characters; `font_family` is the NUL-terminated +UTF-8 name of an installed font family. Set copies both strings before it returns. +`font_size_px` must be non-zero; `color_rgb` is `0x00RRGGBB`; `x/y` are the frame coordinates of the +text box's top-left corner. The font list is managed by the SDK and must not be modified or freed by +the customer; see section 3.3 for its lifetime. `gvfg_osd_bitmap_t.data` is owned by the SDK, +`data_size` is `stride * height`, and `stride` is `width * 4`; see section 3.4 for its lifetime. + +### 3.2 `gvfg_measure_osd_text` ```c gvfg_status_t gvfg_measure_osd_text( - const gvfg_channel_osd_config_t *config, - uint32_t *out_width, uint32_t *out_height); + /* [in] */ const gvfg_channel_osd_config_t *config, + /* [out] */ uint32_t *out_width, + /* [out] */ uint32_t *out_height); ``` -不需要 capture handle;使用與繪製相同的文字、字型及大小,忽略位置及顏色。 -輸出為保守完整文字框,包含 overhang 與四邊安全邊;失敗時可寫入的輸出歸零。 +Needs no capture handle or device. It uses the same text, font, and size as rendering and ignores +position and color. The result is a conservative complete text box that includes overhang and a +one-pixel guard on each edge; the outputs are zeroed on failure. A missing font or invalid input +returns `GVFG_EINVAL`. -### 2.26 OSD 字型、設定、顯示/隱藏與清除 +### 3.3 OSD fonts, setting, show/hide, and clear ```c -gvfg_status_t gvfg_get_osd_fonts(gvfg_osd_font_list_t *out_list); +gvfg_status_t gvfg_get_osd_fonts(/* [out] */ gvfg_osd_font_list_t *out_list); gvfg_status_t gvfg_set_channel_osd( gvfg_handle handle, int channel_index, uint32_t osd_index, const gvfg_channel_osd_config_t *config); @@ -723,206 +818,259 @@ gvfg_status_t gvfg_clear_channel_osd( gvfg_handle handle, int channel_index, uint32_t osd_index); ``` -| 項目 | 契約 | +| Item | Contract | |---|---| -| channel/組別 | Set、visibility、Clear 要求 channel 已 open;`osd_index` 為 0 或 1,重疊時 1 在上方 | -| `gvfg_get_osd_fonts()` | 不需要 handle;每次重新檢查 Windows 已安裝字型。成功時回傳 `count` 與 UTF-8 `names`,失敗時清單為空 | -| 清單所有權 | SDK 擁有陣列及字串,caller 不可修改或 free;有效到下一次清單查詢(含失敗呼叫)或 DLL 卸載。長期保存需自行複製;查詢及讀取須由 caller 序列化 | -| `gvfg_set_channel_osd()` | 設定並顯示一組,返回前複製文字與字型名稱,套用到後續 frame;失敗保留原設定 | -| 文字/字型 | `text` 為 NUL 結尾的 1–32 個 ASCII 0x20–0x7e;`font_family` 為 NUL 結尾的 UTF-8 已安裝家族名稱。不接受缺少的字型或無效 UTF-8 | -| 字級/顏色 | `font_size_px` 是非零 em 大小,不等於字形實際墨色高度;normal weight/style/stretch。`color_rgb` 為 0x00RRGGBB,輸出為 BT.709 limited range | -| 位置/尺寸 | `x/y` 為保守量測文字框左上角,會限制在影像內。框太大時只暫停該組;設定或影像尺寸改變後可恢復,不縮字、截字或換行 | -| `gvfg_set_channel_osd_visible()` | `visible` 只接受 0/1;隱藏保留設定,顯示不必重新 Set。顯示未設定或已清除的組別回傳 `GVFG_ESTATE` | -| `gvfg_clear_channel_osd()` | 停用並清除指定組別;之後須重新 Set,不影響另一組 | -| 設定生命週期 | `gvfg_destroy()` 後不保留設定;應用程式自行保存需要還原的內容 | +| Channel/slot | Set, visibility, and Clear require the channel to be open; `osd_index` is 0 or 1, and slot 1 is on top where they overlap | +| `gvfg_get_osd_fonts()` | Needs no handle; rechecks the fonts installed in Windows on every call. On success returns `count` and UTF-8 `names`; on failure the list is empty | +| List ownership | The SDK owns the array and strings; the caller must not modify or free them. Valid until the next list query (including a failed one) or DLL unload. Copy names you need to keep; the caller must serialize querying and reading | +| `gvfg_set_channel_osd()` | Configures and shows one slot, copies the text and font name before returning, and applies to subsequent frames; on failure the previous settings are kept | +| Text/font | `text` is NUL-terminated, 1–32 ASCII characters 0x20–0x7e; `font_family` is the NUL-terminated UTF-8 name of an installed family. Missing fonts and invalid UTF-8 are rejected | +| Size/color | `font_size_px` is a non-zero em size, not the actual ink height of the glyphs; normal weight/style/stretch. `color_rgb` is 0x00RRGGBB; output uses BT.709 limited range | +| Position/size | `x/y` is the top-left of the conservatively measured text box and is clamped inside the frame. If the box is too large, only that slot is paused; it resumes after the settings or frame size change. Text is never shrunk, truncated, or wrapped | +| `gvfg_set_channel_osd_visible()` | `visible` accepts only 0/1; hiding keeps the settings, and showing does not require Set again. Showing a slot that was never set or has been cleared returns `GVFG_ESTATE` | +| `gvfg_clear_channel_osd()` | Disables and clears the slot; it must be set again afterwards. The other slot is not affected | +| Settings lifetime | Settings are not kept after `gvfg_destroy()`; the application keeps whatever it needs to restore | -- `GVFG_OK`:呼叫成功;不代表已交付的舊 frame 會改變。 -- `GVFG_EINVAL`:NULL pointer、無效字串/字型/字號/組別/visibility 等參數錯誤。 -- `GVFG_ESTATE`:channel 未 open,或要求顯示未設定的組別。 -- `GVFG_EIO`:量測、配置或其他處理失敗。 +- `GVFG_OK`: the call succeeded; frames already delivered do not change. +- `GVFG_EINVAL`: NULL pointer, or an invalid string, font, size, slot, or visibility value. +- `GVFG_ESTATE`: the channel is not open, or a slot that was never set is being shown. +- `GVFG_EIO`: measurement, allocation, or other processing failure. -完整呼叫流程與程式範例見 -[使用手冊:OSD 呼叫範例](../GVFG_CUSTOMER_API.md#osd-呼叫範例)。 +For the full calling sequence and example, see +[Guide: OSD example](../GVFG_CUSTOMER_API.md#osd-example). -## 3. Playback 使用的影像型別 +### 3.4 `gvfg_render_osd_frame_bgra` -以下型別直接定義於 `gvfg_playback.h`,使用端不需額外的後端標頭。 -此標頭包含 Playback 的公開型別與操作函式;本節介紹影像型別,播放操作見第 4 節。 +```c +gvfg_status_t gvfg_render_osd_frame_bgra( + /* [in] */ uint32_t video_width, + /* [in] */ uint32_t video_height, + /* [in] */ const gvfg_channel_osd_config_t *slot0, + /* [in] */ const gvfg_channel_osd_config_t *slot1, + /* [out] */ gvfg_osd_bitmap_t *out_bitmap); +``` -### 3.1 Preview 型別 +Produces a transparent OSD overlay the same size as the video, for an FPGA or another component to +composite. -本節說明 Playback 使用的資料型別;操作函式與錯誤碼見第 4 節。 +- Needs no capture handle; `video_width`/`video_height` is the target video size in pixels. +- The output is top-down BGRA8888 with premultiplied alpha, `stride = width * 4`, and contains no + video pixels. +- Pass NULL for `slot0`/`slot1` to omit that slot; with both NULL the output is fully transparent. + Slot 1 is composited over slot 0. +- `x/y` are frame coordinates clamped inside the frame; a text box larger than the frame skips that + slot. +- The output is 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. +- `GVFG_EINVAL`: invalid arguments or dimensions (including a total byte size above `UINT32_MAX`). +- `GVFG_EIO`: allocation or rendering failure. On failure the output is empty. +- This function does not affect the channel's GPU OSD. -`gvfg_preview_pixel_format_t`: +## 4. Image types used by Playback -| 成員 | 值 | 說明 | -| ---------------------------- | ---:| ---------------------------------------------- | -| `GVFG_PREVIEW_PIXFMT_YUY2` | 1 | Packed 8-bit YUV 4:2:2,Y0 U0 Y1 V0;Capture 格式應明確對應 | -| `GVFG_PREVIEW_PIXFMT_Y210` | 2 | Packed 10-bit YUV 4:2:2,16-bit containers | -| `GVFG_PREVIEW_PIXFMT_GRAY16` | 4 | 每 pixel 一個 16-bit unsigned grayscale component | -| `GVFG_PREVIEW_PIXFMT_RGBA16` | 5 | 每 pixel 四個 16-bit UNORM component:R、G、B、A | -| `GVFG_PREVIEW_PIXFMT_DICOM_YBR_FULL_422` | 6 | 每 pixel pair 四個 16-bit words:Y0、Y1、Cb、Cr,數值依 bit_depth 靠右對齊 | +The following types are defined directly in `gvfg_playback.h`; no extra backend header is needed. +That header contains Playback's public types and functions; this section covers the image types, and +playback operations are in section 5. -`gvfg_preview_frame_t`: +### 4.1 Preview types -| 欄位 | 說明 | -| ------------------ | ------------------------------------------------------ | -| `data`、`data_size` | Caller-owned frame pointer 與 byte 數 | -| `width`、`height` | Frame pixel 尺寸 | -| `pixel_format` | `gvfg_preview_pixel_format_t` | -| `bit_depth` | Frame bit depth | -| `row_bytes` | Source row stride,通常對應 `gvfg_frame_t.row_stride_bytes` | -| `frame_id` | Frame 識別值,通常對應 `gvfg_frame_t.frame_id` | +This section describes the data types used by Playback; functions and error codes are in section 5. -`gvfg_preview_info_t`: +`gvfg_preview_pixel_format_t`: -| 欄位 | 說明 | -| ---------------------------- | ------------------------------ | -| `active` | 非 0 表示 preview pipeline 已啟用 | -| `width`、`height`、`bit_depth` | 最近使用的 frame 資訊 | -| `pixel_format[32]` | Null-terminated 格式名稱 | -| `adapter_name[160]` | Null-terminated D3D adapter 名稱 | -| `adapter_index` | 使用的 adapter 索引 | +| Member | Value | Meaning | +| ---------------------------------------- | ---:| ---------------------------------------------------------------------- | +| `GVFG_PREVIEW_PIXFMT_YUY2` | 1 | Packed 8-bit YUV 4:2:2, Y0 U0 Y1 V0; map Capture formats explicitly | +| `GVFG_PREVIEW_PIXFMT_Y210` | 2 | Packed 10-bit YUV 4:2:2 in 16-bit containers | +| `GVFG_PREVIEW_PIXFMT_GRAY16` | 4 | One 16-bit unsigned grayscale component per pixel | +| `GVFG_PREVIEW_PIXFMT_RGBA16` | 5 | Four 16-bit UNORM components per pixel: R, G, B, A | +| `GVFG_PREVIEW_PIXFMT_DICOM_YBR_FULL_422` | 6 | Four 16-bit words per pixel pair: Y0, Y1, Cb, Cr, right-aligned to bit_depth | -`gvfg_preview_stats_t`: +`gvfg_preview_frame_t`: -| 欄位 | 說明 | -| ------------------ | ------------------------------------ | -| `present_fps` | 最近五秒成功 Present 的速率 | -| `presented_frames` | 成功 Present 的累積 frame 數 | -| `skipped_presents` | 預覽端略過呈現的累積數;不是 Capture 或錄影掉格總數 | +| Field | Meaning | +| -------------------- | ----------------------------------------------------------------------- | +| `data`, `data_size` | Caller-owned frame pointer and byte count | +| `width`, `height` | Frame size in pixels | +| `pixel_format` | `gvfg_preview_pixel_format_t` | +| `bit_depth` | Frame bit depth | +| `row_bytes` | Source row stride; usually `gvfg_frame_t.row_stride_bytes` | +| `frame_id` | Frame identifier; usually `gvfg_frame_t.frame_id` | -## 4. 統一 Playback API +`gvfg_preview_info_t`: -公開標頭為 `gvfg_playback.h`,連結 `gvfg_playback.lib`、部署 `gvfg_playback.dll`。 -MinGW 使用 `libgvfg_playback.dll.a`。 +| Field | Meaning | +| ------------------------------- | ---------------------------------------- | +| `active` | Non-zero when the preview pipeline is active | +| `width`, `height`, `bit_depth` | Most recently used frame information | +| `pixel_format[32]` | Null-terminated format name | +| `adapter_name[160]` | Null-terminated D3D adapter name | +| `adapter_index` | Index of the adapter in use | -`gvfg_playback` 是 opaque handle。`config.struct_size` 須設為 config 結構大小; -可先呼叫 `gvfg_playback_default_config()` 填好預設值。 -音訊格式 `gvfg_audio_playback_format_t` 包含 sample_rate、channels、bits_per_sample, -目前支援 signed interleaved PCM16。 +`gvfg_preview_stats_t`: -| 函式 | 行為 | +| Field | Meaning | +| ------------------ | ---------------------------------------------------------------------------- | +| `present_fps` | Rate of successful Presents over the last five seconds | +| `presented_frames` | Cumulative number of successfully presented frames | +| `skipped_presents` | Cumulative presents skipped by the preview; not the total frames dropped by capture or recording | + +## 5. Unified Playback API + +The public header is `gvfg_playback.h`; link `gvfg_playback.lib` and deploy `gvfg_playback.dll`. +MinGW uses `libgvfg_playback.dll.a`. + +`gvfg_playback` is an opaque handle. `config.struct_size` must be set to the size of the config +struct; call `gvfg_playback_default_config()` first to fill in the defaults. The audio format +`gvfg_audio_playback_format_t` contains sample_rate, channels, and bits_per_sample; signed +interleaved PCM16 is currently supported. + +| Function | Behavior | |---|---| -| `gvfg_playback_default_config(config)` | 預設影音模式、External master、100 ms preroll、48 kHz stereo PCM16 | -| `gvfg_playback_create(out)` | 建立 handle,不啟動輸出 | -| `gvfg_playback_attach_window(p, hwnd)` | 設定 HWND;NULL 表示無畫面輸出但仍消耗影像時間軸 | -| `gvfg_playback_start(p, config)` | 啟動選定的純影像、純音訊或影音模式 | -| `gvfg_playback_submit_video(p, frame)` | 複製影像與 timestamp,排入共用播放佇列 | -| `gvfg_playback_submit_audio(p, pcm, bytes, timestamp_ns)` | 複製 PCM,以 SDK 交付時間建立來源 sample 時間軸 | -| `gvfg_playback_present_image(p, image)` | 停止狀態、已綁定 HWND 時同步顯示單張影像,不需 start 或 PTS | -| `gvfg_playback_set_volume(p, gain)` | PCM16 軟體音量,範圍 0.0 到 2.0 | -| `gvfg_playback_set_sync_enabled(p, enabled)` | 0 為各自播放且不自動恢復同步;1 為啟用同步,預設 1 | -| `gvfg_playback_reset_timeline(p)` | 丟棄待播資料,使用原設定重新建立時間軸 | -| `gvfg_playback_stop(p)` | 停止播放並丟棄待播資料,可重複呼叫 | -| `gvfg_playback_destroy(p)` | 停止並銷毀,NULL 可安全忽略 | -| `gvfg_playback_get_preview_info(p, info)` | 影像輸出資訊 | -| `gvfg_playback_get_preview_stats(p, stats)` | GPU/呈現統計 | -| `gvfg_playback_set_signal_connected(p, connected)` | UI 執行緒轉交訊號狀態:0 顯示 helper 內建 NO SIGNAL 圖卡,1 隱藏 | -| `gvfg_playback_strerror(status)` | 靜態英文錯誤字串,不可 free | +| `gvfg_playback_default_config(config)` | Default audio-video mode, External master, 100 ms preroll, 48 kHz stereo PCM16 | +| `gvfg_playback_create(out)` | Creates a handle without starting output | +| `gvfg_playback_attach_window(p, hwnd)` | Sets the HWND; NULL means no picture output while the video timeline is still consumed | +| `gvfg_playback_start(p, config)` | Starts the selected video-only, audio-only, or audio-video mode | +| `gvfg_playback_submit_video(p, frame)` | Copies the image and timestamp into the shared playback queue | +| `gvfg_playback_submit_audio(p, pcm, bytes, timestamp_ns)` | Copies PCM and builds the source sample timeline from SDK delivery time | +| `gvfg_playback_present_image(p, image)` | Synchronously displays a single image on a stopped handle with an attached HWND; needs no start or PTS; returns EOUTPUT when the image was not actually presented | +| `gvfg_playback_enable_audio_reconnect(p)` | Optional, before start; after the audio output fails in audio-video mode, automatically retries the Windows default output device | +| `gvfg_playback_set_volume(p, gain)` | PCM16 software volume, range 0.0 to 2.0 | +| `gvfg_playback_set_sync_enabled(p, enabled)` | 0 plays streams independently with no automatic resync; 1 enables sync; default 1 | +| `gvfg_playback_reset_timeline(p)` | Discards pending data and rebuilds the timeline with the original config | +| `gvfg_playback_stop(p)` | Stops playback and discards pending data; can be called repeatedly | +| `gvfg_playback_destroy(p)` | Stops and destroys; NULL is safely ignored | +| `gvfg_playback_get_preview_info(p, info)` | Video output information | +| `gvfg_playback_get_preview_stats(p, stats)` | GPU/presentation statistics | +| `gvfg_playback_set_signal_connected(p, connected)` | Forwards the signal state from the UI thread: 0 shows the helper's built-in NO SIGNAL card, 1 hides it | +| `gvfg_playback_strerror(status)` | Static English error string; must not be freed | -狀態碼為 OK、EINVAL、ESTATE、EOUTPUT、EQUEUE_FULL、EDISCONTINUITY、EAUDIO; -queue 壓力會自動降級並略過過期資料,不要求 caller 因此停止擷取。 -預覽可能略過過時影格;成功提交不保證每張影像都實際顯示。 -音訊及獨立錄影不受此預覽策略影響。 -submit 返回後 caller 可立即釋放 SDK frame;present_image 則須保留資料到函式返回。 -控制操作(含 present_image)須由 caller 序列化;可由獨立影音 producer 併行 submit。 -stop/reset 是取消,不是無損 EOS drain。 +The status codes are OK, EINVAL, ESTATE, EOUTPUT, EQUEUE_FULL, EDISCONTINUITY, and EAUDIO. Queue +pressure automatically degrades playback and skips stale data; the caller does not need to stop +capture because of it. The preview may skip stale frames; a successful submit does not guarantee that +every image is actually displayed. Audio and independent recording are not affected by this preview +policy. After submit returns, the caller can release the SDK frame immediately; for present_image the +data must stay valid until the function returns. Control operations (including present_image) must be +serialized by the caller; separate video and audio producers may submit concurrently. Stop/reset +cancel; they are not a lossless EOS drain. -完整使用流程與可編譯的提交範例見 -[統一影音播放使用手冊](../GVFG_PLAYBACK_API.md)。 +For the complete flow and compilable submission examples, see the +[Unified Playback Guide](../GVFG_PLAYBACK_API.md). -### 4.1 `gvfg_playback_config_t` +### 5.1 `gvfg_playback_config_t` -先呼叫 `gvfg_playback_default_config(&config)`,不需要自行填 struct_size。 -start 會複製設定;只接受停止狀態的 handle,不會代替 caller 停掉既有播放。 -一般使用者保留 `max_video_frames`、`max_audio_ms`、`max_video_bytes` 的預設值即可;這三項是進階容量上限,僅在有明確記憶體或待播容量需求時調整,不代表固定播放延遲。 +Call `gvfg_playback_default_config(&config)` first; you do not need to fill in struct_size yourself. +Start copies the config; it only accepts a stopped handle and does not stop existing playback on the +caller's behalf. Typical users keep the defaults for `max_video_frames`, `max_audio_ms`, and +`max_video_bytes`. These are advanced capacity limits to change only for specific memory or +pending-capacity requirements; they do not represent a fixed playback latency. -| 欄位 | 預設值 | 限制與語意 | +| Field | Default | Limits and meaning | |---|---|---| -| `struct_size` | `sizeof(gvfg_playback_config_t)` | 必須等於目前完整結構大小 | -| `mode` | `GVFG_PLAYBACK_AUDIO_VIDEO` | Video-only=1、Audio-only=2、Audio-video=3 | -| `master` | `GVFG_PLAYBACK_MASTER_EXTERNAL` | External=0、Audio=1、Video=2;純影像強制 External,純音訊強制 Audio | -| `audio_format.sample_rate` | 48000 | 啟用音訊時為 1~384000 Hz;通過參數檢查不代表 Windows 裝置一定支援 | -| `audio_format.channels` | 2 | 啟用音訊時為 1~32 | -| `audio_format.bits_per_sample` | 16 | 啟用音訊時必須為 16,signed interleaved PCM | -| `preroll_ms` | 100 | 1~1000 ms;啟用串流需要的初始/重新緩衝覆蓋範圍 | -| `max_video_frames` | 32 | 1~600,待播影像張數上限;純音訊仍須填合法值 | -| `max_audio_ms` | 1000 | 不小於 preroll_ms,且不超過 10000;包括共用 queue 與輸出端待播量 | -| `max_video_bytes` | 256 MiB | 必須大於 0;包括待播與正在處理的影像 | +| `struct_size` | `sizeof(gvfg_playback_config_t)` | Must equal the current full struct size | +| `mode` | `GVFG_PLAYBACK_AUDIO_VIDEO` | Video-only=1, Audio-only=2, Audio-video=3 | +| `master` | `GVFG_PLAYBACK_MASTER_EXTERNAL` | External=0, Audio=1, Video=2; video-only forces External, audio-only forces Audio | +| `audio_format.sample_rate` | 48000 | 1–384000 Hz when audio is enabled; passing validation does not mean the Windows device supports it | +| `audio_format.channels` | 2 | 1–32 when audio is enabled | +| `audio_format.bits_per_sample` | 16 | Must be 16 when audio is enabled; signed interleaved PCM | +| `preroll_ms` | 100 | 1–1000 ms; initial/rebuffer coverage required for the enabled streams | +| `max_video_frames` | 32 | 1–600; maximum pending video frames; must be valid even for audio-only | +| `max_audio_ms` | 1000 | At least preroll_ms and at most 10000; includes the shared queue and output-side pending audio | +| `max_video_bytes` | 256 MiB | Must be greater than 0; includes pending and in-process video | -External/Audio master 的預覽允許過期退休與 GPU-busy 略過,不是逐幀無損輸出。 -Video master 不啟用自動過期退休;有限緩衝也不保證在輸出速度不足時永久接收所有 frame。 -選擇模式不會改變 Capture SDK 的啟用設定;Capture 的 audio enable 仍由 caller 管理。 +With External/Audio master, the preview allows expired frames to be retired and GPU-busy skips; it is +not lossless frame-by-frame output. Video master does not enable automatic expiry; bounded buffers +also do not guarantee that every frame is accepted forever if output cannot keep up. Choosing a mode +does not change the Capture SDK's settings; Capture audio enable is still managed by the caller. -### 4.2 `gvfg_playback_video_frame_t` +### 5.2 `gvfg_playback_video_frame_t` -| 欄位 | 意義 | +| Field | Meaning | |---|---| -| `image` | `gvfg_preview_frame_t`;資料指標、可用 bytes、尺寸、格式、有效 bit depth、row stride、frame ID | -| `timestamp_ns` | 來源共同單調時間軸的交付奈秒值;非 0、各路嚴格遞增、不超過 INT64_MAX | +| `image` | `gvfg_preview_frame_t`: data pointer, usable bytes, size, format, effective bit depth, row stride, frame ID | +| `timestamp_ns` | Delivery time in ns on the shared monotonic source timeline; non-zero, strictly increasing per stream, at most INT64_MAX | -image 支援 YUY2、Y210、GRAY16、RGBA16、DICOM YBR_FULL_422,以 -`GVFG_PREVIEW_PIXFMT_*` 指定。Capture 的 `GVFG_PIXFMT_*` 必須明確對應,不能直接複製 enum 整數。 -`data_size` 至少覆蓋 `row_bytes * height`;row_bytes 須足夠容納一列指定格式。 -submit 會複製實際影像列範圍,frame ID 僅作身分/統計資訊,不用來計算 PTS。 -影像各欄位與格式 layout 詳見第 3 節。 +The image supports YUY2, Y210, GRAY16, RGBA16, and DICOM YBR_FULL_422, specified with +`GVFG_PREVIEW_PIXFMT_*`. Capture `GVFG_PIXFMT_*` values must be mapped explicitly; do not copy the +enum integers directly. `data_size` must cover at least `row_bytes * height`, and row_bytes must be +large enough for one row of the given format: -### 4.3 `gvfg_playback_submit_audio()` 的輸入 - -| 參數 | 契約 | +| Format | Minimum `row_bytes` | |---|---| -| `p` | 已 start 且啟用音訊的 handle | -| `pcm` | 非 NULL 的 signed interleaved PCM16,返回前保持有效 | -| `bytes` | 大於 0,對齊 channels × 2,每包最多 100 ms | -| `timestamp_ns` | 同一來源時鐘域的 SDK delivery time;須大於包長、非 0、嚴格遞增且不超過 INT64_MAX | +| YUY2 | `((width + 1) / 2) * 4`; odd widths must still hold a whole 4-byte macropixel | +| Y210 | `width * 4` | +| GRAY16 | `width * 2` | +| RGBA16 | `width * 8` | +| DICOM YBR_FULL_422 | `((width + 1) / 2) * 8` | -第一包來源起點估為 timestamp 減去包長;後續維持連續的 sample 時間軸, -平滑追蹤與交付時鐘的長期偏差。相鄰 delivery timestamp 的間隔若超過 250 ms 加上本包包長, -會進入獨立播放並建立新的音訊映射;不會因此停止擷取。重複或倒退的時間仍會回報 EDISCONTINUITY。 -這些規則不會提供硬體擷取時間、漏 sample 數或絕對聲學延遲。 +Submit copies the actual image rows. The frame ID is used only for identity/statistics, not to +compute the PTS. See section 4 for the image fields and format layouts. -### 4.4 狀態碼 +### 5.3 `gvfg_playback_submit_audio()` input -| 值 | 名稱 | caller 處理 | +| Parameter | Contract | +|---|---| +| `p` | A started handle with audio enabled | +| `pcm` | Non-NULL signed interleaved PCM16, valid until the call returns | +| `bytes` | Greater than 0, a multiple of channels × 2, at most 100 ms per packet | +| `timestamp_ns` | SDK delivery time in the same source clock domain; greater than the packet duration, non-zero, strictly increasing, at most INT64_MAX | + +The source start of the first packet is estimated as the timestamp minus the packet duration; after +that a continuous sample timeline is maintained that smoothly tracks long-term drift against the +delivery clock. If the gap between adjacent delivery timestamps exceeds 250 ms plus the current packet +duration, playback switches to independent mode and builds a new audio mapping; capture is not +stopped because of it. Duplicate or backwards timestamps still report EDISCONTINUITY. These rules do +not provide the hardware capture time, the number of lost samples, or the absolute acoustic latency. + +### 5.4 Status codes + +| Value | Name | Caller action | |---:|---|---| -| 0 | `GVFG_PLAYBACK_OK` | 操作成功;submit 成功表示接受,不表示已呈現 | -| -1 | `GVFG_PLAYBACK_EINVAL` | 修正 NULL、格式、尺寸、對齊、struct_size 或 config 範圍 | -| -2 | `GVFG_PLAYBACK_ESTATE` | 檢查是否 start、模式是否啟用該路、單張操作是否在停止且已綁窗狀態 | -| -3 | `GVFG_PLAYBACK_EOUTPUT` | 檢查 WASAPI/GPU/視窗/記憶體及重啟流程;不能假設會自動恢復 | -| -4 | `GVFG_PLAYBACK_EQUEUE_FULL` | 保留值,目前 API 不回傳;queue 壓力由核心自動處理,單筆資料超出容量回傳 EINVAL | -| -5 | `GVFG_PLAYBACK_EDISCONTINUITY` | 協調 producer,重設時間軸;新音訊格式須以新 config stop/start | -| -6 | `GVFG_PLAYBACK_EAUDIO` | 影音模式的監聽音效已因輸出故障停用,影像繼續;提示一次,繼續獨立擷取/錄影。此 handle 不再接受音訊,重建 handle 才重試音效 | +| 0 | `GVFG_PLAYBACK_OK` | Success; a successful submit means accepted, not presented | +| -1 | `GVFG_PLAYBACK_EINVAL` | Fix the NULL, format, size, alignment, struct_size, or config range | +| -2 | `GVFG_PLAYBACK_ESTATE` | Check whether the handle is started, whether the mode enables that stream, and whether single-image calls are on a stopped handle with a window | +| -3 | `GVFG_PLAYBACK_EOUTPUT` | Check WASAPI/GPU/window/memory and the restart flow; do not assume automatic recovery | +| -4 | `GVFG_PLAYBACK_EQUEUE_FULL` | Reserved; current APIs do not return it. Queue pressure is handled by the core automatically; a single item larger than the capacity returns EINVAL | +| -5 | `GVFG_PLAYBACK_EDISCONTINUITY` | Coordinate the producers and reset the timeline; a new audio format needs stop/start with a new config | +| -6 | `GVFG_PLAYBACK_EAUDIO` | Audio monitoring in audio-video mode has been disabled by an output failure, and video continues. Warn once and keep capturing/recording independently. With audio reconnect enabled, keep submitting PCM until it recovers; otherwise only a recreated handle retries audio | -影音模式的音訊輸出故障由音訊 submit 回傳 `EAUDIO`, -影像 submit 繼續。影音 start 遇到音效開啟失敗仍可成功,音訊 submit 會回報 `EAUDIO`。 -停用狀態跨 stop/start/reset 保留;重建 handle 才重試音效。純音訊模式仍視為輸出失敗。 -其他非同步輸出錯誤會由後續 submit 回報。start 成功不保證後續輸出一定正常。 +In audio-video mode, an audio output failure is reported by audio submit as `EAUDIO`, and video +submit continues. If the audio device cannot be opened at audio-video start, start can still succeed +and audio submit reports `EAUDIO`. Without audio reconnect, the disabled state persists across +stop/start/reset and only a recreated handle retries audio. After +`gvfg_playback_enable_audio_reconnect()` is called before start, audio-video mode retries the Windows +default output device about once per second; the application keeps submitting new PCM, and audio +submit returns OK again once output is restored. Audio-only mode does not retry and still treats it +as an output failure. Other asynchronous output errors are reported by later submits. A successful +start does not guarantee that later output will work. -### 4.5 控制 API 的細節 +### 5.5 Control API details -`gvfg_playback_set_sync_enabled(p, enabled)` 接受 0 或 1,其他值/NULL handle 回傳 EINVAL。 -可在 start 前或運行中呼叫;0 立即使用獨立播放且不自動恢復同步,1 在條件穩定後恢復同步。 -設定保留到 stop/start、reset_timeline;重新 create 的 handle 預設為 1。 +`gvfg_playback_set_sync_enabled(p, enabled)` accepts 0 or 1; other values or a NULL handle return +EINVAL. It can be called before start or while running: 0 switches to independent playback +immediately with no automatic resync, and 1 resyncs once conditions are stable. The setting persists +across stop/start and reset_timeline; a newly created handle defaults to 1. -| API | 狀態、ownership 與限制 | +| API | State, ownership, and limits | |---|---| -| `default_config(config)` | NULL 時不操作;其餘填完整預設值與 struct_size | -| `create(out)` | out 不可 NULL;成功後 caller 擁有 handle,失敗時 out 為 NULL | -| `attach_window(p, hwnd)` | 綁定 HWND;NULL 隱藏輸出但保留模式與影像時間軸;不自動 start | -| `start(p, config)` | 必須為停止狀態;重設計數、queue、時鐘,沿用已設定音量與視窗 | -| `submit_video(p, frame)` | 已 start 且啟用影像;返回後無論成功與否,都必須結束 caller 自己的 Capture frame ownership | -| `submit_audio(p, pcm, bytes, ts)` | 已 start 且啟用音訊;成功返回前完成複製 | -| `present_image(p, image)` | 停止狀態且有 HWND;同步等待工作完成,資料須有效到返回;GPU busy 不等於實體顯示成功 | -| `set_volume(p, gain)` | finite 0.0~2.0;可先設定再 start,0 是靜音而不是停音訊 | -| `reset_timeline(p)` | 取消舊待播資料並重設時間軸;保留 config,若原本在播放則恢復播放。須檢查回傳值 | -| `stop(p)` | 停止播放並取消待播資料;可重複呼叫 | -| `destroy(p)` | NULL 安全;停止播放並釋放 handle | -| `get_preview_info(p, info)` | 回傳影像資訊;尚未建立 Preview 時為零值 | -| `get_preview_stats(p, stats)` | 回傳呈現 FPS/計數;尚未建立 Preview 時為零值 | -| `set_signal_connected(p, connected)` | 僅接受 0/1,預設 1。0 顯示 helper 內建圖卡、1 隱藏。可在 attach 前設定,跨 stop/start/reset/reattach 保留;與 attach/destroy 在 HWND 執行緒序列化。圖卡隨視窗縮放,detach/destroy 釋放。此 API 不查詢 Capture、不更動影格或同步、不依 FPS 判斷訊號 | -| `strerror(status)` | 靜態字串,不可 free;未知值回傳 unknown error 文字 | +| `default_config(config)` | Does nothing for NULL; otherwise fills in all defaults and struct_size | +| `create(out)` | out must not be NULL; on success the caller owns the handle; on failure out is NULL | +| `attach_window(p, hwnd)` | Binds the HWND; NULL hides output but keeps the mode and video timeline; does not start automatically | +| `start(p, config)` | Must be stopped; resets counters, queues, and clocks; keeps the volume and window already set | +| `submit_video(p, frame)` | Started with video enabled; after it returns, whether it succeeded or not, the caller must end its own Capture frame ownership | +| `submit_audio(p, pcm, bytes, ts)` | Started with audio enabled; copying completes before a successful return | +| `present_image(p, image)` | Requires a stopped handle with an HWND, otherwise ESTATE. Waits synchronously for the work to finish; the data must stay valid until it returns. Returns EOUTPUT if DXGI Present did not accept the image (for example GPU busy or timeout); OK means presented, not that physical scanout has completed | +| `enable_audio_reconnect(p)` | Callable only before start (ESTATE while running); affects only audio-video mode; the setting stays with the handle | +| `set_volume(p, gain)` | Finite 0.0–2.0; can be set before start; 0 mutes rather than stopping audio | +| `reset_timeline(p)` | Cancels old pending data and resets the timeline; keeps the config and resumes playback if it was playing. Check the return value | +| `stop(p)` | Stops playback and cancels pending data; can be called repeatedly | +| `destroy(p)` | NULL-safe; stops playback and frees the handle | +| `get_preview_info(p, info)` | Returns video information; zero values before Preview has been created | +| `get_preview_stats(p, stats)` | Returns present FPS/counters; zero values before Preview has been created | +| `set_signal_connected(p, connected)` | Accepts only 0/1, default 1. 0 shows the helper's built-in card and 1 hides it. Can be set before attach and persists across stop/start/reset/reattach; serialize with attach/destroy on the HWND thread. The card scales with the window and is freed by detach/destroy. This API does not query Capture, does not change frames or sync, and does not infer the signal from FPS | +| `strerror(status)` | Static string, must not be freed; unknown values return "unknown error" text | -函式完整名稱皆為 `gvfg_playback_` 加上表中名稱。getters 的輸出指標不可 NULL。 -控制操作含 present_image,須由 caller 序列化;一個影像與一個音訊 producer 可併行 submit。 -Playback 不控制 Capture handle,亦不接管它的 read/release 或 channel lifecycle。 +Every function's full name is `gvfg_playback_` followed by the name in the table. Getter output +pointers must not be NULL. Control operations, including present_image, must be serialized by the +caller; one video producer and one audio producer may submit concurrently. Playback does not control +the Capture handle and does not take over its read/release or channel lifecycle. diff --git a/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md b/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md new file mode 100644 index 0000000..795355a --- /dev/null +++ b/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.zh-TW.md @@ -0,0 +1,1032 @@ +# GVFG 客戶 API Reference + +[English](GVFG_CUSTOMER_API_REFERENCE.md) | 繁體中文 + +SDK 3.2.0。Capture、OSD 與 Playback 是三個 DLL;Capture 與 Playback 使用各自的 API 與狀態碼, +OSD 使用 Capture 的 `gvfg_status_t`。 + +SDK 3.2.0 將 OSD 函式與型別從 `gvfg_capture.h`/`gvfg.dll` 移到 `gvfg_osd.h`/`gvfg_osd.dll`, +並新增 HDMI 音訊查詢。使用本版 header、import library 與 DLL 重新編譯;不可混用 3.1 或更早版本的二進位檔案。 + +- [擷取型別與常數](#1-gvfg-api-結構與常數) +- [擷取函式](#2-gvfg-api-函式) +- [OSD API](#3-osd-api) +- [播放影像型別](#4-playback-使用的影像型別) +- [播放 API、config 與限制](#5-統一-playback-api) + +## 1. GVFG API 結構與常數 + +說明 `gvfg_capture.h` 的所有公開常數、型別、結構;OSD 型別見第 3 節。除非特別註明, +所有輸出結構都建議先用 `{0}` 初始化。 + +### 1.1 公開常數 + +| 常數 | 值 | 說明 | +| ----------------------- | ------------:| ----------------------------- | +| `GVFG_MAX_DEVICES` | 16 | 一次最多列舉的裝置數 | +| `GVFG_TIMEOUT_INFINITE` | `UINT32_MAX` | 無限等待;`timeout_ms == 0` 則完全不等待 | + +### 1.2 `gvfg_status_t` + +`gvfg_status_t` 是 32-bit 整數。`0` 表示成功,失敗時回傳負數的 `GVFG_E*` 狀態。 + +| 成員 | 值 | 說明 | +| --------------- | ---:| ---------------------------------------------- | +| `GVFG_OK` | 0 | 成功 | +| `GVFG_EINVAL` | -1 | NULL pointer、無效 channel、buffer 大小或 token 等參數錯誤 | +| `GVFG_ENODEV` | -2 | 找不到裝置或裝置無法開啟 | +| `GVFG_ESTATE` | -3 | 呼叫順序或目前 session 狀態不允許此操作 | +| `GVFG_EIO` | -4 | SDK I/O、GPU 或其他處理失敗 | +| `GVFG_ENOTSUP` | -5 | 不支援指定功能或格式 | +| `GVFG_ETIMEOUT` | -6 | 在期限內等不到 frame、event 或操作完成 | +| `GVFG_EBUSY` | -7 | 裝置或 capture resource 正在使用中 | + +統一以 `status != GVFG_OK` 判斷失敗,不可使用 Windows `FAILED()`/`SUCCEEDED()`。 +`gvfg_strerror()` 回傳對應的公開英文錯誤說明。 + +### 1.3 `gvfg_pixel_format_t` + +| 成員 | 值 | 說明 | +| --------------------- | ---:| ------------------------------------------------------------- | +| `GVFG_PIXFMT_UNKNOWN` | 0 | 未知或尚無有效訊號格式 | +| `GVFG_PIXFMT_YUY2` | 1 | 8-bit packed YUV 4:2:2;byte order Y0 U0 Y1 V0,每 pixel 2 bytes | +| `GVFG_PIXFMT_Y210` | 2 | 10-bit packed YUV 4:2:2;目前每 pixel 4 bytes | + +### 1.4 `gvfg_channel_t` + +| 成員 | 值 | 說明 | +| ---------------- | ---:| -------- | +| `GVFG_CHANNEL_0` | 0 | 裝置輸入通道 0 | +| `GVFG_CHANNEL_1` | 1 | 裝置輸入通道 1 | + +### 1.5 `gvfg_video_interface_t` + +| 成員 | 值 | 說明 | +| --------------------------- | ---:| ---------- | +| `GVFG_INPUT_INTERFACE_SDI` | 0 | SDI input | +| `GVFG_INPUT_INTERFACE_HDMI` | 1 | HDMI input | + +### 1.6 `gvfg_sdi_mode_t` + +| 成員 | 值 | 說明 | +| ------------------------ | ---:| ------------ | +| `GVFG_SDI_INPUT_MODE_HD` | 0 | HD-SDI input | +| `GVFG_SDI_INPUT_MODE_SD` | 1 | SD-SDI input | +| `GVFG_SDI_INPUT_MODE_3G` | 2 | 3G-SDI input | + +### 1.7 `gvfg_sdi_resolution_t` + +| 成員 | 值 | 說明 | +| -------------------------------------------------- | -----:| ------------------------ | +| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_ST_274_1920X1080` | `0x0` | SMPTE ST 274,1920 x 1080 | +| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_ST_296_1280X720` | `0x1` | SMPTE ST 296,1280 x 720 | +| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_2048_2048X1080` | `0x2` | SMPTE 2048,2048 x 1080 | +| `GVFG_SDI_INPUT_RESOLUTION_SMPTE_295_1920X1080` | `0x3` | SMPTE 295,1920 x 1080 | +| `GVFG_SDI_INPUT_RESOLUTION_NTSC_720X486` | `0x8` | NTSC,720 x 486 | +| `GVFG_SDI_INPUT_RESOLUTION_PAL_720X576` | `0x9` | PAL,720 x 576 | +| `GVFG_SDI_INPUT_RESOLUTION_UNKNOWN` | `0xF` | 未知或不支援的 resolution | + +### 1.8 `gvfg_sdi_fps_t` + +| 成員 | 值 | 說明 | +| -------------------------- | -----:| -------------- | +| `GVFG_SDI_INPUT_FPS_NONE` | `0x0` | 無可用 frame rate | +| `GVFG_SDI_INPUT_FPS_23_98` | `0x2` | 23.98 fps | +| `GVFG_SDI_INPUT_FPS_24` | `0x3` | 24 fps | +| `GVFG_SDI_INPUT_FPS_47_95` | `0x4` | 47.95 fps | +| `GVFG_SDI_INPUT_FPS_25` | `0x5` | 25 fps | +| `GVFG_SDI_INPUT_FPS_29_97` | `0x6` | 29.97 fps | +| `GVFG_SDI_INPUT_FPS_30` | `0x7` | 30 fps | +| `GVFG_SDI_INPUT_FPS_48` | `0x8` | 48 fps | +| `GVFG_SDI_INPUT_FPS_50` | `0x9` | 50 fps | +| `GVFG_SDI_INPUT_FPS_59_94` | `0xA` | 59.94 fps | +| `GVFG_SDI_INPUT_FPS_60` | `0xB` | 60 fps | + +### 1.9 `gvfg_device_info_t` + +由 `gvfg_enumerate_devices()` 填入。 + +| 欄位 | 型別 | 說明 | +| ------ | ----------- | --------------------------------------- | +| `name` | `char[128]` | 供 UI/log 顯示的 UTF-8、null-terminated 裝置名稱 | + +### 1.10 `gvfg_sdi_info_t` + +由 `gvfg_get_channel_sdi_info()` 填入。數值欄位可供程式判斷;對應的 `*_name` +欄位是可直接用於 UI 或 log 的 null-terminated 英文字串。 + +| 欄位 | 型別 | 說明 | +| -------------------------- | ----------------------- | -------------------------------- | +| `connected` | `int` | 非 0 表示 SDI 輸入訊號已 lock | +| `mode` | `gvfg_sdi_mode_t` | 偵測到的 SDI link mode | +| `resolution` | `gvfg_sdi_resolution_t` | 偵測到的 SDI resolution code | +| `fps` | `gvfg_sdi_fps_t` | 偵測到的 SDI frame-rate code | +| `progressive` | `int` | 非 0 為 progressive;0 為 interlaced | +| `level_b` | `int` | 非 0 表示 3G-SDI Level B | +| `st352_payload` | `uint32_t` | SMPTE ST 352 payload identifier | +| `error_count` | `uint32_t` | 裝置回報的 signal error count | +| `signal_lock_name[32]` | `char[32]` | Signal lock 說明 | +| `mode_name[16]` | `char[16]` | SDI mode 名稱 | +| `resolution_name[64]` | `char[64]` | Resolution 名稱 | +| `fps_name[24]` | `char[24]` | Frame-rate 名稱 | +| `scan_name[16]` | `char[16]` | Scan mode 名稱 | +| `st352_format_name[64]` | `char[64]` | ST 352 format 名稱 | +| `st352_fps_name[24]` | `char[24]` | ST 352 frame-rate 名稱 | +| `st352_chroma_name[36]` | `char[36]` | ST 352 chroma 名稱 | +| `st352_bit_depth_name[24]` | `char[24]` | ST 352 bit-depth 名稱 | + +### 1.11 `gvfg_signal_status_t` + +由 `gvfg_get_channel_signal_status()` 填入。 + +| 欄位 | 型別 | 說明 | +| ----------------- | ----- | ------------------------------------------ | +| `connected` | `int` | 非 0 表示查詢的 channel 目前有有效輸入訊號 | +| `channel` | `int` | 本次查詢對應的 `gvfg_channel_t` 值 | +| `width` | `int` | 連線時的輸入寬度;未連線時為 0 | +| `height` | `int` | 連線時的輸入高度;未連線時為 0 | +| `pixel_format` | `int` | 實際 frame payload 的 `gvfg_pixel_format_t` 值 | +| `bit_depth` | `int` | 從 payload 格式取得的每色彩 channel bit depth | +| `video_interface` | `int` | `gvfg_video_interface_t`,為 SDI 或 HDMI | + +### 1.12 `gvfg_runtime_info_t` + +由 `gvfg_get_channel_runtime_info()` 填入。Channel 從 stopped 成功進入新的 running +session 時重設統計;對已 running 的 channel 再次呼叫 Start 不會重設。 + +| 欄位 | 型別 | 說明 | +| ------------------ | ---------- | ----------------------------------------------------------- | +| `capture_fps` | `double` | 依 `gvfg_read_channel_frame()` 成功交付時間估算的 FPS;尚無足夠 frame 時為 0 | +| `delivered_frames` | `uint64_t` | 此次 running session 中成功交付給 caller 的 frame 數 | + +### 1.13 `gvfg_frame_t` + +由 `gvfg_read_channel_frame()` 填入,也是稍後傳給 `gvfg_release_channel_frame()` 的 frame descriptor。 + +| 欄位 | 型別 | 說明 | +| ------------------ | -------------- | ----------------------------------------- | +| `data` | `const void *` | 借用的 frame buffer;release 或 stop 後失效 | +| `data_size` | `uint64_t` | 此 frame payload 的總 byte 數 | +| `width` | `int` | frame 寬度,單位 pixel | +| `height` | `int` | frame 高度,單位 pixel | +| `row_stride_bytes` | `int` | 相鄰兩列起點間距,單位 byte;處理每列時必須使用此值 | +| `pixel_format` | `int` | `gvfg_pixel_format_t` 值 | +| `bit_depth` | `int` | 原生 frame 每色彩 channel 的 bit depth | +| `frame_id` | `uint64_t` | SDK 成功交付序號;每次 channel Start 從 1 重新開始 | +| `timestamp_ns` | `uint64_t` | SDK 交付時間;與 audio 共用 monotonic clock,單位 ns | + +Caller 應把 read 取得的 descriptor 傳回 release;SDK 以 `data + frame_id` 確認目前 held frame。 + +### 1.14 `gvfg_audio_format_t` + +由 `gvfg_get_channel_audio_format()` 填入,只包含 Application 建立播放或錄音 +格式所需的 PCM metadata。 + +| 欄位 | 型別 | 說明 | +| ----------------- | ---------- | ------------------------- | +| `sample_rate` | `uint32_t` | 每秒 sample 數 | +| `channels` | `uint32_t` | interleaved PCM channel 數 | +| `bits_per_sample` | `uint32_t` | 每個 PCM sample 的 bit 數 | + +每個 audio frame 的有效資料長度由 `gvfg_audio_frame_t.data_size` 提供。 + +### 1.15 `gvfg_audio_frame_t` + +由 `gvfg_read_channel_audio_frame()` 填入,也是稍後傳給 +`gvfg_release_channel_audio_frame()` 的 audio frame descriptor。 + +| 欄位 | 型別 | 說明 | +| ----------------- | -------------- | ----------------------------------------- | +| `data` | `const void *` | 借用的 interleaved PCM;release 或 stop 後失效 | +| `data_size` | `uint64_t` | 此 frame 的有效 PCM byte 數 | +| `sample_rate` | `uint32_t` | 每秒 sample 數 | +| `channels` | `uint32_t` | interleaved PCM channel 數 | +| `bits_per_sample` | `uint32_t` | 每個 PCM sample 的 bit 數 | +| `frame_id` | `uint64_t` | SDK 成功交付序號;每次 channel Start 從 1 重新開始 | +| `timestamp_ns` | `uint64_t` | SDK 交付時間;與 video 共用 monotonic clock,單位 ns | + +與 video 相同,每個 channel 同時只能持有一個 audio frame;release 以 +`data + frame_id` 確認目前 held frame。 + +Video/audio 的 `timestamp_ns` 可在同一 process/session 內直接比較。它代表 SDK +交付時間,不代表訊號來源端產生 frame 的時間。 + +### 1.16 `gvfg_gpu_output_format_t` + +| 成員 | 值 | 說明 | +| ------------------------- | ---:| ---------------------------------------------------------- | +| `GVFG_GPU_OUTPUT_BGRA8` | 1 | DXGI `B8G8R8A8_UNORM` byte layout,alpha 為 255 | +| `GVFG_GPU_OUTPUT_RGB10A2` | 2 | DXGI `R10G10B10A2_UNORM` packed `uint32_t`,alpha 為 3 | +| `GVFG_GPU_OUTPUT_NV12` | 3 | 8-bit BT.709 limited-range 4:2:0;Y plane 後接 interleaved UV | + +### 1.17 `gvfg_gpu_output_buffer_t` + +由 caller 建立並傳給 `gvfg_gpu_convert_to_buffer()`。 + +| 欄位 | 型別 | 說明 | +| -------------- | ---------- | ----------------------------------------------- | +| `data` | `void *` | Caller-owned destination buffer,不可為 NULL | +| `data_size` | `uint64_t` | Destination buffer 可用 byte 數 | +| `row_bytes` | `int` | Destination stride;NV12 的 Y/UV plane 共用此 stride | +| `pixel_format` | `int` | 要求的 `gvfg_gpu_output_format_t` 值 | + +Caller 必須確認尺寸乘法沒有 overflow,並在 conversion 返回前保持 destination 有效。 +呼叫流程見 [使用手冊:GPU 轉換範例](../GVFG_CUSTOMER_API.zh-TW.md#gpu-轉換範例)。 + +### 1.18 `gvfg_event_type_t` + +| 成員 | 值 | 說明 | +| --------------------------------- | ---:| ------------------- | +| `GVFG_EVENT_UNKNOWN` | 0 | 未知事件;正常流程不應依賴此值 | +| `GVFG_EVENT_VIDEO_FORMAT_CHANGED` | 1 | 輸入 video format 已變更 | +| `GVFG_EVENT_VIDEO_INPUT_PLUGIN` | 2 | Video input 已連接 | +| `GVFG_EVENT_VIDEO_INPUT_UNPLUG` | 3 | Video input 已中斷 | + +SDK 會建立並管理完整的 channel event 集合;使用者直接透過 +`gvfg_poll_channel_event()` 接收。 + +### 1.19 `gvfg_handle` + +```c +typedef struct gvfg_handle_t *gvfg_handle; +``` + +只能由 `gvfg_create()` 建立、由 `gvfg_destroy()` 銷毀;caller +不可取得、配置或修改其內部內容。 + +### 1.20 `gvfg_hdmi_info_t` + +由 `gvfg_get_channel_hdmi_info()` 填入。 + +| 欄位 | 型別 | 說明 | +| ------------------------ | ---------- | ----------------------------------------------- | +| `connected` | `int` | 非 0 表示 HDMI 視訊訊號已 lock | +| `width`、`height` | `uint32_t` | 來源寬高,單位 pixel | +| `fps` | `uint32_t` | 每秒幀數,例如 `60` | +| `color_format` | `uint32_t` | HDMI 色彩格式代碼 | +| `color_space` | `uint32_t` | HDMI 色彩空間與範圍代碼 | +| `bit_depth` | `uint32_t` | 來源位深;可與 DMA 輸出位深不同 | +| `fps_name[24]` | `char[24]` | `fps` 的十進位文字,不含單位,例如 `"60"` | +| `color_format_name[24]` | `char[24]` | 例如 `RGB`、`YUV 4:2:2`、`YUV 4:4:4`、`YUV 4:2:0`;未知為 `Unknown` | +| `color_space_name[32]` | `char[32]` | 例如 `YUV 709`、`BT.2020 RGB`、`RGB (Limited)`;未知為 `Unknown` | + +### 1.21 `gvfg_hdmi_audio_info_t` + +由 `gvfg_get_channel_hdmi_audio_info()` 填入。 + +| 欄位 | 型別 | 說明 | +| --------------------------- | ---------- | ------------------------------------------ | +| `connected` | `int` | 非 0 表示 HDMI 音訊訊號已 lock | +| `sample_frequency` | `uint32_t` | HDMI 音訊取樣頻率代碼,不是 Hz 數值 | +| `bits_per_sample` | `uint32_t` | 每個 sample 的 bit 數 | +| `channels` | `uint32_t` | 聲道數 | +| `format` | `uint32_t` | HDMI 音訊格式代碼 | +| `sample_frequency_name[24]` | `char[24]` | 例如 `48 kHz`、`96 kHz`、`HBR`;未知為 `Unknown` | +| `format_name[24]` | `char[24]` | 例如 `Linear PCM`、`AC-3`、`Compressed Audio`;未知為 `Unknown` | + +`connected == 0` 時只填數值欄位,兩個名稱欄位維持空字串。 + +### 1.22 `gvfg_chip_info_t` + +由 `gvfg_get_chip_info()` 填入。 + +| 欄位 | 型別 | 說明 | +| -------------- | ---------- | -------------------------------------- | +| `version_date` | `uint32_t` | 晶片版本日期;以十六進位數字讀作 `YYYYMMDD` | +| `version_time` | `uint32_t` | 晶片版本時間;以十六進位數字讀作 `HHMMSS` | + +例如 `0x20261113`、`0x174645` 代表 `2026-11-13 17:46:45`。 + +## 2. GVFG API 函式 + +說明 `gvfg_capture.h` 的所有公開函式。 + +函式參數方向以 `[in]`、`[out]` 與 `[in, out]` 標示:`[in]` 由 caller 提供, `[out]` 由函式寫入,`[in, out]` 則同時包含 caller 必須先設定的輸入欄位與函式寫回的結果。 + +### 2.1 `gvfg_enumerate_devices` + +```c +int gvfg_enumerate_devices(/* [out] */ gvfg_device_info_t *out_devices, + /* [in] */ int max_devices); +``` + +參數: + +- `out_devices`:接收裝置資料的陣列;只查數量時傳 `NULL`。 +- `max_devices`:陣列可容納的項目數;超過 `GVFG_MAX_DEVICES` 會被截斷。當 + `out_devices == NULL` 時應傳 0。 + +回傳值:有提供 output array 時為實際寫入數量;只查數量時為可用裝置數;沒有裝置 +時為 0。此函式回傳數量,不回傳 `gvfg_status_t`。 + +### 2.2 `gvfg_create` + +```c +gvfg_status_t gvfg_create(/* [out] */ gvfg_handle *out_handle); +``` + +- `out_handle`:接收新 handle,不可為 NULL。 +- 成功:`GVFG_OK`,handle 處於 closed 狀態。 +- 失敗:`GVFG_EINVAL`(output pointer 為 NULL)。 + +### 2.3 `gvfg_destroy` + +```c +gvfg_status_t gvfg_destroy(/* [in] */ gvfg_handle handle); +``` + +- `handle`:`gvfg_create()` 回傳的 handle;可為 NULL。 +- 回傳:`GVFG_OK`。若仍在 running,SDK 會先停止。返回後 handle 不得再使用。 + +### 2.4 `gvfg_open_channel` + +```c +gvfg_status_t gvfg_open_channel(/* [in] */ gvfg_handle handle, + /* [in] */ int device_index, + /* [in] */ int channel_index); +``` + +- `handle`:已建立的 session handle。 +- `device_index`:`gvfg_enumerate_devices()` 結果中的 zero-based 陣列位置。 +- `channel_index`:`GVFG_CHANNEL_0` 或 `GVFG_CHANNEL_1`。 +- 可能回傳:`GVFG_OK`、`GVFG_EINVAL`、`GVFG_ENODEV`、`GVFG_ESTATE`、 + `GVFG_EBUSY`、`GVFG_EIO`。 + +對同一 handle 可分別 open CH0、CH1。已開啟任一 channel 後,不可使用同一 handle +切換至其他 device index。 + +### 2.5 `gvfg_get_channel_sdi_info` + +```c +gvfg_status_t gvfg_get_channel_sdi_info( + /* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_sdi_info_t *out_info); +``` + +- `handle`:已 open 指定 channel 的 session。 +- `channel_index`:要查詢的 `GVFG_CHANNEL_0` 或 `GVFG_CHANNEL_1`。 +- `out_info`:接收 SDI 詳細資訊,不可為 NULL。 +- `GVFG_OK`:查詢成功。 +- `GVFG_EINVAL`:handle 或 output pointer 為 NULL,或 channel index 無效。 +- `GVFG_ESTATE`:指定 channel 尚未 open。 +- 裝置查詢失敗時可能回傳 `GVFG_EIO`。 + +### 2.6 HDMI 輸入資訊、HDMI 音訊資訊與晶片版本 + +```c +gvfg_status_t gvfg_get_channel_hdmi_info( + /* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_hdmi_info_t *out_info); +gvfg_status_t gvfg_get_channel_hdmi_audio_info( + /* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_hdmi_audio_info_t *out_info); +gvfg_status_t gvfg_get_chip_info( + /* [in] */ gvfg_handle handle, + /* [out] */ gvfg_chip_info_t *out_info); +``` + +- 以 `gvfg_get_channel_signal_status()` 的 `video_interface` 選擇 SDI 或 HDMI 查詢。 +- HDMI 視訊與 HDMI 音訊查詢要求指定 channel 已 open;欄位見第 1.20、1.21 節。 +- 晶片版本屬於裝置,只需同一 handle 至少有一個 channel 已 open;欄位見第 1.22 節。 +- `GVFG_EINVAL`:handle 或輸出指標為 NULL,或 channel index 無效。 +- `GVFG_ESTATE`:查詢所需的 channel 尚未 open。 +- 裝置查詢失敗時可能回傳 `GVFG_EIO` 或其他 `GVFG_E*` 狀態。 +- 呼叫時輸出結構先被清零;只有回傳 `GVFG_OK` 時才可使用輸出資料。 + +```c +#include +#include +#include + +void print_chip_info(gvfg_handle handle) +{ + gvfg_chip_info_t info = {0}; + if (gvfg_get_chip_info(handle, &info) == GVFG_OK) { + char date[9]; + char time[9]; + int date_len = snprintf(date, sizeof date, "%08" PRIX32, info.version_date); + int time_len = snprintf(time, sizeof time, "%06" PRIX32, info.version_time); + if (date_len == 8 && time_len == 6) + printf("Chip version: %.4s-%.2s-%.2s %.2s:%.2s:%.2s\n", + date, date + 4, date + 6, time, time + 2, time + 4); + } +} +``` + +### 2.7 Zero-copy mode selection + +```c +gvfg_status_t gvfg_set_channel_zero_copy_enabled(/* [in] */ gvfg_handle handle, + /* [in] */ int channel, + /* [in] */ int enabled); +gvfg_status_t gvfg_get_channel_zero_copy_enabled(/* [in] */ gvfg_handle handle, + /* [in] */ int channel, + /* [out] */ int *out_enabled); +``` + +- `set` 只能在 `gvfg_create()` 後、指定 channel open 前呼叫。 +- `enabled` 只接受 0(copy)或 1(zero-copy);每個 channel 預設為 0。 +- 指定 channel 已 open 時呼叫 `set` 會回傳 `GVFG_ESTATE`;不影響另一條 channel。 +- `get` 可查詢指定 channel 的模式;`out_enabled` 不可為 NULL。 +- Zero-copy mode 的 `frame.data` 是借用的 pointer;仍必須以相同 descriptor + 呼叫 `gvfg_release_channel_frame()`,且每個 channel 同時最多持有一張 frame。 +- 此設定控制原生 frame 的擷取方式。OSD 等 SDK 處理可能交付 SDK-owned output + buffer;caller 的 read/release 流程相同。 + +### 2.8 `gvfg_set_channel_video_format` + +```c +gvfg_status_t gvfg_set_channel_video_format(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [in] */ gvfg_pixel_format_t format); +``` + +- 支援 `GVFG_PIXFMT_YUY2` 與 `GVFG_PIXFMT_Y210`。 +- Channel 必須已 open,且 capture 必須尚未 start 或已 stop。 +- 同一 handle 同時只能有一個 channel 選擇 Y210;衝突的要求回傳 `GVFG_EBUSY`。 +- YUY2 對應 8-bit color depth,Y210 對應 10-bit。 + +### 2.9 Audio capture selection and frame ownership + +```c +gvfg_status_t gvfg_set_channel_audio_enabled(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [in] */ int enabled); +gvfg_status_t gvfg_get_channel_audio_format(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_audio_format_t *out_format); +gvfg_status_t gvfg_read_channel_audio_frame(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_audio_frame_t *out_frame, + /* [in] */ uint32_t timeout_ms); +gvfg_status_t gvfg_release_channel_audio_frame(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [in] */ const gvfg_audio_frame_t *frame); +``` + +- 預設只擷取 video。CH0 可在 start 前用 `gvfg_set_channel_audio_enabled()` + 啟用 audio。 +- `gvfg_start_channel()` 會依 audio enabled 狀態開始 video-only 或 video + audio capture。 +- `gvfg_read_channel_audio_frame()` 取得下一個 PCM frame 並交付借用的 + descriptor。使用完成後必須呼叫 `gvfg_release_channel_audio_frame()`。 +- 未 release 前再次 read 會回傳 `GVFG_ESTATE`。 +- `out_frame` 為 NULL 或 release token 被修改時回傳 `GVFG_EINVAL`。 +- `timeout_ms` 遵循其他 read API:`0` 不等待,`GVFG_TIMEOUT_INFINITE` 無限等待, + 超時回傳 `GVFG_ETIMEOUT`。 +- Video 與 audio 應由不同 worker thread read;同一 channel 不可同時執行兩個 + audio read。 +- Stop/close 後 descriptor 立即失效;要跨越 release/stop 保存 PCM 必須先複製。 + +### 2.10 `gvfg_start_channel` + +```c +gvfg_status_t gvfg_start_channel(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index); +``` + +- `handle`:已成功 open 的 session handle。 +- `GVFG_OK`:開始擷取,或 channel 已經 running。 +- `GVFG_EINVAL`:handle 為 NULL。 +- `GVFG_ESTATE`:尚未 open 裝置。 +- `GVFG_ETIMEOUT`:本次 Start 的即時 signal query 顯示沒有 lock;channel 不會進入 running。 +- `GVFG_EBUSY`:裝置或 capture resource 正在使用中。 +- `GVFG_EIO`:capture 啟動或 I/O 失敗。 + +Channel 從 stopped 開始新的 running session 時會執行一次新的 signal query,不沿用 +停止前的 signal cache。對已 running 的 channel 再次呼叫 Start 會直接回傳 `GVFG_OK`, +不會重新查詢訊號。無訊號時 Application 應等待輸入恢復後再次呼叫 Start。 + +### 2.11 `gvfg_read_channel_frame` + +```c +gvfg_status_t gvfg_read_channel_frame(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_frame_t *out_frame, + /* [in] */ uint32_t timeout_ms); +``` + +- `handle`:running session。 +- `out_frame`:接收 frame descriptor,不可為 NULL;呼叫前建議清零。 +- `timeout_ms`:0 為 non-blocking;`GVFG_TIMEOUT_INFINITE` 為無限等待;其他值為毫秒。 +- `GVFG_OK`:成功取得 frame,caller 現在持有一個必須 release 的 token。 +- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。 +- `GVFG_ESTATE`:未 running、已有 held frame、已有另一個 read,或 read 期間被 stop(包含 stop 後又重新 start;此時不會交出 stop 前的 frame)。 +- `GVFG_ETIMEOUT`:期限內沒有 frame。 +- `GVFG_EBUSY` 表示 capture resource 正在使用中;`GVFG_EIO` 表示 capture 或 I/O 失敗; + `GVFG_ENOTSUP` 表示 SDK 不支援該格式。 + +Copy mode 與 zero-copy mode 都會回傳借用的 frame buffer。兩者的 pointer 都只保證 +有效到對應的 `gvfg_release_channel_frame()`。 + +### 2.12 `gvfg_release_channel_frame` + +```c +gvfg_status_t gvfg_release_channel_frame(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [in] */ const gvfg_frame_t *frame); +``` + +- `handle`:取得該 frame 的同一個 handle。 +- `frame`:`gvfg_read_channel_frame()` 原封不動回傳的完整 descriptor。 +- `GVFG_OK`:成功歸還 frame。 +- 即使輸入訊號在持有 frame 期間中斷,application 仍應對原本成功取得的 frame + 呼叫一次 release。 +- `GVFG_EINVAL`:NULL 或 token 內容與 held frame 不符。 +- `GVFG_ESTATE`:channel 未開啟,或目前沒有可 release 的 held frame。 + +### 2.13 `gvfg_gpu_convert_to_buffer` + +```c +gvfg_status_t gvfg_gpu_convert_to_buffer( + /* [in] */ const gvfg_frame_t *source, + /* [in] */ const gvfg_gpu_output_buffer_t *output); +``` + +- `source`:有效的 YUY2/Y210 frame;若來自 read,必須尚未 release。 +- `output`:caller 填好的 destination descriptor。 +- `GVFG_OK`:同步轉換及 copy 完成。 +- `GVFG_EINVAL`:NULL、尺寸、stride、buffer size、奇偶尺寸或 overflow 錯誤。 +- `GVFG_ENOTSUP`:input/output format 不支援。 +- `GVFG_EIO`:D3D/GPU resource、dispatch 或 readback 失敗。 + +### 2.14 `gvfg_gpu_convert_to_bgra8` + +```c +gvfg_status_t gvfg_gpu_convert_to_bgra8( + /* [in] */ const gvfg_frame_t *source, + /* [out] */ void *destination, + /* [in] */ uint64_t destination_size, + /* [in] */ int row_bytes); +``` + +- `source`:有效且尚未 release 的 YUY2/Y210 frame。 +- `destination`:caller-owned BGRA8 buffer。 +- `destination_size`:buffer byte 數,至少 `row_bytes * source->height`。 +- `row_bytes`:destination stride,至少 `source->width * 4`。 +- 回傳狀態與通用 GPU conversion 相同。 + +### 2.15 `gvfg_gpu_convert_to_rgb10a2` + +```c +gvfg_status_t gvfg_gpu_convert_to_rgb10a2( + /* [in] */ const gvfg_frame_t *source, + /* [out] */ void *destination, + /* [in] */ uint64_t destination_size, + /* [in] */ int row_bytes); +``` + +參數與 BGRA8 wrapper 相同,但 destination layout 是 packed RGB10A2;每列仍至少 +`source->width * 4` bytes。回傳狀態與通用 GPU conversion 相同。 + +### 2.16 `gvfg_gpu_convert_to_nv12` + +```c +gvfg_status_t gvfg_gpu_convert_to_nv12( + /* [in] */ const gvfg_frame_t *source, + /* [out] */ void *destination, + /* [in] */ uint64_t destination_size, + /* [in] */ int row_bytes); +``` + +- `source`:有效且尚未 release 的 YUY2/Y210 frame;width、height 必須為偶數。 +- `destination`:caller-owned NV12 buffer。 +- `destination_size`:至少 `row_bytes * (height + height / 2)`。 +- `row_bytes`:Y 與 UV plane 共用的 stride,至少為 `width`。 +- 回傳狀態與通用 GPU conversion 相同。 + +### 2.17 `gvfg_poll_channel_event` + +```c +gvfg_status_t gvfg_poll_channel_event(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_event_type_t *out_event_type, + /* [in] */ uint32_t timeout_ms); +``` + +- `handle`:running session。 +- `out_event_type`:接收一個 `gvfg_event_type_t` 事件種類,不可為 NULL。 +- `timeout_ms`:規則與 read 相同。 +- `GVFG_OK`:成功取出一個事件。 +- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。 +- `GVFG_ESTATE`:未 running,或等待時被 stop。 +- `GVFG_ETIMEOUT`:期限內沒有事件。 + +### 2.18 `gvfg_stop` + +```c +gvfg_status_t gvfg_stop(/* [in] */ gvfg_handle handle); +``` + +- `handle`:session handle,不可為 NULL。 +- `GVFG_OK`:成功;已經 stopped 也視為成功。 +- `GVFG_EINVAL`:handle 為 NULL。 + +此函式會停止 capture、喚醒等待中的 read/poll,並使未 release frame 失效。 + +### 2.19 `gvfg_stop_channel` + +```c +gvfg_status_t gvfg_stop_channel(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index); +``` + +- 只停止指定 channel;`gvfg_stop()` 會停止同一 handle 已開啟的所有 channel。 +- 尚未 open 的 channel 回傳 `GVFG_ESTATE`。 + +### 2.20 `gvfg_get_channel_signal_status` + +```c +gvfg_status_t gvfg_get_channel_signal_status( + /* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_signal_status_t *out_status); +``` + +- `handle`:已 open 的 session。 +- `out_status`:接收 signal status,不可為 NULL。 +- `GVFG_OK`:查詢成功;沒有訊號時仍成功,但 `connected == 0`。 +- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。 +- `GVFG_ESTATE`:尚未 open 裝置。 +- Capture I/O 失敗時可能回傳 `GVFG_EIO`。 + +Channel 尚未 running 時,此 API 會更新目前的 signal status;running 期間回傳最近一次 +觀察到的狀態。Format changed、input plug-in 與 input unplug event 發生後,後續查詢會 +反映更新後的狀態。 + +### 2.21 `gvfg_get_channel_runtime_info` + +```c +gvfg_status_t gvfg_get_channel_runtime_info( + /* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ gvfg_runtime_info_t *out_info); +``` + +- `handle`:已 open 或 running 的 session。 +- `out_info`:接收 runtime statistics,不可為 NULL。 +- `GVFG_OK`:查詢成功。 +- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。 +- `GVFG_ESTATE`:指定 channel 尚未 open。 + +### 2.22 `gvfg_get_version`/`gvfg_get_gigabyte_lib_version` + +```c +const char *gvfg_get_version(void); +const char *gvfg_get_gigabyte_lib_version(void); +``` + +- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"3.1.0"`。 +- 回傳值是靜態 null-terminated 字串,caller 不可 free。 +- 可用於 log、問題回報,以及確認 header、DLL 是否來自同一版本。 +- `gvfg_get_gigabyte_lib_version()` 回傳編譯進目前 runtime 的 GigabyteLib 版本常數, + 不是執行時查詢的 driver/FPGA 版本;同樣是靜態字串,不需要 handle,也不可 free。 + +### 2.23 `gvfg_pixel_format_name` + +```c +const char *gvfg_pixel_format_name(/* [in] */ int pixel_format); +``` + +- `pixel_format`:`gvfg_pixel_format_t` 或其他整數值。 +- 回傳:靜態英文字串 `"YUY2"`、`"Y210"` 或 `"UNKNOWN"`。Caller 不可 free。 + +### 2.24 `gvfg_strerror` + +```c +const char *gvfg_strerror(/* [in] */ gvfg_status_t status); +``` + +- `status`:任一 GVFG status code。 +- 回傳:靜態、null-terminated 英文說明字串;未知值回傳 unknown 類型說明。 + Caller 不可 free。 + +### 2.25 `gvfg_get_channel_last_sdk_error_detail` + +```c +gvfg_status_t gvfg_get_channel_last_sdk_error_detail(/* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [out] */ char *out_message, + /* [in] */ uint32_t out_message_size); +``` + +此函式提供公開 `GVFG_E*` 失敗狀態的補充說明。回傳內容只描述應用程式可採取行動的 +公開錯誤資訊。 + +- 複製指定 channel 最近一次 fault 或被拒絕操作的 UTF-8 詳細說明;即使該 channel open 失敗仍可查詢。 +- `gvfg_read_channel_frame()`/`gvfg_poll_channel_event()` 的 timeout、non-blocking 無資料, + 以及正常 stop 喚醒 waiter 都不會覆寫此內容。 +- 每次呼叫 `gvfg_start_channel()` 時會清除先前保存的錯誤說明。 +- 同一 channel 若被多執行緒同時操作,內容可能被後續錯誤覆蓋;應在失敗後立即取得。 +- `GVFG_EINVAL`:handle/message 為 NULL、channel index 無效,或 buffer size 為 0。 + +## 3. OSD API + +OSD 定義在 `gvfg_osd.h`(已包含 `gvfg_capture.h`),由 `gvfg_osd.dll` 匯出,回傳 Capture 的 +`gvfg_status_t`。使用時連結 `gvfg_osd.lib`(MinGW 使用 `libgvfg_osd.dll.a`),並隨應用程式部署 +同一次 SDK 建置的 `gvfg_osd.dll` 與 `gvfg.dll`。一般擷取只需連結 `gvfg.dll` 對應的 import library。 + +### 3.1 OSD 常數與型別 + +| 常數 | 值 | 說明 | +|---|---:|---| +| `GVFG_OSD_MAX_TEXT_CHARACTERS` | 32 | 每組 OSD 可列印 ASCII 字元數上限 | +| `GVFG_OSD_SLOT_COUNT` | 2 | 每個 channel 的獨立 OSD 組數 | + +```c +typedef struct gvfg_channel_osd_config_t { + const char *text; + const char *font_family; + uint32_t font_size_px; + uint32_t color_rgb; + int32_t x; + int32_t y; +} gvfg_channel_osd_config_t; + +typedef struct gvfg_osd_font_list_t { + uint32_t count; + const char *const *names; +} gvfg_osd_font_list_t; + +typedef struct gvfg_osd_bitmap_t { + const uint8_t *data; + uint64_t data_size; + uint32_t width; + uint32_t height; + uint32_t stride; +} gvfg_osd_bitmap_t; +``` + +`text` 為 NUL 結尾的 1–32 字元可列印 ASCII;`font_family` 為 NUL 結尾的 UTF-8 +已安裝字型家族名稱。Set 返回前複製兩個字串。 +`font_size_px` 必須非零;`color_rgb` 為 `0x00RRGGBB`;`x/y` 是文字框左上角影像座標。 +字型清單由 SDK 管理,客戶不能修改或 free,使用期限見第 3.3 節。 +`gvfg_osd_bitmap_t` 的 `data` 由 SDK 擁有,`data_size` 為 `stride * height`,`stride` 為 `width * 4`; +有效期限見第 3.4 節。 + +### 3.2 `gvfg_measure_osd_text` + +```c +gvfg_status_t gvfg_measure_osd_text( + /* [in] */ const gvfg_channel_osd_config_t *config, + /* [out] */ uint32_t *out_width, + /* [out] */ uint32_t *out_height); +``` + +不需要 capture handle 或裝置;使用與繪製相同的文字、字型及大小,忽略位置及顏色。 +輸出為保守完整文字框,包含 overhang 與四邊各一 pixel 安全邊;失敗時輸出歸零。 +字型不存在或輸入無效時回傳 `GVFG_EINVAL`。 + +### 3.3 OSD 字型、設定、顯示/隱藏與清除 + +```c +gvfg_status_t gvfg_get_osd_fonts(/* [out] */ gvfg_osd_font_list_t *out_list); +gvfg_status_t gvfg_set_channel_osd( + gvfg_handle handle, int channel_index, uint32_t osd_index, + const gvfg_channel_osd_config_t *config); +gvfg_status_t gvfg_set_channel_osd_visible( + gvfg_handle handle, int channel_index, uint32_t osd_index, int visible); +gvfg_status_t gvfg_clear_channel_osd( + gvfg_handle handle, int channel_index, uint32_t osd_index); +``` + +| 項目 | 契約 | +|---|---| +| channel/組別 | Set、visibility、Clear 要求 channel 已 open;`osd_index` 為 0 或 1,重疊時 1 在上方 | +| `gvfg_get_osd_fonts()` | 不需要 handle;每次重新檢查 Windows 已安裝字型。成功時回傳 `count` 與 UTF-8 `names`,失敗時清單為空 | +| 清單所有權 | SDK 擁有陣列及字串,caller 不可修改或 free;有效到下一次清單查詢(含失敗呼叫)或 DLL 卸載。長期保存需自行複製;查詢及讀取須由 caller 序列化 | +| `gvfg_set_channel_osd()` | 設定並顯示一組,返回前複製文字與字型名稱,套用到後續 frame;失敗保留原設定 | +| 文字/字型 | `text` 為 NUL 結尾的 1–32 個 ASCII 0x20–0x7e;`font_family` 為 NUL 結尾的 UTF-8 已安裝家族名稱。不接受缺少的字型或無效 UTF-8 | +| 字級/顏色 | `font_size_px` 是非零 em 大小,不等於字形實際墨色高度;normal weight/style/stretch。`color_rgb` 為 0x00RRGGBB,輸出為 BT.709 limited range | +| 位置/尺寸 | `x/y` 為保守量測文字框左上角,會限制在影像內。框太大時只暫停該組;設定或影像尺寸改變後可恢復,不縮字、截字或換行 | +| `gvfg_set_channel_osd_visible()` | `visible` 只接受 0/1;隱藏保留設定,顯示不必重新 Set。顯示未設定或已清除的組別回傳 `GVFG_ESTATE` | +| `gvfg_clear_channel_osd()` | 停用並清除指定組別;之後須重新 Set,不影響另一組 | +| 設定生命週期 | `gvfg_destroy()` 後不保留設定;應用程式自行保存需要還原的內容 | + +- `GVFG_OK`:呼叫成功;不代表已交付的舊 frame 會改變。 +- `GVFG_EINVAL`:NULL pointer、無效字串/字型/字號/組別/visibility 等參數錯誤。 +- `GVFG_ESTATE`:channel 未 open,或要求顯示未設定的組別。 +- `GVFG_EIO`:量測、配置或其他處理失敗。 + +完整呼叫流程與程式範例見 +[使用手冊:OSD 呼叫範例](../GVFG_CUSTOMER_API.zh-TW.md#osd-呼叫範例)。 + +### 3.4 `gvfg_render_osd_frame_bgra` + +```c +gvfg_status_t gvfg_render_osd_frame_bgra( + /* [in] */ uint32_t video_width, + /* [in] */ uint32_t video_height, + /* [in] */ const gvfg_channel_osd_config_t *slot0, + /* [in] */ const gvfg_channel_osd_config_t *slot1, + /* [out] */ gvfg_osd_bitmap_t *out_bitmap); +``` + +產生一張與影像同尺寸、透明背景的 OSD 疊圖,供 FPGA 或其他元件自行疊合。 + +- 不需要 capture handle;`video_width`/`video_height` 是目標影像尺寸(pixel)。 +- 輸出為 top-down BGRA8888、premultiplied alpha,`stride = width * 4`,不含任何影像 pixel。 +- `slot0`/`slot1` 傳 NULL 表示該組不顯示;兩者皆 NULL 時輸出全透明。slot 1 疊在 slot 0 上方。 +- `x/y` 為影像座標並限制在影像內;文字框大於影像時略過該組。 +- 輸出資料有效到同一執行緒下一次呼叫此函式(含失敗)、執行緒結束或 DLL 卸載;非同步傳輸前須先複製。 +- `GVFG_EINVAL`:參數或尺寸無效(包含總 byte 數超過 `UINT32_MAX`)。 +- `GVFG_EIO`:配置或繪製失敗。失敗時輸出為空。 +- 此函式不影響通道上的 GPU OSD。 + +## 4. Playback 使用的影像型別 + +以下型別直接定義於 `gvfg_playback.h`,使用端不需額外的後端標頭。 +此標頭包含 Playback 的公開型別與操作函式;本節介紹影像型別,播放操作見第 5 節。 + +### 4.1 Preview 型別 + +本節說明 Playback 使用的資料型別;操作函式與錯誤碼見第 5 節。 + +`gvfg_preview_pixel_format_t`: + +| 成員 | 值 | 說明 | +| ---------------------------- | ---:| ---------------------------------------------- | +| `GVFG_PREVIEW_PIXFMT_YUY2` | 1 | Packed 8-bit YUV 4:2:2,Y0 U0 Y1 V0;Capture 格式應明確對應 | +| `GVFG_PREVIEW_PIXFMT_Y210` | 2 | Packed 10-bit YUV 4:2:2,16-bit containers | +| `GVFG_PREVIEW_PIXFMT_GRAY16` | 4 | 每 pixel 一個 16-bit unsigned grayscale component | +| `GVFG_PREVIEW_PIXFMT_RGBA16` | 5 | 每 pixel 四個 16-bit UNORM component:R、G、B、A | +| `GVFG_PREVIEW_PIXFMT_DICOM_YBR_FULL_422` | 6 | 每 pixel pair 四個 16-bit words:Y0、Y1、Cb、Cr,數值依 bit_depth 靠右對齊 | + +`gvfg_preview_frame_t`: + +| 欄位 | 說明 | +| ------------------ | ------------------------------------------------------ | +| `data`、`data_size` | Caller-owned frame pointer 與 byte 數 | +| `width`、`height` | Frame pixel 尺寸 | +| `pixel_format` | `gvfg_preview_pixel_format_t` | +| `bit_depth` | Frame bit depth | +| `row_bytes` | Source row stride,通常對應 `gvfg_frame_t.row_stride_bytes` | +| `frame_id` | Frame 識別值,通常對應 `gvfg_frame_t.frame_id` | + +`gvfg_preview_info_t`: + +| 欄位 | 說明 | +| ---------------------------- | ------------------------------ | +| `active` | 非 0 表示 preview pipeline 已啟用 | +| `width`、`height`、`bit_depth` | 最近使用的 frame 資訊 | +| `pixel_format[32]` | Null-terminated 格式名稱 | +| `adapter_name[160]` | Null-terminated D3D adapter 名稱 | +| `adapter_index` | 使用的 adapter 索引 | + +`gvfg_preview_stats_t`: + +| 欄位 | 說明 | +| ------------------ | ------------------------------------ | +| `present_fps` | 最近五秒成功 Present 的速率 | +| `presented_frames` | 成功 Present 的累積 frame 數 | +| `skipped_presents` | 預覽端略過呈現的累積數;不是 Capture 或錄影掉格總數 | + +## 5. 統一 Playback API + +公開標頭為 `gvfg_playback.h`,連結 `gvfg_playback.lib`、部署 `gvfg_playback.dll`。 +MinGW 使用 `libgvfg_playback.dll.a`。 + +`gvfg_playback` 是 opaque handle。`config.struct_size` 須設為 config 結構大小; +可先呼叫 `gvfg_playback_default_config()` 填好預設值。 +音訊格式 `gvfg_audio_playback_format_t` 包含 sample_rate、channels、bits_per_sample, +目前支援 signed interleaved PCM16。 + +| 函式 | 行為 | +|---|---| +| `gvfg_playback_default_config(config)` | 預設影音模式、External master、100 ms preroll、48 kHz stereo PCM16 | +| `gvfg_playback_create(out)` | 建立 handle,不啟動輸出 | +| `gvfg_playback_attach_window(p, hwnd)` | 設定 HWND;NULL 表示無畫面輸出但仍消耗影像時間軸 | +| `gvfg_playback_start(p, config)` | 啟動選定的純影像、純音訊或影音模式 | +| `gvfg_playback_submit_video(p, frame)` | 複製影像與 timestamp,排入共用播放佇列 | +| `gvfg_playback_submit_audio(p, pcm, bytes, timestamp_ns)` | 複製 PCM,以 SDK 交付時間建立來源 sample 時間軸 | +| `gvfg_playback_present_image(p, image)` | 停止狀態、已綁定 HWND 時同步顯示單張影像,不需 start 或 PTS;未實際 Present 時回傳 EOUTPUT | +| `gvfg_playback_enable_audio_reconnect(p)` | start 前選用;影音模式音訊輸出失效後,自動重試 Windows 預設輸出裝置 | +| `gvfg_playback_set_volume(p, gain)` | PCM16 軟體音量,範圍 0.0 到 2.0 | +| `gvfg_playback_set_sync_enabled(p, enabled)` | 0 為各自播放且不自動恢復同步;1 為啟用同步,預設 1 | +| `gvfg_playback_reset_timeline(p)` | 丟棄待播資料,使用原設定重新建立時間軸 | +| `gvfg_playback_stop(p)` | 停止播放並丟棄待播資料,可重複呼叫 | +| `gvfg_playback_destroy(p)` | 停止並銷毀,NULL 可安全忽略 | +| `gvfg_playback_get_preview_info(p, info)` | 影像輸出資訊 | +| `gvfg_playback_get_preview_stats(p, stats)` | GPU/呈現統計 | +| `gvfg_playback_set_signal_connected(p, connected)` | UI 執行緒轉交訊號狀態:0 顯示 helper 內建 NO SIGNAL 圖卡,1 隱藏 | +| `gvfg_playback_strerror(status)` | 靜態英文錯誤字串,不可 free | + +狀態碼為 OK、EINVAL、ESTATE、EOUTPUT、EQUEUE_FULL、EDISCONTINUITY、EAUDIO; +queue 壓力會自動降級並略過過期資料,不要求 caller 因此停止擷取。 +預覽可能略過過時影格;成功提交不保證每張影像都實際顯示。 +音訊及獨立錄影不受此預覽策略影響。 +submit 返回後 caller 可立即釋放 SDK frame;present_image 則須保留資料到函式返回。 +控制操作(含 present_image)須由 caller 序列化;可由獨立影音 producer 併行 submit。 +stop/reset 是取消,不是無損 EOS drain。 + +完整使用流程與可編譯的提交範例見 +[統一影音播放使用手冊](../GVFG_PLAYBACK_API.zh-TW.md)。 + +### 5.1 `gvfg_playback_config_t` + +先呼叫 `gvfg_playback_default_config(&config)`,不需要自行填 struct_size。 +start 會複製設定;只接受停止狀態的 handle,不會代替 caller 停掉既有播放。 +一般使用者保留 `max_video_frames`、`max_audio_ms`、`max_video_bytes` 的預設值即可;這三項是進階容量上限,僅在有明確記憶體或待播容量需求時調整,不代表固定播放延遲。 + +| 欄位 | 預設值 | 限制與語意 | +|---|---|---| +| `struct_size` | `sizeof(gvfg_playback_config_t)` | 必須等於目前完整結構大小 | +| `mode` | `GVFG_PLAYBACK_AUDIO_VIDEO` | Video-only=1、Audio-only=2、Audio-video=3 | +| `master` | `GVFG_PLAYBACK_MASTER_EXTERNAL` | External=0、Audio=1、Video=2;純影像強制 External,純音訊強制 Audio | +| `audio_format.sample_rate` | 48000 | 啟用音訊時為 1~384000 Hz;通過參數檢查不代表 Windows 裝置一定支援 | +| `audio_format.channels` | 2 | 啟用音訊時為 1~32 | +| `audio_format.bits_per_sample` | 16 | 啟用音訊時必須為 16,signed interleaved PCM | +| `preroll_ms` | 100 | 1~1000 ms;啟用串流需要的初始/重新緩衝覆蓋範圍 | +| `max_video_frames` | 32 | 1~600,待播影像張數上限;純音訊仍須填合法值 | +| `max_audio_ms` | 1000 | 不小於 preroll_ms,且不超過 10000;包括共用 queue 與輸出端待播量 | +| `max_video_bytes` | 256 MiB | 必須大於 0;包括待播與正在處理的影像 | + +External/Audio master 的預覽允許過期退休與 GPU-busy 略過,不是逐幀無損輸出。 +Video master 不啟用自動過期退休;有限緩衝也不保證在輸出速度不足時永久接收所有 frame。 +選擇模式不會改變 Capture SDK 的啟用設定;Capture 的 audio enable 仍由 caller 管理。 + +### 5.2 `gvfg_playback_video_frame_t` + +| 欄位 | 意義 | +|---|---| +| `image` | `gvfg_preview_frame_t`;資料指標、可用 bytes、尺寸、格式、有效 bit depth、row stride、frame ID | +| `timestamp_ns` | 來源共同單調時間軸的交付奈秒值;非 0、各路嚴格遞增、不超過 INT64_MAX | + +image 支援 YUY2、Y210、GRAY16、RGBA16、DICOM YBR_FULL_422,以 +`GVFG_PREVIEW_PIXFMT_*` 指定。Capture 的 `GVFG_PIXFMT_*` 必須明確對應,不能直接複製 enum 整數。 +`data_size` 至少覆蓋 `row_bytes * height`;row_bytes 須足夠容納一列指定格式: + +| 格式 | `row_bytes` 下限 | +|---|---| +| YUY2 | `((width + 1) / 2) * 4`;奇數寬度也須容納完整的 4-byte macropixel | +| Y210 | `width * 4` | +| GRAY16 | `width * 2` | +| RGBA16 | `width * 8` | +| DICOM YBR_FULL_422 | `((width + 1) / 2) * 8` | + +submit 會複製實際影像列範圍,frame ID 僅作身分/統計資訊,不用來計算 PTS。 +影像各欄位與格式 layout 詳見第 4 節。 + +### 5.3 `gvfg_playback_submit_audio()` 的輸入 + +| 參數 | 契約 | +|---|---| +| `p` | 已 start 且啟用音訊的 handle | +| `pcm` | 非 NULL 的 signed interleaved PCM16,返回前保持有效 | +| `bytes` | 大於 0,對齊 channels × 2,每包最多 100 ms | +| `timestamp_ns` | 同一來源時鐘域的 SDK delivery time;須大於包長、非 0、嚴格遞增且不超過 INT64_MAX | + +第一包來源起點估為 timestamp 減去包長;後續維持連續的 sample 時間軸, +平滑追蹤與交付時鐘的長期偏差。相鄰 delivery timestamp 的間隔若超過 250 ms 加上本包包長, +會進入獨立播放並建立新的音訊映射;不會因此停止擷取。重複或倒退的時間仍會回報 EDISCONTINUITY。 +這些規則不會提供硬體擷取時間、漏 sample 數或絕對聲學延遲。 + +### 5.4 狀態碼 + +| 值 | 名稱 | caller 處理 | +|---:|---|---| +| 0 | `GVFG_PLAYBACK_OK` | 操作成功;submit 成功表示接受,不表示已呈現 | +| -1 | `GVFG_PLAYBACK_EINVAL` | 修正 NULL、格式、尺寸、對齊、struct_size 或 config 範圍 | +| -2 | `GVFG_PLAYBACK_ESTATE` | 檢查是否 start、模式是否啟用該路、單張操作是否在停止且已綁窗狀態 | +| -3 | `GVFG_PLAYBACK_EOUTPUT` | 檢查 WASAPI/GPU/視窗/記憶體及重啟流程;不能假設會自動恢復 | +| -4 | `GVFG_PLAYBACK_EQUEUE_FULL` | 保留值,目前 API 不回傳;queue 壓力由核心自動處理,單筆資料超出容量回傳 EINVAL | +| -5 | `GVFG_PLAYBACK_EDISCONTINUITY` | 協調 producer,重設時間軸;新音訊格式須以新 config stop/start | +| -6 | `GVFG_PLAYBACK_EAUDIO` | 影音模式的監聽音效已因輸出故障停用,影像繼續;提示一次,繼續獨立擷取/錄影。已啟用 audio reconnect 時繼續提交 PCM 等待恢復;否則重建 handle 才重試音效 | + +影音模式的音訊輸出故障由音訊 submit 回傳 `EAUDIO`, +影像 submit 繼續。影音 start 遇到音效開啟失敗仍可成功,音訊 submit 會回報 `EAUDIO`。 +未啟用 audio reconnect 時,停用狀態跨 stop/start/reset 保留,重建 handle 才重試音效。 +start 前呼叫 `gvfg_playback_enable_audio_reconnect()` 後,影音模式約每秒重試一次 Windows 預設輸出裝置; +應用程式持續提交新的 PCM,輸出恢復後音訊 submit 會再回傳 OK。純音訊模式不重試,仍視為輸出失敗。 +其他非同步輸出錯誤會由後續 submit 回報。start 成功不保證後續輸出一定正常。 + +### 5.5 控制 API 的細節 + +`gvfg_playback_set_sync_enabled(p, enabled)` 接受 0 或 1,其他值/NULL handle 回傳 EINVAL。 +可在 start 前或運行中呼叫;0 立即使用獨立播放且不自動恢復同步,1 在條件穩定後恢復同步。 +設定保留到 stop/start、reset_timeline;重新 create 的 handle 預設為 1。 + +| API | 狀態、ownership 與限制 | +|---|---| +| `default_config(config)` | NULL 時不操作;其餘填完整預設值與 struct_size | +| `create(out)` | out 不可 NULL;成功後 caller 擁有 handle,失敗時 out 為 NULL | +| `attach_window(p, hwnd)` | 綁定 HWND;NULL 隱藏輸出但保留模式與影像時間軸;不自動 start | +| `start(p, config)` | 必須為停止狀態;重設計數、queue、時鐘,沿用已設定音量與視窗 | +| `submit_video(p, frame)` | 已 start 且啟用影像;返回後無論成功與否,都必須結束 caller 自己的 Capture frame ownership | +| `submit_audio(p, pcm, bytes, ts)` | 已 start 且啟用音訊;成功返回前完成複製 | +| `present_image(p, image)` | 停止狀態且有 HWND,否則 ESTATE;同步等待工作完成,資料須有效到返回。影像未被 DXGI Present 接受(例如 GPU busy 或逾時)時回傳 EOUTPUT;OK 表示已 Present,不代表實體 scanout 完成 | +| `enable_audio_reconnect(p)` | 只能在 start 前呼叫,執行中回傳 ESTATE;只影響影音模式,設定隨 handle 保留 | +| `set_volume(p, gain)` | finite 0.0~2.0;可先設定再 start,0 是靜音而不是停音訊 | +| `reset_timeline(p)` | 取消舊待播資料並重設時間軸;保留 config,若原本在播放則恢復播放。須檢查回傳值 | +| `stop(p)` | 停止播放並取消待播資料;可重複呼叫 | +| `destroy(p)` | NULL 安全;停止播放並釋放 handle | +| `get_preview_info(p, info)` | 回傳影像資訊;尚未建立 Preview 時為零值 | +| `get_preview_stats(p, stats)` | 回傳呈現 FPS/計數;尚未建立 Preview 時為零值 | +| `set_signal_connected(p, connected)` | 僅接受 0/1,預設 1。0 顯示 helper 內建圖卡、1 隱藏。可在 attach 前設定,跨 stop/start/reset/reattach 保留;與 attach/destroy 在 HWND 執行緒序列化。圖卡隨視窗縮放,detach/destroy 釋放。此 API 不查詢 Capture、不更動影格或同步、不依 FPS 判斷訊號 | +| `strerror(status)` | 靜態字串,不可 free;未知值回傳 unknown error 文字 | + +函式完整名稱皆為 `gvfg_playback_` 加上表中名稱。getters 的輸出指標不可 NULL。 +控制操作含 present_image,須由 caller 序列化;一個影像與一個音訊 producer 可併行 submit。 +Playback 不控制 Capture handle,亦不接管它的 read/release 或 channel lifecycle。 diff --git a/docs/GVFG_ERROR_HANDLING.md b/docs/GVFG_ERROR_HANDLING.md index 931e9c1..67e40fa 100644 --- a/docs/GVFG_ERROR_HANDLING.md +++ b/docs/GVFG_ERROR_HANDLING.md @@ -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)。 diff --git a/docs/GVFG_FRAME_FLOW_AND_STATE.md b/docs/GVFG_FRAME_FLOW_AND_STATE.md index ebd4d2d..25a830b 100644 --- a/docs/GVFG_FRAME_FLOW_AND_STATE.md +++ b/docs/GVFG_FRAME_FLOW_AND_STATE.md @@ -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. 計數與完整性 diff --git a/docs/GVFG_INTERNAL_NOTES.md b/docs/GVFG_INTERNAL_NOTES.md index 649400e..3845ef1 100644 --- a/docs/GVFG_INTERNAL_NOTES.md +++ b/docs/GVFG_INTERNAL_NOTES.md @@ -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. 已知限制與發佈檢查表 diff --git a/docs/GVFG_LEARNING_INDEX.md b/docs/GVFG_LEARNING_INDEX.md index b19be07..b5c92ea 100644 --- a/docs/GVFG_LEARNING_INDEX.md +++ b/docs/GVFG_LEARNING_INDEX.md @@ -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` | diff --git a/docs/GVFG_Overview.md b/docs/GVFG_Overview.md index 5620ec3..06b5074 100644 --- a/docs/GVFG_Overview.md +++ b/docs/GVFG_Overview.md @@ -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 | 不另外部署 | diff --git a/docs/GVFG_PLAYBACK_API.md b/docs/GVFG_PLAYBACK_API.md index 2a49a30..8ab50a9 100644 --- a/docs/GVFG_PLAYBACK_API.md +++ b/docs/GVFG_PLAYBACK_API.md @@ -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). diff --git a/docs/GVFG_PLAYBACK_API.zh-TW.md b/docs/GVFG_PLAYBACK_API.zh-TW.md new file mode 100644 index 0000000..3f4c43c --- /dev/null +++ b/docs/GVFG_PLAYBACK_API.zh-TW.md @@ -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(format.channels), + static_cast(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)。 diff --git a/docs/INTERNAL_BUILD_GUIDE.md b/docs/INTERNAL_BUILD_GUIDE.md index 1799ca3..9c73831 100644 --- a/docs/INTERNAL_BUILD_GUIDE.md +++ b/docs/INTERNAL_BUILD_GUIDE.md @@ -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 打包: