This commit is contained in:
cxh 2025-11-14 09:55:53 +08:00
parent daf91cb542
commit e95d98f983
3 changed files with 26 additions and 6 deletions

View File

@ -37,6 +37,9 @@ class RecordManager
// 根据 segmentId 获取可播放文件列表 // 根据 segmentId 获取可播放文件列表
RecordSegment getSegment(const std::string& segmentId); RecordSegment getSegment(const std::string& segmentId);
static int64_t toMsTimestamp(const std::string& s);
static std::string toReadable(int64_t ms);
// 调试打印全部索引 // 调试打印全部索引
void dumpIndex() const; void dumpIndex() const;

View File

@ -51,15 +51,12 @@ int main()
// 测试一次查询:你可以换成真实时间戳 // 测试一次查询:你可以换成真实时间戳
std::cout << "\n=== 测试 querySegments() ===\n"; std::cout << "\n=== 测试 querySegments() ===\n";
// 用你的 AHD1_main 做示例
std::string stream = "AHD1_main";
// 随便选一个时间区间,比如 2025-11-13 10:23:00 ~ 11:00:00 // 随便选一个时间区间,比如 2025-11-13 10:23:00 ~ 11:00:00
// 你可以换成真实值 // 你可以换成真实值
long long t1 = 1731464600000; int64_t start = RecordManager::toMsTimestamp("2025-11-13 10:00:00");
long long t2 = 1731467400000; int64_t end = RecordManager::toMsTimestamp("2025-11-13 14:30:00");
auto segments = rm.querySegments(stream, t1, t2); auto segments = rm.querySegments("AHD1_main", start, end);
std::cout << "找到录像段数量 = " << segments.size() << "\n"; std::cout << "找到录像段数量 = " << segments.size() << "\n";

View File

@ -194,6 +194,26 @@ RecordSegment RecordManager::getSegment(const std::string& segmentId)
return {}; return {};
} }
int64_t RecordManager::toMsTimestamp(const std::string& s)
{
std::tm tm = {};
char* ret = strptime(s.c_str(), "%Y-%m-%d %H:%M:%S", &tm);
if (!ret) return -1;
time_t t = mktime(&tm); // local time (UTC+8)
return static_cast<int64_t>(t) * 1000;
}
std::string RecordManager::toReadable(int64_t ms)
{
time_t t = ms / 1000;
std::tm* tm = localtime(&t);
char buf[32];
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
return buf;
}
void RecordManager::dumpIndex() const void RecordManager::dumpIndex() const
{ {
std::cout << "\n=== dumpIndex() ===\n"; std::cout << "\n=== dumpIndex() ===\n";