Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e04e910 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

CameraDevice: Add hidden createCustomCaptureSession

This exposes a direct route to selecting the operating mode, instead
of only allowing normal and high-speed modes.

Test: Compiles
Bug: 34853980
Change-Id: Ib4f833399834c9bacb9de666560e909109aa5af9
parent ce29b882
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -718,6 +718,40 @@ public abstract class CameraDevice implements AutoCloseable {
            @Nullable Handler handler)
            throws CameraAccessException;

    /**
     * Create a new camera capture session with a custom operating mode.
     *
     * @param inputConfig The configuration for the input {@link Surface} if a reprocessing session
     *                is desired, or {@code null} otherwise.
     * @param outputs The new set of {@link OutputConfiguration OutputConfigurations} that should be
     *                made available as targets for captured image data.
     * @param operatingMode The custom operating mode to use; a nonnegative value.
     * @param callback The callback to notify about the status of the new capture session.
     * @param handler The handler on which the callback should be invoked, or {@code null} to use
     *                the current thread's {@link android.os.Looper looper}.
     *
     * @throws IllegalArgumentException if the input configuration is null or not supported, the set
     *                                  of output Surfaces do not meet the requirements, the
     *                                  callback is null, or the handler is null but the current
     *                                  thread has no looper.
     * @throws CameraAccessException if the camera device is no longer connected or has
     *                               encountered a fatal error
     * @throws IllegalStateException if the camera device has been closed
     *
     * @see #createCaptureSession
     * @see #createReprocessableCaptureSession
     * @see CameraCaptureSession
     * @see OutputConfiguration
     * @hide
     */
    public abstract void createCustomCaptureSession(
            InputConfiguration inputConfig,
            @NonNull List<OutputConfiguration> outputs,
            int operatingMode,
            @NonNull CameraCaptureSession.StateCallback callback,
            @Nullable Handler handler)
            throws CameraAccessException;

    /**
     * <p>Create a {@link CaptureRequest.Builder} for new capture requests,
     * initialized with template for a target use case. The settings are chosen
+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.ICameraDeviceUser;
import android.hardware.camera2.dispatch.ArgumentReplacingDispatcher;
import android.hardware.camera2.dispatch.BroadcastDispatcher;
import android.hardware.camera2.dispatch.DuckTypingDispatcher;
@@ -742,7 +743,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
                    try {
                        // begin transition to unconfigured
                        mDeviceImpl.configureStreamsChecked(/*inputConfig*/null, /*outputs*/null,
                                /*isConstrainedHighSpeed*/false);
                                /*operatingMode*/ ICameraDeviceUser.NORMAL_MODE);
                    } catch (CameraAccessException e) {
                        // OK: do not throw checked exceptions.
                        Log.e(TAG, mIdString + "Exception while unconfiguring outputs: ", e);
+27 −11
Original line number Diff line number Diff line
@@ -356,7 +356,7 @@ public class CameraDeviceImpl extends CameraDevice
            outputConfigs.add(new OutputConfiguration(s));
        }
        configureStreamsChecked(/*inputConfig*/null, outputConfigs,
                /*isConstrainedHighSpeed*/false);
                /*operatingMode*/ICameraDeviceUser.NORMAL_MODE);

    }

@@ -374,13 +374,14 @@ public class CameraDeviceImpl extends CameraDevice
     *
     * @param inputConfig input configuration or {@code null} for no input
     * @param outputs a list of one or more surfaces, or {@code null} to unconfigure
     * @param isConstrainedHighSpeed If the streams configuration is for constrained high speed output.
     * @param operatingMode If the stream configuration is for a normal session,
     *     a constrained high speed session, or something else.
     * @return whether or not the configuration was successful
     *
     * @throws CameraAccessException if there were any unexpected problems during configuration
     */
    public boolean configureStreamsChecked(InputConfiguration inputConfig,
            List<OutputConfiguration> outputs, boolean isConstrainedHighSpeed)
            List<OutputConfiguration> outputs, int operatingMode)
                    throws CameraAccessException {
        // Treat a null input the same an empty list
        if (outputs == null) {
@@ -456,7 +457,7 @@ public class CameraDeviceImpl extends CameraDevice
                    }
                }

                mRemoteDevice.endConfigure(isConstrainedHighSpeed);
                mRemoteDevice.endConfigure(operatingMode);

                success = true;
            } catch (IllegalArgumentException e) {
@@ -492,7 +493,7 @@ public class CameraDeviceImpl extends CameraDevice
            outConfigurations.add(new OutputConfiguration(surface));
        }
        createCaptureSessionInternal(null, outConfigurations, callback, handler,
                /*isConstrainedHighSpeed*/false);
                /*operatingMode*/ICameraDeviceUser.NORMAL_MODE);
    }

    @Override
@@ -508,7 +509,7 @@ public class CameraDeviceImpl extends CameraDevice
        List<OutputConfiguration> currentOutputs = new ArrayList<>(outputConfigurations);

        createCaptureSessionInternal(null, currentOutputs, callback, handler,
                /*isConstrainedHighSpeed*/false);
                /*operatingMode*/ICameraDeviceUser.NORMAL_MODE);
    }

    @Override
@@ -528,7 +529,7 @@ public class CameraDeviceImpl extends CameraDevice
            outConfigurations.add(new OutputConfiguration(surface));
        }
        createCaptureSessionInternal(inputConfig, outConfigurations, callback, handler,
                /*isConstrainedHighSpeed*/false);
                /*operatingMode*/ICameraDeviceUser.NORMAL_MODE);
    }

    @Override
@@ -556,7 +557,7 @@ public class CameraDeviceImpl extends CameraDevice
            currentOutputs.add(new OutputConfiguration(output));
        }
        createCaptureSessionInternal(inputConfig, currentOutputs,
                callback, handler, /*isConstrainedHighSpeed*/false);
                callback, handler, /*operatingMode*/ICameraDeviceUser.NORMAL_MODE);
    }

    @Override
@@ -576,13 +577,26 @@ public class CameraDeviceImpl extends CameraDevice
            outConfigurations.add(new OutputConfiguration(surface));
        }
        createCaptureSessionInternal(null, outConfigurations, callback, handler,
                /*isConstrainedHighSpeed*/true);
                /*operatingMode*/ICameraDeviceUser.CONSTRAINED_HIGH_SPEED_MODE);
    }

    @Override
    public void createCustomCaptureSession(InputConfiguration inputConfig,
            List<OutputConfiguration> outputs,
            int operatingMode,
            android.hardware.camera2.CameraCaptureSession.StateCallback callback,
            Handler handler) throws CameraAccessException {
        List<OutputConfiguration> currentOutputs = new ArrayList<OutputConfiguration>();
        for (OutputConfiguration output : outputs) {
            currentOutputs.add(new OutputConfiguration(output));
        }
        createCaptureSessionInternal(inputConfig, currentOutputs, callback, handler, operatingMode);
    }

    private void createCaptureSessionInternal(InputConfiguration inputConfig,
            List<OutputConfiguration> outputConfigurations,
            CameraCaptureSession.StateCallback callback, Handler handler,
            boolean isConstrainedHighSpeed) throws CameraAccessException {
            int operatingMode) throws CameraAccessException {
        synchronized(mInterfaceLock) {
            if (DEBUG) {
                Log.d(TAG, "createCaptureSessionInternal");
@@ -590,6 +604,8 @@ public class CameraDeviceImpl extends CameraDevice

            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.");
@@ -608,7 +624,7 @@ public class CameraDeviceImpl extends CameraDevice
            try {
                // configure streams and then block until IDLE
                configureSuccess = configureStreamsChecked(inputConfig, outputConfigurations,
                        isConstrainedHighSpeed);
                        operatingMode);
                if (configureSuccess == true && inputConfig != null) {
                    input = mRemoteDevice.getInputSurface();
                }
+2 −2
Original line number Diff line number Diff line
@@ -106,9 +106,9 @@ public class ICameraDeviceUserWrapper {
        }
    }

    public void endConfigure(boolean isConstrainedHighSpeed) throws CameraAccessException {
    public void endConfigure(int operatingMode) throws CameraAccessException {
        try {
            mRemoteDevice.endConfigure(isConstrainedHighSpeed);
            mRemoteDevice.endConfigure(operatingMode);
        } catch (Throwable t) {
            CameraManager.throwAsPublicException(t);
            throw new UnsupportedOperationException("Unexpected exception", t);
+7 −1
Original line number Diff line number Diff line
@@ -497,7 +497,7 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
    }

    @Override
    public void endConfigure(boolean isConstrainedHighSpeed) {
    public void endConfigure(int operatingMode) {
        if (DEBUG) {
            Log.d(TAG, "endConfigure called.");
        }
@@ -507,6 +507,12 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
            throw new ServiceSpecificException(ICameraService.ERROR_DISCONNECTED, err);
        }

        if (operatingMode != ICameraDeviceUser.NORMAL_MODE) {
            String err = "LEGACY devices do not support this operating mode";
            Log.e(TAG, err);
            throw new ServiceSpecificException(ICameraService.ERROR_ILLEGAL_ARGUMENT, err);
        }

        SparseArray<Surface> surfaces = null;
        synchronized(mConfigureLock) {
            if (!mConfiguring) {