Simplify the SDK around GigabyteLib

Compared with 0af70a5:

- Remove the generic backend directory and legacy PCIE S2MM naming so the SDK now has a direct gvfg facade to GigabyteCaptureSession to GvfgSdk.lib structure.

- Delete the unsupported video-format setter and direct register read/write APIs instead of retaining compatibility methods that cannot be implemented by the supplied GigabyteLib interface.

- Remove output-format controls and requested-format state from the Qt sample; capture now follows the native YUY2 or Y210 format reported by GvfgGetVideoInfo.

- Eliminate the placeholder stream descriptor and allocate copy buffers from current GigabyteLib video metadata when a frame becomes available.

- Rename the internal debug stats API and fields from backend terminology to channel/session terminology, while retaining capture, audio, event, timeout, timing, and zero-copy diagnostics.

- Update source paths and documentation to describe GigabyteLib as the only lower layer and remove stale format-setting, register, and direct IOCTL guidance.

Validation: git diff --cached --check passed. MSVC x64 Release and Debug gvfg.dll builds passed, the Release Qt sample rebuilt and linked successfully, dumpbin verified the intentional 29-export API, and the Release package script produced an archive containing the sample and gvfg.dll without private GigabyteLib files or giga_ioctl.dll. No runtime capture, audio, zero-copy, hot-plug, dual-channel, shutdown, MinGW, or hardware validation was run.
This commit is contained in:
Mark.lin
2026-09-14 10:05:54 +08:00
parent 0af70a59ca
commit a04bd611f9
26 changed files with 532 additions and 920 deletions
+16 -39
View File
@@ -39,11 +39,11 @@ namespace
QString boolText(int value) { return value ? QStringLiteral("yes") : QStringLiteral("no"); } QString boolText(int value) { return value ? QStringLiteral("yes") : QStringLiteral("no"); }
QString valueOrDash(uint64_t value) { return QString::number(static_cast<qulonglong>(value)); } QString valueOrDash(uint64_t value) { return QString::number(static_cast<qulonglong>(value)); }
QString captureStatusText(const gvfg_debug_backend_stats_t &stats, bool signalConnected) QString captureStatusText(const gvfg_debug_channel_stats_t &stats, bool signalConnected)
{ {
if (!stats.backend_running) return QStringLiteral("stopped"); if (!stats.session_running) return QStringLiteral("stopped");
if (!signalConnected) return QStringLiteral("waiting_signal"); if (!signalConnected) return QStringLiteral("waiting_signal");
if (!stats.backend_capture_active) return QStringLiteral("paused"); if (!stats.session_capture_active) return QStringLiteral("paused");
return QStringLiteral("streaming"); return QStringLiteral("streaming");
} }
#endif #endif
@@ -98,13 +98,11 @@ CaptureController::~CaptureController()
closeDevice(); closeDevice();
} }
void CaptureController::setChannelOptions(int channel, bool zeroCopy, void CaptureController::setChannelOptions(int channel, bool zeroCopy, bool audioEnabled)
gvfg_pixel_format_t format, bool audioEnabled)
{ {
if (channel < GVFG_CHANNEL_0 || channel > GVFG_CHANNEL_1) if (channel < GVFG_CHANNEL_0 || channel > GVFG_CHANNEL_1)
return; return;
channels_[channel].zeroCopy = zeroCopy; channels_[channel].zeroCopy = zeroCopy;
channels_[channel].requestedFormat = format;
channels_[channel].requestedAudio = channel == GVFG_CHANNEL_0 && audioEnabled; channels_[channel].requestedAudio = channel == GVFG_CHANNEL_0 && audioEnabled;
} }
@@ -231,7 +229,7 @@ bool CaptureController::openChannel(int channel)
{ {
ChannelRuntime &runtime = channels_[channel]; ChannelRuntime &runtime = channels_[channel];
if (runtime.opened) if (runtime.opened)
return applyOutputFormat(channel); return true;
if (handle_ == nullptr && !openDevice()) if (handle_ == nullptr && !openDevice())
return false; return false;
@@ -249,8 +247,6 @@ bool CaptureController::openChannel(int channel)
return false; return false;
} }
runtime.opened = true; runtime.opened = true;
if (!applyOutputFormat(channel))
return false;
appendLog(QStringLiteral("Opened device index %1 CH%2 | mode=%3") appendLog(QStringLiteral("Opened device index %1 CH%2 | mode=%3")
.arg(selectedDeviceIndex_) .arg(selectedDeviceIndex_)
@@ -295,25 +291,6 @@ void CaptureController::closeDevice()
emit stateChanged(); emit stateChanged();
} }
bool CaptureController::applyOutputFormat(int channel)
{
if (handle_ == nullptr || !channels_[channel].opened ||
channels_[channel].running.load(std::memory_order_acquire))
return false;
const gvfg_pixel_format_t format = channels_[channel].requestedFormat;
const gvfg_status_t status = gvfg_set_channel_video_format(handle_, channel, format);
if (status != GVFG_OK)
{
reportError(QStringLiteral("set output format register"), status, channel);
return false;
}
appendLog(QStringLiteral("CH%1 Output format | %2")
.arg(channel)
.arg(format == GVFG_PIXFMT_Y210 ? QStringLiteral("Y210") : QStringLiteral("YUY2")));
return true;
}
void CaptureController::startCapture(int channelIndex) void CaptureController::startCapture(int channelIndex)
{ {
ChannelRuntime &channel = channels_[channelIndex]; ChannelRuntime &channel = channels_[channelIndex];
@@ -656,8 +633,8 @@ void CaptureController::updateSignalStatus(bool queryHardware)
sdkBytes = channel.audioReceivedBytes; sdkBytes = channel.audioReceivedBytes;
appOutputBytes = channel.audioAcceptedBytes; appOutputBytes = channel.audioAcceptedBytes;
} }
gvfg_debug_backend_stats_t audioStats{}; gvfg_debug_channel_stats_t audioStats{};
if (gvfg_debug_get_channel_backend_stats(handle_, channelIndex, &audioStats) == GVFG_OK) if (gvfg_debug_get_channel_stats(handle_, channelIndex, &audioStats) == GVFG_OK)
{ {
statusLines << QStringLiteral("CH%1 Audio Debug | Events DMA=%2 Extra=%3 | Driver->SDK %4 frames/%5 bytes | SDK->APP %6 frames/%7 bytes | APP->Output %8 bytes") statusLines << QStringLiteral("CH%1 Audio Debug | Events DMA=%2 Extra=%3 | Driver->SDK %4 frames/%5 bytes | SDK->APP %6 frames/%7 bytes | APP->Output %8 bytes")
.arg(channelIndex) .arg(channelIndex)
@@ -702,23 +679,23 @@ void CaptureController::updateSignalStatus(bool queryHardware)
} }
#if GVFG_INTERNAL_DIAGNOSTICS #if GVFG_INTERNAL_DIAGNOSTICS
gvfg_debug_backend_stats_t backendStats{}; gvfg_debug_channel_stats_t channelStats{};
if (gvfg_debug_get_channel_backend_stats(handle_, channelIndex, &backendStats) == GVFG_OK) if (gvfg_debug_get_channel_stats(handle_, channelIndex, &channelStats) == GVFG_OK)
{ {
statusLines << QStringLiteral("CH%1 Capture | status=%2 dma_errors=%3 no_frame_waits=%4") statusLines << QStringLiteral("CH%1 Capture | status=%2 dma_errors=%3 no_frame_waits=%4")
.arg(channelIndex) .arg(channelIndex)
.arg(captureStatusText(backendStats, signal.connected != 0)) .arg(captureStatusText(channelStats, signal.connected != 0))
.arg(static_cast<qulonglong>(backendStats.backend_dma_errors)) .arg(static_cast<qulonglong>(channelStats.session_dma_errors))
.arg(static_cast<qulonglong>(backendStats.backend_wait_timeouts)); .arg(static_cast<qulonglong>(channelStats.session_wait_timeouts));
if (channel.haveDebugBaseline && backendStats.backend_dma_errors > channel.lastDebugDmaErrors) if (channel.haveDebugBaseline && channelStats.session_dma_errors > channel.lastDebugDmaErrors)
{ {
appendLog(QStringLiteral("CH%1 ERROR DMA failures +%2, total=%3") appendLog(QStringLiteral("CH%1 ERROR DMA failures +%2, total=%3")
.arg(channelIndex) .arg(channelIndex)
.arg(valueOrDash(backendStats.backend_dma_errors - channel.lastDebugDmaErrors), .arg(valueOrDash(channelStats.session_dma_errors - channel.lastDebugDmaErrors),
valueOrDash(backendStats.backend_dma_errors))); valueOrDash(channelStats.session_dma_errors)));
diagnosticProblemDetected = true; diagnosticProblemDetected = true;
} }
channel.lastDebugDmaErrors = backendStats.backend_dma_errors; channel.lastDebugDmaErrors = channelStats.session_dma_errors;
channel.haveDebugBaseline = true; channel.haveDebugBaseline = true;
} }
#endif #endif
+1 -3
View File
@@ -29,7 +29,7 @@ public:
~CaptureController() override; ~CaptureController() override;
void setSelectedDeviceIndex(int index) { selectedDeviceIndex_ = index; } void setSelectedDeviceIndex(int index) { selectedDeviceIndex_ = index; }
void setChannelOptions(int channel, bool zeroCopy, gvfg_pixel_format_t format, bool audioEnabled); void setChannelOptions(int channel, bool zeroCopy, bool audioEnabled);
void setChannelStatusVisible(int channel, bool visible); void setChannelStatusVisible(int channel, bool visible);
void setPreviewTarget(int channel, void *nativeWindow); void setPreviewTarget(int channel, void *nativeWindow);
void setPreviewVisible(int channel, bool visible); void setPreviewVisible(int channel, bool visible);
@@ -47,7 +47,6 @@ public slots:
void refreshDevices(); void refreshDevices();
bool openDevice(); bool openDevice();
void closeDevice(); void closeDevice();
bool applyOutputFormat(int channel);
void startCapture(int channel); void startCapture(int channel);
void stopCapture(int channel); void stopCapture(int channel);
void stopAllCaptures(); void stopAllCaptures();
@@ -71,7 +70,6 @@ private:
bool opened = false; bool opened = false;
bool zeroCopy = false; bool zeroCopy = false;
bool requestedAudio = false; bool requestedAudio = false;
gvfg_pixel_format_t requestedFormat = GVFG_PIXFMT_YUY2;
void *previewTarget = nullptr; void *previewTarget = nullptr;
gvfg_preview_handle previewHandle = nullptr; gvfg_preview_handle previewHandle = nullptr;
std::atomic<bool> running{false}, stopRequested{false}, signalConnected{false}; std::atomic<bool> running{false}, stopRequested{false}, signalConnected{false};
+1 -35
View File
@@ -4,7 +4,6 @@
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QCloseEvent> #include <QCloseEvent>
#include <QStandardItemModel>
#include <QSyntaxHighlighter> #include <QSyntaxHighlighter>
#include <QTextCharFormat> #include <QTextCharFormat>
@@ -102,14 +101,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui_->ch0FullscreenButton, &QPushButton::clicked, this, [this] { showPreviewWindow(0, true); }); connect(ui_->ch0FullscreenButton, &QPushButton::clicked, this, [this] { showPreviewWindow(0, true); });
connect(ui_->ch1FullscreenButton, &QPushButton::clicked, this, [this] { showPreviewWindow(1, true); }); connect(ui_->ch1FullscreenButton, &QPushButton::clicked, this, [this] { showPreviewWindow(1, true); });
auto formatChanged = [this](int channel) {
updateOutputFormatOptions(channel);
syncControllerOptions(channel);
if (controller_->channelOpened(channel) && !controller_->channelRunning(channel))
{ controller_->applyOutputFormat(channel); controller_->updateSignalStatus(); }
};
connect(ui_->ch0OutputFormatCombo, &QComboBox::currentIndexChanged, this, [formatChanged](int) { formatChanged(0); });
connect(ui_->ch1OutputFormatCombo, &QComboBox::currentIndexChanged, this, [formatChanged](int) { formatChanged(1); });
connect(ui_->ch0ZeroCopyCheckBox, &QCheckBox::toggled, this, [this](bool) { connect(ui_->ch0ZeroCopyCheckBox, &QCheckBox::toggled, this, [this](bool) {
syncControllerOptions(GVFG_CHANNEL_0); syncControllerOptions(GVFG_CHANNEL_0);
if (controller_->deviceOpen()) controller_->updateSignalStatus(false); if (controller_->deviceOpen()) controller_->updateSignalStatus(false);
@@ -119,7 +110,6 @@ MainWindow::MainWindow(QWidget *parent)
if (controller_->deviceOpen()) controller_->updateSignalStatus(false); if (controller_->deviceOpen()) controller_->updateSignalStatus(false);
}); });
updateOutputFormatOptions();
updateUiState(); updateUiState();
controller_->logStartupInfo(); controller_->logStartupInfo();
controller_->refreshDevices(); controller_->refreshDevices();
@@ -148,10 +138,8 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::syncControllerOptions(int channel) void MainWindow::syncControllerOptions(int channel)
{ {
const bool zeroCopy = channel == 0 ? ui_->ch0ZeroCopyCheckBox->isChecked() : ui_->ch1ZeroCopyCheckBox->isChecked(); const bool zeroCopy = channel == 0 ? ui_->ch0ZeroCopyCheckBox->isChecked() : ui_->ch1ZeroCopyCheckBox->isChecked();
const int formatIndex = channel == 0 ? ui_->ch0OutputFormatCombo->currentIndex() : ui_->ch1OutputFormatCombo->currentIndex();
const bool audio = channel == 0 && ui_->ch0AudioCheckBox->isChecked(); const bool audio = channel == 0 && ui_->ch0AudioCheckBox->isChecked();
controller_->setChannelOptions(channel, zeroCopy, controller_->setChannelOptions(channel, zeroCopy, audio);
formatIndex == 1 ? GVFG_PIXFMT_Y210 : GVFG_PIXFMT_YUY2, audio);
} }
void MainWindow::showPreviewWindow(int channel, bool fullscreen) void MainWindow::showPreviewWindow(int channel, bool fullscreen)
@@ -170,27 +158,6 @@ void MainWindow::showPreviewWindow(int channel, bool fullscreen)
: QStringLiteral("CH%1 Show Preview failed: unable to update preview window").arg(channel)); : QStringLiteral("CH%1 Show Preview failed: unable to update preview window").arg(channel));
} }
void MainWindow::updateOutputFormatOptions(int changedChannel)
{
QComboBox *combos[] = {ui_->ch0OutputFormatCombo, ui_->ch1OutputFormatCombo};
constexpr int y210 = 1;
if ((changedChannel == 0 || changedChannel == 1) && combos[changedChannel]->currentIndex() == y210)
{
const int other = changedChannel == 0 ? 1 : 0;
if (combos[other]->currentIndex() == y210) combos[other]->setCurrentIndex(0);
}
const bool enabled[] = {combos[1]->currentIndex() != y210, combos[0]->currentIndex() != y210};
for (int channel = 0; channel < 2; ++channel)
{
auto *model = qobject_cast<QStandardItemModel *>(combos[channel]->model());
if (model && model->item(y210)) model->item(y210)->setEnabled(enabled[channel]);
combos[channel]->setToolTip(
enabled[channel]
? QStringLiteral("Requested CH%1 capture output format").arg(channel)
: QStringLiteral("Y210 is already selected by the other channel"));
}
}
void MainWindow::updateUiState() void MainWindow::updateUiState()
{ {
const bool open = controller_->deviceOpen(); const bool open = controller_->deviceOpen();
@@ -206,7 +173,6 @@ void MainWindow::updateUiState()
ui_->ch1PreviewButton->setEnabled(running[1] && controller_->frameAvailable(1)); ui_->ch1PreviewButton->setEnabled(running[1] && controller_->frameAvailable(1));
ui_->ch0FullscreenButton->setEnabled(ui_->ch0PreviewButton->isEnabled()); ui_->ch0FullscreenButton->setEnabled(ui_->ch0PreviewButton->isEnabled());
ui_->ch1FullscreenButton->setEnabled(ui_->ch1PreviewButton->isEnabled()); ui_->ch1FullscreenButton->setEnabled(ui_->ch1PreviewButton->isEnabled());
ui_->ch0OutputFormatCombo->setEnabled(!running[0]); ui_->ch1OutputFormatCombo->setEnabled(!running[1]);
ui_->ch0ZeroCopyCheckBox->setEnabled(!controller_->channelOpened(0)); ui_->ch0ZeroCopyCheckBox->setEnabled(!controller_->channelOpened(0));
ui_->ch1ZeroCopyCheckBox->setEnabled(!controller_->channelOpened(1)); ui_->ch1ZeroCopyCheckBox->setEnabled(!controller_->channelOpened(1));
ui_->ch0AudioCheckBox->setEnabled(!running[0]); ui_->ch0AudioCheckBox->setEnabled(!running[0]);
-1
View File
@@ -27,7 +27,6 @@ protected:
private: private:
void syncControllerOptions(int channel); void syncControllerOptions(int channel);
void showPreviewWindow(int channel, bool fullscreen); void showPreviewWindow(int channel, bool fullscreen);
void updateOutputFormatOptions(int changedChannel = -1);
void updateUiState(); void updateUiState();
void appendLogLine(const QString &line); void appendLogLine(const QString &line);
+3 -54
View File
@@ -63,30 +63,6 @@
</property> </property>
<layout class="QGridLayout" name="channel0GridLayout"> <layout class="QGridLayout" name="channel0GridLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="channel0FormatLabel">
<property name="text">
<string>Output format:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="ch0OutputFormatCombo">
<property name="toolTip">
<string>Requested CH0 capture output format</string>
</property>
<item>
<property name="text">
<string>YUY2 (8-bit 4:2:2)</string>
</property>
</item>
<item>
<property name="text">
<string>Y210 (10-bit 4:2:2)</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="ch0ZeroCopyCheckBox"> <widget class="QCheckBox" name="ch0ZeroCopyCheckBox">
<property name="toolTip"> <property name="toolTip">
<string>Must be selected before opening CH0</string> <string>Must be selected before opening CH0</string>
@@ -99,7 +75,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="3"> <item row="0" column="1">
<widget class="QCheckBox" name="ch0AudioCheckBox"> <widget class="QCheckBox" name="ch0AudioCheckBox">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@@ -115,7 +91,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="4"> <item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="channel0ButtonLayout"> <layout class="QHBoxLayout" name="channel0ButtonLayout">
<item> <item>
<widget class="QPushButton" name="ch0StartButton"> <widget class="QPushButton" name="ch0StartButton">
@@ -157,33 +133,6 @@
</property> </property>
<layout class="QGridLayout" name="channel1GridLayout"> <layout class="QGridLayout" name="channel1GridLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="channel1FormatLabel">
<property name="text">
<string>Output format:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="ch1OutputFormatCombo">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Requested CH1 capture output format</string>
</property>
<item>
<property name="text">
<string>YUY2 (8-bit 4:2:2)</string>
</property>
</item>
<item>
<property name="text">
<string>Y210 (10-bit 4:2:2)</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="ch1ZeroCopyCheckBox"> <widget class="QCheckBox" name="ch1ZeroCopyCheckBox">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
@@ -196,7 +145,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="3"> <item row="1" column="0">
<layout class="QHBoxLayout" name="channel1ButtonLayout"> <layout class="QHBoxLayout" name="channel1ButtonLayout">
<item> <item>
<widget class="QPushButton" name="ch1StartButton"> <widget class="QPushButton" name="ch1StartButton">
+6 -6
View File
@@ -7,11 +7,11 @@ add_library(gvfg SHARED
gvfg.def gvfg.def
include/gvfg_capture.h include/gvfg_capture.h
include/gvfg_debug.h include/gvfg_debug.h
src/backend/gigabyte/gigabyte_backend_types.h src/gigabyte/gigabyte_types.h
src/backend/gigabyte/gigabyte_capture_session.cpp src/gigabyte/gigabyte_capture_session.cpp
src/backend/gigabyte/gigabyte_capture_session.h src/gigabyte/gigabyte_capture_session.h
src/backend/gigabyte/gigabyte_device.cpp src/gigabyte/gigabyte_device.cpp
src/backend/gigabyte/gigabyte_device.h src/gigabyte/gigabyte_device.h
src/gpu/d3d_conversion_pipeline.cpp src/gpu/d3d_conversion_pipeline.cpp
src/gpu/d3d_conversion_pipeline.h src/gpu/d3d_conversion_pipeline.h
src/gpu/gvfg_gpu_convert.cpp src/gpu/gvfg_gpu_convert.cpp
@@ -30,7 +30,7 @@ target_include_directories(gvfg
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/gigabyte ${CMAKE_CURRENT_SOURCE_DIR}/src/gigabyte
${CMAKE_CURRENT_SOURCE_DIR}/src/gpu ${CMAKE_CURRENT_SOURCE_DIR}/src/gpu
${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/GigabyteLib ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/GigabyteLib
) )
+1 -4
View File
@@ -9,7 +9,6 @@ EXPORTS
gvfg_get_channel_event_mask gvfg_get_channel_event_mask
gvfg_set_channel_zero_copy_enabled gvfg_set_channel_zero_copy_enabled
gvfg_get_channel_zero_copy_enabled gvfg_get_channel_zero_copy_enabled
gvfg_set_channel_video_format
gvfg_set_channel_audio_enabled gvfg_set_channel_audio_enabled
gvfg_get_channel_audio_format gvfg_get_channel_audio_format
gvfg_start_channel gvfg_start_channel
@@ -30,6 +29,4 @@ EXPORTS
gvfg_pixel_format_name gvfg_pixel_format_name
gvfg_strerror gvfg_strerror
gvfg_get_channel_last_error_detail gvfg_get_channel_last_error_detail
gvfg_debug_get_channel_backend_stats gvfg_debug_get_channel_stats
gvfg_debug_read_register
gvfg_debug_write_register
-12
View File
@@ -340,18 +340,6 @@ extern "C"
_In_ int channel_index, _In_ int channel_index,
_Out_ int *out_enabled); _Out_ int *out_enabled);
/*
* Request the native capture format. Call after opening the device and
* before gvfg_start_channel(), or after gvfg_stop_channel(). A running stream
* rejects the change with GVFG_ESTATE. The GigabyteLib backend does not
* expose format conversion, so it returns GVFG_ENOTSUP when a connected
* input's native format differs from the requested format.
*/
GVFG_API gvfg_status_t gvfg_set_channel_video_format(
_In_ gvfg_handle handle,
_In_ int channel_index,
_In_ gvfg_pixel_format_t format);
/* /*
* Enable or disable audio for the next channel start. Video remains * Enable or disable audio for the next channel start. Video remains
* enabled; applications do not need to construct stream flag masks. * enabled; applications do not need to construct stream flag masks.
+14 -30
View File
@@ -34,17 +34,17 @@ typedef struct
uint64_t frames_returned; uint64_t frames_returned;
gvfg_debug_last_frame_info_t last_frame; gvfg_debug_last_frame_info_t last_frame;
int backend_state; int session_state;
uint64_t backend_frames_captured; uint64_t session_frames_captured;
uint64_t backend_frames_delivered; uint64_t session_frames_delivered;
uint64_t backend_dma_errors; uint64_t session_dma_errors;
uint64_t backend_interrupt_count; uint64_t session_interrupt_count;
uint64_t backend_wait_timeouts; uint64_t session_wait_timeouts;
int backend_running; int session_running;
int backend_capture_active; int session_capture_active;
uint64_t backend_latest_sequence; uint64_t session_latest_sequence;
uint64_t backend_delivered_sequence; uint64_t session_delivered_sequence;
uint64_t audio_dma_event_wakes; uint64_t audio_dma_event_wakes;
uint64_t extra_audio_event_wakes; uint64_t extra_audio_event_wakes;
uint64_t audio_frames_from_driver; uint64_t audio_frames_from_driver;
@@ -55,34 +55,18 @@ typedef struct
double get_frame_timing_average_us; double get_frame_timing_average_us;
double get_frame_timing_max300_us; double get_frame_timing_max300_us;
double get_frame_timing_max_us; double get_frame_timing_max_us;
} gvfg_debug_backend_stats_t; } gvfg_debug_channel_stats_t;
/* /*
* Query driver-neutral internal backend counters. * Query driver-neutral internal session counters.
* *
* This exposes implementation-level counters for internal tools only. Customer * This exposes implementation-level counters for internal tools only. Customer
* applications should use gvfg_get_channel_runtime_info() instead. * applications should use gvfg_get_channel_runtime_info() instead.
*/ */
GVFG_API gvfg_status_t gvfg_debug_get_channel_backend_stats( GVFG_API gvfg_status_t gvfg_debug_get_channel_stats(
_In_ gvfg_handle handle, _In_ gvfg_handle handle,
_In_ int channel_index, _In_ int channel_index,
_Out_ gvfg_debug_backend_stats_t *out_stats); _Out_ gvfg_debug_channel_stats_t *out_stats);
/*
* Read or write one 32-bit BAR-relative hardware register.
*
* The offset must be 4-byte aligned. Register writes can disrupt active DMA,
* interrupt handling, or video capture and are intended for internal tools.
*/
GVFG_API gvfg_status_t gvfg_debug_read_register(
_In_ gvfg_handle handle,
_In_ uint32_t offset,
_Out_ uint32_t *out_value);
GVFG_API gvfg_status_t gvfg_debug_write_register(
_In_ gvfg_handle handle,
_In_ uint32_t offset,
_In_ uint32_t value);
#ifdef __cplusplus #ifdef __cplusplus
} }
@@ -1,118 +0,0 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
typedef enum pcies2mm_status_t
{
PCIES2MM_OK = 0,
PCIES2MM_EINVAL,
PCIES2MM_ENODEV,
PCIES2MM_ESTATE,
PCIES2MM_ENOTSUP,
PCIES2MM_ETIMEOUT,
PCIES2MM_EIO
} pcies2mm_status_t;
typedef enum pcies2mm_pixel_format_t
{
PCIES2MM_PIXFMT_UNKNOWN = 0,
PCIES2MM_PIXFMT_Y210 = 2,
PCIES2MM_PIXFMT_YUY2 = 3
} pcies2mm_pixel_format_t;
typedef enum pcies2mm_stream_state_t
{
PCIES2MM_STREAM_STOPPED = 0,
PCIES2MM_STREAM_CONFIGURED = 1,
PCIES2MM_STREAM_RUNNING = 2
} pcies2mm_stream_state_t;
typedef struct pcies2mm_stream_desc_t
{
uint32_t width;
uint32_t height;
pcies2mm_pixel_format_t pixel_format;
uint32_t buffer_count;
uint32_t flags;
} pcies2mm_stream_desc_t;
typedef struct pcies2mm_signal_status_t
{
int connected;
uint32_t channel;
uint32_t width;
uint32_t height;
pcies2mm_pixel_format_t pixel_format;
uint32_t bit_depth;
} pcies2mm_signal_status_t;
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;
uint32_t bit_depth;
} pcies2mm_frame_t;
typedef struct pcies2mm_audio_format_t
{
uint32_t sample_rate;
uint32_t channels;
uint32_t bits_per_sample;
uint32_t frames_per_second;
uint32_t frame_bytes;
uint32_t block_align;
} pcies2mm_audio_format_t;
typedef struct pcies2mm_stream_stats_t
{
pcies2mm_stream_state_t state;
uint64_t frames_captured;
uint64_t frames_delivered;
uint64_t dma_errors;
uint64_t interrupt_count;
} pcies2mm_stream_stats_t;
typedef struct pcies2mm_debug_state_t
{
int running;
int capture_active;
uint64_t latest_sequence;
uint64_t delivered_sequence;
uint64_t audio_dma_event_wakes;
uint64_t extra_audio_event_wakes;
uint64_t audio_frames_from_driver;
uint64_t audio_bytes_from_driver;
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
{
PCIES2MM_EVENT_PLUG_IN = 1,
PCIES2MM_EVENT_PLUG_OUT = 2,
PCIES2MM_EVENT_STREAM_READY = 3,
PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN = 4
} pcies2mm_event_type_t;
enum
{
PCIES2MM_EVENT_MASK_PLUG_IN = 1u << 0,
PCIES2MM_EVENT_MASK_PLUG_OUT = 1u << 1,
PCIES2MM_EVENT_MASK_STREAM_READY = 1u << 2,
PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN = 1u << 3,
PCIES2MM_EVENT_MASK_DEFAULT = PCIES2MM_EVENT_MASK_PLUG_IN |
PCIES2MM_EVENT_MASK_PLUG_OUT |
PCIES2MM_EVENT_MASK_STREAM_READY |
PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN
};
typedef void (*pcies2mm_event_callback_t)(pcies2mm_event_type_t event, void *user);
@@ -18,80 +18,80 @@ uint64_t monotonic_ns()
return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(now).count()); return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(now).count());
} }
pcies2mm_pixel_format_t decode_fourcc(uint32_t fourcc) gigabyte_pixel_format_t decode_fourcc(uint32_t fourcc)
{ {
if (fourcc == kFourccY210) if (fourcc == kFourccY210)
return PCIES2MM_PIXFMT_Y210; return GIGABYTE_PIXFMT_Y210;
if (fourcc == kFourccYuy2 || fourcc == kFourccYuyv || fourcc == kFourccUyvy) if (fourcc == kFourccYuy2 || fourcc == kFourccYuyv || fourcc == kFourccUyvy)
return PCIES2MM_PIXFMT_YUY2; return GIGABYTE_PIXFMT_YUY2;
return PCIES2MM_PIXFMT_UNKNOWN; return GIGABYTE_PIXFMT_UNKNOWN;
} }
uint32_t bit_depth(pcies2mm_pixel_format_t format) uint32_t bit_depth(gigabyte_pixel_format_t format)
{ {
return format == PCIES2MM_PIXFMT_Y210 ? 10u : return format == GIGABYTE_PIXFMT_Y210 ? 10u :
format == PCIES2MM_PIXFMT_YUY2 ? 8u : 0u; format == GIGABYTE_PIXFMT_YUY2 ? 8u : 0u;
} }
} }
namespace gvfg::internal namespace gvfg::internal
{ {
PcieS2mmCaptureSession::PcieS2mmCaptureSession(ChannelErrorState &errorState) GigabyteCaptureSession::GigabyteCaptureSession(ChannelErrorState &errorState)
: error_state_(errorState) : error_state_(errorState)
{ {
} }
PcieS2mmCaptureSession::~PcieS2mmCaptureSession() GigabyteCaptureSession::~GigabyteCaptureSession()
{ {
close(); close();
} }
pcies2mm_status_t PcieS2mmCaptureSession::open_device_index(size_t deviceIndex) gigabyte_status_t GigabyteCaptureSession::open_device_index(size_t deviceIndex)
{ {
const auto devices = enumerate_gigabyte_devices(); const auto devices = enumerate_gigabyte_devices();
if (deviceIndex >= devices.size()) if (deviceIndex >= devices.size())
return reject(PCIES2MM_ENODEV, "GigabyteLib open rejected: device index is unavailable"); return reject(GIGABYTE_ENODEV, "GigabyteLib open rejected: device index is unavailable");
return open_device(devices[deviceIndex]); return open_device(devices[deviceIndex]);
} }
pcies2mm_status_t PcieS2mmCaptureSession::open_device_connection( gigabyte_status_t GigabyteCaptureSession::open_device_connection(
const std::shared_ptr<PcieS2mmDeviceConnection> &connection) const std::shared_ptr<GigabyteDeviceConnection> &connection)
{ {
if (!connection || connection->interface_path.empty()) if (!connection || connection->interface_path.empty())
return reject(PCIES2MM_EINVAL, "GigabyteLib open rejected: device selection is invalid"); return reject(GIGABYTE_EINVAL, "GigabyteLib open rejected: device selection is invalid");
close(); close();
device_connection_ = connection; device_connection_ = connection;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::open_device(const GigabyteDevice &device) gigabyte_status_t GigabyteCaptureSession::open_device(const GigabyteDevice &device)
{ {
close(); close();
device_connection_ = std::make_shared<PcieS2mmDeviceConnection>(); device_connection_ = std::make_shared<GigabyteDeviceConnection>();
device_connection_->interface_path = device.interface_path; device_connection_->interface_path = device.interface_path;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::ensure_vendor_channel_open() const gigabyte_status_t GigabyteCaptureSession::ensure_vendor_channel_open() const
{ {
if (channel_open_) if (channel_open_)
return PCIES2MM_OK; return GIGABYTE_OK;
if (!device_connection_ || device_connection_->interface_path.empty()) if (!device_connection_ || device_connection_->interface_path.empty())
return reject(PCIES2MM_ESTATE, "GigabyteLib channel open rejected: no device is selected"); return reject(GIGABYTE_ESTATE, "GigabyteLib channel open rejected: no device is selected");
device_handle_ = CreateFileW(device_connection_->interface_path.c_str(), device_handle_ = CreateFileW(device_connection_->interface_path.c_str(),
GENERIC_READ | GENERIC_WRITE, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (device_handle_ == INVALID_HANDLE_VALUE) if (device_handle_ == INVALID_HANDLE_VALUE)
return reject(PCIES2MM_ENODEV, "CreateFile for GigabyteLib failed"); return reject(GIGABYTE_ENODEV, "CreateFile for GigabyteLib failed");
const ULONG memoryMode = zero_copy_enabled_ const ULONG memoryMode = zero_copy_enabled_
? GVFG_VIDEO_FRAME_ZERO_COPY | GVFG_AUDIO_FRAME_BUF_COPY ? GVFG_VIDEO_FRAME_ZERO_COPY | GVFG_AUDIO_FRAME_BUF_COPY
: GVFG_VIDEO_FRAME_BUF_COPY | GVFG_AUDIO_FRAME_BUF_COPY; : GVFG_VIDEO_FRAME_BUF_COPY | GVFG_AUDIO_FRAME_BUF_COPY;
pcies2mm_status_t status = from_vendor( gigabyte_status_t status = from_vendor(
GvfgOpenDev(device_handle_, &context_, memoryMode), "GvfgOpenDev"); GvfgOpenDev(device_handle_, &context_, memoryMode), "GvfgOpenDev");
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
{ {
CloseHandle(device_handle_); CloseHandle(device_handle_);
device_handle_ = INVALID_HANDLE_VALUE; device_handle_ = INVALID_HANDLE_VALUE;
@@ -101,7 +101,7 @@ pcies2mm_status_t PcieS2mmCaptureSession::ensure_vendor_channel_open() const
status = from_vendor(GvfgCreateEvents(&events_, audio_enabled_ ? FALSE : TRUE), status = from_vendor(GvfgCreateEvents(&events_, audio_enabled_ ? FALSE : TRUE),
"GvfgCreateEvents"); "GvfgCreateEvents");
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
{ {
GvfgCloseDev(&context_); GvfgCloseDev(&context_);
CloseHandle(device_handle_); CloseHandle(device_handle_);
@@ -114,12 +114,12 @@ pcies2mm_status_t PcieS2mmCaptureSession::ensure_vendor_channel_open() const
if (!stop_event_) if (!stop_event_)
{ {
close_vendor_channel(); close_vendor_channel();
return reject(PCIES2MM_EIO, "CreateEvent for GigabyteLib cancellation failed"); return reject(GIGABYTE_EIO, "CreateEvent for GigabyteLib cancellation failed");
} }
status = from_vendor(GvfgOpenVideoChn(context_, channel_, &events_), status = from_vendor(GvfgOpenVideoChn(context_, channel_, &events_),
"GvfgOpenVideoChn"); "GvfgOpenVideoChn");
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
{ {
close_vendor_channel(); close_vendor_channel();
return status; return status;
@@ -128,7 +128,7 @@ pcies2mm_status_t PcieS2mmCaptureSession::ensure_vendor_channel_open() const
return refresh_video_info(); return refresh_video_info();
} }
void PcieS2mmCaptureSession::close_vendor_channel() const void GigabyteCaptureSession::close_vendor_channel() const
{ {
if (channel_open_ && context_) if (channel_open_ && context_)
GvfgCloseVideoChn(context_, channel_); GvfgCloseVideoChn(context_, channel_);
@@ -147,76 +147,53 @@ void PcieS2mmCaptureSession::close_vendor_channel() const
device_handle_ = INVALID_HANDLE_VALUE; device_handle_ = INVALID_HANDLE_VALUE;
} }
pcies2mm_status_t PcieS2mmCaptureSession::close() gigabyte_status_t GigabyteCaptureSession::close()
{ {
stop_stream(); stop_stream();
close_vendor_channel(); close_vendor_channel();
device_connection_.reset(); device_connection_.reset();
configured_ = false; configured_ = false;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::set_channel(uint32_t channel) gigabyte_status_t GigabyteCaptureSession::set_channel(uint32_t channel)
{ {
if (channel > 1) if (channel > 1)
return reject(PCIES2MM_EINVAL, "GigabyteLib channel index is invalid"); return reject(GIGABYTE_EINVAL, "GigabyteLib channel index is invalid");
if (channel_open_) if (channel_open_)
return reject(PCIES2MM_ESTATE, "GigabyteLib channel is already open"); return reject(GIGABYTE_ESTATE, "GigabyteLib channel is already open");
channel_ = channel; channel_ = channel;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::set_zero_copy_enabled(bool enabled) gigabyte_status_t GigabyteCaptureSession::set_zero_copy_enabled(bool enabled)
{ {
if (channel_open_ || running_) if (channel_open_ || running_)
return reject(PCIES2MM_ESTATE, "GigabyteLib frame memory mode is already fixed"); return reject(GIGABYTE_ESTATE, "GigabyteLib frame memory mode is already fixed");
zero_copy_enabled_ = enabled; zero_copy_enabled_ = enabled;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::set_audio_enabled(bool enabled) gigabyte_status_t GigabyteCaptureSession::set_audio_enabled(bool enabled)
{ {
if (running_) if (running_)
return reject(PCIES2MM_ESTATE, "GigabyteLib audio mode cannot change while running"); return reject(GIGABYTE_ESTATE, "GigabyteLib audio mode cannot change while running");
if (channel_open_ && audio_enabled_ != enabled) if (channel_open_ && audio_enabled_ != enabled)
close_vendor_channel(); close_vendor_channel();
audio_enabled_ = enabled; audio_enabled_ = enabled;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::set_video_format(pcies2mm_pixel_format_t format) gigabyte_status_t GigabyteCaptureSession::refresh_video_info() const
{
if (format != PCIES2MM_PIXFMT_YUY2 && format != PCIES2MM_PIXFMT_Y210)
return reject(PCIES2MM_EINVAL, "GigabyteLib pixel format is invalid");
if (running_)
return reject(PCIES2MM_ESTATE, "GigabyteLib pixel format cannot change while running");
const pcies2mm_status_t openStatus = ensure_vendor_channel_open();
if (openStatus != PCIES2MM_OK)
return openStatus;
const pcies2mm_status_t infoStatus = refresh_video_info();
if (infoStatus != PCIES2MM_OK)
return infoStatus;
{
std::lock_guard<std::mutex> lock(state_mutex_);
if (cached_signal_.connected && cached_signal_.pixel_format != PCIES2MM_PIXFMT_UNKNOWN &&
cached_signal_.pixel_format != format)
return reject(PCIES2MM_ENOTSUP,
"GigabyteLib does not expose output-format conversion; requested format differs from input");
}
stream_desc_.pixel_format = format;
return PCIES2MM_OK;
}
pcies2mm_status_t PcieS2mmCaptureSession::refresh_video_info() const
{ {
if (!context_) if (!context_)
return reject(PCIES2MM_ESTATE, "GigabyteLib video info requested before open"); return reject(GIGABYTE_ESTATE, "GigabyteLib video info requested before open");
GVFG_VIDEO_INFO info{}; GVFG_VIDEO_INFO info{};
const pcies2mm_status_t status = from_vendor( const gigabyte_status_t status = from_vendor(
GvfgGetVideoInfo(context_, channel_, &info), "GvfgGetVideoInfo"); GvfgGetVideoInfo(context_, channel_, &info), "GvfgGetVideoInfo");
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
return status; return status;
pcies2mm_signal_status_t signal{}; gigabyte_signal_status_t signal{};
signal.connected = info.VideoSignalLock ? 1 : 0; signal.connected = info.VideoSignalLock ? 1 : 0;
signal.channel = channel_; signal.channel = channel_;
signal.width = info.Width; signal.width = info.Width;
@@ -227,16 +204,16 @@ pcies2mm_status_t PcieS2mmCaptureSession::refresh_video_info() const
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
cached_signal_ = signal; cached_signal_ = signal;
} }
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::get_signal_status(pcies2mm_signal_status_t &out) const gigabyte_status_t GigabyteCaptureSession::get_signal_status(gigabyte_signal_status_t &out) const
{ {
const pcies2mm_status_t openStatus = ensure_vendor_channel_open(); const gigabyte_status_t openStatus = ensure_vendor_channel_open();
if (openStatus != PCIES2MM_OK) if (openStatus != GIGABYTE_OK)
return openStatus; return openStatus;
const pcies2mm_status_t status = refresh_video_info(); const gigabyte_status_t status = refresh_video_info();
if (status == PCIES2MM_OK) if (status == GIGABYTE_OK)
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
out = cached_signal_; out = cached_signal_;
@@ -244,14 +221,14 @@ pcies2mm_status_t PcieS2mmCaptureSession::get_signal_status(pcies2mm_signal_stat
return status; return status;
} }
pcies2mm_status_t PcieS2mmCaptureSession::get_audio_format(pcies2mm_audio_format_t &out) const gigabyte_status_t GigabyteCaptureSession::get_audio_format(gigabyte_audio_format_t &out) const
{ {
const pcies2mm_status_t openStatus = ensure_vendor_channel_open(); const gigabyte_status_t openStatus = ensure_vendor_channel_open();
if (openStatus != PCIES2MM_OK) if (openStatus != GIGABYTE_OK)
return openStatus; return openStatus;
const pcies2mm_status_t status = from_vendor( const gigabyte_status_t status = from_vendor(
GvfgGetAudioInfo(context_, channel_, &audio_info_), "GvfgGetAudioInfo"); GvfgGetAudioInfo(context_, channel_, &audio_info_), "GvfgGetAudioInfo");
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
return status; return status;
out = {}; out = {};
out.sample_rate = audio_info_.SamplesPerSec; out.sample_rate = audio_info_.SamplesPerSec;
@@ -261,52 +238,40 @@ pcies2mm_status_t PcieS2mmCaptureSession::get_audio_format(pcies2mm_audio_format
out.frame_bytes = audio_info_.cbBufSize; out.frame_bytes = audio_info_.cbBufSize;
out.block_align = static_cast<uint32_t>(audio_info_.Channels) * out.block_align = static_cast<uint32_t>(audio_info_.Channels) *
static_cast<uint32_t>(audio_info_.BitsPerSample) / 8u; static_cast<uint32_t>(audio_info_.BitsPerSample) / 8u;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::set_event_callback( gigabyte_status_t GigabyteCaptureSession::set_event_callback(
pcies2mm_event_callback_t callback, void *user, uint32_t eventMask) gigabyte_event_callback_t callback, void *user, uint32_t eventMask)
{ {
std::lock_guard<std::mutex> lock(callback_mutex_); std::lock_guard<std::mutex> lock(callback_mutex_);
event_callback_ = callback; event_callback_ = callback;
event_callback_user_ = user; event_callback_user_ = user;
event_mask_filter_ = eventMask; event_mask_filter_ = eventMask;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::configure_stream(const pcies2mm_stream_desc_t &desc) gigabyte_status_t GigabyteCaptureSession::configure_stream()
{ {
if (running_) if (running_)
return reject(PCIES2MM_ESTATE, "GigabyteLib stream is already running"); return reject(GIGABYTE_ESTATE, "GigabyteLib stream is already running");
const pcies2mm_status_t openStatus = ensure_vendor_channel_open(); const gigabyte_status_t openStatus = ensure_vendor_channel_open();
if (openStatus != PCIES2MM_OK) if (openStatus != GIGABYTE_OK)
return openStatus; return openStatus;
stream_desc_ = desc;
{
std::lock_guard<std::mutex> lock(state_mutex_);
if (cached_signal_.connected)
{
stream_desc_.width = cached_signal_.width;
stream_desc_.height = cached_signal_.height;
stream_desc_.pixel_format = cached_signal_.pixel_format;
}
}
if (!zero_copy_enabled_)
copy_buffer_.assign(frame_size_bytes(), 0);
configured_ = true; configured_ = true;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::start_stream() gigabyte_status_t GigabyteCaptureSession::start_stream()
{ {
if (running_) if (running_)
return PCIES2MM_OK; return GIGABYTE_OK;
if (!configured_) if (!configured_)
return reject(PCIES2MM_ESTATE, "GigabyteLib stream has not been configured"); return reject(GIGABYTE_ESTATE, "GigabyteLib stream has not been configured");
ResetEvent(stop_event_); ResetEvent(stop_event_);
const pcies2mm_status_t status = from_vendor( const gigabyte_status_t status = from_vendor(
GvfgStartCapture(context_, channel_), "GvfgStartCapture"); GvfgStartCapture(context_, channel_), "GvfgStartCapture");
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
return status; return status;
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
@@ -316,17 +281,17 @@ pcies2mm_status_t PcieS2mmCaptureSession::start_stream()
} }
running_ = true; running_ = true;
start_event_monitoring(); start_event_monitoring();
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::stop_stream() gigabyte_status_t GigabyteCaptureSession::stop_stream()
{ {
const bool wasRunning = running_.exchange(false); const bool wasRunning = running_.exchange(false);
if (stop_event_) if (stop_event_)
SetEvent(stop_event_); SetEvent(stop_event_);
stop_event_monitoring(); stop_event_monitoring();
pcies2mm_status_t result = PCIES2MM_OK; gigabyte_status_t result = GIGABYTE_OK;
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
if (frame_held_ && zero_copy_enabled_ && context_) if (frame_held_ && zero_copy_enabled_ && context_)
@@ -337,61 +302,61 @@ pcies2mm_status_t PcieS2mmCaptureSession::stop_stream()
} }
if (wasRunning && channel_open_ && context_) if (wasRunning && channel_open_ && context_)
{ {
const pcies2mm_status_t stopStatus = from_vendor( const gigabyte_status_t stopStatus = from_vendor(
GvfgStopCapture(context_, channel_), "GvfgStopCapture"); GvfgStopCapture(context_, channel_), "GvfgStopCapture");
if (result == PCIES2MM_OK) if (result == GIGABYTE_OK)
result = stopStatus; result = stopStatus;
} }
return result; return result;
} }
pcies2mm_status_t PcieS2mmCaptureSession::wait_frame(uint32_t timeoutMs, pcies2mm_frame_t &out) gigabyte_status_t GigabyteCaptureSession::wait_frame(uint32_t timeoutMs, gigabyte_frame_t &out)
{ {
out = {}; out = {};
if (!running_ || !context_) if (!running_ || !context_)
return reject(PCIES2MM_ESTATE, "GigabyteLib frame read rejected: stream is not running"); return reject(GIGABYTE_ESTATE, "GigabyteLib frame read rejected: stream is not running");
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
if (frame_held_) if (frame_held_)
return reject(PCIES2MM_ESTATE, "GigabyteLib frame read rejected: previous frame is held"); return reject(GIGABYTE_ESTATE, "GigabyteLib frame read rejected: previous frame is held");
} }
std::array<HANDLE, 3> handles{stop_event_, events_.hVideoFrameInEvent, events_.hVideoExtraFrame}; std::array<HANDLE, 3> handles{stop_event_, events_.hVideoFrameInEvent, events_.hVideoExtraFrame};
const DWORD count = handles[2] ? 3u : 2u; const DWORD count = handles[2] ? 3u : 2u;
if (!handles[1]) if (!handles[1])
return reject(PCIES2MM_EIO, "GigabyteLib did not provide a video-frame event"); return reject(GIGABYTE_EIO, "GigabyteLib did not provide a video-frame event");
const DWORD waitMs = timeoutMs == UINT32_MAX ? INFINITE : timeoutMs; const DWORD waitMs = timeoutMs == UINT32_MAX ? INFINITE : timeoutMs;
const DWORD wait = WaitForMultipleObjects(count, handles.data(), FALSE, waitMs); const DWORD wait = WaitForMultipleObjects(count, handles.data(), FALSE, waitMs);
if (wait == WAIT_TIMEOUT) if (wait == WAIT_TIMEOUT)
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
++wait_timeout_count_; ++wait_timeout_count_;
return PCIES2MM_ETIMEOUT; return GIGABYTE_ETIMEOUT;
} }
if (wait == WAIT_OBJECT_0) if (wait == WAIT_OBJECT_0)
return PCIES2MM_ESTATE; return GIGABYTE_ESTATE;
if (wait != WAIT_OBJECT_0 + 1 && wait != WAIT_OBJECT_0 + 2) if (wait != WAIT_OBJECT_0 + 1 && wait != WAIT_OBJECT_0 + 2)
return reject(PCIES2MM_EIO, "GigabyteLib video event wait failed"); return reject(GIGABYTE_EIO, "GigabyteLib video event wait failed");
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
++video_event_wakes_; ++video_event_wakes_;
} }
const auto begin = std::chrono::steady_clock::now(); const auto begin = std::chrono::steady_clock::now();
const pcies2mm_status_t infoStatus = refresh_video_info(); const gigabyte_status_t infoStatus = refresh_video_info();
if (infoStatus != PCIES2MM_OK) if (infoStatus != GIGABYTE_OK)
return infoStatus; return infoStatus;
pcies2mm_signal_status_t signal{}; gigabyte_signal_status_t signal{};
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
signal = cached_signal_; signal = cached_signal_;
} }
if (!signal.connected || signal.width == 0 || signal.height == 0) if (!signal.connected || signal.width == 0 || signal.height == 0)
return PCIES2MM_ETIMEOUT; return GIGABYTE_ETIMEOUT;
const size_t bytes = frame_size_bytes(); const size_t bytes = frame_size_bytes();
const void *data = nullptr; const void *data = nullptr;
pcies2mm_status_t status = PCIES2MM_OK; gigabyte_status_t status = GIGABYTE_OK;
if (zero_copy_enabled_) if (zero_copy_enabled_)
{ {
void *buffer = nullptr; void *buffer = nullptr;
@@ -410,10 +375,10 @@ pcies2mm_status_t PcieS2mmCaptureSession::wait_frame(uint32_t timeoutMs, pcies2m
} }
const auto end = std::chrono::steady_clock::now(); const auto end = std::chrono::steady_clock::now();
record_get_frame_timing(std::chrono::duration<double, std::micro>(end - begin).count()); record_get_frame_timing(std::chrono::duration<double, std::micro>(end - begin).count());
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
return status; return status;
if (!data || bytes == 0) if (!data || bytes == 0)
return reject(PCIES2MM_EIO, "GigabyteLib returned an invalid video frame"); return reject(GIGABYTE_EIO, "GigabyteLib returned an invalid video frame");
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
out.data = data; out.data = data;
@@ -426,43 +391,43 @@ pcies2mm_status_t PcieS2mmCaptureSession::wait_frame(uint32_t timeoutMs, pcies2m
out.bit_depth = signal.bit_depth; out.bit_depth = signal.bit_depth;
held_frame_ = out; held_frame_ = out;
frame_held_ = true; frame_held_ = true;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::release_frame(const pcies2mm_frame_t &frame) gigabyte_status_t GigabyteCaptureSession::release_frame(const gigabyte_frame_t &frame)
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
if (!frame_held_) if (!frame_held_)
return reject(PCIES2MM_ESTATE, "GigabyteLib frame release rejected: no frame is held"); return reject(GIGABYTE_ESTATE, "GigabyteLib frame release rejected: no frame is held");
if (frame.data != held_frame_.data || frame.frame_id != held_frame_.frame_id || if (frame.data != held_frame_.data || frame.frame_id != held_frame_.frame_id ||
frame.data_size_bytes != held_frame_.data_size_bytes) frame.data_size_bytes != held_frame_.data_size_bytes)
return reject(PCIES2MM_EINVAL, "GigabyteLib frame release token does not match"); return reject(GIGABYTE_EINVAL, "GigabyteLib frame release token does not match");
if (zero_copy_enabled_) if (zero_copy_enabled_)
{ {
const pcies2mm_status_t status = from_vendor( const gigabyte_status_t status = from_vendor(
GvfgReleaseVideoFrameZeroCopy(context_, channel_), "GvfgReleaseVideoFrameZeroCopy"); GvfgReleaseVideoFrameZeroCopy(context_, channel_), "GvfgReleaseVideoFrameZeroCopy");
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
return status; return status;
} }
held_frame_ = {}; held_frame_ = {};
frame_held_ = false; frame_held_ = false;
return PCIES2MM_OK; return GIGABYTE_OK;
} }
pcies2mm_status_t PcieS2mmCaptureSession::wait_audio( gigabyte_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)
{ {
outBytes = 0; outBytes = 0;
if (!running_ || !audio_enabled_ || !destination) if (!running_ || !audio_enabled_ || !destination)
return reject(PCIES2MM_ESTATE, "GigabyteLib audio read rejected"); return reject(GIGABYTE_ESTATE, "GigabyteLib audio read rejected");
pcies2mm_audio_format_t format{}; gigabyte_audio_format_t format{};
const pcies2mm_status_t formatStatus = get_audio_format(format); const gigabyte_status_t formatStatus = get_audio_format(format);
if (formatStatus != PCIES2MM_OK) if (formatStatus != GIGABYTE_OK)
return formatStatus; return formatStatus;
if (format.frame_bytes == 0 || format.frame_bytes > destinationCapacity) if (format.frame_bytes == 0 || format.frame_bytes > destinationCapacity)
return reject(PCIES2MM_EINVAL, "GigabyteLib audio destination is too small"); return reject(GIGABYTE_EINVAL, "GigabyteLib audio destination is too small");
if (!events_.hAudioFrameInEvent) if (!events_.hAudioFrameInEvent)
return reject(PCIES2MM_EIO, "GigabyteLib did not provide an audio-frame event"); return reject(GIGABYTE_EIO, "GigabyteLib did not provide an audio-frame event");
std::array<HANDLE, 3> handles{stop_event_, events_.hAudioFrameInEvent, events_.hAudioExtraFrame}; std::array<HANDLE, 3> handles{stop_event_, events_.hAudioFrameInEvent, events_.hAudioExtraFrame};
const DWORD count = handles[2] ? 3u : 2u; const DWORD count = handles[2] ? 3u : 2u;
@@ -472,12 +437,12 @@ pcies2mm_status_t PcieS2mmCaptureSession::wait_audio(
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
++wait_timeout_count_; ++wait_timeout_count_;
return PCIES2MM_ETIMEOUT; return GIGABYTE_ETIMEOUT;
} }
if (wait == WAIT_OBJECT_0) if (wait == WAIT_OBJECT_0)
return PCIES2MM_ESTATE; return GIGABYTE_ESTATE;
if (wait != WAIT_OBJECT_0 + 1 && wait != WAIT_OBJECT_0 + 2) if (wait != WAIT_OBJECT_0 + 1 && wait != WAIT_OBJECT_0 + 2)
return reject(PCIES2MM_EIO, "GigabyteLib audio event wait failed"); return reject(GIGABYTE_EIO, "GigabyteLib audio event wait failed");
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
if (wait == WAIT_OBJECT_0 + 1) if (wait == WAIT_OBJECT_0 + 1)
@@ -485,9 +450,9 @@ pcies2mm_status_t PcieS2mmCaptureSession::wait_audio(
else else
++extra_audio_event_wakes_; ++extra_audio_event_wakes_;
} }
const pcies2mm_status_t status = from_vendor( const gigabyte_status_t status = from_vendor(
GvfgGetAudioFrame(context_, channel_, destination, format.frame_bytes), "GvfgGetAudioFrame"); GvfgGetAudioFrame(context_, channel_, destination, format.frame_bytes), "GvfgGetAudioFrame");
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
return status; return status;
outBytes = format.frame_bytes; outBytes = format.frame_bytes;
{ {
@@ -495,18 +460,18 @@ pcies2mm_status_t PcieS2mmCaptureSession::wait_audio(
++audio_frames_from_driver_; ++audio_frames_from_driver_;
audio_bytes_from_driver_ += outBytes; audio_bytes_from_driver_ += outBytes;
} }
return PCIES2MM_OK; return GIGABYTE_OK;
} }
void PcieS2mmCaptureSession::start_event_monitoring() void GigabyteCaptureSession::start_event_monitoring()
{ {
if (monitoring_) if (monitoring_)
return; return;
monitoring_ = true; monitoring_ = true;
event_thread_ = std::thread(&PcieS2mmCaptureSession::event_thread_proc, this); event_thread_ = std::thread(&GigabyteCaptureSession::event_thread_proc, this);
} }
void PcieS2mmCaptureSession::stop_event_monitoring() void GigabyteCaptureSession::stop_event_monitoring()
{ {
monitoring_ = false; monitoring_ = false;
if (stop_event_) if (stop_event_)
@@ -515,7 +480,7 @@ void PcieS2mmCaptureSession::stop_event_monitoring()
event_thread_.join(); event_thread_.join();
} }
void PcieS2mmCaptureSession::event_thread_proc() void GigabyteCaptureSession::event_thread_proc()
{ {
const std::array<HANDLE, 4> handles{stop_event_, events_.hVideoFormatChangedEvent, const std::array<HANDLE, 4> handles{stop_event_, events_.hVideoFormatChangedEvent,
events_.hVideoInputPluginEvent, events_.hVideoInputUnplugEvent}; events_.hVideoInputPluginEvent, events_.hVideoInputUnplugEvent};
@@ -543,15 +508,15 @@ void PcieS2mmCaptureSession::event_thread_proc()
return; return;
if (kind == 1) if (kind == 1)
{ {
emit_event(PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN); emit_event(GIGABYTE_EVENT_FORMAT_CHANGE_BEGIN);
refresh_video_info(); refresh_video_info();
emit_event(PCIES2MM_EVENT_STREAM_READY); emit_event(GIGABYTE_EVENT_STREAM_READY);
} }
else if (kind == 2) else if (kind == 2)
{ {
refresh_video_info(); refresh_video_info();
emit_event(PCIES2MM_EVENT_PLUG_IN); emit_event(GIGABYTE_EVENT_PLUG_IN);
emit_event(PCIES2MM_EVENT_STREAM_READY); emit_event(GIGABYTE_EVENT_STREAM_READY);
} }
else if (kind == 3) else if (kind == 3)
{ {
@@ -560,31 +525,31 @@ void PcieS2mmCaptureSession::event_thread_proc()
cached_signal_ = {}; cached_signal_ = {};
cached_signal_.channel = channel_; cached_signal_.channel = channel_;
} }
emit_event(PCIES2MM_EVENT_PLUG_OUT); emit_event(GIGABYTE_EVENT_PLUG_OUT);
} }
} }
} }
void PcieS2mmCaptureSession::emit_event(pcies2mm_event_type_t type) const void GigabyteCaptureSession::emit_event(gigabyte_event_type_t type) const
{ {
std::lock_guard<std::mutex> lock(callback_mutex_); std::lock_guard<std::mutex> lock(callback_mutex_);
uint32_t bit = 0; uint32_t bit = 0;
if (type == PCIES2MM_EVENT_PLUG_IN) bit = PCIES2MM_EVENT_MASK_PLUG_IN; if (type == GIGABYTE_EVENT_PLUG_IN) bit = GIGABYTE_EVENT_MASK_PLUG_IN;
if (type == PCIES2MM_EVENT_PLUG_OUT) bit = PCIES2MM_EVENT_MASK_PLUG_OUT; if (type == GIGABYTE_EVENT_PLUG_OUT) bit = GIGABYTE_EVENT_MASK_PLUG_OUT;
if (type == PCIES2MM_EVENT_STREAM_READY) bit = PCIES2MM_EVENT_MASK_STREAM_READY; if (type == GIGABYTE_EVENT_STREAM_READY) bit = GIGABYTE_EVENT_MASK_STREAM_READY;
if (type == PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN) bit = PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN; if (type == GIGABYTE_EVENT_FORMAT_CHANGE_BEGIN) bit = GIGABYTE_EVENT_MASK_FORMAT_CHANGE_BEGIN;
if (event_callback_ && (event_mask_filter_ & bit) != 0) if (event_callback_ && (event_mask_filter_ & bit) != 0)
event_callback_(type, event_callback_user_); event_callback_(type, event_callback_user_);
} }
void PcieS2mmCaptureSession::get_debug_stats( void GigabyteCaptureSession::get_debug_stats(
pcies2mm_stream_stats_t &outStats, uint64_t &outWaitTimeouts, gigabyte_stream_stats_t &outStats, uint64_t &outWaitTimeouts,
pcies2mm_debug_state_t &outDebugState) const gigabyte_debug_state_t &outDebugState) const
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
outStats = {}; outStats = {};
outStats.state = running_ ? PCIES2MM_STREAM_RUNNING : outStats.state = running_ ? GIGABYTE_STREAM_RUNNING :
configured_ ? PCIES2MM_STREAM_CONFIGURED : PCIES2MM_STREAM_STOPPED; configured_ ? GIGABYTE_STREAM_CONFIGURED : GIGABYTE_STREAM_STOPPED;
outStats.frames_captured = video_event_wakes_; outStats.frames_captured = video_event_wakes_;
outStats.frames_delivered = frame_id_; outStats.frames_delivered = frame_id_;
outStats.interrupt_count = video_event_wakes_; outStats.interrupt_count = video_event_wakes_;
@@ -606,27 +571,17 @@ void PcieS2mmCaptureSession::get_debug_stats(
outDebugState.get_frame_timing_max_us = get_frame_timing_lifetime_max_us_; outDebugState.get_frame_timing_max_us = get_frame_timing_lifetime_max_us_;
} }
pcies2mm_status_t PcieS2mmCaptureSession::debug_read_register(uint32_t, uint32_t &) const gigabyte_status_t GigabyteCaptureSession::from_vendor(GVFG_HRESULT result, const char *operation) const
{
return reject(PCIES2MM_ENOTSUP, "GigabyteLib does not expose direct register reads");
}
pcies2mm_status_t PcieS2mmCaptureSession::debug_write_register(uint32_t, uint32_t) const
{
return reject(PCIES2MM_ENOTSUP, "GigabyteLib does not expose direct register writes");
}
pcies2mm_status_t PcieS2mmCaptureSession::from_vendor(GVFG_HRESULT result, const char *operation) const
{ {
if (result == GVFG_HRESULT_OK) if (result == GVFG_HRESULT_OK)
return PCIES2MM_OK; return GIGABYTE_OK;
pcies2mm_status_t status = PCIES2MM_EIO; gigabyte_status_t status = GIGABYTE_EIO;
if (result == GVFG_HRESULT_DEV_BUSY || result == GVFG_HRESULT_CONTEXT_ERROR) if (result == GVFG_HRESULT_DEV_BUSY || result == GVFG_HRESULT_CONTEXT_ERROR)
status = PCIES2MM_ESTATE; status = GIGABYTE_ESTATE;
else if (result == GVFG_HRESULT_VIDEO_CHN_INVALID) else if (result == GVFG_HRESULT_VIDEO_CHN_INVALID)
status = PCIES2MM_EINVAL; status = GIGABYTE_EINVAL;
else if (result == GVFG_HRESULT_DEV_ERROR) else if (result == GVFG_HRESULT_DEV_ERROR)
status = PCIES2MM_ENODEV; status = GIGABYTE_ENODEV;
std::ostringstream stream; std::ostringstream stream;
stream << (operation ? operation : "GigabyteLib") stream << (operation ? operation : "GigabyteLib")
<< " failed with GVFG_HRESULT 0x" << std::hex << std::uppercase << " failed with GVFG_HRESULT 0x" << std::hex << std::uppercase
@@ -635,24 +590,23 @@ pcies2mm_status_t PcieS2mmCaptureSession::from_vendor(GVFG_HRESULT result, const
return status; return status;
} }
pcies2mm_status_t PcieS2mmCaptureSession::reject(pcies2mm_status_t status, const char *message) const gigabyte_status_t GigabyteCaptureSession::reject(gigabyte_status_t status, const char *message) const
{ {
error_state_.set(message ? message : "GigabyteLib operation rejected"); error_state_.set(message ? message : "GigabyteLib operation rejected");
return status; return status;
} }
size_t PcieS2mmCaptureSession::frame_size_bytes() const size_t GigabyteCaptureSession::frame_size_bytes() const
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
const uint32_t width = cached_signal_.width ? cached_signal_.width : stream_desc_.width; const uint32_t width = cached_signal_.width;
const uint32_t height = cached_signal_.height ? cached_signal_.height : stream_desc_.height; const uint32_t height = cached_signal_.height;
const pcies2mm_pixel_format_t format = cached_signal_.pixel_format != PCIES2MM_PIXFMT_UNKNOWN const gigabyte_pixel_format_t format = cached_signal_.pixel_format;
? cached_signal_.pixel_format : stream_desc_.pixel_format; const size_t bytesPerPixel = format == GIGABYTE_PIXFMT_Y210 ? 4u : 2u;
const size_t bytesPerPixel = format == PCIES2MM_PIXFMT_Y210 ? 4u : 2u;
return static_cast<size_t>(width) * height * bytesPerPixel; return static_cast<size_t>(width) * height * bytesPerPixel;
} }
void PcieS2mmCaptureSession::record_get_frame_timing(double elapsedUs) void GigabyteCaptureSession::record_get_frame_timing(double elapsedUs)
{ {
std::lock_guard<std::mutex> lock(state_mutex_); std::lock_guard<std::mutex> lock(state_mutex_);
++get_frame_timing_samples_; ++get_frame_timing_samples_;
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "gigabyte_backend_types.h" #include "gigabyte_types.h"
#include "gigabyte_device.h" #include "gigabyte_device.h"
#include "gvfg_error_state.h" #include "gvfg_error_state.h"
#include "gvfgsdkapi.h" #include "gvfgsdkapi.h"
@@ -18,67 +18,63 @@
namespace gvfg::internal namespace gvfg::internal
{ {
struct PcieS2mmDeviceConnection struct GigabyteDeviceConnection
{ {
std::wstring interface_path; std::wstring interface_path;
}; };
class PcieS2mmCaptureSession class GigabyteCaptureSession
{ {
public: public:
explicit PcieS2mmCaptureSession(ChannelErrorState &errorState); explicit GigabyteCaptureSession(ChannelErrorState &errorState);
PcieS2mmCaptureSession(const PcieS2mmCaptureSession &) = delete; GigabyteCaptureSession(const GigabyteCaptureSession &) = delete;
PcieS2mmCaptureSession &operator=(const PcieS2mmCaptureSession &) = delete; GigabyteCaptureSession &operator=(const GigabyteCaptureSession &) = delete;
~PcieS2mmCaptureSession(); ~GigabyteCaptureSession();
pcies2mm_status_t open_device_index(size_t deviceIndex); gigabyte_status_t open_device_index(size_t deviceIndex);
pcies2mm_status_t open_device_connection(const std::shared_ptr<PcieS2mmDeviceConnection> &connection); gigabyte_status_t open_device_connection(const std::shared_ptr<GigabyteDeviceConnection> &connection);
std::shared_ptr<PcieS2mmDeviceConnection> device_connection() const { return device_connection_; } std::shared_ptr<GigabyteDeviceConnection> device_connection() const { return device_connection_; }
pcies2mm_status_t close(); gigabyte_status_t close();
pcies2mm_status_t set_channel(uint32_t channel); gigabyte_status_t set_channel(uint32_t channel);
pcies2mm_status_t set_zero_copy_enabled(bool enabled); gigabyte_status_t set_zero_copy_enabled(bool enabled);
bool zero_copy_enabled() const { return zero_copy_enabled_; } bool zero_copy_enabled() const { return zero_copy_enabled_; }
pcies2mm_status_t set_audio_enabled(bool enabled); gigabyte_status_t set_audio_enabled(bool enabled);
pcies2mm_status_t set_video_format(pcies2mm_pixel_format_t format); gigabyte_status_t get_signal_status(gigabyte_signal_status_t &out) const;
pcies2mm_status_t get_signal_status(pcies2mm_signal_status_t &out) const; gigabyte_status_t get_audio_format(gigabyte_audio_format_t &out) const;
pcies2mm_status_t get_audio_format(pcies2mm_audio_format_t &out) const; gigabyte_status_t set_event_callback(gigabyte_event_callback_t callback, void *user, uint32_t eventMask);
pcies2mm_status_t set_event_callback(pcies2mm_event_callback_t callback, void *user, uint32_t eventMask); gigabyte_status_t configure_stream();
pcies2mm_status_t configure_stream(const pcies2mm_stream_desc_t &desc); gigabyte_status_t start_stream();
pcies2mm_status_t start_stream(); gigabyte_status_t stop_stream();
pcies2mm_status_t stop_stream(); gigabyte_status_t wait_frame(uint32_t timeoutMs, gigabyte_frame_t &out);
pcies2mm_status_t wait_frame(uint32_t timeoutMs, pcies2mm_frame_t &out); gigabyte_status_t wait_audio(uint32_t timeoutMs, void *destination,
pcies2mm_status_t wait_audio(uint32_t timeoutMs, void *destination,
uint32_t destinationCapacity, uint32_t &outBytes); uint32_t destinationCapacity, uint32_t &outBytes);
pcies2mm_status_t release_frame(const pcies2mm_frame_t &frame); gigabyte_status_t release_frame(const gigabyte_frame_t &frame);
void get_debug_stats(pcies2mm_stream_stats_t &outStats, uint64_t &outWaitTimeouts, void get_debug_stats(gigabyte_stream_stats_t &outStats, uint64_t &outWaitTimeouts,
pcies2mm_debug_state_t &outDebugState) const; gigabyte_debug_state_t &outDebugState) const;
pcies2mm_status_t debug_read_register(uint32_t offset, uint32_t &outValue) const;
pcies2mm_status_t debug_write_register(uint32_t offset, uint32_t value) const;
private: private:
pcies2mm_status_t open_device(const GigabyteDevice &device); gigabyte_status_t open_device(const GigabyteDevice &device);
pcies2mm_status_t ensure_vendor_channel_open() const; gigabyte_status_t ensure_vendor_channel_open() const;
void close_vendor_channel() const; void close_vendor_channel() const;
void start_event_monitoring(); void start_event_monitoring();
void stop_event_monitoring(); void stop_event_monitoring();
void event_thread_proc(); void event_thread_proc();
void emit_event(pcies2mm_event_type_t type) const; void emit_event(gigabyte_event_type_t type) const;
pcies2mm_status_t refresh_video_info() const; gigabyte_status_t refresh_video_info() const;
pcies2mm_status_t from_vendor(GVFG_HRESULT result, const char *operation) const; gigabyte_status_t from_vendor(GVFG_HRESULT result, const char *operation) const;
pcies2mm_status_t reject(pcies2mm_status_t status, const char *message) const; gigabyte_status_t reject(gigabyte_status_t status, const char *message) const;
void record_get_frame_timing(double elapsedUs); void record_get_frame_timing(double elapsedUs);
size_t frame_size_bytes() const; size_t frame_size_bytes() const;
ChannelErrorState &error_state_; ChannelErrorState &error_state_;
std::shared_ptr<PcieS2mmDeviceConnection> device_connection_; std::shared_ptr<GigabyteDeviceConnection> device_connection_;
mutable HANDLE device_handle_ = INVALID_HANDLE_VALUE; mutable HANDLE device_handle_ = INVALID_HANDLE_VALUE;
mutable PGVFG_CONTEXT context_ = nullptr; mutable PGVFG_CONTEXT context_ = nullptr;
mutable GVFG_VIDEO_CHN_EVENT events_{}; mutable GVFG_VIDEO_CHN_EVENT events_{};
mutable HANDLE stop_event_ = nullptr; mutable HANDLE stop_event_ = nullptr;
mutable bool events_created_ = false; mutable bool events_created_ = false;
mutable bool channel_open_ = false; mutable bool channel_open_ = false;
pcies2mm_stream_desc_t stream_desc_{}; mutable gigabyte_signal_status_t cached_signal_{};
mutable pcies2mm_signal_status_t cached_signal_{};
mutable GVFG_AUDIO_INFO audio_info_{}; mutable GVFG_AUDIO_INFO audio_info_{};
uint32_t channel_ = 0; uint32_t channel_ = 0;
bool configured_ = false; bool configured_ = false;
@@ -88,12 +84,12 @@ namespace gvfg::internal
std::atomic<bool> monitoring_{false}; std::atomic<bool> monitoring_{false};
std::thread event_thread_; std::thread event_thread_;
mutable std::mutex callback_mutex_; mutable std::mutex callback_mutex_;
pcies2mm_event_callback_t event_callback_ = nullptr; gigabyte_event_callback_t event_callback_ = nullptr;
void *event_callback_user_ = nullptr; void *event_callback_user_ = nullptr;
uint32_t event_mask_filter_ = PCIES2MM_EVENT_MASK_DEFAULT; uint32_t event_mask_filter_ = GIGABYTE_EVENT_MASK_DEFAULT;
mutable std::mutex state_mutex_; mutable std::mutex state_mutex_;
std::vector<uint8_t> copy_buffer_; std::vector<uint8_t> copy_buffer_;
pcies2mm_frame_t held_frame_{}; gigabyte_frame_t held_frame_{};
bool frame_held_ = false; bool frame_held_ = false;
uint64_t frame_id_ = 0; uint64_t frame_id_ = 0;
uint64_t audio_frames_from_driver_ = 0; uint64_t audio_frames_from_driver_ = 0;
@@ -10,7 +10,7 @@
namespace namespace
{ {
// Device interface exported by pcie_s2mm_driver. // Device interface exported by pcie_s2mm_driver.
const GUID kPcieS2mmDeviceInterfaceGuid = const GUID kGigabyteDeviceInterfaceGuid =
{0x8c47b9c3, 0x1faa, 0x4557, {0xbc, 0x1d, 0xf2, 0x25, 0xd2, 0x6c, 0x9e, 0x91}}; {0x8c47b9c3, 0x1faa, 0x4557, {0xbc, 0x1d, 0xf2, 0x25, 0xd2, 0x6c, 0x9e, 0x91}};
std::wstring device_property(HDEVINFO info, SP_DEVINFO_DATA &deviceInfo, DWORD property) std::wstring device_property(HDEVINFO info, SP_DEVINFO_DATA &deviceInfo, DWORD property)
@@ -34,14 +34,14 @@ namespace gvfg::internal
std::vector<GigabyteDevice> enumerate_gigabyte_devices() std::vector<GigabyteDevice> enumerate_gigabyte_devices()
{ {
std::vector<GigabyteDevice> devices; std::vector<GigabyteDevice> devices;
HDEVINFO info = SetupDiGetClassDevsW(&kPcieS2mmDeviceInterfaceGuid, nullptr, nullptr, HDEVINFO info = SetupDiGetClassDevsW(&kGigabyteDeviceInterfaceGuid, nullptr, nullptr,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (info == INVALID_HANDLE_VALUE) if (info == INVALID_HANDLE_VALUE)
return devices; return devices;
SP_DEVICE_INTERFACE_DATA iface = {}; SP_DEVICE_INTERFACE_DATA iface = {};
iface.cbSize = sizeof(iface); iface.cbSize = sizeof(iface);
for (DWORD index = 0; SetupDiEnumDeviceInterfaces(info, nullptr, &kPcieS2mmDeviceInterfaceGuid, index, &iface); ++index) for (DWORD index = 0; SetupDiEnumDeviceInterfaces(info, nullptr, &kGigabyteDeviceInterfaceGuid, index, &iface); ++index)
{ {
DWORD required = 0; DWORD required = 0;
SetupDiGetDeviceInterfaceDetailW(info, &iface, nullptr, 0, &required, nullptr); SetupDiGetDeviceInterfaceDetailW(info, &iface, nullptr, 0, &required, nullptr);
@@ -0,0 +1,109 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
typedef enum gigabyte_status_t
{
GIGABYTE_OK = 0,
GIGABYTE_EINVAL,
GIGABYTE_ENODEV,
GIGABYTE_ESTATE,
GIGABYTE_ENOTSUP,
GIGABYTE_ETIMEOUT,
GIGABYTE_EIO
} gigabyte_status_t;
typedef enum gigabyte_pixel_format_t
{
GIGABYTE_PIXFMT_UNKNOWN = 0,
GIGABYTE_PIXFMT_Y210 = 2,
GIGABYTE_PIXFMT_YUY2 = 3
} gigabyte_pixel_format_t;
typedef enum gigabyte_stream_state_t
{
GIGABYTE_STREAM_STOPPED = 0,
GIGABYTE_STREAM_CONFIGURED = 1,
GIGABYTE_STREAM_RUNNING = 2
} gigabyte_stream_state_t;
typedef struct gigabyte_signal_status_t
{
int connected;
uint32_t channel;
uint32_t width;
uint32_t height;
gigabyte_pixel_format_t pixel_format;
uint32_t bit_depth;
} gigabyte_signal_status_t;
typedef struct gigabyte_frame_t
{
const void *data; /* Valid until the next GigabyteCaptureSession::wait_frame() or close(). */
size_t data_size_bytes;
uint64_t frame_id;
uint64_t timestamp_ns;
uint32_t width;
uint32_t height;
gigabyte_pixel_format_t pixel_format;
uint32_t bit_depth;
} gigabyte_frame_t;
typedef struct gigabyte_audio_format_t
{
uint32_t sample_rate;
uint32_t channels;
uint32_t bits_per_sample;
uint32_t frames_per_second;
uint32_t frame_bytes;
uint32_t block_align;
} gigabyte_audio_format_t;
typedef struct gigabyte_stream_stats_t
{
gigabyte_stream_state_t state;
uint64_t frames_captured;
uint64_t frames_delivered;
uint64_t dma_errors;
uint64_t interrupt_count;
} gigabyte_stream_stats_t;
typedef struct gigabyte_debug_state_t
{
int running;
int capture_active;
uint64_t latest_sequence;
uint64_t delivered_sequence;
uint64_t audio_dma_event_wakes;
uint64_t extra_audio_event_wakes;
uint64_t audio_frames_from_driver;
uint64_t audio_bytes_from_driver;
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;
} gigabyte_debug_state_t;
typedef enum gigabyte_event_type_t
{
GIGABYTE_EVENT_PLUG_IN = 1,
GIGABYTE_EVENT_PLUG_OUT = 2,
GIGABYTE_EVENT_STREAM_READY = 3,
GIGABYTE_EVENT_FORMAT_CHANGE_BEGIN = 4
} gigabyte_event_type_t;
enum
{
GIGABYTE_EVENT_MASK_PLUG_IN = 1u << 0,
GIGABYTE_EVENT_MASK_PLUG_OUT = 1u << 1,
GIGABYTE_EVENT_MASK_STREAM_READY = 1u << 2,
GIGABYTE_EVENT_MASK_FORMAT_CHANGE_BEGIN = 1u << 3,
GIGABYTE_EVENT_MASK_DEFAULT = GIGABYTE_EVENT_MASK_PLUG_IN |
GIGABYTE_EVENT_MASK_PLUG_OUT |
GIGABYTE_EVENT_MASK_STREAM_READY |
GIGABYTE_EVENT_MASK_FORMAT_CHANGE_BEGIN
};
typedef void (*gigabyte_event_callback_t)(gigabyte_event_type_t event, void *user);
+138 -274
View File
@@ -27,10 +27,10 @@ using namespace gvfg::internal;
namespace namespace
{ {
static_assert(GVFG_EVENT_MASK_SIGNAL_CONNECTED == PCIES2MM_EVENT_MASK_PLUG_IN); static_assert(GVFG_EVENT_MASK_SIGNAL_CONNECTED == GIGABYTE_EVENT_MASK_PLUG_IN);
static_assert(GVFG_EVENT_MASK_SIGNAL_DISCONNECTED == PCIES2MM_EVENT_MASK_PLUG_OUT); static_assert(GVFG_EVENT_MASK_SIGNAL_DISCONNECTED == GIGABYTE_EVENT_MASK_PLUG_OUT);
static_assert(GVFG_EVENT_MASK_STREAM_READY == PCIES2MM_EVENT_MASK_STREAM_READY); static_assert(GVFG_EVENT_MASK_STREAM_READY == GIGABYTE_EVENT_MASK_STREAM_READY);
static_assert(GVFG_EVENT_MASK_FORMAT_CHANGE_BEGIN == PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN); static_assert(GVFG_EVENT_MASK_FORMAT_CHANGE_BEGIN == GIGABYTE_EVENT_MASK_FORMAT_CHANGE_BEGIN);
#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");
@@ -70,23 +70,23 @@ namespace
return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(now).count()); return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(now).count());
} }
gvfg_status_t map_status(pcies2mm_status_t st) gvfg_status_t map_status(gigabyte_status_t st)
{ {
switch (st) switch (st)
{ {
case PCIES2MM_OK: case GIGABYTE_OK:
return GVFG_OK; return GVFG_OK;
case PCIES2MM_EINVAL: case GIGABYTE_EINVAL:
return GVFG_EINVAL; return GVFG_EINVAL;
case PCIES2MM_ENODEV: case GIGABYTE_ENODEV:
return GVFG_ENODEV; return GVFG_ENODEV;
case PCIES2MM_ESTATE: case GIGABYTE_ESTATE:
return GVFG_ESTATE; return GVFG_ESTATE;
case PCIES2MM_ETIMEOUT: case GIGABYTE_ETIMEOUT:
return GVFG_ETIMEOUT; return GVFG_ETIMEOUT;
case PCIES2MM_ENOTSUP: case GIGABYTE_ENOTSUP:
return GVFG_ENOTSUP; return GVFG_ENOTSUP;
case PCIES2MM_EIO: case GIGABYTE_EIO:
default: default:
return GVFG_EIO; return GVFG_EIO;
} }
@@ -103,30 +103,30 @@ namespace
dst[dstSize - 1] = '\0'; dst[dstSize - 1] = '\0';
} }
gvfg_event_type_t map_event_type(pcies2mm_event_type_t type) gvfg_event_type_t map_event_type(gigabyte_event_type_t type)
{ {
switch (type) switch (type)
{ {
case PCIES2MM_EVENT_PLUG_IN: case GIGABYTE_EVENT_PLUG_IN:
return GVFG_EVENT_SIGNAL_CONNECTED; return GVFG_EVENT_SIGNAL_CONNECTED;
case PCIES2MM_EVENT_PLUG_OUT: case GIGABYTE_EVENT_PLUG_OUT:
return GVFG_EVENT_SIGNAL_DISCONNECTED; return GVFG_EVENT_SIGNAL_DISCONNECTED;
case PCIES2MM_EVENT_STREAM_READY: case GIGABYTE_EVENT_STREAM_READY:
return GVFG_EVENT_STREAM_READY; return GVFG_EVENT_STREAM_READY;
case PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN: case GIGABYTE_EVENT_FORMAT_CHANGE_BEGIN:
return GVFG_EVENT_FORMAT_CHANGE_BEGIN; return GVFG_EVENT_FORMAT_CHANGE_BEGIN;
default: default:
return GVFG_EVENT_UNKNOWN; return GVFG_EVENT_UNKNOWN;
} }
} }
int to_gvfg_pixel_format(pcies2mm_pixel_format_t fmt) int to_gvfg_pixel_format(gigabyte_pixel_format_t fmt)
{ {
switch (fmt) switch (fmt)
{ {
case PCIES2MM_PIXFMT_YUY2: case GIGABYTE_PIXFMT_YUY2:
return GVFG_PIXFMT_YUY2; return GVFG_PIXFMT_YUY2;
case PCIES2MM_PIXFMT_Y210: case GIGABYTE_PIXFMT_Y210:
return GVFG_PIXFMT_Y210; return GVFG_PIXFMT_Y210;
default: default:
return GVFG_PIXFMT_UNKNOWN; return GVFG_PIXFMT_UNKNOWN;
@@ -155,13 +155,13 @@ namespace
} }
gvfg_status_t native_row_stride_bytes(uint32_t width, gvfg_status_t native_row_stride_bytes(uint32_t width,
pcies2mm_pixel_format_t pixelFormat, gigabyte_pixel_format_t pixelFormat,
int &outStride) int &outStride)
{ {
uint64_t bytesPerPixel = 0; uint64_t bytesPerPixel = 0;
if (pixelFormat == PCIES2MM_PIXFMT_YUY2) if (pixelFormat == GIGABYTE_PIXFMT_YUY2)
bytesPerPixel = 2; bytesPerPixel = 2;
else if (pixelFormat == PCIES2MM_PIXFMT_Y210) else if (pixelFormat == GIGABYTE_PIXFMT_Y210)
bytesPerPixel = 4; bytesPerPixel = 4;
else else
return GVFG_ENOTSUP; return GVFG_ENOTSUP;
@@ -191,28 +191,28 @@ struct gvfg_channel_session_t
gvfg_status_t open(int index, gvfg_status_t open(int index,
int channelIndex = GVFG_CHANNEL_0, int channelIndex = GVFG_CHANNEL_0,
const std::shared_ptr<gvfg::internal::PcieS2mmDeviceConnection> &deviceConnection = nullptr) const std::shared_ptr<gvfg::internal::GigabyteDeviceConnection> &deviceConnection = nullptr)
{ {
if (index < 0 || (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1)) if (index < 0 || (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1))
return reject(GVFG_EINVAL, "gvfg_open_channel rejected: device or channel index is invalid"); return reject(GVFG_EINVAL, "gvfg_open_channel rejected: device or channel index is invalid");
close(); close();
backend = std::make_unique<gvfg::internal::PcieS2mmCaptureSession>(errorState); session = std::make_unique<gvfg::internal::GigabyteCaptureSession>(errorState);
const pcies2mm_status_t stOpen = deviceConnection const gigabyte_status_t stOpen = deviceConnection
? backend->open_device_connection(deviceConnection) ? session->open_device_connection(deviceConnection)
: backend->open_device_index(static_cast<size_t>(index)); : session->open_device_index(static_cast<size_t>(index));
if (stOpen != PCIES2MM_OK) if (stOpen != GIGABYTE_OK)
{ {
backend.reset(); session.reset();
return map_status(stOpen); return map_status(stOpen);
} }
currentIndex = index; currentIndex = index;
syncBackendEventCallback(); syncSessionEventCallback();
selectedChannel = static_cast<uint32_t>(channelIndex); selectedChannel = static_cast<uint32_t>(channelIndex);
resetRuntimeCounters(); resetRuntimeCounters();
const pcies2mm_status_t stChannel = backend->set_channel(selectedChannel); const gigabyte_status_t stChannel = session->set_channel(selectedChannel);
if (stChannel != PCIES2MM_OK) if (stChannel != GIGABYTE_OK)
{ {
close(); close();
return map_status(stChannel); return map_status(stChannel);
@@ -220,8 +220,8 @@ struct gvfg_channel_session_t
if (zeroCopyRequested) if (zeroCopyRequested)
{ {
const pcies2mm_status_t stZeroCopy = backend->set_zero_copy_enabled(true); const gigabyte_status_t stZeroCopy = session->set_zero_copy_enabled(true);
if (stZeroCopy != PCIES2MM_OK) if (stZeroCopy != GIGABYTE_OK)
{ {
close(); close();
return map_status(stZeroCopy); return map_status(stZeroCopy);
@@ -234,7 +234,7 @@ struct gvfg_channel_session_t
gvfg_status_t start() gvfg_status_t start()
{ {
if (!backend) if (!session)
return reject(GVFG_ESTATE, "gvfg_start_channel rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_start_channel rejected: channel is not open");
// A new start request starts a new diagnostic lifetime. Any failure // A new start request starts a new diagnostic lifetime. Any failure
@@ -259,8 +259,8 @@ struct gvfg_channel_session_t
eventQueue.clear(); eventQueue.clear();
} }
const pcies2mm_status_t st = backend->start_stream(); const gigabyte_status_t st = session->start_stream();
if (st != PCIES2MM_OK) if (st != GIGABYTE_OK)
return map_status(st); return map_status(st);
running = true; running = true;
@@ -273,12 +273,12 @@ struct gvfg_channel_session_t
releaseHeldFrameForStop(); releaseHeldFrameForStop();
releaseHeldAudioFrameForStop(); releaseHeldAudioFrameForStop();
pcies2mm_status_t st = PCIES2MM_OK; gigabyte_status_t st = GIGABYTE_OK;
if (backend) if (session)
{ {
// stop_stream() joins the backend event thread, so no new event can // stop_stream() joins the session event thread, so no new event can
// be queued after it returns. // be queued after it returns.
st = backend->stop_stream(); st = session->stop_stream();
} }
{ {
@@ -292,21 +292,21 @@ struct gvfg_channel_session_t
void close() void close()
{ {
stop(); stop();
if (backend) if (session)
{ {
backend->set_event_callback(nullptr, nullptr, 0); session->set_event_callback(nullptr, nullptr, 0);
backend->close(); session->close();
backend.reset(); session.reset();
} }
currentIndex = -1; currentIndex = -1;
} }
gvfg_status_t getSignalStatus(gvfg_signal_status_t &out) gvfg_status_t getSignalStatus(gvfg_signal_status_t &out)
{ {
if (!backend) if (!session)
return reject(GVFG_ESTATE, "gvfg_get_channel_signal_status rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_get_channel_signal_status rejected: channel is not open");
std::memset(&out, 0, sizeof(out)); std::memset(&out, 0, sizeof(out));
const pcies2mm_status_t status = querySignal(); const gigabyte_status_t status = querySignal();
{ {
std::lock_guard<std::mutex> lock(stateMutex); std::lock_guard<std::mutex> lock(stateMutex);
out.connected = signalConnected ? 1 : 0; out.connected = signalConnected ? 1 : 0;
@@ -321,16 +321,16 @@ struct gvfg_channel_session_t
gvfg_status_t getRuntimeInfo(gvfg_runtime_info_t &out) gvfg_status_t getRuntimeInfo(gvfg_runtime_info_t &out)
{ {
if (!backend) if (!session)
return reject(GVFG_ESTATE, "gvfg_get_channel_runtime_info rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_get_channel_runtime_info rejected: channel is not open");
std::memset(&out, 0, sizeof(out)); std::memset(&out, 0, sizeof(out));
out.capture_fps = runtimeFps.load(std::memory_order_relaxed); out.capture_fps = runtimeFps.load(std::memory_order_relaxed);
out.delivered_frames = deliveredFrames.load(std::memory_order_relaxed); out.delivered_frames = deliveredFrames.load(std::memory_order_relaxed);
pcies2mm_stream_stats_t stats{}; gigabyte_stream_stats_t stats{};
pcies2mm_debug_state_t debugState{}; gigabyte_debug_state_t debugState{};
uint64_t waitTimeouts = 0; uint64_t waitTimeouts = 0;
backend->get_debug_stats(stats, waitTimeouts, debugState); session->get_debug_stats(stats, waitTimeouts, debugState);
out.zero_copy_enabled = debugState.get_frame_zero_copy; out.zero_copy_enabled = debugState.get_frame_zero_copy;
out.driver_read_samples = debugState.get_frame_timing_samples; out.driver_read_samples = debugState.get_frame_timing_samples;
out.driver_read_average_us = debugState.get_frame_timing_average_us; out.driver_read_average_us = debugState.get_frame_timing_average_us;
@@ -339,16 +339,16 @@ struct gvfg_channel_session_t
return GVFG_OK; return GVFG_OK;
} }
void syncBackendEventCallback() void syncSessionEventCallback()
{ {
if (!backend) if (!session)
return; return;
backend->set_event_callback(&gvfg_channel_session_t::onBackendEvent, session->set_event_callback(&gvfg_channel_session_t::onSessionEvent,
this, this,
eventMask); eventMask);
} }
static void onBackendEvent(pcies2mm_event_type_t event, void *user) static void onSessionEvent(gigabyte_event_type_t event, void *user)
{ {
auto *self = static_cast<gvfg_channel_session_t *>(user); auto *self = static_cast<gvfg_channel_session_t *>(user);
if (!self) if (!self)
@@ -356,7 +356,7 @@ struct gvfg_channel_session_t
self->emitEvent(event); self->emitEvent(event);
} }
void emitEvent(pcies2mm_event_type_t event) void emitEvent(gigabyte_event_type_t event)
{ {
const gvfg_event_type_t type = map_event_type(event); const gvfg_event_type_t type = map_event_type(event);
{ {
@@ -371,57 +371,34 @@ struct gvfg_channel_session_t
eventCv.notify_one(); eventCv.notify_one();
} }
pcies2mm_status_t querySignal() gigabyte_status_t querySignal()
{ {
if (!backend) if (!session)
return PCIES2MM_ESTATE; return GIGABYTE_ESTATE;
pcies2mm_signal_status_t sig{}; gigabyte_signal_status_t sig{};
const pcies2mm_status_t status = backend->get_signal_status(sig); const gigabyte_status_t status = session->get_signal_status(sig);
std::lock_guard<std::mutex> lock(stateMutex); std::lock_guard<std::mutex> lock(stateMutex);
width = status == PCIES2MM_OK ? sig.width : 0; width = status == GIGABYTE_OK ? sig.width : 0;
height = status == PCIES2MM_OK ? sig.height : 0; height = status == GIGABYTE_OK ? sig.height : 0;
bitDepth = status == PCIES2MM_OK ? sig.bit_depth : 0; bitDepth = status == GIGABYTE_OK ? sig.bit_depth : 0;
pixelFormat = status == PCIES2MM_OK ? sig.pixel_format : PCIES2MM_PIXFMT_UNKNOWN; pixelFormat = status == GIGABYTE_OK ? sig.pixel_format : GIGABYTE_PIXFMT_UNKNOWN;
signalConnected = status == PCIES2MM_OK && sig.connected != 0; signalConnected = status == GIGABYTE_OK && sig.connected != 0;
return status; return status;
} }
gvfg_status_t configureStream() gvfg_status_t configureStream()
{ {
if (!backend) if (!session)
return reject(GVFG_ESTATE, "configure stream rejected: channel is not open"); return reject(GVFG_ESTATE, "configure stream rejected: channel is not open");
const pcies2mm_status_t signalStatus = querySignal(); const gigabyte_status_t signalStatus = querySignal();
if (signalStatus != PCIES2MM_OK) if (signalStatus != GIGABYTE_OK)
return map_status(signalStatus); return map_status(signalStatus);
bool waitingForSignal = false; const gigabyte_status_t st = session->configure_stream();
uint32_t configureWidth = 0; if (st != GIGABYTE_OK)
uint32_t configureHeight = 0;
pcies2mm_pixel_format_t configureFormat = PCIES2MM_PIXFMT_UNKNOWN;
{
std::lock_guard<std::mutex> lock(stateMutex);
waitingForSignal = !signalConnected;
configureWidth = waitingForSignal ? 2 : width;
configureHeight = waitingForSignal ? 1 : height;
configureFormat =
waitingForSignal || pixelFormat == PCIES2MM_PIXFMT_UNKNOWN ? PCIES2MM_PIXFMT_YUY2 : pixelFormat;
}
// configure_stream() is also used to enter event-monitoring mode. Keep
// its inactive placeholder buffer minimal; the real signal descriptor
// replaces it before DMA is enabled after reconnect.
pcies2mm_stream_desc_t desc{};
desc.width = configureWidth;
desc.height = configureHeight;
desc.pixel_format = configureFormat;
desc.buffer_count = 1;
const pcies2mm_status_t st = backend->configure_stream(desc);
if (st != PCIES2MM_OK)
return map_status(st); return map_status(st);
return GVFG_OK; return GVFG_OK;
} }
@@ -429,7 +406,7 @@ struct gvfg_channel_session_t
gvfg_status_t readFrame(gvfg_frame_t &out, uint32_t timeoutMs) gvfg_status_t readFrame(gvfg_frame_t &out, uint32_t timeoutMs)
{ {
std::memset(&out, 0, sizeof(out)); std::memset(&out, 0, sizeof(out));
if (!backend) if (!session)
return reject(GVFG_ESTATE, "gvfg_read_channel_frame rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_read_channel_frame rejected: channel is not open");
if (!running) if (!running)
return reject(GVFG_ESTATE, "gvfg_read_channel_frame rejected: channel is not running"); return reject(GVFG_ESTATE, "gvfg_read_channel_frame rejected: channel is not running");
@@ -447,9 +424,9 @@ struct gvfg_channel_session_t
if (stateError) if (stateError)
return reject(GVFG_ESTATE, stateError); return reject(GVFG_ESTATE, stateError);
pcies2mm_frame_t frame{}; gigabyte_frame_t frame{};
const pcies2mm_status_t st = backend->wait_frame(timeoutMs, frame); const gigabyte_status_t st = session->wait_frame(timeoutMs, frame);
if (st != PCIES2MM_OK) if (st != GIGABYTE_OK)
{ {
{ {
std::lock_guard<std::mutex> lock(frameMutex); std::lock_guard<std::mutex> lock(frameMutex);
@@ -460,7 +437,7 @@ struct gvfg_channel_session_t
if (!frame.data || frame.width == 0 || frame.height == 0) if (!frame.data || frame.width == 0 || frame.height == 0)
{ {
backend->release_frame(frame); session->release_frame(frame);
std::lock_guard<std::mutex> lock(frameMutex); std::lock_guard<std::mutex> lock(frameMutex);
readInProgress = false; readInProgress = false;
return reject(GVFG_EIO, "gvfg_read_channel_frame received an invalid frame descriptor"); return reject(GVFG_EIO, "gvfg_read_channel_frame received an invalid frame descriptor");
@@ -476,14 +453,14 @@ struct gvfg_channel_session_t
} }
else else
{ {
heldBackendFrame = frame; heldSessionFrame = frame;
readInProgress = false; readInProgress = false;
frameHeld = true; frameHeld = true;
} }
} }
if (stoppedWhileWaiting) if (stoppedWhileWaiting)
{ {
backend->release_frame(frame); session->release_frame(frame);
return GVFG_ESTATE; return GVFG_ESTATE;
} }
@@ -497,9 +474,9 @@ struct gvfg_channel_session_t
native_row_stride_bytes(frame.width, frame.pixel_format, out.row_stride_bytes); native_row_stride_bytes(frame.width, frame.pixel_format, out.row_stride_bytes);
if (strideStatus != GVFG_OK) if (strideStatus != GVFG_OK)
{ {
backend->release_frame(frame); session->release_frame(frame);
std::lock_guard<std::mutex> lock(frameMutex); std::lock_guard<std::mutex> lock(frameMutex);
heldBackendFrame = {}; heldSessionFrame = {};
frameHeld = false; frameHeld = false;
return reject(strideStatus, "gvfg_read_channel_frame received an invalid row stride"); return reject(strideStatus, "gvfg_read_channel_frame received an invalid row stride");
} }
@@ -514,7 +491,7 @@ struct gvfg_channel_session_t
gvfg_status_t releaseFrame(const gvfg_frame_t &frameToken) gvfg_status_t releaseFrame(const gvfg_frame_t &frameToken)
{ {
if (!backend) if (!session)
return reject(GVFG_ESTATE, "gvfg_release_channel_frame rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_release_channel_frame rejected: channel is not open");
{ {
@@ -523,27 +500,27 @@ struct gvfg_channel_session_t
return reject(GVFG_ESTATE, "gvfg_release_channel_frame rejected: no frame is currently held"); return reject(GVFG_ESTATE, "gvfg_release_channel_frame rejected: no frame is currently held");
int expectedStride = 0; int expectedStride = 0;
if (native_row_stride_bytes(heldBackendFrame.width, if (native_row_stride_bytes(heldSessionFrame.width,
heldBackendFrame.pixel_format, heldSessionFrame.pixel_format,
expectedStride) != GVFG_OK) expectedStride) != GVFG_OK)
return reject(GVFG_ESTATE, "gvfg_release_channel_frame rejected: held frame has an invalid row stride"); return reject(GVFG_ESTATE, "gvfg_release_channel_frame rejected: held frame has an invalid row stride");
if (frameToken.data != heldBackendFrame.data || if (frameToken.data != heldSessionFrame.data ||
frameToken.data_size != static_cast<uint64_t>(heldBackendFrame.data_size_bytes) || frameToken.data_size != static_cast<uint64_t>(heldSessionFrame.data_size_bytes) ||
frameToken.width != static_cast<int>(heldBackendFrame.width) || frameToken.width != static_cast<int>(heldSessionFrame.width) ||
frameToken.height != static_cast<int>(heldBackendFrame.height) || frameToken.height != static_cast<int>(heldSessionFrame.height) ||
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(heldSessionFrame.pixel_format) ||
frameToken.bit_depth != static_cast<int>(heldBackendFrame.bit_depth) || frameToken.bit_depth != static_cast<int>(heldSessionFrame.bit_depth) ||
frameToken.frame_id != heldBackendFrame.frame_id || frameToken.frame_id != heldSessionFrame.frame_id ||
frameToken.timestamp_ns != heldBackendFrame.timestamp_ns) frameToken.timestamp_ns != heldSessionFrame.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 gigabyte_status_t st = session->release_frame(heldSessionFrame);
if (st != PCIES2MM_OK) if (st != GIGABYTE_OK)
return map_status(st); return map_status(st);
heldBackendFrame = {}; heldSessionFrame = {};
frameHeld = false; frameHeld = false;
} }
@@ -552,29 +529,29 @@ struct gvfg_channel_session_t
void releaseHeldFrameForStop() void releaseHeldFrameForStop()
{ {
if (!backend) if (!session)
return; return;
pcies2mm_frame_t frame{}; gigabyte_frame_t frame{};
bool shouldRelease = false; bool shouldRelease = false;
{ {
std::lock_guard<std::mutex> lock(frameMutex); std::lock_guard<std::mutex> lock(frameMutex);
if (frameHeld) if (frameHeld)
{ {
frame = heldBackendFrame; frame = heldSessionFrame;
heldBackendFrame = {}; heldSessionFrame = {};
frameHeld = false; frameHeld = false;
shouldRelease = true; shouldRelease = true;
} }
} }
if (shouldRelease) if (shouldRelease)
backend->release_frame(frame); session->release_frame(frame);
} }
gvfg_status_t pollEvent(gvfg_event_t &out, uint32_t timeoutMs) gvfg_status_t pollEvent(gvfg_event_t &out, uint32_t timeoutMs)
{ {
if (!backend) if (!session)
return reject(GVFG_ESTATE, "gvfg_poll_channel_event rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_poll_channel_event rejected: channel is not open");
std::unique_lock<std::mutex> lock(eventMutex); std::unique_lock<std::mutex> lock(eventMutex);
@@ -616,7 +593,7 @@ struct gvfg_channel_session_t
return GVFG_OK; return GVFG_OK;
} }
gvfg_status_t getDebugBackendStats(gvfg_debug_backend_stats_t &out) gvfg_status_t getDebugStats(gvfg_debug_channel_stats_t &out)
{ {
std::memset(&out, 0, sizeof(out)); std::memset(&out, 0, sizeof(out));
out.sdk_running = running.load(std::memory_order_relaxed) ? 1 : 0; out.sdk_running = running.load(std::memory_order_relaxed) ? 1 : 0;
@@ -640,22 +617,22 @@ struct gvfg_channel_session_t
out.event_queue_depth = static_cast<uint32_t>(eventQueue.size()); out.event_queue_depth = static_cast<uint32_t>(eventQueue.size());
} }
if (backend) if (session)
{ {
pcies2mm_stream_stats_t stats{}; gigabyte_stream_stats_t stats{};
pcies2mm_debug_state_t debugState{}; gigabyte_debug_state_t debugState{};
uint64_t waitTimeouts = 0; uint64_t waitTimeouts = 0;
backend->get_debug_stats(stats, waitTimeouts, debugState); session->get_debug_stats(stats, waitTimeouts, debugState);
out.backend_state = static_cast<int>(stats.state); out.session_state = static_cast<int>(stats.state);
out.backend_frames_captured = stats.frames_captured; out.session_frames_captured = stats.frames_captured;
out.backend_frames_delivered = stats.frames_delivered; out.session_frames_delivered = stats.frames_delivered;
out.backend_dma_errors = stats.dma_errors; out.session_dma_errors = stats.dma_errors;
out.backend_interrupt_count = stats.interrupt_count; out.session_interrupt_count = stats.interrupt_count;
out.backend_wait_timeouts = waitTimeouts; out.session_wait_timeouts = waitTimeouts;
out.backend_running = debugState.running; out.session_running = debugState.running;
out.backend_capture_active = debugState.capture_active; out.session_capture_active = debugState.capture_active;
out.backend_latest_sequence = debugState.latest_sequence; out.session_latest_sequence = debugState.latest_sequence;
out.backend_delivered_sequence = debugState.delivered_sequence; out.session_delivered_sequence = debugState.delivered_sequence;
out.audio_dma_event_wakes = debugState.audio_dma_event_wakes; out.audio_dma_event_wakes = debugState.audio_dma_event_wakes;
out.extra_audio_event_wakes = debugState.extra_audio_event_wakes; out.extra_audio_event_wakes = debugState.extra_audio_event_wakes;
out.audio_frames_from_driver = debugState.audio_frames_from_driver; out.audio_frames_from_driver = debugState.audio_frames_from_driver;
@@ -670,38 +647,14 @@ struct gvfg_channel_session_t
return GVFG_OK; return GVFG_OK;
} }
gvfg_status_t debugReadRegister(uint32_t offset, uint32_t &outValue)
{
if (!backend)
return reject(GVFG_ESTATE, "debug register read rejected: channel is not open");
return map_status(backend->debug_read_register(offset, outValue));
}
gvfg_status_t setVideoFormat(gvfg_pixel_format_t format)
{
if (!backend)
return reject(GVFG_ESTATE, "gvfg_set_channel_video_format rejected: channel is not open");
pcies2mm_pixel_format_t backendFormat = PCIES2MM_PIXFMT_UNKNOWN;
if (format == GVFG_PIXFMT_YUY2)
backendFormat = PCIES2MM_PIXFMT_YUY2;
else if (format == GVFG_PIXFMT_Y210)
backendFormat = PCIES2MM_PIXFMT_Y210;
else
return reject(GVFG_EINVAL, "gvfg_set_channel_video_format rejected: pixel format is invalid");
const pcies2mm_status_t status = backend->set_video_format(backendFormat);
return map_status(status);
}
gvfg_status_t setAudioEnabled(bool enabled) gvfg_status_t setAudioEnabled(bool enabled)
{ {
if (!backend) if (!session)
return reject(GVFG_ESTATE, "gvfg_set_channel_audio_enabled rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_set_channel_audio_enabled rejected: channel is not open");
if (running) if (running)
return reject(GVFG_ESTATE, "gvfg_set_channel_audio_enabled rejected: channel is running"); return reject(GVFG_ESTATE, "gvfg_set_channel_audio_enabled rejected: channel is running");
const pcies2mm_status_t status = backend->set_audio_enabled(enabled); const gigabyte_status_t status = session->set_audio_enabled(enabled);
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
return map_status(status); return map_status(status);
audioEnabled = enabled; audioEnabled = enabled;
return GVFG_OK; return GVFG_OK;
@@ -710,11 +663,11 @@ struct gvfg_channel_session_t
gvfg_status_t getAudioFormat(gvfg_audio_format_t &out) gvfg_status_t getAudioFormat(gvfg_audio_format_t &out)
{ {
std::memset(&out, 0, sizeof(out)); std::memset(&out, 0, sizeof(out));
if (!backend) if (!session)
return reject(GVFG_ESTATE, "gvfg_get_channel_audio_format rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_get_channel_audio_format rejected: channel is not open");
pcies2mm_audio_format_t format{}; gigabyte_audio_format_t format{};
const pcies2mm_status_t status = backend->get_audio_format(format); const gigabyte_status_t status = session->get_audio_format(format);
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
return map_status(status); return map_status(status);
out.sample_rate = format.sample_rate; out.sample_rate = format.sample_rate;
out.channels = format.channels; out.channels = format.channels;
@@ -725,7 +678,7 @@ struct gvfg_channel_session_t
gvfg_status_t readAudioFrame(gvfg_audio_frame_t &out, uint32_t timeoutMs) gvfg_status_t readAudioFrame(gvfg_audio_frame_t &out, uint32_t timeoutMs)
{ {
std::memset(&out, 0, sizeof(out)); std::memset(&out, 0, sizeof(out));
if (!backend) if (!session)
return reject(GVFG_ESTATE, "gvfg_read_channel_audio_frame rejected: channel is not open"); return reject(GVFG_ESTATE, "gvfg_read_channel_audio_frame rejected: channel is not open");
if (!running || !audioEnabled) if (!running || !audioEnabled)
return reject(GVFG_ESTATE, "gvfg_read_channel_audio_frame rejected: audio capture is not running"); return reject(GVFG_ESTATE, "gvfg_read_channel_audio_frame rejected: audio capture is not running");
@@ -739,20 +692,20 @@ struct gvfg_channel_session_t
audioReadInProgress = true; audioReadInProgress = true;
} }
pcies2mm_audio_format_t format{}; gigabyte_audio_format_t format{};
pcies2mm_status_t status = backend->get_audio_format(format); gigabyte_status_t status = session->get_audio_format(format);
uint32_t bytes = 0; uint32_t bytes = 0;
if (status == PCIES2MM_OK) if (status == GIGABYTE_OK)
{ {
audioBuffer.resize(format.frame_bytes); audioBuffer.resize(format.frame_bytes);
status = backend->wait_audio(timeoutMs, audioBuffer.data(), status = session->wait_audio(timeoutMs, audioBuffer.data(),
static_cast<uint32_t>(audioBuffer.size()), bytes); static_cast<uint32_t>(audioBuffer.size()), bytes);
} }
{ {
std::lock_guard<std::mutex> lock(audioMutex); std::lock_guard<std::mutex> lock(audioMutex);
audioReadInProgress = false; audioReadInProgress = false;
if (status != PCIES2MM_OK) if (status != GIGABYTE_OK)
return map_status(status); return map_status(status);
if (!running.load(std::memory_order_acquire) || bytes == 0 || bytes > audioBuffer.size()) 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"); return reject(GVFG_ESTATE, "gvfg_read_channel_audio_frame completed after capture stopped or returned invalid data");
@@ -793,13 +746,6 @@ struct gvfg_channel_session_t
audioFrameHeld = false; audioFrameHeld = false;
} }
gvfg_status_t debugWriteRegister(uint32_t offset, uint32_t value)
{
if (!backend)
return reject(GVFG_ESTATE, "debug register write rejected: channel is not open");
return map_status(backend->debug_write_register(offset, value));
}
gvfg_status_t reject(gvfg_status_t status, const char *message) gvfg_status_t reject(gvfg_status_t status, const char *message)
{ {
errorState.set(message ? message : "GVFG operation rejected"); errorState.set(message ? message : "GVFG operation rejected");
@@ -851,7 +797,7 @@ struct gvfg_channel_session_t
} }
ChannelErrorState &errorState; ChannelErrorState &errorState;
std::unique_ptr<gvfg::internal::PcieS2mmCaptureSession> backend; std::unique_ptr<gvfg::internal::GigabyteCaptureSession> session;
int currentIndex = -1; int currentIndex = -1;
uint32_t selectedChannel = GVFG_CHANNEL_0; uint32_t selectedChannel = GVFG_CHANNEL_0;
bool zeroCopyRequested = false; bool zeroCopyRequested = false;
@@ -861,7 +807,7 @@ struct gvfg_channel_session_t
uint32_t width = 0; uint32_t width = 0;
uint32_t height = 0; uint32_t height = 0;
uint32_t bitDepth = 0; uint32_t bitDepth = 0;
pcies2mm_pixel_format_t pixelFormat = PCIES2MM_PIXFMT_UNKNOWN; gigabyte_pixel_format_t pixelFormat = GIGABYTE_PIXFMT_UNKNOWN;
bool signalConnected = false; bool signalConnected = false;
mutable std::mutex stateMutex; mutable std::mutex stateMutex;
std::atomic<uint64_t> fpsWindowStartNs{0}; std::atomic<uint64_t> fpsWindowStartNs{0};
@@ -877,7 +823,7 @@ struct gvfg_channel_session_t
std::mutex frameMutex; std::mutex frameMutex;
bool readInProgress = false; bool readInProgress = false;
bool frameHeld = false; bool frameHeld = false;
pcies2mm_frame_t heldBackendFrame{}; gigabyte_frame_t heldSessionFrame{};
std::mutex audioMutex; std::mutex audioMutex;
std::vector<uint8_t> audioBuffer; std::vector<uint8_t> audioBuffer;
bool audioReadInProgress = false; bool audioReadInProgress = false;
@@ -900,13 +846,6 @@ struct gvfg_handle_t
return status; return status;
} }
gvfg_status_t rejectAllChannels(gvfg_status_t status, const char *message)
{
for (ChannelErrorState &error : channelErrors)
error.set(message ? message : "GVFG operation rejected");
return status;
}
gvfg_status_t copyChannelError(int channelIndex, gvfg_status_t copyChannelError(int channelIndex,
char *outMessage, char *outMessage,
uint32_t outMessageSize) const uint32_t outMessageSize) const
@@ -927,13 +866,6 @@ struct gvfg_handle_t
return channels[static_cast<size_t>(channelIndex)].get(); return channels[static_cast<size_t>(channelIndex)].get();
} }
gvfg_channel_session_t *findOpenChannel()
{
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) gvfg_status_t openChannel(int index, int channelIndex)
{ {
if (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1) if (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1)
@@ -965,7 +897,7 @@ struct gvfg_handle_t
if (!deviceConnection) if (!deviceConnection)
{ {
deviceConnection = channel->backend->device_connection(); deviceConnection = channel->session->device_connection();
} }
channels[slot] = std::move(channel); channels[slot] = std::move(channel);
currentIndex = index; currentIndex = index;
@@ -1008,31 +940,6 @@ struct gvfg_handle_t
return GVFG_OK; return GVFG_OK;
} }
gvfg_status_t setChannelVideoFormat(int channelIndex, gvfg_pixel_format_t format)
{
gvfg_channel_session_t *channel = findChannel(channelIndex);
if (!channel)
return rejectChannel(channelIndex,
GVFG_ESTATE,
"gvfg_set_channel_video_format rejected: channel is not open");
if (format != GVFG_PIXFMT_YUY2 && format != GVFG_PIXFMT_Y210)
return rejectChannel(channelIndex,
GVFG_EINVAL,
"gvfg_set_channel_video_format rejected: pixel format is invalid");
const int otherChannel = channelIndex == GVFG_CHANNEL_0 ? GVFG_CHANNEL_1 : GVFG_CHANNEL_0;
if (format == GVFG_PIXFMT_Y210 &&
requestedFormats[static_cast<size_t>(otherChannel)] == GVFG_PIXFMT_Y210)
return rejectChannel(channelIndex,
GVFG_ENOTSUP,
"both channels cannot use Y210 at the same time");
const gvfg_status_t status = channel->setVideoFormat(format);
if (status == GVFG_OK)
requestedFormats[static_cast<size_t>(channelIndex)] = format;
return status;
}
gvfg_status_t stopAll() gvfg_status_t stopAll()
{ {
gvfg_status_t result = GVFG_OK; gvfg_status_t result = GVFG_OK;
@@ -1047,29 +954,12 @@ struct gvfg_handle_t
return result; return result;
} }
gvfg_status_t debugReadRegister(uint32_t offset, uint32_t &outValue)
{
gvfg_channel_session_t *channel = findOpenChannel();
return channel ? channel->debugReadRegister(offset, outValue)
: rejectAllChannels(GVFG_ESTATE,
"debug register read rejected: no channel is open");
}
gvfg_status_t debugWriteRegister(uint32_t offset, uint32_t value)
{
gvfg_channel_session_t *channel = findOpenChannel();
return channel ? channel->debugWriteRegister(offset, value)
: rejectAllChannels(GVFG_ESTATE,
"debug register write rejected: no channel is open");
}
std::array<ChannelErrorState, 2> channelErrors; std::array<ChannelErrorState, 2> channelErrors;
std::shared_ptr<gvfg::internal::PcieS2mmDeviceConnection> deviceConnection; std::shared_ptr<gvfg::internal::GigabyteDeviceConnection> deviceConnection;
std::array<std::unique_ptr<gvfg_channel_session_t>, 2> channels; 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}; std::array<uint32_t, 2> eventMasks{GVFG_EVENT_MASK_ALL, GVFG_EVENT_MASK_ALL};
int currentIndex = -1; int currentIndex = -1;
std::array<bool, 2> zeroCopyRequested{false, false}; std::array<bool, 2> zeroCopyRequested{false, false};
std::array<gvfg_pixel_format_t, 2> requestedFormats{GVFG_PIXFMT_YUY2, GVFG_PIXFMT_YUY2};
}; };
extern "C" extern "C"
@@ -1190,15 +1080,6 @@ extern "C"
"gvfg_start_channel rejected: channel is not open"); "gvfg_start_channel rejected: channel is not open");
} }
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->setChannelVideoFormat(channel_index, format);
}
gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle, gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle,
int channel_index, int channel_index,
int enabled) int enabled)
@@ -1416,9 +1297,9 @@ extern "C"
return handle->copyChannelError(channel_index, out_message, out_message_size); return handle->copyChannelError(channel_index, out_message, out_message_size);
} }
gvfg_status_t gvfg_debug_get_channel_backend_stats(gvfg_handle handle, gvfg_status_t gvfg_debug_get_channel_stats(gvfg_handle handle,
int channel_index, int channel_index,
gvfg_debug_backend_stats_t *out_stats) gvfg_debug_channel_stats_t *out_stats)
{ {
if (!handle || !out_stats) if (!handle || !out_stats)
return GVFG_EINVAL; return GVFG_EINVAL;
@@ -1426,8 +1307,8 @@ extern "C"
gvfg_channel_session_t *channel = handle->findChannel(channel_index); gvfg_channel_session_t *channel = handle->findChannel(channel_index);
if (!channel) if (!channel)
return GVFG_ESTATE; return GVFG_ESTATE;
gvfg_debug_backend_stats_t stats{}; gvfg_debug_channel_stats_t stats{};
const gvfg_status_t status = channel->getDebugBackendStats(stats); const gvfg_status_t status = channel->getDebugStats(stats);
if (status != GVFG_OK) if (status != GVFG_OK)
return status; return status;
@@ -1435,21 +1316,4 @@ extern "C"
return GVFG_OK; return GVFG_OK;
} }
gvfg_status_t gvfg_debug_read_register(gvfg_handle handle,
uint32_t offset,
uint32_t *out_value)
{
if (!handle || !out_value || (offset & 0x3u) != 0)
return GVFG_EINVAL;
return handle->debugReadRegister(offset, *out_value);
}
gvfg_status_t gvfg_debug_write_register(gvfg_handle handle,
uint32_t offset,
uint32_t value)
{
if (!handle || (offset & 0x3u) != 0)
return GVFG_EINVAL;
return handle->debugWriteRegister(offset, value);
}
} }
+3 -21
View File
@@ -76,26 +76,8 @@ MSVC 上層連結 `gvfg.lib` 與 `gvfg_preview.lib`;MinGW 上層連結
## Driver compatibility ## Driver compatibility
此版本只支援新版 PCIE S2MM driver,不再 backward compatible 舊版 driver。 GVFG SDK 不再直接定義 driver IOCTL 或 register layout。底層 driver 相容性由
新版 driver 必須支援: 主管提供的 `GvfgSdk.lib` 負責,GVFG 只使用其 `Gvfg*` API。
- `IOCTL_GIGA_VIDEO_START`(function `0x830`)。
- `IOCTL_GIGA_VIDEO_STOP`(function `0x831`)。
- `IOCTL_GIGA_RELEASE_VIDEO_FRAME` 到 `IOCTL_GIGA_CLOSE_VIDEO`
使用 function `0x832` 到 `0x837`。
- `IOCTL_PCIES2MM_GET_FRAME` 接受 `frameIndex = MAXULONG`(`0xFFFFFFFF`),
由 driver 自行選擇已完成的 frame。
- `IOCTL_PCIES2MM_GET_AUDIO_FRAME`(function `0x809`)同樣接受
`frameIndex = MAXULONG`。
- `IOCTL_GIGA_START_VIDEO_AUDIO`、`IOCTL_GIGA_STOP_VIDEO_AUDIO` 與
`IOCTL_GIGA_GET_AUDIO_INFO`(function `0x839` 到 `0x83B`)。
- Extra video/audio frame event(event type `5`、`6`)表示 driver 仍有
frame 待取;SDK 將它們當成額外的 ready notification。
SDK 不再呼叫 `IOCTL_PCIES2MM_GET_VIDEO_DONE_INDEX`,也不會在新 IOCTL
不支援時退回直接寫入 `VIDEO_DMA_EN_OFFSET`、`VIDEO_EN_OFFSET` 或
`IRQ_MASK_W1S_OFFSET`。若搭配舊版 driver,stream start 或 frame capture
可能失敗。
### Zero-copy selection ### Zero-copy selection
@@ -217,6 +199,6 @@ bin/gvfg_preview.dll
GPU snapshot/export conversion 已整合在 `gvfg.dll`,不需要額外 helper DLL。 GPU snapshot/export conversion 已整合在 `gvfg.dll`,不需要額外 helper DLL。
Customer/demo package 不應包含 `gvfg_debug.h`、SDK source、PCIES2MM backend Customer/demo package 不應包含 `gvfg_debug.h`、SDK source、GigabyteLib session
headers、IRQ details 或 helper source。這些只屬於 internal headers、IRQ details 或 helper source。這些只屬於 internal
debug/full application package。 debug/full application package。
+6 -6
View File
@@ -36,13 +36,13 @@
<mxCell id="workers" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="per-channel workers&lt;br&gt;caller read thread waits DMA&lt;br&gt;event thread waits format / plug events" vertex="1"> <mxCell id="workers" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="per-channel workers&lt;br&gt;caller read thread waits DMA&lt;br&gt;event thread waits format / plug events" vertex="1">
<mxGeometry height="52" width="280" x="510" y="173" as="geometry" /> <mxGeometry height="52" width="280" x="510" y="173" as="geometry" />
</mxCell> </mxCell>
<mxCell id="pcies2mmSession" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="CH0 + CH1 PcieS2mmCaptureSession&lt;br&gt;independent events / state / direct frame read" vertex="1"> <mxCell id="gigabyteSession" parent="backendLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#d6b656;fontSize=14;" value="CH0 + CH1 GigabyteCaptureSession&lt;br&gt;independent events / state / direct frame read" vertex="1">
<mxGeometry height="58" width="340" x="420" y="65" as="geometry" /> <mxGeometry height="58" width="340" x="420" y="65" as="geometry" />
</mxCell> </mxCell>
<mxCell id="e6" edge="1" parent="backendLayer" source="pcies2mmSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="backendTypes" value="uses"> <mxCell id="e6" edge="1" parent="backendLayer" source="gigabyteSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="backendTypes" value="uses">
<mxGeometry relative="1" as="geometry" /> <mxGeometry relative="1" as="geometry" />
</mxCell> </mxCell>
<mxCell id="e7" edge="1" parent="backendLayer" source="pcies2mmSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="workers" value="owns"> <mxCell id="e7" edge="1" parent="backendLayer" source="gigabyteSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="workers" value="owns">
<mxGeometry relative="1" x="-0.004" as="geometry"> <mxGeometry relative="1" x="-0.004" as="geometry">
<mxPoint as="offset" /> <mxPoint as="offset" />
</mxGeometry> </mxGeometry>
@@ -80,7 +80,7 @@
<mxCell id="e4" edge="1" parent="1" source="qtSample" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="render" value="private preview"> <mxCell id="e4" edge="1" parent="1" source="qtSample" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="render" value="private preview">
<mxGeometry relative="1" as="geometry" /> <mxGeometry relative="1" as="geometry" />
</mxCell> </mxCell>
<mxCell id="e5" edge="1" parent="1" source="facade" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="pcies2mmSession" value="backend API calls"> <mxCell id="e5" edge="1" parent="1" source="facade" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="gigabyteSession" value="backend API calls">
<mxGeometry relative="1" as="geometry" /> <mxGeometry relative="1" as="geometry" />
</mxCell> </mxCell>
<mxCell id="e8" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="ring" value=""> <mxCell id="e8" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="ring" value="">
@@ -89,7 +89,7 @@
<mxCell id="e11" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="eventFlow" value="callback / queue"> <mxCell id="e11" edge="1" parent="1" source="workers" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="eventFlow" value="callback / queue">
<mxGeometry relative="1" as="geometry" /> <mxGeometry relative="1" as="geometry" />
</mxCell> </mxCell>
<mxCell id="e9" edge="1" parent="1" source="pcies2mmSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="facade" value="frames / events / status"> <mxCell id="e9" edge="1" parent="1" source="gigabyteSession" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="facade" value="frames / events / status">
<mxGeometry relative="1" as="geometry"> <mxGeometry relative="1" as="geometry">
<Array as="points"> <Array as="points">
<mxPoint x="420" y="589" /> <mxPoint x="420" y="589" />
@@ -97,7 +97,7 @@
</Array> </Array>
</mxGeometry> </mxGeometry>
</mxCell> </mxCell>
<mxCell id="e10" edge="1" parent="1" source="externalBoundary" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="pcies2mmSession" value="input boundary"> <mxCell id="e10" edge="1" parent="1" source="externalBoundary" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="gigabyteSession" value="input boundary">
<mxGeometry relative="1" as="geometry"> <mxGeometry relative="1" as="geometry">
<Array as="points"> <Array as="points">
<mxPoint x="550" y="780" /> <mxPoint x="550" y="780" />
+2 -2
View File
@@ -231,8 +231,8 @@ Zero-copy mode 的 driver lifecycle 由 SDK 管理:open 時 enable,每次成
成功 read 後,不論 PCM 是送往播放、錄音或被丟棄,都必須正好 release 一次。 成功 read 後,不論 PCM 是送往播放、錄音或被丟棄,都必須正好 release 一次。
`gvfg_set_channel_video_format()` 只能在指定 stream 尚未開始或已 stop 時呼叫;streaming 中 Video format 由 `GvfgGetVideoInfo()` 回報的原生輸入格式決定。GigabyteLib 沒有
切換會回傳 `GVFG_ESTATE`。應用程式應在 UI 上同步鎖定格式選項。 輸出格式切換 API,因此 GVFG 不提供格式 setter。
### 查詢 ### 查詢
+1 -16
View File
@@ -263,22 +263,7 @@ gvfg_status_t gvfg_get_channel_zero_copy_enabled(gvfg_handle handle, int channel
呼叫 `gvfg_release_channel_frame()`,且每個 channel 同時最多持有一張 frame。 呼叫 `gvfg_release_channel_frame()`,且每個 channel 同時最多持有一張 frame。
- SDK 在 open 時 enable driver zero-copy,在 destroy/close 前 disable。 - SDK 在 open 時 enable driver zero-copy,在 destroy/close 前 disable。
### 1.19 `gvfg_set_channel_video_format` ### 1.19 Audio capture selection and frame ownership
```c
gvfg_status_t gvfg_set_channel_video_format(gvfg_handle handle,
int channel_index,
gvfg_pixel_format_t format);
```
- 支援 `GVFG_PIXFMT_YUY2` 與 `GVFG_PIXFMT_Y210`。
- Device 必須已 open,且 stream 必須尚未 start 或已 stop。
- Streaming 中呼叫回傳 `GVFG_ESTATE`;不支援的 format 回傳 `GVFG_ENOTSUP` 或
`GVFG_EINVAL`。
- 同一裝置的 CH0、CH1 不可同時設定 Y210;第二個 Y210 request 回傳
`GVFG_ENOTSUP`。
### 1.19a Audio capture selection and frame ownership
```c ```c
gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle, gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle,
+12 -12
View File
@@ -65,7 +65,7 @@ explicit gvfg_channel_session_t(ChannelErrorState &errorState)
backend 也取得同一份 reference: backend 也取得同一份 reference:
```cpp ```cpp
backend = std::make_unique<PcieS2mmCaptureSession>(errorState); backend = std::make_unique<GigabyteCaptureSession>(errorState);
``` ```
因此同一條 channel 的三層共用同一份詳細訊息: 因此同一條 channel 的三層共用同一份詳細訊息:
@@ -75,7 +75,7 @@ backend = std::make_unique<PcieS2mmCaptureSession>(errorState);
↓ ↓
gvfg_channel_session_t gvfg_channel_session_t
↓ ↓
PcieS2mmCaptureSession GigabyteCaptureSession
↓ ↓
同一個 ChannelErrorState 同一個 ChannelErrorState
``` ```
@@ -104,7 +104,7 @@ backend event thread、capture/read thread 與 application thread 都可能產
`gvfg_poll_channel_event()` 的 timeout/non-blocking 無資料不會寫入 `gvfg_poll_channel_event()` 的 timeout/non-blocking 無資料不會寫入
`ChannelErrorState`。目前 `gvfg_read_channel_frame()` 的 backend timeout 會經過 `ChannelErrorState`。目前 `gvfg_read_channel_frame()` 的 backend timeout 會經過
`PcieS2mmCaptureSession::reject()`,因此會保存 timeout 詳細訊息。新的 `GigabyteCaptureSession::reject()`,因此會保存 timeout 詳細訊息。新的
`gvfg_start_channel()` request 會先清除舊內容;若 start 失敗,失敗路徑會立即寫入新的 `gvfg_start_channel()` request 會先清除舊內容;若 start 失敗,失敗路徑會立即寫入新的
詳細資訊。 詳細資訊。
@@ -146,7 +146,7 @@ backend 的 `fail()` 會組合:
例如: 例如:
```cpp ```cpp
return fail(PCIES2MM_EIO, "wait DMA event", err); return fail(GIGABYTE_EIO, "wait DMA event", err);
``` ```
同時會: 同時會:
@@ -157,16 +157,16 @@ return fail(PCIES2MM_EIO, "wait DMA event", err);
## 6. Backend status 如何轉成公開 status ## 6. Backend status 如何轉成公開 status
backend 使用 `pcies2mm_status_t`,facade 透過 `map_status()` 轉成 `gvfg_status_t`: backend 使用 `gigabyte_status_t`,facade 透過 `map_status()` 轉成 `gvfg_status_t`:
```text ```text
PCIES2MM_OK -> GVFG_OK GIGABYTE_OK -> GVFG_OK
PCIES2MM_EINVAL -> GVFG_EINVAL GIGABYTE_EINVAL -> GVFG_EINVAL
PCIES2MM_ENODEV -> GVFG_ENODEV GIGABYTE_ENODEV -> GVFG_ENODEV
PCIES2MM_ESTATE -> GVFG_ESTATE GIGABYTE_ESTATE -> GVFG_ESTATE
PCIES2MM_ENOTSUP -> GVFG_ENOTSUP GIGABYTE_ENOTSUP -> GVFG_ENOTSUP
PCIES2MM_ETIMEOUT -> GVFG_ETIMEOUT GIGABYTE_ETIMEOUT -> GVFG_ETIMEOUT
PCIES2MM_EIO -> GVFG_EIO GIGABYTE_EIO -> GVFG_EIO
``` ```
轉換只改錯誤分類,不應覆蓋 backend 已寫入的詳細訊息。 轉換只改錯誤分類,不應覆蓋 backend 已寫入的詳細訊息。
+3 -3
View File
@@ -58,7 +58,7 @@ frame ownership 與 timeout 契約,不再直接操作 driver IOCTL 或 FPGA re
| signal 欄位 | `stateMutex` | width/height/format/connected cache | | signal 欄位 | `stateMutex` | width/height/format/connected cache |
| delivered/FPS 欄位 | atomic | UI/debug runtime 統計 | | delivered/FPS 欄位 | atomic | UI/debug runtime 統計 |
### `PcieS2mmCaptureSession`:driver backend ### `GigabyteCaptureSession`:driver backend
| 變數 | 保護方式 | 意義 | | 變數 | 保護方式 | 意義 |
|---|---|---| |---|---|---|
@@ -119,9 +119,9 @@ currentIndex = -1
```text ```text
建立 gvfg_channel_session_t 建立 gvfg_channel_session_t
-> 建立 PcieS2mmCaptureSession -> 建立 GigabyteCaptureSession
-> CreateFileW() 得到 Windows HANDLE -> CreateFileW() 得到 Windows HANDLE
-> 建立 PcieS2mmDeviceConnection -> 建立 GigabyteDeviceConnection
-> gvfg_handle_t 保存 shared_ptr -> gvfg_handle_t 保存 shared_ptr
-> backend set_channel(CH0 或 CH1) -> backend set_channel(CH0 或 CH1)
-> 建立並註冊該 channel events -> 建立並註冊該 channel events
+10 -28
View File
@@ -42,9 +42,9 @@ customer/sample (optional)
- `gvfg_capture.cpp`:公開 handle 狀態、狀態碼轉換、frame token 驗證、event - `gvfg_capture.cpp`:公開 handle 狀態、狀態碼轉換、frame token 驗證、event
queue、runtime counter 與 debug API facade。 queue、runtime counter 與 debug API facade。
- `backend/gigabyte/gigabyte_capture_session.*`:把既有 GVFG lifecycle、event、 - `gigabyte/gigabyte_capture_session.*`:把既有 GVFG lifecycle、event、
copy/zero-copy ownership 契約轉接到 `GvfgSdk.lib`。 copy/zero-copy ownership 契約轉接到 `GvfgSdk.lib`。
- `backend/gigabyte/gigabyte_device.*`:SetupAPI 裝置列舉與 interface path。 - `gigabyte/gigabyte_device.*`:SetupAPI 裝置列舉與 interface path。
- `third_party/GigabyteLib`:主管提供的靜態 library 與其 private headers,只供 SDK build。 - `third_party/GigabyteLib`:主管提供的靜態 library 與其 private headers,只供 SDK build。
- `src/gpu/*`:D3D11 同步轉換及 readback 到 caller buffer。 - `src/gpu/*`:D3D11 同步轉換及 readback 到 caller buffer。
@@ -120,19 +120,10 @@ x64 `gvfg_frame_t` ABI 已在 `gvfg_capture.cpp` 以 static assertions 固定為
及明確欄位 offsets。修改公開 struct 時必須視為 ABI 變更,不能只重新編譯 DLL。 及明確欄位 offsets。修改公開 struct 時必須視為 ABI 變更,不能只重新編譯 DLL。
新增 metadata 優先考慮新 query API 或帶 size/version 的新 struct。 新增 metadata 優先考慮新 query API 或帶 size/version 的新 struct。
## Driver ABI requirement ## GigabyteLib requirement
目前 SDK 只支援新版 PCIE S2MM driver,必要 private ABI 包含: GVFG 不再保存或操作 private IOCTL、register offset 或 DMA request layout。
Driver ABI 相容性由主管提供的 `GvfgSdk.lib` 負責。
- `IOCTL_GIGA_VIDEO_START` (`0x830`) / `IOCTL_GIGA_VIDEO_STOP` (`0x831`)。
- `IOCTL_GIGA_RELEASE_VIDEO_FRAME` (`0x832`)。
- `IOCTL_GIGA_ACQUIRE_VIDEO_FRAME_ZEROCOPY` (`0x833`)。
- `IOCTL_GIGA_ENABLE_FRAME_ZEROCOPY` (`0x834`) /
`IOCTL_GIGA_DISABLE_FRAME_ZEROCOPY` (`0x835`)。
- Copy mode 的 `IOCTL_PCIES2MM_GET_FRAME` 接受 `frameIndex=0xFFFFFFFF`。
不再呼叫 `GET_VIDEO_DONE_INDEX`,也不再 fallback 直接寫入 video enable、DMA enable
或 IRQ mask registers。舊 driver 不屬於此 revision 的支援範圍。
目前原生格式: 目前原生格式:
@@ -148,19 +139,15 @@ Backend event 映射:
| Backend | Public | | Backend | Public |
|---|---| |---|---|
| `PCIES2MM_EVENT_PLUG_IN` | `GVFG_EVENT_SIGNAL_CONNECTED` | | `GIGABYTE_EVENT_PLUG_IN` | `GVFG_EVENT_SIGNAL_CONNECTED` |
| `PCIES2MM_EVENT_PLUG_OUT` | `GVFG_EVENT_SIGNAL_DISCONNECTED` | | `GIGABYTE_EVENT_PLUG_OUT` | `GVFG_EVENT_SIGNAL_DISCONNECTED` |
| `PCIES2MM_EVENT_STREAM_READY` | `GVFG_EVENT_STREAM_READY` | | `GIGABYTE_EVENT_STREAM_READY` | `GVFG_EVENT_STREAM_READY` |
| `PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN` | `GVFG_EVENT_FORMAT_CHANGE_BEGIN` | | `GIGABYTE_EVENT_FORMAT_CHANGE_BEGIN` | `GVFG_EVENT_FORMAT_CHANGE_BEGIN` |
每個 channel 的 public event mask 在 open 前設定。Video DMA event 永遠註冊; 每個 channel 的 public event mask 在 open 前設定。Video DMA event 永遠註冊;
format-change、plug-in、unplug driver event 依 mask 選擇性註冊。關閉 driver event format-change、plug-in、unplug driver event 依 mask 選擇性註冊。關閉 driver event
同時代表 backend 不執行該事件所驅動的自動 recovery。 同時代表 backend 不執行該事件所驅動的自動 recovery。
Register read 必須排除純 write-only 位址:global `0x080`,以及每個 video/audio
channel 的 descriptor-write pulse 與 DMA soft-reset register。Interrupt
`0x000/0x004/0x008` 是 read-status/write-control 雙語意位址,讀取其 RO status 合法。
Facade queue 上限為 64;滿時丟棄最舊事件。`pollEvent()` 只允許 running 狀態,支援 Facade queue 上限為 64;滿時丟棄最舊事件。`pollEvent()` 只允許 running 狀態,支援
non-blocking、有限 timeout 與 infinite wait;stop 透過 `eventCv` 喚醒 waiter。 non-blocking、有限 timeout 與 infinite wait;stop 透過 `eventCv` 喚醒 waiter。
@@ -172,13 +159,8 @@ non-blocking、有限 timeout 與 infinite wait;stop 透過 `eventCv` 喚醒 w
`gvfg_debug.h` 僅供內部工具,包含: `gvfg_debug.h` 僅供內部工具,包含:
- `gvfg_debug_get_channel_backend_stats()`:指定 channel 的 facade/backend state、 - `gvfg_debug_get_channel_stats()`:指定 channel 的 facade/backend state、
captured/delivered frame、DMA error、IRQ、timeout、sequence 與 GetFrame timing。 captured/delivered frame、DMA error、IRQ、timeout、sequence 與 GetFrame timing。
- `gvfg_debug_read_register()`:讀取 4-byte aligned BAR-relative register。
- `gvfg_debug_write_register()`:寫入 register。
Register write 可能中斷 DMA、interrupt 或 capture。工具必須確認裝置、offset 與當前
stream 狀態,且不得將 register API 包裝成客戶功能。
客戶診斷使用 `gvfg_get_channel_signal_status()`、`gvfg_get_channel_runtime_info()`、event、 客戶診斷使用 `gvfg_get_channel_signal_status()`、`gvfg_get_channel_runtime_info()`、event、
`gvfg_strerror()` 與 `gvfg_get_channel_last_error_detail()`。每個 channel 的 `ChannelErrorState` `gvfg_strerror()` 與 `gvfg_get_channel_last_error_detail()`。每個 channel 的 `ChannelErrorState`
+2 -2
View File
@@ -5,7 +5,7 @@
## 建議閱讀順序 ## 建議閱讀順序
1. [`GVFG_Overview.md`](GVFG_Overview.md) 1. [`GVFG_Overview.md`](GVFG_Overview.md)
- 先認識 `gvfg_handle_t`、`gvfg_channel_session_t`、`PcieS2mmCaptureSession`。 - 先認識 `gvfg_handle_t`、`gvfg_channel_session_t`、`GigabyteCaptureSession`。
- 理解 `unique_ptr`、`shared_ptr`、宣告與實際配置的差異。 - 理解 `unique_ptr`、`shared_ptr`、宣告與實際配置的差異。
- 理解 CH0、CH1 如何共用同一個 Windows device handle。 - 理解 CH0、CH1 如何共用同一個 Windows device handle。
2. [`GVFG_ERROR_HANDLING.md`](GVFG_ERROR_HANDLING.md) 2. [`GVFG_ERROR_HANDLING.md`](GVFG_ERROR_HANDLING.md)
@@ -31,7 +31,7 @@
目前已實作: 目前已實作:
- 一個 `gvfg_handle_t` 可管理 CH0、CH1。 - 一個 `gvfg_handle_t` 可管理 CH0、CH1。
- CH0、CH1 共用一個 `PcieS2mmDeviceConnection`,底層只有一個 Windows device `HANDLE`。 - CH0、CH1 共用一個 `GigabyteDeviceConnection`,底層只有一個 Windows device `HANDLE`。
- 每條 channel 各自擁有 backend、event、capture thread、copy buffer 與 frame lifetime state。 - 每條 channel 各自擁有 backend、event、capture thread、copy buffer 與 frame lifetime state。
- 公開 API 已改為 channel-aware:open/start/read/release/poll/stop 都帶 `channel_index`。 - 公開 API 已改為 channel-aware:open/start/read/release/poll/stop 都帶 `channel_index`。
- copy mode 直接把 driver frame 寫入該 channel 的 `copy_buffer_`。 - copy mode 直接把 driver frame 寫入該 channel 的 `copy_buffer_`。
+23 -23
View File
@@ -17,7 +17,7 @@ sdk/gvfg/include
sdk/gvfg/src/gvfg_capture.cpp sdk/gvfg/src/gvfg_capture.cpp
C ABI facade、opaque handle、channel 管理、參數驗證、frame token、event queue C ABI facade、opaque handle、channel 管理、參數驗證、frame token、event queue
sdk/gvfg/src/backend/gigabyte sdk/gvfg/src/gigabyte
將公開 API 的 lifecycle、event、copy/zero-copy ownership 轉接至 GvfgSdk.lib 將公開 API 的 lifecycle、event、copy/zero-copy ownership 轉接至 GvfgSdk.lib
third_party/GigabyteLib third_party/GigabyteLib
@@ -112,7 +112,7 @@ struct gvfg_handle_t
std::array<ChannelErrorState, 2> channelErrors; std::array<ChannelErrorState, 2> channelErrors;
std::shared_ptr< std::shared_ptr<
gvfg::internal::PcieS2mmDeviceConnection gvfg::internal::GigabyteDeviceConnection
> deviceConnection; > deviceConnection;
std::array< std::array<
@@ -135,7 +135,7 @@ struct gvfg_handle_t
### `deviceConnection` ### `deviceConnection`
```cpp ```cpp
std::shared_ptr<PcieS2mmDeviceConnection> deviceConnection; std::shared_ptr<GigabyteDeviceConnection> deviceConnection;
``` ```
負責保存底層 Windows driver connection。 負責保存底層 Windows driver connection。
@@ -207,7 +207,7 @@ channels[1] 獨自擁有 CH1 session
struct gvfg_channel_session_t struct gvfg_channel_session_t
{ {
ChannelErrorState &errorState; ChannelErrorState &errorState;
std::unique_ptr<PcieS2mmCaptureSession> backend; std::unique_ptr<GigabyteCaptureSession> backend;
int currentIndex; int currentIndex;
uint32_t selectedChannel; uint32_t selectedChannel;
@@ -218,13 +218,13 @@ struct gvfg_channel_session_t
bool readInProgress; bool readInProgress;
bool frameHeld; bool frameHeld;
pcies2mm_frame_t heldBackendFrame; gigabyte_frame_t heldBackendFrame;
// FPS、signal、event queue 等其他狀態 // FPS、signal、event queue 等其他狀態
}; };
``` ```
它是「公開 GVFG API」與「底層 PCIES2MM backend」中間的包裝層。 它是「公開 GVFG API」與「底層 GIGABYTE backend」中間的包裝層。
例如應用程式呼叫: 例如應用程式呼叫:
@@ -241,7 +241,7 @@ gvfg_read_channel_frame()
↓ ↓
gvfg_channel_session_t::readFrame() gvfg_channel_session_t::readFrame()
↓ ↓
PcieS2mmCaptureSession::wait_frame() GigabyteCaptureSession::wait_frame()
↓ ↓
driver IOCTL driver IOCTL
``` ```
@@ -257,14 +257,14 @@ driver IOCTL
--- ---
## 第四層:`PcieS2mmCaptureSession` ## 第四層:`GigabyteCaptureSession`
這是實際操作 PCIES2MM driver 的單一 channel backend: 這是實際操作 GIGABYTE driver 的單一 channel backend:
```cpp ```cpp
class PcieS2mmCaptureSession class GigabyteCaptureSession
{ {
std::shared_ptr<PcieS2mmDeviceConnection> std::shared_ptr<GigabyteDeviceConnection>
device_connection_; device_connection_;
HANDLE dma_event_; HANDLE dma_event_;
@@ -277,7 +277,7 @@ class PcieS2mmCaptureSession
bool zero_copy_enabled_; bool zero_copy_enabled_;
std::vector<uint8_t> copy_buffer_; std::vector<uint8_t> copy_buffer_;
pcies2mm_frame_t held_frame_; gigabyte_frame_t held_frame_;
bool frame_held_; bool frame_held_;
bool read_in_progress_; bool read_in_progress_;
@@ -288,7 +288,7 @@ class PcieS2mmCaptureSession
}; };
``` ```
CH0、CH1 各有自己的 `PcieS2mmCaptureSession`,因此它們各自擁有: CH0、CH1 各有自己的 `GigabyteCaptureSession`,因此它們各自擁有:
- 自己的 DMA event - 自己的 DMA event
- 自己的 signal event - 自己的 signal event
@@ -308,16 +308,16 @@ device_connection_
--- ---
## 第五層:`PcieS2mmDeviceConnection` ## 第五層:`GigabyteDeviceConnection`
目前非常單純: 目前非常單純:
```cpp ```cpp
struct PcieS2mmDeviceConnection struct GigabyteDeviceConnection
{ {
HANDLE handle = INVALID_HANDLE_VALUE; HANDLE handle = INVALID_HANDLE_VALUE;
~PcieS2mmDeviceConnection(); ~GigabyteDeviceConnection();
}; };
``` ```
@@ -332,7 +332,7 @@ connection->handle = CreateFileW(...);
最後一個 `shared_ptr` 被釋放時,destructor 執行: 最後一個 `shared_ptr` 被釋放時,destructor 執行:
```cpp ```cpp
PcieS2mmDeviceConnection::~PcieS2mmDeviceConnection() GigabyteDeviceConnection::~GigabyteDeviceConnection()
{ {
if (handle != INVALID_HANDLE_VALUE) if (handle != INVALID_HANDLE_VALUE)
CloseHandle(handle); CloseHandle(handle);
@@ -345,8 +345,8 @@ PcieS2mmDeviceConnection::~PcieS2mmDeviceConnection()
```text ```text
gvfg_handle_t gvfg_handle_t
CH0 PcieS2mmCaptureSession CH0 GigabyteCaptureSession
CH1 PcieS2mmCaptureSession CH1 GigabyteCaptureSession
``` ```
它們共同使用同一個 Windows `HANDLE`。 它們共同使用同一個 Windows `HANDLE`。
@@ -462,14 +462,14 @@ gvfg_create()
gvfg_open_channel(CH0) gvfg_open_channel(CH0)
│ │
├─ 建立 CH0 gvfg_channel_session_t ├─ 建立 CH0 gvfg_channel_session_t
├─ 建立 CH0 PcieS2mmCaptureSession ├─ 建立 CH0 GigabyteCaptureSession
├─ CreateFileW() 開啟 driver ├─ CreateFileW() 開啟 driver
└─ deviceConnection 保存 Windows HANDLE └─ deviceConnection 保存 Windows HANDLE
gvfg_open_channel(CH1) gvfg_open_channel(CH1)
│ │
├─ 建立 CH1 gvfg_channel_session_t ├─ 建立 CH1 gvfg_channel_session_t
├─ 建立 CH1 PcieS2mmCaptureSession ├─ 建立 CH1 GigabyteCaptureSession
└─ 共用既有 deviceConnection └─ 共用既有 deviceConnection
gvfg_start_channel(CH0) gvfg_start_channel(CH0)
@@ -496,10 +496,10 @@ gvfg_handle_t
gvfg_channel_session_t gvfg_channel_session_t
= 公開 API 所看到的一條 channel = 公開 API 所看到的一條 channel
PcieS2mmCaptureSession GigabyteCaptureSession
= 實際操作 driver 的一條 channel = 實際操作 driver 的一條 channel
PcieS2mmDeviceConnection GigabyteDeviceConnection
= CH0、CH1 共用的 Windows driver 連線 = CH0、CH1 共用的 Windows driver 連線
copy_buffer_ copy_buffer_
+1 -1
View File
@@ -125,7 +125,7 @@ Debug 診斷會增加 log 與檢查成本,不應拿來判斷正式版本效能
- signal status、runtime FPS 與 channel event。 - signal status、runtime FPS 與 channel event。
- GPU conversion:BGRA8、RGB10A2、NV12。 - GPU conversion:BGRA8、RGB10A2、NV12。
- 公開詳細錯誤 API:`gvfg_get_channel_last_error_detail()`。 - 公開詳細錯誤 API:`gvfg_get_channel_last_error_detail()`。
- 內部 debug API:backend stats、register read/write。 - 內部 debug API:session stats、register read/write。
目前 FPGA 的 8-bit format register 仍可能回報舊 `YVYU` 值;SDK 只把它當作 legacy register identifier,對外格式與實際 DMA layout一律是 YUY2(`Y0 U0 Y1 V0`)。 目前 FPGA 的 8-bit format register 仍可能回報舊 `YVYU` 值;SDK 只把它當作 legacy register identifier,對外格式與實際 DMA layout一律是 YUY2(`Y0 U0 Y1 V0`)。