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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "GCH_BasicRequestProcessor"
19 #define ATRACE_TAG ATRACE_TAG_CAMERA
20 #include <log/log.h>
21 #include <utils/Trace.h>
22
23 #include "basic_request_processor.h"
24
25 namespace android {
26 namespace google_camera_hal {
27
Create(CameraDeviceSessionHwl * device_session_hwl)28 std::unique_ptr<BasicRequestProcessor> BasicRequestProcessor::Create(
29 CameraDeviceSessionHwl* device_session_hwl) {
30 ATRACE_CALL();
31 if (device_session_hwl == nullptr) {
32 ALOGE("%s: device_session_hwl is nullptr", __FUNCTION__);
33 return nullptr;
34 }
35
36 auto request_processor =
37 std::unique_ptr<BasicRequestProcessor>(new BasicRequestProcessor());
38 if (request_processor == nullptr) {
39 ALOGE("%s: Creating BasicRequestProcessor failed.", __FUNCTION__);
40 return nullptr;
41 }
42
43 return request_processor;
44 }
45
ConfigureStreams(InternalStreamManager *,const StreamConfiguration & stream_config,StreamConfiguration * process_block_stream_config)46 status_t BasicRequestProcessor::ConfigureStreams(
47 InternalStreamManager* /*internal_stream_manager*/,
48 const StreamConfiguration& stream_config,
49 StreamConfiguration* process_block_stream_config) {
50 ATRACE_CALL();
51 if (process_block_stream_config == nullptr) {
52 ALOGE("%s: process_block_stream_config is nullptr", __FUNCTION__);
53 return BAD_VALUE;
54 }
55
56 process_block_stream_config->streams = stream_config.streams;
57 process_block_stream_config->operation_mode = stream_config.operation_mode;
58 process_block_stream_config->session_params =
59 HalCameraMetadata::Clone(stream_config.session_params.get());
60 process_block_stream_config->stream_config_counter =
61 stream_config.stream_config_counter;
62 process_block_stream_config->multi_resolution_input_image =
63 stream_config.multi_resolution_input_image;
64
65 return OK;
66 }
67
SetProcessBlock(std::unique_ptr<ProcessBlock> process_block)68 status_t BasicRequestProcessor::SetProcessBlock(
69 std::unique_ptr<ProcessBlock> process_block) {
70 ATRACE_CALL();
71 if (process_block == nullptr) {
72 ALOGE("%s: process_block is nullptr", __FUNCTION__);
73 return BAD_VALUE;
74 }
75
76 std::lock_guard lock(process_block_shared_lock_);
77 if (process_block_ != nullptr) {
78 ALOGE("%s: Already configured.", __FUNCTION__);
79 return ALREADY_EXISTS;
80 }
81
82 process_block_ = std::move(process_block);
83 return OK;
84 }
85
ProcessRequest(const CaptureRequest & request)86 status_t BasicRequestProcessor::ProcessRequest(const CaptureRequest& request) {
87 ATRACE_CALL();
88 std::shared_lock lock(process_block_shared_lock_);
89 if (process_block_ == nullptr) {
90 ALOGE("%s: Not configured yet.", __FUNCTION__);
91 return NO_INIT;
92 }
93
94 CaptureRequest block_request;
95 block_request.frame_number = request.frame_number;
96 block_request.settings = HalCameraMetadata::Clone(request.settings.get());
97 block_request.input_buffers = request.input_buffers;
98 block_request.input_width = request.input_width;
99 block_request.input_height = request.input_height;
100
101 for (auto& metadata : request.input_buffer_metadata) {
102 block_request.input_buffer_metadata.push_back(
103 HalCameraMetadata::Clone(metadata.get()));
104 }
105
106 block_request.output_buffers = request.output_buffers;
107 for (auto& [camera_id, physical_metadata] : request.physical_camera_settings) {
108 block_request.physical_camera_settings[camera_id] =
109 HalCameraMetadata::Clone(physical_metadata.get());
110 }
111
112 std::vector<ProcessBlockRequest> block_requests(1);
113 block_requests[0].request = std::move(block_request);
114
115 return process_block_->ProcessRequests(block_requests, request);
116 }
117
Flush()118 status_t BasicRequestProcessor::Flush() {
119 ATRACE_CALL();
120 std::shared_lock lock(process_block_shared_lock_);
121 if (process_block_ == nullptr) {
122 return OK;
123 }
124
125 return process_block_->Flush();
126 }
127
128 } // namespace google_camera_hal
129 } // namespace android
130