#include "DvppSourceManager.h" #include "dvpp_headers.h" #include "depend_headers.h" using namespace std; DvppSourceManager::~DvppSourceManager() { for(auto iter = ctxMap.begin(); iter != ctxMap.end(); iter++){ aclError ret = aclrtDestroyContext(iter->second); if(ret != ACL_ERROR_NONE){ LOG_ERROR("aclrtDestroyContext failed !"); continue; } } ctxMap.clear(); channelMap.clear(); aclFinalize(); } aclrtContext DvppSourceManager::getContext(int devId) { aclrtContext ctx = ctxMap[devId]; if (ctx == nullptr) { // 初始化硬件解码器 aclError ret = aclrtSetDevice(devId); if(ret != ACL_ERROR_NONE){ // cout << "aclrtSetDevice failed" << endl; LOG_ERROR("aclrtSetDevice failed !"); return nullptr; } ret = aclrtCreateContext(&ctx, devId); if (ret != ACL_ERROR_NONE) { // cout << "aclrtCreateContext failed " << endl; LOG_ERROR("aclrtCreateContext failed !"); return nullptr; } ctxMap[devId] = ctx; } return ctx; } int DvppSourceManager::getChannel(int devId){ // channel 最大值暂定为32, 华为没有接口获取最大channel,只有文档说明 for(int iChannel = 0; iChannel < 32; iChannel++){ string channelKey = "channel_" + to_string(devId) + "_" + to_string(iChannel) ; auto it = channelMap.find(channelKey); if(it == channelMap.end()){ channelMap[channelKey] = iChannel; return iChannel; } } return -1; } void DvppSourceManager::releaseChannel(int devId, int iChannel){ string channelKey = "channel_" + to_string(devId) + "_" + to_string(iChannel) ; channelMap.erase(channelKey); }