Initial standalone GVFG SDK
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
build*/
|
||||
out/
|
||||
.vs/
|
||||
.vscode/
|
||||
.qtcreator/
|
||||
CMakeUserPresets.json
|
||||
*.user
|
||||
*.suo
|
||||
*.obj
|
||||
*.pdb
|
||||
*.ilk
|
||||
*.exp
|
||||
*.lib
|
||||
*.dll
|
||||
*.exe
|
||||
@@ -0,0 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(gvfg_standalone VERSION 0.1.0 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(GVFG_SDK_VERSION "${PROJECT_VERSION}" CACHE STRING "GVFG SDK version")
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
||||
|
||||
option(BUILD_GVFG_SAMPLES "Build GVFG customer samples" ON)
|
||||
option(GVFG_XDMA_DEBUG_LOG "Enable verbose XDMA flow debug logging in GVFG internal XDMA backend" OFF)
|
||||
|
||||
if (NOT WIN32)
|
||||
message(FATAL_ERROR "GVFG currently supports Windows only.")
|
||||
endif()
|
||||
|
||||
add_subdirectory(sdk/gvfg)
|
||||
|
||||
if (BUILD_GVFG_SAMPLES)
|
||||
add_subdirectory(samples/gvfg_qt_preview)
|
||||
endif()
|
||||
@@ -0,0 +1,55 @@
|
||||
# GVFG Standalone SDK
|
||||
|
||||
This is the standalone source tree for the GVFG capture SDK.
|
||||
|
||||
GVFG is the source of truth here. Other projects should consume GVFG through
|
||||
the exported public header, import library, and runtime DLL instead of compiling
|
||||
the GVFG source directly.
|
||||
|
||||
## Contents
|
||||
|
||||
- `sdk/gvfg`: GVFG public C API and internal XDMA backend.
|
||||
- `sdk/gdriver_shared/include`: shared driver ABI headers required by the backend.
|
||||
- `sdk/gcapture`: minimal shared render/logging code currently required by GVFG preview.
|
||||
- `samples/gvfg_qt_preview`: customer-facing Qt preview sample.
|
||||
- `docs`: API and integration notes.
|
||||
|
||||
## Build
|
||||
|
||||
Open this folder's `CMakeLists.txt` in Qt Creator with a Windows MSVC Qt kit, or
|
||||
configure from a Visual Studio developer shell.
|
||||
|
||||
Example:
|
||||
|
||||
```bat
|
||||
cmake -S . -B build -DBUILD_GVFG_SAMPLES=ON -DCMAKE_PREFIX_PATH=C:\Qt\6.10.2\msvc2022_64
|
||||
cmake --build build --target gvfg_qt_preview --config Release
|
||||
```
|
||||
|
||||
Useful CMake options:
|
||||
|
||||
```text
|
||||
BUILD_GVFG_SAMPLES=ON
|
||||
GVFG_XDMA_DEBUG_LOG=OFF
|
||||
```
|
||||
|
||||
Build outputs:
|
||||
|
||||
```text
|
||||
build/.../bin/gvfg.dll
|
||||
build/.../lib/gvfg.lib
|
||||
build/.../bin/gvfg_qt_preview.exe
|
||||
```
|
||||
|
||||
## Consumer Layout
|
||||
|
||||
Applications should consume the SDK with:
|
||||
|
||||
```text
|
||||
include/gvfg_capture.h
|
||||
lib/gvfg.lib
|
||||
bin/gvfg.dll
|
||||
```
|
||||
|
||||
The XDMA backend and driver ABI headers are implementation details and should not
|
||||
be included by customer applications.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
||||
# GVFG Direct SDK Plan
|
||||
|
||||
## Current Direction
|
||||
|
||||
GVFG Direct 目前改成使用獨立的 GVFG SDK:
|
||||
|
||||
- 對外 facade:`sdk/gvfg`
|
||||
- 低階 driver access:`sdk/gvfg/src/backend/xdma`
|
||||
- Viewer 整合:`apps/qt6_viewer` 的 `GVFG Direct`
|
||||
|
||||
GVFG 是客戶看到的 SDK/API 名稱。XDMA 只保留為底層 driver/backend 說明。
|
||||
|
||||
## Build Options
|
||||
|
||||
```text
|
||||
BUILD_GVFG_SDK=ON
|
||||
BUILD_GVFG_SAMPLES=ON
|
||||
GVFG_XDMA_DEBUG_LOG=ON
|
||||
```
|
||||
|
||||
`BUILD_GVFG_SDK` 會 build `gvfg.dll`,並把 `gvfg.dll` 複製到 viewer 輸出資料夾。XDMA backend 會編進 `gvfg.dll`,不再另外產生 backend DLL。
|
||||
|
||||
`GVFG_XDMA_DEBUG_LOG` 會開啟底層 XDMA flow log。
|
||||
|
||||
## Active Components
|
||||
|
||||
- `sdk/gvfg`: customer-facing GVFG capture SDK。
|
||||
- `sdk/gvfg/src/backend/xdma`: internal low-level XDMA driver access。
|
||||
- `apps/qt6_viewer`: viewer demo,`GVFG Direct` 透過 GVFG SDK 啟動。
|
||||
- `samples/gvfg_qt_preview`: 最小客戶 sample。
|
||||
|
||||
## Customer API
|
||||
|
||||
請看:
|
||||
|
||||
```text
|
||||
docs/GVFG_CUSTOMER_API.md
|
||||
```
|
||||
|
||||
## Removed Components
|
||||
|
||||
- old standalone XDMA probe app
|
||||
- KS capture session implementation
|
||||
- KS device enumerator implementation
|
||||
@@ -0,0 +1,54 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(gvfg_qt_preview LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
||||
|
||||
if (QT_VERSION_MAJOR GREATER_EQUAL 6)
|
||||
qt_add_executable(gvfg_qt_preview
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
mainwindow.h
|
||||
mainwindow.ui
|
||||
previewwindow.cpp
|
||||
previewwindow.h
|
||||
previewwindow.ui
|
||||
)
|
||||
else()
|
||||
add_executable(gvfg_qt_preview
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
mainwindow.h
|
||||
mainwindow.ui
|
||||
previewwindow.cpp
|
||||
previewwindow.h
|
||||
previewwindow.ui
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(gvfg_qt_preview PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
gvfg
|
||||
)
|
||||
|
||||
target_include_directories(gvfg_qt_preview PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/include
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(gvfg_qt_preview PRIVATE /utf-8)
|
||||
endif()
|
||||
|
||||
add_custom_command(TARGET gvfg_qt_preview POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_FILE:gvfg>
|
||||
$<TARGET_FILE_DIR:gvfg_qt_preview>
|
||||
)
|
||||
|
||||
set_target_properties(gvfg_qt_preview PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
MainWindow window;
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,459 @@
|
||||
#include "mainwindow.h"
|
||||
#include "previewwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QDateTime>
|
||||
#include <QMetaObject>
|
||||
#include <QTimer>
|
||||
|
||||
namespace
|
||||
{
|
||||
QString fpgaFieldText(bool valid, const QString &text)
|
||||
{
|
||||
return valid ? text : QStringLiteral("--");
|
||||
}
|
||||
|
||||
QString hex32(uint32_t value)
|
||||
{
|
||||
return QStringLiteral("0x") + QString::number(value, 16).rightJustified(8, QLatin1Char('0')).toUpper();
|
||||
}
|
||||
|
||||
QString eventTypeText(gvfg_event_type_t type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GVFG_EVENT_VIDEO_IRQ:
|
||||
return QStringLiteral("VIDEO_IRQ");
|
||||
case GVFG_EVENT_PLUG_IN:
|
||||
return QStringLiteral("PLUG_IN");
|
||||
case GVFG_EVENT_PLUG_OUT:
|
||||
return QStringLiteral("PLUG_OUT");
|
||||
case GVFG_EVENT_CAPTURE_PAUSED:
|
||||
return QStringLiteral("CAPTURE_PAUSED");
|
||||
case GVFG_EVENT_CAPTURE_RESUMED:
|
||||
return QStringLiteral("CAPTURE_RESUMED");
|
||||
default:
|
||||
return QStringLiteral("UNKNOWN");
|
||||
}
|
||||
}
|
||||
|
||||
QString fpgaRawLogLine(const gvfg_runtime_info_t &info)
|
||||
{
|
||||
const auto &fpga = info.input_signal.fpga;
|
||||
return QStringLiteral("fpga_raw\n"
|
||||
" valid_mask=%1\n"
|
||||
" resolution: width_valid=%2 width_raw=%3 height_valid=%4 height_raw=%5\n"
|
||||
" video_format: valid=%6 raw=%7 code=%8 name=%9\n"
|
||||
" frame_rate: valid=%10 raw=%11 code=%12 bits=%13 name=%14\n"
|
||||
" bit_depth: valid=%15 raw=%16 value=%17\n"
|
||||
" status: valid=%18 raw=%19 sdi_lock=%20 sdi_ddr=%21 hdmi_lock=%22 hdmi_ddr=%23")
|
||||
.arg(hex32(fpga.valid_mask))
|
||||
.arg(fpga.width_valid)
|
||||
.arg(fpga.width_raw)
|
||||
.arg(fpga.height_valid)
|
||||
.arg(fpga.height_raw)
|
||||
.arg(fpga.video_format_valid)
|
||||
.arg(hex32(fpga.video_format_raw))
|
||||
.arg(fpga.video_format_code)
|
||||
.arg(QString::fromLatin1(fpga.video_format))
|
||||
.arg(fpga.frame_rate_valid)
|
||||
.arg(hex32(fpga.frame_rate_raw))
|
||||
.arg(fpga.frame_rate_code)
|
||||
.arg(QString::fromLatin1(fpga.frame_rate_bits))
|
||||
.arg(QString::fromLatin1(fpga.frame_rate_name))
|
||||
.arg(fpga.bit_depth_valid)
|
||||
.arg(hex32(fpga.bit_depth_raw))
|
||||
.arg(fpga.bit_depth)
|
||||
.arg(fpga.status_valid)
|
||||
.arg(hex32(fpga.status_raw))
|
||||
.arg(fpga.sdi_locked)
|
||||
.arg(fpga.sdi_ddr_ok)
|
||||
.arg(fpga.hdmi_locked)
|
||||
.arg(fpga.hdmi_ddr_ok);
|
||||
}
|
||||
|
||||
QString fpgaRawStateKey(const gvfg_runtime_info_t &info)
|
||||
{
|
||||
const auto &fpga = info.input_signal.fpga;
|
||||
return QStringLiteral("%1|%2|%3|%4|%5|%6|%7|%8|%9|%10|%11|%12|%13|%14|%15|%16|%17|%18|%19|%20|%21|%22|%23")
|
||||
.arg(fpga.valid_mask)
|
||||
.arg(fpga.width_valid)
|
||||
.arg(fpga.width_raw)
|
||||
.arg(fpga.height_valid)
|
||||
.arg(fpga.height_raw)
|
||||
.arg(fpga.video_format_valid)
|
||||
.arg(fpga.video_format_raw)
|
||||
.arg(fpga.video_format_code)
|
||||
.arg(QString::fromLatin1(fpga.video_format))
|
||||
.arg(fpga.frame_rate_valid)
|
||||
.arg(fpga.frame_rate_raw)
|
||||
.arg(fpga.frame_rate_code)
|
||||
.arg(QString::fromLatin1(fpga.frame_rate_bits))
|
||||
.arg(QString::fromLatin1(fpga.frame_rate_name))
|
||||
.arg(fpga.bit_depth_valid)
|
||||
.arg(fpga.bit_depth_raw)
|
||||
.arg(fpga.bit_depth)
|
||||
.arg(fpga.status_valid)
|
||||
.arg(fpga.status_raw)
|
||||
.arg(fpga.sdi_locked)
|
||||
.arg(fpga.sdi_ddr_ok)
|
||||
.arg(fpga.hdmi_locked)
|
||||
.arg(fpga.hdmi_ddr_ok);
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QWidget(parent), ui_(new Ui::MainWindow)
|
||||
{
|
||||
ui_->setupUi(this);
|
||||
|
||||
previewWindow_ = new PreviewWindow();
|
||||
ui_->logEdit->setMaximumBlockCount(300);
|
||||
ui_->statusLabel->setWordWrap(true);
|
||||
signalStatusTimer_ = new QTimer(this);
|
||||
signalStatusTimer_->setInterval(1000);
|
||||
|
||||
connect(ui_->refreshButton, &QPushButton::clicked, this, [this]() { refreshDevices(); });
|
||||
connect(ui_->openButton, &QPushButton::clicked, this, [this]()
|
||||
{
|
||||
if (handle_)
|
||||
closeDevice();
|
||||
else
|
||||
openDevice();
|
||||
});
|
||||
connect(ui_->showPreviewButton, &QPushButton::clicked, this, [this]() { showPreviewWindow(); });
|
||||
connect(ui_->startButton, &QPushButton::clicked, this, [this]() { startCapture(); });
|
||||
connect(ui_->stopButton, &QPushButton::clicked, this, [this]() { stopCapture(); });
|
||||
connect(signalStatusTimer_, &QTimer::timeout, this, [this]() { updateSignalStatus(true); });
|
||||
|
||||
updateUiState();
|
||||
refreshDevices();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
closeDevice();
|
||||
delete previewWindow_;
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
closeDevice();
|
||||
if (previewWindow_)
|
||||
previewWindow_->closePreview();
|
||||
|
||||
QWidget::closeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::refreshDevices()
|
||||
{
|
||||
if (handle_)
|
||||
closeDevice();
|
||||
|
||||
ui_->deviceCombo->clear();
|
||||
devices_ = {};
|
||||
|
||||
const int count = gvfg_enumerate_devices(devices_.data(), GVFG_MAX_DEVICES);
|
||||
deviceCount_ = count > 0 ? count : 0;
|
||||
|
||||
for (int i = 0; i < deviceCount_; ++i)
|
||||
{
|
||||
const QString name = QString::fromUtf8(devices_[i].name);
|
||||
ui_->deviceCombo->addItem(name.isEmpty() ? QStringLiteral("GVFG Capture") : name, devices_[i].index);
|
||||
}
|
||||
|
||||
if (deviceCount_ <= 0)
|
||||
{
|
||||
ui_->deviceCombo->addItem(QStringLiteral("No GVFG device found"), -1);
|
||||
appendLog(QStringLiteral("No GVFG device found"));
|
||||
}
|
||||
else
|
||||
{
|
||||
appendLog(QStringLiteral("Found %1 XDMA device(s)").arg(deviceCount_));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showPreviewWindow()
|
||||
{
|
||||
previewWindow_->showPreview();
|
||||
|
||||
if (handle_ && !applyPreview())
|
||||
appendLog(QStringLiteral("Show Preview failed: unable to update preview window"));
|
||||
}
|
||||
|
||||
bool MainWindow::openDevice()
|
||||
{
|
||||
if (handle_)
|
||||
return true;
|
||||
|
||||
if (ui_->deviceCombo->currentData().toInt() < 0)
|
||||
{
|
||||
appendLog(QStringLiteral("Open skipped: no device selected"));
|
||||
return false;
|
||||
}
|
||||
|
||||
gvfg_status_t st = gvfg_create(&handle_);
|
||||
if (st != GVFG_OK || !handle_)
|
||||
{
|
||||
showError(QStringLiteral("gvfg_create"), st);
|
||||
handle_ = nullptr;
|
||||
updateUiState();
|
||||
return false;
|
||||
}
|
||||
|
||||
gvfg_set_callbacks(handle_, &MainWindow::onFrame, &MainWindow::onError, this);
|
||||
gvfg_set_event_callback(handle_, &MainWindow::onEvent, this, GVFG_EVENT_MASK_DEFAULT);
|
||||
|
||||
const int deviceIndex = ui_->deviceCombo->currentData().toInt();
|
||||
st = gvfg_open(handle_, deviceIndex);
|
||||
if (st != GVFG_OK)
|
||||
{
|
||||
showError(QStringLiteral("gvfg_open"), st);
|
||||
closeDevice();
|
||||
return false;
|
||||
}
|
||||
|
||||
lastSignalStatusText_.clear();
|
||||
lastFpgaRawStateKey_.clear();
|
||||
appendLog(QStringLiteral("Opened device index %1").arg(deviceIndex));
|
||||
appendLog(QStringLiteral("FPGA signal monitor active"));
|
||||
updateSignalStatus(true);
|
||||
signalStatusTimer_->start();
|
||||
updateUiState();
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::closeDevice()
|
||||
{
|
||||
stopCapture();
|
||||
|
||||
if (signalStatusTimer_)
|
||||
signalStatusTimer_->stop();
|
||||
|
||||
if (handle_)
|
||||
{
|
||||
gvfg_destroy(handle_);
|
||||
handle_ = nullptr;
|
||||
appendLog(QStringLiteral("Closed device"));
|
||||
}
|
||||
|
||||
ui_->statusLabel->setText(QStringLiteral("Idle"));
|
||||
lastSignalStatusText_.clear();
|
||||
lastFpgaRawStateKey_.clear();
|
||||
updateUiState();
|
||||
}
|
||||
|
||||
void MainWindow::startCapture()
|
||||
{
|
||||
if (captureRunning_)
|
||||
return;
|
||||
|
||||
if (!handle_ && !openDevice())
|
||||
return;
|
||||
|
||||
previewWindow_->showPreview();
|
||||
if (!applyPreview())
|
||||
return;
|
||||
|
||||
appendLog(QStringLiteral("FPGA signal before stream start"));
|
||||
updateSignalStatus(true);
|
||||
|
||||
const gvfg_status_t st = gvfg_start(handle_);
|
||||
if (st != GVFG_OK)
|
||||
{
|
||||
showError(QStringLiteral("gvfg_start"), st);
|
||||
updateSignalStatus(true);
|
||||
updateUiState();
|
||||
return;
|
||||
}
|
||||
|
||||
frameCount_ = 0;
|
||||
captureRunning_ = true;
|
||||
updateUiState();
|
||||
appendLog(QStringLiteral("Started capture"));
|
||||
updateSignalStatus(true);
|
||||
}
|
||||
|
||||
void MainWindow::stopCapture()
|
||||
{
|
||||
if (handle_ && captureRunning_)
|
||||
{
|
||||
gvfg_stop(handle_);
|
||||
captureRunning_ = false;
|
||||
appendLog(QStringLiteral("Stopped capture"));
|
||||
updateSignalStatus(true);
|
||||
}
|
||||
|
||||
updateUiState();
|
||||
}
|
||||
|
||||
bool MainWindow::applyPreview()
|
||||
{
|
||||
if (!handle_)
|
||||
return false;
|
||||
|
||||
gvfg_preview_desc_t preview{};
|
||||
preview.hwnd = previewWindow_->nativePreviewHandle();
|
||||
preview.enable_preview = 1;
|
||||
preview.swapchain_bitdepth = GVFG_PREVIEW_BITDEPTH_AUTO;
|
||||
|
||||
const gvfg_status_t st = gvfg_set_preview(handle_, &preview);
|
||||
if (st != GVFG_OK)
|
||||
{
|
||||
showError(QStringLiteral("gvfg_set_preview"), st);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::updateSignalStatus(bool writeLog)
|
||||
{
|
||||
if (!handle_)
|
||||
return;
|
||||
|
||||
gvfg_runtime_info_t info{};
|
||||
if (gvfg_get_runtime_info(handle_, &info) != GVFG_OK)
|
||||
return;
|
||||
|
||||
const auto &fpga = info.input_signal.fpga;
|
||||
const auto &delivered = info.delivered_frame;
|
||||
|
||||
const QString fpgaResolution = (fpga.width_valid && fpga.height_valid)
|
||||
? QStringLiteral("%1x%2").arg(fpga.width_raw).arg(fpga.height_raw)
|
||||
: QStringLiteral("--");
|
||||
const QString line0 = QStringLiteral("FPGA reported | signal=%1 fps=%2 format=%3 bitdepth=%4")
|
||||
.arg(fpgaResolution)
|
||||
.arg(fpgaFieldText(fpga.frame_rate_valid != 0,
|
||||
QStringLiteral("%1 (%2)")
|
||||
.arg(QString::fromLatin1(fpga.frame_rate_bits))
|
||||
.arg(QString::fromLatin1(fpga.frame_rate_name))))
|
||||
.arg(fpgaFieldText(fpga.video_format_valid != 0,
|
||||
QStringLiteral("%1 (%2)")
|
||||
.arg(fpga.video_format_code)
|
||||
.arg(QString::fromLatin1(fpga.video_format))))
|
||||
.arg(fpgaFieldText(fpga.bit_depth_valid != 0,
|
||||
QStringLiteral("%1").arg(fpga.bit_depth)));
|
||||
const QString line2 = QStringLiteral("FPGA status | SDI lock=%1 SDI DDR=%2 HDMI lock=%3 HDMI DDR=%4")
|
||||
.arg(fpgaFieldText(fpga.status_valid != 0, QString::number(fpga.sdi_locked)))
|
||||
.arg(fpgaFieldText(fpga.status_valid != 0, QString::number(fpga.sdi_ddr_ok)))
|
||||
.arg(fpgaFieldText(fpga.status_valid != 0, QString::number(fpga.hdmi_locked)))
|
||||
.arg(fpgaFieldText(fpga.status_valid != 0, QString::number(fpga.hdmi_ddr_ok)));
|
||||
const QString line3 = delivered.valid
|
||||
? QStringLiteral("Delivered frame | frame=%1x%2 format=%3 bitdepth=%4")
|
||||
.arg(delivered.width)
|
||||
.arg(delivered.height)
|
||||
.arg(QString::fromUtf8(delivered.pixel_format))
|
||||
.arg(delivered.bit_depth)
|
||||
: QStringLiteral("Delivered frame | --");
|
||||
const QString line4 = QStringLiteral("App runtime | capture=%1 fps delivered=%2")
|
||||
.arg(info.capture_fps > 0.0 ? QString::number(info.capture_fps, 'f', 2)
|
||||
: QStringLiteral("--"))
|
||||
.arg(static_cast<qulonglong>(info.delivered_frames));
|
||||
|
||||
const QString statusText = line0 + QLatin1Char('\n') + line2 + QLatin1Char('\n') + line3 + QLatin1Char('\n') + line4;
|
||||
if (lastSignalStatusText_ != statusText)
|
||||
{
|
||||
ui_->statusLabel->setText(statusText);
|
||||
lastSignalStatusText_ = statusText;
|
||||
}
|
||||
|
||||
const QString stateKey = fpgaRawStateKey(info);
|
||||
if (writeLog && lastFpgaRawStateKey_ != stateKey)
|
||||
{
|
||||
appendLog(fpgaRawLogLine(info));
|
||||
lastFpgaRawStateKey_ = stateKey;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateUiState()
|
||||
{
|
||||
const bool deviceOpen = handle_ != nullptr;
|
||||
ui_->openButton->setText(deviceOpen ? QStringLiteral("Close Device") : QStringLiteral("Open Device"));
|
||||
ui_->openButton->setEnabled(!captureRunning_);
|
||||
ui_->startButton->setEnabled(deviceOpen && !captureRunning_);
|
||||
ui_->stopButton->setEnabled(captureRunning_);
|
||||
ui_->refreshButton->setEnabled(!deviceOpen && !captureRunning_);
|
||||
ui_->deviceCombo->setEnabled(!deviceOpen && !captureRunning_);
|
||||
}
|
||||
|
||||
void MainWindow::showError(const QString &apiName, gvfg_status_t status)
|
||||
{
|
||||
appendLog(QStringLiteral("%1 failed: %2").arg(apiName, QString::fromUtf8(gvfg_strerror(status))));
|
||||
}
|
||||
|
||||
void MainWindow::appendLog(const QString &message)
|
||||
{
|
||||
const QString line = QStringLiteral("[%1] %2")
|
||||
.arg(QDateTime::currentDateTime().toString(QStringLiteral("HH:mm:ss.zzz")))
|
||||
.arg(message);
|
||||
ui_->logEdit->appendPlainText(line);
|
||||
}
|
||||
|
||||
void MainWindow::onFrame(const gvfg_frame_t *frame, void *user)
|
||||
{
|
||||
MainWindow *self = static_cast<MainWindow *>(user);
|
||||
if (!self || !frame)
|
||||
return;
|
||||
|
||||
const uint64_t count = ++self->frameCount_;
|
||||
if (count <= 5 || (count % 60) == 0)
|
||||
{
|
||||
const int width = frame->width;
|
||||
const int height = frame->height;
|
||||
const uint64_t frameId = frame->frame_id;
|
||||
QMetaObject::invokeMethod(self,
|
||||
[self, count, frameId, width, height]()
|
||||
{
|
||||
self->appendLog(QStringLiteral("callback #%1 source id=%2 %3x%4")
|
||||
.arg(static_cast<qulonglong>(count))
|
||||
.arg(static_cast<qulonglong>(frameId))
|
||||
.arg(width)
|
||||
.arg(height));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onEvent(const gvfg_event_t *event, void *user)
|
||||
{
|
||||
MainWindow *self = static_cast<MainWindow *>(user);
|
||||
if (!self || !event)
|
||||
return;
|
||||
|
||||
const QString type = eventTypeText(event->type);
|
||||
const uint32_t irqBit = event->irq_bit;
|
||||
const uint32_t irqMask = event->irq_mask;
|
||||
const uint64_t timestampNs = event->timestamp_ns;
|
||||
QMetaObject::invokeMethod(self,
|
||||
[self, type, irqBit, irqMask, timestampNs]()
|
||||
{
|
||||
self->appendLog(QStringLiteral("event %1 irq=%2 mask=%3 ts=%4")
|
||||
.arg(type)
|
||||
.arg(irqBit)
|
||||
.arg(hex32(irqMask))
|
||||
.arg(static_cast<qulonglong>(timestampNs)));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void MainWindow::onError(gvfg_status_t status, const char *message, void *user)
|
||||
{
|
||||
MainWindow *self = static_cast<MainWindow *>(user);
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
const QString text = message && message[0]
|
||||
? QString::fromUtf8(message)
|
||||
: QString::fromUtf8(gvfg_strerror(status));
|
||||
|
||||
QMetaObject::invokeMethod(self,
|
||||
[self, status, text]()
|
||||
{
|
||||
self->appendLog(QStringLiteral("message %1: %2")
|
||||
.arg(static_cast<int>(status))
|
||||
.arg(text));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <gvfg_capture.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
class QCloseEvent;
|
||||
class PreviewWindow;
|
||||
class QTimer;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow final : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
void refreshDevices();
|
||||
void showPreviewWindow();
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
void startCapture();
|
||||
void stopCapture();
|
||||
bool applyPreview();
|
||||
void updateSignalStatus(bool writeLog);
|
||||
void updateUiState();
|
||||
void showError(const QString &apiName, gvfg_status_t status);
|
||||
void appendLog(const QString &message);
|
||||
|
||||
static void onFrame(const gvfg_frame_t *frame, void *user);
|
||||
static void onEvent(const gvfg_event_t *event, void *user);
|
||||
static void onError(gvfg_status_t status, const char *message, void *user);
|
||||
|
||||
Ui::MainWindow *ui_ = nullptr;
|
||||
PreviewWindow *previewWindow_ = nullptr;
|
||||
std::array<gvfg_device_info_t, GVFG_MAX_DEVICES> devices_{};
|
||||
int deviceCount_ = 0;
|
||||
gvfg_handle handle_ = nullptr;
|
||||
bool captureRunning_ = false;
|
||||
std::atomic<uint64_t> frameCount_{0};
|
||||
QTimer *signalStatusTimer_ = nullptr;
|
||||
QString lastSignalStatusText_;
|
||||
QString lastFpgaRawStateKey_;
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QWidget" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>960</width>
|
||||
<height>640</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>GVFG Qt Preview Sample</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="topLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="deviceLabel">
|
||||
<property name="text">
|
||||
<string>Device:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="deviceCombo"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="refreshButton">
|
||||
<property name="text">
|
||||
<string>Refresh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="openButton">
|
||||
<property name="text">
|
||||
<string>Open Device</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="showPreviewButton">
|
||||
<property name="text">
|
||||
<string>Show Preview</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="startButton">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="stopButton">
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="text">
|
||||
<string>Idle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPlainTextEdit" name="logEdit">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "previewwindow.h"
|
||||
#include "ui_previewwindow.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
|
||||
PreviewWindow::PreviewWindow(QWidget *parent)
|
||||
: QWidget(parent), ui_(new Ui::PreviewWindow)
|
||||
{
|
||||
ui_->setupUi(this);
|
||||
ui_->previewHost->setAttribute(Qt::WA_NativeWindow, true);
|
||||
ui_->previewHost->setStyleSheet(QStringLiteral("background: black;"));
|
||||
}
|
||||
|
||||
PreviewWindow::~PreviewWindow()
|
||||
{
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void *PreviewWindow::nativePreviewHandle() const
|
||||
{
|
||||
return reinterpret_cast<void *>(ui_->previewHost->winId());
|
||||
}
|
||||
|
||||
void PreviewWindow::closePreview()
|
||||
{
|
||||
closeAllowed_ = true;
|
||||
close();
|
||||
}
|
||||
|
||||
void PreviewWindow::showPreview()
|
||||
{
|
||||
show();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void PreviewWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (closeAllowed_)
|
||||
{
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
hide();
|
||||
event->ignore();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui
|
||||
{
|
||||
class PreviewWindow;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class PreviewWindow final : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PreviewWindow(QWidget *parent = nullptr);
|
||||
~PreviewWindow() override;
|
||||
|
||||
void *nativePreviewHandle() const;
|
||||
void closePreview();
|
||||
|
||||
public slots:
|
||||
void showPreview();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
Ui::PreviewWindow *ui_ = nullptr;
|
||||
bool closeAllowed_ = false;
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PreviewWindow</class>
|
||||
<widget class="QWidget" name="PreviewWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>960</width>
|
||||
<height>540</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>GVFG Preview</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="previewHost" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>640</width>
|
||||
<height>360</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
gcapture audio helper API
|
||||
|
||||
Normal recording users should use:
|
||||
- gcap_audio_device_count()
|
||||
- gcap_audio_enum_devices()
|
||||
- gcap_set_recording_audio_device() from gcapture.h
|
||||
|
||||
The low-level gcap_start_audio_capture()/gcap_stop_audio_capture() APIs run
|
||||
a simple WASAPI preview monitor from a capture endpoint to the default
|
||||
speaker. They are independent from the recording path.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef GCAPTURE_BUILD
|
||||
#define GCAP_API __declspec(dllexport)
|
||||
#else
|
||||
#define GCAP_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define GCAP_API
|
||||
#endif
|
||||
|
||||
#define GCAP_AUDIO_ID_MAX 256
|
||||
#define GCAP_AUDIO_NAME_MAX 256
|
||||
|
||||
/** WASAPI capture endpoint information. */
|
||||
typedef struct gcap_audio_device_t
|
||||
{
|
||||
char id[GCAP_AUDIO_ID_MAX]; /** Opaque WASAPI endpoint id, UTF-8. Use with gcap_set_recording_audio_device(). */
|
||||
char name[GCAP_AUDIO_NAME_MAX]; /** Friendly endpoint name, UTF-8. */
|
||||
|
||||
int channels; /** Channel count when known: 1, 2, 6, etc. 0 means unknown. */
|
||||
int sample_rate; /** Preferred/current sample rate when known, e.g. 48000. 0 means unknown. */
|
||||
int bits_per_sample; /** 16 / 24 / 32 when known. 0 means unknown. */
|
||||
int is_float; /** 1 = IEEE float, 0 = PCM or unknown. */
|
||||
int is_default; /** 1 = system default capture endpoint. */
|
||||
} gcap_audio_device_t;
|
||||
|
||||
/** Return number of active WASAPI capture endpoints. */
|
||||
GCAP_API int gcap_audio_device_count(void);
|
||||
|
||||
/**
|
||||
* Enumerate active WASAPI capture endpoints.
|
||||
*
|
||||
* Parameters:
|
||||
* out - Output array. If null, the function returns total count.
|
||||
* max_count - Number of entries available in out.
|
||||
*
|
||||
* Return:
|
||||
* Number of entries written, or total count when out is null/max_count <= 0.
|
||||
*/
|
||||
GCAP_API int gcap_audio_enum_devices(
|
||||
gcap_audio_device_t *out,
|
||||
int max_count);
|
||||
|
||||
/** Legacy alias for gcap_audio_device_count(). Kept for source/binary compatibility. */
|
||||
GCAP_API int gcap_get_audio_device_count(void);
|
||||
|
||||
/** Legacy alias for gcap_audio_enum_devices(). Kept for source/binary compatibility. */
|
||||
GCAP_API int gcap_enum_audio_devices(
|
||||
gcap_audio_device_t *out,
|
||||
int max_count);
|
||||
|
||||
/**
|
||||
* Best-effort match from a video capture device friendly name to a WASAPI
|
||||
* capture endpoint. Returns 1 and writes out when a likely endpoint is found.
|
||||
*/
|
||||
GCAP_API int gcap_audio_find_device_for_capture(
|
||||
const char *capture_device_name_utf8,
|
||||
gcap_audio_device_t *out);
|
||||
|
||||
/** Experimental low-level audio capture configuration. Prefer gcap_set_recording_audio_device() for recording. */
|
||||
typedef struct gcap_audio_capture_config_t
|
||||
{
|
||||
const char *device_id; /** Endpoint id from gcap_audio_enum_devices(). null/empty may mean default. */
|
||||
int sample_rate; /** Requested sample rate, commonly 48000. */
|
||||
int channels; /** Requested channels, commonly 1 or 2. */
|
||||
} gcap_audio_capture_config_t;
|
||||
|
||||
/** Start low-level WASAPI audio preview/capture from cfg->device_id to the default speaker. */
|
||||
GCAP_API int gcap_start_audio_capture(
|
||||
const gcap_audio_capture_config_t *cfg);
|
||||
|
||||
/** Stop low-level WASAPI audio preview/capture if it was started. */
|
||||
GCAP_API void gcap_stop_audio_capture(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,871 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "gcap_audio.h"
|
||||
|
||||
/*
|
||||
gcapture public C API
|
||||
|
||||
This header is the SDK boundary. It intentionally uses C-compatible types,
|
||||
fixed-size UTF-8 strings, and opaque handles so applications can use the SDK
|
||||
from Qt, Win32/MFC, C#, Python wrappers, or other UI frameworks.
|
||||
|
||||
Typical lifecycle:
|
||||
1. gcap_enumerate()
|
||||
2. gcap_create() + gcap_open2(), or gcap_open()
|
||||
3. Optional: gcap_set_backend(), gcap_set_profile(), gcap_set_processing()
|
||||
4. Optional preview: gcap_set_preview()
|
||||
5. Optional callbacks: gcap_set_callbacks(), gcap_set_frame_packet_callback()
|
||||
6. gcap_start()
|
||||
7. Optional runtime operations: snapshot, recording, signal/runtime queries
|
||||
8. gcap_stop()
|
||||
9. gcap_close()
|
||||
|
||||
Thread-safety notes:
|
||||
- A single gcap_handle should normally be controlled from one application
|
||||
thread, except frame/error callbacks which are invoked from SDK/backend
|
||||
worker threads.
|
||||
- Callback pointers are only valid during the callback call. Copy data you
|
||||
need before returning.
|
||||
- Do not call blocking UI code directly inside callbacks. Marshal to your
|
||||
UI thread.
|
||||
- Unless a function explicitly says otherwise, do not call it concurrently
|
||||
with gcap_close() on the same handle.
|
||||
|
||||
String notes:
|
||||
- Public string parameters and string fields are UTF-8 unless documented
|
||||
otherwise.
|
||||
- Fixed-size output buffers are always intended to be NUL-terminated by the
|
||||
SDK on success.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef GCAPTURE_BUILD
|
||||
#define GCAP_API __declspec(dllexport)
|
||||
#else
|
||||
#define GCAP_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define GCAP_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** Capture backend selection. */
|
||||
typedef enum
|
||||
{
|
||||
/** Media Foundation CPU readback path. */
|
||||
GCAP_BACKEND_WINMF_CPU = 0,
|
||||
/** Media Foundation GPU/DXGI path. Recommended for WinMF preview when supported. */
|
||||
GCAP_BACKEND_WINMF_GPU = 1,
|
||||
/** DirectShow raw-sink path. Recommended for DShow capture devices. */
|
||||
GCAP_BACKEND_DSHOW = 2,
|
||||
/** SDK chooses an available backend. Actual backend can be queried by gcap_get_active_backend(). */
|
||||
GCAP_BACKEND_AUTO = 3
|
||||
} gcap_backend_t;
|
||||
|
||||
/** Profile negotiation mode. */
|
||||
enum gcap_profile_mode_t
|
||||
{
|
||||
/** Let the device/backend choose its default format. */
|
||||
GCAP_PROFILE_DEVICE_DEFAULT = 0,
|
||||
/** Use width/height/fps/format from gcap_profile_t where supported. */
|
||||
GCAP_PROFILE_CUSTOM
|
||||
};
|
||||
|
||||
|
||||
/** SDK log level passed to gcap_log_callback_t. */
|
||||
typedef enum
|
||||
{
|
||||
GCAP_LOG_TRACE = 0,
|
||||
GCAP_LOG_DEBUG = 1,
|
||||
GCAP_LOG_INFO = 2,
|
||||
GCAP_LOG_WARN = 3,
|
||||
GCAP_LOG_ERROR = 4
|
||||
} gcap_log_level_t;
|
||||
|
||||
/**
|
||||
* SDK log callback.
|
||||
*
|
||||
* The callback may be invoked from SDK/backend worker threads. Do not touch
|
||||
* UI objects directly; marshal the message to your UI/log thread.
|
||||
* message_utf8 is valid only during the callback call. Copy it if needed.
|
||||
*/
|
||||
typedef void (*gcap_log_callback_t)(gcap_log_level_t level, const char *message_utf8, void *user);
|
||||
|
||||
/** SDK status code returned by most high-level APIs. */
|
||||
typedef enum
|
||||
{
|
||||
GCAP_OK = 0,
|
||||
/** Invalid argument, null pointer, invalid state-independent parameter, or insufficient buffer. */
|
||||
GCAP_EINVAL,
|
||||
/** Device not found, removed, or unavailable. */
|
||||
GCAP_ENODEV,
|
||||
/** Operation is not valid in the current handle state. */
|
||||
GCAP_ESTATE,
|
||||
/** I/O, backend, driver, media, or file operation failed. */
|
||||
GCAP_EIO,
|
||||
/** Requested backend/format/operation is not supported. */
|
||||
GCAP_ENOTSUP
|
||||
} gcap_status_t;
|
||||
|
||||
/** Pixel format used by capability, negotiated status, callbacks, and recording helpers. */
|
||||
typedef enum
|
||||
{
|
||||
GCAP_FMT_NV12, /** 8-bit YUV 4:2:0, two planes: Y + interleaved UV. */
|
||||
GCAP_FMT_YUY2, /** 8-bit YUV 4:2:2 packed. */
|
||||
GCAP_FMT_ARGB, /** 8-bit packed 32-bit RGB-like surface. In callbacks it is treated as BGRA/ARGB-compatible 4 bytes per pixel. */
|
||||
GCAP_FMT_P010, /** 10-bit YUV 4:2:0 in 16-bit containers, two planes. */
|
||||
GCAP_FMT_Y210, /** 10-bit YUV 4:2:2 packed in 16-bit containers. */
|
||||
GCAP_FMT_V210, /** 10-bit packed 4:2:2. Capability placeholder; conversion support may be limited. */
|
||||
GCAP_FMT_R210 /** 10-bit packed RGB. Capability placeholder; conversion support may be limited. */
|
||||
} gcap_pixfmt_t;
|
||||
|
||||
/** Device enumeration result. */
|
||||
typedef struct
|
||||
{
|
||||
int index; /** Device index accepted by gcap_open() / gcap_open2(). */
|
||||
char name[128]; /** Friendly device name, UTF-8. */
|
||||
char symbolic_link[256]; /** Backend/device symbolic link when available, UTF-8. */
|
||||
unsigned caps; /** Reserved bitmask. Current convention: 1<<0 HDMI, 1<<1 SDI, 1<<2 10-bit capable. */
|
||||
} gcap_device_info_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GCAP_INPUT_UNKNOWN = 0,
|
||||
GCAP_INPUT_HDMI = 1,
|
||||
GCAP_INPUT_SDI = 2
|
||||
} gcap_input_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GCAP_RANGE_UNKNOWN = 0,
|
||||
GCAP_RANGE_LIMITED = 1,
|
||||
GCAP_RANGE_FULL = 2
|
||||
} gcap_range_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GCAP_CSP_UNKNOWN = 0,
|
||||
GCAP_CSP_BT601 = 1,
|
||||
GCAP_CSP_BT709 = 2,
|
||||
GCAP_CSP_BT2020 = 3
|
||||
} gcap_colorspace_t;
|
||||
|
||||
/** Best-effort static device properties. Empty/zero/-1 fields mean unknown or not reported by the driver. */
|
||||
typedef struct
|
||||
{
|
||||
char driver_version[64];
|
||||
char firmware_version[64];
|
||||
char serial_number[64];
|
||||
gcap_input_t input;
|
||||
int pcie_gen; /** 2/3/4/5, or 0 if unknown. */
|
||||
int pcie_lanes; /** 1/4/8/16, or 0 if unknown. */
|
||||
int hdcp; /** 0 = no, 1 = yes, -1 = unknown. */
|
||||
} gcap_device_props_t;
|
||||
|
||||
/** Signal/media-type status. Used for input probe, negotiated format, and runtime info. */
|
||||
typedef struct
|
||||
{
|
||||
int width, height;
|
||||
int fps_num, fps_den; /** FPS numerator/denominator. 0 means unknown. */
|
||||
gcap_pixfmt_t pixfmt;
|
||||
int bit_depth; /** 8/10/12, or 0 if unknown. */
|
||||
gcap_colorspace_t csp;
|
||||
gcap_range_t range;
|
||||
int hdr; /** 0 = SDR/unknown-not-HDR, 1 = HDR, -1 = unknown. */
|
||||
} gcap_signal_status_t;
|
||||
|
||||
/** One video capability entry reported or inferred for a device/backend. */
|
||||
typedef struct
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int fps_num;
|
||||
int fps_den;
|
||||
gcap_pixfmt_t pixfmt;
|
||||
int bit_depth;
|
||||
char subtype_name[32]; /** Backend/native media subtype name, e.g. HDYC/UYVY/v210/ARGB32. May be empty. */
|
||||
} gcap_video_cap_t;
|
||||
|
||||
/** DirectShow property page descriptor. */
|
||||
typedef struct
|
||||
{
|
||||
char page_name[128]; /** Vendor/driver page name, UTF-8 when conversion succeeds. */
|
||||
int capture_pin; /** 0 = filter property page, 1 = capture-pin property page. */
|
||||
} gcap_property_page_t;
|
||||
|
||||
/** Runtime information for UI/status display and diagnostics. */
|
||||
typedef struct
|
||||
{
|
||||
gcap_signal_status_t signal; /** Best-effort input signal shown to UI. */
|
||||
gcap_signal_status_t signal_probe; /** Raw probe/fallback result, for example DShow IAMStreamConfig::GetFormat(). */
|
||||
gcap_signal_status_t negotiated; /** Media type actually negotiated/delivered by the backend. */
|
||||
double runtime_fps; /** Measured delivered-frame FPS. 0 means unknown/not running yet. */
|
||||
int active_backend; /** gcap_backend_t value actually in use. */
|
||||
char backend_name[32]; /** Display string, e.g. WinMF GPU / WinMF CPU / DShow Raw. */
|
||||
char frame_source[32]; /** Display string, e.g. DXGI / CPU / RawSink. */
|
||||
char path_name[64]; /** Display string describing active preview/capture path. */
|
||||
char source_format[32]; /** Legacy display field: negotiated media subtype name. */
|
||||
char render_format[32]; /** Display field: canvas / scene processing format. */
|
||||
char input_signal_desc[64]; /** Display field: RGB/YUV, color space, bit depth, may be inferred. */
|
||||
char input_signal_note[32]; /** Display field: Inferred / Driver / Unknown. */
|
||||
char negotiated_desc[32]; /** Display field: RGB24 / NV12 / YUY2 / ARGB32 / etc. */
|
||||
char selectable_caps_inline[512]; /** Active open-graph selectable modes summary after SDK filtering/policy. */
|
||||
char selectable_caps_tooltip[2048];/** Full active open-graph selectable modes after SDK filtering/policy. */
|
||||
} gcap_runtime_info_t;
|
||||
|
||||
/** Human-readable recording configuration currently selected by the SDK. */
|
||||
typedef struct
|
||||
{
|
||||
char mode_name[64]; /** e.g. DShow + FFmpeg MP4 / Media Foundation Sink Writer. */
|
||||
char encoder_name[160]; /** e.g. FFmpeg HEVC / H.265 Main10. */
|
||||
char input_format[32]; /** SDK pixel format name. */
|
||||
char output_format[32]; /** Encoder/muxer output pixel/codec description. */
|
||||
int input_bit_depth;
|
||||
int output_bit_depth;
|
||||
int output_fps_num;
|
||||
int output_fps_den;
|
||||
int video_only; /** 1 = current recorder writes video only; 0 = audio may be included when configured/supported. */
|
||||
} gcap_recording_info_t;
|
||||
|
||||
/** Snapshot export flags. If desc->flags is 0, SDK exports RAW_ALL + TIFF + STATS + PNG. */
|
||||
typedef enum
|
||||
{
|
||||
GCAP_EXPORT_RAW_NATIVE = 1 << 0, /** Native readback RAW: 10-bit source -> *_abgr2101010.raw; 8-bit source -> *_bgra8.raw. */
|
||||
GCAP_EXPORT_RAW_RGB10_U16 = 1 << 1, /** 10-bit RGB values stored in uint16 containers: *_rgb10.raw. */
|
||||
GCAP_EXPORT_RAW_RGBA16 = 1 << 2, /** 10-bit values expanded to 16-bit RGBA: *_rgba16_expanded.raw. */
|
||||
GCAP_EXPORT_TIFF = 1 << 3, /** WIC TIFF export: *.tiff. */
|
||||
GCAP_EXPORT_STATS = 1 << 4, /** Text statistics: *.stats.txt. */
|
||||
GCAP_EXPORT_PNG = 1 << 5, /** WIC PNG preview/export image: *.png. */
|
||||
GCAP_EXPORT_RAW_GIGABYTE_HEADER = 1 << 6, /** Additional RAW copies with 128-byte GIGABYTE RAW header: *_gigabyte_*.raw. */
|
||||
GCAP_EXPORT_RAW_RGBA8 = 1 << 7, /** 8-bit hex-editor-friendly RGBA dump: *_rgba8.raw, bytes are R G B A per pixel. */
|
||||
GCAP_EXPORT_RAW_ALL = GCAP_EXPORT_RAW_NATIVE | GCAP_EXPORT_RAW_RGB10_U16 | GCAP_EXPORT_RAW_RGBA16
|
||||
} gcap_export_flags_t;
|
||||
|
||||
#define GCAP_GIGABYTE_RAW_HEADER_SIZE 128
|
||||
|
||||
/*
|
||||
* GIGABYTE RAW header is a 128-byte ASCII header before the RAW payload:
|
||||
* GIGABYTE_RAW
|
||||
* header_size=128
|
||||
* Width=<pixels>
|
||||
* Height=<pixels>
|
||||
* Format=<payload format>
|
||||
* SourceBitDepth=<source bit depth>
|
||||
*/
|
||||
|
||||
/** Snapshot export request. */
|
||||
typedef struct
|
||||
{
|
||||
const char *base_path_utf8; /** Base path without SDK suffix. Must not be null/empty. UTF-8. */
|
||||
int flags; /** Bitwise OR of gcap_export_flags_t. 0 means default full export. */
|
||||
} gcap_snapshot_export_desc_t;
|
||||
|
||||
/** Snapshot export result. Empty path means that file type was not requested or not generated for the source format. */
|
||||
typedef struct
|
||||
{
|
||||
char native_raw_path[512]; /** *_abgr2101010.raw for 10-bit sources, or *_bgra8.raw for 8-bit sources. */
|
||||
char fp16_raw_path[512]; /** *_fp16_rgba16f.raw, generated for 10-bit/FP16 scene readback when RAW export is requested. */
|
||||
char rgb10_u16_path[512]; /** *_rgb10.raw, generated for 10-bit sources when RGB10 RAW export is requested. */
|
||||
char rgba16_path[512]; /** *_rgba16_expanded.raw, generated for 10-bit sources when RAW export is requested. */
|
||||
char rgba8_path[512]; /** *_rgba8.raw, generated for 8-bit hex-editor-friendly R8 G8 B8 A8 inspection. */
|
||||
char gigabyte_native_raw_path[512]; /** Headered mirror: *_gigabyte_abgr2101010.raw or *_gigabyte_bgra8.raw. */
|
||||
char gigabyte_fp16_raw_path[512]; /** Reserved legacy field. Current snapshot export leaves this empty. */
|
||||
char gigabyte_rgb10_u16_path[512]; /** Reserved legacy field. Current snapshot export leaves this empty. */
|
||||
char gigabyte_rgba16_path[512]; /** Reserved legacy field. Current snapshot export leaves this empty. */
|
||||
char tiff_path[512]; /** *.tiff when TIFF export is requested. */
|
||||
char stats_path[512]; /** *.stats.txt when STATS export is requested. */
|
||||
char png_path[512]; /** *.png when PNG export is requested. */
|
||||
int width;
|
||||
int height;
|
||||
gcap_pixfmt_t source_format;
|
||||
int source_bit_depth;
|
||||
int generated_flags; /** Bitwise OR of actually generated gcap_export_flags_t values. */
|
||||
} gcap_snapshot_export_result_t;
|
||||
|
||||
/** Recording statistics collected by the active recorder/backend. Unsupported fields remain 0. */
|
||||
typedef struct
|
||||
{
|
||||
uint64_t frames_written;
|
||||
uint64_t frames_dropped;
|
||||
uint64_t frames_duplicated;
|
||||
uint64_t input_frames;
|
||||
uint64_t unsupported_frames;
|
||||
uint64_t overwritten_frames;
|
||||
int width;
|
||||
int height;
|
||||
int fps_num;
|
||||
int fps_den;
|
||||
gcap_pixfmt_t input_pixfmt;
|
||||
int output_bit_depth;
|
||||
char encoder_name[128];
|
||||
char muxer_name[64];
|
||||
double avg_encode_fps;
|
||||
double avg_bitrate_kbps;
|
||||
} gcap_recording_stats_t;
|
||||
|
||||
|
||||
/**
|
||||
* Ramp-pattern validation status for gcap_tiff_analysis_t.
|
||||
*
|
||||
* Important: ramp validation is only meaningful for generated monotonic ramp test
|
||||
* images. A real camera/HDMI frame usually returns GCAP_TIFF_RAMP_NOT_APPLICABLE;
|
||||
* that does not mean the TIFF is 8-bit or invalid. Use likely_ten_bit_content,
|
||||
* min/max, unique_value_count, and effective_bit_depth as the general bit-depth
|
||||
* evidence for arbitrary images.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GCAP_TIFF_RAMP_NOT_CHECKED = 0,
|
||||
GCAP_TIFF_RAMP_NOT_APPLICABLE = 1,
|
||||
GCAP_TIFF_RAMP_DETECTED_VALID = 2,
|
||||
GCAP_TIFF_RAMP_DETECTED_INVALID = 3
|
||||
} gcap_tiff_ramp_status_t;
|
||||
|
||||
/** TIFF bit-depth / optional ramp-pattern analysis result. Fixed-size C struct for SDK clients. */
|
||||
typedef struct
|
||||
{
|
||||
int ok; /** 1 = analysis succeeded, 0 = failed. */
|
||||
char path[512]; /** Input TIFF path, UTF-8 when available. */
|
||||
char error[512]; /** Failure reason, UTF-8. Empty on success. */
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int channels;
|
||||
int bits_per_sample;
|
||||
int samples_per_pixel;
|
||||
int stored_bit_depth;
|
||||
int effective_bit_depth;
|
||||
|
||||
char pixel_format_name[96];
|
||||
char photometric[64];
|
||||
|
||||
uint64_t min_value;
|
||||
uint64_t max_value;
|
||||
uint64_t unique_value_count;
|
||||
|
||||
int likely_ten_bit_ramp; /** Backward-compatible alias: 1 only when ramp_status == GCAP_TIFF_RAMP_DETECTED_VALID. */
|
||||
int strict_ten_bit_ramp; /** Strict monotonic ramp and likely 10-bit content. */
|
||||
int visual_ten_bit_ramp_candidate; /** A monotonic visual ramp pattern was detected, regardless of bit-depth validity. */
|
||||
int likely_ten_bit_content; /** General bit-depth evidence for arbitrary images; does not require a ramp pattern. */
|
||||
int values_look_shifted_10bit;
|
||||
int values_look_8bit_expanded;
|
||||
int ramp_status; /** gcap_tiff_ramp_status_t. Non-ramp images should be NOT_APPLICABLE, not failed. */
|
||||
|
||||
char ramp_reason[512];
|
||||
char strict_ramp_reason[512];
|
||||
char visual_ramp_reason[512];
|
||||
char ramp_note[512]; /** Human-readable explanation of ramp_status. */
|
||||
|
||||
int sampled_row_y;
|
||||
char sampled_row_source[96];
|
||||
char sampled_row_logical10_rule[192];
|
||||
char sampled_row_raw16_csv[4096];
|
||||
char sampled_row_logical10_csv[4096];
|
||||
|
||||
int preview_stride_bytes; /** RGBA64 preview stride. Use gcap_read_tiff_preview_rgba64() to read data. */
|
||||
size_t preview_size_bytes; /** Required RGBA64 preview buffer size. */
|
||||
} gcap_tiff_analysis_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GCAP_DEINT_AUTO = 0,
|
||||
GCAP_DEINT_OFF,
|
||||
GCAP_DEINT_WEAVE,
|
||||
GCAP_DEINT_BOB
|
||||
} gcap_deinterlace_t;
|
||||
|
||||
/** Optional processing preferences. Unsupported options are ignored or return GCAP_ENOTSUP depending on backend. */
|
||||
typedef struct
|
||||
{
|
||||
gcap_pixfmt_t preferred_pixfmt; /** Preferred capture format. Use backend capability APIs to discover support. */
|
||||
gcap_deinterlace_t deinterlace;
|
||||
gcap_range_t force_range; /** GCAP_RANGE_UNKNOWN = auto. */
|
||||
} gcap_processing_opts_t;
|
||||
|
||||
/** ProcAmp settings. SDK UI scale is 0..255, where 128 is neutral. */
|
||||
typedef struct
|
||||
{
|
||||
int brightness;
|
||||
int contrast;
|
||||
int hue;
|
||||
int saturation;
|
||||
int sharpness;
|
||||
} gcap_procamp_t;
|
||||
|
||||
/** One ProcAmp control range in SDK UI units. */
|
||||
typedef struct
|
||||
{
|
||||
int supported; /** Non-zero if this control is supported by the active backend/path. */
|
||||
int min_value; /** Minimum accepted value. */
|
||||
int max_value; /** Maximum accepted value. */
|
||||
int step; /** Recommended slider step. */
|
||||
int default_value; /** Recommended neutral/default value. */
|
||||
int current_value; /** Current value if available; otherwise default_value. */
|
||||
} gcap_procamp_range_t;
|
||||
|
||||
/** ProcAmp capability block for Brightness/Contrast/Hue/Saturation/Sharpness. */
|
||||
typedef struct
|
||||
{
|
||||
gcap_procamp_range_t brightness;
|
||||
gcap_procamp_range_t contrast;
|
||||
gcap_procamp_range_t hue;
|
||||
gcap_procamp_range_t saturation;
|
||||
gcap_procamp_range_t sharpness;
|
||||
} gcap_procamp_caps_t;
|
||||
|
||||
/** Requested capture profile. For GCAP_PROFILE_CUSTOM, set width/height/fps/format. */
|
||||
typedef struct
|
||||
{
|
||||
int width, height;
|
||||
int fps_num, fps_den;
|
||||
gcap_pixfmt_t format;
|
||||
gcap_profile_mode_t mode;
|
||||
} gcap_profile_t;
|
||||
|
||||
/** Legacy frame callback payload. Prefer gcap_frame_packet_t for SDK clients that need backend/source metadata. */
|
||||
typedef struct
|
||||
{
|
||||
const void *data[3]; /** Plane pointers. Valid only during callback. */
|
||||
int stride[3]; /** Bytes per row for each plane. */
|
||||
int plane_count;
|
||||
int width, height;
|
||||
gcap_pixfmt_t format;
|
||||
uint64_t pts_ns;
|
||||
uint64_t frame_id;
|
||||
} gcap_frame_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GCAP_SOURCE_UNKNOWN = 0,
|
||||
GCAP_SOURCE_WINMF_GPU = 1,
|
||||
GCAP_SOURCE_WINMF_CPU = 2,
|
||||
GCAP_SOURCE_DSHOW_RAWSINK = 3,
|
||||
GCAP_SOURCE_DSHOW_RENDERER = 4 /** Legacy/debug renderer path. Prefer GCAP_SOURCE_DSHOW_RAWSINK for SDK clients. */
|
||||
} gcap_frame_source_kind_t;
|
||||
|
||||
/** Preferred raw frame callback payload. Plane pointers are valid only during callback. */
|
||||
typedef struct
|
||||
{
|
||||
int width, height;
|
||||
gcap_pixfmt_t format;
|
||||
int plane_count;
|
||||
const void *data[3]; /** Plane pointers. Do not retain after callback returns. */
|
||||
int stride[3]; /** Bytes per row for each plane. */
|
||||
uint64_t pts_ns;
|
||||
uint64_t frame_id;
|
||||
int backend; /** gcap_backend_t value. */
|
||||
int source_kind; /** gcap_frame_source_kind_t value. */
|
||||
int gpu_backed; /** 1 when frame originated from GPU-backed path; callback data is still CPU-readable. */
|
||||
} gcap_frame_packet_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GCAP_PREVIEW_BITDEPTH_8BIT = 0,
|
||||
GCAP_PREVIEW_BITDEPTH_10BIT = 1,
|
||||
GCAP_PREVIEW_BITDEPTH_AUTO = 2
|
||||
} gcap_preview_bitdepth_t;
|
||||
|
||||
/** Native preview target. The SDK renders into the supplied HWND. */
|
||||
typedef struct
|
||||
{
|
||||
void *hwnd; /** Native HWND. Required when enable_preview is non-zero. */
|
||||
int enable_preview; /** 0 = disable preview, 1 = enable preview. */
|
||||
int use_fp16_pipeline; /** 1 = use FP16 scene pipeline when available. Recommended for 10-bit/HDR-oriented paths. */
|
||||
int swapchain_10bit; /** 0 = force 8-bit BGRA, 1 = prefer/force 10-bit RGB10A2, 2 = auto try 10-bit then fallback 8-bit. */
|
||||
} gcap_preview_desc_t;
|
||||
|
||||
typedef void (*gcap_on_video_cb)(const gcap_frame_t *frame, void *user);
|
||||
typedef void (*gcap_on_frame_packet_cb)(const gcap_frame_packet_t *pkt, void *user);
|
||||
typedef void (*gcap_on_error_cb)(gcap_status_t code, const char *msg, void *user);
|
||||
|
||||
typedef struct gcap_handle_t *gcap_handle;
|
||||
|
||||
/**
|
||||
* Installs a process-wide SDK log callback.
|
||||
*
|
||||
* This is intended for SDK clients to receive WinMF/DShow/snapshot/recording
|
||||
* diagnostics in their own logging system. Passing cb = NULL disables the
|
||||
* callback. The callback may be invoked from SDK/backend worker threads.
|
||||
* The SDK may still also send messages to OutputDebugString on Windows as
|
||||
* a fallback.
|
||||
*/
|
||||
GCAP_API void gcap_set_log_callback(gcap_log_callback_t cb, void *user);
|
||||
|
||||
/**
|
||||
* Enumerate capture devices.
|
||||
*
|
||||
* Parameters:
|
||||
* out - Output array. Must not be null in the current implementation.
|
||||
* max - Number of entries available in out.
|
||||
* count - Receives total/actual count when non-null.
|
||||
*
|
||||
* Return:
|
||||
* GCAP_OK on success. GCAP_EINVAL for invalid output array/max.
|
||||
*
|
||||
* Thread-safety:
|
||||
* Safe to call before any handle is created. Avoid calling repeatedly from
|
||||
* a real-time callback thread because device enumeration can touch OS/driver APIs.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_enumerate(gcap_device_info_t *out, int max, int *count);
|
||||
|
||||
/** Create an unopened handle. Use gcap_open2() before gcap_start(). */
|
||||
GCAP_API gcap_status_t gcap_create(gcap_handle *out);
|
||||
|
||||
/** Convenience API: create and open a device in one call. Close with gcap_close(). */
|
||||
GCAP_API gcap_status_t gcap_open(int device_index, gcap_handle *out);
|
||||
|
||||
/** Open an existing handle created by gcap_create(). Must be called before gcap_start(). */
|
||||
GCAP_API gcap_status_t gcap_open2(gcap_handle h, int device_index);
|
||||
|
||||
/**
|
||||
* Set requested capture profile.
|
||||
*
|
||||
* Call state:
|
||||
* Recommended after open and before start. Changing profile while running
|
||||
* may return GCAP_ESTATE or may require stop/start depending on backend.
|
||||
*
|
||||
* Notes:
|
||||
* Use gcap_enum_video_caps_ex() / gcap_get_recommended_profile() to find
|
||||
* supported values. The driver may still negotiate a different final format;
|
||||
* query gcap_get_runtime_info() after start to verify.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_set_profile(gcap_handle h, const gcap_profile_t *prof);
|
||||
|
||||
/** Configure SDK buffering hints. Call before gcap_start(). Backend may ignore unsupported hints. */
|
||||
GCAP_API gcap_status_t gcap_set_buffers(gcap_handle h, int count, size_t bytes_hint);
|
||||
|
||||
/**
|
||||
* Set legacy video/error callbacks.
|
||||
*
|
||||
* Callback lifetime:
|
||||
* Frame data is valid only during the callback. Copy before returning.
|
||||
* Passing null callbacks disables that callback type.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_set_callbacks(gcap_handle h, gcap_on_video_cb vcb, gcap_on_error_cb ecb, void *user);
|
||||
|
||||
/**
|
||||
* Set preferred frame packet callback.
|
||||
*
|
||||
* Call state:
|
||||
* Usually configured before gcap_start(); can be cleared before/after stop.
|
||||
*
|
||||
* Thread-safety:
|
||||
* Invoked from SDK/backend worker thread. Do not block for long periods.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_set_frame_packet_callback(gcap_handle h, gcap_on_frame_packet_cb cb, void *user);
|
||||
|
||||
/** Start capture/preview/callback delivery. Requires an opened handle. */
|
||||
GCAP_API gcap_status_t gcap_start(gcap_handle h);
|
||||
|
||||
/**
|
||||
* Start recording to an output path.
|
||||
*
|
||||
* Call state:
|
||||
* Requires an opened and normally running capture session. If called before
|
||||
* capture is started, backend support is not guaranteed.
|
||||
*
|
||||
* Parameters:
|
||||
* path_utf8 - Output file path, UTF-8. MP4 is the intended container for
|
||||
* current FFmpeg/MF recorder paths.
|
||||
*
|
||||
* Notes:
|
||||
* Use gcap_get_recording_info() after profile/backend selection to show the
|
||||
* selected encoder/mode to the user. Use gcap_get_recording_stats() after or
|
||||
* during recording to inspect counters supported by the active backend.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_start_recording(gcap_handle h, const char *path_utf8);
|
||||
|
||||
/** Stop active recording. Safe to call when recording is not active; backend may return GCAP_ESTATE. */
|
||||
GCAP_API gcap_status_t gcap_stop_recording(gcap_handle h);
|
||||
|
||||
/** Stop capture/preview/callback delivery. Recording should be stopped first. */
|
||||
GCAP_API gcap_status_t gcap_stop(gcap_handle h);
|
||||
|
||||
/**
|
||||
* Enumerate WASAPI capture endpoints.
|
||||
*
|
||||
* Legacy status-code API. New clients may prefer gcap_audio_device_count()
|
||||
* and gcap_audio_enum_devices().
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_enumerate_audio_devices(gcap_audio_device_t *out, int max, int *count);
|
||||
|
||||
/**
|
||||
* Select WASAPI capture endpoint for recording.
|
||||
*
|
||||
* Call state:
|
||||
* Call before gcap_start_recording(). If changed while recording, behavior is
|
||||
* backend-dependent and not recommended.
|
||||
*
|
||||
* Parameters:
|
||||
* device_id_utf8 - Endpoint id from audio enumeration. null or empty string
|
||||
* means system default capture endpoint.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_set_recording_audio_device(gcap_handle h, const char *device_id_utf8);
|
||||
|
||||
/** Close and destroy a handle. Do not use the handle after this call. */
|
||||
GCAP_API gcap_status_t gcap_close(gcap_handle h);
|
||||
|
||||
/** Set global preferred backend for subsequently opened sessions. Not per-handle. */
|
||||
GCAP_API void gcap_set_backend(int backend);
|
||||
|
||||
/** Select D3D11 adapter index for GPU/DXGI processing. -1 means system default adapter. */
|
||||
GCAP_API void gcap_set_d3d_adapter(int adapter_index);
|
||||
|
||||
/** Query actual backend currently used by an opened/running handle. Returns -1 for invalid handle. */
|
||||
GCAP_API int gcap_get_active_backend(gcap_handle h);
|
||||
|
||||
/**
|
||||
* Legacy snapshot helper.
|
||||
*
|
||||
* Prefer gcap_export_snapshot() for new SDK clients because it returns the
|
||||
* generated paths and flags. This helper uses base_path_utf8 plus SDK-defined
|
||||
* suffixes and writes requested RAW/TIFF/STATS outputs.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_export_preview_scene_rgb10(gcap_handle h, const char *base_path_utf8,
|
||||
int export_raw, int export_tiff, int export_stats);
|
||||
|
||||
/**
|
||||
* Export a snapshot from the current preview scene/readback path.
|
||||
*
|
||||
* Call state:
|
||||
* Requires a valid opened handle and a capture/preview scene that has already
|
||||
* produced at least one frame. In normal use, call after gcap_start() and
|
||||
* after frames are visible/delivered. It does not require the caller to have
|
||||
* a frame callback. A preview HWND is strongly recommended because the export
|
||||
* currently reads from the SDK preview/scene pipeline.
|
||||
*
|
||||
* Recording interaction:
|
||||
* Intended to be callable while recording, but it may briefly contend with
|
||||
* GPU/readback/file I/O. Avoid calling it from frame callbacks or timing-
|
||||
* critical threads.
|
||||
*
|
||||
* Output naming:
|
||||
* Given base_path_utf8 = "C:/cap/snapshot_001", generated paths are:
|
||||
* 10-bit source RAW:
|
||||
* C:/cap/snapshot_001_abgr2101010.raw
|
||||
* C:/cap/snapshot_001_fp16_rgba16f.raw
|
||||
* C:/cap/snapshot_001_rgb10.raw
|
||||
* C:/cap/snapshot_001_rgba16_expanded.raw
|
||||
* 8-bit source RAW:
|
||||
* C:/cap/snapshot_001_bgra8.raw
|
||||
* TIFF:
|
||||
* C:/cap/snapshot_001.tiff
|
||||
* STATS:
|
||||
* C:/cap/snapshot_001.stats.txt
|
||||
* PNG:
|
||||
* C:/cap/snapshot_001.png
|
||||
*
|
||||
* Parameters:
|
||||
* h - Opened capture handle.
|
||||
* desc - Export request. desc->base_path_utf8 must not be null/empty.
|
||||
* desc->flags == 0 means RAW_ALL | TIFF | STATS | PNG.
|
||||
* out - Optional result. If non-null, SDK clears it to zero before writing.
|
||||
*
|
||||
* Return:
|
||||
* GCAP_OK on success. On failure, no guarantee is made that partial files were
|
||||
* not written; callers may delete files using the expected suffixes if needed.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_export_snapshot(gcap_handle h, const gcap_snapshot_export_desc_t *desc,
|
||||
gcap_snapshot_export_result_t *out);
|
||||
|
||||
/** Query best-effort static device properties. Can be called after open; values may be unknown. */
|
||||
GCAP_API gcap_status_t gcap_get_device_props(gcap_handle h, gcap_device_props_t *out);
|
||||
|
||||
/** Query current/best-effort input signal. Can be called after open/start. */
|
||||
GCAP_API gcap_status_t gcap_get_signal_status(gcap_handle h, gcap_signal_status_t *out);
|
||||
|
||||
/** Query combined runtime status. Most useful after gcap_start(). */
|
||||
GCAP_API gcap_status_t gcap_get_runtime_info(gcap_handle h, gcap_runtime_info_t *out);
|
||||
|
||||
/** Set processing preferences such as preferred format, deinterlace, or forced range. Prefer calling before start. */
|
||||
GCAP_API gcap_status_t gcap_set_processing(gcap_handle h, const gcap_processing_opts_t *opts);
|
||||
|
||||
/**
|
||||
* Query current ProcAmp values from the active backend/path.
|
||||
*
|
||||
* Can be called after gcap_open(). If the active backend/path does not
|
||||
* support SDK ProcAmp, returns GCAP_ENOTSUP.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_get_procamp(gcap_handle h, gcap_procamp_t *out);
|
||||
|
||||
/**
|
||||
* Query ProcAmp control ranges/capabilities.
|
||||
*
|
||||
* The current implementation exposes SDK-side preview/conversion ProcAmp
|
||||
* controls in 0..255 units, default 128. These are not necessarily the
|
||||
* hardware driver's IAMVideoProcAmp ranges. Unsupported controls are marked
|
||||
* supported = 0.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_get_procamp_caps(gcap_handle h, gcap_procamp_caps_t *out);
|
||||
|
||||
/** Apply ProcAmp settings on supported CPU/GPU preview/conversion paths. Passing null resets to neutral. */
|
||||
GCAP_API gcap_status_t gcap_set_procamp(gcap_handle h, const gcap_procamp_t *p);
|
||||
|
||||
/** Reset ProcAmp settings to backend defaults/neutral values. */
|
||||
GCAP_API gcap_status_t gcap_reset_procamp(gcap_handle h);
|
||||
|
||||
/** Legacy audio count helper. Prefer gcap_audio_device_count() for new code. */
|
||||
GCAP_API int gcap_get_audio_device_count(void);
|
||||
|
||||
/** Legacy audio enumeration helper. Prefer gcap_audio_enum_devices() for new code. Returns number written, or total if out_devices is null. */
|
||||
GCAP_API int gcap_enum_audio_devices(gcap_audio_device_t *out_devices, int max_devices);
|
||||
|
||||
/** Return number of active WASAPI capture devices. */
|
||||
GCAP_API int gcap_audio_device_count(void);
|
||||
|
||||
/** Enumerate active WASAPI capture devices. Returns number written, or total if out_devices is null or max_devices <= 0. */
|
||||
GCAP_API int gcap_audio_enum_devices(gcap_audio_device_t *out_devices, int max_devices);
|
||||
|
||||
/** Best-effort match from the selected video capture device name to a WASAPI capture endpoint. */
|
||||
GCAP_API int gcap_audio_find_device_for_capture(const char *capture_device_name_utf8, gcap_audio_device_t *out_device);
|
||||
|
||||
/** Return stable SDK pixel format display name. Never returns null. */
|
||||
GCAP_API const char *gcap_pixfmt_name(gcap_pixfmt_t fmt);
|
||||
|
||||
/** Return gcapture SDK version string, for example "1.0.0". Never returns null. */
|
||||
GCAP_API const char *gcap_version_string(void);
|
||||
|
||||
/** Return nominal bit depth for a pixel format, or 0 if unknown/unsupported. */
|
||||
GCAP_API int gcap_pixfmt_bit_depth(gcap_pixfmt_t fmt);
|
||||
|
||||
/** Return non-zero if the pixel format is treated as 10-bit by SDK helpers. */
|
||||
GCAP_API int gcap_pixfmt_is_10bit(gcap_pixfmt_t fmt);
|
||||
|
||||
/** Return non-zero if the pixel format is YUV-family. */
|
||||
GCAP_API int gcap_pixfmt_is_yuv(gcap_pixfmt_t fmt);
|
||||
|
||||
/** Return default stride in bytes for a single row/primary plane at the given width, or 0 if unknown. */
|
||||
GCAP_API int gcap_pixfmt_default_stride(int width, gcap_pixfmt_t fmt);
|
||||
|
||||
/** Return stable backend display name. Never returns null. */
|
||||
GCAP_API const char *gcap_backend_name(int backend);
|
||||
|
||||
/** Return stable frame source display name. Never returns null. */
|
||||
GCAP_API const char *gcap_source_kind_name(int source_kind);
|
||||
|
||||
/** Return non-zero when the recording helper would choose HEVC/H.265 Main10 for the input format. */
|
||||
GCAP_API int gcap_recording_uses_hevc_main10(gcap_pixfmt_t fmt);
|
||||
|
||||
/** Return human-readable recording mode name for a backend. Never returns null. */
|
||||
GCAP_API const char *gcap_recording_mode_name(int backend);
|
||||
|
||||
/**
|
||||
* Query current recording mode/encoder information.
|
||||
*
|
||||
* Call state:
|
||||
* Can be called after open/profile selection, before or during recording.
|
||||
* The result is based on current backend and negotiated/requested format;
|
||||
* after gcap_start(), it is more accurate.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_get_recording_info(gcap_handle h, gcap_recording_info_t *out);
|
||||
|
||||
/**
|
||||
* Query recording counters/statistics.
|
||||
*
|
||||
* Call state:
|
||||
* Can be called during recording or after gcap_stop_recording() while the
|
||||
* handle is still valid. Unsupported counters remain 0.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_get_recording_stats(gcap_handle h, gcap_recording_stats_t *out);
|
||||
|
||||
/**
|
||||
* Convert callback frame packet to packed BGRA8.
|
||||
*
|
||||
* Parameters:
|
||||
* src - Frame packet received from gcap_on_frame_packet_cb.
|
||||
* dst - Destination buffer.
|
||||
* dst_stride - Destination bytes per row. Must be >= src->width * 4.
|
||||
*
|
||||
* Supported input formats:
|
||||
* GCAP_FMT_ARGB, GCAP_FMT_NV12, GCAP_FMT_YUY2, GCAP_FMT_Y210.
|
||||
*
|
||||
* Thread-safety:
|
||||
* Stateless helper. It may be called from inside the frame callback if the
|
||||
* destination buffer is caller-owned and conversion cost is acceptable.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_frame_to_bgra8(const gcap_frame_packet_t *src, void *dst, int dst_stride);
|
||||
|
||||
|
||||
/**
|
||||
* Analyze a TIFF file written by SDK snapshot export or any WIC-readable TIFF.
|
||||
*
|
||||
* The analysis uses Windows Imaging Component on Windows and reports stored
|
||||
* bit depth, effective bit depth heuristics, min/max/unique values, and
|
||||
* optional ramp-pattern validation. Ramp validation is only meaningful for
|
||||
* generated monotonic ramp test images; normal camera/HDMI content commonly
|
||||
* reports GCAP_TIFF_RAMP_NOT_APPLICABLE. That is not a failure and does not
|
||||
* imply 8-bit content. Use likely_ten_bit_content and the value statistics
|
||||
* as the general bit-depth evidence for arbitrary images.
|
||||
*
|
||||
* It does not allocate memory for the caller.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_analyze_tiff(const char *path_utf8, gcap_tiff_analysis_t *out);
|
||||
|
||||
/**
|
||||
* Decode the first TIFF frame into RGBA64 little-endian pixels for preview.
|
||||
*
|
||||
* Pass dst = NULL or dst_size = 0 to query required_size/width/height/stride.
|
||||
* The destination buffer must be at least required_size bytes.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_read_tiff_preview_rgba64(const char *path_utf8,
|
||||
void *dst,
|
||||
size_t dst_size,
|
||||
int *width,
|
||||
int *height,
|
||||
int *stride_bytes,
|
||||
size_t *required_size);
|
||||
|
||||
/** Return human-readable status string. Never returns null. */
|
||||
GCAP_API const char *gcap_strerror(gcap_status_t);
|
||||
|
||||
/**
|
||||
* Configure native HWND preview.
|
||||
*
|
||||
* Call state:
|
||||
* Recommended after open and before start. Some backends may allow changing
|
||||
* preview target while stopped only. To disable preview, pass enable_preview=0.
|
||||
*
|
||||
* Notes:
|
||||
* The SDK does not own the HWND. The application must keep it valid while
|
||||
* preview is enabled/running.
|
||||
*/
|
||||
GCAP_API gcap_status_t gcap_set_preview(gcap_handle h, const gcap_preview_desc_t *desc);
|
||||
|
||||
/**
|
||||
* Enumerate DirectShow video format capabilities for a device index.
|
||||
*
|
||||
* Return:
|
||||
* Number of entries written. Passing null or max_caps <= 0 returns supported
|
||||
* count when available.
|
||||
*
|
||||
* Notes:
|
||||
* DShow-specific legacy helper. New code can use gcap_enum_video_caps_ex().
|
||||
*/
|
||||
GCAP_API int gcap_enum_video_caps(int device_index, gcap_video_cap_t *out_caps, int max_caps);
|
||||
|
||||
/** Backend-aware capability enumeration helper. Returns number written, or count when out_caps is null/max_caps <= 0. */
|
||||
GCAP_API int gcap_enum_video_caps_ex(int backend, int device_index, gcap_video_cap_t *out_caps, int max_caps);
|
||||
|
||||
/** Return SDK-recommended profile for backend/device based on current format priority and capabilities. */
|
||||
GCAP_API gcap_status_t gcap_get_recommended_profile(int backend, int device_index, gcap_profile_t *out_profile);
|
||||
|
||||
/** Enumerate unique pixel formats supported by a device/backend. Returns number written, or count when out_formats is null/max_formats <= 0. */
|
||||
GCAP_API int gcap_enum_supported_pixel_formats(int backend, int device_index, gcap_pixfmt_t *out_formats, int max_formats);
|
||||
|
||||
/** Enumerate available DirectShow property pages for a device. Returns number written, or count when out_pages is null/max_pages <= 0. */
|
||||
GCAP_API int gcap_enum_property_pages(int device_index, gcap_property_page_t *out_pages, int max_pages);
|
||||
|
||||
/** Open a device-specific vendor DShow property page. Debug/test helper; not required for generic capture flow. */
|
||||
GCAP_API int gcap_open_vendor_property_page(int device_index);
|
||||
|
||||
/** Open a named DirectShow property page. page_name_utf8 must match a name returned by gcap_enum_property_pages(). */
|
||||
GCAP_API int gcap_open_named_property_page(int device_index, const char *page_name_utf8, int capture_pin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "gcapture.h"
|
||||
#include <cstdarg>
|
||||
|
||||
|
||||
namespace gcap
|
||||
{
|
||||
void log_message(gcap_log_level_t level, const char *message_utf8);
|
||||
void log_message_w(gcap_log_level_t level, const wchar_t *message_wide);
|
||||
void log_printf(gcap_log_level_t level, const char *fmt, ...);
|
||||
}
|
||||
|
||||
inline void gcap_log_trace(const char *message_utf8) { gcap::log_message(GCAP_LOG_TRACE, message_utf8); }
|
||||
inline void gcap_log_debug(const char *message_utf8) { gcap::log_message(GCAP_LOG_DEBUG, message_utf8); }
|
||||
inline void gcap_log_info(const char *message_utf8) { gcap::log_message(GCAP_LOG_INFO, message_utf8); }
|
||||
inline void gcap_log_warn(const char *message_utf8) { gcap::log_message(GCAP_LOG_WARN, message_utf8); }
|
||||
inline void gcap_log_error(const char *message_utf8) { gcap::log_message(GCAP_LOG_ERROR, message_utf8); }
|
||||
inline void gcap_log_debug_w(const wchar_t *message_wide) { gcap::log_message_w(GCAP_LOG_DEBUG, message_wide); }
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,129 @@
|
||||
#pragma once
|
||||
|
||||
#include "gcapture.h"
|
||||
|
||||
#include <d3d11_1.h>
|
||||
#include <d2d1_1.h>
|
||||
#include <dwrite.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <wrl.h>
|
||||
|
||||
class SharedScenePipeline
|
||||
{
|
||||
public:
|
||||
SharedScenePipeline() = default;
|
||||
~SharedScenePipeline() = default;
|
||||
|
||||
bool initialize(ID3D11Device *d3d,
|
||||
ID3D11DeviceContext *ctx,
|
||||
ID2D1DeviceContext *d2d_ctx,
|
||||
IDWriteFactory *dwrite = nullptr,
|
||||
ID2D1SolidColorBrush *white = nullptr,
|
||||
ID2D1SolidColorBrush *black = nullptr);
|
||||
void shutdown();
|
||||
|
||||
bool configurePreview(const gcap_preview_desc_t &desc);
|
||||
void set_source_bit_depth(int bits);
|
||||
int source_bit_depth() const { return preview_source_bit_depth_; }
|
||||
void release_preview_swapchain();
|
||||
|
||||
bool create_shaders_and_states();
|
||||
bool ensure_rt_and_pipeline(int w, int h);
|
||||
uint64_t last_ensure_rt_ns() const { return lastEnsureRtNs_; }
|
||||
uint64_t total_ensure_rt_ns() const { return totalEnsureRtNs_; }
|
||||
uint64_t ensure_rt_calls() const { return ensureRtCalls_; }
|
||||
bool last_ensure_rt_rebuilt() const { return lastEnsureRtRebuilt_; }
|
||||
const char *last_ensure_rt_rebuild_reason() const { return lastEnsureRtReason_; }
|
||||
bool ensure_preview_swapchain(int w, int h);
|
||||
bool preview_swapchain_10bit() const { return preview_swapchain_10bit_; }
|
||||
int preview_swapchain_mode() const { return preview_swapchain_mode_; }
|
||||
bool present_preview(int src_w, int src_h);
|
||||
DXGI_FORMAT preview_backbuffer_format() const;
|
||||
DXGI_FORMAT scene_texture_format() const;
|
||||
DXGI_FORMAT linear_fp16_texture_format() const;
|
||||
bool gpu_overlay_text(const wchar_t *text, int frame_w, int frame_h);
|
||||
bool composite_overlay_to_scene_fp16(int frame_w, int frame_h);
|
||||
bool blit_fp16_to_rgba8(int frame_w, int frame_h);
|
||||
bool upload_argb_frame(const void *data, int frame_w, int frame_h, int src_stride);
|
||||
bool render_uploaded_argb_to_fp16(int frame_w, int frame_h);
|
||||
bool upload_nv12_frame(const uint8_t *y, int stride_y, const uint8_t *uv, int stride_uv, int frame_w, int frame_h);
|
||||
bool upload_p010_frame(const uint8_t *y, int stride_y, const uint8_t *uv, int stride_uv, int frame_w, int frame_h);
|
||||
bool upload_yuy2_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h);
|
||||
bool upload_y210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h);
|
||||
bool upload_v210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h);
|
||||
bool render_uploaded_yuv_to_fp16(gcap_pixfmt_t fmt, int frame_w, int frame_h);
|
||||
bool copy_fp16_to_scene();
|
||||
bool readback_to_frame(int frame_w, int frame_h, uint64_t pts_ns, uint64_t frame_id,
|
||||
gcap_frame_t *out);
|
||||
bool export_scene_rgb10(const wchar_t *base_path, int raw_flags, bool export_tiff, bool export_stats, bool export_gigabyte_raw);
|
||||
|
||||
ID3D11Device *d3d_ = nullptr;
|
||||
ID3D11DeviceContext *ctx_ = nullptr;
|
||||
ID2D1DeviceContext *d2d_ctx_ = nullptr;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv_fp16_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_scene_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_scene_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv_scene_fp16_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_rgba8_to_preview_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_nv12_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_yuy2_packed_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_y210_packed_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_stage_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_scene_stage_fp16_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> cs_params_;
|
||||
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> rt_uav_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11VertexShader> vs_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_nv12_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_p010_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_yuy2_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_y210_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_fp16_to_rgba8_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_fp16_to_preview_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_composite_overlay_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11InputLayout> il_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> vb_;
|
||||
Microsoft::WRL::ComPtr<ID3D11SamplerState> samp_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1Bitmap1> d2d_bitmap_rt_;
|
||||
|
||||
Microsoft::WRL::ComPtr<IDWriteFactory> dwrite_;
|
||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> d2d_white_;
|
||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> d2d_black_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> overlay_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> overlay_rtv_;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> overlay_srv_;
|
||||
|
||||
void *preview_hwnd_ = nullptr;
|
||||
bool preview_enabled_ = false;
|
||||
bool preview_use_fp16_ = false;
|
||||
int preview_swapchain_mode_ = GCAP_PREVIEW_BITDEPTH_10BIT;
|
||||
int preview_source_bit_depth_ = 0;
|
||||
bool preview_swapchain_10bit_ = false;
|
||||
DXGI_FORMAT preview_swapchain_format_ = DXGI_FORMAT_UNKNOWN;
|
||||
int preview_w_ = 0;
|
||||
int preview_h_ = 0;
|
||||
|
||||
|
||||
int rt_w_ = 0;
|
||||
int rt_h_ = 0;
|
||||
uint64_t lastEnsureRtNs_ = 0;
|
||||
uint64_t totalEnsureRtNs_ = 0;
|
||||
uint64_t ensureRtCalls_ = 0;
|
||||
bool lastEnsureRtRebuilt_ = false;
|
||||
const char *lastEnsureRtReason_ = "never";
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGISwapChain1> preview_swapchain_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> preview_backbuf_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> preview_rtv_;
|
||||
};
|
||||
@@ -0,0 +1,197 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define GDRIVER_ABI_VERSION_MAJOR 0u
|
||||
#define GDRIVER_ABI_VERSION_MINOR 1u
|
||||
#define GDRIVER_ABI_VERSION_PATCH 0u
|
||||
|
||||
#define GDRIVER_ABI_MAKE_VERSION(major, minor, patch) \
|
||||
((((uint32_t)(major) & 0xffu) << 24) | (((uint32_t)(minor) & 0xffu) << 16) | ((uint32_t)(patch) & 0xffffu))
|
||||
|
||||
#define GDRIVER_ABI_VERSION \
|
||||
GDRIVER_ABI_MAKE_VERSION(GDRIVER_ABI_VERSION_MAJOR, GDRIVER_ABI_VERSION_MINOR, GDRIVER_ABI_VERSION_PATCH)
|
||||
|
||||
#define GDRIVER_MAX_FRIENDLY_NAME 128
|
||||
#define GDRIVER_MAX_SERIAL_NUMBER 64
|
||||
#define GDRIVER_MAX_FIRMWARE_VERSION 64
|
||||
#define GDRIVER_MAX_DRIVER_VERSION 64
|
||||
#define GDRIVER_MAX_PLANES 3
|
||||
|
||||
typedef enum gdriver_status_t
|
||||
{
|
||||
GDRIVER_STATUS_OK = 0,
|
||||
GDRIVER_STATUS_INVALID_ARGUMENT = 1,
|
||||
GDRIVER_STATUS_UNSUPPORTED = 2,
|
||||
GDRIVER_STATUS_INVALID_STATE = 3,
|
||||
GDRIVER_STATUS_NO_DEVICE = 4,
|
||||
GDRIVER_STATUS_TIMEOUT = 5,
|
||||
GDRIVER_STATUS_BUFFER_TOO_SMALL = 6,
|
||||
GDRIVER_STATUS_IO_ERROR = 7
|
||||
} gdriver_status_t;
|
||||
|
||||
typedef enum gdriver_input_t
|
||||
{
|
||||
GDRIVER_INPUT_UNKNOWN = 0,
|
||||
GDRIVER_INPUT_SDI = 1,
|
||||
GDRIVER_INPUT_HDMI = 2
|
||||
} gdriver_input_t;
|
||||
|
||||
typedef enum gdriver_pixel_format_t
|
||||
{
|
||||
GDRIVER_PIXFMT_UNKNOWN = 0,
|
||||
GDRIVER_PIXFMT_YUY2 = 1,
|
||||
GDRIVER_PIXFMT_UYVY = 2,
|
||||
GDRIVER_PIXFMT_RGB24 = 3,
|
||||
GDRIVER_PIXFMT_BGRX32 = 4,
|
||||
GDRIVER_PIXFMT_NV12 = 5,
|
||||
GDRIVER_PIXFMT_P010 = 6,
|
||||
GDRIVER_PIXFMT_Y210 = 7,
|
||||
GDRIVER_PIXFMT_YUV444 = 8
|
||||
} gdriver_pixel_format_t;
|
||||
|
||||
typedef enum gdriver_memory_kind_t
|
||||
{
|
||||
GDRIVER_MEMORY_DRIVER_COPY = 0,
|
||||
GDRIVER_MEMORY_SHARED_SECTION = 1,
|
||||
GDRIVER_MEMORY_DMA_RING = 2
|
||||
} gdriver_memory_kind_t;
|
||||
|
||||
typedef enum gdriver_stream_state_t
|
||||
{
|
||||
GDRIVER_STREAM_STOPPED = 0,
|
||||
GDRIVER_STREAM_CONFIGURED = 1,
|
||||
GDRIVER_STREAM_RUNNING = 2
|
||||
} gdriver_stream_state_t;
|
||||
|
||||
typedef struct gdriver_abi_version_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
uint32_t driver_build;
|
||||
uint32_t reserved0;
|
||||
} gdriver_abi_version_t;
|
||||
|
||||
typedef struct gdriver_device_info_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
char friendly_name[GDRIVER_MAX_FRIENDLY_NAME];
|
||||
char serial_number[GDRIVER_MAX_SERIAL_NUMBER];
|
||||
char firmware_version[GDRIVER_MAX_FIRMWARE_VERSION];
|
||||
char driver_version[GDRIVER_MAX_DRIVER_VERSION];
|
||||
uint32_t supported_inputs_mask;
|
||||
uint32_t supported_pixel_formats_mask;
|
||||
} gdriver_device_info_t;
|
||||
|
||||
typedef struct gdriver_capability_t
|
||||
{
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t fps_num;
|
||||
uint32_t fps_den;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t bit_depth;
|
||||
} gdriver_capability_t;
|
||||
|
||||
typedef struct gdriver_capabilities_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
uint32_t capability_count;
|
||||
uint32_t capability_capacity;
|
||||
gdriver_capability_t capabilities[1];
|
||||
} gdriver_capabilities_t;
|
||||
|
||||
typedef struct gdriver_set_input_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
gdriver_input_t input;
|
||||
} gdriver_set_input_t;
|
||||
|
||||
typedef struct gdriver_stream_config_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
gdriver_input_t input;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t fps_num;
|
||||
uint32_t fps_den;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t buffer_count;
|
||||
gdriver_memory_kind_t memory_kind;
|
||||
uint32_t flags;
|
||||
} gdriver_stream_config_t;
|
||||
|
||||
typedef struct gdriver_signal_status_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
uint32_t signal_locked;
|
||||
gdriver_input_t input;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t fps_num;
|
||||
uint32_t fps_den;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t bit_depth;
|
||||
} gdriver_signal_status_t;
|
||||
|
||||
typedef struct gdriver_wait_frame_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
uint32_t timeout_ms;
|
||||
uint32_t reserved0;
|
||||
} gdriver_wait_frame_t;
|
||||
|
||||
typedef struct gdriver_frame_desc_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
uint64_t frame_id;
|
||||
uint64_t timestamp_ns;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t bit_depth;
|
||||
uint32_t plane_count;
|
||||
uint32_t data_size_bytes;
|
||||
uint32_t plane_offset_bytes[GDRIVER_MAX_PLANES];
|
||||
uint32_t plane_stride_bytes[GDRIVER_MAX_PLANES];
|
||||
uint32_t driver_buffer_index;
|
||||
uint32_t flags;
|
||||
} gdriver_frame_desc_t;
|
||||
|
||||
typedef struct gdriver_release_frame_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
uint64_t frame_id;
|
||||
uint32_t driver_buffer_index;
|
||||
uint32_t reserved0;
|
||||
} gdriver_release_frame_t;
|
||||
|
||||
typedef struct gdriver_stream_stats_t
|
||||
{
|
||||
uint32_t struct_size;
|
||||
uint32_t abi_version;
|
||||
gdriver_stream_state_t state;
|
||||
uint32_t reserved0;
|
||||
uint64_t frames_captured;
|
||||
uint64_t frames_delivered;
|
||||
uint64_t frames_dropped;
|
||||
uint64_t dma_errors;
|
||||
uint64_t interrupt_count;
|
||||
} gdriver_stream_stats_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <guiddef.h>
|
||||
#include <winioctl.h>
|
||||
|
||||
/* 5a09f9e5-7d62-4a65-bce8-d0d9830eb27c */
|
||||
DEFINE_GUID(GUID_DEVINTERFACE_GDRIVER_CAPTURE,
|
||||
0x5a09f9e5, 0x7d62, 0x4a65, 0xbc, 0xe8, 0xd0, 0xd9, 0x83, 0x0e, 0xb2, 0x7c);
|
||||
|
||||
#ifndef FILE_DEVICE_GDRIVER_CAPTURE
|
||||
#define FILE_DEVICE_GDRIVER_CAPTURE 0x8337u
|
||||
#endif
|
||||
|
||||
#define GDRIVER_IOCTL(index, method, access) \
|
||||
CTL_CODE(FILE_DEVICE_GDRIVER_CAPTURE, (index), (method), (access))
|
||||
|
||||
#define IOCTL_GDRIVER_GET_ABI_VERSION \
|
||||
GDRIVER_IOCTL(0x800u, METHOD_BUFFERED, FILE_READ_ACCESS)
|
||||
#define IOCTL_GDRIVER_GET_DEVICE_INFO \
|
||||
GDRIVER_IOCTL(0x801u, METHOD_BUFFERED, FILE_READ_ACCESS)
|
||||
#define IOCTL_GDRIVER_GET_CAPABILITIES \
|
||||
GDRIVER_IOCTL(0x802u, METHOD_BUFFERED, FILE_READ_ACCESS)
|
||||
#define IOCTL_GDRIVER_SET_INPUT \
|
||||
GDRIVER_IOCTL(0x803u, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
||||
#define IOCTL_GDRIVER_CONFIGURE_STREAM \
|
||||
GDRIVER_IOCTL(0x804u, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
||||
#define IOCTL_GDRIVER_START_STREAM \
|
||||
GDRIVER_IOCTL(0x805u, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
||||
#define IOCTL_GDRIVER_STOP_STREAM \
|
||||
GDRIVER_IOCTL(0x806u, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
||||
#define IOCTL_GDRIVER_WAIT_FRAME \
|
||||
GDRIVER_IOCTL(0x807u, METHOD_BUFFERED, FILE_READ_ACCESS)
|
||||
#define IOCTL_GDRIVER_RELEASE_FRAME \
|
||||
GDRIVER_IOCTL(0x808u, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
||||
#define IOCTL_GDRIVER_GET_SIGNAL_STATUS \
|
||||
GDRIVER_IOCTL(0x809u, METHOD_BUFFERED, FILE_READ_ACCESS)
|
||||
#define IOCTL_GDRIVER_GET_STATS \
|
||||
GDRIVER_IOCTL(0x80au, METHOD_BUFFERED, FILE_READ_ACCESS)
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
if (NOT DEFINED GVFG_SDK_VERSION)
|
||||
set(GVFG_SDK_VERSION "0.1.0" CACHE STRING "GVFG SDK version")
|
||||
endif()
|
||||
|
||||
option(GVFG_XDMA_DEBUG_LOG "Enable verbose XDMA flow debug logging in GVFG internal XDMA backend" OFF)
|
||||
|
||||
project(gvfg VERSION ${GVFG_SDK_VERSION} LANGUAGES CXX)
|
||||
|
||||
add_library(gvfg SHARED
|
||||
include/gvfg_capture.h
|
||||
src/backend/xdma/xdma_backend_types.h
|
||||
src/backend/xdma/xdma_capture_session.cpp
|
||||
src/backend/xdma/xdma_capture_session.h
|
||||
src/backend/xdma/xdma_public.h
|
||||
src/gvfg_capture.cpp
|
||||
src/gcapture_log_bridge.cpp
|
||||
${CMAKE_SOURCE_DIR}/sdk/gcapture/src/pipeline/shared_scene_pipeline.cpp
|
||||
)
|
||||
|
||||
set_target_properties(gvfg PROPERTIES
|
||||
AUTOMOC OFF
|
||||
AUTOUIC OFF
|
||||
AUTORCC OFF
|
||||
)
|
||||
|
||||
target_include_directories(gvfg
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/xdma
|
||||
${CMAKE_SOURCE_DIR}/sdk/gdriver_shared/include
|
||||
${CMAKE_SOURCE_DIR}/sdk/gcapture/include
|
||||
${CMAKE_SOURCE_DIR}/sdk/gcapture/src
|
||||
${CMAKE_SOURCE_DIR}/sdk/gcapture/src/pipeline
|
||||
)
|
||||
|
||||
target_compile_definitions(gvfg PRIVATE
|
||||
GVFG_BUILD
|
||||
GVFG_SDK_VERSION="${GVFG_SDK_VERSION}"
|
||||
)
|
||||
|
||||
if (GVFG_XDMA_DEBUG_LOG)
|
||||
target_compile_definitions(gvfg PRIVATE GVFG_XDMA_DEBUG_LOG=1)
|
||||
endif()
|
||||
|
||||
target_link_libraries(gvfg PRIVATE
|
||||
setupapi
|
||||
ole32 user32 windowscodecs
|
||||
dxgi d3d11 d2d1 dwrite D3DCompiler
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(gvfg PRIVATE /utf-8 /EHsc)
|
||||
endif()
|
||||
@@ -0,0 +1,458 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Customer-facing GVFG capture API.
|
||||
*
|
||||
* Include only this header in customer applications. Do not include internal
|
||||
* backend/gdriver headers; those layers are implementation details behind
|
||||
* gvfg.dll.
|
||||
*
|
||||
* Minimal capture flow:
|
||||
*
|
||||
* gvfg_device_info_t devices[GVFG_MAX_DEVICES] = {};
|
||||
* int count = gvfg_enumerate_devices(devices, GVFG_MAX_DEVICES);
|
||||
*
|
||||
* gvfg_handle h = NULL;
|
||||
* gvfg_create(&h);
|
||||
* gvfg_set_callbacks(h, on_frame, on_error, user);
|
||||
* // Optional: gvfg_set_frame_callback_interval(h, 6); // one callback per 6 frames
|
||||
*
|
||||
* // Optional: let the SDK render preview directly into a native HWND.
|
||||
* gvfg_preview_desc_t preview = {};
|
||||
* preview.hwnd = hwnd;
|
||||
* preview.enable_preview = 1;
|
||||
* preview.swapchain_bitdepth = GVFG_PREVIEW_BITDEPTH_AUTO;
|
||||
* gvfg_set_preview(h, &preview);
|
||||
*
|
||||
* gvfg_open(h, devices[0].index);
|
||||
* gvfg_start(h);
|
||||
*
|
||||
* // Capture is now running. Use callbacks for frames/messages and
|
||||
* // gvfg_get_runtime_info() for status.
|
||||
*
|
||||
* gvfg_stop(h);
|
||||
* gvfg_destroy(h);
|
||||
*
|
||||
* Threading notes:
|
||||
* - Frame and error callbacks are called from an SDK worker thread, not from
|
||||
* the UI thread. UI applications should marshal callback work back to their
|
||||
* UI thread.
|
||||
* - The frame data pointer is valid only during the callback. Copy the data if
|
||||
* it must be used after the callback returns.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef GVFG_BUILD
|
||||
#define GVFG_API __declspec(dllexport)
|
||||
#else
|
||||
#define GVFG_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define GVFG_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
GVFG_MAX_DEVICES = 16
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_OK = 0,
|
||||
GVFG_EINVAL = -1, /* Invalid argument, such as NULL handle/output pointer. */
|
||||
GVFG_ENODEV = -2, /* No GVFG device, no signal, or device open failed. */
|
||||
GVFG_ESTATE = -3, /* API was called in the wrong state. */
|
||||
GVFG_EIO = -4, /* Driver/backend I/O failure. */
|
||||
GVFG_ENOTSUP = -5, /* Requested feature or format is not supported. */
|
||||
GVFG_ETIMEOUT = -6 /* Timed out waiting for driver/backend work. */
|
||||
} gvfg_status_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_PREVIEW_BITDEPTH_AUTO = 0, /* Let the SDK choose the best swapchain format. */
|
||||
GVFG_PREVIEW_BITDEPTH_10BIT = 10, /* Prefer a 10-bit preview swapchain when available. */
|
||||
GVFG_PREVIEW_BITDEPTH_8BIT = 8 /* Force an 8-bit preview swapchain. */
|
||||
} gvfg_preview_bitdepth_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int index; /* Device index to pass to gvfg_open(). */
|
||||
char name[128]; /* Display name for UI/logging. UTF-8, null-terminated. */
|
||||
} gvfg_device_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *hwnd; /* Native Windows HWND that stays alive while capture runs. */
|
||||
int enable_preview; /* Non-zero enables SDK-managed preview rendering. */
|
||||
int swapchain_bitdepth; /* gvfg_preview_bitdepth_t value. */
|
||||
} gvfg_preview_desc_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t valid_mask; /* FPGA register read-valid mask: bit0=0x0c, bit1=0x18, bit2=0x1c, bit3=0x180. */
|
||||
int width_valid; /* Non-zero when FPGA 0x10 read succeeded. */
|
||||
int height_valid; /* Non-zero when FPGA 0x14 read succeeded. */
|
||||
uint32_t width_raw; /* Raw FPGA 0x10 width register. */
|
||||
uint32_t height_raw; /* Raw FPGA 0x14 height register. */
|
||||
uint32_t video_format_raw; /* Raw FPGA 0x0c value. */
|
||||
int video_format_valid;
|
||||
int video_format_code; /* 0=yuv422, 1=rgb, 2=yuv444, 3=yuv420 */
|
||||
char video_format[16];
|
||||
|
||||
uint32_t frame_rate_raw; /* Raw FPGA 0x18 value. */
|
||||
int frame_rate_valid;
|
||||
int frame_rate_code; /* FPGA frame-rate code from 0x18 low nibble. */
|
||||
char frame_rate_bits[5]; /* 4-bit binary text, for example "0110". */
|
||||
char frame_rate_name[16]; /* None, 23.98, 24, 47.95, ..., or "--" for unsupported codes. */
|
||||
|
||||
uint32_t bit_depth_raw; /* Raw FPGA 0x1c value. */
|
||||
int bit_depth_valid;
|
||||
int bit_depth; /* 8 or 10 when valid. */
|
||||
|
||||
uint32_t status_raw; /* Raw FPGA 0x180 value. */
|
||||
int status_valid;
|
||||
int sdi_locked; /* FPGA 0x180 bit0 */
|
||||
int sdi_ddr_ok; /* FPGA 0x180 bit1 */
|
||||
int hdmi_locked; /* FPGA 0x180 bit2 */
|
||||
int hdmi_ddr_ok; /* FPGA 0x180 bit3 */
|
||||
} gvfg_fpga_signal_status_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width; /* Signal width in pixels, from FPGA when available. */
|
||||
int height; /* Signal height in pixels, from FPGA when available. */
|
||||
double fps; /* Legacy field; GVFG leaves this 0. Use fpga.frame_rate_* instead. */
|
||||
int bit_depth; /* Legacy SDK source-buffer bit depth. Prefer fpga.* and runtime delivered_frame. */
|
||||
char pixel_format[32]; /* Legacy SDK source-buffer format. Prefer fpga.* and runtime delivered_frame. */
|
||||
gvfg_fpga_signal_status_t fpga; /* Raw/decoded FPGA signal metadata. */
|
||||
} gvfg_signal_status_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width; /* Width of frames delivered to the customer callback. */
|
||||
int height; /* Height of frames delivered to the customer callback. */
|
||||
int bit_depth; /* Bit depth of the delivered callback buffer. */
|
||||
char pixel_format[32]; /* Delivered callback buffer format, for example BGRA8. */
|
||||
int valid; /* Non-zero while capture is running after at least one callback frame. */
|
||||
} gvfg_delivered_frame_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gvfg_signal_status_t input_signal; /* FPGA-reported signal metadata plus legacy buffer fields. */
|
||||
gvfg_delivered_frame_info_t delivered_frame; /* Frame buffer delivered by gvfg.dll to the app. */
|
||||
double capture_fps; /* Runtime FPS measured from backend frames seen by the SDK worker. */
|
||||
uint64_t delivered_frames; /* Number of frames delivered to the app callback. */
|
||||
} gvfg_runtime_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int enabled; /* Non-zero when preview was requested. */
|
||||
int active; /* Non-zero when the preview pipeline is currently active. */
|
||||
int width; /* Preview render width. */
|
||||
int height; /* Preview render height. */
|
||||
int swapchain_bitdepth; /* Actual preview swapchain bit depth, usually 8 or 10. */
|
||||
int swapchain_10bit; /* Non-zero when the active swapchain is 10-bit. */
|
||||
char render_path[128]; /* Human-readable preview pipeline description. */
|
||||
char backbuffer_format[64]; /* DXGI backbuffer format name. */
|
||||
} gvfg_preview_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const void *data; /* Frame pixels. Valid only during the frame callback. */
|
||||
int stride; /* Bytes per row for data. */
|
||||
int width; /* Frame width in pixels. */
|
||||
int height; /* Frame height in pixels. */
|
||||
uint64_t pts_ns; /* Presentation timestamp in nanoseconds. */
|
||||
uint64_t frame_id; /* Monotonic frame identifier from the backend. */
|
||||
} gvfg_frame_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_EVENT_VIDEO_IRQ = 1,
|
||||
GVFG_EVENT_PLUG_IN = 2,
|
||||
GVFG_EVENT_PLUG_OUT = 3,
|
||||
GVFG_EVENT_CAPTURE_PAUSED = 4,
|
||||
GVFG_EVENT_CAPTURE_RESUMED = 5
|
||||
} gvfg_event_type_t;
|
||||
|
||||
enum
|
||||
{
|
||||
GVFG_EVENT_MASK_VIDEO_IRQ = 1u << 0,
|
||||
GVFG_EVENT_MASK_PLUG_IN = 1u << 1,
|
||||
GVFG_EVENT_MASK_PLUG_OUT = 1u << 2,
|
||||
GVFG_EVENT_MASK_CAPTURE_PAUSED = 1u << 3,
|
||||
GVFG_EVENT_MASK_CAPTURE_RESUMED = 1u << 4,
|
||||
GVFG_EVENT_MASK_HOTPLUG = GVFG_EVENT_MASK_PLUG_IN |
|
||||
GVFG_EVENT_MASK_PLUG_OUT |
|
||||
GVFG_EVENT_MASK_CAPTURE_PAUSED |
|
||||
GVFG_EVENT_MASK_CAPTURE_RESUMED,
|
||||
GVFG_EVENT_MASK_DEFAULT = GVFG_EVENT_MASK_HOTPLUG,
|
||||
GVFG_EVENT_MASK_ALL = GVFG_EVENT_MASK_VIDEO_IRQ | GVFG_EVENT_MASK_HOTPLUG
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gvfg_event_type_t type;
|
||||
uint32_t irq_bit;
|
||||
uint32_t irq_mask;
|
||||
uint64_t timestamp_ns;
|
||||
} gvfg_event_t;
|
||||
|
||||
/* Opaque session handle created by gvfg_create() and released by gvfg_destroy(). */
|
||||
typedef struct gvfg_handle_t *gvfg_handle;
|
||||
|
||||
/* Called when the SDK provides a frame for application use.
|
||||
* This callback is not required for SDK-managed preview rendering.
|
||||
*/
|
||||
typedef void (*gvfg_on_frame_cb)(const gvfg_frame_t *frame, void *user);
|
||||
|
||||
/* Called for capture events such as PLUG_IN / PLUG_OUT. */
|
||||
typedef void (*gvfg_on_event_cb)(const gvfg_event_t *event, void *user);
|
||||
|
||||
/* Called for asynchronous SDK messages or errors. */
|
||||
typedef void (*gvfg_on_error_cb)(gvfg_status_t status, const char *message, void *user);
|
||||
|
||||
/*
|
||||
* Enumerate GVFG capture devices.
|
||||
*
|
||||
* Parameters:
|
||||
* - out_devices: Output array that receives device entries. Pass NULL to query
|
||||
* the device count only.
|
||||
* - max_devices: Number of entries available in out_devices. Values larger
|
||||
* than GVFG_MAX_DEVICES are clamped. Pass 0 when out_devices is NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - When out_devices is non-NULL, returns the number of entries written.
|
||||
* - When out_devices is NULL or max_devices is 0, returns the number of
|
||||
* available devices.
|
||||
* - Returns <= 0 when no device is available.
|
||||
*/
|
||||
GVFG_API int gvfg_enumerate_devices(gvfg_device_info_t *out_devices, int max_devices);
|
||||
|
||||
/*
|
||||
* Create a GVFG capture session.
|
||||
*
|
||||
* Parameters:
|
||||
* - out_handle: Receives the new session handle. Must not be NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if out_handle is NULL.
|
||||
*
|
||||
* The returned handle starts in the closed state. Release it with
|
||||
* gvfg_destroy().
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_create(gvfg_handle *out_handle);
|
||||
|
||||
/*
|
||||
* Destroy a GVFG capture session.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK.
|
||||
*
|
||||
* If capture is still running, it is stopped first. After this call, the handle
|
||||
* must not be used again.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_destroy(gvfg_handle handle);
|
||||
|
||||
/*
|
||||
* Register frame and error callbacks.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - on_frame: Function called when a frame is available. Pass NULL if frame
|
||||
* callbacks are not needed.
|
||||
* - on_error: Function called for asynchronous SDK messages/errors. Pass NULL
|
||||
* if error callbacks are not needed.
|
||||
* - user: Application-defined pointer passed back to both callbacks.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* Callbacks are called from an SDK worker thread. The application must marshal
|
||||
* UI work to its UI thread.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_callbacks(gvfg_handle handle,
|
||||
gvfg_on_frame_cb on_frame,
|
||||
gvfg_on_error_cb on_error,
|
||||
void *user);
|
||||
|
||||
/*
|
||||
* Configure frame callback rate.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - frame_interval: 0 or 1 calls on_frame for every delivered frame. N > 1
|
||||
* calls on_frame once for every N delivered backend frames.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* This only affects the application frame callback. SDK-managed preview
|
||||
* rendering, gvfg_get_runtime_info(), and capture itself continue at full rate.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_frame_callback_interval(gvfg_handle handle,
|
||||
uint32_t frame_interval);
|
||||
|
||||
/*
|
||||
* Register capture event callback.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - on_event: Function called when an enabled capture event occurs. Pass NULL
|
||||
* to disable event callbacks.
|
||||
* - user: Application-defined pointer passed back to the callback.
|
||||
* - event_mask: GVFG_EVENT_MASK_* bits. Pass 0 to use GVFG_EVENT_MASK_DEFAULT.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* VIDEO_IRQ is not included in the default mask because it can occur once per
|
||||
* video frame. Enable GVFG_EVENT_MASK_VIDEO_IRQ only for debug or when the
|
||||
* application explicitly needs it.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_event_callback(gvfg_handle handle,
|
||||
gvfg_on_event_cb on_event,
|
||||
void *user,
|
||||
uint32_t event_mask);
|
||||
|
||||
/*
|
||||
* Configure SDK-managed preview rendering.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - desc: Preview configuration. Must not be NULL. When preview is enabled,
|
||||
* desc->hwnd must be a valid native Windows HWND.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle or desc is NULL.
|
||||
*
|
||||
* This API is optional. If enabled, call it before gvfg_start() and keep the
|
||||
* HWND alive while capture is running. Applications that render frames
|
||||
* themselves can skip this API and use the frame callback instead.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_preview(gvfg_handle handle, const gvfg_preview_desc_t *desc);
|
||||
|
||||
/*
|
||||
* Open a device by index from gvfg_enumerate_devices().
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - device_index: Device index from gvfg_device_info_t::index.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
* - GVFG_ENODEV if the device cannot be opened.
|
||||
* - GVFG_EIO for driver/backend failures.
|
||||
*
|
||||
* The current implementation selects the SDI input internally.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_open(gvfg_handle handle, int device_index);
|
||||
|
||||
/*
|
||||
* Configure and start capture on an opened device.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Opened session handle.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success, including when capture is already running.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
* - GVFG_ESTATE if no device is open.
|
||||
* - GVFG_EIO or another status code if stream configuration/start fails.
|
||||
*
|
||||
* After success, frames and asynchronous messages are delivered through the
|
||||
* callbacks registered by gvfg_set_callbacks().
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_start(gvfg_handle handle);
|
||||
|
||||
/*
|
||||
* Stop capture.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success, including when capture is already stopped.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* This waits for the SDK capture worker thread to exit.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_stop(gvfg_handle handle);
|
||||
|
||||
/*
|
||||
* Query current signal information and delivered buffer format.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Opened session handle.
|
||||
* - out_status: Receives signal status. Must not be NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle or out_status is NULL.
|
||||
* - GVFG_ENODEV if no valid signal information is available.
|
||||
*
|
||||
* The FPGA metadata describes the hardware signal. The pixel_format and
|
||||
* bit_depth fields describe the buffer format delivered by the customer API.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_signal_status(gvfg_handle handle, gvfg_signal_status_t *out_status);
|
||||
|
||||
/*
|
||||
* Query runtime capture diagnostics.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Opened or running session handle.
|
||||
* - out_info: Receives runtime information. Must not be NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle or out_info is NULL.
|
||||
*
|
||||
* The result includes current signal status, SDK-measured capture FPS, and the
|
||||
* number of frames delivered by the SDK.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_runtime_info(gvfg_handle handle, gvfg_runtime_info_t *out_info);
|
||||
|
||||
/*
|
||||
* Query SDK-managed preview diagnostics.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - out_info: Receives preview information. Must not be NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle or out_info is NULL.
|
||||
*
|
||||
* This is useful only when the application uses gvfg_set_preview().
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_preview_info(gvfg_handle handle, gvfg_preview_info_t *out_info);
|
||||
|
||||
/*
|
||||
* Convert a GVFG status code to a static English error string.
|
||||
*
|
||||
* Parameters:
|
||||
* - status: Status code returned by a GVFG API.
|
||||
*
|
||||
* Returns:
|
||||
* - Static null-terminated English string. The caller must not free it.
|
||||
*/
|
||||
GVFG_API const char *gvfg_strerror(gvfg_status_t status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,118 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "gdriver_abi.h"
|
||||
|
||||
typedef enum xdma_status_t
|
||||
{
|
||||
XDMA_OK = 0,
|
||||
XDMA_EINVAL,
|
||||
XDMA_ENODEV,
|
||||
XDMA_ESTATE,
|
||||
XDMA_ENOTSUP,
|
||||
XDMA_ETIMEOUT,
|
||||
XDMA_EIO,
|
||||
XDMA_EABI
|
||||
} xdma_status_t;
|
||||
|
||||
typedef struct xdma_device_info_t
|
||||
{
|
||||
char friendly_name[GDRIVER_MAX_FRIENDLY_NAME];
|
||||
char serial_number[GDRIVER_MAX_SERIAL_NUMBER];
|
||||
char firmware_version[GDRIVER_MAX_FIRMWARE_VERSION];
|
||||
char driver_version[GDRIVER_MAX_DRIVER_VERSION];
|
||||
uint32_t supported_inputs_mask;
|
||||
uint32_t supported_pixel_formats_mask;
|
||||
} xdma_device_info_t;
|
||||
|
||||
typedef struct xdma_stream_desc_t
|
||||
{
|
||||
gdriver_input_t input;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t buffer_count;
|
||||
gdriver_memory_kind_t memory_kind;
|
||||
uint32_t flags;
|
||||
} xdma_stream_desc_t;
|
||||
|
||||
typedef struct xdma_signal_status_t
|
||||
{
|
||||
int signal_locked;
|
||||
gdriver_input_t input;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t bit_depth;
|
||||
uint32_t fpga_valid_mask; /* bit0:0x0c, bit1:0x18, bit2:0x1c, bit3:0x180 */
|
||||
uint32_t fpga_width_valid; /* Non-zero when FPGA 0x10 read succeeded. */
|
||||
uint32_t fpga_height_valid; /* Non-zero when FPGA 0x14 read succeeded. */
|
||||
uint32_t fpga_width_raw; /* Raw FPGA 0x10 width register. */
|
||||
uint32_t fpga_height_raw; /* Raw FPGA 0x14 height register. */
|
||||
uint32_t fpga_video_format_raw; /* 0x0c: 0=yuv422, 1=rgb, 2=yuv444, 3=yuv420 */
|
||||
uint32_t fpga_frame_rate_raw; /* 0x18 low nibble: frame-rate code */
|
||||
uint32_t fpga_bit_depth_raw; /* 0x1c: 8 or 10 */
|
||||
uint32_t fpga_status_raw; /* 0x180: bit0 SDI lock, bit1 SDI DDR, bit2 HDMI lock, bit3 HDMI DDR */
|
||||
} xdma_signal_status_t;
|
||||
|
||||
typedef struct xdma_frame_t
|
||||
{
|
||||
const void *data; /* Valid until the next XdmaCaptureSession::wait_frame() or close(). */
|
||||
size_t data_size_bytes;
|
||||
uint64_t frame_id;
|
||||
uint64_t timestamp_ns;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t bit_depth;
|
||||
uint32_t plane_count;
|
||||
uint32_t plane_offset_bytes[GDRIVER_MAX_PLANES];
|
||||
uint32_t plane_stride_bytes[GDRIVER_MAX_PLANES];
|
||||
uint32_t driver_buffer_index;
|
||||
uint32_t flags;
|
||||
} xdma_frame_t;
|
||||
|
||||
typedef struct xdma_stream_stats_t
|
||||
{
|
||||
gdriver_stream_state_t state;
|
||||
uint64_t frames_captured;
|
||||
uint64_t frames_delivered;
|
||||
uint64_t frames_dropped;
|
||||
uint64_t dma_errors;
|
||||
uint64_t interrupt_count;
|
||||
} xdma_stream_stats_t;
|
||||
|
||||
typedef enum xdma_event_type_t
|
||||
{
|
||||
XDMA_EVENT_VIDEO_IRQ = 1,
|
||||
XDMA_EVENT_PLUG_IN = 2,
|
||||
XDMA_EVENT_PLUG_OUT = 3,
|
||||
XDMA_EVENT_CAPTURE_PAUSED = 4,
|
||||
XDMA_EVENT_CAPTURE_RESUMED = 5
|
||||
} xdma_event_type_t;
|
||||
|
||||
enum
|
||||
{
|
||||
XDMA_EVENT_MASK_VIDEO_IRQ = 1u << 0,
|
||||
XDMA_EVENT_MASK_PLUG_IN = 1u << 1,
|
||||
XDMA_EVENT_MASK_PLUG_OUT = 1u << 2,
|
||||
XDMA_EVENT_MASK_CAPTURE_PAUSED = 1u << 3,
|
||||
XDMA_EVENT_MASK_CAPTURE_RESUMED = 1u << 4,
|
||||
XDMA_EVENT_MASK_HOTPLUG = XDMA_EVENT_MASK_PLUG_IN |
|
||||
XDMA_EVENT_MASK_PLUG_OUT |
|
||||
XDMA_EVENT_MASK_CAPTURE_PAUSED |
|
||||
XDMA_EVENT_MASK_CAPTURE_RESUMED,
|
||||
XDMA_EVENT_MASK_DEFAULT = XDMA_EVENT_MASK_HOTPLUG,
|
||||
XDMA_EVENT_MASK_ALL = XDMA_EVENT_MASK_VIDEO_IRQ | XDMA_EVENT_MASK_HOTPLUG
|
||||
};
|
||||
|
||||
typedef struct xdma_event_t
|
||||
{
|
||||
xdma_event_type_t type;
|
||||
uint32_t irq_bit;
|
||||
uint32_t irq_mask;
|
||||
uint64_t timestamp_ns;
|
||||
} xdma_event_t;
|
||||
|
||||
typedef void (*xdma_event_callback_t)(const xdma_event_t *event, void *user);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,128 @@
|
||||
#pragma once
|
||||
|
||||
#include "xdma_backend_types.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
struct XdmaDevice
|
||||
{
|
||||
std::wstring interface_path;
|
||||
std::wstring friendly_name;
|
||||
};
|
||||
|
||||
std::vector<XdmaDevice> enumerate_xdma_devices();
|
||||
|
||||
class XdmaCaptureSession
|
||||
{
|
||||
public:
|
||||
XdmaCaptureSession();
|
||||
XdmaCaptureSession(const XdmaCaptureSession &) = delete;
|
||||
XdmaCaptureSession &operator=(const XdmaCaptureSession &) = delete;
|
||||
~XdmaCaptureSession();
|
||||
|
||||
xdma_status_t open_default();
|
||||
xdma_status_t open_device_index(size_t deviceIndex);
|
||||
xdma_status_t close();
|
||||
|
||||
xdma_status_t set_input(gdriver_input_t input);
|
||||
xdma_status_t get_device_info(xdma_device_info_t &out) const;
|
||||
xdma_status_t get_signal_status(xdma_signal_status_t &out) const;
|
||||
xdma_status_t get_stream_stats(xdma_stream_stats_t &out) const;
|
||||
|
||||
xdma_status_t set_event_callback(xdma_event_callback_t callback, void *user, uint32_t eventMask);
|
||||
xdma_status_t configure_stream(const xdma_stream_desc_t &desc);
|
||||
xdma_status_t start_stream();
|
||||
xdma_status_t stop_stream();
|
||||
xdma_status_t wait_frame(uint32_t timeoutMs, xdma_frame_t &out);
|
||||
xdma_status_t release_frame(const xdma_frame_t &frame);
|
||||
|
||||
const char *last_error() const;
|
||||
|
||||
private:
|
||||
xdma_status_t open_device(const XdmaDevice &device);
|
||||
void close_handles();
|
||||
|
||||
HANDLE open_subdevice(const wchar_t *name) const;
|
||||
int read_device(HANDLE device, long address, DWORD size, uint8_t *buffer) const;
|
||||
int write_device(HANDLE device, long address, DWORD size, const uint8_t *buffer) const;
|
||||
bool read_user_reg(long address, uint32_t &out) const;
|
||||
bool write_user_reg(long address, uint32_t value) const;
|
||||
bool enable_user_event(uint32_t mask);
|
||||
bool disable_user_event(uint32_t mask);
|
||||
|
||||
void event_thread_proc(uint32_t role, uint32_t irqBit);
|
||||
void data_thread_proc();
|
||||
bool start_data_worker();
|
||||
void stop_data_worker();
|
||||
void publish_frame(const uint8_t *data, size_t bytes);
|
||||
void pause_capture_for_plug_out();
|
||||
void resume_capture_after_plug_in();
|
||||
void handle_plug_in_frame_fix(const uint8_t *data, size_t bytes);
|
||||
void pulse_plug_in_frame_fix();
|
||||
void emit_event(xdma_event_type_t type, uint32_t irqBit, uint32_t irqMask) const;
|
||||
|
||||
xdma_status_t fail(xdma_status_t status, const char *where, DWORD winerr = GetLastError()) const;
|
||||
void set_last_error(const std::string &message) const;
|
||||
void clear_last_error() const;
|
||||
|
||||
uint32_t active_input_path() const;
|
||||
uint32_t event_mask(uint32_t role) const;
|
||||
uint32_t video_event_mask() const;
|
||||
uint32_t plug_in_event_mask() const;
|
||||
uint32_t plug_out_event_mask() const;
|
||||
uint32_t active_event_mask() const;
|
||||
long capture_enable_reg() const;
|
||||
size_t frame_size_bytes() const;
|
||||
|
||||
std::wstring base_path_;
|
||||
std::wstring friendly_name_;
|
||||
|
||||
HANDLE user_device_ = INVALID_HANDLE_VALUE;
|
||||
HANDLE c2h_device_[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
||||
HANDLE event_device_[4] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
||||
|
||||
xdma_stream_desc_t stream_desc_{};
|
||||
uint32_t stream_bit_depth_ = 8;
|
||||
gdriver_input_t input_ = GDRIVER_INPUT_SDI;
|
||||
bool opened_ = false;
|
||||
bool configured_ = false;
|
||||
|
||||
std::atomic<bool> running_{false};
|
||||
std::atomic<bool> capture_active_{false};
|
||||
std::atomic<bool> data_worker_stop_{false};
|
||||
std::atomic<int> save_frames_after_plug_in_{0};
|
||||
std::atomic<bool> fix_pulsed_after_plug_in_{false};
|
||||
std::thread event_thread_[4];
|
||||
std::thread data_thread_;
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
std::mutex worker_mutex_;
|
||||
mutable std::mutex event_callback_mutex_;
|
||||
std::condition_variable frame_cv_;
|
||||
std::condition_variable data_cv_;
|
||||
xdma_event_callback_t event_callback_ = nullptr;
|
||||
void *event_callback_user_ = nullptr;
|
||||
uint32_t event_mask_filter_ = XDMA_EVENT_MASK_DEFAULT;
|
||||
uint32_t pending_events_ = 0;
|
||||
std::vector<uint8_t> dma_buffer_;
|
||||
std::vector<uint8_t> latest_frame_;
|
||||
std::vector<uint8_t> delivery_frame_;
|
||||
uint64_t latest_sequence_ = 0;
|
||||
uint64_t delivered_sequence_ = 0;
|
||||
uint64_t wait_timeout_count_ = 0;
|
||||
bool stream_error_ = false;
|
||||
xdma_stream_stats_t stats_{};
|
||||
mutable std::string last_error_;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* XDMA Driver public API
|
||||
*
|
||||
* This header mirrors the public IOCTL values exposed by the Xilinx XDMA
|
||||
* Windows driver. The values are consumed by the GVFG internal XDMA backend.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define XDMA_MAKE_VERSION(major, minor, patch) (((major) << 24) | ((minor) << 16) | (patch))
|
||||
#define XDMA_VERSION_MAJOR(version) (((uint32_t)(version) >> 24) & 0xff)
|
||||
#define XDMA_VERSION_MINOR(version) (((uint32_t)(version) >> 16) & 0xff)
|
||||
#define XDMA_VERSION_PATCH(version) ((uint32_t)(version) & 0xffff)
|
||||
|
||||
#define XDMA_DRIVER_VERSION XDMA_MAKE_VERSION(1, 0, 0)
|
||||
|
||||
#define XDMA_IOCTL(index) CTL_CODE(FILE_DEVICE_UNKNOWN, index, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_XDMA_GET_VERSION XDMA_IOCTL(0x0)
|
||||
#define IOCTL_XDMA_PERF_START XDMA_IOCTL(0x1)
|
||||
#define IOCTL_XDMA_PERF_STOP XDMA_IOCTL(0x2)
|
||||
#define IOCTL_XDMA_PERF_GET XDMA_IOCTL(0x3)
|
||||
#define IOCTL_XDMA_USER_INT_ENABLE XDMA_IOCTL(0x4)
|
||||
#define IOCTL_XDMA_USER_INT_DISABLE XDMA_IOCTL(0x5)
|
||||
|
||||
typedef struct XDMA_PERF_DATA
|
||||
{
|
||||
UINT64 clockCycleCount;
|
||||
UINT64 dataCycleCount;
|
||||
UINT64 pendingCount;
|
||||
} XDMA_PERF_DATA;
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "gcapture.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace gcap
|
||||
{
|
||||
void log_message(gcap_log_level_t, const char *message_utf8)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const char *msg = message_utf8 ? message_utf8 : "";
|
||||
OutputDebugStringA(msg);
|
||||
const size_t len = std::strlen(msg);
|
||||
if (len == 0 || msg[len - 1] != '\n')
|
||||
OutputDebugStringA("\n");
|
||||
#else
|
||||
(void)message_utf8;
|
||||
#endif
|
||||
}
|
||||
|
||||
void log_message_w(gcap_log_level_t level, const wchar_t *message_wide)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!message_wide)
|
||||
{
|
||||
log_message(level, "");
|
||||
return;
|
||||
}
|
||||
const int needed = WideCharToMultiByte(CP_UTF8, 0, message_wide, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (needed <= 0)
|
||||
return;
|
||||
std::string utf8(static_cast<size_t>(needed - 1), '\0');
|
||||
WideCharToMultiByte(CP_UTF8, 0, message_wide, -1, utf8.data(), needed, nullptr, nullptr);
|
||||
log_message(level, utf8.c_str());
|
||||
#else
|
||||
(void)level;
|
||||
(void)message_wide;
|
||||
#endif
|
||||
}
|
||||
|
||||
void log_printf(gcap_log_level_t level, const char *fmt, ...)
|
||||
{
|
||||
if (!fmt)
|
||||
{
|
||||
log_message(level, "");
|
||||
return;
|
||||
}
|
||||
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
std::vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
log_message(level, buf);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user