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_HDRPLUS_REQUEST_PROCESSOR_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_HDRPLUS_REQUEST_PROCESSOR_H_
19 
20 #include "process_block.h"
21 #include "request_processor.h"
22 
23 namespace android {
24 namespace google_camera_hal {
25 
26 // HdrplusRequestProcessor implements a RequestProcessor that adds
27 // internal raw stream as input stream to request and forwards the request to
28 // its ProcessBlock.
29 class HdrplusRequestProcessor : public RequestProcessor {
30  public:
31   // device_session_hwl is owned by the caller and must be valid during the
32   // lifetime of this HdrplusRequestProcessor.
33   static std::unique_ptr<HdrplusRequestProcessor> Create(
34       CameraDeviceSessionHwl* device_session_hwl, int32_t raw_stream_id,
35       uint32_t physical_camera_id);
36 
37   virtual ~HdrplusRequestProcessor() = default;
38 
39   // Override functions of RequestProcessor start.
40   status_t ConfigureStreams(
41       InternalStreamManager* internal_stream_manager,
42       const StreamConfiguration& stream_config,
43       StreamConfiguration* process_block_stream_config) override;
44 
45   status_t SetProcessBlock(std::unique_ptr<ProcessBlock> process_block) override;
46 
47   // Adds internal raw stream as input stream to request and forwards the
48   // request to its ProcessBlock.
49   status_t ProcessRequest(const CaptureRequest& request) override;
50 
51   status_t Flush() override;
52   // Override functions of RequestProcessor end.
53 
54  protected:
HdrplusRequestProcessor(uint32_t physical_camera_id)55   HdrplusRequestProcessor(uint32_t physical_camera_id)
56       : kCameraId(physical_camera_id){};
57 
58  private:
59   // Physical camera ID of request processor.
60   const uint32_t kCameraId;
61 
62   status_t Initialize(CameraDeviceSessionHwl* device_session_hwl,
63                       int32_t raw_stream_id);
64   bool IsReadyForNextRequest();
65   // For CTS (android.hardware.camera2.cts.StillCaptureTest#testJpegExif)
66   // Remove JPEG metadata (THUMBNAIL_SIZE, ORIENTATION...) from internal raw
67   // buffer in order to get these metadata from HDR+ capture request directly
68   void RemoveJpegMetadata(
69       std::vector<std::unique_ptr<HalCameraMetadata>>* metadata);
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_;
76   int32_t raw_stream_id_ = -1;
77   uint32_t active_array_width_ = 0;
78   uint32_t active_array_height_ = 0;
79   // The number of HDR+ input buffers
80   uint32_t payload_frames_ = 0;
81 };
82 
83 }  // namespace google_camera_hal
84 }  // namespace android
85 
86 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_HDRPLUS_REQUEST_PROCESSOR_H_
87