Java Code Examples for android.hardware.camera2.CameraCharacteristics#LENS_FACING_BACK

The following examples show how to use android.hardware.camera2.CameraCharacteristics#LENS_FACING_BACK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 7 votes vote down vote up
private String getCameraId() {
    try {
        String[] ids = mCameraManager.getCameraIdList();
        for (String id : ids) {
            CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
            Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            Integer facingDirection = c.get(CameraCharacteristics.LENS_FACING);
            if (flashAvailable != null
                    && flashAvailable
                    && facingDirection != null
                    && facingDirection == CameraCharacteristics.LENS_FACING_BACK) {
                return id;
            }
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 2
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 6 votes vote down vote up
private String getCameraId() {
    try {
        String[] ids = mCameraManager.getCameraIdList();
        for (String id : ids) {
            CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
            Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            Integer facingDirection = c.get(CameraCharacteristics.LENS_FACING);
            if (flashAvailable != null
                    && flashAvailable
                    && facingDirection != null
                    && facingDirection == CameraCharacteristics.LENS_FACING_BACK) {
                return id;
            }
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 3
Source File: Camera2Recorder.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * カメラの位置を判定する.
 * @return カメラの位置
 */
private CameraFacing detectFacing() {
    try {
        int facing = Camera2Helper.getFacing(mCameraManager, mCameraId);
        switch (facing) {
            case CameraCharacteristics.LENS_FACING_BACK:
                return CameraFacing.BACK;
            case CameraCharacteristics.LENS_FACING_FRONT:
                return CameraFacing.FRONT;
            case CameraCharacteristics.LENS_FACING_EXTERNAL:
                return CameraFacing.EXTERNAL;
            default:
                return CameraFacing.UNKNOWN;
        }
    } catch (CameraAccessException e) {
        return CameraFacing.UNKNOWN;
    }
}
 
Example 4
Source File: TorchService.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private String getCameraId() {
    if (mCameraId == null) {
        try {
            String[] ids = mCameraManager.getCameraIdList();
            for (String id : ids) {
                CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
                Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
                Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
                if (flashAvailable != null && flashAvailable && lensFacing != null &&
                        lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
                    mCameraId = id;
                }
            }
            if (DEBUG) Log.d(TAG, "getCameraId: " + mCameraId);
        } catch (Exception e) {
            e.printStackTrace();
            mTorchStatus = TORCH_STATUS_ERROR;
            broadcastStatus();
            stopSelf();
        }
    }
    return mCameraId;
}
 
Example 5
Source File: FlashHandler.java    From habpanelviewer with GNU General Public License v3.0 6 votes vote down vote up
public FlashHandler(CameraManager cameraManager) {
    mCameraManager = cameraManager;

    try {
        for (String camId : mCameraManager.getCameraIdList()) {
            CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(camId);
            Boolean hasFlash = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);

            if (facing != null && facing == CameraCharacteristics.LENS_FACING_BACK
                    && Boolean.TRUE.equals(hasFlash)) {
                torchId = camId;
                break;
            }
        }

        if (torchId != null) {
            controller = new FlashControlThread();
            controller.start();
        }
    } catch (CameraAccessException e) {
        Log.d(TAG, "Could not create flash controller");
    }
}
 
Example 6
Source File: CameraInfo.java    From MobileInfo with Apache License 2.0 5 votes vote down vote up
private static String getFacing(Integer facing) {
    if (facing == null) {
        return UNKNOWN;
    }
    switch (facing) {
        case CameraCharacteristics.LENS_FACING_FRONT:
            return "FRONT";
        case CameraCharacteristics.LENS_FACING_BACK:
            return "BACK";
        case CameraCharacteristics.LENS_FACING_EXTERNAL:
            return "EXTERNAL";
        default:
            return UNKNOWN + "-" + facing;
    }
}
 
Example 7
Source File: Camera2WrapperManager.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * サポートしているカメラのタイプ一覧を取得します.
 *
 * @param context コンテキスト
 * @return カメラのタイプ一覧
 */
public static List<Integer> supportCameraIds(Context context) {
    CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    if (manager == null) {
        throw new UnsupportedOperationException("Not supported a Camera.");
    }

    List<Integer> list = new ArrayList<>();
    try {
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null) {
                switch (facing) {
                    case CameraCharacteristics.LENS_FACING_BACK:
                        list.add(CameraCharacteristics.LENS_FACING_BACK);
                        break;
                    case CameraCharacteristics.LENS_FACING_FRONT:
                        list.add(CameraCharacteristics.LENS_FACING_FRONT);
                        break;
                    default:
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            list.add(CameraCharacteristics.LENS_FACING_EXTERNAL);
                        }
                        break;
                }
            }
        }
    } catch (CameraAccessException e) {
        // ignore.
    }
    return list;
}
 
Example 8
Source File: Camera2Helper.java    From CameraCompat with MIT License 5 votes vote down vote up
private void initCameraIds() throws CameraAccessException {
    for (String cameraId : mCameraManager.getCameraIdList()) {
        CameraCharacteristics characteristics =
                mCameraManager.getCameraCharacteristics(cameraId);

        Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
        if (facing != null) {
            if (facing == CameraCharacteristics.LENS_FACING_FRONT) {
                mFrontCameraId = cameraId;
            } else if (facing == CameraCharacteristics.LENS_FACING_BACK) {
                mBackCameraId = cameraId;
            }
        }
    }
}
 
Example 9
Source File: BaseCameraActivity.java    From fritz-examples with MIT License 5 votes vote down vote up
protected void toggleCameraFacingDirection() {
    final OverlayView overlay = findViewById(R.id.debug_overlay);
    if (overlay != null) {
        overlay.setVisibility(View.INVISIBLE);
    }

    if (cameraFacingDirection == CameraCharacteristics.LENS_FACING_FRONT) {
        cameraFacingDirection = CameraCharacteristics.LENS_FACING_BACK;
    } else {
        cameraFacingDirection = CameraCharacteristics.LENS_FACING_FRONT;
    }

    cameraId = chooseCamera();
    fragment.switchCamera(cameraId);
}
 
Example 10
Source File: AndroidSensorsDriver.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
protected void createCameraOutputs(Context androidContext) throws SensorException
{
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.LOLLIPOP+2)
    {
        CameraManager cameraManager = (CameraManager)androidContext.getSystemService(Context.CAMERA_SERVICE);
        
        try
        {
            String[] camIds = cameraManager.getCameraIdList();
            for (String cameraId: camIds)
            {
                log.debug("Detected camera " + cameraId);
                int camDir = cameraManager.getCameraCharacteristics(cameraId).get(CameraCharacteristics.LENS_FACING);
                if ( (camDir == CameraCharacteristics.LENS_FACING_BACK && config.activateBackCamera) ||
                     (camDir == CameraCharacteristics.LENS_FACING_FRONT && config.activateFrontCamera))
                {
                    useCamera2(new AndroidCamera2Output(this, cameraManager, cameraId, config.camPreviewSurfaceHolder), cameraId);
                }
            }
        }
        catch (CameraAccessException e)
        {
            throw new SensorException("Error while accessing cameras", e);
        }
    }
    else
    {
        for (int cameraId = 0; cameraId < android.hardware.Camera.getNumberOfCameras(); cameraId++)
        {
            android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();                    
            android.hardware.Camera.getCameraInfo(cameraId, info);
            if ( (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK && config.activateBackCamera) ||
                 (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT && config.activateFrontCamera))
            {
                useCamera(new AndroidCameraOutput(this, cameraId, config.camPreviewSurfaceHolder), cameraId);
            }
        }
    }
}
 
Example 11
Source File: AndroidCamera2AgentImpl.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
public AndroidCamera2DeviceInfo(CameraManager cameraManager,
                                String[] cameraIds, int numberOfCameras) {
    mCameraManager = cameraManager;
    mCameraIds = cameraIds;
    mNumberOfCameras = numberOfCameras;

    int firstBackId = NO_DEVICE;
    int firstFrontId = NO_DEVICE;
    for (int id = 0; id < cameraIds.length; ++id) {
        try {
            int lensDirection = cameraManager.getCameraCharacteristics(cameraIds[id])
                    .get(CameraCharacteristics.LENS_FACING);
            if (firstBackId == NO_DEVICE &&
                    lensDirection == CameraCharacteristics.LENS_FACING_BACK) {
                firstBackId = id;
            }
            if (firstFrontId == NO_DEVICE &&
                    lensDirection == CameraCharacteristics.LENS_FACING_FRONT) {
                firstFrontId = id;
            }
        } catch (CameraAccessException ex) {
            Log.w(TAG, "Couldn't get characteristics of camera '" + id + "'", ex);
        }
    }
    mFirstBackCameraId = firstBackId;
    mFirstFrontCameraId = firstFrontId;
}
 
Example 12
Source File: MainActivity.java    From AndroidPlayground with MIT License 5 votes vote down vote up
private void initCameraIds() throws CameraAccessException {
    for (String cameraId : mCameraManager.getCameraIdList()) {
        CameraCharacteristics characteristics =
                mCameraManager.getCameraCharacteristics(cameraId);

        Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
        if (facing != null) {
            if (facing == CameraCharacteristics.LENS_FACING_BACK) {
                mBackCameraId = cameraId;
            }
        }
    }
}
 
Example 13
Source File: CameraPluginActivity.java    From unity-android-native-camera with MIT License 5 votes vote down vote up
private String getCamera(CameraManager manager) {
    try {
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
            int cameraOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (cameraOrientation == CameraCharacteristics.LENS_FACING_BACK) {
                return cameraId;
            }
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 14
Source File: OBCameraManager.java    From GLEXP-Team-onebillion with Apache License 2.0 4 votes vote down vote up
private int getCameraCharacteristic(int cameraLoc)
{
    return cameraLoc == CAMERA_BACK ? CameraCharacteristics.LENS_FACING_BACK : CameraCharacteristics.LENS_FACING_FRONT;
}
 
Example 15
Source File: CameraCharacteristicsMinApiLevel21.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
private boolean isLensFacingBack(final String cameraId) throws FDroidDeviceException {
    final Integer lensFacing = getCameraCharacteristics(cameraId).get(CameraCharacteristics.LENS_FACING);

    return lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK;
}
 
Example 16
Source File: Camera2.java    From SimpleVideoEditor with Apache License 2.0 4 votes vote down vote up
void initCameraDevices() {
    try {
        String[] ids = mCameraManager.getCameraIdList();
        if (ids.length == 0) {
            // 这表示这台机器上没有任何摄像头设备
            mConfig.setCameraSupported(false);
            mCallback.onError(ICameraCallback.ERROR_CODE_NO_CAMERA_DEVICES);
            return;
        }
        for (String id : ids) {
            CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(id);
            Integer internal = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (internal == null) {
                mCallback.onError(ICameraCallback.ERROR_CODE_UNKNOWN);
                continue;
            }
            // 目前仅支持前置和后置摄像头,其他外接摄像头暂不支持
            if (internal == CameraCharacteristics.LENS_FACING_FRONT) {
                mDeviceInfo.addInfo(new Camera2DeviceInfo.Device(id, Constants.CAMERA_FACING_FRONT));
            } else if (internal == CameraCharacteristics.LENS_FACING_BACK) {
                mDeviceInfo.addInfo(new Camera2DeviceInfo.Device(id, Constants.CAMERA_FACING_BACK));
                // 目前仅考虑后置摄像头上的闪光灯
                if (characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)) {
                    // 在闪光灯可用的情况下,默认关闭闪光灯
                    mConfig.setCurrentFlashlightState(Constants.FLASH_LIGHT_OFF);
                }
            }
        }

        // 优先使用后置摄像头
        if (mDeviceInfo.getDeviceByFacing(Constants.CAMERA_FACING_BACK) != null) {
            mConfig.setCurrentFacing(Constants.CAMERA_FACING_BACK);
        } else if (mDeviceInfo.getDeviceByFacing(Constants.CAMERA_FACING_FRONT) != null) {
            mConfig.setCurrentFacing(Constants.CAMERA_FACING_FRONT);
        }

        mConfig.setCurrentCameraId(mDeviceInfo.getDeviceByFacing(mConfig.getCurrentFacing()).getCameraId());
    } catch (CameraAccessException e) {
        //e.printStackTrace();
        // 获取摄像头设备列表失败,一般都是没有权限
        mCallback.onError(ICameraCallback.ERROR_CODE_NO_PERMISSION);
    }
}
 
Example 17
Source File: Camera2Utils.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
	 * 指定した条件に合うカメラを探す
	 * @param manager
	 * @param preferedFace カメラの方向、対応するカメラがなければ異なるfaceのカメラが選択される
	 * @return
	 * @throws CameraAccessException
	 */
	public static CameraConst.CameraInfo findCamera(
		@NonNull final CameraManager manager,
		@CameraConst.FaceType final int preferedFace)
			throws CameraAccessException {

		if (DEBUG) Log.v(TAG, "findCamera:preferedFace=" + preferedFace);
		CameraConst.CameraInfo info = null;
		int targetFace;
		final String[] cameraIds = manager.getCameraIdList();
		if ((cameraIds != null) && (cameraIds.length > 0)) {
			final int face = (preferedFace == FACING_BACK
				? CameraCharacteristics.LENS_FACING_BACK
				: CameraCharacteristics.LENS_FACING_FRONT);
			boolean triedAllCameras = false;
			targetFace = face;
			String cameraId = null;
			int orientation = 0;
cameraLoop:
			for (; !triedAllCameras ;) {
				for (final String id: cameraIds) {
					final CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);
					if (characteristics.get(CameraCharacteristics.LENS_FACING) == targetFace) {
						final StreamConfigurationMap map = characteristics.get(
								CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
						cameraId = id;
						orientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
						break cameraLoop;
					}
				}
				if ((cameraId == null) && (targetFace == face)) {
					targetFace = (face == CameraCharacteristics.LENS_FACING_BACK
						? CameraCharacteristics.LENS_FACING_FRONT
						: CameraCharacteristics.LENS_FACING_BACK);
				} else {
					triedAllCameras = true;
				}
			}
			if (!TextUtils.isEmpty(cameraId)) {
				info = new CameraConst.CameraInfo(cameraId, face, orientation,
					CameraConst.DEFAULT_WIDTH, CameraConst.DEFAULT_HEIGHT);
			}
		}
		return info;
	}
 
Example 18
Source File: Camera2Utils.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
	 * 指定した条件に合うカメラを探す
	 * @param manager
	 * @param width
	 * @param height
	 * @param preferedFace
	 * @param degrees
	 * @return
	 * @throws CameraAccessException
	 */
	@Nullable
	public static CameraConst.CameraInfo findCamera(
		@NonNull final CameraManager manager,
		final int width, final int height,
		final int preferedFace, final int degrees)
			throws CameraAccessException {

		if (DEBUG) Log.v(TAG, String.format("findCamera:Size(%dx%d),preferedFace=%d,degrees=%d",
			width, height, preferedFace, degrees));

		String cameraId = null;
		Size previewSize = null;
		int targetFace = -1;
		int orientation = 0;
		final String[] cameraIds = manager.getCameraIdList();
		if ((cameraIds != null) && (cameraIds.length > 0)) {
			final int face = (preferedFace == FACING_BACK
				? CameraCharacteristics.LENS_FACING_BACK
				: CameraCharacteristics.LENS_FACING_FRONT);
			boolean triedAllCameras = false;
			targetFace = face;
cameraLoop:
			for (; !triedAllCameras ;) {
				for (final String id: cameraIds) {
					final CameraCharacteristics characteristics
						= manager.getCameraCharacteristics(id);
					if (characteristics.get(CameraCharacteristics.LENS_FACING) == targetFace) {
						final StreamConfigurationMap map = characteristics.get(
								CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
						previewSize = chooseOptimalSize(characteristics, map, width, height, degrees);
						orientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
						cameraId = id;
						break cameraLoop;
					}
				}
				if ((cameraId == null) && (targetFace == face)) {
					targetFace = (face == CameraCharacteristics.LENS_FACING_BACK
						? CameraCharacteristics.LENS_FACING_FRONT
						: CameraCharacteristics.LENS_FACING_BACK);
				} else {
					triedAllCameras = true;
				}
			}
		}
		if (!TextUtils.isEmpty(cameraId) && (previewSize != null)) {
			return new CameraConst.CameraInfo(cameraId, targetFace, orientation,
				previewSize.getWidth(), previewSize.getHeight());
		}
		if (DEBUG) Log.w(TAG, "findCamera: not found");
		return null;
	}
 
Example 19
Source File: CameraUtils.java    From SimpleSmsRemote with MIT License 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static MyCameraInfo CreateFromCameraCharacteristics(String cameraId,
                                                           CameraCharacteristics characteristics) {
    StreamConfigurationMap configMap =
            characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    Size[] outputSizes = configMap.getOutputSizes(ImageFormat.JPEG);
    List<int[]> outputResolutions = new ArrayList<>();
    for (Size outputSize : outputSizes) {
        outputResolutions.add(new int[]{outputSize.getWidth(), outputSize.getHeight()});
    }

    MyCameraInfo cameraInfo = new MyCameraInfo(cameraId, outputResolutions);

    // supported functionality depends on the supported hardware level
    switch (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)) {
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3:

        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
            cameraInfo.setAutofocusSupport(true);
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
            // only supports camera 1 api features
            break;
    }

    int[] ints = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES);

    if (characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE))
        cameraInfo.setFlashlightSupport(true);

    Integer lensFacing = characteristics.get(CameraCharacteristics.LENS_FACING);
    if (lensFacing != null) {
        if (lensFacing == CameraCharacteristics.LENS_FACING_BACK)
            cameraInfo.setLensFacing(LensFacing.BACK);
        else if (lensFacing == CameraCharacteristics.LENS_FACING_FRONT)
            cameraInfo.setLensFacing(LensFacing.FRONT);
        else if (lensFacing == CameraCharacteristics.LENS_FACING_EXTERNAL)
            cameraInfo.setLensFacing(LensFacing.EXTERNAL);
    }

    /*
    jpeg is always supported
    boolean isSupported = configMap.isOutputSupportedFor(0x100);
    */


    //TODO add more info

    return cameraInfo;
}
 
Example 20
Source File: VideoCaptureCamera2.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public boolean allocate(int width, int height, int frameRate) {
    Log.d(TAG, "allocate: requested (%d x %d) @%dfps", width, height, frameRate);
    ThreadUtils.assertOnUiThread();
    synchronized (mCameraStateLock) {
        if (mCameraState == CameraState.OPENING || mCameraState == CameraState.CONFIGURING) {
            Log.e(TAG, "allocate() invoked while Camera is busy opening/configuring.");
            return false;
        }
    }
    final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(mId);
    final StreamConfigurationMap streamMap =
            cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

    // Find closest supported size.
    final Size[] supportedSizes = streamMap.getOutputSizes(ImageFormat.YUV_420_888);
    final Size closestSupportedSize = findClosestSizeInArray(supportedSizes, width, height);
    if (closestSupportedSize == null) {
        Log.e(TAG, "No supported resolutions.");
        return false;
    }
    final List<Range<Integer>> fpsRanges = Arrays.asList(cameraCharacteristics.get(
            CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES));
    if (fpsRanges.isEmpty()) {
        Log.e(TAG, "No supported framerate ranges.");
        return false;
    }
    final List<FramerateRange> framerateRanges =
            new ArrayList<FramerateRange>(fpsRanges.size());
    // On some legacy implementations FPS values are multiplied by 1000. Multiply by 1000
    // everywhere for consistency. Set fpsUnitFactor to 1 if fps ranges are already multiplied
    // by 1000.
    final int fpsUnitFactor = fpsRanges.get(0).getUpper() > 1000 ? 1 : 1000;
    for (Range<Integer> range : fpsRanges) {
        framerateRanges.add(new FramerateRange(
                range.getLower() * fpsUnitFactor, range.getUpper() * fpsUnitFactor));
    }
    final FramerateRange aeFramerateRange =
            getClosestFramerateRange(framerateRanges, frameRate * 1000);
    mAeFpsRange = new Range<Integer>(
            aeFramerateRange.min / fpsUnitFactor, aeFramerateRange.max / fpsUnitFactor);
    Log.d(TAG, "allocate: matched (%d x %d) @[%d - %d]", closestSupportedSize.getWidth(),
            closestSupportedSize.getHeight(), mAeFpsRange.getLower(), mAeFpsRange.getUpper());

    // |mCaptureFormat| is also used to configure the ImageReader.
    mCaptureFormat = new VideoCaptureFormat(closestSupportedSize.getWidth(),
            closestSupportedSize.getHeight(), frameRate, ImageFormat.YUV_420_888);
    mCameraNativeOrientation =
            cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    // TODO(mcasas): The following line is correct for N5 with prerelease Build,
    // but NOT for N7 with a dev Build. Figure out which one to support.
    mInvertDeviceOrientationReadings =
            cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
            == CameraCharacteristics.LENS_FACING_BACK;
    return true;
}