- 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>
24 KiB
GVFG Customer API Guide
English | 繁體中文
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 for the full flow. Capture, OSD, and Playback are
separate DLLs, and Capture and Playback use separate handles.
Follow the flow below to integrate capture. For per-parameter definitions and all limits, see the API Reference.
1. Package contents
Core capture:
include/gvfg_capture.h
lib/gvfg.lib
bin/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):
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):
include/gvfg_playback.h
lib/gvfg_playback.lib
bin/gvfg_playback.dll
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. Minimal capture flow
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
-> repeat:
gvfg_read_channel_frame
use / copy / convert the frame
gvfg_release_channel_frame
if audio is enabled, on a separate worker thread repeat:
gvfg_read_channel_audio_frame
use / copy the PCM
gvfg_release_channel_audio_frame
-> gvfg_stop
-> gvfg_destroy
Complete example:
#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;
/* Process, convert, or copy frame.data before release. */
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. Threading and frame ownership
- 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.datais 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 matchinggvfg_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 returnsGVFG_ESTATE. - Pass the
gvfg_frame_treturned 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 uses the same pull and ownership model:
- Use a separate audio worker thread so that audio does not block video reads or the UI thread.
gvfg_audio_frame_t.datais SDK-owned PCM, valid only until the matchinggvfg_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_treturned 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.
Common timeout_ms rule: 0 does not wait; GVFG_TIMEOUT_INFINITE waits indefinitely; other
values are in milliseconds.
4. Status codes
| 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 |
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() returns a static English description; the caller must not free it.
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. Data formats
Native capture formats
| 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 |
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 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 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 contains:
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.
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 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. Public API
Devices and lifecycle
gvfg_enumerate_devices(out_devices, max_devices): enumerate devices. PassNULL, 0to query the count only. Returns the number written or the number available;0when 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;channelmust beGVFG_CHANNEL_0orGVFG_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 returnsGVFG_ETIMEOUTand 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 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.
Frames
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
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.
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.
- 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. - Fill in
gvfg_channel_osd_config_t: text,font_family, size, color, andx/y.textis 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. - Measure with
gvfg_measure_osd_text(&config, &width, &height), then callgvfg_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. - To hide a slot temporarily, call
gvfg_set_channel_osd_visible(..., 0); use1to show it again. Hide/show keeps the slot's settings; onlygvfg_clear_channel_osd()clears the slot, after which it must be set again.
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.
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.
For all fields, size definitions, return values, and limits, see API Reference: OSD.
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.
#include <gvfg_osd.h> // includes 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 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.
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;
Migrating to SDK 3.2.0
- OSD functions and types moved from
gvfg_capture.h/gvfg.dlltogvfg_osd.h/gvfg_osd.dll. Applications that use OSD must includegvfg_osd.h, linkgvfg_osd.lib, and deploygvfg_osd.dll. Function names and parameters are unchanged, but existing applications must be recompiled and relinked. - Added
gvfg_get_channel_hdmi_audio_info().
Migrating to SDK 3.1.0
- Added
gvfg_get_channel_hdmi_info()andgvfg_get_chip_info(). - The full-frame OSD overlay function was renamed to
gvfg_render_osd_frame_bgra(), replacinggvfg_render_osd_bgra().
Migrating to SDK 3.0.0
- OSD
set/cleargained anosd_index; the single configuration became two slots per channel. gvfg_channel_osd_config_tnow uses NUL-terminated strings, dropstext_length, and addsfont_family. The measurement function takes the same configuration; there is no compatibility entry point for the old form.- Public Playback removed
gvfg_playback_stats_tandgvfg_playback_get_stats(). Usegvfg_playback_get_preview_info()andgvfg_playback_get_preview_stats()for general display information and presentation statistics. - Public Playback also removed
gvfg_preview_delivery_stats_tandgvfg_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_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.
After a successful read, release exactly once, whether the PCM goes to playback, to recording, or is discarded.
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.
Queries
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 returnsGVFG_OKwithconnected == 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 andcapture_fpsestimated 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.
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.
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.
| 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 |
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.
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 conversion example
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.
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) {
/* Use pixels here. */
}
free(pixels);
return status;
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. Playback API
gvfg_playback.dll provides video and audio playback and audio/video synchronization. Capture is
still done by the application through gvfg.dll. Typical flow:
gvfg_playback_create -> attach_window -> default_config -> start
capture video/audio -> submit_video / submit_audio -> release SDK frame
stop submitting -> gvfg_playback_stop -> gvfg_playback_destroy
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.
9. Error-handling recommendations
GVFG_ETIMEOUT: while connected, this is usually retryable; also check the signal status and events. AfterGVFG_EVENT_VIDEO_INPUT_UNPLUG, do not poll the read API in a tight loop; wait forGVFG_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, loggvfg_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.
Full API Reference
For every public constant, type, struct field, function parameter, and return value, see
GVFG_CUSTOMER_API_REFERENCE.md.