Blame view

check_tool/FFCuContextManager.cpp 757 Bytes
7e9074f2   Hu Chunming   添加check_tool
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
  #include "FFCuContextManager.h"
  #include <iostream>
  
  using namespace std;
  
  FFCuContextManager::~FFCuContextManager()
  {
      for(auto iter = ctxMap.begin(); iter != ctxMap.end(); iter++){
          av_buffer_unref(&iter->second);
      }
      ctxMap.clear();
  }
  
  AVBufferRef *FFCuContextManager::getCuCtx(string gpuid)
  {
       AVBufferRef *hw_device_ctx = ctxMap[gpuid];
       if (nullptr == hw_device_ctx)
       {
          // 初始化硬件解码器
          if (av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_CUDA, gpuid.c_str(), nullptr, 0) < 0) 
          {
              av_log(nullptr, AV_LOG_ERROR, "Failed to create specified HW device ! \n");
              return nullptr;
          }
          ctxMap[gpuid] = hw_device_ctx;
       }
       return hw_device_ctx;
  }