Revert "Revert "UI: Stop recording when disk space is low""

This reverts commit 8a48a1ba8e.

I have regrets.
master
jp9000 2019-10-02 13:10:29 -07:00
parent 8a48a1ba8e
commit 6929c6a9f1
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()));
@ -5346,6 +5350,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);
@ -5390,6 +5400,9 @@ void OBSBasic::RecordingStart()
if (api)
api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED);
if (!diskFullTimer->isActive())
diskFullTimer->start(1000);
OnActivate();
UpdatePause();
@ -5454,6 +5467,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();
@ -5512,6 +5528,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 =
@ -7521,3 +7543,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

@ -172,6 +172,8 @@ private:
QPointer<OBSAbout> about;
QPointer<QTimer> cpuUsageTimer;
QPointer<QTimer> 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);
@ -581,8 +585,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();