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

upload video files

上级 2566dd52
......@@ -7,34 +7,37 @@ query configuration for edge device with specified sn
- sn: string. device serial
##### return
- type: json
- field "code": 0 - success; otherwise failed.
- field "code": 0 - success;
otherwise failed.
- field "msg": string, readable string for "code"
- field "data": configuration for sn.
- example
```
- field "data": configuration for sn.
- example
```
{
"code": 0,
"data": {
"NMXH73Y2": {
"addr": "127.0.0.1",
"api-cloud": "http://127.0.0.1:8089",
"ipcs": [
{
"addr": "172.31.0.51",
"modules": {
"evml": [
"data": {
"NMXH73Y2": {
"addr": "127.0.0.1"
,
"api-cloud": "http://127.0.0.1:8089"
,
"ipcs":
[ {
"addr": "172.31.0.51",
"modules": {
"evml": [
{
"area": 300,
"enabled": 1,
"iid": 1,
"post": 30,
"pre": 3,
"sn": "NMXH73Y2",
"sn": "NMXH73Y2",
"thresh": 80,
"type": "motion"
"type": "motion"
}
],
"evpuller": [
"evpuller": [
{
"addr": "127.0.0.1",
"enabled": 1,
......@@ -43,7 +46,7 @@ query configuration for edge device with specified sn
"sn": "NMXH73Y2"
}
],
"evpusher": [
"evpusher": [
{
"enabled": 1,
"iid": 1,
......@@ -54,7 +57,7 @@ query configuration for edge device with specified sn
"user": ""
}
],
"evslicer": [
"evslicer": [
{
"enabled": 1,
"iid": 1,
......@@ -63,21 +66,23 @@ query configuration for edge device with specified sn
}
]
},
"password": "FWBWTU",
"password": "FWBWTU",
"port": 554,
"proto": "rtsp",
"user": "admin"
"proto": "rtsp",
"user": "admin"
}
],
"mqtt-cloud": "<cloud_addr>",
"mqtt-cloud": "<cloud_addr>"
,
"port-cloud": 5556,
"port-router": 5550,
"proto": "zmq",
"sn": "NMXH73Y2"
"proto": "zmq"
,
"sn": "NMXH73Y2"
}
},
"msg": "ok"
}
"msg": "ok"
}
```
......@@ -89,31 +94,33 @@ set or change configuration for edge device
- sn: string, only used when patch is set as true
##### body
- type: json
- example
1. full configure
```
- example
1. full configure
```
{
"data":{
"NMXH73Y2":{
"addr":"127.0.0.1",
"api-cloud":"http://127.0.0.1:8089",
"ipcs":[
{
"addr":"172.31.0.51",
"modules":{
"evml":[
"data": {
"NMXH73Y2": {
"addr":"127.0.0.1"
,
"api-cloud":"http://127.0.0.1:8089"
,
"ipcs":
[ {
"addr":"172.31.0.51",
"modules":{
"evml":[
{
"area":300,
"enabled":1,
"iid":1,
"post":30,
"pre":3,
"sn":"NMXH73Y2",
"sn":"NMXH73Y2",
"thresh":80,
"type":"motion"
"type":"motion"
}
],
"evpuller":[
"evpuller":[
{
"addr":"127.0.0.1",
"iid":1,
......@@ -122,7 +129,7 @@ set or change configuration for edge device
"sn":"NMXH73Y2"
}
],
"evpusher":[
"evpusher":[
{
"enabled":1,
"iid":1,
......@@ -133,7 +140,7 @@ set or change configuration for edge device
"user":""
}
],
"evslicer":[
"evslicer":[
{
"enabled":1,
"iid":1,
......@@ -142,17 +149,19 @@ set or change configuration for edge device
}
]
},
"password":"FWBWTU",
"password":"FWBWTU",
"port":554,
"proto":"rtsp",
"user":"admin"
"proto":"rtsp",
"user":"admin"
}
],
"mqtt-cloud":"<cloud_addr>",
"mqtt-cloud":"<cloud_addr>"
,
"port-cloud":5556,
"port-router":5550,
"proto":"zmq",
"sn":"NMXH73Y2"
"proto":"zmq"
,
"sn":"NMXH73Y2"
}
},
"lastupdated":1567669674
......@@ -160,13 +169,16 @@ set or change configuration for edge device
```
2. patch configure (POST /config?patch=true&sn=NMXH73Y2)
```
[{"op":"add","path":"/ipcs/0/modules/evpuller/0/enabled","value":1}]
[ {"op":"add","path":"/ipcs/0/modules/evpuller/0/enabled","value":1}]
```
##### return
- type: json
- example:
```
{"code": 0, "msg":"ok", "data":JSON}
- example:
```
{"code": 0, "msg":"ok"
, "data":
JSON
}
```
#### GET /keys
......@@ -175,38 +187,43 @@ query all keys in cloud db
##### params
- none
##### return
- type: json array
- example
```
[
- type: json array
- example
```
[
"NMXH73Y2",
"NMXH73Y2_bak",
"SN",
"configmap",
"configmap_bak"
]
```
]
```
#### GET /value
##### description
get value for specified key in cloud db. keys list is queried by /keys api
get value for specified key in cloud db. keys list is queried by /keys api
##### params
- key: string
- key: string
##### return
- type: json
- example
```
- type: json
- example
```
# GET /value?key=configmap
{
"NMXH73Y2": "NMXH73Y2",
"code": 0,
"mod2mgr": {
"NMXH73Y2:evml:motion": "NMXH73Y2",
"NMXH73Y2:evpuller": "NMXH73Y2",
"NMXH73Y2:evpusher": "NMXH73Y2",
"NMXH73Y2:evslicer": "NMXH73Y2"
},
"sn2mods": {
"NMXH73Y2": [
"NMXH73Y2": "NMXH73Y2"
,
"code": 0,
"mod2mgr": {
"NMXH73Y2:evml:motion": "NMXH73Y2"
,
"NMXH73Y2:evpuller": "NMXH73Y2"
,
"NMXH73Y2:evpusher": "NMXH73Y2"
,
"NMXH73Y2:evslicer": "NMXH73Y2"
},
"sn2mods": {
"NMXH73Y2":
[
"NMXH73Y2:evml:motion",
"NMXH73Y2:evpuller",
"NMXH73Y2:evpusher",
......@@ -221,10 +238,12 @@ get value for specified key in cloud db. keys list is queried by /keys api
##### params
- sn: string
##### return
- type: json
- example
```
{"code": 0, "msg":"ok", ...}
- type: json
- example
```
{"code": 0, "msg":"ok"
, ...
}
```
#### GET /sysinfo
......@@ -236,17 +255,18 @@ get value for specified key in cloud db. keys list is queried by /keys api
*[NOT IMPLEMENTED]* turn on/off debug tunnel
##### params
- sn: string
- op: on|off
- ip: string. ip of public accessable host
- port(optional): number. ssh port of the public accessable host. default 22.
- port_tun(optional): number. tunnuel port of the public accessable host. default 11222.
- user: ssh user of the public accessable host
- password: ssh password of the public accessable host
- op: on|off
- ip: string. ip of public accessable host
- port(optional): number. ssh port of the public accessable host. default 22.
- port_tun(optional): number. tunnuel port of the public accessable host. default 11222.
- user: ssh user of the public accessable host
- password: ssh password of the public accessable host
##### return
- type: json
- example
```
{"code":0, "msg":"ok"}
- type: json
- example
```
{"code":0, "msg":"ok"
}
```
......@@ -44,7 +44,8 @@ private:
mutex eventQLock;
thread thMsgProcessor;
void loadConfigMap(){
void loadConfigMap()
{
// load configmap
json cnfm;
int ret = LVDB::getValue(cnfm, KEY_CONFIG_MAP);
......@@ -65,19 +66,21 @@ private:
}
// populate peerData
for(auto &[k,v]: this->configMap["sn2mods"].items()){
for(auto &[k,v]: this->configMap["sn2mods"].items()) {
// load config from database
json cfg;
if(LVDB::getLocalConfig(cfg, k) < 0) {
spdlog::error("evcloudsvc failed to load config for device: {}", k);
}else{
}
else {
this->peerData["config"][k] = cfg;
spdlog::info("evcloudsvc loaded config for device: {}", k);
}
}
}
int sendConfig(json &config_, string sn) {
int sendConfig(json &config_, string sn)
{
int ret = 0;
string cfg = config_.dump();
json j;
......@@ -169,16 +172,17 @@ private:
}
// check exist
bool hasModKey =false;
for(auto &modKey_:this->configMap["sn2mods"][sn]){
for(auto &modKey_:this->configMap["sn2mods"][sn]) {
if(modKey_ == modKey) {
hasModKey = true;
break;
}
}
if(hasModKey){
if(hasModKey) {
//nop
}else{
}
else {
this->configMap["sn2mods"][sn].push_back(modKey);
}
......@@ -227,10 +231,12 @@ private:
deltaCfg[k] = 1;
this->peerData["config"][k] = v;
spdlog::info("evcloudsvc peer {} config diff:\n{}\norigin:\n{}", k, diff.dump(), this->peerData["config"][k].dump());
}else{
}
else {
spdlog::info("evcloudsvc peer {} config no diff. ignored:\n{}", k, this->peerData["config"][k].dump());
}
}else{
}
else {
this->peerData["config"][k] = v;
}
// TODO: important! always send config in case edge config is corrupted.
......@@ -255,7 +261,7 @@ private:
}
// update config
for(auto &[x,y]: deltaCfg.items()){
for(auto &[x,y]: deltaCfg.items()) {
json j = getConfigForDevice(x);
if(j["code"] == 0) {
sendConfig(j["data"], x);
......@@ -276,7 +282,8 @@ private:
}
//
bool handleConnection(string selfId) {
bool handleConnection(string selfId)
{
bool ret = false;
int state = zmq_socket_get_peer_state(pRouter, selfId.data(), selfId.size());
spdlog::info("evcloudsvc peer {} state: {}", selfId, state);
......@@ -288,7 +295,8 @@ private:
json data = getConfigForDevice(selfId);
if(data["code"] != 0) {
//
}else{
}
else {
sendConfig(data["data"], selfId);
}
}
......@@ -405,14 +413,15 @@ private:
return ret;
}
json getConfigForDevice(string sn) {
json getConfigForDevice(string sn)
{
json ret;
ret["code"] = 0;
ret["msg"] = "ok";
ret["data"] = json();
json &data = ret["data"];
spdlog::info("evcloudsvc get config for sn {}", sn);
try{
try {
if(this->configMap["sn2mods"].count(sn) != 0) {
auto mods = this->configMap["sn2mods"][sn];
set<string> s;
......@@ -424,7 +433,8 @@ private:
for(auto &key : s) {
if(this->peerData["config"].count(key) == 0) {
spdlog::error("evcloudsvc no peerData config for device {}", key);
}else{
}
else {
if(data.count(key) != 0) {
json diff = json::diff(data[key], this->peerData["config"][key]);
if(diff.size() != 0) {
......@@ -433,19 +443,22 @@ private:
ret["msg"] = msg;
break;
}
}else{
}
else {
data[key] = this->peerData["config"][key];
}
}
} // for keys of mgr
ret["data"] = data;
}else{
}
else {
ret["code"] = 1;
string msg = "no such sn: " + sn;
ret["msg"] = msg;
spdlog::warn("evcloudsvc no config for sn: {}", sn);
}
}catch(exception &e) {
}
catch(exception &e) {
string msg = "evcloudsvc exception in file" + string(__FILE__) + ":" + to_string(__LINE__) + " for: " + e.what();
spdlog::error(msg);
ret["code"] = -1;
......@@ -506,7 +519,8 @@ public:
}
else if(!sn.empty() && module.empty()) {
ret = getConfigForDevice(sn);
}else{
}
else {
ret["code"] = 2;
ret["msg"] = "invalid request. no param for sn/module";
}
......@@ -525,7 +539,7 @@ public:
string msg;
try {
json cfg = json::parse(req.body);
if(req.has_param("sn") && req.has_param("patch")){
if(req.has_param("sn") && req.has_param("patch")) {
string _sn = req.get_param_value("sn");
string _patch = req.get_param_value("patch");
if(!_sn.empty() && _patch == "true") {
......@@ -533,11 +547,13 @@ public:
ret = getConfigForDevice(_sn);
if(ret["code"]!= 0) {
//
}else{
}
else {
ret["data"].merge_patch(cfg);
}
}
}else{
}
else {
ret = this->config(cfg);
}
}
......@@ -599,12 +615,13 @@ public:
exit(1);
}
// setup edge msg processor
thMsgProcessor = thread([this](){
while(true){
thMsgProcessor = thread([this]() {
while(true) {
auto v = zmqhelper::z_recv_multiple(this->pRouter);
if(v.size() == 0) {
spdlog::error("evdaemon {} failed to receive msg {}", this->devSn, zmq_strerror(zmq_errno()));
}else{
}
else {
handleMsg(v);
}
}
......
......@@ -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;
......@@ -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,13 +189,15 @@ 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{
}
else {
terms.push_back(k);
}
cnt++;
......@@ -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,7 +446,8 @@ 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);
}
}
......
......@@ -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);
}
}
......@@ -285,7 +286,8 @@ public:
}
devSn = v[0];
}else{
}
else {
spdlog::error("evmgr failed to start. no SN set");
exit(1);
}
......@@ -301,7 +303,7 @@ 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();
......
......@@ -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;
......@@ -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,7 +104,8 @@ 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) {
len(len), pDealer(pDealer)
{
selfId = devSn+":evpuller:" + to_string(iid);
};
......@@ -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;
}
......@@ -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;
}
......@@ -277,7 +282,8 @@ protected:
string proto = urlIn.substr(0,4);
if(proto == "rtsp") {
av_dict_set(&optsIn, "rtsp_transport", "tcp", 0);
}else{
}
else {
//
}
......@@ -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();
}
......
......@@ -223,9 +223,11 @@ 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());
}
......@@ -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);
}
}
......@@ -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) {
......@@ -848,7 +854,7 @@ public:
this->eventQueue.pop();
}
if(evt.empty()){
if(evt.empty()) {
continue;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论