blob: 2e6eb065d37f634b8d2296d5793bcaeaba158444 [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 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700552 }
553 mRequestIdCounter++;
554
555 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700556 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
557 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800558 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700559 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800560 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700561 mCameraIdStr.c_str(), strerror(-err), err);
562 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800563 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700564 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700565 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700566 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700567 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700568 }
569 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700570 err = mDevice->captureList(metadataRequestList, surfaceMapList,
571 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800572 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700573 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800574 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700575 mCameraIdStr.c_str(), strerror(-err), err);
576 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800577 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700578 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700579 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800580 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700581 }
582
Austin Borger1c1bee02023-06-01 16:51:35 -0700583 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700584 return res;
585}
586
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800587binder::Status CameraDeviceClient::cancelRequest(
588 int requestId,
589 /*out*/
590 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700591 ATRACE_CALL();
592 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
593
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800594 status_t err;
595 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700596
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800597 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700598
599 Mutex::Autolock icl(mBinderSerializationLock);
600
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800601 if (!mDevice.get()) {
602 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
603 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700604
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700605 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700606 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700607 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
608 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
609 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
610 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700611 }
612
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800613 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700614
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800615 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800616 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700617 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700618 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800619 } else {
620 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800621 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700622 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700623 }
624
625 return res;
626}
627
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800628binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700629 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700630 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700631 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800632 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700633}
634
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100635binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700636 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800637 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700638 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700639 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
640 __FUNCTION__, mInputStream.configured ? 1 : 0,
641 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700642
Zhijun He0effd522016-03-04 10:22:27 -0800643 binder::Status res;
644 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
645
Emilian Peevcc0b7952020-01-07 13:54:47 -0800646 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700647 std::string msg = "Invalid offline stream ids";
648 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
649 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800650 }
651
Zhijun He0effd522016-03-04 10:22:27 -0800652 Mutex::Autolock icl(mBinderSerializationLock);
653
654 if (!mDevice.get()) {
655 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
656 }
657
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700658 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000659 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000660 if (!res.isOk()) {
661 return res;
662 }
663
664 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
665 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700666 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
667 mCameraIdStr.c_str());
668 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
669 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000670 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700671 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
672 mCameraIdStr.c_str(), strerror(-err), err);
673 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
674 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000675 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800676 offlineStreamIds->clear();
677 mDevice->getOfflineStreamIds(offlineStreamIds);
678
Emilian Peev2f5d6012022-01-19 16:16:50 -0800679 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000680 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
681 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800682 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700683 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
684 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
685 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
686 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000687 break;
688 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800689
690 // Composite streams can only support offline mode in case all individual internal
691 // streams are also supported.
692 std::vector<int> internalStreams;
693 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800694 offlineStreamIds->erase(
695 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800696 [&internalStreams] (int streamId) {
697 auto it = std::find(internalStreams.begin(), internalStreams.end(),
698 streamId);
699 if (it != internalStreams.end()) {
700 internalStreams.erase(it);
701 return true;
702 }
703
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800704 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800705 if (internalStreams.empty()) {
706 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
707 }
708 }
709
710 for (const auto& offlineStreamId : *offlineStreamIds) {
711 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000712 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700713
714 nsecs_t configureEnd = systemTime();
715 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700716 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700717 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000718 }
719
720 return res;
721}
722
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800723binder::Status CameraDeviceClient::isSessionConfigurationSupported(
724 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800725
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800726 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800727 binder::Status res;
728 status_t ret = OK;
729 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
730
731 Mutex::Autolock icl(mBinderSerializationLock);
732
733 if (!mDevice.get()) {
734 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
735 }
736
737 auto operatingMode = sessionConfiguration.getOperatingMode();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700738 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000739 mCameraIdStr);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800740 if (!res.isOk()) {
741 return res;
742 }
743
744 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700745 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
746 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
747 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800748 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700749
Emilian Peev35ae8262018-11-08 13:11:32 +0000750 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700751 camera3::metadataGetter getMetadata = [this](const std::string &id,
752 bool /*overrideForPerfClass*/) {
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700753 return mDevice->infoPhysical(id);};
Austin Borger1c1bee02023-06-01 16:51:35 -0700754 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700755 sessionConfiguration, mOverrideForPerfClass, getMetadata, status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000756 switch (ret) {
757 case OK:
758 // Expected, do nothing.
759 break;
760 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700761 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000762 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700763 mCameraIdStr.c_str());
764 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
765 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000766 }
767
768 break;
769 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700770 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000771 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700772 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000773 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700774 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000775 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800776 }
777
778 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700779}
780
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800781binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700782 ATRACE_CALL();
783 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
784
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800785 binder::Status res;
786 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700787
788 Mutex::Autolock icl(mBinderSerializationLock);
789
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800790 if (!mDevice.get()) {
791 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
792 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700793
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700794 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700795 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700796 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000797 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700798
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700799 if (mInputStream.configured && mInputStream.id == streamId) {
800 isInput = true;
801 } else {
802 // Guard against trying to delete non-created streams
803 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700804 if (streamId == mStreamMap.valueAt(i).streamId()) {
805 surfaces.push_back(mStreamMap.keyAt(i));
806 }
807 }
808
809 // See if this stream is one of the deferred streams.
810 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
811 if (streamId == mDeferredStreams[i]) {
812 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700813 break;
814 }
815 }
816
Emilian Peev2f5d6012022-01-19 16:16:50 -0800817 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000818 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
819 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
820 compositeIndex = i;
821 break;
822 }
823 }
824
Shuzhen Wang0129d522016-10-30 22:43:41 -0700825 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700826 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
827 " stream created yet", mCameraIdStr.c_str(), streamId);
828 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
829 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700830 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700831 }
832
833 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800834 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700835
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800836 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700837 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
838 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
839 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
840 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800841 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700842 if (isInput) {
843 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700844 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700845 for (auto& surface : surfaces) {
846 mStreamMap.removeItem(surface);
847 }
848
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800849 mConfiguredOutputs.removeItem(streamId);
850
Shuzhen Wang0129d522016-10-30 22:43:41 -0700851 if (dIndex != NAME_NOT_FOUND) {
852 mDeferredStreams.removeItemsAt(dIndex);
853 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000854
855 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800856 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000857 status_t ret;
858 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
859 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700860 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
861 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
862 err, streamId);
863 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
864 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000865 }
866 mCompositeStreamMap.removeItemsAt(compositeIndex);
867 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800868 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
869 auto &streamSet = mapIt.second;
870 if (streamSet.find(streamId) != streamSet.end()) {
871 streamSet.erase(streamId);
872 break;
873 }
874 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700875 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700876 }
877
878 return res;
879}
880
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800881binder::Status CameraDeviceClient::createStream(
882 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
883 /*out*/
884 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700885 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700886
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800887 binder::Status res;
888 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700889
890 Mutex::Autolock icl(mBinderSerializationLock);
891
Shuzhen Wang0129d522016-10-30 22:43:41 -0700892 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
893 outputConfiguration.getGraphicBufferProducers();
894 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800895 bool deferredConsumer = outputConfiguration.isDeferred();
896 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700897 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800898 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800899 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800900 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800901 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800902 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800903 int mirrorMode = outputConfiguration.getMirrorMode();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700904 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000905 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700906
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700907 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Emilian Peev35ae8262018-11-08 13:11:32 +0000908 outputConfiguration.getSurfaceType());
909 if (!res.isOk()) {
910 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700911 }
Zhijun He5d677d12016-05-29 16:52:39 -0700912
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800913 if (!mDevice.get()) {
914 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
915 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700916 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800917 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000918 if (!res.isOk()) {
919 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800920 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000921
Shuzhen Wang0129d522016-10-30 22:43:41 -0700922 std::vector<sp<Surface>> surfaces;
923 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700924 status_t err;
925
926 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700927 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800928 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700929 }
930
Shuzhen Wang758c2152017-01-10 18:26:18 -0800931 OutputStreamInfo streamInfo;
932 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800933 const std::vector<int32_t> &sensorPixelModesUsed =
934 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700935 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700936 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700937 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800938 ssize_t index = mStreamMap.indexOfKey(binder);
939 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700940 std::string msg = std::string("Camera ") + mCameraIdStr
941 + ": Surface already has a stream created for it (ID "
942 + std::to_string(index) + ")";
943 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
944 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700945 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700946
Shuzhen Wang758c2152017-01-10 18:26:18 -0800947 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700948 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800949 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800950 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700951 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800952
953 if (!res.isOk())
954 return res;
955
956 if (!isStreamInfoValid) {
957 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700958 }
959
Shuzhen Wang758c2152017-01-10 18:26:18 -0800960 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang0129d522016-10-30 22:43:41 -0700961 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -0800962 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700963
964 // If mOverrideForPerfClass is true, do not fail createStream() for small
965 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
966 // closest possible supported size.
967
Zhijun He125684a2015-12-26 15:07:30 -0800968 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100969 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800970 bool isDepthCompositeStream =
971 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0]);
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800972 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(surfaces[0]);
Emilian Peev434248e2022-10-06 14:58:54 -0700973 bool isJpegRCompositeStream =
Emilian Peeve579d8b2023-02-28 14:16:08 -0800974 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0]) &&
Emilian Peev15230142023-04-27 20:22:54 +0000975 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800976 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800977 sp<CompositeStream> compositeStream;
978 if (isDepthCompositeStream) {
979 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800980 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800981 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -0700982 } else {
983 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800984 }
985
Emilian Peev538c90e2018-12-17 18:03:19 +0000986 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
987 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -0700988 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800989 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -0700990 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000991 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
992 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +0000993 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800994 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000995 mCompositeStreamMap.add(IInterface::asBinder(surfaces[0]->getIGraphicBufferProducer()),
996 compositeStream);
997 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800998 } else {
999 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
1000 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001001 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001002 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -08001003 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -08001004 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001005 streamInfo.timestampBase, streamInfo.mirrorMode, streamInfo.colorSpace,
1006 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001007 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001008
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001009 if (err != OK) {
1010 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001011 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001012 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001013 streamInfo.dataSpace, strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001014 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001015 int i = 0;
1016 for (auto& binder : binders) {
1017 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1018 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001019 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1020 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001021 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001022
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001023 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001024 mStreamInfoMap[streamId] = streamInfo;
1025
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001026 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001027 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001028 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001029 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001030
Zhijun He5d677d12016-05-29 16:52:39 -07001031 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001032 res = setStreamTransformLocked(streamId, streamInfo.mirrorMode);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001033
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001034 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001035 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001036 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001037 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001038 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001039 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001040 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001041 }
1042
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001043 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001044 }
1045
1046 return res;
1047}
1048
Zhijun He5d677d12016-05-29 16:52:39 -07001049binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1050 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001051 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001052 /*out*/
1053 int* newStreamId) {
1054 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001055 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001056 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001057 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001058 status_t err;
1059 binder::Status res;
1060
1061 if (!mDevice.get()) {
1062 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1063 }
1064
1065 // Infer the surface info for deferred surface stream creation.
1066 width = outputConfiguration.getWidth();
1067 height = outputConfiguration.getHeight();
1068 surfaceType = outputConfiguration.getSurfaceType();
1069 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1070 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001071 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001072 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1073 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1074 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1075 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1076 }
1077 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001078 std::vector<sp<Surface>> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001079 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001080 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1081 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001082 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1083 // Here, we override sensor pixel modes
1084 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1085 const std::vector<int32_t> &sensorPixelModesUsed =
1086 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001087 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001088 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001089 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001090 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1091 "sensor pixel modes used not valid for deferred stream");
1092 }
1093
Shuzhen Wang0129d522016-10-30 22:43:41 -07001094 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1095 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001096 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001097 &streamId, physicalCameraId,
1098 overriddenSensorPixelModesUsed,
1099 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001100 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001101 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001102 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001103 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001104 outputConfiguration.getMirrorMode(),
1105 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001106
1107 if (err != OK) {
1108 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001109 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001110 mCameraIdStr.c_str(), width, height, format, dataSpace, strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001111 } else {
1112 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1113 // a separate list to track. Once the deferred surface is set, this id will be
1114 // relocated to mStreamMap.
1115 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001116 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001117 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001118 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001119 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001120 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001121 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001122 outputConfiguration.getMirrorMode(),
1123 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001124
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001125 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001126 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001127 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001128
1129 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001130 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001131
1132 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001133 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001134 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001135 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001136 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001137 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001138 }
Zhijun He5d677d12016-05-29 16:52:39 -07001139 }
1140 return res;
1141}
1142
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001143binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001144 int32_t transform = 0;
1145 status_t err;
1146 binder::Status res;
1147
1148 if (!mDevice.get()) {
1149 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1150 }
1151
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001152 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001153 if (err != OK) {
1154 // Error logged by getRotationTransformLocked.
1155 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1156 "Unable to calculate rotation transform for new stream");
1157 }
1158
1159 err = mDevice->setStreamTransform(streamId, transform);
1160 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001161 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001162 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001163 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1164 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001165 }
1166
1167 return res;
1168}
Ruben Brunkbba75572014-11-20 17:29:50 -08001169
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001170binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001171 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001172 /*out*/
1173 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001174
1175 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001176 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1177 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001178
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001179 binder::Status res;
1180 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001181
1182 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001183
1184 if (!mDevice.get()) {
1185 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1186 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001187
1188 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001189 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1190 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1191 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1192 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001193 }
1194
1195 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001196 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001197 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001198 mInputStream.configured = true;
1199 mInputStream.width = width;
1200 mInputStream.height = height;
1201 mInputStream.format = format;
1202 mInputStream.id = streamId;
1203
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001204 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001205 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001206
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001207 *newStreamId = streamId;
1208 } else {
1209 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001210 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001211 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001212 }
1213
1214 return res;
1215}
1216
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001217binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001218
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001219 binder::Status res;
1220 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1221
1222 if (inputSurface == NULL) {
1223 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001224 }
1225
1226 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001227 if (!mDevice.get()) {
1228 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1229 }
1230 sp<IGraphicBufferProducer> producer;
1231 status_t err = mDevice->getInputBufferProducer(&producer);
1232 if (err != OK) {
1233 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001234 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001235 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001236 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001237 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001238 inputSurface->graphicBufferProducer = producer;
1239 }
1240 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001241}
1242
Emilian Peev40ead602017-09-26 15:46:36 +01001243binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1244 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1245 ATRACE_CALL();
1246
1247 binder::Status res;
1248 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1249
1250 Mutex::Autolock icl(mBinderSerializationLock);
1251
1252 if (!mDevice.get()) {
1253 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1254 }
1255
1256 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1257 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001258 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001259
Emilian Peev40ead602017-09-26 15:46:36 +01001260 auto producerCount = bufferProducers.size();
1261 if (producerCount == 0) {
1262 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1263 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1264 "bufferProducers must not be empty");
1265 }
1266
1267 // The first output is the one associated with the output configuration.
1268 // It should always be present, valid and the corresponding stream id should match.
1269 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1270 ssize_t index = mStreamMap.indexOfKey(binder);
1271 if (index == NAME_NOT_FOUND) {
1272 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1273 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1274 "OutputConfiguration is invalid");
1275 }
1276 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1277 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1278 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1279 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1280 "Stream id is invalid");
1281 }
1282
1283 std::vector<size_t> removedSurfaceIds;
1284 std::vector<sp<IBinder>> removedOutputs;
1285 std::vector<sp<Surface>> newOutputs;
1286 std::vector<OutputStreamInfo> streamInfos;
1287 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1288 for (auto &it : bufferProducers) {
1289 newOutputsMap.add(IInterface::asBinder(it), it);
1290 }
1291
1292 for (size_t i = 0; i < mStreamMap.size(); i++) {
1293 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1294 if (idx == NAME_NOT_FOUND) {
1295 if (mStreamMap[i].streamId() == streamId) {
1296 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1297 removedOutputs.push_back(mStreamMap.keyAt(i));
1298 }
1299 } else {
1300 if (mStreamMap[i].streamId() != streamId) {
1301 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1302 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1303 "Target Surface is invalid");
1304 }
1305 newOutputsMap.removeItemsAt(idx);
1306 }
1307 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001308 const std::vector<int32_t> &sensorPixelModesUsed =
1309 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001310 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001311 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001312 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001313 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001314 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001315
Emilian Peev40ead602017-09-26 15:46:36 +01001316 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1317 OutputStreamInfo outInfo;
1318 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001319 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001320 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001321 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001322 streamUseCase, timestampBase, mirrorMode, colorSpace);
Emilian Peev40ead602017-09-26 15:46:36 +01001323 if (!res.isOk())
1324 return res;
1325
Emilian Peev40ead602017-09-26 15:46:36 +01001326 streamInfos.push_back(outInfo);
1327 newOutputs.push_back(surface);
1328 }
1329
1330 //Trivial case no changes required
1331 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1332 return binder::Status::ok();
1333 }
1334
1335 KeyedVector<sp<Surface>, size_t> outputMap;
1336 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1337 &outputMap);
1338 if (ret != OK) {
1339 switch (ret) {
1340 case NAME_NOT_FOUND:
1341 case BAD_VALUE:
1342 case -EBUSY:
1343 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1344 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001345 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001346 break;
1347 default:
1348 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1349 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001350 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001351 break;
1352 }
1353 } else {
1354 for (const auto &it : removedOutputs) {
1355 mStreamMap.removeItem(it);
1356 }
1357
1358 for (size_t i = 0; i < outputMap.size(); i++) {
1359 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1360 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1361 }
1362
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001363 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1364
Emilian Peev40ead602017-09-26 15:46:36 +01001365 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001366 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001367 }
1368
1369 return res;
1370}
1371
Igor Murashkine7ee7632013-06-11 18:10:18 -07001372// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001373binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1374 /*out*/
1375 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001376{
1377 ATRACE_CALL();
1378 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1379
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001380 binder::Status res;
1381 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001382
1383 Mutex::Autolock icl(mBinderSerializationLock);
1384
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001385 if (!mDevice.get()) {
1386 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1387 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001388
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001389 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001390 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
1391 if (!(res = mapRequestTemplate(templateId, &tempId)).isOk()) return res;
1392
1393 CameraMetadata metadata;
1394 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001395 request != NULL) {
1396
1397 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001398 } else if (err == BAD_VALUE) {
1399 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001400 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001401 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001402
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001403 } else {
1404 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001405 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001406 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001407 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001408 return res;
1409}
1410
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001411binder::Status CameraDeviceClient::getCameraInfo(
1412 /*out*/
1413 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001414{
1415 ATRACE_CALL();
1416 ALOGV("%s", __FUNCTION__);
1417
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001418 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001419
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001420 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001421
1422 Mutex::Autolock icl(mBinderSerializationLock);
1423
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001424 if (!mDevice.get()) {
1425 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1426 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001427
Igor Murashkin099b4572013-07-12 17:52:16 -07001428 if (info != NULL) {
1429 *info = mDevice->info(); // static camera metadata
1430 // TODO: merge with device-specific camera metadata
1431 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001432
1433 return res;
1434}
1435
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001436binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001437{
1438 ATRACE_CALL();
1439 ALOGV("%s", __FUNCTION__);
1440
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001441 binder::Status res;
1442 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001443
1444 Mutex::Autolock icl(mBinderSerializationLock);
1445
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001446 if (!mDevice.get()) {
1447 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1448 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001449
1450 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001451 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001452 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001453 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001454 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001455 mCameraIdStr.c_str());
1456 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1457 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001458 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001459 status_t err = mDevice->waitUntilDrained();
1460 if (err != OK) {
1461 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001462 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001463 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001464 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001465 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001466 return res;
1467}
1468
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001469binder::Status CameraDeviceClient::flush(
1470 /*out*/
1471 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001472 ATRACE_CALL();
1473 ALOGV("%s", __FUNCTION__);
1474
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001475 binder::Status res;
1476 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001477
1478 Mutex::Autolock icl(mBinderSerializationLock);
1479
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001480 if (!mDevice.get()) {
1481 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1482 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001483
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001484 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001485 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001486 status_t err = mDevice->flush(lastFrameNumber);
1487 if (err != OK) {
1488 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001489 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1490 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001491 }
1492 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001493}
1494
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001495binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001496 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001497 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001498
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001499 binder::Status res;
1500 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001501
1502 Mutex::Autolock icl(mBinderSerializationLock);
1503
1504 // Guard against trying to prepare non-created streams
1505 ssize_t index = NAME_NOT_FOUND;
1506 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001507 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001508 index = i;
1509 break;
1510 }
1511 }
1512
1513 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001514 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1515 "with that ID exists", mCameraIdStr.c_str(), streamId);
1516 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1517 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001518 }
1519
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001520 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1521 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001522 status_t err = mDevice->prepare(streamId);
1523 if (err == BAD_VALUE) {
1524 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001525 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001526 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001527 } else if (err != OK) {
1528 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001529 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001530 strerror(-err), err);
1531 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001532 return res;
1533}
1534
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001535binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001536 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001537 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001538
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001539 binder::Status res;
1540 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001541
1542 Mutex::Autolock icl(mBinderSerializationLock);
1543
1544 // Guard against trying to prepare non-created streams
1545 ssize_t index = NAME_NOT_FOUND;
1546 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001547 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001548 index = i;
1549 break;
1550 }
1551 }
1552
1553 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001554 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1555 "with that ID exists", mCameraIdStr.c_str(), streamId);
1556 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1557 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001558 }
1559
1560 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001561 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1562 mCameraIdStr.c_str(), maxCount);
1563 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1564 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001565 }
1566
1567 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1568 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001569 status_t err = mDevice->prepare(maxCount, streamId);
1570 if (err == BAD_VALUE) {
1571 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001572 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001573 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001574 } else if (err != OK) {
1575 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001576 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001577 strerror(-err), err);
1578 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001579
1580 return res;
1581}
1582
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001583binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001584 ATRACE_CALL();
1585 ALOGV("%s", __FUNCTION__);
1586
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001587 binder::Status res;
1588 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001589
1590 Mutex::Autolock icl(mBinderSerializationLock);
1591
1592 // Guard against trying to prepare non-created streams
1593 ssize_t index = NAME_NOT_FOUND;
1594 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001595 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001596 index = i;
1597 break;
1598 }
1599 }
1600
1601 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001602 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1603 "with that ID exists", mCameraIdStr.c_str(), streamId);
1604 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1605 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001606 }
1607
1608 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1609 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001610 status_t err = mDevice->tearDown(streamId);
1611 if (err == BAD_VALUE) {
1612 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001613 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001614 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001615 } else if (err != OK) {
1616 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001617 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001618 strerror(-err), err);
1619 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001620
1621 return res;
1622}
1623
Shuzhen Wang758c2152017-01-10 18:26:18 -08001624binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001625 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1626 ATRACE_CALL();
1627
1628 binder::Status res;
1629 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1630
1631 Mutex::Autolock icl(mBinderSerializationLock);
1632
Shuzhen Wang0129d522016-10-30 22:43:41 -07001633 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1634 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001635 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001636
Shuzhen Wang0129d522016-10-30 22:43:41 -07001637 if (bufferProducers.size() == 0) {
1638 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001639 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1640 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001641
Shuzhen Wang758c2152017-01-10 18:26:18 -08001642 // streamId should be in mStreamMap if this stream already has a surface attached
1643 // to it. Otherwise, it should be in mDeferredStreams.
1644 bool streamIdConfigured = false;
1645 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1646 for (size_t i = 0; i < mStreamMap.size(); i++) {
1647 if (mStreamMap.valueAt(i).streamId() == streamId) {
1648 streamIdConfigured = true;
1649 break;
1650 }
Zhijun He5d677d12016-05-29 16:52:39 -07001651 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001652 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1653 if (streamId == mDeferredStreams[i]) {
1654 deferredStreamIndex = i;
1655 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001656 }
1657
Shuzhen Wang758c2152017-01-10 18:26:18 -08001658 }
1659 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001660 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1661 "(ID %d)", mCameraIdStr.c_str(), streamId);
1662 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1663 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001664 }
1665
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001666 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001667 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1668 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1669 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1670 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001671 }
1672
Zhijun He5d677d12016-05-29 16:52:39 -07001673 if (!mDevice.get()) {
1674 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1675 }
1676
Shuzhen Wang758c2152017-01-10 18:26:18 -08001677 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001678 const std::vector<int32_t> &sensorPixelModesUsed =
1679 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001680 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001681 int32_t colorSpace = outputConfiguration.getColorSpace();
1682 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001683 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001684 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001685 for (auto& bufferProducer : bufferProducers) {
1686 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001687 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1688 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001689 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001690 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001691 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001692 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001693
1694 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001695 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001696 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001697 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001698 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001699
1700 if (!res.isOk())
1701 return res;
1702
1703 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001704 }
1705
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001706 // Gracefully handle case where finalizeOutputConfigurations is called
1707 // without any new surface.
1708 if (consumerSurfaces.size() == 0) {
1709 mStreamInfoMap[streamId].finalized = true;
1710 return res;
1711 }
1712
Zhijun He5d677d12016-05-29 16:52:39 -07001713 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001714 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001715 std::vector<int> consumerSurfaceIds;
1716 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001717 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001718 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1719 sp<IBinder> binder = IInterface::asBinder(
1720 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001721 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001722 binder.get(), streamId, consumerSurfaceIds[i]);
1723 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1724 }
1725 if (deferredStreamIndex != NAME_NOT_FOUND) {
1726 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001727 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001728 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001729 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001730 } else if (err == NO_INIT) {
1731 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001732 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001733 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001734 } else {
1735 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001736 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001737 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001738 }
1739
1740 return res;
1741}
1742
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001743binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001744 ATRACE_CALL();
1745 binder::Status res;
1746 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1747
1748 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001749 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1750 mCameraIdStr.c_str(), mode);
1751 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1752 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001753 }
1754
1755 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001756 BasicClient::setAudioRestriction(mode);
1757 return binder::Status::ok();
1758}
1759
1760binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1761 ATRACE_CALL();
1762 binder::Status res;
1763 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1764 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001765 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001766 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001767 }
1768 return binder::Status::ok();
1769}
1770
Ravneetaeb20dc2022-03-30 05:33:03 +00001771status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1772 return mDevice->setCameraServiceWatchdog(enabled);
1773}
1774
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001775status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal) {
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001776 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1777
1778 return mDevice->setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001779 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop), fromHal);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001780}
1781
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001782status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1783 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1784
1785 return mDevice->setAutoframingAutoBehavior(
1786 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1787}
1788
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001789bool CameraDeviceClient::supportsCameraMute() {
1790 return mDevice->supportsCameraMute();
1791}
1792
1793status_t CameraDeviceClient::setCameraMute(bool enabled) {
1794 return mDevice->setCameraMute(enabled);
1795}
1796
Shuzhen Wang16610a62022-12-15 22:38:07 -08001797void CameraDeviceClient::setStreamUseCaseOverrides(
1798 const std::vector<int64_t>& useCaseOverrides) {
1799 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1800}
1801
1802void CameraDeviceClient::clearStreamUseCaseOverrides() {
1803 mDevice->clearStreamUseCaseOverrides();
1804}
1805
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001806bool CameraDeviceClient::supportsZoomOverride() {
1807 return mDevice->supportsZoomOverride();
1808}
1809
1810status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1811 return mDevice->setZoomOverride(zoomOverride);
1812}
1813
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001814binder::Status CameraDeviceClient::switchToOffline(
1815 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001816 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001817 /*out*/
1818 sp<hardware::camera2::ICameraOfflineSession>* session) {
1819 ATRACE_CALL();
1820
1821 binder::Status res;
1822 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1823
1824 Mutex::Autolock icl(mBinderSerializationLock);
1825
1826 if (!mDevice.get()) {
1827 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1828 }
1829
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001830 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001831 std::string msg = "Offline surfaces must not be empty";
1832 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1833 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001834 }
1835
1836 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001837 std::string msg = "Invalid offline session";
1838 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1839 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001840 }
1841
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001842 std::vector<int32_t> offlineStreamIds;
1843 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001844 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001845 for (const auto& streamId : offlineOutputIds) {
1846 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001847 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001848 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001849 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001850 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1851 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001852 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001853
1854 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001855 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001856 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001857 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1858 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001859 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001860
Emilian Peev2f5d6012022-01-19 16:16:50 -08001861 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001862 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001863 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001864 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001865 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001866 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001867 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001868 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001869 if (isCompositeStream) {
1870 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1871 if (compositeIdx == NAME_NOT_FOUND) {
1872 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1873 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1874 "Unknown composite stream");
1875 }
1876
1877 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1878 &offlineStreamIds);
1879 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1880 mCompositeStreamMap.valueAt(compositeIdx));
1881 break;
1882 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001883 }
1884
Emilian Peev4697b642019-11-19 17:11:14 -08001885 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001886 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001887 }
1888 }
1889
1890 sp<CameraOfflineSessionBase> offlineSession;
1891 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1892 if (ret != OK) {
1893 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1894 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001895 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001896 }
1897
Emilian Peevcc0b7952020-01-07 13:54:47 -08001898 sp<CameraOfflineSessionClient> offlineClient;
1899 if (offlineSession.get() != nullptr) {
1900 offlineClient = new CameraOfflineSessionClient(sCameraService,
1901 offlineSession, offlineCompositeStreamMap, cameraCb, mClientPackageName,
Emilian Peev8b64f282021-03-25 16:49:57 -07001902 mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation, mClientPid, mClientUid,
1903 mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001904 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1905 }
1906
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001907 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001908 // A successful offline session switch must reset the current camera client
1909 // and release any resources occupied by previously configured streams.
1910 mStreamMap.clear();
1911 mConfiguredOutputs.clear();
1912 mDeferredStreams.clear();
1913 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001914 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001915 mCompositeStreamMap.clear();
1916 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001917 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001918 // In case we failed to register the offline client, ensure that it still initialized
1919 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001920 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001921
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001922 switch(ret) {
1923 case BAD_VALUE:
1924 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1925 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1926 case TIMED_OUT:
1927 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1928 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1929 default:
1930 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1931 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1932 strerror(-ret), ret);
1933 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001934 }
1935
1936 *session = offlineClient;
1937
1938 return binder::Status::ok();
1939}
1940
Igor Murashkine7ee7632013-06-11 18:10:18 -07001941status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001942 return BasicClient::dump(fd, args);
1943}
1944
1945status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001946 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001947 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001948 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001949 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001950 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001951
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001952 dprintf(fd, " State:\n");
1953 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001954 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001955 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001956 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001957 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001958 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001959 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001960 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001961 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001962 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001963 mStreamMap.valueAt(i).streamId(),
1964 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001965 }
Zhijun He5d677d12016-05-29 16:52:39 -07001966 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001967 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001968 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001969 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001970 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001971 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001972 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001973 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001974 // TODO: print dynamic/request section from most recent requests
1975 mFrameProcessor->dump(fd, args);
1976
1977 return dumpDevice(fd, args);
1978}
1979
Austin Borger1c1bee02023-06-01 16:51:35 -07001980status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07001981 sp<CameraDeviceBase> device = mDevice;
1982 if (!device) {
1983 dprintf(out, " Device is detached.");
1984 return OK;
1985 }
1986 device->startWatchingTags(tags);
1987 return OK;
1988}
1989
1990status_t CameraDeviceClient::stopWatchingTags(int out) {
1991 sp<CameraDeviceBase> device = mDevice;
1992 if (!device) {
1993 dprintf(out, " Device is detached.");
1994 return OK;
1995 }
1996 device->stopWatchingTags();
1997 return OK;
1998}
1999
2000status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
2001 sp<CameraDeviceBase> device = mDevice;
2002 if (!device) {
2003 return OK;
2004 }
2005 device->dumpWatchedEventsToVector(out);
2006 return OK;
2007}
2008
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002009void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07002010 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002011 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002012 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002013
Emilian Peev538c90e2018-12-17 18:03:19 +00002014 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002015 {
2016 // Access to the composite stream map must be synchronized
2017 Mutex::Autolock l(mCompositeLock);
2018 // Composites can have multiple internal streams. Error notifications coming from such
2019 // internal streams may need to remain within camera service.
2020 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2021 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2022 resultExtras);
2023 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002024 }
2025
2026 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002027 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002028 }
2029}
2030
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002031void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2032 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2033
2034 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002035 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002036 }
2037
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002038 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002039 mStreamingRequestId = REQUEST_ID_NONE;
2040}
2041
Shuzhen Wang316781a2020-08-18 18:11:01 -07002042void CameraDeviceClient::notifyIdle(
2043 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2044 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002045 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002046 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002047
2048 if (remoteCb != 0) {
2049 remoteCb->onDeviceIdle();
2050 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002051
2052 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2053 {
2054 Mutex::Autolock l(mCompositeLock);
2055 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2056 hardware::CameraStreamStats compositeStats;
2057 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2058 if (compositeStats.mWidth > 0) {
2059 fullStreamStats.push_back(compositeStats);
2060 }
2061 }
2062 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002063 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -07002064 fullStreamStats, mUserTag, mVideoStabilizationMode, mUsedUltraWide);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002065}
2066
Jianing Weicb0652e2014-03-12 18:29:36 -07002067void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002068 nsecs_t timestamp) {
2069 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002070 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002071 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002072 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002073 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002074 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002075
Emilian Peev2f5d6012022-01-19 16:16:50 -08002076 // Access to the composite stream map must be synchronized
2077 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002078 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2079 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2080 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002081}
2082
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002083void CameraDeviceClient::notifyPrepared(int streamId) {
2084 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002085 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002086 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002087 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002088 remoteCb->onPrepared(streamId);
2089 }
2090}
2091
Shuzhen Wang9d066012016-09-30 11:30:20 -07002092void CameraDeviceClient::notifyRequestQueueEmpty() {
2093 // Thread safe. Don't bother locking.
2094 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2095 if (remoteCb != 0) {
2096 remoteCb->onRequestQueueEmpty();
2097 }
2098}
2099
Igor Murashkine7ee7632013-06-11 18:10:18 -07002100void CameraDeviceClient::detachDevice() {
2101 if (mDevice == 0) return;
2102
Shuzhen Wang316781a2020-08-18 18:11:01 -07002103 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002104 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002105
Emilian Peev7ee731f2022-02-08 14:55:52 -08002106 if (mFrameProcessor.get() != nullptr) {
2107 mFrameProcessor->removeListener(
2108 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2109 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2110 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002111 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002112 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002113 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002114 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002115
2116 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2117 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002118 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002119 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002120 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2121 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2122 }
2123
Igor Murashkine7ee7632013-06-11 18:10:18 -07002124 if ((code = mDevice->waitUntilDrained()) != OK) {
2125 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2126 code);
2127 }
2128 }
2129
Emilian Peev2f5d6012022-01-19 16:16:50 -08002130 {
2131 Mutex::Autolock l(mCompositeLock);
2132 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2133 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2134 if (ret != OK) {
2135 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2136 strerror(-ret), ret);
2137 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002138 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002139 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002140 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002141
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002142 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002143 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002144
2145 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002146 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002147}
2148
2149/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002150void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002151 ATRACE_CALL();
2152 ALOGV("%s", __FUNCTION__);
2153
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002154 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002155 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002156 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002157 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2158 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002159 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002160
Emilian Peev2f5d6012022-01-19 16:16:50 -08002161 // Access to the composite stream map must be synchronized
2162 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002163 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2164 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2165 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002166}
2167
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002168binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002169 if (mDisconnected) {
2170 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2171 "The camera device has been disconnected");
2172 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002173 status_t res = checkPid(checkLocation);
2174 return (res == OK) ? binder::Status::ok() :
2175 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2176 "Attempt to use camera from a different process than original client");
2177}
2178
Igor Murashkine7ee7632013-06-11 18:10:18 -07002179// TODO: move to Camera2ClientBase
2180bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2181
Jayant Chowdhary12361932018-08-27 14:46:13 -07002182 const int pid = CameraThreadState::getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002183 const int selfPid = getpid();
2184 camera_metadata_entry_t entry;
2185
2186 /**
2187 * Mixin default important security values
2188 * - android.led.transmit = defaulted ON
2189 */
2190 CameraMetadata staticInfo = mDevice->info();
2191 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2192 for(size_t i = 0; i < entry.count; ++i) {
2193 uint8_t led = entry.data.u8[i];
2194
2195 switch(led) {
2196 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2197 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2198 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2199 metadata.update(ANDROID_LED_TRANSMIT,
2200 &transmitDefault, 1);
2201 }
2202 break;
2203 }
2204 }
2205 }
2206
2207 // We can do anything!
2208 if (pid == selfPid) {
2209 return true;
2210 }
2211
2212 /**
2213 * Permission check special fields in the request
2214 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2215 */
2216 entry = metadata.find(ANDROID_LED_TRANSMIT);
2217 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2218 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002219 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002220 if (!checkCallingPermission(permissionString)) {
Jayant Chowdhary12361932018-08-27 14:46:13 -07002221 const int uid = CameraThreadState::getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002222 ALOGE("Permission Denial: "
2223 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2224 return false;
2225 }
2226 }
2227
2228 return true;
2229}
2230
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002231status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2232 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002233 ALOGV("%s: begin", __FUNCTION__);
2234
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002235 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002236 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002237}
2238
Emilian Peevf4816702020-04-03 15:44:51 -07002239binder::Status CameraDeviceClient::mapRequestTemplate(int templateId,
2240 camera_request_template_t* tempId /*out*/) {
2241 binder::Status ret = binder::Status::ok();
2242
2243 if (tempId == nullptr) {
2244 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -07002245 "Camera %s: Invalid template argument", mCameraIdStr.c_str());
Emilian Peevf4816702020-04-03 15:44:51 -07002246 return ret;
2247 }
2248 switch(templateId) {
2249 case ICameraDeviceUser::TEMPLATE_PREVIEW:
2250 *tempId = camera_request_template_t::CAMERA_TEMPLATE_PREVIEW;
2251 break;
2252 case ICameraDeviceUser::TEMPLATE_RECORD:
2253 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_RECORD;
2254 break;
2255 case ICameraDeviceUser::TEMPLATE_STILL_CAPTURE:
2256 *tempId = camera_request_template_t::CAMERA_TEMPLATE_STILL_CAPTURE;
2257 break;
2258 case ICameraDeviceUser::TEMPLATE_VIDEO_SNAPSHOT:
2259 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_SNAPSHOT;
2260 break;
2261 case ICameraDeviceUser::TEMPLATE_ZERO_SHUTTER_LAG:
2262 *tempId = camera_request_template_t::CAMERA_TEMPLATE_ZERO_SHUTTER_LAG;
2263 break;
2264 case ICameraDeviceUser::TEMPLATE_MANUAL:
2265 *tempId = camera_request_template_t::CAMERA_TEMPLATE_MANUAL;
2266 break;
2267 default:
2268 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
2269 "Camera %s: Template ID %d is invalid or not supported",
Austin Borger1c1bee02023-06-01 16:51:35 -07002270 mCameraIdStr.c_str(), templateId);
Emilian Peevf4816702020-04-03 15:44:51 -07002271 return ret;
2272 }
2273
2274 return ret;
2275}
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002276
Austin Borger1c1bee02023-06-01 16:51:35 -07002277const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002278 if (mDevice->getId() == cameraId) {
2279 return mDevice->info();
2280 }
2281 return mDevice->infoPhysical(cameraId);
2282}
2283
Austin Borger1c1bee02023-06-01 16:51:35 -07002284bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002285 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002286 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002287}
2288
2289bool CameraDeviceClient::isSensorPixelModeConsistent(
2290 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2291 // First we get the sensorPixelMode from the settings metadata.
2292 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2293 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2294 if (sensorPixelModeEntry.count != 0) {
2295 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2296 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2297 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2298 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2299 __FUNCTION__, sensorPixelMode);
2300 return false;
2301 }
2302 }
2303 // Check whether each stream has max resolution allowed.
2304 bool consistent = true;
2305 for (auto it : streamIdList) {
2306 auto const streamInfoIt = mStreamInfoMap.find(it);
2307 if (streamInfoIt == mStreamInfoMap.end()) {
2308 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2309 return false;
2310 }
2311 consistent =
2312 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2313 streamInfoIt->second.sensorPixelModesUsed.end();
2314 if (!consistent) {
2315 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2316 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2317 ALOGE("sensor pixel mode used list: %i", m);
2318 }
2319 break;
2320 }
2321 }
2322
2323 return consistent;
2324}
2325
Igor Murashkine7ee7632013-06-11 18:10:18 -07002326} // namespace android