RecordControlApplication/CheckStorageThread.cpp

62 lines
2.1 KiB
C++
Raw Normal View History

2024-03-04 16:22:40 +08:00
#include "CheckStorageThread.h"
#include "Constant.h"
#include "Log.h"
#include "Tool.h"
#include <QFile>
#include <QMutex>
#include <QWaitCondition>
// 磁盘剩余最小容量
#define THRESHOLD 10 * 1024 * 1024
// 检查间隔
#define INTERVAL 10 * 60 * 1000
extern QString curFilename;
extern QMutex mutex;
extern QWaitCondition condition;
CheckStorageThread::CheckStorageThread()
{
}
/**
* @brief 10
2024-03-04 16:22:40 +08:00
*/
void CheckStorageThread::run()
{
while (true) {
int64_t available = Tool::getAvailableStorage(Constant::MountedPath);
if (available < THRESHOLD) {
Log::info("there are not enough storage, then remove some files...");
emit diskWillFull();
// 获取文件列表
2024-03-04 16:22:40 +08:00
QStringList fileList = Tool::getFileList(QString("%1/%2").arg(Constant::VideoPath).arg(Constant::MainChannel));
if (!fileList.isEmpty()) {
QString filename = fileList.first();
// 判断文件是否再回放,如果在回放就阻塞等待
2024-03-04 16:22:40 +08:00
mutex.lock();
if (filename == curFilename) {
Log::info("{} is playing, wait for play end and remove the files...", filename.toStdString());
condition.wait(&mutex);
Log::info("check thread end wait...");
}
mutex.unlock();
// 删除文件
2024-03-04 16:22:40 +08:00
QString path = QString("%1/%2/%3").arg(Constant::VideoPath).arg(Constant::MainChannel).arg(filename);
bool ret = Tool::removeFile(path);
if (!ret) {
Log::error("remove file {} failed", path.toStdString());
}
path = QString("%1/%2/%3").arg(Constant::VideoPath).arg(Constant::SecondaryChannel).arg(filename);
ret = Tool::removeFile(path);
if (!ret) {
Log::error("remove file {} failed", path.toStdString());
}
}
} else {
emit diskNotFull();
2024-03-04 16:22:40 +08:00
}
QThread::msleep(INTERVAL);
}
}