Expose common delivery timestamps for A/V sync
Compared with 7e5d3d2:
- Add monotonic timestamp_ns fields to public video and audio frame tokens so applications can compare delivery timing in one SDK clock domain.
- Stamp video delivery in the PCIe backend and audio delivery in the GVFG facade while preserving complete read/release token validation.
- Update x64 ABI assertions and bump the standalone SDK version to 0.2.0 for the public frame-structure change.
- Document timestamp semantics and limitations across the README, customer API references, internal ABI notes, and build guidance.
- Leave the standalone preview sample behavior unchanged; timestamp-based synchronization remains an application policy.
Validation: git diff --check and focused source inspection passed; no build, ABI consumer rebuild, recording, or hardware capture validation was run.
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
project(gvfg_standalone VERSION 0.1.0 LANGUAGES CXX)
|
project(gvfg_standalone VERSION 0.2.0 LANGUAGES CXX)
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ Application 收到 `GVFG_EVENT_SIGNAL_DISCONNECTED` 後應暫停 video/audio rea
|
|||||||
等待 `GVFG_EVENT_SIGNAL_CONNECTED` 或 stop 再喚醒 worker,不應在已知無訊號時持續
|
等待 `GVFG_EVENT_SIGNAL_CONNECTED` 或 stop 再喚醒 worker,不應在已知無訊號時持續
|
||||||
輪詢 timeout。
|
輪詢 timeout。
|
||||||
|
|
||||||
|
每個成功取得的 video/audio frame 都包含 `timestamp_ns`。兩者使用相同的
|
||||||
|
monotonic SDK delivery clock,可供 Application 做 soft A/V sync;它不是硬體
|
||||||
|
capture timestamp,也不能跨 process 或 session 比較。
|
||||||
|
|
||||||
每個 channel 預設為 copy mode。指定 channel open 後不可切換該路模式;
|
每個 channel 預設為 copy mode。指定 channel open 後不可切換該路模式;
|
||||||
另一條尚未 open 的 channel 仍可獨立選擇。Zero-copy mode 仍使用相同的 `gvfg_read_channel_frame()` /
|
另一條尚未 open 的 channel 仍可獨立選擇。Zero-copy mode 仍使用相同的 `gvfg_read_channel_frame()` /
|
||||||
`gvfg_release_channel_frame()` ownership contract,每次成功 read 都必須 release。
|
`gvfg_release_channel_frame()` ownership contract,每次成功 read 都必須 release。
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ Audio 採用相同的 pull 與 ownership 模型:
|
|||||||
可用 `gvfg_strerror()` 取得靜態英文說明字串;呼叫端不可釋放該字串。
|
可用 `gvfg_strerror()` 取得靜態英文說明字串;呼叫端不可釋放該字串。
|
||||||
|
|
||||||
可用 `gvfg_get_version()` 查詢目前實際載入的 `gvfg.dll` 版本。回傳值為
|
可用 `gvfg_get_version()` 查詢目前實際載入的 `gvfg.dll` 版本。回傳值為
|
||||||
靜態字串,例如 `"0.1.0"`,呼叫端不可釋放。
|
靜態字串,例如 `"0.2.0"`,呼叫端不可釋放。
|
||||||
需要記錄最近一次失敗的詳細原因時,可在 API 失敗後立即呼叫
|
需要記錄最近一次失敗的詳細原因時,可在 API 失敗後立即呼叫
|
||||||
`gvfg_get_channel_last_error_detail()`;driver/register 等內部診斷仍保留在 debug API。
|
`gvfg_get_channel_last_error_detail()`;driver/register 等內部診斷仍保留在 debug API。
|
||||||
|
|
||||||
@@ -168,6 +168,7 @@ Audio 採用相同的 pull 與 ownership 模型:
|
|||||||
- `row_stride_bytes`:相鄰兩列起點的 byte 距離。
|
- `row_stride_bytes`:相鄰兩列起點的 byte 距離。
|
||||||
- `pixel_format`、`bit_depth`:原生 payload 格式。
|
- `pixel_format`、`bit_depth`:原生 payload 格式。
|
||||||
- `frame_id`:同一次 start/stop session 中單調遞增的識別值。
|
- `frame_id`:同一次 start/stop session 中單調遞增的識別值。
|
||||||
|
- `timestamp_ns`:SDK monotonic delivery timestamp,與 audio 使用相同 clock domain。
|
||||||
|
|
||||||
### PCM audio
|
### PCM audio
|
||||||
|
|
||||||
@@ -180,6 +181,10 @@ Audio 採用相同的 pull 與 ownership 模型:
|
|||||||
- `data`、`data_size`:SDK-owned PCM 與本次有效 byte 數。
|
- `data`、`data_size`:SDK-owned PCM 與本次有效 byte 數。
|
||||||
- `sample_rate`、`channels`、`bits_per_sample`:此 frame 的 PCM 格式。
|
- `sample_rate`、`channels`、`bits_per_sample`:此 frame 的 PCM 格式。
|
||||||
- `frame_id`:同一次 start/stop session 中單調遞增的 audio frame ID。
|
- `frame_id`:同一次 start/stop session 中單調遞增的 audio frame ID。
|
||||||
|
- `timestamp_ns`:SDK monotonic delivery timestamp,與 video 使用相同 clock domain。
|
||||||
|
|
||||||
|
`timestamp_ns` 用於比較同一 process/session 內的 video/audio delivery timing;它
|
||||||
|
不是 driver 或硬體 capture timestamp。
|
||||||
|
|
||||||
目前 audio 僅支援 CH0,且必須與 video 一起啟動;不支援 audio-only。公開
|
目前 audio 僅支援 CH0,且必須與 video 一起啟動;不支援 audio-only。公開
|
||||||
audio API 不是 zero-copy,但上層仍使用和 video 相同的 read/release contract。
|
audio API 不是 zero-copy,但上層仍使用和 video 相同的 read/release contract。
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ register 與 DMA 實作不屬於本文件。
|
|||||||
| `pixel_format` | `int` | `gvfg_pixel_format_t` 值 |
|
| `pixel_format` | `int` | `gvfg_pixel_format_t` 值 |
|
||||||
| `bit_depth` | `int` | 原生 frame 每色彩 channel 的 bit depth |
|
| `bit_depth` | `int` | 原生 frame 每色彩 channel 的 bit depth |
|
||||||
| `frame_id` | `uint64_t` | 此次 start/stop run 中單調遞增的 frame ID |
|
| `frame_id` | `uint64_t` | 此次 start/stop run 中單調遞增的 frame ID |
|
||||||
|
| `timestamp_ns` | `uint64_t` | SDK 交付時間;與 audio 共用 monotonic clock,單位 ns |
|
||||||
|
|
||||||
Caller 不得修改任何欄位再 release。SDK 會將完整 token 與目前 held frame 比對。
|
Caller 不得修改任何欄位再 release。SDK 會將完整 token 與目前 held frame 比對。
|
||||||
|
|
||||||
@@ -127,10 +128,14 @@ Driver 一次傳回多少 bytes、buffer capacity 與 block alignment 均由 SDK
|
|||||||
| `channels` | `uint32_t` | interleaved PCM channel 數 |
|
| `channels` | `uint32_t` | interleaved PCM channel 數 |
|
||||||
| `bits_per_sample` | `uint32_t` | 每個 PCM sample 的 bit 數 |
|
| `bits_per_sample` | `uint32_t` | 每個 PCM sample 的 bit 數 |
|
||||||
| `frame_id` | `uint64_t` | 此次 start/stop run 中單調遞增的 audio frame ID |
|
| `frame_id` | `uint64_t` | 此次 start/stop run 中單調遞增的 audio frame ID |
|
||||||
|
| `timestamp_ns` | `uint64_t` | SDK 交付時間;與 video 共用 monotonic clock,單位 ns |
|
||||||
|
|
||||||
與 video 相同,每個 channel 同時只能持有一個 audio frame,且 caller 不得修改
|
與 video 相同,每個 channel 同時只能持有一個 audio frame,且 caller 不得修改
|
||||||
descriptor 後再 release。
|
descriptor 後再 release。
|
||||||
|
|
||||||
|
Video/audio 的 `timestamp_ns` 可在同一 process/session 內直接比較。它代表 SDK
|
||||||
|
delivery timing,不是 driver 或硬體 capture timestamp。
|
||||||
|
|
||||||
### 1.9 `gvfg_gpu_output_format_t`
|
### 1.9 `gvfg_gpu_output_format_t`
|
||||||
|
|
||||||
| 成員 | 值 | 說明 |
|
| 成員 | 值 | 說明 |
|
||||||
@@ -491,7 +496,7 @@ gvfg_status_t gvfg_get_channel_runtime_info(
|
|||||||
const char *gvfg_get_version(void);
|
const char *gvfg_get_version(void);
|
||||||
```
|
```
|
||||||
|
|
||||||
- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"0.1.0"`。
|
- 回傳目前實際載入的 GVFG runtime DLL 版本,例如 `"0.2.0"`。
|
||||||
- 回傳值是靜態 null-terminated 字串,caller 不可 free。
|
- 回傳值是靜態 null-terminated 字串,caller 不可 free。
|
||||||
- 可用於 log、問題回報,以及確認 header、LIB、DLL 是否來自同一版本。
|
- 可用於 log、問題回報,以及確認 header、LIB、DLL 是否來自同一版本。
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ driver pointer,才能再次 read。SDK 不根據 read 間隔推算 frame loss
|
|||||||
Facade 在 release 時驗證原 token 的 data、size、width、height、stride、format、
|
Facade 在 release 時驗證原 token 的 data、size、width、height、stride、format、
|
||||||
bit depth 與 frame ID。任何欄位遭修改都回傳 `GVFG_EINVAL`。
|
bit depth 與 frame ID。任何欄位遭修改都回傳 `GVFG_EINVAL`。
|
||||||
|
|
||||||
x64 `gvfg_frame_t` ABI 已在 `gvfg_capture.cpp` 以 static assertions 固定為 48 bytes
|
x64 `gvfg_frame_t` ABI 已在 `gvfg_capture.cpp` 以 static assertions 固定為 56 bytes
|
||||||
及明確欄位 offsets。修改公開 struct 時必須視為 ABI 變更,不能只重新編譯 DLL。
|
及明確欄位 offsets。修改公開 struct 時必須視為 ABI 變更,不能只重新編譯 DLL。
|
||||||
新增 metadata 優先考慮新 query API 或帶 size/version 的新 struct。
|
新增 metadata 優先考慮新 query API 或帶 size/version 的新 struct。
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
版本只有一個來源:根目錄 `CMakeLists.txt` 的 `project()`:
|
版本只有一個來源:根目錄 `CMakeLists.txt` 的 `project()`:
|
||||||
|
|
||||||
```cmake
|
```cmake
|
||||||
project(gvfg_standalone VERSION 0.1.0 LANGUAGES CXX)
|
project(gvfg_standalone VERSION 0.2.0 LANGUAGES CXX)
|
||||||
```
|
```
|
||||||
|
|
||||||
例如準備 `0.2.0` 時改成:
|
例如準備 `0.2.0` 時改成:
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ extern "C"
|
|||||||
int pixel_format; /* gvfg_pixel_format_t value. */
|
int pixel_format; /* gvfg_pixel_format_t value. */
|
||||||
int bit_depth; /* Bits per color channel of the native frame. */
|
int bit_depth; /* Bits per color channel of the native frame. */
|
||||||
uint64_t frame_id; /* Monotonic identifier within the current channel start/stop run. */
|
uint64_t frame_id; /* Monotonic identifier within the current channel start/stop run. */
|
||||||
|
uint64_t timestamp_ns; /* Monotonic SDK delivery time; same clock domain as audio. */
|
||||||
} gvfg_frame_t;
|
} gvfg_frame_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -166,6 +167,7 @@ extern "C"
|
|||||||
uint32_t bits_per_sample; /* Bits in each native PCM sample. */
|
uint32_t bits_per_sample; /* Bits in each native PCM sample. */
|
||||||
uint32_t reserved;
|
uint32_t reserved;
|
||||||
uint64_t frame_id; /* Monotonic identifier within the current start/stop run. */
|
uint64_t frame_id; /* Monotonic identifier within the current start/stop run. */
|
||||||
|
uint64_t timestamp_ns; /* Monotonic SDK delivery time; same clock domain as video. */
|
||||||
} gvfg_audio_frame_t;
|
} gvfg_audio_frame_t;
|
||||||
|
|
||||||
/* Formats produced by gvfg_gpu_convert_to_buffer(). */
|
/* Formats produced by gvfg_gpu_convert_to_buffer(). */
|
||||||
@@ -574,7 +576,7 @@ extern "C"
|
|||||||
_In_ int channel_index,
|
_In_ int channel_index,
|
||||||
_Out_ gvfg_runtime_info_t *out_info);
|
_Out_ gvfg_runtime_info_t *out_info);
|
||||||
|
|
||||||
/* Return the loaded GVFG runtime DLL version, for example "0.1.0". */
|
/* Return the loaded GVFG runtime DLL version, for example "0.2.0". */
|
||||||
GVFG_API const char *gvfg_get_version(void);
|
GVFG_API const char *gvfg_get_version(void);
|
||||||
|
|
||||||
/* 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. */
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ typedef struct pcies2mm_frame_t
|
|||||||
const void *data; /* Valid until the next PcieS2mmCaptureSession::wait_frame() or close(). */
|
const void *data; /* Valid until the next PcieS2mmCaptureSession::wait_frame() or close(). */
|
||||||
size_t data_size_bytes;
|
size_t data_size_bytes;
|
||||||
uint64_t frame_id;
|
uint64_t frame_id;
|
||||||
|
uint64_t timestamp_ns;
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
pcies2mm_pixel_format_t pixel_format;
|
pcies2mm_pixel_format_t pixel_format;
|
||||||
|
|||||||
@@ -761,6 +761,9 @@ namespace gvfg::internal
|
|||||||
out.data = zero_copy_enabled_ ? data : copy_buffer_.data();
|
out.data = zero_copy_enabled_ ? data : copy_buffer_.data();
|
||||||
out.data_size_bytes = bytes;
|
out.data_size_bytes = bytes;
|
||||||
out.frame_id = delivered_sequence_;
|
out.frame_id = delivered_sequence_;
|
||||||
|
out.timestamp_ns = static_cast<uint64_t>(
|
||||||
|
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||||
|
std::chrono::steady_clock::now().time_since_epoch()).count());
|
||||||
out.width = stream_desc_.width;
|
out.width = stream_desc_.width;
|
||||||
out.height = stream_desc_.height;
|
out.height = stream_desc_.height;
|
||||||
out.pixel_format = stream_desc_.pixel_format;
|
out.pixel_format = stream_desc_.pixel_format;
|
||||||
|
|||||||
@@ -35,14 +35,15 @@ namespace
|
|||||||
#if INTPTR_MAX == INT64_MAX
|
#if INTPTR_MAX == INT64_MAX
|
||||||
static_assert(sizeof(gvfg_audio_format_t) == 12, "gvfg_audio_format_t ABI must remain frozen");
|
static_assert(sizeof(gvfg_audio_format_t) == 12, "gvfg_audio_format_t ABI must remain frozen");
|
||||||
static_assert(std::is_standard_layout_v<gvfg_audio_frame_t>);
|
static_assert(std::is_standard_layout_v<gvfg_audio_frame_t>);
|
||||||
static_assert(sizeof(gvfg_audio_frame_t) == 40, "gvfg_audio_frame_t x64 ABI must remain frozen");
|
static_assert(sizeof(gvfg_audio_frame_t) == 48, "gvfg_audio_frame_t x64 ABI must remain frozen");
|
||||||
static_assert(offsetof(gvfg_audio_frame_t, data) == 0);
|
static_assert(offsetof(gvfg_audio_frame_t, data) == 0);
|
||||||
static_assert(offsetof(gvfg_audio_frame_t, data_size) == 8);
|
static_assert(offsetof(gvfg_audio_frame_t, data_size) == 8);
|
||||||
static_assert(offsetof(gvfg_audio_frame_t, sample_rate) == 16);
|
static_assert(offsetof(gvfg_audio_frame_t, sample_rate) == 16);
|
||||||
static_assert(offsetof(gvfg_audio_frame_t, frame_id) == 32);
|
static_assert(offsetof(gvfg_audio_frame_t, frame_id) == 32);
|
||||||
|
static_assert(offsetof(gvfg_audio_frame_t, timestamp_ns) == 40);
|
||||||
static_assert(sizeof(gvfg_runtime_info_t) == 56, "gvfg_runtime_info_t x64 ABI must remain frozen");
|
static_assert(sizeof(gvfg_runtime_info_t) == 56, "gvfg_runtime_info_t x64 ABI must remain frozen");
|
||||||
static_assert(std::is_standard_layout_v<gvfg_frame_t>);
|
static_assert(std::is_standard_layout_v<gvfg_frame_t>);
|
||||||
static_assert(sizeof(gvfg_frame_t) == 48, "gvfg_frame_t x64 ABI must remain frozen");
|
static_assert(sizeof(gvfg_frame_t) == 56, "gvfg_frame_t x64 ABI must remain frozen");
|
||||||
static_assert(offsetof(gvfg_frame_t, data) == 0);
|
static_assert(offsetof(gvfg_frame_t, data) == 0);
|
||||||
static_assert(offsetof(gvfg_frame_t, data_size) == 8);
|
static_assert(offsetof(gvfg_frame_t, data_size) == 8);
|
||||||
static_assert(offsetof(gvfg_frame_t, width) == 16);
|
static_assert(offsetof(gvfg_frame_t, width) == 16);
|
||||||
@@ -51,6 +52,7 @@ namespace
|
|||||||
static_assert(offsetof(gvfg_frame_t, pixel_format) == 28);
|
static_assert(offsetof(gvfg_frame_t, pixel_format) == 28);
|
||||||
static_assert(offsetof(gvfg_frame_t, bit_depth) == 32);
|
static_assert(offsetof(gvfg_frame_t, bit_depth) == 32);
|
||||||
static_assert(offsetof(gvfg_frame_t, frame_id) == 40);
|
static_assert(offsetof(gvfg_frame_t, frame_id) == 40);
|
||||||
|
static_assert(offsetof(gvfg_frame_t, timestamp_ns) == 48);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void copy_cstr(char *dst, size_t dstSize, const char *src)
|
void copy_cstr(char *dst, size_t dstSize, const char *src)
|
||||||
@@ -504,6 +506,7 @@ struct gvfg_channel_session_t
|
|||||||
out.pixel_format = to_gvfg_pixel_format(frame.pixel_format);
|
out.pixel_format = to_gvfg_pixel_format(frame.pixel_format);
|
||||||
out.bit_depth = static_cast<int>(frame.bit_depth);
|
out.bit_depth = static_cast<int>(frame.bit_depth);
|
||||||
out.frame_id = frame.frame_id;
|
out.frame_id = frame.frame_id;
|
||||||
|
out.timestamp_ns = frame.timestamp_ns;
|
||||||
noteDeliveredFrame(out.width, out.height, out.bit_depth, out.pixel_format);
|
noteDeliveredFrame(out.width, out.height, out.bit_depth, out.pixel_format);
|
||||||
|
|
||||||
return GVFG_OK;
|
return GVFG_OK;
|
||||||
@@ -532,7 +535,8 @@ struct gvfg_channel_session_t
|
|||||||
frameToken.row_stride_bytes != expectedStride ||
|
frameToken.row_stride_bytes != expectedStride ||
|
||||||
frameToken.pixel_format != to_gvfg_pixel_format(heldBackendFrame.pixel_format) ||
|
frameToken.pixel_format != to_gvfg_pixel_format(heldBackendFrame.pixel_format) ||
|
||||||
frameToken.bit_depth != static_cast<int>(heldBackendFrame.bit_depth) ||
|
frameToken.bit_depth != static_cast<int>(heldBackendFrame.bit_depth) ||
|
||||||
frameToken.frame_id != heldBackendFrame.frame_id)
|
frameToken.frame_id != heldBackendFrame.frame_id ||
|
||||||
|
frameToken.timestamp_ns != heldBackendFrame.timestamp_ns)
|
||||||
return reject(GVFG_EINVAL, "gvfg_release_channel_frame rejected: frame token does not match the held frame");
|
return reject(GVFG_EINVAL, "gvfg_release_channel_frame rejected: frame token does not match the held frame");
|
||||||
|
|
||||||
const pcies2mm_status_t st = backend->release_frame(heldBackendFrame);
|
const pcies2mm_status_t st = backend->release_frame(heldBackendFrame);
|
||||||
@@ -756,6 +760,7 @@ struct gvfg_channel_session_t
|
|||||||
out.channels = format.channels;
|
out.channels = format.channels;
|
||||||
out.bits_per_sample = format.bits_per_sample;
|
out.bits_per_sample = format.bits_per_sample;
|
||||||
out.frame_id = audioFrameId;
|
out.frame_id = audioFrameId;
|
||||||
|
out.timestamp_ns = now_ns();
|
||||||
heldAudioFrame = out;
|
heldAudioFrame = out;
|
||||||
}
|
}
|
||||||
return GVFG_OK;
|
return GVFG_OK;
|
||||||
@@ -769,7 +774,8 @@ struct gvfg_channel_session_t
|
|||||||
if (token.data != heldAudioFrame.data || token.data_size != heldAudioFrame.data_size ||
|
if (token.data != heldAudioFrame.data || token.data_size != heldAudioFrame.data_size ||
|
||||||
token.sample_rate != heldAudioFrame.sample_rate || token.channels != heldAudioFrame.channels ||
|
token.sample_rate != heldAudioFrame.sample_rate || token.channels != heldAudioFrame.channels ||
|
||||||
token.bits_per_sample != heldAudioFrame.bits_per_sample ||
|
token.bits_per_sample != heldAudioFrame.bits_per_sample ||
|
||||||
token.reserved != heldAudioFrame.reserved || token.frame_id != heldAudioFrame.frame_id)
|
token.reserved != heldAudioFrame.reserved || token.frame_id != heldAudioFrame.frame_id ||
|
||||||
|
token.timestamp_ns != heldAudioFrame.timestamp_ns)
|
||||||
return reject(GVFG_EINVAL, "gvfg_release_channel_audio_frame rejected: frame token does not match the held audio frame");
|
return reject(GVFG_EINVAL, "gvfg_release_channel_audio_frame rejected: frame token does not match the held audio frame");
|
||||||
heldAudioFrame = {};
|
heldAudioFrame = {};
|
||||||
audioFrameHeld = false;
|
audioFrameHeld = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user