From d3b7bbe7102cd089680a828f5d8f6402c8cf6342 Mon Sep 17 00:00:00 2001 From: pansen <pansen626@sina.com> Date: 星期四, 07 三月 2019 14:43:28 +0800 Subject: [PATCH] GB28181集成完成,集成推流模块 --- QiaoJiaSystem/DataManagerServer/vss/controller/VssLocalSettingTblController.h | 187 ++++++++++++---------- QiaoJiaSystem/VideoToImageMulth/CMakeLists.txt | 6 QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.h | 29 +++ QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h | 6 QiaoJiaSystem/VideoToImageMulth/main.cpp | 10 + QiaoJiaSystem/VideoAnalysFromHC/main.cpp | 2 QiaoJiaSystem/DataManagerServer/vss/dao/BaseDao.h | 80 +++++---- QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.cpp | 50 ++++++ QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp | 60 ++++--- QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp | 11 QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp | 3 11 files changed, 286 insertions(+), 158 deletions(-) diff --git a/QiaoJiaSystem/DataManagerServer/vss/controller/VssLocalSettingTblController.h b/QiaoJiaSystem/DataManagerServer/vss/controller/VssLocalSettingTblController.h index 13c8d09..2bef196 100755 --- a/QiaoJiaSystem/DataManagerServer/vss/controller/VssLocalSettingTblController.h +++ b/QiaoJiaSystem/DataManagerServer/vss/controller/VssLocalSettingTblController.h @@ -17,47 +17,52 @@ */ class VssLocalSettingTblController : public VssBaseController { private: - /** 鏈湴鍥芥爣閰嶇疆鏋勯�犲嚱鏁� */ - VssLocalSettingTblController() {} + /** 鏈湴鍥芥爣閰嶇疆鏋勯�犲嚱鏁� */ + VssLocalSettingTblController() {} + public: - /** 鏈湴鍥芥爣閰嶇疆鍗曚緥妯″紡 */ - static VssLocalSettingTblController* instance() { + /** 鏈湴鍥芥爣閰嶇疆鍗曚緥妯″紡 */ + static VssLocalSettingTblController *instance() { static VssLocalSettingTblController instance; return &instance; } -public: - /** 娉ㄥ唽{label}http鏈嶅姟 */ - void registerHttpServices(HttpSrvRetRecieve& _HttpSrvRetRecieve) { - _HttpSrvRetRecieve.setInfo("^/addVssLocalSettingTbl$", "POST", - std::bind(&VssLocalSettingTblController::addVssLocalSettingTbl, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4)); - - _HttpSrvRetRecieve.setInfo("^/delVssLocalSettingTbl$", "POST", - std::bind(&VssLocalSettingTblController::delVssLocalSettingTbl, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4)); - - _HttpSrvRetRecieve.setInfo("^/updateVssLocalSettingTbl$", "POST", - std::bind(&VssLocalSettingTblController::updateVssLocalSettingTbl, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4)); - - _HttpSrvRetRecieve.setInfo("^/findVssLocalSettingTbl$", "POST", - std::bind(&VssLocalSettingTblController::findVssLocalSettingTbl, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4)); - - _HttpSrvRetRecieve.setInfo("^/findVssLocalSettingTblList$", "POST", - std::bind(&VssLocalSettingTblController::findVssLocalSettingTblList, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4)); +public: + /** 娉ㄥ唽{label}http鏈嶅姟 */ + void registerHttpServices(HttpSrvRetRecieve &_HttpSrvRetRecieve) { + + _HttpSrvRetRecieve.setInfo("^/addVssLocalSettingTbl$", "POST", + std::bind(&VssLocalSettingTblController::addVssLocalSettingTbl, this, + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4)); + + _HttpSrvRetRecieve.setInfo("^/delVssLocalSettingTbl$", "POST", + std::bind(&VssLocalSettingTblController::delVssLocalSettingTbl, this, + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4)); + + _HttpSrvRetRecieve.setInfo("^/updateVssLocalSettingTbl$", "POST", + std::bind(&VssLocalSettingTblController::updateVssLocalSettingTbl, this, + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4)); + + _HttpSrvRetRecieve.setInfo("^/findVssLocalSettingTbl$", "POST", + std::bind(&VssLocalSettingTblController::findVssLocalSettingTbl, this, + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4)); + + _HttpSrvRetRecieve.setInfo("^/findVssLocalSettingTblList$", "POST", + std::bind(&VssLocalSettingTblController::findVssLocalSettingTblList, this, + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4)); } + public: - /** 娣诲姞鏈湴鍥芥爣閰嶇疆 */ + /** 娣诲姞鏈湴鍥芥爣閰嶇疆 */ std::string addVssLocalSettingTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { + DBG("ip:" << ip << "; port:" << port); + DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; @@ -65,43 +70,43 @@ responseJsonValue["success"] = "false"; if (requestJsonReader.parse(content, requestJsonValue)) { VssLocalSettingTblBuilder vssLocalSettingTblBuilder; - - Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; + + Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addID(std::stoi(iDJsonValue.asString())); } - Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; + Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; if (serverIpJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerIp(serverIpJsonValue.asString()); } - Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; + Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; if (serverPortJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerPort(serverPortJsonValue.asString()); } - Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; + Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; if (serverIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerId(serverIdJsonValue.asString()); } - Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; + Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; if (userAuthIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUserAuthId(userAuthIdJsonValue.asString()); } - Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; + Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; if (passwordJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addPassword(passwordJsonValue.asString()); } - Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; + Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUpdateTime(updateTimeJsonValue.asString()); } - auto keyValuesToAdd = vssLocalSettingTblBuilder.buildVssLocalSettingTblMap(); - if (keyValuesToAdd.size() > 0) { + auto keyValuesToAdd = vssLocalSettingTblBuilder.buildVssLocalSettingTblMap(); + if (keyValuesToAdd.size() > 0) { responseJsonValue = VssLocalSettingTblSqliteDao::instance()->addVssLocalSettingTbl(keyValuesToAdd); } } @@ -110,16 +115,18 @@ /** 鍒犻櫎鏈湴鍥芥爣閰嶇疆 */ std::string delVssLocalSettingTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { + DBG("ip:" << ip << "; port:" << port); + DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; responseJsonValue["message"] = "鍒犻櫎澶辫触锛�"; responseJsonValue["success"] = "false"; if (requestJsonReader.parse(content, requestJsonValue)) { - Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; - if (iDJsonValue.type() != Json::ValueType::nullValue) { - string iDValue = iDJsonValue.asString(); - responseJsonValue = VssLocalSettingTblSqliteDao::instance()->deleteByColumn("ID", iDValue); + Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; + if (iDJsonValue.type() != Json::ValueType::nullValue) { + string iDValue = iDJsonValue.asString(); + responseJsonValue = VssLocalSettingTblSqliteDao::instance()->deleteByColumn("ID", iDValue); } } @@ -128,6 +135,8 @@ /** 鏇存柊鏈湴鍥芥爣閰嶇疆 */ std::string updateVssLocalSettingTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { + DBG("ip:" << ip << "; port:" << port); + DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; @@ -136,43 +145,44 @@ if (requestJsonReader.parse(content, requestJsonValue)) { VssLocalSettingTblBuilder vssLocalSettingTblBuilder; - Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; + Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addID(std::stoi(iDJsonValue.asString())); } - Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; + Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; if (serverIpJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerIp(serverIpJsonValue.asString()); } - Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; + Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; if (serverPortJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerPort(serverPortJsonValue.asString()); } - Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; + Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; if (serverIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerId(serverIdJsonValue.asString()); } - Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; + Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; if (userAuthIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUserAuthId(userAuthIdJsonValue.asString()); } - Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; + Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; if (passwordJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addPassword(passwordJsonValue.asString()); } - Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; + Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUpdateTime(updateTimeJsonValue.asString()); } - if (iDJsonValue.type() != Json::ValueType::nullValue) { - string iDValue = iDJsonValue.asString(); - responseJsonValue = VssLocalSettingTblSqliteDao::instance()->updateVssLocalSettingTbl(vssLocalSettingTblBuilder.buildVssLocalSettingTblMap(), "ID", iDValue); + if (iDJsonValue.type() != Json::ValueType::nullValue) { + string iDValue = iDJsonValue.asString(); + responseJsonValue = VssLocalSettingTblSqliteDao::instance()->updateVssLocalSettingTbl( + vssLocalSettingTblBuilder.buildVssLocalSettingTblMap(), "ID", iDValue); } } return responseJsonValue.toStyledString(); @@ -180,6 +190,8 @@ /** 鏌ユ壘鍗曚釜鏈湴鍥芥爣閰嶇疆 */ std::string findVssLocalSettingTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { + DBG("ip:" << ip << "; port:" << port); + DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; @@ -188,49 +200,53 @@ if (requestJsonReader.parse(content, requestJsonValue)) { VssLocalSettingTblBuilder vssLocalSettingTblBuilder; - Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; + Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addID(std::stoi(iDJsonValue.asString())); } - Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; + Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; if (serverIpJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerIp(serverIpJsonValue.asString()); } - Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; + Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; if (serverPortJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerPort(serverPortJsonValue.asString()); } - Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; + Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; if (serverIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerId(serverIdJsonValue.asString()); } - Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; + Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; if (userAuthIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUserAuthId(userAuthIdJsonValue.asString()); } - Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; + Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; if (passwordJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addPassword(passwordJsonValue.asString()); } - Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; + Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUpdateTime(updateTimeJsonValue.asString()); } - responseJsonValue["message"] = "鏌ヨ鎴愬姛锛�"; - responseJsonValue["success"] = "true"; - responseJsonValue = VssLocalSettingTblSqliteDao::instance()->findVssLocalSettingTblList(vssLocalSettingTblBuilder.buildVssLocalSettingTblMap()); + responseJsonValue["message"] = "鏌ヨ鎴愬姛锛�"; + responseJsonValue["success"] = "true"; + responseJsonValue = VssLocalSettingTblSqliteDao::instance()->findVssLocalSettingTblList( + vssLocalSettingTblBuilder.buildVssLocalSettingTblMap()); } return responseJsonValue.toStyledString(); } /** 鏌ユ壘鏈湴鍥芥爣閰嶇疆鍒楄〃 */ - std::string findVssLocalSettingTblList(std::string ip, unsigned int port, std::string content, PResponse &response) { + std::string + findVssLocalSettingTblList(std::string ip, unsigned int port, std::string content, PResponse &response) { + DBG("ip:" << ip << "; port:" << port); + DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; @@ -239,52 +255,49 @@ if (content == "" || requestJsonReader.parse(content, requestJsonValue)) { VssLocalSettingTblBuilder vssLocalSettingTblBuilder; - Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; + Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addID(std::stoi(iDJsonValue.asString())); } - - Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; + + Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; if (serverIpJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerIp(serverIpJsonValue.asString()); } - - Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; + + Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; if (serverPortJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerPort(serverPortJsonValue.asString()); } - - Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; + + Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; if (serverIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerId(serverIdJsonValue.asString()); } - - Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; + + Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; if (userAuthIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUserAuthId(userAuthIdJsonValue.asString()); } - - Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; + + Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; if (passwordJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addPassword(passwordJsonValue.asString()); } - - Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; + + Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUpdateTime(updateTimeJsonValue.asString()); } - responseJsonValue["message"] = "鏌ヨ鎴愬姛锛�"; - responseJsonValue["success"] = "true"; - responseJsonValue = VssLocalSettingTblSqliteDao::instance()->findVssLocalSettingTblList(vssLocalSettingTblBuilder.buildVssLocalSettingTblMap()); + responseJsonValue["message"] = "鏌ヨ鎴愬姛锛�"; + responseJsonValue["success"] = "true"; + responseJsonValue = VssLocalSettingTblSqliteDao::instance()->findVssLocalSettingTblList( + vssLocalSettingTblBuilder.buildVssLocalSettingTblMap()); } return responseJsonValue.toStyledString(); } }; - - - - #endif //VSSLOCALSETTINGTBL_CONTROLLER_H diff --git a/QiaoJiaSystem/DataManagerServer/vss/dao/BaseDao.h b/QiaoJiaSystem/DataManagerServer/vss/dao/BaseDao.h index 636a246..3bb9da3 100644 --- a/QiaoJiaSystem/DataManagerServer/vss/dao/BaseDao.h +++ b/QiaoJiaSystem/DataManagerServer/vss/dao/BaseDao.h @@ -11,10 +11,11 @@ using namespace std; -static mysqlpp::Connection* conn; +static mysqlpp::Connection *conn; + class BaseDao { public: - static mysqlpp::SimpleResult add(std::map<std::string, std::string>& columns, string tableName) { + static mysqlpp::SimpleResult add(std::map<std::string, std::string> &columns, string tableName) { initConnection(); mysqlpp::SimpleResult simpleResult; try { @@ -28,17 +29,20 @@ } return simpleResult; } - static bool del(string tableName, std::map<std::string, std::string>& whereColumns) { + + static bool del(string tableName, std::map<std::string, std::string> &whereColumns) { initConnection(); string sql = "DELETE FROM " + tableName + " where 1=1 " + getWhereColumnNameValuePair(whereColumns); mysqlpp::Query query = conn->query(sql); bool ret = query.exec(); if (!ret) { - cout << "error " <<query.error() << endl; + cout << "error " << query.error() << endl; } return ret; } - static bool update(std::map<std::string, std::string>& columns, string tableName, std::map<std::string, std::string>& whereColumns) { + + static bool update(std::map<std::string, std::string> &columns, string tableName, + std::map<std::string, std::string> &whereColumns) { string updateSql = getUpdateSql(columns, tableName, whereColumns); initConnection(); mysqlpp::Query query = conn->query(updateSql); @@ -58,7 +62,7 @@ map<string, string> rowData; mysqlpp::Row row = *it; auto field_list = row.field_list(); - const mysqlpp::FieldNames* fieldNames = field_list.list; + const mysqlpp::FieldNames *fieldNames = field_list.list; for (int i = 0; i < fieldNames->size(); i++) { string columnValue; row[i].to_string(columnValue); @@ -80,7 +84,7 @@ if (auto res = query.store()) { for (auto it = res.begin(); it != res.end(); ++it) { Json::Value row; - const mysqlpp::FieldNames* fieldNames = it->field_list().list; + const mysqlpp::FieldNames *fieldNames = it->field_list().list; for (int i = 0; i < fieldNames->size(); i++) { string columnValue; (*it)[i].to_string(columnValue); @@ -103,12 +107,13 @@ mysqlpp::Query query = conn->query(sql); bool ret = query.exec(); if (!ret) { - cout << "error " <<query.error() << endl; + cout << "error " << query.error() << endl; } return ret; } - static string getInsertSql(std::map<std::string, std::string>& columns, string tableName) { - string insertSql = "INSERT INTO "+tableName+" (" + + static string getInsertSql(std::map<std::string, std::string> &columns, string tableName) { + string insertSql = "INSERT INTO " + tableName + " (" + getColumnNames(columns) + " ) values ( " + getColumnValues(columns) + @@ -116,35 +121,38 @@ cout << "insertSql " << insertSql << endl; return insertSql; } - static string getUpdateSql(std::map<std::string, std::string>& columns, string tableName, std::map<std::string, std::string>& whereColumns) { - string updateSql = "update "+tableName+" set " + + static string getUpdateSql(std::map<std::string, std::string> &columns, string tableName, + std::map<std::string, std::string> &whereColumns) { + string updateSql = "update " + tableName + " set " + getColumnNameValuePair(columns) + - " where 1=1 "+ - getWhereColumnNameValuePair(whereColumns) - ; + " where 1=1 " + + getWhereColumnNameValuePair(whereColumns); cout << "updateSql " << updateSql << endl; return updateSql; } + static void doConnect() { - // if (conn->connect( -// appConfig.getStringProperty("database").c_str(), -// appConfig.getStringProperty("db_host").c_str(), -// appConfig.getStringProperty("db_user").c_str(), -// appConfig.getStringProperty("db_password").c_str(), -// appConfig.getIntProperty("db_port") -// )) { if (conn->connect( - "EGEyesForVSS", - "127.0.0.1", - "root", - "123456", - 3306 + appConfig.getStringProperty("database").c_str(), + appConfig.getStringProperty("db_host").c_str(), + appConfig.getStringProperty("db_user").c_str(), + appConfig.getStringProperty("db_password").c_str(), + appConfig.getIntProperty("db_port") )) { +// if (conn->connect( +// "EGEyesForVSS", +// "192.168.1.148", +// "root", +// "123456", +// 3306 +// )) { cout << "connect success" << endl; } else { cout << "connect failed" << endl; } } + static void initConnection() { static bool inited = false; if (!inited) { @@ -156,7 +164,8 @@ doConnect(); } } - static string getColumnNames(std::map<std::string, std::string>& columns) { + + static string getColumnNames(std::map<std::string, std::string> &columns) { string columnNames; auto size = columns.size(); int i = 0; @@ -169,12 +178,13 @@ } return columnNames; } - static string getColumnValues(std::map<std::string, std::string>& columns) { + + static string getColumnValues(std::map<std::string, std::string> &columns) { string columnValues; auto size = columns.size(); int i = 0; for (auto column : columns) { - columnValues.append("'"+column.second+"'"); + columnValues.append("'" + column.second + "'"); if (i != columns.size() - 1) { columnValues.append(","); } @@ -182,14 +192,15 @@ } return columnValues; } - static string getColumnNameValuePair(std::map<std::string, std::string>& columns) { + + static string getColumnNameValuePair(std::map<std::string, std::string> &columns) { string columnNameValuePair; auto size = columns.size(); int i = 0; for (auto column : columns) { columnNameValuePair.append(column.first); columnNameValuePair.append("="); - columnNameValuePair.append("'"+column.second+"'"); + columnNameValuePair.append("'" + column.second + "'"); if (i != size - 1) { columnNameValuePair.append(","); @@ -198,7 +209,8 @@ } return columnNameValuePair; } - static string getWhereColumnNameValuePair(std::map<std::string, std::string>& columns) { + + static string getWhereColumnNameValuePair(std::map<std::string, std::string> &columns) { string columnNameValuePair; auto size = columns.size(); int i = 0; @@ -206,7 +218,7 @@ columnNameValuePair.append(" and "); columnNameValuePair.append(column.first); columnNameValuePair.append("="); - columnNameValuePair.append("'"+column.second+"' "); + columnNameValuePair.append("'" + column.second + "' "); i++; } diff --git a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp index 5106cbf..c353675 100644 --- a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp +++ b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp @@ -44,7 +44,6 @@ } BASICGB28181::FFmpegDecoderJPG::~FFmpegDecoderJPG() { - while (m_rtpQueue.count_queue()) { m_rtpQueue.popNotWait(); } @@ -65,10 +64,20 @@ info->buffLen = datalen; info->camIdx = camIdx; memcpy(info->buff, data, datalen); + { +// FILE *fp11 = NULL; +// if (!fp11) { +// fp11 = fopen(camIdx.c_str(), "a+"); +// } +// fwrite(data, sizeof(char), datalen, fp11); +// fclose(fp11); + } + #ifdef TestCode DBG(" m_rtpQueue.push before "); #endif - m_rtpQueue.push(info); + m_rtpQueue. + push(info); #ifdef TestCode DBG(" m_rtpQueue.push after "); #endif @@ -193,7 +202,7 @@ p_this->frame_number++; int err6 = avcodec_send_packet(ctx, &pkt); - av_packet_unref(&pkt); +// av_packet_unref(&pkt); int err7 = avcodec_receive_frame(ctx, frame); if ((err7 == AVERROR(EAGAIN)) || (err5 < 0) || (err6 < 0)) { ERR(" error << err7:" << err7 << " err5: " << err5 << " err6: " << err6); @@ -446,6 +455,7 @@ m_frameIndex++; m_packetsVec.push_back({m_frameIndex, newPacket}); if (newPacket.flags & AV_PKT_FLAG_KEY) { + DBG("newPacket.flags & AV_PKT_FLAG_KEY "); m_last_I_FrameId = m_frameIndex; } } @@ -466,27 +476,27 @@ */ m_pOutVideo_stream = avformat_new_stream(m_pOutFmtCtx, NULL); { -// AVCodecContext *c; -// c = m_pOutVideo_stream->codec; -// c->bit_rate = 400000; -// c->codec_id = video_st->codec->codec_id; -// c->codec_type = video_st->codec->codec_type; -// c->time_base.num = video_st->time_base.num; -// c->time_base.den = video_st->time_base.den; -// fprintf(stderr, "time_base.num = %d time_base.den = %d\n", c->time_base.num, c->time_base.den); -// c->width = video_st->codec->width; -// c->height = video_st->codec->height; -// c->pix_fmt = video_st->codec->pix_fmt; -// printf("%d %d %d", c->width, c->height, c->pix_fmt); -// c->flags = video_st->codec->flags; -// c->flags |= CODEC_FLAG_GLOBAL_HEADER; -// c->me_range = video_st->codec->me_range; -// c->max_qdiff = video_st->codec->max_qdiff; -// -// c->qmin = video_st->codec->qmin; -// c->qmax = video_st->codec->qmax; -// -// c->qcompress = video_st->codec->qcompress; + AVCodecContext *c; + c = m_pOutVideo_stream->codec; + c->bit_rate = 400000; + c->codec_id = video_st->codec->codec_id; + c->codec_type = video_st->codec->codec_type; + c->time_base.num = video_st->time_base.num; + c->time_base.den = video_st->time_base.den; + fprintf(stderr, "time_base.num = %d time_base.den = %d\n", c->time_base.num, c->time_base.den); + c->width = video_st->codec->width; + c->height = video_st->codec->height; + c->pix_fmt = video_st->codec->pix_fmt; + printf("%d %d %d", c->width, c->height, c->pix_fmt); + c->flags = video_st->codec->flags; + c->flags |= CODEC_FLAG_GLOBAL_HEADER; + c->me_range = video_st->codec->me_range; + c->max_qdiff = video_st->codec->max_qdiff; + + c->qmin = video_st->codec->qmin; + c->qmax = video_st->codec->qmax; + + c->qcompress = video_st->codec->qcompress; } ret = avio_open(&m_pOutFmtCtx->pb, filename, AVIO_FLAG_WRITE); if (ret < 0) { @@ -494,7 +504,7 @@ return -1; } - avformat_write_header(m_pOutFmtCtx, NULL); + DBG(" avformat_write_header " << avformat_write_header(m_pOutFmtCtx, NULL)); m_bstartWrite = true; m_bFirstKeyFrame = true; diff --git a/QiaoJiaSystem/VideoAnalysFromHC/main.cpp b/QiaoJiaSystem/VideoAnalysFromHC/main.cpp index 87b89d5..9755c39 100644 --- a/QiaoJiaSystem/VideoAnalysFromHC/main.cpp +++ b/QiaoJiaSystem/VideoAnalysFromHC/main.cpp @@ -84,7 +84,7 @@ int arg1 = atoi(argv[1]); int gindx = abs(arg1) % 2; - int GB28181_Enable = arg1 < 0 ? gindx : -1; + int GB28181_Enable = arg1 < 0 ? 1 : -1; DBG(gindx); appPref.setIntData("GB28181_Enable", GB28181_Enable); diff --git a/QiaoJiaSystem/VideoToImageMulth/CMakeLists.txt b/QiaoJiaSystem/VideoToImageMulth/CMakeLists.txt index 8b92de1..d484908 100644 --- a/QiaoJiaSystem/VideoToImageMulth/CMakeLists.txt +++ b/QiaoJiaSystem/VideoToImageMulth/CMakeLists.txt @@ -96,12 +96,14 @@ ) add_executable(${PROJECT_NAME} + + ./pushStream/PushStreamAppPipeController.cpp ../GB28181DecoderModel/FFmpegDecoderJPG.cpp ../GB28181DecoderModel/GB28181Server.cpp ../GB28181DecoderModel/VideoCaptureElementWithRtp.cpp - ../../../BasicPlatForm/basic/pipe_element/ffmpeg/VideoChangeScore.cpp + # ../../../BasicPlatForm/basic/pipe_element/ffmpeg/VideoChangeScore.cpp ../../../BasicPlatForm/basic/util/BASE64/Base64.cpp - # ../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp +# ../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp ../VideoServer/QiaoJia/DB/LDBTool.cpp ./rpc/RtspAnalysServer.cpp RtspCaptureElement.cpp diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp index 8eafe6d..a49c256 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp +++ b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp @@ -165,9 +165,12 @@ m_imgRedisCRwLock.unlock(); //VideoCaptureElementWithRtp(std::string &chanPubID, int fps, int streamTransType, int gpuIdx = -1) - m_controllers_videoCapElem[index] = new BASICGB28181::VideoCaptureElementWithRtp( - const_cast<string &>(index), - 25, 0, 0, this); +// m_controllers_videoCapElem[index] = new BASICGB28181::VideoCaptureElementWithRtp( +// const_cast<string &>(index), +// 25, 0, 0, this); + + m_controllers_videoCapElem[index] = new PushStreamAppPipeController(const_cast<string &>(index), + 25, 0, 0, this); m_controllers_videoCapElem[index]->SetVideoMinMaxSeconds(lst_dev.n_cut_min_duration, lst_dev.n_cut_max_duration); m_controllers_videoCapElem[index]->start(); @@ -310,7 +313,7 @@ auto pCaptureElem = m_controllers_videoCapElem.find(nameSt.m_camId); if (pCaptureElem != m_controllers_videoCapElem.end()) { //#todo ~~~~~~!!!!!!! 杩欓噷鏈塨ug 闇�瑕佹斁寮�璋冭瘯 -// pCaptureElem->second->SaveVideo(name); + pCaptureElem->second->SaveVideo(name); } else { ERR("Can not Find CamId " << nameSt.m_camId); } diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h index d608547..fbd73ba 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h +++ b/QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h @@ -9,7 +9,8 @@ #include <map> #include "RtspCaptureElement.h" #include "RtspImageRedis.h" -#include "../GB28181DecoderModel/VideoCaptureElementWithRtp.h" +//#include "../GB28181DecoderModel/VideoCaptureElementWithRtp.h" +#include "pushStream/PushStreamAppPipeController.h" //#include <VideoCaptureElementWithRtp.h> #include <QiaoJia/DB/LDBTool.h> #include <basic/util/app/AppPreference.hpp> @@ -63,7 +64,8 @@ std::map<std::string, RtspCaptureElement *> m_controllers; //淇濆瓨CamID鍜孷ideoCaptureElementWithRtp鐨勬槧灏勫叧绯� - std::map<std::string, BASICGB28181::VideoCaptureElementWithRtp *> m_controllers_videoCapElem; +// std::map<std::string, BASICGB28181::VideoCaptureElementWithRtp *> m_controllers_videoCapElem; + std::map<std::string, PushStreamAppPipeController *> m_controllers_videoCapElem; //淇濆瓨CamID鍜孯tspImageRedisElement鐨勬槧灏勫叧绯� std::map<std::string, RtspImageRedisElement *> m_imgRedisControllers; diff --git a/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp b/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp index 70c9143..b8d983d 100644 --- a/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp +++ b/QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp @@ -2,12 +2,13 @@ #include <basic/debug/Debug.h> #include <opencv2/opencv.hpp> #include <basic/timer_counter/Clocktimer.h> -#include <basic/pipe_element/ffmpeg/cap_ffmpeg_impl.hpp> #include <thread> #include <basic/util/app/AppPreference.hpp> #include <QString> #include <QDateTime> #include "RtspAnalysManager.h" +//#include <basic/pipe_element/ffmpeg/cap_ffmpeg_impl.hpp> +#include "../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp" RtspCaptureElement::RtspCaptureElement(const std::string &path, const std::string &camId, int fps, int reopenTime, int gpuIndex, RtspAnalysManager *manager) : diff --git a/QiaoJiaSystem/VideoToImageMulth/main.cpp b/QiaoJiaSystem/VideoToImageMulth/main.cpp index 6403ebd..4f96c52 100644 --- a/QiaoJiaSystem/VideoToImageMulth/main.cpp +++ b/QiaoJiaSystem/VideoToImageMulth/main.cpp @@ -62,11 +62,17 @@ 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 ? gindx : -1; + int GB28181_Enable = arg1 < 0 ? 1 : 0; DBG(gindx); appPref.setIntData("GB28181_Enable", GB28181_Enable); diff --git a/QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.cpp b/QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.cpp new file mode 100644 index 0000000..553a451 --- /dev/null +++ b/QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.cpp @@ -0,0 +1,50 @@ +#include "PushStreamAppPipeController.h" +#include <basic/util/app/AppPreference.hpp> +#include <basic/util/app/AppUtil.h> +//#include <sstream> +#include <algorithm> +#include <basic/util/app/AppConfig.h> + +PushStreamAppPipeController::PushStreamAppPipeController(std::string &chanPubID, int fps, + int streamTransType, + int gpuIdx, RtspAnalysManager *manager) : + videoCaptureElement(chanPubID, fps, streamTransType, gpuIdx, manager), + index(chanPubID), + videoPublishElement(nullptr) { + + string path = appConfig.getStringProperty("srsAddr") + "cam" + chanPubID + ".flv"; + cv::Size size_(appPref.getIntData("pulish.width"), appPref.getIntData("pulish.height")); + int gupIdx = appPref.getLongData("gpu.index"); + videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx); + if (appPref.getIntData("pulish.width") < 0 || appPref.getIntData("pulish.height") < 0) { + ERR("pulish.width: " << appPref.getIntData("pulish.width") << " Height: " + << appPref.getIntData("pulish.height")); + } + videoCaptureElement.registerConnector([&] { + //if(!videoPublishElement.isBusy()){ + videoPublishElement->setImage(videoCaptureElement.getImage()); + //videoPublishElement.submit(); + //} + }); + + registerElement(videoCaptureElement); + registerElement(*videoPublishElement); + +// videoCaptureElement.setOutPutInterval(3); +} + +std::string PushStreamAppPipeController::getRtmp() { + std::string ret = videoPublishElement->getPath(); + size_t pos = ret.find(".flv"); + ret = ret.substr(0, pos); + INFO(ret); + return ret; +} + +void PushStreamAppPipeController::SaveVideo(const std::string &strImageName) { + videoCaptureElement.SaveVideo(strImageName); +} + +void PushStreamAppPipeController::SetVideoMinMaxSeconds(const int minSeconds, const int maxSeconds) { + videoCaptureElement.SetVideoMinMaxSeconds(minSeconds, maxSeconds); +} diff --git a/QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.h b/QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.h new file mode 100644 index 0000000..ea0085f --- /dev/null +++ b/QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.h @@ -0,0 +1,29 @@ +#ifndef PUSHSTREAMAPPPIPECONTROLLER_H +#define PUSHSTREAMAPPPIPECONTROLLER_H + +#include <basic/pipe/PipeController.h> +#include <basic/pipe_element/ffmpeg/FfmpegElement.h> +#include <jsoncpp/json/json.h> +#include "../GB28181DecoderModel/VideoCaptureElementWithRtp.h" + +class PushStreamAppPipeController : public PipeController { +public: + PushStreamAppPipeController(std::string &chanPubID, int fps, + int streamTransType, + int gpuIdx, RtspAnalysManager *manager); + + std::string getRtmp(); + + + void SaveVideo(const std::string &strImageName); + + //璁剧疆淇濆瓨瑙嗛鐨勬渶灏忓拰鏈�澶ч暱搴�,鍗曚綅鏄,瀹為檯鐨勮繍琛屾儏鍐垫湁涓�浜涘樊璺濓紝闇�瑕佸畬鍠� + void SetVideoMinMaxSeconds(const int minSeconds, const int maxSeconds); + +private: + BASICGB28181::VideoCaptureElementWithRtp videoCaptureElement; + ffmpeg::VideoPublishElement* videoPublishElement; + std::string index; +}; + +#endif // PUSHSTREAMAPPPIPECONTROLLER_H -- Gitblit v1.8.0