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 using google_camera_hal::HalStream; 28 using google_camera_hal::HwlPipelineCallback; 29 30 struct EmulatedStream : public HalStream { 31 uint32_t width, height; 32 size_t buffer_size; 33 bool is_input; 34 int32_t group_id; 35 int64_t use_case; 36 int32_t color_space; 37 }; 38 39 struct EmulatedPipeline { 40 HwlPipelineCallback cb; 41 // stream id -> stream map 42 std::unordered_map<uint32_t, EmulatedStream> streams; 43 uint32_t physical_camera_id, pipeline_id; 44 }; 45 46 // [physical_camera_id -> [group_id -> stream_id]] 47 typedef std::map<uint32_t, std::map<uint32_t, int32_t>> DynamicStreamIdMapType; 48 49 // Info keeping track of mapping between zoom ratio range, focal length, and 50 // physical camera Id. 51 struct ZoomRatioPhysicalCameraInfo { 52 float focal_length; 53 float min_zoom_ratio; 54 float max_zoom_ratio; 55 uint32_t physical_camera_id; 56 }; 57 58 class EmulatedLogicalRequestState { 59 public: 60 EmulatedLogicalRequestState(uint32_t camera_id); 61 virtual ~EmulatedLogicalRequestState(); 62 63 status_t Initialize(std::unique_ptr<EmulatedCameraDeviceInfo> device_info, 64 PhysicalDeviceMapPtr physical_device_map); 65 66 status_t GetDefaultRequest( 67 RequestTemplate type, 68 std::unique_ptr<HalCameraMetadata>* default_settings /*out*/); 69 70 std::unique_ptr<HwlPipelineResult> InitializeLogicalResult( 71 uint32_t pipeline_id, uint32_t frame_number, bool is_partial_result); 72 73 status_t InitializeLogicalSettings( 74 std::unique_ptr<HalCameraMetadata> request_settings, 75 std::unique_ptr<std::set<uint32_t>> physical_camera_output_ids, 76 uint32_t frame_number, 77 EmulatedSensor::LogicalCameraSettings* logical_settings /*out*/); 78 79 static std::unique_ptr<HalCameraMetadata> AdaptLogicalCharacteristics( 80 std::unique_ptr<HalCameraMetadata> logical_chars, 81 PhysicalDeviceMapPtr physical_devices); 82 83 status_t UpdateRequestForDynamicStreams( 84 HwlPipelineRequest* request, 85 const std::vector<EmulatedPipeline>& pipelines, 86 const DynamicStreamIdMapType& dynamic_stream_id_map_type, 87 bool use_default_physical_camera); 88 89 private: 90 uint32_t logical_camera_id_ = 0; 91 std::unique_ptr<EmulatedRequestState> logical_request_state_; 92 bool is_logical_device_ = false; 93 std::unique_ptr<std::set<uint32_t>> physical_camera_output_ids_; 94 PhysicalDeviceMapPtr physical_device_map_; 95 // Maps a physical device id to its respective request state 96 std::unordered_map<uint32_t, std::unique_ptr<EmulatedRequestState>> 97 physical_request_states_; 98 99 // Describes the mapping between particular zoom ratio boundary value and 100 // physical device id. The vector is sorted by ascending zoom ratios. 101 std::vector<ZoomRatioPhysicalCameraInfo> zoom_ratio_physical_camera_info_; 102 uint32_t current_physical_camera_ = 0; 103 104 static std::vector<ZoomRatioPhysicalCameraInfo> GetZoomRatioPhysicalCameraInfo( 105 const HalCameraMetadata* logical_chars, 106 const PhysicalDeviceMap* physical_devices); 107 static void UpdateActivePhysicalId(HalCameraMetadata* result_metadata, 108 uint32_t device_id); 109 110 EmulatedLogicalRequestState(const EmulatedLogicalRequestState&) = delete; 111 EmulatedLogicalRequestState& operator=(const EmulatedLogicalRequestState&) = 112 delete; 113 }; 114 115 } // namespace android 116 117 #endif // EMULATOR_CAMERA_HAL_LOGICAL_REQUEST_STATE_H 118