summarylogtreecommitdiffstats
path: root/chromium-vaapi-init-r16.patch
blob: 8b49d2a08e046c28af6b51cb78a329127a883794 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
From 281edc278272f0650fc190c8539d443ac59157bc Mon Sep 17 00:00:00 2001
From: Daniel Charles <daniel.charles@intel.com>
Date: Thu, 08 Feb 2018 02:36:51 +0000
Subject: [PATCH] vaapi initialization: move it to vaapi_wrapper

vaapi loading of libraries happens on the Pre and Post Sandbox
functions.  Moving dynamic loading of libaries, i.e. libva,libva-drm
and i965_drv_video shared libraries to vaapi_wrapper.

When calling PreSandbox function in vaapi_wrapper libva will open
i965_drv_video shared library and both will be available for use

BUG=785117
TEST=video initialization of h/w dec/enc, VAVDA/VAVEA/VAJDA subjective
     testing and include unittests and autotests

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I862bb49f1167d7437e80387882cb9081ad53f54b
Signed-off-by: Daniel Charles <daniel.charles@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/666138
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Antoine Labour <piman@chromium.org>
Reviewed-by: Dongseong Hwang <dongseong.hwang@intel.com>
Reviewed-by: Pawel Osciak <posciak@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#535274}
---

diff --git a/content/gpu/gpu_sandbox_hook_linux.cc b/content/gpu/gpu_sandbox_hook_linux.cc
index e69e23e..5c4013c 100644
--- a/content/gpu/gpu_sandbox_hook_linux.cc
+++ b/content/gpu/gpu_sandbox_hook_linux.cc
@@ -29,10 +29,6 @@
 #include "services/service_manager/sandbox/linux/bpf_gpu_policy_linux.h"
 #include "services/service_manager/sandbox/linux/sandbox_linux.h"
 
-#if BUILDFLAG(USE_VAAPI)
-#include <va/va_version.h>
-#endif
-
 using sandbox::bpf_dsl::Policy;
 using sandbox::syscall_broker::BrokerFilePermission;
 using sandbox::syscall_broker::BrokerProcess;
@@ -48,22 +44,6 @@
 #endif
 }
 
-inline bool IsArchitectureX86_64() {
-#if defined(__x86_64__)
-  return true;
-#else
-  return false;
-#endif
-}
-
-inline bool IsArchitectureI386() {
-#if defined(__i386__)
-  return true;
-#else
-  return false;
-#endif
-}
-
 inline bool IsArchitectureArm() {
 #if defined(ARCH_CPU_ARM_FAMILY)
   return true;
@@ -88,14 +68,6 @@
 #endif
 }
 
-inline bool IsLibVAVersion2() {
-#if BUILDFLAG(USE_VAAPI) && VA_MAJOR_VERSION == 1
-  return true;
-#else
-  return false;
-#endif
-}
-
 constexpr int dlopen_flag = RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE;
 
 void AddV4L2GpuWhitelist(
@@ -270,50 +242,6 @@
   }
 }
 
-void LoadStandardLibraries(
-    const service_manager::SandboxSeccompBPF::Options& options) {
-  if (IsArchitectureX86_64() || IsArchitectureI386()) {
-    // Accelerated video dlopen()'s some shared objects
-    // inside the sandbox, so preload them now.
-    if (IsAcceleratedVideoEnabled(options)) {
-      if (IsLibVAVersion2()) {
-        if (IsArchitectureX86_64()) {
-          dlopen("/usr/lib64/va/drivers/i965_drv_video.so", dlopen_flag);
-          dlopen("/usr/lib64/va/drivers/hybrid_drv_video.so", dlopen_flag);
-        } else if (IsArchitectureI386()) {
-          dlopen("/usr/lib/va/drivers/i965_drv_video.so", dlopen_flag);
-        }
-        dlopen("libva.so.2", dlopen_flag);
-#if defined(USE_OZONE)
-        dlopen("libva-drm.so.2", dlopen_flag);
-#endif
-      } else {
-        // If we are linked against libva 1, we have two cases to handle:
-        // - the sysroot includes both libva 1 and 2, in which case the drivers
-        //   are in /usr/lib{64}/va1/
-        // - the sysroot only includes libva 1, in which case the drivers are
-        //   are in /usr/lib{64}/va/
-        // This is ugly, but temporary until all builds have switched to libva 2.
-        if (IsArchitectureX86_64()) {
-          if (!dlopen("/usr/lib64/va1/drivers/i965_drv_video.so", dlopen_flag))
-            dlopen("/usr/lib64/va/drivers/i965_drv_video.so", dlopen_flag);
-          if (!dlopen("/usr/lib64/va1/drivers/hybrid_drv_video.so", dlopen_flag))
-            dlopen("/usr/lib64/va/drivers/hybrid_drv_video.so", dlopen_flag);
-        } else if (IsArchitectureI386()) {
-          if (!dlopen("/usr/lib/va1/drivers/i965_drv_video.so", dlopen_flag))
-            dlopen("/usr/lib/va/drivers/i965_drv_video.so", dlopen_flag);
-        }
-        dlopen("libva.so.1", dlopen_flag);
-#if defined(USE_OZONE)
-        dlopen("libva-drm.so.1", dlopen_flag);
-#elif defined(USE_X11)
-        dlopen("libva-x11.so.1", dlopen_flag);
-#endif
-      }
-    }
-  }
-}
-
 bool LoadLibrariesForGpu(
     const service_manager::SandboxSeccompBPF::Options& options) {
   if (IsChromeOS()) {
@@ -326,7 +254,6 @@
     if (options.use_amd_specific_policies)
       return LoadAmdGpuLibraries();
   }
-  LoadStandardLibraries(options);
   return true;
 }
 
diff --git a/media/gpu/vaapi/vaapi_wrapper.cc b/media/gpu/vaapi/vaapi_wrapper.cc
index bc3d735..7421a74 100644
--- a/media/gpu/vaapi/vaapi_wrapper.cc
+++ b/media/gpu/vaapi/vaapi_wrapper.cc
@@ -48,6 +48,11 @@
 using media_gpu_vaapi::kModuleVa_x11;
 #endif
 using media_gpu_vaapi::InitializeStubs;
+using media_gpu_vaapi::IsVaInitialized;
+#if defined(USE_X11)
+using media_gpu_vaapi::IsVa_x11Initialized;
+#endif
+using media_gpu_vaapi::IsVa_drmInitialized;
 using media_gpu_vaapi::StubPathMap;
 
 #define LOG_VA_ERROR_AND_REPORT(va_error, err_msg)                  \
@@ -166,9 +171,6 @@
   void SetDrmFd(base::PlatformFile fd) { drm_fd_.reset(HANDLE_EINTR(dup(fd))); }
 
  private:
-  // Returns false on init failure.
-  static bool PostSandboxInitialization();
-
   // Protected by |va_lock_|.
   int refcount_;
 
@@ -203,41 +205,17 @@
     VADisplayState::Get()->SetDrmFd(drm_file.GetPlatformFile());
 }
 
-// static
-bool VADisplayState::PostSandboxInitialization() {
-  const std::string va_suffix(std::to_string(VA_MAJOR_VERSION + 1));
-  StubPathMap paths;
-
-  paths[kModuleVa].push_back(std::string("libva.so.") + va_suffix);
-  paths[kModuleVa_drm].push_back(std::string("libva-drm.so.") + va_suffix);
-#if defined(USE_X11)
-  // libva-x11 does not exist on libva >= 2
-  if (VA_MAJOR_VERSION == 0)
-    paths[kModuleVa_x11].push_back("libva-x11.so.1");
-#endif
-
-  const bool success = InitializeStubs(paths);
-  if (!success) {
-    static const char kErrorMsg[] = "Failed to initialize VAAPI libs";
-#if defined(OS_CHROMEOS)
-    // When Chrome runs on Linux with target_os="chromeos", do not log error
-    // message without VAAPI libraries.
-    LOG_IF(ERROR, base::SysInfo::IsRunningOnChromeOS()) << kErrorMsg;
-#else
-    DVLOG(1) << kErrorMsg;
-#endif
-  }
-  return success;
-}
-
 VADisplayState::VADisplayState()
     : refcount_(0), va_display_(nullptr), va_initialized_(false) {}
 
 bool VADisplayState::Initialize() {
   va_lock_.AssertAcquired();
 
-  static bool result = PostSandboxInitialization();
-  if (!result)
+  if (!IsVaInitialized() ||
+#if defined(USE_X11)
+      !IsVa_x11Initialized() ||
+#endif
+      !IsVa_drmInitialized())
     return false;
 
   if (refcount_++ > 0)
@@ -1169,6 +1147,38 @@
 // static
 void VaapiWrapper::PreSandboxInitialization() {
   VADisplayState::PreSandboxInitialization();
+
+  const std::string va_suffix(std::to_string(VA_MAJOR_VERSION + 1));
+  StubPathMap paths;
+
+  paths[kModuleVa].push_back(std::string("libva.so.") + va_suffix);
+  paths[kModuleVa_drm].push_back(std::string("libva-drm.so.") + va_suffix);
+#if defined(USE_X11)
+  paths[kModuleVa_x11].push_back(std::string("libva-x11.so.") + va_suffix);
+#endif
+
+  // InitializeStubs dlopen() VA-API libraries
+  // libva.so
+  // libva-x11.so (X11)
+  // libva-drm.so (X11 and Ozone).
+  static bool result = InitializeStubs(paths);
+  if (!result) {
+    static const char kErrorMsg[] = "Failed to initialize VAAPI libs";
+#if defined(OS_CHROMEOS)
+    // When Chrome runs on Linux with target_os="chromeos", do not log error
+    // message without VAAPI libraries.
+    LOG_IF(ERROR, base::SysInfo::IsRunningOnChromeOS()) << kErrorMsg;
+#else
+    DVLOG(1) << kErrorMsg;
+#endif
+  }
+
+  // VASupportedProfiles::Get creates VADisplayState and in so doing
+  // driver associated libraries are dlopen(), to know:
+  // i965_drv_video.so
+  // hybrid_drv_video.so (platforms that support it)
+  // libcmrt.so (platforms that support it)
+  VASupportedProfiles::Get();
 }
 
 VaapiWrapper::VaapiWrapper()