Add dual-slot font-selectable OSD and privatize playback diagnostics for SDK 3.0.0

- replace the single-overlay API with two independently configured OSD slots per channel, simplify NUL-terminated text/font settings, and add explicit visibility controls that preserve cached glyphs separately from Clear

- enumerate installed Windows font families as an SDK-owned UTF-8 list without callbacks or caller-side free, refresh installed fonts on demand, and use the selected family consistently for measurement and rendering with invalid/missing-font rejection

- retain per-slot YUV and A8 mask caches, blend slot 1 over slot 0 in one GPU dispatch/readback, preserve hidden surfaces, and skip oversized slots independently while capture and the other slot continue

- move detailed playback core statistics to a private Debug-only header/export, remove the public legacy statistics query and compatibility layouts, and retain public preview/delivery statistics

- bump the SDK major version to 3.0.0 for the breaking OSD and playback API changes and document matching header, import-library and runtime deployment requirements

- refresh the capture/playback guides, internal build notes and API reference, document all 51 public Capture/Playback functions, add checked OSD usage examples, and regenerate the branded 23-page PDF

Validation: git diff --cached --check and public API documentation coverage checks passed. The regenerated PDF passed text/content checks and visual review of its rendered pages, including the OSD types, API contracts and examples. Earlier session SDK Release compilation and synthetic YUY2/Y210 blending checks passed; no new build, hardware capture, FPGA upload or long-duration runtime validation was performed during this commit pass.
This commit is contained in:
Mark.lin
2026-10-29 09:02:54 +08:00
parent bfa9397f6b
commit c8b2d0608a
24 changed files with 796 additions and 482 deletions
+2 -2
View File
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.16)
project(gvfg_sdk LANGUAGES CXX) project(gvfg_sdk LANGUAGES CXX)
# Version policy: new features bump MINOR and reset PATCH; bug fixes bump PATCH. # Version policy: breaking public API changes bump MAJOR; features bump MINOR; fixes bump PATCH.
set(GVFG_SDK_VERSION "2.1.1") set(GVFG_SDK_VERSION "3.0.0")
option(GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE option(GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
"UNSAFE local experiment: write OSD into driver zero-copy buffers" OFF) "UNSAFE local experiment: write OSD into driver zero-copy buffers" OFF)
+14 -8
View File
@@ -6,12 +6,12 @@ live video frames, communicate with the driver, or present a preview. The
library is linked into `gvfg.dll`; it is not installed or shipped as a library is linked into `gvfg.dll`; it is not installed or shipped as a
separate customer DLL. separate customer DLL.
The initial API supports: The helper supports:
- YUY2 and Y210 output - YUY2 and Y210 output
- printable ASCII text, up to 32 characters - printable ASCII text, up to 32 characters
- Arial-preferred font with DirectWrite fallback, configurable pixel size, - caller-selected installed font family (UTF-8), configurable pixel size,
RGB color, and `(x, y)` position RGB color, and `(x, y)` position; missing families are rejected
- one non-wrapping line, with a shared DirectWrite layout for measurement and - one non-wrapping line, with a shared DirectWrite layout for measurement and
rendering at 96 DPI rendering at 96 DPI
- BT.709 limited-range RGB-to-YUV conversion - BT.709 limited-range RGB-to-YUV conversion
@@ -32,14 +32,20 @@ device. Font size must be non-zero; the SDK does not impose the viewer's
to `[0, frame width - text width]` and `[0, frame height - text height]` so the to `[0, frame width - text width]` and `[0, frame height - text height]` so the
complete box remains visible. The internal render function returns `EINVAL` complete box remains visible. The internal render function returns `EINVAL`
if the text box is larger than the frame. For live capture, the GPU processor if the text box is larger than the frame. For live capture, the GPU processor
detects that case before rendering and temporarily bypasses OSD while keeping detects that case before rendering and temporarily skips only the oversized slot,
capture and the requested OSD settings active. It retries when the settings, keeping capture, the other slot, and the saved settings active. It retries when the settings,
frame dimensions, or pixel format change. It does not shrink, truncate, or wrap frame dimensions, or pixel format change. It does not shrink, truncate, or wrap
the text to make it fit. the text to make it fit.
For live SDK OSD, `GpuOsdProcessor` caches the non-zero mask bounds, aligned For live SDK OSD, each channel owns two independently configured slots. Each
to complete YUV422 pixel pairs. Only this rectangle is uploaded, blended, slot caches its YUV and A8 mask. The shared ROI is the union of both slots'
and read back each frame. For non-zero-copy acquisition, the backend explicitly non-zero mask bounds, aligned to complete YUV422 pixel pairs. A single compute
dispatch blends slot 0 then slot 1, followed by one readback. Slot textures are
uploaded on settings/geometry changes, not every frame. Hidden slots retain
their rasterized surfaces and textures; shader visibility bits implement show/hide
without rebuilding. If all slots are hidden, no blend or readback is performed.
Clearing a slot discards its configuration and surfaces. An oversized slot is
skipped independently, leaving capture and the other slot active. For non-zero-copy acquisition, the backend explicitly
grants writable access to its currently held SDK-owned capture buffer: the grants writable access to its currently held SDK-owned capture buffer: the
GPU result replaces only that rectangle in place, retaining the original GPU result replaces only that rectangle in place, retaining the original
stride and size. No second full-frame copy or output-buffer resize is needed. stride and size. No second full-frame copy or output-buffer resize is needed.
+6 -1
View File
@@ -26,7 +26,7 @@ typedef enum gvfg_osd_pixel_format_t
} gvfg_osd_pixel_format_t; } gvfg_osd_pixel_format_t;
/* /*
* Generates an off-line OSD surface using the Arial system font. Text is * Generates an off-line OSD surface using the requested installed system font. Text is
* restricted to printable ASCII and at most GVFG_OSD_MAX_TEXT_CHARACTERS * restricted to printable ASCII and at most GVFG_OSD_MAX_TEXT_CHARACTERS
* characters on one line without wrapping. color_rgb is 0xRRGGBB. * characters on one line without wrapping. color_rgb is 0xRRGGBB.
* x/y identify the top-left of the conservative measured text box (including * x/y identify the top-left of the conservative measured text box (including
@@ -42,6 +42,7 @@ typedef struct gvfg_osd_config_t
uint32_t height; uint32_t height;
uint32_t pixel_format; uint32_t pixel_format;
const char *text; const char *text;
const char *font_family; /* UTF-8, NUL-terminated. */
uint32_t text_length; uint32_t text_length;
int32_t x; int32_t x;
int32_t y; int32_t y;
@@ -73,9 +74,13 @@ gvfg_osd_status_t gvfg_osd_measure(
const char *text, const char *text,
uint32_t text_length, uint32_t text_length,
uint32_t font_size_px, uint32_t font_size_px,
const char *font_family,
uint32_t *out_width, uint32_t *out_width,
uint32_t *out_height); uint32_t *out_height);
/* SDK-owned snapshot, invalidated by the next call. Serialize call/read access. */
gvfg_osd_status_t gvfg_osd_get_fonts(uint32_t *out_count, const char *const **out_names);
gvfg_osd_status_t gvfg_osd_render( gvfg_osd_status_t gvfg_osd_render(
gvfg_osd_handle handle, gvfg_osd_handle handle,
const gvfg_osd_config_t *config, const gvfg_osd_config_t *config,
+144 -16
View File
@@ -10,22 +10,38 @@
#include <cstring> #include <cstring>
#include <limits> #include <limits>
#include <new> #include <new>
#include <mutex>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;
namespace namespace
{ {
struct MeasuredTextLayout
{
ComPtr<IDWriteTextLayout> layout;
uint32_t width = 0;
uint32_t height = 0;
float drawOffsetX = 0;
float drawOffsetY = 0;
};
struct OsdContext struct OsdContext
{ {
ComPtr<IWICImagingFactory> wic; ComPtr<IWICImagingFactory> wic;
ComPtr<ID2D1Factory> d2d; ComPtr<ID2D1Factory> d2d;
ComPtr<IDWriteFactory> dwrite; ComPtr<IDWriteFactory> dwrite;
bool ownsComInitialization = false; bool ownsComInitialization = false;
std::string cachedText;
std::string cachedFontFamily;
uint32_t cachedFontSizePx = 0;
MeasuredTextLayout cachedLayout;
~OsdContext() ~OsdContext()
{ {
cachedLayout.layout.Reset();
dwrite.Reset(); dwrite.Reset();
d2d.Reset(); d2d.Reset();
wic.Reset(); wic.Reset();
@@ -85,25 +101,59 @@ std::wstring widenAscii(const char *text, uint32_t length)
return result; return result;
} }
struct MeasuredTextLayout bool utf8FontName(const char *name, std::wstring &wide)
{ {
ComPtr<IDWriteTextLayout> layout; if (!name || !*name)
uint32_t width = 0; return false;
uint32_t height = 0; // Bound input scans and reject malformed UTF-8 rather than substitute.
float drawOffsetX = 0; const size_t length = strnlen_s(name, 4096);
float drawOffsetY = 0; if (length == 4096)
}; return false;
const int count = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
name, static_cast<int>(length), nullptr, 0);
if (count <= 0)
return false;
wide.resize(count);
return MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, name,
static_cast<int>(length), wide.data(), count) == count;
}
gvfg_osd_status_t createTextLayout(OsdContext &context, const char *text, gvfg_osd_status_t createTextLayout(OsdContext &context, const char *text,
uint32_t textLength, uint32_t fontSizePx, uint32_t textLength, uint32_t fontSizePx, const char *fontFamily,
MeasuredTextLayout &result) MeasuredTextLayout &result)
{ {
if (!validAscii(text, textLength) || fontSizePx == 0) if (!validAscii(text, textLength) || fontSizePx == 0)
return GVFG_OSD_EINVAL; return GVFG_OSD_EINVAL;
std::wstring wideFamily;
if (!utf8FontName(fontFamily, wideFamily))
return GVFG_OSD_EINVAL;
// measure() and render() share the most recent successful layout.
// Position, color and output format do not affect text layout.
if (context.cachedLayout.layout && context.cachedFontSizePx == fontSizePx &&
context.cachedFontFamily == fontFamily &&
context.cachedText.size() == textLength &&
context.cachedText.compare(0, textLength, text, textLength) == 0)
{
result = context.cachedLayout;
return GVFG_OSD_OK;
}
std::string cacheKey(text, textLength);
ComPtr<IDWriteFontCollection> fonts;
HRESULT hr = context.dwrite->GetSystemFontCollection(&fonts, TRUE);
if (FAILED(hr))
return GVFG_OSD_ERENDER;
UINT32 familyIndex = 0;
BOOL exists = FALSE;
if (FAILED(fonts->FindFamilyName(wideFamily.c_str(), &familyIndex, &exists)))
return GVFG_OSD_ERENDER;
if (!exists)
return GVFG_OSD_EINVAL;
ComPtr<IDWriteTextFormat> format; ComPtr<IDWriteTextFormat> format;
HRESULT hr = context.dwrite->CreateTextFormat( hr = context.dwrite->CreateTextFormat(
L"Arial", nullptr, DWRITE_FONT_WEIGHT_NORMAL, wideFamily.c_str(), fonts.Get(), DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
static_cast<float>(fontSizePx), L"en-us", &format); static_cast<float>(fontSizePx), L"en-us", &format);
if (FAILED(hr) || if (FAILED(hr) ||
@@ -168,6 +218,10 @@ gvfg_osd_status_t createTextLayout(OsdContext &context, const char *text,
result.height = static_cast<uint32_t>(height); result.height = static_cast<uint32_t>(height);
result.drawOffsetX = static_cast<float>(-left); result.drawOffsetX = static_cast<float>(-left);
result.drawOffsetY = static_cast<float>(-top); result.drawOffsetY = static_cast<float>(-top);
context.cachedFontFamily = fontFamily;
context.cachedText.swap(cacheKey);
context.cachedFontSizePx = fontSizePx;
context.cachedLayout = result;
return GVFG_OSD_OK; return GVFG_OSD_OK;
} }
@@ -178,7 +232,7 @@ gvfg_osd_status_t renderMask(OsdContext &context,
{ {
MeasuredTextLayout textLayout; MeasuredTextLayout textLayout;
const gvfg_osd_status_t layoutStatus = createTextLayout( const gvfg_osd_status_t layoutStatus = createTextLayout(
context, config.text, config.text_length, config.font_size_px, textLayout); context, config.text, config.text_length, config.font_size_px, config.font_family, textLayout);
if (layoutStatus != GVFG_OSD_OK) if (layoutStatus != GVFG_OSD_OK)
return layoutStatus; return layoutStatus;
if (textLayout.width > config.width || textLayout.height > config.height) if (textLayout.width > config.width || textLayout.height > config.height)
@@ -188,14 +242,14 @@ gvfg_osd_status_t renderMask(OsdContext &context,
ComPtr<IWICBitmap> bitmap; ComPtr<IWICBitmap> bitmap;
HRESULT hr = context.wic->CreateBitmap(config.width, config.height, HRESULT hr = context.wic->CreateBitmap(config.width, config.height,
GUID_WICPixelFormat32bppPBGRA, GUID_WICPixelFormat8bppAlpha,
WICBitmapCacheOnLoad, &bitmap); WICBitmapCacheOnLoad, &bitmap);
if (FAILED(hr)) if (FAILED(hr))
return GVFG_OSD_ERENDER; return GVFG_OSD_ERENDER;
D2D1_RENDER_TARGET_PROPERTIES properties = D2D1::RenderTargetProperties( D2D1_RENDER_TARGET_PROPERTIES properties = D2D1::RenderTargetProperties(
D2D1_RENDER_TARGET_TYPE_SOFTWARE, D2D1_RENDER_TARGET_TYPE_SOFTWARE,
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1::PixelFormat(DXGI_FORMAT_A8_UNORM,
D2D1_ALPHA_MODE_PREMULTIPLIED), D2D1_ALPHA_MODE_PREMULTIPLIED),
96.0f, 96.0f); 96.0f, 96.0f);
ComPtr<ID2D1RenderTarget> target; ComPtr<ID2D1RenderTarget> target;
@@ -235,8 +289,8 @@ gvfg_osd_status_t renderMask(OsdContext &context,
{ {
const uint8_t *sourceRow = source + static_cast<size_t>(y) * sourceStride; const uint8_t *sourceRow = source + static_cast<size_t>(y) * sourceStride;
uint8_t *destinationRow = destination + static_cast<size_t>(y) * destinationStride; uint8_t *destinationRow = destination + static_cast<size_t>(y) * destinationStride;
for (uint32_t x = 0; x < config.width; ++x) // The A8 bitmap already contains one coverage byte per pixel.
destinationRow[x] = sourceRow[x * 4u + 3u]; std::memcpy(destinationRow, sourceRow, config.width);
} }
return GVFG_OSD_OK; return GVFG_OSD_OK;
} }
@@ -339,6 +393,7 @@ void gvfg_osd_destroy(gvfg_osd_handle handle)
gvfg_osd_status_t gvfg_osd_measure(gvfg_osd_handle handle, gvfg_osd_status_t gvfg_osd_measure(gvfg_osd_handle handle,
const char *text, uint32_t text_length, const char *text, uint32_t text_length,
uint32_t font_size_px, uint32_t font_size_px,
const char *font_family,
uint32_t *out_width, uint32_t *out_height) uint32_t *out_width, uint32_t *out_height)
{ {
if (out_width) if (out_width)
@@ -352,7 +407,7 @@ gvfg_osd_status_t gvfg_osd_measure(gvfg_osd_handle handle,
{ {
MeasuredTextLayout layout; MeasuredTextLayout layout;
const gvfg_osd_status_t status = createTextLayout( const gvfg_osd_status_t status = createTextLayout(
*static_cast<OsdContext *>(handle), text, text_length, font_size_px, layout); *static_cast<OsdContext *>(handle), text, text_length, font_size_px, font_family, layout);
if (status != GVFG_OSD_OK) if (status != GVFG_OSD_OK)
return status; return status;
*out_width = layout.width; *out_width = layout.width;
@@ -369,6 +424,79 @@ gvfg_osd_status_t gvfg_osd_measure(gvfg_osd_handle handle,
} }
} }
gvfg_osd_status_t gvfg_osd_get_fonts(uint32_t *out_count, const char *const **out_names)
{
if (!out_count || !out_names)
return GVFG_OSD_EINVAL;
*out_count = 0;
*out_names = nullptr;
static std::mutex mutex;
static std::vector<std::string> names;
static std::vector<const char *> pointers;
std::lock_guard<std::mutex> lock(mutex);
names.clear();
pointers.clear();
try
{
ComPtr<IDWriteFactory> factory;
if (FAILED(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
reinterpret_cast<IUnknown **>(factory.GetAddressOf()))))
return GVFG_OSD_ERENDER;
ComPtr<IDWriteFontCollection> fonts;
if (FAILED(factory->GetSystemFontCollection(&fonts, TRUE)))
return GVFG_OSD_ERENDER;
wchar_t locale[LOCALE_NAME_MAX_LENGTH] = L"en-us";
GetUserDefaultLocaleName(locale, LOCALE_NAME_MAX_LENGTH);
for (UINT32 i = 0; i < fonts->GetFontFamilyCount(); ++i)
{
ComPtr<IDWriteFontFamily> family;
ComPtr<IDWriteLocalizedStrings> localized;
if (FAILED(fonts->GetFontFamily(i, &family)) ||
FAILED(family->GetFamilyNames(&localized)))
return GVFG_OSD_ERENDER;
UINT32 index = 0;
BOOL exists = FALSE;
if (FAILED(localized->FindLocaleName(locale, &index, &exists)))
return GVFG_OSD_ERENDER;
if (!exists && FAILED(localized->FindLocaleName(L"en-us", &index, &exists)))
return GVFG_OSD_ERENDER;
if (!exists)
index = 0;
UINT32 length = 0;
if (FAILED(localized->GetStringLength(index, &length)))
return GVFG_OSD_ERENDER;
std::wstring wide(length + 1, L'\0');
if (FAILED(localized->GetString(index, wide.data(), length + 1)))
return GVFG_OSD_ERENDER;
// Verify that the family can be used by this renderer.
ComPtr<IDWriteTextFormat> format;
if (FAILED(factory->CreateTextFormat(wide.c_str(), fonts.Get(),
DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, 48.0f, L"en-us", &format)))
continue;
const int bytes = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS,
wide.data(), static_cast<int>(length), nullptr, 0, nullptr, nullptr);
if (bytes <= 0)
continue;
std::string name(bytes, '\0');
if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wide.data(),
static_cast<int>(length), name.data(), bytes, nullptr, nullptr) != bytes)
return GVFG_OSD_ERENDER;
names.push_back(std::move(name));
}
std::sort(names.begin(), names.end());
names.erase(std::unique(names.begin(), names.end()), names.end());
pointers.reserve(names.size());
for (const auto &name : names)
pointers.push_back(name.c_str());
*out_count = static_cast<uint32_t>(pointers.size());
*out_names = pointers.empty() ? nullptr : pointers.data();
return GVFG_OSD_OK;
}
catch (const std::bad_alloc &) { return GVFG_OSD_ENOMEM; }
catch (...) { return GVFG_OSD_ERENDER; }
}
gvfg_osd_status_t gvfg_osd_render(gvfg_osd_handle handle, gvfg_osd_status_t gvfg_osd_render(gvfg_osd_handle handle,
const gvfg_osd_config_t *config, const gvfg_osd_config_t *config,
const gvfg_osd_output_t *output) const gvfg_osd_output_t *output)
@@ -5,6 +5,7 @@ add_library(gvfg_playback SHARED
include/gvfg_playback.h include/gvfg_playback.h
src/gvfg_playback.cpp src/gvfg_playback.cpp
src/playback_timing.h src/playback_timing.h
src/playback_debug.h
src/signal_card.h src/signal_card.h
src/signal_card.cpp src/signal_card.cpp
src/signal_card.rc src/signal_card.rc
@@ -20,7 +21,8 @@ target_include_directories(gvfg_playback
${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_audio_playback/src ${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_audio_playback/src
${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_preview/src ${CMAKE_CURRENT_SOURCE_DIR}/../gvfg_preview/src
) )
target_compile_definitions(gvfg_playback PRIVATE GVFG_PLAYBACK_BUILD) target_compile_definitions(gvfg_playback PRIVATE GVFG_PLAYBACK_BUILD
GVFG_INTERNAL_DIAGNOSTICS=$<IF:$<CONFIG:Debug>,1,0>)
target_link_libraries(gvfg_playback PRIVATE gvfg_audio_playback gvfg_preview user32 gdi32 comctl32) target_link_libraries(gvfg_playback PRIVATE gvfg_audio_playback gvfg_preview user32 gdi32 comctl32)
if(MSVC) if(MSVC)
target_compile_options(gvfg_playback PRIVATE /utf-8 /EHsc) target_compile_options(gvfg_playback PRIVATE /utf-8 /EHsc)
+8 -6
View File
@@ -1,6 +1,6 @@
# Playback 維護與同步實作 # Playback 維護與同步實作
SDK 2.1.1;客戶整合從 [公開播放手冊](../../../docs/GVFG_PLAYBACK_API.md) 開始, SDK 3.0.0;客戶整合從 [公開播放手冊](../../../docs/GVFG_PLAYBACK_API.md) 開始,
逐參數契約見 [API Reference](../../../docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。 逐參數契約見 [API Reference](../../../docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md)。
本文件供 SDK 維護者,說明目前實作,不作為 Customer Demo 的除錯畫面需求。 本文件供 SDK 維護者,說明目前實作,不作為 Customer Demo 的除錯畫面需求。
@@ -146,9 +146,11 @@ core 非同步失敗保存在 last_error,worker 暫停,後續 submit 回報
stop/reset 取消 queue,不是無損 drain。reset 沿用舊 config,音訊格式改變應明確 stop/start 新設定。 stop/reset 取消 queue,不是無損 drain。reset 沿用舊 config,音訊格式改變應明確 stop/start 新設定。
呼叫端先停止/join read producers、release token,再停止 Playback 與 Capture。 呼叫端先停止/join read producers、release token,再停止 Playback 與 Capture。
2.0.2 stats 尾端新增 video_dropped;2.0.4 追加 sync_degraded、sync_fallbacks、audio_dropped_frames。 詳細統計位於私有 `src/playback_debug.h`,不安裝到客戶套件。核心保留診斷計數與同步狀態。
getter 明確接受目前大小、2.0.2/2.0.3 大小及 2.0.0/2.0.1 原始大小, 僅 Debug DLL 匯出 `gvfg_playback_debug_get_stats()`;內部工具須定義
只回填 caller 提供的範圍;不是對任意 struct_size 都相容。config 仍要求目前完整大小。 `GVFG_INTERNAL_DIAGNOSTICS=1` 並使用同一版私有標頭與 MSVC Debug 匯入庫。
診斷結構不提供穩定 ABI 或舊大小相容;Release DLL 不匯出診斷查詢。
config 仍要求目前完整的 struct_size。
公開 API/資料變更需同步標頭、匯入庫、DLL、Reference 與 Demo,避免混版。 公開 API/資料變更需同步標頭、匯入庫、DLL、Reference 與 Demo,避免混版。
## 10. 既有驗證範圍 ## 10. 既有驗證範圍
@@ -157,7 +159,7 @@ getter 明確接受目前大小、2.0.2/2.0.3 大小及 2.0.0/2.0.1 原始
既有實際 Qt Sample 測試為 CH0 1080p YUY2、48 kHz stereo PCM16、External master、120 秒, 既有實際 Qt Sample 測試為 CH0 1080p YUY2、48 kHz stereo PCM16、External master、120 秒,
含視窗/全螢幕切換:約 60 fps,queue 未持續增長;7166 張輸入,processed 7160、presented 7158、dropped 2。 含視窗/全螢幕切換:約 60 fps,queue 未持續增長;7166 張輸入,processed 7160、presented 7158、dropped 2。
其餘待播 frame 在 stop 時取消。 其餘待播 frame 在 stop 時取消。
慢速輸出模擬為 60 fps 輸入、30 ms/張輸出與 busy:300 張輸入,略過 159、呈現 134、最大 queue 8、無拒收;舊 stats guard 通過。 慢速輸出模擬為 60 fps 輸入、30 ms/張輸出與 busy:300 張輸入,略過 159、呈現 134、最大 queue 8、無拒收。
2.0.3 的決定性模擬使用實際 Playback core,僅替換時鐘/worker 步進與輸出後端: 2.0.3 的決定性模擬使用實際 Playback core,僅替換時鐘/worker 步進與輸出後端:
舊版在 audio source 慢 500 ppm 時,910.084 秒出現 buffering、video queue 32、EQUEUE_FULL。 舊版在 audio source 慢 500 ppm 時,910.084 秒出現 buffering、video queue 32、EQUEUE_FULL。
@@ -172,7 +174,7 @@ Audio master 遇到來源較慢時仍會耗盡既有緩衝並重新緩衝,未
2.0.4 決定性 core 模擬通過:完全無音訊、延後出現、五秒斷音、五秒停影、 2.0.4 決定性 core 模擬通過:完全無音訊、延後出現、五秒斷音、五秒停影、
來源半速/兩倍速及恢復、各 master、video-only/audio-only、GPU worker 暫停且 video queue 只有兩張。 來源半速/兩倍速及恢復、各 master、video-only/audio-only、GPU worker 暫停且 video queue 只有兩張。
檢查無拒收、容量不超限、影像持續消化、來源恢復後退出降級,以及兩種既有 stats 大小的尾端 guard。 檢查無拒收、容量不超限、影像持續消化、來源恢復後退出降級。
後端模擬 reset 延遲五毫秒,驗證 reset 完成前不會餵入新 mapping。 後端模擬 reset 延遲五毫秒,驗證 reset 完成前不會餵入新 mapping。
正常 ±500 ppm 各模擬兩小時,沒有降級,video queue 最大 6~7。 正常 ±500 ppm 各模擬兩小時,沒有降級,video queue 最大 6~7。
@@ -13,7 +13,6 @@ EXPORTS
gvfg_playback_reset_timeline gvfg_playback_reset_timeline
gvfg_playback_stop gvfg_playback_stop
gvfg_playback_destroy gvfg_playback_destroy
gvfg_playback_get_stats
gvfg_playback_get_preview_info gvfg_playback_get_preview_info
gvfg_playback_get_preview_stats gvfg_playback_get_preview_stats
gvfg_playback_get_delivery_stats gvfg_playback_get_delivery_stats
@@ -59,30 +59,6 @@ typedef struct {
gvfg_preview_frame_t image; gvfg_preview_frame_t image;
uint64_t timestamp_ns; /* Common monotonic delivery clock, NOT UTC. */ uint64_t timestamp_ns; /* Common monotonic delivery clock, NOT UTC. */
} gvfg_playback_video_frame_t; } gvfg_playback_video_frame_t;
typedef struct {
uint32_t struct_size;
int running;
int buffering;
gvfg_playback_status_t last_error;
uint64_t video_submitted;
uint64_t video_processed; /* Includes hidden frames and counted late/skipped previews. */
uint64_t video_presented;
uint64_t audio_submitted;
uint64_t queue_rejections;
uint64_t rebuffer_count;
uint64_t video_queue_bytes;
uint32_t video_queue_frames;
double audio_queue_ms;
uint64_t video_timestamp_ns;
uint64_t audio_timestamp_ns; /* Estimated output position, NOT acoustic time. */
int64_t av_difference_ns; /* audio - video; valid only with both clocks. */
double audio_rate_ratio;
uint64_t video_dropped; /* Late or GPU-busy preview frames; never audio/recording loss. */
int sync_degraded; /* Independent best-effort playback; capture may continue. */
uint64_t sync_fallbacks;
uint64_t audio_dropped_frames; /* PCM frames discarded from the core queue, not device padding. */
} gvfg_playback_stats_t;
GVFG_PLAYBACK_API void gvfg_playback_default_config(gvfg_playback_config_t *config); GVFG_PLAYBACK_API void gvfg_playback_default_config(gvfg_playback_config_t *config);
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_create(gvfg_playback *out); GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_create(gvfg_playback *out);
/* A null HWND hides video while preserving its timeline. Attach on HWND thread. */ /* A null HWND hides video while preserving its timeline. Attach on HWND thread. */
@@ -127,7 +103,6 @@ GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_set_sync_enabled(gvfg_pla
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_reset_timeline(gvfg_playback p); GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_reset_timeline(gvfg_playback p);
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_stop(gvfg_playback p); GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_stop(gvfg_playback p);
GVFG_PLAYBACK_API void gvfg_playback_destroy(gvfg_playback p); GVFG_PLAYBACK_API void gvfg_playback_destroy(gvfg_playback p);
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_stats(gvfg_playback p, gvfg_playback_stats_t *stats);
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_preview_info(gvfg_playback p, gvfg_preview_info_t *info); GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_preview_info(gvfg_playback p, gvfg_preview_info_t *info);
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_preview_stats(gvfg_playback p, gvfg_preview_stats_t *stats); GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_preview_stats(gvfg_playback p, gvfg_preview_stats_t *stats);
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_delivery_stats(gvfg_playback p, gvfg_preview_delivery_stats_t *stats); GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_get_delivery_stats(gvfg_playback p, gvfg_preview_delivery_stats_t *stats);
@@ -2,6 +2,7 @@
#include "audio_output_internal.h" #include "audio_output_internal.h"
#include "preview_output_internal.h" #include "preview_output_internal.h"
#include "playback_timing.h" #include "playback_timing.h"
#include "playback_debug.h"
#include "signal_card.h" #include "signal_card.h"
#include <windows.h> #include <windows.h>
#include <algorithm> #include <algorithm>
@@ -9,8 +10,6 @@
#include <chrono> #include <chrono>
#include <cmath> #include <cmath>
#include <condition_variable> #include <condition_variable>
#include <cstring>
#include <cstddef>
#include <cstdlib> #include <cstdlib>
#include <deque> #include <deque>
#include <limits> #include <limits>
@@ -49,7 +48,7 @@ struct gvfg_playback_t {
gvfg_preview_handle preview = nullptr; gvfg_preview_handle preview = nullptr;
gvfg_audio_player audio = nullptr; gvfg_audio_player audio = nullptr;
gvfg_playback_config_t config{}; gvfg_playback_config_t config{};
gvfg_playback_stats_t stats{}; gvfg_playback_debug_stats_t stats{};
std::deque<Video> videos; std::deque<Video> videos;
std::deque<Audio> audios; std::deque<Audio> audios;
uint64_t video_bytes = 0, audio_bytes = 0; uint64_t video_bytes = 0, audio_bytes = 0;
@@ -376,7 +375,7 @@ gvfg_playback_status_t gvfg_playback_start(gvfg_playback p, const gvfg_playback_
p->config = *c; p->config = *c;
if (c->mode == GVFG_PLAYBACK_VIDEO_ONLY) p->config.master = GVFG_PLAYBACK_MASTER_EXTERNAL; if (c->mode == GVFG_PLAYBACK_VIDEO_ONLY) p->config.master = GVFG_PLAYBACK_MASTER_EXTERNAL;
if (c->mode == GVFG_PLAYBACK_AUDIO_ONLY) p->config.master = GVFG_PLAYBACK_MASTER_AUDIO; if (c->mode == GVFG_PLAYBACK_AUDIO_ONLY) p->config.master = GVFG_PLAYBACK_MASTER_AUDIO;
p->stats = {}; p->stats.struct_size = sizeof(p->stats); p->stats.buffering = 1; p->stats = {}; p->stats.buffering = 1;
p->stats.running = 1; p->stats.audio_rate_ratio = 1; p->stats.running = 1; p->stats.audio_rate_ratio = 1;
p->stopping = false; p->first_video = p->last_video = p->first_audio = p->audio_end = 0; p->stopping = false; p->first_video = p->last_video = p->first_audio = p->audio_end = 0;
p->last_audio_delivery = p->video_bytes = p->audio_bytes = 0; p->last_audio_delivery = p->video_bytes = p->audio_bytes = 0;
@@ -579,15 +578,11 @@ void gvfg_playback_destroy(gvfg_playback p) {
gvfg_playback_stop(p); p->signal_card.attach(nullptr); gvfg_playback_stop(p); p->signal_card.attach(nullptr);
gvfg_preview_destroy(p->preview); delete p; gvfg_preview_destroy(p->preview); delete p;
} }
gvfg_playback_status_t gvfg_playback_get_stats(gvfg_playback p, gvfg_playback_stats_t *s) { #if GVFG_INTERNAL_DIAGNOSTICS
// Keep 2.0.0/2.0.1 callers with the original struct size ABI-compatible. gvfg_playback_status_t gvfg_playback_debug_get_stats(gvfg_playback p, gvfg_playback_debug_stats_t *s) {
constexpr uint32_t legacy_size = offsetof(gvfg_playback_stats_t, video_dropped); if (!p || !s) return GVFG_PLAYBACK_EINVAL;
constexpr uint32_t previous_size = offsetof(gvfg_playback_stats_t, sync_degraded);
if (!p || !s || (s->struct_size != sizeof(*s) && s->struct_size != legacy_size &&
s->struct_size != previous_size)) return GVFG_PLAYBACK_EINVAL;
const uint32_t requested_size = s->struct_size;
std::lock_guard<std::mutex> lock(p->mutex); std::lock_guard<std::mutex> lock(p->mutex);
auto result = p->stats; result.struct_size = requested_size; auto result = p->stats;
result.video_queue_bytes = p->video_bytes; result.video_queue_frames = static_cast<uint32_t>(p->videos.size()); result.video_queue_bytes = p->video_bytes; result.video_queue_frames = static_cast<uint32_t>(p->videos.size());
if (p->has_audio() && p->audio) { if (p->has_audio() && p->audio) {
const auto pos = audio_output_position(p->audio); const auto pos = audio_output_position(p->audio);
@@ -595,9 +590,10 @@ gvfg_playback_status_t gvfg_playback_get_stats(gvfg_playback p, gvfg_playback_st
result.audio_queue_ms = (static_cast<double>(p->audio_bytes) / (p->config.audio_format.channels * 2) + pos.queued_frames) * result.audio_queue_ms = (static_cast<double>(p->audio_bytes) / (p->config.audio_format.channels * 2) + pos.queued_frames) *
1000.0 / p->config.audio_format.sample_rate; 1000.0 / p->config.audio_format.sample_rate;
} }
std::memcpy(s, &result, requested_size); *s = result;
return GVFG_PLAYBACK_OK; return GVFG_PLAYBACK_OK;
} }
#endif
gvfg_playback_status_t gvfg_playback_get_preview_info(gvfg_playback p, gvfg_preview_info_t *s) { gvfg_playback_status_t gvfg_playback_get_preview_info(gvfg_playback p, gvfg_preview_info_t *s) {
if (!p || !s) return GVFG_PLAYBACK_EINVAL; if (!p || !s) return GVFG_PLAYBACK_EINVAL;
@@ -0,0 +1,38 @@
#pragma once
/* Internal playback diagnostics. Do not install or ship this header.
* The query is exported only by Debug builds. No stable diagnostic ABI. */
#include "gvfg_playback.h"
typedef struct {
int running;
int buffering;
gvfg_playback_status_t last_error;
uint64_t video_submitted;
uint64_t video_processed; /* Includes hidden and skipped preview frames. */
uint64_t video_presented; /* Accepted by Present, not physical scanout. */
uint64_t audio_submitted;
uint64_t rebuffer_count;
uint64_t video_queue_bytes; /* Includes the in-flight CPU copy. */
uint32_t video_queue_frames;
double audio_queue_ms;
uint64_t video_timestamp_ns;
uint64_t audio_timestamp_ns; /* Estimated output position, not acoustic time. */
int64_t av_difference_ns; /* audio - video; requires both clocks. */
double audio_rate_ratio;
uint64_t video_dropped;
int sync_degraded;
uint64_t sync_fallbacks;
uint64_t audio_dropped_frames; /* Core queue only; not device padding. */
} gvfg_playback_debug_stats_t;
#if GVFG_INTERNAL_DIAGNOSTICS
#ifdef __cplusplus
extern "C" {
#endif
GVFG_PLAYBACK_API gvfg_playback_status_t gvfg_playback_debug_get_stats(
gvfg_playback p, gvfg_playback_debug_stats_t *stats);
#ifdef __cplusplus
}
#endif
#endif
+2
View File
@@ -8,6 +8,8 @@ EXPORTS
gvfg_set_channel_zero_copy_enabled gvfg_set_channel_zero_copy_enabled
gvfg_get_channel_zero_copy_enabled gvfg_get_channel_zero_copy_enabled
gvfg_set_channel_video_format gvfg_set_channel_video_format
gvfg_get_osd_fonts
gvfg_set_channel_osd_visible
gvfg_measure_osd_text gvfg_measure_osd_text
gvfg_set_channel_osd gvfg_set_channel_osd
gvfg_clear_channel_osd gvfg_clear_channel_osd
+45 -33
View File
@@ -207,21 +207,24 @@ extern "C"
uint64_t timestamp_ns; /* Monotonic SDK delivery time; same clock domain as audio. */ uint64_t timestamp_ns; /* Monotonic SDK delivery time; same clock domain as audio. */
} gvfg_frame_t; } gvfg_frame_t;
/* /* Strings are copied synchronously by gvfg_set_channel_osd(). */
* Text overlay applied by the SDK to subsequently delivered video frames. typedef struct gvfg_channel_osd_config_t
* The text is copied by gvfg_set_channel_osd(); the caller does not need to
* keep the pointer alive after that function returns.
*/
typedef struct
{ {
const char *text; /* Printable English ASCII text (0x20-0x7e). */ const char *text; /* NUL-terminated printable ASCII, 1..32 characters. */
uint32_t text_length; /* 1 through GVFG_OSD_MAX_TEXT_CHARACTERS. */ const char *font_family; /* NUL-terminated UTF-8 installed font family name. */
int32_t x; /* Measured text-box left in frame pixels; clamped to fit. */ uint32_t font_size_px; /* Non-zero em size; 96-DPI rendering, not ink height. */
int32_t y; /* Measured text-box top in frame pixels; clamped to fit. */ uint32_t color_rgb; /* 0x00RRGGBB. */
uint32_t font_size_px; /* Font size in pixels; must be non-zero. */ int32_t x; /* Text-box left in frame pixels; clamped to fit. */
uint32_t color_rgb; /* 0x00RRGGBB. */ int32_t y; /* Text-box top in frame pixels; clamped to fit. */
} gvfg_channel_osd_config_t; } gvfg_channel_osd_config_t;
typedef struct gvfg_osd_font_list_t
{
uint32_t count;
const char *const *names; /* SDK-owned UTF-8 family names; do not modify/free. */
} gvfg_osd_font_list_t;
#define GVFG_OSD_SLOT_COUNT 2u
#define GVFG_OSD_MAX_TEXT_CHARACTERS 32u #define GVFG_OSD_MAX_TEXT_CHARACTERS 32u
typedef struct typedef struct
@@ -368,40 +371,49 @@ extern "C"
GVFG_PARAM_IN int channel_index, GVFG_PARAM_IN int channel_index,
GVFG_PARAM_IN gvfg_pixel_format_t format); GVFG_PARAM_IN gvfg_pixel_format_t format);
/* /* Refresh installed fonts and return an SDK-owned snapshot. No device needed.
* Measure printable ASCII text as a single non-wrapping line, using the * Pointers expire at the next call (including a failed call), or DLL unload.
* same font/layout as SDK OSD. No capture handle or open device is needed. * Copy names before then. Serialize calls and use of this borrowed list.
* Returns a conservative whole-text box in pixels, including glyph * Returns an empty list on failure; no callback or caller-side free is needed.
* overhang and a one-pixel guard per edge; these are not pixel-tight bounds. */
* Both outputs must be non-NULL and are zeroed on failure. GVFG_API gvfg_status_t gvfg_get_osd_fonts(
* Returns GVFG_EINVAL for invalid input or unrepresentable dimensions, GVFG_PARAM_OUT gvfg_osd_font_list_t *out_list);
* and GVFG_EIO on measurement failure.
/* Measure the same conservative text box used for rendering, including
* overhang and a one-pixel guard per edge. Ignores x/y/color; no device needed.
* Outputs are zeroed on failure. Missing font/invalid input: GVFG_EINVAL.
*/ */
GVFG_API gvfg_status_t gvfg_measure_osd_text( GVFG_API gvfg_status_t gvfg_measure_osd_text(
GVFG_PARAM_IN const char *text, GVFG_PARAM_IN const gvfg_channel_osd_config_t *config,
GVFG_PARAM_IN uint32_t text_length,
GVFG_PARAM_IN uint32_t font_size_px,
GVFG_PARAM_OUT uint32_t *out_width, GVFG_PARAM_OUT uint32_t *out_width,
GVFG_PARAM_OUT uint32_t *out_height); GVFG_PARAM_OUT uint32_t *out_height);
/* /* Set and show slot 0 or 1 on an opened channel. Strings are copied before
* Enable or update SDK-side OSD for an opened channel. The configuration * return; slot 1 is blended over slot 0. Applies to subsequent YUY2/Y210
* is copied synchronously and applies to subsequent YUY2 or Y210 frames. * frames using BT.709 limited range. X/Y are clamped to fit the text box.
* Text is rendered as BT.709 limited-range video and blended by the GPU. * An oversized slot is skipped until settings/frame size allow it to fit;
* The single-line measured text box is positioned at x/y, clamped inside * capture and the other slot continue. No wrapping/shrinking/truncation.
* each frame. If the whole box is larger than the frame, OSD is temporarily
* skipped while capture continues. It resumes when settings or frame size
* change so that the text fits; text is not wrapped, shrunk, or truncated.
*/ */
GVFG_API gvfg_status_t gvfg_set_channel_osd( GVFG_API gvfg_status_t gvfg_set_channel_osd(
GVFG_PARAM_IN gvfg_handle handle, GVFG_PARAM_IN gvfg_handle handle,
GVFG_PARAM_IN int channel_index, GVFG_PARAM_IN int channel_index,
GVFG_PARAM_IN uint32_t osd_index,
GVFG_PARAM_IN const gvfg_channel_osd_config_t *config); GVFG_PARAM_IN const gvfg_channel_osd_config_t *config);
/* Disable SDK-side OSD for subsequently delivered frames. */ /* visible must be 0 or 1. Retains settings and cached glyph surfaces.
* Showing an unconfigured/cleared slot returns GVFG_ESTATE.
*/
GVFG_API gvfg_status_t gvfg_set_channel_osd_visible(
GVFG_PARAM_IN gvfg_handle handle,
GVFG_PARAM_IN int channel_index,
GVFG_PARAM_IN uint32_t osd_index,
GVFG_PARAM_IN int visible);
/* Disable one slot and discard its settings and cached glyph surfaces. */
GVFG_API gvfg_status_t gvfg_clear_channel_osd( GVFG_API gvfg_status_t gvfg_clear_channel_osd(
GVFG_PARAM_IN gvfg_handle handle, GVFG_PARAM_IN gvfg_handle handle,
GVFG_PARAM_IN int channel_index); GVFG_PARAM_IN int channel_index,
GVFG_PARAM_IN uint32_t osd_index);
/* /*
* Enable or disable audio for the next channel start. Video remains * Enable or disable audio for the next channel start. Video remains
+224 -202
View File
@@ -7,6 +7,7 @@
#include <wrl/client.h> #include <wrl/client.h>
#include <algorithm> #include <algorithm>
#include <array>
#include <chrono> #include <chrono>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
@@ -75,12 +76,15 @@ constexpr char kOsdBlendShader[] = R"(
Texture2D<uint4> sourceTexture : register(t0); Texture2D<uint4> sourceTexture : register(t0);
Texture2D<uint4> osdTexture : register(t1); Texture2D<uint4> osdTexture : register(t1);
Texture2D<uint2> maskTexture : register(t2); Texture2D<uint2> maskTexture : register(t2);
Texture2D<uint4> osdTexture1 : register(t3);
Texture2D<uint2> maskTexture1 : register(t4);
RWTexture2D<uint4> outputTexture : register(u0); RWTexture2D<uint4> outputTexture : register(u0);
cbuffer BlendParameters : register(b0) cbuffer BlendParameters : register(b0)
{ {
uint outputValueMask; uint outputValueMask;
uint3 padding; uint visibleSlots;
uint2 padding;
}; };
uint blendComponent(uint sourceValue, uint osdValue, uint alpha) uint blendComponent(uint sourceValue, uint osdValue, uint alpha)
@@ -89,6 +93,17 @@ uint blendComponent(uint sourceValue, uint osdValue, uint alpha)
outputValueMask; outputValueMask;
} }
uint4 blendLayer(uint4 sourceValue, uint4 osdValue, uint2 maskValue)
{
uint pairAlpha = max(maskValue.x, maskValue.y);
uint4 result;
result.x = blendComponent(sourceValue.x, osdValue.x, maskValue.x);
result.y = blendComponent(sourceValue.y, osdValue.y, pairAlpha);
result.z = blendComponent(sourceValue.z, osdValue.z, maskValue.y);
result.w = blendComponent(sourceValue.w, osdValue.w, pairAlpha);
return result;
}
[numthreads(16, 16, 1)] [numthreads(16, 16, 1)]
void main(uint3 id : SV_DispatchThreadID) void main(uint3 id : SV_DispatchThreadID)
{ {
@@ -97,24 +112,13 @@ void main(uint3 id : SV_DispatchThreadID)
outputTexture.GetDimensions(width, height); outputTexture.GetDimensions(width, height);
if (id.x >= width || id.y >= height) if (id.x >= width || id.y >= height)
return; return;
const uint3 location = uint3(id.xy, 0);
const uint2 location = id.xy; uint4 result = sourceTexture.Load(location);
const uint4 sourceValue = sourceTexture.Load(uint3(location, 0)); if ((visibleSlots & 1u) != 0u)
const uint2 maskValue = maskTexture.Load(uint3(location, 0)); result = blendLayer(result, osdTexture.Load(location), maskTexture.Load(location));
const uint pairAlpha = max(maskValue.x, maskValue.y); if ((visibleSlots & 2u) != 0u)
if (pairAlpha == 0u) result = blendLayer(result, osdTexture1.Load(location), maskTexture1.Load(location));
{ outputTexture[id.xy] = result;
outputTexture[location] = sourceValue;
return;
}
const uint4 osdValue = osdTexture.Load(uint3(location, 0));
uint4 result;
result.x = blendComponent(sourceValue.x, osdValue.x, maskValue.x);
result.y = blendComponent(sourceValue.y, osdValue.y, pairAlpha);
result.z = blendComponent(sourceValue.z, osdValue.z, maskValue.y);
result.w = blendComponent(sourceValue.w, osdValue.w, pairAlpha);
outputTexture[location] = result;
} }
)"; )";
@@ -195,36 +199,70 @@ void copyFrameRows(const gvfg_frame_t &source, uint8_t *destination,
struct GpuOsdProcessor::Impl struct GpuOsdProcessor::Impl
{ {
gvfg_status_t configure(const gvfg_channel_osd_config_t &value) struct Slot
{ {
if (!value.text || value.text_length == 0 || bool configured = false;
value.text_length > GVFG_OSD_MAX_TEXT_CHARACTERS || bool visible = false;
value.font_size_px == 0) bool dirty = true;
return GVFG_EINVAL; std::string text;
for (uint32_t i = 0; i < value.text_length; ++i) std::string fontFamily;
{ int32_t x = 0, y = 0;
const unsigned char c = static_cast<unsigned char>(value.text[i]); uint32_t fontSize = 0, colorRgb = 0xffffffu;
if (c < 0x20 || c > 0x7e) uint32_t width = 0, height = 0;
return GVFG_EINVAL; int format = GVFG_PIXFMT_UNKNOWN;
} OsdRegion region;
std::vector<uint8_t> yuv, mask;
ComPtr<ID3D11Texture2D> texture, maskTexture;
ComPtr<ID3D11ShaderResourceView> srv, maskSrv;
};
gvfg_status_t configure(uint32_t index, const gvfg_channel_osd_config_t &value)
{
if (index >= slots.size())
return GVFG_EINVAL;
uint32_t width = 0, height = 0;
const auto status = gvfg_measure_osd_text(&value, &width, &height);
if (status != GVFG_OK)
return status;
// Allocate copies before changing state so failures retain the old slot.
std::string text(value.text), family(value.font_family);
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
text.assign(value.text, value.text + value.text_length); auto &slot = slots[index];
x = value.x; const bool changed = !slot.configured || slot.text != text || slot.fontFamily != family ||
y = value.y; slot.x != value.x || slot.y != value.y || slot.fontSize != value.font_size_px ||
fontSize = value.font_size_px; slot.colorRgb != (value.color_rgb & 0x00ffffffu);
colorRgb = value.color_rgb & 0x00ffffffu; slot.text.swap(text);
active = true; slot.fontFamily.swap(family);
slot.x = value.x;
slot.y = value.y;
slot.fontSize = value.font_size_px;
slot.colorRgb = value.color_rgb & 0x00ffffffu;
slot.configured = slot.visible = true;
slot.dirty = slot.dirty || changed;
surfaceDirty = surfaceDirty || changed;
return GVFG_OK;
}
gvfg_status_t clear(uint32_t index)
{
if (index >= slots.size())
return GVFG_EINVAL;
std::lock_guard<std::mutex> lock(mutex);
slots[index] = Slot{};
surfaceDirty = true; surfaceDirty = true;
return GVFG_OK; return GVFG_OK;
} }
void clear() gvfg_status_t setVisible(uint32_t index, int visible)
{ {
if (index >= slots.size() || (visible != 0 && visible != 1))
return GVFG_EINVAL;
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
active = false; if (!slots[index].configured && visible)
text.clear(); return GVFG_ESTATE;
surfaceDirty = true; slots[index].visible = visible != 0;
// Keep rasterized surfaces and GPU textures intact.
return GVFG_OK;
} }
bool ensureDevice() bool ensureDevice()
@@ -305,169 +343,152 @@ struct GpuOsdProcessor::Impl
bool ensureResources(uint32_t regionWidth, uint32_t regionHeight, int pixelFormat) bool ensureResources(uint32_t regionWidth, uint32_t regionHeight, int pixelFormat)
{ {
if ((regionWidth & 1u) != 0 || regionWidth == 0 || regionHeight == 0)
return false;
const DXGI_FORMAT packedFormat = pixelFormat == GVFG_PIXFMT_YUY2 const DXGI_FORMAT packedFormat = pixelFormat == GVFG_PIXFMT_YUY2
? DXGI_FORMAT_R8G8B8A8_UINT ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R16G16B16A16_UINT;
: pixelFormat == GVFG_PIXFMT_Y210 const bool changed = resourceWidth != regionWidth || resourceHeight != regionHeight ||
? DXGI_FORMAT_R16G16B16A16_UINT resourceFormat != pixelFormat;
: DXGI_FORMAT_UNKNOWN; if (changed)
if (packedFormat == DXGI_FORMAT_UNKNOWN)
return false;
if (resourceWidth != regionWidth || resourceHeight != regionHeight ||
resourceFormat != pixelFormat || !sourceSrv || !osdSrv || !maskSrv || !outputUav)
{ {
// Failed partial recreation must never leave views cached against
// old textures, including when the next request returns to an old size.
sourceSrv.Reset(); sourceSrv.Reset();
osdSrv.Reset();
maskSrv.Reset();
outputUav.Reset(); outputUav.Reset();
resourceWidth = 0; for (auto &slot : slots) { slot.srv.Reset(); slot.maskSrv.Reset(); }
resourceHeight = 0; resourceWidth = resourceHeight = 0;
resourceFormat = GVFG_PIXFMT_UNKNOWN; resourceFormat = GVFG_PIXFMT_UNKNOWN;
} }
const uint32_t pairWidth = regionWidth / 2u; const uint32_t pairWidth = regionWidth / 2u;
if (!ensureTexture(sourceTexture, pairWidth, regionHeight, packedFormat, if (!ensureTexture(sourceTexture, pairWidth, regionHeight, packedFormat,
D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, D3D11_CPU_ACCESS_WRITE) ||
D3D11_CPU_ACCESS_WRITE) ||
!ensureTexture(osdTexture, pairWidth, regionHeight, packedFormat,
D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE,
D3D11_CPU_ACCESS_WRITE) ||
!ensureTexture(maskTexture, pairWidth, regionHeight, DXGI_FORMAT_R8G8_UINT,
D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE,
D3D11_CPU_ACCESS_WRITE) ||
!ensureTexture(outputTexture, pairWidth, regionHeight, packedFormat, !ensureTexture(outputTexture, pairWidth, regionHeight, packedFormat,
D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS, 0) || D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS, 0) ||
!ensureTexture(readbackTexture, pairWidth, regionHeight, packedFormat, !ensureTexture(readbackTexture, pairWidth, regionHeight, packedFormat,
D3D11_USAGE_STAGING, 0, D3D11_CPU_ACCESS_READ)) D3D11_USAGE_STAGING, 0, D3D11_CPU_ACCESS_READ))
return false; return false;
for (auto &slot : slots)
if (!sourceSrv || resourceWidth != regionWidth || resourceHeight != regionHeight ||
resourceFormat != pixelFormat)
{ {
sourceSrv.Reset(); if (!ensureTexture(slot.texture, pairWidth, regionHeight, packedFormat,
osdSrv.Reset(); D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, D3D11_CPU_ACCESS_WRITE) ||
maskSrv.Reset(); !ensureTexture(slot.maskTexture, pairWidth, regionHeight, DXGI_FORMAT_R8G8_UINT,
outputUav.Reset(); D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, D3D11_CPU_ACCESS_WRITE))
if (FAILED(device->CreateShaderResourceView(sourceTexture.Get(), nullptr, &sourceSrv)) || return false;
FAILED(device->CreateShaderResourceView(osdTexture.Get(), nullptr, &osdSrv)) || if ((!slot.srv && FAILED(device->CreateShaderResourceView(slot.texture.Get(), nullptr, &slot.srv))) ||
FAILED(device->CreateShaderResourceView(maskTexture.Get(), nullptr, &maskSrv)) || (!slot.maskSrv && FAILED(device->CreateShaderResourceView(slot.maskTexture.Get(), nullptr, &slot.maskSrv))))
FAILED(device->CreateUnorderedAccessView(outputTexture.Get(), nullptr, &outputUav)))
return false; return false;
resourceWidth = regionWidth;
resourceHeight = regionHeight;
resourceFormat = pixelFormat;
} }
if ((!sourceSrv && FAILED(device->CreateShaderResourceView(sourceTexture.Get(), nullptr, &sourceSrv))) ||
(!outputUav && FAILED(device->CreateUnorderedAccessView(outputTexture.Get(), nullptr, &outputUav))))
return false;
resourceWidth = regionWidth;
resourceHeight = regionHeight;
resourceFormat = pixelFormat;
return true; return true;
} }
bool rebuildSurface(uint32_t frameWidth, uint32_t frameHeight, int pixelFormat) bool rebuildSlot(Slot &slot, uint32_t width, uint32_t height, int format)
{ {
// Any failed rebuild must be retried, even if input dimensions then if (!slot.dirty && slot.width == width && slot.height == height && slot.format == format)
// return to the previously cached frame size.
surfaceDirty = true;
const uint32_t yuvStride = frameWidth * (pixelFormat == GVFG_PIXFMT_YUY2 ? 2u : 4u);
const uint32_t maskStride = frameWidth;
gvfg_osd_handle rawHandle = nullptr;
if (gvfg_osd_create(&rawHandle) != GVFG_OSD_OK)
return false;
std::unique_ptr<void, decltype(&gvfg_osd_destroy)> handle(rawHandle, &gvfg_osd_destroy);
uint32_t textWidth = 0;
uint32_t textHeight = 0;
const gvfg_osd_status_t measureStatus = gvfg_osd_measure(
handle.get(), text.c_str(), static_cast<uint32_t>(text.size()),
fontSize, &textWidth, &textHeight);
// Stored input already passed configure() validation. EINVAL here
// means the measured box cannot be represented by uint32_t either.
if (measureStatus != GVFG_OSD_OK && measureStatus != GVFG_OSD_EINVAL)
return false;
if (measureStatus == GVFG_OSD_EINVAL ||
textWidth > frameWidth || textHeight > frameHeight)
{
// Retain the configuration and retry only after settings or the
// input dimensions/format change. Capture must continue normally.
region = {};
surfaceWidth = frameWidth;
surfaceHeight = frameHeight;
surfaceFormat = pixelFormat;
surfaceDirty = false;
return true; return true;
} const uint32_t stride = width * (format == GVFG_PIXFMT_YUY2 ? 2u : 4u);
yuvSurface.resize(static_cast<size_t>(yuvStride) * frameHeight); slot.yuv.assign(static_cast<size_t>(stride) * height, 0);
maskSurface.resize(static_cast<size_t>(maskStride) * frameHeight); slot.mask.assign(static_cast<size_t>(width) * height, 0);
slot.region = {};
gvfg_osd_config_t config{}; if (slot.configured)
config.struct_size = sizeof(config);
config.width = frameWidth;
config.height = frameHeight;
config.pixel_format = pixelFormat == GVFG_PIXFMT_YUY2
? GVFG_OSD_PIXFMT_YUY2
: GVFG_OSD_PIXFMT_Y210;
config.text = text.c_str();
config.text_length = static_cast<uint32_t>(text.size());
config.x = x;
config.y = y;
config.font_size_px = fontSize;
config.color_rgb = colorRgb;
gvfg_osd_output_t output{};
output.struct_size = sizeof(output);
output.yuv_data = yuvSurface.data();
output.yuv_size = yuvSurface.size();
output.yuv_stride = yuvStride;
output.mask_data = maskSurface.data();
output.mask_size = maskSurface.size();
output.mask_stride = maskStride;
const gvfg_osd_status_t status = gvfg_osd_render(handle.get(), &config, &output);
handle.reset();
if (status != GVFG_OSD_OK)
return false;
region = findCoveredRegion(maskSurface, frameWidth, frameHeight);
if (region.empty())
{ {
surfaceWidth = frameWidth; gvfg_osd_handle raw = nullptr;
surfaceHeight = frameHeight; if (gvfg_osd_create(&raw) != GVFG_OSD_OK)
surfaceFormat = pixelFormat; return false;
surfaceDirty = false; std::unique_ptr<void, decltype(&gvfg_osd_destroy)> helper(raw, &gvfg_osd_destroy);
return true; uint32_t textWidth = 0, textHeight = 0;
const auto measured = gvfg_osd_measure(raw, slot.text.c_str(),
static_cast<uint32_t>(slot.text.size()), slot.fontSize, slot.fontFamily.c_str(),
&textWidth, &textHeight);
if (measured != GVFG_OSD_OK)
return false;
// Oversized text skips only this slot, preserving capture and the other slot.
if (textWidth <= width && textHeight <= height)
{
gvfg_osd_config_t config{};
config.struct_size = sizeof(config);
config.width = width;
config.height = height;
config.pixel_format = format == GVFG_PIXFMT_YUY2 ? GVFG_OSD_PIXFMT_YUY2 : GVFG_OSD_PIXFMT_Y210;
config.text = slot.text.c_str();
config.text_length = static_cast<uint32_t>(slot.text.size());
config.font_family = slot.fontFamily.c_str();
config.font_size_px = slot.fontSize;
config.color_rgb = slot.colorRgb;
config.x = slot.x;
config.y = slot.y;
gvfg_osd_output_t output{};
output.struct_size = sizeof(output);
output.yuv_data = slot.yuv.data();
output.yuv_size = slot.yuv.size();
output.yuv_stride = stride;
output.mask_data = slot.mask.data();
output.mask_size = slot.mask.size();
output.mask_stride = width;
if (gvfg_osd_render(raw, &config, &output) != GVFG_OSD_OK)
return false;
slot.region = findCoveredRegion(slot.mask, width, height);
}
} }
if (!ensureDevice() || !ensureResources(region.width, region.height, pixelFormat)) slot.width = width;
return false; slot.height = height;
slot.format = format;
slot.dirty = false;
return true;
}
const uint32_t bytesPerPixel = pixelFormat == GVFG_PIXFMT_YUY2 ? 2u : 4u; bool rebuildSurface(uint32_t width, uint32_t height, int format)
const uint32_t regionRowBytes = region.width * bytesPerPixel; {
const size_t yuvOffset = static_cast<size_t>(region.top) * yuvStride + surfaceDirty = true; // Retry partial failures, including upload failures.
static_cast<size_t>(region.left) * bytesPerPixel; region = {};
const size_t maskOffset = static_cast<size_t>(region.top) * maskStride + region.left; for (auto &slot : slots)
{
D3D11_MAPPED_SUBRESOURCE mapped{}; if (!rebuildSlot(slot, width, height, format))
if (FAILED(context->Map(osdTexture.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped))) return false;
return false; if (slot.region.empty())
const bool copiedYuv = copyRowsToMapped( continue;
yuvSurface.data() + yuvOffset, static_cast<int>(yuvStride), if (region.empty())
regionRowBytes, region.height, mapped); region = slot.region;
context->Unmap(osdTexture.Get(), 0); else
if (!copiedYuv) {
return false; const uint32_t right = (std::max)(region.left + region.width, slot.region.left + slot.region.width);
const uint32_t bottom = (std::max)(region.top + region.height, slot.region.top + slot.region.height);
if (FAILED(context->Map(maskTexture.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped))) region.left = (std::min)(region.left, slot.region.left);
return false; region.top = (std::min)(region.top, slot.region.top);
const bool copiedMask = copyRowsToMapped( region.width = right - region.left;
maskSurface.data() + maskOffset, static_cast<int>(maskStride), region.height = bottom - region.top;
region.width, region.height, mapped); }
context->Unmap(maskTexture.Get(), 0); }
if (!copiedMask) // Include hidden slots in the shared ROI so show/hide never rerasterizes
return false; // glyphs or recreates textures. Visibility is a shader constant.
if (!region.empty())
const uint32_t blendValues[4] = { {
pixelFormat == GVFG_PIXFMT_Y210 ? 0xffc0u : 0x00ffu, if (!ensureDevice() || !ensureResources(region.width, region.height, format))
0u, 0u, 0u}; return false;
context->UpdateSubresource(blendParameters.Get(), 0, nullptr, blendValues, 0, 0); const uint32_t bpp = format == GVFG_PIXFMT_YUY2 ? 2u : 4u;
surfaceWidth = frameWidth; const size_t yuvOffset = (static_cast<size_t>(region.top) * width + region.left) * bpp;
surfaceHeight = frameHeight; const size_t maskOffset = static_cast<size_t>(region.top) * width + region.left;
surfaceFormat = pixelFormat; for (auto &slot : slots)
{
D3D11_MAPPED_SUBRESOURCE mapped{};
if (FAILED(context->Map(slot.texture.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)))
return false;
const bool yuvOk = copyRowsToMapped(slot.yuv.data() + yuvOffset,
static_cast<int>(width * bpp), region.width * bpp, region.height, mapped);
context->Unmap(slot.texture.Get(), 0);
if (!yuvOk || FAILED(context->Map(slot.maskTexture.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)))
return false;
const bool maskOk = copyRowsToMapped(slot.mask.data() + maskOffset,
static_cast<int>(width), region.width, region.height, mapped);
context->Unmap(slot.maskTexture.Get(), 0);
if (!maskOk)
return false;
}
}
surfaceWidth = width;
surfaceHeight = height;
surfaceFormat = format;
surfaceDirty = false; surfaceDirty = false;
return true; return true;
} }
@@ -505,7 +526,11 @@ struct GpuOsdProcessor::Impl
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
finishStage(GVFG_DEBUG_OSD_LOCK_WAIT); finishStage(GVFG_DEBUG_OSD_LOCK_WAIT);
applied = false; applied = false;
if (!active) uint32_t visibleSlots = 0;
for (uint32_t i = 0; i < slots.size(); ++i)
if (slots[i].configured && slots[i].visible)
visibleSlots |= 1u << i;
if (!visibleSlots)
return GVFG_OK; return GVFG_OK;
if (!source.data || source.width <= 0 || source.height <= 0 || if (!source.data || source.width <= 0 || source.height <= 0 ||
(source.width & 1) != 0 || source.row_stride_bytes <= 0 || (source.width & 1) != 0 || source.row_stride_bytes <= 0 ||
@@ -537,7 +562,10 @@ struct GpuOsdProcessor::Impl
return GVFG_EIO; return GVFG_EIO;
finishStage(GVFG_DEBUG_OSD_SURFACE); finishStage(GVFG_DEBUG_OSD_SURFACE);
// Invisible text needs no processed buffer or GPU work. // Invisible text needs no processed buffer or GPU work.
if (region.empty()) bool hasVisibleInk = false;
for (const auto &slot : slots)
hasVisibleInk = hasVisibleInk || (slot.visible && !slot.region.empty());
if (region.empty() || !hasVisibleInk)
return GVFG_OK; return GVFG_OK;
const uint32_t rowBytes = static_cast<uint32_t>(rowBytes64); const uint32_t rowBytes = static_cast<uint32_t>(rowBytes64);
@@ -582,18 +610,22 @@ struct GpuOsdProcessor::Impl
return GVFG_EIO; return GVFG_EIO;
finishStage(GVFG_DEBUG_OSD_UPLOAD); finishStage(GVFG_DEBUG_OSD_UPLOAD);
ID3D11ShaderResourceView *srvs[] = {sourceSrv.Get(), osdSrv.Get(), maskSrv.Get()}; const uint32_t blendValues[4] = {
source.pixel_format == GVFG_PIXFMT_Y210 ? 0xffc0u : 0x00ffu, visibleSlots, 0u, 0u};
context->UpdateSubresource(blendParameters.Get(), 0, nullptr, blendValues, 0, 0);
ID3D11ShaderResourceView *srvs[] = {sourceSrv.Get(), slots[0].srv.Get(), slots[0].maskSrv.Get(),
slots[1].srv.Get(), slots[1].maskSrv.Get()};
ID3D11UnorderedAccessView *uavs[] = {outputUav.Get()}; ID3D11UnorderedAccessView *uavs[] = {outputUav.Get()};
context->CSSetShader(shader.Get(), nullptr, 0); context->CSSetShader(shader.Get(), nullptr, 0);
ID3D11Buffer *constantBuffers[] = {blendParameters.Get()}; ID3D11Buffer *constantBuffers[] = {blendParameters.Get()};
context->CSSetConstantBuffers(0, 1, constantBuffers); context->CSSetConstantBuffers(0, 1, constantBuffers);
context->CSSetShaderResources(0, 3, srvs); context->CSSetShaderResources(0, 5, srvs);
context->CSSetUnorderedAccessViews(0, 1, uavs, nullptr); context->CSSetUnorderedAccessViews(0, 1, uavs, nullptr);
context->Dispatch((region.width / 2u + 15u) / 16u, context->Dispatch((region.width / 2u + 15u) / 16u,
(region.height + 15u) / 16u, 1); (region.height + 15u) / 16u, 1);
ID3D11ShaderResourceView *nullSrvs[] = {nullptr, nullptr, nullptr}; ID3D11ShaderResourceView *nullSrvs[] = {nullptr, nullptr, nullptr, nullptr, nullptr};
ID3D11UnorderedAccessView *nullUav = nullptr; ID3D11UnorderedAccessView *nullUav = nullptr;
context->CSSetShaderResources(0, 3, nullSrvs); context->CSSetShaderResources(0, 5, nullSrvs);
context->CSSetUnorderedAccessViews(0, 1, &nullUav, nullptr); context->CSSetUnorderedAccessViews(0, 1, &nullUav, nullptr);
ID3D11Buffer *nullBuffer = nullptr; ID3D11Buffer *nullBuffer = nullptr;
context->CSSetConstantBuffers(0, 1, &nullBuffer); context->CSSetConstantBuffers(0, 1, &nullBuffer);
@@ -650,13 +682,8 @@ struct GpuOsdProcessor::Impl
} }
mutable std::mutex mutex; mutable std::mutex mutex;
bool active = false; std::array<Slot, GVFG_OSD_SLOT_COUNT> slots;
bool surfaceDirty = true; bool surfaceDirty = true;
std::string text;
int32_t x = 0;
int32_t y = 0;
uint32_t fontSize = 0;
uint32_t colorRgb = 0xffffffu;
OsdRegion region; OsdRegion region;
uint32_t surfaceWidth = 0; uint32_t surfaceWidth = 0;
uint32_t surfaceHeight = 0; uint32_t surfaceHeight = 0;
@@ -664,37 +691,32 @@ struct GpuOsdProcessor::Impl
uint32_t resourceWidth = 0; uint32_t resourceWidth = 0;
uint32_t resourceHeight = 0; uint32_t resourceHeight = 0;
int resourceFormat = GVFG_PIXFMT_UNKNOWN; int resourceFormat = GVFG_PIXFMT_UNKNOWN;
std::vector<uint8_t> yuvSurface;
std::vector<uint8_t> maskSurface;
ComPtr<ID3D11Device> device; ComPtr<ID3D11Device> device;
ComPtr<ID3D11DeviceContext> context; ComPtr<ID3D11DeviceContext> context;
ComPtr<ID3D11ComputeShader> shader; ComPtr<ID3D11ComputeShader> shader;
ComPtr<ID3D11Buffer> blendParameters; ComPtr<ID3D11Buffer> blendParameters;
ComPtr<ID3D11Texture2D> sourceTexture; ComPtr<ID3D11Texture2D> sourceTexture;
ComPtr<ID3D11Texture2D> osdTexture;
ComPtr<ID3D11Texture2D> maskTexture;
ComPtr<ID3D11Texture2D> outputTexture; ComPtr<ID3D11Texture2D> outputTexture;
ComPtr<ID3D11Texture2D> readbackTexture; ComPtr<ID3D11Texture2D> readbackTexture;
ComPtr<ID3D11ShaderResourceView> sourceSrv; ComPtr<ID3D11ShaderResourceView> sourceSrv;
ComPtr<ID3D11ShaderResourceView> osdSrv;
ComPtr<ID3D11ShaderResourceView> maskSrv;
ComPtr<ID3D11UnorderedAccessView> outputUav; ComPtr<ID3D11UnorderedAccessView> outputUav;
}; };
GpuOsdProcessor::GpuOsdProcessor() : impl_(std::make_unique<Impl>()) {} GpuOsdProcessor::GpuOsdProcessor() : impl_(std::make_unique<Impl>()) {}
GpuOsdProcessor::~GpuOsdProcessor() = default; GpuOsdProcessor::~GpuOsdProcessor() = default;
gvfg_status_t GpuOsdProcessor::configure(const gvfg_channel_osd_config_t &config) gvfg_status_t GpuOsdProcessor::configure(uint32_t index, const gvfg_channel_osd_config_t &config)
{ {
try try
{ {
return impl_->configure(config); return impl_->configure(index, config);
} }
catch (...) catch (...)
{ {
return GVFG_EIO; return GVFG_EIO;
} }
} }
void GpuOsdProcessor::clear() { impl_->clear(); } gvfg_status_t GpuOsdProcessor::clear(uint32_t index) { return impl_->clear(index); }
gvfg_status_t GpuOsdProcessor::setVisible(uint32_t index, int visible) { return impl_->setVisible(index, visible); }
gvfg_status_t GpuOsdProcessor::process(const gvfg_frame_t &source, gvfg_status_t GpuOsdProcessor::process(const gvfg_frame_t &source,
std::vector<uint8_t> &destination, std::vector<uint8_t> &destination,
int &destinationStride, int &destinationStride,
+3 -2
View File
@@ -15,8 +15,9 @@ public:
GpuOsdProcessor(); GpuOsdProcessor();
~GpuOsdProcessor(); ~GpuOsdProcessor();
gvfg_status_t configure(const gvfg_channel_osd_config_t &config); gvfg_status_t configure(uint32_t index, const gvfg_channel_osd_config_t &config);
void clear(); gvfg_status_t clear(uint32_t index);
gvfg_status_t setVisible(uint32_t index, int visible);
// writableSource must equal source.data. Only the backend can grant this // writableSource must equal source.data. Only the backend can grant this
// writable SDK-owned storage, held until the caller releases the frame. // writable SDK-owned storage, held until the caller releases the frame.
// The default-OFF experimental override admits driver storage only after // The default-OFF experimental override admits driver storage only after
+60 -48
View File
@@ -682,11 +682,11 @@ struct gvfg_channel_session_t
return session->set_video_format(format); return session->set_video_format(format);
} }
gvfg_status_t setOsd(const gvfg_channel_osd_config_t &config) gvfg_status_t setOsd(uint32_t index, const gvfg_channel_osd_config_t &config)
{ {
if (!session) if (!session)
return reject(GVFG_ESTATE, "gvfg_set_channel_osd rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_set_channel_osd rejected: channel is not open");
const gvfg_status_t status = osdProcessor.configure(config); const gvfg_status_t status = osdProcessor.configure(index, config);
return status == GVFG_OK return status == GVFG_OK
? GVFG_OK ? GVFG_OK
: reject(status, status == GVFG_EINVAL : reject(status, status == GVFG_EINVAL
@@ -694,12 +694,19 @@ struct gvfg_channel_session_t
: "gvfg_set_channel_osd failed to store configuration"); : "gvfg_set_channel_osd failed to store configuration");
} }
gvfg_status_t clearOsd() gvfg_status_t clearOsd(uint32_t index)
{ {
if (!session) if (!session)
return reject(GVFG_ESTATE, "gvfg_clear_channel_osd rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_clear_channel_osd rejected: channel is not open");
osdProcessor.clear(); return osdProcessor.clear(index);
return GVFG_OK; }
gvfg_status_t setOsdVisible(uint32_t index, int visible)
{
if (!session)
return reject(GVFG_ESTATE, "OSD visibility rejected: channel is not open");
const gvfg_status_t status = osdProcessor.setVisible(index, visible);
return status == GVFG_OK ? status : reject(status, "OSD visibility rejected: invalid slot, visibility, or no saved configuration");
} }
gvfg_status_t setAudioEnabled(bool enabled) gvfg_status_t setAudioEnabled(bool enabled)
@@ -1173,68 +1180,73 @@ extern "C"
return handle->setChannelVideoFormat(channel_index, format); return handle->setChannelVideoFormat(channel_index, format);
} }
gvfg_status_t gvfg_measure_osd_text(const char *text, uint32_t text_length, gvfg_status_t gvfg_get_osd_fonts(gvfg_osd_font_list_t *out_list)
uint32_t font_size_px,
uint32_t *out_width, uint32_t *out_height)
{ {
if (out_width) if (!out_list)
*out_width = 0;
if (out_height)
*out_height = 0;
if (!text || text_length == 0 || text_length > GVFG_OSD_MAX_TEXT_CHARACTERS ||
font_size_px == 0 || !out_width || !out_height)
return GVFG_EINVAL; return GVFG_EINVAL;
for (uint32_t i = 0; i < text_length; ++i) *out_list = {};
{ const auto status = gvfg_osd_get_fonts(&out_list->count, &out_list->names);
const unsigned char c = static_cast<unsigned char>(text[i]); return status == GVFG_OSD_OK ? GVFG_OK : GVFG_EIO;
if (c < 0x20 || c > 0x7e) }
return GVFG_EINVAL;
}
gvfg_status_t gvfg_measure_osd_text(const gvfg_channel_osd_config_t *config,
uint32_t *out_width, uint32_t *out_height)
{
if (out_width) *out_width = 0;
if (out_height) *out_height = 0;
if (!config || !config->text || !out_width || !out_height)
return GVFG_EINVAL;
const size_t length = strnlen_s(config->text, GVFG_OSD_MAX_TEXT_CHARACTERS + 1u);
if (length == 0 || length > GVFG_OSD_MAX_TEXT_CHARACTERS)
return GVFG_EINVAL;
try try
{ {
gvfg_osd_handle rawHandle = nullptr; gvfg_osd_handle rawHandle = nullptr;
if (gvfg_osd_create(&rawHandle) != GVFG_OSD_OK) if (gvfg_osd_create(&rawHandle) != GVFG_OSD_OK)
return GVFG_EIO; return GVFG_EIO;
const std::unique_ptr<void, decltype(&gvfg_osd_destroy)> helper( const std::unique_ptr<void, decltype(&gvfg_osd_destroy)> helper(rawHandle, &gvfg_osd_destroy);
rawHandle, &gvfg_osd_destroy); const auto status = gvfg_osd_measure(helper.get(), config->text,
const gvfg_osd_status_t status = gvfg_osd_measure( static_cast<uint32_t>(length), config->font_size_px, config->font_family,
helper.get(), text, text_length, font_size_px, out_width, out_height); out_width, out_height);
if (status == GVFG_OSD_OK) return status == GVFG_OSD_OK ? GVFG_OK :
return GVFG_OK; status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO;
return status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO;
}
catch (...)
{
*out_width = 0;
*out_height = 0;
return GVFG_EIO;
} }
catch (...) { return GVFG_EIO; }
} }
gvfg_status_t gvfg_set_channel_osd(gvfg_handle handle, gvfg_status_t gvfg_set_channel_osd(gvfg_handle handle, int channel_index,
int channel_index, uint32_t osd_index, const gvfg_channel_osd_config_t *config)
const gvfg_channel_osd_config_t *config)
{ {
if (!handle) if (!handle)
return GVFG_EINVAL; return GVFG_EINVAL;
if (!config) if (!config || osd_index >= GVFG_OSD_SLOT_COUNT)
return handle->rejectChannel(channel_index, GVFG_EINVAL, return handle->rejectChannel(channel_index, GVFG_EINVAL, "OSD config or index is invalid");
"gvfg_set_channel_osd rejected: config is null"); auto *channel = handle->findChannel(channel_index);
gvfg_channel_session_t *channel = handle->findChannel(channel_index); return channel ? channel->setOsd(osd_index, *config)
return channel ? channel->setOsd(*config) : handle->rejectChannel(channel_index, GVFG_ESTATE, "OSD channel is not open");
: handle->rejectChannel(channel_index, GVFG_ESTATE,
"gvfg_set_channel_osd rejected: channel is not open");
} }
gvfg_status_t gvfg_clear_channel_osd(gvfg_handle handle, int channel_index) gvfg_status_t gvfg_set_channel_osd_visible(gvfg_handle handle, int channel_index,
uint32_t osd_index, int visible)
{ {
if (!handle) if (!handle)
return GVFG_EINVAL; return GVFG_EINVAL;
gvfg_channel_session_t *channel = handle->findChannel(channel_index); if (osd_index >= GVFG_OSD_SLOT_COUNT || (visible != 0 && visible != 1))
return channel ? channel->clearOsd() return handle->rejectChannel(channel_index, GVFG_EINVAL, "OSD index or visibility is invalid");
: handle->rejectChannel(channel_index, GVFG_ESTATE, auto *channel = handle->findChannel(channel_index);
"gvfg_clear_channel_osd rejected: channel is not open"); return channel ? channel->setOsdVisible(osd_index, visible)
: handle->rejectChannel(channel_index, GVFG_ESTATE, "OSD channel is not open");
}
gvfg_status_t gvfg_clear_channel_osd(gvfg_handle handle, int channel_index, uint32_t osd_index)
{
if (!handle)
return GVFG_EINVAL;
if (osd_index >= GVFG_OSD_SLOT_COUNT)
return handle->rejectChannel(channel_index, GVFG_EINVAL, "OSD index is invalid");
auto *channel = handle->findChannel(channel_index);
return channel ? channel->clearOsd(osd_index)
: handle->rejectChannel(channel_index, GVFG_ESTATE, "OSD channel is not open");
} }
gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle, gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle,
+1 -1
View File
@@ -1,6 +1,6 @@
# GVFG Standalone SDK # GVFG Standalone SDK
目前 SDK 版本為 2.1.1,來源是 [GVFG_SDK/CMakeLists.txt](GVFG_SDK/CMakeLists.txt)。 目前 SDK 版本為 3.0.0,來源是 [GVFG_SDK/CMakeLists.txt](GVFG_SDK/CMakeLists.txt)。
擷取使用 `gvfg.dll`;選用播放功能使用 `gvfg_playback.dll`。Audio 與 Preview 是 擷取使用 `gvfg.dll`;選用播放功能使用 `gvfg_playback.dll`。Audio 與 Preview 是
Playback 內部靜態 library,不再各自部署 DLL。 Playback 內部靜態 library,不再各自部署 DLL。
+64 -20
View File
@@ -1,6 +1,6 @@
# GVFG 客戶 API 使用手冊 # GVFG 客戶 API 使用手冊
本文件說明 SDK 2.1.1 的公開擷取介面 `gvfg_capture.h`。 本文件說明 SDK 3.0.0 的公開擷取介面 `gvfg_capture.h`。
影像/音訊/同步播放另使用 `gvfg_playback.h`,完整流程見 影像/音訊/同步播放另使用 `gvfg_playback.h`,完整流程見
[統一影音播放使用手冊](GVFG_PLAYBACK_API.md)。Capture 與 Playback 是不同 handle 與 DLL。 [統一影音播放使用手冊](GVFG_PLAYBACK_API.md)。Capture 與 Playback 是不同 handle 與 DLL。
@@ -122,7 +122,7 @@ Audio 採用相同的 pull 與 ownership 模型:
- 若播放或錄音需要在 release 後繼續使用 PCM,Application 必須先複製。 - 若播放或錄音需要在 release 後繼續使用 PCM,Application 必須先複製。
- Capture 保有自己的交付 buffer;播放副本、queue、同步與輸出由 Playback 管理。 - Capture 保有自己的交付 buffer;播放副本、queue、同步與輸出由 Playback 管理。
- 使用 Playback 時,submit 已完成複製後即可 release,Demo 不自行實作音訊調速或同步。 - 使用 Playback 時,submit 已完成複製後即可 release,Demo 不自行實作音訊調速或同步。
- 播放錯誤由 Playback status/last_error 回報,caller 決定停止與重啟。 - 播放錯誤由 Playback API 回傳狀態碼回報,caller 決定停止與重啟。
輸出裝置故障後,應用程式須處理錯誤並決定是否重新啟動播放。 輸出裝置故障後,應用程式須處理錯誤並決定是否重新啟動播放。
`timeout_ms` 的共同規則:`0` 表示不等待;`GVFG_TIMEOUT_INFINITE` 表示無限等待; `timeout_ms` 的共同規則:`0` 表示不等待;`GVFG_TIMEOUT_INFINITE` 表示無限等待;
@@ -226,28 +226,69 @@ Zero-copy mode 的 driver lifecycle 由 SDK 管理:open 時 enable,destroy/c
### SDK OSD ### SDK OSD
OSD 由 `gvfg.dll` 提供。啟用後, 每個已 open 的 channel 支援兩組獨立 OSD,`osd_index` 為 `0` 或 `1`;
`gvfg_read_channel_frame()` 交付含 OSD 的完整 YUY2/Y210 frame;使用後照常 release。 重疊時第 `1` 組蓋在第 `0` 組上。後續 `gvfg_read_channel_frame()` 交付含 OSD 的
YUY2/Y210 frame,使用後照常 release。
- `gvfg_measure_osd_text(text, text_length, font_size_px, &width, &height)`:量測與實際 - `gvfg_get_osd_fonts(&list)`:重新檢查 Windows 已安裝字型,取得當前可用家族名稱。
OSD 相同的單行文字框;不需要 handle,也不會開啟 capture device。 不需要 handle、callback 或客戶端 free。`list.count` 是數量,`list.names[i]` 是 UTF-8 名稱。
- `gvfg_set_channel_osd(handle, channel, &config)`:啟用或更新已 open channel 的 OSD。 清單由 SDK 管理,指標有效到下一次呼叫此函式(包含失敗呼叫)或 DLL 卸載為止;
SDK 同步複製文字設定,後續 frame 使用新設定。 填入 UI 或長期保存時自行複製。呼叫及讀取借用清單須由 caller 序列化。
- `gvfg_clear_channel_osd(handle, channel)`:停用後續 frame 的 OSD。 - `gvfg_measure_osd_text(&config, &width, &height)`:使用設定中的文字、字型與大小量測;
忽略位置與顏色,不需要開啟裝置。
- `gvfg_set_channel_osd(handle, channel, osd_index, &config)`:設定並顯示一組 OSD。
函式返回前同步複製文字與字型名稱;設定失敗保留該組原設定。
- `gvfg_set_channel_osd_visible(handle, channel, osd_index, visible)`:`0` 隱藏、`1` 顯示。
保留設定、YUV 字圖、Mask 與 GPU 資源;單純 Hide/Show 不重新產生字圖。
影像尺寸或格式改變仍可能更新資源。尚未設定或已清除的組別不能直接 Show。
- `gvfg_clear_channel_osd(handle, channel, osd_index)`:停用該組並清除設定與字圖快取;
後續須重新 Set 才能顯示,不影響另一組。
`gvfg_channel_osd_config_t` 可設定文字、`x/y`、`font_size_px` 與 `color_rgb`。 `gvfg_channel_osd_config_t` 沒有 `struct_size` 或 `text_length`,欄位順序為:
文字為 1–32 個可列印 ASCII 字元(`0x20`–`0x7e`),使用 Arial-preferred normal 字型;
保持單行,不自動換行。字號必須大於 0;SDK 沒有 viewer 的 512 px UI 上限。
顏色為 `0x00RRGGBB`,轉為 BT.709 limited range 後由 GPU 與影片混合。
量測的 `width/height` 包含排版空白、glyph overhang 及四邊各 1 px 安全邊, ```c
是保守的完整文字框,不是逐像素緊貼的字形邊界。`x/y` 表示這個框的左上角; const char *text; /* NUL 結尾,1–32 個可列印 ASCII 字元 */
SDK 會依實際 frame 限制在 `0..frame.width - text_width`、 const char *font_family; /* NUL 結尾的 UTF-8 字型家族名稱,不是檔案路徑 */
`0..frame.height - text_height`。文字框比 frame 大時,SDK 暫不疊字並繼續擷取; uint32_t font_size_px; /* 大於 0 */
設定或 frame 尺寸改成可容納後會恢復,不會縮字、截字或換行。 uint32_t color_rgb; /* 0x00RRGGBB */
int32_t x;
int32_t y;
```
量測的兩個 output pointer 不可為 NULL;失敗時可寫入的 output 會歸零。 客戶先在 Windows 安裝字型,再重新取得清單,將選到的名稱放入 `font_family`。
無效文字、長度、字號或 pointer 回傳 `GVFG_EINVAL`;量測失敗回傳 `GVFG_EIO`。 只下載但未安裝的字型不會自動列入。字型名稱可為 UTF-8,但 OSD 文字仍只接受
ASCII `0x20`–`0x7e`,不接受中文或換行。清單中的字型不保證含有所有語言的字元。
不存在的字型或無效 UTF-8 名稱回傳 `GVFG_EINVAL`,不靜默改用 Arial。
字型為 normal weight/style/stretch。字級傳給 DirectWrite 的 em 大小,繪製目標固定
96 DPI,因此數值可對應影像像素;不是 Word 的 pt,也不是字形實際墨色高度。
SDK 沒有 viewer 的 512 px UI 上限。顏色轉為 BT.709 limited range,由 GPU 混合。
量測框包含排版空白、glyph overhang 及四邊各 1 px 安全邊,不是 pixel-tight 邊界。
`x/y` 是該框左上角,SDK 依每張影像限制位置,使完整文字框留在影像內。
某組文字框比影像大時,只暫停疊該組;擷取及另一組繼續。設定、尺寸或格式改變後
重新判斷,可容納時恢復,不縮字、截字或換行。
量測失敗時可寫入的尺寸 output 歸零。無效參數、文字、字號、字型或組別回傳
`GVFG_EINVAL`;channel 未 open 或要求顯示未設定的組別回傳 `GVFG_ESTATE`;
其他初始化、量測或資源失敗回傳 `GVFG_EIO`。設定成功不表示已取得的 frame 會被修改。
SDK 不跨 `gvfg_destroy()` 保留設定;viewer 自行保存兩組設定及 visibility,於重新 Start 時還原。
這次是 breaking API 更新:客戶須使用同一版本的 header、import library 與 DLL 重新編譯。
SDK 本身不提供固定角落的預設位置;呼叫端明確傳入 `x/y`。`srcroot` Viewer 的
OSD 1 預設 `(32, 32)`、OSD 2 預設右下角屬於 APP 行為,不是 SDK 自動錨定規則。
### 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()`。
仍可查詢公開 preview/delivery 統計;詳細核心診斷改為私有的 Debug-only 介面,
不屬於客戶 API,也不提供 Release 匯出或穩定 ABI。
- 字型清單不需要 capture handle。先選擇實際已安裝的字型,再量測/設定 OSD,
並檢查每次 API 回傳值。單一組別的 Set 不提供兩組一起更新的交易保證。
### Audio frame ### Audio frame
@@ -265,6 +306,9 @@ SDK 會依實際 frame 限制在 `0..frame.width - text_width`、
### 查詢 ### 查詢
- `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 的連線、尺寸、 - `gvfg_get_channel_signal_status(handle, channel, &status)`:查詢指定 channel 的連線、尺寸、
原生格式與 bit depth。沒有輸入訊號是正常狀態:回傳 `GVFG_OK` 且 原生格式與 bit depth。沒有輸入訊號是正常狀態:回傳 `GVFG_OK` 且
`connected == 0`。Channel 尚未 running 時會向 capture backend 更新;running 期間則回傳 `connected == 0`。Channel 尚未 running 時會向 capture backend 更新;running 期間則回傳
@@ -1,11 +1,14 @@
# GVFG 客戶 API Reference # GVFG 客戶 API Reference
SDK 2.1.1。Capture 與 Playback 使用各自的 API 與狀態碼。 SDK 3.0.0。Capture 與 Playback 使用各自的 API 與狀態碼。
本版含不相容的 OSD 介面更新,並移除公開的 Playback 核心詳細統計查詢。
使用本版 header、import library 與 DLL 重新編譯;不可混用 SDK 2.x 二進位檔案。
- [擷取型別與常數](#1-gvfg-api-結構與常數) - [擷取型別與常數](#1-gvfg-api-結構與常數)
- [擷取函式](#2-gvfg-api-函式) - [擷取函式](#2-gvfg-api-函式)
- [播放影像型別](#3-playback-使用的影像型別) - [播放影像型別](#3-playback-使用的影像型別)
- [播放 API、config、stats 與限制](#4-統一-playback-api) - [播放 API、config 與限制](#4-統一-playback-api)
## 1. GVFG API 結構與常數 ## 1. GVFG API 結構與常數
@@ -18,7 +21,8 @@ SDK 2.1.1。Capture 與 Playback 使用各自的 API 與狀態碼。
| ----------------------- | ------------:| ----------------------------- | | ----------------------- | ------------:| ----------------------------- |
| `GVFG_MAX_DEVICES` | 16 | 一次最多列舉的裝置數 | | `GVFG_MAX_DEVICES` | 16 | 一次最多列舉的裝置數 |
| `GVFG_TIMEOUT_INFINITE` | `UINT32_MAX` | 無限等待;`timeout_ms == 0` 則完全不等待 | | `GVFG_TIMEOUT_INFINITE` | `UINT32_MAX` | 無限等待;`timeout_ms == 0` 則完全不等待 |
| `GVFG_OSD_MAX_TEXT_CHARACTERS` | 32 | OSD 可列印 ASCII 字元數上限 | | `GVFG_OSD_MAX_TEXT_CHARACTERS` | 32 | 每組 OSD 可列印 ASCII 字元數上限 |
| `GVFG_OSD_SLOT_COUNT` | 2 | 每個 channel 的獨立 OSD 組數 |
### 1.2 `gvfg_status_t` ### 1.2 `gvfg_status_t`
@@ -264,21 +268,28 @@ typedef struct gvfg_handle_t *gvfg_handle;
只能由 `gvfg_create()` 建立、由 `gvfg_destroy()` 銷毀;caller 只能由 `gvfg_create()` 建立、由 `gvfg_destroy()` 銷毀;caller
不可取得、配置或修改其內部內容。 不可取得、配置或修改其內部內容。
### 1.20 `gvfg_channel_osd_config_t` ### 1.20 `gvfg_channel_osd_config_t` 與 `gvfg_osd_font_list_t`
由 caller 建立並傳給 `gvfg_set_channel_osd()`。SDK 在函式返回前複製文字及設定, ```c
caller 不必持續保留 `text` pointer。 typedef struct gvfg_channel_osd_config_t {
const char *text;
const char *font_family;
uint32_t font_size_px;
uint32_t color_rgb;
int32_t x;
int32_t y;
} gvfg_channel_osd_config_t;
| 欄位 | 型別 | 說明 | typedef struct gvfg_osd_font_list_t {
| --- | --- | --- | uint32_t count;
| `text` | `const char *` | 可列印 ASCII(`0x20`–`0x7e`),不可為 NULL | const char *const *names;
| `text_length` | `uint32_t` | 1–32 個字元;不包含結尾 NUL | } gvfg_osd_font_list_t;
| `x`、`y` | `int32_t` | 完整量測文字框的左上角,單位 frame pixel;會限制在可完整顯示範圍 | ```
| `font_size_px` | `uint32_t` | 非零字號;SDK 沒有 viewer 的 512 px UI 上限 |
| `color_rgb` | `uint32_t` | `0x00RRGGBB`;忽略最高 8 bits |
使用 Arial-preferred normal 字型,固定單行不換行。文字框包含排版空白、glyph overhang `text` 為 NUL 結尾的 1–32 字元可列印 ASCII;`font_family` 為 NUL 結尾的 UTF-8
及四邊各 1 px 安全邊;用 `gvfg_measure_osd_text()` 取得與繪製相同的保守框大小。 已安裝字型家族名稱。Set 返回前複製兩個字串。沒有 `struct_size`、`text_length`。
`font_size_px` 必須非零;`color_rgb` 為 `0x00RRGGBB`;`x/y` 是文字框左上角影像座標。
字型清單由 SDK 管理,客戶不能修改或 free,使用期限與完整行為見第 2.26 節。
## 2. GVFG API 函式 ## 2. GVFG API 函式
@@ -610,15 +621,18 @@ gvfg_status_t gvfg_get_channel_runtime_info(
- `GVFG_EINVAL`:handle 或 output pointer 為 NULL。 - `GVFG_EINVAL`:handle 或 output pointer 為 NULL。
- `GVFG_ESTATE`:指定 channel 尚未 open。 - `GVFG_ESTATE`:指定 channel 尚未 open。
### 2.21 `gvfg_get_version` ### 2.21 `gvfg_get_version`/`gvfg_get_gigabyte_lib_version`
```c ```c
const char *gvfg_get_version(void); const char *gvfg_get_version(void);
const char *gvfg_get_gigabyte_lib_version(void);
``` ```
- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"2.1.1"`。 - 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"3.0.0"`。
- 回傳值是靜態 null-terminated 字串,caller 不可 free。 - 回傳值是靜態 null-terminated 字串,caller 不可 free。
- 可用於 log、問題回報,以及確認 header、DLL 是否來自同一版本。 - 可用於 log、問題回報,以及確認 header、DLL 是否來自同一版本。
- `gvfg_get_gigabyte_lib_version()` 回傳編譯進目前 runtime 的 GigabyteLib 版本常數,
不是執行時查詢的 driver/FPGA 版本;同樣是靜態字串,不需要 handle,也不可 free。
### 2.22 `gvfg_pixel_format_name` ### 2.22 `gvfg_pixel_format_name`
@@ -662,47 +676,135 @@ gvfg_status_t gvfg_get_channel_last_sdk_error_detail(/* [in] */ gvfg_handle hand
```c ```c
gvfg_status_t gvfg_measure_osd_text( gvfg_status_t gvfg_measure_osd_text(
/* [in] */ const char *text, const gvfg_channel_osd_config_t *config,
/* [in] */ uint32_t text_length, uint32_t *out_width, uint32_t *out_height);
/* [in] */ uint32_t font_size_px,
/* [out] */ uint32_t *out_width,
/* [out] */ uint32_t *out_height);
``` ```
- 不需要 capture handle,不會開啟 device,可在 Start 前量測。 不需要 capture handle;使用與繪製相同的文字、字型及大小,忽略位置及顏色。
- `text`:1–32 個可列印 ASCII 字元(`0x20`–`0x7e`),不接受換行。 輸出為保守完整文字框,包含 overhang 與四邊安全邊;失敗時可寫入的輸出歸零。
- `font_size_px`:必須大於 0;字型、單行排版與 SDK OSD 繪製相同。
- `out_width`、`out_height`:不可為 NULL,接收單位為 pixel 的保守完整文字框。
包含排版空白、glyph overhang 及四邊各 1 px 安全邊,不是 pixel-tight 字形邊界。
- `GVFG_OK`:量測成功。
- `GVFG_EINVAL`:pointer、文字、長度或字號無效,或量測結果超過可表示範圍。
- `GVFG_EIO`:文字量測或配置失敗。失敗時可寫入的 output 會歸零。
### 2.26 `gvfg_set_channel_osd`/`gvfg_clear_channel_osd` ### 2.26 OSD 字型、設定、顯示/隱藏與清除
```c ```c
gvfg_status_t gvfg_get_osd_fonts(gvfg_osd_font_list_t *out_list);
gvfg_status_t gvfg_set_channel_osd( gvfg_status_t gvfg_set_channel_osd(
/* [in] */ gvfg_handle handle, gvfg_handle handle, int channel_index, uint32_t osd_index,
/* [in] */ int channel_index, const gvfg_channel_osd_config_t *config);
/* [in] */ const gvfg_channel_osd_config_t *config); gvfg_status_t gvfg_set_channel_osd_visible(
gvfg_handle handle, int channel_index, uint32_t osd_index, int visible);
gvfg_status_t gvfg_clear_channel_osd( gvfg_status_t gvfg_clear_channel_osd(
/* [in] */ gvfg_handle handle, gvfg_handle handle, int channel_index, uint32_t osd_index);
/* [in] */ int channel_index);
``` ```
- Channel 必須已 open;可在 Start 前或擷取期間設定或停用。 每個已 open 的 channel 支援兩組獨立 OSD,`osd_index` 為 `0` 或 `1`;
- `set` 同步複製設定,套用於後續 YUY2/Y210 frame;文字顏色為 BT.709 limited range, 重疊時第 `1` 組蓋在第 `0` 組上。後續 `gvfg_read_channel_frame()` 交付含 OSD 的
由 GPU 混合。 YUY2/Y210 frame,使用後照常 release。
- `x/y` 是量測文字框左上角。SDK 依每個 frame 把位置限制在
`[0, frame.width - text_width]`/`[0, frame.height - text_height]`。 - `gvfg_get_osd_fonts(&list)`:重新檢查 Windows 已安裝字型,取得當前可用家族名稱。
- 文字框本身比 frame 大時暫不疊字,擷取仍繼續;設定、frame 尺寸或格式變更後重新判斷。 不需要 handle、callback 或客戶端 free。`list.count` 是數量,`list.names[i]` 是 UTF-8 名稱。
可容納時恢復 OSD,不縮字、截字或換行。 清單由 SDK 管理,指標有效到下一次呼叫此函式(包含失敗呼叫)或 DLL 卸載為止;
- `clear` 停用後續 frame 的 OSD。已取得的 frame 仍照原本生命週期使用與 release。 填入 UI 或長期保存時自行複製。呼叫及讀取借用清單須由 caller 序列化。
- `GVFG_OK`:設定或停用成功;不表示文字已完成繪製或一定能放入當前 frame。 - `gvfg_measure_osd_text(&config, &width, &height)`:使用設定中的文字、字型與大小量測;
- `GVFG_EINVAL`:NULL handle/config、無效文字長度、字元或零字號。 忽略位置與顏色,不需要開啟裝置。
- `GVFG_ESTATE`:指定 channel 尚未 open;其他處理失敗可回傳 `GVFG_EIO`。 - `gvfg_set_channel_osd(handle, channel, osd_index, &config)`:設定並顯示一組 OSD。
- 啟用 OSD 的 frame 可能為 SDK-owned output,即使擷取使用 zero-copy; 函式返回前同步複製文字與字型名稱;設定失敗保留該組原設定。
每次成功 read 仍須恰好 release 一次。 - `gvfg_set_channel_osd_visible(handle, channel, osd_index, visible)`:`0` 隱藏、`1` 顯示。
保留設定、YUV 字圖、Mask 與 GPU 資源;單純 Hide/Show 不重新產生字圖。
影像尺寸或格式改變仍可能更新資源。尚未設定或已清除的組別不能直接 Show。
- `gvfg_clear_channel_osd(handle, channel, osd_index)`:停用該組並清除設定與字圖快取;
後續須重新 Set 才能顯示,不影響另一組。
`gvfg_channel_osd_config_t` 沒有 `struct_size` 或 `text_length`,欄位順序為:
```c
const char *text; /* NUL 結尾,1–32 個可列印 ASCII 字元 */
const char *font_family; /* NUL 結尾的 UTF-8 字型家族名稱,不是檔案路徑 */
uint32_t font_size_px; /* 大於 0 */
uint32_t color_rgb; /* 0x00RRGGBB */
int32_t x;
int32_t y;
```
客戶先在 Windows 安裝字型,再重新取得清單,將選到的名稱放入 `font_family`。
只下載但未安裝的字型不會自動列入。字型名稱可為 UTF-8,但 OSD 文字仍只接受
ASCII `0x20`–`0x7e`,不接受中文或換行。清單中的字型不保證含有所有語言的字元。
不存在的字型或無效 UTF-8 名稱回傳 `GVFG_EINVAL`,不靜默改用 Arial。
字型為 normal weight/style/stretch。字級傳給 DirectWrite 的 em 大小,繪製目標固定
96 DPI,因此數值可對應影像像素;不是 Word 的 pt,也不是字形實際墨色高度。
SDK 沒有 viewer 的 512 px UI 上限。顏色轉為 BT.709 limited range,由 GPU 混合。
量測框包含排版空白、glyph overhang 及四邊各 1 px 安全邊,不是 pixel-tight 邊界。
`x/y` 是該框左上角,SDK 依每張影像限制位置,使完整文字框留在影像內。
某組文字框比影像大時,只暫停疊該組;擷取及另一組繼續。設定、尺寸或格式改變後
重新判斷,可容納時恢復,不縮字、截字或換行。
量測失敗時可寫入的尺寸 output 歸零。無效參數、文字、字號、字型或組別回傳
`GVFG_EINVAL`;channel 未 open 或要求顯示未設定的組別回傳 `GVFG_ESTATE`;
其他初始化、量測或資源失敗回傳 `GVFG_EIO`。設定成功不表示已取得的 frame 會被修改。
SDK 不跨 `gvfg_destroy()` 保留設定;viewer 自行保存兩組設定及 visibility,於重新 Start 時還原。
這次是 breaking API 更新:客戶須使用同一版本的 header、import library 與 DLL 重新編譯。
SDK 不自動選擇畫面角落,`x/y` 由 caller 指定。`srcroot` Viewer 中 OSD 1 預設
`(32, 32)`、OSD 2 預設右下角屬於 APP 設定,不是 SDK 提供的持續角落錨定。
### 2.27 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;
```
量測只使用文字、字型與大小;不需要額外開啟裝置。
```cpp
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;
```
## 3. Playback 使用的影像型別 ## 3. Playback 使用的影像型別
@@ -780,8 +882,8 @@ submitted = presented + replaced + busy + failed + cancelled + in_flight
公開標頭為 `gvfg_playback.h`,連結 `gvfg_playback.lib`、部署 `gvfg_playback.dll`。 公開標頭為 `gvfg_playback.h`,連結 `gvfg_playback.lib`、部署 `gvfg_playback.dll`。
MinGW 使用 `libgvfg_playback.dll.a`。 MinGW 使用 `libgvfg_playback.dll.a`。
`gvfg_playback` 是 opaque handle。`config.struct_size`、`stats.struct_size` `gvfg_playback` 是 opaque handle。`config.struct_size` 須設為 config 結構大小;
須設為對應結構大小;config 可先呼叫 `gvfg_playback_default_config()` 填好預設值。 可先呼叫 `gvfg_playback_default_config()` 填好預設值。
音訊格式 `gvfg_audio_playback_format_t` 包含 sample_rate、channels、bits_per_sample, 音訊格式 `gvfg_audio_playback_format_t` 包含 sample_rate、channels、bits_per_sample,
目前支援 signed interleaved PCM16。 目前支援 signed interleaved PCM16。
@@ -799,7 +901,6 @@ MinGW 使用 `libgvfg_playback.dll.a`。
| `gvfg_playback_reset_timeline(p)` | 丟棄待播資料,使用原設定重新建立時間軸 | | `gvfg_playback_reset_timeline(p)` | 丟棄待播資料,使用原設定重新建立時間軸 |
| `gvfg_playback_stop(p)` | 停止播放並丟棄待播資料,可重複呼叫 | | `gvfg_playback_stop(p)` | 停止播放並丟棄待播資料,可重複呼叫 |
| `gvfg_playback_destroy(p)` | 停止並銷毀,NULL 可安全忽略 | | `gvfg_playback_destroy(p)` | 停止並銷毀,NULL 可安全忽略 |
| `gvfg_playback_get_stats(p, stats)` | 共同緩衝、queue、影音進度、誤差及調速資訊 |
| `gvfg_playback_get_preview_info(p, info)` | 影像輸出資訊 | | `gvfg_playback_get_preview_info(p, info)` | 影像輸出資訊 |
| `gvfg_playback_get_preview_stats(p, stats)` | GPU/呈現統計 | | `gvfg_playback_get_preview_stats(p, stats)` | GPU/呈現統計 |
| `gvfg_playback_set_signal_connected(p, connected)` | UI 執行緒轉交訊號狀態:0 顯示 helper 內建 NO SIGNAL 圖卡,1 隱藏 | | `gvfg_playback_set_signal_connected(p, connected)` | UI 執行緒轉交訊號狀態:0 顯示 helper 內建 NO SIGNAL 圖卡,1 隱藏 |
@@ -807,9 +908,9 @@ MinGW 使用 `libgvfg_playback.dll.a`。
| `gvfg_playback_strerror(status)` | 靜態英文錯誤字串,不可 free | | `gvfg_playback_strerror(status)` | 靜態英文錯誤字串,不可 free |
狀態碼為 OK、EINVAL、ESTATE、EOUTPUT、EQUEUE_FULL、EDISCONTINUITY、EAUDIO; 狀態碼為 OK、EINVAL、ESTATE、EOUTPUT、EQUEUE_FULL、EDISCONTINUITY、EAUDIO;
queue 壓力會自動降級並略過過期資料,不要求 caller 因此停止擷取。正常同步時 External/Audio master 會退休過期預覽影格,並累計 queue 壓力會自動降級並略過過期資料,不要求 caller 因此停止擷取。
`video_dropped`;GPU busy 也計為略過,真正 GPU 失敗才回報 EOUTPUT。音訊及獨立錄影不受此預覽策略影響。 正常同步時 External/Audio master 會退休過期預覽影格;GPU busy 也可略過,真正 GPU 失敗才回報 EOUTPUT。
2.0.2 的 get_stats 也接受舊 stats 大小,只寫入呼叫端提供的原始結構範圍。 音訊及獨立錄影不受此預覽策略影響。
submit 返回後 caller 可立即釋放 SDK frame;present_image 則須保留資料到函式返回。 submit 返回後 caller 可立即釋放 SDK frame;present_image 則須保留資料到函式返回。
控制操作(含 present_image)須由 caller 序列化;可由獨立影音 producer 併行 submit。 控制操作(含 present_image)須由 caller 序列化;可由獨立影音 producer 併行 submit。
stop/reset 是取消,不是無損 EOS drain。 stop/reset 是取消,不是無損 EOS drain。
@@ -878,51 +979,16 @@ submit 會複製實際影像列範圍,frame ID 僅作身分/統計資訊,
| -5 | `GVFG_PLAYBACK_EDISCONTINUITY` | 協調 producer,重設時間軸;新音訊格式須以新 config stop/start | | -5 | `GVFG_PLAYBACK_EDISCONTINUITY` | 協調 producer,重設時間軸;新音訊格式須以新 config stop/start |
| -6 | `GVFG_PLAYBACK_EAUDIO` | 影音模式的監聽音效已因輸出故障停用,影像繼續;提示一次,繼續獨立擷取/錄影。此 handle 不再接受音訊,重建 handle 才重試音效 | | -6 | `GVFG_PLAYBACK_EAUDIO` | 影音模式的監聽音效已因輸出故障停用,影像繼續;提示一次,繼續獨立擷取/錄影。此 handle 不再接受音訊,重建 handle 才重試音效 |
影音模式的音訊輸出故障不設定整體 `last_error`;音訊 submit 回傳 `EAUDIO`, 影音模式的音訊輸出故障由音訊 submit 回傳 `EAUDIO`,
影像 submit 繼續。影音 start 遇到音效開啟失敗仍可成功,音訊 submit 會回報 `EAUDIO`。 影像 submit 繼續。影音 start 遇到音效開啟失敗仍可成功,音訊 submit 會回報 `EAUDIO`。
停用狀態跨 stop/start/reset 保留;重建 handle 才重試音效。純音訊模式仍視為輸出失敗。 停用狀態跨 stop/start/reset 保留;重建 handle 才重試音效。純音訊模式仍視為輸出失敗。
其他非同步輸出錯誤會保存在 `last_error`,後續 submit 會回傳此錯誤。 其他非同步輸出錯誤會由後續 submit 回報。start 成功不保證後續輸出一定正常。
`running` 仍可能為 1,因此不能只看 running 判斷輸出健康。
### 4.5 `gvfg_playback_stats_t` ### 4.5 控制 API 的細節
一般 Customer Demo 不需要定期顯示本表;診斷或整合工具可自行查詢。
先設 `stats.struct_size = sizeof(stats)`。getter 也接受 2.0.0/2.0.1 與 2.0.2/2.0.3 的 stats 大小,
只回填舊結構範圍;config 並未因此接受任意大小。
| 欄位 | 定義 |
|---|---|
| `struct_size` | caller 的有效結構大小 |
| `running` | Playback 是否已 start 且尚未 stop,不是輸出健康保證 |
| `buffering` | 正在等初始/重新緩衝,或因持續錯誤暫停 |
| `last_error` | 共用 worker 的持續錯誤;查詢 API 返回 OK 不表示此欄也為 OK |
| `video_submitted` | 成功接受的來源影像張數 |
| `video_processed` | 已呈現、隱藏消化或已計數略過的張數 |
| `video_presented` | 成功被 DXGI Present 接受的張數,不代表完成螢幕 scanout |
| `audio_submitted` | 成功接受的音訊 packet 數,不是 sample 數 |
| `queue_rejections` | 保留的容量拒收計數;一般 queue 壓力會自動降級/略過,不增加此值 |
| `rebuffer_count` | 已運行時間軸重新進入共同緩衝的次數 |
| `video_queue_bytes` | CPU 影像副本 bytes,包含 worker 目前處理中的副本 |
| `video_queue_frames` | 共用待播 deque 張數,不含已移交 worker 的單張 |
| `audio_queue_ms` | 共用 PCM queue 加上音訊輸出端待播 frames 的估計毫秒數 |
| `video_timestamp_ns` | 最近完成影像處理所記錄的來源時間;隱藏模式也可推進,不是實體 scanout 時間 |
| `audio_timestamp_ns` | 已消耗音訊 frames 換算的來源位置估計,不是麥克風量得的發聲時間 |
| `av_difference_ns` | worker 保存的 audio 減 video clock 差值;兩個 clock 有效時才有意義,不是同時刻外部量測 |
| `audio_rate_ratio` | 最近給輸出端的速率比例,1.0 表示不補償 |
| `video_dropped` | 2.0.2 新增,過期退休與 GPU-busy 等預覽略過數,不是 capture/recording loss |
| `sync_degraded` | 1 表示目前獨立播放,不等待另一路完成同步;0 表示正常同步流程 |
| `sync_fallbacks` | 本次 start 後進入獨立播放的次數 |
| `audio_dropped_frames` | 從 Playback 共用 queue 丟棄的 PCM sample frames;不含 WASAPI reset 取消的 padding,不是擷取遺失數 |
不要把 submitted、processed、presented 視為必定相等。初始/共同緩衝、隱藏顯示、
過期略過、in-flight 與 stop/reset 取消,都會影響計數關係。
### 4.6 控制 API 的細節
`gvfg_playback_set_sync_enabled(p, enabled)` 接受 0 或 1,其他值/NULL handle 回傳 EINVAL。 `gvfg_playback_set_sync_enabled(p, enabled)` 接受 0 或 1,其他值/NULL handle 回傳 EINVAL。
可在 start 前或運行中呼叫;0 立即使用獨立播放且不自動恢復同步,1 在條件穩定後恢復同步。 可在 start 前或運行中呼叫;0 立即使用獨立播放且不自動恢復同步,1 在條件穩定後恢復同步。
設定保留到 stop/start、reset_timeline;重新 create 的 handle 預設為 1。 設定保留到 stop/start、reset_timeline;重新 create 的 handle 預設為 1。
主動關閉同步也會使 `sync_degraded` 為 1,但不增加 `sync_fallbacks`。
| API | 狀態、ownership 與限制 | | API | 狀態、ownership 與限制 |
|---|---| |---|---|
@@ -937,7 +1003,6 @@ submit 會複製實際影像列範圍,frame ID 僅作身分/統計資訊,
| `reset_timeline(p)` | stop、清畫面、若原本 active 則用原 config start;未建立呈現表面(swapchain)的空畫面視為清除成功;會取消舊 queue,真正的清畫面或重啟失敗仍回報錯誤 | | `reset_timeline(p)` | stop、清畫面、若原本 active 則用原 config start;未建立呈現表面(swapchain)的空畫面視為清除成功;會取消舊 queue,真正的清畫面或重啟失敗仍回報錯誤 |
| `stop(p)` | 可重複呼叫;join 共用 worker、銷毀音訊輸出並清 queue;保留 Preview 物件供後續重用 | | `stop(p)` | 可重複呼叫;join 共用 worker、銷毀音訊輸出並清 queue;保留 Preview 物件供後續重用 |
| `destroy(p)` | NULL 安全;stop 後銷毀 Preview 與 handle | | `destroy(p)` | NULL 安全;stop 後銷毀 Preview 與 handle |
| `get_stats(p, stats)` | 驗證 struct_size,回填共同快照;沒有音訊輸出時不建立它 |
| `get_preview_info(p, info)` | 回傳影像資訊;尚未建立 Preview 時為零值 | | `get_preview_info(p, info)` | 回傳影像資訊;尚未建立 Preview 時為零值 |
| `get_preview_stats(p, stats)` | 回傳呈現 FPS/計數;尚未建立 Preview 時為零值 | | `get_preview_stats(p, stats)` | 回傳呈現 FPS/計數;尚未建立 Preview 時為零值 |
| `set_signal_connected(p, connected)` | 僅接受 0/1,預設 1。0 顯示 helper 內建圖卡、1 隱藏。可在 attach 前設定,跨 stop/start/reset/reattach 保留;與 attach/destroy 在 HWND 執行緒序列化。圖卡隨視窗縮放,detach/destroy 釋放。此 API 不查詢 Capture、不更動影格或同步、不依 FPS 判斷訊號 | | `set_signal_connected(p, connected)` | 僅接受 0/1,預設 1。0 顯示 helper 內建圖卡、1 隱藏。可在 attach 前設定,跨 stop/start/reset/reattach 保留;與 attach/destroy 在 HWND 執行緒序列化。圖卡隨視窗縮放,detach/destroy 釋放。此 API 不查詢 Capture、不更動影格或同步、不依 FPS 判斷訊號 |
+2 -2
View File
@@ -51,8 +51,8 @@ Playback 的錯誤型別是 gvfg_playback_status_t:OK=0、EINVAL=-1、ESTATE=-
EOUTPUT=-3、EQUEUE_FULL=-4、EDISCONTINUITY=-5。 EOUTPUT=-3、EQUEUE_FULL=-4、EDISCONTINUITY=-5。
例如 Capture 的 -4 是 EIO,Playback 的 -4 是 queue full;這正是不能混用 strerror 的原因。 例如 Capture 的 -4 是 EIO,Playback 的 -4 是 queue full;這正是不能混用 strerror 的原因。
submit 是接受/複製,不是實體輸出完成。非同步 GPU/WASAPI 失敗會保存為 last_error, submit 是接受/複製,不是實體輸出完成。其他非同步輸出失敗會由後續 submit 回報;
後續 submit 回報該錯誤;running 仍可能為 1。get_stats 回傳 OK 只是查詢成功。 start 或 submit 成功不保證後續輸出一定正常。
目前輸出錯誤沒有自動重建裝置的保證,由 caller 協調停止與重啟。 目前輸出錯誤沒有自動重建裝置的保證,由 caller 協調停止與重啟。
| 情況 | ownership 與後續處理 | | 情況 | ownership 與後續處理 |
+2 -2
View File
@@ -49,11 +49,11 @@ SDK 配置交付 buffer;Playback 接受 PCM16 後另有自己的副本。
| start 後初始緩衝 | 等啟用串流與時間覆蓋範圍;音訊暫停,先準備 GPU | | start 後初始緩衝 | 等啟用串流與時間覆蓋範圍;音訊暫停,先準備 GPU |
| 播放中 | 根據 master 排程,音訊補足小段輸出 lead,影像到期才提交 | | 播放中 | 根據 master 排程,音訊補足小段輸出 lead,影像到期才提交 |
| 重新緩衝 | 覆蓋範圍用盡,暫停共同時鐘與音訊,等待補足 | | 重新緩衝 | 覆蓋範圍用盡,暫停共同時鐘與音訊,等待補足 |
| 持續輸出錯誤 | last_error 保存錯誤,後續 submit 回報,等待 caller 處理 | | 持續輸出錯誤 | 後續 submit 回報同一錯誤,等待 caller 處理 |
| stop | join worker、清 queue、結束音訊輸出;保留可重用的 Preview 物件 | | stop | join worker、清 queue、結束音訊輸出;保留可重用的 Preview 物件 |
| destroy | stop,再銷毀 Preview 與 handle | | destroy | stop,再銷毀 Preview 與 handle |
`running=1` 只表示 session 已啟動,不能取代 last_error 檢查。 start 成功只表示 session 已啟動,仍須處理後續 submit 回傳的輸出錯誤。
External/Audio master 的過期預覽可退休;未到期 frame 不提前顯示,音訊不因此任意丟包。 External/Audio master 的過期預覽可退休;未到期 frame 不提前顯示,音訊不因此任意丟包。
隱藏預覽仍消化影像時間軸,不可停止 video submit 卻保留影音模式。 隱藏預覽仍消化影像時間軸,不可停止 video submit 卻保留影音模式。
+1 -1
View File
@@ -1,6 +1,6 @@
# GVFG 文件閱讀入口 # GVFG 文件閱讀入口
更新於 2026-10-22;SDK 2.1.1。以下連結以目前 source tree 為準。 更新於 2026-10-29;SDK 3.0.0。以下連結以目前 source tree 為準。
## 客戶與 Demo 使用者 ## 客戶與 Demo 使用者
+2 -2
View File
@@ -1,6 +1,6 @@
# GVFG 統一影音播放使用手冊 # GVFG 統一影音播放使用手冊
適用於 SDK 2.1.1。應用程式使用 `gvfg_capture.h` 擷取資料,使用 適用於 SDK 3.0.0。應用程式使用 `gvfg_capture.h` 擷取資料,使用
`gvfg_playback.h` 播放;時鐘、共同緩衝及影音同步由 Playback 管理。 `gvfg_playback.h` 播放;時鐘、共同緩衝及影音同步由 Playback 管理。
## 1. 連結與部署 ## 1. 連結與部署
@@ -154,7 +154,7 @@ bool SubmitOneAudio(gvfg_handle capture, int channel, gvfg_playback player)
Playback 自動降級:影像持續顯示最新可用影格,音訊以正常速率播放並丟棄積壓的待播資料。 Playback 自動降級:影像持續顯示最新可用影格,音訊以正常速率播放並丟棄積壓的待播資料。
沒有音訊資料時保持靜音,不會因為等待音訊而持續凍結影像;資料不足仍可能聽見音訊間斷。 沒有音訊資料時保持靜音,不會因為等待音訊而持續凍結影像;資料不足仍可能聽見音訊間斷。
來源與輸出穩定後會自動恢復同步,重新對齊時可能短暫保留目前畫面。 來源與輸出穩定後會自動恢復同步,重新對齊時可能短暫保留目前畫面。
`sync_degraded`、`sync_fallbacks`、`audio_dropped_frames` 可供整合工具查詢;應用程式不需實作降級控制。 降級、待播資料丟棄與恢復由 Playback 內部處理,應用程式不需另寫控制邏輯。
submit 返回 OK 表示資料已由播放器管理,包含略過顯示或丟棄待播副本的情況;不保證每筆都輸出。 submit 返回 OK 表示資料已由播放器管理,包含略過顯示或丟棄待播副本的情況;不保證每筆都輸出。
單張影像/單包 PCM 超出其設定容量屬於 `EINVAL`,應修正 config 或輸入大小。 單張影像/單包 PCM 超出其設定容量屬於 `EINVAL`,應修正 config 或輸入大小。
+7 -2
View File
@@ -1,6 +1,11 @@
# GVFG SDK 與 Demo 建置說明 # GVFG SDK 與 Demo 建置說明
SDK version 由 `GVFG_SDK/CMakeLists.txt` 決定,目前為 2.1.1。 SDK version 由 `GVFG_SDK/CMakeLists.txt` 決定,目前為 3.0.0。
修改共用類別的成員配置或公開 API 後,先完整重建 SDK,再清理並重建使用它的 APP。
連結成功不代表 object 使用相同的類別大小;標頭相依追蹤失效時,舊 object 可能造成
heap corruption。SDK 3.0.0 的 OSD 與 Playback 統計介面含不相容變更,部署時必須配套
使用同版 header、import library 與 DLL,不可只替換單一檔案。
Sample version 由自己的 CMake 決定;目前 checkout 是內部分支,與 customer master 不必相同。 Sample version 由自己的 CMake 決定;目前 checkout 是內部分支,與 customer master 不必相同。
SDK Debug 在原有等待流程實際收到格式事件時,透過 `OutputDebugStringA()` SDK Debug 在原有等待流程實際收到格式事件時,透過 `OutputDebugStringA()`
@@ -112,6 +117,6 @@ package_release.bat "C:\path\to\gvfg_qt_preview.exe" "C:\Qt\6.10.2\msvc2022_64\b
| 找不到 Playback symbol | 標頭、匯入庫、DLL 不配套,或誤連內部靜態 backend | | 找不到 Playback symbol | 標頭、匯入庫、DLL 不配套,或誤連內部靜態 backend |
| Sample 沒找到預建 SDK | 確認來源選擇、bin/lib 位置、MSVC/MinGW 匯入庫檔名 | | Sample 沒找到預建 SDK | 確認來源選擇、bin/lib 位置、MSVC/MinGW 匯入庫檔名 |
| 視窗關閉後音訊停止 | 確認沒有停止 video producer 卻保留 audio-video 模式;隱藏預覽仍需影像時間軸 | | 視窗關閉後音訊停止 | 確認沒有停止 video producer 卻保留 audio-video 模式;隱藏預覽仍需影像時間軸 |
| 狀態顯示 running 但無輸出 | 檢查 start/submit 回傳、last_error、buffering 與啟用串流資料 | | 已 start 但無輸出 | 檢查 start/submit 回傳與啟用串流資料;詳細狀態使用 Debug DLL 與私有 playback_debug.h 查詢 |
本次文件變更只驗證文件/來源、範例與安裝規則;不因文件改版宣稱新增硬體測試。 本次文件變更只驗證文件/來源、範例與安裝規則;不因文件改版宣稱新增硬體測試。