Search in sources :

Example 71 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project platform_frameworks_base by android.

the class CameraTestUtils method configureCameraSession.

/**
     * Configure a new camera session with output surfaces and type.
     *
     * @param camera The CameraDevice to be configured.
     * @param outputSurfaces The surface list that used for camera output.
     * @param listener The callback CameraDevice will notify when capture results are available.
     */
public static CameraCaptureSession configureCameraSession(CameraDevice camera, List<Surface> outputSurfaces, boolean isHighSpeed, CameraCaptureSession.StateCallback listener, Handler handler) throws CameraAccessException {
    BlockingSessionCallback sessionListener = new BlockingSessionCallback(listener);
    if (isHighSpeed) {
        camera.createConstrainedHighSpeedCaptureSession(outputSurfaces, sessionListener, handler);
    } else {
        camera.createCaptureSession(outputSurfaces, sessionListener, handler);
    }
    CameraCaptureSession session = sessionListener.waitAndGetSession(SESSION_CONFIGURE_TIMEOUT_MS);
    assertFalse("Camera session should not be a reprocessable session", session.isReprocessable());
    String sessionType = isHighSpeed ? "High Speed" : "Normal";
    assertTrue("Capture session type must be " + sessionType, isHighSpeed == CameraConstrainedHighSpeedCaptureSession.class.isAssignableFrom(session.getClass()));
    return session;
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession)

Example 72 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project platform_frameworks_base by android.

the class CameraTestUtils method getSupportedSizeForClass.

/**
     * Get the available output sizes for the given class.
     *
     */
public static Size[] getSupportedSizeForClass(Class klass, String cameraId, CameraManager cameraManager) throws CameraAccessException {
    CameraCharacteristics properties = cameraManager.getCameraCharacteristics(cameraId);
    assertNotNull("Can't get camera characteristics!", properties);
    if (VERBOSE) {
        Log.v(TAG, "get camera characteristics for camera: " + cameraId);
    }
    StreamConfigurationMap configMap = properties.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    Size[] availableSizes = configMap.getOutputSizes(klass);
    assertArrayNotEmpty(availableSizes, "availableSizes should not be empty for class: " + klass);
    Size[] highResAvailableSizes = configMap.getHighResolutionOutputSizes(ImageFormat.PRIVATE);
    if (highResAvailableSizes != null && highResAvailableSizes.length > 0) {
        Size[] allSizes = new Size[availableSizes.length + highResAvailableSizes.length];
        System.arraycopy(availableSizes, 0, allSizes, 0, availableSizes.length);
        System.arraycopy(highResAvailableSizes, 0, allSizes, availableSizes.length, highResAvailableSizes.length);
        availableSizes = allSizes;
    }
    if (VERBOSE)
        Log.v(TAG, "Supported sizes are: " + Arrays.deepToString(availableSizes));
    return availableSizes;
}
Also used : Size(android.util.Size) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap)

Example 73 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project platform_frameworks_base by android.

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 74 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project platform_frameworks_base by android.

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 75 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project platform_frameworks_base by android.

the class CameraUtilsUncheckedThrowTest method testUncheckedThrow.

@SmallTest
public void testUncheckedThrow() {
    try {
        UncheckedThrow.throwAnyException(new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED));
        Assert.fail("unreachable");
        fakeNeverThrowsCameraAccess();
    } catch (CameraAccessException e) {
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

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