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_PROCESS_BLOCK_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_PROCESS_BLOCK_H_ 19 20 #include <shared_mutex> 21 22 #include "process_block.h" 23 24 namespace android { 25 namespace google_camera_hal { 26 27 // RealtimeProcessBlock implements a real-time ProcessBlock. 28 // It can process real-time capture requests for a single physical camera. 29 class RealtimeProcessBlock : public ProcessBlock { 30 public: 31 // Create a RealtimeProcessBlock. 32 // device_session_hwl is owned by the caller and must be valid during the 33 // lifetime of this RealtimeProcessBlock. 34 static std::unique_ptr<RealtimeProcessBlock> Create( 35 CameraDeviceSessionHwl* device_session_hwl); 36 37 virtual ~RealtimeProcessBlock() = default; 38 39 // Override functions of ProcessBlock start. 40 // All output streams must be physical streams. RealtimeProcessBlock does not 41 // support logical output streams. 42 status_t ConfigureStreams(const StreamConfiguration& stream_config, 43 const StreamConfiguration& overall_config) override; 44 45 status_t SetResultProcessor( 46 std::unique_ptr<ResultProcessor> result_processor) override; 47 48 status_t GetConfiguredHalStreams( 49 std::vector<HalStream>* hal_streams) const override; 50 51 status_t ProcessRequests( 52 const std::vector<ProcessBlockRequest>& process_block_requests, 53 const CaptureRequest& remaining_session_request) override; 54 55 status_t Flush() override; 56 // Override functions of ProcessBlock end. 57 58 protected: 59 RealtimeProcessBlock(CameraDeviceSessionHwl* device_session_hwl); 60 61 private: 62 // Camera ID of this process block. 63 const uint32_t kCameraId; 64 65 // If the real-time process block supports the device session. 66 static bool IsSupported(CameraDeviceSessionHwl* device_session_hwl); 67 68 // Invoked when the HWL pipeline sends a result. 69 void NotifyHwlPipelineResult(std::unique_ptr<HwlPipelineResult> hwl_result); 70 71 // Invoked when the HWL pipeline sends a message. 72 void NotifyHwlPipelineMessage(uint32_t pipeline_id, 73 const NotifyMessage& message); 74 75 HwlPipelineCallback hwl_pipeline_callback_; 76 CameraDeviceSessionHwl* device_session_hwl_ = nullptr; 77 78 mutable std::shared_mutex configure_shared_mutex_; 79 80 // If streams are configured. Must be protected by configure_shared_mutex_. 81 bool is_configured_ = false; 82 83 // HWL pipeline ID. Must be protected by configure_shared_mutex_. 84 uint32_t pipeline_id_ = 0; 85 86 std::mutex result_processor_lock_; 87 88 // Result processor. Must be protected by result_processor_lock_. 89 std::unique_ptr<ResultProcessor> result_processor_ = nullptr; 90 }; 91 92 } // namespace google_camera_hal 93 } // namespace android 94 95 #endif // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_REALTIME_PROCESS_BLOCK_H_ 96