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

Side by Side Diff: content/common/gpu/media/vaapi_wrapper.cc

Issue 825843002: Add JPEG decoder for VAAPI JPEG decode acceleration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mjpeg-vaapi-jpeg-parser
Patch Set: 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
« no previous file with comments | « content/common/gpu/media/vaapi_wrapper.h ('k') | content/content_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
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))
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))
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 (attribs[i].value & required_attribs[i].value) != 353 (attribs[i].value & required_attribs[i].value) !=
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, VAProfile va_profile) {
342 media::VideoCodecProfile profile,
343 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) { 364 if (va_profile == VAProfileNone) {
351 DVLOG(1) << "Unsupported profile"; 365 DVLOG(1) << "Unsupported profile";
352 return false; 366 return false;
353 } 367 }
354 VAEntrypoint entrypoint = 368 VAEntrypoint entrypoint =
355 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD); 369 (mode == kEncode ? VAEntrypointEncSlice : VAEntrypointVLD);
356 if (!IsEntrypointSupported(va_profile, entrypoint)) 370 if (!IsEntrypointSupported(va_profile, entrypoint))
357 return false; 371 return false;
358 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode); 372 std::vector<VAConfigAttrib> required_attribs = GetRequiredAttribs(mode);
359 if (!AreAttribsSupported(va_profile, entrypoint, required_attribs)) 373 if (!AreAttribsSupported(va_profile, entrypoint, required_attribs))
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 va_surface_id, 672 va_surface_id,
659 x_pixmap, 673 x_pixmap,
660 0, 0, dest_size.width(), dest_size.height(), 674 0, 0, dest_size.width(), dest_size.height(),
661 0, 0, dest_size.width(), dest_size.height(), 675 0, 0, dest_size.width(), dest_size.height(),
662 NULL, 0, 0); 676 NULL, 0, 0);
663 VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false); 677 VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false);
664 return true; 678 return true;
665 } 679 }
666 #endif // USE_X11 680 #endif // USE_X11
667 681
668 bool VaapiWrapper::GetVaImageForTesting(VASurfaceID va_surface_id, 682 bool VaapiWrapper::GetDerivedVaImage(VASurfaceID va_surface_id,
669 VAImage* image, 683 VAImage* image,
670 void** mem) { 684 void** mem) {
671 base::AutoLock auto_lock(va_lock_); 685 base::AutoLock auto_lock(va_lock_);
672 686
673 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); 687 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
674 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); 688 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false);
675 689
676 // Derive a VAImage from the VASurface 690 // Derive a VAImage from the VASurface
677 va_res = vaDeriveImage(va_display_, va_surface_id, image); 691 va_res = vaDeriveImage(va_display_, va_surface_id, image);
678 VA_LOG_ON_ERROR(va_res, "vaDeriveImage failed"); 692 VA_LOG_ON_ERROR(va_res, "vaDeriveImage failed");
679 if (va_res != VA_STATUS_SUCCESS) 693 if (va_res != VA_STATUS_SUCCESS)
680 return false; 694 return false;
681 695
682 // Map the VAImage into memory 696 // Map the VAImage into memory
683 va_res = vaMapBuffer(va_display_, image->buf, mem); 697 va_res = vaMapBuffer(va_display_, image->buf, mem);
684 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed"); 698 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed");
685 if (va_res == VA_STATUS_SUCCESS) 699 if (va_res == VA_STATUS_SUCCESS)
686 return true; 700 return true;
687 701
688 va_res = vaDestroyImage(va_display_, image->image_id); 702 va_res = vaDestroyImage(va_display_, image->image_id);
689 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); 703 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed");
690 704
691 return false; 705 return false;
692 } 706 }
693 707
694 void VaapiWrapper::ReturnVaImageForTesting(VAImage* image) { 708 bool VaapiWrapper::GetVaImage(VASurfaceID va_surface_id,
709 VAImageFormat* format,
710 const gfx::Size& size,
711 VAImage* image,
712 void** mem) {
713 base::AutoLock auto_lock(va_lock_);
714
715 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
716 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false);
717
718 va_res =
719 vaCreateImage(va_display_, format, size.width(), size.height(), image);
720 VA_SUCCESS_OR_RETURN(va_res, "vaCreateImage failed", false);
721
722 va_res = vaGetImage(va_display_, va_surface_id, 0, 0, size.width(),
723 size.height(), image->image_id);
724 VA_LOG_ON_ERROR(va_res, "vaGetImage failed");
725
726 if (va_res == VA_STATUS_SUCCESS) {
727 // Map the VAImage into memory
728 va_res = vaMapBuffer(va_display_, image->buf, mem);
729 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed");
730 }
731
732 if (va_res != VA_STATUS_SUCCESS) {
733 va_res = vaDestroyImage(va_display_, image->image_id);
734 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed");
735 return false;
736 }
737
738 return true;
739 }
740
741 void VaapiWrapper::ReturnVaImage(VAImage* image) {
695 base::AutoLock auto_lock(va_lock_); 742 base::AutoLock auto_lock(va_lock_);
696 743
697 VAStatus va_res = vaUnmapBuffer(va_display_, image->buf); 744 VAStatus va_res = vaUnmapBuffer(va_display_, image->buf);
698 VA_LOG_ON_ERROR(va_res, "vaUnmapBuffer failed"); 745 VA_LOG_ON_ERROR(va_res, "vaUnmapBuffer failed");
699 746
700 va_res = vaDestroyImage(va_display_, image->image_id); 747 va_res = vaDestroyImage(va_display_, image->image_id);
701 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); 748 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed");
702 } 749 }
703 750
704 static void DestroyVAImage(VADisplay va_display, VAImage image) { 751 static void DestroyVAImage(VADisplay va_display, VAImage image) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 #if defined(USE_X11) 953 #if defined(USE_X11)
907 paths[kModuleVa_x11].push_back("libva-x11.so.1"); 954 paths[kModuleVa_x11].push_back("libva-x11.so.1");
908 #elif defined(USE_OZONE) 955 #elif defined(USE_OZONE)
909 paths[kModuleVa_drm].push_back("libva-drm.so.1"); 956 paths[kModuleVa_drm].push_back("libva-drm.so.1");
910 #endif 957 #endif
911 958
912 return InitializeStubs(paths); 959 return InitializeStubs(paths);
913 } 960 }
914 961
915 } // namespace content 962 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_wrapper.h ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698