blob: dad42dd0ae8984b7cfab0e82b3ef447cbf1d24e8 [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Igor Murashkine7ee7632013-06-11 18:10:18 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "CameraDeviceClient"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
Jianing Weicb0652e2014-03-12 18:29:36 -070019//#define LOG_NDEBUG 0
Igor Murashkine7ee7632013-06-11 18:10:18 -070020
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070021#include <cutils/properties.h>
Jayant Chowdhary12361932018-08-27 14:46:13 -070022#include <utils/CameraThreadState.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070023#include <utils/Log.h>
Colin Crossb8a9dbb2020-08-27 04:12:26 +000024#include <utils/SessionConfigurationUtils.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070025#include <utils/Trace.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070026#include <gui/Surface.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070027#include <camera/camera2/CaptureRequest.h>
Ruben Brunk5698d442014-06-18 10:39:40 -070028#include <camera/CameraUtils.h>
Austin Borger0fb3ad92023-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 Borger0fb3ad92023-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 Borger0fb3ad92023-06-01 16:51:35 -070050 fmt::sprintf("%s:%d: " errorString, __FUNCTION__, __LINE__, \
51 __VA_ARGS__).c_str())
Igor Murashkine7ee7632013-06-11 18:10:18 -070052
53namespace android {
54using namespace camera2;
Austin Borgerea931242021-12-13 23:10:41 +000055using namespace camera3;
Emilian Peevf4816702020-04-03 15:44:51 -070056using camera3::camera_stream_rotation_t::CAMERA_STREAM_ROTATION_0;
Igor Murashkine7ee7632013-06-11 18:10:18 -070057
58CameraDeviceClientBase::CameraDeviceClientBase(
59 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080060 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger0fb3ad92023-06-01 16:51:35 -070061 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080062 bool systemNativeClient,
Austin Borger0fb3ad92023-06-01 16:51:35 -070063 const std::optional<std::string>& clientFeatureId,
64 const std::string& cameraId,
Jing Mikec7f9b132023-03-12 11:12:04 +080065 [[maybe_unused]] int api1CameraId,
Igor Murashkine7ee7632013-06-11 18:10:18 -070066 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070067 int sensorOrientation,
Igor Murashkine7ee7632013-06-11 18:10:18 -070068 int clientPid,
69 uid_t clientUid,
Austin Borger3560b7e2022-10-27 12:20:29 -070070 int servicePid,
71 bool overrideToPortrait) :
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080072 BasicClient(cameraService,
Marco Nelissenf8880202014-11-14 07:58:25 -080073 IInterface::asBinder(remoteCallback),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080074 clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080075 systemNativeClient,
Philip P. Moltmann9e648f62019-11-04 12:52:45 -080076 clientFeatureId,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080077 cameraId,
78 cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070079 sensorOrientation,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080080 clientPid,
81 clientUid,
Austin Borger3560b7e2022-10-27 12:20:29 -070082 servicePid,
83 overrideToPortrait),
Igor Murashkine7ee7632013-06-11 18:10:18 -070084 mRemoteCallback(remoteCallback) {
85}
Igor Murashkine7ee7632013-06-11 18:10:18 -070086
87// Interface used by CameraService
88
89CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080090 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070091 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger0fb3ad92023-06-01 16:51:35 -070092 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080093 bool systemNativeClient,
Austin Borger0fb3ad92023-06-01 16:51:35 -070094 const std::optional<std::string>& clientFeatureId,
95 const std::string& cameraId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080096 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070097 int sensorOrientation,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080098 int clientPid,
99 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700100 int servicePid,
Austin Borger3560b7e2022-10-27 12:20:29 -0700101 bool overrideForPerfClass,
102 bool overrideToPortrait) :
Austin Borger74fca042022-05-23 12:41:21 -0700103 Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper, clientPackageName,
104 systemNativeClient, clientFeatureId, cameraId, /*API1 camera ID*/ -1, cameraFacing,
Austin Borger18b30a72022-10-27 12:20:29 -0700105 sensorOrientation, clientPid, clientUid, servicePid, overrideForPerfClass,
106 overrideToPortrait),
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700107 mInputStream(),
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700108 mStreamingRequestId(REQUEST_ID_NONE),
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700109 mRequestIdCounter(0),
110 mOverrideForPerfClass(overrideForPerfClass) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700111
112 ATRACE_CALL();
Austin Borger0fb3ad92023-06-01 16:51:35 -0700113 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700114}
115
Emilian Peevbd8c5032018-02-14 23:05:40 +0000116status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700117 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000118 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800119}
120
121template<typename TProviderPtr>
Austin Borger0fb3ad92023-06-01 16:51:35 -0700122status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
123 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700124 ATRACE_CALL();
125 status_t res;
126
Emilian Peevbd8c5032018-02-14 23:05:40 +0000127 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700128 if (res != OK) {
129 return res;
130 }
131
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700132 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger0fb3ad92023-06-01 16:51:35 -0700133 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
Xin Li65d53082023-08-25 14:16:11 -0700134 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700135 if (res != OK) {
136 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
137 __FUNCTION__, strerror(-res), res);
138 return res;
139 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700140
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800141 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
142 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800143 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700144 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700145
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800146 const CameraMetadata &deviceInfo = mDevice->info();
147 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000148 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
149 if (physicalKeysEntry.count > 0) {
150 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
151 physicalKeysEntry.data.i32,
152 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
153 }
154
Emilian Peev2295df72021-11-12 18:14:10 -0800155 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
156 mDynamicProfileMap.emplace(
157 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
158 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
159 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800160 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800161 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800162 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800163 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800164 if (entry.count > 0 || ((entry.count % 3) != 0)) {
165 int64_t standardBitmap =
166 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
167 for (size_t i = 0; i < entry.count; i += 3) {
168 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800169 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800170 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
171 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800172 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800173 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800174 }
175 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800176 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
177 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800178 }
179 }
Emilian Peevef715e22022-05-19 17:44:33 -0700180 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
181 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800182 } else {
183 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
184 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
185 }
186 }
187 }
188
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700189 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800190 // Cache physical camera ids corresponding to this device and also the high
191 // resolution sensors in this device + physical camera ids
Austin Borger0fb3ad92023-06-01 16:51:35 -0700192 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800193 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700194 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800195 }
196 for (auto &physicalId : mPhysicalCameraIds) {
Xin Li65d53082023-08-25 14:16:11 -0700197 if (supportsUltraHighResolutionCapture(physicalId)) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700198 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800199 }
200 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700201 return OK;
202}
203
204CameraDeviceClient::~CameraDeviceClient() {
205}
206
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800207binder::Status CameraDeviceClient::submitRequest(
208 const hardware::camera2::CaptureRequest& request,
209 bool streaming,
210 /*out*/
211 hardware::camera2::utils::SubmitInfo *submitInfo) {
212 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
213 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700214}
215
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800216binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000217 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000218 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800219 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
220
Emilian Peev2f5d6012022-01-19 16:16:50 -0800221 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800222 // Trying to submit request with surface that wasn't created
223 if (idx == NAME_NOT_FOUND) {
224 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
225 " we have not called createStream on",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700226 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800227 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
228 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000229 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
230 != NAME_NOT_FOUND) {
231 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
232 currentStreamId);
233 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800234 }
235
236 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
237 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800238 outputStreamIds->push_back(streamSurfaceId.streamId());
239 }
240 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
241
242 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700243 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800244 streamSurfaceId.surfaceId());
245
Emilian Peevf873aa52018-01-26 14:58:28 +0000246 if (currentStreamId != nullptr) {
247 *currentStreamId = streamSurfaceId.streamId();
248 }
249
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800250 return binder::Status::ok();
251}
252
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800253static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
254 const Vector<int> &streamIdsForThisRequest) {
255 std::list<int> intersection;
256 for (auto &streamId : streamIdsForThisRequest) {
257 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
258 intersection.emplace_back(streamId);
259 }
260 }
261 return intersection;
262}
263
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800264binder::Status CameraDeviceClient::submitRequestList(
265 const std::vector<hardware::camera2::CaptureRequest>& requests,
266 bool streaming,
267 /*out*/
268 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700269 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700270 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700271
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800272 binder::Status res = binder::Status::ok();
273 status_t err;
274 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
275 return res;
276 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700277
278 Mutex::Autolock icl(mBinderSerializationLock);
279
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800280 if (!mDevice.get()) {
281 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
282 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700283
284 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800285 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700286 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800287 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700288 }
289
Emilian Peevaebbe412018-01-15 13:53:24 +0000290 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700291 std::list<const SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800292 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700293 uint32_t loopCounter = 0;
294
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800295 for (auto&& request: requests) {
296 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700297 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800298 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700299 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800300 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800301 "No input configured for camera %s but request is for reprocessing",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700302 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700303 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800304 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700305 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800306 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
307 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000308 } else if (request.mPhysicalCameraSettings.size() > 1) {
309 ALOGE("%s: Camera %s: reprocess requests not supported for "
310 "multiple physical cameras.", __FUNCTION__,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700311 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000312 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
313 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700314 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700315 }
316
Emilian Peevaebbe412018-01-15 13:53:24 +0000317 if (request.mPhysicalCameraSettings.empty()) {
318 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700319 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800320 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000321 "Request doesn't contain any settings");
322 }
323
324 //The first capture settings should always match the logical camera id
Austin Borger0fb3ad92023-06-01 16:51:35 -0700325 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
Emilian Peevaebbe412018-01-15 13:53:24 +0000326 if (mDevice->getId() != logicalId) {
327 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700328 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000329 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
330 "Invalid camera request settings");
331 }
332
Emilian Peevaebbe412018-01-15 13:53:24 +0000333 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800334 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger0fb3ad92023-06-01 16:51:35 -0700335 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800336 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
337 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700338 }
339
Jianing Wei90e59c92014-03-12 18:29:36 -0700340 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700341 * Write in the output stream IDs and map from stream ID to surface ID
342 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700343 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700344 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700345 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000346 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800347 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800348 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800349 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800350 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700351
Emilian Peevf873aa52018-01-26 14:58:28 +0000352 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800353 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000354 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800355 if (!res.isOk()) {
356 return res;
357 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000358
359 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
360 if (index >= 0) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700361 const std::string &requestedPhysicalId =
362 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
363 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800364 dynamicProfileBitmap |=
365 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000366 } else {
367 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
368 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700369 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800370 } else {
371 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
372 int streamId = request.mStreamIdxList.itemAt(i);
373 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700374
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800375 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
376 if (index < 0) {
377 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
378 " we have not called createStream on: stream %d",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700379 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800380 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
381 "Request targets Surface that is not part of current capture session");
382 }
383
384 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
385 if ((size_t)surfaceIdx >= gbps.size()) {
386 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
387 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700388 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800389 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
390 "Request targets Surface has invalid surface index");
391 }
392
Emilian Peevf873aa52018-01-26 14:58:28 +0000393 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800394 if (!res.isOk()) {
395 return res;
396 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000397
Austin Borger0fb3ad92023-06-01 16:51:35 -0700398 const std::string &requestedPhysicalId =
399 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
400 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800401 dynamicProfileBitmap |=
402 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
403 }
404 }
405
406 if (dynamicProfileBitmap !=
407 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
408 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
409 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
410 if ((dynamicProfileBitmap & i) == 0) {
411 continue;
412 }
413
414 const auto& it = mDynamicProfileMap.find(i);
415 if (it != mDynamicProfileMap.end()) {
416 if ((it->second == 0) ||
417 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
418 continue;
419 } else {
420 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
421 " reference an unsupported dynamic range profile combination"
Austin Borger0fb3ad92023-06-01 16:51:35 -0700422 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800423 dynamicProfileBitmap);
424 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
425 "Request targets an unsupported dynamic range profile"
426 " combination");
427 }
428 } else {
429 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
430 " references unsupported dynamic range profile 0x%x!",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700431 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800432 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
433 "Request targets 10-bit Surface with unsupported dynamic range"
434 " profile");
435 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700436 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700437 }
438
Emilian Peevf873aa52018-01-26 14:58:28 +0000439 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
440 for (const auto& it : request.mPhysicalCameraSettings) {
Emilian Peev00420d22018-02-05 21:33:13 +0000441 if (it.settings.isEmpty()) {
442 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700443 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000444 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
445 "Request settings are empty");
446 }
447
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800448 // Check whether the physical / logical stream has settings
449 // consistent with the sensor pixel mode(s) it was configured with.
450 // mCameraIdToStreamSet will only have ids that are high resolution
451 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(it.id);
452 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
453 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
454 outputStreamIds);
455 if (!request.mIsReprocess &&
456 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
457 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
458 "consistent with configured streams. Rejecting request.",
459 __FUNCTION__, it.id.c_str());
460 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
461 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
462 "streams configured");
463 }
464 }
465
Austin Borger0fb3ad92023-06-01 16:51:35 -0700466 const std::string &physicalId = it.id;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700467 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
468 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
469 mSupportedPhysicalRequestKeys.end();
470 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
471 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
472 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000473 if (physicalId != mDevice->getId()) {
474 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
475 it.id);
476 if (found == requestedPhysicalIds.end()) {
477 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700478 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000479 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
480 "Invalid physical camera id");
481 }
Emilian Peev00420d22018-02-05 21:33:13 +0000482
483 if (!mSupportedPhysicalRequestKeys.empty()) {
484 // Filter out any unsupported physical request keys.
485 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
486 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
487 filteredParams.getAndLock());
488 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
489 filteredParams.unlock(meta);
490
491 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
492 camera_metadata_ro_entry entry = it.settings.find(keyIt);
493 if (entry.count > 0) {
494 filteredParams.update(entry);
495 }
496 }
497
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700498 physicalSettingsList.push_back({it.id, filteredParams,
499 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000500 }
501 } else {
502 physicalSettingsList.push_back({it.id, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000503 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000504 }
505
506 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
507 // Callee logs
508 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
509 "Caller does not have permission to change restricted controls");
510 }
511
Emilian Peevaebbe412018-01-15 13:53:24 +0000512 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
513 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700514
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800515 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000516 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
517 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700518 }
519
Emilian Peevaebbe412018-01-15 13:53:24 +0000520 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
521 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700522 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800523 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700524 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800525 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700526
Emilian Peevaebbe412018-01-15 13:53:24 +0000527 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700528 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800529
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700530 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800531 if (!request.mUserTag.empty()) {
532 mUserTag = request.mUserTag;
533 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700534 camera_metadata_entry entry =
535 physicalSettingsList.begin()->metadata.find(
536 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
537 if (entry.count == 1) {
538 mVideoStabilizationMode = entry.data.u8[0];
539 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700540 }
541 mRequestIdCounter++;
542
543 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700544 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
545 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800546 if (err != OK) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700547 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800548 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700549 mCameraIdStr.c_str(), strerror(-err), err);
550 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800551 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700552 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700553 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700554 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700555 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700556 }
557 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700558 err = mDevice->captureList(metadataRequestList, surfaceMapList,
559 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800560 if (err != OK) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700561 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800562 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700563 mCameraIdStr.c_str(), strerror(-err), err);
564 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800565 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700566 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700567 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800568 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700569 }
570
Austin Borger0fb3ad92023-06-01 16:51:35 -0700571 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700572 return res;
573}
574
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800575binder::Status CameraDeviceClient::cancelRequest(
576 int requestId,
577 /*out*/
578 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700579 ATRACE_CALL();
580 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
581
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800582 status_t err;
583 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700584
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800585 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700586
587 Mutex::Autolock icl(mBinderSerializationLock);
588
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800589 if (!mDevice.get()) {
590 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
591 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700592
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700593 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700594 if (mStreamingRequestId != requestId) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700595 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
596 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
597 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
598 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700599 }
600
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800601 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700602
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800603 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800604 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700605 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700606 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800607 } else {
608 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800609 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700610 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700611 }
612
613 return res;
614}
615
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800616binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700617 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700618 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700619 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800620 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700621}
622
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100623binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700624 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800625 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700626 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700627 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
628 __FUNCTION__, mInputStream.configured ? 1 : 0,
629 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700630
Zhijun He0effd522016-03-04 10:22:27 -0800631 binder::Status res;
632 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
633
Emilian Peevcc0b7952020-01-07 13:54:47 -0800634 if (offlineStreamIds == nullptr) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700635 std::string msg = "Invalid offline stream ids";
636 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
637 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800638 }
639
Zhijun He0effd522016-03-04 10:22:27 -0800640 Mutex::Autolock icl(mBinderSerializationLock);
641
642 if (!mDevice.get()) {
643 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
644 }
645
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700646 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000647 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000648 if (!res.isOk()) {
649 return res;
650 }
651
652 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
653 if (err == BAD_VALUE) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700654 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
655 mCameraIdStr.c_str());
656 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
657 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000658 } else if (err != OK) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700659 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
660 mCameraIdStr.c_str(), strerror(-err), err);
661 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
662 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000663 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800664 offlineStreamIds->clear();
665 mDevice->getOfflineStreamIds(offlineStreamIds);
666
Emilian Peev2f5d6012022-01-19 16:16:50 -0800667 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000668 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
669 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800670 if (err != OK) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700671 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
672 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
673 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
674 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000675 break;
676 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800677
678 // Composite streams can only support offline mode in case all individual internal
679 // streams are also supported.
680 std::vector<int> internalStreams;
681 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800682 offlineStreamIds->erase(
683 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800684 [&internalStreams] (int streamId) {
685 auto it = std::find(internalStreams.begin(), internalStreams.end(),
686 streamId);
687 if (it != internalStreams.end()) {
688 internalStreams.erase(it);
689 return true;
690 }
691
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800692 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800693 if (internalStreams.empty()) {
694 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
695 }
696 }
697
698 for (const auto& offlineStreamId : *offlineStreamIds) {
699 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000700 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700701
702 nsecs_t configureEnd = systemTime();
703 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700704 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700705 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000706 }
707
708 return res;
709}
710
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800711binder::Status CameraDeviceClient::isSessionConfigurationSupported(
712 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800713
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800714 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800715 binder::Status res;
716 status_t ret = OK;
717 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
718
719 Mutex::Autolock icl(mBinderSerializationLock);
720
721 if (!mDevice.get()) {
722 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
723 }
724
725 auto operatingMode = sessionConfiguration.getOperatingMode();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700726 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000727 mCameraIdStr);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800728 if (!res.isOk()) {
729 return res;
730 }
731
732 if (status == nullptr) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700733 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
734 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
735 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800736 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700737
Emilian Peev35ae8262018-11-08 13:11:32 +0000738 *status = false;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700739 camera3::metadataGetter getMetadata = [this](const std::string &id,
740 bool /*overrideForPerfClass*/) {
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700741 return mDevice->infoPhysical(id);};
Austin Borger0fb3ad92023-06-01 16:51:35 -0700742 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700743 sessionConfiguration, mOverrideForPerfClass, getMetadata, status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000744 switch (ret) {
745 case OK:
746 // Expected, do nothing.
747 break;
748 case INVALID_OPERATION: {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700749 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000750 "Camera %s: Session configuration query not supported!",
Austin Borger0fb3ad92023-06-01 16:51:35 -0700751 mCameraIdStr.c_str());
752 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
753 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000754 }
755
756 break;
757 default: {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700758 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000759 strerror(-ret), ret);
Austin Borger0fb3ad92023-06-01 16:51:35 -0700760 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000761 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700762 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000763 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800764 }
765
766 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700767}
768
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800769binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700770 ATRACE_CALL();
771 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
772
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800773 binder::Status res;
774 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700775
776 Mutex::Autolock icl(mBinderSerializationLock);
777
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800778 if (!mDevice.get()) {
779 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
780 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700781
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700782 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700783 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700784 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000785 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700786
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700787 if (mInputStream.configured && mInputStream.id == streamId) {
788 isInput = true;
789 } else {
790 // Guard against trying to delete non-created streams
791 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700792 if (streamId == mStreamMap.valueAt(i).streamId()) {
793 surfaces.push_back(mStreamMap.keyAt(i));
794 }
795 }
796
797 // See if this stream is one of the deferred streams.
798 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
799 if (streamId == mDeferredStreams[i]) {
800 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700801 break;
802 }
803 }
804
Emilian Peev2f5d6012022-01-19 16:16:50 -0800805 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000806 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
807 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
808 compositeIndex = i;
809 break;
810 }
811 }
812
Shuzhen Wang0129d522016-10-30 22:43:41 -0700813 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700814 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
815 " stream created yet", mCameraIdStr.c_str(), streamId);
816 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
817 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700818 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700819 }
820
821 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800822 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700823
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800824 if (err != OK) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700825 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
826 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
827 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
828 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800829 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700830 if (isInput) {
831 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700832 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700833 for (auto& surface : surfaces) {
834 mStreamMap.removeItem(surface);
835 }
836
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800837 mConfiguredOutputs.removeItem(streamId);
838
Shuzhen Wang0129d522016-10-30 22:43:41 -0700839 if (dIndex != NAME_NOT_FOUND) {
840 mDeferredStreams.removeItemsAt(dIndex);
841 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000842
843 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800844 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000845 status_t ret;
846 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
847 != OK) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700848 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
849 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
850 err, streamId);
851 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
852 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000853 }
854 mCompositeStreamMap.removeItemsAt(compositeIndex);
855 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800856 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
857 auto &streamSet = mapIt.second;
858 if (streamSet.find(streamId) != streamSet.end()) {
859 streamSet.erase(streamId);
860 break;
861 }
862 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700863 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700864 }
865
866 return res;
867}
868
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800869binder::Status CameraDeviceClient::createStream(
870 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
871 /*out*/
872 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700873 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700874
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800875 binder::Status res;
876 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700877
878 Mutex::Autolock icl(mBinderSerializationLock);
879
Shuzhen Wang0129d522016-10-30 22:43:41 -0700880 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
881 outputConfiguration.getGraphicBufferProducers();
882 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800883 bool deferredConsumer = outputConfiguration.isDeferred();
884 bool isShared = outputConfiguration.isShared();
Austin Borger0fb3ad92023-06-01 16:51:35 -0700885 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800886 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800887 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800888 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800889 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800890 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800891 int mirrorMode = outputConfiguration.getMirrorMode();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700892 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000893 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700894
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700895 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Emilian Peev35ae8262018-11-08 13:11:32 +0000896 outputConfiguration.getSurfaceType());
897 if (!res.isOk()) {
898 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700899 }
Zhijun He5d677d12016-05-29 16:52:39 -0700900
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800901 if (!mDevice.get()) {
902 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
903 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700904 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800905 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000906 if (!res.isOk()) {
907 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800908 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000909
Shuzhen Wang0129d522016-10-30 22:43:41 -0700910 std::vector<sp<Surface>> surfaces;
911 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700912 status_t err;
913
914 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700915 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800916 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700917 }
918
Shuzhen Wang758c2152017-01-10 18:26:18 -0800919 OutputStreamInfo streamInfo;
920 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800921 const std::vector<int32_t> &sensorPixelModesUsed =
922 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700923 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700924 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700925 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800926 ssize_t index = mStreamMap.indexOfKey(binder);
927 if (index != NAME_NOT_FOUND) {
Austin Borger0fb3ad92023-06-01 16:51:35 -0700928 std::string msg = std::string("Camera ") + mCameraIdStr
929 + ": Surface already has a stream created for it (ID "
930 + std::to_string(index) + ")";
931 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
932 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700933 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700934
Shuzhen Wang758c2152017-01-10 18:26:18 -0800935 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700936 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800937 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800938 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700939 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800940
941 if (!res.isOk())
942 return res;
943
944 if (!isStreamInfoValid) {
945 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700946 }
947
Shuzhen Wang758c2152017-01-10 18:26:18 -0800948 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang0129d522016-10-30 22:43:41 -0700949 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -0800950 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700951
952 // If mOverrideForPerfClass is true, do not fail createStream() for small
953 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
954 // closest possible supported size.
955
Zhijun He125684a2015-12-26 15:07:30 -0800956 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100957 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800958 bool isDepthCompositeStream =
959 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0]);
Chema Gonzalezdcc8a912022-12-21 08:59:30 -0800960 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(surfaces[0]);
Emilian Peev434248e2022-10-06 14:58:54 -0700961 bool isJpegRCompositeStream =
Emilian Peeve579d8b2023-02-28 14:16:08 -0800962 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0]) &&
Emilian Peev15230142023-04-27 20:22:54 +0000963 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800964 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800965 sp<CompositeStream> compositeStream;
966 if (isDepthCompositeStream) {
967 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800968 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800969 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -0700970 } else {
971 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800972 }
973
Emilian Peev538c90e2018-12-17 18:03:19 +0000974 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
975 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -0700976 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800977 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -0700978 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000979 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
980 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000981 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800982 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000983 mCompositeStreamMap.add(IInterface::asBinder(surfaces[0]->getIGraphicBufferProducer()),
984 compositeStream);
985 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800986 } else {
987 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
988 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -0700989 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800990 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -0800991 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -0800992 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000993 streamInfo.timestampBase, streamInfo.mirrorMode, streamInfo.colorSpace,
994 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000995 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700996
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800997 if (err != OK) {
998 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800999 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001000 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Henri Chataingbcb99452023-11-01 17:40:30 +00001001 static_cast<int>(streamInfo.dataSpace), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001002 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001003 int i = 0;
1004 for (auto& binder : binders) {
1005 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1006 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001007 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1008 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001009 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001010
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001011 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001012 mStreamInfoMap[streamId] = streamInfo;
1013
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001014 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001015 " (%d x %d) with format 0x%x.",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001016 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001017 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001018
Zhijun He5d677d12016-05-29 16:52:39 -07001019 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001020 res = setStreamTransformLocked(streamId, streamInfo.mirrorMode);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001021
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001022 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger0fb3ad92023-06-01 16:51:35 -07001023 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001024 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001025 // Only needed for high resolution sensors
Austin Borger0fb3ad92023-06-01 16:51:35 -07001026 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001027 mHighResolutionSensors.end()) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001028 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001029 }
1030
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001031 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001032 }
1033
1034 return res;
1035}
1036
Zhijun He5d677d12016-05-29 16:52:39 -07001037binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1038 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001039 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001040 /*out*/
1041 int* newStreamId) {
1042 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001043 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001044 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001045 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001046 status_t err;
1047 binder::Status res;
1048
1049 if (!mDevice.get()) {
1050 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1051 }
1052
1053 // Infer the surface info for deferred surface stream creation.
1054 width = outputConfiguration.getWidth();
1055 height = outputConfiguration.getHeight();
1056 surfaceType = outputConfiguration.getSurfaceType();
1057 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1058 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001059 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001060 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1061 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1062 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1063 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1064 }
1065 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001066 std::vector<sp<Surface>> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001067 std::vector<int> surfaceIds;
Austin Borger0fb3ad92023-06-01 16:51:35 -07001068 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1069 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001070 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1071 // Here, we override sensor pixel modes
1072 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1073 const std::vector<int32_t> &sensorPixelModesUsed =
1074 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001075 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001076 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001077 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001078 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1079 "sensor pixel modes used not valid for deferred stream");
1080 }
1081
Shuzhen Wang0129d522016-10-30 22:43:41 -07001082 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1083 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001084 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001085 &streamId, physicalCameraId,
1086 overriddenSensorPixelModesUsed,
1087 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001088 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001089 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001090 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001091 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001092 outputConfiguration.getMirrorMode(),
1093 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001094
1095 if (err != OK) {
1096 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001097 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Henri Chataingbcb99452023-11-01 17:40:30 +00001098 mCameraIdStr.c_str(), width, height, format, static_cast<int>(dataSpace),
1099 strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001100 } else {
1101 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1102 // a separate list to track. Once the deferred surface is set, this id will be
1103 // relocated to mStreamMap.
1104 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001105 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001106 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001107 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001108 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001109 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001110 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001111 outputConfiguration.getMirrorMode(),
1112 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001113
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001114 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001115 " (%d x %d) stream with format 0x%x.",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001116 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001117
1118 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001119 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001120
1121 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001122 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001123 // Only needed for high resolution sensors
Austin Borger0fb3ad92023-06-01 16:51:35 -07001124 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001125 mHighResolutionSensors.end()) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001126 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001127 }
Zhijun He5d677d12016-05-29 16:52:39 -07001128 }
1129 return res;
1130}
1131
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001132binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001133 int32_t transform = 0;
1134 status_t err;
1135 binder::Status res;
1136
1137 if (!mDevice.get()) {
1138 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1139 }
1140
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001141 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001142 if (err != OK) {
1143 // Error logged by getRotationTransformLocked.
1144 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1145 "Unable to calculate rotation transform for new stream");
1146 }
1147
1148 err = mDevice->setStreamTransform(streamId, transform);
1149 if (err != OK) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001150 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001151 streamId);
Austin Borger0fb3ad92023-06-01 16:51:35 -07001152 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1153 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001154 }
1155
1156 return res;
1157}
Ruben Brunkbba75572014-11-20 17:29:50 -08001158
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001159binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001160 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001161 /*out*/
1162 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001163
1164 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001165 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1166 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001167
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001168 binder::Status res;
1169 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001170
1171 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001172
1173 if (!mDevice.get()) {
1174 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1175 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001176
1177 if (mInputStream.configured) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001178 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1179 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1180 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1181 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001182 }
1183
1184 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001185 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001186 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001187 mInputStream.configured = true;
1188 mInputStream.width = width;
1189 mInputStream.height = height;
1190 mInputStream.format = format;
1191 mInputStream.id = streamId;
1192
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001193 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001194 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001195
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001196 *newStreamId = streamId;
1197 } else {
1198 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger0fb3ad92023-06-01 16:51:35 -07001199 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001200 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001201 }
1202
1203 return res;
1204}
1205
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001206binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001207
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001208 binder::Status res;
1209 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1210
1211 if (inputSurface == NULL) {
1212 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001213 }
1214
1215 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001216 if (!mDevice.get()) {
1217 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1218 }
1219 sp<IGraphicBufferProducer> producer;
1220 status_t err = mDevice->getInputBufferProducer(&producer);
1221 if (err != OK) {
1222 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001223 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001224 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001225 } else {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001226 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001227 inputSurface->graphicBufferProducer = producer;
1228 }
1229 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001230}
1231
Emilian Peev40ead602017-09-26 15:46:36 +01001232binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1233 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1234 ATRACE_CALL();
1235
1236 binder::Status res;
1237 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1238
1239 Mutex::Autolock icl(mBinderSerializationLock);
1240
1241 if (!mDevice.get()) {
1242 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1243 }
1244
1245 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1246 outputConfiguration.getGraphicBufferProducers();
Austin Borger0fb3ad92023-06-01 16:51:35 -07001247 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001248
Emilian Peev40ead602017-09-26 15:46:36 +01001249 auto producerCount = bufferProducers.size();
1250 if (producerCount == 0) {
1251 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1252 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1253 "bufferProducers must not be empty");
1254 }
1255
1256 // The first output is the one associated with the output configuration.
1257 // It should always be present, valid and the corresponding stream id should match.
1258 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1259 ssize_t index = mStreamMap.indexOfKey(binder);
1260 if (index == NAME_NOT_FOUND) {
1261 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1262 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1263 "OutputConfiguration is invalid");
1264 }
1265 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1266 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1267 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1268 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1269 "Stream id is invalid");
1270 }
1271
1272 std::vector<size_t> removedSurfaceIds;
1273 std::vector<sp<IBinder>> removedOutputs;
1274 std::vector<sp<Surface>> newOutputs;
1275 std::vector<OutputStreamInfo> streamInfos;
1276 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1277 for (auto &it : bufferProducers) {
1278 newOutputsMap.add(IInterface::asBinder(it), it);
1279 }
1280
1281 for (size_t i = 0; i < mStreamMap.size(); i++) {
1282 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1283 if (idx == NAME_NOT_FOUND) {
1284 if (mStreamMap[i].streamId() == streamId) {
1285 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1286 removedOutputs.push_back(mStreamMap.keyAt(i));
1287 }
1288 } else {
1289 if (mStreamMap[i].streamId() != streamId) {
1290 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1291 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1292 "Target Surface is invalid");
1293 }
1294 newOutputsMap.removeItemsAt(idx);
1295 }
1296 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001297 const std::vector<int32_t> &sensorPixelModesUsed =
1298 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001299 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001300 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001301 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001302 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001303 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001304
Emilian Peev40ead602017-09-26 15:46:36 +01001305 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1306 OutputStreamInfo outInfo;
1307 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001308 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001309 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001310 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001311 streamUseCase, timestampBase, mirrorMode, colorSpace);
Emilian Peev40ead602017-09-26 15:46:36 +01001312 if (!res.isOk())
1313 return res;
1314
Emilian Peev40ead602017-09-26 15:46:36 +01001315 streamInfos.push_back(outInfo);
1316 newOutputs.push_back(surface);
1317 }
1318
1319 //Trivial case no changes required
1320 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1321 return binder::Status::ok();
1322 }
1323
1324 KeyedVector<sp<Surface>, size_t> outputMap;
1325 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1326 &outputMap);
1327 if (ret != OK) {
1328 switch (ret) {
1329 case NAME_NOT_FOUND:
1330 case BAD_VALUE:
1331 case -EBUSY:
1332 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1333 "Camera %s: Error updating stream: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001334 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001335 break;
1336 default:
1337 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1338 "Camera %s: Error updating stream: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001339 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001340 break;
1341 }
1342 } else {
1343 for (const auto &it : removedOutputs) {
1344 mStreamMap.removeItem(it);
1345 }
1346
1347 for (size_t i = 0; i < outputMap.size(); i++) {
1348 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1349 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1350 }
1351
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001352 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1353
Emilian Peev40ead602017-09-26 15:46:36 +01001354 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001355 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001356 }
1357
1358 return res;
1359}
1360
Igor Murashkine7ee7632013-06-11 18:10:18 -07001361// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001362binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1363 /*out*/
1364 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001365{
1366 ATRACE_CALL();
1367 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1368
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001369 binder::Status res;
1370 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001371
1372 Mutex::Autolock icl(mBinderSerializationLock);
1373
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001374 if (!mDevice.get()) {
1375 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1376 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001377
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001378 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001379 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
1380 if (!(res = mapRequestTemplate(templateId, &tempId)).isOk()) return res;
1381
1382 CameraMetadata metadata;
1383 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001384 request != NULL) {
1385
1386 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001387 } else if (err == BAD_VALUE) {
1388 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001389 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001390 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001391
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001392 } else {
1393 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001394 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001395 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001396 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001397 return res;
1398}
1399
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001400binder::Status CameraDeviceClient::getCameraInfo(
1401 /*out*/
1402 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001403{
1404 ATRACE_CALL();
1405 ALOGV("%s", __FUNCTION__);
1406
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001407 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001408
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001409 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001410
1411 Mutex::Autolock icl(mBinderSerializationLock);
1412
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001413 if (!mDevice.get()) {
1414 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1415 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001416
Igor Murashkin099b4572013-07-12 17:52:16 -07001417 if (info != NULL) {
1418 *info = mDevice->info(); // static camera metadata
1419 // TODO: merge with device-specific camera metadata
1420 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001421
1422 return res;
1423}
1424
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001425binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001426{
1427 ATRACE_CALL();
1428 ALOGV("%s", __FUNCTION__);
1429
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001430 binder::Status res;
1431 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001432
1433 Mutex::Autolock icl(mBinderSerializationLock);
1434
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001435 if (!mDevice.get()) {
1436 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1437 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001438
1439 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001440 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001441 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001442 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001443 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001444 mCameraIdStr.c_str());
1445 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1446 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001447 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001448 status_t err = mDevice->waitUntilDrained();
1449 if (err != OK) {
1450 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001451 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001452 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001453 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001454 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001455 return res;
1456}
1457
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001458binder::Status CameraDeviceClient::flush(
1459 /*out*/
1460 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001461 ATRACE_CALL();
1462 ALOGV("%s", __FUNCTION__);
1463
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001464 binder::Status res;
1465 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001466
1467 Mutex::Autolock icl(mBinderSerializationLock);
1468
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001469 if (!mDevice.get()) {
1470 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1471 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001472
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001473 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001474 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001475 status_t err = mDevice->flush(lastFrameNumber);
1476 if (err != OK) {
1477 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger0fb3ad92023-06-01 16:51:35 -07001478 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1479 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001480 }
1481 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001482}
1483
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001484binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001485 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001486 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001487
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001488 binder::Status res;
1489 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001490
1491 Mutex::Autolock icl(mBinderSerializationLock);
1492
1493 // Guard against trying to prepare non-created streams
1494 ssize_t index = NAME_NOT_FOUND;
1495 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001496 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001497 index = i;
1498 break;
1499 }
1500 }
1501
1502 if (index == NAME_NOT_FOUND) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001503 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1504 "with that ID exists", mCameraIdStr.c_str(), streamId);
1505 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1506 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001507 }
1508
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001509 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1510 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001511 status_t err = mDevice->prepare(streamId);
1512 if (err == BAD_VALUE) {
1513 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001514 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001515 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001516 } else if (err != OK) {
1517 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger0fb3ad92023-06-01 16:51:35 -07001518 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001519 strerror(-err), err);
1520 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001521 return res;
1522}
1523
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001524binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001525 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001526 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001527
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001528 binder::Status res;
1529 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001530
1531 Mutex::Autolock icl(mBinderSerializationLock);
1532
1533 // Guard against trying to prepare non-created streams
1534 ssize_t index = NAME_NOT_FOUND;
1535 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001536 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001537 index = i;
1538 break;
1539 }
1540 }
1541
1542 if (index == NAME_NOT_FOUND) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001543 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1544 "with that ID exists", mCameraIdStr.c_str(), streamId);
1545 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1546 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001547 }
1548
1549 if (maxCount <= 0) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001550 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1551 mCameraIdStr.c_str(), maxCount);
1552 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1553 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001554 }
1555
1556 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1557 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001558 status_t err = mDevice->prepare(maxCount, streamId);
1559 if (err == BAD_VALUE) {
1560 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001561 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001562 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001563 } else if (err != OK) {
1564 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger0fb3ad92023-06-01 16:51:35 -07001565 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001566 strerror(-err), err);
1567 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001568
1569 return res;
1570}
1571
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001572binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001573 ATRACE_CALL();
1574 ALOGV("%s", __FUNCTION__);
1575
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001576 binder::Status res;
1577 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001578
1579 Mutex::Autolock icl(mBinderSerializationLock);
1580
1581 // Guard against trying to prepare non-created streams
1582 ssize_t index = NAME_NOT_FOUND;
1583 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001584 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001585 index = i;
1586 break;
1587 }
1588 }
1589
1590 if (index == NAME_NOT_FOUND) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001591 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1592 "with that ID exists", mCameraIdStr.c_str(), streamId);
1593 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1594 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001595 }
1596
1597 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1598 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001599 status_t err = mDevice->tearDown(streamId);
1600 if (err == BAD_VALUE) {
1601 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001602 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001603 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001604 } else if (err != OK) {
1605 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger0fb3ad92023-06-01 16:51:35 -07001606 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001607 strerror(-err), err);
1608 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001609
1610 return res;
1611}
1612
Shuzhen Wang758c2152017-01-10 18:26:18 -08001613binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001614 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1615 ATRACE_CALL();
1616
1617 binder::Status res;
1618 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1619
1620 Mutex::Autolock icl(mBinderSerializationLock);
1621
Shuzhen Wang0129d522016-10-30 22:43:41 -07001622 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1623 outputConfiguration.getGraphicBufferProducers();
Austin Borger0fb3ad92023-06-01 16:51:35 -07001624 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001625
Shuzhen Wang0129d522016-10-30 22:43:41 -07001626 if (bufferProducers.size() == 0) {
1627 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001628 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1629 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001630
Shuzhen Wang758c2152017-01-10 18:26:18 -08001631 // streamId should be in mStreamMap if this stream already has a surface attached
1632 // to it. Otherwise, it should be in mDeferredStreams.
1633 bool streamIdConfigured = false;
1634 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1635 for (size_t i = 0; i < mStreamMap.size(); i++) {
1636 if (mStreamMap.valueAt(i).streamId() == streamId) {
1637 streamIdConfigured = true;
1638 break;
1639 }
Zhijun He5d677d12016-05-29 16:52:39 -07001640 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001641 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1642 if (streamId == mDeferredStreams[i]) {
1643 deferredStreamIndex = i;
1644 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001645 }
1646
Shuzhen Wang758c2152017-01-10 18:26:18 -08001647 }
1648 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001649 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1650 "(ID %d)", mCameraIdStr.c_str(), streamId);
1651 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1652 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001653 }
1654
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001655 if (mStreamInfoMap[streamId].finalized) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001656 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1657 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1658 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1659 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001660 }
1661
Zhijun He5d677d12016-05-29 16:52:39 -07001662 if (!mDevice.get()) {
1663 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1664 }
1665
Shuzhen Wang758c2152017-01-10 18:26:18 -08001666 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001667 const std::vector<int32_t> &sensorPixelModesUsed =
1668 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001669 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001670 int32_t colorSpace = outputConfiguration.getColorSpace();
1671 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001672 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001673 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001674 for (auto& bufferProducer : bufferProducers) {
1675 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001676 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1677 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001678 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger0fb3ad92023-06-01 16:51:35 -07001679 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001680 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001681 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001682
1683 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001684 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001685 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001686 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001687 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001688
1689 if (!res.isOk())
1690 return res;
1691
1692 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001693 }
1694
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001695 // Gracefully handle case where finalizeOutputConfigurations is called
1696 // without any new surface.
1697 if (consumerSurfaces.size() == 0) {
1698 mStreamInfoMap[streamId].finalized = true;
1699 return res;
1700 }
1701
Zhijun He5d677d12016-05-29 16:52:39 -07001702 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001703 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001704 std::vector<int> consumerSurfaceIds;
1705 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001706 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001707 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1708 sp<IBinder> binder = IInterface::asBinder(
1709 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001710 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001711 binder.get(), streamId, consumerSurfaceIds[i]);
1712 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1713 }
1714 if (deferredStreamIndex != NAME_NOT_FOUND) {
1715 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001716 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001717 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001718 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001719 } else if (err == NO_INIT) {
1720 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001721 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001722 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001723 } else {
1724 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001725 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001726 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001727 }
1728
1729 return res;
1730}
1731
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001732binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001733 ATRACE_CALL();
1734 binder::Status res;
1735 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1736
1737 if (!isValidAudioRestriction(mode)) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001738 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1739 mCameraIdStr.c_str(), mode);
1740 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1741 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001742 }
1743
1744 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001745 BasicClient::setAudioRestriction(mode);
1746 return binder::Status::ok();
1747}
1748
1749binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1750 ATRACE_CALL();
1751 binder::Status res;
1752 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1753 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001754 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001755 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001756 }
1757 return binder::Status::ok();
1758}
1759
Ravneet74cd3732022-03-30 05:33:03 +00001760status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1761 return mDevice->setCameraServiceWatchdog(enabled);
1762}
1763
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001764status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop) {
1765 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1766
1767 return mDevice->setRotateAndCropAutoBehavior(
1768 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop));
1769}
1770
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001771status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1772 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1773
1774 return mDevice->setAutoframingAutoBehavior(
1775 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1776}
1777
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001778bool CameraDeviceClient::supportsCameraMute() {
1779 return mDevice->supportsCameraMute();
1780}
1781
1782status_t CameraDeviceClient::setCameraMute(bool enabled) {
1783 return mDevice->setCameraMute(enabled);
1784}
1785
Shuzhen Wangabe5ea12022-12-15 22:38:07 -08001786void CameraDeviceClient::setStreamUseCaseOverrides(
1787 const std::vector<int64_t>& useCaseOverrides) {
1788 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1789}
1790
1791void CameraDeviceClient::clearStreamUseCaseOverrides() {
1792 mDevice->clearStreamUseCaseOverrides();
1793}
1794
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001795bool CameraDeviceClient::supportsZoomOverride() {
1796 return mDevice->supportsZoomOverride();
1797}
1798
1799status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1800 return mDevice->setZoomOverride(zoomOverride);
1801}
1802
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001803binder::Status CameraDeviceClient::switchToOffline(
1804 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001805 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001806 /*out*/
1807 sp<hardware::camera2::ICameraOfflineSession>* session) {
1808 ATRACE_CALL();
1809
1810 binder::Status res;
1811 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1812
1813 Mutex::Autolock icl(mBinderSerializationLock);
1814
1815 if (!mDevice.get()) {
1816 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1817 }
1818
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001819 if (offlineOutputIds.empty()) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001820 std::string msg = "Offline surfaces must not be empty";
1821 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1822 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001823 }
1824
1825 if (session == nullptr) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001826 std::string msg = "Invalid offline session";
1827 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1828 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001829 }
1830
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001831 std::vector<int32_t> offlineStreamIds;
1832 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001833 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001834 for (const auto& streamId : offlineOutputIds) {
1835 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001836 if (index == NAME_NOT_FOUND) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001837 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001838 streamId);
Austin Borger0fb3ad92023-06-01 16:51:35 -07001839 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1840 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001841 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001842
1843 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger0fb3ad92023-06-01 16:51:35 -07001844 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001845 "offline mode", streamId);
Austin Borger0fb3ad92023-06-01 16:51:35 -07001846 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1847 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001848 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001849
Emilian Peev2f5d6012022-01-19 16:16:50 -08001850 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001851 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001852 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001853 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001854 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001855 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001856 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001857 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001858 if (isCompositeStream) {
1859 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1860 if (compositeIdx == NAME_NOT_FOUND) {
1861 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1862 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1863 "Unknown composite stream");
1864 }
1865
1866 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1867 &offlineStreamIds);
1868 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1869 mCompositeStreamMap.valueAt(compositeIdx));
1870 break;
1871 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001872 }
1873
Emilian Peev4697b642019-11-19 17:11:14 -08001874 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001875 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001876 }
1877 }
1878
1879 sp<CameraOfflineSessionBase> offlineSession;
1880 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1881 if (ret != OK) {
1882 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1883 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001884 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001885 }
1886
Emilian Peevcc0b7952020-01-07 13:54:47 -08001887 sp<CameraOfflineSessionClient> offlineClient;
1888 if (offlineSession.get() != nullptr) {
1889 offlineClient = new CameraOfflineSessionClient(sCameraService,
1890 offlineSession, offlineCompositeStreamMap, cameraCb, mClientPackageName,
Emilian Peev8b64f282021-03-25 16:49:57 -07001891 mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation, mClientPid, mClientUid,
1892 mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001893 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1894 }
1895
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001896 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001897 // A successful offline session switch must reset the current camera client
1898 // and release any resources occupied by previously configured streams.
1899 mStreamMap.clear();
1900 mConfiguredOutputs.clear();
1901 mDeferredStreams.clear();
1902 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001903 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001904 mCompositeStreamMap.clear();
1905 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001906 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001907 // In case we failed to register the offline client, ensure that it still initialized
1908 // so that all failing requests can return back correctly once the object is released.
Austin Borger0fb3ad92023-06-01 16:51:35 -07001909 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001910
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001911 switch(ret) {
1912 case BAD_VALUE:
1913 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1914 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1915 case TIMED_OUT:
1916 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1917 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1918 default:
1919 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1920 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1921 strerror(-ret), ret);
1922 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001923 }
1924
1925 *session = offlineClient;
1926
1927 return binder::Status::ok();
1928}
1929
Igor Murashkine7ee7632013-06-11 18:10:18 -07001930status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001931 return BasicClient::dump(fd, args);
1932}
1933
1934status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001935 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger0fb3ad92023-06-01 16:51:35 -07001936 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001937 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001938 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001939 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001940
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001941 dprintf(fd, " State:\n");
1942 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001943 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001944 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001945 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001946 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001947 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001948 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001949 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001950 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001951 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001952 mStreamMap.valueAt(i).streamId(),
1953 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001954 }
Zhijun He5d677d12016-05-29 16:52:39 -07001955 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001956 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001957 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001958 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001959 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001960 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001961 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001962 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001963 // TODO: print dynamic/request section from most recent requests
1964 mFrameProcessor->dump(fd, args);
1965
1966 return dumpDevice(fd, args);
1967}
1968
Austin Borger0fb3ad92023-06-01 16:51:35 -07001969status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07001970 sp<CameraDeviceBase> device = mDevice;
1971 if (!device) {
1972 dprintf(out, " Device is detached.");
1973 return OK;
1974 }
1975 device->startWatchingTags(tags);
1976 return OK;
1977}
1978
1979status_t CameraDeviceClient::stopWatchingTags(int out) {
1980 sp<CameraDeviceBase> device = mDevice;
1981 if (!device) {
1982 dprintf(out, " Device is detached.");
1983 return OK;
1984 }
1985 device->stopWatchingTags();
1986 return OK;
1987}
1988
1989status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
1990 sp<CameraDeviceBase> device = mDevice;
1991 if (!device) {
1992 return OK;
1993 }
1994 device->dumpWatchedEventsToVector(out);
1995 return OK;
1996}
1997
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001998void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07001999 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002000 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002001 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002002
Emilian Peev538c90e2018-12-17 18:03:19 +00002003 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002004 {
2005 // Access to the composite stream map must be synchronized
2006 Mutex::Autolock l(mCompositeLock);
2007 // Composites can have multiple internal streams. Error notifications coming from such
2008 // internal streams may need to remain within camera service.
2009 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2010 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2011 resultExtras);
2012 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002013 }
2014
2015 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002016 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002017 }
2018}
2019
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002020void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2021 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2022
2023 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002024 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002025 }
2026
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002027 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002028 mStreamingRequestId = REQUEST_ID_NONE;
2029}
2030
Shuzhen Wang316781a2020-08-18 18:11:01 -07002031void CameraDeviceClient::notifyIdle(
2032 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2033 const std::vector<hardware::CameraStreamStats>& streamStats) {
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
2037 if (remoteCb != 0) {
2038 remoteCb->onDeviceIdle();
2039 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002040
2041 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2042 {
2043 Mutex::Autolock l(mCompositeLock);
2044 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2045 hardware::CameraStreamStats compositeStats;
2046 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2047 if (compositeStats.mWidth > 0) {
2048 fullStreamStats.push_back(compositeStats);
2049 }
2050 }
2051 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002052 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Emilian Peev567c31c2023-03-06 15:02:37 -08002053 fullStreamStats, mUserTag, mVideoStabilizationMode);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002054}
2055
Jianing Weicb0652e2014-03-12 18:29:36 -07002056void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002057 nsecs_t timestamp) {
2058 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002059 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002060 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002061 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002062 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002063 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002064
Emilian Peev2f5d6012022-01-19 16:16:50 -08002065 // Access to the composite stream map must be synchronized
2066 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002067 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2068 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2069 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002070}
2071
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002072void CameraDeviceClient::notifyPrepared(int streamId) {
2073 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002074 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002075 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002076 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002077 remoteCb->onPrepared(streamId);
2078 }
2079}
2080
Shuzhen Wang9d066012016-09-30 11:30:20 -07002081void CameraDeviceClient::notifyRequestQueueEmpty() {
2082 // Thread safe. Don't bother locking.
2083 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2084 if (remoteCb != 0) {
2085 remoteCb->onRequestQueueEmpty();
2086 }
2087}
2088
Igor Murashkine7ee7632013-06-11 18:10:18 -07002089void CameraDeviceClient::detachDevice() {
2090 if (mDevice == 0) return;
2091
Shuzhen Wang316781a2020-08-18 18:11:01 -07002092 nsecs_t startTime = systemTime();
Austin Borger0fb3ad92023-06-01 16:51:35 -07002093 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002094
Emilian Peev7ee731f2022-02-08 14:55:52 -08002095 if (mFrameProcessor.get() != nullptr) {
2096 mFrameProcessor->removeListener(
2097 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2098 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2099 mFrameProcessor->requestExit();
Austin Borger0fb3ad92023-06-01 16:51:35 -07002100 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002101 mFrameProcessor->join();
Austin Borger0fb3ad92023-06-01 16:51:35 -07002102 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002103 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002104
2105 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2106 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002107 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002108 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002109 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2110 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2111 }
2112
Igor Murashkine7ee7632013-06-11 18:10:18 -07002113 if ((code = mDevice->waitUntilDrained()) != OK) {
2114 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2115 code);
2116 }
2117 }
2118
Emilian Peev2f5d6012022-01-19 16:16:50 -08002119 {
2120 Mutex::Autolock l(mCompositeLock);
2121 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2122 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2123 if (ret != OK) {
2124 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2125 strerror(-ret), ret);
2126 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002127 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002128 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002129 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002130
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002131 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002132 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002133
2134 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002135 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002136}
2137
2138/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002139void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002140 ATRACE_CALL();
2141 ALOGV("%s", __FUNCTION__);
2142
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002143 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002144 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002145 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002146 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2147 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002148 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002149
Emilian Peev2f5d6012022-01-19 16:16:50 -08002150 // Access to the composite stream map must be synchronized
2151 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002152 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2153 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2154 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002155}
2156
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002157binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002158 if (mDisconnected) {
2159 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2160 "The camera device has been disconnected");
2161 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002162 status_t res = checkPid(checkLocation);
2163 return (res == OK) ? binder::Status::ok() :
2164 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2165 "Attempt to use camera from a different process than original client");
2166}
2167
Igor Murashkine7ee7632013-06-11 18:10:18 -07002168// TODO: move to Camera2ClientBase
2169bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2170
Jayant Chowdhary12361932018-08-27 14:46:13 -07002171 const int pid = CameraThreadState::getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002172 const int selfPid = getpid();
2173 camera_metadata_entry_t entry;
2174
2175 /**
2176 * Mixin default important security values
2177 * - android.led.transmit = defaulted ON
2178 */
2179 CameraMetadata staticInfo = mDevice->info();
2180 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2181 for(size_t i = 0; i < entry.count; ++i) {
2182 uint8_t led = entry.data.u8[i];
2183
2184 switch(led) {
2185 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2186 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2187 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2188 metadata.update(ANDROID_LED_TRANSMIT,
2189 &transmitDefault, 1);
2190 }
2191 break;
2192 }
2193 }
2194 }
2195
2196 // We can do anything!
2197 if (pid == selfPid) {
2198 return true;
2199 }
2200
2201 /**
2202 * Permission check special fields in the request
2203 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2204 */
2205 entry = metadata.find(ANDROID_LED_TRANSMIT);
2206 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2207 String16 permissionString =
Austin Borger0fb3ad92023-06-01 16:51:35 -07002208 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002209 if (!checkCallingPermission(permissionString)) {
Jayant Chowdhary12361932018-08-27 14:46:13 -07002210 const int uid = CameraThreadState::getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002211 ALOGE("Permission Denial: "
2212 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2213 return false;
2214 }
2215 }
2216
2217 return true;
2218}
2219
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002220status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2221 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002222 ALOGV("%s: begin", __FUNCTION__);
2223
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002224 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002225 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002226}
2227
Emilian Peevf4816702020-04-03 15:44:51 -07002228binder::Status CameraDeviceClient::mapRequestTemplate(int templateId,
2229 camera_request_template_t* tempId /*out*/) {
2230 binder::Status ret = binder::Status::ok();
2231
2232 if (tempId == nullptr) {
2233 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger0fb3ad92023-06-01 16:51:35 -07002234 "Camera %s: Invalid template argument", mCameraIdStr.c_str());
Emilian Peevf4816702020-04-03 15:44:51 -07002235 return ret;
2236 }
2237 switch(templateId) {
2238 case ICameraDeviceUser::TEMPLATE_PREVIEW:
2239 *tempId = camera_request_template_t::CAMERA_TEMPLATE_PREVIEW;
2240 break;
2241 case ICameraDeviceUser::TEMPLATE_RECORD:
2242 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_RECORD;
2243 break;
2244 case ICameraDeviceUser::TEMPLATE_STILL_CAPTURE:
2245 *tempId = camera_request_template_t::CAMERA_TEMPLATE_STILL_CAPTURE;
2246 break;
2247 case ICameraDeviceUser::TEMPLATE_VIDEO_SNAPSHOT:
2248 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_SNAPSHOT;
2249 break;
2250 case ICameraDeviceUser::TEMPLATE_ZERO_SHUTTER_LAG:
2251 *tempId = camera_request_template_t::CAMERA_TEMPLATE_ZERO_SHUTTER_LAG;
2252 break;
2253 case ICameraDeviceUser::TEMPLATE_MANUAL:
2254 *tempId = camera_request_template_t::CAMERA_TEMPLATE_MANUAL;
2255 break;
2256 default:
2257 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
2258 "Camera %s: Template ID %d is invalid or not supported",
Austin Borger0fb3ad92023-06-01 16:51:35 -07002259 mCameraIdStr.c_str(), templateId);
Emilian Peevf4816702020-04-03 15:44:51 -07002260 return ret;
2261 }
2262
2263 return ret;
2264}
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002265
Austin Borger0fb3ad92023-06-01 16:51:35 -07002266const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002267 if (mDevice->getId() == cameraId) {
2268 return mDevice->info();
2269 }
2270 return mDevice->infoPhysical(cameraId);
2271}
2272
Xin Li65d53082023-08-25 14:16:11 -07002273bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002274 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002275 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002276}
2277
2278bool CameraDeviceClient::isSensorPixelModeConsistent(
2279 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2280 // First we get the sensorPixelMode from the settings metadata.
2281 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2282 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2283 if (sensorPixelModeEntry.count != 0) {
2284 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2285 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2286 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2287 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2288 __FUNCTION__, sensorPixelMode);
2289 return false;
2290 }
2291 }
2292 // Check whether each stream has max resolution allowed.
2293 bool consistent = true;
2294 for (auto it : streamIdList) {
2295 auto const streamInfoIt = mStreamInfoMap.find(it);
2296 if (streamInfoIt == mStreamInfoMap.end()) {
2297 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2298 return false;
2299 }
2300 consistent =
2301 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2302 streamInfoIt->second.sensorPixelModesUsed.end();
2303 if (!consistent) {
2304 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2305 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2306 ALOGE("sensor pixel mode used list: %i", m);
2307 }
2308 break;
2309 }
2310 }
2311
2312 return consistent;
2313}
2314
Igor Murashkine7ee7632013-06-11 18:10:18 -07002315} // namespace android