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