Restore GVFG features missing from GigabyteLib

Compared with a04bd61:

- Restore the existing gvfg_set_channel_video_format API and the Qt sample YUY2/Y210 output-format controls with the original dual-channel Y210 restriction.

- Restore gvfg_debug_read_register, gvfg_debug_write_register, and the original gvfg_debug_get_channel_backend_stats names and fields so the established internal API remains compatible.

- Implement the three missing operations through a small in-process driver extension using the existing register read/write requests; capture, audio, events, signal queries, copy, and zero-copy paths continue to use GvfgSdk.lib.

- Mark every fallback as a GIGABYTELIB GAP and add a focused gap report requesting official format-selection and diagnostic register APIs from the GigabyteLib owner.

- Remove empty legacy backend and giga_ioctl directories without restoring giga_ioctl.dll or a second capture backend.

Validation: git diff --cached --check passed. MSVC x64 Release and Debug gvfg.dll builds passed, the Release Qt sample rebuilt and linked successfully, dumpbin confirmed all original 32 exports are present, and the Release package contains gvfg.dll without giga_ioctl.dll or private GigabyteLib files. The actual register operations, output-format switching, capture, audio, zero-copy, hot-plug, dual-channel behavior, shutdown, MinGW, and hardware behavior were not runtime-tested.
This commit is contained in:
Mark.lin
2026-09-14 10:22:09 +08:00
parent a04bd611f9
commit 9bc38c4862
20 changed files with 413 additions and 57 deletions
+2
View File
@@ -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
+4 -1
View File
@@ -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
+10
View File
@@ -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.
+25 -14
View File
@@ -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
}
@@ -1,4 +1,5 @@
#include "gigabyte_capture_session.h"
#include "gigabyte_driver_extensions.h"
#include <algorithm>
#include <array>
@@ -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)
@@ -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);
@@ -0,0 +1,39 @@
#include "gigabyte_driver_extensions.h"
#include <winioctl.h>
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;
}
}
@@ -0,0 +1,13 @@
#pragma once
#include <windows.h>
#include <cstdint>
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);
}
+124 -15
View File
@@ -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<int>(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<int>(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<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)
{
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<size_t>(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<size_t>(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<ChannelErrorState, 2> channelErrors;
std::shared_ptr<gvfg::internal::GigabyteDeviceConnection> deviceConnection;
std::array<std::unique_ptr<gvfg_channel_session_t>, 2> channels;
std::array<uint32_t, 2> eventMasks{GVFG_EVENT_MASK_ALL, GVFG_EVENT_MASK_ALL};
int currentIndex = -1;
std::array<bool, 2> zeroCopyRequested{false, false};
std::array<gvfg_pixel_format_t, 2> 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);
}
}