1 /* 2 * Copyright (C) 2019 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_AUTOMOTIVE_EVS_V1_1_EVSCAMERAENUMERATOR_H 18 #define ANDROID_AUTOMOTIVE_EVS_V1_1_EVSCAMERAENUMERATOR_H 19 20 #include "HalCamera.h" 21 #include "VirtualCamera.h" 22 #include "emul/EvsEmulatedCamera.h" 23 #include "stats/StatsCollector.h" 24 25 #include <list> 26 #include <unordered_map> 27 #include <unordered_set> 28 29 #include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h> 30 #include <android/hardware/automotive/evs/1.1/IEvsDisplay.h> 31 #include <android/hardware/camera/device/3.2/ICameraDevice.h> 32 #include <system/camera_metadata.h> 33 34 using namespace ::android::hardware::automotive::evs::V1_1; 35 using ::android::hardware::Return; 36 using ::android::hardware::hidl_string; 37 using ::android::hardware::camera::device::V3_2::Stream; 38 39 namespace android { 40 namespace automotive { 41 namespace evs { 42 namespace V1_1 { 43 namespace implementation { 44 45 using IEvsCamera_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCamera; 46 using IEvsCamera_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCamera; 47 using IEvsEnumerator_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsEnumerator; 48 using IEvsEnumerator_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsEnumerator; 49 using IEvsDisplay_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsDisplay; 50 using IEvsDisplay_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsDisplay; 51 using EvsDisplayState = ::android::hardware::automotive::evs::V1_0::DisplayState; 52 53 class Enumerator : public IEvsEnumerator { 54 public: 55 // Methods from ::android::hardware::automotive::evs::V1_0::IEvsEnumerator follow. 56 Return<void> getCameraList(getCameraList_cb _hidl_cb) override; 57 Return<sp<IEvsCamera_1_0>> openCamera(const hidl_string& cameraId) override; 58 Return<void> closeCamera(const ::android::sp<IEvsCamera_1_0>& virtualCamera) override; 59 Return<sp<IEvsDisplay_1_0>> openDisplay() override; 60 Return<void> closeDisplay(const ::android::sp<IEvsDisplay_1_0>& display) override; 61 Return<EvsDisplayState> getDisplayState() override; 62 63 // Methods from ::android::hardware::automotive::evs::V1_1::IEvsEnumerator follow. 64 Return<void> getCameraList_1_1(getCameraList_1_1_cb _hidl_cb) override; 65 Return<sp<IEvsCamera_1_1>> openCamera_1_1(const hidl_string& cameraId, 66 const Stream& streamCfg) override; isHardware()67 Return<bool> isHardware() override { return false; } 68 Return<void> getDisplayIdList(getDisplayIdList_cb _list_cb) override; 69 Return<sp<IEvsDisplay_1_1>> openDisplay_1_1(uint8_t id) override; 70 Return<void> getUltrasonicsArrayList(getUltrasonicsArrayList_cb _hidl_cb) override; 71 Return<sp<IEvsUltrasonicsArray>> openUltrasonicsArray( 72 const hidl_string& ultrasonicsArrayId) override; 73 Return<void> closeUltrasonicsArray( 74 const ::android::sp<IEvsUltrasonicsArray>& evsUltrasonicsArray) override; 75 76 // Methods from ::android.hidl.base::V1_0::IBase follow. 77 Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override; 78 79 // Implementation details 80 bool init(const char* hardwareServiceName); 81 82 // Destructor 83 virtual ~Enumerator(); 84 85 private: 86 bool inline checkPermission(); 87 bool isLogicalCamera(const camera_metadata_t *metadata); 88 std::unordered_set<std::string> getPhysicalCameraIds(const std::string& id); 89 90 sp<IEvsEnumerator_1_1> mHwEnumerator; // Hardware enumerator 91 wp<IEvsDisplay_1_0> mActiveDisplay; // Display proxy object warpping hw display 92 93 // List of active camera proxy objects that wrap hw cameras 94 std::unordered_map<std::string, 95 sp<HalCamera>> mActiveCameras; 96 97 // List of camera descriptors of enumerated hw cameras 98 std::unordered_map<std::string, 99 CameraDesc> mCameraDevices; 100 101 // List of available physical display devices 102 std::list<uint8_t> mDisplayPorts; 103 104 // Display port the internal display is connected to. 105 uint8_t mInternalDisplayPort; 106 107 // Collecting camera usage statistics from clients 108 sp<StatsCollector> mClientsMonitor; 109 110 // Boolean flag to tell whether the camera usages are being monitored or not 111 bool mMonitorEnabled; 112 113 // Boolean flag to tell whether EvsDisplay is owned exclusively or not 114 bool mDisplayOwnedExclusively; 115 116 // LSHAL dump 117 void cmdDump(int fd, const hidl_vec<hidl_string>& options); 118 void cmdHelp(int fd); 119 void cmdList(int fd, const hidl_vec<hidl_string>& options); 120 void cmdDumpDevice(int fd, const hidl_vec<hidl_string>& options); 121 122 // List of emulated camera devices 123 std::unordered_map<std::string, 124 EmulatedCameraDesc> mEmulatedCameraDevices; 125 126 // LSHAL command to use emulated camera device 127 void cmdConfigureEmulatedCamera(int fd, const hidl_vec<hidl_string>& options); 128 }; 129 130 } // namespace implementation 131 } // namespace V1_1 132 } // namespace evs 133 } // namespace automotive 134 } // namespace android 135 136 #endif // ANDROID_AUTOMOTIVE_EVS_V1_1_EVSCAMERAENUMERATOR_H 137