| Index: webrtc/api/java/android/org/webrtc/Camera1Enumerator.java
|
| diff --git a/webrtc/api/java/android/org/webrtc/CameraEnumerator.java b/webrtc/api/java/android/org/webrtc/Camera1Enumerator.java
|
| similarity index 59%
|
| copy from webrtc/api/java/android/org/webrtc/CameraEnumerator.java
|
| copy to webrtc/api/java/android/org/webrtc/Camera1Enumerator.java
|
| index 203c1954b744de4ff88bd5942fec1dca6274b7fc..13a5237074f4f8c72b85f58e3d9e71ab46ab8258 100644
|
| --- a/webrtc/api/java/android/org/webrtc/CameraEnumerator.java
|
| +++ b/webrtc/api/java/android/org/webrtc/Camera1Enumerator.java
|
| @@ -10,23 +10,49 @@
|
|
|
| package org.webrtc;
|
|
|
| -import android.os.SystemClock;
|
| -
|
| import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
|
| -import org.webrtc.Logging;
|
| +
|
| +import android.os.SystemClock;
|
|
|
| import java.util.ArrayList;
|
| import java.util.List;
|
|
|
| @SuppressWarnings("deprecation")
|
| -public class CameraEnumerator {
|
| - private final static String TAG = "CameraEnumerator";
|
| +public class Camera1Enumerator implements CameraEnumerator {
|
| + private final static String TAG = "Camera1Enumerator";
|
| // Each entry contains the supported formats for corresponding camera index. The formats for all
|
| // cameras are enumerated on the first call to getSupportedFormats(), and cached for future
|
| // reference.
|
| private static List<List<CaptureFormat>> cachedSupportedFormats;
|
|
|
| - public static synchronized List<CaptureFormat> getSupportedFormats(int cameraId) {
|
| +
|
| + public boolean isFrontFacing(String deviceName) {
|
| + android.hardware.Camera.CameraInfo info = getCameraInfo(getCameraIndex(deviceName));
|
| + return info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT;
|
| + }
|
| +
|
| + public boolean isBackFacing(String deviceName) {
|
| + android.hardware.Camera.CameraInfo info = getCameraInfo(getCameraIndex(deviceName));
|
| + return info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK;
|
| + }
|
| +
|
| + public CameraVideoCapturer createCapturer(String deviceName,
|
| + CameraVideoCapturer.CameraEventsHandler eventsHandler) {
|
| + return new VideoCapturerAndroid(deviceName, eventsHandler, true);
|
| + }
|
| +
|
| + private static android.hardware.Camera.CameraInfo getCameraInfo(int index) {
|
| + android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
|
| + try {
|
| + android.hardware.Camera.getCameraInfo(index, info);
|
| + } catch (Exception e) {
|
| + Logging.e(TAG, "getCameraInfo failed on index " + index,e);
|
| + return null;
|
| + }
|
| + return info;
|
| + }
|
| +
|
| + static synchronized List<CaptureFormat> getSupportedFormats(int cameraId) {
|
| if (cachedSupportedFormats == null) {
|
| cachedSupportedFormats = new ArrayList<List<CaptureFormat>>();
|
| for (int i = 0; i < CameraEnumerationAndroid.getDeviceCount(); ++i) {
|
| @@ -80,8 +106,7 @@ public class CameraEnumerator {
|
| }
|
|
|
| // Convert from android.hardware.Camera.Size to Size.
|
| - public static List<Size> convertSizes(
|
| - List<android.hardware.Camera.Size> cameraSizes) {
|
| + public static List<Size> convertSizes(List<android.hardware.Camera.Size> cameraSizes) {
|
| final List<Size> sizes = new ArrayList<Size>();
|
| for (android.hardware.Camera.Size size : cameraSizes) {
|
| sizes.add(new Size(size.width, size.height));
|
| @@ -90,8 +115,7 @@ public class CameraEnumerator {
|
| }
|
|
|
| // Convert from int[2] to CaptureFormat.FramerateRange.
|
| - public static List<CaptureFormat.FramerateRange> convertFramerates(
|
| - List<int[]> arrayRanges) {
|
| + public static List<CaptureFormat.FramerateRange> convertFramerates(List<int[]> arrayRanges) {
|
| final List<CaptureFormat.FramerateRange> ranges = new ArrayList<CaptureFormat.FramerateRange>();
|
| for (int[] range : arrayRanges) {
|
| ranges.add(new CaptureFormat.FramerateRange(
|
| @@ -100,4 +124,36 @@ public class CameraEnumerator {
|
| }
|
| return ranges;
|
| }
|
| +
|
| + // Returns device names that can be used to create a new VideoCapturerAndroid.
|
| + public String[] getDeviceNames() {
|
| + String[] names = new String[android.hardware.Camera.getNumberOfCameras()];
|
| + for (int i = 0; i < android.hardware.Camera.getNumberOfCameras(); ++i) {
|
| + names[i] = getDeviceName(i);
|
| + }
|
| + return names;
|
| + }
|
| +
|
| + // Returns the camera index for camera with name |deviceName|, or throws IllegalArgumentException
|
| + // if no such camera can be found.
|
| + 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;
|
| + }
|
| + }
|
| + throw new IllegalArgumentException("No such camera: " + deviceName);
|
| + }
|
| +
|
| + // Returns the name of the camera with camera index. Returns null if the
|
| + // camera can not be used.
|
| + static String getDeviceName(int index) {
|
| + android.hardware.Camera.CameraInfo info = getCameraInfo(index);
|
| +
|
| + String facing =
|
| + (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) ? "front" : "back";
|
| + return "Camera " + index + ", Facing " + facing
|
| + + ", Orientation " + info.orientation;
|
| + }
|
| }
|
|
|