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:
@@ -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
|
||||
separate customer DLL.
|
||||
|
||||
The initial API supports:
|
||||
The helper supports:
|
||||
|
||||
- YUY2 and Y210 output
|
||||
- printable ASCII text, up to 32 characters
|
||||
- Arial-preferred font with DirectWrite fallback, configurable pixel size,
|
||||
RGB color, and `(x, y)` position
|
||||
- caller-selected installed font family (UTF-8), configurable pixel size,
|
||||
RGB color, and `(x, y)` position; missing families are rejected
|
||||
- one non-wrapping line, with a shared DirectWrite layout for measurement and
|
||||
rendering at 96 DPI
|
||||
- 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
|
||||
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
|
||||
detects that case before rendering and temporarily bypasses OSD while keeping
|
||||
capture and the requested OSD settings active. It retries when the settings,
|
||||
detects that case before rendering and temporarily skips only the oversized slot,
|
||||
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
|
||||
the text to make it fit.
|
||||
|
||||
For live SDK OSD, `GpuOsdProcessor` caches the non-zero mask bounds, aligned
|
||||
to complete YUV422 pixel pairs. Only this rectangle is uploaded, blended,
|
||||
and read back each frame. For non-zero-copy acquisition, the backend explicitly
|
||||
For live SDK OSD, each channel owns two independently configured slots. Each
|
||||
slot caches its YUV and A8 mask. The shared ROI is the union of both slots'
|
||||
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
|
||||
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.
|
||||
|
||||
@@ -26,7 +26,7 @@ typedef enum 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
|
||||
* characters on one line without wrapping. color_rgb is 0xRRGGBB.
|
||||
* 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 pixel_format;
|
||||
const char *text;
|
||||
const char *font_family; /* UTF-8, NUL-terminated. */
|
||||
uint32_t text_length;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
@@ -73,9 +74,13 @@ gvfg_osd_status_t gvfg_osd_measure(
|
||||
const char *text,
|
||||
uint32_t text_length,
|
||||
uint32_t font_size_px,
|
||||
const char *font_family,
|
||||
uint32_t *out_width,
|
||||
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_handle handle,
|
||||
const gvfg_osd_config_t *config,
|
||||
|
||||
@@ -10,22 +10,38 @@
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <new>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
namespace
|
||||
{
|
||||
struct MeasuredTextLayout
|
||||
{
|
||||
ComPtr<IDWriteTextLayout> layout;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
float drawOffsetX = 0;
|
||||
float drawOffsetY = 0;
|
||||
};
|
||||
|
||||
struct OsdContext
|
||||
{
|
||||
ComPtr<IWICImagingFactory> wic;
|
||||
ComPtr<ID2D1Factory> d2d;
|
||||
ComPtr<IDWriteFactory> dwrite;
|
||||
bool ownsComInitialization = false;
|
||||
std::string cachedText;
|
||||
std::string cachedFontFamily;
|
||||
uint32_t cachedFontSizePx = 0;
|
||||
MeasuredTextLayout cachedLayout;
|
||||
|
||||
~OsdContext()
|
||||
{
|
||||
cachedLayout.layout.Reset();
|
||||
dwrite.Reset();
|
||||
d2d.Reset();
|
||||
wic.Reset();
|
||||
@@ -85,25 +101,59 @@ std::wstring widenAscii(const char *text, uint32_t length)
|
||||
return result;
|
||||
}
|
||||
|
||||
struct MeasuredTextLayout
|
||||
bool utf8FontName(const char *name, std::wstring &wide)
|
||||
{
|
||||
ComPtr<IDWriteTextLayout> layout;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
float drawOffsetX = 0;
|
||||
float drawOffsetY = 0;
|
||||
};
|
||||
if (!name || !*name)
|
||||
return false;
|
||||
// Bound input scans and reject malformed UTF-8 rather than substitute.
|
||||
const size_t length = strnlen_s(name, 4096);
|
||||
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,
|
||||
uint32_t textLength, uint32_t fontSizePx,
|
||||
uint32_t textLength, uint32_t fontSizePx, const char *fontFamily,
|
||||
MeasuredTextLayout &result)
|
||||
{
|
||||
if (!validAscii(text, textLength) || fontSizePx == 0)
|
||||
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;
|
||||
HRESULT hr = context.dwrite->CreateTextFormat(
|
||||
L"Arial", nullptr, DWRITE_FONT_WEIGHT_NORMAL,
|
||||
hr = context.dwrite->CreateTextFormat(
|
||||
wideFamily.c_str(), fonts.Get(), DWRITE_FONT_WEIGHT_NORMAL,
|
||||
DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
|
||||
static_cast<float>(fontSizePx), L"en-us", &format);
|
||||
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.drawOffsetX = static_cast<float>(-left);
|
||||
result.drawOffsetY = static_cast<float>(-top);
|
||||
context.cachedFontFamily = fontFamily;
|
||||
context.cachedText.swap(cacheKey);
|
||||
context.cachedFontSizePx = fontSizePx;
|
||||
context.cachedLayout = result;
|
||||
return GVFG_OSD_OK;
|
||||
}
|
||||
|
||||
@@ -178,7 +232,7 @@ gvfg_osd_status_t renderMask(OsdContext &context,
|
||||
{
|
||||
MeasuredTextLayout textLayout;
|
||||
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)
|
||||
return layoutStatus;
|
||||
if (textLayout.width > config.width || textLayout.height > config.height)
|
||||
@@ -188,14 +242,14 @@ gvfg_osd_status_t renderMask(OsdContext &context,
|
||||
|
||||
ComPtr<IWICBitmap> bitmap;
|
||||
HRESULT hr = context.wic->CreateBitmap(config.width, config.height,
|
||||
GUID_WICPixelFormat32bppPBGRA,
|
||||
GUID_WICPixelFormat8bppAlpha,
|
||||
WICBitmapCacheOnLoad, &bitmap);
|
||||
if (FAILED(hr))
|
||||
return GVFG_OSD_ERENDER;
|
||||
|
||||
D2D1_RENDER_TARGET_PROPERTIES properties = D2D1::RenderTargetProperties(
|
||||
D2D1_RENDER_TARGET_TYPE_SOFTWARE,
|
||||
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
|
||||
D2D1::PixelFormat(DXGI_FORMAT_A8_UNORM,
|
||||
D2D1_ALPHA_MODE_PREMULTIPLIED),
|
||||
96.0f, 96.0f);
|
||||
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;
|
||||
uint8_t *destinationRow = destination + static_cast<size_t>(y) * destinationStride;
|
||||
for (uint32_t x = 0; x < config.width; ++x)
|
||||
destinationRow[x] = sourceRow[x * 4u + 3u];
|
||||
// The A8 bitmap already contains one coverage byte per pixel.
|
||||
std::memcpy(destinationRow, sourceRow, config.width);
|
||||
}
|
||||
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,
|
||||
const char *text, uint32_t text_length,
|
||||
uint32_t font_size_px,
|
||||
const char *font_family,
|
||||
uint32_t *out_width, uint32_t *out_height)
|
||||
{
|
||||
if (out_width)
|
||||
@@ -352,7 +407,7 @@ gvfg_osd_status_t gvfg_osd_measure(gvfg_osd_handle handle,
|
||||
{
|
||||
MeasuredTextLayout layout;
|
||||
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)
|
||||
return status;
|
||||
*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,
|
||||
const gvfg_osd_config_t *config,
|
||||
const gvfg_osd_output_t *output)
|
||||
|
||||
Reference in New Issue
Block a user