blob: 939f969d8a321a8eeed7f8c6eae4e57cd113f813 [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Igor Murashkine7ee7632013-06-11 18:10:18 -07003 *
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_TAG "CameraDeviceClient"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
Jianing Weicb0652e2014-03-12 18:29:36 -070019//#define LOG_NDEBUG 0
Igor Murashkine7ee7632013-06-11 18:10:18 -070020
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070021#include <cutils/properties.h>
Jayant Chowdhary12361932018-08-27 14:46:13 -070022#include <utils/CameraThreadState.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070023#include <utils/Log.h>
Colin Crossb8a9dbb2020-08-27 04:12:26 +000024#include <utils/SessionConfigurationUtils.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070025#include <utils/Trace.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070026#include <gui/Surface.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070027#include <camera/camera2/CaptureRequest.h>
Ruben Brunk5698d442014-06-18 10:39:40 -070028#include <camera/CameraUtils.h>
Austin Borger1c1bee02023-06-01 16:51:35 -070029#include <camera/StringUtils.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070030
31#include "common/CameraDeviceBase.h"
Emilian Peev35ae8262018-11-08 13:11:32 +000032#include "device3/Camera3Device.h"
33#include "device3/Camera3OutputStream.h"
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070034#include "api2/CameraDeviceClient.h"
35
Emilian Peev00420d22018-02-05 21:33:13 +000036#include <camera_metadata_hidden.h>
37
Emilian Peev538c90e2018-12-17 18:03:19 +000038#include "DepthCompositeStream.h"
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080039#include "HeicCompositeStream.h"
Emilian Peev434248e2022-10-06 14:58:54 -070040#include "JpegRCompositeStream.h"
Emilian Peev538c90e2018-12-17 18:03:19 +000041
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080042// Convenience methods for constructing binder::Status objects for error returns
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070043
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080044#define STATUS_ERROR(errorCode, errorString) \
45 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070046 fmt::sprintf("%s:%d: %s", __FUNCTION__, __LINE__, errorString).c_str())
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080047
48#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
49 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070050 fmt::sprintf("%s:%d: " errorString, __FUNCTION__, __LINE__, \
51 __VA_ARGS__).c_str())
Igor Murashkine7ee7632013-06-11 18:10:18 -070052
53namespace android {
54using namespace camera2;
Austin Borgerea931242021-12-13 23:10:41 +000055using namespace camera3;
Emilian Peevf4816702020-04-03 15:44:51 -070056using camera3::camera_stream_rotation_t::CAMERA_STREAM_ROTATION_0;
Igor Murashkine7ee7632013-06-11 18:10:18 -070057
58CameraDeviceClientBase::CameraDeviceClientBase(
59 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080060 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger1c1bee02023-06-01 16:51:35 -070061 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080062 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070063 const std::optional<std::string>& clientFeatureId,
64 const std::string& cameraId,
Jing Mikec7f9b132023-03-12 11:12:04 +080065 [[maybe_unused]] int api1CameraId,
Igor Murashkine7ee7632013-06-11 18:10:18 -070066 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070067 int sensorOrientation,
Igor Murashkine7ee7632013-06-11 18:10:18 -070068 int clientPid,
69 uid_t clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070070 int servicePid,
71 bool overrideToPortrait) :
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080072 BasicClient(cameraService,
Marco Nelissenf8880202014-11-14 07:58:25 -080073 IInterface::asBinder(remoteCallback),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080074 clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080075 systemNativeClient,
Philip P. Moltmann9e648f62019-11-04 12:52:45 -080076 clientFeatureId,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080077 cameraId,
78 cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070079 sensorOrientation,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080080 clientPid,
81 clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070082 servicePid,
83 overrideToPortrait),
Igor Murashkine7ee7632013-06-11 18:10:18 -070084 mRemoteCallback(remoteCallback) {
85}
Igor Murashkine7ee7632013-06-11 18:10:18 -070086
87// Interface used by CameraService
88
89CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080090 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070091 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger1c1bee02023-06-01 16:51:35 -070092 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080093 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070094 const std::optional<std::string>& clientFeatureId,
95 const std::string& cameraId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080096 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070097 int sensorOrientation,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080098 int clientPid,
99 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700100 int servicePid,
Austin Borger18b30a72022-10-27 12:20:29 -0700101 bool overrideForPerfClass,
malikakash73125c62023-07-21 22:44:34 +0000102 bool overrideToPortrait,
103 const std::string& originalCameraId) :
Austin Borger74fca042022-05-23 12:41:21 -0700104 Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper, clientPackageName,
105 systemNativeClient, clientFeatureId, cameraId, /*API1 camera ID*/ -1, cameraFacing,
Austin Borger18b30a72022-10-27 12:20:29 -0700106 sensorOrientation, clientPid, clientUid, servicePid, overrideForPerfClass,
107 overrideToPortrait),
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700108 mInputStream(),
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700109 mStreamingRequestId(REQUEST_ID_NONE),
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700110 mRequestIdCounter(0),
malikakash73125c62023-07-21 22:44:34 +0000111 mOverrideForPerfClass(overrideForPerfClass),
112 mOriginalCameraId(originalCameraId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700113 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -0700114 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700115}
116
Emilian Peevbd8c5032018-02-14 23:05:40 +0000117status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -0700118 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000119 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800120}
121
122template<typename TProviderPtr>
Austin Borger1c1bee02023-06-01 16:51:35 -0700123status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
124 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700125 ATRACE_CALL();
126 status_t res;
127
Emilian Peevbd8c5032018-02-14 23:05:40 +0000128 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700129 if (res != OK) {
130 return res;
131 }
132
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700133 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger1c1bee02023-06-01 16:51:35 -0700134 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
135 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700136 if (res != OK) {
137 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
138 __FUNCTION__, strerror(-res), res);
139 return res;
140 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700141
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800142 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
143 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800144 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700145 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700146
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800147 const CameraMetadata &deviceInfo = mDevice->info();
148 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000149 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
150 if (physicalKeysEntry.count > 0) {
151 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
152 physicalKeysEntry.data.i32,
153 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
154 }
155
Emilian Peev2295df72021-11-12 18:14:10 -0800156 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
157 mDynamicProfileMap.emplace(
158 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
159 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
160 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800161 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800162 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800163 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800164 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800165 if (entry.count > 0 || ((entry.count % 3) != 0)) {
166 int64_t standardBitmap =
167 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
168 for (size_t i = 0; i < entry.count; i += 3) {
169 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800170 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800171 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
172 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800173 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800174 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800175 }
176 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800177 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
178 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800179 }
180 }
Emilian Peevef715e22022-05-19 17:44:33 -0700181 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
182 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800183 } else {
184 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
185 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
186 }
187 }
188 }
189
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700190 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800191 // Cache physical camera ids corresponding to this device and also the high
192 // resolution sensors in this device + physical camera ids
Austin Borger1c1bee02023-06-01 16:51:35 -0700193 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800194 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700195 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800196 }
197 for (auto &physicalId : mPhysicalCameraIds) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700198 if (supportsUltraHighResolutionCapture(physicalId)) {
199 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800200 }
201 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700202 return OK;
203}
204
205CameraDeviceClient::~CameraDeviceClient() {
206}
207
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800208binder::Status CameraDeviceClient::submitRequest(
209 const hardware::camera2::CaptureRequest& request,
210 bool streaming,
211 /*out*/
212 hardware::camera2::utils::SubmitInfo *submitInfo) {
213 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
214 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700215}
216
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800217binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000218 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000219 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800220 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
221
Emilian Peev2f5d6012022-01-19 16:16:50 -0800222 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800223 // Trying to submit request with surface that wasn't created
224 if (idx == NAME_NOT_FOUND) {
225 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
226 " we have not called createStream on",
Austin Borger1c1bee02023-06-01 16:51:35 -0700227 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800228 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
229 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000230 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
231 != NAME_NOT_FOUND) {
232 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
233 currentStreamId);
234 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800235 }
236
237 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
238 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800239 outputStreamIds->push_back(streamSurfaceId.streamId());
240 }
241 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
242
243 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700244 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800245 streamSurfaceId.surfaceId());
246
Emilian Peevf873aa52018-01-26 14:58:28 +0000247 if (currentStreamId != nullptr) {
248 *currentStreamId = streamSurfaceId.streamId();
249 }
250
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800251 return binder::Status::ok();
252}
253
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800254static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
255 const Vector<int> &streamIdsForThisRequest) {
256 std::list<int> intersection;
257 for (auto &streamId : streamIdsForThisRequest) {
258 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
259 intersection.emplace_back(streamId);
260 }
261 }
262 return intersection;
263}
264
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800265binder::Status CameraDeviceClient::submitRequestList(
266 const std::vector<hardware::camera2::CaptureRequest>& requests,
267 bool streaming,
268 /*out*/
269 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700270 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700271 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700272
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800273 binder::Status res = binder::Status::ok();
274 status_t err;
275 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
276 return res;
277 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700278
279 Mutex::Autolock icl(mBinderSerializationLock);
280
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800281 if (!mDevice.get()) {
282 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
283 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700284
285 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800286 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700287 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800288 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700289 }
290
Emilian Peevaebbe412018-01-15 13:53:24 +0000291 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700292 std::list<const SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800293 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700294 uint32_t loopCounter = 0;
295
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800296 for (auto&& request: requests) {
297 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700298 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800299 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700300 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800301 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800302 "No input configured for camera %s but request is for reprocessing",
Austin Borger1c1bee02023-06-01 16:51:35 -0700303 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700304 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800305 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700306 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800307 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
308 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000309 } else if (request.mPhysicalCameraSettings.size() > 1) {
310 ALOGE("%s: Camera %s: reprocess requests not supported for "
311 "multiple physical cameras.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700312 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000313 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
314 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700315 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700316 }
317
Emilian Peevaebbe412018-01-15 13:53:24 +0000318 if (request.mPhysicalCameraSettings.empty()) {
319 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700320 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800321 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000322 "Request doesn't contain any settings");
323 }
324
325 //The first capture settings should always match the logical camera id
Austin Borger1c1bee02023-06-01 16:51:35 -0700326 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
malikakash73125c62023-07-21 22:44:34 +0000327 if (mDevice->getId() != logicalId && mOriginalCameraId != logicalId) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000328 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700329 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000330 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
331 "Invalid camera request settings");
332 }
333
Emilian Peevaebbe412018-01-15 13:53:24 +0000334 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800335 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger1c1bee02023-06-01 16:51:35 -0700336 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800337 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
338 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700339 }
340
Jianing Wei90e59c92014-03-12 18:29:36 -0700341 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700342 * Write in the output stream IDs and map from stream ID to surface ID
343 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700344 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700345 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700346 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000347 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800348 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800349 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800350 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800351 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700352
Emilian Peevf873aa52018-01-26 14:58:28 +0000353 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800354 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000355 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800356 if (!res.isOk()) {
357 return res;
358 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000359
360 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
361 if (index >= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700362 const std::string &requestedPhysicalId =
363 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
364 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800365 dynamicProfileBitmap |=
366 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000367 } else {
368 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
369 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700370 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800371 } else {
372 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
373 int streamId = request.mStreamIdxList.itemAt(i);
374 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700375
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800376 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
377 if (index < 0) {
378 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
379 " we have not called createStream on: stream %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700380 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800381 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
382 "Request targets Surface that is not part of current capture session");
383 }
384
385 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
386 if ((size_t)surfaceIdx >= gbps.size()) {
387 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
388 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700389 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800390 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
391 "Request targets Surface has invalid surface index");
392 }
393
Emilian Peevf873aa52018-01-26 14:58:28 +0000394 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800395 if (!res.isOk()) {
396 return res;
397 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000398
Austin Borger1c1bee02023-06-01 16:51:35 -0700399 const std::string &requestedPhysicalId =
400 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
401 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800402 dynamicProfileBitmap |=
403 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
404 }
405 }
406
407 if (dynamicProfileBitmap !=
408 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
409 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
410 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
411 if ((dynamicProfileBitmap & i) == 0) {
412 continue;
413 }
414
415 const auto& it = mDynamicProfileMap.find(i);
416 if (it != mDynamicProfileMap.end()) {
417 if ((it->second == 0) ||
418 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
419 continue;
420 } else {
421 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
422 " reference an unsupported dynamic range profile combination"
Austin Borger1c1bee02023-06-01 16:51:35 -0700423 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800424 dynamicProfileBitmap);
425 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
426 "Request targets an unsupported dynamic range profile"
427 " combination");
428 }
429 } else {
430 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
431 " references unsupported dynamic range profile 0x%x!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700432 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800433 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
434 "Request targets 10-bit Surface with unsupported dynamic range"
435 " profile");
436 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700437 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700438 }
439
Emilian Peevf873aa52018-01-26 14:58:28 +0000440 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
441 for (const auto& it : request.mPhysicalCameraSettings) {
malikakash73125c62023-07-21 22:44:34 +0000442 const std::string resolvedId = (mOriginalCameraId == it.id) ? mDevice->getId() : it.id;
Emilian Peev00420d22018-02-05 21:33:13 +0000443 if (it.settings.isEmpty()) {
444 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700445 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000446 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
447 "Request settings are empty");
448 }
449
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800450 // Check whether the physical / logical stream has settings
451 // consistent with the sensor pixel mode(s) it was configured with.
452 // mCameraIdToStreamSet will only have ids that are high resolution
malikakash73125c62023-07-21 22:44:34 +0000453 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(resolvedId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800454 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
455 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
456 outputStreamIds);
457 if (!request.mIsReprocess &&
458 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
459 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
460 "consistent with configured streams. Rejecting request.",
malikakash73125c62023-07-21 22:44:34 +0000461 __FUNCTION__, resolvedId.c_str());
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800462 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
463 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
464 "streams configured");
465 }
466 }
467
malikakash73125c62023-07-21 22:44:34 +0000468 const std::string &physicalId = resolvedId;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700469 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
470 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
471 mSupportedPhysicalRequestKeys.end();
472 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
473 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
474 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000475 if (physicalId != mDevice->getId()) {
476 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
malikakash73125c62023-07-21 22:44:34 +0000477 resolvedId);
Emilian Peevf873aa52018-01-26 14:58:28 +0000478 if (found == requestedPhysicalIds.end()) {
479 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700480 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000481 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
482 "Invalid physical camera id");
483 }
Emilian Peev00420d22018-02-05 21:33:13 +0000484
485 if (!mSupportedPhysicalRequestKeys.empty()) {
486 // Filter out any unsupported physical request keys.
487 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
488 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
489 filteredParams.getAndLock());
490 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
491 filteredParams.unlock(meta);
492
493 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
494 camera_metadata_ro_entry entry = it.settings.find(keyIt);
495 if (entry.count > 0) {
496 filteredParams.update(entry);
497 }
498 }
499
malikakash73125c62023-07-21 22:44:34 +0000500 physicalSettingsList.push_back({resolvedId, filteredParams,
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700501 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000502 }
503 } else {
malikakash73125c62023-07-21 22:44:34 +0000504 physicalSettingsList.push_back({resolvedId, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000505 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000506 }
507
508 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
509 // Callee logs
510 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
511 "Caller does not have permission to change restricted controls");
512 }
513
Emilian Peevaebbe412018-01-15 13:53:24 +0000514 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
515 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700516
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800517 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000518 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
519 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700520 }
521
Emilian Peevaebbe412018-01-15 13:53:24 +0000522 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
523 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700524 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800525 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700526 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800527 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700528
Emilian Peevaebbe412018-01-15 13:53:24 +0000529 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700530 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800531
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700532 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800533 if (!request.mUserTag.empty()) {
534 mUserTag = request.mUserTag;
535 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700536 camera_metadata_entry entry =
537 physicalSettingsList.begin()->metadata.find(
538 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
539 if (entry.count == 1) {
540 mVideoStabilizationMode = entry.data.u8[0];
541 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700542 }
543 mRequestIdCounter++;
544
545 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700546 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
547 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800548 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700549 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800550 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700551 mCameraIdStr.c_str(), strerror(-err), err);
552 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800553 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700554 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700555 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700556 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700557 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700558 }
559 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700560 err = mDevice->captureList(metadataRequestList, surfaceMapList,
561 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800562 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700563 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800564 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700565 mCameraIdStr.c_str(), strerror(-err), err);
566 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800567 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700568 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700569 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800570 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700571 }
572
Austin Borger1c1bee02023-06-01 16:51:35 -0700573 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700574 return res;
575}
576
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800577binder::Status CameraDeviceClient::cancelRequest(
578 int requestId,
579 /*out*/
580 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700581 ATRACE_CALL();
582 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
583
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800584 status_t err;
585 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700586
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800587 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700588
589 Mutex::Autolock icl(mBinderSerializationLock);
590
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800591 if (!mDevice.get()) {
592 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
593 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700594
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700595 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700596 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700597 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
598 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
599 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
600 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700601 }
602
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800603 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700604
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800605 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800606 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700607 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700608 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800609 } else {
610 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800611 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700612 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700613 }
614
615 return res;
616}
617
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800618binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700619 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700620 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700621 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800622 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700623}
624
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100625binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700626 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800627 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700628 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700629 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
630 __FUNCTION__, mInputStream.configured ? 1 : 0,
631 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700632
Zhijun He0effd522016-03-04 10:22:27 -0800633 binder::Status res;
634 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
635
Emilian Peevcc0b7952020-01-07 13:54:47 -0800636 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700637 std::string msg = "Invalid offline stream ids";
638 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
639 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800640 }
641
Zhijun He0effd522016-03-04 10:22:27 -0800642 Mutex::Autolock icl(mBinderSerializationLock);
643
644 if (!mDevice.get()) {
645 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
646 }
647
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700648 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000649 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000650 if (!res.isOk()) {
651 return res;
652 }
653
654 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
655 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700656 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
657 mCameraIdStr.c_str());
658 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
659 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000660 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700661 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
662 mCameraIdStr.c_str(), strerror(-err), err);
663 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
664 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000665 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800666 offlineStreamIds->clear();
667 mDevice->getOfflineStreamIds(offlineStreamIds);
668
Emilian Peev2f5d6012022-01-19 16:16:50 -0800669 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000670 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
671 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800672 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700673 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
674 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
675 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
676 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000677 break;
678 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800679
680 // Composite streams can only support offline mode in case all individual internal
681 // streams are also supported.
682 std::vector<int> internalStreams;
683 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800684 offlineStreamIds->erase(
685 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800686 [&internalStreams] (int streamId) {
687 auto it = std::find(internalStreams.begin(), internalStreams.end(),
688 streamId);
689 if (it != internalStreams.end()) {
690 internalStreams.erase(it);
691 return true;
692 }
693
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800694 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800695 if (internalStreams.empty()) {
696 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
697 }
698 }
699
700 for (const auto& offlineStreamId : *offlineStreamIds) {
701 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000702 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700703
704 nsecs_t configureEnd = systemTime();
705 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700706 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700707 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000708 }
709
710 return res;
711}
712
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800713binder::Status CameraDeviceClient::isSessionConfigurationSupported(
714 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800715
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800716 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800717 binder::Status res;
718 status_t ret = OK;
719 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
720
721 Mutex::Autolock icl(mBinderSerializationLock);
722
723 if (!mDevice.get()) {
724 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
725 }
726
727 auto operatingMode = sessionConfiguration.getOperatingMode();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700728 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000729 mCameraIdStr);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800730 if (!res.isOk()) {
731 return res;
732 }
733
734 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700735 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
736 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
737 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800738 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700739
Emilian Peev35ae8262018-11-08 13:11:32 +0000740 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700741 camera3::metadataGetter getMetadata = [this](const std::string &id,
742 bool /*overrideForPerfClass*/) {
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700743 return mDevice->infoPhysical(id);};
Austin Borger1c1bee02023-06-01 16:51:35 -0700744 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700745 sessionConfiguration, mOverrideForPerfClass, getMetadata, status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000746 switch (ret) {
747 case OK:
748 // Expected, do nothing.
749 break;
750 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700751 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000752 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700753 mCameraIdStr.c_str());
754 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
755 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000756 }
757
758 break;
759 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700760 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000761 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700762 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000763 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700764 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000765 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800766 }
767
768 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700769}
770
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800771binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700772 ATRACE_CALL();
773 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
774
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800775 binder::Status res;
776 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700777
778 Mutex::Autolock icl(mBinderSerializationLock);
779
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800780 if (!mDevice.get()) {
781 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
782 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700783
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700784 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700785 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700786 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000787 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700788
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700789 if (mInputStream.configured && mInputStream.id == streamId) {
790 isInput = true;
791 } else {
792 // Guard against trying to delete non-created streams
793 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700794 if (streamId == mStreamMap.valueAt(i).streamId()) {
795 surfaces.push_back(mStreamMap.keyAt(i));
796 }
797 }
798
799 // See if this stream is one of the deferred streams.
800 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
801 if (streamId == mDeferredStreams[i]) {
802 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700803 break;
804 }
805 }
806
Emilian Peev2f5d6012022-01-19 16:16:50 -0800807 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000808 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
809 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
810 compositeIndex = i;
811 break;
812 }
813 }
814
Shuzhen Wang0129d522016-10-30 22:43:41 -0700815 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700816 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
817 " stream created yet", mCameraIdStr.c_str(), streamId);
818 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
819 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700820 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700821 }
822
823 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800824 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700825
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800826 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700827 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
828 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
829 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
830 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800831 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700832 if (isInput) {
833 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700834 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700835 for (auto& surface : surfaces) {
836 mStreamMap.removeItem(surface);
837 }
838
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800839 mConfiguredOutputs.removeItem(streamId);
840
Shuzhen Wang0129d522016-10-30 22:43:41 -0700841 if (dIndex != NAME_NOT_FOUND) {
842 mDeferredStreams.removeItemsAt(dIndex);
843 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000844
845 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800846 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000847 status_t ret;
848 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
849 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700850 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
851 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
852 err, streamId);
853 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
854 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000855 }
856 mCompositeStreamMap.removeItemsAt(compositeIndex);
857 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800858 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
859 auto &streamSet = mapIt.second;
860 if (streamSet.find(streamId) != streamSet.end()) {
861 streamSet.erase(streamId);
862 break;
863 }
864 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700865 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700866 }
867
868 return res;
869}
870
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800871binder::Status CameraDeviceClient::createStream(
872 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
873 /*out*/
874 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700875 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700876
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800877 binder::Status res;
878 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700879
880 Mutex::Autolock icl(mBinderSerializationLock);
881
Shuzhen Wang0129d522016-10-30 22:43:41 -0700882 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
883 outputConfiguration.getGraphicBufferProducers();
884 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800885 bool deferredConsumer = outputConfiguration.isDeferred();
886 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700887 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800888 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800889 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800890 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800891 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800892 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800893 int mirrorMode = outputConfiguration.getMirrorMode();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700894 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000895 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700896
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700897 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Emilian Peev35ae8262018-11-08 13:11:32 +0000898 outputConfiguration.getSurfaceType());
899 if (!res.isOk()) {
900 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700901 }
Zhijun He5d677d12016-05-29 16:52:39 -0700902
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800903 if (!mDevice.get()) {
904 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
905 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700906 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800907 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000908 if (!res.isOk()) {
909 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800910 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000911
Shuzhen Wang0129d522016-10-30 22:43:41 -0700912 std::vector<sp<Surface>> surfaces;
913 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700914 status_t err;
915
916 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700917 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800918 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700919 }
920
Shuzhen Wang758c2152017-01-10 18:26:18 -0800921 OutputStreamInfo streamInfo;
922 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800923 const std::vector<int32_t> &sensorPixelModesUsed =
924 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700925 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700926 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700927 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800928 ssize_t index = mStreamMap.indexOfKey(binder);
929 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700930 std::string msg = std::string("Camera ") + mCameraIdStr
931 + ": Surface already has a stream created for it (ID "
932 + std::to_string(index) + ")";
933 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
934 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700935 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700936
Shuzhen Wang758c2152017-01-10 18:26:18 -0800937 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700938 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800939 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800940 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700941 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800942
943 if (!res.isOk())
944 return res;
945
946 if (!isStreamInfoValid) {
947 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700948 }
949
Shuzhen Wang758c2152017-01-10 18:26:18 -0800950 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang0129d522016-10-30 22:43:41 -0700951 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -0800952 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700953
954 // If mOverrideForPerfClass is true, do not fail createStream() for small
955 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
956 // closest possible supported size.
957
Zhijun He125684a2015-12-26 15:07:30 -0800958 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100959 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800960 bool isDepthCompositeStream =
961 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0]);
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800962 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(surfaces[0]);
Emilian Peev434248e2022-10-06 14:58:54 -0700963 bool isJpegRCompositeStream =
Emilian Peeve579d8b2023-02-28 14:16:08 -0800964 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0]) &&
Emilian Peev15230142023-04-27 20:22:54 +0000965 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800966 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800967 sp<CompositeStream> compositeStream;
968 if (isDepthCompositeStream) {
969 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800970 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800971 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -0700972 } else {
973 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800974 }
975
Emilian Peev538c90e2018-12-17 18:03:19 +0000976 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
977 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -0700978 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800979 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -0700980 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000981 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
982 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000983 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800984 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000985 mCompositeStreamMap.add(IInterface::asBinder(surfaces[0]->getIGraphicBufferProducer()),
986 compositeStream);
987 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800988 } else {
989 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
990 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -0700991 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800992 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -0800993 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -0800994 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000995 streamInfo.timestampBase, streamInfo.mirrorMode, streamInfo.colorSpace,
996 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000997 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700998
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800999 if (err != OK) {
1000 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001001 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001002 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001003 streamInfo.dataSpace, strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001004 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001005 int i = 0;
1006 for (auto& binder : binders) {
1007 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1008 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001009 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1010 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001011 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001012
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001013 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001014 mStreamInfoMap[streamId] = streamInfo;
1015
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001016 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001017 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001018 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001019 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001020
Zhijun He5d677d12016-05-29 16:52:39 -07001021 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001022 res = setStreamTransformLocked(streamId, streamInfo.mirrorMode);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001023
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001024 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001025 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001026 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001027 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001028 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001029 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001030 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001031 }
1032
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001033 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001034 }
1035
1036 return res;
1037}
1038
Zhijun He5d677d12016-05-29 16:52:39 -07001039binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1040 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001041 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001042 /*out*/
1043 int* newStreamId) {
1044 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001045 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001046 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001047 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001048 status_t err;
1049 binder::Status res;
1050
1051 if (!mDevice.get()) {
1052 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1053 }
1054
1055 // Infer the surface info for deferred surface stream creation.
1056 width = outputConfiguration.getWidth();
1057 height = outputConfiguration.getHeight();
1058 surfaceType = outputConfiguration.getSurfaceType();
1059 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1060 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001061 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001062 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1063 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1064 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1065 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1066 }
1067 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001068 std::vector<sp<Surface>> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001069 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001070 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1071 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001072 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1073 // Here, we override sensor pixel modes
1074 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1075 const std::vector<int32_t> &sensorPixelModesUsed =
1076 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001077 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001078 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001079 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001080 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1081 "sensor pixel modes used not valid for deferred stream");
1082 }
1083
Shuzhen Wang0129d522016-10-30 22:43:41 -07001084 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1085 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001086 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001087 &streamId, physicalCameraId,
1088 overriddenSensorPixelModesUsed,
1089 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001090 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001091 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001092 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001093 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001094 outputConfiguration.getMirrorMode(),
1095 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001096
1097 if (err != OK) {
1098 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001099 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001100 mCameraIdStr.c_str(), width, height, format, dataSpace, strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001101 } else {
1102 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1103 // a separate list to track. Once the deferred surface is set, this id will be
1104 // relocated to mStreamMap.
1105 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001106 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001107 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001108 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001109 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001110 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001111 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001112 outputConfiguration.getMirrorMode(),
1113 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001114
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001115 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001116 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001117 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001118
1119 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001120 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001121
1122 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001123 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001124 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001125 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001126 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001127 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001128 }
Zhijun He5d677d12016-05-29 16:52:39 -07001129 }
1130 return res;
1131}
1132
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001133binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001134 int32_t transform = 0;
1135 status_t err;
1136 binder::Status res;
1137
1138 if (!mDevice.get()) {
1139 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1140 }
1141
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001142 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001143 if (err != OK) {
1144 // Error logged by getRotationTransformLocked.
1145 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1146 "Unable to calculate rotation transform for new stream");
1147 }
1148
1149 err = mDevice->setStreamTransform(streamId, transform);
1150 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001151 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001152 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001153 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1154 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001155 }
1156
1157 return res;
1158}
Ruben Brunkbba75572014-11-20 17:29:50 -08001159
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001160binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001161 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001162 /*out*/
1163 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001164
1165 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001166 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1167 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001168
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001169 binder::Status res;
1170 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001171
1172 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001173
1174 if (!mDevice.get()) {
1175 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1176 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001177
1178 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001179 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1180 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1181 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1182 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001183 }
1184
1185 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001186 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001187 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001188 mInputStream.configured = true;
1189 mInputStream.width = width;
1190 mInputStream.height = height;
1191 mInputStream.format = format;
1192 mInputStream.id = streamId;
1193
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001194 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001195 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001196
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001197 *newStreamId = streamId;
1198 } else {
1199 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001200 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001201 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001202 }
1203
1204 return res;
1205}
1206
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001207binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001208
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001209 binder::Status res;
1210 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1211
1212 if (inputSurface == NULL) {
1213 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001214 }
1215
1216 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001217 if (!mDevice.get()) {
1218 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1219 }
1220 sp<IGraphicBufferProducer> producer;
1221 status_t err = mDevice->getInputBufferProducer(&producer);
1222 if (err != OK) {
1223 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001224 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001225 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001226 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001227 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001228 inputSurface->graphicBufferProducer = producer;
1229 }
1230 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001231}
1232
Emilian Peev40ead602017-09-26 15:46:36 +01001233binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1234 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1235 ATRACE_CALL();
1236
1237 binder::Status res;
1238 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1239
1240 Mutex::Autolock icl(mBinderSerializationLock);
1241
1242 if (!mDevice.get()) {
1243 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1244 }
1245
1246 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1247 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001248 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001249
Emilian Peev40ead602017-09-26 15:46:36 +01001250 auto producerCount = bufferProducers.size();
1251 if (producerCount == 0) {
1252 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1253 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1254 "bufferProducers must not be empty");
1255 }
1256
1257 // The first output is the one associated with the output configuration.
1258 // It should always be present, valid and the corresponding stream id should match.
1259 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1260 ssize_t index = mStreamMap.indexOfKey(binder);
1261 if (index == NAME_NOT_FOUND) {
1262 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1263 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1264 "OutputConfiguration is invalid");
1265 }
1266 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1267 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1268 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1269 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1270 "Stream id is invalid");
1271 }
1272
1273 std::vector<size_t> removedSurfaceIds;
1274 std::vector<sp<IBinder>> removedOutputs;
1275 std::vector<sp<Surface>> newOutputs;
1276 std::vector<OutputStreamInfo> streamInfos;
1277 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1278 for (auto &it : bufferProducers) {
1279 newOutputsMap.add(IInterface::asBinder(it), it);
1280 }
1281
1282 for (size_t i = 0; i < mStreamMap.size(); i++) {
1283 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1284 if (idx == NAME_NOT_FOUND) {
1285 if (mStreamMap[i].streamId() == streamId) {
1286 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1287 removedOutputs.push_back(mStreamMap.keyAt(i));
1288 }
1289 } else {
1290 if (mStreamMap[i].streamId() != streamId) {
1291 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1292 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1293 "Target Surface is invalid");
1294 }
1295 newOutputsMap.removeItemsAt(idx);
1296 }
1297 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001298 const std::vector<int32_t> &sensorPixelModesUsed =
1299 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001300 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001301 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001302 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001303 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001304 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001305
Emilian Peev40ead602017-09-26 15:46:36 +01001306 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1307 OutputStreamInfo outInfo;
1308 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001309 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001310 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001311 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001312 streamUseCase, timestampBase, mirrorMode, colorSpace);
Emilian Peev40ead602017-09-26 15:46:36 +01001313 if (!res.isOk())
1314 return res;
1315
Emilian Peev40ead602017-09-26 15:46:36 +01001316 streamInfos.push_back(outInfo);
1317 newOutputs.push_back(surface);
1318 }
1319
1320 //Trivial case no changes required
1321 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1322 return binder::Status::ok();
1323 }
1324
1325 KeyedVector<sp<Surface>, size_t> outputMap;
1326 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1327 &outputMap);
1328 if (ret != OK) {
1329 switch (ret) {
1330 case NAME_NOT_FOUND:
1331 case BAD_VALUE:
1332 case -EBUSY:
1333 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1334 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001335 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001336 break;
1337 default:
1338 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1339 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001340 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001341 break;
1342 }
1343 } else {
1344 for (const auto &it : removedOutputs) {
1345 mStreamMap.removeItem(it);
1346 }
1347
1348 for (size_t i = 0; i < outputMap.size(); i++) {
1349 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1350 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1351 }
1352
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001353 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1354
Emilian Peev40ead602017-09-26 15:46:36 +01001355 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001356 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001357 }
1358
1359 return res;
1360}
1361
Igor Murashkine7ee7632013-06-11 18:10:18 -07001362// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001363binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1364 /*out*/
1365 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001366{
1367 ATRACE_CALL();
1368 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1369
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001370 binder::Status res;
1371 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001372
1373 Mutex::Autolock icl(mBinderSerializationLock);
1374
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001375 if (!mDevice.get()) {
1376 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1377 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001378
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001379 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001380 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
1381 if (!(res = mapRequestTemplate(templateId, &tempId)).isOk()) return res;
1382
1383 CameraMetadata metadata;
1384 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001385 request != NULL) {
1386
1387 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001388 } else if (err == BAD_VALUE) {
1389 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001390 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001391 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001392
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001393 } else {
1394 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001395 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001396 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001397 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001398 return res;
1399}
1400
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001401binder::Status CameraDeviceClient::getCameraInfo(
1402 /*out*/
1403 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001404{
1405 ATRACE_CALL();
1406 ALOGV("%s", __FUNCTION__);
1407
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001408 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001409
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001410 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001411
1412 Mutex::Autolock icl(mBinderSerializationLock);
1413
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001414 if (!mDevice.get()) {
1415 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1416 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001417
Igor Murashkin099b4572013-07-12 17:52:16 -07001418 if (info != NULL) {
1419 *info = mDevice->info(); // static camera metadata
1420 // TODO: merge with device-specific camera metadata
1421 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001422
1423 return res;
1424}
1425
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001426binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001427{
1428 ATRACE_CALL();
1429 ALOGV("%s", __FUNCTION__);
1430
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001431 binder::Status res;
1432 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001433
1434 Mutex::Autolock icl(mBinderSerializationLock);
1435
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001436 if (!mDevice.get()) {
1437 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1438 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001439
1440 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001441 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001442 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001443 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001444 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001445 mCameraIdStr.c_str());
1446 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1447 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001448 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001449 status_t err = mDevice->waitUntilDrained();
1450 if (err != OK) {
1451 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001452 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001453 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001454 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001455 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001456 return res;
1457}
1458
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001459binder::Status CameraDeviceClient::flush(
1460 /*out*/
1461 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001462 ATRACE_CALL();
1463 ALOGV("%s", __FUNCTION__);
1464
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001465 binder::Status res;
1466 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001467
1468 Mutex::Autolock icl(mBinderSerializationLock);
1469
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001470 if (!mDevice.get()) {
1471 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1472 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001473
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001474 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001475 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001476 status_t err = mDevice->flush(lastFrameNumber);
1477 if (err != OK) {
1478 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001479 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1480 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001481 }
1482 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001483}
1484
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001485binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001486 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001487 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001488
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001489 binder::Status res;
1490 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001491
1492 Mutex::Autolock icl(mBinderSerializationLock);
1493
1494 // Guard against trying to prepare non-created streams
1495 ssize_t index = NAME_NOT_FOUND;
1496 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001497 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001498 index = i;
1499 break;
1500 }
1501 }
1502
1503 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001504 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1505 "with that ID exists", mCameraIdStr.c_str(), streamId);
1506 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1507 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001508 }
1509
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001510 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1511 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001512 status_t err = mDevice->prepare(streamId);
1513 if (err == BAD_VALUE) {
1514 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001515 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001516 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001517 } else if (err != OK) {
1518 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001519 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001520 strerror(-err), err);
1521 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001522 return res;
1523}
1524
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001525binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001526 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001527 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001528
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001529 binder::Status res;
1530 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001531
1532 Mutex::Autolock icl(mBinderSerializationLock);
1533
1534 // Guard against trying to prepare non-created streams
1535 ssize_t index = NAME_NOT_FOUND;
1536 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001537 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001538 index = i;
1539 break;
1540 }
1541 }
1542
1543 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001544 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1545 "with that ID exists", mCameraIdStr.c_str(), streamId);
1546 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1547 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001548 }
1549
1550 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001551 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1552 mCameraIdStr.c_str(), maxCount);
1553 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1554 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001555 }
1556
1557 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1558 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001559 status_t err = mDevice->prepare(maxCount, streamId);
1560 if (err == BAD_VALUE) {
1561 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001562 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001563 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001564 } else if (err != OK) {
1565 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001566 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001567 strerror(-err), err);
1568 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001569
1570 return res;
1571}
1572
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001573binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001574 ATRACE_CALL();
1575 ALOGV("%s", __FUNCTION__);
1576
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001577 binder::Status res;
1578 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001579
1580 Mutex::Autolock icl(mBinderSerializationLock);
1581
1582 // Guard against trying to prepare non-created streams
1583 ssize_t index = NAME_NOT_FOUND;
1584 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001585 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001586 index = i;
1587 break;
1588 }
1589 }
1590
1591 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001592 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1593 "with that ID exists", mCameraIdStr.c_str(), streamId);
1594 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1595 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001596 }
1597
1598 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1599 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001600 status_t err = mDevice->tearDown(streamId);
1601 if (err == BAD_VALUE) {
1602 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001603 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001604 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001605 } else if (err != OK) {
1606 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001607 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001608 strerror(-err), err);
1609 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001610
1611 return res;
1612}
1613
Shuzhen Wang758c2152017-01-10 18:26:18 -08001614binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001615 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1616 ATRACE_CALL();
1617
1618 binder::Status res;
1619 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1620
1621 Mutex::Autolock icl(mBinderSerializationLock);
1622
Shuzhen Wang0129d522016-10-30 22:43:41 -07001623 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1624 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001625 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001626
Shuzhen Wang0129d522016-10-30 22:43:41 -07001627 if (bufferProducers.size() == 0) {
1628 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001629 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1630 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001631
Shuzhen Wang758c2152017-01-10 18:26:18 -08001632 // streamId should be in mStreamMap if this stream already has a surface attached
1633 // to it. Otherwise, it should be in mDeferredStreams.
1634 bool streamIdConfigured = false;
1635 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1636 for (size_t i = 0; i < mStreamMap.size(); i++) {
1637 if (mStreamMap.valueAt(i).streamId() == streamId) {
1638 streamIdConfigured = true;
1639 break;
1640 }
Zhijun He5d677d12016-05-29 16:52:39 -07001641 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001642 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1643 if (streamId == mDeferredStreams[i]) {
1644 deferredStreamIndex = i;
1645 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001646 }
1647
Shuzhen Wang758c2152017-01-10 18:26:18 -08001648 }
1649 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001650 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1651 "(ID %d)", mCameraIdStr.c_str(), streamId);
1652 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1653 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001654 }
1655
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001656 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001657 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1658 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1659 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1660 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001661 }
1662
Zhijun He5d677d12016-05-29 16:52:39 -07001663 if (!mDevice.get()) {
1664 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1665 }
1666
Shuzhen Wang758c2152017-01-10 18:26:18 -08001667 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001668 const std::vector<int32_t> &sensorPixelModesUsed =
1669 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001670 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001671 int32_t colorSpace = outputConfiguration.getColorSpace();
1672 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001673 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001674 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001675 for (auto& bufferProducer : bufferProducers) {
1676 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001677 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1678 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001679 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001680 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001681 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001682 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001683
1684 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001685 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001686 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001687 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001688 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001689
1690 if (!res.isOk())
1691 return res;
1692
1693 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001694 }
1695
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001696 // Gracefully handle case where finalizeOutputConfigurations is called
1697 // without any new surface.
1698 if (consumerSurfaces.size() == 0) {
1699 mStreamInfoMap[streamId].finalized = true;
1700 return res;
1701 }
1702
Zhijun He5d677d12016-05-29 16:52:39 -07001703 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001704 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001705 std::vector<int> consumerSurfaceIds;
1706 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001707 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001708 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1709 sp<IBinder> binder = IInterface::asBinder(
1710 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001711 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001712 binder.get(), streamId, consumerSurfaceIds[i]);
1713 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1714 }
1715 if (deferredStreamIndex != NAME_NOT_FOUND) {
1716 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001717 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001718 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001719 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001720 } else if (err == NO_INIT) {
1721 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001722 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001723 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001724 } else {
1725 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001726 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001727 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001728 }
1729
1730 return res;
1731}
1732
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001733binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001734 ATRACE_CALL();
1735 binder::Status res;
1736 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1737
1738 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001739 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1740 mCameraIdStr.c_str(), mode);
1741 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1742 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001743 }
1744
1745 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001746 BasicClient::setAudioRestriction(mode);
1747 return binder::Status::ok();
1748}
1749
1750binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1751 ATRACE_CALL();
1752 binder::Status res;
1753 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1754 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001755 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001756 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001757 }
1758 return binder::Status::ok();
1759}
1760
Ravneetaeb20dc2022-03-30 05:33:03 +00001761status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1762 return mDevice->setCameraServiceWatchdog(enabled);
1763}
1764
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001765status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop) {
1766 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1767
1768 return mDevice->setRotateAndCropAutoBehavior(
1769 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop));
1770}
1771
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001772status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1773 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1774
1775 return mDevice->setAutoframingAutoBehavior(
1776 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1777}
1778
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001779bool CameraDeviceClient::supportsCameraMute() {
1780 return mDevice->supportsCameraMute();
1781}
1782
1783status_t CameraDeviceClient::setCameraMute(bool enabled) {
1784 return mDevice->setCameraMute(enabled);
1785}
1786
Shuzhen Wang16610a62022-12-15 22:38:07 -08001787void CameraDeviceClient::setStreamUseCaseOverrides(
1788 const std::vector<int64_t>& useCaseOverrides) {
1789 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1790}
1791
1792void CameraDeviceClient::clearStreamUseCaseOverrides() {
1793 mDevice->clearStreamUseCaseOverrides();
1794}
1795
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001796bool CameraDeviceClient::supportsZoomOverride() {
1797 return mDevice->supportsZoomOverride();
1798}
1799
1800status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1801 return mDevice->setZoomOverride(zoomOverride);
1802}
1803
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001804binder::Status CameraDeviceClient::switchToOffline(
1805 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001806 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001807 /*out*/
1808 sp<hardware::camera2::ICameraOfflineSession>* session) {
1809 ATRACE_CALL();
1810
1811 binder::Status res;
1812 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1813
1814 Mutex::Autolock icl(mBinderSerializationLock);
1815
1816 if (!mDevice.get()) {
1817 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1818 }
1819
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001820 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001821 std::string msg = "Offline surfaces must not be empty";
1822 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1823 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001824 }
1825
1826 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001827 std::string msg = "Invalid offline session";
1828 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1829 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001830 }
1831
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001832 std::vector<int32_t> offlineStreamIds;
1833 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001834 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001835 for (const auto& streamId : offlineOutputIds) {
1836 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001837 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001838 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001839 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001840 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1841 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001842 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001843
1844 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001845 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001846 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001847 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1848 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001849 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001850
Emilian Peev2f5d6012022-01-19 16:16:50 -08001851 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001852 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001853 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001854 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001855 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001856 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001857 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001858 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001859 if (isCompositeStream) {
1860 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1861 if (compositeIdx == NAME_NOT_FOUND) {
1862 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1863 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1864 "Unknown composite stream");
1865 }
1866
1867 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1868 &offlineStreamIds);
1869 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1870 mCompositeStreamMap.valueAt(compositeIdx));
1871 break;
1872 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001873 }
1874
Emilian Peev4697b642019-11-19 17:11:14 -08001875 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001876 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001877 }
1878 }
1879
1880 sp<CameraOfflineSessionBase> offlineSession;
1881 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1882 if (ret != OK) {
1883 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1884 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001885 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001886 }
1887
Emilian Peevcc0b7952020-01-07 13:54:47 -08001888 sp<CameraOfflineSessionClient> offlineClient;
1889 if (offlineSession.get() != nullptr) {
1890 offlineClient = new CameraOfflineSessionClient(sCameraService,
1891 offlineSession, offlineCompositeStreamMap, cameraCb, mClientPackageName,
Emilian Peev8b64f282021-03-25 16:49:57 -07001892 mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation, mClientPid, mClientUid,
1893 mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001894 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1895 }
1896
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001897 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001898 // A successful offline session switch must reset the current camera client
1899 // and release any resources occupied by previously configured streams.
1900 mStreamMap.clear();
1901 mConfiguredOutputs.clear();
1902 mDeferredStreams.clear();
1903 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001904 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001905 mCompositeStreamMap.clear();
1906 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001907 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001908 // In case we failed to register the offline client, ensure that it still initialized
1909 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001910 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001911
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001912 switch(ret) {
1913 case BAD_VALUE:
1914 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1915 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1916 case TIMED_OUT:
1917 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1918 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1919 default:
1920 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1921 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1922 strerror(-ret), ret);
1923 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001924 }
1925
1926 *session = offlineClient;
1927
1928 return binder::Status::ok();
1929}
1930
Igor Murashkine7ee7632013-06-11 18:10:18 -07001931status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001932 return BasicClient::dump(fd, args);
1933}
1934
1935status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001936 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001937 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001938 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001939 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001940 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001941
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001942 dprintf(fd, " State:\n");
1943 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001944 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001945 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001946 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001947 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001948 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001949 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001950 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001951 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001952 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001953 mStreamMap.valueAt(i).streamId(),
1954 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001955 }
Zhijun He5d677d12016-05-29 16:52:39 -07001956 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001957 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001958 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001959 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001960 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001961 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001962 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001963 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001964 // TODO: print dynamic/request section from most recent requests
1965 mFrameProcessor->dump(fd, args);
1966
1967 return dumpDevice(fd, args);
1968}
1969
Austin Borger1c1bee02023-06-01 16:51:35 -07001970status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07001971 sp<CameraDeviceBase> device = mDevice;
1972 if (!device) {
1973 dprintf(out, " Device is detached.");
1974 return OK;
1975 }
1976 device->startWatchingTags(tags);
1977 return OK;
1978}
1979
1980status_t CameraDeviceClient::stopWatchingTags(int out) {
1981 sp<CameraDeviceBase> device = mDevice;
1982 if (!device) {
1983 dprintf(out, " Device is detached.");
1984 return OK;
1985 }
1986 device->stopWatchingTags();
1987 return OK;
1988}
1989
1990status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
1991 sp<CameraDeviceBase> device = mDevice;
1992 if (!device) {
1993 return OK;
1994 }
1995 device->dumpWatchedEventsToVector(out);
1996 return OK;
1997}
1998
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001999void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07002000 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002001 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002002 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002003
Emilian Peev538c90e2018-12-17 18:03:19 +00002004 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002005 {
2006 // Access to the composite stream map must be synchronized
2007 Mutex::Autolock l(mCompositeLock);
2008 // Composites can have multiple internal streams. Error notifications coming from such
2009 // internal streams may need to remain within camera service.
2010 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2011 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2012 resultExtras);
2013 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002014 }
2015
2016 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002017 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002018 }
2019}
2020
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002021void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2022 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2023
2024 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002025 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002026 }
2027
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002028 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002029 mStreamingRequestId = REQUEST_ID_NONE;
2030}
2031
Shuzhen Wang316781a2020-08-18 18:11:01 -07002032void CameraDeviceClient::notifyIdle(
2033 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2034 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002035 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002036 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002037
2038 if (remoteCb != 0) {
2039 remoteCb->onDeviceIdle();
2040 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002041
2042 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2043 {
2044 Mutex::Autolock l(mCompositeLock);
2045 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2046 hardware::CameraStreamStats compositeStats;
2047 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2048 if (compositeStats.mWidth > 0) {
2049 fullStreamStats.push_back(compositeStats);
2050 }
2051 }
2052 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002053 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Emilian Peev567c31c2023-03-06 15:02:37 -08002054 fullStreamStats, mUserTag, mVideoStabilizationMode);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002055}
2056
Jianing Weicb0652e2014-03-12 18:29:36 -07002057void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002058 nsecs_t timestamp) {
2059 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002060 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002061 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002062 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002063 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002064 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002065
Emilian Peev2f5d6012022-01-19 16:16:50 -08002066 // Access to the composite stream map must be synchronized
2067 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002068 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2069 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2070 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002071}
2072
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002073void CameraDeviceClient::notifyPrepared(int streamId) {
2074 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002075 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002076 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002077 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002078 remoteCb->onPrepared(streamId);
2079 }
2080}
2081
Shuzhen Wang9d066012016-09-30 11:30:20 -07002082void CameraDeviceClient::notifyRequestQueueEmpty() {
2083 // Thread safe. Don't bother locking.
2084 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2085 if (remoteCb != 0) {
2086 remoteCb->onRequestQueueEmpty();
2087 }
2088}
2089
Igor Murashkine7ee7632013-06-11 18:10:18 -07002090void CameraDeviceClient::detachDevice() {
2091 if (mDevice == 0) return;
2092
Shuzhen Wang316781a2020-08-18 18:11:01 -07002093 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002094 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002095
Emilian Peev7ee731f2022-02-08 14:55:52 -08002096 if (mFrameProcessor.get() != nullptr) {
2097 mFrameProcessor->removeListener(
2098 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2099 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2100 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002101 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002102 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002103 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002104 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002105
2106 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2107 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002108 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002109 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002110 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2111 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2112 }
2113
Igor Murashkine7ee7632013-06-11 18:10:18 -07002114 if ((code = mDevice->waitUntilDrained()) != OK) {
2115 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2116 code);
2117 }
2118 }
2119
Emilian Peev2f5d6012022-01-19 16:16:50 -08002120 {
2121 Mutex::Autolock l(mCompositeLock);
2122 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2123 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2124 if (ret != OK) {
2125 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2126 strerror(-ret), ret);
2127 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002128 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002129 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002130 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002131
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002132 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002133 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002134
2135 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002136 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002137}
2138
2139/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002140void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002141 ATRACE_CALL();
2142 ALOGV("%s", __FUNCTION__);
2143
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002144 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002145 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002146 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002147 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2148 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002149 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002150
Emilian Peev2f5d6012022-01-19 16:16:50 -08002151 // Access to the composite stream map must be synchronized
2152 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002153 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2154 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2155 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002156}
2157
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002158binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002159 if (mDisconnected) {
2160 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2161 "The camera device has been disconnected");
2162 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002163 status_t res = checkPid(checkLocation);
2164 return (res == OK) ? binder::Status::ok() :
2165 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2166 "Attempt to use camera from a different process than original client");
2167}
2168
Igor Murashkine7ee7632013-06-11 18:10:18 -07002169// TODO: move to Camera2ClientBase
2170bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2171
Jayant Chowdhary12361932018-08-27 14:46:13 -07002172 const int pid = CameraThreadState::getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002173 const int selfPid = getpid();
2174 camera_metadata_entry_t entry;
2175
2176 /**
2177 * Mixin default important security values
2178 * - android.led.transmit = defaulted ON
2179 */
2180 CameraMetadata staticInfo = mDevice->info();
2181 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2182 for(size_t i = 0; i < entry.count; ++i) {
2183 uint8_t led = entry.data.u8[i];
2184
2185 switch(led) {
2186 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2187 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2188 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2189 metadata.update(ANDROID_LED_TRANSMIT,
2190 &transmitDefault, 1);
2191 }
2192 break;
2193 }
2194 }
2195 }
2196
2197 // We can do anything!
2198 if (pid == selfPid) {
2199 return true;
2200 }
2201
2202 /**
2203 * Permission check special fields in the request
2204 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2205 */
2206 entry = metadata.find(ANDROID_LED_TRANSMIT);
2207 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2208 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002209 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002210 if (!checkCallingPermission(permissionString)) {
Jayant Chowdhary12361932018-08-27 14:46:13 -07002211 const int uid = CameraThreadState::getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002212 ALOGE("Permission Denial: "
2213 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2214 return false;
2215 }
2216 }
2217
2218 return true;
2219}
2220
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002221status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2222 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002223 ALOGV("%s: begin", __FUNCTION__);
2224
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002225 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002226 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002227}
2228
Emilian Peevf4816702020-04-03 15:44:51 -07002229binder::Status CameraDeviceClient::mapRequestTemplate(int templateId,
2230 camera_request_template_t* tempId /*out*/) {
2231 binder::Status ret = binder::Status::ok();
2232
2233 if (tempId == nullptr) {
2234 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -07002235 "Camera %s: Invalid template argument", mCameraIdStr.c_str());
Emilian Peevf4816702020-04-03 15:44:51 -07002236 return ret;
2237 }
2238 switch(templateId) {
2239 case ICameraDeviceUser::TEMPLATE_PREVIEW:
2240 *tempId = camera_request_template_t::CAMERA_TEMPLATE_PREVIEW;
2241 break;
2242 case ICameraDeviceUser::TEMPLATE_RECORD:
2243 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_RECORD;
2244 break;
2245 case ICameraDeviceUser::TEMPLATE_STILL_CAPTURE:
2246 *tempId = camera_request_template_t::CAMERA_TEMPLATE_STILL_CAPTURE;
2247 break;
2248 case ICameraDeviceUser::TEMPLATE_VIDEO_SNAPSHOT:
2249 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_SNAPSHOT;
2250 break;
2251 case ICameraDeviceUser::TEMPLATE_ZERO_SHUTTER_LAG:
2252 *tempId = camera_request_template_t::CAMERA_TEMPLATE_ZERO_SHUTTER_LAG;
2253 break;
2254 case ICameraDeviceUser::TEMPLATE_MANUAL:
2255 *tempId = camera_request_template_t::CAMERA_TEMPLATE_MANUAL;
2256 break;
2257 default:
2258 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
2259 "Camera %s: Template ID %d is invalid or not supported",
Austin Borger1c1bee02023-06-01 16:51:35 -07002260 mCameraIdStr.c_str(), templateId);
Emilian Peevf4816702020-04-03 15:44:51 -07002261 return ret;
2262 }
2263
2264 return ret;
2265}
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002266
Austin Borger1c1bee02023-06-01 16:51:35 -07002267const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002268 if (mDevice->getId() == cameraId) {
2269 return mDevice->info();
2270 }
2271 return mDevice->infoPhysical(cameraId);
2272}
2273
Austin Borger1c1bee02023-06-01 16:51:35 -07002274bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002275 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002276 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002277}
2278
2279bool CameraDeviceClient::isSensorPixelModeConsistent(
2280 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2281 // First we get the sensorPixelMode from the settings metadata.
2282 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2283 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2284 if (sensorPixelModeEntry.count != 0) {
2285 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2286 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2287 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2288 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2289 __FUNCTION__, sensorPixelMode);
2290 return false;
2291 }
2292 }
2293 // Check whether each stream has max resolution allowed.
2294 bool consistent = true;
2295 for (auto it : streamIdList) {
2296 auto const streamInfoIt = mStreamInfoMap.find(it);
2297 if (streamInfoIt == mStreamInfoMap.end()) {
2298 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2299 return false;
2300 }
2301 consistent =
2302 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2303 streamInfoIt->second.sensorPixelModesUsed.end();
2304 if (!consistent) {
2305 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2306 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2307 ALOGE("sensor pixel mode used list: %i", m);
2308 }
2309 break;
2310 }
2311 }
2312
2313 return consistent;
2314}
2315
Igor Murashkine7ee7632013-06-11 18:10:18 -07002316} // namespace android