From b4403fe59a1db0ed012e8958df73090ac94a3b96 Mon Sep 17 00:00:00 2001 From: "Mark.lin" Date: Mon, 19 Oct 2026 16:41:15 +0800 Subject: [PATCH] Release SDK 1.1.0 with bounded OSD placement and delivery diagnostics - expose stateless OSD text measurement and use matching single-line glyph bounds, overhang, and guard pixels to clamp placement within each frame without wrapping or truncating oversized text - reuse the held SDK-owned capture buffer for non-zero-copy OSD, preserve its stride and size, and overwrite only the GPU-processed rectangle while retaining the backend hold until application release - add internal timed and profiled frame reads with acquisition timing after the frame event wait, per-stage OSD wall times, and unchanged public frame timestamps and existing timing layouts - isolate driver-buffer writes behind a default-OFF experimental build option, validate committed writable pages before ROI writes, retain independent-output fallback, and expose per-frame rejection details without changing vendor release rules - bump the SDK version from 1.0.2 to 1.1.0 and document minor-version feature releases, patch-version bug fixes, placement behavior, ownership, diagnostics, and experimental DMA limitations Validation: git diff --cached --check passed before commit. No SDK rebuild or Customer Demo regression suite was run in this commit pass. User-provided capture logs exercised delivery diagnostics and showed PAGE_READONLY fallback; successful driver-buffer writes and DMA ownership safety remain unverified. --- GVFG_SDK/CMakeLists.txt | 9 +- GVFG_SDK/helpers/gvfg_osd/README.md | 89 ++++++- GVFG_SDK/helpers/gvfg_osd/include/gvfg_osd.h | 14 +- GVFG_SDK/helpers/gvfg_osd/src/gvfg_osd.cpp | 199 +++++++++++++--- GVFG_SDK/sdk/gvfg/CMakeLists.txt | 3 + GVFG_SDK/sdk/gvfg/gvfg.def | 5 + GVFG_SDK/sdk/gvfg/include/gvfg_capture.h | 24 +- GVFG_SDK/sdk/gvfg/include/gvfg_debug.h | 110 +++++++++ .../src/gigabyte/gigabyte_capture_session.cpp | 42 +++- .../src/gigabyte/gigabyte_capture_session.h | 10 +- GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.cpp | 222 ++++++++++++++++-- GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.h | 14 +- GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp | 173 +++++++++++++- docs/GVFG_CUSTOMER_API.md | 35 ++- .../GVFG_CUSTOMER_API_REFERENCE.md | 67 +++++- docs/INTERNAL_BUILD_GUIDE.md | 6 + 16 files changed, 946 insertions(+), 76 deletions(-) diff --git a/GVFG_SDK/CMakeLists.txt b/GVFG_SDK/CMakeLists.txt index 95fcbf2..3056dd9 100644 --- a/GVFG_SDK/CMakeLists.txt +++ b/GVFG_SDK/CMakeLists.txt @@ -2,7 +2,14 @@ cmake_minimum_required(VERSION 3.16) project(gvfg_sdk LANGUAGES CXX) -set(GVFG_SDK_VERSION "1.0.2") +# Version policy: new features bump MINOR and reset PATCH; bug fixes bump PATCH. +set(GVFG_SDK_VERSION "1.1.0") + +option(GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE + "UNSAFE local experiment: write OSD into driver zero-copy buffers" OFF) +if (GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE) + message(WARNING "EXPERIMENTAL driver-buffer writes enabled. Writable pages do not guarantee DMA ownership. Do not ship this build.") +endif() include(GNUInstallDirs) diff --git a/GVFG_SDK/helpers/gvfg_osd/README.md b/GVFG_SDK/helpers/gvfg_osd/README.md index 21a9438..f60b612 100644 --- a/GVFG_SDK/helpers/gvfg_osd/README.md +++ b/GVFG_SDK/helpers/gvfg_osd/README.md @@ -12,6 +12,8 @@ The initial API supports: - printable ASCII text, up to 32 characters - Arial-preferred font with DirectWrite fallback, configurable pixel size, RGB color, and `(x, y)` position +- one non-wrapping line, with a shared DirectWrite layout for measurement and + rendering at 96 DPI - BT.709 limited-range RGB-to-YUV conversion - an 8-bit coverage mask (`0` transparent, `255` fully covered) @@ -19,9 +21,88 @@ The caller owns all output memory. Width must be even. YUY2 requires at least `width * 2` bytes per output row; Y210 requires `width * 4`. The mask requires at least `width` bytes per row. +`gvfg_osd_measure()` returns a conservative complete text box containing logical +spacing, glyph overhang, and a one-pixel guard on each edge. It is not a +pixel-tight raster bound. The public `gvfg_measure_osd_text()` API in `gvfg.dll` +provides the same measurement without creating a capture handle or opening a +device. Font size must be non-zero; the SDK does not impose the viewer's +512-pixel UI limit. + +`x` and `y` identify the top-left of this measured box. Rendering clamps them +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, +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. The SDK preserves the complete native frame with -memory copies and replaces the processed rectangle; CPU code does not blend -pixels. Text with no visible coverage bypasses processing. The public frame -format and read/release contract remain unchanged. +and read back each frame. 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. +The backend frame stays held until the application's normal release, including +across signal-recovery requests. The application still receives read-only data. + +By default, driver zero-copy acquisition grants no writable access. The SDK still +copies the complete native frame into independent output storage, replaces +the processed rectangle there, and releases the backend frame before delivery. +CPU code copies bytes but does not blend pixels. Text with no visible coverage +bypasses processing. The public frame and read/release ABI remain unchanged. + +Internal tools can use `gvfg_debug_read_channel_frame_timed()` from +`gvfg_debug.h` to obtain per-frame CPU wall times for OSD lock/surface/preparation, +ROI upload, command submission, full-frame copy, readback Map wait, ROI overwrite, +and pre-delivery backend release. The result is tied to the returned `frame_id`; +`osd_applied` reports whether that frame was actually blended. `process_total` +includes the process sub-stages and must not be added to them again. +Submission time is not GPU execution time, and readback wait includes unfinished +earlier GPU work. Normal public reads do not collect these timings. The timed +path introduces clock reads only, not new GPU queries, Flush, or synchronization. +In-place non-zero-copy OSD reports zero full-frame-copy and pre-delivery backend +release time; the actual backend release is deferred to application release. +`gvfg_debug_read_channel_frame_profiled()` additionally returns +`acquisition_begin_ns`, sampled after the frame event wait succeeds and before +buffer preparation or vendor data retrieval/copy. From this timestamp to the +returned frame timestamp is acquisition cost (including required capture copies); +to application receipt is acquisition plus OSD/delivery cost. Waiting for the +next frame is excluded. The public frame timestamp and old timed-read ABI are +unchanged; this uses a separate internal result type and export. +Do not ship the internal debug header in customer packages. + +### Unsafe local zero-copy experiment (default OFF) + +Set `GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE=ON` in the standalone SDK's +CMake configuration, rebuild `gvfg.dll` and its import library, then rebuild +the srcroot viewer against the matching SDK. Enable zero-copy and apply OSD. +This is an SDK build option, not the viewer console option. + +The experimental backend supplies the original mutable vendor pointer, without +casting away const on the public API. Before processing, `VirtualQuery` checks +the entire destination ROI span for committed `PAGE_READWRITE` pages; readonly, +guard, copy-on-write, and failed queries fall back to independent output and a +full-frame copy. Permissions are checked again immediately before ROI writes; +failure at that point returns `GVFG_EIO` without writing. No `VirtualProtect` +or vendor release contract change is used. Successful in-place processing +retains the backend hold until normal application frame release. + +WARNING: these checks do not prevent concurrent DMA, buffer reuse, or a mapping +change after the check. Corruption and access violations remain possible; C++ +exception handling is not an access-violation safety guarantee. Do not ship this +configuration. A successful capture does not establish driver ownership safety. + +The viewer warns at startup and labels each 300-frame diagnostic batch as actual +driver-buffer writes, fallback copies, or no in-place processing. Flags use the +separate `gvfg_debug_get_channel_osd_experiment_flags` export; existing timing +struct layouts stay unchanged. Revert by setting the option OFF and rebuilding +the SDK. The client-facing frame pointer remains read-only in all modes. + +Fallback batches also report the final frame's first rejected region: a readable +reason, native Protect/State/Type, VirtualQuery return byte count, and Win32 error +(captured immediately only when VirtualQuery returns zero). Other frames may +have different reasons. This uses the separate internal +`gvfg_debug_get_channel_osd_page_check` export, queried while the frame is held; +rebuild both SDK and viewer together. No per-frame logging or permission changes +are introduced. Zero Win32 error does not imply a writable page. diff --git a/GVFG_SDK/helpers/gvfg_osd/include/gvfg_osd.h b/GVFG_SDK/helpers/gvfg_osd/include/gvfg_osd.h index 42259ca..4430280 100644 --- a/GVFG_SDK/helpers/gvfg_osd/include/gvfg_osd.h +++ b/GVFG_SDK/helpers/gvfg_osd/include/gvfg_osd.h @@ -28,7 +28,10 @@ typedef enum gvfg_osd_pixel_format_t /* * Generates an off-line OSD surface using the Arial system font. Text is * restricted to printable ASCII and at most GVFG_OSD_MAX_TEXT_CHARACTERS - * characters. 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 + * glyph overhang and a one-pixel guard). They are clamped to keep that box + * inside the frame. Rendering returns EINVAL if the box cannot fit the frame. * Output YUV uses BT.709 limited range. The mask is one coverage byte per * pixel: 0 is transparent and 255 is fully covered. */ @@ -64,6 +67,15 @@ gvfg_osd_status_t gvfg_osd_create( void gvfg_osd_destroy( gvfg_osd_handle handle); +/* Conservative whole-text bounds in pixels, not pixel-tight raster bounds. */ +gvfg_osd_status_t gvfg_osd_measure( + gvfg_osd_handle handle, + const char *text, + uint32_t text_length, + uint32_t font_size_px, + uint32_t *out_width, + uint32_t *out_height); + gvfg_osd_status_t gvfg_osd_render( gvfg_osd_handle handle, const gvfg_osd_config_t *config, diff --git a/GVFG_SDK/helpers/gvfg_osd/src/gvfg_osd.cpp b/GVFG_SDK/helpers/gvfg_osd/src/gvfg_osd.cpp index 2904467..991cec1 100644 --- a/GVFG_SDK/helpers/gvfg_osd/src/gvfg_osd.cpp +++ b/GVFG_SDK/helpers/gvfg_osd/src/gvfg_osd.cpp @@ -85,11 +85,107 @@ std::wstring widenAscii(const char *text, uint32_t length) return result; } +struct MeasuredTextLayout +{ + ComPtr layout; + uint32_t width = 0; + uint32_t height = 0; + float drawOffsetX = 0; + float drawOffsetY = 0; +}; + +gvfg_osd_status_t createTextLayout(OsdContext &context, const char *text, + uint32_t textLength, uint32_t fontSizePx, + MeasuredTextLayout &result) +{ + if (!validAscii(text, textLength) || fontSizePx == 0) + return GVFG_OSD_EINVAL; + + ComPtr format; + HRESULT hr = context.dwrite->CreateTextFormat( + L"Arial", nullptr, DWRITE_FONT_WEIGHT_NORMAL, + DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, + static_cast(fontSizePx), L"en-us", &format); + if (FAILED(hr) || + FAILED(format->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP)) || + FAILED(format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING)) || + FAILED(format->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR))) + return GVFG_OSD_ERENDER; + + const std::wstring wideText = widenAscii(text, textLength); + hr = context.dwrite->CreateTextLayout( + wideText.c_str(), textLength, format.Get(), 1.0f, 1.0f, &result.layout); + if (FAILED(hr)) + return GVFG_OSD_ERENDER; + + DWRITE_TEXT_METRICS metrics{}; + if (FAILED(result.layout->GetMetrics(&metrics)) || + !std::isfinite(metrics.widthIncludingTrailingWhitespace) || + !std::isfinite(metrics.height)) + return GVFG_OSD_ERENDER; + // Tighten the logical box before requesting overhangs: they are relative + // to the layout box, not directly to metrics.width or metrics.height. + const float layoutWidth = (std::max)(1.0f, metrics.widthIncludingTrailingWhitespace); + const float layoutHeight = (std::max)(1.0f, metrics.height); + if (FAILED(result.layout->SetMaxWidth(layoutWidth)) || + FAILED(result.layout->SetMaxHeight(layoutHeight)) || + FAILED(result.layout->GetMetrics(&metrics))) + return GVFG_OSD_ERENDER; + DWRITE_OVERHANG_METRICS overhang{}; + if (FAILED(result.layout->GetOverhangMetrics(&overhang)) || + !std::isfinite(metrics.left) || !std::isfinite(metrics.top) || + !std::isfinite(metrics.widthIncludingTrailingWhitespace) || + !std::isfinite(metrics.height) || + !std::isfinite(overhang.left) || !std::isfinite(overhang.top) || + !std::isfinite(overhang.right) || !std::isfinite(overhang.bottom)) + return GVFG_OSD_ERENDER; + + // Include logical spacing and glyph ink, then round outward and reserve + // one pixel per edge for rasterization/grid-fitting differences. + const double left = std::floor((std::min)( + (std::min)(0.0, static_cast(metrics.left)), + -static_cast(overhang.left))) - 1.0; + const double top = std::floor((std::min)( + (std::min)(0.0, static_cast(metrics.top)), + -static_cast(overhang.top))) - 1.0; + const double right = std::ceil((std::max)( + (std::max)(static_cast(layoutWidth), + static_cast(metrics.left) + metrics.widthIncludingTrailingWhitespace), + static_cast(layoutWidth) + overhang.right)) + 1.0; + const double bottom = std::ceil((std::max)( + (std::max)(static_cast(layoutHeight), + static_cast(metrics.top) + metrics.height), + static_cast(layoutHeight) + overhang.bottom)) + 1.0; + const double width = right - left; + const double height = bottom - top; + if (!std::isfinite(width) || !std::isfinite(height) || + width <= 0 || height <= 0 || + width > (std::numeric_limits::max)() || + height > (std::numeric_limits::max)()) + return GVFG_OSD_EINVAL; + + result.width = static_cast(width); + result.height = static_cast(height); + result.drawOffsetX = static_cast(-left); + result.drawOffsetY = static_cast(-top); + return GVFG_OSD_OK; +} + gvfg_osd_status_t renderMask(OsdContext &context, const gvfg_osd_config_t &config, uint8_t *destination, uint32_t destinationStride) { + MeasuredTextLayout textLayout; + const gvfg_osd_status_t layoutStatus = createTextLayout( + context, config.text, config.text_length, config.font_size_px, textLayout); + if (layoutStatus != GVFG_OSD_OK) + return layoutStatus; + if (textLayout.width > config.width || textLayout.height > config.height) + return GVFG_OSD_EINVAL; + const int64_t x = std::clamp(config.x, 0, config.width - textLayout.width); + const int64_t y = std::clamp(config.y, 0, config.height - textLayout.height); + ComPtr bitmap; HRESULT hr = context.wic->CreateBitmap(config.width, config.height, GUID_WICPixelFormat32bppPBGRA, @@ -100,22 +196,13 @@ gvfg_osd_status_t renderMask(OsdContext &context, D2D1_RENDER_TARGET_PROPERTIES properties = D2D1::RenderTargetProperties( D2D1_RENDER_TARGET_TYPE_SOFTWARE, D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, - D2D1_ALPHA_MODE_PREMULTIPLIED)); + D2D1_ALPHA_MODE_PREMULTIPLIED), + 96.0f, 96.0f); ComPtr target; hr = context.d2d->CreateWicBitmapRenderTarget(bitmap.Get(), properties, &target); if (FAILED(hr)) return GVFG_OSD_ERENDER; - const std::wstring text = widenAscii(config.text, config.text_length); - - ComPtr format; - hr = context.dwrite->CreateTextFormat( - L"Arial", nullptr, DWRITE_FONT_WEIGHT_NORMAL, - DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, - static_cast(config.font_size_px), L"en-us", &format); - if (FAILED(hr)) - return GVFG_OSD_ERENDER; - ComPtr brush; hr = target->CreateSolidColorBrush(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f), &brush); if (FAILED(hr)) @@ -123,12 +210,10 @@ gvfg_osd_status_t renderMask(OsdContext &context, target->BeginDraw(); target->Clear(D2D1::ColorF(0.0f, 0.0f)); - const D2D1_RECT_F layout = D2D1::RectF( - static_cast(config.x), static_cast(config.y), - static_cast(config.width), static_cast(config.height)); - target->DrawText(text.c_str(), config.text_length, format.Get(), layout, - brush.Get(), D2D1_DRAW_TEXT_OPTIONS_CLIP, - DWRITE_MEASURING_MODE_NATURAL); + target->DrawTextLayout( + D2D1::Point2F(static_cast(x) + textLayout.drawOffsetX, + static_cast(y) + textLayout.drawOffsetY), + textLayout.layout.Get(), brush.Get(), D2D1_DRAW_TEXT_OPTIONS_NONE); hr = target->EndDraw(); if (FAILED(hr)) return GVFG_OSD_ERENDER; @@ -251,6 +336,39 @@ void gvfg_osd_destroy(gvfg_osd_handle handle) delete static_cast(handle); } +gvfg_osd_status_t gvfg_osd_measure(gvfg_osd_handle handle, + const char *text, uint32_t text_length, + uint32_t font_size_px, + uint32_t *out_width, uint32_t *out_height) +{ + if (out_width) + *out_width = 0; + if (out_height) + *out_height = 0; + if (!handle || !out_width || !out_height || + !validAscii(text, text_length) || font_size_px == 0) + return GVFG_OSD_EINVAL; + try + { + MeasuredTextLayout layout; + const gvfg_osd_status_t status = createTextLayout( + *static_cast(handle), text, text_length, font_size_px, layout); + if (status != GVFG_OSD_OK) + return status; + *out_width = layout.width; + *out_height = layout.height; + 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) @@ -260,14 +378,16 @@ gvfg_osd_status_t gvfg_osd_render(gvfg_osd_handle handle, output->struct_size != sizeof(gvfg_osd_output_t) || !validAscii(config->text, config->text_length) || config->width == 0 || config->height == 0 || (config->width & 1u) != 0 || + config->width > static_cast((std::numeric_limits::max)()) || + config->height > static_cast((std::numeric_limits::max)()) || config->font_size_px == 0 || !output->yuv_data || !output->mask_data) return GVFG_OSD_EINVAL; - uint32_t minimumYuvStride = 0; + uint64_t minimumYuvStride = 0; if (config->pixel_format == GVFG_OSD_PIXFMT_YUY2) - minimumYuvStride = config->width * 2u; + minimumYuvStride = static_cast(config->width) * 2u; else if (config->pixel_format == GVFG_OSD_PIXFMT_Y210) - minimumYuvStride = config->width * 4u; + minimumYuvStride = static_cast(config->width) * 4u; else return GVFG_OSD_EINVAL; @@ -278,22 +398,35 @@ gvfg_osd_status_t gvfg_osd_render(gvfg_osd_handle handle, uint64_t requiredMask = 0; if (!checkedImageBytes(output->yuv_stride, config->height, requiredYuv) || !checkedImageBytes(output->mask_stride, config->height, requiredMask) || - output->yuv_size < requiredYuv || output->mask_size < requiredMask) + output->yuv_size < requiredYuv || output->mask_size < requiredMask || + requiredYuv > (std::numeric_limits::max)() || + requiredMask > (std::numeric_limits::max)()) return GVFG_OSD_EINVAL; - std::memset(output->mask_data, 0, static_cast(requiredMask)); - const gvfg_osd_status_t maskStatus = renderMask( - *static_cast(handle), *config, - static_cast(output->mask_data), output->mask_stride); - if (maskStatus != GVFG_OSD_OK) - return maskStatus; + try + { + std::memset(output->mask_data, 0, static_cast(requiredMask)); + const gvfg_osd_status_t maskStatus = renderMask( + *static_cast(handle), *config, + static_cast(output->mask_data), output->mask_stride); + if (maskStatus != GVFG_OSD_OK) + return maskStatus; - const Yuv8 color = rgbToBt709Limited(config->color_rgb); - if (config->pixel_format == GVFG_OSD_PIXFMT_YUY2) - writeYuy2(*config, *output, color); - else - writeY210(*config, *output, color); - return GVFG_OSD_OK; + const Yuv8 color = rgbToBt709Limited(config->color_rgb); + if (config->pixel_format == GVFG_OSD_PIXFMT_YUY2) + writeYuy2(*config, *output, color); + else + writeY210(*config, *output, color); + return GVFG_OSD_OK; + } + catch (const std::bad_alloc &) + { + return GVFG_OSD_ENOMEM; + } + catch (...) + { + return GVFG_OSD_ERENDER; + } } const char *gvfg_osd_strerror(gvfg_osd_status_t status) diff --git a/GVFG_SDK/sdk/gvfg/CMakeLists.txt b/GVFG_SDK/sdk/gvfg/CMakeLists.txt index 6387ffa..e8e04aa 100644 --- a/GVFG_SDK/sdk/gvfg/CMakeLists.txt +++ b/GVFG_SDK/sdk/gvfg/CMakeLists.txt @@ -46,6 +46,9 @@ target_compile_definitions(gvfg PRIVATE target_compile_definitions(gvfg PRIVATE GVFG_INTERNAL_DIAGNOSTICS=$,1,0> ) +if (GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE) + target_compile_definitions(gvfg PRIVATE GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE=1) +endif() target_link_libraries(gvfg PRIVATE gvfg_osd_core diff --git a/GVFG_SDK/sdk/gvfg/gvfg.def b/GVFG_SDK/sdk/gvfg/gvfg.def index 700f8d3..527eaa3 100644 --- a/GVFG_SDK/sdk/gvfg/gvfg.def +++ b/GVFG_SDK/sdk/gvfg/gvfg.def @@ -8,6 +8,7 @@ EXPORTS gvfg_set_channel_zero_copy_enabled gvfg_get_channel_zero_copy_enabled gvfg_set_channel_video_format + gvfg_measure_osd_text gvfg_set_channel_osd gvfg_clear_channel_osd gvfg_set_channel_audio_enabled @@ -33,6 +34,10 @@ EXPORTS gvfg_strerror gvfg_get_channel_last_sdk_error_detail gvfg_debug_get_channel_backend_stats + gvfg_debug_read_channel_frame_timed + gvfg_debug_read_channel_frame_profiled + gvfg_debug_get_channel_osd_experiment_flags + gvfg_debug_get_channel_osd_page_check gvfg_debug_get_device_capabilities gvfg_debug_read_register gvfg_debug_write_register diff --git a/GVFG_SDK/sdk/gvfg/include/gvfg_capture.h b/GVFG_SDK/sdk/gvfg/include/gvfg_capture.h index 192501b..acca8e1 100644 --- a/GVFG_SDK/sdk/gvfg/include/gvfg_capture.h +++ b/GVFG_SDK/sdk/gvfg/include/gvfg_capture.h @@ -216,8 +216,8 @@ extern "C" { const char *text; /* Printable English ASCII text (0x20-0x7e). */ uint32_t text_length; /* 1 through GVFG_OSD_MAX_TEXT_CHARACTERS. */ - int32_t x; /* Left position in output-frame pixels. */ - int32_t y; /* Top position in output-frame pixels. */ + int32_t x; /* Measured text-box left in frame pixels; clamped to fit. */ + int32_t y; /* Measured text-box top in frame pixels; clamped to fit. */ uint32_t font_size_px; /* Font size in pixels; must be non-zero. */ uint32_t color_rgb; /* 0x00RRGGBB. */ } gvfg_channel_osd_config_t; @@ -368,10 +368,30 @@ extern "C" GVFG_PARAM_IN int channel_index, GVFG_PARAM_IN gvfg_pixel_format_t format); + /* + * Measure printable ASCII text as a single non-wrapping line, using the + * same font/layout as SDK OSD. No capture handle or open device is needed. + * Returns a conservative whole-text box in pixels, including glyph + * 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. + * Returns GVFG_EINVAL for invalid input or unrepresentable dimensions, + * and GVFG_EIO on measurement failure. + */ + GVFG_API gvfg_status_t gvfg_measure_osd_text( + GVFG_PARAM_IN const char *text, + 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_height); + /* * Enable or update SDK-side OSD for an opened channel. The configuration * is copied synchronously and applies to subsequent YUY2 or Y210 frames. * Text is rendered as BT.709 limited-range video and blended by the GPU. + * The single-line measured text box is positioned at x/y, clamped inside + * 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_PARAM_IN gvfg_handle handle, diff --git a/GVFG_SDK/sdk/gvfg/include/gvfg_debug.h b/GVFG_SDK/sdk/gvfg/include/gvfg_debug.h index 46bf643..76e0001 100644 --- a/GVFG_SDK/sdk/gvfg/include/gvfg_debug.h +++ b/GVFG_SDK/sdk/gvfg/include/gvfg_debug.h @@ -49,6 +49,116 @@ typedef struct int has_audio; } gvfg_debug_device_capabilities_t; +/* CPU wall times around the synchronous OSD delivery path, in milliseconds. + * SUBMIT is command submission, not GPU execution time. READBACK_WAIT includes + * waiting for earlier GPU work; FRAME_COPY can overlap that GPU work. + * PROCESS_TOTAL includes the other process stages, but not BACKEND_RELEASE. + */ +typedef enum +{ + GVFG_DEBUG_OSD_LOCK_WAIT, + GVFG_DEBUG_OSD_SURFACE, + GVFG_DEBUG_OSD_PREPARE, + GVFG_DEBUG_OSD_UPLOAD, + GVFG_DEBUG_OSD_SUBMIT, + GVFG_DEBUG_OSD_FRAME_COPY, + GVFG_DEBUG_OSD_READBACK_WAIT, + GVFG_DEBUG_OSD_ROI_COPY, + GVFG_DEBUG_OSD_BACKEND_RELEASE, + GVFG_DEBUG_OSD_PROCESS_TOTAL, + GVFG_DEBUG_OSD_STAGE_COUNT +} gvfg_debug_osd_stage_t; + +typedef struct +{ + uint64_t frame_id; + int osd_applied; + int surface_rebuilt; + uint32_t roi_width; + uint32_t roi_height; + double stage_ms[GVFG_DEBUG_OSD_STAGE_COUNT]; +} gvfg_debug_osd_frame_timing_t; + +/* Internal diagnostic variant of read_channel_frame, with identical frame + * ownership/release semantics. Timing is collected only through this entry + * point; normal customer reads do not perform these extra clock queries. + * On success timing.frame_id matches out_frame->frame_id. No GPU queries, + * extra Flush, or additional synchronization are introduced. + */ +GVFG_DEBUG_API gvfg_status_t gvfg_debug_read_channel_frame_timed( + GVFG_PARAM_IN gvfg_handle handle, + GVFG_PARAM_IN int channel_index, + GVFG_PARAM_OUT gvfg_frame_t *out_frame, + GVFG_PARAM_OUT gvfg_debug_osd_frame_timing_t *out_timing, + GVFG_PARAM_IN uint32_t timeout_ms); + +/* Acquisition starts after a video-frame event is ready, before retrieving + * or copying its data. Excludes waiting for the next frame. The public frame + * timestamp remains unchanged (data acquired, before OSD). + * A separate type/entry point preserves the older timed-read ABI. + */ +typedef struct +{ + gvfg_debug_osd_frame_timing_t osd; + uint64_t acquisition_begin_ns; +} gvfg_debug_frame_read_timing_t; + +enum +{ + GVFG_DEBUG_OSD_EXPERIMENT_ENABLED = 1u, + GVFG_DEBUG_OSD_EXPERIMENT_USED = 2u, + GVFG_DEBUG_OSD_EXPERIMENT_REJECTED = 4u +}; + +typedef enum +{ + GVFG_DEBUG_OSD_PAGE_OK = 0, + GVFG_DEBUG_OSD_PAGE_NO_POINTER, + GVFG_DEBUG_OSD_PAGE_INVALID_RANGE, + GVFG_DEBUG_OSD_PAGE_QUERY_FAILED, + GVFG_DEBUG_OSD_PAGE_NOT_COMMITTED, + GVFG_DEBUG_OSD_PAGE_GUARD_OR_NOACCESS, + GVFG_DEBUG_OSD_PAGE_NOT_READWRITE, + GVFG_DEBUG_OSD_PAGE_INVALID_REGION +} gvfg_debug_osd_page_reason_t; + +/* Separate diagnostic type: existing timing/flags ABI remains unchanged. + * Native Windows values; win32_error is meaningful only for QUERY_FAILED. + * Does not expose addresses or imply DMA safety. */ +typedef struct +{ + uint32_t reason; + uint32_t protect; + uint32_t state; + uint32_t type; + uint32_t win32_error; + uint32_t query_bytes; +} gvfg_debug_osd_page_check_t; + +/* Query before releasing the matching successfully delivered frame. */ +GVFG_DEBUG_API gvfg_status_t gvfg_debug_get_channel_osd_page_check( + GVFG_PARAM_IN gvfg_handle handle, + GVFG_PARAM_IN int channel_index, + GVFG_PARAM_IN uint64_t frame_id, + GVFG_PARAM_OUT gvfg_debug_osd_page_check_t *out_check); + +/* frame_id=0 queries build configuration only. Otherwise the frame must still + * be held and its ID must match. Never implies a DMA ownership guarantee. + * Separate query preserves all existing timing struct layouts/read ABIs. + */ +GVFG_DEBUG_API gvfg_status_t gvfg_debug_get_channel_osd_experiment_flags( + GVFG_PARAM_IN gvfg_handle handle, + GVFG_PARAM_IN int channel_index, + GVFG_PARAM_IN uint64_t frame_id, + GVFG_PARAM_OUT uint32_t *out_flags); + +GVFG_DEBUG_API gvfg_status_t gvfg_debug_read_channel_frame_profiled( + GVFG_PARAM_IN gvfg_handle handle, + GVFG_PARAM_IN int channel_index, + GVFG_PARAM_OUT gvfg_frame_t *out_frame, + GVFG_PARAM_OUT gvfg_debug_frame_read_timing_t *out_timing, + GVFG_PARAM_IN uint32_t timeout_ms); + /* * Query driver-neutral internal backend counters. * diff --git a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp index 4c8da2d..a5d438b 100644 --- a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp +++ b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp @@ -458,6 +458,8 @@ namespace gvfg::internal { std::lock_guard lock(state_mutex_); frame_held_ = false; + held_zero_copy_data_ = nullptr; + held_zero_copy_bytes_ = 0; } running_ = true; start_event_monitoring(); @@ -477,6 +479,8 @@ namespace gvfg::internal { std::lock_guard lock(state_mutex_); frame_held_ = false; + held_zero_copy_data_ = nullptr; + held_zero_copy_bytes_ = 0; } recovery_cv_.notify_all(); stop_event_monitoring(); @@ -499,9 +503,12 @@ namespace gvfg::internal return result; } - gvfg_status_t GigabyteCaptureSession::wait_frame(uint32_t timeoutMs, gvfg_frame_t &out) + gvfg_status_t GigabyteCaptureSession::wait_frame(uint32_t timeoutMs, gvfg_frame_t &out, + uint64_t *acquisitionBeginNs) { out = {}; + if (acquisitionBeginNs) + *acquisitionBeginNs = 0; if (!running_ || !context_) return reject(GVFG_ESTATE, "Capture frame read rejected: stream is not running"); { @@ -525,6 +532,10 @@ namespace gvfg::internal return wait_for_recovery(timeoutMs); if (wait != WAIT_OBJECT_0 + 2 && wait != WAIT_OBJECT_0 + 3) return reject(GVFG_EIO, "Capture video event wait failed"); + // The frame event is ready. Start before buffer preparation, vendor + // retrieval/copy and their locks, but after waiting for a new frame. + if (acquisitionBeginNs) + *acquisitionBeginNs = monotonic_ns(); { std::lock_guard lock(state_mutex_); if (wait == WAIT_OBJECT_0 + 2) @@ -547,6 +558,7 @@ namespace gvfg::internal bytes = video_info_.cbBufSize; } const void *data = nullptr; + void *zeroCopyData = nullptr; gvfg_status_t status = GVFG_OK; if (zero_copy_enabled_) { @@ -560,6 +572,7 @@ namespace gvfg::internal const auto end = std::chrono::steady_clock::now(); record_get_frame_timing(std::chrono::duration(end - begin).count()); data = buffer; + zeroCopyData = buffer; } else { @@ -593,9 +606,34 @@ namespace gvfg::internal out.bit_depth = signal.bit_depth; ++video_frames_from_lib_; frame_held_ = true; + held_zero_copy_data_ = zeroCopyData; + held_zero_copy_bytes_ = zeroCopyData ? bytes : 0; return GVFG_OK; } + uint8_t *GigabyteCaptureSession::writable_copy_frame_data(const gvfg_frame_t &frame) + { + std::lock_guard lock(state_mutex_); + if (zero_copy_enabled_ || !frame_held_ || copy_buffer_.empty() || + frame.data != copy_buffer_.data() || frame.data_size != copy_buffer_.size()) + return nullptr; + return copy_buffer_.data(); + } + + uint8_t *GigabyteCaptureSession::experimental_zero_copy_frame_data(const gvfg_frame_t &frame) + { +#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE + std::lock_guard lock(state_mutex_); + if (!zero_copy_enabled_ || !frame_held_ || !held_zero_copy_data_ || + frame.data != held_zero_copy_data_ || frame.data_size != held_zero_copy_bytes_) + return nullptr; + return static_cast(held_zero_copy_data_); +#else + (void)frame; + return nullptr; +#endif + } + gvfg_status_t GigabyteCaptureSession::release_frame() { { @@ -604,6 +642,8 @@ namespace gvfg::internal return reject(GVFG_ESTATE, "Capture frame release rejected: no frame is held"); // Current GigabyteLib zero-copy contract requires no per-frame release call. frame_held_ = false; + held_zero_copy_data_ = nullptr; + held_zero_copy_bytes_ = 0; } recovery_cv_.notify_all(); return GVFG_OK; diff --git a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.h b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.h index 6264afe..d0e5639 100644 --- a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.h +++ b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.h @@ -55,7 +55,13 @@ namespace gvfg::internal gvfg_status_t configure_stream(); gvfg_status_t start_stream(); gvfg_status_t stop_stream(); - gvfg_status_t wait_frame(uint32_t timeoutMs, gvfg_frame_t &out); + gvfg_status_t wait_frame(uint32_t timeoutMs, gvfg_frame_t &out, + uint64_t *acquisitionBeginNs = nullptr); + // Internal writable access only to the currently held SDK-owned copy. + // Driver zero-copy buffers are never returned. Valid until release. + uint8_t *writable_copy_frame_data(const gvfg_frame_t &frame); + // Opt-in test candidate only, not a driver write/hold guarantee. + uint8_t *experimental_zero_copy_frame_data(const gvfg_frame_t &frame); gvfg_status_t wait_audio(uint32_t timeoutMs, void *destination, uint32_t destinationCapacity, uint32_t &outBytes); gvfg_status_t release_frame(); @@ -112,6 +118,8 @@ namespace gvfg::internal std::mutex capture_mutex_; std::vector copy_buffer_; bool frame_held_ = false; + void *held_zero_copy_data_ = nullptr; + uint64_t held_zero_copy_bytes_ = 0; uint64_t video_frames_from_lib_ = 0; uint64_t audio_frames_from_lib_ = 0; uint64_t video_dma_event_wakes_ = 0; diff --git a/GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.cpp b/GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.cpp index f262a72..0fd068e 100644 --- a/GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.cpp +++ b/GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,56 @@ namespace gvfg::internal { namespace { +#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE +// Permission snapshot only: this does NOT establish exclusive DMA ownership. +bool writableExperimentalRange(const gvfg_frame_t &source, uint64_t offset, uint64_t span, + gvfg_debug_osd_page_check_t *result) +{ + gvfg_debug_osd_page_check_t check{}; + const auto reject = [&](gvfg_debug_osd_page_reason_t reason) { + check.reason = static_cast(reason); + if (result) + *result = check; + return false; + }; + const uintptr_t base = reinterpret_cast(source.data); + const uintptr_t limit = (std::numeric_limits::max)(); + if (!span || offset > source.data_size || span > source.data_size - offset || + offset > limit - base || span > limit - (base + offset)) + return reject(GVFG_DEBUG_OSD_PAGE_INVALID_RANGE); + uintptr_t cursor = base + static_cast(offset); + const uintptr_t end = cursor + static_cast(span); + while (cursor < end) + { + MEMORY_BASIC_INFORMATION info{}; + const SIZE_T queried = VirtualQuery(reinterpret_cast(cursor), &info, sizeof(info)); + // Capture the error immediately, and only on a failed native call. + check.win32_error = queried == 0 ? GetLastError() : 0; + check.query_bytes = static_cast(queried); + check.protect = info.Protect; + check.state = info.State; + check.type = info.Type; + if (queried != sizeof(info)) + return reject(GVFG_DEBUG_OSD_PAGE_QUERY_FAILED); + if (info.State != MEM_COMMIT) + return reject(GVFG_DEBUG_OSD_PAGE_NOT_COMMITTED); + if (info.Protect & (PAGE_GUARD | PAGE_NOACCESS)) + return reject(GVFG_DEBUG_OSD_PAGE_GUARD_OR_NOACCESS); + if ((info.Protect & 0xffu) != PAGE_READWRITE) + return reject(GVFG_DEBUG_OSD_PAGE_NOT_READWRITE); + const uintptr_t regionBase = reinterpret_cast(info.BaseAddress); + if (info.RegionSize > limit - regionBase) + return reject(GVFG_DEBUG_OSD_PAGE_INVALID_REGION); + const uintptr_t next = regionBase + info.RegionSize; + if (next <= cursor) + return reject(GVFG_DEBUG_OSD_PAGE_INVALID_REGION); + cursor = next; + } + if (result) + *result = {}; + return true; +} +#endif constexpr char kOsdBlendShader[] = R"( Texture2D sourceTexture : register(t0); Texture2D osdTexture : register(t1); @@ -318,12 +369,34 @@ struct GpuOsdProcessor::Impl 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 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(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; + } yuvSurface.resize(static_cast(yuvStride) * frameHeight); maskSurface.resize(static_cast(maskStride) * frameHeight); - gvfg_osd_handle handle = nullptr; - if (gvfg_osd_create(&handle) != GVFG_OSD_OK) - return false; gvfg_osd_config_t config{}; config.struct_size = sizeof(config); config.width = frameWidth; @@ -346,8 +419,8 @@ struct GpuOsdProcessor::Impl output.mask_data = maskSurface.data(); output.mask_size = maskSurface.size(); output.mask_stride = maskStride; - const gvfg_osd_status_t status = gvfg_osd_render(handle, &config, &output); - gvfg_osd_destroy(handle); + const gvfg_osd_status_t status = gvfg_osd_render(handle.get(), &config, &output); + handle.reset(); if (status != GVFG_OSD_OK) return false; @@ -402,9 +475,35 @@ struct GpuOsdProcessor::Impl gvfg_status_t process(const gvfg_frame_t &source, std::vector &destination, int &destinationStride, - bool &applied) + bool &applied, + gvfg_debug_osd_frame_timing_t *timing, + uint8_t *writableSource, + bool experimentalZeroCopy, + bool *inPlaceApplied, + uint32_t *experimentFlags, + gvfg_debug_osd_page_check_t *pageCheck) { + if (pageCheck) + *pageCheck = {}; + if (inPlaceApplied) + *inPlaceApplied = false; +#ifndef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE + if (experimentalZeroCopy) + return GVFG_EINVAL; + (void)experimentFlags; +#endif + using Clock = std::chrono::steady_clock; + auto stageStart = timing ? Clock::now() : Clock::time_point{}; + const auto finishStage = [timing, &stageStart](gvfg_debug_osd_stage_t stage) { + if (timing) + { + const auto end = Clock::now(); + timing->stage_ms[stage] = std::chrono::duration(end - stageStart).count(); + stageStart = end; + } + }; std::lock_guard lock(mutex); + finishStage(GVFG_DEBUG_OSD_LOCK_WAIT); applied = false; if (!active) return GVFG_OK; @@ -424,13 +523,19 @@ struct GpuOsdProcessor::Impl rowBytes64; if (source.data_size < requiredSource) return GVFG_EINVAL; + if (writableSource && static_cast(writableSource) != source.data) + return GVFG_EINVAL; - if ((surfaceDirty || surfaceWidth != static_cast(source.width) || - surfaceHeight != static_cast(source.height) || - surfaceFormat != source.pixel_format) && + const bool rebuild = surfaceDirty || surfaceWidth != static_cast(source.width) || + surfaceHeight != static_cast(source.height) || + surfaceFormat != source.pixel_format; + if (timing) + timing->surface_rebuilt = rebuild ? 1 : 0; + if (rebuild && !rebuildSurface(static_cast(source.width), static_cast(source.height), source.pixel_format)) return GVFG_EIO; + finishStage(GVFG_DEBUG_OSD_SURFACE); // Invisible text needs no processed buffer or GPU work. if (region.empty()) return GVFG_OK; @@ -438,9 +543,34 @@ struct GpuOsdProcessor::Impl const uint32_t rowBytes = static_cast(rowBytes64); const uint32_t bytesPerPixel = source.pixel_format == GVFG_PIXFMT_YUY2 ? 2u : 4u; const uint32_t regionRowBytes = region.width * bytesPerPixel; - const size_t sourceOffset = static_cast(region.top) * source.row_stride_bytes + - static_cast(region.left) * bytesPerPixel; - destination.resize(static_cast(rowBytes) * static_cast(source.height)); + const uint64_t sourceOffset64 = static_cast(region.top) * source.row_stride_bytes + + static_cast(region.left) * bytesPerPixel; + if (sourceOffset64 > (std::numeric_limits::max)()) + return GVFG_EINVAL; + const size_t sourceOffset = static_cast(sourceOffset64); +#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE + const uint64_t writeSpan = static_cast(region.height - 1u) * + source.row_stride_bytes + regionRowBytes; + if (experimentalZeroCopy && + (!writableSource || !writableExperimentalRange(source, sourceOffset, writeSpan, pageCheck))) + { + if (!writableSource && pageCheck) + pageCheck->reason = GVFG_DEBUG_OSD_PAGE_NO_POINTER; + writableSource = nullptr; + if (experimentFlags) + *experimentFlags |= GVFG_DEBUG_OSD_EXPERIMENT_REJECTED; + } +#endif + if (!writableSource) + destination.resize(static_cast(rowBytes) * static_cast(source.height)); + uint8_t *outputData = writableSource ? writableSource : destination.data(); + const uint32_t outputStride = writableSource ? static_cast(source.row_stride_bytes) : rowBytes; + if (timing) + { + timing->roi_width = region.width; + timing->roi_height = region.height; + } + finishStage(GVFG_DEBUG_OSD_PREPARE); D3D11_MAPPED_SUBRESOURCE mapped{}; if (FAILED(context->Map(sourceTexture.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped))) return GVFG_EIO; @@ -450,6 +580,7 @@ struct GpuOsdProcessor::Impl context->Unmap(sourceTexture.Get(), 0); if (!copiedSource) return GVFG_EIO; + finishStage(GVFG_DEBUG_OSD_UPLOAD); ID3D11ShaderResourceView *srvs[] = {sourceSrv.Get(), osdSrv.Get(), maskSrv.Get()}; ID3D11UnorderedAccessView *uavs[] = {outputUav.Get()}; @@ -469,28 +600,52 @@ struct GpuOsdProcessor::Impl context->CSSetShader(nullptr, nullptr, 0); context->CopyResource(readbackTexture.Get(), outputTexture.Get()); - // CPU only preserves the native frame; all blending remains on the GPU. - // Copy before Map READ so it can overlap queued GPU work. - copyFrameRows(source, destination.data(), rowBytes); + finishStage(GVFG_DEBUG_OSD_SUBMIT); + // Driver zero-copy input requires an independent frame by default. + // SDK-owned copy input already contains the untouched full frame, so + // only its ROI is overwritten after GPU readback; no full copy/resize. + if (!writableSource) + { + copyFrameRows(source, outputData, rowBytes); + finishStage(GVFG_DEBUG_OSD_FRAME_COPY); + } if (FAILED(context->Map(readbackTexture.Get(), 0, D3D11_MAP_READ, 0, &mapped))) return GVFG_EIO; + finishStage(GVFG_DEBUG_OSD_READBACK_WAIT); if (mapped.RowPitch < regionRowBytes) { context->Unmap(readbackTexture.Get(), 0); return GVFG_EIO; } - const size_t destinationOffset = static_cast(region.top) * rowBytes + + const size_t destinationOffset = static_cast(region.top) * outputStride + static_cast(region.left) * bytesPerPixel; +#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE + // Recheck immediately before writing. Permissions can still change after + // this check; neither this nor the SDK hold prevents concurrent DMA. + if (experimentalZeroCopy && writableSource && + !writableExperimentalRange(source, sourceOffset, writeSpan, pageCheck)) + { + context->Unmap(readbackTexture.Get(), 0); + return GVFG_EIO; + } +#endif for (uint32_t row = 0; row < region.height; ++row) { - std::memcpy(destination.data() + destinationOffset + static_cast(row) * rowBytes, + std::memcpy(outputData + destinationOffset + static_cast(row) * outputStride, static_cast(mapped.pData) + static_cast(row) * mapped.RowPitch, regionRowBytes); } context->Unmap(readbackTexture.Get(), 0); - destinationStride = static_cast(rowBytes); + finishStage(GVFG_DEBUG_OSD_ROI_COPY); + destinationStride = static_cast(outputStride); applied = true; + if (inPlaceApplied) + *inPlaceApplied = writableSource != nullptr; + if (experimentalZeroCopy && writableSource && experimentFlags) + *experimentFlags |= GVFG_DEBUG_OSD_EXPERIMENT_USED; + if (timing) + timing->osd_applied = 1; return GVFG_OK; } @@ -530,14 +685,39 @@ GpuOsdProcessor::GpuOsdProcessor() : impl_(std::make_unique()) {} GpuOsdProcessor::~GpuOsdProcessor() = default; gvfg_status_t GpuOsdProcessor::configure(const gvfg_channel_osd_config_t &config) { - return impl_->configure(config); + try + { + return impl_->configure(config); + } + catch (...) + { + return GVFG_EIO; + } } void GpuOsdProcessor::clear() { impl_->clear(); } gvfg_status_t GpuOsdProcessor::process(const gvfg_frame_t &source, std::vector &destination, int &destinationStride, - bool &applied) + bool &applied, + gvfg_debug_osd_frame_timing_t *timing, + uint8_t *writableSource, + bool experimentalZeroCopy, + bool *inPlaceApplied, + uint32_t *experimentFlags, + gvfg_debug_osd_page_check_t *pageCheck) { - return impl_->process(source, destination, destinationStride, applied); + try + { + return impl_->process(source, destination, destinationStride, applied, timing, writableSource, + experimentalZeroCopy, inPlaceApplied, experimentFlags, pageCheck); + } + catch (...) + { + applied = false; + if (inPlaceApplied) + *inPlaceApplied = false; + destinationStride = 0; + return GVFG_EIO; + } } } diff --git a/GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.h b/GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.h index 357a35b..7d2deb9 100644 --- a/GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.h +++ b/GVFG_SDK/sdk/gvfg/src/gpu/gvfg_gpu_osd.h @@ -1,6 +1,7 @@ #pragma once #include "gvfg_capture.h" +#include "gvfg_debug.h" #include #include @@ -16,10 +17,21 @@ public: gvfg_status_t configure(const gvfg_channel_osd_config_t &config); void clear(); + // writableSource must equal source.data. Only the backend can grant this + // writable SDK-owned storage, held until the caller releases the frame. + // The default-OFF experimental override admits driver storage only after + // page checks; this is not a driver/DMA ownership guarantee. + // nullptr preserves the separate-output path used for driver zero-copy. gvfg_status_t process(const gvfg_frame_t &source, std::vector &destination, int &destinationStride, - bool &applied); + bool &applied, + gvfg_debug_osd_frame_timing_t *timing = nullptr, + uint8_t *writableSource = nullptr, + bool experimentalZeroCopy = false, + bool *inPlaceApplied = nullptr, + uint32_t *experimentFlags = nullptr, + gvfg_debug_osd_page_check_t *pageCheck = nullptr); private: struct Impl; diff --git a/GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp b/GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp index 44bd9ba..c525d41 100644 --- a/GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp +++ b/GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp @@ -3,6 +3,7 @@ #include "gvfg_debug.h" #include "gigabyte_capture_session.h" #include "gpu/gvfg_gpu_osd.h" +#include "gvfg_osd.h" #include "gvfgframework.h" #include @@ -367,9 +368,15 @@ struct gvfg_channel_session_t return GVFG_OK; } - gvfg_status_t readFrame(gvfg_frame_t &out, uint32_t timeoutMs) + gvfg_status_t readFrame(gvfg_frame_t &out, uint32_t timeoutMs, + gvfg_debug_osd_frame_timing_t *timing = nullptr, + uint64_t *acquisitionBeginNs = nullptr) { std::memset(&out, 0, sizeof(out)); + if (timing) + *timing = {}; + if (acquisitionBeginNs) + *acquisitionBeginNs = 0; if (!session) return reject(GVFG_ESTATE, "gvfg_read_channel_frame rejected: channel is not open"); if (!running) @@ -389,7 +396,7 @@ struct gvfg_channel_session_t return reject(GVFG_ESTATE, stateError); gvfg_frame_t frame{}; - const gvfg_status_t st = session->wait_frame(timeoutMs, frame); + const gvfg_status_t st = session->wait_frame(timeoutMs, frame, acquisitionBeginNs); if (st != GVFG_OK) { { @@ -422,8 +429,28 @@ struct gvfg_channel_session_t bool osdApplied = false; int processedStride = 0; + // This capability comes from the backend, never from const_cast of a + // public frame pointer. Driver storage is excluded by default; only + // the explicit unsafe build option below can admit it for experiments. + uint8_t *writableSource = session->writable_copy_frame_data(frame); + bool experimentalZeroCopy = false; + bool inPlaceApplied = false; + uint32_t experimentFlags = 0; + gvfg_debug_osd_page_check_t pageCheck{}; +#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE + experimentFlags = GVFG_DEBUG_OSD_EXPERIMENT_ENABLED; + if (!writableSource) + { + writableSource = session->experimental_zero_copy_frame_data(frame); + experimentalZeroCopy = writableSource != nullptr; + } +#endif + const uint64_t processBeginNs = timing ? now_ns() : 0; const gvfg_status_t osdStatus = - osdProcessor.process(frame, processedVideoBuffer, processedStride, osdApplied); + osdProcessor.process(frame, processedVideoBuffer, processedStride, osdApplied, timing, + writableSource, experimentalZeroCopy, &inPlaceApplied, &experimentFlags, &pageCheck); + if (timing) + timing->stage_ms[GVFG_DEBUG_OSD_PROCESS_TOTAL] = static_cast(now_ns() - processBeginNs) / 1e6; if (osdStatus != GVFG_OK) { session->release_frame(); @@ -433,9 +460,14 @@ struct gvfg_channel_session_t } bool backendFrameHeld = true; - if (osdApplied) + // An in-place copy-mode frame must keep the backend hold until the + // user's release; otherwise recovery/next capture may reuse its data. + if (osdApplied && !inPlaceApplied) { + const uint64_t releaseBeginNs = timing ? now_ns() : 0; const gvfg_status_t releaseStatus = session->release_frame(); + if (timing) + timing->stage_ms[GVFG_DEBUG_OSD_BACKEND_RELEASE] = static_cast(now_ns() - releaseBeginNs) / 1e6; if (releaseStatus != GVFG_OK) { std::lock_guard lock(frameMutex); @@ -460,6 +492,8 @@ struct gvfg_channel_session_t { frame.frame_id = ++videoFrameId; heldSessionFrame = frame; + heldOsdExperimentFlags = experimentFlags; + heldOsdPageCheck = pageCheck; heldFrameNeedsBackendRelease = backendFrameHeld; readInProgress = false; frameHeld = true; @@ -483,11 +517,38 @@ struct gvfg_channel_session_t out.bit_depth = static_cast(frame.bit_depth); out.frame_id = frame.frame_id; out.timestamp_ns = frame.timestamp_ns; + if (timing) + timing->frame_id = out.frame_id; noteDeliveredFrame(out.width, out.height, out.bit_depth, out.pixel_format); return GVFG_OK; } + gvfg_status_t osdExperimentFlags(uint64_t frameId, uint32_t &flags) + { + flags = 0; +#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE + flags = GVFG_DEBUG_OSD_EXPERIMENT_ENABLED; +#endif + if (frameId == 0) + return GVFG_OK; + std::lock_guard lock(frameMutex); + if (!frameHeld || heldSessionFrame.frame_id != frameId) + return GVFG_ESTATE; + flags = heldOsdExperimentFlags; + return GVFG_OK; + } + + gvfg_status_t osdPageCheck(uint64_t frameId, gvfg_debug_osd_page_check_t &check) + { + check = {}; + std::lock_guard lock(frameMutex); + if (!frameId || !frameHeld || heldSessionFrame.frame_id != frameId) + return GVFG_ESTATE; + check = heldOsdPageCheck; + return GVFG_OK; + } + gvfg_status_t releaseFrame(const gvfg_frame_t &frameToken) { if (!session) @@ -628,7 +689,9 @@ struct gvfg_channel_session_t const gvfg_status_t status = osdProcessor.configure(config); return status == GVFG_OK ? GVFG_OK - : reject(status, "gvfg_set_channel_osd rejected: configuration is invalid"); + : reject(status, status == GVFG_EINVAL + ? "gvfg_set_channel_osd rejected: configuration is invalid" + : "gvfg_set_channel_osd failed to store configuration"); } gvfg_status_t clearOsd() @@ -820,6 +883,8 @@ struct gvfg_channel_session_t std::atomic running{false}; std::mutex frameMutex; bool readInProgress = false; + uint32_t heldOsdExperimentFlags = 0; + gvfg_debug_osd_page_check_t heldOsdPageCheck{}; bool frameHeld = false; bool heldFrameNeedsBackendRelease = false; uint64_t videoFrameId = 0; @@ -1108,6 +1173,45 @@ extern "C" return handle->setChannelVideoFormat(channel_index, format); } + gvfg_status_t gvfg_measure_osd_text(const char *text, uint32_t text_length, + uint32_t font_size_px, + uint32_t *out_width, uint32_t *out_height) + { + if (out_width) + *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; + for (uint32_t i = 0; i < text_length; ++i) + { + const unsigned char c = static_cast(text[i]); + if (c < 0x20 || c > 0x7e) + return GVFG_EINVAL; + } + + try + { + gvfg_osd_handle rawHandle = nullptr; + if (gvfg_osd_create(&rawHandle) != GVFG_OSD_OK) + return GVFG_EIO; + const std::unique_ptr helper( + rawHandle, &gvfg_osd_destroy); + const gvfg_osd_status_t status = gvfg_osd_measure( + helper.get(), text, text_length, font_size_px, out_width, out_height); + if (status == GVFG_OSD_OK) + return GVFG_OK; + return status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO; + } + catch (...) + { + *out_width = 0; + *out_height = 0; + return GVFG_EIO; + } + } + gvfg_status_t gvfg_set_channel_osd(gvfg_handle handle, int channel_index, const gvfg_channel_osd_config_t *config) @@ -1180,6 +1284,65 @@ extern "C" "gvfg_read_channel_frame rejected: channel is not open"); } + gvfg_status_t gvfg_debug_read_channel_frame_timed(gvfg_handle handle, + int channel_index, + gvfg_frame_t *out_frame, + gvfg_debug_osd_frame_timing_t *out_timing, + uint32_t timeout_ms) + { + if (out_timing) + *out_timing = {}; + if (!handle || !out_frame || !out_timing) + return GVFG_EINVAL; + gvfg_channel_session_t *channel = handle->findChannel(channel_index); + return channel ? channel->readFrame(*out_frame, timeout_ms, out_timing) + : handle->rejectChannel(channel_index, GVFG_ESTATE, + "gvfg_debug_read_channel_frame_timed rejected: channel is not open"); + } + + gvfg_status_t gvfg_debug_read_channel_frame_profiled(gvfg_handle handle, + int channel_index, + gvfg_frame_t *out_frame, + gvfg_debug_frame_read_timing_t *out_timing, + uint32_t timeout_ms) + { + if (out_timing) + *out_timing = {}; + if (!handle || !out_frame || !out_timing) + return GVFG_EINVAL; + gvfg_channel_session_t *channel = handle->findChannel(channel_index); + return channel ? channel->readFrame(*out_frame, timeout_ms, &out_timing->osd, + &out_timing->acquisition_begin_ns) + : handle->rejectChannel(channel_index, GVFG_ESTATE, + "gvfg_debug_read_channel_frame_profiled rejected: channel is not open"); + } + + gvfg_status_t gvfg_debug_get_channel_osd_experiment_flags(gvfg_handle handle, + int channel_index, + uint64_t frame_id, + uint32_t *out_flags) + { + if (out_flags) + *out_flags = 0; + if (!handle || !out_flags) + return GVFG_EINVAL; + gvfg_channel_session_t *channel = handle->findChannel(channel_index); + return channel ? channel->osdExperimentFlags(frame_id, *out_flags) : GVFG_ESTATE; + } + + gvfg_status_t gvfg_debug_get_channel_osd_page_check(gvfg_handle handle, + int channel_index, + uint64_t frame_id, + gvfg_debug_osd_page_check_t *out_check) + { + if (out_check) + *out_check = {}; + if (!handle || !out_check) + return GVFG_EINVAL; + gvfg_channel_session_t *channel = handle->findChannel(channel_index); + return channel ? channel->osdPageCheck(frame_id, *out_check) : GVFG_ESTATE; + } + gvfg_status_t gvfg_release_channel_frame(gvfg_handle handle, int channel_index, const gvfg_frame_t *frame) diff --git a/docs/GVFG_CUSTOMER_API.md b/docs/GVFG_CUSTOMER_API.md index 4346c15..db1023a 100644 --- a/docs/GVFG_CUSTOMER_API.md +++ b/docs/GVFG_CUSTOMER_API.md @@ -99,9 +99,9 @@ int main(void) - API 是 pull model;應用程式自行決定在哪個執行緒呼叫 `gvfg_read_channel_frame()`。GUI 程式建議每個 channel 使用一個 worker thread,再把 UI 更新送回 UI thread。 -- Copy mode 的 `frame.data` 由 SDK 擁有;zero-copy mode 則指向 driver-owned - buffer。兩種模式都只在對應的 `gvfg_release_channel_frame()` 前有效,資料若要長期 - 保存,必須先複製。 +- `frame.data` 是唯讀的借用 pointer,可能指向原生擷取 buffer 或 SDK 處理後的 + buffer。Zero-copy 設定控制擷取方式;啟用 OSD 時仍可能交付 SDK-owned buffer。 + Pointer 只在對應的 `gvfg_release_channel_frame()` 前有效,資料若要長期保存,必須先複製。 - 每個 channel 同時最多持有一個 frame。尚未 release 又對同一 channel 呼叫 `gvfg_read_channel_frame()`,會回傳 `GVFG_ESTATE`。 - release 時傳回 read 取得的 `gvfg_frame_t`;SDK 以 `data + frame_id` 確認目前 held frame。 @@ -220,10 +220,35 @@ Zero-copy mode 的 driver lifecycle 由 SDK 管理:open 時 enable,destroy/c ### Frame -- `gvfg_read_channel_frame(handle, channel, &frame, timeout_ms)`:取得一個 frame;ownership 依 copy/ - zero-copy mode 而定,但 release contract 相同。 +- `gvfg_read_channel_frame(handle, channel, &frame, timeout_ms)`:取得原生或 SDK 處理後的唯讀 + frame;copy/zero-copy acquisition 的 release contract 相同。 - `gvfg_release_channel_frame(handle, channel, &frame)`:釋放原 frame token。 +### SDK OSD + +OSD 整合在 `gvfg.dll`,不需要額外的 OSD DLL 或 `gvfg_preview.dll`。啟用後, +`gvfg_read_channel_frame()` 交付含 OSD 的完整 YUY2/Y210 frame;使用後照常 release。 + +- `gvfg_measure_osd_text(text, text_length, font_size_px, &width, &height)`:量測與實際 + OSD 相同的單行文字框;不需要 handle,也不會開啟 capture device。 +- `gvfg_set_channel_osd(handle, channel, &config)`:啟用或更新已 open channel 的 OSD。 + SDK 同步複製文字設定,後續 frame 使用新設定。 +- `gvfg_clear_channel_osd(handle, channel)`:停用後續 frame 的 OSD。 + +`gvfg_channel_osd_config_t` 可設定文字、`x/y`、`font_size_px` 與 `color_rgb`。 +文字為 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 安全邊, +是保守的完整文字框,不是逐像素緊貼的字形邊界。`x/y` 表示這個框的左上角; +SDK 會依實際 frame 限制在 `0..frame.width - text_width`、 +`0..frame.height - text_height`。文字框比 frame 大時,SDK 暫不疊字並繼續擷取; +設定或 frame 尺寸改成可容納後會恢復,不會縮字、截字或換行。 + +量測的兩個 output pointer 不可為 NULL;失敗時可寫入的 output 會歸零。 +無效文字、長度、字號或 pointer 回傳 `GVFG_EINVAL`;量測失敗回傳 `GVFG_EIO`。 + ### Audio frame - `gvfg_set_channel_audio_enabled(handle, channel, enabled)`:在 start 前啟用或停用 diff --git a/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md b/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md index f53aac5..4c6b9ec 100644 --- a/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md +++ b/docs/GVFG_Customer_doc/GVFG_CUSTOMER_API_REFERENCE.md @@ -20,6 +20,7 @@ | ----------------------- | ------------:| ----------------------------- | | `GVFG_MAX_DEVICES` | 16 | 一次最多列舉的裝置數 | | `GVFG_TIMEOUT_INFINITE` | `UINT32_MAX` | 無限等待;`timeout_ms == 0` 則完全不等待 | +| `GVFG_OSD_MAX_TEXT_CHARACTERS` | 32 | OSD 可列印 ASCII 字元數上限 | ### 1.2 `gvfg_status_t` @@ -265,6 +266,22 @@ typedef struct gvfg_handle_t *gvfg_handle; 只能由 `gvfg_create()` 建立、由 `gvfg_destroy()` 銷毀;caller 不可取得、配置或修改其內部內容。 +### 1.20 `gvfg_channel_osd_config_t` + +由 caller 建立並傳給 `gvfg_set_channel_osd()`。SDK 在函式返回前複製文字及設定, +caller 不必持續保留 `text` pointer。 + +| 欄位 | 型別 | 說明 | +| --- | --- | --- | +| `text` | `const char *` | 可列印 ASCII(`0x20`–`0x7e`),不可為 NULL | +| `text_length` | `uint32_t` | 1–32 個字元;不包含結尾 NUL | +| `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 +及四邊各 1 px 安全邊;用 `gvfg_measure_osd_text()` 取得與繪製相同的保守框大小。 + ## 2. GVFG API 函式 說明 `gvfg_capture.h` 的所有公開函式。 @@ -357,6 +374,8 @@ gvfg_status_t gvfg_get_channel_zero_copy_enabled(/* [in] */ gvfg_handle handle, - `get` 可查詢指定 channel 的模式;`out_enabled` 不可為 NULL。 - Zero-copy mode 的 `frame.data` 是借用的 pointer;仍必須以相同 descriptor 呼叫 `gvfg_release_channel_frame()`,且每個 channel 同時最多持有一張 frame。 +- 此設定控制原生 frame 的擷取方式。OSD 等 SDK 處理可能交付 SDK-owned output + buffer;caller 的 read/release 流程相同。 ### 2.7 `gvfg_set_channel_video_format` @@ -599,7 +618,7 @@ gvfg_status_t gvfg_get_channel_runtime_info( const char *gvfg_get_version(void); ``` -- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"1.0.2"`。 +- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"1.1.0"`。 - 回傳值是靜態 null-terminated 字串,caller 不可 free。 - 可用於 log、問題回報,以及確認 header、DLL 是否來自同一版本。 @@ -641,6 +660,52 @@ gvfg_status_t gvfg_get_channel_last_sdk_error_detail(/* [in] */ gvfg_handle hand - 同一 channel 若被多執行緒同時操作,內容可能被後續錯誤覆蓋;應在失敗後立即取得。 - `GVFG_EINVAL`:handle/message 為 NULL、channel index 無效,或 buffer size 為 0。 +### 2.25 `gvfg_measure_osd_text` + +```c +gvfg_status_t gvfg_measure_osd_text( + /* [in] */ const char *text, + /* [in] */ uint32_t text_length, + /* [in] */ uint32_t font_size_px, + /* [out] */ uint32_t *out_width, + /* [out] */ uint32_t *out_height); +``` + +- 不需要 capture handle,不會開啟 device,可在 Start 前量測。 +- `text`:1–32 個可列印 ASCII 字元(`0x20`–`0x7e`),不接受換行。 +- `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` + +```c +gvfg_status_t gvfg_set_channel_osd( + /* [in] */ gvfg_handle handle, + /* [in] */ int channel_index, + /* [in] */ const gvfg_channel_osd_config_t *config); +gvfg_status_t gvfg_clear_channel_osd( + /* [in] */ gvfg_handle handle, + /* [in] */ int channel_index); +``` + +- Channel 必須已 open;可在 Start 前或擷取期間設定或停用。 +- `set` 同步複製設定,套用於後續 YUY2/Y210 frame;文字顏色為 BT.709 limited range, + 由 GPU 混合。客戶不需要額外部署 OSD DLL 或使用 preview helper。 +- `x/y` 是量測文字框左上角。SDK 依每個 frame 把位置限制在 + `[0, frame.width - text_width]`/`[0, frame.height - text_height]`。 +- 文字框本身比 frame 大時暫不疊字,擷取仍繼續;設定、frame 尺寸或格式變更後重新判斷。 + 可容納時恢復 OSD,不縮字、截字或換行。 +- `clear` 停用後續 frame 的 OSD。已取得的 frame 仍照原本生命週期使用與 release。 +- `GVFG_OK`:設定或停用成功;不表示文字已完成繪製或一定能放入當前 frame。 +- `GVFG_EINVAL`:NULL handle/config、無效文字長度、字元或零字號。 +- `GVFG_ESTATE`:指定 channel 尚未 open;其他處理失敗可回傳 `GVFG_EIO`。 +- 啟用 OSD 的 frame 可能為 SDK-owned output,即使擷取使用 zero-copy; + 每次成功 read 仍須恰好 release 一次。 + ## 3. Preview API 完整參考 本節說明選用的 `gvfg_preview.h`。Preview status 與 core `gvfg_status_t` 是不同 enum, diff --git a/docs/INTERNAL_BUILD_GUIDE.md b/docs/INTERNAL_BUILD_GUIDE.md index 8013fc0..cdf1135 100644 --- a/docs/INTERNAL_BUILD_GUIDE.md +++ b/docs/INTERNAL_BUILD_GUIDE.md @@ -38,6 +38,12 @@ ## 4. 更新 SDK 版本 +目前 SDK 版本為 `1.1.0`。後續版本採 `MAJOR.MINOR.PATCH`: + +- 新增功能:更新中間的 MINOR,並將 PATCH 歸零,例如 `1.1.0` → `1.2.0`。 +- 修正 bug:更新最後的 PATCH,例如 `1.1.0` → `1.1.1`。 +- 同一次版本同時有新功能與 bug 修正時,以新增功能的升版規則為準。 + 版本只有一個來源:`GVFG_SDK/CMakeLists.txt` 的 `GVFG_SDK_VERSION`。例如準備 `1.0.0-rc.1` 時改成: