Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: content/common/gpu/media/vaapi_wrapper.cc

Issue 872623002: VaapiVEA: Get maximum resolution from libva (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/gpu/media/vaapi_wrapper.h" 5 #include "content/common/gpu/media/vaapi_wrapper.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/command_line.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/numerics/safe_conversions.h" 13 #include "base/numerics/safe_conversions.h"
13 #include "base/sys_info.h" 14 #include "base/sys_info.h"
14 // Auto-generated for dlopen libva libraries 15 // Auto-generated for dlopen libva libraries
15 #include "content/common/gpu/media/va_stubs.h" 16 #include "content/common/gpu/media/va_stubs.h"
16 #include "content/common/gpu/media/vaapi_picture.h" 17 #include "content/common/gpu/media/vaapi_picture.h"
18 #include "content/public/common/content_switches.h"
17 #include "third_party/libyuv/include/libyuv.h" 19 #include "third_party/libyuv/include/libyuv.h"
18 #include "ui/gl/gl_bindings.h" 20 #include "ui/gl/gl_bindings.h"
19 #if defined(USE_X11) 21 #if defined(USE_X11)
20 #include "ui/gfx/x/x11_types.h" 22 #include "ui/gfx/x/x11_types.h"
21 #elif defined(USE_OZONE) 23 #elif defined(USE_OZONE)
22 #include "third_party/libva/va/drm/va_drm.h" 24 #include "third_party/libva/va/drm/va_drm.h"
23 #include "ui/ozone/public/ozone_platform.h" 25 #include "ui/ozone/public/ozone_platform.h"
24 #include "ui/ozone/public/surface_factory_ozone.h" 26 #include "ui/ozone/public/surface_factory_ozone.h"
25 #endif // USE_X11 27 #endif // USE_X11
26 28
(...skipping 22 matching lines...) Expand all
49 #define VA_SUCCESS_OR_RETURN(va_error, err_msg, ret) \ 51 #define VA_SUCCESS_OR_RETURN(va_error, err_msg, ret) \
50 do { \ 52 do { \
51 if ((va_error) != VA_STATUS_SUCCESS) { \ 53 if ((va_error) != VA_STATUS_SUCCESS) { \
52 LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ 54 LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \
53 return (ret); \ 55 return (ret); \
54 } \ 56 } \
55 } while (0) 57 } while (0)
56 58
57 namespace content { 59 namespace content {
58 60
61 // Maximum framerate of encoded profile. This value is an arbitary limit
62 // and not taken from HW documentation.
63 const int kMaxEncoderFramerate = 30;
64
65 base::LazyInstance<VaapiWrapper::LazyProfileInfos>
66 VaapiWrapper::profile_infos_ = LAZY_INSTANCE_INITIALIZER;
67
59 // Config attributes common for both encode and decode. 68 // Config attributes common for both encode and decode.
60 static const VAConfigAttrib kCommonVAConfigAttribs[] = { 69 static const VAConfigAttrib kCommonVAConfigAttribs[] = {
61 {VAConfigAttribRTFormat, VA_RT_FORMAT_YUV420}, 70 {VAConfigAttribRTFormat, VA_RT_FORMAT_YUV420},
62 }; 71 };
63 72
64 // Attributes required for encode. 73 // Attributes required for encode.
65 static const VAConfigAttrib kEncodeVAConfigAttribs[] = { 74 static const VAConfigAttrib kEncodeVAConfigAttribs[] = {
66 {VAConfigAttribRateControl, VA_RC_CBR}, 75 {VAConfigAttribRateControl, VA_RC_CBR},
67 {VAConfigAttribEncPackedHeaders, 76 {VAConfigAttribEncPackedHeaders,
68 VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE}, 77 VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE},
(...skipping 22 matching lines...) Expand all
91 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs)); 100 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs));
92 if (mode == VaapiWrapper::kEncode) { 101 if (mode == VaapiWrapper::kEncode) {
93 required_attribs.insert( 102 required_attribs.insert(
94 required_attribs.end(), 103 required_attribs.end(),
95 kEncodeVAConfigAttribs, 104 kEncodeVAConfigAttribs,
96 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs)); 105 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs));
97 } 106 }
98 return required_attribs; 107 return required_attribs;
99 } 108 }
100 109
101 // Maps Profile enum values to VaProfile values.
102 static VAProfile ProfileToVAProfile(
103 media::VideoCodecProfile profile,
104 const std::vector<VAProfile>& supported_profiles) {
105
106 VAProfile va_profile = VAProfileNone;
107 for (size_t i = 0; i < arraysize(kProfileMap); i++) {
108 if (kProfileMap[i].profile == profile) {
109 va_profile = kProfileMap[i].va_profile;
110 break;
111 }
112 }
113
114 bool supported = std::find(supported_profiles.begin(),
115 supported_profiles.end(),
116 va_profile) != supported_profiles.end();
117
118 if (!supported && va_profile == VAProfileH264Baseline) {
119 // crbug.com/345569: media::ProfileIDToVideoCodecProfile() currently strips
120 // the information whether the profile is constrained or not, so we have no
121 // way to know here. Try for baseline first, but if it is not supported,
122 // try constrained baseline and hope this is what it actually is
123 // (which in practice is true for a great majority of cases).
124 if (std::find(supported_profiles.begin(),
125 supported_profiles.end(),
126 VAProfileH264ConstrainedBaseline) !=
127 supported_profiles.end()) {
128 va_profile = VAProfileH264ConstrainedBaseline;
129 DVLOG(1) << "Falling back to constrained baseline profile.";
130 }
131 }
132
133 return va_profile;
134 }
135
136 VASurface::VASurface(VASurfaceID va_surface_id, 110 VASurface::VASurface(VASurfaceID va_surface_id,
137 const gfx::Size& size, 111 const gfx::Size& size,
138 const ReleaseCB& release_cb) 112 const ReleaseCB& release_cb)
139 : va_surface_id_(va_surface_id), size_(size), release_cb_(release_cb) { 113 : va_surface_id_(va_surface_id), size_(size), release_cb_(release_cb) {
140 DCHECK(!release_cb_.is_null()); 114 DCHECK(!release_cb_.is_null());
141 } 115 }
142 116
143 VASurface::~VASurface() { 117 VASurface::~VASurface() {
144 release_cb_.Run(va_surface_id_); 118 release_cb_.Run(va_surface_id_);
145 } 119 }
146 120
147 VaapiWrapper::VaapiWrapper() 121 VaapiWrapper::VaapiWrapper()
148 : va_display_(NULL), 122 : va_display_(NULL),
149 va_config_id_(VA_INVALID_ID), 123 va_config_id_(VA_INVALID_ID),
150 va_context_id_(VA_INVALID_ID), 124 va_context_id_(VA_INVALID_ID),
151 va_initialized_(false), 125 va_initialized_(false),
152 va_vpp_config_id_(VA_INVALID_ID), 126 va_vpp_config_id_(VA_INVALID_ID),
153 va_vpp_context_id_(VA_INVALID_ID), 127 va_vpp_context_id_(VA_INVALID_ID),
154 va_vpp_buffer_id_(VA_INVALID_ID) { 128 va_vpp_buffer_id_(VA_INVALID_ID) {
155 } 129 }
156 130
157 VaapiWrapper::~VaapiWrapper() { 131 VaapiWrapper::~VaapiWrapper() {
158 DestroyPendingBuffers(); 132 DestroyPendingBuffers();
159 DestroyCodedBuffers(); 133 DestroyCodedBuffers();
160 DestroySurfaces(); 134 DestroySurfaces();
161 DeinitializeVpp(); 135 DeinitializeVpp();
162 Deinitialize(); 136 Deinitialize();
163 } 137 }
164 138
139 // static
165 scoped_ptr<VaapiWrapper> VaapiWrapper::Create( 140 scoped_ptr<VaapiWrapper> VaapiWrapper::Create(
166 CodecMode mode, 141 CodecMode mode,
167 VAProfile va_profile, 142 VAProfile va_profile,
168 const base::Closure& report_error_to_uma_cb) { 143 const base::Closure& report_error_to_uma_cb) {
169 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); 144 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
170 145
171 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) 146 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb))
172 return nullptr; 147 return nullptr;
173 if (!vaapi_wrapper->Initialize(mode, va_profile)) 148
149 if (!vaapi_wrapper->Initialize(mode, va_profile)) {
150 DVLOG(1) << "Unsupported va profile: " << va_profile;
Pawel Osciak 2015/03/08 00:58:24 Initialize() may fail for other reasons too. Perha
henryhsu 2015/03/09 03:56:52 Done.
174 return nullptr; 151 return nullptr;
152 }
175 153
176 return vaapi_wrapper.Pass(); 154 return vaapi_wrapper.Pass();
177 } 155 }
178 156
157 // static
179 scoped_ptr<VaapiWrapper> VaapiWrapper::CreateForVideoCodec( 158 scoped_ptr<VaapiWrapper> VaapiWrapper::CreateForVideoCodec(
180 CodecMode mode, 159 CodecMode mode,
181 media::VideoCodecProfile profile, 160 media::VideoCodecProfile profile,
182 const base::Closure& report_error_to_uma_cb) { 161 const base::Closure& report_error_to_uma_cb) {
183 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); 162 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
184 163
185 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) 164 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb))
186 return nullptr; 165 return nullptr;
187 166
188 std::vector<VAProfile> supported_va_profiles; 167 VAProfile va_profile = ProfileToVAProfile(profile, mode);
189 if (!vaapi_wrapper->GetSupportedVaProfiles(&supported_va_profiles)) 168 if (!vaapi_wrapper->Initialize(mode, va_profile)) {
169 DVLOG(1) << "Initialize failed. Profile: " << profile;
190 return nullptr; 170 return nullptr;
191 171 }
192 VAProfile va_profile = ProfileToVAProfile(profile, supported_va_profiles);
193 if (!vaapi_wrapper->Initialize(mode, va_profile))
194 return nullptr;
195
196 return vaapi_wrapper.Pass(); 172 return vaapi_wrapper.Pass();
197 } 173 }
198 174
199 std::vector<media::VideoCodecProfile> VaapiWrapper::GetSupportedEncodeProfiles( 175 // static
200 const base::Closure& report_error_to_uma_cb) { 176 std::vector<media::VideoEncodeAccelerator::SupportedProfile>
201 std::vector<media::VideoCodecProfile> supported_profiles; 177 VaapiWrapper::GetSupportedEncodeProfiles() {
178 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles;
179 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
180 if (cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode))
181 return profiles;
202 182
203 scoped_ptr<VaapiWrapper> wrapper(new VaapiWrapper()); 183 std::vector<ProfileInfo> encode_profile_infos =
204 if (!wrapper->VaInitialize(report_error_to_uma_cb)) { 184 profile_infos_.Get().GetSupportedProfileInfosForCodecMode(kEncode);
205 return supported_profiles;
206 }
207 185
208 std::vector<VAProfile> va_profiles; 186 for (size_t i = 0; i < arraysize(kProfileMap); ++i) {
209 if (!wrapper->GetSupportedVaProfiles(&va_profiles)) 187 VAProfile va_profile = ProfileToVAProfile(kProfileMap[i].profile, kEncode);
210 return supported_profiles; 188 if (va_profile == VAProfileNone)
211 189 continue;
212 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(kEncode); 190 for (const auto& profile_info : encode_profile_infos) {
213 for (size_t i = 0; i < arraysize(kProfileMap); i++) { 191 if (profile_info.va_profile == va_profile) {
214 VAProfile va_profile = 192 media::VideoEncodeAccelerator::SupportedProfile profile;
215 ProfileToVAProfile(kProfileMap[i].profile, va_profiles); 193 profile.profile = kProfileMap[i].profile;
216 if (va_profile != VAProfileNone && 194 profile.max_resolution = profile_info.max_resolution;
217 wrapper->IsEntrypointSupported(va_profile, VAEntrypointEncSlice) && 195 profile.max_framerate_numerator = kMaxEncoderFramerate;
218 wrapper->AreAttribsSupported( 196 profile.max_framerate_denominator = 1;
219 va_profile, VAEntrypointEncSlice, required_attribs)) { 197 profiles.push_back(profile);
220 supported_profiles.push_back(kProfileMap[i].profile); 198 }
Pawel Osciak 2015/03/08 00:58:24 Could we break here?
henryhsu 2015/03/09 03:56:52 Done.
221 } 199 }
222 } 200 }
223 return supported_profiles; 201 return profiles;
202 }
203
204 // static
205 std::vector<VaapiWrapper::ProfileInfo>
206 VaapiWrapper::GetSupportedProfileInfosForCodecMode(CodecMode mode) {
207 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
208 if (!vaapi_wrapper->VaInitialize(base::Bind(&base::DoNothing)))
209 return std::vector<ProfileInfo>();
210 return vaapi_wrapper->GetSupportedProfileInfosForCodecModeInternal(mode);
224 } 211 }
225 212
226 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { 213 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() {
227 base::AutoLock auto_lock(va_lock_); 214 base::AutoLock auto_lock(va_lock_);
228 VADisplayAttribute item = {VADisplayAttribRenderMode, 215 VADisplayAttribute item = {VADisplayAttribRenderMode,
229 1, // At least support '_LOCAL_OVERLAY'. 216 1, // At least support '_LOCAL_OVERLAY'.
230 -1, // The maximum possible support 'ALL'. 217 -1, // The maximum possible support 'ALL'.
231 VA_RENDER_MODE_LOCAL_GPU, 218 VA_RENDER_MODE_LOCAL_GPU,
232 VA_DISPLAY_ATTRIB_SETTABLE}; 219 VA_DISPLAY_ATTRIB_SETTABLE};
233 220
234 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1); 221 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1);
235 if (va_res != VA_STATUS_SUCCESS) 222 if (va_res != VA_STATUS_SUCCESS)
236 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default."; 223 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default.";
237 } 224 }
238 225
226 // static
227 VAProfile VaapiWrapper::ProfileToVAProfile(
228 media::VideoCodecProfile profile, CodecMode mode) {
229 VAProfile va_profile = VAProfileNone;
230 for (size_t i = 0; i < arraysize(kProfileMap); ++i) {
231 if (kProfileMap[i].profile == profile) {
232 va_profile = kProfileMap[i].va_profile;
233 break;
234 }
235 }
236 if (!profile_infos_.Get().IsProfileSupported(mode, va_profile) &&
237 va_profile == VAProfileH264Baseline) {
238 // crbug.com/345569: media::ProfileIDToVideoCodecProfile() currently strips
239 // the information whether the profile is constrained or not, so we have no
240 // way to know here. Try for baseline first, but if it is not supported,
241 // try constrained baseline and hope this is what it actually is
242 // (which in practice is true for a great majority of cases).
243 if (profile_infos_.Get().IsProfileSupported(
244 mode, VAProfileH264ConstrainedBaseline)) {
245 va_profile = VAProfileH264ConstrainedBaseline;
246 DVLOG(1) << "Fall back to constrained baseline profile.";
247 }
248 }
249 return va_profile;
250 }
251
252 std::vector<VaapiWrapper::ProfileInfo>
253 VaapiWrapper::GetSupportedProfileInfosForCodecModeInternal(CodecMode mode) {
254 std::vector<ProfileInfo> supported_profile_infos;
255 std::vector<VAProfile> va_profiles;
256 if (!GetSupportedVaProfiles(&va_profiles))
257 return supported_profile_infos;
258
259 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode);
260 VAEntrypoint entrypoint =
261 (mode == kEncode ? VAEntrypointEncSlice: VAEntrypointVLD);
262
263 base::AutoLock auto_lock(va_lock_);
264 for (const auto& va_profile : va_profiles) {
265 if (!IsEntrypointSupported(va_profile, entrypoint))
266 continue;
267 if (!AreAttribsSupported(va_profile, entrypoint, required_attribs))
268 continue;
269 VAConfigID config_id;
270 VAStatus va_res = vaCreateConfig(
271 va_display_,
272 va_profile,
273 entrypoint,
274 &required_attribs[0],
275 required_attribs.size(),
276 &config_id);
277 if (va_res != VA_STATUS_SUCCESS) {
278 LOG_VA_ERROR_AND_REPORT(va_res, "vaCreateConfig failed");
279 continue;
280 }
281 ProfileInfo profile_info;
282 if (!GetMaxResolutionForVAConfigID(config_id, &profile_info.max_resolution))
Pawel Osciak 2015/03/08 00:58:24 I think we should LOG(ERROR) here, failure here ma
henryhsu 2015/03/09 03:56:52 Done.
283 continue;
284 profile_info.va_profile = va_profile;
285 supported_profile_infos.push_back(profile_info);
286 }
287 return supported_profile_infos;
288 }
289
239 bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) { 290 bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) {
240 static bool vaapi_functions_initialized = PostSandboxInitialization(); 291 static bool vaapi_functions_initialized = PostSandboxInitialization();
241 if (!vaapi_functions_initialized) { 292 if (!vaapi_functions_initialized) {
242 bool running_on_chromeos = false; 293 bool running_on_chromeos = false;
243 #if defined(OS_CHROMEOS) 294 #if defined(OS_CHROMEOS)
244 // When chrome runs on linux with chromeos=1, do not log error message 295 // When chrome runs on linux with chromeos=1, do not log error message
245 // without VAAPI libraries. 296 // without VAAPI libraries.
246 running_on_chromeos = base::SysInfo::IsRunningOnChromeOS(); 297 running_on_chromeos = base::SysInfo::IsRunningOnChromeOS();
247 #endif 298 #endif
248 static const char kErrorMsg[] = "Failed to initialize VAAPI libs"; 299 static const char kErrorMsg[] = "Failed to initialize VAAPI libs";
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 return false; 350 return false;
300 } 351 }
301 352
302 supported_profiles.resize(base::checked_cast<size_t>(num_supported_profiles)); 353 supported_profiles.resize(base::checked_cast<size_t>(num_supported_profiles));
303 *profiles = supported_profiles; 354 *profiles = supported_profiles;
304 return true; 355 return true;
305 } 356 }
306 357
307 bool VaapiWrapper::IsEntrypointSupported(VAProfile va_profile, 358 bool VaapiWrapper::IsEntrypointSupported(VAProfile va_profile,
308 VAEntrypoint entrypoint) { 359 VAEntrypoint entrypoint) {
309 base::AutoLock auto_lock(va_lock_); 360 va_lock_.AssertAcquired();
310 // Query the driver for supported entrypoints. 361 // Query the driver for supported entrypoints.
311 int max_entrypoints = vaMaxNumEntrypoints(va_display_); 362 int max_entrypoints = vaMaxNumEntrypoints(va_display_);
312 std::vector<VAEntrypoint> supported_entrypoints( 363 std::vector<VAEntrypoint> supported_entrypoints(
313 base::checked_cast<size_t>(max_entrypoints)); 364 base::checked_cast<size_t>(max_entrypoints));
314 365
315 int num_supported_entrypoints; 366 int num_supported_entrypoints;
316 VAStatus va_res = vaQueryConfigEntrypoints(va_display_, 367 VAStatus va_res = vaQueryConfigEntrypoints(va_display_,
317 va_profile, 368 va_profile,
318 &supported_entrypoints[0], 369 &supported_entrypoints[0],
319 &num_supported_entrypoints); 370 &num_supported_entrypoints);
(...skipping 11 matching lines...) Expand all
331 DVLOG(1) << "Unsupported entrypoint"; 382 DVLOG(1) << "Unsupported entrypoint";
332 return false; 383 return false;
333 } 384 }
334 return true; 385 return true;
335 } 386 }
336 387
337 bool VaapiWrapper::AreAttribsSupported( 388 bool VaapiWrapper::AreAttribsSupported(
338 VAProfile va_profile, 389 VAProfile va_profile,
339 VAEntrypoint entrypoint, 390 VAEntrypoint entrypoint,
340 const std::vector<VAConfigAttrib>& required_attribs) { 391 const std::vector<VAConfigAttrib>& required_attribs) {
341 base::AutoLock auto_lock(va_lock_); 392 va_lock_.AssertAcquired();
342 // Query the driver for required attributes. 393 // Query the driver for required attributes.
343 std::vector<VAConfigAttrib> attribs = required_attribs; 394 std::vector<VAConfigAttrib> attribs = required_attribs;
344 for (size_t i = 0; i < required_attribs.size(); ++i) 395 for (size_t i = 0; i < required_attribs.size(); ++i)
345 attribs[i].value = 0; 396 attribs[i].value = 0;
346 397
347 VAStatus va_res = vaGetConfigAttributes( 398 VAStatus va_res = vaGetConfigAttributes(
348 va_display_, va_profile, entrypoint, &attribs[0], attribs.size()); 399 va_display_, va_profile, entrypoint, &attribs[0], attribs.size());
349 VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes failed", false); 400 VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes failed", false);
350 401
351 for (size_t i = 0; i < required_attribs.size(); ++i) { 402 for (size_t i = 0; i < required_attribs.size(); ++i) {
352 if (attribs[i].type != required_attribs[i].type || 403 if (attribs[i].type != required_attribs[i].type ||
353 (attribs[i].value & required_attribs[i].value) != 404 (attribs[i].value & required_attribs[i].value) !=
354 required_attribs[i].value) { 405 required_attribs[i].value) {
355 DVLOG(1) << "Unsupported value " << required_attribs[i].value 406 DVLOG(1) << "Unsupported value " << required_attribs[i].value
356 << " for attribute type " << required_attribs[i].type; 407 << " for attribute type " << required_attribs[i].type;
357 return false; 408 return false;
358 } 409 }
359 } 410 }
360 return true; 411 return true;
361 } 412 }
362 413
414 bool VaapiWrapper::GetMaxResolutionForVAConfigID(VAConfigID va_config_id,
415 gfx::Size* resolution) {
416 va_lock_.AssertAcquired();
417 unsigned int num_attribs;
418
419 // Calls vaQuerySurfaceAttributes twice. The first time is to get the number
420 // of attributes to prepare the space and the second time is to get all
421 // attributes.
422 VAStatus va_res;
423 va_res = vaQuerySurfaceAttributes(
424 va_display_, va_config_id, NULL, &num_attribs);
Pawel Osciak 2015/03/08 00:58:24 s/NULL/nullptr/
henryhsu 2015/03/09 03:56:52 Done.
425 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false);
426 if (!num_attribs)
427 return false;
428
429 std::vector<VASurfaceAttrib> attrib_list(
430 base::checked_cast<size_t>(num_attribs));
431
432 va_res = vaQuerySurfaceAttributes(
433 va_display_, va_config_id, &attrib_list[0], &num_attribs);
434 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false);
435
436 resolution->SetSize(0, 0);
437 for (size_t i = 0; i < num_attribs; i++) {
Pawel Osciak 2015/03/08 00:58:24 for (const auto& attrib : attrib_list)
henryhsu 2015/03/09 03:56:52 Done.
438 if (attrib_list[i].type == VASurfaceAttribMaxWidth)
439 resolution->set_width(attrib_list[i].value.value.i);
440 else if (attrib_list[i].type == VASurfaceAttribMaxHeight)
441 resolution->set_height(attrib_list[i].value.value.i);
442 }
443 if (resolution->IsEmpty()) {
444 LOG(ERROR) << "Codec resolution " << resolution->ToString()
445 << " cannot be zero.";
446 return false;
447 }
448 return true;
449 }
450
363 bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) { 451 bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) {
364 if (va_profile == VAProfileNone) { 452 if (!profile_infos_.Get().IsProfileSupported(mode, va_profile))
365 DVLOG(1) << "Unsupported profile";
366 return false;
367 }
368 VAEntrypoint entrypoint =
369 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD);
370 if (!IsEntrypointSupported(va_profile, entrypoint))
371 return false;
372 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode);
373 if (!AreAttribsSupported(va_profile, entrypoint, required_attribs))
374 return false; 453 return false;
375 454
376 TryToSetVADisplayAttributeToLocalGPU(); 455 TryToSetVADisplayAttributeToLocalGPU();
377 456
457 VAEntrypoint entrypoint =
458 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD);
459 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode);
378 base::AutoLock auto_lock(va_lock_); 460 base::AutoLock auto_lock(va_lock_);
379 VAStatus va_res = vaCreateConfig(va_display_, 461 VAStatus va_res = vaCreateConfig(va_display_,
380 va_profile, 462 va_profile,
381 entrypoint, 463 entrypoint,
382 &required_attribs[0], 464 &required_attribs[0],
383 required_attribs.size(), 465 required_attribs.size(),
384 &va_config_id_); 466 &va_config_id_);
385 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); 467 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false);
386 468
387 return true; 469 return true;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 va_res = vaUnmapBuffer(va_display_, buffer_id); 648 va_res = vaUnmapBuffer(va_display_, buffer_id);
567 VA_LOG_ON_ERROR(va_res, "vaUnmapBuffer failed"); 649 VA_LOG_ON_ERROR(va_res, "vaUnmapBuffer failed");
568 650
569 pending_va_bufs_.push_back(buffer_id); 651 pending_va_bufs_.push_back(buffer_id);
570 return true; 652 return true;
571 } 653 }
572 654
573 void VaapiWrapper::DestroyPendingBuffers() { 655 void VaapiWrapper::DestroyPendingBuffers() {
574 base::AutoLock auto_lock(va_lock_); 656 base::AutoLock auto_lock(va_lock_);
575 657
576 for (size_t i = 0; i < pending_va_bufs_.size(); ++i) { 658 for (const auto& pending_va_buf : pending_va_bufs_) {
577 VAStatus va_res = vaDestroyBuffer(va_display_, pending_va_bufs_[i]); 659 VAStatus va_res = vaDestroyBuffer(va_display_, pending_va_buf);
578 VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); 660 VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed");
579 } 661 }
580 662
581 for (size_t i = 0; i < pending_slice_bufs_.size(); ++i) { 663 for (const auto& pending_slice_buf : pending_slice_bufs_) {
582 VAStatus va_res = vaDestroyBuffer(va_display_, pending_slice_bufs_[i]); 664 VAStatus va_res = vaDestroyBuffer(va_display_, pending_slice_buf);
583 VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); 665 VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed");
584 } 666 }
585 667
586 pending_va_bufs_.clear(); 668 pending_va_bufs_.clear();
587 pending_slice_bufs_.clear(); 669 pending_slice_bufs_.clear();
588 } 670 }
589 671
590 bool VaapiWrapper::CreateCodedBuffer(size_t size, VABufferID* buffer_id) { 672 bool VaapiWrapper::CreateCodedBuffer(size_t size, VABufferID* buffer_id) {
591 base::AutoLock auto_lock(va_lock_); 673 base::AutoLock auto_lock(va_lock_);
592 VAStatus va_res = vaCreateBuffer(va_display_, 674 VAStatus va_res = vaCreateBuffer(va_display_,
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 1034
953 #if defined(USE_X11) 1035 #if defined(USE_X11)
954 paths[kModuleVa_x11].push_back("libva-x11.so.1"); 1036 paths[kModuleVa_x11].push_back("libva-x11.so.1");
955 #elif defined(USE_OZONE) 1037 #elif defined(USE_OZONE)
956 paths[kModuleVa_drm].push_back("libva-drm.so.1"); 1038 paths[kModuleVa_drm].push_back("libva-drm.so.1");
957 #endif 1039 #endif
958 1040
959 return InitializeStubs(paths); 1041 return InitializeStubs(paths);
960 } 1042 }
961 1043
1044 VaapiWrapper::LazyProfileInfos::LazyProfileInfos() {
1045 for (size_t i = 0; i < kCodecModeMax; ++i) {
Pawel Osciak 2015/03/08 00:58:24 Ok, but let's at least do static_assert(arraysize(
henryhsu 2015/03/09 03:56:52 Done.
1046 supported_profiles_[i] =
1047 VaapiWrapper::GetSupportedProfileInfosForCodecMode(
1048 static_cast<CodecMode>(i));
1049 }
1050 }
1051
1052 VaapiWrapper::LazyProfileInfos::~LazyProfileInfos() {
1053 }
1054
1055 std::vector<VaapiWrapper::ProfileInfo>
1056 VaapiWrapper::LazyProfileInfos::GetSupportedProfileInfosForCodecMode(
1057 CodecMode mode) {
1058 return supported_profiles_[mode];
1059 }
1060
1061 bool VaapiWrapper::LazyProfileInfos::IsProfileSupported(
1062 CodecMode mode, VAProfile va_profile) {
1063 for (const auto& profile : supported_profiles_[mode]) {
1064 if (profile.va_profile == va_profile)
1065 return true;
1066 }
1067 return false;
1068 }
1069
962 } // namespace content 1070 } // namespace content
OLDNEW
« content/common/gpu/media/vaapi_wrapper.h ('K') | « content/common/gpu/media/vaapi_wrapper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698