summaryrefslogtreecommitdiffstats
path: root/core/java/android/hardware/camera2
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2014-07-29 18:38:04 -0700
committerIgor Murashkin <iam@google.com>2014-08-06 14:35:40 -0700
commit733341bf0db89c93ee1341ddfca9b0c49731c836 (patch)
treec8378584e47bd0bf0d8e176f4564b38f296e4c86 /core/java/android/hardware/camera2
parentd2a9363208efc721b2ebb8f98a55b4ee08af4a76 (diff)
downloadframeworks_base-733341bf0db89c93ee1341ddfca9b0c49731c836.zip
frameworks_base-733341bf0db89c93ee1341ddfca9b0c49731c836.tar.gz
frameworks_base-733341bf0db89c93ee1341ddfca9b0c49731c836.tar.bz2
camera2: (legacy) Support awb mode, test mode metadata keys
Change-Id: Ic013aa820bbea02a662d546eb9f70baa20c0136e
Diffstat (limited to 'core/java/android/hardware/camera2')
-rw-r--r--core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java71
-rw-r--r--core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java56
-rw-r--r--core/java/android/hardware/camera2/legacy/LegacyResultMapper.java79
3 files changed, 177 insertions, 29 deletions
diff --git a/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java b/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
index 986f9a8..711edf4 100644
--- a/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
+++ b/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
@@ -94,7 +94,7 @@ public class LegacyMetadataMapper {
static final boolean LIE_ABOUT_AF = false;
static final boolean LIE_ABOUT_AF_MAX_REGIONS = false;
static final boolean LIE_ABOUT_AWB_STATE = false;
- static final boolean LIE_ABOUT_AWB = true;
+ static final boolean LIE_ABOUT_AWB = false;
/**
* Create characteristics for a legacy device by mapping the {@code parameters}
@@ -436,8 +436,52 @@ public class LegacyMetadataMapper {
}
private static void mapControlAwb(CameraMetadataNative m, Camera.Parameters p) {
- if (!LIE_ABOUT_AWB) {
- throw new AssertionError("Not implemented yet");
+ /*
+ * control.awbAvailableModes
+ */
+
+ {
+ List<String> wbModes = p.getSupportedWhiteBalance();
+
+ String[] wbModeStrings = new String[] {
+ Camera.Parameters.WHITE_BALANCE_AUTO ,
+ Camera.Parameters.WHITE_BALANCE_INCANDESCENT ,
+ Camera.Parameters.WHITE_BALANCE_FLUORESCENT ,
+ Camera.Parameters.WHITE_BALANCE_WARM_FLUORESCENT ,
+ Camera.Parameters.WHITE_BALANCE_DAYLIGHT ,
+ Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT ,
+ Camera.Parameters.WHITE_BALANCE_TWILIGHT ,
+ Camera.Parameters.WHITE_BALANCE_SHADE ,
+ };
+
+ int[] wbModeInts = new int[] {
+ CONTROL_AWB_MODE_AUTO,
+ CONTROL_AWB_MODE_INCANDESCENT ,
+ CONTROL_AWB_MODE_FLUORESCENT ,
+ CONTROL_AWB_MODE_WARM_FLUORESCENT ,
+ CONTROL_AWB_MODE_DAYLIGHT ,
+ CONTROL_AWB_MODE_CLOUDY_DAYLIGHT ,
+ CONTROL_AWB_MODE_TWILIGHT ,
+ CONTROL_AWB_MODE_SHADE ,
+ // Note that CONTROL_AWB_MODE_OFF is unsupported
+ };
+
+ List<Integer> awbAvail = ArrayUtils.convertStringListToIntList(
+ wbModes, wbModeStrings, wbModeInts);
+
+ // No AWB modes supported? That's unpossible!
+ if (awbAvail == null || awbAvail.size() == 0) {
+ Log.w(TAG, "No AWB modes supported (HAL bug); defaulting to AWB_MODE_AUTO only");
+ awbAvail = new ArrayList<Integer>(/*capacity*/1);
+ awbAvail.add(CONTROL_AWB_MODE_AUTO);
+ }
+
+ m.set(CONTROL_AWB_AVAILABLE_MODES, ArrayUtils.toIntArray(awbAvail));
+
+ if (VERBOSE) {
+ Log.v(TAG, "mapControlAwb - control.awbAvailableModes set to " +
+ ListUtils.listToString(awbAvail));
+ }
}
}
@@ -650,6 +694,11 @@ public class LegacyMetadataMapper {
m.set(REQUEST_MAX_NUM_INPUT_STREAMS, REQUEST_MAX_NUM_INPUT_STREAMS_COUNT);
/*
+ * request.partialResultCount
+ */
+ m.set(REQUEST_PARTIAL_RESULT_COUNT, 1); // No partial results supported
+
+ /*
* request.pipelineMaxDepth
*/
m.set(REQUEST_PIPELINE_MAX_DEPTH,
@@ -680,6 +729,14 @@ public class LegacyMetadataMapper {
}
/*
+ * sensor.availableTestPatternModes
+ */
+ {
+ // Only "OFF" test pattern mode is available
+ m.set(SENSOR_AVAILABLE_TEST_PATTERN_MODES, new int[] { SENSOR_TEST_PATTERN_MODE_OFF });
+ }
+
+ /*
* sensor.info.pixelArraySize
*/
m.set(SENSOR_INFO_PIXEL_ARRAY_SIZE, largestJpegSize);
@@ -921,11 +978,9 @@ public class LegacyMetadataMapper {
* control.*
*/
- if (LIE_ABOUT_AWB) {
- m.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_AUTO);
- } else {
- throw new AssertionError("Valid control.awbMode not implemented yet");
- }
+ // control.awbMode
+ m.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_AUTO);
+ // AWB is always unconditionally available in API1 devices
// control.aeAntibandingMode
m.set(CaptureRequest.CONTROL_AE_ANTIBANDING_MODE, CONTROL_AE_ANTIBANDING_MODE_AUTO);
diff --git a/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java b/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java
index dfec9008..a6fe035 100644
--- a/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java
+++ b/core/java/android/hardware/camera2/legacy/LegacyRequestMapper.java
@@ -216,6 +216,25 @@ public class LegacyRequestMapper {
}
}
+ // control.awbMode
+ {
+ Integer awbMode = getIfSupported(request, CONTROL_AWB_MODE,
+ /*defaultValue*/CONTROL_AWB_MODE_AUTO,
+ params.getSupportedWhiteBalance() != null,
+ /*allowedValue*/CONTROL_AWB_MODE_AUTO);
+
+ String whiteBalanceMode = null;
+ if (awbMode != null) { // null iff AWB is not supported by camera1 api
+ whiteBalanceMode = convertAwbModeToLegacy(awbMode);
+ params.setWhiteBalance(whiteBalanceMode);
+ }
+
+ if (VERBOSE) {
+ Log.v(TAG, "convertRequestToMetadata - control.awbMode "
+ + awbMode + " mapped to " + whiteBalanceMode);
+ }
+ }
+
// control.awbLock
{
Boolean awbLock = getIfSupported(request, CONTROL_AWB_LOCK, /*defaultValue*/false,
@@ -294,6 +313,20 @@ public class LegacyRequestMapper {
}
}
}
+
+ /*
+ * sensor
+ */
+
+ // sensor.testPattern
+ {
+ int testPatternMode = ParamsUtils.getOrDefault(request, SENSOR_TEST_PATTERN_MODE,
+ /*defaultValue*/SENSOR_TEST_PATTERN_MODE_OFF);
+ if (testPatternMode != SENSOR_TEST_PATTERN_MODE_OFF) {
+ Log.w(TAG, "convertRequestToMetadata - ignoring sensor.testPatternMode "
+ + testPatternMode + "; only OFF is supported");
+ }
+ }
}
private static List<Camera.Area> convertMeteringRegionsToLegacy(
@@ -445,6 +478,29 @@ public class LegacyRequestMapper {
return legacyFps;
}
+ private static String convertAwbModeToLegacy(int mode) {
+ switch (mode) {
+ case CONTROL_AWB_MODE_AUTO:
+ return Camera.Parameters.WHITE_BALANCE_AUTO;
+ case CONTROL_AWB_MODE_INCANDESCENT:
+ return Camera.Parameters.WHITE_BALANCE_INCANDESCENT;
+ case CONTROL_AWB_MODE_FLUORESCENT:
+ return Camera.Parameters.WHITE_BALANCE_FLUORESCENT;
+ case CONTROL_AWB_MODE_WARM_FLUORESCENT:
+ return Camera.Parameters.WHITE_BALANCE_WARM_FLUORESCENT;
+ case CONTROL_AWB_MODE_DAYLIGHT:
+ return Camera.Parameters.WHITE_BALANCE_DAYLIGHT;
+ case CONTROL_AWB_MODE_CLOUDY_DAYLIGHT:
+ return Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT;
+ case CONTROL_AWB_MODE_TWILIGHT:
+ return Camera.Parameters.WHITE_BALANCE_TWILIGHT;
+ default:
+ Log.w(TAG, "convertAwbModeToLegacy - unrecognized control.awbMode" + mode);
+ return Camera.Parameters.WHITE_BALANCE_AUTO;
+ }
+ }
+
+
/**
* Return {@code null} if the value is not supported, otherwise return the retrieved key's
* value from the request (or the default value if it wasn't set).
diff --git a/core/java/android/hardware/camera2/legacy/LegacyResultMapper.java b/core/java/android/hardware/camera2/legacy/LegacyResultMapper.java
index 6da5dd0..9eff943 100644
--- a/core/java/android/hardware/camera2/legacy/LegacyResultMapper.java
+++ b/core/java/android/hardware/camera2/legacy/LegacyResultMapper.java
@@ -20,7 +20,6 @@ import android.graphics.Rect;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.camera2.CameraCharacteristics;
-import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.CaptureResult;
import android.hardware.camera2.impl.CameraMetadataNative;
@@ -133,26 +132,15 @@ public class LegacyResultMapper {
*/
mapAe(result, characteristics, request, activeArraySize, zoomData, /*out*/params);
- // control.afMode
- result.set(CaptureResult.CONTROL_AF_MODE, convertLegacyAfMode(params.getFocusMode()));
-
- // control.awbLock
- result.set(CaptureResult.CONTROL_AWB_LOCK, params.getAutoWhiteBalanceLock());
-
- // control.awbState
- if (LegacyMetadataMapper.LIE_ABOUT_AWB_STATE) {
- // Lie to pass CTS temporarily.
- // TODO: CTS needs to be updated not to query this value
- // for LIMITED devices unless its guaranteed to be available.
- result.set(CaptureResult.CONTROL_AWB_STATE,
- CameraMetadata.CONTROL_AWB_STATE_CONVERGED);
- // TODO: Read the awb mode from parameters instead
- }
+ /*
+ * control.af*
+ */
+ mapAf(result, activeArraySize, zoomData, /*out*/params);
- if (LegacyMetadataMapper.LIE_ABOUT_AWB) {
- result.set(CaptureResult.CONTROL_AWB_MODE,
- request.get(CaptureRequest.CONTROL_AWB_MODE));
- }
+ /*
+ * control.awb*
+ */
+ mapAwb(result, /*out*/params);
/*
@@ -203,7 +191,7 @@ public class LegacyResultMapper {
* flash
*/
{
- // TODO
+ // flash.mode, flash.state mapped in mapAeAndFlashMode
}
/*
@@ -234,6 +222,11 @@ public class LegacyResultMapper {
/*
* sensor
*/
+ // sensor.timestamp varies every frame; mapping is done in #cachedConvertResultMetadata
+ {
+ // Unconditionally no test patterns
+ result.set(SENSOR_TEST_PATTERN_MODE, SENSOR_TEST_PATTERN_MODE_OFF);
+ }
// TODO: Remaining result metadata tags conversions.
return result;
@@ -295,6 +288,13 @@ public class LegacyResultMapper {
m.set(CONTROL_AE_REGIONS, meteringRectArray);
}
+ }
+
+ private static void mapAf(CameraMetadataNative m,
+ Rect activeArray, ZoomData zoomData, Camera.Parameters p) {
+ // control.afMode
+ m.set(CaptureResult.CONTROL_AF_MODE, convertLegacyAfMode(p.getFocusMode()));
+
// control.afRegions
{
if (VERBOSE) {
@@ -307,13 +307,21 @@ public class LegacyResultMapper {
m.set(CONTROL_AF_REGIONS, meteringRectArray);
}
+ }
+ private static void mapAwb(CameraMetadataNative m, Camera.Parameters p) {
// control.awbLock
{
boolean lock = p.isAutoWhiteBalanceLockSupported() ?
p.getAutoWhiteBalanceLock() : false;
m.set(CONTROL_AWB_LOCK, lock);
}
+
+ // control.awbMode
+ {
+ int awbMode = convertLegacyAwbMode(p.getWhiteBalance());
+ m.set(CONTROL_AWB_MODE, awbMode);
+ }
}
private static MeteringRectangle[] getMeteringRectangles(Rect activeArray, ZoomData zoomData,
@@ -412,6 +420,35 @@ public class LegacyResultMapper {
}
}
+ private static int convertLegacyAwbMode(String mode) {
+ if (mode == null) {
+ // OK: camera1 api may not support changing WB modes; assume AUTO
+ return CONTROL_AWB_MODE_AUTO;
+ }
+
+ switch (mode) {
+ case Camera.Parameters.WHITE_BALANCE_AUTO:
+ return CONTROL_AWB_MODE_AUTO;
+ case Camera.Parameters.WHITE_BALANCE_INCANDESCENT:
+ return CONTROL_AWB_MODE_INCANDESCENT;
+ case Camera.Parameters.WHITE_BALANCE_FLUORESCENT:
+ return CONTROL_AWB_MODE_FLUORESCENT;
+ case Camera.Parameters.WHITE_BALANCE_WARM_FLUORESCENT:
+ return CONTROL_AWB_MODE_WARM_FLUORESCENT;
+ case Camera.Parameters.WHITE_BALANCE_DAYLIGHT:
+ return CONTROL_AWB_MODE_DAYLIGHT;
+ case Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT:
+ return CONTROL_AWB_MODE_CLOUDY_DAYLIGHT;
+ case Camera.Parameters.WHITE_BALANCE_TWILIGHT:
+ return CONTROL_AWB_MODE_TWILIGHT;
+ case Camera.Parameters.WHITE_BALANCE_SHADE:
+ return CONTROL_AWB_MODE_SHADE;
+ default:
+ Log.w(TAG, "convertAwbMode - unrecognized WB mode " + mode);
+ return CONTROL_AWB_MODE_AUTO;
+ }
+ }
+
/** Map results for scaler.* */
private static void mapScaler(CameraMetadataNative m,
ZoomData zoomData,