Simplify Qt sample controller boundaries

Compared with 57ad00c:

- Remove the redundant GvfgClient and gvfg_api forwarding layer so the sample calls the public GVFG capture and preview C APIs directly from CaptureController.

- Keep MainWindow limited to widget state, user actions, preview-window presentation, and option synchronization while CaptureController continues to own device, channel, worker, delivery, and logging state.

- Restore the f612cfd customer-visible behavior for hidden CH1 status, Y210 option tooltips, startup log-path reporting, contextual preview errors, timestamped error logging, and zero-copy option status synchronization.

- Preserve the requested device-name number suffixes, MinGW consumer support, video frame release handling, audio read-copy-release queue, QAudioSink playback-thread ownership, delivery accounting, and diagnostic output.

- Destroy and disconnect CaptureController while MainWindow and its UI are still valid, preventing destructor-time callbacks from reaching an object whose derived destructor has completed.

- Use supported QString multi-argument formatting to satisfy clazy without mixing numeric arguments into QString-only overloads.

Validation: git diff --cached --check and focused source/API parity inspection against f612cfd passed. No configure, build, runtime launch, capture, audio playback, device-event, shutdown, or hardware validation was run.
This commit is contained in:
Mark.lin
2026-09-11 16:32:58 +08:00
parent 57ad00c40e
commit 8282724e47
8 changed files with 126 additions and 190 deletions
+28 -13
View File
@@ -1,6 +1,5 @@
#include "mainwindow.h"
#include "capture_controller.h"
#include "gvfg_api.h"
#include "previewwindow.h"
#include "ui_mainwindow.h"
@@ -61,6 +60,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(previewWindows_[channel], &PreviewWindow::previewVisibilityChanged,
this, [this, channel](bool visible) { controller_->setPreviewVisible(channel, visible); });
}
controller_->setChannelStatusVisible(GVFG_CHANNEL_1, kChannel1UiVisible);
connect(controller_, &CaptureController::devicesChanged, this, [this](const QStringList &names) {
ui_->deviceCombo->clear();
@@ -71,7 +71,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(controller_, &CaptureController::stateChanged, this, &MainWindow::updateUiState);
connect(controller_, &CaptureController::statusChanged, ui_->statusLabel, &QLabel::setText);
connect(controller_, &CaptureController::logMessage, this, &MainWindow::appendLogLine);
connect(controller_, &CaptureController::errorOccurred, this, &MainWindow::showError);
connect(controller_, &CaptureController::previewSourceSizeChanged, this,
[this](int channel, int width, int height) {
if (width > 0 && height > 0) previewWindows_[channel]->setSourceSize(width, height);
@@ -84,7 +83,12 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui_->refreshButton, &QPushButton::clicked, controller_, &CaptureController::refreshDevices);
connect(ui_->openButton, &QPushButton::clicked, this, [this] {
if (controller_->deviceOpen()) controller_->closeDevice();
else { controller_->setSelectedDeviceIndex(ui_->deviceCombo->currentData().toInt()); controller_->openDevice(); }
else {
syncControllerOptions(GVFG_CHANNEL_0);
syncControllerOptions(GVFG_CHANNEL_1);
controller_->setSelectedDeviceIndex(ui_->deviceCombo->currentData().toInt());
controller_->openDevice();
}
});
connect(ui_->ch0StartButton, &QPushButton::clicked, this, [this] { syncControllerOptions(0); controller_->startCapture(0); });
connect(ui_->ch1StartButton, &QPushButton::clicked, this, [this] { syncControllerOptions(1); controller_->startCapture(1); });
@@ -103,16 +107,27 @@ MainWindow::MainWindow(QWidget *parent)
};
connect(ui_->ch0OutputFormatCombo, &QComboBox::currentIndexChanged, this, [formatChanged](int) { formatChanged(0); });
connect(ui_->ch1OutputFormatCombo, &QComboBox::currentIndexChanged, this, [formatChanged](int) { formatChanged(1); });
connect(ui_->ch0ZeroCopyCheckBox, &QCheckBox::toggled, this, [this](bool) {
syncControllerOptions(GVFG_CHANNEL_0);
if (controller_->deviceOpen()) controller_->updateSignalStatus(false);
});
connect(ui_->ch1ZeroCopyCheckBox, &QCheckBox::toggled, this, [this](bool) {
syncControllerOptions(GVFG_CHANNEL_1);
if (controller_->deviceOpen()) controller_->updateSignalStatus(false);
});
updateOutputFormatOptions();
updateUiState();
appendLogLine(QStringLiteral("GVFG SDK version | %1").arg(controller_->sdkVersion()));
controller_->logStartupInfo();
controller_->refreshDevices();
}
MainWindow::~MainWindow()
{
controller_->closeDevice();
QObject::disconnect(controller_, nullptr, nullptr, nullptr);
delete controller_;
controller_ = nullptr;
delete previewWindows_[0];
delete previewWindows_[1];
delete ui_;
@@ -144,7 +159,11 @@ void MainWindow::showPreviewWindow(int channel, bool fullscreen)
previewWindows_[channel]->setSourceSize(signal.width, signal.height);
if (fullscreen) previewWindows_[channel]->showFullscreenPreview();
else previewWindows_[channel]->showPreview();
controller_->applyPreview(channel);
if (!controller_->applyPreview(channel))
controller_->logUiMessage(
fullscreen
? QStringLiteral("CH%1 Fullscreen Preview failed: unable to update preview window").arg(channel)
: QStringLiteral("CH%1 Show Preview failed: unable to update preview window").arg(channel));
}
void MainWindow::updateOutputFormatOptions(int changedChannel)
@@ -161,6 +180,10 @@ void MainWindow::updateOutputFormatOptions(int changedChannel)
{
auto *model = qobject_cast<QStandardItemModel *>(combos[channel]->model());
if (model && model->item(y210)) model->item(y210)->setEnabled(enabled[channel]);
combos[channel]->setToolTip(
enabled[channel]
? QStringLiteral("Requested CH%1 capture output format").arg(channel)
: QStringLiteral("Y210 is already selected by the other channel"));
}
}
@@ -186,12 +209,4 @@ void MainWindow::updateUiState()
ui_->channel1GroupBox->setVisible(kChannel1UiVisible);
}
void MainWindow::showError(const QString &apiName, gvfg_status_t status, int channel, const QString &detail)
{
QString message = QStringLiteral("%1 failed: %2").arg(apiName, QString::fromUtf8(gvfg_api::statusText(status)));
if (channel == 0 || channel == 1) message.prepend(QStringLiteral("CH%1 ").arg(channel));
if (!detail.isEmpty()) message += QStringLiteral(" | %1").arg(detail);
appendLogLine(message);
}
void MainWindow::appendLogLine(const QString &line) { ui_->logEdit->appendPlainText(line); }