Search in sources :

Example 6 with CameraDeviceImpl

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

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

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

the class ShadowCameraManager method openCameraDeviceUserAsync.

@Implementation(minSdk = Build.VERSION_CODES.S)
protected CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateCallback callback, Executor executor, int unusedClientUid, int unusedOomScoreOffset) {
    CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
    Context context = RuntimeEnvironment.getApplication();
    CameraDeviceImpl deviceImpl = ReflectionHelpers.callConstructor(CameraDeviceImpl.class, ClassParameter.from(String.class, cameraId), ClassParameter.from(CameraDevice.StateCallback.class, callback), ClassParameter.from(Executor.class, executor), ClassParameter.from(CameraCharacteristics.class, characteristics), ClassParameter.from(Map.class, Collections.emptyMap()), ClassParameter.from(int.class, context.getApplicationInfo().targetSdkVersion), ClassParameter.from(Context.class, context));
    createdCameras.add(deviceImpl);
    updateCameraCallback(deviceImpl, callback, null, executor);
    executor.execute(() -> callback.onOpened(deviceImpl));
    return deviceImpl;
}
Also used : Context(android.content.Context) Executor(java.util.concurrent.Executor) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) StateCallback(android.hardware.camera2.CameraDevice.StateCallback) CameraDeviceImpl(android.hardware.camera2.impl.CameraDeviceImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) Implementation(org.robolectric.annotation.Implementation)

Example 8 with CameraDeviceImpl

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

the class ShadowCameraManager method openCameraDeviceUserAsync.

@Implementation(minSdk = VERSION_CODES.N_MR1, maxSdk = VERSION_CODES.O_MR1)
protected CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateCallback callback, Handler handler, final int uid) throws CameraAccessException {
    CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
    Context context = reflector(ReflectorCameraManager.class, realObject).getContext();
    CameraDeviceImpl deviceImpl;
    if (Build.VERSION.SDK_INT == VERSION_CODES.N_MR1) {
        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));
    } else {
        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), ClassParameter.from(int.class, context.getApplicationInfo().targetSdkVersion));
    }
    createdCameras.add(deviceImpl);
    updateCameraCallback(deviceImpl, callback, handler, null);
    handler.post(() -> callback.onOpened(deviceImpl));
    return deviceImpl;
}
Also used : Context(android.content.Context) CameraDevice(android.hardware.camera2.CameraDevice) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CameraDeviceImpl(android.hardware.camera2.impl.CameraDeviceImpl) Implementation(org.robolectric.annotation.Implementation)

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