From ea06a58f4018d85510acd96cf0304cb413a800b4 Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Mon, 14 Sep 2015 16:10:40 +0200 Subject: [PATCH] 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} --- .../org/webrtc/VideoCapturerAndroidTest.java | 12 +++--- .../org/webrtc/CameraEnumerationAndroid.java | 39 ++++++++----------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java index cc47741f36..8e195ac937 100644 --- a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java +++ b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java @@ -156,7 +156,7 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { return (Camera.getNumberOfCameras() >= 2); } - void starCapturerAndRender(String deviceName) throws InterruptedException { + void startCapturerAndRender(String deviceName) throws InterruptedException { PeerConnectionFactory factory = new PeerConnectionFactory(); VideoCapturerAndroid capturer = VideoCapturerAndroid.create(deviceName, null); @@ -216,9 +216,9 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { } @SmallTest - public void testCreateNoneExistingCamera() throws Exception { + public void testCreateNonExistingCamera() throws Exception { VideoCapturerAndroid capturer = VideoCapturerAndroid.create( - "none existing camera", null); + "non-existing camera", null); assertNull(capturer); } @@ -227,7 +227,7 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { // to a Java video renderer using a "default" capturer. // It tests both the Java and the C++ layer. public void testStartVideoCapturer() throws Exception { - starCapturerAndRender(""); + startCapturerAndRender(""); } @SmallTest @@ -235,7 +235,7 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { // 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 { - starCapturerAndRender(CameraEnumerationAndroid.getNameOfFrontFacingDevice()); + startCapturerAndRender(CameraEnumerationAndroid.getNameOfFrontFacingDevice()); } @SmallTest @@ -246,7 +246,7 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { if (!HaveTwoCameras()) { return; } - starCapturerAndRender(CameraEnumerationAndroid.getNameOfBackFacingDevice()); + startCapturerAndRender(CameraEnumerationAndroid.getNameOfBackFacingDevice()); } @SmallTest diff --git a/talk/app/webrtc/java/android/org/webrtc/CameraEnumerationAndroid.java b/talk/app/webrtc/java/android/org/webrtc/CameraEnumerationAndroid.java index 136c232b7f..11bdb6abb1 100644 --- a/talk/app/webrtc/java/android/org/webrtc/CameraEnumerationAndroid.java +++ b/talk/app/webrtc/java/android/org/webrtc/CameraEnumerationAndroid.java @@ -160,33 +160,13 @@ public class CameraEnumerationAndroid { // Returns the name of the front facing camera. Returns null if the // camera can not be used or does not exist. public static String getNameOfFrontFacingDevice() { - for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { - 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; + return getNameOfDevice(Camera.CameraInfo.CAMERA_FACING_FRONT); } // Returns the name of the back facing camera. Returns null if the // camera can not be used or does not exist. public static String getNameOfBackFacingDevice() { - for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { - 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; + return getNameOfDevice(Camera.CameraInfo.CAMERA_FACING_BACK); } 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; + } }