QCamera3VendorTags.cpp revision 176b827c0d215524c39a35149bba09f8ee4ead00
1/* Copyright (c) 2014, The Linux Foundataion. All rights reserved. 2* 3* Redistribution and use in source and binary forms, with or without 4* modification, are permitted provided that the following conditions are 5* met: 6* * Redistributions of source code must retain the above copyright 7* notice, this list of conditions and the following disclaimer. 8* * Redistributions in binary form must reproduce the above 9* copyright notice, this list of conditions and the following 10* disclaimer in the documentation and/or other materials provided 11* with the distribution. 12* * Neither the name of The Linux Foundation nor the names of its 13* contributors may be used to endorse or promote products derived 14* from this software without specific prior written permission. 15* 16* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27* 28*/ 29 30#define LOG_TAG "QCamera3VendorTags" 31//#define LOG_NDEBUG 0 32 33#include <hardware/camera3.h> 34#include <utils/Log.h> 35#include <utils/Errors.h> 36#include "QCamera3VendorTags.h" 37 38using namespace android; 39 40namespace qcamera { 41 42const int QCAMERA3_SECTION_COUNT = QCAMERA3_SECTIONS_END - VENDOR_SECTION; 43 44enum qcamera3_ext_tags qcamera3_ext3_section_bounds[QCAMERA3_SECTIONS_END - 45 VENDOR_SECTION] = { 46 QCAMERA3_PRIVATEDATA_END 47} ; 48 49typedef struct vendor_tag_info { 50 const char *tag_name; 51 uint8_t tag_type; 52} vendor_tag_info_t; 53 54const char *qcamera3_ext_section_names[QCAMERA3_SECTIONS_END - 55 VENDOR_SECTION] = { 56 "org.codeaurora.qcamera3.privatedata" 57}; 58 59vendor_tag_info_t qcamera3_privatedata[QCAMERA3_PRIVATEDATA_END - QCAMERA3_PRIVATEDATA_START] = { 60 { "privatedata", TYPE_BYTE } 61}; 62 63vendor_tag_info_t *qcamera3_tag_info[QCAMERA3_SECTIONS_END - 64 VENDOR_SECTION] = { 65 qcamera3_privatedata 66}; 67 68uint32_t qcamera3_all_tags[] = { 69 // QCAMERA3_PRIVATEDATA 70 (uint32_t)QCAMERA3_PRIVATEDATA_REPROCESS 71}; 72 73const vendor_tag_ops_t* QCamera3VendorTags::Ops = NULL; 74 75/*=========================================================================== 76 * FUNCTION : get_vendor_tag_ops 77 * 78 * DESCRIPTION: Get the metadata vendor tag function pointers 79 * 80 * PARAMETERS : 81 * @ops : function pointer table to be filled by HAL 82 * 83 * 84 * RETURN : NONE 85 *==========================================================================*/ 86void QCamera3VendorTags::get_vendor_tag_ops( 87 vendor_tag_ops_t* ops) 88{ 89 ALOGV("%s: E", __func__); 90 91 Ops = ops; 92 93 ops->get_tag_count = get_tag_count; 94 ops->get_all_tags = get_all_tags; 95 ops->get_section_name = get_section_name; 96 ops->get_tag_name = get_tag_name; 97 ops->get_tag_type = get_tag_type; 98 ops->reserved[0] = NULL; 99 100 ALOGV("%s: X", __func__); 101 return; 102} 103 104/*=========================================================================== 105 * FUNCTION : get_tag_count 106 * 107 * DESCRIPTION: Get number of vendor tags supported 108 * 109 * PARAMETERS : 110 * @ops : Vendor tag ops data structure 111 * 112 * 113 * RETURN : Number of vendor tags supported 114 *==========================================================================*/ 115 116int QCamera3VendorTags::get_tag_count( 117 const vendor_tag_ops_t * ops) 118{ 119 int count = 0; 120 if (ops == Ops) 121 count = sizeof(qcamera3_all_tags)/sizeof(qcamera3_all_tags[0]); 122 123 ALOGV("%s: count is %d", __func__, count); 124 return count; 125} 126 127/*=========================================================================== 128 * FUNCTION : get_all_tags 129 * 130 * DESCRIPTION: Fill array with all supported vendor tags 131 * 132 * PARAMETERS : 133 * @ops : Vendor tag ops data structure 134 * @tag_array: array of metadata tags 135 * 136 * RETURN : Success: the section name of the specific tag 137 * Failure: NULL 138 *==========================================================================*/ 139void QCamera3VendorTags::get_all_tags( 140 const vendor_tag_ops_t * ops, 141 uint32_t *g_array) 142{ 143 if (ops != Ops) 144 return; 145 146 for (size_t i = 0; 147 i < sizeof(qcamera3_all_tags)/sizeof(qcamera3_all_tags[0]); 148 i++) { 149 g_array[i] = qcamera3_all_tags[i]; 150 ALOGV("%s: g_array[%d] is %d", __func__, i, g_array[i]); 151 } 152} 153 154/*=========================================================================== 155 * FUNCTION : get_section_name 156 * 157 * DESCRIPTION: Get section name for vendor tag 158 * 159 * PARAMETERS : 160 * @ops : Vendor tag ops structure 161 * @tag : Vendor specific tag 162 * 163 * 164 * RETURN : Success: the section name of the specific tag 165 * Failure: NULL 166 *==========================================================================*/ 167 168const char* QCamera3VendorTags::get_section_name( 169 const vendor_tag_ops_t * ops, 170 uint32_t tag) 171{ 172 ALOGV("%s: E", __func__); 173 if (ops != Ops) 174 return NULL; 175 176 const char *ret; 177 uint32_t section = tag >> 16; 178 179 if (section < VENDOR_SECTION || section > QCAMERA3_SECTIONS_END) 180 ret = NULL; 181 else 182 ret = qcamera3_ext_section_names[section - VENDOR_SECTION]; 183 184 if (ret) 185 ALOGV("%s: section_name[%d] is %s", __func__, tag, ret); 186 ALOGV("%s: X", __func__); 187 return ret; 188} 189 190/*=========================================================================== 191 * FUNCTION : get_tag_name 192 * 193 * DESCRIPTION: Get name of a vendor specific tag 194 * 195 * PARAMETERS : 196 * @tag : Vendor specific tag 197 * 198 * 199 * RETURN : Success: the name of the specific tag 200 * Failure: NULL 201 *==========================================================================*/ 202const char* QCamera3VendorTags::get_tag_name( 203 const vendor_tag_ops_t * ops, 204 uint32_t tag) 205{ 206 ALOGV("%s: E", __func__); 207 const char *ret; 208 uint32_t section = tag >> 16; 209 uint32_t section_index = section - VENDOR_SECTION; 210 uint32_t tag_index = tag & 0xFFFF; 211 212 if (ops != Ops) { 213 ret = NULL; 214 goto done; 215 } 216 217 if (section < VENDOR_SECTION || section > QCAMERA3_SECTIONS_END) 218 ret = NULL; 219 else if (tag >= (uint32_t)qcamera3_ext3_section_bounds[section_index]) 220 ret = NULL; 221 else 222 ret = qcamera3_tag_info[section_index][tag_index].tag_name; 223 224 if (ret) 225 ALOGV("%s: tag name for tag %d is %s", __func__, tag, ret); 226 ALOGV("%s: X", __func__); 227 228done: 229 return ret; 230} 231 232/*=========================================================================== 233 * FUNCTION : get_tag_type 234 * 235 * DESCRIPTION: Get type of a vendor specific tag 236 * 237 * PARAMETERS : 238 * @tag : Vendor specific tag 239 * 240 * 241 * RETURN : Success: the type of the specific tag 242 * Failure: -1 243 *==========================================================================*/ 244int QCamera3VendorTags::get_tag_type( 245 const vendor_tag_ops_t *ops, 246 uint32_t tag) 247{ 248 ALOGV("%s: E", __func__); 249 int ret; 250 uint32_t section = tag >> 16; 251 uint32_t section_index = section - VENDOR_SECTION; 252 uint32_t tag_index = tag & 0xFFFF; 253 254 if (ops != Ops) { 255 ret = -1; 256 goto done; 257 } 258 if (section < VENDOR_SECTION || section > QCAMERA3_SECTIONS_END) 259 ret = -1; 260 else if (tag >= (uint32_t )qcamera3_ext3_section_bounds[section_index]) 261 ret = -1; 262 else 263 ret = qcamera3_tag_info[section_index][tag_index].tag_type; 264 265 ALOGV("%s: tag type for tag %d is %d", __func__, tag, ret); 266 ALOGV("%s: X", __func__); 267done: 268 return ret; 269} 270 271}; //end namespace qcamera 272