diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 3a08a2f11..d6a7a56b1 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -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())); @@ -5320,6 +5324,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); @@ -5364,6 +5374,9 @@ void OBSBasic::RecordingStart() if (api) api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED); + if (!diskFullTimer->isActive()) + diskFullTimer->start(1000); + OnActivate(); UpdatePause(); @@ -5428,6 +5441,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(); @@ -5486,6 +5502,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 = @@ -7496,3 +7518,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(); + } +} diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 419c11eac..9f7171a13 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -172,6 +172,8 @@ private: QPointer about; QPointer cpuUsageTimer; + QPointer diskFullTimer; + os_cpu_usage_info_t *cpuUsageInfo = nullptr; OBSService service; @@ -556,6 +558,8 @@ private slots: void SceneCopyFilters(); void ScenePasteFilters(); + void CheckDiskSpaceRemaining(); + private: /* OBS Callbacks */ static void SceneReordered(void *data, calldata_t *params); @@ -579,8 +583,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();