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 HARDWARE_GOOGLE_CAMERA_HAL_HWL_INTERFACE_CAMERA_DEVICE_SESSION_HWL_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_HWL_INTERFACE_CAMERA_DEVICE_SESSION_HWL_H_ 19 20 #include <utils/Errors.h> 21 22 #include <set> 23 #include <vector> 24 25 #include "hal_camera_metadata.h" 26 #include "hwl_types.h" 27 #include "multicam_coordinator_hwl.h" 28 #include "physical_camera_info_hwl.h" 29 #include "profiler.h" 30 #include "session_data_defs.h" 31 #include "zoom_ratio_mapper_hwl.h" 32 33 namespace android { 34 namespace google_camera_hal { 35 36 // CameraDeviceSessionHwl provides methods to return default settings, 37 // create pipelines, submit capture requests, and flush the session. 38 class CameraDeviceSessionHwl : public PhysicalCameraInfoHwl { 39 public: 40 virtual ~CameraDeviceSessionHwl() = default; 41 42 // Construct the default request settings for a request template type. 43 virtual status_t ConstructDefaultRequestSettings( 44 RequestTemplate type, 45 std::unique_ptr<HalCameraMetadata>* default_settings) = 0; 46 47 virtual status_t PrepareConfigureStreams( 48 const StreamConfiguration& request_config) = 0; 49 50 // To create pipelines for a capture session, the client will call 51 // ConfigurePipeline() to configure each pipeline, and call BuildPipelines() 52 // to build all successfully configured pipelines. If a ConfigurePipeline() 53 // returns an error, BuildPipelines() will not build that failed pipeline 54 // configuration. If ConfigurePipeline() is called when previously built 55 // pipelines have not been destroyed, it will return ALREADY_EXISTS. If 56 // DestroyPipelines() is call after ConfigurePipeline(), it will reset 57 // and discard the configured pipelines. 58 // 59 // camera ID specifies which camera this pipeline captures requests from. It 60 // will be one of the camera IDs returned from GetCameraId() and 61 // GetPhysicalCameraIds(). 62 // hwl_pipeline_callback contains callback functions to notify results and 63 // messages. 64 // request_config is the requested stream configuration for one pipeline. 65 // overall_config is the complete requested stream configuration from 66 // frameworks. 67 // pipeline_id is an unique pipeline ID filled by this method. It can be used 68 // to submit requests to a specific pipeline in SubmitRequests(). 69 virtual status_t ConfigurePipeline(uint32_t camera_id, 70 HwlPipelineCallback hwl_pipeline_callback, 71 const StreamConfiguration& request_config, 72 const StreamConfiguration& overall_config, 73 uint32_t* pipeline_id) = 0; 74 75 // Build the successfully configured pipelines from ConfigurePipeline(). If 76 // there is no successfully configured pipeline, this method will return 77 // NO_INIT. 78 virtual status_t BuildPipelines() = 0; 79 80 // Get the stream ids that should be HAL buffer managed. 81 // This is an hwl level method since the hwl layer can make the best decision 82 // about whether to use hal buffer manager for the session configured - since 83 // it has device specific context. GetHalBufferManagedStreams(const StreamConfiguration & config)84 virtual std::set<int32_t> GetHalBufferManagedStreams( 85 const StreamConfiguration& config) { 86 std::set<int32_t> ret; 87 for (const auto& stream : config.streams) { 88 ret.insert(stream.id); 89 } 90 return ret; 91 } 92 93 // Warm up pipeline to ready for taking request, this can be a NoOp for 94 // implementation which doesn't support to put pipeline in standby mode 95 // This call is optional for capture session before sending request. only 96 // needed when capture session want to confirm if the pipeline is ready before 97 // sending request, otherwise HWL session should implicitly get back to ready 98 // state after receiving a request.Multiple pipelines in the same session can 99 // be prepared in parallel by calling this function. 100 // pipeline_id is the id returned from ConfigurePipeline 101 // frame_number is the request frame number when call this interface 102 virtual status_t PreparePipeline(uint32_t pipeline_id, 103 uint32_t frame_number) = 0; 104 105 // Fills required input streams for a certain offline pipeline. Returns an 106 // error if the pipeline being queried is not an offline pipeline. 107 // overall_config is the requested configuration from framework. 108 // pipeline_role is the role of the offline pipeline to query for. 109 // streams is a vector of required input streams to return. 110 virtual status_t GetRequiredIntputStreams( 111 const StreamConfiguration& overall_config, 112 HwlOfflinePipelineRole pipeline_role, std::vector<Stream>* streams) = 0; 113 114 // Get the configured HAL streams for a pipeline. If no pipeline was built, 115 // this method will return NO_INIT. If pipeline_id was not built, this method 116 // will return NAME_NOT_FOUND. 117 virtual status_t GetConfiguredHalStream( 118 uint32_t pipeline_id, std::vector<HalStream>* hal_streams) const = 0; 119 120 // Destroy built pipelines or discard configured pipelines. 121 virtual void DestroyPipelines() = 0; 122 123 // frame_number is the frame number of the requests. 124 // requests contain requests from all different pipelines. If requests contain 125 // more than one request from a certain pipeline, this method will return an 126 // error. All requests captured from camera sensors must be captured 127 // synchronously. 128 virtual status_t SubmitRequests(uint32_t frame_number, 129 std::vector<HwlPipelineRequest>& requests) = 0; 130 131 // Flush all pending requests. 132 virtual status_t Flush() = 0; 133 134 virtual void RepeatingRequestEnd(int32_t frame_number, 135 const std::vector<int32_t>& stream_ids) = 0; 136 137 // Return the camera ID that this camera device session is associated with. 138 virtual uint32_t GetCameraId() const = 0; 139 140 // Returns true if the two given physical camera ids can be streamed 141 // simultaneously from this device session. CanStreamSimultaneously(uint32_t,uint32_t)142 virtual bool CanStreamSimultaneously(uint32_t /* physical_camera_id_1 */, 143 uint32_t /* physical_camera_id_2 */) const { 144 return true; 145 } 146 147 // Return the characteristics that this camera device session is associated with. 148 virtual status_t GetCameraCharacteristics( 149 std::unique_ptr<HalCameraMetadata>* characteristics) const = 0; 150 151 // See common/session_data_def.h for more info on Session Data API 152 // Set a key/value pair for this session 153 virtual status_t SetSessionData(SessionDataKey key, void* value) = 0; 154 155 // Get the value corresponding to the give key in the session 156 virtual status_t GetSessionData(SessionDataKey key, void** value) const = 0; 157 158 // Set the session callback. 159 virtual void SetSessionCallback( 160 const HwlSessionCallback& hwl_session_callback) = 0; 161 162 // Filter out the result metadata to remove any private metadata that is meant 163 // to be internal to the HWL and should not be delivered to the upper layer. 164 // Unless the request specified intermediate processing via 165 // VendorTagIds::kProcessingMode, the HWL impelmentation should by default 166 // remove any private data from the result metadata. 167 virtual status_t FilterResultMetadata(HalCameraMetadata* metadata) const = 0; 168 169 // Return the corresponding HWL coordinator utility interface 170 virtual std::unique_ptr<IMulticamCoordinatorHwl> 171 CreateMulticamCoordinatorHwl() = 0; 172 173 // Check reconfiguration is required or not 174 // old_session is old session parameter 175 // new_session is new session parameter 176 // If reconfiguration is required, set reconfiguration_required to true 177 // If reconfiguration is not required, set reconfiguration_required to false 178 virtual status_t IsReconfigurationRequired( 179 const HalCameraMetadata* old_session, const HalCameraMetadata* new_session, 180 bool* reconfiguration_required) const = 0; 181 182 // Get zoom ratio mapper from HWL. 183 virtual std::unique_ptr<ZoomRatioMapperHwl> GetZoomRatioMapperHwl() = 0; 184 185 // Get maximum number of cameras allowed to stream concurrently. GetMaxSupportedConcurrentCameras()186 virtual int GetMaxSupportedConcurrentCameras() const { 187 return 1; 188 } 189 190 // Get customized profiler GetProfiler(uint32_t,int)191 virtual std::unique_ptr<google::camera_common::Profiler> GetProfiler( 192 uint32_t /* camera_id */, int /* option */) { 193 return nullptr; 194 } 195 196 // Release unused framework buffers from cache. This should be called when a 197 // ProcessCaptureRequest call includes a non-empty cachesToRemove argument. It 198 // is used to pass the list of buffers to the HWL to handle any internal 199 // caching of file descriptors done by the HWL. RemoveCachedBuffers(const native_handle_t *)200 virtual void RemoveCachedBuffers(const native_handle_t* /*handle*/) { 201 } 202 setConfigureStreamsV2(bool set)203 void setConfigureStreamsV2(bool set) { 204 configure_streams_v2_ = set; 205 } 206 configure_streams_v2()207 bool configure_streams_v2() const { 208 return configure_streams_v2_; 209 } 210 211 private: 212 bool configure_streams_v2_ = false; 213 }; 214 215 } // namespace google_camera_hal 216 } // namespace android 217 218 #endif // HARDWARE_GOOGLE_CAMERA_HAL_HWL_INTERFACE_CAMERA_DEVICE_SESSION_HWL_H_ 219