Files
GVFG_Standalone/README.md
T
Mark.lin a04bd611f9 Simplify the SDK around GigabyteLib
Compared with 0af70a5:

- Remove the generic backend directory and legacy PCIE S2MM naming so the SDK now has a direct gvfg facade to GigabyteCaptureSession to GvfgSdk.lib structure.

- Delete the unsupported video-format setter and direct register read/write APIs instead of retaining compatibility methods that cannot be implemented by the supplied GigabyteLib interface.

- Remove output-format controls and requested-format state from the Qt sample; capture now follows the native YUY2 or Y210 format reported by GvfgGetVideoInfo.

- Eliminate the placeholder stream descriptor and allocate copy buffers from current GigabyteLib video metadata when a frame becomes available.

- Rename the internal debug stats API and fields from backend terminology to channel/session terminology, while retaining capture, audio, event, timeout, timing, and zero-copy diagnostics.

- Update source paths and documentation to describe GigabyteLib as the only lower layer and remove stale format-setting, register, and direct IOCTL guidance.

Validation: git diff --cached --check passed. MSVC x64 Release and Debug gvfg.dll builds passed, the Release Qt sample rebuilt and linked successfully, dumpbin verified the intentional 29-export API, and the Release package script produced an archive containing the sample and gvfg.dll without private GigabyteLib files or giga_ioctl.dll. No runtime capture, audio, zero-copy, hot-plug, dual-channel, shutdown, MinGW, or hardware validation was run.
2026-09-14 10:05:54 +08:00

205 lines
8.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# GVFG Standalone SDK
這個 repository 將 GVFG SDK 與 Qt Sample 分成兩個獨立 CMake project。
這個 repo 以 GVFG 為 source of truth。其他專案應該透過 public header、
import library、runtime DLL 來使用 GVFG,不要直接把 GVFG source 編進去。
## Driver compatibility
此開發版本僅支援新 driver `vfg100_0821c`。舊版 driver、舊 IOCTL、
done-index 與舊 SDK frame-ring 流程不在相容範圍內。
## 內容
- `GVFG_SDK`:獨立 SDK project,使用內嵌的 `GvfgSdk.lib` 建立 `gvfg.dll` 與選用的 `gvfg_preview.dll`。
- `GVFG_Qt_Sample`:獨立 Qt APP project,只連結預先建好的 SDK,不會編譯 SDK source。
- `docs`:API 與整合說明。
Qt Sample 的 source boundary:
- `mainwindow.cpp`:Widget 建立、signal/slot、畫面狀態與使用者操作。
- `capture_controller.cpp/.h`:不依賴 UI widget 的裝置/channel lifecycle、video/audio worker、preview submission、狀態與 log 資料流。
- `capture_controller.cpp/.h` 直接示範公開的 GVFG C API,並明確管理 `gvfg_create()`/停止流程/`gvfg_destroy()`,不建立重複轉呼叫層。
客戶使用指南在 `docs/GVFG_CUSTOMER_API.md`,完整函式與結構參考在
`docs/GVFG_CUSTOMER_API_REFERENCE.md`。內部架構、package
切分、threading、frame ownership 說明在 `docs/GVFG_INTERNAL_NOTES.md`。
## Build
先使用 MSVC 建立 SDK,再使用需要的 Qt kit 建立 Sample。兩個 project
使用不同 build directory,切換 Qt compiler 不會重新編譯 SDK source。
SDK build 會保留 MSVC `.lib`,並在找到 MinGW `dlltool` 時從固定的
DLL export 清單同步產生 MinGW `.dll.a`;兩種上層共用同一組 MSVC DLL。
範例:
```bat
cmake -S GVFG_SDK -B GVFG_SDK/build/Desktop_Qt_6_10_2_MSVC2022_64bit-Release
cmake --build GVFG_SDK/build/Desktop_Qt_6_10_2_MSVC2022_64bit-Release --config Release
cmake -S GVFG_Qt_Sample -B GVFG_Qt_Sample/build-release ^
-DCMAKE_PREFIX_PATH=C:\Qt\6.10.2\msvc2022_64 ^
-DGVFG_SDK_RELEASE_DIR=%CD%\GVFG_SDK\build\Desktop_Qt_6_10_2_MSVC2022_64bit-Release
cmake --build GVFG_Qt_Sample/build-release --config Release
```
Qt Sample 只從一個固定的 `GVFG_SDK_RELEASE_DIR` 找 DLL 與對應 compiler
的 import library,不再依 Sample configuration 搜尋不同 SDK build。
它不會使用 `add_subdirectory()` 將 SDK source 編入 APP。
```text
GVFG_SDK_ROOT=<path-to-GVFG_SDK>
GVFG_SDK_RELEASE_DIR=<path-to-one-Release-SDK-build>
```
目前內部開發也統一使用上述 Release 流程,不另外維護 SDK/Sample 的
Debug 配對。內部 header、診斷程式碼與 source 仍保留在 repository;等正式
發布客戶套件時,再整理實際交付的 public header、LIB、DLL 與文件。
Build 產物:
```text
GVFG_SDK/build/Desktop_Qt_6_10_2_MSVC2022_64bit-Release/bin/gvfg.dll
GVFG_SDK/build/Desktop_Qt_6_10_2_MSVC2022_64bit-Release/bin/gvfg_preview.dll
GVFG_SDK/build/Desktop_Qt_6_10_2_MSVC2022_64bit-Release/lib/gvfg.lib
GVFG_SDK/build/Desktop_Qt_6_10_2_MSVC2022_64bit-Release/lib/gvfg_preview.lib
GVFG_SDK/build/Desktop_Qt_6_10_2_MSVC2022_64bit-Release/lib/libgvfg.dll.a
GVFG_SDK/build/Desktop_Qt_6_10_2_MSVC2022_64bit-Release/lib/libgvfg_preview.dll.a
GVFG_Qt_Sample/build-release/bin/gvfg_qt_preview.exe
```
MSVC 上層連結 `gvfg.lib` 與 `gvfg_preview.lib`;MinGW 上層連結
`libgvfg.dll.a` 與 `libgvfg_preview.dll.a`。如果 CMake 找不到 `dlltool`,
可在 SDK configure 時指定 `-DGVFG_MINGW_DLLTOOL=<path-to-dlltool.exe>`。
## Driver compatibility
GVFG SDK 不再直接定義 driver IOCTL 或 register layout。底層 driver 相容性由
主管提供的 `GvfgSdk.lib` 負責,GVFG 只使用其 `Gvfg*` API。
### Zero-copy selection
上層程式可在 `gvfg_create()` 後、`gvfg_open_channel()` 前選擇 zero-copy:
```c
gvfg_handle handle = NULL;
gvfg_create(&handle);
gvfg_set_channel_zero_copy_enabled(handle, GVFG_CHANNEL_0, 1);
gvfg_open_channel(handle, device_index, GVFG_CHANNEL_0);
```
每個 channel 可在 open 前選擇要註冊/接收的事件:
```c
uint32_t events = GVFG_EVENT_MASK_SIGNAL_CONNECTED |
GVFG_EVENT_MASK_SIGNAL_DISCONNECTED |
GVFG_EVENT_MASK_FORMAT_CHANGE_BEGIN;
gvfg_set_channel_event_mask(handle, GVFG_CHANNEL_0, events);
gvfg_open_channel(handle, device_index, GVFG_CHANNEL_0);
```
`VIDEO_DMA` 為 frame capture 必需,SDK 固定註冊。Plug-in、Unplug 與
Format-change driver event 則依 mask 註冊;關閉它們也會停用對應的自動訊號恢復。
Application 收到 `GVFG_EVENT_SIGNAL_DISCONNECTED` 後應暫停 video/audio read,
等待 `GVFG_EVENT_SIGNAL_CONNECTED` 或 stop 再喚醒 worker,不應在已知無訊號時持續
輪詢 timeout。
每個成功取得的 video/audio frame 都包含 `timestamp_ns`。兩者使用相同的
monotonic SDK delivery clock,可供 Application 做 soft A/V sync;它不是硬體
capture timestamp,也不能跨 process 或 session 比較。
每個 channel 預設為 copy mode。指定 channel open 後不可切換該路模式;
另一條尚未 open 的 channel 仍可獨立選擇。Zero-copy mode 仍使用相同的 `gvfg_read_channel_frame()` /
`gvfg_release_channel_frame()` ownership contract,每次成功 read 都必須 release。
SDK 會在 open 時 enable zero-copy,並在 close/destroy 時 disable。
### Audio capture
Channel 預設只啟動 video。CH0 可在 start 前改成 video + audio:
```c
gvfg_open_channel(handle, device_index, GVFG_CHANNEL_0);
gvfg_set_channel_audio_enabled(handle, GVFG_CHANNEL_0, 1);
gvfg_audio_format_t audio = {0};
gvfg_get_channel_audio_format(handle, GVFG_CHANNEL_0, &audio);
gvfg_start_channel(handle, GVFG_CHANNEL_0);
gvfg_audio_frame_t pcm = {0};
if (gvfg_read_channel_audio_frame(handle, GVFG_CHANNEL_0, &pcm, 1000) == GVFG_OK) {
/* Consume pcm.data / pcm.data_size here. */
gvfg_release_channel_audio_frame(handle, GVFG_CHANNEL_0, &pcm);
}
```
Video-only 使用 `IOCTL_GIGA_VIDEO_START/STOP`;video + audio 使用
`IOCTL_GIGA_START/STOP_VIDEO_AUDIO`。PCM 由 driver DMA buffer 複製到
SDK-owned frame buffer,再以和 video 相同的 read/release ownership 交付。
SDK 不建立 audio ring buffer。Audio zero-copy
尚未納入,CH1 audio 也尚未正式支援。
Qt sample 的 monitoring playback 與 capture reader 分開。若 `QAudioSink` write
失敗或連續兩秒沒有寫入進度,只會清除過期的播放 queue 並在 audio thread 重新取得
預設 output device、重建 sink;video/audio capture 不會因此停止。Playback recovery
不影響 SDK frame release contract。
### 同一裝置雙 channel
同一個 `gvfg_handle` 可對同一個 device index 開啟 CH0、CH1。SDK 只建立一個
Windows device handle;兩個 channel 各自保有 event、單一 frame buffer
以及 held-frame/zero-copy ownership:
```c
gvfg_open_channel(handle, device_index, GVFG_CHANNEL_0);
gvfg_open_channel(handle, device_index, GVFG_CHANNEL_1);
gvfg_start_channel(handle, GVFG_CHANNEL_0);
gvfg_start_channel(handle, GVFG_CHANNEL_1);
gvfg_frame_t frame0 = {0};
if (gvfg_read_channel_frame(handle, GVFG_CHANNEL_0, &frame0, 1000) == GVFG_OK)
gvfg_release_channel_frame(handle, GVFG_CHANNEL_0, &frame0);
gvfg_stop(handle); /* stop both channels */
```
兩個 channel 應由不同 worker thread 讀取。所有 stream、frame、event、signal 與
runtime API 都明確要求 `channel_index`;不再保留隱含 selected-channel 的舊 API。
目前硬體不允許 CH0、CH1 同時使用 Y210;SDK 會拒絕第二個 Y210 設定。
`gvfg_qt_preview.exe` 只使用 public API,主畫面只顯示 input 與 Preview
狀態;CH0、CH1 各自有 Start、Stop 與獨立 Preview 視窗,可單獨測試,
也可同時啟動。第二個 channel open/start 失敗時不會停止已運作的 channel。
關閉獨立 Preview 視窗只會停止該視窗的 frame submission;capture/audio 仍可繼續,
未顯示的 frame 不計為 preview delivery failure。重新開啟 Preview 或 Fullscreen 會
恢復 frame submission。
IRQ、DMA 等資訊只存在 internal diagnostic tool。
## Consumer Layout
一般 application 使用 core SDK 只需要:
```text
include/gvfg_capture.h
lib/gvfg.lib
bin/gvfg.dll
```
`GvfgSdk.lib` 已靜態連結進 `gvfg.dll`,Application 不需另外部署
`giga_ioctl.dll` 或主管 library 的額外 runtime DLL。
需要 optional display helper 時,再加:
```text
include/gvfg_preview.h
lib/gvfg_preview.lib
bin/gvfg_preview.dll
```
GPU snapshot/export conversion 已整合在 `gvfg.dll`,不需要額外 helper DLL。
Customer/demo package 不應包含 `gvfg_debug.h`、SDK source、GigabyteLib session
headers、IRQ details 或 helper source。這些只屬於 internal
debug/full application package。