• 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_BASIC_CAPTURE_SESSION_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_BASIC_CAPTURE_SESSION_H_
19 
20 #include <vector>
21 
22 #include "camera_buffer_allocator_hwl.h"
23 #include "camera_device_session_hwl.h"
24 #include "capture_session.h"
25 #include "hal_types.h"
26 #include "hwl_types.h"
27 #include "request_processor.h"
28 #include "result_dispatcher.h"
29 #include "result_processor.h"
30 
31 namespace android {
32 namespace google_camera_hal {
33 
34 // BasicCaptureSession implements a CaptureSession that contains a single
35 // process chain that consists of
36 //
37 //   BasicRequestProcessor -> RealtimeProcessBlock -> BasicResultProcessor
38 //
39 // It only supports a single physical camera device session.
40 class BasicCaptureSession : 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 BasicCaptureSession.
48   //
49   // device_session_hwl is owned by the caller and must be valid during the
50   // lifetime of BasicCaptureSession.
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 BasicCaptureSession
59   static std::unique_ptr<CaptureSession> 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, NotifyBatchFunc notify_batch,
65       HwlSessionCallback session_callback,
66       std::vector<HalStream>* hal_configured_streams,
67       CameraBufferAllocatorHwl* camera_allocator_hwl = nullptr);
68 
69   virtual ~BasicCaptureSession();
70 
71   // Override functions in CaptureSession start.
72   status_t ProcessRequest(const CaptureRequest& request) override;
73 
74   status_t Flush() override;
75   // Override functions in CaptureSession end.
76 
77   void RepeatingRequestEnd(int32_t frame_number,
78                            const std::vector<int32_t>& stream_ids) override;
79 
80  protected:
81   BasicCaptureSession() = default;
82 
83  private:
84   status_t Initialize(CameraDeviceSessionHwl* device_session_hwl,
85                       const StreamConfiguration& stream_config,
86                       ProcessCaptureResultFunc process_capture_result,
87                       ProcessBatchCaptureResultFunc process_batch_capture_result,
88                       NotifyFunc notify, NotifyBatchFunc notify_batch,
89                       std::vector<HalStream>* hal_configured_streams);
90 
91   // Configure streams for request processor and process block.
92   status_t ConfigureStreams(const StreamConfiguration& stream_config,
93                             RequestProcessor* request_processor,
94                             ProcessBlock* process_block);
95 
96   // Build pipelines and return HAL configured streams.
97   status_t BuildPipelines(ProcessBlock* process_block,
98                           std::vector<HalStream>* hal_configured_streams);
99 
100   // Connect the process chain.
101   status_t ConnectProcessChain(RequestProcessor* request_processor,
102                                std::unique_ptr<ProcessBlock> process_block,
103                                std::unique_ptr<ResultProcessor> result_processor);
104 
105   void ProcessCaptureResult(std::unique_ptr<CaptureResult> result);
106   void Notify(const NotifyMessage& message);
107   void ProcessBatchCaptureResult(
108       std::vector<std::unique_ptr<CaptureResult>> results);
109   void NotifyBatch(const std::vector<NotifyMessage>& messages);
110 
111   std::unique_ptr<RequestProcessor> request_processor_;
112 
113   // device_session_hwl_ is owned by the client.
114   CameraDeviceSessionHwl* device_session_hwl_ = nullptr;
115   std::unique_ptr<InternalStreamManager> internal_stream_manager_;
116   std::unique_ptr<ResultDispatcher> result_dispatcher_;
117 };
118 
119 }  // namespace google_camera_hal
120 }  // namespace android
121 
122 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_BASIC_CAPTURE_SESSION_H_
123