提交 1afbaa51 authored 作者: blu's avatar blu

init

上级 025ff250
CC = gcc
CPP = g++
CPPFLAGS = -g -Wall -std=gnu++1z
CFLAGS = -g -Wall
CPPFLAGS = -Wall -std=gnu++1z
CFLAGS = -Wall
LIBOPENCV = `pkg-config opencv --cflags --libs`
LIBFFMPEG = `pkg-config libavformat libavutil libavcodec libswscale --cflags --libs`
......
......@@ -96,12 +96,12 @@ private:
// ID_SENDER, ID_TARGET, MSG
if(body.size() != 3) {
spdlog::error("evmgr {} illegal message received, frame num: {}", devSn, body.size());
return -1;
spdlog::warn("evmgr {} dropped a message, since its size is incorrect: {}", devSn, body.size());
return 0;
}
// if need forward
if(memcmp((void*)(body[1].data()), devSn.data(), body[1].size()) != 0) {
if(memcmp((void*)(body[1].data()), (devSn +":0:0").data(), body[1].size()) != 0) {
spdlog::info("evmgr {} route msg from {} to {}", devSn, body2str(body[0]), body2str(body[1]));
vector<vector<uint8_t> >v;
v.push_back(body[1]);
......@@ -159,6 +159,7 @@ public:
int main(int argc, const char *argv[])
{
EvMgr mgr;
spdlog::set_level(spdlog::level::debug);
mgr.join();
return 0;
}
\ No newline at end of file
......@@ -47,7 +47,7 @@ protected:
// declare ready to router
vector<vector<uint8_t> >body;
// since identity is auto set
body.push_back(str2body(mgrSn));
body.push_back(str2body(mgrSn + ":0:0"));
body.push_back(str2body(MSG_HELLO));
ret = z_send_multiple(pDealer, body);
......@@ -328,7 +328,7 @@ public:
int main(int argc, char **argv)
{
av_log_set_level(AV_LOG_INFO);
spdlog::set_level(spdlog::level::info);
spdlog::set_level(spdlog::level::debug);
//DB::exec(NULL, NULL, NULL,NULL);
auto evp = EvPuller();
evp.join();
......
......@@ -108,7 +108,6 @@ private:
}
int setupMq()
{
teardownMq();
int ret = 0;
// setup sub
......@@ -125,7 +124,7 @@ private:
return -2;
}
// setup req
// setup dealer
pDealerCtx = zmq_ctx_new();
pDealer = zmq_socket(pDealerCtx, ZMQ_DEALER);
spdlog::info("evpusher {} {} try create req to {}", devSn, iid, urlDealer);
......@@ -141,9 +140,10 @@ private:
}
// send hello to router
spdlog::info("evpusher {} {} send hello to router: {}", devSn, iid, mgrSn);
vector<vector<uint8_t> >body;
// since identity is auto set
body.push_back(str2body(mgrSn));
body.push_back(str2body(mgrSn+":0:0"));
body.push_back(str2body(MSG_HELLO));
ret = z_send_multiple(pDealer, body);
......@@ -158,27 +158,6 @@ private:
return 0;
}
int teardownMq()
{
if(pSub != NULL) {
zmq_close(pSub);
pSub = NULL;
}
if(pSubCtx != NULL) {
zmq_ctx_destroy(pSubCtx);
pSubCtx = NULL;
}
if(pDealer != NULL) {
zmq_close(pSub);
pDealer = NULL;
}
if(pDealerCtx != NULL) {
zmq_ctx_destroy(pSub);
pDealerCtx = NULL;
}
return 0;
}
int setupStream()
{
......@@ -187,12 +166,13 @@ private:
// req avformatcontext packet
// send hello to puller
spdlog::info("evpusher {} {} send hello to puller: {}", devSn, iid, pullerGid);
vector<vector<uint8_t> > body;
body.push_back(str2body(pullerGid));
body.push_back(str2body(MSG_HELLO));
ret = z_send_multiple(pDealer, body);
if(ret < 0) {
spdlog::error("evpusher {} {}, failed to send hello: {}", devSn, iid, zmq_strerror(zmq_errno()));
spdlog::error("evpusher {} {}, failed to send hello to puller: {}", devSn, iid, zmq_strerror(zmq_errno()));
return ret;
}
spdlog::info("evpusher {} {} success send hello", devSn, iid);
......@@ -347,16 +327,28 @@ public:
EvPusher()
{
init();
if(setupMq() < 0) {
// TODO: reconnect
exit(1);
}
setupMq();
setupStream();
}
~EvPusher()
{
teardownMq();
if(pSub != NULL) {
zmq_close(pSub);
pSub = NULL;
}
if(pSubCtx != NULL) {
zmq_ctx_destroy(pSubCtx);
pSubCtx = NULL;
}
if(pDealer != NULL) {
zmq_close(pSub);
pDealer = NULL;
}
if(pDealerCtx != NULL) {
zmq_ctx_destroy(pSub);
pDealerCtx = NULL;
}
// free avformatcontex
if(pAVFormatInput != NULL) {
AVFormatCtxSerializer::freeCtx(pAVFormatInput);
......
......@@ -94,7 +94,7 @@ int encode(AVPacket &pkt, char **bytes)
memcpy((*bytes) + cnt, PS_MARK_E, strlen(PS_MARK_E));
cnt += strlen(PS_MARK_E);
assert(cnt == wholeSize);
spdlog::debug("pkt origin size {:d}, serialized size: {:d}, elems: {:d}", pkt.size, wholeSize, pkt.side_data_elems);
av_log(NULL, AV_LOG_DEBUG, "pkt origin size %d, serialized size: %d, elems: %d", pkt.size, wholeSize, pkt.side_data_elems);
return wholeSize;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论