- 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>
13 KiB
GVFG Unified Playback Guide
English | 繁體中文
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.
1. Linking and deployment
| Purpose | MSVC import library | Runtime 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 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 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 |
Image size, format, and graphics adapter information |
gvfg_playback_get_preview_stats() |
gvfg_preview_stats_t |
present_fps, presented_frames, 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.
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. Choosing a mode
Initialize the config with gvfg_playback_default_config() first, then change the fields you need.
Synchronization is on by default. You can change it after create, before start, or during playback:
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.
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 |
Data required | Effective master | Audio output |
|---|---|---|---|
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 |
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.
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. Creating and starting
The following is a C++ initialization example. Get format from the Capture API; do not assume
every input is 48 kHz.
#include "gvfg_capture.h"
#include "gvfg_playback.h"
gvfg_playback_status_t BeginPlayback(
gvfg_playback *out, void *hwnd, const gvfg_audio_format_t &format,
bool enableAudio)
{
if (!out) return GVFG_PLAYBACK_EINVAL;
*out = nullptr;
gvfg_playback p = nullptr;
auto st = gvfg_playback_create(&p);
if (st != GVFG_PLAYBACK_OK) return st;
if (hwnd) st = gvfg_playback_attach_window(p, hwnd);
if (st == GVFG_PLAYBACK_OK) {
gvfg_playback_config_t c{};
gvfg_playback_default_config(&c);
c.mode = enableAudio ? GVFG_PLAYBACK_AUDIO_VIDEO : GVFG_PLAYBACK_VIDEO_ONLY;
if (enableAudio)
c.audio_format = {format.sample_rate,
static_cast<uint16_t>(format.channels),
static_cast<uint16_t>(format.bits_per_sample)};
st = gvfg_playback_start(p, &c);
}
if (st != GVFG_PLAYBACK_OK) {
gvfg_playback_destroy(p);
return st;
}
*out = p;
return GVFG_PLAYBACK_OK;
}
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. Submitting video and releasing
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.
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; // No frame this time, so nothing to release
if (read != GVFG_OK) return false;
gvfg_playback_video_frame_t v{};
v.image.data = source.data;
v.image.data_size = source.data_size;
v.image.width = source.width;
v.image.height = source.height;
v.image.bit_depth = source.bit_depth;
v.image.row_bytes = source.row_stride_bytes;
v.image.frame_id = source.frame_id;
v.timestamp_ns = source.timestamp_ns;
switch (source.pixel_format) {
case GVFG_PIXFMT_YUY2: v.image.pixel_format = GVFG_PREVIEW_PIXFMT_YUY2; break;
case GVFG_PIXFMT_Y210: v.image.pixel_format = GVFG_PREVIEW_PIXFMT_Y210; break;
default: v.image.pixel_format = 0; break;
}
const auto submit = gvfg_playback_submit_video(player, &v);
const auto release = gvfg_release_channel_frame(capture, channel, &source);
return submit == GVFG_PLAYBACK_OK && release == GVFG_OK;
}
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. Submitting PCM and releasing
bool SubmitOneAudio(gvfg_handle capture, int channel, gvfg_playback player)
{
gvfg_audio_frame_t source{};
const auto read = gvfg_read_channel_audio_frame(capture, channel, &source, 100);
if (read == GVFG_ETIMEOUT) return true;
if (read != GVFG_OK) return false;
const auto submit = gvfg_playback_submit_audio(
player, source.data, source.data_size, source.timestamp_ns);
const auto release = gvfg_release_channel_audio_frame(capture, channel, &source);
return submit == GVFG_PLAYBACK_OK && release == GVFG_OK;
}
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. Timestamps and playback latency
- Pass the Capture
timestamp_nsdirectly. 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 thanINT64_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, andmax_video_bytesare advanced capacity limits; change them only for specific memory or pending-capacity requirements. They do not guarantee a fixed playback latency. Seegvfg_playback_config_tin the API Reference for the fields and valid ranges.
7. Threads, reset, and stop
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.
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.
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 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. Single RAW/DICOM images
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. Examples and API Reference
The NO SIGNAL card is built into and displayed by the Playback helper; the application only forwards the Capture signal state:
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);
// Check status; on failure use gvfg_playback_strerror(status).
}
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.
The Customer Demo shows API start/stop, submission, release, events, and basic error handling.
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.
For per-field limits and every function, see Public API Reference, section 5.