1 /*
2  * Copyright (C) 2019 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 HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_PROVIDER_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_PROVIDER_H_
19 
20 #include <android/hardware/camera/provider/2.6/ICameraProvider.h>
21 #include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h>
22 #include "camera_provider.h"
23 
24 namespace android {
25 namespace hardware {
26 namespace camera {
27 namespace provider {
28 namespace V2_6 {
29 namespace implementation {
30 
31 using ::android::sp;
32 using ::android::hardware::hidl_string;
33 using ::android::hardware::hidl_vec;
34 using ::android::hardware::Return;
35 using ::android::hardware::Void;
36 using ::android::hardware::camera::common::V1_0::CameraDeviceStatus;
37 using ::android::hardware::camera::common::V1_0::Status;
38 using ::android::hardware::camera::common::V1_0::TorchModeStatus;
39 using ::android::hardware::camera::common::V1_0::VendorTag;
40 using ::android::hardware::camera::common::V1_0::VendorTagSection;
41 using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
42 using ::android::hardware::camera::provider::V2_5::DeviceState;
43 using ::android::hardware::camera::provider::V2_6::CameraIdAndStreamCombination;
44 using ::android::hardware::camera::provider::V2_6::ICameraProvider;
45 
46 using ::android::google_camera_hal::CameraProvider;
47 
48 // HidlCameraProvider implements the HIDL camera provider interface,
49 // ICameraProvider, to enumerate the available individual camera devices
50 // in the system, and provide updates about changes to device status.
51 class HidlCameraProvider : public ICameraProvider {
52  public:
53   static const std::string kProviderName;
54   static std::unique_ptr<HidlCameraProvider> Create();
55   virtual ~HidlCameraProvider() = default;
56 
57   // Override functions in ICameraProvider.
58   Return<Status> setCallback(
59       const sp<ICameraProviderCallback>& callback) override;
60 
61   Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override;
62 
63   Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override;
64 
65   Return<void> isSetTorchModeSupported(
66       isSetTorchModeSupported_cb _hidl_cb) override;
67 
68   Return<void> getConcurrentStreamingCameraIds(
69       getConcurrentStreamingCameraIds_cb _hidl_cb) override;
70 
71   Return<void> isConcurrentStreamCombinationSupported(
72       const hidl_vec<CameraIdAndStreamCombination>& configs,
73       isConcurrentStreamCombinationSupported_cb _hidl_cb) override;
74 
75   Return<void> getCameraDeviceInterface_V1_x(
76       const hidl_string& cameraDeviceName,
77       getCameraDeviceInterface_V1_x_cb _hidl_cb) override;
78 
79   Return<void> getCameraDeviceInterface_V3_x(
80       const hidl_string& cameraDeviceName,
81       getCameraDeviceInterface_V3_x_cb _hidl_cb) override;
82 
83   Return<void> notifyDeviceStateChange(
84       hardware::hidl_bitfield<DeviceState> newState) override;
85   // End of override functions in ICameraProvider.
86 
87  protected:
88   HidlCameraProvider() = default;
89 
90  private:
91   static const std::regex kDeviceNameRegex;
92 
93   status_t Initialize();
94 
95   // Parse device version and camera ID.
96   bool ParseDeviceName(const hidl_string& device_name,
97                        std::string* device_version, std::string* camera_id);
98 
99   std::mutex callbacks_lock_;
100   sp<ICameraProviderCallback> callbacks_;
101 
102   std::unique_ptr<CameraProvider> google_camera_provider_;
103   google_camera_hal::CameraProviderCallback camera_provider_callback_;
104 };
105 
106 extern "C" ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name);
107 
108 }  // namespace implementation
109 }  // namespace V2_6
110 }  // namespace provider
111 }  // namespace camera
112 }  // namespace hardware
113 }  // namespace android
114 
115 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_PROVIDER_H_
116