Commit df78b98d authored by dheideman's avatar dheideman

Add disable, different defaults for mobile/desktop to video auto-delete

parent 1b7983d7
......@@ -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",
......
......@@ -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) {
......
......@@ -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;
};
......
......@@ -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();
}
}
}
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment