blob: 095d4250f4315ce914ccf734472b28fab9632884 [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) :
Austin Borger74fca042022-05-23 12:41:21 -0700107 Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper, clientPackageName,
108 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,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001012 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)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001109 mCameraIdStr.c_str(), width, height, format, dataSpace, strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001110 } else {
1111 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1112 // a separate list to track. Once the deferred surface is set, this id will be
1113 // relocated to mStreamMap.
1114 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001115 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001116 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001117 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001118 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001119 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001120 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001121 outputConfiguration.getMirrorMode(),
1122 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001123
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001124 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001125 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001126 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001127
1128 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001129 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001130
1131 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001132 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001133 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001134 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001135 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001136 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001137 }
Zhijun He5d677d12016-05-29 16:52:39 -07001138 }
1139 return res;
1140}
1141
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001142binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001143 int32_t transform = 0;
1144 status_t err;
1145 binder::Status res;
1146
1147 if (!mDevice.get()) {
1148 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1149 }
1150
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001151 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001152 if (err != OK) {
1153 // Error logged by getRotationTransformLocked.
1154 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1155 "Unable to calculate rotation transform for new stream");
1156 }
1157
1158 err = mDevice->setStreamTransform(streamId, transform);
1159 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001160 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001161 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001162 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1163 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001164 }
1165
1166 return res;
1167}
Ruben Brunkbba75572014-11-20 17:29:50 -08001168
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001169binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001170 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001171 /*out*/
1172 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001173
1174 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001175 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1176 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001177
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001178 binder::Status res;
1179 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001180
1181 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001182
1183 if (!mDevice.get()) {
1184 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1185 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001186
1187 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001188 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1189 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1190 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1191 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001192 }
1193
1194 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001195 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001196 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001197 mInputStream.configured = true;
1198 mInputStream.width = width;
1199 mInputStream.height = height;
1200 mInputStream.format = format;
1201 mInputStream.id = streamId;
1202
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001203 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001204 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001205
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001206 *newStreamId = streamId;
1207 } else {
1208 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001209 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001210 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001211 }
1212
1213 return res;
1214}
1215
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001216binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001217
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001218 binder::Status res;
1219 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1220
1221 if (inputSurface == NULL) {
1222 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001223 }
1224
1225 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001226 if (!mDevice.get()) {
1227 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1228 }
1229 sp<IGraphicBufferProducer> producer;
1230 status_t err = mDevice->getInputBufferProducer(&producer);
1231 if (err != OK) {
1232 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001233 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001234 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001235 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001236 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001237 inputSurface->graphicBufferProducer = producer;
1238 }
1239 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001240}
1241
Emilian Peev40ead602017-09-26 15:46:36 +01001242binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1243 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1244 ATRACE_CALL();
1245
1246 binder::Status res;
1247 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1248
1249 Mutex::Autolock icl(mBinderSerializationLock);
1250
1251 if (!mDevice.get()) {
1252 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1253 }
1254
1255 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1256 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001257 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001258
Emilian Peev40ead602017-09-26 15:46:36 +01001259 auto producerCount = bufferProducers.size();
1260 if (producerCount == 0) {
1261 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1262 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1263 "bufferProducers must not be empty");
1264 }
1265
1266 // The first output is the one associated with the output configuration.
1267 // It should always be present, valid and the corresponding stream id should match.
1268 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1269 ssize_t index = mStreamMap.indexOfKey(binder);
1270 if (index == NAME_NOT_FOUND) {
1271 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1272 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1273 "OutputConfiguration is invalid");
1274 }
1275 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1276 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1277 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1278 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1279 "Stream id is invalid");
1280 }
1281
1282 std::vector<size_t> removedSurfaceIds;
1283 std::vector<sp<IBinder>> removedOutputs;
1284 std::vector<sp<Surface>> newOutputs;
1285 std::vector<OutputStreamInfo> streamInfos;
1286 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1287 for (auto &it : bufferProducers) {
1288 newOutputsMap.add(IInterface::asBinder(it), it);
1289 }
1290
1291 for (size_t i = 0; i < mStreamMap.size(); i++) {
1292 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1293 if (idx == NAME_NOT_FOUND) {
1294 if (mStreamMap[i].streamId() == streamId) {
1295 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1296 removedOutputs.push_back(mStreamMap.keyAt(i));
1297 }
1298 } else {
1299 if (mStreamMap[i].streamId() != streamId) {
1300 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1301 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1302 "Target Surface is invalid");
1303 }
1304 newOutputsMap.removeItemsAt(idx);
1305 }
1306 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001307 const std::vector<int32_t> &sensorPixelModesUsed =
1308 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001309 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001310 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001311 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001312 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001313 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001314
Emilian Peev40ead602017-09-26 15:46:36 +01001315 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1316 OutputStreamInfo outInfo;
1317 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001318 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001319 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001320 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001321 streamUseCase, timestampBase, mirrorMode, colorSpace);
Emilian Peev40ead602017-09-26 15:46:36 +01001322 if (!res.isOk())
1323 return res;
1324
Emilian Peev40ead602017-09-26 15:46:36 +01001325 streamInfos.push_back(outInfo);
1326 newOutputs.push_back(surface);
1327 }
1328
1329 //Trivial case no changes required
1330 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1331 return binder::Status::ok();
1332 }
1333
1334 KeyedVector<sp<Surface>, size_t> outputMap;
1335 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1336 &outputMap);
1337 if (ret != OK) {
1338 switch (ret) {
1339 case NAME_NOT_FOUND:
1340 case BAD_VALUE:
1341 case -EBUSY:
1342 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1343 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001344 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001345 break;
1346 default:
1347 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1348 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001349 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001350 break;
1351 }
1352 } else {
1353 for (const auto &it : removedOutputs) {
1354 mStreamMap.removeItem(it);
1355 }
1356
1357 for (size_t i = 0; i < outputMap.size(); i++) {
1358 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1359 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1360 }
1361
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001362 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1363
Emilian Peev40ead602017-09-26 15:46:36 +01001364 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001365 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001366 }
1367
1368 return res;
1369}
1370
Igor Murashkine7ee7632013-06-11 18:10:18 -07001371// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001372binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1373 /*out*/
1374 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001375{
1376 ATRACE_CALL();
1377 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1378
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001379 binder::Status res;
1380 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001381
1382 Mutex::Autolock icl(mBinderSerializationLock);
1383
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001384 if (!mDevice.get()) {
1385 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1386 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001387
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001388 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001389 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
Shuzhen Wang045be6c2023-10-12 10:01:10 -07001390 res = SessionConfigurationUtils::mapRequestTemplateFromClient(
1391 mCameraIdStr, templateId, &tempId);
1392 if (!res.isOk()) return res;
Emilian Peevf4816702020-04-03 15:44:51 -07001393
1394 CameraMetadata metadata;
1395 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001396 request != NULL) {
1397
1398 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001399 } else if (err == BAD_VALUE) {
1400 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001401 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001402 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001403
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001404 } else {
1405 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001406 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001407 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001408 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001409 return res;
1410}
1411
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001412binder::Status CameraDeviceClient::getCameraInfo(
1413 /*out*/
1414 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001415{
1416 ATRACE_CALL();
1417 ALOGV("%s", __FUNCTION__);
1418
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001419 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001420
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001421 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001422
1423 Mutex::Autolock icl(mBinderSerializationLock);
1424
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001425 if (!mDevice.get()) {
1426 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1427 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001428
Igor Murashkin099b4572013-07-12 17:52:16 -07001429 if (info != NULL) {
1430 *info = mDevice->info(); // static camera metadata
1431 // TODO: merge with device-specific camera metadata
1432 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001433
1434 return res;
1435}
1436
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001437binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001438{
1439 ATRACE_CALL();
1440 ALOGV("%s", __FUNCTION__);
1441
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001442 binder::Status res;
1443 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001444
1445 Mutex::Autolock icl(mBinderSerializationLock);
1446
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001447 if (!mDevice.get()) {
1448 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1449 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001450
1451 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001452 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001453 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001454 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001455 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001456 mCameraIdStr.c_str());
1457 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1458 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001459 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001460 status_t err = mDevice->waitUntilDrained();
1461 if (err != OK) {
1462 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001463 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001464 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001465 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001466 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001467 return res;
1468}
1469
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001470binder::Status CameraDeviceClient::flush(
1471 /*out*/
1472 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001473 ATRACE_CALL();
1474 ALOGV("%s", __FUNCTION__);
1475
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001476 binder::Status res;
1477 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001478
1479 Mutex::Autolock icl(mBinderSerializationLock);
1480
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001481 if (!mDevice.get()) {
1482 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1483 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001484
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001485 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001486 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001487 status_t err = mDevice->flush(lastFrameNumber);
1488 if (err != OK) {
1489 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001490 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1491 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001492 }
1493 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001494}
1495
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001496binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001497 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001498 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001499
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001500 binder::Status res;
1501 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001502
1503 Mutex::Autolock icl(mBinderSerializationLock);
1504
1505 // Guard against trying to prepare non-created streams
1506 ssize_t index = NAME_NOT_FOUND;
1507 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001508 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001509 index = i;
1510 break;
1511 }
1512 }
1513
1514 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001515 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1516 "with that ID exists", mCameraIdStr.c_str(), streamId);
1517 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1518 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001519 }
1520
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001521 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1522 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001523 status_t err = mDevice->prepare(streamId);
1524 if (err == BAD_VALUE) {
1525 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001526 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001527 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001528 } else if (err != OK) {
1529 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001530 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001531 strerror(-err), err);
1532 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001533 return res;
1534}
1535
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001536binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001537 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001538 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001539
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001540 binder::Status res;
1541 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001542
1543 Mutex::Autolock icl(mBinderSerializationLock);
1544
1545 // Guard against trying to prepare non-created streams
1546 ssize_t index = NAME_NOT_FOUND;
1547 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001548 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001549 index = i;
1550 break;
1551 }
1552 }
1553
1554 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001555 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1556 "with that ID exists", mCameraIdStr.c_str(), streamId);
1557 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1558 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001559 }
1560
1561 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001562 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1563 mCameraIdStr.c_str(), maxCount);
1564 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1565 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001566 }
1567
1568 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1569 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001570 status_t err = mDevice->prepare(maxCount, streamId);
1571 if (err == BAD_VALUE) {
1572 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001573 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001574 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001575 } else if (err != OK) {
1576 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001577 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001578 strerror(-err), err);
1579 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001580
1581 return res;
1582}
1583
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001584binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001585 ATRACE_CALL();
1586 ALOGV("%s", __FUNCTION__);
1587
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001588 binder::Status res;
1589 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001590
1591 Mutex::Autolock icl(mBinderSerializationLock);
1592
1593 // Guard against trying to prepare non-created streams
1594 ssize_t index = NAME_NOT_FOUND;
1595 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001596 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001597 index = i;
1598 break;
1599 }
1600 }
1601
1602 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001603 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1604 "with that ID exists", mCameraIdStr.c_str(), streamId);
1605 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1606 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001607 }
1608
1609 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1610 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001611 status_t err = mDevice->tearDown(streamId);
1612 if (err == BAD_VALUE) {
1613 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001614 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001615 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001616 } else if (err != OK) {
1617 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001618 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001619 strerror(-err), err);
1620 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001621
1622 return res;
1623}
1624
Shuzhen Wang758c2152017-01-10 18:26:18 -08001625binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001626 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1627 ATRACE_CALL();
1628
1629 binder::Status res;
1630 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1631
1632 Mutex::Autolock icl(mBinderSerializationLock);
1633
Shuzhen Wang0129d522016-10-30 22:43:41 -07001634 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1635 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001636 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001637
Shuzhen Wang0129d522016-10-30 22:43:41 -07001638 if (bufferProducers.size() == 0) {
1639 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001640 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1641 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001642
Shuzhen Wang758c2152017-01-10 18:26:18 -08001643 // streamId should be in mStreamMap if this stream already has a surface attached
1644 // to it. Otherwise, it should be in mDeferredStreams.
1645 bool streamIdConfigured = false;
1646 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1647 for (size_t i = 0; i < mStreamMap.size(); i++) {
1648 if (mStreamMap.valueAt(i).streamId() == streamId) {
1649 streamIdConfigured = true;
1650 break;
1651 }
Zhijun He5d677d12016-05-29 16:52:39 -07001652 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001653 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1654 if (streamId == mDeferredStreams[i]) {
1655 deferredStreamIndex = i;
1656 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001657 }
1658
Shuzhen Wang758c2152017-01-10 18:26:18 -08001659 }
1660 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001661 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1662 "(ID %d)", mCameraIdStr.c_str(), streamId);
1663 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1664 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001665 }
1666
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001667 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001668 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1669 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1670 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1671 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001672 }
1673
Zhijun He5d677d12016-05-29 16:52:39 -07001674 if (!mDevice.get()) {
1675 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1676 }
1677
Shuzhen Wang758c2152017-01-10 18:26:18 -08001678 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001679 const std::vector<int32_t> &sensorPixelModesUsed =
1680 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001681 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001682 int32_t colorSpace = outputConfiguration.getColorSpace();
1683 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001684 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001685 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001686 for (auto& bufferProducer : bufferProducers) {
1687 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001688 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1689 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001690 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001691 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001692 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001693 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001694
1695 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001696 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001697 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001698 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001699 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001700
1701 if (!res.isOk())
1702 return res;
1703
1704 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001705 }
1706
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001707 // Gracefully handle case where finalizeOutputConfigurations is called
1708 // without any new surface.
1709 if (consumerSurfaces.size() == 0) {
1710 mStreamInfoMap[streamId].finalized = true;
1711 return res;
1712 }
1713
Zhijun He5d677d12016-05-29 16:52:39 -07001714 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001715 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001716 std::vector<int> consumerSurfaceIds;
1717 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001718 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001719 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1720 sp<IBinder> binder = IInterface::asBinder(
1721 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001722 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001723 binder.get(), streamId, consumerSurfaceIds[i]);
1724 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1725 }
1726 if (deferredStreamIndex != NAME_NOT_FOUND) {
1727 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001728 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001729 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001730 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001731 } else if (err == NO_INIT) {
1732 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001733 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001734 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001735 } else {
1736 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001737 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001738 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001739 }
1740
1741 return res;
1742}
1743
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001744binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001745 ATRACE_CALL();
1746 binder::Status res;
1747 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1748
1749 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001750 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1751 mCameraIdStr.c_str(), mode);
1752 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1753 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001754 }
1755
1756 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001757 BasicClient::setAudioRestriction(mode);
1758 return binder::Status::ok();
1759}
1760
1761binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1762 ATRACE_CALL();
1763 binder::Status res;
1764 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1765 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001766 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001767 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001768 }
1769 return binder::Status::ok();
1770}
1771
Ravneetaeb20dc2022-03-30 05:33:03 +00001772status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1773 return mDevice->setCameraServiceWatchdog(enabled);
1774}
1775
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001776status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal) {
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001777 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1778
1779 return mDevice->setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001780 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop), fromHal);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001781}
1782
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001783status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1784 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1785
1786 return mDevice->setAutoframingAutoBehavior(
1787 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1788}
1789
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001790bool CameraDeviceClient::supportsCameraMute() {
1791 return mDevice->supportsCameraMute();
1792}
1793
1794status_t CameraDeviceClient::setCameraMute(bool enabled) {
1795 return mDevice->setCameraMute(enabled);
1796}
1797
Shuzhen Wang16610a62022-12-15 22:38:07 -08001798void CameraDeviceClient::setStreamUseCaseOverrides(
1799 const std::vector<int64_t>& useCaseOverrides) {
1800 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1801}
1802
1803void CameraDeviceClient::clearStreamUseCaseOverrides() {
1804 mDevice->clearStreamUseCaseOverrides();
1805}
1806
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001807bool CameraDeviceClient::supportsZoomOverride() {
1808 return mDevice->supportsZoomOverride();
1809}
1810
1811status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1812 return mDevice->setZoomOverride(zoomOverride);
1813}
1814
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001815binder::Status CameraDeviceClient::switchToOffline(
1816 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001817 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001818 /*out*/
1819 sp<hardware::camera2::ICameraOfflineSession>* session) {
1820 ATRACE_CALL();
1821
1822 binder::Status res;
1823 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1824
1825 Mutex::Autolock icl(mBinderSerializationLock);
1826
1827 if (!mDevice.get()) {
1828 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1829 }
1830
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001831 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001832 std::string msg = "Offline surfaces must not be empty";
1833 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1834 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001835 }
1836
1837 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001838 std::string msg = "Invalid offline session";
1839 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1840 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001841 }
1842
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001843 std::vector<int32_t> offlineStreamIds;
1844 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001845 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001846 for (const auto& streamId : offlineOutputIds) {
1847 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001848 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001849 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001850 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001851 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1852 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001853 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001854
1855 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001856 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001857 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001858 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1859 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001860 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001861
Emilian Peev2f5d6012022-01-19 16:16:50 -08001862 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001863 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001864 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001865 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001866 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001867 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001868 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001869 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001870 if (isCompositeStream) {
1871 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1872 if (compositeIdx == NAME_NOT_FOUND) {
1873 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1874 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1875 "Unknown composite stream");
1876 }
1877
1878 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1879 &offlineStreamIds);
1880 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1881 mCompositeStreamMap.valueAt(compositeIdx));
1882 break;
1883 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001884 }
1885
Emilian Peev4697b642019-11-19 17:11:14 -08001886 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001887 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001888 }
1889 }
1890
1891 sp<CameraOfflineSessionBase> offlineSession;
1892 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1893 if (ret != OK) {
1894 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1895 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001896 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001897 }
1898
Emilian Peevcc0b7952020-01-07 13:54:47 -08001899 sp<CameraOfflineSessionClient> offlineClient;
1900 if (offlineSession.get() != nullptr) {
1901 offlineClient = new CameraOfflineSessionClient(sCameraService,
1902 offlineSession, offlineCompositeStreamMap, cameraCb, mClientPackageName,
Emilian Peev8b64f282021-03-25 16:49:57 -07001903 mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation, mClientPid, mClientUid,
1904 mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001905 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1906 }
1907
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001908 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001909 // A successful offline session switch must reset the current camera client
1910 // and release any resources occupied by previously configured streams.
1911 mStreamMap.clear();
1912 mConfiguredOutputs.clear();
1913 mDeferredStreams.clear();
1914 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001915 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001916 mCompositeStreamMap.clear();
1917 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001918 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001919 // In case we failed to register the offline client, ensure that it still initialized
1920 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001921 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001922
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001923 switch(ret) {
1924 case BAD_VALUE:
1925 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1926 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1927 case TIMED_OUT:
1928 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1929 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1930 default:
1931 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1932 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1933 strerror(-ret), ret);
1934 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001935 }
1936
1937 *session = offlineClient;
1938
1939 return binder::Status::ok();
1940}
1941
Igor Murashkine7ee7632013-06-11 18:10:18 -07001942status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001943 return BasicClient::dump(fd, args);
1944}
1945
1946status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001947 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001948 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001949 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001950 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001951 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001952
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001953 dprintf(fd, " State:\n");
1954 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001955 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001956 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001957 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001958 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001959 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001960 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001961 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001962 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001963 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001964 mStreamMap.valueAt(i).streamId(),
1965 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001966 }
Zhijun He5d677d12016-05-29 16:52:39 -07001967 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001968 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001969 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001970 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001971 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001972 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001973 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001974 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001975 // TODO: print dynamic/request section from most recent requests
1976 mFrameProcessor->dump(fd, args);
1977
1978 return dumpDevice(fd, args);
1979}
1980
Austin Borger1c1bee02023-06-01 16:51:35 -07001981status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07001982 sp<CameraDeviceBase> device = mDevice;
1983 if (!device) {
1984 dprintf(out, " Device is detached.");
1985 return OK;
1986 }
1987 device->startWatchingTags(tags);
1988 return OK;
1989}
1990
1991status_t CameraDeviceClient::stopWatchingTags(int out) {
1992 sp<CameraDeviceBase> device = mDevice;
1993 if (!device) {
1994 dprintf(out, " Device is detached.");
1995 return OK;
1996 }
1997 device->stopWatchingTags();
1998 return OK;
1999}
2000
2001status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
2002 sp<CameraDeviceBase> device = mDevice;
2003 if (!device) {
2004 return OK;
2005 }
2006 device->dumpWatchedEventsToVector(out);
2007 return OK;
2008}
2009
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002010void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07002011 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002012 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002013 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002014
Emilian Peev538c90e2018-12-17 18:03:19 +00002015 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002016 {
2017 // Access to the composite stream map must be synchronized
2018 Mutex::Autolock l(mCompositeLock);
2019 // Composites can have multiple internal streams. Error notifications coming from such
2020 // internal streams may need to remain within camera service.
2021 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2022 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2023 resultExtras);
2024 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002025 }
2026
2027 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002028 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002029 }
2030}
2031
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002032void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2033 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2034
2035 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002036 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002037 }
2038
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002039 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002040 mStreamingRequestId = REQUEST_ID_NONE;
2041}
2042
Shuzhen Wang316781a2020-08-18 18:11:01 -07002043void CameraDeviceClient::notifyIdle(
2044 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2045 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002046 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002047 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002048
2049 if (remoteCb != 0) {
2050 remoteCb->onDeviceIdle();
2051 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002052
2053 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2054 {
2055 Mutex::Autolock l(mCompositeLock);
2056 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2057 hardware::CameraStreamStats compositeStats;
2058 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2059 if (compositeStats.mWidth > 0) {
2060 fullStreamStats.push_back(compositeStats);
2061 }
2062 }
2063 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002064 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Shuzhen Wang6e08d202023-10-24 20:27:14 +00002065 fullStreamStats, mUserTag, mVideoStabilizationMode, mUsedUltraWide,
2066 mUsedSettingsOverrideZoom);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002067}
2068
Jianing Weicb0652e2014-03-12 18:29:36 -07002069void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002070 nsecs_t timestamp) {
2071 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002072 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002073 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002074 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002075 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002076 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002077
Emilian Peev2f5d6012022-01-19 16:16:50 -08002078 // Access to the composite stream map must be synchronized
2079 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002080 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2081 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2082 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002083}
2084
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002085void CameraDeviceClient::notifyPrepared(int streamId) {
2086 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002087 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002088 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002089 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002090 remoteCb->onPrepared(streamId);
2091 }
2092}
2093
Shuzhen Wang9d066012016-09-30 11:30:20 -07002094void CameraDeviceClient::notifyRequestQueueEmpty() {
2095 // Thread safe. Don't bother locking.
2096 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2097 if (remoteCb != 0) {
2098 remoteCb->onRequestQueueEmpty();
2099 }
2100}
2101
Igor Murashkine7ee7632013-06-11 18:10:18 -07002102void CameraDeviceClient::detachDevice() {
2103 if (mDevice == 0) return;
2104
Shuzhen Wang316781a2020-08-18 18:11:01 -07002105 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002106 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002107
Emilian Peev7ee731f2022-02-08 14:55:52 -08002108 if (mFrameProcessor.get() != nullptr) {
2109 mFrameProcessor->removeListener(
2110 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2111 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2112 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002113 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002114 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002115 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002116 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002117
2118 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2119 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002120 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002121 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002122 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2123 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2124 }
2125
Igor Murashkine7ee7632013-06-11 18:10:18 -07002126 if ((code = mDevice->waitUntilDrained()) != OK) {
2127 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2128 code);
2129 }
2130 }
2131
Emilian Peev2f5d6012022-01-19 16:16:50 -08002132 {
2133 Mutex::Autolock l(mCompositeLock);
2134 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2135 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2136 if (ret != OK) {
2137 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2138 strerror(-ret), ret);
2139 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002140 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002141 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002142 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002143
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002144 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002145 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002146
2147 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002148 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002149}
2150
2151/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002152void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002153 ATRACE_CALL();
2154 ALOGV("%s", __FUNCTION__);
2155
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002156 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002157 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002158 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002159 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2160 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002161 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002162
Emilian Peev2f5d6012022-01-19 16:16:50 -08002163 // Access to the composite stream map must be synchronized
2164 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002165 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2166 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2167 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002168}
2169
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002170binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002171 if (mDisconnected) {
2172 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2173 "The camera device has been disconnected");
2174 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002175 status_t res = checkPid(checkLocation);
2176 return (res == OK) ? binder::Status::ok() :
2177 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2178 "Attempt to use camera from a different process than original client");
2179}
2180
Igor Murashkine7ee7632013-06-11 18:10:18 -07002181// TODO: move to Camera2ClientBase
2182bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2183
Jayant Chowdhary12361932018-08-27 14:46:13 -07002184 const int pid = CameraThreadState::getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002185 const int selfPid = getpid();
2186 camera_metadata_entry_t entry;
2187
2188 /**
2189 * Mixin default important security values
2190 * - android.led.transmit = defaulted ON
2191 */
2192 CameraMetadata staticInfo = mDevice->info();
2193 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2194 for(size_t i = 0; i < entry.count; ++i) {
2195 uint8_t led = entry.data.u8[i];
2196
2197 switch(led) {
2198 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2199 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2200 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2201 metadata.update(ANDROID_LED_TRANSMIT,
2202 &transmitDefault, 1);
2203 }
2204 break;
2205 }
2206 }
2207 }
2208
2209 // We can do anything!
2210 if (pid == selfPid) {
2211 return true;
2212 }
2213
2214 /**
2215 * Permission check special fields in the request
2216 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2217 */
2218 entry = metadata.find(ANDROID_LED_TRANSMIT);
2219 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2220 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002221 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002222 if (!checkCallingPermission(permissionString)) {
Jayant Chowdhary12361932018-08-27 14:46:13 -07002223 const int uid = CameraThreadState::getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002224 ALOGE("Permission Denial: "
2225 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2226 return false;
2227 }
2228 }
2229
2230 return true;
2231}
2232
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002233status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2234 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002235 ALOGV("%s: begin", __FUNCTION__);
2236
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002237 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002238 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002239}
2240
Austin Borger1c1bee02023-06-01 16:51:35 -07002241const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002242 if (mDevice->getId() == cameraId) {
2243 return mDevice->info();
2244 }
2245 return mDevice->infoPhysical(cameraId);
2246}
2247
Austin Borger1c1bee02023-06-01 16:51:35 -07002248bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002249 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002250 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002251}
2252
2253bool CameraDeviceClient::isSensorPixelModeConsistent(
2254 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2255 // First we get the sensorPixelMode from the settings metadata.
2256 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2257 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2258 if (sensorPixelModeEntry.count != 0) {
2259 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2260 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2261 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2262 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2263 __FUNCTION__, sensorPixelMode);
2264 return false;
2265 }
2266 }
2267 // Check whether each stream has max resolution allowed.
2268 bool consistent = true;
2269 for (auto it : streamIdList) {
2270 auto const streamInfoIt = mStreamInfoMap.find(it);
2271 if (streamInfoIt == mStreamInfoMap.end()) {
2272 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2273 return false;
2274 }
2275 consistent =
2276 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2277 streamInfoIt->second.sensorPixelModesUsed.end();
2278 if (!consistent) {
2279 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2280 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2281 ALOGE("sensor pixel mode used list: %i", m);
2282 }
2283 break;
2284 }
2285 }
2286
2287 return consistent;
2288}
2289
Igor Murashkine7ee7632013-06-11 18:10:18 -07002290} // namespace android