Search in sources :

Example 41 with CameraAccessException

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

the class CameraDeviceImpl method createCaptureSessionInternal.

private void createCaptureSessionInternal(InputConfiguration inputConfig, List<OutputConfiguration> outputConfigurations, CameraCaptureSession.StateCallback callback, Handler handler, boolean isConstrainedHighSpeed) throws CameraAccessException {
    synchronized (mInterfaceLock) {
        if (DEBUG) {
            Log.d(TAG, "createCaptureSessionInternal");
        }
        checkIfCameraClosedOrInError();
        if (isConstrainedHighSpeed && inputConfig != null) {
            throw new IllegalArgumentException("Constrained high speed session doesn't support" + " input configuration yet.");
        }
        // After this call completes, the session is not allowed to call into CameraDeviceImpl
        if (mCurrentSession != null) {
            mCurrentSession.replaceSessionClose();
        }
        // TODO: dont block for this
        boolean configureSuccess = true;
        CameraAccessException pendingException = null;
        Surface input = null;
        try {
            // configure streams and then block until IDLE
            configureSuccess = configureStreamsChecked(inputConfig, outputConfigurations, isConstrainedHighSpeed);
            if (configureSuccess == true && inputConfig != null) {
                input = mRemoteDevice.getInputSurface();
            }
        } catch (CameraAccessException e) {
            configureSuccess = false;
            pendingException = e;
            input = null;
            if (DEBUG) {
                Log.v(TAG, "createCaptureSession - failed with exception ", e);
            }
        }
        List<Surface> outSurfaces = new ArrayList<>(outputConfigurations.size());
        for (OutputConfiguration config : outputConfigurations) {
            outSurfaces.add(config.getSurface());
        }
        // Fire onConfigured if configureOutputs succeeded, fire onConfigureFailed otherwise.
        CameraCaptureSessionCore newSession = null;
        if (isConstrainedHighSpeed) {
            newSession = new CameraConstrainedHighSpeedCaptureSessionImpl(mNextSessionId++, outSurfaces, callback, handler, this, mDeviceHandler, configureSuccess, mCharacteristics);
        } else {
            newSession = new CameraCaptureSessionImpl(mNextSessionId++, input, outSurfaces, callback, handler, this, mDeviceHandler, configureSuccess);
        }
        // TODO: wait until current session closes, then create the new session
        mCurrentSession = newSession;
        if (pendingException != null) {
            throw pendingException;
        }
        mSessionStateCallback = mCurrentSession.getDeviceStateCallback();
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) OutputConfiguration(android.hardware.camera2.params.OutputConfiguration) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Example 42 with CameraAccessException

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

the class CameraCaptureSessionImpl method captureBurst.

@Override
public synchronized int captureBurst(List<CaptureRequest> requests, CaptureCallback callback, Handler handler) throws CameraAccessException {
    if (requests == null) {
        throw new IllegalArgumentException("Requests must not be null");
    } else if (requests.isEmpty()) {
        throw new IllegalArgumentException("Requests must have at least one element");
    }
    for (CaptureRequest request : requests) {
        if (request.isReprocess()) {
            if (!isReprocessable()) {
                throw new IllegalArgumentException("This capture session cannot handle " + "reprocess requests");
            } else if (request.getReprocessableSessionId() != mId) {
                throw new IllegalArgumentException("Capture request was created for another " + "session");
            }
        }
    }
    checkNotClosed();
    handler = checkHandler(handler, callback);
    if (DEBUG) {
        CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
        Log.v(TAG, mIdString + "captureBurst - requests " + Arrays.toString(requestArray) + ", callback " + callback + " handler " + handler);
    }
    return addPendingSequence(mDeviceImpl.captureBurst(requests, createCaptureCallbackProxy(handler, callback), mDeviceHandler));
}
Also used : CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 43 with CameraAccessException

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

the class CameraDeviceImpl method finishDeferredConfig.

public void finishDeferredConfig(List<OutputConfiguration> deferredConfigs) throws CameraAccessException {
    if (deferredConfigs == null || deferredConfigs.size() == 0) {
        throw new IllegalArgumentException("deferred config is null or empty");
    }
    synchronized (mInterfaceLock) {
        for (OutputConfiguration config : deferredConfigs) {
            int streamId = -1;
            for (int i = 0; i < mConfiguredOutputs.size(); i++) {
                // createReprocessableCaptureSessionByConfigurations() do a copy of the configs.
                if (config.equals(mConfiguredOutputs.valueAt(i))) {
                    streamId = mConfiguredOutputs.keyAt(i);
                    break;
                }
            }
            if (streamId == -1) {
                throw new IllegalArgumentException("Deferred config is not part of this " + "session");
            }
            if (config.getSurface() == null) {
                throw new IllegalArgumentException("The deferred config for stream " + streamId + " must have a non-null surface");
            }
            mRemoteDevice.setDeferredConfiguration(streamId, config);
        }
    }
}
Also used : OutputConfiguration(android.hardware.camera2.params.OutputConfiguration)

Example 44 with CameraAccessException

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

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

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

the class Camera2 method startCaptureSession.

/**
     * <p>Starts a capture session for camera preview.</p>
     * <p>This rewrites {@link #mPreviewRequestBuilder}.</p>
     * <p>The result will be continuously processed in {@link #mSessionCallback}.</p>
     */
void startCaptureSession() {
    if (!isCameraOpened() || !mPreview.isReady() || mImageReader == null) {
        return;
    }
    Size previewSize = chooseOptimalSize();
    mPreview.setBufferSize(previewSize.getWidth(), previewSize.getHeight());
    Surface surface = mPreview.getSurface();
    try {
        mPreviewRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mPreviewRequestBuilder.addTarget(surface);
        mCamera.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()), mSessionCallback, null);
    } catch (CameraAccessException e) {
        throw new RuntimeException("Failed to start camera session");
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) Surface(android.view.Surface)

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