Skip to content

Commit 2ac15dd

Browse files
committed
Force stop recording if insufficient disk space
1 parent 7f672fb commit 2ac15dd

3 files changed

Lines changed: 46 additions & 6 deletions

File tree

Source/Processors/RecordNode/RecordNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ void RecordNode::checkDiskSpace()
9090
File dataDir(dataDirectory);
9191
int64 freeSpace = dataDir.getBytesFreeOnVolume();
9292

93-
float avaialableBytes = freeSpace / pow(2, 30); //1 GB == 2^30 bytes
93+
float availableBytes = freeSpace / pow(2, 30); //1 GB == 2^30 bytes
9494

95-
if (avaialableBytes < diskSpaceWarningThreshold)
95+
if (availableBytes < diskSpaceWarningThreshold && !isRecording)
9696
{
9797
String msg = "Less than " + String(diskSpaceWarningThreshold) + " GB of disk space available in " + String(dataDirectory.getFullPathName());
9898
msg += ". Recording may fail. Please free up space or change the recording directory.";

Source/Processors/RecordNode/RecordNodeEditor.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,12 @@ FifoMonitor::FifoMonitor(RecordNode* node, uint16 streamId_, String streamName_)
473473
streamId(streamId_),
474474
streamName(streamName_),
475475
fillPercentage(0.0),
476-
stateChangeSinceLastUpdate(false)
476+
stateChangeSinceLastUpdate(false),
477+
dataRate(0.0),
478+
lastUpdateTime(0.0),
479+
lastFreeSpace(0.0),
480+
recordingTimeLeftInSeconds(0)
477481
{
478-
479482
startTimer(500);
480483
setTooltip(streamName);
481484
}
@@ -552,9 +555,41 @@ void FifoMonitor::timerCallback()
552555
if (ratio > 0)
553556
setFillPercentage(1.0f - ratio);
554557

555-
//std::cout << "Setting fill percentage for " << streamId << " to " << 1 - ratio << std::endl;
558+
if (!recordingTimeLeftInSeconds)
559+
setTooltip(String(bytesFree / pow(2, 30)) + " GB available");
560+
561+
float currentTime = Time::getMillisecondCounterHiRes();
562+
563+
// Update data rate and recording time left every 30 seconds
564+
if (recordNode->getRecordingStatus() && currentTime - lastUpdateTime > 30000) {
565+
566+
if (lastUpdateTime == 0.0) {
567+
lastUpdateTime = Time::getMillisecondCounterHiRes();
568+
lastFreeSpace = bytesFree;
569+
}
570+
else
571+
{
572+
dataRate = (lastFreeSpace - bytesFree) / (currentTime - lastUpdateTime); //bytes/ms
573+
lastUpdateTime = currentTime;
574+
lastFreeSpace = bytesFree;
556575

557-
setTooltip(String(bytesFree / pow(2, 30)) + " GB available");
576+
recordingTimeLeftInSeconds = (int) (bytesFree / dataRate / 1000.0f);
577+
578+
LOGD("Data rate: ", dataRate, " bytes/ms");
579+
580+
// Stop recording and show warning when less than 5 minutes of disk space left
581+
if (dataRate > 0 && recordingTimeLeftInSeconds < 60*5) {
582+
CoreServices::setRecordingStatus(false);
583+
String msg = "Recording stopped. Less than 60 seconds of disk space remaining.";
584+
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "WARNING", msg);
585+
}
586+
587+
String msg = String(bytesFree / pow(2, 30)) + " GB available\n";
588+
msg += String(recordingTimeLeftInSeconds / 60) + " minutes remaining\n";
589+
msg += "Data rate: " + String(dataRate * 1000 / pow(2, 20), 2) + " MB/s";
590+
setTooltip(msg);
591+
}
592+
}
558593
}
559594
else /* Subprocessor monitor */
560595
{

Source/Processors/RecordNode/RecordNodeEditor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ private :
9797
Random random;
9898

9999
bool stateChangeSinceLastUpdate;
100+
101+
float dataRate;
102+
float lastFreeSpace;
103+
float lastUpdateTime;
104+
int recordingTimeLeftInSeconds;
100105

101106
};
102107

0 commit comments

Comments
 (0)