Harden GVFG signal recovery and preview lifecycle

Compared with d03f064:

- Pause the sample video and audio readers after signal disconnect events and resume them only after reconnect or stream-ready notification.

- Serialize plug, unplug, and format transitions against active reads and held zero-copy frames while keeping stop and close able to interrupt lifecycle waits.

- Treat ERROR_BAD_COMMAND as unplug-revoked zero-copy ownership only after the backend has confirmed signal loss, while preserving all other release failures for retry and diagnosis.

- Stop submitting frames when the user closes an independent preview window, account those frames as intentionally skipped, and resume submission when preview is reopened.

- Emit UTF-16 Windows debug output so localized Win32 error messages remain readable in Qt and debugger output.

- Add startup and first-frame timing diagnostics, reduce routine stream-ready logging, and update public and internal documentation for the new disconnect and ownership behavior.

Validation: git diff --check and focused symbol/document consistency searches passed; no build or hardware validation was run.
This commit is contained in:
Mark.lin
2026-09-08 12:20:39 +08:00
parent d03f064b4f
commit 8cde31feaf
11 changed files with 244 additions and 29 deletions
+8 -1
View File
@@ -10,6 +10,7 @@
#include <array>
#include <atomic>
#include <condition_variable>
#include <chrono>
#include <cstdint>
#include <deque>
#include <mutex>
@@ -45,7 +46,11 @@ private:
gvfg_preview_handle previewHandle = nullptr;
std::atomic<bool> running{false};
std::atomic<bool> stopRequested{false};
std::atomic<bool> signalConnected{false};
std::mutex signalMutex;
std::condition_variable signalReady;
std::atomic<bool> frameAvailable{false};
std::atomic<bool> previewVisible{false};
std::thread captureThread;
std::thread audioThread;
std::thread audioPlaybackThread;
@@ -73,10 +78,12 @@ private:
qint64 audioLastDropTimeMs = 0;
double audioMaxWriteStallMs = 0;
double audioMaxReadGapMs = 0;
std::atomic<uint64_t> videoReceived{0}, videoSubmitted{0}, videoFailed{0};
std::atomic<uint64_t> videoReceived{0}, videoSubmitted{0}, videoSkipped{0}, videoFailed{0};
std::atomic<uint64_t> videoIdGaps{0}, videoIdResets{0};
std::atomic<uint64_t> videoLastId{0};
gvfg_preview_delivery_stats_t previewBaseline{};
std::chrono::steady_clock::time_point startupStartTime{};
double startupStartCallMs = 0.0;
uint64_t lastLoggedVideoIssues = 0, lastLoggedAudioIssues = 0;
qint64 lastDeliveryLogMs = 0;
std::atomic<double> getFrameAverageMs{0.0};