Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VP9 on Android M and below by advertising profile level #8462

Merged
merged 5 commits into from
Jan 19, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.util.ArrayList;

/** Information about a {@link MediaCodec} for a given mime type. */
@SuppressWarnings("InlinedApi")
Expand Down Expand Up @@ -298,7 +299,15 @@ public boolean isCodecSupported(Format format) {
// which may not be widely supported. See https://github.com/google/ExoPlayer/issues/5145.
return true;
}
for (CodecProfileLevel capabilities : getProfileLevels()) {

final CodecProfileLevel[] codecProfileLevels;
if (MimeTypes.VIDEO_VP9.equals(mimeType) && Util.SDK_INT <= 23 && capabilities != null) {
codecProfileLevels = getVp9CodecProfileLevelsV23(capabilities);
} else {
codecProfileLevels = getProfileLevels();
zeninsta marked this conversation as resolved.
Show resolved Hide resolved
}

for (CodecProfileLevel capabilities : codecProfileLevels) {
if (capabilities.profile == profile && capabilities.level >= level) {
return true;
}
Expand Down Expand Up @@ -572,6 +581,41 @@ public boolean isAudioChannelCountSupportedV21(int channelCount) {
return true;
}

/**
* On versions L and M, VP9 codecCapabilities do not advertise profile level
* support. In this case, estimate the level from MediaCodecInfo.VideoCapabilities
* instead. Assume VP9 is not supported before L. For more information, consult
* https://developer.android.com/reference/android/media/MediaCodecInfo.CodecProfileLevel.html
*/
private static CodecProfileLevel[] getVp9CodecProfileLevelsV23(CodecCapabilities capabilities) {
zeninsta marked this conversation as resolved.
Show resolved Hide resolved
// https://www.webmproject.org/vp9/levels
final int[][] bitrateMapping = {
{200, 10}, {800, 11}, {1800, 20}, {3600, 21}, {7200, 30}, {12000, 31}, {18000, 40},
zeninsta marked this conversation as resolved.
Show resolved Hide resolved
{30000, 41}, {60000, 50}, {120000, 51}, {180000, 52},
};

VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();

if (videoCapabilities == null) {
return new CodecProfileLevel[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to always assume VP9Level1 is supported.

}

ArrayList<CodecProfileLevel> profileLevelList = new ArrayList<>();
for (int[] entry : bitrateMapping) {
int bitrate = entry[0];
int level = entry[1];
if (videoCapabilities.getBitrateRange().contains(bitrate)) {
CodecProfileLevel profileLevel = new CodecProfileLevel();
// Assume all platforms before N only support VP9 profile 0.
profileLevel.profile = CodecProfileLevel.VP9Profile0;
profileLevel.level = level;
profileLevelList.add(profileLevel);
}
}

return profileLevelList.toArray(new CodecProfileLevel[profileLevelList.size()]);
}

private void logNoSupport(String message) {
Log.d(TAG, "NoSupport [" + message + "] [" + name + ", " + mimeType + "] ["
+ Util.DEVICE_DEBUG_INFO + "]");
Expand Down