1 /*
2  * Copyright (C) 2022 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_AIDL_SERVICE_AIDL_CAMERA_PROVIDER_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_PROVIDER_H_
19 
20 #include <aidl/android/hardware/camera/provider/BnCameraProvider.h>
21 #include <aidl/android/hardware/camera/provider/ICameraProviderCallback.h>
22 
23 #include <regex>
24 
25 #include "camera_provider.h"
26 
27 namespace android {
28 namespace hardware {
29 namespace camera {
30 namespace provider {
31 namespace implementation {
32 
33 using aidl::android::hardware::camera::common::VendorTagSection;
34 using aidl::android::hardware::camera::device::ICameraDevice;
35 using aidl::android::hardware::camera::provider::BnCameraProvider;
36 using aidl::android::hardware::camera::provider::CameraIdAndStreamCombination;
37 using aidl::android::hardware::camera::provider::ConcurrentCameraIdCombination;
38 using aidl::android::hardware::camera::provider::ICameraProviderCallback;
39 
40 using ::android::google_camera_hal::CameraProvider;
41 using ndk::ScopedAStatus;
42 
43 // AidlCameraProvider implements the AIDL camera provider interface,
44 // ICameraProvider, to enumerate the available individual camera devices
45 // in the system, and provide updates about changes to device status.
46 class AidlCameraProvider : public BnCameraProvider {
47  public:
48   static const std::string kProviderName;
49   static std::shared_ptr<AidlCameraProvider> Create();
50   virtual ~AidlCameraProvider() = default;
51 
52   // Override functions in ICameraProvider.
53 
54   ScopedAStatus setCallback(
55       const std::shared_ptr<ICameraProviderCallback>& callback) override;
56 
57   ScopedAStatus getVendorTags(std::vector<VendorTagSection>* vts) override;
58 
59   ScopedAStatus getCameraIdList(std::vector<std::string>* camera_ids) override;
60 
61   ScopedAStatus getCameraDeviceInterface(
62       const std::string& in_cameraDeviceName,
63       std::shared_ptr<ICameraDevice>* device) override;
64 
65   ScopedAStatus notifyDeviceStateChange(int64_t in_deviceState) override;
66 
67   ScopedAStatus getConcurrentCameraIds(
68       std::vector<ConcurrentCameraIdCombination>* concurrent_camera_ids) override;
69 
70   ScopedAStatus isConcurrentStreamCombinationSupported(
71       const std::vector<CameraIdAndStreamCombination>& in_configs,
72       bool* support) override;
73 
74   // End of override functions in ICameraProvider.
75   AidlCameraProvider() = default;
76 
77  private:
78   static const std::regex kDeviceNameRegex;
79 
80   status_t Initialize();
81 
82   // Parse device version and camera ID.
83   bool ParseDeviceName(const std::string& device_name,
84                        std::string* device_version, std::string* camera_id);
85 
86   std::mutex callbacks_lock_;
87   std::shared_ptr<ICameraProviderCallback> callbacks_;
88 
89   std::unique_ptr<CameraProvider> google_camera_provider_;
90   google_camera_hal::CameraProviderCallback camera_provider_callback_;
91 };
92 
93 }  // namespace implementation
94 }  // namespace provider
95 }  // namespace camera
96 }  // namespace hardware
97 }  // namespace android
98 
99 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_PROVIDER_H_
100