Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Unified Diff: webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java

Issue 1854103002: Android VideoCapture: Add null checks in stopCaptureOnCameraThread (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java
diff --git a/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java b/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java
index b8ab1a8c5ea6223ce46aebf7dae8a43e8fd21241..93e623e4bd7dd35eaab39ddb6166db38184106e1 100644
--- a/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java
+++ b/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java
@@ -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();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698