Improved camera switching algorithm

This commit is contained in:
Sylvain Berfini 2019-10-25 11:06:28 +02:00
parent 2fb953e80e
commit 426262c3d7

View file

@ -87,32 +87,26 @@ public class CallManager {
public void switchCamera() { public void switchCamera() {
Core core = LinphoneManager.getCore(); Core core = LinphoneManager.getCore();
try { if (core == null) return;
String currentDevice = core.getVideoDevice(); String currentDevice = core.getVideoDevice();
Log.i("[Call Manager] Current camera device is " + currentDevice);
String[] devices = core.getVideoDevicesList(); String[] devices = core.getVideoDevicesList();
int index = 0;
for (String d : devices) { for (String d : devices) {
if (d.equals(currentDevice)) { if (!d.equals(currentDevice) && !d.equals("StaticImage: Static picture")) {
Log.i("[Call Manager] New camera device will be " + d);
core.setVideoDevice(d);
break; break;
} }
index++;
} }
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(); Call call = core.getCurrentCall();
if (call == null) { if (call == null) {
Log.w("[Call Manager] Trying to switch camera while not in call"); Log.i("[Call Manager] Switching camera while not in call");
return; return;
} }
call.update(null); call.update(null);
} catch (ArithmeticException ae) {
Log.e("[Call Manager] [Video] Cannot switch camera: no camera");
}
} }
public boolean acceptCall(Call call) { public boolean acceptCall(Call call) {