派生自 development/c++

pansen
2019-02-22 9186da86847cf954341d1bf58b0c4079a3ab5ac5
回滚改bug。
6个文件已修改
483 ■■■■ 已修改文件
QiaoJiaSystem/CMakeLists.txt 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QiaoJiaSystem/StructureApp/AppPipeController.h 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QiaoJiaSystem/StructureApp/HiredisTool.cpp 426 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QiaoJiaSystem/StructureApp/HiredisTool.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QiaoJiaSystem/VideoAnalysFromHC/CMakeLists.txt 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
QiaoJiaSystem/VideoToImageMulth/CMakeLists.txt 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
QiaoJiaSystem/CMakeLists.txt
@@ -16,16 +16,16 @@
    ../../BasicPlatForm/libs/libuuid/include
)
add_subdirectory(StructureApp)
#add_subdirectory(StructureApp)
add_subdirectory(FaceDetectServer)
add_subdirectory(YoloServer)
add_subdirectory(FaceSearchServer)
add_subdirectory(VideoAnalysFromHC)
#add_subdirectory(RapidStructureApp)
add_subdirectory(RecordVideo)
#add_subdirectory(RecordVideo)
add_subdirectory(DataManagerServer)
add_subdirectory(EncodeServer)
add_subdirectory(VideoToImage)
#add_subdirectory(EncodeServer)
#add_subdirectory(VideoToImage)
add_subdirectory(UnitTest)
add_subdirectory(VideoToImageMulth)
#add_subdirectory(FaceSearchDbWithImg)
QiaoJiaSystem/StructureApp/AppPipeController.h
@@ -20,6 +20,22 @@
#include <jsoncpp/json/json.h>
#include "DBStruct.h"
#include "SaveVideoRpc.h"
class VideoCaptureElementNotDecoder : public ffmpeg::VideoCaptureElement {
    using ffmpeg::VideoCaptureElement::VideoCaptureElement;
private:
    virtual void timerFunc() override {
        fireConnectors();
    }
    virtual void threadInitial() override {}
    virtual void threadClosing() override {}
private:
    bool m_decoderRet = {false};
};
class AppPipeController : public PipeController {
public:
    /***
@@ -27,14 +43,14 @@
     * @param folderPath 任务根目录,用于做共享内存id
     * @param json 参数为rtsp流地址 sdk是否启用的标识
     */
  //  AppPipeController(std::string folderPath, const Json::Value &json);
    AppPipeController(std::string folderPath, const SdkRuleMap& ruleMap);
    //  AppPipeController(std::string folderPath, const Json::Value &json);
    AppPipeController(std::string folderPath, const SdkRuleMap &ruleMap);
  //  AppPipeController(int index, const Json::Value &json, bool RecordVideoEnable = false);
    //  AppPipeController(int index, const Json::Value &json, bool RecordVideoEnable = false);
  //  AppPipeController(std::string camId, const Json::Value &json, bool RecordVideoEnable);
    //  AppPipeController(std::string camId, const Json::Value &json, bool RecordVideoEnable);
    AppPipeController(std::string camId, const SdkRuleMap& ruleMap, bool RecordVideoEnable);
    AppPipeController(std::string camId, const SdkRuleMap &ruleMap, bool RecordVideoEnable);
    virtual ~AppPipeController();
@@ -46,12 +62,14 @@
    void setfdfsClient(FastFdsWithLock *p_fdfsClient);
    void setWeekRule(const std::map<int, std::vector<LActRuleWeekRecord>>& weekRuleMap);
    void setWeekRule(const std::map<int, std::vector<LActRuleWeekRecord>> &weekRuleMap);
private:
    void init();
private://Perimete
    PerimeterElement perimeterElement;
   // TriggerElement peTriggerElement;
    // TriggerElement peTriggerElement;
    void initPerimeter();
@@ -60,7 +78,9 @@
    //TriggerElement crowdTriggerElement;
    void initCrowd();
    void RecordVideo();
private://KeepRight
    JudgmentRetrogradeTool leftJudgment;
    JudgmentRetrogradeTool rightJudgment;
@@ -72,15 +92,19 @@
private:
    PerStaticElement perStaticElement;
    void initPerStatic();
private://Perimete
    PerimeterElement perHubElement;
   // TriggerElement peTriggerElement;
    // TriggerElement peTriggerElement;
    void initPerHub();
private:
    SaveVideoRpcClient_t m_rpcClient;
    ffmpeg::VideoCaptureElement videoCaptureElement;
    VideoCaptureElementNotDecoder videoCaptureElement;
//    ffmpeg::VideoCaptureElement videoCaptureElement;
    YoloRpcElement yoloRpcElement;
    FaceRpcElement faceRpcElement;
    FaceExtractElement faceExtractElement;
@@ -109,7 +133,9 @@
    std::map<int, std::vector<LActRuleWeekRecord>> m_weekRuleMap;
    SdkRuleMap m_sdkRuleMap;
    std::string m_localIp;
    std::string getFullFileName();
    std::mutex mutex;
    bool m_bSetWH;
    HiredisTool m_hiredisTool;
QiaoJiaSystem/StructureApp/HiredisTool.cpp
@@ -4,42 +4,38 @@
#include <jsoncpp/json/json.h>
#include <basic/debug/Debug.h>
#include <basic/util/app/AppConfig.h>
HiredisTool::HiredisTool():
m_redis(nullptr),
m_nImgListLen(0)
{
HiredisTool::HiredisTool() :
    m_redis(nullptr),
    m_nImgListLen(0) {
    init();
}
HiredisTool::~HiredisTool()
{
    if(m_redis != nullptr)
    {
HiredisTool::~HiredisTool() {
    if (m_redis != nullptr) {
        redisFree(m_redis);//析构函数释放资源
        DBG("~RedisTool :: free redis connection ") ;
        DBG("~RedisTool :: free redis connection ");
    }
}
void HiredisTool::init()
{
       struct timeval timeout = { 1, 500000 }; // 1.5 seconds 设置连接等待时间
void HiredisTool::init() {
    struct timeval timeout = {1, 500000}; // 1.5 seconds 设置连接等待时间
     //  m_nImgListLen=appConfig.getIntProperty("redis_buf_len");
       std::string ip=appConfig.getStringProperty("redis_ip");
    //  m_nImgListLen=appConfig.getIntProperty("redis_buf_len");
    std::string ip = appConfig.getStringProperty("redis_ip");
        int port=appConfig.getIntProperty("redis_port");
        m_redis = redisConnectWithTimeout(ip.c_str(), port, timeout);//建立连接
        if (m_redis->err) {
    int port = appConfig.getIntProperty("redis_port");
    m_redis = redisConnectWithTimeout(ip.c_str(), port, timeout);//建立连接
    if (m_redis->err) {
            DBG("RedisTool : Connection error: %s"<< m_redis->errstr);
            redisFree(m_redis);
            m_redis= nullptr;
        }
        else
        {
                DBG( "init redis tool success " );
        DBG("RedisTool : Connection error: %s" << m_redis->errstr);
        redisFree(m_redis);
        m_redis = nullptr;
    } else {
        DBG("init redis tool success ");
        }
    }
}
@@ -81,42 +77,41 @@
bool HiredisTool::pushImageBuf(const std::string& file_name,const cv::Mat& img)
{
       std::vector<uchar> buf;
      Json::Value json;
      CvUtil::cvMat2Buffer(img,buf);
//      json["time"]=info.time;
      json["img"]=std::string(buf.begin(),buf.end());
  //    buf.clear();
      std::string strBuf=std::string(buf.begin(),buf.end());
      if(!listLpush(file_name,json.toStyledString()));
      {
          return false;
      }
      //DBG(json.toStyledString());
      return true;
}
bool HiredisTool::setKeyImage(const std::string &file_name, const cv::Mat &img)
{
bool HiredisTool::pushImageBuf(const std::string &file_name, const cv::Mat &img) {
    std::vector<uchar> buf;
    Json::Value json;
    CvUtil::cvMat2Buffer(img,buf);
    CvUtil::cvMat2Buffer(img, buf);
//      json["time"]=info.time;
    json["img"]=std::string(buf.begin(),buf.end());
    json["img"] = std::string(buf.begin(), buf.end());
    //    buf.clear();
    std::string strBuf = std::string(buf.begin(), buf.end());
    if (!listLpush(file_name, json.toStyledString()));
    {
        return false;
    }
    //DBG(json.toStyledString());
    return true;
}
bool HiredisTool::setKeyImage(const std::string &file_name, const cv::Mat &img) {
    std::vector<uchar> buf;
    Json::Value json;
    CvUtil::cvMat2Buffer(img, buf);
//      json["time"]=info.time;
    json["img"] = std::move(m_base64.Encode(buf.data(), buf.size()));
//    json["img"] = std::string(buf.begin(), buf.end());
    //    buf.clear();
//    std::string strBuf=std::string(buf.begin(),buf.end());
    if(!setKeyValue(file_name,json.toStyledString()));
    if (!setKeyValue(file_name, json.toStyledString()));
    {
        return false;
@@ -128,62 +123,59 @@
}
void  HiredisTool::getImage(const std::string& file_name, cv::Mat& img)
{
void HiredisTool::getImage(const std::string &file_name, cv::Mat &img) {
        std::string content;
        cv::Mat imgTep;
        listRpop(file_name,content);
        Json::Reader reader;
        Json::Value value;
        if(!reader.parse(content,value))
        {
           return ;
        }
        std::string str=value["img"].asString();
        std::vector<uchar> data;
        data.resize(str.size());
        data.assign(str.begin(),str.end());
        CvUtil::buffer2CvMat(data,imgTep);
        imgTep.copyTo(img);
    // return img;
}
void HiredisTool::getKeyImage(const std::string &imageName, cv::Mat &img)
{
    std::string content;
    cv::Mat imgTep;
    getKeyValue(imageName,content);
    listRpop(file_name, content);
    Json::Reader reader;
    Json::Value value;
    if(!reader.parse(content,value))
    {
        return ;
    if (!reader.parse(content, value)) {
        return;
    }
    std::string str=value["img"].asString();
    std::string str = value["img"].asString();
    std::vector<uchar> data;
    data.resize(str.size());
    data.assign(str.begin(),str.end());
    data.assign(str.begin(), str.end());
    CvUtil::buffer2CvMat(data,imgTep);
    CvUtil::buffer2CvMat(data, imgTep);
    imgTep.copyTo(img);
    // return img;
}
void HiredisTool::getKeyImage(const std::string &imageName, cv::Mat &img) {
    std::string content;
    cv::Mat imgTep;
    getKeyValue(imageName, content);
    Json::Reader reader;
    Json::Value value;
    if (!reader.parse(content, value)) {
        return;
    }
    std::string str = value["img"].asString();
    str = std::move(m_base64.Decode(str.c_str(), str.size()));
    std::vector<uchar> data;
    data.resize(str.size());
    data.assign(str.begin(), str.end());
    CvUtil::buffer2CvMat(data, imgTep);
    imgTep.copyTo(img);
    // return img;
@@ -195,25 +187,22 @@
//    DBG("type="<<type);
//    return hashSet(file_list,cam_id,type);
//}
bool HiredisTool::clearAllImageBuf()
{
bool HiredisTool::clearAllImageBuf() {
//    auto cam_map=findAllCamera();
//    for(auto cam:cam_map)
//    {
//        delKey(cam.first);
//    }
}
bool HiredisTool::listLpush(const std::string& key,const std::string& value)
{
    if(!checkParam())
    {
bool HiredisTool::listLpush(const std::string &key, const std::string &value) {
    if (!checkParam()) {
        return false;
    }
    redisReply *reply;
    reply = (redisReply*)redisCommand(m_redis,"lpush %s %s", key.c_str(),value.c_str());
    if(!checkResult(reply))
    {
    reply = (redisReply *) redisCommand(m_redis, "lpush %s %s", key.c_str(), value.c_str());
    if (!checkResult(reply)) {
        return false;
    }
@@ -222,17 +211,14 @@
    return true;
}
bool HiredisTool::setKeyValue(const std::string &key, const std::string &value)
{
    if(!checkParam())
    {
bool HiredisTool::setKeyValue(const std::string &key, const std::string &value) {
    if (!checkParam()) {
        return false;
    }
    redisReply *reply;
    reply = (redisReply*)redisCommand(m_redis,"set %s %s", key.c_str(),value.c_str());
    if(!checkResult(reply))
    {
    reply = (redisReply *) redisCommand(m_redis, "set %s %s", key.c_str(), value.c_str());
    if (!checkResult(reply)) {
        return false;
    }
@@ -241,64 +227,54 @@
    return true;
}
bool HiredisTool::getKeyValue(const std::string &key, std::string &value)
{
    if(!checkParam())
    {
bool HiredisTool::getKeyValue(const std::string &key, std::string &value) {
    if (!checkParam()) {
        return false;
    }
    redisReply *reply;
    //1.find all filename
    reply = (redisReply*)redisCommand(m_redis,"get %s  ", key.c_str());
    reply = (redisReply *) redisCommand(m_redis, "get %s  ", key.c_str());
    if(!checkResult(reply))
    {
    if (!checkResult(reply)) {
        return false;
    }
    if(reply->type == REDIS_REPLY_STRING)
    {
        value=reply->str;
    if (reply->type == REDIS_REPLY_STRING) {
        value = reply->str;
    }
    freeReplyObject(reply);
    return true;
}
bool HiredisTool::listRpop(const std::string& key,std::string& value)
{
    if(!checkParam())
    {
bool HiredisTool::listRpop(const std::string &key, std::string &value) {
    if (!checkParam()) {
        return false;
    }
    redisReply *reply;
    //1.find all filename
    reply = (redisReply*)redisCommand(m_redis,"rpop %s  ", key.c_str());
    reply = (redisReply *) redisCommand(m_redis, "rpop %s  ", key.c_str());
    if(!checkResult(reply))
    {
    if (!checkResult(reply)) {
        return false;
    }
    if(reply->type == REDIS_REPLY_STRING)
    {
        value=reply->str;
    if (reply->type == REDIS_REPLY_STRING) {
        value = reply->str;
    }
    freeReplyObject(reply);
    return true;
}
bool HiredisTool::hashSet(const std::string& tab,const std::string& key,const int& value)
{
    if(!checkParam())
    {
bool HiredisTool::hashSet(const std::string &tab, const std::string &key, const int &value) {
    if (!checkParam()) {
        return false;
    }
    redisReply *reply;
    reply = (redisReply*)redisCommand(m_redis,"hset %s %s %d", tab.c_str(),key.c_str(),value);
    reply = (redisReply *) redisCommand(m_redis, "hset %s %s %d", tab.c_str(), key.c_str(), value);
    if(!checkResult(reply))
    {
    if (!checkResult(reply)) {
        return false;
    }
    freeReplyObject(reply);
@@ -307,176 +283,154 @@
    return true;
}
int  HiredisTool::getSize(const std::string& key)
{
    int size=0;
    if(!checkParam())
    {
int HiredisTool::getSize(const std::string &key) {
    int size = 0;
    if (!checkParam()) {
        return size;
    }
    redisReply *reply;
    reply = (redisReply*)redisCommand(m_redis,"llen %s", key.c_str());
    reply = (redisReply *) redisCommand(m_redis, "llen %s", key.c_str());
    if(!checkResult(reply))
    {
    if (!checkResult(reply)) {
        return size;
    }
    size=reply->integer;
    size = reply->integer;
    freeReplyObject(reply);
    return size;
}
bool HiredisTool::listLindex(const std::string& key,std::string& value)
{
    int size=0;
    if(!checkParam())
    {
bool HiredisTool::listLindex(const std::string &key, std::string &value) {
    int size = 0;
    if (!checkParam()) {
        return size;
    }
    redisReply *reply;
    reply = (redisReply*)redisCommand(m_redis,"lindex %s -1", key.c_str());
    reply = (redisReply *) redisCommand(m_redis, "lindex %s -1", key.c_str());
    if(!checkResult(reply))
    {
    if (!checkResult(reply)) {
        return false;
    }
    if(reply->type == REDIS_REPLY_STRING)
    {
        value=reply->str;
    if (reply->type == REDIS_REPLY_STRING) {
        value = reply->str;
    }
    freeReplyObject(reply);
}
bool HiredisTool::delKey(const std::string& key)
{
    if(!checkParam())
    {
bool HiredisTool::delKey(const std::string &key) {
    if (!checkParam()) {
        return false;
    }
    redisReply *reply;
    reply = (redisReply*)redisCommand(m_redis,"del %s", key.c_str());
    reply = (redisReply *) redisCommand(m_redis, "del %s", key.c_str());
    if(!checkResult(reply))
    {
    if (!checkResult(reply)) {
        return false;
    }
    freeReplyObject(reply);
    return true;
}
bool HiredisTool::checkParam()
{
     if(m_redis == nullptr || m_redis->err)
     {
         if(m_redis)
         {
             redisFree(m_redis);
             m_redis= nullptr;
         }
         DBG("Redis init Error !!!");
         init();
         return false;
     }
     return true;
bool HiredisTool::checkParam() {
    if (m_redis == nullptr || m_redis->err) {
        if (m_redis) {
            redisFree(m_redis);
            m_redis = nullptr;
        }
        DBG("Redis init Error !!!");
        init();
        return false;
    }
    return true;
}
bool HiredisTool::checkResult(redisReply *reply)
{
    if (reply==nullptr)
    {
         DBG("reply nullptr !!!");
         return false;
bool HiredisTool::checkResult(redisReply *reply) {
    if (reply == nullptr) {
        DBG("reply nullptr !!!");
        return false;
    }
    if (reply->type == REDIS_REPLY_ERROR)
    {
        ERR("redisCommand Error: "<<reply->str);
    if (reply->type == REDIS_REPLY_ERROR) {
        ERR("redisCommand Error: " << reply->str);
        freeReplyObject(reply);
        return false;
    }
    return true;
}
void HiredisTool::addFileInfo(const std::string& filename,const int& file_status)
{
      hashSet(file_list,filename,file_status);
 }
std::queue<cv::Mat> HiredisTool::getImgQue(const std::string& filename)
{
void HiredisTool::addFileInfo(const std::string &filename, const int &file_status) {
    hashSet(file_list, filename, file_status);
}
std::queue<cv::Mat> HiredisTool::getImgQue(const std::string &filename) {
    std::queue<cv::Mat> que;
    if(!checkParam())
    {
    if (!checkParam()) {
        return que;
    }
    redisReply *reply;
    reply = (redisReply*)redisCommand(m_redis,"lrange %s 0 -1", filename.c_str());
    reply = (redisReply *) redisCommand(m_redis, "lrange %s 0 -1", filename.c_str());
    if(!checkResult(reply))
    {
    if (!checkResult(reply)) {
        return que;
    }
    if(reply->type == REDIS_REPLY_ARRAY)
    {
        for(int i=0;i<reply->elements;++i)
        {
            std::string str=reply->element[i]->str;
    if (reply->type == REDIS_REPLY_ARRAY) {
        for (int i = 0; i < reply->elements; ++i) {
            std::string str = reply->element[i]->str;
            std::vector<uchar> data;
            cv::Mat img;
            data.resize(str.size());
            data.assign(str.begin(),str.end());
            CvUtil::buffer2CvMat(data,img);
            data.assign(str.begin(), str.end());
            CvUtil::buffer2CvMat(data, img);
            que.push(img);
        }
    }
    freeReplyObject(reply);
}
std::map<std::string,int> HiredisTool::findAllFileStatus()
{
     std::map<std::string,int> fileMap;
     if(!checkParam())
     {
         return fileMap;
     }
     redisReply *reply;
std::map<std::string, int> HiredisTool::findAllFileStatus() {
    std::map<std::string, int> fileMap;
    if (!checkParam()) {
        return fileMap;
    }
     reply = (redisReply*)redisCommand(m_redis,"hgetall %s", file_list);
    redisReply *reply;
     if(!checkResult(reply))
     {
         return fileMap;
     }
    reply = (redisReply *) redisCommand(m_redis, "hgetall %s", file_list);
     if(reply->type == REDIS_REPLY_ARRAY)
     {
    if (!checkResult(reply)) {
        return fileMap;
    }
         for (int i= 0; i < reply->elements; i+=2)
         {
             std::string key=reply->element[i]->str;
             std::string value=reply->element[i+1]->str;
    if (reply->type == REDIS_REPLY_ARRAY) {
             if(key.empty()||value.empty()) continue;
        for (int i = 0; i < reply->elements; i += 2) {
            std::string key = reply->element[i]->str;
            std::string value = reply->element[i + 1]->str;
             fileMap.insert(std::pair<std::string,int>(key,atoi(value.c_str())));
         }
     }
     freeReplyObject(reply);
     return fileMap;
            if (key.empty() || value.empty()) continue;
            fileMap.insert(std::pair<std::string, int>(key, atoi(value.c_str())));
        }
    }
    freeReplyObject(reply);
    return fileMap;
}
bool HiredisTool::hashDel(const std::string& tab,const std::string &key)
{
    if(!checkParam())
    {
bool HiredisTool::hashDel(const std::string &tab, const std::string &key) {
    if (!checkParam()) {
        return false;
    }
    redisReply *reply;
    reply = (redisReply*)redisCommand(m_redis,"hdel %s %s", tab.c_str(),key.c_str());
    reply = (redisReply *) redisCommand(m_redis, "hdel %s %s", tab.c_str(), key.c_str());
    if(!checkResult(reply))
    {
    if (!checkResult(reply)) {
        return false;
    }
    freeReplyObject(reply);
QiaoJiaSystem/StructureApp/HiredisTool.h
@@ -2,6 +2,7 @@
#define HIREDISTOOL_H
#include <opencv/cv.h>
//#include <hiredis.h>
#include <basic/util/BASE64/Base64.h>
#include "../../BasicPlatForm/libs/hiredis-master/include/hiredis.h"
#include <map>
#include <queue>
@@ -57,6 +58,7 @@
private:
    redisContext *m_redis;
    int m_nImgListLen;
    Base64 m_base64;
};
QiaoJiaSystem/VideoAnalysFromHC/CMakeLists.txt
@@ -57,7 +57,7 @@
    ../StructureApp/NewEncodeVideoManager.cpp
    ../StructureApp/NewEncodeVideo.cpp
    ../StructureApp/HiredisTool.cpp
     ../StructureApp/PersonElement.cpp
    ../StructureApp/PersonElement.cpp
    ../StructureApp/PerStaticElement.cpp
    ../StructureApp/IntAreaCalcUtil.cpp
QiaoJiaSystem/VideoToImageMulth/CMakeLists.txt
@@ -84,6 +84,7 @@
add_executable(${PROJECT_NAME}
      ../../../BasicPlatForm/basic/pipe_element/ffmpeg/VideoChangeScore.cpp
    ../../../BasicPlatForm/basic/util/BASE64/Base64.cpp
#       ../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp
       ../VideoServer/QiaoJia/DB/LDBTool.cpp
       ./rpc/RtspAnalysServer.cpp