• 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_GOOGLE_CAMERA_HAL_HDRPLUS_CAPTURE_SESSION_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_HDRPLUS_CAPTURE_SESSION_H_
19 
20 #include "camera_buffer_allocator_hwl.h"
21 #include "camera_device_session_hwl.h"
22 #include "capture_session.h"
23 #include "hwl_types.h"
24 #include "request_processor.h"
25 #include "result_dispatcher.h"
26 #include "result_processor.h"
27 #include "vendor_tag_types.h"
28 
29 namespace android {
30 namespace google_camera_hal {
31 
32 // HdrplusCaptureSession implements a CaptureSession that contains two
33 // process chains (realtime and HDR+)
34 //
35 // 1. RealtimeZslRequestProcessor -> RealtimeProcessBlock ->
36 //    RealtimeZslResultRequestProcessor
37 // 2. HdrplusRequestProcessor -> HdrplusProcessBlock -> HdrplusResultProcessor
38 //
39 // It only supports a single physical camera device session.
40 class HdrplusCaptureSession : public CaptureSession {
41  public:
42   // Return if the device session HWL and stream configuration are supported.
43   static bool IsStreamConfigurationSupported(
44       CameraDeviceSessionHwl* device_session_hwl,
45       const StreamConfiguration& stream_config);
46 
47   // Create a HdrplusCaptureSession.
48   //
49   // device_session_hwl is owned by the caller and must be valid during the
50   // lifetime of HdrplusCaptureSession.
51   // stream_config is the stream configuration.
52   // process_capture_result is the callback function to notify results.
53   // process_batch_capture_result is the callback function to notify batched
54   // results.
55   // notify is the callback function to notify messages.
56   // hal_configured_streams will be filled with HAL configured streams.
57   // camera_allocator_hwl is owned by the caller and must be valid during the
58   // lifetime of HdrplusCaptureSession
59   static std::unique_ptr<HdrplusCaptureSession> Create(
60       CameraDeviceSessionHwl* device_session_hwl,
61       const StreamConfiguration& stream_config,
62       ProcessCaptureResultFunc process_capture_result,
63       ProcessBatchCaptureResultFunc process_batch_capture_result,
64       NotifyFunc notify, HwlSessionCallback session_callback,
65       std::vector<HalStream>* hal_configured_streams,
66       CameraBufferAllocatorHwl* camera_allocator_hwl = nullptr);
67 
68   virtual ~HdrplusCaptureSession();
69 
70   // Override functions in CaptureSession start.
71   status_t ProcessRequest(const CaptureRequest& request) override;
72 
73   status_t Flush() override;
74   // Override functions in CaptureSession end.
75 
76  protected:
77   HdrplusCaptureSession() = default;
78 
79  private:
80   static const uint32_t kRawBufferCount = 16;
81   static const uint32_t kRawMinBufferCount = 12;
82   static constexpr uint32_t kPartialResult = 1;
83   static const android_pixel_format_t kHdrplusRawFormat = HAL_PIXEL_FORMAT_RAW10;
84   status_t Initialize(CameraDeviceSessionHwl* device_session_hwl,
85                       const StreamConfiguration& stream_config,
86                       ProcessCaptureResultFunc process_capture_result,
87                       NotifyFunc notify,
88                       std::vector<HalStream>* hal_configured_streams);
89 
90   // Setup realtime process chain
91   status_t SetupRealtimeProcessChain(
92       const StreamConfiguration& stream_config,
93       ProcessCaptureResultFunc process_capture_result, NotifyFunc notify,
94       std::unique_ptr<ProcessBlock>* realtime_process_block,
95       std::unique_ptr<ResultProcessor>* realtime_result_processor,
96       int32_t* raw_stream_id);
97 
98   // Setup hdrplus process chain
99   status_t SetupHdrplusProcessChain(
100       const StreamConfiguration& stream_config,
101       ProcessCaptureResultFunc process_capture_result, NotifyFunc notify,
102       std::unique_ptr<ProcessBlock>* hdrplus_process_block,
103       std::unique_ptr<ResultProcessor>* hdrplus_result_processor,
104       int32_t raw_stream_id);
105 
106   // Configure streams for request processor and process block.
107   status_t ConfigureStreams(const StreamConfiguration& stream_config,
108                             RequestProcessor* request_processor,
109                             ProcessBlock* process_block, int32_t* raw_stream_id);
110 
111   // Configure hdrplus streams for request processor and process block.
112   status_t ConfigureHdrplusStreams(const StreamConfiguration& stream_config,
113                                    RequestProcessor* hdrplus_request_processor,
114                                    ProcessBlock* hdrplus_process_block);
115 
116   // Build pipelines and return HAL configured streams.
117   // Allocate internal raw buffer
118   status_t BuildPipelines(ProcessBlock* process_block,
119                           ProcessBlock* hdrplus_process_block,
120                           std::vector<HalStream>* hal_configured_streams);
121 
122   // Connect the process chain.
123   status_t ConnectProcessChain(RequestProcessor* request_processor,
124                                std::unique_ptr<ProcessBlock> process_block,
125                                std::unique_ptr<ResultProcessor> result_processor);
126 
127   // Purge the hal_configured_streams such that only framework streams are left
128   status_t PurgeHalConfiguredStream(
129       const StreamConfiguration& stream_config,
130       std::vector<HalStream>* hal_configured_streams);
131 
132   // Invoked when receiving a result from result processor.
133   void ProcessCaptureResult(std::unique_ptr<CaptureResult> result);
134 
135   // Invoked when reciving a message from result processor.
136   void NotifyHalMessage(const NotifyMessage& message);
137 
138   std::unique_ptr<RequestProcessor> request_processor_;
139 
140   std::unique_ptr<RequestProcessor> hdrplus_request_processor_;
141   // device_session_hwl_ is owned by the client.
142   CameraDeviceSessionHwl* device_session_hwl_ = nullptr;
143 
144   std::unique_ptr<InternalStreamManager> internal_stream_manager_;
145 
146   std::unique_ptr<ResultDispatcher> result_dispatcher_;
147 
148   std::mutex callback_lock_;
149   // The following callbacks must be protected by callback_lock_.
150   ProcessCaptureResultFunc process_capture_result_;
151   NotifyFunc notify_;
152   // For error notify to framework directly
153   NotifyFunc device_session_notify_;
154   // Use this stream id to check the request is HDR+ compatible
155   int32_t hal_preview_stream_id_ = -1;
156 
157   HdrMode hdr_mode_ = HdrMode::kHdrplusMode;
158 };
159 
160 }  // namespace google_camera_hal
161 }  // namespace android
162 
163 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_HDRPLUS_CAPTURE_SESSION_H_
164