mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-03-01 22:22:15 +00:00
Revert attempts to fix broken camera issue
This commit is contained in:
@@ -39,14 +39,11 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
|
||||
private static final String TAG = Log.tag(Camera.class);
|
||||
|
||||
@NonNull private final Context context;
|
||||
@Nullable private CameraVideoCapturer capturer;
|
||||
@Nullable private final CameraVideoCapturer capturer;
|
||||
@Nullable private CameraEventListener cameraEventListener;
|
||||
@NonNull private final EglBaseWrapper eglBase;
|
||||
private final int cameraCount;
|
||||
@NonNull private CameraState.Direction activeDirection;
|
||||
private CameraState.Direction oldActiveDirection;
|
||||
private CapturerObserver observer;
|
||||
|
||||
private boolean enabled;
|
||||
private boolean isInitialized;
|
||||
private int orientation;
|
||||
@@ -64,12 +61,12 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
|
||||
|
||||
CameraState.Direction firstChoice = desiredCameraDirection.isUsable() ? desiredCameraDirection : FRONT;
|
||||
|
||||
CameraVideoCapturer capturerCandidate = createVideoCapturer(enumerator, firstChoice, false);
|
||||
CameraVideoCapturer capturerCandidate = createVideoCapturer(enumerator, firstChoice);
|
||||
if (capturerCandidate != null) {
|
||||
activeDirection = firstChoice;
|
||||
} else {
|
||||
CameraState.Direction secondChoice = firstChoice.switchDirection();
|
||||
capturerCandidate = createVideoCapturer(enumerator, secondChoice, false);
|
||||
capturerCandidate = createVideoCapturer(enumerator, secondChoice);
|
||||
if (capturerCandidate != null) {
|
||||
activeDirection = secondChoice;
|
||||
} else {
|
||||
@@ -82,7 +79,6 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
|
||||
@Override
|
||||
public void initCapturer(@NonNull CapturerObserver observer) {
|
||||
if (capturer != null) {
|
||||
this.observer = observer; // save in case we need to disposeAndFlipCamera
|
||||
eglBase.performWithValidEglBase(base -> {
|
||||
capturer.initialize(SurfaceTextureHelper.create("WebRTC-SurfaceTextureHelper", base.getEglBaseContext()),
|
||||
context,
|
||||
@@ -103,7 +99,6 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
|
||||
if (capturer == null || cameraCount < 2) {
|
||||
throw new AssertionError("Tried to flip the camera, but we only have " + cameraCount + " of them.");
|
||||
}
|
||||
oldActiveDirection = activeDirection;
|
||||
activeDirection = PENDING;
|
||||
capturer.switchCamera(this);
|
||||
}
|
||||
@@ -151,35 +146,6 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
|
||||
}
|
||||
}
|
||||
|
||||
public void disposeAndFlipCamera() {
|
||||
if (capturer != null) {
|
||||
Log.i(TAG, "disposeAndFlipCamera(): enabled: " + this.enabled + " isInitialized: " + this.isInitialized);
|
||||
capturer.dispose();
|
||||
boolean wasInitialized = isInitialized;
|
||||
isInitialized = false;
|
||||
CameraState.Direction candidateDirection = oldActiveDirection.switchDirection();
|
||||
CameraVideoCapturer captureCandidate = createVideoCapturer(getCameraEnumerator(context), candidateDirection, true);
|
||||
Log.i(TAG, "disposeAndFlipCamera(): candidateDirection: " + candidateDirection + " oldActiveDirection: " + oldActiveDirection +
|
||||
" captureCandidate: " + captureCandidate + " wasInitialized: " + wasInitialized + " enabled: " + enabled);
|
||||
if (captureCandidate != null) {
|
||||
capturer = captureCandidate;
|
||||
activeDirection = candidateDirection;
|
||||
if (wasInitialized) {
|
||||
Log.i(TAG, "disposeAndFlipCamera(): re-initialize");
|
||||
initCapturer(this.observer);
|
||||
}
|
||||
if (enabled) {
|
||||
Log.i(TAG, "disposeAndFlipCamera(): setEnabled");
|
||||
setEnabled(true);
|
||||
}
|
||||
} else {
|
||||
activeDirection = NONE;
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "disposeAndFlipCamera(): capturer was null");
|
||||
}
|
||||
}
|
||||
|
||||
int getCount() {
|
||||
return cameraCount;
|
||||
}
|
||||
@@ -201,17 +167,13 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
|
||||
}
|
||||
|
||||
private @Nullable CameraVideoCapturer createVideoCapturer(@NonNull CameraEnumerator enumerator,
|
||||
@NonNull CameraState.Direction direction,
|
||||
boolean logSelectedCameraName)
|
||||
@NonNull CameraState.Direction direction)
|
||||
{
|
||||
String[] deviceNames = enumerator.getDeviceNames();
|
||||
for (String deviceName : deviceNames) {
|
||||
if ((direction == FRONT && enumerator.isFrontFacing(deviceName)) ||
|
||||
(direction == BACK && enumerator.isBackFacing(deviceName)))
|
||||
{
|
||||
if (logSelectedCameraName) {
|
||||
Log.i(TAG, "createVideoCapturer(): Trying device " + deviceName);
|
||||
}
|
||||
return enumerator.createCapturer(deviceName, null);
|
||||
}
|
||||
}
|
||||
@@ -242,9 +204,7 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
|
||||
@Override
|
||||
public void onCameraSwitchError(String errorMessage) {
|
||||
Log.e(TAG, "onCameraSwitchError: " + errorMessage);
|
||||
if (cameraEventListener != null) {
|
||||
cameraEventListener.onCameraSwitchFailure(new CameraState(getActiveDirection(), getCount()));
|
||||
}
|
||||
if (cameraEventListener != null) cameraEventListener.onCameraSwitchCompleted(new CameraState(getActiveDirection(), getCount()));
|
||||
}
|
||||
|
||||
private static class FilteredCamera2Enumerator extends Camera2Enumerator {
|
||||
@@ -354,7 +314,7 @@ public class Camera implements CameraControl, CameraVideoCapturer.CameraSwitchHa
|
||||
public void onCapturerStarted(boolean success) {
|
||||
observer.onCapturerStarted(success);
|
||||
if (success && cameraEventListener != null) {
|
||||
cameraEventListener.onFullyInitialized(getCameraState());
|
||||
cameraEventListener.onFullyInitialized();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,7 @@ import androidx.annotation.NonNull;
|
||||
* onCameraSwitchCompleted is triggered by {@link org.webrtc.CameraVideoCapturer.CameraSwitchHandler}
|
||||
*/
|
||||
public interface CameraEventListener {
|
||||
void onFullyInitialized(@NonNull CameraState newCameraState);
|
||||
void onFullyInitialized();
|
||||
void onCameraSwitchCompleted(@NonNull CameraState newCameraState);
|
||||
void onCameraSwitchFailure(@NonNull CameraState newCameraState);
|
||||
void onCameraStopped();
|
||||
}
|
||||
|
||||
@@ -80,23 +80,4 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ 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;
|
||||
@@ -989,11 +990,8 @@ public final class SignalCallManager implements CallManager.Observer, GroupCall.
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
});
|
||||
public void onFullyInitialized() {
|
||||
process((s, p) -> p.handleOrientationChanged(s, s.getLocalDeviceState().isLandscapeEnabled(), s.getLocalDeviceState().getDeviceOrientation().getDegrees()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1001,11 +999,6 @@ 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.");
|
||||
|
||||
@@ -569,11 +569,6 @@ 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;
|
||||
@@ -635,18 +630,6 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user