2013-11-07 16:45:03 -07:00
|
|
|
/******************************************************************************
|
2023-05-18 17:37:26 -07:00
|
|
|
Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
|
|
|
|
|
Zachary Lund <admin@computerquip.com>
|
|
|
|
|
Philippe Groarke <philippe.groarke@gmail.com>
|
2013-11-07 16:45:03 -07:00
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2013-12-02 22:24:38 -07:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-11-07 16:45:03 -07:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2013-11-09 00:19:38 -07:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2013-11-07 16:45:03 -07:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#include "OBSBasic.hpp"
|
2019-04-07 03:34:21 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#include <components/UIValidation.hpp>
|
2021-11-03 21:11:06 +01:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#include <qt-wrappers.hpp>
|
2019-04-23 15:56:30 +08:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#include <QCheckBox>
|
2019-04-23 15:56:30 +08:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
#define REPLAY_BUFFER_START "==== Replay Buffer Start ==========================================="
|
|
|
|
|
#define REPLAY_BUFFER_STOP "==== Replay Buffer Stop ============================================"
|
2019-05-05 20:00:06 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::ReplayBufferActionTriggered()
|
2019-05-05 20:00:06 -07:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (outputHandler->ReplayBufferActive())
|
|
|
|
|
StopReplayBuffer();
|
|
|
|
|
else
|
|
|
|
|
StartReplayBuffer();
|
|
|
|
|
};
|
2019-07-07 15:47:29 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::ShowReplayBufferPauseWarning()
|
2019-07-07 15:47:29 -07:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
auto msgBox = []() {
|
|
|
|
|
QMessageBox msgbox(App()->GetMainWindow());
|
|
|
|
|
msgbox.setWindowTitle(QTStr("Output.ReplayBuffer."
|
|
|
|
|
"PauseWarning.Title"));
|
|
|
|
|
msgbox.setText(QTStr("Output.ReplayBuffer."
|
|
|
|
|
"PauseWarning.Text"));
|
|
|
|
|
msgbox.setIcon(QMessageBox::Icon::Information);
|
|
|
|
|
msgbox.addButton(QMessageBox::Ok);
|
2024-02-29 20:46:07 +00:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
QCheckBox *cb = new QCheckBox(QTStr("DoNotShowAgain"));
|
|
|
|
|
msgbox.setCheckBox(cb);
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
msgbox.exec();
|
2020-04-14 20:16:33 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (cb->isChecked()) {
|
|
|
|
|
config_set_bool(App()->GetUserConfig(), "General", "WarnedAboutReplayBufferPausing", true);
|
|
|
|
|
config_save_safe(App()->GetUserConfig(), "tmp", nullptr);
|
2020-11-12 23:39:32 +01:00
|
|
|
}
|
2024-12-11 17:43:35 +01:00
|
|
|
};
|
2019-10-02 19:44:47 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
bool warned = config_get_bool(App()->GetUserConfig(), "General", "WarnedAboutReplayBufferPausing");
|
|
|
|
|
if (!warned) {
|
|
|
|
|
QMetaObject::invokeMethod(App(), "Exec", Qt::QueuedConnection, Q_ARG(VoidFunc, msgBox));
|
2019-07-07 15:47:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::StartReplayBuffer()
|
2019-07-07 15:47:29 -07:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->replayBuffer)
|
2019-07-07 15:47:29 -07:00
|
|
|
return;
|
2024-12-11 17:43:35 +01:00
|
|
|
if (outputHandler->ReplayBufferActive())
|
|
|
|
|
return;
|
|
|
|
|
if (disableOutputsRef)
|
2019-07-07 15:47:29 -07:00
|
|
|
return;
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!UIValidation::NoSourcesConfirmation(this))
|
|
|
|
|
return;
|
2019-07-07 15:47:29 -07:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!OutputPathValid()) {
|
|
|
|
|
OutputPathInvalidMessage();
|
|
|
|
|
return;
|
2019-07-07 15:47:29 -07:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (LowDiskSpace()) {
|
|
|
|
|
DiskSpaceMessage();
|
|
|
|
|
return;
|
2019-09-27 15:04:07 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnEvent(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING);
|
2019-12-27 17:12:31 +08:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
SaveProject();
|
2019-12-27 17:12:31 +08:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (outputHandler->StartReplayBuffer() && os_atomic_load_bool(&recording_paused)) {
|
|
|
|
|
ShowReplayBufferPauseWarning();
|
2020-09-08 20:29:40 -07:00
|
|
|
}
|
2024-03-28 16:43:12 -04:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::ReplayBufferStopping()
|
2019-06-12 04:56:00 -05:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->replayBuffer)
|
|
|
|
|
return;
|
2019-09-27 15:04:07 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
emit ReplayBufStopping();
|
2019-06-12 04:56:00 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (sysTrayReplayBuffer)
|
|
|
|
|
sysTrayReplayBuffer->setText(QTStr("Basic.Main.StoppingReplayBuffer"));
|
2019-06-12 04:56:00 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
replayBufferStopping = true;
|
|
|
|
|
OnEvent(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING);
|
2019-06-12 04:56:00 -05:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::StopReplayBuffer()
|
2019-06-12 04:56:00 -05:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->replayBuffer)
|
|
|
|
|
return;
|
2019-06-12 04:56:00 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
SaveProject();
|
2019-10-10 20:12:20 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (outputHandler->ReplayBufferActive())
|
|
|
|
|
outputHandler->StopReplayBuffer(replayBufferStopping);
|
2019-10-15 23:20:35 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnDeactivate();
|
2019-10-15 23:20:35 -05:00
|
|
|
}
|
2020-02-14 23:30:34 +11:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::ReplayBufferStart()
|
2020-02-14 23:30:34 +11:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->replayBuffer)
|
|
|
|
|
return;
|
2020-06-13 21:00:55 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
emit ReplayBufStarted();
|
2020-06-13 21:00:55 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (sysTrayReplayBuffer)
|
|
|
|
|
sysTrayReplayBuffer->setText(QTStr("Basic.Main.StopReplayBuffer"));
|
2018-08-23 20:43:44 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
replayBufferStopping = false;
|
|
|
|
|
OnEvent(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED);
|
2020-08-23 05:12:46 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnActivate();
|
2018-08-23 20:43:44 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
blog(LOG_INFO, REPLAY_BUFFER_START);
|
2018-08-23 20:43:44 -05:00
|
|
|
}
|
2021-01-11 23:26:02 -06:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::ReplayBufferSave()
|
2022-09-09 07:20:48 -05:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->replayBuffer)
|
|
|
|
|
return;
|
|
|
|
|
if (!outputHandler->ReplayBufferActive())
|
|
|
|
|
return;
|
2022-09-09 07:20:48 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
calldata_t cd = {0};
|
|
|
|
|
proc_handler_t *ph = obs_output_get_proc_handler(outputHandler->replayBuffer);
|
|
|
|
|
proc_handler_call(ph, "save", &cd);
|
|
|
|
|
calldata_free(&cd);
|
2021-01-11 23:26:02 -06:00
|
|
|
}
|
2021-02-04 06:01:35 -06:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::ReplayBufferSaved()
|
2021-02-04 06:01:35 -06:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->replayBuffer)
|
|
|
|
|
return;
|
|
|
|
|
if (!outputHandler->ReplayBufferActive())
|
|
|
|
|
return;
|
2021-08-19 23:56:49 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
calldata_t cd = {0};
|
|
|
|
|
proc_handler_t *ph = obs_output_get_proc_handler(outputHandler->replayBuffer);
|
|
|
|
|
proc_handler_call(ph, "get_last_replay", &cd);
|
|
|
|
|
std::string path = calldata_string(&cd, "path");
|
|
|
|
|
QString msg = QTStr("Basic.StatusBar.ReplayBufferSavedTo").arg(QT_UTF8(path.c_str()));
|
|
|
|
|
ShowStatusBarMessage(msg);
|
|
|
|
|
lastReplay = path;
|
|
|
|
|
calldata_free(&cd);
|
2020-06-27 02:31:08 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnEvent(OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED);
|
2023-02-10 13:27:08 +01:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
AutoRemux(QT_UTF8(path.c_str()));
|
2023-02-10 13:27:08 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
void OBSBasic::ReplayBufferStop(int code)
|
2020-06-27 02:31:08 +02:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler || !outputHandler->replayBuffer)
|
2020-06-27 02:31:08 +02:00
|
|
|
return;
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
emit ReplayBufStopped();
|
2021-07-03 17:55:47 +12:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (sysTrayReplayBuffer)
|
|
|
|
|
sysTrayReplayBuffer->setText(QTStr("Basic.Main.StartReplayBuffer"));
|
2021-07-03 17:55:47 +12:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
blog(LOG_INFO, REPLAY_BUFFER_STOP);
|
2021-07-03 17:55:47 +12:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
|
|
|
|
|
OBSMessageBox::critical(this, QTStr("Output.RecordFail.Title"), QTStr("Output.RecordFail.Unsupported"));
|
2021-07-03 17:55:47 +12:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
} else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
|
|
|
|
|
OBSMessageBox::warning(this, QTStr("Output.RecordNoSpace.Title"), QTStr("Output.RecordNoSpace.Msg"));
|
2021-11-01 02:16:56 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
} else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
|
|
|
|
|
OBSMessageBox::critical(this, QTStr("Output.RecordError.Title"), QTStr("Output.RecordError.Msg"));
|
2022-07-29 20:31:13 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
} else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
|
|
|
|
|
SysTrayNotify(QTStr("Output.RecordFail.Unsupported"), QSystemTrayIcon::Warning);
|
2024-06-18 14:18:22 -05:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
} else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
|
|
|
|
|
SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"), QSystemTrayIcon::Warning);
|
2024-07-31 10:53:59 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
} else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
|
|
|
|
|
SysTrayNotify(QTStr("Output.RecordError.Msg"), QSystemTrayIcon::Warning);
|
2024-07-31 10:53:59 -04:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnEvent(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED);
|
2024-07-31 10:53:59 -04:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
OnDeactivate();
|
2024-07-31 10:53:59 -04:00
|
|
|
}
|
2024-09-03 16:29:30 +02:00
|
|
|
|
2024-12-11 17:43:35 +01:00
|
|
|
bool OBSBasic::ReplayBufferActive()
|
2024-09-03 16:29:30 +02:00
|
|
|
{
|
2024-12-11 17:43:35 +01:00
|
|
|
if (!outputHandler)
|
|
|
|
|
return false;
|
|
|
|
|
return outputHandler->ReplayBufferActive();
|
2024-09-03 16:29:30 +02:00
|
|
|
}
|