Index: talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java |
diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java |
similarity index 62% |
copy from talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java |
copy to talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java |
index 0fe827d1f9c658151dd05cb10edf0106e218700d..7e24f8c0dc0c1f4ffe64febfd913822cb7a4e121 100644 |
--- a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java |
+++ b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java |
@@ -26,23 +26,19 @@ |
*/ |
package org.webrtc; |
+import android.content.Context; |
import android.hardware.Camera; |
-import android.test.ActivityTestCase; |
-import android.test.suitebuilder.annotation.SmallTest; |
-import android.test.suitebuilder.annotation.MediumTest; |
-import android.util.Size; |
import org.webrtc.CameraEnumerationAndroid.CaptureFormat; |
import org.webrtc.VideoRenderer.I420Frame; |
import java.util.ArrayList; |
-import java.util.HashSet; |
import java.util.List; |
-import java.util.Set; |
import java.util.concurrent.CountDownLatch; |
-@SuppressWarnings("deprecation") |
-public class VideoCapturerAndroidTest extends ActivityTestCase { |
+import static junit.framework.Assert.*; |
+ |
+public class VideoCapturerAndroidTestFixtures { |
static class RendererCallbacks implements VideoRenderer.Callbacks { |
private int framesRendered = 0; |
private Object frameLock = 0; |
@@ -90,13 +86,15 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
VideoCapturerAndroid.CapturerObserver { |
private int framesCaptured = 0; |
private int frameSize = 0; |
+ private int frameWidth = 0; |
+ private int frameHeight = 0; |
private Object frameLock = 0; |
private Object capturerStartLock = 0; |
private boolean captureStartResult = false; |
private List<Long> timestamps = new ArrayList<Long>(); |
@Override |
- public void OnCapturerStarted(boolean success) { |
+ public void onCapturerStarted(boolean success) { |
synchronized (capturerStartLock) { |
captureStartResult = success; |
capturerStartLock.notify(); |
@@ -104,18 +102,32 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
} |
@Override |
- public void OnFrameCaptured(byte[] frame, int length, int width, int height, |
+ public void onByteBufferFrameCaptured(byte[] frame, int length, int width, int height, |
int rotation, long timeStamp) { |
synchronized (frameLock) { |
++framesCaptured; |
frameSize = length; |
+ frameWidth = width; |
+ frameHeight = height; |
+ timestamps.add(timeStamp); |
+ frameLock.notify(); |
+ } |
+ } |
+ @Override |
+ public void onTextureFrameCaptured( |
+ int width, int height, int oesTextureId, float[] transformMatrix, long timeStamp) { |
+ synchronized (frameLock) { |
+ ++framesCaptured; |
+ frameWidth = width; |
+ frameHeight = height; |
+ frameSize = 0; |
timestamps.add(timeStamp); |
frameLock.notify(); |
} |
} |
@Override |
- public void OnOutputFormatRequest(int width, int height, int fps) {} |
+ public void onOutputFormatRequest(int width, int height, int fps) {} |
public boolean WaitForCapturerToStart() throws InterruptedException { |
synchronized (capturerStartLock) { |
@@ -137,6 +149,18 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
} |
} |
+ int frameWidth() { |
+ synchronized (frameLock) { |
+ return frameWidth; |
+ } |
+ } |
+ |
+ int frameHeight() { |
+ synchronized (frameLock) { |
+ return frameHeight; |
+ } |
+ } |
+ |
List<Long> getCopyAndResetListOftimeStamps() { |
synchronized (frameLock) { |
ArrayList<Long> list = new ArrayList<Long>(timestamps); |
@@ -148,14 +172,19 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
// Return true if the device under test have at least two cameras. |
@SuppressWarnings("deprecation") |
- boolean HaveTwoCameras() { |
+ static public boolean HaveTwoCameras() { |
return (Camera.getNumberOfCameras() >= 2); |
} |
- void startCapturerAndRender(String deviceName) throws InterruptedException { |
+ static public void release(VideoCapturerAndroid capturer) { |
+ assertNotNull(capturer); |
+ capturer.dispose(); |
+ assertTrue(capturer.isReleased()); |
+ } |
+ |
+ static public void startCapturerAndRender(VideoCapturerAndroid capturer) |
+ throws InterruptedException { |
PeerConnectionFactory factory = new PeerConnectionFactory(); |
- VideoCapturerAndroid capturer = |
- VideoCapturerAndroid.create(deviceName, null); |
VideoSource source = |
factory.createVideoSource(capturer, new MediaConstraints()); |
VideoTrack track = factory.createVideoTrack("dummy", source); |
@@ -168,92 +197,8 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
assertTrue(capturer.isReleased()); |
} |
- @Override |
- protected void setUp() { |
- assertTrue(PeerConnectionFactory.initializeAndroidGlobals( |
- getInstrumentation().getContext(), true, true, true)); |
- } |
- |
- @SmallTest |
- // Test that enumerating formats using android.hardware.camera2 will give the same formats as |
- // android.hardware.camera in the range 320x240 to 1280x720. Often the camera2 API may contain |
- // some high resolutions that are not supported in camera1, but it may also be the other way |
- // around in some cases. Supported framerates may also differ, so don't compare those. |
- public void testCamera2Enumerator() { |
- if (!Camera2Enumerator.isSupported()) { |
- return; |
- } |
- final CameraEnumerationAndroid.Enumerator camera1Enumerator = new CameraEnumerator(); |
- final CameraEnumerationAndroid.Enumerator camera2Enumerator = |
- new Camera2Enumerator(getInstrumentation().getContext()); |
- |
- for (int i = 0; i < CameraEnumerationAndroid.getDeviceCount(); ++i) { |
- final Set<Size> resolutions1 = new HashSet<Size>(); |
- for (CaptureFormat format : camera1Enumerator.getSupportedFormats(i)) { |
- resolutions1.add(new Size(format.width, format.height)); |
- } |
- final Set<Size> resolutions2 = new HashSet<Size>(); |
- for (CaptureFormat format : camera2Enumerator.getSupportedFormats(i)) { |
- resolutions2.add(new Size(format.width, format.height)); |
- } |
- for (Size size : resolutions1) { |
- if (size.getWidth() >= 320 && size.getHeight() >= 240 |
- && size.getWidth() <= 1280 && size.getHeight() <= 720) { |
- assertTrue(resolutions2.contains(size)); |
- } |
- } |
- } |
- } |
- |
- @SmallTest |
- public void testCreateAndRelease() throws Exception { |
- VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); |
- assertNotNull(capturer); |
- capturer.dispose(); |
- assertTrue(capturer.isReleased()); |
- } |
- |
- @SmallTest |
- public void testCreateNonExistingCamera() throws Exception { |
- VideoCapturerAndroid capturer = VideoCapturerAndroid.create( |
- "non-existing camera", null); |
- assertNull(capturer); |
- } |
- |
- @SmallTest |
- // 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. |
- public void testStartVideoCapturer() throws Exception { |
- startCapturerAndRender(""); |
- } |
- |
- @SmallTest |
- // 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. |
- public void testStartFrontFacingVideoCapturer() throws Exception { |
- startCapturerAndRender(CameraEnumerationAndroid.getNameOfFrontFacingDevice()); |
- } |
- |
- @SmallTest |
- // 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. |
- public void testStartBackFacingVideoCapturer() throws Exception { |
- if (!HaveTwoCameras()) { |
- return; |
- } |
- startCapturerAndRender(CameraEnumerationAndroid.getNameOfBackFacingDevice()); |
- } |
- |
- @SmallTest |
- // 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. |
- public void testSwitchVideoCapturer() throws Exception { |
+ static public void switchCamera(VideoCapturerAndroid capturer) throws InterruptedException { |
PeerConnectionFactory factory = new PeerConnectionFactory(); |
- VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); |
VideoSource source = |
factory.createVideoSource(capturer, new MediaConstraints()); |
VideoTrack track = factory.createVideoTrack("dummy", source); |
@@ -292,17 +237,14 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
assertTrue(capturer.isReleased()); |
} |
- @MediumTest |
- // Test what happens when attempting to call e.g. switchCamera() after camera has been stopped. |
- public void testCameraCallsAfterStop() throws InterruptedException { |
- final String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
- final VideoCapturerAndroid capturer = VideoCapturerAndroid.create(deviceName, null); |
- final List<CaptureFormat> formats = CameraEnumerationAndroid.getSupportedFormats(0); |
+ static public void cameraCallsAfterStop( |
+ VideoCapturerAndroid capturer, Context appContext) throws InterruptedException { |
+ final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
final FakeCapturerObserver observer = new FakeCapturerObserver(); |
capturer.startCapture(format.width, format.height, format.maxFramerate, |
- getInstrumentation().getContext(), observer); |
+ appContext, observer); |
// Make sure camera is started and then stop it. |
assertTrue(observer.WaitForCapturerToStart()); |
capturer.stopCapture(); |
@@ -318,12 +260,9 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
assertTrue(capturer.isReleased()); |
} |
- @SmallTest |
- // This test that the VideoSource that the VideoCapturer is connected to can |
- // be stopped and restarted. It tests both the Java and the C++ layer. |
- public void testStopRestartVideoSource() throws Exception { |
+ static public void stopRestartVideoSource(VideoCapturerAndroid capturer) |
+ throws InterruptedException { |
PeerConnectionFactory factory = new PeerConnectionFactory(); |
- VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); |
VideoSource source = |
factory.createVideoSource(capturer, new MediaConstraints()); |
VideoTrack track = factory.createVideoTrack("dummy", source); |
@@ -344,25 +283,34 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
assertTrue(capturer.isReleased()); |
} |
- @SmallTest |
- // This test that the camera can be started at different resolutions. |
- // It does not test or use the C++ layer. |
- public void testStartStopWithDifferentResolutions() throws Exception { |
+ static public void startStopWithDifferentResolutions(VideoCapturerAndroid capturer, |
+ Context appContext) throws InterruptedException { |
FakeCapturerObserver observer = new FakeCapturerObserver(); |
- |
- String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
- List<CaptureFormat> formats = CameraEnumerationAndroid.getSupportedFormats(0); |
- VideoCapturerAndroid capturer = |
- VideoCapturerAndroid.create(deviceName, null); |
+ List<CaptureFormat> formats = capturer.getSupportedFormats(); |
for(int i = 0; i < 3 ; ++i) { |
CameraEnumerationAndroid.CaptureFormat format = formats.get(i); |
capturer.startCapture(format.width, format.height, format.maxFramerate, |
- getInstrumentation().getContext(), observer); |
+ appContext, observer); |
assertTrue(observer.WaitForCapturerToStart()); |
observer.WaitForNextCapturedFrame(); |
- // Check the frame size. |
- assertEquals(format.frameSize(), observer.frameSize()); |
+ |
+ // Check the frame size. The actual width and height depend on how the capturer is mounted. |
+ final boolean identicalResolution = (observer.frameWidth() == format.width |
+ && observer.frameHeight() == format.height); |
+ final boolean flippedResolution = (observer.frameWidth() == format.height |
+ && observer.frameHeight() == format.width); |
+ if (!identicalResolution && !flippedResolution) { |
+ fail("Wrong resolution, got: " + observer.frameWidth() + "x" + observer.frameHeight() |
+ + " expected: " + format.width + "x" + format.height + " or " + format.height + "x" |
+ + format.width); |
+ } |
+ |
+ if (capturer.isCapturingToTexture()) { |
+ assertEquals(0, observer.frameSize()); |
+ } else { |
+ assertEquals(format.frameSize(), observer.frameSize()); |
+ } |
capturer.stopCapture(); |
for (long timestamp : observer.getCopyAndResetListOftimeStamps()) { |
capturer.returnBuffer(timestamp); |
@@ -372,20 +320,14 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
assertTrue(capturer.isReleased()); |
} |
- @SmallTest |
- // 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. |
- public void testReturnBufferLate() throws Exception { |
+ static public void returnBufferLate(VideoCapturerAndroid capturer, |
+ Context appContext) throws InterruptedException { |
FakeCapturerObserver observer = new FakeCapturerObserver(); |
- String deviceName = CameraEnumerationAndroid.getDeviceName(0); |
- List<CaptureFormat> formats = CameraEnumerationAndroid.getSupportedFormats(0); |
- VideoCapturerAndroid capturer = |
- VideoCapturerAndroid.create(deviceName, null); |
- |
+ List<CaptureFormat> formats = capturer.getSupportedFormats(); |
CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
capturer.startCapture(format.width, format.height, format.maxFramerate, |
- getInstrumentation().getContext(), observer); |
+ appContext, observer); |
assertTrue(observer.WaitForCapturerToStart()); |
observer.WaitForNextCapturedFrame(); |
@@ -395,9 +337,8 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
format = formats.get(1); |
capturer.startCapture(format.width, format.height, format.maxFramerate, |
- getInstrumentation().getContext(), observer); |
+ appContext, observer); |
observer.WaitForCapturerToStart(); |
- observer.WaitForNextCapturedFrame(); |
for (Long timeStamp : listOftimestamps) { |
capturer.returnBuffer(timeStamp); |
@@ -407,7 +348,7 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
capturer.stopCapture(); |
listOftimestamps = observer.getCopyAndResetListOftimeStamps(); |
- assertTrue(listOftimestamps.size() >= 2); |
+ assertTrue(listOftimestamps.size() >= 1); |
for (Long timeStamp : listOftimestamps) { |
capturer.returnBuffer(timeStamp); |
} |
@@ -415,12 +356,8 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { |
assertTrue(capturer.isReleased()); |
} |
- @MediumTest |
- // 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. |
- public void testReturnBufferLateEndToEnd() throws InterruptedException { |
- final VideoCapturerAndroid capturer = VideoCapturerAndroid.create("", null); |
+ static public void returnBufferLateEndToEnd(VideoCapturerAndroid capturer) |
+ throws InterruptedException { |
final PeerConnectionFactory factory = new PeerConnectionFactory(); |
final VideoSource source = factory.createVideoSource(capturer, new MediaConstraints()); |
final VideoTrack track = factory.createVideoTrack("dummy", source); |