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 38 using namespace android; 39 40 namespace qcamera { 41 42 const int QCAMERA3_SECTION_COUNT = QCAMERA3_SECTIONS_END - VENDOR_SECTION; 43 44 enum qcamera3_ext_tags qcamera3_ext3_section_bounds[QCAMERA3_SECTIONS_END - 45 VENDOR_SECTION] = { 46 QCAMERA3_PRIVATEDATA_END, 47 QCAMERA3_OPAQUE_RAW_END 48 } ; 49 50 typedef struct vendor_tag_info { 51 const char *tag_name; 52 uint8_t tag_type; 53 } vendor_tag_info_t; 54 55 const char *qcamera3_ext_section_names[QCAMERA3_SECTIONS_END - 56 VENDOR_SECTION] = { 57 "org.codeaurora.qcamera3.privatedata", 58 "org.codeaurora.qcamera3.opaque_raw" 59 }; 60 61 vendor_tag_info_t qcamera3_privatedata[QCAMERA3_PRIVATEDATA_END - QCAMERA3_PRIVATEDATA_START] = { 62 { "privatedata_reprocess", TYPE_BYTE } 63 }; 64 65 vendor_tag_info_t qcamera3_opaque_raw[QCAMERA3_OPAQUE_RAW_END - QCAMERA3_OPAQUE_RAW_START] = { 66 { "opaque_raw_strides", TYPE_INT32 }, 67 { "opaque_raw_format", TYPE_BYTE } 68 }; 69 70 vendor_tag_info_t *qcamera3_tag_info[QCAMERA3_SECTIONS_END - 71 VENDOR_SECTION] = { 72 qcamera3_privatedata, 73 qcamera3_opaque_raw 74 }; 75 76 uint32_t qcamera3_all_tags[] = { 77 // QCAMERA3_PRIVATEDATA 78 (uint32_t)QCAMERA3_PRIVATEDATA_REPROCESS, 79 80 // QCAMERA3_OPAQUE_RAW 81 (uint32_t)QCAMERA3_OPAQUE_RAW_STRIDES, 82 (uint32_t)QCAMERA3_OPAQUE_RAW_FORMAT 83 }; 84 85 const vendor_tag_ops_t* QCamera3VendorTags::Ops = NULL; 86 87 /*=========================================================================== 88 * FUNCTION : get_vendor_tag_ops 89 * 90 * DESCRIPTION: Get the metadata vendor tag function pointers 91 * 92 * PARAMETERS : 93 * @ops : function pointer table to be filled by HAL 94 * 95 * 96 * RETURN : NONE 97 *==========================================================================*/ 98 void QCamera3VendorTags::get_vendor_tag_ops( 99 vendor_tag_ops_t* ops) 100 { 101 ALOGV("%s: E", __func__); 102 103 Ops = ops; 104 105 ops->get_tag_count = get_tag_count; 106 ops->get_all_tags = get_all_tags; 107 ops->get_section_name = get_section_name; 108 ops->get_tag_name = get_tag_name; 109 ops->get_tag_type = get_tag_type; 110 ops->reserved[0] = NULL; 111 112 ALOGV("%s: X", __func__); 113 return; 114 } 115 116 /*=========================================================================== 117 * FUNCTION : get_tag_count 118 * 119 * DESCRIPTION: Get number of vendor tags supported 120 * 121 * PARAMETERS : 122 * @ops : Vendor tag ops data structure 123 * 124 * 125 * RETURN : Number of vendor tags supported 126 *==========================================================================*/ 127 128 int QCamera3VendorTags::get_tag_count( 129 const vendor_tag_ops_t * ops) 130 { 131 int count = 0; 132 if (ops == Ops) 133 count = sizeof(qcamera3_all_tags)/sizeof(qcamera3_all_tags[0]); 134 135 ALOGV("%s: count is %d", __func__, count); 136 return count; 137 } 138 139 /*=========================================================================== 140 * FUNCTION : get_all_tags 141 * 142 * DESCRIPTION: Fill array with all supported vendor tags 143 * 144 * PARAMETERS : 145 * @ops : Vendor tag ops data structure 146 * @tag_array: array of metadata tags 147 * 148 * RETURN : Success: the section name of the specific tag 149 * Failure: NULL 150 *==========================================================================*/ 151 void QCamera3VendorTags::get_all_tags( 152 const vendor_tag_ops_t * ops, 153 uint32_t *g_array) 154 { 155 if (ops != Ops) 156 return; 157 158 for (size_t i = 0; 159 i < sizeof(qcamera3_all_tags)/sizeof(qcamera3_all_tags[0]); 160 i++) { 161 g_array[i] = qcamera3_all_tags[i]; 162 ALOGV("%s: g_array[%d] is %d", __func__, i, g_array[i]); 163 } 164 } 165 166 /*=========================================================================== 167 * FUNCTION : get_section_name 168 * 169 * DESCRIPTION: Get section name for vendor tag 170 * 171 * PARAMETERS : 172 * @ops : Vendor tag ops structure 173 * @tag : Vendor specific tag 174 * 175 * 176 * RETURN : Success: the section name of the specific tag 177 * Failure: NULL 178 *==========================================================================*/ 179 180 const char* QCamera3VendorTags::get_section_name( 181 const vendor_tag_ops_t * ops, 182 uint32_t tag) 183 { 184 ALOGV("%s: E", __func__); 185 if (ops != Ops) 186 return NULL; 187 188 const char *ret; 189 uint32_t section = tag >> 16; 190 191 if (section < VENDOR_SECTION || section > QCAMERA3_SECTIONS_END) 192 ret = NULL; 193 else 194 ret = qcamera3_ext_section_names[section - VENDOR_SECTION]; 195 196 if (ret) 197 ALOGV("%s: section_name[%d] is %s", __func__, tag, ret); 198 ALOGV("%s: X", __func__); 199 return ret; 200 } 201 202 /*=========================================================================== 203 * FUNCTION : get_tag_name 204 * 205 * DESCRIPTION: Get name of a vendor specific tag 206 * 207 * PARAMETERS : 208 * @tag : Vendor specific tag 209 * 210 * 211 * RETURN : Success: the name of the specific tag 212 * Failure: NULL 213 *==========================================================================*/ 214 const char* QCamera3VendorTags::get_tag_name( 215 const vendor_tag_ops_t * ops, 216 uint32_t tag) 217 { 218 ALOGV("%s: E", __func__); 219 const char *ret; 220 uint32_t section = tag >> 16; 221 uint32_t section_index = section - VENDOR_SECTION; 222 uint32_t tag_index = tag & 0xFFFF; 223 224 if (ops != Ops) { 225 ret = NULL; 226 goto done; 227 } 228 229 if (section < VENDOR_SECTION || section > QCAMERA3_SECTIONS_END) 230 ret = NULL; 231 else if (tag >= (uint32_t)qcamera3_ext3_section_bounds[section_index]) 232 ret = NULL; 233 else 234 ret = qcamera3_tag_info[section_index][tag_index].tag_name; 235 236 if (ret) 237 ALOGV("%s: tag name for tag %d is %s", __func__, tag, ret); 238 ALOGV("%s: X", __func__); 239 240 done: 241 return ret; 242 } 243 244 /*=========================================================================== 245 * FUNCTION : get_tag_type 246 * 247 * DESCRIPTION: Get type of a vendor specific tag 248 * 249 * PARAMETERS : 250 * @tag : Vendor specific tag 251 * 252 * 253 * RETURN : Success: the type of the specific tag 254 * Failure: -1 255 *==========================================================================*/ 256 int QCamera3VendorTags::get_tag_type( 257 const vendor_tag_ops_t *ops, 258 uint32_t tag) 259 { 260 ALOGV("%s: E", __func__); 261 int ret; 262 uint32_t section = tag >> 16; 263 uint32_t section_index = section - VENDOR_SECTION; 264 uint32_t tag_index = tag & 0xFFFF; 265 266 if (ops != Ops) { 267 ret = -1; 268 goto done; 269 } 270 if (section < VENDOR_SECTION || section > QCAMERA3_SECTIONS_END) 271 ret = -1; 272 else if (tag >= (uint32_t )qcamera3_ext3_section_bounds[section_index]) 273 ret = -1; 274 else 275 ret = qcamera3_tag_info[section_index][tag_index].tag_type; 276 277 ALOGV("%s: tag type for tag %d is %d", __func__, tag, ret); 278 ALOGV("%s: X", __func__); 279 done: 280 return ret; 281 } 282 283 }; //end namespace qcamera 284