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_REALTIME_ZSL_RESULT_PROCESSOR_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_PROCESSOR_H_
19 
20 #include <shared_mutex>
21 
22 #include "internal_stream_manager.h"
23 #include "result_processor.h"
24 
25 namespace android {
26 namespace google_camera_hal {
27 
28 // RealtimeZslResultProcessor implements a ResultProcessor that return
29 // filled buffer and metadata to internal stream manager.
30 class RealtimeZslResultProcessor : public ResultProcessor {
31  public:
32   static std::unique_ptr<RealtimeZslResultProcessor> Create(
33       InternalStreamManager* internal_stream_manager, int32_t stream_id,
34       android_pixel_format_t pixel_format, uint32_t partial_result_count = 1);
35 
36   virtual ~RealtimeZslResultProcessor() = default;
37 
38   // Override functions of ResultProcessor start.
39   void SetResultCallback(
40       ProcessCaptureResultFunc process_capture_result, NotifyFunc notify,
41       ProcessBatchCaptureResultFunc process_batch_capture_result) override;
42 
43   status_t AddPendingRequests(
44       const std::vector<ProcessBlockRequest>& process_block_requests,
45       const CaptureRequest& remaining_session_request) override;
46 
47   // Return filled buffer and metadata to internal stream manager
48   // and forwards the results without buffer to its callback functions.
49   void ProcessResult(ProcessBlockResult block_result) override;
50 
51   void Notify(const ProcessBlockNotifyMessage& block_message) override;
52 
53   status_t FlushPendingRequests() override;
54   // Override functions of ResultProcessor end.
55 
56  protected:
57   RealtimeZslResultProcessor(InternalStreamManager* internal_stream_manager,
58                              int32_t stream_id, uint32_t partial_result_count);
59 
60   InternalStreamManager* internal_stream_manager_;
61   int32_t stream_id_ = -1;
62   // Partial result count reported by HAL
63   uint32_t partial_result_count_;
64 
65   std::mutex callback_lock_;
66 
67   // The following callbacks must be protected by callback_lock_.
68   ProcessCaptureResultFunc process_capture_result_;
69   NotifyFunc notify_;
70 
71  private:
72   std::shared_mutex process_block_shared_lock_;
73 };
74 
75 }  // namespace google_camera_hal
76 }  // namespace android
77 
78 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_REQUEST_PROCESSOR_H_
79