Update Android camera switch API to allow specifying a name

The current camera switch API sequentially cycles through each
camera name for each method invocation. This policy provides
reasonable behavior for devices with 2 or 3 cameras, but
presents challenges with devices that contain several cameras.
For example in a scenario where the current camera is oriented
on the same side as the next camera name, a developer would need to
call switchCamera multiple times to capture from a camera oriented on
a different side of the device.

This commit allows a developer to specify a camera name when switching
cameras. This flexibility allows developers to have more control over
which device they switch to in cases where a device contains several cameras.

Bug: webrtc:11261
Change-Id: I93d46d70b2c7cf735a411a4ef4f33e926bf3a5ea
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165040
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30199}
This commit is contained in:
Aaron Alaniz
2020-01-09 04:26:04 +00:00
committed by Commit Bot
parent e1cbb9c20e
commit 415e39da56
7 changed files with 85 additions and 27 deletions

View File

@ -114,6 +114,12 @@ public class Camera1CapturerUsingByteBufferTest {
fixtures.switchCamera();
}
@Test
@MediumTest
public void testSwitchVideoCapturerToSpecificCameraName() throws InterruptedException {
fixtures.switchCamera(true /* specifyCameraName */);
}
@Test
@MediumTest
public void testCameraEvents() throws InterruptedException {

View File

@ -109,6 +109,12 @@ public class Camera1CapturerUsingTextureTest {
fixtures.switchCamera();
}
@Test
@MediumTest
public void testSwitchVideoCapturerToSpecificCameraName() throws InterruptedException {
fixtures.switchCamera(true /* specifyCameraName */);
}
@Test
@MediumTest
public void testCameraEvents() throws InterruptedException {

View File

@ -237,6 +237,12 @@ public class Camera2CapturerTest {
fixtures.switchCamera();
}
@Test
@MediumTest
public void testSwitchVideoCapturerToSpecificCameraName() throws InterruptedException {
fixtures.switchCamera(true /* specifyCameraName */);
}
@Test
@MediumTest
public void testCameraEvents() throws InterruptedException {

View File

@ -472,6 +472,10 @@ class CameraVideoCapturerTestFixtures {
}
public void switchCamera() throws InterruptedException {
switchCamera(false /* specifyCameraName */);
}
public void switchCamera(boolean specifyCameraName) throws InterruptedException {
if (!testObjectFactory.haveTwoCameras()) {
Logging.w(
TAG, "Skipping test switch video capturer because the device doesn't have two cameras.");
@ -487,18 +491,25 @@ class CameraVideoCapturerTestFixtures {
// Array with one element to avoid final problem in nested classes.
final boolean[] cameraSwitchSuccessful = new boolean[1];
final CountDownLatch barrier = new CountDownLatch(1);
capturerInstance.capturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() {
@Override
public void onCameraSwitchDone(boolean isFrontCamera) {
cameraSwitchSuccessful[0] = true;
barrier.countDown();
}
@Override
public void onCameraSwitchError(String errorDescription) {
cameraSwitchSuccessful[0] = false;
barrier.countDown();
}
});
final CameraVideoCapturer.CameraSwitchHandler cameraSwitchHandler =
new CameraVideoCapturer.CameraSwitchHandler() {
@Override
public void onCameraSwitchDone(boolean isFrontCamera) {
cameraSwitchSuccessful[0] = true;
barrier.countDown();
}
@Override
public void onCameraSwitchError(String errorDescription) {
cameraSwitchSuccessful[0] = false;
barrier.countDown();
}
};
if (specifyCameraName) {
String expectedCameraName = testObjectFactory.cameraEnumerator.getDeviceNames()[1];
capturerInstance.capturer.switchCamera(cameraSwitchHandler, expectedCameraName);
} else {
capturerInstance.capturer.switchCamera(cameraSwitchHandler);
}
// Wait until the camera has been switched.
barrier.await();