Java Code Examples for android.hardware.camera2.CameraCaptureSession#StateCallback

The following examples show how to use android.hardware.camera2.CameraCaptureSession#StateCallback . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraDeviceImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void createReprocessableCaptureSession(InputConfiguration inputConfig,
        List<Surface> outputs, CameraCaptureSession.StateCallback callback, Handler handler)
        throws CameraAccessException {
    if (DEBUG) {
        Log.d(TAG, "createReprocessableCaptureSession");
    }

    if (inputConfig == null) {
        throw new IllegalArgumentException("inputConfig cannot be null when creating a " +
                "reprocessable capture session");
    }
    List<OutputConfiguration> outConfigurations = new ArrayList<>(outputs.size());
    for (Surface surface : outputs) {
        outConfigurations.add(new OutputConfiguration(surface));
    }
    createCaptureSessionInternal(inputConfig, outConfigurations, callback,
            checkAndWrapHandler(handler), /*operatingMode*/ICameraDeviceUser.NORMAL_MODE,
            /*sessionParams*/ null);
}
 
Example 2
Source File: CameraConstrainedHighSpeedCaptureSessionImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new CameraCaptureSession.
 *
 * <p>The camera device must already be in the {@code IDLE} state when this is invoked.
 * There must be no pending actions
 * (e.g. no pending captures, no repeating requests, no flush).</p>
 */
CameraConstrainedHighSpeedCaptureSessionImpl(int id,
        CameraCaptureSession.StateCallback callback, Executor stateExecutor,
        android.hardware.camera2.impl.CameraDeviceImpl deviceImpl,
        Executor deviceStateExecutor, boolean configureSuccess,
        CameraCharacteristics characteristics) {
    mCharacteristics = characteristics;
    CameraCaptureSession.StateCallback wrapperCallback = new WrapperCallback(callback);
    mSessionImpl = new CameraCaptureSessionImpl(id, /*input*/null, wrapperCallback,
            stateExecutor, deviceImpl, deviceStateExecutor, configureSuccess);
}
 
Example 3
Source File: CameraDeviceImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void createCaptureSession(List<Surface> outputs,
        CameraCaptureSession.StateCallback callback, Handler handler)
        throws CameraAccessException {
    List<OutputConfiguration> outConfigurations = new ArrayList<>(outputs.size());
    for (Surface surface : outputs) {
        outConfigurations.add(new OutputConfiguration(surface));
    }
    createCaptureSessionInternal(null, outConfigurations, callback,
            checkAndWrapHandler(handler), /*operatingMode*/ICameraDeviceUser.NORMAL_MODE,
            /*sessionParams*/ null);
}
 
Example 4
Source File: CameraDeviceImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void createCaptureSessionByOutputConfigurations(
        List<OutputConfiguration> outputConfigurations,
        CameraCaptureSession.StateCallback callback, Handler handler)
        throws CameraAccessException {
    if (DEBUG) {
        Log.d(TAG, "createCaptureSessionByOutputConfigurations");
    }

    // OutputConfiguration objects are immutable, but need to have our own array
    List<OutputConfiguration> currentOutputs = new ArrayList<>(outputConfigurations);

    createCaptureSessionInternal(null, currentOutputs, callback, checkAndWrapHandler(handler),
            /*operatingMode*/ICameraDeviceUser.NORMAL_MODE, /*sessionParams*/null);
}
 
Example 5
Source File: CameraCaptureSessionImpl.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new CameraCaptureSession.
 *
 * <p>The camera device must already be in the {@code IDLE} state when this is invoked.
 * There must be no pending actions
 * (e.g. no pending captures, no repeating requests, no flush).</p>
 */
CameraCaptureSessionImpl(int id, Surface input,
        CameraCaptureSession.StateCallback callback, Executor stateExecutor,
        android.hardware.camera2.impl.CameraDeviceImpl deviceImpl,
        Executor deviceStateExecutor, boolean configureSuccess) {
    if (callback == null) {
        throw new IllegalArgumentException("callback must not be null");
    }

    mId = id;
    mIdString = String.format("Session %d: ", mId);

    mInput = input;
    mStateExecutor = checkNotNull(stateExecutor, "stateExecutor must not be null");
    mStateCallback = createUserStateCallbackProxy(mStateExecutor, callback);

    mDeviceExecutor = checkNotNull(deviceStateExecutor,
            "deviceStateExecutor must not be null");
    mDeviceImpl = checkNotNull(deviceImpl, "deviceImpl must not be null");

    /*
     * Use the same handler as the device's StateCallback for all the internal coming events
     *
     * This ensures total ordering between CameraDevice.StateCallback and
     * CameraDeviceImpl.CaptureCallback events.
     */
    mSequenceDrainer = new TaskDrainer<>(mDeviceExecutor, new SequenceDrainListener(),
            /*name*/"seq");
    mIdleDrainer = new TaskSingleDrainer(mDeviceExecutor, new IdleDrainListener(),
            /*name*/"idle");
    mAbortDrainer = new TaskSingleDrainer(mDeviceExecutor, new AbortDrainListener(),
            /*name*/"abort");

    // CameraDevice should call configureOutputs and have it finish before constructing us

    if (configureSuccess) {
        mStateCallback.onConfigured(this);
        if (DEBUG) Log.v(TAG, mIdString + "Created session successfully");
        mConfigureSuccess = true;
    } else {
        mStateCallback.onConfigureFailed(this);
        mClosed = true; // do not fire any other callbacks, do not allow any other work
        Log.e(TAG, mIdString + "Failed to create capture session; configuration failed");
        mConfigureSuccess = false;
    }
}
 
Example 6
Source File: CallbackProxies.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public SessionStateCallbackProxy(Executor executor,
        CameraCaptureSession.StateCallback callback) {
    mExecutor = checkNotNull(executor, "executor must not be null");
    mCallback = checkNotNull(callback, "callback must not be null");
}
 
Example 7
Source File: CameraDeviceImpl.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void createCaptureSessionInternal(InputConfiguration inputConfig,
        List<OutputConfiguration> outputConfigurations,
        CameraCaptureSession.StateCallback callback, Executor executor,
        int operatingMode, CaptureRequest sessionParams) throws CameraAccessException {
    synchronized(mInterfaceLock) {
        if (DEBUG) {
            Log.d(TAG, "createCaptureSessionInternal");
        }

        checkIfCameraClosedOrInError();

        boolean isConstrainedHighSpeed =
                (operatingMode == ICameraDeviceUser.CONSTRAINED_HIGH_SPEED_MODE);
        if (isConstrainedHighSpeed && inputConfig != null) {
            throw new IllegalArgumentException("Constrained high speed session doesn't support"
                    + " input configuration yet.");
        }

        // Notify current session that it's going away, before starting camera operations
        // 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,
                    operatingMode, sessionParams);
            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);
            }
        }

        // Fire onConfigured if configureOutputs succeeded, fire onConfigureFailed otherwise.
        CameraCaptureSessionCore newSession = null;
        if (isConstrainedHighSpeed) {
            ArrayList<Surface> surfaces = new ArrayList<>(outputConfigurations.size());
            for (OutputConfiguration outConfig : outputConfigurations) {
                surfaces.add(outConfig.getSurface());
            }
            StreamConfigurationMap config =
                getCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            SurfaceUtils.checkConstrainedHighSpeedSurfaces(surfaces, /*fpsRange*/null, config);

            newSession = new CameraConstrainedHighSpeedCaptureSessionImpl(mNextSessionId++,
                    callback, executor, this, mDeviceExecutor, configureSuccess,
                    mCharacteristics);
        } else {
            newSession = new CameraCaptureSessionImpl(mNextSessionId++, input,
                    callback, executor, this, mDeviceExecutor, configureSuccess);
        }

        // TODO: wait until current session closes, then create the new session
        mCurrentSession = newSession;

        if (pendingException != null) {
            throw pendingException;
        }

        mSessionStateCallback = mCurrentSession.getDeviceStateCallback();
    }
}
 
Example 8
Source File: SessionConfiguration.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new {@link SessionConfiguration}.
 *
 * @param sessionType The session type.
 * @param outputs A list of output configurations for the capture session.
 * @param executor The executor which should be used to invoke the callback. In general it is
 *                 recommended that camera operations are not done on the main (UI) thread.
 * @param cb A state callback interface implementation.
 *
 * @see #SESSION_REGULAR
 * @see #SESSION_HIGH_SPEED
 * @see CameraDevice#createCaptureSession(List, CameraCaptureSession.StateCallback, Handler)
 * @see CameraDevice#createCaptureSessionByOutputConfigurations
 * @see CameraDevice#createReprocessableCaptureSession
 * @see CameraDevice#createConstrainedHighSpeedCaptureSession
 */
public SessionConfiguration(@SessionMode int sessionType,
        @NonNull List<OutputConfiguration> outputs,
        @NonNull @CallbackExecutor Executor executor,
        @NonNull CameraCaptureSession.StateCallback cb) {
    mSessionType = sessionType;
    mOutputConfigurations = Collections.unmodifiableList(new ArrayList<>(outputs));
    mStateCallback = cb;
    mExecutor = executor;
}
 
Example 9
Source File: BlockingSessionCallback.java    From Camera2 with Apache License 2.0 3 votes vote down vote up
/**
 * Create a blocking session listener; forward original listener invocations
 * into {@code listener}.
 *
 * @param listener a non-{@code null} listener to forward invocations into
 *
 * @throws NullPointerException if {@code listener} was {@code null}
 */
public BlockingSessionCallback(CameraCaptureSession.StateCallback listener) {
    if (listener == null) {
        throw new NullPointerException("listener must not be null");
    }
    mProxy = listener;
}
 
Example 10
Source File: SessionConfiguration.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve the {@link CameraCaptureSession.StateCallback} for the capture session.
 *
 * @return A state callback interface implementation.
 */
public CameraCaptureSession.StateCallback getStateCallback() {
    return mStateCallback;
}