- move public PCM, image and presentation types into gvfg_playback.h and remove the separate backend headers from source and installation - keep WASAPI and D3D backends private while preserving the existing public type names, fields and static backend integration - move detailed preview delivery counters into a private header and expose their playback query only through the Debug diagnostics API - retain public preview information and basic presentation statistics, mark EQUEUE_FULL as reserved, and document capacity limits as advanced settings with recommended defaults - refresh customer guides, API reference and error handling for the single-header interface, presentation counter limits and EAUDIO handle-recreation policy - add SDK-owned standalone premultiplied BGRA text rendering with transparent backgrounds, measured dimensions, thread-local snapshot lifetime and validated output bounds Validation: git diff --cached --check passed. Release gvfg_playback and Customer Sample builds, standalone C/C++ header checks, Debug playback syntax checks and Release export inspection passed earlier in this session. Final follow-up changes affect comments and documentation only. No runtime or hardware playback validation was performed. The existing Release gvfg target was also checked and was up to date. OSD rendering changes were source-reviewed; no new bitmap or hardware test was run in this commit pass. Capture debug exports are unchanged.
451 lines
20 KiB
Markdown
451 lines
20 KiB
Markdown
# GVFG 客戶 API 使用手冊
|
||
|
||
本文件說明 SDK 3.0.0 的公開擷取介面 `gvfg_capture.h`。
|
||
影像/音訊/同步播放另使用 `gvfg_playback.h`,完整流程見
|
||
[統一影音播放使用手冊](GVFG_PLAYBACK_API.md)。Capture 與 Playback 是不同 handle 與 DLL。
|
||
|
||
先依下列流程完成擷取整合;逐參數定義與完整限制見
|
||
[API Reference](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
|
||
|
||
## 1. 套件內容
|
||
|
||
核心擷取:
|
||
|
||
```text
|
||
include/gvfg_capture.h
|
||
lib/gvfg.lib
|
||
bin/gvfg.dll
|
||
```
|
||
|
||
核心擷取只需連結 `gvfg.lib`,並部署相同版本的 `gvfg.dll`。
|
||
|
||
選用播放(純影像、純音訊或影音):
|
||
|
||
```text
|
||
include/gvfg_playback.h
|
||
lib/gvfg_playback.lib
|
||
bin/gvfg_playback.dll
|
||
```
|
||
|
||
目前支援 Windows x64。API 使用 C ABI,可由 C 或 C++ 呼叫。
|
||
|
||
## 2. 最小擷取流程
|
||
|
||
```text
|
||
gvfg_enumerate_devices
|
||
-> gvfg_create
|
||
-> gvfg_set_channel_zero_copy_enabled (optional, before channel open)
|
||
-> gvfg_open_channel
|
||
-> gvfg_set_channel_audio_enabled (optional, before start)
|
||
-> gvfg_start_channel
|
||
-> 重複:
|
||
gvfg_read_channel_frame
|
||
使用/複製/轉換 frame
|
||
gvfg_release_channel_frame
|
||
若已啟用 audio,另一個 worker thread 重複:
|
||
gvfg_read_channel_audio_frame
|
||
使用/複製 PCM
|
||
gvfg_release_channel_audio_frame
|
||
-> gvfg_stop
|
||
-> gvfg_destroy
|
||
```
|
||
|
||
完整範例:
|
||
|
||
```c
|
||
#include <gvfg_capture.h>
|
||
|
||
int main(void)
|
||
{
|
||
gvfg_device_info_t devices[GVFG_MAX_DEVICES] = {0};
|
||
int count = gvfg_enumerate_devices(devices, GVFG_MAX_DEVICES);
|
||
if (count <= 0)
|
||
return 1;
|
||
|
||
gvfg_handle h = NULL;
|
||
if (gvfg_create(&h) != GVFG_OK)
|
||
return 2;
|
||
|
||
gvfg_status_t st = gvfg_open_channel(h, 0, GVFG_CHANNEL_0);
|
||
if (st == GVFG_OK)
|
||
st = gvfg_start_channel(h, GVFG_CHANNEL_0);
|
||
|
||
if (st == GVFG_OK) {
|
||
for (int i = 0; i < 100; ++i) {
|
||
gvfg_frame_t frame = {0};
|
||
st = gvfg_read_channel_frame(h, GVFG_CHANNEL_0, &frame, 1000);
|
||
if (st == GVFG_ETIMEOUT)
|
||
continue;
|
||
if (st != GVFG_OK)
|
||
break;
|
||
|
||
/* 在 release 前處理、轉換或複製 frame.data。 */
|
||
|
||
st = gvfg_release_channel_frame(h, GVFG_CHANNEL_0, &frame);
|
||
if (st != GVFG_OK)
|
||
break;
|
||
}
|
||
}
|
||
|
||
gvfg_stop(h);
|
||
gvfg_destroy(h);
|
||
return st == GVFG_OK ? 0 : 3;
|
||
}
|
||
```
|
||
|
||
## 3. 執行緒與 frame 所有權
|
||
|
||
- API 是 pull model;應用程式自行決定在哪個執行緒呼叫
|
||
`gvfg_read_channel_frame()`。GUI 程式建議每個 channel 使用一個 worker thread,再把 UI 更新送回
|
||
UI thread。
|
||
- `frame.data` 是唯讀的借用 pointer,可能指向原生擷取 buffer 或 SDK 處理後的
|
||
buffer。Zero-copy 設定控制擷取方式;啟用 OSD 時仍可能交付 SDK-owned buffer。
|
||
Pointer 只在對應的 `gvfg_release_channel_frame()` 前有效,資料若要長期保存,必須先複製。
|
||
- 每個 channel 同時最多持有一個 frame。尚未 release 又對同一 channel 呼叫
|
||
`gvfg_read_channel_frame()`,會回傳 `GVFG_ESTATE`。
|
||
- release 時傳回 read 取得的 `gvfg_frame_t`;不要自行修改 frame descriptor 的內容。
|
||
- `gvfg_stop()` 會中止等待並使尚未 release 的 frame 失效。
|
||
- 同一個 handle 的 lifecycle 操作應由應用程式自行序列化;不要同時 open、
|
||
start、stop 或 destroy。
|
||
|
||
Audio 採用相同的 pull 與 ownership 模型:
|
||
|
||
- 建議使用獨立 audio worker thread,避免阻塞 video read 或 UI thread。
|
||
- `gvfg_audio_frame_t.data` 是 SDK-owned PCM,只在對應的
|
||
`gvfg_release_channel_audio_frame()` 前有效。
|
||
- 同一 channel 同時只能持有一個 audio frame;未 release 再 read 會回傳
|
||
`GVFG_ESTATE`。
|
||
- release 時傳回 read 取得的 `gvfg_audio_frame_t`;不要自行修改 frame descriptor 的內容。
|
||
- 若播放或錄音需要在 release 後繼續使用 PCM,Application 必須先複製。
|
||
- Capture 保有自己的交付 buffer;播放副本、queue、同步與輸出由 Playback 管理。
|
||
- 使用 Playback 時,submit 已完成複製後即可 release,Demo 不自行實作音訊調速或同步。
|
||
- 播放錯誤由 Playback API 回傳狀態碼回報,caller 決定停止與重啟。
|
||
輸出裝置故障後,應用程式須處理錯誤並決定是否重新啟動播放。
|
||
|
||
`timeout_ms` 的共同規則:`0` 表示不等待;`GVFG_TIMEOUT_INFINITE` 表示無限等待;
|
||
其他值的單位為毫秒。
|
||
|
||
## 4. 狀態碼
|
||
|
||
| 狀態 | 說明 |
|
||
| --------------- | --------------------------- |
|
||
| `GVFG_OK` | 成功 |
|
||
| `GVFG_EINVAL` | 參數、channel 或 frame token 無效 |
|
||
| `GVFG_ENODEV` | 找不到裝置或裝置無法開啟 |
|
||
| `GVFG_ESTATE` | 呼叫時機或 handle 狀態不正確 |
|
||
| `GVFG_EIO` | 擷取、轉換或其他 I/O 失敗 |
|
||
| `GVFG_ENOTSUP` | 格式或功能不支援 |
|
||
| `GVFG_ETIMEOUT` | 等待逾時 |
|
||
| `GVFG_EBUSY` | 裝置或 capture resource 正在使用中 |
|
||
|
||
公開 API 不暴露底層 capture library 的錯誤型別。所有失敗都會轉成上述
|
||
`GVFG_E*` 狀態;Application 應使用 `status != GVFG_OK` 判斷,不可套用
|
||
Windows `FAILED()`/`SUCCEEDED()`。
|
||
|
||
可用 `gvfg_strerror()` 取得靜態英文說明字串;呼叫端不可釋放該字串。
|
||
|
||
可用 `gvfg_get_version()` 查詢目前實際載入的 `gvfg.dll` 版本。回傳值為
|
||
靜態字串,例如 `"3.0.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(handle)`:停止擷取;重複呼叫仍回傳成功。
|
||
- `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
|
||
|
||
每個已 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。
|
||
|
||
`x/y` 是量測文字框左上角;位置會限制在影像內。文字框本身放不下時,該組暫停顯示,
|
||
另一組與擷取繼續;文字或影像尺寸調整後可恢復。不自動縮字、截字或換行。
|
||
無效字型/文字/組別回傳 `GVFG_EINVAL`;尚未設定的組別不能直接 Show。
|
||
SDK handle 銷毀後,應用程式需自行保存並重設所需的 OSD 設定。
|
||
|
||
完整欄位、字級定義、回傳值與限制見
|
||
[API Reference:OSD](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md#226-osd-字型設定顯示隱藏與清除)。
|
||
|
||
### OSD 呼叫範例
|
||
|
||
以下 C++ 範例假設 `handle` 的 `channel` 已 open。先選擇清單中的實際字型,
|
||
立即複製名稱,再使用相同設定量測與繪製;每一步都檢查回傳值。
|
||
|
||
```cpp
|
||
#include <gvfg_capture.h>
|
||
#include <string>
|
||
|
||
gvfg_status_t configure_osd(gvfg_handle handle, int channel)
|
||
{
|
||
gvfg_osd_font_list_t fonts{};
|
||
auto status = gvfg_get_osd_fonts(&fonts);
|
||
if (status != GVFG_OK) return status;
|
||
if (fonts.count == 0) return GVFG_EINVAL;
|
||
const std::string family(fonts.names[0]);
|
||
|
||
gvfg_channel_osd_config_t first{};
|
||
first.text = "CAMERA 01";
|
||
first.font_family = family.c_str();
|
||
first.font_size_px = 48;
|
||
first.color_rgb = 0xffffff;
|
||
first.x = 32;
|
||
first.y = 32;
|
||
|
||
// Measurement uses text, font and size; it does not open a device.
|
||
uint32_t width = 0, height = 0;
|
||
status = gvfg_measure_osd_text(&first, &width, &height);
|
||
if (status != GVFG_OK) return status;
|
||
status = gvfg_set_channel_osd(handle, channel, 0, &first);
|
||
if (status != GVFG_OK) return status;
|
||
|
||
auto second = first;
|
||
second.text = "ROOM 02";
|
||
second.font_size_px = 32;
|
||
second.color_rgb = 0xffff00;
|
||
second.y = 120;
|
||
return gvfg_set_channel_osd(handle, channel, 1, &second);
|
||
}
|
||
```
|
||
|
||
Set 返回前已複製字串,函式內的 `family` 可正常離開作用域。兩次 Set 各自生效;
|
||
若第二次失敗,第一組仍保持成功設定。下列是之後對第二組的三個獨立操作範例,
|
||
並非必須連續執行的初始化步驟;每個結果仍須檢查。
|
||
|
||
```cpp
|
||
auto status = gvfg_set_channel_osd_visible(handle, channel, 1, 0); // Hide
|
||
if (status != GVFG_OK) return status;
|
||
status = gvfg_set_channel_osd_visible(handle, channel, 1, 1); // Show
|
||
if (status != GVFG_OK) return status;
|
||
status = gvfg_clear_channel_osd(handle, channel, 1); // Clear
|
||
if (status != GVFG_OK) return status;
|
||
```
|
||
|
||
### SDK 3.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 時統計值重設。
|
||
|
||
### Event
|
||
|
||
`gvfg_poll_channel_event(handle, channel, &event, timeout_ms)` 一次取出指定 channel 的事件,只能在 running
|
||
狀態使用。stop 會喚醒阻塞中的 poll,並回傳 `GVFG_ESTATE`。
|
||
|
||
| Event | 應用程式動作 |
|
||
| -------------------------------- | --------------------------- |
|
||
| `GVFG_EVENT_VIDEO_FORMAT_CHANGED` | Lib 的 video format changed event |
|
||
| `GVFG_EVENT_VIDEO_INPUT_PLUGIN` | Lib 的 video input plug-in event |
|
||
| `GVFG_EVENT_VIDEO_INPUT_UNPLUG` | Lib 的 video input unplug event |
|
||
|
||
`event` 使用 `gvfg_event_type_t`;SDK 直接寫入本次取出的事件種類。
|
||
SDK 會在 format changed、input plug-in 或 input unplug event 放入 public queue 前先同步
|
||
signal cache。Application 收到事件後可呼叫 `gvfg_get_channel_signal_status()` 取得對應的新狀態;
|
||
running 期間此查詢讀取 cache,不會再次向 driver 查詢。
|
||
|
||
## 7. GPU 同步轉換
|
||
|
||
GPU 轉換在 `gvfg.dll` 內完成,呼叫是同步的。必須在
|
||
`gvfg_release_channel_frame()` 前轉換;函式返回後 SDK 不保留 source 或 destination
|
||
pointer。
|
||
|
||
支援輸出:
|
||
|
||
| 格式 | 配置需求 |
|
||
| ------------------------- | --------------------------------------- |
|
||
| `GVFG_GPU_OUTPUT_BGRA8` | `row_bytes >= width * 4`;alpha = 255 |
|
||
| `GVFG_GPU_OUTPUT_RGB10A2` | `row_bytes >= width * 4`;alpha = 3 |
|
||
| `GVFG_GPU_OUTPUT_NV12` | width/height 必須為偶數;`row_bytes >= width` |
|
||
|
||
BGRA8/RGB10A2 的 destination 至少為 `row_bytes * height`。NV12 至少為
|
||
`row_bytes * (height + height / 2)`,排列為 Y plane,接著是 interleaved UV
|
||
plane;使用 BT.709 limited range。
|
||
|
||
可使用通用函式 `gvfg_gpu_convert_to_buffer()`,或便利函式:
|
||
|
||
- `gvfg_gpu_convert_to_bgra8()`
|
||
- `gvfg_gpu_convert_to_rgb10a2()`
|
||
- `gvfg_gpu_convert_to_nv12()`
|
||
|
||
### GPU 轉換範例
|
||
|
||
例如,要建立一個與輸入 frame 同尺寸的 BGRA8 destination:
|
||
以下片段放在回傳 `gvfg_status_t` 的函式內,使用 `<limits.h>`、`<stdint.h>`、`<stdlib.h>`;
|
||
`source` 必須有效,且尚未 release。
|
||
|
||
```c
|
||
if (source.width <= 0 || source.height <= 0 || source.width > INT_MAX / 4)
|
||
return GVFG_EINVAL;
|
||
const int row_bytes = source.width * 4;
|
||
const uint64_t buffer_size = (uint64_t)row_bytes * (uint64_t)source.height;
|
||
if (buffer_size > SIZE_MAX)
|
||
return GVFG_EINVAL;
|
||
void *pixels = malloc((size_t)buffer_size);
|
||
if (!pixels)
|
||
return GVFG_EIO;
|
||
|
||
gvfg_gpu_output_buffer_t output = {0};
|
||
output.data = pixels;
|
||
output.data_size = buffer_size;
|
||
output.row_bytes = row_bytes;
|
||
output.pixel_format = GVFG_GPU_OUTPUT_BGRA8;
|
||
|
||
gvfg_status_t status = gvfg_gpu_convert_to_buffer(&source, &output);
|
||
if (status == GVFG_OK) {
|
||
/* 在這裡使用 pixels。 */
|
||
}
|
||
free(pixels);
|
||
return status;
|
||
```
|
||
|
||
配置前須確認尺寸乘法不會 overflow,並檢查 `malloc()` 是否成功。
|
||
不論 conversion 成功或失敗,呼叫端都需在不再使用輸出時釋放自行配置的 `pixels`。
|
||
|
||
## 8. 播放 API
|
||
|
||
`gvfg_playback.dll` 提供影像、音訊播放與影音同步功能。
|
||
擷取仍由應用程式呼叫 `gvfg.dll`。典型流程:
|
||
|
||
```text
|
||
gvfg_playback_create -> attach_window -> default_config -> start
|
||
capture video/audio -> submit_video / submit_audio -> release SDK frame
|
||
停止提交 -> gvfg_playback_stop -> gvfg_playback_destroy
|
||
```
|
||
|
||
submit 成功前已完成資料複製,返回後即可 release SDK frame;失敗時也必須 release,
|
||
時間不連續或輸出錯誤仍須處理;queue 壓力由 Playback 自動降級並略過過時資料,不要求停止擷取。
|
||
stop/reset 會丟棄待播資料,不代表無損排空。
|
||
單張影像用 `gvfg_playback_present_image()`,在已綁定視窗、未 start 的 handle 上同步呼叫。
|
||
詳細模式、master、緩衝與 timestamp 規則見
|
||
[`統一影音播放使用手冊`](GVFG_PLAYBACK_API.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.md`](GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
|