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:
Mark.lin
2026-08-19 15:34:37 +08:00
parent 61da467d83
commit 024df690c3
12 changed files with 443 additions and 138 deletions
+16
View File
@@ -67,6 +67,22 @@ SDK 不再呼叫 `IOCTL_PCIES2MM_GET_VIDEO_DONE_INDEX`,也不會在新 IOCTL
`IRQ_MASK_W1S_OFFSET`。若搭配舊版 driver,stream start 或 frame capture
可能失敗。
### Zero-copy selection
上層程式可在 `gvfg_create()` 後、`gvfg_open_channel()` 前選擇 zero-copy:
```c
gvfg_handle handle = NULL;
gvfg_create(&handle);
gvfg_set_zero_copy_enabled(handle, 1); /* 0: copy, 1: zero-copy */
gvfg_open_channel(handle, device_index, GVFG_CHANNEL_0);
```
預設為 copy mode。Device open 後不可切換模式;如需切換,必須 destroy
並重建 session。Zero-copy mode 仍使用相同的 `gvfg_read_frame()` /
`gvfg_release_frame()` ownership contract,每次成功 read 都必須 release。
SDK 會在 open 時 enable zero-copy,並在 close/destroy 時 disable。
`gvfg_qt_preview.exe` 只使用 public API,主畫面只顯示 input 與 Preview
狀態;IRQ、DMA、ring slot 等資訊只存在 internal diagnostic tool。