private VideoCapturer createVideoCapturer() { VideoCapturer videoCapturer = null; Log.d(TAG, "Creating capturer using camera2 API."); // Creating camera capturer Camera2Enumerator enumerator = new Camera2Enumerator(this); final String[] deviceNames = enumerator.getDeviceNames(); Log.d(TAG, "Looking for back facing cameras."); for (String deviceName : deviceNames) { if (enumerator.isBackFacing(deviceName)) { Log.d(TAG, "Creating back facing camera capturer."); videoCapturer = enumerator.createCapturer(deviceName, null); break; } } if (videoCapturer == null) { Log.e(TAG, "Failed to open camera."); return null; } return videoCapturer; }
private void setCameraPairs(Context context) { Camera2Enumerator camera2Enumerator = new Camera2Enumerator(context); for (String cameraId : camera2Enumerator.getDeviceNames()) { if (camera2Enumerator.isFrontFacing(cameraId)) { frontCameraPair = new Pair<>(CameraCapturer.CameraSource.FRONT_CAMERA, cameraId); } if (camera2Enumerator.isBackFacing(cameraId)) { backCameraPair = new Pair<>(CameraCapturer.CameraSource.BACK_CAMERA, cameraId); } } }
/** * Get a camera enumerator * * @param context the context * @return the camera enumerator */ private static CameraEnumerator getCameraEnumerator(Context context) { if (useCamera2(context)) { return new Camera2Enumerator(context); } else { return new Camera1Enumerator(false); } }
private boolean useCamera2() { return Camera2Enumerator.isSupported(this) && getIntent().getBooleanExtra(EXTRA_CAMERA2, true); }
public static VideoCapturer createCamera2Capturer(Context context) { return createCameraCapturer(new Camera2Enumerator(context)); }
/** * Tells if the camera2 Api is supported * * @param context the context * @return true if the Camera2 API is supported */ private static boolean useCamera2(Context context) { return Camera2Enumerator.isSupported(context); }