Prevent incorrect state changes during vanity camera switchover.

This commit is contained in:
Cody Henthorne
2023-10-03 11:27:33 -04:00
parent 880ce18fd0
commit b74a431ac9
2 changed files with 10 additions and 5 deletions

View File

@@ -40,7 +40,7 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
@NonNull private final Context context;
@Nullable private final CameraVideoCapturer capturer;
@NonNull private final CameraEventListener cameraEventListener;
@Nullable private CameraEventListener cameraEventListener;
@NonNull private final EglBaseWrapper eglBase;
private final int cameraCount;
@NonNull private CameraState.Direction activeDirection;
@@ -135,6 +135,10 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
}
}
public void setCameraEventListener(@Nullable CameraEventListener cameraEventListener) {
this.cameraEventListener = cameraEventListener;
}
public void dispose() {
if (capturer != null) {
capturer.dispose();
@@ -194,13 +198,13 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
@Override
public void onCameraSwitchDone(boolean isFrontFacing) {
activeDirection = isFrontFacing ? FRONT : BACK;
cameraEventListener.onCameraSwitchCompleted(new CameraState(getActiveDirection(), getCount()));
if (cameraEventListener != null) cameraEventListener.onCameraSwitchCompleted(new CameraState(getActiveDirection(), getCount()));
}
@Override
public void onCameraSwitchError(String errorMessage) {
Log.e(TAG, "onCameraSwitchError: " + errorMessage);
cameraEventListener.onCameraSwitchCompleted(new CameraState(getActiveDirection(), getCount()));
if (cameraEventListener != null) cameraEventListener.onCameraSwitchCompleted(new CameraState(getActiveDirection(), getCount()));
}
private static class FilteredCamera2Enumerator extends Camera2Enumerator {
@@ -309,7 +313,7 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
@Override
public void onCapturerStarted(boolean success) {
observer.onCapturerStarted(success);
if (success) {
if (success && cameraEventListener != null) {
cameraEventListener.onFullyInitialized();
}
}
@@ -317,7 +321,7 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
@Override
public void onCapturerStopped() {
observer.onCapturerStopped();
cameraEventListener.onCameraStopped();
if (cameraEventListener != null) cameraEventListener.onCameraStopped();
}
@Override

View File

@@ -62,6 +62,7 @@ public final class WebRtcVideoUtil {
ThreadUtil.runOnMainSync(() -> {
Camera camera = currentState.getVideoState().requireCamera();
camera.setCameraEventListener(null);
camera.setEnabled(false);
camera.dispose();