yuzu-emu
/
yuzu
Archived
1
0
Fork 0

video_core/codec: address comments

This commit is contained in:
liushuyu 2021-11-24 18:00:55 -07:00
parent 72aa418b0b
commit 60928cf8cd
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437
1 changed files with 11 additions and 17 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm>
#include <cstdio> #include <cstdio>
#include <fstream> #include <fstream>
#include <vector> #include <vector>
@ -63,15 +64,16 @@ Codec::~Codec() {
#ifdef LIBVA_FOUND #ifdef LIBVA_FOUND
// List all the currently loaded Linux modules // List all the currently loaded Linux modules
static std::vector<std::string> ListLinuxKernelModules() { static std::vector<std::string> ListLinuxKernelModules() {
using FILEPtr = std::unique_ptr<FILE, decltype(&std::fclose)>;
auto module_listing = FILEPtr{fopen("/proc/modules", "rt"), std::fclose};
std::vector<std::string> modules{}; std::vector<std::string> modules{};
auto module_listing = fopen("/proc/modules", "rt");
char* buffer = nullptr;
size_t buf_len = 0;
if (!module_listing) { if (!module_listing) {
LOG_WARNING(Service_NVDRV, "Could not open /proc/modules to collect available modules"); LOG_WARNING(Service_NVDRV, "Could not open /proc/modules to collect available modules");
return modules; return modules;
} }
while (getline(&buffer, &buf_len, module_listing) != -1) { char* buffer = nullptr;
size_t buf_len = 0;
while (getline(&buffer, &buf_len, module_listing.get()) != -1) {
// format for the module listing file (sysfs) // format for the module listing file (sysfs)
// <name> <module_size> <depended_by_count> <depended_by_names> <status> <load_address> // <name> <module_size> <depended_by_count> <depended_by_names> <status> <load_address>
auto line = std::string(buffer); auto line = std::string(buffer);
@ -80,12 +82,9 @@ static std::vector<std::string> ListLinuxKernelModules() {
if (name_pos == std::string::npos) { if (name_pos == std::string::npos) {
continue; continue;
} }
modules.push_back(line.erase(name_pos + 1)); modules.push_back(line.erase(name_pos));
} }
if (buffer) { free(buffer);
free(buffer);
}
fclose(module_listing);
return modules; return modules;
} }
#endif #endif
@ -98,17 +97,12 @@ bool Codec::CreateGpuAvDevice() {
"amdgpu", "amdgpu",
}; };
AVDictionary* hwdevice_options = nullptr; AVDictionary* hwdevice_options = nullptr;
auto loaded_modules = ListLinuxKernelModules(); const auto loaded_modules = ListLinuxKernelModules();
av_dict_set(&hwdevice_options, "connection_type", "drm", 0); av_dict_set(&hwdevice_options, "connection_type", "drm", 0);
for (const auto& driver : VAAPI_DRIVERS) { for (const auto& driver : VAAPI_DRIVERS) {
bool found = false;
// first check if the target driver is loaded in the kernel // first check if the target driver is loaded in the kernel
for (const auto& module : loaded_modules) { bool found = std::any_of(loaded_modules.begin(), loaded_modules.end(),
if (module == driver) { [&driver](const auto& module) { return module == driver; });
found = true;
break;
}
}
if (!found) { if (!found) {
LOG_DEBUG(Service_NVDRV, "Kernel driver {} is not loaded, trying the next one", driver); LOG_DEBUG(Service_NVDRV, "Kernel driver {} is not loaded, trying the next one", driver);
continue; continue;