From fd12e30c534ee8e4ce976356713a0941253dd5cf Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 10 Oct 2015 23:28:48 -0700 Subject: [PATCH] Set constraint flags corresponding to Constrained High Profile on KitKat and higher. Fixes Nexus Player high latency on Android 6.0. --- .../video/MediaCodecDecoderRenderer.java | 19 +++++++++++++++++++ decoder-errata.txt | 7 +++++-- 2 files changed, 24 insertions(+), 2 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 a88a3a00..ed5a6aa2 100644 --- a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java +++ b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java @@ -535,6 +535,25 @@ public class MediaCodecDecoderRenderer extends EnhancedDecoderRenderer { sps.vuiParams.bitstreamRestriction = null; } + // Set constraint flags 4 & 5 to make this Constrained High Profile + // which allows the decoder to assume there will be no B-frames and + // reduce delay and buffering accordingly. + // + // This profile is fairly new (standardized in H264 revision 2012-06) and + // it's known that at least some devices don't like these previously unused + // constraints being set. To minimize the chance of interfering with old devices, + // I'm only setting these on KitKat or higher. It's an arbitrary limitation and could + // change if it causes problems. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + sps.constraint_set_4_flag = true; + sps.constraint_set_5_flag = true; + } + else { + // Force the constraints unset for < 4.4 (some may be set by default) + sps.constraint_set_4_flag = false; + sps.constraint_set_5_flag = false; + } + // If we need to hack this SPS to say we're baseline, do so now if (needsBaselineSpsHack) { LimeLog.info("Hacking SPS to baseline"); diff --git a/decoder-errata.txt b/decoder-errata.txt index 577562b4..621fa198 100644 --- a/decoder-errata.txt +++ b/decoder-errata.txt @@ -21,5 +21,8 @@ This file serves to document some of the decoder errata when using MediaCodec ha 7. Some decoders will not enter low latency mode if adaptive playback is enabled - Affected decoders: Intel decoder in Nexus Player -8. Some decoders will not enter low latency mode if the profile isn't baseline in the first SPS. - - Affected decoders: Intel decoder in Nexus Player \ No newline at end of file +8. Some decoders will not enter low latency mode if the profile isn't baseline in the first SPS because B-frames may be present. + - Affected decoders: Intel decoder in Nexus Player (prior to Android 6.0) + +9. Some decoders will not enter low latency mode if the profile isn't constrained high profile because B-frames may be present. + - Affected decoders: Intel decoder in Nexus Player (after Android 6.0) \ No newline at end of file