Refine signal caching and Sample device lifecycle

Compared with 350e8e5:

- perform one fresh GigabyteLib signal query for each explicit channel Start and reject a no-lock request with GVFG_ETIMEOUT instead of entering a placeholder monitoring stream

- keep running signal-status reads on the SDK cache and synchronize format-change, input plug-in, and input unplug state before publishing the corresponding event

- invalidate cached video information when the output depth changes so format selection does not cause an extra immediate hardware read

- make the Qt Sample refresh SDI information after a successful Start and on signal events without polling it from the periodic status timer

- close the Sample device session after the final running channel stops or an idle Start path fails, while preserving the selected device for the next Start

- document the updated Start result, event/cache ordering, query boundaries, and Sample ownership policy across the public API and internal flow guides

Validation: git diff --check passed. The SDK and Qt Sample builds completed successfully during this change. Hardware no-signal, plug/unplug, dual-process handoff, and recording tests were not rerun for this commit.
This commit is contained in:
Mark.lin
2026-09-16 10:37:18 +08:00
parent 350e8e519c
commit 7fb0028ba6
11 changed files with 178 additions and 72 deletions
+8 -5
View File
@@ -385,16 +385,16 @@ extern "C"
* - handle: Running session handle.
*
* Returns:
* - GVFG_OK on success, including when capture is already running or the SDK
* has entered signal-monitoring mode while no input is connected.
* - GVFG_OK on success, including when capture is already running.
* - GVFG_EINVAL if handle is NULL.
* - GVFG_ESTATE if no device is open.
* - GVFG_ETIMEOUT if a fresh signal query reports no connected input.
* - GVFG_EIO or another status code if stream configuration/start fails.
*
* After success, call gvfg_read_channel_frame() to receive frames and
* gvfg_poll_channel_event()
* to receive capture events. With no input signal, frame reads time out; capture
* starts automatically after a signal-connected event.
* to receive capture events. Each explicit start performs one fresh signal
* query; a no-signal result does not leave the channel running.
*/
GVFG_API gvfg_status_t gvfg_start_channel(
GVFG_PARAM_IN gvfg_handle handle,
@@ -569,7 +569,10 @@ extern "C"
* - GVFG_ESTATE if no capture device is open.
*
* No input signal is a normal state: the function returns GVFG_OK with
* out_status->connected set to 0.
* out_status->connected set to 0. Before capture starts, this function
* refreshes the status from GigabyteLib. While capture is running, it returns
* the SDK cache; format-change, input-plug and input-unplug processing updates
* that cache before the corresponding public event is queued.
*/
GVFG_API gvfg_status_t gvfg_get_channel_signal_status(
GVFG_PARAM_IN gvfg_handle handle,
@@ -139,6 +139,10 @@ void GigabyteCaptureSession::close_vendor_channel() const
std::lock_guard<std::mutex> lock(state_mutex_);
video_info_valid_ = false;
audio_info_valid_ = false;
cached_signal_ = {};
cached_signal_.channel = channel_;
video_info_ = {};
audio_info_ = {};
}
if (context_)
GvfgCloseDev(&context_);
@@ -214,7 +218,12 @@ gvfg_status_t GigabyteCaptureSession::set_video_format(gvfg_pixel_format_t forma
: GVFG_VIDEO_COLOR_DEPTH_8_BITS;
const gvfg_status_t status = from_vendor(
GvfgSetVideoColorDepth(context_, channel_, colorDepth));
return status == GVFG_OK ? refresh_video_info() : status;
if (status == GVFG_OK)
{
std::lock_guard<std::mutex> lock(state_mutex_);
video_info_valid_ = false;
}
return status;
}
gvfg_status_t GigabyteCaptureSession::refresh_video_info() const
@@ -364,17 +373,6 @@ gvfg_status_t GigabyteCaptureSession::configure_stream()
const gvfg_status_t openStatus = ensure_vendor_channel_open();
if (openStatus != GVFG_OK)
return openStatus;
bool refresh = false;
{
std::lock_guard<std::mutex> lock(state_mutex_);
refresh = !video_info_valid_;
}
if (refresh)
{
const gvfg_status_t status = refresh_video_info();
if (status != GVFG_OK)
return status;
}
configured_ = true;
return GVFG_OK;
}
@@ -537,6 +535,12 @@ gvfg_status_t GigabyteCaptureSession::release_frame()
return GVFG_OK;
}
void GigabyteCaptureSession::get_cached_signal_status(gvfg_signal_status_t &out) const
{
std::lock_guard<std::mutex> lock(state_mutex_);
out = cached_signal_;
}
gvfg_status_t GigabyteCaptureSession::wait_audio(
uint32_t timeoutMs, void *destination, uint32_t destinationCapacity, uint32_t &outBytes)
{
@@ -47,6 +47,7 @@ namespace gvfg::internal
gvfg_status_t set_audio_enabled(bool enabled);
gvfg_status_t set_video_format(gvfg_pixel_format_t format);
gvfg_status_t get_signal_status(gvfg_signal_status_t &out) const;
void get_cached_signal_status(gvfg_signal_status_t &out) const;
gvfg_status_t get_device_capabilities(gvfg_device_capabilities_t &out) const;
gvfg_status_t get_sdi_info(gvfg_sdi_info_t &out) const;
gvfg_status_t get_audio_format(GigabyteAudioInfo &out) const;
+33 -2
View File
@@ -254,7 +254,7 @@ struct gvfg_channel_session_t
if (!session)
return reject(GVFG_ESTATE, "gvfg_get_channel_signal_status rejected: channel is not open");
std::memset(&out, 0, sizeof(out));
const gvfg_status_t status = querySignal();
const gvfg_status_t status = running ? syncCachedSignal() : querySignal();
{
std::lock_guard<std::mutex> lock(stateMutex);
out.connected = signalConnected ? 1 : 0;
@@ -263,6 +263,7 @@ struct gvfg_channel_session_t
out.height = static_cast<int>(height);
out.pixel_format = static_cast<int>(pixelFormat);
out.bit_depth = static_cast<int>(bitDepth);
out.video_interface = videoInterface;
}
return status;
}
@@ -291,6 +292,7 @@ struct gvfg_channel_session_t
auto *self = static_cast<gvfg_channel_session_t *>(user);
if (!self)
return;
self->syncCachedSignal();
self->emitEvent(event);
}
@@ -323,10 +325,29 @@ struct gvfg_channel_session_t
pixelFormat = status == GVFG_OK
? static_cast<gvfg_pixel_format_t>(sig.pixel_format)
: GVFG_PIXFMT_UNKNOWN;
videoInterface = status == GVFG_OK ? sig.video_interface : 0;
signalConnected = status == GVFG_OK && sig.connected != 0;
return status;
}
gvfg_status_t syncCachedSignal()
{
if (!session)
return GVFG_ESTATE;
gvfg_signal_status_t sig{};
session->get_cached_signal_status(sig);
std::lock_guard<std::mutex> lock(stateMutex);
width = sig.width > 0 ? static_cast<uint32_t>(sig.width) : 0;
height = sig.height > 0 ? static_cast<uint32_t>(sig.height) : 0;
bitDepth = sig.bit_depth > 0 ? static_cast<uint32_t>(sig.bit_depth) : 0;
pixelFormat = static_cast<gvfg_pixel_format_t>(sig.pixel_format);
videoInterface = sig.video_interface;
signalConnected = sig.connected != 0;
return GVFG_OK;
}
gvfg_status_t configureStream()
{
if (!session)
@@ -335,7 +356,16 @@ struct gvfg_channel_session_t
const gvfg_status_t st = session->configure_stream();
if (st != GVFG_OK)
return st;
return querySignal();
const gvfg_status_t signalStatus = querySignal();
if (signalStatus != GVFG_OK)
return signalStatus;
{
std::lock_guard<std::mutex> lock(stateMutex);
if (!signalConnected)
return reject(GVFG_ETIMEOUT,
"gvfg_start_channel rejected: no input signal");
}
return GVFG_OK;
}
gvfg_status_t readFrame(gvfg_frame_t &out, uint32_t timeoutMs)
@@ -721,6 +751,7 @@ struct gvfg_channel_session_t
uint32_t height = 0;
uint32_t bitDepth = 0;
gvfg_pixel_format_t pixelFormat = GVFG_PIXFMT_UNKNOWN;
int videoInterface = 0;
bool signalConnected = false;
mutable std::mutex stateMutex;
std::atomic<uint64_t> fpsWindowStartNs{0};