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

Unified Diff: webrtc/api/android/java/src/org/webrtc/Camera2Session.java

Issue 2357213002: Fix deadlock issue in CameraCapturer.stopCapture. (Closed)
Patch Set: Changes according to magjed's comments. Created 4 years, 3 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
Index: webrtc/api/android/java/src/org/webrtc/Camera2Session.java
diff --git a/webrtc/api/android/java/src/org/webrtc/Camera2Session.java b/webrtc/api/android/java/src/org/webrtc/Camera2Session.java
index 460bba68ecf98d7d2a8b483d77b4cb50f1fdaecc..c699bbb8458f258f5f19810e7ec39cd6cf1698d3 100644
--- a/webrtc/api/android/java/src/org/webrtc/Camera2Session.java
+++ b/webrtc/api/android/java/src/org/webrtc/Camera2Session.java
@@ -31,7 +31,6 @@ import android.view.WindowManager;
import java.util.Arrays;
import java.util.List;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@TargetApi(21)
@@ -366,40 +365,15 @@ public class Camera2Session implements CameraSession {
@Override
public void stop() {
- final long stopStartTime = System.nanoTime();
Logging.d(TAG, "Stop camera2 session on camera " + cameraId);
- if (Thread.currentThread() == cameraThreadHandler.getLooper().getThread()) {
- if (state != SessionState.STOPPED) {
- state = SessionState.STOPPED;
- // Post the stopInternal to return earlier.
- cameraThreadHandler.post(new Runnable() {
- @Override
- public void run() {
- stopInternal();
- final int stopTimeMs =
- (int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - stopStartTime);
- camera2StopTimeMsHistogram.addSample(stopTimeMs);
- }
- });
- }
- } else {
- final CountDownLatch stopLatch = new CountDownLatch(1);
-
- cameraThreadHandler.post(new Runnable() {
- @Override
- public void run() {
- if (state != SessionState.STOPPED) {
- state = SessionState.STOPPED;
- stopLatch.countDown();
- stopInternal();
- final int stopTimeMs =
- (int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - stopStartTime);
- camera2StopTimeMsHistogram.addSample(stopTimeMs);
- }
- }
- });
-
- ThreadUtils.awaitUninterruptibly(stopLatch);
+ checkIsOnCameraThread();
+ if (state != SessionState.STOPPED) {
+ final long stopStartTime = System.nanoTime();
+ state = SessionState.STOPPED;
+ stopInternal();
+ final int stopTimeMs =
+ (int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - stopStartTime);
+ camera2StopTimeMsHistogram.addSample(stopTimeMs);
}
}
« no previous file with comments | « webrtc/api/android/java/src/org/webrtc/Camera1Session.java ('k') | webrtc/api/android/java/src/org/webrtc/CameraCapturer.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698