Split GVFG customer API and preview helper
Refactor GVFG into a pull-based customer API with internal debug diagnostics in gvfg_debug.h. Move preview rendering into the separate gvfg_preview helper DLL and update the Qt sample to link it explicitly. Clean legacy callback/preview docs and removed SDK-internal render/log helper sources from the core GVFG DLL.
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
<mxCell id="apiLayer" parent="1" style="swimlane;html=1;startSize=34;horizontal=1;fillColor=#d5e8d4;strokeColor=#82b366;fontStyle=1;align=left;" value="2. Public API / gvfg.dll" vertex="1">
|
||||
<mxGeometry height="230" width="1180" x="50" y="230" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="render" parent="apiLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="sdk/gvfg/src/render/shared_scene_pipeline.cpp<br>SDK-managed D3D preview" vertex="1">
|
||||
<mxGeometry height="58" width="310" x="850" y="151" as="geometry" />
|
||||
<mxCell id="render" parent="appLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=14;" value="helpers/gvfg_preview<br>optional gvfg_preview.dll" vertex="1">
|
||||
<mxGeometry height="58" width="330" x="820" y="45" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="publicHeader" parent="apiLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="sdk/gvfg/include/gvfg_capture.h<br>customer-facing C API" vertex="1">
|
||||
<mxGeometry height="58" width="280" x="450" y="50" as="geometry" />
|
||||
@@ -50,7 +50,7 @@
|
||||
<mxCell id="customerApp" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=14;" value="Customer application" vertex="1">
|
||||
<mxGeometry height="52" width="230" x="715" y="85" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="facade" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="sdk/gvfg/src/gvfg_capture.cpp<br>session facade / lifecycle / callbacks" vertex="1">
|
||||
<mxCell id="facade" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="sdk/gvfg/src/gvfg_capture.cpp<br>session facade / lifecycle / pull API" vertex="1">
|
||||
<mxGeometry height="58" width="340" x="470" y="385" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="ring" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="frame_ring_<br>ready / in_use / sequence" vertex="1">
|
||||
@@ -65,7 +65,7 @@
|
||||
<mxCell id="e3" edge="1" parent="1" source="publicHeader" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="facade" value="exports">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="e4" edge="1" parent="1" source="facade" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="render" value="preview path">
|
||||
<mxCell id="e4" edge="1" parent="1" source="qtSample" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="render" value="private preview">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="e5" edge="1" parent="1" source="facade" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="xdmaSession" value="backend API calls">
|
||||
|
||||
+17
-34
@@ -25,8 +25,8 @@ gvfg_enumerate_devices
|
||||
|
||||
## Threading
|
||||
|
||||
The frame API is pull-based. The SDK does not start a customer callback thread
|
||||
or preview thread from the public API layer.
|
||||
The frame API is pull-based. The SDK does not start a customer frame thread or
|
||||
preview thread from the public API layer.
|
||||
|
||||
Applications decide where to call `gvfg_read_frame()`:
|
||||
|
||||
@@ -90,14 +90,14 @@ Device entry returned by `gvfg_enumerate_devices()`.
|
||||
Customer-readable input signal status:
|
||||
|
||||
- width / height
|
||||
- video format code and text
|
||||
- frame-rate code and text
|
||||
- video format text
|
||||
- frame-rate text
|
||||
- bit depth
|
||||
- SDI / HDMI lock status
|
||||
- raw FPGA values for diagnostics
|
||||
|
||||
The raw values are exposed only as signal diagnostics. Register access remains
|
||||
outside the customer API.
|
||||
Raw FPGA values, register-like values, and validity masks are internal debug
|
||||
data and are available only through `gvfg_debug.h` in the internal debug
|
||||
package.
|
||||
|
||||
### `gvfg_frame_t`
|
||||
|
||||
@@ -126,7 +126,9 @@ Customer events are driver-neutral:
|
||||
- `GVFG_EVENT_PLUG_OUT`
|
||||
- `GVFG_EVENT_CAPTURE_PAUSED`
|
||||
- `GVFG_EVENT_CAPTURE_RESUMED`
|
||||
- `GVFG_EVENT_VIDEO_IRQ` for debug or explicit event monitoring
|
||||
|
||||
Frame interrupts, IRQ bit numbers, and IRQ masks are internal details and are
|
||||
not exposed through `gvfg_capture.h`.
|
||||
|
||||
## Main APIs
|
||||
|
||||
@@ -220,38 +222,19 @@ gvfg_status_t gvfg_get_runtime_info(gvfg_handle handle,
|
||||
Queries current signal status, last read frame format, FPS, and delivered frame
|
||||
count.
|
||||
|
||||
### Legacy Callback APIs
|
||||
|
||||
```c
|
||||
gvfg_status_t gvfg_set_callbacks(gvfg_handle handle,
|
||||
gvfg_on_frame_cb on_frame,
|
||||
gvfg_on_error_cb on_error,
|
||||
void *user);
|
||||
|
||||
gvfg_status_t gvfg_set_event_callback(gvfg_handle handle,
|
||||
gvfg_on_event_cb on_event,
|
||||
void *user,
|
||||
uint32_t event_mask);
|
||||
```
|
||||
|
||||
These remain for source compatibility during transition. New customer code
|
||||
should use `gvfg_read_frame()`, `gvfg_release_frame()`, and
|
||||
`gvfg_poll_event()`.
|
||||
|
||||
## Preview Boundary
|
||||
|
||||
Preview is not part of the customer SDK API.
|
||||
Preview is not part of the core capture SDK API.
|
||||
|
||||
Internal tools such as `samples/gvfg_qt_preview` may render frames by using
|
||||
app-owned code:
|
||||
Applications have two choices after `gvfg_read_frame()` returns a frame:
|
||||
|
||||
```text
|
||||
gvfg_read_frame
|
||||
-> app/private preview renderer
|
||||
-> snapshot or recording if needed
|
||||
-> customer-owned display / processing / recording / snapshot
|
||||
-> optional gvfg_preview_render_frame from gvfg_preview.dll
|
||||
-> gvfg_release_frame
|
||||
```
|
||||
|
||||
Customer demo source should only rely on `gvfg_capture.h`. Internal preview
|
||||
renderer source or binaries can be packaged separately for internal debug or
|
||||
full application builds.
|
||||
Customer demo source may include `gvfg_preview.h` and link `gvfg_preview.dll`
|
||||
when it needs a simple display path. The preview helper source remains private;
|
||||
customer code only sees the helper API and binary.
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
# GVFG Direct SDK Plan
|
||||
|
||||
## Current Direction
|
||||
|
||||
GVFG Direct 目前改成使用獨立的 GVFG SDK:
|
||||
|
||||
- 對外 facade:`sdk/gvfg`
|
||||
- 低階 driver access:`sdk/gvfg/src/backend/xdma`
|
||||
- Viewer 整合:`apps/qt6_viewer` 的 `GVFG Direct`
|
||||
|
||||
GVFG 是客戶看到的 SDK/API 名稱。XDMA 只保留為底層 driver/backend 說明。
|
||||
|
||||
## Build Options
|
||||
|
||||
```text
|
||||
BUILD_GVFG_SDK=ON
|
||||
BUILD_GVFG_SAMPLES=ON
|
||||
GVFG_XDMA_DEBUG_LOG=ON
|
||||
```
|
||||
|
||||
`BUILD_GVFG_SDK` 會 build `gvfg.dll`,並把 `gvfg.dll` 複製到 viewer 輸出資料夾。XDMA backend 會編進 `gvfg.dll`,不再另外產生 backend DLL。
|
||||
|
||||
`GVFG_XDMA_DEBUG_LOG` 會開啟底層 XDMA flow log。
|
||||
|
||||
## Active Components
|
||||
|
||||
- `sdk/gvfg`: customer-facing GVFG capture SDK。
|
||||
- `sdk/gvfg/src/backend/xdma`: internal low-level XDMA driver access。
|
||||
- `apps/qt6_viewer`: viewer demo,`GVFG Direct` 透過 GVFG SDK 啟動。
|
||||
- `samples/gvfg_qt_preview`: 最小客戶 sample。
|
||||
|
||||
## Customer API
|
||||
|
||||
請看:
|
||||
|
||||
```text
|
||||
docs/GVFG_CUSTOMER_API.md
|
||||
```
|
||||
|
||||
## Removed Components
|
||||
|
||||
- old standalone XDMA probe app
|
||||
- KS capture session implementation
|
||||
- KS device enumerator implementation
|
||||
@@ -49,10 +49,10 @@
|
||||
<mxCell id="select" value="wait_frame() selects newest ready slot
slot.ready = false
slot.in_use = true
out.data = slot.data.data()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
||||
<mxGeometry x="430" y="540" width="310" height="120" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="render" value="app/private preview renderer
uses frame before release" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
||||
<mxCell id="render" value="optional gvfg_preview.dll
uses frame before release" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
||||
<mxGeometry x="820" y="540" width="270" height="90" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="callback" value="app uses frame
data valid until gvfg_release_frame()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
||||
<mxCell id="appUse" value="app uses frame
data valid until gvfg_release_frame()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
||||
<mxGeometry x="1160" y="540" width="300" height="90" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="release" value="release_frame(frame)
slot.in_use = false
data_cv_.notify_all()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
||||
@@ -92,8 +92,8 @@
|
||||
<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>
|
||||
<mxCell id="e13" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="wait" target="select"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||
<mxCell id="e14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="select" target="render"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||
<mxCell id="e15" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="render" target="callback"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||
<mxCell id="e16" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="callback" target="release"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="1310" y="700"/><mxPoint x="780" y="700"/></Array></mxGeometry></mxCell>
|
||||
<mxCell id="e15" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="render" target="appUse"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||
<mxCell id="e16" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="appUse" target="release"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="1310" y="700"/><mxPoint x="780" y="700"/></Array></mxGeometry></mxCell>
|
||||
<mxCell id="e17" value="slot reusable" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1" edge="1" parent="1" source="release" target="findslot"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="780" y="850"/><mxPoint x="40" y="850"/><mxPoint x="40" y="350"/></Array></mxGeometry></mxCell>
|
||||
|
||||
<mxCell id="se1" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block" edge="1" parent="1" source="sfree" target="swriting"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
# GVFG Internal Notes
|
||||
|
||||
This document is the internal engineering map for the standalone GVFG SDK.
|
||||
Customer-facing API details live in `docs/GVFG_CUSTOMER_API.md`.
|
||||
|
||||
## Current Direction
|
||||
|
||||
GVFG is split into three clear pieces:
|
||||
|
||||
```text
|
||||
sdk/gvfg/
|
||||
gvfg.dll
|
||||
capture API, handle lifecycle, pull frame/event bridge, internal debug API
|
||||
|
||||
helpers/gvfg_preview/
|
||||
gvfg_preview.dll
|
||||
optional display helper; renders gvfg_frame_t after gvfg_read_frame()
|
||||
|
||||
samples/gvfg_qt_preview/
|
||||
internal debug Qt tool
|
||||
uses gvfg.dll + gvfg_preview.dll + gvfg_debug.h
|
||||
```
|
||||
|
||||
The core SDK must stay driver-neutral from the customer's point of view.
|
||||
XDMA, IRQ, DMA counters, raw FPGA values, and backend details are internal.
|
||||
|
||||
## Architecture
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
subgraph App["Application / Sample"]
|
||||
QtApp["samples/gvfg_qt_preview"]
|
||||
CustomerApp["Customer application"]
|
||||
end
|
||||
|
||||
subgraph Preview["Optional Preview Helper: gvfg_preview.dll"]
|
||||
PreviewApi["helpers/gvfg_preview/include/gvfg_preview.h"]
|
||||
PreviewPipe["private D3D preview pipeline"]
|
||||
end
|
||||
|
||||
subgraph SDK["Core SDK: gvfg.dll"]
|
||||
CaptureApi["sdk/gvfg/include/gvfg_capture.h"]
|
||||
DebugApi["sdk/gvfg/include/gvfg_debug.h\ninternal only"]
|
||||
Facade["sdk/gvfg/src/gvfg_capture.cpp"]
|
||||
end
|
||||
|
||||
subgraph Backend["Internal Backend"]
|
||||
Xdma["sdk/gvfg/src/backend/xdma"]
|
||||
Ring["frame_ring_"]
|
||||
Workers["event worker + data worker"]
|
||||
end
|
||||
|
||||
CustomerApp --> CaptureApi
|
||||
CustomerApp -. optional display .-> PreviewApi
|
||||
QtApp --> CaptureApi
|
||||
QtApp --> DebugApi
|
||||
QtApp --> PreviewApi
|
||||
PreviewApi --> PreviewPipe
|
||||
CaptureApi --> Facade
|
||||
DebugApi --> Facade
|
||||
Facade --> Xdma
|
||||
Xdma --> Workers
|
||||
Workers --> Ring
|
||||
```
|
||||
|
||||
## Capture Flow
|
||||
|
||||
The capture API follows an FFmpeg-style pull model:
|
||||
|
||||
```text
|
||||
gvfg_enumerate_devices
|
||||
-> gvfg_create
|
||||
-> gvfg_open
|
||||
-> gvfg_start
|
||||
-> loop:
|
||||
gvfg_read_frame
|
||||
customer processing and/or gvfg_preview_render_frame
|
||||
gvfg_release_frame
|
||||
gvfg_poll_event optional
|
||||
-> gvfg_stop
|
||||
-> gvfg_destroy
|
||||
```
|
||||
|
||||
`gvfg.dll` does not own the application's public read thread. UI apps should
|
||||
create their own worker thread and call `gvfg_read_frame()` there.
|
||||
|
||||
## Frame Ownership
|
||||
|
||||
- `gvfg_read_frame()` returns one SDK-owned frame buffer.
|
||||
- `frame.data` remains valid until `gvfg_release_frame()` is called.
|
||||
- A handle may hold only one frame at a time.
|
||||
- If the application needs data after release, it must copy the frame.
|
||||
- `gvfg_preview_render_frame()` is synchronous and should be called before
|
||||
`gvfg_release_frame()`.
|
||||
|
||||
Typical two-way use:
|
||||
|
||||
```text
|
||||
gvfg_read_frame
|
||||
-> customer-owned display / AI / recording / snapshot
|
||||
-> optional gvfg_preview_render_frame
|
||||
-> gvfg_release_frame
|
||||
```
|
||||
|
||||
## Event Boundary
|
||||
|
||||
Customer events stay driver-neutral:
|
||||
|
||||
```text
|
||||
GVFG_EVENT_PLUG_IN
|
||||
GVFG_EVENT_PLUG_OUT
|
||||
GVFG_EVENT_CAPTURE_PAUSED
|
||||
GVFG_EVENT_CAPTURE_RESUMED
|
||||
```
|
||||
|
||||
Video IRQ handling is internal to `sdk/gvfg/src/backend/xdma`. IRQ bit numbers,
|
||||
IRQ masks, DMA counters, and raw FPGA register-like values should not appear in
|
||||
`gvfg_capture.h`.
|
||||
|
||||
## API Surfaces
|
||||
|
||||
Customer/demo visible:
|
||||
|
||||
```text
|
||||
include/gvfg_capture.h
|
||||
include/gvfg_preview.h when display helper is used
|
||||
```
|
||||
|
||||
Internal debug only:
|
||||
|
||||
```text
|
||||
include/gvfg_debug.h
|
||||
backend counters
|
||||
interrupt count
|
||||
DMA errors
|
||||
raw FPGA signal values
|
||||
latest backend error detail
|
||||
PDB symbols
|
||||
internal diagnostic tools
|
||||
```
|
||||
|
||||
## Package Split
|
||||
|
||||
### Demo / Customer Package
|
||||
|
||||
Include:
|
||||
|
||||
```text
|
||||
include/gvfg_capture.h
|
||||
include/gvfg_preview.h when the demo shows video
|
||||
lib/gvfg.lib
|
||||
lib/gvfg_preview.lib when the demo shows video
|
||||
bin/gvfg.dll
|
||||
bin/gvfg_preview.dll when the demo shows video
|
||||
samples/customer-facing source
|
||||
docs/GVFG_CUSTOMER_API.md
|
||||
```
|
||||
|
||||
Do not include:
|
||||
|
||||
```text
|
||||
include/gvfg_debug.h
|
||||
SDK source
|
||||
preview helper source
|
||||
XDMA backend headers
|
||||
PDB symbols
|
||||
register / DMA / IRQ debug docs
|
||||
internal diagnostic tools
|
||||
```
|
||||
|
||||
### Internal Debug Package
|
||||
|
||||
Include:
|
||||
|
||||
```text
|
||||
include/gvfg_capture.h
|
||||
include/gvfg_debug.h
|
||||
include/gvfg_preview.h
|
||||
lib/gvfg.lib
|
||||
lib/gvfg_preview.lib
|
||||
bin/gvfg.dll
|
||||
bin/gvfg_preview.dll
|
||||
bin/gvfg_qt_preview.exe
|
||||
PDB symbols
|
||||
internal debug notes
|
||||
```
|
||||
|
||||
### Full Release Package
|
||||
|
||||
The full application release can use `gvfg.dll` and `gvfg_preview.dll`, plus
|
||||
licensing and closed-source application integration. Do not use the full release
|
||||
package as the daily driver/FPGA bring-up vehicle.
|
||||
|
||||
## Build
|
||||
|
||||
Top-level CMake builds the core SDK, preview helper, and optional sample:
|
||||
|
||||
```text
|
||||
BUILD_GVFG_SAMPLES=ON
|
||||
GVFG_XDMA_DEBUG_LOG=OFF
|
||||
```
|
||||
|
||||
Outputs:
|
||||
|
||||
```text
|
||||
bin/gvfg.dll
|
||||
bin/gvfg_preview.dll
|
||||
lib/gvfg.lib
|
||||
lib/gvfg_preview.lib
|
||||
bin/gvfg_qt_preview.exe
|
||||
```
|
||||
|
||||
`GVFG_XDMA_DEBUG_LOG=ON` enables verbose XDMA flow logging in the internal
|
||||
backend.
|
||||
|
||||
## Draw.io Files
|
||||
|
||||
Keep draw.io files for visual discussions:
|
||||
|
||||
```text
|
||||
docs/GVFG_ARCHITECTURE_OVERVIEW.drawio
|
||||
docs/GVFG_DMA_RING_DATA_FLOW.drawio
|
||||
```
|
||||
|
||||
When code changes only affect API order, package boundaries, or module
|
||||
ownership, update this Markdown file. Update draw.io only when the deeper data
|
||||
flow or frame ownership diagram changes.
|
||||
@@ -1,166 +0,0 @@
|
||||
# GVFG Project Map
|
||||
|
||||
這份文件的目標是幫人快速釐清 GVFG Standalone SDK 的專案分層。依目前工作範圍,圖的邊界停在 SDK 內部 backend;更底層的外部輸入來源先不展開。
|
||||
|
||||
建議不要只畫一張巨大流程圖,因為這個專案同時有「使用者 API」、「SDK 內部 worker」、「preview render」和「frame/event 轉交」幾條不同的線。最清楚的方式是分成 3 到 4 張不同視角的圖。
|
||||
|
||||
## 建議圖層
|
||||
|
||||
| 圖 | 回答的問題 | 適合格式 |
|
||||
| --- | --- | --- |
|
||||
| 1. 架構分層圖 | 哪些 code 屬於 App / API / SDK backend? | Mermaid 或 draw.io |
|
||||
| 2. API 生命週期圖 | App 呼叫 API 的正確順序是什麼? | Mermaid flowchart |
|
||||
| 3. SDK Frame 資料流圖 | frame 在 SDK 內部怎麼進 ring、出 callback / preview? | Mermaid 或 draw.io |
|
||||
| 4. Event / hotplug 圖 | backend event 怎麼回到 App? | Mermaid sequence |
|
||||
|
||||
draw.io 適合畫第 3 張的進階版,尤其是 worker thread、ring slot ownership、callback lifetime 這類需要精準框線的圖。其他圖建議放在 Markdown 裡用 Mermaid,這樣改 code 時可以一起 diff 和 review。
|
||||
|
||||
## 1. 架構分層圖
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
subgraph L1["上層 App / Sample"]
|
||||
direction LR
|
||||
QtApp["samples/gvfg_qt_preview\nMainWindow / PreviewWindow"]
|
||||
CustomerApp["Customer application"]
|
||||
end
|
||||
|
||||
subgraph L2["中層 Public API: gvfg.dll"]
|
||||
direction TB
|
||||
Header["sdk/gvfg/include/gvfg_capture.h\ncustomer-facing C API"]
|
||||
Facade["sdk/gvfg/src/gvfg_capture.cpp\nsession facade / lifecycle / callbacks"]
|
||||
Render["sdk/gvfg/src/render/shared_scene_pipeline.cpp\nSDK-managed D3D preview"]
|
||||
end
|
||||
|
||||
subgraph L3["SDK 內部 Backend / Data Flow"]
|
||||
direction TB
|
||||
XdmaSession["sdk/gvfg/src/backend/xdma/xdma_capture_session.cpp\ninternal session / workers / frame ring"]
|
||||
XdmaTypes["xdma_backend_types.h\ninternal frame/event/status types"]
|
||||
Ring["frame_ring_\nready / in_use / sequence"]
|
||||
Workers["event worker + data worker\npublish frames and events"]
|
||||
end
|
||||
|
||||
QtApp --> Header
|
||||
CustomerApp --> Header
|
||||
Header --> Facade
|
||||
Facade --> XdmaSession
|
||||
Facade --> Render
|
||||
XdmaSession --> XdmaTypes
|
||||
XdmaSession --> Workers
|
||||
Workers --> Ring
|
||||
```
|
||||
|
||||
### 三大塊對照
|
||||
|
||||
| 你說的層 | 專案裡的實際位置 | 主要責任 |
|
||||
| --- | --- | --- |
|
||||
| 1. 上層 App | `samples/gvfg_qt_preview` | UI、device selection、start/stop、status 顯示、preview window HWND |
|
||||
| 2. 中層 API | `sdk/gvfg/include`, `sdk/gvfg/src/gvfg_capture.cpp` | 對外 C API、handle 狀態、callback/event 轉接、runtime info、preview pipeline 管理 |
|
||||
| 3. 底層資料流 | `sdk/gvfg/src/backend/xdma` | SDK 內部 worker、frame ring、event/frame 轉交、backend 狀態 |
|
||||
|
||||
`sdk/gvfg/src/render` 是中層 API 內部的 preview 支線,不是客戶 App 的 UI。它吃 backend frame,輸出 D3D swapchain 到 App 傳入的 `HWND`。
|
||||
|
||||
## 2. API 生命週期圖
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A["gvfg_enumerate_devices"] --> B["gvfg_create"]
|
||||
B --> C["gvfg_set_callbacks\noptional frame/error callback"]
|
||||
C --> D["gvfg_set_event_callback\noptional event callback"]
|
||||
D --> E["gvfg_open"]
|
||||
E --> G["gvfg_start"]
|
||||
G --> H["running"]
|
||||
H --> I["gvfg_get_runtime_info\nor gvfg_get_signal_status"]
|
||||
H --> J["gvfg_read_frame\napp-owned loop"]
|
||||
H --> K["gvfg_poll_event\noptional"]
|
||||
I --> H
|
||||
J --> H
|
||||
K --> H
|
||||
H --> M["gvfg_stop"]
|
||||
M --> N["gvfg_destroy"]
|
||||
```
|
||||
|
||||
上層 App 目前的主要路徑在 `samples/gvfg_qt_preview/mainwindow.cpp`:
|
||||
|
||||
1. `refreshDevices()` calls `gvfg_enumerate_devices()`.
|
||||
2. `openDevice()` calls `gvfg_create()`, callback setup, then `gvfg_open()`.
|
||||
3. `startCapture()` calls `gvfg_start()` and starts an app-owned read loop.
|
||||
4. The read loop calls `gvfg_read_frame()`, renders preview with app-private code, then calls `gvfg_release_frame()`.
|
||||
5. A timer calls `gvfg_get_runtime_info()` to refresh signal, read-frame, and FPS status.
|
||||
6. `stopCapture()` calls `gvfg_stop()`, and `closeDevice()` calls `gvfg_destroy()`.
|
||||
|
||||
## 3. SDK Frame 資料流圖
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
Boundary["External frame/event source\nnot detailed here"] --> EventWorker["XdmaCaptureSession event worker"]
|
||||
EventWorker --> DataWorker["XdmaCaptureSession data worker"]
|
||||
DataWorker --> Ring["frame_ring_ slot\nready=true, sequence++"]
|
||||
Ring --> WaitFrame["wait_frame()"]
|
||||
WaitFrame --> ReadFrame["gvfg_read_frame()"]
|
||||
ReadFrame --> App["App-owned read loop\nframe valid until release"]
|
||||
App --> Preview["app-private preview renderer\ninternal/demo tool only"]
|
||||
Preview --> HWND["App-provided HWND"]
|
||||
App --> Release["gvfg_release_frame()\nslot reusable"]
|
||||
Release --> Ring
|
||||
```
|
||||
|
||||
這張圖如果要再細畫,重點應該放在 SDK 內部 ownership:
|
||||
|
||||
1. data worker 什麼時候寫入 `frame_ring_`。
|
||||
2. `wait_frame()` 什麼時候把 slot 交給 `gvfg_capture.cpp`。
|
||||
3. `gvfg_read_frame()` owns the backend frame until the app calls `gvfg_release_frame()`.
|
||||
4. `release_frame()` 後 slot 什麼時候可重用。
|
||||
|
||||
更底層的外部來源細節先不放進這張圖。
|
||||
|
||||
## 4. Event / Hotplug 圖
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant Source as External event source
|
||||
participant Backend as XdmaCaptureSession
|
||||
participant Facade as gvfg_capture.cpp
|
||||
participant App as Qt/customer app
|
||||
|
||||
Source->>Backend: backend event
|
||||
Backend->>Backend: classify event and update capture state
|
||||
Backend->>Facade: xdma_event_callback_t
|
||||
Facade->>Facade: map XDMA event and queue gvfg_event_t
|
||||
App->>Facade: gvfg_poll_event()
|
||||
Facade->>App: gvfg_event_t
|
||||
```
|
||||
|
||||
`VIDEO_IRQ` 類型的事件會推動 frame 資料進入 SDK frame path。Hotplug 類型事件則可能讓 backend pause/resume capture,App 可透過 `gvfg_poll_event()` 取得事件。
|
||||
|
||||
## 5. Build / 交付圖
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
Root["top-level CMakeLists.txt"] --> SDK["sdk/gvfg\nbuilds gvfg.dll + gvfg.lib"]
|
||||
Root --> Sample["samples/gvfg_qt_preview\nbuilds gvfg_qt_preview.exe"]
|
||||
SDK --> PublicHeader["include/gvfg_capture.h"]
|
||||
SDK --> Runtime["bin/gvfg.dll"]
|
||||
SDK --> ImportLib["lib/gvfg.lib"]
|
||||
Sample --> Exe["bin/gvfg_qt_preview.exe"]
|
||||
Runtime --> Exe
|
||||
```
|
||||
|
||||
客戶整合時應該只依賴:
|
||||
|
||||
```text
|
||||
include/gvfg_capture.h
|
||||
lib/gvfg.lib
|
||||
bin/gvfg.dll
|
||||
```
|
||||
|
||||
`sdk/gvfg/src/backend/xdma` 內的 header 和 types 都是 SDK 內部實作細節,不應該被客戶 App include。
|
||||
|
||||
## 建議維護方式
|
||||
|
||||
1. `GVFG_PROJECT_MAP.md`: 放高階架構、生命週期、SDK 內部資料流,適合每天看。
|
||||
2. `GVFG_ARCHITECTURE_OVERVIEW.drawio`: 放同一個三層視角的可視化版本,適合討論。
|
||||
3. `GVFG_DMA_RING_DATA_FLOW.drawio`: 若暫時只看 SDK code,可先當作底層參考,不放在主要 onboarding 流程。
|
||||
4. `GVFG_CUSTOMER_API.md`: 放 API 文件和客戶整合說明,適合交付和支援。
|
||||
|
||||
當 code 改動只影響 API 呼叫順序或 module 邊界,更新 Markdown 圖。當 code 改動影響 SDK worker、frame ring、callback lifetime,才更新 draw.io 細節圖。
|
||||
@@ -1,72 +0,0 @@
|
||||
# GVFG Pull API Notes
|
||||
|
||||
## Direction
|
||||
|
||||
The customer-facing capture path follows an FFmpeg-style pull model:
|
||||
|
||||
```text
|
||||
gvfg_enumerate_devices
|
||||
-> gvfg_create
|
||||
-> gvfg_open
|
||||
-> gvfg_start
|
||||
-> loop:
|
||||
gvfg_read_frame
|
||||
use frame data
|
||||
gvfg_release_frame
|
||||
gvfg_poll_event optional
|
||||
-> gvfg_stop
|
||||
-> gvfg_destroy
|
||||
```
|
||||
|
||||
## Frame Ownership
|
||||
|
||||
- `gvfg_read_frame()` returns one SDK-owned frame buffer.
|
||||
- `frame.data` remains valid until `gvfg_release_frame()` is called.
|
||||
- A handle may hold only one frame at a time.
|
||||
- If the application needs the frame after release, it must copy the data.
|
||||
|
||||
## Threading Model
|
||||
|
||||
The SDK may keep internal driver I/O workers, but it no longer starts a public
|
||||
frame callback loop for the application.
|
||||
|
||||
Applications own their threading model:
|
||||
|
||||
```text
|
||||
UI thread
|
||||
-> start capture
|
||||
-> create app-owned worker thread
|
||||
|
||||
worker thread
|
||||
-> gvfg_read_frame
|
||||
-> process or signal UI
|
||||
-> gvfg_release_frame
|
||||
```
|
||||
|
||||
This keeps the customer API simple while avoiding hidden callback-thread rules.
|
||||
|
||||
## Preview Boundary
|
||||
|
||||
Preview is not part of the customer SDK API. Internal apps or debug tools may
|
||||
render frames after `gvfg_read_frame()` with app-owned code:
|
||||
|
||||
```text
|
||||
gvfg_read_frame
|
||||
-> app/private preview renderer
|
||||
-> optional snapshot or recording
|
||||
-> gvfg_release_frame
|
||||
```
|
||||
|
||||
This keeps `gvfg.dll` focused on capture and avoids exposing D3D/render helper
|
||||
APIs to customers.
|
||||
|
||||
## Legacy APIs
|
||||
|
||||
`gvfg_set_callbacks()` and `gvfg_set_event_callback()` remain in the header for
|
||||
source compatibility during the transition. New customer code should prefer:
|
||||
|
||||
```text
|
||||
gvfg_read_frame
|
||||
gvfg_release_frame
|
||||
gvfg_poll_event
|
||||
```
|
||||
Reference in New Issue
Block a user