Fix use of Android 11 low latency decoding feature

This commit is contained in:
Cameron Gutman
2021-04-27 17:43:04 -05:00
parent cc23f8b831
commit ee50e19dbd
2 changed files with 45 additions and 28 deletions

View File

@@ -706,6 +706,15 @@ public class MediaCodecHelper {
// and we want to be sure all callers are handling this possibility // and we want to be sure all callers are handling this possibility
@SuppressWarnings("RedundantThrows") @SuppressWarnings("RedundantThrows")
private static MediaCodecInfo findKnownSafeDecoder(String mimeType, int requiredProfile) throws Exception { private static MediaCodecInfo findKnownSafeDecoder(String mimeType, int requiredProfile) throws Exception {
// Some devices (Exynos devces, at least) have two sets of decoders.
// The first set of decoders are C2 which do not support FEATURE_LowLatency,
// but the second set of OMX decoders do support FEATURE_LowLatency. We want
// to pick the OMX decoders despite the fact that C2 is listed first.
// On some Qualcomm devices (like Pixel 4), there are separate low latency decoders
// (like c2.qti.hevc.decoder.low_latency) that advertise FEATURE_LowLatency while
// the standard ones (like c2.qti.hevc.decoder) do not. Like Exynos, the decoders
// with FEATURE_LowLatency support are listed after the standard ones.
for (int i = 0; i < 2; i++) {
for (MediaCodecInfo codecInfo : getMediaCodecList()) { for (MediaCodecInfo codecInfo : getMediaCodecList()) {
// Skip encoders // Skip encoders
if (codecInfo.isEncoder()) { if (codecInfo.isEncoder()) {
@@ -722,7 +731,7 @@ public class MediaCodecHelper {
// Find a decoder that supports the requested video format // Find a decoder that supports the requested video format
for (String mime : codecInfo.getSupportedTypes()) { for (String mime : codecInfo.getSupportedTypes()) {
if (mime.equalsIgnoreCase(mimeType)) { if (mime.equalsIgnoreCase(mimeType)) {
LimeLog.info("Examining decoder capabilities of "+codecInfo.getName()); LimeLog.info("Examining decoder capabilities of " + codecInfo.getName() + " (round " + (i + 1) + ")");
// Skip blacklisted codecs // Skip blacklisted codecs
if (isCodecBlacklisted(codecInfo)) { if (isCodecBlacklisted(codecInfo)) {
@@ -731,6 +740,11 @@ public class MediaCodecHelper {
CodecCapabilities caps = codecInfo.getCapabilitiesForType(mime); CodecCapabilities caps = codecInfo.getCapabilitiesForType(mime);
if (i == 0 && !decoderSupportsAndroidRLowLatency(codecInfo, mime)) {
LimeLog.info("Skipping decoder that lacks FEATURE_LowLatency for round 1");
continue;
}
if (requiredProfile != -1) { if (requiredProfile != -1) {
for (CodecProfileLevel profile : caps.profileLevels) { for (CodecProfileLevel profile : caps.profileLevels) {
if (profile.profile == requiredProfile) { if (profile.profile == requiredProfile) {
@@ -740,13 +754,13 @@ public class MediaCodecHelper {
} }
LimeLog.info("Decoder " + codecInfo.getName() + " does NOT support required profile"); LimeLog.info("Decoder " + codecInfo.getName() + " does NOT support required profile");
} } else {
else {
return codecInfo; return codecInfo;
} }
} }
} }
} }
}
return null; return null;
} }

View File

@@ -41,3 +41,6 @@ This file serves to document some of the decoder errata when using MediaCodec ha
14. Some HEVC decoders lag when receiving a stream with 16 reference frames 14. Some HEVC decoders lag when receiving a stream with 16 reference frames
- Affected decoders: Tegra X1 in Pixel C (but NOT in SHIELD TV darcy) - Affected decoders: Tegra X1 in Pixel C (but NOT in SHIELD TV darcy)
15. Some devices that support Android 11's FEATURE_LowLatency don't support it on their first compatible H.264/HEVC decoder. It is important to examine *all* decoders for FEATURE_LowLatency before deciding on one.
- Affected devices: Pixel 4 (c2.qti.avc.decoder.low_latency vs c2.qti.avc.decoder) and Galaxy S21 Exynos (OMX.Exynos.avc.dec [FEATURE_LowLatency] vs C2.Exynos.avc.decoder [no FEATURE_LowLatency])