//
|
// Created by basic on 18-8-22.
|
//
|
|
#ifndef VIDEOANALYSFROMHC_BAISCSDKANALYSVIDEO_H
|
#define VIDEOANALYSFROMHC_BAISCSDKANALYSVIDEO_H
|
|
#include "myThread.h"
|
#include <vector>
|
#include <basic/io/io.h>
|
#include <basic/debug/Debug.h>
|
#include <basic/util/file/FileUtil.h>
|
#include "../StructureApp/AppPipeController.h"
|
#include "dispathdatatype.hpp"
|
|
#include <basic/util/app/AppPreference.hpp>
|
#include <basic/http_server/HttpSrvRetRecieve.hpp>
|
#include <basic/util/net_config/net_config.h>
|
#include "DBStruct.h"
|
#define SETSCORE(VEC, POS, IDENT) appPref.setFloatData(IDENT, POS >= VEC.size() ? 80 : VEC[POS]);
|
|
class BaiscSDKAnalysVideo : public mythread<getsdkHdlManage> {
|
using TASK_FUNCTION = std::function<void(std::shared_ptr<finishSdkHdlManage> &, int)>;
|
public:
|
BaiscSDKAnalysVideo(TASK_FUNCTION task_f = nullptr) : m_task_function(task_f) {
|
resetFdfs();
|
{
|
std::thread httpServer([&]() {
|
HttpSrvRetRecieve httpSrvRetRecieve("0.0.0.0", 9090, 1);
|
httpSrvRetRecieve.setInfo("^/resetFdfs$", "POST", std::bind(&BaiscSDKAnalysVideo::resetFdfs, this,
|
std::placeholders::_1,
|
std::placeholders::_2,
|
std::placeholders::_3));
|
httpSrvRetRecieve.start();
|
httpSrvRetRecieve.waitForShutDown();
|
});
|
httpServer.detach();
|
}
|
}
|
|
~BaiscSDKAnalysVideo() {
|
}
|
|
std::string resetFdfs(std::string ip = "", unsigned int port = 0, std::string content = "") {
|
|
std::thread reset([&]() {
|
fdfsClient.rwLock.rdlock();
|
if (fdfsClient.fastFds != nullptr) {
|
delete fdfsClient.fastFds;
|
}
|
fdfsClient.fastFds = new FastFds("fastDfsClient.conf");
|
fdfsClient.rwLock.unlock();
|
});
|
reset.detach();
|
|
return "";
|
}
|
|
private:
|
virtual void doFunc(std::shared_ptr<getsdkHdlManage> spPacket) {
|
|
// DBG("do func sdk");
|
// Json::Value json;
|
|
//split sdks enable
|
//#todo other sdk
|
vector<int> sdkVec = chnString2Vec(spPacket->en_sdk);
|
//设置检测得分
|
// std::string s_d = str_det_thr;
|
// std::string s_c = str_cmp_thr;
|
vector<int> sdkDetCoVec = chnString2Vec(spPacket->str_det_thr);
|
vector<int> sdkComCoVec = chnString2Vec(spPacket->str_cmp_thr);
|
SdkRuleMap ruleMap;
|
int t_size = sdkVec.size();
|
std::string str_pre(spPacket->strDevID);
|
str_pre.append(to_string(spPacket->nChannelID));
|
for (int i = 0; i < t_size; i++) {
|
switch (sdkVec[i]) {
|
case FaceSdk: {
|
// json["face.enable"] = "1";
|
|
DBG("" << str_pre);
|
|
DBG(" TESTCODE setValue" << str_pre << " " << sdkDetCoVec[i] << " " << sdkComCoVec[i]);
|
// SETSCORE(sdkDetCoVec, i, str_pre + "face.det");
|
// SETSCORE(sdkComCoVec, i, str_pre + "face.cmp");
|
SdkRule rule;
|
rule.nIsRun=1;
|
rule.nQuality=sdkDetCoVec[i];
|
rule.nThreshold=sdkComCoVec[i];
|
rule.strAddr=spPacket->str_addr.c_str();
|
ruleMap[FaceSdk]=rule;
|
break;
|
}
|
case CarSdk: {
|
// DBG("XX.enable " << "1");
|
DBG(" TESTCODE setValue" << str_pre << " " << sdkDetCoVec[i] << " " << sdkComCoVec[i]);
|
// SETSCORE(sdkDetCoVec, i, str_pre + "XX.det");
|
// SETSCORE(sdkComCoVec, i, str_pre + "XX.cmp");
|
SdkRule rule;
|
rule.nIsRun=1;
|
rule.nQuality=sdkDetCoVec[i];
|
rule.nThreshold=sdkComCoVec[i];
|
rule.strAddr=spPacket->str_addr.c_str();
|
ruleMap[CarSdk]=rule;
|
break;
|
}
|
case YoloSdk: {
|
// json["yolo.enable"] = "1";
|
DBG(" TESTCODE setValue" << str_pre << " " << sdkDetCoVec[i] << " " << sdkComCoVec[i]);
|
// SETSCORE(sdkDetCoVec, i, str_pre + "yolo.det");
|
// SETSCORE(sdkComCoVec, i, str_pre + "yolo.cmp");
|
SdkRule rule;
|
rule.nIsRun=1;
|
rule.nQuality=sdkDetCoVec[i];
|
rule.nThreshold=sdkComCoVec[i];
|
rule.strAddr=spPacket->str_addr.c_str();
|
ruleMap[YoloSdk]=rule;
|
break;
|
}
|
}
|
}
|
// json["addr"] = spPacket->str_addr;
|
INFO("cam add is " << spPacket->str_addr);
|
|
//#todo get address
|
|
AppPipeController _AppPipeController(spPacket->src_path, ruleMap);
|
_AppPipeController.setfdfsClient(&fdfsClient);
|
//#todo from path get file list
|
file_filter_type filter = [](const char *dirName, const char *dirent) {
|
return (strstr(dirent, ".mp4") != nullptr);// add format
|
};
|
std::vector<std::string> vec = for_each_file(spPacket->src_path, filter);
|
auto size = vec.size();
|
int pos = spPacket->pos;
|
if (size == 0 || spPacket->total == 0) {
|
if (m_task_function != nullptr) {
|
auto fp_task(
|
std::make_shared<finishSdkHdlManage>(
|
finishSdkHdlManage{spPacket->src_path, 0}));
|
m_task_function(fp_task, 0);
|
return;
|
} else {
|
ERR("m_task_function == nullptr");
|
return;
|
}
|
}
|
for (; pos < size;) {
|
//#todo
|
_AppPipeController.resetVideoCapturePath(vec[pos]);
|
_AppPipeController.start();
|
while (_AppPipeController.getRunning()) {
|
usleep(40000);
|
}
|
_AppPipeController.stop();
|
_AppPipeController.wait();
|
if (m_task_function != nullptr) {
|
auto fp_task(
|
std::make_shared<finishSdkHdlManage>(
|
finishSdkHdlManage{spPacket->src_path, pos}));
|
m_task_function(fp_task, size - pos - 1);
|
} else {
|
ERR("m_task_function == nullptr");
|
return;
|
}
|
pos++;
|
}
|
_AppPipeController;
|
}
|
|
private:
|
TASK_FUNCTION m_task_function;
|
FastFdsWithLock fdfsClient;
|
};
|
|
|
#endif //VIDEOANALYSFROMHC_BAISCSDKANALYSVIDEO_H
|