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 EMULATOR_CAMERA_HAL_HWL_CAMERA_DEVICE_HWL_H
18 #define EMULATOR_CAMERA_HAL_HWL_CAMERA_DEVICE_HWL_H
19 
20 #include <camera_device_hwl.h>
21 #include <hal_types.h>
22 
23 #include <vector>
24 
25 #include "EmulatedCameraDeviceInfo.h"
26 #include "EmulatedSensor.h"
27 #include "EmulatedTorchState.h"
28 #include "utils/HWLUtils.h"
29 #include "utils/StreamConfigurationMap.h"
30 
31 namespace android {
32 
33 using google_camera_hal::CameraBufferAllocatorHwl;
34 using google_camera_hal::CameraDeviceHwl;
35 using google_camera_hal::CameraDeviceSessionHwl;
36 using google_camera_hal::CameraResourceCost;
37 using google_camera_hal::HalCameraMetadata;
38 using google_camera_hal::HwlMemoryConfig;
39 using google_camera_hal::kTemplateCount;
40 using google_camera_hal::RequestTemplate;
41 using google_camera_hal::StreamConfiguration;
42 using google_camera_hal::TorchMode;
43 
44 class EmulatedCameraDeviceHwlImpl : public CameraDeviceHwl {
45  public:
46   static std::unique_ptr<CameraDeviceHwl> Create(
47       uint32_t camera_id, std::unique_ptr<HalCameraMetadata> static_meta,
48       PhysicalDeviceMapPtr physical_devices,
49       std::shared_ptr<EmulatedTorchState> torch_state);
50 
51   virtual ~EmulatedCameraDeviceHwlImpl() = default;
52 
53   // Override functions in CameraDeviceHwl.
54   uint32_t GetCameraId() const override;
55 
56   status_t GetResourceCost(CameraResourceCost* cost) const override;
57 
58   status_t GetCameraCharacteristics(
59       std::unique_ptr<HalCameraMetadata>* characteristics) const override;
60 
61   status_t GetSessionCharacteristics(
62       const StreamConfiguration& session_config,
63       std::unique_ptr<HalCameraMetadata>& characteristics) const override;
64 
65   std::vector<uint32_t> GetPhysicalCameraIds() const override;
66 
67   status_t GetPhysicalCameraCharacteristics(
68       uint32_t physical_camera_id,
69       std::unique_ptr<HalCameraMetadata>* characteristics) const override;
70 
71   HwlMemoryConfig GetMemoryConfig() const override;
72 
73   status_t SetTorchMode(TorchMode mode) override;
74 
75   status_t TurnOnTorchWithStrengthLevel(int32_t torch_strength) override;
76 
77   status_t GetTorchStrengthLevel(int32_t& torch_strength) const override;
78 
79   status_t ConstructDefaultRequestSettings(
80       RequestTemplate type,
81       std::unique_ptr<HalCameraMetadata>* request_settings) override;
82 
83   status_t DumpState(int fd) override;
84 
85   status_t CreateCameraDeviceSessionHwl(
86       CameraBufferAllocatorHwl* camera_allocator_hwl,
87       std::unique_ptr<CameraDeviceSessionHwl>* session) override;
88 
89   bool IsStreamCombinationSupported(const StreamConfiguration& stream_config,
90                                     const bool /*check_settings*/) const override;
91 
92   // End of override functions in CameraDeviceHwl.
93 
94  private:
95   EmulatedCameraDeviceHwlImpl(uint32_t camera_id,
96                               std::unique_ptr<HalCameraMetadata> static_meta,
97                               PhysicalDeviceMapPtr physical_devices,
98                               std::shared_ptr<EmulatedTorchState> torch_state);
99 
100   status_t Initialize();
101 
102   int32_t GetDefaultTorchStrengthLevel() const;
103   int32_t GetMaximumTorchStrengthLevel() const;
104 
105   const uint32_t camera_id_ = 0;
106 
107   std::unique_ptr<HalCameraMetadata> static_metadata_;
108   std::unique_ptr<EmulatedCameraDeviceInfo> device_info_;
109   std::unique_ptr<StreamConfigurationMap> stream_configuration_map_;
110   std::unique_ptr<StreamConfigurationMap> stream_configuration_map_max_resolution_;
111   PhysicalStreamConfigurationMap physical_stream_configuration_map_;
112   PhysicalStreamConfigurationMap physical_stream_configuration_map_max_resolution_;
113   PhysicalDeviceMapPtr physical_device_map_;
114   std::shared_ptr<EmulatedTorchState> torch_state_;
115   LogicalCharacteristics sensor_chars_;
116   int32_t default_torch_strength_level_ = 0;
117   int32_t maximum_torch_strength_level_ = 0;
118 
119 };
120 
121 }  // namespace android
122 
123 #endif  // EMULATOR_CAMERA_HAL_HWL_CAMERA_DEVICE_HWL_H
124