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
63 return OK;
64 }
65
SetProcessBlock(std::unique_ptr<ProcessBlock> process_block)66 status_t BasicRequestProcessor::SetProcessBlock(
67 std::unique_ptr<ProcessBlock> process_block) {
68 ATRACE_CALL();
69 if (process_block == nullptr) {
70 ALOGE("%s: process_block is nullptr", __FUNCTION__);
71 return BAD_VALUE;
72 }
73
74 std::lock_guard lock(process_block_shared_lock_);
75 if (process_block_ != nullptr) {
76 ALOGE("%s: Already configured.", __FUNCTION__);
77 return ALREADY_EXISTS;
78 }
79
80 process_block_ = std::move(process_block);
81 return OK;
82 }
83
ProcessRequest(const CaptureRequest & request)84 status_t BasicRequestProcessor::ProcessRequest(const CaptureRequest& request) {
85 ATRACE_CALL();
86 std::shared_lock lock(process_block_shared_lock_);
87 if (process_block_ == nullptr) {
88 ALOGE("%s: Not configured yet.", __FUNCTION__);
89 return NO_INIT;
90 }
91
92 CaptureRequest block_request;
93 block_request.frame_number = request.frame_number;
94 block_request.settings = HalCameraMetadata::Clone(request.settings.get());
95 block_request.input_buffers = request.input_buffers;
96
97 for (auto& metadata : request.input_buffer_metadata) {
98 block_request.input_buffer_metadata.push_back(
99 HalCameraMetadata::Clone(metadata.get()));
100 }
101
102 block_request.output_buffers = request.output_buffers;
103 for (auto& [camera_id, physical_metadata] : request.physical_camera_settings) {
104 block_request.physical_camera_settings[camera_id] =
105 HalCameraMetadata::Clone(physical_metadata.get());
106 }
107
108 std::vector<ProcessBlockRequest> block_requests(1);
109 block_requests[0].request = std::move(block_request);
110
111 return process_block_->ProcessRequests(block_requests, request);
112 }
113
Flush()114 status_t BasicRequestProcessor::Flush() {
115 ATRACE_CALL();
116 std::shared_lock lock(process_block_shared_lock_);
117 if (process_block_ == nullptr) {
118 return OK;
119 }
120
121 return process_block_->Flush();
122 }
123
124 } // namespace google_camera_hal
125 } // namespace android
126