• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #define LOG_TAG "CamComm1.0-CamModule"
18 #define ATRACE_TAG ATRACE_TAG_CAMERA
19 //#define LOG_NDEBUG 0
20 
21 #include <utils/Trace.h>
22 
23 #include "CameraModule.h"
24 
25 namespace android {
26 namespace hardware {
27 namespace camera {
28 namespace common {
29 namespace V1_0 {
30 namespace helper {
31 
deriveCameraCharacteristicsKeys(uint32_t deviceVersion,CameraMetadata & chars)32 void CameraModule::deriveCameraCharacteristicsKeys(
33         uint32_t deviceVersion, CameraMetadata &chars) {
34     ATRACE_CALL();
35 
36     Vector<int32_t> derivedCharKeys;
37     Vector<int32_t> derivedRequestKeys;
38     Vector<int32_t> derivedResultKeys;
39     // Keys added in HAL3.3
40     if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_3) {
41         Vector<uint8_t> controlModes;
42         uint8_t data = ANDROID_CONTROL_AE_LOCK_AVAILABLE_TRUE;
43         chars.update(ANDROID_CONTROL_AE_LOCK_AVAILABLE, &data, /*count*/1);
44         data = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_TRUE;
45         chars.update(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, &data, /*count*/1);
46         controlModes.push(ANDROID_CONTROL_MODE_AUTO);
47         camera_metadata_entry entry = chars.find(ANDROID_CONTROL_AVAILABLE_SCENE_MODES);
48         if (entry.count > 1 || entry.data.u8[0] != ANDROID_CONTROL_SCENE_MODE_DISABLED) {
49             controlModes.push(ANDROID_CONTROL_MODE_USE_SCENE_MODE);
50         }
51 
52         // Only advertise CONTROL_OFF mode if 3A manual controls are supported.
53         bool isManualAeSupported = false;
54         bool isManualAfSupported = false;
55         bool isManualAwbSupported = false;
56         entry = chars.find(ANDROID_CONTROL_AE_AVAILABLE_MODES);
57         if (entry.count > 0) {
58             for (size_t i = 0; i < entry.count; i++) {
59                 if (entry.data.u8[i] == ANDROID_CONTROL_AE_MODE_OFF) {
60                     isManualAeSupported = true;
61                     break;
62                 }
63             }
64         }
65         entry = chars.find(ANDROID_CONTROL_AF_AVAILABLE_MODES);
66         if (entry.count > 0) {
67             for (size_t i = 0; i < entry.count; i++) {
68                 if (entry.data.u8[i] == ANDROID_CONTROL_AF_MODE_OFF) {
69                     isManualAfSupported = true;
70                     break;
71                 }
72             }
73         }
74         entry = chars.find(ANDROID_CONTROL_AWB_AVAILABLE_MODES);
75         if (entry.count > 0) {
76             for (size_t i = 0; i < entry.count; i++) {
77                 if (entry.data.u8[i] == ANDROID_CONTROL_AWB_MODE_OFF) {
78                     isManualAwbSupported = true;
79                     break;
80                 }
81             }
82         }
83         if (isManualAeSupported && isManualAfSupported && isManualAwbSupported) {
84             controlModes.push(ANDROID_CONTROL_MODE_OFF);
85         }
86 
87         chars.update(ANDROID_CONTROL_AVAILABLE_MODES, controlModes);
88 
89         entry = chars.find(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS);
90         // HAL3.2 devices passing existing CTS test should all support all LSC modes and LSC map
91         bool lensShadingModeSupported = false;
92         if (entry.count > 0) {
93             for (size_t i = 0; i < entry.count; i++) {
94                 if (entry.data.i32[i] == ANDROID_SHADING_MODE) {
95                     lensShadingModeSupported = true;
96                     break;
97                 }
98             }
99         }
100         Vector<uint8_t> lscModes;
101         Vector<uint8_t> lscMapModes;
102         lscModes.push(ANDROID_SHADING_MODE_FAST);
103         lscModes.push(ANDROID_SHADING_MODE_HIGH_QUALITY);
104         lscMapModes.push(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF);
105         if (lensShadingModeSupported) {
106             lscModes.push(ANDROID_SHADING_MODE_OFF);
107             lscMapModes.push(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_ON);
108         }
109         chars.update(ANDROID_SHADING_AVAILABLE_MODES, lscModes);
110         chars.update(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, lscMapModes);
111 
112         derivedCharKeys.push(ANDROID_CONTROL_AE_LOCK_AVAILABLE);
113         derivedCharKeys.push(ANDROID_CONTROL_AWB_LOCK_AVAILABLE);
114         derivedCharKeys.push(ANDROID_CONTROL_AVAILABLE_MODES);
115         derivedCharKeys.push(ANDROID_SHADING_AVAILABLE_MODES);
116         derivedCharKeys.push(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES);
117 
118         // Need update android.control.availableHighSpeedVideoConfigurations since HAL3.3
119         // adds batch size to this array.
120         entry = chars.find(ANDROID_CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS);
121         if (entry.count > 0) {
122             Vector<int32_t> highSpeedConfig;
123             for (size_t i = 0; i < entry.count; i += 4) {
124                 highSpeedConfig.add(entry.data.i32[i]); // width
125                 highSpeedConfig.add(entry.data.i32[i + 1]); // height
126                 highSpeedConfig.add(entry.data.i32[i + 2]); // fps_min
127                 highSpeedConfig.add(entry.data.i32[i + 3]); // fps_max
128                 highSpeedConfig.add(1); // batchSize_max. default to 1 for HAL3.2
129             }
130             chars.update(ANDROID_CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS,
131                     highSpeedConfig);
132         }
133     }
134 
135     // Keys added in HAL3.4
136     if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_4) {
137         // Check if HAL supports RAW_OPAQUE output
138         camera_metadata_entry entry = chars.find(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS);
139         bool supportRawOpaque = false;
140         bool supportAnyRaw = false;
141         const int STREAM_CONFIGURATION_SIZE = 4;
142         const int STREAM_FORMAT_OFFSET = 0;
143         const int STREAM_WIDTH_OFFSET = 1;
144         const int STREAM_HEIGHT_OFFSET = 2;
145         const int STREAM_IS_INPUT_OFFSET = 3;
146         Vector<int32_t> rawOpaqueSizes;
147 
148         for (size_t i=0; i < entry.count; i += STREAM_CONFIGURATION_SIZE) {
149             int32_t format = entry.data.i32[i + STREAM_FORMAT_OFFSET];
150             int32_t width = entry.data.i32[i + STREAM_WIDTH_OFFSET];
151             int32_t height = entry.data.i32[i + STREAM_HEIGHT_OFFSET];
152             int32_t isInput = entry.data.i32[i + STREAM_IS_INPUT_OFFSET];
153             if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT &&
154                     format == HAL_PIXEL_FORMAT_RAW_OPAQUE) {
155                 supportRawOpaque = true;
156                 rawOpaqueSizes.push(width);
157                 rawOpaqueSizes.push(height);
158                 // 2 bytes per pixel. This rough estimation is only used when
159                 // HAL does not fill in the opaque raw size
160                 rawOpaqueSizes.push(width * height *2);
161             }
162             if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT &&
163                     (format == HAL_PIXEL_FORMAT_RAW16 ||
164                      format == HAL_PIXEL_FORMAT_RAW10 ||
165                      format == HAL_PIXEL_FORMAT_RAW12 ||
166                      format == HAL_PIXEL_FORMAT_RAW_OPAQUE)) {
167                 supportAnyRaw = true;
168             }
169         }
170 
171         if (supportRawOpaque) {
172             entry = chars.find(ANDROID_SENSOR_OPAQUE_RAW_SIZE);
173             if (entry.count == 0) {
174                 // Fill in estimated value if HAL does not list it
175                 chars.update(ANDROID_SENSOR_OPAQUE_RAW_SIZE, rawOpaqueSizes);
176                 derivedCharKeys.push(ANDROID_SENSOR_OPAQUE_RAW_SIZE);
177             }
178         }
179 
180         // Check if HAL supports any RAW output, if so, fill in postRawSensitivityBoost range
181         if (supportAnyRaw) {
182             int32_t defaultRange[2] = {100, 100};
183             entry = chars.find(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE);
184             if (entry.count == 0) {
185                 // Fill in default value (100, 100)
186                 chars.update(
187                         ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE,
188                         defaultRange, 2);
189                 derivedCharKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE);
190                 // Actual request/results will be derived by camera device.
191                 derivedRequestKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST);
192                 derivedResultKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST);
193             }
194         }
195     }
196 
197     // Always add a default for the pre-correction active array if the vendor chooses to omit this
198     camera_metadata_entry entry = chars.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
199     if (entry.count == 0) {
200         Vector<int32_t> preCorrectionArray;
201         entry = chars.find(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE);
202         preCorrectionArray.appendArray(entry.data.i32, entry.count);
203         chars.update(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE, preCorrectionArray);
204         derivedCharKeys.push(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
205     }
206 
207     // Add those newly added keys to AVAILABLE_CHARACTERISTICS_KEYS
208     // This has to be done at this end of this function.
209     if (derivedCharKeys.size() > 0) {
210         appendAvailableKeys(
211                 chars, ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, derivedCharKeys);
212     }
213     if (derivedRequestKeys.size() > 0) {
214         appendAvailableKeys(
215                 chars, ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, derivedRequestKeys);
216     }
217     if (derivedResultKeys.size() > 0) {
218         appendAvailableKeys(
219                 chars, ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, derivedResultKeys);
220     }
221     return;
222 }
223 
appendAvailableKeys(CameraMetadata & chars,int32_t keyTag,const Vector<int32_t> & appendKeys)224 void CameraModule::appendAvailableKeys(CameraMetadata &chars,
225         int32_t keyTag, const Vector<int32_t>& appendKeys) {
226     camera_metadata_entry entry = chars.find(keyTag);
227     Vector<int32_t> availableKeys;
228     availableKeys.setCapacity(entry.count + appendKeys.size());
229     for (size_t i = 0; i < entry.count; i++) {
230         availableKeys.push(entry.data.i32[i]);
231     }
232     for (size_t i = 0; i < appendKeys.size(); i++) {
233         availableKeys.push(appendKeys[i]);
234     }
235     chars.update(keyTag, availableKeys);
236 }
237 
CameraModule(camera_module_t * module)238 CameraModule::CameraModule(camera_module_t *module) : mNumberOfCameras(0) {
239     if (module == NULL) {
240         ALOGE("%s: camera hardware module must not be null", __FUNCTION__);
241         assert(0);
242     }
243     mModule = module;
244 }
245 
~CameraModule()246 CameraModule::~CameraModule()
247 {
248     while (mCameraInfoMap.size() > 0) {
249         camera_info cameraInfo = mCameraInfoMap.editValueAt(0);
250         if (cameraInfo.static_camera_characteristics != NULL) {
251             free_camera_metadata(
252                     const_cast<camera_metadata_t*>(cameraInfo.static_camera_characteristics));
253         }
254         mCameraInfoMap.removeItemsAt(0);
255     }
256 
257     while (mPhysicalCameraInfoMap.size() > 0) {
258         camera_metadata_t* metadata = mPhysicalCameraInfoMap.editValueAt(0);
259         if (metadata != NULL) {
260             free_camera_metadata(metadata);
261         }
262         mPhysicalCameraInfoMap.removeItemsAt(0);
263     }
264 }
265 
init()266 int CameraModule::init() {
267     ATRACE_CALL();
268     int res = OK;
269     if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 &&
270             mModule->init != NULL) {
271         ATRACE_BEGIN("camera_module->init");
272         res = mModule->init();
273         ATRACE_END();
274     }
275     mNumberOfCameras = getNumberOfCameras();
276     mCameraInfoMap.setCapacity(mNumberOfCameras);
277     return res;
278 }
279 
getCameraInfo(int cameraId,struct camera_info * info)280 int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) {
281     ATRACE_CALL();
282     Mutex::Autolock lock(mCameraInfoLock);
283     if (cameraId < 0) {
284         ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId);
285         return -EINVAL;
286     }
287 
288     // Only override static_camera_characteristics for API2 devices
289     int apiVersion = mModule->common.module_api_version;
290     if (apiVersion < CAMERA_MODULE_API_VERSION_2_0) {
291         int ret;
292         ATRACE_BEGIN("camera_module->get_camera_info");
293         ret = mModule->get_camera_info(cameraId, info);
294         // Fill in this so CameraService won't be confused by
295         // possibly 0 device_version
296         info->device_version = CAMERA_DEVICE_API_VERSION_1_0;
297         ATRACE_END();
298         return ret;
299     }
300 
301     ssize_t index = mCameraInfoMap.indexOfKey(cameraId);
302     if (index == NAME_NOT_FOUND) {
303         // Get camera info from raw module and cache it
304         camera_info rawInfo, cameraInfo;
305         ATRACE_BEGIN("camera_module->get_camera_info");
306         int ret = mModule->get_camera_info(cameraId, &rawInfo);
307         ATRACE_END();
308         if (ret != 0) {
309             return ret;
310         }
311         int deviceVersion = rawInfo.device_version;
312         if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_0) {
313             // static_camera_characteristics is invalid
314             *info = rawInfo;
315             return ret;
316         }
317         CameraMetadata m;
318         m.append(rawInfo.static_camera_characteristics);
319         deriveCameraCharacteristicsKeys(rawInfo.device_version, m);
320         cameraInfo = rawInfo;
321         cameraInfo.static_camera_characteristics = m.release();
322         index = mCameraInfoMap.add(cameraId, cameraInfo);
323     }
324 
325     assert(index != NAME_NOT_FOUND);
326     // return the cached camera info
327     *info = mCameraInfoMap[index];
328     return OK;
329 }
330 
getPhysicalCameraInfo(int physicalCameraId,camera_metadata_t ** physicalInfo)331 int CameraModule::getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo) {
332     ATRACE_CALL();
333     Mutex::Autolock lock(mCameraInfoLock);
334     if (physicalCameraId < mNumberOfCameras) {
335         ALOGE("%s: Invalid physical camera ID %d", __FUNCTION__, physicalCameraId);
336         return -EINVAL;
337     }
338 
339     // Only query physical camera info for 2.5 version for newer
340     int apiVersion = mModule->common.module_api_version;
341     if (apiVersion < CAMERA_MODULE_API_VERSION_2_5) {
342         ALOGE("%s: Module version must be at least 2.5 to handle getPhysicalCameraInfo",
343                 __FUNCTION__);
344         return -ENODEV;
345     }
346     if (mModule->get_physical_camera_info == nullptr) {
347         ALOGE("%s: get_physical_camera is NULL for module version 2.5", __FUNCTION__);
348         return -EINVAL;
349     }
350 
351     ssize_t index = mPhysicalCameraInfoMap.indexOfKey(physicalCameraId);
352     if (index == NAME_NOT_FOUND) {
353         // Get physical camera characteristics, and cache it
354         camera_metadata_t *info = nullptr;
355         ATRACE_BEGIN("camera_module->get_physical_camera_info");
356         int ret = mModule->get_physical_camera_info(physicalCameraId, &info);
357         ATRACE_END();
358         if (ret != 0) {
359             return ret;
360         }
361 
362         // The camera_metadata_t returned by get_physical_camera_info could be using
363         // more memory than necessary due to unused reserved space. Reduce the
364         // size by appending it to a new CameraMetadata object, which internally
365         // calls resizeIfNeeded.
366         CameraMetadata m;
367         m.append(info);
368         camera_metadata_t* derivedMetadata = m.release();
369         index = mPhysicalCameraInfoMap.add(physicalCameraId, derivedMetadata);
370     }
371 
372     assert(index != NAME_NOT_FOUND);
373     *physicalInfo = mPhysicalCameraInfoMap[index];
374     return OK;
375 }
376 
getDeviceVersion(int cameraId)377 int CameraModule::getDeviceVersion(int cameraId) {
378     ssize_t index = mDeviceVersionMap.indexOfKey(cameraId);
379     if (index == NAME_NOT_FOUND) {
380         int deviceVersion;
381         if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_0) {
382             struct camera_info info;
383             getCameraInfo(cameraId, &info);
384             deviceVersion = info.device_version;
385         } else {
386             deviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
387         }
388         index = mDeviceVersionMap.add(cameraId, deviceVersion);
389     }
390     assert(index != NAME_NOT_FOUND);
391     return mDeviceVersionMap[index];
392 }
393 
open(const char * id,struct hw_device_t ** device)394 int CameraModule::open(const char* id, struct hw_device_t** device) {
395     int res;
396     ATRACE_BEGIN("camera_module->open");
397     res = filterOpenErrorCode(mModule->common.methods->open(&mModule->common, id, device));
398     ATRACE_END();
399     return res;
400 }
401 
isOpenLegacyDefined() const402 bool CameraModule::isOpenLegacyDefined() const {
403     if (getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_3) {
404         return false;
405     }
406     return mModule->open_legacy != NULL;
407 }
408 
openLegacy(const char * id,uint32_t halVersion,struct hw_device_t ** device)409 int CameraModule::openLegacy(
410         const char* id, uint32_t halVersion, struct hw_device_t** device) {
411     int res;
412     ATRACE_BEGIN("camera_module->open_legacy");
413     res = mModule->open_legacy(&mModule->common, id, halVersion, device);
414     ATRACE_END();
415     return res;
416 }
417 
getNumberOfCameras()418 int CameraModule::getNumberOfCameras() {
419     int numCameras;
420     ATRACE_BEGIN("camera_module->get_number_of_cameras");
421     numCameras = mModule->get_number_of_cameras();
422     ATRACE_END();
423     return numCameras;
424 }
425 
setCallbacks(const camera_module_callbacks_t * callbacks)426 int CameraModule::setCallbacks(const camera_module_callbacks_t *callbacks) {
427     int res = OK;
428     ATRACE_BEGIN("camera_module->set_callbacks");
429     if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_1) {
430         res = mModule->set_callbacks(callbacks);
431     }
432     ATRACE_END();
433     return res;
434 }
435 
isVendorTagDefined() const436 bool CameraModule::isVendorTagDefined() const {
437     return mModule->get_vendor_tag_ops != NULL;
438 }
439 
getVendorTagOps(vendor_tag_ops_t * ops)440 void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) {
441     if (mModule->get_vendor_tag_ops) {
442         ATRACE_BEGIN("camera_module->get_vendor_tag_ops");
443         mModule->get_vendor_tag_ops(ops);
444         ATRACE_END();
445     }
446 }
447 
isSetTorchModeSupported() const448 bool CameraModule::isSetTorchModeSupported() const {
449     if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4) {
450         if (mModule->set_torch_mode == NULL) {
451             ALOGE("%s: Module 2.4 device must support set torch API!",
452                     __FUNCTION__);
453             return false;
454         }
455         return true;
456     }
457     return false;
458 }
459 
setTorchMode(const char * camera_id,bool enable)460 int CameraModule::setTorchMode(const char* camera_id, bool enable) {
461     int res = INVALID_OPERATION;
462     if (mModule->set_torch_mode != NULL) {
463         ATRACE_BEGIN("camera_module->set_torch_mode");
464         res = mModule->set_torch_mode(camera_id, enable);
465         ATRACE_END();
466     }
467     return res;
468 }
469 
isStreamCombinationSupported(int cameraId,camera_stream_combination_t * streams)470 int CameraModule::isStreamCombinationSupported(int cameraId, camera_stream_combination_t *streams) {
471     int res = INVALID_OPERATION;
472     if (mModule->is_stream_combination_supported != NULL) {
473         ATRACE_BEGIN("camera_module->is_stream_combination_supported");
474         res = mModule->is_stream_combination_supported(cameraId, streams);
475         ATRACE_END();
476     }
477     return res;
478 }
479 
notifyDeviceStateChange(uint64_t deviceState)480 void CameraModule::notifyDeviceStateChange(uint64_t deviceState) {
481    if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_5 &&
482            mModule->notify_device_state_change != NULL) {
483        ATRACE_BEGIN("camera_module->notify_device_state_change");
484        ALOGI("%s: calling notify_device_state_change with state %" PRId64, __FUNCTION__,
485                deviceState);
486        mModule->notify_device_state_change(deviceState);
487        ATRACE_END();
488    }
489 }
490 
isLogicalMultiCamera(const common::V1_0::helper::CameraMetadata & metadata,std::unordered_set<std::string> * physicalCameraIds)491 bool CameraModule::isLogicalMultiCamera(
492         const common::V1_0::helper::CameraMetadata& metadata,
493         std::unordered_set<std::string>* physicalCameraIds) {
494     if (physicalCameraIds == nullptr) {
495         ALOGE("%s: physicalCameraIds must not be null", __FUNCTION__);
496         return false;
497     }
498 
499     bool isLogicalMultiCamera = false;
500     camera_metadata_ro_entry_t capabilities =
501             metadata.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
502     for (size_t i = 0; i < capabilities.count; i++) {
503         if (capabilities.data.u8[i] ==
504                 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA) {
505             isLogicalMultiCamera = true;
506             break;
507         }
508     }
509 
510     if (isLogicalMultiCamera) {
511         camera_metadata_ro_entry_t entry =
512                 metadata.find(ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS);
513         const uint8_t* ids = entry.data.u8;
514         size_t start = 0;
515         for (size_t i = 0; i < entry.count; ++i) {
516             if (ids[i] == '\0') {
517                 if (start != i) {
518                     const char* physicalId = reinterpret_cast<const char*>(ids+start);
519                     physicalCameraIds->emplace(physicalId);
520                 }
521                 start = i + 1;
522             }
523         }
524     }
525     return isLogicalMultiCamera;
526 }
527 
filterOpenErrorCode(status_t err)528 status_t CameraModule::filterOpenErrorCode(status_t err) {
529     switch(err) {
530         case NO_ERROR:
531         case -EBUSY:
532         case -EINVAL:
533         case -EUSERS:
534             return err;
535         default:
536             break;
537     }
538     return -ENODEV;
539 }
540 
removeCamera(int cameraId)541 void CameraModule::removeCamera(int cameraId) {
542     std::unordered_set<std::string> physicalIds;
543     camera_metadata_t *metadata = const_cast<camera_metadata_t*>(
544             mCameraInfoMap.valueFor(cameraId).static_camera_characteristics);
545     common::V1_0::helper::CameraMetadata hidlMetadata(metadata);
546 
547     if (isLogicalMultiCamera(hidlMetadata, &physicalIds)) {
548         for (const auto& id : physicalIds) {
549             int idInt = std::stoi(id);
550             if (mPhysicalCameraInfoMap.indexOfKey(idInt) >= 0) {
551                 free_camera_metadata(mPhysicalCameraInfoMap[idInt]);
552                 mPhysicalCameraInfoMap.removeItem(idInt);
553             } else {
554                 ALOGE("%s: Cannot find corresponding static metadata for physical id %s",
555                         __FUNCTION__, id.c_str());
556             }
557         }
558     }
559     free_camera_metadata(metadata);
560     mCameraInfoMap.removeItem(cameraId);
561     mDeviceVersionMap.removeItem(cameraId);
562 }
563 
getModuleApiVersion() const564 uint16_t CameraModule::getModuleApiVersion() const {
565     return mModule->common.module_api_version;
566 }
567 
getModuleName() const568 const char* CameraModule::getModuleName() const {
569     return mModule->common.name;
570 }
571 
getHalApiVersion() const572 uint16_t CameraModule::getHalApiVersion() const {
573     return mModule->common.hal_api_version;
574 }
575 
getModuleAuthor() const576 const char* CameraModule::getModuleAuthor() const {
577     return mModule->common.author;
578 }
579 
getDso()580 void* CameraModule::getDso() {
581     return mModule->common.dso;
582 }
583 
584 } // namespace helper
585 } // namespace V1_0
586 } // namespace common
587 } // namespace camera
588 } // namespace hardware
589 } // namespace android
590