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

Commit e3fc290f authored by Yin-Chia Yeh's avatar Yin-Chia Yeh Committed by android-build-merger
Browse files

Merge "Camera: remove capture session lock" into oc-dr1-dev

am: 104b68d0

Change-Id: Idf53e22c091914d504830e24e76c3936ef5e6257
parents c6e3a65d 104b68d0
Loading
Loading
Loading
Loading
+113 −113
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
    }

    @Override
    public synchronized int capture(CaptureRequest request, CaptureCallback callback,
    public int capture(CaptureRequest request, CaptureCallback callback,
            Handler handler) throws CameraAccessException {
        if (request == null) {
            throw new IllegalArgumentException("request must not be null");
@@ -169,6 +169,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            throw new IllegalArgumentException("capture request was created for another session");
        }

        synchronized (mDeviceImpl.mInterfaceLock) {
            checkNotClosed();

            handler = checkHandler(handler, callback);
@@ -181,9 +182,10 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            return addPendingSequence(mDeviceImpl.capture(request,
                    createCaptureCallbackProxy(handler, callback), mDeviceHandler));
        }
    }

    @Override
    public synchronized int captureBurst(List<CaptureRequest> requests, CaptureCallback callback,
    public int captureBurst(List<CaptureRequest> requests, CaptureCallback callback,
            Handler handler) throws CameraAccessException {
        if (requests == null) {
            throw new IllegalArgumentException("Requests must not be null");
@@ -203,6 +205,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            }
        }

        synchronized (mDeviceImpl.mInterfaceLock) {
            checkNotClosed();

            handler = checkHandler(handler, callback);
@@ -216,9 +219,10 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            return addPendingSequence(mDeviceImpl.captureBurst(requests,
                    createCaptureCallbackProxy(handler, callback), mDeviceHandler));
        }
    }

    @Override
    public synchronized int setRepeatingRequest(CaptureRequest request, CaptureCallback callback,
    public int setRepeatingRequest(CaptureRequest request, CaptureCallback callback,
            Handler handler) throws CameraAccessException {
        if (request == null) {
            throw new IllegalArgumentException("request must not be null");
@@ -226,6 +230,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            throw new IllegalArgumentException("repeating reprocess requests are not supported");
        }

        synchronized (mDeviceImpl.mInterfaceLock) {
            checkNotClosed();

            handler = checkHandler(handler, callback);
@@ -238,9 +243,10 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            return addPendingSequence(mDeviceImpl.setRepeatingRequest(request,
                    createCaptureCallbackProxy(handler, callback), mDeviceHandler));
        }
    }

    @Override
    public synchronized int setRepeatingBurst(List<CaptureRequest> requests,
    public int setRepeatingBurst(List<CaptureRequest> requests,
            CaptureCallback callback, Handler handler) throws CameraAccessException {
        if (requests == null) {
            throw new IllegalArgumentException("requests must not be null");
@@ -255,22 +261,26 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            }
        }

        synchronized (mDeviceImpl.mInterfaceLock) {
            checkNotClosed();

            handler = checkHandler(handler, callback);

            if (DEBUG) {
                CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
            Log.v(TAG, mIdString + "setRepeatingBurst - requests " + Arrays.toString(requestArray) +
                    ", callback " + callback + " handler" + "" + handler);
                Log.v(TAG, mIdString + "setRepeatingBurst - requests " +
                        Arrays.toString(requestArray) + ", callback " + callback +
                        " handler" + "" + handler);
            }

            return addPendingSequence(mDeviceImpl.setRepeatingBurst(requests,
                    createCaptureCallbackProxy(handler, callback), mDeviceHandler));
        }
    }

    @Override
    public synchronized void stopRepeating() throws CameraAccessException {
    public void stopRepeating() throws CameraAccessException {
        synchronized (mDeviceImpl.mInterfaceLock) {
            checkNotClosed();

            if (DEBUG) {
@@ -279,10 +289,11 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession

            mDeviceImpl.stopRepeating();
        }
    }

    @Override
    public void abortCaptures() throws CameraAccessException {
        synchronized (this) {
        synchronized (mDeviceImpl.mInterfaceLock) {
            checkNotClosed();

            if (DEBUG) {
@@ -296,15 +307,11 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession

            mAborting = true;
            mAbortDrainer.taskStarted();
        }

        synchronized (mDeviceImpl.mInterfaceLock) {
            synchronized (this) {
            mDeviceImpl.flush();
            // The next BUSY -> IDLE set of transitions will mark the end of the abort.
        }
    }
    }

    @Override
    public boolean isReprocessable() {
@@ -332,7 +339,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
     */
    @Override
    public void replaceSessionClose() {
        synchronized (this) {
        synchronized (mDeviceImpl.mInterfaceLock) {
            /*
             * In order for creating new sessions to be fast, the new session should be created
             * before the old session is closed.
@@ -357,13 +364,13 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            // 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();
        }
    }

    @Override
    public void close() {
        synchronized (this) {
        synchronized (mDeviceImpl.mInterfaceLock) {
            if (mClosed) {
                if (DEBUG) Log.v(TAG, mIdString + "close - reentering");
                return;
@@ -372,10 +379,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            if (DEBUG) Log.v(TAG, mIdString + "close - first time");

            mClosed = true;
        }

        synchronized (mDeviceImpl.mInterfaceLock) {
            synchronized (this) {
            /*
             * Flush out any repeating request. Since camera is closed, no new requests
             * can be queued, and eventually the entire request queue will be drained.
@@ -404,10 +408,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession

                // TODO: call onError instead of onClosed if this happens
            }
            }
        }

        synchronized (this) {
            // If no sequences are pending, fire #onClosed immediately
            mSequenceDrainer.beginDrain();
        }
@@ -552,6 +553,8 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
    @Override
    public CameraDeviceImpl.StateCallbackKK getDeviceStateCallback() {
        final CameraCaptureSession session = this;
        final Object interfaceLock = mDeviceImpl.mInterfaceLock;


        return new CameraDeviceImpl.StateCallbackKK() {
            private boolean mBusy = false;
@@ -588,7 +591,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
                boolean isAborting;
                if (DEBUG) Log.v(TAG, mIdString + "onIdle");

                synchronized (session) {
                synchronized (interfaceLock) {
                    isAborting = mAborting;
                }

@@ -606,7 +609,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
                if (mBusy && isAborting) {
                    mAbortDrainer.taskFinished();

                    synchronized (session) {
                    synchronized (interfaceLock) {
                        mAborting = false;
                    }
                }
@@ -729,7 +732,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
        @Override
        public void onDrained() {
            if (DEBUG) Log.v(TAG, mIdString + "onAbortDrained");
            synchronized (CameraCaptureSessionImpl.this) {
            synchronized (mDeviceImpl.mInterfaceLock) {
                /*
                 * Any queued aborts have now completed.
                 *
@@ -757,7 +760,6 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
            // Take device lock before session lock so that we can call back into device
            // without causing a deadlock
            synchronized (mDeviceImpl.mInterfaceLock) {
                synchronized (CameraCaptureSessionImpl.this) {
                /*
                 * The device is now IDLE, and has settled. It will not transition to
                 * ACTIVE or BUSY again by itself.
@@ -792,8 +794,6 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
                    if (DEBUG) Log.v(TAG, mIdString +
                            "Camera was already closed or busy, skipping unconfigure");
                }

                }
            }
        }
    }