blob: c60f327fa58af711f2eab13a3f8dc12dde7dab70 [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,
102 bool overrideToPortrait) :
Austin Borger74fca042022-05-23 12:41:21 -0700103 Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper, clientPackageName,
104 systemNativeClient, clientFeatureId, cameraId, /*API1 camera ID*/ -1, cameraFacing,
Austin Borger18b30a72022-10-27 12:20:29 -0700105 sensorOrientation, clientPid, clientUid, servicePid, overrideForPerfClass,
106 overrideToPortrait),
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700107 mInputStream(),
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700108 mStreamingRequestId(REQUEST_ID_NONE),
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700109 mRequestIdCounter(0),
110 mOverrideForPerfClass(overrideForPerfClass) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700111
112 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -0700113 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700114}
115
Emilian Peevbd8c5032018-02-14 23:05:40 +0000116status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -0700117 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000118 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800119}
120
121template<typename TProviderPtr>
Austin Borger1c1bee02023-06-01 16:51:35 -0700122status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
123 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700124 ATRACE_CALL();
125 status_t res;
126
Emilian Peevbd8c5032018-02-14 23:05:40 +0000127 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700128 if (res != OK) {
129 return res;
130 }
131
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700132 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger1c1bee02023-06-01 16:51:35 -0700133 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
134 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700135 if (res != OK) {
136 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
137 __FUNCTION__, strerror(-res), res);
138 return res;
139 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700140
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800141 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
142 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800143 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700144 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700145
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800146 const CameraMetadata &deviceInfo = mDevice->info();
147 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000148 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
149 if (physicalKeysEntry.count > 0) {
150 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
151 physicalKeysEntry.data.i32,
152 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
153 }
154
Emilian Peev2295df72021-11-12 18:14:10 -0800155 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
156 mDynamicProfileMap.emplace(
157 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
158 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
159 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800160 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800161 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800162 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800163 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800164 if (entry.count > 0 || ((entry.count % 3) != 0)) {
165 int64_t standardBitmap =
166 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
167 for (size_t i = 0; i < entry.count; i += 3) {
168 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800169 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800170 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
171 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800172 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800173 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800174 }
175 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800176 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
177 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800178 }
179 }
Emilian Peevef715e22022-05-19 17:44:33 -0700180 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
181 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800182 } else {
183 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
184 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
185 }
186 }
187 }
188
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700189 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800190 // Cache physical camera ids corresponding to this device and also the high
191 // resolution sensors in this device + physical camera ids
Austin Borger1c1bee02023-06-01 16:51:35 -0700192 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800193 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700194 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800195 }
196 for (auto &physicalId : mPhysicalCameraIds) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700197 if (supportsUltraHighResolutionCapture(physicalId)) {
198 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800199 }
200 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700201 return OK;
202}
203
204CameraDeviceClient::~CameraDeviceClient() {
205}
206
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800207binder::Status CameraDeviceClient::submitRequest(
208 const hardware::camera2::CaptureRequest& request,
209 bool streaming,
210 /*out*/
211 hardware::camera2::utils::SubmitInfo *submitInfo) {
212 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
213 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700214}
215
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800216binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000217 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000218 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800219 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
220
Emilian Peev2f5d6012022-01-19 16:16:50 -0800221 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800222 // Trying to submit request with surface that wasn't created
223 if (idx == NAME_NOT_FOUND) {
224 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
225 " we have not called createStream on",
Austin Borger1c1bee02023-06-01 16:51:35 -0700226 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800227 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
228 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000229 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
230 != NAME_NOT_FOUND) {
231 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
232 currentStreamId);
233 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800234 }
235
236 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
237 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800238 outputStreamIds->push_back(streamSurfaceId.streamId());
239 }
240 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
241
242 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700243 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800244 streamSurfaceId.surfaceId());
245
Emilian Peevf873aa52018-01-26 14:58:28 +0000246 if (currentStreamId != nullptr) {
247 *currentStreamId = streamSurfaceId.streamId();
248 }
249
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800250 return binder::Status::ok();
251}
252
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800253static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
254 const Vector<int> &streamIdsForThisRequest) {
255 std::list<int> intersection;
256 for (auto &streamId : streamIdsForThisRequest) {
257 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
258 intersection.emplace_back(streamId);
259 }
260 }
261 return intersection;
262}
263
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800264binder::Status CameraDeviceClient::submitRequestList(
265 const std::vector<hardware::camera2::CaptureRequest>& requests,
266 bool streaming,
267 /*out*/
268 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700269 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700270 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700271
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800272 binder::Status res = binder::Status::ok();
273 status_t err;
274 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
275 return res;
276 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700277
278 Mutex::Autolock icl(mBinderSerializationLock);
279
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800280 if (!mDevice.get()) {
281 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
282 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700283
284 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800285 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700286 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800287 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700288 }
289
Emilian Peevaebbe412018-01-15 13:53:24 +0000290 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700291 std::list<const SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800292 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700293 uint32_t loopCounter = 0;
294
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800295 for (auto&& request: requests) {
296 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700297 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800298 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700299 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800300 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800301 "No input configured for camera %s but request is for reprocessing",
Austin Borger1c1bee02023-06-01 16:51:35 -0700302 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700303 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800304 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700305 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800306 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
307 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000308 } else if (request.mPhysicalCameraSettings.size() > 1) {
309 ALOGE("%s: Camera %s: reprocess requests not supported for "
310 "multiple physical cameras.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700311 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000312 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
313 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700314 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700315 }
316
Emilian Peevaebbe412018-01-15 13:53:24 +0000317 if (request.mPhysicalCameraSettings.empty()) {
318 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700319 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800320 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000321 "Request doesn't contain any settings");
322 }
323
324 //The first capture settings should always match the logical camera id
Austin Borger1c1bee02023-06-01 16:51:35 -0700325 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
Emilian Peevaebbe412018-01-15 13:53:24 +0000326 if (mDevice->getId() != logicalId) {
327 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700328 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000329 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
330 "Invalid camera request settings");
331 }
332
Emilian Peevaebbe412018-01-15 13:53:24 +0000333 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800334 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger1c1bee02023-06-01 16:51:35 -0700335 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800336 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
337 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700338 }
339
Jianing Wei90e59c92014-03-12 18:29:36 -0700340 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700341 * Write in the output stream IDs and map from stream ID to surface ID
342 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700343 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700344 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700345 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000346 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800347 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800348 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800349 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800350 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700351
Emilian Peevf873aa52018-01-26 14:58:28 +0000352 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800353 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000354 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800355 if (!res.isOk()) {
356 return res;
357 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000358
359 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
360 if (index >= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700361 const std::string &requestedPhysicalId =
362 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
363 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800364 dynamicProfileBitmap |=
365 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000366 } else {
367 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
368 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700369 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800370 } else {
371 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
372 int streamId = request.mStreamIdxList.itemAt(i);
373 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700374
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800375 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
376 if (index < 0) {
377 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
378 " we have not called createStream on: stream %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700379 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800380 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
381 "Request targets Surface that is not part of current capture session");
382 }
383
384 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
385 if ((size_t)surfaceIdx >= gbps.size()) {
386 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
387 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700388 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800389 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
390 "Request targets Surface has invalid surface index");
391 }
392
Emilian Peevf873aa52018-01-26 14:58:28 +0000393 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800394 if (!res.isOk()) {
395 return res;
396 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000397
Austin Borger1c1bee02023-06-01 16:51:35 -0700398 const std::string &requestedPhysicalId =
399 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
400 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800401 dynamicProfileBitmap |=
402 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
403 }
404 }
405
406 if (dynamicProfileBitmap !=
407 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
408 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
409 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
410 if ((dynamicProfileBitmap & i) == 0) {
411 continue;
412 }
413
414 const auto& it = mDynamicProfileMap.find(i);
415 if (it != mDynamicProfileMap.end()) {
416 if ((it->second == 0) ||
417 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
418 continue;
419 } else {
420 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
421 " reference an unsupported dynamic range profile combination"
Austin Borger1c1bee02023-06-01 16:51:35 -0700422 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800423 dynamicProfileBitmap);
424 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
425 "Request targets an unsupported dynamic range profile"
426 " combination");
427 }
428 } else {
429 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
430 " references unsupported dynamic range profile 0x%x!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700431 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800432 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
433 "Request targets 10-bit Surface with unsupported dynamic range"
434 " profile");
435 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700436 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700437 }
438
Emilian Peevf873aa52018-01-26 14:58:28 +0000439 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
440 for (const auto& it : request.mPhysicalCameraSettings) {
Emilian Peev00420d22018-02-05 21:33:13 +0000441 if (it.settings.isEmpty()) {
442 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700443 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000444 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
445 "Request settings are empty");
446 }
447
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800448 // Check whether the physical / logical stream has settings
449 // consistent with the sensor pixel mode(s) it was configured with.
450 // mCameraIdToStreamSet will only have ids that are high resolution
451 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(it.id);
452 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
453 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
454 outputStreamIds);
455 if (!request.mIsReprocess &&
456 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
457 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
458 "consistent with configured streams. Rejecting request.",
459 __FUNCTION__, it.id.c_str());
460 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
461 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
462 "streams configured");
463 }
464 }
465
Austin Borger1c1bee02023-06-01 16:51:35 -0700466 const std::string &physicalId = it.id;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700467 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
468 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
469 mSupportedPhysicalRequestKeys.end();
470 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
471 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
472 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000473 if (physicalId != mDevice->getId()) {
474 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
475 it.id);
476 if (found == requestedPhysicalIds.end()) {
477 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700478 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000479 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
480 "Invalid physical camera id");
481 }
Emilian Peev00420d22018-02-05 21:33:13 +0000482
483 if (!mSupportedPhysicalRequestKeys.empty()) {
484 // Filter out any unsupported physical request keys.
485 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
486 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
487 filteredParams.getAndLock());
488 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
489 filteredParams.unlock(meta);
490
491 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
492 camera_metadata_ro_entry entry = it.settings.find(keyIt);
493 if (entry.count > 0) {
494 filteredParams.update(entry);
495 }
496 }
497
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700498 physicalSettingsList.push_back({it.id, filteredParams,
499 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000500 }
501 } else {
502 physicalSettingsList.push_back({it.id, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000503 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000504 }
505
506 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
507 // Callee logs
508 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
509 "Caller does not have permission to change restricted controls");
510 }
511
Emilian Peevaebbe412018-01-15 13:53:24 +0000512 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
513 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700514
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800515 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000516 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
517 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700518 }
519
Emilian Peevaebbe412018-01-15 13:53:24 +0000520 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
521 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700522 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800523 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700524 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800525 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700526
Emilian Peevaebbe412018-01-15 13:53:24 +0000527 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700528 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800529
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700530 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800531 if (!request.mUserTag.empty()) {
532 mUserTag = request.mUserTag;
533 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700534 camera_metadata_entry entry =
535 physicalSettingsList.begin()->metadata.find(
536 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
537 if (entry.count == 1) {
538 mVideoStabilizationMode = entry.data.u8[0];
539 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700540 }
541 mRequestIdCounter++;
542
543 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700544 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
545 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800546 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700547 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800548 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700549 mCameraIdStr.c_str(), strerror(-err), err);
550 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800551 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700552 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700553 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700554 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700555 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700556 }
557 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700558 err = mDevice->captureList(metadataRequestList, surfaceMapList,
559 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800560 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700561 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800562 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700563 mCameraIdStr.c_str(), strerror(-err), err);
564 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800565 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700566 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700567 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800568 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700569 }
570
Austin Borger1c1bee02023-06-01 16:51:35 -0700571 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700572 return res;
573}
574
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800575binder::Status CameraDeviceClient::cancelRequest(
576 int requestId,
577 /*out*/
578 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700579 ATRACE_CALL();
580 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
581
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800582 status_t err;
583 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700584
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800585 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700586
587 Mutex::Autolock icl(mBinderSerializationLock);
588
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800589 if (!mDevice.get()) {
590 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
591 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700592
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700593 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700594 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700595 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
596 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
597 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
598 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700599 }
600
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800601 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700602
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800603 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800604 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700605 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700606 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800607 } else {
608 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800609 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700610 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700611 }
612
613 return res;
614}
615
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800616binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700617 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700618 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700619 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800620 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700621}
622
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100623binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700624 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800625 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700626 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700627 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
628 __FUNCTION__, mInputStream.configured ? 1 : 0,
629 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700630
Zhijun He0effd522016-03-04 10:22:27 -0800631 binder::Status res;
632 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
633
Emilian Peevcc0b7952020-01-07 13:54:47 -0800634 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700635 std::string msg = "Invalid offline stream ids";
636 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
637 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800638 }
639
Zhijun He0effd522016-03-04 10:22:27 -0800640 Mutex::Autolock icl(mBinderSerializationLock);
641
642 if (!mDevice.get()) {
643 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
644 }
645
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700646 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000647 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000648 if (!res.isOk()) {
649 return res;
650 }
651
652 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
653 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700654 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
655 mCameraIdStr.c_str());
656 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
657 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000658 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700659 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
660 mCameraIdStr.c_str(), strerror(-err), err);
661 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
662 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000663 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800664 offlineStreamIds->clear();
665 mDevice->getOfflineStreamIds(offlineStreamIds);
666
Emilian Peev2f5d6012022-01-19 16:16:50 -0800667 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000668 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
669 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800670 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700671 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
672 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
673 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
674 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000675 break;
676 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800677
678 // Composite streams can only support offline mode in case all individual internal
679 // streams are also supported.
680 std::vector<int> internalStreams;
681 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800682 offlineStreamIds->erase(
683 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800684 [&internalStreams] (int streamId) {
685 auto it = std::find(internalStreams.begin(), internalStreams.end(),
686 streamId);
687 if (it != internalStreams.end()) {
688 internalStreams.erase(it);
689 return true;
690 }
691
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800692 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800693 if (internalStreams.empty()) {
694 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
695 }
696 }
697
698 for (const auto& offlineStreamId : *offlineStreamIds) {
699 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000700 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700701
702 nsecs_t configureEnd = systemTime();
703 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700704 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700705 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000706 }
707
708 return res;
709}
710
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800711binder::Status CameraDeviceClient::isSessionConfigurationSupported(
712 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800713
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800714 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800715 binder::Status res;
716 status_t ret = OK;
717 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
718
719 Mutex::Autolock icl(mBinderSerializationLock);
720
721 if (!mDevice.get()) {
722 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
723 }
724
725 auto operatingMode = sessionConfiguration.getOperatingMode();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700726 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000727 mCameraIdStr);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800728 if (!res.isOk()) {
729 return res;
730 }
731
732 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700733 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
734 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
735 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800736 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700737
Emilian Peev35ae8262018-11-08 13:11:32 +0000738 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700739 camera3::metadataGetter getMetadata = [this](const std::string &id,
740 bool /*overrideForPerfClass*/) {
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700741 return mDevice->infoPhysical(id);};
Austin Borger1c1bee02023-06-01 16:51:35 -0700742 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700743 sessionConfiguration, mOverrideForPerfClass, getMetadata, status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000744 switch (ret) {
745 case OK:
746 // Expected, do nothing.
747 break;
748 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700749 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000750 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700751 mCameraIdStr.c_str());
752 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
753 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000754 }
755
756 break;
757 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700758 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000759 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700760 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000761 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700762 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000763 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800764 }
765
766 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700767}
768
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800769binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700770 ATRACE_CALL();
771 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
772
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800773 binder::Status res;
774 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700775
776 Mutex::Autolock icl(mBinderSerializationLock);
777
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800778 if (!mDevice.get()) {
779 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
780 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700781
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700782 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700783 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700784 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000785 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700786
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700787 if (mInputStream.configured && mInputStream.id == streamId) {
788 isInput = true;
789 } else {
790 // Guard against trying to delete non-created streams
791 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700792 if (streamId == mStreamMap.valueAt(i).streamId()) {
793 surfaces.push_back(mStreamMap.keyAt(i));
794 }
795 }
796
797 // See if this stream is one of the deferred streams.
798 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
799 if (streamId == mDeferredStreams[i]) {
800 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700801 break;
802 }
803 }
804
Emilian Peev2f5d6012022-01-19 16:16:50 -0800805 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000806 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
807 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
808 compositeIndex = i;
809 break;
810 }
811 }
812
Shuzhen Wang0129d522016-10-30 22:43:41 -0700813 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700814 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
815 " stream created yet", mCameraIdStr.c_str(), streamId);
816 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
817 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700818 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700819 }
820
821 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800822 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700823
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800824 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700825 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
826 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
827 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
828 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800829 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700830 if (isInput) {
831 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700832 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700833 for (auto& surface : surfaces) {
834 mStreamMap.removeItem(surface);
835 }
836
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800837 mConfiguredOutputs.removeItem(streamId);
838
Shuzhen Wang0129d522016-10-30 22:43:41 -0700839 if (dIndex != NAME_NOT_FOUND) {
840 mDeferredStreams.removeItemsAt(dIndex);
841 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000842
843 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800844 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000845 status_t ret;
846 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
847 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700848 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
849 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
850 err, streamId);
851 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
852 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000853 }
854 mCompositeStreamMap.removeItemsAt(compositeIndex);
855 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800856 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
857 auto &streamSet = mapIt.second;
858 if (streamSet.find(streamId) != streamSet.end()) {
859 streamSet.erase(streamId);
860 break;
861 }
862 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700863 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700864 }
865
866 return res;
867}
868
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800869binder::Status CameraDeviceClient::createStream(
870 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
871 /*out*/
872 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700873 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700874
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800875 binder::Status res;
876 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700877
878 Mutex::Autolock icl(mBinderSerializationLock);
879
Shuzhen Wang0129d522016-10-30 22:43:41 -0700880 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
881 outputConfiguration.getGraphicBufferProducers();
882 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800883 bool deferredConsumer = outputConfiguration.isDeferred();
884 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700885 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800886 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800887 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800888 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800889 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800890 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800891 int mirrorMode = outputConfiguration.getMirrorMode();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700892 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000893 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700894
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700895 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Emilian Peev35ae8262018-11-08 13:11:32 +0000896 outputConfiguration.getSurfaceType());
897 if (!res.isOk()) {
898 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700899 }
Zhijun He5d677d12016-05-29 16:52:39 -0700900
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800901 if (!mDevice.get()) {
902 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
903 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700904 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800905 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000906 if (!res.isOk()) {
907 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800908 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000909
Shuzhen Wang0129d522016-10-30 22:43:41 -0700910 std::vector<sp<Surface>> surfaces;
911 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700912 status_t err;
913
914 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700915 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800916 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700917 }
918
Shuzhen Wang758c2152017-01-10 18:26:18 -0800919 OutputStreamInfo streamInfo;
920 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800921 const std::vector<int32_t> &sensorPixelModesUsed =
922 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700923 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700924 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700925 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800926 ssize_t index = mStreamMap.indexOfKey(binder);
927 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700928 std::string msg = std::string("Camera ") + mCameraIdStr
929 + ": Surface already has a stream created for it (ID "
930 + std::to_string(index) + ")";
931 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
932 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700933 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700934
Shuzhen Wang758c2152017-01-10 18:26:18 -0800935 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700936 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800937 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800938 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700939 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800940
941 if (!res.isOk())
942 return res;
943
944 if (!isStreamInfoValid) {
945 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700946 }
947
Shuzhen Wang758c2152017-01-10 18:26:18 -0800948 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang0129d522016-10-30 22:43:41 -0700949 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -0800950 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700951
952 // If mOverrideForPerfClass is true, do not fail createStream() for small
953 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
954 // closest possible supported size.
955
Zhijun He125684a2015-12-26 15:07:30 -0800956 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100957 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800958 bool isDepthCompositeStream =
959 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0]);
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800960 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(surfaces[0]);
Emilian Peev434248e2022-10-06 14:58:54 -0700961 bool isJpegRCompositeStream =
Emilian Peeve579d8b2023-02-28 14:16:08 -0800962 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0]) &&
Emilian Peev15230142023-04-27 20:22:54 +0000963 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800964 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800965 sp<CompositeStream> compositeStream;
966 if (isDepthCompositeStream) {
967 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800968 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800969 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -0700970 } else {
971 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800972 }
973
Emilian Peev538c90e2018-12-17 18:03:19 +0000974 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
975 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -0700976 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800977 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -0700978 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000979 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
980 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000981 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800982 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000983 mCompositeStreamMap.add(IInterface::asBinder(surfaces[0]->getIGraphicBufferProducer()),
984 compositeStream);
985 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800986 } else {
987 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
988 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -0700989 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800990 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -0800991 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -0800992 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000993 streamInfo.timestampBase, streamInfo.mirrorMode, streamInfo.colorSpace,
994 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000995 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700996
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800997 if (err != OK) {
998 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800999 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001000 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001001 streamInfo.dataSpace, strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001002 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001003 int i = 0;
1004 for (auto& binder : binders) {
1005 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1006 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001007 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1008 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001009 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001010
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001011 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001012 mStreamInfoMap[streamId] = streamInfo;
1013
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001014 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001015 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001016 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001017 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001018
Zhijun He5d677d12016-05-29 16:52:39 -07001019 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001020 res = setStreamTransformLocked(streamId, streamInfo.mirrorMode);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001021
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001022 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001023 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001024 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001025 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001026 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001027 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001028 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001029 }
1030
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001031 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001032 }
1033
1034 return res;
1035}
1036
Zhijun He5d677d12016-05-29 16:52:39 -07001037binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1038 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001039 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001040 /*out*/
1041 int* newStreamId) {
1042 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001043 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001044 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001045 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001046 status_t err;
1047 binder::Status res;
1048
1049 if (!mDevice.get()) {
1050 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1051 }
1052
1053 // Infer the surface info for deferred surface stream creation.
1054 width = outputConfiguration.getWidth();
1055 height = outputConfiguration.getHeight();
1056 surfaceType = outputConfiguration.getSurfaceType();
1057 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1058 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001059 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001060 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1061 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1062 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1063 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1064 }
1065 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001066 std::vector<sp<Surface>> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001067 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001068 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1069 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001070 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1071 // Here, we override sensor pixel modes
1072 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1073 const std::vector<int32_t> &sensorPixelModesUsed =
1074 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001075 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001076 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001077 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001078 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1079 "sensor pixel modes used not valid for deferred stream");
1080 }
1081
Shuzhen Wang0129d522016-10-30 22:43:41 -07001082 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1083 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001084 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001085 &streamId, physicalCameraId,
1086 overriddenSensorPixelModesUsed,
1087 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001088 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001089 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001090 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001091 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001092 outputConfiguration.getMirrorMode(),
1093 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001094
1095 if (err != OK) {
1096 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001097 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001098 mCameraIdStr.c_str(), width, height, format, dataSpace, strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001099 } else {
1100 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1101 // a separate list to track. Once the deferred surface is set, this id will be
1102 // relocated to mStreamMap.
1103 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001104 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001105 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001106 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001107 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001108 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001109 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001110 outputConfiguration.getMirrorMode(),
1111 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001112
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001113 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001114 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001115 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001116
1117 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001118 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001119
1120 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001121 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001122 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001123 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001124 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001125 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001126 }
Zhijun He5d677d12016-05-29 16:52:39 -07001127 }
1128 return res;
1129}
1130
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001131binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001132 int32_t transform = 0;
1133 status_t err;
1134 binder::Status res;
1135
1136 if (!mDevice.get()) {
1137 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1138 }
1139
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001140 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001141 if (err != OK) {
1142 // Error logged by getRotationTransformLocked.
1143 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1144 "Unable to calculate rotation transform for new stream");
1145 }
1146
1147 err = mDevice->setStreamTransform(streamId, transform);
1148 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001149 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001150 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001151 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1152 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001153 }
1154
1155 return res;
1156}
Ruben Brunkbba75572014-11-20 17:29:50 -08001157
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001158binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001159 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001160 /*out*/
1161 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001162
1163 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001164 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1165 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001166
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001167 binder::Status res;
1168 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001169
1170 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001171
1172 if (!mDevice.get()) {
1173 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1174 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001175
1176 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001177 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1178 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1179 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1180 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001181 }
1182
1183 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001184 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001185 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001186 mInputStream.configured = true;
1187 mInputStream.width = width;
1188 mInputStream.height = height;
1189 mInputStream.format = format;
1190 mInputStream.id = streamId;
1191
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001192 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001193 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001194
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001195 *newStreamId = streamId;
1196 } else {
1197 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001198 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001199 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001200 }
1201
1202 return res;
1203}
1204
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001205binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001206
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001207 binder::Status res;
1208 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1209
1210 if (inputSurface == NULL) {
1211 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001212 }
1213
1214 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001215 if (!mDevice.get()) {
1216 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1217 }
1218 sp<IGraphicBufferProducer> producer;
1219 status_t err = mDevice->getInputBufferProducer(&producer);
1220 if (err != OK) {
1221 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001222 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001223 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001224 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001225 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001226 inputSurface->graphicBufferProducer = producer;
1227 }
1228 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001229}
1230
Emilian Peev40ead602017-09-26 15:46:36 +01001231binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1232 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1233 ATRACE_CALL();
1234
1235 binder::Status res;
1236 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1237
1238 Mutex::Autolock icl(mBinderSerializationLock);
1239
1240 if (!mDevice.get()) {
1241 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1242 }
1243
1244 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1245 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001246 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001247
Emilian Peev40ead602017-09-26 15:46:36 +01001248 auto producerCount = bufferProducers.size();
1249 if (producerCount == 0) {
1250 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1251 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1252 "bufferProducers must not be empty");
1253 }
1254
1255 // The first output is the one associated with the output configuration.
1256 // It should always be present, valid and the corresponding stream id should match.
1257 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1258 ssize_t index = mStreamMap.indexOfKey(binder);
1259 if (index == NAME_NOT_FOUND) {
1260 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1261 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1262 "OutputConfiguration is invalid");
1263 }
1264 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1265 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1266 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1267 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1268 "Stream id is invalid");
1269 }
1270
1271 std::vector<size_t> removedSurfaceIds;
1272 std::vector<sp<IBinder>> removedOutputs;
1273 std::vector<sp<Surface>> newOutputs;
1274 std::vector<OutputStreamInfo> streamInfos;
1275 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1276 for (auto &it : bufferProducers) {
1277 newOutputsMap.add(IInterface::asBinder(it), it);
1278 }
1279
1280 for (size_t i = 0; i < mStreamMap.size(); i++) {
1281 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1282 if (idx == NAME_NOT_FOUND) {
1283 if (mStreamMap[i].streamId() == streamId) {
1284 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1285 removedOutputs.push_back(mStreamMap.keyAt(i));
1286 }
1287 } else {
1288 if (mStreamMap[i].streamId() != streamId) {
1289 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1290 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1291 "Target Surface is invalid");
1292 }
1293 newOutputsMap.removeItemsAt(idx);
1294 }
1295 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001296 const std::vector<int32_t> &sensorPixelModesUsed =
1297 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001298 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001299 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001300 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001301 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001302 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001303
Emilian Peev40ead602017-09-26 15:46:36 +01001304 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1305 OutputStreamInfo outInfo;
1306 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001307 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001308 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001309 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001310 streamUseCase, timestampBase, mirrorMode, colorSpace);
Emilian Peev40ead602017-09-26 15:46:36 +01001311 if (!res.isOk())
1312 return res;
1313
Emilian Peev40ead602017-09-26 15:46:36 +01001314 streamInfos.push_back(outInfo);
1315 newOutputs.push_back(surface);
1316 }
1317
1318 //Trivial case no changes required
1319 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1320 return binder::Status::ok();
1321 }
1322
1323 KeyedVector<sp<Surface>, size_t> outputMap;
1324 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1325 &outputMap);
1326 if (ret != OK) {
1327 switch (ret) {
1328 case NAME_NOT_FOUND:
1329 case BAD_VALUE:
1330 case -EBUSY:
1331 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1332 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001333 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001334 break;
1335 default:
1336 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1337 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001338 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001339 break;
1340 }
1341 } else {
1342 for (const auto &it : removedOutputs) {
1343 mStreamMap.removeItem(it);
1344 }
1345
1346 for (size_t i = 0; i < outputMap.size(); i++) {
1347 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1348 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1349 }
1350
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001351 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1352
Emilian Peev40ead602017-09-26 15:46:36 +01001353 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001354 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001355 }
1356
1357 return res;
1358}
1359
Igor Murashkine7ee7632013-06-11 18:10:18 -07001360// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001361binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1362 /*out*/
1363 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001364{
1365 ATRACE_CALL();
1366 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1367
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001368 binder::Status res;
1369 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001370
1371 Mutex::Autolock icl(mBinderSerializationLock);
1372
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001373 if (!mDevice.get()) {
1374 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1375 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001376
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001377 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001378 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
1379 if (!(res = mapRequestTemplate(templateId, &tempId)).isOk()) return res;
1380
1381 CameraMetadata metadata;
1382 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001383 request != NULL) {
1384
1385 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001386 } else if (err == BAD_VALUE) {
1387 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001388 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001389 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001390
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001391 } else {
1392 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001393 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001394 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001395 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001396 return res;
1397}
1398
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001399binder::Status CameraDeviceClient::getCameraInfo(
1400 /*out*/
1401 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001402{
1403 ATRACE_CALL();
1404 ALOGV("%s", __FUNCTION__);
1405
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001406 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001407
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001408 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001409
1410 Mutex::Autolock icl(mBinderSerializationLock);
1411
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001412 if (!mDevice.get()) {
1413 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1414 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001415
Igor Murashkin099b4572013-07-12 17:52:16 -07001416 if (info != NULL) {
1417 *info = mDevice->info(); // static camera metadata
1418 // TODO: merge with device-specific camera metadata
1419 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001420
1421 return res;
1422}
1423
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001424binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001425{
1426 ATRACE_CALL();
1427 ALOGV("%s", __FUNCTION__);
1428
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001429 binder::Status res;
1430 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001431
1432 Mutex::Autolock icl(mBinderSerializationLock);
1433
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001434 if (!mDevice.get()) {
1435 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1436 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001437
1438 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001439 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001440 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001441 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001442 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001443 mCameraIdStr.c_str());
1444 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1445 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001446 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001447 status_t err = mDevice->waitUntilDrained();
1448 if (err != OK) {
1449 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001450 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001451 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001452 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001453 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001454 return res;
1455}
1456
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001457binder::Status CameraDeviceClient::flush(
1458 /*out*/
1459 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001460 ATRACE_CALL();
1461 ALOGV("%s", __FUNCTION__);
1462
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001463 binder::Status res;
1464 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001465
1466 Mutex::Autolock icl(mBinderSerializationLock);
1467
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001468 if (!mDevice.get()) {
1469 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1470 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001471
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001472 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001473 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001474 status_t err = mDevice->flush(lastFrameNumber);
1475 if (err != OK) {
1476 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001477 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1478 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001479 }
1480 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001481}
1482
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001483binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001484 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001485 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001486
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001487 binder::Status res;
1488 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001489
1490 Mutex::Autolock icl(mBinderSerializationLock);
1491
1492 // Guard against trying to prepare non-created streams
1493 ssize_t index = NAME_NOT_FOUND;
1494 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001495 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001496 index = i;
1497 break;
1498 }
1499 }
1500
1501 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001502 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1503 "with that ID exists", mCameraIdStr.c_str(), streamId);
1504 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1505 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001506 }
1507
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001508 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1509 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001510 status_t err = mDevice->prepare(streamId);
1511 if (err == BAD_VALUE) {
1512 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001513 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001514 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001515 } else if (err != OK) {
1516 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001517 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001518 strerror(-err), err);
1519 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001520 return res;
1521}
1522
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001523binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001524 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001525 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001526
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001527 binder::Status res;
1528 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001529
1530 Mutex::Autolock icl(mBinderSerializationLock);
1531
1532 // Guard against trying to prepare non-created streams
1533 ssize_t index = NAME_NOT_FOUND;
1534 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001535 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001536 index = i;
1537 break;
1538 }
1539 }
1540
1541 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001542 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1543 "with that ID exists", mCameraIdStr.c_str(), streamId);
1544 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1545 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001546 }
1547
1548 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001549 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1550 mCameraIdStr.c_str(), maxCount);
1551 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1552 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001553 }
1554
1555 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1556 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001557 status_t err = mDevice->prepare(maxCount, streamId);
1558 if (err == BAD_VALUE) {
1559 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001560 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001561 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001562 } else if (err != OK) {
1563 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001564 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001565 strerror(-err), err);
1566 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001567
1568 return res;
1569}
1570
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001571binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001572 ATRACE_CALL();
1573 ALOGV("%s", __FUNCTION__);
1574
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001575 binder::Status res;
1576 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001577
1578 Mutex::Autolock icl(mBinderSerializationLock);
1579
1580 // Guard against trying to prepare non-created streams
1581 ssize_t index = NAME_NOT_FOUND;
1582 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001583 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001584 index = i;
1585 break;
1586 }
1587 }
1588
1589 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001590 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1591 "with that ID exists", mCameraIdStr.c_str(), streamId);
1592 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1593 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001594 }
1595
1596 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1597 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001598 status_t err = mDevice->tearDown(streamId);
1599 if (err == BAD_VALUE) {
1600 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001601 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001602 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001603 } else if (err != OK) {
1604 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001605 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001606 strerror(-err), err);
1607 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001608
1609 return res;
1610}
1611
Shuzhen Wang758c2152017-01-10 18:26:18 -08001612binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001613 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1614 ATRACE_CALL();
1615
1616 binder::Status res;
1617 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1618
1619 Mutex::Autolock icl(mBinderSerializationLock);
1620
Shuzhen Wang0129d522016-10-30 22:43:41 -07001621 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1622 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001623 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001624
Shuzhen Wang0129d522016-10-30 22:43:41 -07001625 if (bufferProducers.size() == 0) {
1626 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001627 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1628 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001629
Shuzhen Wang758c2152017-01-10 18:26:18 -08001630 // streamId should be in mStreamMap if this stream already has a surface attached
1631 // to it. Otherwise, it should be in mDeferredStreams.
1632 bool streamIdConfigured = false;
1633 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1634 for (size_t i = 0; i < mStreamMap.size(); i++) {
1635 if (mStreamMap.valueAt(i).streamId() == streamId) {
1636 streamIdConfigured = true;
1637 break;
1638 }
Zhijun He5d677d12016-05-29 16:52:39 -07001639 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001640 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1641 if (streamId == mDeferredStreams[i]) {
1642 deferredStreamIndex = i;
1643 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001644 }
1645
Shuzhen Wang758c2152017-01-10 18:26:18 -08001646 }
1647 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001648 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1649 "(ID %d)", mCameraIdStr.c_str(), streamId);
1650 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1651 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001652 }
1653
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001654 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001655 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1656 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1657 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1658 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001659 }
1660
Zhijun He5d677d12016-05-29 16:52:39 -07001661 if (!mDevice.get()) {
1662 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1663 }
1664
Shuzhen Wang758c2152017-01-10 18:26:18 -08001665 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001666 const std::vector<int32_t> &sensorPixelModesUsed =
1667 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001668 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001669 int32_t colorSpace = outputConfiguration.getColorSpace();
1670 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001671 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001672 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001673 for (auto& bufferProducer : bufferProducers) {
1674 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001675 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1676 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001677 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001678 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001679 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001680 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001681
1682 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001683 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001684 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001685 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001686 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001687
1688 if (!res.isOk())
1689 return res;
1690
1691 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001692 }
1693
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001694 // Gracefully handle case where finalizeOutputConfigurations is called
1695 // without any new surface.
1696 if (consumerSurfaces.size() == 0) {
1697 mStreamInfoMap[streamId].finalized = true;
1698 return res;
1699 }
1700
Zhijun He5d677d12016-05-29 16:52:39 -07001701 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001702 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001703 std::vector<int> consumerSurfaceIds;
1704 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001705 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001706 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1707 sp<IBinder> binder = IInterface::asBinder(
1708 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001709 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001710 binder.get(), streamId, consumerSurfaceIds[i]);
1711 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1712 }
1713 if (deferredStreamIndex != NAME_NOT_FOUND) {
1714 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001715 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001716 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001717 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001718 } else if (err == NO_INIT) {
1719 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001720 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001721 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001722 } else {
1723 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001724 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001725 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001726 }
1727
1728 return res;
1729}
1730
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001731binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001732 ATRACE_CALL();
1733 binder::Status res;
1734 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1735
1736 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001737 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1738 mCameraIdStr.c_str(), mode);
1739 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1740 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001741 }
1742
1743 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001744 BasicClient::setAudioRestriction(mode);
1745 return binder::Status::ok();
1746}
1747
1748binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1749 ATRACE_CALL();
1750 binder::Status res;
1751 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1752 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001753 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001754 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001755 }
1756 return binder::Status::ok();
1757}
1758
Ravneetaeb20dc2022-03-30 05:33:03 +00001759status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1760 return mDevice->setCameraServiceWatchdog(enabled);
1761}
1762
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001763status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop) {
1764 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1765
1766 return mDevice->setRotateAndCropAutoBehavior(
1767 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop));
1768}
1769
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001770status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1771 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1772
1773 return mDevice->setAutoframingAutoBehavior(
1774 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1775}
1776
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001777bool CameraDeviceClient::supportsCameraMute() {
1778 return mDevice->supportsCameraMute();
1779}
1780
1781status_t CameraDeviceClient::setCameraMute(bool enabled) {
1782 return mDevice->setCameraMute(enabled);
1783}
1784
Shuzhen Wang16610a62022-12-15 22:38:07 -08001785void CameraDeviceClient::setStreamUseCaseOverrides(
1786 const std::vector<int64_t>& useCaseOverrides) {
1787 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1788}
1789
1790void CameraDeviceClient::clearStreamUseCaseOverrides() {
1791 mDevice->clearStreamUseCaseOverrides();
1792}
1793
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001794bool CameraDeviceClient::supportsZoomOverride() {
1795 return mDevice->supportsZoomOverride();
1796}
1797
1798status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1799 return mDevice->setZoomOverride(zoomOverride);
1800}
1801
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001802binder::Status CameraDeviceClient::switchToOffline(
1803 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001804 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001805 /*out*/
1806 sp<hardware::camera2::ICameraOfflineSession>* session) {
1807 ATRACE_CALL();
1808
1809 binder::Status res;
1810 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1811
1812 Mutex::Autolock icl(mBinderSerializationLock);
1813
1814 if (!mDevice.get()) {
1815 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1816 }
1817
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001818 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001819 std::string msg = "Offline surfaces must not be empty";
1820 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1821 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001822 }
1823
1824 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001825 std::string msg = "Invalid offline session";
1826 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1827 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001828 }
1829
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001830 std::vector<int32_t> offlineStreamIds;
1831 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001832 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001833 for (const auto& streamId : offlineOutputIds) {
1834 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001835 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001836 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001837 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001838 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1839 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001840 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001841
1842 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001843 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001844 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001845 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1846 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001847 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001848
Emilian Peev2f5d6012022-01-19 16:16:50 -08001849 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001850 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001851 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001852 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001853 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001854 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001855 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001856 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001857 if (isCompositeStream) {
1858 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1859 if (compositeIdx == NAME_NOT_FOUND) {
1860 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1861 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1862 "Unknown composite stream");
1863 }
1864
1865 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1866 &offlineStreamIds);
1867 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1868 mCompositeStreamMap.valueAt(compositeIdx));
1869 break;
1870 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001871 }
1872
Emilian Peev4697b642019-11-19 17:11:14 -08001873 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001874 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001875 }
1876 }
1877
1878 sp<CameraOfflineSessionBase> offlineSession;
1879 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1880 if (ret != OK) {
1881 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1882 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001883 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001884 }
1885
Emilian Peevcc0b7952020-01-07 13:54:47 -08001886 sp<CameraOfflineSessionClient> offlineClient;
1887 if (offlineSession.get() != nullptr) {
1888 offlineClient = new CameraOfflineSessionClient(sCameraService,
1889 offlineSession, offlineCompositeStreamMap, cameraCb, mClientPackageName,
Emilian Peev8b64f282021-03-25 16:49:57 -07001890 mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation, mClientPid, mClientUid,
1891 mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001892 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1893 }
1894
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001895 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001896 // A successful offline session switch must reset the current camera client
1897 // and release any resources occupied by previously configured streams.
1898 mStreamMap.clear();
1899 mConfiguredOutputs.clear();
1900 mDeferredStreams.clear();
1901 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001902 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001903 mCompositeStreamMap.clear();
1904 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001905 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001906 // In case we failed to register the offline client, ensure that it still initialized
1907 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001908 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001909
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001910 switch(ret) {
1911 case BAD_VALUE:
1912 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1913 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1914 case TIMED_OUT:
1915 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1916 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1917 default:
1918 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1919 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1920 strerror(-ret), ret);
1921 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001922 }
1923
1924 *session = offlineClient;
1925
1926 return binder::Status::ok();
1927}
1928
Igor Murashkine7ee7632013-06-11 18:10:18 -07001929status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001930 return BasicClient::dump(fd, args);
1931}
1932
1933status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001934 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001935 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001936 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001937 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001938 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001939
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001940 dprintf(fd, " State:\n");
1941 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001942 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001943 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001944 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001945 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001946 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001947 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001948 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001949 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001950 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001951 mStreamMap.valueAt(i).streamId(),
1952 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001953 }
Zhijun He5d677d12016-05-29 16:52:39 -07001954 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001955 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001956 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001957 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001958 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001959 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001960 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001961 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001962 // TODO: print dynamic/request section from most recent requests
1963 mFrameProcessor->dump(fd, args);
1964
1965 return dumpDevice(fd, args);
1966}
1967
Austin Borger1c1bee02023-06-01 16:51:35 -07001968status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07001969 sp<CameraDeviceBase> device = mDevice;
1970 if (!device) {
1971 dprintf(out, " Device is detached.");
1972 return OK;
1973 }
1974 device->startWatchingTags(tags);
1975 return OK;
1976}
1977
1978status_t CameraDeviceClient::stopWatchingTags(int out) {
1979 sp<CameraDeviceBase> device = mDevice;
1980 if (!device) {
1981 dprintf(out, " Device is detached.");
1982 return OK;
1983 }
1984 device->stopWatchingTags();
1985 return OK;
1986}
1987
1988status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
1989 sp<CameraDeviceBase> device = mDevice;
1990 if (!device) {
1991 return OK;
1992 }
1993 device->dumpWatchedEventsToVector(out);
1994 return OK;
1995}
1996
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001997void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07001998 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07001999 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002000 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002001
Emilian Peev538c90e2018-12-17 18:03:19 +00002002 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002003 {
2004 // Access to the composite stream map must be synchronized
2005 Mutex::Autolock l(mCompositeLock);
2006 // Composites can have multiple internal streams. Error notifications coming from such
2007 // internal streams may need to remain within camera service.
2008 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2009 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2010 resultExtras);
2011 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002012 }
2013
2014 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002015 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002016 }
2017}
2018
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002019void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2020 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2021
2022 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002023 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002024 }
2025
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002026 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002027 mStreamingRequestId = REQUEST_ID_NONE;
2028}
2029
Shuzhen Wang316781a2020-08-18 18:11:01 -07002030void CameraDeviceClient::notifyIdle(
2031 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2032 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002033 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002034 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002035
2036 if (remoteCb != 0) {
2037 remoteCb->onDeviceIdle();
2038 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002039
2040 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2041 {
2042 Mutex::Autolock l(mCompositeLock);
2043 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2044 hardware::CameraStreamStats compositeStats;
2045 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2046 if (compositeStats.mWidth > 0) {
2047 fullStreamStats.push_back(compositeStats);
2048 }
2049 }
2050 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002051 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Emilian Peev567c31c2023-03-06 15:02:37 -08002052 fullStreamStats, mUserTag, mVideoStabilizationMode);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002053}
2054
Jianing Weicb0652e2014-03-12 18:29:36 -07002055void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002056 nsecs_t timestamp) {
2057 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002058 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002059 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002060 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002061 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002062 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002063
Emilian Peev2f5d6012022-01-19 16:16:50 -08002064 // Access to the composite stream map must be synchronized
2065 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002066 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2067 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2068 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002069}
2070
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002071void CameraDeviceClient::notifyPrepared(int streamId) {
2072 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002073 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002074 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002075 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002076 remoteCb->onPrepared(streamId);
2077 }
2078}
2079
Shuzhen Wang9d066012016-09-30 11:30:20 -07002080void CameraDeviceClient::notifyRequestQueueEmpty() {
2081 // Thread safe. Don't bother locking.
2082 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2083 if (remoteCb != 0) {
2084 remoteCb->onRequestQueueEmpty();
2085 }
2086}
2087
Igor Murashkine7ee7632013-06-11 18:10:18 -07002088void CameraDeviceClient::detachDevice() {
2089 if (mDevice == 0) return;
2090
Shuzhen Wang316781a2020-08-18 18:11:01 -07002091 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002092 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002093
Emilian Peev7ee731f2022-02-08 14:55:52 -08002094 if (mFrameProcessor.get() != nullptr) {
2095 mFrameProcessor->removeListener(
2096 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2097 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2098 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002099 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002100 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002101 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002102 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002103
2104 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2105 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002106 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002107 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002108 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2109 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2110 }
2111
Igor Murashkine7ee7632013-06-11 18:10:18 -07002112 if ((code = mDevice->waitUntilDrained()) != OK) {
2113 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2114 code);
2115 }
2116 }
2117
Emilian Peev2f5d6012022-01-19 16:16:50 -08002118 {
2119 Mutex::Autolock l(mCompositeLock);
2120 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2121 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2122 if (ret != OK) {
2123 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2124 strerror(-ret), ret);
2125 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002126 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002127 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002128 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002129
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002130 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002131 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002132
2133 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002134 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002135}
2136
2137/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002138void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002139 ATRACE_CALL();
2140 ALOGV("%s", __FUNCTION__);
2141
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002142 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002143 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002144 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002145 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2146 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002147 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002148
Emilian Peev2f5d6012022-01-19 16:16:50 -08002149 // Access to the composite stream map must be synchronized
2150 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002151 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2152 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2153 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002154}
2155
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002156binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002157 if (mDisconnected) {
2158 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2159 "The camera device has been disconnected");
2160 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002161 status_t res = checkPid(checkLocation);
2162 return (res == OK) ? binder::Status::ok() :
2163 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2164 "Attempt to use camera from a different process than original client");
2165}
2166
Igor Murashkine7ee7632013-06-11 18:10:18 -07002167// TODO: move to Camera2ClientBase
2168bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2169
Jayant Chowdhary12361932018-08-27 14:46:13 -07002170 const int pid = CameraThreadState::getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002171 const int selfPid = getpid();
2172 camera_metadata_entry_t entry;
2173
2174 /**
2175 * Mixin default important security values
2176 * - android.led.transmit = defaulted ON
2177 */
2178 CameraMetadata staticInfo = mDevice->info();
2179 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2180 for(size_t i = 0; i < entry.count; ++i) {
2181 uint8_t led = entry.data.u8[i];
2182
2183 switch(led) {
2184 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2185 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2186 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2187 metadata.update(ANDROID_LED_TRANSMIT,
2188 &transmitDefault, 1);
2189 }
2190 break;
2191 }
2192 }
2193 }
2194
2195 // We can do anything!
2196 if (pid == selfPid) {
2197 return true;
2198 }
2199
2200 /**
2201 * Permission check special fields in the request
2202 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2203 */
2204 entry = metadata.find(ANDROID_LED_TRANSMIT);
2205 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2206 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002207 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002208 if (!checkCallingPermission(permissionString)) {
Jayant Chowdhary12361932018-08-27 14:46:13 -07002209 const int uid = CameraThreadState::getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002210 ALOGE("Permission Denial: "
2211 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2212 return false;
2213 }
2214 }
2215
2216 return true;
2217}
2218
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002219status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2220 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002221 ALOGV("%s: begin", __FUNCTION__);
2222
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002223 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002224 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002225}
2226
Emilian Peevf4816702020-04-03 15:44:51 -07002227binder::Status CameraDeviceClient::mapRequestTemplate(int templateId,
2228 camera_request_template_t* tempId /*out*/) {
2229 binder::Status ret = binder::Status::ok();
2230
2231 if (tempId == nullptr) {
2232 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -07002233 "Camera %s: Invalid template argument", mCameraIdStr.c_str());
Emilian Peevf4816702020-04-03 15:44:51 -07002234 return ret;
2235 }
2236 switch(templateId) {
2237 case ICameraDeviceUser::TEMPLATE_PREVIEW:
2238 *tempId = camera_request_template_t::CAMERA_TEMPLATE_PREVIEW;
2239 break;
2240 case ICameraDeviceUser::TEMPLATE_RECORD:
2241 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_RECORD;
2242 break;
2243 case ICameraDeviceUser::TEMPLATE_STILL_CAPTURE:
2244 *tempId = camera_request_template_t::CAMERA_TEMPLATE_STILL_CAPTURE;
2245 break;
2246 case ICameraDeviceUser::TEMPLATE_VIDEO_SNAPSHOT:
2247 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_SNAPSHOT;
2248 break;
2249 case ICameraDeviceUser::TEMPLATE_ZERO_SHUTTER_LAG:
2250 *tempId = camera_request_template_t::CAMERA_TEMPLATE_ZERO_SHUTTER_LAG;
2251 break;
2252 case ICameraDeviceUser::TEMPLATE_MANUAL:
2253 *tempId = camera_request_template_t::CAMERA_TEMPLATE_MANUAL;
2254 break;
2255 default:
2256 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
2257 "Camera %s: Template ID %d is invalid or not supported",
Austin Borger1c1bee02023-06-01 16:51:35 -07002258 mCameraIdStr.c_str(), templateId);
Emilian Peevf4816702020-04-03 15:44:51 -07002259 return ret;
2260 }
2261
2262 return ret;
2263}
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002264
Austin Borger1c1bee02023-06-01 16:51:35 -07002265const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002266 if (mDevice->getId() == cameraId) {
2267 return mDevice->info();
2268 }
2269 return mDevice->infoPhysical(cameraId);
2270}
2271
Austin Borger1c1bee02023-06-01 16:51:35 -07002272bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002273 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002274 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002275}
2276
2277bool CameraDeviceClient::isSensorPixelModeConsistent(
2278 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2279 // First we get the sensorPixelMode from the settings metadata.
2280 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2281 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2282 if (sensorPixelModeEntry.count != 0) {
2283 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2284 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2285 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2286 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2287 __FUNCTION__, sensorPixelMode);
2288 return false;
2289 }
2290 }
2291 // Check whether each stream has max resolution allowed.
2292 bool consistent = true;
2293 for (auto it : streamIdList) {
2294 auto const streamInfoIt = mStreamInfoMap.find(it);
2295 if (streamInfoIt == mStreamInfoMap.end()) {
2296 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2297 return false;
2298 }
2299 consistent =
2300 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2301 streamInfoIt->second.sensorPixelModesUsed.end();
2302 if (!consistent) {
2303 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2304 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2305 ALOGE("sensor pixel mode used list: %i", m);
2306 }
2307 break;
2308 }
2309 }
2310
2311 return consistent;
2312}
2313
Igor Murashkine7ee7632013-06-11 18:10:18 -07002314} // namespace android