Separate the SDK and Qt sample build projects
Compared with f612cfd:
- Move the capture SDK, private IOCTL wrapper, and optional preview helper under GVFG_SDK with an independent top-level CMake project and version source.
- Move the Qt preview application into GVFG_Qt_Sample and consume prebuilt SDK DLLs and compiler-specific import libraries through imported CMake targets instead of compiling SDK sources as subdirectories.
- Resolve Qt Creator configuration-specific SDK build directories automatically, copy the three runtime DLLs beside the sample executable, and keep missing MSVC or MinGW artifacts as explicit configure errors.
- Update Release and Debug packaging scripts to read SDK and sample outputs separately, and update the repository build instructions for the two-project workflow.
- Preserve the pre-existing uncommitted device display-name suffix change outside this commit.
Validation: independent MSVC SDK configure/build and independent Qt MSVC sample configure/build passed; the sample build graph contains no SDK implementation sources; git diff --check passed. No MinGW link, runtime launch, capture, audio playback, or hardware validation was run.
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(gvfg_qt_preview LANGUAGES CXX)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
|
||||
if (NOT WIN32)
|
||||
message(FATAL_ERROR "GVFG Qt Sample currently supports Windows only.")
|
||||
endif()
|
||||
|
||||
set(GVFG_SDK_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../GVFG_SDK"
|
||||
CACHE PATH "GVFG SDK source root containing public headers")
|
||||
set(GVFG_SDK_BUILD_DIR "${GVFG_SDK_ROOT}/build"
|
||||
CACHE PATH "Prebuilt GVFG SDK directory containing bin and lib")
|
||||
|
||||
set(_GVFG_INCLUDE_DIR "${GVFG_SDK_ROOT}/sdk/gvfg/include")
|
||||
set(_GVFG_PREVIEW_INCLUDE_DIR "${GVFG_SDK_ROOT}/helpers/gvfg_preview/include")
|
||||
|
||||
if (MSVC)
|
||||
set(_GVFG_IMPLIB_NAME "gvfg.lib")
|
||||
set(_GVFG_PREVIEW_IMPLIB_NAME "gvfg_preview.lib")
|
||||
elseif (MINGW)
|
||||
set(_GVFG_IMPLIB_NAME "libgvfg.dll.a")
|
||||
set(_GVFG_PREVIEW_IMPLIB_NAME "libgvfg_preview.dll.a")
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported compiler. Use MSVC or MinGW on Windows x64.")
|
||||
endif()
|
||||
|
||||
# Accept either one exact SDK build directory or the parent `build` directory
|
||||
# created by Qt Creator. In the latter case, select the current configuration's
|
||||
# child only when it contains this compiler's import libraries.
|
||||
set(_GVFG_RESOLVED_BUILD_DIR "${GVFG_SDK_BUILD_DIR}")
|
||||
if (NOT EXISTS "${_GVFG_RESOLVED_BUILD_DIR}/lib/${_GVFG_IMPLIB_NAME}")
|
||||
if (CMAKE_BUILD_TYPE)
|
||||
file(GLOB _GVFG_BUILD_CANDIDATES LIST_DIRECTORIES true
|
||||
"${GVFG_SDK_BUILD_DIR}/*-${CMAKE_BUILD_TYPE}")
|
||||
foreach(_candidate IN LISTS _GVFG_BUILD_CANDIDATES)
|
||||
if (EXISTS "${_candidate}/bin/gvfg.dll" AND
|
||||
EXISTS "${_candidate}/lib/${_GVFG_IMPLIB_NAME}" AND
|
||||
EXISTS "${_candidate}/lib/${_GVFG_PREVIEW_IMPLIB_NAME}")
|
||||
set(_GVFG_RESOLVED_BUILD_DIR "${_candidate}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(_GVFG_BIN_DIR "${_GVFG_RESOLVED_BUILD_DIR}/bin")
|
||||
set(_GVFG_LIB_DIR "${_GVFG_RESOLVED_BUILD_DIR}/lib")
|
||||
set(_GVFG_IMPLIB "${_GVFG_LIB_DIR}/${_GVFG_IMPLIB_NAME}")
|
||||
set(_GVFG_PREVIEW_IMPLIB "${_GVFG_LIB_DIR}/${_GVFG_PREVIEW_IMPLIB_NAME}")
|
||||
|
||||
message(STATUS "GVFG SDK build: ${_GVFG_RESOLVED_BUILD_DIR}")
|
||||
|
||||
foreach(_required_file
|
||||
"${_GVFG_INCLUDE_DIR}/gvfg_capture.h"
|
||||
"${_GVFG_PREVIEW_INCLUDE_DIR}/gvfg_preview.h"
|
||||
"${_GVFG_BIN_DIR}/gvfg.dll"
|
||||
"${_GVFG_BIN_DIR}/giga_ioctl.dll"
|
||||
"${_GVFG_BIN_DIR}/gvfg_preview.dll"
|
||||
"${_GVFG_IMPLIB}"
|
||||
"${_GVFG_PREVIEW_IMPLIB}")
|
||||
if (NOT EXISTS "${_required_file}")
|
||||
message(FATAL_ERROR
|
||||
"Required prebuilt GVFG SDK file was not found: ${_required_file}\n"
|
||||
"Build/install GVFG_SDK first or set GVFG_SDK_BUILD_DIR.")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
add_library(GVFG::Capture SHARED IMPORTED GLOBAL)
|
||||
set_target_properties(GVFG::Capture PROPERTIES
|
||||
IMPORTED_LOCATION "${_GVFG_BIN_DIR}/gvfg.dll"
|
||||
IMPORTED_IMPLIB "${_GVFG_IMPLIB}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_GVFG_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
add_library(GVFG::Preview SHARED IMPORTED GLOBAL)
|
||||
set_target_properties(GVFG::Preview PROPERTIES
|
||||
IMPORTED_LOCATION "${_GVFG_BIN_DIR}/gvfg_preview.dll"
|
||||
IMPORTED_IMPLIB "${_GVFG_PREVIEW_IMPLIB}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_GVFG_PREVIEW_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Multimedia)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia)
|
||||
|
||||
set(GVFG_QT_PREVIEW_SOURCES
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
mainwindow.h
|
||||
mainwindow.ui
|
||||
previewwindow.cpp
|
||||
previewwindow.h
|
||||
previewwindow.ui
|
||||
)
|
||||
|
||||
if (QT_VERSION_MAJOR GREATER_EQUAL 6)
|
||||
qt_add_executable(gvfg_qt_preview ${GVFG_QT_PREVIEW_SOURCES})
|
||||
else()
|
||||
add_executable(gvfg_qt_preview ${GVFG_QT_PREVIEW_SOURCES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(gvfg_qt_preview PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
Qt${QT_VERSION_MAJOR}::Multimedia
|
||||
GVFG::Capture
|
||||
GVFG::Preview
|
||||
)
|
||||
|
||||
target_compile_definitions(gvfg_qt_preview PRIVATE
|
||||
GVFG_INTERNAL_DIAGNOSTICS=$<IF:$<CONFIG:Debug>,1,0>
|
||||
)
|
||||
|
||||
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
|
||||
"${_GVFG_BIN_DIR}/gvfg.dll"
|
||||
"${_GVFG_BIN_DIR}/giga_ioctl.dll"
|
||||
"${_GVFG_BIN_DIR}/gvfg_preview.dll"
|
||||
$<TARGET_FILE_DIR:gvfg_qt_preview>
|
||||
)
|
||||
|
||||
set_target_properties(gvfg_qt_preview PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
install(TARGETS gvfg_qt_preview
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
# 關鍵交付 Log
|
||||
|
||||
畫面保留原本狀態,不顯示完整交付統計,也不增加設定控制。正常的預覽與音訊佇列取捨不輸出 Log。
|
||||
|
||||
- 預覽排隊逾時或容量不足是顯示節拍取捨,不輸出 Log。只有提交/渲染失敗或序號異常增加時,才記錄 `ERROR preview delivery`。
|
||||
- Audio 播放佇列滿而淘汰舊 PCM 區塊不輸出 Log。只有序號異常或寫入失敗時,才記錄 `ERROR audio delivery`。
|
||||
- 序號缺口、倒退/重複、音訊失敗位元組僅在有異常時附上。
|
||||
- 錯誤最多每 5 秒彙整一次;Stop 會補記尚未輸出的錯誤。
|
||||
- Stop 不列印正常統計摘要。只有資料去向核對不一致時才印 `ERROR delivery accounting mismatch`。正常停止清掉的待處理資料不算運行錯誤。
|
||||
|
||||
## 拿到 Log 後怎麼處理
|
||||
|
||||
`ERROR preview delivery` 表示提交/渲染失敗或 frame ID 異常,需查 Preview API、GPU 與來源序號。APP 持續讀取並釋放每張影像,沒有新增預覽降頻行為。
|
||||
|
||||
預覽使用 Present(0, 0),讓 DXGI 等待呈現相依條件,不做外部重試。SyncInterval 仍為 0,並非每張都保證顯示。預覽改成 FIFO,最多保留 3 張待處理影像(包含正在上傳的容量保留),另有 1 個處理中槽位,共 4 個 GPU 槽。60 FPS 下 3 張約 50 ms;這不是刻意等滿 50 ms 才顯示。從上傳完成入列開始計時,等待超過 50 ms 的影像才丟棄(expired);容量滿時跳過新影像(busy),不替換仍在期限內的舊影像。50 ms 是開始處理前的等待期限,不含 GPU 執行/DXGI Present 等待,不保證端到端延遲或實體螢幕逐張呈現。Stop/關閉/鎖等待只處理 Windows 同步送達的視窗訊息,避免 DXGI 等待 UI 而 UI 又等待 worker;不處理一般排隊輸入或 Qt callbacks。
|
||||
|
||||
Audio 保留原本最多 10 個 PCM 區塊的播放佇列(`kMaxQueuedAudioFrames`);滿時丟掉最舊區塊,再加入新區塊。丟棄區塊、停滯與收音間隔仍保留為內部診斷計數,但不顯示在一般 Log;audio frame 不保證與 video frame 等長。
|
||||
|
||||
播放 write 失敗,或持續回傳 0、兩秒沒有進展,會記錄原因並停止通道;檢查音效裝置後重新 Start。此檢查無法中斷本身永不返回的 write 呼叫。
|
||||
|
||||
統計從 APP 成功取得 SDK frame 開始。SDK ID 連續不能證明更上游沒有丟失;DXGI 接受 Present 不代表實體螢幕已顯示,QAudioSink 接受 PCM 也不代表已實際發聲。已丟掉的原始資料無法靠這些處理補回。
|
||||
|
||||
擷取 API/驅動不修改。新版 APP 需配套的新版 gvfg_preview.dll。後續 GPU 優化修改了共用的轉換原始碼;若要發佈包含該優化的 SDK GPU buffer converter,也需重建其 DLL。尚待 build、播放/預覽異常測試與硬體長測;靜態檢查不能證明零丟失。
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QWidget *window = createMainWindow();
|
||||
window->show();
|
||||
|
||||
const int result = app.exec();
|
||||
delete window;
|
||||
return result;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,148 @@
|
||||
#pragma once
|
||||
|
||||
#include <gvfg_capture.h>
|
||||
#include <gvfg_preview.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
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:
|
||||
struct ChannelRuntime
|
||||
{
|
||||
bool opened = false;
|
||||
gvfg_preview_handle previewHandle = nullptr;
|
||||
std::atomic<bool> running{false};
|
||||
std::atomic<bool> stopRequested{false};
|
||||
std::atomic<bool> signalConnected{false};
|
||||
std::mutex signalMutex;
|
||||
std::condition_variable signalReady;
|
||||
std::atomic<bool> frameAvailable{false};
|
||||
std::atomic<bool> previewVisible{false};
|
||||
std::thread captureThread;
|
||||
std::thread audioThread;
|
||||
std::thread audioPlaybackThread;
|
||||
std::mutex audioQueueMutex;
|
||||
std::condition_variable audioQueueReady;
|
||||
struct AudioPacket { std::vector<uint8_t> pcm; };
|
||||
std::deque<AudioPacket> audioQueue;
|
||||
bool audioEnabled = false;
|
||||
gvfg_audio_format_t audioFormat{};
|
||||
// Audio accounting is protected by audioQueueMutex. Accepted means
|
||||
// written to QAudioSink, not physically played by the device.
|
||||
uint64_t audioReceivedFrames = 0;
|
||||
uint64_t audioReceivedBytes = 0;
|
||||
uint64_t audioAcceptedBytes = 0;
|
||||
uint64_t audioQueuedBytes = 0;
|
||||
uint64_t audioDroppedBytes = 0;
|
||||
uint64_t audioCancelledBytes = 0;
|
||||
uint64_t audioFailedBytes = 0;
|
||||
uint64_t audioIdGaps = 0;
|
||||
uint64_t audioIdResets = 0;
|
||||
uint64_t audioLastId = 0;
|
||||
std::atomic<uint64_t> videoReceived{0}, videoSubmitted{0}, videoSkipped{0}, videoFailed{0};
|
||||
std::atomic<uint64_t> videoIdGaps{0}, videoIdResets{0};
|
||||
std::atomic<uint64_t> videoLastId{0};
|
||||
gvfg_preview_delivery_stats_t previewBaseline{};
|
||||
std::chrono::steady_clock::time_point startupStartTime{};
|
||||
double startupStartCallMs = 0.0;
|
||||
uint64_t lastLoggedVideoIssues = 0, lastLoggedAudioIssues = 0;
|
||||
qint64 lastDeliveryLogMs = 0;
|
||||
std::atomic<double> getFrameAverageMs{0.0};
|
||||
std::atomic<double> getFrameMaximumMs{0.0};
|
||||
std::atomic<double> getFrameWindowMaximumMs{0.0};
|
||||
std::atomic<uint64_t> getFrameSamples{0};
|
||||
uint64_t previewFailureCount = 0;
|
||||
gvfg_signal_status_t cachedSignalStatus{};
|
||||
bool haveCachedSignalStatus = false;
|
||||
QString lastLoggedInputStatus;
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
uint64_t lastDebugDmaErrors = 0;
|
||||
bool haveDebugBaseline = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
void refreshDevices();
|
||||
void showPreviewWindow(int channel);
|
||||
void showFullscreenPreviewWindow(int channel);
|
||||
bool openDevice();
|
||||
bool openChannel(int channel);
|
||||
bool applyOutputFormat(int channel);
|
||||
void updateOutputFormatOptions(int changedChannel = -1);
|
||||
void closeDevice();
|
||||
void startCapture(int channel);
|
||||
void stopCapture(int channel);
|
||||
void stopAllCaptures();
|
||||
bool applyPreview(int channel);
|
||||
void updatePreviewSourceSize(int channel, const gvfg_signal_status_t &signal);
|
||||
void processPendingEvents();
|
||||
void updateSignalStatus(bool queryHardware = true);
|
||||
void updateUiState();
|
||||
void showError(const QString &apiName, gvfg_status_t status, int channel = -1);
|
||||
void openLogFile();
|
||||
bool openLogFilePart();
|
||||
void rotateLogFileIfNeeded();
|
||||
void writeLogFileLine(const QString &line);
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
void writeDiagnosticSnapshot(const QString &statusText);
|
||||
#endif
|
||||
void appendLog(const QString &message);
|
||||
void captureReadLoop(int channel);
|
||||
void audioReadLoop(int channel);
|
||||
void audioPlaybackLoop(int channel);
|
||||
void joinCaptureThread(int channel);
|
||||
void joinAudioThread(int channel);
|
||||
void logDeliveryStatus(int channel, bool finalSnapshot = false);
|
||||
|
||||
static constexpr qint64 kMaxLogFileBytes = 20ll * 1024ll * 1024ll;
|
||||
|
||||
Ui::MainWindow *ui_ = nullptr;
|
||||
std::array<PreviewWindow *, 2> previewWindows_{};
|
||||
std::array<gvfg_device_info_t, GVFG_MAX_DEVICES> devices_{};
|
||||
int deviceCount_ = 0;
|
||||
gvfg_handle handle_ = nullptr;
|
||||
int selectedDeviceIndex_ = -1;
|
||||
std::array<ChannelRuntime, 2> channels_{};
|
||||
QTimer *runtimeStatusTimer_ = nullptr;
|
||||
QString lastSignalStatusText_;
|
||||
QFile logFile_;
|
||||
std::mutex logFileMutex_;
|
||||
QString logDirPath_;
|
||||
QString logFilePath_;
|
||||
QString logSessionStamp_;
|
||||
int logPartIndex_ = 1;
|
||||
};
|
||||
|
||||
QWidget *createMainWindow();
|
||||
@@ -0,0 +1,266 @@
|
||||
<?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="minimumSize">
|
||||
<size>
|
||||
<width>86</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>86</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<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>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="channelPanelsLayout" stretch="1,1">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="channel0GroupBox">
|
||||
<property name="title">
|
||||
<string>CH0</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="channel0GridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="channel0FormatLabel">
|
||||
<property name="text">
|
||||
<string>Output format:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="ch0OutputFormatCombo">
|
||||
<property name="toolTip">
|
||||
<string>Requested CH0 capture output format</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>YUY2 (8-bit 4:2:2)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Y210 (10-bit 4:2:2)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QCheckBox" name="ch0ZeroCopyCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>Must be selected before opening CH0</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Zero-copy</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QCheckBox" name="ch0AudioCheckBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Capture and play CH0 PCM audio together with video</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Audio</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<layout class="QHBoxLayout" name="channel0ButtonLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch0StartButton">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch0StopButton">
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch0PreviewButton">
|
||||
<property name="text">
|
||||
<string>Open view</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch0FullscreenButton">
|
||||
<property name="text">
|
||||
<string>Fullscreen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="channel1GroupBox">
|
||||
<property name="title">
|
||||
<string>CH1</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="channel1GridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="channel1FormatLabel">
|
||||
<property name="text">
|
||||
<string>Output format:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="ch1OutputFormatCombo">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Requested CH1 capture output format</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>YUY2 (8-bit 4:2:2)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Y210 (10-bit 4:2:2)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QCheckBox" name="ch1ZeroCopyCheckBox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Must be selected before opening CH1</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Zero-copy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<layout class="QHBoxLayout" name="channel1ButtonLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch1StartButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch1StopButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch1PreviewButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Open view</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch1FullscreenButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fullscreen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="text">
|
||||
<string>Idle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QPlainTextEdit" name="logEdit">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,148 @@
|
||||
#include "previewwindow.h"
|
||||
#include "ui_previewwindow.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QCloseEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QScreen>
|
||||
#include <QSize>
|
||||
#include <algorithm>
|
||||
|
||||
PreviewWindow::PreviewWindow(QWidget *parent)
|
||||
: QWidget(parent), ui_(new Ui::PreviewWindow)
|
||||
{
|
||||
ui_->setupUi(this);
|
||||
ui_->verticalLayout->setContentsMargins(0, 0, 0, 0);
|
||||
ui_->verticalLayout->setSpacing(0);
|
||||
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::setSourceSize(int sourceWidth, int sourceHeight)
|
||||
{
|
||||
if (sourceWidth <= 0 || sourceHeight <= 0)
|
||||
return;
|
||||
|
||||
if (sourceWidth_ == sourceWidth && sourceHeight_ == sourceHeight && isVisible())
|
||||
return;
|
||||
|
||||
sourceWidth_ = sourceWidth;
|
||||
sourceHeight_ = sourceHeight;
|
||||
|
||||
if (isFullScreen())
|
||||
return;
|
||||
|
||||
QScreen *targetScreen = screen();
|
||||
if (!targetScreen)
|
||||
targetScreen = QGuiApplication::primaryScreen();
|
||||
|
||||
ui_->previewHost->setMinimumSize(QSize(1, 1));
|
||||
ui_->previewHost->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||
|
||||
const QSize currentHostSize = ui_->previewHost->size();
|
||||
const QSize windowOverhead = size() - currentHostSize;
|
||||
|
||||
QSize targetSize(sourceWidth, sourceHeight);
|
||||
if (targetScreen)
|
||||
{
|
||||
const QSize maxSize = targetScreen->availableGeometry().size() - windowOverhead - QSize(16, 48);
|
||||
const QSize boundedSize(std::max(320, maxSize.width()), std::max(180, maxSize.height()));
|
||||
if (targetSize.width() > boundedSize.width() || targetSize.height() > boundedSize.height())
|
||||
targetSize.scale(boundedSize, Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
resize(targetSize + windowOverhead);
|
||||
}
|
||||
|
||||
void PreviewWindow::closePreview()
|
||||
{
|
||||
closeAllowed_ = true;
|
||||
emit previewVisibilityChanged(false);
|
||||
close();
|
||||
}
|
||||
|
||||
void PreviewWindow::showPreview(int sourceWidth, int sourceHeight)
|
||||
{
|
||||
closeAllowed_ = false;
|
||||
setSourceSize(sourceWidth, sourceHeight);
|
||||
if (isFullScreen())
|
||||
showNormal();
|
||||
show();
|
||||
emit previewVisibilityChanged(true);
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void PreviewWindow::showFullscreenPreview(int sourceWidth, int sourceHeight)
|
||||
{
|
||||
closeAllowed_ = false;
|
||||
setSourceSize(sourceWidth, sourceHeight);
|
||||
enterFullscreen();
|
||||
emit previewVisibilityChanged(true);
|
||||
}
|
||||
|
||||
void PreviewWindow::enterFullscreen()
|
||||
{
|
||||
showFullScreen();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void PreviewWindow::exitFullscreen()
|
||||
{
|
||||
if (!isFullScreen())
|
||||
return;
|
||||
|
||||
showNormal();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void PreviewWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (closeAllowed_)
|
||||
{
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
hide();
|
||||
emit previewVisibilityChanged(false);
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void PreviewWindow::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Escape && isFullScreen())
|
||||
{
|
||||
exitFullscreen();
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->key() == Qt::Key_F11)
|
||||
{
|
||||
isFullScreen() ? exitFullscreen() : enterFullscreen();
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
void PreviewWindow::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
isFullScreen() ? exitFullscreen() : enterFullscreen();
|
||||
event->accept();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QKeyEvent;
|
||||
class QMouseEvent;
|
||||
|
||||
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 setSourceSize(int sourceWidth, int sourceHeight);
|
||||
void closePreview();
|
||||
|
||||
public slots:
|
||||
void showPreview(int sourceWidth = 0, int sourceHeight = 0);
|
||||
void showFullscreenPreview(int sourceWidth = 0, int sourceHeight = 0);
|
||||
|
||||
signals:
|
||||
void previewVisibilityChanged(bool visible);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
void enterFullscreen();
|
||||
void exitFullscreen();
|
||||
|
||||
Ui::PreviewWindow *ui_ = nullptr;
|
||||
bool closeAllowed_ = false;
|
||||
int sourceWidth_ = 0;
|
||||
int sourceHeight_ = 0;
|
||||
};
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user