OLD | NEW |
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 "media/gpu/vaapi_wrapper.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 |
17 // Auto-generated for dlopen libva libraries | 18 // Auto-generated for dlopen libva libraries |
18 #include "content/common/gpu/media/va_stubs.h" | 19 #include "media/gpu/va_stubs.h" |
19 #include "content/common/gpu/media/vaapi_picture.h" | 20 |
| 21 #include "media/gpu/vaapi_picture.h" |
20 #include "third_party/libyuv/include/libyuv.h" | 22 #include "third_party/libyuv/include/libyuv.h" |
21 #include "ui/gl/gl_bindings.h" | 23 #include "ui/gl/gl_bindings.h" |
| 24 |
22 #if defined(USE_X11) | 25 #if defined(USE_X11) |
23 #include "ui/gfx/x/x11_types.h" | 26 #include "ui/gfx/x/x11_types.h" |
24 #elif defined(USE_OZONE) | 27 #elif defined(USE_OZONE) |
25 #include "third_party/libva/va/drm/va_drm.h" | 28 #include "third_party/libva/va/drm/va_drm.h" |
26 #include "third_party/libva/va/va_drmcommon.h" | 29 #include "third_party/libva/va/va_drmcommon.h" |
27 #include "ui/ozone/public/ozone_platform.h" | 30 #include "ui/ozone/public/ozone_platform.h" |
28 #include "ui/ozone/public/surface_factory_ozone.h" | 31 #include "ui/ozone/public/surface_factory_ozone.h" |
29 #endif // USE_X11 | 32 #endif // USE_X11 |
30 | 33 |
31 using content_common_gpu_media::kModuleVa; | 34 using media_gpu::kModuleVa; |
32 #if defined(USE_X11) | 35 #if defined(USE_X11) |
33 using content_common_gpu_media::kModuleVa_x11; | 36 using media_gpu::kModuleVa_x11; |
34 #elif defined(USE_OZONE) | 37 #elif defined(USE_OZONE) |
35 using content_common_gpu_media::kModuleVa_drm; | 38 using media_gpu::kModuleVa_drm; |
36 #endif // USE_X11 | 39 #endif // USE_X11 |
37 using content_common_gpu_media::InitializeStubs; | 40 using media_gpu::InitializeStubs; |
38 using content_common_gpu_media::StubPathMap; | 41 using media_gpu::StubPathMap; |
39 | 42 |
40 #define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \ | 43 #define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \ |
41 do { \ | 44 do { \ |
42 LOG(ERROR) << err_msg \ | 45 LOG(ERROR) << err_msg << " VA error: " << vaErrorStr(va_error); \ |
43 << " VA error: " << vaErrorStr(va_error); \ | 46 report_error_to_uma_cb_.Run(); \ |
44 report_error_to_uma_cb_.Run(); \ | |
45 } while (0) | 47 } while (0) |
46 | 48 |
47 #define VA_LOG_ON_ERROR(va_error, err_msg) \ | 49 #define VA_LOG_ON_ERROR(va_error, err_msg) \ |
48 do { \ | 50 do { \ |
49 if ((va_error) != VA_STATUS_SUCCESS) \ | 51 if ((va_error) != VA_STATUS_SUCCESS) \ |
50 LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ | 52 LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ |
51 } while (0) | 53 } while (0) |
52 | 54 |
53 #define VA_SUCCESS_OR_RETURN(va_error, err_msg, ret) \ | 55 #define VA_SUCCESS_OR_RETURN(va_error, err_msg, ret) \ |
54 do { \ | 56 do { \ |
55 if ((va_error) != VA_STATUS_SUCCESS) { \ | 57 if ((va_error) != VA_STATUS_SUCCESS) { \ |
56 LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ | 58 LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ |
57 return (ret); \ | 59 return (ret); \ |
58 } \ | 60 } \ |
59 } while (0) | 61 } while (0) |
60 | 62 |
61 #if defined(USE_OZONE) | 63 #if defined(USE_OZONE) |
62 namespace { | 64 namespace { |
63 | 65 |
64 uint32_t BufferFormatToVAFourCC(gfx::BufferFormat fmt) { | 66 uint32_t BufferFormatToVAFourCC(gfx::BufferFormat fmt) { |
65 switch (fmt) { | 67 switch (fmt) { |
66 case gfx::BufferFormat::BGRX_8888: | 68 case gfx::BufferFormat::BGRX_8888: |
67 return VA_FOURCC_BGRX; | 69 return VA_FOURCC_BGRX; |
68 case gfx::BufferFormat::UYVY_422: | 70 case gfx::BufferFormat::UYVY_422: |
(...skipping 12 matching lines...) Expand all Loading... |
81 return VA_RT_FORMAT_RGB32; | 83 return VA_RT_FORMAT_RGB32; |
82 default: | 84 default: |
83 NOTREACHED(); | 85 NOTREACHED(); |
84 return 0; | 86 return 0; |
85 } | 87 } |
86 } | 88 } |
87 | 89 |
88 } // namespace | 90 } // namespace |
89 #endif | 91 #endif |
90 | 92 |
91 namespace content { | 93 namespace media { |
92 | 94 |
93 // Maximum framerate of encoded profile. This value is an arbitary limit | 95 // Maximum framerate of encoded profile. This value is an arbitary limit |
94 // and not taken from HW documentation. | 96 // and not taken from HW documentation. |
95 const int kMaxEncoderFramerate = 30; | 97 const int kMaxEncoderFramerate = 30; |
96 | 98 |
97 base::LazyInstance<VaapiWrapper::VADisplayState> | 99 base::LazyInstance<VaapiWrapper::VADisplayState> |
98 VaapiWrapper::va_display_state_ = LAZY_INSTANCE_INITIALIZER; | 100 VaapiWrapper::va_display_state_ = LAZY_INSTANCE_INITIALIZER; |
99 | 101 |
100 base::LazyInstance<VaapiWrapper::LazyProfileInfos> | 102 base::LazyInstance<VaapiWrapper::LazyProfileInfos> |
101 VaapiWrapper::profile_infos_ = LAZY_INSTANCE_INITIALIZER; | 103 VaapiWrapper::profile_infos_ = LAZY_INSTANCE_INITIALIZER; |
(...skipping 25 matching lines...) Expand all Loading... |
127 {media::VP8PROFILE_ANY, VAProfileVP8Version0_3}, | 129 {media::VP8PROFILE_ANY, VAProfileVP8Version0_3}, |
128 // TODO(servolk): Need to add VP9 profiles 1,2,3 here after rolling | 130 // TODO(servolk): Need to add VP9 profiles 1,2,3 here after rolling |
129 // third_party/libva to 1.7. crbug.com/598118 | 131 // third_party/libva to 1.7. crbug.com/598118 |
130 {media::VP9PROFILE_PROFILE0, VAProfileVP9Profile0}, | 132 {media::VP9PROFILE_PROFILE0, VAProfileVP9Profile0}, |
131 }; | 133 }; |
132 | 134 |
133 static std::vector<VAConfigAttrib> GetRequiredAttribs( | 135 static std::vector<VAConfigAttrib> GetRequiredAttribs( |
134 VaapiWrapper::CodecMode mode) { | 136 VaapiWrapper::CodecMode mode) { |
135 std::vector<VAConfigAttrib> required_attribs; | 137 std::vector<VAConfigAttrib> required_attribs; |
136 required_attribs.insert( | 138 required_attribs.insert( |
137 required_attribs.end(), | 139 required_attribs.end(), kCommonVAConfigAttribs, |
138 kCommonVAConfigAttribs, | |
139 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs)); | 140 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs)); |
140 if (mode == VaapiWrapper::kEncode) { | 141 if (mode == VaapiWrapper::kEncode) { |
141 required_attribs.insert( | 142 required_attribs.insert( |
142 required_attribs.end(), | 143 required_attribs.end(), kEncodeVAConfigAttribs, |
143 kEncodeVAConfigAttribs, | |
144 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs)); | 144 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs)); |
145 } | 145 } |
146 return required_attribs; | 146 return required_attribs; |
147 } | 147 } |
148 | 148 |
149 VASurface::VASurface(VASurfaceID va_surface_id, | 149 VASurface::VASurface(VASurfaceID va_surface_id, |
150 const gfx::Size& size, | 150 const gfx::Size& size, |
151 unsigned int format, | 151 unsigned int format, |
152 const ReleaseCB& release_cb) | 152 const ReleaseCB& release_cb) |
153 : va_surface_id_(va_surface_id), | 153 : va_surface_id_(va_surface_id), |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 263 |
264 // static | 264 // static |
265 bool VaapiWrapper::IsJpegDecodeSupported() { | 265 bool VaapiWrapper::IsJpegDecodeSupported() { |
266 return profile_infos_.Get().IsProfileSupported(kDecode, | 266 return profile_infos_.Get().IsProfileSupported(kDecode, |
267 VAProfileJPEGBaseline); | 267 VAProfileJPEGBaseline); |
268 } | 268 } |
269 | 269 |
270 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { | 270 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { |
271 base::AutoLock auto_lock(*va_lock_); | 271 base::AutoLock auto_lock(*va_lock_); |
272 VADisplayAttribute item = {VADisplayAttribRenderMode, | 272 VADisplayAttribute item = {VADisplayAttribRenderMode, |
273 1, // At least support '_LOCAL_OVERLAY'. | 273 1, // At least support '_LOCAL_OVERLAY'. |
274 -1, // The maximum possible support 'ALL'. | 274 -1, // The maximum possible support 'ALL'. |
275 VA_RENDER_MODE_LOCAL_GPU, | 275 VA_RENDER_MODE_LOCAL_GPU, |
276 VA_DISPLAY_ATTRIB_SETTABLE}; | 276 VA_DISPLAY_ATTRIB_SETTABLE}; |
277 | 277 |
278 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1); | 278 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1); |
279 if (va_res != VA_STATUS_SUCCESS) | 279 if (va_res != VA_STATUS_SUCCESS) |
280 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default."; | 280 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default."; |
281 } | 281 } |
282 | 282 |
283 // static | 283 // static |
284 VAProfile VaapiWrapper::ProfileToVAProfile( | 284 VAProfile VaapiWrapper::ProfileToVAProfile(media::VideoCodecProfile profile, |
285 media::VideoCodecProfile profile, CodecMode mode) { | 285 CodecMode mode) { |
286 VAProfile va_profile = VAProfileNone; | 286 VAProfile va_profile = VAProfileNone; |
287 for (size_t i = 0; i < arraysize(kProfileMap); ++i) { | 287 for (size_t i = 0; i < arraysize(kProfileMap); ++i) { |
288 if (kProfileMap[i].profile == profile) { | 288 if (kProfileMap[i].profile == profile) { |
289 va_profile = kProfileMap[i].va_profile; | 289 va_profile = kProfileMap[i].va_profile; |
290 break; | 290 break; |
291 } | 291 } |
292 } | 292 } |
293 if (!profile_infos_.Get().IsProfileSupported(mode, va_profile) && | 293 if (!profile_infos_.Get().IsProfileSupported(mode, va_profile) && |
294 va_profile == VAProfileH264Baseline) { | 294 va_profile == VAProfileH264Baseline) { |
295 // crbug.com/345569: media::ProfileIDToVideoCodecProfile() currently strips | 295 // crbug.com/345569: media::ProfileIDToVideoCodecProfile() currently strips |
296 // the information whether the profile is constrained or not, so we have no | 296 // the information whether the profile is constrained or not, so we have no |
297 // way to know here. Try for baseline first, but if it is not supported, | 297 // way to know here. Try for baseline first, but if it is not supported, |
298 // try constrained baseline and hope this is what it actually is | 298 // try constrained baseline and hope this is what it actually is |
299 // (which in practice is true for a great majority of cases). | 299 // (which in practice is true for a great majority of cases). |
300 if (profile_infos_.Get().IsProfileSupported( | 300 if (profile_infos_.Get().IsProfileSupported( |
301 mode, VAProfileH264ConstrainedBaseline)) { | 301 mode, VAProfileH264ConstrainedBaseline)) { |
302 va_profile = VAProfileH264ConstrainedBaseline; | 302 va_profile = VAProfileH264ConstrainedBaseline; |
303 DVLOG(1) << "Fall back to constrained baseline profile."; | 303 DVLOG(1) << "Fall back to constrained baseline profile."; |
304 } | 304 } |
305 } | 305 } |
306 return va_profile; | 306 return va_profile; |
307 } | 307 } |
308 | 308 |
309 std::vector<VaapiWrapper::ProfileInfo> | 309 std::vector<VaapiWrapper::ProfileInfo> |
310 VaapiWrapper::GetSupportedProfileInfosForCodecModeInternal(CodecMode mode) { | 310 VaapiWrapper::GetSupportedProfileInfosForCodecModeInternal(CodecMode mode) { |
311 std::vector<ProfileInfo> supported_profile_infos; | 311 std::vector<ProfileInfo> supported_profile_infos; |
312 std::vector<VAProfile> va_profiles; | 312 std::vector<VAProfile> va_profiles; |
313 if (!GetSupportedVaProfiles(&va_profiles)) | 313 if (!GetSupportedVaProfiles(&va_profiles)) |
314 return supported_profile_infos; | 314 return supported_profile_infos; |
315 | 315 |
316 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); | 316 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); |
317 VAEntrypoint entrypoint = | 317 VAEntrypoint entrypoint = |
318 (mode == kEncode ? VAEntrypointEncSlice: VAEntrypointVLD); | 318 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); |
319 | 319 |
320 base::AutoLock auto_lock(*va_lock_); | 320 base::AutoLock auto_lock(*va_lock_); |
321 for (const auto& va_profile : va_profiles) { | 321 for (const auto& va_profile : va_profiles) { |
322 if (!IsEntrypointSupported_Locked(va_profile, entrypoint)) | 322 if (!IsEntrypointSupported_Locked(va_profile, entrypoint)) |
323 continue; | 323 continue; |
324 if (!AreAttribsSupported_Locked(va_profile, entrypoint, required_attribs)) | 324 if (!AreAttribsSupported_Locked(va_profile, entrypoint, required_attribs)) |
325 continue; | 325 continue; |
326 ProfileInfo profile_info; | 326 ProfileInfo profile_info; |
327 if (!GetMaxResolution_Locked(va_profile, | 327 if (!GetMaxResolution_Locked(va_profile, entrypoint, required_attribs, |
328 entrypoint, | |
329 required_attribs, | |
330 &profile_info.max_resolution)) { | 328 &profile_info.max_resolution)) { |
331 LOG(ERROR) << "GetMaxResolution failed for va_profile " << va_profile | 329 LOG(ERROR) << "GetMaxResolution failed for va_profile " << va_profile |
332 << " and entrypoint " << entrypoint; | 330 << " and entrypoint " << entrypoint; |
333 continue; | 331 continue; |
334 } | 332 } |
335 profile_info.va_profile = va_profile; | 333 profile_info.va_profile = va_profile; |
336 supported_profile_infos.push_back(profile_info); | 334 supported_profile_infos.push_back(profile_info); |
337 } | 335 } |
338 return supported_profile_infos; | 336 return supported_profile_infos; |
339 } | 337 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 371 } |
374 | 372 |
375 bool VaapiWrapper::GetSupportedVaProfiles(std::vector<VAProfile>* profiles) { | 373 bool VaapiWrapper::GetSupportedVaProfiles(std::vector<VAProfile>* profiles) { |
376 base::AutoLock auto_lock(*va_lock_); | 374 base::AutoLock auto_lock(*va_lock_); |
377 // Query the driver for supported profiles. | 375 // Query the driver for supported profiles. |
378 int max_profiles = vaMaxNumProfiles(va_display_); | 376 int max_profiles = vaMaxNumProfiles(va_display_); |
379 std::vector<VAProfile> supported_profiles( | 377 std::vector<VAProfile> supported_profiles( |
380 base::checked_cast<size_t>(max_profiles)); | 378 base::checked_cast<size_t>(max_profiles)); |
381 | 379 |
382 int num_supported_profiles; | 380 int num_supported_profiles; |
383 VAStatus va_res = vaQueryConfigProfiles( | 381 VAStatus va_res = vaQueryConfigProfiles(va_display_, &supported_profiles[0], |
384 va_display_, &supported_profiles[0], &num_supported_profiles); | 382 &num_supported_profiles); |
385 VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigProfiles failed", false); | 383 VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigProfiles failed", false); |
386 if (num_supported_profiles < 0 || num_supported_profiles > max_profiles) { | 384 if (num_supported_profiles < 0 || num_supported_profiles > max_profiles) { |
387 LOG(ERROR) << "vaQueryConfigProfiles returned: " << num_supported_profiles; | 385 LOG(ERROR) << "vaQueryConfigProfiles returned: " << num_supported_profiles; |
388 return false; | 386 return false; |
389 } | 387 } |
390 | 388 |
391 supported_profiles.resize(base::checked_cast<size_t>(num_supported_profiles)); | 389 supported_profiles.resize(base::checked_cast<size_t>(num_supported_profiles)); |
392 *profiles = supported_profiles; | 390 *profiles = supported_profiles; |
393 return true; | 391 return true; |
394 } | 392 } |
395 | 393 |
396 bool VaapiWrapper::IsEntrypointSupported_Locked(VAProfile va_profile, | 394 bool VaapiWrapper::IsEntrypointSupported_Locked(VAProfile va_profile, |
397 VAEntrypoint entrypoint) { | 395 VAEntrypoint entrypoint) { |
398 va_lock_->AssertAcquired(); | 396 va_lock_->AssertAcquired(); |
399 // Query the driver for supported entrypoints. | 397 // Query the driver for supported entrypoints. |
400 int max_entrypoints = vaMaxNumEntrypoints(va_display_); | 398 int max_entrypoints = vaMaxNumEntrypoints(va_display_); |
401 std::vector<VAEntrypoint> supported_entrypoints( | 399 std::vector<VAEntrypoint> supported_entrypoints( |
402 base::checked_cast<size_t>(max_entrypoints)); | 400 base::checked_cast<size_t>(max_entrypoints)); |
403 | 401 |
404 int num_supported_entrypoints; | 402 int num_supported_entrypoints; |
405 VAStatus va_res = vaQueryConfigEntrypoints(va_display_, | 403 VAStatus va_res = vaQueryConfigEntrypoints(va_display_, va_profile, |
406 va_profile, | |
407 &supported_entrypoints[0], | 404 &supported_entrypoints[0], |
408 &num_supported_entrypoints); | 405 &num_supported_entrypoints); |
409 VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigEntrypoints failed", false); | 406 VA_SUCCESS_OR_RETURN(va_res, "vaQueryConfigEntrypoints failed", false); |
410 if (num_supported_entrypoints < 0 || | 407 if (num_supported_entrypoints < 0 || |
411 num_supported_entrypoints > max_entrypoints) { | 408 num_supported_entrypoints > max_entrypoints) { |
412 LOG(ERROR) << "vaQueryConfigEntrypoints returned: " | 409 LOG(ERROR) << "vaQueryConfigEntrypoints returned: " |
413 << num_supported_entrypoints; | 410 << num_supported_entrypoints; |
414 return false; | 411 return false; |
415 } | 412 } |
416 | 413 |
417 if (std::find(supported_entrypoints.begin(), | 414 if (std::find(supported_entrypoints.begin(), supported_entrypoints.end(), |
418 supported_entrypoints.end(), | |
419 entrypoint) == supported_entrypoints.end()) { | 415 entrypoint) == supported_entrypoints.end()) { |
420 DVLOG(1) << "Unsupported entrypoint"; | 416 DVLOG(1) << "Unsupported entrypoint"; |
421 return false; | 417 return false; |
422 } | 418 } |
423 return true; | 419 return true; |
424 } | 420 } |
425 | 421 |
426 bool VaapiWrapper::AreAttribsSupported_Locked( | 422 bool VaapiWrapper::AreAttribsSupported_Locked( |
427 VAProfile va_profile, | 423 VAProfile va_profile, |
428 VAEntrypoint entrypoint, | 424 VAEntrypoint entrypoint, |
429 const std::vector<VAConfigAttrib>& required_attribs) { | 425 const std::vector<VAConfigAttrib>& required_attribs) { |
430 va_lock_->AssertAcquired(); | 426 va_lock_->AssertAcquired(); |
431 // Query the driver for required attributes. | 427 // Query the driver for required attributes. |
432 std::vector<VAConfigAttrib> attribs = required_attribs; | 428 std::vector<VAConfigAttrib> attribs = required_attribs; |
433 for (size_t i = 0; i < required_attribs.size(); ++i) | 429 for (size_t i = 0; i < required_attribs.size(); ++i) |
434 attribs[i].value = 0; | 430 attribs[i].value = 0; |
435 | 431 |
436 VAStatus va_res = vaGetConfigAttributes( | 432 VAStatus va_res = vaGetConfigAttributes(va_display_, va_profile, entrypoint, |
437 va_display_, va_profile, entrypoint, &attribs[0], attribs.size()); | 433 &attribs[0], attribs.size()); |
438 VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes failed", false); | 434 VA_SUCCESS_OR_RETURN(va_res, "vaGetConfigAttributes failed", false); |
439 | 435 |
440 for (size_t i = 0; i < required_attribs.size(); ++i) { | 436 for (size_t i = 0; i < required_attribs.size(); ++i) { |
441 if (attribs[i].type != required_attribs[i].type || | 437 if (attribs[i].type != required_attribs[i].type || |
442 (attribs[i].value & required_attribs[i].value) != | 438 (attribs[i].value & required_attribs[i].value) != |
443 required_attribs[i].value) { | 439 required_attribs[i].value) { |
444 DVLOG(1) << "Unsupported value " << required_attribs[i].value | 440 DVLOG(1) << "Unsupported value " << required_attribs[i].value |
445 << " for attribute type " << required_attribs[i].type; | 441 << " for attribute type " << required_attribs[i].type; |
446 return false; | 442 return false; |
447 } | 443 } |
448 } | 444 } |
449 return true; | 445 return true; |
450 } | 446 } |
451 | 447 |
452 bool VaapiWrapper::GetMaxResolution_Locked( | 448 bool VaapiWrapper::GetMaxResolution_Locked( |
453 VAProfile va_profile, | 449 VAProfile va_profile, |
454 VAEntrypoint entrypoint, | 450 VAEntrypoint entrypoint, |
455 std::vector<VAConfigAttrib>& required_attribs, | 451 std::vector<VAConfigAttrib>& required_attribs, |
456 gfx::Size* resolution) { | 452 gfx::Size* resolution) { |
457 va_lock_->AssertAcquired(); | 453 va_lock_->AssertAcquired(); |
458 VAConfigID va_config_id; | 454 VAConfigID va_config_id; |
459 VAStatus va_res = vaCreateConfig( | 455 VAStatus va_res = |
460 va_display_, | 456 vaCreateConfig(va_display_, va_profile, entrypoint, &required_attribs[0], |
461 va_profile, | 457 required_attribs.size(), &va_config_id); |
462 entrypoint, | |
463 &required_attribs[0], | |
464 required_attribs.size(), | |
465 &va_config_id); | |
466 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); | 458 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); |
467 | 459 |
468 // Calls vaQuerySurfaceAttributes twice. The first time is to get the number | 460 // Calls vaQuerySurfaceAttributes twice. The first time is to get the number |
469 // of attributes to prepare the space and the second time is to get all | 461 // of attributes to prepare the space and the second time is to get all |
470 // attributes. | 462 // attributes. |
471 unsigned int num_attribs; | 463 unsigned int num_attribs; |
472 va_res = vaQuerySurfaceAttributes( | 464 va_res = vaQuerySurfaceAttributes(va_display_, va_config_id, nullptr, |
473 va_display_, va_config_id, nullptr, &num_attribs); | 465 &num_attribs); |
474 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); | 466 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); |
475 if (!num_attribs) | 467 if (!num_attribs) |
476 return false; | 468 return false; |
477 | 469 |
478 std::vector<VASurfaceAttrib> attrib_list( | 470 std::vector<VASurfaceAttrib> attrib_list( |
479 base::checked_cast<size_t>(num_attribs)); | 471 base::checked_cast<size_t>(num_attribs)); |
480 | 472 |
481 va_res = vaQuerySurfaceAttributes( | 473 va_res = vaQuerySurfaceAttributes(va_display_, va_config_id, &attrib_list[0], |
482 va_display_, va_config_id, &attrib_list[0], &num_attribs); | 474 &num_attribs); |
483 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); | 475 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); |
484 | 476 |
485 resolution->SetSize(0, 0); | 477 resolution->SetSize(0, 0); |
486 for (const auto& attrib : attrib_list) { | 478 for (const auto& attrib : attrib_list) { |
487 if (attrib.type == VASurfaceAttribMaxWidth) | 479 if (attrib.type == VASurfaceAttribMaxWidth) |
488 resolution->set_width(attrib.value.value.i); | 480 resolution->set_width(attrib.value.value.i); |
489 else if (attrib.type == VASurfaceAttribMaxHeight) | 481 else if (attrib.type == VASurfaceAttribMaxHeight) |
490 resolution->set_height(attrib.value.value.i); | 482 resolution->set_height(attrib.value.value.i); |
491 } | 483 } |
492 if (resolution->IsEmpty()) { | 484 if (resolution->IsEmpty()) { |
493 LOG(ERROR) << "Codec resolution " << resolution->ToString() | 485 LOG(ERROR) << "Codec resolution " << resolution->ToString() |
494 << " cannot be zero."; | 486 << " cannot be zero."; |
495 return false; | 487 return false; |
496 } | 488 } |
497 return true; | 489 return true; |
498 } | 490 } |
499 | 491 |
500 bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) { | 492 bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) { |
501 TryToSetVADisplayAttributeToLocalGPU(); | 493 TryToSetVADisplayAttributeToLocalGPU(); |
502 | 494 |
503 VAEntrypoint entrypoint = | 495 VAEntrypoint entrypoint = |
504 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); | 496 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); |
505 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); | 497 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); |
506 base::AutoLock auto_lock(*va_lock_); | 498 base::AutoLock auto_lock(*va_lock_); |
507 VAStatus va_res = vaCreateConfig(va_display_, | 499 VAStatus va_res = |
508 va_profile, | 500 vaCreateConfig(va_display_, va_profile, entrypoint, &required_attribs[0], |
509 entrypoint, | 501 required_attribs.size(), &va_config_id_); |
510 &required_attribs[0], | |
511 required_attribs.size(), | |
512 &va_config_id_); | |
513 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); | 502 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); |
514 | 503 |
515 return true; | 504 return true; |
516 } | 505 } |
517 | 506 |
518 void VaapiWrapper::Deinitialize() { | 507 void VaapiWrapper::Deinitialize() { |
519 base::AutoLock auto_lock(*va_lock_); | 508 base::AutoLock auto_lock(*va_lock_); |
520 | 509 |
521 if (va_config_id_ != VA_INVALID_ID) { | 510 if (va_config_id_ != VA_INVALID_ID) { |
522 VAStatus va_res = vaDestroyConfig(va_display_, va_config_id_); | 511 VAStatus va_res = vaDestroyConfig(va_display_, va_config_id_); |
(...skipping 28 matching lines...) Expand all Loading... |
551 vaCreateSurfaces(va_display_, va_format, size.width(), size.height(), | 540 vaCreateSurfaces(va_display_, va_format, size.width(), size.height(), |
552 &va_surface_ids_[0], va_surface_ids_.size(), NULL, 0); | 541 &va_surface_ids_[0], va_surface_ids_.size(), NULL, 0); |
553 | 542 |
554 VA_LOG_ON_ERROR(va_res, "vaCreateSurfaces failed"); | 543 VA_LOG_ON_ERROR(va_res, "vaCreateSurfaces failed"); |
555 if (va_res != VA_STATUS_SUCCESS) { | 544 if (va_res != VA_STATUS_SUCCESS) { |
556 va_surface_ids_.clear(); | 545 va_surface_ids_.clear(); |
557 return false; | 546 return false; |
558 } | 547 } |
559 | 548 |
560 // And create a context associated with them. | 549 // And create a context associated with them. |
561 va_res = vaCreateContext(va_display_, va_config_id_, | 550 va_res = vaCreateContext(va_display_, va_config_id_, size.width(), |
562 size.width(), size.height(), VA_PROGRESSIVE, | 551 size.height(), VA_PROGRESSIVE, &va_surface_ids_[0], |
563 &va_surface_ids_[0], va_surface_ids_.size(), | 552 va_surface_ids_.size(), &va_context_id_); |
564 &va_context_id_); | |
565 | 553 |
566 VA_LOG_ON_ERROR(va_res, "vaCreateContext failed"); | 554 VA_LOG_ON_ERROR(va_res, "vaCreateContext failed"); |
567 if (va_res != VA_STATUS_SUCCESS) { | 555 if (va_res != VA_STATUS_SUCCESS) { |
568 DestroySurfaces(); | 556 DestroySurfaces(); |
569 return false; | 557 return false; |
570 } | 558 } |
571 | 559 |
572 *va_surfaces = va_surface_ids_; | 560 *va_surfaces = va_surface_ids_; |
573 va_surface_format_ = va_format; | 561 va_surface_format_ = va_format; |
574 return true; | 562 return true; |
575 } | 563 } |
576 | 564 |
577 void VaapiWrapper::DestroySurfaces() { | 565 void VaapiWrapper::DestroySurfaces() { |
578 base::AutoLock auto_lock(*va_lock_); | 566 base::AutoLock auto_lock(*va_lock_); |
579 DVLOG(2) << "Destroying " << va_surface_ids_.size() << " surfaces"; | 567 DVLOG(2) << "Destroying " << va_surface_ids_.size() << " surfaces"; |
580 | 568 |
581 if (va_context_id_ != VA_INVALID_ID) { | 569 if (va_context_id_ != VA_INVALID_ID) { |
582 VAStatus va_res = vaDestroyContext(va_display_, va_context_id_); | 570 VAStatus va_res = vaDestroyContext(va_display_, va_context_id_); |
583 VA_LOG_ON_ERROR(va_res, "vaDestroyContext failed"); | 571 VA_LOG_ON_ERROR(va_res, "vaDestroyContext failed"); |
584 } | 572 } |
585 | 573 |
586 if (!va_surface_ids_.empty()) { | 574 if (!va_surface_ids_.empty()) { |
587 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_ids_[0], | 575 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_ids_[0], |
588 va_surface_ids_.size()); | 576 va_surface_ids_.size()); |
589 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces failed"); | 577 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces failed"); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_id, 1); | 692 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_id, 1); |
705 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces on surface failed"); | 693 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces on surface failed"); |
706 } | 694 } |
707 | 695 |
708 bool VaapiWrapper::SubmitBuffer(VABufferType va_buffer_type, | 696 bool VaapiWrapper::SubmitBuffer(VABufferType va_buffer_type, |
709 size_t size, | 697 size_t size, |
710 void* buffer) { | 698 void* buffer) { |
711 base::AutoLock auto_lock(*va_lock_); | 699 base::AutoLock auto_lock(*va_lock_); |
712 | 700 |
713 VABufferID buffer_id; | 701 VABufferID buffer_id; |
714 VAStatus va_res = vaCreateBuffer(va_display_, va_context_id_, | 702 VAStatus va_res = vaCreateBuffer(va_display_, va_context_id_, va_buffer_type, |
715 va_buffer_type, size, | 703 size, 1, buffer, &buffer_id); |
716 1, buffer, &buffer_id); | |
717 VA_SUCCESS_OR_RETURN(va_res, "Failed to create a VA buffer", false); | 704 VA_SUCCESS_OR_RETURN(va_res, "Failed to create a VA buffer", false); |
718 | 705 |
719 switch (va_buffer_type) { | 706 switch (va_buffer_type) { |
720 case VASliceParameterBufferType: | 707 case VASliceParameterBufferType: |
721 case VASliceDataBufferType: | 708 case VASliceDataBufferType: |
722 case VAEncSliceParameterBufferType: | 709 case VAEncSliceParameterBufferType: |
723 pending_slice_bufs_.push_back(buffer_id); | 710 pending_slice_bufs_.push_back(buffer_id); |
724 break; | 711 break; |
725 | 712 |
726 default: | 713 default: |
727 pending_va_bufs_.push_back(buffer_id); | 714 pending_va_bufs_.push_back(buffer_id); |
728 break; | 715 break; |
729 } | 716 } |
730 | 717 |
731 return true; | 718 return true; |
732 } | 719 } |
733 | 720 |
734 bool VaapiWrapper::SubmitVAEncMiscParamBuffer( | 721 bool VaapiWrapper::SubmitVAEncMiscParamBuffer( |
735 VAEncMiscParameterType misc_param_type, | 722 VAEncMiscParameterType misc_param_type, |
736 size_t size, | 723 size_t size, |
737 void* buffer) { | 724 void* buffer) { |
738 base::AutoLock auto_lock(*va_lock_); | 725 base::AutoLock auto_lock(*va_lock_); |
739 | 726 |
740 VABufferID buffer_id; | 727 VABufferID buffer_id; |
741 VAStatus va_res = vaCreateBuffer(va_display_, | 728 VAStatus va_res = vaCreateBuffer( |
742 va_context_id_, | 729 va_display_, va_context_id_, VAEncMiscParameterBufferType, |
743 VAEncMiscParameterBufferType, | 730 sizeof(VAEncMiscParameterBuffer) + size, 1, NULL, &buffer_id); |
744 sizeof(VAEncMiscParameterBuffer) + size, | |
745 1, | |
746 NULL, | |
747 &buffer_id); | |
748 VA_SUCCESS_OR_RETURN(va_res, "Failed to create a VA buffer", false); | 731 VA_SUCCESS_OR_RETURN(va_res, "Failed to create a VA buffer", false); |
749 | 732 |
750 void* data_ptr = NULL; | 733 void* data_ptr = NULL; |
751 va_res = vaMapBuffer(va_display_, buffer_id, &data_ptr); | 734 va_res = vaMapBuffer(va_display_, buffer_id, &data_ptr); |
752 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed"); | 735 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed"); |
753 if (va_res != VA_STATUS_SUCCESS) { | 736 if (va_res != VA_STATUS_SUCCESS) { |
754 vaDestroyBuffer(va_display_, buffer_id); | 737 vaDestroyBuffer(va_display_, buffer_id); |
755 return false; | 738 return false; |
756 } | 739 } |
757 | 740 |
(...skipping 22 matching lines...) Expand all Loading... |
780 VAStatus va_res = vaDestroyBuffer(va_display_, pending_slice_buf); | 763 VAStatus va_res = vaDestroyBuffer(va_display_, pending_slice_buf); |
781 VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); | 764 VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); |
782 } | 765 } |
783 | 766 |
784 pending_va_bufs_.clear(); | 767 pending_va_bufs_.clear(); |
785 pending_slice_bufs_.clear(); | 768 pending_slice_bufs_.clear(); |
786 } | 769 } |
787 | 770 |
788 bool VaapiWrapper::CreateCodedBuffer(size_t size, VABufferID* buffer_id) { | 771 bool VaapiWrapper::CreateCodedBuffer(size_t size, VABufferID* buffer_id) { |
789 base::AutoLock auto_lock(*va_lock_); | 772 base::AutoLock auto_lock(*va_lock_); |
790 VAStatus va_res = vaCreateBuffer(va_display_, | 773 VAStatus va_res = |
791 va_context_id_, | 774 vaCreateBuffer(va_display_, va_context_id_, VAEncCodedBufferType, size, 1, |
792 VAEncCodedBufferType, | 775 NULL, buffer_id); |
793 size, | |
794 1, | |
795 NULL, | |
796 buffer_id); | |
797 VA_SUCCESS_OR_RETURN(va_res, "Failed to create a coded buffer", false); | 776 VA_SUCCESS_OR_RETURN(va_res, "Failed to create a coded buffer", false); |
798 | 777 |
799 const auto is_new_entry = coded_buffers_.insert(*buffer_id).second; | 778 const auto is_new_entry = coded_buffers_.insert(*buffer_id).second; |
800 DCHECK(is_new_entry); | 779 DCHECK(is_new_entry); |
801 return true; | 780 return true; |
802 } | 781 } |
803 | 782 |
804 void VaapiWrapper::DestroyCodedBuffers() { | 783 void VaapiWrapper::DestroyCodedBuffers() { |
805 base::AutoLock auto_lock(*va_lock_); | 784 base::AutoLock auto_lock(*va_lock_); |
806 | 785 |
807 for (std::set<VABufferID>::const_iterator iter = coded_buffers_.begin(); | 786 for (std::set<VABufferID>::const_iterator iter = coded_buffers_.begin(); |
808 iter != coded_buffers_.end(); | 787 iter != coded_buffers_.end(); ++iter) { |
809 ++iter) { | |
810 VAStatus va_res = vaDestroyBuffer(va_display_, *iter); | 788 VAStatus va_res = vaDestroyBuffer(va_display_, *iter); |
811 VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); | 789 VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed"); |
812 } | 790 } |
813 | 791 |
814 coded_buffers_.clear(); | 792 coded_buffers_.clear(); |
815 } | 793 } |
816 | 794 |
817 bool VaapiWrapper::Execute(VASurfaceID va_surface_id) { | 795 bool VaapiWrapper::Execute(VASurfaceID va_surface_id) { |
818 base::AutoLock auto_lock(*va_lock_); | 796 base::AutoLock auto_lock(*va_lock_); |
819 | 797 |
820 DVLOG(4) << "Pending VA bufs to commit: " << pending_va_bufs_.size(); | 798 DVLOG(4) << "Pending VA bufs to commit: " << pending_va_bufs_.size(); |
821 DVLOG(4) << "Pending slice bufs to commit: " << pending_slice_bufs_.size(); | 799 DVLOG(4) << "Pending slice bufs to commit: " << pending_slice_bufs_.size(); |
822 DVLOG(4) << "Target VA surface " << va_surface_id; | 800 DVLOG(4) << "Target VA surface " << va_surface_id; |
823 | 801 |
824 // Get ready to execute for given surface. | 802 // Get ready to execute for given surface. |
825 VAStatus va_res = vaBeginPicture(va_display_, va_context_id_, | 803 VAStatus va_res = vaBeginPicture(va_display_, va_context_id_, va_surface_id); |
826 va_surface_id); | |
827 VA_SUCCESS_OR_RETURN(va_res, "vaBeginPicture failed", false); | 804 VA_SUCCESS_OR_RETURN(va_res, "vaBeginPicture failed", false); |
828 | 805 |
829 if (pending_va_bufs_.size() > 0) { | 806 if (pending_va_bufs_.size() > 0) { |
830 // Commit parameter and slice buffers. | 807 // Commit parameter and slice buffers. |
831 va_res = vaRenderPicture(va_display_, | 808 va_res = vaRenderPicture(va_display_, va_context_id_, &pending_va_bufs_[0], |
832 va_context_id_, | |
833 &pending_va_bufs_[0], | |
834 pending_va_bufs_.size()); | 809 pending_va_bufs_.size()); |
835 VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for va_bufs failed", false); | 810 VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for va_bufs failed", false); |
836 } | 811 } |
837 | 812 |
838 if (pending_slice_bufs_.size() > 0) { | 813 if (pending_slice_bufs_.size() > 0) { |
839 va_res = vaRenderPicture(va_display_, | 814 va_res = |
840 va_context_id_, | 815 vaRenderPicture(va_display_, va_context_id_, &pending_slice_bufs_[0], |
841 &pending_slice_bufs_[0], | 816 pending_slice_bufs_.size()); |
842 pending_slice_bufs_.size()); | |
843 VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for slices failed", false); | 817 VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for slices failed", false); |
844 } | 818 } |
845 | 819 |
846 // Instruct HW codec to start processing committed buffers. | 820 // Instruct HW codec to start processing committed buffers. |
847 // Does not block and the job is not finished after this returns. | 821 // Does not block and the job is not finished after this returns. |
848 va_res = vaEndPicture(va_display_, va_context_id_); | 822 va_res = vaEndPicture(va_display_, va_context_id_); |
849 VA_SUCCESS_OR_RETURN(va_res, "vaEndPicture failed", false); | 823 VA_SUCCESS_OR_RETURN(va_res, "vaEndPicture failed", false); |
850 | 824 |
851 return true; | 825 return true; |
852 } | 826 } |
853 | 827 |
854 bool VaapiWrapper::ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id) { | 828 bool VaapiWrapper::ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id) { |
855 bool result = Execute(va_surface_id); | 829 bool result = Execute(va_surface_id); |
856 DestroyPendingBuffers(); | 830 DestroyPendingBuffers(); |
857 return result; | 831 return result; |
858 } | 832 } |
859 | 833 |
860 #if defined(USE_X11) | 834 #if defined(USE_X11) |
861 bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, | 835 bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
862 Pixmap x_pixmap, | 836 Pixmap x_pixmap, |
863 gfx::Size dest_size) { | 837 gfx::Size dest_size) { |
864 base::AutoLock auto_lock(*va_lock_); | 838 base::AutoLock auto_lock(*va_lock_); |
865 | 839 |
866 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); | 840 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); |
867 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); | 841 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
868 | 842 |
869 // Put the data into an X Pixmap. | 843 // Put the data into an X Pixmap. |
870 va_res = vaPutSurface(va_display_, | 844 va_res = vaPutSurface(va_display_, va_surface_id, x_pixmap, 0, 0, |
871 va_surface_id, | 845 dest_size.width(), dest_size.height(), 0, 0, |
872 x_pixmap, | 846 dest_size.width(), dest_size.height(), NULL, 0, 0); |
873 0, 0, dest_size.width(), dest_size.height(), | |
874 0, 0, dest_size.width(), dest_size.height(), | |
875 NULL, 0, 0); | |
876 VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false); | 847 VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false); |
877 return true; | 848 return true; |
878 } | 849 } |
879 #endif // USE_X11 | 850 #endif // USE_X11 |
880 | 851 |
881 bool VaapiWrapper::GetDerivedVaImage(VASurfaceID va_surface_id, | 852 bool VaapiWrapper::GetDerivedVaImage(VASurfaceID va_surface_id, |
882 VAImage* image, | 853 VAImage* image, |
883 void** mem) { | 854 void** mem) { |
884 base::AutoLock auto_lock(*va_lock_); | 855 base::AutoLock auto_lock(*va_lock_); |
885 | 856 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 VASurfaceID sync_surface_id, | 974 VASurfaceID sync_surface_id, |
1004 uint8_t* target_ptr, | 975 uint8_t* target_ptr, |
1005 size_t target_size, | 976 size_t target_size, |
1006 size_t* coded_data_size) { | 977 size_t* coded_data_size) { |
1007 base::AutoLock auto_lock(*va_lock_); | 978 base::AutoLock auto_lock(*va_lock_); |
1008 | 979 |
1009 VAStatus va_res = vaSyncSurface(va_display_, sync_surface_id); | 980 VAStatus va_res = vaSyncSurface(va_display_, sync_surface_id); |
1010 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); | 981 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
1011 | 982 |
1012 VACodedBufferSegment* buffer_segment = NULL; | 983 VACodedBufferSegment* buffer_segment = NULL; |
1013 va_res = vaMapBuffer( | 984 va_res = vaMapBuffer(va_display_, buffer_id, |
1014 va_display_, buffer_id, reinterpret_cast<void**>(&buffer_segment)); | 985 reinterpret_cast<void**>(&buffer_segment)); |
1015 VA_SUCCESS_OR_RETURN(va_res, "vaMapBuffer failed", false); | 986 VA_SUCCESS_OR_RETURN(va_res, "vaMapBuffer failed", false); |
1016 DCHECK(target_ptr); | 987 DCHECK(target_ptr); |
1017 | 988 |
1018 { | 989 { |
1019 base::AutoUnlock auto_unlock(*va_lock_); | 990 base::AutoUnlock auto_unlock(*va_lock_); |
1020 *coded_data_size = 0; | 991 *coded_data_size = 0; |
1021 | 992 |
1022 while (buffer_segment) { | 993 while (buffer_segment) { |
1023 DCHECK(buffer_segment->buf); | 994 DCHECK(buffer_segment->buf); |
1024 | 995 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 scoped_refptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); | 1148 scoped_refptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); |
1178 if (!vaapi_wrapper->VaInitialize(base::Bind(&base::DoNothing))) | 1149 if (!vaapi_wrapper->VaInitialize(base::Bind(&base::DoNothing))) |
1179 return; | 1150 return; |
1180 for (size_t i = 0; i < kCodecModeMax; ++i) { | 1151 for (size_t i = 0; i < kCodecModeMax; ++i) { |
1181 supported_profiles_[i] = | 1152 supported_profiles_[i] = |
1182 vaapi_wrapper->GetSupportedProfileInfosForCodecModeInternal( | 1153 vaapi_wrapper->GetSupportedProfileInfosForCodecModeInternal( |
1183 static_cast<CodecMode>(i)); | 1154 static_cast<CodecMode>(i)); |
1184 } | 1155 } |
1185 } | 1156 } |
1186 | 1157 |
1187 VaapiWrapper::LazyProfileInfos::~LazyProfileInfos() { | 1158 VaapiWrapper::LazyProfileInfos::~LazyProfileInfos() {} |
1188 } | |
1189 | 1159 |
1190 std::vector<VaapiWrapper::ProfileInfo> | 1160 std::vector<VaapiWrapper::ProfileInfo> |
1191 VaapiWrapper::LazyProfileInfos::GetSupportedProfileInfosForCodecMode( | 1161 VaapiWrapper::LazyProfileInfos::GetSupportedProfileInfosForCodecMode( |
1192 CodecMode mode) { | 1162 CodecMode mode) { |
1193 return supported_profiles_[mode]; | 1163 return supported_profiles_[mode]; |
1194 } | 1164 } |
1195 | 1165 |
1196 bool VaapiWrapper::LazyProfileInfos::IsProfileSupported( | 1166 bool VaapiWrapper::LazyProfileInfos::IsProfileSupported(CodecMode mode, |
1197 CodecMode mode, VAProfile va_profile) { | 1167 VAProfile va_profile) { |
1198 for (const auto& profile : supported_profiles_[mode]) { | 1168 for (const auto& profile : supported_profiles_[mode]) { |
1199 if (profile.va_profile == va_profile) | 1169 if (profile.va_profile == va_profile) |
1200 return true; | 1170 return true; |
1201 } | 1171 } |
1202 return false; | 1172 return false; |
1203 } | 1173 } |
1204 | 1174 |
1205 VaapiWrapper::VADisplayState::VADisplayState() | 1175 VaapiWrapper::VADisplayState::VADisplayState() |
1206 : refcount_(0), | 1176 : refcount_(0), |
1207 va_display_(nullptr), | 1177 va_display_(nullptr), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 } | 1231 } |
1262 | 1232 |
1263 #if defined(USE_OZONE) | 1233 #if defined(USE_OZONE) |
1264 void VaapiWrapper::VADisplayState::SetDrmFd(base::PlatformFile fd) { | 1234 void VaapiWrapper::VADisplayState::SetDrmFd(base::PlatformFile fd) { |
1265 drm_fd_.reset(HANDLE_EINTR(dup(fd))); | 1235 drm_fd_.reset(HANDLE_EINTR(dup(fd))); |
1266 } | 1236 } |
1267 #endif // USE_OZONE | 1237 #endif // USE_OZONE |
1268 | 1238 |
1269 bool VaapiWrapper::VADisplayState::VAAPIVersionLessThan(int major, int minor) { | 1239 bool VaapiWrapper::VADisplayState::VAAPIVersionLessThan(int major, int minor) { |
1270 return (major_version_ < major) || | 1240 return (major_version_ < major) || |
1271 (major_version_ == major && minor_version_ < minor); | 1241 (major_version_ == major && minor_version_ < minor); |
1272 } | 1242 } |
1273 | 1243 |
1274 } // namespace content | 1244 } // namespace media |
OLD | NEW |