diff --git a/GVFG_Qt_Sample/capture_controller.cpp b/GVFG_Qt_Sample/capture_controller.cpp index e1b82aa..433bcbb 100644 --- a/GVFG_Qt_Sample/capture_controller.cpp +++ b/GVFG_Qt_Sample/capture_controller.cpp @@ -39,11 +39,11 @@ namespace QString boolText(int value) { return value ? QStringLiteral("yes") : QStringLiteral("no"); } QString valueOrDash(uint64_t value) { return QString::number(static_cast(value)); } - QString captureStatusText(const gvfg_debug_channel_stats_t &stats, bool signalConnected) + QString captureStatusText(const gvfg_debug_backend_stats_t &stats, bool signalConnected) { - if (!stats.session_running) return QStringLiteral("stopped"); + if (!stats.backend_running) return QStringLiteral("stopped"); if (!signalConnected) return QStringLiteral("waiting_signal"); - if (!stats.session_capture_active) return QStringLiteral("paused"); + if (!stats.backend_capture_active) return QStringLiteral("paused"); return QStringLiteral("streaming"); } #endif @@ -98,11 +98,13 @@ CaptureController::~CaptureController() closeDevice(); } -void CaptureController::setChannelOptions(int channel, bool zeroCopy, bool audioEnabled) +void CaptureController::setChannelOptions(int channel, bool zeroCopy, + gvfg_pixel_format_t format, bool audioEnabled) { if (channel < GVFG_CHANNEL_0 || channel > GVFG_CHANNEL_1) return; channels_[channel].zeroCopy = zeroCopy; + channels_[channel].requestedFormat = format; channels_[channel].requestedAudio = channel == GVFG_CHANNEL_0 && audioEnabled; } @@ -229,7 +231,7 @@ bool CaptureController::openChannel(int channel) { ChannelRuntime &runtime = channels_[channel]; if (runtime.opened) - return true; + return applyOutputFormat(channel); if (handle_ == nullptr && !openDevice()) return false; @@ -247,6 +249,8 @@ bool CaptureController::openChannel(int channel) return false; } runtime.opened = true; + if (!applyOutputFormat(channel)) + return false; appendLog(QStringLiteral("Opened device index %1 CH%2 | mode=%3") .arg(selectedDeviceIndex_) @@ -256,6 +260,25 @@ bool CaptureController::openChannel(int channel) return true; } +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("gvfg_set_channel_video_format"), status, channel); + return false; + } + appendLog(QStringLiteral("CH%1 Output format | %2 (GigabyteLib extension)") + .arg(channel) + .arg(format == GVFG_PIXFMT_Y210 ? QStringLiteral("Y210") : QStringLiteral("YUY2"))); + return true; +} + void CaptureController::closeDevice() { if (runtimeStatusTimer_) @@ -633,8 +656,8 @@ void CaptureController::updateSignalStatus(bool queryHardware) sdkBytes = channel.audioReceivedBytes; appOutputBytes = channel.audioAcceptedBytes; } - gvfg_debug_channel_stats_t audioStats{}; - if (gvfg_debug_get_channel_stats(handle_, channelIndex, &audioStats) == GVFG_OK) + gvfg_debug_backend_stats_t audioStats{}; + if (gvfg_debug_get_channel_backend_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") .arg(channelIndex) @@ -679,23 +702,23 @@ void CaptureController::updateSignalStatus(bool queryHardware) } #if GVFG_INTERNAL_DIAGNOSTICS - gvfg_debug_channel_stats_t channelStats{}; - if (gvfg_debug_get_channel_stats(handle_, channelIndex, &channelStats) == GVFG_OK) + gvfg_debug_backend_stats_t channelStats{}; + if (gvfg_debug_get_channel_backend_stats(handle_, channelIndex, &channelStats) == GVFG_OK) { statusLines << QStringLiteral("CH%1 Capture | status=%2 dma_errors=%3 no_frame_waits=%4") .arg(channelIndex) .arg(captureStatusText(channelStats, signal.connected != 0)) - .arg(static_cast(channelStats.session_dma_errors)) - .arg(static_cast(channelStats.session_wait_timeouts)); - if (channel.haveDebugBaseline && channelStats.session_dma_errors > channel.lastDebugDmaErrors) + .arg(static_cast(channelStats.backend_dma_errors)) + .arg(static_cast(channelStats.backend_wait_timeouts)); + if (channel.haveDebugBaseline && channelStats.backend_dma_errors > channel.lastDebugDmaErrors) { appendLog(QStringLiteral("CH%1 ERROR DMA failures +%2, total=%3") .arg(channelIndex) - .arg(valueOrDash(channelStats.session_dma_errors - channel.lastDebugDmaErrors), - valueOrDash(channelStats.session_dma_errors))); + .arg(valueOrDash(channelStats.backend_dma_errors - channel.lastDebugDmaErrors), + valueOrDash(channelStats.backend_dma_errors))); diagnosticProblemDetected = true; } - channel.lastDebugDmaErrors = channelStats.session_dma_errors; + channel.lastDebugDmaErrors = channelStats.backend_dma_errors; channel.haveDebugBaseline = true; } #endif diff --git a/GVFG_Qt_Sample/capture_controller.h b/GVFG_Qt_Sample/capture_controller.h index 30c75b5..45ee7a5 100644 --- a/GVFG_Qt_Sample/capture_controller.h +++ b/GVFG_Qt_Sample/capture_controller.h @@ -29,7 +29,7 @@ public: ~CaptureController() override; void setSelectedDeviceIndex(int index) { selectedDeviceIndex_ = index; } - void setChannelOptions(int channel, bool zeroCopy, bool audioEnabled); + void setChannelOptions(int channel, bool zeroCopy, gvfg_pixel_format_t format, bool audioEnabled); void setChannelStatusVisible(int channel, bool visible); void setPreviewTarget(int channel, void *nativeWindow); void setPreviewVisible(int channel, bool visible); @@ -47,6 +47,7 @@ public slots: void refreshDevices(); bool openDevice(); void closeDevice(); + bool applyOutputFormat(int channel); void startCapture(int channel); void stopCapture(int channel); void stopAllCaptures(); @@ -70,6 +71,7 @@ private: bool opened = false; bool zeroCopy = false; bool requestedAudio = false; + gvfg_pixel_format_t requestedFormat = GVFG_PIXFMT_YUY2; void *previewTarget = nullptr; gvfg_preview_handle previewHandle = nullptr; std::atomic running{false}, stopRequested{false}, signalConnected{false}; diff --git a/GVFG_Qt_Sample/mainwindow.cpp b/GVFG_Qt_Sample/mainwindow.cpp index 47eac47..803aa27 100644 --- a/GVFG_Qt_Sample/mainwindow.cpp +++ b/GVFG_Qt_Sample/mainwindow.cpp @@ -4,6 +4,7 @@ #include "ui_mainwindow.h" #include +#include #include #include @@ -101,6 +102,15 @@ MainWindow::MainWindow(QWidget *parent) connect(ui_->ch0FullscreenButton, &QPushButton::clicked, this, [this] { showPreviewWindow(0, 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) { syncControllerOptions(GVFG_CHANNEL_0); if (controller_->deviceOpen()) controller_->updateSignalStatus(false); @@ -110,6 +120,7 @@ MainWindow::MainWindow(QWidget *parent) if (controller_->deviceOpen()) controller_->updateSignalStatus(false); }); + updateOutputFormatOptions(); updateUiState(); controller_->logStartupInfo(); controller_->refreshDevices(); @@ -138,8 +149,10 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::syncControllerOptions(int channel) { 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(); - controller_->setChannelOptions(channel, zeroCopy, audio); + controller_->setChannelOptions(channel, zeroCopy, + formatIndex == 1 ? GVFG_PIXFMT_Y210 : GVFG_PIXFMT_YUY2, audio); } void MainWindow::showPreviewWindow(int channel, bool fullscreen) @@ -158,6 +171,27 @@ void MainWindow::showPreviewWindow(int channel, bool fullscreen) : 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(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 (GigabyteLib extension)").arg(channel) + : QStringLiteral("Y210 is already selected by the other channel")); + } +} + void MainWindow::updateUiState() { const bool open = controller_->deviceOpen(); @@ -173,6 +207,7 @@ void MainWindow::updateUiState() ui_->ch1PreviewButton->setEnabled(running[1] && controller_->frameAvailable(1)); ui_->ch0FullscreenButton->setEnabled(ui_->ch0PreviewButton->isEnabled()); ui_->ch1FullscreenButton->setEnabled(ui_->ch1PreviewButton->isEnabled()); + ui_->ch0OutputFormatCombo->setEnabled(!running[0]); ui_->ch1OutputFormatCombo->setEnabled(!running[1]); ui_->ch0ZeroCopyCheckBox->setEnabled(!controller_->channelOpened(0)); ui_->ch1ZeroCopyCheckBox->setEnabled(!controller_->channelOpened(1)); ui_->ch0AudioCheckBox->setEnabled(!running[0]); diff --git a/GVFG_Qt_Sample/mainwindow.h b/GVFG_Qt_Sample/mainwindow.h index 10569cf..dc2cb92 100644 --- a/GVFG_Qt_Sample/mainwindow.h +++ b/GVFG_Qt_Sample/mainwindow.h @@ -27,6 +27,7 @@ protected: private: void syncControllerOptions(int channel); void showPreviewWindow(int channel, bool fullscreen); + void updateOutputFormatOptions(int changedChannel = -1); void updateUiState(); void appendLogLine(const QString &line); diff --git a/GVFG_Qt_Sample/mainwindow.ui b/GVFG_Qt_Sample/mainwindow.ui index 3138fc8..80d7378 100644 --- a/GVFG_Qt_Sample/mainwindow.ui +++ b/GVFG_Qt_Sample/mainwindow.ui @@ -63,6 +63,18 @@ + + Output format: + + + + + GigabyteLib extension: requested CH0 output format + YUY2 (8-bit 4:2:2) + Y210 (10-bit 4:2:2) + + + Must be selected before opening CH0 @@ -75,7 +87,7 @@ - + true @@ -91,7 +103,7 @@ - + @@ -133,6 +145,19 @@ + + Output format: + + + + + false + GigabyteLib extension: requested CH1 output format + YUY2 (8-bit 4:2:2) + Y210 (10-bit 4:2:2) + + + false @@ -145,7 +170,7 @@ - + diff --git a/GVFG_SDK/sdk/gvfg/CMakeLists.txt b/GVFG_SDK/sdk/gvfg/CMakeLists.txt index 2c21871..2caac9c 100644 --- a/GVFG_SDK/sdk/gvfg/CMakeLists.txt +++ b/GVFG_SDK/sdk/gvfg/CMakeLists.txt @@ -10,6 +10,8 @@ add_library(gvfg SHARED src/gigabyte/gigabyte_types.h src/gigabyte/gigabyte_capture_session.cpp src/gigabyte/gigabyte_capture_session.h + src/gigabyte/gigabyte_driver_extensions.cpp + src/gigabyte/gigabyte_driver_extensions.h src/gigabyte/gigabyte_device.cpp src/gigabyte/gigabyte_device.h src/gpu/d3d_conversion_pipeline.cpp diff --git a/GVFG_SDK/sdk/gvfg/gvfg.def b/GVFG_SDK/sdk/gvfg/gvfg.def index 131574e..9e8433f 100644 --- a/GVFG_SDK/sdk/gvfg/gvfg.def +++ b/GVFG_SDK/sdk/gvfg/gvfg.def @@ -9,6 +9,7 @@ EXPORTS gvfg_get_channel_event_mask gvfg_set_channel_zero_copy_enabled gvfg_get_channel_zero_copy_enabled + gvfg_set_channel_video_format gvfg_set_channel_audio_enabled gvfg_get_channel_audio_format gvfg_start_channel @@ -29,4 +30,6 @@ EXPORTS gvfg_pixel_format_name gvfg_strerror gvfg_get_channel_last_error_detail - gvfg_debug_get_channel_stats + gvfg_debug_get_channel_backend_stats + gvfg_debug_read_register + gvfg_debug_write_register diff --git a/GVFG_SDK/sdk/gvfg/include/gvfg_capture.h b/GVFG_SDK/sdk/gvfg/include/gvfg_capture.h index 1a23ac2..8f24286 100644 --- a/GVFG_SDK/sdk/gvfg/include/gvfg_capture.h +++ b/GVFG_SDK/sdk/gvfg/include/gvfg_capture.h @@ -340,6 +340,16 @@ extern "C" _In_ int channel_index, _Out_ int *out_enabled); + /* + * Select the hardware output format before capture starts. This capability + * currently uses an isolated driver extension because GvfgSdk.lib 1.0.0 + * does not expose an equivalent API. + */ + 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 * enabled; applications do not need to construct stream flag masks. diff --git a/GVFG_SDK/sdk/gvfg/include/gvfg_debug.h b/GVFG_SDK/sdk/gvfg/include/gvfg_debug.h index 27262b1..c7a985c 100644 --- a/GVFG_SDK/sdk/gvfg/include/gvfg_debug.h +++ b/GVFG_SDK/sdk/gvfg/include/gvfg_debug.h @@ -34,17 +34,17 @@ typedef struct uint64_t frames_returned; gvfg_debug_last_frame_info_t last_frame; - int session_state; - uint64_t session_frames_captured; - uint64_t session_frames_delivered; - uint64_t session_dma_errors; - uint64_t session_interrupt_count; - uint64_t session_wait_timeouts; + int backend_state; + uint64_t backend_frames_captured; + uint64_t backend_frames_delivered; + uint64_t backend_dma_errors; + uint64_t backend_interrupt_count; + uint64_t backend_wait_timeouts; - int session_running; - int session_capture_active; - uint64_t session_latest_sequence; - uint64_t session_delivered_sequence; + int backend_running; + int backend_capture_active; + uint64_t backend_latest_sequence; + uint64_t backend_delivered_sequence; uint64_t audio_dma_event_wakes; uint64_t extra_audio_event_wakes; uint64_t audio_frames_from_driver; @@ -55,18 +55,29 @@ typedef struct double get_frame_timing_average_us; double get_frame_timing_max300_us; double get_frame_timing_max_us; -} gvfg_debug_channel_stats_t; +} gvfg_debug_backend_stats_t; /* - * Query driver-neutral internal session counters. + * Query driver-neutral internal backend counters. * * This exposes implementation-level counters for internal tools only. Customer * applications should use gvfg_get_channel_runtime_info() instead. */ -GVFG_API gvfg_status_t gvfg_debug_get_channel_stats( +GVFG_API gvfg_status_t gvfg_debug_get_channel_backend_stats( _In_ gvfg_handle handle, _In_ int channel_index, - _Out_ gvfg_debug_channel_stats_t *out_stats); + _Out_ gvfg_debug_backend_stats_t *out_stats); + +/* GIGABYTELIB GAP: GvfgSdk.lib 1.0.0 has no register-access API. */ +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 } diff --git a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp index 8cf997b..b8cc8a3 100644 --- a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp +++ b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.cpp @@ -1,4 +1,5 @@ #include "gigabyte_capture_session.h" +#include "gigabyte_driver_extensions.h" #include #include @@ -184,6 +185,24 @@ gigabyte_status_t GigabyteCaptureSession::set_audio_enabled(bool enabled) return GIGABYTE_OK; } +gigabyte_status_t GigabyteCaptureSession::set_video_format(gigabyte_pixel_format_t format) +{ + if (format != GIGABYTE_PIXFMT_YUY2 && format != GIGABYTE_PIXFMT_Y210) + return reject(GIGABYTE_EINVAL, "video format is invalid"); + if (running_) + return reject(GIGABYTE_ESTATE, "video format cannot change while capture is running"); + const gigabyte_status_t openStatus = ensure_vendor_channel_open(); + if (openStatus != GIGABYTE_OK) + return openStatus; + + constexpr uint32_t kVideoOutputFormatRegister = 0x080; + if (!gigabyte_write_register(device_handle_, kVideoOutputFormatRegister, + format == GIGABYTE_PIXFMT_Y210 ? 1u : 0u)) + return reject(GIGABYTE_EIO, + "GigabyteLib gap: driver extension failed to set the output format register"); + return GIGABYTE_OK; +} + gigabyte_status_t GigabyteCaptureSession::refresh_video_info() const { if (!context_) @@ -571,6 +590,28 @@ void GigabyteCaptureSession::get_debug_stats( outDebugState.get_frame_timing_max_us = get_frame_timing_lifetime_max_us_; } +gigabyte_status_t GigabyteCaptureSession::debug_read_register(uint32_t offset, uint32_t &outValue) const +{ + const gigabyte_status_t openStatus = ensure_vendor_channel_open(); + if (openStatus != GIGABYTE_OK) + return openStatus; + if (!gigabyte_read_register(device_handle_, offset, outValue)) + return reject(GIGABYTE_EIO, + "GigabyteLib gap: driver extension register read failed"); + return GIGABYTE_OK; +} + +gigabyte_status_t GigabyteCaptureSession::debug_write_register(uint32_t offset, uint32_t value) const +{ + const gigabyte_status_t openStatus = ensure_vendor_channel_open(); + if (openStatus != GIGABYTE_OK) + return openStatus; + if (!gigabyte_write_register(device_handle_, offset, value)) + return reject(GIGABYTE_EIO, + "GigabyteLib gap: driver extension register write failed"); + return GIGABYTE_OK; +} + gigabyte_status_t GigabyteCaptureSession::from_vendor(GVFG_HRESULT result, const char *operation) const { if (result == GVFG_HRESULT_OK) diff --git a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.h b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.h index 7bd2d34..dfc52bd 100644 --- a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.h +++ b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_capture_session.h @@ -39,6 +39,7 @@ namespace gvfg::internal gigabyte_status_t set_zero_copy_enabled(bool enabled); bool zero_copy_enabled() const { return zero_copy_enabled_; } gigabyte_status_t set_audio_enabled(bool enabled); + gigabyte_status_t set_video_format(gigabyte_pixel_format_t format); gigabyte_status_t get_signal_status(gigabyte_signal_status_t &out) const; gigabyte_status_t get_audio_format(gigabyte_audio_format_t &out) const; gigabyte_status_t set_event_callback(gigabyte_event_callback_t callback, void *user, uint32_t eventMask); @@ -51,6 +52,8 @@ namespace gvfg::internal gigabyte_status_t release_frame(const gigabyte_frame_t &frame); void get_debug_stats(gigabyte_stream_stats_t &outStats, uint64_t &outWaitTimeouts, gigabyte_debug_state_t &outDebugState) const; + gigabyte_status_t debug_read_register(uint32_t offset, uint32_t &outValue) const; + gigabyte_status_t debug_write_register(uint32_t offset, uint32_t value) const; private: gigabyte_status_t open_device(const GigabyteDevice &device); diff --git a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_driver_extensions.cpp b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_driver_extensions.cpp new file mode 100644 index 0000000..32ce0f4 --- /dev/null +++ b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_driver_extensions.cpp @@ -0,0 +1,39 @@ +#include "gigabyte_driver_extensions.h" + +#include + +namespace +{ + constexpr DWORD kWriteRegister = CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS); + constexpr DWORD kReadRegister = CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS); + + struct RegisterAccess + { + ULONG offset; + ULONG value; + }; +} + +namespace gvfg::internal +{ + bool gigabyte_read_register(HANDLE device, uint32_t offset, uint32_t &value) + { + RegisterAccess request{offset, 0}; + DWORD returned = 0; + if (!DeviceIoControl(device, kReadRegister, + &request, sizeof(request), &request, sizeof(request), + &returned, nullptr)) + return false; + value = request.value; + return true; + } + + bool gigabyte_write_register(HANDLE device, uint32_t offset, uint32_t value) + { + RegisterAccess request{offset, value}; + DWORD returned = 0; + return DeviceIoControl(device, kWriteRegister, + &request, sizeof(request), nullptr, 0, + &returned, nullptr) != FALSE; + } +} diff --git a/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_driver_extensions.h b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_driver_extensions.h new file mode 100644 index 0000000..0e57b8d --- /dev/null +++ b/GVFG_SDK/sdk/gvfg/src/gigabyte/gigabyte_driver_extensions.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +namespace gvfg::internal +{ + // GIGABYTELIB GAP: GvfgSdk.lib 1.0.0 does not expose register access or + // output-format selection. Keep these driver extensions isolated here so + // they can be deleted when equivalent Gvfg* APIs are supplied. + bool gigabyte_read_register(HANDLE device, uint32_t offset, uint32_t &value); + bool gigabyte_write_register(HANDLE device, uint32_t offset, uint32_t value); +} diff --git a/GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp b/GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp index 8e5e824..029140d 100644 --- a/GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp +++ b/GVFG_SDK/sdk/gvfg/src/gvfg_capture.cpp @@ -593,7 +593,7 @@ struct gvfg_channel_session_t return GVFG_OK; } - gvfg_status_t getDebugStats(gvfg_debug_channel_stats_t &out) + gvfg_status_t getDebugStats(gvfg_debug_backend_stats_t &out) { std::memset(&out, 0, sizeof(out)); out.sdk_running = running.load(std::memory_order_relaxed) ? 1 : 0; @@ -623,16 +623,16 @@ struct gvfg_channel_session_t gigabyte_debug_state_t debugState{}; uint64_t waitTimeouts = 0; session->get_debug_stats(stats, waitTimeouts, debugState); - out.session_state = static_cast(stats.state); - out.session_frames_captured = stats.frames_captured; - out.session_frames_delivered = stats.frames_delivered; - out.session_dma_errors = stats.dma_errors; - out.session_interrupt_count = stats.interrupt_count; - out.session_wait_timeouts = waitTimeouts; - out.session_running = debugState.running; - out.session_capture_active = debugState.capture_active; - out.session_latest_sequence = debugState.latest_sequence; - out.session_delivered_sequence = debugState.delivered_sequence; + out.backend_state = static_cast(stats.state); + out.backend_frames_captured = stats.frames_captured; + out.backend_frames_delivered = stats.frames_delivered; + out.backend_dma_errors = stats.dma_errors; + out.backend_interrupt_count = stats.interrupt_count; + out.backend_wait_timeouts = waitTimeouts; + out.backend_running = debugState.running; + out.backend_capture_active = debugState.capture_active; + out.backend_latest_sequence = debugState.latest_sequence; + out.backend_delivered_sequence = debugState.delivered_sequence; out.audio_dma_event_wakes = debugState.audio_dma_event_wakes; out.extra_audio_event_wakes = debugState.extra_audio_event_wakes; out.audio_frames_from_driver = debugState.audio_frames_from_driver; @@ -647,6 +647,28 @@ struct gvfg_channel_session_t return GVFG_OK; } + gvfg_status_t debugReadRegister(uint32_t offset, uint32_t &outValue) + { + if (!session) + return reject(GVFG_ESTATE, "debug register read rejected: channel is not open"); + return map_status(session->debug_read_register(offset, outValue)); + } + + gvfg_status_t setVideoFormat(gvfg_pixel_format_t format) + { + if (!session) + return reject(GVFG_ESTATE, "gvfg_set_channel_video_format rejected: channel is not open"); + + gigabyte_pixel_format_t nativeFormat = GIGABYTE_PIXFMT_UNKNOWN; + if (format == GVFG_PIXFMT_YUY2) + nativeFormat = GIGABYTE_PIXFMT_YUY2; + else if (format == GVFG_PIXFMT_Y210) + nativeFormat = GIGABYTE_PIXFMT_Y210; + else + return reject(GVFG_EINVAL, "gvfg_set_channel_video_format rejected: pixel format is invalid"); + return map_status(session->set_video_format(nativeFormat)); + } + gvfg_status_t setAudioEnabled(bool enabled) { if (!session) @@ -660,6 +682,13 @@ struct gvfg_channel_session_t return GVFG_OK; } + gvfg_status_t debugWriteRegister(uint32_t offset, uint32_t value) + { + if (!session) + return reject(GVFG_ESTATE, "debug register write rejected: channel is not open"); + return map_status(session->debug_write_register(offset, value)); + } + gvfg_status_t getAudioFormat(gvfg_audio_format_t &out) { std::memset(&out, 0, sizeof(out)); @@ -846,6 +875,13 @@ struct gvfg_handle_t 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, char *outMessage, uint32_t outMessageSize) const @@ -866,6 +902,13 @@ struct gvfg_handle_t return channels[static_cast(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) { if (channelIndex != GVFG_CHANNEL_0 && channelIndex != GVFG_CHANNEL_1) @@ -940,6 +983,28 @@ struct gvfg_handle_t 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 other = channelIndex == GVFG_CHANNEL_0 ? GVFG_CHANNEL_1 : GVFG_CHANNEL_0; + if (format == GVFG_PIXFMT_Y210 && + requestedFormats[static_cast(other)] == 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(channelIndex)] = format; + return status; + } + gvfg_status_t stopAll() { gvfg_status_t result = GVFG_OK; @@ -954,12 +1019,29 @@ struct gvfg_handle_t 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 channelErrors; std::shared_ptr deviceConnection; std::array, 2> channels; std::array eventMasks{GVFG_EVENT_MASK_ALL, GVFG_EVENT_MASK_ALL}; int currentIndex = -1; std::array zeroCopyRequested{false, false}; + std::array requestedFormats{GVFG_PIXFMT_YUY2, GVFG_PIXFMT_YUY2}; }; extern "C" @@ -1080,6 +1162,15 @@ extern "C" "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, int channel_index, int enabled) @@ -1297,9 +1388,9 @@ extern "C" return handle->copyChannelError(channel_index, out_message, out_message_size); } - gvfg_status_t gvfg_debug_get_channel_stats(gvfg_handle handle, - int channel_index, - gvfg_debug_channel_stats_t *out_stats) + gvfg_status_t gvfg_debug_get_channel_backend_stats(gvfg_handle handle, + int channel_index, + gvfg_debug_backend_stats_t *out_stats) { if (!handle || !out_stats) return GVFG_EINVAL; @@ -1307,7 +1398,7 @@ extern "C" gvfg_channel_session_t *channel = handle->findChannel(channel_index); if (!channel) return GVFG_ESTATE; - gvfg_debug_channel_stats_t stats{}; + gvfg_debug_backend_stats_t stats{}; const gvfg_status_t status = channel->getDebugStats(stats); if (status != GVFG_OK) return status; @@ -1316,4 +1407,22 @@ extern "C" 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); + } + } diff --git a/README.md b/README.md index a209fa5..1661936 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Qt Sample 的 source boundary: 客戶使用指南在 `docs/GVFG_CUSTOMER_API.md`,完整函式與結構參考在 `docs/GVFG_CUSTOMER_API_REFERENCE.md`。內部架構、package 切分、threading、frame ownership 說明在 `docs/GVFG_INTERNAL_NOTES.md`。 +主管 library 尚缺少的 API 與目前暫時補法整理在 `docs/GIGABYTELIB_GAPS.md`。 ## Build diff --git a/docs/GIGABYTELIB_GAPS.md b/docs/GIGABYTELIB_GAPS.md new file mode 100644 index 0000000..96b5a2f --- /dev/null +++ b/docs/GIGABYTELIB_GAPS.md @@ -0,0 +1,22 @@ +# GigabyteLib 1.0.0 integration gaps + +Capture, audio, events, signal information, copy mode, and zero-copy mode use +the supervisor-provided `GvfgSdk.lib` API directly. + +## Action required from the GigabyteLib owner + +The following existing GVFG capabilities are not exposed by `GvfgSdk.lib 1.0.0`: + +| GVFG capability | Current temporary implementation | Requested GigabyteLib API | +|---|---|---| +| Select YUY2 or Y210 output | Write global register `0x080` through the isolated driver extension | Add a channel-aware `GvfgSetVideoFormat` or equivalent | +| Read a diagnostic register | Driver read-register request in `gigabyte_driver_extensions.cpp` | Add a supported diagnostic register-read API | +| Write a diagnostic register | Driver write-register request in `gigabyte_driver_extensions.cpp` | Add a supported diagnostic register-write API | + +These are marked `GIGABYTELIB GAP` in source. They intentionally do not use +the removed `giga_ioctl.dll`; the minimal fallback is compiled into `gvfg.dll`. +Once official `Gvfg*` functions exist, replace the three extension calls and +delete `gigabyte_driver_extensions.*`. + +The library owner should also confirm whether output-format register `0x080` +is global or channel-specific and whether CH0 and CH1 may both select Y210. diff --git a/docs/GVFG_CUSTOMER_API.md b/docs/GVFG_CUSTOMER_API.md index a7064b8..899cd61 100644 --- a/docs/GVFG_CUSTOMER_API.md +++ b/docs/GVFG_CUSTOMER_API.md @@ -231,8 +231,8 @@ Zero-copy mode 的 driver lifecycle 由 SDK 管理:open 時 enable,每次成 成功 read 後,不論 PCM 是送往播放、錄音或被丟棄,都必須正好 release 一次。 -Video format 由 `GvfgGetVideoInfo()` 回報的原生輸入格式決定。GigabyteLib 沒有 -輸出格式切換 API,因此 GVFG 不提供格式 setter。 +`gvfg_set_channel_video_format()` 可在 stream 尚未開始或已 stop 時選擇 YUY2/Y210。 +目前 GigabyteLib 1.0.0 沒有對應 API,因此此功能由隔離的 driver extension 暫時補足。 ### 查詢 diff --git a/docs/GVFG_CUSTOMER_API_REFERENCE.md b/docs/GVFG_CUSTOMER_API_REFERENCE.md index e317655..a1a7f95 100644 --- a/docs/GVFG_CUSTOMER_API_REFERENCE.md +++ b/docs/GVFG_CUSTOMER_API_REFERENCE.md @@ -263,7 +263,21 @@ gvfg_status_t gvfg_get_channel_zero_copy_enabled(gvfg_handle handle, int channel 呼叫 `gvfg_release_channel_frame()`,且每個 channel 同時最多持有一張 frame。 - SDK 在 open 時 enable driver zero-copy,在 destroy/close 前 disable。 -### 1.19 Audio capture selection and frame ownership +### 1.19 `gvfg_set_channel_video_format` + +```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`。 +- Channel 必須已 open,且 capture 必須尚未 start 或已 stop。 +- 目前透過隔離的 driver extension 寫入 output-format register;這是 + `GvfgSdk.lib 1.0.0` 尚未提供的功能。 +- 同一裝置 CH0、CH1 不可同時設定 Y210。 + +### 1.20 Audio capture selection and frame ownership ```c gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle, diff --git a/docs/GVFG_INTERNAL_NOTES.md b/docs/GVFG_INTERNAL_NOTES.md index b57d5f7..26d57d4 100644 --- a/docs/GVFG_INTERNAL_NOTES.md +++ b/docs/GVFG_INTERNAL_NOTES.md @@ -122,8 +122,10 @@ x64 `gvfg_frame_t` ABI 已在 `gvfg_capture.cpp` 以 static assertions 固定為 ## GigabyteLib requirement -GVFG 不再保存或操作 private IOCTL、register offset 或 DMA request layout。 -Driver ABI 相容性由主管提供的 `GvfgSdk.lib` 負責。 +Capture、audio、event 與 frame ownership 的 driver ABI 由主管提供的 +`GvfgSdk.lib` 負責。例外只有 library 1.0.0 尚未提供的 output-format selection +與 diagnostic register R/W;它們集中在 `gigabyte_driver_extensions.*`,不得擴大 +成第二套 capture backend。待主管補上正式 `Gvfg*` API 後應刪除此 extension。 目前原生格式: @@ -159,7 +161,7 @@ non-blocking、有限 timeout 與 infinite wait;stop 透過 `eventCv` 喚醒 w `gvfg_debug.h` 僅供內部工具,包含: -- `gvfg_debug_get_channel_stats()`:指定 channel 的 facade/backend state、 +- `gvfg_debug_get_channel_backend_stats()`:指定 channel 的 facade/backend state、 captured/delivered frame、DMA error、IRQ、timeout、sequence 與 GetFrame timing。 客戶診斷使用 `gvfg_get_channel_signal_status()`、`gvfg_get_channel_runtime_info()`、event、 diff --git a/docs/INTERNAL_BUILD_GUIDE.md b/docs/INTERNAL_BUILD_GUIDE.md index 8e74dec..c0db91e 100644 --- a/docs/INTERNAL_BUILD_GUIDE.md +++ b/docs/INTERNAL_BUILD_GUIDE.md @@ -125,7 +125,7 @@ Debug 診斷會增加 log 與檢查成本,不應拿來判斷正式版本效能 - signal status、runtime FPS 與 channel event。 - GPU conversion:BGRA8、RGB10A2、NV12。 - 公開詳細錯誤 API:`gvfg_get_channel_last_error_detail()`。 -- 內部 debug API:session stats、register read/write。 +- 內部 debug API:backend stats、register read/write。 目前 FPGA 的 8-bit format register 仍可能回報舊 `YVYU` 值;SDK 只把它當作 legacy register identifier,對外格式與實際 DMA layout一律是 YUY2(`Y0 U0 Y1 V0`)。