Add new Camera2Enumerator.isSupported with Context parameter.
The old method is marked deprecated and will be removed soon. The new method checks if all cameras on the device support better than legacy implementation of the camera2 API. BUG=webrtc:6390 Review-Url: https://codereview.webrtc.org/2354883002 Cr-Commit-Position: refs/heads/master@{#14350}
This commit is contained in:
parent
09baefeaf9
commit
1c6d3f7eae
@ -104,10 +104,44 @@ public class Camera2Enumerator implements CameraEnumerator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Android version is new enough to support camera2.
|
||||
*
|
||||
* This method will be removed soon. Use isSupported(Context).
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isSupported() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if API is supported and all cameras have better than legacy support.
|
||||
*/
|
||||
public static boolean isSupported(Context context) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
|
||||
try {
|
||||
String[] cameraIds = cameraManager.getCameraIdList();
|
||||
for (String id : cameraIds) {
|
||||
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(id);
|
||||
if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
|
||||
== CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
|
||||
// catch statement with an Exception from a newer API, even if the code is never executed.
|
||||
// https://code.google.com/p/android/issues/detail?id=209129
|
||||
} catch (/* CameraAccessException */ AndroidException e) {
|
||||
Logging.e(TAG, "Camera access exception: " + e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int getFpsUnitFactor(Range<Integer>[] fpsRanges) {
|
||||
if (fpsRanges.length == 0) {
|
||||
return 1000;
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
<string name="pref_camera2_key">camera2_preference</string>
|
||||
<string name="pref_camera2_title">Use Camera2.</string>
|
||||
<string name="pref_camera2_default">true</string>
|
||||
<string name="pref_camera2_not_supported">Only supported on Android Lollipop and forward.</string>
|
||||
<string name="pref_camera2_not_supported">Not supported on this device.</string>
|
||||
|
||||
<string name="pref_resolution_key">resolution_preference</string>
|
||||
<string name="pref_resolution_title">Video resolution.</string>
|
||||
|
||||
@ -232,7 +232,7 @@ public class CallActivity extends Activity
|
||||
boolean loopback = intent.getBooleanExtra(EXTRA_LOOPBACK, false);
|
||||
boolean tracing = intent.getBooleanExtra(EXTRA_TRACING, false);
|
||||
|
||||
boolean useCamera2 = Camera2Enumerator.isSupported()
|
||||
boolean useCamera2 = Camera2Enumerator.isSupported(this)
|
||||
&& intent.getBooleanExtra(EXTRA_CAMERA2, true);
|
||||
|
||||
peerConnectionParameters = new PeerConnectionParameters(
|
||||
|
||||
@ -126,7 +126,7 @@ public class SettingsActivity extends Activity
|
||||
updateSummaryB(sharedPreferences, keyPrefDisplayHud);
|
||||
updateSummaryB(sharedPreferences, keyPrefTracing);
|
||||
|
||||
if (!Camera2Enumerator.isSupported()) {
|
||||
if (!Camera2Enumerator.isSupported(this)) {
|
||||
Preference camera2Preference =
|
||||
settingsFragment.findPreference(keyprefCamera2);
|
||||
|
||||
|
||||
@ -291,7 +291,8 @@ public class PeerConnectionClientTest extends InstrumentationTestCase
|
||||
|
||||
private PeerConnectionParameters createParametersForVideoCall(
|
||||
String videoCodec, boolean captureToTexture) {
|
||||
final boolean useCamera2 = captureToTexture && Camera2Enumerator.isSupported();
|
||||
final boolean useCamera2 = captureToTexture
|
||||
&& Camera2Enumerator.isSupported(getInstrumentation().getTargetContext());
|
||||
|
||||
PeerConnectionParameters peerConnectionParameters =
|
||||
new PeerConnectionParameters(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user