Blame view

src/dvpp/DvppSourceManager.cpp 1.77 KB
63e6f7bc   Hu Chunming   完成dvpp。但是nv和gb281...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  #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);
  }