blob: 7c2f71c670f9c018242ec5a0a0f09af0aa50a36f [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Igor Murashkine7ee7632013-06-11 18:10:18 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "CameraDeviceClient"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
Jianing Weicb0652e2014-03-12 18:29:36 -070019//#define LOG_NDEBUG 0
Igor Murashkine7ee7632013-06-11 18:10:18 -070020
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -070021#include <com_android_internal_camera_flags.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070022#include <cutils/properties.h>
Jayant Chowdhary12361932018-08-27 14:46:13 -070023#include <utils/CameraThreadState.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070024#include <utils/Log.h>
Colin Crossb8a9dbb2020-08-27 04:12:26 +000025#include <utils/SessionConfigurationUtils.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070026#include <utils/Trace.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070027#include <gui/Surface.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070028#include <camera/camera2/CaptureRequest.h>
Ruben Brunk5698d442014-06-18 10:39:40 -070029#include <camera/CameraUtils.h>
Austin Borger1c1bee02023-06-01 16:51:35 -070030#include <camera/StringUtils.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070031
32#include "common/CameraDeviceBase.h"
Emilian Peev35ae8262018-11-08 13:11:32 +000033#include "device3/Camera3Device.h"
34#include "device3/Camera3OutputStream.h"
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070035#include "api2/CameraDeviceClient.h"
36
Emilian Peev00420d22018-02-05 21:33:13 +000037#include <camera_metadata_hidden.h>
38
Emilian Peev538c90e2018-12-17 18:03:19 +000039#include "DepthCompositeStream.h"
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080040#include "HeicCompositeStream.h"
Emilian Peev434248e2022-10-06 14:58:54 -070041#include "JpegRCompositeStream.h"
Emilian Peev538c90e2018-12-17 18:03:19 +000042
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080043// Convenience methods for constructing binder::Status objects for error returns
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070044
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080045#define STATUS_ERROR(errorCode, errorString) \
46 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070047 fmt::sprintf("%s:%d: %s", __FUNCTION__, __LINE__, errorString).c_str())
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080048
49#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
50 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070051 fmt::sprintf("%s:%d: " errorString, __FUNCTION__, __LINE__, \
52 __VA_ARGS__).c_str())
Igor Murashkine7ee7632013-06-11 18:10:18 -070053
54namespace android {
55using namespace camera2;
Austin Borgerea931242021-12-13 23:10:41 +000056using namespace camera3;
Emilian Peevf4816702020-04-03 15:44:51 -070057using camera3::camera_stream_rotation_t::CAMERA_STREAM_ROTATION_0;
Igor Murashkine7ee7632013-06-11 18:10:18 -070058
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -070059namespace flags = com::android::internal::camera::flags;
60
Igor Murashkine7ee7632013-06-11 18:10:18 -070061CameraDeviceClientBase::CameraDeviceClientBase(
62 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080063 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger249e6592024-03-10 22:28:11 -070064 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borger1c1bee02023-06-01 16:51:35 -070065 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080066 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070067 const std::optional<std::string>& clientFeatureId,
68 const std::string& cameraId,
Jing Mikec7f9b132023-03-12 11:12:04 +080069 [[maybe_unused]] int api1CameraId,
Igor Murashkine7ee7632013-06-11 18:10:18 -070070 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070071 int sensorOrientation,
Igor Murashkine7ee7632013-06-11 18:10:18 -070072 int clientPid,
73 uid_t clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070074 int servicePid,
75 bool overrideToPortrait) :
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080076 BasicClient(cameraService,
Marco Nelissenf8880202014-11-14 07:58:25 -080077 IInterface::asBinder(remoteCallback),
Austin Borger249e6592024-03-10 22:28:11 -070078 attributionAndPermissionUtils,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080079 clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080080 systemNativeClient,
Philip P. Moltmann9e648f62019-11-04 12:52:45 -080081 clientFeatureId,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080082 cameraId,
83 cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070084 sensorOrientation,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080085 clientPid,
86 clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070087 servicePid,
88 overrideToPortrait),
Igor Murashkine7ee7632013-06-11 18:10:18 -070089 mRemoteCallback(remoteCallback) {
90}
Igor Murashkine7ee7632013-06-11 18:10:18 -070091
92// Interface used by CameraService
93
94CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080095 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070096 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger249e6592024-03-10 22:28:11 -070097 std::shared_ptr<AttributionAndPermissionUtils> attributionAndPermissionUtils,
Austin Borger1c1bee02023-06-01 16:51:35 -070098 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080099 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -0700100 const std::optional<std::string>& clientFeatureId,
101 const std::string& cameraId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800102 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -0700103 int sensorOrientation,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800104 int clientPid,
105 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700106 int servicePid,
Austin Borger18b30a72022-10-27 12:20:29 -0700107 bool overrideForPerfClass,
malikakash73125c62023-07-21 22:44:34 +0000108 bool overrideToPortrait,
109 const std::string& originalCameraId) :
Austin Borger249e6592024-03-10 22:28:11 -0700110 Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper,
111 attributionAndPermissionUtils, clientPackageName,
Austin Borger74fca042022-05-23 12:41:21 -0700112 systemNativeClient, clientFeatureId, cameraId, /*API1 camera ID*/ -1, cameraFacing,
Austin Borger18b30a72022-10-27 12:20:29 -0700113 sensorOrientation, clientPid, clientUid, servicePid, overrideForPerfClass,
114 overrideToPortrait),
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700115 mInputStream(),
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700116 mStreamingRequestId(REQUEST_ID_NONE),
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700117 mRequestIdCounter(0),
malikakash73125c62023-07-21 22:44:34 +0000118 mOverrideForPerfClass(overrideForPerfClass),
119 mOriginalCameraId(originalCameraId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700120 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -0700121 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700122}
123
Emilian Peevbd8c5032018-02-14 23:05:40 +0000124status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -0700125 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000126 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800127}
128
129template<typename TProviderPtr>
Austin Borger1c1bee02023-06-01 16:51:35 -0700130status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
131 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700132 ATRACE_CALL();
133 status_t res;
134
Emilian Peevbd8c5032018-02-14 23:05:40 +0000135 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700136 if (res != OK) {
137 return res;
138 }
139
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700140 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger1c1bee02023-06-01 16:51:35 -0700141 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
142 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700143 if (res != OK) {
144 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
145 __FUNCTION__, strerror(-res), res);
146 return res;
147 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700148
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800149 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
150 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800151 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700152 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700153
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800154 const CameraMetadata &deviceInfo = mDevice->info();
155 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000156 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
157 if (physicalKeysEntry.count > 0) {
158 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
159 physicalKeysEntry.data.i32,
160 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
161 }
162
Emilian Peev2295df72021-11-12 18:14:10 -0800163 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
164 mDynamicProfileMap.emplace(
165 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
166 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
167 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800168 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800169 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800170 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800171 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800172 if (entry.count > 0 || ((entry.count % 3) != 0)) {
173 int64_t standardBitmap =
174 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
175 for (size_t i = 0; i < entry.count; i += 3) {
176 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800177 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800178 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
179 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800180 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800181 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800182 }
183 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800184 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
185 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800186 }
187 }
Emilian Peevef715e22022-05-19 17:44:33 -0700188 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
189 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800190 } else {
191 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
192 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
193 }
194 }
195 }
196
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700197 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800198 // Cache physical camera ids corresponding to this device and also the high
199 // resolution sensors in this device + physical camera ids
Austin Borger1c1bee02023-06-01 16:51:35 -0700200 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800201 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700202 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800203 }
204 for (auto &physicalId : mPhysicalCameraIds) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700205 if (supportsUltraHighResolutionCapture(physicalId)) {
206 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800207 }
208 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700209 return OK;
210}
211
212CameraDeviceClient::~CameraDeviceClient() {
213}
214
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800215binder::Status CameraDeviceClient::submitRequest(
216 const hardware::camera2::CaptureRequest& request,
217 bool streaming,
218 /*out*/
219 hardware::camera2::utils::SubmitInfo *submitInfo) {
220 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
221 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700222}
223
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800224binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000225 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000226 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800227 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
228
Emilian Peev2f5d6012022-01-19 16:16:50 -0800229 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800230 // Trying to submit request with surface that wasn't created
231 if (idx == NAME_NOT_FOUND) {
232 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
233 " we have not called createStream on",
Austin Borger1c1bee02023-06-01 16:51:35 -0700234 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800235 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
236 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000237 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
238 != NAME_NOT_FOUND) {
239 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
240 currentStreamId);
241 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800242 }
243
244 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
245 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800246 outputStreamIds->push_back(streamSurfaceId.streamId());
247 }
248 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
249
250 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700251 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800252 streamSurfaceId.surfaceId());
253
Emilian Peevf873aa52018-01-26 14:58:28 +0000254 if (currentStreamId != nullptr) {
255 *currentStreamId = streamSurfaceId.streamId();
256 }
257
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800258 return binder::Status::ok();
259}
260
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800261static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
262 const Vector<int> &streamIdsForThisRequest) {
263 std::list<int> intersection;
264 for (auto &streamId : streamIdsForThisRequest) {
265 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
266 intersection.emplace_back(streamId);
267 }
268 }
269 return intersection;
270}
271
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800272binder::Status CameraDeviceClient::submitRequestList(
273 const std::vector<hardware::camera2::CaptureRequest>& requests,
274 bool streaming,
275 /*out*/
276 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700277 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700278 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700279
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800280 binder::Status res = binder::Status::ok();
281 status_t err;
282 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
283 return res;
284 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700285
286 Mutex::Autolock icl(mBinderSerializationLock);
287
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800288 if (!mDevice.get()) {
289 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
290 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700291
292 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800293 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700294 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800295 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700296 }
297
Emilian Peevaebbe412018-01-15 13:53:24 +0000298 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700299 std::list<const SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800300 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700301 uint32_t loopCounter = 0;
302
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800303 for (auto&& request: requests) {
304 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700305 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800306 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700307 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800308 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800309 "No input configured for camera %s but request is for reprocessing",
Austin Borger1c1bee02023-06-01 16:51:35 -0700310 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700311 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800312 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700313 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800314 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
315 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000316 } else if (request.mPhysicalCameraSettings.size() > 1) {
317 ALOGE("%s: Camera %s: reprocess requests not supported for "
318 "multiple physical cameras.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700319 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000320 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
321 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700322 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700323 }
324
Emilian Peevaebbe412018-01-15 13:53:24 +0000325 if (request.mPhysicalCameraSettings.empty()) {
326 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700327 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800328 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000329 "Request doesn't contain any settings");
330 }
331
332 //The first capture settings should always match the logical camera id
Austin Borger1c1bee02023-06-01 16:51:35 -0700333 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
malikakash73125c62023-07-21 22:44:34 +0000334 if (mDevice->getId() != logicalId && mOriginalCameraId != logicalId) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000335 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700336 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000337 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
338 "Invalid camera request settings");
339 }
340
Emilian Peevaebbe412018-01-15 13:53:24 +0000341 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800342 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger1c1bee02023-06-01 16:51:35 -0700343 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800344 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
345 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700346 }
347
Jianing Wei90e59c92014-03-12 18:29:36 -0700348 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700349 * Write in the output stream IDs and map from stream ID to surface ID
350 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700351 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700352 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700353 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000354 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800355 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800356 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800357 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800358 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700359
Emilian Peevf873aa52018-01-26 14:58:28 +0000360 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800361 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000362 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800363 if (!res.isOk()) {
364 return res;
365 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000366
367 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
368 if (index >= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700369 const std::string &requestedPhysicalId =
370 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
371 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800372 dynamicProfileBitmap |=
373 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000374 } else {
375 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
376 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700377 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800378 } else {
379 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
380 int streamId = request.mStreamIdxList.itemAt(i);
381 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700382
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800383 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
384 if (index < 0) {
385 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
386 " we have not called createStream on: stream %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700387 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800388 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
389 "Request targets Surface that is not part of current capture session");
390 }
391
392 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
393 if ((size_t)surfaceIdx >= gbps.size()) {
394 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
395 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700396 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800397 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
398 "Request targets Surface has invalid surface index");
399 }
400
Emilian Peevf873aa52018-01-26 14:58:28 +0000401 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800402 if (!res.isOk()) {
403 return res;
404 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000405
Austin Borger1c1bee02023-06-01 16:51:35 -0700406 const std::string &requestedPhysicalId =
407 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
408 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800409 dynamicProfileBitmap |=
410 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
411 }
412 }
413
414 if (dynamicProfileBitmap !=
415 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
416 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
417 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
418 if ((dynamicProfileBitmap & i) == 0) {
419 continue;
420 }
421
422 const auto& it = mDynamicProfileMap.find(i);
423 if (it != mDynamicProfileMap.end()) {
424 if ((it->second == 0) ||
425 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
426 continue;
427 } else {
428 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
429 " reference an unsupported dynamic range profile combination"
Austin Borger1c1bee02023-06-01 16:51:35 -0700430 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800431 dynamicProfileBitmap);
432 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
433 "Request targets an unsupported dynamic range profile"
434 " combination");
435 }
436 } else {
437 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
438 " references unsupported dynamic range profile 0x%x!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700439 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800440 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
441 "Request targets 10-bit Surface with unsupported dynamic range"
442 " profile");
443 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700444 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700445 }
446
Emilian Peevf873aa52018-01-26 14:58:28 +0000447 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
448 for (const auto& it : request.mPhysicalCameraSettings) {
malikakash73125c62023-07-21 22:44:34 +0000449 const std::string resolvedId = (mOriginalCameraId == it.id) ? mDevice->getId() : it.id;
Emilian Peev00420d22018-02-05 21:33:13 +0000450 if (it.settings.isEmpty()) {
451 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700452 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000453 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
454 "Request settings are empty");
455 }
456
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800457 // Check whether the physical / logical stream has settings
458 // consistent with the sensor pixel mode(s) it was configured with.
459 // mCameraIdToStreamSet will only have ids that are high resolution
malikakash73125c62023-07-21 22:44:34 +0000460 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(resolvedId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800461 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
462 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
463 outputStreamIds);
464 if (!request.mIsReprocess &&
465 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
466 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
467 "consistent with configured streams. Rejecting request.",
malikakash73125c62023-07-21 22:44:34 +0000468 __FUNCTION__, resolvedId.c_str());
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800469 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
470 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
471 "streams configured");
472 }
473 }
474
malikakash73125c62023-07-21 22:44:34 +0000475 const std::string &physicalId = resolvedId;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700476 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
477 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
478 mSupportedPhysicalRequestKeys.end();
479 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
480 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
481 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000482 if (physicalId != mDevice->getId()) {
483 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
malikakash73125c62023-07-21 22:44:34 +0000484 resolvedId);
Emilian Peevf873aa52018-01-26 14:58:28 +0000485 if (found == requestedPhysicalIds.end()) {
486 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700487 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000488 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
489 "Invalid physical camera id");
490 }
Emilian Peev00420d22018-02-05 21:33:13 +0000491
492 if (!mSupportedPhysicalRequestKeys.empty()) {
493 // Filter out any unsupported physical request keys.
494 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
495 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
496 filteredParams.getAndLock());
497 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
498 filteredParams.unlock(meta);
499
500 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
501 camera_metadata_ro_entry entry = it.settings.find(keyIt);
502 if (entry.count > 0) {
503 filteredParams.update(entry);
504 }
505 }
506
malikakash73125c62023-07-21 22:44:34 +0000507 physicalSettingsList.push_back({resolvedId, filteredParams,
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700508 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000509 }
510 } else {
malikakash73125c62023-07-21 22:44:34 +0000511 physicalSettingsList.push_back({resolvedId, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000512 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000513 }
514
515 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
516 // Callee logs
517 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
518 "Caller does not have permission to change restricted controls");
519 }
520
Emilian Peevaebbe412018-01-15 13:53:24 +0000521 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
522 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700523
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800524 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000525 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
526 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700527 }
528
Emilian Peevaebbe412018-01-15 13:53:24 +0000529 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
530 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700531 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800532 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700533 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800534 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700535
Emilian Peevaebbe412018-01-15 13:53:24 +0000536 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700537 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800538
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700539 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800540 if (!request.mUserTag.empty()) {
541 mUserTag = request.mUserTag;
542 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700543 camera_metadata_entry entry =
544 physicalSettingsList.begin()->metadata.find(
545 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
546 if (entry.count == 1) {
547 mVideoStabilizationMode = entry.data.u8[0];
548 }
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -0700549 if (flags::log_ultrawide_usage()) {
550 entry = physicalSettingsList.begin()->metadata.find(
551 ANDROID_CONTROL_ZOOM_RATIO);
552 if (entry.count == 1 && entry.data.f[0] < 1.0f ) {
553 mUsedUltraWide = true;
554 }
555 }
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000556 if (!mUsedSettingsOverrideZoom && flags::log_zoom_override_usage()) {
557 entry = physicalSettingsList.begin()->metadata.find(
558 ANDROID_CONTROL_SETTINGS_OVERRIDE);
559 if (entry.count == 1 && entry.data.i32[0] ==
560 ANDROID_CONTROL_SETTINGS_OVERRIDE_ZOOM) {
561 mUsedSettingsOverrideZoom = true;
562 }
563 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700564 }
565 mRequestIdCounter++;
566
567 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700568 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
569 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800570 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700571 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800572 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700573 mCameraIdStr.c_str(), strerror(-err), err);
574 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800575 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700576 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700577 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700578 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700579 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700580 }
581 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700582 err = mDevice->captureList(metadataRequestList, surfaceMapList,
583 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800584 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700585 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800586 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700587 mCameraIdStr.c_str(), strerror(-err), err);
588 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800589 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700590 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700591 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800592 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700593 }
594
Austin Borger1c1bee02023-06-01 16:51:35 -0700595 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700596 return res;
597}
598
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800599binder::Status CameraDeviceClient::cancelRequest(
600 int requestId,
601 /*out*/
602 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700603 ATRACE_CALL();
604 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
605
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800606 status_t err;
607 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700608
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800609 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700610
611 Mutex::Autolock icl(mBinderSerializationLock);
612
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800613 if (!mDevice.get()) {
614 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
615 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700616
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700617 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700618 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700619 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
620 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
621 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
622 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700623 }
624
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800625 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700626
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800627 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800628 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700629 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700630 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800631 } else {
632 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800633 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700634 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700635 }
636
637 return res;
638}
639
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800640binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700641 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700642 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700643 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800644 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700645}
646
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100647binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700648 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800649 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700650 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700651 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
652 __FUNCTION__, mInputStream.configured ? 1 : 0,
653 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700654
Zhijun He0effd522016-03-04 10:22:27 -0800655 binder::Status res;
656 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
657
Emilian Peevcc0b7952020-01-07 13:54:47 -0800658 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700659 std::string msg = "Invalid offline stream ids";
660 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
661 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800662 }
663
Zhijun He0effd522016-03-04 10:22:27 -0800664 Mutex::Autolock icl(mBinderSerializationLock);
665
666 if (!mDevice.get()) {
667 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
668 }
669
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700670 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000671 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000672 if (!res.isOk()) {
673 return res;
674 }
675
676 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
677 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700678 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
679 mCameraIdStr.c_str());
680 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
681 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000682 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700683 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
684 mCameraIdStr.c_str(), strerror(-err), err);
685 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
686 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000687 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800688 offlineStreamIds->clear();
689 mDevice->getOfflineStreamIds(offlineStreamIds);
690
Emilian Peev2f5d6012022-01-19 16:16:50 -0800691 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000692 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
693 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800694 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700695 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
696 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
697 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
698 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000699 break;
700 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800701
702 // Composite streams can only support offline mode in case all individual internal
703 // streams are also supported.
704 std::vector<int> internalStreams;
705 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800706 offlineStreamIds->erase(
707 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800708 [&internalStreams] (int streamId) {
709 auto it = std::find(internalStreams.begin(), internalStreams.end(),
710 streamId);
711 if (it != internalStreams.end()) {
712 internalStreams.erase(it);
713 return true;
714 }
715
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800716 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800717 if (internalStreams.empty()) {
718 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
719 }
720 }
721
722 for (const auto& offlineStreamId : *offlineStreamIds) {
723 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000724 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700725
726 nsecs_t configureEnd = systemTime();
727 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700728 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700729 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000730 }
731
732 return res;
733}
734
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800735binder::Status CameraDeviceClient::isSessionConfigurationSupported(
736 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800737
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800738 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800739 binder::Status res;
740 status_t ret = OK;
741 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
742
743 Mutex::Autolock icl(mBinderSerializationLock);
744
745 if (!mDevice.get()) {
746 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
747 }
748
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800749 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700750 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
751 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
752 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800753 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700754
Emilian Peev35ae8262018-11-08 13:11:32 +0000755 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700756 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700757 sessionConfiguration, mOverrideForPerfClass, /*checkSessionParams*/false,
758 status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000759 switch (ret) {
760 case OK:
761 // Expected, do nothing.
762 break;
763 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700764 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000765 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700766 mCameraIdStr.c_str());
767 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
768 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000769 }
770
771 break;
772 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700773 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000774 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700775 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000776 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700777 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000778 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800779 }
780
781 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700782}
783
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800784binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700785 ATRACE_CALL();
786 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
787
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800788 binder::Status res;
789 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700790
791 Mutex::Autolock icl(mBinderSerializationLock);
792
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800793 if (!mDevice.get()) {
794 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
795 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700796
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700797 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700798 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700799 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000800 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700801
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700802 if (mInputStream.configured && mInputStream.id == streamId) {
803 isInput = true;
804 } else {
805 // Guard against trying to delete non-created streams
806 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700807 if (streamId == mStreamMap.valueAt(i).streamId()) {
808 surfaces.push_back(mStreamMap.keyAt(i));
809 }
810 }
811
812 // See if this stream is one of the deferred streams.
813 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
814 if (streamId == mDeferredStreams[i]) {
815 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700816 break;
817 }
818 }
819
Emilian Peev2f5d6012022-01-19 16:16:50 -0800820 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000821 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
822 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
823 compositeIndex = i;
824 break;
825 }
826 }
827
Shuzhen Wang0129d522016-10-30 22:43:41 -0700828 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700829 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
830 " stream created yet", mCameraIdStr.c_str(), streamId);
831 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
832 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700833 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700834 }
835
836 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800837 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700838
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800839 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700840 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
841 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
842 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
843 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800844 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700845 if (isInput) {
846 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700847 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700848 for (auto& surface : surfaces) {
849 mStreamMap.removeItem(surface);
850 }
851
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800852 mConfiguredOutputs.removeItem(streamId);
853
Shuzhen Wang0129d522016-10-30 22:43:41 -0700854 if (dIndex != NAME_NOT_FOUND) {
855 mDeferredStreams.removeItemsAt(dIndex);
856 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000857
858 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800859 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000860 status_t ret;
861 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
862 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700863 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
864 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
865 err, streamId);
866 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
867 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000868 }
869 mCompositeStreamMap.removeItemsAt(compositeIndex);
870 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800871 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
872 auto &streamSet = mapIt.second;
873 if (streamSet.find(streamId) != streamSet.end()) {
874 streamSet.erase(streamId);
875 break;
876 }
877 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700878 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700879 }
880
881 return res;
882}
883
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800884binder::Status CameraDeviceClient::createStream(
885 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
886 /*out*/
887 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700888 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700889
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800890 binder::Status res;
891 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700892
893 Mutex::Autolock icl(mBinderSerializationLock);
894
Shuzhen Wang0129d522016-10-30 22:43:41 -0700895 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
896 outputConfiguration.getGraphicBufferProducers();
897 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800898 bool deferredConsumer = outputConfiguration.isDeferred();
899 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700900 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800901 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800902 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800903 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800904 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800905 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800906 int mirrorMode = outputConfiguration.getMirrorMode();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700907 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000908 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700909
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700910 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Emilian Peev35ae8262018-11-08 13:11:32 +0000911 outputConfiguration.getSurfaceType());
912 if (!res.isOk()) {
913 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700914 }
Zhijun He5d677d12016-05-29 16:52:39 -0700915
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800916 if (!mDevice.get()) {
917 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
918 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700919 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800920 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000921 if (!res.isOk()) {
922 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800923 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000924
Shuzhen Wang0129d522016-10-30 22:43:41 -0700925 std::vector<sp<Surface>> surfaces;
926 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700927 status_t err;
928
929 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700930 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800931 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700932 }
933
Shuzhen Wang758c2152017-01-10 18:26:18 -0800934 OutputStreamInfo streamInfo;
935 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800936 const std::vector<int32_t> &sensorPixelModesUsed =
937 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700938 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700939 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700940 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800941 ssize_t index = mStreamMap.indexOfKey(binder);
942 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700943 std::string msg = std::string("Camera ") + mCameraIdStr
944 + ": Surface already has a stream created for it (ID "
945 + std::to_string(index) + ")";
946 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
947 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700948 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700949
Shuzhen Wang758c2152017-01-10 18:26:18 -0800950 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700951 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800952 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800953 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700954 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800955
956 if (!res.isOk())
957 return res;
958
959 if (!isStreamInfoValid) {
960 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700961 }
962
Shuzhen Wang758c2152017-01-10 18:26:18 -0800963 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang0129d522016-10-30 22:43:41 -0700964 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -0800965 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700966
967 // If mOverrideForPerfClass is true, do not fail createStream() for small
968 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
969 // closest possible supported size.
970
Zhijun He125684a2015-12-26 15:07:30 -0800971 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100972 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800973 bool isDepthCompositeStream =
974 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0]);
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800975 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(surfaces[0]);
Emilian Peev434248e2022-10-06 14:58:54 -0700976 bool isJpegRCompositeStream =
Emilian Peeve579d8b2023-02-28 14:16:08 -0800977 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0]) &&
Emilian Peev15230142023-04-27 20:22:54 +0000978 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800979 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800980 sp<CompositeStream> compositeStream;
981 if (isDepthCompositeStream) {
982 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800983 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800984 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -0700985 } else {
986 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800987 }
988
Emilian Peev538c90e2018-12-17 18:03:19 +0000989 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
990 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -0700991 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800992 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -0700993 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000994 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
995 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000996 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800997 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000998 mCompositeStreamMap.add(IInterface::asBinder(surfaces[0]->getIGraphicBufferProducer()),
999 compositeStream);
1000 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08001001 } else {
1002 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
1003 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001004 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001005 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -08001006 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -08001007 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001008 streamInfo.timestampBase, streamInfo.mirrorMode, streamInfo.colorSpace,
1009 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001010 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001011
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001012 if (err != OK) {
1013 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001014 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001015 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Henri Chataingbcb99452023-11-01 17:40:30 +00001016 static_cast<int>(streamInfo.dataSpace), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001017 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001018 int i = 0;
1019 for (auto& binder : binders) {
1020 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1021 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001022 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1023 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001024 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001025
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001026 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001027 mStreamInfoMap[streamId] = streamInfo;
1028
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001029 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001030 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001031 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001032 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001033
Zhijun He5d677d12016-05-29 16:52:39 -07001034 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001035 res = setStreamTransformLocked(streamId, streamInfo.mirrorMode);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001036
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001037 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001038 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001039 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001040 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001041 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001042 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001043 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001044 }
1045
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001046 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001047 }
1048
1049 return res;
1050}
1051
Zhijun He5d677d12016-05-29 16:52:39 -07001052binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1053 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001054 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001055 /*out*/
1056 int* newStreamId) {
1057 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001058 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001059 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001060 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001061 status_t err;
1062 binder::Status res;
1063
1064 if (!mDevice.get()) {
1065 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1066 }
1067
1068 // Infer the surface info for deferred surface stream creation.
1069 width = outputConfiguration.getWidth();
1070 height = outputConfiguration.getHeight();
1071 surfaceType = outputConfiguration.getSurfaceType();
1072 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1073 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001074 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001075 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1076 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1077 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1078 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1079 }
1080 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001081 std::vector<sp<Surface>> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001082 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001083 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1084 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001085 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1086 // Here, we override sensor pixel modes
1087 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1088 const std::vector<int32_t> &sensorPixelModesUsed =
1089 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001090 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001091 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001092 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001093 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1094 "sensor pixel modes used not valid for deferred stream");
1095 }
1096
Shuzhen Wang0129d522016-10-30 22:43:41 -07001097 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1098 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001099 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001100 &streamId, physicalCameraId,
1101 overriddenSensorPixelModesUsed,
1102 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001103 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001104 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001105 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001106 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001107 outputConfiguration.getMirrorMode(),
1108 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001109
1110 if (err != OK) {
1111 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001112 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Henri Chataingbcb99452023-11-01 17:40:30 +00001113 mCameraIdStr.c_str(), width, height, format, static_cast<int>(dataSpace),
1114 strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001115 } else {
1116 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1117 // a separate list to track. Once the deferred surface is set, this id will be
1118 // relocated to mStreamMap.
1119 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001120 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001121 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001122 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001123 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001124 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001125 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001126 outputConfiguration.getMirrorMode(),
1127 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001128
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001129 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001130 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001131 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001132
1133 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001134 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001135
1136 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001137 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001138 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001139 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001140 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001141 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001142 }
Zhijun He5d677d12016-05-29 16:52:39 -07001143 }
1144 return res;
1145}
1146
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001147binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001148 int32_t transform = 0;
1149 status_t err;
1150 binder::Status res;
1151
1152 if (!mDevice.get()) {
1153 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1154 }
1155
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001156 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001157 if (err != OK) {
1158 // Error logged by getRotationTransformLocked.
1159 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1160 "Unable to calculate rotation transform for new stream");
1161 }
1162
1163 err = mDevice->setStreamTransform(streamId, transform);
1164 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001165 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001166 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001167 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1168 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001169 }
1170
1171 return res;
1172}
Ruben Brunkbba75572014-11-20 17:29:50 -08001173
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001174binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001175 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001176 /*out*/
1177 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001178
1179 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001180 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1181 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001182
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001183 binder::Status res;
1184 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001185
1186 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001187
1188 if (!mDevice.get()) {
1189 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1190 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001191
1192 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001193 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1194 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1195 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1196 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001197 }
1198
1199 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001200 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001201 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001202 mInputStream.configured = true;
1203 mInputStream.width = width;
1204 mInputStream.height = height;
1205 mInputStream.format = format;
1206 mInputStream.id = streamId;
1207
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001208 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001209 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001210
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001211 *newStreamId = streamId;
1212 } else {
1213 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001214 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001215 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001216 }
1217
1218 return res;
1219}
1220
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001221binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001222
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001223 binder::Status res;
1224 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1225
1226 if (inputSurface == NULL) {
1227 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001228 }
1229
1230 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001231 if (!mDevice.get()) {
1232 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1233 }
1234 sp<IGraphicBufferProducer> producer;
1235 status_t err = mDevice->getInputBufferProducer(&producer);
1236 if (err != OK) {
1237 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001238 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001239 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001240 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001241 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001242 inputSurface->graphicBufferProducer = producer;
1243 }
1244 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001245}
1246
Emilian Peev40ead602017-09-26 15:46:36 +01001247binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1248 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1249 ATRACE_CALL();
1250
1251 binder::Status res;
1252 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1253
1254 Mutex::Autolock icl(mBinderSerializationLock);
1255
1256 if (!mDevice.get()) {
1257 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1258 }
1259
1260 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1261 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001262 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001263
Emilian Peev40ead602017-09-26 15:46:36 +01001264 auto producerCount = bufferProducers.size();
1265 if (producerCount == 0) {
1266 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1267 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1268 "bufferProducers must not be empty");
1269 }
1270
1271 // The first output is the one associated with the output configuration.
1272 // It should always be present, valid and the corresponding stream id should match.
1273 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1274 ssize_t index = mStreamMap.indexOfKey(binder);
1275 if (index == NAME_NOT_FOUND) {
1276 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1277 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1278 "OutputConfiguration is invalid");
1279 }
1280 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1281 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1282 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1283 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1284 "Stream id is invalid");
1285 }
1286
1287 std::vector<size_t> removedSurfaceIds;
1288 std::vector<sp<IBinder>> removedOutputs;
1289 std::vector<sp<Surface>> newOutputs;
1290 std::vector<OutputStreamInfo> streamInfos;
1291 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1292 for (auto &it : bufferProducers) {
1293 newOutputsMap.add(IInterface::asBinder(it), it);
1294 }
1295
1296 for (size_t i = 0; i < mStreamMap.size(); i++) {
1297 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1298 if (idx == NAME_NOT_FOUND) {
1299 if (mStreamMap[i].streamId() == streamId) {
1300 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1301 removedOutputs.push_back(mStreamMap.keyAt(i));
1302 }
1303 } else {
1304 if (mStreamMap[i].streamId() != streamId) {
1305 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1306 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1307 "Target Surface is invalid");
1308 }
1309 newOutputsMap.removeItemsAt(idx);
1310 }
1311 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001312 const std::vector<int32_t> &sensorPixelModesUsed =
1313 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001314 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001315 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001316 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001317 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001318 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001319
Emilian Peev40ead602017-09-26 15:46:36 +01001320 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1321 OutputStreamInfo outInfo;
1322 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001323 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001324 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001325 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001326 streamUseCase, timestampBase, mirrorMode, colorSpace);
Emilian Peev40ead602017-09-26 15:46:36 +01001327 if (!res.isOk())
1328 return res;
1329
Emilian Peev40ead602017-09-26 15:46:36 +01001330 streamInfos.push_back(outInfo);
1331 newOutputs.push_back(surface);
1332 }
1333
1334 //Trivial case no changes required
1335 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1336 return binder::Status::ok();
1337 }
1338
1339 KeyedVector<sp<Surface>, size_t> outputMap;
1340 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1341 &outputMap);
1342 if (ret != OK) {
1343 switch (ret) {
1344 case NAME_NOT_FOUND:
1345 case BAD_VALUE:
1346 case -EBUSY:
1347 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1348 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001349 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001350 break;
1351 default:
1352 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1353 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001354 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001355 break;
1356 }
1357 } else {
1358 for (const auto &it : removedOutputs) {
1359 mStreamMap.removeItem(it);
1360 }
1361
1362 for (size_t i = 0; i < outputMap.size(); i++) {
1363 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1364 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1365 }
1366
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001367 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1368
Emilian Peev40ead602017-09-26 15:46:36 +01001369 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001370 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001371 }
1372
1373 return res;
1374}
1375
Igor Murashkine7ee7632013-06-11 18:10:18 -07001376// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001377binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1378 /*out*/
1379 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001380{
1381 ATRACE_CALL();
1382 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1383
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001384 binder::Status res;
1385 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001386
1387 Mutex::Autolock icl(mBinderSerializationLock);
1388
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001389 if (!mDevice.get()) {
1390 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1391 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001392
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001393 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001394 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
Shuzhen Wang045be6c2023-10-12 10:01:10 -07001395 res = SessionConfigurationUtils::mapRequestTemplateFromClient(
1396 mCameraIdStr, templateId, &tempId);
1397 if (!res.isOk()) return res;
Emilian Peevf4816702020-04-03 15:44:51 -07001398
1399 CameraMetadata metadata;
1400 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001401 request != NULL) {
1402
1403 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001404 } else if (err == BAD_VALUE) {
1405 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001406 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001407 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001408
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001409 } else {
1410 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001411 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001412 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001413 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001414 return res;
1415}
1416
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001417binder::Status CameraDeviceClient::getCameraInfo(
1418 /*out*/
1419 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001420{
1421 ATRACE_CALL();
1422 ALOGV("%s", __FUNCTION__);
1423
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001424 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001425
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001426 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001427
1428 Mutex::Autolock icl(mBinderSerializationLock);
1429
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001430 if (!mDevice.get()) {
1431 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1432 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001433
Igor Murashkin099b4572013-07-12 17:52:16 -07001434 if (info != NULL) {
1435 *info = mDevice->info(); // static camera metadata
1436 // TODO: merge with device-specific camera metadata
1437 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001438
1439 return res;
1440}
1441
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001442binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001443{
1444 ATRACE_CALL();
1445 ALOGV("%s", __FUNCTION__);
1446
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001447 binder::Status res;
1448 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001449
1450 Mutex::Autolock icl(mBinderSerializationLock);
1451
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001452 if (!mDevice.get()) {
1453 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1454 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001455
1456 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001457 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001458 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001459 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001460 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001461 mCameraIdStr.c_str());
1462 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1463 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001464 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001465 status_t err = mDevice->waitUntilDrained();
1466 if (err != OK) {
1467 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001468 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001469 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001470 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001471 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001472 return res;
1473}
1474
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001475binder::Status CameraDeviceClient::flush(
1476 /*out*/
1477 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001478 ATRACE_CALL();
1479 ALOGV("%s", __FUNCTION__);
1480
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001481 binder::Status res;
1482 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001483
1484 Mutex::Autolock icl(mBinderSerializationLock);
1485
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001486 if (!mDevice.get()) {
1487 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1488 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001489
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001490 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001491 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001492 status_t err = mDevice->flush(lastFrameNumber);
1493 if (err != OK) {
1494 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001495 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1496 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001497 }
1498 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001499}
1500
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001501binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001502 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001503 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001504
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001505 binder::Status res;
1506 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001507
1508 Mutex::Autolock icl(mBinderSerializationLock);
1509
1510 // Guard against trying to prepare non-created streams
1511 ssize_t index = NAME_NOT_FOUND;
1512 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001513 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001514 index = i;
1515 break;
1516 }
1517 }
1518
1519 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001520 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1521 "with that ID exists", mCameraIdStr.c_str(), streamId);
1522 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1523 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001524 }
1525
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001526 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1527 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001528 status_t err = mDevice->prepare(streamId);
1529 if (err == BAD_VALUE) {
1530 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001531 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001532 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001533 } else if (err != OK) {
1534 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001535 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001536 strerror(-err), err);
1537 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001538 return res;
1539}
1540
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001541binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001542 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001543 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001544
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001545 binder::Status res;
1546 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001547
1548 Mutex::Autolock icl(mBinderSerializationLock);
1549
1550 // Guard against trying to prepare non-created streams
1551 ssize_t index = NAME_NOT_FOUND;
1552 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001553 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001554 index = i;
1555 break;
1556 }
1557 }
1558
1559 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001560 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1561 "with that ID exists", mCameraIdStr.c_str(), streamId);
1562 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1563 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001564 }
1565
1566 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001567 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1568 mCameraIdStr.c_str(), maxCount);
1569 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1570 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001571 }
1572
1573 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1574 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001575 status_t err = mDevice->prepare(maxCount, streamId);
1576 if (err == BAD_VALUE) {
1577 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001578 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001579 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001580 } else if (err != OK) {
1581 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001582 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001583 strerror(-err), err);
1584 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001585
1586 return res;
1587}
1588
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001589binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001590 ATRACE_CALL();
1591 ALOGV("%s", __FUNCTION__);
1592
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001593 binder::Status res;
1594 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001595
1596 Mutex::Autolock icl(mBinderSerializationLock);
1597
1598 // Guard against trying to prepare non-created streams
1599 ssize_t index = NAME_NOT_FOUND;
1600 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001601 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001602 index = i;
1603 break;
1604 }
1605 }
1606
1607 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001608 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1609 "with that ID exists", mCameraIdStr.c_str(), streamId);
1610 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1611 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001612 }
1613
1614 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1615 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001616 status_t err = mDevice->tearDown(streamId);
1617 if (err == BAD_VALUE) {
1618 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001619 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001620 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001621 } else if (err != OK) {
1622 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001623 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001624 strerror(-err), err);
1625 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001626
1627 return res;
1628}
1629
Shuzhen Wang758c2152017-01-10 18:26:18 -08001630binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001631 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1632 ATRACE_CALL();
1633
1634 binder::Status res;
1635 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1636
1637 Mutex::Autolock icl(mBinderSerializationLock);
1638
Shuzhen Wang0129d522016-10-30 22:43:41 -07001639 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1640 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001641 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001642
Shuzhen Wang0129d522016-10-30 22:43:41 -07001643 if (bufferProducers.size() == 0) {
1644 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001645 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1646 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001647
Shuzhen Wang758c2152017-01-10 18:26:18 -08001648 // streamId should be in mStreamMap if this stream already has a surface attached
1649 // to it. Otherwise, it should be in mDeferredStreams.
1650 bool streamIdConfigured = false;
1651 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1652 for (size_t i = 0; i < mStreamMap.size(); i++) {
1653 if (mStreamMap.valueAt(i).streamId() == streamId) {
1654 streamIdConfigured = true;
1655 break;
1656 }
Zhijun He5d677d12016-05-29 16:52:39 -07001657 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001658 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1659 if (streamId == mDeferredStreams[i]) {
1660 deferredStreamIndex = i;
1661 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001662 }
1663
Shuzhen Wang758c2152017-01-10 18:26:18 -08001664 }
1665 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001666 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1667 "(ID %d)", mCameraIdStr.c_str(), streamId);
1668 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1669 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001670 }
1671
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001672 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001673 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1674 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1675 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1676 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001677 }
1678
Zhijun He5d677d12016-05-29 16:52:39 -07001679 if (!mDevice.get()) {
1680 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1681 }
1682
Shuzhen Wang758c2152017-01-10 18:26:18 -08001683 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001684 const std::vector<int32_t> &sensorPixelModesUsed =
1685 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001686 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001687 int32_t colorSpace = outputConfiguration.getColorSpace();
1688 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001689 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001690 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001691 for (auto& bufferProducer : bufferProducers) {
1692 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001693 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1694 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001695 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001696 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001697 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001698 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001699
1700 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001701 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001702 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001703 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001704 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001705
1706 if (!res.isOk())
1707 return res;
1708
1709 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001710 }
1711
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001712 // Gracefully handle case where finalizeOutputConfigurations is called
1713 // without any new surface.
1714 if (consumerSurfaces.size() == 0) {
1715 mStreamInfoMap[streamId].finalized = true;
1716 return res;
1717 }
1718
Zhijun He5d677d12016-05-29 16:52:39 -07001719 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001720 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001721 std::vector<int> consumerSurfaceIds;
1722 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001723 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001724 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1725 sp<IBinder> binder = IInterface::asBinder(
1726 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001727 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001728 binder.get(), streamId, consumerSurfaceIds[i]);
1729 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1730 }
1731 if (deferredStreamIndex != NAME_NOT_FOUND) {
1732 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001733 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001734 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001735 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001736 } else if (err == NO_INIT) {
1737 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001738 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001739 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001740 } else {
1741 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001742 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001743 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001744 }
1745
1746 return res;
1747}
1748
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001749binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001750 ATRACE_CALL();
1751 binder::Status res;
1752 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1753
1754 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001755 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1756 mCameraIdStr.c_str(), mode);
1757 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1758 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001759 }
1760
1761 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001762 BasicClient::setAudioRestriction(mode);
1763 return binder::Status::ok();
1764}
1765
1766binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1767 ATRACE_CALL();
1768 binder::Status res;
1769 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1770 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001771 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001772 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001773 }
1774 return binder::Status::ok();
1775}
1776
Ravneetaeb20dc2022-03-30 05:33:03 +00001777status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1778 return mDevice->setCameraServiceWatchdog(enabled);
1779}
1780
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001781status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal) {
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001782 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1783
1784 return mDevice->setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001785 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop), fromHal);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001786}
1787
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001788status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1789 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1790
1791 return mDevice->setAutoframingAutoBehavior(
1792 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1793}
1794
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001795bool CameraDeviceClient::supportsCameraMute() {
1796 return mDevice->supportsCameraMute();
1797}
1798
1799status_t CameraDeviceClient::setCameraMute(bool enabled) {
1800 return mDevice->setCameraMute(enabled);
1801}
1802
Shuzhen Wang16610a62022-12-15 22:38:07 -08001803void CameraDeviceClient::setStreamUseCaseOverrides(
1804 const std::vector<int64_t>& useCaseOverrides) {
1805 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1806}
1807
1808void CameraDeviceClient::clearStreamUseCaseOverrides() {
1809 mDevice->clearStreamUseCaseOverrides();
1810}
1811
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001812bool CameraDeviceClient::supportsZoomOverride() {
1813 return mDevice->supportsZoomOverride();
1814}
1815
1816status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1817 return mDevice->setZoomOverride(zoomOverride);
1818}
1819
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001820binder::Status CameraDeviceClient::switchToOffline(
1821 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001822 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001823 /*out*/
1824 sp<hardware::camera2::ICameraOfflineSession>* session) {
1825 ATRACE_CALL();
1826
1827 binder::Status res;
1828 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1829
1830 Mutex::Autolock icl(mBinderSerializationLock);
1831
1832 if (!mDevice.get()) {
1833 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1834 }
1835
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001836 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001837 std::string msg = "Offline surfaces must not be empty";
1838 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1839 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001840 }
1841
1842 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001843 std::string msg = "Invalid offline session";
1844 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1845 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001846 }
1847
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001848 std::vector<int32_t> offlineStreamIds;
1849 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001850 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001851 for (const auto& streamId : offlineOutputIds) {
1852 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001853 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001854 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001855 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001856 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1857 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001858 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001859
1860 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001861 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001862 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001863 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1864 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001865 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001866
Emilian Peev2f5d6012022-01-19 16:16:50 -08001867 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001868 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001869 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001870 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001871 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001872 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001873 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001874 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001875 if (isCompositeStream) {
1876 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1877 if (compositeIdx == NAME_NOT_FOUND) {
1878 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1879 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1880 "Unknown composite stream");
1881 }
1882
1883 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1884 &offlineStreamIds);
1885 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1886 mCompositeStreamMap.valueAt(compositeIdx));
1887 break;
1888 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001889 }
1890
Emilian Peev4697b642019-11-19 17:11:14 -08001891 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001892 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001893 }
1894 }
1895
1896 sp<CameraOfflineSessionBase> offlineSession;
1897 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1898 if (ret != OK) {
1899 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1900 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001901 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001902 }
1903
Emilian Peevcc0b7952020-01-07 13:54:47 -08001904 sp<CameraOfflineSessionClient> offlineClient;
1905 if (offlineSession.get() != nullptr) {
1906 offlineClient = new CameraOfflineSessionClient(sCameraService,
Austin Borger249e6592024-03-10 22:28:11 -07001907 offlineSession, offlineCompositeStreamMap, cameraCb, mAttributionAndPermissionUtils,
1908 mClientPackageName, mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation,
1909 mClientPid, mClientUid, mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001910 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1911 }
1912
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001913 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001914 // A successful offline session switch must reset the current camera client
1915 // and release any resources occupied by previously configured streams.
1916 mStreamMap.clear();
1917 mConfiguredOutputs.clear();
1918 mDeferredStreams.clear();
1919 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001920 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001921 mCompositeStreamMap.clear();
1922 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001923 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001924 // In case we failed to register the offline client, ensure that it still initialized
1925 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001926 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001927
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001928 switch(ret) {
1929 case BAD_VALUE:
1930 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1931 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1932 case TIMED_OUT:
1933 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1934 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1935 default:
1936 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1937 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1938 strerror(-ret), ret);
1939 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001940 }
1941
1942 *session = offlineClient;
1943
1944 return binder::Status::ok();
1945}
1946
Igor Murashkine7ee7632013-06-11 18:10:18 -07001947status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001948 return BasicClient::dump(fd, args);
1949}
1950
1951status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001952 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001953 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001954 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001955 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001956 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001957
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001958 dprintf(fd, " State:\n");
1959 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001960 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001961 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001962 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001963 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001964 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001965 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001966 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001967 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001968 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001969 mStreamMap.valueAt(i).streamId(),
1970 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001971 }
Zhijun He5d677d12016-05-29 16:52:39 -07001972 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001973 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001974 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001975 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001976 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001977 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001978 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001979 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001980 // TODO: print dynamic/request section from most recent requests
1981 mFrameProcessor->dump(fd, args);
1982
1983 return dumpDevice(fd, args);
1984}
1985
Austin Borger1c1bee02023-06-01 16:51:35 -07001986status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07001987 sp<CameraDeviceBase> device = mDevice;
1988 if (!device) {
1989 dprintf(out, " Device is detached.");
1990 return OK;
1991 }
1992 device->startWatchingTags(tags);
1993 return OK;
1994}
1995
1996status_t CameraDeviceClient::stopWatchingTags(int out) {
1997 sp<CameraDeviceBase> device = mDevice;
1998 if (!device) {
1999 dprintf(out, " Device is detached.");
2000 return OK;
2001 }
2002 device->stopWatchingTags();
2003 return OK;
2004}
2005
2006status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
2007 sp<CameraDeviceBase> device = mDevice;
2008 if (!device) {
2009 return OK;
2010 }
2011 device->dumpWatchedEventsToVector(out);
2012 return OK;
2013}
2014
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002015void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07002016 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002017 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002018 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002019
Emilian Peev538c90e2018-12-17 18:03:19 +00002020 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002021 {
2022 // Access to the composite stream map must be synchronized
2023 Mutex::Autolock l(mCompositeLock);
2024 // Composites can have multiple internal streams. Error notifications coming from such
2025 // internal streams may need to remain within camera service.
2026 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2027 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2028 resultExtras);
2029 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002030 }
2031
2032 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002033 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002034 }
2035}
2036
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002037void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2038 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2039
2040 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002041 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002042 }
2043
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002044 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002045 mStreamingRequestId = REQUEST_ID_NONE;
2046}
2047
Shuzhen Wang316781a2020-08-18 18:11:01 -07002048void CameraDeviceClient::notifyIdle(
2049 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2050 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002051 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002052 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002053
2054 if (remoteCb != 0) {
2055 remoteCb->onDeviceIdle();
2056 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002057
2058 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2059 {
2060 Mutex::Autolock l(mCompositeLock);
2061 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2062 hardware::CameraStreamStats compositeStats;
2063 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2064 if (compositeStats.mWidth > 0) {
2065 fullStreamStats.push_back(compositeStats);
2066 }
2067 }
2068 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002069 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Shuzhen Wang6e08d202023-10-24 20:27:14 +00002070 fullStreamStats, mUserTag, mVideoStabilizationMode, mUsedUltraWide,
2071 mUsedSettingsOverrideZoom);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002072}
2073
Jianing Weicb0652e2014-03-12 18:29:36 -07002074void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002075 nsecs_t timestamp) {
2076 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002077 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002078 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002079 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002080 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002081 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002082
Emilian Peev2f5d6012022-01-19 16:16:50 -08002083 // Access to the composite stream map must be synchronized
2084 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002085 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2086 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2087 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002088}
2089
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002090void CameraDeviceClient::notifyPrepared(int streamId) {
2091 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002092 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002093 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002094 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002095 remoteCb->onPrepared(streamId);
2096 }
2097}
2098
Shuzhen Wang9d066012016-09-30 11:30:20 -07002099void CameraDeviceClient::notifyRequestQueueEmpty() {
2100 // Thread safe. Don't bother locking.
2101 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2102 if (remoteCb != 0) {
2103 remoteCb->onRequestQueueEmpty();
2104 }
2105}
2106
Igor Murashkine7ee7632013-06-11 18:10:18 -07002107void CameraDeviceClient::detachDevice() {
2108 if (mDevice == 0) return;
2109
Shuzhen Wang316781a2020-08-18 18:11:01 -07002110 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002111 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002112
Emilian Peev7ee731f2022-02-08 14:55:52 -08002113 if (mFrameProcessor.get() != nullptr) {
2114 mFrameProcessor->removeListener(
2115 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2116 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2117 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002118 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002119 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002120 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002121 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002122
2123 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2124 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002125 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002126 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002127 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2128 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2129 }
2130
Igor Murashkine7ee7632013-06-11 18:10:18 -07002131 if ((code = mDevice->waitUntilDrained()) != OK) {
2132 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2133 code);
2134 }
2135 }
2136
Emilian Peev2f5d6012022-01-19 16:16:50 -08002137 {
2138 Mutex::Autolock l(mCompositeLock);
2139 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2140 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2141 if (ret != OK) {
2142 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2143 strerror(-ret), ret);
2144 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002145 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002146 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002147 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002148
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002149 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002150 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002151
2152 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002153 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002154}
2155
2156/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002157void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002158 ATRACE_CALL();
2159 ALOGV("%s", __FUNCTION__);
2160
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002161 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002162 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002163 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002164 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2165 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002166 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002167
Emilian Peev2f5d6012022-01-19 16:16:50 -08002168 // Access to the composite stream map must be synchronized
2169 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002170 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2171 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2172 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002173}
2174
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002175binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002176 if (mDisconnected) {
2177 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2178 "The camera device has been disconnected");
2179 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002180 status_t res = checkPid(checkLocation);
2181 return (res == OK) ? binder::Status::ok() :
2182 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2183 "Attempt to use camera from a different process than original client");
2184}
2185
Igor Murashkine7ee7632013-06-11 18:10:18 -07002186// TODO: move to Camera2ClientBase
2187bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2188
Jayant Chowdhary12361932018-08-27 14:46:13 -07002189 const int pid = CameraThreadState::getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002190 const int selfPid = getpid();
2191 camera_metadata_entry_t entry;
2192
2193 /**
2194 * Mixin default important security values
2195 * - android.led.transmit = defaulted ON
2196 */
2197 CameraMetadata staticInfo = mDevice->info();
2198 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2199 for(size_t i = 0; i < entry.count; ++i) {
2200 uint8_t led = entry.data.u8[i];
2201
2202 switch(led) {
2203 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2204 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2205 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2206 metadata.update(ANDROID_LED_TRANSMIT,
2207 &transmitDefault, 1);
2208 }
2209 break;
2210 }
2211 }
2212 }
2213
2214 // We can do anything!
2215 if (pid == selfPid) {
2216 return true;
2217 }
2218
2219 /**
2220 * Permission check special fields in the request
2221 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2222 */
2223 entry = metadata.find(ANDROID_LED_TRANSMIT);
2224 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2225 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002226 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002227 if (!checkCallingPermission(permissionString)) {
Jayant Chowdhary12361932018-08-27 14:46:13 -07002228 const int uid = CameraThreadState::getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002229 ALOGE("Permission Denial: "
2230 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2231 return false;
2232 }
2233 }
2234
2235 return true;
2236}
2237
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002238status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2239 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002240 ALOGV("%s: begin", __FUNCTION__);
2241
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002242 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002243 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002244}
2245
Austin Borger1c1bee02023-06-01 16:51:35 -07002246const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002247 if (mDevice->getId() == cameraId) {
2248 return mDevice->info();
2249 }
2250 return mDevice->infoPhysical(cameraId);
2251}
2252
Austin Borger1c1bee02023-06-01 16:51:35 -07002253bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002254 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002255 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002256}
2257
2258bool CameraDeviceClient::isSensorPixelModeConsistent(
2259 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2260 // First we get the sensorPixelMode from the settings metadata.
2261 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2262 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2263 if (sensorPixelModeEntry.count != 0) {
2264 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2265 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2266 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2267 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2268 __FUNCTION__, sensorPixelMode);
2269 return false;
2270 }
2271 }
2272 // Check whether each stream has max resolution allowed.
2273 bool consistent = true;
2274 for (auto it : streamIdList) {
2275 auto const streamInfoIt = mStreamInfoMap.find(it);
2276 if (streamInfoIt == mStreamInfoMap.end()) {
2277 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2278 return false;
2279 }
2280 consistent =
2281 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2282 streamInfoIt->second.sensorPixelModesUsed.end();
2283 if (!consistent) {
2284 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2285 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2286 ALOGE("sensor pixel mode used list: %i", m);
2287 }
2288 break;
2289 }
2290 }
2291
2292 return consistent;
2293}
2294
Igor Murashkine7ee7632013-06-11 18:10:18 -07002295} // namespace android