Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
a8c826da
提交
a8c826da
authored
8月 21, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
b4f34e71
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
23 行删除
+24
-23
evpuller.cpp
opencv-motion-detect/evpuller.cpp
+1
-1
evpusher.cpp
opencv-motion-detect/evpusher.cpp
+23
-22
没有找到文件。
opencv-motion-detect/evpuller.cpp
浏览文件 @
a8c826da
...
...
@@ -13,7 +13,7 @@
namespace
fs
=
std
::
filesystem
;
#endif
#include
<zmqhelper.hpp>
#include
"zmqhelper.hpp"
#include "tinythread.hpp"
#include "common.hpp"
#include "database.h"
...
...
opencv-motion-detect/evpusher.cpp
浏览文件 @
a8c826da
...
...
@@ -14,7 +14,7 @@
namespace
fs
=
std
::
filesystem
;
#endif
#include "
vendor/include/zmq.h
"
#include "
zmqhelper.hpp
"
#include "tinythread.hpp"
#include "common.hpp"
#include "database.h"
...
...
@@ -25,14 +25,15 @@ using namespace std;
class
EvPusher
:
public
TinyThread
{
private
:
void
*
pSubCtx
=
NULL
,
*
p
Req
Ctx
=
NULL
;
// for packets relay
void
*
pSub
=
NULL
,
*
p
Req
=
NULL
;
void
*
pSubCtx
=
NULL
,
*
p
Dealer
Ctx
=
NULL
;
// for packets relay
void
*
pSub
=
NULL
,
*
p
Dealer
=
NULL
;
string
urlOut
,
urlPub
,
urlRep
,
sn
;
int
iid
;
bool
enablePush
=
false
;
int
*
streamList
=
NULL
;
AVFormatContext
*
pAVFormatRemux
=
NULL
;
AVFormatContext
*
pAVFormatInput
=
NULL
;
json
config
;
int
init
()
{
...
...
@@ -42,11 +43,11 @@ private:
iid
=
2
;
while
(
!
inited
)
{
// req config
json
jr
=
cloudutils
::
registry
(
sn
.
c_str
(),
"evpusher"
,
iid
);
onfig
=
cloudutils
::
registry
(
sn
.
c_str
(),
"evpusher"
,
iid
);
bool
bcnt
=
false
;
try
{
spdlog
::
info
(
"registry: {:s}"
,
jr
.
dump
());
json
data
=
jr
[
"data"
][
"services"
][
"evpuller"
];
spdlog
::
info
(
"registry: {:s}"
,
config
.
dump
());
json
data
=
config
[
"data"
][
"services"
][
"evpuller"
];
string
addr
=
data
[
"addr"
].
get
<
string
>
();
if
(
addr
==
"0.0.0.0"
)
{
addr
=
"localhost"
;
...
...
@@ -55,7 +56,7 @@ private:
urlRep
=
string
(
"tcp://"
)
+
addr
+
":"
+
to_string
(
data
[
"port-rep"
]);
spdlog
::
info
(
"evpusher {} {} will connect to {} for sub, {} for req"
,
sn
,
iid
,
urlPub
,
urlRep
);
data
=
jr
[
"data"
][
"services"
][
"evpusher"
];
data
=
config
[
"data"
][
"services"
][
"evpusher"
];
for
(
auto
&
j
:
data
)
{
if
(
j
[
"sn"
]
==
sn
&&
iid
==
j
[
"iid"
]
&&
j
[
"enabled"
]
!=
0
)
{
urlOut
=
j
[
"urlDest"
];
...
...
@@ -99,10 +100,10 @@ private:
}
// setup req
p
Req
Ctx
=
zmq_ctx_new
();
p
Req
=
zmq_socket
(
pReq
Ctx
,
ZMQ_REQ
);
p
Dealer
Ctx
=
zmq_ctx_new
();
p
Dealer
=
zmq_socket
(
pDealer
Ctx
,
ZMQ_REQ
);
spdlog
::
info
(
"evpusher {} {} try create req to {}"
,
sn
,
iid
,
urlRep
);
ret
=
zmq_connect
(
p
Req
,
urlRep
.
c_str
());
ret
=
zmq_connect
(
p
Dealer
,
urlRep
.
c_str
());
if
(
ret
!=
0
)
{
spdlog
::
error
(
"evpusher {} {} failed create req to {}"
,
sn
,
iid
,
urlRep
);
...
...
@@ -124,13 +125,13 @@ private:
zmq_ctx_destroy
(
pSubCtx
);
pSubCtx
=
NULL
;
}
if
(
p
Req
!=
NULL
)
{
if
(
p
Dealer
!=
NULL
)
{
zmq_close
(
pSub
);
p
Req
=
NULL
;
p
Dealer
=
NULL
;
}
if
(
p
Req
Ctx
!=
NULL
)
{
if
(
p
Dealer
Ctx
!=
NULL
)
{
zmq_ctx_destroy
(
pSub
);
p
Req
Ctx
=
NULL
;
p
Dealer
Ctx
=
NULL
;
}
return
0
;
...
...
@@ -144,7 +145,7 @@ private:
// req avformatcontext packet
// send first packet to init connection
zmq_msg_t
msg
;
zmq_send
(
p
Req
,
"hello"
,
5
,
0
);
zmq_send
(
p
Dealer
,
"hello"
,
5
,
0
);
spdlog
::
info
(
"evpusher {} {} success send hello"
,
sn
,
iid
);
ret
=
zmq_msg_init
(
&
msg
);
if
(
ret
!=
0
)
{
...
...
@@ -152,7 +153,7 @@ private:
exit
(
1
);
}
// receive packet
ret
=
zmq_recvmsg
(
p
Req
,
&
msg
,
0
);
ret
=
zmq_recvmsg
(
p
Dealer
,
&
msg
,
0
);
spdlog
::
info
(
"evpusher {} {} recv"
,
sn
,
iid
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"evpusher {} {} failed to recv zmq msg: {}"
,
sn
,
iid
,
zmq_strerror
(
ret
));
...
...
@@ -165,13 +166,13 @@ private:
// close req
{
zmq_msg_close
(
&
msg
);
if
(
p
Req
!=
NULL
)
{
zmq_close
(
p
Req
);
p
Req
=
NULL
;
if
(
p
Dealer
!=
NULL
)
{
zmq_close
(
p
Dealer
);
p
Dealer
=
NULL
;
}
if
(
p
Req
Ctx
!=
NULL
)
{
zmq_ctx_destroy
(
p
Req
Ctx
);
p
Req
Ctx
=
NULL
;
if
(
p
Dealer
Ctx
!=
NULL
)
{
zmq_ctx_destroy
(
p
Dealer
Ctx
);
p
Dealer
Ctx
=
NULL
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论