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_BASIC_REQUEST_PROCESSOR_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_BASIC_REQUEST_PROCESSOR_H_
19 
20 #include <shared_mutex>
21 #include <vector>
22 
23 #include "process_block.h"
24 #include "request_processor.h"
25 
26 namespace android {
27 namespace google_camera_hal {
28 
29 // BasicRequestProcessor implements a basic RequestProcessor that simply
30 // forwards the request to its ProcessBlock without any modification.
31 class BasicRequestProcessor : public RequestProcessor {
32  public:
33   // device_session_hwl is owned by the caller and must be valid during the
34   // lifetime of this BasicRequestProcessor.
35   static std::unique_ptr<BasicRequestProcessor> Create(
36       CameraDeviceSessionHwl* device_session_hwl);
37 
38   virtual ~BasicRequestProcessor() = default;
39 
40   // Override functions of RequestProcessor start.
41   // BasicRequestProcessor will configure all streams in stream_config.
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   status_t ProcessRequest(const CaptureRequest& request) override;
50 
51   status_t Flush() override;
52 
53   void RepeatingRequestEnd(int32_t frame_number,
54                            const std::vector<int32_t>& stream_ids) override;
55   // Override functions of RequestProcessor end.
56 
57  protected:
58   BasicRequestProcessor() = default;
59 
60  private:
61   std::shared_mutex process_block_shared_lock_;
62 
63   // Protected by process_block_shared_lock_.
64   std::unique_ptr<ProcessBlock> process_block_;
65 };
66 
67 }  // namespace google_camera_hal
68 }  // namespace android
69 
70 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_BASIC_REQUEST_PROCESSOR_H_
71