52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#pragma once
|
||
|
||
#include <chrono>
|
||
#include <filesystem>
|
||
#include <string>
|
||
#include <unordered_map>
|
||
#include <vector>
|
||
|
||
struct RecordFileInfo
|
||
{
|
||
std::string stream; // AHD1_main
|
||
std::string path; // /sata/record/AHD1_main/2025-11-13/10/10-23-17.mp4
|
||
int64_t start_ms; // 文件起始时间(ms)
|
||
int64_t end_ms; // 文件结束时间(ms)
|
||
};
|
||
|
||
struct RecordSegment
|
||
{
|
||
int index; // 段号
|
||
std::string segment_id;
|
||
int64_t start_ms;
|
||
int64_t end_ms;
|
||
std::vector<RecordFileInfo> files;
|
||
};
|
||
|
||
class RecordManager
|
||
{
|
||
public:
|
||
explicit RecordManager(const std::string& base_dir);
|
||
|
||
// 执行一次全扫描
|
||
void scanAll();
|
||
|
||
// 查询时间段的录像段
|
||
std::vector<RecordSegment> querySegments(const std::string& stream, int64_t start_ms, int64_t end_ms);
|
||
|
||
// 根据 segmentId 获取可播放文件列表
|
||
RecordSegment getSegment(const std::string& segmentId);
|
||
|
||
// 调试打印全部索引
|
||
void dumpIndex() const;
|
||
|
||
private:
|
||
std::string base_dir_; // /sata/record/
|
||
std::unordered_map<std::string, std::vector<RecordFileInfo>> index_;
|
||
|
||
// 解析文件名得到 start_ms 和 end_ms
|
||
RecordFileInfo parseFile(const std::filesystem::path& p);
|
||
|
||
// 给一个 stream 的文件列表排序
|
||
void sortStream(const std::string& stream);
|
||
}; |