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

init

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