UI: Stop recording when disk space is low

This stops the recording when disk space is low. It is currently
set to stop when disk space is below 500 MB.
This commit is contained in:
Clayton Groeneveld 2019-06-12 04:56:00 -05:00
parent d396b2ec15
commit d9a4842604
2 changed files with 69 additions and 0 deletions

View file

@ -287,6 +287,10 @@ OBSBasic::OBSBasic(QWidget *parent)
SLOT(UpdateCPUUsage()));
cpuUsageTimer->start(3000);
diskFullTimer = new QTimer(this);
connect(diskFullTimer, SIGNAL(timeout()), this,
SLOT(CheckDiskSpaceRemaining()));
QAction *renameScene = new QAction(ui->scenesDock);
renameScene->setShortcutContext(Qt::WidgetWithChildrenShortcut);
connect(renameScene, SIGNAL(triggered()), this, SLOT(EditSceneName()));
@ -5294,6 +5298,12 @@ void OBSBasic::StartRecording()
if (disableOutputsRef)
return;
if (LowDiskSpace()) {
DiskSpaceMessage();
ui->recordButton->setChecked(false);
return;
}
if (api)
api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTING);
@ -5338,6 +5348,9 @@ void OBSBasic::RecordingStart()
if (api)
api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED);
if (!diskFullTimer->isActive())
diskFullTimer->start(1000);
OnActivate();
UpdatePause();
@ -5402,6 +5415,9 @@ void OBSBasic::RecordingStop(int code, QString last_error)
if (api)
api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPED);
if (diskFullTimer->isActive())
diskFullTimer->stop();
if (remuxAfterRecord)
AutoRemux();
@ -5460,6 +5476,12 @@ void OBSBasic::StartReplayBuffer()
return;
}
if (LowDiskSpace()) {
DiskSpaceMessage();
replayBufferButton->setChecked(false);
return;
}
obs_output_t *output = outputHandler->replayBuffer;
obs_data_t *hotkeys = obs_hotkeys_save_output(output);
obs_data_array_t *bindings =
@ -7456,3 +7478,42 @@ void OBSBasic::UpdatePause(bool activate)
pause.reset();
}
}
#define MBYTE (1024ULL * 1024ULL)
#define MBYTES_LEFT_STOP_REC 50ULL
#define MAX_BYTES_LEFT (MBYTES_LEFT_STOP_REC * MBYTE)
void OBSBasic::DiskSpaceMessage()
{
blog(LOG_ERROR, "Recording stopped because of low disk space");
OBSMessageBox::critical(this, QTStr("Output.RecordNoSpace.Title"),
QTStr("Output.RecordNoSpace.Msg"));
}
bool OBSBasic::LowDiskSpace()
{
const char *mode = config_get_string(Config(), "Output", "Mode");
const char *path =
strcmp(mode, "Advanced")
? config_get_string(Config(), "SimpleOutput",
"FilePath")
: config_get_string(Config(), "AdvOut", "RecFilePath");
uint64_t num_bytes = os_get_free_disk_space(path);
if (num_bytes < (MAX_BYTES_LEFT))
return true;
else
return false;
}
void OBSBasic::CheckDiskSpaceRemaining()
{
if (LowDiskSpace()) {
StopRecording();
StopReplayBuffer();
DiskSpaceMessage();
}
}

View file

@ -170,6 +170,8 @@ private:
QPointer<OBSAbout> about;
QPointer<QTimer> cpuUsageTimer;
QPointer<QTimer> diskFullTimer;
os_cpu_usage_info_t *cpuUsageInfo = nullptr;
OBSService service;
@ -540,6 +542,8 @@ private slots:
void SceneCopyFilters();
void ScenePasteFilters();
void CheckDiskSpaceRemaining();
private:
/* OBS Callbacks */
static void SceneReordered(void *data, calldata_t *params);
@ -563,8 +567,12 @@ private:
static void HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed);
void AutoRemux();
void UpdatePause(bool activate = true);
bool LowDiskSpace();
void DiskSpaceMessage();
public:
OBSSource GetProgramSource();
OBSScene GetCurrentScene();