Simplify GVFG API and frame diagnostics
This commit is contained in:
@@ -461,7 +461,6 @@ void MainWindow::init()
|
|||||||
const uint64_t frameSize =
|
const uint64_t frameSize =
|
||||||
(uint64_t)video_width * 4u * (uint64_t)video_height;
|
(uint64_t)video_width * 4u * (uint64_t)video_height;
|
||||||
gvfg_preview_frame_t frame{};
|
gvfg_preview_frame_t frame{};
|
||||||
frame.struct_size = sizeof(frame);
|
|
||||||
frame.data = data;
|
frame.data = data;
|
||||||
frame.data_size = frameSize;
|
frame.data_size = frameSize;
|
||||||
frame.width = video_width;
|
frame.width = video_width;
|
||||||
|
|||||||
@@ -461,7 +461,6 @@ void MainWindow::init()
|
|||||||
const uint64_t frameSize =
|
const uint64_t frameSize =
|
||||||
(uint64_t)video_width * 4u * (uint64_t)video_height;
|
(uint64_t)video_width * 4u * (uint64_t)video_height;
|
||||||
gvfg_preview_frame_t frame{};
|
gvfg_preview_frame_t frame{};
|
||||||
frame.struct_size = sizeof(frame);
|
|
||||||
frame.data = data;
|
frame.data = data;
|
||||||
frame.data_size = frameSize;
|
frame.data_size = frameSize;
|
||||||
frame.width = video_width;
|
frame.width = video_width;
|
||||||
|
|||||||
-1
@@ -37,7 +37,6 @@ extern "C"
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t struct_size; /* Set to sizeof(gvfg_preview_frame_t). */
|
|
||||||
const void *data;
|
const void *data;
|
||||||
uint64_t data_size;
|
uint64_t data_size;
|
||||||
int width;
|
int width;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<mxfile host="Electron">
|
<mxfile host="Electron" modified="2026-07-30T00:00:00.000Z">
|
||||||
<diagram id="gvfg-architecture-overview" name="Architecture Overview">
|
<diagram id="gvfg-architecture-overview" name="Architecture Overview">
|
||||||
<mxGraphModel dx="1230" dy="1558" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1280" pageHeight="820" math="0" shadow="0">
|
<mxGraphModel dx="1230" dy="1558" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1280" pageHeight="820" math="0" shadow="0">
|
||||||
<root>
|
<root>
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
<mxCell id="backendTypes" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="pcies2mm_backend_types.h<br>internal frame/event/status types" vertex="1">
|
<mxCell id="backendTypes" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="pcies2mm_backend_types.h<br>internal frame/event/status types" vertex="1">
|
||||||
<mxGeometry height="58" width="285" x="30" y="95" as="geometry" />
|
<mxGeometry height="58" width="285" x="30" y="95" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="workers" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="single driver event + DMA worker<br>publish frames and events" vertex="1">
|
<mxCell id="workers" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="single capture thread<br>WaitForMultipleObjects: DMA / format / plug events" vertex="1">
|
||||||
<mxGeometry height="52" width="280" x="510" y="173" as="geometry" />
|
<mxGeometry height="52" width="280" x="510" y="173" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="pcies2mmSession" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.cpp<br>internal session / workers / frame ring" vertex="1">
|
<mxCell id="pcies2mmSession" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.cpp<br>internal session / workers / frame ring" vertex="1">
|
||||||
@@ -56,6 +56,9 @@
|
|||||||
<mxCell id="ring" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="frame_ring_<br>ready / in_use / sequence" vertex="1">
|
<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">
|
||||||
<mxGeometry height="58" width="270" x="880" y="610" as="geometry" />
|
<mxGeometry height="58" width="270" x="880" y="610" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
|
<mxCell id="eventFlow" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=13;" value="Public event flow<br>driver format IRQ -> FORMAT_CHANGE_BEGIN<br>first new frame published -> STREAM_READY" vertex="1">
|
||||||
|
<mxGeometry height="82" width="330" x="850" y="690" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
<mxCell id="externalBoundary" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#f5f5f5;strokeColor=#666666;dashed=1;fontColor=#333333;fontSize=14;" value="External frame/event source" vertex="1">
|
<mxCell id="externalBoundary" parent="1" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#f5f5f5;strokeColor=#666666;dashed=1;fontColor=#333333;fontSize=14;" value="External frame/event source" vertex="1">
|
||||||
<mxGeometry height="52" width="280" x="410" y="900" as="geometry" />
|
<mxGeometry height="52" width="280" x="410" y="900" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
@@ -74,6 +77,9 @@
|
|||||||
<mxCell id="e8" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="ring" value="">
|
<mxCell id="e8" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="ring" value="">
|
||||||
<mxGeometry relative="1" as="geometry" />
|
<mxGeometry relative="1" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
|
<mxCell id="e11" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="eventFlow" value="callback / queue">
|
||||||
|
<mxGeometry relative="1" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
<mxCell id="e9" edge="1" parent="1" source="pcies2mmSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="facade" value="frames / events / status">
|
<mxCell id="e9" edge="1" parent="1" source="pcies2mmSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="facade" value="frames / events / status">
|
||||||
<mxGeometry relative="1" as="geometry">
|
<mxGeometry relative="1" as="geometry">
|
||||||
<Array as="points">
|
<Array as="points">
|
||||||
|
|||||||
@@ -108,12 +108,10 @@ Customer-readable input signal status:
|
|||||||
新 driver 未提供 frame-rate、SDI/HDMI lock、DDR status 或舊 FPGA validity
|
新 driver 未提供 frame-rate、SDI/HDMI lock、DDR status 或舊 FPGA validity
|
||||||
register,因此 SDK 不再合成或公開這些欄位。
|
register,因此 SDK 不再合成或公開這些欄位。
|
||||||
|
|
||||||
這是可擴充的 query output,呼叫前必須設定 `struct_size`。沒有 input signal 是正常
|
沒有 input signal 是正常狀態:API 回傳 `GVFG_OK`,同時 `connected == 0`。
|
||||||
狀態:API 回傳 `GVFG_OK`,同時 `connected == 0`。
|
|
||||||
|
|
||||||
```c
|
```c
|
||||||
gvfg_signal_status_t signal = {};
|
gvfg_signal_status_t signal = {};
|
||||||
signal.struct_size = sizeof(signal);
|
|
||||||
gvfg_get_signal_status(h, &signal);
|
gvfg_get_signal_status(h, &signal);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -145,7 +143,6 @@ Memory layout、color metadata 與 timestamp metadata 不會繼續塞進這個 s
|
|||||||
```c
|
```c
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t struct_size;
|
|
||||||
int plane_count;
|
int plane_count;
|
||||||
const void *plane_data[GVFG_MAX_PLANES];
|
const void *plane_data[GVFG_MAX_PLANES];
|
||||||
int plane_stride[GVFG_MAX_PLANES];
|
int plane_stride[GVFG_MAX_PLANES];
|
||||||
@@ -161,7 +158,7 @@ typedef struct
|
|||||||
|
|
||||||
- `gvfg_handle` 永遠保持 opaque。
|
- `gvfg_handle` 永遠保持 opaque。
|
||||||
- `gvfg_frame_t` 保持極小,stable release 後凍結。
|
- `gvfg_frame_t` 保持極小,stable release 後凍結。
|
||||||
- 真正可擴充的 query output 使用 `struct_size`。
|
- 第一版 API 不做跨版本 struct 相容;DLL、header 與 application 必須整套更新。
|
||||||
- Layout 使用 `gvfg_get_frame_layout()`。
|
- Layout 使用 `gvfg_get_frame_layout()`。
|
||||||
- 未來 color metadata 使用獨立的 `gvfg_get_frame_color_info()`。
|
- 未來 color metadata 使用獨立的 `gvfg_get_frame_color_info()`。
|
||||||
- 未來 timestamp metadata 使用獨立的 `gvfg_get_frame_timestamp_info()`。
|
- 未來 timestamp metadata 使用獨立的 `gvfg_get_frame_timestamp_info()`。
|
||||||
@@ -184,15 +181,11 @@ typedef struct gvfg_convert_frame_t *gvfg_convert_frame;
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t struct_size;
|
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int pixel_format;
|
int pixel_format;
|
||||||
int row_bytes;
|
int row_bytes;
|
||||||
uint32_t flags;
|
|
||||||
uint32_t reserved0;
|
|
||||||
uint64_t data_size;
|
uint64_t data_size;
|
||||||
uint64_t reserved[8];
|
|
||||||
} gvfg_convert_frame_desc_t;
|
} gvfg_convert_frame_desc_t;
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -217,9 +210,9 @@ captured source frame 自動決定大小。
|
|||||||
Conversion 使用 BT.709 limited-range YUV to RGB,和 preview path 對齊。其他
|
Conversion 使用 BT.709 limited-range YUV to RGB,和 preview path 對齊。其他
|
||||||
source 或 destination format 會回傳 `GVFG_ENOTSUP`。
|
source 或 destination format 會回傳 `GVFG_ENOTSUP`。
|
||||||
|
|
||||||
### `gvfg_event_t`
|
### `gvfg_event_type_t`
|
||||||
|
|
||||||
`gvfg_poll_event()` 回傳的 capture event。
|
`gvfg_poll_event()` 直接回傳 capture event 類型。
|
||||||
|
|
||||||
Customer event 保持 driver-neutral:
|
Customer event 保持 driver-neutral:
|
||||||
|
|
||||||
@@ -302,11 +295,8 @@ gvfg_status_t gvfg_get_frame_layout(const gvfg_frame_t *frame,
|
|||||||
|
|
||||||
回傳 `gvfg_read_frame()` 取得 frame 的 per-plane layout。
|
回傳 `gvfg_read_frame()` 取得 frame 的 per-plane layout。
|
||||||
|
|
||||||
呼叫前先初始化 `out_layout->struct_size`:
|
|
||||||
|
|
||||||
```c
|
```c
|
||||||
gvfg_frame_layout_t layout = {};
|
gvfg_frame_layout_t layout = {};
|
||||||
layout.struct_size = sizeof(layout);
|
|
||||||
gvfg_get_frame_layout(&frame, &layout);
|
gvfg_get_frame_layout(&frame, &layout);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -343,7 +333,6 @@ Snapshot buffer flow 範例:
|
|||||||
gvfg_frame_t frame = {};
|
gvfg_frame_t frame = {};
|
||||||
if (gvfg_read_frame(h, &frame, 1000) == GVFG_OK) {
|
if (gvfg_read_frame(h, &frame, 1000) == GVFG_OK) {
|
||||||
gvfg_convert_frame_desc_t desc = {};
|
gvfg_convert_frame_desc_t desc = {};
|
||||||
desc.struct_size = sizeof(desc);
|
|
||||||
desc.pixel_format = GVFG_CONVERT_FMT_RGB48;
|
desc.pixel_format = GVFG_CONVERT_FMT_RGB48;
|
||||||
|
|
||||||
gvfg_convert_frame image = NULL;
|
gvfg_convert_frame image = NULL;
|
||||||
@@ -388,7 +377,7 @@ Release `gvfg_read_frame()` 回傳的 frame。
|
|||||||
|
|
||||||
```c
|
```c
|
||||||
gvfg_status_t gvfg_poll_event(gvfg_handle handle,
|
gvfg_status_t gvfg_poll_event(gvfg_handle handle,
|
||||||
gvfg_event_t *out_event,
|
gvfg_event_type_t *out_event,
|
||||||
uint32_t timeout_ms);
|
uint32_t timeout_ms);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -408,7 +397,6 @@ gvfg_status_t gvfg_get_signal_status(gvfg_handle handle,
|
|||||||
|
|
||||||
```c
|
```c
|
||||||
gvfg_signal_status_t status = {};
|
gvfg_signal_status_t status = {};
|
||||||
status.struct_size = sizeof(status);
|
|
||||||
gvfg_get_signal_status(h, &status);
|
gvfg_get_signal_status(h, &status);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -421,13 +409,12 @@ gvfg_status_t gvfg_get_runtime_info(gvfg_handle handle,
|
|||||||
gvfg_runtime_info_t *out_info);
|
gvfg_runtime_info_t *out_info);
|
||||||
```
|
```
|
||||||
|
|
||||||
查詢 last read frame format、FPS、delivered frame count。Input signal metadata 請另外
|
查詢 FPS 與 delivered frame count。Input signal metadata 請另外呼叫
|
||||||
呼叫 `gvfg_get_signal_status()`;不要把可擴充的 signal struct 內嵌進 runtime struct,
|
`gvfg_get_signal_status()`;每張實際交付的 frame metadata 由 `gvfg_frame_t`
|
||||||
避免未來欄位位移破壞 ABI。
|
提供。Last-delivered frame metadata 僅保留於 internal debug API。
|
||||||
|
|
||||||
```c
|
```c
|
||||||
gvfg_runtime_info_t info = {};
|
gvfg_runtime_info_t info = {};
|
||||||
info.struct_size = sizeof(info);
|
|
||||||
gvfg_get_runtime_info(h, &info);
|
gvfg_get_runtime_info(h, &info);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +1,42 @@
|
|||||||
<mxfile host="app.diagrams.net" modified="2026-06-10T00:00:00.000Z" agent="Codex" version="24.7.17" type="device">
|
<mxfile host="app.diagrams.net" modified="2026-07-30T00:00:00.000Z" agent="Codex" version="24.7.17" type="device">
|
||||||
<diagram id="gvfg-dma-ring-flow" name="GVFG DMA Ring Data Flow">
|
<diagram id="gvfg-dma-ring-flow" name="GVFG DMA Ring Data Flow">
|
||||||
<mxGraphModel dx="1600" dy="1000" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1100" math="0" shadow="0">
|
<mxGraphModel dx="1600" dy="1000" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1100" math="0" shadow="0">
|
||||||
<root>
|
<root>
|
||||||
<mxCell id="0"/>
|
<mxCell id="0"/>
|
||||||
<mxCell id="1" parent="0"/>
|
<mxCell id="1" parent="0"/>
|
||||||
<mxCell id="title" value="GVFG user-space DMA ring data flow" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=28;fontStyle=1" vertex="1" parent="1">
|
<mxCell id="title" value="GVFG driver DMA buffer to SDK ring data flow" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=28;fontStyle=1" vertex="1" parent="1">
|
||||||
<mxGeometry x="360" y="30" width="880" height="40" as="geometry"/>
|
<mxGeometry x="360" y="30" width="880" height="40" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
|
|
||||||
<mxCell id="hw" value="FPGA / PCIES2MM hardware
VIDEO IRQ" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
<mxCell id="hw" value="Video source / FPGA
writes DMA buffer N
DMA complete interrupt" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
||||||
<mxGeometry x="80" y="130" width="210" height="80" as="geometry"/>
|
<mxGeometry x="80" y="130" width="210" height="80" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="event" value="event_thread_proc()
ReadFile(event_N) returns" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
<mxCell id="event" value="Kernel driver
SetEvent(dma_event_)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
||||||
<mxGeometry x="360" y="130" width="230" height="80" as="geometry"/>
|
<mxGeometry x="360" y="130" width="230" height="80" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="pending" value="pending_events_++
data_cv_.notify_one()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14" vertex="1" parent="1">
|
<mxCell id="pending" value="single capture_thread_proc()
WaitForMultipleObjects() wakes
dispatches DMA event" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14" vertex="1" parent="1">
|
||||||
<mxGeometry x="660" y="130" width="230" height="80" as="geometry"/>
|
<mxGeometry x="660" y="130" width="230" height="80" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="datawait" value="data_thread_proc()
waits for pending_events_ > 0" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
<mxCell id="datawait" value="handle_dma_event()
IOCTL_GET_VIDEO_DONE_INDEX" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
||||||
<mxGeometry x="960" y="130" width="260" height="80" as="geometry"/>
|
<mxGeometry x="960" y="130" width="260" height="80" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="clear" value="Clear VIDEO IRQ
write INT_CLR high/low
enable_user_event()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
|
<mxCell id="clear" value="frameIndex = doneIndex % 16
select completed driver DMA buffer N" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
|
||||||
<mxGeometry x="1280" y="130" width="240" height="90" as="geometry"/>
|
<mxGeometry x="1280" y="130" width="240" height="90" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
|
|
||||||
<mxCell id="findslot" value="Find free FrameSlot
slot.in_use == false" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
<mxCell id="findslot" value="SDK 3-slot frame_ring_
search slot.in_use == false" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
||||||
<mxGeometry x="80" y="310" width="240" height="80" as="geometry"/>
|
<mxGeometry x="80" y="310" width="240" height="80" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="droptest" value="Slot already ready?
ready == true and newer than delivered" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=13" vertex="1" parent="1">
|
<mxCell id="droptest" value="Free slot available?" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=13" vertex="1" parent="1">
|
||||||
<mxGeometry x="390" y="300" width="190" height="100" as="geometry"/>
|
<mxGeometry x="390" y="300" width="190" height="100" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="drop" value="Drop old ready frame
stats_.frames_dropped++" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=14" vertex="1" parent="1">
|
<mxCell id="drop" value="No: capture thread waits
data_cv_.wait_for()
driver buffers may advance" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=14" vertex="1" parent="1">
|
||||||
<mxGeometry x="650" y="290" width="230" height="70" as="geometry"/>
|
<mxGeometry x="650" y="290" width="230" height="70" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="markwriting" value="Mark slot writing
ready = false
in_use = true" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
|
<mxCell id="markwriting" value="Mark slot writing
ready = false
in_use = true" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
|
||||||
<mxGeometry x="650" y="390" width="230" height="90" as="geometry"/>
|
<mxGeometry x="650" y="390" width="230" height="90" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="readc2h" value="ReadFile(c2h_N)
directly into slot.data" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
<mxCell id="readc2h" value="IOCTL_GET_FRAME
driver DMA buffer N -> one copy -> slot.data
validate bytesReturned == expected" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1" vertex="1" parent="1">
|
||||||
<mxGeometry x="960" y="330" width="260" height="80" as="geometry"/>
|
<mxGeometry x="960" y="330" width="260" height="80" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="publish" value="publish_frame(slotIndex, bytes)
slot.ready = true
slot.in_use = false
frame_cv_.notify_one()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
|
<mxCell id="publish" value="publish_frame(slotIndex, bytes)
slot.ready = true
slot.in_use = false
frame_cv_.notify_one()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14" vertex="1" parent="1">
|
||||||
@@ -84,9 +84,9 @@
|
|||||||
<mxCell id="e4" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="datawait" target="clear"><mxGeometry relative="1" as="geometry"/></mxCell>
|
<mxCell id="e4" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="datawait" target="clear"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||||
<mxCell id="e5" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="clear" target="findslot"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="1400" y="260"/><mxPoint x="200" y="260"/></Array></mxGeometry></mxCell>
|
<mxCell id="e5" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="clear" target="findslot"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="1400" y="260"/><mxPoint x="200" y="260"/></Array></mxGeometry></mxCell>
|
||||||
<mxCell id="e6" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="findslot" target="droptest"><mxGeometry relative="1" as="geometry"/></mxCell>
|
<mxCell id="e6" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="findslot" target="droptest"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||||
<mxCell id="e7" value="yes" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="droptest" target="drop"><mxGeometry relative="1" as="geometry"/></mxCell>
|
<mxCell id="e7" value="yes" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="droptest" target="markwriting"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||||
<mxCell id="e8" value="no / after drop" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="droptest" target="markwriting"><mxGeometry relative="1" as="geometry"/></mxCell>
|
<mxCell id="e8" value="no" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="droptest" target="drop"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||||
<mxCell id="e9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="drop" target="markwriting"><mxGeometry relative="1" as="geometry"/></mxCell>
|
<mxCell id="e9" value="release wakes waiter" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1" edge="1" parent="1" source="drop" target="findslot"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||||
<mxCell id="e10" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="markwriting" target="readc2h"><mxGeometry relative="1" as="geometry"/></mxCell>
|
<mxCell id="e10" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="markwriting" target="readc2h"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||||
<mxCell id="e11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="readc2h" target="publish"><mxGeometry relative="1" as="geometry"/></mxCell>
|
<mxCell id="e11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="readc2h" target="publish"><mxGeometry relative="1" as="geometry"/></mxCell>
|
||||||
<mxCell id="e12" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2" edge="1" parent="1" source="publish" target="wait"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="1410" y="500"/><mxPoint x="220" y="500"/></Array></mxGeometry></mxCell>
|
<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>
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ flowchart TD
|
|||||||
subgraph Backend["Internal Backend"]
|
subgraph Backend["Internal Backend"]
|
||||||
PcieS2mm["sdk/gvfg/src/backend/pcies2mm"]
|
PcieS2mm["sdk/gvfg/src/backend/pcies2mm"]
|
||||||
Ring["frame_ring_"]
|
Ring["frame_ring_"]
|
||||||
Workers["single driver event + DMA worker"]
|
Workers["single capture thread: DMA / format / plug events"]
|
||||||
end
|
end
|
||||||
|
|
||||||
CustomerApp --> CaptureApi
|
CustomerApp --> CaptureApi
|
||||||
@@ -125,14 +125,77 @@ Pull mode 下,`gvfg.dll` 不擁有 application 的 public read thread。UI app
|
|||||||
自己建立 worker thread,並在那個 thread 呼叫 `gvfg_read_frame()`。
|
自己建立 worker thread,並在那個 thread 呼叫 `gvfg_read_frame()`。
|
||||||
|
|
||||||
`gvfg_start()` 在尚未確認 input signal 時仍會註冊 driver events 並啟動單一 backend
|
`gvfg_start()` 在尚未確認 input signal 時仍會註冊 driver events 並啟動單一 backend
|
||||||
wait thread。`gvfg_read_frame()` 此時 timeout;收到 signal-connected event 後,backend
|
capture thread。`gvfg_read_frame()` 此時 timeout;收到 signal-connected event 後,
|
||||||
在相同 thread 重讀 width/height/payload format、resize ring,然後 enable DMA 並送出
|
backend 在相同 thread 重讀 width/height/payload format、resize ring,然後 enable DMA。
|
||||||
capture-resumed event。
|
第一張完整 frame publish 後,public event queue 收到 `GVFG_EVENT_STREAM_READY`。
|
||||||
|
|
||||||
FPGA H/V/format registers 可能在拔除來源後保留 last-known values,因此它們只能用來
|
FPGA H/V/format registers 可能在拔除來源後保留 last-known values,因此它們只能用來
|
||||||
準備 DMA probe layout,不能當作 signal-present 判斷。啟動時 backend 可以在內部 enable
|
準備 DMA probe layout,不能當作 signal-present 判斷。啟動時 backend 可以在內部 enable
|
||||||
probe DMA,以涵蓋來源早於 event registration 就已接上的情況;只有收到 driver plug-in
|
probe DMA,以涵蓋來源早於 event registration 就已接上的情況;只有收到 driver plug-in
|
||||||
event 或成功取得第一張完整 frame 後,public signal status 才能回報 connected。
|
event 或成功取得第一張完整 frame 後,public signal status 才能回報 connected。DMA
|
||||||
|
probe 成功不偽造 plug-in event,而是送出 `GVFG_EVENT_STREAM_READY`。
|
||||||
|
|
||||||
|
## Internal DMA / Ring Data Flow
|
||||||
|
|
||||||
|
Driver DMA buffer 與 SDK `frame_ring_` 是兩層不同的 storage。Driver buffer 負責接收
|
||||||
|
硬體 DMA;SDK ring 保存一份 user-mode copy,讓 application 能持有 frame 到
|
||||||
|
`gvfg_release_frame()`。三個 SDK ring slots 只增加緩衝空間,每一張 frame 仍只有一次
|
||||||
|
driver-to-SDK copy。
|
||||||
|
|
||||||
|
目前完整路徑:
|
||||||
|
|
||||||
|
```text
|
||||||
|
video source produces one frame
|
||||||
|
-> hardware writes driver DMA buffer N
|
||||||
|
-> DMA complete interrupt
|
||||||
|
-> driver SetEvent(dma_event_)
|
||||||
|
-> capture_thread_proc() wakes from WaitForMultipleObjects()
|
||||||
|
-> handle_dma_event()
|
||||||
|
-> IOCTL_GET_VIDEO_DONE_INDEX
|
||||||
|
-> frameIndex = doneIndex % kDmaBufferCount (currently 16)
|
||||||
|
-> search the 3-slot SDK frame_ring_ for slot.in_use == false
|
||||||
|
-> mark slot: ready=false, in_use=true
|
||||||
|
-> IOCTL_GET_FRAME
|
||||||
|
-> one copy: driver DMA buffer N -> slot.data
|
||||||
|
-> validate bytesReturned == expected frame size
|
||||||
|
-> publish_frame()
|
||||||
|
- sequence = ++latest_sequence_
|
||||||
|
- ready = true
|
||||||
|
- in_use = false
|
||||||
|
- frame_cv_.notify_one()
|
||||||
|
-> gvfg_read_frame() / wait_frame() wakes
|
||||||
|
-> select the newest ready sequence
|
||||||
|
-> mark delivered slot: ready=false, in_use=true
|
||||||
|
-> return gvfg_frame_t pointing at slot.data
|
||||||
|
-> preview / conversion / customer processing
|
||||||
|
-> gvfg_release_frame()
|
||||||
|
-> mark slot.in_use=false
|
||||||
|
-> data_cv_.notify_all()
|
||||||
|
-> slot becomes reusable
|
||||||
|
```
|
||||||
|
|
||||||
|
FrameSlot 的主要狀態:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Free : ready=false, in_use=false
|
||||||
|
Writing : ready=false, in_use=true
|
||||||
|
Ready : ready=true, in_use=false
|
||||||
|
Delivered : ready=false, in_use=true
|
||||||
|
Released : ready=false, in_use=false
|
||||||
|
```
|
||||||
|
|
||||||
|
同步責任:
|
||||||
|
|
||||||
|
- `mutex_` 保護 `frame_ring_`、slot flags、sequence 與 active delivery slot。
|
||||||
|
- `frame_cv_` 喚醒等待 ready frame 的 `wait_frame()`。
|
||||||
|
- `data_cv_` 喚醒等待 free slot 的 capture thread。
|
||||||
|
- `eventMutex`、`eventCv` 與 `eventQueue` 是 public capture event 的另一套同步機制,
|
||||||
|
不保存 frame。
|
||||||
|
|
||||||
|
如果三個 SDK slots 全部 `in_use`,capture thread 目前會在 `data_cv_` 等待,不會主動
|
||||||
|
從 SDK ring 丟掉 application 正在持有的 frame。硬體與 driver DMA 仍可能繼續前進,
|
||||||
|
因此等待期間的中間 frame 可能在 driver 層被覆寫或 event 被合併,形成隱性掉幀。
|
||||||
|
這是 backpressure policy,不是 lossless queue 保證。
|
||||||
|
|
||||||
## Frame 所有權
|
## Frame 所有權
|
||||||
|
|
||||||
@@ -144,7 +207,7 @@ event 或成功取得第一張完整 frame 後,public signal status 才能回
|
|||||||
- `gvfg_get_frame_layout()` 回傳 SDK-filled layout metadata:`plane_data`、
|
- `gvfg_get_frame_layout()` 回傳 SDK-filled layout metadata:`plane_data`、
|
||||||
`plane_stride`、`plane_size`。目前 PCIES2MM backend 使用
|
`plane_stride`、`plane_size`。目前 PCIES2MM backend 使用
|
||||||
width/height/format 推導 tightly packed layout。
|
width/height/format 推導 tightly packed layout。
|
||||||
- 未來 color/timestamp metadata 應新增各自帶 `struct_size` 的 query output,例如
|
- 未來 color/timestamp metadata 應新增獨立的 query output,例如
|
||||||
`gvfg_get_frame_color_info()` 與 `gvfg_get_frame_timestamp_info()`。不要預先在每個
|
`gvfg_get_frame_color_info()` 與 `gvfg_get_frame_timestamp_info()`。不要預先在每個
|
||||||
struct 放大型 reserved array;等 metadata 類型真的很多再考慮 side data。
|
struct 放大型 reserved array;等 metadata 類型真的很多再考慮 side data。
|
||||||
- `gvfg_preview.dll` 應優先吃 `gvfg_get_frame_layout()`;layout query 不可用時才
|
- `gvfg_preview.dll` 應優先吃 `gvfg_get_frame_layout()`;layout query 不可用時才
|
||||||
@@ -174,8 +237,36 @@ Customer event 保持 driver-neutral:
|
|||||||
```text
|
```text
|
||||||
GVFG_EVENT_SIGNAL_CONNECTED
|
GVFG_EVENT_SIGNAL_CONNECTED
|
||||||
GVFG_EVENT_SIGNAL_DISCONNECTED
|
GVFG_EVENT_SIGNAL_DISCONNECTED
|
||||||
|
GVFG_EVENT_STREAM_READY
|
||||||
|
GVFG_EVENT_FORMAT_CHANGE_BEGIN
|
||||||
```
|
```
|
||||||
|
|
||||||
|
事件語意:
|
||||||
|
|
||||||
|
- `GVFG_EVENT_SIGNAL_CONNECTED`:backend 收到真正的 driver plug-in event。
|
||||||
|
- `GVFG_EVENT_SIGNAL_DISCONNECTED`:backend 收到真正的 driver plug-out event。
|
||||||
|
- `GVFG_EVENT_FORMAT_CHANGE_BEGIN`:收到 driver format-change event,舊格式資源即將
|
||||||
|
失效;backend 自動停止舊 DMA、重讀格式並恢復 capture。
|
||||||
|
- `GVFG_EVENT_STREAM_READY`:start、plug-in recovery 或 format recovery 後,第一張
|
||||||
|
完整 frame 已經 publish。Application 可讀取新 `gvfg_frame_t`,依其中的
|
||||||
|
width/height/pixel_format/bit_depth 重建 render resources。
|
||||||
|
|
||||||
|
Format change 是兩階段通知:
|
||||||
|
|
||||||
|
```text
|
||||||
|
driver format-change event
|
||||||
|
-> GVFG_EVENT_FORMAT_CHANGE_BEGIN
|
||||||
|
-> backend disables old DMA/video
|
||||||
|
-> backend refreshes width/height/payload format and resizes ring
|
||||||
|
-> backend enables capture
|
||||||
|
-> first complete new-format frame is published
|
||||||
|
-> GVFG_EVENT_STREAM_READY
|
||||||
|
```
|
||||||
|
|
||||||
|
Application 可在 `FORMAT_CHANGE_BEGIN` 暫停 render 或清理舊格式資源,但不應自行對同一
|
||||||
|
session 執行 Stop/Start;backend 負責恢復。在 `STREAM_READY` 後,以新 frame metadata
|
||||||
|
重建並恢復 render。
|
||||||
|
|
||||||
Video IRQ handling 是 `sdk/gvfg/src/backend/pcies2mm` 內部細節。IRQ bit numbers、
|
Video IRQ handling 是 `sdk/gvfg/src/backend/pcies2mm` 內部細節。IRQ bit numbers、
|
||||||
IRQ masks 與 DMA counters 不應出現在
|
IRQ masks 與 DMA counters 不應出現在
|
||||||
`gvfg_capture.h`。
|
`gvfg_capture.h`。
|
||||||
|
|||||||
@@ -35,15 +35,11 @@ typedef struct gvfg_convert_frame_t *gvfg_convert_frame;
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t struct_size; /* Set to sizeof(gvfg_convert_frame_desc_t) before calling. */
|
|
||||||
int width; /* Frame width in pixels. Use 0 to size from source during conversion. */
|
int width; /* Frame width in pixels. Use 0 to size from source during conversion. */
|
||||||
int height; /* Frame height in pixels. Use 0 to size from source during conversion. */
|
int height; /* Frame height in pixels. Use 0 to size from source during conversion. */
|
||||||
int pixel_format; /* gvfg_convert_format_t destination format. */
|
int pixel_format; /* gvfg_convert_format_t destination format. */
|
||||||
int row_bytes; /* Destination row stride in bytes. Use 0 for helper default. */
|
int row_bytes; /* Destination row stride in bytes. Use 0 for helper default. */
|
||||||
uint32_t flags; /* Reserved for future conversion options. Must be 0. */
|
|
||||||
uint32_t reserved0; /* Reserved. Must be 0. */
|
|
||||||
uint64_t data_size; /* Output buffer size in bytes, filled after create/convert. */
|
uint64_t data_size; /* Output buffer size in bytes, filled after create/convert. */
|
||||||
uint64_t reserved[8]; /* Reserved for future helper metadata. Must be ignored. */
|
|
||||||
} gvfg_convert_frame_desc_t;
|
} gvfg_convert_frame_desc_t;
|
||||||
|
|
||||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_create_frame(
|
GVFG_CONVERT_API gvfg_status_t gvfg_convert_create_frame(
|
||||||
@@ -59,7 +55,7 @@ GVFG_CONVERT_API gvfg_status_t gvfg_convert_frame_from_capture(
|
|||||||
|
|
||||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_frame_desc(
|
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_frame_desc(
|
||||||
_In_ gvfg_convert_frame frame,
|
_In_ gvfg_convert_frame frame,
|
||||||
_Inout_ gvfg_convert_frame_desc_t *out_desc);
|
_Out_ gvfg_convert_frame_desc_t *out_desc);
|
||||||
|
|
||||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_buffer(
|
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_buffer(
|
||||||
_In_ gvfg_convert_frame frame,
|
_In_ gvfg_convert_frame frame,
|
||||||
@@ -68,7 +64,7 @@ GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_buffer(
|
|||||||
|
|
||||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_layout(
|
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_layout(
|
||||||
_In_ gvfg_convert_frame frame,
|
_In_ gvfg_convert_frame frame,
|
||||||
_Inout_ gvfg_frame_layout_t *out_layout);
|
_Out_ gvfg_frame_layout_t *out_layout);
|
||||||
|
|
||||||
GVFG_CONVERT_API const char *gvfg_convert_strerror(
|
GVFG_CONVERT_API const char *gvfg_convert_strerror(
|
||||||
_In_ gvfg_status_t status);
|
_In_ gvfg_status_t status);
|
||||||
|
|||||||
@@ -160,7 +160,6 @@ struct gvfg_convert_frame_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
layout = {};
|
layout = {};
|
||||||
layout.struct_size = sizeof(layout);
|
|
||||||
layout.plane_count = 1;
|
layout.plane_count = 1;
|
||||||
layout.plane_data[0] = buffer.data();
|
layout.plane_data[0] = buffer.data();
|
||||||
layout.plane_stride[0] = actualStride;
|
layout.plane_stride[0] = actualStride;
|
||||||
@@ -323,17 +322,13 @@ extern "C"
|
|||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
*out_frame = nullptr;
|
*out_frame = nullptr;
|
||||||
|
|
||||||
if (desc->struct_size < sizeof(gvfg_convert_frame_desc_t) ||
|
if (convert_format_bytes_per_pixel(desc->pixel_format) <= 0)
|
||||||
desc->flags != 0 ||
|
|
||||||
desc->reserved0 != 0 ||
|
|
||||||
convert_format_bytes_per_pixel(desc->pixel_format) <= 0)
|
|
||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
if (desc->width < 0 || desc->height < 0 || desc->row_bytes < 0)
|
if (desc->width < 0 || desc->height < 0 || desc->row_bytes < 0)
|
||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
|
|
||||||
auto frame = std::make_unique<gvfg_convert_frame_t>();
|
auto frame = std::make_unique<gvfg_convert_frame_t>();
|
||||||
frame->request = {};
|
frame->request = {};
|
||||||
frame->request.struct_size = sizeof(gvfg_convert_frame_desc_t);
|
|
||||||
frame->request.width = desc->width;
|
frame->request.width = desc->width;
|
||||||
frame->request.height = desc->height;
|
frame->request.height = desc->height;
|
||||||
frame->request.pixel_format = desc->pixel_format;
|
frame->request.pixel_format = desc->pixel_format;
|
||||||
@@ -374,7 +369,6 @@ extern "C"
|
|||||||
return cfg;
|
return cfg;
|
||||||
|
|
||||||
gvfg_frame_layout_t srcLayout{};
|
gvfg_frame_layout_t srcLayout{};
|
||||||
srcLayout.struct_size = sizeof(srcLayout);
|
|
||||||
const gvfg_status_t layoutStatus = gvfg_get_frame_layout(src, &srcLayout);
|
const gvfg_status_t layoutStatus = gvfg_get_frame_layout(src, &srcLayout);
|
||||||
if (layoutStatus != GVFG_OK)
|
if (layoutStatus != GVFG_OK)
|
||||||
return layoutStatus;
|
return layoutStatus;
|
||||||
@@ -395,13 +389,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
if (!frame || !out_desc)
|
if (!frame || !out_desc)
|
||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
if (out_desc->struct_size < sizeof(gvfg_convert_frame_desc_t))
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
const uint32_t callerSize = out_desc->struct_size;
|
|
||||||
std::memset(out_desc, 0, sizeof(*out_desc));
|
|
||||||
*out_desc = frame->desc;
|
*out_desc = frame->desc;
|
||||||
out_desc->struct_size = callerSize;
|
|
||||||
return GVFG_OK;
|
return GVFG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,15 +409,10 @@ extern "C"
|
|||||||
{
|
{
|
||||||
if (!frame || !out_layout)
|
if (!frame || !out_layout)
|
||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
if (out_layout->struct_size < sizeof(gvfg_frame_layout_t))
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
if (frame->buffer.empty() || frame->layout.plane_count <= 0)
|
if (frame->buffer.empty() || frame->layout.plane_count <= 0)
|
||||||
return GVFG_ESTATE;
|
return GVFG_ESTATE;
|
||||||
|
|
||||||
const uint32_t callerSize = out_layout->struct_size;
|
|
||||||
std::memset(out_layout, 0, sizeof(*out_layout));
|
|
||||||
*out_layout = frame->layout;
|
*out_layout = frame->layout;
|
||||||
out_layout->struct_size = callerSize;
|
|
||||||
return GVFG_OK;
|
return GVFG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ typedef enum
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t struct_size; /* Set to sizeof(gvfg_preview_frame_t). */
|
|
||||||
const void *data;
|
const void *data;
|
||||||
uint64_t data_size;
|
uint64_t data_size;
|
||||||
int width;
|
int width;
|
||||||
@@ -74,7 +73,6 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t struct_size; /* Set to sizeof(gvfg_preview_stats_t). */
|
|
||||||
double present_fps;
|
double present_fps;
|
||||||
uint64_t presented_frames;
|
uint64_t presented_frames;
|
||||||
uint64_t skipped_presents;
|
uint64_t skipped_presents;
|
||||||
|
|||||||
@@ -429,8 +429,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
if (!handle || !frame)
|
if (!handle || !frame)
|
||||||
return GVFG_PREVIEW_EINVAL;
|
return GVFG_PREVIEW_EINVAL;
|
||||||
if (frame->struct_size < sizeof(gvfg_preview_frame_t) ||
|
if (!frame->data ||
|
||||||
!frame->data ||
|
|
||||||
frame->width <= 0 ||
|
frame->width <= 0 ||
|
||||||
frame->height <= 0 ||
|
frame->height <= 0 ||
|
||||||
frame->row_bytes <= 0)
|
frame->row_bytes <= 0)
|
||||||
@@ -481,18 +480,12 @@ extern "C"
|
|||||||
gvfg_preview_status_t gvfg_preview_get_stats(gvfg_preview_handle handle,
|
gvfg_preview_status_t gvfg_preview_get_stats(gvfg_preview_handle handle,
|
||||||
gvfg_preview_stats_t *out_stats)
|
gvfg_preview_stats_t *out_stats)
|
||||||
{
|
{
|
||||||
constexpr size_t kMinimumSize =
|
if (!handle || !out_stats)
|
||||||
offsetof(gvfg_preview_stats_t, skipped_presents) +
|
|
||||||
sizeof(uint64_t);
|
|
||||||
if (!handle || !out_stats || out_stats->struct_size < kMinimumSize)
|
|
||||||
return GVFG_PREVIEW_EINVAL;
|
return GVFG_PREVIEW_EINVAL;
|
||||||
|
|
||||||
const uint32_t callerSize = out_stats->struct_size;
|
|
||||||
gvfg_preview_stats_t stats{};
|
gvfg_preview_stats_t stats{};
|
||||||
stats.struct_size = sizeof(stats);
|
|
||||||
handle->renderer.getStats(stats);
|
handle->renderer.getStats(stats);
|
||||||
std::memcpy(out_stats, &stats, (callerSize < sizeof(stats)) ? callerSize : sizeof(stats));
|
*out_stats = stats;
|
||||||
out_stats->struct_size = callerSize;
|
|
||||||
return GVFG_PREVIEW_OK;
|
return GVFG_PREVIEW_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,10 @@ namespace
|
|||||||
return QStringLiteral("SIGNAL_CONNECTED");
|
return QStringLiteral("SIGNAL_CONNECTED");
|
||||||
case GVFG_EVENT_SIGNAL_DISCONNECTED:
|
case GVFG_EVENT_SIGNAL_DISCONNECTED:
|
||||||
return QStringLiteral("SIGNAL_DISCONNECTED");
|
return QStringLiteral("SIGNAL_DISCONNECTED");
|
||||||
|
case GVFG_EVENT_STREAM_READY:
|
||||||
|
return QStringLiteral("STREAM_READY");
|
||||||
|
case GVFG_EVENT_FORMAT_CHANGE_BEGIN:
|
||||||
|
return QStringLiteral("FORMAT_CHANGE_BEGIN");
|
||||||
default:
|
default:
|
||||||
return QStringLiteral("UNKNOWN");
|
return QStringLiteral("UNKNOWN");
|
||||||
}
|
}
|
||||||
@@ -412,19 +416,10 @@ bool MainWindow::applyPreview()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updatePreviewSourceSize(const gvfg_runtime_info_t &info,
|
void MainWindow::updatePreviewSourceSize(const gvfg_signal_status_t &signal)
|
||||||
const gvfg_signal_status_t &signal)
|
|
||||||
{
|
{
|
||||||
const auto &readFrame = info.last_frame;
|
|
||||||
|
|
||||||
if (signal.width > 0 && signal.height > 0)
|
if (signal.width > 0 && signal.height > 0)
|
||||||
{
|
|
||||||
previewWindow_->setSourceSize(signal.width, signal.height);
|
previewWindow_->setSourceSize(signal.width, signal.height);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (readFrame.valid && readFrame.width > 0 && readFrame.height > 0)
|
|
||||||
previewWindow_->setSourceSize(readFrame.width, readFrame.height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updatePreviewSourceSize()
|
void MainWindow::updatePreviewSourceSize()
|
||||||
@@ -432,13 +427,9 @@ void MainWindow::updatePreviewSourceSize()
|
|||||||
if (!handle_)
|
if (!handle_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gvfg_runtime_info_t info{};
|
|
||||||
info.struct_size = sizeof(info);
|
|
||||||
gvfg_signal_status_t signal{};
|
gvfg_signal_status_t signal{};
|
||||||
signal.struct_size = sizeof(signal);
|
if (gvfg_get_signal_status(handle_, &signal) == GVFG_OK)
|
||||||
if (gvfg_get_runtime_info(handle_, &info) == GVFG_OK &&
|
updatePreviewSourceSize(signal);
|
||||||
gvfg_get_signal_status(handle_, &signal) == GVFG_OK)
|
|
||||||
updatePreviewSourceSize(info, signal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateSignalStatus()
|
void MainWindow::updateSignalStatus()
|
||||||
@@ -446,30 +437,22 @@ void MainWindow::updateSignalStatus()
|
|||||||
if (!handle_)
|
if (!handle_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gvfg_runtime_info_t info{};
|
|
||||||
info.struct_size = sizeof(info);
|
|
||||||
if (gvfg_get_runtime_info(handle_, &info) != GVFG_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
gvfg_signal_status_t signal{};
|
gvfg_signal_status_t signal{};
|
||||||
signal.struct_size = sizeof(signal);
|
|
||||||
if (gvfg_get_signal_status(handle_, &signal) != GVFG_OK)
|
if (gvfg_get_signal_status(handle_, &signal) != GVFG_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
gvfg_debug_backend_stats_t backendStats{};
|
gvfg_debug_backend_stats_t backendStats{};
|
||||||
backendStats.struct_size = sizeof(backendStats);
|
|
||||||
const bool haveBackendStats = gvfg_debug_get_backend_stats(handle_, &backendStats) == GVFG_OK;
|
const bool haveBackendStats = gvfg_debug_get_backend_stats(handle_, &backendStats) == GVFG_OK;
|
||||||
#endif
|
#endif
|
||||||
if (previewWindow_->isVisible())
|
if (previewWindow_->isVisible())
|
||||||
updatePreviewSourceSize(info, signal);
|
updatePreviewSourceSize(signal);
|
||||||
|
|
||||||
gvfg_preview_info_t previewInfo{};
|
gvfg_preview_info_t previewInfo{};
|
||||||
const bool previewInfoOk = previewHandle_ &&
|
const bool previewInfoOk = previewHandle_ &&
|
||||||
gvfg_preview_get_info(previewHandle_, &previewInfo) == GVFG_PREVIEW_OK &&
|
gvfg_preview_get_info(previewHandle_, &previewInfo) == GVFG_PREVIEW_OK &&
|
||||||
previewInfo.active;
|
previewInfo.active;
|
||||||
gvfg_preview_stats_t previewStats{};
|
gvfg_preview_stats_t previewStats{};
|
||||||
previewStats.struct_size = sizeof(previewStats);
|
|
||||||
const bool previewStatsOk = previewHandle_ &&
|
const bool previewStatsOk = previewHandle_ &&
|
||||||
gvfg_preview_get_stats(previewHandle_, &previewStats) == GVFG_PREVIEW_OK;
|
gvfg_preview_get_stats(previewHandle_, &previewStats) == GVFG_PREVIEW_OK;
|
||||||
const QString previewFps = previewStatsOk && previewStats.present_fps > 0.0
|
const QString previewFps = previewStatsOk && previewStats.present_fps > 0.0
|
||||||
@@ -482,6 +465,11 @@ void MainWindow::updateSignalStatus()
|
|||||||
previewInfo.pixel_format,
|
previewInfo.pixel_format,
|
||||||
previewInfo.bit_depth)
|
previewInfo.bit_depth)
|
||||||
: QStringLiteral("--");
|
: QStringLiteral("--");
|
||||||
|
const QString previewState = !captureRunning_
|
||||||
|
? QStringLiteral("Stopped")
|
||||||
|
: previewFps == QStringLiteral("--")
|
||||||
|
? QStringLiteral("Measuring")
|
||||||
|
: QStringLiteral("%1 FPS").arg(previewFps);
|
||||||
QStringList statusLines;
|
QStringList statusLines;
|
||||||
statusLines << (signal.connected
|
statusLines << (signal.connected
|
||||||
? QStringLiteral("Input | CH%1 | Connected | %2")
|
? QStringLiteral("Input | CH%1 | Connected | %2")
|
||||||
@@ -491,10 +479,7 @@ void MainWindow::updateSignalStatus()
|
|||||||
.arg(signal.channel));
|
.arg(signal.channel));
|
||||||
statusLines << (previewInfoOk
|
statusLines << (previewInfoOk
|
||||||
? QStringLiteral("Preview | %1 | %2")
|
? QStringLiteral("Preview | %1 | %2")
|
||||||
.arg(previewFps == QStringLiteral("--")
|
.arg(previewState, previewFrame)
|
||||||
? QStringLiteral("Measuring")
|
|
||||||
: QStringLiteral("%1 FPS").arg(previewFps),
|
|
||||||
previewFrame)
|
|
||||||
: QStringLiteral("Preview | Inactive"));
|
: QStringLiteral("Preview | Inactive"));
|
||||||
|
|
||||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
@@ -728,21 +713,13 @@ void MainWindow::captureReadLoop()
|
|||||||
|
|
||||||
while (!captureStop_.load(std::memory_order_acquire))
|
while (!captureStop_.load(std::memory_order_acquire))
|
||||||
{
|
{
|
||||||
gvfg_event_t event{};
|
gvfg_event_type_t event = GVFG_EVENT_UNKNOWN;
|
||||||
while (gvfg_poll_event(handle_, &event, 0) == GVFG_OK)
|
while (gvfg_poll_event(handle_, &event, 0) == GVFG_OK)
|
||||||
{
|
{
|
||||||
const QString type = eventTypeText(event.type);
|
const QString type = eventTypeText(event);
|
||||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
|
||||||
const uint64_t timestampNs = event.timestamp_ns;
|
|
||||||
QMetaObject::invokeMethod(this, [this, type, timestampNs]()
|
|
||||||
{ appendLog(QStringLiteral("event %1 ts=%2")
|
|
||||||
.arg(type)
|
|
||||||
.arg(static_cast<qulonglong>(timestampNs))); }, Qt::QueuedConnection);
|
|
||||||
#else
|
|
||||||
QMetaObject::invokeMethod(this, [this, type]()
|
QMetaObject::invokeMethod(this, [this, type]()
|
||||||
{ appendLog(QStringLiteral("EVENT %1").arg(type)); },
|
{ appendLog(QStringLiteral("EVENT %1").arg(type)); },
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gvfg_frame_t frame{};
|
gvfg_frame_t frame{};
|
||||||
@@ -761,7 +738,6 @@ void MainWindow::captureReadLoop()
|
|||||||
if (previewHandle_)
|
if (previewHandle_)
|
||||||
{
|
{
|
||||||
gvfg_preview_frame_t previewFrame{};
|
gvfg_preview_frame_t previewFrame{};
|
||||||
previewFrame.struct_size = sizeof(previewFrame);
|
|
||||||
previewFrame.data = frame.data;
|
previewFrame.data = frame.data;
|
||||||
previewFrame.data_size = frame.data_size;
|
previewFrame.data_size = frame.data_size;
|
||||||
previewFrame.width = frame.width;
|
previewFrame.width = frame.width;
|
||||||
@@ -785,7 +761,6 @@ void MainWindow::captureReadLoop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
gvfg_frame_layout_t layout{};
|
gvfg_frame_layout_t layout{};
|
||||||
layout.struct_size = sizeof(layout);
|
|
||||||
if (gvfg_get_frame_layout(&frame, &layout) == GVFG_OK &&
|
if (gvfg_get_frame_layout(&frame, &layout) == GVFG_OK &&
|
||||||
layout.plane_count > 0 &&
|
layout.plane_count > 0 &&
|
||||||
layout.plane_data[0] &&
|
layout.plane_data[0] &&
|
||||||
@@ -834,7 +809,6 @@ void MainWindow::captureReadLoop()
|
|||||||
(consecutiveTimeouts % 5) == 0)
|
(consecutiveTimeouts % 5) == 0)
|
||||||
{
|
{
|
||||||
gvfg_signal_status_t signal{};
|
gvfg_signal_status_t signal{};
|
||||||
signal.struct_size = sizeof(signal);
|
|
||||||
if (gvfg_get_signal_status(handle_, &signal) == GVFG_OK && signal.connected)
|
if (gvfg_get_signal_status(handle_, &signal) == GVFG_OK && signal.connected)
|
||||||
{
|
{
|
||||||
captureStalledLogged = true;
|
captureStalledLogged = true;
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ private:
|
|||||||
void startCapture();
|
void startCapture();
|
||||||
void stopCapture();
|
void stopCapture();
|
||||||
bool applyPreview();
|
bool applyPreview();
|
||||||
void updatePreviewSourceSize(const gvfg_runtime_info_t &info,
|
void updatePreviewSourceSize(const gvfg_signal_status_t &signal);
|
||||||
const gvfg_signal_status_t &signal);
|
|
||||||
void updatePreviewSourceSize();
|
void updatePreviewSourceSize();
|
||||||
void updateSignalStatus();
|
void updateSignalStatus();
|
||||||
void updateUiState();
|
void updateUiState();
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ PreviewWindow::PreviewWindow(QWidget *parent)
|
|||||||
: QWidget(parent), ui_(new Ui::PreviewWindow)
|
: QWidget(parent), ui_(new Ui::PreviewWindow)
|
||||||
{
|
{
|
||||||
ui_->setupUi(this);
|
ui_->setupUi(this);
|
||||||
|
ui_->verticalLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
ui_->verticalLayout->setSpacing(0);
|
||||||
ui_->previewHost->setAttribute(Qt::WA_NativeWindow, true);
|
ui_->previewHost->setAttribute(Qt::WA_NativeWindow, true);
|
||||||
ui_->previewHost->setStyleSheet(QStringLiteral("background: black;"));
|
ui_->previewHost->setStyleSheet(QStringLiteral("background: black;"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ extern "C"
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t struct_size; /* Set to sizeof(gvfg_signal_status_t) before calling. */
|
|
||||||
int connected; /* Non-zero while the selected channel has a valid input signal. */
|
int connected; /* Non-zero while the selected channel has a valid input signal. */
|
||||||
int channel; /* gvfg_channel_t selected when the device was opened. */
|
int channel; /* gvfg_channel_t selected when the device was opened. */
|
||||||
int width; /* Signal width in pixels when connected. */
|
int width; /* Signal width in pixels when connected. */
|
||||||
@@ -129,17 +128,6 @@ extern "C"
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int width; /* Width of the most recent frame returned by gvfg_read_frame(). */
|
|
||||||
int height; /* Height of the most recent frame returned by gvfg_read_frame(). */
|
|
||||||
int bit_depth; /* Bits per color channel of the frame buffer. */
|
|
||||||
int pixel_format; /* gvfg_pixel_format_t value: YUY2 or Y210. */
|
|
||||||
int valid; /* Non-zero while capture is running after at least one frame read. */
|
|
||||||
} gvfg_last_frame_info_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint32_t struct_size; /* Set to sizeof(gvfg_runtime_info_t) before calling. */
|
|
||||||
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(). */
|
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(). */
|
uint64_t delivered_frames; /* Number of frames returned by gvfg_read_frame(). */
|
||||||
} gvfg_runtime_info_t;
|
} gvfg_runtime_info_t;
|
||||||
@@ -157,7 +145,6 @@ extern "C"
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t struct_size; /* Set to sizeof(gvfg_frame_layout_t) before calling. */
|
|
||||||
int plane_count; /* Number of valid entries in plane_data/plane_stride/plane_size. */
|
int plane_count; /* Number of valid entries in plane_data/plane_stride/plane_size. */
|
||||||
const void *plane_data[GVFG_MAX_PLANES]; /* Plane pointers inside frame.data, valid until gvfg_release_frame(). */
|
const void *plane_data[GVFG_MAX_PLANES]; /* Plane pointers inside frame.data, valid until gvfg_release_frame(). */
|
||||||
int plane_stride[GVFG_MAX_PLANES]; /* Bytes from one row to the next for each plane. */
|
int plane_stride[GVFG_MAX_PLANES]; /* Bytes from one row to the next for each plane. */
|
||||||
@@ -168,15 +155,13 @@ extern "C"
|
|||||||
{
|
{
|
||||||
GVFG_EVENT_UNKNOWN = 0,
|
GVFG_EVENT_UNKNOWN = 0,
|
||||||
GVFG_EVENT_SIGNAL_CONNECTED = 1,
|
GVFG_EVENT_SIGNAL_CONNECTED = 1,
|
||||||
GVFG_EVENT_SIGNAL_DISCONNECTED = 2
|
GVFG_EVENT_SIGNAL_DISCONNECTED = 2,
|
||||||
|
/* First complete frame after stream start, plug-in, or format recovery is ready. */
|
||||||
|
GVFG_EVENT_STREAM_READY = 3,
|
||||||
|
/* Input format is changing; pause use of resources created for the old format. */
|
||||||
|
GVFG_EVENT_FORMAT_CHANGE_BEGIN = 4
|
||||||
} gvfg_event_type_t;
|
} gvfg_event_type_t;
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
gvfg_event_type_t type;
|
|
||||||
uint64_t timestamp_ns; /* Monotonic timestamp for ordering; not Unix/wall-clock time. */
|
|
||||||
} gvfg_event_t;
|
|
||||||
|
|
||||||
/* Opaque session handle created by gvfg_create() and released by gvfg_destroy(). */
|
/* Opaque session handle created by gvfg_create() and released by gvfg_destroy(). */
|
||||||
typedef struct gvfg_handle_t *gvfg_handle;
|
typedef struct gvfg_handle_t *gvfg_handle;
|
||||||
|
|
||||||
@@ -299,13 +284,11 @@ extern "C"
|
|||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* - frame: Frame descriptor returned by gvfg_read_frame(). Must not be NULL.
|
* - frame: Frame descriptor returned by gvfg_read_frame(). Must not be NULL.
|
||||||
* - out_layout: Receives plane pointers, strides, and sizes. Must not
|
* - out_layout: Receives plane pointers, strides, and sizes. Must not be NULL.
|
||||||
* be NULL. Set out_layout->struct_size to sizeof(gvfg_frame_layout_t) before
|
|
||||||
* calling so future SDKs can safely extend this struct.
|
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* - GVFG_OK on success.
|
* - GVFG_OK on success.
|
||||||
* - GVFG_EINVAL if frame/out_layout is NULL or struct_size is too small.
|
* - GVFG_EINVAL if frame or out_layout is NULL.
|
||||||
* - GVFG_ENOTSUP if the SDK cannot describe the frame layout.
|
* - GVFG_ENOTSUP if the SDK cannot describe the frame layout.
|
||||||
*
|
*
|
||||||
* The returned plane_data pointers are owned by the SDK and remain valid only
|
* The returned plane_data pointers are owned by the SDK and remain valid only
|
||||||
@@ -313,7 +296,7 @@ extern "C"
|
|||||||
*/
|
*/
|
||||||
GVFG_API gvfg_status_t gvfg_get_frame_layout(
|
GVFG_API gvfg_status_t gvfg_get_frame_layout(
|
||||||
_In_ const gvfg_frame_t *frame,
|
_In_ const gvfg_frame_t *frame,
|
||||||
_Inout_ gvfg_frame_layout_t *out_layout);
|
_Out_ gvfg_frame_layout_t *out_layout);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Release a frame returned by gvfg_read_frame().
|
* Release a frame returned by gvfg_read_frame().
|
||||||
@@ -349,7 +332,7 @@ extern "C"
|
|||||||
*/
|
*/
|
||||||
GVFG_API gvfg_status_t gvfg_poll_event(
|
GVFG_API gvfg_status_t gvfg_poll_event(
|
||||||
_In_ gvfg_handle handle,
|
_In_ gvfg_handle handle,
|
||||||
_Out_ gvfg_event_t *out_event,
|
_Out_ gvfg_event_type_t *out_event,
|
||||||
_In_ uint32_t timeout_ms);
|
_In_ uint32_t timeout_ms);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -377,15 +360,14 @@ extern "C"
|
|||||||
* Returns:
|
* Returns:
|
||||||
* - GVFG_OK on success.
|
* - GVFG_OK on success.
|
||||||
* - GVFG_EINVAL if handle or out_status is NULL.
|
* - GVFG_EINVAL if handle or out_status is NULL.
|
||||||
* - GVFG_EINVAL if out_status->struct_size is too small.
|
|
||||||
* - GVFG_ESTATE if no capture device is open.
|
* - GVFG_ESTATE if no capture device is open.
|
||||||
*
|
*
|
||||||
* No input signal is a normal state: the function returns GVFG_OK with
|
* No input signal is a normal state: the function returns GVFG_OK with
|
||||||
* out_status->connected set to 0. Set out_status->struct_size before calling.
|
* out_status->connected set to 0.
|
||||||
*/
|
*/
|
||||||
GVFG_API gvfg_status_t gvfg_get_signal_status(
|
GVFG_API gvfg_status_t gvfg_get_signal_status(
|
||||||
_In_ gvfg_handle handle,
|
_In_ gvfg_handle handle,
|
||||||
_Inout_ gvfg_signal_status_t *out_status);
|
_Out_ gvfg_signal_status_t *out_status);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Query runtime frame-delivery diagnostics.
|
* Query runtime frame-delivery diagnostics.
|
||||||
@@ -397,16 +379,14 @@ extern "C"
|
|||||||
* Returns:
|
* Returns:
|
||||||
* - GVFG_OK on success.
|
* - GVFG_OK on success.
|
||||||
* - GVFG_EINVAL if handle or out_info is NULL.
|
* - GVFG_EINVAL if handle or out_info is NULL.
|
||||||
* - GVFG_EINVAL if out_info->struct_size is too small.
|
|
||||||
*
|
*
|
||||||
* The result includes the latest delivered frame, SDK-measured capture FPS,
|
* The result includes the latest delivered frame, SDK-measured capture FPS,
|
||||||
* and the number of frames delivered by the SDK. Query current input signal
|
* and the number of frames delivered by the SDK. Query current input signal
|
||||||
* metadata separately with gvfg_get_signal_status(). Set out_info->struct_size
|
* metadata separately with gvfg_get_signal_status().
|
||||||
* before calling.
|
|
||||||
*/
|
*/
|
||||||
GVFG_API gvfg_status_t gvfg_get_runtime_info(
|
GVFG_API gvfg_status_t gvfg_get_runtime_info(
|
||||||
_In_ gvfg_handle handle,
|
_In_ gvfg_handle handle,
|
||||||
_Inout_ gvfg_runtime_info_t *out_info);
|
_Out_ gvfg_runtime_info_t *out_info);
|
||||||
|
|
||||||
/* Convert a gvfg_pixel_format_t value to a static English format name. */
|
/* Convert a gvfg_pixel_format_t value to a static English format name. */
|
||||||
GVFG_API const char *gvfg_pixel_format_name(
|
GVFG_API const char *gvfg_pixel_format_name(
|
||||||
|
|||||||
@@ -17,17 +17,22 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t struct_size; /* Set to sizeof(gvfg_debug_backend_stats_t) before calling. */
|
int width; /* Width of the most recent frame returned by gvfg_read_frame(). */
|
||||||
|
int height; /* Height of the most recent frame returned by gvfg_read_frame(). */
|
||||||
|
int bit_depth; /* Bits per color channel of the frame buffer. */
|
||||||
|
int pixel_format; /* gvfg_pixel_format_t value: YUY2 or Y210. */
|
||||||
|
int valid; /* Non-zero after a frame is returned during the current running session. */
|
||||||
|
} gvfg_debug_last_frame_info_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
int sdk_running;
|
int sdk_running;
|
||||||
int frame_held;
|
int frame_held;
|
||||||
uint32_t event_queue_depth;
|
uint32_t event_queue_depth;
|
||||||
|
|
||||||
double runtime_fps;
|
double runtime_fps;
|
||||||
uint64_t frames_returned;
|
uint64_t frames_returned;
|
||||||
int last_frame_width;
|
gvfg_debug_last_frame_info_t last_frame;
|
||||||
int last_frame_height;
|
|
||||||
int last_frame_pixel_format;
|
|
||||||
int last_frame_bit_depth;
|
|
||||||
|
|
||||||
int backend_state;
|
int backend_state;
|
||||||
uint64_t backend_frames_captured;
|
uint64_t backend_frames_captured;
|
||||||
|
|||||||
@@ -84,21 +84,21 @@ typedef struct pcies2mm_debug_state_t
|
|||||||
typedef enum pcies2mm_event_type_t
|
typedef enum pcies2mm_event_type_t
|
||||||
{
|
{
|
||||||
PCIES2MM_EVENT_PLUG_IN = 1,
|
PCIES2MM_EVENT_PLUG_IN = 1,
|
||||||
PCIES2MM_EVENT_PLUG_OUT = 2
|
PCIES2MM_EVENT_PLUG_OUT = 2,
|
||||||
|
PCIES2MM_EVENT_STREAM_READY = 3,
|
||||||
|
PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN = 4
|
||||||
} pcies2mm_event_type_t;
|
} pcies2mm_event_type_t;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PCIES2MM_EVENT_MASK_PLUG_IN = 1u << 0,
|
PCIES2MM_EVENT_MASK_PLUG_IN = 1u << 0,
|
||||||
PCIES2MM_EVENT_MASK_PLUG_OUT = 1u << 1,
|
PCIES2MM_EVENT_MASK_PLUG_OUT = 1u << 1,
|
||||||
|
PCIES2MM_EVENT_MASK_STREAM_READY = 1u << 2,
|
||||||
|
PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN = 1u << 3,
|
||||||
PCIES2MM_EVENT_MASK_DEFAULT = PCIES2MM_EVENT_MASK_PLUG_IN |
|
PCIES2MM_EVENT_MASK_DEFAULT = PCIES2MM_EVENT_MASK_PLUG_IN |
|
||||||
PCIES2MM_EVENT_MASK_PLUG_OUT
|
PCIES2MM_EVENT_MASK_PLUG_OUT |
|
||||||
|
PCIES2MM_EVENT_MASK_STREAM_READY |
|
||||||
|
PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct pcies2mm_event_t
|
typedef void (*pcies2mm_event_callback_t)(pcies2mm_event_type_t event, void *user);
|
||||||
{
|
|
||||||
pcies2mm_event_type_t type;
|
|
||||||
uint64_t timestamp_ns;
|
|
||||||
} pcies2mm_event_t;
|
|
||||||
|
|
||||||
typedef void (*pcies2mm_event_callback_t)(const pcies2mm_event_t *event, void *user);
|
|
||||||
|
|||||||
@@ -20,12 +20,6 @@ namespace
|
|||||||
constexpr uint32_t kDefaultRingBufferCount = 3;
|
constexpr uint32_t kDefaultRingBufferCount = 3;
|
||||||
constexpr uint32_t kMaxRingBufferCount = 16;
|
constexpr uint32_t kMaxRingBufferCount = 16;
|
||||||
|
|
||||||
static uint64_t steady_now_ns()
|
|
||||||
{
|
|
||||||
const auto now = std::chrono::steady_clock::now().time_since_epoch();
|
|
||||||
return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(now).count());
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool should_log_counter(uint64_t count)
|
static bool should_log_counter(uint64_t count)
|
||||||
{
|
{
|
||||||
return count <= 5 || (count % 60) == 0;
|
return count <= 5 || (count % 60) == 0;
|
||||||
@@ -109,6 +103,10 @@ namespace
|
|||||||
return PCIES2MM_EVENT_MASK_PLUG_IN;
|
return PCIES2MM_EVENT_MASK_PLUG_IN;
|
||||||
case PCIES2MM_EVENT_PLUG_OUT:
|
case PCIES2MM_EVENT_PLUG_OUT:
|
||||||
return PCIES2MM_EVENT_MASK_PLUG_OUT;
|
return PCIES2MM_EVENT_MASK_PLUG_OUT;
|
||||||
|
case PCIES2MM_EVENT_STREAM_READY:
|
||||||
|
return PCIES2MM_EVENT_MASK_STREAM_READY;
|
||||||
|
case PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN:
|
||||||
|
return PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -354,6 +352,7 @@ namespace gvfg::internal
|
|||||||
running_ = true;
|
running_ = true;
|
||||||
capture_active_ = startProbeNow;
|
capture_active_ = startProbeNow;
|
||||||
signal_probe_active_ = startProbeNow;
|
signal_probe_active_ = startProbeNow;
|
||||||
|
stream_ready_pending_ = startProbeNow;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
capture_thread_ = std::thread(&PcieS2mmCaptureSession::capture_thread_proc, this);
|
capture_thread_ = std::thread(&PcieS2mmCaptureSession::capture_thread_proc, this);
|
||||||
@@ -363,6 +362,7 @@ namespace gvfg::internal
|
|||||||
running_ = false;
|
running_ = false;
|
||||||
capture_active_ = false;
|
capture_active_ = false;
|
||||||
signal_probe_active_ = false;
|
signal_probe_active_ = false;
|
||||||
|
stream_ready_pending_ = false;
|
||||||
if (startProbeNow)
|
if (startProbeNow)
|
||||||
{
|
{
|
||||||
write_reg(video_base() + VIDEO_DMA_EN_OFFSET, 0);
|
write_reg(video_base() + VIDEO_DMA_EN_OFFSET, 0);
|
||||||
@@ -390,6 +390,7 @@ namespace gvfg::internal
|
|||||||
running_ = false;
|
running_ = false;
|
||||||
capture_active_ = false;
|
capture_active_ = false;
|
||||||
signal_probe_active_ = false;
|
signal_probe_active_ = false;
|
||||||
|
stream_ready_pending_ = false;
|
||||||
|
|
||||||
if (device_ != INVALID_HANDLE_VALUE)
|
if (device_ != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
@@ -731,6 +732,7 @@ namespace gvfg::internal
|
|||||||
if (dmaEnableOk && videoEnableOk)
|
if (dmaEnableOk && videoEnableOk)
|
||||||
{
|
{
|
||||||
signal_probe_active_.store(true, std::memory_order_release);
|
signal_probe_active_.store(true, std::memory_order_release);
|
||||||
|
stream_ready_pending_.store(true, std::memory_order_release);
|
||||||
capture_active_.store(true, std::memory_order_release);
|
capture_active_.store(true, std::memory_order_release);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -861,7 +863,6 @@ namespace gvfg::internal
|
|||||||
{
|
{
|
||||||
signal_present_.store(true, std::memory_order_release);
|
signal_present_.store(true, std::memory_order_release);
|
||||||
signal_presence_known_.store(true, std::memory_order_release);
|
signal_presence_known_.store(true, std::memory_order_release);
|
||||||
emit_event(PCIES2MM_EVENT_PLUG_IN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -870,10 +871,14 @@ namespace gvfg::internal
|
|||||||
--pending_events_;
|
--pending_events_;
|
||||||
publish_frame(slotIndex, static_cast<size_t>(ret));
|
publish_frame(slotIndex, static_cast<size_t>(ret));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stream_ready_pending_.exchange(false, std::memory_order_acq_rel))
|
||||||
|
emit_event(PCIES2MM_EVENT_STREAM_READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PcieS2mmCaptureSession::handle_format_change_event(uint32_t channel)
|
void PcieS2mmCaptureSession::handle_format_change_event(uint32_t channel)
|
||||||
{
|
{
|
||||||
|
emit_event(PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN);
|
||||||
write_reg(video_base() + VIDEO_DMA_EN_OFFSET, 0);
|
write_reg(video_base() + VIDEO_DMA_EN_OFFSET, 0);
|
||||||
write_reg(video_base() + VIDEO_EN_OFFSET, 0);
|
write_reg(video_base() + VIDEO_EN_OFFSET, 0);
|
||||||
capture_active_ = false;
|
capture_active_ = false;
|
||||||
@@ -906,6 +911,7 @@ namespace gvfg::internal
|
|||||||
void PcieS2mmCaptureSession::handle_unplug_event(uint32_t channel)
|
void PcieS2mmCaptureSession::handle_unplug_event(uint32_t channel)
|
||||||
{
|
{
|
||||||
signal_probe_active_.store(false, std::memory_order_release);
|
signal_probe_active_.store(false, std::memory_order_release);
|
||||||
|
stream_ready_pending_.store(false, std::memory_order_release);
|
||||||
signal_present_.store(false, std::memory_order_release);
|
signal_present_.store(false, std::memory_order_release);
|
||||||
signal_presence_known_.store(true, std::memory_order_release);
|
signal_presence_known_.store(true, std::memory_order_release);
|
||||||
write_reg(video_base() + VIDEO_DMA_EN_OFFSET, 0);
|
write_reg(video_base() + VIDEO_DMA_EN_OFFSET, 0);
|
||||||
@@ -942,6 +948,7 @@ namespace gvfg::internal
|
|||||||
write_reg(video_base() + VIDEO_DMA_EN_OFFSET, 0);
|
write_reg(video_base() + VIDEO_DMA_EN_OFFSET, 0);
|
||||||
write_reg(video_base() + VIDEO_EN_OFFSET, 0);
|
write_reg(video_base() + VIDEO_EN_OFFSET, 0);
|
||||||
capture_active_.store(false, std::memory_order_release);
|
capture_active_.store(false, std::memory_order_release);
|
||||||
|
stream_ready_pending_.store(false, std::memory_order_release);
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
stream_error_ = false;
|
stream_error_ = false;
|
||||||
@@ -956,6 +963,7 @@ namespace gvfg::internal
|
|||||||
|
|
||||||
capture_active_.store(true, std::memory_order_release);
|
capture_active_.store(true, std::memory_order_release);
|
||||||
signal_probe_active_.store(false, std::memory_order_release);
|
signal_probe_active_.store(false, std::memory_order_release);
|
||||||
|
stream_ready_pending_.store(true, std::memory_order_release);
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
stream_error_ = false;
|
stream_error_ = false;
|
||||||
@@ -1055,10 +1063,7 @@ namespace gvfg::internal
|
|||||||
user = event_callback_user_;
|
user = event_callback_user_;
|
||||||
}
|
}
|
||||||
|
|
||||||
pcies2mm_event_t event{};
|
callback(type, user);
|
||||||
event.type = type;
|
|
||||||
event.timestamp_ns = steady_now_ns();
|
|
||||||
callback(&event, user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pcies2mm_status_t PcieS2mmCaptureSession::fail(pcies2mm_status_t status, const char *where, DWORD winerr) const
|
pcies2mm_status_t PcieS2mmCaptureSession::fail(pcies2mm_status_t status, const char *where, DWORD winerr) const
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ namespace gvfg::internal
|
|||||||
std::atomic<bool> running_{false};
|
std::atomic<bool> running_{false};
|
||||||
std::atomic<bool> capture_active_{false};
|
std::atomic<bool> capture_active_{false};
|
||||||
std::atomic<bool> signal_probe_active_{false};
|
std::atomic<bool> signal_probe_active_{false};
|
||||||
|
std::atomic<bool> stream_ready_pending_{false};
|
||||||
mutable std::atomic<bool> signal_presence_known_{false};
|
mutable std::atomic<bool> signal_presence_known_{false};
|
||||||
mutable std::atomic<bool> signal_present_{false};
|
mutable std::atomic<bool> signal_present_{false};
|
||||||
std::thread capture_thread_;
|
std::thread capture_thread_;
|
||||||
|
|||||||
@@ -36,9 +36,8 @@ namespace
|
|||||||
static_assert(offsetof(gvfg_frame_t, frame_id) == 32);
|
static_assert(offsetof(gvfg_frame_t, frame_id) == 32);
|
||||||
|
|
||||||
static_assert(std::is_standard_layout_v<gvfg_frame_layout_t>);
|
static_assert(std::is_standard_layout_v<gvfg_frame_layout_t>);
|
||||||
static_assert(sizeof(gvfg_frame_layout_t) == 32, "gvfg_frame_layout_t x64 ABI must remain stable");
|
static_assert(sizeof(gvfg_frame_layout_t) == 32, "gvfg_frame_layout_t x64 ABI must remain frozen");
|
||||||
static_assert(offsetof(gvfg_frame_layout_t, struct_size) == 0);
|
static_assert(offsetof(gvfg_frame_layout_t, plane_count) == 0);
|
||||||
static_assert(offsetof(gvfg_frame_layout_t, plane_count) == 4);
|
|
||||||
static_assert(offsetof(gvfg_frame_layout_t, plane_data) == 8);
|
static_assert(offsetof(gvfg_frame_layout_t, plane_data) == 8);
|
||||||
static_assert(offsetof(gvfg_frame_layout_t, plane_stride) == 16);
|
static_assert(offsetof(gvfg_frame_layout_t, plane_stride) == 16);
|
||||||
static_assert(offsetof(gvfg_frame_layout_t, plane_size) == 24);
|
static_assert(offsetof(gvfg_frame_layout_t, plane_size) == 24);
|
||||||
@@ -131,6 +130,10 @@ namespace
|
|||||||
return GVFG_EVENT_SIGNAL_CONNECTED;
|
return GVFG_EVENT_SIGNAL_CONNECTED;
|
||||||
case PCIES2MM_EVENT_PLUG_OUT:
|
case PCIES2MM_EVENT_PLUG_OUT:
|
||||||
return GVFG_EVENT_SIGNAL_DISCONNECTED;
|
return GVFG_EVENT_SIGNAL_DISCONNECTED;
|
||||||
|
case PCIES2MM_EVENT_STREAM_READY:
|
||||||
|
return GVFG_EVENT_STREAM_READY;
|
||||||
|
case PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN:
|
||||||
|
return GVFG_EVENT_FORMAT_CHANGE_BEGIN;
|
||||||
default:
|
default:
|
||||||
return GVFG_EVENT_UNKNOWN;
|
return GVFG_EVENT_UNKNOWN;
|
||||||
}
|
}
|
||||||
@@ -297,7 +300,6 @@ struct gvfg_handle_t
|
|||||||
gvfg_status_t getSignalStatus(gvfg_signal_status_t &out)
|
gvfg_status_t getSignalStatus(gvfg_signal_status_t &out)
|
||||||
{
|
{
|
||||||
std::memset(&out, 0, sizeof(out));
|
std::memset(&out, 0, sizeof(out));
|
||||||
out.struct_size = sizeof(out);
|
|
||||||
const pcies2mm_status_t status = querySignal();
|
const pcies2mm_status_t status = querySignal();
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(stateMutex);
|
std::lock_guard<std::mutex> lock(stateMutex);
|
||||||
@@ -319,20 +321,8 @@ struct gvfg_handle_t
|
|||||||
return GVFG_ESTATE;
|
return GVFG_ESTATE;
|
||||||
|
|
||||||
std::memset(&out, 0, sizeof(out));
|
std::memset(&out, 0, sizeof(out));
|
||||||
out.struct_size = sizeof(out);
|
|
||||||
const uint64_t frames = deliveredFrames.load(std::memory_order_relaxed);
|
|
||||||
const bool deliveredValid = running.load(std::memory_order_relaxed) && frames > 0;
|
|
||||||
|
|
||||||
out.last_frame.valid = deliveredValid ? 1 : 0;
|
|
||||||
if (deliveredValid)
|
|
||||||
{
|
|
||||||
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));
|
|
||||||
out.last_frame.pixel_format = deliveredPixelFormat.load(std::memory_order_relaxed);
|
|
||||||
}
|
|
||||||
out.capture_fps = runtimeFps.load(std::memory_order_relaxed);
|
out.capture_fps = runtimeFps.load(std::memory_order_relaxed);
|
||||||
out.delivered_frames = frames;
|
out.delivered_frames = deliveredFrames.load(std::memory_order_relaxed);
|
||||||
return GVFG_OK;
|
return GVFG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,19 +335,17 @@ struct gvfg_handle_t
|
|||||||
PCIES2MM_EVENT_MASK_DEFAULT);
|
PCIES2MM_EVENT_MASK_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onBackendEvent(const pcies2mm_event_t *event, void *user)
|
static void onBackendEvent(pcies2mm_event_type_t event, void *user)
|
||||||
{
|
{
|
||||||
auto *self = static_cast<gvfg_handle_t *>(user);
|
auto *self = static_cast<gvfg_handle_t *>(user);
|
||||||
if (!self || !event)
|
if (!self)
|
||||||
return;
|
return;
|
||||||
self->emitEvent(*event);
|
self->emitEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitEvent(const pcies2mm_event_t &event)
|
void emitEvent(pcies2mm_event_type_t event)
|
||||||
{
|
{
|
||||||
gvfg_event_t out{};
|
const gvfg_event_type_t out = map_event_type(event);
|
||||||
out.type = map_event_type(event.type);
|
|
||||||
out.timestamp_ns = event.timestamp_ns;
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(eventMutex);
|
std::lock_guard<std::mutex> lock(eventMutex);
|
||||||
if (eventQueue.size() >= 64)
|
if (eventQueue.size() >= 64)
|
||||||
@@ -541,31 +529,40 @@ struct gvfg_handle_t
|
|||||||
backend->release_frame(frame);
|
backend->release_frame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
gvfg_status_t pollEvent(gvfg_event_t &out, uint32_t timeoutMs)
|
gvfg_status_t pollEvent(gvfg_event_type_t &out, uint32_t timeoutMs)
|
||||||
{
|
{
|
||||||
if (!backend || !running.load(std::memory_order_acquire))
|
if (!backend || !running.load(std::memory_order_acquire))
|
||||||
return GVFG_ESTATE;
|
return GVFG_ESTATE;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(eventMutex);
|
std::unique_lock<std::mutex> lock(eventMutex);
|
||||||
const auto hasEvent = [this]()
|
const auto eventAvailableOrStopped = [this]()
|
||||||
{
|
{
|
||||||
return !eventQueue.empty() || !running.load(std::memory_order_acquire);
|
return !eventQueue.empty() || !running.load(std::memory_order_acquire);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool waitConditionMet = false;
|
||||||
if (timeoutMs == 0)
|
if (timeoutMs == 0)
|
||||||
{
|
{
|
||||||
if (!hasEvent())
|
// Non-blocking: inspect the current state without sleeping.
|
||||||
return GVFG_ETIMEOUT;
|
waitConditionMet = eventAvailableOrStopped();
|
||||||
}
|
}
|
||||||
else if (timeoutMs == GVFG_TIMEOUT_INFINITE)
|
else if (timeoutMs == GVFG_TIMEOUT_INFINITE)
|
||||||
{
|
{
|
||||||
eventCv.wait(lock, hasEvent);
|
// Wake when an event arrives or capture is stopped.
|
||||||
|
eventCv.wait(lock, eventAvailableOrStopped);
|
||||||
|
waitConditionMet = true;
|
||||||
}
|
}
|
||||||
else if (!eventCv.wait_for(lock, std::chrono::milliseconds(timeoutMs), hasEvent))
|
else
|
||||||
{
|
{
|
||||||
return GVFG_ETIMEOUT;
|
waitConditionMet = eventCv.wait_for(lock,
|
||||||
|
std::chrono::milliseconds(timeoutMs),
|
||||||
|
eventAvailableOrStopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!waitConditionMet)
|
||||||
|
return GVFG_ETIMEOUT;
|
||||||
|
|
||||||
|
// A wake-up without an event means capture was stopped while waiting.
|
||||||
if (eventQueue.empty())
|
if (eventQueue.empty())
|
||||||
return GVFG_ESTATE;
|
return GVFG_ESTATE;
|
||||||
|
|
||||||
@@ -581,10 +578,14 @@ struct gvfg_handle_t
|
|||||||
out.sdk_running = running.load(std::memory_order_relaxed) ? 1 : 0;
|
out.sdk_running = running.load(std::memory_order_relaxed) ? 1 : 0;
|
||||||
out.runtime_fps = runtimeFps.load(std::memory_order_relaxed);
|
out.runtime_fps = runtimeFps.load(std::memory_order_relaxed);
|
||||||
out.frames_returned = deliveredFrames.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.valid = out.sdk_running && out.frames_returned > 0 ? 1 : 0;
|
||||||
out.last_frame_height = static_cast<int>(deliveredHeight.load(std::memory_order_relaxed));
|
if (out.last_frame.valid)
|
||||||
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));
|
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));
|
||||||
|
out.last_frame.pixel_format = deliveredPixelFormat.load(std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(frameMutex);
|
std::lock_guard<std::mutex> lock(frameMutex);
|
||||||
@@ -701,7 +702,7 @@ struct gvfg_handle_t
|
|||||||
pcies2mm_frame_t heldBackendFrame{};
|
pcies2mm_frame_t heldBackendFrame{};
|
||||||
std::mutex eventMutex;
|
std::mutex eventMutex;
|
||||||
std::condition_variable eventCv;
|
std::condition_variable eventCv;
|
||||||
std::deque<gvfg_event_t> eventQueue;
|
std::deque<gvfg_event_type_t> eventQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@@ -776,20 +777,12 @@ extern "C"
|
|||||||
{
|
{
|
||||||
if (!frame || !out_layout)
|
if (!frame || !out_layout)
|
||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
constexpr uint32_t kFrameLayoutV1Size =
|
|
||||||
static_cast<uint32_t>(offsetof(gvfg_frame_layout_t, plane_size) + sizeof(out_layout->plane_size));
|
|
||||||
const uint32_t callerSize = out_layout->struct_size;
|
|
||||||
if (callerSize < kFrameLayoutV1Size)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
gvfg_frame_layout_t layout{};
|
gvfg_frame_layout_t layout{};
|
||||||
layout.struct_size = sizeof(layout);
|
|
||||||
const gvfg_status_t status = populate_frame_layout(*frame, layout);
|
const gvfg_status_t status = populate_frame_layout(*frame, layout);
|
||||||
if (status != GVFG_OK)
|
if (status != GVFG_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
std::memcpy(out_layout, &layout, std::min<size_t>(callerSize, sizeof(layout)));
|
*out_layout = layout;
|
||||||
out_layout->struct_size = callerSize;
|
|
||||||
return GVFG_OK;
|
return GVFG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,7 +793,7 @@ extern "C"
|
|||||||
return handle->releaseFrame(*frame);
|
return handle->releaseFrame(*frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
gvfg_status_t gvfg_poll_event(gvfg_handle handle, gvfg_event_t *out_event, uint32_t timeout_ms)
|
gvfg_status_t gvfg_poll_event(gvfg_handle handle, gvfg_event_type_t *out_event, uint32_t timeout_ms)
|
||||||
{
|
{
|
||||||
if (!handle || !out_event)
|
if (!handle || !out_event)
|
||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
@@ -818,20 +811,12 @@ extern "C"
|
|||||||
{
|
{
|
||||||
if (!handle || !out_status)
|
if (!handle || !out_status)
|
||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
constexpr uint32_t kSignalStatusV1Size =
|
|
||||||
static_cast<uint32_t>(offsetof(gvfg_signal_status_t, bit_depth) + sizeof(out_status->bit_depth));
|
|
||||||
const uint32_t callerSize = out_status->struct_size;
|
|
||||||
if (callerSize < kSignalStatusV1Size)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
gvfg_signal_status_t statusInfo{};
|
gvfg_signal_status_t statusInfo{};
|
||||||
statusInfo.struct_size = sizeof(statusInfo);
|
|
||||||
const gvfg_status_t status = handle->getSignalStatus(statusInfo);
|
const gvfg_status_t status = handle->getSignalStatus(statusInfo);
|
||||||
if (status != GVFG_OK)
|
if (status != GVFG_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
std::memcpy(out_status, &statusInfo, std::min<size_t>(callerSize, sizeof(statusInfo)));
|
*out_status = statusInfo;
|
||||||
out_status->struct_size = callerSize;
|
|
||||||
return GVFG_OK;
|
return GVFG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -839,20 +824,12 @@ extern "C"
|
|||||||
{
|
{
|
||||||
if (!handle || !out_info)
|
if (!handle || !out_info)
|
||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
constexpr uint32_t kRuntimeInfoV1Size =
|
|
||||||
static_cast<uint32_t>(offsetof(gvfg_runtime_info_t, delivered_frames) + sizeof(out_info->delivered_frames));
|
|
||||||
const uint32_t callerSize = out_info->struct_size;
|
|
||||||
if (callerSize < kRuntimeInfoV1Size)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
gvfg_runtime_info_t runtimeInfo{};
|
gvfg_runtime_info_t runtimeInfo{};
|
||||||
runtimeInfo.struct_size = sizeof(runtimeInfo);
|
|
||||||
const gvfg_status_t status = handle->getRuntimeInfo(runtimeInfo);
|
const gvfg_status_t status = handle->getRuntimeInfo(runtimeInfo);
|
||||||
if (status != GVFG_OK)
|
if (status != GVFG_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
std::memcpy(out_info, &runtimeInfo, std::min<size_t>(callerSize, sizeof(runtimeInfo)));
|
*out_info = runtimeInfo;
|
||||||
out_info->struct_size = callerSize;
|
|
||||||
return GVFG_OK;
|
return GVFG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,18 +868,12 @@ extern "C"
|
|||||||
if (!handle || !out_stats)
|
if (!handle || !out_stats)
|
||||||
return GVFG_EINVAL;
|
return GVFG_EINVAL;
|
||||||
|
|
||||||
const uint32_t callerSize = out_stats->struct_size;
|
|
||||||
if (callerSize < sizeof(uint32_t) || callerSize > sizeof(gvfg_debug_backend_stats_t))
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
gvfg_debug_backend_stats_t stats{};
|
gvfg_debug_backend_stats_t stats{};
|
||||||
const gvfg_status_t status = handle->getDebugBackendStats(stats);
|
const gvfg_status_t status = handle->getDebugBackendStats(stats);
|
||||||
if (status != GVFG_OK)
|
if (status != GVFG_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
stats.struct_size = sizeof(stats);
|
*out_stats = stats;
|
||||||
std::memcpy(out_stats, &stats, callerSize);
|
|
||||||
out_stats->struct_size = callerSize;
|
|
||||||
return GVFG_OK;
|
return GVFG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user