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_GOOGLE_CAMERA_HAL_CAMERA_PROVIDER_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_PROVIDER_H_
19 
20 #include <utils/Errors.h>
21 #include <memory>
22 
23 #include "camera_buffer_allocator_hwl.h"
24 #include "camera_device.h"
25 #include "camera_provider_callback.h"
26 #include "camera_provider_hwl.h"
27 #include "vendor_tags.h"
28 
29 namespace android {
30 namespace google_camera_hal {
31 class CameraProvider {
32  public:
33   // Create a Camera Provider.
34   // If camera_provider_hwl is nullptr, CameraProvider will try to open
35   // a library containing the camera_provider_hwl implementation for the device.
36   static std::unique_ptr<CameraProvider> Create(
37       std::unique_ptr<CameraProviderHwl> camera_provider_hwl = nullptr);
38   virtual ~CameraProvider();
39 
40   // Set callback functions.
41   status_t SetCallback(const CameraProviderCallback* callback);
42 
43   // Trigger deferred callbacks (such as physical camera avail/unavail) right
44   // after setCallback() is called.
45   status_t TriggerDeferredCallbacks();
46 
47   // Get vendor tags.
48   status_t GetVendorTags(
49       std::vector<VendorTagSection>* vendor_tag_sections) const;
50 
51   // Get a list of camera IDs.
52   status_t GetCameraIdList(std::vector<uint32_t>* camera_ids) const;
53 
54   // Return if torch mode is supported.
55   bool IsSetTorchModeSupported() const;
56 
57   // Create a CameraDevice for camera_id.
58   status_t CreateCameraDevice(uint32_t camera_id,
59                               std::unique_ptr<CameraDevice>* device);
60 
61   // Get the combinations of camera ids which support concurrent streaming
62   status_t GetConcurrentStreamingCameraIds(
63       std::vector<std::unordered_set<uint32_t>>* camera_id_combinations);
64 
65   // Check if a set of concurrent stream  configurations are supported
66   status_t IsConcurrentStreamCombinationSupported(
67       const std::vector<CameraIdAndStreamConfiguration>& configs,
68       bool* is_supported);
69 
70   status_t NotifyDeviceStateChange(google_camera_hal::DeviceState device_state);
71 
72  protected:
73   CameraProvider() = default;
74 
75  private:
76   status_t Initialize(std::unique_ptr<CameraProviderHwl> camera_provider_hwl);
77 
78   // Initialize the vendor tag manager
79   status_t InitializeVendorTags();
80 
81   status_t CreateHwl(std::unique_ptr<CameraProviderHwl>* camera_provider_hwl);
82 
83   // Provider library handle.
84   void* hwl_lib_handle_ = nullptr;
85 
86   std::unique_ptr<CameraProviderHwl> camera_provider_hwl_;
87 
88   const CameraProviderCallback* provider_callback_ = nullptr;
89   HwlCameraProviderCallback hwl_provider_callback_;
90 
91   std::unique_ptr<CameraBufferAllocatorHwl> camera_allocator_hwl_;
92   // Combined list of vendor tags from HAL and HWL
93   std::vector<VendorTagSection> vendor_tag_sections_;
94 };
95 
96 extern "C" CameraProviderHwl* CreateCameraProviderHwl();
97 
98 }  // namespace google_camera_hal
99 }  // namespace android
100 
101 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_PROVIDER_H_
102