Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
f7aa0a70
提交
f7aa0a70
authored
8月 28, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
c12209ff
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
212 行增加
和
73 行删除
+212
-73
Makefile
opencv-motion-detect/Makefile
+9
-7
database.cpp
opencv-motion-detect/database.cpp
+69
-18
evmgr.cpp
opencv-motion-detect/evmgr.cpp
+22
-2
evmlmotion.cpp
opencv-motion-detect/evmlmotion.cpp
+23
-4
evpuller.cpp
opencv-motion-detect/evpuller.cpp
+22
-5
evpusher.cpp
opencv-motion-detect/evpusher.cpp
+23
-5
evslicer.cpp
opencv-motion-detect/evslicer.cpp
+21
-4
common.hpp
opencv-motion-detect/inc/common.hpp
+8
-6
database.h
opencv-motion-detect/inc/database.h
+9
-6
test_database.cpp
opencv-motion-detect/test_database.cpp
+6
-16
没有找到文件。
opencv-motion-detect/Makefile
浏览文件 @
f7aa0a70
...
...
@@ -7,8 +7,10 @@ CFLAGS = $(DEBUG) -Wall
LIBOPENCV
=
`
pkg-config opencv
--cflags
--libs
`
LIBFFMPEG
=
`
pkg-config libavformat libavutil libavcodec libswscale
--cflags
--libs
`
LIBS
=
-Ivendor
/lib
-lpthread
-lleveldb
LD_FLAGS
=
-Lvendor
/lib
-lpthread
-lrocksdb
#-static
HEADERS
=
-Iinc
-Ivendor
/include
LIBS
=
#SQLITE_SRC=vendor/sqlite/sqlite3.
#SQLITE=sqlite3.o
SQLITE_SRC
=
...
...
@@ -21,22 +23,22 @@ sqlite3.o: vendor/sqlite/sqlite3.c
gcc
-D
SQLITE_THREADSAFE
=
1
-c
vendor/sqlite/sqlite3.c
evmgr
:
evmgr.cpp database.cpp inc/common.hpp inc/database.h inc/zmqhelper.hpp inc/tinythread.hpp $(SQLITE_SRC)
$(CPP)
$(CPPFLAGS)
-o
evmgr evmgr.cpp
$(SQLITE)
database.cpp
$(HEADERS)
$(LIBFFMPEG)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
$(LD_FLAGS)
-o
evmgr evmgr.cpp
$(SQLITE)
database.cpp
$(HEADERS)
$(LIBFFMPEG)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
evpuller
:
evpuller.cpp database.cpp inc/common.hpp inc/database.h inc/zmqhelper.hpp inc/tinythread.hpp $(SQLITE_SRC)
$(CPP)
$(CPPFLAGS)
-o
evpuller evpuller.cpp
$(SQLITE)
database.cpp
$(HEADERS)
$(LIBFFMPEG)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
$(LD_FLAGS)
-o
evpuller evpuller.cpp
$(SQLITE)
database.cpp
$(HEADERS)
$(LIBFFMPEG)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
evpusher
:
evpusher.cpp inc/common.hpp inc/tinythread.hpp inc/database.h inc/zmqhelper.hpp database.cpp $(SQLITE_SRC)
$(CPP)
$(CPPFLAGS)
-o
evpusher evpusher.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
$(LD_FLAGS)
-o
evpusher evpusher.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
evslicer
:
evslicer.cpp inc/common.hpp inc/tinythread.hpp inc/database.h inc/zmqhelper.hpp database.cpp $(SQLITE_SRC)
$(CPP)
$(CPPFLAGS)
-o
evslicer evslicer.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
$(LD_FLAGS)
-o
evslicer evslicer.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
evmlmotion
:
evmlmotion.cpp inc/common.hpp inc/avcvhelpers.hpp inc/database.h inc/zmqhelper.hpp inc/tinythread.hpp database.cpp $(SQLITE_SRC)
$(CPP)
$(CPPFLAGS)
-o
evmlmotion evmlmotion.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
$(LIBOPENCV)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
$(CPP)
$(CPPFLAGS)
$(LD_FLAGS)
-o
evmlmotion evmlmotion.cpp database.cpp
$(SQLITE)
$(LIBFFMPEG)
$(HEADERS)
$(LIBOPENCV)
`
pkg-config
--cflags
--libs
vendor/lib/pkgconfig/libzmq.pc
`
$(LIBS)
rtspr
:
rtsp-relay.cpp
$(CPP)
$(CPPFLAGS)
-o
rtspr rtsp-relay.cpp
$(LIBFFMPEG)
$(LIB
S)
$(CPP)
$(CPPFLAGS)
$(LD_FLAGS)
-o
rtspr rtsp-relay.cpp
$(LIBFFMPEG)
$(LD_FLAG
S)
cvsample
:
cvsample.cpp
$(CPP)
$(CPPFLAGS)
-o
cvsample cvsample.cpp
$(LIBOPENCV)
...
...
opencv-motion-detect/database.cpp
浏览文件 @
f7aa0a70
...
...
@@ -5,7 +5,34 @@
#include <mutex>
#include <map>
using
namespace
leveldb
;
using
namespace
rocksdb
;
string
_config_default_tmpl
=
"{
\"
time
\"
:0,
\"
code
\"
:0,
\"
data
\"
:{
\"
<SN_MGR>
\"
:{
\"
sn
\"
:
\"
<SN_MGR>
\"
,
\"
addr
\"
:
\"
127.0.0.1
\"
,
\"
addr-cloud
\"
:
\"
<cloud_addr>
\"
,
\"
proto
\"
:
\"
zmq
\"
,
\"
port-cloud
\"
:5556,
\"
port-router
\"
:5550,
\"
status
\"
:1,
\"
ipcs
\"
:[{
\"
addr
\"
:
\"
172.31.0.51
\"
,
\"
proto
\"
:
\"
rtsp
\"
,
\"
user
\"
:
\"
admin
\"
,
\"
password
\"
:
\"
FWBWTU
\"
,
\"
status
\"
:0,
\"
modules
\"
:{
\"
evpuller
\"
:[{
\"
sn
\"
:
\"
<SN_PULLER>
\"
,
\"
addr
\"
:
\"
127.0.0.1
\"
,
\"
iid
\"
:1,
\"
port-pub
\"
:5556,
\"
status
\"
:0}],
\"
evpusher
\"
:[{
\"
sn
\"
:
\"
<SN_PUSHER>
\"
,
\"
iid
\"
:1,
\"
urlDest
\"
:
\"
rtsp://40.73.41.176:554/test1
\"
,
\"
user
\"
:
\"\"
,
\"
password
\"
:
\"\"
,
\"
token
\"
:
\"\"
,
\"
enabled
\"
:1,
\"
status
\"
:0}],
\"
evslicer
\"
:[{
\"
sn
\"
:
\"
<SN_SLICER>
\"
,
\"
iid
\"
:1,
\"
path
\"
:
\"
slices
\"
,
\"
enabled
\"
:1,
\"
status
\"
:0}],
\"
evml
\"
:[{
\"
type
\"
:
\"
motion
\"
,
\"
sn
\"
:
\"
<SN_ML>
\"
,
\"
iid
\"
:1,
\"
enabled
\"
:1,
\"
status
\"
:0}]}}]}}}"
;
const
string
_sn_tmpl
[]
=
{
"<SN_MGR>"
,
"<SN_PULLER>"
,
"<SN_PUSHER>"
,
"<SN_SLICER>"
,
"<SN_ML>"
};
const
string
_addr_tmpl
[]
=
{
"<ADDR_CAMERA>"
};
// TODO:
string
getStrRand
(
int
length
)
{
static
bool
bRand
=
false
;
if
(
!
bRand
)
{
srand
(
time
(
NULL
));
bRand
=
true
;
}
static
string
charset
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
;
string
result
;
result
.
resize
(
length
);
srand
(
time
(
NULL
));
for
(
int
i
=
0
;
i
<
length
;
i
++
)
result
[
i
]
=
charset
[
rand
()
%
charset
.
length
()];
return
result
;
}
namespace
LVDB
{
map
<
string
,
DB
*>
mappDB
;
DB
*
_getDB
(
string
fileName
)
{
...
...
@@ -45,9 +72,9 @@ namespace LVDB {
int
getValue
(
string
&
value
,
string
key
,
string
fileName
,
cb_verify_str
cb
)
{
int
ret
=
0
;
DB
*
pdb
=
_getDB
(
fileName
);
Status
s
=
pdb
->
Get
(
leveldb
::
ReadOptions
(),
key
,
&
value
);
Status
s
=
pdb
->
Get
(
ReadOptions
(),
key
,
&
value
);
if
(
!
s
.
ok
())
{
spdlog
::
error
(
"failed to get {} from {}: {}"
,
key
,
fileName
,
s
.
ToString
());
spdlog
::
debug
(
"failed to get {} from {}: {}"
,
key
,
fileName
,
s
.
ToString
());
return
-
1
;
}
if
(
cb
!=
NULL
)
{
...
...
@@ -57,7 +84,6 @@ namespace LVDB {
return
ret
;
}
int
setValue
(
const
string
&
value
,
string
key
,
string
fileName
,
cb_verify_str
cb
)
{
int
ret
=
0
;
if
(
cb
!=
NULL
)
{
...
...
@@ -71,17 +97,17 @@ namespace LVDB {
string
oldVal
;
Status
s
=
pdb
->
Get
(
ReadOptions
(),
key
,
&
oldVal
);
if
(
!
s
.
ok
())
{
spdlog
::
warn
(
"get old {} error {}:{}"
,
key
,
fileName
,
s
.
ToString
());
spdlog
::
debug
(
"get old {} error {}:{}"
,
key
,
fileName
,
s
.
ToString
());
}
s
=
pdb
->
Put
(
leveldb
::
WriteOptions
(),
key
,
value
);
s
=
pdb
->
Put
(
WriteOptions
(),
key
,
value
);
if
(
!
s
.
ok
())
{
spdlog
::
error
(
"failed to put {} -> {}: {}"
,
key
,
value
,
s
.
ToString
());
return
-
2
;
}
if
(
!
oldVal
.
empty
())
{
s
=
pdb
->
Put
(
leveldb
::
WriteOptions
(),
key
+
LVDB_KEY_SUFFIX_BACK
,
oldVal
);
s
=
pdb
->
Put
(
WriteOptions
(),
key
+
LVDB_KEY_SUFFIX_BACK
,
oldVal
);
if
(
!
s
.
ok
())
{
spdlog
::
error
(
"failed to put backup {} -> {}: {}"
,
key
,
oldVal
,
s
.
ToString
());
return
-
2
;
...
...
@@ -92,15 +118,6 @@ namespace LVDB {
}
int
getValue
(
json
&
value
,
string
key
,
string
fileName
,
cb_verify_json
cb
)
{
// DB* pdb = _getDB(fileName);
// string oldVal;
// int ret = 0;
// json j;
// Status s = pdb->Get(leveldb::ReadOptions(), key, &oldVal);
// if(!s.ok()) {
// spdlog::error("failed to get {} from {}: {}",key, fileName, s.ToString());
// return -1;
// }
string
s
;
int
ret
=
getValue
(
s
,
key
,
fileName
,
NULL
);
if
(
ret
<
0
)
{
...
...
@@ -160,7 +177,41 @@ namespace LVDB {
}
int
getSn
(
json
&
info
,
string
fileName
){
return
getValue
(
info
,
LVDB_KEY_SN
,
fileName
,
_validateSn
);
int
ret
=
0
;
ret
=
getValue
(
info
,
LVDB_KEY_SN
,
fileName
,
_validateSn
);
if
(
ret
<
0
)
{
// create default sn.
string
sn
=
getStrRand
(
8
);
info
[
"sn"
]
=
sn
;
spdlog
::
warn
(
"no local sn set. create a new one: {}"
,
sn
);
auto
tsNow
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
info
[
"lastboot"
]
=
tsNow
;
info
[
"updatetime"
]
=
tsNow
;
ret
=
setSn
(
info
,
fileName
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to save new generated sn"
);
exit
(
1
);
}
else
{
// replace sn
int
idx
=
0
;
for
(
auto
&
j
:
_sn_tmpl
)
{
idx
=
0
;
while
(
true
)
{
idx
=
_config_default_tmpl
.
find
(
j
,
idx
);
if
(
idx
==
string
::
npos
)
break
;
_config_default_tmpl
.
replace
(
idx
,
j
.
size
(),
sn
);
idx
+=
sn
.
size
();
}
}
// replace camera addr, user, password, cloud-addr
spdlog
::
debug
(
"new config: {}"
,
_config_default_tmpl
);
return
setValue
(
_config_default_tmpl
,
LVDB_KEY_CONFIG
,
fileName
,
NULL
);
}
}
return
ret
;
};
int
setSn
(
json
&
info
,
string
fileName
){
...
...
@@ -177,7 +228,7 @@ namespace LVDB {
}
int
getLocalConfig
(
json
&
config
,
string
fileName
){
return
getValue
(
config
,
LVDB_KEY_CONFIG
,
fileName
,
_validateConfig
);
return
getValue
(
config
,
LVDB_KEY_CONFIG
,
fileName
,
_validateConfig
);
};
int
setLocalConfig
(
json
&
config
,
string
fileName
){
...
...
opencv-motion-detect/evmgr.cpp
浏览文件 @
f7aa0a70
...
...
@@ -19,6 +19,7 @@ update: 2019/08/23
#include <chrono>
#include <future>
#include <queue>
#include <ctime>
#ifdef OS_LINUX
#include <filesystem>
...
...
@@ -45,6 +46,7 @@ private:
mutex
cacheLock
;
queue
<
string
>
eventQue
;
mutex
eventQLock
;
time_t
tsLastBoot
,
tsUpdateTime
;
//
void
init
()
...
...
@@ -52,12 +54,29 @@ private:
int
ret
;
bool
inited
=
false
;
// TODO: load config from local db
devSn
=
"ILSEVMGR1"
;
json
info
;
ret
=
LVDB
::
getSn
(
info
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get sn"
);
exit
(
1
);
}
tsLastBoot
=
info
[
"lastboot"
];
tsUpdateTime
=
info
[
"updatetime"
];
spdlog
::
info
(
"evmgr info: sn = {}, lastboot = {}, updatetime = {}"
,
info
[
"sn"
].
get
<
string
>
(),
ctime
(
&
tsLastBoot
),
ctime
(
&
tsUpdateTime
));
devSn
=
info
[
"sn"
];
ret
=
LVDB
::
getLocalConfig
(
config
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get local configuration"
);
exit
(
1
);
}
int
opt_notify
=
ZMQ_NOTIFY_DISCONNECT
|
ZMQ_NOTIFY_CONNECT
;
string
proto
,
addr
;
while
(
!
inited
)
{
try
{
config
=
json
::
parse
(
cloudutils
::
config
);
spdlog
::
info
(
"config dumps:
\n
{}"
,
config
.
dump
());
// TODO: verify sn
if
(
!
config
.
count
(
"data"
)
||!
config
[
"data"
].
count
(
devSn
)
||!
config
[
"data"
][
devSn
].
count
(
"ipcs"
))
{
...
...
@@ -65,6 +84,7 @@ private:
goto
togo_sleep_continue
;
}
jmgr
=
config
[
"data"
][
devSn
];
proto
=
jmgr
[
"proto"
];
if
(
proto
!=
"zmq"
)
{
spdlog
::
warn
(
"evmgr {} unsupported protocol: {}, try fallback to zmq instead now..."
,
devSn
,
proto
);
...
...
opencv-motion-detect/evmlmotion.cpp
浏览文件 @
f7aa0a70
...
...
@@ -26,6 +26,7 @@ update: 2019/08/23
namespace
fs
=
std
::
filesystem
;
#endif
#include <cstdlib>
#include <ctime>
#include "zmqhelper.hpp"
#include "tinythread.hpp"
#include "common.hpp"
...
...
@@ -77,6 +78,7 @@ private:
chrono
::
system_clock
::
time_point
evtStartTm
,
evtStartTmLast
;
queue
<
string
>
*
evtQueue
;
int
streamIdx
=
-
1
;
time_t
tsLastBoot
,
tsUpdateTime
;
json
config
;
thread
thPing
;
thread
thEvent
;
...
...
@@ -86,15 +88,31 @@ private:
{
int
ret
=
0
;
bool
inited
=
false
;
// TODO: read db to get devSn
devSn
=
"ILSEVMLMOTION1"
;
iid
=
1
;
// TODO: load config from local db
json
info
;
ret
=
LVDB
::
getSn
(
info
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get sn"
);
exit
(
1
);
}
tsLastBoot
=
info
[
"lastboot"
];
tsUpdateTime
=
info
[
"updatetime"
];
spdlog
::
info
(
"evmgr info: sn = {}, lastboot = {}, updatetime = {}"
,
info
[
"sn"
].
get
<
string
>
(),
ctime
(
&
tsLastBoot
),
ctime
(
&
tsUpdateTime
));
devSn
=
info
[
"sn"
];
ret
=
LVDB
::
getLocalConfig
(
config
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get local configuration"
);
exit
(
1
);
}
selfId
=
devSn
+
":evmlmotion:"
+
to_string
(
iid
);
while
(
!
inited
)
{
// TODO: req config
bool
found
=
false
;
try
{
config
=
json
::
parse
(
cloudutils
::
config
);
spdlog
::
info
(
"config: {:s}"
,
config
.
dump
());
json
evmlmotion
;
json
evmgr
;
...
...
@@ -387,6 +405,7 @@ private:
if
(
detect
)
{
detectMotion
(
pCodecContext
->
pix_fmt
,
pFrame
);
}
break
;
}
}
return
0
;
...
...
opencv-motion-detect/evpuller.cpp
浏览文件 @
f7aa0a70
...
...
@@ -18,6 +18,7 @@ update: 2019/08/23
#include <iostream>
#include <chrono>
#include <future>
#include <ctime>
#ifdef OS_LINUX
#include <filesystem>
...
...
@@ -153,22 +154,38 @@ private:
AVFormatContext
*
pAVFormatInput
=
NULL
;
string
urlIn
,
urlPub
,
urlDealer
,
mgrSn
,
devSn
,
selfId
;
int
*
streamList
=
NULL
,
numStreams
=
0
,
iid
;
time_t
tsLastBoot
,
tsUpdateTime
;
json
config
;
int
init
()
{
bool
inited
=
false
;
// TODO: load devSn iid from database
devSn
=
"ILSEVPULLER1"
;
iid
=
1
;
// TODO: load config from local db
json
info
;
int
ret
=
LVDB
::
getSn
(
info
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get sn"
);
exit
(
1
);
}
tsLastBoot
=
info
[
"lastboot"
];
tsUpdateTime
=
info
[
"updatetime"
];
spdlog
::
info
(
"evmgr info: sn = {}, lastboot = {}, updatetime = {}"
,
info
[
"sn"
].
get
<
string
>
(),
ctime
(
&
tsLastBoot
),
ctime
(
&
tsUpdateTime
));
devSn
=
info
[
"sn"
];
ret
=
LVDB
::
getLocalConfig
(
config
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get local configuration"
);
exit
(
1
);
}
selfId
=
devSn
+
":evpuller:"
+
to_string
(
iid
);
int
ret
=
0
;
while
(
!
inited
)
{
// TODO: req config
bool
found
=
false
;
string
user
,
passwd
,
addr
;
try
{
config
=
json
::
parse
(
cloudutils
::
config
);
spdlog
::
info
(
"config dump: {:s}"
,
config
.
dump
());
json
data
=
config
[
"data"
];
// first try to check mgr with same sn
...
...
opencv-motion-detect/evpusher.cpp
浏览文件 @
f7aa0a70
...
...
@@ -18,6 +18,7 @@ update: 2019/08/23
#include <iostream>
#include <chrono>
#include <future>
#include <ctime>
#ifdef OS_LINUX
#include <filesystem>
...
...
@@ -44,21 +45,38 @@ private:
int
*
streamList
=
NULL
;
AVFormatContext
*
pAVFormatRemux
=
NULL
;
AVFormatContext
*
pAVFormatInput
=
NULL
;
time_t
tsLastBoot
,
tsUpdateTime
;
json
config
;
thread
thPing
;
int
init
()
{
bool
inited
=
false
;
// TODO: read db to get devSn
devSn
=
"ILSEVPUSHER1"
;
iid
=
1
;
// TODO: load config from local db
json
info
;
int
ret
=
LVDB
::
getSn
(
info
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get sn"
);
exit
(
1
);
}
tsLastBoot
=
info
[
"lastboot"
];
tsUpdateTime
=
info
[
"updatetime"
];
spdlog
::
info
(
"evmgr info: sn = {}, lastboot = {}, updatetime = {}"
,
info
[
"sn"
].
get
<
string
>
(),
ctime
(
&
tsLastBoot
),
ctime
(
&
tsUpdateTime
));
devSn
=
info
[
"sn"
];
ret
=
LVDB
::
getLocalConfig
(
config
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get local configuration"
);
exit
(
1
);
}
selfId
=
devSn
+
":evpusher:"
+
to_string
(
iid
);
while
(
!
inited
)
{
// TODO: req config
bool
found
=
false
;
try
{
config
=
json
::
parse
(
cloudutils
::
config
);
spdlog
::
info
(
"config: {:s}"
,
config
.
dump
());
json
evpusher
;
json
evmgr
;
...
...
@@ -349,7 +367,7 @@ protected:
bStopSig
=
true
;
break
;
}
int
ret
=
zmq_msg_init
(
&
msg
);
ret
=
zmq_msg_init
(
&
msg
);
if
(
ret
!=
0
)
{
spdlog
::
error
(
"failed to init zmq msg"
);
continue
;
...
...
opencv-motion-detect/evslicer.cpp
浏览文件 @
f7aa0a70
...
...
@@ -19,6 +19,7 @@ update: 2019/08/20
#include <chrono>
#include <future>
#include <vector>
#include <ctime>
#ifdef OS_LINUX
#include <filesystem>
...
...
@@ -52,6 +53,7 @@ private:
// load from db
vector
<
int
>
*
sliceIdxToName
=
NULL
;
int
*
streamList
=
NULL
;
time_t
tsLastBoot
,
tsUpdateTime
;
json
config
;
thread
thPing
;
...
...
@@ -59,9 +61,25 @@ private:
{
int
ret
=
0
;
bool
inited
=
false
;
// TODO: read db to get devSn
devSn
=
"ILSEVSLICER1"
;
iid
=
1
;
// TODO: load config from local db
json
info
;
ret
=
LVDB
::
getSn
(
info
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get sn"
);
exit
(
1
);
}
tsLastBoot
=
info
[
"lastboot"
];
tsUpdateTime
=
info
[
"updatetime"
];
spdlog
::
info
(
"evmgr info: sn = {}, lastboot = {}, updatetime = {}"
,
info
[
"sn"
].
get
<
string
>
(),
ctime
(
&
tsLastBoot
),
ctime
(
&
tsUpdateTime
));
devSn
=
info
[
"sn"
];
ret
=
LVDB
::
getLocalConfig
(
config
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed to get local configuration"
);
exit
(
1
);
}
selfId
=
devSn
+
":evslicer:"
+
to_string
(
iid
);
// TODO: read local slices list and last index
...
...
@@ -69,7 +87,6 @@ private:
// TODO: req config
bool
found
=
false
;
try
{
config
=
json
::
parse
(
cloudutils
::
config
);
spdlog
::
info
(
"config: {:s}"
,
config
.
dump
());
json
evslicer
;
json
evmgr
;
...
...
opencv-motion-detect/inc/common.hpp
浏览文件 @
f7aa0a70
...
...
@@ -364,18 +364,20 @@ namespace cloudutils
}
}
*/
const
char
*
config
=
"{
\"
time
\"
:0,
\"
code
\"
:0,
\"
data
\"
:{
\"
ILSEVMGR1
\"
:{
\"
sn
\"
:
\"
ILSEVMGR1
\"
,
\"
addr
\"
:
\"
127.0.0.1
\"
,
\"
addr-cloud
\"
:
\"
127.0.0.1
\"
,
\"
proto
\"
:
\"
zmq
\"
,
\"
port-cloud
\"
:5556,
\"
port-router
\"
:5550,
\"
status
\"
:1,
\"
ipcs
\"
:[{
\"
addr
\"
:
\"
172.31.0.203
\"
,
\"
proto
\"
:
\"
rtsp
\"
,
\"
user
\"
:
\"
admin
\"
,
\"
password
\"
:
\"
iLabService
\"
,
\"
status
\"
:1,
\"
modules
\"
:{
\"
evpuller
\"
:[{
\"
sn
\"
:
\"
ILSEVPULLER1
\"
,
\"
addr
\"
:
\"
127.0.0.1
\"
,
\"
iid
\"
:1,
\"
port-pub
\"
:5556,
\"
status
\"
:1}],
\"
evpusher
\"
:[{
\"
sn
\"
:
\"
ILSEVPUSHER1
\"
,
\"
iid
\"
:1,
\"
urlDest
\"
:
\"
rtsp://40.73.41.176:554/test1
\"
,
\"
user
\"
:
\"\"
,
\"
password
\"
:
\"\"
,
\"
token
\"
:
\"\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evslicer
\"
:[{
\"
sn
\"
:
\"
ILSEVSLICER1
\"
,
\"
iid
\"
:1,
\"
path
\"
:
\"
slices
\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evml
\"
:[{
\"
type
\"
:
\"
motion
\"
,
\"
sn
\"
:
\"
ILSEVMLMOTION1
\"
,
\"
iid
\"
:1,
\"
enabled
\"
:1,
\"
status
\"
:1}]}}]}}}"
;
// const char *config = "{\"time\":0,\"code\":0,\"data\":{\"ILSEVMGR1\":{\"sn\":\"ILSEVMGR1\",\"addr\":\"127.0.0.1\",\"addr-cloud\":\"127.0.0.1\",\"proto\":\"zmq\",\"port-cloud\":5556,\"port-router\":5550,\"status\":1,\"ipcs\":[{\"addr\":\"172.31.0.51
\",\"proto\":\"rtsp\",\"user\":\"admin\",\"password\":\"iLabService\",\"status\":1,\"modules\":{\"evpuller\":[{\"sn\":\"ILSEVPULLER1\",\"addr\":\"127.0.0.1\",\"iid\":1,\"port-pub\":5556,\"status\":1}],\"evpusher\":[{\"sn\":\"ILSEVPUSHER1\",\"iid\":1,\"urlDest\":\"rtsp://40.73.41.176:554/test1\",\"user\":\"\",\"password\":\"\",\"token\":\"\",\"enabled\":1,\"status\":1}],\"evslicer\":[{\"sn\":\"ILSEVSLICER1\",\"iid\":1,\"path\":\"slices\",\"enabled\":1,\"status\":1}],\"evml\":[{\"type\":\"motion\",\"sn\":\"ILSEVMLMOTION1\",\"iid\":1,\"enabled\":1,\"status\":1}]}}]}}}";
json
registry
(
const
char
*
sn
,
const
char
*
scn
,
int
iid
)
json
registry
(
const
char
*
sn
,
const
json
&
config
)
{
// find local info in db
// request cloud info
// moc
json
ret
=
json
::
parse
(
config
);
return
ret
;
return
json
();
}
}
// namespace cloudutils
...
...
opencv-motion-detect/inc/database.h
浏览文件 @
f7aa0a70
#ifndef __DATABSE_LEVEL_DB_H__
#define __DATABSE_LEVEL_DB_H__
#include "leveldb/db.h"
// #include "leveldb/db.h"
#include "rocksdb/db.h"
#include "rocksdb/slice.h"
#include "rocksdb/options.h"
#include "json.hpp"
using
namespace
nlohmann
;
...
...
@@ -10,7 +13,7 @@ namespace LVDB {
#define LVDB_PATH "/opt/lvldb/"
// sn, config
#define LVDB_FILE_GENERAL LVDB_PATH"general.db"
#define LVDB_FILE_GENERAL LVDB_PATH
"general.db"
// slices, log
#define LVDB_FILE_LOG LVDB_PATH"log.db"
...
...
@@ -23,12 +26,12 @@ namespace LVDB {
int
delValue
(
string
key
,
string
fileName
);
// sn, updatetime, boottime
int
setSn
(
json
&
info
,
string
fileName
);
int
getSn
(
json
&
info
,
string
fileName
);
int
setSn
(
json
&
info
,
string
fileName
=
LVDB_FILE_GENERAL
);
int
getSn
(
json
&
info
,
string
fileName
=
LVDB_FILE_GENERAL
);
// cloudutils::config
int
getLocalConfig
(
json
&
config
,
string
fileName
);
int
setLocalConfig
(
json
&
config
,
string
fileName
);
int
getLocalConfig
(
json
&
config
,
string
fileName
=
LVDB_FILE_GENERAL
);
int
setLocalConfig
(
json
&
config
,
string
fileName
=
LVDB_FILE_GENERAL
);
// slices
int
getSlices
(
json
&
slices
,
string
fileName
);
...
...
opencv-motion-detect/test_database.cpp
浏览文件 @
f7aa0a70
...
...
@@ -2,20 +2,16 @@
#include "inc/database.h"
#include "spdlog/spdlog.h"
const
char
*
_config
=
"{
\"
time
\"
:0,
\"
code
\"
:0,
\"
data
\"
:{
\"
ILSEVMGR1
\"
:{
\"
sn
\"
:
\"
ILSEVMGR1
\"
,
\"
addr
\"
:
\"
172.31.0.76
\"
,
\"
addr-cloud
\"
:
\"
172.31.0.76
\"
,
\"
proto
\"
:
\"
zmq
\"
,
\"
port-cloud
\"
:5556,
\"
port-router
\"
:5550,
\"
status
\"
:1,
\"
ipcs
\"
:[{
\"
addr
\"
:
\"
172.31.0.51
\"
,
\"
proto
\"
:
\"
rtsp
\"
,
\"
user
\"
:
\"
admin
\"
,
\"
password
\"
:
\"
FWBWTU
\"
,
\"
status
\"
:1,
\"
modules
\"
:{
\"
evpuller
\"
:[{
\"
sn
\"
:
\"
ILSEVPULLER1
\"
,
\"
addr
\"
:
\"
172.31.0.76
\"
,
\"
iid
\"
:1,
\"
port-pub
\"
:5556,
\"
status
\"
:1}],
\"
evpusher
\"
:[{
\"
sn
\"
:
\"
ILSEVPUSHER1
\"
,
\"
iid
\"
:1,
\"
urlDest
\"
:
\"
rtsp://40.73.41.176:554/test1
\"
,
\"
user
\"
:
\"\"
,
\"
password
\"
:
\"\"
,
\"
token
\"
:
\"\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evslicer
\"
:[{
\"
sn
\"
:
\"
ILSEVSLICER1
\"
,
\"
iid
\"
:1,
\"
path
\"
:
\"
slices
\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evml
\"
:[{
\"
type
\"
:
\"
motion
\"
,
\"
sn
\"
:
\"
ILSEVMLMOTION1
\"
,
\"
iid
\"
:1,
\"
enabled
\"
:1,
\"
status
\"
:1}]}}]}}}"
;
int
main
(){
json
j
;
int
ret
=
0
;
// sn
ret
=
LVDB
::
delValue
(
LVDB_KEY_SN
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}"
,
ret
);
ret
=
LVDB
::
setSn
(
j
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}"
,
ret
);
j
[
"sn"
]
=
"snaaaa"
;
j
[
"lastboot"
]
=
"2019-08-25 10:10:10"
;
j
[
"updatetime"
]
=
"2019-08-25 10:10:11"
;
ret
=
LVDB
::
getSn
(
j
,
LVDB_FILE_GENERAL
)
;
spdlog
::
info
(
"ret2: {}, {}"
,
ret
,
j
.
dump
())
;
ret
=
LVDB
::
setSn
(
j
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}"
,
ret
);
...
...
@@ -24,23 +20,17 @@ int main(){
ret
=
LVDB
::
getSn
(
j
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
j
.
dump
());
//
json
config
=
json
::
parse
(
_config
);
j
.
clear
();
ret
=
LVDB
::
delValue
(
LVDB_KEY_CONFIG
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}"
,
ret
);
ret
=
LVDB
::
getLocalConfig
(
j
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
j
.
dump
());
spdlog
::
info
(
"ret
1
: {}, {}"
,
ret
,
j
.
dump
());
ret
=
LVDB
::
setLocalConfig
(
j
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
j
.
dump
());
ret
=
LVDB
::
setLocalConfig
(
config
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
config
.
dump
());
spdlog
::
info
(
"ret2: {}, {}"
,
ret
,
j
.
dump
());
ret
=
LVDB
::
getLocalConfig
(
j
,
LVDB_FILE_GENERAL
);
spdlog
::
info
(
"ret: {}, {}"
,
ret
,
j
.
dump
());
spdlog
::
info
(
"ret
3
: {}, {}"
,
ret
,
j
.
dump
());
return
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论