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