blob: 28f7054d8b853d458cf315bf65eaf47522934a2c [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Igor Murashkine7ee7632013-06-11 18:10:18 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "CameraDeviceClient"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
Jianing Weicb0652e2014-03-12 18:29:36 -070019//#define LOG_NDEBUG 0
Igor Murashkine7ee7632013-06-11 18:10:18 -070020
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -070021#include <com_android_internal_camera_flags.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070022#include <cutils/properties.h>
Jayant Chowdhary12361932018-08-27 14:46:13 -070023#include <utils/CameraThreadState.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070024#include <utils/Log.h>
Colin Crossb8a9dbb2020-08-27 04:12:26 +000025#include <utils/SessionConfigurationUtils.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070026#include <utils/Trace.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070027#include <gui/Surface.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070028#include <camera/camera2/CaptureRequest.h>
Ruben Brunk5698d442014-06-18 10:39:40 -070029#include <camera/CameraUtils.h>
Austin Borger1c1bee02023-06-01 16:51:35 -070030#include <camera/StringUtils.h>
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070031
32#include "common/CameraDeviceBase.h"
Emilian Peev35ae8262018-11-08 13:11:32 +000033#include "device3/Camera3Device.h"
34#include "device3/Camera3OutputStream.h"
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070035#include "api2/CameraDeviceClient.h"
36
Emilian Peev00420d22018-02-05 21:33:13 +000037#include <camera_metadata_hidden.h>
38
Emilian Peev538c90e2018-12-17 18:03:19 +000039#include "DepthCompositeStream.h"
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080040#include "HeicCompositeStream.h"
Emilian Peev434248e2022-10-06 14:58:54 -070041#include "JpegRCompositeStream.h"
Emilian Peev538c90e2018-12-17 18:03:19 +000042
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080043// Convenience methods for constructing binder::Status objects for error returns
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070044
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080045#define STATUS_ERROR(errorCode, errorString) \
46 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070047 fmt::sprintf("%s:%d: %s", __FUNCTION__, __LINE__, errorString).c_str())
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080048
49#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
50 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger1c1bee02023-06-01 16:51:35 -070051 fmt::sprintf("%s:%d: " errorString, __FUNCTION__, __LINE__, \
52 __VA_ARGS__).c_str())
Igor Murashkine7ee7632013-06-11 18:10:18 -070053
54namespace android {
55using namespace camera2;
Austin Borgerea931242021-12-13 23:10:41 +000056using namespace camera3;
Emilian Peevf4816702020-04-03 15:44:51 -070057using camera3::camera_stream_rotation_t::CAMERA_STREAM_ROTATION_0;
Igor Murashkine7ee7632013-06-11 18:10:18 -070058
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -070059namespace flags = com::android::internal::camera::flags;
60
Igor Murashkine7ee7632013-06-11 18:10:18 -070061CameraDeviceClientBase::CameraDeviceClientBase(
62 const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080063 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger1c1bee02023-06-01 16:51:35 -070064 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080065 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070066 const std::optional<std::string>& clientFeatureId,
67 const std::string& cameraId,
Jing Mikec7f9b132023-03-12 11:12:04 +080068 [[maybe_unused]] int api1CameraId,
Igor Murashkine7ee7632013-06-11 18:10:18 -070069 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070070 int sensorOrientation,
Igor Murashkine7ee7632013-06-11 18:10:18 -070071 int clientPid,
72 uid_t clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070073 int servicePid,
74 bool overrideToPortrait) :
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080075 BasicClient(cameraService,
Marco Nelissenf8880202014-11-14 07:58:25 -080076 IInterface::asBinder(remoteCallback),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080077 clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080078 systemNativeClient,
Philip P. Moltmann9e648f62019-11-04 12:52:45 -080079 clientFeatureId,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080080 cameraId,
81 cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -070082 sensorOrientation,
Eino-Ville Talvalae992e752014-11-07 16:17:48 -080083 clientPid,
84 clientUid,
Austin Borger18b30a72022-10-27 12:20:29 -070085 servicePid,
86 overrideToPortrait),
Igor Murashkine7ee7632013-06-11 18:10:18 -070087 mRemoteCallback(remoteCallback) {
88}
Igor Murashkine7ee7632013-06-11 18:10:18 -070089
90// Interface used by CameraService
91
92CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080093 const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
Austin Borger74fca042022-05-23 12:41:21 -070094 std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper,
Austin Borger1c1bee02023-06-01 16:51:35 -070095 const std::string& clientPackageName,
Jayant Chowdharyeb0169f2022-01-31 00:00:02 -080096 bool systemNativeClient,
Austin Borger1c1bee02023-06-01 16:51:35 -070097 const std::optional<std::string>& clientFeatureId,
98 const std::string& cameraId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080099 int cameraFacing,
Emilian Peev8b64f282021-03-25 16:49:57 -0700100 int sensorOrientation,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800101 int clientPid,
102 uid_t clientUid,
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700103 int servicePid,
Austin Borger18b30a72022-10-27 12:20:29 -0700104 bool overrideForPerfClass,
malikakash73125c62023-07-21 22:44:34 +0000105 bool overrideToPortrait,
106 const std::string& originalCameraId) :
Austin Borger74fca042022-05-23 12:41:21 -0700107 Camera2ClientBase(cameraService, remoteCallback, cameraServiceProxyWrapper, clientPackageName,
108 systemNativeClient, clientFeatureId, cameraId, /*API1 camera ID*/ -1, cameraFacing,
Austin Borger18b30a72022-10-27 12:20:29 -0700109 sensorOrientation, clientPid, clientUid, servicePid, overrideForPerfClass,
110 overrideToPortrait),
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700111 mInputStream(),
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700112 mStreamingRequestId(REQUEST_ID_NONE),
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700113 mRequestIdCounter(0),
malikakash73125c62023-07-21 22:44:34 +0000114 mOverrideForPerfClass(overrideForPerfClass),
115 mOriginalCameraId(originalCameraId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700116 ATRACE_CALL();
Austin Borger1c1bee02023-06-01 16:51:35 -0700117 ALOGI("CameraDeviceClient %s: Opened", cameraId.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700118}
119
Emilian Peevbd8c5032018-02-14 23:05:40 +0000120status_t CameraDeviceClient::initialize(sp<CameraProviderManager> manager,
Austin Borger1c1bee02023-06-01 16:51:35 -0700121 const std::string& monitorTags) {
Emilian Peevbd8c5032018-02-14 23:05:40 +0000122 return initializeImpl(manager, monitorTags);
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800123}
124
125template<typename TProviderPtr>
Austin Borger1c1bee02023-06-01 16:51:35 -0700126status_t CameraDeviceClient::initializeImpl(TProviderPtr providerPtr,
127 const std::string& monitorTags) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700128 ATRACE_CALL();
129 status_t res;
130
Emilian Peevbd8c5032018-02-14 23:05:40 +0000131 res = Camera2ClientBase::initialize(providerPtr, monitorTags);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700132 if (res != OK) {
133 return res;
134 }
135
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -0700136 mFrameProcessor = new FrameProcessorBase(mDevice);
Austin Borger1c1bee02023-06-01 16:51:35 -0700137 std::string threadName = std::string("CDU-") + mCameraIdStr + "-FrameProc";
138 res = mFrameProcessor->run(threadName.c_str());
Austin Borger7b129542022-06-09 13:23:06 -0700139 if (res != OK) {
140 ALOGE("%s: Unable to start frame processor thread: %s (%d)",
141 __FUNCTION__, strerror(-res), res);
142 return res;
143 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700144
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800145 mFrameProcessor->registerListener(camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
146 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID,
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800147 /*listener*/this,
Zhijun He25a0aef2014-06-25 11:40:02 -0700148 /*sendPartials*/true);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700149
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800150 const CameraMetadata &deviceInfo = mDevice->info();
151 camera_metadata_ro_entry_t physicalKeysEntry = deviceInfo.find(
Emilian Peev00420d22018-02-05 21:33:13 +0000152 ANDROID_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS);
153 if (physicalKeysEntry.count > 0) {
154 mSupportedPhysicalRequestKeys.insert(mSupportedPhysicalRequestKeys.begin(),
155 physicalKeysEntry.data.i32,
156 physicalKeysEntry.data.i32 + physicalKeysEntry.count);
157 }
158
Emilian Peev2295df72021-11-12 18:14:10 -0800159 auto entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
160 mDynamicProfileMap.emplace(
161 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
162 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD);
163 if (entry.count > 0) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800164 const auto it = std::find(entry.data.u8, entry.data.u8 + entry.count,
Emilian Peev2295df72021-11-12 18:14:10 -0800165 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800166 if (it != entry.data.u8 + entry.count) {
Emilian Peev2295df72021-11-12 18:14:10 -0800167 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP);
Emilian Peevc81a7592022-02-14 17:38:18 -0800168 if (entry.count > 0 || ((entry.count % 3) != 0)) {
169 int64_t standardBitmap =
170 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
171 for (size_t i = 0; i < entry.count; i += 3) {
172 if (entry.data.i64[i] !=
Emilian Peev2295df72021-11-12 18:14:10 -0800173 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800174 mDynamicProfileMap.emplace(entry.data.i64[i], entry.data.i64[i+1]);
175 if ((entry.data.i64[i+1] == 0) || (entry.data.i64[i+1] &
Emilian Peev2295df72021-11-12 18:14:10 -0800176 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD)) {
Emilian Peevc81a7592022-02-14 17:38:18 -0800177 standardBitmap |= entry.data.i64[i];
Emilian Peev2295df72021-11-12 18:14:10 -0800178 }
179 } else {
Emilian Peevc81a7592022-02-14 17:38:18 -0800180 ALOGE("%s: Device %s includes unexpected profile entry: 0x%" PRIx64 "!",
181 __FUNCTION__, mCameraIdStr.c_str(), entry.data.i64[i]);
Emilian Peev2295df72021-11-12 18:14:10 -0800182 }
183 }
Emilian Peevef715e22022-05-19 17:44:33 -0700184 mDynamicProfileMap[ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD] =
185 standardBitmap;
Emilian Peev2295df72021-11-12 18:14:10 -0800186 } else {
187 ALOGE("%s: Device %s supports 10-bit output but doesn't include a dynamic range"
188 " profile map!", __FUNCTION__, mCameraIdStr.c_str());
189 }
190 }
191 }
192
Shuzhen Wang03d8cc12018-09-12 14:17:09 -0700193 mProviderManager = providerPtr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800194 // Cache physical camera ids corresponding to this device and also the high
195 // resolution sensors in this device + physical camera ids
Austin Borger1c1bee02023-06-01 16:51:35 -0700196 mProviderManager->isLogicalCamera(mCameraIdStr, &mPhysicalCameraIds);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -0800197 if (supportsUltraHighResolutionCapture(mCameraIdStr)) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700198 mHighResolutionSensors.insert(mCameraIdStr);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800199 }
200 for (auto &physicalId : mPhysicalCameraIds) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700201 if (supportsUltraHighResolutionCapture(physicalId)) {
202 mHighResolutionSensors.insert(physicalId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800203 }
204 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700205 return OK;
206}
207
208CameraDeviceClient::~CameraDeviceClient() {
209}
210
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800211binder::Status CameraDeviceClient::submitRequest(
212 const hardware::camera2::CaptureRequest& request,
213 bool streaming,
214 /*out*/
215 hardware::camera2::utils::SubmitInfo *submitInfo) {
216 std::vector<hardware::camera2::CaptureRequest> requestList = { request };
217 return submitRequestList(requestList, streaming, submitInfo);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700218}
219
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800220binder::Status CameraDeviceClient::insertGbpLocked(const sp<IGraphicBufferProducer>& gbp,
Emilian Peevf873aa52018-01-26 14:58:28 +0000221 SurfaceMap* outSurfaceMap, Vector<int32_t>* outputStreamIds, int32_t *currentStreamId) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000222 int compositeIdx;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800223 int idx = mStreamMap.indexOfKey(IInterface::asBinder(gbp));
224
Emilian Peev2f5d6012022-01-19 16:16:50 -0800225 Mutex::Autolock l(mCompositeLock);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800226 // Trying to submit request with surface that wasn't created
227 if (idx == NAME_NOT_FOUND) {
228 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
229 " we have not called createStream on",
Austin Borger1c1bee02023-06-01 16:51:35 -0700230 __FUNCTION__, mCameraIdStr.c_str());
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800231 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
232 "Request targets Surface that is not part of current capture session");
Emilian Peev538c90e2018-12-17 18:03:19 +0000233 } else if ((compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp)))
234 != NAME_NOT_FOUND) {
235 mCompositeStreamMap.valueAt(compositeIdx)->insertGbp(outSurfaceMap, outputStreamIds,
236 currentStreamId);
237 return binder::Status::ok();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800238 }
239
240 const StreamSurfaceId& streamSurfaceId = mStreamMap.valueAt(idx);
241 if (outSurfaceMap->find(streamSurfaceId.streamId()) == outSurfaceMap->end()) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800242 outputStreamIds->push_back(streamSurfaceId.streamId());
243 }
244 (*outSurfaceMap)[streamSurfaceId.streamId()].push_back(streamSurfaceId.surfaceId());
245
246 ALOGV("%s: Camera %s: Appending output stream %d surface %d to request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700247 __FUNCTION__, mCameraIdStr.c_str(), streamSurfaceId.streamId(),
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800248 streamSurfaceId.surfaceId());
249
Emilian Peevf873aa52018-01-26 14:58:28 +0000250 if (currentStreamId != nullptr) {
251 *currentStreamId = streamSurfaceId.streamId();
252 }
253
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800254 return binder::Status::ok();
255}
256
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800257static std::list<int> getIntersection(const std::unordered_set<int> &streamIdsForThisCamera,
258 const Vector<int> &streamIdsForThisRequest) {
259 std::list<int> intersection;
260 for (auto &streamId : streamIdsForThisRequest) {
261 if (streamIdsForThisCamera.find(streamId) != streamIdsForThisCamera.end()) {
262 intersection.emplace_back(streamId);
263 }
264 }
265 return intersection;
266}
267
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800268binder::Status CameraDeviceClient::submitRequestList(
269 const std::vector<hardware::camera2::CaptureRequest>& requests,
270 bool streaming,
271 /*out*/
272 hardware::camera2::utils::SubmitInfo *submitInfo) {
Jianing Wei90e59c92014-03-12 18:29:36 -0700273 ATRACE_CALL();
Mark Salyzyn50468412014-06-18 16:33:43 -0700274 ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700275
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800276 binder::Status res = binder::Status::ok();
277 status_t err;
278 if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
279 return res;
280 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700281
282 Mutex::Autolock icl(mBinderSerializationLock);
283
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800284 if (!mDevice.get()) {
285 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
286 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700287
288 if (requests.empty()) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800289 ALOGE("%s: Camera %s: Sent null request. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700290 __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800291 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
Jianing Wei90e59c92014-03-12 18:29:36 -0700292 }
293
Emilian Peevaebbe412018-01-15 13:53:24 +0000294 List<const CameraDeviceBase::PhysicalCameraSettingsList> metadataRequestList;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700295 std::list<const SurfaceMap> surfaceMapList;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800296 submitInfo->mRequestId = mRequestIdCounter;
Jianing Wei90e59c92014-03-12 18:29:36 -0700297 uint32_t loopCounter = 0;
298
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800299 for (auto&& request: requests) {
300 if (request.mIsReprocess) {
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700301 if (!mInputStream.configured) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800302 ALOGE("%s: Camera %s: no input stream is configured.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700303 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800304 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800305 "No input configured for camera %s but request is for reprocessing",
Austin Borger1c1bee02023-06-01 16:51:35 -0700306 mCameraIdStr.c_str());
Chien-Yu Chened0412e2015-04-27 15:04:22 -0700307 } else if (streaming) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800308 ALOGE("%s: Camera %s: streaming reprocess requests not supported.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700309 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800310 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
311 "Repeating reprocess requests not supported");
Emilian Peevaebbe412018-01-15 13:53:24 +0000312 } else if (request.mPhysicalCameraSettings.size() > 1) {
313 ALOGE("%s: Camera %s: reprocess requests not supported for "
314 "multiple physical cameras.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700315 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000316 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
317 "Reprocess requests not supported for multiple cameras");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700318 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700319 }
320
Emilian Peevaebbe412018-01-15 13:53:24 +0000321 if (request.mPhysicalCameraSettings.empty()) {
322 ALOGE("%s: Camera %s: request doesn't contain any settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700323 mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800324 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Emilian Peevaebbe412018-01-15 13:53:24 +0000325 "Request doesn't contain any settings");
326 }
327
328 //The first capture settings should always match the logical camera id
Austin Borger1c1bee02023-06-01 16:51:35 -0700329 const std::string &logicalId = request.mPhysicalCameraSettings.begin()->id;
malikakash73125c62023-07-21 22:44:34 +0000330 if (mDevice->getId() != logicalId && mOriginalCameraId != logicalId) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000331 ALOGE("%s: Camera %s: Invalid camera request settings.", __FUNCTION__,
Austin Borger1c1bee02023-06-01 16:51:35 -0700332 mCameraIdStr.c_str());
Emilian Peevaebbe412018-01-15 13:53:24 +0000333 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
334 "Invalid camera request settings");
335 }
336
Emilian Peevaebbe412018-01-15 13:53:24 +0000337 if (request.mSurfaceList.isEmpty() && request.mStreamIdxList.size() == 0) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800338 ALOGE("%s: Camera %s: Requests must have at least one surface target. "
Austin Borger1c1bee02023-06-01 16:51:35 -0700339 "Rejecting request.", __FUNCTION__, mCameraIdStr.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800340 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
341 "Request has no output targets");
Jianing Wei90e59c92014-03-12 18:29:36 -0700342 }
343
Jianing Wei90e59c92014-03-12 18:29:36 -0700344 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700345 * Write in the output stream IDs and map from stream ID to surface ID
346 * which we calculate from the capture request's list of surface target
Jianing Wei90e59c92014-03-12 18:29:36 -0700347 */
Shuzhen Wang0129d522016-10-30 22:43:41 -0700348 SurfaceMap surfaceMap;
Jianing Wei90e59c92014-03-12 18:29:36 -0700349 Vector<int32_t> outputStreamIds;
Emilian Peevf873aa52018-01-26 14:58:28 +0000350 std::vector<std::string> requestedPhysicalIds;
Emilian Peevc81a7592022-02-14 17:38:18 -0800351 int64_t dynamicProfileBitmap = 0;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800352 if (request.mSurfaceList.size() > 0) {
Chih-Hung Hsieh3ef324d2018-12-11 11:48:12 -0800353 for (const sp<Surface>& surface : request.mSurfaceList) {
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800354 if (surface == 0) continue;
Jianing Wei90e59c92014-03-12 18:29:36 -0700355
Emilian Peevf873aa52018-01-26 14:58:28 +0000356 int32_t streamId;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800357 sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
Emilian Peevf873aa52018-01-26 14:58:28 +0000358 res = insertGbpLocked(gbp, &surfaceMap, &outputStreamIds, &streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800359 if (!res.isOk()) {
360 return res;
361 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000362
363 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
364 if (index >= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700365 const std::string &requestedPhysicalId =
366 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
367 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800368 dynamicProfileBitmap |=
369 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
Emilian Peevf873aa52018-01-26 14:58:28 +0000370 } else {
371 ALOGW("%s: Output stream Id not found among configured outputs!", __FUNCTION__);
372 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700373 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800374 } else {
375 for (size_t i = 0; i < request.mStreamIdxList.size(); i++) {
376 int streamId = request.mStreamIdxList.itemAt(i);
377 int surfaceIdx = request.mSurfaceIdxList.itemAt(i);
Jianing Wei90e59c92014-03-12 18:29:36 -0700378
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800379 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
380 if (index < 0) {
381 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
382 " we have not called createStream on: stream %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700383 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800384 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
385 "Request targets Surface that is not part of current capture session");
386 }
387
388 const auto& gbps = mConfiguredOutputs.valueAt(index).getGraphicBufferProducers();
389 if ((size_t)surfaceIdx >= gbps.size()) {
390 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
391 " we have not called createStream on: stream %d, surfaceIdx %d",
Austin Borger1c1bee02023-06-01 16:51:35 -0700392 __FUNCTION__, mCameraIdStr.c_str(), streamId, surfaceIdx);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800393 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
394 "Request targets Surface has invalid surface index");
395 }
396
Emilian Peevf873aa52018-01-26 14:58:28 +0000397 res = insertGbpLocked(gbps[surfaceIdx], &surfaceMap, &outputStreamIds, nullptr);
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800398 if (!res.isOk()) {
399 return res;
400 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000401
Austin Borger1c1bee02023-06-01 16:51:35 -0700402 const std::string &requestedPhysicalId =
403 mConfiguredOutputs.valueAt(index).getPhysicalCameraId();
404 requestedPhysicalIds.push_back(requestedPhysicalId);
Emilian Peev2295df72021-11-12 18:14:10 -0800405 dynamicProfileBitmap |=
406 mConfiguredOutputs.valueAt(index).getDynamicRangeProfile();
407 }
408 }
409
410 if (dynamicProfileBitmap !=
411 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
412 for (int i = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
413 i < ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX; i <<= 1) {
414 if ((dynamicProfileBitmap & i) == 0) {
415 continue;
416 }
417
418 const auto& it = mDynamicProfileMap.find(i);
419 if (it != mDynamicProfileMap.end()) {
420 if ((it->second == 0) ||
421 ((it->second & dynamicProfileBitmap) == dynamicProfileBitmap)) {
422 continue;
423 } else {
424 ALOGE("%s: Camera %s: Tried to submit a request with a surfaces that"
425 " reference an unsupported dynamic range profile combination"
Austin Borger1c1bee02023-06-01 16:51:35 -0700426 " 0x%" PRIx64 "!", __FUNCTION__, mCameraIdStr.c_str(),
Emilian Peev2295df72021-11-12 18:14:10 -0800427 dynamicProfileBitmap);
428 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
429 "Request targets an unsupported dynamic range profile"
430 " combination");
431 }
432 } else {
433 ALOGE("%s: Camera %s: Tried to submit a request with a surface that"
434 " references unsupported dynamic range profile 0x%x!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700435 __FUNCTION__, mCameraIdStr.c_str(), i);
Emilian Peev2295df72021-11-12 18:14:10 -0800436 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
437 "Request targets 10-bit Surface with unsupported dynamic range"
438 " profile");
439 }
Shuzhen Wang0129d522016-10-30 22:43:41 -0700440 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700441 }
442
Emilian Peevf873aa52018-01-26 14:58:28 +0000443 CameraDeviceBase::PhysicalCameraSettingsList physicalSettingsList;
444 for (const auto& it : request.mPhysicalCameraSettings) {
malikakash73125c62023-07-21 22:44:34 +0000445 const std::string resolvedId = (mOriginalCameraId == it.id) ? mDevice->getId() : it.id;
Emilian Peev00420d22018-02-05 21:33:13 +0000446 if (it.settings.isEmpty()) {
447 ALOGE("%s: Camera %s: Sent empty metadata packet. Rejecting request.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700448 __FUNCTION__, mCameraIdStr.c_str());
Emilian Peev00420d22018-02-05 21:33:13 +0000449 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
450 "Request settings are empty");
451 }
452
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800453 // Check whether the physical / logical stream has settings
454 // consistent with the sensor pixel mode(s) it was configured with.
455 // mCameraIdToStreamSet will only have ids that are high resolution
malikakash73125c62023-07-21 22:44:34 +0000456 const auto streamIdSetIt = mHighResolutionCameraIdToStreamIdSet.find(resolvedId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800457 if (streamIdSetIt != mHighResolutionCameraIdToStreamIdSet.end()) {
458 std::list<int> streamIdsUsedInRequest = getIntersection(streamIdSetIt->second,
459 outputStreamIds);
460 if (!request.mIsReprocess &&
461 !isSensorPixelModeConsistent(streamIdsUsedInRequest, it.settings)) {
462 ALOGE("%s: Camera %s: Request settings CONTROL_SENSOR_PIXEL_MODE not "
463 "consistent with configured streams. Rejecting request.",
malikakash73125c62023-07-21 22:44:34 +0000464 __FUNCTION__, resolvedId.c_str());
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800465 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
466 "Request settings CONTROL_SENSOR_PIXEL_MODE are not consistent with "
467 "streams configured");
468 }
469 }
470
malikakash73125c62023-07-21 22:44:34 +0000471 const std::string &physicalId = resolvedId;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700472 bool hasTestPatternModePhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
473 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_MODE) !=
474 mSupportedPhysicalRequestKeys.end();
475 bool hasTestPatternDataPhysicalKey = std::find(mSupportedPhysicalRequestKeys.begin(),
476 mSupportedPhysicalRequestKeys.end(), ANDROID_SENSOR_TEST_PATTERN_DATA) !=
477 mSupportedPhysicalRequestKeys.end();
Emilian Peevf873aa52018-01-26 14:58:28 +0000478 if (physicalId != mDevice->getId()) {
479 auto found = std::find(requestedPhysicalIds.begin(), requestedPhysicalIds.end(),
malikakash73125c62023-07-21 22:44:34 +0000480 resolvedId);
Emilian Peevf873aa52018-01-26 14:58:28 +0000481 if (found == requestedPhysicalIds.end()) {
482 ALOGE("%s: Camera %s: Physical camera id: %s not part of attached outputs.",
Austin Borger1c1bee02023-06-01 16:51:35 -0700483 __FUNCTION__, mCameraIdStr.c_str(), physicalId.c_str());
Emilian Peevf873aa52018-01-26 14:58:28 +0000484 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
485 "Invalid physical camera id");
486 }
Emilian Peev00420d22018-02-05 21:33:13 +0000487
488 if (!mSupportedPhysicalRequestKeys.empty()) {
489 // Filter out any unsupported physical request keys.
490 CameraMetadata filteredParams(mSupportedPhysicalRequestKeys.size());
491 camera_metadata_t *meta = const_cast<camera_metadata_t *>(
492 filteredParams.getAndLock());
493 set_camera_metadata_vendor_id(meta, mDevice->getVendorTagId());
494 filteredParams.unlock(meta);
495
496 for (const auto& keyIt : mSupportedPhysicalRequestKeys) {
497 camera_metadata_ro_entry entry = it.settings.find(keyIt);
498 if (entry.count > 0) {
499 filteredParams.update(entry);
500 }
501 }
502
malikakash73125c62023-07-21 22:44:34 +0000503 physicalSettingsList.push_back({resolvedId, filteredParams,
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700504 hasTestPatternModePhysicalKey, hasTestPatternDataPhysicalKey});
Emilian Peev00420d22018-02-05 21:33:13 +0000505 }
506 } else {
malikakash73125c62023-07-21 22:44:34 +0000507 physicalSettingsList.push_back({resolvedId, it.settings});
Emilian Peevf873aa52018-01-26 14:58:28 +0000508 }
Emilian Peevf873aa52018-01-26 14:58:28 +0000509 }
510
511 if (!enforceRequestPermissions(physicalSettingsList.begin()->metadata)) {
512 // Callee logs
513 return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
514 "Caller does not have permission to change restricted controls");
515 }
516
Emilian Peevaebbe412018-01-15 13:53:24 +0000517 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS,
518 &outputStreamIds[0], outputStreamIds.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700519
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800520 if (request.mIsReprocess) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000521 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_INPUT_STREAMS,
522 &mInputStream.id, 1);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700523 }
524
Emilian Peevaebbe412018-01-15 13:53:24 +0000525 physicalSettingsList.begin()->metadata.update(ANDROID_REQUEST_ID,
526 &(submitInfo->mRequestId), /*size*/1);
Jianing Wei90e59c92014-03-12 18:29:36 -0700527 loopCounter++; // loopCounter starts from 1
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800528 ALOGV("%s: Camera %s: Creating request with ID %d (%d of %zu)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700529 __FUNCTION__, mCameraIdStr.c_str(), submitInfo->mRequestId,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800530 loopCounter, requests.size());
Jianing Wei90e59c92014-03-12 18:29:36 -0700531
Emilian Peevaebbe412018-01-15 13:53:24 +0000532 metadataRequestList.push_back(physicalSettingsList);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700533 surfaceMapList.push_back(surfaceMap);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800534
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700535 // Save certain CaptureRequest settings
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800536 if (!request.mUserTag.empty()) {
537 mUserTag = request.mUserTag;
538 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700539 camera_metadata_entry entry =
540 physicalSettingsList.begin()->metadata.find(
541 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE);
542 if (entry.count == 1) {
543 mVideoStabilizationMode = entry.data.u8[0];
544 }
Eino-Ville Talvala6f1a9c12023-09-14 17:26:28 -0700545 if (flags::log_ultrawide_usage()) {
546 entry = physicalSettingsList.begin()->metadata.find(
547 ANDROID_CONTROL_ZOOM_RATIO);
548 if (entry.count == 1 && entry.data.f[0] < 1.0f ) {
549 mUsedUltraWide = true;
550 }
551 }
Shuzhen Wang6e08d202023-10-24 20:27:14 +0000552 if (!mUsedSettingsOverrideZoom && flags::log_zoom_override_usage()) {
553 entry = physicalSettingsList.begin()->metadata.find(
554 ANDROID_CONTROL_SETTINGS_OVERRIDE);
555 if (entry.count == 1 && entry.data.i32[0] ==
556 ANDROID_CONTROL_SETTINGS_OVERRIDE_ZOOM) {
557 mUsedSettingsOverrideZoom = true;
558 }
559 }
Jianing Wei90e59c92014-03-12 18:29:36 -0700560 }
561 mRequestIdCounter++;
562
563 if (streaming) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700564 err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,
565 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800566 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700567 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800568 "Camera %s: Got error %s (%d) after trying to set streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700569 mCameraIdStr.c_str(), strerror(-err), err);
570 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800571 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700572 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700573 } else {
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700574 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700575 mStreamingRequestId = submitInfo->mRequestId;
Jianing Wei90e59c92014-03-12 18:29:36 -0700576 }
577 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700578 err = mDevice->captureList(metadataRequestList, surfaceMapList,
579 &(submitInfo->mLastFrameNumber));
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800580 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700581 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800582 "Camera %s: Got error %s (%d) after trying to submit capture request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700583 mCameraIdStr.c_str(), strerror(-err), err);
584 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800585 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -0700586 msg.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700587 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800588 ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
Jianing Wei90e59c92014-03-12 18:29:36 -0700589 }
590
Austin Borger1c1bee02023-06-01 16:51:35 -0700591 ALOGV("%s: Camera %s: End of function", __FUNCTION__, mCameraIdStr.c_str());
Jianing Wei90e59c92014-03-12 18:29:36 -0700592 return res;
593}
594
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800595binder::Status CameraDeviceClient::cancelRequest(
596 int requestId,
597 /*out*/
598 int64_t* lastFrameNumber) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700599 ATRACE_CALL();
600 ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
601
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800602 status_t err;
603 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700604
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800605 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700606
607 Mutex::Autolock icl(mBinderSerializationLock);
608
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800609 if (!mDevice.get()) {
610 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
611 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700612
Shuzhen Wangc9ca6782016-04-26 13:40:31 -0700613 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700614 if (mStreamingRequestId != requestId) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700615 std::string msg = fmt::sprintf("Camera %s: Canceling request ID %d doesn't match "
616 "current request ID %d", mCameraIdStr.c_str(), requestId, mStreamingRequestId);
617 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
618 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700619 }
620
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800621 err = mDevice->clearStreamingRequest(lastFrameNumber);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700622
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800623 if (err == OK) {
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800624 ALOGV("%s: Camera %s: Successfully cleared streaming request",
Austin Borger1c1bee02023-06-01 16:51:35 -0700625 __FUNCTION__, mCameraIdStr.c_str());
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700626 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800627 } else {
628 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800629 "Camera %s: Error clearing streaming request: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -0700630 mCameraIdStr.c_str(), strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700631 }
632
633 return res;
634}
635
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800636binder::Status CameraDeviceClient::beginConfigure() {
Ruben Brunkb2119af2014-05-09 19:57:56 -0700637 // TODO: Implement this.
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700638 ATRACE_CALL();
Zhijun He1fa89992015-06-01 15:44:31 -0700639 ALOGV("%s: Not implemented yet.", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800640 return binder::Status::ok();
Ruben Brunkb2119af2014-05-09 19:57:56 -0700641}
642
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100643binder::Status CameraDeviceClient::endConfigure(int operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700644 const hardware::camera2::impl::CameraMetadataNative& sessionParams, int64_t startTimeMs,
Emilian Peevcc0b7952020-01-07 13:54:47 -0800645 std::vector<int>* offlineStreamIds /*out*/) {
Eino-Ville Talvala6aeb8882017-08-07 17:40:49 -0700646 ATRACE_CALL();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700647 ALOGV("%s: ending configure (%d input stream, %zu output surfaces)",
648 __FUNCTION__, mInputStream.configured ? 1 : 0,
649 mStreamMap.size());
Igor Murashkine2d167e2014-08-19 16:19:59 -0700650
Zhijun He0effd522016-03-04 10:22:27 -0800651 binder::Status res;
652 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
653
Emilian Peevcc0b7952020-01-07 13:54:47 -0800654 if (offlineStreamIds == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700655 std::string msg = "Invalid offline stream ids";
656 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
657 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800658 }
659
Zhijun He0effd522016-03-04 10:22:27 -0800660 Mutex::Autolock icl(mBinderSerializationLock);
661
662 if (!mDevice.get()) {
663 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
664 }
665
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700666 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000667 mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000668 if (!res.isOk()) {
669 return res;
670 }
671
672 status_t err = mDevice->configureStreams(sessionParams, operatingMode);
673 if (err == BAD_VALUE) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700674 std::string msg = fmt::sprintf("Camera %s: Unsupported set of inputs/outputs provided",
675 mCameraIdStr.c_str());
676 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
677 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000678 } else if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700679 std::string msg = fmt::sprintf("Camera %s: Error configuring streams: %s (%d)",
680 mCameraIdStr.c_str(), strerror(-err), err);
681 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
682 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000683 } else {
Emilian Peevcc0b7952020-01-07 13:54:47 -0800684 offlineStreamIds->clear();
685 mDevice->getOfflineStreamIds(offlineStreamIds);
686
Emilian Peev2f5d6012022-01-19 16:16:50 -0800687 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000688 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
689 err = mCompositeStreamMap.valueAt(i)->configureStream();
Emilian Peevcc0b7952020-01-07 13:54:47 -0800690 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700691 std::string msg = fmt::sprintf("Camera %s: Error configuring composite "
692 "streams: %s (%d)", mCameraIdStr.c_str(), strerror(-err), err);
693 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
694 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000695 break;
696 }
Emilian Peevcc0b7952020-01-07 13:54:47 -0800697
698 // Composite streams can only support offline mode in case all individual internal
699 // streams are also supported.
700 std::vector<int> internalStreams;
701 mCompositeStreamMap.valueAt(i)->insertCompositeStreamIds(&internalStreams);
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800702 offlineStreamIds->erase(
703 std::remove_if(offlineStreamIds->begin(), offlineStreamIds->end(),
Emilian Peevcc0b7952020-01-07 13:54:47 -0800704 [&internalStreams] (int streamId) {
705 auto it = std::find(internalStreams.begin(), internalStreams.end(),
706 streamId);
707 if (it != internalStreams.end()) {
708 internalStreams.erase(it);
709 return true;
710 }
711
Emilian Peevfaa4bde2020-01-23 12:19:37 -0800712 return false;}), offlineStreamIds->end());
Emilian Peevcc0b7952020-01-07 13:54:47 -0800713 if (internalStreams.empty()) {
714 offlineStreamIds->push_back(mCompositeStreamMap.valueAt(i)->getStreamId());
715 }
716 }
717
718 for (const auto& offlineStreamId : *offlineStreamIds) {
719 mStreamInfoMap[offlineStreamId].supportsOffline = true;
Emilian Peev538c90e2018-12-17 18:03:19 +0000720 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700721
722 nsecs_t configureEnd = systemTime();
723 int32_t configureDurationMs = ns2ms(configureEnd) - startTimeMs;
Austin Borger74fca042022-05-23 12:41:21 -0700724 mCameraServiceProxyWrapper->logStreamConfigured(mCameraIdStr, operatingMode,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700725 false /*internalReconfig*/, configureDurationMs);
Emilian Peev35ae8262018-11-08 13:11:32 +0000726 }
727
728 return res;
729}
730
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800731binder::Status CameraDeviceClient::isSessionConfigurationSupported(
732 const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800733
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800734 ATRACE_CALL();
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800735 binder::Status res;
736 status_t ret = OK;
737 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
738
739 Mutex::Autolock icl(mBinderSerializationLock);
740
741 if (!mDevice.get()) {
742 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
743 }
744
745 auto operatingMode = sessionConfiguration.getOperatingMode();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700746 res = SessionConfigurationUtils::checkOperatingMode(operatingMode, mDevice->info(),
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000747 mCameraIdStr);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800748 if (!res.isOk()) {
749 return res;
750 }
751
752 if (status == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700753 std::string msg = fmt::sprintf( "Camera %s: Invalid status!", mCameraIdStr.c_str());
754 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
755 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800756 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700757
Emilian Peev35ae8262018-11-08 13:11:32 +0000758 *status = false;
Austin Borger1c1bee02023-06-01 16:51:35 -0700759 camera3::metadataGetter getMetadata = [this](const std::string &id,
760 bool /*overrideForPerfClass*/) {
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700761 return mDevice->infoPhysical(id);};
Austin Borger1c1bee02023-06-01 16:51:35 -0700762 ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.c_str(),
Shuzhen Wanga79a64d2022-04-24 19:56:30 -0700763 sessionConfiguration, mOverrideForPerfClass, getMetadata, status);
Emilian Peev35ae8262018-11-08 13:11:32 +0000764 switch (ret) {
765 case OK:
766 // Expected, do nothing.
767 break;
768 case INVALID_OPERATION: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700769 std::string msg = fmt::sprintf(
Emilian Peev35ae8262018-11-08 13:11:32 +0000770 "Camera %s: Session configuration query not supported!",
Austin Borger1c1bee02023-06-01 16:51:35 -0700771 mCameraIdStr.c_str());
772 ALOGD("%s: %s", __FUNCTION__, msg.c_str());
773 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000774 }
775
776 break;
777 default: {
Austin Borger1c1bee02023-06-01 16:51:35 -0700778 std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", mCameraIdStr.c_str(),
Emilian Peev35ae8262018-11-08 13:11:32 +0000779 strerror(-ret), ret);
Austin Borger1c1bee02023-06-01 16:51:35 -0700780 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000781 res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -0700782 msg.c_str());
Emilian Peev35ae8262018-11-08 13:11:32 +0000783 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800784 }
785
786 return res;
Ruben Brunkb2119af2014-05-09 19:57:56 -0700787}
788
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800789binder::Status CameraDeviceClient::deleteStream(int streamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700790 ATRACE_CALL();
791 ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
792
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800793 binder::Status res;
794 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700795
796 Mutex::Autolock icl(mBinderSerializationLock);
797
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800798 if (!mDevice.get()) {
799 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
800 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700801
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700802 bool isInput = false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700803 std::vector<sp<IBinder>> surfaces;
Zhijun He5d677d12016-05-29 16:52:39 -0700804 ssize_t dIndex = NAME_NOT_FOUND;
Emilian Peev538c90e2018-12-17 18:03:19 +0000805 ssize_t compositeIndex = NAME_NOT_FOUND;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700806
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700807 if (mInputStream.configured && mInputStream.id == streamId) {
808 isInput = true;
809 } else {
810 // Guard against trying to delete non-created streams
811 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700812 if (streamId == mStreamMap.valueAt(i).streamId()) {
813 surfaces.push_back(mStreamMap.keyAt(i));
814 }
815 }
816
817 // See if this stream is one of the deferred streams.
818 for (size_t i = 0; i < mDeferredStreams.size(); ++i) {
819 if (streamId == mDeferredStreams[i]) {
820 dIndex = i;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700821 break;
822 }
823 }
824
Emilian Peev2f5d6012022-01-19 16:16:50 -0800825 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000826 for (size_t i = 0; i < mCompositeStreamMap.size(); ++i) {
827 if (streamId == mCompositeStreamMap.valueAt(i)->getStreamId()) {
828 compositeIndex = i;
829 break;
830 }
831 }
832
Shuzhen Wang0129d522016-10-30 22:43:41 -0700833 if (surfaces.empty() && dIndex == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700834 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no such"
835 " stream created yet", mCameraIdStr.c_str(), streamId);
836 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
837 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700838 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700839 }
840
841 // Also returns BAD_VALUE if stream ID was not valid
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800842 status_t err = mDevice->deleteStream(streamId);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700843
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800844 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700845 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when deleting stream "
846 "%d", mCameraIdStr.c_str(), strerror(-err), err, streamId);
847 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
848 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800849 } else {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700850 if (isInput) {
851 mInputStream.configured = false;
Zhijun He5d677d12016-05-29 16:52:39 -0700852 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700853 for (auto& surface : surfaces) {
854 mStreamMap.removeItem(surface);
855 }
856
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800857 mConfiguredOutputs.removeItem(streamId);
858
Shuzhen Wang0129d522016-10-30 22:43:41 -0700859 if (dIndex != NAME_NOT_FOUND) {
860 mDeferredStreams.removeItemsAt(dIndex);
861 }
Emilian Peev538c90e2018-12-17 18:03:19 +0000862
863 if (compositeIndex != NAME_NOT_FOUND) {
Emilian Peev2f5d6012022-01-19 16:16:50 -0800864 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +0000865 status_t ret;
866 if ((ret = mCompositeStreamMap.valueAt(compositeIndex)->deleteStream())
867 != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700868 std::string msg = fmt::sprintf("Camera %s: Unexpected error %s (%d) when "
869 "deleting composite stream %d", mCameraIdStr.c_str(), strerror(-err),
870 err, streamId);
871 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
872 res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Emilian Peev538c90e2018-12-17 18:03:19 +0000873 }
874 mCompositeStreamMap.removeItemsAt(compositeIndex);
875 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800876 for (auto &mapIt: mHighResolutionCameraIdToStreamIdSet) {
877 auto &streamSet = mapIt.second;
878 if (streamSet.find(streamId) != streamSet.end()) {
879 streamSet.erase(streamId);
880 break;
881 }
882 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700883 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700884 }
885
886 return res;
887}
888
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800889binder::Status CameraDeviceClient::createStream(
890 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
891 /*out*/
892 int32_t* newStreamId) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700893 ATRACE_CALL();
Igor Murashkine7ee7632013-06-11 18:10:18 -0700894
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800895 binder::Status res;
896 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700897
898 Mutex::Autolock icl(mBinderSerializationLock);
899
Shuzhen Wang0129d522016-10-30 22:43:41 -0700900 const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
901 outputConfiguration.getGraphicBufferProducers();
902 size_t numBufferProducers = bufferProducers.size();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800903 bool deferredConsumer = outputConfiguration.isDeferred();
904 bool isShared = outputConfiguration.isShared();
Austin Borger1c1bee02023-06-01 16:51:35 -0700905 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang758c2152017-01-10 18:26:18 -0800906 bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800907 bool isMultiResolution = outputConfiguration.isMultiResolution();
Emilian Peevc81a7592022-02-14 17:38:18 -0800908 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800909 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -0800910 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800911 int mirrorMode = outputConfiguration.getMirrorMode();
Austin Borger9e2b27c2022-07-15 11:27:24 -0700912 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000913 bool useReadoutTimestamp = outputConfiguration.useReadoutTimestamp();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700914
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700915 res = SessionConfigurationUtils::checkSurfaceType(numBufferProducers, deferredConsumer,
Emilian Peev35ae8262018-11-08 13:11:32 +0000916 outputConfiguration.getSurfaceType());
917 if (!res.isOk()) {
918 return res;
Yin-Chia Yeh89f14da2014-06-10 16:05:44 -0700919 }
Zhijun He5d677d12016-05-29 16:52:39 -0700920
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800921 if (!mDevice.get()) {
922 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
923 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700924 res = SessionConfigurationUtils::checkPhysicalCameraId(mPhysicalCameraIds,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800925 physicalCameraId, mCameraIdStr);
Emilian Peev35ae8262018-11-08 13:11:32 +0000926 if (!res.isOk()) {
927 return res;
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800928 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000929
Shuzhen Wang0129d522016-10-30 22:43:41 -0700930 std::vector<sp<Surface>> surfaces;
931 std::vector<sp<IBinder>> binders;
Zhijun He5d677d12016-05-29 16:52:39 -0700932 status_t err;
933
934 // Create stream for deferred surface case.
Shuzhen Wang0129d522016-10-30 22:43:41 -0700935 if (deferredConsumerOnly) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800936 return createDeferredSurfaceStreamLocked(outputConfiguration, isShared, newStreamId);
Zhijun He5d677d12016-05-29 16:52:39 -0700937 }
938
Shuzhen Wang758c2152017-01-10 18:26:18 -0800939 OutputStreamInfo streamInfo;
940 bool isStreamInfoValid = false;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800941 const std::vector<int32_t> &sensorPixelModesUsed =
942 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700943 for (auto& bufferProducer : bufferProducers) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700944 // Don't create multiple streams for the same target surface
Shuzhen Wang0129d522016-10-30 22:43:41 -0700945 sp<IBinder> binder = IInterface::asBinder(bufferProducer);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800946 ssize_t index = mStreamMap.indexOfKey(binder);
947 if (index != NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700948 std::string msg = std::string("Camera ") + mCameraIdStr
949 + ": Surface already has a stream created for it (ID "
950 + std::to_string(index) + ")";
951 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
952 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Shuzhen Wang0129d522016-10-30 22:43:41 -0700953 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700954
Shuzhen Wang758c2152017-01-10 18:26:18 -0800955 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700956 res = SessionConfigurationUtils::createSurfaceFromGbp(streamInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800957 isStreamInfoValid, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800958 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700959 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800960
961 if (!res.isOk())
962 return res;
963
964 if (!isStreamInfoValid) {
965 isStreamInfoValid = true;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700966 }
967
Shuzhen Wang758c2152017-01-10 18:26:18 -0800968 binders.push_back(IInterface::asBinder(bufferProducer));
Shuzhen Wang0129d522016-10-30 22:43:41 -0700969 surfaces.push_back(surface);
Ruben Brunkbba75572014-11-20 17:29:50 -0800970 }
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700971
972 // If mOverrideForPerfClass is true, do not fail createStream() for small
973 // JPEG sizes because existing createSurfaceFromGbp() logic will find the
974 // closest possible supported size.
975
Zhijun He125684a2015-12-26 15:07:30 -0800976 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Emilian Peev40ead602017-09-26 15:46:36 +0100977 std::vector<int> surfaceIds;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800978 bool isDepthCompositeStream =
979 camera3::DepthCompositeStream::isDepthCompositeStream(surfaces[0]);
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800980 bool isHeicCompositeStream = camera3::HeicCompositeStream::isHeicCompositeStream(surfaces[0]);
Emilian Peev434248e2022-10-06 14:58:54 -0700981 bool isJpegRCompositeStream =
Emilian Peeve579d8b2023-02-28 14:16:08 -0800982 camera3::JpegRCompositeStream::isJpegRCompositeStream(surfaces[0]) &&
Emilian Peev15230142023-04-27 20:22:54 +0000983 !mDevice->isCompositeJpegRDisabled();
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800984 if (isDepthCompositeStream || isHeicCompositeStream || isJpegRCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800985 sp<CompositeStream> compositeStream;
986 if (isDepthCompositeStream) {
987 compositeStream = new camera3::DepthCompositeStream(mDevice, getRemoteCallback());
Chema Gonzalez67de9c82022-12-21 08:59:30 -0800988 } else if (isHeicCompositeStream) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800989 compositeStream = new camera3::HeicCompositeStream(mDevice, getRemoteCallback());
Emilian Peev434248e2022-10-06 14:58:54 -0700990 } else {
991 compositeStream = new camera3::JpegRCompositeStream(mDevice, getRemoteCallback());
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800992 }
993
Emilian Peev538c90e2018-12-17 18:03:19 +0000994 err = compositeStream->createStream(surfaces, deferredConsumer, streamInfo.width,
995 streamInfo.height, streamInfo.format,
Emilian Peevf4816702020-04-03 15:44:51 -0700996 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800997 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev434248e2022-10-06 14:58:54 -0700998 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000999 streamInfo.colorSpace, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
1000 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001001 if (err == OK) {
Emilian Peev2f5d6012022-01-19 16:16:50 -08001002 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00001003 mCompositeStreamMap.add(IInterface::asBinder(surfaces[0]->getIGraphicBufferProducer()),
1004 compositeStream);
1005 }
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08001006 } else {
1007 err = mDevice->createStream(surfaces, deferredConsumer, streamInfo.width,
1008 streamInfo.height, streamInfo.format, streamInfo.dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001009 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001010 &streamId, physicalCameraId, streamInfo.sensorPixelModesUsed, &surfaceIds,
Emilian Peev2295df72021-11-12 18:14:10 -08001011 outputConfiguration.getSurfaceSetID(), isShared, isMultiResolution,
Shuzhen Wange4208922022-02-01 16:52:48 -08001012 /*consumerUsage*/0, streamInfo.dynamicRangeProfile, streamInfo.streamUseCase,
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001013 streamInfo.timestampBase, streamInfo.mirrorMode, streamInfo.colorSpace,
1014 useReadoutTimestamp);
Emilian Peev538c90e2018-12-17 18:03:19 +00001015 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001016
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001017 if (err != OK) {
1018 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001019 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001020 mCameraIdStr.c_str(), streamInfo.width, streamInfo.height, streamInfo.format,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001021 streamInfo.dataSpace, strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001022 } else {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001023 int i = 0;
1024 for (auto& binder : binders) {
1025 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d",
1026 __FUNCTION__, binder.get(), streamId, i);
Emilian Peev40ead602017-09-26 15:46:36 +01001027 mStreamMap.add(binder, StreamSurfaceId(streamId, surfaceIds[i]));
1028 i++;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001029 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001030
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001031 mConfiguredOutputs.add(streamId, outputConfiguration);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001032 mStreamInfoMap[streamId] = streamInfo;
1033
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001034 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for output surface"
Shuzhen Wang0129d522016-10-30 22:43:41 -07001035 " (%d x %d) with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001036 __FUNCTION__, mCameraIdStr.c_str(), streamId, streamInfo.width,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001037 streamInfo.height, streamInfo.format);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001038
Zhijun He5d677d12016-05-29 16:52:39 -07001039 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001040 res = setStreamTransformLocked(streamId, streamInfo.mirrorMode);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07001041
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001042 // Fill in mHighResolutionCameraIdToStreamIdSet map
Austin Borger1c1bee02023-06-01 16:51:35 -07001043 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001044 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001045 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001046 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001047 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001048 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001049 }
1050
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001051 *newStreamId = streamId;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001052 }
1053
1054 return res;
1055}
1056
Zhijun He5d677d12016-05-29 16:52:39 -07001057binder::Status CameraDeviceClient::createDeferredSurfaceStreamLocked(
1058 const hardware::camera2::params::OutputConfiguration &outputConfiguration,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001059 bool isShared,
Zhijun He5d677d12016-05-29 16:52:39 -07001060 /*out*/
1061 int* newStreamId) {
1062 int width, height, format, surfaceType;
Emilian Peev050f5dc2017-05-18 14:43:56 +01001063 uint64_t consumerUsage;
Zhijun He5d677d12016-05-29 16:52:39 -07001064 android_dataspace dataSpace;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001065 int32_t colorSpace;
Zhijun He5d677d12016-05-29 16:52:39 -07001066 status_t err;
1067 binder::Status res;
1068
1069 if (!mDevice.get()) {
1070 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1071 }
1072
1073 // Infer the surface info for deferred surface stream creation.
1074 width = outputConfiguration.getWidth();
1075 height = outputConfiguration.getHeight();
1076 surfaceType = outputConfiguration.getSurfaceType();
1077 format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
1078 dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
Austin Borger9e2b27c2022-07-15 11:27:24 -07001079 colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Zhijun He5d677d12016-05-29 16:52:39 -07001080 // Hardcode consumer usage flags: SurfaceView--0x900, SurfaceTexture--0x100.
1081 consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
1082 if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
1083 consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
1084 }
1085 int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001086 std::vector<sp<Surface>> noSurface;
Emilian Peev40ead602017-09-26 15:46:36 +01001087 std::vector<int> surfaceIds;
Austin Borger1c1bee02023-06-01 16:51:35 -07001088 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
1089 const std::string &cameraIdUsed =
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001090 physicalCameraId.size() != 0 ? physicalCameraId : mCameraIdStr;
1091 // Here, we override sensor pixel modes
1092 std::unordered_set<int32_t> overriddenSensorPixelModesUsed;
1093 const std::vector<int32_t> &sensorPixelModesUsed =
1094 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001095 if (SessionConfigurationUtils::checkAndOverrideSensorPixelModesUsed(
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001096 sensorPixelModesUsed, format, width, height, getStaticInfo(cameraIdUsed),
Jayant Chowdharya80ad242023-03-17 00:49:47 +00001097 &overriddenSensorPixelModesUsed) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001098 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1099 "sensor pixel modes used not valid for deferred stream");
1100 }
1101
Shuzhen Wang0129d522016-10-30 22:43:41 -07001102 err = mDevice->createStream(noSurface, /*hasDeferredConsumer*/true, width,
1103 height, format, dataSpace,
Emilian Peevf4816702020-04-03 15:44:51 -07001104 static_cast<camera_stream_rotation_t>(outputConfiguration.getRotation()),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001105 &streamId, physicalCameraId,
1106 overriddenSensorPixelModesUsed,
1107 &surfaceIds,
Shuzhen Wangc28189a2017-11-27 23:05:10 -08001108 outputConfiguration.getSurfaceSetID(), isShared,
Emilian Peev2295df72021-11-12 18:14:10 -08001109 outputConfiguration.isMultiResolution(), consumerUsage,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001110 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001111 outputConfiguration.getStreamUseCase(),
Shuzhen Wangbce53db2022-12-03 00:38:20 +00001112 outputConfiguration.getMirrorMode(),
1113 outputConfiguration.useReadoutTimestamp());
Zhijun He5d677d12016-05-29 16:52:39 -07001114
1115 if (err != OK) {
1116 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001117 "Camera %s: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001118 mCameraIdStr.c_str(), width, height, format, dataSpace, strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001119 } else {
1120 // Can not add streamId to mStreamMap here, as the surface is deferred. Add it to
1121 // a separate list to track. Once the deferred surface is set, this id will be
1122 // relocated to mStreamMap.
1123 mDeferredStreams.push_back(streamId);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001124 mStreamInfoMap.emplace(std::piecewise_construct, std::forward_as_tuple(streamId),
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001125 std::forward_as_tuple(width, height, format, dataSpace, consumerUsage,
Emilian Peev2295df72021-11-12 18:14:10 -08001126 overriddenSensorPixelModesUsed,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001127 outputConfiguration.getDynamicRangeProfile(),
Shuzhen Wange4208922022-02-01 16:52:48 -08001128 outputConfiguration.getStreamUseCase(),
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001129 outputConfiguration.getTimestampBase(),
Austin Borger9e2b27c2022-07-15 11:27:24 -07001130 outputConfiguration.getMirrorMode(),
1131 colorSpace));
Shuzhen Wang758c2152017-01-10 18:26:18 -08001132
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001133 ALOGV("%s: Camera %s: Successfully created a new stream ID %d for a deferred surface"
Zhijun He5d677d12016-05-29 16:52:39 -07001134 " (%d x %d) stream with format 0x%x.",
Austin Borger1c1bee02023-06-01 16:51:35 -07001135 __FUNCTION__, mCameraIdStr.c_str(), streamId, width, height, format);
Zhijun He5d677d12016-05-29 16:52:39 -07001136
1137 // Set transform flags to ensure preview to be rotated correctly.
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001138 res = setStreamTransformLocked(streamId, outputConfiguration.getMirrorMode());
Zhijun He5d677d12016-05-29 16:52:39 -07001139
1140 *newStreamId = streamId;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001141 // Fill in mHighResolutionCameraIdToStreamIdSet
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001142 // Only needed for high resolution sensors
Austin Borger1c1bee02023-06-01 16:51:35 -07001143 if (mHighResolutionSensors.find(cameraIdUsed) !=
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001144 mHighResolutionSensors.end()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001145 mHighResolutionCameraIdToStreamIdSet[cameraIdUsed].insert(streamId);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001146 }
Zhijun He5d677d12016-05-29 16:52:39 -07001147 }
1148 return res;
1149}
1150
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001151binder::Status CameraDeviceClient::setStreamTransformLocked(int streamId, int mirrorMode) {
Zhijun He5d677d12016-05-29 16:52:39 -07001152 int32_t transform = 0;
1153 status_t err;
1154 binder::Status res;
1155
1156 if (!mDevice.get()) {
1157 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1158 }
1159
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001160 err = getRotationTransformLocked(mirrorMode, &transform);
Zhijun He5d677d12016-05-29 16:52:39 -07001161 if (err != OK) {
1162 // Error logged by getRotationTransformLocked.
1163 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
1164 "Unable to calculate rotation transform for new stream");
1165 }
1166
1167 err = mDevice->setStreamTransform(streamId, transform);
1168 if (err != OK) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001169 std::string msg = fmt::sprintf("Failed to set stream transform (stream id %d)",
Zhijun He5d677d12016-05-29 16:52:39 -07001170 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001171 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1172 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001173 }
1174
1175 return res;
1176}
Ruben Brunkbba75572014-11-20 17:29:50 -08001177
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001178binder::Status CameraDeviceClient::createInputStream(
Shuzhen Wang83bff122020-11-20 15:51:39 -08001179 int width, int height, int format, bool isMultiResolution,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001180 /*out*/
1181 int32_t* newStreamId) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001182
1183 ATRACE_CALL();
Shuzhen Wang83bff122020-11-20 15:51:39 -08001184 ALOGV("%s (w = %d, h = %d, f = 0x%x, isMultiResolution %d)", __FUNCTION__,
1185 width, height, format, isMultiResolution);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001186
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001187 binder::Status res;
1188 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001189
1190 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001191
1192 if (!mDevice.get()) {
1193 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1194 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001195
1196 if (mInputStream.configured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001197 std::string msg = fmt::sprintf("Camera %s: Already has an input stream "
1198 "configured (ID %d)", mCameraIdStr.c_str(), mInputStream.id);
1199 ALOGE("%s: %s", __FUNCTION__, msg.c_str() );
1200 return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.c_str());
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001201 }
1202
1203 int streamId = -1;
Shuzhen Wang83bff122020-11-20 15:51:39 -08001204 status_t err = mDevice->createInputStream(width, height, format, isMultiResolution, &streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001205 if (err == OK) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001206 mInputStream.configured = true;
1207 mInputStream.width = width;
1208 mInputStream.height = height;
1209 mInputStream.format = format;
1210 mInputStream.id = streamId;
1211
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001212 ALOGV("%s: Camera %s: Successfully created a new input stream ID %d",
Austin Borger1c1bee02023-06-01 16:51:35 -07001213 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001214
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001215 *newStreamId = streamId;
1216 } else {
1217 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001218 "Camera %s: Error creating new input stream: %s (%d)", mCameraIdStr.c_str(),
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001219 strerror(-err), err);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001220 }
1221
1222 return res;
1223}
1224
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001225binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001226
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001227 binder::Status res;
1228 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1229
1230 if (inputSurface == NULL) {
1231 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001232 }
1233
1234 Mutex::Autolock icl(mBinderSerializationLock);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001235 if (!mDevice.get()) {
1236 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1237 }
1238 sp<IGraphicBufferProducer> producer;
1239 status_t err = mDevice->getInputBufferProducer(&producer);
1240 if (err != OK) {
1241 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001242 "Camera %s: Error getting input Surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001243 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001244 } else {
Austin Borger1c1bee02023-06-01 16:51:35 -07001245 inputSurface->name = toString16("CameraInput");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001246 inputSurface->graphicBufferProducer = producer;
1247 }
1248 return res;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001249}
1250
Emilian Peev40ead602017-09-26 15:46:36 +01001251binder::Status CameraDeviceClient::updateOutputConfiguration(int streamId,
1252 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1253 ATRACE_CALL();
1254
1255 binder::Status res;
1256 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1257
1258 Mutex::Autolock icl(mBinderSerializationLock);
1259
1260 if (!mDevice.get()) {
1261 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1262 }
1263
1264 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1265 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001266 const std::string &physicalCameraId = outputConfiguration.getPhysicalCameraId();
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -07001267
Emilian Peev40ead602017-09-26 15:46:36 +01001268 auto producerCount = bufferProducers.size();
1269 if (producerCount == 0) {
1270 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
1271 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1272 "bufferProducers must not be empty");
1273 }
1274
1275 // The first output is the one associated with the output configuration.
1276 // It should always be present, valid and the corresponding stream id should match.
1277 sp<IBinder> binder = IInterface::asBinder(bufferProducers[0]);
1278 ssize_t index = mStreamMap.indexOfKey(binder);
1279 if (index == NAME_NOT_FOUND) {
1280 ALOGE("%s: Outputconfiguration is invalid", __FUNCTION__);
1281 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1282 "OutputConfiguration is invalid");
1283 }
1284 if (mStreamMap.valueFor(binder).streamId() != streamId) {
1285 ALOGE("%s: Stream Id: %d provided doesn't match the id: %d in the stream map",
1286 __FUNCTION__, streamId, mStreamMap.valueFor(binder).streamId());
1287 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1288 "Stream id is invalid");
1289 }
1290
1291 std::vector<size_t> removedSurfaceIds;
1292 std::vector<sp<IBinder>> removedOutputs;
1293 std::vector<sp<Surface>> newOutputs;
1294 std::vector<OutputStreamInfo> streamInfos;
1295 KeyedVector<sp<IBinder>, sp<IGraphicBufferProducer>> newOutputsMap;
1296 for (auto &it : bufferProducers) {
1297 newOutputsMap.add(IInterface::asBinder(it), it);
1298 }
1299
1300 for (size_t i = 0; i < mStreamMap.size(); i++) {
1301 ssize_t idx = newOutputsMap.indexOfKey(mStreamMap.keyAt(i));
1302 if (idx == NAME_NOT_FOUND) {
1303 if (mStreamMap[i].streamId() == streamId) {
1304 removedSurfaceIds.push_back(mStreamMap[i].surfaceId());
1305 removedOutputs.push_back(mStreamMap.keyAt(i));
1306 }
1307 } else {
1308 if (mStreamMap[i].streamId() != streamId) {
1309 ALOGE("%s: Output surface already part of a different stream", __FUNCTION__);
1310 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1311 "Target Surface is invalid");
1312 }
1313 newOutputsMap.removeItemsAt(idx);
1314 }
1315 }
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001316 const std::vector<int32_t> &sensorPixelModesUsed =
1317 outputConfiguration.getSensorPixelModesUsed();
Shuzhen Wang8ed1e872022-03-08 16:34:33 -08001318 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001319 int timestampBase = outputConfiguration.getTimestampBase();
Emilian Peevc81a7592022-02-14 17:38:18 -08001320 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001321 int32_t colorSpace = outputConfiguration.getColorSpace();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001322 int mirrorMode = outputConfiguration.getMirrorMode();
Emilian Peev2295df72021-11-12 18:14:10 -08001323
Emilian Peev40ead602017-09-26 15:46:36 +01001324 for (size_t i = 0; i < newOutputsMap.size(); i++) {
1325 OutputStreamInfo outInfo;
1326 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001327 res = SessionConfigurationUtils::createSurfaceFromGbp(outInfo,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001328 /*isStreamInfoValid*/ false, surface, newOutputsMap.valueAt(i), mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001329 mDevice->infoPhysical(physicalCameraId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001330 streamUseCase, timestampBase, mirrorMode, colorSpace);
Emilian Peev40ead602017-09-26 15:46:36 +01001331 if (!res.isOk())
1332 return res;
1333
Emilian Peev40ead602017-09-26 15:46:36 +01001334 streamInfos.push_back(outInfo);
1335 newOutputs.push_back(surface);
1336 }
1337
1338 //Trivial case no changes required
1339 if (removedSurfaceIds.empty() && newOutputs.empty()) {
1340 return binder::Status::ok();
1341 }
1342
1343 KeyedVector<sp<Surface>, size_t> outputMap;
1344 auto ret = mDevice->updateStream(streamId, newOutputs, streamInfos, removedSurfaceIds,
1345 &outputMap);
1346 if (ret != OK) {
1347 switch (ret) {
1348 case NAME_NOT_FOUND:
1349 case BAD_VALUE:
1350 case -EBUSY:
1351 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1352 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001353 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001354 break;
1355 default:
1356 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1357 "Camera %s: Error updating stream: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001358 mCameraIdStr.c_str(), strerror(ret), ret);
Emilian Peev40ead602017-09-26 15:46:36 +01001359 break;
1360 }
1361 } else {
1362 for (const auto &it : removedOutputs) {
1363 mStreamMap.removeItem(it);
1364 }
1365
1366 for (size_t i = 0; i < outputMap.size(); i++) {
1367 mStreamMap.add(IInterface::asBinder(outputMap.keyAt(i)->getIGraphicBufferProducer()),
1368 StreamSurfaceId(streamId, outputMap.valueAt(i)));
1369 }
1370
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001371 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
1372
Emilian Peev40ead602017-09-26 15:46:36 +01001373 ALOGV("%s: Camera %s: Successful stream ID %d update",
Austin Borger1c1bee02023-06-01 16:51:35 -07001374 __FUNCTION__, mCameraIdStr.c_str(), streamId);
Emilian Peev40ead602017-09-26 15:46:36 +01001375 }
1376
1377 return res;
1378}
1379
Igor Murashkine7ee7632013-06-11 18:10:18 -07001380// Create a request object from a template.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001381binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
1382 /*out*/
1383 hardware::camera2::impl::CameraMetadataNative* request)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001384{
1385 ATRACE_CALL();
1386 ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
1387
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001388 binder::Status res;
1389 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001390
1391 Mutex::Autolock icl(mBinderSerializationLock);
1392
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001393 if (!mDevice.get()) {
1394 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1395 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001396
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001397 status_t err;
Emilian Peevf4816702020-04-03 15:44:51 -07001398 camera_request_template_t tempId = camera_request_template_t::CAMERA_TEMPLATE_COUNT;
1399 if (!(res = mapRequestTemplate(templateId, &tempId)).isOk()) return res;
1400
1401 CameraMetadata metadata;
1402 if ( (err = mDevice->createDefaultRequest(tempId, &metadata) ) == OK &&
Igor Murashkine7ee7632013-06-11 18:10:18 -07001403 request != NULL) {
1404
1405 request->swap(metadata);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001406 } else if (err == BAD_VALUE) {
1407 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001408 "Camera %s: Template ID %d is invalid or not supported: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001409 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Chien-Yu Chen9cd14022016-03-09 12:21:01 -08001410
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001411 } else {
1412 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001413 "Camera %s: Error creating default request for template %d: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001414 mCameraIdStr.c_str(), templateId, strerror(-err), err);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001415 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001416 return res;
1417}
1418
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001419binder::Status CameraDeviceClient::getCameraInfo(
1420 /*out*/
1421 hardware::camera2::impl::CameraMetadataNative* info)
Igor Murashkine7ee7632013-06-11 18:10:18 -07001422{
1423 ATRACE_CALL();
1424 ALOGV("%s", __FUNCTION__);
1425
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001426 binder::Status res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001427
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001428 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Igor Murashkine7ee7632013-06-11 18:10:18 -07001429
1430 Mutex::Autolock icl(mBinderSerializationLock);
1431
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001432 if (!mDevice.get()) {
1433 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1434 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001435
Igor Murashkin099b4572013-07-12 17:52:16 -07001436 if (info != NULL) {
1437 *info = mDevice->info(); // static camera metadata
1438 // TODO: merge with device-specific camera metadata
1439 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001440
1441 return res;
1442}
1443
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001444binder::Status CameraDeviceClient::waitUntilIdle()
Zhijun He2ab500c2013-07-23 08:02:53 -07001445{
1446 ATRACE_CALL();
1447 ALOGV("%s", __FUNCTION__);
1448
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001449 binder::Status res;
1450 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Zhijun He2ab500c2013-07-23 08:02:53 -07001451
1452 Mutex::Autolock icl(mBinderSerializationLock);
1453
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001454 if (!mDevice.get()) {
1455 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1456 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001457
1458 // FIXME: Also need check repeating burst.
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001459 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001460 if (mStreamingRequestId != REQUEST_ID_NONE) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001461 std::string msg = fmt::sprintf(
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001462 "Camera %s: Try to waitUntilIdle when there are active streaming requests",
Austin Borger1c1bee02023-06-01 16:51:35 -07001463 mCameraIdStr.c_str());
1464 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1465 return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
Zhijun He2ab500c2013-07-23 08:02:53 -07001466 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001467 status_t err = mDevice->waitUntilDrained();
1468 if (err != OK) {
1469 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001470 "Camera %s: Error waiting to drain: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001471 mCameraIdStr.c_str(), strerror(-err), err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001472 }
Zhijun He2ab500c2013-07-23 08:02:53 -07001473 ALOGV("%s Done", __FUNCTION__);
Zhijun He2ab500c2013-07-23 08:02:53 -07001474 return res;
1475}
1476
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001477binder::Status CameraDeviceClient::flush(
1478 /*out*/
1479 int64_t* lastFrameNumber) {
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001480 ATRACE_CALL();
1481 ALOGV("%s", __FUNCTION__);
1482
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001483 binder::Status res;
1484 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001485
1486 Mutex::Autolock icl(mBinderSerializationLock);
1487
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001488 if (!mDevice.get()) {
1489 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1490 }
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001491
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07001492 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07001493 mStreamingRequestId = REQUEST_ID_NONE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001494 status_t err = mDevice->flush(lastFrameNumber);
1495 if (err != OK) {
1496 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001497 "Camera %s: Error flushing device: %s (%d)", mCameraIdStr.c_str(), strerror(-err),
1498 err);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001499 }
1500 return res;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -07001501}
1502
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001503binder::Status CameraDeviceClient::prepare(int streamId) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001504 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001505 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001506
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001507 binder::Status res;
1508 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001509
1510 Mutex::Autolock icl(mBinderSerializationLock);
1511
1512 // Guard against trying to prepare non-created streams
1513 ssize_t index = NAME_NOT_FOUND;
1514 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001515 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001516 index = i;
1517 break;
1518 }
1519 }
1520
1521 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001522 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1523 "with that ID exists", mCameraIdStr.c_str(), streamId);
1524 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1525 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001526 }
1527
Eino-Ville Talvala261394e2015-05-13 14:28:38 -07001528 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1529 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001530 status_t err = mDevice->prepare(streamId);
1531 if (err == BAD_VALUE) {
1532 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001533 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001534 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001535 } else if (err != OK) {
1536 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001537 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001538 strerror(-err), err);
1539 }
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07001540 return res;
1541}
1542
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001543binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001544 ATRACE_CALL();
Jayant Chowdhary57184d52023-02-14 20:54:39 +00001545 ALOGV("%s stream id %d", __FUNCTION__, streamId);
Ruben Brunkc78ac262015-08-13 17:58:46 -07001546
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001547 binder::Status res;
1548 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Ruben Brunkc78ac262015-08-13 17:58:46 -07001549
1550 Mutex::Autolock icl(mBinderSerializationLock);
1551
1552 // Guard against trying to prepare non-created streams
1553 ssize_t index = NAME_NOT_FOUND;
1554 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001555 if (streamId == mStreamMap.valueAt(i).streamId()) {
Ruben Brunkc78ac262015-08-13 17:58:46 -07001556 index = i;
1557 break;
1558 }
1559 }
1560
1561 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001562 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1563 "with that ID exists", mCameraIdStr.c_str(), streamId);
1564 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1565 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001566 }
1567
1568 if (maxCount <= 0) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001569 std::string msg = fmt::sprintf("Camera %s: maxCount (%d) must be greater than 0",
1570 mCameraIdStr.c_str(), maxCount);
1571 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1572 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Ruben Brunkc78ac262015-08-13 17:58:46 -07001573 }
1574
1575 // Also returns BAD_VALUE if stream ID was not valid, or stream already
1576 // has been used
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001577 status_t err = mDevice->prepare(maxCount, streamId);
1578 if (err == BAD_VALUE) {
1579 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001580 "Camera %s: Stream %d has already been used, and cannot be prepared",
Austin Borger1c1bee02023-06-01 16:51:35 -07001581 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001582 } else if (err != OK) {
1583 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001584 "Camera %s: Error preparing stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001585 strerror(-err), err);
1586 }
Ruben Brunkc78ac262015-08-13 17:58:46 -07001587
1588 return res;
1589}
1590
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001591binder::Status CameraDeviceClient::tearDown(int streamId) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001592 ATRACE_CALL();
1593 ALOGV("%s", __FUNCTION__);
1594
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001595 binder::Status res;
1596 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001597
1598 Mutex::Autolock icl(mBinderSerializationLock);
1599
1600 // Guard against trying to prepare non-created streams
1601 ssize_t index = NAME_NOT_FOUND;
1602 for (size_t i = 0; i < mStreamMap.size(); ++i) {
Shuzhen Wang0129d522016-10-30 22:43:41 -07001603 if (streamId == mStreamMap.valueAt(i).streamId()) {
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001604 index = i;
1605 break;
1606 }
1607 }
1608
1609 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001610 std::string msg = fmt::sprintf("Camera %s: Invalid stream ID (%d) specified, no stream "
1611 "with that ID exists", mCameraIdStr.c_str(), streamId);
1612 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1613 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001614 }
1615
1616 // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
1617 // use
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001618 status_t err = mDevice->tearDown(streamId);
1619 if (err == BAD_VALUE) {
1620 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001621 "Camera %s: Stream %d is still in use, cannot be torn down",
Austin Borger1c1bee02023-06-01 16:51:35 -07001622 mCameraIdStr.c_str(), streamId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001623 } else if (err != OK) {
1624 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Austin Borger1c1bee02023-06-01 16:51:35 -07001625 "Camera %s: Error tearing down stream %d: %s (%d)", mCameraIdStr.c_str(), streamId,
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08001626 strerror(-err), err);
1627 }
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -07001628
1629 return res;
1630}
1631
Shuzhen Wang758c2152017-01-10 18:26:18 -08001632binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId,
Zhijun He5d677d12016-05-29 16:52:39 -07001633 const hardware::camera2::params::OutputConfiguration &outputConfiguration) {
1634 ATRACE_CALL();
1635
1636 binder::Status res;
1637 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1638
1639 Mutex::Autolock icl(mBinderSerializationLock);
1640
Shuzhen Wang0129d522016-10-30 22:43:41 -07001641 const std::vector<sp<IGraphicBufferProducer> >& bufferProducers =
1642 outputConfiguration.getGraphicBufferProducers();
Austin Borger1c1bee02023-06-01 16:51:35 -07001643 const std::string &physicalId = outputConfiguration.getPhysicalCameraId();
Zhijun He5d677d12016-05-29 16:52:39 -07001644
Shuzhen Wang0129d522016-10-30 22:43:41 -07001645 if (bufferProducers.size() == 0) {
1646 ALOGE("%s: bufferProducers must not be empty", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -07001647 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
1648 }
Shuzhen Wang0129d522016-10-30 22:43:41 -07001649
Shuzhen Wang758c2152017-01-10 18:26:18 -08001650 // streamId should be in mStreamMap if this stream already has a surface attached
1651 // to it. Otherwise, it should be in mDeferredStreams.
1652 bool streamIdConfigured = false;
1653 ssize_t deferredStreamIndex = NAME_NOT_FOUND;
1654 for (size_t i = 0; i < mStreamMap.size(); i++) {
1655 if (mStreamMap.valueAt(i).streamId() == streamId) {
1656 streamIdConfigured = true;
1657 break;
1658 }
Zhijun He5d677d12016-05-29 16:52:39 -07001659 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001660 for (size_t i = 0; i < mDeferredStreams.size(); i++) {
1661 if (streamId == mDeferredStreams[i]) {
1662 deferredStreamIndex = i;
1663 break;
Shuzhen Wang0129d522016-10-30 22:43:41 -07001664 }
1665
Shuzhen Wang758c2152017-01-10 18:26:18 -08001666 }
1667 if (deferredStreamIndex == NAME_NOT_FOUND && !streamIdConfigured) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001668 std::string msg = fmt::sprintf("Camera %s: deferred surface is set to a unknown stream"
1669 "(ID %d)", mCameraIdStr.c_str(), streamId);
1670 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1671 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Zhijun He5d677d12016-05-29 16:52:39 -07001672 }
1673
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001674 if (mStreamInfoMap[streamId].finalized) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001675 std::string msg = fmt::sprintf("Camera %s: finalizeOutputConfigurations has been called"
1676 " on stream ID %d", mCameraIdStr.c_str(), streamId);
1677 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1678 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001679 }
1680
Zhijun He5d677d12016-05-29 16:52:39 -07001681 if (!mDevice.get()) {
1682 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1683 }
1684
Shuzhen Wang758c2152017-01-10 18:26:18 -08001685 std::vector<sp<Surface>> consumerSurfaces;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08001686 const std::vector<int32_t> &sensorPixelModesUsed =
1687 outputConfiguration.getSensorPixelModesUsed();
Emilian Peevc81a7592022-02-14 17:38:18 -08001688 int64_t dynamicRangeProfile = outputConfiguration.getDynamicRangeProfile();
Austin Borger9e2b27c2022-07-15 11:27:24 -07001689 int32_t colorSpace = outputConfiguration.getColorSpace();
1690 int64_t streamUseCase = outputConfiguration.getStreamUseCase();
Shuzhen Wange4208922022-02-01 16:52:48 -08001691 int timestampBase = outputConfiguration.getTimestampBase();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08001692 int mirrorMode = outputConfiguration.getMirrorMode();
Shuzhen Wang758c2152017-01-10 18:26:18 -08001693 for (auto& bufferProducer : bufferProducers) {
1694 // Don't create multiple streams for the same target surface
Zhijun He5d677d12016-05-29 16:52:39 -07001695 ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
1696 if (index != NAME_NOT_FOUND) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001697 ALOGV("Camera %s: Surface already has a stream created "
Austin Borger1c1bee02023-06-01 16:51:35 -07001698 " for it (ID %zd)", mCameraIdStr.c_str(), index);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001699 continue;
Zhijun He5d677d12016-05-29 16:52:39 -07001700 }
Shuzhen Wang758c2152017-01-10 18:26:18 -08001701
1702 sp<Surface> surface;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -07001703 res = SessionConfigurationUtils::createSurfaceFromGbp(mStreamInfoMap[streamId],
Colin Crossb8a9dbb2020-08-27 04:12:26 +00001704 true /*isStreamInfoValid*/, surface, bufferProducer, mCameraIdStr,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -08001705 mDevice->infoPhysical(physicalId), sensorPixelModesUsed, dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -07001706 streamUseCase, timestampBase, mirrorMode, colorSpace);
Shuzhen Wang758c2152017-01-10 18:26:18 -08001707
1708 if (!res.isOk())
1709 return res;
1710
1711 consumerSurfaces.push_back(surface);
Zhijun He5d677d12016-05-29 16:52:39 -07001712 }
1713
Shuzhen Wanga81ce342017-04-13 15:18:36 -07001714 // Gracefully handle case where finalizeOutputConfigurations is called
1715 // without any new surface.
1716 if (consumerSurfaces.size() == 0) {
1717 mStreamInfoMap[streamId].finalized = true;
1718 return res;
1719 }
1720
Zhijun He5d677d12016-05-29 16:52:39 -07001721 // Finish the deferred stream configuration with the surface.
Shuzhen Wang758c2152017-01-10 18:26:18 -08001722 status_t err;
Emilian Peev40ead602017-09-26 15:46:36 +01001723 std::vector<int> consumerSurfaceIds;
1724 err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces, &consumerSurfaceIds);
Zhijun He5d677d12016-05-29 16:52:39 -07001725 if (err == OK) {
Shuzhen Wang758c2152017-01-10 18:26:18 -08001726 for (size_t i = 0; i < consumerSurfaces.size(); i++) {
1727 sp<IBinder> binder = IInterface::asBinder(
1728 consumerSurfaces[i]->getIGraphicBufferProducer());
Emilian Peev40ead602017-09-26 15:46:36 +01001729 ALOGV("%s: mStreamMap add binder %p streamId %d, surfaceId %d", __FUNCTION__,
Shuzhen Wang758c2152017-01-10 18:26:18 -08001730 binder.get(), streamId, consumerSurfaceIds[i]);
1731 mStreamMap.add(binder, StreamSurfaceId(streamId, consumerSurfaceIds[i]));
1732 }
1733 if (deferredStreamIndex != NAME_NOT_FOUND) {
1734 mDeferredStreams.removeItemsAt(deferredStreamIndex);
Shuzhen Wang0129d522016-10-30 22:43:41 -07001735 }
Shuzhen Wang88fd0052017-02-09 16:40:07 -08001736 mStreamInfoMap[streamId].finalized = true;
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -08001737 mConfiguredOutputs.replaceValueFor(streamId, outputConfiguration);
Zhijun He5d677d12016-05-29 16:52:39 -07001738 } else if (err == NO_INIT) {
1739 res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001740 "Camera %s: Deferred surface is invalid: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001741 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001742 } else {
1743 res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -08001744 "Camera %s: Error setting output stream deferred surface: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001745 mCameraIdStr.c_str(), strerror(-err), err);
Zhijun He5d677d12016-05-29 16:52:39 -07001746 }
1747
1748 return res;
1749}
1750
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001751binder::Status CameraDeviceClient::setCameraAudioRestriction(int32_t mode) {
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001752 ATRACE_CALL();
1753 binder::Status res;
1754 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1755
1756 if (!isValidAudioRestriction(mode)) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001757 std::string msg = fmt::sprintf("Camera %s: invalid audio restriction mode %d",
1758 mCameraIdStr.c_str(), mode);
1759 ALOGW("%s: %s", __FUNCTION__, msg.c_str());
1760 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001761 }
1762
1763 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001764 BasicClient::setAudioRestriction(mode);
1765 return binder::Status::ok();
1766}
1767
1768binder::Status CameraDeviceClient::getGlobalAudioRestriction(/*out*/ int32_t* outMode) {
1769 ATRACE_CALL();
1770 binder::Status res;
1771 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1772 Mutex::Autolock icl(mBinderSerializationLock);
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001773 if (outMode != nullptr) {
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -07001774 *outMode = BasicClient::getServiceAudioRestriction();
Yin-Chia Yehdba03232019-08-19 15:54:28 -07001775 }
1776 return binder::Status::ok();
1777}
1778
Ravneetaeb20dc2022-03-30 05:33:03 +00001779status_t CameraDeviceClient::setCameraServiceWatchdog(bool enabled) {
1780 return mDevice->setCameraServiceWatchdog(enabled);
1781}
1782
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001783status_t CameraDeviceClient::setRotateAndCropOverride(uint8_t rotateAndCrop, bool fromHal) {
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001784 if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
1785
1786 return mDevice->setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +00001787 static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop), fromHal);
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001788}
1789
Bharatt Kukreja7146ced2022-10-25 15:45:29 +00001790status_t CameraDeviceClient::setAutoframingOverride(uint8_t autoframingValue) {
1791 if (autoframingValue > ANDROID_CONTROL_AUTOFRAMING_AUTO) return BAD_VALUE;
1792
1793 return mDevice->setAutoframingAutoBehavior(
1794 static_cast<camera_metadata_enum_android_control_autoframing_t>(autoframingValue));
1795}
1796
Eino-Ville Talvala305cec62020-11-12 14:18:17 -08001797bool CameraDeviceClient::supportsCameraMute() {
1798 return mDevice->supportsCameraMute();
1799}
1800
1801status_t CameraDeviceClient::setCameraMute(bool enabled) {
1802 return mDevice->setCameraMute(enabled);
1803}
1804
Shuzhen Wang16610a62022-12-15 22:38:07 -08001805void CameraDeviceClient::setStreamUseCaseOverrides(
1806 const std::vector<int64_t>& useCaseOverrides) {
1807 mDevice->setStreamUseCaseOverrides(useCaseOverrides);
1808}
1809
1810void CameraDeviceClient::clearStreamUseCaseOverrides() {
1811 mDevice->clearStreamUseCaseOverrides();
1812}
1813
Shuzhen Wangaf22e912023-04-11 16:03:17 -07001814bool CameraDeviceClient::supportsZoomOverride() {
1815 return mDevice->supportsZoomOverride();
1816}
1817
1818status_t CameraDeviceClient::setZoomOverride(int32_t zoomOverride) {
1819 return mDevice->setZoomOverride(zoomOverride);
1820}
1821
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001822binder::Status CameraDeviceClient::switchToOffline(
1823 const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001824 const std::vector<int>& offlineOutputIds,
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001825 /*out*/
1826 sp<hardware::camera2::ICameraOfflineSession>* session) {
1827 ATRACE_CALL();
1828
1829 binder::Status res;
1830 if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
1831
1832 Mutex::Autolock icl(mBinderSerializationLock);
1833
1834 if (!mDevice.get()) {
1835 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
1836 }
1837
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001838 if (offlineOutputIds.empty()) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001839 std::string msg = "Offline surfaces must not be empty";
1840 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1841 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001842 }
1843
1844 if (session == nullptr) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001845 std::string msg = "Invalid offline session";
1846 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1847 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001848 }
1849
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -08001850 std::vector<int32_t> offlineStreamIds;
1851 offlineStreamIds.reserve(offlineOutputIds.size());
Emilian Peev4697b642019-11-19 17:11:14 -08001852 KeyedVector<sp<IBinder>, sp<CompositeStream>> offlineCompositeStreamMap;
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001853 for (const auto& streamId : offlineOutputIds) {
1854 ssize_t index = mConfiguredOutputs.indexOfKey(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001855 if (index == NAME_NOT_FOUND) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001856 std::string msg = fmt::sprintf("Offline surface with id: %d is not registered",
Emilian Peevcc0b7952020-01-07 13:54:47 -08001857 streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001858 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1859 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001860 }
Emilian Peevcc0b7952020-01-07 13:54:47 -08001861
1862 if (!mStreamInfoMap[streamId].supportsOffline) {
Austin Borger1c1bee02023-06-01 16:51:35 -07001863 std::string msg = fmt::sprintf("Offline surface with id: %d doesn't support "
Emilian Peevcc0b7952020-01-07 13:54:47 -08001864 "offline mode", streamId);
Austin Borger1c1bee02023-06-01 16:51:35 -07001865 ALOGE("%s: %s", __FUNCTION__, msg.c_str());
1866 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
Emilian Peevcc0b7952020-01-07 13:54:47 -08001867 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001868
Emilian Peev2f5d6012022-01-19 16:16:50 -08001869 Mutex::Autolock l(mCompositeLock);
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001870 bool isCompositeStream = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08001871 for (const auto& gbp : mConfiguredOutputs.valueAt(index).getGraphicBufferProducers()) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001872 sp<Surface> s = new Surface(gbp, false /*controlledByApp*/);
Pirama Arumuga Nainar8db21062022-01-28 10:15:12 -08001873 isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s) ||
Emilian Peev434248e2022-10-06 14:58:54 -07001874 camera3::HeicCompositeStream::isHeicCompositeStream(s) ||
Emilian Peeve579d8b2023-02-28 14:16:08 -08001875 (camera3::JpegRCompositeStream::isJpegRCompositeStream(s) &&
Emilian Peev15230142023-04-27 20:22:54 +00001876 !mDevice->isCompositeJpegRDisabled());
Emilian Peev4697b642019-11-19 17:11:14 -08001877 if (isCompositeStream) {
1878 auto compositeIdx = mCompositeStreamMap.indexOfKey(IInterface::asBinder(gbp));
1879 if (compositeIdx == NAME_NOT_FOUND) {
1880 ALOGE("%s: Unknown composite stream", __FUNCTION__);
1881 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
1882 "Unknown composite stream");
1883 }
1884
1885 mCompositeStreamMap.valueAt(compositeIdx)->insertCompositeStreamIds(
1886 &offlineStreamIds);
1887 offlineCompositeStreamMap.add(mCompositeStreamMap.keyAt(compositeIdx),
1888 mCompositeStreamMap.valueAt(compositeIdx));
1889 break;
1890 }
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001891 }
1892
Emilian Peev4697b642019-11-19 17:11:14 -08001893 if (!isCompositeStream) {
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001894 offlineStreamIds.push_back(streamId);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001895 }
1896 }
1897
1898 sp<CameraOfflineSessionBase> offlineSession;
1899 auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
1900 if (ret != OK) {
1901 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1902 "Camera %s: Error switching to offline mode: %s (%d)",
Austin Borger1c1bee02023-06-01 16:51:35 -07001903 mCameraIdStr.c_str(), strerror(ret), ret);
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001904 }
1905
Emilian Peevcc0b7952020-01-07 13:54:47 -08001906 sp<CameraOfflineSessionClient> offlineClient;
1907 if (offlineSession.get() != nullptr) {
1908 offlineClient = new CameraOfflineSessionClient(sCameraService,
1909 offlineSession, offlineCompositeStreamMap, cameraCb, mClientPackageName,
Emilian Peev8b64f282021-03-25 16:49:57 -07001910 mClientFeatureId, mCameraIdStr, mCameraFacing, mOrientation, mClientPid, mClientUid,
1911 mServicePid);
Emilian Peevcc0b7952020-01-07 13:54:47 -08001912 ret = sCameraService->addOfflineClient(mCameraIdStr, offlineClient);
1913 }
1914
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001915 if (ret == OK) {
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001916 // A successful offline session switch must reset the current camera client
1917 // and release any resources occupied by previously configured streams.
1918 mStreamMap.clear();
1919 mConfiguredOutputs.clear();
1920 mDeferredStreams.clear();
1921 mStreamInfoMap.clear();
Emilian Peev2f5d6012022-01-19 16:16:50 -08001922 Mutex::Autolock l(mCompositeLock);
Emilian Peevd99c8ae2019-11-26 13:19:13 -08001923 mCompositeStreamMap.clear();
1924 mInputStream = {false, 0, 0, 0, 0};
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001925 } else {
Emilian Peev886ac212023-02-07 14:10:24 -08001926 // In case we failed to register the offline client, ensure that it still initialized
1927 // so that all failing requests can return back correctly once the object is released.
Austin Borger1c1bee02023-06-01 16:51:35 -07001928 offlineClient->initialize(nullptr /*cameraProviderManager*/, std::string()/*monitorTags*/);
Emilian Peev886ac212023-02-07 14:10:24 -08001929
Emilian Peevb2bc5a42019-11-20 16:02:14 -08001930 switch(ret) {
1931 case BAD_VALUE:
1932 return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
1933 "Illegal argument to HAL module for camera \"%s\"", mCameraIdStr.c_str());
1934 case TIMED_OUT:
1935 return STATUS_ERROR_FMT(CameraService::ERROR_CAMERA_IN_USE,
1936 "Camera \"%s\" is already open", mCameraIdStr.c_str());
1937 default:
1938 return STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
1939 "Failed to initialize camera \"%s\": %s (%d)", mCameraIdStr.c_str(),
1940 strerror(-ret), ret);
1941 }
Yin-Chia Yehb978c382019-10-30 00:22:37 -07001942 }
1943
1944 *session = offlineClient;
1945
1946 return binder::Status::ok();
1947}
1948
Igor Murashkine7ee7632013-06-11 18:10:18 -07001949status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
Eino-Ville Talvalac4003962016-01-13 10:07:04 -08001950 return BasicClient::dump(fd, args);
1951}
1952
1953status_t CameraDeviceClient::dumpClient(int fd, const Vector<String16>& args) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001954 dprintf(fd, " CameraDeviceClient[%s] (%p) dump:\n",
Austin Borger1c1bee02023-06-01 16:51:35 -07001955 mCameraIdStr.c_str(),
Eino-Ville Talvalae992e752014-11-07 16:17:48 -08001956 (getRemoteCallback() != NULL ?
Marco Nelissenf8880202014-11-14 07:58:25 -08001957 IInterface::asBinder(getRemoteCallback()).get() : NULL) );
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001958 dprintf(fd, " Current client UID %u\n", mClientUid);
Igor Murashkine7ee7632013-06-11 18:10:18 -07001959
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001960 dprintf(fd, " State:\n");
1961 dprintf(fd, " Request ID counter: %d\n", mRequestIdCounter);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001962 if (mInputStream.configured) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001963 dprintf(fd, " Current input stream ID: %d\n", mInputStream.id);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001964 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001965 dprintf(fd, " No input stream configured.\n");
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -07001966 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001967 if (!mStreamMap.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001968 dprintf(fd, " Current output stream/surface IDs:\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001969 for (size_t i = 0; i < mStreamMap.size(); i++) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001970 dprintf(fd, " Stream %d Surface %d\n",
Shuzhen Wang0129d522016-10-30 22:43:41 -07001971 mStreamMap.valueAt(i).streamId(),
1972 mStreamMap.valueAt(i).surfaceId());
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001973 }
Zhijun He5d677d12016-05-29 16:52:39 -07001974 } else if (!mDeferredStreams.isEmpty()) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001975 dprintf(fd, " Current deferred surface output stream IDs:\n");
Zhijun He5d677d12016-05-29 16:52:39 -07001976 for (auto& streamId : mDeferredStreams) {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001977 dprintf(fd, " Stream %d\n", streamId);
Zhijun He5d677d12016-05-29 16:52:39 -07001978 }
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001979 } else {
Eino-Ville Talvalad00111e2017-01-31 11:59:12 -08001980 dprintf(fd, " No output streams configured.\n");
Eino-Ville Talvala67489d22014-09-18 15:52:02 -07001981 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07001982 // TODO: print dynamic/request section from most recent requests
1983 mFrameProcessor->dump(fd, args);
1984
1985 return dumpDevice(fd, args);
1986}
1987
Austin Borger1c1bee02023-06-01 16:51:35 -07001988status_t CameraDeviceClient::startWatchingTags(const std::string &tags, int out) {
Avichal Rakesh7e53cad2021-10-05 13:46:30 -07001989 sp<CameraDeviceBase> device = mDevice;
1990 if (!device) {
1991 dprintf(out, " Device is detached.");
1992 return OK;
1993 }
1994 device->startWatchingTags(tags);
1995 return OK;
1996}
1997
1998status_t CameraDeviceClient::stopWatchingTags(int out) {
1999 sp<CameraDeviceBase> device = mDevice;
2000 if (!device) {
2001 dprintf(out, " Device is detached.");
2002 return OK;
2003 }
2004 device->stopWatchingTags();
2005 return OK;
2006}
2007
2008status_t CameraDeviceClient::dumpWatchedEventsToVector(std::vector<std::string> &out) {
2009 sp<CameraDeviceBase> device = mDevice;
2010 if (!device) {
2011 return OK;
2012 }
2013 device->dumpWatchedEventsToVector(out);
2014 return OK;
2015}
2016
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002017void CameraDeviceClient::notifyError(int32_t errorCode,
Jianing Weicb0652e2014-03-12 18:29:36 -07002018 const CaptureResultExtras& resultExtras) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002019 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002020 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002021
Emilian Peev538c90e2018-12-17 18:03:19 +00002022 bool skipClientNotification = false;
Emilian Peev2f5d6012022-01-19 16:16:50 -08002023 {
2024 // Access to the composite stream map must be synchronized
2025 Mutex::Autolock l(mCompositeLock);
2026 // Composites can have multiple internal streams. Error notifications coming from such
2027 // internal streams may need to remain within camera service.
2028 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2029 skipClientNotification |= mCompositeStreamMap.valueAt(i)->onError(errorCode,
2030 resultExtras);
2031 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002032 }
2033
2034 if ((remoteCb != 0) && (!skipClientNotification)) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002035 remoteCb->onDeviceError(errorCode, resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002036 }
2037}
2038
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002039void CameraDeviceClient::notifyRepeatingRequestError(long lastFrameNumber) {
2040 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2041
2042 if (remoteCb != 0) {
Yin-Chia Yeh8ca23dc2017-09-05 18:15:56 -07002043 remoteCb->onRepeatingRequestError(lastFrameNumber, mStreamingRequestId);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002044 }
2045
Shuzhen Wangc9ca6782016-04-26 13:40:31 -07002046 Mutex::Autolock idLock(mStreamingRequestIdLock);
Chien-Yu Chene8c535e2016-04-14 12:18:26 -07002047 mStreamingRequestId = REQUEST_ID_NONE;
2048}
2049
Shuzhen Wang316781a2020-08-18 18:11:01 -07002050void CameraDeviceClient::notifyIdle(
2051 int64_t requestCount, int64_t resultErrorCount, bool deviceError,
2052 const std::vector<hardware::CameraStreamStats>& streamStats) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002053 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002054 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002055
2056 if (remoteCb != 0) {
2057 remoteCb->onDeviceIdle();
2058 }
Emilian Peev567c31c2023-03-06 15:02:37 -08002059
2060 std::vector<hardware::CameraStreamStats> fullStreamStats = streamStats;
2061 {
2062 Mutex::Autolock l(mCompositeLock);
2063 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2064 hardware::CameraStreamStats compositeStats;
2065 mCompositeStreamMap.valueAt(i)->getStreamStats(&compositeStats);
2066 if (compositeStats.mWidth > 0) {
2067 fullStreamStats.push_back(compositeStats);
2068 }
2069 }
2070 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -08002071 Camera2ClientBase::notifyIdleWithUserTag(requestCount, resultErrorCount, deviceError,
Shuzhen Wang6e08d202023-10-24 20:27:14 +00002072 fullStreamStats, mUserTag, mVideoStabilizationMode, mUsedUltraWide,
2073 mUsedSettingsOverrideZoom);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002074}
2075
Jianing Weicb0652e2014-03-12 18:29:36 -07002076void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002077 nsecs_t timestamp) {
2078 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002079 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002080 if (remoteCb != 0) {
Jianing Weicb0652e2014-03-12 18:29:36 -07002081 remoteCb->onCaptureStarted(resultExtras, timestamp);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002082 }
Eino-Ville Talvala412fe562015-08-20 17:08:32 -07002083 Camera2ClientBase::notifyShutter(resultExtras, timestamp);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002084
Emilian Peev2f5d6012022-01-19 16:16:50 -08002085 // Access to the composite stream map must be synchronized
2086 Mutex::Autolock l(mCompositeLock);
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -08002087 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2088 mCompositeStreamMap.valueAt(i)->onShutter(resultExtras, timestamp);
2089 }
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -07002090}
2091
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002092void CameraDeviceClient::notifyPrepared(int streamId) {
2093 // Thread safe. Don't bother locking.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002094 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002095 if (remoteCb != 0) {
Jayant Chowdhary57184d52023-02-14 20:54:39 +00002096 ALOGV("%s: stream id %d", __FUNCTION__, streamId);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -07002097 remoteCb->onPrepared(streamId);
2098 }
2099}
2100
Shuzhen Wang9d066012016-09-30 11:30:20 -07002101void CameraDeviceClient::notifyRequestQueueEmpty() {
2102 // Thread safe. Don't bother locking.
2103 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
2104 if (remoteCb != 0) {
2105 remoteCb->onRequestQueueEmpty();
2106 }
2107}
2108
Igor Murashkine7ee7632013-06-11 18:10:18 -07002109void CameraDeviceClient::detachDevice() {
2110 if (mDevice == 0) return;
2111
Shuzhen Wang316781a2020-08-18 18:11:01 -07002112 nsecs_t startTime = systemTime();
Austin Borger1c1bee02023-06-01 16:51:35 -07002113 ALOGV("Camera %s: Stopping processors", mCameraIdStr.c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -07002114
Emilian Peev7ee731f2022-02-08 14:55:52 -08002115 if (mFrameProcessor.get() != nullptr) {
2116 mFrameProcessor->removeListener(
2117 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MIN_ID,
2118 camera2::FrameProcessorBase::FRAME_PROCESSOR_LISTENER_MAX_ID, /*listener*/this);
2119 mFrameProcessor->requestExit();
Austin Borger1c1bee02023-06-01 16:51:35 -07002120 ALOGV("Camera %s: Waiting for threads", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002121 mFrameProcessor->join();
Austin Borger1c1bee02023-06-01 16:51:35 -07002122 ALOGV("Camera %s: Disconnecting device", mCameraIdStr.c_str());
Emilian Peev7ee731f2022-02-08 14:55:52 -08002123 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002124
2125 // WORKAROUND: HAL refuses to disconnect while there's streams in flight
2126 {
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002127 int64_t lastFrameNumber;
Igor Murashkine7ee7632013-06-11 18:10:18 -07002128 status_t code;
Emilian Peev6b51d7d2018-07-23 11:41:44 +01002129 if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
2130 ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
2131 }
2132
Igor Murashkine7ee7632013-06-11 18:10:18 -07002133 if ((code = mDevice->waitUntilDrained()) != OK) {
2134 ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
2135 code);
2136 }
2137 }
2138
Emilian Peev2f5d6012022-01-19 16:16:50 -08002139 {
2140 Mutex::Autolock l(mCompositeLock);
2141 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2142 auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
2143 if (ret != OK) {
2144 ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
2145 strerror(-ret), ret);
2146 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002147 }
Emilian Peev2f5d6012022-01-19 16:16:50 -08002148 mCompositeStreamMap.clear();
Emilian Peev5e4c7322019-10-22 14:20:52 -07002149 }
Emilian Peev5e4c7322019-10-22 14:20:52 -07002150
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002151 bool hasDeviceError = mDevice->hasDeviceError();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002152 Camera2ClientBase::detachDevice();
Shuzhen Wang316781a2020-08-18 18:11:01 -07002153
2154 int32_t closeLatencyMs = ns2ms(systemTime() - startTime);
Shuzhen Wang03fe6232023-02-05 12:41:15 -08002155 mCameraServiceProxyWrapper->logClose(mCameraIdStr, closeLatencyMs, hasDeviceError);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002156}
2157
2158/** Device-related methods */
Jianing Weicb0652e2014-03-12 18:29:36 -07002159void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
Igor Murashkine7ee7632013-06-11 18:10:18 -07002160 ATRACE_CALL();
2161 ALOGV("%s", __FUNCTION__);
2162
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002163 // Thread-safe. No lock necessary.
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002164 sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
Igor Murashkin4fb55c12013-08-29 17:43:01 -07002165 if (remoteCb != NULL) {
Shuzhen Wang5c22c152017-12-31 17:12:25 -08002166 remoteCb->onResultReceived(result.mMetadata, result.mResultExtras,
2167 result.mPhysicalMetadatas);
Igor Murashkine7ee7632013-06-11 18:10:18 -07002168 }
Emilian Peev538c90e2018-12-17 18:03:19 +00002169
Emilian Peev2f5d6012022-01-19 16:16:50 -08002170 // Access to the composite stream map must be synchronized
2171 Mutex::Autolock l(mCompositeLock);
Emilian Peev538c90e2018-12-17 18:03:19 +00002172 for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
2173 mCompositeStreamMap.valueAt(i)->onResultAvailable(result);
2174 }
Igor Murashkine7ee7632013-06-11 18:10:18 -07002175}
2176
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002177binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
Eino-Ville Talvala6192b892016-04-04 12:31:18 -07002178 if (mDisconnected) {
2179 return STATUS_ERROR(CameraService::ERROR_DISCONNECTED,
2180 "The camera device has been disconnected");
2181 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -08002182 status_t res = checkPid(checkLocation);
2183 return (res == OK) ? binder::Status::ok() :
2184 STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
2185 "Attempt to use camera from a different process than original client");
2186}
2187
Igor Murashkine7ee7632013-06-11 18:10:18 -07002188// TODO: move to Camera2ClientBase
2189bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
2190
Jayant Chowdhary12361932018-08-27 14:46:13 -07002191 const int pid = CameraThreadState::getCallingPid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002192 const int selfPid = getpid();
2193 camera_metadata_entry_t entry;
2194
2195 /**
2196 * Mixin default important security values
2197 * - android.led.transmit = defaulted ON
2198 */
2199 CameraMetadata staticInfo = mDevice->info();
2200 entry = staticInfo.find(ANDROID_LED_AVAILABLE_LEDS);
2201 for(size_t i = 0; i < entry.count; ++i) {
2202 uint8_t led = entry.data.u8[i];
2203
2204 switch(led) {
2205 case ANDROID_LED_AVAILABLE_LEDS_TRANSMIT: {
2206 uint8_t transmitDefault = ANDROID_LED_TRANSMIT_ON;
2207 if (!metadata.exists(ANDROID_LED_TRANSMIT)) {
2208 metadata.update(ANDROID_LED_TRANSMIT,
2209 &transmitDefault, 1);
2210 }
2211 break;
2212 }
2213 }
2214 }
2215
2216 // We can do anything!
2217 if (pid == selfPid) {
2218 return true;
2219 }
2220
2221 /**
2222 * Permission check special fields in the request
2223 * - android.led.transmit = android.permission.CAMERA_DISABLE_TRANSMIT
2224 */
2225 entry = metadata.find(ANDROID_LED_TRANSMIT);
2226 if (entry.count > 0 && entry.data.u8[0] != ANDROID_LED_TRANSMIT_ON) {
2227 String16 permissionString =
Austin Borger1c1bee02023-06-01 16:51:35 -07002228 toString16("android.permission.CAMERA_DISABLE_TRANSMIT_LED");
Igor Murashkine7ee7632013-06-11 18:10:18 -07002229 if (!checkCallingPermission(permissionString)) {
Jayant Chowdhary12361932018-08-27 14:46:13 -07002230 const int uid = CameraThreadState::getCallingUid();
Igor Murashkine7ee7632013-06-11 18:10:18 -07002231 ALOGE("Permission Denial: "
2232 "can't disable transmit LED pid=%d, uid=%d", pid, uid);
2233 return false;
2234 }
2235 }
2236
2237 return true;
2238}
2239
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002240status_t CameraDeviceClient::getRotationTransformLocked(int mirrorMode,
2241 int32_t* transform) {
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002242 ALOGV("%s: begin", __FUNCTION__);
2243
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002244 const CameraMetadata& staticInfo = mDevice->info();
Shuzhen Wang610d7b82022-02-08 14:37:22 -08002245 return CameraUtils::getRotationTransform(staticInfo, mirrorMode, transform);
Igor Murashkinf8b2a6f2013-09-17 17:03:28 -07002246}
2247
Emilian Peevf4816702020-04-03 15:44:51 -07002248binder::Status CameraDeviceClient::mapRequestTemplate(int templateId,
2249 camera_request_template_t* tempId /*out*/) {
2250 binder::Status ret = binder::Status::ok();
2251
2252 if (tempId == nullptr) {
2253 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
Austin Borger1c1bee02023-06-01 16:51:35 -07002254 "Camera %s: Invalid template argument", mCameraIdStr.c_str());
Emilian Peevf4816702020-04-03 15:44:51 -07002255 return ret;
2256 }
2257 switch(templateId) {
2258 case ICameraDeviceUser::TEMPLATE_PREVIEW:
2259 *tempId = camera_request_template_t::CAMERA_TEMPLATE_PREVIEW;
2260 break;
2261 case ICameraDeviceUser::TEMPLATE_RECORD:
2262 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_RECORD;
2263 break;
2264 case ICameraDeviceUser::TEMPLATE_STILL_CAPTURE:
2265 *tempId = camera_request_template_t::CAMERA_TEMPLATE_STILL_CAPTURE;
2266 break;
2267 case ICameraDeviceUser::TEMPLATE_VIDEO_SNAPSHOT:
2268 *tempId = camera_request_template_t::CAMERA_TEMPLATE_VIDEO_SNAPSHOT;
2269 break;
2270 case ICameraDeviceUser::TEMPLATE_ZERO_SHUTTER_LAG:
2271 *tempId = camera_request_template_t::CAMERA_TEMPLATE_ZERO_SHUTTER_LAG;
2272 break;
2273 case ICameraDeviceUser::TEMPLATE_MANUAL:
2274 *tempId = camera_request_template_t::CAMERA_TEMPLATE_MANUAL;
2275 break;
2276 default:
2277 ret = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
2278 "Camera %s: Template ID %d is invalid or not supported",
Austin Borger1c1bee02023-06-01 16:51:35 -07002279 mCameraIdStr.c_str(), templateId);
Emilian Peevf4816702020-04-03 15:44:51 -07002280 return ret;
2281 }
2282
2283 return ret;
2284}
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002285
Austin Borger1c1bee02023-06-01 16:51:35 -07002286const CameraMetadata &CameraDeviceClient::getStaticInfo(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002287 if (mDevice->getId() == cameraId) {
2288 return mDevice->info();
2289 }
2290 return mDevice->infoPhysical(cameraId);
2291}
2292
Austin Borger1c1bee02023-06-01 16:51:35 -07002293bool CameraDeviceClient::supportsUltraHighResolutionCapture(const std::string &cameraId) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002294 const CameraMetadata &deviceInfo = getStaticInfo(cameraId);
Jayant Chowdharydbd1efb2023-02-07 16:14:48 -08002295 return SessionConfigurationUtils::supportsUltraHighResolutionCapture(deviceInfo);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -08002296}
2297
2298bool CameraDeviceClient::isSensorPixelModeConsistent(
2299 const std::list<int> &streamIdList, const CameraMetadata &settings) {
2300 // First we get the sensorPixelMode from the settings metadata.
2301 int32_t sensorPixelMode = ANDROID_SENSOR_PIXEL_MODE_DEFAULT;
2302 camera_metadata_ro_entry sensorPixelModeEntry = settings.find(ANDROID_SENSOR_PIXEL_MODE);
2303 if (sensorPixelModeEntry.count != 0) {
2304 sensorPixelMode = sensorPixelModeEntry.data.u8[0];
2305 if (sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_DEFAULT &&
2306 sensorPixelMode != ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION) {
2307 ALOGE("%s: Request sensor pixel mode not is not one of the valid values %d",
2308 __FUNCTION__, sensorPixelMode);
2309 return false;
2310 }
2311 }
2312 // Check whether each stream has max resolution allowed.
2313 bool consistent = true;
2314 for (auto it : streamIdList) {
2315 auto const streamInfoIt = mStreamInfoMap.find(it);
2316 if (streamInfoIt == mStreamInfoMap.end()) {
2317 ALOGE("%s: stream id %d not created, skipping", __FUNCTION__, it);
2318 return false;
2319 }
2320 consistent =
2321 streamInfoIt->second.sensorPixelModesUsed.find(sensorPixelMode) !=
2322 streamInfoIt->second.sensorPixelModesUsed.end();
2323 if (!consistent) {
2324 ALOGE("sensorPixelMode used %i not consistent with configured modes", sensorPixelMode);
2325 for (auto m : streamInfoIt->second.sensorPixelModesUsed) {
2326 ALOGE("sensor pixel mode used list: %i", m);
2327 }
2328 break;
2329 }
2330 }
2331
2332 return consistent;
2333}
2334
Igor Murashkine7ee7632013-06-11 18:10:18 -07002335} // namespace android