From 419344264cfc7445af3e82024bd285303e17b3d6 Mon Sep 17 00:00:00 2001 From: Sergey Silkin Date: Wed, 16 Feb 2022 11:01:09 +0100 Subject: [PATCH] Disable periodic keyframes Bug: none Change-Id: I8bd049cb8e8c958e59bf90a61198b7933eb5d40f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251692 Reviewed-by: Stefan Holmer Commit-Queue: Sergey Silkin Cr-Commit-Position: refs/heads/main@{#36019} --- .../webrtc/HardwareVideoEncoderFactory.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java b/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java index 2ac61cb6b0..2454182923 100644 --- a/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java +++ b/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java @@ -27,6 +27,11 @@ import java.util.List; public class HardwareVideoEncoderFactory implements VideoEncoderFactory { private static final String TAG = "HardwareVideoEncoderFactory"; + // We don't need periodic keyframes. But some HW encoders, Exynos in particular, fails to + // initialize with value -1 which should disable periodic keyframes according to the spec. Set it + // to 1 hour. + private static final int PERIODIC_KEY_FRAME_INTERVAL_S = 3600; + // Forced key frame interval - used to reduce color distortions on Qualcomm platforms. private static final int QCOM_VP8_KEY_FRAME_INTERVAL_ANDROID_L_MS = 15000; private static final int QCOM_VP8_KEY_FRAME_INTERVAL_ANDROID_M_MS = 20000; @@ -123,7 +128,7 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory { } return new HardwareVideoEncoder(new MediaCodecWrapperFactoryImpl(), codecName, type, - surfaceColorFormat, yuvColorFormat, input.params, getKeyFrameIntervalSec(type), + surfaceColorFormat, yuvColorFormat, input.params, PERIODIC_KEY_FRAME_INTERVAL_S, getForcedKeyFrameIntervalMs(type, codecName), createBitrateAdjuster(type, codecName), sharedContext); } @@ -250,18 +255,6 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory { return codecAllowedPredicate.test(info); } - private int getKeyFrameIntervalSec(VideoCodecMimeType type) { - switch (type) { - case VP8: // Fallthrough intended. - case VP9: - case AV1: - return 100; - case H264: - return 20; - } - throw new IllegalArgumentException("Unsupported VideoCodecMimeType " + type); - } - private int getForcedKeyFrameIntervalMs(VideoCodecMimeType type, String codecName) { if (type == VideoCodecMimeType.VP8 && codecName.startsWith(QCOM_PREFIX)) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP