Yin-Chia Yeh | f906b3b | 2016-12-14 19:13:15 -0800 | [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 ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H |
| 18 | #define ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H |
| 19 | |
| 20 | #include "hardware/camera_common.h" |
| 21 | #include "utils/Mutex.h" |
| 22 | #include "utils/SortedVector.h" |
| 23 | #include <android/hardware/camera/provider/2.4/ICameraProvider.h> |
| 24 | #include <hidl/Status.h> |
| 25 | #include <hidl/MQDescriptor.h> |
| 26 | #include "CameraModule.h" |
| 27 | #include "VendorTagDescriptor.h" |
| 28 | |
| 29 | namespace android { |
| 30 | namespace hardware { |
| 31 | namespace camera { |
| 32 | namespace provider { |
| 33 | namespace V2_4 { |
| 34 | namespace implementation { |
| 35 | |
| 36 | using ::android::hardware::camera::common::V1_0::CameraDeviceStatus; |
| 37 | using ::android::hardware::camera::common::V1_0::Status; |
| 38 | using ::android::hardware::camera::common::V1_0::TorchModeStatus; |
| 39 | using ::android::hardware::camera::common::V1_0::VendorTag; |
| 40 | using ::android::hardware::camera::common::V1_0::VendorTagSection; |
| 41 | using ::android::hardware::camera::common::V1_0::helper::CameraModule; |
| 42 | using ::android::hardware::camera::common::V1_0::helper::VendorTagDescriptor; |
| 43 | using ::android::hardware::camera::provider::V2_4::ICameraProvider; |
| 44 | using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback; |
| 45 | using ::android::hardware::Return; |
| 46 | using ::android::hardware::Void; |
| 47 | using ::android::hardware::hidl_vec; |
| 48 | using ::android::hardware::hidl_string; |
| 49 | using ::android::sp; |
| 50 | using ::android::Mutex; |
| 51 | |
| 52 | struct CameraProvider : public ICameraProvider, public camera_module_callbacks_t { |
| 53 | CameraProvider(); |
| 54 | ~CameraProvider(); |
| 55 | |
| 56 | // Caller must use this method to check if CameraProvider ctor failed |
| 57 | bool isInitFailed() { return mInitFailed; } |
| 58 | |
| 59 | // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow. |
| 60 | Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override; |
| 61 | Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override; |
| 62 | Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override; |
| 63 | Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override; |
Yin-Chia Yeh | 9c6dbd5 | 2016-12-22 14:55:02 -0800 | [diff] [blame] | 64 | Return<void> getCameraDeviceInterface_V1_x( |
| 65 | const hidl_string& cameraDeviceName, |
| 66 | getCameraDeviceInterface_V1_x_cb _hidl_cb) override; |
| 67 | Return<void> getCameraDeviceInterface_V3_x( |
| 68 | const hidl_string& cameraDeviceName, |
| 69 | getCameraDeviceInterface_V3_x_cb _hidl_cb) override; |
Yin-Chia Yeh | f906b3b | 2016-12-14 19:13:15 -0800 | [diff] [blame] | 70 | |
| 71 | private: |
| 72 | Mutex mCbLock; |
| 73 | sp<ICameraProviderCallback> mCallbacks = nullptr; |
| 74 | |
| 75 | sp<CameraModule> mModule; |
| 76 | |
| 77 | int mNumberOfLegacyCameras; |
| 78 | std::map<std::string, camera_device_status_t> mCameraStatusMap; // camera id -> status |
| 79 | std::map<std::string, bool> mOpenLegacySupported; // camera id -> open_legacy HAL1.0 supported |
| 80 | SortedVector<std::string> mCameraIds; // the "0"/"1" legacy camera Ids |
| 81 | // (cameraId string, hidl device name) pairs |
| 82 | SortedVector<std::pair<std::string, std::string>> mCameraDeviceNames; |
| 83 | |
| 84 | // Must be queried before using any APIs. |
| 85 | // APIs will only work when this returns true |
| 86 | bool mInitFailed; |
| 87 | bool initialize(); |
| 88 | |
| 89 | hidl_vec<VendorTagSection> mVendorTagSections; |
| 90 | bool setUpVendorTags(); |
| 91 | |
| 92 | // extract legacy camera ID/device version from a HIDL device name |
| 93 | static bool matchDeviceName(const hidl_string& deviceName, std::smatch& sm); |
| 94 | static std::string getLegacyCameraId(const hidl_string& deviceName); |
| 95 | static int getCameraDeviceVersion(const hidl_string& deviceName); |
| 96 | |
| 97 | // create HIDL device name from camera ID and device version |
| 98 | static std::string getHidlDeviceName(std::string cameraId, int deviceVersion); |
| 99 | |
| 100 | // convert conventional HAL status to HIDL Status |
| 101 | static Status getHidlStatus(int); |
| 102 | |
| 103 | // static callback forwarding methods |
| 104 | static void sCameraDeviceStatusChange( |
| 105 | const struct camera_module_callbacks* callbacks, |
| 106 | int camera_id, |
| 107 | int new_status); |
| 108 | static void sTorchModeStatusChange( |
| 109 | const struct camera_module_callbacks* callbacks, |
| 110 | const char* camera_id, |
| 111 | int new_status); |
| 112 | }; |
| 113 | |
| 114 | extern "C" ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name); |
| 115 | |
| 116 | } // namespace implementation |
| 117 | } // namespace V2_4 |
| 118 | } // namespace provider |
| 119 | } // namespace camera |
| 120 | } // namespace hardware |
| 121 | } // namespace android |
| 122 | |
| 123 | #endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H |