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 
20 #include <string>
21 #include <unordered_set>
22 
23 #include <hardware/camera.h>
24 #include <utils/KeyedVector.h>
25 #include <utils/Mutex.h>
26 #include <utils/RefBase.h>
27 
28 #include "CameraMetadata.h"
29 
30 namespace android {
31 namespace hardware {
32 namespace camera {
33 namespace common {
34 namespace helper {
35 /**
36  * A wrapper class for HAL camera module.
37  *
38  * This class wraps camera_module_t returned from HAL to provide a wrapped
39  * get_camera_info implementation which CameraService generates some
40  * camera characteristics keys defined in newer HAL version on an older HAL.
41  */
42 class CameraModule : public RefBase {
43   public:
44     explicit CameraModule(camera_module_t* module);
45     virtual ~CameraModule();
46 
47     // Must be called after construction
48     // Returns OK on success, NO_INIT on failure
49     int init();
50 
51     int getCameraInfo(int cameraId, struct camera_info* info);
52     int getDeviceVersion(int cameraId);
53     int getNumberOfCameras(void);
54     int open(const char* id, struct hw_device_t** device);
55     bool isOpenLegacyDefined() const;
56     int openLegacy(const char* id, uint32_t halVersion, struct hw_device_t** device);
57     int setCallbacks(const camera_module_callbacks_t* callbacks);
58     bool isVendorTagDefined() const;
59     void getVendorTagOps(vendor_tag_ops_t* ops);
60     bool isSetTorchModeSupported() const;
61     int setTorchMode(const char* camera_id, bool enable);
62     uint16_t getModuleApiVersion() const;
63     const char* getModuleName() const;
64     uint16_t getHalApiVersion() const;
65     const char* getModuleAuthor() const;
66     // Only used by CameraModuleFixture native test. Do NOT use elsewhere.
67     void* getDso();
68     // Only used by CameraProvider
69     void removeCamera(int cameraId);
70     int getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t** physicalInfo);
71     int isStreamCombinationSupported(int cameraId, camera_stream_combination_t* streams);
72     void notifyDeviceStateChange(uint64_t deviceState);
73 
74     static bool isLogicalMultiCamera(const common::helper::CameraMetadata& metadata,
75                                      std::unordered_set<std::string>* physicalCameraIds);
76 
77   private:
78     // Derive camera characteristics keys defined after HAL device version
79     static void deriveCameraCharacteristicsKeys(uint32_t deviceVersion, CameraMetadata& chars);
80     // Helper function to append available[request|result|chars]Keys
81     static void appendAvailableKeys(CameraMetadata& chars, int32_t keyTag,
82                                     const Vector<int32_t>& appendKeys);
83     status_t filterOpenErrorCode(status_t err);
84     camera_module_t* mModule;
85     int mNumberOfCameras;
86     KeyedVector<int, camera_info> mCameraInfoMap;
87     KeyedVector<int, int> mDeviceVersionMap;
88     KeyedVector<int, camera_metadata_t*> mPhysicalCameraInfoMap;
89     Mutex mCameraInfoLock;
90 };
91 
92 }  // namespace helper
93 
94 // NOTE: Deprecated namespace. This namespace should no longer be used for the following symbols
95 namespace V1_0::helper {
96 // Export symbols to the old namespace to preserve compatibility
97 typedef android::hardware::camera::common::helper::CameraModule CameraModule;
98 }  // namespace V1_0::helper
99 
100 }  // namespace common
101 }  // namespace camera
102 }  // namespace hardware
103 }  // namespace android
104 
105 #endif
106