Index: webrtc/api/androidtests/src/org/webrtc/Camera1CapturerTestFixtures.java |
diff --git a/webrtc/api/androidtests/src/org/webrtc/Camera1CapturerTestFixtures.java b/webrtc/api/androidtests/src/org/webrtc/Camera1CapturerTestFixtures.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b298521dd2168b01694e5837f459a02baec7a3cb |
--- /dev/null |
+++ b/webrtc/api/androidtests/src/org/webrtc/Camera1CapturerTestFixtures.java |
@@ -0,0 +1,104 @@ |
+/* |
+ * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+package org.webrtc; |
+ |
+import java.util.ArrayList; |
+import java.util.List; |
+import java.util.concurrent.CountDownLatch; |
+ |
+import android.content.Context; |
+ |
+import org.webrtc.CameraEnumerationAndroid.CaptureFormat; |
+ |
+import static junit.framework.Assert.*; |
+ |
+@SuppressWarnings("deprecation") |
+public class Camera1CapturerTestFixtures { |
+ static public void startWhileCameraIsAlreadyOpen( |
+ VideoCapturerAndroid capturer, Context appContext) throws InterruptedException { |
+ final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
+ final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
+ android.hardware.Camera camera = android.hardware.Camera.open(capturer.getCurrentCameraId()); |
+ |
+ final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create( |
+ "SurfaceTextureHelper test" /* threadName */, null /* sharedContext */); |
+ final CameraVideoCapturerTestFixtures.FakeCapturerObserver observer |
+ = new CameraVideoCapturerTestFixtures.FakeCapturerObserver(); |
+ capturer.startCapture(format.width, format.height, format.framerate.max, |
+ surfaceTextureHelper, appContext, observer); |
+ |
+ if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { |
+ // The first opened camera client will be evicted. |
+ assertTrue(observer.WaitForCapturerToStart()); |
+ capturer.stopCapture(); |
+ } else { |
+ assertFalse(observer.WaitForCapturerToStart()); |
+ } |
+ |
+ CameraVideoCapturerTestFixtures.release(capturer); |
+ camera.release(); |
+ surfaceTextureHelper.dispose(); |
+ } |
+ |
+ static public void startWhileCameraIsAlreadyOpenAndCloseCamera( |
+ VideoCapturerAndroid capturer, Context appContext) throws InterruptedException { |
+ final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
+ final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
+ android.hardware.Camera camera = android.hardware.Camera.open(capturer.getCurrentCameraId()); |
+ |
+ final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create( |
+ "SurfaceTextureHelper test" /* threadName */, null /* sharedContext */); |
+ final CameraVideoCapturerTestFixtures.FakeCapturerObserver observer |
+ = new CameraVideoCapturerTestFixtures.FakeCapturerObserver(); |
+ capturer.startCapture(format.width, format.height, format.framerate.max, |
+ surfaceTextureHelper, appContext, observer); |
+ waitUntilIdle(capturer); |
+ |
+ camera.release(); |
+ |
+ // Make sure camera is started and first frame is received and then stop it. |
+ assertTrue(observer.WaitForCapturerToStart()); |
+ observer.WaitForNextCapturedFrame(); |
+ capturer.stopCapture(); |
+ if (capturer.isCapturingToTexture()) { |
+ surfaceTextureHelper.returnTextureFrame(); |
+ } |
+ CameraVideoCapturerTestFixtures.release(capturer); |
+ surfaceTextureHelper.dispose(); |
+ } |
+ |
+ static public void startWhileCameraIsAlreadyOpenAndStop( |
+ VideoCapturerAndroid capturer, Context appContext) throws InterruptedException { |
+ final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
+ final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
+ android.hardware.Camera camera = android.hardware.Camera.open(capturer.getCurrentCameraId()); |
+ |
+ final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create( |
+ "SurfaceTextureHelper test" /* threadName */, null /* sharedContext */); |
+ final CameraVideoCapturerTestFixtures.FakeCapturerObserver observer |
+ = new CameraVideoCapturerTestFixtures.FakeCapturerObserver(); |
+ capturer.startCapture(format.width, format.height, format.framerate.max, |
+ surfaceTextureHelper, appContext, observer); |
+ capturer.stopCapture(); |
+ CameraVideoCapturerTestFixtures.release(capturer); |
+ camera.release(); |
+ surfaceTextureHelper.dispose(); |
+ } |
+ |
+ static void waitUntilIdle(VideoCapturerAndroid capturer) throws InterruptedException { |
+ final CountDownLatch barrier = new CountDownLatch(1); |
+ capturer.getCameraThreadHandler().post(new Runnable() { |
+ @Override public void run() { |
+ barrier.countDown(); |
+ } |
+ }); |
+ barrier.await(); |
+ } |
+} |