Android video capture: Remove duplicated code and fix spelling mistakes
This CL does not contain any functional changes, it is purely nit fixes. R=hbos@webrtc.org Review URL: https://codereview.webrtc.org/1340923002 . Cr-Commit-Position: refs/heads/master@{#9931}
This commit is contained in:
@ -156,7 +156,7 @@ public class VideoCapturerAndroidTest extends ActivityTestCase {
|
|||||||
return (Camera.getNumberOfCameras() >= 2);
|
return (Camera.getNumberOfCameras() >= 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void starCapturerAndRender(String deviceName) throws InterruptedException {
|
void startCapturerAndRender(String deviceName) throws InterruptedException {
|
||||||
PeerConnectionFactory factory = new PeerConnectionFactory();
|
PeerConnectionFactory factory = new PeerConnectionFactory();
|
||||||
VideoCapturerAndroid capturer =
|
VideoCapturerAndroid capturer =
|
||||||
VideoCapturerAndroid.create(deviceName, null);
|
VideoCapturerAndroid.create(deviceName, null);
|
||||||
@ -216,9 +216,9 @@ public class VideoCapturerAndroidTest extends ActivityTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testCreateNoneExistingCamera() throws Exception {
|
public void testCreateNonExistingCamera() throws Exception {
|
||||||
VideoCapturerAndroid capturer = VideoCapturerAndroid.create(
|
VideoCapturerAndroid capturer = VideoCapturerAndroid.create(
|
||||||
"none existing camera", null);
|
"non-existing camera", null);
|
||||||
assertNull(capturer);
|
assertNull(capturer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ public class VideoCapturerAndroidTest extends ActivityTestCase {
|
|||||||
// to a Java video renderer using a "default" capturer.
|
// to a Java video renderer using a "default" capturer.
|
||||||
// It tests both the Java and the C++ layer.
|
// It tests both the Java and the C++ layer.
|
||||||
public void testStartVideoCapturer() throws Exception {
|
public void testStartVideoCapturer() throws Exception {
|
||||||
starCapturerAndRender("");
|
startCapturerAndRender("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@ -235,7 +235,7 @@ public class VideoCapturerAndroidTest extends ActivityTestCase {
|
|||||||
// to a Java video renderer using the front facing video capturer.
|
// to a Java video renderer using the front facing video capturer.
|
||||||
// It tests both the Java and the C++ layer.
|
// It tests both the Java and the C++ layer.
|
||||||
public void testStartFrontFacingVideoCapturer() throws Exception {
|
public void testStartFrontFacingVideoCapturer() throws Exception {
|
||||||
starCapturerAndRender(CameraEnumerationAndroid.getNameOfFrontFacingDevice());
|
startCapturerAndRender(CameraEnumerationAndroid.getNameOfFrontFacingDevice());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@ -246,7 +246,7 @@ public class VideoCapturerAndroidTest extends ActivityTestCase {
|
|||||||
if (!HaveTwoCameras()) {
|
if (!HaveTwoCameras()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
starCapturerAndRender(CameraEnumerationAndroid.getNameOfBackFacingDevice());
|
startCapturerAndRender(CameraEnumerationAndroid.getNameOfBackFacingDevice());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
|
@ -160,33 +160,13 @@ public class CameraEnumerationAndroid {
|
|||||||
// Returns the name of the front facing camera. Returns null if the
|
// Returns the name of the front facing camera. Returns null if the
|
||||||
// camera can not be used or does not exist.
|
// camera can not be used or does not exist.
|
||||||
public static String getNameOfFrontFacingDevice() {
|
public static String getNameOfFrontFacingDevice() {
|
||||||
for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
|
return getNameOfDevice(Camera.CameraInfo.CAMERA_FACING_FRONT);
|
||||||
Camera.CameraInfo info = new Camera.CameraInfo();
|
|
||||||
try {
|
|
||||||
Camera.getCameraInfo(i, info);
|
|
||||||
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
|
|
||||||
return getDeviceName(i);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "getCameraInfo failed on index " + i, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the name of the back facing camera. Returns null if the
|
// Returns the name of the back facing camera. Returns null if the
|
||||||
// camera can not be used or does not exist.
|
// camera can not be used or does not exist.
|
||||||
public static String getNameOfBackFacingDevice() {
|
public static String getNameOfBackFacingDevice() {
|
||||||
for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
|
return getNameOfDevice(Camera.CameraInfo.CAMERA_FACING_BACK);
|
||||||
Camera.CameraInfo info = new Camera.CameraInfo();
|
|
||||||
try {
|
|
||||||
Camera.getCameraInfo(i, info);
|
|
||||||
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK)
|
|
||||||
return getDeviceName(i);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "getCameraInfo failed on index " + i, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSupportedFormatsAsJson(int id) throws JSONException {
|
public static String getSupportedFormatsAsJson(int id) throws JSONException {
|
||||||
@ -239,4 +219,19 @@ public class CameraEnumerationAndroid {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getNameOfDevice(int facing) {
|
||||||
|
final Camera.CameraInfo info = new Camera.CameraInfo();
|
||||||
|
for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
|
||||||
|
try {
|
||||||
|
Camera.getCameraInfo(i, info);
|
||||||
|
if (info.facing == facing) {
|
||||||
|
return getDeviceName(i);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "getCameraInfo() failed on index " + i, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user