1 /* 2 * Copyright (C) 2021 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_7_EXTCAMERAPROVIDER_H 18 #define ANDROID_HARDWARE_CAMERA_PROVIDER_V2_7_EXTCAMERAPROVIDER_H 19 20 #include <hidl/MQDescriptor.h> 21 #include <hidl/Status.h> 22 #include <utils/Mutex.h> 23 #include <utils/Thread.h> 24 #include <string> 25 #include <unordered_map> 26 #include <unordered_set> 27 #include "ExternalCameraUtils.h" 28 29 #include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h> 30 #include <android/hardware/camera/provider/2.7/ICameraProvider.h> 31 32 namespace android { 33 namespace hardware { 34 namespace camera { 35 namespace provider { 36 namespace V2_7 { 37 namespace implementation { 38 39 using ::android::hardware::hidl_string; 40 using ::android::hardware::hidl_vec; 41 using ::android::hardware::Return; 42 using ::android::hardware::Void; 43 using ::android::hardware::camera::common::V1_0::CameraDeviceStatus; 44 using ::android::hardware::camera::common::V1_0::Status; 45 using ::android::hardware::camera::common::V1_0::VendorTagSection; 46 using ::android::hardware::camera::external::common::ExternalCameraConfig; 47 using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback; 48 using ::android::hardware::camera::provider::V2_5::DeviceState; 49 using ::android::hardware::camera::provider::V2_7::CameraIdAndStreamCombination; 50 using ::android::hardware::camera::provider::V2_7::ICameraProvider; 51 using ::android::hidl::base::V1_0::IBase; 52 53 /** 54 * The implementation of external webcam CameraProvider 2.7, separated 55 * from the HIDL interface layer to allow for implementation reuse by later 56 * provider versions. 57 * 58 * This camera provider supports standard UVC webcameras via the Linux V4L2 59 * UVC driver. 60 */ 61 struct ExternalCameraProviderImpl_2_7 { 62 ExternalCameraProviderImpl_2_7(); 63 ~ExternalCameraProviderImpl_2_7(); 64 65 // Caller must use this method to check if CameraProvider ctor failed isInitFailedExternalCameraProviderImpl_2_766 bool isInitFailed() { return false; } 67 68 // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow. 69 Return<Status> setCallback(const sp<ICameraProviderCallback>& callback); 70 Return<void> getVendorTags(ICameraProvider::getVendorTags_cb _hidl_cb); 71 Return<void> getCameraIdList(ICameraProvider::getCameraIdList_cb _hidl_cb); 72 Return<void> isSetTorchModeSupported(ICameraProvider::isSetTorchModeSupported_cb _hidl_cb); 73 Return<void> getCameraDeviceInterface_V1_x(const hidl_string&, 74 ICameraProvider::getCameraDeviceInterface_V1_x_cb); 75 Return<void> getCameraDeviceInterface_V3_x(const hidl_string&, 76 ICameraProvider::getCameraDeviceInterface_V3_x_cb); 77 78 // Methods from ::android::hardware::camera::provider::V2_5::ICameraProvider follow. 79 Return<void> notifyDeviceStateChange(hidl_bitfield<DeviceState> newState); 80 81 // Methods from ::android::hardware::camera::provider::V2_7::ICameraProvider follow. 82 Return<void> getConcurrentStreamingCameraIds( 83 ICameraProvider::getConcurrentStreamingCameraIds_cb _hidl_cb); 84 85 Return<void> isConcurrentStreamCombinationSupported( 86 const hidl_vec< 87 ::android::hardware::camera::provider::V2_6::CameraIdAndStreamCombination>& 88 configs, 89 ICameraProvider::isConcurrentStreamCombinationSupported_cb _hidl_cb); 90 91 Return<void> isConcurrentStreamCombinationSupported_2_7( 92 const hidl_vec<CameraIdAndStreamCombination>& configs, 93 ICameraProvider::isConcurrentStreamCombinationSupported_2_7_cb _hidl_cb); 94 95 private: 96 void addExternalCamera(const char* devName); 97 98 void deviceAdded(const char* devName); 99 100 void deviceRemoved(const char* devName); 101 102 void updateAttachedCameras(); 103 104 class HotplugThread : public android::Thread { 105 public: 106 HotplugThread(ExternalCameraProviderImpl_2_7* parent); 107 ~HotplugThread(); 108 109 virtual bool threadLoop() override; 110 111 private: 112 ExternalCameraProviderImpl_2_7* mParent = nullptr; 113 const std::unordered_set<std::string> mInternalDevices; 114 115 int mINotifyFD = -1; 116 int mWd = -1; 117 }; 118 119 Mutex mLock; 120 sp<ICameraProviderCallback> mCallbacks = nullptr; 121 std::unordered_map<std::string, CameraDeviceStatus> mCameraStatusMap; // camera id -> status 122 const ExternalCameraConfig mCfg; 123 sp<HotplugThread> mHotPlugThread; 124 int mPreferredHal3MinorVersion; 125 }; 126 127 } // namespace implementation 128 } // namespace V2_7 129 } // namespace provider 130 } // namespace camera 131 } // namespace hardware 132 } // namespace android 133 134 #endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_7_EXTCAMERAPROVIDER_H 135