Add failure type parameter to onFailure callback.

This allows Camera2Session to correctly signal camera disconnect
when starting the camera.

BUG=webrtc:7008

Review-Url: https://codereview.webrtc.org/2642703002
Cr-Commit-Position: refs/heads/master@{#16142}
This commit is contained in:
sakal 2017-01-18 03:22:16 -08:00 committed by Commit bot
parent 2fcd2dd93a
commit 5850a9484d
4 changed files with 13 additions and 7 deletions

View File

@ -65,7 +65,7 @@ public class Camera1Session implements CameraSession {
try {
camera = android.hardware.Camera.open(cameraId);
} catch (RuntimeException e) {
callback.onFailure(e.getMessage());
callback.onFailure(FailureType.ERROR, e.getMessage());
return;
}
@ -73,7 +73,7 @@ public class Camera1Session implements CameraSession {
camera.setPreviewTexture(surfaceTextureHelper.getSurfaceTexture());
} catch (IOException e) {
camera.release();
callback.onFailure(e.getMessage());
callback.onFailure(FailureType.ERROR, e.getMessage());
return;
}

View File

@ -101,7 +101,7 @@ public class Camera2Session implements CameraSession {
state = SessionState.STOPPED;
stopInternal();
if (startFailure) {
callback.onFailure("Camera disconnected / evicted.");
callback.onFailure(FailureType.DISCONNECTED, "Camera disconnected / evicted.");
} else {
events.onCameraDisconnected(Camera2Session.this);
}
@ -406,7 +406,7 @@ public class Camera2Session implements CameraSession {
state = SessionState.STOPPED;
stopInternal();
if (startFailure) {
callback.onFailure(error);
callback.onFailure(FailureType.ERROR, error);
} else {
events.onCameraError(this, error);
}

View File

@ -61,7 +61,7 @@ public abstract class CameraCapturer implements CameraVideoCapturer {
}
@Override
public void onFailure(String error) {
public void onFailure(CameraSession.FailureType failureType, String error) {
checkIsOnCameraThread();
uiThreadHandler.removeCallbacks(openCameraTimeoutRunnable);
synchronized (stateLock) {
@ -81,7 +81,11 @@ public abstract class CameraCapturer implements CameraVideoCapturer {
switchState = SwitchState.IDLE;
}
eventsHandler.onCameraError(error);
if (failureType == CameraSession.FailureType.DISCONNECTED) {
eventsHandler.onCameraDisconnected();
} else {
eventsHandler.onCameraError(error);
}
} else {
Logging.w(TAG, "Opening camera failed, retry: " + error);

View File

@ -11,10 +11,12 @@
package org.webrtc;
public interface CameraSession {
enum FailureType { ERROR, DISCONNECTED }
// Callbacks are fired on the camera thread.
public interface CreateSessionCallback {
void onDone(CameraSession session);
void onFailure(String error);
void onFailure(FailureType failureType, String error);
}
// Events are fired on the camera thread.