| Index: webrtc/api/androidtests/src/org/webrtc/CameraVideoCapturerTest.java
|
| diff --git a/webrtc/api/androidtests/src/org/webrtc/CameraVideoCapturerTest.java b/webrtc/api/androidtests/src/org/webrtc/CameraVideoCapturerTest.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8a4ea69b8285f83c44637d56ad094cf46dac844f
|
| --- /dev/null
|
| +++ b/webrtc/api/androidtests/src/org/webrtc/CameraVideoCapturerTest.java
|
| @@ -0,0 +1,187 @@
|
| +/*
|
| + * Copyright 2015 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 android.test.InstrumentationTestCase;
|
| +import android.test.suitebuilder.annotation.SmallTest;
|
| +import android.test.suitebuilder.annotation.MediumTest;
|
| +import android.test.suitebuilder.annotation.Suppress;
|
| +
|
| +import org.webrtc.Logging;
|
| +
|
| +public abstract class CameraVideoCapturerTest extends InstrumentationTestCase {
|
| + static final String TAG = "CameraVideoCapturerTest";
|
| +
|
| + abstract protected CameraVideoCapturer createCapturer(
|
| + String name, CameraVideoCapturer.CameraEventsHandler eventsHandler);
|
| + abstract protected String getNameOfFrontFacingDevice();
|
| + abstract protected String getNameOfBackFacingDevice();
|
| + abstract protected boolean haveTwoCameras();
|
| + abstract protected boolean isCapturingToTexture();
|
| +
|
| + private void startVideoCapturerWithNameTestHelper(String deviceName) throws InterruptedException {
|
| + if (deviceName == null) {
|
| + Logging.w(TAG, "Skipping video capturer test because device name is null.");
|
| + return;
|
| + }
|
| +
|
| + CameraVideoCapturer capturer = createCapturer(deviceName, null);
|
| + CameraVideoCapturerTestFixtures.startCapturerAndRender(capturer);
|
| + }
|
| +
|
| + @Override
|
| + protected void setUp() {
|
| + assertTrue(PeerConnectionFactory.initializeAndroidGlobals(
|
| + getInstrumentation().getContext(), true, true, true));
|
| + }
|
| +
|
| + // This test that the default camera can be started and that the camera can
|
| + // later be switched to another camera.
|
| + // It tests both the Java and the C++ layer.
|
| + @Suppress
|
| + @SmallTest
|
| + public void testSwitchVideoCapturer() throws InterruptedException {
|
| + if (!haveTwoCameras()) {
|
| + Logging.w(TAG,
|
| + "Skipping test switch video capturer because the device doesn't have two cameras.");
|
| + }
|
| +
|
| + CameraVideoCapturer capturer = createCapturer("", null);
|
| + CameraVideoCapturerTestFixtures.switchCamera(capturer);
|
| + }
|
| +
|
| + @Suppress
|
| + @SmallTest
|
| + public void testCreateAndRelease() {
|
| + CameraVideoCapturerTestFixtures.release(createCapturer("", null));
|
| + }
|
| +
|
| + @Suppress
|
| + @SmallTest
|
| + public void testCreateNonExistingCamera() {
|
| + try {
|
| + CameraVideoCapturer capturer = createCapturer("non-existing camera", null);
|
| + } catch (IllegalArgumentException e) {
|
| + return;
|
| + }
|
| +
|
| + fail("Expected illegal argument exception when creating non-existing camera.");
|
| + }
|
| +
|
| + // This test that the camera can be started and that the frames are forwarded
|
| + // to a Java video renderer using a "default" capturer.
|
| + // It tests both the Java and the C++ layer.
|
| + @Suppress
|
| + @SmallTest
|
| + public void testStartVideoCapturer() throws InterruptedException {
|
| + CameraVideoCapturer capturer = createCapturer("", null);
|
| + CameraVideoCapturerTestFixtures.startCapturerAndRender(capturer);
|
| + }
|
| +
|
| + @Suppress
|
| + @MediumTest
|
| + public void testCameraEvents() throws InterruptedException {
|
| + CameraVideoCapturerTestFixtures.CameraEvents cameraEvents =
|
| + CameraVideoCapturerTestFixtures.createCameraEvents();
|
| + CameraVideoCapturer capturer = createCapturer("", cameraEvents);
|
| + CameraVideoCapturerTestFixtures.cameraEventsInvoked(
|
| + capturer, cameraEvents, getInstrumentation().getContext(), isCapturingToTexture());
|
| + }
|
| +
|
| + // This test that the VideoSource that the CameraVideoCapturer is connected to can
|
| + // be stopped and restarted. It tests both the Java and the C++ layer.
|
| + @Suppress
|
| + @SmallTest
|
| + public void testStopRestartVideoSource() throws InterruptedException {
|
| + CameraVideoCapturer capturer = createCapturer("", null);
|
| + CameraVideoCapturerTestFixtures.stopRestartVideoSource(capturer);
|
| + }
|
| +
|
| + // This test that the camera can be started at different resolutions.
|
| + // It does not test or use the C++ layer.
|
| + @Suppress
|
| + @SmallTest
|
| + public void testStartStopWithDifferentResolutions() throws InterruptedException {
|
| + CameraVideoCapturer capturer = createCapturer("", null);
|
| + CameraVideoCapturerTestFixtures.startStopWithDifferentResolutions(capturer,
|
| + getInstrumentation().getContext(), isCapturingToTexture());
|
| + }
|
| +
|
| + // This test what happens if buffers are returned after the capturer have
|
| + // been stopped and restarted. It does not test or use the C++ layer.
|
| + @Suppress
|
| + @SmallTest
|
| + public void testReturnBufferLate() throws InterruptedException {
|
| + CameraVideoCapturer capturer = createCapturer("", null);
|
| + CameraVideoCapturerTestFixtures.returnBufferLate(capturer,
|
| + getInstrumentation().getContext(), isCapturingToTexture());
|
| + }
|
| +
|
| + // This test that we can capture frames, keep the frames in a local renderer, stop capturing,
|
| + // and then return the frames. The difference between the test testReturnBufferLate() is that we
|
| + // also test the JNI and C++ AndroidVideoCapturer parts.
|
| + @Suppress
|
| + @MediumTest
|
| + public void testReturnBufferLateEndToEnd() throws InterruptedException {
|
| + final CameraVideoCapturer capturer = createCapturer("", null);
|
| + CameraVideoCapturerTestFixtures.returnBufferLateEndToEnd(capturer);
|
| + }
|
| +
|
| + // This test that CameraEventsHandler.onError is triggered if video buffers are not returned to
|
| + // the capturer.
|
| + @Suppress
|
| + @MediumTest
|
| + public void testCameraFreezedEventOnBufferStarvation() throws InterruptedException {
|
| + CameraVideoCapturerTestFixtures.CameraEvents cameraEvents =
|
| + CameraVideoCapturerTestFixtures.createCameraEvents();
|
| + CameraVideoCapturer capturer = createCapturer("", cameraEvents);
|
| + CameraVideoCapturerTestFixtures.cameraFreezedEventOnBufferStarvationUsingTextures(capturer,
|
| + cameraEvents, getInstrumentation().getContext(), isCapturingToTexture());
|
| + }
|
| +
|
| + // This test that frames forwarded to a renderer is scaled if onOutputFormatRequest is
|
| + // called. This test both Java and C++ parts of of the stack.
|
| + @Suppress
|
| + @MediumTest
|
| + public void testScaleCameraOutput() throws InterruptedException {
|
| + CameraVideoCapturer capturer = createCapturer("", null);
|
| + CameraVideoCapturerTestFixtures.scaleCameraOutput(capturer);
|
| + }
|
| +
|
| + // This test that the camera can be started and that the frames are forwarded
|
| + // to a Java video renderer using the front facing video capturer.
|
| + // It tests both the Java and the C++ layer.
|
| + @Suppress
|
| + @SmallTest
|
| + public void testStartFrontFacingVideoCapturer() throws InterruptedException {
|
| + String deviceName = getNameOfFrontFacingDevice();
|
| + startVideoCapturerWithNameTestHelper(deviceName);
|
| + }
|
| +
|
| + // This test that the camera can be started and that the frames are forwarded
|
| + // to a Java video renderer using the back facing video capturer.
|
| + // It tests both the Java and the C++ layer.
|
| + @Suppress
|
| + @SmallTest
|
| + public void testStartBackFacingVideoCapturer() throws InterruptedException {
|
| + String deviceName = getNameOfBackFacingDevice();
|
| + startVideoCapturerWithNameTestHelper(deviceName);
|
| + }
|
| +
|
| + // Test what happens when attempting to call e.g. switchCamera() after camera has been stopped.
|
| + @Suppress
|
| + @MediumTest
|
| + public void testCameraCallsAfterStop() throws InterruptedException {
|
| + CameraVideoCapturer capturer = createCapturer("", null);
|
| +
|
| + CameraVideoCapturerTestFixtures.cameraCallsAfterStop(capturer,
|
| + getInstrumentation().getContext(), isCapturingToTexture());
|
| + }
|
| +}
|
|
|