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