FFCuContextManager.cpp
741 Bytes
#include "FFCuContextManager.h"
#include "common_header.h"
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)
{
LOG_ERROR("Failed to create specified HW device.");
return nullptr;
}
ctxMap[gpuid] = hw_device_ctx;
}
return hw_device_ctx;
}