Index: webrtc/api/androidtests/src/org/webrtc/CameraVideoCapturerTestFixtures.java |
diff --git a/webrtc/api/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java b/webrtc/api/androidtests/src/org/webrtc/CameraVideoCapturerTestFixtures.java |
similarity index 74% |
rename from webrtc/api/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java |
rename to webrtc/api/androidtests/src/org/webrtc/CameraVideoCapturerTestFixtures.java |
index 6c4a6ea96fbaf50128f35af41fd1119b933e6360..f8db967b7abb626d689e1d2a13b8bf3af8610840 100644 |
--- a/webrtc/api/androidtests/src/org/webrtc/VideoCapturerAndroidTestFixtures.java |
+++ b/webrtc/api/androidtests/src/org/webrtc/CameraVideoCapturerTestFixtures.java |
@@ -9,20 +9,20 @@ |
*/ |
package org.webrtc; |
+import java.util.ArrayList; |
+import java.util.List; |
+import java.util.concurrent.CountDownLatch; |
+ |
import android.content.Context; |
-import org.webrtc.VideoCapturerAndroidTestFixtures; |
+import org.webrtc.CameraVideoCapturerTestFixtures; |
import org.webrtc.CameraEnumerationAndroid.CaptureFormat; |
import org.webrtc.VideoRenderer.I420Frame; |
-import java.util.ArrayList; |
-import java.util.List; |
-import java.util.concurrent.CountDownLatch; |
- |
import static junit.framework.Assert.*; |
-@SuppressWarnings("deprecation") |
-public class VideoCapturerAndroidTestFixtures { |
+public class CameraVideoCapturerTestFixtures { |
+ static final String TAG = "CameraVideoCapturerTestFixtures"; |
static class RendererCallbacks implements VideoRenderer.Callbacks { |
private int framesRendered = 0; |
private Object frameLock = 0; |
@@ -82,7 +82,7 @@ public class VideoCapturerAndroidTestFixtures { |
} |
} |
- static class FakeCapturerObserver implements VideoCapturer.CapturerObserver { |
+ static class FakeCapturerObserver implements CameraVideoCapturer.CapturerObserver { |
private int framesCaptured = 0; |
private int frameSize = 0; |
private int frameWidth = 0; |
@@ -171,7 +171,7 @@ public class VideoCapturerAndroidTestFixtures { |
} |
static class CameraEvents implements |
- VideoCapturerAndroid.CameraEventsHandler { |
+ CameraVideoCapturer.CameraEventsHandler { |
public boolean onCameraOpeningCalled; |
public boolean onFirstFrameAvailableCalled; |
public final Object onCameraFreezedLock = new Object(); |
@@ -214,18 +214,12 @@ public class VideoCapturerAndroidTestFixtures { |
return new CameraEvents(); |
} |
- // Return true if the device under test have at least two cameras. |
- @SuppressWarnings("deprecation") |
- static public boolean HaveTwoCameras() { |
- return (android.hardware.Camera.getNumberOfCameras() >= 2); |
- } |
- |
- static public void release(VideoCapturerAndroid capturer) { |
+ static public void release(CameraVideoCapturer capturer) { |
assertNotNull(capturer); |
capturer.dispose(); |
} |
- static public void startCapturerAndRender(VideoCapturerAndroid capturer) |
+ static public void startCapturerAndRender(CameraVideoCapturer capturer) |
throws InterruptedException { |
PeerConnectionFactory factory = new PeerConnectionFactory(null /* options */); |
VideoSource source = |
@@ -239,7 +233,7 @@ public class VideoCapturerAndroidTestFixtures { |
factory.dispose(); |
} |
- static public void switchCamera(VideoCapturerAndroid capturer) throws InterruptedException { |
+ static public void switchCamera(CameraVideoCapturer capturer) throws InterruptedException { |
PeerConnectionFactory factory = new PeerConnectionFactory(null /* options */); |
VideoSource source = |
factory.createVideoSource(capturer, new MediaConstraints()); |
@@ -248,7 +242,7 @@ public class VideoCapturerAndroidTestFixtures { |
// Array with one element to avoid final problem in nested classes. |
final boolean[] cameraSwitchSuccessful = new boolean[1]; |
final CountDownLatch barrier = new CountDownLatch(1); |
- capturer.switchCamera(new VideoCapturerAndroid.CameraSwitchHandler() { |
+ capturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() { |
@Override |
public void onCameraSwitchDone(boolean isFrontCamera) { |
cameraSwitchSuccessful[0] = true; |
@@ -264,11 +258,7 @@ public class VideoCapturerAndroidTestFixtures { |
barrier.await(); |
// Check result. |
- if (HaveTwoCameras()) { |
- assertTrue(cameraSwitchSuccessful[0]); |
- } else { |
- assertFalse(cameraSwitchSuccessful[0]); |
- } |
+ assertTrue(cameraSwitchSuccessful[0]); |
// Ensure that frames are received. |
RendererCallbacks callbacks = new RendererCallbacks(); |
track.addRenderer(new VideoRenderer(callbacks)); |
@@ -278,8 +268,8 @@ public class VideoCapturerAndroidTestFixtures { |
factory.dispose(); |
} |
- static public void cameraEventsInvoked(VideoCapturerAndroid capturer, CameraEvents events, |
- Context appContext) throws InterruptedException { |
+ static public void cameraEventsInvoked(CameraVideoCapturer capturer, CameraEvents events, |
+ Context appContext, boolean isCapturingToTexture) throws InterruptedException { |
final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
@@ -292,7 +282,7 @@ public class VideoCapturerAndroidTestFixtures { |
assertTrue(observer.WaitForCapturerToStart()); |
observer.WaitForNextCapturedFrame(); |
capturer.stopCapture(); |
- if (capturer.isCapturingToTexture()) { |
+ if (isCapturingToTexture) { |
surfaceTextureHelper.returnTextureFrame(); |
} |
release(capturer); |
@@ -303,7 +293,8 @@ public class VideoCapturerAndroidTestFixtures { |
} |
static public void cameraCallsAfterStop( |
- VideoCapturerAndroid capturer, Context appContext) throws InterruptedException { |
+ CameraVideoCapturer capturer, Context appContext, |
+ boolean isCapturingToTexture) throws InterruptedException { |
final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
@@ -315,7 +306,7 @@ public class VideoCapturerAndroidTestFixtures { |
// Make sure camera is started and then stop it. |
assertTrue(observer.WaitForCapturerToStart()); |
capturer.stopCapture(); |
- if (capturer.isCapturingToTexture()) { |
+ if (isCapturingToTexture) { |
surfaceTextureHelper.returnTextureFrame(); |
} |
@@ -328,7 +319,7 @@ public class VideoCapturerAndroidTestFixtures { |
surfaceTextureHelper.dispose(); |
} |
- static public void stopRestartVideoSource(VideoCapturerAndroid capturer) |
+ static public void stopRestartVideoSource(CameraVideoCapturer capturer) |
throws InterruptedException { |
PeerConnectionFactory factory = new PeerConnectionFactory(null /* options */); |
VideoSource source = |
@@ -350,8 +341,8 @@ public class VideoCapturerAndroidTestFixtures { |
factory.dispose(); |
} |
- static public void startStopWithDifferentResolutions(VideoCapturerAndroid capturer, |
- Context appContext) throws InterruptedException { |
+ static public void startStopWithDifferentResolutions(CameraVideoCapturer capturer, |
+ Context appContext, boolean isCapturingToTexture) throws InterruptedException { |
final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create( |
"SurfaceTextureHelper test" /* threadName */, null /* sharedContext */); |
FakeCapturerObserver observer = new FakeCapturerObserver(); |
@@ -375,13 +366,13 @@ public class VideoCapturerAndroidTestFixtures { |
+ format.width); |
} |
- if (capturer.isCapturingToTexture()) { |
+ if (isCapturingToTexture) { |
assertEquals(0, observer.frameSize()); |
} else { |
assertTrue(format.frameSize() <= observer.frameSize()); |
} |
capturer.stopCapture(); |
- if (capturer.isCapturingToTexture()) { |
+ if (isCapturingToTexture) { |
surfaceTextureHelper.returnTextureFrame(); |
} |
} |
@@ -389,86 +380,8 @@ public class VideoCapturerAndroidTestFixtures { |
surfaceTextureHelper.dispose(); |
} |
- static void waitUntilIdle(VideoCapturerAndroid capturer) throws InterruptedException { |
- final CountDownLatch barrier = new CountDownLatch(1); |
- capturer.getCameraThreadHandler().post(new Runnable() { |
- @Override public void run() { |
- barrier.countDown(); |
- } |
- }); |
- barrier.await(); |
- } |
- |
- static public void startWhileCameraIsAlreadyOpen( |
- VideoCapturerAndroid capturer, Context appContext) throws InterruptedException { |
- final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
- final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
- android.hardware.Camera camera = android.hardware.Camera.open(capturer.getCurrentCameraId()); |
- |
- final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create( |
- "SurfaceTextureHelper test" /* threadName */, null /* sharedContext */); |
- final FakeCapturerObserver observer = new FakeCapturerObserver(); |
- capturer.startCapture(format.width, format.height, format.framerate.max, |
- surfaceTextureHelper, appContext, observer); |
- |
- if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { |
- // The first opened camera client will be evicted. |
- assertTrue(observer.WaitForCapturerToStart()); |
- capturer.stopCapture(); |
- } else { |
- assertFalse(observer.WaitForCapturerToStart()); |
- } |
- |
- release(capturer); |
- camera.release(); |
- surfaceTextureHelper.dispose(); |
- } |
- |
- static public void startWhileCameraIsAlreadyOpenAndCloseCamera( |
- VideoCapturerAndroid capturer, Context appContext) throws InterruptedException { |
- final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
- final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
- android.hardware.Camera camera = android.hardware.Camera.open(capturer.getCurrentCameraId()); |
- |
- final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create( |
- "SurfaceTextureHelper test" /* threadName */, null /* sharedContext */); |
- final FakeCapturerObserver observer = new FakeCapturerObserver(); |
- capturer.startCapture(format.width, format.height, format.framerate.max, |
- surfaceTextureHelper, appContext, observer); |
- waitUntilIdle(capturer); |
- |
- camera.release(); |
- |
- // Make sure camera is started and first frame is received and then stop it. |
- assertTrue(observer.WaitForCapturerToStart()); |
- observer.WaitForNextCapturedFrame(); |
- capturer.stopCapture(); |
- if (capturer.isCapturingToTexture()) { |
- surfaceTextureHelper.returnTextureFrame(); |
- } |
- release(capturer); |
- surfaceTextureHelper.dispose(); |
- } |
- |
- static public void startWhileCameraIsAlreadyOpenAndStop( |
- VideoCapturerAndroid capturer, Context appContext) throws InterruptedException { |
- final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
- final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
- android.hardware.Camera camera = android.hardware.Camera.open(capturer.getCurrentCameraId()); |
- |
- final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create( |
- "SurfaceTextureHelper test" /* threadName */, null /* sharedContext */); |
- final FakeCapturerObserver observer = new FakeCapturerObserver(); |
- capturer.startCapture(format.width, format.height, format.framerate.max, |
- surfaceTextureHelper, appContext, observer); |
- capturer.stopCapture(); |
- release(capturer); |
- camera.release(); |
- surfaceTextureHelper.dispose(); |
- } |
- |
- static public void returnBufferLate(VideoCapturerAndroid capturer, |
- Context appContext) throws InterruptedException { |
+ static public void returnBufferLate(CameraVideoCapturer capturer, |
+ Context appContext, boolean isCapturingToTexture) throws InterruptedException { |
final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create( |
"SurfaceTextureHelper test" /* threadName */, null /* sharedContext */); |
FakeCapturerObserver observer = new FakeCapturerObserver(); |
@@ -488,7 +401,7 @@ public class VideoCapturerAndroidTestFixtures { |
capturer.startCapture(format.width, format.height, format.framerate.max, |
surfaceTextureHelper, appContext, observer); |
observer.WaitForCapturerToStart(); |
- if (capturer.isCapturingToTexture()) { |
+ if (isCapturingToTexture) { |
surfaceTextureHelper.returnTextureFrame(); |
} |
@@ -497,7 +410,7 @@ public class VideoCapturerAndroidTestFixtures { |
listOftimestamps = observer.getCopyAndResetListOftimeStamps(); |
assertTrue(listOftimestamps.size() >= 1); |
- if (capturer.isCapturingToTexture()) { |
+ if (isCapturingToTexture) { |
surfaceTextureHelper.returnTextureFrame(); |
} |
@@ -505,7 +418,7 @@ public class VideoCapturerAndroidTestFixtures { |
surfaceTextureHelper.dispose(); |
} |
- static public void returnBufferLateEndToEnd(VideoCapturerAndroid capturer) |
+ static public void returnBufferLateEndToEnd(CameraVideoCapturer capturer) |
throws InterruptedException { |
final PeerConnectionFactory factory = new PeerConnectionFactory(null /* options */); |
final VideoSource source = factory.createVideoSource(capturer, new MediaConstraints()); |
@@ -538,9 +451,9 @@ public class VideoCapturerAndroidTestFixtures { |
} |
static public void cameraFreezedEventOnBufferStarvationUsingTextures( |
- VideoCapturerAndroid capturer, |
- CameraEvents events, Context appContext) throws InterruptedException { |
- assertTrue("Not capturing to textures.", capturer.isCapturingToTexture()); |
+ CameraVideoCapturer capturer, CameraEvents events, Context appContext, |
+ boolean isCapturingToTexture) throws InterruptedException { |
+ assertTrue("Not capturing to textures.", isCapturingToTexture); |
final List<CaptureFormat> formats = capturer.getSupportedFormats(); |
final CameraEnumerationAndroid.CaptureFormat format = formats.get(0); |
@@ -558,7 +471,7 @@ public class VideoCapturerAndroidTestFixtures { |
events.WaitForCameraFreezed()); |
capturer.stopCapture(); |
- if (capturer.isCapturingToTexture()) { |
+ if (isCapturingToTexture) { |
surfaceTextureHelper.returnTextureFrame(); |
} |
@@ -566,7 +479,7 @@ public class VideoCapturerAndroidTestFixtures { |
surfaceTextureHelper.dispose(); |
} |
- static public void scaleCameraOutput(VideoCapturerAndroid capturer) throws InterruptedException { |
+ static public void scaleCameraOutput(CameraVideoCapturer capturer) throws InterruptedException { |
PeerConnectionFactory factory = new PeerConnectionFactory(null /* options */); |
VideoSource source = |
factory.createVideoSource(capturer, new MediaConstraints()); |
@@ -602,5 +515,4 @@ public class VideoCapturerAndroidTestFixtures { |
assertTrue(gotExpectedResolution); |
} |
- |
} |