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