#include <stdio.h>
|
#include <iostream>
|
#include <unistd.h>
|
#include <cstring>
|
#include "RtspAnalysManager.h"
|
#include <basic/debug/Debug.h>
|
#include <thread>
|
#include <Ice/Ice.h>
|
#include <basic/rpc/IceRpc.hpp>
|
//"192.168.1.4", 8000, "admin", "basic123"
|
|
using namespace std;
|
|
#include <basic/util/file/FileUtil.h>
|
#include <basic/util/app/AppPreference.hpp>
|
#include <basic/util/app/AppConfig.h>
|
|
#include <GB28181Server.h>
|
#include <basic/util/net_config/net_config.h>
|
#include <DataManagerServer/vss/dao/VssLocalSettingTblSqliteDao.h>
|
|
static void startManager(LDBTool *_dbTool) {
|
RtspAnalysManager rtspAnalysManager(_dbTool);
|
while (1) {
|
sleep(1 * 60 * 60 * 12);
|
}
|
}
|
|
std::string getLocalIp() {
|
unsigned char netmask_old[15] = {0};
|
unsigned char gateway_old[15] = {0};
|
unsigned char ip_old[15] = {0};
|
|
std::string net_ifname = appConfig.getStringProperty("netIfName");
|
std::string str_ip;
|
|
if (GetIpAddress(net_ifname.c_str(), ip_old)) {
|
std::string ip_old_temp((char *) ip_old);
|
str_ip = ip_old_temp;
|
} else {
|
// value["ipaddr"] = "";
|
ERR("not get ip addr");
|
}
|
assert(!str_ip.empty());
|
return std::move(str_ip);
|
}
|
|
/***
|
* arg1 为-1时启用gb28181
|
* @param argc
|
* @param argv
|
* @return
|
*/
|
int main(int argc, char **argv) {
|
std::cout << __DATE__ << " " << __TIME__ << std::endl;
|
SAVE_APP_ARGS
|
|
#ifdef GLOG
|
ENABLEGLOG(GET_STR_CONFIG("logPath").c_str());
|
#endif
|
|
if (argc < 4) {
|
assert("t_value.size()");
|
}
|
{
|
// std::string rtmpAddr = appConfig.getStringProperty("srsAddr");
|
// std::string publish_basepath = rtmpAddr + "" ;
|
// appPref.setStringData("publish.basepath", publish_basepath);
|
appPref.setIntData("pulish.width", 640);
|
appPref.setIntData("pulish.height", 360);
|
}
|
int arg1 = atoi(argv[1]);
|
|
int gindx = abs(arg1) % 2;
|
int GB28181_Enable = arg1 < 0 ? 1 : 0;
|
|
DBG(gindx);
|
appPref.setIntData("GB28181_Enable", GB28181_Enable);
|
appPref.setLongData("gpu.index", gindx);
|
appPref.setIntData("show.image", 0);
|
|
//todo
|
appPref.setIntData("CamStart", arg1);
|
appPref.setIntData("CamStep", atoi(argv[2]));
|
appPref.setIntData("RpcServerPort", atoi(argv[3]));
|
if (GB28181_Enable) {
|
//#todo search from db
|
MysqlDBServerCfg mysqlDBServerCfg;
|
mysqlDBServerCfg.Host = getLocalIp();
|
mysqlDBServerCfg.Port = 3306;
|
mysqlDBServerCfg.UserName = "root";
|
mysqlDBServerCfg.Passwd = "123456";
|
mysqlDBServerCfg.DBName = "EGEyesForVSS";
|
mysqlDBServerCfg.DBConnCount = 5;
|
|
LDBTool ldbTool;
|
BaseSqliteDao::setLDBTool(&ldbTool);
|
|
//#todo search from db
|
Json::Value t_value;
|
{
|
LDBTool ldbTool;
|
BaseSqliteDao::setLDBTool(&ldbTool);
|
t_value = VssLocalSettingTblSqliteDao::instance()->findAllVssLocalSettingTblList();
|
}
|
if (t_value.size() == 1 && t_value["data"].size() > 1) {
|
assert("t_value.size()");
|
}
|
DBG(t_value["data"].begin()->toStyledString());
|
auto &t_cfg = *t_value["data"].begin();
|
GBServerCfg gbServerCfg;
|
gbServerCfg.SvrIp = t_cfg["ServerIp"].asString(); // 国标服务的ip地址 (本机的ip地址)
|
gbServerCfg.SvrPort = atoi(t_cfg["ServerPort"].asString().c_str());// 7060; // 国标服务监听的端口
|
gbServerCfg.SvrPubID = t_cfg["ServerId"].asString();// "44120000002000000001"; // 国标服务器的ID
|
gbServerCfg.bMD5Auth = false; // 是否需要MD5加密
|
gbServerCfg.UserName = t_cfg["UserAuthId"].asString();// "44120100002000000002"; // 国标服务的用户名 (下级设备注册的用户名)
|
gbServerCfg.Passwd = t_cfg["Password"].asString();// "123456"; // 国标服务的密码 (下级设备注册的密码)
|
gbServerCfg.SubScribeTime = 3600; // 订阅时间 如果为0 表示不订阅
|
|
SpinLock spinLock;
|
|
bool running = false;
|
bool serinit = false;
|
auto func = [&] {
|
spinLock.lock();
|
GB28181Server m_gbs;
|
m_gbs.setMysqlConnParam(mysqlDBServerCfg);
|
m_gbs.setGBServerParam(gbServerCfg);
|
DBG("initServer start before");
|
running = true;
|
m_gbs.initServer();
|
DBG("initServer start after");
|
|
spinLock.unlock();
|
while (running) {
|
usleep(4000);
|
}
|
};
|
|
std::thread thd(func);
|
thd.detach();
|
|
usleep(400);
|
// ---------------------测试------------------------
|
spinLock.lock();
|
// if (!running) {
|
// ERR("running is false << DB init error");
|
// exit(0);
|
// }
|
}
|
DBG("test start");
|
|
appPref.setStringData("user.loop.absolute.path", appConfig.getStringProperty("cutPath"));
|
IceRpcServer<RtspAnalysManager> server("RtspAnalysServer", appPref.getIntData("RpcServerPort"), "tcp");
|
server.setMessageSizeMax(1024 * 1024 * 50);
|
server.setPoolInitSize(1);
|
server.setPoolMaxSize(1);
|
server.runWaitShutDown();
|
return 0;
|
|
}
|