From 44d28a48d4b5c6750d066cc57be5f4c4d79be24d Mon Sep 17 00:00:00 2001 From: Stone Date: Sun, 30 Jul 2023 07:01:54 +0800 Subject: [PATCH] Cherry pick PR #807: [android] Reset frame rate estimator when the stream fps changed (#807) (#1062) Cherry pick PR #807: [android] Reset frame rate estimator when the stream fps changed (#807) Refer to the original PR: https://github.com/youtube/cobalt/pull/807 When playing a stream, the key operating rate is set to MediaCodec for resource planning. It's calculated by the playback rate and the estimated fps. While the latter is calculated by the number of rendered frames in duration. When the stream fps is changed, the estimated fps will be affected by the frames already rendered with the old fps and slowly adjusted to the new fps. This may lead to insufficient resources prepared for the stream and cause some performance issues. b/290409989 Change-Id: I5126794d0ac98d29fc8405359bcb4f62dc444308 --- .../app/src/main/java/dev/cobalt/media/MediaCodecBridge.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java b/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java index 1478b37debee..7efa46515216 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java @@ -498,6 +498,9 @@ public void onOutputFormatChanged(MediaCodec codec, MediaFormat format) { return; } nativeOnMediaCodecOutputFormatChanged(mNativeMediaCodecBridge); + if (mFrameRateEstimator != null) { + mFrameRateEstimator.reset(); + } } } };