Search in sources :

Example 91 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class Camera2Focuser method cancelAutoFocus.

/**
     * Cancel ongoing auto focus, unlock the auto-focus if it was locked, and
     * resume to passive continuous auto focus.
     *
     * @throws CameraAccessException
     */
public synchronized void cancelAutoFocus() throws CameraAccessException {
    mSuccess = false;
    mLocked = false;
    // reset the AF regions:
    setAfRegions(null);
    // Create request builders, the af regions are automatically updated.
    mRepeatingBuilder = createRequestBuilder();
    CaptureRequest.Builder requestBuilder = createRequestBuilder();
    mAutoFocus.setPassiveAutoFocus(/*picture*/
    true, mRepeatingBuilder);
    mAutoFocus.unlockAutoFocus(mRepeatingBuilder, requestBuilder);
    CaptureCallback listener = createCaptureListener();
    mSession.setRepeatingRequest(mRepeatingBuilder.build(), listener, mHandler);
    mSession.capture(requestBuilder.build(), listener, mHandler);
}
Also used : CaptureCallback(android.hardware.camera2.CameraCaptureSession.CaptureCallback) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 92 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class Camera2Focuser method startAutoFocusFullActiveLocked.

private void startAutoFocusFullActiveLocked() throws CameraAccessException {
    // Create request builders, the af regions are automatically updated.
    mRepeatingBuilder = createRequestBuilder();
    CaptureRequest.Builder requestBuilder = createRequestBuilder();
    mAutoFocus.setActiveAutoFocus(mRepeatingBuilder, requestBuilder);
    if (mRepeatingBuilder.get(CaptureRequest.CONTROL_AF_TRIGGER) != CaptureRequest.CONTROL_AF_TRIGGER_IDLE) {
        throw new AssertionError("Wrong trigger set in repeating request");
    }
    if (requestBuilder.get(CaptureRequest.CONTROL_AF_TRIGGER) != CaptureRequest.CONTROL_AF_TRIGGER_START) {
        throw new AssertionError("Wrong trigger set in queued request");
    }
    mAutoFocus.resetState();
    CaptureCallback listener = createCaptureListener();
    mSession.setRepeatingRequest(mRepeatingBuilder.build(), listener, mHandler);
    mSession.capture(requestBuilder.build(), listener, mHandler);
}
Also used : CaptureCallback(android.hardware.camera2.CameraCaptureSession.CaptureCallback) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 93 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project AndroidDevelop by 7449.

the class Camera2 method chooseCameraIdByFacing.

/**
     * <p>Chooses a camera ID by the specified camera facing ({@link #mFacing}).</p>
     * <p>This rewrites {@link #mCameraId}, {@link #mCameraCharacteristics}, and optionally
     * {@link #mFacing}.</p>
     */
private void chooseCameraIdByFacing() {
    try {
        int internalFacing = INTERNAL_FACINGS.get(mFacing);
        final String[] ids = mCameraManager.getCameraIdList();
        for (String id : ids) {
            CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(id);
            Integer internal = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (internal == null) {
                throw new NullPointerException("Unexpected state: LENS_FACING null");
            }
            if (internal == internalFacing) {
                mCameraId = id;
                mCameraCharacteristics = characteristics;
                return;
            }
        }
        // Not found
        mCameraId = ids[0];
        mCameraCharacteristics = mCameraManager.getCameraCharacteristics(mCameraId);
        Integer internal = mCameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
        if (internal == null) {
            throw new NullPointerException("Unexpected state: LENS_FACING null");
        }
        for (int i = 0, count = INTERNAL_FACINGS.size(); i < count; i++) {
            if (INTERNAL_FACINGS.valueAt(i) == internal) {
                mFacing = INTERNAL_FACINGS.keyAt(i);
                return;
            }
        }
        // The operation can reach here when the only camera device is an external one.
        // We treat it as facing back.
        mFacing = Constants.FACING_BACK;
    } catch (CameraAccessException e) {
        throw new RuntimeException("Failed to get a list of camera devices", e);
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics)

Example 94 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class CameraManager method getCameraCharacteristics.

/**
     * <p>Query the capabilities of a camera device. These capabilities are
     * immutable for a given camera.</p>
     *
     * @param cameraId The id of the camera device to query
     * @return The properties of the given camera
     *
     * @throws IllegalArgumentException if the cameraId does not match any
     *         known camera device.
     * @throws CameraAccessException if the camera device has been disconnected.
     *
     * @see #getCameraIdList
     * @see android.app.admin.DevicePolicyManager#setCameraDisabled
     */
@NonNull
public CameraCharacteristics getCameraCharacteristics(@NonNull String cameraId) throws CameraAccessException {
    CameraCharacteristics characteristics = null;
    synchronized (mLock) {
        if (!getOrCreateDeviceIdListLocked().contains(cameraId)) {
            throw new IllegalArgumentException(String.format("Camera id %s does not match any" + " currently connected camera device", cameraId));
        }
        int id = Integer.parseInt(cameraId);
        /*
             * Get the camera characteristics from the camera service directly if it supports it,
             * otherwise get them from the legacy shim instead.
             */
        ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
        if (cameraService == null) {
            throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable");
        }
        try {
            if (!supportsCamera2ApiLocked(cameraId)) {
                // Legacy backwards compatibility path; build static info from the camera
                // parameters
                String parameters = cameraService.getLegacyParameters(id);
                CameraInfo info = cameraService.getCameraInfo(id);
                characteristics = LegacyMetadataMapper.createCharacteristics(parameters, info);
            } else {
                // Normal path: Get the camera characteristics directly from the camera service
                CameraMetadataNative info = cameraService.getCameraCharacteristics(id);
                characteristics = new CameraCharacteristics(info);
            }
        } catch (ServiceSpecificException e) {
            throwAsPublicException(e);
        } catch (RemoteException e) {
            // Camera service died - act as if the camera was disconnected
            throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable", e);
        }
    }
    return characteristics;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService) CameraInfo(android.hardware.CameraInfo) NonNull(android.annotation.NonNull)

Example 95 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class CameraManager method getOrCreateDeviceIdListLocked.

/**
     * Return or create the list of currently connected camera devices.
     *
     * <p>In case of errors connecting to the camera service, will return an empty list.</p>
     */
private ArrayList<String> getOrCreateDeviceIdListLocked() throws CameraAccessException {
    if (mDeviceIdList == null) {
        int numCameras = 0;
        ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
        ArrayList<String> deviceIdList = new ArrayList<>();
        // If no camera service, then no devices
        if (cameraService == null) {
            return deviceIdList;
        }
        try {
            numCameras = cameraService.getNumberOfCameras(CAMERA_TYPE_ALL);
        } catch (ServiceSpecificException e) {
            throwAsPublicException(e);
        } catch (RemoteException e) {
            // camera service just died - if no camera service, then no devices
            return deviceIdList;
        }
        for (int i = 0; i < numCameras; ++i) {
            // Non-removable cameras use integers starting at 0 for their
            // identifiers
            boolean isDeviceSupported = false;
            try {
                CameraMetadataNative info = cameraService.getCameraCharacteristics(i);
                if (!info.isEmpty()) {
                    isDeviceSupported = true;
                } else {
                    throw new AssertionError("Expected to get non-empty characteristics");
                }
            } catch (ServiceSpecificException e) {
                // propagate exception onward
                if (e.errorCode != ICameraService.ERROR_DISCONNECTED || e.errorCode != ICameraService.ERROR_ILLEGAL_ARGUMENT) {
                    throwAsPublicException(e);
                }
            } catch (RemoteException e) {
                // Camera service died - no devices to list
                deviceIdList.clear();
                return deviceIdList;
            }
            if (isDeviceSupported) {
                deviceIdList.add(String.valueOf(i));
            } else {
                Log.w(TAG, "Error querying camera device " + i + " for listing.");
            }
        }
        mDeviceIdList = deviceIdList;
    }
    return mDeviceIdList;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService)

Aggregations

ArrayList (java.util.ArrayList)50 Surface (android.view.Surface)42 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)40 CaptureRequest (android.hardware.camera2.CaptureRequest)35 CameraAccessException (android.hardware.camera2.CameraAccessException)34 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)24 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)21 RemoteException (android.os.RemoteException)15 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)14 CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)12 Size (android.util.Size)11 ICameraService (android.hardware.ICameraService)10 CaptureCallback (android.hardware.camera2.CameraCaptureSession.CaptureCallback)10 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)10 ServiceSpecificException (android.os.ServiceSpecificException)10 NonNull (android.annotation.NonNull)5 CameraInfo (android.hardware.CameraInfo)5 CameraManager (android.hardware.camera2.CameraManager)5 InputConfiguration (android.hardware.camera2.params.InputConfiguration)5 SubmitInfo (android.hardware.camera2.utils.SubmitInfo)5