Qt: Sync video capture state

This commit is contained in:
Stenzek 2023-07-06 23:18:30 +10:00 committed by Connor McLaughlin
parent 0e78f3f3bc
commit 1fa3111e67
8 changed files with 70 additions and 6 deletions

View File

@ -334,6 +334,14 @@ void Host::SetFullscreen(bool enabled)
{
}
void Host::OnCaptureStarted(const std::string& filename)
{
}
void Host::OnCaptureStopped()
{
}
void Host::RequestExit(bool allow_confirm)
{
}

View File

@ -421,6 +421,8 @@ void MainWindow::connectVMThreadSignals(EmuThread* thread)
connect(thread, &EmuThread::onVMResumed, this, &MainWindow::onVMResumed);
connect(thread, &EmuThread::onVMStopped, this, &MainWindow::onVMStopped);
connect(thread, &EmuThread::onGameChanged, this, &MainWindow::onGameChanged);
connect(thread, &EmuThread::onCaptureStarted, this, &MainWindow::onCaptureStarted);
connect(thread, &EmuThread::onCaptureStopped, this, &MainWindow::onCaptureStopped);
connect(m_ui.actionReset, &QAction::triggered, thread, &EmuThread::resetVM);
connect(m_ui.actionPause, &QAction::toggled, thread, &EmuThread::setVMPaused);
@ -586,6 +588,10 @@ void MainWindow::onToolsVideoCaptureToggled(bool checked)
if (!s_vm_valid)
return;
// Reset the checked state, we'll get updated by the GS thread.
QSignalBlocker sb(m_ui.actionToolsVideoCapture);
m_ui.actionToolsVideoCapture->setChecked(!checked);
if (!checked)
{
g_emu_thread->endCapture();
@ -599,15 +605,29 @@ void MainWindow::onToolsVideoCaptureToggled(bool checked)
QString path(QStringLiteral("%1.%2").arg(QString::fromStdString(GSGetBaseVideoFilename())).arg(container));
path = QFileDialog::getSaveFileName(this, tr("Video Capture"), path, filter);
if (path.isEmpty())
{
QSignalBlocker sb(m_ui.actionToolsVideoCapture);
m_ui.actionToolsVideoCapture->setChecked(false);
return;
}
g_emu_thread->beginCapture(path);
}
void MainWindow::onCaptureStarted(const QString& filename)
{
if (!s_vm_valid)
return;
QSignalBlocker sb(m_ui.actionToolsVideoCapture);
m_ui.actionToolsVideoCapture->setChecked(true);
}
void MainWindow::onCaptureStopped()
{
if (!s_vm_valid)
return;
QSignalBlocker sb(m_ui.actionToolsVideoCapture);
m_ui.actionToolsVideoCapture->setChecked(false);
}
void MainWindow::onSettingsTriggeredFromToolbar()
{
if (s_vm_valid)

View File

@ -183,6 +183,9 @@ private Q_SLOTS:
void onGameChanged(const QString& title, const QString& elf_override, const QString& disc_path,
const QString& serial, quint32 disc_crc, quint32 crc);
void onCaptureStarted(const QString& filename);
void onCaptureStopped();
protected:
void showEvent(QShowEvent* event) override;
void closeEvent(QCloseEvent* event) override;

View File

@ -1186,6 +1186,16 @@ void Host::SetFullscreen(bool enabled)
g_emu_thread->setFullscreen(enabled, true);
}
void Host::OnCaptureStarted(const std::string& filename)
{
emit g_emu_thread->onCaptureStarted(QString::fromStdString(filename));
}
void Host::OnCaptureStopped()
{
emit g_emu_thread->onCaptureStopped();
}
bool QtHost::InitializeConfig()
{
if (!EmuFolders::InitializeCriticalFolders())

View File

@ -158,6 +158,10 @@ Q_SIGNALS:
/// Called when achievements are reloaded/refreshed (e.g. game change, login, option change).
void onAchievementsRefreshed(quint32 id, const QString& game_info_string, quint32 total, quint32 points);
/// Called when video capture starts/stops.
void onCaptureStarted(const QString& filename);
void onCaptureStopped();
protected:
void run();

View File

@ -139,4 +139,8 @@ namespace Host
/// Returns the desired vsync mode, depending on the runtime environment.
VsyncMode GetEffectiveVSyncMode();
/// Called when video capture starts or stops. Called on the MTGS thread.
void OnCaptureStarted(const std::string& filename);
void OnCaptureStopped();
}

View File

@ -794,6 +794,9 @@ bool GSCapture::BeginCapture(float fps, GSVector2i recommendedResolution, float
s_capturing.store(true, std::memory_order_release);
StartEncoderThread();
lock.unlock();
Host::OnCaptureStarted(s_filename);
return true;
}
@ -1300,8 +1303,12 @@ void GSCapture::InternalEndCapture(std::unique_lock<std::mutex>& lock)
void GSCapture::EndCapture()
{
std::unique_lock<std::mutex> lock(s_lock);
InternalEndCapture(lock);
{
std::unique_lock<std::mutex> lock(s_lock);
InternalEndCapture(lock);
}
Host::OnCaptureStopped();
}
bool GSCapture::IsCapturing()

View File

@ -178,6 +178,14 @@ void Host::SetFullscreen(bool enabled)
{
}
void Host::OnCaptureStarted(const std::string& filename)
{
}
void Host::OnCaptureStopped()
{
}
void Host::RequestExit(bool save_state_if_running)
{
}