Commit 19a50060 authored by liberato@chromium.org's avatar liberato@chromium.org Committed by Commit Bot

Enable AV1 if supported by MediaCodec.

Bug: 953376
Change-Id: I7c2bf8a54481bb31ead4eeb86c15510228a10988
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1575818Reviewed-by: default avatarFrank Liberato <liberato@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Frank Liberato <liberato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666128}
parent 39134f65
...@@ -18,6 +18,7 @@ import android.os.Build; ...@@ -18,6 +18,7 @@ import android.os.Build;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import org.chromium.base.BuildInfo;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
...@@ -434,6 +435,8 @@ class MediaCodecUtil { ...@@ -434,6 +435,8 @@ class MediaCodecUtil {
if (Build.MODEL.equals("Nexus Player")) { if (Build.MODEL.equals("Nexus Player")) {
return false; return false;
} }
} else if (mime.equals("video/av01")) {
if (!BuildInfo.isAtLeastQ()) return false;
} else if (mime.equals("audio/opus") } else if (mime.equals("audio/opus")
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return false; return false;
......
...@@ -47,6 +47,7 @@ const char kAvcMimeType[] = "video/avc"; ...@@ -47,6 +47,7 @@ const char kAvcMimeType[] = "video/avc";
const char kHevcMimeType[] = "video/hevc"; const char kHevcMimeType[] = "video/hevc";
const char kVp8MimeType[] = "video/x-vnd.on2.vp8"; const char kVp8MimeType[] = "video/x-vnd.on2.vp8";
const char kVp9MimeType[] = "video/x-vnd.on2.vp9"; const char kVp9MimeType[] = "video/x-vnd.on2.vp9";
const char kAv1MimeType[] = "video/av01";
} // namespace } // namespace
static CodecProfileLevel MediaCodecProfileLevelToChromiumProfileLevel( static CodecProfileLevel MediaCodecProfileLevelToChromiumProfileLevel(
...@@ -63,8 +64,8 @@ static CodecProfileLevel MediaCodecProfileLevelToChromiumProfileLevel( ...@@ -63,8 +64,8 @@ static CodecProfileLevel MediaCodecProfileLevelToChromiumProfileLevel(
static bool IsSupportedAndroidMimeType(const std::string& mime_type) { static bool IsSupportedAndroidMimeType(const std::string& mime_type) {
std::vector<std::string> supported{ std::vector<std::string> supported{
kMp3MimeType, kAacMimeType, kOpusMimeType, kVorbisMimeType, kMp3MimeType, kAacMimeType, kOpusMimeType, kVorbisMimeType, kAvcMimeType,
kAvcMimeType, kHevcMimeType, kVp8MimeType, kVp9MimeType}; kHevcMimeType, kVp8MimeType, kVp9MimeType, kAv1MimeType};
return std::find(supported.begin(), supported.end(), mime_type) != return std::find(supported.begin(), supported.end(), mime_type) !=
supported.end(); supported.end();
} }
...@@ -132,6 +133,8 @@ std::string MediaCodecUtil::CodecToAndroidMimeType(VideoCodec codec) { ...@@ -132,6 +133,8 @@ std::string MediaCodecUtil::CodecToAndroidMimeType(VideoCodec codec) {
return kVp8MimeType; return kVp8MimeType;
case kCodecVP9: case kCodecVP9:
return kVp9MimeType; return kVp9MimeType;
case kCodecAV1:
return kAv1MimeType;
default: default:
return std::string(); return std::string();
} }
...@@ -338,6 +341,11 @@ bool MediaCodecUtil::IsVp9DecoderAvailable() { ...@@ -338,6 +341,11 @@ bool MediaCodecUtil::IsVp9DecoderAvailable() {
return IsMediaCodecAvailable() && IsDecoderSupportedByDevice(kVp9MimeType); return IsMediaCodecAvailable() && IsDecoderSupportedByDevice(kVp9MimeType);
} }
// static
bool MediaCodecUtil::IsAv1DecoderAvailable() {
return IsMediaCodecAvailable() && IsDecoderSupportedByDevice(kAv1MimeType);
}
// static // static
bool MediaCodecUtil::IsH264EncoderAvailable() { bool MediaCodecUtil::IsH264EncoderAvailable() {
return IsMediaCodecAvailable() && IsEncoderSupportedByDevice(kAvcMimeType); return IsMediaCodecAvailable() && IsEncoderSupportedByDevice(kAvcMimeType);
......
...@@ -78,6 +78,9 @@ class MEDIA_EXPORT MediaCodecUtil { ...@@ -78,6 +78,9 @@ class MEDIA_EXPORT MediaCodecUtil {
// Indicates if the vp9 decoder is available on this device. // Indicates if the vp9 decoder is available on this device.
static bool IsVp9DecoderAvailable(); static bool IsVp9DecoderAvailable();
// Indicates if the av1 decoder is available on this device.
static bool IsAv1DecoderAvailable();
// Indicates if the h264 encoder is available on this device. // Indicates if the h264 encoder is available on this device.
static bool IsH264EncoderAvailable(); static bool IsH264EncoderAvailable();
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "media/base/supported_types.h" #include "media/base/supported_types.h"
#include "base/command_line.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "build/build_config.h"
#include "media/base/media_client.h" #include "media/base/media_client.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
#include "media/media_buildflags.h" #include "media/media_buildflags.h"
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
#include "third_party/libvpx/source/libvpx/vpx/vpx_codec.h" #include "third_party/libvpx/source/libvpx/vpx/vpx_codec.h"
#endif #endif
#if defined(OS_ANDROID)
#include "base/android/build_info.h"
#endif
namespace media { namespace media {
bool IsSupportedAudioType(const AudioType& type) { bool IsSupportedAudioType(const AudioType& type) {
...@@ -232,11 +236,16 @@ bool IsDefaultSupportedVideoType(const VideoType& type) { ...@@ -232,11 +236,16 @@ bool IsDefaultSupportedVideoType(const VideoType& type) {
switch (type.codec) { switch (type.codec) {
case media::kCodecAV1: case media::kCodecAV1:
// If the AV1 decoder is enabled, or if we're on Q or later, yes.
#if BUILDFLAG(ENABLE_AV1_DECODER) #if BUILDFLAG(ENABLE_AV1_DECODER)
return IsColorSpaceSupported(type.color_space); return IsColorSpaceSupported(type.color_space);
#else #elif defined(OS_ANDROID)
return false; if (base::android::BuildInfo::GetInstance()->is_at_least_q() &&
IsColorSpaceSupported(type.color_space)) {
return true;
}
#endif #endif
return false;
case media::kCodecVP9: case media::kCodecVP9:
// Color management required for HDR to not look terrible. // Color management required for HDR to not look terrible.
......
...@@ -15,17 +15,22 @@ DeviceInfo* DeviceInfo::GetInstance() { ...@@ -15,17 +15,22 @@ DeviceInfo* DeviceInfo::GetInstance() {
} }
int DeviceInfo::SdkVersion() { int DeviceInfo::SdkVersion() {
static int result = base::android::BuildInfo::GetInstance()->sdk_int(); static const int result = base::android::BuildInfo::GetInstance()->sdk_int();
return result; return result;
} }
bool DeviceInfo::IsVp8DecoderAvailable() { bool DeviceInfo::IsVp8DecoderAvailable() {
static bool result = MediaCodecUtil::IsVp8DecoderAvailable(); static const bool result = MediaCodecUtil::IsVp8DecoderAvailable();
return result; return result;
} }
bool DeviceInfo::IsVp9DecoderAvailable() { bool DeviceInfo::IsVp9DecoderAvailable() {
static bool result = MediaCodecUtil::IsVp9DecoderAvailable(); static const bool result = MediaCodecUtil::IsVp9DecoderAvailable();
return result;
}
bool DeviceInfo::IsAv1DecoderAvailable() {
static const bool result = MediaCodecUtil::IsAv1DecoderAvailable();
return result; return result;
} }
...@@ -35,12 +40,12 @@ bool DeviceInfo::IsDecoderKnownUnaccelerated(VideoCodec codec) { ...@@ -35,12 +40,12 @@ bool DeviceInfo::IsDecoderKnownUnaccelerated(VideoCodec codec) {
} }
bool DeviceInfo::IsSetOutputSurfaceSupported() { bool DeviceInfo::IsSetOutputSurfaceSupported() {
static bool result = MediaCodecUtil::IsSetOutputSurfaceSupported(); static const bool result = MediaCodecUtil::IsSetOutputSurfaceSupported();
return result; return result;
} }
bool DeviceInfo::SupportsOverlaySurfaces() { bool DeviceInfo::SupportsOverlaySurfaces() {
static bool result = MediaCodecUtil::IsSurfaceViewOutputSupported(); static const bool result = MediaCodecUtil::IsSurfaceViewOutputSupported();
return result; return result;
} }
......
...@@ -19,6 +19,7 @@ struct MEDIA_GPU_EXPORT DeviceInfo { ...@@ -19,6 +19,7 @@ struct MEDIA_GPU_EXPORT DeviceInfo {
virtual int SdkVersion(); virtual int SdkVersion();
virtual bool IsVp8DecoderAvailable(); virtual bool IsVp8DecoderAvailable();
virtual bool IsVp9DecoderAvailable(); virtual bool IsVp9DecoderAvailable();
virtual bool IsAv1DecoderAvailable();
virtual bool IsDecoderKnownUnaccelerated(VideoCodec codec); virtual bool IsDecoderKnownUnaccelerated(VideoCodec codec);
virtual bool IsSetOutputSurfaceSupported(); virtual bool IsSetOutputSurfaceSupported();
virtual bool SupportsOverlaySurfaces(); virtual bool SupportsOverlaySurfaces();
......
...@@ -81,6 +81,8 @@ bool ConfigSupported(const VideoDecoderConfig& config, ...@@ -81,6 +81,8 @@ bool ConfigSupported(const VideoDecoderConfig& config,
return true; return true;
} }
case kCodecAV1:
return device_info->IsAv1DecoderAvailable();
#if BUILDFLAG(USE_PROPRIETARY_CODECS) #if BUILDFLAG(USE_PROPRIETARY_CODECS)
case kCodecH264: case kCodecH264:
return true; return true;
...@@ -163,6 +165,13 @@ MediaCodecVideoDecoder::GetSupportedConfigs() { ...@@ -163,6 +165,13 @@ MediaCodecVideoDecoder::GetSupportedConfigs() {
true); // require_encrypted true); // require_encrypted
} }
if (MediaCodecUtil::IsAv1DecoderAvailable()) {
supported_configs.emplace_back(AV1PROFILE_MIN, AV1PROFILE_MAX,
gfx::Size(0, 0), gfx::Size(3840, 2160),
true, // allow_encrypted
false); // require_encrypted
}
#if BUILDFLAG(USE_PROPRIETARY_CODECS) #if BUILDFLAG(USE_PROPRIETARY_CODECS)
// MediaCodec is only guaranteed to support baseline, but some devices may // MediaCodec is only guaranteed to support baseline, but some devices may
// support others. Advertise support for all H.264 profiles and let the // support others. Advertise support for all H.264 profiles and let the
......
...@@ -312,6 +312,10 @@ TEST_P(MediaCodecVideoDecoderVp8Test, SmallVp8IsRejected) { ...@@ -312,6 +312,10 @@ TEST_P(MediaCodecVideoDecoderVp8Test, SmallVp8IsRejected) {
ASSERT_FALSE(Initialize(TestVideoConfig::Normal())); ASSERT_FALSE(Initialize(TestVideoConfig::Normal()));
} }
TEST_P(MediaCodecVideoDecoderH264Test, Av1IsSupported) {
ASSERT_TRUE(Initialize(TestVideoConfig::Normal(kCodecAV1)));
}
TEST_P(MediaCodecVideoDecoderTest, InitializeDoesntInitSurfaceOrCodec) { TEST_P(MediaCodecVideoDecoderTest, InitializeDoesntInitSurfaceOrCodec) {
CreateMcvd(); CreateMcvd();
EXPECT_CALL(*video_frame_factory_, Initialize(ExpectedOverlayMode(), _)) EXPECT_CALL(*video_frame_factory_, Initialize(ExpectedOverlayMode(), _))
......
...@@ -16,6 +16,7 @@ MockDeviceInfo::MockDeviceInfo() { ...@@ -16,6 +16,7 @@ MockDeviceInfo::MockDeviceInfo() {
.WillByDefault(Return(base::android::SDK_VERSION_MARSHMALLOW)); .WillByDefault(Return(base::android::SDK_VERSION_MARSHMALLOW));
ON_CALL(*this, IsVp8DecoderAvailable()).WillByDefault(Return(true)); ON_CALL(*this, IsVp8DecoderAvailable()).WillByDefault(Return(true));
ON_CALL(*this, IsVp9DecoderAvailable()).WillByDefault(Return(true)); ON_CALL(*this, IsVp9DecoderAvailable()).WillByDefault(Return(true));
ON_CALL(*this, IsAv1DecoderAvailable()).WillByDefault(Return(true));
ON_CALL(*this, IsDecoderKnownUnaccelerated(_)).WillByDefault(Return(false)); ON_CALL(*this, IsDecoderKnownUnaccelerated(_)).WillByDefault(Return(false));
ON_CALL(*this, IsSetOutputSurfaceSupported()).WillByDefault(Return(true)); ON_CALL(*this, IsSetOutputSurfaceSupported()).WillByDefault(Return(true));
ON_CALL(*this, SupportsOverlaySurfaces()).WillByDefault(Return(true)); ON_CALL(*this, SupportsOverlaySurfaces()).WillByDefault(Return(true));
......
...@@ -20,6 +20,7 @@ class MockDeviceInfo : public DeviceInfo { ...@@ -20,6 +20,7 @@ class MockDeviceInfo : public DeviceInfo {
MOCK_METHOD0(SdkVersion, int()); MOCK_METHOD0(SdkVersion, int());
MOCK_METHOD0(IsVp8DecoderAvailable, bool()); MOCK_METHOD0(IsVp8DecoderAvailable, bool());
MOCK_METHOD0(IsVp9DecoderAvailable, bool()); MOCK_METHOD0(IsVp9DecoderAvailable, bool());
MOCK_METHOD0(IsAv1DecoderAvailable, bool());
MOCK_METHOD1(IsDecoderKnownUnaccelerated, bool(VideoCodec codec)); MOCK_METHOD1(IsDecoderKnownUnaccelerated, bool(VideoCodec codec));
MOCK_METHOD0(IsSetOutputSurfaceSupported, bool()); MOCK_METHOD0(IsSetOutputSurfaceSupported, bool());
MOCK_METHOD0(SupportsOverlaySurfaces, bool()); MOCK_METHOD0(SupportsOverlaySurfaces, bool());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment