From 574936894d3044445a272b39f2d925af40ece5d8 Mon Sep 17 00:00:00 2001 From: Ruben Brunk Date: Tue, 27 May 2014 18:58:08 -0700 Subject: camera2: Update native/managed key mappings. Switches to using managed value classes for the following keys: - android.sensor.info.sensitivityRange - android.sensor.info.exposureTimeRange - android.jpeg.gpsCoordinates - android.jpeg.gpsTimestamp - android.jpeg.gpsProcessingMethod - android.statistics.lensShadingMap - android.lens.info.shadingMapSize Also fixes a minor bug in LensShadingMap Bug: 14628001 Change-Id: Ia0f541242f529ab9ba3111db799306b198f2b40b --- api/current.txt | 11 +-- .../hardware/camera2/CameraCharacteristics.java | 12 +-- .../android/hardware/camera2/CameraManager.java | 4 +- .../android/hardware/camera2/CameraMetadata.java | 6 +- .../android/hardware/camera2/CaptureRequest.java | 23 +++-- .../android/hardware/camera2/CaptureResult.java | 78 ++++++++++++++--- .../hardware/camera2/impl/CameraDevice.java | 18 +++- .../camera2/impl/CameraMetadataNative.java | 99 +++++++++++++++++++++- .../hardware/camera2/params/LensShadingMap.java | 8 +- 9 files changed, 211 insertions(+), 48 deletions(-) diff --git a/api/current.txt b/api/current.txt index 3e6ad72e2d08..441ad2683abd 100644 --- a/api/current.txt +++ b/api/current.txt @@ -12165,7 +12165,6 @@ package android.hardware.camera2 { field public static final android.hardware.camera2.CameraCharacteristics.Key LENS_INFO_FOCUS_DISTANCE_CALIBRATION; field public static final android.hardware.camera2.CameraCharacteristics.Key LENS_INFO_HYPERFOCAL_DISTANCE; field public static final android.hardware.camera2.CameraCharacteristics.Key LENS_INFO_MINIMUM_FOCUS_DISTANCE; - field public static final android.hardware.camera2.CameraCharacteristics.Key LENS_INFO_SHADING_MAP_SIZE; field public static final android.hardware.camera2.CameraCharacteristics.Key NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES; field public static final android.hardware.camera2.CameraCharacteristics.Key REQUEST_AVAILABLE_CAPABILITIES; field public static final android.hardware.camera2.CameraCharacteristics.Key REQUEST_MAX_NUM_INPUT_STREAMS; @@ -12484,9 +12483,7 @@ package android.hardware.camera2 { field public static final android.hardware.camera2.CaptureRequest.Key EDGE_MODE; field public static final android.hardware.camera2.CaptureRequest.Key FLASH_MODE; field public static final android.hardware.camera2.CaptureRequest.Key HOT_PIXEL_MODE; - field public static final android.hardware.camera2.CaptureRequest.Key JPEG_GPS_COORDINATES; - field public static final android.hardware.camera2.CaptureRequest.Key JPEG_GPS_PROCESSING_METHOD; - field public static final android.hardware.camera2.CaptureRequest.Key JPEG_GPS_TIMESTAMP; + field public static final android.hardware.camera2.CaptureRequest.Key JPEG_GPS_LOCATION; field public static final android.hardware.camera2.CaptureRequest.Key JPEG_ORIENTATION; field public static final android.hardware.camera2.CaptureRequest.Key JPEG_QUALITY; field public static final android.hardware.camera2.CaptureRequest.Key JPEG_THUMBNAIL_QUALITY; @@ -12560,9 +12557,7 @@ package android.hardware.camera2 { field public static final android.hardware.camera2.CaptureResult.Key FLASH_MODE; field public static final android.hardware.camera2.CaptureResult.Key FLASH_STATE; field public static final android.hardware.camera2.CaptureResult.Key HOT_PIXEL_MODE; - field public static final android.hardware.camera2.CaptureResult.Key JPEG_GPS_COORDINATES; - field public static final android.hardware.camera2.CaptureResult.Key JPEG_GPS_PROCESSING_METHOD; - field public static final android.hardware.camera2.CaptureResult.Key JPEG_GPS_TIMESTAMP; + field public static final android.hardware.camera2.CaptureResult.Key JPEG_GPS_LOCATION; field public static final android.hardware.camera2.CaptureResult.Key JPEG_ORIENTATION; field public static final android.hardware.camera2.CaptureResult.Key JPEG_QUALITY; field public static final android.hardware.camera2.CaptureResult.Key JPEG_THUMBNAIL_QUALITY; @@ -12591,7 +12586,7 @@ package android.hardware.camera2 { field public static final android.hardware.camera2.CaptureResult.Key STATISTICS_FACE_DETECT_MODE; field public static final android.hardware.camera2.CaptureResult.Key STATISTICS_HOT_PIXEL_MAP; field public static final android.hardware.camera2.CaptureResult.Key STATISTICS_HOT_PIXEL_MAP_MODE; - field public static final android.hardware.camera2.CaptureResult.Key STATISTICS_LENS_SHADING_MAP; + field public static final android.hardware.camera2.CaptureResult.Key STATISTICS_LENS_SHADING_CORRECTION_MAP; field public static final android.hardware.camera2.CaptureResult.Key STATISTICS_LENS_SHADING_MAP_MODE; field public static final android.hardware.camera2.CaptureResult.Key STATISTICS_SCENE_FLICKER; field public static final android.hardware.camera2.CaptureResult.Key TONEMAP_CURVE; diff --git a/core/java/android/hardware/camera2/CameraCharacteristics.java b/core/java/android/hardware/camera2/CameraCharacteristics.java index 1a05b98144bc..eb8d402c06fc 100644 --- a/core/java/android/hardware/camera2/CameraCharacteristics.java +++ b/core/java/android/hardware/camera2/CameraCharacteristics.java @@ -587,6 +587,7 @@ public final class CameraCharacteristics extends CameraMetadataDimensions of lens shading map.

*

The map should be on the order of 30-40 rows and columns, and * must be smaller than 64x64.

+ * @hide */ public static final Key LENS_INFO_SHADING_MAP_SIZE = new Key("android.lens.info.shadingMapSize", android.util.Size.class); @@ -852,7 +853,7 @@ public final class CameraCharacteristics extends CameraMetadata *

The following keys may return null unless they are enabled:

*
    - *
  • {@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap} (non-null iff {@link CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE android.statistics.lensShadingMapMode} == ON)
  • + *
  • android.statistics.lensShadingMap (non-null iff {@link CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE android.statistics.lensShadingMapMode} == ON)
  • *
*

(Those sometimes-null keys should nevertheless be listed here * if they are available.)

@@ -863,7 +864,6 @@ public final class CameraCharacteristics extends CameraMetadataTODO: This should be used by #getAvailableCaptureResultKeys.

* * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES - * @see CaptureResult#STATISTICS_LENS_SHADING_MAP * @see CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE * @hide */ @@ -1331,8 +1331,8 @@ public final class CameraCharacteristics extends CameraMetadataRange of valid sensitivities

*/ - public static final Key SENSOR_INFO_SENSITIVITY_RANGE = - new Key("android.sensor.info.sensitivityRange", int[].class); + public static final Key> SENSOR_INFO_SENSITIVITY_RANGE = + new Key>("android.sensor.info.sensitivityRange", new TypeReference>() {{ }}); /** *

Arrangement of color filters on sensor; @@ -1353,8 +1353,8 @@ public final class CameraCharacteristics extends CameraMetadata SENSOR_INFO_EXPOSURE_TIME_RANGE = - new Key("android.sensor.info.exposureTimeRange", long[].class); + public static final Key> SENSOR_INFO_EXPOSURE_TIME_RANGE = + new Key>("android.sensor.info.exposureTimeRange", new TypeReference>() {{ }}); /** *

Maximum possible frame duration (minimum frame diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java index 03b342c03ff5..83db056dc771 100644 --- a/core/java/android/hardware/camera2/CameraManager.java +++ b/core/java/android/hardware/camera2/CameraManager.java @@ -220,6 +220,7 @@ public final class CameraManager { private CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateListener listener, Handler handler) throws CameraAccessException { + CameraCharacteristics characteristics = getCameraCharacteristics(cameraId); CameraDevice device = null; try { @@ -231,7 +232,8 @@ public final class CameraManager { new android.hardware.camera2.impl.CameraDevice( cameraId, listener, - handler); + handler, + characteristics); BinderHolder holder = new BinderHolder(); diff --git a/core/java/android/hardware/camera2/CameraMetadata.java b/core/java/android/hardware/camera2/CameraMetadata.java index 86c691f97855..27b4fb8ee6b1 100644 --- a/core/java/android/hardware/camera2/CameraMetadata.java +++ b/core/java/android/hardware/camera2/CameraMetadata.java @@ -290,8 +290,8 @@ public abstract class CameraMetadata { * * *

  • Lens shading map information
      - *
    • {@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap}
    • - *
    • {@link CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE android.lens.info.shadingMapSize}
    • + *
    • android.statistics.lensShadingMap
    • + *
    • android.lens.info.shadingMapSize
    • *
    *
  • * @@ -302,8 +302,6 @@ public abstract class CameraMetadata { * * @see CaptureRequest#COLOR_CORRECTION_GAINS * @see CaptureRequest#COLOR_CORRECTION_TRANSFORM - * @see CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE - * @see CaptureResult#STATISTICS_LENS_SHADING_MAP * @see CaptureRequest#TONEMAP_CURVE * @see CameraCharacteristics#TONEMAP_MAX_CURVE_POINTS * @see CaptureRequest#TONEMAP_MODE diff --git a/core/java/android/hardware/camera2/CaptureRequest.java b/core/java/android/hardware/camera2/CaptureRequest.java index 9d490ca0d7f6..79659f1f5239 100644 --- a/core/java/android/hardware/camera2/CaptureRequest.java +++ b/core/java/android/hardware/camera2/CaptureRequest.java @@ -1051,9 +1051,16 @@ public final class CaptureRequest extends CameraMetadata> public static final Key HOT_PIXEL_MODE = new Key("android.hotPixel.mode", int.class); + /** + *

    A location object to use when generating image GPS metadata.

    + */ + public static final Key JPEG_GPS_LOCATION = + new Key("android.jpeg.gpsLocation", android.location.Location.class); + /** *

    GPS coordinates to include in output JPEG * EXIF

    + * @hide */ public static final Key JPEG_GPS_COORDINATES = new Key("android.jpeg.gpsCoordinates", double[].class); @@ -1061,6 +1068,7 @@ public final class CaptureRequest extends CameraMetadata> /** *

    32 characters describing GPS algorithm to * include in EXIF

    + * @hide */ public static final Key JPEG_GPS_PROCESSING_METHOD = new Key("android.jpeg.gpsProcessingMethod", String.class); @@ -1068,6 +1076,7 @@ public final class CaptureRequest extends CameraMetadata> /** *

    Time GPS fix was made to include in * EXIF

    + * @hide */ public static final Key JPEG_GPS_TIMESTAMP = new Key("android.jpeg.gpsTimestamp", long.class); @@ -1416,8 +1425,8 @@ public final class CaptureRequest extends CameraMetadata> *

    When set to OFF mode, no lens shading correction will be applied by the * camera device, and an identity lens shading map data will be provided * if {@link CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE android.statistics.lensShadingMapMode} == ON. For example, for lens - * shading map with size specified as {@link CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE android.lens.info.shadingMapSize} = [ 4, 3 ], - * the output {@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap} for this case will be an identity map + * shading map with size specified as android.lens.info.shadingMapSize = [ 4, 3 ], + * the output android.statistics.lensShadingMap for this case will be an identity map * shown below:

    *
    [ 1.0, 1.0, 1.0, 1.0,  1.0, 1.0, 1.0, 1.0,
          * 1.0, 1.0, 1.0, 1.0,  1.0, 1.0, 1.0, 1.0,
    @@ -1429,8 +1438,8 @@ public final class CaptureRequest extends CameraMetadata>
          * 

    When set to other modes, lens shading correction will be applied by the * camera device. Applications can request lens shading map data by setting * {@link CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE android.statistics.lensShadingMapMode} to ON, and then the camera device will provide - * lens shading map data in {@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap}, with size specified - * by {@link CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE android.lens.info.shadingMapSize}; the returned shading map data will be the one + * lens shading map data in android.statistics.lensShadingMap, with size specified + * by android.lens.info.shadingMapSize; the returned shading map data will be the one * applied by the camera device for this capture request.

    *

    The shading map data may depend on the AE and AWB statistics, therefore the reliability * of the map data may be affected by the AE and AWB algorithms. When AE and AWB are in @@ -1440,8 +1449,6 @@ public final class CaptureRequest extends CameraMetadata> * * @see CaptureRequest#CONTROL_AE_MODE * @see CaptureRequest#CONTROL_AWB_MODE - * @see CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE - * @see CaptureResult#STATISTICS_LENS_SHADING_MAP * @see CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE * @see #SHADING_MODE_OFF * @see #SHADING_MODE_FAST @@ -1482,10 +1489,8 @@ public final class CaptureRequest extends CameraMetadata> *

    Whether the camera device will output the lens * shading map in output result metadata.

    *

    When set to ON, - * {@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap} must be provided in + * android.statistics.lensShadingMap must be provided in * the output result metadata.

    - * - * @see CaptureResult#STATISTICS_LENS_SHADING_MAP * @see #STATISTICS_LENS_SHADING_MAP_MODE_OFF * @see #STATISTICS_LENS_SHADING_MAP_MODE_ON */ diff --git a/core/java/android/hardware/camera2/CaptureResult.java b/core/java/android/hardware/camera2/CaptureResult.java index 51180e8f2c62..aa202acc0512 100644 --- a/core/java/android/hardware/camera2/CaptureResult.java +++ b/core/java/android/hardware/camera2/CaptureResult.java @@ -1639,9 +1639,16 @@ public class CaptureResult extends CameraMetadata> { public static final Key HOT_PIXEL_MODE = new Key("android.hotPixel.mode", int.class); + /** + *

    A location object to use when generating image GPS metadata.

    + */ + public static final Key JPEG_GPS_LOCATION = + new Key("android.jpeg.gpsLocation", android.location.Location.class); + /** *

    GPS coordinates to include in output JPEG * EXIF

    + * @hide */ public static final Key JPEG_GPS_COORDINATES = new Key("android.jpeg.gpsCoordinates", double[].class); @@ -1649,6 +1656,7 @@ public class CaptureResult extends CameraMetadata> { /** *

    32 characters describing GPS algorithm to * include in EXIF

    + * @hide */ public static final Key JPEG_GPS_PROCESSING_METHOD = new Key("android.jpeg.gpsProcessingMethod", String.class); @@ -1656,6 +1664,7 @@ public class CaptureResult extends CameraMetadata> { /** *

    Time GPS fix was made to include in * EXIF

    + * @hide */ public static final Key JPEG_GPS_TIMESTAMP = new Key("android.jpeg.gpsTimestamp", long.class); @@ -2145,8 +2154,8 @@ public class CaptureResult extends CameraMetadata> { *

    When set to OFF mode, no lens shading correction will be applied by the * camera device, and an identity lens shading map data will be provided * if {@link CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE android.statistics.lensShadingMapMode} == ON. For example, for lens - * shading map with size specified as {@link CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE android.lens.info.shadingMapSize} = [ 4, 3 ], - * the output {@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap} for this case will be an identity map + * shading map with size specified as android.lens.info.shadingMapSize = [ 4, 3 ], + * the output android.statistics.lensShadingMap for this case will be an identity map * shown below:

    *
    [ 1.0, 1.0, 1.0, 1.0,  1.0, 1.0, 1.0, 1.0,
          * 1.0, 1.0, 1.0, 1.0,  1.0, 1.0, 1.0, 1.0,
    @@ -2158,8 +2167,8 @@ public class CaptureResult extends CameraMetadata> {
          * 

    When set to other modes, lens shading correction will be applied by the * camera device. Applications can request lens shading map data by setting * {@link CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE android.statistics.lensShadingMapMode} to ON, and then the camera device will provide - * lens shading map data in {@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap}, with size specified - * by {@link CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE android.lens.info.shadingMapSize}; the returned shading map data will be the one + * lens shading map data in android.statistics.lensShadingMap, with size specified + * by android.lens.info.shadingMapSize; the returned shading map data will be the one * applied by the camera device for this capture request.

    *

    The shading map data may depend on the AE and AWB statistics, therefore the reliability * of the map data may be affected by the AE and AWB algorithms. When AE and AWB are in @@ -2169,8 +2178,6 @@ public class CaptureResult extends CameraMetadata> { * * @see CaptureRequest#CONTROL_AE_MODE * @see CaptureRequest#CONTROL_AWB_MODE - * @see CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE - * @see CaptureResult#STATISTICS_LENS_SHADING_MAP * @see CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE * @see #SHADING_MODE_OFF * @see #SHADING_MODE_FAST @@ -2242,6 +2249,52 @@ public class CaptureResult extends CameraMetadata> { public static final Key STATISTICS_FACES = new Key("android.statistics.faces", android.hardware.camera2.params.Face[].class); + /** + *

    The shading map is a low-resolution floating-point map + * that lists the coefficients used to correct for vignetting, for each + * Bayer color channel.

    + *

    The least shaded section of the image should have a gain factor + * of 1; all other sections should have gains above 1.

    + *

    When {@link CaptureRequest#COLOR_CORRECTION_MODE android.colorCorrection.mode} = TRANSFORM_MATRIX, the map + * must take into account the colorCorrection settings.

    + *

    The shading map is for the entire active pixel array, and is not + * affected by the crop region specified in the request. Each shading map + * entry is the value of the shading compensation map over a specific + * pixel on the sensor. Specifically, with a (N x M) resolution shading + * map, and an active pixel array size (W x H), shading map entry + * (x,y) ϵ (0 ... N-1, 0 ... M-1) is the value of the shading map at + * pixel ( ((W-1)/(N-1)) * x, ((H-1)/(M-1)) * y) for the four color channels. + * The map is assumed to be bilinearly interpolated between the sample points.

    + *

    The channel order is [R, Geven, Godd, B], where Geven is the green + * channel for the even rows of a Bayer pattern, and Godd is the odd rows. + * The shading map is stored in a fully interleaved format.

    + *

    The shading map should have on the order of 30-40 rows and columns, + * and must be smaller than 64x64.

    + *

    As an example, given a very small map defined as:

    + *
    width,height = [ 4, 3 ]
    +     * values =
    +     * [ 1.3, 1.2, 1.15, 1.2,  1.2, 1.2, 1.15, 1.2,
    +     * 1.1, 1.2, 1.2, 1.2,  1.3, 1.2, 1.3, 1.3,
    +     * 1.2, 1.2, 1.25, 1.1,  1.1, 1.1, 1.1, 1.0,
    +     * 1.0, 1.0, 1.0, 1.0,  1.2, 1.3, 1.25, 1.2,
    +     * 1.3, 1.2, 1.2, 1.3,   1.2, 1.15, 1.1, 1.2,
    +     * 1.2, 1.1, 1.0, 1.2,  1.3, 1.15, 1.2, 1.3 ]
    +     * 
    + *

    The low-resolution scaling map images for each channel are + * (displayed using nearest-neighbor interpolation):

    + *

    Red lens shading map + * Green (even rows) lens shading map + * Green (odd rows) lens shading map + * Blue lens shading map

    + *

    As a visualization only, inverting the full-color map to recover an + * image of a gray wall (using bicubic interpolation for visual quality) as captured by the sensor gives:

    + *

    Image of a uniform white wall (inverse shading map)

    + * + * @see CaptureRequest#COLOR_CORRECTION_MODE + */ + public static final Key STATISTICS_LENS_SHADING_CORRECTION_MAP = + new Key("android.statistics.lensShadingCorrectionMap", android.hardware.camera2.params.LensShadingMap.class); + /** *

    The shading map is a low-resolution floating-point map * that lists the coefficients used to correct for vignetting, for each @@ -2261,12 +2314,12 @@ public class CaptureResult extends CameraMetadata> { *

    The channel order is [R, Geven, Godd, B], where Geven is the green * channel for the even rows of a Bayer pattern, and Godd is the odd rows. * The shading map is stored in a fully interleaved format, and its size - * is provided in the camera static metadata by {@link CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE android.lens.info.shadingMapSize}.

    + * is provided in the camera static metadata by android.lens.info.shadingMapSize.

    *

    The shading map should have on the order of 30-40 rows and columns, * and must be smaller than 64x64.

    *

    As an example, given a very small map defined as:

    - *
    {@link CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE android.lens.info.shadingMapSize} = [ 4, 3 ]
    -     * {@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap} =
    +     * 
    android.lens.info.shadingMapSize = [ 4, 3 ]
    +     * android.statistics.lensShadingMap =
          * [ 1.3, 1.2, 1.15, 1.2,  1.2, 1.2, 1.15, 1.2,
          * 1.1, 1.2, 1.2, 1.2,  1.3, 1.2, 1.3, 1.3,
          * 1.2, 1.2, 1.25, 1.1,  1.1, 1.1, 1.1, 1.0,
    @@ -2285,8 +2338,7 @@ public class CaptureResult extends CameraMetadata> {
          * 

    Image of a uniform white wall (inverse shading map)

    * * @see CaptureRequest#COLOR_CORRECTION_MODE - * @see CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE - * @see CaptureResult#STATISTICS_LENS_SHADING_MAP + * @hide */ public static final Key STATISTICS_LENS_SHADING_MAP = new Key("android.statistics.lensShadingMap", float[].class); @@ -2393,10 +2445,8 @@ public class CaptureResult extends CameraMetadata> { *

    Whether the camera device will output the lens * shading map in output result metadata.

    *

    When set to ON, - * {@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap} must be provided in + * android.statistics.lensShadingMap must be provided in * the output result metadata.

    - * - * @see CaptureResult#STATISTICS_LENS_SHADING_MAP * @see #STATISTICS_LENS_SHADING_MAP_MODE_OFF * @see #STATISTICS_LENS_SHADING_MAP_MODE_ON */ diff --git a/core/java/android/hardware/camera2/impl/CameraDevice.java b/core/java/android/hardware/camera2/impl/CameraDevice.java index 7b249766a977..9a4c53155704 100644 --- a/core/java/android/hardware/camera2/impl/CameraDevice.java +++ b/core/java/android/hardware/camera2/impl/CameraDevice.java @@ -20,6 +20,8 @@ import static android.hardware.camera2.CameraAccessException.CAMERA_IN_USE; import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraCaptureSession; +import android.hardware.camera2.CameraCharacteristics; +import android.hardware.camera2.CameraManager; import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.CaptureResult; import android.hardware.camera2.ICameraDeviceCallbacks; @@ -73,6 +75,7 @@ public class CameraDevice implements android.hardware.camera2.CameraDevice { private final SparseArray mConfiguredOutputs = new SparseArray(); private final String mCameraId; + private final CameraCharacteristics mCharacteristics; /** * A list tracking request and its expected last frame. @@ -151,13 +154,15 @@ public class CameraDevice implements android.hardware.camera2.CameraDevice { } }; - public CameraDevice(String cameraId, StateListener listener, Handler handler) { + public CameraDevice(String cameraId, StateListener listener, Handler handler, + CameraCharacteristics characteristics) { if (cameraId == null || listener == null || handler == null) { throw new IllegalArgumentException("Null argument given"); } mCameraId = cameraId; mDeviceListener = listener; mDeviceHandler = handler; + mCharacteristics = characteristics; final int MAX_TAG_LEN = 23; String tag = String.format("CameraDevice-JV-%s", mCameraId); @@ -851,11 +856,18 @@ public class CameraDevice implements android.hardware.camera2.CameraDevice { @Override public void onResultReceived(CameraMetadataNative result, CaptureResultExtras resultExtras) throws RemoteException { + int requestId = resultExtras.getRequestId(); if (DEBUG) { Log.v(TAG, "Received result frame " + resultExtras.getFrameNumber() + " for id " + requestId); } + + + // TODO: Handle CameraCharacteristics access from CaptureResult correctly. + result.set(CameraCharacteristics.LENS_INFO_SHADING_MAP_SIZE, + getCharacteristics().get(CameraCharacteristics.LENS_INFO_SHADING_MAP_SIZE)); + final CaptureListenerHolder holder; synchronized (mLock) { holder = CameraDevice.this.mCaptureListenerMap.get(requestId); @@ -965,4 +977,8 @@ public class CameraDevice implements android.hardware.camera2.CameraDevice { return (mRemoteDevice == null); } } + + private CameraCharacteristics getCharacteristics() { + return mCharacteristics; + } } diff --git a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java index 12d8ddf36708..dc0c65250386 100644 --- a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java +++ b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java @@ -43,15 +43,19 @@ import android.hardware.camera2.marshal.impl.MarshalQueryableStreamConfiguration import android.hardware.camera2.marshal.impl.MarshalQueryableStreamConfigurationDuration; import android.hardware.camera2.marshal.impl.MarshalQueryableString; import android.hardware.camera2.params.Face; +import android.hardware.camera2.params.LensShadingMap; import android.hardware.camera2.params.StreamConfiguration; import android.hardware.camera2.params.StreamConfigurationDuration; import android.hardware.camera2.params.StreamConfigurationMap; import android.hardware.camera2.params.TonemapCurve; import android.hardware.camera2.utils.TypeReference; +import android.location.Location; +import android.location.LocationManager; import android.os.Parcelable; import android.os.Parcel; import android.util.Log; import android.util.Pair; +import android.util.Size; import com.android.internal.util.Preconditions; @@ -59,6 +63,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; +import java.util.HashMap; /** * Implementation of camera metadata marshal/unmarshal across Binder to @@ -211,6 +216,37 @@ public class CameraMetadataNative implements Parcelable { // this should be in sync with HAL_PIXEL_FORMAT_BLOB defined in graphics.h public static final int NATIVE_JPEG_FORMAT = 0x21; + private static final String CELLID_PROCESS = "CELLID"; + private static final String GPS_PROCESS = "GPS"; + + private static String translateLocationProviderToProcess(final String provider) { + if (provider == null) { + return null; + } + switch(provider) { + case LocationManager.GPS_PROVIDER: + return GPS_PROCESS; + case LocationManager.NETWORK_PROVIDER: + return CELLID_PROCESS; + default: + return null; + } + } + + private static String translateProcessToLocationProvider(final String process) { + if (process == null) { + return null; + } + switch(process) { + case GPS_PROCESS: + return LocationManager.GPS_PROVIDER; + case CELLID_PROCESS: + return LocationManager.NETWORK_PROVIDER; + default: + return null; + } + } + public CameraMetadataNative() { super(); mMetadataPtr = nativeAllocate(); @@ -411,7 +447,6 @@ public class CameraMetadataNative implements Parcelable { ByteBuffer buffer = ByteBuffer.wrap(values).order(ByteOrder.nativeOrder()); return marshaler.unmarshal(buffer); } - // Need overwrite some metadata that has different definitions between native // and managed sides. @SuppressWarnings("unchecked") @@ -441,6 +476,10 @@ public class CameraMetadataNative implements Parcelable { value = (T) getMaxNumOutputs(key); } else if (key.equals(CaptureRequest.TONEMAP_CURVE)) { value = (T) getTonemapCurve(); + } else if (key.equals(CaptureResult.JPEG_GPS_LOCATION)) { + value = (T) getGpsLocation(); + } else if (key.equals(CaptureResult.STATISTICS_LENS_SHADING_CORRECTION_MAP)) { + value = (T) getLensShadingMap(); } else { override = false; } @@ -561,6 +600,62 @@ public class CameraMetadataNative implements Parcelable { return fixedFaceRectangles; } + private LensShadingMap getLensShadingMap() { + float[] lsmArray = getBase(CaptureResult.STATISTICS_LENS_SHADING_MAP); + if (lsmArray == null) { + Log.w(TAG, "getLensShadingMap - Lens shading map was null."); + return null; + } + Size s = get(CameraCharacteristics.LENS_INFO_SHADING_MAP_SIZE); + LensShadingMap map = new LensShadingMap(lsmArray, s.getHeight(), s.getWidth()); + return map; + } + + private Location getGpsLocation() { + String processingMethod = get(CaptureResult.JPEG_GPS_PROCESSING_METHOD); + Location l = new Location(translateProcessToLocationProvider(processingMethod)); + + double[] coords = get(CaptureResult.JPEG_GPS_COORDINATES); + Long timeStamp = get(CaptureResult.JPEG_GPS_TIMESTAMP); + + if (timeStamp != null) { + l.setTime(timeStamp); + } else { + Log.w(TAG, "getGpsLocation - No timestamp for GPS location."); + } + + if (coords != null) { + l.setLatitude(coords[0]); + l.setLongitude(coords[1]); + l.setAltitude(coords[2]); + } else { + Log.w(TAG, "getGpsLocation - No coordinates for GPS location"); + } + + return l; + } + + private boolean setGpsLocation(Location l) { + if (l == null) { + return false; + } + + double[] coords = { l.getLatitude(), l.getLongitude(), l.getAltitude() }; + String processMethod = translateLocationProviderToProcess(l.getProvider()); + long timestamp = l.getTime(); + + set(CaptureRequest.JPEG_GPS_TIMESTAMP, timestamp); + set(CaptureRequest.JPEG_GPS_COORDINATES, coords); + + if (processMethod == null) { + Log.w(TAG, "setGpsLocation - No process method, Location is not from a GPS or NETWORK" + + "provider"); + } else { + setBase(CaptureRequest.JPEG_GPS_PROCESSING_METHOD, processMethod); + } + return true; + } + private StreamConfigurationMap getStreamConfigurationMap() { StreamConfiguration[] configurations = getBase( CameraCharacteristics.SCALER_AVAILABLE_STREAM_CONFIGURATIONS); @@ -670,6 +765,8 @@ public class CameraMetadataNative implements Parcelable { return setFaceRectangles((Rect[]) value); } else if (key.equals(CaptureRequest.TONEMAP_CURVE)) { return setTonemapCurve((TonemapCurve) value); + } else if (key.equals(CaptureResult.JPEG_GPS_LOCATION)) { + return setGpsLocation((Location) value); } // For other keys, set() falls back to setBase(). return false; diff --git a/core/java/android/hardware/camera2/params/LensShadingMap.java b/core/java/android/hardware/camera2/params/LensShadingMap.java index b328f5786321..9bbc33a85f17 100644 --- a/core/java/android/hardware/camera2/params/LensShadingMap.java +++ b/core/java/android/hardware/camera2/params/LensShadingMap.java @@ -28,7 +28,7 @@ import java.util.Arrays; /** * Immutable class for describing a {@code 4 x N x M} lens shading map of floats. * - * @see CameraCharacteristics#LENS_SHADING_MAP + * @see CaptureResult#STATISTICS_LENS_SHADING_CORRECTION_MAP */ public final class LensShadingMap { @@ -62,12 +62,12 @@ public final class LensShadingMap { public LensShadingMap(final float[] elements, final int rows, final int columns) { mRows = checkArgumentPositive(rows, "rows must be positive"); - mColumns = checkArgumentPositive(rows, "columns must be positive"); + mColumns = checkArgumentPositive(columns, "columns must be positive"); mElements = checkNotNull(elements, "elements must not be null"); if (elements.length != getGainFactorCount()) { throw new IllegalArgumentException("elements must be " + getGainFactorCount() + - " length"); + " length, received " + elements.length); } // Every element must be finite and >= 1.0f @@ -242,4 +242,4 @@ public final class LensShadingMap { private final int mRows; private final int mColumns; private final float[] mElements; -}; +} -- cgit v1.2.3-59-g8ed1b