CameraEnumerationAndroid: Remove Enumerator class

BUG=webrtc:5519

Review-Url: https://codereview.webrtc.org/2015143004
Cr-Commit-Position: refs/heads/master@{#12999}
This commit is contained in:
magjed
2016-06-01 14:39:35 -07:00
committed by Commit bot
parent 0fe8548303
commit 453018a29e
5 changed files with 24 additions and 46 deletions

View File

@ -31,26 +31,26 @@ import java.util.List;
import java.util.Map;
@TargetApi(21)
public class Camera2Enumerator implements CameraEnumerationAndroid.Enumerator {
public class Camera2Enumerator {
private final static String TAG = "Camera2Enumerator";
private final static double NANO_SECONDS_PER_SECOND = 1.0e9;
private final CameraManager cameraManager;
// Each entry contains the supported formats for a given camera index. The formats are enumerated
// lazily in getSupportedFormats(), and cached for future reference.
private final Map<Integer, List<CaptureFormat>> cachedSupportedFormats =
new HashMap<Integer, List<CaptureFormat>>();
private static final Map<String, List<CaptureFormat>> cachedSupportedFormats =
new HashMap<String, List<CaptureFormat>>();
public static boolean isSupported() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}
public Camera2Enumerator(Context context) {
cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
public static List<CaptureFormat> getSupportedFormats(Context context, String cameraId) {
return getSupportedFormats(
(CameraManager) context.getSystemService(Context.CAMERA_SERVICE), cameraId);
}
@Override
public List<CaptureFormat> getSupportedFormats(int cameraId) {
public static List<CaptureFormat> getSupportedFormats(
CameraManager cameraManager, String cameraId) {
synchronized (cachedSupportedFormats) {
if (cachedSupportedFormats.containsKey(cameraId)) {
return cachedSupportedFormats.get(cameraId);
@ -60,7 +60,7 @@ public class Camera2Enumerator implements CameraEnumerationAndroid.Enumerator {
final CameraCharacteristics cameraCharacteristics;
try {
cameraCharacteristics = cameraManager.getCameraCharacteristics(Integer.toString(cameraId));
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
} catch (Exception ex) {
Logging.e(TAG, "getCameraCharacteristics(): " + ex);
return new ArrayList<CaptureFormat>();

View File

@ -22,25 +22,6 @@ import java.util.List;
@SuppressWarnings("deprecation")
public class CameraEnumerationAndroid {
private final static String TAG = "CameraEnumerationAndroid";
// Synchronized on |CameraEnumerationAndroid.this|.
private static Enumerator enumerator = new CameraEnumerator();
public interface Enumerator {
/**
* Returns a list of supported CaptureFormats for the camera with index |cameraId|.
*/
List<CaptureFormat> getSupportedFormats(int cameraId);
}
public static synchronized void setEnumerator(Enumerator enumerator) {
CameraEnumerationAndroid.enumerator = enumerator;
}
public static synchronized List<CaptureFormat> getSupportedFormats(int cameraId) {
final List<CaptureFormat> formats = enumerator.getSupportedFormats(cameraId);
Logging.d(TAG, "Supported formats for camera " + cameraId + ": " + formats);
return formats;
}
public static class CaptureFormat {
// Class to represent a framerate range. The framerate varies because of lightning conditions.

View File

@ -19,27 +19,24 @@ import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("deprecation")
public class CameraEnumerator implements CameraEnumerationAndroid.Enumerator {
public class CameraEnumerator {
private final static String TAG = "CameraEnumerator";
// 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 List<List<CaptureFormat>> cachedSupportedFormats;
private static List<List<CaptureFormat>> cachedSupportedFormats;
@Override
public List<CaptureFormat> getSupportedFormats(int cameraId) {
synchronized (this) {
if (cachedSupportedFormats == null) {
cachedSupportedFormats = new ArrayList<List<CaptureFormat>>();
for (int i = 0; i < CameraEnumerationAndroid.getDeviceCount(); ++i) {
cachedSupportedFormats.add(enumerateFormats(i));
}
public static synchronized List<CaptureFormat> getSupportedFormats(int cameraId) {
if (cachedSupportedFormats == null) {
cachedSupportedFormats = new ArrayList<List<CaptureFormat>>();
for (int i = 0; i < CameraEnumerationAndroid.getDeviceCount(); ++i) {
cachedSupportedFormats.add(enumerateFormats(i));
}
}
return cachedSupportedFormats.get(cameraId);
}
private List<CaptureFormat> enumerateFormats(int cameraId) {
private static List<CaptureFormat> enumerateFormats(int cameraId) {
Logging.d(TAG, "Get supported formats for camera index " + cameraId + ".");
final long startTimeMs = SystemClock.elapsedRealtime();
final android.hardware.Camera.Parameters parameters;

View File

@ -207,7 +207,7 @@ public class VideoCapturerAndroid implements
@Override
public List<CaptureFormat> getSupportedFormats() {
return CameraEnumerationAndroid.getSupportedFormats(getCurrentCameraId());
return CameraEnumerator.getSupportedFormats(getCurrentCameraId());
}
// Returns true if this VideoCapturer is setup to capture video frames to a SurfaceTexture.