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

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