feat: align GVFG output with YUY2

- expose YUY2 across the public API, preview helper, backend, and GPU conversion paths while translating the legacy FPGA format value internally
- correct YUY2 chroma byte interpretation and update customer/internal documentation
- centralize the Standalone SDK version and expose it through gvfg_get_version
- show the SDK version in the sample and enable preview-window controls only after the first valid frame
- close and disable external preview windows when capture stops
This commit is contained in:
Mark.lin
2026-08-13 16:14:16 +08:00
parent a5b86e5872
commit 17fb9bfabd
20 changed files with 302 additions and 63 deletions
+4 -1
View File
@@ -115,6 +115,9 @@ int main(void)
| `GVFG_ETIMEOUT` | 等待逾時 |
可用 `gvfg_strerror()` 取得靜態英文說明字串;呼叫端不可釋放該字串。
可用 `gvfg_get_version()` 查詢目前實際載入的 `gvfg.dll` 版本。回傳值為
靜態字串,例如 `"0.1.0"`,呼叫端不可釋放。
需要記錄最近一次失敗的詳細原因時,可在 API 失敗後立即呼叫
`gvfg_get_last_error_detail()`;driver/register 等內部診斷仍保留在 debug API。
@@ -124,7 +127,7 @@ int main(void)
| 格式 | `pixel_format` | bit depth | 每列大小 |
| ----------------- | ------------------:| ---------:| -----------:|
| YVYU packed 4:2:2 | `GVFG_PIXFMT_YVYU` | 8 | `width * 2` |
| 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` 為準。
+18 -8
View File
@@ -39,7 +39,7 @@ register 與 DMA 實作不屬於本文件。
| --------------------- | ---:| ----------------------------------------- |
| `GVFG_PIXFMT_UNKNOWN` | 0 | 未知或尚無有效訊號格式 |
| `GVFG_PIXFMT_Y210` | 2 | 10-bit packed YUV 4:2:2;目前每 pixel 4 bytes |
| `GVFG_PIXFMT_YVYU` | 3 | 8-bit packed YUV 4:2:2;目前每 pixel 2 bytes |
| `GVFG_PIXFMT_YUY2` | 3 | 8-bit packed YUV 4:2:2;byte order Y0 U0 Y1 V0,每 pixel 2 bytes |
### 1.4 `gvfg_channel_t`
@@ -241,7 +241,7 @@ gvfg_status_t gvfg_gpu_convert_to_buffer(
const gvfg_gpu_output_buffer_t *output);
```
- `source`:有效的 YVYU/Y210 frame;若來自 read,必須尚未 release。
- `source`:有效的 YUY2/Y210 frame;若來自 read,必須尚未 release。
- `output`:caller 填好的 destination descriptor。
- `GVFG_OK`:同步轉換及 copy 完成。
- `GVFG_EINVAL`:NULL、尺寸、stride、buffer size、奇偶尺寸或 overflow 錯誤。
@@ -258,7 +258,7 @@ gvfg_status_t gvfg_gpu_convert_to_bgra8(
int row_bytes);
```
- `source`:有效且尚未 release 的 YVYU/Y210 frame。
- `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`。
@@ -287,7 +287,7 @@ gvfg_status_t gvfg_gpu_convert_to_nv12(
int row_bytes);
```
- `source`:有效且尚未 release 的 YVYU/Y210 frame;width、height 必須為偶數。
- `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`。
@@ -350,16 +350,26 @@ gvfg_status_t gvfg_get_runtime_info(
- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。
- `GVFG_ESTATE`:handle 尚無已開啟的 backend 裝置。
### 1.28 `gvfg_pixel_format_name`
### 1.28 `gvfg_get_version`
```c
const char *gvfg_get_version(void);
```
- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"0.1.0"`。
- 回傳值是靜態 null-terminated 字串,caller 不可 free。
- 可用於 log、問題回報,以及確認 header、LIB、DLL 是否來自同一版本。
### 1.29 `gvfg_pixel_format_name`
```c
const char *gvfg_pixel_format_name(int pixel_format);
```
- `pixel_format`:`gvfg_pixel_format_t` 或其他整數值。
- 回傳:靜態英文字串 `"YVYU"`、`"Y210"` 或 `"UNKNOWN"`。Caller 不可 free。
- 回傳:靜態英文字串 `"YUY2"`、`"Y210"` 或 `"UNKNOWN"`。Caller 不可 free。
### 1.29 `gvfg_strerror`
### 1.30 `gvfg_strerror`
```c
const char *gvfg_strerror(gvfg_status_t status);
@@ -401,7 +411,7 @@ gvfg_status_t gvfg_get_last_error_detail(gvfg_handle handle,
`gvfg_preview_handle` 是 opaque pointer,只能由 preview create/destroy 管理。
`gvfg_preview_pixel_format_t` 包含 `GVFG_PREVIEW_PIXFMT_Y210` 與
`GVFG_PREVIEW_PIXFMT_YVYU`,值與對應 core pixel format 相同。
`GVFG_PREVIEW_PIXFMT_YUY2`,值與對應 core pixel format 相同。
`gvfg_preview_frame_t`:
+4 -4
View File
@@ -39,7 +39,7 @@ customer/sample (optional)
- `pcies2mm_device.*`:SetupAPI 裝置列舉與 interface path。
- `pcies2mm_ioctl.h`:與 driver 共用的 private ABI。
- `pcies2mm_reg.h`:FPGA register offsets/masks。
- `pcies2mm_video_format.*`:format register 解碼與 YVYU/Y210 layout。
- `pcies2mm_video_format.*`:format register 解碼與 YUY2/Y210 layout;相容舊 FPGA 回報的 YVYU register 值。
- `src/gpu/*`:D3D11 同步轉換及 readback 到 caller buffer。
## 3. 公開 facade 狀態
@@ -105,7 +105,7 @@ x64 `gvfg_frame_t` ABI 已在 `gvfg_capture.cpp` 以 static assertions 固定為
目前原生格式:
- YVYU:2 bytes/pixel,8-bit packed 4:2:2。
- YUY2:2 bytes/pixel,8-bit packed 4:2:2,byte order 為 Y0 U0 Y1 V0。
- Y210:4 bytes/pixel,10-bit packed 4:2:2。
目前皆為 single-plane。加入 multi-plane 格式前,必須先設計 plane count、offset、
@@ -148,7 +148,7 @@ stream 狀態,且不得將 register API 包裝成客戶功能。
## 8. GPU conversion
公開 GPU conversion 是同步的:建立 D3D pipeline、轉換/readback 到 caller-owned
buffer,返回後不保留指標。輸入只接受目前公開的 YVYU/Y210;輸出為 BGRA8、
buffer,返回後不保留指標。輸入只接受目前公開的 YUY2/Y210;輸出為 BGRA8、
RGB10A2 或 BT.709 limited-range NV12。
維護時必測:
@@ -171,7 +171,7 @@ internal debug header,但客戶 sample/package 不應包含 internal diagnosti
## 10. 已知限制與發佈檢查表
目前設計限制:Windows only、每 handle 單一 channel、每 handle 最多一個 held
frame、原生格式限 YVYU/Y210、event queue 非持久化且可能淘汰最舊事件。
frame、原生格式限 YUY2/Y210、event queue 非持久化且可能淘汰最舊事件。
每次發佈前確認:
+182
View File
@@ -0,0 +1,182 @@
# GVFG Standalone 內部建置與功能說明
本文件供內部開發使用,說明 `GVFG_Standalone` 的用途、CMake 設定、Debug 診斷功能、輸出檔案,以及如何提供 `qt6/srcroot` 使用。
## 1. 專案定位
`GVFG_Standalone` 是 GVFG 擷取功能的 source of truth,包含:
- `sdk/gvfg`:GVFG 公開 C API、PCIe S2MM backend、GPU conversion。
- `helpers/gvfg_preview`:獨立的 D3D preview helper。
- `samples/gvfg_qt_preview`:直接使用 GVFG API 的 Qt 測試程式。
- `docs`:客戶 API、內部架構及建置文件。
`qt6/srcroot` 不會重新編譯這裡的 source,而是透過 header、LIB 與 DLL 匯入已建置完成的 Standalone SDK。
## 2. 必要環境
- Windows x64。
- Visual Studio 2022 MSVC Build Tools。
- CMake 3.16 以上。
- Qt 6 MSVC x64;只有建置 `gvfg_qt_preview` sample 時需要 Qt。
建議先進入 Visual Studio Developer Command Prompt,避免 `cl.exe` 找不到標準函式庫,或系統同時存在 `Path` 與 `PATH` 時造成 MSBuild 錯誤。
## 3. CMake 選項
| 變數 | 類型/預設 | 功能 |
|---|---|---|
| `BUILD_GVFG_SAMPLES` | BOOL/`ON` | 是否建置 `gvfg_qt_preview.exe`。SDK 與 preview DLL 不受此選項影響。 |
| `CMAKE_PREFIX_PATH` | PATH | Qt MSVC kit 的根目錄,例如 `C:\Qt\6.10.2\msvc2022_64`。 |
`GVFG_INTERNAL_DIAGNOSTICS` 不是給使用者手動設定的 cache option。CMake 會依 configuration 自動決定:
- Debug:`GVFG_INTERNAL_DIAGNOSTICS=1`
- Release:`GVFG_INTERNAL_DIAGNOSTICS=0`
這個設定會同時套用到 `gvfg.dll`、`gvfg_preview.dll` 與 `gvfg_qt_preview.exe`。
## 4. 更新 SDK 版本
版本只有一個來源:根目錄 `CMakeLists.txt` 的 `project()`:
```cmake
project(gvfg_standalone VERSION 0.1.0 LANGUAGES CXX)
```
例如準備 `0.2.0` 時改成:
```cmake
project(gvfg_standalone VERSION 0.2.0 LANGUAGES CXX)
```
`sdk/gvfg` 會直接繼承根 project version,並將它編入 `gvfg.dll`。不再存在 `GVFG_SDK_VERSION` cache option,也不應使用 `-DGVFG_SDK_VERSION=...` 覆寫。修改版本後要重新 configure,再重新建置 DLL。
程式可用下列公開 API 查詢實際載入的 DLL 版本:
```c
const char *version = gvfg_get_version();
```
`qt6_viewer` 啟動時也會把這個 runtime 版本寫入 log,便於發現 header、LIB、DLL 混用舊版本的問題。
## 5. 建置方式
### 5.1 Release:一般整合與效能測試
```bat
cmake -S . -B build_release ^
-DBUILD_GVFG_SAMPLES=ON ^
-DCMAKE_PREFIX_PATH=C:\Qt\6.10.2\msvc2022_64
cmake --build build_release --config Release --target gvfg_qt_preview
```
若只需要 SDK,不需要 Qt sample:
```bat
cmake -S . -B build_sdk ^
-DBUILD_GVFG_SAMPLES=OFF
cmake --build build_sdk --config Release --target gvfg gvfg_preview
```
### 5.2 Debug:內部診斷
```bat
cmake -S . -B build_debug ^
-DBUILD_GVFG_SAMPLES=ON ^
-DCMAKE_PREFIX_PATH=C:\Qt\6.10.2\msvc2022_64
cmake --build build_debug --config Debug --target gvfg_qt_preview
```
Debug 版本會增加:
- backend/DMA/IRQ 統計資訊。
- preview submit、render、Present 慢幀診斷。
- frame loss 與 held-frame 診斷。
- 詳細 backend error。
- `gvfg_qt_preview` 的 diagnostic status 與 snapshot log。
Debug 診斷會增加 log 與檢查成本,不應拿來判斷正式版本效能。
## 6. 輸出檔案
輸出位置由 CMake 統一設定:
```text
<build>/bin/gvfg.dll
<build>/bin/gvfg_preview.dll
<build>/bin/gvfg_qt_preview.exe
<build>/lib/gvfg.lib
<build>/lib/gvfg_preview.lib
```
不同 generator 的 configuration 可能位於 `bin/Release`、`lib/Release`,或 Qt Creator 自己建立的 configuration build 目錄。整合到 `srcroot` 時,`GVFG_STANDALONE_BUILD_DIR` 必須指向實際包含 `bin` 與 `lib` 的那一層。
## 7. 主要功能
### `gvfg.dll`
- 列舉裝置、開啟 channel、開始與停止擷取。
- 取得原生 YUY2 8-bit 或 Y210 10-bit frame。
- 使用 `gvfg_get_version()` 查詢實際載入的 runtime DLL 版本。
- signal status、runtime FPS、frame loss event。
- GPU conversion:BGRA8、RGB10A2、NV12。
- 內部 debug API:backend stats、last error、register read/write。
目前 FPGA 的 8-bit format register 仍可能回報舊 `YVYU` 值;SDK 只把它當作 legacy register identifier,對外格式與實際 DMA layout一律是 YUY2(`Y0 U0 Y1 V0`)。
### `gvfg_preview.dll`
- 將 YUY2/Y210 frame 顯示到指定 HWND。
- 自動依來源 bit depth 選擇 preview pipeline。
- preview worker 與 capture frame delivery 分離;preview 落後時可淘汰舊 preview frame,不阻塞擷取交付。
### `gvfg_qt_preview.exe`
- 最小化的 GVFG 整合範例。
- 視窗標題與啟動 log 顯示 `gvfg_get_version()` 回傳的實際 DLL 版本。
- 裝置/channel 選擇、start/stop、preview window。
- 顯示輸入格式、bit depth、capture FPS、preview FPS 與 loss。
- Debug build 顯示額外 backend diagnostics。
## 8. 提供給 srcroot 使用
建置 Standalone 後,在 `qt6/srcroot` configure 時指定:
```bat
-DBUILD_GVFG_SDK=ON
-DGVFG_STANDALONE_ROOT=C:\Users\mark\Desktop\GcaptureSDK\GVFG_Standalone
-DGVFG_STANDALONE_BUILD_DIR=C:\path\to\standalone-build
```
`GVFG_STANDALONE_BUILD_DIR` 應包含:
```text
bin/gvfg.dll
bin/gvfg_preview.dll
lib/gvfg.lib
lib/gvfg_preview.lib
```
修改公開 enum、struct 或函式後,必須先重建 Standalone,再重新 configure/build `srcroot`,否則 header、LIB、DLL 可能版本不一致。
## 9. 常見問題
### `GVFG_PIXFMT_*` 未宣告
上層正在使用舊 enum,或 include 到另一份舊 header。確認 include path 指向本專案的 `sdk/gvfg/include`,並同步修改上層。
### `Path`/`PATH` duplicate key
這是啟動 Codex/PowerShell 環境時同時存在兩種大小寫造成的 MSBuild 問題。改從 Visual Studio Developer Command Prompt 建置,或清理重複環境變數。
### 找不到 `type_traits` 或 `utility`
表示 MSVC developer environment 尚未載入。先執行 `VsDevCmd.bat -arch=x64`,再呼叫 CMake build。
### DLL 更新但 viewer 行為仍舊
確認 viewer 執行目錄的 DLL timestamp,並關閉正在執行的 viewer 後重新建置。Windows 會鎖住使用中的 EXE/DLL。