blob: 64a8878b558de902560640ef0b5222a3974d1a1b [file] [log] [blame]
Yin-Chia Yeh19030592017-10-19 17:30:11 -07001/*
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
Yin-Chia Yeh53f4cb12018-01-29 10:31:45 -080020#include <string>
Yin-Chia Yeh19030592017-10-19 17:30:11 -070021#include <unordered_map>
Yin-Chia Yeh53f4cb12018-01-29 10:31:45 -080022#include <unordered_set>
Yin-Chia Yeh19030592017-10-19 17:30:11 -070023#include "utils/Mutex.h"
24#include "utils/Thread.h"
25#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
26#include <hidl/Status.h>
27#include <hidl/MQDescriptor.h>
28
29namespace android {
30namespace hardware {
31namespace camera {
32namespace provider {
33namespace V2_4 {
34namespace implementation {
35
36using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
37using ::android::hardware::camera::common::V1_0::Status;
38using ::android::hardware::camera::common::V1_0::VendorTagSection;
39using ::android::hardware::camera::provider::V2_4::ICameraProvider;
40using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
41using ::android::hardware::Return;
42using ::android::hardware::Void;
43using ::android::hardware::hidl_vec;
44using ::android::hardware::hidl_string;
45using ::android::sp;
46using ::android::Mutex;
47
48struct ExternalCameraProvider : public ICameraProvider {
49 ExternalCameraProvider();
50 ~ExternalCameraProvider();
51
52 // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
53 Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override;
54
55 Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override;
56
57 Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override;
58
59 Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override;
60
61 Return<void> getCameraDeviceInterface_V1_x(
62 const hidl_string&,
63 getCameraDeviceInterface_V1_x_cb) override;
64 Return<void> getCameraDeviceInterface_V3_x(
65 const hidl_string&,
66 getCameraDeviceInterface_V3_x_cb) override;
67
68private:
69
70 void addExternalCamera(const char* devName);
71
72 void deviceAdded(const char* devName);
73
74 void deviceRemoved(const char* devName);
75
76 class HotplugThread : public android::Thread {
77 public:
78 HotplugThread(ExternalCameraProvider* parent);
79 ~HotplugThread();
80
81 virtual bool threadLoop() override;
82
83 private:
Yin-Chia Yeh53f4cb12018-01-29 10:31:45 -080084 static std::unordered_set<std::string> initInternalDevices();
85
Yin-Chia Yeh19030592017-10-19 17:30:11 -070086 ExternalCameraProvider* mParent = nullptr;
Yin-Chia Yeh53f4cb12018-01-29 10:31:45 -080087 const std::unordered_set<std::string> mInternalDevices;
Yin-Chia Yeh19030592017-10-19 17:30:11 -070088
89 int mINotifyFD = -1;
90 int mWd = -1;
Yin-Chia Yeh53f4cb12018-01-29 10:31:45 -080091 };
Yin-Chia Yeh19030592017-10-19 17:30:11 -070092
93 Mutex mLock;
94 sp<ICameraProviderCallback> mCallbacks = nullptr;
95 std::unordered_map<std::string, CameraDeviceStatus> mCameraStatusMap; // camera id -> status
Yin-Chia Yeh53f4cb12018-01-29 10:31:45 -080096 HotplugThread mHotPlugThread;
Yin-Chia Yeh19030592017-10-19 17:30:11 -070097};
98
99
100
101} // namespace implementation
102} // namespace V2_4
103} // namespace provider
104} // namespace camera
105} // namespace hardware
106} // namespace android
107
108#endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_EXTCAMERAPROVIDER_H