diff --git a/src/Settings/Video.SettingsGroup.json b/src/Settings/Video.SettingsGroup.json index 2b7c9b76dc7eda66caa23395aa1d4439c12b8a88..68088d4e68c7fe160f5beed4678f8b7ed10cf0bb 100644 --- a/src/Settings/Video.SettingsGroup.json +++ b/src/Settings/Video.SettingsGroup.json @@ -75,7 +75,16 @@ "type": "uint32", "min": 100, "units": "MB", - "defaultValue": 2048 + "defaultValue": 10240, + "mobileDefaultValue": 2048 +}, +{ + "name": "EnableStorageLimit", + "shortDescription": "Enable/Disable Limits on Storage Usage", + "longDescription": "When enabled, old video files will be auto-deleted when the total size of QGC-recorded video exceeds the maximum video storage usage.", + "type": "bool", + "defaultValue": false, + "mobileDefaultValue": true }, { "name": "RtspTimeout", diff --git a/src/Settings/VideoSettings.cc b/src/Settings/VideoSettings.cc index a23dc2163ed5fee331413ecdcbb23f48641c3ffc..631a7d14a202390924513fe4984a4e38a6df3759 100644 --- a/src/Settings/VideoSettings.cc +++ b/src/Settings/VideoSettings.cc @@ -28,6 +28,7 @@ const char* VideoSettings::videoGridLinesName = "VideoGridLines"; const char* VideoSettings::showRecControlName = "ShowRecControl"; const char* VideoSettings::recordingFormatName = "RecordingFormat"; const char* VideoSettings::maxVideoSizeName = "MaxVideoSize"; +const char* VideoSettings::enableStorageLimitName = "EnableStorageLimit"; const char* VideoSettings::rtspTimeoutName = "RtspTimeout"; const char* VideoSettings::videoSourceNoVideo = "No Video Available"; @@ -47,6 +48,7 @@ VideoSettings::VideoSettings(QObject* parent) , _showRecControlFact(NULL) , _recordingFormatFact(NULL) , _maxVideoSizeFact(NULL) + , _enableStorageLimitFact(NULL) , _rtspTimeoutFact(NULL) { QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); @@ -169,6 +171,15 @@ Fact* VideoSettings::maxVideoSize(void) return _maxVideoSizeFact; } +Fact* VideoSettings::enableStorageLimit(void) +{ + if (!_enableStorageLimitFact) { + _enableStorageLimitFact = _createSettingsFact(enableStorageLimitName); + } + + return _enableStorageLimitFact; +} + Fact* VideoSettings::rtspTimeout(void) { if (!_rtspTimeoutFact) { diff --git a/src/Settings/VideoSettings.h b/src/Settings/VideoSettings.h index 328c3b304946489a6bda96f2059d4b5f44faa455..e05816a1cc561cbd4b05c029cf8b3c1e36ddb062 100644 --- a/src/Settings/VideoSettings.h +++ b/src/Settings/VideoSettings.h @@ -28,6 +28,7 @@ public: Q_PROPERTY(Fact* showRecControl READ showRecControl CONSTANT) Q_PROPERTY(Fact* recordingFormat READ recordingFormat CONSTANT) Q_PROPERTY(Fact* maxVideoSize READ maxVideoSize CONSTANT) + Q_PROPERTY(Fact* enableStorageLimit READ enableStorageLimit CONSTANT) Q_PROPERTY(Fact* rtspTimeout READ rtspTimeout CONSTANT) Fact* videoSource (void); @@ -39,6 +40,7 @@ public: Fact* showRecControl (void); Fact* recordingFormat (void); Fact* maxVideoSize (void); + Fact* enableStorageLimit(void); Fact* rtspTimeout (void); static const char* videoSettingsGroupName; @@ -52,6 +54,7 @@ public: static const char* showRecControlName; static const char* recordingFormatName; static const char* maxVideoSizeName; + static const char* enableStorageLimitName; static const char* rtspTimeoutName; static const char* videoSourceNoVideo; @@ -70,6 +73,7 @@ private: SettingsFact* _showRecControlFact; SettingsFact* _recordingFormatFact; SettingsFact* _maxVideoSizeFact; + SettingsFact* _enableStorageLimitFact; SettingsFact* _rtspTimeoutFact; }; diff --git a/src/VideoStreaming/VideoReceiver.cc b/src/VideoStreaming/VideoReceiver.cc index d77ffc2a78c6b7b2ff380fcba1f2556f0084643b..5091f215a1bc134c1f65ea02c50dcced9ae1143a 100644 --- a/src/VideoStreaming/VideoReceiver.cc +++ b/src/VideoStreaming/VideoReceiver.cc @@ -549,33 +549,36 @@ VideoReceiver::_onBusMessage(GstBus* bus, GstMessage* msg, gpointer data) void VideoReceiver::_cleanupOldVideos() { - QString savePath = qgcApp()->toolbox()->settingsManager()->appSettings()->videoSavePath(); - QDir videoDir = QDir(savePath); - videoDir.setFilter(QDir::Files | QDir::Readable | QDir::NoSymLinks | QDir::Writable); - videoDir.setSorting(QDir::Time); - //-- All the movie extensions we support - QStringList nameFilters; - for(uint32_t i = 0; i < NUM_MUXES; i++) { - nameFilters << QString("*.") + QString(kVideoExtensions[i]); - } - videoDir.setNameFilters(nameFilters); - //-- get the list of videos stored - QFileInfoList vidList = videoDir.entryInfoList(); - if(!vidList.isEmpty()) { - uint64_t total = 0; - //-- Settings are stored using MB - uint64_t maxSize = (qgcApp()->toolbox()->settingsManager()->videoSettings()->maxVideoSize()->rawValue().toUInt() * 1024 * 1024); - //-- Compute total used storage - for(int i = 0; i < vidList.size(); i++) { - total += vidList[i].size(); + //-- Only perform cleanup if storage limit is enabled + if(qgcApp()->toolbox()->settingsManager()->videoSettings()->enableStorageLimit()->rawValue().toBool()) { + QString savePath = qgcApp()->toolbox()->settingsManager()->appSettings()->videoSavePath(); + QDir videoDir = QDir(savePath); + videoDir.setFilter(QDir::Files | QDir::Readable | QDir::NoSymLinks | QDir::Writable); + videoDir.setSorting(QDir::Time); + //-- All the movie extensions we support + QStringList nameFilters; + for(uint32_t i = 0; i < NUM_MUXES; i++) { + nameFilters << QString("*.") + QString(kVideoExtensions[i]); } - //-- Remove old movies until max size is satisfied. - while(total >= maxSize && !vidList.isEmpty()) { - total -= vidList.last().size(); - qCDebug(VideoReceiverLog) << "Removing old video file:" << vidList.last().filePath(); - QFile file (vidList.last().filePath()); - file.remove(); - vidList.removeLast(); + videoDir.setNameFilters(nameFilters); + //-- get the list of videos stored + QFileInfoList vidList = videoDir.entryInfoList(); + if(!vidList.isEmpty()) { + uint64_t total = 0; + //-- Settings are stored using MB + uint64_t maxSize = (qgcApp()->toolbox()->settingsManager()->videoSettings()->maxVideoSize()->rawValue().toUInt() * 1024 * 1024); + //-- Compute total used storage + for(int i = 0; i < vidList.size(); i++) { + total += vidList[i].size(); + } + //-- Remove old movies until max size is satisfied. + while(total >= maxSize && !vidList.isEmpty()) { + total -= vidList.last().size(); + qCDebug(VideoReceiverLog) << "Removing old video file:" << vidList.last().filePath(); + QFile file (vidList.last().filePath()); + file.remove(); + vidList.removeLast(); + } } } } diff --git a/src/ui/preferences/GeneralSettings.qml b/src/ui/preferences/GeneralSettings.qml index 8a03865c67adeed3914c3675fa060e7b2efa5f31..5440a34e43b4ca4f4db8ccc5c5fb66e919dd5beb 100644 --- a/src/ui/preferences/GeneralSettings.qml +++ b/src/ui/preferences/GeneralSettings.qml @@ -630,7 +630,21 @@ QGCView { anchors.centerIn: parent Row { spacing: ScreenTools.defaultFontPixelWidth - visible: QGroundControl.videoManager.isGStreamer && videoSource.currentIndex && videoSource.currentIndex < 4 && QGroundControl.settingsManager.videoSettings.maxVideoSize.visible + visible: QGroundControl.videoManager.isGStreamer && videoSource.currentIndex && videoSource.currentIndex < 4 && QGroundControl.settingsManager.videoSettings.enableStorageLimit.visible + QGCLabel { + text: qsTr("Auto-Delete Files:") + width: _labelWidth + anchors.verticalCenter: parent.verticalCenter + } + FactCheckBox { + text: "" + fact: QGroundControl.settingsManager.videoSettings.enableStorageLimit + anchors.verticalCenter: parent.verticalCenter + } + } + Row { + spacing: ScreenTools.defaultFontPixelWidth + visible: QGroundControl.videoManager.isGStreamer && videoSource.currentIndex && videoSource.currentIndex < 4 && QGroundControl.settingsManager.videoSettings.maxVideoSize.visible && QGroundControl.settingsManager.videoSettings.enableStorageLimit.value QGCLabel { text: qsTr("Max Storage Usage:") width: _labelWidth