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

Commit de62d84e authored by Emilian Peev's avatar Emilian Peev
Browse files

Camera: Initial support for vendor tag caches

Vendor tag cache will be used alternatively to the regular
Vendor tag descriptor. The caches can support multiple vendor
tag providers at the same time. The native metadata along with
the requests/results/characteristics will store vendor specific
information that will be used to indentify the respective
descriptor.

Bug: 34275821
Test: Complete Camera/Camera2 CTS tests
Change-Id: I50b7cf9aa5575944fde7673a1728869690b2ce0d
parent 8d41ad08
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -62,6 +62,15 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
    public static final class Key<T> {
        private final CameraMetadataNative.Key<T> mKey;

        /**
         * Visible for testing and vendor extensions only.
         *
         * @hide
         */
        public Key(String name, Class<T> type, long vendorId) {
            mKey = new CameraMetadataNative.Key<T>(name,  type, vendorId);
        }

        /**
         * Visible for testing and vendor extensions only.
         *
@@ -98,6 +107,15 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
            return mKey.getName();
        }

        /**
         * Return vendor tag id.
         *
         * @hide
         */
        public long getVendorId() {
            return mKey.getVendorId();
        }

        /**
         * {@inheritDoc}
         */
@@ -159,6 +177,7 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
     */
    public CameraCharacteristics(CameraMetadataNative properties) {
        mProperties = CameraMetadataNative.move(properties);
        setNativeInstance(mProperties);
    }

    /**
@@ -227,7 +246,7 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
        }

        mKeys = Collections.unmodifiableList(
                getKeysStatic(getClass(), getKeyClass(), this, filterTags));
                getKeys(getClass(), getKeyClass(), this, filterTags));
        return mKeys;
    }

@@ -320,7 +339,7 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
                    "metadataClass must be a subclass of CameraMetadata");
        }

        List<TKey> staticKeyList = CameraCharacteristics.<TKey>getKeysStatic(
        List<TKey> staticKeyList = getKeys(
                metadataClass, keyClass, /*instance*/null, filterTags);
        return Collections.unmodifiableList(staticKeyList);
    }
+20 −4
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public abstract class CameraMetadata<TKey> {

    private static final String TAG = "CameraMetadataAb";
    private static final boolean DEBUG = false;
    private CameraMetadataNative mNativeInstance = null;

    /**
     * Set a camera metadata field to a value. The field definitions can be
@@ -86,6 +87,13 @@ public abstract class CameraMetadata<TKey> {
     */
     protected abstract <T> T getProtected(TKey key);

     /**
      * @hide
      */
     protected void setNativeInstance(CameraMetadataNative nativeInstance) {
        mNativeInstance = nativeInstance;
     }

     /**
      * @hide
      */
@@ -108,7 +116,7 @@ public abstract class CameraMetadata<TKey> {
    public List<TKey> getKeys() {
        Class<CameraMetadata<TKey>> thisClass = (Class<CameraMetadata<TKey>>) getClass();
        return Collections.unmodifiableList(
                getKeysStatic(thisClass, getKeyClass(), this, /*filterTags*/null));
                getKeys(thisClass, getKeyClass(), this, /*filterTags*/null));
    }

    /**
@@ -126,7 +134,7 @@ public abstract class CameraMetadata<TKey> {
     * </p>
     */
     /*package*/ @SuppressWarnings("unchecked")
    static <TKey> ArrayList<TKey> getKeysStatic(
    <TKey> ArrayList<TKey> getKeys(
             Class<?> type, Class<TKey> keyClass,
             CameraMetadata<TKey> instance,
             int[] filterTags) {
@@ -173,23 +181,31 @@ public abstract class CameraMetadata<TKey> {
            }
        }

        ArrayList<TKey> vendorKeys = CameraMetadataNative.getAllVendorKeys(keyClass);
        if (null == mNativeInstance) {
            return keyList;
        }

        ArrayList<TKey> vendorKeys = mNativeInstance.getAllVendorKeys(keyClass);

        if (vendorKeys != null) {
            for (TKey k : vendorKeys) {
                String keyName;
                long vendorId;
                if (k instanceof CaptureRequest.Key<?>) {
                    keyName = ((CaptureRequest.Key<?>) k).getName();
                    vendorId = ((CaptureRequest.Key<?>) k).getVendorId();
                } else if (k instanceof CaptureResult.Key<?>) {
                    keyName = ((CaptureResult.Key<?>) k).getName();
                    vendorId = ((CaptureResult.Key<?>) k).getVendorId();
                } else if (k instanceof CameraCharacteristics.Key<?>) {
                    keyName = ((CameraCharacteristics.Key<?>) k).getName();
                    vendorId = ((CameraCharacteristics.Key<?>) k).getVendorId();
                } else {
                    continue;
                }

                if (filterTags == null || Arrays.binarySearch(filterTags,
                        CameraMetadataNative.getTag(keyName)) >= 0) {
                        CameraMetadataNative.getTag(keyName, vendorId)) >= 0) {
                    keyList.add(k);
                }
            }
+22 −0
Original line number Diff line number Diff line
@@ -96,6 +96,15 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>>
    public final static class Key<T> {
        private final CameraMetadataNative.Key<T> mKey;

        /**
         * Visible for testing and vendor extensions only.
         *
         * @hide
         */
        public Key(String name, Class<T> type, long vendorId) {
            mKey = new CameraMetadataNative.Key<T>(name, type, vendorId);
        }

        /**
         * Visible for testing and vendor extensions only.
         *
@@ -132,6 +141,15 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>>
            return mKey.getName();
        }

        /**
         * Return vendor tag id.
         *
         * @hide
         */
        public long getVendorId() {
            return mKey.getVendorId();
        }

        /**
         * {@inheritDoc}
         */
@@ -199,6 +217,7 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>>
     */
    private CaptureRequest() {
        mSettings = new CameraMetadataNative();
        setNativeInstance(mSettings);
        mSurfaceSet = new HashSet<Surface>();
        mIsReprocess = false;
        mReprocessableSessionId = CameraCaptureSession.SESSION_ID_NONE;
@@ -212,6 +231,7 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>>
    @SuppressWarnings("unchecked")
    private CaptureRequest(CaptureRequest source) {
        mSettings = new CameraMetadataNative(source.mSettings);
        setNativeInstance(mSettings);
        mSurfaceSet = (HashSet<Surface>) source.mSurfaceSet.clone();
        mIsReprocess = source.mIsReprocess;
        mIsPartOfCHSRequestList = source.mIsPartOfCHSRequestList;
@@ -242,6 +262,7 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>>
    private CaptureRequest(CameraMetadataNative settings, boolean isReprocess,
            int reprocessableSessionId) {
        mSettings = CameraMetadataNative.move(settings);
        setNativeInstance(mSettings);
        mSurfaceSet = new HashSet<Surface>();
        mIsReprocess = isReprocess;
        if (isReprocess) {
@@ -441,6 +462,7 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>>
     */
    private void readFromParcel(Parcel in) {
        mSettings.readFromParcel(in);
        setNativeInstance(mSettings);

        mSurfaceSet.clear();

+20 −0
Original line number Diff line number Diff line
@@ -73,6 +73,15 @@ public class CaptureResult extends CameraMetadata<CaptureResult.Key<?>> {
    public final static class Key<T> {
        private final CameraMetadataNative.Key<T> mKey;

        /**
         * Visible for testing and vendor extensions only.
         *
         * @hide
         */
        public Key(String name, Class<T> type, long vendorId) {
            mKey = new CameraMetadataNative.Key<T>(name, type, vendorId);
        }

        /**
         * Visible for testing and vendor extensions only.
         *
@@ -109,6 +118,15 @@ public class CaptureResult extends CameraMetadata<CaptureResult.Key<?>> {
            return mKey.getName();
        }

        /**
         * Return vendor tag id.
         *
         * @hide
         */
        public long getVendorId() {
            return mKey.getVendorId();
        }

        /**
         * {@inheritDoc}
         */
@@ -186,6 +204,7 @@ public class CaptureResult extends CameraMetadata<CaptureResult.Key<?>> {
        if (mResults.isEmpty()) {
            throw new AssertionError("Results must not be empty");
        }
        setNativeInstance(mResults);
        mRequest = parent;
        mSequenceId = extras.getRequestId();
        mFrameNumber = extras.getFrameNumber();
@@ -215,6 +234,7 @@ public class CaptureResult extends CameraMetadata<CaptureResult.Key<?>> {
            throw new AssertionError("Results must not be empty");
        }

        setNativeInstance(mResults);
        mRequest = null;
        mSequenceId = sequenceId;
        mFrameNumber = -1;
+60 −15
Original line number Diff line number Diff line
@@ -79,10 +79,28 @@ public class CameraMetadataNative implements Parcelable {
    public static class Key<T> {
        private boolean mHasTag;
        private int mTag;
        private long mVendorId = Long.MAX_VALUE;
        private final Class<T> mType;
        private final TypeReference<T> mTypeReference;
        private final String mName;
        private final int mHash;

        /**
         * @hide
         */
        public Key(String name, Class<T> type, long vendorId) {
            if (name == null) {
                throw new NullPointerException("Key needs a valid name");
            } else if (type == null) {
                throw new NullPointerException("Type needs to be non-null");
            }
            mName = name;
            mType = type;
            mVendorId = vendorId;
            mTypeReference = TypeReference.createSpecializedTypeReference(type);
            mHash = mName.hashCode() ^ mTypeReference.hashCode();
        }

        /**
         * Visible for testing only.
         *
@@ -194,7 +212,7 @@ public class CameraMetadataNative implements Parcelable {
         */
        public final int getTag() {
            if (!mHasTag) {
                mTag = CameraMetadataNative.getTag(mName);
                mTag = CameraMetadataNative.getTag(mName, mVendorId);
                mHasTag = true;
            }
            return mTag;
@@ -211,6 +229,15 @@ public class CameraMetadataNative implements Parcelable {
            return mType;
        }

        /**
         * Get the vendor tag provider id.
         *
         * @hide
         */
        public final long getVendorId() {
            return mVendorId;
        }

        /**
         * Get the type reference backing the type {@code T} for this key.
         *
@@ -463,13 +490,14 @@ public class CameraMetadataNative implements Parcelable {
    }

    private <T> T getBase(Key<T> key) {
        int tag = key.getTag();
        int tag = nativeGetTagFromKeyLocal(key.getName());
        byte[] values = readValues(tag);
        if (values == null) {
            return null;
        }

        Marshaler<T> marshaler = getMarshalerForKey(key);
        int nativeType = nativeGetTypeFromTagLocal(tag);
        Marshaler<T> marshaler = getMarshalerForKey(key, nativeType);
        ByteBuffer buffer = ByteBuffer.wrap(values).order(ByteOrder.nativeOrder());
        return marshaler.unmarshal(buffer);
    }
@@ -947,15 +975,15 @@ public class CameraMetadataNative implements Parcelable {
    }

    private <T> void setBase(Key<T> key, T value) {
        int tag = key.getTag();

        int tag = nativeGetTagFromKeyLocal(key.getName());
        if (value == null) {
            // Erase the entry
            writeValues(tag, /*src*/null);
            return;
        } // else update the entry to a new value

        Marshaler<T> marshaler = getMarshalerForKey(key);
        int nativeType = nativeGetTypeFromTagLocal(tag);
        Marshaler<T> marshaler = getMarshalerForKey(key, nativeType);
        int size = marshaler.calculateMarshalSize(value);

        // TODO: Optimization. Cache the byte[] and reuse if the size is big enough.
@@ -1092,10 +1120,14 @@ public class CameraMetadataNative implements Parcelable {
    private native synchronized void nativeWriteValues(int tag, byte[] src);
    private native synchronized void nativeDump() throws IOException; // dump to ALOGD

    private static native ArrayList nativeGetAllVendorKeys(Class keyClass);
    private static native int nativeGetTagFromKey(String keyName)
    private native synchronized ArrayList nativeGetAllVendorKeys(Class keyClass);
    private native synchronized int nativeGetTagFromKeyLocal(String keyName)
            throws IllegalArgumentException;
    private static native int nativeGetTypeFromTag(int tag)
    private native synchronized int nativeGetTypeFromTagLocal(int tag)
            throws IllegalArgumentException;
    private static native int nativeGetTagFromKey(String keyName, long vendorId)
            throws IllegalArgumentException;
    private static native int nativeGetTypeFromTag(int tag, long vendorId)
            throws IllegalArgumentException;

    /**
@@ -1133,7 +1165,7 @@ public class CameraMetadataNative implements Parcelable {
     *
     * @hide
     */
    public static <K> ArrayList<K> getAllVendorKeys(Class<K> keyClass) {
    public <K>  ArrayList<K> getAllVendorKeys(Class<K> keyClass) {
        if (keyClass == null) {
            throw new NullPointerException();
        }
@@ -1149,19 +1181,32 @@ public class CameraMetadataNative implements Parcelable {
     * @hide
     */
    public static int getTag(String key) {
        return nativeGetTagFromKey(key);
        return nativeGetTagFromKey(key, Long.MAX_VALUE);
    }

    /**
     * Convert a key string into the equivalent native tag.
     *
     * @throws IllegalArgumentException if the key was not recognized
     * @throws NullPointerException if the key was null
     *
     * @hide
     */
    public static int getTag(String key, long vendorId) {
        return nativeGetTagFromKey(key, vendorId);
    }

    /**
     * Get the underlying native type for a tag.
     *
     * @param tag An integer tag, see e.g. {@link #getTag}
     * @param vendorId A vendor tag provider id
     * @return An int enum for the metadata type, see e.g. {@link #TYPE_BYTE}
     *
     * @hide
     */
    public static int getNativeType(int tag) {
        return nativeGetTypeFromTag(tag);
    public static int getNativeType(int tag, long vendorId) {
        return nativeGetTypeFromTag(tag, vendorId);
    }

    /**
@@ -1226,9 +1271,9 @@ public class CameraMetadataNative implements Parcelable {
     * @throws UnsupportedOperationException
     *          if the native/managed type combination for {@code key} is not supported
     */
    private static <T> Marshaler<T> getMarshalerForKey(Key<T> key) {
    private static <T> Marshaler<T> getMarshalerForKey(Key<T> key, int nativeType) {
        return MarshalRegistry.getMarshaler(key.getTypeReference(),
                getNativeType(key.getTag()));
                nativeType);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
Loading