summaryrefslogtreecommitdiffstats
path: root/src/recording
diff options
context:
space:
mode:
authorDaniel Poelzleithner <git@poelzi.org>2018-04-25 22:38:02 +0200
committerDaniel Poelzleithner <git@poelzi.org>2018-04-25 22:38:02 +0200
commit7de52df603bc7bd935229be79aec02dc308a17a3 (patch)
tree521cceae5d7fb7bcfbc769b21891155eecf0cf98 /src/recording
parent54d15e3b6d6878131e36f2dac8d1b6180a8bf06b (diff)
Check for free diskspace when recording
Check every 1MB of written stream for free diskspace. Warn the user if free space drops below 1GB. Not supported on Windows + QT4, QT5 should be fine.
Diffstat (limited to 'src/recording')
-rw-r--r--src/recording/recordingmanager.cpp62
-rw-r--r--src/recording/recordingmanager.h4
2 files changed, 66 insertions, 0 deletions
diff --git a/src/recording/recordingmanager.cpp b/src/recording/recordingmanager.cpp
index 0c31478829..afc4405133 100644
--- a/src/recording/recordingmanager.cpp
+++ b/src/recording/recordingmanager.cpp
@@ -3,8 +3,17 @@
#include <QMutex>
#include <QDir>
#include <QtDebug>
+#include <QDebug>
+#include <QMessageBox>
#include <climits>
+#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
+#include <QStorageInfo>
+#elif not __WINDOWS__
+#include <sys/statvfs.h>
+#endif
+
+
#include "control/controlproxy.h"
#include "control/controlpushbutton.h"
#include "engine/enginemaster.h"
@@ -14,6 +23,9 @@
#include "recording/defs_recording.h"
#include "recording/recordingmanager.h"
+// one gigabyte
+#define MIN_DISK_FREE (qint64)1024*1024*1024
+
RecordingManager::RecordingManager(UserSettingsPointer pConfig, EngineMaster* pEngine)
: m_pConfig(pConfig),
m_recordingDir(""),
@@ -84,6 +96,25 @@ void RecordingManager::slotToggleRecording(double v) {
}
}
+qint64 RecordingManager::getFreeSpace() {
+ // returns the free space on the recording location in bytes
+ // return -1 if the free space could not be determined
+ qint64 rv = -1;
+#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
+ QStorageInfo storage(getRecordingDir());
+ if (storage.isValid()) {
+ rv = storage.bytesAvailable();
+ }
+#elif not __WINDOWS__
+ struct statvfs stats;
+ QByteArray bpath = getRecordingDir().toUtf8();
+ const char *path = bpath.data();
+ statvfs(path, &stats);
+ rv = stats.f_bsize * stats.f_bavail;
+#endif
+ return rv;
+}
+
void RecordingManager::startRecording() {
QString encodingType = m_pConfig->getValueString(
ConfigKey(RECORDING_PREF_KEY, "Encoding"));
@@ -92,6 +123,8 @@ void RecordingManager::startRecording() {
m_secondsRecordedSplit=0;
m_iNumberOfBytesRecorded = 0;
m_secondsRecorded=0;
+ m_dfSilence=0;
+ m_dfCounter=0;
m_split_size = getFileSplitSize();
m_split_time = getFileSplitSeconds();
if (m_split_time < INT_MAX) {
@@ -212,6 +245,35 @@ void RecordingManager::slotBytesRecorded(int bytes)
splitContinueRecording();
}
emit(bytesRecorded(m_iNumberOfBytesRecorded));
+
+ // check for free space
+
+ // we only check every 1 MB of data to minimize syscalls
+ m_dfCounter -= bytes;
+
+ if (m_dfCounter > 0) {
+ return;
+ }
+
+ qint64 dfree = getFreeSpace();
+ // reset counter
+ m_dfCounter = 1024 * 1024;
+ if (dfree == -1) {
+ qDebug() << "can't determine free space";
+ return;
+ }
+ if (dfree > MIN_DISK_FREE) {
+ m_dfSilence = false;
+ } else if (m_dfSilence != true) {
+ // surpress further warnings until the situation has cleared
+ m_dfSilence = true;
+ // we run out of diskspace and should warn the user.
+ // FIXME(poelzi) temporary display a error message. Replace this with Message Infrastructure when ready
+ QMessageBox::warning(
+ NULL,
+ tr("Free Space Warning"),
+ tr("There is less then 1 gb of useable space in the recording folder"));
+ }
}
void RecordingManager::slotIsRecording(bool isRecordingActive, bool error) {
diff --git a/src/recording/recordingmanager.h b/src/recording/recordingmanager.h
index c106f15c10..574ef72f9e 100644
--- a/src/recording/recordingmanager.h
+++ b/src/recording/recordingmanager.h
@@ -72,6 +72,7 @@ class RecordingManager : public QObject
quint64 getFileSplitSize();
unsigned int getFileSplitSeconds();
+ qint64 getFreeSpace();
UserSettingsPointer m_pConfig;
QString m_recordingDir;
@@ -83,6 +84,9 @@ class RecordingManager : public QObject
QString m_recordingLocation;
bool m_bRecording;
+ bool m_dfSilence;
+ qint64 m_dfCounter;
+
// will be a very large number
quint64 m_iNumberOfBytesRecorded;
quint64 m_iNumberOfBytesRecordedSplit;