OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 18 matching lines...) Expand all Loading... |
29 import android.test.ActivityTestCase; | 29 import android.test.ActivityTestCase; |
30 import android.test.suitebuilder.annotation.MediumTest; | 30 import android.test.suitebuilder.annotation.MediumTest; |
31 import android.test.suitebuilder.annotation.SmallTest; | 31 import android.test.suitebuilder.annotation.SmallTest; |
32 import android.util.Size; | 32 import android.util.Size; |
33 | 33 |
34 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; | 34 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; |
35 | 35 |
36 import java.util.HashSet; | 36 import java.util.HashSet; |
37 import java.util.Set; | 37 import java.util.Set; |
38 | 38 |
39 import javax.microedition.khronos.egl.EGL10; | |
40 | |
41 @SuppressWarnings("deprecation") | 39 @SuppressWarnings("deprecation") |
42 public class VideoCapturerAndroidTest extends ActivityTestCase { | 40 public class VideoCapturerAndroidTest extends ActivityTestCase { |
43 static final String TAG = "VideoCapturerAndroidTest"; | 41 static final String TAG = "VideoCapturerAndroidTest"; |
44 | 42 |
45 @Override | 43 @Override |
46 protected void setUp() { | 44 protected void setUp() { |
47 assertTrue(PeerConnectionFactory.initializeAndroidGlobals( | 45 assertTrue(PeerConnectionFactory.initializeAndroidGlobals( |
48 getInstrumentation().getContext(), true, true, true)); | 46 getInstrumentation().getContext(), true, true, true)); |
49 } | 47 } |
50 | 48 |
(...skipping 28 matching lines...) Expand all Loading... |
79 } | 77 } |
80 } | 78 } |
81 | 79 |
82 @SmallTest | 80 @SmallTest |
83 public void testCreateAndRelease() { | 81 public void testCreateAndRelease() { |
84 VideoCapturerAndroidTestFixtures.release(VideoCapturerAndroid.create("", nul
l)); | 82 VideoCapturerAndroidTestFixtures.release(VideoCapturerAndroid.create("", nul
l)); |
85 } | 83 } |
86 | 84 |
87 @SmallTest | 85 @SmallTest |
88 public void testCreateAndReleaseUsingTextures() { | 86 public void testCreateAndReleaseUsingTextures() { |
| 87 EglBase eglBase = EglBase.create(); |
89 VideoCapturerAndroidTestFixtures.release( | 88 VideoCapturerAndroidTestFixtures.release( |
90 VideoCapturerAndroid.create("", null, EGL10.EGL_NO_CONTEXT)); | 89 VideoCapturerAndroid.create("", null, eglBase.getEglBaseContext())); |
| 90 eglBase.release(); |
91 } | 91 } |
92 | 92 |
93 @SmallTest | 93 @SmallTest |
94 public void testCreateNonExistingCamera() { | 94 public void testCreateNonExistingCamera() { |
95 VideoCapturerAndroid capturer = VideoCapturerAndroid.create( | 95 VideoCapturerAndroid capturer = VideoCapturerAndroid.create( |
96 "non-existing camera", null); | 96 "non-existing camera", null); |
97 assertNull(capturer); | 97 assertNull(capturer); |
98 } | 98 } |
99 | 99 |
100 @SmallTest | 100 @SmallTest |
101 // This test that the camera can be started and that the frames are forwarded | 101 // This test that the camera can be started and that the frames are forwarded |
102 // to a Java video renderer using a "default" capturer. | 102 // to a Java video renderer using a "default" capturer. |
103 // It tests both the Java and the C++ layer. | 103 // It tests both the Java and the C++ layer. |
104 public void testStartVideoCapturer() throws InterruptedException { | 104 public void testStartVideoCapturer() throws InterruptedException { |
105 VideoCapturerAndroid capturer = | 105 VideoCapturerAndroid capturer = |
106 VideoCapturerAndroid.create("", null); | 106 VideoCapturerAndroid.create("", null); |
107 VideoCapturerAndroidTestFixtures.startCapturerAndRender(capturer); | 107 VideoCapturerAndroidTestFixtures.startCapturerAndRender(capturer); |
108 } | 108 } |
109 | 109 |
110 @SmallTest | 110 @SmallTest |
111 public void testStartVideoCapturerUsingTextures() throws InterruptedException
{ | 111 public void testStartVideoCapturerUsingTextures() throws InterruptedException
{ |
| 112 EglBase eglBase = EglBase.create(); |
112 VideoCapturerAndroid capturer = | 113 VideoCapturerAndroid capturer = |
113 VideoCapturerAndroid.create("", null, EGL10.EGL_NO_CONTEXT); | 114 VideoCapturerAndroid.create("", null, eglBase.getEglBaseContext()); |
114 VideoCapturerAndroidTestFixtures.startCapturerAndRender(capturer); | 115 VideoCapturerAndroidTestFixtures.startCapturerAndRender(capturer); |
| 116 eglBase.release(); |
115 } | 117 } |
116 | 118 |
117 @SmallTest | 119 @SmallTest |
118 // This test that the camera can be started and that the frames are forwarded | 120 // This test that the camera can be started and that the frames are forwarded |
119 // to a Java video renderer using the front facing video capturer. | 121 // to a Java video renderer using the front facing video capturer. |
120 // It tests both the Java and the C++ layer. | 122 // It tests both the Java and the C++ layer. |
121 public void testStartFrontFacingVideoCapturer() throws InterruptedException { | 123 public void testStartFrontFacingVideoCapturer() throws InterruptedException { |
122 String deviceName = CameraEnumerationAndroid.getNameOfFrontFacingDevice(); | 124 String deviceName = CameraEnumerationAndroid.getNameOfFrontFacingDevice(); |
123 VideoCapturerAndroid capturer = | 125 VideoCapturerAndroid capturer = |
124 VideoCapturerAndroid.create(deviceName, null); | 126 VideoCapturerAndroid.create(deviceName, null); |
(...skipping 19 matching lines...) Expand all Loading... |
144 // This test that the default camera can be started and that the camera can | 146 // This test that the default camera can be started and that the camera can |
145 // later be switched to another camera. | 147 // later be switched to another camera. |
146 // It tests both the Java and the C++ layer. | 148 // It tests both the Java and the C++ layer. |
147 public void testSwitchVideoCapturer() throws InterruptedException { | 149 public void testSwitchVideoCapturer() throws InterruptedException { |
148 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); | 150 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); |
149 VideoCapturerAndroidTestFixtures.switchCamera(capturer); | 151 VideoCapturerAndroidTestFixtures.switchCamera(capturer); |
150 } | 152 } |
151 | 153 |
152 @SmallTest | 154 @SmallTest |
153 public void testSwitchVideoCapturerUsingTextures() throws InterruptedException
{ | 155 public void testSwitchVideoCapturerUsingTextures() throws InterruptedException
{ |
154 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null, EGL10.
EGL_NO_CONTEXT); | 156 EglBase eglBase = EglBase.create(); |
| 157 VideoCapturerAndroid capturer = |
| 158 VideoCapturerAndroid.create("", null, eglBase.getEglBaseContext()); |
155 VideoCapturerAndroidTestFixtures.switchCamera(capturer); | 159 VideoCapturerAndroidTestFixtures.switchCamera(capturer); |
| 160 eglBase.release(); |
156 } | 161 } |
157 | 162 |
158 @MediumTest | 163 @MediumTest |
159 public void testCameraEvents() throws InterruptedException { | 164 public void testCameraEvents() throws InterruptedException { |
160 VideoCapturerAndroidTestFixtures.CameraEvents cameraEvents = | 165 VideoCapturerAndroidTestFixtures.CameraEvents cameraEvents = |
161 VideoCapturerAndroidTestFixtures.createCameraEvents(); | 166 VideoCapturerAndroidTestFixtures.createCameraEvents(); |
162 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", cameraEvents
); | 167 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", cameraEvents
); |
163 VideoCapturerAndroidTestFixtures.cameraEventsInvoked( | 168 VideoCapturerAndroidTestFixtures.cameraEventsInvoked( |
164 capturer, cameraEvents, getInstrumentation().getContext()); | 169 capturer, cameraEvents, getInstrumentation().getContext()); |
165 } | 170 } |
166 | 171 |
167 @MediumTest | 172 @MediumTest |
168 // Test what happens when attempting to call e.g. switchCamera() after camera
has been stopped. | 173 // Test what happens when attempting to call e.g. switchCamera() after camera
has been stopped. |
169 public void testCameraCallsAfterStop() throws InterruptedException { | 174 public void testCameraCallsAfterStop() throws InterruptedException { |
170 final String deviceName = CameraEnumerationAndroid.getDeviceName(0); | 175 final String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
171 final VideoCapturerAndroid capturer = VideoCapturerAndroid.create(deviceName
, null); | 176 final VideoCapturerAndroid capturer = VideoCapturerAndroid.create(deviceName
, null); |
172 | 177 |
173 VideoCapturerAndroidTestFixtures.cameraCallsAfterStop(capturer, | 178 VideoCapturerAndroidTestFixtures.cameraCallsAfterStop(capturer, |
174 getInstrumentation().getContext()); | 179 getInstrumentation().getContext()); |
175 } | 180 } |
176 | 181 |
177 @MediumTest | 182 @MediumTest |
178 public void testCameraCallsAfterStopUsingTextures() throws InterruptedExceptio
n { | 183 public void testCameraCallsAfterStopUsingTextures() throws InterruptedExceptio
n { |
| 184 EglBase eglBase = EglBase.create(); |
179 final String deviceName = CameraEnumerationAndroid.getDeviceName(0); | 185 final String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
180 final VideoCapturerAndroid capturer = VideoCapturerAndroid.create(deviceName
, null, | 186 final VideoCapturerAndroid capturer = VideoCapturerAndroid.create(deviceName
, null, |
181 EGL10.EGL_NO_CONTEXT); | 187 eglBase.getEglBaseContext()); |
182 | 188 |
183 VideoCapturerAndroidTestFixtures.cameraCallsAfterStop(capturer, | 189 VideoCapturerAndroidTestFixtures.cameraCallsAfterStop(capturer, |
184 getInstrumentation().getContext()); | 190 getInstrumentation().getContext()); |
| 191 eglBase.release(); |
185 } | 192 } |
186 | 193 |
187 @SmallTest | 194 @SmallTest |
188 // This test that the VideoSource that the VideoCapturer is connected to can | 195 // This test that the VideoSource that the VideoCapturer is connected to can |
189 // be stopped and restarted. It tests both the Java and the C++ layer. | 196 // be stopped and restarted. It tests both the Java and the C++ layer. |
190 public void testStopRestartVideoSource() throws InterruptedException { | 197 public void testStopRestartVideoSource() throws InterruptedException { |
191 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); | 198 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); |
192 VideoCapturerAndroidTestFixtures.stopRestartVideoSource(capturer); | 199 VideoCapturerAndroidTestFixtures.stopRestartVideoSource(capturer); |
193 } | 200 } |
194 | 201 |
195 @SmallTest | 202 @SmallTest |
196 public void testStopRestartVideoSourceUsingTextures() throws InterruptedExcept
ion { | 203 public void testStopRestartVideoSourceUsingTextures() throws InterruptedExcept
ion { |
197 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null, EGL10.
EGL_NO_CONTEXT); | 204 EglBase eglBase = EglBase.create(); |
| 205 VideoCapturerAndroid capturer = |
| 206 VideoCapturerAndroid.create("", null, eglBase.getEglBaseContext()); |
198 VideoCapturerAndroidTestFixtures.stopRestartVideoSource(capturer); | 207 VideoCapturerAndroidTestFixtures.stopRestartVideoSource(capturer); |
| 208 eglBase.release(); |
199 } | 209 } |
200 | 210 |
201 @SmallTest | 211 @SmallTest |
202 // This test that the camera can be started at different resolutions. | 212 // This test that the camera can be started at different resolutions. |
203 // It does not test or use the C++ layer. | 213 // It does not test or use the C++ layer. |
204 public void testStartStopWithDifferentResolutions() throws InterruptedExceptio
n { | 214 public void testStartStopWithDifferentResolutions() throws InterruptedExceptio
n { |
205 String deviceName = CameraEnumerationAndroid.getDeviceName(0); | 215 String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
206 VideoCapturerAndroid capturer = | 216 VideoCapturerAndroid capturer = |
207 VideoCapturerAndroid.create(deviceName, null); | 217 VideoCapturerAndroid.create(deviceName, null); |
208 VideoCapturerAndroidTestFixtures.startStopWithDifferentResolutions(capturer, | 218 VideoCapturerAndroidTestFixtures.startStopWithDifferentResolutions(capturer, |
209 getInstrumentation().getContext()); | 219 getInstrumentation().getContext()); |
210 } | 220 } |
211 | 221 |
212 @SmallTest | 222 @SmallTest |
213 public void testStartStopWithDifferentResolutionsUsingTextures() throws Interr
uptedException { | 223 public void testStartStopWithDifferentResolutionsUsingTextures() throws Interr
uptedException { |
| 224 EglBase eglBase = EglBase.create(); |
214 String deviceName = CameraEnumerationAndroid.getDeviceName(0); | 225 String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
215 VideoCapturerAndroid capturer = | 226 VideoCapturerAndroid capturer = |
216 VideoCapturerAndroid.create(deviceName, null, EGL10.EGL_NO_CONTEXT); | 227 VideoCapturerAndroid.create(deviceName, null, eglBase.getEglBaseContext(
)); |
217 VideoCapturerAndroidTestFixtures.startStopWithDifferentResolutions(capturer, | 228 VideoCapturerAndroidTestFixtures.startStopWithDifferentResolutions(capturer, |
218 getInstrumentation().getContext()); | 229 getInstrumentation().getContext()); |
| 230 eglBase.release(); |
219 } | 231 } |
220 | 232 |
221 @SmallTest | 233 @SmallTest |
222 // This test that an error is reported if the camera is already opened | 234 // This test that an error is reported if the camera is already opened |
223 // when VideoCapturerAndroid is started. | 235 // when VideoCapturerAndroid is started. |
224 public void testStartWhileCameraAlreadyOpened() throws InterruptedException { | 236 public void testStartWhileCameraAlreadyOpened() throws InterruptedException { |
225 String deviceName = CameraEnumerationAndroid.getDeviceName(0); | 237 String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
226 VideoCapturerAndroid capturer = | 238 VideoCapturerAndroid capturer = |
227 VideoCapturerAndroid.create(deviceName, null); | 239 VideoCapturerAndroid.create(deviceName, null); |
228 VideoCapturerAndroidTestFixtures.startWhileCameraIsAlreadyOpen( | 240 VideoCapturerAndroidTestFixtures.startWhileCameraIsAlreadyOpen( |
(...skipping 30 matching lines...) Expand all Loading... |
259 public void testReturnBufferLate() throws InterruptedException { | 271 public void testReturnBufferLate() throws InterruptedException { |
260 String deviceName = CameraEnumerationAndroid.getDeviceName(0); | 272 String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
261 VideoCapturerAndroid capturer = | 273 VideoCapturerAndroid capturer = |
262 VideoCapturerAndroid.create(deviceName, null); | 274 VideoCapturerAndroid.create(deviceName, null); |
263 VideoCapturerAndroidTestFixtures.returnBufferLate(capturer, | 275 VideoCapturerAndroidTestFixtures.returnBufferLate(capturer, |
264 getInstrumentation().getContext()); | 276 getInstrumentation().getContext()); |
265 } | 277 } |
266 | 278 |
267 @SmallTest | 279 @SmallTest |
268 public void testReturnBufferLateUsingTextures() throws InterruptedException { | 280 public void testReturnBufferLateUsingTextures() throws InterruptedException { |
| 281 EglBase eglBase = EglBase.create(); |
269 String deviceName = CameraEnumerationAndroid.getDeviceName(0); | 282 String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
270 VideoCapturerAndroid capturer = | 283 VideoCapturerAndroid capturer = |
271 VideoCapturerAndroid.create(deviceName, null, EGL10.EGL_NO_CONTEXT); | 284 VideoCapturerAndroid.create(deviceName, null, eglBase.getEglBaseContext(
)); |
272 VideoCapturerAndroidTestFixtures.returnBufferLate(capturer, | 285 VideoCapturerAndroidTestFixtures.returnBufferLate(capturer, |
273 getInstrumentation().getContext()); | 286 getInstrumentation().getContext()); |
| 287 eglBase.release(); |
274 } | 288 } |
275 | 289 |
276 @MediumTest | 290 @MediumTest |
277 // This test that we can capture frames, keep the frames in a local renderer,
stop capturing, | 291 // This test that we can capture frames, keep the frames in a local renderer,
stop capturing, |
278 // and then return the frames. The difference between the test testReturnBuffe
rLate() is that we | 292 // and then return the frames. The difference between the test testReturnBuffe
rLate() is that we |
279 // also test the JNI and C++ AndroidVideoCapturer parts. | 293 // also test the JNI and C++ AndroidVideoCapturer parts. |
280 public void testReturnBufferLateEndToEnd() throws InterruptedException { | 294 public void testReturnBufferLateEndToEnd() throws InterruptedException { |
281 final VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); | 295 final VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); |
282 VideoCapturerAndroidTestFixtures.returnBufferLateEndToEnd(capturer); | 296 VideoCapturerAndroidTestFixtures.returnBufferLateEndToEnd(capturer); |
283 } | 297 } |
284 | 298 |
285 @MediumTest | 299 @MediumTest |
286 public void testReturnBufferLateEndToEndUsingTextures() throws InterruptedExce
ption { | 300 public void testReturnBufferLateEndToEndUsingTextures() throws InterruptedExce
ption { |
| 301 EglBase eglBase = EglBase.create(); |
287 final VideoCapturerAndroid capturer = | 302 final VideoCapturerAndroid capturer = |
288 VideoCapturerAndroid.create("", null, EGL10.EGL_NO_CONTEXT); | 303 VideoCapturerAndroid.create("", null, eglBase.getEglBaseContext()); |
289 VideoCapturerAndroidTestFixtures.returnBufferLateEndToEnd(capturer); | 304 VideoCapturerAndroidTestFixtures.returnBufferLateEndToEnd(capturer); |
| 305 eglBase.release(); |
290 } | 306 } |
291 | 307 |
292 @MediumTest | 308 @MediumTest |
293 // This test that CameraEventsHandler.onError is triggered if video buffers ar
e not returned to | 309 // This test that CameraEventsHandler.onError is triggered if video buffers ar
e not returned to |
294 // the capturer. | 310 // the capturer. |
295 public void testCameraErrorEventOnBufferStarvation() throws InterruptedExcepti
on { | 311 public void testCameraErrorEventOnBufferStarvation() throws InterruptedExcepti
on { |
296 VideoCapturerAndroidTestFixtures.CameraEvents cameraEvents = | 312 VideoCapturerAndroidTestFixtures.CameraEvents cameraEvents = |
297 VideoCapturerAndroidTestFixtures.createCameraEvents(); | 313 VideoCapturerAndroidTestFixtures.createCameraEvents(); |
298 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", cameraEvents
); | 314 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", cameraEvents
); |
299 VideoCapturerAndroidTestFixtures.cameraErrorEventOnBufferStarvation(capturer
, | 315 VideoCapturerAndroidTestFixtures.cameraErrorEventOnBufferStarvation(capturer
, |
300 cameraEvents, getInstrumentation().getContext()); | 316 cameraEvents, getInstrumentation().getContext()); |
301 } | 317 } |
302 | 318 |
303 @MediumTest | 319 @MediumTest |
304 // This test that frames forwarded to a renderer is scaled if onOutputFormatRe
quest is | 320 // This test that frames forwarded to a renderer is scaled if onOutputFormatRe
quest is |
305 // called. This test both Java and C++ parts of of the stack. | 321 // called. This test both Java and C++ parts of of the stack. |
306 public void testScaleCameraOutput() throws InterruptedException { | 322 public void testScaleCameraOutput() throws InterruptedException { |
307 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); | 323 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); |
308 VideoCapturerAndroidTestFixtures.scaleCameraOutput(capturer); | 324 VideoCapturerAndroidTestFixtures.scaleCameraOutput(capturer); |
309 } | 325 } |
310 | 326 |
311 @MediumTest | 327 @MediumTest |
312 // This test that frames forwarded to a renderer is scaled if onOutputFormatRe
quest is | 328 // This test that frames forwarded to a renderer is scaled if onOutputFormatRe
quest is |
313 // called. This test both Java and C++ parts of of the stack. | 329 // called. This test both Java and C++ parts of of the stack. |
314 public void testScaleCameraOutputUsingTextures() throws InterruptedException { | 330 public void testScaleCameraOutputUsingTextures() throws InterruptedException { |
315 VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null, EGL10.
EGL_NO_CONTEXT); | 331 EglBase eglBase = EglBase.create(); |
| 332 VideoCapturerAndroid capturer = |
| 333 VideoCapturerAndroid.create("", null, eglBase.getEglBaseContext()); |
316 VideoCapturerAndroidTestFixtures.scaleCameraOutput(capturer); | 334 VideoCapturerAndroidTestFixtures.scaleCameraOutput(capturer); |
| 335 eglBase.release(); |
317 } | 336 } |
318 } | 337 } |
OLD | NEW |