Fix zero-copy frame lifecycle
Enable zero-copy through the public API before opening the device and configure a driver-owned zero-copy ring slot. Return every delivered frame through IOCTL_GIGA_RELEASE_VIDEO_FRAME and validate the complete frame token before release. Preserve ownership when the release IOCTL fails so stop, close, or the next start can retry instead of discarding the driver pointer. Stop DMA and join the backend acquire/event thread before draining frames, preventing acquire from racing stop or disable. Drain caller-held, ready, unread, and pending zero-copy frames before stop, restart, disable, device close, or process destruction. Block restart and zero-copy disable when outstanding frames cannot be released successfully. Release unread frames on signal unplug and before format or resolution changes rebuild the frame ring. Propagate stop and release errors through the public API and report release failures in the standalone preview. Document zero-copy ownership, lifecycle requirements, diagnostics, and data flow. Verified with Standalone Debug and Release builds.
This commit is contained in:
@@ -228,10 +228,29 @@ struct gvfg_handle_t
|
||||
return map_status(stChannel);
|
||||
}
|
||||
|
||||
if (zeroCopyRequested)
|
||||
{
|
||||
const pcies2mm_status_t stZeroCopy = backend->set_zero_copy_enabled(true);
|
||||
if (stZeroCopy != PCIES2MM_OK)
|
||||
{
|
||||
recordError(pcies2mm_error_text(stZeroCopy, backend.get()));
|
||||
close();
|
||||
return map_status(stZeroCopy);
|
||||
}
|
||||
}
|
||||
|
||||
querySignal();
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t setZeroCopyEnabled(bool enabled)
|
||||
{
|
||||
if (backend)
|
||||
return GVFG_ESTATE;
|
||||
zeroCopyRequested = enabled;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t start()
|
||||
{
|
||||
if (!backend)
|
||||
@@ -265,9 +284,13 @@ struct gvfg_handle_t
|
||||
running = false;
|
||||
eventCv.notify_all();
|
||||
releaseHeldFrameForStop();
|
||||
if (backend)
|
||||
backend->stop_stream();
|
||||
return GVFG_OK;
|
||||
if (!backend)
|
||||
return GVFG_OK;
|
||||
|
||||
const pcies2mm_status_t st = backend->stop_stream();
|
||||
if (st != PCIES2MM_OK)
|
||||
recordError(pcies2mm_error_text(st, backend.get()));
|
||||
return map_status(st);
|
||||
}
|
||||
|
||||
void close()
|
||||
@@ -734,6 +757,7 @@ struct gvfg_handle_t
|
||||
std::unique_ptr<gvfg::internal::PcieS2mmCaptureSession> backend;
|
||||
int currentIndex = -1;
|
||||
uint32_t selectedChannel = GVFG_CHANNEL_0;
|
||||
bool zeroCopyRequested = false;
|
||||
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
@@ -815,6 +839,21 @@ extern "C"
|
||||
return handle->open(device_index, channel_index);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_zero_copy_enabled(gvfg_handle handle, int enabled)
|
||||
{
|
||||
if (!handle || (enabled != 0 && enabled != 1))
|
||||
return GVFG_EINVAL;
|
||||
return handle->setZeroCopyEnabled(enabled != 0);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_zero_copy_enabled(gvfg_handle handle, int *out_enabled)
|
||||
{
|
||||
if (!handle || !out_enabled)
|
||||
return GVFG_EINVAL;
|
||||
*out_enabled = handle->zeroCopyRequested ? 1 : 0;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_start(gvfg_handle handle)
|
||||
{
|
||||
if (!handle)
|
||||
|
||||
Reference in New Issue
Block a user