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