From 426262c3d7c5e9c83c7bc20dfed5d0c682d90e83 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 25 Oct 2019 11:06:28 +0200 Subject: [PATCH] Improved camera switching algorithm --- .../java/org/linphone/call/CallManager.java | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/linphone/call/CallManager.java b/app/src/main/java/org/linphone/call/CallManager.java index aa4d778b3..3f5e68310 100644 --- a/app/src/main/java/org/linphone/call/CallManager.java +++ b/app/src/main/java/org/linphone/call/CallManager.java @@ -87,32 +87,26 @@ public class CallManager { public void switchCamera() { Core core = LinphoneManager.getCore(); - try { - String currentDevice = core.getVideoDevice(); - String[] devices = core.getVideoDevicesList(); - int index = 0; - for (String d : devices) { - if (d.equals(currentDevice)) { - break; - } - index++; - } + if (core == null) return; - String newDevice; - if (index == 1) newDevice = devices[0]; - else if (devices.length > 1) newDevice = devices[1]; - else newDevice = devices[index]; - core.setVideoDevice(newDevice); - - Call call = core.getCurrentCall(); - if (call == null) { - Log.w("[Call Manager] Trying to switch camera while not in call"); - return; + String currentDevice = core.getVideoDevice(); + Log.i("[Call Manager] Current camera device is " + currentDevice); + + String[] devices = core.getVideoDevicesList(); + for (String d : devices) { + if (!d.equals(currentDevice) && !d.equals("StaticImage: Static picture")) { + Log.i("[Call Manager] New camera device will be " + d); + core.setVideoDevice(d); + break; } - call.update(null); - } catch (ArithmeticException ae) { - Log.e("[Call Manager] [Video] Cannot switch camera: no camera"); } + + Call call = core.getCurrentCall(); + if (call == null) { + Log.i("[Call Manager] Switching camera while not in call"); + return; + } + call.update(null); } public boolean acceptCall(Call call) {