Use all GigabyteLib frame metadata
Compared with 13aad44:
- size video buffers from GVFG_VIDEO_INFO.cbBufSize instead of recalculating them in the SDK
- expose the GigabyteLib video interface through channel signal status and display it in the Qt sample
- use GVFG_VIDEO_INFO.FrameCount and GVFG_AUDIO_INFO.FrameCount as the public frame identifiers
- expose all four formatted ST 352 payload descriptions returned by GvfgStringifySdiVideoInputInfo
- remove the redundant SDK-owned video and audio frame counters and the local frame-size helper
- update the customer and frame-flow documentation to identify the GigabyteLib metadata source
This commit is contained in:
@@ -217,9 +217,11 @@ gvfg_status_t GigabyteCaptureSession::refresh_video_info() const
|
||||
signal.height = info.Height;
|
||||
signal.pixel_format = decode_fourcc(info.Fourcc);
|
||||
signal.bit_depth = bit_depth(signal.pixel_format);
|
||||
signal.video_interface = static_cast<int>(info.VideoInterface);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
cached_signal_ = signal;
|
||||
video_info_ = info;
|
||||
}
|
||||
return GVFG_OK;
|
||||
}
|
||||
@@ -283,6 +285,10 @@ gvfg_status_t GigabyteCaptureSession::get_sdi_info(gvfg_sdi_info_t &out) const
|
||||
strncpy_s(out.resolution_name, text.Resol, _TRUNCATE);
|
||||
strncpy_s(out.fps_name, text.Fps, _TRUNCATE);
|
||||
strncpy_s(out.scan_name, text.Progressive, _TRUNCATE);
|
||||
strncpy_s(out.st352_format_name, text.St352PayloadByte0Fmt, _TRUNCATE);
|
||||
strncpy_s(out.st352_fps_name, text.St352PayloadByte1Fps, _TRUNCATE);
|
||||
strncpy_s(out.st352_chroma_name, text.St352PayloadByte2Chroma, _TRUNCATE);
|
||||
strncpy_s(out.st352_bit_depth_name, text.St352PayloadByte3BitDepth, _TRUNCATE);
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
@@ -301,6 +307,7 @@ gvfg_status_t GigabyteCaptureSession::get_audio_format(GigabyteAudioInfo &out) c
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -338,7 +345,6 @@ gvfg_status_t GigabyteCaptureSession::start_stream()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
frame_held_ = false;
|
||||
frame_id_ = 0;
|
||||
}
|
||||
running_ = true;
|
||||
start_event_monitoring();
|
||||
@@ -414,7 +420,13 @@ gvfg_status_t GigabyteCaptureSession::wait_frame(uint32_t timeoutMs, gvfg_frame_
|
||||
if (!signal.connected || signal.width == 0 || signal.height == 0)
|
||||
return GVFG_ETIMEOUT;
|
||||
|
||||
const size_t bytes = frame_size_bytes();
|
||||
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_)
|
||||
@@ -443,7 +455,7 @@ 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 = ++frame_id_;
|
||||
out.frame_id = frameCount;
|
||||
out.timestamp_ns = monotonic_ns();
|
||||
out.width = signal.width;
|
||||
out.height = signal.height;
|
||||
@@ -471,9 +483,11 @@ gvfg_status_t GigabyteCaptureSession::release_frame()
|
||||
}
|
||||
|
||||
gvfg_status_t GigabyteCaptureSession::wait_audio(
|
||||
uint32_t timeoutMs, void *destination, uint32_t destinationCapacity, uint32_t &outBytes)
|
||||
uint32_t timeoutMs, void *destination, uint32_t destinationCapacity, uint32_t &outBytes,
|
||||
uint64_t &outFrameCount)
|
||||
{
|
||||
outBytes = 0;
|
||||
outFrameCount = 0;
|
||||
if (!running_ || !audio_enabled_ || !destination)
|
||||
return reject(GVFG_ESTATE, "GigabyteLib audio read rejected");
|
||||
GigabyteAudioInfo format{};
|
||||
@@ -506,11 +520,17 @@ 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, format.frame_bytes), "GvfgGetAudioFrame");
|
||||
GvfgGetAudioFrame(context_, channel_, destination, frameBytes), "GvfgGetAudioFrame");
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
outBytes = format.frame_bytes;
|
||||
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_;
|
||||
@@ -656,16 +676,6 @@ gvfg_status_t GigabyteCaptureSession::reject(gvfg_status_t status, const char *m
|
||||
return status;
|
||||
}
|
||||
|
||||
size_t GigabyteCaptureSession::frame_size_bytes() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
const uint32_t width = cached_signal_.width;
|
||||
const uint32_t height = cached_signal_.height;
|
||||
const int format = cached_signal_.pixel_format;
|
||||
const size_t bytesPerPixel = format == GVFG_PIXFMT_Y210 ? 4u : 2u;
|
||||
return static_cast<size_t>(width) * height * bytesPerPixel;
|
||||
}
|
||||
|
||||
void GigabyteCaptureSession::record_get_frame_timing(double elapsedUs)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace gvfg::internal
|
||||
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);
|
||||
@@ -56,7 +57,8 @@ 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);
|
||||
uint32_t destinationCapacity, uint32_t &outBytes,
|
||||
uint64_t &outFrameCount);
|
||||
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;
|
||||
@@ -74,7 +76,6 @@ namespace gvfg::internal
|
||||
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);
|
||||
size_t frame_size_bytes() const;
|
||||
|
||||
ChannelErrorState &error_state_;
|
||||
std::wstring device_path_;
|
||||
@@ -85,6 +86,7 @@ namespace gvfg::internal
|
||||
mutable bool events_created_ = false;
|
||||
mutable bool channel_open_ = false;
|
||||
mutable gvfg_signal_status_t cached_signal_{};
|
||||
mutable GVFG_VIDEO_INFO video_info_{};
|
||||
mutable GVFG_AUDIO_INFO audio_info_{};
|
||||
uint32_t channel_ = 0;
|
||||
bool configured_ = false;
|
||||
@@ -99,7 +101,6 @@ namespace gvfg::internal
|
||||
mutable std::mutex state_mutex_;
|
||||
std::vector<uint8_t> copy_buffer_;
|
||||
bool frame_held_ = false;
|
||||
uint64_t frame_id_ = 0;
|
||||
uint64_t audio_frames_from_driver_ = 0;
|
||||
uint64_t audio_bytes_from_driver_ = 0;
|
||||
uint64_t video_event_wakes_ = 0;
|
||||
|
||||
@@ -195,7 +195,6 @@ struct gvfg_channel_session_t
|
||||
std::lock_guard<std::mutex> lock(audioMutex);
|
||||
heldAudioFrame = {};
|
||||
audioFrameHeld = false;
|
||||
audioFrameId = 0;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(eventMutex);
|
||||
@@ -621,11 +620,13 @@ struct gvfg_channel_session_t
|
||||
GigabyteAudioInfo format{};
|
||||
gvfg_status_t status = session->get_audio_format(format);
|
||||
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);
|
||||
static_cast<uint32_t>(audioBuffer.size()), bytes,
|
||||
frameCount);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -636,13 +637,12 @@ struct gvfg_channel_session_t
|
||||
if (!running.load(std::memory_order_acquire) || bytes == 0 || bytes > audioBuffer.size())
|
||||
return reject(GVFG_ESTATE, "gvfg_read_channel_audio_frame completed after capture stopped or returned invalid data");
|
||||
audioFrameHeld = true;
|
||||
++audioFrameId;
|
||||
out.data = audioBuffer.data();
|
||||
out.data_size = bytes;
|
||||
out.sample_rate = format.sample_rate;
|
||||
out.channels = format.channels;
|
||||
out.bits_per_sample = format.bits_per_sample;
|
||||
out.frame_id = audioFrameId;
|
||||
out.frame_id = frameCount;
|
||||
out.timestamp_ns = now_ns();
|
||||
heldAudioFrame = out;
|
||||
}
|
||||
@@ -753,7 +753,6 @@ struct gvfg_channel_session_t
|
||||
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