Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
57b5178413 | |
|
|
f18e10f8f3 | |
|
|
d72bd78b59 |
236
CMakeLists.txt
236
CMakeLists.txt
File diff suppressed because one or more lines are too long
|
|
@ -114,7 +114,7 @@ model:
|
||||||
|
|
||||||
gc_http_open: 1
|
gc_http_open: 1
|
||||||
username: "guest_01"
|
username: "guest_01"
|
||||||
password: "d55b0f642e817eea24725d2f2a31dd08" # 神东
|
password: "0a1688bce402a5f6a4279abbfc89c203" # 神东 d55b0f642e817eea24725d2f2a31dd08
|
||||||
gc_http_url: "http://192.168.2.211:20004/api/train-carriage/identification/video-save"
|
gc_http_url: "http://192.168.2.211:20004/api/train-carriage/identification/video-save"
|
||||||
gc_gettoken_url: "http://192.168.2.211:20004/api/blade-auth/oauth/token"
|
gc_gettoken_url: "http://192.168.2.211:20004/api/blade-auth/oauth/token"
|
||||||
gc_image_srv: "http://192.168.2.211:9010/"
|
gc_image_srv: "http://192.168.2.211:9010/"
|
||||||
|
|
@ -182,5 +182,5 @@ gc_c_space_frame_width: 500
|
||||||
# 是否识别车头
|
# 是否识别车头
|
||||||
gc_train_heard_detect: true
|
gc_train_heard_detect: true
|
||||||
|
|
||||||
#过期文件夹天数
|
# 识别结果保存天数
|
||||||
gc_days_for_result_expire_folder: 3
|
gc_days_for_result_expire_folder: 3
|
||||||
|
|
|
||||||
|
|
@ -459,7 +459,7 @@ typedef struct
|
||||||
std::shared_ptr<void> pSrcData; // Smart pointer of data(源数据) 推理时,RGB数据会拷贝一份,源数据不变用于传送到后处理引擎画框,另一份数据用于resize成640x640并归一化到0-1
|
std::shared_ptr<void> pSrcData; // Smart pointer of data(源数据) 推理时,RGB数据会拷贝一份,源数据不变用于传送到后处理引擎画框,另一份数据用于resize成640x640并归一化到0-1
|
||||||
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
||||||
Step1Location step1Location; //step2 use
|
Step1Location step1Location; //step2 use
|
||||||
int iTargetType; //目标类别 (0:车号; 1:属性; 2:车头; 3:定检期; 4:集装箱)
|
int iTargetType; //目标类别 (0:车号; 1:属性; 2:车头; 3:定检期; 4:集装箱)
|
||||||
int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号)
|
int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号)
|
||||||
int iCarXH = 0; //当前大框所属车厢
|
int iCarXH = 0; //当前大框所属车厢
|
||||||
|
|
||||||
|
|
@ -491,7 +491,7 @@ typedef struct
|
||||||
std::shared_ptr<void> pData = nullptr; // Smart pointer of data
|
std::shared_ptr<void> pData = nullptr; // Smart pointer of data
|
||||||
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
||||||
bool bHostMemory = false; //数据解码后内存是否在Host侧
|
bool bHostMemory = false; //数据解码后内存是否在Host侧
|
||||||
std::string strPicFilePath;
|
std::string strPicFilePath;
|
||||||
std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD)
|
std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD)
|
||||||
std::string strTrainName; //车次 (格式:HH-MM-SS)
|
std::string strTrainName; //车次 (格式:HH-MM-SS)
|
||||||
bool bIsEnd = false; //列车结束标识
|
bool bIsEnd = false; //列车结束标识
|
||||||
|
|
@ -516,6 +516,7 @@ typedef struct
|
||||||
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
uint64_t i64TimeStamp = 0; //帧数据时间戳
|
||||||
std::shared_ptr<DecodedData> pDecodeData = nullptr;
|
std::shared_ptr<DecodedData> pDecodeData = nullptr;
|
||||||
int iDirection = 0; //行驶方向(0-未知; 1-向左; 2-向右)
|
int iDirection = 0; //行驶方向(0-未知; 1-向左; 2-向右)
|
||||||
|
int nMonitorState = MONITOR_MODEL_INIT_STATE;
|
||||||
} SaveImgData;
|
} SaveImgData;
|
||||||
|
|
||||||
//识别处理数据
|
//识别处理数据
|
||||||
|
|
@ -755,7 +756,7 @@ typedef struct
|
||||||
std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD)
|
std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD)
|
||||||
std::string strTrainName; //车次 (格式:HH-MM-SS)
|
std::string strTrainName; //车次 (格式:HH-MM-SS)
|
||||||
std::string strContainerNo; //集装箱号
|
std::string strContainerNo; //集装箱号
|
||||||
std::string strBestImg; //集装箱最优图
|
std::string strBestImg; //集装箱最优图
|
||||||
float fScoreSum = 0; //集装箱最优图总得分, 取最优帧用
|
float fScoreSum = 0; //集装箱最优图总得分, 取最优帧用
|
||||||
uint64_t i64TimeStamp = 0; //集装箱最优图时间戳
|
uint64_t i64TimeStamp = 0; //集装箱最优图时间戳
|
||||||
Step1Location step1Location; //原图上大框坐标
|
Step1Location step1Location; //原图上大框坐标
|
||||||
|
|
@ -831,30 +832,30 @@ typedef struct imganalyse
|
||||||
{
|
{
|
||||||
// from file
|
// from file
|
||||||
/////////下述设定取自csv文件
|
/////////下述设定取自csv文件
|
||||||
int nType; //算法目的 0:动态检测 1:车厢划分
|
int nType; //算法目的 0:动态检测 1:车厢划分
|
||||||
int nAreaX1; //算法监测区域 开始位置x坐标
|
int nAreaX1; //算法监测区域 开始位置x坐标
|
||||||
int nAreaY1; //算法监测区域 开始位置y坐标
|
int nAreaY1; //算法监测区域 开始位置y坐标
|
||||||
int nAreaX2; //算法监测区域 结束位置x坐标
|
int nAreaX2; //算法监测区域 结束位置x坐标
|
||||||
int nAreaY2; //算法监测区域 结束位置y坐标
|
int nAreaY2; //算法监测区域 结束位置y坐标
|
||||||
int bOrLevel; //算法结果融合等级 相同值进行与运算 不同值进行或运算
|
int bOrLevel; //算法结果融合等级 相同值进行与运算 不同值进行或运算
|
||||||
bool bDiff; //是否以不同作为判断条件 false:以匹配度相同作为判定条件 true:以匹配度不同作为判定条件
|
bool bDiff; //是否以不同作为判断条件 false:以匹配度相同作为判定条件 true:以匹配度不同作为判定条件
|
||||||
bool bOn; //是否启用改区域匹配监测(该算法是否有效) false:不启用(无效) true:启用(有效)
|
bool bOn; //是否启用改区域匹配监测(该算法是否有效) false:不启用(无效) true:启用(有效)
|
||||||
double dSameThresholdVal; //判定匹配相同的阈值
|
double dSameThresholdVal; //判定匹配相同的阈值
|
||||||
double dDiffThresholdVal; //判定匹配不同的阈值
|
double dDiffThresholdVal; //判定匹配不同的阈值
|
||||||
int nPauseMaxCoumt; //判定为停车的最大计量(超过设定值判定为停车)
|
int nPauseMaxCoumt; //判定为停车的最大计量(超过设定值判定为停车)
|
||||||
int npicimprovetype; //图像改善处理(包含 灰度化/均衡化直方图/gamma变换/自定义)
|
int npicimprovetype; //图像改善处理(包含 灰度化/均衡化直方图/gamma变换/自定义)
|
||||||
int templemethod; //模型比对模式
|
int templemethod; //模型比对模式
|
||||||
int histmethod; //直方图比对模式
|
int histmethod; //直方图比对模式
|
||||||
int specmethod; //自定义比对模式
|
int specmethod; //自定义比对模式
|
||||||
int compmethod; //对比类型(模型比对/模型比对/自定义比对,可多选)
|
int compmethod; //对比类型(模型比对/模型比对/自定义比对,可多选)
|
||||||
std::string baseImagePath; //基准图片路径
|
std::string baseImagePath; //基准图片路径
|
||||||
/////////下述设定为处理识别变量
|
/////////下述设定为处理识别变量
|
||||||
double dComparePoint; //比对值
|
double dComparePoint; //比对值
|
||||||
double dPreComparePoint; //比对值
|
double dPreComparePoint; //比对值
|
||||||
bool bChanged; //与基准图对比值 是否发生变化 true:发生变化 false:没有发生变化
|
bool bChanged; //与基准图对比值 是否发生变化 true:发生变化 false:没有发生变化
|
||||||
bool bPreChanged; //上一帧与基准图对比值
|
bool bPreChanged; //上一帧与基准图对比值
|
||||||
bool fluctuationFlag; //最近100帧的最大值与最小值的波动标志
|
bool fluctuationFlag; //最近100帧的最大值与最小值的波动标志
|
||||||
int nSameCount; //比对值没有发生变化的计数
|
int nSameCount; //比对值没有发生变化的计数
|
||||||
int iIndex; //第几个配置项
|
int iIndex; //第几个配置项
|
||||||
}AnalyseInfo;
|
}AnalyseInfo;
|
||||||
|
|
||||||
|
|
@ -865,19 +866,19 @@ typedef struct trainpartion
|
||||||
{
|
{
|
||||||
std::string strTrainDate;
|
std::string strTrainDate;
|
||||||
std::string strTrainName;
|
std::string strTrainName;
|
||||||
int nindex; //车厢顺位
|
int nindex; //车厢顺位
|
||||||
uint64_t i64StartTimeStamp; //当节车厢出现的开始帧时间
|
uint64_t i64StartTimeStamp; //当节车厢出现的开始帧时间
|
||||||
uint64_t i64EndTimeStamp; //当节车厢出现的结束帧时间
|
uint64_t i64EndTimeStamp; //当节车厢出现的结束帧时间
|
||||||
float fspeed; //当节车厢的车速
|
float fspeed; //当节车厢的车速
|
||||||
int startframe; //当节车厢出现的开始帧帧号
|
int startframe; //当节车厢出现的开始帧帧号
|
||||||
int endframe; //当节车厢出现的结束帧帧号
|
int endframe; //当节车厢出现的结束帧帧号
|
||||||
int modelSpaceFrame;
|
int modelSpaceFrame;
|
||||||
bool bfuncconfirmed; //是否算法划分完成 true:是 false:否
|
bool bfuncconfirmed; //是否算法划分完成 true:是 false:否
|
||||||
bool bmodelconfirmed; //是否根据第一次识别结果确认完成 true:是 false:否
|
bool bmodelconfirmed; //是否根据第一次识别结果确认完成 true:是 false:否
|
||||||
float fLTX; //车钩开始位置X值
|
float fLTX; //车钩开始位置X值
|
||||||
float fLTY; //车钩开始位置y值
|
float fLTY; //车钩开始位置y值
|
||||||
float fRBX; //车钩结束位置X值
|
float fRBX; //车钩结束位置X值
|
||||||
float fRBY; //车钩结束位置y值
|
float fRBY; //车钩结束位置y值
|
||||||
bool bIsEnd = false; //是否最后一节
|
bool bIsEnd = false; //是否最后一节
|
||||||
int nStatus; //方向(0:未知,1:向左行驶,2:向右行驶)
|
int nStatus; //方向(0:未知,1:向左行驶,2:向右行驶)
|
||||||
int iRate; //帧率
|
int iRate; //帧率
|
||||||
|
|
@ -894,7 +895,8 @@ typedef struct
|
||||||
{
|
{
|
||||||
int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号)
|
int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号)
|
||||||
uint32_t iFrameId = 0; //帧号
|
uint32_t iFrameId = 0; //帧号
|
||||||
float fCenterX; //第一步识别目标中心点X坐标
|
float fCenterX; //第一步识别目标中心点X坐标
|
||||||
|
float fTargetWidth; // 第一步识别目标X坐标宽度
|
||||||
} CalculateInfo;
|
} CalculateInfo;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -50,6 +50,7 @@ private:
|
||||||
std::map<int, std::vector<std::string>> mapSourcePushPort_;
|
std::map<int, std::vector<std::string>> mapSourcePushPort_;
|
||||||
|
|
||||||
MoveData moveData_;
|
MoveData moveData_;
|
||||||
|
std::queue<MoveData> queuwMoveData_;
|
||||||
std::string strDataDir_;
|
std::string strDataDir_;
|
||||||
|
|
||||||
uint32_t iOrigDataNO_; //原过车数据个数
|
uint32_t iOrigDataNO_; //原过车数据个数
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -9,7 +9,7 @@
|
||||||
#include "AppCommon.h"
|
#include "AppCommon.h"
|
||||||
|
|
||||||
|
|
||||||
//编译器这部分代码按C语言(而不是C++)的方式进行编译
|
//编译器这部分代码按C语言(而不是C++)的方式进行编译
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
|
@ -65,6 +65,8 @@ private:
|
||||||
int nDelayTime;
|
int nDelayTime;
|
||||||
bool bIsAvc_ = false;
|
bool bIsAvc_ = false;
|
||||||
int iAudioStream_ = -1;
|
int iAudioStream_ = -1;
|
||||||
|
|
||||||
|
bool bCameraError_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ENGINE_REGIST(CameraEngine)
|
ENGINE_REGIST(CameraEngine)
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -48,6 +48,7 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string strResultPath_;
|
std::string strResultPath_;
|
||||||
|
std::string strLogBakPath_;
|
||||||
|
|
||||||
int iDaysNumber_;
|
int iDaysNumber_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -58,7 +58,7 @@ private:
|
||||||
int iChkStopPX_;
|
int iChkStopPX_;
|
||||||
int iChkStopCount_;
|
int iChkStopCount_;
|
||||||
int iDirection_; //方向
|
int iDirection_; //方向
|
||||||
int iPushDirection_; //需要识别的方向
|
int iPushDirection_; //需要识别的方向
|
||||||
int rightFirst_; // 向右行驶的在前大框类型
|
int rightFirst_; // 向右行驶的在前大框类型
|
||||||
int leftFirst_; // 向左行驶的在前大框类型
|
int leftFirst_; // 向左行驶的在前大框类型
|
||||||
int iPartitionFrameNum_; //满足跨车厢的帧间隔
|
int iPartitionFrameNum_; //满足跨车厢的帧间隔
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,22 @@
|
||||||
|
|
||||||
using namespace ai_matrix;
|
using namespace ai_matrix;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::map<std::string, std::string> mapLoad = {
|
||||||
|
{"C62", "60"},
|
||||||
|
{"C62B", "61"},
|
||||||
|
{"C63", "61"},
|
||||||
|
{"C64", "61"},
|
||||||
|
{"C65", "60"},
|
||||||
|
{"C70", "70"},
|
||||||
|
{"C80", "80"},
|
||||||
|
{"KM70", "70"},
|
||||||
|
{"KM81", "81"},
|
||||||
|
{"KM98", "98"}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
MergerAllEngine::MergerAllEngine() {}
|
MergerAllEngine::MergerAllEngine() {}
|
||||||
|
|
||||||
MergerAllEngine::~MergerAllEngine() {}
|
MergerAllEngine::~MergerAllEngine() {}
|
||||||
|
|
@ -113,6 +129,8 @@ void MergerAllEngine::PushData(std::shared_ptr<Train> pTrain)
|
||||||
<< "集装箱2: " << pTrain->container2.strContainerNo << "\n"
|
<< "集装箱2: " << pTrain->container2.strContainerNo << "\n"
|
||||||
<< "集装箱2图片: " << pTrain->container2.strBestImg << "\n"
|
<< "集装箱2图片: " << pTrain->container2.strBestImg << "\n"
|
||||||
<< "集装箱2时间戳: " << pTrain->container2.i64TimeStamp << "\n"
|
<< "集装箱2时间戳: " << pTrain->container2.i64TimeStamp << "\n"
|
||||||
|
<< "车厢开始时间: " << MyUtils::getins()->Stamp2Time(pTrain->i64StartTimeStamp, true) << "\n"
|
||||||
|
<< "车厢结束时间: " << MyUtils::getins()->Stamp2Time(pTrain->i64EndTimeStamp, true) << "\n"
|
||||||
<< " ---所有信息合并结果 END--- ";
|
<< " ---所有信息合并结果 END--- ";
|
||||||
if (pTrain->bIsEnd)
|
if (pTrain->bIsEnd)
|
||||||
{
|
{
|
||||||
|
|
@ -249,7 +267,7 @@ APP_ERROR MergerAllEngine::Process()
|
||||||
}
|
}
|
||||||
|
|
||||||
int iHaveDataCnt = QueueHaveDataCount();
|
int iHaveDataCnt = QueueHaveDataCount();
|
||||||
//识别目标信息个数和获取信息个数相等,则合并信息推送web
|
//识别目标信息个数和获取信息个数相等,则合并信息推送web
|
||||||
if (iHaveDataCnt == iPopPortCnt_)
|
if (iHaveDataCnt == iPopPortCnt_)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Train> pTrain = nullptr;
|
std::shared_ptr<Train> pTrain = nullptr;
|
||||||
|
|
@ -310,12 +328,28 @@ APP_ERROR MergerAllEngine::Process()
|
||||||
特殊处理:针对车头在后的且当前为最后一节,且未识别到车型,则默认设置为车头。
|
特殊处理:针对车头在后的且当前为最后一节,且未识别到车型,则默认设置为车头。
|
||||||
防止车尾间隔误识别,多切分车型,且web端无法过滤的问题。
|
防止车尾间隔误识别,多切分车型,且web端无法过滤的问题。
|
||||||
*/
|
*/
|
||||||
if (!bHeadFrontFlag_ && pTrain->bIsEnd && pTrain->trainNum.iTrainTypeId == -1)
|
if (!bHeadFrontFlag_
|
||||||
|
&& pTrain->bIsEnd
|
||||||
|
&& pTrain->trainNum.iTrainTypeId == -1)
|
||||||
{
|
{
|
||||||
LogDebug << "cometime:" << pTrain->strTrainDate << " " << pTrain->strTrainName << " iCarXH:" << pTrain->iCarXH
|
LogDebug << "cometime:" << pTrain->strTrainDate << " " << pTrain->strTrainName << " iCarXH:" << pTrain->iCarXH
|
||||||
<< " num:" << pTrain->trainNum.strTrainNum;
|
<< " num:" << pTrain->trainNum.strTrainNum;
|
||||||
pTrain->trainNum.iTrainTypeId = 0;
|
pTrain->trainNum.iTrainTypeId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修正载重
|
||||||
|
for (std::map<std::string, std::string>::iterator it =
|
||||||
|
mapLoad.begin();
|
||||||
|
it != mapLoad.end(); ++it) {
|
||||||
|
|
||||||
|
if (pTrain->trainNum.strTrainType.find(it->first) !=
|
||||||
|
std::string::npos) {
|
||||||
|
pTrain->trainPro.strLoad = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (pTrain->trainPro.strLoad.size() > 2 && pTrain->trainPro.strLoad[0] != '1') pTrain->trainPro.strLoad = "";
|
||||||
|
|
||||||
PushData(pTrain);
|
PushData(pTrain);
|
||||||
|
|
||||||
//最后一节处理后,初始化参数
|
//最后一节处理后,初始化参数
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -47,8 +47,8 @@ APP_ERROR SaveImgEngine::Process()
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int> compression_params;
|
vector<int> compression_params;
|
||||||
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); //选择jpeg
|
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); //选择jpeg
|
||||||
compression_params.push_back(iPicQuality); //图片质量
|
compression_params.push_back(iPicQuality); //图片质量
|
||||||
iDirection_ = DIRECTION_UNKNOWN;
|
iDirection_ = DIRECTION_UNKNOWN;
|
||||||
|
|
||||||
int iRet = APP_ERR_OK;
|
int iRet = APP_ERR_OK;
|
||||||
|
|
@ -154,6 +154,7 @@ APP_ERROR SaveImgEngine::Process()
|
||||||
Json::Value jvFrameInfo;
|
Json::Value jvFrameInfo;
|
||||||
jvFrameInfo["timeStamp"] = pSaveImgData->i64TimeStamp;
|
jvFrameInfo["timeStamp"] = pSaveImgData->i64TimeStamp;
|
||||||
jvFrameInfo["status"] = iStatus;
|
jvFrameInfo["status"] = iStatus;
|
||||||
|
jvFrameInfo["moveType"] = pSaveImgData->nMonitorState;
|
||||||
jvFrameInfo["direction"] = pSaveImgData->iDirection;
|
jvFrameInfo["direction"] = pSaveImgData->iDirection;
|
||||||
jvFrameInfo["width"] = iWidth;
|
jvFrameInfo["width"] = iWidth;
|
||||||
jvFrameInfo["height"] = iHeight;
|
jvFrameInfo["height"] = iHeight;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,279 +1,279 @@
|
||||||
#include "SocketEngine.h"
|
#include "SocketEngine.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SocketEngine::SocketEngine()
|
SocketEngine::SocketEngine()
|
||||||
{
|
{
|
||||||
isStop_ = false;
|
isStop_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketEngine::~SocketEngine() {}
|
SocketEngine::~SocketEngine() {}
|
||||||
|
|
||||||
APP_ERROR SocketEngine::Init()
|
APP_ERROR SocketEngine::Init()
|
||||||
{
|
{
|
||||||
strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0";
|
strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0";
|
||||||
|
|
||||||
this->socketOpenType_ = MyYaml::GetIns()->GetIntValue("socket_server_open");
|
this->socketOpenType_ = MyYaml::GetIns()->GetIntValue("socket_server_open");
|
||||||
this->socketPort_ = MyYaml::GetIns()->GetIntValue("socket_server_port");
|
this->socketPort_ = MyYaml::GetIns()->GetIntValue("socket_server_port");
|
||||||
this->socketQueueLen_ = MyYaml::GetIns()->GetIntValue("socket_server_queue_len");
|
this->socketQueueLen_ = MyYaml::GetIns()->GetIntValue("socket_server_queue_len");
|
||||||
|
|
||||||
MyShellInfo << "SocketEngine init ok";
|
MyShellInfo << "SocketEngine init ok";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
APP_ERROR SocketEngine::DeInit()
|
APP_ERROR SocketEngine::DeInit()
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int fd = 0; fd <= max_fd; ++fd)
|
for (int fd = 0; fd <= max_fd; ++fd)
|
||||||
{
|
{
|
||||||
if (FD_ISSET(fd, &master_set))
|
if (FD_ISSET(fd, &master_set))
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MyShellInfo << "SocketEngine deinit ok";
|
MyShellInfo << "SocketEngine deinit ok";
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
APP_ERROR SocketEngine::Process()
|
APP_ERROR SocketEngine::Process()
|
||||||
{
|
{
|
||||||
int ret = APP_ERR_OK;
|
int ret = APP_ERR_OK;
|
||||||
|
|
||||||
if (this->socketOpenType_)
|
if (this->socketOpenType_)
|
||||||
{
|
{
|
||||||
while (!isStop_)
|
while (!isStop_)
|
||||||
{
|
{
|
||||||
if (!this->Socket_(this->socketPort_)) continue;
|
if (!this->Socket_(this->socketPort_)) continue;
|
||||||
if (!this->Bind()) continue;
|
if (!this->Bind()) continue;
|
||||||
this->Listen(this->socketQueueLen_);
|
this->Listen(this->socketQueueLen_);
|
||||||
this->Run();
|
this->Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (!isStop_)
|
while (!isStop_)
|
||||||
{
|
{
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return APP_ERR_OK;
|
return APP_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Socket_(int port)
|
bool SocketEngine::Socket_(int port)
|
||||||
{
|
{
|
||||||
bzero(&server_addr, sizeof(server_addr));
|
bzero(&server_addr, sizeof(server_addr));
|
||||||
server_addr.sin_family = AF_INET;
|
server_addr.sin_family = AF_INET;
|
||||||
server_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
server_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
||||||
server_addr.sin_port = htons(port);
|
server_addr.sin_port = htons(port);
|
||||||
// create socket to listen
|
// create socket to listen
|
||||||
listen_fd = socket(PF_INET, SOCK_STREAM, 0);
|
listen_fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
if (listen_fd < 0)
|
if (listen_fd < 0)
|
||||||
{
|
{
|
||||||
LogError << "Create Scoket_Server Failed!";
|
LogError << "Create Scoket_Server Failed!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int opt = 1;
|
int opt = 1;
|
||||||
setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Bind()
|
bool SocketEngine::Bind()
|
||||||
{
|
{
|
||||||
if (-1 == (bind(listen_fd, (struct sockaddr*)&server_addr, sizeof(server_addr))))
|
if (-1 == (bind(listen_fd, (struct sockaddr*)&server_addr, sizeof(server_addr))))
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Bind Failed!";
|
LogError << "Scoket_Server Bind Failed!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LogInfo << "Scoket_Server Bind Successfully.";
|
LogInfo << "Scoket_Server Bind Successfully.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Listen(int queue_len)
|
bool SocketEngine::Listen(int queue_len)
|
||||||
{
|
{
|
||||||
if (-1 == listen(listen_fd, queue_len))
|
if (-1 == listen(listen_fd, queue_len))
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Listen Failed!";
|
LogError << "Scoket_Server Listen Failed!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LogInfo << "Scoket_Server Listen Successfully.";
|
LogInfo << "Scoket_Server Listen Successfully.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Accept()
|
bool SocketEngine::Accept()
|
||||||
{
|
{
|
||||||
struct sockaddr_in client_addr;
|
struct sockaddr_in client_addr;
|
||||||
socklen_t client_addr_len = sizeof(client_addr);
|
socklen_t client_addr_len = sizeof(client_addr);
|
||||||
|
|
||||||
int new_fd = accept(listen_fd, (struct sockaddr*)&client_addr, &client_addr_len);
|
int new_fd = accept(listen_fd, (struct sockaddr*)&client_addr, &client_addr_len);
|
||||||
if (new_fd < 0)
|
if (new_fd < 0)
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Accept Failed!";
|
LogError << "Scoket_Server Accept Failed!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ip(inet_ntoa(client_addr.sin_addr)); // 获取客户端IP
|
std::string ip(inet_ntoa(client_addr.sin_addr)); // 获取客户端IP
|
||||||
|
|
||||||
LogInfo << ip << " new connection was accepted.";
|
LogInfo << ip << " new connection was accepted.";
|
||||||
|
|
||||||
mmap.insert(std::make_pair(new_fd, std::make_pair(ip, 0)));
|
mmap.insert(std::make_pair(new_fd, std::make_pair(ip, 0)));
|
||||||
|
|
||||||
// 将新建立的连接的fd加入master_set
|
// 将新建立的连接的fd加入master_set
|
||||||
FD_SET(new_fd, &master_set);
|
FD_SET(new_fd, &master_set);
|
||||||
if (new_fd > max_fd)
|
if (new_fd > max_fd)
|
||||||
{
|
{
|
||||||
max_fd = new_fd;
|
max_fd = new_fd;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Recv(int nums)
|
bool SocketEngine::Recv(int nums)
|
||||||
{
|
{
|
||||||
for (int fd = 0; fd <= max_fd; ++fd)
|
for (int fd = 0; fd <= max_fd; ++fd)
|
||||||
{
|
{
|
||||||
if (FD_ISSET(fd, &working_set))
|
if (FD_ISSET(fd, &working_set))
|
||||||
{
|
{
|
||||||
bool close_conn = false; // 标记当前连接是否断开了
|
bool close_conn = false; // 标记当前连接是否断开了
|
||||||
|
|
||||||
char order_str[512] = { 0 };
|
char order_str[512] = { 0 };
|
||||||
|
|
||||||
int size_get = recv(fd, (char*)&order_str, sizeof(order_str) - 1, 0);
|
int size_get = recv(fd, (char*)&order_str, sizeof(order_str) - 1, 0);
|
||||||
|
|
||||||
if (size_get <= 0)
|
if (size_get <= 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
bool isHeart_beat = (std::string(order_str) == "matrixai");
|
bool isHeart_beat = (std::string(order_str) == "matrixai");
|
||||||
if (isHeart_beat)
|
if (isHeart_beat)
|
||||||
{
|
{
|
||||||
mmap[fd].second = 0; // 每次收到心跳包,count置0
|
mmap[fd].second = 0; // 每次收到心跳包,count置0
|
||||||
//LogDebug << "Scoket_Server Received heart-beat from client.";
|
//LogDebug << "Scoket_Server Received heart-beat from client.";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogInfo << "Received message from client:" << std::string(order_str);
|
LogInfo << "Received message from client:" << std::string(order_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (close_conn) // 当前这个连接有问题,关闭它
|
if (close_conn) // 当前这个连接有问题,关闭它
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
FD_CLR(fd, &master_set);
|
FD_CLR(fd, &master_set);
|
||||||
if (fd == max_fd) // 需要更新max_fd;
|
if (fd == max_fd) // 需要更新max_fd;
|
||||||
{
|
{
|
||||||
while (FD_ISSET(max_fd, &master_set) == false)
|
while (FD_ISSET(max_fd, &master_set) == false)
|
||||||
--max_fd;
|
--max_fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::Run()
|
bool SocketEngine::Run()
|
||||||
{
|
{
|
||||||
pthread_t id; // 创建心跳检测线程
|
pthread_t id; // 创建心跳检测线程
|
||||||
int ret = pthread_create(&id, NULL, heart_handler, (void*)this);
|
int ret = pthread_create(&id, NULL, heart_handler, (void*)this);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Can not create heart-beat checking thread.";
|
LogError << "Scoket_Server Can not create heart-beat checking thread.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = pthread_create(&id, NULL, sendInfo, (void*)this);
|
ret = pthread_create(&id, NULL, sendInfo, (void*)this);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server Can not create message send thread.";
|
LogError << "Scoket_Server Can not create message send thread.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
max_fd = listen_fd; // 初始化max_fd
|
max_fd = listen_fd; // 初始化max_fd
|
||||||
FD_ZERO(&master_set);
|
FD_ZERO(&master_set);
|
||||||
FD_SET(listen_fd, &master_set); // 添加监听fd
|
FD_SET(listen_fd, &master_set); // 添加监听fd
|
||||||
|
|
||||||
while (!isStop_)
|
while (!isStop_)
|
||||||
{
|
{
|
||||||
FD_ZERO(&working_set);
|
FD_ZERO(&working_set);
|
||||||
memcpy(&working_set, &master_set, sizeof(master_set));
|
memcpy(&working_set, &master_set, sizeof(master_set));
|
||||||
|
|
||||||
timeout.tv_sec = 30;
|
timeout.tv_sec = 30;
|
||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
int nums = select(max_fd + 1, &working_set, NULL, NULL, &timeout);
|
int nums = select(max_fd + 1, &working_set, NULL, NULL, &timeout);
|
||||||
/*if (nums < 0)
|
/*if (nums < 0)
|
||||||
{
|
{
|
||||||
LogError << "Scoket_Server select() error!";
|
LogError << "Scoket_Server select() error!";
|
||||||
return false;
|
return false;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (nums <= 0)
|
if (nums <= 0)
|
||||||
{
|
{
|
||||||
//cout << "select() is timeout!";
|
//cout << "select() is timeout!";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(listen_fd, &working_set))
|
if (FD_ISSET(listen_fd, &working_set))
|
||||||
Accept(); // 有新的客户端请求
|
Accept(); // 有新的客户端请求
|
||||||
else
|
else
|
||||||
Recv(nums); // 接收客户端的消息
|
Recv(nums); // 接收客户端的消息
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//解析命令
|
//解析命令
|
||||||
bool SocketEngine::getOrder(const std::string &recv, Json::Value &order)
|
bool SocketEngine::getOrder(const std::string &recv, Json::Value &order)
|
||||||
{
|
{
|
||||||
Json::CharReaderBuilder readerBuilder;
|
Json::CharReaderBuilder readerBuilder;
|
||||||
std::shared_ptr<Json::CharReader> reader(readerBuilder.newCharReader());
|
std::shared_ptr<Json::CharReader> reader(readerBuilder.newCharReader());
|
||||||
|
|
||||||
JSONCPP_STRING errs;
|
JSONCPP_STRING errs;
|
||||||
if (!reader->parse(recv.data(), recv.data() + recv.size(), &order, &errs))
|
if (!reader->parse(recv.data(), recv.data() + recv.size(), &order, &errs))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (order.isArray()) {
|
if (order.isArray()) {
|
||||||
if (order.size() > 0) order = order[0];
|
if (order.size() > 0) order = order[0];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SocketEngine::getFeedBack(const std::string poundNo, const std::string type, const std::string info)
|
std::string SocketEngine::getFeedBack(const std::string poundNo, const std::string type, const std::string info)
|
||||||
{
|
{
|
||||||
Json::Value feedBack;
|
Json::Value feedBack;
|
||||||
Json::StreamWriterBuilder strbuild;
|
Json::StreamWriterBuilder strbuild;
|
||||||
|
|
||||||
feedBack["poundNo"] = poundNo;
|
feedBack["poundNo"] = poundNo;
|
||||||
feedBack["type"] = type;
|
feedBack["type"] = type;
|
||||||
feedBack["info"] = info;
|
feedBack["info"] = info;
|
||||||
//
|
//
|
||||||
return Json::writeString(strbuild, feedBack);
|
return Json::writeString(strbuild, feedBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* SocketEngine::sendInfo(void* arg) {
|
void* SocketEngine::sendInfo(void* arg) {
|
||||||
SocketEngine* s = (SocketEngine*)arg;
|
SocketEngine* s = (SocketEngine*)arg;
|
||||||
while (!s->isStop_) {
|
while (!s->isStop_) {
|
||||||
//pop端口0
|
//pop端口0
|
||||||
std::shared_ptr<void> pVoidData0 = nullptr;
|
std::shared_ptr<void> pVoidData0 = nullptr;
|
||||||
s->inputQueMap_[s->strPort0_]->pop(pVoidData0);
|
s->inputQueMap_[s->strPort0_]->pop(pVoidData0);
|
||||||
if (nullptr == pVoidData0)
|
if (nullptr == pVoidData0)
|
||||||
{
|
{
|
||||||
usleep(1000); //1ms
|
usleep(1000); //1ms
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<std::string> pMessage = std::static_pointer_cast<std::string>(pVoidData0);
|
std::shared_ptr<std::string> pMessage = std::static_pointer_cast<std::string>(pVoidData0);
|
||||||
|
|
||||||
SendAllClient(s->mmap, *pMessage);
|
SendAllClient(s->mmap, *pMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -281,176 +281,176 @@ void* SocketEngine::sendInfo(void* arg) {
|
||||||
// thread function
|
// thread function
|
||||||
void* SocketEngine::heart_handler(void* arg)
|
void* SocketEngine::heart_handler(void* arg)
|
||||||
{
|
{
|
||||||
LogInfo << "Scoket_Server The heartbeat checking thread started.\n";
|
LogInfo << "Scoket_Server The heartbeat checking thread started.\n";
|
||||||
SocketEngine* s = (SocketEngine*)arg;
|
SocketEngine* s = (SocketEngine*)arg;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
std::map<int, std::pair<std::string, int> >::iterator it = s->mmap.begin();
|
std::map<int, std::pair<std::string, int> >::iterator it = s->mmap.begin();
|
||||||
for (; it != s->mmap.end(); )
|
for (; it != s->mmap.end(); )
|
||||||
{
|
{
|
||||||
if (it->second.second == 5) // sleep(3)*5没有收到心跳包,判定客户端掉线
|
if (it->second.second == 5) // sleep(3)*5没有收到心跳包,判定客户端掉线
|
||||||
{
|
{
|
||||||
LogInfo << "The client " << it->second.first << " has be offline.\n";
|
LogInfo << "The client " << it->second.first << " has be offline.\n";
|
||||||
|
|
||||||
int fd = it->first;
|
int fd = it->first;
|
||||||
close(fd); // 关闭该连接
|
close(fd); // 关闭该连接
|
||||||
FD_CLR(fd, &s->master_set);
|
FD_CLR(fd, &s->master_set);
|
||||||
if (fd == s->max_fd) // 需要更新max_fd;
|
if (fd == s->max_fd) // 需要更新max_fd;
|
||||||
{
|
{
|
||||||
while (FD_ISSET(s->max_fd, &s->master_set) == false)
|
while (FD_ISSET(s->max_fd, &s->master_set) == false)
|
||||||
s->max_fd--;
|
s->max_fd--;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->mmap.erase(it++); // 从map中移除该记录
|
s->mmap.erase(it++); // 从map中移除该记录
|
||||||
}
|
}
|
||||||
else if (it->second.second < 5 && it->second.second >= 0)
|
else if (it->second.second < 5 && it->second.second >= 0)
|
||||||
{
|
{
|
||||||
it->second.second += 1;
|
it->second.second += 1;
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sleep(3); // 定时三秒
|
sleep(1); // 定时三秒
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool SocketEngine::SendClient(std::map<int, std::pair<std::string, int> > mmap, const std::string ip, const std::string message) {
|
bool SocketEngine::SendClient(std::map<int, std::pair<std::string, int> > mmap, const std::string ip, const std::string message) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
|
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
|
||||||
for (; it != mmap.end(); ++it)
|
for (; it != mmap.end(); ++it)
|
||||||
{
|
{
|
||||||
if (it->second.first == ip) // 遍历找雷达ip
|
if (it->second.first == ip) // 遍历找雷达ip
|
||||||
{
|
{
|
||||||
int fd = it->first;
|
int fd = it->first;
|
||||||
|
|
||||||
if (send(fd, message.c_str(), message.size(), 0) <= 0)
|
if (send(fd, message.c_str(), message.size(), 0) <= 0)
|
||||||
{
|
{
|
||||||
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
|
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char clientFeedBack[256] = { 0 };
|
char clientFeedBack[256] = { 0 };
|
||||||
if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
|
if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
|
||||||
{
|
{
|
||||||
Json::Value feedBack;
|
Json::Value feedBack;
|
||||||
|
|
||||||
if (!getOrder(clientFeedBack, feedBack)) {
|
if (!getOrder(clientFeedBack, feedBack)) {
|
||||||
LogError << "Get Client IP:" << ip << " feekBack format is error : " << clientFeedBack;
|
LogError << "Get Client IP:" << ip << " feekBack format is error : " << clientFeedBack;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feedBack.get("success", "").asString() == "true")
|
if (feedBack.get("success", "").asString() == "true")
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
|
LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
LogError << "Socker Server send message to IP:" << ip << " successful, But recv error!";
|
LogError << "Socker Server send message to IP:" << ip << " successful, But recv error!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception&)
|
catch (const std::exception&)
|
||||||
{
|
{
|
||||||
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
|
LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LogError << "Socker Server send message to IP:" << ip << " failed, because no find connection";
|
LogError << "Socker Server send message to IP:" << ip << " failed, because no find connection";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketEngine::SendAllClient(std::map<int, std::pair<std::string, int> > mmap, const std::string message) {
|
bool SocketEngine::SendAllClient(std::map<int, std::pair<std::string, int> > mmap, const std::string message) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
|
std::map<int, std::pair<std::string, int> >::iterator it = mmap.begin();
|
||||||
for (; it != mmap.end(); ++it)
|
for (; it != mmap.end(); ++it)
|
||||||
{
|
{
|
||||||
int fd = it->first;
|
int fd = it->first;
|
||||||
LogInfo << "Socket send IP: " << it->second.first << " msg:" << message;
|
LogInfo << "Socket send IP: " << it->second.first << " msg:" << message;
|
||||||
if (send(fd, message.c_str(), message.size(), MSG_NOSIGNAL) <= 0)
|
if (send(fd, message.c_str(), message.size(), MSG_NOSIGNAL) <= 0)
|
||||||
{
|
{
|
||||||
LogError << "Socker Server send message to IP:" << it->second.first << " failed, message:" << message;
|
LogError << "Socker Server send message to IP:" << it->second.first << " failed, message:" << message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// char clientFeedBack[256] = { 0 };
|
// char clientFeedBack[256] = { 0 };
|
||||||
// if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
|
// if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0)
|
||||||
// {
|
// {
|
||||||
// Json::Value feedBack;
|
// Json::Value feedBack;
|
||||||
|
|
||||||
// if (!getOrder(clientFeedBack, feedBack)) {
|
// if (!getOrder(clientFeedBack, feedBack)) {
|
||||||
// LogError << "Get Client IP: "<< it->second.first << " feekBack format is error : " << clientFeedBack;
|
// LogError << "Get Client IP: "<< it->second.first << " feekBack format is error : " << clientFeedBack;
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (feedBack.get("success", "").asString() == "true")
|
// if (feedBack.get("success", "").asString() == "true")
|
||||||
// {
|
// {
|
||||||
// return true;
|
// return true;
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
|
// LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString();
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
|
|
||||||
// LogError << "Socker Server send message to IP:" << it->second.first << " successful, But recv error!";
|
// LogError << "Socker Server send message to IP:" << it->second.first << " successful, But recv error!";
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception&)
|
catch (const std::exception&)
|
||||||
{
|
{
|
||||||
LogError << "Socker Server send message to all client failed, message:" << message;
|
LogError << "Socker Server send message to all client failed, message:" << message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SocketEngine::HexToStr(const std::string &str)
|
std::string SocketEngine::HexToStr(const std::string &str)
|
||||||
{
|
{
|
||||||
std::string hex = str;
|
std::string hex = str;
|
||||||
long len = hex.length();
|
long len = hex.length();
|
||||||
std::string newString;
|
std::string newString;
|
||||||
for (long i = 0; i < len; i += 2)
|
for (long i = 0; i < len; i += 2)
|
||||||
{
|
{
|
||||||
std::string byte = hex.substr(i, 2);
|
std::string byte = hex.substr(i, 2);
|
||||||
char chr = (char)(int)strtol(byte.c_str(), NULL, 16);
|
char chr = (char)(int)strtol(byte.c_str(), NULL, 16);
|
||||||
newString.push_back(chr);
|
newString.push_back(chr);
|
||||||
}
|
}
|
||||||
return newString;
|
return newString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string SocketEngine::StrToHex(const std::string &str)
|
std::string SocketEngine::StrToHex(const std::string &str)
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
char buf[2];
|
char buf[2];
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << str;
|
ss << str;
|
||||||
while (ss.read((char*)(&c), sizeof(c)))
|
while (ss.read((char*)(&c), sizeof(c)))
|
||||||
{
|
{
|
||||||
sprintf(buf, "%02x", c);
|
sprintf(buf, "%02x", c);
|
||||||
result += buf;
|
result += buf;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -4,50 +4,50 @@ using namespace std;
|
||||||
|
|
||||||
HardH264FFmpegDecode::HardH264FFmpegDecode()
|
HardH264FFmpegDecode::HardH264FFmpegDecode()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
HardH264FFmpegDecode::~HardH264FFmpegDecode()
|
HardH264FFmpegDecode::~HardH264FFmpegDecode()
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsigned int uiHeight, unsigned int uiFrameRate)
|
int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsigned int uiHeight, unsigned int uiFrameRate)
|
||||||
{
|
{
|
||||||
uiWidth_ = uiWidth; uiHeight_ = uiHeight;
|
uiWidth_ = uiWidth; uiHeight_ = uiHeight;
|
||||||
uiFrameRate_ = uiFrameRate;
|
uiFrameRate_ = uiFrameRate;
|
||||||
iFrameFinished_ = 0;
|
iFrameFinished_ = 0;
|
||||||
|
|
||||||
av_log_set_level(AV_LOG_ERROR);
|
av_log_set_level(AV_LOG_ERROR);
|
||||||
|
|
||||||
// AVCodecID codec_id = AV_CODEC_ID_H264; //解码H264
|
// AVCodecID codec_id = AV_CODEC_ID_H264; //解码H264
|
||||||
// pCodec_ = avcodec_find_decoder(codec_id); //获取解码器
|
// pCodec_ = avcodec_find_decoder(codec_id); //获取解码器
|
||||||
|
|
||||||
pCodec_ = avcodec_find_decoder_by_name(NVIDIA_H264_DECODER);
|
pCodec_ = avcodec_find_decoder_by_name(NVIDIA_H264_DECODER);
|
||||||
if (!pCodec_) {
|
if (!pCodec_) {
|
||||||
fprintf(stderr, "Codec '%s' not found\n", pCodec_->long_name);
|
fprintf(stderr, "Codec '%s' not found\n", pCodec_->long_name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
printf("Codec found with name %d(%s)\n", pCodec_->id, pCodec_->long_name);
|
printf("Codec found with name %d(%s)\n", pCodec_->id, pCodec_->long_name);
|
||||||
|
|
||||||
//创建上下文
|
//创建上下文
|
||||||
pCodecCtx_ = avcodec_alloc_context3(pCodec_);
|
pCodecCtx_ = avcodec_alloc_context3(pCodec_);
|
||||||
if (!pCodecCtx_){
|
if (!pCodecCtx_){
|
||||||
fprintf(stderr, "Could not allocate video codec context\n");
|
fprintf(stderr, "Could not allocate video codec context\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建解析器
|
//创建解析器
|
||||||
pCodecParserCtx_ = av_parser_init(pCodec_->id);
|
pCodecParserCtx_ = av_parser_init(pCodec_->id);
|
||||||
if (!pCodecParserCtx_){
|
if (!pCodecParserCtx_){
|
||||||
fprintf(stderr, "parser not found\n");
|
fprintf(stderr, "parser not found\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(pCodec_->capabilities&CODEC_CAP_TRUNCATED)
|
//if(pCodec_->capabilities&CODEC_CAP_TRUNCATED)
|
||||||
// pCodecCtx_->flags|= CODEC_FLAG_TRUNCATED;
|
// pCodecCtx_->flags|= CODEC_FLAG_TRUNCATED;
|
||||||
|
|
||||||
//打开解码器
|
//打开解码器
|
||||||
int ret = avcodec_open2(pCodecCtx_, pCodec_, nullptr);
|
int ret = avcodec_open2(pCodecCtx_, pCodec_, nullptr);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "Could not open codec\n");
|
fprintf(stderr, "Could not open codec\n");
|
||||||
|
|
@ -63,7 +63,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsign
|
||||||
}
|
}
|
||||||
// av_init_packet(pPacket_);
|
// av_init_packet(pPacket_);
|
||||||
|
|
||||||
//分配frame
|
//分配frame
|
||||||
pSrcFrame_ = av_frame_alloc();
|
pSrcFrame_ = av_frame_alloc();
|
||||||
if (!pSrcFrame_) {
|
if (!pSrcFrame_) {
|
||||||
fprintf(stderr, "Could not allocate video src pFrame\n");
|
fprintf(stderr, "Could not allocate video src pFrame\n");
|
||||||
|
|
@ -78,14 +78,14 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsign
|
||||||
|
|
||||||
printf("after align down video_width: %d, video_height: %d\n", uiWidth_, uiHeight_);
|
printf("after align down video_width: %d, video_height: %d\n", uiWidth_, uiHeight_);
|
||||||
|
|
||||||
//初始化解析器参数
|
//初始化解析器参数
|
||||||
pCodecCtx_->time_base.num = 1;
|
pCodecCtx_->time_base.num = 1;
|
||||||
pCodecCtx_->frame_number = 1; //每包一个视频帧
|
pCodecCtx_->frame_number = 1; //每包一个视频帧
|
||||||
pCodecCtx_->codec_type = AVMEDIA_TYPE_VIDEO;
|
pCodecCtx_->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||||
pCodecCtx_->bit_rate = 0;
|
pCodecCtx_->bit_rate = 0;
|
||||||
pCodecCtx_->time_base.den = uiFrameRate_;//帧率
|
pCodecCtx_->time_base.den = uiFrameRate_;//帧率
|
||||||
pCodecCtx_->width = uiWidth_; //视频宽
|
pCodecCtx_->width = uiWidth_; //视频宽
|
||||||
pCodecCtx_->height = uiHeight_; //视频高
|
pCodecCtx_->height = uiHeight_; //视频高
|
||||||
// pCodecCtx_->pix_fmt = AV_PIX_FMT_YUV420P;
|
// pCodecCtx_->pix_fmt = AV_PIX_FMT_YUV420P;
|
||||||
|
|
||||||
int bufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P,
|
int bufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P,
|
||||||
|
|
@ -102,46 +102,46 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderInit(unsigned int uiWidth, unsign
|
||||||
printf("pDstFrame_->linesize: %d, bufferSize: %d\n", pDstFrame_->linesize, bufferSize);
|
printf("pDstFrame_->linesize: %d, bufferSize: %d\n", pDstFrame_->linesize, bufferSize);
|
||||||
|
|
||||||
pSwsContext_ = sws_getContext(pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt,
|
pSwsContext_ = sws_getContext(pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt,
|
||||||
pCodecCtx_->width, pCodecCtx_->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, nullptr, nullptr, nullptr);
|
pCodecCtx_->width, pCodecCtx_->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, nullptr, nullptr, nullptr);
|
||||||
printf("pCodecCtx_->width: %d, pCodecCtx_->height: %d, pCodecCtx_->pix_fmt: %d\n", pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt);
|
printf("pCodecCtx_->width: %d, pCodecCtx_->height: %d, pCodecCtx_->pix_fmt: %d\n", pCodecCtx_->width, pCodecCtx_->height, pCodecCtx_->pix_fmt);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardH264FFmpegDecode::HardH264FFmpegDecoderDeInit()
|
int HardH264FFmpegDecode::HardH264FFmpegDecoderDeInit()
|
||||||
{
|
{
|
||||||
if(pu8OutBuffer_){
|
if(pu8OutBuffer_){
|
||||||
av_free(pu8OutBuffer_);
|
av_free(pu8OutBuffer_);
|
||||||
pu8OutBuffer_ = nullptr;
|
pu8OutBuffer_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pSrcFrame_){
|
if(pSrcFrame_){
|
||||||
av_frame_free(&pSrcFrame_);
|
av_frame_free(&pSrcFrame_);
|
||||||
pSrcFrame_ = nullptr;
|
pSrcFrame_ = nullptr;
|
||||||
}
|
}
|
||||||
if(pDstFrame_){
|
if(pDstFrame_){
|
||||||
av_frame_free(&pDstFrame_);
|
av_frame_free(&pDstFrame_);
|
||||||
pDstFrame_ = nullptr;
|
pDstFrame_ = nullptr;
|
||||||
}
|
}
|
||||||
if(pPacket_){
|
if(pPacket_){
|
||||||
av_packet_free(&pPacket_);
|
av_packet_free(&pPacket_);
|
||||||
pPacket_ = nullptr;
|
pPacket_ = nullptr;
|
||||||
}
|
}
|
||||||
if(pCodecParserCtx_){
|
if(pCodecParserCtx_){
|
||||||
av_parser_close(pCodecParserCtx_);
|
av_parser_close(pCodecParserCtx_);
|
||||||
pCodecParserCtx_ = nullptr;
|
pCodecParserCtx_ = nullptr;
|
||||||
}
|
}
|
||||||
if(pCodecCtx_){
|
if(pCodecCtx_){
|
||||||
avcodec_close(pCodecCtx_);
|
avcodec_close(pCodecCtx_);
|
||||||
av_free(pCodecCtx_);
|
av_free(pCodecCtx_);
|
||||||
pCodecCtx_ = nullptr;
|
pCodecCtx_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pSwsContext_){
|
if(pSwsContext_){
|
||||||
sws_freeContext(pSwsContext_);
|
sws_freeContext(pSwsContext_);
|
||||||
pSwsContext_ = nullptr;
|
pSwsContext_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardH264FFmpegDecode::HardH264FFmpegDecoderFilterGraph(AVFilterGraph *pGraph, AVFilterContext *pSourceCtx, AVFilterContext *pSinkCtx)
|
int HardH264FFmpegDecode::HardH264FFmpegDecoderFilterGraph(AVFilterGraph *pGraph, AVFilterContext *pSourceCtx, AVFilterContext *pSinkCtx)
|
||||||
|
|
@ -149,7 +149,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderFilterGraph(AVFilterGraph *pGraph
|
||||||
int ret;
|
int ret;
|
||||||
AVFilterInOut *pOutputs = nullptr, *pInputs = nullptr;
|
AVFilterInOut *pOutputs = nullptr, *pInputs = nullptr;
|
||||||
if ((ret = avfilter_link(pSourceCtx, 0, pSinkCtx, 0)) >= 0){
|
if ((ret = avfilter_link(pSourceCtx, 0, pSinkCtx, 0)) >= 0){
|
||||||
ret = avfilter_graph_config(pGraph, nullptr);
|
ret = avfilter_graph_config(pGraph, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
avfilter_inout_free(&pOutputs);
|
avfilter_inout_free(&pOutputs);
|
||||||
|
|
@ -168,14 +168,14 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderConfigureVideoFilters(AVFilterGra
|
||||||
"video_size=%dx%d:pix_fmt=%d:time_base=1/1200000",
|
"video_size=%dx%d:pix_fmt=%d:time_base=1/1200000",
|
||||||
iWidth, iHeight, iFormat);
|
iWidth, iHeight, iFormat);
|
||||||
if ((ret = avfilter_graph_create_filter(&pFiltSrc,
|
if ((ret = avfilter_graph_create_filter(&pFiltSrc,
|
||||||
avfilter_get_by_name("buffer"), "ffplay_buffer", BufferSrcArgs,
|
avfilter_get_by_name("buffer"), "ffplay_buffer", BufferSrcArgs,
|
||||||
nullptr, pGraph)) < 0){
|
nullptr, pGraph)) < 0){
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = avfilter_graph_create_filter(&pFiltDst,
|
ret = avfilter_graph_create_filter(&pFiltDst,
|
||||||
avfilter_get_by_name("buffersink"),
|
avfilter_get_by_name("buffersink"),
|
||||||
"ffplay_buffersink", nullptr, nullptr, pGraph);
|
"ffplay_buffersink", nullptr, nullptr, pGraph);
|
||||||
if (ret < 0){
|
if (ret < 0){
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
@ -190,14 +190,14 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderConfigureVideoFilters(AVFilterGra
|
||||||
pDecoderFilterIn = pFiltSrc;
|
pDecoderFilterIn = pFiltSrc;
|
||||||
pDecoderFilterOut = pFiltDst;
|
pDecoderFilterOut = pFiltDst;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame *pFrame, AVPacket *pPkt, void* pOutputData, unsigned int* puiOutputDataSize)
|
int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame *pFrame, AVPacket *pPkt, void* pOutputData, unsigned int* puiOutputDataSize)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
AVFilterGraph* pDecoderGraph = nullptr;
|
AVFilterGraph* pDecoderGraph = nullptr;
|
||||||
|
|
||||||
ret = avcodec_send_packet(pDecCtx, pPkt); //接收packet解码
|
ret = avcodec_send_packet(pDecCtx, pPkt); //接收packet解码
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
@ -208,7 +208,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame
|
||||||
while (ret >= 0) {
|
while (ret >= 0) {
|
||||||
ret = avcodec_receive_frame(pDecCtx, pFrame); //解码
|
ret = avcodec_receive_frame(pDecCtx, pFrame); //解码
|
||||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
|
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
|
||||||
fprintf(stderr, "During decoding eof\n");
|
fprintf(stderr, "During decoding eof\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (ret < 0) {
|
else if (ret < 0) {
|
||||||
|
|
@ -219,7 +219,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame
|
||||||
//printf("saving frame %3d\n", pDecCtx->frame_number);
|
//printf("saving frame %3d\n", pDecCtx->frame_number);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
AVFilterContext *pDecoderFilterIn = nullptr, *pDecoderFilterOut = nullptr;
|
AVFilterContext *pDecoderFilterIn = nullptr, *pDecoderFilterOut = nullptr;
|
||||||
|
|
||||||
// pFrame->width = ALIGN_DOWN(pFrame->width, 32);
|
// pFrame->width = ALIGN_DOWN(pFrame->width, 32);
|
||||||
// pFrame->height = ALIGN_DOWN(pFrame->height, 32);
|
// pFrame->height = ALIGN_DOWN(pFrame->height, 32);
|
||||||
|
|
@ -228,26 +228,26 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoder(AVCodecContext *pDecCtx, AVFrame
|
||||||
pDecoderGraph = avfilter_graph_alloc();
|
pDecoderGraph = avfilter_graph_alloc();
|
||||||
HardH264FFmpegDecoderConfigureVideoFilters(pDecoderGraph, pDecoderFilterIn, pDecoderFilterOut, pFrame->width, pFrame->height, pFrame->format);
|
HardH264FFmpegDecoderConfigureVideoFilters(pDecoderGraph, pDecoderFilterIn, pDecoderFilterOut, pFrame->width, pFrame->height, pFrame->format);
|
||||||
|
|
||||||
if (pFrame->format != AV_PIX_FMT_YUV420P){
|
if (pFrame->format != AV_PIX_FMT_YUV420P){
|
||||||
DUMP_FRAME(pFrame);
|
DUMP_FRAME(pFrame);
|
||||||
ret = av_buffersrc_add_frame(pDecoderFilterIn, pFrame);
|
ret = av_buffersrc_add_frame(pDecoderFilterIn, pFrame);
|
||||||
ret = av_buffersink_get_frame_flags(pDecoderFilterOut, pFrame, 0);
|
ret = av_buffersink_get_frame_flags(pDecoderFilterOut, pFrame, 0);
|
||||||
DUMP_FRAME(pFrame);
|
DUMP_FRAME(pFrame);
|
||||||
|
|
||||||
int iSize = pFrame->width * pFrame->height;
|
int iSize = pFrame->width * pFrame->height;
|
||||||
memcpy(pOutputData, pFrame->data[0], iSize); //Y
|
memcpy(pOutputData, pFrame->data[0], iSize); //Y
|
||||||
memcpy(pOutputData+iSize, pFrame->data[1], iSize/4); //U
|
memcpy(pOutputData+iSize, pFrame->data[1], iSize/4); //U
|
||||||
memcpy(pOutputData+iSize+iSize/4, pFrame->data[2], iSize/4); //V
|
memcpy(pOutputData+iSize+iSize/4, pFrame->data[2], iSize/4); //V
|
||||||
*puiOutputDataSize = iSize*3/2;
|
*puiOutputDataSize = iSize*3/2;
|
||||||
return iSize*3/2;
|
return iSize*3/2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsContext *pSwsCtx, AVFrame *pSrcFrame, AVFrame *pDstFrame, AVPacket *pPkt, void* pOutputData,unsigned int* puiOutputDataSize)
|
int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsContext *pSwsCtx, AVFrame *pSrcFrame, AVFrame *pDstFrame, AVPacket *pPkt, void* pOutputData,unsigned int* puiOutputDataSize)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = avcodec_send_packet(pDecCtx, pPkt); //接收packet解码
|
ret = avcodec_send_packet(pDecCtx, pPkt); //接收packet解码
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
@ -258,7 +258,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsCo
|
||||||
while (ret >= 0) {
|
while (ret >= 0) {
|
||||||
ret = avcodec_receive_frame(pDecCtx, pSrcFrame); //解码
|
ret = avcodec_receive_frame(pDecCtx, pSrcFrame); //解码
|
||||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
|
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
|
||||||
fprintf(stderr, "During decoding eof\n");
|
fprintf(stderr, "During decoding eof\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (ret < 0) {
|
else if (ret < 0) {
|
||||||
|
|
@ -266,7 +266,7 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsCo
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pDecCtx->width = ALIGN_DOWN(pDecCtx->width, 32);
|
// pDecCtx->width = ALIGN_DOWN(pDecCtx->width, 32);
|
||||||
// pDecCtx->height = ALIGN_DOWN(pDecCtx->height, 32);
|
// pDecCtx->height = ALIGN_DOWN(pDecCtx->height, 32);
|
||||||
|
|
||||||
sws_scale(pSwsCtx,
|
sws_scale(pSwsCtx,
|
||||||
|
|
@ -280,13 +280,13 @@ int HardH264FFmpegDecode::HardH264FFmpegDecoderV2(AVCodecContext *pDecCtx, SwsCo
|
||||||
//printf("saving frame %3d\n", pDecCtx->frame_number);
|
//printf("saving frame %3d\n", pDecCtx->frame_number);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
int iSize = pDecCtx->width * pDecCtx->height;
|
int iSize = pDecCtx->width * pDecCtx->height;
|
||||||
|
|
||||||
memcpy(pOutputData, pDstFrame->data[0], iSize); //Y
|
memcpy(pOutputData, pDstFrame->data[0], iSize); //Y
|
||||||
memcpy(pOutputData+iSize, pDstFrame->data[1], iSize/4); //U
|
memcpy(pOutputData+iSize, pDstFrame->data[1], iSize/4); //U
|
||||||
memcpy(pOutputData+iSize+iSize/4, pDstFrame->data[2], iSize/4); //V
|
memcpy(pOutputData+iSize+iSize/4, pDstFrame->data[2], iSize/4); //V
|
||||||
*puiOutputDataSize = iSize*3/2;
|
*puiOutputDataSize = iSize*3/2;
|
||||||
return iSize*3/2;
|
return iSize*3/2;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +72,7 @@ public:
|
||||||
|
|
||||||
const AVCodec *pCodec_ = nullptr; //解码器
|
const AVCodec *pCodec_ = nullptr; //解码器
|
||||||
AVCodecContext *pCodecCtx_ = nullptr; //上下文
|
AVCodecContext *pCodecCtx_ = nullptr; //上下文
|
||||||
AVCodecParserContext *pCodecParserCtx_ = nullptr; //解析器上下文
|
AVCodecParserContext *pCodecParserCtx_ = nullptr; //解析器上下文
|
||||||
AVFrame *pSrcFrame_ = nullptr;
|
AVFrame *pSrcFrame_ = nullptr;
|
||||||
AVFrame *pDstFrame_ = nullptr;
|
AVFrame *pDstFrame_ = nullptr;
|
||||||
AVPacket *pPacket_ = nullptr;
|
AVPacket *pPacket_ = nullptr;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -192,6 +192,8 @@ void MoveEngine::SingleDeviceProcess(std::shared_ptr<ProcessData> pProcessData,
|
||||||
{
|
{
|
||||||
outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_" + std::to_string(*iter)]->push(std::static_pointer_cast<void>(pMoveData));
|
outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_" + std::to_string(*iter)]->push(std::static_pointer_cast<void>(pMoveData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LogInfo << "【来车检测】" << pMoveData->iFrameId << " isEnd:" << pProcessData->bIsEnd;
|
||||||
//通知第一步开始识别
|
//通知第一步开始识别
|
||||||
outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_5"]->push(std::static_pointer_cast<void>(pMoveData));
|
outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_5"]->push(std::static_pointer_cast<void>(pMoveData));
|
||||||
}
|
}
|
||||||
|
|
@ -211,6 +213,7 @@ void MoveEngine::SingleDeviceProcess(std::shared_ptr<ProcessData> pProcessData,
|
||||||
pSaveImgData->bIsEnd = pProcessData->bIsEnd;
|
pSaveImgData->bIsEnd = pProcessData->bIsEnd;
|
||||||
pSaveImgData->bSaveToFtp = true;
|
pSaveImgData->bSaveToFtp = true;
|
||||||
pSaveImgData->i64TimeStamp = pProcessData->i64TimeStamp;
|
pSaveImgData->i64TimeStamp = pProcessData->i64TimeStamp;
|
||||||
|
pSaveImgData->nMonitorState = nType;
|
||||||
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pSaveImgData));
|
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pSaveImgData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -282,16 +285,16 @@ APP_ERROR MoveEngine::Process()
|
||||||
// LogInfo<<"来车当前状态:"<< (nType == 0 ? "有车头" : (nType == 1 ? "无车"));
|
// LogInfo<<"来车当前状态:"<< (nType == 0 ? "有车头" : (nType == 1 ? "无车"));
|
||||||
switch (nType) {
|
switch (nType) {
|
||||||
case 0:
|
case 0:
|
||||||
LogDebug << "来车状态:有车头";
|
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:有车头";
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
LogDebug << "来车状态:无车";
|
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:无车";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
LogDebug << "来车状态:车尾";
|
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:车尾";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
LogDebug << "来车状态:有车";
|
LogDebug << iMoveDataNO_ * dataSourceCfg_.iSkipInterval << "来车状态:有车";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,9 +194,9 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
|
||||||
std::vector<stDetection> vecSpaceInfo;
|
std::vector<stDetection> vecSpaceInfo;
|
||||||
for (auto it = vecRet.begin(); it != vecRet.end();)
|
for (auto it = vecRet.begin(); it != vecRet.end();)
|
||||||
{
|
{
|
||||||
LogDebug << "frameId:" << pProcessData->iFrameId
|
// LogDebug << "frameId:" << pProcessData->iFrameId
|
||||||
<< " bigclassid:" << it->class_id << " ltx:" << it->bbox[0] << " lty:" << it->bbox[1]
|
// << " bigclassid:" << it->class_id << " ltx:" << it->bbox[0] << " lty:" << it->bbox[1]
|
||||||
<< " rbx:" << it->bbox[2] << " rby:" << it->bbox[3];
|
// << " rbx:" << it->bbox[2] << " rby:" << it->bbox[3];
|
||||||
// 根据配置文件中 设置的识别范围,过滤掉无效数据
|
// 根据配置文件中 设置的识别范围,过滤掉无效数据
|
||||||
if (!(it->bbox[0] >= dataSourceCfg.fIdentifyAreasLTX &&
|
if (!(it->bbox[0] >= dataSourceCfg.fIdentifyAreasLTX &&
|
||||||
it->bbox[1] >= dataSourceCfg.fIdentifyAreasLTY &&
|
it->bbox[1] >= dataSourceCfg.fIdentifyAreasLTY &&
|
||||||
|
|
@ -322,6 +322,22 @@ void TrainStepOneEngine::FilterInvalidInfo(std::vector<stDetection> &vecRet, std
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (it->class_id == K_TRAIN_NUM)
|
||||||
|
{
|
||||||
|
int iCenterY = pProcessData->iHeight / 2;
|
||||||
|
int iHeight0 = it->bbox[1] / 2 + it->bbox[3] / 2;
|
||||||
|
if (iHeight0 > iCenterY) {
|
||||||
|
LogWarn << "矿车编号大框在画面Y轴中线以下,帧号:"
|
||||||
|
<< pProcessData->iFrameId
|
||||||
|
<< " 画面Y轴中心:" << iCenterY
|
||||||
|
<< " 大框Y轴中心:" << iHeight0 ;
|
||||||
|
// << "[" << it->bbox[0] << "," << it->bbox[1] << "]"
|
||||||
|
// << "[" << it->bbox[2] << "," << it->bbox[3] << "]";
|
||||||
|
it = vecRet.erase(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//补连塔的相机比较近,间隔基本在画面底部,因此当间隔比较靠画面上时过滤掉。
|
//补连塔的相机比较近,间隔基本在画面底部,因此当间隔比较靠画面上时过滤掉。
|
||||||
if ((it->class_id >= 9 && it->class_id <= 17 && it->class_id != 15) || it->class_id == U_TRAIN_SPACE)
|
if ((it->class_id >= 9 && it->class_id <= 17 && it->class_id != 15) || it->class_id == U_TRAIN_SPACE)
|
||||||
{
|
{
|
||||||
|
|
@ -484,10 +500,10 @@ APP_ERROR TrainStepOneEngine::Process()
|
||||||
SetTargetType(postSubData);
|
SetTargetType(postSubData);
|
||||||
pPostData->vecPostSubData.emplace_back(postSubData);
|
pPostData->vecPostSubData.emplace_back(postSubData);
|
||||||
|
|
||||||
// LogDebug << "数据源:" << pProcessData->iDataSource << " 帧:" << pProcessData->iFrameId
|
LogDebug << "数据源:" << pProcessData->iDataSource << " 帧:" << pProcessData->iFrameId
|
||||||
// << " --iClassId:" << singledata.iClassId << " iLine:" << singledata.iLine << " confidence=" << singledata.fScore
|
<< " --iClassId:" << singledata.iClassId << " iLine:" << singledata.iLine << " confidence=" << singledata.fScore
|
||||||
// << " lx=" << singledata.fLTX << " ly=" << singledata.fLTY << " rx=" << singledata.fRBX << " ry=" << singledata.fRBY
|
<< " lx=" << singledata.fLTX << " ly=" << singledata.fLTY << " rx=" << singledata.fRBX << " ry=" << singledata.fRBY
|
||||||
// << " clear:" << singledata.fClear;
|
<< " clear:" << singledata.fClear;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -113,8 +113,8 @@ void Inference::doInference(IExecutionContext& context, cudaStream_t& stream, vo
|
||||||
|
|
||||||
void Inference::doInferenceV2(IExecutionContext& context, cudaStream_t& stream, void **buffers, unsigned int outputIndex, float* output, int outputSize, int batchSize)
|
void Inference::doInferenceV2(IExecutionContext& context, cudaStream_t& stream, void **buffers, unsigned int outputIndex, float* output, int outputSize, int batchSize)
|
||||||
{
|
{
|
||||||
context.enqueue(batchSize, buffers, stream, nullptr);
|
// context.enqueue(batchSize, buffers, stream, nullptr);
|
||||||
//context.enqueueV2(buffers, stream, nullptr);
|
context.enqueueV2(buffers, stream, nullptr);
|
||||||
CUDA_CHECK(cudaMemcpyAsync(output, buffers[outputIndex], batchSize * outputSize * sizeof(float), cudaMemcpyDeviceToHost, stream));
|
CUDA_CHECK(cudaMemcpyAsync(output, buffers[outputIndex], batchSize * outputSize * sizeof(float), cudaMemcpyDeviceToHost, stream));
|
||||||
cudaStreamSynchronize(stream);
|
cudaStreamSynchronize(stream);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue