Reject frames read across a stop and restart of a GVFG channel

- Record the channel's run generation when a read begins and refuse delivery if stop and start ran during the read. The frame belonged to the stopped stream and its backend hold had been reset, so the caller's release failed with GVFG_ESTATE and every later read stayed rejected until the next stop.
- Return GVFG_ESTATE with a specific last-error message in that case, and document it in the customer API reference.

Validation: git diff --cached --check passed. The MSVC Release SDK build passed. On a GIGABYTE SDI VFG100 with a 1080p60 SDI signal, a hardware reproduction that parks a read between capture and delivery left the channel stuck with the previous 3.2.0 code and with 3.1.0, and passed with this change. The Viewer capture journey (start, snapshot, stop, restart) passed on this SDK. A TLA+ model of the frame-hold protocol, kept outside this commit, passes with the reader running across stop and start. SDK version not bumped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 16:24:35 +08:00
co-authored by Claude Opus 5.5
parent b47f27bd39
commit 1d89392cef
2 changed files with 16 additions and 4 deletions
+15 -3
View File
@@ -218,7 +218,11 @@ struct gvfg_channel_session_t
if (st != GVFG_OK)
return st;
running = true;
{
std::lock_guard<std::mutex> lock(frameMutex);
++runGeneration;
running = true;
}
return GVFG_OK;
}
@@ -383,6 +387,7 @@ struct gvfg_channel_session_t
return reject(GVFG_ESTATE, "gvfg_read_channel_frame rejected: channel is not running");
const char *stateError = nullptr;
uint64_t readRunGeneration = 0;
{
std::lock_guard<std::mutex> lock(frameMutex);
if (frameHeld)
@@ -390,7 +395,10 @@ struct gvfg_channel_session_t
else if (readInProgress)
stateError = "gvfg_read_channel_frame rejected: another read is already in progress";
else
{
readInProgress = true;
readRunGeneration = runGeneration;
}
}
if (stateError)
return reject(GVFG_ESTATE, stateError);
@@ -478,7 +486,9 @@ struct gvfg_channel_session_t
bool stoppedWhileWaiting = false;
{
std::lock_guard<std::mutex> lock(frameMutex);
if (!running.load(std::memory_order_acquire))
// A stop and start during this read set running back to true, but the
// frame belongs to the stopped stream and its backend hold is gone.
if (!running.load(std::memory_order_acquire) || runGeneration != readRunGeneration)
{
readInProgress = false;
stoppedWhileWaiting = true;
@@ -496,7 +506,8 @@ struct gvfg_channel_session_t
{
if (backendFrameHeld)
session->release_frame();
return GVFG_ESTATE;
return reject(GVFG_ESTATE,
"gvfg_read_channel_frame rejected: capture stopped or restarted during the read");
}
updateRuntimeFps(now_ns());
@@ -839,6 +850,7 @@ struct gvfg_channel_session_t
bool readInProgress = false;
bool frameHeld = false;
bool heldFrameNeedsBackendRelease = false;
uint64_t runGeneration = 0; // Protected by frameMutex; bumped by every successful start.
uint64_t videoFrameId = 0;
gvfg_frame_t heldSessionFrame{};
std::mutex processorMutex;