提交 758a826f authored 作者: blu's avatar blu

restart meter

上级 248ebcde
...@@ -776,14 +776,11 @@ protected: ...@@ -776,14 +776,11 @@ protected:
// file monitor callback // file monitor callback
static void fileMonHandler(const std::vector<event>& evts, void *pUserData) static void fileMonHandler(const std::vector<event>& evts, void *pUserData)
{ {
static string lastFile; static string lastFile;
string ext = ".mp4"; string ext = ".mp4";
auto self = static_cast<EvSlicer*>(pUserData); auto self = static_cast<EvSlicer*>(pUserData);
if(self->segHead == -1) {
self->segHead = 1;
}
for(auto &i : evts) { for(auto &i : evts) {
string fullPath = i.get_path(); string fullPath = i.get_path();
size_t pos = fullPath.find(ext, 0); size_t pos = fullPath.find(ext, 0);
...@@ -791,50 +788,51 @@ protected: ...@@ -791,50 +788,51 @@ protected:
spdlog::debug("evslicer {} invalid file: {}, last: {}", self->selfId, fullPath, lastFile); spdlog::debug("evslicer {} invalid file: {}, last: {}", self->selfId, fullPath, lastFile);
continue; continue;
} }
if(lastFile == i.get_path()) {
spdlog::debug("evslicer {} skip file : {}, last: {}", self->selfId, fullPath, lastFile);
continue;
}
else if(!lastFile.empty()) {
// insert into ts active
spdlog::debug("evslicer {} filemon file: {}, ts: {}, last: {}", self->selfId, i.get_path().c_str(), i.get_time(), lastFile);
if(self->segHead == 0) {
//wrap it;
self->bSegFull = true;
}
if(self->bSegFull) {
}
try {
auto baseName = self->getBaseName(lastFile);
auto ts = self->videoFileName2Ts(baseName);
if(ts == -1) {
spdlog::error("evslicer {} fileMonHandler failed to process file: {}", self->selfId, lastFile);
continue;
}
auto oldTs = self->vTsActive[self->segHead];
if(oldTs != 0) {
// TODO
fs::path fname(self->urlOut + "/" + self->videoFileTs2Name(oldTs) + ".mp4");
fs::remove(fname);
}
self->vTsActive[self->segHead] = ts;
self->segHead++;
self->segHead = self->segToIdx(self->segHead);
}
catch(exception &e) {
spdlog::error("evslicer {} fileMonHandler exception: {}", self->selfId, e.what());
}
}
else {
//nop
}
lastFile = i.get_path();
} }
// if(lastFile == i.get_path()) {
// spdlog::debug("evslicer {} skip file : {}, last: {}", self->selfId, fullPath, lastFile);
// continue;
// }
// else if(!lastFile.empty()) {
// // insert into ts active
// spdlog::debug("evslicer {} filemon file: {}, ts: {}, last: {}", self->selfId, i.get_path().c_str(), i.get_time(), lastFile);
// if(self->segHead == 0) {
// //wrap it;
// self->bSegFull = true;
// }
// if(self->bSegFull) {
// }
// try {
// auto baseName = self->getBaseName(lastFile);
// auto ts = self->videoFileName2Ts(baseName);
// if(ts == -1) {
// spdlog::error("evslicer {} fileMonHandler failed to process file: {}", self->selfId, lastFile);
// continue;
// }
// auto oldTs = self->vTsActive[self->segHead];
// if(oldTs != 0) {
// // TODO
// fs::path fname(self->urlOut + "/" + self->videoFileTs2Name(oldTs) + ".mp4");
// fs::remove(fname);
// }
// self->vTsActive[self->segHead] = ts;
// self->segHead++;
// self->segHead = self->segToIdx(self->segHead);
// }
// catch(exception &e) {
// spdlog::error("evslicer {} fileMonHandler exception: {}", self->selfId, e.what());
// }
// }
// else {
// //nop
// }
// lastFile = i.get_path();
// }
} }
......
#include <list> #include <set>
#include <algorithm> #include <algorithm>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <json.hpp> #include <json.hpp>
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
using namespace std; using namespace std;
void insertTsList(list<long> &_list, long elem, int maxSize) { void insertTsList(set<long> &_list, long elem, int maxSize) {
// _list.insert(lower_bound(_list.begin(), _list.end(), elem), elem); // _list.insert(lower_bound(_list.begin(), _list.end(), elem), elem);
if(_list.size() == 0) { if(_list.size() == 0) {
_list.insert(_list.begin(),elem); _list.insert(_list.begin(),elem);
...@@ -28,18 +28,18 @@ void insertTsList(list<long> &_list, long elem, int maxSize) { ...@@ -28,18 +28,18 @@ void insertTsList(list<long> &_list, long elem, int maxSize) {
} }
if(_list.size() > maxSize) { if(_list.size() > maxSize) {
_list.pop_front(); _list.erase(_list.begin());
} }
} }
void printTsList(list<long>&_list) { void printTsList(set<long>&_list) {
for(auto &i:_list) { for(auto &i:_list) {
cout <<i <<endl; cout <<i <<endl;
} }
} }
int main() { int main() {
list<long> tsList; set<long> tsList;
insertTsList(tsList, 10, 5); insertTsList(tsList, 10, 5);
insertTsList(tsList,6, 5); insertTsList(tsList,6, 5);
insertTsList(tsList, 11, 5); insertTsList(tsList, 11, 5);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论