Skip to content

Commit

Permalink
Refine HW/SW codec approximation for API level 28 and earlier
Browse files Browse the repository at this point in the history
Hardware audio decoders aren't really a thing, particularly on older
devices. SOC vendors do sometimes provide their own software decoders
though. Hence we update the approximation to assume that audio
decoders on older devices are software.

PiperOrigin-RevId: 413757859
  • Loading branch information
ojw28 committed Dec 6, 2021
1 parent e288f94 commit 1a1636e
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ private static ArrayList<MediaCodecInfo> getDecoderInfosInternal(
if ((!key.secure && secureRequired) || (key.secure && !secureSupported)) {
continue;
}
boolean hardwareAccelerated = isHardwareAccelerated(codecInfo);
boolean softwareOnly = isSoftwareOnly(codecInfo);
boolean hardwareAccelerated = isHardwareAccelerated(codecInfo, mimeType);
boolean softwareOnly = isSoftwareOnly(codecInfo, mimeType);
boolean vendor = isVendor(codecInfo);
if ((secureDecodersExplicit && key.secure == secureSupported)
|| (!secureDecodersExplicit && !key.secure)) {
Expand Down Expand Up @@ -601,13 +601,14 @@ private static boolean isAliasV29(android.media.MediaCodecInfo info) {
* The result of {@link android.media.MediaCodecInfo#isHardwareAccelerated()} for API levels 29+,
* or a best-effort approximation for lower levels.
*/
private static boolean isHardwareAccelerated(android.media.MediaCodecInfo codecInfo) {
private static boolean isHardwareAccelerated(
android.media.MediaCodecInfo codecInfo, String mimeType) {
if (Util.SDK_INT >= 29) {
return isHardwareAcceleratedV29(codecInfo);
}
// codecInfo.isHardwareAccelerated() != codecInfo.isSoftwareOnly() is not necessarily true.
// However, we assume this to be true as an approximation.
return !isSoftwareOnly(codecInfo);
return !isSoftwareOnly(codecInfo, mimeType);
}

@RequiresApi(29)
Expand All @@ -619,12 +620,17 @@ private static boolean isHardwareAcceleratedV29(android.media.MediaCodecInfo cod
* The result of {@link android.media.MediaCodecInfo#isSoftwareOnly()} for API levels 29+, or a
* best-effort approximation for lower levels.
*/
private static boolean isSoftwareOnly(android.media.MediaCodecInfo codecInfo) {
private static boolean isSoftwareOnly(android.media.MediaCodecInfo codecInfo, String mimeType) {
if (Util.SDK_INT >= 29) {
return isSoftwareOnlyV29(codecInfo);
}
if (MimeTypes.isAudio(mimeType)) {
// Assume audio decoders are software only.
return true;
}
String codecName = Ascii.toLowerCase(codecInfo.getName());
if (codecName.startsWith("arc.")) { // App Runtime for Chrome (ARC) codecs
if (codecName.startsWith("arc.")) {
// App Runtime for Chrome (ARC) codecs
return false;
}
return codecName.startsWith("omx.google.")
Expand Down

0 comments on commit 1a1636e

Please sign in to comment.