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

Commit 5609c1cf authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Android Git Automerger
Browse files

am 90952cfd: Merge topic \'camera2-remove-hidden\' into lmp-dev

* commit '90952cfdb43e769da1a177e294973e3aacca12eb':
  Camera2: Fix session shutdown race, frequent warning log
  Camera2: Remove hidden parts of public CameraDevice
  Camera2: Fix null-listener capture for CameraCaptureSession
parents d696634f 47082b9c
Loading
Loading
Loading
Loading
+0 −207
Original line number Diff line number Diff line
@@ -129,15 +129,6 @@ public abstract class CameraDevice implements AutoCloseable {
     */
    public abstract String getId();

    /**
     * <p>Set up a new output set of Surfaces for the camera device.</p>
     *
     * @deprecated Use {@link #createCaptureSession} instead
     * @hide
     */
    @Deprecated
    public abstract void configureOutputs(List<Surface> outputs) throws CameraAccessException;

    /**
     * <p>Create a new camera capture session by providing the target output set of Surfaces to the
     * camera device.</p>
@@ -275,68 +266,6 @@ public abstract class CameraDevice implements AutoCloseable {
    public abstract CaptureRequest.Builder createCaptureRequest(int templateType)
            throws CameraAccessException;

    /**
     * <p>Submit a request for an image to be captured by this CameraDevice.</p>
     *
     * @deprecated Use {@link CameraCaptureSession#capture} instead
     * @hide
     */
    @Deprecated
    public abstract int capture(CaptureRequest request, CaptureListener listener, Handler handler)
            throws CameraAccessException;

    /**
     * Submit a list of requests to be captured in sequence as a burst.
     *
     * @deprecated Use {@link CameraCaptureSession#captureBurst} instead
     * @hide
     */
    @Deprecated
    public abstract int captureBurst(List<CaptureRequest> requests, CaptureListener listener,
            Handler handler) throws CameraAccessException;

    /**
     * Request endlessly repeating capture of images by this CameraDevice.
     *
     * @deprecated Use {@link CameraCaptureSession#setRepeatingRequest} instead
     * @hide
     */
    @Deprecated
    public abstract int setRepeatingRequest(CaptureRequest request, CaptureListener listener,
            Handler handler) throws CameraAccessException;

    /**
     * <p>Request endlessly repeating capture of a sequence of images by this
     * CameraDevice.</p>
     *
     * @deprecated Use {@link CameraCaptureSession#setRepeatingBurst} instead
     * @hide
     */
    @Deprecated
    public abstract int setRepeatingBurst(List<CaptureRequest> requests, CaptureListener listener,
            Handler handler) throws CameraAccessException;

    /**
     * <p>Cancel any ongoing repeating capture set by either
     * {@link #setRepeatingRequest setRepeatingRequest} or
     * {@link #setRepeatingBurst}.
     *
     * @deprecated Use {@link CameraCaptureSession#stopRepeating} instead
     * @hide
     */
    @Deprecated
    public abstract void stopRepeating() throws CameraAccessException;

    /**
     * Flush all captures currently pending and in-progress as fast as
     * possible.
     *
     * @deprecated Use {@link CameraCaptureSession#abortCaptures} instead
     * @hide
     */
    @Deprecated
    public abstract void flush() throws CameraAccessException;

    /**
     * Close the connection to this camera device as quickly as possible.
     *
@@ -355,96 +284,6 @@ public abstract class CameraDevice implements AutoCloseable {
    @Override
    public abstract void close();

    /**
     * <p>A listener for tracking the progress of a {@link CaptureRequest}
     * submitted to the camera device.</p>
     *
     * @deprecated Use {@link CameraCaptureSession.CaptureListener} instead
     * @hide
     */
    @Deprecated
    public static abstract class CaptureListener {

        /**
         * This constant is used to indicate that no images were captured for
         * the request.
         *
         * @hide
         */
        public static final int NO_FRAMES_CAPTURED = -1;

        /**
         * This method is called when the camera device has started capturing
         * the output image for the request, at the beginning of image exposure.
         *
         * @see android.media.MediaActionSound
         */
        public void onCaptureStarted(CameraDevice camera,
                CaptureRequest request, long timestamp) {
            // default empty implementation
        }

        /**
         * This method is called when some results from an image capture are
         * available.
         *
         * @hide
         */
        public void onCapturePartial(CameraDevice camera,
                CaptureRequest request, CaptureResult result) {
            // default empty implementation
        }

        /**
         * This method is called when an image capture makes partial forward progress; some
         * (but not all) results from an image capture are available.
         *
         */
        public void onCaptureProgressed(CameraDevice camera,
                CaptureRequest request, CaptureResult partialResult) {
            // default empty implementation
        }

        /**
         * This method is called when an image capture has fully completed and all the
         * result metadata is available.
         */
        public void onCaptureCompleted(CameraDevice camera,
                CaptureRequest request, TotalCaptureResult result) {
            // default empty implementation
        }

        /**
         * This method is called instead of {@link #onCaptureCompleted} when the
         * camera device failed to produce a {@link CaptureResult} for the
         * request.
         */
        public void onCaptureFailed(CameraDevice camera,
                CaptureRequest request, CaptureFailure failure) {
            // default empty implementation
        }

        /**
         * This method is called independently of the others in CaptureListener,
         * when a capture sequence finishes and all {@link CaptureResult}
         * or {@link CaptureFailure} for it have been returned via this listener.
         */
        public void onCaptureSequenceCompleted(CameraDevice camera,
                int sequenceId, long frameNumber) {
            // default empty implementation
        }

        /**
         * This method is called independently of the others in CaptureListener,
         * when a capture sequence aborts before any {@link CaptureResult}
         * or {@link CaptureFailure} for it have been returned via this listener.
         */
        public void onCaptureSequenceAborted(CameraDevice camera,
                int sequenceId) {
            // default empty implementation
        }
    }

    /**
     * A listener for notifications about the state of a camera
     * device.
@@ -541,40 +380,6 @@ public abstract class CameraDevice implements AutoCloseable {
         */
        public abstract void onOpened(CameraDevice camera); // Must implement

        /**
         * The method called when a camera device has no outputs configured.
         *
         * @deprecated Use {@link #onOpened} instead.
         * @hide
         */
        @Deprecated
        public void onUnconfigured(CameraDevice camera) {
            // Default empty implementation
        }

        /**
         * The method called when a camera device begins processing
         * {@link CaptureRequest capture requests}.
         *
         * @deprecated Use {@link CameraCaptureSession.StateListener#onActive} instead.
         * @hide
         */
        @Deprecated
        public void onActive(CameraDevice camera) {
            // Default empty implementation
        }

        /**
         * The method called when a camera device is busy.
         *
         * @deprecated Use {@link CameraCaptureSession.StateListener#onConfigured} instead.
         * @hide
         */
        @Deprecated
        public void onBusy(CameraDevice camera) {
            // Default empty implementation
        }

        /**
         * The method called when a camera device has been closed with
         * {@link CameraDevice#close}.
@@ -590,18 +395,6 @@ public abstract class CameraDevice implements AutoCloseable {
            // Default empty implementation
        }

        /**
         * The method called when a camera device has finished processing all
         * submitted capture requests and has reached an idle state.
         *
         * @deprecated Use {@link CameraCaptureSession.StateListener#onReady} instead.
         * @hide
         */
        @Deprecated
        public void onIdle(CameraDevice camera) {
            // Default empty implementation
        }

        /**
         * The method called when a camera device is no longer available for
         * use.
+43 −31
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
         * Use the same handler as the device's StateListener for all the internal coming events
         *
         * This ensures total ordering between CameraDevice.StateListener and
         * CameraDevice.CaptureListener events.
         * CameraDeviceImpl.CaptureListener events.
         */
        mSequenceDrainer = new TaskDrainer<>(mDeviceHandler, new SequenceDrainListener(),
                /*name*/"seq");
@@ -141,7 +141,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
        checkNotClosed();
        checkLegalToCapture();

        handler = checkHandler(handler);
        handler = checkHandler(handler, listener);

        if (VERBOSE) {
            Log.v(TAG, "capture - request " + request + ", listener " + listener + " handler" +
@@ -164,7 +164,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
        checkNotClosed();
        checkLegalToCapture();

        handler = checkHandler(handler);
        handler = checkHandler(handler, listener);

        if (VERBOSE) {
            CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
@@ -186,7 +186,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
        checkNotClosed();
        checkLegalToCapture();

        handler = checkHandler(handler);
        handler = checkHandler(handler, listener);

        if (VERBOSE) {
            Log.v(TAG, "setRepeatingRequest - request " + request + ", listener " + listener +
@@ -209,7 +209,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
        checkNotClosed();
        checkLegalToCapture();

        handler = checkHandler(handler);
        handler = checkHandler(handler, listener);

        if (VERBOSE) {
            CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
@@ -261,9 +261,12 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
     * <p>The semantics are identical to {@link #close}, except that unconfiguring will be skipped.
     * <p>
     *
     * <p>After this call completes, the session will not call any further methods on the camera
     * device.</p>
     *
     * @see CameraCaptureSession#close
     */
    synchronized void replaceSessionClose(CameraCaptureSession other) {
    synchronized void replaceSessionClose() {
        /*
         * In order for creating new sessions to be fast, the new session should be created
         * before the old session is closed.
@@ -278,13 +281,17 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {

        if (VERBOSE) Log.v(TAG, "replaceSessionClose");

        // #close was already called explicitly, keep going the slow route
        if (mClosed) {
            if (VERBOSE) Log.v(TAG, "replaceSessionClose - close was already called");
            return;
        }

        // Set up fast shutdown. Possible alternative paths:
        // - This session is active, so close() below starts the shutdown drain
        // - This session is mid-shutdown drain, and hasn't yet reached the idle drain listener.
        // - This session is already closed and has executed the idle drain listener, and
        //   configureOutputs(null) has already been called.
        //
        // Do not call configureOutputs(null) going forward, since it would race with the
        // configuration for the new session. If it was already called, then we don't care, since it
        // won't get called again.
        mSkipUnconfigure = true;

        close();
    }

@@ -347,7 +354,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {

    /**
     * Forward callbacks from
     * CameraDevice.CaptureListener to the CameraCaptureSession.CaptureListener.
     * CameraDeviceImpl.CaptureListener to the CameraCaptureSession.CaptureListener.
     *
     * <p>In particular, all calls are automatically split to go both to our own
     * internal listener, and to the user-specified listener (by transparently posting
@@ -356,9 +363,9 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
     * <p>When a capture sequence finishes, update the pending checked sequences set.</p>
     */
    @SuppressWarnings("deprecation")
    private CameraDevice.CaptureListener createCaptureListenerProxy(
    private CameraDeviceImpl.CaptureListener createCaptureListenerProxy(
            Handler handler, CaptureListener listener) {
        CameraDevice.CaptureListener localListener = new CameraDevice.CaptureListener() {
        CameraDeviceImpl.CaptureListener localListener = new CameraDeviceImpl.CaptureListener() {
            @Override
            public void onCaptureSequenceCompleted(CameraDevice camera,
                    int sequenceId, long frameNumber) {
@@ -379,25 +386,28 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
         * - then forward the call to a handler
         * - then finally invoke the destination method on the session listener object
         */
        Dispatchable<CaptureListener> userListenerSink;
        if (listener == null) { // OK: API allows the user to not specify a listener
            userListenerSink = new NullDispatcher<>();
        } else {
            userListenerSink = new InvokeDispatcher<>(listener);
        if (listener == null) {
            // OK: API allows the user to not specify a listener, and the handler may
            // also be null in that case. Collapse whole dispatch chain to only call the local
            // listener
            return localListener;
        }

        InvokeDispatcher<CameraDevice.CaptureListener> localSink =
        InvokeDispatcher<CameraDeviceImpl.CaptureListener> localSink =
                new InvokeDispatcher<>(localListener);

        InvokeDispatcher<CaptureListener> userListenerSink =
                new InvokeDispatcher<>(listener);
        HandlerDispatcher<CaptureListener> handlerPassthrough =
                new HandlerDispatcher<>(userListenerSink, handler);
        DuckTypingDispatcher<CameraDevice.CaptureListener, CaptureListener> duckToSession
        DuckTypingDispatcher<CameraDeviceImpl.CaptureListener, CaptureListener> duckToSession
                = new DuckTypingDispatcher<>(handlerPassthrough, CaptureListener.class);
        ArgumentReplacingDispatcher<CameraDevice.CaptureListener, CameraCaptureSessionImpl>
        ArgumentReplacingDispatcher<CameraDeviceImpl.CaptureListener, CameraCaptureSessionImpl>
                replaceDeviceWithSession = new ArgumentReplacingDispatcher<>(duckToSession,
                        /*argumentIndex*/0, this);

        BroadcastDispatcher<CameraDevice.CaptureListener> broadcaster =
                new BroadcastDispatcher<CameraDevice.CaptureListener>(
        BroadcastDispatcher<CameraDeviceImpl.CaptureListener> broadcaster =
                new BroadcastDispatcher<CameraDeviceImpl.CaptureListener>(
                    replaceDeviceWithSession,
                    localSink);

@@ -415,10 +425,10 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
     * </ul>
     * </p>
     * */
    CameraDevice.StateListener getDeviceStateListener() {
    CameraDeviceImpl.StateListenerKK getDeviceStateListener() {
        final CameraCaptureSession session = this;

        return new CameraDevice.StateListener() {
        return new CameraDeviceImpl.StateListenerKK() {
            private boolean mBusy = false;
            private boolean mActive = false;

@@ -596,6 +606,8 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
                 *
                 * This operation is idempotent; a session will not be closed twice.
                 */
                if (VERBOSE) Log.v(TAG, "Session drain complete, skip unconfigure: " +
                        mSkipUnconfigure);

                // Fast path: A new capture session has replaced this one; don't unconfigure.
                if (mSkipUnconfigure) {
+165 −28

File changed.

Preview size limit exceeded, changes collapsed.

+8 −8
Original line number Diff line number Diff line
@@ -36,13 +36,13 @@ public class ListenerProxies {

    // TODO: replace with codegen

    public static class DeviceStateListenerProxy extends CameraDevice.StateListener {
        private final MethodNameInvoker<CameraDevice.StateListener> mProxy;
    public static class DeviceStateListenerProxy extends CameraDeviceImpl.StateListenerKK {
        private final MethodNameInvoker<CameraDeviceImpl.StateListenerKK> mProxy;

        public DeviceStateListenerProxy(
                Dispatchable<CameraDevice.StateListener> dispatchTarget) {
                Dispatchable<CameraDeviceImpl.StateListenerKK> dispatchTarget) {
            dispatchTarget = checkNotNull(dispatchTarget, "dispatchTarget must not be null");
            mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDevice.StateListener.class);
            mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDeviceImpl.StateListenerKK.class);
        }

        @Override
@@ -87,13 +87,13 @@ public class ListenerProxies {
    }

    @SuppressWarnings("deprecation")
    public static class DeviceCaptureListenerProxy extends CameraDevice.CaptureListener {
        private final MethodNameInvoker<CameraDevice.CaptureListener> mProxy;
    public static class DeviceCaptureListenerProxy extends CameraDeviceImpl.CaptureListener {
        private final MethodNameInvoker<CameraDeviceImpl.CaptureListener> mProxy;

        public DeviceCaptureListenerProxy(
                Dispatchable<CameraDevice.CaptureListener> dispatchTarget) {
                Dispatchable<CameraDeviceImpl.CaptureListener> dispatchTarget) {
            dispatchTarget = checkNotNull(dispatchTarget, "dispatchTarget must not be null");
            mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDevice.CaptureListener.class);
            mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDeviceImpl.CaptureListener.class);
        }

        @Override
+1 −6
Original line number Diff line number Diff line
@@ -813,6 +813,7 @@ public final class StreamConfigurationMap {
        switch (format) {
            case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
            case HAL_PIXEL_FORMAT_BLOB:
            case HAL_PIXEL_FORMAT_RAW_OPAQUE:
                return format;
            case ImageFormat.JPEG:
                throw new IllegalArgumentException(
@@ -843,12 +844,6 @@ public final class StreamConfigurationMap {
     * @throws IllegalArgumentException if the format was not user-defined
     */
    static int checkArgumentFormat(int format) {
        // TODO: remove this hack , CTS shouldn't have been using internal constants
        if (format == HAL_PIXEL_FORMAT_RAW_OPAQUE) {
            Log.w(TAG, "RAW_OPAQUE is not yet a published format; allowing it anyway");
            return format;
        }

        if (!ImageFormat.isPublicFormat(format) && !PixelFormat.isPublicFormat(format)) {
            throw new IllegalArgumentException(String.format(
                    "format 0x%x was not defined in either ImageFormat or PixelFormat", format));