• 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_AUTOMOTIVE_EVS_V1_1_EVSCAMERAENUMERATOR_H
18 #define ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_1_EVSCAMERAENUMERATOR_H
19 
20 #include <android/hardware/automotive/evs/1.1/IEvsEnumerator.h>
21 #include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
22 #include <android/hardware/camera/device/3.2/ICameraDevice.h>
23 #include <android/frameworks/automotive/display/1.0/IAutomotiveDisplayProxyService.h>
24 
25 #include <unordered_map>
26 #include <thread>
27 #include <atomic>
28 
29 #include "ConfigManager.h"
30 
31 using ::android::hardware::camera::device::V3_2::Stream;
32 using EvsDisplayState = ::android::hardware::automotive::evs::V1_0::DisplayState;
33 using IEvsCamera_1_0  = ::android::hardware::automotive::evs::V1_0::IEvsCamera;
34 using IEvsCamera_1_1  = ::android::hardware::automotive::evs::V1_1::IEvsCamera;
35 using IEvsDisplay_1_0  = ::android::hardware::automotive::evs::V1_0::IEvsDisplay;
36 using IEvsDisplay_1_1  = ::android::hardware::automotive::evs::V1_1::IEvsDisplay;
37 using android::frameworks::automotive::display::V1_0::IAutomotiveDisplayProxyService;
38 
39 namespace android {
40 namespace hardware {
41 namespace automotive {
42 namespace evs {
43 namespace V1_1 {
44 namespace implementation {
45 
46 
47 class EvsV4lCamera;    // from EvsCamera.h
48 class EvsGlDisplay;    // from EvsGlDisplay.h
49 
50 class EvsEnumerator : public IEvsEnumerator {
51 public:
52     // Methods from ::android::hardware::automotive::evs::V1_0::IEvsEnumerator follow.
53     Return<void>                getCameraList(getCameraList_cb _hidl_cb)  override;
54     Return<sp<IEvsCamera_1_0>>  openCamera(const hidl_string& cameraId) override;
55     Return<void>                closeCamera(const ::android::sp<IEvsCamera_1_0>& pCamera)  override;
56     Return<sp<IEvsDisplay_1_0>> openDisplay()  override;
57     Return<void>                closeDisplay(const ::android::sp<IEvsDisplay_1_0>& display)  override;
58     Return<EvsDisplayState>     getDisplayState()  override;
59 
60     // Methods from ::android::hardware::automotive::evs::V1_1::IEvsEnumerator follow.
61     Return<void>                getCameraList_1_1(getCameraList_1_1_cb _hidl_cb) override;
62     Return<sp<IEvsCamera_1_1>>  openCamera_1_1(const hidl_string& cameraId,
63                                                const Stream& streamCfg) override;
isHardware()64     Return<bool>                isHardware() override { return true; }
65     Return<void>                getDisplayIdList(getDisplayIdList_cb _list_cb) override;
66     Return<sp<IEvsDisplay_1_1>> openDisplay_1_1(uint8_t port) override;
67     Return<void> getUltrasonicsArrayList(getUltrasonicsArrayList_cb _hidl_cb) override;
68     Return<sp<IEvsUltrasonicsArray>> openUltrasonicsArray(
69             const hidl_string& ultrasonicsArrayId) override;
70     Return<void> closeUltrasonicsArray(
71             const ::android::sp<IEvsUltrasonicsArray>& evsUltrasonicsArray) override;
72 
73     // Implementation details
74     EvsEnumerator(sp<IAutomotiveDisplayProxyService> proxyService = nullptr);
75 
76     // Listen to video device uevents
77     static void EvsUeventThread(std::atomic<bool>& running);
78 
79 private:
80     struct CameraRecord {
81         CameraDesc          desc;
82         wp<EvsV4lCamera>    activeInstance;
83 
CameraRecordCameraRecord84         CameraRecord(const char *cameraId) : desc() { desc.v1.cameraId = cameraId; }
85     };
86 
87     bool checkPermission();
88 
89     static bool qualifyCaptureDevice(const char* deviceName);
90     static CameraRecord* findCameraById(const std::string& cameraId);
91     static void enumerateCameras();
92     static void enumerateDisplays();
93 
94     void closeCamera_impl(const sp<IEvsCamera_1_0>& pCamera, const std::string& cameraId);
95 
96     // NOTE:  All members values are static so that all clients operate on the same state
97     //        That is to say, this is effectively a singleton despite the fact that HIDL
98     //        constructs a new instance for each client.
99     //        Because our server has a single thread in the thread pool, these values are
100     //        never accessed concurrently despite potentially having multiple instance objects
101     //        using them.
102     static std::unordered_map<std::string,
103                               CameraRecord> sCameraList;
104 
105     static wp<EvsGlDisplay>                 sActiveDisplay; // Weak pointer.
106                                                             // Object destructs if client dies.
107 
108     static std::mutex                       sLock;          // Mutex on shared camera device list.
109     static std::condition_variable          sCameraSignal;  // Signal on camera device addition.
110 
111     static std::unique_ptr<ConfigManager>   sConfigManager; // ConfigManager
112 
113     static sp<IAutomotiveDisplayProxyService> sDisplayProxy;
114     static std::unordered_map<uint8_t,
115                               uint64_t>       sDisplayPortList;
116     static uint64_t                           sInternalDisplayId;
117 };
118 
119 } // namespace implementation
120 } // namespace V1_1
121 } // namespace evs
122 } // namespace automotive
123 } // namespace hardware
124 } // namespace android
125 
126 #endif  // ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_1_EVSCAMERAENUMERATOR_H
127