OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "media/gpu/android_video_decode_accelerator.h" | 5 #include "media/gpu/android_video_decode_accelerator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 // Only support VP8 on Android versions where we don't have to synchronously | 1566 // Only support VP8 on Android versions where we don't have to synchronously |
1567 // tear down the MediaCodec on surface destruction because VP8 requires | 1567 // tear down the MediaCodec on surface destruction because VP8 requires |
1568 // us to completely drain the decoder before releasing it, which is difficult | 1568 // us to completely drain the decoder before releasing it, which is difficult |
1569 // and time consuming to do while the surface is being destroyed. | 1569 // and time consuming to do while the surface is being destroyed. |
1570 if (base::android::BuildInfo::GetInstance()->sdk_int() >= 18 && | 1570 if (base::android::BuildInfo::GetInstance()->sdk_int() >= 18 && |
1571 MediaCodecUtil::IsVp8DecoderAvailable()) { | 1571 MediaCodecUtil::IsVp8DecoderAvailable()) { |
1572 SupportedProfile profile; | 1572 SupportedProfile profile; |
1573 profile.profile = VP8PROFILE_ANY; | 1573 profile.profile = VP8PROFILE_ANY; |
1574 // Since there is little to no power benefit below 360p, don't advertise | 1574 // Since there is little to no power benefit below 360p, don't advertise |
1575 // support for it. Let libvpx decode it, and save a MediaCodec instance. | 1575 // support for it. Let libvpx decode it, and save a MediaCodec instance. |
| 1576 // Note that we allow it anyway for encrypted content, since we push a |
| 1577 // separate profile for that. |
1576 profile.min_resolution.SetSize(480, 360); | 1578 profile.min_resolution.SetSize(480, 360); |
1577 profile.max_resolution.SetSize(3840, 2160); | 1579 profile.max_resolution.SetSize(3840, 2160); |
1578 // If we know MediaCodec will just create a software codec, prefer our | 1580 // If we know MediaCodec will just create a software codec, prefer our |
1579 // internal software decoder instead. It's more up to date and secured | 1581 // internal software decoder instead. It's more up to date and secured |
1580 // within the renderer sandbox. However if the content is encrypted, we | 1582 // within the renderer sandbox. However if the content is encrypted, we |
1581 // must use MediaCodec anyways since MediaDrm offers no way to decrypt | 1583 // must use MediaCodec anyways since MediaDrm offers no way to decrypt |
1582 // the buffers and let us use our internal software decoders. | 1584 // the buffers and let us use our internal software decoders. |
1583 profile.encrypted_only = | 1585 profile.encrypted_only = |
1584 VideoCodecBridge::IsKnownUnaccelerated(kCodecVP8, MEDIA_CODEC_DECODER); | 1586 VideoCodecBridge::IsKnownUnaccelerated(kCodecVP8, MEDIA_CODEC_DECODER); |
1585 profiles.push_back(profile); | 1587 profiles.push_back(profile); |
| 1588 |
| 1589 // Always allow encrypted content, even at low resolutions. |
| 1590 profile.min_resolution.SetSize(0, 0); |
| 1591 profile.encrypted_only = true; |
| 1592 profiles.push_back(profile); |
1586 } | 1593 } |
1587 | 1594 |
1588 if (MediaCodecUtil::IsVp9DecoderAvailable()) { | 1595 if (MediaCodecUtil::IsVp9DecoderAvailable()) { |
1589 SupportedProfile profile; | 1596 const VideoCodecProfile profile_types[] = { |
1590 // Limit to 360p, like we do for vp8. See above. | 1597 VP9PROFILE_PROFILE0, VP9PROFILE_PROFILE1, VP9PROFILE_PROFILE2, |
1591 profile.min_resolution.SetSize(480, 360); | 1598 VP9PROFILE_PROFILE3, VIDEO_CODEC_PROFILE_UNKNOWN}; |
1592 profile.max_resolution.SetSize(3840, 2160); | 1599 const bool is_known_unaccelerated = |
1593 // If we know MediaCodec will just create a software codec, prefer our | |
1594 // internal software decoder instead. It's more up to date and secured | |
1595 // within the renderer sandbox. However if the content is encrypted, we | |
1596 // must use MediaCodec anyways since MediaDrm offers no way to decrypt | |
1597 // the buffers and let us use our internal software decoders. | |
1598 profile.encrypted_only = | |
1599 VideoCodecBridge::IsKnownUnaccelerated(kCodecVP9, MEDIA_CODEC_DECODER); | 1600 VideoCodecBridge::IsKnownUnaccelerated(kCodecVP9, MEDIA_CODEC_DECODER); |
1600 profile.profile = VP9PROFILE_PROFILE0; | 1601 for (int i = 0; profile_types[i] != VIDEO_CODEC_PROFILE_UNKNOWN; i++) { |
1601 profiles.push_back(profile); | 1602 SupportedProfile profile; |
1602 profile.profile = VP9PROFILE_PROFILE1; | 1603 // Limit to 360p, like we do for vp8. See above. |
1603 profiles.push_back(profile); | 1604 profile.min_resolution.SetSize(480, 360); |
1604 profile.profile = VP9PROFILE_PROFILE2; | 1605 profile.max_resolution.SetSize(3840, 2160); |
1605 profiles.push_back(profile); | 1606 // If we know MediaCodec will just create a software codec, prefer our |
1606 profile.profile = VP9PROFILE_PROFILE3; | 1607 // internal software decoder instead. It's more up to date and secured |
1607 profiles.push_back(profile); | 1608 // within the renderer sandbox. However if the content is encrypted, we |
| 1609 // must use MediaCodec anyways since MediaDrm offers no way to decrypt |
| 1610 // the buffers and let us use our internal software decoders. |
| 1611 profile.encrypted_only = is_known_unaccelerated; |
| 1612 profile.profile = profile_types[i]; |
| 1613 profiles.push_back(profile); |
| 1614 |
| 1615 // Always allow encrypted content. |
| 1616 profile.min_resolution.SetSize(0, 0); |
| 1617 profile.encrypted_only = true; |
| 1618 profiles.push_back(profile); |
| 1619 } |
1608 } | 1620 } |
1609 | 1621 |
1610 for (const auto& supported_profile : kSupportedH264Profiles) { | 1622 for (const auto& supported_profile : kSupportedH264Profiles) { |
1611 SupportedProfile profile; | 1623 SupportedProfile profile; |
1612 profile.profile = supported_profile; | 1624 profile.profile = supported_profile; |
1613 profile.min_resolution.SetSize(0, 0); | 1625 profile.min_resolution.SetSize(0, 0); |
1614 // Advertise support for 4k and let the MediaCodec fail when decoding if it | 1626 // Advertise support for 4k and let the MediaCodec fail when decoding if it |
1615 // doesn't support the resolution. It's assumed that consumers won't have | 1627 // doesn't support the resolution. It's assumed that consumers won't have |
1616 // software fallback for H264 on Android anyway. | 1628 // software fallback for H264 on Android anyway. |
1617 profile.max_resolution.SetSize(3840, 2160); | 1629 profile.max_resolution.SetSize(3840, 2160); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 | 1661 |
1650 bool AndroidVideoDecodeAccelerator::IsMediaCodecSoftwareDecodingForbidden() | 1662 bool AndroidVideoDecodeAccelerator::IsMediaCodecSoftwareDecodingForbidden() |
1651 const { | 1663 const { |
1652 // Prevent MediaCodec from using its internal software decoders when we have | 1664 // Prevent MediaCodec from using its internal software decoders when we have |
1653 // more secure and up to date versions in the renderer process. | 1665 // more secure and up to date versions in the renderer process. |
1654 return !config_.is_encrypted && (codec_config_->codec_ == kCodecVP8 || | 1666 return !config_.is_encrypted && (codec_config_->codec_ == kCodecVP8 || |
1655 codec_config_->codec_ == kCodecVP9); | 1667 codec_config_->codec_ == kCodecVP9); |
1656 } | 1668 } |
1657 | 1669 |
1658 } // namespace media | 1670 } // namespace media |
OLD | NEW |