Simplify GVFG API and frame diagnostics

This commit is contained in:
Mark.lin
2026-07-30 16:43:30 +08:00
parent 9124930e98
commit 2b5e75ade9
20 changed files with 245 additions and 257 deletions
+8 -2
View File
@@ -1,4 +1,4 @@
<mxfile host="Electron">
<mxfile host="Electron" modified="2026-07-30T00:00:00.000Z">
<diagram id="gvfg-architecture-overview" name="Architecture Overview">
<mxGraphModel dx="1230" dy="1558" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1280" pageHeight="820" math="0" shadow="0">
<root>
@@ -30,7 +30,7 @@
<mxCell id="backendTypes" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="pcies2mm_backend_types.h&lt;br&gt;internal frame/event/status types" vertex="1">
<mxGeometry height="58" width="285" x="30" y="95" as="geometry" />
</mxCell>
<mxCell id="workers" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="single driver event + DMA worker&lt;br&gt;publish frames and events" vertex="1">
<mxCell id="workers" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="single capture thread&lt;br&gt;WaitForMultipleObjects: DMA / format / plug events" vertex="1">
<mxGeometry height="52" width="280" x="510" y="173" as="geometry" />
</mxCell>
<mxCell id="pcies2mmSession" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.cpp&lt;br&gt;internal session / workers / frame ring" vertex="1">
@@ -56,6 +56,9 @@
<mxCell id="ring" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="frame_ring_&lt;br&gt;ready / in_use / sequence" vertex="1">
<mxGeometry height="58" width="270" x="880" y="610" as="geometry" />
</mxCell>
<mxCell id="eventFlow" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=13;" value="Public event flow&lt;br&gt;driver format IRQ -&gt; FORMAT_CHANGE_BEGIN&lt;br&gt;first new frame published -&gt; STREAM_READY" vertex="1">
<mxGeometry height="82" width="330" x="850" y="690" as="geometry" />
</mxCell>
<mxCell id="externalBoundary" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#f5f5f5;strokeColor=#666666;dashed=1;fontColor=#333333;fontSize=14;" value="External frame/event source" vertex="1">
<mxGeometry height="52" width="280" x="410" y="900" as="geometry" />
</mxCell>
@@ -74,6 +77,9 @@
<mxCell id="e8" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="ring" value="">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e11" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="eventFlow" value="callback / queue">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="e9" edge="1" parent="1" source="pcies2mmSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="facade" value="frames / events / status">
<mxGeometry relative="1" as="geometry">
<Array as="points">
+8 -21
View File
@@ -108,12 +108,10 @@ Customer-readable input signal status:
新 driver 未提供 frame-rate、SDI/HDMI lock、DDR status 或舊 FPGA validity
register,因此 SDK 不再合成或公開這些欄位。
這是可擴充的 query output,呼叫前必須設定 `struct_size`。沒有 input signal 是正常
狀態:API 回傳 `GVFG_OK`,同時 `connected == 0`。
沒有 input signal 是正常狀態:API 回傳 `GVFG_OK`,同時 `connected == 0`。
```c
gvfg_signal_status_t signal = {};
signal.struct_size = sizeof(signal);
gvfg_get_signal_status(h, &signal);
```
@@ -145,7 +143,6 @@ Memory layout、color metadata 與 timestamp metadata 不會繼續塞進這個 s
```c
typedef struct
{
uint32_t struct_size;
int plane_count;
const void *plane_data[GVFG_MAX_PLANES];
int plane_stride[GVFG_MAX_PLANES];
@@ -161,7 +158,7 @@ typedef struct
- `gvfg_handle` 永遠保持 opaque。
- `gvfg_frame_t` 保持極小,stable release 後凍結。
- 真正可擴充的 query output 使用 `struct_size`。
- 第一版 API 不做跨版本 struct 相容;DLL、header 與 application 必須整套更新。
- Layout 使用 `gvfg_get_frame_layout()`。
- 未來 color metadata 使用獨立的 `gvfg_get_frame_color_info()`。
- 未來 timestamp metadata 使用獨立的 `gvfg_get_frame_timestamp_info()`。
@@ -184,15 +181,11 @@ typedef struct gvfg_convert_frame_t *gvfg_convert_frame;
typedef struct
{
uint32_t struct_size;
int width;
int height;
int pixel_format;
int row_bytes;
uint32_t flags;
uint32_t reserved0;
uint64_t data_size;
uint64_t reserved[8];
} gvfg_convert_frame_desc_t;
```
@@ -217,9 +210,9 @@ captured source frame 自動決定大小。
Conversion 使用 BT.709 limited-range YUV to RGB,和 preview path 對齊。其他
source 或 destination format 會回傳 `GVFG_ENOTSUP`。
### `gvfg_event_t`
### `gvfg_event_type_t`
`gvfg_poll_event()` 回傳的 capture event。
`gvfg_poll_event()` 直接回傳 capture event 類型。
Customer event 保持 driver-neutral:
@@ -302,11 +295,8 @@ gvfg_status_t gvfg_get_frame_layout(const gvfg_frame_t *frame,
回傳 `gvfg_read_frame()` 取得 frame 的 per-plane layout。
呼叫前先初始化 `out_layout->struct_size`:
```c
gvfg_frame_layout_t layout = {};
layout.struct_size = sizeof(layout);
gvfg_get_frame_layout(&frame, &layout);
```
@@ -343,7 +333,6 @@ Snapshot buffer flow 範例:
gvfg_frame_t frame = {};
if (gvfg_read_frame(h, &frame, 1000) == GVFG_OK) {
gvfg_convert_frame_desc_t desc = {};
desc.struct_size = sizeof(desc);
desc.pixel_format = GVFG_CONVERT_FMT_RGB48;
gvfg_convert_frame image = NULL;
@@ -388,7 +377,7 @@ Release `gvfg_read_frame()` 回傳的 frame。
```c
gvfg_status_t gvfg_poll_event(gvfg_handle handle,
gvfg_event_t *out_event,
gvfg_event_type_t *out_event,
uint32_t timeout_ms);
```
@@ -408,7 +397,6 @@ gvfg_status_t gvfg_get_signal_status(gvfg_handle handle,
```c
gvfg_signal_status_t status = {};
status.struct_size = sizeof(status);
gvfg_get_signal_status(h, &status);
```
@@ -421,13 +409,12 @@ gvfg_status_t gvfg_get_runtime_info(gvfg_handle handle,
gvfg_runtime_info_t *out_info);
```
查詢 last read frame format、FPS、delivered frame count。Input signal metadata 請另外
呼叫 `gvfg_get_signal_status()`;不要把可擴充的 signal struct 內嵌進 runtime struct,
避免未來欄位位移破壞 ABI。
查詢 FPS 與 delivered frame count。Input signal metadata 請另外呼叫
`gvfg_get_signal_status()`;每張實際交付的 frame metadata 由 `gvfg_frame_t`
提供。Last-delivered frame metadata 僅保留於 internal debug API。
```c
gvfg_runtime_info_t info = {};
info.struct_size = sizeof(info);
gvfg_get_runtime_info(h, &info);
```
+14 -14
View File
@@ -1,42 +1,42 @@
<mxfile host="app.diagrams.net" modified="2026-06-10T00:00:00.000Z" agent="Codex" version="24.7.17" type="device">
<mxfile host="app.diagrams.net" modified="2026-07-30T00:00:00.000Z" agent="Codex" version="24.7.17" type="device">
<diagram id="gvfg-dma-ring-flow" name="GVFG DMA Ring Data Flow">
<mxGraphModel dx="1600" dy="1000" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="title" value="GVFG user-space DMA ring data flow" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=28;fontStyle=1" vertex="1" parent="1">
<mxCell id="title" value="GVFG driver DMA buffer to SDK ring data flow" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=28;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="360" y="30" width="880" height="40" as="geometry"/>
</mxCell>
<mxCell id="hw" value="FPGA / PCIES2MM hardware&#xa;VIDEO IRQ" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxCell id="hw" value="Video source / FPGA&#xa;writes DMA buffer N&#xa;DMA complete interrupt" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="80" y="130" width="210" height="80" as="geometry"/>
</mxCell>
<mxCell id="event" value="event_thread_proc()&#xa;ReadFile(event_N) returns" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxCell id="event" value="Kernel driver&#xa;SetEvent(dma_event_)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="360" y="130" width="230" height="80" as="geometry"/>
</mxCell>
<mxCell id="pending" value="pending_events_++&#xa;data_cv_.notify_one()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14" vertex="1" parent="1">
<mxCell id="pending" value="single capture_thread_proc()&#xa;WaitForMultipleObjects() wakes&#xa;dispatches DMA event" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14" vertex="1" parent="1">
<mxGeometry x="660" y="130" width="230" height="80" as="geometry"/>
</mxCell>
<mxCell id="datawait" value="data_thread_proc()&#xa;waits for pending_events_ &gt; 0" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxCell id="datawait" value="handle_dma_event()&#xa;IOCTL_GET_VIDEO_DONE_INDEX" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="960" y="130" width="260" height="80" as="geometry"/>
</mxCell>
<mxCell id="clear" value="Clear VIDEO IRQ&#xa;write INT_CLR high/low&#xa;enable_user_event()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
<mxCell id="clear" value="frameIndex = doneIndex % 16&#xa;select completed driver DMA buffer N" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
<mxGeometry x="1280" y="130" width="240" height="90" as="geometry"/>
</mxCell>
<mxCell id="findslot" value="Find free FrameSlot&#xa;slot.in_use == false" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxCell id="findslot" value="SDK 3-slot frame_ring_&#xa;search slot.in_use == false" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="80" y="310" width="240" height="80" as="geometry"/>
</mxCell>
<mxCell id="droptest" value="Slot already ready?&#xa;ready == true and newer than delivered" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=13" vertex="1" parent="1">
<mxCell id="droptest" value="Free slot available?" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=13" vertex="1" parent="1">
<mxGeometry x="390" y="300" width="190" height="100" as="geometry"/>
</mxCell>
<mxCell id="drop" value="Drop old ready frame&#xa;stats_.frames_dropped++" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=14" vertex="1" parent="1">
<mxCell id="drop" value="No: capture thread waits&#xa;data_cv_.wait_for()&#xa;driver buffers may advance" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=14" vertex="1" parent="1">
<mxGeometry x="650" y="290" width="230" height="70" as="geometry"/>
</mxCell>
<mxCell id="markwriting" value="Mark slot writing&#xa;ready = false&#xa;in_use = true" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
<mxGeometry x="650" y="390" width="230" height="90" as="geometry"/>
</mxCell>
<mxCell id="readc2h" value="ReadFile(c2h_N)&#xa;directly into slot.data" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxCell id="readc2h" value="IOCTL_GET_FRAME&#xa;driver DMA buffer N -&gt; one copy -&gt; slot.data&#xa;validate bytesReturned == expected" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="960" y="330" width="260" height="80" as="geometry"/>
</mxCell>
<mxCell id="publish" value="publish_frame(slotIndex, bytes)&#xa;slot.ready = true&#xa;slot.in_use = false&#xa;frame_cv_.notify_one()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
@@ -84,9 +84,9 @@
<mxCell id="e4" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="datawait" target="clear"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e5" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="clear" target="findslot"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="1400" y="260"/><mxPoint x="200" y="260"/></Array></mxGeometry></mxCell>
<mxCell id="e6" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="findslot" target="droptest"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e7" value="yes" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="droptest" target="drop"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e8" value="no / after drop" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="droptest" target="markwriting"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="drop" target="markwriting"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e7" value="yes" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="droptest" target="markwriting"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e8" value="no" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="droptest" target="drop"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e9" value="release wakes waiter" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1" edge="1" parent="1" source="drop" target="findslot"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e10" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="markwriting" target="readc2h"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="readc2h" target="publish"><mxGeometry relative="1" as="geometry"/></mxCell>
<mxCell id="e12" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="publish" target="wait"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="1410" y="500"/><mxPoint x="220" y="500"/></Array></mxGeometry></mxCell>
+97 -6
View File
@@ -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`。