Refactor GVFG channel and driver access flow
- support only the new vfg100_0821c driver; legacy drivers and IOCTL contracts are intentionally unsupported - use one SDK handle per physical device with independent CH0/CH1 sessions and selectable event masks - expose Device Manager friendly names and remove redundant enumerated device indices - align active capture IOCTLs with the new driver while omitting unsupported OPEN_VIDEO/CLOSE_VIDEO calls - isolate IOCTL codes, request layouts, and DeviceIoControl calls in the new giga_ioctl DLL - block reads of pure write-only registers while preserving dual-semantics interrupt status reads - reduce duplicate signal register queries during open/start - add zero-copy/copy driver GetFrame timing in microseconds and show it in the preview status - update public/internal documentation for the revised lifecycle and channel APIs Validation: static searches and git diff --check only; build intentionally not run.
This commit is contained in:
@@ -78,6 +78,11 @@ typedef struct pcies2mm_debug_state_t
|
||||
uint64_t active_delivery_slot;
|
||||
uint64_t next_write_slot;
|
||||
uint64_t ring_size;
|
||||
int get_frame_zero_copy;
|
||||
uint64_t get_frame_timing_samples;
|
||||
double get_frame_timing_average_us;
|
||||
double get_frame_timing_max300_us;
|
||||
double get_frame_timing_max_us;
|
||||
} pcies2mm_debug_state_t;
|
||||
|
||||
typedef enum pcies2mm_event_type_t
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "pcies2mm_capture_session.h"
|
||||
#include "pcies2mm_ioctl.h"
|
||||
#include "giga_ioctl.h"
|
||||
#include "pcies2mm_reg.h"
|
||||
#include "pcies2mm_video_format.h"
|
||||
|
||||
@@ -19,6 +19,26 @@ namespace
|
||||
constexpr uint32_t kDefaultRingBufferCount = 3;
|
||||
constexpr uint32_t kMaxRingBufferCount = 16;
|
||||
|
||||
static bool is_write_only_register(uint32_t offset)
|
||||
{
|
||||
if (offset == VIDEO_OUTPUT_FORMAT_REGISTER)
|
||||
return true;
|
||||
|
||||
for (uint32_t channel = 0; channel < kMaxChannels; ++channel)
|
||||
{
|
||||
const uint32_t videoBase = CH_VIDEO_BASE(channel);
|
||||
if (offset == videoBase + VIDEO_DMA_DESC_WR_OFFSET ||
|
||||
offset == videoBase + VIDEO_DMA_SOFT_RESET_OFFSET)
|
||||
return true;
|
||||
|
||||
const uint32_t audioBase = CH_AUDIO_BASE(channel);
|
||||
if (offset == audioBase + AUDIO_DMA_DESC_WR_OFFSET ||
|
||||
offset == audioBase + AUDIO_DMA_SOFT_RESET_OFFSET)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool should_log_counter(uint64_t count)
|
||||
{
|
||||
return count <= 5 || (count % 60) == 0;
|
||||
@@ -122,6 +142,12 @@ namespace
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
PcieS2mmCaptureSession::SharedDevice::~SharedDevice()
|
||||
{
|
||||
if (handle != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(handle);
|
||||
}
|
||||
|
||||
PcieS2mmCaptureSession::PcieS2mmCaptureSession()
|
||||
{
|
||||
stream_desc_.width = kDefaultWidth;
|
||||
@@ -151,19 +177,22 @@ namespace gvfg::internal
|
||||
base_path_ = device.interface_path;
|
||||
friendly_name_ = device.friendly_name.empty() ? L"PcieS2mm Capture Device" : device.friendly_name;
|
||||
|
||||
device_ = CreateFileW(base_path_.c_str(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
nullptr);
|
||||
if (device_ == INVALID_HANDLE_VALUE)
|
||||
auto sharedDevice = std::make_shared<SharedDevice>();
|
||||
sharedDevice->handle = CreateFileW(base_path_.c_str(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
nullptr);
|
||||
if (sharedDevice->handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
const DWORD err = GetLastError();
|
||||
close_handles();
|
||||
return fail(PCIES2MM_EIO, "CreateFile(PcieS2mm)", err);
|
||||
}
|
||||
shared_device_ = std::move(sharedDevice);
|
||||
device_ = shared_device_->handle;
|
||||
|
||||
opened_ = true;
|
||||
configured_ = false;
|
||||
@@ -176,6 +205,31 @@ namespace gvfg::internal
|
||||
return PCIES2MM_OK;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::open_shared_device(
|
||||
const PcieS2mmCaptureSession &source,
|
||||
uint32_t channel)
|
||||
{
|
||||
if (channel >= kMaxChannels)
|
||||
return PCIES2MM_EINVAL;
|
||||
if (!source.opened_ || !source.shared_device_ ||
|
||||
source.shared_device_->handle == INVALID_HANDLE_VALUE)
|
||||
return PCIES2MM_ESTATE;
|
||||
|
||||
close();
|
||||
shared_device_ = source.shared_device_;
|
||||
device_ = shared_device_->handle;
|
||||
base_path_ = source.base_path_;
|
||||
friendly_name_ = source.friendly_name_;
|
||||
opened_ = true;
|
||||
configured_ = false;
|
||||
signal_presence_known_.store(false, std::memory_order_release);
|
||||
signal_present_.store(false, std::memory_order_release);
|
||||
signal_probe_active_.store(false, std::memory_order_release);
|
||||
signal_metadata_valid_ = false;
|
||||
clear_last_error();
|
||||
return PCIES2MM_OK;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::close()
|
||||
{
|
||||
pcies2mm_status_t result = stop_stream();
|
||||
@@ -203,11 +257,8 @@ namespace gvfg::internal
|
||||
void PcieS2mmCaptureSession::close_handles()
|
||||
{
|
||||
close_event_handles();
|
||||
if (device_ != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(device_);
|
||||
device_ = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
device_ = INVALID_HANDLE_VALUE;
|
||||
shared_device_.reset();
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::set_channel(uint32_t channel)
|
||||
@@ -246,12 +297,7 @@ namespace gvfg::internal
|
||||
return releaseStatus;
|
||||
}
|
||||
|
||||
ULONG channel = active_channel();
|
||||
DWORD bytesReturned = 0;
|
||||
const DWORD ioctl = enabled ? IOCTL_GIGA_ENABLE_FRAME_ZEROCOPY
|
||||
: IOCTL_GIGA_DISABLE_FRAME_ZEROCOPY;
|
||||
if (!DeviceIoControl(device_, ioctl, &channel, sizeof(channel), nullptr, 0,
|
||||
&bytesReturned, nullptr))
|
||||
if (!giga_ioctl_set_frame_zerocopy(device_, active_channel(), enabled ? TRUE : FALSE))
|
||||
return fail(PCIES2MM_EIO, enabled ? "enable zero copy" : "disable zero copy");
|
||||
zero_copy_enabled_ = enabled;
|
||||
return PCIES2MM_OK;
|
||||
@@ -341,7 +387,7 @@ namespace gvfg::internal
|
||||
std::lock_guard<std::mutex> lock(event_callback_mutex_);
|
||||
event_callback_ = callback;
|
||||
event_callback_user_ = user;
|
||||
event_mask_filter_ = eventMask ? eventMask : PCIES2MM_EVENT_MASK_DEFAULT;
|
||||
event_mask_filter_ = eventMask;
|
||||
return PCIES2MM_OK;
|
||||
}
|
||||
|
||||
@@ -407,6 +453,12 @@ namespace gvfg::internal
|
||||
latest_sequence_ = 0;
|
||||
delivered_sequence_ = 0;
|
||||
wait_timeout_count_ = 0;
|
||||
get_frame_timing_samples_ = 0;
|
||||
get_frame_timing_window_samples_ = 0;
|
||||
get_frame_timing_total_us_ = 0.0;
|
||||
get_frame_timing_window_max_us_ = 0.0;
|
||||
get_frame_timing_last_max300_us_ = 0.0;
|
||||
get_frame_timing_lifetime_max_us_ = 0.0;
|
||||
stream_error_ = false;
|
||||
reset_stats(stats_, PCIES2MM_STREAM_CONFIGURED);
|
||||
}
|
||||
@@ -417,12 +469,16 @@ namespace gvfg::internal
|
||||
// another stream.
|
||||
if (!monitoring_.load(std::memory_order_acquire) && !start_event_monitoring())
|
||||
return fail(PCIES2MM_EIO, "start event monitoring");
|
||||
// Events are edge-triggered, so a source connected before registration
|
||||
// may not produce a plug-in event. Probe DMA using the register layout,
|
||||
// but do not report connected until a full frame is received.
|
||||
// configureStream() immediately preceded this call and already read
|
||||
// and validated the signal descriptor. Reuse it for the initial DMA
|
||||
// probe instead of reading width/height/format a second time.
|
||||
const bool probeAvailable = signal_presence_known_.load(std::memory_order_acquire) &&
|
||||
signal_present_.load(std::memory_order_acquire) &&
|
||||
stream_desc_.width > 0 &&
|
||||
stream_desc_.height > 0 &&
|
||||
stream_desc_.pixel_format != PCIES2MM_PIXFMT_UNKNOWN;
|
||||
signal_presence_known_.store(false, std::memory_order_release);
|
||||
signal_present_.store(false, std::memory_order_release);
|
||||
const bool probeAvailable = refresh_stream_from_registers(true);
|
||||
|
||||
running_ = true;
|
||||
capture_active_ = false;
|
||||
@@ -490,7 +546,13 @@ namespace gvfg::internal
|
||||
const bool presenceKnown = signal_presence_known_.load(std::memory_order_acquire);
|
||||
const bool signalPresent = signal_present_.load(std::memory_order_acquire);
|
||||
probingSignal = !presenceKnown;
|
||||
if (!presenceKnown || signalPresent)
|
||||
// start_stream() already refreshed width/height/format before it
|
||||
// armed the initial signal probe. Reuse that validated descriptor
|
||||
// for the first read instead of issuing the same three register
|
||||
// reads again immediately.
|
||||
if (!presenceKnown && signal_probe_active_.load(std::memory_order_acquire))
|
||||
descriptorReady = true;
|
||||
else if (!presenceKnown || signalPresent)
|
||||
descriptorReady = refresh_stream_from_registers(true);
|
||||
}
|
||||
|
||||
@@ -654,25 +716,21 @@ namespace gvfg::internal
|
||||
: static_cast<uint64_t>(active_delivery_slot_);
|
||||
outDebugState.next_write_slot = static_cast<uint64_t>(next_write_slot_);
|
||||
outDebugState.ring_size = static_cast<uint64_t>(frame_ring_.size());
|
||||
outDebugState.get_frame_zero_copy = zero_copy_enabled_ ? 1 : 0;
|
||||
outDebugState.get_frame_timing_samples = get_frame_timing_samples_;
|
||||
outDebugState.get_frame_timing_average_us =
|
||||
get_frame_timing_samples_ > 0
|
||||
? get_frame_timing_total_us_ / static_cast<double>(get_frame_timing_samples_)
|
||||
: 0.0;
|
||||
outDebugState.get_frame_timing_max300_us = get_frame_timing_last_max300_us_;
|
||||
outDebugState.get_frame_timing_max_us = get_frame_timing_lifetime_max_us_;
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::read_reg(uint32_t offset, uint32_t &out) const
|
||||
{
|
||||
PCIES2MM_REG_ACCESS reg{};
|
||||
reg.Offset = offset;
|
||||
DWORD bytesReturned = 0;
|
||||
const BOOL ok = DeviceIoControl(device_,
|
||||
IOCTL_PCIES2MM_READ_REG,
|
||||
®,
|
||||
sizeof(reg),
|
||||
®,
|
||||
sizeof(reg),
|
||||
&bytesReturned,
|
||||
nullptr);
|
||||
if (!ok)
|
||||
if (is_write_only_register(offset))
|
||||
return false;
|
||||
out = reg.Value;
|
||||
return true;
|
||||
return giga_ioctl_read_register(device_, offset, &out) != FALSE;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::debug_read_register(uint32_t offset,
|
||||
@@ -680,70 +738,31 @@ namespace gvfg::internal
|
||||
{
|
||||
if (!opened_ || device_ == INVALID_HANDLE_VALUE)
|
||||
return PCIES2MM_ESTATE;
|
||||
if ((offset & 0x3u) != 0)
|
||||
if ((offset & 0x3u) != 0 || is_write_only_register(offset))
|
||||
return PCIES2MM_EINVAL;
|
||||
return read_reg(offset, outValue) ? PCIES2MM_OK : fail(PCIES2MM_EIO, "debug_read_register");
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::write_reg(uint32_t offset, uint32_t value) const
|
||||
{
|
||||
PCIES2MM_REG_ACCESS reg{};
|
||||
reg.Offset = offset;
|
||||
reg.Value = value;
|
||||
DWORD bytesReturned = 0;
|
||||
return DeviceIoControl(device_,
|
||||
IOCTL_PCIES2MM_WRITE_REG,
|
||||
®,
|
||||
sizeof(reg),
|
||||
nullptr,
|
||||
0,
|
||||
&bytesReturned,
|
||||
nullptr) != FALSE;
|
||||
return giga_ioctl_write_register(device_, offset, value) != FALSE;
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::start_video(uint32_t channelIndex) const
|
||||
{
|
||||
ULONG channel = channelIndex;
|
||||
DWORD bytesReturned = 0;
|
||||
return DeviceIoControl(device_,
|
||||
IOCTL_GIGA_VIDEO_START,
|
||||
&channel,
|
||||
sizeof(channel),
|
||||
nullptr,
|
||||
0,
|
||||
&bytesReturned,
|
||||
nullptr) != FALSE;
|
||||
return giga_ioctl_video_start(device_, channelIndex) != FALSE;
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::stop_video(uint32_t channelIndex) const
|
||||
{
|
||||
ULONG channel = channelIndex;
|
||||
DWORD bytesReturned = 0;
|
||||
return DeviceIoControl(device_,
|
||||
IOCTL_GIGA_VIDEO_STOP,
|
||||
&channel,
|
||||
sizeof(channel),
|
||||
nullptr,
|
||||
0,
|
||||
&bytesReturned,
|
||||
nullptr) != FALSE;
|
||||
return giga_ioctl_video_stop(device_, channelIndex) != FALSE;
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::acquire_zero_copy_frame(uint32_t channelIndex,
|
||||
const uint8_t *&outData) const
|
||||
{
|
||||
ULONG input[2] = {channelIndex, (std::numeric_limits<ULONG>::max)()};
|
||||
void *buffer = nullptr;
|
||||
DWORD bytesReturned = 0;
|
||||
const BOOL ok = DeviceIoControl(device_,
|
||||
IOCTL_GIGA_ACQUIRE_VIDEO_FRAME_ZEROCOPY,
|
||||
input,
|
||||
sizeof(input),
|
||||
&buffer,
|
||||
sizeof(buffer),
|
||||
&bytesReturned,
|
||||
nullptr);
|
||||
if (!ok || !buffer)
|
||||
const void *buffer = nullptr;
|
||||
if (!giga_ioctl_acquire_video_frame_zerocopy(device_, channelIndex, &buffer))
|
||||
return false;
|
||||
outData = static_cast<const uint8_t *>(buffer);
|
||||
return true;
|
||||
@@ -751,16 +770,7 @@ namespace gvfg::internal
|
||||
|
||||
bool PcieS2mmCaptureSession::release_zero_copy_frame(uint32_t channelIndex) const
|
||||
{
|
||||
ULONG channel = channelIndex;
|
||||
DWORD bytesReturned = 0;
|
||||
return DeviceIoControl(device_,
|
||||
IOCTL_GIGA_RELEASE_VIDEO_FRAME,
|
||||
&channel,
|
||||
sizeof(channel),
|
||||
nullptr,
|
||||
0,
|
||||
&bytesReturned,
|
||||
nullptr) != FALSE;
|
||||
return giga_ioctl_release_video_frame(device_, channelIndex) != FALSE;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::release_all_zero_copy_frames(bool includeInUse)
|
||||
@@ -798,36 +808,12 @@ namespace gvfg::internal
|
||||
|
||||
bool PcieS2mmCaptureSession::register_event(uint32_t channelIndex, uint32_t eventType, HANDLE eventHandle)
|
||||
{
|
||||
PCIES2MM_EVENT_REG eventReg{};
|
||||
eventReg.Type = eventType;
|
||||
eventReg.ChannelIndex = channelIndex;
|
||||
eventReg.EventHandle = eventHandle;
|
||||
DWORD bytesReturned = 0;
|
||||
return DeviceIoControl(device_,
|
||||
IOCTL_PCIES2MM_REGISTER_EVENT,
|
||||
&eventReg,
|
||||
sizeof(eventReg),
|
||||
nullptr,
|
||||
0,
|
||||
&bytesReturned,
|
||||
nullptr) != FALSE;
|
||||
return giga_ioctl_register_event(device_, channelIndex, eventType, eventHandle) != FALSE;
|
||||
}
|
||||
|
||||
void PcieS2mmCaptureSession::unregister_event(uint32_t channelIndex, uint32_t eventType)
|
||||
{
|
||||
PCIES2MM_EVENT_REG eventReg{};
|
||||
eventReg.Type = eventType;
|
||||
eventReg.ChannelIndex = channelIndex;
|
||||
eventReg.EventHandle = nullptr;
|
||||
DWORD bytesReturned = 0;
|
||||
DeviceIoControl(device_,
|
||||
IOCTL_PCIES2MM_UNREGISTER_EVENT,
|
||||
&eventReg,
|
||||
sizeof(eventReg),
|
||||
nullptr,
|
||||
0,
|
||||
&bytesReturned,
|
||||
nullptr);
|
||||
giga_ioctl_unregister_event(device_, channelIndex, eventType);
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::create_and_register_events(uint32_t channelIndex)
|
||||
@@ -839,23 +825,29 @@ namespace gvfg::internal
|
||||
if (!dma_event_ || !format_change_event_ || !plug_in_event_ || !plug_out_event_)
|
||||
return false;
|
||||
|
||||
if (!register_event(channelIndex, PCIES2MM_EVENT_TYPE_VIDEO_DMA, dma_event_))
|
||||
if (!register_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_DMA, dma_event_))
|
||||
return false;
|
||||
if (!register_event(channelIndex, PCIES2MM_EVENT_TYPE_VIDEO_FORMAT_CHANGE, format_change_event_))
|
||||
if ((event_mask_filter_ & PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN) != 0 &&
|
||||
!register_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_FORMAT_CHANGE, format_change_event_))
|
||||
return false;
|
||||
if (!register_event(channelIndex, PCIES2MM_EVENT_TYPE_VIDEO_PLUGIN, plug_in_event_))
|
||||
if ((event_mask_filter_ & PCIES2MM_EVENT_MASK_PLUG_IN) != 0 &&
|
||||
!register_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_PLUGIN, plug_in_event_))
|
||||
return false;
|
||||
if (!register_event(channelIndex, PCIES2MM_EVENT_TYPE_VIDEO_UNPLUG, plug_out_event_))
|
||||
if ((event_mask_filter_ & PCIES2MM_EVENT_MASK_PLUG_OUT) != 0 &&
|
||||
!register_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_UNPLUG, plug_out_event_))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void PcieS2mmCaptureSession::unregister_events(uint32_t channelIndex)
|
||||
{
|
||||
unregister_event(channelIndex, PCIES2MM_EVENT_TYPE_VIDEO_DMA);
|
||||
unregister_event(channelIndex, PCIES2MM_EVENT_TYPE_VIDEO_FORMAT_CHANGE);
|
||||
unregister_event(channelIndex, PCIES2MM_EVENT_TYPE_VIDEO_PLUGIN);
|
||||
unregister_event(channelIndex, PCIES2MM_EVENT_TYPE_VIDEO_UNPLUG);
|
||||
unregister_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_DMA);
|
||||
if ((event_mask_filter_ & PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN) != 0)
|
||||
unregister_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_FORMAT_CHANGE);
|
||||
if ((event_mask_filter_ & PCIES2MM_EVENT_MASK_PLUG_IN) != 0)
|
||||
unregister_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_PLUGIN);
|
||||
if ((event_mask_filter_ & PCIES2MM_EVENT_MASK_PLUG_OUT) != 0)
|
||||
unregister_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_UNPLUG);
|
||||
}
|
||||
|
||||
void PcieS2mmCaptureSession::close_event_handles()
|
||||
@@ -928,16 +920,9 @@ namespace gvfg::internal
|
||||
|
||||
int PcieS2mmCaptureSession::get_frame(uint32_t channelIndex, uint32_t frameIndex, uint8_t *buffer, DWORD bufferSize) const
|
||||
{
|
||||
ULONG input[2] = {channelIndex, frameIndex};
|
||||
DWORD bytesReturned = 0;
|
||||
const BOOL ok = DeviceIoControl(device_,
|
||||
IOCTL_PCIES2MM_GET_FRAME,
|
||||
input,
|
||||
sizeof(input),
|
||||
buffer,
|
||||
bufferSize,
|
||||
&bytesReturned,
|
||||
nullptr);
|
||||
uint32_t bytesReturned = 0;
|
||||
const BOOL ok = giga_ioctl_get_frame(device_, channelIndex, frameIndex,
|
||||
buffer, bufferSize, &bytesReturned);
|
||||
if (!ok)
|
||||
return -1;
|
||||
return static_cast<int>(bytesReturned);
|
||||
@@ -1175,11 +1160,34 @@ namespace gvfg::internal
|
||||
const int ret = zero_copy_enabled_
|
||||
? (acquire_zero_copy_frame(channel, zeroCopyData) ? static_cast<int>(bytes) : -1)
|
||||
: get_frame(channel, frameIndex, slotData, bytes);
|
||||
const double getFrameMs = std::chrono::duration<double, std::milli>(
|
||||
const double getFrameUs = std::chrono::duration<double, std::micro>(
|
||||
std::chrono::steady_clock::now() - getFrameStarted).count();
|
||||
if (getFrameMs >= 10.0)
|
||||
PCIES2MM_LOG("slow GET_FRAME: frame_index=0x%08X elapsed_ms=%.3f ret=%d",
|
||||
frameIndex, getFrameMs, ret);
|
||||
const bool getFrameSucceeded = ret >= 0 && static_cast<DWORD>(ret) == bytes;
|
||||
if (getFrameSucceeded)
|
||||
{
|
||||
std::lock_guard<std::mutex> timingLock(mutex_);
|
||||
++get_frame_timing_samples_;
|
||||
++get_frame_timing_window_samples_;
|
||||
get_frame_timing_total_us_ += getFrameUs;
|
||||
get_frame_timing_window_max_us_ =
|
||||
(std::max)(get_frame_timing_window_max_us_, getFrameUs);
|
||||
get_frame_timing_lifetime_max_us_ =
|
||||
(std::max)(get_frame_timing_lifetime_max_us_, getFrameUs);
|
||||
|
||||
if (get_frame_timing_window_samples_ >= 300)
|
||||
{
|
||||
get_frame_timing_last_max300_us_ = get_frame_timing_window_max_us_;
|
||||
PCIES2MM_LOG("%s avg=%.3f us max300=%.3f us max=%.3f us samples=%llu",
|
||||
zero_copy_enabled_ ? "ZEROCOPY_ACQUIRE" : "COPY_GET_FRAME",
|
||||
get_frame_timing_total_us_ /
|
||||
static_cast<double>(get_frame_timing_samples_),
|
||||
get_frame_timing_last_max300_us_,
|
||||
get_frame_timing_lifetime_max_us_,
|
||||
static_cast<unsigned long long>(get_frame_timing_samples_));
|
||||
get_frame_timing_window_samples_ = 0;
|
||||
get_frame_timing_window_max_us_ = 0.0;
|
||||
}
|
||||
}
|
||||
if (!running_)
|
||||
{
|
||||
if (zero_copy_enabled_ && zeroCopyData)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
@@ -26,6 +27,8 @@ namespace gvfg::internal
|
||||
~PcieS2mmCaptureSession();
|
||||
|
||||
pcies2mm_status_t open_device_index(size_t deviceIndex);
|
||||
pcies2mm_status_t open_shared_device(const PcieS2mmCaptureSession &source,
|
||||
uint32_t channel);
|
||||
pcies2mm_status_t close();
|
||||
|
||||
pcies2mm_status_t set_channel(uint32_t channel);
|
||||
@@ -49,6 +52,12 @@ namespace gvfg::internal
|
||||
pcies2mm_status_t debug_write_register(uint32_t offset, uint32_t value) const;
|
||||
|
||||
private:
|
||||
struct SharedDevice
|
||||
{
|
||||
HANDLE handle = INVALID_HANDLE_VALUE;
|
||||
~SharedDevice();
|
||||
};
|
||||
|
||||
pcies2mm_status_t open_device(const PcieS2mmDevice &device);
|
||||
void close_handles();
|
||||
|
||||
@@ -103,6 +112,7 @@ namespace gvfg::internal
|
||||
std::wstring friendly_name_;
|
||||
|
||||
HANDLE device_ = INVALID_HANDLE_VALUE;
|
||||
std::shared_ptr<SharedDevice> shared_device_;
|
||||
HANDLE dma_event_ = nullptr;
|
||||
HANDLE format_change_event_ = nullptr;
|
||||
HANDLE plug_in_event_ = nullptr;
|
||||
@@ -141,6 +151,12 @@ namespace gvfg::internal
|
||||
uint64_t latest_sequence_ = 0;
|
||||
uint64_t delivered_sequence_ = 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;
|
||||
double get_frame_timing_window_max_us_ = 0.0;
|
||||
double get_frame_timing_last_max300_us_ = 0.0;
|
||||
double get_frame_timing_lifetime_max_us_ = 0.0;
|
||||
std::chrono::steady_clock::time_point active_delivery_started_{};
|
||||
std::chrono::steady_clock::time_point last_delivery_started_{};
|
||||
bool stream_error_ = false;
|
||||
|
||||
@@ -12,6 +12,21 @@ namespace
|
||||
// Device interface exported by pcie_s2mm_driver.
|
||||
const GUID kPcieS2mmDeviceInterfaceGuid =
|
||||
{0x8c47b9c3, 0x1faa, 0x4557, {0xbc, 0x1d, 0xf2, 0x25, 0xd2, 0x6c, 0x9e, 0x91}};
|
||||
|
||||
std::wstring device_property(HDEVINFO info, SP_DEVINFO_DATA &deviceInfo, DWORD property)
|
||||
{
|
||||
DWORD required = 0;
|
||||
SetupDiGetDeviceRegistryPropertyW(info, &deviceInfo, property, nullptr,
|
||||
nullptr, 0, &required);
|
||||
if (required < sizeof(wchar_t))
|
||||
return {};
|
||||
|
||||
std::vector<uint8_t> bytes(required);
|
||||
if (!SetupDiGetDeviceRegistryPropertyW(info, &deviceInfo, property, nullptr,
|
||||
bytes.data(), required, nullptr))
|
||||
return {};
|
||||
return reinterpret_cast<const wchar_t *>(bytes.data());
|
||||
}
|
||||
}
|
||||
|
||||
namespace gvfg::internal
|
||||
@@ -36,12 +51,18 @@ namespace gvfg::internal
|
||||
std::vector<uint8_t> detailBytes(required);
|
||||
auto *detail = reinterpret_cast<SP_DEVICE_INTERFACE_DETAIL_DATA_W *>(detailBytes.data());
|
||||
detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
|
||||
if (!SetupDiGetDeviceInterfaceDetailW(info, &iface, detail, required, nullptr, nullptr))
|
||||
SP_DEVINFO_DATA deviceInfo = {};
|
||||
deviceInfo.cbSize = sizeof(deviceInfo);
|
||||
if (!SetupDiGetDeviceInterfaceDetailW(info, &iface, detail, required, nullptr, &deviceInfo))
|
||||
continue;
|
||||
|
||||
PcieS2mmDevice device;
|
||||
device.interface_path = detail->DevicePath;
|
||||
device.friendly_name = L"PcieS2mm Capture Device " + std::to_wstring(devices.size());
|
||||
device.friendly_name = device_property(info, deviceInfo, SPDRP_FRIENDLYNAME);
|
||||
if (device.friendly_name.empty())
|
||||
device.friendly_name = device_property(info, deviceInfo, SPDRP_DEVICEDESC);
|
||||
if (device.friendly_name.empty())
|
||||
device.friendly_name = L"PcieS2mm Capture Device " + std::to_wstring(devices.size());
|
||||
devices.push_back(device);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Private ABI contract between the GVFG backend and the PCIE S2MM driver.
|
||||
* This header is not part of the public GVFG SDK API.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define PCIES2MM_IOCTL(index, method, access) CTL_CODE(FILE_DEVICE_UNKNOWN, index, method, access)
|
||||
|
||||
#define IOCTL_PCIES2MM_WRITE_REG PCIES2MM_IOCTL(0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_PCIES2MM_READ_REG PCIES2MM_IOCTL(0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_PCIES2MM_REGISTER_EVENT PCIES2MM_IOCTL(0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_PCIES2MM_GET_FRAME PCIES2MM_IOCTL(0x803, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
|
||||
#define IOCTL_PCIES2MM_UNREGISTER_EVENT PCIES2MM_IOCTL(0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_VIDEO_START PCIES2MM_IOCTL(0x808, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_VIDEO_STOP PCIES2MM_IOCTL(0x809, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_RELEASE_VIDEO_FRAME PCIES2MM_IOCTL(0x80A, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_ACQUIRE_VIDEO_FRAME_ZEROCOPY PCIES2MM_IOCTL(0x80B, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_ENABLE_FRAME_ZEROCOPY PCIES2MM_IOCTL(0x80C, METHOD_NEITHER, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_DISABLE_FRAME_ZEROCOPY PCIES2MM_IOCTL(0x80D, METHOD_NEITHER, FILE_ANY_ACCESS)
|
||||
|
||||
enum PCIES2MM_DRIVER_EVENT_TYPE
|
||||
{
|
||||
PCIES2MM_EVENT_TYPE_VIDEO_DMA = 0,
|
||||
PCIES2MM_EVENT_TYPE_VIDEO_FORMAT_CHANGE = 1,
|
||||
PCIES2MM_EVENT_TYPE_VIDEO_PLUGIN = 2,
|
||||
PCIES2MM_EVENT_TYPE_VIDEO_UNPLUG = 3,
|
||||
PCIES2MM_EVENT_TYPE_AUDIO_DMA = 4
|
||||
};
|
||||
|
||||
struct PCIES2MM_REG_ACCESS
|
||||
{
|
||||
ULONG Offset;
|
||||
ULONG Value;
|
||||
};
|
||||
|
||||
struct PCIES2MM_EVENT_REG
|
||||
{
|
||||
ULONG Type;
|
||||
ULONG ChannelIndex;
|
||||
HANDLE EventHandle;
|
||||
};
|
||||
+210
-47
@@ -4,6 +4,7 @@
|
||||
#include "pcies2mm_capture_session.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <climits>
|
||||
@@ -26,6 +27,12 @@ using namespace gvfg::internal;
|
||||
|
||||
namespace
|
||||
{
|
||||
static_assert(GVFG_EVENT_MASK_SIGNAL_CONNECTED == PCIES2MM_EVENT_MASK_PLUG_IN);
|
||||
static_assert(GVFG_EVENT_MASK_SIGNAL_DISCONNECTED == PCIES2MM_EVENT_MASK_PLUG_OUT);
|
||||
static_assert(GVFG_EVENT_MASK_STREAM_READY == PCIES2MM_EVENT_MASK_STREAM_READY);
|
||||
static_assert(GVFG_EVENT_MASK_FORMAT_CHANGE_BEGIN == PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN);
|
||||
static_assert(GVFG_EVENT_MASK_FRAME_LOSS == PCIES2MM_EVENT_MASK_FRAME_LOSS);
|
||||
|
||||
#if INTPTR_MAX == INT64_MAX
|
||||
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");
|
||||
@@ -194,21 +201,26 @@ namespace
|
||||
|
||||
}
|
||||
|
||||
struct gvfg_handle_t
|
||||
struct gvfg_channel_session_t
|
||||
{
|
||||
~gvfg_handle_t()
|
||||
~gvfg_channel_session_t()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
gvfg_status_t open(int index, int channelIndex = GVFG_CHANNEL_0)
|
||||
gvfg_status_t open(int index,
|
||||
int channelIndex = GVFG_CHANNEL_0,
|
||||
gvfg::internal::PcieS2mmCaptureSession *sharedDeviceSource = nullptr)
|
||||
{
|
||||
if (index < 0 || (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1))
|
||||
return GVFG_EINVAL;
|
||||
close();
|
||||
|
||||
backend = std::make_unique<gvfg::internal::PcieS2mmCaptureSession>();
|
||||
const pcies2mm_status_t stOpen = backend->open_device_index(static_cast<size_t>(index));
|
||||
const pcies2mm_status_t stOpen = sharedDeviceSource
|
||||
? backend->open_shared_device(*sharedDeviceSource,
|
||||
static_cast<uint32_t>(channelIndex))
|
||||
: backend->open_device_index(static_cast<size_t>(index));
|
||||
if (stOpen != PCIES2MM_OK)
|
||||
{
|
||||
recordError(pcies2mm_error_text(stOpen, backend.get()));
|
||||
@@ -350,14 +362,14 @@ struct gvfg_handle_t
|
||||
{
|
||||
if (!backend)
|
||||
return;
|
||||
backend->set_event_callback(&gvfg_handle_t::onBackendEvent,
|
||||
backend->set_event_callback(&gvfg_channel_session_t::onBackendEvent,
|
||||
this,
|
||||
PCIES2MM_EVENT_MASK_DEFAULT);
|
||||
eventMask);
|
||||
}
|
||||
|
||||
static void onBackendEvent(pcies2mm_event_type_t event, void *user)
|
||||
{
|
||||
auto *self = static_cast<gvfg_handle_t *>(user);
|
||||
auto *self = static_cast<gvfg_channel_session_t *>(user);
|
||||
if (!self)
|
||||
return;
|
||||
self->emitEvent(event);
|
||||
@@ -671,6 +683,11 @@ struct gvfg_handle_t
|
||||
out.backend_active_delivery_slot = debugState.active_delivery_slot;
|
||||
out.backend_next_write_slot = debugState.next_write_slot;
|
||||
out.backend_ring_size = debugState.ring_size;
|
||||
out.get_frame_zero_copy = debugState.get_frame_zero_copy;
|
||||
out.get_frame_timing_samples = debugState.get_frame_timing_samples;
|
||||
out.get_frame_timing_average_us = debugState.get_frame_timing_average_us;
|
||||
out.get_frame_timing_max300_us = debugState.get_frame_timing_max300_us;
|
||||
out.get_frame_timing_max_us = debugState.get_frame_timing_max_us;
|
||||
}
|
||||
|
||||
return GVFG_OK;
|
||||
@@ -774,6 +791,7 @@ struct gvfg_handle_t
|
||||
int currentIndex = -1;
|
||||
uint32_t selectedChannel = GVFG_CHANNEL_0;
|
||||
bool zeroCopyRequested = false;
|
||||
uint32_t eventMask = GVFG_EVENT_MASK_ALL;
|
||||
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
@@ -802,6 +820,103 @@ struct gvfg_handle_t
|
||||
std::deque<gvfg_event_t> eventQueue;
|
||||
};
|
||||
|
||||
struct gvfg_handle_t
|
||||
{
|
||||
gvfg_channel_session_t *findChannel(int channelIndex)
|
||||
{
|
||||
if (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1)
|
||||
return nullptr;
|
||||
return channels[static_cast<size_t>(channelIndex)].get();
|
||||
}
|
||||
|
||||
gvfg_channel_session_t *firstOpenChannel()
|
||||
{
|
||||
if (channels[GVFG_CHANNEL_0])
|
||||
return channels[GVFG_CHANNEL_0].get();
|
||||
return channels[GVFG_CHANNEL_1].get();
|
||||
}
|
||||
|
||||
gvfg_status_t openChannel(int index, int channelIndex)
|
||||
{
|
||||
if (index < 0 || (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1))
|
||||
return GVFG_EINVAL;
|
||||
if (currentIndex >= 0 && currentIndex != index)
|
||||
return GVFG_ESTATE;
|
||||
|
||||
const size_t slot = static_cast<size_t>(channelIndex);
|
||||
if (channels[slot])
|
||||
return GVFG_OK;
|
||||
|
||||
auto channel = std::make_unique<gvfg_channel_session_t>();
|
||||
channel->zeroCopyRequested = zeroCopyRequested;
|
||||
channel->eventMask = eventMasks[slot];
|
||||
|
||||
gvfg::internal::PcieS2mmCaptureSession *sharedSource = nullptr;
|
||||
if (gvfg_channel_session_t *existing = firstOpenChannel())
|
||||
sharedSource = existing->backend.get();
|
||||
|
||||
const gvfg_status_t status = channel->open(index, channelIndex, sharedSource);
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
|
||||
channels[slot] = std::move(channel);
|
||||
currentIndex = index;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t setZeroCopyEnabled(bool enabled)
|
||||
{
|
||||
if (firstOpenChannel())
|
||||
return GVFG_ESTATE;
|
||||
zeroCopyRequested = enabled;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t setChannelEventMask(int channelIndex, uint32_t eventMask)
|
||||
{
|
||||
if (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1)
|
||||
return GVFG_EINVAL;
|
||||
if ((eventMask & ~static_cast<uint32_t>(GVFG_EVENT_MASK_ALL)) != 0)
|
||||
return GVFG_EINVAL;
|
||||
const size_t slot = static_cast<size_t>(channelIndex);
|
||||
if (channels[slot])
|
||||
return GVFG_ESTATE;
|
||||
eventMasks[slot] = eventMask;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t stopAll()
|
||||
{
|
||||
gvfg_status_t result = GVFG_OK;
|
||||
for (const auto &channel : channels)
|
||||
{
|
||||
if (!channel)
|
||||
continue;
|
||||
const gvfg_status_t status = channel->stop();
|
||||
if (result == GVFG_OK)
|
||||
result = status;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
gvfg_status_t debugReadRegister(uint32_t offset, uint32_t &outValue)
|
||||
{
|
||||
gvfg_channel_session_t *channel = firstOpenChannel();
|
||||
return channel ? channel->debugReadRegister(offset, outValue) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t debugWriteRegister(uint32_t offset, uint32_t value)
|
||||
{
|
||||
gvfg_channel_session_t *channel = firstOpenChannel();
|
||||
return channel ? channel->debugWriteRegister(offset, value) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
std::array<std::unique_ptr<gvfg_channel_session_t>, 2> channels;
|
||||
std::array<uint32_t, 2> eventMasks{GVFG_EVENT_MASK_ALL, GVFG_EVENT_MASK_ALL};
|
||||
int currentIndex = -1;
|
||||
bool zeroCopyRequested = false;
|
||||
};
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int gvfg_enumerate_devices(gvfg_device_info_t *out_devices, int max_devices)
|
||||
@@ -820,7 +935,6 @@ extern "C"
|
||||
for (int i = 0; i < written; ++i)
|
||||
{
|
||||
out_devices[i] = {};
|
||||
out_devices[i].index = i;
|
||||
copy_cstr(out_devices[i].name, sizeof(out_devices[i].name),
|
||||
"GVFG Capture");
|
||||
copy_wide_to_utf8(devices[static_cast<size_t>(i)].friendly_name,
|
||||
@@ -852,7 +966,27 @@ extern "C"
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->open(device_index, channel_index);
|
||||
return handle->openChannel(device_index, channel_index);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_channel_event_mask(gvfg_handle handle,
|
||||
int channel_index,
|
||||
uint32_t event_mask)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->setChannelEventMask(channel_index, event_mask);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_channel_event_mask(gvfg_handle handle,
|
||||
int channel_index,
|
||||
uint32_t *out_event_mask)
|
||||
{
|
||||
if (!handle || !out_event_mask ||
|
||||
(channel_index != GVFG_CHANNEL_0 && channel_index != GVFG_CHANNEL_1))
|
||||
return GVFG_EINVAL;
|
||||
*out_event_mask = handle->eventMasks[static_cast<size_t>(channel_index)];
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_zero_copy_enabled(gvfg_handle handle, int enabled)
|
||||
@@ -870,41 +1004,58 @@ extern "C"
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_start(gvfg_handle handle)
|
||||
gvfg_status_t gvfg_start_channel(gvfg_handle handle, int channel_index)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->start();
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->start() : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_video_format(gvfg_handle handle, gvfg_pixel_format_t format)
|
||||
gvfg_status_t gvfg_set_channel_video_format(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_pixel_format_t format)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->setVideoFormat(format);
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->setVideoFormat(format) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_read_frame(gvfg_handle handle, gvfg_frame_t *out_frame, uint32_t timeout_ms)
|
||||
gvfg_status_t gvfg_read_channel_frame(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_frame_t *out_frame,
|
||||
uint32_t timeout_ms)
|
||||
{
|
||||
if (!handle || !out_frame)
|
||||
return GVFG_EINVAL;
|
||||
return handle->readFrame(*out_frame, timeout_ms);
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->readFrame(*out_frame, timeout_ms) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_release_frame(gvfg_handle handle, const gvfg_frame_t *frame)
|
||||
gvfg_status_t gvfg_release_channel_frame(gvfg_handle handle,
|
||||
int channel_index,
|
||||
const gvfg_frame_t *frame)
|
||||
{
|
||||
if (!handle || !frame)
|
||||
return GVFG_EINVAL;
|
||||
return handle->releaseFrame(*frame);
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->releaseFrame(*frame) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_poll_event(gvfg_handle handle, gvfg_event_t *out_event, uint32_t timeout_ms)
|
||||
gvfg_status_t gvfg_poll_channel_event(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_event_t *out_event,
|
||||
uint32_t timeout_ms)
|
||||
{
|
||||
if (!handle || !out_event || out_event->struct_size < sizeof(gvfg_event_t))
|
||||
return GVFG_EINVAL;
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
if (!channel)
|
||||
return GVFG_ESTATE;
|
||||
gvfg_event_t event{};
|
||||
event.struct_size = sizeof(event);
|
||||
const gvfg_status_t status = handle->pollEvent(event, timeout_ms);
|
||||
const gvfg_status_t status = channel->pollEvent(event, timeout_ms);
|
||||
if (status == GVFG_OK)
|
||||
*out_event = event;
|
||||
return status;
|
||||
@@ -914,33 +1065,37 @@ extern "C"
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->stop();
|
||||
return handle->stopAll();
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_signal_status(gvfg_handle handle, gvfg_signal_status_t *out_status)
|
||||
gvfg_status_t gvfg_stop_channel(gvfg_handle handle, int channel_index)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->stop() : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_channel_signal_status(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_signal_status_t *out_status)
|
||||
{
|
||||
if (!handle || !out_status)
|
||||
return GVFG_EINVAL;
|
||||
gvfg_signal_status_t statusInfo{};
|
||||
const gvfg_status_t status = handle->getSignalStatus(statusInfo);
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
|
||||
*out_status = statusInfo;
|
||||
return GVFG_OK;
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
if (!channel)
|
||||
return GVFG_ESTATE;
|
||||
return channel->getSignalStatus(*out_status);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_runtime_info(gvfg_handle handle, gvfg_runtime_info_t *out_info)
|
||||
gvfg_status_t gvfg_get_channel_runtime_info(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_runtime_info_t *out_info)
|
||||
{
|
||||
if (!handle || !out_info)
|
||||
return GVFG_EINVAL;
|
||||
gvfg_runtime_info_t runtimeInfo{};
|
||||
const gvfg_status_t status = handle->getRuntimeInfo(runtimeInfo);
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
|
||||
*out_info = runtimeInfo;
|
||||
return GVFG_OK;
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->getRuntimeInfo(*out_info) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
const char *gvfg_get_version(void)
|
||||
@@ -976,23 +1131,29 @@ extern "C"
|
||||
}
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_last_error_detail(gvfg_handle handle,
|
||||
char *out_message,
|
||||
uint32_t out_message_size)
|
||||
gvfg_status_t gvfg_get_channel_last_error_detail(gvfg_handle handle,
|
||||
int channel_index,
|
||||
char *out_message,
|
||||
uint32_t out_message_size)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->getLastErrorDetail(out_message, out_message_size);
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->getLastErrorDetail(out_message, out_message_size) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_get_backend_stats(gvfg_handle handle,
|
||||
gvfg_debug_backend_stats_t *out_stats)
|
||||
gvfg_status_t gvfg_debug_get_channel_backend_stats(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_debug_backend_stats_t *out_stats)
|
||||
{
|
||||
if (!handle || !out_stats)
|
||||
return GVFG_EINVAL;
|
||||
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
if (!channel)
|
||||
return GVFG_ESTATE;
|
||||
gvfg_debug_backend_stats_t stats{};
|
||||
const gvfg_status_t status = handle->getDebugBackendStats(stats);
|
||||
const gvfg_status_t status = channel->getDebugBackendStats(stats);
|
||||
if (status != GVFG_OK)
|
||||
return status;
|
||||
|
||||
@@ -1000,13 +1161,15 @@ extern "C"
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_get_last_error_detail(gvfg_handle handle,
|
||||
char *out_message,
|
||||
uint32_t out_message_size)
|
||||
gvfg_status_t gvfg_debug_get_channel_last_error_detail(gvfg_handle handle,
|
||||
int channel_index,
|
||||
char *out_message,
|
||||
uint32_t out_message_size)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->getLastErrorDetail(out_message, out_message_size);
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->getLastErrorDetail(out_message, out_message_size) : GVFG_ESTATE;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_debug_read_register(gvfg_handle handle,
|
||||
|
||||
Reference in New Issue
Block a user