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

Commit 7336f470 authored by Igor Murashkin's avatar Igor Murashkin
Browse files

camera: (LEGACY) - Add captureIntent and physicalSize metadata

Bug: 16900182
Change-Id: I159f2416da71c2d7ea803d61b63476da90e03b1c
parent 8c4486c1
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.hardware.camera2.utils.ParamsUtils;
import android.util.Log;
import android.util.Range;
import android.util.Size;
import android.util.SizeF;

import java.util.ArrayList;
import java.util.Arrays;
@@ -764,6 +765,23 @@ public class LegacyMetadataMapper {
         * sensor.info.pixelArraySize
         */
        m.set(SENSOR_INFO_PIXEL_ARRAY_SIZE, largestJpegSize);

        /*
         * sensor.info.physicalSize
         */
        {
            /*
             * Assume focal length is at infinity focus and that the lens is rectilinear.
             */
            float focalLength = p.getFocalLength(); // in mm
            double angleHor = p.getHorizontalViewAngle() * Math.PI / 180; // to radians
            double angleVer = p.getVerticalViewAngle() * Math.PI / 180; // to radians

            float height = (float)Math.abs(2 * focalLength * Math.tan(angleVer / 2));
            float width = (float)Math.abs(2 * focalLength * Math.tan(angleHor / 2));

            m.set(SENSOR_INFO_PHYSICAL_SIZE, new SizeF(width, height)); // in mm
        }
    }

    private static void mapStatistics(CameraMetadataNative m, Parameters p) {
@@ -1069,7 +1087,24 @@ public class LegacyMetadataMapper {
        }

        // control.captureIntent
        m.set(CaptureRequest.CONTROL_CAPTURE_INTENT, templateId);
        {
            int captureIntent;
            switch (templateId) {
                case CameraDevice.TEMPLATE_PREVIEW:
                    captureIntent = CONTROL_CAPTURE_INTENT_PREVIEW;
                    break;
                case CameraDevice.TEMPLATE_STILL_CAPTURE:
                    captureIntent = CONTROL_CAPTURE_INTENT_STILL_CAPTURE;
                    break;
                case CameraDevice.TEMPLATE_RECORD:
                    captureIntent = CONTROL_CAPTURE_INTENT_VIDEO_RECORD;
                    break;
                default:
                    // Can't get anything else since it's guarded by the IAE check
                    throw new AssertionError("Impossible; keep in sync with sAllowedTemplates");
            }
            m.set(CaptureRequest.CONTROL_CAPTURE_INTENT, captureIntent);
        }

        // control.aeMode
        m.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
+35 −0
Original line number Diff line number Diff line
@@ -246,6 +246,19 @@ public class LegacyRequestMapper {
         // TODO: Don't add control.awbLock to availableRequestKeys if it's not supported
        }

        // control.captureIntent
        {
            int captureIntent = ParamsUtils.getOrDefault(request,
                    CONTROL_CAPTURE_INTENT,
                    /*defaultValue*/CONTROL_CAPTURE_INTENT_PREVIEW);

            captureIntent = filterSupportedCaptureIntent(captureIntent);

            params.setRecordingHint(
                    captureIntent == CONTROL_CAPTURE_INTENT_VIDEO_RECORD ||
                    captureIntent == CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT);
        }

        // control.videoStabilizationMode
        {
            Integer stabMode = getIfSupported(request, CONTROL_VIDEO_STABILIZATION_MODE,
@@ -339,6 +352,28 @@ public class LegacyRequestMapper {
        }
    }

    static int filterSupportedCaptureIntent(int captureIntent) {
        switch (captureIntent) {
            case CONTROL_CAPTURE_INTENT_CUSTOM:
            case CONTROL_CAPTURE_INTENT_PREVIEW:
            case CONTROL_CAPTURE_INTENT_STILL_CAPTURE:
            case CONTROL_CAPTURE_INTENT_VIDEO_RECORD:
            case CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT:
                break;
            case CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG:
            case CONTROL_CAPTURE_INTENT_MANUAL:
                captureIntent = CONTROL_CAPTURE_INTENT_PREVIEW;
                Log.w(TAG, "Unsupported control.captureIntent value " + captureIntent
                        + "; default to PREVIEW");
            default:
                captureIntent = CONTROL_CAPTURE_INTENT_PREVIEW;
                Log.w(TAG, "Unknown control.captureIntent value " + captureIntent
                        + "; default to PREVIEW");
        }

        return captureIntent;
    }

    private static List<Camera.Area> convertMeteringRegionsToLegacy(
            Rect activeArray, ParameterUtils.ZoomData zoomData,
            MeteringRectangle[] meteringRegions, int maxNumMeteringAreas, String regionName) {
+13 −0
Original line number Diff line number Diff line
@@ -142,6 +142,19 @@ public class LegacyResultMapper {
         */
        mapAwb(result, /*out*/params);

        /*
         * control.captureIntent
         */
        {
            int captureIntent = ParamsUtils.getOrDefault(request,
                    CaptureRequest.CONTROL_CAPTURE_INTENT,
                    /*defaultValue*/CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW);

            captureIntent = LegacyRequestMapper.filterSupportedCaptureIntent(captureIntent);

            result.set(CONTROL_CAPTURE_INTENT, captureIntent);
        }

        /*
         * control.mode
         */