• 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 #ifndef ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_LEGACYCAMERAPROVIDER_H
18 #define ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_LEGACYCAMERAPROVIDER_H
19 
20 #include <android/hardware/camera/provider/2.4/ICameraProvider.h>
21 #include "hardware/camera_common.h"
22 #include "utils/Mutex.h"
23 #include "utils/SortedVector.h"
24 
25 #include "CameraModule.h"
26 #include "VendorTagDescriptor.h"
27 
28 namespace android {
29 namespace hardware {
30 namespace camera {
31 namespace provider {
32 namespace V2_4 {
33 namespace implementation {
34 
35 using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
36 using ::android::hardware::camera::common::V1_0::Status;
37 using ::android::hardware::camera::common::V1_0::TorchModeStatus;
38 using ::android::hardware::camera::common::V1_0::VendorTag;
39 using ::android::hardware::camera::common::V1_0::VendorTagSection;
40 using ::android::hardware::camera::common::V1_0::helper::CameraModule;
41 using ::android::hardware::camera::common::V1_0::helper::VendorTagDescriptor;
42 using ::android::hardware::camera::provider::V2_4::ICameraProvider;
43 using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
44 using ::android::hardware::Return;
45 using ::android::hardware::Void;
46 using ::android::hardware::hidl_vec;
47 using ::android::hardware::hidl_string;
48 using ::android::sp;
49 using ::android::Mutex;
50 
51 /**
52  * The implementation of legacy wrapper CameraProvider 2.4, separated
53  * from the HIDL interface layer to allow for implementation reuse by later
54  * provider versions.
55  *
56  * This implementation supports cameras implemented via the legacy libhardware
57  * camera HAL definitions.
58  */
59 struct LegacyCameraProviderImpl_2_4 : public camera_module_callbacks_t {
60     LegacyCameraProviderImpl_2_4();
61     ~LegacyCameraProviderImpl_2_4();
62 
63     // Caller must use this method to check if CameraProvider ctor failed
isInitFailedLegacyCameraProviderImpl_2_464     bool isInitFailed() { return mInitFailed; }
65 
66     // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
67     Return<Status> setCallback(const sp<ICameraProviderCallback>& callback);
68     Return<void> getVendorTags(ICameraProvider::getVendorTags_cb _hidl_cb);
69     Return<void> getCameraIdList(ICameraProvider::getCameraIdList_cb _hidl_cb);
70     Return<void> isSetTorchModeSupported(ICameraProvider::isSetTorchModeSupported_cb _hidl_cb);
71     Return<void> getCameraDeviceInterface_V1_x(
72             const hidl_string& cameraDeviceName,
73             ICameraProvider::getCameraDeviceInterface_V1_x_cb _hidl_cb);
74     Return<void> getCameraDeviceInterface_V3_x(
75             const hidl_string& cameraDeviceName,
76             ICameraProvider::getCameraDeviceInterface_V3_x_cb _hidl_cb);
77 
78 protected:
79     Mutex mCbLock;
80     sp<ICameraProviderCallback> mCallbacks = nullptr;
81 
82     sp<CameraModule> mModule;
83 
84     int mNumberOfLegacyCameras;
85     std::map<std::string, camera_device_status_t> mCameraStatusMap; // camera id -> status
86     std::map<std::string, bool> mOpenLegacySupported; // camera id -> open_legacy HAL1.0 supported
87     SortedVector<std::string> mCameraIds; // the "0"/"1" legacy camera Ids
88     // (cameraId string, hidl device name) pairs
89     SortedVector<std::pair<std::string, std::string>> mCameraDeviceNames;
90 
91     int mPreferredHal3MinorVersion;
92 
93     // Must be queried before using any APIs.
94     // APIs will only work when this returns true
95     bool mInitFailed;
96     bool initialize();
97 
98     hidl_vec<VendorTagSection> mVendorTagSections;
99     bool setUpVendorTags();
100     int checkCameraVersion(int id, camera_info info);
101 
102     // create HIDL device name from camera ID and legacy device version
103     std::string getHidlDeviceName(std::string cameraId, int deviceVersion);
104 
105     // extract legacy camera ID/device version from a HIDL device name
106     static std::string getLegacyCameraId(const hidl_string& deviceName);
107 
108     // convert conventional HAL status to HIDL Status
109     static Status getHidlStatus(int);
110 
111     // static callback forwarding methods
112     static void sCameraDeviceStatusChange(
113         const struct camera_module_callbacks* callbacks,
114         int camera_id,
115         int new_status);
116     static void sTorchModeStatusChange(
117         const struct camera_module_callbacks* callbacks,
118         const char* camera_id,
119         int new_status);
120 
121     void addDeviceNames(int camera_id, CameraDeviceStatus status = CameraDeviceStatus::PRESENT,
122                         bool cam_new = false);
123     void removeDeviceNames(int camera_id);
124 
125 };
126 
127 }  // namespace implementation
128 }  // namespace V2_4
129 }  // namespace provider
130 }  // namespace camera
131 }  // namespace hardware
132 }  // namespace android
133 
134 #endif  // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_LEGACYCAMERAPROVIDER_H
135