Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Unified Diff: webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java

Issue 2012193003: VideoCapturerAndroid: Replace static create() with ctor (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add @Deprecated. Make ctor public. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698