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