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" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 VAProfile va_profile; | 62 VAProfile va_profile; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // A map between VideoCodecProfile and VAProfile. | 65 // A map between VideoCodecProfile and VAProfile. |
| 66 static const ProfileMap kProfileMap[] = { | 66 static const ProfileMap kProfileMap[] = { |
| 67 {media::H264PROFILE_BASELINE, VAProfileH264Baseline}, | 67 {media::H264PROFILE_BASELINE, VAProfileH264Baseline}, |
| 68 {media::H264PROFILE_MAIN, VAProfileH264Main}, | 68 {media::H264PROFILE_MAIN, VAProfileH264Main}, |
| 69 // TODO(posciak): See if we can/want support other variants of | 69 // TODO(posciak): See if we can/want support other variants of |
| 70 // media::H264PROFILE_HIGH*. | 70 // media::H264PROFILE_HIGH*. |
| 71 {media::H264PROFILE_HIGH, VAProfileH264High}, | 71 {media::H264PROFILE_HIGH, VAProfileH264High}, |
| 72 {media::MJPEGPROFILE, VAProfileJPEGBaseline}, | |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 static std::vector<VAConfigAttrib> GetRequiredAttribs( | 75 static std::vector<VAConfigAttrib> GetRequiredAttribs( |
| 75 VaapiWrapper::CodecMode mode) { | 76 VaapiWrapper::CodecMode mode) { |
| 76 std::vector<VAConfigAttrib> required_attribs; | 77 std::vector<VAConfigAttrib> required_attribs; |
| 77 required_attribs.insert( | 78 required_attribs.insert( |
| 78 required_attribs.end(), | 79 required_attribs.end(), |
| 79 kCommonVAConfigAttribs, | 80 kCommonVAConfigAttribs, |
| 80 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs)); | 81 kCommonVAConfigAttribs + arraysize(kCommonVAConfigAttribs)); |
| 81 if (mode == VaapiWrapper::kEncode) { | 82 if (mode == VaapiWrapper::kEncode) { |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed"); | 613 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed"); |
| 613 if (va_res == VA_STATUS_SUCCESS) | 614 if (va_res == VA_STATUS_SUCCESS) |
| 614 return true; | 615 return true; |
| 615 | 616 |
| 616 va_res = vaDestroyImage(va_display_, image->image_id); | 617 va_res = vaDestroyImage(va_display_, image->image_id); |
| 617 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); | 618 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); |
| 618 | 619 |
| 619 return false; | 620 return false; |
| 620 } | 621 } |
| 621 | 622 |
| 623 bool VaapiWrapper::GetVaImageWithFormat(VASurfaceID va_surface_id, | |
|
wuchengli
2015/01/12 09:08:53
Is CreateVaImage better? This actually passes form
kcwu
2015/01/16 15:12:56
Done.
In order to emphasis its difference to GetVa
| |
| 624 VAImageFormat* format, | |
| 625 gfx::Size size, | |
| 626 VAImage* image, | |
| 627 void** mem) { | |
| 628 base::AutoLock auto_lock(va_lock_); | |
| 629 | |
| 630 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); | |
| 631 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); | |
| 632 | |
| 633 va_res = | |
| 634 vaCreateImage(va_display_, format, size.width(), size.height(), image); | |
| 635 VA_LOG_ON_ERROR(va_res, "vaCreateImage failed"); | |
|
wuchengli
2015/01/12 09:08:53
VA_SUCCESS_OR_RETURN
kcwu
2015/01/16 15:12:56
Done.
| |
| 636 if (va_res != VA_STATUS_SUCCESS) | |
| 637 return false; | |
| 638 | |
| 639 va_res = vaGetImage(va_display_, va_surface_id, 0, 0, size.width(), | |
| 640 size.height(), image->image_id); | |
| 641 VA_LOG_ON_ERROR(va_res, "vaDeriveImage failed"); | |
|
wuchengli
2015/01/12 09:08:53
s/vaDeriveImage/vaGetImage/ and VA_SUCCESS_OR_RETU
kcwu
2015/01/16 15:12:56
Done.
| |
| 642 if (va_res != VA_STATUS_SUCCESS) | |
|
Owen Lin
2015/01/13 06:17:59
free the resource of image (since it has been crea
kcwu
2015/01/16 15:12:56
Done.
| |
| 643 return false; | |
| 644 | |
| 645 // Map the VAImage into memory | |
| 646 va_res = vaMapBuffer(va_display_, image->buf, mem); | |
| 647 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed"); | |
| 648 if (va_res == VA_STATUS_SUCCESS) | |
| 649 return true; | |
| 650 | |
| 651 va_res = vaDestroyImage(va_display_, image->image_id); | |
| 652 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); | |
| 653 | |
| 654 return false; | |
|
wuchengli
2015/01/12 09:08:53
It's easier to understand to return true at the en
Owen Lin
2015/01/13 06:17:59
+1
kcwu
2015/01/16 15:12:56
Since I need to call vaDestroyImage for failed cas
| |
| 655 } | |
| 656 | |
| 622 void VaapiWrapper::ReturnVaImageForTesting(VAImage* image) { | 657 void VaapiWrapper::ReturnVaImageForTesting(VAImage* image) { |
| 623 base::AutoLock auto_lock(va_lock_); | 658 base::AutoLock auto_lock(va_lock_); |
| 624 | 659 |
| 625 VAStatus va_res = vaUnmapBuffer(va_display_, image->buf); | 660 VAStatus va_res = vaUnmapBuffer(va_display_, image->buf); |
| 626 VA_LOG_ON_ERROR(va_res, "vaUnmapBuffer failed"); | 661 VA_LOG_ON_ERROR(va_res, "vaUnmapBuffer failed"); |
| 627 | 662 |
| 628 va_res = vaDestroyImage(va_display_, image->image_id); | 663 va_res = vaDestroyImage(va_display_, image->image_id); |
| 629 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); | 664 VA_LOG_ON_ERROR(va_res, "vaDestroyImage failed"); |
| 630 } | 665 } |
| 631 | 666 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 | 770 |
| 736 // static | 771 // static |
| 737 bool VaapiWrapper::PostSandboxInitialization() { | 772 bool VaapiWrapper::PostSandboxInitialization() { |
| 738 StubPathMap paths; | 773 StubPathMap paths; |
| 739 paths[kModuleVa].push_back(kVaLib); | 774 paths[kModuleVa].push_back(kVaLib); |
| 740 | 775 |
| 741 return InitializeStubs(paths); | 776 return InitializeStubs(paths); |
| 742 } | 777 } |
| 743 | 778 |
| 744 } // namespace content | 779 } // namespace content |
| OLD | NEW |