diff --git a/src/record_manager.cpp b/src/record_manager.cpp index ad9c37b..7217023 100644 --- a/src/record_manager.cpp +++ b/src/record_manager.cpp @@ -6,9 +6,30 @@ #include #include #include +#include #include "logger.hpp" +namespace +{ +std::optional getEarliestRecordMsInternal( + const std::unordered_map>& index_) +{ + int64_t earliest = -1; + + for (auto& kv : index_) + { + for (auto& f : kv.second) + { + if (earliest < 0 || f.start_ms < earliest) earliest = f.start_ms; + } + } + + if (earliest < 0) return std::nullopt; + return earliest; +} +} // namespace + std::shared_ptr g_record_manager = nullptr; extern std::atomic g_running; @@ -125,24 +146,6 @@ bool RecordManager::loadSrsConfig() return true; } -std::optional RecordManager::getEarliestRecordMs() -{ - std::lock_guard lock(index_mutex_); - - int64_t earliest = -1; - - for (auto& kv : index_) - { - for (auto& f : kv.second) - { - if (earliest < 0 || f.start_ms < earliest) earliest = f.start_ms; - } - } - - if (earliest < 0) return std::nullopt; - return earliest; -} - void RecordManager::removeExpiredDays() { namespace fs = std::filesystem; @@ -310,7 +313,11 @@ void RecordManager::startAutoScan(int interval_sec) this->scanAll(); // ======= 新增:打印最早录像时间 + 磁盘使用率 ======= - auto earliestOpt = this->getEarliestRecordMs(); + std::optional earliestOpt; + { + std::lock_guard lock(index_mutex_); + earliestOpt = getEarliestRecordMsInternal(index_); + } if (earliestOpt.has_value()) { std::string tReadable = RecordManager::toReadable(earliestOpt.value());