FFCuContextManager.cpp
1.01 KB
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
#include "FFCuContextManager.h"
#include "common_header.h"
using namespace std;
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#include <libavfilter/avfilter.h>
#include <libavutil/avutil.h>
#include <libavutil/pixdesc.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}
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;
}