Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 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 | #ifndef CAMERA_COMMON_1_0_CAMERAMODULE_H |
| 18 | #define CAMERA_COMMON_1_0_CAMERAMODULE_H |
| 19 | |
Shuzhen Wang | 892e826 | 2019-02-08 16:12:30 -0800 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <unordered_set> |
| 22 | |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 23 | #include <hardware/camera.h> |
| 24 | #include <utils/Mutex.h> |
| 25 | #include <utils/KeyedVector.h> |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 26 | #include <utils/RefBase.h> |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 27 | |
| 28 | #include "CameraMetadata.h" |
| 29 | |
| 30 | namespace android { |
| 31 | namespace hardware { |
| 32 | namespace camera { |
| 33 | namespace common { |
| 34 | namespace V1_0 { |
| 35 | namespace helper { |
| 36 | /** |
| 37 | * A wrapper class for HAL camera module. |
| 38 | * |
| 39 | * This class wraps camera_module_t returned from HAL to provide a wrapped |
| 40 | * get_camera_info implementation which CameraService generates some |
| 41 | * camera characteristics keys defined in newer HAL version on an older HAL. |
| 42 | */ |
| 43 | class CameraModule : public RefBase { |
| 44 | public: |
| 45 | explicit CameraModule(camera_module_t *module); |
| 46 | virtual ~CameraModule(); |
| 47 | |
| 48 | // Must be called after construction |
| 49 | // Returns OK on success, NO_INIT on failure |
| 50 | int init(); |
| 51 | |
| 52 | int getCameraInfo(int cameraId, struct camera_info *info); |
| 53 | int getDeviceVersion(int cameraId); |
| 54 | int getNumberOfCameras(void); |
| 55 | int open(const char* id, struct hw_device_t** device); |
Yin-Chia Yeh | f906b3b | 2016-12-14 19:13:15 -0800 | [diff] [blame] | 56 | bool isOpenLegacyDefined() const; |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 57 | int openLegacy(const char* id, uint32_t halVersion, struct hw_device_t** device); |
| 58 | int setCallbacks(const camera_module_callbacks_t *callbacks); |
Yin-Chia Yeh | f906b3b | 2016-12-14 19:13:15 -0800 | [diff] [blame] | 59 | bool isVendorTagDefined() const; |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 60 | void getVendorTagOps(vendor_tag_ops_t* ops); |
Yin-Chia Yeh | f906b3b | 2016-12-14 19:13:15 -0800 | [diff] [blame] | 61 | bool isSetTorchModeSupported() const; |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 62 | int setTorchMode(const char* camera_id, bool enable); |
Yin-Chia Yeh | f906b3b | 2016-12-14 19:13:15 -0800 | [diff] [blame] | 63 | uint16_t getModuleApiVersion() const; |
| 64 | const char* getModuleName() const; |
| 65 | uint16_t getHalApiVersion() const; |
| 66 | const char* getModuleAuthor() const; |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 67 | // Only used by CameraModuleFixture native test. Do NOT use elsewhere. |
| 68 | void *getDso(); |
Guennadi Liakhovetski | eca1d45 | 2017-12-07 10:59:35 +0100 | [diff] [blame] | 69 | // Only used by CameraProvider |
| 70 | void removeCamera(int cameraId); |
Shuzhen Wang | d3feb3d | 2018-08-17 13:52:40 -0700 | [diff] [blame] | 71 | int getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo); |
Emilian Peev | 40a8c6e | 2018-10-29 09:35:21 +0000 | [diff] [blame] | 72 | int isStreamCombinationSupported(int cameraId, camera_stream_combination_t *streams); |
Eino-Ville Talvala | 2951804 | 2019-01-18 17:32:06 -0800 | [diff] [blame] | 73 | void notifyDeviceStateChange(uint64_t deviceState); |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 74 | |
Shuzhen Wang | 892e826 | 2019-02-08 16:12:30 -0800 | [diff] [blame] | 75 | static bool isLogicalMultiCamera( |
| 76 | const common::V1_0::helper::CameraMetadata& metadata, |
| 77 | std::unordered_set<std::string>* physicalCameraIds); |
| 78 | |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 79 | private: |
| 80 | // Derive camera characteristics keys defined after HAL device version |
| 81 | static void deriveCameraCharacteristicsKeys(uint32_t deviceVersion, CameraMetadata &chars); |
| 82 | // Helper function to append available[request|result|chars]Keys |
| 83 | static void appendAvailableKeys(CameraMetadata &chars, |
| 84 | int32_t keyTag, const Vector<int32_t>& appendKeys); |
| 85 | status_t filterOpenErrorCode(status_t err); |
| 86 | camera_module_t *mModule; |
Shuzhen Wang | 6bdeaf5 | 2018-09-05 09:40:00 -0700 | [diff] [blame] | 87 | int mNumberOfCameras; |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 88 | KeyedVector<int, camera_info> mCameraInfoMap; |
| 89 | KeyedVector<int, int> mDeviceVersionMap; |
Shuzhen Wang | d3feb3d | 2018-08-17 13:52:40 -0700 | [diff] [blame] | 90 | KeyedVector<int, camera_metadata_t*> mPhysicalCameraInfoMap; |
Yin-Chia Yeh | faef8f9 | 2016-10-31 12:53:56 -0700 | [diff] [blame] | 91 | Mutex mCameraInfoLock; |
| 92 | }; |
| 93 | |
| 94 | } // namespace helper |
| 95 | } // namespace V1_0 |
| 96 | } // namespace common |
| 97 | } // namespace camera |
| 98 | } // namespace hardware |
| 99 | } // namespace android |
| 100 | |
| 101 | #endif |