Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evcamera
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evcamera
Commits
ead11e58
提交
ead11e58
authored
5月 29, 2020
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
video upload & motion detection
上级
0b173acb
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
133 行增加
和
49 行删除
+133
-49
video_file_request.md
docs/video_file_request.md
+1
-1
video_upload_stream.md
docs/video_upload_stream.md
+1
-1
CMakeCache.txt
hi3518/CMakeCache.txt
+6
-0
CMakeLists.txt
hi3518/CMakeLists.txt
+3
-1
evutils.cc
hi3518/evutils.cc
+13
-0
evutils.hpp
hi3518/evutils.hpp
+29
-2
internal_types.h
hi3518/internal_types.h
+1
-0
main.cc
hi3518/main.cc
+0
-0
motiondetect.hpp
hi3518/motiondetect.hpp
+34
-5
raw_tcp.cc
hi3518/raw_tcp.cc
+20
-0
raw_tcp.h
hi3518/raw_tcp.h
+2
-1
smart.cc
hi3518/smart.cc
+23
-16
evpacket.h
include/evpacket.h
+0
-13
mqtt_helper.hpp
include/mqtt_helper.hpp
+0
-9
没有找到文件。
docs/video_file_request.md
浏览文件 @
ead11e58
...
...
@@ -80,6 +80,6 @@ payload: {
```json
{ "time":1567669674, "cmd":"upload_video", "rid":"001231554A20", "data":{ "start":1590
542800, "end":15905429
00, "type":6 } }
{ "time":1567669674, "cmd":"upload_video", "rid":"001231554A20", "data":{ "start":1590
716600, "end":15907167
00, "type":6 } }
```
docs/video_upload_stream.md
浏览文件 @
ead11e58
...
...
@@ -45,7 +45,7 @@ SN := {UINT8*SN_LEN} # 摄像头SN, 长度为
START_TS := TS # 事件开始时间
END_TS := TS # 时间结束时间
TYPE := UINT8 # 0 - 未定义, 1 - AI人形, 2 - AI人脸, 3 - 移动侦测,
# 4 - 覆盖, 5 - 覆盖解除, 6 - 视频获取
# 4 - 覆盖, 5 - 覆盖解除, 6 - 视频获取
, 7 - AI和移动综合
# 其他 - 由发起请求的微服务自定义
FILE_META := FILE_TS,SIZE
FILE_TS := TS # 文件开始时间
...
...
hi3518/CMakeCache.txt
浏览文件 @
ead11e58
...
...
@@ -203,12 +203,18 @@ ntp_LIB_DEPENDS:STATIC=
//Dependencies for target
ptz_LIB_DEPENDS:STATIC=
//Dependencies for target
record_upload_LIB_DEPENDS:STATIC=
//Dependencies for target
smart_LIB_DEPENDS:STATIC=
//Dependencies for target
tcp_client_LIB_DEPENDS:STATIC=
//Dependencies for target
upload_LIB_DEPENDS:STATIC=
//Dependencies for target
util_LIB_DEPENDS:STATIC=
...
...
hi3518/CMakeLists.txt
浏览文件 @
ead11e58
...
...
@@ -24,7 +24,8 @@ add_library(mqtthelper STATIC ../include/mqtt_helper.cc)
add_library
(
motion STATIC motion.cc
)
add_library
(
smart STATIC smart.cc
)
add_library
(
ptz STATIC ptz.cc
)
add_library
(
record_upload STATIC record_upload.cc
)
add_executable
(
evcamera main.cc
)
target_link_libraries
(
evcamera PUBLIC ntp paho-mqtt3a mqtthelper tcp_client evutils smart motion ptz zmq
${
COMMON_LIBS
}
${
XM_LIBS
}
)
target_link_libraries
(
evcamera PUBLIC ntp paho-mqtt3a mqtthelper tcp_client evutils smart motion
record_upload
ptz zmq
${
COMMON_LIBS
}
${
XM_LIBS
}
)
add_executable
(
test_fsm test_fsm.cc
)
\ No newline at end of file
hi3518/evutils.cc
浏览文件 @
ead11e58
...
...
@@ -4,6 +4,18 @@ using namespace std;
using
namespace
jsoncons
;
using
namespace
jsoncons
::
literals
;
unsigned
short
crc16
(
const
unsigned
char
*
data_p
,
unsigned
char
length
){
unsigned
char
x
;
unsigned
short
crc
=
0xFFFF
;
while
(
length
--
){
x
=
crc
>>
8
^
*
data_p
++
;
x
^=
x
>>
4
;
crc
=
(
crc
<<
8
)
^
((
unsigned
short
)(
x
<<
12
))
^
((
unsigned
short
)(
x
<<
5
))
^
((
unsigned
short
)
x
);
}
return
crc
;
}
namespace
evutils
{
const
char
consts
::
version
[]
=
"EVC20200429"
;
const
string
consts
::
kMsgCmd
=
"cmd"
;
...
...
@@ -55,6 +67,7 @@ const string consts::pub_topic_report = "/evcamera/v1.0/report";
const
string
consts
::
mqtt_url
=
"tcp://admin:vJ3zHqWrHbrqxVMT@evcloudsvc.ilabservice.cloud:11883"
;
const
string
consts
::
vgw_addr
=
"tcp://evcloudsvc.ilabservice.cloud:7123"
;
const
string
consts
::
upload_addr
=
"tcp://evcloudsvc.ilabservice.cloud:10009"
;
const
string
consts
::
strPubUrl
=
"inproc://frame"
;
consts
&
consts
::
self
()
{
...
...
hi3518/evutils.hpp
浏览文件 @
ead11e58
...
...
@@ -15,6 +15,19 @@
#include <fmt/format.h>
#include <jsoncons/json.hpp>
struct
StrException
:
public
std
::
exception
{
std
::
string
s
;
StrException
(
std
::
string
ss
)
:
s
(
ss
)
{}
~
StrException
()
throw
()
{}
// Updated
const
char
*
what
()
const
throw
()
{
return
s
.
c_str
();
}
};
unsigned
short
crc16
(
const
unsigned
char
*
data_p
,
unsigned
char
length
);
namespace
evutils
{
using
namespace
std
;
using
namespace
jsoncons
;
...
...
@@ -70,6 +83,7 @@ typedef struct consts{
static
const
string
mqtt_url
;
static
const
string
vgw_addr
;
static
const
string
upload_addr
;
static
const
string
strPubUrl
;
static
consts
&
self
();
}
consts
;
...
...
@@ -167,7 +181,7 @@ public:
}
}
set
<
TN
>
findByRange
(
TN
tss
,
TN
tse
,
TN
&
offsetS
,
TN
&
offsetE
)
set
<
TN
>
findByRange
(
TN
tss
,
TN
tse
,
TN
&
offsetS
,
TN
&
offsetE
,
int
lagSecs
,
int
*
status
=
nullptr
)
{
set
<
TN
>
ret
;
lock_guard
<
mutex
>
lg
(
mut
);
...
...
@@ -179,8 +193,18 @@ public:
auto
_it
=
list_
.
end
();
TN
end
=
*
(
--
_it
);
if
(
tse
<
first
||
tss
>
end
)
{
if
(
tse
<
first
||
tss
>
end
||
tse
>
end
||
end
-
tse
<
lagSecs
*
1000
)
{
int
s
=
0
;
spdlog
::
info
(
"range requested ({}, {}) is not in range existed ({}, {})."
,
tss
,
tse
,
first
,
end
);
if
(
tse
<
first
)
{
s
=
-
1
;
}
else
{
s
=
1
;
}
if
(
status
){
*
status
=
s
;
}
return
ret
;
}
...
...
@@ -218,6 +242,9 @@ public:
if
(
last
!=
0
)
{
offsetE
=
last
-
tse
;
}
if
(
status
){
*
status
=
0
;
}
}
return
ret
;
...
...
hi3518/internal_types.h
浏览文件 @
ead11e58
...
...
@@ -13,6 +13,7 @@ typedef struct ev_region_t {
}
ev_region_t
;
typedef
struct
ev_module_config_t
{
MqttHelper
*
pClient
;
void
**
pPubCtx
;
struct
module
{
struct
record
{
int
interval
;
// in seconds
...
...
hi3518/main.cc
浏览文件 @
ead11e58
差异被折叠。
点击展开。
hi3518/motiondetect.hpp
浏览文件 @
ead11e58
...
...
@@ -7,8 +7,10 @@
#include <sml.hpp>
#include <map>
#include <string>
#include "record_upload.h"
namespace
sml
=
boost
::
sml
;
extern
thread_upload_args_t
gUploadArgs
;
namespace
md
{
/// types
...
...
@@ -23,6 +25,7 @@ namespace md{
const
string
kKeyN
=
"n"
;
const
string
kKeyP
=
"p"
;
const
int
kMaxCntMotionInPre
=
5
;
// about 20s
const
int
kMaxDuration
=
60
*
20
;
// max 20 minutes duration to force generating event videos
/// helpers
auto
event_inspection
(
auto
e
,
std
::
map
<
const
std
::
string
,
int
>
&
m
){
...
...
@@ -102,10 +105,13 @@ namespace md{
spdlog
::
info
(
"post -n-> none, {}"
,
timeEnd
/
1000
);
}
/// TODO: force event generation when max time duration reached
spdlog
::
info
(
"event start:{}, end:{}, hasMotion: {}"
,
timeStart
,
timeEnd
,
hasMotion
);
/// TODO: generate event for uploading
upload_item_t
item
{
timeStart
,
timeEnd
,
7
,
-
1
,
timeEnd
};
{
lock_guard
<
mutex
>
lg
(
*
gUploadArgs
.
mut
);
gUploadArgs
.
que
->
push
(
item
);
gUploadArgs
.
cv
->
notify_one
();
}
};
const
auto
action_pre2pre
=
[
this
](
auto
e
){
cntMotionOnly
++
;
...
...
@@ -114,6 +120,22 @@ namespace md{
timeStart
=
chrono
::
duration_cast
<
chrono
::
milliseconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
}
};
const
auto
may_generate_event
=
[
this
]{
auto
now
=
chrono
::
duration_cast
<
chrono
::
milliseconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
if
(
timeStart
!=
0
&&
(
now
-
timeStart
)
>=
kMaxDuration
*
1000
){
upload_item_t
item
{
timeStart
,
now
,
6
,
-
1
,
now
};
{
lock_guard
<
mutex
>
lg
(
*
gUploadArgs
.
mut
);
gUploadArgs
.
que
->
push
(
item
);
gUploadArgs
.
cv
->
notify_one
();
}
timeStart
=
now
;
return
true
;
}
return
false
;
};
using
namespace
sml
;
return
make_transition_table
(
*
"init"
_s
=
"none"
_s
,
...
...
@@ -121,28 +143,35 @@ namespace md{
"none"
_s
+
event
<
motion
>/
[]{
spdlog
::
info
(
"none -m-> pre"
);}
=
"pre"
_s
,
"none"
_s
+
event
<
people
>/
action_none2in
=
"in"
_s
,
"none"
_s
+
event
<
mpboth
>/
action_none2in
=
"in"
_s
,
// pre
"pre"
_s
+
event
<
none
>/
[]{
spdlog
::
info
(
"pre -n-> none"
);}
=
"none"
_s
,
"pre"
_s
+
event
<
motion
>/
action_pre2pre
=
"pre"
_s
,
"pre"
_s
+
event
<
people
>/
action_pre2in
=
"in"
_s
,
"pre"
_s
+
event
<
mpboth
>/
action_pre2in
=
"in"
_s
,
// in
"in"
_s
+
event
<
none
>
[
guard_in2post
]
/
[]{
spdlog
::
info
(
"in -n-> post"
);}
=
"post"
_s
,
"in"
_s
+
event
<
motion
>
[
guard_in2post
]
/
[]{
spdlog
::
info
(
"in -m-> post"
);}
=
"post"
_s
,
"in"
_s
+
event
<
people
>
[
guard_in2post
]
/
[]{
spdlog
::
info
(
"in -p-> post"
);}
=
"post"
_s
,
"in"
_s
+
event
<
mpboth
>/
guard_in2post
,
"in"
_s
+
sml
::
on_entry
<
_
>
/
may_generate_event
,
// post
"post"
_s
+
event
<
mpboth
>/
guard_post2none
=
"in"
_s
,
"post"
_s
+
event
<
people
>
[
guard_post2none
]
/
action_post2none
=
"none"
_s
,
"post"
_s
+
event
<
motion
>
[
guard_post2none
]
/
action_post2none
=
"none"
_s
,
"post"
_s
+
event
<
none
>
[
guard_post2none
]
/
action_post2none
=
"none"
_s
,
// "post"_s + sml::on_entry<_> / may_generate_event,
//
"none"
_s
+
sml
::
on_entry
<
_
>
/
[
this
]{
hasMotion
=
false
,
timeStart
=
0
;}
);
}
private
:
bool
hasMotion
{
false
};
int
cntMotionOnly
=
0
;
u
int64_t
timeStart
{
0
};
int64_t
timeStart
{
0
};
std
::
map
<
const
std
::
string
,
int
>
guards
{{
"m"
,
0
},
{
"p"
,
0
},
{
"n"
,
0
}};
};
}
...
...
hi3518/raw_tcp.cc
浏览文件 @
ead11e58
...
...
@@ -7,6 +7,8 @@
#include <fcntl.h>
#include "raw_tcp.h"
using
namespace
std
;
int
raw_connect
(
std
::
string
host
,
std
::
string
port
,
int
*
socket_
,
int
recv_timeout
,
int
send_timeout
)
{
int
rv
=
0
;
...
...
@@ -70,4 +72,21 @@ int raw_connect(std::string host, std::string port, int *socket_, int recv_timeo
::
freeaddrinfo
(
addrinfo_result
);
return
rv
;
}
string
raw_send
(
int
s
,
const
void
*
buf
,
size_t
len
){
string
rc
;
ssize_t
sent
=
0
;
while
(
len
>
0
)
{
sent
=
::
send
(
s
,
buf
,
len
,
0
);
if
(
sent
<=
0
){
break
;
}
len
-=
sent
;
}
if
(
len
>
0
||
sent
<=
0
){
rc
=
fmt
::
format
(
"failed to send: {}"
,
strerror
(
errno
));
}
return
rc
;
}
\ No newline at end of file
hi3518/raw_tcp.h
浏览文件 @
ead11e58
...
...
@@ -9,6 +9,6 @@
#include <mutex>
#include "common.h"
using
namespace
std
;
int
raw_connect
(
std
::
string
host
,
std
::
string
port
,
int
*
socket_
,
int
recv_timeout
=
3
,
int
send_timeout
=
3
);
std
::
string
raw_send
(
int
s
,
const
void
*
buf
,
size_t
len
);
#endif
\ No newline at end of file
hi3518/smart.cc
浏览文件 @
ead11e58
...
...
@@ -39,7 +39,6 @@ XM_S32 MaQue_JpegEnc_getFrame_callback (XM_VOID *pUserArg, MaQueSmartJpegFrame_s
return
XM_SUCCESS
;
}
void
maq_smart_task_entry
(
ev_module_config_t
*
pArg
)
{
if
(
!
pArg
->
module
.
ai
.
enabled
)
{
...
...
@@ -210,22 +209,30 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
int
deltaMotionCnt
=
motionCnt_
-
motionCntLast
;
motionCntLast
=
motionCnt_
;
spdlog
::
info
(
"deltaTimeMs {}"
,
deltaTimeMs
);
if
(
deltaMotionCnt
>=
motionCntThresh
)
{
hasMotion
=
true
;
}
if
(
hasMotion
&&
hasHuman
)
{
fsm
.
process_event
(
md
::
mpboth
{});
}
else
if
(
hasMotion
)
{
fsm
.
process_event
(
md
::
motion
{});
}
else
if
(
hasHuman
)
{
fsm
.
process_event
(
md
::
people
{});
}
else
{
fsm
.
process_event
(
md
::
none
{});
if
(
deltaTimeMs
==
0
){
spdlog
::
warn
(
"no video frames in last ~5 seconds"
);
}
else
{
if
(
deltaMotionCnt
>=
motionCntThresh
)
{
hasMotion
=
true
;
}
if
(
hasMotion
&&
hasHuman
)
{
spdlog
::
info
(
"ai_task: deltaTimeMs {}, mpboth"
,
deltaTimeMs
);
fsm
.
process_event
(
md
::
mpboth
{});
}
else
if
(
hasMotion
)
{
spdlog
::
info
(
"ai_task: deltaTimeMs {}, motion"
,
deltaTimeMs
);
fsm
.
process_event
(
md
::
motion
{});
}
else
if
(
hasHuman
)
{
spdlog
::
info
(
"ai_task: deltaTimeMs {}, people"
,
deltaTimeMs
);
fsm
.
process_event
(
md
::
people
{});
}
else
{
spdlog
::
info
(
"ai_task: deltaTimeMs {}, none"
,
deltaTimeMs
);
fsm
.
process_event
(
md
::
none
{});
}
}
// reset
windowSecs
=
kMotionDetectWindowSeconds
;
hasHuman
=
false
;
...
...
include/evpacket.h
浏览文件 @
ead11e58
...
...
@@ -49,18 +49,6 @@ typedef struct evpacket_t {
uint32_t
length
;
}
*
evpacket_ptr_t
;
static
inline
unsigned
short
crc16
(
const
unsigned
char
*
data_p
,
unsigned
char
length
){
unsigned
char
x
;
unsigned
short
crc
=
0xFFFF
;
while
(
length
--
){
x
=
crc
>>
8
^
*
data_p
++
;
x
^=
x
>>
4
;
crc
=
(
crc
<<
8
)
^
((
unsigned
short
)(
x
<<
12
))
^
((
unsigned
short
)(
x
<<
5
))
^
((
unsigned
short
)
x
);
}
return
crc
;
}
#endif
\ No newline at end of file
include/mqtt_helper.hpp
浏览文件 @
ead11e58
...
...
@@ -48,15 +48,6 @@ typedef void (*on_msg_fun_ptr_t)(MqttHelper *hlp, const void * const data, int l
template
<
typename
R
>
bool
is_ready
(
std
::
future
<
R
>
const
&
f
);
struct
StrException
:
public
std
::
exception
{
std
::
string
s
;
StrException
(
std
::
string
ss
)
:
s
(
ss
)
{}
~
StrException
()
throw
()
{}
// Updated
const
char
*
what
()
const
throw
()
{
return
s
.
c_str
();
}
};
class
MqttPub
{
private
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论