Simplify GVFG API and frame diagnostics
This commit is contained in:
@@ -84,7 +84,7 @@ flowchart TD
|
||||
subgraph Backend["Internal Backend"]
|
||||
PcieS2mm["sdk/gvfg/src/backend/pcies2mm"]
|
||||
Ring["frame_ring_"]
|
||||
Workers["single driver event + DMA worker"]
|
||||
Workers["single capture thread: DMA / format / plug events"]
|
||||
end
|
||||
|
||||
CustomerApp --> CaptureApi
|
||||
@@ -125,14 +125,77 @@ Pull mode 下,`gvfg.dll` 不擁有 application 的 public read thread。UI app
|
||||
自己建立 worker thread,並在那個 thread 呼叫 `gvfg_read_frame()`。
|
||||
|
||||
`gvfg_start()` 在尚未確認 input signal 時仍會註冊 driver events 並啟動單一 backend
|
||||
wait thread。`gvfg_read_frame()` 此時 timeout;收到 signal-connected event 後,backend
|
||||
在相同 thread 重讀 width/height/payload format、resize ring,然後 enable DMA 並送出
|
||||
capture-resumed event。
|
||||
capture thread。`gvfg_read_frame()` 此時 timeout;收到 signal-connected event 後,
|
||||
backend 在相同 thread 重讀 width/height/payload format、resize ring,然後 enable DMA。
|
||||
第一張完整 frame publish 後,public event queue 收到 `GVFG_EVENT_STREAM_READY`。
|
||||
|
||||
FPGA H/V/format registers 可能在拔除來源後保留 last-known values,因此它們只能用來
|
||||
準備 DMA probe layout,不能當作 signal-present 判斷。啟動時 backend 可以在內部 enable
|
||||
probe DMA,以涵蓋來源早於 event registration 就已接上的情況;只有收到 driver plug-in
|
||||
event 或成功取得第一張完整 frame 後,public signal status 才能回報 connected。
|
||||
event 或成功取得第一張完整 frame 後,public signal status 才能回報 connected。DMA
|
||||
probe 成功不偽造 plug-in event,而是送出 `GVFG_EVENT_STREAM_READY`。
|
||||
|
||||
## Internal DMA / Ring Data Flow
|
||||
|
||||
Driver DMA buffer 與 SDK `frame_ring_` 是兩層不同的 storage。Driver buffer 負責接收
|
||||
硬體 DMA;SDK ring 保存一份 user-mode copy,讓 application 能持有 frame 到
|
||||
`gvfg_release_frame()`。三個 SDK ring slots 只增加緩衝空間,每一張 frame 仍只有一次
|
||||
driver-to-SDK copy。
|
||||
|
||||
目前完整路徑:
|
||||
|
||||
```text
|
||||
video source produces one frame
|
||||
-> hardware writes driver DMA buffer N
|
||||
-> DMA complete interrupt
|
||||
-> driver SetEvent(dma_event_)
|
||||
-> capture_thread_proc() wakes from WaitForMultipleObjects()
|
||||
-> handle_dma_event()
|
||||
-> IOCTL_GET_VIDEO_DONE_INDEX
|
||||
-> frameIndex = doneIndex % kDmaBufferCount (currently 16)
|
||||
-> search the 3-slot SDK frame_ring_ for slot.in_use == false
|
||||
-> mark slot: ready=false, in_use=true
|
||||
-> IOCTL_GET_FRAME
|
||||
-> one copy: driver DMA buffer N -> slot.data
|
||||
-> validate bytesReturned == expected frame size
|
||||
-> publish_frame()
|
||||
- sequence = ++latest_sequence_
|
||||
- ready = true
|
||||
- in_use = false
|
||||
- frame_cv_.notify_one()
|
||||
-> gvfg_read_frame() / wait_frame() wakes
|
||||
-> select the newest ready sequence
|
||||
-> mark delivered slot: ready=false, in_use=true
|
||||
-> return gvfg_frame_t pointing at slot.data
|
||||
-> preview / conversion / customer processing
|
||||
-> gvfg_release_frame()
|
||||
-> mark slot.in_use=false
|
||||
-> data_cv_.notify_all()
|
||||
-> slot becomes reusable
|
||||
```
|
||||
|
||||
FrameSlot 的主要狀態:
|
||||
|
||||
```text
|
||||
Free : ready=false, in_use=false
|
||||
Writing : ready=false, in_use=true
|
||||
Ready : ready=true, in_use=false
|
||||
Delivered : ready=false, in_use=true
|
||||
Released : ready=false, in_use=false
|
||||
```
|
||||
|
||||
同步責任:
|
||||
|
||||
- `mutex_` 保護 `frame_ring_`、slot flags、sequence 與 active delivery slot。
|
||||
- `frame_cv_` 喚醒等待 ready frame 的 `wait_frame()`。
|
||||
- `data_cv_` 喚醒等待 free slot 的 capture thread。
|
||||
- `eventMutex`、`eventCv` 與 `eventQueue` 是 public capture event 的另一套同步機制,
|
||||
不保存 frame。
|
||||
|
||||
如果三個 SDK slots 全部 `in_use`,capture thread 目前會在 `data_cv_` 等待,不會主動
|
||||
從 SDK ring 丟掉 application 正在持有的 frame。硬體與 driver DMA 仍可能繼續前進,
|
||||
因此等待期間的中間 frame 可能在 driver 層被覆寫或 event 被合併,形成隱性掉幀。
|
||||
這是 backpressure policy,不是 lossless queue 保證。
|
||||
|
||||
## Frame 所有權
|
||||
|
||||
@@ -144,7 +207,7 @@ event 或成功取得第一張完整 frame 後,public signal status 才能回
|
||||
- `gvfg_get_frame_layout()` 回傳 SDK-filled layout metadata:`plane_data`、
|
||||
`plane_stride`、`plane_size`。目前 PCIES2MM backend 使用
|
||||
width/height/format 推導 tightly packed layout。
|
||||
- 未來 color/timestamp metadata 應新增各自帶 `struct_size` 的 query output,例如
|
||||
- 未來 color/timestamp metadata 應新增獨立的 query output,例如
|
||||
`gvfg_get_frame_color_info()` 與 `gvfg_get_frame_timestamp_info()`。不要預先在每個
|
||||
struct 放大型 reserved array;等 metadata 類型真的很多再考慮 side data。
|
||||
- `gvfg_preview.dll` 應優先吃 `gvfg_get_frame_layout()`;layout query 不可用時才
|
||||
@@ -174,8 +237,36 @@ Customer event 保持 driver-neutral:
|
||||
```text
|
||||
GVFG_EVENT_SIGNAL_CONNECTED
|
||||
GVFG_EVENT_SIGNAL_DISCONNECTED
|
||||
GVFG_EVENT_STREAM_READY
|
||||
GVFG_EVENT_FORMAT_CHANGE_BEGIN
|
||||
```
|
||||
|
||||
事件語意:
|
||||
|
||||
- `GVFG_EVENT_SIGNAL_CONNECTED`:backend 收到真正的 driver plug-in event。
|
||||
- `GVFG_EVENT_SIGNAL_DISCONNECTED`:backend 收到真正的 driver plug-out event。
|
||||
- `GVFG_EVENT_FORMAT_CHANGE_BEGIN`:收到 driver format-change event,舊格式資源即將
|
||||
失效;backend 自動停止舊 DMA、重讀格式並恢復 capture。
|
||||
- `GVFG_EVENT_STREAM_READY`:start、plug-in recovery 或 format recovery 後,第一張
|
||||
完整 frame 已經 publish。Application 可讀取新 `gvfg_frame_t`,依其中的
|
||||
width/height/pixel_format/bit_depth 重建 render resources。
|
||||
|
||||
Format change 是兩階段通知:
|
||||
|
||||
```text
|
||||
driver format-change event
|
||||
-> GVFG_EVENT_FORMAT_CHANGE_BEGIN
|
||||
-> backend disables old DMA/video
|
||||
-> backend refreshes width/height/payload format and resizes ring
|
||||
-> backend enables capture
|
||||
-> first complete new-format frame is published
|
||||
-> GVFG_EVENT_STREAM_READY
|
||||
```
|
||||
|
||||
Application 可在 `FORMAT_CHANGE_BEGIN` 暫停 render 或清理舊格式資源,但不應自行對同一
|
||||
session 執行 Stop/Start;backend 負責恢復。在 `STREAM_READY` 後,以新 frame metadata
|
||||
重建並恢復 render。
|
||||
|
||||
Video IRQ handling 是 `sdk/gvfg/src/backend/pcies2mm` 內部細節。IRQ bit numbers、
|
||||
IRQ masks 與 DMA counters 不應出現在
|
||||
`gvfg_capture.h`。
|
||||
|
||||
Reference in New Issue
Block a user