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_LOGICAL_REQUEST_STATE_H
18 #define EMULATOR_CAMERA_HAL_LOGICAL_REQUEST_STATE_H
19 
20 #include "EmulatedRequestState.h"
21 #include "hwl_types.h"
22 #include "utils/HWLUtils.h"
23 
24 namespace android {
25 
26 using google_camera_hal::HalCameraMetadata;
27 
28 class EmulatedLogicalRequestState {
29  public:
30   EmulatedLogicalRequestState(uint32_t camera_id);
31   virtual ~EmulatedLogicalRequestState();
32 
33   status_t Initialize(std::unique_ptr<HalCameraMetadata> static_meta,
34                       PhysicalDeviceMapPtr physical_device_map);
35 
36   status_t GetDefaultRequest(
37       RequestTemplate type,
38       std::unique_ptr<HalCameraMetadata>* default_settings /*out*/);
39 
40   std::unique_ptr<HwlPipelineResult> InitializeLogicalResult(
41       uint32_t pipeline_id, uint32_t frame_number);
42 
43   status_t InitializeLogicalSettings(
44       std::unique_ptr<HalCameraMetadata> request_settings,
45       std::unique_ptr<std::set<uint32_t>> physical_camera_output_ids,
46       EmulatedSensor::LogicalCameraSettings* logical_settings /*out*/);
47 
48   static std::unique_ptr<HalCameraMetadata> AdaptLogicalCharacteristics(
49       std::unique_ptr<HalCameraMetadata> logical_chars,
50       PhysicalDeviceMapPtr physical_devices);
51 
52  private:
53   uint32_t logical_camera_id_ = 0;
54   std::unique_ptr<EmulatedRequestState> logical_request_state_;
55   bool is_logical_device_ = false;
56   std::unique_ptr<std::set<uint32_t>> physical_camera_output_ids_;
57   PhysicalDeviceMapPtr physical_device_map_;
58   // Maps a physical device id to its respective request state
59   std::unordered_map<uint32_t, std::unique_ptr<EmulatedRequestState>>
60       physical_request_states_;
61   // Maps particular focal length to physical device id
62   std::unordered_map<float, uint32_t> physical_focal_length_map_;
63   float current_focal_length_ = 0.f;
64 
65   EmulatedLogicalRequestState(const EmulatedLogicalRequestState&) = delete;
66   EmulatedLogicalRequestState& operator=(const EmulatedLogicalRequestState&) =
67       delete;
68 };
69 
70 }  // namespace android
71 
72 #endif  // EMULATOR_CAMERA_HAL_LOGICAL_REQUEST_STATE_H
73