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

Commit 8c4486c1 authored by Igor Murashkin's avatar Igor Murashkin
Browse files

camera: (Legacy) Add support for SCENE_MODE == FACE_PRIORITY

Bug: 16898478
Change-Id: I4306f6380ea06e8bd95af8738e5dde1a42a8098c
parent 61da0fdf
Loading
Loading
Loading
Loading
+36 −3
Original line number Diff line number Diff line
@@ -48,9 +48,16 @@ public class LegacyFaceDetectMapper {
    private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);

    private final Camera mCamera;
    /** Is the camera capable of face detection? */
    private final boolean mFaceDetectSupported;
    /** Is the camera is running face detection? */
    private boolean mFaceDetectEnabled = false;
    /** Did the last request say to use SCENE_MODE = FACE_PRIORITY? */
    private boolean mFaceDetectScenePriority = false;
    /** Did the last request enable the face detect mode to ON? */
    private boolean mFaceDetectReporting = false;

    /** Synchronize access to all fields */
    private final Object mLock = new Object();
    private Camera.Face[] mFaces;
    private Camera.Face[] mFacesPrev;
@@ -129,6 +136,17 @@ public class LegacyFaceDetectMapper {
            return;
        }

        /*
         * control.sceneMode
         */
        int sceneMode = ParamsUtils.getOrDefault(captureRequest, CONTROL_SCENE_MODE,
                CONTROL_SCENE_MODE_DISABLED);
        if (sceneMode == CONTROL_SCENE_MODE_FACE_PRIORITY && !mFaceDetectSupported) {
            Log.w(TAG, "processFaceDetectMode - ignoring control.sceneMode == FACE_PRIORITY; " +
                    "face detection is not available");
            return;
        }

        // Print some warnings out in case the values were wrong
        switch (fdMode) {
            case STATISTICS_FACE_DETECT_MODE_OFF:
@@ -145,7 +163,8 @@ public class LegacyFaceDetectMapper {
                return;
        }

        boolean enableFaceDetect = fdMode != STATISTICS_FACE_DETECT_MODE_OFF;
        boolean enableFaceDetect = (fdMode != STATISTICS_FACE_DETECT_MODE_OFF)
                || (sceneMode == CONTROL_SCENE_MODE_FACE_PRIORITY);
        synchronized (mLock) {
            // Enable/disable face detection if it's changed since last time
            if (enableFaceDetect != mFaceDetectEnabled) {
@@ -166,6 +185,8 @@ public class LegacyFaceDetectMapper {
                }

                mFaceDetectEnabled = enableFaceDetect;
                mFaceDetectScenePriority = sceneMode == CONTROL_SCENE_MODE_FACE_PRIORITY;
                mFaceDetectReporting = fdMode != STATISTICS_FACE_DETECT_MODE_OFF;
            }
        }
    }
@@ -177,6 +198,10 @@ public class LegacyFaceDetectMapper {
     * <p>Face detect callbacks are processed in the background, and each call to
     * {@link #mapResultFaces} will have the latest faces as reflected by the camera1 callbacks.</p>
     *
     * <p>If the scene mode was set to {@code FACE_PRIORITY} but face detection is disabled,
     * the camera will still run face detection in the background, but no faces will be reported
     * in the capture result.</p>
     *
     * @param result a non-{@code null} result
     * @param legacyRequest a non-{@code null} request (read-only)
     */
@@ -186,16 +211,19 @@ public class LegacyFaceDetectMapper {

        Camera.Face[] faces, previousFaces;
        int fdMode;
        boolean fdScenePriority;
        synchronized (mLock) {
            fdMode = mFaceDetectEnabled ?
            fdMode = mFaceDetectReporting ?
                            STATISTICS_FACE_DETECT_MODE_SIMPLE : STATISTICS_FACE_DETECT_MODE_OFF;

            if (mFaceDetectEnabled) {
            if (mFaceDetectReporting) {
                faces = mFaces;
            } else {
                faces = null;
            }

            fdScenePriority = mFaceDetectScenePriority;

            previousFaces = mFacesPrev;
            mFacesPrev = faces;
        }
@@ -227,5 +255,10 @@ public class LegacyFaceDetectMapper {

        result.set(CaptureResult.STATISTICS_FACES, convertedFaces.toArray(new Face[0]));
        result.set(CaptureResult.STATISTICS_FACE_DETECT_MODE, fdMode);

        // Override scene mode with FACE_PRIORITY if the request was using FACE_PRIORITY
        if (fdScenePriority) {
            result.set(CaptureResult.CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_FACE_PRIORITY);
        }
    }
}
+15 −3
Original line number Diff line number Diff line
@@ -535,9 +535,16 @@ public class LegacyMetadataMapper {
         * android.control.availableSceneModes
         */
        List<String> sceneModes = p.getSupportedSceneModes();
        int[] supportedSceneModes = (sceneModes == null) ? new int[0] :
                ArrayUtils.convertStringListToIntArray(sceneModes, sLegacySceneModes, sSceneModes);
        m.set(CONTROL_AVAILABLE_SCENE_MODES, supportedSceneModes);
        List<Integer> supportedSceneModes =
                ArrayUtils.convertStringListToIntList(sceneModes, sLegacySceneModes, sSceneModes);
        if (supportedSceneModes == null) { // camera1 doesn't support scene mode settings
            supportedSceneModes = new ArrayList<Integer>();
            supportedSceneModes.add(CONTROL_SCENE_MODE_DISABLED); // disabled is always available
        }
        if (p.getMaxNumDetectedFaces() > 0) { // always supports FACE_PRIORITY when face detecting
            supportedSceneModes.add(CONTROL_SCENE_MODE_FACE_PRIORITY);
        }
        m.set(CONTROL_AVAILABLE_SCENE_MODES, ArrayUtils.toIntArray(supportedSceneModes));
    }

    private static void mapLens(CameraMetadataNative m, Camera.Parameters p) {
@@ -850,6 +857,11 @@ public class LegacyMetadataMapper {
    }

    static String convertSceneModeToLegacy(int mode) {
        if (mode == CONTROL_SCENE_MODE_FACE_PRIORITY) {
            // OK: Let LegacyFaceDetectMapper handle turning face detection on/off
            return Parameters.SCENE_MODE_AUTO;
        }

        int index = ArrayUtils.getArrayIndex(sSceneModes, mode);
        if (index < 0) {
            return null;
+2 −3
Original line number Diff line number Diff line
@@ -35,9 +35,6 @@ import java.util.ArrayList;
import java.util.List;

import static com.android.internal.util.Preconditions.*;
import static android.hardware.camera2.CameraMetadata.CONTROL_VIDEO_STABILIZATION_MODE_OFF;
import static android.hardware.camera2.CameraMetadata.CONTROL_VIDEO_STABILIZATION_MODE_ON;
import static android.hardware.camera2.CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE;
import static android.hardware.camera2.CaptureResult.*;

/**
@@ -166,6 +163,8 @@ public class LegacyResultMapper {
            int mode = LegacyMetadataMapper.convertSceneModeFromLegacy(legacySceneMode);
            if (mode != LegacyMetadataMapper.UNKNOWN_MODE) {
                result.set(CaptureResult.CONTROL_SCENE_MODE, mode);
                // In case of SCENE_MODE == FACE_PRIORITY, LegacyFaceDetectMapper will override
                // the result to say SCENE_MODE == FACE_PRIORITY.
            }  else {
                Log.w(TAG, "Unknown scene mode " + legacySceneMode +
                        " returned by camera HAL, setting to disabled.");
+7 −1
Original line number Diff line number Diff line
@@ -725,9 +725,15 @@ public class RequestThreadManager {

                        CameraMetadataNative result = mMapper.cachedConvertResultMetadata(
                                mLastRequest, timestampMutable.value);
                        /*
                         * Order matters: The default result mapper is state-less; the
                         * other mappers carry state and may override keys set by the default
                         * mapper with their own values.
                         */

                        // Update AF state
                        mFocusStateMapper.mapResultTriggers(result);
                        // Update detected faces list
                        // Update face-related results
                        mFaceDetectMapper.mapResultFaces(result, mLastRequest);

                        mDeviceState.setCaptureResult(holder, result);
+1 −1

File changed.

Contains only whitespace changes.