Chromium Code Reviews| 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 "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/lazy_instance.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" |
| 17 #include "third_party/libyuv/include/libyuv.h" | 18 #include "third_party/libyuv/include/libyuv.h" |
| 18 #include "ui/gl/gl_bindings.h" | 19 #include "ui/gl/gl_bindings.h" |
| 19 #if defined(USE_X11) | 20 #if defined(USE_X11) |
| 20 #include "ui/gfx/x/x11_types.h" | 21 #include "ui/gfx/x/x11_types.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 49 #define VA_SUCCESS_OR_RETURN(va_error, err_msg, ret) \ | 50 #define VA_SUCCESS_OR_RETURN(va_error, err_msg, ret) \ |
| 50 do { \ | 51 do { \ |
| 51 if ((va_error) != VA_STATUS_SUCCESS) { \ | 52 if ((va_error) != VA_STATUS_SUCCESS) { \ |
| 52 LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ | 53 LOG_VA_ERROR_AND_REPORT(va_error, err_msg); \ |
| 53 return (ret); \ | 54 return (ret); \ |
| 54 } \ | 55 } \ |
| 55 } while (0) | 56 } while (0) |
| 56 | 57 |
| 57 namespace content { | 58 namespace content { |
| 58 | 59 |
| 60 base::LazyInstance<LazyProfileConfig> g_profile_config = | |
| 61 LAZY_INSTANCE_INITIALIZER; | |
| 62 | |
| 59 // Config attributes common for both encode and decode. | 63 // Config attributes common for both encode and decode. |
| 60 static const VAConfigAttrib kCommonVAConfigAttribs[] = { | 64 static const VAConfigAttrib kCommonVAConfigAttribs[] = { |
| 61 {VAConfigAttribRTFormat, VA_RT_FORMAT_YUV420}, | 65 {VAConfigAttribRTFormat, VA_RT_FORMAT_YUV420}, |
| 62 }; | 66 }; |
| 63 | 67 |
| 64 // Attributes required for encode. | 68 // Attributes required for encode. |
| 65 static const VAConfigAttrib kEncodeVAConfigAttribs[] = { | 69 static const VAConfigAttrib kEncodeVAConfigAttribs[] = { |
| 66 {VAConfigAttribRateControl, VA_RC_CBR}, | 70 {VAConfigAttribRateControl, VA_RC_CBR}, |
| 67 {VAConfigAttribEncPackedHeaders, | 71 {VAConfigAttribEncPackedHeaders, |
| 68 VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE}, | 72 VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE}, |
| 69 }; | 73 }; |
| 70 | 74 |
| 71 struct ProfileMap { | 75 struct ProfileMap { |
| 72 media::VideoCodecProfile profile; | 76 media::VideoCodecProfile profile; |
| 73 VAProfile va_profile; | 77 VAProfile va_profile; |
| 74 }; | 78 }; |
| 75 | 79 |
| 76 // A map between VideoCodecProfile and VAProfile. | 80 // A map between VideoCodecProfile and VAProfile. |
| 77 static const ProfileMap kProfileMap[] = { | 81 static const ProfileMap kProfileMap[] = { |
| 78 {media::H264PROFILE_BASELINE, VAProfileH264Baseline}, | 82 {media::H264PROFILE_BASELINE, VAProfileH264Baseline}, |
| 79 {media::H264PROFILE_MAIN, VAProfileH264Main}, | 83 {media::H264PROFILE_MAIN, VAProfileH264Main}, |
| 80 // TODO(posciak): See if we can/want support other variants of | 84 // TODO(posciak): See if we can/want support other variants of |
| 81 // media::H264PROFILE_HIGH*. | 85 // media::H264PROFILE_HIGH*. |
| 82 {media::H264PROFILE_HIGH, VAProfileH264High}, | 86 {media::H264PROFILE_HIGH, VAProfileH264High}, |
| 87 // crbug.com/345569: media::ProfileIDToVideoCodecProfile() currently strips | |
| 88 // the information whether the profile is constrained or not, so we have no | |
| 89 // way to know here. Try for baseline first, but if it is not supported, | |
| 90 // try constrained baseline and hope this is what it actually is | |
| 91 // (which in practice is true for a great majority of cases). | |
| 92 {media::H264PROFILE_BASELINE, VAProfileH264ConstrainedBaseline}, | |
|
kcwu
2015/02/13 07:15:38
This is incorrect. You break the original behavior
kcwu
2015/02/13 07:35:11
offline talked with henry. The code is good. Pleas
henryhsu
2015/02/13 07:35:28
As discuss, the logic is correct. But I'll modify
henryhsu
2015/02/13 17:24:28
Done.
| |
| 83 }; | 93 }; |
| 84 | 94 |
| 85 static std::vector<VAConfigAttrib> GetRequiredAttribs( | 95 static std::vector<VAConfigAttrib> GetRequiredAttribs( |
| 86 VaapiWrapper::CodecMode mode) { | 96 VaapiWrapper::CodecMode mode) { |
| 87 std::vector<VAConfigAttrib> required_attribs; | 97 std::vector<VAConfigAttrib> required_attribs; |
| 88 required_attribs.insert( | 98 required_attribs.insert( |
| 89 required_attribs.end(), | 99 required_attribs.end(), |
| 90 kCommonVAConfigAttribs, | 100 kCommonVAConfigAttribs, |
| 91 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs)); | 101 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs)); |
| 92 if (mode == VaapiWrapper::kEncode) { | 102 if (mode == VaapiWrapper::kEncode) { |
| 93 required_attribs.insert( | 103 required_attribs.insert( |
| 94 required_attribs.end(), | 104 required_attribs.end(), |
| 95 kEncodeVAConfigAttribs, | 105 kEncodeVAConfigAttribs, |
| 96 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs)); | 106 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs)); |
| 97 } | 107 } |
| 98 return required_attribs; | 108 return required_attribs; |
| 99 } | 109 } |
| 100 | 110 |
| 101 // Maps Profile enum values to VaProfile values. | 111 // Maps VaProfile enum values to Profile values. |
| 102 static VAProfile ProfileToVAProfile( | 112 static media::VideoCodecProfile VAProfileToProfile(VAProfile va_profile) { |
| 103 media::VideoCodecProfile profile, | 113 media::VideoCodecProfile profile = media::VIDEO_CODEC_PROFILE_UNKNOWN; |
| 104 const std::vector<VAProfile>& supported_profiles) { | |
| 105 | |
| 106 VAProfile va_profile = VAProfileNone; | |
| 107 for (size_t i = 0; i < arraysize(kProfileMap); i++) { | 114 for (size_t i = 0; i < arraysize(kProfileMap); i++) { |
| 108 if (kProfileMap[i].profile == profile) { | 115 if (kProfileMap[i].va_profile == va_profile) { |
| 109 va_profile = kProfileMap[i].va_profile; | 116 profile = kProfileMap[i].profile; |
| 110 break; | 117 break; |
| 111 } | 118 } |
| 112 } | 119 } |
| 113 | 120 return profile; |
| 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 } | 121 } |
| 135 | 122 |
| 136 VASurface::VASurface(VASurfaceID va_surface_id, | 123 VASurface::VASurface(VASurfaceID va_surface_id, |
| 137 const gfx::Size& size, | 124 const gfx::Size& size, |
| 138 const ReleaseCB& release_cb) | 125 const ReleaseCB& release_cb) |
| 139 : va_surface_id_(va_surface_id), size_(size), release_cb_(release_cb) { | 126 : va_surface_id_(va_surface_id), size_(size), release_cb_(release_cb) { |
| 140 DCHECK(!release_cb_.is_null()); | 127 DCHECK(!release_cb_.is_null()); |
| 141 } | 128 } |
| 142 | 129 |
| 143 VASurface::~VASurface() { | 130 VASurface::~VASurface() { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 155 } | 142 } |
| 156 | 143 |
| 157 VaapiWrapper::~VaapiWrapper() { | 144 VaapiWrapper::~VaapiWrapper() { |
| 158 DestroyPendingBuffers(); | 145 DestroyPendingBuffers(); |
| 159 DestroyCodedBuffers(); | 146 DestroyCodedBuffers(); |
| 160 DestroySurfaces(); | 147 DestroySurfaces(); |
| 161 DeinitializeVpp(); | 148 DeinitializeVpp(); |
| 162 Deinitialize(); | 149 Deinitialize(); |
| 163 } | 150 } |
| 164 | 151 |
| 152 // static | |
| 165 scoped_ptr<VaapiWrapper> VaapiWrapper::Create( | 153 scoped_ptr<VaapiWrapper> VaapiWrapper::Create( |
| 166 CodecMode mode, | 154 CodecMode mode, |
| 167 VAProfile va_profile, | 155 VAProfile va_profile, |
| 168 const base::Closure& report_error_to_uma_cb) { | 156 const base::Closure& report_error_to_uma_cb) { |
| 169 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); | 157 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); |
| 170 | 158 |
| 171 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) | 159 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) |
| 172 return nullptr; | 160 return nullptr; |
| 173 if (!vaapi_wrapper->Initialize(mode, va_profile)) | 161 |
| 162 if (!vaapi_wrapper->Initialize(mode, va_profile)) { | |
| 163 DVLOG(1) << "Unsupported profile"; | |
|
wuchengli
2015/02/13 15:38:54
also print |va_profile|
henryhsu
2015/02/13 17:24:28
Done.
| |
| 174 return nullptr; | 164 return nullptr; |
| 165 } | |
| 175 | 166 |
| 176 return vaapi_wrapper.Pass(); | 167 return vaapi_wrapper.Pass(); |
| 177 } | 168 } |
| 178 | 169 |
| 170 // static | |
| 179 scoped_ptr<VaapiWrapper> VaapiWrapper::CreateForVideoCodec( | 171 scoped_ptr<VaapiWrapper> VaapiWrapper::CreateForVideoCodec( |
| 180 CodecMode mode, | 172 CodecMode mode, |
| 181 media::VideoCodecProfile profile, | 173 media::VideoCodecProfile profile, |
| 182 const base::Closure& report_error_to_uma_cb) { | 174 const base::Closure& report_error_to_uma_cb) { |
| 183 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); | 175 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); |
| 184 | 176 |
| 185 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) | 177 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) |
| 186 return nullptr; | 178 return nullptr; |
| 187 | 179 |
| 188 std::vector<VAProfile> supported_va_profiles; | 180 for (size_t i = 0; i < arraysize(kProfileMap); ++i) { |
| 189 if (!vaapi_wrapper->GetSupportedVaProfiles(&supported_va_profiles)) | 181 if (kProfileMap[i].profile == profile && |
| 190 return nullptr; | 182 vaapi_wrapper->Initialize(mode, kProfileMap[i].va_profile)) |
| 191 | 183 return vaapi_wrapper.Pass(); |
| 192 VAProfile va_profile = ProfileToVAProfile(profile, supported_va_profiles); | 184 } |
| 193 if (!vaapi_wrapper->Initialize(mode, va_profile)) | 185 DVLOG(1) << "Unsupported profile"; |
|
wuchengli
2015/02/13 15:38:55
also print |profile|
henryhsu
2015/02/13 17:24:28
Done.
| |
| 194 return nullptr; | 186 return nullptr; |
| 195 | |
| 196 return vaapi_wrapper.Pass(); | |
| 197 } | 187 } |
| 198 | 188 |
| 199 std::vector<media::VideoCodecProfile> VaapiWrapper::GetSupportedEncodeProfiles( | 189 // static |
| 200 const base::Closure& report_error_to_uma_cb) { | 190 std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
| 201 std::vector<media::VideoCodecProfile> supported_profiles; | 191 VaapiWrapper::GetSupportedEncodeProfiles() { |
| 202 | 192 std::vector<ProfileConfig> encode_profile_configs = |
| 203 scoped_ptr<VaapiWrapper> wrapper(new VaapiWrapper()); | 193 g_profile_config.Get().GetSupportedEncodeProfileConfigs(); |
| 204 if (!wrapper->VaInitialize(report_error_to_uma_cb)) { | 194 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles; |
| 205 return supported_profiles; | 195 media::VideoEncodeAccelerator::SupportedProfile profile; |
| 206 } | 196 for (size_t i = 0; i < encode_profile_configs.size(); ++i) { |
| 207 | 197 media::VideoCodecProfile hw_profile = VAProfileToProfile( |
| 208 std::vector<VAProfile> va_profiles; | 198 encode_profile_configs[i].va_profile); |
| 209 if (!wrapper->GetSupportedVaProfiles(&va_profiles)) | 199 if (hw_profile != media::VIDEO_CODEC_PROFILE_UNKNOWN) { |
| 210 return supported_profiles; | 200 profile.profile = hw_profile; |
| 211 | 201 profile.max_resolution = encode_profile_configs[i].max_resolution; |
| 212 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(kEncode); | 202 profiles.push_back(profile); |
| 213 for (size_t i = 0; i < arraysize(kProfileMap); i++) { | |
| 214 VAProfile va_profile = | |
| 215 ProfileToVAProfile(kProfileMap[i].profile, va_profiles); | |
| 216 if (va_profile != VAProfileNone && | |
| 217 wrapper->IsEntrypointSupported(va_profile, VAEntrypointEncSlice) && | |
| 218 wrapper->AreAttribsSupported( | |
| 219 va_profile, VAEntrypointEncSlice, required_attribs)) { | |
| 220 supported_profiles.push_back(kProfileMap[i].profile); | |
| 221 } | 203 } |
| 222 } | 204 } |
| 223 return supported_profiles; | 205 return profiles; |
| 206 } | |
| 207 | |
| 208 // static | |
| 209 std::vector<VaapiWrapper::ProfileConfig> | |
| 210 VaapiWrapper::InitSupportedProfileConfigs() { | |
| 211 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); | |
| 212 if (!vaapi_wrapper->VaInitialize(base::Bind(&base::DoNothing))) | |
| 213 return std::vector<VaapiWrapper::ProfileConfig>(); | |
| 214 return vaapi_wrapper->GetSupportedProfileConfigs(); | |
| 224 } | 215 } |
| 225 | 216 |
| 226 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { | 217 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { |
| 227 base::AutoLock auto_lock(va_lock_); | 218 base::AutoLock auto_lock(va_lock_); |
| 228 VADisplayAttribute item = {VADisplayAttribRenderMode, | 219 VADisplayAttribute item = {VADisplayAttribRenderMode, |
| 229 1, // At least support '_LOCAL_OVERLAY'. | 220 1, // At least support '_LOCAL_OVERLAY'. |
| 230 -1, // The maximum possible support 'ALL'. | 221 -1, // The maximum possible support 'ALL'. |
| 231 VA_RENDER_MODE_LOCAL_GPU, | 222 VA_RENDER_MODE_LOCAL_GPU, |
| 232 VA_DISPLAY_ATTRIB_SETTABLE}; | 223 VA_DISPLAY_ATTRIB_SETTABLE}; |
| 233 | 224 |
| 234 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1); | 225 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1); |
| 235 if (va_res != VA_STATUS_SUCCESS) | 226 if (va_res != VA_STATUS_SUCCESS) |
| 236 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default."; | 227 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default."; |
| 237 } | 228 } |
| 238 | 229 |
| 230 std::vector<VaapiWrapper::ProfileConfig> | |
| 231 VaapiWrapper::GetSupportedProfileConfigs() { | |
| 232 std::vector<VaapiWrapper::ProfileConfig> supported_profiles; | |
| 233 std::vector<VAProfile> va_profiles; | |
| 234 if (!GetSupportedVaProfiles(&va_profiles)) | |
| 235 return supported_profiles; | |
| 236 | |
| 237 VaapiWrapper::ProfileConfig supported_profile; | |
| 238 std::vector<CodecMode> modes({kDecode, kEncode}); | |
| 239 for (size_t i = 0; i < modes.size(); ++i) { | |
| 240 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(modes[i]); | |
| 241 VAEntrypoint entrypoint = | |
| 242 (modes[i] == kEncode ? VAEntrypointEncSlice: VAEntrypointVLD); | |
| 243 for (size_t j = 0; j < va_profiles.size(); ++j) { | |
| 244 if (va_profiles[j] != VAProfileNone && | |
|
wuchengli
2015/02/13 15:38:54
Why this can be VAProfileNone?
henryhsu
2015/02/13 17:24:28
oh...this is typo. In original implementation, we
| |
| 245 IsEntrypointSupported(va_profiles[j], entrypoint) && | |
| 246 AreAttribsSupported(va_profiles[j], entrypoint, required_attribs)) { | |
| 247 supported_profile.va_profile = va_profiles[j]; | |
| 248 supported_profile.mode = modes[i]; | |
|
wuchengli
2015/02/13 15:38:54
move l247-248 to l259. No need to do this if it fa
henryhsu
2015/02/13 17:24:28
Done.
| |
| 249 VAConfigID config_id; | |
| 250 VAStatus va_res = vaCreateConfig( | |
| 251 va_display_, | |
| 252 va_profiles[j], | |
| 253 entrypoint, | |
| 254 &required_attribs[0], | |
| 255 required_attribs.size(), | |
| 256 &config_id); | |
| 257 if (va_res == VA_STATUS_SUCCESS && | |
| 258 GetVaCodecMaxResolution(config_id, | |
| 259 &supported_profile.max_resolution)) | |
|
wuchengli
2015/02/13 15:38:55
This for loop is hard to read. Can you flatten the
henryhsu
2015/02/13 17:24:28
Done.
| |
| 260 supported_profiles.push_back(supported_profile); | |
| 261 } | |
| 262 } | |
| 263 } | |
| 264 return supported_profiles; | |
| 265 } | |
| 266 | |
| 239 bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) { | 267 bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) { |
| 240 static bool vaapi_functions_initialized = PostSandboxInitialization(); | 268 static bool vaapi_functions_initialized = PostSandboxInitialization(); |
| 241 if (!vaapi_functions_initialized) { | 269 if (!vaapi_functions_initialized) { |
| 242 bool running_on_chromeos = false; | 270 bool running_on_chromeos = false; |
| 243 #if defined(OS_CHROMEOS) | 271 #if defined(OS_CHROMEOS) |
| 244 // When chrome runs on linux with chromeos=1, do not log error message | 272 // When chrome runs on linux with chromeos=1, do not log error message |
| 245 // without VAAPI libraries. | 273 // without VAAPI libraries. |
| 246 running_on_chromeos = base::SysInfo::IsRunningOnChromeOS(); | 274 running_on_chromeos = base::SysInfo::IsRunningOnChromeOS(); |
| 247 #endif | 275 #endif |
| 248 static const char kErrorMsg[] = "Failed to initialize VAAPI libs"; | 276 static const char kErrorMsg[] = "Failed to initialize VAAPI libs"; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 (attribs[i].value & required_attribs[i].value) != | 381 (attribs[i].value & required_attribs[i].value) != |
| 354 required_attribs[i].value) { | 382 required_attribs[i].value) { |
| 355 DVLOG(1) << "Unsupported value " << required_attribs[i].value | 383 DVLOG(1) << "Unsupported value " << required_attribs[i].value |
| 356 << " for attribute type " << required_attribs[i].type; | 384 << " for attribute type " << required_attribs[i].type; |
| 357 return false; | 385 return false; |
| 358 } | 386 } |
| 359 } | 387 } |
| 360 return true; | 388 return true; |
| 361 } | 389 } |
| 362 | 390 |
| 391 bool VaapiWrapper::GetVaCodecMaxResolution(VAConfigID config_id, | |
| 392 gfx::Size* resolution) { | |
| 393 base::AutoLock auto_lock(va_lock_); | |
| 394 unsigned int num_attribs; | |
| 395 VAStatus va_res; | |
| 396 | |
| 397 va_res = vaQuerySurfaceAttributes( | |
| 398 va_display_, config_id, NULL, &num_attribs); | |
| 399 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); | |
| 400 | |
| 401 std::vector<VASurfaceAttrib> attrib_list( | |
| 402 base::checked_cast<size_t>(num_attribs)); | |
| 403 | |
| 404 va_res = vaQuerySurfaceAttributes( | |
| 405 va_display_, config_id, &attrib_list[0], &num_attribs); | |
| 406 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false); | |
| 407 | |
| 408 resolution->SetSize(0, 0); | |
| 409 for (size_t i = 0; i < num_attribs; i++) { | |
| 410 switch (attrib_list[i].type) { | |
| 411 case VASurfaceAttribMaxWidth: | |
| 412 resolution->set_width(attrib_list[i].value.value.i); | |
| 413 break; | |
| 414 case VASurfaceAttribMaxHeight: | |
| 415 resolution->set_height(attrib_list[i].value.value.i); | |
| 416 break; | |
| 417 default: | |
| 418 break; | |
| 419 } | |
| 420 } | |
| 421 if (!resolution->height() || !resolution->width()) | |
|
wuchengli
2015/02/13 15:38:54
This shouldn't happen. Right? Add LOG(ERROR)
henryhsu
2015/02/13 17:24:28
Done.
| |
| 422 return false; | |
| 423 return true; | |
| 424 } | |
| 425 | |
| 363 bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) { | 426 bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) { |
| 364 if (va_profile == VAProfileNone) { | 427 std::vector<ProfileConfig> profile_configs = (mode == kEncode) ? |
| 365 DVLOG(1) << "Unsupported profile"; | 428 g_profile_config.Get().GetSupportedEncodeProfileConfigs() : |
| 366 return false; | 429 g_profile_config.Get().GetSupportedDecodeProfileConfigs(); |
| 367 } | 430 |
| 368 VAEntrypoint entrypoint = | 431 size_t i; |
| 369 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); | 432 for (i = 0; i < profile_configs.size(); ++i) |
|
wuchengli
2015/02/13 15:38:54
This for loops have two lines. Please add braces f
henryhsu
2015/02/13 17:24:28
Done.
| |
| 370 if (!IsEntrypointSupported(va_profile, entrypoint)) | 433 if (profile_configs[i].va_profile == va_profile) |
| 371 return false; | 434 break; |
| 372 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); | 435 if (i == profile_configs.size()) |
| 373 if (!AreAttribsSupported(va_profile, entrypoint, required_attribs)) | |
| 374 return false; | 436 return false; |
|
wuchengli
2015/02/13 15:38:55
Move line 427-436 to a LazyProfileConfig::IsProfil
henryhsu
2015/02/13 17:24:28
Done.
| |
| 375 | 437 |
| 376 TryToSetVADisplayAttributeToLocalGPU(); | 438 TryToSetVADisplayAttributeToLocalGPU(); |
| 377 | 439 |
| 440 VAEntrypoint entrypoint = | |
| 441 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); | |
| 442 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); | |
| 378 base::AutoLock auto_lock(va_lock_); | 443 base::AutoLock auto_lock(va_lock_); |
| 379 VAStatus va_res = vaCreateConfig(va_display_, | 444 VAStatus va_res = vaCreateConfig(va_display_, |
| 380 va_profile, | 445 va_profile, |
| 381 entrypoint, | 446 entrypoint, |
| 382 &required_attribs[0], | 447 &required_attribs[0], |
| 383 required_attribs.size(), | 448 required_attribs.size(), |
| 384 &va_config_id_); | 449 &va_config_id_); |
| 385 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); | 450 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); |
| 386 | 451 |
| 387 return true; | 452 return true; |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 | 1017 |
| 953 #if defined(USE_X11) | 1018 #if defined(USE_X11) |
| 954 paths[kModuleVa_x11].push_back("libva-x11.so.1"); | 1019 paths[kModuleVa_x11].push_back("libva-x11.so.1"); |
| 955 #elif defined(USE_OZONE) | 1020 #elif defined(USE_OZONE) |
| 956 paths[kModuleVa_drm].push_back("libva-drm.so.1"); | 1021 paths[kModuleVa_drm].push_back("libva-drm.so.1"); |
| 957 #endif | 1022 #endif |
| 958 | 1023 |
| 959 return InitializeStubs(paths); | 1024 return InitializeStubs(paths); |
| 960 } | 1025 } |
| 961 | 1026 |
| 1027 LazyProfileConfig::LazyProfileConfig() { | |
| 1028 std::vector<VaapiWrapper::ProfileConfig> all_profile_configs = | |
| 1029 VaapiWrapper::InitSupportedProfileConfigs(); | |
| 1030 | |
| 1031 for (size_t i = 0; i < all_profile_configs.size(); ++i) { | |
| 1032 switch (all_profile_configs[i].mode) { | |
| 1033 case VaapiWrapper::kEncode: | |
| 1034 supported_encode_profiles_.push_back(all_profile_configs[i]); | |
|
kcwu
2015/02/13 07:15:38
How about define it something like array of vector
henryhsu
2015/02/13 07:35:28
ok. I'll add kCodecMax and CHECK rule.
| |
| 1035 break; | |
| 1036 case VaapiWrapper::kDecode: | |
| 1037 supported_decode_profiles_.push_back(all_profile_configs[i]); | |
| 1038 break; | |
| 1039 default: | |
| 1040 break; | |
|
kcwu
2015/02/13 07:15:38
NOTREACHED
| |
| 1041 } | |
| 1042 } | |
| 1043 } | |
| 1044 | |
| 1045 LazyProfileConfig::~LazyProfileConfig() { | |
| 1046 } | |
| 1047 | |
| 1048 std::vector<VaapiWrapper::ProfileConfig> | |
| 1049 LazyProfileConfig::GetSupportedEncodeProfileConfigs() { | |
| 1050 return supported_encode_profiles_; | |
| 1051 } | |
| 1052 | |
| 1053 std::vector<VaapiWrapper::ProfileConfig> | |
| 1054 LazyProfileConfig::GetSupportedDecodeProfileConfigs() { | |
| 1055 return supported_decode_profiles_; | |
| 1056 } | |
| 1057 | |
| 962 } // namespace content | 1058 } // namespace content |
| OLD | NEW |