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 "EmulatedSensor.h"
24 #include "EmulatedTorchState.h"
25 #include "utils/HWLUtils.h"
26 #include "utils/StreamConfigurationMap.h"
27 
28 namespace android {
29 
30 using google_camera_hal::CameraBufferAllocatorHwl;
31 using google_camera_hal::CameraDeviceHwl;
32 using google_camera_hal::CameraDeviceSessionHwl;
33 using google_camera_hal::CameraResourceCost;
34 using google_camera_hal::HalCameraMetadata;
35 using google_camera_hal::StreamConfiguration;
36 using google_camera_hal::TorchMode;
37 
38 class EmulatedCameraDeviceHwlImpl : public CameraDeviceHwl {
39  public:
40   static std::unique_ptr<CameraDeviceHwl> Create(
41       uint32_t camera_id, std::unique_ptr<HalCameraMetadata> static_meta,
42       PhysicalDeviceMapPtr physical_devices,
43       std::shared_ptr<EmulatedTorchState> torch_state);
44 
45   virtual ~EmulatedCameraDeviceHwlImpl() = default;
46 
47   // Override functions in CameraDeviceHwl.
48   uint32_t GetCameraId() const override;
49 
50   status_t GetResourceCost(CameraResourceCost* cost) const override;
51 
52   status_t GetCameraCharacteristics(
53       std::unique_ptr<HalCameraMetadata>* characteristics) const override;
54 
55   status_t GetPhysicalCameraCharacteristics(
56       uint32_t physical_camera_id,
57       std::unique_ptr<HalCameraMetadata>* characteristics) const override;
58 
59   status_t SetTorchMode(TorchMode mode) override;
60 
61   status_t DumpState(int fd) override;
62 
63   status_t CreateCameraDeviceSessionHwl(
64       CameraBufferAllocatorHwl* camera_allocator_hwl,
65       std::unique_ptr<CameraDeviceSessionHwl>* session) override;
66 
67   bool IsStreamCombinationSupported(
68       const StreamConfiguration& stream_config) override;
69 
70   // End of override functions in CameraDeviceHwl.
71 
72  private:
73   EmulatedCameraDeviceHwlImpl(uint32_t camera_id,
74                               std::unique_ptr<HalCameraMetadata> static_meta,
75                               PhysicalDeviceMapPtr physical_devices,
76                               std::shared_ptr<EmulatedTorchState> torch_state);
77 
78   status_t Initialize();
79 
80   const uint32_t camera_id_ = 0;
81 
82   std::unique_ptr<HalCameraMetadata> static_metadata_;
83   std::unique_ptr<StreamConfigurationMap> stream_configuration_map_;
84   std::unique_ptr<StreamConfigurationMap> stream_configuration_map_max_resolution_;
85   PhysicalStreamConfigurationMap physical_stream_configuration_map_;
86   PhysicalStreamConfigurationMap physical_stream_configuration_map_max_resolution_;
87   PhysicalDeviceMapPtr physical_device_map_;
88   std::shared_ptr<EmulatedTorchState> torch_state_;
89   LogicalCharacteristics sensor_chars_;
90 };
91 
92 }  // namespace android
93 
94 #endif  // EMULATOR_CAMERA_HAL_HWL_CAMERA_DEVICE_HWL_H
95