• 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 "camera_buffer_allocator_hwl.h"
21 #include "camera_device_session_hwl.h"
22 #include "capture_session.h"
23 #include "hal_types.h"
24 #include "hwl_types.h"
25 #include "request_processor.h"
26 #include "result_dispatcher.h"
27 #include "result_processor.h"
28 
29 namespace android {
30 namespace google_camera_hal {
31 
32 // BasicCaptureSession implements a CaptureSession that contains a single
33 // process chain that consists of
34 //
35 //   BasicRequestProcessor -> RealtimeProcessBlock -> BasicResultProcessor
36 //
37 // It only supports a single physical camera device session.
38 class BasicCaptureSession : public CaptureSession {
39  public:
40   // Return if the device session HWL and stream configuration are supported.
41   static bool IsStreamConfigurationSupported(
42       CameraDeviceSessionHwl* device_session_hwl,
43       const StreamConfiguration& stream_config);
44 
45   // Create a BasicCaptureSession.
46   //
47   // device_session_hwl is owned by the caller and must be valid during the
48   // lifetime of BasicCaptureSession.
49   // stream_config is the stream configuration.
50   // process_capture_result is the callback function to notify results.
51   // process_batch_capture_result is the callback function to notify batched
52   // results.
53   // notify is the callback function to notify messages.
54   // hal_configured_streams will be filled with HAL configured streams.
55   // camera_allocator_hwl is owned by the caller and must be valid during the
56   // lifetime of BasicCaptureSession
57   static std::unique_ptr<CaptureSession> Create(
58       CameraDeviceSessionHwl* device_session_hwl,
59       const StreamConfiguration& stream_config,
60       ProcessCaptureResultFunc process_capture_result,
61       ProcessBatchCaptureResultFunc process_batch_capture_result,
62       NotifyFunc notify, HwlSessionCallback session_callback,
63       std::vector<HalStream>* hal_configured_streams,
64       CameraBufferAllocatorHwl* camera_allocator_hwl = nullptr);
65 
66   virtual ~BasicCaptureSession();
67 
68   // Override functions in CaptureSession start.
69   status_t ProcessRequest(const CaptureRequest& request) override;
70 
71   status_t Flush() override;
72   // Override functions in CaptureSession end.
73 
74  protected:
75   BasicCaptureSession() = default;
76 
77  private:
78   status_t Initialize(CameraDeviceSessionHwl* device_session_hwl,
79                       const StreamConfiguration& stream_config,
80                       ProcessCaptureResultFunc process_capture_result,
81                       ProcessBatchCaptureResultFunc process_batch_capture_result,
82                       NotifyFunc notify,
83                       std::vector<HalStream>* hal_configured_streams);
84 
85   // Configure streams for request processor and process block.
86   status_t ConfigureStreams(const StreamConfiguration& stream_config,
87                             RequestProcessor* request_processor,
88                             ProcessBlock* process_block);
89 
90   // Build pipelines and return HAL configured streams.
91   status_t BuildPipelines(ProcessBlock* process_block,
92                           std::vector<HalStream>* hal_configured_streams);
93 
94   // Connect the process chain.
95   status_t ConnectProcessChain(RequestProcessor* request_processor,
96                                std::unique_ptr<ProcessBlock> process_block,
97                                std::unique_ptr<ResultProcessor> result_processor);
98 
99   void ProcessCaptureResult(std::unique_ptr<CaptureResult> result);
100   void Notify(const NotifyMessage& message);
101   void ProcessBatchCaptureResult(
102       std::vector<std::unique_ptr<CaptureResult>> results);
103 
104   std::unique_ptr<RequestProcessor> request_processor_;
105 
106   // device_session_hwl_ is owned by the client.
107   CameraDeviceSessionHwl* device_session_hwl_ = nullptr;
108   std::unique_ptr<InternalStreamManager> internal_stream_manager_;
109   std::unique_ptr<ResultDispatcher> result_dispatcher_;
110 };
111 
112 }  // namespace google_camera_hal
113 }  // namespace android
114 
115 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_BASIC_CAPTURE_SESSION_H_
116