Revert attempts to fix broken camera issue

This commit is contained in:
Miriam Zimmerman
2025-07-17 15:30:06 -04:00
committed by GitHub
parent b0d89ccc97
commit 6553c416f8
5 changed files with 10 additions and 94 deletions

View File

@@ -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();
}
}

View File

@@ -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();
}