提交 369d2115 authored 作者: blu's avatar blu

init

上级 b1faa8a0
...@@ -25,9 +25,27 @@ using namespace std; ...@@ -25,9 +25,27 @@ using namespace std;
* app update * app update
* control msg * control msg
* *
*
**/ **/
class EvMgr:public TinyThread {
private:
void *pRouterCtx = NULL;
void *pRouter = NULL;
void init(){
}
protected:
public:
EvMgr() {
init();
}
~EvMgr(){
}
};
int main(int argc, const char *argv[]){ int main(int argc, const char *argv[]){
return 0; return 0;
......
...@@ -21,7 +21,7 @@ namespace fs = std::filesystem; ...@@ -21,7 +21,7 @@ namespace fs = std::filesystem;
using namespace std; using namespace std;
class RepSrv: public TinyThread { class RepSrv: public TinyThread {
private: private:
string sn; string sn;
int iid; int iid;
string urlRep; string urlRep;
...@@ -40,7 +40,8 @@ class RepSrv: public TinyThread { ...@@ -40,7 +40,8 @@ class RepSrv: public TinyThread {
} }
return 0; return 0;
} }
int setupMq(){ int setupMq()
{
int ret = 0; int ret = 0;
pRepCtx = zmq_ctx_new(); pRepCtx = zmq_ctx_new();
...@@ -54,14 +55,15 @@ class RepSrv: public TinyThread { ...@@ -54,14 +55,15 @@ class RepSrv: public TinyThread {
return 0; return 0;
} }
public: public:
RepSrv() = delete; RepSrv() = delete;
RepSrv(RepSrv &) = delete; RepSrv(RepSrv &) = delete;
RepSrv(RepSrv&&) = delete; RepSrv(RepSrv&&) = delete;
RepSrv(string sn, int iid, string urlRep, const char* formatBytes, int len):sn(sn), iid(iid),urlRep(urlRep), bytes(formatBytes), len(len){}; RepSrv(string sn, int iid, string urlRep, const char* formatBytes, int len):sn(sn), iid(iid),urlRep(urlRep), bytes(formatBytes), len(len) {};
~RepSrv(){}; ~RepSrv() {};
protected: protected:
void run(){ void run()
{
bool bStopSig = false; bool bStopSig = false;
if(setupMq() != 0) { if(setupMq() != 0) {
exit(1); exit(1);
...@@ -96,6 +98,69 @@ private: ...@@ -96,6 +98,69 @@ private:
AVFormatContext *pAVFormatInput = NULL; AVFormatContext *pAVFormatInput = NULL;
string urlIn, urlPub, urlRep, sn; string urlIn, urlPub, urlRep, sn;
int *streamList = NULL, numStreams = 0, iid; int *streamList = NULL, numStreams = 0, iid;
int init()
{
bool inited = false;
sn = "ILS-2";
iid = 2;
while(!inited) {
// TODO: read db to get sn
// req config
json jr = cloudutils::registry(sn.c_str(), "evpuller", iid);
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"]);
urlRep = string("tcp://") +data["addr"].get<string>() + ":" + to_string(data["port-rep"]);
spdlog::info("evpuller {} {} bind on {} for pub, {} for rep", sn, iid, urlPub, urlRep);
}
catch(exception &e) {
bcnt = true;
spdlog::error("exception in EvPuller.init {:s}, retrying... ", e.what());
}
if(bcnt) {
this_thread::sleep_for(chrono::milliseconds(1000*20));
continue;
}
inited = true;
}
return 0;
}
int setupMq()
{
teardownMq();
pPubCtx = zmq_ctx_new();
pPub = zmq_socket(pPubCtx, ZMQ_PUB);
int rc = zmq_bind(pPub, urlPub.c_str());
if(rc != 0) {
spdlog::error("failed create pub: {}, {}", zmq_strerror(rc), urlPub.c_str());
this_thread::sleep_for(chrono::milliseconds(1000*20));
return -1;
}
return 0;
}
int teardownMq()
{
if(pPub != NULL) {
zmq_close(pPub);
}
if(pPubCtx != NULL) {
zmq_ctx_destroy(pPubCtx);
}
return 0;
}
public: public:
EvPuller() EvPuller()
...@@ -207,71 +272,6 @@ protected: ...@@ -207,71 +272,6 @@ protected:
std::cout << "Task End" << std::endl; std::cout << "Task End" << std::endl;
} }
} }
private:
int init()
{
bool inited = false;
sn = "ILS-2";
iid = 2;
while(!inited) {
// TODO: read db to get sn
// req config
json jr = cloudutils::registry(sn.c_str(), "evpuller", iid);
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"]);
urlRep = string("tcp://") +data["addr"].get<string>() + ":" + to_string(data["port-rep"]);
spdlog::info("evpuller {} {} bind on {} for pub, {} for rep", sn, iid, urlPub, urlRep);
}
catch(exception &e) {
bcnt = true;
spdlog::error("exception in EvPuller.init {:s}, retrying... ", e.what());
}
if(bcnt) {
this_thread::sleep_for(chrono::milliseconds(1000*20));
continue;
}
inited = true;
}
return 0;
}
int setupMq()
{
teardownMq();
pPubCtx = zmq_ctx_new();
pPub = zmq_socket(pPubCtx, ZMQ_PUB);
int rc = zmq_bind(pPub, urlPub.c_str());
if(rc != 0) {
spdlog::error("failed create pub: {}, {}", zmq_strerror(rc), urlPub.c_str());
this_thread::sleep_for(chrono::milliseconds(1000*20));
return -1;
}
return 0;
}
int teardownMq()
{
if(pPub != NULL) {
zmq_close(pPub);
}
if(pPubCtx != NULL) {
zmq_ctx_destroy(pPubCtx);
}
return 0;
}
}; };
...@@ -285,4 +285,3 @@ int main(int argc, char **argv) ...@@ -285,4 +285,3 @@ int main(int argc, char **argv)
evp.join(); evp.join();
return 0; return 0;
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论