88 lines
2.1 KiB
C++
88 lines
2.1 KiB
C++
/*
|
|
* @Date: 2024-09-04 18:57:40
|
|
* @LastEditors: Jacky
|
|
* @LastEditTime: 2024-09-18 17:31:57
|
|
* @FilePath: /GeneralTracker/Universal/CModuleArith.cpp
|
|
*/
|
|
#include "CModuleArith.h"
|
|
#include "ArithDetect.h"
|
|
#include "ArithTracker.h"
|
|
|
|
int CModuleArith::create(const char* name){
|
|
m_pcName = std::string(name);
|
|
m_pSelfQueue.queueInit(m_pcName, QUEUE_SIZE);
|
|
|
|
//用名字区分算法类型
|
|
if(m_pcName.find("track") != std::string::npos){
|
|
_arith_instance = new ArithTracker();
|
|
_is_track = true;
|
|
}else if(m_pcName.find("detect") != std::string::npos){
|
|
_arith_instance = new ArithDetect();
|
|
}
|
|
|
|
if(_arith_instance){
|
|
_arith_instance->arithInit(1280, 1024, GD_PIXEL_FORMAT_NV12);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int CModuleArith::destroy(){
|
|
stop();
|
|
return 0;
|
|
}
|
|
|
|
int CModuleArith::set_data(const char* data, void* value){
|
|
if(_arith_instance){
|
|
_arith_instance->msgProcess(data);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
char* CModuleArith::get_data(){
|
|
return nullptr;
|
|
}
|
|
|
|
int CModuleArith::start(const char* data){
|
|
if(_vi_thread){
|
|
return -1;
|
|
}
|
|
|
|
_thread_flag = true;
|
|
_vi_thread = new std::thread(std::bind(&CModuleArith::moduleThread, std::ref(*this)));
|
|
return 0;
|
|
}
|
|
int CModuleArith::stop(){
|
|
if(_vi_thread){
|
|
_thread_flag = false;
|
|
_vi_thread->join();
|
|
delete _vi_thread;
|
|
_vi_thread = nullptr;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void CModuleArith::push_data(DataProcessBase *src, pool::IMemoryBlock* block){
|
|
m_pSelfQueue.sendFrame(block);
|
|
}
|
|
|
|
int CModuleArith::moduleThread(){
|
|
int timeout = 100;
|
|
while(_thread_flag){
|
|
pool::IMemoryBlock* mb = m_pSelfQueue.getFrame(timeout);
|
|
if(mb){
|
|
AdditionalImp* imp = mb->data();
|
|
GD_VIDEO_FRAME_S *frame = imp->data<GD_VIDEO_FRAME_S*>("YUV");
|
|
|
|
//算法接口
|
|
_arith_instance->arithRun(imp);
|
|
|
|
if(_is_track){
|
|
//跟踪算法作为主框架的一部分,需要进行数据流转
|
|
push_input_pipe(mb);
|
|
}
|
|
m_pSelfQueue.releaseFrame(mb);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|