3#include <boost/filesystem.hpp>
4#include <boost/multi_index_container.hpp>
5#include <boost/multi_index/ordered_index.hpp>
6#include <boost/multi_index/identity.hpp>
7#include <boost/multi_index/member.hpp>
10#define batch_size 1440
12namespace fs = boost::filesystem;
13namespace bmi = boost::multi_index;
19 OrderedCacheOfFiles(std::string& video_folder, uint32_t initial_batch_size = 1440, uint32_t _lowerWaterMark = 1441, uint32_t _upperWaterMark = 2880);
38 std::string
getFileAt(uint64_t timestamp,
bool direction);
44 bool parseFiles(uint64_t start_ts,
bool direction,
bool includeFloorFile =
false,
bool disableBatchSizeCheck =
false, uint64_t skipTS = 0);
45 bool getRandomSeekFile(uint64_t ts,
bool direction, uint64_t& skipMsecs, std::string& fileName);
46 bool getFileFromCache(uint64_t timestamp,
bool direction, std::string& fileName);
52 bool fetchFromCache(std::string& videoFile, uint64_t& start_ts, uint64_t& end_ts);
53 void readVideoStartEnd(std::string& filePath, uint64_t& start_ts, uint64_t& end_ts);
57 void updateCache(std::string& filePath, uint64_t& start_ts, uint64_t& end_ts);
58 std::map<std::string, std::pair<uint64_t, uint64_t>>
getSnapShot();
59 bool probe(boost::filesystem::path dirPath, std::string& videoName);
64 boost::shared_ptr<boost::thread>
mThread =
nullptr;
113 typedef boost::multi_index_container<
117 bmi::ordered_unique<bmi::tag<videoPath>, bmi::member<Video, std::string, &Video::path> >,
120 bmi::ordered_non_unique<bmi::tag<videoTS>, bmi::member<Video, uint64_t, &Video::start_ts> >
uint32_t upperWaterMark
Definition OrderedCacheOfFiles.h:69
bool hourPatternCheck(const boost::filesystem::path &path)
Definition OrderedCacheOfFiles.cpp:900
std::vector< boost::filesystem::path > parseAndSortHourDir(const std::string &rootDir)
Definition OrderedCacheOfFiles.cpp:618
bool refreshCache()
Definition OrderedCacheOfFiles.cpp:871
void cleanCacheOnSeperateThread(bool flag)
Definition OrderedCacheOfFiles.h:31
std::string getNextFileAfter(std::string ¤tFile, bool direction)
Definition OrderedCacheOfFiles.cpp:258
size_t getCacheSize()
Definition OrderedCacheOfFiles.h:47
void readVideoStartEnd(std::string &filePath, uint64_t &start_ts, uint64_t &end_ts)
Definition OrderedCacheOfFiles.cpp:337
OrderedCacheOfFiles(std::string &video_folder, uint32_t initial_batch_size=1440, uint32_t _lowerWaterMark=1441, uint32_t _upperWaterMark=2880)
Definition OrderedCacheOfFiles.cpp:8
bool getFileFromCache(uint64_t timestamp, bool direction, std::string &fileName)
Definition OrderedCacheOfFiles.cpp:525
VideoCache videoCache
Definition OrderedCacheOfFiles.h:125
bool filePatternCheck(const fs::path &path)
Definition OrderedCacheOfFiles.cpp:879
uint64_t getFileDuration(std::string &filename)
Definition OrderedCacheOfFiles.cpp:17
bool lastKnownPlaybackDir
Definition OrderedCacheOfFiles.h:62
int cacheSize
Definition OrderedCacheOfFiles.h:65
bool fetchAndUpdateFromDisk(std::string videoFile, uint64_t &start_ts, uint64_t &end_ts)
Definition OrderedCacheOfFiles.cpp:64
void deleteLostEntry(std::string &filePath)
Definition OrderedCacheOfFiles.cpp:848
bool cleanCacheOnMainThread
Definition OrderedCacheOfFiles.h:70
void clearCache()
Definition OrderedCacheOfFiles.cpp:862
bool datePatternCheck(const boost::filesystem::path &path)
Definition OrderedCacheOfFiles.cpp:889
void updateBatchSize(uint32_t _batchSize)
Definition OrderedCacheOfFiles.h:27
bool parseFiles(uint64_t start_ts, bool direction, bool includeFloorFile=false, bool disableBatchSizeCheck=false, uint64_t skipTS=0)
Definition OrderedCacheOfFiles.cpp:661
void dropFarthestFromTS(uint64_t startTS)
Definition OrderedCacheOfFiles.cpp:792
VideoCache::index< videoTS >::type & videoCacheStartTSIndex
Definition OrderedCacheOfFiles.h:126
int batchSize
Definition OrderedCacheOfFiles.h:66
uint32_t lowerWaterMark
Definition OrderedCacheOfFiles.h:68
boost::multi_index_container< Video, bmi::indexed_by< bmi::ordered_unique< bmi::tag< videoPath >, bmi::member< Video, std::string, &Video::path > >, bmi::ordered_non_unique< bmi::tag< videoTS >, bmi::member< Video, uint64_t, &Video::start_ts > > > > VideoCache
Definition OrderedCacheOfFiles.h:122
bool getPreviousAndNextFile(std::string videoPath, std::string &previousFile, std::string &nextFile)
Definition OrderedCacheOfFiles.cpp:155
std::map< std::string, std::pair< uint64_t, uint64_t > > getSnapShot()
Definition OrderedCacheOfFiles.cpp:105
bool probe(boost::filesystem::path dirPath, std::string &videoName)
Definition OrderedCacheOfFiles.cpp:119
~OrderedCacheOfFiles()
Definition OrderedCacheOfFiles.h:20
void retireOldFiles(uint64_t startTSofRelevantFile)
Definition OrderedCacheOfFiles.cpp:776
std::string getFileAt(uint64_t timestamp, bool direction)
Definition OrderedCacheOfFiles.cpp:195
boost::mutex m_mutex
Definition OrderedCacheOfFiles.h:63
bool fetchFromCache(std::string &videoFile, uint64_t &start_ts, uint64_t &end_ts)
Definition OrderedCacheOfFiles.cpp:32
void insertInVideoCache(Video vid)
Definition OrderedCacheOfFiles.cpp:572
std::vector< boost::filesystem::path > parseAndSortDateDir(const std::string &rootDir)
Definition OrderedCacheOfFiles.cpp:589
bool isTimeStampInFile(std::string &filename, uint64_t timestamp)
Definition OrderedCacheOfFiles.cpp:309
void updateCache(std::string &filePath, uint64_t &start_ts, uint64_t &end_ts)
Definition OrderedCacheOfFiles.cpp:391
boost::shared_ptr< boost::thread > mThread
Definition OrderedCacheOfFiles.h:64
std::vector< boost::filesystem::path > parseAndSortMp4Files(const std::string &rootDir)
Definition OrderedCacheOfFiles.cpp:642
bool getRandomSeekFile(uint64_t ts, bool direction, uint64_t &skipMsecs, std::string &fileName)
Definition OrderedCacheOfFiles.cpp:409
std::string rootDir
Definition OrderedCacheOfFiles.h:67
struct OrderedCacheOfFiles::CacheIteratorState cacheIteratorState
std::string getLastVideoInCache()
Definition OrderedCacheOfFiles.h:56
Definition OrderedCacheOfFiles.h:80
std::string END_ITER
Definition OrderedCacheOfFiles.h:81
Definition OrderedCacheOfFiles.h:86
Video(std::string _path, uint64_t _start_ts, uint64_t _end_ts)
Definition OrderedCacheOfFiles.h:100
std::string path
Definition OrderedCacheOfFiles.h:88
Video(std::string &_path, uint64_t _start_ts)
Definition OrderedCacheOfFiles.h:90
uint64_t end_ts
Definition OrderedCacheOfFiles.h:87
Video(const std::string _path, uint64_t _start_ts)
Definition OrderedCacheOfFiles.h:95
void updateEndTS(uint64_t ts)
Definition OrderedCacheOfFiles.h:102
uint64_t start_ts
Definition OrderedCacheOfFiles.h:87
Definition OrderedCacheOfFiles.h:109
Definition OrderedCacheOfFiles.h:110