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

Commit 47907370 authored by Rucha Katakwar's avatar Rucha Katakwar Committed by Automerger Merge Worker
Browse files

Merge "Camera:Fix the memory leak caused during HFR mode." into sc-qpr1-dev am: 4881b7d6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15828855

Change-Id: I7a9e1944893d88ed9099023ee255e027f5e8ed01
parents 8f79c108 4881b7d6
Loading
Loading
Loading
Loading
+65 −10
Original line number Diff line number Diff line
@@ -104,6 +104,9 @@ public class CameraDeviceImpl extends CameraDevice
    private SparseArray<CaptureCallbackHolder> mCaptureCallbackMap =
            new SparseArray<CaptureCallbackHolder>();

    /** map request IDs which have batchedOutputs to requestCount*/
    private HashMap<Integer, Integer> mBatchOutputMap = new HashMap<>();

    private int mRepeatingRequestId = REQUEST_ID_NONE;
    // Latest repeating request list's types
    private int[] mRepeatingRequestTypes;
@@ -973,6 +976,7 @@ public class CameraDeviceImpl extends CameraDevice
            mConfiguredInput = new SimpleEntry<Integer, InputConfiguration>(REQUEST_ID_NONE, null);
            mIdle = true;
            mCaptureCallbackMap = new SparseArray<CaptureCallbackHolder>();
            mBatchOutputMap = new HashMap<>();
            mFrameNumberTracker = new FrameNumberTracker();

            mCurrentSession.closeWithoutDraining();
@@ -1179,6 +1183,41 @@ public class CameraDeviceImpl extends CameraDevice
        return requestTypes;
    }

    private boolean hasBatchedOutputs(List<CaptureRequest> requestList) {
        boolean hasBatchedOutputs = true;
        for (int i = 0; i < requestList.size(); i++) {
            CaptureRequest request = requestList.get(i);
            if (!request.isPartOfCRequestList()) {
                hasBatchedOutputs = false;
                break;
            }
            if (i == 0) {
                Collection<Surface> targets = request.getTargets();
                if (targets.size() != 2) {
                    hasBatchedOutputs = false;
                    break;
                }
            }
        }
        return hasBatchedOutputs;
    }

    private void updateTracker(int requestId, long frameNumber,
            int requestType, CaptureResult result, boolean isPartialResult) {
        int requestCount = 1;
        // If the request has batchedOutputs update each frame within the batch.
        if (mBatchOutputMap.containsKey(requestId)) {
            requestCount = mBatchOutputMap.get(requestId);
            for (int i = 0; i < requestCount; i++) {
                mFrameNumberTracker.updateTracker(frameNumber - (requestCount - 1 - i),
                        result, isPartialResult, requestType);
            }
        } else {
            mFrameNumberTracker.updateTracker(frameNumber, result,
                    isPartialResult, requestType);
        }
    }

    private int submitCaptureRequest(List<CaptureRequest> requestList, CaptureCallback callback,
            Executor executor, boolean repeating) throws CameraAccessException {

@@ -1224,6 +1263,14 @@ public class CameraDeviceImpl extends CameraDevice
                request.recoverStreamIdToSurface();
            }

            // If the request has batched outputs, then store the
            // requestCount and requestId in the map.
            boolean hasBatchedOutputs = hasBatchedOutputs(requestList);
            if (hasBatchedOutputs) {
                int requestCount = requestList.size();
                mBatchOutputMap.put(requestInfo.getRequestId(), requestCount);
            }

            if (callback != null) {
                mCaptureCallbackMap.put(requestInfo.getRequestId(),
                        new CaptureCallbackHolder(
@@ -1839,8 +1886,18 @@ public class CameraDeviceImpl extends CameraDevice
            if (DEBUG) {
                Log.v(TAG, String.format("got error frame %d", frameNumber));
            }

            // Update FrameNumberTracker for every frame during HFR mode.
            if (mBatchOutputMap.containsKey(requestId)) {
                for (int i = 0; i < mBatchOutputMap.get(requestId); i++) {
                    mFrameNumberTracker.updateTracker(frameNumber - (subsequenceId - i),
                            /*error*/true, request.getRequestType());
                }
            } else {
                mFrameNumberTracker.updateTracker(frameNumber,
                        /*error*/true, request.getRequestType());
            }

            checkAndFireSequenceComplete();

            // Dispatch the failure callback
@@ -2023,7 +2080,6 @@ public class CameraDeviceImpl extends CameraDevice
        public void onResultReceived(CameraMetadataNative result,
                CaptureResultExtras resultExtras, PhysicalCaptureResultInfo physicalResults[])
                throws RemoteException {

            int requestId = resultExtras.getRequestId();
            long frameNumber = resultExtras.getFrameNumber();

@@ -2064,8 +2120,8 @@ public class CameraDeviceImpl extends CameraDevice
                                        + frameNumber);
                    }

                    mFrameNumberTracker.updateTracker(frameNumber, /*result*/null, isPartialResult,
                            requestType);
                    updateTracker(requestId, frameNumber, requestType, /*result*/null,
                            isPartialResult);

                    return;
                }
@@ -2077,8 +2133,9 @@ public class CameraDeviceImpl extends CameraDevice
                                        + frameNumber);
                    }

                    mFrameNumberTracker.updateTracker(frameNumber, /*result*/null, isPartialResult,
                            requestType);
                    updateTracker(requestId, frameNumber, requestType, /*result*/null,
                            isPartialResult);

                    return;
                }

@@ -2184,9 +2241,7 @@ public class CameraDeviceImpl extends CameraDevice
                    Binder.restoreCallingIdentity(ident);
                }

                // Collect the partials for a total result; or mark the frame as totally completed
                mFrameNumberTracker.updateTracker(frameNumber, finalResult, isPartialResult,
                        requestType);
                updateTracker(requestId, frameNumber, requestType, finalResult, isPartialResult);

                // Fire onCaptureSequenceCompleted
                if (!isPartialResult) {