Split GVFG customer API and preview helper
Refactor GVFG into a pull-based customer API with internal debug diagnostics in gvfg_debug.h. Move preview rendering into the separate gvfg_preview helper DLL and update the Qt sample to link it explicitly. Clean legacy callback/preview docs and removed SDK-internal render/log helper sources from the core GVFG DLL.
This commit is contained in:
@@ -17,10 +17,6 @@ if (QT_VERSION_MAJOR GREATER_EQUAL 6)
|
||||
previewwindow.cpp
|
||||
previewwindow.h
|
||||
previewwindow.ui
|
||||
sample_preview_renderer.cpp
|
||||
sample_preview_renderer.h
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/gvfg_log_bridge.cpp
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/render/shared_scene_pipeline.cpp
|
||||
)
|
||||
else()
|
||||
add_executable(gvfg_qt_preview
|
||||
@@ -31,26 +27,17 @@ else()
|
||||
previewwindow.cpp
|
||||
previewwindow.h
|
||||
previewwindow.ui
|
||||
sample_preview_renderer.cpp
|
||||
sample_preview_renderer.h
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/gvfg_log_bridge.cpp
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/render/shared_scene_pipeline.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(gvfg_qt_preview PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
gvfg
|
||||
user32
|
||||
dxgi
|
||||
d3d11
|
||||
D3DCompiler
|
||||
gvfg_preview
|
||||
)
|
||||
|
||||
target_include_directories(gvfg_qt_preview PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/include
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/internal
|
||||
${CMAKE_SOURCE_DIR}/sdk/gvfg/src/render
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "previewwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <gvfg_debug.h>
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QDateTime>
|
||||
#include <QMetaObject>
|
||||
@@ -18,8 +20,6 @@ namespace
|
||||
{
|
||||
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:
|
||||
@@ -166,7 +166,11 @@ bool MainWindow::openDevice()
|
||||
void MainWindow::closeDevice()
|
||||
{
|
||||
stopCapture();
|
||||
previewRenderer_.shutdown();
|
||||
if (previewHandle_)
|
||||
{
|
||||
gvfg_preview_destroy(previewHandle_);
|
||||
previewHandle_ = nullptr;
|
||||
}
|
||||
|
||||
if (signalStatusTimer_)
|
||||
signalStatusTimer_->stop();
|
||||
@@ -235,9 +239,23 @@ void MainWindow::stopCapture()
|
||||
|
||||
bool MainWindow::applyPreview()
|
||||
{
|
||||
if (!previewRenderer_.configure(previewWindow_->nativePreviewHandle()))
|
||||
if (!previewHandle_)
|
||||
{
|
||||
appendLog(QStringLiteral("Preview setup failed: invalid preview window"));
|
||||
const gvfg_preview_status_t st = gvfg_preview_create(&previewHandle_);
|
||||
if (st != GVFG_PREVIEW_OK || !previewHandle_)
|
||||
{
|
||||
appendLog(QStringLiteral("Preview setup failed: %1")
|
||||
.arg(QString::fromUtf8(gvfg_preview_strerror(st))));
|
||||
previewHandle_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const gvfg_preview_status_t st = gvfg_preview_attach_window(previewHandle_, previewWindow_->nativePreviewHandle());
|
||||
if (st != GVFG_PREVIEW_OK)
|
||||
{
|
||||
appendLog(QStringLiteral("Preview setup failed: %1")
|
||||
.arg(QString::fromUtf8(gvfg_preview_strerror(st))));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -246,7 +264,7 @@ bool MainWindow::applyPreview()
|
||||
void MainWindow::updatePreviewSourceSize(const gvfg_runtime_info_t &info)
|
||||
{
|
||||
const auto &signal = info.input_signal;
|
||||
const auto &readFrame = info.callback_frame;
|
||||
const auto &readFrame = info.last_frame;
|
||||
|
||||
if (signal.width > 0 && signal.height > 0)
|
||||
{
|
||||
@@ -278,47 +296,46 @@ void MainWindow::updateSignalStatus(bool writeLog)
|
||||
return;
|
||||
|
||||
const auto &signal = info.input_signal;
|
||||
const auto &readFrame = info.callback_frame;
|
||||
const auto &readFrame = info.last_frame;
|
||||
gvfg_debug_fpga_signal_raw_t fpgaRaw{};
|
||||
const bool haveRaw = gvfg_debug_get_fpga_signal_raw(handle_, &fpgaRaw) == GVFG_OK;
|
||||
if (previewWindow_->isVisible())
|
||||
updatePreviewSourceSize(info);
|
||||
|
||||
const QString fpgaResolution = (signal.width > 0 && signal.height > 0)
|
||||
? QStringLiteral("%1x%2").arg(signal.width).arg(signal.height)
|
||||
: QStringLiteral("--");
|
||||
const QString frameRateText = signal.frame_rate_code >= 0
|
||||
? QStringLiteral("%1 (%2)")
|
||||
.arg(QString::fromLatin1(signal.frame_rate_bits))
|
||||
.arg(QString::fromLatin1(signal.frame_rate_name))
|
||||
: QStringLiteral("--");
|
||||
const QString formatText = signal.video_format_code >= 0
|
||||
? QStringLiteral("%1 (%2)")
|
||||
.arg(signal.video_format_code)
|
||||
.arg(QString::fromLatin1(signal.video_format))
|
||||
: QStringLiteral("--");
|
||||
const QString frameRateText = QString::fromLatin1(signal.frame_rate_name);
|
||||
const QString formatText = QString::fromLatin1(signal.video_format);
|
||||
const QString bitDepthText = signal.bit_depth > 0 ? QString::number(signal.bit_depth) : QStringLiteral("--");
|
||||
const QString line0 = QStringLiteral("FPGA reported | signal=%1 fps=%2 format=%3 bitdepth=%4")
|
||||
.arg(fpgaResolution)
|
||||
.arg(frameRateText)
|
||||
.arg(formatText)
|
||||
.arg(bitDepthText);
|
||||
const QString line2 = QStringLiteral("FPGA status | SDI lock=%1 SDI DDR=%2 HDMI lock=%3 HDMI DDR=%4")
|
||||
const QString line2 = QStringLiteral("Signal lock | SDI=%1 HDMI=%2")
|
||||
.arg(signal.sdi_locked)
|
||||
.arg(signal.sdi_ddr_ok)
|
||||
.arg(signal.hdmi_locked)
|
||||
.arg(signal.hdmi_ddr_ok);
|
||||
const QString lineRaw = QStringLiteral("FPGA raw | size=%1x%2 fmt=%3 fps=%4 bit=%5 status=%6")
|
||||
.arg(signal.raw.width)
|
||||
.arg(signal.raw.height)
|
||||
.arg(hex32(signal.raw.video_format))
|
||||
.arg(hex32(signal.raw.frame_rate))
|
||||
.arg(signal.raw.bit_depth)
|
||||
.arg(hex32(signal.raw.status));
|
||||
const QString line3 = previewRenderer_.active()
|
||||
.arg(signal.hdmi_locked);
|
||||
const QString lineRaw = haveRaw
|
||||
? QStringLiteral("FPGA raw | valid=%1 size=%2x%3 fmt=%4 fps=%5 bit=%6 status=%7")
|
||||
.arg(hex32(fpgaRaw.valid_mask))
|
||||
.arg(fpgaRaw.width_raw)
|
||||
.arg(fpgaRaw.height_raw)
|
||||
.arg(hex32(fpgaRaw.video_format_raw))
|
||||
.arg(hex32(fpgaRaw.frame_rate_raw))
|
||||
.arg(fpgaRaw.bit_depth_raw)
|
||||
.arg(hex32(fpgaRaw.status_raw))
|
||||
: QStringLiteral("FPGA raw | unavailable");
|
||||
gvfg_preview_info_t previewInfo{};
|
||||
const bool previewInfoOk = previewHandle_ &&
|
||||
gvfg_preview_get_info(previewHandle_, &previewInfo) == GVFG_PREVIEW_OK &&
|
||||
previewInfo.active;
|
||||
const QString line3 = previewInfoOk
|
||||
? QStringLiteral("Preview output | frame=%1x%2 format=%3 bitdepth=%4")
|
||||
.arg(previewRenderer_.width())
|
||||
.arg(previewRenderer_.height())
|
||||
.arg(QString::fromUtf8(previewRenderer_.pixelFormat()))
|
||||
.arg(previewRenderer_.bitDepth())
|
||||
.arg(previewInfo.width)
|
||||
.arg(previewInfo.height)
|
||||
.arg(QString::fromUtf8(previewInfo.pixel_format))
|
||||
.arg(previewInfo.bit_depth)
|
||||
: QStringLiteral("Preview output | app renderer inactive");
|
||||
const QString line4 = readFrame.valid
|
||||
? QStringLiteral("Read frame | frame=%1x%2 format=%3 bitdepth=%4")
|
||||
@@ -377,16 +394,12 @@ void MainWindow::captureReadLoop()
|
||||
while (gvfg_poll_event(handle_, &event, 0) == GVFG_OK)
|
||||
{
|
||||
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(this,
|
||||
[this, type, irqBit, irqMask, timestampNs]()
|
||||
[this, type, timestampNs]()
|
||||
{
|
||||
appendLog(QStringLiteral("event %1 irq=%2 mask=%3 ts=%4")
|
||||
appendLog(QStringLiteral("event %1 ts=%2")
|
||||
.arg(type)
|
||||
.arg(irqBit)
|
||||
.arg(hex32(irqMask))
|
||||
.arg(static_cast<qulonglong>(timestampNs)));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
@@ -400,7 +413,8 @@ void MainWindow::captureReadLoop()
|
||||
const int width = frame.width;
|
||||
const int height = frame.height;
|
||||
const uint64_t frameId = frame.frame_id;
|
||||
previewRenderer_.render(frame);
|
||||
if (previewHandle_)
|
||||
gvfg_preview_render_frame(previewHandle_, &frame);
|
||||
gvfg_release_frame(handle_, &frame);
|
||||
|
||||
if (count <= 5 || (count % 60) == 0)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <gvfg_capture.h>
|
||||
|
||||
#include "sample_preview_renderer.h"
|
||||
#include <gvfg_preview.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
@@ -57,7 +56,7 @@ private:
|
||||
std::array<gvfg_device_info_t, GVFG_MAX_DEVICES> devices_{};
|
||||
int deviceCount_ = 0;
|
||||
gvfg_handle handle_ = nullptr;
|
||||
SamplePreviewRenderer previewRenderer_;
|
||||
gvfg_preview_handle previewHandle_ = nullptr;
|
||||
bool captureRunning_ = false;
|
||||
std::atomic<bool> captureStop_{false};
|
||||
std::thread captureThread_;
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
#include "sample_preview_renderer.h"
|
||||
|
||||
#include "gvfg_render_types.h"
|
||||
#include "shared_scene_pipeline.h"
|
||||
|
||||
#include <d3d11_4.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
struct SamplePreviewRenderer::D3DState
|
||||
{
|
||||
ComPtr<ID3D11Device> device;
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
};
|
||||
|
||||
SamplePreviewRenderer::SamplePreviewRenderer() = default;
|
||||
|
||||
SamplePreviewRenderer::~SamplePreviewRenderer()
|
||||
{
|
||||
shutdown();
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::configure(void *hwnd)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
hwnd_ = hwnd;
|
||||
configured_ = hwnd_ != nullptr;
|
||||
if (pipeline_)
|
||||
{
|
||||
gvfg::internal::gvfg_render_preview_desc_t desc{};
|
||||
desc.hwnd = hwnd_;
|
||||
desc.enable_preview = configured_ ? 1 : 0;
|
||||
desc.use_fp16_pipeline = 1;
|
||||
desc.swapchain_10bit = gvfg::internal::GVFG_RENDER_PREVIEW_BITDEPTH_AUTO;
|
||||
pipeline_->configurePreview(desc);
|
||||
}
|
||||
return configured_;
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::render(const gvfg_frame_t &frame)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!configured_ || !hwnd_ || !frame.data || frame.width <= 0 || frame.height <= 0)
|
||||
return false;
|
||||
|
||||
if (!ensureDevice() || !ensurePipeline(frame.width, frame.height, frame.bit_depth > 0 ? frame.bit_depth : 8))
|
||||
return false;
|
||||
|
||||
const auto *base = static_cast<const uint8_t *>(frame.data);
|
||||
gvfg::internal::gvfg_render_pixfmt_t renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
||||
bool uploaded = false;
|
||||
|
||||
switch (frame.pixel_format)
|
||||
{
|
||||
case GVFG_PIXFMT_YUY2:
|
||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
||||
uploaded = pipeline_->upload_yuy2_frame(base, frame.width * 2, frame.width, frame.height);
|
||||
break;
|
||||
case GVFG_PIXFMT_Y210:
|
||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_Y210;
|
||||
uploaded = pipeline_->upload_y210_frame(base, frame.width * 4, frame.width, frame.height);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!uploaded ||
|
||||
!pipeline_->render_uploaded_yuv_to_fp16(renderFmt, frame.width, frame.height) ||
|
||||
!pipeline_->copy_fp16_to_scene())
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
if (!pipeline_->preview_swapchain_10bit())
|
||||
ok = pipeline_->blit_fp16_to_rgba8(frame.width, frame.height);
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
pipeline_->present_preview(frame.width, frame.height);
|
||||
width_ = pipeline_->preview_w_;
|
||||
height_ = pipeline_->preview_h_;
|
||||
bitDepth_ = pipeline_->preview_swapchain_10bit() ? 10 : 8;
|
||||
swapchain10Bit_ = pipeline_->preview_swapchain_10bit();
|
||||
return true;
|
||||
}
|
||||
|
||||
void SamplePreviewRenderer::shutdown()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (pipeline_)
|
||||
pipeline_->release_preview_swapchain();
|
||||
pipeline_.reset();
|
||||
d3d_.reset();
|
||||
configured_ = false;
|
||||
hwnd_ = nullptr;
|
||||
width_ = 0;
|
||||
height_ = 0;
|
||||
bitDepth_ = 0;
|
||||
swapchain10Bit_ = false;
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::active() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return configured_ && pipeline_ && width_ > 0 && height_ > 0;
|
||||
}
|
||||
|
||||
int SamplePreviewRenderer::width() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return width_;
|
||||
}
|
||||
|
||||
int SamplePreviewRenderer::height() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return height_;
|
||||
}
|
||||
|
||||
int SamplePreviewRenderer::bitDepth() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return bitDepth_;
|
||||
}
|
||||
|
||||
const char *SamplePreviewRenderer::pixelFormat() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return swapchain10Bit_ ? "RGB10A2" : "BGRA8";
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::ensureDevice()
|
||||
{
|
||||
if (d3d_ && d3d_->device && d3d_->context)
|
||||
return true;
|
||||
|
||||
auto state = std::make_unique<D3DState>();
|
||||
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
||||
#ifdef _DEBUG
|
||||
flags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
D3D_FEATURE_LEVEL levels[] = {D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0};
|
||||
D3D_FEATURE_LEVEL got{};
|
||||
HRESULT hr = D3D11CreateDevice(nullptr,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
flags,
|
||||
levels,
|
||||
_countof(levels),
|
||||
D3D11_SDK_VERSION,
|
||||
&state->device,
|
||||
&got,
|
||||
&state->context);
|
||||
#ifdef _DEBUG
|
||||
if (FAILED(hr))
|
||||
{
|
||||
flags &= ~D3D11_CREATE_DEVICE_DEBUG;
|
||||
hr = D3D11CreateDevice(nullptr,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
flags,
|
||||
levels,
|
||||
_countof(levels),
|
||||
D3D11_SDK_VERSION,
|
||||
&state->device,
|
||||
&got,
|
||||
&state->context);
|
||||
}
|
||||
#endif
|
||||
if (FAILED(hr) || !state->device || !state->context)
|
||||
return false;
|
||||
|
||||
ComPtr<ID3D11Multithread> mt;
|
||||
if (SUCCEEDED(state->device.As(&mt)) && mt)
|
||||
mt->SetMultithreadProtected(TRUE);
|
||||
|
||||
d3d_ = std::move(state);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SamplePreviewRenderer::ensurePipeline(int width, int height, int sourceBitDepth)
|
||||
{
|
||||
if (!pipeline_)
|
||||
pipeline_ = std::make_unique<gvfg::internal::SharedScenePipeline>();
|
||||
|
||||
if (!pipeline_->initialize(d3d_->device.Get(), d3d_->context.Get()))
|
||||
return false;
|
||||
|
||||
gvfg::internal::gvfg_render_preview_desc_t desc{};
|
||||
desc.hwnd = hwnd_;
|
||||
desc.enable_preview = configured_ ? 1 : 0;
|
||||
desc.use_fp16_pipeline = 1;
|
||||
desc.swapchain_10bit = gvfg::internal::GVFG_RENDER_PREVIEW_BITDEPTH_AUTO;
|
||||
pipeline_->configurePreview(desc);
|
||||
pipeline_->set_source_bit_depth(sourceBitDepth > 0 ? sourceBitDepth : 8);
|
||||
return pipeline_->ensure_rt_and_pipeline(width, height) &&
|
||||
pipeline_->ensure_preview_swapchain(width, height);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gvfg_capture.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
class SharedScenePipeline;
|
||||
}
|
||||
|
||||
class SamplePreviewRenderer
|
||||
{
|
||||
public:
|
||||
SamplePreviewRenderer();
|
||||
~SamplePreviewRenderer();
|
||||
|
||||
bool configure(void *hwnd);
|
||||
bool render(const gvfg_frame_t &frame);
|
||||
void shutdown();
|
||||
|
||||
bool active() const;
|
||||
int width() const;
|
||||
int height() const;
|
||||
int bitDepth() const;
|
||||
const char *pixelFormat() const;
|
||||
|
||||
private:
|
||||
bool ensureDevice();
|
||||
bool ensurePipeline(int width, int height, int sourceBitDepth);
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
void *hwnd_ = nullptr;
|
||||
bool configured_ = false;
|
||||
int width_ = 0;
|
||||
int height_ = 0;
|
||||
int bitDepth_ = 0;
|
||||
bool swapchain10Bit_ = false;
|
||||
|
||||
struct D3DState;
|
||||
std::unique_ptr<D3DState> d3d_;
|
||||
std::unique_ptr<gvfg::internal::SharedScenePipeline> pipeline_;
|
||||
};
|
||||
Reference in New Issue
Block a user