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_REQUEST_PROCESSOR_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_SNAPSHOT_REQUEST_PROCESSOR_H_ 19 20 #include <vector> 21 22 #include "process_block.h" 23 #include "request_processor.h" 24 25 namespace android { 26 namespace google_camera_hal { 27 28 // SnapshotRequestProcessor implements a RequestProcessor that adds 29 // internal yuv stream as input stream to request and forwards the request to 30 // its ProcessBlock. 31 class SnapshotRequestProcessor : public RequestProcessor { 32 public: 33 // device_session_hwl is owned by the caller and must be valid during the 34 // lifetime of this SnapshotRequestProcessor. 35 static std::unique_ptr<SnapshotRequestProcessor> Create( 36 CameraDeviceSessionHwl* device_session_hwl, 37 HwlSessionCallback session_callback, int32_t yuv_stream_id); 38 39 virtual ~SnapshotRequestProcessor() = default; 40 41 // Override functions of RequestProcessor start. 42 status_t ConfigureStreams( 43 InternalStreamManager* internal_stream_manager, 44 const StreamConfiguration& stream_config, 45 StreamConfiguration* process_block_stream_config) override; 46 47 status_t SetProcessBlock(std::unique_ptr<ProcessBlock> process_block) override; 48 49 // Adds internal yuv stream as input stream to request and forwards the 50 // request to its ProcessBlock. 51 status_t ProcessRequest(const CaptureRequest& request) override; 52 53 status_t Flush() override; 54 // Override functions of RequestProcessor end. 55 56 void RepeatingRequestEnd(int32_t frame_number, 57 const std::vector<int32_t>& stream_ids) override; 58 59 protected: SnapshotRequestProcessor(HwlSessionCallback session_callback)60 explicit SnapshotRequestProcessor(HwlSessionCallback session_callback) 61 : session_callback_(session_callback) { 62 } 63 64 private: 65 status_t Initialize(CameraDeviceSessionHwl* device_session_hwl, 66 int32_t yuv_stream_id); 67 bool IsReadyForNextRequest(); 68 69 static constexpr int kZslBufferSize = 3; 70 std::mutex process_block_lock_; 71 72 // Protected by process_block_lock_. 73 std::unique_ptr<ProcessBlock> process_block_; 74 75 InternalStreamManager* internal_stream_manager_ = nullptr; 76 int32_t yuv_stream_id_ = -1; 77 uint32_t active_array_width_ = 0; 78 uint32_t active_array_height_ = 0; 79 80 HwlSessionCallback session_callback_; 81 }; 82 83 } // namespace google_camera_hal 84 } // namespace android 85 86 #endif // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_SNAPSHOT_REQUEST_PROCESSOR_H_ 87