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:
+131
-94
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user