Make capture metadata event-driven
Stop querying GigabyteLib video and audio information for every captured frame. Refresh cached video metadata at open, start, format changes, and signal events, and refresh audio metadata at stream start. Ignore the vendor FrameCount fields as requested by the driver and library owner. Generate independent SDK delivery IDs for video and audio, reset them for every channel start, and document the new public frame_id semantics. Clarify diagnostic ownership with LIB, SDK, and APP log prefixes. Add frame-only video and audio path counters, separate application and SDK failures, remove redundant byte and timeout counters, and keep vendor GetFrame timing tightly scoped to the actual API calls. Update customer documentation and internal diagnostic text to match the event-driven metadata and SDK-owned frame IDs.
This commit is contained in:
@@ -205,7 +205,7 @@ extern "C"
|
||||
int row_stride_bytes; /* Byte distance between the starts of adjacent rows. */
|
||||
int pixel_format; /* gvfg_pixel_format_t value. */
|
||||
int bit_depth; /* Bits per color channel of the native frame. */
|
||||
uint64_t frame_id; /* GigabyteLib GVFG_VIDEO_INFO.FrameCount. */
|
||||
uint64_t frame_id; /* SDK delivery sequence; starts at 1 for each channel start. */
|
||||
uint64_t timestamp_ns; /* Monotonic SDK delivery time; same clock domain as audio. */
|
||||
} gvfg_frame_t;
|
||||
|
||||
@@ -217,7 +217,7 @@ extern "C"
|
||||
uint32_t channels; /* Interleaved PCM channel count. */
|
||||
uint32_t bits_per_sample; /* Bits in each native PCM sample. */
|
||||
uint32_t reserved;
|
||||
uint64_t frame_id; /* GigabyteLib GVFG_AUDIO_INFO.FrameCount. */
|
||||
uint64_t frame_id; /* SDK delivery sequence; starts at 1 for each channel start. */
|
||||
uint64_t timestamp_ns; /* Monotonic SDK delivery time; same clock domain as video. */
|
||||
} gvfg_audio_frame_t;
|
||||
|
||||
@@ -625,9 +625,8 @@ extern "C"
|
||||
|
||||
/*
|
||||
* Copy the most recent detailed fault or rejected API call for one
|
||||
* channel. Event-poll timeouts are not stored; frame-read timeouts currently
|
||||
* retain the backend timeout detail. A successful gvfg_start_channel()
|
||||
* begins a new diagnostic lifetime.
|
||||
* channel. Normal frame-read and event-poll timeouts are not stored.
|
||||
* A successful gvfg_start_channel() begins a new diagnostic lifetime.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_channel_last_error_detail(
|
||||
GVFG_PARAM_IN gvfg_handle handle,
|
||||
|
||||
@@ -20,12 +20,11 @@ typedef struct
|
||||
int running;
|
||||
int frame_held;
|
||||
uint32_t event_queue_depth;
|
||||
uint64_t frame_wait_timeouts;
|
||||
uint64_t video_event_wakes;
|
||||
uint64_t video_frames_from_lib;
|
||||
uint64_t audio_dma_event_wakes;
|
||||
uint64_t extra_audio_event_wakes;
|
||||
uint64_t audio_frames_from_driver;
|
||||
uint64_t audio_bytes_from_driver;
|
||||
uint64_t audio_frames_from_lib;
|
||||
uint64_t get_frame_timing_samples;
|
||||
double get_frame_timing_average_us;
|
||||
double get_frame_timing_max300_us;
|
||||
|
||||
@@ -196,8 +196,9 @@ gvfg_status_t GigabyteCaptureSession::set_video_format(gvfg_pixel_format_t forma
|
||||
const ULONG colorDepth = format == GVFG_PIXFMT_Y210
|
||||
? GVFG_VIDEO_COLOR_DEPTH_10_BITS
|
||||
: GVFG_VIDEO_COLOR_DEPTH_8_BITS;
|
||||
return from_vendor(GvfgSetVideoColorDepth(context_, channel_, colorDepth),
|
||||
"GvfgSetVideoColorDepth");
|
||||
const gvfg_status_t status = from_vendor(
|
||||
GvfgSetVideoColorDepth(context_, channel_, colorDepth), "GvfgSetVideoColorDepth");
|
||||
return status == GVFG_OK ? refresh_video_info() : status;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::refresh_video_info() const
|
||||
@@ -230,13 +231,9 @@ gvfg_status_t GigabyteCaptureSession::get_signal_status(gvfg_signal_status_t &ou
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
const gvfg_status_t status = refresh_video_info();
|
||||
if (status == GVFG_OK)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
out = cached_signal_;
|
||||
}
|
||||
return status;
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
out = cached_signal_;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::get_device_capabilities(
|
||||
@@ -296,17 +293,27 @@ gvfg_status_t GigabyteCaptureSession::get_audio_format(GigabyteAudioInfo &out) c
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
const gvfg_status_t status = from_vendor(
|
||||
GvfgGetAudioInfo(context_, channel_, &audio_info_), "GvfgGetAudioInfo");
|
||||
const gvfg_status_t status = refresh_audio_info();
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
out = {};
|
||||
out.sample_rate = audio_info_.SamplesPerSec;
|
||||
out.channels = audio_info_.Channels;
|
||||
out.bits_per_sample = audio_info_.BitsPerSample;
|
||||
out.frames_per_second = audio_info_.FramesPerSec;
|
||||
out.frame_bytes = audio_info_.cbBufSize;
|
||||
out.frame_count = audio_info_.FrameCount;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::refresh_audio_info() const
|
||||
{
|
||||
GVFG_AUDIO_INFO info{};
|
||||
const gvfg_status_t status = from_vendor(
|
||||
GvfgGetAudioInfo(context_, channel_, &info), "GvfgGetAudioInfo");
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
audio_info_ = info;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
@@ -326,6 +333,9 @@ gvfg_status_t GigabyteCaptureSession::configure_stream()
|
||||
const gvfg_status_t openStatus = ensure_vendor_channel_open();
|
||||
if (openStatus != GVFG_OK)
|
||||
return openStatus;
|
||||
const gvfg_status_t infoStatus = refresh_video_info();
|
||||
if (infoStatus != GVFG_OK)
|
||||
return infoStatus;
|
||||
configured_ = true;
|
||||
return GVFG_OK;
|
||||
}
|
||||
@@ -393,11 +403,7 @@ gvfg_status_t GigabyteCaptureSession::wait_frame(uint32_t timeoutMs, gvfg_frame_
|
||||
const DWORD waitMs = timeoutMs == UINT32_MAX ? INFINITE : timeoutMs;
|
||||
const DWORD wait = WaitForMultipleObjects(count, handles.data(), FALSE, waitMs);
|
||||
if (wait == WAIT_TIMEOUT)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
++wait_timeout_count_;
|
||||
return GVFG_ETIMEOUT;
|
||||
}
|
||||
if (wait == WAIT_OBJECT_0)
|
||||
return GVFG_ESTATE;
|
||||
if (wait != WAIT_OBJECT_0 + 1 && wait != WAIT_OBJECT_0 + 2)
|
||||
@@ -407,10 +413,6 @@ gvfg_status_t GigabyteCaptureSession::wait_frame(uint32_t timeoutMs, gvfg_frame_
|
||||
++video_event_wakes_;
|
||||
}
|
||||
|
||||
const auto begin = std::chrono::steady_clock::now();
|
||||
const gvfg_status_t infoStatus = refresh_video_info();
|
||||
if (infoStatus != GVFG_OK)
|
||||
return infoStatus;
|
||||
gvfg_signal_status_t signal{};
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
@@ -420,32 +422,34 @@ gvfg_status_t GigabyteCaptureSession::wait_frame(uint32_t timeoutMs, gvfg_frame_
|
||||
return GVFG_ETIMEOUT;
|
||||
|
||||
size_t bytes = 0;
|
||||
uint64_t frameCount = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
bytes = video_info_.cbBufSize;
|
||||
frameCount = video_info_.FrameCount;
|
||||
}
|
||||
const void *data = nullptr;
|
||||
gvfg_status_t status = GVFG_OK;
|
||||
if (zero_copy_enabled_)
|
||||
{
|
||||
void *buffer = nullptr;
|
||||
const auto begin = std::chrono::steady_clock::now();
|
||||
status = from_vendor(GvfgGetVideoFrameZeroCopy(context_, channel_, &buffer),
|
||||
"GvfgGetVideoFrameZeroCopy");
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
record_get_frame_timing(std::chrono::duration<double, std::micro>(end - begin).count());
|
||||
data = buffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (copy_buffer_.size() != bytes)
|
||||
copy_buffer_.assign(bytes, 0);
|
||||
const auto begin = std::chrono::steady_clock::now();
|
||||
status = from_vendor(GvfgGetVideoFrame(context_, channel_, copy_buffer_.data(),
|
||||
static_cast<ULONG>(copy_buffer_.size())),
|
||||
"GvfgGetVideoFrame");
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
record_get_frame_timing(std::chrono::duration<double, std::micro>(end - begin).count());
|
||||
data = copy_buffer_.data();
|
||||
}
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
record_get_frame_timing(std::chrono::duration<double, std::micro>(end - begin).count());
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
if (!data || bytes == 0)
|
||||
@@ -454,13 +458,14 @@ gvfg_status_t GigabyteCaptureSession::wait_frame(uint32_t timeoutMs, gvfg_frame_
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
out.data = data;
|
||||
out.data_size = bytes;
|
||||
out.frame_id = frameCount;
|
||||
out.frame_id = 0;
|
||||
out.timestamp_ns = monotonic_ns();
|
||||
out.width = signal.width;
|
||||
out.height = signal.height;
|
||||
out.row_stride_bytes = static_cast<int>(bytes / signal.height);
|
||||
out.pixel_format = signal.pixel_format;
|
||||
out.bit_depth = signal.bit_depth;
|
||||
++video_frames_from_lib_;
|
||||
frame_held_ = true;
|
||||
return GVFG_OK;
|
||||
}
|
||||
@@ -482,18 +487,17 @@ gvfg_status_t GigabyteCaptureSession::release_frame()
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::wait_audio(
|
||||
uint32_t timeoutMs, void *destination, uint32_t destinationCapacity, uint32_t &outBytes,
|
||||
uint64_t &outFrameCount)
|
||||
uint32_t timeoutMs, void *destination, uint32_t destinationCapacity, uint32_t &outBytes)
|
||||
{
|
||||
outBytes = 0;
|
||||
outFrameCount = 0;
|
||||
if (!running_ || !audio_enabled_ || !destination)
|
||||
return reject(GVFG_ESTATE, "GigabyteLib audio read rejected");
|
||||
GigabyteAudioInfo format{};
|
||||
const gvfg_status_t formatStatus = get_audio_format(format);
|
||||
if (formatStatus != GVFG_OK)
|
||||
return formatStatus;
|
||||
if (format.frame_bytes == 0 || format.frame_bytes > destinationCapacity)
|
||||
uint32_t frameBytes = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
frameBytes = audio_info_.cbBufSize;
|
||||
}
|
||||
if (frameBytes == 0 || frameBytes > destinationCapacity)
|
||||
return reject(GVFG_EINVAL, "GigabyteLib audio destination is too small");
|
||||
if (!events_.hAudioFrameInEvent)
|
||||
return reject(GVFG_EIO, "GigabyteLib did not provide an audio-frame event");
|
||||
@@ -503,11 +507,7 @@ gvfg_status_t GigabyteCaptureSession::wait_audio(
|
||||
const DWORD waitMs = timeoutMs == UINT32_MAX ? INFINITE : timeoutMs;
|
||||
const DWORD wait = WaitForMultipleObjects(count, handles.data(), FALSE, waitMs);
|
||||
if (wait == WAIT_TIMEOUT)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
++wait_timeout_count_;
|
||||
return GVFG_ETIMEOUT;
|
||||
}
|
||||
if (wait == WAIT_OBJECT_0)
|
||||
return GVFG_ESTATE;
|
||||
if (wait != WAIT_OBJECT_0 + 1 && wait != WAIT_OBJECT_0 + 2)
|
||||
@@ -519,21 +519,14 @@ gvfg_status_t GigabyteCaptureSession::wait_audio(
|
||||
else
|
||||
++extra_audio_event_wakes_;
|
||||
}
|
||||
const uint32_t frameBytes = format.frame_bytes;
|
||||
const gvfg_status_t status = from_vendor(
|
||||
GvfgGetAudioFrame(context_, channel_, destination, frameBytes), "GvfgGetAudioFrame");
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
GigabyteAudioInfo latestInfo{};
|
||||
const gvfg_status_t infoStatus = get_audio_format(latestInfo);
|
||||
if (infoStatus != GVFG_OK)
|
||||
return infoStatus;
|
||||
outBytes = frameBytes;
|
||||
outFrameCount = latestInfo.frame_count;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
++audio_frames_from_driver_;
|
||||
audio_bytes_from_driver_ += outBytes;
|
||||
++audio_frames_from_lib_;
|
||||
}
|
||||
return GVFG_OK;
|
||||
}
|
||||
@@ -615,12 +608,11 @@ void GigabyteCaptureSession::emit_event(gvfg_event_type_t type) const
|
||||
void GigabyteCaptureSession::fill_debug_stats(gvfg_debug_backend_stats_t &out) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
out.frame_wait_timeouts = wait_timeout_count_;
|
||||
out.video_event_wakes = video_event_wakes_;
|
||||
out.video_frames_from_lib = video_frames_from_lib_;
|
||||
out.audio_dma_event_wakes = audio_event_wakes_;
|
||||
out.extra_audio_event_wakes = extra_audio_event_wakes_;
|
||||
out.audio_frames_from_driver = audio_frames_from_driver_;
|
||||
out.audio_bytes_from_driver = audio_bytes_from_driver_;
|
||||
out.audio_frames_from_lib = audio_frames_from_lib_;
|
||||
out.get_frame_timing_samples = get_frame_timing_samples_;
|
||||
out.get_frame_timing_average_us = get_frame_timing_samples_
|
||||
? get_frame_timing_total_us_ / static_cast<double>(get_frame_timing_samples_) : 0.0;
|
||||
|
||||
@@ -23,9 +23,7 @@ namespace gvfg::internal
|
||||
uint32_t sample_rate = 0;
|
||||
uint32_t channels = 0;
|
||||
uint32_t bits_per_sample = 0;
|
||||
uint32_t frames_per_second = 0;
|
||||
uint32_t frame_bytes = 0;
|
||||
uint64_t frame_count = 0;
|
||||
};
|
||||
|
||||
using GigabyteEventCallback = void (*)(gvfg_event_type_t event, void *user);
|
||||
@@ -57,8 +55,7 @@ namespace gvfg::internal
|
||||
gvfg_status_t stop_stream();
|
||||
gvfg_status_t wait_frame(uint32_t timeoutMs, gvfg_frame_t &out);
|
||||
gvfg_status_t wait_audio(uint32_t timeoutMs, void *destination,
|
||||
uint32_t destinationCapacity, uint32_t &outBytes,
|
||||
uint64_t &outFrameCount);
|
||||
uint32_t destinationCapacity, uint32_t &outBytes);
|
||||
gvfg_status_t release_frame();
|
||||
void fill_debug_stats(gvfg_debug_backend_stats_t &out) const;
|
||||
gvfg_status_t debug_read_register(uint32_t offset, uint32_t &outValue) const;
|
||||
@@ -73,6 +70,7 @@ namespace gvfg::internal
|
||||
void event_thread_proc();
|
||||
void emit_event(gvfg_event_type_t type) const;
|
||||
gvfg_status_t refresh_video_info() const;
|
||||
gvfg_status_t refresh_audio_info() const;
|
||||
gvfg_status_t from_vendor(GVFG_HRESULT result, const char *operation) const;
|
||||
gvfg_status_t reject(gvfg_status_t status, const char *message) const;
|
||||
void record_get_frame_timing(double elapsedUs);
|
||||
@@ -101,12 +99,11 @@ namespace gvfg::internal
|
||||
mutable std::mutex state_mutex_;
|
||||
std::vector<uint8_t> copy_buffer_;
|
||||
bool frame_held_ = false;
|
||||
uint64_t audio_frames_from_driver_ = 0;
|
||||
uint64_t audio_bytes_from_driver_ = 0;
|
||||
uint64_t video_frames_from_lib_ = 0;
|
||||
uint64_t audio_frames_from_lib_ = 0;
|
||||
uint64_t video_event_wakes_ = 0;
|
||||
uint64_t audio_event_wakes_ = 0;
|
||||
uint64_t extra_audio_event_wakes_ = 0;
|
||||
uint64_t wait_timeout_count_ = 0;
|
||||
uint64_t get_frame_timing_samples_ = 0;
|
||||
uint32_t get_frame_timing_window_samples_ = 0;
|
||||
double get_frame_timing_total_us_ = 0.0;
|
||||
|
||||
@@ -189,6 +189,12 @@ struct gvfg_channel_session_t
|
||||
const gvfg_status_t cfg = configureStream();
|
||||
if (cfg != GVFG_OK)
|
||||
return cfg;
|
||||
if (audioEnabled)
|
||||
{
|
||||
const gvfg_status_t audioStatus = session->get_audio_format(cachedAudioFormat);
|
||||
if (audioStatus != GVFG_OK)
|
||||
return audioStatus;
|
||||
}
|
||||
|
||||
resetRuntimeCounters();
|
||||
{
|
||||
@@ -326,14 +332,10 @@ struct gvfg_channel_session_t
|
||||
if (!session)
|
||||
return reject(GVFG_ESTATE, "configure stream rejected: channel is not open");
|
||||
|
||||
const gvfg_status_t signalStatus = querySignal();
|
||||
if (signalStatus != GVFG_OK)
|
||||
return signalStatus;
|
||||
|
||||
const gvfg_status_t st = session->configure_stream();
|
||||
if (st != GVFG_OK)
|
||||
return st;
|
||||
return GVFG_OK;
|
||||
return querySignal();
|
||||
}
|
||||
|
||||
gvfg_status_t readFrame(gvfg_frame_t &out, uint32_t timeoutMs)
|
||||
@@ -386,6 +388,7 @@ struct gvfg_channel_session_t
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.frame_id = ++videoFrameId;
|
||||
heldSessionFrame = frame;
|
||||
readInProgress = false;
|
||||
frameHeld = true;
|
||||
@@ -594,6 +597,7 @@ struct gvfg_channel_session_t
|
||||
const gvfg_status_t status = session->get_audio_format(format);
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
cachedAudioFormat = format;
|
||||
out.sample_rate = format.sample_rate;
|
||||
out.channels = format.channels;
|
||||
out.bits_per_sample = format.bits_per_sample;
|
||||
@@ -617,16 +621,14 @@ struct gvfg_channel_session_t
|
||||
audioReadInProgress = true;
|
||||
}
|
||||
|
||||
GigabyteAudioInfo format{};
|
||||
gvfg_status_t status = session->get_audio_format(format);
|
||||
const GigabyteAudioInfo format = cachedAudioFormat;
|
||||
gvfg_status_t status = format.frame_bytes != 0 ? GVFG_OK : GVFG_ESTATE;
|
||||
uint32_t bytes = 0;
|
||||
uint64_t frameCount = 0;
|
||||
if (status == GVFG_OK)
|
||||
{
|
||||
audioBuffer.resize(format.frame_bytes);
|
||||
status = session->wait_audio(timeoutMs, audioBuffer.data(),
|
||||
static_cast<uint32_t>(audioBuffer.size()), bytes,
|
||||
frameCount);
|
||||
static_cast<uint32_t>(audioBuffer.size()), bytes);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -642,7 +644,7 @@ struct gvfg_channel_session_t
|
||||
out.sample_rate = format.sample_rate;
|
||||
out.channels = format.channels;
|
||||
out.bits_per_sample = format.bits_per_sample;
|
||||
out.frame_id = frameCount;
|
||||
out.frame_id = ++audioFrameId;
|
||||
out.timestamp_ns = now_ns();
|
||||
heldAudioFrame = out;
|
||||
}
|
||||
@@ -711,6 +713,8 @@ struct gvfg_channel_session_t
|
||||
deliveredBitDepth.store(0, std::memory_order_relaxed);
|
||||
deliveredPixelFormat.store(GVFG_PIXFMT_UNKNOWN, std::memory_order_relaxed);
|
||||
runtimeFps.store(0.0, std::memory_order_relaxed);
|
||||
videoFrameId = 0;
|
||||
audioFrameId = 0;
|
||||
}
|
||||
|
||||
void noteDeliveredFrame(int frameWidth, int frameHeight, int bitDepth, int pixelFormat)
|
||||
@@ -728,6 +732,7 @@ struct gvfg_channel_session_t
|
||||
uint32_t selectedChannel = GVFG_CHANNEL_0;
|
||||
bool zeroCopyRequested = false;
|
||||
bool audioEnabled = false;
|
||||
GigabyteAudioInfo cachedAudioFormat{};
|
||||
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
@@ -748,11 +753,13 @@ struct gvfg_channel_session_t
|
||||
std::mutex frameMutex;
|
||||
bool readInProgress = false;
|
||||
bool frameHeld = false;
|
||||
uint64_t videoFrameId = 0;
|
||||
gvfg_frame_t heldSessionFrame{};
|
||||
std::mutex audioMutex;
|
||||
std::vector<uint8_t> audioBuffer;
|
||||
bool audioReadInProgress = false;
|
||||
bool audioFrameHeld = false;
|
||||
uint64_t audioFrameId = 0;
|
||||
gvfg_audio_frame_t heldAudioFrame{};
|
||||
std::mutex eventMutex;
|
||||
std::condition_variable eventCv;
|
||||
|
||||
Reference in New Issue
Block a user