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
@@ -5,6 +5,7 @@ add_library(gvfg_playback SHARED
include/gvfg_playback.h
src/gvfg_playback.cpp
src/playback_timing.h
src/playback_debug.h
src/signal_card.h
src/signal_card.cpp
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_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)
if(MSVC)
target_compile_options(gvfg_playback PRIVATE /utf-8 /EHsc)
+8 -6
View File
@@ -1,6 +1,6 @@
# 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)。
本文件供 SDK 維護者,說明目前實作,不作為 Customer Demo 的除錯畫面需求。
@@ -146,9 +146,11 @@ core 非同步失敗保存在 last_error,worker 暫停,後續 submit 回報
stop/reset 取消 queue,不是無損 drain。reset 沿用舊 config,音訊格式改變應明確 stop/start 新設定。
呼叫端先停止/join read producers、release token,再停止 Playback 與 Capture。
2.0.2 stats 尾端新增 video_dropped;2.0.4 追加 sync_degraded、sync_fallbacks、audio_dropped_frames。
getter 明確接受目前大小、2.0.2/2.0.3 大小及 2.0.0/2.0.1 原始大小,
只回填 caller 提供的範圍;不是對任意 struct_size 都相容。config 仍要求目前完整大小。
詳細統計位於私有 `src/playback_debug.h`,不安裝到客戶套件。核心保留診斷計數與同步狀態。
僅 Debug DLL 匯出 `gvfg_playback_debug_get_stats()`;內部工具須定義
`GVFG_INTERNAL_DIAGNOSTICS=1` 並使用同一版私有標頭與 MSVC Debug 匯入庫。
診斷結構不提供穩定 ABI 或舊大小相容;Release DLL 不匯出診斷查詢。
config 仍要求目前完整的 struct_size。
公開 API/資料變更需同步標頭、匯入庫、DLL、Reference 與 Demo,避免混版。
## 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 秒,
含視窗/全螢幕切換:約 60 fps,queue 未持續增長;7166 張輸入,processed 7160、presented 7158、dropped 2。
其餘待播 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 步進與輸出後端:
舊版在 audio source 慢 500 ppm 時,910.084 秒出現 buffering、video queue 32、EQUEUE_FULL。
@@ -172,7 +174,7 @@ Audio master 遇到來源較慢時仍會耗盡既有緩衝並重新緩衝,未
2.0.4 決定性 core 模擬通過:完全無音訊、延後出現、五秒斷音、五秒停影、
來源半速/兩倍速及恢復、各 master、video-only/audio-only、GPU worker 暫停且 video queue 只有兩張。
檢查無拒收、容量不超限、影像持續消化、來源恢復後退出降級,以及兩種既有 stats 大小的尾端 guard。
檢查無拒收、容量不超限、影像持續消化、來源恢復後退出降級。
後端模擬 reset 延遲五毫秒,驗證 reset 完成前不會餵入新 mapping。
正常 ±500 ppm 各模擬兩小時,沒有降級,video queue 最大 6~7。
@@ -13,7 +13,6 @@ EXPORTS
gvfg_playback_reset_timeline
gvfg_playback_stop
gvfg_playback_destroy
gvfg_playback_get_stats
gvfg_playback_get_preview_info
gvfg_playback_get_preview_stats
gvfg_playback_get_delivery_stats
@@ -59,30 +59,6 @@ typedef struct {
gvfg_preview_frame_t image;
uint64_t timestamp_ns; /* Common monotonic delivery clock, NOT UTC. */
} 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 gvfg_playback_status_t gvfg_playback_create(gvfg_playback *out);
/* 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_stop(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_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);
@@ -2,6 +2,7 @@
#include "audio_output_internal.h"
#include "preview_output_internal.h"
#include "playback_timing.h"
#include "playback_debug.h"
#include "signal_card.h"
#include <windows.h>
#include <algorithm>
@@ -9,8 +10,6 @@
#include <chrono>
#include <cmath>
#include <condition_variable>
#include <cstring>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <limits>
@@ -49,7 +48,7 @@ struct gvfg_playback_t {
gvfg_preview_handle preview = nullptr;
gvfg_audio_player audio = nullptr;
gvfg_playback_config_t config{};
gvfg_playback_stats_t stats{};
gvfg_playback_debug_stats_t stats{};
std::deque<Video> videos;
std::deque<Audio> audios;
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;
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;
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->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;
@@ -579,15 +578,11 @@ void gvfg_playback_destroy(gvfg_playback p) {
gvfg_playback_stop(p); p->signal_card.attach(nullptr);
gvfg_preview_destroy(p->preview); delete p;
}
gvfg_playback_status_t gvfg_playback_get_stats(gvfg_playback p, gvfg_playback_stats_t *s) {
// Keep 2.0.0/2.0.1 callers with the original struct size ABI-compatible.
constexpr uint32_t legacy_size = offsetof(gvfg_playback_stats_t, video_dropped);
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;
#if GVFG_INTERNAL_DIAGNOSTICS
gvfg_playback_status_t gvfg_playback_debug_get_stats(gvfg_playback p, gvfg_playback_debug_stats_t *s) {
if (!p || !s) return GVFG_PLAYBACK_EINVAL;
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());
if (p->has_audio() && 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) *
1000.0 / p->config.audio_format.sample_rate;
}
std::memcpy(s, &result, requested_size);
*s = result;
return GVFG_PLAYBACK_OK;
}
#endif
gvfg_playback_status_t gvfg_playback_get_preview_info(gvfg_playback p, gvfg_preview_info_t *s) {
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