blob: c7ed99e8ea36374a587ae4b96fe111861c102a76 [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
20#include <unordered_map>
21#include "utils/Mutex.h"
22#include "utils/Thread.h"
23#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
24#include <hidl/Status.h>
25#include <hidl/MQDescriptor.h>
26
27namespace android {
28namespace hardware {
29namespace camera {
30namespace provider {
31namespace V2_4 {
32namespace implementation {
33
34using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
35using ::android::hardware::camera::common::V1_0::Status;
36using ::android::hardware::camera::common::V1_0::VendorTagSection;
37using ::android::hardware::camera::provider::V2_4::ICameraProvider;
38using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
39using ::android::hardware::Return;
40using ::android::hardware::Void;
41using ::android::hardware::hidl_vec;
42using ::android::hardware::hidl_string;
43using ::android::sp;
44using ::android::Mutex;
45
46struct ExternalCameraProvider : public ICameraProvider {
47 ExternalCameraProvider();
48 ~ExternalCameraProvider();
49
50 // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
51 Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override;
52
53 Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override;
54
55 Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override;
56
57 Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override;
58
59 Return<void> getCameraDeviceInterface_V1_x(
60 const hidl_string&,
61 getCameraDeviceInterface_V1_x_cb) override;
62 Return<void> getCameraDeviceInterface_V3_x(
63 const hidl_string&,
64 getCameraDeviceInterface_V3_x_cb) override;
65
66private:
67
68 void addExternalCamera(const char* devName);
69
70 void deviceAdded(const char* devName);
71
72 void deviceRemoved(const char* devName);
73
74 class HotplugThread : public android::Thread {
75 public:
76 HotplugThread(ExternalCameraProvider* parent);
77 ~HotplugThread();
78
79 virtual bool threadLoop() override;
80
81 private:
82 ExternalCameraProvider* mParent = nullptr;
83
84 int mINotifyFD = -1;
85 int mWd = -1;
86 } mHotPlugThread;
87
88 Mutex mLock;
89 sp<ICameraProviderCallback> mCallbacks = nullptr;
90 std::unordered_map<std::string, CameraDeviceStatus> mCameraStatusMap; // camera id -> status
91};
92
93
94
95} // namespace implementation
96} // namespace V2_4
97} // namespace provider
98} // namespace camera
99} // namespace hardware
100} // namespace android
101
102#endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_EXTCAMERAPROVIDER_H