Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <system/camera_metadata.h>
     18 #include "Metadata.h"
     19 
     20 //#define LOG_NDEBUG 0
     21 #define LOG_TAG "VendorTags"
     22 #include <cutils/log.h>
     23 
     24 #define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
     25 #include <utils/Trace.h>
     26 
     27 #include "VendorTags.h"
     28 
     29 namespace default_camera_hal {
     30 
     31 // Internal representations of vendor tags for convenience.
     32 // Other classes must access this data via public interfaces.
     33 // Structured to be easy to extend and contain complexity.
     34 namespace {
     35 // Describes a single vendor tag entry
     36 struct Entry {
     37     const char* name;
     38     uint8_t     type;
     39 };
     40 // Describes a vendor tag section
     41 struct Section {
     42     const char* name;
     43     uint32_t start;
     44     uint32_t end;
     45     const Entry* tags;
     46 };
     47 
     48 // Entry arrays for each section
     49 const Entry DemoWizardry[demo_wizardry_end - demo_wizardry_start] = {
     50     [demo_wizardry_dimension_size - demo_wizardry_start] =
     51         {"dimensionSize",   TYPE_INT32},
     52     [demo_wizardry_dimensions - demo_wizardry_start] =
     53         {"dimensions",      TYPE_INT32},
     54     [demo_wizardry_familiar - demo_wizardry_start] =
     55         {"familiar",        TYPE_BYTE},
     56     [demo_wizardry_fire - demo_wizardry_start] =
     57         {"fire",            TYPE_RATIONAL}
     58 };
     59 
     60 const Entry DemoSorcery[demo_sorcery_end - demo_sorcery_start] = {
     61     [demo_sorcery_difficulty - demo_sorcery_start] =
     62         {"difficulty",      TYPE_INT64},
     63     [demo_sorcery_light - demo_sorcery_start] =
     64         {"light",           TYPE_BYTE}
     65 };
     66 
     67 const Entry DemoMagic[demo_magic_end - demo_magic_start] = {
     68     [demo_magic_card_trick - demo_magic_start] =
     69         {"cardTrick",       TYPE_DOUBLE},
     70     [demo_magic_levitation - demo_magic_start] =
     71         {"levitation",      TYPE_FLOAT}
     72 };
     73 
     74 // Array of all sections
     75 const Section DemoSections[DEMO_SECTION_COUNT] = {
     76     [DEMO_WIZARDRY] = { "demo.wizardry",
     77                         demo_wizardry_start,
     78                         demo_wizardry_end,
     79                         DemoWizardry },
     80     [DEMO_SORCERY]  = { "demo.sorcery",
     81                         demo_sorcery_start,
     82                         demo_sorcery_end,
     83                         DemoSorcery },
     84     [DEMO_MAGIC]    = { "demo.magic",
     85                         demo_magic_start,
     86                         demo_magic_end,
     87                         DemoMagic }
     88 };
     89 
     90 // Get a static handle to a specific vendor tag section
     91 const Section* getSection(uint32_t tag)
     92 {
     93     uint32_t section = (tag - vendor_section_start) >> 16;
     94 
     95     if (tag < vendor_section_start) {
     96         ALOGE("%s: Tag 0x%x before vendor section", __func__, tag);
     97         return NULL;
     98     }
     99 
    100     if (section >= DEMO_SECTION_COUNT) {
    101         ALOGE("%s: Tag 0x%x after vendor section", __func__, tag);
    102         return NULL;
    103     }
    104 
    105     return &DemoSections[section];
    106 }
    107 
    108 // Get a static handle to a specific vendor tag entry
    109 const Entry* getEntry(uint32_t tag)
    110 {
    111     const Section* section = getSection(tag);
    112     int index;
    113 
    114     if (section == NULL)
    115         return NULL;
    116 
    117     if (tag >= section->end) {
    118         ALOGE("%s: Tag 0x%x outside section", __func__, tag);
    119         return NULL;
    120     }
    121 
    122     index = tag - section->start;
    123     return &section->tags[index];
    124 }
    125 } // namespace
    126 
    127 VendorTags::VendorTags()
    128   : mTagCount(0)
    129 {
    130     for (int i = 0; i < DEMO_SECTION_COUNT; i++) {
    131         mTagCount += DemoSections[i].end - DemoSections[i].start;
    132     }
    133 }
    134 
    135 VendorTags::~VendorTags()
    136 {
    137 }
    138 
    139 int VendorTags::getTagCount(const vendor_tag_ops_t* ops)
    140 {
    141     return mTagCount;
    142 }
    143 
    144 void VendorTags::getAllTags(const vendor_tag_ops_t* ops, uint32_t* tag_array)
    145 {
    146     if (tag_array == NULL) {
    147         ALOGE("%s: NULL tag_array", __func__);
    148         return;
    149     }
    150 
    151     for (int i = 0; i < DEMO_SECTION_COUNT; i++) {
    152         for (uint32_t tag = DemoSections[i].start;
    153                 tag < DemoSections[i].end; tag++) {
    154             *tag_array++ = tag;
    155         }
    156     }
    157 }
    158 
    159 const char* VendorTags::getSectionName(const vendor_tag_ops_t* ops, uint32_t tag)
    160 {
    161     const Section* section = getSection(tag);
    162 
    163     if (section == NULL)
    164         return NULL;
    165 
    166     return section->name;
    167 }
    168 
    169 const char* VendorTags::getTagName(const vendor_tag_ops_t* ops, uint32_t tag)
    170 {
    171     const Entry* entry = getEntry(tag);
    172 
    173     if (entry == NULL)
    174         return NULL;
    175 
    176     return entry->name;
    177 }
    178 
    179 int VendorTags::getTagType(const vendor_tag_ops_t* ops, uint32_t tag)
    180 {
    181     const Entry* entry = getEntry(tag);
    182 
    183     if (entry == NULL)
    184         return -1;
    185 
    186     return entry->type;
    187 }
    188 } // namespace default_camera_hal
    189