Files
GVFG_Standalone/samples/gvfg_qt_preview/mainwindow.h
T
Mark.lin 3f905d8a09 Add CH0 audio capture and customer runtime diagnostics
Extend the internal driver ABI and public GVFG API for combined CH0 video/audio capture, PCM format discovery, blocking copy-out reads, extra-frame wake events, and coordinated teardown of video and audio readers.

Update the Qt sample with optional CH0 audio playback on a dedicated thread, customer-visible copy/zero-copy timing telemetry, mutually exclusive CH0/CH1 Y210 selection, and a refresh-safe temporary hide for the unsupported CH1 panel.

Harden Win32 error text conversion, document the new stream and ownership contracts, and package giga_ioctl plus the VC143 runtime in customer Debug/Release bundles.

Validation: git diff --check passed before commit. No build, package execution, runtime, audio-device, or capture-hardware test was run.
2026-09-01 12:26:27 +08:00

120 lines
3.5 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::thread audioThread;
bool audioEnabled = false;
gvfg_audio_format_t audioFormat{};
std::atomic<uint64_t> audioFrames{0};
std::atomic<uint64_t> audioBytes{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;
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 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 joinCaptureThread(int channel);
void joinAudioThread(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();