| Index: webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java
|
| diff --git a/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java b/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java
|
| index e4c33d50a002acf0aee02dae3a93e80808015e39..aa4461fbe26a9df5025a9c82d2262e9500b4a827 100644
|
| --- a/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java
|
| +++ b/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java
|
| @@ -105,13 +105,16 @@ public class VideoCapturerAndroid implements
|
| return VideoCapturerAndroid.create(name, eventsHandler, false /* captureToTexture */);
|
| }
|
|
|
| + // Use ctor directly instead.
|
| + @Deprecated
|
| public static VideoCapturerAndroid create(String name,
|
| CameraEventsHandler eventsHandler, boolean captureToTexture) {
|
| - final int cameraId = lookupDeviceName(name);
|
| - if (cameraId == -1) {
|
| + try {
|
| + return new VideoCapturerAndroid(name, eventsHandler, captureToTexture);
|
| + } catch (RuntimeException e) {
|
| + Logging.e(TAG, "Couldn't create camera.", e);
|
| return null;
|
| }
|
| - return new VideoCapturerAndroid(cameraId, eventsHandler, captureToTexture);
|
| }
|
|
|
| public void printStackTrace() {
|
| @@ -213,9 +216,16 @@ public class VideoCapturerAndroid implements
|
| return isCapturingToTexture;
|
| }
|
|
|
| - private VideoCapturerAndroid(int cameraId, CameraEventsHandler eventsHandler,
|
| + public VideoCapturerAndroid(String cameraName, CameraEventsHandler eventsHandler,
|
| boolean captureToTexture) {
|
| - this.id = cameraId;
|
| + if (android.hardware.Camera.getNumberOfCameras() == 0) {
|
| + throw new RuntimeException("No cameras available");
|
| + }
|
| + if (cameraName == null || cameraName == "") {
|
| + this.id = 0;
|
| + } else {
|
| + this.id = getCameraIndex(cameraName);
|
| + }
|
| this.eventsHandler = eventsHandler;
|
| isCapturingToTexture = captureToTexture;
|
| Logging.d(TAG, "VideoCapturerAndroid isCapturingToTexture : " + isCapturingToTexture);
|
| @@ -227,22 +237,16 @@ public class VideoCapturerAndroid implements
|
| }
|
| }
|
|
|
| - // Returns the camera index for camera with name |deviceName|, or -1 if no such camera can be
|
| - // found. If |deviceName| is empty, the first available device is used.
|
| - private static int lookupDeviceName(String deviceName) {
|
| - Logging.d(TAG, "lookupDeviceName: " + deviceName);
|
| - if (deviceName == null || android.hardware.Camera.getNumberOfCameras() == 0) {
|
| - return -1;
|
| - }
|
| - if (deviceName.isEmpty()) {
|
| - return 0;
|
| - }
|
| + // Returns the camera index for camera with name |deviceName|, or throws IllegalArgumentException
|
| + // if no such camera can be found.
|
| + private static int getCameraIndex(String deviceName) {
|
| + Logging.d(TAG, "getCameraIndex: " + deviceName);
|
| for (int i = 0; i < android.hardware.Camera.getNumberOfCameras(); ++i) {
|
| if (deviceName.equals(CameraEnumerationAndroid.getDeviceName(i))) {
|
| return i;
|
| }
|
| }
|
| - return -1;
|
| + throw new IllegalArgumentException("No such camera: " + deviceName);
|
| }
|
|
|
| private boolean maybePostOnCameraThread(Runnable runnable) {
|
|
|