OSDN Git Service

Improvements to the camera metadata structure
authorEino-Ville Talvala <etalvala@google.com>
Wed, 4 Apr 2012 22:30:06 +0000 (15:30 -0700)
committerEino-Ville Talvala <etalvala@google.com>
Mon, 16 Apr 2012 17:52:27 +0000 (10:52 -0700)
- Add vendor_tag_query_ops_t as argument to methods inside it.

- Add version and flags fields

- Add sorted flag; additions and appends are not sorted, and thus
  reset the flag.

- Add sort method, which sets the sorted flag.

- Add find-by-tag method, which uses a linear search on a non-sorted
  buffer, and a binary search on a sorted buffer.

- Change dump method to take in a fd, like the HAL-level dump methods
  do.

- Minor revisions to tag definitions, including a few enums for
  enumerated-value tags.

Change-Id: I5f37e326519bda032cb3362da4ab3bf50eb98b4e

camera/include/system/camera_metadata.h
camera/include/system/camera_metadata_tags.h
camera/src/camera_metadata.c
camera/src/camera_metadata_tag_info.c
camera/tests/camera_metadata_tests.cpp
camera/tests/camera_metadata_tests_fake_vendor.h

index 424fc0f..6a11cfb 100644 (file)
@@ -208,7 +208,8 @@ camera_metadata_t *copy_camera_metadata(void *dst, size_t dst_size,
 /**
  * Append camera metadata in src to an existing metadata structure in dst.  This
  * does not resize the destination structure, so if it is too small, a non-zero
- * value is returned. On success, 0 is returned.
+ * value is returned. On success, 0 is returned. Appending onto a sorted
+ * structure results in a non-sorted combined structure.
  */
 ANDROID_API
 int append_camera_metadata(camera_metadata_t *dst, const camera_metadata_t *src);
@@ -229,7 +230,9 @@ size_t calculate_camera_metadata_entry_data_size(uint8_t type,
  * left to add the entry, or if the tag is unknown.  data_count is the number of
  * entries in the data array of the tag's type, not a count of
  * bytes. Vendor-defined tags can not be added using this method, unless
- * set_vendor_tag_query_ops() has been called first.
+ * set_vendor_tag_query_ops() has been called first. Entries are always added to
+ * the end of the structure (highest index), so after addition, a
+ * previously-sorted array will be marked as unsorted.
  */
 ANDROID_API
 int add_camera_metadata_entry(camera_metadata_t *dst,
@@ -238,13 +241,22 @@ int add_camera_metadata_entry(camera_metadata_t *dst,
         size_t data_count);
 
 /**
+ * Sort the metadata buffer for fast searching. If already sorted, does
+ * nothing. Adding or appending entries to the buffer will place the buffer back
+ * into an unsorted state.
+ */
+ANDROID_API
+int sort_camera_metadata(camera_metadata_t *dst);
+
+/**
  * Get pointers to the fields for a metadata entry at position index in the
  * entry array.  The data pointer points either to the entry's data.value field
  * or to the right offset in camera_metadata_t.data. Returns 0 on
  * success. Data_count is the number of entries in the data array when cast to
  * the tag's type, not a count of bytes.
  *
- * src and index are inputs; tag, type, data, and data_count are outputs.
+ * src and index are inputs; tag, type, data, and data_count are outputs. Any of
+ * the outputs can be set to NULL to skip reading that value.
  */
 ANDROID_API
 int get_camera_metadata_entry(camera_metadata_t *src,
@@ -255,6 +267,22 @@ int get_camera_metadata_entry(camera_metadata_t *src,
         size_t *data_count);
 
 /**
+ * Find an entry with given tag value. If not found, returns -ENOENT. Otherwise,
+ * returns entry contents like get_camera_metadata_entry. Any of
+ * the outputs can be set to NULL to skip reading that value.
+ *
+ * Note: Returns only the first entry with a given tag. To speed up searching
+ * for tags, sort the metadata structure first by calling
+ * sort_camera_metadata().
+ */
+ANDROID_API
+int find_camera_metadata_entry(camera_metadata_t *src,
+        uint32_t tag,
+        uint8_t *type,
+        void **data,
+        size_t *data_count);
+
+/**
  * Retrieve human-readable name of section the tag is in. Returns NULL if
  * no such tag is defined. Returns NULL for tags in the vendor section, unless
  * set_vendor_tag_query_ops() has been used.
@@ -284,7 +312,8 @@ int get_camera_metadata_tag_type(uint32_t tag);
  * get_camera_metadata_section_name, _tag_name, and _tag_type methods with
  * vendor tags. Returns 0 on success.
  */
-typedef struct vendor_tag_query_ops {
+typedef struct vendor_tag_query_ops vendor_tag_query_ops_t;
+struct vendor_tag_query_ops {
     /**
      * Get vendor section name for a vendor-specified entry tag. Only called for
      * tags >= 0x80000000. The section name must start with the name of the
@@ -292,20 +321,26 @@ typedef struct vendor_tag_query_ops {
      * their sections with "com.camerazoom." Must return NULL if the tag is
      * outside the bounds of vendor-defined sections.
      */
-    const char *(*get_camera_vendor_section_name)(uint32_t tag);
+    const char *(*get_camera_vendor_section_name)(
+        const vendor_tag_query_ops_t *v,
+        uint32_t tag);
     /**
      * Get tag name for a vendor-specified entry tag. Only called for tags >=
      * 0x80000000. Must return NULL if the tag is outside the bounds of
      * vendor-defined sections.
      */
-    const char *(*get_camera_vendor_tag_name)(uint32_t tag);
+    const char *(*get_camera_vendor_tag_name)(
+        const vendor_tag_query_ops_t *v,
+        uint32_t tag);
     /**
      * Get tag type for a vendor-specified entry tag. Only called for tags >=
      * 0x80000000. Must return -1 if the tag is outside the bounds of
      * vendor-defined sections.
      */
-    int         (*get_camera_vendor_tag_type)(uint32_t tag);
-} vendor_tag_query_ops_t;
+    int (*get_camera_vendor_tag_type)(
+        const vendor_tag_query_ops_t *v,
+        uint32_t tag);
+};
 
 ANDROID_API
 int set_camera_metadata_vendor_tag_ops(const vendor_tag_query_ops_t *query_ops);
@@ -318,6 +353,7 @@ int set_camera_metadata_vendor_tag_ops(const vendor_tag_query_ops_t *query_ops);
  */
 ANDROID_API
 void dump_camera_metadata(const camera_metadata_t *metadata,
+        int fd,
         int verbosity);
 
 #ifdef __cplusplus
index 1fcfacb..ce1319e 100644 (file)
@@ -142,7 +142,7 @@ enum {
 
     ANDROID_SENSOR_EXPOSURE_TIME_RANGE = ANDROID_SENSOR_INFO_START,
     ANDROID_SENSOR_MAX_FRAME_DURATION,
-    ANDROID_SENSOR_SENSITIVITY_RANGE,
+    ANDROID_SENSOR_AVAILABLE_SENSITIVITIES,
     ANDROID_SENSOR_COLOR_FILTER_ARRANGEMENT,
     ANDROID_SENSOR_PIXEL_ARRAY_SIZE,
     ANDROID_SENSOR_ACTIVE_ARRAY_SIZE,
@@ -289,3 +289,25 @@ enum {
     ANDROID_CONTROL_AF_AVAILABLE_MODES,
     ANDROID_CONTROL_INFO_END
 };
+
+/**
+ * Enumeration definitions for the various entries that need them
+ */
+
+// ANDROID_REQUEST_METADATA_MODE
+enum {
+    ANDROID_REQUEST_METADATA_NONE = 0,
+    ANDROID_REQUEST_METADATA_FULL
+};
+
+// ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT
+enum {
+    ANDROID_SENSOR_RGGB = 0,
+    ANDROID_SENSOR_GRBG,
+    ANDROID_SENSOR_GBRG,
+    ANDROID_SENSOR_BGGR,
+    ANDROID_SENSOR_RGB
+};
+
+// ANDROID_SCALER_AVAILABLE_FORMATS uses HAL_PIXEL_FORMAT_* from
+// system/graphics.h
index a481bec..c7121ca 100644 (file)
 
 #include <system/camera_metadata.h>
 #include <cutils/log.h>
-
-#define OK    0
-#define ERROR 1
-
+#define _GNU_SOURCE // for fdprintf
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#define OK         0
+#define ERROR      1
+#define NOT_FOUND -ENOENT
 /**
  * A single metadata entry, storing an array of values of a given type. If the
  * array is no larger than 4 bytes in size, it is stored in the data.value[]
@@ -73,6 +77,8 @@ typedef struct camera_metadata_entry {
  */
 struct camera_metadata {
     size_t                   size;
+    uint32_t                 version;
+    uint32_t                 flags;
     size_t                   entry_count;
     size_t                   entry_capacity;
     camera_metadata_entry_t *entries;
@@ -82,6 +88,14 @@ struct camera_metadata {
     uint8_t                  reserved[0];
 };
 
+/** Versioning information */
+#define CURRENT_METADATA_VERSION 1
+
+/** Flag definitions */
+#define FLAG_SORTED 0x00000001
+
+/** Tag information */
+
 typedef struct tag_info {
     const char *tag_name;
     uint8_t     tag_type;
@@ -128,6 +142,8 @@ camera_metadata_t *place_camera_metadata(void *dst,
     if (memory_needed > dst_size) return NULL;
 
     camera_metadata_t *metadata = (camera_metadata_t*)dst;
+    metadata->version = CURRENT_METADATA_VERSION;
+    metadata->flags = 0;
     metadata->entry_count = 0;
     metadata->entry_capacity = entry_capacity;
     metadata->entries = (camera_metadata_entry_t*)(metadata + 1);
@@ -202,6 +218,8 @@ camera_metadata_t* copy_camera_metadata(void *dst, size_t dst_size,
                                            src->data_capacity);
 
     camera_metadata_t *metadata = (camera_metadata_t*)dst;
+    metadata->version = CURRENT_METADATA_VERSION;
+    metadata->flags = src->flags;
     metadata->entry_count = src->entry_count;
     metadata->entry_capacity = src->entry_count;
     metadata->entries = (camera_metadata_entry_t*)
@@ -246,6 +264,7 @@ int append_camera_metadata(camera_metadata_t *dst,
     }
     dst->entry_count += src->entry_count;
     dst->data_count += src->data_count;
+    dst->flags &= ~FLAG_SORTED;
 
     return OK;
 }
@@ -258,7 +277,7 @@ size_t calculate_camera_metadata_entry_data_size(uint8_t type,
     return data_bytes <= 4 ? 0 : data_bytes;
 }
 
-int add_camera_metadata_entry_raw(camera_metadata_t *dst,
+static int add_camera_metadata_entry_raw(camera_metadata_t *dst,
         uint32_t tag,
         uint8_t  type,
         const void *data,
@@ -285,6 +304,7 @@ int add_camera_metadata_entry_raw(camera_metadata_t *dst,
         dst->data_count += data_bytes;
     }
     dst->entry_count++;
+    dst->flags &= ~FLAG_SORTED;
     return OK;
 }
 
@@ -295,7 +315,7 @@ int add_camera_metadata_entry(camera_metadata_t *dst,
 
     int type = get_camera_metadata_tag_type(tag);
     if (type == -1) {
-        ALOGE("Unknown tag %04x (can't find type)", tag);
+        ALOGE("%s: Unknown tag %04x.", __FUNCTION__, tag);
         return ERROR;
     }
 
@@ -306,6 +326,26 @@ int add_camera_metadata_entry(camera_metadata_t *dst,
             data_count);
 }
 
+static int compare_entry_tags(const void *p1, const void *p2) {
+    uint32_t tag1 = ((camera_metadata_entry_t*)p1)->tag;
+    uint32_t tag2 = ((camera_metadata_entry_t*)p2)->tag;
+    return  tag1 < tag2 ? -1 :
+            tag1 == tag2 ? 0 :
+            1;
+}
+
+int sort_camera_metadata(camera_metadata_t *dst) {
+    if (dst == NULL) return ERROR;
+    if (dst->flags & FLAG_SORTED) return OK;
+
+    qsort(dst->entries, dst->entry_count,
+            sizeof(camera_metadata_entry_t),
+            compare_entry_tags);
+    dst->flags |= FLAG_SORTED;
+
+    return OK;
+}
+
 int get_camera_metadata_entry(camera_metadata_t *src,
         uint32_t index,
         uint32_t *tag,
@@ -313,22 +353,60 @@ int get_camera_metadata_entry(camera_metadata_t *src,
         void **data,
         size_t *data_count) {
     if (src == NULL ) return ERROR;
-    if (tag == NULL) return ERROR;
-    if (type == NULL ) return ERROR;
-    if (data == NULL) return ERROR;
-    if (data_count == NULL) return ERROR;
-
     if (index >= src->entry_count) return ERROR;
 
     camera_metadata_entry_t *entry = src->entries + index;
 
-    *tag = entry->tag;
-    *type = entry->type;
-    *data_count = entry->count;
-    if (entry->count * camera_metadata_type_size[entry->type] > 4) {
-        *data = src->data + entry->data.offset;
+    if (tag != NULL) *tag = entry->tag;
+    if (type != NULL) *type = entry->type;
+    if (data_count != NULL) *data_count = entry->count;
+    if (data != NULL) {
+        if (entry->count * camera_metadata_type_size[entry->type] > 4) {
+            *data = src->data + entry->data.offset;
+        } else {
+            *data = entry->data.value;
+        }
+    }
+    return OK;
+}
+
+int find_camera_metadata_entry(camera_metadata_t *src,
+        uint32_t tag,
+        uint8_t *type,
+        void **data,
+        size_t *data_count) {
+    if (src == NULL) return ERROR;
+
+    camera_metadata_entry_t *entry = NULL;
+    if (src->flags & FLAG_SORTED) {
+        // Sorted entries, do a binary search
+        camera_metadata_entry_t key;
+        key.tag = tag;
+        entry = bsearch(&key,
+                src->entries,
+                src->entry_count,
+                sizeof(camera_metadata_entry_t),
+                compare_entry_tags);
     } else {
-        *data = entry->data.value;
+        // Not sorted, linear search
+        unsigned int i;
+        for (i = 0; i < src->entry_count; i++) {
+            if (src->entries[i].tag == tag) {
+                entry = src->entries + i;
+                break;
+            }
+        }
+    }
+    if (entry == NULL) return NOT_FOUND;
+
+    if (type != NULL) *type = entry->type;
+    if (data_count != NULL) *data_count = entry->count;
+    if (data != NULL) {
+        if (entry->count * camera_metadata_type_size[entry->type] > 4) {
+            *data = src->data + entry->data.offset;
+        } else {
+            *data = entry->data.value;
+        }
     }
     return OK;
 }
@@ -338,7 +416,9 @@ static const vendor_tag_query_ops_t *vendor_tag_ops = NULL;
 const char *get_camera_metadata_section_name(uint32_t tag) {
     uint32_t tag_section = tag >> 16;
     if (tag_section >= VENDOR_SECTION && vendor_tag_ops != NULL) {
-        return vendor_tag_ops->get_camera_vendor_section_name(tag);
+        return vendor_tag_ops->get_camera_vendor_section_name(
+            vendor_tag_ops,
+            tag);
     }
     if (tag_section >= ANDROID_SECTION_COUNT) {
         return NULL;
@@ -349,7 +429,9 @@ const char *get_camera_metadata_section_name(uint32_t tag) {
 const char *get_camera_metadata_tag_name(uint32_t tag) {
     uint32_t tag_section = tag >> 16;
     if (tag_section >= VENDOR_SECTION && vendor_tag_ops != NULL) {
-        return vendor_tag_ops->get_camera_vendor_tag_name(tag);
+        return vendor_tag_ops->get_camera_vendor_tag_name(
+            vendor_tag_ops,
+            tag);
     }
     if (tag_section >= ANDROID_SECTION_COUNT ||
         tag >= camera_metadata_section_bounds[tag_section][1] ) {
@@ -362,7 +444,9 @@ const char *get_camera_metadata_tag_name(uint32_t tag) {
 int get_camera_metadata_tag_type(uint32_t tag) {
     uint32_t tag_section = tag >> 16;
     if (tag_section >= VENDOR_SECTION && vendor_tag_ops != NULL) {
-        return vendor_tag_ops->get_camera_vendor_tag_type(tag);
+        return vendor_tag_ops->get_camera_vendor_tag_type(
+            vendor_tag_ops,
+            tag);
     }
     if (tag_section >= ANDROID_SECTION_COUNT ||
             tag >= camera_metadata_section_bounds[tag_section][1] ) {
@@ -377,18 +461,24 @@ int set_camera_metadata_vendor_tag_ops(const vendor_tag_query_ops_t *query_ops)
     return OK;
 }
 
-void print_data(const uint8_t *data_ptr, int type, int count);
+static void print_data(int fd, const uint8_t *data_ptr, int type, int count);
 
-void dump_camera_metadata(const camera_metadata_t *metadata, int verbosity) {
+void dump_camera_metadata(const camera_metadata_t *metadata,
+        int fd,
+        int verbosity) {
     if (metadata == NULL) {
-        ALOGE("Metadata is null.");
+        ALOGE("%s: Metadata is null.", __FUNCTION__);
         return;
     }
     unsigned int i;
-    ALOGD("Dumping camera metadata array. %d entries, %d bytes of extra data.",
+    fdprintf(fd,
+            "Dumping camera metadata array. %d entries, "
+            "%d bytes of extra data.\n",
             metadata->entry_count, metadata->data_count);
-    ALOGD("  (%d entries and %d bytes data reserved)",
+    fdprintf(fd, "  (%d entries and %d bytes data reserved)\n",
             metadata->entry_capacity, metadata->data_capacity);
+    fdprintf(fd, "  Version: %d, Flags: %08x\n",
+            metadata->version, metadata->flags);
     for (i=0; i < metadata->entry_count; i++) {
         camera_metadata_entry_t *entry = metadata->entries + i;
 
@@ -407,7 +497,7 @@ void dump_camera_metadata(const camera_metadata_t *metadata, int verbosity) {
         } else {
             type_name = camera_metadata_type_names[entry->type];
         }
-        ALOGD("Tag: %s.%s (%05x): %s[%d]",
+        fdprintf(fd, "Tag: %s.%s (%05x): %s[%d]\n",
              tag_section,
              tag_name,
              entry->tag,
@@ -422,9 +512,10 @@ void dump_camera_metadata(const camera_metadata_t *metadata, int verbosity) {
         uint8_t *data_ptr;
         if ( type_size * entry->count > 4 ) {
             if (entry->data.offset >= metadata->data_count) {
-                ALOGE("Malformed entry data offset: %d (max %d)",
-                     entry->data.offset,
-                     metadata->data_count);
+                ALOGE("%s: Malformed entry data offset: %d (max %d)",
+                        __FUNCTION__,
+                        entry->data.offset,
+                        metadata->data_count);
                 continue;
             }
             data_ptr = metadata->data + entry->data.offset;
@@ -434,11 +525,11 @@ void dump_camera_metadata(const camera_metadata_t *metadata, int verbosity) {
         int count = entry->count;
         if (verbosity < 2 && count > 16) count = 16;
 
-        print_data(data_ptr, entry->type, count);
+        print_data(fd, data_ptr, entry->type, count);
     }
 }
 
-void print_data(const uint8_t *data_ptr, int type, int count) {
+static void print_data(int fd, const uint8_t *data_ptr, int type, int count) {
     static int values_per_line[NUM_TYPES] = {
         [TYPE_BYTE]     = 16,
         [TYPE_INT32]    = 4,
@@ -452,49 +543,46 @@ void print_data(const uint8_t *data_ptr, int type, int count) {
     int lines = count / values_per_line[type];
     if (count % values_per_line[type] != 0) lines++;
 
-    char tmp1[80], tmp2[80];
-
     int index = 0;
     int j, k;
     for (j = 0; j < lines; j++) {
-        tmp1[0] = 0;
+        fdprintf(fd, " [");
         for (k = 0;
              k < values_per_line[type] && count > 0;
              k++, count--, index += type_size) {
 
             switch (type) {
                 case TYPE_BYTE:
-                    snprintf(tmp2, sizeof(tmp2), "%hhu ",
+                    fdprintf(fd, "%hhu ",
                             *(data_ptr + index));
                     break;
                 case TYPE_INT32:
-                    snprintf(tmp2, sizeof(tmp2), "%d ",
+                    fdprintf(fd, "%d ",
                             *(int32_t*)(data_ptr + index));
                     break;
                 case TYPE_FLOAT:
-                    snprintf(tmp2, sizeof(tmp2), "%0.2f ",
+                    fdprintf(fd, "%0.2f ",
                             *(float*)(data_ptr + index));
                     break;
                 case TYPE_INT64:
-                    snprintf(tmp2, sizeof(tmp2), "%lld ",
+                    fdprintf(fd, "%lld ",
                             *(int64_t*)(data_ptr + index));
                     break;
                 case TYPE_DOUBLE:
-                    snprintf(tmp2, sizeof(tmp2), "%0.2f ",
+                    fdprintf(fd, "%0.2f ",
                             *(float*)(data_ptr + index));
                     break;
                 case TYPE_RATIONAL: {
                     int32_t numerator = *(int32_t*)(data_ptr + index);
                     int32_t denominator = *(int32_t*)(data_ptr + index + 4);
-                    snprintf(tmp2, sizeof(tmp2), "(%d / %d) ",
+                    fdprintf(fd, "(%d / %d) ",
                             numerator, denominator);
                     break;
                 }
                 default:
-                    snprintf(tmp2, sizeof(tmp2), "??? ");
+                    fdprintf(fd, "??? ");
             }
-            strncat(tmp1, tmp2, sizeof(tmp1));
         }
-        ALOGD(" [ %s]", tmp1);
+        fdprintf(fd, "]\n");
     }
 }
index 5d394e2..fada37e 100644 (file)
@@ -139,7 +139,7 @@ tag_info_t android_sensor_info[ANDROID_SENSOR_INFO_END -
         ANDROID_SENSOR_INFO_START] = {
     { "exposureTimeRange",      TYPE_INT64 },
     { "maxFrameDuration",       TYPE_INT64 },
-    { "sensitivityRange",       TYPE_INT32 },
+    { "availableSensitivities", TYPE_INT32 },
     { "colorFilterArrangement", TYPE_BYTE },
     { "pixelArraySize",         TYPE_INT32 },
     { "activeArraySize",        TYPE_INT32 },
index 3f1800e..53a4c45 100644 (file)
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <errno.h>
+
 #include "gtest/gtest.h"
 #include "system/camera_metadata.h"
 
@@ -24,6 +26,7 @@
 
 #define OK    0
 #define ERROR 1
+#define NOT_FOUND (-ENOENT)
 
 TEST(camera_metadata, allocate_normal) {
     camera_metadata_t *m = NULL;
@@ -270,7 +273,7 @@ TEST(camera_metadata, add_get_normal) {
     EXPECT_EQ(calculate_camera_metadata_size(entries_used, data_used),
             get_camera_metadata_compact_size(m) );
 
-    dump_camera_metadata(m, 2);
+    dump_camera_metadata(m, 0, 2);
 
     free_camera_metadata(m);
 }
@@ -342,7 +345,7 @@ TEST(camera_metadata, add_get_toomany) {
     EXPECT_EQ((size_t)0, data_count);
     EXPECT_EQ(NULL, data_int32);
 
-    dump_camera_metadata(m, 2);
+    dump_camera_metadata(m, 0, 2);
 
     free_camera_metadata(m);
 }
@@ -823,7 +826,100 @@ TEST(camera_metadata, add_all_tags) {
         }
     }
 
-    dump_camera_metadata(m, 2);
+    dump_camera_metadata(m, 0, 2);
+
+    free_camera_metadata(m);
+}
+
+TEST(camera_metadata, sort_metadata) {
+    camera_metadata_t *m = NULL;
+    const size_t entry_capacity = 5;
+    const size_t data_capacity = 100;
+
+    int result;
+
+    m = allocate_camera_metadata(entry_capacity, data_capacity);
+
+    // Add several unique entries in non-sorted order
+
+    float colorTransform[9] = {
+        0.9f, 0.0f, 0.0f,
+        0.2f, 0.5f, 0.0f,
+        0.0f, 0.1f, 0.7f
+    };
+    result = add_camera_metadata_entry(m,
+            ANDROID_COLOR_TRANSFORM,
+            colorTransform, 9);
+    EXPECT_EQ(OK, result);
+
+    float focus_distance = 0.5f;
+    result = add_camera_metadata_entry(m,
+            ANDROID_LENS_FOCUS_DISTANCE,
+            &focus_distance, 1);
+    EXPECT_EQ(OK, result);
+
+    int64_t exposure_time = 1000000000;
+    result = add_camera_metadata_entry(m,
+            ANDROID_SENSOR_EXPOSURE_TIME,
+            &exposure_time, 1);
+    EXPECT_EQ(OK, result);
+
+    int32_t sensitivity = 800;
+    result = add_camera_metadata_entry(m,
+            ANDROID_SENSOR_SENSITIVITY,
+            &sensitivity, 1);
+    EXPECT_EQ(OK, result);
+
+    // Test unsorted find
+    uint8_t type;
+    float  *f;
+    size_t  data_count;
+    result = find_camera_metadata_entry(m,
+            ANDROID_LENS_FOCUS_DISTANCE,
+            &type,
+            (void**)&f,
+            &data_count);
+    EXPECT_EQ(OK, result);
+    EXPECT_EQ(TYPE_FLOAT, type);
+    EXPECT_EQ(1, (int)data_count);
+    EXPECT_EQ(focus_distance, *f);
+
+    result = find_camera_metadata_entry(m,
+            ANDROID_NOISE_STRENGTH,
+            &type,
+            (void**)&f,
+            &data_count);
+    EXPECT_EQ(NOT_FOUND, result);
+
+    // Sort
+    std::cout << "Pre-sorted metadata" << std::endl;
+    dump_camera_metadata(m, 0, 2);
+
+    result = sort_camera_metadata(m);
+    EXPECT_EQ(OK, result);
+
+    std::cout << "Sorted metadata" << std::endl;
+    dump_camera_metadata(m, 0, 2);
+
+    // Test sorted find
+
+    result = find_camera_metadata_entry(m,
+            ANDROID_LENS_FOCUS_DISTANCE,
+            &type,
+            (void**)&f,
+            &data_count);
+    EXPECT_EQ(OK, result);
+    EXPECT_EQ(TYPE_FLOAT, type);
+    EXPECT_EQ(1, (int)data_count);
+    EXPECT_EQ(focus_distance, *f);
+
+    result = find_camera_metadata_entry(m,
+            ANDROID_NOISE_STRENGTH,
+            &type,
+            (void**)&f,
+            &data_count);
+    EXPECT_EQ(NOT_FOUND, result);
+
 
     free_camera_metadata(m);
 }
index 8522fa6..8e08776 100644 (file)
@@ -104,7 +104,22 @@ vendor_tag_info_t *fakevendor_tag_info[FAKEVENDOR_SECTION_COUNT] = {
     fakevendor_scaler
 };
 
-const char *get_fakevendor_section_name(uint32_t tag) {
+const char *get_fakevendor_section_name(const vendor_tag_query_ops_t *v,
+        uint32_t tag);
+const char *get_fakevendor_tag_name(const vendor_tag_query_ops_t *v,
+        uint32_t tag);
+int get_fakevendor_tag_type(const vendor_tag_query_ops_t *v,
+        uint32_t tag);
+
+static const vendor_tag_query_ops_t fakevendor_query_ops = {
+    get_fakevendor_section_name,
+    get_fakevendor_tag_name,
+    get_fakevendor_tag_type
+};
+
+const char *get_fakevendor_section_name(const vendor_tag_query_ops_t *v,
+        uint32_t tag) {
+    if (v != &fakevendor_query_ops) return NULL;
     int tag_section = (tag >> 16) - VENDOR_SECTION;
     if (tag_section < 0 ||
             tag_section >= FAKEVENDOR_SECTION_COUNT) return NULL;
@@ -112,7 +127,9 @@ const char *get_fakevendor_section_name(uint32_t tag) {
     return fakevendor_section_names[tag_section];
 }
 
-const char *get_fakevendor_tag_name(uint32_t tag) {
+const char *get_fakevendor_tag_name(const vendor_tag_query_ops_t *v,
+        uint32_t tag) {
+    if (v != &fakevendor_query_ops) return NULL;
     int tag_section = (tag >> 16) - VENDOR_SECTION;
     if (tag_section < 0
             || tag_section >= FAKEVENDOR_SECTION_COUNT
@@ -121,7 +138,9 @@ const char *get_fakevendor_tag_name(uint32_t tag) {
     return fakevendor_tag_info[tag_section][tag_index].tag_name;
 }
 
-int get_fakevendor_tag_type(uint32_t tag) {
+int get_fakevendor_tag_type(const vendor_tag_query_ops_t *v,
+        uint32_t tag) {
+    if (v != &fakevendor_query_ops) return -1;
     int tag_section = (tag >> 16) - VENDOR_SECTION;
     if (tag_section < 0
             || tag_section >= FAKEVENDOR_SECTION_COUNT
@@ -130,10 +149,5 @@ int get_fakevendor_tag_type(uint32_t tag) {
     return fakevendor_tag_info[tag_section][tag_index].tag_type;
 }
 
-static const vendor_tag_query_ops_t fakevendor_query_ops = {
-    get_fakevendor_section_name,
-    get_fakevendor_tag_name,
-    get_fakevendor_tag_type
-};
 
 #endif