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 "internal_stream_manager.h"
21 #include "result_processor.h"
22 
23 namespace android {
24 namespace google_camera_hal {
25 
26 // RealtimeZslResultProcessor implements a ResultProcessor that return filled
27 // raw buffer and matedata to internal stream manager and forwards the results
28 // without raw buffer to its callback functions.
29 class RealtimeZslResultProcessor : public ResultProcessor {
30  public:
31   static std::unique_ptr<RealtimeZslResultProcessor> Create(
32       InternalStreamManager* internal_stream_manager, int32_t raw_stream_id);
33 
34   virtual ~RealtimeZslResultProcessor() = default;
35 
36   // Override functions of ResultProcessor start.
37   void SetResultCallback(ProcessCaptureResultFunc process_capture_result,
38                          NotifyFunc notify) override;
39 
40   status_t AddPendingRequests(
41       const std::vector<ProcessBlockRequest>& process_block_requests,
42       const CaptureRequest& remaining_session_request) override;
43 
44   // Return filled raw buffer and matedata to internal stream manager
45   // and forwards the results without raw buffer to its callback functions.
46   void ProcessResult(ProcessBlockResult block_result) override;
47 
48   void Notify(const ProcessBlockNotifyMessage& block_message) override;
49 
50   status_t FlushPendingRequests() override;
51   // Override functions of ResultProcessor end.
52 
53  protected:
54   RealtimeZslResultProcessor(InternalStreamManager* internal_stream_manager,
55                              int32_t raw_stream_id);
56 
57  private:
58   // Save face detect mode for HDR+
59   void SaveFdForHdrplus(const CaptureRequest& request);
60   // Handle face detect metadata from result for HDR+
61   status_t HandleFdResultForHdrplus(uint32_t frameNumber,
62                                     HalCameraMetadata* metadata);
63   // Save lens shading map mode for HDR+
64   void SaveLsForHdrplus(const CaptureRequest& request);
65   // Handle Lens shading metadata from result for HDR+
66   status_t HandleLsResultForHdrplus(uint32_t frameNumber,
67                                     HalCameraMetadata* metadata);
68   std::mutex callback_lock_;
69 
70   // The following callbacks must be protected by callback_lock_.
71   ProcessCaptureResultFunc process_capture_result_;
72   NotifyFunc notify_;
73 
74   InternalStreamManager* internal_stream_manager_;
75   int32_t raw_stream_id_ = -1;
76 
77   // Current face detect mode set by framework.
78   uint8_t current_face_detect_mode_ = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;
79 
80   std::mutex face_detect_lock_;
81   // Map from frame number to face detect mode requested for that frame by
82   // framework. And requested_face_detect_modes_ is protected by
83   // face_detect_lock_
84   std::unordered_map<uint32_t, uint8_t> requested_face_detect_modes_;
85 
86   // Current lens shading map mode set by framework.
87   uint8_t current_lens_shading_map_mode_ =
88       ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF;
89 
90   std::mutex lens_shading_lock_;
91   // Map from frame number to lens shading map mode requested for that frame
92   // by framework. And requested_lens_shading_map_modes_ is protected by
93   // lens_shading_lock_
94   std::unordered_map<uint32_t, uint8_t> requested_lens_shading_map_modes_;
95 };
96 
97 }  // namespace google_camera_hal
98 }  // namespace android
99 
100 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_PROCESSOR_H_
101