From d00cdb4d6364ac06a91519f49e2d8a465ae120c0 Mon Sep 17 00:00:00 2001 From: davidliu Date: Sat, 25 May 2024 18:42:04 +0900 Subject: [PATCH] android: only change capture format for screen if dimen actually changed --- .../AbstractVideoCaptureController.java | 4 +-- .../WebRTCModule/ScreenCaptureController.java | 26 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java b/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java index d21aab531..393f73c51 100644 --- a/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +++ b/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java @@ -3,8 +3,8 @@ import org.webrtc.VideoCapturer; public abstract class AbstractVideoCaptureController { - private final int width; - private final int height; + protected int width; + protected int height; private final int fps; /** diff --git a/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java b/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java index 39964eea2..9d50263cb 100644 --- a/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +++ b/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java @@ -41,17 +41,21 @@ public void onOrientationChanged(int orientation) { DisplayMetrics displayMetrics = DisplayUtils.getDisplayMetrics((Activity) context); final int width = displayMetrics.widthPixels; final int height = displayMetrics.heightPixels; - - // Pivot to the executor thread because videoCapturer.changeCaptureFormat runs in the main - // thread and may deadlock. - ThreadUtils.runOnExecutor(() -> { - try { - videoCapturer.changeCaptureFormat(width, height, DEFAULT_FPS); - } catch (Exception ex) { - // We ignore exceptions here. The video capturer runs on its own - // thread and we cannot synchronize with it. - } - }); + if (width != ScreenCaptureController.this.width || height != ScreenCaptureController.this.height) { + ScreenCaptureController.this.width = width; + ScreenCaptureController.this.height = height; + + // Pivot to the executor thread because videoCapturer.changeCaptureFormat runs in the main + // thread and may deadlock. + ThreadUtils.runOnExecutor(() -> { + try { + videoCapturer.changeCaptureFormat(width, height, DEFAULT_FPS); + } catch (Exception ex) { + // We ignore exceptions here. The video capturer runs on its own + // thread and we cannot synchronize with it. + } + }); + } } };