OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return cameraManager.getCameraCharacteristics(deviceName); | 97 return cameraManager.getCameraCharacteristics(deviceName); |
98 // On Android OS pre 4.4.2, a class will not load because of VerifyError i
f it contains a | 98 // On Android OS pre 4.4.2, a class will not load because of VerifyError i
f it contains a |
99 // catch statement with an Exception from a newer API, even if the code is
never executed. | 99 // catch statement with an Exception from a newer API, even if the code is
never executed. |
100 // https://code.google.com/p/android/issues/detail?id=209129 | 100 // https://code.google.com/p/android/issues/detail?id=209129 |
101 } catch (/* CameraAccessException */ AndroidException e) { | 101 } catch (/* CameraAccessException */ AndroidException e) { |
102 Logging.e(TAG, "Camera access exception: " + e); | 102 Logging.e(TAG, "Camera access exception: " + e); |
103 return null; | 103 return null; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
| 107 /** |
| 108 * Checks if Android version is new enough to support camera2. |
| 109 * |
| 110 * This method will be removed soon. Use isSupported(Context). |
| 111 */ |
| 112 @Deprecated |
107 public static boolean isSupported() { | 113 public static boolean isSupported() { |
108 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; | 114 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; |
109 } | 115 } |
110 | 116 |
| 117 /** |
| 118 * Checks if API is supported and all cameras have better than legacy support. |
| 119 */ |
| 120 public static boolean isSupported(Context context) { |
| 121 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
| 122 return false; |
| 123 } |
| 124 |
| 125 CameraManager cameraManager = (CameraManager) context.getSystemService(Conte
xt.CAMERA_SERVICE); |
| 126 try { |
| 127 String[] cameraIds = cameraManager.getCameraIdList(); |
| 128 for (String id : cameraIds) { |
| 129 CameraCharacteristics characteristics = cameraManager.getCameraCharacter
istics(id); |
| 130 if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LE
VEL) |
| 131 == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) { |
| 132 return false; |
| 133 } |
| 134 } |
| 135 // On Android OS pre 4.4.2, a class will not load because of VerifyError if
it contains a |
| 136 // catch statement with an Exception from a newer API, even if the code is n
ever executed. |
| 137 // https://code.google.com/p/android/issues/detail?id=209129 |
| 138 } catch (/* CameraAccessException */ AndroidException e) { |
| 139 Logging.e(TAG, "Camera access exception: " + e); |
| 140 return false; |
| 141 } |
| 142 return true; |
| 143 } |
| 144 |
111 static int getFpsUnitFactor(Range<Integer>[] fpsRanges) { | 145 static int getFpsUnitFactor(Range<Integer>[] fpsRanges) { |
112 if (fpsRanges.length == 0) { | 146 if (fpsRanges.length == 0) { |
113 return 1000; | 147 return 1000; |
114 } | 148 } |
115 return fpsRanges[0].getUpper() < 1000 ? 1000 : 1; | 149 return fpsRanges[0].getUpper() < 1000 ? 1000 : 1; |
116 } | 150 } |
117 | 151 |
118 static List<Size> getSupportedSizes( | 152 static List<Size> getSupportedSizes( |
119 CameraCharacteristics cameraCharacteristics) { | 153 CameraCharacteristics cameraCharacteristics) { |
120 final StreamConfigurationMap streamMap = | 154 final StreamConfigurationMap streamMap = |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 Range<Integer>[] arrayRanges, int unitFactor) { | 254 Range<Integer>[] arrayRanges, int unitFactor) { |
221 final List<CaptureFormat.FramerateRange> ranges = new ArrayList<CaptureForma
t.FramerateRange>(); | 255 final List<CaptureFormat.FramerateRange> ranges = new ArrayList<CaptureForma
t.FramerateRange>(); |
222 for (Range<Integer> range : arrayRanges) { | 256 for (Range<Integer> range : arrayRanges) { |
223 ranges.add(new CaptureFormat.FramerateRange( | 257 ranges.add(new CaptureFormat.FramerateRange( |
224 range.getLower() * unitFactor, | 258 range.getLower() * unitFactor, |
225 range.getUpper() * unitFactor)); | 259 range.getUpper() * unitFactor)); |
226 } | 260 } |
227 return ranges; | 261 return ranges; |
228 } | 262 } |
229 } | 263 } |
OLD | NEW |