Files
GVFG_Standalone/samples/gvfg_qt_preview/mainwindow.h
T
Mark.lin 226369df0e Add independent dual-channel preview controls
Compared with f380a8a:

- Let CH0 and CH1 open, start, stop, and preview independently while sharing one device connection.

- Give each channel its own capture worker, preview window, frame ownership, runtime status, and failure reporting.

- Expose channel-indexed zero-copy selection to match the driver IOCTL contract and keep output format selection independent per channel.

- Prevent immediate timeout responses from hot-looping and flooding the Qt event queue.

- Align the CH0 and CH1 controls in equal-width channel panels and update the public and internal documentation.

Validation: Qt uic parsing and git diff --check passed; no build or hardware validation was run.
2026-08-27 17:13:22 +08:00

112 lines
3.2 KiB
C++

#pragma once
#include <gvfg_capture.h>
#include <gvfg_preview.h>
#include <QFile>
#include <QString>
#include <QWidget>
#include <array>
#include <atomic>
#include <cstdint>
#include <mutex>
#include <thread>
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> frameAvailable{false};
std::thread captureThread;
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;
std::atomic<double> previewCallAverageMs{0.0};
std::atomic<double> previewCallMaximumMs{0.0};
std::atomic<double> previewCallWindowMaximumMs{0.0};
std::atomic<uint64_t> previewCallSamples{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 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 joinCaptureThread(int channel);
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();