1 /* 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 package org.webrtc; 12 13 import android.content.Context; 14 import android.support.test.InstrumentationRegistry; 15 import androidx.test.filters.LargeTest; 16 import androidx.test.filters.MediumTest; 17 import androidx.test.filters.SmallTest; 18 import org.junit.After; 19 import org.junit.Before; 20 import org.junit.Test; 21 22 public class Camera1CapturerUsingTextureTest { 23 static final String TAG = "Camera1CapturerUsingTextureTest"; 24 25 private static class TestObjectFactory extends CameraVideoCapturerTestFixtures.TestObjectFactory { 26 @Override getCameraEnumerator()27 public CameraEnumerator getCameraEnumerator() { 28 return new Camera1Enumerator(); 29 } 30 31 @Override getAppContext()32 public Context getAppContext() { 33 return InstrumentationRegistry.getTargetContext(); 34 } 35 36 @SuppressWarnings("deprecation") 37 @Override rawOpenCamera(String cameraName)38 public Object rawOpenCamera(String cameraName) { 39 return android.hardware.Camera.open(Camera1Enumerator.getCameraIndex(cameraName)); 40 } 41 42 @SuppressWarnings("deprecation") 43 @Override rawCloseCamera(Object camera)44 public void rawCloseCamera(Object camera) { 45 ((android.hardware.Camera) camera).release(); 46 } 47 } 48 49 private CameraVideoCapturerTestFixtures fixtures; 50 51 @Before setUp()52 public void setUp() { 53 fixtures = new CameraVideoCapturerTestFixtures(new TestObjectFactory()); 54 } 55 56 @After tearDown()57 public void tearDown() { 58 fixtures.dispose(); 59 } 60 61 @Test 62 @SmallTest testCreateAndDispose()63 public void testCreateAndDispose() throws InterruptedException { 64 fixtures.createCapturerAndDispose(); 65 } 66 67 @Test 68 @SmallTest testCreateNonExistingCamera()69 public void testCreateNonExistingCamera() throws InterruptedException { 70 fixtures.createNonExistingCamera(); 71 } 72 73 // This test that the camera can be started and that the frames are forwarded 74 // to a Java video renderer using a "default" capturer. 75 // It tests both the Java and the C++ layer. 76 @Test 77 @MediumTest testCreateCapturerAndRender()78 public void testCreateCapturerAndRender() throws InterruptedException { 79 fixtures.createCapturerAndRender(); 80 } 81 82 // This test that the camera can be started and that the frames are forwarded 83 // to a Java video renderer using the front facing video capturer. 84 // It tests both the Java and the C++ layer. 85 @Test 86 @MediumTest testStartFrontFacingVideoCapturer()87 public void testStartFrontFacingVideoCapturer() throws InterruptedException { 88 fixtures.createFrontFacingCapturerAndRender(); 89 } 90 91 // This test that the camera can be started and that the frames are forwarded 92 // to a Java video renderer using the back facing video capturer. 93 // It tests both the Java and the C++ layer. 94 @Test 95 @MediumTest testStartBackFacingVideoCapturer()96 public void testStartBackFacingVideoCapturer() throws InterruptedException { 97 fixtures.createBackFacingCapturerAndRender(); 98 } 99 100 // This test that the default camera can be started and that the camera can 101 // later be switched to another camera. 102 // It tests both the Java and the C++ layer. 103 @Test 104 @MediumTest testSwitchVideoCapturer()105 public void testSwitchVideoCapturer() throws InterruptedException { 106 fixtures.switchCamera(); 107 } 108 109 @Test 110 @MediumTest testSwitchVideoCapturerToSpecificCameraName()111 public void testSwitchVideoCapturerToSpecificCameraName() throws InterruptedException { 112 fixtures.switchCamera(true /* specifyCameraName */); 113 } 114 115 @Test 116 @MediumTest testCameraEvents()117 public void testCameraEvents() throws InterruptedException { 118 fixtures.cameraEventsInvoked(); 119 } 120 121 // Test what happens when attempting to call e.g. switchCamera() after camera has been stopped. 122 @Test 123 @MediumTest testCameraCallsAfterStop()124 public void testCameraCallsAfterStop() throws InterruptedException { 125 fixtures.cameraCallsAfterStop(); 126 } 127 128 // This test that the VideoSource that the CameraVideoCapturer is connected to can 129 // be stopped and restarted. It tests both the Java and the C++ layer. 130 @Test 131 @LargeTest testStopRestartVideoSource()132 public void testStopRestartVideoSource() throws InterruptedException { 133 fixtures.stopRestartVideoSource(); 134 } 135 136 // This test that the camera can be started at different resolutions. 137 // It does not test or use the C++ layer. 138 @Test 139 @LargeTest testStartStopWithDifferentResolutions()140 public void testStartStopWithDifferentResolutions() throws InterruptedException { 141 fixtures.startStopWithDifferentResolutions(); 142 } 143 144 // This test what happens if buffers are returned after the capturer have 145 // been stopped and restarted. It does not test or use the C++ layer. 146 @Test 147 @LargeTest testReturnBufferLate()148 public void testReturnBufferLate() throws InterruptedException { 149 fixtures.returnBufferLate(); 150 } 151 152 // This test that we can capture frames, keep the frames in a local renderer, stop capturing, 153 // and then return the frames. The difference between the test testReturnBufferLate() is that we 154 // also test the JNI and C++ AndroidVideoCapturer parts. 155 @Test 156 @MediumTest testReturnBufferLateEndToEnd()157 public void testReturnBufferLateEndToEnd() throws InterruptedException { 158 fixtures.returnBufferLateEndToEnd(); 159 } 160 161 // This test that CameraEventsHandler.onError is triggered if video buffers are not returned to 162 // the capturer. 163 @Test 164 @LargeTest testCameraFreezedEventOnBufferStarvation()165 public void testCameraFreezedEventOnBufferStarvation() throws InterruptedException { 166 fixtures.cameraFreezedEventOnBufferStarvation(); 167 } 168 169 // This test that frames forwarded to a renderer is scaled if adaptOutputFormat is 170 // called. This test both Java and C++ parts of of the stack. 171 @Test 172 @MediumTest testScaleCameraOutput()173 public void testScaleCameraOutput() throws InterruptedException { 174 fixtures.scaleCameraOutput(); 175 } 176 177 // This test that frames forwarded to a renderer is cropped to a new orientation if 178 // adaptOutputFormat is called in such a way. This test both Java and C++ parts of of the stack. 179 @Test 180 @MediumTest testCropCameraOutput()181 public void testCropCameraOutput() throws InterruptedException { 182 fixtures.cropCameraOutput(); 183 } 184 185 // This test that an error is reported if the camera is already opened 186 // when CameraVideoCapturer is started. 187 @Test 188 @LargeTest testStartWhileCameraIsAlreadyOpen()189 public void testStartWhileCameraIsAlreadyOpen() throws InterruptedException { 190 fixtures.startWhileCameraIsAlreadyOpen(); 191 } 192 193 // This test that CameraVideoCapturer can be started, even if the camera is already opened 194 // if the camera is closed while CameraVideoCapturer is re-trying to start. 195 @Test 196 @LargeTest testStartWhileCameraIsAlreadyOpenAndCloseCamera()197 public void testStartWhileCameraIsAlreadyOpenAndCloseCamera() throws InterruptedException { 198 fixtures.startWhileCameraIsAlreadyOpenAndCloseCamera(); 199 } 200 201 // This test that CameraVideoCapturer.stop can be called while CameraVideoCapturer is 202 // re-trying to start. 203 @Test 204 @MediumTest testStartWhileCameraIsAlreadyOpenAndStop()205 public void testStartWhileCameraIsAlreadyOpenAndStop() throws InterruptedException { 206 fixtures.startWhileCameraIsAlreadyOpenAndStop(); 207 } 208 } 209