From 6f9021a5e6f002b661379d065f88485db1885564 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 1 Jun 2022 22:06:11 -0500 Subject: [PATCH] Add magic performance boost for MediaTek devices --- .../binding/video/MediaCodecHelper.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 809ae80a..880749bd 100644 --- a/app/src/main/java/com/limelight/binding/video/MediaCodecHelper.java +++ b/app/src/main/java/com/limelight/binding/video/MediaCodecHelper.java @@ -41,6 +41,7 @@ public class MediaCodecHelper { private static final List qualcommDecoderPrefixes; private static final List kirinDecoderPrefixes; private static final List exynosDecoderPrefixes; + private static final List mediatekDecoderPrefixes; public static final boolean IS_EMULATOR = Build.HARDWARE.equals("ranchu") || Build.HARDWARE.equals("cheets"); @@ -211,6 +212,12 @@ public class MediaCodecHelper { exynosDecoderPrefixes.add("omx.exynos"); } + static { + mediatekDecoderPrefixes = new LinkedList<>(); + + mediatekDecoderPrefixes.add("omx.mtk"); + } + private static boolean isPowerVR(String glRenderer) { return glRenderer.toLowerCase().contains("powervr"); } @@ -392,6 +399,15 @@ public class MediaCodecHelper { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && decoderSupportsAndroidRLowLatency(decoderInfo, mimeType)) { videoFormat.setInteger(MediaFormat.KEY_LOW_LATENCY, 1); } + else if (isDecoderInList(mediatekDecoderPrefixes, decoderInfo.getName())) { + // MediaTek decoders don't use vendor-defined keys for low latency mode. Instead, they have a modified + // version of AOSP's ACodec.cpp which supports the "vdec-lowlatency" option. This option is passed down + // to the decoder as OMX.MTK.index.param.video.LowLatencyDecode. + // + // https://github.com/yuan1617/Framwork/blob/master/frameworks/av/media/libstagefright/ACodec.cpp + // https://github.com/iykex/vendor_mediatek_proprietary_hardware/blob/master/libomx/video/MtkOmxVdecEx/MtkOmxVdecEx.h + videoFormat.setInteger("vdec-lowlatency", 1); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // MediaCodec supports vendor-defined format keys using the "vendor.." syntax. // These allow access to functionality that is not exposed through documented MediaFormat.KEY_* values.