blob: 9513eeb7ac3f68a68c98d3567553fbca9203f59d [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 Talvala6f1a9c12023-09-14 17:26:28 -070021#include <com_android_internal_camera_flags.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070022#include <cutils/properties.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
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -070058namespace flags = com::android::internal::camera::flags;
59
Igor Murashkine7ee7632013-06-11 18:10:18 -070060CameraDeviceClientBase::CameraDeviceClientBase(
61 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080062 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger17e3ebe2024-02-14 15:02:11 -080063 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borger1c1bee02023-06-01 16:51:35 -070064 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080065 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070066 const std::optional<std::string>& clientFeatureId,
67 const std::string& cameraId,
Jing Mikec7f9b132023-03-12 11:12:04 +080068 [[maybe_unused]] int api1CameraId,
Igor Murashkine7ee7632013-06-11 18:10:18 -070069 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070070 int sensorOrientation,
Igor Murashkine7ee7632013-06-11 18:10:18 -070071 int clientPid,
72 uid_t clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070073 int servicePid,
74 bool overrideToPortrait) :
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080075 BasicClient(cameraService,
Marco Nelissenf8880202014-11-14 07:58:25 -080076 IInterface::asBinder(remoteCallback),
Austin Borger17e3ebe2024-02-14 15:02:11 -080077 attributionAndPermissionUtils,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080078 clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080079 systemNativeClient,
Philip P. Moltmann9e648f62019-11-04 12:52:45 -080080 clientFeatureId,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080081 cameraId,
82 cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070083 sensorOrientation,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080084 clientPid,
85 clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070086 servicePid,
87 overrideToPortrait),
Igor Murashkine7ee7632013-06-11 18:10:18 -070088 mRemoteCallback(remoteCallback) {
89}
Igor Murashkine7ee7632013-06-11 18:10:18 -070090
91// Interface used by CameraService
92
93CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080094 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070095 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger17e3ebe2024-02-14 15:02:11 -080096 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borger1c1bee02023-06-01 16:51:35 -070097 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080098 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070099 const std::optional<std::string>& clientFeatureId,
100 const std::string& cameraId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800101 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -0700102 int sensorOrientation,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800103 int clientPid,
104 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700105 int servicePid,
Austin Borger18b30a72022-10-27 12:20:29 -0700106 bool overrideForPerfClass,
malikakash73125c62023-07-21 22:44:34 +0000107 bool overrideToPortrait,
108 const std::string& originalCameraId) :
Austin Borger17e3ebe2024-02-14 15:02:11 -0800109 Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper,
110 attributionAndPermissionUtils, clientPackageName,
Austin Borger74fca042022-05-23 12:41:21 -0700111 systemNativeClient, clientFeatureId, cameraId, /*API1 camera ID*/ -1, cameraFacing,
Austin Borger18b30a72022-10-27 12:20:29 -0700112 sensorOrientation, clientPid, clientUid, servicePid, overrideForPerfClass,
113 overrideToPortrait),
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700114 mInputStream(),
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700115 mStreamingRequestId(REQUEST_ID_NONE),
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700116 mRequestIdCounter(0),
malikakash73125c62023-07-21 22:44:34 +0000117 mOverrideForPerfClass(overrideForPerfClass),
118 mOriginalCameraId(originalCameraId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700119 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -0700120 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700121}
122
Emilian Peevbd8c5032018-02-14 23:05:40 +0000123status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -0700124 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000125 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800126}
127
128template<typename TProviderPtr>
Austin Borger1c1bee02023-06-01 16:51:35 -0700129status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
130 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700131 ATRACE_CALL();
132 status_t res;
133
Emilian Peevbd8c5032018-02-14 23:05:40 +0000134 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700135 if (res != OK) {
136 return res;
137 }
138
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700139 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger1c1bee02023-06-01 16:51:35 -0700140 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
141 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700142 if (res != OK) {
143 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
144 __FUNCTION__, strerror(-res), res);
145 return res;
146 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700147
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800148 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
149 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800150 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700151 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700152
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800153 const CameraMetadata &deviceInfo = mDevice->info();
154 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000155 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
156 if (physicalKeysEntry.count > 0) {
157 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
158 physicalKeysEntry.data.i32,
159 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
160 }
161
Emilian Peev2295df72021-11-12 18:14:10 -0800162 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
163 mDynamicProfileMap.emplace(
164 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
165 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
166 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800167 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800168 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800169 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800170 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800171 if (entry.count > 0 || ((entry.count % 3) != 0)) {
172 int64_t standardBitmap =
173 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
174 for (size_t i = 0; i < entry.count; i += 3) {
175 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800176 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800177 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
178 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800179 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800180 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800181 }
182 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800183 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
184 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800185 }
186 }
Emilian Peevef715e22022-05-19 17:44:33 -0700187 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
188 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800189 } else {
190 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
191 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
192 }
193 }
194 }
195
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700196 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800197 // Cache physical camera ids corresponding to this device and also the high
198 // resolution sensors in this device + physical camera ids
Austin Borger1c1bee02023-06-01 16:51:35 -0700199 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800200 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700201 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800202 }
203 for (auto &physicalId : mPhysicalCameraIds) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700204 if (supportsUltraHighResolutionCapture(physicalId)) {
205 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800206 }
207 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700208 return OK;
209}
210
211CameraDeviceClient::~CameraDeviceClient() {
212}
213
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800214binder::Status CameraDeviceClient::submitRequest(
215 const hardware::camera2::CaptureRequest& request,
216 bool streaming,
217 /*out*/
218 hardware::camera2::utils::SubmitInfo *submitInfo) {
219 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
220 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700221}
222
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800223binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000224 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000225 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800226 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
227
Emilian Peev2f5d6012022-01-19 16:16:50 -0800228 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800229 // Trying to submit request with surface that wasn't created
230 if (idx == NAME_NOT_FOUND) {
231 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
232 " we have not called createStream on",
Austin Borger1c1bee02023-06-01 16:51:35 -0700233 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800234 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
235 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000236 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
237 != NAME_NOT_FOUND) {
238 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
239 currentStreamId);
240 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800241 }
242
243 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
244 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800245 outputStreamIds->push_back(streamSurfaceId.streamId());
246 }
247 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
248
249 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700250 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800251 streamSurfaceId.surfaceId());
252
Emilian Peevf873aa52018-01-26 14:58:28 +0000253 if (currentStreamId != nullptr) {
254 *currentStreamId = streamSurfaceId.streamId();
255 }
256
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800257 return binder::Status::ok();
258}
259
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800260static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
261 const Vector<int> &streamIdsForThisRequest) {
262 std::list<int> intersection;
263 for (auto &streamId : streamIdsForThisRequest) {
264 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
265 intersection.emplace_back(streamId);
266 }
267 }
268 return intersection;
269}
270
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800271binder::Status CameraDeviceClient::submitRequestList(
272 const std::vector<hardware::camera2::CaptureRequest>& requests,
273 bool streaming,
274 /*out*/
275 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700276 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700277 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700278
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800279 binder::Status res = binder::Status::ok();
280 status_t err;
281 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
282 return res;
283 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700284
285 Mutex::Autolock icl(mBinderSerializationLock);
286
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800287 if (!mDevice.get()) {
288 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
289 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700290
291 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800292 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700293 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800294 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700295 }
296
Emilian Peevaebbe412018-01-15 13:53:24 +0000297 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700298 std::list<const SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800299 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700300 uint32_t loopCounter = 0;
301
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800302 for (auto&& request: requests) {
303 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700304 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800305 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700306 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800307 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800308 "No input configured for camera %s but request is for reprocessing",
Austin Borger1c1bee02023-06-01 16:51:35 -0700309 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700310 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800311 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700312 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800313 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
314 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000315 } else if (request.mPhysicalCameraSettings.size() > 1) {
316 ALOGE("%s: Camera %s: reprocess requests not supported for "
317 "multiple physical cameras.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700318 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000319 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
320 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700321 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700322 }
323
Emilian Peevaebbe412018-01-15 13:53:24 +0000324 if (request.mPhysicalCameraSettings.empty()) {
325 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700326 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800327 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000328 "Request doesn't contain any settings");
329 }
330
331 //The first capture settings should always match the logical camera id
Austin Borger1c1bee02023-06-01 16:51:35 -0700332 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
malikakash73125c62023-07-21 22:44:34 +0000333 if (mDevice->getId() != logicalId && mOriginalCameraId != logicalId) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000334 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700335 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000336 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
337 "Invalid camera request settings");
338 }
339
Emilian Peevaebbe412018-01-15 13:53:24 +0000340 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800341 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger1c1bee02023-06-01 16:51:35 -0700342 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800343 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
344 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700345 }
346
Jianing Wei90e59c92014-03-12 18:29:36 -0700347 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700348 * Write in the output stream IDs and map from stream ID to surface ID
349 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700350 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700351 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700352 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000353 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800354 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800355 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800356 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800357 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700358
Emilian Peevf873aa52018-01-26 14:58:28 +0000359 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800360 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000361 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800362 if (!res.isOk()) {
363 return res;
364 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000365
366 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
367 if (index >= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700368 const std::string &requestedPhysicalId =
369 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
370 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800371 dynamicProfileBitmap |=
372 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000373 } else {
374 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
375 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700376 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800377 } else {
378 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
379 int streamId = request.mStreamIdxList.itemAt(i);
380 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700381
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800382 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
383 if (index < 0) {
384 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
385 " we have not called createStream on: stream %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700386 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800387 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
388 "Request targets Surface that is not part of current capture session");
389 }
390
391 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
392 if ((size_t)surfaceIdx >= gbps.size()) {
393 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
394 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700395 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800396 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
397 "Request targets Surface has invalid surface index");
398 }
399
Emilian Peevf873aa52018-01-26 14:58:28 +0000400 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800401 if (!res.isOk()) {
402 return res;
403 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000404
Austin Borger1c1bee02023-06-01 16:51:35 -0700405 const std::string &requestedPhysicalId =
406 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
407 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800408 dynamicProfileBitmap |=
409 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
410 }
411 }
412
413 if (dynamicProfileBitmap !=
414 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
415 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
416 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
417 if ((dynamicProfileBitmap & i) == 0) {
418 continue;
419 }
420
421 const auto& it = mDynamicProfileMap.find(i);
422 if (it != mDynamicProfileMap.end()) {
423 if ((it->second == 0) ||
424 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
425 continue;
426 } else {
427 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
428 " reference an unsupported dynamic range profile combination"
Austin Borger1c1bee02023-06-01 16:51:35 -0700429 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800430 dynamicProfileBitmap);
431 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
432 "Request targets an unsupported dynamic range profile"
433 " combination");
434 }
435 } else {
436 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
437 " references unsupported dynamic range profile 0x%x!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700438 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800439 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
440 "Request targets 10-bit Surface with unsupported dynamic range"
441 " profile");
442 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700443 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700444 }
445
Emilian Peevf873aa52018-01-26 14:58:28 +0000446 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
447 for (const auto& it : request.mPhysicalCameraSettings) {
malikakash73125c62023-07-21 22:44:34 +0000448 const std::string resolvedId = (mOriginalCameraId == it.id) ? mDevice->getId() : it.id;
Emilian Peev00420d22018-02-05 21:33:13 +0000449 if (it.settings.isEmpty()) {
450 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700451 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000452 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
453 "Request settings are empty");
454 }
455
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800456 // Check whether the physical / logical stream has settings
457 // consistent with the sensor pixel mode(s) it was configured with.
458 // mCameraIdToStreamSet will only have ids that are high resolution
malikakash73125c62023-07-21 22:44:34 +0000459 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(resolvedId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800460 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
461 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
462 outputStreamIds);
463 if (!request.mIsReprocess &&
464 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
465 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
466 "consistent with configured streams. Rejecting request.",
malikakash73125c62023-07-21 22:44:34 +0000467 __FUNCTION__, resolvedId.c_str());
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800468 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
469 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
470 "streams configured");
471 }
472 }
473
malikakash73125c62023-07-21 22:44:34 +0000474 const std::string &physicalId = resolvedId;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700475 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
476 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
477 mSupportedPhysicalRequestKeys.end();
478 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
479 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
480 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000481 if (physicalId != mDevice->getId()) {
482 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
malikakash73125c62023-07-21 22:44:34 +0000483 resolvedId);
Emilian Peevf873aa52018-01-26 14:58:28 +0000484 if (found == requestedPhysicalIds.end()) {
485 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700486 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000487 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
488 "Invalid physical camera id");
489 }
Emilian Peev00420d22018-02-05 21:33:13 +0000490
491 if (!mSupportedPhysicalRequestKeys.empty()) {
492 // Filter out any unsupported physical request keys.
493 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
494 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
495 filteredParams.getAndLock());
496 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
497 filteredParams.unlock(meta);
498
499 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
500 camera_metadata_ro_entry entry = it.settings.find(keyIt);
501 if (entry.count > 0) {
502 filteredParams.update(entry);
503 }
504 }
505
malikakash73125c62023-07-21 22:44:34 +0000506 physicalSettingsList.push_back({resolvedId, filteredParams,
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700507 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000508 }
509 } else {
malikakash73125c62023-07-21 22:44:34 +0000510 physicalSettingsList.push_back({resolvedId, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000511 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000512 }
513
514 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
515 // Callee logs
516 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
517 "Caller does not have permission to change restricted controls");
518 }
519
Emilian Peevaebbe412018-01-15 13:53:24 +0000520 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
521 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700522
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800523 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000524 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
525 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700526 }
527
Emilian Peevaebbe412018-01-15 13:53:24 +0000528 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
529 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700530 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800531 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700532 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800533 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700534
Emilian Peevaebbe412018-01-15 13:53:24 +0000535 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700536 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800537
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700538 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800539 if (!request.mUserTag.empty()) {
540 mUserTag = request.mUserTag;
541 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700542 camera_metadata_entry entry =
543 physicalSettingsList.begin()->metadata.find(
544 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
545 if (entry.count == 1) {
546 mVideoStabilizationMode = entry.data.u8[0];
547 }
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -0700548 if (flags::log_ultrawide_usage()) {
549 entry = physicalSettingsList.begin()->metadata.find(
550 ANDROID_CONTROL_ZOOM_RATIO);
551 if (entry.count == 1 && entry.data.f[0] < 1.0f ) {
552 mUsedUltraWide = true;
553 }
554 }
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000555 if (!mUsedSettingsOverrideZoom && flags::log_zoom_override_usage()) {
556 entry = physicalSettingsList.begin()->metadata.find(
557 ANDROID_CONTROL_SETTINGS_OVERRIDE);
558 if (entry.count == 1 && entry.data.i32[0] ==
559 ANDROID_CONTROL_SETTINGS_OVERRIDE_ZOOM) {
560 mUsedSettingsOverrideZoom = true;
561 }
562 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700563 }
564 mRequestIdCounter++;
565
566 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700567 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
568 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800569 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700570 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800571 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700572 mCameraIdStr.c_str(), strerror(-err), err);
573 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800574 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700575 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700576 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700577 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700578 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700579 }
580 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700581 err = mDevice->captureList(metadataRequestList, surfaceMapList,
582 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800583 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700584 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800585 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700586 mCameraIdStr.c_str(), strerror(-err), err);
587 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800588 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700589 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700590 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800591 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700592 }
593
Austin Borger1c1bee02023-06-01 16:51:35 -0700594 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700595 return res;
596}
597
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800598binder::Status CameraDeviceClient::cancelRequest(
599 int requestId,
600 /*out*/
601 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700602 ATRACE_CALL();
603 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
604
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800605 status_t err;
606 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700607
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800608 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700609
610 Mutex::Autolock icl(mBinderSerializationLock);
611
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800612 if (!mDevice.get()) {
613 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
614 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700615
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700616 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700617 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700618 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
619 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
620 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
621 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700622 }
623
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800624 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700625
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800626 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800627 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700628 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700629 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800630 } else {
631 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800632 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700633 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700634 }
635
636 return res;
637}
638
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800639binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700640 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700641 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700642 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800643 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700644}
645
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100646binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700647 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800648 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700649 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700650 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
651 __FUNCTION__, mInputStream.configured ? 1 : 0,
652 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700653
Zhijun He0effd522016-03-04 10:22:27 -0800654 binder::Status res;
655 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
656
Emilian Peevcc0b7952020-01-07 13:54:47 -0800657 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700658 std::string msg = "Invalid offline stream ids";
659 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
660 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800661 }
662
Zhijun He0effd522016-03-04 10:22:27 -0800663 Mutex::Autolock icl(mBinderSerializationLock);
664
665 if (!mDevice.get()) {
666 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
667 }
668
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700669 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000670 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000671 if (!res.isOk()) {
672 return res;
673 }
674
675 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
676 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700677 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
678 mCameraIdStr.c_str());
679 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
680 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000681 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700682 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
683 mCameraIdStr.c_str(), strerror(-err), err);
684 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
685 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000686 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800687 offlineStreamIds->clear();
688 mDevice->getOfflineStreamIds(offlineStreamIds);
689
Emilian Peev2f5d6012022-01-19 16:16:50 -0800690 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000691 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
692 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800693 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700694 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
695 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
696 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
697 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000698 break;
699 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800700
701 // Composite streams can only support offline mode in case all individual internal
702 // streams are also supported.
703 std::vector<int> internalStreams;
704 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800705 offlineStreamIds->erase(
706 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800707 [&internalStreams] (int streamId) {
708 auto it = std::find(internalStreams.begin(), internalStreams.end(),
709 streamId);
710 if (it != internalStreams.end()) {
711 internalStreams.erase(it);
712 return true;
713 }
714
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800715 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800716 if (internalStreams.empty()) {
717 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
718 }
719 }
720
721 for (const auto& offlineStreamId : *offlineStreamIds) {
722 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000723 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700724
725 nsecs_t configureEnd = systemTime();
726 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700727 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700728 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000729 }
730
731 return res;
732}
733
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800734binder::Status CameraDeviceClient::isSessionConfigurationSupported(
735 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800736
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800737 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800738 binder::Status res;
739 status_t ret = OK;
740 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
741
742 Mutex::Autolock icl(mBinderSerializationLock);
743
744 if (!mDevice.get()) {
745 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
746 }
747
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800748 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700749 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
750 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
751 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800752 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700753
Emilian Peev35ae8262018-11-08 13:11:32 +0000754 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700755 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700756 sessionConfiguration, mOverrideForPerfClass, /*checkSessionParams*/false,
757 status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000758 switch (ret) {
759 case OK:
760 // Expected, do nothing.
761 break;
762 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700763 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000764 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700765 mCameraIdStr.c_str());
766 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
767 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000768 }
769
770 break;
771 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700772 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000773 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700774 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000775 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700776 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000777 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800778 }
779
780 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700781}
782
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800783binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700784 ATRACE_CALL();
785 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
786
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800787 binder::Status res;
788 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700789
790 Mutex::Autolock icl(mBinderSerializationLock);
791
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800792 if (!mDevice.get()) {
793 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
794 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700795
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700796 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700797 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700798 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000799 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700800
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700801 if (mInputStream.configured && mInputStream.id == streamId) {
802 isInput = true;
803 } else {
804 // Guard against trying to delete non-created streams
805 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700806 if (streamId == mStreamMap.valueAt(i).streamId()) {
807 surfaces.push_back(mStreamMap.keyAt(i));
808 }
809 }
810
811 // See if this stream is one of the deferred streams.
812 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
813 if (streamId == mDeferredStreams[i]) {
814 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700815 break;
816 }
817 }
818
Emilian Peev2f5d6012022-01-19 16:16:50 -0800819 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000820 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
821 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
822 compositeIndex = i;
823 break;
824 }
825 }
826
Shuzhen Wang0129d522016-10-30 22:43:41 -0700827 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700828 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
829 " stream created yet", mCameraIdStr.c_str(), streamId);
830 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
831 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700832 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700833 }
834
835 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800836 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700837
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800838 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700839 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
840 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
841 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
842 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800843 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700844 if (isInput) {
845 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700846 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700847 for (auto& surface : surfaces) {
848 mStreamMap.removeItem(surface);
849 }
850
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800851 mConfiguredOutputs.removeItem(streamId);
852
Shuzhen Wang0129d522016-10-30 22:43:41 -0700853 if (dIndex != NAME_NOT_FOUND) {
854 mDeferredStreams.removeItemsAt(dIndex);
855 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000856
857 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800858 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000859 status_t ret;
860 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
861 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700862 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
863 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
864 err, streamId);
865 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
866 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000867 }
868 mCompositeStreamMap.removeItemsAt(compositeIndex);
869 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800870 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
871 auto &streamSet = mapIt.second;
872 if (streamSet.find(streamId) != streamSet.end()) {
873 streamSet.erase(streamId);
874 break;
875 }
876 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700877 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700878 }
879
880 return res;
881}
882
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800883binder::Status CameraDeviceClient::createStream(
884 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
885 /*out*/
886 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700887 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700888
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800889 binder::Status res;
890 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700891
892 Mutex::Autolock icl(mBinderSerializationLock);
893
Shuzhen Wang0709c282024-02-12 09:09:32 -0800894 if (!outputConfiguration.isComplete()) {
895 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
896 "OutputConfiguration isn't valid!");
897 }
898
Shuzhen Wang0129d522016-10-30 22:43:41 -0700899 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
900 outputConfiguration.getGraphicBufferProducers();
901 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800902 bool deferredConsumer = outputConfiguration.isDeferred();
903 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700904 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800905 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800906 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800907 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800908 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800909 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800910 int mirrorMode = outputConfiguration.getMirrorMode();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700911 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000912 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700913
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700914 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Shuzhen Wang0709c282024-02-12 09:09:32 -0800915 outputConfiguration.getSurfaceType(), /*isConfigurationComplete*/true);
Emilian Peev35ae8262018-11-08 13:11:32 +0000916 if (!res.isOk()) {
917 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700918 }
Zhijun He5d677d12016-05-29 16:52:39 -0700919
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800920 if (!mDevice.get()) {
921 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
922 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700923 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800924 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000925 if (!res.isOk()) {
926 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800927 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000928
Shuzhen Wang0129d522016-10-30 22:43:41 -0700929 std::vector<sp<Surface>> surfaces;
930 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700931 status_t err;
932
933 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700934 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800935 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700936 }
937
Shuzhen Wang758c2152017-01-10 18:26:18 -0800938 OutputStreamInfo streamInfo;
939 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800940 const std::vector<int32_t> &sensorPixelModesUsed =
941 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700942 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700943 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700944 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800945 ssize_t index = mStreamMap.indexOfKey(binder);
946 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700947 std::string msg = std::string("Camera ") + mCameraIdStr
948 + ": Surface already has a stream created for it (ID "
949 + std::to_string(index) + ")";
950 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
951 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700952 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700953
Shuzhen Wang758c2152017-01-10 18:26:18 -0800954 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700955 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800956 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800957 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Shuzhen Wang0709c282024-02-12 09:09:32 -0800958 streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800959
960 if (!res.isOk())
961 return res;
962
963 if (!isStreamInfoValid) {
964 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700965 }
966
Shuzhen Wang758c2152017-01-10 18:26:18 -0800967 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang0129d522016-10-30 22:43:41 -0700968 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -0800969 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700970
971 // If mOverrideForPerfClass is true, do not fail createStream() for small
972 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
973 // closest possible supported size.
974
Zhijun He125684a2015-12-26 15:07:30 -0800975 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100976 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800977 bool isDepthCompositeStream =
978 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0]);
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800979 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(surfaces[0]);
Emilian Peev434248e2022-10-06 14:58:54 -0700980 bool isJpegRCompositeStream =
Emilian Peeve579d8b2023-02-28 14:16:08 -0800981 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0]) &&
Emilian Peev15230142023-04-27 20:22:54 +0000982 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800983 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800984 sp<CompositeStream> compositeStream;
985 if (isDepthCompositeStream) {
986 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800987 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800988 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -0700989 } else {
990 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800991 }
992
Emilian Peev538c90e2018-12-17 18:03:19 +0000993 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
994 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -0700995 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800996 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -0700997 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000998 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
999 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001000 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -08001001 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00001002 mCompositeStreamMap.add(IInterface::asBinder(surfaces[0]->getIGraphicBufferProducer()),
1003 compositeStream);
1004 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08001005 } else {
1006 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
1007 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001008 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001009 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -08001010 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -08001011 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001012 streamInfo.timestampBase, streamInfo.mirrorMode, streamInfo.colorSpace,
1013 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001014 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001015
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001016 if (err != OK) {
1017 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001018 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001019 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Henri Chataingbcb99452023-11-01 17:40:30 +00001020 static_cast<int>(streamInfo.dataSpace), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001021 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001022 int i = 0;
1023 for (auto& binder : binders) {
1024 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1025 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001026 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1027 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001028 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001029
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001030 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001031 mStreamInfoMap[streamId] = streamInfo;
1032
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001033 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001034 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001035 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001036 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001037
Zhijun He5d677d12016-05-29 16:52:39 -07001038 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001039 res = setStreamTransformLocked(streamId, streamInfo.mirrorMode);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001040
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001041 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001042 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001043 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001044 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001045 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001046 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001047 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001048 }
1049
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001050 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001051 }
1052
1053 return res;
1054}
1055
Zhijun He5d677d12016-05-29 16:52:39 -07001056binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1057 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001058 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001059 /*out*/
1060 int* newStreamId) {
1061 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001062 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001063 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001064 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001065 status_t err;
1066 binder::Status res;
1067
1068 if (!mDevice.get()) {
1069 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1070 }
Shuzhen Wang0709c282024-02-12 09:09:32 -08001071 if (!outputConfiguration.isComplete()) {
1072 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1073 "OutputConfiguration isn't valid!");
1074 }
Zhijun He5d677d12016-05-29 16:52:39 -07001075
1076 // Infer the surface info for deferred surface stream creation.
1077 width = outputConfiguration.getWidth();
1078 height = outputConfiguration.getHeight();
1079 surfaceType = outputConfiguration.getSurfaceType();
1080 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1081 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001082 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001083 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1084 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1085 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1086 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1087 }
1088 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001089 std::vector<sp<Surface>> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001090 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001091 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1092 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001093 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1094 // Here, we override sensor pixel modes
1095 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1096 const std::vector<int32_t> &sensorPixelModesUsed =
1097 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001098 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001099 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001100 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001101 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1102 "sensor pixel modes used not valid for deferred stream");
1103 }
1104
Shuzhen Wang0129d522016-10-30 22:43:41 -07001105 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1106 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001107 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001108 &streamId, physicalCameraId,
1109 overriddenSensorPixelModesUsed,
1110 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001111 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001112 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001113 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001114 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001115 outputConfiguration.getMirrorMode(),
1116 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001117
1118 if (err != OK) {
1119 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001120 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Henri Chataingbcb99452023-11-01 17:40:30 +00001121 mCameraIdStr.c_str(), width, height, format, static_cast<int>(dataSpace),
1122 strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001123 } else {
1124 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1125 // a separate list to track. Once the deferred surface is set, this id will be
1126 // relocated to mStreamMap.
1127 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001128 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001129 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001130 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001131 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001132 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001133 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001134 outputConfiguration.getMirrorMode(),
1135 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001136
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001137 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001138 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001139 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001140
1141 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001142 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001143
1144 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001145 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001146 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001147 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001148 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001149 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001150 }
Zhijun He5d677d12016-05-29 16:52:39 -07001151 }
1152 return res;
1153}
1154
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001155binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001156 int32_t transform = 0;
1157 status_t err;
1158 binder::Status res;
1159
1160 if (!mDevice.get()) {
1161 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1162 }
1163
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001164 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001165 if (err != OK) {
1166 // Error logged by getRotationTransformLocked.
1167 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1168 "Unable to calculate rotation transform for new stream");
1169 }
1170
1171 err = mDevice->setStreamTransform(streamId, transform);
1172 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001173 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001174 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001175 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1176 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001177 }
1178
1179 return res;
1180}
Ruben Brunkbba75572014-11-20 17:29:50 -08001181
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001182binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001183 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001184 /*out*/
1185 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001186
1187 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001188 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1189 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001190
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001191 binder::Status res;
1192 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001193
1194 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001195
1196 if (!mDevice.get()) {
1197 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1198 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001199
1200 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001201 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1202 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1203 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1204 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001205 }
1206
1207 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001208 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001209 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001210 mInputStream.configured = true;
1211 mInputStream.width = width;
1212 mInputStream.height = height;
1213 mInputStream.format = format;
1214 mInputStream.id = streamId;
1215
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001216 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001217 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001218
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001219 *newStreamId = streamId;
1220 } else {
1221 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001222 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001223 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001224 }
1225
1226 return res;
1227}
1228
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001229binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001230
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001231 binder::Status res;
1232 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1233
1234 if (inputSurface == NULL) {
1235 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001236 }
1237
1238 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001239 if (!mDevice.get()) {
1240 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1241 }
1242 sp<IGraphicBufferProducer> producer;
1243 status_t err = mDevice->getInputBufferProducer(&producer);
1244 if (err != OK) {
1245 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001246 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001247 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001248 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001249 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001250 inputSurface->graphicBufferProducer = producer;
1251 }
1252 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001253}
1254
Emilian Peev40ead602017-09-26 15:46:36 +01001255binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1256 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1257 ATRACE_CALL();
1258
1259 binder::Status res;
1260 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1261
1262 Mutex::Autolock icl(mBinderSerializationLock);
1263
1264 if (!mDevice.get()) {
1265 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1266 }
Shuzhen Wang0709c282024-02-12 09:09:32 -08001267 if (!outputConfiguration.isComplete()) {
1268 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1269 "OutputConfiguration isn't valid!");
1270 }
Emilian Peev40ead602017-09-26 15:46:36 +01001271
1272 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1273 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001274 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001275
Emilian Peev40ead602017-09-26 15:46:36 +01001276 auto producerCount = bufferProducers.size();
1277 if (producerCount == 0) {
1278 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1279 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1280 "bufferProducers must not be empty");
1281 }
1282
1283 // The first output is the one associated with the output configuration.
1284 // It should always be present, valid and the corresponding stream id should match.
1285 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1286 ssize_t index = mStreamMap.indexOfKey(binder);
1287 if (index == NAME_NOT_FOUND) {
1288 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1289 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1290 "OutputConfiguration is invalid");
1291 }
1292 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1293 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1294 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1295 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1296 "Stream id is invalid");
1297 }
1298
1299 std::vector<size_t> removedSurfaceIds;
1300 std::vector<sp<IBinder>> removedOutputs;
1301 std::vector<sp<Surface>> newOutputs;
1302 std::vector<OutputStreamInfo> streamInfos;
1303 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1304 for (auto &it : bufferProducers) {
1305 newOutputsMap.add(IInterface::asBinder(it), it);
1306 }
1307
1308 for (size_t i = 0; i < mStreamMap.size(); i++) {
1309 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1310 if (idx == NAME_NOT_FOUND) {
1311 if (mStreamMap[i].streamId() == streamId) {
1312 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1313 removedOutputs.push_back(mStreamMap.keyAt(i));
1314 }
1315 } else {
1316 if (mStreamMap[i].streamId() != streamId) {
1317 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1318 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1319 "Target Surface is invalid");
1320 }
1321 newOutputsMap.removeItemsAt(idx);
1322 }
1323 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001324 const std::vector<int32_t> &sensorPixelModesUsed =
1325 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001326 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001327 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001328 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001329 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001330 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001331
Emilian Peev40ead602017-09-26 15:46:36 +01001332 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1333 OutputStreamInfo outInfo;
1334 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001335 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001336 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001337 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Shuzhen Wang0709c282024-02-12 09:09:32 -08001338 streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
Emilian Peev40ead602017-09-26 15:46:36 +01001339 if (!res.isOk())
1340 return res;
1341
Emilian Peev40ead602017-09-26 15:46:36 +01001342 streamInfos.push_back(outInfo);
1343 newOutputs.push_back(surface);
1344 }
1345
1346 //Trivial case no changes required
1347 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1348 return binder::Status::ok();
1349 }
1350
1351 KeyedVector<sp<Surface>, size_t> outputMap;
1352 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1353 &outputMap);
1354 if (ret != OK) {
1355 switch (ret) {
1356 case NAME_NOT_FOUND:
1357 case BAD_VALUE:
1358 case -EBUSY:
1359 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1360 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001361 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001362 break;
1363 default:
1364 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1365 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001366 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001367 break;
1368 }
1369 } else {
1370 for (const auto &it : removedOutputs) {
1371 mStreamMap.removeItem(it);
1372 }
1373
1374 for (size_t i = 0; i < outputMap.size(); i++) {
1375 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1376 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1377 }
1378
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001379 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1380
Emilian Peev40ead602017-09-26 15:46:36 +01001381 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001382 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001383 }
1384
1385 return res;
1386}
1387
Igor Murashkine7ee7632013-06-11 18:10:18 -07001388// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001389binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1390 /*out*/
1391 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001392{
1393 ATRACE_CALL();
1394 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1395
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001396 binder::Status res;
1397 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001398
1399 Mutex::Autolock icl(mBinderSerializationLock);
1400
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001401 if (!mDevice.get()) {
1402 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1403 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001404
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001405 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001406 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
Shuzhen Wang045be6c2023-10-12 10:01:10 -07001407 res = SessionConfigurationUtils::mapRequestTemplateFromClient(
1408 mCameraIdStr, templateId, &tempId);
1409 if (!res.isOk()) return res;
Emilian Peevf4816702020-04-03 15:44:51 -07001410
1411 CameraMetadata metadata;
1412 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001413 request != NULL) {
1414
1415 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001416 } else if (err == BAD_VALUE) {
1417 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001418 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001419 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001420
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001421 } else {
1422 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001423 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001424 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001425 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001426 return res;
1427}
1428
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001429binder::Status CameraDeviceClient::getCameraInfo(
1430 /*out*/
1431 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001432{
1433 ATRACE_CALL();
1434 ALOGV("%s", __FUNCTION__);
1435
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001436 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001437
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001438 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001439
1440 Mutex::Autolock icl(mBinderSerializationLock);
1441
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001442 if (!mDevice.get()) {
1443 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1444 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001445
Igor Murashkin099b4572013-07-12 17:52:16 -07001446 if (info != NULL) {
1447 *info = mDevice->info(); // static camera metadata
1448 // TODO: merge with device-specific camera metadata
1449 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001450
1451 return res;
1452}
1453
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001454binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001455{
1456 ATRACE_CALL();
1457 ALOGV("%s", __FUNCTION__);
1458
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001459 binder::Status res;
1460 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001461
1462 Mutex::Autolock icl(mBinderSerializationLock);
1463
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001464 if (!mDevice.get()) {
1465 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1466 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001467
1468 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001469 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001470 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001471 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001472 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001473 mCameraIdStr.c_str());
1474 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1475 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001476 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001477 status_t err = mDevice->waitUntilDrained();
1478 if (err != OK) {
1479 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001480 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001481 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001482 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001483 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001484 return res;
1485}
1486
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001487binder::Status CameraDeviceClient::flush(
1488 /*out*/
1489 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001490 ATRACE_CALL();
1491 ALOGV("%s", __FUNCTION__);
1492
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001493 binder::Status res;
1494 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001495
1496 Mutex::Autolock icl(mBinderSerializationLock);
1497
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001498 if (!mDevice.get()) {
1499 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1500 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001501
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001502 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001503 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001504 status_t err = mDevice->flush(lastFrameNumber);
1505 if (err != OK) {
1506 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001507 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1508 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001509 }
1510 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001511}
1512
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001513binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001514 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001515 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001516
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001517 binder::Status res;
1518 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001519
1520 Mutex::Autolock icl(mBinderSerializationLock);
1521
1522 // Guard against trying to prepare non-created streams
1523 ssize_t index = NAME_NOT_FOUND;
1524 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001525 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001526 index = i;
1527 break;
1528 }
1529 }
1530
1531 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001532 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1533 "with that ID exists", mCameraIdStr.c_str(), streamId);
1534 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1535 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001536 }
1537
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001538 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1539 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001540 status_t err = mDevice->prepare(streamId);
1541 if (err == BAD_VALUE) {
1542 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001543 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001544 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001545 } else if (err != OK) {
1546 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001547 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001548 strerror(-err), err);
1549 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001550 return res;
1551}
1552
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001553binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001554 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001555 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001556
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001557 binder::Status res;
1558 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001559
1560 Mutex::Autolock icl(mBinderSerializationLock);
1561
1562 // Guard against trying to prepare non-created streams
1563 ssize_t index = NAME_NOT_FOUND;
1564 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001565 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001566 index = i;
1567 break;
1568 }
1569 }
1570
1571 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001572 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1573 "with that ID exists", mCameraIdStr.c_str(), streamId);
1574 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1575 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001576 }
1577
1578 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001579 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1580 mCameraIdStr.c_str(), maxCount);
1581 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1582 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001583 }
1584
1585 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1586 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001587 status_t err = mDevice->prepare(maxCount, streamId);
1588 if (err == BAD_VALUE) {
1589 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001590 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001591 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001592 } else if (err != OK) {
1593 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001594 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001595 strerror(-err), err);
1596 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001597
1598 return res;
1599}
1600
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001601binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001602 ATRACE_CALL();
1603 ALOGV("%s", __FUNCTION__);
1604
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001605 binder::Status res;
1606 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001607
1608 Mutex::Autolock icl(mBinderSerializationLock);
1609
1610 // Guard against trying to prepare non-created streams
1611 ssize_t index = NAME_NOT_FOUND;
1612 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001613 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001614 index = i;
1615 break;
1616 }
1617 }
1618
1619 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001620 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1621 "with that ID exists", mCameraIdStr.c_str(), streamId);
1622 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1623 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001624 }
1625
1626 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1627 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001628 status_t err = mDevice->tearDown(streamId);
1629 if (err == BAD_VALUE) {
1630 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001631 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001632 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001633 } else if (err != OK) {
1634 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001635 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001636 strerror(-err), err);
1637 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001638
1639 return res;
1640}
1641
Shuzhen Wang758c2152017-01-10 18:26:18 -08001642binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001643 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1644 ATRACE_CALL();
1645
1646 binder::Status res;
1647 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1648
1649 Mutex::Autolock icl(mBinderSerializationLock);
1650
Shuzhen Wang0709c282024-02-12 09:09:32 -08001651 if (!outputConfiguration.isComplete()) {
1652 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1653 "OutputConfiguration isn't valid!");
1654 }
1655
Shuzhen Wang0129d522016-10-30 22:43:41 -07001656 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1657 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001658 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001659
Shuzhen Wang0129d522016-10-30 22:43:41 -07001660 if (bufferProducers.size() == 0) {
1661 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001662 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1663 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001664
Shuzhen Wang758c2152017-01-10 18:26:18 -08001665 // streamId should be in mStreamMap if this stream already has a surface attached
1666 // to it. Otherwise, it should be in mDeferredStreams.
1667 bool streamIdConfigured = false;
1668 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1669 for (size_t i = 0; i < mStreamMap.size(); i++) {
1670 if (mStreamMap.valueAt(i).streamId() == streamId) {
1671 streamIdConfigured = true;
1672 break;
1673 }
Zhijun He5d677d12016-05-29 16:52:39 -07001674 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001675 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1676 if (streamId == mDeferredStreams[i]) {
1677 deferredStreamIndex = i;
1678 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001679 }
1680
Shuzhen Wang758c2152017-01-10 18:26:18 -08001681 }
1682 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001683 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1684 "(ID %d)", mCameraIdStr.c_str(), streamId);
1685 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1686 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001687 }
1688
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001689 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001690 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1691 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1692 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1693 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001694 }
1695
Zhijun He5d677d12016-05-29 16:52:39 -07001696 if (!mDevice.get()) {
1697 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1698 }
1699
Shuzhen Wang758c2152017-01-10 18:26:18 -08001700 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001701 const std::vector<int32_t> &sensorPixelModesUsed =
1702 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001703 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001704 int32_t colorSpace = outputConfiguration.getColorSpace();
1705 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001706 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001707 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001708 for (auto& bufferProducer : bufferProducers) {
1709 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001710 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1711 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001712 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001713 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001714 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001715 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001716
1717 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001718 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001719 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001720 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Shuzhen Wang0709c282024-02-12 09:09:32 -08001721 streamUseCase, timestampBase, mirrorMode, colorSpace, /*respectSurfaceSize*/false);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001722
1723 if (!res.isOk())
1724 return res;
1725
1726 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001727 }
1728
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001729 // Gracefully handle case where finalizeOutputConfigurations is called
1730 // without any new surface.
1731 if (consumerSurfaces.size() == 0) {
1732 mStreamInfoMap[streamId].finalized = true;
1733 return res;
1734 }
1735
Zhijun He5d677d12016-05-29 16:52:39 -07001736 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001737 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001738 std::vector<int> consumerSurfaceIds;
1739 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001740 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001741 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1742 sp<IBinder> binder = IInterface::asBinder(
1743 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001744 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001745 binder.get(), streamId, consumerSurfaceIds[i]);
1746 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1747 }
1748 if (deferredStreamIndex != NAME_NOT_FOUND) {
1749 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001750 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001751 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001752 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001753 } else if (err == NO_INIT) {
1754 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001755 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001756 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001757 } else {
1758 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001759 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001760 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001761 }
1762
1763 return res;
1764}
1765
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001766binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001767 ATRACE_CALL();
1768 binder::Status res;
1769 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1770
1771 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001772 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1773 mCameraIdStr.c_str(), mode);
1774 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1775 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001776 }
1777
1778 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001779 BasicClient::setAudioRestriction(mode);
1780 return binder::Status::ok();
1781}
1782
1783binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1784 ATRACE_CALL();
1785 binder::Status res;
1786 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1787 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001788 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001789 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001790 }
1791 return binder::Status::ok();
1792}
1793
Ravneetaeb20dc2022-03-30 05:33:03 +00001794status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1795 return mDevice->setCameraServiceWatchdog(enabled);
1796}
1797
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001798status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal) {
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001799 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1800
1801 return mDevice->setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001802 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop), fromHal);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001803}
1804
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001805status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1806 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1807
1808 return mDevice->setAutoframingAutoBehavior(
1809 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1810}
1811
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001812bool CameraDeviceClient::supportsCameraMute() {
1813 return mDevice->supportsCameraMute();
1814}
1815
1816status_t CameraDeviceClient::setCameraMute(bool enabled) {
1817 return mDevice->setCameraMute(enabled);
1818}
1819
Shuzhen Wang16610a62022-12-15 22:38:07 -08001820void CameraDeviceClient::setStreamUseCaseOverrides(
1821 const std::vector<int64_t>& useCaseOverrides) {
1822 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1823}
1824
1825void CameraDeviceClient::clearStreamUseCaseOverrides() {
1826 mDevice->clearStreamUseCaseOverrides();
1827}
1828
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001829bool CameraDeviceClient::supportsZoomOverride() {
1830 return mDevice->supportsZoomOverride();
1831}
1832
1833status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1834 return mDevice->setZoomOverride(zoomOverride);
1835}
1836
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001837binder::Status CameraDeviceClient::switchToOffline(
1838 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001839 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001840 /*out*/
1841 sp<hardware::camera2::ICameraOfflineSession>* session) {
1842 ATRACE_CALL();
1843
1844 binder::Status res;
1845 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1846
1847 Mutex::Autolock icl(mBinderSerializationLock);
1848
1849 if (!mDevice.get()) {
1850 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1851 }
1852
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001853 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001854 std::string msg = "Offline surfaces must not be empty";
1855 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1856 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001857 }
1858
1859 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001860 std::string msg = "Invalid offline session";
1861 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1862 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001863 }
1864
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001865 std::vector<int32_t> offlineStreamIds;
1866 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001867 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001868 for (const auto& streamId : offlineOutputIds) {
1869 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001870 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001871 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001872 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001873 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1874 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001875 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001876
1877 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001878 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001879 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001880 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1881 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001882 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001883
Emilian Peev2f5d6012022-01-19 16:16:50 -08001884 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001885 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001886 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001887 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001888 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001889 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001890 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001891 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001892 if (isCompositeStream) {
1893 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1894 if (compositeIdx == NAME_NOT_FOUND) {
1895 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1896 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1897 "Unknown composite stream");
1898 }
1899
1900 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1901 &offlineStreamIds);
1902 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1903 mCompositeStreamMap.valueAt(compositeIdx));
1904 break;
1905 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001906 }
1907
Emilian Peev4697b642019-11-19 17:11:14 -08001908 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001909 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001910 }
1911 }
1912
1913 sp<CameraOfflineSessionBase> offlineSession;
1914 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1915 if (ret != OK) {
1916 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1917 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001918 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001919 }
1920
Emilian Peevcc0b7952020-01-07 13:54:47 -08001921 sp<CameraOfflineSessionClient> offlineClient;
1922 if (offlineSession.get() != nullptr) {
1923 offlineClient = new CameraOfflineSessionClient(sCameraService,
Austin Borger17e3ebe2024-02-14 15:02:11 -08001924 offlineSession, offlineCompositeStreamMap, cameraCb, mAttributionAndPermissionUtils,
1925 mClientPackageName, mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation,
1926 mClientPid, mClientUid, mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001927 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1928 }
1929
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001930 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001931 // A successful offline session switch must reset the current camera client
1932 // and release any resources occupied by previously configured streams.
1933 mStreamMap.clear();
1934 mConfiguredOutputs.clear();
1935 mDeferredStreams.clear();
1936 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001937 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001938 mCompositeStreamMap.clear();
1939 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001940 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001941 // In case we failed to register the offline client, ensure that it still initialized
1942 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001943 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001944
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001945 switch(ret) {
1946 case BAD_VALUE:
1947 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1948 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1949 case TIMED_OUT:
1950 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1951 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1952 default:
1953 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1954 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1955 strerror(-ret), ret);
1956 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001957 }
1958
1959 *session = offlineClient;
1960
1961 return binder::Status::ok();
1962}
1963
Igor Murashkine7ee7632013-06-11 18:10:18 -07001964status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001965 return BasicClient::dump(fd, args);
1966}
1967
1968status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001969 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001970 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001971 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001972 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001973 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001974
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001975 dprintf(fd, " State:\n");
1976 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001977 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001978 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001979 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001980 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001981 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001982 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001983 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001984 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001985 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001986 mStreamMap.valueAt(i).streamId(),
1987 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001988 }
Zhijun He5d677d12016-05-29 16:52:39 -07001989 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001990 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001991 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001992 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001993 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001994 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001995 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001996 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001997 // TODO: print dynamic/request section from most recent requests
1998 mFrameProcessor->dump(fd, args);
1999
2000 return dumpDevice(fd, args);
2001}
2002
Austin Borger1c1bee02023-06-01 16:51:35 -07002003status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07002004 sp<CameraDeviceBase> device = mDevice;
2005 if (!device) {
2006 dprintf(out, " Device is detached.");
2007 return OK;
2008 }
2009 device->startWatchingTags(tags);
2010 return OK;
2011}
2012
2013status_t CameraDeviceClient::stopWatchingTags(int out) {
2014 sp<CameraDeviceBase> device = mDevice;
2015 if (!device) {
2016 dprintf(out, " Device is detached.");
2017 return OK;
2018 }
2019 device->stopWatchingTags();
2020 return OK;
2021}
2022
2023status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
2024 sp<CameraDeviceBase> device = mDevice;
2025 if (!device) {
2026 return OK;
2027 }
2028 device->dumpWatchedEventsToVector(out);
2029 return OK;
2030}
2031
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002032void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07002033 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002034 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002035 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002036
Emilian Peev538c90e2018-12-17 18:03:19 +00002037 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002038 {
2039 // Access to the composite stream map must be synchronized
2040 Mutex::Autolock l(mCompositeLock);
2041 // Composites can have multiple internal streams. Error notifications coming from such
2042 // internal streams may need to remain within camera service.
2043 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2044 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2045 resultExtras);
2046 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002047 }
2048
2049 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002050 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002051 }
2052}
2053
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002054void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2055 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2056
2057 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002058 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002059 }
2060
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002061 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002062 mStreamingRequestId = REQUEST_ID_NONE;
2063}
2064
Shuzhen Wang316781a2020-08-18 18:11:01 -07002065void CameraDeviceClient::notifyIdle(
2066 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2067 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002068 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002069 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002070
2071 if (remoteCb != 0) {
2072 remoteCb->onDeviceIdle();
2073 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002074
2075 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2076 {
2077 Mutex::Autolock l(mCompositeLock);
2078 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2079 hardware::CameraStreamStats compositeStats;
2080 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2081 if (compositeStats.mWidth > 0) {
2082 fullStreamStats.push_back(compositeStats);
2083 }
2084 }
2085 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002086 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Shuzhen Wang6e08d202023-10-24 20:27:14 +00002087 fullStreamStats, mUserTag, mVideoStabilizationMode, mUsedUltraWide,
2088 mUsedSettingsOverrideZoom);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002089}
2090
Jianing Weicb0652e2014-03-12 18:29:36 -07002091void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002092 nsecs_t timestamp) {
2093 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002094 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002095 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002096 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002097 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002098 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002099
Emilian Peev2f5d6012022-01-19 16:16:50 -08002100 // Access to the composite stream map must be synchronized
2101 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002102 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2103 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2104 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002105}
2106
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002107void CameraDeviceClient::notifyPrepared(int streamId) {
2108 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002109 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002110 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002111 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002112 remoteCb->onPrepared(streamId);
2113 }
2114}
2115
Shuzhen Wang9d066012016-09-30 11:30:20 -07002116void CameraDeviceClient::notifyRequestQueueEmpty() {
2117 // Thread safe. Don't bother locking.
2118 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2119 if (remoteCb != 0) {
2120 remoteCb->onRequestQueueEmpty();
2121 }
2122}
2123
Igor Murashkine7ee7632013-06-11 18:10:18 -07002124void CameraDeviceClient::detachDevice() {
2125 if (mDevice == 0) return;
2126
Shuzhen Wang316781a2020-08-18 18:11:01 -07002127 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002128 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002129
Emilian Peev7ee731f2022-02-08 14:55:52 -08002130 if (mFrameProcessor.get() != nullptr) {
2131 mFrameProcessor->removeListener(
2132 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2133 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2134 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002135 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002136 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002137 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002138 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002139
2140 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2141 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002142 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002143 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002144 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2145 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2146 }
2147
Igor Murashkine7ee7632013-06-11 18:10:18 -07002148 if ((code = mDevice->waitUntilDrained()) != OK) {
2149 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2150 code);
2151 }
2152 }
2153
Emilian Peev2f5d6012022-01-19 16:16:50 -08002154 {
2155 Mutex::Autolock l(mCompositeLock);
2156 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2157 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2158 if (ret != OK) {
2159 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2160 strerror(-ret), ret);
2161 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002162 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002163 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002164 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002165
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002166 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002167 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002168
2169 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002170 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002171}
2172
2173/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002174void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002175 ATRACE_CALL();
2176 ALOGV("%s", __FUNCTION__);
2177
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002178 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002179 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002180 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002181 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2182 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002183 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002184
Emilian Peev2f5d6012022-01-19 16:16:50 -08002185 // Access to the composite stream map must be synchronized
2186 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002187 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2188 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2189 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002190}
2191
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002192binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002193 if (mDisconnected) {
2194 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2195 "The camera device has been disconnected");
2196 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002197 status_t res = checkPid(checkLocation);
2198 return (res == OK) ? binder::Status::ok() :
2199 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2200 "Attempt to use camera from a different process than original client");
2201}
2202
Igor Murashkine7ee7632013-06-11 18:10:18 -07002203// TODO: move to Camera2ClientBase
2204bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2205
Austin Borger22c5c852024-03-08 13:31:36 -08002206 const int pid = getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002207 const int selfPid = getpid();
2208 camera_metadata_entry_t entry;
2209
2210 /**
2211 * Mixin default important security values
2212 * - android.led.transmit = defaulted ON
2213 */
2214 CameraMetadata staticInfo = mDevice->info();
2215 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2216 for(size_t i = 0; i < entry.count; ++i) {
2217 uint8_t led = entry.data.u8[i];
2218
2219 switch(led) {
2220 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2221 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2222 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2223 metadata.update(ANDROID_LED_TRANSMIT,
2224 &transmitDefault, 1);
2225 }
2226 break;
2227 }
2228 }
2229 }
2230
2231 // We can do anything!
2232 if (pid == selfPid) {
2233 return true;
2234 }
2235
2236 /**
2237 * Permission check special fields in the request
2238 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2239 */
2240 entry = metadata.find(ANDROID_LED_TRANSMIT);
2241 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2242 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002243 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002244 if (!checkCallingPermission(permissionString)) {
Austin Borger22c5c852024-03-08 13:31:36 -08002245 const int uid = getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002246 ALOGE("Permission Denial: "
2247 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2248 return false;
2249 }
2250 }
2251
2252 return true;
2253}
2254
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002255status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2256 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002257 ALOGV("%s: begin", __FUNCTION__);
2258
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002259 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002260 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002261}
2262
Austin Borger1c1bee02023-06-01 16:51:35 -07002263const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002264 if (mDevice->getId() == cameraId) {
2265 return mDevice->info();
2266 }
2267 return mDevice->infoPhysical(cameraId);
2268}
2269
Austin Borger1c1bee02023-06-01 16:51:35 -07002270bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002271 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002272 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002273}
2274
2275bool CameraDeviceClient::isSensorPixelModeConsistent(
2276 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2277 // First we get the sensorPixelMode from the settings metadata.
2278 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2279 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2280 if (sensorPixelModeEntry.count != 0) {
2281 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2282 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2283 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2284 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2285 __FUNCTION__, sensorPixelMode);
2286 return false;
2287 }
2288 }
2289 // Check whether each stream has max resolution allowed.
2290 bool consistent = true;
2291 for (auto it : streamIdList) {
2292 auto const streamInfoIt = mStreamInfoMap.find(it);
2293 if (streamInfoIt == mStreamInfoMap.end()) {
2294 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2295 return false;
2296 }
2297 consistent =
2298 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2299 streamInfoIt->second.sensorPixelModesUsed.end();
2300 if (!consistent) {
2301 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2302 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2303 ALOGE("sensor pixel mode used list: %i", m);
2304 }
2305 break;
2306 }
2307 }
2308
2309 return consistent;
2310}
2311
Igor Murashkine7ee7632013-06-11 18:10:18 -07002312} // namespace android