Search in sources :

Example 1 with CameraDeviceImpl

use of android.hardware.camera2.impl.CameraDeviceImpl 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 2 with CameraDeviceImpl

use of android.hardware.camera2.impl.CameraDeviceImpl in project platform_frameworks_base by android.

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 3 with CameraDeviceImpl

use of android.hardware.camera2.impl.CameraDeviceImpl in project android_frameworks_base by crdroidandroid.

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 4 with CameraDeviceImpl

use of android.hardware.camera2.impl.CameraDeviceImpl in project robolectric by robolectric.

the class ShadowCameraManager method openCameraDeviceUserAsync.

/**
 * Enables {@link CameraManager#openCamera(String, StateCallback, Handler)} to open a
 * {@link CameraDevice}.
 *
 * <p>If the provided cameraId exists, this will always post
 * {@link CameraDevice.StateCallback#onOpened(CameraDevice) to the provided {@link Handler}.
 * Unlike on real Android, this will not check if the camera has been disabled by device policy
 * and does not attempt to connect to the camera service, so
 * {@link CameraDevice.StateCallback#onError(CameraDevice, int)} and
 * {@link CameraDevice.StateCallback#onDisconnected(CameraDevice)} will not be triggered by
 * {@link CameraManager#openCamera(String, StateCallback, Handler)}.
 */
@Implementation(minSdk = VERSION_CODES.LOLLIPOP, maxSdk = VERSION_CODES.N)
protected CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateCallback callback, Handler handler) throws CameraAccessException {
    CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
    CameraDeviceImpl deviceImpl = ReflectionHelpers.callConstructor(CameraDeviceImpl.class, ClassParameter.from(String.class, cameraId), ClassParameter.from(CameraDevice.StateCallback.class, callback), ClassParameter.from(Handler.class, handler), ClassParameter.from(CameraCharacteristics.class, characteristics));
    createdCameras.add(deviceImpl);
    updateCameraCallback(deviceImpl, callback, handler, null);
    handler.post(() -> callback.onOpened(deviceImpl));
    return deviceImpl;
}
Also used : CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) StateCallback(android.hardware.camera2.CameraDevice.StateCallback) Handler(android.os.Handler) CameraDeviceImpl(android.hardware.camera2.impl.CameraDeviceImpl) Implementation(org.robolectric.annotation.Implementation)

Example 5 with CameraDeviceImpl

use of android.hardware.camera2.impl.CameraDeviceImpl in project android_frameworks_base by DirtyUnicorns.

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)

Aggregations

CameraAccessException (android.hardware.camera2.CameraAccessException)5 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)5 Surface (android.view.Surface)5 ArrayList (java.util.ArrayList)5 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)3 CameraDeviceImpl (android.hardware.camera2.impl.CameraDeviceImpl)3 Implementation (org.robolectric.annotation.Implementation)3 Context (android.content.Context)2 StateCallback (android.hardware.camera2.CameraDevice.StateCallback)2 CameraDevice (android.hardware.camera2.CameraDevice)1 Handler (android.os.Handler)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 Executor (java.util.concurrent.Executor)1