blob: c83cc708bf8e4464056311b71b486990f2860773 [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>
Yin-Chia Yeh17982492018-02-05 17:41:01 -080028#include "ExternalCameraUtils.h"
Yin-Chia Yeh19030592017-10-19 17:30:11 -070029
30namespace android {
31namespace hardware {
32namespace camera {
33namespace provider {
34namespace V2_4 {
35namespace implementation {
36
37using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
38using ::android::hardware::camera::common::V1_0::Status;
39using ::android::hardware::camera::common::V1_0::VendorTagSection;
Yin-Chia Yeh17982492018-02-05 17:41:01 -080040using ::android::hardware::camera::external::common::ExternalCameraConfig;
Yin-Chia Yeh19030592017-10-19 17:30:11 -070041using ::android::hardware::camera::provider::V2_4::ICameraProvider;
42using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
43using ::android::hardware::Return;
44using ::android::hardware::Void;
45using ::android::hardware::hidl_vec;
46using ::android::hardware::hidl_string;
47using ::android::sp;
48using ::android::Mutex;
49
50struct ExternalCameraProvider : public ICameraProvider {
51 ExternalCameraProvider();
52 ~ExternalCameraProvider();
53
54 // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
55 Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override;
56
57 Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override;
58
59 Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override;
60
61 Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override;
62
63 Return<void> getCameraDeviceInterface_V1_x(
64 const hidl_string&,
65 getCameraDeviceInterface_V1_x_cb) override;
66 Return<void> getCameraDeviceInterface_V3_x(
67 const hidl_string&,
68 getCameraDeviceInterface_V3_x_cb) override;
69
70private:
71
72 void addExternalCamera(const char* devName);
73
74 void deviceAdded(const char* devName);
75
76 void deviceRemoved(const char* devName);
77
78 class HotplugThread : public android::Thread {
79 public:
80 HotplugThread(ExternalCameraProvider* parent);
81 ~HotplugThread();
82
83 virtual bool threadLoop() override;
84
85 private:
86 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 Yeh17982492018-02-05 17:41:01 -080096 const ExternalCameraConfig mCfg;
Yin-Chia Yeh53f4cb12018-01-29 10:31:45 -080097 HotplugThread mHotPlugThread;
Yin-Chia Yeh19030592017-10-19 17:30:11 -070098};
99
100
101
102} // namespace implementation
103} // namespace V2_4
104} // namespace provider
105} // namespace camera
106} // namespace hardware
107} // namespace android
108
109#endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_EXTCAMERAPROVIDER_H