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

Commit 70c2207c authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

Camera2: Immutable metadata

Make all camera metadata immutable once created; requests are
created using CameraRequest.Builder.

- Separate CameraMetadata implementation from interface
- Implement deep copying of metadata
- Requests/results/properties have-a native implementation

Bug: 10360518
Change-Id: Ia6300c237219d39f70c63156fa9ca666d951a36e
parent 4af73c21
Loading
Loading
Loading
Loading
+17 −15
Original line number Original line Diff line number Diff line
@@ -10804,7 +10804,7 @@ package android.hardware.camera2 {
    method public abstract void captureBurst(java.util.List<android.hardware.camera2.CaptureRequest>, android.hardware.camera2.CameraDevice.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract void captureBurst(java.util.List<android.hardware.camera2.CaptureRequest>, android.hardware.camera2.CameraDevice.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract void close() throws java.lang.Exception;
    method public abstract void close() throws java.lang.Exception;
    method public abstract void configureOutputs(java.util.List<android.view.Surface>) throws android.hardware.camera2.CameraAccessException;
    method public abstract void configureOutputs(java.util.List<android.view.Surface>) throws android.hardware.camera2.CameraAccessException;
    method public abstract android.hardware.camera2.CaptureRequest createCaptureRequest(int) throws android.hardware.camera2.CameraAccessException;
    method public abstract android.hardware.camera2.CaptureRequest.Builder createCaptureRequest(int) throws android.hardware.camera2.CameraAccessException;
    method public abstract void flush() throws android.hardware.camera2.CameraAccessException;
    method public abstract void flush() throws android.hardware.camera2.CameraAccessException;
    method public abstract java.lang.String getId();
    method public abstract java.lang.String getId();
    method public abstract android.hardware.camera2.CameraProperties getProperties() throws android.hardware.camera2.CameraAccessException;
    method public abstract android.hardware.camera2.CameraProperties getProperties() throws android.hardware.camera2.CameraAccessException;
@@ -10850,14 +10850,8 @@ package android.hardware.camera2 {
    method public void onCameraUnavailable(java.lang.String);
    method public void onCameraUnavailable(java.lang.String);
  }
  }
  public class CameraMetadata implements java.lang.AutoCloseable android.os.Parcelable {
  public abstract class CameraMetadata {
    ctor public CameraMetadata();
    method public abstract T get(android.hardware.camera2.CameraMetadata.Key<T>);
    method public void close() throws java.lang.Exception;
    method public int describeContents();
    method public T get(android.hardware.camera2.CameraMetadata.Key<T>);
    method public void readFromParcel(android.os.Parcel);
    method public void set(android.hardware.camera2.CameraMetadata.Key<T>, T);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int COLOR_CORRECTION_MODE_FAST = 1; // 0x1
    field public static final int COLOR_CORRECTION_MODE_FAST = 1; // 0x1
    field public static final int COLOR_CORRECTION_MODE_HIGH_QUALITY = 2; // 0x2
    field public static final int COLOR_CORRECTION_MODE_HIGH_QUALITY = 2; // 0x2
    field public static final int COLOR_CORRECTION_MODE_TRANSFORM_MATRIX = 0; // 0x0
    field public static final int COLOR_CORRECTION_MODE_TRANSFORM_MATRIX = 0; // 0x0
@@ -10941,7 +10935,6 @@ package android.hardware.camera2 {
    field public static final int CONTROL_SCENE_MODE_SUNSET = 10; // 0xa
    field public static final int CONTROL_SCENE_MODE_SUNSET = 10; // 0xa
    field public static final int CONTROL_SCENE_MODE_THEATRE = 7; // 0x7
    field public static final int CONTROL_SCENE_MODE_THEATRE = 7; // 0x7
    field public static final int CONTROL_SCENE_MODE_UNSUPPORTED = 0; // 0x0
    field public static final int CONTROL_SCENE_MODE_UNSUPPORTED = 0; // 0x0
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final int EDGE_MODE_FAST = 1; // 0x1
    field public static final int EDGE_MODE_FAST = 1; // 0x1
    field public static final int EDGE_MODE_HIGH_QUALITY = 2; // 0x2
    field public static final int EDGE_MODE_HIGH_QUALITY = 2; // 0x2
    field public static final int EDGE_MODE_OFF = 0; // 0x0
    field public static final int EDGE_MODE_OFF = 0; // 0x0
@@ -10974,14 +10967,13 @@ package android.hardware.camera2 {
  }
  }
  public static class CameraMetadata.Key {
  public static class CameraMetadata.Key {
    ctor public CameraMetadata.Key(java.lang.String, java.lang.Class<T>);
    method public final boolean equals(java.lang.Object);
    method public final boolean equals(java.lang.Object);
    method public final java.lang.String getName();
    method public final java.lang.String getName();
    method public final int hashCode();
    method public final int hashCode();
  }
  }
  public final class CameraProperties extends android.hardware.camera2.CameraMetadata {
  public final class CameraProperties extends android.hardware.camera2.CameraMetadata {
    ctor public CameraProperties();
    method public T get(android.hardware.camera2.CameraMetadata.Key<T>);
    field public static final android.hardware.camera2.CameraMetadata.Key CONTROL_AE_AVAILABLE_ANTIBANDING_MODES;
    field public static final android.hardware.camera2.CameraMetadata.Key CONTROL_AE_AVAILABLE_ANTIBANDING_MODES;
    field public static final android.hardware.camera2.CameraMetadata.Key CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES;
    field public static final android.hardware.camera2.CameraMetadata.Key CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES;
    field public static final android.hardware.camera2.CameraMetadata.Key CONTROL_AE_COMPENSATION_RANGE;
    field public static final android.hardware.camera2.CameraMetadata.Key CONTROL_AE_COMPENSATION_RANGE;
@@ -11024,10 +11016,10 @@ package android.hardware.camera2 {
  }
  }
  public final class CaptureRequest extends android.hardware.camera2.CameraMetadata implements android.os.Parcelable {
  public final class CaptureRequest extends android.hardware.camera2.CameraMetadata implements android.os.Parcelable {
    method public void addTarget(android.view.Surface);
    method public int describeContents();
    method public T get(android.hardware.camera2.CameraMetadata.Key<T>);
    method public java.lang.Object getTag();
    method public java.lang.Object getTag();
    method public void removeTarget(android.view.Surface);
    method public void writeToParcel(android.os.Parcel, int);
    method public void setTag(java.lang.Object);
    field public static final android.hardware.camera2.CameraMetadata.Key BLACK_LEVEL_LOCK;
    field public static final android.hardware.camera2.CameraMetadata.Key BLACK_LEVEL_LOCK;
    field public static final android.hardware.camera2.CameraMetadata.Key COLOR_CORRECTION_GAINS;
    field public static final android.hardware.camera2.CameraMetadata.Key COLOR_CORRECTION_GAINS;
    field public static final android.hardware.camera2.CameraMetadata.Key COLOR_CORRECTION_MODE;
    field public static final android.hardware.camera2.CameraMetadata.Key COLOR_CORRECTION_MODE;
@@ -11077,7 +11069,17 @@ package android.hardware.camera2 {
    field public static final android.hardware.camera2.CameraMetadata.Key TONEMAP_MODE;
    field public static final android.hardware.camera2.CameraMetadata.Key TONEMAP_MODE;
  }
  }
  public static final class CaptureRequest.Builder {
    method public void addTarget(android.view.Surface);
    method public android.hardware.camera2.CaptureRequest build();
    method public T get(android.hardware.camera2.CameraMetadata.Key<T>);
    method public void removeTarget(android.view.Surface);
    method public void set(android.hardware.camera2.CameraMetadata.Key<T>, T);
    method public void setTag(java.lang.Object);
  }
  public final class CaptureResult extends android.hardware.camera2.CameraMetadata {
  public final class CaptureResult extends android.hardware.camera2.CameraMetadata {
    method public T get(android.hardware.camera2.CameraMetadata.Key<T>);
    field public static final android.hardware.camera2.CameraMetadata.Key BLACK_LEVEL_LOCK;
    field public static final android.hardware.camera2.CameraMetadata.Key BLACK_LEVEL_LOCK;
    field public static final android.hardware.camera2.CameraMetadata.Key COLOR_CORRECTION_GAINS;
    field public static final android.hardware.camera2.CameraMetadata.Key COLOR_CORRECTION_GAINS;
    field public static final android.hardware.camera2.CameraMetadata.Key COLOR_CORRECTION_TRANSFORM;
    field public static final android.hardware.camera2.CameraMetadata.Key COLOR_CORRECTION_TRANSFORM;
+18 −15
Original line number Original line Diff line number Diff line
@@ -230,15 +230,17 @@ public interface CameraDevice extends AutoCloseable {
    public void configureOutputs(List<Surface> outputs) throws CameraAccessException;
    public void configureOutputs(List<Surface> outputs) throws CameraAccessException;


    /**
    /**
     * <p>Create a {@link CaptureRequest} initialized with template for a target
     * <p>Create a {@link CaptureRequest.Builder} for new capture requests,
     * use case. The settings are chosen to be the best options for the specific
     * initialized with template for a target use case. The settings are chosen
     * camera device, so it is not recommended to reuse the same request for a
     * to be the best options for the specific camera device, so it is not
     * different camera device; create a request for that device and override
     * recommended to reuse the same request for a different camera device;
     * the settings as desired, instead.</p>
     * create a builder specific for that device and template and override the
     * settings as desired, instead.</p>
     *
     *
     * @param templateType An enumeration selecting the use case for this
     * @param templateType An enumeration selecting the use case for this
     * request; one of the CameraDevice.TEMPLATE_ values.
     * request; one of the CameraDevice.TEMPLATE_ values.
     * @return a filled-in CaptureRequest, except for output streams
     * @return a builder for a capture request, initialized with default
     * settings for that template, and no output streams
     *
     *
     * @throws IllegalArgumentException if the templateType is not in the list
     * @throws IllegalArgumentException if the templateType is not in the list
     * of supported templates.
     * of supported templates.
@@ -252,7 +254,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see #TEMPLATE_VIDEO_SNAPSHOT
     * @see #TEMPLATE_VIDEO_SNAPSHOT
     * @see #TEMPLATE_MANUAL
     * @see #TEMPLATE_MANUAL
     */
     */
    public CaptureRequest createCaptureRequest(int templateType)
    public CaptureRequest.Builder createCaptureRequest(int templateType)
            throws CameraAccessException;
            throws CameraAccessException;


    /**
    /**
@@ -262,10 +264,10 @@ public interface CameraDevice extends AutoCloseable {
     * including sensor, lens, flash, and post-processing settings.</p>
     * including sensor, lens, flash, and post-processing settings.</p>
     *
     *
     * <p>Each request will produce one {@link CaptureResult} and produce new
     * <p>Each request will produce one {@link CaptureResult} and produce new
     * frames for one or more target Surfaces, set with CaptureRequests's {@link
     * frames for one or more target Surfaces, set with the CaptureRequest
     * CaptureRequest#addTarget}. The target surfaces must be configured as
     * builder's {@link CaptureRequest.Builder#addTarget} method. The target
     * active outputs with {@link #configureOutputs} before calling this
     * surfaces must be configured as active outputs with
     * method.</p>
     * {@link #configureOutputs} before calling this method.</p>
     *
     *
     * <p>Multiple requests can be in progress at once. They are processed in
     * <p>Multiple requests can be in progress at once. They are processed in
     * first-in, first-out order, with minimal delays between each
     * first-in, first-out order, with minimal delays between each
@@ -303,10 +305,11 @@ public interface CameraDevice extends AutoCloseable {
     * calls.
     * calls.
     *
     *
     * <p>The requests will be captured in order, each capture producing one
     * <p>The requests will be captured in order, each capture producing one
     * {@link CaptureResult} and image buffers for one or more target {@link
     * {@link CaptureResult} and image buffers for one or more target
     * android.view.Surface surfaces}. The target surfaces for each request (set
     * {@link android.view.Surface surfaces}. The target surfaces for each
     * with {@link CaptureRequest#addTarget}) must be configured as active
     * request (set with {@link CaptureRequest.Builder#addTarget}) must be
     * outputs with {@link #configureOutputs} before calling this method.</p>
     * configured as active outputs with {@link #configureOutputs} before
     * calling this method.</p>
     *
     *
     * <p>The main difference between this method and simply calling
     * <p>The main difference between this method and simply calling
     * {@link #capture} repeatedly is that this method guarantees that no
     * {@link #capture} repeatedly is that this method guarantees that no
+2 −1
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.hardware.ICameraService;
import android.hardware.ICameraService;
import android.hardware.ICameraServiceListener;
import android.hardware.ICameraServiceListener;
import android.hardware.IProCameraUser;
import android.hardware.IProCameraUser;
import android.hardware.camera2.impl.CameraMetadataNative;
import android.hardware.camera2.utils.CameraBinderDecorator;
import android.hardware.camera2.utils.CameraBinderDecorator;
import android.hardware.camera2.utils.CameraRuntimeException;
import android.hardware.camera2.utils.CameraRuntimeException;
import android.hardware.camera2.utils.BinderHolder;
import android.hardware.camera2.utils.BinderHolder;
@@ -178,7 +179,7 @@ public final class CameraManager {
        // TODO: implement and call a service function to get the capabilities on C++ side
        // TODO: implement and call a service function to get the capabilities on C++ side


        // TODO: get properties from service
        // TODO: get properties from service
        return new CameraProperties();
        return new CameraProperties(new CameraMetadataNative());
    }
    }


    /**
    /**
+13 −651

File changed.

Preview size limit exceeded, changes collapsed.

+17 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package android.hardware.camera2;
package android.hardware.camera2;


import android.hardware.camera2.impl.CameraMetadataNative;

/**
/**
 * <p>The properties describing a
 * <p>The properties describing a
 * {@link CameraDevice CameraDevice}.</p>
 * {@link CameraDevice CameraDevice}.</p>
@@ -29,6 +31,21 @@ package android.hardware.camera2;
 */
 */
public final class CameraProperties extends CameraMetadata {
public final class CameraProperties extends CameraMetadata {


    private final CameraMetadataNative mProperties;

    /**
     * Takes ownership of the passed-in properties object
     * @hide
     */
    public CameraProperties(CameraMetadataNative properties) {
        mProperties = properties;
    }

    @Override
    public <T> T get(Key<T> key) {
        return mProperties.get(key);
    }

    /*@O~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
    /*@O~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
     * The key entries below this point are generated from metadata
     * The key entries below this point are generated from metadata
     * definitions in /system/media/camera/docs. Do not modify by hand or
     * definitions in /system/media/camera/docs. Do not modify by hand or
Loading