Android VideoCapture: Add null checks in stopCaptureOnCameraThread
If stopCapture is called shortly after startCapture, and the first startCaptureOnCameraThread failed, but still hasn't retried 3 times, stopCaptureOnCameraThread will be called in a state where the camera is not initialized. This CL adds null checks in stopCaptureOnCameraThread to avoid crashes. BUG=b/27939867 Review URL: https://codereview.webrtc.org/1854103002 Cr-Commit-Position: refs/heads/master@{#12234}
This commit is contained in:
parent
844dd2ad4b
commit
23b08eb531
@ -467,10 +467,8 @@ public class VideoCapturerAndroid implements
|
||||
error = e;
|
||||
}
|
||||
Logging.e(TAG, "startCapture failed", error);
|
||||
if (camera != null) {
|
||||
// Make sure the camera is released.
|
||||
stopCaptureOnCameraThread();
|
||||
}
|
||||
// Make sure the camera is released.
|
||||
stopCaptureOnCameraThread();
|
||||
synchronized (handlerLock) {
|
||||
// Remove all pending Runnables posted from |this|.
|
||||
cameraThreadHandler.removeCallbacksAndMessages(this /* token */);
|
||||
@ -607,20 +605,28 @@ public class VideoCapturerAndroid implements
|
||||
private void stopCaptureOnCameraThread() {
|
||||
checkIsOnCameraThread();
|
||||
Logging.d(TAG, "stopCaptureOnCameraThread");
|
||||
// Note that the camera might still not be started here if startCaptureOnCameraThread failed
|
||||
// and we posted a retry.
|
||||
|
||||
// Make sure onTextureFrameAvailable() is not called anymore.
|
||||
surfaceHelper.stopListening();
|
||||
if (surfaceHelper != null) {
|
||||
surfaceHelper.stopListening();
|
||||
}
|
||||
cameraThreadHandler.removeCallbacks(cameraObserver);
|
||||
cameraStatistics.getAndResetFrameCount();
|
||||
Logging.d(TAG, "Stop preview.");
|
||||
camera.stopPreview();
|
||||
camera.setPreviewCallbackWithBuffer(null);
|
||||
if (camera != null) {
|
||||
camera.stopPreview();
|
||||
camera.setPreviewCallbackWithBuffer(null);
|
||||
}
|
||||
queuedBuffers.clear();
|
||||
captureFormat = null;
|
||||
|
||||
Logging.d(TAG, "Release camera.");
|
||||
camera.release();
|
||||
camera = null;
|
||||
if (camera != null) {
|
||||
camera.release();
|
||||
camera = null;
|
||||
}
|
||||
if (eventsHandler != null) {
|
||||
eventsHandler.onCameraClosed();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user