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:
Mark.lin
2026-09-08 15:20:40 +08:00
parent 7e5d3d2cca
commit 3cd7fbbb3f
10 changed files with 36 additions and 10 deletions
+3 -1
View File
@@ -155,6 +155,7 @@ extern "C"
int pixel_format; /* gvfg_pixel_format_t value. */
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 timestamp_ns; /* Monotonic SDK delivery time; same clock domain as audio. */
} gvfg_frame_t;
typedef struct
@@ -166,6 +167,7 @@ extern "C"
uint32_t bits_per_sample; /* Bits in each native PCM sample. */
uint32_t reserved;
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;
/* Formats produced by gvfg_gpu_convert_to_buffer(). */
@@ -574,7 +576,7 @@ extern "C"
_In_ int channel_index,
_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);
/* 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(). */
size_t data_size_bytes;
uint64_t frame_id;
uint64_t timestamp_ns;
uint32_t width;
uint32_t height;
pcies2mm_pixel_format_t pixel_format;
@@ -761,6 +761,9 @@ namespace gvfg::internal
out.data = zero_copy_enabled_ ? data : copy_buffer_.data();
out.data_size_bytes = bytes;
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.height = stream_desc_.height;
out.pixel_format = stream_desc_.pixel_format;
+10 -4
View File
@@ -35,14 +35,15 @@ namespace
#if INTPTR_MAX == INT64_MAX
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(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_size) == 8);
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, timestamp_ns) == 40);
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(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_size) == 8);
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, bit_depth) == 32);
static_assert(offsetof(gvfg_frame_t, frame_id) == 40);
static_assert(offsetof(gvfg_frame_t, timestamp_ns) == 48);
#endif
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.bit_depth = static_cast<int>(frame.bit_depth);
out.frame_id = frame.frame_id;
out.timestamp_ns = frame.timestamp_ns;
noteDeliveredFrame(out.width, out.height, out.bit_depth, out.pixel_format);
return GVFG_OK;
@@ -532,7 +535,8 @@ struct gvfg_channel_session_t
frameToken.row_stride_bytes != expectedStride ||
frameToken.pixel_format != to_gvfg_pixel_format(heldBackendFrame.pixel_format) ||
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");
const pcies2mm_status_t st = backend->release_frame(heldBackendFrame);
@@ -756,6 +760,7 @@ struct gvfg_channel_session_t
out.channels = format.channels;
out.bits_per_sample = format.bits_per_sample;
out.frame_id = audioFrameId;
out.timestamp_ns = now_ns();
heldAudioFrame = out;
}
return GVFG_OK;
@@ -769,7 +774,8 @@ struct gvfg_channel_session_t
if (token.data != heldAudioFrame.data || token.data_size != heldAudioFrame.data_size ||
token.sample_rate != heldAudioFrame.sample_rate || token.channels != heldAudioFrame.channels ||
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");
heldAudioFrame = {};
audioFrameHeld = false;