Improve handling of missing camera during calls.

This commit is contained in:
Miriam Zimmerman
2025-05-30 14:02:19 -04:00
committed by Cody Henthorne
parent faf0b630c1
commit 340b94f849
5 changed files with 80 additions and 7 deletions

View File

@@ -80,4 +80,23 @@ public abstract class DeviceAwareActionProcessor extends WebRtcActionProcessor {
.cameraState(newCameraState)
.build();
}
@Override
public @NonNull WebRtcServiceState handleCameraSwitchFailure(@NonNull WebRtcServiceState currentState, @NonNull CameraState newCameraState) {
Log.i(tag, "handleCameraSwitchFailure():");
BroadcastVideoSink localSink = currentState.getVideoState().getLocalSink();
if (localSink != null) {
localSink.setRotateToRightSide(false);
}
if (currentState.getVideoState().getCamera() != null) {
// Retry by recreating with the opposite preferred camera
currentState.getVideoState().getCamera().disposeAndFlipCamera();
}
return currentState.builder()
.changeLocalDeviceState()
.cameraState(newCameraState)
.build();
}
}

View File

@@ -68,7 +68,6 @@ import org.thoughtcrime.securesms.service.webrtc.state.WebRtcEphemeralState;
import org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState;
import org.thoughtcrime.securesms.util.AppForegroundObserver;
import org.thoughtcrime.securesms.util.RecipientAccessList;
import org.thoughtcrime.securesms.util.RemoteConfig;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.rx.RxStore;
@@ -988,8 +987,11 @@ public final class SignalCallManager implements CallManager.Observer, GroupCall.
}
@Override
public void onFullyInitialized() {
process((s, p) -> p.handleOrientationChanged(s, s.getLocalDeviceState().isLandscapeEnabled(), s.getLocalDeviceState().getDeviceOrientation().getDegrees()));
public void onFullyInitialized(@NonNull final CameraState newCameraState) {
process((s, p) -> {
WebRtcServiceState s1 = p.handleSetCameraDirection(s, newCameraState);
return p.handleOrientationChanged(s1, s.getLocalDeviceState().isLandscapeEnabled(), s.getLocalDeviceState().getDeviceOrientation().getDegrees());
});
}
@Override
@@ -997,6 +999,11 @@ public final class SignalCallManager implements CallManager.Observer, GroupCall.
process((s, p) -> p.handleCameraSwitchCompleted(s, newCameraState));
}
@Override
public void onCameraSwitchFailure(@NonNull final CameraState newCameraState) {
process((s, p) -> p.handleCameraSwitchFailure(s, newCameraState));
}
@Override
public void onCameraStopped() {
Log.i(TAG, "Camera error. Muting video.");

View File

@@ -569,6 +569,11 @@ public abstract class WebRtcActionProcessor {
return currentState;
}
public @NonNull WebRtcServiceState handleCameraSwitchFailure(@NonNull WebRtcServiceState currentState, @NonNull CameraState newCameraState) {
Log.i(tag, "handleCameraSwitchFailure not processed");
return currentState;
}
public @NonNull WebRtcServiceState handleNetworkChanged(@NonNull WebRtcServiceState currentState, boolean available) {
Log.i(tag, "handleNetworkChanged not processed");
return currentState;
@@ -630,6 +635,18 @@ public abstract class WebRtcActionProcessor {
.build();
}
protected @NonNull WebRtcServiceState handleSetCameraDirection(@NonNull WebRtcServiceState currentState, CameraState state) {
BroadcastVideoSink sink = currentState.getVideoState().getLocalSink();
if (sink != null) {
sink.setRotateToRightSide(state.getActiveDirection() == CameraState.Direction.BACK);
}
return currentState.builder()
.changeLocalDeviceState()
.cameraState(state)
.build();
}
//endregion Local device
//region End call