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