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

Commit bc0a0675 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Camera: Various offline processing fixes"

parents 751b89c3 ce371cac
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public class CameraDeviceImpl extends CameraDevice
    private boolean mIdle = true;

    /** map request IDs to callback/request data */
    private final SparseArray<CaptureCallbackHolder> mCaptureCallbackMap =
    private SparseArray<CaptureCallbackHolder> mCaptureCallbackMap =
            new SparseArray<CaptureCallbackHolder>();

    private int mRepeatingRequestId = REQUEST_ID_NONE;
@@ -123,7 +123,7 @@ public class CameraDeviceImpl extends CameraDevice
     * An object tracking received frame numbers.
     * Updated when receiving callbacks from ICameraDeviceCallbacks.
     */
    private final FrameNumberTracker mFrameNumberTracker = new FrameNumberTracker();
    private FrameNumberTracker mFrameNumberTracker = new FrameNumberTracker();

    private CameraCaptureSessionCore mCurrentSession;
    private int mNextSessionId = 0;
@@ -892,6 +892,7 @@ public class CameraDeviceImpl extends CameraDevice
        HashSet<Integer> offlineStreamIds = new HashSet<Integer>();
        SparseArray<OutputConfiguration> offlineConfiguredOutputs =
                new SparseArray<OutputConfiguration>();
        CameraOfflineSession ret;

        synchronized(mInterfaceLock) {
            if (mOfflineSessionImpl != null) {
@@ -919,15 +920,20 @@ public class CameraDeviceImpl extends CameraDevice

                offlineStreamIds.add(streamId);
            }
            stopRepeating();

            mOfflineSessionImpl = new CameraOfflineSessionImpl(mCameraId,
                    mCharacteristics, executor, listener, offlineConfiguredOutputs,
                    mConfiguredInput, mFrameNumberTracker, mCaptureCallbackMap,
                    mConfiguredInput, mConfiguredOutputs, mFrameNumberTracker, mCaptureCallbackMap,
                    mRequestLastFrameNumbersList);
            ret = mOfflineSessionImpl;

            mOfflineSwitchService = Executors.newSingleThreadExecutor();
            mConfiguredOutputs.clear();
            mConfiguredInput = new SimpleEntry<Integer, InputConfiguration>(REQUEST_ID_NONE, null);
            mIdle = true;
            mCaptureCallbackMap = new SparseArray<CaptureCallbackHolder>();
            mFrameNumberTracker = new FrameNumberTracker();

            mCurrentSession.closeWithoutDraining();
            mCurrentSession = null;
@@ -949,11 +955,13 @@ public class CameraDeviceImpl extends CameraDevice
                    mOfflineSessionImpl.setRemoteSession(remoteOfflineSession);
                } catch (CameraAccessException e) {
                    mOfflineSessionImpl.notifyFailedSwitch();
                } finally {
                    mOfflineSessionImpl = null;
                }
            }
        });

        return mOfflineSessionImpl;
        return ret;
    }

    public boolean supportsOfflineProcessing(Surface surface) {
+21 −18
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
    private SimpleEntry<Integer, InputConfiguration> mOfflineInput =
            new SimpleEntry<>(REQUEST_ID_NONE, null);
    private SparseArray<OutputConfiguration> mOfflineOutputs = new SparseArray<>();
    private SparseArray<OutputConfiguration> mConfiguredOutputs = new SparseArray<>();

    final Object mInterfaceLock = new Object(); // access from this class and Session only!

@@ -96,6 +97,7 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
            Executor offlineExecutor, CameraOfflineSessionCallback offlineCallback,
            SparseArray<OutputConfiguration> offlineOutputs,
            SimpleEntry<Integer, InputConfiguration> offlineInput,
            SparseArray<OutputConfiguration> configuredOutputs,
            FrameNumberTracker frameNumberTracker, SparseArray<CaptureCallbackHolder> callbackMap,
            List<RequestLastFrameNumbersHolder> frameNumberList) {
        if ((cameraId == null) || (characteristics == null)) {
@@ -117,6 +119,7 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
        mOfflineRequestLastFrameNumbersList.addAll(frameNumberList);
        mFrameNumberTracker = frameNumberTracker;
        mCaptureCallbackMap = callbackMap;
        mConfiguredOutputs = configuredOutputs;
        mOfflineOutputs = offlineOutputs;
        mOfflineInput = offlineInput;
        mOfflineExecutor = checkNotNull(offlineExecutor, "offline executor must not be null");
@@ -137,9 +140,6 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
        @Override
        public void onDeviceError(final int errorCode, CaptureResultExtras resultExtras) {
            synchronized(mInterfaceLock) {
                if (mRemoteSession == null) {
                    return; // Camera already closed
                }

                switch (errorCode) {
                    case CameraDeviceCallbacks.ERROR_CAMERA_REQUEST:
@@ -177,6 +177,11 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
        @Override
        public void onDeviceIdle() {
            synchronized(mInterfaceLock) {
                if (mRemoteSession == null) {
                    Log.v(TAG, "Ignoring idle state notifications during offline switches");
                    return;
                }

                Runnable idleDispatch = new Runnable() {
                    @Override
                    public void run() {
@@ -203,8 +208,6 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
            final CaptureCallbackHolder holder;

            synchronized(mInterfaceLock) {
                if (mRemoteSession == null) return; // Camera already closed

                // Get the callback for this frame ID, if there is one
                holder = CameraOfflineSessionImpl.this.mCaptureCallbackMap.get(requestId);

@@ -269,8 +272,6 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
            long frameNumber = resultExtras.getFrameNumber();

            synchronized(mInterfaceLock) {
                if (mRemoteSession == null) return; // Camera already closed

                // TODO: Handle CameraCharacteristics access from CaptureResult correctly.
                result.set(CameraCharacteristics.LENS_INFO_SHADING_MAP_SIZE,
                        mCharacteristics.get(CameraCharacteristics.LENS_INFO_SHADING_MAP_SIZE));
@@ -445,8 +446,12 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
            if (errorCode == ERROR_CAMERA_BUFFER) {
                // Because 1 stream id could map to multiple surfaces, we need to specify both
                // streamId and surfaceId.
                OutputConfiguration config = mOfflineOutputs.get(
                        resultExtras.getErrorStreamId());
                OutputConfiguration config;
                if ((mRemoteSession == null) && !isClosed()) {
                    config = mConfiguredOutputs.get(resultExtras.getErrorStreamId());
                } else {
                    config = mOfflineOutputs.get(resultExtras.getErrorStreamId());
                }
                if (config == null) {
                    Log.v(TAG, String.format(
                            "Stream %d has been removed. Skipping buffer lost callback",
@@ -538,11 +543,6 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
            final Executor executor;
            final CameraCaptureSession.CaptureCallback callback;
            synchronized(mInterfaceLock) {
                if (mRemoteSession == null) {
                    Log.w(TAG, "Camera closed while checking sequences");
                    return;
                }

                int index = mCaptureCallbackMap.indexOfKey(requestId);
                holder = (index >= 0) ?
                        mCaptureCallbackMap.valueAt(index) : null;
@@ -575,7 +575,7 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
            }

            // Call onCaptureSequenceCompleted
            if ((sequenceCompleted) && (callback != null) && (executor == null)) {
            if ((sequenceCompleted) && (callback != null) && (executor != null)) {
                Runnable resultDispatch = new Runnable() {
                    @Override
                    public void run() {
@@ -592,8 +592,13 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }

                if (mCaptureCallbackMap.size() == 0) {
                    getCallbacks().onDeviceIdle();
                }
            }

        }
    }

    public void notifyFailedSwitch() {
@@ -686,10 +691,8 @@ public class CameraOfflineSessionImpl extends CameraOfflineSession
            Runnable closeDispatch = new Runnable() {
                @Override
                public void run() {
                    if (!isClosed()) {
                    mOfflineCallback.onClosed(CameraOfflineSessionImpl.this);
                }
                }
            };

            final long ident = Binder.clearCallingIdentity();