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