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