Consolidate playback APIs and add standalone OSD bitmap rendering

- move public PCM, image and presentation types into gvfg_playback.h and remove the separate backend headers from source and installation

- keep WASAPI and D3D backends private while preserving the existing public type names, fields and static backend integration

- move detailed preview delivery counters into a private header and expose their playback query only through the Debug diagnostics API

- retain public preview information and basic presentation statistics, mark EQUEUE_FULL as reserved, and document capacity limits as advanced settings with recommended defaults

- refresh customer guides, API reference and error handling for the single-header interface, presentation counter limits and EAUDIO handle-recreation policy

- add SDK-owned standalone premultiplied BGRA text rendering with transparent backgrounds, measured dimensions, thread-local snapshot lifetime and validated output bounds

Validation: git diff --cached --check passed. Release gvfg_playback and Customer Sample builds, standalone C/C++ header checks, Debug playback syntax checks and Release export inspection passed earlier in this session. Final follow-up changes affect comments and documentation only. No runtime or hardware playback validation was performed. The existing Release gvfg target was also checked and was up to date. OSD rendering changes were source-reviewed; no new bitmap or hardware test was run in this commit pass. Capture debug exports are unchanged.
This commit is contained in:
Mark.lin
2026-11-04 16:53:41 +08:00
parent d6935df9ae
commit 5ebe03a2bb
23 changed files with 262 additions and 156 deletions
+43 -10
View File
@@ -225,10 +225,11 @@ gvfg_osd_status_t createTextLayout(OsdContext &context, const char *text,
return GVFG_OSD_OK;
}
gvfg_osd_status_t renderMask(OsdContext &context,
const gvfg_osd_config_t &config,
uint8_t *destination,
uint32_t destinationStride)
gvfg_osd_status_t renderBitmap(OsdContext &context,
const gvfg_osd_config_t &config,
uint8_t *destination,
uint32_t destinationStride,
bool bgra = false)
{
MeasuredTextLayout textLayout;
const gvfg_osd_status_t layoutStatus = createTextLayout(
@@ -242,14 +243,14 @@ gvfg_osd_status_t renderMask(OsdContext &context,
ComPtr<IWICBitmap> bitmap;
HRESULT hr = context.wic->CreateBitmap(config.width, config.height,
GUID_WICPixelFormat8bppAlpha,
bgra ? 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_A8_UNORM,
D2D1::PixelFormat(bgra ? DXGI_FORMAT_B8G8R8A8_UNORM : DXGI_FORMAT_A8_UNORM,
D2D1_ALPHA_MODE_PREMULTIPLIED),
96.0f, 96.0f);
ComPtr<ID2D1RenderTarget> target;
@@ -258,7 +259,8 @@ gvfg_osd_status_t renderMask(OsdContext &context,
return GVFG_OSD_ERENDER;
ComPtr<ID2D1SolidColorBrush> brush;
hr = target->CreateSolidColorBrush(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f), &brush);
hr = target->CreateSolidColorBrush(
D2D1::ColorF(bgra ? (config.color_rgb & 0xffffffu) : 0xffffffu, 1.0f), &brush);
if (FAILED(hr))
return GVFG_OSD_ERENDER;
@@ -285,12 +287,16 @@ gvfg_osd_status_t renderMask(OsdContext &context,
FAILED(lock->GetDataPointer(&sourceSize, &source)) || !source)
return GVFG_OSD_ERENDER;
const uint32_t rowBytes = config.width * (bgra ? 4u : 1u);
if (sourceStride < rowBytes ||
static_cast<uint64_t>(sourceStride) * (config.height - 1u) + rowBytes > sourceSize)
return GVFG_OSD_ERENDER;
for (uint32_t y = 0; y < config.height; ++y)
{
const uint8_t *sourceRow = source + static_cast<size_t>(y) * sourceStride;
uint8_t *destinationRow = destination + static_cast<size_t>(y) * destinationStride;
// The A8 bitmap already contains one coverage byte per pixel.
std::memcpy(destinationRow, sourceRow, config.width);
// Copy native WIC pixels without changing channels or alpha.
std::memcpy(destinationRow, sourceRow, rowBytes);
}
return GVFG_OSD_OK;
}
@@ -534,7 +540,7 @@ gvfg_osd_status_t gvfg_osd_render(gvfg_osd_handle handle,
try
{
std::memset(output->mask_data, 0, static_cast<size_t>(requiredMask));
const gvfg_osd_status_t maskStatus = renderMask(
const gvfg_osd_status_t maskStatus = renderBitmap(
*static_cast<OsdContext *>(handle), *config,
static_cast<uint8_t *>(output->mask_data), output->mask_stride);
if (maskStatus != GVFG_OSD_OK)
@@ -557,6 +563,33 @@ gvfg_osd_status_t gvfg_osd_render(gvfg_osd_handle handle,
}
}
gvfg_osd_status_t gvfg_osd_render_bgra(gvfg_osd_handle handle,
const gvfg_osd_config_t *config,
void *data, uint64_t data_size, uint32_t stride)
{
if (!handle || !config || !data ||
config->struct_size != sizeof(gvfg_osd_config_t) ||
!validAscii(config->text, config->text_length) || config->font_size_px == 0 ||
config->width == 0 || config->height == 0 ||
config->width > static_cast<uint32_t>((std::numeric_limits<INT>::max)()) ||
config->height > static_cast<uint32_t>((std::numeric_limits<INT>::max)()) ||
static_cast<uint64_t>(config->width) * 4u > stride)
return GVFG_OSD_EINVAL;
uint64_t bytes = 0;
if (!checkedImageBytes(stride, config->height, bytes) || data_size < bytes ||
bytes > (std::numeric_limits<UINT>::max)() ||
bytes > (std::numeric_limits<size_t>::max)())
return GVFG_OSD_EINVAL;
try
{
std::memset(data, 0, static_cast<size_t>(bytes));
return renderBitmap(*static_cast<OsdContext *>(handle), *config,
static_cast<uint8_t *>(data), stride, true);
}
catch (const std::bad_alloc &) { return GVFG_OSD_ENOMEM; }
catch (...) { return GVFG_OSD_ERENDER; }
}
const char *gvfg_osd_strerror(gvfg_osd_status_t status)
{
switch (status)