Skip to content

Commit 7336f47

Browse files
committed
camera: (LEGACY) - Add captureIntent and physicalSize metadata
Bug: 16900182 Change-Id: I159f2416da71c2d7ea803d61b63476da90e03b1c
1 parent 8c4486c commit 7336f47

3 files changed

Lines changed: 84 additions & 1 deletion

File tree

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import android.util.Log;
3737
import android.util.Range;
3838
import android.util.Size;
39+
import android.util.SizeF;
3940

4041
import java.util.ArrayList;
4142
import java.util.Arrays;
@@ -764,6 +765,23 @@ private static void mapSensor(CameraMetadataNative m, Parameters p) {
764765
* sensor.info.pixelArraySize
765766
*/
766767
m.set(SENSOR_INFO_PIXEL_ARRAY_SIZE, largestJpegSize);
768+
769+
/*
770+
* sensor.info.physicalSize
771+
*/
772+
{
773+
/*
774+
* Assume focal length is at infinity focus and that the lens is rectilinear.
775+
*/
776+
float focalLength = p.getFocalLength(); // in mm
777+
double angleHor = p.getHorizontalViewAngle() * Math.PI / 180; // to radians
778+
double angleVer = p.getVerticalViewAngle() * Math.PI / 180; // to radians
779+
780+
float height = (float)Math.abs(2 * focalLength * Math.tan(angleVer / 2));
781+
float width = (float)Math.abs(2 * focalLength * Math.tan(angleHor / 2));
782+
783+
m.set(SENSOR_INFO_PHYSICAL_SIZE, new SizeF(width, height)); // in mm
784+
}
767785
}
768786

769787
private static void mapStatistics(CameraMetadataNative m, Parameters p) {
@@ -1069,7 +1087,24 @@ public static CameraMetadataNative createRequestTemplate(
10691087
}
10701088

10711089
// control.captureIntent
1072-
m.set(CaptureRequest.CONTROL_CAPTURE_INTENT, templateId);
1090+
{
1091+
int captureIntent;
1092+
switch (templateId) {
1093+
case CameraDevice.TEMPLATE_PREVIEW:
1094+
captureIntent = CONTROL_CAPTURE_INTENT_PREVIEW;
1095+
break;
1096+
case CameraDevice.TEMPLATE_STILL_CAPTURE:
1097+
captureIntent = CONTROL_CAPTURE_INTENT_STILL_CAPTURE;
1098+
break;
1099+
case CameraDevice.TEMPLATE_RECORD:
1100+
captureIntent = CONTROL_CAPTURE_INTENT_VIDEO_RECORD;
1101+
break;
1102+
default:
1103+
// Can't get anything else since it's guarded by the IAE check
1104+
throw new AssertionError("Impossible; keep in sync with sAllowedTemplates");
1105+
}
1106+
m.set(CaptureRequest.CONTROL_CAPTURE_INTENT, captureIntent);
1107+
}
10731108

10741109
// control.aeMode
10751110
m.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,19 @@ public static void convertRequestMetadata(LegacyRequest legacyRequest) {
246246
// TODO: Don't add control.awbLock to availableRequestKeys if it's not supported
247247
}
248248

249+
// control.captureIntent
250+
{
251+
int captureIntent = ParamsUtils.getOrDefault(request,
252+
CONTROL_CAPTURE_INTENT,
253+
/*defaultValue*/CONTROL_CAPTURE_INTENT_PREVIEW);
254+
255+
captureIntent = filterSupportedCaptureIntent(captureIntent);
256+
257+
params.setRecordingHint(
258+
captureIntent == CONTROL_CAPTURE_INTENT_VIDEO_RECORD ||
259+
captureIntent == CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT);
260+
}
261+
249262
// control.videoStabilizationMode
250263
{
251264
Integer stabMode = getIfSupported(request, CONTROL_VIDEO_STABILIZATION_MODE,
@@ -339,6 +352,28 @@ public static void convertRequestMetadata(LegacyRequest legacyRequest) {
339352
}
340353
}
341354

355+
static int filterSupportedCaptureIntent(int captureIntent) {
356+
switch (captureIntent) {
357+
case CONTROL_CAPTURE_INTENT_CUSTOM:
358+
case CONTROL_CAPTURE_INTENT_PREVIEW:
359+
case CONTROL_CAPTURE_INTENT_STILL_CAPTURE:
360+
case CONTROL_CAPTURE_INTENT_VIDEO_RECORD:
361+
case CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT:
362+
break;
363+
case CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG:
364+
case CONTROL_CAPTURE_INTENT_MANUAL:
365+
captureIntent = CONTROL_CAPTURE_INTENT_PREVIEW;
366+
Log.w(TAG, "Unsupported control.captureIntent value " + captureIntent
367+
+ "; default to PREVIEW");
368+
default:
369+
captureIntent = CONTROL_CAPTURE_INTENT_PREVIEW;
370+
Log.w(TAG, "Unknown control.captureIntent value " + captureIntent
371+
+ "; default to PREVIEW");
372+
}
373+
374+
return captureIntent;
375+
}
376+
342377
private static List<Camera.Area> convertMeteringRegionsToLegacy(
343378
Rect activeArray, ParameterUtils.ZoomData zoomData,
344379
MeteringRectangle[] meteringRegions, int maxNumMeteringAreas, String regionName) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ private static CameraMetadataNative convertResultMetadata(LegacyRequest legacyRe
142142
*/
143143
mapAwb(result, /*out*/params);
144144

145+
/*
146+
* control.captureIntent
147+
*/
148+
{
149+
int captureIntent = ParamsUtils.getOrDefault(request,
150+
CaptureRequest.CONTROL_CAPTURE_INTENT,
151+
/*defaultValue*/CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW);
152+
153+
captureIntent = LegacyRequestMapper.filterSupportedCaptureIntent(captureIntent);
154+
155+
result.set(CONTROL_CAPTURE_INTENT, captureIntent);
156+
}
157+
145158
/*
146159
* control.mode
147160
*/

0 commit comments

Comments
 (0)