OSDN Git Service

camera: (LEGACY) - Add captureIntent and physicalSize metadata
authorIgor Murashkin <iam@google.com>
Fri, 8 Aug 2014 23:44:34 +0000 (16:44 -0700)
committerIgor Murashkin <iam@google.com>
Mon, 11 Aug 2014 20:25:01 +0000 (13:25 -0700)
Bug: 16900182
Change-Id: I159f2416da71c2d7ea803d61b63476da90e03b1c

core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java
core/java/android/hardware/camera2/legacy/LegacyResultMapper.java

index 0672dae..faacbeb 100644 (file)
@@ -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);
index f31b778..35646fe 100644 (file)
@@ -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) {
index 041cc22..a2f9b4c 100644 (file)
@@ -143,6 +143,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
          */
         {