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:
@@ -23,6 +23,7 @@ if (NOT WIN32)
|
||||
endif()
|
||||
|
||||
add_subdirectory(sdk/gvfg)
|
||||
add_subdirectory(helpers/gvfg_preview)
|
||||
|
||||
if (BUILD_GVFG_SAMPLES)
|
||||
add_subdirectory(samples/gvfg_qt_preview)
|
||||
|
||||
@@ -8,13 +8,14 @@ the GVFG source directly.
|
||||
|
||||
## Contents
|
||||
|
||||
- `sdk/gvfg`: GVFG public C API and internal XDMA backend.
|
||||
- `sdk/gvfg/src/render`: GVFG internal D3D preview/render pipeline.
|
||||
- `samples/gvfg_qt_preview`: customer-facing Qt preview sample.
|
||||
- `sdk/gvfg`: GVFG customer C API, internal debug API, and XDMA backend.
|
||||
- `helpers/gvfg_preview`: optional preview helper DLL used after gvfg_read_frame().
|
||||
- `samples/gvfg_qt_preview`: internal debug Qt preview tool.
|
||||
- `docs`: API and integration notes.
|
||||
|
||||
Start with `docs/GVFG_PROJECT_MAP.md` for the project layer map, API
|
||||
lifecycle, and frame/event data-flow overview.
|
||||
Customer-facing API details are in `docs/GVFG_CUSTOMER_API.md`. Internal
|
||||
architecture, package split, threading, and frame ownership notes are in
|
||||
`docs/GVFG_INTERNAL_NOTES.md`.
|
||||
|
||||
## Build
|
||||
|
||||
@@ -39,7 +40,9 @@ Build outputs:
|
||||
|
||||
```text
|
||||
build/.../bin/gvfg.dll
|
||||
build/.../bin/gvfg_preview.dll
|
||||
build/.../lib/gvfg.lib
|
||||
build/.../lib/gvfg_preview.lib
|
||||
build/.../bin/gvfg_qt_preview.exe
|
||||
```
|
||||
|
||||
@@ -53,6 +56,15 @@ lib/gvfg.lib
|
||||
bin/gvfg.dll
|
||||
```
|
||||
|
||||
The XDMA backend headers are implementation details and should not be included by
|
||||
customer applications.
|
||||
Applications that want the optional display helper can also consume:
|
||||
|
||||
```text
|
||||
include/gvfg_preview.h
|
||||
lib/gvfg_preview.lib
|
||||
bin/gvfg_preview.dll
|
||||
```
|
||||
|
||||
Customer/demo packages should not include `gvfg_debug.h`, SDK source, XDMA
|
||||
backend headers, IRQ details, raw FPGA values, or preview helper source. Those
|
||||
belong in the internal debug/full application packages.
|
||||
|
||||
|
||||
@@ -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
|
||||
```
|
||||
@@ -0,0 +1,37 @@
|
||||
project(gvfg_preview LANGUAGES CXX)
|
||||
|
||||
add_library(gvfg_preview SHARED
|
||||
include/gvfg_preview.h
|
||||
src/d3d_preview_pipeline.cpp
|
||||
src/d3d_preview_pipeline.h
|
||||
src/gvfg_preview.cpp
|
||||
)
|
||||
|
||||
set_target_properties(gvfg_preview PROPERTIES
|
||||
AUTOMOC OFF
|
||||
AUTOUIC OFF
|
||||
AUTORCC OFF
|
||||
)
|
||||
|
||||
target_include_directories(gvfg_preview
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/include
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
target_compile_definitions(gvfg_preview PRIVATE
|
||||
GVFG_PREVIEW_BUILD
|
||||
)
|
||||
|
||||
target_link_libraries(gvfg_preview PRIVATE
|
||||
user32
|
||||
dxgi
|
||||
d3d11
|
||||
D3DCompiler
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(gvfg_preview PRIVATE /utf-8 /EHsc)
|
||||
endif()
|
||||
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Optional GVFG preview helper API.
|
||||
*
|
||||
* This helper renders frames returned by gvfg_read_frame(). It is intentionally
|
||||
* separate from gvfg.dll: applications own the read loop and decide whether to
|
||||
* render through this DLL, render themselves, record, snapshot, or process data.
|
||||
*/
|
||||
|
||||
#include <gvfg_capture.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef GVFG_PREVIEW_BUILD
|
||||
#define GVFG_PREVIEW_API __declspec(dllexport)
|
||||
#else
|
||||
#define GVFG_PREVIEW_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define GVFG_PREVIEW_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_PREVIEW_OK = 0,
|
||||
GVFG_PREVIEW_EINVAL = -1,
|
||||
GVFG_PREVIEW_ESTATE = -2,
|
||||
GVFG_PREVIEW_ENOTSUP = -3,
|
||||
GVFG_PREVIEW_ERENDER = -4
|
||||
} gvfg_preview_status_t;
|
||||
|
||||
typedef struct gvfg_preview_handle_t *gvfg_preview_handle;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int active;
|
||||
int width;
|
||||
int height;
|
||||
int bit_depth;
|
||||
char pixel_format[32];
|
||||
} gvfg_preview_info_t;
|
||||
|
||||
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_create(gvfg_preview_handle *out_handle);
|
||||
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_destroy(gvfg_preview_handle handle);
|
||||
|
||||
/*
|
||||
* Attach a native window handle for preview output.
|
||||
*
|
||||
* On Windows, native_window_handle is an HWND.
|
||||
*/
|
||||
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_attach_window(gvfg_preview_handle handle,
|
||||
void *native_window_handle);
|
||||
|
||||
/*
|
||||
* Synchronously render one frame.
|
||||
*
|
||||
* The frame remains owned by gvfg.dll. The caller should call this between
|
||||
* gvfg_read_frame() and gvfg_release_frame().
|
||||
*/
|
||||
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_render_frame(gvfg_preview_handle handle,
|
||||
const gvfg_frame_t *frame);
|
||||
|
||||
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_get_info(gvfg_preview_handle handle,
|
||||
gvfg_preview_info_t *out_info);
|
||||
|
||||
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_shutdown(gvfg_preview_handle handle);
|
||||
|
||||
GVFG_PREVIEW_API const char *gvfg_preview_strerror(gvfg_preview_status_t status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+27
-23
@@ -1,9 +1,8 @@
|
||||
#include "../internal/gvfg_logging.h"
|
||||
#include "d3d_preview_pipeline.h"
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include "shared_scene_pipeline.h"
|
||||
|
||||
using namespace gvfg::internal;
|
||||
|
||||
@@ -14,6 +13,11 @@ using namespace gvfg::internal;
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
static void d3d_preview_log_debug(const char *message)
|
||||
{
|
||||
OutputDebugStringA(message ? message : "");
|
||||
}
|
||||
|
||||
static inline uint16_t normalize_y210_word_for_upload(uint16_t v)
|
||||
{
|
||||
// Y210 stores each 10-bit component left-aligned in a 16-bit WORD.
|
||||
@@ -46,8 +50,8 @@ static void ssp_log_text(const char *msg)
|
||||
{
|
||||
if (!msg)
|
||||
return;
|
||||
gvfg_log_debug(msg);
|
||||
gvfg_log_debug("\n");
|
||||
d3d_preview_log_debug(msg);
|
||||
d3d_preview_log_debug("\n");
|
||||
}
|
||||
|
||||
static ComPtr<ID3D11ShaderResourceView> createSRV_NV12(ID3D11Device *dev, ID3D11Texture2D *tex, bool uv)
|
||||
@@ -615,7 +619,7 @@ float4 main(PSIn i) : SV_Target
|
||||
}
|
||||
)";
|
||||
|
||||
bool SharedScenePipeline::initialize(ID3D11Device *d3d,
|
||||
bool D3DPreviewPipeline::initialize(ID3D11Device *d3d,
|
||||
ID3D11DeviceContext *ctx)
|
||||
{
|
||||
d3d_ = d3d;
|
||||
@@ -623,7 +627,7 @@ bool SharedScenePipeline::initialize(ID3D11Device *d3d,
|
||||
return d3d_ && ctx_;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::configurePreview(const gvfg_render_preview_desc_t &desc)
|
||||
bool D3DPreviewPipeline::configurePreview(const gvfg_render_preview_desc_t &desc)
|
||||
{
|
||||
int requestedMode = desc.swapchain_10bit;
|
||||
if (requestedMode != GVFG_RENDER_PREVIEW_BITDEPTH_8BIT &&
|
||||
@@ -648,7 +652,7 @@ bool SharedScenePipeline::configurePreview(const gvfg_render_preview_desc_t &des
|
||||
return true;
|
||||
}
|
||||
|
||||
void SharedScenePipeline::set_source_bit_depth(int bits)
|
||||
void D3DPreviewPipeline::set_source_bit_depth(int bits)
|
||||
{
|
||||
if (bits != 8 && bits != 10 && bits != 12 && bits != 16)
|
||||
bits = 0;
|
||||
@@ -665,7 +669,7 @@ void SharedScenePipeline::set_source_bit_depth(int bits)
|
||||
release_preview_swapchain();
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::create_shaders_and_states()
|
||||
bool D3DPreviewPipeline::create_shaders_and_states()
|
||||
{
|
||||
// Compile shaders
|
||||
ComPtr<ID3DBlob> vsb, psb1, psb2, psb3, psb4, psb5, psb6, err;
|
||||
@@ -764,7 +768,7 @@ bool SharedScenePipeline::create_shaders_and_states()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::ensure_rt_and_pipeline(int w, int h)
|
||||
bool D3DPreviewPipeline::ensure_rt_and_pipeline(int w, int h)
|
||||
{
|
||||
const bool hasAllTargets = rt_fp16_ && rtv_fp16_ && srv_fp16_ &&
|
||||
rt_scene_fp16_ && rtv_scene_fp16_ && srv_scene_fp16_ &&
|
||||
@@ -844,7 +848,7 @@ bool SharedScenePipeline::ensure_rt_and_pipeline(int w, int h)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::blit_fp16_to_rgba8(int frame_w, int frame_h)
|
||||
bool D3DPreviewPipeline::blit_fp16_to_rgba8(int frame_w, int frame_h)
|
||||
{
|
||||
if (!rtv_rgba_ || !srv_scene_fp16_ || !vs_ || !ps_fp16_to_rgba8_ || !ctx_)
|
||||
return false;
|
||||
@@ -887,7 +891,7 @@ bool SharedScenePipeline::blit_fp16_to_rgba8(int frame_w, int frame_h)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::upload_nv12_frame(const uint8_t *y, int stride_y, const uint8_t *uv, int stride_uv, int frame_w, int frame_h)
|
||||
bool D3DPreviewPipeline::upload_nv12_frame(const uint8_t *y, int stride_y, const uint8_t *uv, int stride_uv, int frame_w, int frame_h)
|
||||
{
|
||||
if (!d3d_ || !ctx_ || !y || !uv || frame_w <= 0 || frame_h <= 0 || stride_y <= 0 || stride_uv <= 0)
|
||||
return false;
|
||||
@@ -935,7 +939,7 @@ bool SharedScenePipeline::upload_nv12_frame(const uint8_t *y, int stride_y, cons
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::upload_p010_frame(const uint8_t *y, int stride_y, const uint8_t *uv, int stride_uv, int frame_w, int frame_h)
|
||||
bool D3DPreviewPipeline::upload_p010_frame(const uint8_t *y, int stride_y, const uint8_t *uv, int stride_uv, int frame_w, int frame_h)
|
||||
{
|
||||
if (!ctx_ || !d3d_ || !y || !uv || frame_w <= 0 || frame_h <= 0)
|
||||
return false;
|
||||
@@ -983,7 +987,7 @@ bool SharedScenePipeline::upload_p010_frame(const uint8_t *y, int stride_y, cons
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::upload_yuy2_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h)
|
||||
bool D3DPreviewPipeline::upload_yuy2_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h)
|
||||
{
|
||||
if (!d3d_ || !ctx_ || !data || frame_w <= 0 || frame_h <= 0 || src_stride <= 0)
|
||||
return false;
|
||||
@@ -1031,7 +1035,7 @@ bool SharedScenePipeline::upload_yuy2_frame(const uint8_t *data, int src_stride,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::upload_y210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h)
|
||||
bool D3DPreviewPipeline::upload_y210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h)
|
||||
{
|
||||
if (!ctx_ || !d3d_ || !data || frame_w <= 0 || frame_h <= 0)
|
||||
return false;
|
||||
@@ -1099,7 +1103,7 @@ bool SharedScenePipeline::upload_y210_frame(const uint8_t *data, int src_stride,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, int frame_w, int frame_h)
|
||||
bool D3DPreviewPipeline::render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, int frame_w, int frame_h)
|
||||
{
|
||||
if (!ctx_ || !vs_ || !il_ || !vb_ || !rtv_fp16_ || !rt_fp16_ || frame_w <= 0 || frame_h <= 0)
|
||||
return false;
|
||||
@@ -1250,7 +1254,7 @@ bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::copy_fp16_to_scene()
|
||||
bool D3DPreviewPipeline::copy_fp16_to_scene()
|
||||
{
|
||||
if (!ctx_ || !rt_fp16_ || !rt_scene_fp16_)
|
||||
return false;
|
||||
@@ -1258,7 +1262,7 @@ bool SharedScenePipeline::copy_fp16_to_scene()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::readback_to_frame(int frame_w, int frame_h, uint64_t pts_ns, uint64_t frame_id,
|
||||
bool D3DPreviewPipeline::readback_to_frame(int frame_w, int frame_h, uint64_t pts_ns, uint64_t frame_id,
|
||||
gvfg_render_frame_t *out)
|
||||
{
|
||||
if (!out || !ctx_ || !rt_stage_ || !rt_rgba_)
|
||||
@@ -1281,7 +1285,7 @@ bool SharedScenePipeline::readback_to_frame(int frame_w, int frame_h, uint64_t p
|
||||
return true;
|
||||
}
|
||||
|
||||
void SharedScenePipeline::release_preview_swapchain()
|
||||
void D3DPreviewPipeline::release_preview_swapchain()
|
||||
{
|
||||
preview_rtv_.Reset();
|
||||
preview_backbuf_.Reset();
|
||||
@@ -1292,7 +1296,7 @@ void SharedScenePipeline::release_preview_swapchain()
|
||||
preview_swapchain_format_ = DXGI_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::ensure_preview_swapchain(int w, int h)
|
||||
bool D3DPreviewPipeline::ensure_preview_swapchain(int w, int h)
|
||||
{
|
||||
if (!preview_enabled_ || !preview_hwnd_ || !d3d_)
|
||||
return false;
|
||||
@@ -1441,7 +1445,7 @@ bool SharedScenePipeline::ensure_preview_swapchain(int w, int h)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SharedScenePipeline::present_preview(int src_w, int src_h)
|
||||
bool D3DPreviewPipeline::present_preview(int src_w, int src_h)
|
||||
{
|
||||
static bool s_loggedPresentPath = false;
|
||||
if (!preview_enabled_ || !preview_swapchain_ || !preview_backbuf_ || !ctx_)
|
||||
@@ -1554,7 +1558,7 @@ bool SharedScenePipeline::present_preview(int src_w, int src_h)
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
DXGI_FORMAT SharedScenePipeline::preview_backbuffer_format() const
|
||||
DXGI_FORMAT D3DPreviewPipeline::preview_backbuffer_format() const
|
||||
{
|
||||
if (preview_swapchain_format_ != DXGI_FORMAT_UNKNOWN)
|
||||
return preview_swapchain_format_;
|
||||
@@ -1565,7 +1569,7 @@ DXGI_FORMAT SharedScenePipeline::preview_backbuffer_format() const
|
||||
return d.Format;
|
||||
}
|
||||
|
||||
DXGI_FORMAT SharedScenePipeline::scene_texture_format() const
|
||||
DXGI_FORMAT D3DPreviewPipeline::scene_texture_format() const
|
||||
{
|
||||
if (!rt_scene_fp16_)
|
||||
return DXGI_FORMAT_UNKNOWN;
|
||||
@@ -1574,7 +1578,7 @@ DXGI_FORMAT SharedScenePipeline::scene_texture_format() const
|
||||
return d.Format;
|
||||
}
|
||||
|
||||
DXGI_FORMAT SharedScenePipeline::linear_fp16_texture_format() const
|
||||
DXGI_FORMAT D3DPreviewPipeline::linear_fp16_texture_format() const
|
||||
{
|
||||
if (!rt_fp16_)
|
||||
return DXGI_FORMAT_UNKNOWN;
|
||||
+40
-5
@@ -1,19 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "../internal/gvfg_render_types.h"
|
||||
|
||||
#include <d3d11_1.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <stdint.h>
|
||||
#include <wrl.h>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
|
||||
class SharedScenePipeline
|
||||
typedef enum
|
||||
{
|
||||
GVFG_RENDER_FMT_NV12,
|
||||
GVFG_RENDER_FMT_YUY2,
|
||||
GVFG_RENDER_FMT_ARGB,
|
||||
GVFG_RENDER_FMT_P010,
|
||||
GVFG_RENDER_FMT_Y210
|
||||
} gvfg_render_pixfmt_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const void *data[3];
|
||||
int stride[3];
|
||||
int plane_count;
|
||||
int width;
|
||||
int height;
|
||||
gvfg_render_pixfmt_t format;
|
||||
uint64_t pts_ns;
|
||||
uint64_t frame_id;
|
||||
} gvfg_render_frame_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_8BIT = 0,
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_10BIT = 1,
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_AUTO = 2
|
||||
} gvfg_render_preview_bitdepth_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *hwnd;
|
||||
int enable_preview;
|
||||
int use_fp16_pipeline;
|
||||
int swapchain_10bit;
|
||||
} gvfg_render_preview_desc_t;
|
||||
|
||||
class D3DPreviewPipeline
|
||||
{
|
||||
public:
|
||||
SharedScenePipeline() = default;
|
||||
~SharedScenePipeline() = default;
|
||||
D3DPreviewPipeline() = default;
|
||||
~D3DPreviewPipeline() = default;
|
||||
|
||||
bool initialize(ID3D11Device *d3d,
|
||||
ID3D11DeviceContext *ctx);
|
||||
@@ -0,0 +1,317 @@
|
||||
#include "gvfg_preview.h"
|
||||
|
||||
#include "d3d_preview_pipeline.h"
|
||||
|
||||
#include <d3d11_4.h>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <wrl/client.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
class PreviewRenderer
|
||||
{
|
||||
public:
|
||||
PreviewRenderer() = default;
|
||||
~PreviewRenderer() { shutdown(); }
|
||||
|
||||
bool configure(void *hwnd)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
hwnd_ = hwnd;
|
||||
configured_ = hwnd_ != nullptr;
|
||||
if (pipeline_)
|
||||
{
|
||||
gvfg::internal::gvfg_render_preview_desc_t desc{};
|
||||
desc.hwnd = hwnd_;
|
||||
desc.enable_preview = configured_ ? 1 : 0;
|
||||
desc.use_fp16_pipeline = 1;
|
||||
desc.swapchain_10bit = gvfg::internal::GVFG_RENDER_PREVIEW_BITDEPTH_AUTO;
|
||||
pipeline_->configurePreview(desc);
|
||||
}
|
||||
return configured_;
|
||||
}
|
||||
|
||||
bool render(const gvfg_frame_t &frame)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!configured_ || !hwnd_ || !frame.data || frame.width <= 0 || frame.height <= 0)
|
||||
return false;
|
||||
|
||||
if (!ensureDevice() || !ensurePipeline(frame.width, frame.height, frame.bit_depth > 0 ? frame.bit_depth : 8))
|
||||
return false;
|
||||
|
||||
const auto *base = static_cast<const uint8_t *>(frame.data);
|
||||
gvfg::internal::gvfg_render_pixfmt_t renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
||||
bool uploaded = false;
|
||||
|
||||
switch (frame.pixel_format)
|
||||
{
|
||||
case GVFG_PIXFMT_YUY2:
|
||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
||||
uploaded = pipeline_->upload_yuy2_frame(base, frame.width * 2, frame.width, frame.height);
|
||||
break;
|
||||
case GVFG_PIXFMT_Y210:
|
||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_Y210;
|
||||
uploaded = pipeline_->upload_y210_frame(base, frame.width * 4, frame.width, frame.height);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!uploaded ||
|
||||
!pipeline_->render_uploaded_yuv_to_fp16(renderFmt, frame.width, frame.height) ||
|
||||
!pipeline_->copy_fp16_to_scene())
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
if (!pipeline_->preview_swapchain_10bit())
|
||||
ok = pipeline_->blit_fp16_to_rgba8(frame.width, frame.height);
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
pipeline_->present_preview(frame.width, frame.height);
|
||||
width_ = pipeline_->preview_w_;
|
||||
height_ = pipeline_->preview_h_;
|
||||
bitDepth_ = pipeline_->preview_swapchain_10bit() ? 10 : 8;
|
||||
swapchain10Bit_ = pipeline_->preview_swapchain_10bit();
|
||||
return true;
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (pipeline_)
|
||||
pipeline_->release_preview_swapchain();
|
||||
pipeline_.reset();
|
||||
d3d_.reset();
|
||||
configured_ = false;
|
||||
hwnd_ = nullptr;
|
||||
width_ = 0;
|
||||
height_ = 0;
|
||||
bitDepth_ = 0;
|
||||
swapchain10Bit_ = false;
|
||||
}
|
||||
|
||||
bool active() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return configured_ && pipeline_ && width_ > 0 && height_ > 0;
|
||||
}
|
||||
|
||||
int width() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return width_;
|
||||
}
|
||||
|
||||
int height() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return height_;
|
||||
}
|
||||
|
||||
int bitDepth() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return bitDepth_;
|
||||
}
|
||||
|
||||
const char *pixelFormat() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return swapchain10Bit_ ? "RGB10A2" : "BGRA8";
|
||||
}
|
||||
|
||||
private:
|
||||
struct D3DState
|
||||
{
|
||||
ComPtr<ID3D11Device> device;
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
};
|
||||
|
||||
bool ensureDevice()
|
||||
{
|
||||
if (d3d_ && d3d_->device && d3d_->context)
|
||||
return true;
|
||||
|
||||
auto state = std::make_unique<D3DState>();
|
||||
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
||||
#ifdef _DEBUG
|
||||
flags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
D3D_FEATURE_LEVEL levels[] = {D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0};
|
||||
D3D_FEATURE_LEVEL got{};
|
||||
HRESULT hr = D3D11CreateDevice(nullptr,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
flags,
|
||||
levels,
|
||||
_countof(levels),
|
||||
D3D11_SDK_VERSION,
|
||||
&state->device,
|
||||
&got,
|
||||
&state->context);
|
||||
#ifdef _DEBUG
|
||||
if (FAILED(hr))
|
||||
{
|
||||
flags &= ~D3D11_CREATE_DEVICE_DEBUG;
|
||||
hr = D3D11CreateDevice(nullptr,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
flags,
|
||||
levels,
|
||||
_countof(levels),
|
||||
D3D11_SDK_VERSION,
|
||||
&state->device,
|
||||
&got,
|
||||
&state->context);
|
||||
}
|
||||
#endif
|
||||
if (FAILED(hr) || !state->device || !state->context)
|
||||
return false;
|
||||
|
||||
ComPtr<ID3D11Multithread> mt;
|
||||
if (SUCCEEDED(state->device.As(&mt)) && mt)
|
||||
mt->SetMultithreadProtected(TRUE);
|
||||
|
||||
d3d_ = std::move(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ensurePipeline(int width, int height, int sourceBitDepth)
|
||||
{
|
||||
if (!pipeline_)
|
||||
pipeline_ = std::make_unique<gvfg::internal::D3DPreviewPipeline>();
|
||||
|
||||
if (!pipeline_->initialize(d3d_->device.Get(), d3d_->context.Get()))
|
||||
return false;
|
||||
|
||||
gvfg::internal::gvfg_render_preview_desc_t desc{};
|
||||
desc.hwnd = hwnd_;
|
||||
desc.enable_preview = configured_ ? 1 : 0;
|
||||
desc.use_fp16_pipeline = 1;
|
||||
desc.swapchain_10bit = gvfg::internal::GVFG_RENDER_PREVIEW_BITDEPTH_AUTO;
|
||||
pipeline_->configurePreview(desc);
|
||||
pipeline_->set_source_bit_depth(sourceBitDepth > 0 ? sourceBitDepth : 8);
|
||||
return pipeline_->ensure_rt_and_pipeline(width, height) &&
|
||||
pipeline_->ensure_preview_swapchain(width, height);
|
||||
}
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
void *hwnd_ = nullptr;
|
||||
bool configured_ = false;
|
||||
int width_ = 0;
|
||||
int height_ = 0;
|
||||
int bitDepth_ = 0;
|
||||
bool swapchain10Bit_ = false;
|
||||
std::unique_ptr<D3DState> d3d_;
|
||||
std::unique_ptr<gvfg::internal::D3DPreviewPipeline> pipeline_;
|
||||
};
|
||||
|
||||
struct gvfg_preview_handle_t
|
||||
{
|
||||
PreviewRenderer renderer;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
void copy_cstr(char *dst, size_t dstSize, const char *src)
|
||||
{
|
||||
if (!dst || dstSize == 0)
|
||||
return;
|
||||
dst[0] = '\0';
|
||||
if (src)
|
||||
strncpy_s(dst, dstSize, src, _TRUNCATE);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
gvfg_preview_status_t gvfg_preview_create(gvfg_preview_handle *out_handle)
|
||||
{
|
||||
if (!out_handle)
|
||||
return GVFG_PREVIEW_EINVAL;
|
||||
*out_handle = nullptr;
|
||||
auto handle = std::make_unique<gvfg_preview_handle_t>();
|
||||
*out_handle = handle.release();
|
||||
return GVFG_PREVIEW_OK;
|
||||
}
|
||||
|
||||
gvfg_preview_status_t gvfg_preview_destroy(gvfg_preview_handle handle)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_PREVIEW_OK;
|
||||
delete handle;
|
||||
return GVFG_PREVIEW_OK;
|
||||
}
|
||||
|
||||
gvfg_preview_status_t gvfg_preview_attach_window(gvfg_preview_handle handle,
|
||||
void *native_window_handle)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_PREVIEW_EINVAL;
|
||||
if (!native_window_handle)
|
||||
{
|
||||
handle->renderer.shutdown();
|
||||
return GVFG_PREVIEW_EINVAL;
|
||||
}
|
||||
return handle->renderer.configure(native_window_handle) ? GVFG_PREVIEW_OK : GVFG_PREVIEW_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_preview_status_t gvfg_preview_render_frame(gvfg_preview_handle handle,
|
||||
const gvfg_frame_t *frame)
|
||||
{
|
||||
if (!handle || !frame)
|
||||
return GVFG_PREVIEW_EINVAL;
|
||||
if (!frame->data || frame->width <= 0 || frame->height <= 0)
|
||||
return GVFG_PREVIEW_EINVAL;
|
||||
if (frame->pixel_format != GVFG_PIXFMT_YUY2 && frame->pixel_format != GVFG_PIXFMT_Y210)
|
||||
return GVFG_PREVIEW_ENOTSUP;
|
||||
return handle->renderer.render(*frame) ? GVFG_PREVIEW_OK : GVFG_PREVIEW_ERENDER;
|
||||
}
|
||||
|
||||
gvfg_preview_status_t gvfg_preview_get_info(gvfg_preview_handle handle,
|
||||
gvfg_preview_info_t *out_info)
|
||||
{
|
||||
if (!handle || !out_info)
|
||||
return GVFG_PREVIEW_EINVAL;
|
||||
std::memset(out_info, 0, sizeof(*out_info));
|
||||
out_info->active = handle->renderer.active() ? 1 : 0;
|
||||
out_info->width = handle->renderer.width();
|
||||
out_info->height = handle->renderer.height();
|
||||
out_info->bit_depth = handle->renderer.bitDepth();
|
||||
copy_cstr(out_info->pixel_format,
|
||||
sizeof(out_info->pixel_format),
|
||||
handle->renderer.pixelFormat());
|
||||
return GVFG_PREVIEW_OK;
|
||||
}
|
||||
|
||||
gvfg_preview_status_t gvfg_preview_shutdown(gvfg_preview_handle handle)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_PREVIEW_EINVAL;
|
||||
handle->renderer.shutdown();
|
||||
return GVFG_PREVIEW_OK;
|
||||
}
|
||||
|
||||
const char *gvfg_preview_strerror(gvfg_preview_status_t status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case GVFG_PREVIEW_OK:
|
||||
return "OK";
|
||||
case GVFG_PREVIEW_EINVAL:
|
||||
return "Invalid argument";
|
||||
case GVFG_PREVIEW_ESTATE:
|
||||
return "Invalid state";
|
||||
case GVFG_PREVIEW_ENOTSUP:
|
||||
return "Unsupported frame format";
|
||||
case GVFG_PREVIEW_ERENDER:
|
||||
return "Render failed";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,16 @@ if not exist "%LIB_DIR%\gvfg.lib" (
|
||||
goto fail
|
||||
)
|
||||
|
||||
if not exist "%BIN_DIR%\gvfg_preview.dll" (
|
||||
echo [release] ERROR: "%BIN_DIR%\gvfg_preview.dll" not found.
|
||||
goto fail
|
||||
)
|
||||
|
||||
if not exist "%LIB_DIR%\gvfg_preview.lib" (
|
||||
echo [release] ERROR: "%LIB_DIR%\gvfg_preview.lib" not found.
|
||||
goto fail
|
||||
)
|
||||
|
||||
if not exist "%BIN_DIR%\gvfg_qt_preview.exe" (
|
||||
echo [release] ERROR: "%BIN_DIR%\gvfg_qt_preview.exe" not found.
|
||||
goto fail
|
||||
@@ -82,10 +92,14 @@ mkdir "%STAGE_DIR%\samples\gvfg_qt_preview" || goto fail
|
||||
mkdir "%STAGE_DIR%\samples\gvfg_qt_preview_source" || goto fail
|
||||
|
||||
copy /Y "%PROJECT_DIR%\sdk\gvfg\include\gvfg_capture.h" "%STAGE_DIR%\include\" >nul || goto fail
|
||||
copy /Y "%PROJECT_DIR%\helpers\gvfg_preview\include\gvfg_preview.h" "%STAGE_DIR%\include\" >nul || goto fail
|
||||
copy /Y "%BIN_DIR%\gvfg.dll" "%STAGE_DIR%\bin\" >nul || goto fail
|
||||
copy /Y "%BIN_DIR%\gvfg_preview.dll" "%STAGE_DIR%\bin\" >nul || goto fail
|
||||
copy /Y "%LIB_DIR%\gvfg.lib" "%STAGE_DIR%\lib\" >nul || goto fail
|
||||
copy /Y "%LIB_DIR%\gvfg_preview.lib" "%STAGE_DIR%\lib\" >nul || goto fail
|
||||
copy /Y "%BIN_DIR%\gvfg_qt_preview.exe" "%STAGE_DIR%\samples\gvfg_qt_preview\" >nul || goto fail
|
||||
copy /Y "%BIN_DIR%\gvfg.dll" "%STAGE_DIR%\samples\gvfg_qt_preview\" >nul || goto fail
|
||||
copy /Y "%BIN_DIR%\gvfg_preview.dll" "%STAGE_DIR%\samples\gvfg_qt_preview\" >nul || goto fail
|
||||
copy /Y "%PROJECT_DIR%\README.md" "%STAGE_DIR%\" >nul || goto fail
|
||||
copy /Y "%PROJECT_DIR%\docs\GVFG_CUSTOMER_API.md" "%STAGE_DIR%\docs\" >nul || goto fail
|
||||
|
||||
@@ -115,13 +129,18 @@ echo [release] Write package notes...
|
||||
echo.
|
||||
echo Layout:
|
||||
echo include\gvfg_capture.h
|
||||
echo include\gvfg_preview.h
|
||||
echo lib\gvfg.lib
|
||||
echo lib\gvfg_preview.lib
|
||||
echo bin\gvfg.dll
|
||||
echo bin\gvfg_preview.dll
|
||||
echo samples\gvfg_qt_preview\gvfg_qt_preview.exe
|
||||
echo samples\gvfg_qt_preview_source\
|
||||
echo docs\GVFG_CUSTOMER_API.md
|
||||
echo.
|
||||
echo Link with lib\gvfg.lib and deploy bin\gvfg.dll next to the customer application executable.
|
||||
echo Link with lib\gvfg.lib for capture.
|
||||
echo Link with lib\gvfg_preview.lib only if the application uses the optional preview helper.
|
||||
echo Deploy bin\gvfg.dll and, when used, bin\gvfg_preview.dll next to the customer application executable.
|
||||
echo Run samples\gvfg_qt_preview\gvfg_qt_preview.exe to verify the packaged runtime.
|
||||
) > "%STAGE_DIR%\PACKAGE_README.txt"
|
||||
|
||||
|
||||
@@ -17,10 +17,6 @@ if (QT_VERSION_MAJOR GREATER_EQUAL 6)
|
||||
previewwindow.cpp
|
||||
previewwindow.h
|
||||
previewwindow.ui
|
||||
sample_preview_renderer.cpp
|
||||
sample_preview_renderer.h
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/gvfg_log_bridge.cpp
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/render/shared_scene_pipeline.cpp
|
||||
)
|
||||
else()
|
||||
add_executable(gvfg_qt_preview
|
||||
@@ -31,26 +27,17 @@ else()
|
||||
previewwindow.cpp
|
||||
previewwindow.h
|
||||
previewwindow.ui
|
||||
sample_preview_renderer.cpp
|
||||
sample_preview_renderer.h
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/gvfg_log_bridge.cpp
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/render/shared_scene_pipeline.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(gvfg_qt_preview PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
gvfg
|
||||
user32
|
||||
dxgi
|
||||
d3d11
|
||||
D3DCompiler
|
||||
gvfg_preview
|
||||
)
|
||||
|
||||
target_include_directories(gvfg_qt_preview PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/include
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/internal
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/render
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "previewwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <gvfg_debug.h>
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QDateTime>
|
||||
#include <QMetaObject>
|
||||
@@ -18,8 +20,6 @@ namespace
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GVFG_EVENT_VIDEO_IRQ:
|
||||
return QStringLiteral("VIDEO_IRQ");
|
||||
case GVFG_EVENT_PLUG_IN:
|
||||
return QStringLiteral("PLUG_IN");
|
||||
case GVFG_EVENT_PLUG_OUT:
|
||||
@@ -166,7 +166,11 @@ bool MainWindow::openDevice()
|
||||
void MainWindow::closeDevice()
|
||||
{
|
||||
stopCapture();
|
||||
previewRenderer_.shutdown();
|
||||
if (previewHandle_)
|
||||
{
|
||||
gvfg_preview_destroy(previewHandle_);
|
||||
previewHandle_ = nullptr;
|
||||
}
|
||||
|
||||
if (signalStatusTimer_)
|
||||
signalStatusTimer_->stop();
|
||||
@@ -235,9 +239,23 @@ void MainWindow::stopCapture()
|
||||
|
||||
bool MainWindow::applyPreview()
|
||||
{
|
||||
if (!previewRenderer_.configure(previewWindow_->nativePreviewHandle()))
|
||||
if (!previewHandle_)
|
||||
{
|
||||
appendLog(QStringLiteral("Preview setup failed: invalid preview window"));
|
||||
const gvfg_preview_status_t st = gvfg_preview_create(&previewHandle_);
|
||||
if (st != GVFG_PREVIEW_OK || !previewHandle_)
|
||||
{
|
||||
appendLog(QStringLiteral("Preview setup failed: %1")
|
||||
.arg(QString::fromUtf8(gvfg_preview_strerror(st))));
|
||||
previewHandle_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const gvfg_preview_status_t st = gvfg_preview_attach_window(previewHandle_, previewWindow_->nativePreviewHandle());
|
||||
if (st != GVFG_PREVIEW_OK)
|
||||
{
|
||||
appendLog(QStringLiteral("Preview setup failed: %1")
|
||||
.arg(QString::fromUtf8(gvfg_preview_strerror(st))));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -246,7 +264,7 @@ bool MainWindow::applyPreview()
|
||||
void MainWindow::updatePreviewSourceSize(const gvfg_runtime_info_t &info)
|
||||
{
|
||||
const auto &signal = info.input_signal;
|
||||
const auto &readFrame = info.callback_frame;
|
||||
const auto &readFrame = info.last_frame;
|
||||
|
||||
if (signal.width > 0 && signal.height > 0)
|
||||
{
|
||||
@@ -278,47 +296,46 @@ void MainWindow::updateSignalStatus(bool writeLog)
|
||||
return;
|
||||
|
||||
const auto &signal = info.input_signal;
|
||||
const auto &readFrame = info.callback_frame;
|
||||
const auto &readFrame = info.last_frame;
|
||||
gvfg_debug_fpga_signal_raw_t fpgaRaw{};
|
||||
const bool haveRaw = gvfg_debug_get_fpga_signal_raw(handle_, &fpgaRaw) == GVFG_OK;
|
||||
if (previewWindow_->isVisible())
|
||||
updatePreviewSourceSize(info);
|
||||
|
||||
const QString fpgaResolution = (signal.width > 0 && signal.height > 0)
|
||||
? QStringLiteral("%1x%2").arg(signal.width).arg(signal.height)
|
||||
: QStringLiteral("--");
|
||||
const QString frameRateText = signal.frame_rate_code >= 0
|
||||
? QStringLiteral("%1 (%2)")
|
||||
.arg(QString::fromLatin1(signal.frame_rate_bits))
|
||||
.arg(QString::fromLatin1(signal.frame_rate_name))
|
||||
: QStringLiteral("--");
|
||||
const QString formatText = signal.video_format_code >= 0
|
||||
? QStringLiteral("%1 (%2)")
|
||||
.arg(signal.video_format_code)
|
||||
.arg(QString::fromLatin1(signal.video_format))
|
||||
: QStringLiteral("--");
|
||||
const QString frameRateText = QString::fromLatin1(signal.frame_rate_name);
|
||||
const QString formatText = QString::fromLatin1(signal.video_format);
|
||||
const QString bitDepthText = signal.bit_depth > 0 ? QString::number(signal.bit_depth) : QStringLiteral("--");
|
||||
const QString line0 = QStringLiteral("FPGA reported | signal=%1 fps=%2 format=%3 bitdepth=%4")
|
||||
.arg(fpgaResolution)
|
||||
.arg(frameRateText)
|
||||
.arg(formatText)
|
||||
.arg(bitDepthText);
|
||||
const QString line2 = QStringLiteral("FPGA status | SDI lock=%1 SDI DDR=%2 HDMI lock=%3 HDMI DDR=%4")
|
||||
const QString line2 = QStringLiteral("Signal lock | SDI=%1 HDMI=%2")
|
||||
.arg(signal.sdi_locked)
|
||||
.arg(signal.sdi_ddr_ok)
|
||||
.arg(signal.hdmi_locked)
|
||||
.arg(signal.hdmi_ddr_ok);
|
||||
const QString lineRaw = QStringLiteral("FPGA raw | size=%1x%2 fmt=%3 fps=%4 bit=%5 status=%6")
|
||||
.arg(signal.raw.width)
|
||||
.arg(signal.raw.height)
|
||||
.arg(hex32(signal.raw.video_format))
|
||||
.arg(hex32(signal.raw.frame_rate))
|
||||
.arg(signal.raw.bit_depth)
|
||||
.arg(hex32(signal.raw.status));
|
||||
const QString line3 = previewRenderer_.active()
|
||||
.arg(signal.hdmi_locked);
|
||||
const QString lineRaw = haveRaw
|
||||
? QStringLiteral("FPGA raw | valid=%1 size=%2x%3 fmt=%4 fps=%5 bit=%6 status=%7")
|
||||
.arg(hex32(fpgaRaw.valid_mask))
|
||||
.arg(fpgaRaw.width_raw)
|
||||
.arg(fpgaRaw.height_raw)
|
||||
.arg(hex32(fpgaRaw.video_format_raw))
|
||||
.arg(hex32(fpgaRaw.frame_rate_raw))
|
||||
.arg(fpgaRaw.bit_depth_raw)
|
||||
.arg(hex32(fpgaRaw.status_raw))
|
||||
: QStringLiteral("FPGA raw | unavailable");
|
||||
gvfg_preview_info_t previewInfo{};
|
||||
const bool previewInfoOk = previewHandle_ &&
|
||||
gvfg_preview_get_info(previewHandle_, &previewInfo) == GVFG_PREVIEW_OK &&
|
||||
previewInfo.active;
|
||||
const QString line3 = previewInfoOk
|
||||
? QStringLiteral("Preview output | frame=%1x%2 format=%3 bitdepth=%4")
|
||||
.arg(previewRenderer_.width())
|
||||
.arg(previewRenderer_.height())
|
||||
.arg(QString::fromUtf8(previewRenderer_.pixelFormat()))
|
||||
.arg(previewRenderer_.bitDepth())
|
||||
.arg(previewInfo.width)
|
||||
.arg(previewInfo.height)
|
||||
.arg(QString::fromUtf8(previewInfo.pixel_format))
|
||||
.arg(previewInfo.bit_depth)
|
||||
: QStringLiteral("Preview output | app renderer inactive");
|
||||
const QString line4 = readFrame.valid
|
||||
? QStringLiteral("Read frame | frame=%1x%2 format=%3 bitdepth=%4")
|
||||
@@ -377,16 +394,12 @@ void MainWindow::captureReadLoop()
|
||||
while (gvfg_poll_event(handle_, &event, 0) == GVFG_OK)
|
||||
{
|
||||
const QString type = eventTypeText(event.type);
|
||||
const uint32_t irqBit = event.irq_bit;
|
||||
const uint32_t irqMask = event.irq_mask;
|
||||
const uint64_t timestampNs = event.timestamp_ns;
|
||||
QMetaObject::invokeMethod(this,
|
||||
[this, type, irqBit, irqMask, timestampNs]()
|
||||
[this, type, timestampNs]()
|
||||
{
|
||||
appendLog(QStringLiteral("event %1 irq=%2 mask=%3 ts=%4")
|
||||
appendLog(QStringLiteral("event %1 ts=%2")
|
||||
.arg(type)
|
||||
.arg(irqBit)
|
||||
.arg(hex32(irqMask))
|
||||
.arg(static_cast<qulonglong>(timestampNs)));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
@@ -400,7 +413,8 @@ void MainWindow::captureReadLoop()
|
||||
const int width = frame.width;
|
||||
const int height = frame.height;
|
||||
const uint64_t frameId = frame.frame_id;
|
||||
previewRenderer_.render(frame);
|
||||
if (previewHandle_)
|
||||
gvfg_preview_render_frame(previewHandle_, &frame);
|
||||
gvfg_release_frame(handle_, &frame);
|
||||
|
||||
if (count <= 5 || (count % 60) == 0)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <gvfg_capture.h>
|
||||
|
||||
#include "sample_preview_renderer.h"
|
||||
#include <gvfg_preview.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
@@ -57,7 +56,7 @@ private:
|
||||
std::array<gvfg_device_info_t, GVFG_MAX_DEVICES> devices_{};
|
||||
int deviceCount_ = 0;
|
||||
gvfg_handle handle_ = nullptr;
|
||||
SamplePreviewRenderer previewRenderer_;
|
||||
gvfg_preview_handle previewHandle_ = nullptr;
|
||||
bool captureRunning_ = false;
|
||||
std::atomic<bool> captureStop_{false};
|
||||
std::thread captureThread_;
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
#include "sample_preview_renderer.h"
|
||||
|
||||
#include "gvfg_render_types.h"
|
||||
#include "shared_scene_pipeline.h"
|
||||
|
||||
#include <d3d11_4.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
struct SamplePreviewRenderer::D3DState
|
||||
{
|
||||
ComPtr<ID3D11Device> device;
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
};
|
||||
|
||||
SamplePreviewRenderer::SamplePreviewRenderer() = default;
|
||||
|
||||
SamplePreviewRenderer::~SamplePreviewRenderer()
|
||||
{
|
||||
shutdown();
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::configure(void *hwnd)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
hwnd_ = hwnd;
|
||||
configured_ = hwnd_ != nullptr;
|
||||
if (pipeline_)
|
||||
{
|
||||
gvfg::internal::gvfg_render_preview_desc_t desc{};
|
||||
desc.hwnd = hwnd_;
|
||||
desc.enable_preview = configured_ ? 1 : 0;
|
||||
desc.use_fp16_pipeline = 1;
|
||||
desc.swapchain_10bit = gvfg::internal::GVFG_RENDER_PREVIEW_BITDEPTH_AUTO;
|
||||
pipeline_->configurePreview(desc);
|
||||
}
|
||||
return configured_;
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::render(const gvfg_frame_t &frame)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!configured_ || !hwnd_ || !frame.data || frame.width <= 0 || frame.height <= 0)
|
||||
return false;
|
||||
|
||||
if (!ensureDevice() || !ensurePipeline(frame.width, frame.height, frame.bit_depth > 0 ? frame.bit_depth : 8))
|
||||
return false;
|
||||
|
||||
const auto *base = static_cast<const uint8_t *>(frame.data);
|
||||
gvfg::internal::gvfg_render_pixfmt_t renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
||||
bool uploaded = false;
|
||||
|
||||
switch (frame.pixel_format)
|
||||
{
|
||||
case GVFG_PIXFMT_YUY2:
|
||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
||||
uploaded = pipeline_->upload_yuy2_frame(base, frame.width * 2, frame.width, frame.height);
|
||||
break;
|
||||
case GVFG_PIXFMT_Y210:
|
||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_Y210;
|
||||
uploaded = pipeline_->upload_y210_frame(base, frame.width * 4, frame.width, frame.height);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!uploaded ||
|
||||
!pipeline_->render_uploaded_yuv_to_fp16(renderFmt, frame.width, frame.height) ||
|
||||
!pipeline_->copy_fp16_to_scene())
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
if (!pipeline_->preview_swapchain_10bit())
|
||||
ok = pipeline_->blit_fp16_to_rgba8(frame.width, frame.height);
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
pipeline_->present_preview(frame.width, frame.height);
|
||||
width_ = pipeline_->preview_w_;
|
||||
height_ = pipeline_->preview_h_;
|
||||
bitDepth_ = pipeline_->preview_swapchain_10bit() ? 10 : 8;
|
||||
swapchain10Bit_ = pipeline_->preview_swapchain_10bit();
|
||||
return true;
|
||||
}
|
||||
|
||||
void SamplePreviewRenderer::shutdown()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (pipeline_)
|
||||
pipeline_->release_preview_swapchain();
|
||||
pipeline_.reset();
|
||||
d3d_.reset();
|
||||
configured_ = false;
|
||||
hwnd_ = nullptr;
|
||||
width_ = 0;
|
||||
height_ = 0;
|
||||
bitDepth_ = 0;
|
||||
swapchain10Bit_ = false;
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::active() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return configured_ && pipeline_ && width_ > 0 && height_ > 0;
|
||||
}
|
||||
|
||||
int SamplePreviewRenderer::width() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return width_;
|
||||
}
|
||||
|
||||
int SamplePreviewRenderer::height() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return height_;
|
||||
}
|
||||
|
||||
int SamplePreviewRenderer::bitDepth() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return bitDepth_;
|
||||
}
|
||||
|
||||
const char *SamplePreviewRenderer::pixelFormat() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return swapchain10Bit_ ? "RGB10A2" : "BGRA8";
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::ensureDevice()
|
||||
{
|
||||
if (d3d_ && d3d_->device && d3d_->context)
|
||||
return true;
|
||||
|
||||
auto state = std::make_unique<D3DState>();
|
||||
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
||||
#ifdef _DEBUG
|
||||
flags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
D3D_FEATURE_LEVEL levels[] = {D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0};
|
||||
D3D_FEATURE_LEVEL got{};
|
||||
HRESULT hr = D3D11CreateDevice(nullptr,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
flags,
|
||||
levels,
|
||||
_countof(levels),
|
||||
D3D11_SDK_VERSION,
|
||||
&state->device,
|
||||
&got,
|
||||
&state->context);
|
||||
#ifdef _DEBUG
|
||||
if (FAILED(hr))
|
||||
{
|
||||
flags &= ~D3D11_CREATE_DEVICE_DEBUG;
|
||||
hr = D3D11CreateDevice(nullptr,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
flags,
|
||||
levels,
|
||||
_countof(levels),
|
||||
D3D11_SDK_VERSION,
|
||||
&state->device,
|
||||
&got,
|
||||
&state->context);
|
||||
}
|
||||
#endif
|
||||
if (FAILED(hr) || !state->device || !state->context)
|
||||
return false;
|
||||
|
||||
ComPtr<ID3D11Multithread> mt;
|
||||
if (SUCCEEDED(state->device.As(&mt)) && mt)
|
||||
mt->SetMultithreadProtected(TRUE);
|
||||
|
||||
d3d_ = std::move(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::ensurePipeline(int width, int height, int sourceBitDepth)
|
||||
{
|
||||
if (!pipeline_)
|
||||
pipeline_ = std::make_unique<gvfg::internal::SharedScenePipeline>();
|
||||
|
||||
if (!pipeline_->initialize(d3d_->device.Get(), d3d_->context.Get()))
|
||||
return false;
|
||||
|
||||
gvfg::internal::gvfg_render_preview_desc_t desc{};
|
||||
desc.hwnd = hwnd_;
|
||||
desc.enable_preview = configured_ ? 1 : 0;
|
||||
desc.use_fp16_pipeline = 1;
|
||||
desc.swapchain_10bit = gvfg::internal::GVFG_RENDER_PREVIEW_BITDEPTH_AUTO;
|
||||
pipeline_->configurePreview(desc);
|
||||
pipeline_->set_source_bit_depth(sourceBitDepth > 0 ? sourceBitDepth : 8);
|
||||
return pipeline_->ensure_rt_and_pipeline(width, height) &&
|
||||
pipeline_->ensure_preview_swapchain(width, height);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gvfg_capture.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
class SharedScenePipeline;
|
||||
}
|
||||
|
||||
class SamplePreviewRenderer
|
||||
{
|
||||
public:
|
||||
SamplePreviewRenderer();
|
||||
~SamplePreviewRenderer();
|
||||
|
||||
bool configure(void *hwnd);
|
||||
bool render(const gvfg_frame_t &frame);
|
||||
void shutdown();
|
||||
|
||||
bool active() const;
|
||||
int width() const;
|
||||
int height() const;
|
||||
int bitDepth() const;
|
||||
const char *pixelFormat() const;
|
||||
|
||||
private:
|
||||
bool ensureDevice();
|
||||
bool ensurePipeline(int width, int height, int sourceBitDepth);
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
void *hwnd_ = nullptr;
|
||||
bool configured_ = false;
|
||||
int width_ = 0;
|
||||
int height_ = 0;
|
||||
int bitDepth_ = 0;
|
||||
bool swapchain10Bit_ = false;
|
||||
|
||||
struct D3DState;
|
||||
std::unique_ptr<D3DState> d3d_;
|
||||
std::unique_ptr<gvfg::internal::SharedScenePipeline> pipeline_;
|
||||
};
|
||||
@@ -8,12 +8,12 @@ project(gvfg VERSION ${GVFG_SDK_VERSION} LANGUAGES CXX)
|
||||
|
||||
add_library(gvfg SHARED
|
||||
include/gvfg_capture.h
|
||||
include/gvfg_debug.h
|
||||
src/backend/xdma/xdma_backend_types.h
|
||||
src/backend/xdma/xdma_capture_session.cpp
|
||||
src/backend/xdma/xdma_capture_session.h
|
||||
src/backend/xdma/xdma_public.h
|
||||
src/gvfg_capture.cpp
|
||||
src/gvfg_log_bridge.cpp
|
||||
)
|
||||
|
||||
set_target_properties(gvfg PROPERTIES
|
||||
@@ -27,7 +27,6 @@ target_include_directories(gvfg
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/xdma
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/internal
|
||||
)
|
||||
|
||||
target_compile_definitions(gvfg PRIVATE
|
||||
|
||||
+15
-121
@@ -3,8 +3,8 @@
|
||||
/*
|
||||
* Customer-facing GVFG capture API.
|
||||
*
|
||||
* Include only this header in customer applications. Internal XDMA backend
|
||||
* headers are implementation details behind gvfg.dll.
|
||||
* Include only this header in customer applications. Driver/backend headers
|
||||
* are implementation details behind gvfg.dll.
|
||||
*
|
||||
* Minimal capture flow:
|
||||
*
|
||||
@@ -90,29 +90,13 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t width; /* Raw FPGA width value. */
|
||||
uint32_t height; /* Raw FPGA height value. */
|
||||
uint32_t video_format; /* Raw FPGA video-format value. */
|
||||
uint32_t frame_rate; /* Raw FPGA frame-rate value. */
|
||||
uint32_t bit_depth; /* Raw FPGA bit-depth value. */
|
||||
uint32_t status; /* Raw FPGA lock/status value. */
|
||||
} gvfg_fpga_signal_raw_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width; /* Signal width in pixels, from FPGA when available. */
|
||||
int height; /* Signal height in pixels, from FPGA when available. */
|
||||
int video_format_code; /* 0=yuv422, 1=rgb, 2=yuv444, 3=yuv420. */
|
||||
char video_format[16]; /* Decoded FPGA signal format name. */
|
||||
int frame_rate_code; /* FPGA frame-rate code. */
|
||||
char frame_rate_bits[5]; /* 4-bit binary text, for example "0110". */
|
||||
int width; /* Signal width in pixels when available. */
|
||||
int height; /* Signal height in pixels when available. */
|
||||
char video_format[16]; /* Decoded signal format name. */
|
||||
char frame_rate_name[16]; /* None, 23.98, 24, 47.95, ..., or "--" for unsupported codes. */
|
||||
int bit_depth; /* FPGA signal bit depth: 8 or 10 when valid. */
|
||||
int bit_depth; /* Signal bit depth: 8 or 10 when valid. */
|
||||
int sdi_locked; /* Non-zero when SDI reports locked. */
|
||||
int sdi_ddr_ok; /* Non-zero when SDI DDR status is OK. */
|
||||
int hdmi_locked; /* Non-zero when HDMI reports locked. */
|
||||
int hdmi_ddr_ok; /* Non-zero when HDMI DDR status is OK. */
|
||||
gvfg_fpga_signal_raw_t raw; /* Raw FPGA values for diagnostics; validity is handled by the SDK. */
|
||||
} gvfg_signal_status_t;
|
||||
|
||||
typedef struct
|
||||
@@ -122,12 +106,12 @@ typedef struct
|
||||
int bit_depth; /* Bits per color channel of the frame buffer. */
|
||||
char pixel_format[32]; /* Native frame buffer format, for example YUY2, Y210, NV12, or P010. */
|
||||
int valid; /* Non-zero while capture is running after at least one frame read. */
|
||||
} gvfg_callback_frame_info_t;
|
||||
} gvfg_last_frame_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gvfg_signal_status_t input_signal; /* FPGA-reported signal metadata. */
|
||||
gvfg_callback_frame_info_t callback_frame; /* Last frame returned by gvfg_read_frame(); name kept for ABI compatibility. */
|
||||
gvfg_signal_status_t input_signal; /* Decoded input signal metadata. */
|
||||
gvfg_last_frame_info_t last_frame; /* Last frame returned by gvfg_read_frame(). */
|
||||
double capture_fps; /* Runtime FPS measured from frames returned by gvfg_read_frame(). */
|
||||
uint64_t delivered_frames; /* Number of frames returned by gvfg_read_frame(). */
|
||||
} gvfg_runtime_info_t;
|
||||
@@ -145,48 +129,22 @@ typedef struct
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_EVENT_VIDEO_IRQ = 1,
|
||||
GVFG_EVENT_PLUG_IN = 2,
|
||||
GVFG_EVENT_PLUG_OUT = 3,
|
||||
GVFG_EVENT_CAPTURE_PAUSED = 4,
|
||||
GVFG_EVENT_CAPTURE_RESUMED = 5
|
||||
GVFG_EVENT_UNKNOWN = 0,
|
||||
GVFG_EVENT_PLUG_IN = 1,
|
||||
GVFG_EVENT_PLUG_OUT = 2,
|
||||
GVFG_EVENT_CAPTURE_PAUSED = 3,
|
||||
GVFG_EVENT_CAPTURE_RESUMED = 4
|
||||
} gvfg_event_type_t;
|
||||
|
||||
enum
|
||||
{
|
||||
GVFG_EVENT_MASK_VIDEO_IRQ = 1u << 0,
|
||||
GVFG_EVENT_MASK_PLUG_IN = 1u << 1,
|
||||
GVFG_EVENT_MASK_PLUG_OUT = 1u << 2,
|
||||
GVFG_EVENT_MASK_CAPTURE_PAUSED = 1u << 3,
|
||||
GVFG_EVENT_MASK_CAPTURE_RESUMED = 1u << 4,
|
||||
GVFG_EVENT_MASK_HOTPLUG = GVFG_EVENT_MASK_PLUG_IN |
|
||||
GVFG_EVENT_MASK_PLUG_OUT |
|
||||
GVFG_EVENT_MASK_CAPTURE_PAUSED |
|
||||
GVFG_EVENT_MASK_CAPTURE_RESUMED,
|
||||
GVFG_EVENT_MASK_DEFAULT = GVFG_EVENT_MASK_HOTPLUG,
|
||||
GVFG_EVENT_MASK_ALL = GVFG_EVENT_MASK_VIDEO_IRQ | GVFG_EVENT_MASK_HOTPLUG
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gvfg_event_type_t type;
|
||||
uint32_t irq_bit;
|
||||
uint32_t irq_mask;
|
||||
uint64_t timestamp_ns;
|
||||
} gvfg_event_t;
|
||||
|
||||
/* Opaque session handle created by gvfg_create() and released by gvfg_destroy(). */
|
||||
typedef struct gvfg_handle_t *gvfg_handle;
|
||||
|
||||
/* Legacy callback type kept for source compatibility. */
|
||||
typedef void (*gvfg_on_frame_cb)(const gvfg_frame_t *frame, void *user);
|
||||
|
||||
/* Called for capture events such as PLUG_IN / PLUG_OUT. */
|
||||
typedef void (*gvfg_on_event_cb)(const gvfg_event_t *event, void *user);
|
||||
|
||||
/* Called for asynchronous SDK messages or errors. */
|
||||
typedef void (*gvfg_on_error_cb)(gvfg_status_t status, const char *message, void *user);
|
||||
|
||||
/*
|
||||
* Enumerate GVFG capture devices.
|
||||
*
|
||||
@@ -233,69 +191,6 @@ GVFG_API gvfg_status_t gvfg_create(gvfg_handle *out_handle);
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_destroy(gvfg_handle handle);
|
||||
|
||||
/*
|
||||
* Register legacy frame and error callbacks.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - on_frame: Reserved for the legacy callback path. The pull-based
|
||||
* gvfg_read_frame() API is the primary frame API.
|
||||
* - on_error: Function called for asynchronous SDK messages/errors. Pass NULL
|
||||
* if error callbacks are not needed.
|
||||
* - user: Application-defined pointer passed back to both callbacks.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* New applications should use gvfg_read_frame() and gvfg_release_frame()
|
||||
* instead of frame callbacks.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_callbacks(gvfg_handle handle,
|
||||
gvfg_on_frame_cb on_frame,
|
||||
gvfg_on_error_cb on_error,
|
||||
void *user);
|
||||
|
||||
/*
|
||||
* Configure frame callback rate.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - frame_interval: 0 or 1 calls on_frame for every delivered frame. N > 1
|
||||
* calls on_frame once for every N delivered backend frames.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* This setting is kept for source compatibility with the legacy callback API.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_frame_callback_interval(gvfg_handle handle,
|
||||
uint32_t frame_interval);
|
||||
|
||||
/*
|
||||
* Register legacy capture event callback.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - on_event: Function called when an enabled capture event occurs. Pass NULL
|
||||
* to disable event callbacks. New applications should use gvfg_poll_event().
|
||||
* - user: Application-defined pointer passed back to the callback.
|
||||
* - event_mask: GVFG_EVENT_MASK_* bits. Pass 0 to use GVFG_EVENT_MASK_DEFAULT.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* VIDEO_IRQ is not included in the default mask because it can occur once per
|
||||
* video frame. Enable GVFG_EVENT_MASK_VIDEO_IRQ only for debug or when the
|
||||
* application explicitly needs it.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_event_callback(gvfg_handle handle,
|
||||
gvfg_on_event_cb on_event,
|
||||
void *user,
|
||||
uint32_t event_mask);
|
||||
|
||||
/*
|
||||
* Open a device by index from gvfg_enumerate_devices().
|
||||
*
|
||||
@@ -412,8 +307,7 @@ GVFG_API gvfg_status_t gvfg_stop(gvfg_handle handle);
|
||||
* - GVFG_EINVAL if handle or out_status is NULL.
|
||||
* - GVFG_ENODEV if no valid signal information is available.
|
||||
*
|
||||
* The FPGA metadata describes the hardware signal. Use
|
||||
* gvfg_runtime_info_t::callback_frame for the callback buffer format.
|
||||
* Use gvfg_runtime_info_t::last_frame for the frame buffer format.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_signal_status(gvfg_handle handle, gvfg_signal_status_t *out_status);
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Internal GVFG debug API.
|
||||
*
|
||||
* Do not ship this header in customer/demo packages. It is intended for
|
||||
* internal driver, FPGA, hardware bring-up, and diagnostic tools.
|
||||
*/
|
||||
|
||||
#include "gvfg_capture.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sdk_running;
|
||||
int frame_held;
|
||||
uint32_t event_queue_depth;
|
||||
|
||||
double runtime_fps;
|
||||
uint64_t frames_returned;
|
||||
int last_frame_width;
|
||||
int last_frame_height;
|
||||
int last_frame_pixel_format;
|
||||
int last_frame_bit_depth;
|
||||
|
||||
int backend_state;
|
||||
uint64_t backend_frames_captured;
|
||||
uint64_t backend_frames_delivered;
|
||||
uint64_t backend_frames_dropped;
|
||||
uint64_t backend_dma_errors;
|
||||
uint64_t backend_interrupt_count;
|
||||
uint64_t backend_wait_timeouts;
|
||||
} gvfg_debug_backend_stats_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t valid_mask;
|
||||
uint32_t width_valid;
|
||||
uint32_t height_valid;
|
||||
uint32_t width_raw;
|
||||
uint32_t height_raw;
|
||||
uint32_t video_format_raw;
|
||||
uint32_t frame_rate_raw;
|
||||
uint32_t bit_depth_raw;
|
||||
uint32_t status_raw;
|
||||
} gvfg_debug_fpga_signal_raw_t;
|
||||
|
||||
/*
|
||||
* Query driver-neutral internal backend counters.
|
||||
*
|
||||
* This exposes implementation-level counters for internal tools only. Customer
|
||||
* applications should use gvfg_get_runtime_info() instead.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_debug_get_backend_stats(gvfg_handle handle,
|
||||
gvfg_debug_backend_stats_t *out_stats);
|
||||
|
||||
/*
|
||||
* Query raw FPGA signal values for internal hardware/FPGA debugging.
|
||||
*
|
||||
* These values are intentionally excluded from gvfg_capture.h.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_debug_get_fpga_signal_raw(gvfg_handle handle,
|
||||
gvfg_debug_fpga_signal_raw_t *out_raw);
|
||||
|
||||
/*
|
||||
* Copy the latest backend error detail into out_message.
|
||||
*
|
||||
* The message is UTF-8 and null-terminated when out_message_size is non-zero.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_debug_get_last_error_detail(gvfg_handle handle,
|
||||
char *out_message,
|
||||
uint32_t out_message_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1679,6 +1679,13 @@ namespace gvfg::internal
|
||||
return last_error_.c_str();
|
||||
}
|
||||
|
||||
void XdmaCaptureSession::get_debug_stats(xdma_stream_stats_t &outStats, uint64_t &outWaitTimeouts) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
outStats = stats_;
|
||||
outWaitTimeouts = wait_timeout_count_;
|
||||
}
|
||||
|
||||
uint32_t XdmaCaptureSession::active_input_path() const
|
||||
{
|
||||
return stream_desc_.input == XDMA_INPUT_HDMI ? 1u : 0u;
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace gvfg::internal
|
||||
xdma_status_t release_frame(const xdma_frame_t &frame);
|
||||
|
||||
const char *last_error() const;
|
||||
void get_debug_stats(xdma_stream_stats_t &outStats, uint64_t &outWaitTimeouts) const;
|
||||
|
||||
private:
|
||||
xdma_status_t open_device(const XdmaDevice &device);
|
||||
|
||||
+113
-115
@@ -1,5 +1,6 @@
|
||||
#include "gvfg_capture.h"
|
||||
|
||||
#include "gvfg_debug.h"
|
||||
#include "xdma_capture_session.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -101,8 +102,6 @@ namespace
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case XDMA_EVENT_VIDEO_IRQ:
|
||||
return GVFG_EVENT_VIDEO_IRQ;
|
||||
case XDMA_EVENT_PLUG_IN:
|
||||
return GVFG_EVENT_PLUG_IN;
|
||||
case XDMA_EVENT_PLUG_OUT:
|
||||
@@ -112,27 +111,10 @@ namespace
|
||||
case XDMA_EVENT_CAPTURE_RESUMED:
|
||||
return GVFG_EVENT_CAPTURE_RESUMED;
|
||||
default:
|
||||
return GVFG_EVENT_VIDEO_IRQ;
|
||||
return GVFG_EVENT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t map_event_mask_to_xdma(uint32_t mask)
|
||||
{
|
||||
const uint32_t effective = mask ? mask : GVFG_EVENT_MASK_DEFAULT;
|
||||
uint32_t out = 0;
|
||||
if (effective & GVFG_EVENT_MASK_VIDEO_IRQ)
|
||||
out |= XDMA_EVENT_MASK_VIDEO_IRQ;
|
||||
if (effective & GVFG_EVENT_MASK_PLUG_IN)
|
||||
out |= XDMA_EVENT_MASK_PLUG_IN;
|
||||
if (effective & GVFG_EVENT_MASK_PLUG_OUT)
|
||||
out |= XDMA_EVENT_MASK_PLUG_OUT;
|
||||
if (effective & GVFG_EVENT_MASK_CAPTURE_PAUSED)
|
||||
out |= XDMA_EVENT_MASK_CAPTURE_PAUSED;
|
||||
if (effective & GVFG_EVENT_MASK_CAPTURE_RESUMED)
|
||||
out |= XDMA_EVENT_MASK_CAPTURE_RESUMED;
|
||||
return out ? out : XDMA_EVENT_MASK_DEFAULT;
|
||||
}
|
||||
|
||||
bool fpga_field_valid(uint32_t mask, int bit)
|
||||
{
|
||||
return (mask & (1u << bit)) != 0;
|
||||
@@ -238,18 +220,6 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void copy_binary4(char *dst, size_t dstSize, uint32_t value)
|
||||
{
|
||||
if (!dst || dstSize == 0)
|
||||
return;
|
||||
const uint32_t code = value & 0x0fu;
|
||||
char bits[5] = {};
|
||||
for (int i = 0; i < 4; ++i)
|
||||
bits[i] = (code & (1u << (3 - i))) ? '1' : '0';
|
||||
bits[4] = '\0';
|
||||
copy_cstr(dst, dstSize, bits);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct gvfg_handle_t
|
||||
@@ -270,7 +240,7 @@ struct gvfg_handle_t
|
||||
const xdma_status_t stOpen = backend->open_device_index(static_cast<size_t>(index));
|
||||
if (stOpen != XDMA_OK)
|
||||
{
|
||||
emitError(map_status(stOpen), xdma_error_text(stOpen, backend.get()));
|
||||
recordError(xdma_error_text(stOpen, backend.get()));
|
||||
backend.reset();
|
||||
return map_status(stOpen);
|
||||
}
|
||||
@@ -282,7 +252,7 @@ struct gvfg_handle_t
|
||||
const xdma_status_t stInput = backend->set_input(selectedInput);
|
||||
if (stInput != XDMA_OK)
|
||||
{
|
||||
emitError(map_status(stInput), xdma_error_text(stInput, backend.get()));
|
||||
recordError(xdma_error_text(stInput, backend.get()));
|
||||
close();
|
||||
return map_status(stInput);
|
||||
}
|
||||
@@ -306,7 +276,7 @@ struct gvfg_handle_t
|
||||
const xdma_status_t st = backend->start_stream();
|
||||
if (st != XDMA_OK)
|
||||
{
|
||||
emitError(map_status(st), xdma_error_text(st, backend.get()));
|
||||
recordError(xdma_error_text(st, backend.get()));
|
||||
return map_status(st);
|
||||
}
|
||||
|
||||
@@ -335,15 +305,6 @@ struct gvfg_handle_t
|
||||
currentIndex = -1;
|
||||
}
|
||||
|
||||
gvfg_status_t setEventCallback(gvfg_on_event_cb callback, void *user, uint32_t mask)
|
||||
{
|
||||
onEvent = callback;
|
||||
eventCallbackUser = user;
|
||||
eventMask = mask ? mask : GVFG_EVENT_MASK_DEFAULT;
|
||||
syncBackendEventCallback();
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t getSignalStatus(gvfg_signal_status_t &out)
|
||||
{
|
||||
std::memset(&out, 0, sizeof(out));
|
||||
@@ -358,29 +319,15 @@ struct gvfg_handle_t
|
||||
const bool statusValid = fpga_field_valid(fpgaValidMask, 3);
|
||||
out.width = haveSignalSize ? static_cast<int>(fpgaWidthRaw) : 0;
|
||||
out.height = haveSignalSize ? static_cast<int>(fpgaHeightRaw) : 0;
|
||||
out.video_format_code = videoFormatValid ? static_cast<int>(fpgaVideoFormatRaw & 0x3u) : -1;
|
||||
copy_cstr(out.video_format,
|
||||
sizeof(out.video_format),
|
||||
videoFormatValid ? fpga_video_format_name(fpgaVideoFormatRaw) : "--");
|
||||
out.frame_rate_code = frameRateValid ? static_cast<int>(fpgaFrameRateRaw & 0x0fu) : -1;
|
||||
if (frameRateValid)
|
||||
copy_binary4(out.frame_rate_bits, sizeof(out.frame_rate_bits), fpgaFrameRateRaw);
|
||||
else
|
||||
copy_cstr(out.frame_rate_bits, sizeof(out.frame_rate_bits), "--");
|
||||
copy_cstr(out.frame_rate_name,
|
||||
sizeof(out.frame_rate_name),
|
||||
frameRateValid ? fpga_frame_rate_name(fpgaFrameRateRaw) : "--");
|
||||
out.bit_depth = bitDepthValid ? static_cast<int>(fpgaBitDepthRaw) : 0;
|
||||
out.sdi_locked = statusValid && (fpgaStatusRaw & (1u << 0)) ? 1 : 0;
|
||||
out.sdi_ddr_ok = statusValid && (fpgaStatusRaw & (1u << 1)) ? 1 : 0;
|
||||
out.hdmi_locked = statusValid && (fpgaStatusRaw & (1u << 2)) ? 1 : 0;
|
||||
out.hdmi_ddr_ok = statusValid && (fpgaStatusRaw & (1u << 3)) ? 1 : 0;
|
||||
out.raw.width = fpgaWidthRaw;
|
||||
out.raw.height = fpgaHeightRaw;
|
||||
out.raw.video_format = fpgaVideoFormatRaw;
|
||||
out.raw.frame_rate = fpgaFrameRateRaw;
|
||||
out.raw.bit_depth = fpgaBitDepthRaw;
|
||||
out.raw.status = fpgaStatusRaw;
|
||||
}
|
||||
return haveSignalSize ? GVFG_OK : GVFG_ENODEV;
|
||||
}
|
||||
@@ -392,14 +339,14 @@ struct gvfg_handle_t
|
||||
const uint64_t frames = deliveredFrames.load(std::memory_order_relaxed);
|
||||
const bool deliveredValid = running.load(std::memory_order_relaxed) && frames > 0;
|
||||
|
||||
out.callback_frame.valid = deliveredValid ? 1 : 0;
|
||||
out.last_frame.valid = deliveredValid ? 1 : 0;
|
||||
if (deliveredValid)
|
||||
{
|
||||
out.callback_frame.width = static_cast<int>(deliveredWidth.load(std::memory_order_relaxed));
|
||||
out.callback_frame.height = static_cast<int>(deliveredHeight.load(std::memory_order_relaxed));
|
||||
out.callback_frame.bit_depth = static_cast<int>(deliveredBitDepth.load(std::memory_order_relaxed));
|
||||
copy_cstr(out.callback_frame.pixel_format,
|
||||
sizeof(out.callback_frame.pixel_format),
|
||||
out.last_frame.width = static_cast<int>(deliveredWidth.load(std::memory_order_relaxed));
|
||||
out.last_frame.height = static_cast<int>(deliveredHeight.load(std::memory_order_relaxed));
|
||||
out.last_frame.bit_depth = static_cast<int>(deliveredBitDepth.load(std::memory_order_relaxed));
|
||||
copy_cstr(out.last_frame.pixel_format,
|
||||
sizeof(out.last_frame.pixel_format),
|
||||
gvfg_pixel_format_name(deliveredPixelFormat.load(std::memory_order_relaxed)));
|
||||
}
|
||||
out.capture_fps = runtimeFps.load(std::memory_order_relaxed);
|
||||
@@ -413,7 +360,7 @@ struct gvfg_handle_t
|
||||
return;
|
||||
backend->set_event_callback(&gvfg_handle_t::onBackendEvent,
|
||||
this,
|
||||
map_event_mask_to_xdma(eventMask));
|
||||
XDMA_EVENT_MASK_DEFAULT);
|
||||
}
|
||||
|
||||
static void onBackendEvent(const xdma_event_t *event, void *user)
|
||||
@@ -428,8 +375,6 @@ struct gvfg_handle_t
|
||||
{
|
||||
gvfg_event_t out{};
|
||||
out.type = map_event_type(event.type);
|
||||
out.irq_bit = event.irq_bit;
|
||||
out.irq_mask = event.irq_mask;
|
||||
out.timestamp_ns = event.timestamp_ns;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(eventMutex);
|
||||
@@ -439,8 +384,6 @@ struct gvfg_handle_t
|
||||
}
|
||||
eventCv.notify_one();
|
||||
|
||||
if (onEvent)
|
||||
onEvent(&out, eventCallbackUser);
|
||||
}
|
||||
|
||||
void querySignal()
|
||||
@@ -507,7 +450,7 @@ struct gvfg_handle_t
|
||||
sdiDdrOk ? 1 : 0,
|
||||
hdmiLocked ? 1 : 0,
|
||||
hdmiDdrOk ? 1 : 0);
|
||||
emitError(GVFG_ENODEV, msg);
|
||||
recordError(msg);
|
||||
return GVFG_ENODEV;
|
||||
}
|
||||
|
||||
@@ -522,7 +465,7 @@ struct gvfg_handle_t
|
||||
fpgaWidthRaw,
|
||||
fpgaHeightValid ? 1 : 0,
|
||||
fpgaHeightRaw);
|
||||
emitError(GVFG_ENODEV, msg);
|
||||
recordError(msg);
|
||||
return GVFG_ENODEV;
|
||||
}
|
||||
|
||||
@@ -554,7 +497,7 @@ struct gvfg_handle_t
|
||||
const xdma_status_t st = backend->configure_stream(desc);
|
||||
if (st != XDMA_OK)
|
||||
{
|
||||
emitError(map_status(st), xdma_error_text(st, backend.get()));
|
||||
recordError(xdma_error_text(st, backend.get()));
|
||||
return map_status(st);
|
||||
}
|
||||
return GVFG_OK;
|
||||
@@ -582,7 +525,7 @@ struct gvfg_handle_t
|
||||
readInProgress = false;
|
||||
}
|
||||
if (st != XDMA_ETIMEOUT && st != XDMA_ESTATE)
|
||||
emitError(map_status(st), xdma_error_text(st, backend.get()));
|
||||
recordError(xdma_error_text(st, backend.get()));
|
||||
return map_status(st);
|
||||
}
|
||||
|
||||
@@ -675,10 +618,78 @@ struct gvfg_handle_t
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
void emitError(gvfg_status_t code, const char *msg)
|
||||
gvfg_status_t getDebugBackendStats(gvfg_debug_backend_stats_t &out)
|
||||
{
|
||||
if (onError)
|
||||
onError(code, msg ? msg : "", callbackUser);
|
||||
std::memset(&out, 0, sizeof(out));
|
||||
out.sdk_running = running.load(std::memory_order_relaxed) ? 1 : 0;
|
||||
out.runtime_fps = runtimeFps.load(std::memory_order_relaxed);
|
||||
out.frames_returned = deliveredFrames.load(std::memory_order_relaxed);
|
||||
out.last_frame_width = static_cast<int>(deliveredWidth.load(std::memory_order_relaxed));
|
||||
out.last_frame_height = static_cast<int>(deliveredHeight.load(std::memory_order_relaxed));
|
||||
out.last_frame_pixel_format = deliveredPixelFormat.load(std::memory_order_relaxed);
|
||||
out.last_frame_bit_depth = static_cast<int>(deliveredBitDepth.load(std::memory_order_relaxed));
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(frameMutex);
|
||||
out.frame_held = frameHeld ? 1 : 0;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(eventMutex);
|
||||
out.event_queue_depth = static_cast<uint32_t>(eventQueue.size());
|
||||
}
|
||||
|
||||
if (backend)
|
||||
{
|
||||
xdma_stream_stats_t stats{};
|
||||
uint64_t waitTimeouts = 0;
|
||||
backend->get_debug_stats(stats, waitTimeouts);
|
||||
out.backend_state = static_cast<int>(stats.state);
|
||||
out.backend_frames_captured = stats.frames_captured;
|
||||
out.backend_frames_delivered = stats.frames_delivered;
|
||||
out.backend_frames_dropped = stats.frames_dropped;
|
||||
out.backend_dma_errors = stats.dma_errors;
|
||||
out.backend_interrupt_count = stats.interrupt_count;
|
||||
out.backend_wait_timeouts = waitTimeouts;
|
||||
}
|
||||
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t getDebugFpgaSignalRaw(gvfg_debug_fpga_signal_raw_t &out)
|
||||
{
|
||||
if (!backend)
|
||||
return GVFG_ESTATE;
|
||||
|
||||
querySignal();
|
||||
std::lock_guard<std::mutex> lock(stateMutex);
|
||||
std::memset(&out, 0, sizeof(out));
|
||||
out.valid_mask = fpgaValidMask;
|
||||
out.width_valid = fpgaWidthValid ? 1u : 0u;
|
||||
out.height_valid = fpgaHeightValid ? 1u : 0u;
|
||||
out.width_raw = fpgaWidthRaw;
|
||||
out.height_raw = fpgaHeightRaw;
|
||||
out.video_format_raw = fpgaVideoFormatRaw;
|
||||
out.frame_rate_raw = fpgaFrameRateRaw;
|
||||
out.bit_depth_raw = fpgaBitDepthRaw;
|
||||
out.status_raw = fpgaStatusRaw;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t getLastErrorDetail(char *outMessage, uint32_t outMessageSize)
|
||||
{
|
||||
if (!outMessage || outMessageSize == 0)
|
||||
return GVFG_EINVAL;
|
||||
outMessage[0] = '\0';
|
||||
if (!lastError.empty())
|
||||
copy_cstr(outMessage, outMessageSize, lastError.c_str());
|
||||
else
|
||||
copy_cstr(outMessage, outMessageSize, backend ? backend->last_error() : "");
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
void recordError(const char *msg)
|
||||
{
|
||||
lastError = msg ? msg : "";
|
||||
}
|
||||
|
||||
void updateRuntimeFps(uint64_t ptsNs)
|
||||
@@ -742,13 +753,7 @@ struct gvfg_handle_t
|
||||
std::atomic<int> deliveredPixelFormat{GVFG_PIXFMT_UNKNOWN};
|
||||
std::atomic<double> runtimeFps{0.0};
|
||||
|
||||
gvfg_on_frame_cb onFrame = nullptr;
|
||||
gvfg_on_error_cb onError = nullptr;
|
||||
void *callbackUser = nullptr;
|
||||
std::atomic<uint32_t> callbackFrameInterval{1};
|
||||
gvfg_on_event_cb onEvent = nullptr;
|
||||
void *eventCallbackUser = nullptr;
|
||||
uint32_t eventMask = GVFG_EVENT_MASK_DEFAULT;
|
||||
std::string lastError;
|
||||
|
||||
std::atomic<bool> running{false};
|
||||
std::mutex frameMutex;
|
||||
@@ -804,38 +809,6 @@ extern "C"
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_callbacks(gvfg_handle handle,
|
||||
gvfg_on_frame_cb on_frame,
|
||||
gvfg_on_error_cb on_error,
|
||||
void *user)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
handle->onFrame = on_frame;
|
||||
handle->onError = on_error;
|
||||
handle->callbackUser = user;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_frame_callback_interval(gvfg_handle handle, uint32_t frame_interval)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
handle->callbackFrameInterval.store(frame_interval <= 1 ? 1u : frame_interval,
|
||||
std::memory_order_relaxed);
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_event_callback(gvfg_handle handle,
|
||||
gvfg_on_event_cb on_event,
|
||||
void *user,
|
||||
uint32_t event_mask)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->setEventCallback(on_event, user, event_mask);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_open(gvfg_handle handle, int device_index)
|
||||
{
|
||||
if (!handle)
|
||||
@@ -914,6 +887,31 @@ extern "C"
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_get_backend_stats(gvfg_handle handle,
|
||||
gvfg_debug_backend_stats_t *out_stats)
|
||||
{
|
||||
if (!handle || !out_stats)
|
||||
return GVFG_EINVAL;
|
||||
return handle->getDebugBackendStats(*out_stats);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_get_fpga_signal_raw(gvfg_handle handle,
|
||||
gvfg_debug_fpga_signal_raw_t *out_raw)
|
||||
{
|
||||
if (!handle || !out_raw)
|
||||
return GVFG_EINVAL;
|
||||
return handle->getDebugFpgaSignalRaw(*out_raw);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_get_last_error_detail(gvfg_handle handle,
|
||||
char *out_message,
|
||||
uint32_t out_message_size)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->getLastErrorDetail(out_message, out_message_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#include "gvfg_logging.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
void log_message(gvfg_log_level_t, const char *message_utf8)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const char *msg = message_utf8 ? message_utf8 : "";
|
||||
OutputDebugStringA(msg);
|
||||
const size_t len = std::strlen(msg);
|
||||
if (len == 0 || msg[len - 1] != '\n')
|
||||
OutputDebugStringA("\n");
|
||||
#else
|
||||
(void)message_utf8;
|
||||
#endif
|
||||
}
|
||||
|
||||
void log_message_w(gvfg_log_level_t level, const wchar_t *message_wide)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!message_wide)
|
||||
{
|
||||
log_message(level, "");
|
||||
return;
|
||||
}
|
||||
const int needed = WideCharToMultiByte(CP_UTF8, 0, message_wide, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (needed <= 0)
|
||||
return;
|
||||
std::string utf8(static_cast<size_t>(needed - 1), '\0');
|
||||
WideCharToMultiByte(CP_UTF8, 0, message_wide, -1, utf8.data(), needed, nullptr, nullptr);
|
||||
log_message(level, utf8.c_str());
|
||||
#else
|
||||
(void)level;
|
||||
(void)message_wide;
|
||||
#endif
|
||||
}
|
||||
|
||||
void log_printf(gvfg_log_level_t level, const char *fmt, ...)
|
||||
{
|
||||
if (!fmt)
|
||||
{
|
||||
log_message(level, "");
|
||||
return;
|
||||
}
|
||||
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
std::vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
log_message(level, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdarg>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
typedef enum
|
||||
{
|
||||
GVFG_LOG_TRACE = 0,
|
||||
GVFG_LOG_DEBUG = 1,
|
||||
GVFG_LOG_INFO = 2,
|
||||
GVFG_LOG_WARN = 3,
|
||||
GVFG_LOG_ERROR = 4
|
||||
} gvfg_log_level_t;
|
||||
|
||||
void log_message(gvfg_log_level_t level, const char *message_utf8);
|
||||
void log_message_w(gvfg_log_level_t level, const wchar_t *message_wide);
|
||||
void log_printf(gvfg_log_level_t level, const char *fmt, ...);
|
||||
}
|
||||
|
||||
inline void gvfg_log_trace(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_TRACE, message_utf8); }
|
||||
inline void gvfg_log_debug(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_DEBUG, message_utf8); }
|
||||
inline void gvfg_log_info(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_INFO, message_utf8); }
|
||||
inline void gvfg_log_warn(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_WARN, message_utf8); }
|
||||
inline void gvfg_log_error(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_ERROR, message_utf8); }
|
||||
inline void gvfg_log_debug_w(const wchar_t *message_wide) { gvfg::internal::log_message_w(gvfg::internal::GVFG_LOG_DEBUG, message_wide); }
|
||||
@@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
typedef enum
|
||||
{
|
||||
GVFG_RENDER_FMT_NV12,
|
||||
GVFG_RENDER_FMT_YUY2,
|
||||
GVFG_RENDER_FMT_ARGB,
|
||||
GVFG_RENDER_FMT_P010,
|
||||
GVFG_RENDER_FMT_Y210
|
||||
} gvfg_render_pixfmt_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const void *data[3];
|
||||
int stride[3];
|
||||
int plane_count;
|
||||
int width;
|
||||
int height;
|
||||
gvfg_render_pixfmt_t format;
|
||||
uint64_t pts_ns;
|
||||
uint64_t frame_id;
|
||||
} gvfg_render_frame_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_8BIT = 0,
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_10BIT = 1,
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_AUTO = 2
|
||||
} gvfg_render_preview_bitdepth_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *hwnd;
|
||||
int enable_preview;
|
||||
int use_fp16_pipeline;
|
||||
int swapchain_10bit;
|
||||
} gvfg_render_preview_desc_t;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user