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() {
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);
String currentDevice = core.getVideoDevice();
Log.i("[Call Manager] Current camera device is " + currentDevice);
Call call = core.getCurrentCall();
if (call == null) {
Log.w("[Call Manager] Trying to switch camera while not in call");
return;
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) {