• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SESSION_HWL_IMPL_H
18 #define EMULATOR_CAMERA_HAL_HWL_CAMERA_DEVICE_SESSION_HWL_IMPL_H
19 
20 #include <camera_device_session_hwl.h>
21 
22 #include <memory>
23 #include <set>
24 
25 #include "EmulatedCameraDeviceHWLImpl.h"
26 #include "EmulatedRequestProcessor.h"
27 #include "EmulatedTorchState.h"
28 #include "multicam_coordinator_hwl.h"
29 #include "utils/StreamConfigurationMap.h"
30 
31 namespace android {
32 
33 using google_camera_hal::CameraDeviceHwl;
34 using google_camera_hal::CameraDeviceSessionHwl;
35 using google_camera_hal::CaptureRequest;
36 using google_camera_hal::CaptureResult;
37 using google_camera_hal::Dimension;
38 using google_camera_hal::HalStream;
39 using google_camera_hal::HwlOfflinePipelineRole;
40 using google_camera_hal::HwlPipelineCallback;
41 using google_camera_hal::HwlPipelineRequest;
42 using google_camera_hal::HwlSessionCallback;
43 using google_camera_hal::IMulticamCoordinatorHwl;
44 using google_camera_hal::RequestTemplate;
45 using google_camera_hal::SessionDataKey;
46 using google_camera_hal::Stream;
47 using google_camera_hal::StreamConfiguration;
48 using google_camera_hal::ZoomRatioMapperHwl;
49 
50 class EmulatedCameraZoomRatioMapperHwlImpl : public ZoomRatioMapperHwl {
51  public:
52   EmulatedCameraZoomRatioMapperHwlImpl(
53       const std::unordered_map<uint32_t, std::pair<Dimension, Dimension>>& dims);
54   virtual ~EmulatedCameraZoomRatioMapperHwlImpl() = default;
55 
56   // Limit zoom ratio if concurrent mode is on
LimitZoomRatioIfConcurrent(float *)57   virtual void LimitZoomRatioIfConcurrent(float*) const override{};
58 
59   // Get the array dimensions to be used for this capture request / result
60   virtual bool GetActiveArrayDimensionToBeUsed(
61       uint32_t camera_id, const HalCameraMetadata* settings,
62       Dimension* active_array_dimension) const override;
63   // Apply zoom ratio to capture request
UpdateCaptureRequest(CaptureRequest *)64   virtual void UpdateCaptureRequest(CaptureRequest*) override{};
65 
66   // Apply zoom ratio to capture result
UpdateCaptureResult(CaptureResult *)67   virtual void UpdateCaptureResult(CaptureResult*) override{};
68 
69   static std::unique_ptr<EmulatedCameraZoomRatioMapperHwlImpl> Create(
70       const std::unordered_map<uint32_t, std::pair<Dimension, Dimension>>& dims);
71 
72  private:
73   // camera id -> {max res dimension (array size), default dimension }
74   std::unordered_map<uint32_t, std::pair<Dimension, Dimension>>
75       camera_ids_to_dimensions_;
76 };
77 
78 // Implementation of CameraDeviceSessionHwl interface
79 class EmulatedCameraDeviceSessionHwlImpl : public CameraDeviceSessionHwl {
80  public:
81   static std::unique_ptr<EmulatedCameraDeviceSessionHwlImpl> Create(
82       uint32_t camera_id, std::unique_ptr<HalCameraMetadata> static_meta,
83       PhysicalDeviceMapPtr physical_devices,
84       std::shared_ptr<EmulatedTorchState> torch_state);
85 
86   virtual ~EmulatedCameraDeviceSessionHwlImpl();
87 
88   // Override functions in CameraDeviceSessionHwl
89   status_t ConstructDefaultRequestSettings(
90       RequestTemplate type,
91       std::unique_ptr<HalCameraMetadata>* default_settings) override;
92 
PrepareConfigureStreams(const StreamConfiguration &)93   status_t PrepareConfigureStreams(
94       const StreamConfiguration& /*request_config*/) override {
95     return OK;
96   }  // Noop for now
97 
98   status_t ConfigurePipeline(uint32_t physical_camera_id,
99                              HwlPipelineCallback hwl_pipeline_callback,
100                              const StreamConfiguration& request_config,
101                              const StreamConfiguration& overall_config,
102                              uint32_t* pipeline_id) override;
103 
104   status_t BuildPipelines() override;
105 
PreparePipeline(uint32_t,uint32_t)106   status_t PreparePipeline(uint32_t /*pipeline_id*/,
107                            uint32_t /*frame_number*/) override {
108     return OK;
109   }  // Noop for now
110 
GetRequiredIntputStreams(const StreamConfiguration &,HwlOfflinePipelineRole,std::vector<Stream> *)111   status_t GetRequiredIntputStreams(const StreamConfiguration& /*overall_config*/,
112                                     HwlOfflinePipelineRole /*pipeline_role*/,
113                                     std::vector<Stream>* /*streams*/) override {
114     // N/A
115     return INVALID_OPERATION;
116   }
117 
118   status_t GetConfiguredHalStream(
119       uint32_t pipeline_id, std::vector<HalStream>* hal_streams) const override;
120 
121   void DestroyPipelines() override;
122 
123   status_t SubmitRequests(uint32_t frame_number,
124                           std::vector<HwlPipelineRequest>& requests) override;
125 
126   status_t Flush() override;
127 
128   uint32_t GetCameraId() const override;
129 
130   std::vector<uint32_t> GetPhysicalCameraIds() const override;
131 
132   status_t GetCameraCharacteristics(
133       std::unique_ptr<HalCameraMetadata>* characteristics) const override;
134 
135   status_t GetPhysicalCameraCharacteristics(
136       uint32_t physical_camera_id,
137       std::unique_ptr<HalCameraMetadata>* characteristics) const override;
138 
SetSessionData(SessionDataKey,void *)139   status_t SetSessionData(SessionDataKey /*key*/
140                                     ,
141                                     void* /*value*/) override {
142     return OK;
143   }  // Noop for now
144 
GetSessionData(SessionDataKey,void **)145   status_t GetSessionData(SessionDataKey /*key*/,
146                           void** /*value*/) const override {
147     return OK;
148   }  // Noop for now
149 
150   void SetSessionCallback(
151       const HwlSessionCallback& hwl_session_callback) override;
152 
FilterResultMetadata(HalCameraMetadata *)153   status_t FilterResultMetadata(HalCameraMetadata* /*metadata*/) const override {
154     return OK;
155   }  // Noop for now
156 
CreateMulticamCoordinatorHwl()157   std::unique_ptr<IMulticamCoordinatorHwl> CreateMulticamCoordinatorHwl()
158       override {
159     return nullptr;
160   }
161 
IsReconfigurationRequired(const HalCameraMetadata *,const HalCameraMetadata *,bool * reconfiguration_required)162   status_t IsReconfigurationRequired(
163       const HalCameraMetadata* /*old_session*/,
164       const HalCameraMetadata* /*new_session*/,
165       bool* reconfiguration_required) const override {
166     if (reconfiguration_required == nullptr) {
167       return BAD_VALUE;
168     }
169     *reconfiguration_required = true;
170     return OK;
171   }
172 
GetZoomRatioMapperHwl()173   std::unique_ptr<google_camera_hal::ZoomRatioMapperHwl> GetZoomRatioMapperHwl()
174       override {
175     return std::move(zoom_ratio_mapper_hwl_impl_);
176   }
177   // End override functions in CameraDeviceSessionHwl
178 
179  private:
180   status_t Initialize(uint32_t camera_id,
181                       std::unique_ptr<HalCameraMetadata> static_meta);
182   status_t InitializeRequestProcessor();
183 
184   status_t CheckOutputFormatsForInput(
185       const HwlPipelineRequest& request,
186       const std::unordered_map<uint32_t, EmulatedStream>& streams,
187       const std::unique_ptr<StreamConfigurationMap>& stream_configuration_map,
188       android_pixel_format_t input_format);
189 
EmulatedCameraDeviceSessionHwlImpl(PhysicalDeviceMapPtr physical_devices,std::shared_ptr<EmulatedTorchState> torch_state)190   EmulatedCameraDeviceSessionHwlImpl(
191       PhysicalDeviceMapPtr physical_devices,
192       std::shared_ptr<EmulatedTorchState> torch_state)
193       : torch_state_(torch_state),
194         physical_device_map_(std::move(physical_devices)) {
195   }
196 
197   uint8_t max_pipeline_depth_ = 0;
198 
199   // Protects the API entry points
200   mutable std::mutex api_mutex_;
201   uint32_t camera_id_ = 0;
202   bool error_state_ = false;
203   bool pipelines_built_ = false;
204   bool has_raw_stream_ = false;
205   std::unique_ptr<HalCameraMetadata> static_metadata_;
206   std::vector<EmulatedPipeline> pipelines_;
207   std::shared_ptr<EmulatedRequestProcessor> request_processor_;
208   std::unique_ptr<StreamConfigurationMap> stream_configuration_map_;
209   PhysicalStreamConfigurationMap physical_stream_configuration_map_;
210   PhysicalStreamConfigurationMap physical_stream_configuration_map_max_resolution_;
211   std::unique_ptr<StreamConfigurationMap> stream_configuration_map_max_resolution_;
212   SensorCharacteristics sensor_chars_;
213   std::shared_ptr<EmulatedTorchState> torch_state_;
214   PhysicalDeviceMapPtr physical_device_map_;
215   LogicalCharacteristics logical_chars_;
216   HwlSessionCallback session_callback_;
217   DynamicStreamIdMapType dynamic_stream_id_map_;
218   std::unique_ptr<EmulatedCameraZoomRatioMapperHwlImpl> zoom_ratio_mapper_hwl_impl_;
219 };
220 
221 }  // namespace android
222 
223 #endif
224