blob: 0f0959f1f02a46c6d05c3d46027f647770c3cb08 [file] [log] [blame]
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -08001/*
2 * Copyright (C) 2016 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_CAMERAPROVIDER_H
18#define ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H
19
Yin-Chia Yeh10d68342017-01-10 14:21:06 -080020#include <regex>
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080021#include "hardware/camera_common.h"
22#include "utils/Mutex.h"
23#include "utils/SortedVector.h"
24#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
25#include <hidl/Status.h>
26#include <hidl/MQDescriptor.h>
27#include "CameraModule.h"
28#include "VendorTagDescriptor.h"
29
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::TorchModeStatus;
40using ::android::hardware::camera::common::V1_0::VendorTag;
41using ::android::hardware::camera::common::V1_0::VendorTagSection;
42using ::android::hardware::camera::common::V1_0::helper::CameraModule;
43using ::android::hardware::camera::common::V1_0::helper::VendorTagDescriptor;
44using ::android::hardware::camera::provider::V2_4::ICameraProvider;
45using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
46using ::android::hardware::Return;
47using ::android::hardware::Void;
48using ::android::hardware::hidl_vec;
49using ::android::hardware::hidl_string;
50using ::android::sp;
51using ::android::Mutex;
52
53struct CameraProvider : public ICameraProvider, public camera_module_callbacks_t {
54 CameraProvider();
55 ~CameraProvider();
56
57 // Caller must use this method to check if CameraProvider ctor failed
58 bool isInitFailed() { return mInitFailed; }
59
60 // Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
61 Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override;
62 Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override;
63 Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override;
64 Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override;
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -080065 Return<void> getCameraDeviceInterface_V1_x(
66 const hidl_string& cameraDeviceName,
67 getCameraDeviceInterface_V1_x_cb _hidl_cb) override;
68 Return<void> getCameraDeviceInterface_V3_x(
69 const hidl_string& cameraDeviceName,
70 getCameraDeviceInterface_V3_x_cb _hidl_cb) override;
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080071
72private:
73 Mutex mCbLock;
74 sp<ICameraProviderCallback> mCallbacks = nullptr;
75
76 sp<CameraModule> mModule;
77
78 int mNumberOfLegacyCameras;
79 std::map<std::string, camera_device_status_t> mCameraStatusMap; // camera id -> status
80 std::map<std::string, bool> mOpenLegacySupported; // camera id -> open_legacy HAL1.0 supported
81 SortedVector<std::string> mCameraIds; // the "0"/"1" legacy camera Ids
82 // (cameraId string, hidl device name) pairs
83 SortedVector<std::pair<std::string, std::string>> mCameraDeviceNames;
84
Eino-Ville Talvala50fe4302017-08-22 16:15:09 -070085 int mPreferredHal3MinorVersion;
86
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080087 // Must be queried before using any APIs.
88 // APIs will only work when this returns true
89 bool mInitFailed;
90 bool initialize();
91
92 hidl_vec<VendorTagSection> mVendorTagSections;
93 bool setUpVendorTags();
Emilian Peevc9ded512017-04-10 16:12:55 +010094 int checkCameraVersion(int id, camera_info info);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080095
Eino-Ville Talvala50fe4302017-08-22 16:15:09 -070096 // create HIDL device name from camera ID and legacy device version
97 std::string getHidlDeviceName(std::string cameraId, int deviceVersion);
98
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080099 // extract legacy camera ID/device version from a HIDL device name
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800100 static std::string getLegacyCameraId(const hidl_string& deviceName);
101 static int getCameraDeviceVersion(const hidl_string& deviceName);
102
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800103 // convert conventional HAL status to HIDL Status
104 static Status getHidlStatus(int);
105
106 // static callback forwarding methods
107 static void sCameraDeviceStatusChange(
108 const struct camera_module_callbacks* callbacks,
109 int camera_id,
110 int new_status);
111 static void sTorchModeStatusChange(
112 const struct camera_module_callbacks* callbacks,
113 const char* camera_id,
114 int new_status);
Guennadi Liakhovetski7b7ede72017-11-28 09:28:56 +0100115
116 void addDeviceNames(int camera_id, CameraDeviceStatus status = CameraDeviceStatus::PRESENT,
117 bool cam_new = false);
Guennadi Liakhovetskieca1d452017-12-07 10:59:35 +0100118 void removeDeviceNames(int camera_id);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800119};
120
121extern "C" ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name);
122
123} // namespace implementation
124} // namespace V2_4
125} // namespace provider
126} // namespace camera
127} // namespace hardware
128} // namespace android
129
130#endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H