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( 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 raw buffer and metadata to internal stream manager 48 // and forwards the results without raw 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, 59 android_pixel_format_t pixel_format, 60 uint32_t partial_result_count); 61 62 InternalStreamManager* internal_stream_manager_; 63 int32_t stream_id_ = -1; 64 // Partial result count reported by HAL 65 uint32_t partial_result_count_; 66 67 std::mutex callback_lock_; 68 69 // The following callbacks must be protected by callback_lock_. 70 ProcessCaptureResultFunc process_capture_result_; 71 NotifyFunc notify_; 72 73 private: 74 // Save face detect mode for HDR+ 75 void SaveFdForHdrplus(const CaptureRequest& request); 76 // Handle face detect metadata from result for HDR+ 77 status_t HandleFdResultForHdrplus(uint32_t frameNumber, 78 HalCameraMetadata* metadata); 79 // Save lens shading map mode for HDR+ 80 void SaveLsForHdrplus(const CaptureRequest& request); 81 // Handle Lens shading metadata from result for HDR+ 82 status_t HandleLsResultForHdrplus(uint32_t frameNumber, 83 HalCameraMetadata* metadata); 84 85 android_pixel_format_t pixel_format_; 86 87 // Current face detect mode set by framework. 88 uint8_t current_face_detect_mode_ = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; 89 90 std::mutex face_detect_lock_; 91 // Map from frame number to face detect mode requested for that frame by 92 // framework. And requested_face_detect_modes_ is protected by 93 // face_detect_lock_ 94 std::unordered_map<uint32_t, uint8_t> requested_face_detect_modes_; 95 96 // Current lens shading map mode set by framework. 97 uint8_t current_lens_shading_map_mode_ = 98 ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF; 99 100 std::mutex lens_shading_lock_; 101 // Map from frame number to lens shading map mode requested for that frame 102 // by framework. And requested_lens_shading_map_modes_ is protected by 103 // lens_shading_lock_ 104 std::unordered_map<uint32_t, uint8_t> requested_lens_shading_map_modes_; 105 106 std::shared_mutex process_block_shared_lock_; 107 }; 108 109 } // namespace google_camera_hal 110 } // namespace android 111 112 #endif // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_ZSL_RESULT_REQUEST_PROCESSOR_H_ 113