提交 2566dd52 authored 作者: blu's avatar blu

upload video files

上级 98979301
...@@ -46,7 +46,7 @@ private: ...@@ -46,7 +46,7 @@ private:
void *pSubCtx = nullptr, *pDealerCtx = nullptr; // for packets relay void *pSubCtx = nullptr, *pDealerCtx = nullptr; // for packets relay
void *pSub = nullptr, *pDealer = nullptr, *pDaemonCtx = nullptr, *pDaemon = nullptr; void *pSub = nullptr, *pDealer = nullptr, *pDaemonCtx = nullptr, *pDaemon = nullptr;
string urlOut, urlPub, urlRouter, devSn, mgrSn, selfId, pullerGid, ipcSn; string urlOut, urlPub, urlRouter, devSn, mgrSn, selfId, pullerGid, ipcSn;
int iid, hours, seconds, numSlices, segHead = 0, segHeadP = 0; int iid, hours, seconds, numSlices, segHead = 1, segHeadP = 0;
long bootTime = 0; long bootTime = 0;
bool enablePush = false, bSegFull = false; bool enablePush = false, bSegFull = false;
AVFormatContext *pAVFormatRemux = nullptr; AVFormatContext *pAVFormatRemux = nullptr;
...@@ -595,8 +595,13 @@ protected: ...@@ -595,8 +595,13 @@ protected:
pos = tsToProcess.begin(); pos = tsToProcess.begin();
for(auto &i:tsToProcess) { for(auto &i:tsToProcess) {
// remove // remove
// fs::path fname(this->urlOut + "/" + videoFileTs2Name(i) + ".mp4"); fs::path fname(this->urlOut + "/" + videoFileTs2Name(i) + ".mp4");
// fs::remove(fname); fs::remove(fname);
// TODO: currently we don't cache event videos. lost on reboot.
// TODO: this behavior will be enhenced later.
continue;
// skip cache operations
if(idx < skip) { if(idx < skip) {
idx++; idx++;
pos++; pos++;
...@@ -617,32 +622,30 @@ protected: ...@@ -617,32 +622,30 @@ protected:
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;
static long lastTs; string ext = ".mp4";
auto self = static_cast<EvSlicer*>(pUserData); auto self = static_cast<EvSlicer*>(pUserData);
for(auto &i : evts) { for(auto &i : evts) {
string fullPath = i.get_path(); string fullPath = i.get_path();
string ext = ".mp4";
size_t pos = fullPath.find(ext, 0); size_t pos = fullPath.find(ext, 0);
if(fullPath.size() < ext.size() || pos == string::npos || pos != (fullPath.size() - ext.size())){ if(fullPath.size() < ext.size() || pos == string::npos || pos != (fullPath.size() - ext.size())){
spdlog::debug("evslicer {} invalid file : {}", self->selfId, fullPath); spdlog::debug("evslicer {} invalid file : {}", self->selfId, fullPath);
continue; continue;
} }
if(lastFile == i.get_path()) { if(lastFile == i.get_path() || lastFile.empty()) {
// skip // skip
continue;
} }
else if(!lastFile.empty()) { else if(!lastFile.empty()) {
// insert into ts active // insert into ts active
//spdlog::info("evslicer {} filemon file: {}, ts: {}, last: {}", self->selfId, i.get_path().c_str(), i.get_time(), lastFile); spdlog::info("evslicer {} filemon file: {}, ts: {}, last: {}", self->selfId, i.get_path().c_str(), i.get_time(), lastFile);
if(self->segHead >= self->numSlices) { if(self->segHead == 0) {
//wrap it; //wrap it;
self->segHead = 0;
self->bSegFull = true; self->bSegFull = true;
} }
if(self->bSegFull) { if(self->bSegFull) {
// TODO: backup orignal self->vTsActive[self->segHead] // TODO: backup orignal self->vTsActive[self->segHead]
} }
try { try {
...@@ -655,12 +658,12 @@ protected: ...@@ -655,12 +658,12 @@ protected:
auto oldTs = self->vTsActive[self->segHead]; auto oldTs = self->vTsActive[self->segHead];
if(oldTs != 0) { if(oldTs != 0) {
// TODO // TODO
//fs::path fname(self->urlOut + "/" + self->videoFileTs2Name(oldTs) + ".mp4"); fs::path fname(self->urlOut + "/" + self->videoFileTs2Name(oldTs) + ".mp4");
//fs::remove(fname); fs::remove(fname);
} }
self->vTsActive[self->segHead] = ts; self->vTsActive[self->segHead] = ts;
self->segHead++; self->segHead++;
//spdlog::info("evslicer {} fileMonHandler video seg done: {}/{}.mp4, ts:{}", self->selfId, self->urlOut, baseName, ts); self->segHead = self->segToIdx(self->segHead);
} }
catch(exception &e) { catch(exception &e) {
spdlog::error("evslicer {} fileMonHandler exception: {}", self->selfId, e.what()); spdlog::error("evslicer {} fileMonHandler exception: {}", self->selfId, e.what());
...@@ -678,9 +681,21 @@ protected: ...@@ -678,9 +681,21 @@ protected:
{ {
if(seg >= numSlices) { if(seg >= numSlices) {
seg -= numSlices; seg -= numSlices;
}else if(seg <=-1) {
seg = numSlices + seg;
} }
return seg; return seg;
} }
int incSegHead(int seg) {
return segToIdx(++seg);
}
int decSegHead(int seg) {
return segToIdx(--seg);
}
// find video files // find video files
vector<string> findSlicesByRange(long tss, long tse, int offsetS, int offsetE) vector<string> findSlicesByRange(long tss, long tse, int offsetS, int offsetE)
{ {
...@@ -689,10 +704,13 @@ protected: ...@@ -689,10 +704,13 @@ protected:
int _itss = 0; int _itss = 0;
if(bSegFull) { if(bSegFull) {
_itss = segHead; _itss = segHead;
}else{
_itss = 1;
} }
if(vTsActive[_itss] >= tse || vTsActive[segHead -1] < tss||(!bSegFull && segHead == 0)) { if(segHead == -1){
spdlog::error("evslicer {} findSlicesByRange event range ({},{}) is not in recorded range ({}, {})", selfId, this->videoFileTs2Name(tss), this->videoFileTs2Name(tse), this->videoFileTs2Name(vTsActive[_itss]), this->videoFileTs2Name(vTsActive[segHead -1])); spdlog::error("evslicer {} no local records.");
return ret;
} }
else { else {
int idxS, idxE; int idxS, idxE;
...@@ -708,7 +726,7 @@ protected: ...@@ -708,7 +726,7 @@ protected:
} }
} }
if(tss > vTsActive[segToIdx(i)]) { if(tss >= vTsActive[segToIdx(i)]) {
if((found &2) != 2) { if((found &2) != 2) {
idxS = segToIdx(i); idxS = segToIdx(i);
found |=2; found |=2;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论