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_RGBIRD_DEPTH_RESULT_PROCESSOR_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_RGBIRD_DEPTH_RESULT_PROCESSOR_H_
19 
20 #include "internal_stream_manager.h"
21 #include "result_processor.h"
22 
23 namespace android {
24 namespace google_camera_hal {
25 
26 // RgbirdDepthResultProcessor implements a ResultProcessor that returns depth
27 // stream to the framework, and the internal NIR raw streams(and optionally
28 // internal YUV stream) to the capture session internal stream manager.
29 // It is assumed that the result metadata and shutter has been reported to the
30 // framework by the request_result_processor before depth process block. So
31 // RgbirdDepthResultProcessor is not responsible for metadata or shutter
32 // notification. It only needs to return/recycle buffers unless there is an
33 // error returned from the depth process block.
34 class RgbirdDepthResultProcessor : public ResultProcessor {
35  public:
36   static std::unique_ptr<RgbirdDepthResultProcessor> Create(
37       InternalStreamManager* internal_stream_manager);
38 
39   virtual ~RgbirdDepthResultProcessor() = default;
40 
41   // Override functions of ResultProcessor start.
42   void SetResultCallback(
43       ProcessCaptureResultFunc process_capture_result, NotifyFunc notify,
44       ProcessBatchCaptureResultFunc process_batch_capture_result) override;
45 
46   status_t AddPendingRequests(
47       const std::vector<ProcessBlockRequest>& process_block_requests,
48       const CaptureRequest& remaining_session_request) override;
49 
50   void ProcessResult(ProcessBlockResult block_result) override;
51 
52   void Notify(const ProcessBlockNotifyMessage& block_message) override;
53 
54   status_t FlushPendingRequests() override;
55   // Override functions of ResultProcessor end.
56 
57  protected:
58   RgbirdDepthResultProcessor(InternalStreamManager* internal_stream_manager);
59 
60  private:
61   static constexpr int32_t kInvalidStreamId = -1;
62   InternalStreamManager* internal_stream_manager_ = nullptr;
63 
64   std::mutex callback_lock_;
65 
66   // The following callbacks must be protected by callback_lock_.
67   ProcessCaptureResultFunc process_capture_result_;
68   NotifyFunc notify_;
69 };
70 
71 }  // namespace google_camera_hal
72 }  // namespace android
73 
74 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_RGBIRD_DEPTH_RESULT_PROCESSOR_H_