From 43c67b49399aa18380b518abb45dc3cd9d95f7ea Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 1 Jul 2020 11:26:40 -0500 Subject: [PATCH] Avoid using max operating rate on Android Q and non-Qualcomm devices --- .../binding/video/MediaCodecDecoderRenderer.java | 8 +++----- .../limelight/binding/video/MediaCodecHelper.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java index 15246ea4..554e5cfd 100644 --- a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java +++ b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java @@ -334,11 +334,9 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer { videoFormat.setInteger("vendor.qti-ext-dec-low-latency.enable", 1); } - // Operate at maximum rate to lower latency as much as possible on - // some Qualcomm platforms. We could also set KEY_PRIORITY to 0 (realtime) - // but that will actually result in the decoder crashing if it can't satisfy - // our (ludicrous) operating rate requirement. - videoFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE); + if (MediaCodecHelper.decoderSupportsMaxOperatingRate(selectedDecoderName)) { + videoFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, Short.MAX_VALUE); + } } configuredFormat = videoFormat; diff --git a/app/src/main/java/com/limelight/binding/video/MediaCodecHelper.java b/app/src/main/java/com/limelight/binding/video/MediaCodecHelper.java index a9cac570..f9e6bbb4 100644 --- a/app/src/main/java/com/limelight/binding/video/MediaCodecHelper.java +++ b/app/src/main/java/com/limelight/binding/video/MediaCodecHelper.java @@ -354,6 +354,19 @@ public class MediaCodecHelper { return false; } + public static boolean decoderSupportsMaxOperatingRate(String decoderName) { + // Operate at maximum rate to lower latency as much as possible on + // some Qualcomm platforms. We could also set KEY_PRIORITY to 0 (realtime) + // but that will actually result in the decoder crashing if it can't satisfy + // our (ludicrous) operating rate requirement. This seems to cause reliable + // crashes on the Xiaomi Mi 10 lite 5G on Android 10, and probably isn't too + // useful in light of the qti-ext-dec-low-latency code. To be safe, we'll + // disable it on devices running Q or non-Qualcomm devices. + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && + Build.VERSION.SDK_INT < Build.VERSION_CODES.Q && + isDecoderInList(qualcommDecoderPrefixes, decoderName); + } + public static boolean decoderSupportsAdaptivePlayback(MediaCodecInfo decoderInfo, String mimeType) { // Possibly enable adaptive playback on KitKat and above if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {