Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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_EXTCAMERAPROVIDER_H |
| 18 | #define ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_EXTCAMERAPROVIDER_H |
| 19 | |
Yin-Chia Yeh | 53f4cb1 | 2018-01-29 10:31:45 -0800 | [diff] [blame] | 20 | #include <string> |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 21 | #include <unordered_map> |
Yin-Chia Yeh | 53f4cb1 | 2018-01-29 10:31:45 -0800 | [diff] [blame] | 22 | #include <unordered_set> |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 23 | #include "utils/Mutex.h" |
| 24 | #include "utils/Thread.h" |
| 25 | #include <android/hardware/camera/provider/2.4/ICameraProvider.h> |
| 26 | #include <hidl/Status.h> |
| 27 | #include <hidl/MQDescriptor.h> |
Yin-Chia Yeh | 1798249 | 2018-02-05 17:41:01 -0800 | [diff] [blame] | 28 | #include "ExternalCameraUtils.h" |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | namespace hardware { |
| 32 | namespace camera { |
| 33 | namespace provider { |
| 34 | namespace V2_4 { |
| 35 | namespace implementation { |
| 36 | |
| 37 | using ::android::hardware::camera::common::V1_0::CameraDeviceStatus; |
| 38 | using ::android::hardware::camera::common::V1_0::Status; |
| 39 | using ::android::hardware::camera::common::V1_0::VendorTagSection; |
Yin-Chia Yeh | 1798249 | 2018-02-05 17:41:01 -0800 | [diff] [blame] | 40 | using ::android::hardware::camera::external::common::ExternalCameraConfig; |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 41 | using ::android::hardware::camera::provider::V2_4::ICameraProvider; |
| 42 | using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback; |
| 43 | using ::android::hardware::Return; |
| 44 | using ::android::hardware::Void; |
| 45 | using ::android::hardware::hidl_vec; |
| 46 | using ::android::hardware::hidl_string; |
| 47 | using ::android::sp; |
| 48 | using ::android::Mutex; |
| 49 | |
| 50 | struct ExternalCameraProvider : public ICameraProvider { |
| 51 | ExternalCameraProvider(); |
| 52 | ~ExternalCameraProvider(); |
| 53 | |
| 54 | // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow. |
| 55 | Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override; |
| 56 | |
| 57 | Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override; |
| 58 | |
| 59 | Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override; |
| 60 | |
| 61 | Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override; |
| 62 | |
| 63 | Return<void> getCameraDeviceInterface_V1_x( |
| 64 | const hidl_string&, |
| 65 | getCameraDeviceInterface_V1_x_cb) override; |
| 66 | Return<void> getCameraDeviceInterface_V3_x( |
| 67 | const hidl_string&, |
| 68 | getCameraDeviceInterface_V3_x_cb) override; |
| 69 | |
| 70 | private: |
| 71 | |
| 72 | void addExternalCamera(const char* devName); |
| 73 | |
| 74 | void deviceAdded(const char* devName); |
| 75 | |
| 76 | void deviceRemoved(const char* devName); |
| 77 | |
| 78 | class HotplugThread : public android::Thread { |
| 79 | public: |
| 80 | HotplugThread(ExternalCameraProvider* parent); |
| 81 | ~HotplugThread(); |
| 82 | |
| 83 | virtual bool threadLoop() override; |
| 84 | |
| 85 | private: |
| 86 | ExternalCameraProvider* mParent = nullptr; |
Yin-Chia Yeh | 53f4cb1 | 2018-01-29 10:31:45 -0800 | [diff] [blame] | 87 | const std::unordered_set<std::string> mInternalDevices; |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 88 | |
| 89 | int mINotifyFD = -1; |
| 90 | int mWd = -1; |
Yin-Chia Yeh | 53f4cb1 | 2018-01-29 10:31:45 -0800 | [diff] [blame] | 91 | }; |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 92 | |
| 93 | Mutex mLock; |
| 94 | sp<ICameraProviderCallback> mCallbacks = nullptr; |
| 95 | std::unordered_map<std::string, CameraDeviceStatus> mCameraStatusMap; // camera id -> status |
Yin-Chia Yeh | 1798249 | 2018-02-05 17:41:01 -0800 | [diff] [blame] | 96 | const ExternalCameraConfig mCfg; |
Yin-Chia Yeh | 53f4cb1 | 2018-01-29 10:31:45 -0800 | [diff] [blame] | 97 | HotplugThread mHotPlugThread; |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | |
| 101 | |
| 102 | } // namespace implementation |
| 103 | } // namespace V2_4 |
| 104 | } // namespace provider |
| 105 | } // namespace camera |
| 106 | } // namespace hardware |
| 107 | } // namespace android |
| 108 | |
| 109 | #endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_EXTCAMERAPROVIDER_H |