Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
ed3f32a9
提交
ed3f32a9
authored
8月 14, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
eee69bf3
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
71 行增加
和
117 行删除
+71
-117
evpuller.cpp
opencv-motion-detect/evpuller.cpp
+71
-117
common.hpp
opencv-motion-detect/inc/common.hpp
+0
-0
没有找到文件。
opencv-motion-detect/evpuller.cpp
浏览文件 @
ed3f32a9
...
...
@@ -20,28 +20,35 @@ namespace fs = std::filesystem;
using
namespace
std
;
class
PacketProduc
er
:
public
TinyThread
{
class
EvPull
er
:
public
TinyThread
{
private
:
void
*
pPubContext
=
NULL
;
// for packets publishing
void
*
pPublisher
=
NULL
;
void
*
pPubCtx
=
NULL
;
// for packets publishing
void
*
pPub
=
NULL
;
void
*
pRepCtx
=
NULL
;
// for packets REP
void
*
pRep
=
NULL
;
AVFormatContext
*
pAVFormatInput
=
NULL
;
string
urlIn
;
string
urlIn
,
urlPub
;
int
*
streamList
=
NULL
,
numStreams
=
0
;
public
:
PacketProducer
(
string
urlIn
)
:
urlIn
(
urlIn
){
setupMq
();
}
EvPuller
()
{
int
ret
=
0
;
do
{
init
();
ret
=
setupMq
();
}
while
(
ret
<
0
);
}
~
PacketProducer
(){
}
~
EvPuller
()
{
}
protected
:
// Function to be executed by thread function
void
run
()
{
int
ret
=
0
;
setupMq
();
if
((
ret
=
avformat_open_input
(
&
pAVFormatInput
,
urlIn
.
c_str
(),
NULL
,
NULL
))
<
0
)
{
spdlog
::
error
(
"Could not open input file {}"
,
urlIn
);
}
...
...
@@ -83,7 +90,7 @@ protected:
AVStream
*
in_stream
;
AVPacket
packet
;
zmq_msg_t
msg
;
ret
=
av_read_frame
(
pAVFormatInput
,
&
packet
);
if
(
ret
<
0
)
{
spdlog
::
error
(
"failed read packet: {}"
,
av_err2str
(
ret
));
...
...
@@ -109,29 +116,66 @@ protected:
char
*
data
=
NULL
;
int
size
=
AVPacketSerializer
::
encode
(
packet
,
&
data
);
zmq_msg_init_data
(
&
msg
,
(
void
*
)
data
,
size
,
mqPacketFree
,
NULL
);
zmq_send_const
(
pPub
lisher
,
zmq_msg_data
(
&
msg
),
size
,
0
);
zmq_send_const
(
pPub
,
zmq_msg_data
(
&
msg
),
size
,
0
);
av_packet_unref
(
&
packet
);
}
// TODO:
if
(
ret
<
0
&&
!
bStopSig
)
{
// reconnect
}
else
{
}
else
{
std
::
cout
<<
"Task End"
<<
std
::
endl
;
}
}
private
:
private
:
int
init
()
{
bool
inited
=
false
;
while
(
!
inited
)
{
// TODO: read db to get sn
const
char
*
sn
=
"ILS-2"
;
// req config
json
jr
=
cloudutils
::
registry
(
sn
,
"evpuller"
,
0
);
bool
bcnt
=
false
;
try
{
spdlog
::
info
(
"registry: {:s}"
,
jr
.
dump
());
string
ipc
=
jr
[
"data"
][
"ipc"
];
string
user
=
jr
[
"data"
][
"username"
];
string
passwd
=
jr
[
"data"
][
"password"
];
json
data
=
jr
[
"data"
][
"services"
][
"evpuller"
];
urlIn
=
"rtsp://"
+
user
+
":"
+
passwd
+
"@"
+
ipc
+
"/h264/ch1/sub/av_stream"
;
urlPub
=
string
(
"tcp://"
)
+
data
[
"addr"
].
get
<
string
>
()
+
":"
+
to_string
(
data
[
"port-pub"
]);
}
catch
(
exception
&
e
)
{
bcnt
=
true
;
spdlog
::
error
(
e
.
what
());
}
if
(
bcnt
)
{
this_thread
::
sleep_for
(
chrono
::
milliseconds
(
1000
*
10
));
continue
;
}
inited
=
true
;
}
return
0
;
}
int
setupMq
()
{
teardownMq
();
pPubC
ontext
=
zmq_ctx_new
();
pPub
lisher
=
zmq_socket
(
pPubContext
,
ZMQ_PUB
);
pPubC
tx
=
zmq_ctx_new
();
pPub
=
zmq_socket
(
pPubCtx
,
ZMQ_PUB
);
int
rc
=
zmq_bind
(
pPub
lisher
,
"tcp://0.0.0.0:5556"
);
int
rc
=
zmq_bind
(
pPub
,
urlPub
.
c_str
()
);
if
(
rc
!=
0
)
{
spdlog
::
error
(
"failed create pub"
);
spdlog
::
error
(
"failed create pub: {}, {}"
,
zmq_strerror
(
rc
),
urlPub
.
c_str
());
this_thread
::
sleep_for
(
chrono
::
milliseconds
(
100
*
10
));
return
-
1
;
}
return
0
;
...
...
@@ -139,11 +183,11 @@ protected:
int
teardownMq
()
{
if
(
pPub
lisher
!=
NULL
)
{
zmq_close
(
pPub
lisher
);
if
(
pPub
!=
NULL
)
{
zmq_close
(
pPub
);
}
if
(
pPubC
ontext
!=
NULL
)
{
zmq_ctx_destroy
(
pPubC
ontext
);
if
(
pPubC
tx
!=
NULL
)
{
zmq_ctx_destroy
(
pPubC
tx
);
}
return
0
;
}
...
...
@@ -151,103 +195,13 @@ protected:
class
EdgeVideoMgr
{
private
:
#define SECS_SLICE (60*5/2)
AVFormatContext
*
pAVFormatInput
=
NULL
,
*
pAVFormatRemux
=
NULL
;
AVCodec
*
pCodec
=
NULL
;
AVDictionary
*
pOptsRemux
=
NULL
,
*
pOptsInput
=
NULL
,
*
pOptsOutput
=
NULL
;
int
idxVideo
=
-
1
,
idxAudio
=
-
1
,
numStreams
=
0
,
numSlices
=
6
,
secsSlice
=
SECS_SLICE
;
int
*
streamList
=
NULL
;
bool
bPush
=
true
,
bRecord
=
false
;
string
urlIn
,
urlOut
,
pathSlice
;
unordered_map
<
string
,
string
>
envParams
=
unordered_map
<
string
,
string
>
();
// mq
void
*
pRepContext
=
NULL
;
// for msg from edge gateway
void
*
pReqContext
=
NULL
;
// for msg to edge gateway
private
:
void
setupParams
()
{
char
*
tmp
=
getenv
(
"URL_IN"
);
urlIn
=
(
tmp
==
NULL
?
string
(
""
)
:
string
(
tmp
));
tmp
=
getenv
(
"URL_OUT"
);
urlOut
=
(
tmp
==
NULL
?
string
(
""
)
:
string
(
tmp
));
tmp
=
getenv
(
"SLICE_NUM"
);
numSlices
=
(
tmp
==
NULL
?
6
:
atoi
(
tmp
));
if
(
numSlices
<=
2
)
{
numSlices
=
6
;
}
spdlog
::
info
(
"in: {}"
,
urlIn
);
tmp
=
getenv
(
"SLICE_PATH"
);
pathSlice
=
(
tmp
==
NULL
?
string
(
"slices"
)
:
string
(
tmp
));
// OSX XCode doesn't ship with the filesystem header as of version 10.x
#ifdef __LINUX___
if
(
!
fs
::
exists
(
pathSlice
.
c_str
()))
{
if
(
!
fs
::
create_directory
(
pathSlice
.
c_str
()))
{
spdlog
::
error
(
"can't create directory: {}"
,
pathSlice
.
c_str
());
exit
(
1
);
}
fs
::
permissions
(
pathSlice
.
c_str
(),
fs
::
perms
::
all
);
}
#endif
tmp
=
getenv
(
"PUSH"
);
bPush
=
(
tmp
==
NULL
?
false
:
(
string
(
tmp
)
==
string
(
"false"
)
?
false
:
true
));
tmp
=
getenv
(
"SLICE_SECS"
);
secsSlice
=
(
tmp
==
NULL
?
SECS_SLICE
:
atoi
(
tmp
));
if
(
secsSlice
<
SECS_SLICE
)
{
secsSlice
=
SECS_SLICE
;
}
if
(
urlIn
==
""
or
urlOut
==
""
)
{
spdlog
::
error
(
"no input/output url"
);
exit
(
1
);
}
}
int
setupStreams
()
{
int
ret
=
0
;
PacketProducer
packetProducer
(
urlIn
);
packetProducer
.
join
();
// std::this_thread::sleep_for(std::chrono::milliseconds(30000));
// packetProducer.stop();
return
ret
;
}
public
:
// ctor
EdgeVideoMgr
()
{
setupParams
();
setupStreams
();
}
// dtor
~
EdgeVideoMgr
()
{
avformat_close_input
(
&
pAVFormatInput
);
/* close output */
if
(
pAVFormatRemux
&&
!
(
pAVFormatRemux
->
oformat
->
flags
&
AVFMT_NOFILE
))
avio_closep
(
&
pAVFormatRemux
->
pb
);
avformat_free_context
(
pAVFormatRemux
);
av_freep
(
&
streamList
);
}
};
int
main
(
int
argc
,
char
**
argv
)
{
av_log_set_level
(
AV_LOG_INFO
);
spdlog
::
set_level
(
spdlog
::
level
::
info
);
DB
::
exec
(
NULL
,
NULL
,
NULL
,
NULL
);
spdlog
::
info
(
"hello"
);
auto
vp
=
EdgeVideoMgr
();
DB
::
exec
(
NULL
,
NULL
,
NULL
,
NULL
);
auto
evp
=
EvPuller
(
);
evp
.
join
();
return
0
;
}
opencv-motion-detect/inc/common.hpp
浏览文件 @
ed3f32a9
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论