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" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 VaapiWrapper::~VaapiWrapper() { | 157 VaapiWrapper::~VaapiWrapper() { |
158 DestroyPendingBuffers(); | 158 DestroyPendingBuffers(); |
159 DestroyCodedBuffers(); | 159 DestroyCodedBuffers(); |
160 DestroySurfaces(); | 160 DestroySurfaces(); |
161 DeinitializeVpp(); | 161 DeinitializeVpp(); |
162 Deinitialize(); | 162 Deinitialize(); |
163 } | 163 } |
164 | 164 |
165 scoped_ptr<VaapiWrapper> VaapiWrapper::Create( | 165 scoped_ptr<VaapiWrapper> VaapiWrapper::Create( |
166 CodecMode mode, | 166 CodecMode mode, |
| 167 VAProfile va_profile, |
| 168 const base::Closure& report_error_to_uma_cb) { |
| 169 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); |
| 170 |
| 171 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) |
| 172 return nullptr; |
| 173 if (!vaapi_wrapper->Initialize(mode, va_profile, report_error_to_uma_cb)) |
| 174 return nullptr; |
| 175 |
| 176 return vaapi_wrapper.Pass(); |
| 177 } |
| 178 |
| 179 scoped_ptr<VaapiWrapper> VaapiWrapper::CreateForVideoCodec( |
| 180 CodecMode mode, |
167 media::VideoCodecProfile profile, | 181 media::VideoCodecProfile profile, |
168 const base::Closure& report_error_to_uma_cb) { | 182 const base::Closure& report_error_to_uma_cb) { |
169 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); | 183 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); |
170 | 184 |
171 if (!vaapi_wrapper->Initialize(mode, profile, report_error_to_uma_cb)) | 185 if (!vaapi_wrapper->VaInitialize(report_error_to_uma_cb)) |
172 vaapi_wrapper.reset(); | 186 return nullptr; |
| 187 |
| 188 std::vector<VAProfile> supported_va_profiles; |
| 189 if (!vaapi_wrapper->GetSupportedVaProfiles(&supported_va_profiles)) |
| 190 return nullptr; |
| 191 |
| 192 VAProfile va_profile = ProfileToVAProfile(profile, supported_va_profiles); |
| 193 if (!vaapi_wrapper->Initialize(mode, va_profile, report_error_to_uma_cb)) |
| 194 return nullptr; |
173 | 195 |
174 return vaapi_wrapper.Pass(); | 196 return vaapi_wrapper.Pass(); |
175 } | 197 } |
176 | 198 |
177 std::vector<media::VideoCodecProfile> VaapiWrapper::GetSupportedEncodeProfiles( | 199 std::vector<media::VideoCodecProfile> VaapiWrapper::GetSupportedEncodeProfiles( |
178 const base::Closure& report_error_to_uma_cb) { | 200 const base::Closure& report_error_to_uma_cb) { |
179 std::vector<media::VideoCodecProfile> supported_profiles; | 201 std::vector<media::VideoCodecProfile> supported_profiles; |
180 | 202 |
181 scoped_ptr<VaapiWrapper> wrapper(new VaapiWrapper()); | 203 scoped_ptr<VaapiWrapper> wrapper(new VaapiWrapper()); |
182 if (!wrapper->VaInitialize(report_error_to_uma_cb)) { | 204 if (!wrapper->VaInitialize(report_error_to_uma_cb)) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 required_attribs[i].value) { | 354 required_attribs[i].value) { |
333 DVLOG(1) << "Unsupported value " << required_attribs[i].value | 355 DVLOG(1) << "Unsupported value " << required_attribs[i].value |
334 << " for attribute type " << required_attribs[i].type; | 356 << " for attribute type " << required_attribs[i].type; |
335 return false; | 357 return false; |
336 } | 358 } |
337 } | 359 } |
338 return true; | 360 return true; |
339 } | 361 } |
340 | 362 |
341 bool VaapiWrapper::Initialize(CodecMode mode, | 363 bool VaapiWrapper::Initialize(CodecMode mode, |
342 media::VideoCodecProfile profile, | 364 VAProfile va_profile, |
343 const base::Closure& report_error_to_uma_cb) { | 365 const base::Closure& report_error_to_uma_cb) { |
344 if (!VaInitialize(report_error_to_uma_cb)) | |
345 return false; | |
346 std::vector<VAProfile> supported_va_profiles; | |
347 if (!GetSupportedVaProfiles(&supported_va_profiles)) | |
348 return false; | |
349 VAProfile va_profile = ProfileToVAProfile(profile, supported_va_profiles); | |
350 if (va_profile == VAProfileNone) { | 366 if (va_profile == VAProfileNone) { |
351 DVLOG(1) << "Unsupported profile"; | 367 DVLOG(1) << "Unsupported profile"; |
352 return false; | 368 return false; |
353 } | 369 } |
354 VAEntrypoint entrypoint = | 370 VAEntrypoint entrypoint = |
355 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); | 371 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); |
356 if (!IsEntrypointSupported(va_profile, entrypoint)) | 372 if (!IsEntrypointSupported(va_profile, entrypoint)) |
357 return false; | 373 return false; |
358 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); | 374 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); |
359 if (!AreAttribsSupported(va_profile, entrypoint, required_attribs)) | 375 if (!AreAttribsSupported(va_profile, entrypoint, required_attribs)) |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 va_surface_id, | 674 va_surface_id, |
659 x_pixmap, | 675 x_pixmap, |
660 0, 0, dest_size.width(), dest_size.height(), | 676 0, 0, dest_size.width(), dest_size.height(), |
661 0, 0, dest_size.width(), dest_size.height(), | 677 0, 0, dest_size.width(), dest_size.height(), |
662 NULL, 0, 0); | 678 NULL, 0, 0); |
663 VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false); | 679 VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false); |
664 return true; | 680 return true; |
665 } | 681 } |
666 #endif // USE_X11 | 682 #endif // USE_X11 |
667 | 683 |
668 bool VaapiWrapper::GetVaImageForTesting(VASurfaceID va_surface_id, | 684 bool VaapiWrapper::GetDerivedVaImageForTesting(VASurfaceID va_surface_id, |
669 VAImage* image, | 685 VAImage* image, |
670 void** mem) { | 686 void** mem) { |
671 base::AutoLock auto_lock(va_lock_); | 687 base::AutoLock auto_lock(va_lock_); |
672 | 688 |
673 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); | 689 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); |
674 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); | 690 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
675 | 691 |
676 // Derive a VAImage from the VASurface | 692 // Derive a VAImage from the VASurface |
677 va_res = vaDeriveImage(va_display_, va_surface_id, image); | 693 va_res = vaDeriveImage(va_display_, va_surface_id, image); |
678 VA_LOG_ON_ERROR(va_res, "vaDeriveImage failed"); | 694 VA_LOG_ON_ERROR(va_res, "vaDeriveImage failed"); |
679 if (va_res != VA_STATUS_SUCCESS) | 695 if (va_res != VA_STATUS_SUCCESS) |
680 return false; | 696 return false; |
681 | 697 |
682 // Map the VAImage into memory | 698 // Map the VAImage into memory |
683 va_res = vaMapBuffer(va_display_, image->buf, mem); | 699 va_res = vaMapBuffer(va_display_, image->buf, mem); |
684 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed"); | 700 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed"); |
685 if (va_res == VA_STATUS_SUCCESS) | 701 if (va_res == VA_STATUS_SUCCESS) |
686 return true; | 702 return true; |
687 | 703 |
688 va_res = vaDestroyImage(va_display_, image->image_id); | 704 va_res = vaDestroyImage(va_display_, image->image_id); |
689 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); | 705 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); |
690 | 706 |
691 return false; | 707 return false; |
692 } | 708 } |
693 | 709 |
694 void VaapiWrapper::ReturnVaImageForTesting(VAImage* image) { | 710 bool VaapiWrapper::GetVaImage(VASurfaceID va_surface_id, |
| 711 VAImageFormat* format, |
| 712 const gfx::Size& size, |
| 713 VAImage* image, |
| 714 void** mem) { |
| 715 base::AutoLock auto_lock(va_lock_); |
| 716 |
| 717 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); |
| 718 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
| 719 |
| 720 va_res = |
| 721 vaCreateImage(va_display_, format, size.width(), size.height(), image); |
| 722 VA_SUCCESS_OR_RETURN(va_res, "vaCreateImage failed", false); |
| 723 |
| 724 va_res = vaGetImage(va_display_, va_surface_id, 0, 0, size.width(), |
| 725 size.height(), image->image_id); |
| 726 VA_LOG_ON_ERROR(va_res, "vaGetImage failed"); |
| 727 |
| 728 if (va_res == VA_STATUS_SUCCESS) { |
| 729 // Map the VAImage into memory |
| 730 va_res = vaMapBuffer(va_display_, image->buf, mem); |
| 731 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed"); |
| 732 } |
| 733 |
| 734 if (va_res != VA_STATUS_SUCCESS) { |
| 735 va_res = vaDestroyImage(va_display_, image->image_id); |
| 736 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); |
| 737 } |
| 738 |
| 739 return va_res == VA_STATUS_SUCCESS; |
| 740 } |
| 741 |
| 742 void VaapiWrapper::ReturnVaImage(VAImage* image) { |
695 base::AutoLock auto_lock(va_lock_); | 743 base::AutoLock auto_lock(va_lock_); |
696 | 744 |
697 VAStatus va_res = vaUnmapBuffer(va_display_, image->buf); | 745 VAStatus va_res = vaUnmapBuffer(va_display_, image->buf); |
698 VA_LOG_ON_ERROR(va_res, "vaUnmapBuffer failed"); | 746 VA_LOG_ON_ERROR(va_res, "vaUnmapBuffer failed"); |
699 | 747 |
700 va_res = vaDestroyImage(va_display_, image->image_id); | 748 va_res = vaDestroyImage(va_display_, image->image_id); |
701 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); | 749 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); |
702 } | 750 } |
703 | 751 |
704 static void DestroyVAImage(VADisplay va_display, VAImage image) { | 752 static void DestroyVAImage(VADisplay va_display, VAImage image) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 #if defined(USE_X11) | 954 #if defined(USE_X11) |
907 paths[kModuleVa_x11].push_back("libva-x11.so.1"); | 955 paths[kModuleVa_x11].push_back("libva-x11.so.1"); |
908 #elif defined(USE_OZONE) | 956 #elif defined(USE_OZONE) |
909 paths[kModuleVa_drm].push_back("libva-drm.so.1"); | 957 paths[kModuleVa_drm].push_back("libva-drm.so.1"); |
910 #endif | 958 #endif |
911 | 959 |
912 return InitializeStubs(paths); | 960 return InitializeStubs(paths); |
913 } | 961 } |
914 | 962 |
915 } // namespace content | 963 } // namespace content |
OLD | NEW |