#include "FFCuContextManager.h" #include 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; }