提交 03d9d89b authored 作者: blu's avatar blu

upload video files

上级 82e45de2
......@@ -72,7 +72,7 @@ evpusher: evpusher.cpp inc/common.hpp inc/av_common.hpp objs/utils.o inc/tinythr
$(CPP) $(CPPFLAGS) $(LD_FLAGS) -o evpusher evpusher.cpp objs/database.o objs/utils.o objs/zmqhelper.o $(SQLITE) $(LIBFFMPEG) $(HEADERS) `pkg-config --cflags --libs vendor/lib/pkgconfig/libzmq.pc` $(LIBS)
evslicer: evslicer.cpp inc/common.hpp inc/av_common.hpp objs/utils.o objs/dirmon.o inc/tinythread.hpp objs/database.o objs/zmqhelper.o $(SQLITE_SRC)
$(CPP) $(CPPFLAGS) $(LD_FLAGS) -o evslicer evslicer.cpp objs/database.o objs/dirmon.o objs/utils.o objs/zmqhelper.o $(SQLITE) $(LIBFFMPEG) $(HEADERS) `pkg-config --cflags --libs vendor/lib/pkgconfig/libzmq.pc` $(LIBS)
$(CPP) $(CPPFLAGS) $(LD_FLAGS) -o evslicer evslicer.cpp postfile.cpp objs/database.o objs/dirmon.o objs/utils.o objs/zmqhelper.o $(SQLITE) $(LIBFFMPEG) $(HEADERS) `pkg-config --cflags --libs vendor/lib/pkgconfig/libzmq.pc` $(LIBS) -lcurl
evmlmotion: evmlmotion.cpp inc/common.hpp inc/av_common.hpp objs/utils.o inc/avcvhelpers.hpp objs/database.o objs/zmqhelper.o inc/tinythread.hpp $(SQLITE_SRC)
$(CPP) $(CPPFLAGS) $(LD_FLAGS) -o evmlmotion evmlmotion.cpp objs/database.o objs/utils.o objs/zmqhelper.o $(SQLITE) $(LIBFFMPEG) $(HEADERS) $(LIBOPENCV) `pkg-config --cflags --libs vendor/lib/pkgconfig/libzmq.pc` $(LIBS)
......
......@@ -51,7 +51,8 @@
"password":"FWBWTU",
"port":554,
"proto":"rtsp",
"user":"admin"
"user":"admin",
"sn": "SN_CAMERA"
}
],
"mqtt-cloud":"<cloud_addr>",
......
......@@ -567,8 +567,10 @@ protected:
json meta;
meta["type"] = EV_MSG_META_EVENT;
string metaType = meta.dump();
string daemonId = this->devSn + ":evdaemon:0";
int ret = 0;
vector<vector<uint8_t> > v = {str2body(this->slicerGid), str2body(metaType), str2body("")};
vector<vector<uint8_t> > v1 = {str2body(daemonId), str2body(metaType), str2body("")};
while(true) {
if(!this->evtQueue->empty()) {
// send to evslicer
......@@ -587,21 +589,19 @@ protected:
v[2] = str2body(eventToSlicer.dump());
ret = z_send_multiple(this->pDealer, v);
if(ret < 0) {
spdlog::error("evmlmotion {} failed to send event {} to {}: {}", this->selfId, evt, this->slicerGid, zmq_strerror(zmq_errno()));
spdlog::error("evmlmotion {} failed to send event {} to {}: {}", this->selfId, eventToSlicer.dump(), this->slicerGid, zmq_strerror(zmq_errno()));
}
else {
spdlog::info("evmlmotion {} sent event to {}: {}", this->selfId, this->slicerGid, evt);
spdlog::info("evmlmotion {} sent event to {}: {}", this->selfId, this->slicerGid, eventToSlicer.dump());
}
eventToSlicer.clear();
}else{
spdlog::error("evmlmotion {} unknown event to {}: {}", this->selfId, this->slicerGid, evt);
spdlog::error("evmlmotion {} unknown event to {}: {}", this->selfId, this->slicerGid, eventToSlicer.dump());
}
// send to evdaemon
v[2] = str2body(evt);
string daemonId = this->devSn + ":evdaemon:0";
v[0] = str2body(daemonId);
ret = z_send_multiple(this->pDealer, v);
v1[2] = str2body(evt);
ret = z_send_multiple(this->pDealer, v1);
if(ret < 0) {
spdlog::error("evmlmotion {} failed to send event {} to {}: {}", this->selfId, evt, daemonId, zmq_strerror(zmq_errno()));
}
......
......@@ -44,7 +44,7 @@ private:
// 2 days, 5 minutes per record
void *pSubCtx = nullptr, *pDealerCtx = nullptr; // for packets relay
void *pSub = nullptr, *pDealer = nullptr, *pDaemonCtx = nullptr, *pDaemon = nullptr;
string urlOut, urlPub, urlRouter, devSn, mgrSn, selfId, pullerGid;
string urlOut, urlPub, urlRouter, devSn, mgrSn, selfId, pullerGid, ipcSn;
int iid, days, minutes, numSlices, segHead = 0, segHeadP;
bool enablePush = false, bSegFull = false;
AVFormatContext *pAVFormatRemux = nullptr;
......@@ -65,6 +65,7 @@ private:
condition_variable cvEvent;
mutex mutEvent;
thread thEventHandler;
string videoFileServerApi = "http://139.219.142.18:10008/upload/evtvideos/";
bool validMsg(json &msg) {
return true;
......@@ -101,7 +102,7 @@ private:
spdlog::info("evslicer {} received msg from {}, type = {}, data = {}", selfId, peerId, meta, data.dump());
if(data["type"] == "event") {
lock_guard<mutex> lock(mutEvent);
eventQueue.push(data);
eventQueue.push(data.dump());
if(eventQueue.size() > MAX_EVENT_QUEUE_SIZE) {
eventQueue.pop();
}
......@@ -113,7 +114,7 @@ private:
}
}
catch(exception &e) {
spdlog::error("evslicer {} failed to process msg:{}", selfId, msg);
spdlog::error("evslicer {} exception to process msg {}: {}", selfId, msg, e.what());
}
}
else {
......@@ -158,6 +159,11 @@ private:
}
selfId = devSn + ":evslicer:" + to_string(iid);
if(ipc.count("sn") == 0) {
ipcSn = "unkown";
}else{
ipcSn = ipc["sn"];
}
json evpuller = ipc["modules"]["evpuller"][0];
pullerGid = evpuller["sn"].get<string>() + ":evpuller:" + to_string(evpuller["iid"]);
......@@ -595,7 +601,7 @@ protected:
// skip
}else if(!lastFile.empty()){
// 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) {
//wrap it;
self->segHead = 0;
......@@ -613,7 +619,7 @@ protected:
auto oldTs = self->vTsActive[self->segHead];
self->vTsActive[self->segHead] = ts;
self->segHead++;
spdlog::info("evslicer {} fileMonHandler video seg done: {}/{}.mp4, ts:{}", self->selfId, self->urlOut, baseName, ts);
//spdlog::info("evslicer {} fileMonHandler video seg done: {}/{}.mp4, ts:{}", self->selfId, self->urlOut, baseName, ts);
}catch(exception &e) {
spdlog::error("evslicer {} fileMonHandler exception: {}", self->selfId, e.what());
}
......@@ -625,8 +631,8 @@ protected:
}
// find video files
int findTsRang(vector<long> &vTs, long start, long end, int &poss, int &pose) {
return 0;
vector<string> findSlicesByRange(long tss, long tse, int offsetS, int offsetE){
}
public:
......@@ -701,18 +707,36 @@ public:
thEventHandler = thread([this]{
while(true){
unique_lock<mutex> lk(this->mutEvent);
while(this->eventQueue.empty()){
this->cvEvent.wait(lk);
}
this->cvEvent.wait(lk, [this]{return !(this->eventQueue.empty());});
if(this->eventQueue.empty()){
continue;
}
auto evt = this->eventQueue.front();
this->eventQueue.pop();
json jEvt = json::parse(evt);
// TODO: upload video
spdlog::info("evslicer processing event: {}", evt);
if(jEvt["type"] == "event") {
auto tss = jEvt["start"].get<long>();
auto tse = jEvt["end"].get<long>();
long offsetS = 0;
long offsetE = 0;
auto v = findSlicesByRange(tss, tse, offsetS, offsetE);
if(v.size() == 0) {
spdlog::error("evslicer {} can't find slices by range: {}, {}", this->selfId, tss, tse);
}else{
vector<tuple<const char *, const char *> > params= {{"startTime", to_string(tss).c_str()},{"endTime", to_string(tse).c_str()},{"cameraId", ipcSn.c_str()}, {"headOffset", to_string(offsetS).c_str()},{"tailOffset", to_string(offsetE).c_str()}};
vector<const char*> fileNames;
for(auto &i: v) {
fileNames.push_back(i.c_str());
}
auto url = (videoFileServerApi + ipcSn).c_str();
netutils::postFiles(url, params, fileNames);
}
}
}
});
......@@ -741,7 +765,7 @@ public:
int main(int argc, const char *argv[])
{
av_log_set_level(AV_LOG_INFO);
av_log_set_level(AV_LOG_ERROR);
spdlog::set_level(spdlog::level::info);
EvSlicer es;
es.join();
......
......@@ -10,7 +10,7 @@ static void libcurlInit(){
}
}
int postFiles(const char*url, vector<tuple<const char* const, const char* const> > params, vector<const char *> fileNames){
int postFiles(const char*url, vector<tuple<const char*, const char*> > params, vector<const char *> fileNames){
CURL *curl;
CURLcode res;
curl_mime *form = NULL;
......
......@@ -7,9 +7,9 @@
#include <vector>
#include "inc/spdlog/spdlog.h"
namespace {
int postFiles(const char*url, vector<tuple<const char* const, const char* const> > params, vector<const char *> fileNames);
namespace netutils{
using namespace std;
int postFiles(const char*url, vector<tuple<const char*, const char*> > params, vector<const char *> fileNames);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论