• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include <string>
21 #include <unordered_map>
22 #include <unordered_set>
23 #include <utils/Mutex.h>
24 #include <utils/Thread.h>
25 #include <hidl/Status.h>
26 #include <hidl/MQDescriptor.h>
27 #include "ExternalCameraUtils.h"
28 
29 #include "CameraProvider_2_4.h"
30 
31 namespace android {
32 namespace hardware {
33 namespace camera {
34 namespace provider {
35 namespace V2_4 {
36 namespace implementation {
37 
38 using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
39 using ::android::hardware::camera::common::V1_0::Status;
40 using ::android::hardware::camera::common::V1_0::VendorTagSection;
41 using ::android::hardware::camera::external::common::ExternalCameraConfig;
42 using ::android::hardware::camera::provider::V2_4::ICameraProvider;
43 using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
44 using ::android::hardware::Return;
45 using ::android::hardware::Void;
46 using ::android::hardware::hidl_vec;
47 using ::android::hardware::hidl_string;
48 using ::android::sp;
49 using ::android::Mutex;
50 
51 /**
52  * The implementation of external webcam CameraProvider 2.4, separated
53  * from the HIDL interface layer to allow for implementation reuse by later
54  * provider versions.
55  *
56  * This camera provider supports standard UVC webcameras via the Linux V4L2
57  * UVC driver.
58  */
59 struct ExternalCameraProviderImpl_2_4 {
60     ExternalCameraProviderImpl_2_4();
61     ~ExternalCameraProviderImpl_2_4();
62 
63     // Caller must use this method to check if CameraProvider ctor failed
isInitFailedExternalCameraProviderImpl_2_464     bool isInitFailed() { return false;}
65 
66     // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
67     Return<Status> setCallback(const sp<ICameraProviderCallback>& callback);
68     Return<void> getVendorTags(ICameraProvider::getVendorTags_cb _hidl_cb);
69     Return<void> getCameraIdList(ICameraProvider::getCameraIdList_cb _hidl_cb);
70     Return<void> isSetTorchModeSupported(ICameraProvider::isSetTorchModeSupported_cb _hidl_cb);
71     Return<void> getCameraDeviceInterface_V1_x(
72             const hidl_string&,
73             ICameraProvider::getCameraDeviceInterface_V1_x_cb);
74     Return<void> getCameraDeviceInterface_V3_x(
75             const hidl_string&,
76             ICameraProvider::getCameraDeviceInterface_V3_x_cb);
77 
78 private:
79 
80     void addExternalCamera(const char* devName);
81 
82     void deviceAdded(const char* devName);
83 
84     void deviceRemoved(const char* devName);
85 
86     class HotplugThread : public android::Thread {
87     public:
88         HotplugThread(ExternalCameraProviderImpl_2_4* parent);
89         ~HotplugThread();
90 
91         virtual bool threadLoop() override;
92 
93     private:
94         ExternalCameraProviderImpl_2_4* mParent = nullptr;
95         const std::unordered_set<std::string> mInternalDevices;
96 
97         int mINotifyFD = -1;
98         int mWd = -1;
99     };
100 
101     Mutex mLock;
102     sp<ICameraProviderCallback> mCallbacks = nullptr;
103     std::unordered_map<std::string, CameraDeviceStatus> mCameraStatusMap; // camera id -> status
104     const ExternalCameraConfig mCfg;
105     HotplugThread mHotPlugThread;
106     int mPreferredHal3MinorVersion;
107 };
108 
109 
110 
111 }  // namespace implementation
112 }  // namespace V2_4
113 }  // namespace provider
114 }  // namespace camera
115 }  // namespace hardware
116 }  // namespace android
117 
118 #endif  // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_EXTCAMERAPROVIDER_H
119