blob: f4d64d3b1ce8ea98253046232d869a2be75c5531 [file] [log] [blame]
Scott Randolphb342cb12017-04-25 17:38:29 -07001/*
Changyeon Jo6fa38022019-05-03 16:35:16 -07002 * Copyright (C) 2016-2019 The Android Open Source Project
Scott Randolphb342cb12017-04-25 17:38:29 -07003 *
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_0_EVSCAMERAENUMERATOR_H
18#define ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_0_EVSCAMERAENUMERATOR_H
19
20#include <android/hardware/automotive/evs/1.0/IEvsEnumerator.h>
21#include <android/hardware/automotive/evs/1.0/IEvsCamera.h>
22
Changyeon Job67c0202019-05-20 12:05:25 -070023#include <unordered_map>
Changyeon Jo6fa38022019-05-03 16:35:16 -070024#include <thread>
25#include <atomic>
Scott Randolphb342cb12017-04-25 17:38:29 -070026
Scott Randolphb342cb12017-04-25 17:38:29 -070027namespace android {
28namespace hardware {
29namespace automotive {
30namespace evs {
31namespace V1_0 {
32namespace implementation {
33
34
35class EvsV4lCamera; // from EvsCamera.h
36class EvsGlDisplay; // from EvsGlDisplay.h
37
Scott Randolphb342cb12017-04-25 17:38:29 -070038class EvsEnumerator : public IEvsEnumerator {
39public:
40 // Methods from ::android::hardware::automotive::evs::V1_0::IEvsEnumerator follow.
41 Return<void> getCameraList(getCameraList_cb _hidl_cb) override;
42 Return<sp<IEvsCamera>> openCamera(const hidl_string& cameraId) override;
43 Return<void> closeCamera(const ::android::sp<IEvsCamera>& carCamera) override;
44 Return<sp<IEvsDisplay>> openDisplay() override;
45 Return<void> closeDisplay(const ::android::sp<IEvsDisplay>& display) override;
46 Return<DisplayState> getDisplayState() override;
47
48 // Implementation details
49 EvsEnumerator();
50
Changyeon Jo6fa38022019-05-03 16:35:16 -070051 // Listen to video device uevents
52 static void EvsUeventThread(std::atomic<bool>& running);
53
Scott Randolphb342cb12017-04-25 17:38:29 -070054private:
55 struct CameraRecord {
56 CameraDesc desc;
57 wp<EvsV4lCamera> activeInstance;
58
59 CameraRecord(const char *cameraId) : desc() { desc.cameraId = cameraId; }
60 };
61
Scott Randolphf937fa52017-05-04 14:53:38 -070062 static bool qualifyCaptureDevice(const char* deviceName);
Scott Randolphb342cb12017-04-25 17:38:29 -070063 static CameraRecord* findCameraById(const std::string& cameraId);
Changyeon Jo59adbd92019-03-05 07:32:59 -080064 static void enumerateDevices();
Scott Randolphb342cb12017-04-25 17:38:29 -070065
66 // NOTE: All members values are static so that all clients operate on the same state
67 // That is to say, this is effectively a singleton despite the fact that HIDL
68 // constructs a new instance for each client.
69 // Because our server has a single thread in the thread pool, these values are
70 // never accessed concurrently despite potentially having multiple instance objects
71 // using them.
Changyeon Job67c0202019-05-20 12:05:25 -070072 static std::unordered_map<std::string,
73 CameraRecord> sCameraList;
Scott Randolphb342cb12017-04-25 17:38:29 -070074
Changyeon Job67c0202019-05-20 12:05:25 -070075 static wp<EvsGlDisplay> sActiveDisplay; // Weak pointer.
76 // Object destructs if client dies.
Changyeon Jo6fa38022019-05-03 16:35:16 -070077
Changyeon Job67c0202019-05-20 12:05:25 -070078 static std::mutex sLock; // Mutex on shared camera device list.
79 static std::condition_variable sCameraSignal; // Signal on camera device addition.
Scott Randolphb342cb12017-04-25 17:38:29 -070080};
81
82} // namespace implementation
83} // namespace V1_0
84} // namespace evs
85} // namespace automotive
86} // namespace hardware
87} // namespace android
88
89#endif // ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_0_EVSCAMERAENUMERATOR_H