提交 c8b301f8 authored 作者: blu's avatar blu

upload video files

上级 2566dd52
......@@ -104,7 +104,8 @@ private:
this->peerData["config"][peerId] = v;
if(this->peerData["status"].count(peerId) == 0) {
this->peerData["status"][peerId] = -1; // unkown
}else{
}
else {
// nop
}
this->peerData["enabled"][peerId] = 1;
......@@ -119,8 +120,8 @@ private:
for(auto &m : ml) {
if(m["sn"] != this->devSn) {
continue;
}
}
string peerName;
ret = cfgutils::getPeerId(mn, m, peerId, peerName);
if(ret != 0) {
......@@ -130,14 +131,16 @@ private:
if(m.count("enabled") == 0 || m["enabled"] == 0) {
spdlog::warn("evdaemon {} {} was disabled", this->devSn, mn);
this->peerData["enabled"][peerId] = 0;
}else{
}
else {
this->peerData["enabled"][peerId] = 1;
}
this->peerData["config"][peerId] = v;
if(this->peerData["status"].count(peerId) == 0) {
this->peerData["status"][peerId] = -1; // unkown
}else{
}
else {
// nop
}
......@@ -186,18 +189,20 @@ private:
int cnt = 0;
for(auto &[k,v]: this->peerData["config"].items()) {
if(this->peerData["enabled"].count(k) != 0 && this->peerData["enabled"][k] != 0) {
if((this->peerData["status"].count(k) == 0 || this->peerData["status"][k] == 0)){
if((this->peerData["status"].count(k) == 0 || this->peerData["status"][k] == 0)) {
tmp.push_back(k);
info += (cnt == 0? "" : string(", ")) + k;
}else if(this->peerData["status"][k] == -1) {
}
else if(this->peerData["status"][k] == -1) {
unkown[k] = -1;
}
}else{
terms.push_back(k);
}
}
else {
terms.push_back(k);
}
cnt++;
}
spdlog::info("evdaemon {} will start following subsystems: {}", devSn, info);
//
for(string &e : tmp) {
......@@ -276,7 +281,7 @@ private:
string meta = j.dump();
vector<vector<uint8_t> > v = {str2body(selfId), str2body(this->daemonId), str2body(meta), str2body(cfg)};
z_send_multiple(pRouter, v);
spdlog::info("evdaemon {} peer {} config sent: {}", devSn ,selfId, cfg);
spdlog::info("evdaemon {} peer {} config sent: {}", devSn,selfId, cfg);
}
else {
peerData["status"][selfId] = 0;
......@@ -416,7 +421,8 @@ private:
if(meta == EV_MSG_META_CONFIG) {
if(data.size() == 0) {
spdlog::error("evdaemon {} received invalid empty config", devSn);
} else {
}
else {
this->deltaCfg = json::diff(this->config, data);
spdlog::info("evdaemon {} received cloud config diff: {}\nnew: {}", devSn, this->deltaCfg.dump(4), data.dump());
if(this->deltaCfg.size() != 0 || this->bColdStart) {
......@@ -440,9 +446,10 @@ private:
if(bBootstrap) {
// TODO: wait for previous started modules to connecting
startSubSystems();
}else{
}
else {
spdlog::info("evdaemon {} skip startup subsystems since BOOTSTRAP is set to false", devSn);
}
}
}
}
}
......@@ -539,7 +546,7 @@ public:
EvDaemon()
{
/// peerId -> value
/// peerId -> value
peerData["status"] = json();
peerData["pids"] = json();
peerData["config"] = json();
......
......@@ -83,9 +83,10 @@ private:
}
spdlog::info("evmgr {} bind success to {}", devSn, addr);
inited = true;
error_exit:
error_exit:
if(inited) {
}else{
}
else {
exit(1);
}
}
......@@ -93,7 +94,7 @@ private:
spdlog::error("evmgr {} exception on init() for: {}. abort booting up.", devSn, e.what());
exit(1);
}
spdlog::info("evmgr {} successfuly inited", devSn);
}
......@@ -285,7 +286,8 @@ public:
}
devSn = v[0];
}else{
}
else {
spdlog::error("evmgr failed to start. no SN set");
exit(1);
}
......@@ -301,9 +303,9 @@ public:
ret = zmqhelper::recvConfigMsg(pDealer, config, addr, ident);
if(ret != 0) {
spdlog::error("evmgr {} failed to receive configration message {}", devSn , addr);
spdlog::error("evmgr {} failed to receive configration message {}", devSn, addr);
}
init();
}
~EvMgr()
......
......@@ -70,7 +70,7 @@ private:
AVFormatContext *pAVFormatInput = nullptr;
AVCodecContext *pCodecCtx = nullptr;
AVDictionary *pOptsRemux = nullptr;
DetectParam detPara = {25,500,-1,10,3,30, 2};
DetectParam detPara = {25, 500, -1, 10, 3, 30, 0.3};
EventState evtState = EventState::NONE;
chrono::system_clock::time_point evtStartTm, evtStartTmLast;
queue<string> *evtQueue;
......@@ -81,7 +81,7 @@ private:
thread thEvent;
string drport = "5549";
//
int init()
{
int ret = 0;
......@@ -577,13 +577,14 @@ protected:
string evt = this->evtQueue->front();
json jevt = json::parse(evt);
this->evtQueue->pop();
if(jevt["event"] == EV_MSG_EVENT_MOTION_START){
if(jevt["event"] == EV_MSG_EVENT_MOTION_START) {
eventToSlicer["type"] = "event";
eventToSlicer["start"] = jevt["ts"];
eventToSlicer["extraInfo"] = json(); //array
eventToSlicer["extraInfo"].push_back(jevt);
// TODO: save and load saved evt on crash
}else if(jevt["event"] == EV_MSG_EVENT_MOTION_END){
}
else if(jevt["event"] == EV_MSG_EVENT_MOTION_END) {
eventToSlicer["end"] = jevt["ts"];
eventToSlicer["extraInfo"].push_back(jevt);
v[2] = str2body(eventToSlicer.dump());
......@@ -595,7 +596,8 @@ protected:
spdlog::info("evmlmotion {} sent event to {}: {}", this->selfId, this->slicerGid, eventToSlicer.dump());
}
eventToSlicer.clear();
}else{
}
else {
spdlog::error("evmlmotion {} unknown event to {}: {}", this->selfId, this->slicerGid, eventToSlicer.dump());
}
......
......@@ -55,7 +55,8 @@ private:
ret = z_send_multiple(pDealer, rep);
if(ret < 0) {
spdlog::error("evpuller {} failed to send avformatctx data to requester {}: {}", selfId, peerId, zmq_strerror(zmq_errno()));
}else{
}
else {
spdlog::info("evpuller {} success to send avformatctx data to requester {}", selfId, peerId);
}
}
......@@ -103,9 +104,10 @@ public:
RepSrv(RepSrv&&) = delete;
RepSrv(string mgrSn, string devSn, int iid, const char* formatBytes,
int len, void *pDealer):mgrSn(mgrSn),devSn(devSn), iid(iid), bytes(formatBytes),
len(len), pDealer(pDealer) {
selfId = devSn+":evpuller:" + to_string(iid);
};
len(len), pDealer(pDealer)
{
selfId = devSn+":evpuller:" + to_string(iid);
};
~RepSrv() {};
};
......@@ -126,13 +128,14 @@ private:
string drport = "5549";
bool isIpStr(string ip) {
bool isIpStr(string ip)
{
int cnt = 3*4 + 3;
if(ip.size() == 0 || ip.size() > cnt) {
return false;
}
auto v = strutils::split(ip, '.');
if(v.size() == 0 || v.size () != 4){
if(v.size() == 0 || v.size () != 4) {
return false;
}
......@@ -154,7 +157,7 @@ private:
int init()
{
bool inited = false;
int ret = 0;
int ret = 0;
bool found = false;
string user, passwd, addr;
try {
......@@ -180,7 +183,7 @@ private:
if(ipc.size()!=0 && evpuller.size()!=0) {
found = true;
}
if(!found) {
spdlog::error("evpuller {} no valid config found", devSn);
......@@ -194,27 +197,29 @@ private:
// default stream port
if(ipc.count("port") == 0) {
ipcPort = "554";
}else{
}
else {
ipcPort = to_string(ipc["port"]);
}
string ipcAddr = ipc["addr"].get<string>();
if(isIpStr(ipcAddr)){
if(isIpStr(ipcAddr)) {
string chan = "ch1";
string streamName = "main";
if(ipc.count("channel") != 0 && !ipc["channel"].get<string>().empty()){
if(ipc.count("channel") != 0 && !ipc["channel"].get<string>().empty()) {
chan = ipc["channel"].get<string>();
}
if(ipc.count("streamName") != 0 && !ipc["streamName"].get<string>().empty()){
if(ipc.count("streamName") != 0 && !ipc["streamName"].get<string>().empty()) {
streamName = ipc["streamName"].get<string>();
}
if(ipc.count("proto") != 0 && !ipc["proto"].get<string>().empty()){
if(ipc.count("proto") != 0 && !ipc["proto"].get<string>().empty()) {
proto = ipc["proto"];
}
urlIn = proto + "://" + user + ":" + passwd + "@" + ipc["addr"].get<string>() + ":" + ipcPort + "/h264/" + chan + "/" + streamName + "/av_stream";
}else{
}
else {
urlIn = ipcAddr;
}
......@@ -249,7 +254,7 @@ private:
exit(1);
}
ret = zmq_connect(pDealer, urlDealer.c_str());
if(ret < 0) {
if(ret < 0) {
spdlog::error("evpuller {} failed to connect to router {}", selfId, urlDealer);
exit(1);
}
......@@ -277,10 +282,11 @@ protected:
string proto = urlIn.substr(0,4);
if(proto == "rtsp") {
av_dict_set(&optsIn, "rtsp_transport", "tcp", 0);
}else{
}
else {
//
}
spdlog::info("evpuller {} openning stream: {}", selfId, urlIn);
if ((ret = avformat_open_input(&pAVFormatInput, urlIn.c_str(), NULL, &optsIn)) < 0) {
spdlog::error("evpuller {} Could not open input stream {}", selfId, urlIn);
......@@ -396,7 +402,8 @@ public:
}
devSn = v[0];
iid = stoi(v[2]);
}else{
}
else {
spdlog::error("evpuller {} failed to start. no SN set", selfId);
exit(1);
}
......@@ -411,7 +418,7 @@ public:
ret = zmqhelper::recvConfigMsg(pDaemon, config, addr, selfId);
if(ret != 0) {
spdlog::error("evpuller {} failed to receive configration message {}", selfId , addr);
spdlog::error("evpuller {} failed to receive configration message {}", selfId, addr);
}
init();
}
......
......@@ -93,13 +93,13 @@ private:
spdlog::info("evpusher {} connect to {} for sub, {} for router", selfId, urlPub, urlDealer);
// TODO: multiple protocols support
urlOut = evpusher["urlDest"].get<string>();
// setup sub
// setup sub
pSubCtx = zmq_ctx_new();
pSub = zmq_socket(pSubCtx, ZMQ_SUB);
ret = zmq_setsockopt(pSub, ZMQ_SUBSCRIBE, "", 0);
if(ret != 0) {
spdlog::error("evpusher {} {} failed set setsockopt: {}", devSn, iid, urlPub);
}
ret = zmq_connect(pSub, urlPub.c_str());
if(ret != 0) {
......@@ -223,12 +223,14 @@ private:
ret = AVERROR_UNKNOWN;
}
ret = avformat_alloc_output_context2(&pAVFormatRemux, nullptr, "rtsp", urlOut.c_str());
}else if(proto == "rtmp"){
}
else if(proto == "rtmp") {
ret = avformat_alloc_output_context2(&pAVFormatRemux, nullptr, "rtmp", urlOut.c_str());
}else{
}
else {
ret = avformat_alloc_output_context2(&pAVFormatRemux, nullptr, nullptr, urlOut.c_str());
}
if (ret < 0) {
spdlog::error("evpusher {} {} failed create avformatcontext for output: %s", devSn, iid, av_err2str(ret));
exit(1);
......@@ -406,7 +408,8 @@ public:
}
devSn = v[0];
iid = stoi(v[2]);
}else{
}
else {
spdlog::error("evpusher failed to start. no SN set");
exit(1);
}
......@@ -421,7 +424,7 @@ public:
ret = zmqhelper::recvConfigMsg(pDaemon, config, addr, selfId);
if(ret != 0) {
spdlog::error("evpusher {} failed to receive configration message {}", devSn , addr);
spdlog::error("evpusher {} failed to receive configration message {}", devSn, addr);
}
init();
......
......@@ -112,7 +112,8 @@ private:
eventQueue.pop();
}
cvEvent.notify_one();
}else{
}
else {
spdlog::error("evslicer {} msg not supported from {}: {}", selfId, peerId, msg);
}
}
......@@ -597,7 +598,7 @@ protected:
// remove
fs::path fname(this->urlOut + "/" + videoFileTs2Name(i) + ".mp4");
fs::remove(fname);
// TODO: currently we don't cache event videos. lost on reboot.
// TODO: currently we don't cache event videos. lost on reboot.
// TODO: this behavior will be enhenced later.
continue;
......@@ -628,7 +629,7 @@ protected:
for(auto &i : evts) {
string fullPath = i.get_path();
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);
continue;
}
......@@ -681,18 +682,21 @@ protected:
{
if(seg >= numSlices) {
seg -= numSlices;
}else if(seg <=-1) {
}
else if(seg <=-1) {
seg = numSlices + seg;
}
return seg;
}
int incSegHead(int seg) {
int incSegHead(int seg)
{
return segToIdx(++seg);
}
int decSegHead(int seg) {
int decSegHead(int seg)
{
return segToIdx(--seg);
}
......@@ -704,11 +708,12 @@ protected:
int _itss = 0;
if(bSegFull) {
_itss = segHead;
}else{
}
else {
_itss = 1;
}
if(segHead == -1){
if(segHead == -1) {
spdlog::error("evslicer {} no local records.");
return ret;
}
......@@ -756,7 +761,8 @@ protected:
return ret;
}
void printSlices(){
void printSlices()
{
for(int i = 0; i < numSlices; i++) {
spdlog::info("evslicer {} vector[{}] = {}, {}", selfId, i, vTsActive[i], videoFileTs2Name(vTsActive[i]));
if(vTsActive[i] == 0) {
......@@ -842,16 +848,16 @@ public:
string evt;
unique_lock<mutex> lk(this->mutEvent);
this->cvEvent.wait(lk, [this] {return !(this->eventQueue.empty());});
if(!this->eventQueue.empty()) {
evt = this->eventQueue.front();
this->eventQueue.pop();
}
if(evt.empty()){
if(evt.empty()) {
continue;
}
}
json jEvt = json::parse(evt);
if(jEvt["type"] == "event") {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论