1 /*
2  * Copyright (C) 2021 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_SNAPSHOT_RESULT_PROCESSOR_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_SNAPSHOT_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 // SnapshotResultProcessor implements a ResultProcessor that return
27 // yuv buffer to internal stream manager and forwards the results without
28 // yuv buffer to its callback functions.
29 class SnapshotResultProcessor : public ResultProcessor {
30  public:
31   static std::unique_ptr<SnapshotResultProcessor> Create(
32       InternalStreamManager* internal_stream_manager, int32_t yuv_stream_id);
33 
34   virtual ~SnapshotResultProcessor() = default;
35 
36   // Override functions of ResultProcessor start.
37   void SetResultCallback(
38       ProcessCaptureResultFunc process_capture_result, NotifyFunc notify,
39       ProcessBatchCaptureResultFunc process_batch_capture_result) override;
40 
41   status_t AddPendingRequests(
42       const std::vector<ProcessBlockRequest>& process_block_requests,
43       const CaptureRequest& remaining_session_request) override;
44 
45   // Return yuv buffer to internal stream manager and forwards the results
46   // without yuv buffer to its callback functions.
47   void ProcessResult(ProcessBlockResult block_result) override;
48 
49   void Notify(const ProcessBlockNotifyMessage& block_message) override;
50 
51   status_t FlushPendingRequests() override;
52   // Override functions of ResultProcessor end.
53 
54  protected:
55   SnapshotResultProcessor(InternalStreamManager* internal_stream_manager,
56                           int32_t yuv_stream_id);
57 
58  private:
59   std::mutex callback_lock_;
60 
61   // The following callbacks must be protected by callback_lock_.
62   ProcessCaptureResultFunc process_capture_result_;
63   NotifyFunc notify_;
64 
65   InternalStreamManager* internal_stream_manager_ = nullptr;
66   int32_t yuv_stream_id_ = -1;
67 };
68 
69 }  // namespace google_camera_hal
70 }  // namespace android
71 
72 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_SNAPSHOT_RESULT_PROCESSOR_H_