Update SDK 3.2 documentation and add English and Traditional Chinese versions

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

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 16:03:38 +08:00
co-authored by Claude Opus 5.5
parent 02c7004e8c
commit 784aa5c579
21 changed files with 3277 additions and 1044 deletions
+304 -231
View File
@@ -1,15 +1,18 @@
# GVFG 客戶 API 使用手冊
# GVFG Customer API Guide
本文件說明 SDK 3.1.0 的公開擷取介面 `gvfg_capture.h`。
影像/音訊/同步播放另使用 `gvfg_playback.h`,完整流程見
[統一影音播放使用手冊](GVFG_PLAYBACK_API.md)。Capture 與 Playback 是不同 handle 與 DLL。
English | [繁體中文](GVFG_CUSTOMER_API.zh-TW.md)
先依下列流程完成擷取整合;逐參數定義與完整限制見
[API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
This guide covers the public capture interface `gvfg_capture.h` in SDK 3.2.0, and the optional
OSD interface `gvfg_osd.h`. Video, audio, and synchronized playback use `gvfg_playback.h`; see the
[Unified Playback Guide](GVFG_PLAYBACK_API.md) for the full flow. Capture, OSD, and Playback are
separate DLLs, and Capture and Playback use separate handles.
## 1. 套件內容
Follow the flow below to integrate capture. For per-parameter definitions and all limits, see the
[API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md).
核心擷取:
## 1. Package contents
Core capture:
```text
include/gvfg_capture.h
@@ -17,9 +20,19 @@ lib/gvfg.lib
bin/gvfg.dll
```
核心擷取只需連結 `gvfg.lib`,並部署相同版本的 `gvfg.dll`。
Core capture only needs `gvfg.lib` at link time and the matching `gvfg.dll` at run time.
選用播放(純影像、純音訊或影音):
Optional OSD (font list, text measurement, channel OSD, standalone BGRA overlay):
```text
include/gvfg_osd.h
lib/gvfg_osd.lib
bin/gvfg_osd.dll
```
`gvfg_osd.dll` depends on the `gvfg.dll` from the same SDK build; update both together.
Optional playback (video-only, audio-only, or audio-video):
```text
include/gvfg_playback.h
@@ -27,9 +40,10 @@ lib/gvfg_playback.lib
bin/gvfg_playback.dll
```
目前支援 Windows x64。API 使用 C ABI,可由 C 或 C++ 呼叫。
MinGW uses the matching `libgvfg.dll.a`, `libgvfg_osd.dll.a`, and `libgvfg_playback.dll.a`.
Windows x64 is currently supported. The API uses a C ABI and can be called from C or C++.
## 2. 最小擷取流程
## 2. Minimal capture flow
```text
gvfg_enumerate_devices
@@ -38,19 +52,19 @@ gvfg_enumerate_devices
-> gvfg_open_channel
-> gvfg_set_channel_audio_enabled (optional, before start)
-> gvfg_start_channel
-> 重複:
-> repeat:
gvfg_read_channel_frame
使用/複製/轉換 frame
use / copy / convert the frame
gvfg_release_channel_frame
若已啟用 audio,另一個 worker thread 重複:
if audio is enabled, on a separate worker thread repeat:
gvfg_read_channel_audio_frame
使用/複製 PCM
use / copy the PCM
gvfg_release_channel_audio_frame
-> gvfg_stop
-> gvfg_destroy
```
完整範例:
Complete example:
```c
#include <gvfg_capture.h>
@@ -79,7 +93,7 @@ int main(void)
if (st != GVFG_OK)
break;
/* 在 release 前處理、轉換或複製 frame.data。 */
/* Process, convert, or copy frame.data before release. */
st = gvfg_release_channel_frame(h, GVFG_CHANNEL_0, &frame);
if (st != GVFG_OK)
@@ -93,168 +107,191 @@ int main(void)
}
```
## 3. 執行緒與 frame 所有權
## 3. Threading and frame ownership
- API 是 pull model;應用程式自行決定在哪個執行緒呼叫
`gvfg_read_channel_frame()`。GUI 程式建議每個 channel 使用一個 worker thread,再把 UI 更新送回
UI thread。
- `frame.data` 是唯讀的借用 pointer,可能指向原生擷取 buffer 或 SDK 處理後的
buffer。Zero-copy 設定控制擷取方式;啟用 OSD 時仍可能交付 SDK-owned buffer。
Pointer 只在對應的 `gvfg_release_channel_frame()` 前有效,資料若要長期保存,必須先複製。
- 每個 channel 同時最多持有一個 frame。尚未 release 又對同一 channel 呼叫
`gvfg_read_channel_frame()`,會回傳 `GVFG_ESTATE`。
- release 時傳回 read 取得的 `gvfg_frame_t`;不要自行修改 frame descriptor 的內容。
- `gvfg_stop()` 會中止等待並使尚未 release 的 frame 失效。
- 同一個 handle 的 lifecycle 操作應由應用程式自行序列化;不要同時 open、
start、stop 或 destroy。
- The API is pull-based; the application decides which thread calls
`gvfg_read_channel_frame()`. GUI applications should use one worker thread per channel and
post UI updates back to the UI thread.
- `frame.data` is a read-only borrowed pointer. It may point to the native capture buffer or to an
SDK-processed buffer. The zero-copy setting controls acquisition; with OSD enabled, the SDK may
still deliver an SDK-owned buffer. The pointer is valid only until the matching
`gvfg_release_channel_frame()`; copy the data if it must be kept longer.
- Each channel holds at most one frame at a time. Calling `gvfg_read_channel_frame()` again on the
same channel before release returns `GVFG_ESTATE`.
- Pass the `gvfg_frame_t` returned by read back to release; do not modify the frame descriptor.
- `gvfg_stop()` aborts waits and invalidates unreleased frames.
- The application must serialize lifecycle operations on a handle; do not open, start, stop, or
destroy concurrently.
Audio 採用相同的 pull 與 ownership 模型:
Audio uses the same pull and ownership model:
- 建議使用獨立 audio worker thread,避免阻塞 video read 或 UI thread。
- `gvfg_audio_frame_t.data` 是 SDK-owned PCM,只在對應的
`gvfg_release_channel_audio_frame()` 前有效。
- 同一 channel 同時只能持有一個 audio frame;未 release 再 read 會回傳
`GVFG_ESTATE`。
- release 時傳回 read 取得的 `gvfg_audio_frame_t`;不要自行修改 frame descriptor 的內容。
- 若播放或錄音需要在 release 後繼續使用 PCM,Application 必須先複製。
- Capture 保有自己的交付 buffer;播放副本、queue、同步與輸出由 Playback 管理。
- 使用 Playback 時,submit 已完成複製後即可 release,Demo 不自行實作音訊調速或同步。
- 播放錯誤由 Playback API 回傳狀態碼回報,caller 決定停止與重啟。
輸出裝置故障後,應用程式須處理錯誤並決定是否重新啟動播放。
- Use a separate audio worker thread so that audio does not block video reads or the UI thread.
- `gvfg_audio_frame_t.data` is SDK-owned PCM, valid only until the matching
`gvfg_release_channel_audio_frame()`.
- Each channel holds at most one audio frame at a time; reading again before release returns
`GVFG_ESTATE`.
- Pass the `gvfg_audio_frame_t` returned by read back to release; do not modify the descriptor.
- If playback or recording needs the PCM after release, the application must copy it first.
- Capture keeps its own delivery buffers; playback copies, queues, synchronization, and output are
managed by Playback.
- With Playback, release the frame once submit has copied it; the demo does not implement its own
audio rate adjustment or synchronization.
- Playback errors are reported through Playback API status codes, and the caller decides whether to
stop and restart. After an output-device failure, the application handles the error and decides
whether to restart playback.
`timeout_ms` 的共同規則:`0` 表示不等待;`GVFG_TIMEOUT_INFINITE` 表示無限等待;
其他值的單位為毫秒。
Common `timeout_ms` rule: `0` does not wait; `GVFG_TIMEOUT_INFINITE` waits indefinitely; other
values are in milliseconds.
## 4. 狀態碼
## 4. Status codes
| 狀態 | 說明 |
| --------------- | --------------------------- |
| `GVFG_OK` | 成功 |
| `GVFG_EINVAL` | 參數、channel 或 frame token 無效 |
| `GVFG_ENODEV` | 找不到裝置或裝置無法開啟 |
| `GVFG_ESTATE` | 呼叫時機或 handle 狀態不正確 |
| `GVFG_EIO` | 擷取、轉換或其他 I/O 失敗 |
| `GVFG_ENOTSUP` | 格式或功能不支援 |
| `GVFG_ETIMEOUT` | 等待逾時 |
| `GVFG_EBUSY` | 裝置或 capture resource 正在使用中 |
| Status | Meaning |
| --------------- | ----------------------------------------------- |
| `GVFG_OK` | Success |
| `GVFG_EINVAL` | Invalid argument, channel, or frame token |
| `GVFG_ENODEV` | No device found, or the device cannot be opened |
| `GVFG_ESTATE` | Wrong call timing or handle state |
| `GVFG_EIO` | Capture, conversion, or other I/O failure |
| `GVFG_ENOTSUP` | Format or feature not supported |
| `GVFG_ETIMEOUT` | Wait timed out |
| `GVFG_EBUSY` | Device or capture resource is in use |
公開 API 不暴露底層 capture library 的錯誤型別。所有失敗都會轉成上述
`GVFG_E*` 狀態;Application 應使用 `status != GVFG_OK` 判斷,不可套用
Windows `FAILED()`/`SUCCEEDED()`。
The public API does not expose the underlying capture library's error types. Every failure is
mapped to one of the `GVFG_E*` statuses above. Test with `status != GVFG_OK`; do not use the
Windows `FAILED()`/`SUCCEEDED()` macros.
可用 `gvfg_strerror()` 取得靜態英文說明字串;呼叫端不可釋放該字串。
`gvfg_strerror()` returns a static English description; the caller must not free it.
可用 `gvfg_get_version()` 查詢目前實際載入的 `gvfg.dll` 版本。回傳值為
靜態字串,例如 `"3.1.0"`,呼叫端不可釋放。
需要記錄最近一次失敗的詳細原因時,可在 API 失敗後立即呼叫
`gvfg_get_channel_last_sdk_error_detail()`。此 API 回傳可供問題回報使用的公開診斷文字。
`gvfg_get_version()` returns the version of the `gvfg.dll` actually loaded, as a static string such
as `"3.2.0"`; the caller must not free it. To record the detailed reason for the most recent
failure, call `gvfg_get_channel_last_sdk_error_detail()` immediately after the failing call. It
returns public diagnostic text suitable for problem reports.
## 5. 資料格式
## 5. Data formats
### 原生擷取格式
### Native capture formats
| 格式 | `pixel_format` | bit depth | 每列大小 |
| ----------------- | ------------------:| ---------:| -----------:|
| YUY2 packed 4:2:2 (`Y0 U0 Y1 V0`) | `GVFG_PIXFMT_YUY2` | 8 | `width * 2` |
| Y210 packed 4:2:2 | `GVFG_PIXFMT_Y210` | 10 | `width * 4` |
| Format | `pixel_format` | Bit depth | Row size |
| --------------------------------- | ------------------:| ---------:| -----------:|
| YUY2 packed 4:2:2 (`Y0 U0 Y1 V0`) | `GVFG_PIXFMT_YUY2` | 8 | `width * 2` |
| Y210 packed 4:2:2 | `GVFG_PIXFMT_Y210` | 10 | `width * 4` |
實際列距以 `gvfg_frame_t.row_stride_bytes` 為準。
目前不支援的輸入格式會回傳 `GVFG_ENOTSUP`。可用
`gvfg_pixel_format_name()` 取得靜態格式名稱。
Always use `gvfg_frame_t.row_stride_bytes` as the actual row pitch. Currently unsupported input
formats return `GVFG_ENOTSUP`. `gvfg_pixel_format_name()` returns a static format name.
### `gvfg_frame_t`
- `data`、`data_size`:SDK buffer 與可用 byte 數。
- `width`、`height`:影像尺寸。
- `row_stride_bytes`:相鄰兩列起點的 byte 距離。
- `pixel_format`、`bit_depth`:原生 payload 格式。
- `frame_id`:SDK 成功交付序號;每次 channel Start 從 1 重新開始。
- `timestamp_ns`:SDK monotonic delivery timestamp,與 audio 使用相同 clock domain。
- `data`, `data_size`: SDK buffer and its usable byte count.
- `width`, `height`: image size.
- `row_stride_bytes`: byte distance between the starts of adjacent rows.
- `pixel_format`, `bit_depth`: native payload format.
- `frame_id`: SDK delivery sequence number; restarts at 1 on every channel start.
- `timestamp_ns`: SDK monotonic delivery timestamp, in the same clock domain as audio.
### PCM audio
`gvfg_audio_format_t` 只提供上層實際需要的播放格式:`sample_rate`、
`channels`、`bits_per_sample`。Driver frame 大小與 block alignment 是 backend
細節,不要求 Application 配置相同大小的 buffer。
`gvfg_audio_format_t` provides only the playback format the application needs: `sample_rate`,
`channels`, and `bits_per_sample`. Driver frame size and block alignment are backend details; the
application does not need to allocate buffers of the same size.
`gvfg_audio_frame_t` 包含:
`gvfg_audio_frame_t` contains:
- `data`、`data_size`:SDK-owned PCM 與本次有效 byte 數。
- `sample_rate`、`channels`、`bits_per_sample`:此 frame 的 PCM 格式。
- `frame_id`:SDK 成功交付序號;每次 channel Start 從 1 重新開始。
- `timestamp_ns`:SDK monotonic delivery timestamp,與 video 使用相同 clock domain。
- `data`, `data_size`: SDK-owned PCM and its valid byte count for this frame.
- `sample_rate`, `channels`, `bits_per_sample`: PCM format of this frame.
- `frame_id`: SDK delivery sequence number; restarts at 1 on every channel start.
- `timestamp_ns`: SDK monotonic delivery timestamp, in the same clock domain as video.
`timestamp_ns` 用於比較同一 process/session 內的 video/audio delivery timing;它
不是 driver 或硬體 capture timestamp。
Use `timestamp_ns` to compare video and audio delivery timing within the same process/session. It
is not a driver or hardware capture timestamp.
目前 audio 僅支援 CH0,且必須與 video 一起啟動;不支援 audio-only。公開
audio API 不是 zero-copy,但上層仍使用和 video 相同的 read/release contract。
Audio is currently supported on CH0 only and must start together with video; audio-only capture is
not supported. The public audio API is not zero-copy, but it uses the same read/release contract as
video.
## 6. 公開 API
## 6. Public API
### 裝置與生命週期
### Devices and lifecycle
- `gvfg_enumerate_devices(out_devices, max_devices)`:列舉裝置。傳入
`NULL, 0` 可只查數量;回傳值是寫入數量或可用裝置數,無裝置時為 `0`。
- `gvfg_create(&handle)`:建立 closed session。
- `gvfg_set_channel_zero_copy_enabled(handle, channel, enabled)`:替指定 channel
選用 zero-copy;只能在該 channel open 前呼叫,預設為關閉。
- `gvfg_get_channel_zero_copy_enabled(handle, channel, &enabled)`:查詢指定
channel 選擇的模式。
- `gvfg_open_channel(handle, device_index, channel)`:開啟列舉所得裝置,channel
必須為 `GVFG_CHANNEL_0` 或 `GVFG_CHANNEL_1`。
- `gvfg_start_channel(handle, channel)`:開始指定 channel 擷取。每次明確 Start 都會重新查詢一次
signal;若目前沒有 lock,回傳 `GVFG_ETIMEOUT`,channel 維持 stopped,接上訊號後須由
Application 再次呼叫 Start。
- `gvfg_stop(handle)`:停止擷取;重複呼叫仍回傳成功。
- `gvfg_destroy(handle)`:必要時先停止,再銷毀 handle。銷毀後不得再使用。
- `gvfg_enumerate_devices(out_devices, max_devices)`: enumerate devices. Pass `NULL, 0` to query
the count only. Returns the number written or the number available; `0` when there is no device.
- `gvfg_create(&handle)`: create a closed session.
- `gvfg_set_channel_zero_copy_enabled(handle, channel, enabled)`: select zero-copy for a channel.
Call only before that channel is opened; the default is off.
- `gvfg_get_channel_zero_copy_enabled(handle, channel, &enabled)`: query the mode selected for a
channel.
- `gvfg_open_channel(handle, device_index, channel)`: open an enumerated device; `channel` must be
`GVFG_CHANNEL_0` or `GVFG_CHANNEL_1`.
- `gvfg_start_channel(handle, channel)`: start capture on a channel. Every explicit start queries
the signal once. If there is no lock, it returns `GVFG_ETIMEOUT` and the channel stays stopped;
the application must call start again after the signal is connected.
- `gvfg_stop_channel(handle, channel)`: stop only the given channel; the other channel keeps
capturing.
- `gvfg_stop(handle)`: stop every opened channel on the handle; repeated calls still succeed.
- `gvfg_destroy(handle)`: stop if necessary, then destroy the handle. Do not use it afterwards.
Zero-copy 模式必須在 channel open 前選擇;要切換模式時,先銷毀並重新建立 session。
每次成功 `gvfg_read_channel_frame()` 後仍須呼叫 `gvfg_release_channel_frame()`,用來結束
公開 pointer/token lifetime;依目前 Lib 契約不送逐 frame driver release。Device open 後
不可直接切換;應 destroy session、重新 create、設定模式後再 open。
Zero-copy mode must be selected before the channel is opened. To switch modes, destroy and
recreate the session. Every successful `gvfg_read_channel_frame()` still requires
`gvfg_release_channel_frame()` to end the public pointer/token lifetime; under the current library
contract no per-frame driver release is sent. The mode cannot be switched after the device is
opened: destroy the session, create it again, set the mode, then open.
### Frame
### Frames
- `gvfg_read_channel_frame(handle, channel, &frame, timeout_ms)`:取得原生或 SDK 處理後的唯讀
frame;copy/zero-copy acquisition 的 release contract 相同。
- `gvfg_release_channel_frame(handle, channel, &frame)`:釋放原 frame token。
- `gvfg_read_channel_frame(handle, channel, &frame, timeout_ms)`: get a read-only native or
SDK-processed frame. Copy and zero-copy acquisition share the same release contract.
- `gvfg_release_channel_frame(handle, channel, &frame)`: release the original frame token.
### SDK OSD
使用 OSD 時請包含 `gvfg_osd.h`,連結 `gvfg_osd.lib`(MinGW 使用 `libgvfg_osd.dll.a`),並隨應用程式部署同一次 SDK 建置的 `gvfg_osd.dll` 和 `gvfg.dll`。一般擷取只需連結 `gvfg.dll` 對應的 import library。
To use OSD, include `gvfg_osd.h`, link `gvfg_osd.lib` (`libgvfg_osd.dll.a` for MinGW), and deploy
`gvfg_osd.dll` and `gvfg.dll` from the same SDK build with the application. Plain capture only
needs the import library for `gvfg.dll`.
每個已 open 的 channel 可設定兩組 OSD,`osd_index` 為 `0`、`1`;重疊時第 `1` 組在上方。
OSD 會加入後續取得的 YUY2/Y210 frame,preview、snapshot 或錄影是否顯示 OSD,
取決於它們是否使用這份 frame。
Each opened channel has two OSD slots, `osd_index` `0` and `1`; where they overlap, slot `1` is on
top. OSD is applied to subsequently read YUY2/Y210 frames. Whether a preview, snapshot, or
recording shows the OSD depends on whether it uses those frames.
1. 呼叫 `gvfg_get_osd_fonts(&list)`,取得可用字型,將選到的 UTF-8 名稱複製保存。
客戶可先在 Windows 安裝新字型,再重新取得清單。SDK 管理清單,不需 callback 或 free;
指標有效到下一次清單查詢或 DLL 卸載,查詢與讀取清單須由 caller 序列化。
2. 填寫 `gvfg_channel_osd_config_t`:文字、`font_family`、大小、顏色與 `x/y`。
`text` 是 NUL 結尾的 1–32 個可列印 ASCII 字元,不接受中文或換行;
字型名稱是 NUL 結尾的 UTF-8 字串,不是檔案路徑。字號必須大於 0。
3. 用 `gvfg_measure_osd_text(&config, &width, &height)` 量測,再呼叫
`gvfg_set_channel_osd(handle, channel, osd_index, &config)` 設定並顯示該組。
Set 返回前已複製字串,caller 不必持續保存原設定字串。
4. 暫時不顯示時,呼叫 `gvfg_set_channel_osd_visible(..., 0)`;恢復使用 `1`。
Hide/Show 保留該組設定;`gvfg_clear_channel_osd()` 才清除該組,之後須重新 Set。
1. Call `gvfg_get_osd_fonts(&list)` to get the available fonts, and copy the chosen UTF-8 name.
Customers can install new fonts in Windows and query the list again. The SDK manages the list,
so no callback or free is needed. The pointers are valid until the next list query or DLL
unload, and the caller must serialize querying and reading the list.
2. Fill in `gvfg_channel_osd_config_t`: text, `font_family`, size, color, and `x/y`.
`text` is a NUL-terminated string of 1–32 printable ASCII characters; Chinese text and line
breaks are not accepted. The font name is a NUL-terminated UTF-8 string, not a file path. The
font size must be greater than 0.
3. Measure with `gvfg_measure_osd_text(&config, &width, &height)`, then call
`gvfg_set_channel_osd(handle, channel, osd_index, &config)` to configure and show that slot.
Set copies the strings before it returns, so the caller does not need to keep them.
4. To hide a slot temporarily, call `gvfg_set_channel_osd_visible(..., 0)`; use `1` to show it
again. Hide/show keeps the slot's settings; only `gvfg_clear_channel_osd()` clears the slot, after
which it must be set again.
`x/y` 是量測文字框左上角;位置會限制在影像內。文字框本身放不下時,該組暫停顯示,
另一組與擷取繼續;文字或影像尺寸調整後可恢復。不自動縮字、截字或換行。
無效字型/文字/組別回傳 `GVFG_EINVAL`;尚未設定的組別不能直接 Show。
SDK handle 銷毀後,應用程式需自行保存並重設所需的 OSD 設定。
To hand the OSD to an FPGA or another component for compositing, call
`gvfg_render_osd_frame_bgra(video_width, video_height, slot0, slot1, &bitmap)`. It needs no
capture handle and produces a top-down, premultiplied BGRA8888 image with a transparent background,
the same size as the video, with a stride of `width * 4`. Pass NULL for `slot0`/`slot1` to omit that
slot. The output is SDK-owned and valid until the next call to this function on the same thread
(including a failed call), thread exit, or DLL unload; copy it before any asynchronous transfer. This
function does not affect the channel's GPU OSD.
完整欄位、字級定義、回傳值與限制見
[API Reference:OSD](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md#226-osd-字型設定顯示隱藏與清除)。
`x/y` is the top-left corner of the measured text box; the position is clamped to stay inside the
frame. If the text box itself does not fit, that slot is paused while the other slot and capture
continue; it resumes once the text or frame size allows it to fit. Text is never shrunk, truncated,
or wrapped. Invalid fonts, text, or slots return `GVFG_EINVAL`; a slot that has never been set
cannot be shown directly. After the SDK handle is destroyed, the application must keep and reapply
any OSD settings it needs.
### OSD 呼叫範例
For all fields, size definitions, return values, and limits, see
[API Reference: OSD](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md#3-osd-api).
以下 C++ 範例假設 `handle` 的 `channel` 已 open。先選擇清單中的實際字型,
立即複製名稱,再使用相同設定量測與繪製;每一步都檢查回傳值。
### OSD example
The following C++ example assumes `channel` is already open on `handle`. It picks an actual font
from the list, copies the name immediately, then measures and draws with the same settings,
checking every return value.
```cpp
#include <gvfg_capture.h>
#include <gvfg_osd.h> // includes gvfg_capture.h
#include <string>
gvfg_status_t configure_osd(gvfg_handle handle, int channel)
@@ -289,9 +326,10 @@ gvfg_status_t configure_osd(gvfg_handle handle, int channel)
}
```
Set 返回前已複製字串,函式內的 `family` 可正常離開作用域。兩次 Set 各自生效;
若第二次失敗,第一組仍保持成功設定。下列是之後對第二組的三個獨立操作範例,
並非必須連續執行的初始化步驟;每個結果仍須檢查。
Set copies the strings before returning, so `family` can go out of scope normally. Each Set takes
effect on its own; if the second one fails, the first slot stays configured. The following are three
independent later operations on the second slot, not initialization steps that must run in
sequence; check each result.
```cpp
auto status = gvfg_set_channel_osd_visible(handle, channel, 1, 0); // Hide
@@ -302,89 +340,121 @@ status = gvfg_clear_channel_osd(handle, channel, 1); // Clear
if (status != GVFG_OK) return status;
```
### SDK 3.0.0 介面遷移
### Migrating to SDK 3.2.0
- OSD 的 `set`/`clear` 新增 `osd_index`;原先的一組設定改為每 channel 兩組。
- `gvfg_channel_osd_config_t` 改用 NUL 結尾字串、移除 `text_length`,新增 `font_family`;
量測函式改收同一份設定,沒有舊版相容入口。
- 公開 Playback 移除 `gvfg_playback_stats_t` 與 `gvfg_playback_get_stats()`。
一般顯示資訊與呈現統計改用 `gvfg_playback_get_preview_info()`、`gvfg_playback_get_preview_stats()`。
- 公開 Playback 另移除 `gvfg_preview_delivery_stats_t` 與 `gvfg_playback_get_delivery_stats()`;
詳細佇列與呈現流程計數移至內部 Debug API,不提供公開相容入口。
- 字型清單不需要 capture handle。先選擇實際已安裝的字型,再量測/設定 OSD,
並檢查每次 API 回傳值。單一組別的 Set 不提供兩組一起更新的交易保證。
- OSD functions and types moved from `gvfg_capture.h`/`gvfg.dll` to `gvfg_osd.h`/`gvfg_osd.dll`.
Applications that use OSD must include `gvfg_osd.h`, link `gvfg_osd.lib`, and deploy
`gvfg_osd.dll`. Function names and parameters are unchanged, but existing applications must be
recompiled and relinked.
- Added `gvfg_get_channel_hdmi_audio_info()`.
### Audio frame
### Migrating to SDK 3.1.0
- `gvfg_set_channel_audio_enabled(handle, channel, enabled)`:在 start 前啟用或停用
audio;video 永遠保留,不需要組合 stream flags。
- `gvfg_get_channel_audio_format(handle, channel, &format)`:取得 PCM 播放格式。
- `gvfg_read_channel_audio_frame(handle, channel, &frame, timeout_ms)`:取得一個
SDK-owned PCM frame。
- `gvfg_release_channel_audio_frame(handle, channel, &frame)`:釋放原 audio token。
- Added `gvfg_get_channel_hdmi_info()` and `gvfg_get_chip_info()`.
- The full-frame OSD overlay function was renamed to `gvfg_render_osd_frame_bgra()`, replacing
`gvfg_render_osd_bgra()`.
成功 read 後,不論 PCM 是送往播放、錄音或被丟棄,都必須正好 release 一次。
### Migrating to SDK 3.0.0
`gvfg_set_channel_video_format()` 可在 stream 尚未開始或已 stop 時選擇 YUY2/Y210。
此功能由 SDK 的 capture backend 實作。
- OSD `set`/`clear` gained an `osd_index`; the single configuration became two slots per channel.
- `gvfg_channel_osd_config_t` now uses NUL-terminated strings, drops `text_length`, and adds
`font_family`. The measurement function takes the same configuration; there is no compatibility
entry point for the old form.
- Public Playback removed `gvfg_playback_stats_t` and `gvfg_playback_get_stats()`. Use
`gvfg_playback_get_preview_info()` and `gvfg_playback_get_preview_stats()` for general display
information and presentation statistics.
- Public Playback also removed `gvfg_preview_delivery_stats_t` and
`gvfg_playback_get_delivery_stats()`; detailed queue and presentation counters moved to the
internal Debug API with no public compatibility entry point.
- The font list does not need a capture handle. Pick an actually installed font, then measure/set
the OSD and check every return value. A Set on one slot does not provide a transactional guarantee
of updating both slots together.
### 查詢
### Audio frames
- `gvfg_get_version()`:目前載入的 GVFG runtime 版本。
- `gvfg_get_gigabyte_lib_version()`:編譯進該 runtime 的 GigabyteLib 版本;不是 driver
或 FPGA 的執行時版本查詢。兩者回傳靜態字串,不需要 handle 或 free。
- `gvfg_get_channel_signal_status(handle, channel, &status)`:查詢指定 channel 的連線、尺寸、
原生格式與 bit depth。沒有輸入訊號是正常狀態:回傳 `GVFG_OK` 且
`connected == 0`。Channel 尚未 running 時會向 capture backend 更新;running 期間則回傳
SDK cache,不再額外讀取硬體。
- `gvfg_get_channel_runtime_info(handle, channel, &info)`:取得指定 channel 已交付 frame 數與
依 read 間隔估算的 `capture_fps`。start 時統計值重設。
- `gvfg_set_channel_audio_enabled(handle, channel, enabled)`: enable or disable audio before start.
Video is always kept; there are no stream flags to combine.
- `gvfg_get_channel_audio_format(handle, channel, &format)`: get the PCM playback format.
- `gvfg_read_channel_audio_frame(handle, channel, &frame, timeout_ms)`: get one SDK-owned PCM frame.
- `gvfg_release_channel_audio_frame(handle, channel, &frame)`: release the original audio token.
### Event
After a successful read, release exactly once, whether the PCM goes to playback, to recording, or is
discarded.
`gvfg_poll_channel_event(handle, channel, &event, timeout_ms)` 一次取出指定 channel 的事件,只能在 running
狀態使用。stop 會喚醒阻塞中的 poll,並回傳 `GVFG_ESTATE`。
`gvfg_set_channel_video_format()` selects YUY2/Y210 while the stream has not started or has been
stopped. It is implemented by the SDK's capture backend.
| Event | 應用程式動作 |
| -------------------------------- | --------------------------- |
| `GVFG_EVENT_VIDEO_FORMAT_CHANGED` | Lib 的 video format changed event |
| `GVFG_EVENT_VIDEO_INPUT_PLUGIN` | Lib 的 video input plug-in event |
| `GVFG_EVENT_VIDEO_INPUT_UNPLUG` | Lib 的 video input unplug event |
### Queries
`event` 使用 `gvfg_event_type_t`;SDK 直接寫入本次取出的事件種類。
SDK 會在 format changed、input plug-in 或 input unplug event 放入 public queue 前先同步
signal cache。Application 收到事件後可呼叫 `gvfg_get_channel_signal_status()` 取得對應的新狀態;
running 期間此查詢讀取 cache,不會再次向 driver 查詢。
- `gvfg_get_version()`: version of the loaded GVFG runtime.
- `gvfg_get_gigabyte_lib_version()`: version of GigabyteLib compiled into that runtime; it is not a
run-time driver or FPGA version query. Both return static strings and need no handle or free.
- `gvfg_get_channel_signal_status(handle, channel, &status)`: connection state, size, native
format, and bit depth of a channel. No input signal is a normal state: it returns `GVFG_OK` with
`connected == 0`. While the channel is not running, the status is refreshed from the capture
backend; while running, the SDK cache is returned without reading the hardware again.
- `gvfg_get_channel_runtime_info(handle, channel, &info)`: frames delivered on the channel and
`capture_fps` estimated from read intervals. The statistics reset on start.
- `gvfg_get_channel_sdi_info(handle, channel, &info)`: raw values and display strings for SDI mode,
resolution, fps, scan, ST 352, and so on.
- `gvfg_get_channel_hdmi_info(handle, channel, &info)`: HDMI lock, width/height, FPS, color format,
color space, and bit depth.
- `gvfg_get_channel_hdmi_audio_info(handle, channel, &info)`: HDMI audio lock, sample-frequency
code, bits per sample, channel count, and format code.
- `gvfg_get_chip_info(handle, &info)`: chip version date and time; at least one channel on the
handle must be open.
## 7. GPU 同步轉換
Use the `video_interface` from `gvfg_get_channel_signal_status()` to choose between the SDI and HDMI
queries. All of these queries require the channel to be open and otherwise return `GVFG_ESTATE`;
use the output only when the call returns `GVFG_OK`.
GPU 轉換在 `gvfg.dll` 內完成,呼叫是同步的。必須在
`gvfg_release_channel_frame()` 前轉換;函式返回後 SDK 不保留 source 或 destination
pointer。
### Events
支援輸出:
`gvfg_poll_channel_event(handle, channel, &event, timeout_ms)` takes one event for the given
channel and can only be used while running. Stop wakes a blocked poll, which then returns
`GVFG_ESTATE`.
| 格式 | 配置需求 |
| ------------------------- | --------------------------------------- |
| `GVFG_GPU_OUTPUT_BGRA8` | `row_bytes >= width * 4`;alpha = 255 |
| `GVFG_GPU_OUTPUT_RGB10A2` | `row_bytes >= width * 4`;alpha = 3 |
| `GVFG_GPU_OUTPUT_NV12` | width/height 必須為偶數;`row_bytes >= width` |
| Event | Source |
| --------------------------------- | ------------------------------------- |
| `GVFG_EVENT_VIDEO_FORMAT_CHANGED` | Library video format changed event |
| `GVFG_EVENT_VIDEO_INPUT_PLUGIN` | Library video input plug-in event |
| `GVFG_EVENT_VIDEO_INPUT_UNPLUG` | Library video input unplug event |
BGRA8/RGB10A2 的 destination 至少為 `row_bytes * height`。NV12 至少為
`row_bytes * (height + height / 2)`,排列為 Y plane,接著是 interleaved UV
plane;使用 BT.709 limited range。
`event` is a `gvfg_event_type_t`; the SDK writes the kind of the event taken. Before a format
changed, input plug-in, or input unplug event is placed in the public queue, the SDK synchronizes
its signal cache. After receiving an event, the application can call
`gvfg_get_channel_signal_status()` to get the corresponding new state; while running, that query
reads the cache and does not query the driver again.
可使用通用函式 `gvfg_gpu_convert_to_buffer()`,或便利函式:
## 7. Synchronous GPU conversion
GPU conversion runs inside `gvfg.dll` and is synchronous. Convert before
`gvfg_release_channel_frame()`; after the function returns, the SDK keeps neither the source nor the
destination pointer.
Supported outputs:
| Format | Requirements |
| ------------------------- | ------------------------------------------------ |
| `GVFG_GPU_OUTPUT_BGRA8` | `row_bytes >= width * 4`; alpha = 255 |
| `GVFG_GPU_OUTPUT_RGB10A2` | `row_bytes >= width * 4`; alpha = 3 |
| `GVFG_GPU_OUTPUT_NV12` | width and height must be even; `row_bytes >= width` |
For BGRA8/RGB10A2 the destination must be at least `row_bytes * height`. For NV12 it must be at
least `row_bytes * (height + height / 2)`, laid out as the Y plane followed by the interleaved UV
plane, using BT.709 limited range.
Use the generic `gvfg_gpu_convert_to_buffer()` or a convenience function:
- `gvfg_gpu_convert_to_bgra8()`
- `gvfg_gpu_convert_to_rgb10a2()`
- `gvfg_gpu_convert_to_nv12()`
### GPU 轉換範例
### GPU conversion example
例如,要建立一個與輸入 frame 同尺寸的 BGRA8 destination:
以下片段放在回傳 `gvfg_status_t` 的函式內,使用 `<limits.h>`、`<stdint.h>`、`<stdlib.h>`;
`source` 必須有效,且尚未 release。
For example, to create a BGRA8 destination of the same size as the input frame. The snippet belongs
inside a function that returns `gvfg_status_t` and uses `<limits.h>`, `<stdint.h>`, and
`<stdlib.h>`; `source` must be valid and not yet released.
```c
if (source.width <= 0 || source.height <= 0 || source.width > INT_MAX / 4)
@@ -405,48 +475,51 @@ output.pixel_format = GVFG_GPU_OUTPUT_BGRA8;
gvfg_status_t status = gvfg_gpu_convert_to_buffer(&source, &output);
if (status == GVFG_OK) {
/* 在這裡使用 pixels。 */
/* Use pixels here. */
}
free(pixels);
return status;
```
配置前須確認尺寸乘法不會 overflow,並檢查 `malloc()` 是否成功。
不論 conversion 成功或失敗,呼叫端都需在不再使用輸出時釋放自行配置的 `pixels`。
Check that the size multiplication cannot overflow before allocating, and check that `malloc()`
succeeded. Whether the conversion succeeds or fails, free the `pixels` you allocated once you no
longer need the output.
## 8. 播放 API
## 8. Playback API
`gvfg_playback.dll` 提供影像、音訊播放與影音同步功能。
擷取仍由應用程式呼叫 `gvfg.dll`。典型流程:
`gvfg_playback.dll` provides video and audio playback and audio/video synchronization. Capture is
still done by the application through `gvfg.dll`. Typical flow:
```text
gvfg_playback_create -> attach_window -> default_config -> start
capture video/audio -> submit_video / submit_audio -> release SDK frame
停止提交 -> gvfg_playback_stop -> gvfg_playback_destroy
stop submitting -> gvfg_playback_stop -> gvfg_playback_destroy
```
submit 成功前已完成資料複製,返回後即可 release SDK frame;失敗時也必須 release,
時間不連續或輸出錯誤仍須處理;queue 壓力由 Playback 自動降級並略過過時資料,不要求停止擷取。
stop/reset 會丟棄待播資料,不代表無損排空。
單張影像用 `gvfg_playback_present_image()`,在已綁定視窗、未 start 的 handle 上同步呼叫。
詳細模式、master、緩衝與 timestamp 規則見
[`統一影音播放使用手冊`](GVFG_PLAYBACK_API.md)。
Submit has copied the data before it returns successfully, so the SDK frame can be released right
after; release it on failure too. Timestamp discontinuities and output errors still need handling.
Under queue pressure, Playback automatically degrades and skips stale data; it does not require
capture to stop. Stop and reset discard pending data; they are not a lossless drain. For a single
image, call `gvfg_playback_present_image()` synchronously on a handle that has a window attached and
is not started. For modes, masters, buffering, and timestamp rules, see the
[Unified Playback Guide](GVFG_PLAYBACK_API.md).
## 9. 錯誤處理建議
## 9. Error-handling recommendations
- `GVFG_ETIMEOUT`:連線期間通常可重試,並檢查 signal status/event。收到
`GVFG_EVENT_VIDEO_INPUT_UNPLUG` 後,不應高速輪詢 read API;應等待
`GVFG_EVENT_VIDEO_INPUT_PLUGIN`(或 application stop)再恢復 video/audio read。
- 每次成功取得的 frame 仍必須恰好 release 一次。若 release 與實體拔線競爭,
SDK 會處理 driver 已撤銷 zero-copy ownership 的情況,application 不應特判
`ERROR_BAD_COMMAND (22)`。
- `GVFG_EVENT_VIDEO_FORMAT_CHANGED`:依 Lib 更新後的 video info 重建格式相關資源。
- `GVFG_ESTATE`:檢查 lifecycle、是否重複 read、或是否已 stop。
- `GVFG_EIO`/`GVFG_ENODEV`:停止 session,記錄 `gvfg_strerror()`,再由應用程式
決定是否重新列舉與開啟。
- 不要讀寫硬體 register 或依賴 driver/backend counter;這些不是客戶 API。
- `GVFG_ETIMEOUT`: while connected, this is usually retryable; also check the signal status and
events. After `GVFG_EVENT_VIDEO_INPUT_UNPLUG`, do not poll the read API in a tight loop; wait for
`GVFG_EVENT_VIDEO_INPUT_PLUGIN` (or an application stop) before resuming video/audio reads.
- Every frame read successfully must still be released exactly once. If release races with a
physical unplug, the SDK handles the case where the driver has already revoked zero-copy
ownership; the application should not special-case `ERROR_BAD_COMMAND (22)`.
- `GVFG_EVENT_VIDEO_FORMAT_CHANGED`: rebuild format-dependent resources from the updated video info.
- `GVFG_ESTATE`: check the lifecycle, a repeated read, or whether capture has been stopped.
- `GVFG_EIO`/`GVFG_ENODEV`: stop the session, log `gvfg_strerror()`, and let the application decide
whether to enumerate and open again.
- Do not read or write hardware registers or rely on driver/backend counters; they are not part of
the customer API.
## 完整 API Reference
## Full API Reference
所有公開常數、型別、結構欄位、函式參數與回傳值,請參閱
[`GVFG_CUSTOMER_API_REFERENCE.md`](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
For every public constant, type, struct field, function parameter, and return value, see
[`GVFG_CUSTOMER_API_REFERENCE.md`](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md).