summaryrefslogtreecommitdiff
path: root/src/video_core/command_classes
diff options
context:
space:
mode:
authorGravatar liushuyu2021-11-24 18:00:55 -0700
committerGravatar liushuyu2021-11-24 18:06:38 -0700
commit60928cf8cd0d6f46826d588926969913d7fc6740 (patch)
tree2ec8c02dd6febecf0af07fe20386e281b0489ff3 /src/video_core/command_classes
parentvideo_core/codecs: fix multiple decoding issues on Linux ... (diff)
downloadyuzu-60928cf8cd0d6f46826d588926969913d7fc6740.tar.gz
yuzu-60928cf8cd0d6f46826d588926969913d7fc6740.tar.xz
yuzu-60928cf8cd0d6f46826d588926969913d7fc6740.zip
video_core/codec: address comments
Diffstat (limited to 'src/video_core/command_classes')
-rw-r--r--src/video_core/command_classes/codecs/codec.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/video_core/command_classes/codecs/codec.cpp b/src/video_core/command_classes/codecs/codec.cpp
index 403ce30fe..02d309170 100644
--- a/src/video_core/command_classes/codecs/codec.cpp
+++ b/src/video_core/command_classes/codecs/codec.cpp
@@ -2,6 +2,7 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm>
5#include <cstdio> 6#include <cstdio>
6#include <fstream> 7#include <fstream>
7#include <vector> 8#include <vector>
@@ -63,15 +64,16 @@ Codec::~Codec() {
63#ifdef LIBVA_FOUND 64#ifdef LIBVA_FOUND
64// List all the currently loaded Linux modules 65// List all the currently loaded Linux modules
65static std::vector<std::string> ListLinuxKernelModules() { 66static std::vector<std::string> ListLinuxKernelModules() {
67 using FILEPtr = std::unique_ptr<FILE, decltype(&std::fclose)>;
68 auto module_listing = FILEPtr{fopen("/proc/modules", "rt"), std::fclose};
66 std::vector<std::string> modules{}; 69 std::vector<std::string> modules{};
67 auto module_listing = fopen("/proc/modules", "rt");
68 char* buffer = nullptr;
69 size_t buf_len = 0;
70 if (!module_listing) { 70 if (!module_listing) {
71 LOG_WARNING(Service_NVDRV, "Could not open /proc/modules to collect available modules"); 71 LOG_WARNING(Service_NVDRV, "Could not open /proc/modules to collect available modules");
72 return modules; 72 return modules;
73 } 73 }
74 while (getline(&buffer, &buf_len, module_listing) != -1) { 74 char* buffer = nullptr;
75 size_t buf_len = 0;
76 while (getline(&buffer, &buf_len, module_listing.get()) != -1) {
75 // format for the module listing file (sysfs) 77 // format for the module listing file (sysfs)
76 // <name> <module_size> <depended_by_count> <depended_by_names> <status> <load_address> 78 // <name> <module_size> <depended_by_count> <depended_by_names> <status> <load_address>
77 auto line = std::string(buffer); 79 auto line = std::string(buffer);
@@ -80,12 +82,9 @@ static std::vector<std::string> ListLinuxKernelModules() {
80 if (name_pos == std::string::npos) { 82 if (name_pos == std::string::npos) {
81 continue; 83 continue;
82 } 84 }
83 modules.push_back(line.erase(name_pos + 1)); 85 modules.push_back(line.erase(name_pos));
84 } 86 }
85 if (buffer) { 87 free(buffer);
86 free(buffer);
87 }
88 fclose(module_listing);
89 return modules; 88 return modules;
90} 89}
91#endif 90#endif
@@ -98,17 +97,12 @@ bool Codec::CreateGpuAvDevice() {
98 "amdgpu", 97 "amdgpu",
99 }; 98 };
100 AVDictionary* hwdevice_options = nullptr; 99 AVDictionary* hwdevice_options = nullptr;
101 auto loaded_modules = ListLinuxKernelModules(); 100 const auto loaded_modules = ListLinuxKernelModules();
102 av_dict_set(&hwdevice_options, "connection_type", "drm", 0); 101 av_dict_set(&hwdevice_options, "connection_type", "drm", 0);
103 for (const auto& driver : VAAPI_DRIVERS) { 102 for (const auto& driver : VAAPI_DRIVERS) {
104 bool found = false;
105 // first check if the target driver is loaded in the kernel 103 // first check if the target driver is loaded in the kernel
106 for (const auto& module : loaded_modules) { 104 bool found = std::any_of(loaded_modules.begin(), loaded_modules.end(),
107 if (module == driver) { 105 [&driver](const auto& module) { return module == driver; });
108 found = true;
109 break;
110 }
111 }
112 if (!found) { 106 if (!found) {
113 LOG_DEBUG(Service_NVDRV, "Kernel driver {} is not loaded, trying the next one", driver); 107 LOG_DEBUG(Service_NVDRV, "Kernel driver {} is not loaded, trying the next one", driver);
114 continue; 108 continue;