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

Commit 3a3eb157 authored by Igor Murashkin's avatar Igor Murashkin
Browse files

camera2: legacy: fix cached results bug and fix focus modes

- Also add request.frameCounter and request.pipelineDepth results

Change-Id: I104c8243fa525622cb4ab7b5535cbca8588862f3
parent 83d8639e
Loading
Loading
Loading
Loading
+24 −5
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ public class LegacyFocusStateMapper {
                ++mAfRun;
                mAfState = CONTROL_AF_STATE_INACTIVE;
            }
            mCamera.cancelAutoFocus();
        }

        mAfModePrevious = afMode;
@@ -156,10 +157,25 @@ public class LegacyFocusStateMapper {
        // AF Locking
        switch (afTrigger) {
            case CONTROL_AF_TRIGGER_START:

                int afStateAfterStart;
                switch (afMode) {
                    case Parameters.FOCUS_MODE_AUTO:
                    case Parameters.FOCUS_MODE_MACRO:
                        afStateAfterStart = CONTROL_AF_STATE_ACTIVE_SCAN;
                        break;
                    case Parameters.FOCUS_MODE_CONTINUOUS_PICTURE:
                    case Parameters.FOCUS_MODE_CONTINUOUS_VIDEO:
                        afStateAfterStart = CONTROL_AF_STATE_PASSIVE_SCAN;
                    default:
                        // EDOF, INFINITY
                        afStateAfterStart = CONTROL_AF_STATE_INACTIVE;
                }

                final int currentAfRun;
                synchronized (mLock) {
                    currentAfRun = ++mAfRun;
                    mAfState = CONTROL_AF_STATE_ACTIVE_SCAN;
                    mAfState = afStateAfterStart;
                }

                if (VERBOSE) {
@@ -211,11 +227,14 @@ public class LegacyFocusStateMapper {
                break;
            case CONTROL_AF_TRIGGER_CANCEL:
                synchronized (mLock) {
                    int updatedAfRun = ++mAfRun;
                    mCamera.cancelAutoFocus();
                    int updatedAfRun;

                    int newAfState = CONTROL_AF_STATE_INACTIVE;
                    mAfState = newAfState;
                    synchronized (mLock) {
                        updatedAfRun = ++mAfRun;
                        mAfState = CONTROL_AF_STATE_INACTIVE;
                    }

                    mCamera.cancelAutoFocus();

                    if (VERBOSE) {
                        Log.v(TAG, "processRequestTriggers - got AF_TRIGGER_CANCEL, " +
+46 −10
Original line number Diff line number Diff line
@@ -57,22 +57,53 @@ public class LegacyResultMapper {
     *
     * @param legacyRequest a non-{@code null} legacy request containing the latest parameters
     * @param timestamp the timestamp to use for this result in nanoseconds.
     * @param frameCounter a monotonically increasing frame counter for the result
     *
     * @return {@link CameraMetadataNative} object containing result metadata.
     */
    public CameraMetadataNative cachedConvertResultMetadata(
            LegacyRequest legacyRequest, long timestamp) {
            LegacyRequest legacyRequest, long timestamp, long frameCounter) {
        CameraMetadataNative result;
        boolean cached;

        /*
         * Attempt to look up the result from the cache if the parameters haven't changed
         */
        if (mCachedRequest != null && legacyRequest.parameters.same(mCachedRequest.parameters)) {
            CameraMetadataNative newResult = new CameraMetadataNative(mCachedResult);
            result = new CameraMetadataNative(mCachedResult);
            cached = true;
        } else {
            result = convertResultMetadata(legacyRequest, timestamp);
            cached = false;

            // Always cache a *copy* of the metadata result,
            // since api2's client side takes ownership of it after it receives a result
            mCachedRequest = legacyRequest;
            mCachedResult = new CameraMetadataNative(result);
        }

        /*
         * Unconditionally set fields that change in every single frame
         */
        {
            // request.frameCounter
            result.set(REQUEST_FRAME_COUNT, (int)frameCounter);
            // TODO: fix CaptureResult#getFrameNumber not to need this key

            // sensor.timestamp
            newResult.set(CaptureResult.SENSOR_TIMESTAMP, timestamp);
            return newResult;
            result.set(SENSOR_TIMESTAMP, timestamp);
        }

        mCachedRequest = legacyRequest;
        mCachedResult = convertResultMetadata(mCachedRequest, timestamp);
        return mCachedResult;
        if (VERBOSE) {
            Log.v(TAG, "cachedConvertResultMetadata - cached? " + cached +
                    " frameCounter = " + frameCounter + " timestamp = " + timestamp);

            Log.v(TAG, "----- beginning of result dump ------");
            result.dumpToLog();
            Log.v(TAG, "----- end of result dump ------");
        }

        return result;
    }

    /**
@@ -83,7 +114,7 @@ public class LegacyResultMapper {
     *
     * @return a {@link CameraMetadataNative} object containing result metadata.
     */
    public static CameraMetadataNative convertResultMetadata(LegacyRequest legacyRequest,
    private static CameraMetadataNative convertResultMetadata(LegacyRequest legacyRequest,
                                                      long timestamp) {
        CameraCharacteristics characteristics = legacyRequest.characteristics;
        CaptureRequest request = legacyRequest.captureRequest;
@@ -147,6 +178,13 @@ public class LegacyResultMapper {
        // lens.focalLength
        result.set(CaptureResult.LENS_FOCAL_LENGTH, params.getFocalLength());

        /*
         * request
         */
        // request.pipelineDepth
        result.set(REQUEST_PIPELINE_DEPTH,
                characteristics.get(CameraCharacteristics.REQUEST_PIPELINE_MAX_DEPTH));

        /*
         * scaler
         */
@@ -155,8 +193,6 @@ public class LegacyResultMapper {
        /*
         * sensor
         */
        // sensor.timestamp
        result.set(CaptureResult.SENSOR_TIMESTAMP, timestamp);

        // TODO: Remaining result metadata tags conversions.
        return result;
+2 −1
Original line number Diff line number Diff line
@@ -614,6 +614,7 @@ public class RequestThreadManager {
                        }

                        // Unconditionally process AF triggers, since they're non-idempotent
                        // - must be done after setting the most-up-to-date AF mode
                        mFocusStateMapper.processRequestTriggers(request, mParams);

                        try {
@@ -673,7 +674,7 @@ public class RequestThreadManager {
                        }

                        CameraMetadataNative result = mMapper.cachedConvertResultMetadata(
                                mLastRequest, timestampMutable.value);
                                mLastRequest, timestampMutable.value, holder.getFrameNumber());
                        // Update AF state
                        mFocusStateMapper.mapResultTriggers(result);