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

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: fix nits Created 5 years, 10 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/lazy_instance.h"
Pawel Osciak 2015/03/02 11:00:20 Already in the header.
henryhsu 2015/03/03 10:48:01 Done.
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
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 const int kDefaultFramerate = 30;
wuchengli 2015/03/02 07:10:12 s/kDefaultFramerate/kMaxFramerate/. in VaapiVDA, i
Pawel Osciak 2015/03/02 11:00:20 Please add a comment saying that this is an arbitr
henryhsu 2015/03/03 10:48:02 Done.
henryhsu 2015/03/03 10:48:02 Done.
61
62 base::LazyInstance<VaapiWrapper::LazyProfileInfo>
63 VaapiWrapper::profile_info_ = LAZY_INSTANCE_INITIALIZER;
64
59 // Config attributes common for both encode and decode. 65 // Config attributes common for both encode and decode.
60 static const VAConfigAttrib kCommonVAConfigAttribs[] = { 66 static const VAConfigAttrib kCommonVAConfigAttribs[] = {
61 {VAConfigAttribRTFormat, VA_RT_FORMAT_YUV420}, 67 {VAConfigAttribRTFormat, VA_RT_FORMAT_YUV420},
62 }; 68 };
63 69
64 // Attributes required for encode. 70 // Attributes required for encode.
65 static const VAConfigAttrib kEncodeVAConfigAttribs[] = { 71 static const VAConfigAttrib kEncodeVAConfigAttribs[] = {
66 {VAConfigAttribRateControl, VA_RC_CBR}, 72 {VAConfigAttribRateControl, VA_RC_CBR},
67 {VAConfigAttribEncPackedHeaders, 73 {VAConfigAttribEncPackedHeaders,
68 VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE}, 74 VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE},
69 }; 75 };
70 76
71 struct ProfileMap { 77 struct ProfileMap {
78 VAProfile va_profile;
72 media::VideoCodecProfile profile; 79 media::VideoCodecProfile profile;
73 VAProfile va_profile;
74 }; 80 };
75 81
76 // A map between VideoCodecProfile and VAProfile. 82 // A map between VAProfile and VideoCodecProfile.
77 static const ProfileMap kProfileMap[] = { 83 static const ProfileMap kProfileMap[] = {
78 {media::H264PROFILE_BASELINE, VAProfileH264Baseline}, 84 {VAProfileH264Baseline, media::H264PROFILE_BASELINE},
79 {media::H264PROFILE_MAIN, VAProfileH264Main}, 85 {VAProfileH264Main, media::H264PROFILE_MAIN},
80 // TODO(posciak): See if we can/want support other variants of 86 // TODO(posciak): See if we can/want support other variants of
81 // media::H264PROFILE_HIGH*. 87 // media::H264PROFILE_HIGH*.
82 {media::H264PROFILE_HIGH, VAProfileH264High}, 88 {VAProfileH264High, media::H264PROFILE_HIGH},
89 // crbug.com/345569: media::ProfileIDToVideoCodecProfile() currently strips
90 // the information whether the profile is constrained or not, so we have no
91 // way to know here. We try all va profiles with matched profile in
92 // CreateForVideoCodec. So for H264PROFILE_BASELINE, we try
93 // VAProfileH264Baseline first. If it is not supported, try constrained
94 // baseline and hope this is what it actually is. (which in practice is
95 // true for a great majority of cases).
96 {VAProfileH264ConstrainedBaseline, media::H264PROFILE_BASELINE},
wuchengli 2015/03/02 07:28:32 Move this below VAProfileH264Baseline so two H264P
Pawel Osciak 2015/03/02 11:00:20 How does fallback to Constrained work now?
henryhsu 2015/03/03 10:48:01 Done.
henryhsu 2015/03/03 10:48:01 Change back to original way.
83 }; 97 };
84 98
85 static std::vector<VAConfigAttrib> GetRequiredAttribs( 99 static std::vector<VAConfigAttrib> GetRequiredAttribs(
86 VaapiWrapper::CodecMode mode) { 100 VaapiWrapper::CodecMode mode) {
87 std::vector<VAConfigAttrib> required_attribs; 101 std::vector<VAConfigAttrib> required_attribs;
88 required_attribs.insert( 102 required_attribs.insert(
89 required_attribs.end(), 103 required_attribs.end(),
90 kCommonVAConfigAttribs, 104 kCommonVAConfigAttribs,
91 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs)); 105 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs));
92 if (mode == VaapiWrapper::kEncode) { 106 if (mode == VaapiWrapper::kEncode) {
93 required_attribs.insert( 107 required_attribs.insert(
94 required_attribs.end(), 108 required_attribs.end(),
95 kEncodeVAConfigAttribs, 109 kEncodeVAConfigAttribs,
96 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs)); 110 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs));
97 } 111 }
98 return required_attribs; 112 return required_attribs;
99 } 113 }
100 114
101 // Maps Profile enum values to VaProfile values. 115 // Maps VaProfile enum values to Profile values.
102 static VAProfile ProfileToVAProfile( 116 static media::VideoCodecProfile VAProfileToProfile(VAProfile va_profile) {
103 media::VideoCodecProfile profile, 117 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++) { 118 for (size_t i = 0; i < arraysize(kProfileMap); i++) {
108 if (kProfileMap[i].profile == profile) { 119 if (kProfileMap[i].va_profile == va_profile) {
109 va_profile = kProfileMap[i].va_profile; 120 profile = kProfileMap[i].profile;
110 break; 121 break;
111 } 122 }
112 } 123 }
113 124 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 } 125 }
135 126
136 VASurface::VASurface(VASurfaceID va_surface_id, 127 VASurface::VASurface(VASurfaceID va_surface_id,
137 const gfx::Size& size, 128 const gfx::Size& size,
138 const ReleaseCB& release_cb) 129 const ReleaseCB& release_cb)
139 : va_surface_id_(va_surface_id), size_(size), release_cb_(release_cb) { 130 : va_surface_id_(va_surface_id), size_(size), release_cb_(release_cb) {
140 DCHECK(!release_cb_.is_null()); 131 DCHECK(!release_cb_.is_null());
141 } 132 }
142 133
143 VASurface::~VASurface() { 134 VASurface::~VASurface() {
(...skipping 11 matching lines...) Expand all
155 } 146 }
156 147
157 VaapiWrapper::~VaapiWrapper() { 148 VaapiWrapper::~VaapiWrapper() {
158 DestroyPendingBuffers(); 149 DestroyPendingBuffers();
159 DestroyCodedBuffers(); 150 DestroyCodedBuffers();
160 DestroySurfaces(); 151 DestroySurfaces();
161 DeinitializeVpp(); 152 DeinitializeVpp();
162 Deinitialize(); 153 Deinitialize();
163 } 154 }
164 155
156 // static
165 scoped_ptr<VaapiWrapper> VaapiWrapper::Create( 157 scoped_ptr<VaapiWrapper> VaapiWrapper::Create(
166 CodecMode mode, 158 CodecMode mode,
167 VAProfile va_profile, 159 VAProfile va_profile,
168 const base::Closure& report_error_to_uma_cb) { 160 const base::Closure& report_error_to_uma_cb) {
169 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); 161 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
170 162
171 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) 163 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb))
172 return nullptr; 164 return nullptr;
173 if (!vaapi_wrapper->Initialize(mode, va_profile)) 165
166 if (!vaapi_wrapper->Initialize(mode, va_profile)) {
167 DVLOG(1) << "Unsupported va profile: " << va_profile;
174 return nullptr; 168 return nullptr;
169 }
175 170
176 return vaapi_wrapper.Pass(); 171 return vaapi_wrapper.Pass();
177 } 172 }
178 173
174 // static
179 scoped_ptr<VaapiWrapper> VaapiWrapper::CreateForVideoCodec( 175 scoped_ptr<VaapiWrapper> VaapiWrapper::CreateForVideoCodec(
180 CodecMode mode, 176 CodecMode mode,
181 media::VideoCodecProfile profile, 177 media::VideoCodecProfile profile,
182 const base::Closure& report_error_to_uma_cb) { 178 const base::Closure& report_error_to_uma_cb) {
183 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); 179 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
184 180
185 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) 181 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb))
186 return nullptr; 182 return nullptr;
187 183
188 std::vector<VAProfile> supported_va_profiles; 184 for (size_t i = 0; i < arraysize(kProfileMap); ++i) {
189 if (!vaapi_wrapper->GetSupportedVaProfiles(&supported_va_profiles)) 185 if (kProfileMap[i].profile == profile &&
190 return nullptr; 186 vaapi_wrapper->Initialize(mode, kProfileMap[i].va_profile))
191 187 return vaapi_wrapper.Pass();
192 VAProfile va_profile = ProfileToVAProfile(profile, supported_va_profiles); 188 }
193 if (!vaapi_wrapper->Initialize(mode, va_profile)) 189 DVLOG(1) << "Unsupported profile: " << profile;
Pawel Osciak 2015/03/02 11:00:20 This may also fail if profile is supported, but va
henryhsu 2015/03/03 10:48:02 Done.
194 return nullptr; 190 return nullptr;
195
196 return vaapi_wrapper.Pass();
197 } 191 }
198 192
199 std::vector<media::VideoCodecProfile> VaapiWrapper::GetSupportedEncodeProfiles( 193 // static
200 const base::Closure& report_error_to_uma_cb) { 194 std::vector<media::VideoEncodeAccelerator::SupportedProfile>
201 std::vector<media::VideoCodecProfile> supported_profiles; 195 VaapiWrapper::GetSupportedEncodeProfiles() {
196 std::vector<ProfileInfo> encode_profile_info =
wuchengli 2015/03/02 07:10:12 s/encode_profile_info/encode_profile_infos/
henryhsu 2015/03/03 10:48:01 Done.
197 profile_info_.Get().GetSupportedProfileInfos(kEncode);
198 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles;
199 media::VideoEncodeAccelerator::SupportedProfile profile;
202 200
203 scoped_ptr<VaapiWrapper> wrapper(new VaapiWrapper()); 201 for (size_t i = 0; i < encode_profile_info.size(); ++i) {
204 if (!wrapper->VaInitialize(report_error_to_uma_cb)) { 202 media::VideoCodecProfile hw_profile = VAProfileToProfile(
wuchengli 2015/03/02 07:28:32 As discussed, this can add two media::H264PROFILE_
henryhsu 2015/03/03 10:48:01 Done.
205 return supported_profiles; 203 encode_profile_info[i].va_profile);
206 } 204 if (hw_profile != media::VIDEO_CODEC_PROFILE_UNKNOWN) {
207 205 profile.profile = hw_profile;
208 std::vector<VAProfile> va_profiles; 206 profile.max_resolution = encode_profile_info[i].max_resolution;
209 if (!wrapper->GetSupportedVaProfiles(&va_profiles)) 207 profile.max_framerate_numerator = kDefaultFramerate;
210 return supported_profiles; 208 profile.max_framerate_denominator = 1;
211 209 profiles.push_back(profile);
212 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(kEncode);
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 } 210 }
222 } 211 }
223 return supported_profiles; 212 return profiles;
213 }
214
215 // static
216 std::vector<VaapiWrapper::ProfileInfo>
wuchengli 2015/03/02 07:10:12 InitSupportedProfileInfos should be renamed.
henryhsu 2015/03/03 10:48:01 Done.
217 VaapiWrapper::InitSupportedProfileInfos() {
wuchengli 2015/03/02 07:10:12 How about adding CodecMode parameter to InitSuppor
henryhsu 2015/03/03 10:48:01 Done.
218 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
219 if (!vaapi_wrapper->VaInitialize(base::Bind(&base::DoNothing)))
220 return std::vector<ProfileInfo>();
221 return vaapi_wrapper->GetSupportedProfileInfos();
224 } 222 }
225 223
226 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { 224 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() {
227 base::AutoLock auto_lock(va_lock_); 225 base::AutoLock auto_lock(va_lock_);
228 VADisplayAttribute item = {VADisplayAttribRenderMode, 226 VADisplayAttribute item = {VADisplayAttribRenderMode,
229 1, // At least support '_LOCAL_OVERLAY'. 227 1, // At least support '_LOCAL_OVERLAY'.
230 -1, // The maximum possible support 'ALL'. 228 -1, // The maximum possible support 'ALL'.
231 VA_RENDER_MODE_LOCAL_GPU, 229 VA_RENDER_MODE_LOCAL_GPU,
232 VA_DISPLAY_ATTRIB_SETTABLE}; 230 VA_DISPLAY_ATTRIB_SETTABLE};
233 231
234 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1); 232 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1);
235 if (va_res != VA_STATUS_SUCCESS) 233 if (va_res != VA_STATUS_SUCCESS)
236 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default."; 234 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default.";
237 } 235 }
238 236
237 std::vector<VaapiWrapper::ProfileInfo>
238 VaapiWrapper::GetSupportedProfileInfos() {
239 std::vector<ProfileInfo> supported_profiles;
wuchengli 2015/03/02 07:10:12 s/supported_profiles/supported_profile_infos/. Let
henryhsu 2015/03/03 10:48:02 Done.
240 std::vector<VAProfile> va_profiles;
241 if (!GetSupportedVaProfiles(&va_profiles))
242 return supported_profiles;
243
244 ProfileInfo profile_info;
245 std::vector<CodecMode> modes({kDecode, kEncode});
246 for (size_t i = 0; i < modes.size(); ++i) {
247 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(modes[i]);
248 VAEntrypoint entrypoint =
249 (modes[i] == kEncode ? VAEntrypointEncSlice: VAEntrypointVLD);
250 for (size_t j = 0; j < va_profiles.size(); ++j) {
251 if (!IsEntrypointSupported(va_profiles[j], entrypoint))
252 continue;
253 if (!AreAttribsSupported(va_profiles[j], entrypoint, required_attribs))
254 continue;
255 VAConfigID config_id;
256 VAStatus va_res = vaCreateConfig(
257 va_display_,
258 va_profiles[j],
259 entrypoint,
260 &required_attribs[0],
261 required_attribs.size(),
262 &config_id);
263 if (va_res != VA_STATUS_SUCCESS)
264 continue;
265 if (!GetVaCodecMaxResolution(config_id, &profile_info.max_resolution))
266 continue;
267 profile_info.va_profile = va_profiles[j];
268 profile_info.mode = modes[i];
269 supported_profiles.push_back(profile_info);
270 }
271 }
272 return supported_profiles;
273 }
274
239 bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) { 275 bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) {
240 static bool vaapi_functions_initialized = PostSandboxInitialization(); 276 static bool vaapi_functions_initialized = PostSandboxInitialization();
241 if (!vaapi_functions_initialized) { 277 if (!vaapi_functions_initialized) {
242 bool running_on_chromeos = false; 278 bool running_on_chromeos = false;
243 #if defined(OS_CHROMEOS) 279 #if defined(OS_CHROMEOS)
244 // When chrome runs on linux with chromeos=1, do not log error message 280 // When chrome runs on linux with chromeos=1, do not log error message
245 // without VAAPI libraries. 281 // without VAAPI libraries.
246 running_on_chromeos = base::SysInfo::IsRunningOnChromeOS(); 282 running_on_chromeos = base::SysInfo::IsRunningOnChromeOS();
247 #endif 283 #endif
248 static const char kErrorMsg[] = "Failed to initialize VAAPI libs"; 284 static const char kErrorMsg[] = "Failed to initialize VAAPI libs";
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 (attribs[i].value & required_attribs[i].value) != 389 (attribs[i].value & required_attribs[i].value) !=
354 required_attribs[i].value) { 390 required_attribs[i].value) {
355 DVLOG(1) << "Unsupported value " << required_attribs[i].value 391 DVLOG(1) << "Unsupported value " << required_attribs[i].value
356 << " for attribute type " << required_attribs[i].type; 392 << " for attribute type " << required_attribs[i].type;
357 return false; 393 return false;
358 } 394 }
359 } 395 }
360 return true; 396 return true;
361 } 397 }
362 398
399 bool VaapiWrapper::GetVaCodecMaxResolution(VAConfigID config_id,
400 gfx::Size* resolution) {
401 base::AutoLock auto_lock(va_lock_);
402 unsigned int num_attribs;
403 VAStatus va_res;
Pawel Osciak 2015/03/02 11:00:20 Please define each variable just before use.
henryhsu 2015/03/03 10:48:01 Done.
404
405 va_res = vaQuerySurfaceAttributes(
Pawel Osciak 2015/03/02 11:00:20 Please add a comment why we are calling this twic
henryhsu 2015/03/03 10:48:02 Done.
406 va_display_, config_id, NULL, &num_attribs);
407 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false);
408
409 std::vector<VASurfaceAttrib> attrib_list(
Pawel Osciak 2015/03/02 11:00:20 Probably better to check if num_attribs != 0?
henryhsu 2015/03/03 10:48:01 Done.
410 base::checked_cast<size_t>(num_attribs));
411
412 va_res = vaQuerySurfaceAttributes(
413 va_display_, config_id, &attrib_list[0], &num_attribs);
414 VA_SUCCESS_OR_RETURN(va_res, "vaQuerySurfaceAttributes failed", false);
415
416 resolution->SetSize(0, 0);
417 for (size_t i = 0; i < num_attribs; i++) {
418 switch (attrib_list[i].type) {
wuchengli 2015/03/02 07:10:12 nit: using if clause can have less code. Up to you
henryhsu 2015/03/03 10:48:01 Done.
419 case VASurfaceAttribMaxWidth:
420 resolution->set_width(attrib_list[i].value.value.i);
421 break;
422 case VASurfaceAttribMaxHeight:
423 resolution->set_height(attrib_list[i].value.value.i);
424 break;
425 default:
426 break;
427 }
428 }
429 if (!resolution->height() || !resolution->width()) {
kcwu 2015/03/02 14:02:18 resolution->IsEmpty()
henryhsu 2015/03/03 10:48:01 Done.
430 LOG(ERROR) << "Codec resolution cannot be zero.";
wuchengli 2015/03/02 07:10:12 also print resolution->ToString().
henryhsu 2015/03/03 10:48:01 Done.
431 return false;
432 }
433 return true;
434 }
435
363 bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) { 436 bool VaapiWrapper::Initialize(CodecMode mode, VAProfile va_profile) {
364 if (va_profile == VAProfileNone) { 437 if (!profile_info_.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; 438 return false;
375 439
376 TryToSetVADisplayAttributeToLocalGPU(); 440 TryToSetVADisplayAttributeToLocalGPU();
377 441
442 VAEntrypoint entrypoint =
443 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD);
444 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode);
378 base::AutoLock auto_lock(va_lock_); 445 base::AutoLock auto_lock(va_lock_);
379 VAStatus va_res = vaCreateConfig(va_display_, 446 VAStatus va_res = vaCreateConfig(va_display_,
380 va_profile, 447 va_profile,
381 entrypoint, 448 entrypoint,
382 &required_attribs[0], 449 &required_attribs[0],
383 required_attribs.size(), 450 required_attribs.size(),
384 &va_config_id_); 451 &va_config_id_);
385 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false); 452 VA_SUCCESS_OR_RETURN(va_res, "vaCreateConfig failed", false);
386 453
387 return true; 454 return true;
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 1019
953 #if defined(USE_X11) 1020 #if defined(USE_X11)
954 paths[kModuleVa_x11].push_back("libva-x11.so.1"); 1021 paths[kModuleVa_x11].push_back("libva-x11.so.1");
955 #elif defined(USE_OZONE) 1022 #elif defined(USE_OZONE)
956 paths[kModuleVa_drm].push_back("libva-drm.so.1"); 1023 paths[kModuleVa_drm].push_back("libva-drm.so.1");
957 #endif 1024 #endif
958 1025
959 return InitializeStubs(paths); 1026 return InitializeStubs(paths);
960 } 1027 }
961 1028
1029 VaapiWrapper::LazyProfileInfo::LazyProfileInfo() {
1030 std::vector<VaapiWrapper::ProfileInfo> all_profile_info =
1031 VaapiWrapper::InitSupportedProfileInfos();
1032
1033 for (size_t i = 0; i < all_profile_info.size(); ++i) {
kcwu 2015/03/02 14:02:18 how about for (const auto& info : all_profile_info
henryhsu 2015/03/03 10:48:02 Done.
1034 supported_profiles_[all_profile_info[i].mode].push_back(
1035 all_profile_info[i]);
1036 }
1037 }
1038
1039 VaapiWrapper::LazyProfileInfo::~LazyProfileInfo() {
1040 }
1041
1042 std::vector<VaapiWrapper::ProfileInfo>
1043 VaapiWrapper::LazyProfileInfo::GetSupportedProfileInfos(
Pawel Osciak 2015/03/02 11:00:20 GetSupportedProfileInfosForCodecMode
henryhsu 2015/03/03 10:48:01 Done.
1044 VaapiWrapper::CodecMode mode) {
1045 CHECK(mode < VaapiWrapper::kCodecModeMax);
wuchengli 2015/03/02 07:10:12 Use DCHECK. See http://www.chromium.org/developers
Pawel Osciak 2015/03/02 11:00:20 I'd prefer if. Also, better to compare against sup
henryhsu 2015/03/03 10:48:01 supported_profiles_ is an array instead of class o
henryhsu 2015/03/03 10:48:02 Done.
1046 return supported_profiles_[mode];
1047 }
1048
1049 bool VaapiWrapper::LazyProfileInfo::IsProfileSupported(
1050 VaapiWrapper::CodecMode mode, VAProfile va_profile) {
1051 for (size_t i = 0; i < supported_profiles_[mode].size(); ++i) {
Pawel Osciak 2015/03/02 11:00:20 for (const auto& profile : supported_profiles_[mod
henryhsu 2015/03/03 10:48:02 Done.
1052 if (supported_profiles_[mode][i].va_profile == va_profile)
1053 return true;
1054 }
1055 return false;
1056 }
1057
962 } // namespace content 1058 } // 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