blob: 508d487104895649c33833cbde2367e5bb597ff2 [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 Borger1c1bee02023-06-01 16:51:35 -070064 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080065 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070066 const std::optional<std::string>& clientFeatureId,
67 const std::string& cameraId,
Jing Mikec7f9b132023-03-12 11:12:04 +080068 [[maybe_unused]] int api1CameraId,
Igor Murashkine7ee7632013-06-11 18:10:18 -070069 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070070 int sensorOrientation,
Igor Murashkine7ee7632013-06-11 18:10:18 -070071 int clientPid,
72 uid_t clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070073 int servicePid,
74 bool overrideToPortrait) :
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080075 BasicClient(cameraService,
Marco Nelissenf8880202014-11-14 07:58:25 -080076 IInterface::asBinder(remoteCallback),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080077 clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080078 systemNativeClient,
Philip P. Moltmann9e648f62019-11-04 12:52:45 -080079 clientFeatureId,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080080 cameraId,
81 cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070082 sensorOrientation,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080083 clientPid,
84 clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070085 servicePid,
86 overrideToPortrait),
Igor Murashkine7ee7632013-06-11 18:10:18 -070087 mRemoteCallback(remoteCallback) {
88}
Igor Murashkine7ee7632013-06-11 18:10:18 -070089
90// Interface used by CameraService
91
92CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080093 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070094 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger1c1bee02023-06-01 16:51:35 -070095 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080096 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070097 const std::optional<std::string>& clientFeatureId,
98 const std::string& cameraId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080099 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -0700100 int sensorOrientation,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800101 int clientPid,
102 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700103 int servicePid,
Austin Borger18b30a72022-10-27 12:20:29 -0700104 bool overrideForPerfClass,
malikakash73125c62023-07-21 22:44:34 +0000105 bool overrideToPortrait,
106 const std::string& originalCameraId) :
Charles Chenf075f082024-03-04 23:32:55 +0000107 Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper, clientPackageName,
Austin Borger74fca042022-05-23 12:41:21 -0700108 systemNativeClient, clientFeatureId, cameraId, /*API1 camera ID*/ -1, cameraFacing,
Austin Borger18b30a72022-10-27 12:20:29 -0700109 sensorOrientation, clientPid, clientUid, servicePid, overrideForPerfClass,
110 overrideToPortrait),
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700111 mInputStream(),
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700112 mStreamingRequestId(REQUEST_ID_NONE),
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700113 mRequestIdCounter(0),
malikakash73125c62023-07-21 22:44:34 +0000114 mOverrideForPerfClass(overrideForPerfClass),
115 mOriginalCameraId(originalCameraId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700116 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -0700117 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700118}
119
Emilian Peevbd8c5032018-02-14 23:05:40 +0000120status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -0700121 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000122 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800123}
124
125template<typename TProviderPtr>
Austin Borger1c1bee02023-06-01 16:51:35 -0700126status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
127 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700128 ATRACE_CALL();
129 status_t res;
130
Emilian Peevbd8c5032018-02-14 23:05:40 +0000131 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700132 if (res != OK) {
133 return res;
134 }
135
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700136 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger1c1bee02023-06-01 16:51:35 -0700137 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
138 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700139 if (res != OK) {
140 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
141 __FUNCTION__, strerror(-res), res);
142 return res;
143 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700144
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800145 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
146 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800147 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700148 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700149
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800150 const CameraMetadata &deviceInfo = mDevice->info();
151 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000152 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
153 if (physicalKeysEntry.count > 0) {
154 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
155 physicalKeysEntry.data.i32,
156 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
157 }
158
Emilian Peev2295df72021-11-12 18:14:10 -0800159 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
160 mDynamicProfileMap.emplace(
161 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
162 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
163 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800164 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800165 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800166 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800167 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800168 if (entry.count > 0 || ((entry.count % 3) != 0)) {
169 int64_t standardBitmap =
170 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
171 for (size_t i = 0; i < entry.count; i += 3) {
172 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800173 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800174 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
175 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800176 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800177 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800178 }
179 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800180 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
181 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800182 }
183 }
Emilian Peevef715e22022-05-19 17:44:33 -0700184 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
185 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800186 } else {
187 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
188 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
189 }
190 }
191 }
192
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700193 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800194 // Cache physical camera ids corresponding to this device and also the high
195 // resolution sensors in this device + physical camera ids
Austin Borger1c1bee02023-06-01 16:51:35 -0700196 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800197 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700198 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800199 }
200 for (auto &physicalId : mPhysicalCameraIds) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700201 if (supportsUltraHighResolutionCapture(physicalId)) {
202 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800203 }
204 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700205 return OK;
206}
207
208CameraDeviceClient::~CameraDeviceClient() {
209}
210
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800211binder::Status CameraDeviceClient::submitRequest(
212 const hardware::camera2::CaptureRequest& request,
213 bool streaming,
214 /*out*/
215 hardware::camera2::utils::SubmitInfo *submitInfo) {
216 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
217 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700218}
219
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800220binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000221 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000222 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800223 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
224
Emilian Peev2f5d6012022-01-19 16:16:50 -0800225 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800226 // Trying to submit request with surface that wasn't created
227 if (idx == NAME_NOT_FOUND) {
228 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
229 " we have not called createStream on",
Austin Borger1c1bee02023-06-01 16:51:35 -0700230 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800231 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
232 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000233 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
234 != NAME_NOT_FOUND) {
235 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
236 currentStreamId);
237 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800238 }
239
240 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
241 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800242 outputStreamIds->push_back(streamSurfaceId.streamId());
243 }
244 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
245
246 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700247 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800248 streamSurfaceId.surfaceId());
249
Emilian Peevf873aa52018-01-26 14:58:28 +0000250 if (currentStreamId != nullptr) {
251 *currentStreamId = streamSurfaceId.streamId();
252 }
253
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800254 return binder::Status::ok();
255}
256
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800257static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
258 const Vector<int> &streamIdsForThisRequest) {
259 std::list<int> intersection;
260 for (auto &streamId : streamIdsForThisRequest) {
261 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
262 intersection.emplace_back(streamId);
263 }
264 }
265 return intersection;
266}
267
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800268binder::Status CameraDeviceClient::submitRequestList(
269 const std::vector<hardware::camera2::CaptureRequest>& requests,
270 bool streaming,
271 /*out*/
272 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700273 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700274 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700275
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800276 binder::Status res = binder::Status::ok();
277 status_t err;
278 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
279 return res;
280 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700281
282 Mutex::Autolock icl(mBinderSerializationLock);
283
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800284 if (!mDevice.get()) {
285 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
286 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700287
288 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800289 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700290 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800291 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700292 }
293
Emilian Peevaebbe412018-01-15 13:53:24 +0000294 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700295 std::list<const SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800296 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700297 uint32_t loopCounter = 0;
298
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800299 for (auto&& request: requests) {
300 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700301 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800302 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700303 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800304 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800305 "No input configured for camera %s but request is for reprocessing",
Austin Borger1c1bee02023-06-01 16:51:35 -0700306 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700307 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800308 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700309 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800310 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
311 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000312 } else if (request.mPhysicalCameraSettings.size() > 1) {
313 ALOGE("%s: Camera %s: reprocess requests not supported for "
314 "multiple physical cameras.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700315 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000316 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
317 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700318 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700319 }
320
Emilian Peevaebbe412018-01-15 13:53:24 +0000321 if (request.mPhysicalCameraSettings.empty()) {
322 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700323 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800324 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000325 "Request doesn't contain any settings");
326 }
327
328 //The first capture settings should always match the logical camera id
Austin Borger1c1bee02023-06-01 16:51:35 -0700329 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
malikakash73125c62023-07-21 22:44:34 +0000330 if (mDevice->getId() != logicalId && mOriginalCameraId != logicalId) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000331 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700332 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000333 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
334 "Invalid camera request settings");
335 }
336
Emilian Peevaebbe412018-01-15 13:53:24 +0000337 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800338 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger1c1bee02023-06-01 16:51:35 -0700339 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800340 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
341 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700342 }
343
Jianing Wei90e59c92014-03-12 18:29:36 -0700344 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700345 * Write in the output stream IDs and map from stream ID to surface ID
346 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700347 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700348 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700349 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000350 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800351 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800352 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800353 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800354 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700355
Emilian Peevf873aa52018-01-26 14:58:28 +0000356 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800357 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000358 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800359 if (!res.isOk()) {
360 return res;
361 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000362
363 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
364 if (index >= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700365 const std::string &requestedPhysicalId =
366 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
367 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800368 dynamicProfileBitmap |=
369 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000370 } else {
371 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
372 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700373 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800374 } else {
375 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
376 int streamId = request.mStreamIdxList.itemAt(i);
377 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700378
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800379 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
380 if (index < 0) {
381 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
382 " we have not called createStream on: stream %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700383 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800384 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
385 "Request targets Surface that is not part of current capture session");
386 }
387
388 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
389 if ((size_t)surfaceIdx >= gbps.size()) {
390 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
391 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700392 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800393 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
394 "Request targets Surface has invalid surface index");
395 }
396
Emilian Peevf873aa52018-01-26 14:58:28 +0000397 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800398 if (!res.isOk()) {
399 return res;
400 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000401
Austin Borger1c1bee02023-06-01 16:51:35 -0700402 const std::string &requestedPhysicalId =
403 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
404 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800405 dynamicProfileBitmap |=
406 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
407 }
408 }
409
410 if (dynamicProfileBitmap !=
411 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
412 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
413 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
414 if ((dynamicProfileBitmap & i) == 0) {
415 continue;
416 }
417
418 const auto& it = mDynamicProfileMap.find(i);
419 if (it != mDynamicProfileMap.end()) {
420 if ((it->second == 0) ||
421 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
422 continue;
423 } else {
424 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
425 " reference an unsupported dynamic range profile combination"
Austin Borger1c1bee02023-06-01 16:51:35 -0700426 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800427 dynamicProfileBitmap);
428 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
429 "Request targets an unsupported dynamic range profile"
430 " combination");
431 }
432 } else {
433 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
434 " references unsupported dynamic range profile 0x%x!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700435 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800436 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
437 "Request targets 10-bit Surface with unsupported dynamic range"
438 " profile");
439 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700440 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700441 }
442
Emilian Peevf873aa52018-01-26 14:58:28 +0000443 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
444 for (const auto& it : request.mPhysicalCameraSettings) {
malikakash73125c62023-07-21 22:44:34 +0000445 const std::string resolvedId = (mOriginalCameraId == it.id) ? mDevice->getId() : it.id;
Emilian Peev00420d22018-02-05 21:33:13 +0000446 if (it.settings.isEmpty()) {
447 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700448 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000449 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
450 "Request settings are empty");
451 }
452
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800453 // Check whether the physical / logical stream has settings
454 // consistent with the sensor pixel mode(s) it was configured with.
455 // mCameraIdToStreamSet will only have ids that are high resolution
malikakash73125c62023-07-21 22:44:34 +0000456 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(resolvedId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800457 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
458 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
459 outputStreamIds);
460 if (!request.mIsReprocess &&
461 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
462 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
463 "consistent with configured streams. Rejecting request.",
malikakash73125c62023-07-21 22:44:34 +0000464 __FUNCTION__, resolvedId.c_str());
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800465 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
466 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
467 "streams configured");
468 }
469 }
470
malikakash73125c62023-07-21 22:44:34 +0000471 const std::string &physicalId = resolvedId;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700472 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
473 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
474 mSupportedPhysicalRequestKeys.end();
475 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
476 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
477 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000478 if (physicalId != mDevice->getId()) {
479 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
malikakash73125c62023-07-21 22:44:34 +0000480 resolvedId);
Emilian Peevf873aa52018-01-26 14:58:28 +0000481 if (found == requestedPhysicalIds.end()) {
482 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700483 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000484 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
485 "Invalid physical camera id");
486 }
Emilian Peev00420d22018-02-05 21:33:13 +0000487
488 if (!mSupportedPhysicalRequestKeys.empty()) {
489 // Filter out any unsupported physical request keys.
490 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
491 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
492 filteredParams.getAndLock());
493 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
494 filteredParams.unlock(meta);
495
496 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
497 camera_metadata_ro_entry entry = it.settings.find(keyIt);
498 if (entry.count > 0) {
499 filteredParams.update(entry);
500 }
501 }
502
malikakash73125c62023-07-21 22:44:34 +0000503 physicalSettingsList.push_back({resolvedId, filteredParams,
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700504 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000505 }
506 } else {
malikakash73125c62023-07-21 22:44:34 +0000507 physicalSettingsList.push_back({resolvedId, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000508 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000509 }
510
511 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
512 // Callee logs
513 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
514 "Caller does not have permission to change restricted controls");
515 }
516
Emilian Peevaebbe412018-01-15 13:53:24 +0000517 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
518 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700519
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800520 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000521 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
522 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700523 }
524
Emilian Peevaebbe412018-01-15 13:53:24 +0000525 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
526 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700527 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800528 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700529 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800530 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700531
Emilian Peevaebbe412018-01-15 13:53:24 +0000532 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700533 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800534
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700535 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800536 if (!request.mUserTag.empty()) {
537 mUserTag = request.mUserTag;
538 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700539 camera_metadata_entry entry =
540 physicalSettingsList.begin()->metadata.find(
541 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
542 if (entry.count == 1) {
543 mVideoStabilizationMode = entry.data.u8[0];
544 }
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -0700545 if (flags::log_ultrawide_usage()) {
546 entry = physicalSettingsList.begin()->metadata.find(
547 ANDROID_CONTROL_ZOOM_RATIO);
548 if (entry.count == 1 && entry.data.f[0] < 1.0f ) {
549 mUsedUltraWide = true;
550 }
551 }
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000552 if (!mUsedSettingsOverrideZoom && flags::log_zoom_override_usage()) {
553 entry = physicalSettingsList.begin()->metadata.find(
554 ANDROID_CONTROL_SETTINGS_OVERRIDE);
555 if (entry.count == 1 && entry.data.i32[0] ==
556 ANDROID_CONTROL_SETTINGS_OVERRIDE_ZOOM) {
557 mUsedSettingsOverrideZoom = true;
558 }
559 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700560 }
561 mRequestIdCounter++;
562
563 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700564 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
565 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800566 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700567 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800568 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700569 mCameraIdStr.c_str(), strerror(-err), err);
570 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800571 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700572 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700573 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700574 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700575 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700576 }
577 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700578 err = mDevice->captureList(metadataRequestList, surfaceMapList,
579 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800580 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700581 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800582 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700583 mCameraIdStr.c_str(), strerror(-err), err);
584 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800585 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700586 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700587 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800588 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700589 }
590
Austin Borger1c1bee02023-06-01 16:51:35 -0700591 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700592 return res;
593}
594
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800595binder::Status CameraDeviceClient::cancelRequest(
596 int requestId,
597 /*out*/
598 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700599 ATRACE_CALL();
600 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
601
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800602 status_t err;
603 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700604
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800605 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700606
607 Mutex::Autolock icl(mBinderSerializationLock);
608
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800609 if (!mDevice.get()) {
610 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
611 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700612
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700613 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700614 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700615 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
616 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
617 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
618 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700619 }
620
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800621 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700622
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800623 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800624 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700625 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700626 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800627 } else {
628 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800629 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700630 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700631 }
632
633 return res;
634}
635
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800636binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700637 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700638 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700639 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800640 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700641}
642
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100643binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700644 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800645 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700646 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700647 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
648 __FUNCTION__, mInputStream.configured ? 1 : 0,
649 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700650
Zhijun He0effd522016-03-04 10:22:27 -0800651 binder::Status res;
652 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
653
Emilian Peevcc0b7952020-01-07 13:54:47 -0800654 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700655 std::string msg = "Invalid offline stream ids";
656 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
657 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800658 }
659
Zhijun He0effd522016-03-04 10:22:27 -0800660 Mutex::Autolock icl(mBinderSerializationLock);
661
662 if (!mDevice.get()) {
663 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
664 }
665
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700666 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000667 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000668 if (!res.isOk()) {
669 return res;
670 }
671
672 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
673 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700674 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
675 mCameraIdStr.c_str());
676 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
677 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000678 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700679 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
680 mCameraIdStr.c_str(), strerror(-err), err);
681 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
682 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000683 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800684 offlineStreamIds->clear();
685 mDevice->getOfflineStreamIds(offlineStreamIds);
686
Emilian Peev2f5d6012022-01-19 16:16:50 -0800687 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000688 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
689 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800690 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700691 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
692 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
693 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
694 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000695 break;
696 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800697
698 // Composite streams can only support offline mode in case all individual internal
699 // streams are also supported.
700 std::vector<int> internalStreams;
701 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800702 offlineStreamIds->erase(
703 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800704 [&internalStreams] (int streamId) {
705 auto it = std::find(internalStreams.begin(), internalStreams.end(),
706 streamId);
707 if (it != internalStreams.end()) {
708 internalStreams.erase(it);
709 return true;
710 }
711
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800712 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800713 if (internalStreams.empty()) {
714 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
715 }
716 }
717
718 for (const auto& offlineStreamId : *offlineStreamIds) {
719 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000720 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700721
722 nsecs_t configureEnd = systemTime();
723 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700724 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700725 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000726 }
727
728 return res;
729}
730
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800731binder::Status CameraDeviceClient::isSessionConfigurationSupported(
732 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800733
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800734 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800735 binder::Status res;
736 status_t ret = OK;
737 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
738
739 Mutex::Autolock icl(mBinderSerializationLock);
740
741 if (!mDevice.get()) {
742 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
743 }
744
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800745 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700746 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
747 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
748 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800749 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700750
Emilian Peev35ae8262018-11-08 13:11:32 +0000751 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700752 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700753 sessionConfiguration, mOverrideForPerfClass, /*checkSessionParams*/false,
754 status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000755 switch (ret) {
756 case OK:
757 // Expected, do nothing.
758 break;
759 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700760 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000761 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700762 mCameraIdStr.c_str());
763 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
764 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000765 }
766
767 break;
768 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700769 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000770 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700771 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000772 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700773 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000774 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800775 }
776
777 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700778}
779
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800780binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700781 ATRACE_CALL();
782 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
783
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800784 binder::Status res;
785 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700786
787 Mutex::Autolock icl(mBinderSerializationLock);
788
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800789 if (!mDevice.get()) {
790 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
791 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700792
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700793 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700794 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700795 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000796 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700797
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700798 if (mInputStream.configured && mInputStream.id == streamId) {
799 isInput = true;
800 } else {
801 // Guard against trying to delete non-created streams
802 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700803 if (streamId == mStreamMap.valueAt(i).streamId()) {
804 surfaces.push_back(mStreamMap.keyAt(i));
805 }
806 }
807
808 // See if this stream is one of the deferred streams.
809 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
810 if (streamId == mDeferredStreams[i]) {
811 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700812 break;
813 }
814 }
815
Emilian Peev2f5d6012022-01-19 16:16:50 -0800816 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000817 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
818 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
819 compositeIndex = i;
820 break;
821 }
822 }
823
Shuzhen Wang0129d522016-10-30 22:43:41 -0700824 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700825 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
826 " stream created yet", mCameraIdStr.c_str(), streamId);
827 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
828 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700829 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700830 }
831
832 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800833 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700834
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800835 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700836 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
837 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
838 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
839 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800840 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700841 if (isInput) {
842 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700843 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700844 for (auto& surface : surfaces) {
845 mStreamMap.removeItem(surface);
846 }
847
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800848 mConfiguredOutputs.removeItem(streamId);
849
Shuzhen Wang0129d522016-10-30 22:43:41 -0700850 if (dIndex != NAME_NOT_FOUND) {
851 mDeferredStreams.removeItemsAt(dIndex);
852 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000853
854 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800855 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000856 status_t ret;
857 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
858 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700859 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
860 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
861 err, streamId);
862 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
863 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000864 }
865 mCompositeStreamMap.removeItemsAt(compositeIndex);
866 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800867 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
868 auto &streamSet = mapIt.second;
869 if (streamSet.find(streamId) != streamSet.end()) {
870 streamSet.erase(streamId);
871 break;
872 }
873 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700874 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700875 }
876
877 return res;
878}
879
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800880binder::Status CameraDeviceClient::createStream(
881 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
882 /*out*/
883 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700884 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700885
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800886 binder::Status res;
887 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700888
889 Mutex::Autolock icl(mBinderSerializationLock);
890
Shuzhen Wang0129d522016-10-30 22:43:41 -0700891 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
892 outputConfiguration.getGraphicBufferProducers();
893 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800894 bool deferredConsumer = outputConfiguration.isDeferred();
895 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700896 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800897 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800898 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800899 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800900 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800901 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800902 int mirrorMode = outputConfiguration.getMirrorMode();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700903 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000904 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700905
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700906 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Emilian Peev35ae8262018-11-08 13:11:32 +0000907 outputConfiguration.getSurfaceType());
908 if (!res.isOk()) {
909 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700910 }
Zhijun He5d677d12016-05-29 16:52:39 -0700911
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800912 if (!mDevice.get()) {
913 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
914 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700915 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800916 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000917 if (!res.isOk()) {
918 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800919 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000920
Shuzhen Wang0129d522016-10-30 22:43:41 -0700921 std::vector<sp<Surface>> surfaces;
922 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700923 status_t err;
924
925 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700926 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800927 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700928 }
929
Shuzhen Wang758c2152017-01-10 18:26:18 -0800930 OutputStreamInfo streamInfo;
931 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800932 const std::vector<int32_t> &sensorPixelModesUsed =
933 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700934 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700935 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700936 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800937 ssize_t index = mStreamMap.indexOfKey(binder);
938 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700939 std::string msg = std::string("Camera ") + mCameraIdStr
940 + ": Surface already has a stream created for it (ID "
941 + std::to_string(index) + ")";
942 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
943 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700944 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700945
Shuzhen Wang758c2152017-01-10 18:26:18 -0800946 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700947 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800948 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800949 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700950 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800951
952 if (!res.isOk())
953 return res;
954
955 if (!isStreamInfoValid) {
956 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700957 }
958
Shuzhen Wang758c2152017-01-10 18:26:18 -0800959 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang0129d522016-10-30 22:43:41 -0700960 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -0800961 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700962
963 // If mOverrideForPerfClass is true, do not fail createStream() for small
964 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
965 // closest possible supported size.
966
Zhijun He125684a2015-12-26 15:07:30 -0800967 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100968 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800969 bool isDepthCompositeStream =
970 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0]);
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800971 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(surfaces[0]);
Emilian Peev434248e2022-10-06 14:58:54 -0700972 bool isJpegRCompositeStream =
Emilian Peeve579d8b2023-02-28 14:16:08 -0800973 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0]) &&
Emilian Peev15230142023-04-27 20:22:54 +0000974 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800975 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800976 sp<CompositeStream> compositeStream;
977 if (isDepthCompositeStream) {
978 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800979 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800980 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -0700981 } else {
982 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800983 }
984
Emilian Peev538c90e2018-12-17 18:03:19 +0000985 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
986 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -0700987 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800988 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -0700989 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000990 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
991 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000992 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800993 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000994 mCompositeStreamMap.add(IInterface::asBinder(surfaces[0]->getIGraphicBufferProducer()),
995 compositeStream);
996 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800997 } else {
998 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
999 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001000 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001001 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -08001002 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -08001003 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001004 streamInfo.timestampBase, streamInfo.mirrorMode, streamInfo.colorSpace,
1005 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001006 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001007
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001008 if (err != OK) {
1009 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001010 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001011 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Henri Chataingbcb99452023-11-01 17:40:30 +00001012 static_cast<int>(streamInfo.dataSpace), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001013 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001014 int i = 0;
1015 for (auto& binder : binders) {
1016 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1017 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001018 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1019 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001020 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001021
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001022 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001023 mStreamInfoMap[streamId] = streamInfo;
1024
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001025 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001026 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001027 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001028 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001029
Zhijun He5d677d12016-05-29 16:52:39 -07001030 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001031 res = setStreamTransformLocked(streamId, streamInfo.mirrorMode);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001032
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001033 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001034 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001035 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001036 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001037 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001038 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001039 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001040 }
1041
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001042 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001043 }
1044
1045 return res;
1046}
1047
Zhijun He5d677d12016-05-29 16:52:39 -07001048binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1049 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001050 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001051 /*out*/
1052 int* newStreamId) {
1053 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001054 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001055 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001056 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001057 status_t err;
1058 binder::Status res;
1059
1060 if (!mDevice.get()) {
1061 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1062 }
1063
1064 // Infer the surface info for deferred surface stream creation.
1065 width = outputConfiguration.getWidth();
1066 height = outputConfiguration.getHeight();
1067 surfaceType = outputConfiguration.getSurfaceType();
1068 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1069 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001070 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001071 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1072 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1073 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1074 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1075 }
1076 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001077 std::vector<sp<Surface>> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001078 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001079 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1080 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001081 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1082 // Here, we override sensor pixel modes
1083 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1084 const std::vector<int32_t> &sensorPixelModesUsed =
1085 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001086 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001087 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001088 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001089 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1090 "sensor pixel modes used not valid for deferred stream");
1091 }
1092
Shuzhen Wang0129d522016-10-30 22:43:41 -07001093 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1094 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001095 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001096 &streamId, physicalCameraId,
1097 overriddenSensorPixelModesUsed,
1098 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001099 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001100 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001101 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001102 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001103 outputConfiguration.getMirrorMode(),
1104 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001105
1106 if (err != OK) {
1107 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001108 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Henri Chataingbcb99452023-11-01 17:40:30 +00001109 mCameraIdStr.c_str(), width, height, format, static_cast<int>(dataSpace),
1110 strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001111 } else {
1112 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1113 // a separate list to track. Once the deferred surface is set, this id will be
1114 // relocated to mStreamMap.
1115 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001116 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001117 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001118 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001119 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001120 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001121 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001122 outputConfiguration.getMirrorMode(),
1123 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001124
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001125 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001126 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001127 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001128
1129 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001130 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001131
1132 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001133 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001134 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001135 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001136 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001137 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001138 }
Zhijun He5d677d12016-05-29 16:52:39 -07001139 }
1140 return res;
1141}
1142
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001143binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001144 int32_t transform = 0;
1145 status_t err;
1146 binder::Status res;
1147
1148 if (!mDevice.get()) {
1149 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1150 }
1151
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001152 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001153 if (err != OK) {
1154 // Error logged by getRotationTransformLocked.
1155 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1156 "Unable to calculate rotation transform for new stream");
1157 }
1158
1159 err = mDevice->setStreamTransform(streamId, transform);
1160 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001161 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001162 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001163 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1164 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001165 }
1166
1167 return res;
1168}
Ruben Brunkbba75572014-11-20 17:29:50 -08001169
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001170binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001171 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001172 /*out*/
1173 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001174
1175 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001176 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1177 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001178
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001179 binder::Status res;
1180 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001181
1182 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001183
1184 if (!mDevice.get()) {
1185 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1186 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001187
1188 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001189 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1190 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1191 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1192 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001193 }
1194
1195 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001196 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001197 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001198 mInputStream.configured = true;
1199 mInputStream.width = width;
1200 mInputStream.height = height;
1201 mInputStream.format = format;
1202 mInputStream.id = streamId;
1203
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001204 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001205 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001206
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001207 *newStreamId = streamId;
1208 } else {
1209 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001210 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001211 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001212 }
1213
1214 return res;
1215}
1216
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001217binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001218
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001219 binder::Status res;
1220 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1221
1222 if (inputSurface == NULL) {
1223 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001224 }
1225
1226 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001227 if (!mDevice.get()) {
1228 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1229 }
1230 sp<IGraphicBufferProducer> producer;
1231 status_t err = mDevice->getInputBufferProducer(&producer);
1232 if (err != OK) {
1233 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001234 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001235 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001236 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001237 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001238 inputSurface->graphicBufferProducer = producer;
1239 }
1240 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001241}
1242
Emilian Peev40ead602017-09-26 15:46:36 +01001243binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1244 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1245 ATRACE_CALL();
1246
1247 binder::Status res;
1248 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1249
1250 Mutex::Autolock icl(mBinderSerializationLock);
1251
1252 if (!mDevice.get()) {
1253 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1254 }
1255
1256 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1257 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001258 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001259
Emilian Peev40ead602017-09-26 15:46:36 +01001260 auto producerCount = bufferProducers.size();
1261 if (producerCount == 0) {
1262 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1263 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1264 "bufferProducers must not be empty");
1265 }
1266
1267 // The first output is the one associated with the output configuration.
1268 // It should always be present, valid and the corresponding stream id should match.
1269 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1270 ssize_t index = mStreamMap.indexOfKey(binder);
1271 if (index == NAME_NOT_FOUND) {
1272 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1273 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1274 "OutputConfiguration is invalid");
1275 }
1276 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1277 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1278 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1279 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1280 "Stream id is invalid");
1281 }
1282
1283 std::vector<size_t> removedSurfaceIds;
1284 std::vector<sp<IBinder>> removedOutputs;
1285 std::vector<sp<Surface>> newOutputs;
1286 std::vector<OutputStreamInfo> streamInfos;
1287 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1288 for (auto &it : bufferProducers) {
1289 newOutputsMap.add(IInterface::asBinder(it), it);
1290 }
1291
1292 for (size_t i = 0; i < mStreamMap.size(); i++) {
1293 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1294 if (idx == NAME_NOT_FOUND) {
1295 if (mStreamMap[i].streamId() == streamId) {
1296 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1297 removedOutputs.push_back(mStreamMap.keyAt(i));
1298 }
1299 } else {
1300 if (mStreamMap[i].streamId() != streamId) {
1301 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1302 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1303 "Target Surface is invalid");
1304 }
1305 newOutputsMap.removeItemsAt(idx);
1306 }
1307 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001308 const std::vector<int32_t> &sensorPixelModesUsed =
1309 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001310 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001311 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001312 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001313 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001314 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001315
Emilian Peev40ead602017-09-26 15:46:36 +01001316 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1317 OutputStreamInfo outInfo;
1318 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001319 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001320 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001321 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001322 streamUseCase, timestampBase, mirrorMode, colorSpace);
Emilian Peev40ead602017-09-26 15:46:36 +01001323 if (!res.isOk())
1324 return res;
1325
Emilian Peev40ead602017-09-26 15:46:36 +01001326 streamInfos.push_back(outInfo);
1327 newOutputs.push_back(surface);
1328 }
1329
1330 //Trivial case no changes required
1331 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1332 return binder::Status::ok();
1333 }
1334
1335 KeyedVector<sp<Surface>, size_t> outputMap;
1336 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1337 &outputMap);
1338 if (ret != OK) {
1339 switch (ret) {
1340 case NAME_NOT_FOUND:
1341 case BAD_VALUE:
1342 case -EBUSY:
1343 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1344 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001345 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001346 break;
1347 default:
1348 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1349 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001350 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001351 break;
1352 }
1353 } else {
1354 for (const auto &it : removedOutputs) {
1355 mStreamMap.removeItem(it);
1356 }
1357
1358 for (size_t i = 0; i < outputMap.size(); i++) {
1359 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1360 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1361 }
1362
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001363 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1364
Emilian Peev40ead602017-09-26 15:46:36 +01001365 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001366 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001367 }
1368
1369 return res;
1370}
1371
Igor Murashkine7ee7632013-06-11 18:10:18 -07001372// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001373binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1374 /*out*/
1375 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001376{
1377 ATRACE_CALL();
1378 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1379
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001380 binder::Status res;
1381 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001382
1383 Mutex::Autolock icl(mBinderSerializationLock);
1384
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001385 if (!mDevice.get()) {
1386 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1387 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001388
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001389 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001390 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
Shuzhen Wang045be6c2023-10-12 10:01:10 -07001391 res = SessionConfigurationUtils::mapRequestTemplateFromClient(
1392 mCameraIdStr, templateId, &tempId);
1393 if (!res.isOk()) return res;
Emilian Peevf4816702020-04-03 15:44:51 -07001394
1395 CameraMetadata metadata;
1396 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001397 request != NULL) {
1398
1399 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001400 } else if (err == BAD_VALUE) {
1401 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001402 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001403 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001404
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001405 } else {
1406 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001407 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001408 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001409 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001410 return res;
1411}
1412
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001413binder::Status CameraDeviceClient::getCameraInfo(
1414 /*out*/
1415 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001416{
1417 ATRACE_CALL();
1418 ALOGV("%s", __FUNCTION__);
1419
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001420 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001421
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001422 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001423
1424 Mutex::Autolock icl(mBinderSerializationLock);
1425
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001426 if (!mDevice.get()) {
1427 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1428 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001429
Igor Murashkin099b4572013-07-12 17:52:16 -07001430 if (info != NULL) {
1431 *info = mDevice->info(); // static camera metadata
1432 // TODO: merge with device-specific camera metadata
1433 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001434
1435 return res;
1436}
1437
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001438binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001439{
1440 ATRACE_CALL();
1441 ALOGV("%s", __FUNCTION__);
1442
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001443 binder::Status res;
1444 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001445
1446 Mutex::Autolock icl(mBinderSerializationLock);
1447
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001448 if (!mDevice.get()) {
1449 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1450 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001451
1452 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001453 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001454 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001455 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001456 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001457 mCameraIdStr.c_str());
1458 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1459 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001460 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001461 status_t err = mDevice->waitUntilDrained();
1462 if (err != OK) {
1463 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001464 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001465 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001466 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001467 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001468 return res;
1469}
1470
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001471binder::Status CameraDeviceClient::flush(
1472 /*out*/
1473 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001474 ATRACE_CALL();
1475 ALOGV("%s", __FUNCTION__);
1476
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001477 binder::Status res;
1478 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001479
1480 Mutex::Autolock icl(mBinderSerializationLock);
1481
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001482 if (!mDevice.get()) {
1483 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1484 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001485
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001486 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001487 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001488 status_t err = mDevice->flush(lastFrameNumber);
1489 if (err != OK) {
1490 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001491 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1492 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001493 }
1494 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001495}
1496
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001497binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001498 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001499 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001500
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001501 binder::Status res;
1502 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001503
1504 Mutex::Autolock icl(mBinderSerializationLock);
1505
1506 // Guard against trying to prepare non-created streams
1507 ssize_t index = NAME_NOT_FOUND;
1508 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001509 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001510 index = i;
1511 break;
1512 }
1513 }
1514
1515 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001516 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1517 "with that ID exists", mCameraIdStr.c_str(), streamId);
1518 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1519 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001520 }
1521
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001522 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1523 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001524 status_t err = mDevice->prepare(streamId);
1525 if (err == BAD_VALUE) {
1526 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001527 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001528 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001529 } else if (err != OK) {
1530 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001531 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001532 strerror(-err), err);
1533 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001534 return res;
1535}
1536
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001537binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001538 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001539 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001540
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001541 binder::Status res;
1542 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001543
1544 Mutex::Autolock icl(mBinderSerializationLock);
1545
1546 // Guard against trying to prepare non-created streams
1547 ssize_t index = NAME_NOT_FOUND;
1548 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001549 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001550 index = i;
1551 break;
1552 }
1553 }
1554
1555 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001556 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1557 "with that ID exists", mCameraIdStr.c_str(), streamId);
1558 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1559 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001560 }
1561
1562 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001563 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1564 mCameraIdStr.c_str(), maxCount);
1565 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1566 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001567 }
1568
1569 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1570 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001571 status_t err = mDevice->prepare(maxCount, streamId);
1572 if (err == BAD_VALUE) {
1573 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001574 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001575 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001576 } else if (err != OK) {
1577 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001578 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001579 strerror(-err), err);
1580 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001581
1582 return res;
1583}
1584
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001585binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001586 ATRACE_CALL();
1587 ALOGV("%s", __FUNCTION__);
1588
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001589 binder::Status res;
1590 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001591
1592 Mutex::Autolock icl(mBinderSerializationLock);
1593
1594 // Guard against trying to prepare non-created streams
1595 ssize_t index = NAME_NOT_FOUND;
1596 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001597 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001598 index = i;
1599 break;
1600 }
1601 }
1602
1603 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001604 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1605 "with that ID exists", mCameraIdStr.c_str(), streamId);
1606 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1607 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001608 }
1609
1610 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1611 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001612 status_t err = mDevice->tearDown(streamId);
1613 if (err == BAD_VALUE) {
1614 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001615 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001616 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001617 } else if (err != OK) {
1618 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001619 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001620 strerror(-err), err);
1621 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001622
1623 return res;
1624}
1625
Shuzhen Wang758c2152017-01-10 18:26:18 -08001626binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001627 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1628 ATRACE_CALL();
1629
1630 binder::Status res;
1631 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1632
1633 Mutex::Autolock icl(mBinderSerializationLock);
1634
Shuzhen Wang0129d522016-10-30 22:43:41 -07001635 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1636 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001637 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001638
Shuzhen Wang0129d522016-10-30 22:43:41 -07001639 if (bufferProducers.size() == 0) {
1640 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001641 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1642 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001643
Shuzhen Wang758c2152017-01-10 18:26:18 -08001644 // streamId should be in mStreamMap if this stream already has a surface attached
1645 // to it. Otherwise, it should be in mDeferredStreams.
1646 bool streamIdConfigured = false;
1647 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1648 for (size_t i = 0; i < mStreamMap.size(); i++) {
1649 if (mStreamMap.valueAt(i).streamId() == streamId) {
1650 streamIdConfigured = true;
1651 break;
1652 }
Zhijun He5d677d12016-05-29 16:52:39 -07001653 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001654 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1655 if (streamId == mDeferredStreams[i]) {
1656 deferredStreamIndex = i;
1657 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001658 }
1659
Shuzhen Wang758c2152017-01-10 18:26:18 -08001660 }
1661 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001662 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1663 "(ID %d)", mCameraIdStr.c_str(), streamId);
1664 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1665 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001666 }
1667
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001668 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001669 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1670 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1671 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1672 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001673 }
1674
Zhijun He5d677d12016-05-29 16:52:39 -07001675 if (!mDevice.get()) {
1676 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1677 }
1678
Shuzhen Wang758c2152017-01-10 18:26:18 -08001679 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001680 const std::vector<int32_t> &sensorPixelModesUsed =
1681 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001682 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001683 int32_t colorSpace = outputConfiguration.getColorSpace();
1684 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001685 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001686 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001687 for (auto& bufferProducer : bufferProducers) {
1688 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001689 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1690 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001691 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001692 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001693 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001694 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001695
1696 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001697 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001698 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001699 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001700 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001701
1702 if (!res.isOk())
1703 return res;
1704
1705 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001706 }
1707
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001708 // Gracefully handle case where finalizeOutputConfigurations is called
1709 // without any new surface.
1710 if (consumerSurfaces.size() == 0) {
1711 mStreamInfoMap[streamId].finalized = true;
1712 return res;
1713 }
1714
Zhijun He5d677d12016-05-29 16:52:39 -07001715 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001716 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001717 std::vector<int> consumerSurfaceIds;
1718 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001719 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001720 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1721 sp<IBinder> binder = IInterface::asBinder(
1722 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001723 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001724 binder.get(), streamId, consumerSurfaceIds[i]);
1725 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1726 }
1727 if (deferredStreamIndex != NAME_NOT_FOUND) {
1728 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001729 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001730 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001731 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001732 } else if (err == NO_INIT) {
1733 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001734 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001735 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001736 } else {
1737 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001738 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001739 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001740 }
1741
1742 return res;
1743}
1744
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001745binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001746 ATRACE_CALL();
1747 binder::Status res;
1748 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1749
1750 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001751 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1752 mCameraIdStr.c_str(), mode);
1753 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1754 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001755 }
1756
1757 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001758 BasicClient::setAudioRestriction(mode);
1759 return binder::Status::ok();
1760}
1761
1762binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1763 ATRACE_CALL();
1764 binder::Status res;
1765 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1766 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001767 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001768 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001769 }
1770 return binder::Status::ok();
1771}
1772
Ravneetaeb20dc2022-03-30 05:33:03 +00001773status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1774 return mDevice->setCameraServiceWatchdog(enabled);
1775}
1776
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001777status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal) {
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001778 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1779
1780 return mDevice->setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001781 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop), fromHal);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001782}
1783
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001784status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1785 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1786
1787 return mDevice->setAutoframingAutoBehavior(
1788 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1789}
1790
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001791bool CameraDeviceClient::supportsCameraMute() {
1792 return mDevice->supportsCameraMute();
1793}
1794
1795status_t CameraDeviceClient::setCameraMute(bool enabled) {
1796 return mDevice->setCameraMute(enabled);
1797}
1798
Shuzhen Wang16610a62022-12-15 22:38:07 -08001799void CameraDeviceClient::setStreamUseCaseOverrides(
1800 const std::vector<int64_t>& useCaseOverrides) {
1801 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1802}
1803
1804void CameraDeviceClient::clearStreamUseCaseOverrides() {
1805 mDevice->clearStreamUseCaseOverrides();
1806}
1807
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001808bool CameraDeviceClient::supportsZoomOverride() {
1809 return mDevice->supportsZoomOverride();
1810}
1811
1812status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1813 return mDevice->setZoomOverride(zoomOverride);
1814}
1815
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001816binder::Status CameraDeviceClient::switchToOffline(
1817 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001818 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001819 /*out*/
1820 sp<hardware::camera2::ICameraOfflineSession>* session) {
1821 ATRACE_CALL();
1822
1823 binder::Status res;
1824 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1825
1826 Mutex::Autolock icl(mBinderSerializationLock);
1827
1828 if (!mDevice.get()) {
1829 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1830 }
1831
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001832 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001833 std::string msg = "Offline surfaces must not be empty";
1834 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1835 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001836 }
1837
1838 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001839 std::string msg = "Invalid offline session";
1840 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1841 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001842 }
1843
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001844 std::vector<int32_t> offlineStreamIds;
1845 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001846 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001847 for (const auto& streamId : offlineOutputIds) {
1848 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001849 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001850 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001851 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001852 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1853 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001854 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001855
1856 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001857 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001858 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001859 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1860 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001861 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001862
Emilian Peev2f5d6012022-01-19 16:16:50 -08001863 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001864 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001865 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001866 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001867 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001868 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001869 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001870 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001871 if (isCompositeStream) {
1872 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1873 if (compositeIdx == NAME_NOT_FOUND) {
1874 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1875 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1876 "Unknown composite stream");
1877 }
1878
1879 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1880 &offlineStreamIds);
1881 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1882 mCompositeStreamMap.valueAt(compositeIdx));
1883 break;
1884 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001885 }
1886
Emilian Peev4697b642019-11-19 17:11:14 -08001887 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001888 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001889 }
1890 }
1891
1892 sp<CameraOfflineSessionBase> offlineSession;
1893 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1894 if (ret != OK) {
1895 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1896 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001897 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001898 }
1899
Emilian Peevcc0b7952020-01-07 13:54:47 -08001900 sp<CameraOfflineSessionClient> offlineClient;
1901 if (offlineSession.get() != nullptr) {
1902 offlineClient = new CameraOfflineSessionClient(sCameraService,
Charles Chenf075f082024-03-04 23:32:55 +00001903 offlineSession, offlineCompositeStreamMap, cameraCb, mClientPackageName,
1904 mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation, mClientPid, mClientUid,
1905 mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001906 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1907 }
1908
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001909 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001910 // A successful offline session switch must reset the current camera client
1911 // and release any resources occupied by previously configured streams.
1912 mStreamMap.clear();
1913 mConfiguredOutputs.clear();
1914 mDeferredStreams.clear();
1915 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001916 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001917 mCompositeStreamMap.clear();
1918 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001919 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001920 // In case we failed to register the offline client, ensure that it still initialized
1921 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001922 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001923
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001924 switch(ret) {
1925 case BAD_VALUE:
1926 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1927 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1928 case TIMED_OUT:
1929 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1930 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1931 default:
1932 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1933 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1934 strerror(-ret), ret);
1935 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001936 }
1937
1938 *session = offlineClient;
1939
1940 return binder::Status::ok();
1941}
1942
Igor Murashkine7ee7632013-06-11 18:10:18 -07001943status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001944 return BasicClient::dump(fd, args);
1945}
1946
1947status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001948 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001949 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001950 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001951 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001952 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001953
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001954 dprintf(fd, " State:\n");
1955 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001956 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001957 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001958 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001959 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001960 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001961 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001962 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001963 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001964 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001965 mStreamMap.valueAt(i).streamId(),
1966 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001967 }
Zhijun He5d677d12016-05-29 16:52:39 -07001968 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001969 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001970 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001971 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001972 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001973 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001974 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001975 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001976 // TODO: print dynamic/request section from most recent requests
1977 mFrameProcessor->dump(fd, args);
1978
1979 return dumpDevice(fd, args);
1980}
1981
Austin Borger1c1bee02023-06-01 16:51:35 -07001982status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07001983 sp<CameraDeviceBase> device = mDevice;
1984 if (!device) {
1985 dprintf(out, " Device is detached.");
1986 return OK;
1987 }
1988 device->startWatchingTags(tags);
1989 return OK;
1990}
1991
1992status_t CameraDeviceClient::stopWatchingTags(int out) {
1993 sp<CameraDeviceBase> device = mDevice;
1994 if (!device) {
1995 dprintf(out, " Device is detached.");
1996 return OK;
1997 }
1998 device->stopWatchingTags();
1999 return OK;
2000}
2001
2002status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
2003 sp<CameraDeviceBase> device = mDevice;
2004 if (!device) {
2005 return OK;
2006 }
2007 device->dumpWatchedEventsToVector(out);
2008 return OK;
2009}
2010
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002011void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07002012 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002013 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002014 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002015
Emilian Peev538c90e2018-12-17 18:03:19 +00002016 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002017 {
2018 // Access to the composite stream map must be synchronized
2019 Mutex::Autolock l(mCompositeLock);
2020 // Composites can have multiple internal streams. Error notifications coming from such
2021 // internal streams may need to remain within camera service.
2022 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2023 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2024 resultExtras);
2025 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002026 }
2027
2028 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002029 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002030 }
2031}
2032
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002033void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2034 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2035
2036 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002037 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002038 }
2039
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002040 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002041 mStreamingRequestId = REQUEST_ID_NONE;
2042}
2043
Shuzhen Wang316781a2020-08-18 18:11:01 -07002044void CameraDeviceClient::notifyIdle(
2045 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2046 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002047 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002048 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002049
2050 if (remoteCb != 0) {
2051 remoteCb->onDeviceIdle();
2052 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002053
2054 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2055 {
2056 Mutex::Autolock l(mCompositeLock);
2057 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2058 hardware::CameraStreamStats compositeStats;
2059 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2060 if (compositeStats.mWidth > 0) {
2061 fullStreamStats.push_back(compositeStats);
2062 }
2063 }
2064 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002065 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Shuzhen Wang6e08d202023-10-24 20:27:14 +00002066 fullStreamStats, mUserTag, mVideoStabilizationMode, mUsedUltraWide,
2067 mUsedSettingsOverrideZoom);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002068}
2069
Jianing Weicb0652e2014-03-12 18:29:36 -07002070void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002071 nsecs_t timestamp) {
2072 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002073 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002074 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002075 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002076 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002077 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002078
Emilian Peev2f5d6012022-01-19 16:16:50 -08002079 // Access to the composite stream map must be synchronized
2080 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002081 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2082 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2083 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002084}
2085
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002086void CameraDeviceClient::notifyPrepared(int streamId) {
2087 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002088 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002089 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002090 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002091 remoteCb->onPrepared(streamId);
2092 }
2093}
2094
Shuzhen Wang9d066012016-09-30 11:30:20 -07002095void CameraDeviceClient::notifyRequestQueueEmpty() {
2096 // Thread safe. Don't bother locking.
2097 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2098 if (remoteCb != 0) {
2099 remoteCb->onRequestQueueEmpty();
2100 }
2101}
2102
Igor Murashkine7ee7632013-06-11 18:10:18 -07002103void CameraDeviceClient::detachDevice() {
2104 if (mDevice == 0) return;
2105
Shuzhen Wang316781a2020-08-18 18:11:01 -07002106 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002107 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002108
Emilian Peev7ee731f2022-02-08 14:55:52 -08002109 if (mFrameProcessor.get() != nullptr) {
2110 mFrameProcessor->removeListener(
2111 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2112 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2113 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002114 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002115 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002116 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002117 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002118
2119 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2120 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002121 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002122 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002123 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2124 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2125 }
2126
Igor Murashkine7ee7632013-06-11 18:10:18 -07002127 if ((code = mDevice->waitUntilDrained()) != OK) {
2128 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2129 code);
2130 }
2131 }
2132
Emilian Peev2f5d6012022-01-19 16:16:50 -08002133 {
2134 Mutex::Autolock l(mCompositeLock);
2135 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2136 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2137 if (ret != OK) {
2138 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2139 strerror(-ret), ret);
2140 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002141 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002142 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002143 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002144
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002145 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002146 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002147
2148 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002149 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002150}
2151
2152/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002153void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002154 ATRACE_CALL();
2155 ALOGV("%s", __FUNCTION__);
2156
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002157 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002158 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002159 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002160 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2161 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002162 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002163
Emilian Peev2f5d6012022-01-19 16:16:50 -08002164 // Access to the composite stream map must be synchronized
2165 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002166 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2167 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2168 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002169}
2170
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002171binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002172 if (mDisconnected) {
2173 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2174 "The camera device has been disconnected");
2175 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002176 status_t res = checkPid(checkLocation);
2177 return (res == OK) ? binder::Status::ok() :
2178 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2179 "Attempt to use camera from a different process than original client");
2180}
2181
Igor Murashkine7ee7632013-06-11 18:10:18 -07002182// TODO: move to Camera2ClientBase
2183bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2184
Jayant Chowdhary12361932018-08-27 14:46:13 -07002185 const int pid = CameraThreadState::getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002186 const int selfPid = getpid();
2187 camera_metadata_entry_t entry;
2188
2189 /**
2190 * Mixin default important security values
2191 * - android.led.transmit = defaulted ON
2192 */
2193 CameraMetadata staticInfo = mDevice->info();
2194 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2195 for(size_t i = 0; i < entry.count; ++i) {
2196 uint8_t led = entry.data.u8[i];
2197
2198 switch(led) {
2199 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2200 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2201 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2202 metadata.update(ANDROID_LED_TRANSMIT,
2203 &transmitDefault, 1);
2204 }
2205 break;
2206 }
2207 }
2208 }
2209
2210 // We can do anything!
2211 if (pid == selfPid) {
2212 return true;
2213 }
2214
2215 /**
2216 * Permission check special fields in the request
2217 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2218 */
2219 entry = metadata.find(ANDROID_LED_TRANSMIT);
2220 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2221 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002222 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002223 if (!checkCallingPermission(permissionString)) {
Jayant Chowdhary12361932018-08-27 14:46:13 -07002224 const int uid = CameraThreadState::getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002225 ALOGE("Permission Denial: "
2226 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2227 return false;
2228 }
2229 }
2230
2231 return true;
2232}
2233
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002234status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2235 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002236 ALOGV("%s: begin", __FUNCTION__);
2237
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002238 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002239 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002240}
2241
Austin Borger1c1bee02023-06-01 16:51:35 -07002242const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002243 if (mDevice->getId() == cameraId) {
2244 return mDevice->info();
2245 }
2246 return mDevice->infoPhysical(cameraId);
2247}
2248
Austin Borger1c1bee02023-06-01 16:51:35 -07002249bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002250 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002251 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002252}
2253
2254bool CameraDeviceClient::isSensorPixelModeConsistent(
2255 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2256 // First we get the sensorPixelMode from the settings metadata.
2257 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2258 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2259 if (sensorPixelModeEntry.count != 0) {
2260 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2261 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2262 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2263 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2264 __FUNCTION__, sensorPixelMode);
2265 return false;
2266 }
2267 }
2268 // Check whether each stream has max resolution allowed.
2269 bool consistent = true;
2270 for (auto it : streamIdList) {
2271 auto const streamInfoIt = mStreamInfoMap.find(it);
2272 if (streamInfoIt == mStreamInfoMap.end()) {
2273 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2274 return false;
2275 }
2276 consistent =
2277 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2278 streamInfoIt->second.sensorPixelModesUsed.end();
2279 if (!consistent) {
2280 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2281 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2282 ALOGE("sensor pixel mode used list: %i", m);
2283 }
2284 break;
2285 }
2286 }
2287
2288 return consistent;
2289}
2290
Igor Murashkine7ee7632013-06-11 18:10:18 -07002291} // namespace android