video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-11-17 e3d02acd52ca4604b17b73d0aea3bb9097876f39
update
3个文件已修改
34 ■■■■■ 已修改文件
csrc/common/gpu/info.cpp 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/common/gpu/info.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/ffmpeg/format/FormatIn.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/common/gpu/info.cpp
@@ -369,6 +369,37 @@
    return suitable_gpu;
}
int getGPUPrior(const int need, const int reserved, const int lastChoice){
    nvGpuInfo_t gpu_info;
    int ret = get_gpu_info(&gpu_info);
    if(!ret){
        if (gpu_info.device_count == 0) return -1;
        int suitable_gpu = -1;
        int mem_idle = need;
        for(int i = 0; i < gpu_info.device_count; i++){
            if (i != lastChoice){
                int mem_free = gpu_info.devices[i].memory_free >> 20;
                if(mem_free > mem_idle){
                    mem_idle = mem_free;
                    suitable_gpu = i;
                }
            }
        }
        if (suitable_gpu != -1){
            return suitable_gpu;
        }else{
            if (gpu_info.device_count <= lastChoice) return -1;
            int mem_free = (gpu_info.devices[lastChoice].memory_free >> 20) - reserved;
            if(mem_free > need){
                return lastChoice;
            }
        }
    }
    return -1;
}
int getGPU(const int need){
    nvGpuInfo_t gpu_buf;
csrc/common/gpu/info.h
@@ -3,6 +3,7 @@
namespace gpu{
    int getGPU(const int need);
    int getGPUPrior(const int need, const int reserved, const int lastChoice);
}
#endif
csrc/ffmpeg/format/FormatIn.cpp
@@ -194,7 +194,7 @@
        for (int i = 0; i < 2; ++i)
        {
            if(hw_accl_){
                idle_gpu = gpu::getGPU(100);
                idle_gpu = gpu::getGPUPrior(300, 1024, 0);
                if(idle_gpu < 0){
                    logIt("NO GPU RESOURCE TO DECODE");
                    hw_accl_ = false;