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 raw 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(ProcessCaptureResultFunc process_capture_result, 40 NotifyFunc notify) override; 41 42 status_t AddPendingRequests( 43 const std::vector<ProcessBlockRequest>& process_block_requests, 44 const CaptureRequest& remaining_session_request) override; 45 46 // Return filled raw buffer and metadata to internal stream manager 47 // and forwards the results without raw buffer to its callback functions. 48 void ProcessResult(ProcessBlockResult block_result) override; 49 50 void Notify(const ProcessBlockNotifyMessage& block_message) override; 51 52 status_t FlushPendingRequests() override; 53 // Override functions of ResultProcessor end. 54 55 protected: 56 RealtimeZslResultProcessor(InternalStreamManager* internal_stream_manager, 57 int32_t stream_id, 58 android_pixel_format_t pixel_format, 59 uint32_t partial_result_count); 60 61 InternalStreamManager* internal_stream_manager_; 62 int32_t stream_id_ = -1; 63 // Partial result count reported by HAL 64 uint32_t partial_result_count_; 65 66 std::mutex callback_lock_; 67 68 // The following callbacks must be protected by callback_lock_. 69 ProcessCaptureResultFunc process_capture_result_; 70 NotifyFunc notify_; 71 72 private: 73 // Save face detect mode for HDR+ 74 void SaveFdForHdrplus(const CaptureRequest& request); 75 // Handle face detect metadata from result for HDR+ 76 status_t HandleFdResultForHdrplus(uint32_t frameNumber, 77 HalCameraMetadata* metadata); 78 // Save lens shading map mode for HDR+ 79 void SaveLsForHdrplus(const CaptureRequest& request); 80 // Handle Lens shading metadata from result for HDR+ 81 status_t HandleLsResultForHdrplus(uint32_t frameNumber, 82 HalCameraMetadata* metadata); 83 84 android_pixel_format_t pixel_format_; 85 86 // Current face detect mode set by framework. 87 uint8_t current_face_detect_mode_ = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; 88 89 std::mutex face_detect_lock_; 90 // Map from frame number to face detect mode requested for that frame by 91 // framework. And requested_face_detect_modes_ is protected by 92 // face_detect_lock_ 93 std::unordered_map<uint32_t, uint8_t> requested_face_detect_modes_; 94 95 // Current lens shading map mode set by framework. 96 uint8_t current_lens_shading_map_mode_ = 97 ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF; 98 99 std::mutex lens_shading_lock_; 100 // Map from frame number to lens shading map mode requested for that frame 101 // by framework. And requested_lens_shading_map_modes_ is protected by 102 // lens_shading_lock_ 103 std::unordered_map<uint32_t, uint8_t> requested_lens_shading_map_modes_; 104 105 std::shared_mutex process_block_shared_lock_; 106 }; 107 108 } // namespace google_camera_hal 109 } // namespace android 110 111 #endif // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_REQUEST_PROCESSOR_H_ 112